@portabletext/editor 1.15.0 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,10 @@ function createGuards({
16
16
  }
17
17
  const selectionIsCollapsed = ({
18
18
  context
19
- }) => JSON.stringify(context.selection?.anchor.path) === JSON.stringify(context.selection?.focus.path) && context.selection?.anchor.offset === context.selection?.focus.offset, getFocusBlock = ({
19
+ }) => {
20
+ var _a, _b, _c, _d;
21
+ return JSON.stringify((_a = context.selection) == null ? void 0 : _a.anchor.path) === JSON.stringify((_b = context.selection) == null ? void 0 : _b.focus.path) && ((_c = context.selection) == null ? void 0 : _c.anchor.offset) === ((_d = context.selection) == null ? void 0 : _d.focus.offset);
22
+ }, getFocusBlock = ({
20
23
  context
21
24
  }) => {
22
25
  const key = context.selection && types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
@@ -275,7 +278,16 @@ const getSelectionText = ({
275
278
  break;
276
279
  }
277
280
  return text;
278
- }, getBlockTextBefore = ({
281
+ };
282
+ var __defProp = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols = Object.getOwnPropertySymbols, __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
283
+ for (var prop in b || (b = {}))
284
+ __hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
285
+ if (__getOwnPropSymbols)
286
+ for (var prop of __getOwnPropSymbols(b))
287
+ __propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
288
+ return a;
289
+ }, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
290
+ const getBlockTextBefore = ({
279
291
  context
280
292
  }) => {
281
293
  if (!context.selection)
@@ -290,14 +302,13 @@ const getSelectionText = ({
290
302
  }]
291
303
  });
292
304
  return getSelectionText({
293
- context: {
294
- ...context,
305
+ context: __spreadProps(__spreadValues({}, context), {
295
306
  value: context.value,
296
307
  selection: {
297
308
  anchor: startOfBlock,
298
309
  focus: point
299
310
  }
300
- }
311
+ })
301
312
  });
302
313
  };
303
314
  exports.createGuards = createGuards;
