@portabletext/editor
Version:
Portable Text Editor made in React
80 lines (79 loc) • 2.61 kB
JavaScript
import { isEqualSelectionPoints, sliceBlocks, isSpan } from "../_chunks-es/util.slice-blocks.js";
import { blockOffsetToSpanSelectionPoint, getBlockEndPoint, getBlockStartPoint, getTextBlockText, isEmptyTextBlock, isKeyedSegment, reverseSelection, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
import { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset, selectionPointToBlockOffset } from "../_chunks-es/util.selection-point-to-block-offset.js";
import { getSelectionEndPoint, isSelectionCollapsed } from "../_chunks-es/util.is-selection-collapsed.js";
import { isTextBlock } from "../_chunks-es/util.merge-text-blocks.js";
import { mergeTextBlocks } from "../_chunks-es/util.merge-text-blocks.js";
function getSelectionStartPoint(selection) {
return selection ? selection.backward ? selection.focus : selection.anchor : null;
}
function isEqualSelections(a, b) {
return !a && !b ? !0 : !a || !b ? !1 : isEqualSelectionPoints(a.anchor, b.anchor) && isEqualSelectionPoints(a.focus, b.focus);
}
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 = sliceBlocks({
blocks: [block],
selection: {
anchor: {
path: [{
_key: block._key
}, "children", {
_key: firstChild._key
}],
offset: 0
},
focus: point
}
}).at(0), after = sliceBlocks({
blocks: [block],
selection: {
anchor: point,
focus: {
path: [{
_key: block._key
}, "children", {
_key: lastChild._key
}],
offset: isSpan(context, lastChild) ? lastChild.text.length : 0
}
}
}).at(0);
if (!(!before || !after) && !(!isTextBlock(context, before) || !isTextBlock(context, after)))
return {
before,
after
};
}
export {
blockOffsetToBlockSelectionPoint,
blockOffsetToSelectionPoint,
blockOffsetToSpanSelectionPoint,
blockOffsetsToSelection,
childSelectionPointToBlockOffset,
getBlockEndPoint,
getBlockStartPoint,
getSelectionEndPoint,
getSelectionStartPoint,
getTextBlockText,
isEmptyTextBlock,
isEqualSelectionPoints,
isEqualSelections,
isKeyedSegment,
isSelectionCollapsed,
isSpan,
isTextBlock,
mergeTextBlocks,
reverseSelection,
selectionPointToBlockOffset,
sliceBlocks,
spanSelectionPointToBlockOffset,
splitTextBlock
};
//# sourceMappingURL=index.js.map