UNPKG

@portabletext/editor

Version:

Portable Text Editor made in React

27 lines (26 loc) 1.03 kB
"use strict"; var util_sliceBlocks = require("./util.slice-blocks.cjs"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"); const getBlockTextBefore = (snapshot) => { if (!snapshot.context.selection) return ""; const point = (snapshot.context.selection.backward ? util_sliceBlocks.reverseSelection(snapshot.context.selection) : snapshot.context.selection).anchor, key = util_sliceBlocks.isKeyedSegment(point.path[0]) ? point.path[0]._key : void 0, block = key ? snapshot.context.value.find((block2) => block2._key === key) : void 0; if (!block) return ""; const startOfBlock = util_sliceBlocks.getBlockStartPoint({ node: block, path: [{ _key: block._key }] }); return selector_isOverlappingSelection.getSelectionText({ context: { ...snapshot.context, selection: { anchor: startOfBlock, focus: point } } }); }; exports.getBlockTextBefore = getBlockTextBefore; //# sourceMappingURL=selector.get-text-before.cjs.map