UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

37 lines 1.76 kB
import { NodeSelection, } from '../../prosemirror'; import { moveLeft, atTheBeginningOfDoc, isTemporary } from '../../utils'; import * as commands from '../../commands'; export var removeMediaNode = function (view, node, getPos) { var id = node.attrs.id; var state = view.state; var tr = state.tr, selection = state.selection, doc = state.doc; var currentMediaNodePos = getPos(); tr.deleteRange(currentMediaNodePos, currentMediaNodePos + node.nodeSize); if (isTemporary(id)) { tr.setMeta('addToHistory', false); } view.dispatch(tr); var $currentMediaNodePos = doc.resolve(currentMediaNodePos); var isLastMediaNode = $currentMediaNodePos.index() === $currentMediaNodePos.parent.childCount - 1; // If deleting a selected media node, we need to tell where the cursor to go next. // Prosemirror didn't gave us the behaviour of moving left if the media node is not the last one. // So we handle it ourselves. if (selection.from === currentMediaNodePos && !isLastMediaNode && !atTheBeginningOfDoc(state)) { moveLeft(view); } }; export var splitMediaGroup = function (view) { var selection = view.state.selection; // if selection is not a media node, do nothing. if (!(selection instanceof NodeSelection) || selection.node.type !== view.state.schema.nodes.media) { return false; } commands.deleteSelection(view.state, view.dispatch); // if selected media node is the last one, no need to insert a new p or split the block, prosemirror handled it. if (selection.$to.nodeAfter) { commands.splitBlock(view.state, view.dispatch); commands.createParagraphNear(view, false); } return true; }; //# sourceMappingURL=media-common.js.map