UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

39 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var prosemirror_1 = require("../../prosemirror"); var utils_1 = require("../../utils"); var commands = require("../../commands"); exports.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 (utils_1.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 && !utils_1.atTheBeginningOfDoc(state)) { utils_1.moveLeft(view); } }; exports.splitMediaGroup = function (view) { var selection = view.state.selection; // if selection is not a media node, do nothing. if (!(selection instanceof prosemirror_1.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