@@ -1 +1 @@
1
- {"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/editor/behavior/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/editor/utils/utils.get-start-point.ts","../../src/editor/utils/utils.is-keyed-segment.ts","../../src/editor/utils/utils.reverse-selection.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {PortableTextMemberSchemaTypes} from '../../types/editor'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({\n schema,\n}: {\n schema: PortableTextMemberSchemaTypes\n}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../editor/behavior/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @alpha\n */\nexport const selectionIsCollapsed: EditorSelector<boolean> = ({context}) => {\n return (\n JSON.stringify(context.selection?.anchor.path) ===\n JSON.stringify(context.selection?.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n\n/**\n * @alpha\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @alpha\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @alpha\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../../types/editor'\n\nexport function getStartPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n return {\n path: [...path, 'children', {_key: node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import type {KeyedSegment, PathSegment} from '@sanity/types'\n\nexport function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {EditorSelection} from '../../types/editor'\n\nexport function reverseSelection(\n selection: NonNullable<EditorSelection>,\n): NonNullable<EditorSelection> {\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n }\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n }\n}\n","import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'\nimport {reverseSelection} from '../editor/utils/utils.reverse-selection'\n\n/**\n * @alpha\n */\nexport const getSelectionText: EditorSelector<string> = ({context}) => {\n let text = ''\n\n const {value, selection} = context\n\n if (!value || !selection) {\n return text\n }\n\n const forwardSelection = selection.backward\n ? reverseSelection(selection)\n : selection\n\n if (!forwardSelection) {\n return text\n }\n\n for (const block of value) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[0]) &&\n block._key !== forwardSelection.anchor.path[0]._key\n ) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (isPortableTextSpan(child)) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key &&\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text =\n text +\n child.text.slice(\n forwardSelection.anchor.offset,\n forwardSelection.focus.offset,\n )\n\n break\n }\n\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key\n ) {\n text = text + child.text.slice(forwardSelection.anchor.offset)\n continue\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text = text + child.text.slice(0, forwardSelection.focus.offset)\n break\n }\n\n if (text.length > 0) {\n text + child.text\n }\n }\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[0]) &&\n block._key === forwardSelection.focus.path[0]._key\n ) {\n break\n }\n }\n\n return text\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getStartPoint} from '../editor/utils/utils.get-start-point'\nimport {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'\nimport {reverseSelection} from '../editor/utils/utils.reverse-selection'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @alpha\n */\nexport const getBlockTextBefore: EditorSelector<string> = ({context}) => {\n if (!context.selection) {\n return ''\n }\n\n const selection = context.selection.backward\n ? reverseSelection(context.selection)\n : context.selection\n const point = selection.anchor\n const key = isKeyedSegment(point.path[0]) ? point.path[0]._key : undefined\n\n const block = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getStartPoint({node: block, path: [{_key: block._key}]})\n\n return getSelectionText({\n context: {\n ...context,\n value: context.value,\n selection: {\n anchor: startOfBlock,\n focus: point,\n },\n },\n })\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","selectionIsCollapsed","context","JSON","stringify","selection","anchor","path","focus","offset","getFocusBlock","key","isKeySegment","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getStartPoint","isKeyedSegment","segment","reverseSelection","getSelectionText","text","forwardSelection","child","slice","getBlockTextBefore","point","startOfBlock"],"mappings":";;AAaO,SAASA,aAAa;AAAA,EAC3BC;AAGF,GAAG;AACD,WAASC,YAAYC,OAAgD;AACnE,WAAOC,MAAAA,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,MAAAA,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACVO,MAAME,uBAAgDA,CAAC;AAAA,EAACC;AAAO,MAElEC,KAAKC,UAAUF,QAAQG,WAAWC,OAAOC,IAAI,MAC3CJ,KAAKC,UAAUF,QAAQG,WAAWG,MAAMD,IAAI,KAC9CL,QAAQG,WAAWC,OAAOG,WAAWP,QAAQG,WAAWG,MAAMC,QAOrDC,gBAETA,CAAC;AAAA,EAACR;AAAO,MAAM;AACjB,QAAMS,MAAMT,QAAQG,aAChBO,MAAAA,aAAaV,QAAQG,UAAUG,MAAMD,KAAK,CAAC,CAAC,IAC1CL,QAAQG,UAAUG,MAAMD,KAAK,CAAC,EAAEM,OAElCC,QA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;"}
1
+ {"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/editor/behavior/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/editor/utils/utils.get-start-point.ts","../../src/editor/utils/utils.is-keyed-segment.ts","../../src/editor/utils/utils.reverse-selection.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {PortableTextMemberSchemaTypes} from '../../types/editor'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({\n schema,\n}: {\n schema: PortableTextMemberSchemaTypes\n}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../editor/behavior/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @alpha\n */\nexport const selectionIsCollapsed: EditorSelector<boolean> = ({context}) => {\n return (\n JSON.stringify(context.selection?.anchor.path) ===\n JSON.stringify(context.selection?.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n\n/**\n * @alpha\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @alpha\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @alpha\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../../types/editor'\n\nexport function getStartPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n return {\n path: [...path, 'children', {_key: node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import type {KeyedSegment, PathSegment} from '@sanity/types'\n\nexport function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {EditorSelection} from '../../types/editor'\n\nexport function reverseSelection(\n selection: NonNullable<EditorSelection>,\n): NonNullable<EditorSelection> {\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n }\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n }\n}\n","import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'\nimport {reverseSelection} from '../editor/utils/utils.reverse-selection'\n\n/**\n * @alpha\n */\nexport const getSelectionText: EditorSelector<string> = ({context}) => {\n let text = ''\n\n const {value, selection} = context\n\n if (!value || !selection) {\n return text\n }\n\n const forwardSelection = selection.backward\n ? reverseSelection(selection)\n : selection\n\n if (!forwardSelection) {\n return text\n }\n\n for (const block of value) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[0]) &&\n block._key !== forwardSelection.anchor.path[0]._key\n ) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (isPortableTextSpan(child)) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key &&\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text =\n text +\n child.text.slice(\n forwardSelection.anchor.offset,\n forwardSelection.focus.offset,\n )\n\n break\n }\n\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key\n ) {\n text = text + child.text.slice(forwardSelection.anchor.offset)\n continue\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text = text + child.text.slice(0, forwardSelection.focus.offset)\n break\n }\n\n if (text.length > 0) {\n text + child.text\n }\n }\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[0]) &&\n block._key === forwardSelection.focus.path[0]._key\n ) {\n break\n }\n }\n\n return text\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getStartPoint} from '../editor/utils/utils.get-start-point'\nimport {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'\nimport {reverseSelection} from '../editor/utils/utils.reverse-selection'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @alpha\n */\nexport const getBlockTextBefore: EditorSelector<string> = ({context}) => {\n if (!context.selection) {\n return ''\n }\n\n const selection = context.selection.backward\n ? reverseSelection(context.selection)\n : context.selection\n const point = selection.anchor\n const key = isKeyedSegment(point.path[0]) ? point.path[0]._key : undefined\n\n const block = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getStartPoint({node: block, path: [{_key: block._key}]})\n\n return getSelectionText({\n context: {\n ...context,\n value: context.value,\n selection: {\n anchor: startOfBlock,\n focus: point,\n },\n },\n })\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","selectionIsCollapsed","context","JSON","stringify","selection","anchor","path","focus","offset","getFocusBlock","key","isKeySegment","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getStartPoint","isKeyedSegment","segment","reverseSelection","getSelectionText","text","forwardSelection","child","slice","getBlockTextBefore","point","startOfBlock"],"mappings":";;AAaO,SAASA,aAAa;AAAA,EAC3BC;AAGF,GAAG;AACD,WAASC,YAAYC,OAAgD;AACnE,WAAOC,MAAAA,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,MAAAA,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACVO,MAAME,uBAAgDA,CAAC;AAAA,EAACC;AAAO,MAAM;AAjB5E,MAAA,IAAA,IAAA,IAAA;AAmBIC,SAAAA,KAAKC,WAAUF,KAAAA,QAAQG,cAARH,OAAAA,SAAAA,GAAmBI,OAAOC,IAAI,MAC3CJ,KAAKC,WAAUF,KAAQG,QAAAA,cAARH,mBAAmBM,MAAMD,IAAI,OAC9CL,KAAAA,QAAQG,cAARH,OAAAA,SAAAA,GAAmBI,OAAOG,cAAWP,KAAAA,QAAQG,cAARH,OAAAA,SAAAA,GAAmBM,MAAMC;AAElE,GAKaC,gBAETA,CAAC;AAAA,EAACR;AAAO,MAAM;AACjB,QAAMS,MAAMT,QAAQG,aAChBO,MAAAA,aAAaV,QAAQG,UAAUG,MAAMD,KAAK,CAAC,CAAC,IAC1CL,QAAQG,UAAUG,MAAMD,KAAK,CAAC,EAAEM,OAElCC,QAEEC,OAAOJ,MACTT,QAAQc,MAAMC,KAAMtB,CAAUA,UAAAA,MAAMkB,SAASF,GAAG,IAChDG;AAEJ,SAAOC,QAAQJ,MAAM;AAA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selection?.anchor.path) === JSON.stringify(context.selection?.focus.path) && context.selection?.anchor.offset === context.selection?.focus.offset, getFocusBlock = ({
18
+ }) => {
19
+ var _a, _b, _c, _d;
20
+ return JSON.stringify((_a = context.selection) == null ? void 0 : _a.anchor.path) === JSON.stringify((_b = context.selection) == null ? void 0 : _b.focus.path) && ((_c = context.selection) == null ? void 0 : _c.anchor.offset) === ((_d = context.selection) == null ? void 0 : _d.focus.offset);
21
+ }, getFocusBlock = ({
19
22
  context
20
23
  }) => {
21
24
  const key = context.selection && isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
@@ -274,7 +277,16 @@ const getSelectionText = ({
274
277
  break;
275
278
  }
276
279
  return text;
277
- }, getBlockTextBefore = ({
280
+ };
281
+ var __defProp = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols = Object.getOwnPropertySymbols, __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
282
+ for (var prop in b || (b = {}))
283
+ __hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
284
+ if (__getOwnPropSymbols)
285
+ for (var prop of __getOwnPropSymbols(b))
286
+ __propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
287
+ return a;
288
+ }, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
289
+ const getBlockTextBefore = ({
278
290
  context
279
291
  }) => {
280
292
  if (!context.selection)
@@ -289,14 +301,13 @@ const getSelectionText = ({
289
301
  }]
290
302
  });
