UNPKG

@atlaskit/editor-plugin-breakout

Version:

Breakout plugin for @atlaskit/editor-core

39 lines (38 loc) 1.28 kB
import { transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block'; import { NodeSelection } from '@atlaskit/editor-prosemirror/state'; import { updateExpandedStateNew } from '../pm-plugins/utils/single-player-expand'; export function setBreakoutWidth(width, mode, pos, isLivePage) { return (state, dispatch) => { const node = state.doc.nodeAt(pos); if (!node) { return false; } const tr = state.tr.setNodeMarkup(pos, node.type, node.attrs, [state.schema.marks.breakout.create({ width, mode })]); if (node.type === state.schema.nodes.expand) { updateExpandedStateNew({ tr, node, pos, isLivePage }); } else if (node.type === state.schema.nodes.codeBlock) { const newNode = tr.doc.nodeAt(pos); const oldNode = node; if (newNode) { transferCodeBlockWrappedValue(oldNode, newNode); } } tr.setMeta('scrollIntoView', false); // keep current selection, necessary to not remove NodeSelection for keyboard resizing if (state.selection instanceof NodeSelection && state.selection.node.eq(node)) { tr.setSelection(NodeSelection.create(tr.doc, pos)); } if (dispatch) { dispatch(tr); } return true; }; }