@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
52 lines (49 loc) • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isSelectionInNode = exports.isNonEditableBlock = exports.isNestedNodeSelected = exports.isInTextSelection = void 0;
var _state = require("@atlaskit/editor-prosemirror/state");
var isNestedNodeSelected = exports.isNestedNodeSelected = function isNestedNodeSelected(view) {
var selection = view.state.selection;
return selection instanceof _state.NodeSelection && selection.$from.depth > 0;
};
var isSelectionInNode = exports.isSelectionInNode = function isSelectionInNode(start, view) {
var node = view.state.doc.nodeAt(start);
if (node === null) {
return false;
}
var endPos = start + node.nodeSize;
var startPos = start;
var _view$state$selection = view.state.selection,
$from = _view$state$selection.$from,
$to = _view$state$selection.$to;
return $from.pos >= startPos && endPos >= $to.pos;
};
// checks if the selection is in a text node
var isInTextSelection = exports.isInTextSelection = function isInTextSelection(view) {
var selection = view.state.selection;
if (selection instanceof _state.TextSelection) {
return true;
} else if (selection instanceof _state.NodeSelection) {
// check if this is a node that can appear among text
return selection.node.isInline;
}
};
var isNonEditableBlock = exports.isNonEditableBlock = function isNonEditableBlock(start, view) {
var node = view.state.doc.nodeAt(start);
if (node === null) {
return false;
}
// We want to treat some elements as if they are non-editable blocks for
// the purposes of quick insert.
switch (node.type.name) {
// mediaSingle and mediaGroup always contain a media child node, which is
// both a block and an atom. mediaSingle can also have a caption child node
// which is an editable block.
case 'mediaGroup':
case 'mediaSingle':
return true;
}
return node.isBlock && (node.isAtom || node.isLeaf);
};