291
303
  return getSelectionText({
292
- context: {
293
- ...context,
304
+ context: __spreadProps(__spreadValues({}, context), {
294
305
  value: context.value,
295
306
  selection: {
296
307
  anchor: startOfBlock,
297
308
  focus: point
298
309
  }
299
- }
310
+ })
300
311
  });
301
312
  };
302
313
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"selector.get-text-before.js","sources":["../../src/editor/behavior/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/editor/utils/utils.get-start-point.ts","../../src/editor/utils/utils.is-keyed-segment.ts","../../src/editor/utils/utils.reverse-selection.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {PortableTextMemberSchemaTypes} from '../../types/editor'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({\n schema,\n}: {\n schema: PortableTextMemberSchemaTypes\n}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../editor/behavior/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @alpha\n */\nexport const selectionIsCollapsed: EditorSelector<boolean> = ({context}) => {\n return (\n JSON.stringify(context.selection?.anchor.path) ===\n JSON.stringify(context.selection?.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n\n/**\n * @alpha\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @alpha\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @alpha\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../../types/editor'\n\nexport function getStartPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n return {\n path: [...path, 'children', {_key: node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import type {KeyedSegment, PathSegment} from '@sanity/types'\n\nexport function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {EditorSelection} from '../../types/editor'\n\nexport function reverseSelection(\n selection: NonNullable<EditorSelection>,\n): NonNullable<EditorSelection> {\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n }\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n }\n}\n","import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'\nimport {reverseSelection} from '../editor/utils/utils.reverse-selection'\n\n/**\n * @alpha\n */\nexport const getSelectionText: EditorSelector<string> = ({context}) => {\n let text = ''\n\n const {value, selection} = context\n\n if (!value || !selection) {\n return text\n }\n\n const forwardSelection = selection.backward\n ? reverseSelection(selection)\n : selection\n\n if (!forwardSelection) {\n return text\n }\n\n for (const block of value) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[0]) &&\n block._key !== forwardSelection.anchor.path[0]._key\n ) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (isPortableTextSpan(child)) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key &&\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text =\n text +\n child.text.slice(\n forwardSelection.anchor.offset,\n forwardSelection.focus.offset,\n )\n\n break\n }\n\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key\n ) {\n text = text + child.text.slice(forwardSelection.anchor.offset)\n continue\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text = text + child.text.slice(0, forwardSelection.focus.offset)\n break\n }\n\n if (text.length > 0) {\n text + child.text\n }\n }\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[0]) &&\n block._key === forwardSelection.focus.path[0]._key\n ) {\n break\n }\n }\n\n return text\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getStartPoint} from '../editor/utils/utils.get-start-point'\nimport {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'\nimport {reverseSelection} from '../editor/utils/utils.reverse-selection'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @alpha\n */\nexport const getBlockTextBefore: EditorSelector<string> = ({context}) => {\n if (!context.selection) {\n return ''\n }\n\n const selection = context.selection.backward\n ? reverseSelection(context.selection)\n : context.selection\n const point = selection.anchor\n const key = isKeyedSegment(point.path[0]) ? point.path[0]._key : undefined\n\n const block = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getStartPoint({node: block, path: [{_key: block._key}]})\n\n return getSelectionText({\n context: {\n ...context,\n value: context.value,\n selection: {\n anchor: startOfBlock,\n focus: point,\n },\n },\n })\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","selectionIsCollapsed","context","JSON","stringify","selection","anchor","path","focus","offset","getFocusBlock","key","isKeySegment","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getStartPoint","isKeyedSegment","segment","reverseSelection","getSelectionText","text","forwardSelection","child","slice","getBlockTextBefore","point","startOfBlock"],"mappings":";AAaO,SAASA,aAAa;AAAA,EAC3BC;AAGF,GAAG;AACD,WAASC,YAAYC,OAAgD;AACnE,WAAOC,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACVO,MAAME,uBAAgDA,CAAC;AAAA,EAACC;AAAO,MAElEC,KAAKC,UAAUF,QAAQG,WAAWC,OAAOC,IAAI,MAC3CJ,KAAKC,UAAUF,QAAQG,WAAWG,MAAMD,IAAI,KAC9CL,QAAQG,WAAWC,OAAOG,WAAWP,QAAQG,WAAWG,MAAMC,QAOrDC,gBAETA,CAAC;AAAA,EAACR;AAAO,MAAM;AACjB,QAAMS,MAAMT,QAAQG,aAChBO,aAAaV,QAAQG,UAAUG,MAAMD,KAAK,CAAC,CAAC,IAC1CL,QAAQG,UAAUG,MAAMD,KAAK,CAAC,EAAEM,OAElCC,QAEEC,OAAOJ,MACTT,QAAQc,MAAMC,KAAMtB,CAAUA,UAAAA,MAAMkB,SAASF,GAAG,IAChDG;AAEJ,SAAOC,QAAQJ,MAAM;AAAA,IAACI;AAAAA,IAAMR,MAAM,CAAC;AAAA,MAACM,MAAMF;AAAAA,IAAI,CAAA;AAAA,EAAKG,IAAAA;AACrD,GAKaI,oBAETA,CAAC;AA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4C;AAKnB,UACEJ,eAAeK,iBAAiB9C,MAAMD,KAAK,CAAC,CAAC,KAC7CZ,MAAMkB,SAASyC,iBAAiB9C,MAAMD,KAAK,CAAC,EAAEM;AAE9C;AAAA,IAAA;AAIGwC,SAAAA;AACT,GC7EaI,qBAA6CA,CAAC;AAAA,EAACvD;AAAO,MAAM;AACvE,MAAI,CAACA,QAAQG;AACJ,WAAA;AAMT,QAAMqD,SAHYxD,QAAQG,UAAU8B,WAChCgB,iBAAiBjD,QAAQG,SAAS,IAClCH,QAAQG,WACYC,QAClBK,MAAMsC,eAAeS,MAAMnD,KAAK,CAAC,CAAC,IAAImD,MAAMnD,KAAK,CAAC,EAAEM,OAAOC,QAE3DnB,QAAQgB,MACVT,QAAQc,MAAMC,KAAMtB,CAAAA,WAAUA,OAAMkB,SAASF,GAAG,IAChDG;AAEJ,MAAI,CAACnB;AACI,WAAA;AAGT,QAAMgE,eAAeX,cAAc;AAAA,IAACjC,MAAMpB;AAAAA,IAAOY,MAAM,CAAC;AAAA,MAACM,MAAMlB,MAAMkB;AAAAA,IAAK,CAAA;AAAA,EAAA,CAAE;AAE5E,SAAOuC,iBAAiB;AAAA,IACtBlD,SAAS;AAAA,MACP,GAAGA;AAAAA,MACHc,OAAOd,QAAQc;AAAAA,MACfX,WAAW;AAAA,QACTC,QAAQqD;AAAAA,QACRnD,OAAOkD;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;"}
1
+ {"version":3,"file":"selector.get-text-before.js","sources":["../../src/editor/behavior/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/editor/utils/utils.get-start-point.ts","../../src/editor/utils/utils.is-keyed-segment.ts","../../src/editor/utils/utils.reverse-selection.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {PortableTextMemberSchemaTypes} from '../../types/editor'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({\n schema,\n}: {\n schema: PortableTextMemberSchemaTypes\n}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../editor/behavior/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @alpha\n */\nexport const selectionIsCollapsed: EditorSelector<boolean> = ({context}) => {\n return (\n JSON.stringify(context.selection?.anchor.path) ===\n JSON.stringify(context.selection?.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n\n/**\n * @alpha\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @alpha\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @alpha\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @alpha\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @alpha\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../../types/editor'\n\nexport function getStartPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n return {\n path: [...path, 'children', {_key: node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import type {KeyedSegment, PathSegment} from '@sanity/types'\n\nexport function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {EditorSelection} from '../../types/editor'\n\nexport function reverseSelection(\n selection: NonNullable<EditorSelection>,\n): NonNullable<EditorSelection> {\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n }\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n }\n}\n","import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'\nimport {reverseSelection} from '../editor/utils/utils.reverse-selection'\n\n/**\n * @alpha\n */\nexport const getSelectionText: EditorSelector<string> = ({context}) => {\n let text = ''\n\n const {value, selection} = context\n\n if (!value || !selection) {\n return text\n }\n\n const forwardSelection = selection.backward\n ? reverseSelection(selection)\n : selection\n\n if (!forwardSelection) {\n return text\n }\n\n for (const block of value) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[0]) &&\n block._key !== forwardSelection.anchor.path[0]._key\n ) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (isPortableTextSpan(child)) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key &&\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text =\n text +\n child.text.slice(\n forwardSelection.anchor.offset,\n forwardSelection.focus.offset,\n )\n\n break\n }\n\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key\n ) {\n text = text + child.text.slice(forwardSelection.anchor.offset)\n continue\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text = text + child.text.slice(0, forwardSelection.focus.offset)\n break\n }\n\n if (text.length > 0) {\n text + child.text\n }\n }\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[0]) &&\n block._key === forwardSelection.focus.path[0]._key\n ) {\n break\n }\n }\n\n return text\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getStartPoint} from '../editor/utils/utils.get-start-point'\nimport {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'\nimport {reverseSelection} from '../editor/utils/utils.reverse-selection'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @alpha\n */\nexport const getBlockTextBefore: EditorSelector<string> = ({context}) => {\n if (!context.selection) {\n return ''\n }\n\n const selection = context.selection.backward\n ? reverseSelection(context.selection)\n : context.selection\n const point = selection.anchor\n const key = isKeyedSegment(point.path[0]) ? point.path[0]._key : undefined\n\n const block = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getStartPoint({node: block, path: [{_key: block._key}]})\n\n return getSelectionText({\n context: {\n ...context,\n value: context.value,\n selection: {\n anchor: startOfBlock,\n focus: point,\n },\n },\n })\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","selectionIsCollapsed","context","JSON","stringify","selection","anchor","path","focus","offset","getFocusBlock","key","isKeySegment","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getStartPoint","isKeyedSegment","segment","reverseSelection","getSelectionText","text","forwardSelection","child","slice","getBlockTextBefore","point","startOfBlock"],"mappings":";AAaO,SAASA,aAAa;AAAA,EAC3BC;AAGF,GAAG;AACD,WAASC,YAAYC,OAAgD;AACnE,WAAOC,wBAAwBD,KAAK,KAAKA,MAAME,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