@portabletext/editor
Version:
Portable Text Editor made in React
89 lines (88 loc) • 3.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: !0 });
var selectionPoint = require("../_chunks-cjs/selection-point.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_isEqualSelectionPoints = require("../_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("../_chunks-cjs/util.selection-point-to-block-offset.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
function isEqualSelections(a, b) {
return !a && !b ? !0 : !a || !b ? !1 : util_isEqualSelectionPoints.isEqualSelectionPoints(a.anchor, b.anchor) && util_isEqualSelectionPoints.isEqualSelectionPoints(a.focus, b.focus);
}
function reverseSelection(selection) {
return selection && (selection.backward ? {
anchor: selection.focus,
focus: selection.anchor,
backward: !1
} : {
anchor: selection.focus,
focus: selection.anchor,
backward: !0
});
}
function splitTextBlock({
context,
block,
point
}) {
const firstChild = block.children.at(0), lastChild = block.children.at(block.children.length - 1);
if (!firstChild || !lastChild)
return;
const before = selectionPoint.sliceBlocks({
context: {
schema: context.schema,
selection: {
anchor: {
path: [{
_key: block._key
}, "children", {
_key: firstChild._key
}],
offset: 0
},
focus: point
}
},
blocks: [block]
}).at(0), after = selectionPoint.sliceBlocks({
context: {
schema: context.schema,
selection: {
anchor: point,
focus: {
path: [{
_key: block._key
}, "children", {
_key: lastChild._key
}],
offset: selectionPoint.isSpan(context, lastChild) ? lastChild.text.length : 0
}
}
},
blocks: [block]
}).at(0);
if (!(!before || !after) && !(!util_mergeTextBlocks.isTextBlock(context, before) || !util_mergeTextBlocks.isTextBlock(context, after)))
return {
before,
after
};
}
exports.blockOffsetToSpanSelectionPoint = selectionPoint.blockOffsetToSpanSelectionPoint;
exports.getBlockStartPoint = selectionPoint.getBlockStartPoint;
exports.getSelectionEndPoint = selectionPoint.getSelectionEndPoint;
exports.getSelectionStartPoint = selectionPoint.getSelectionStartPoint;
exports.getTextBlockText = selectionPoint.getTextBlockText;
exports.isKeyedSegment = selectionPoint.isKeyedSegment;
exports.isSpan = selectionPoint.isSpan;
exports.sliceBlocks = selectionPoint.sliceBlocks;
exports.spanSelectionPointToBlockOffset = selectionPoint.spanSelectionPointToBlockOffset;
exports.blockOffsetToBlockSelectionPoint = util_childSelectionPointToBlockOffset.blockOffsetToBlockSelectionPoint;
exports.blockOffsetToSelectionPoint = util_childSelectionPointToBlockOffset.blockOffsetToSelectionPoint;
exports.blockOffsetsToSelection = util_childSelectionPointToBlockOffset.blockOffsetsToSelection;
exports.childSelectionPointToBlockOffset = util_childSelectionPointToBlockOffset.childSelectionPointToBlockOffset;
exports.getBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint;
exports.isEmptyTextBlock = util_isEqualSelectionPoints.isEmptyTextBlock;
exports.isEqualSelectionPoints = util_isEqualSelectionPoints.isEqualSelectionPoints;
exports.isSelectionCollapsed = util_selectionPointToBlockOffset.isSelectionCollapsed;
exports.selectionPointToBlockOffset = util_selectionPointToBlockOffset.selectionPointToBlockOffset;
exports.isTextBlock = util_mergeTextBlocks.isTextBlock;
exports.mergeTextBlocks = util_mergeTextBlocks.mergeTextBlocks;
exports.isEqualSelections = isEqualSelections;
exports.reverseSelection = reverseSelection;
exports.splitTextBlock = splitTextBlock;
//# sourceMappingURL=index.cjs.map