@atlaskit/editor-plugin-breakout
Version:
Breakout plugin for @atlaskit/editor-core
35 lines • 1.33 kB
JavaScript
import { transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
import { findSupportedNodeForBreakout } from '../pm-plugins/utils/find-breakout-node';
import { updateExpandedState } from '../pm-plugins/utils/single-player-expand';
export function removeBreakout(isLivePage) {
return function (state, dispatch) {
var node = findSupportedNodeForBreakout(state.selection);
if (!node) {
return false;
}
var marks = node.node.marks.filter(function (m) {
return m.type.name !== 'breakout';
});
var tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, marks);
if (node.node.type === state.schema.nodes.expand) {
updateExpandedState(tr, node, isLivePage);
} else if (node.node.type === state.schema.nodes.codeBlock) {
var newNode = tr.doc.nodeAt(node.pos);
var oldNode = node.node;
if (newNode) {
transferCodeBlockWrappedValue(oldNode, newNode);
}
}
tr.setMeta('scrollIntoView', false);
if (state.selection instanceof NodeSelection) {
if (state.selection.$anchor.pos === node.pos) {
tr.setSelection(NodeSelection.create(tr.doc, node.pos));
}
}
if (dispatch) {
dispatch(tr);
}
return true;
};
}