@portabletext/editor 1.50.8 → 1.52.0

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.
Files changed (104) hide show
  1. package/lib/_chunks-cjs/{util.slice-blocks.cjs → selection-point.cjs} +26 -18
  2. package/lib/_chunks-cjs/selection-point.cjs.map +1 -0
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +13 -10
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +46 -46
  6. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +21 -17
  8. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
  9. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +10 -10
  10. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
  11. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +5 -5
  12. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
  13. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
  14. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  15. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +7 -14
  16. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  17. package/lib/_chunks-es/{util.slice-blocks.js → selection-point.js} +26 -18
  18. package/lib/_chunks-es/selection-point.js.map +1 -0
  19. package/lib/_chunks-es/selector.get-text-before.js +13 -10
  20. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  21. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +21 -21
  22. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  23. package/lib/_chunks-es/selector.is-selection-expanded.js +14 -10
  24. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
  25. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +2 -2
  26. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
  27. package/lib/_chunks-es/util.is-equal-selection-points.js +1 -1
  28. package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
  29. package/lib/_chunks-es/util.selection-point-to-block-offset.js +4 -11
  30. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  31. package/lib/behaviors/index.cjs.map +1 -1
  32. package/lib/behaviors/index.d.cts +25 -2010
  33. package/lib/behaviors/index.d.ts +25 -2010
  34. package/lib/behaviors/index.js.map +1 -1
  35. package/lib/index.cjs +515 -393
  36. package/lib/index.cjs.map +1 -1
  37. package/lib/index.d.cts +361 -34
  38. package/lib/index.d.ts +361 -34
  39. package/lib/index.js +471 -349
  40. package/lib/index.js.map +1 -1
  41. package/lib/plugins/index.cjs +11 -11
  42. package/lib/plugins/index.cjs.map +1 -1
  43. package/lib/plugins/index.d.cts +32 -1986
  44. package/lib/plugins/index.d.ts +32 -1986
  45. package/lib/plugins/index.js +1 -1
  46. package/lib/selectors/index.cjs +11 -7
  47. package/lib/selectors/index.cjs.map +1 -1
  48. package/lib/selectors/index.d.cts +2 -2648
  49. package/lib/selectors/index.d.ts +2 -2648
  50. package/lib/selectors/index.js +7 -3
  51. package/lib/selectors/index.js.map +1 -1
  52. package/lib/utils/index.cjs +25 -14
  53. package/lib/utils/index.cjs.map +1 -1
  54. package/lib/utils/index.d.cts +0 -2647
  55. package/lib/utils/index.d.ts +0 -2647
  56. package/lib/utils/index.js +14 -3
  57. package/lib/utils/index.js.map +1 -1
  58. package/package.json +14 -14
  59. package/src/behaviors/behavior.abstract.delete.ts +0 -2
  60. package/src/behaviors/behavior.abstract.insert.ts +8 -8
  61. package/src/behaviors/behavior.abstract.ts +0 -113
  62. package/src/behaviors/behavior.core.block-element.ts +9 -3
  63. package/src/behaviors/behavior.core.dnd.ts +328 -1
  64. package/src/behaviors/behavior.perform-event.ts +10 -0
  65. package/src/behaviors/behavior.types.action.ts +2 -0
  66. package/src/behaviors/behavior.types.event.ts +5 -0
  67. package/src/behaviors/behavior.types.guard.ts +2 -0
  68. package/src/converters/converter.portable-text.ts +2 -7
  69. package/src/converters/converter.text-html.ts +1 -3
  70. package/src/converters/converter.text-plain.ts +3 -5
  71. package/src/editor/Editable.tsx +6 -133
  72. package/src/editor/editor-machine.ts +15 -10
  73. package/src/editor/editor-selector.ts +0 -2
  74. package/src/editor/editor-snapshot.ts +0 -18
  75. package/src/internal-utils/create-test-snapshot.ts +0 -2
  76. package/src/internal-utils/event-position.ts +42 -30
  77. package/src/internal-utils/selection-block-keys.ts +7 -7
  78. package/src/internal-utils/selection-elements.ts +108 -0
  79. package/src/internal-utils/selection-focus-text.ts +13 -9
  80. package/src/internal-utils/selection-text.ts +9 -78
  81. package/src/internal-utils/terse-pt.test.ts +108 -26
  82. package/src/internal-utils/terse-pt.ts +132 -14
  83. package/src/operations/behavior.operation.decorator.add.ts +0 -2
  84. package/src/operations/behavior.operation.delete.ts +18 -13
  85. package/src/operations/behavior.operation.insert.block.ts +5 -1
  86. package/src/selection/selection-point.ts +22 -0
  87. package/src/selectors/selector.get-anchor-block.ts +6 -6
  88. package/src/selectors/selector.get-anchor-child.ts +6 -6
  89. package/src/selectors/selector.get-selected-spans.ts +16 -19
  90. package/src/selectors/selector.get-selected-text-blocks.ts +11 -19
  91. package/src/selectors/selector.get-selection-end-block.ts +30 -0
  92. package/src/selectors/selector.get-selection-start-block.ts +30 -0
  93. package/src/selectors/selector.get-text-before.ts +15 -16
  94. package/src/selectors/selector.get-trimmed-selection.ts +15 -21
  95. package/src/selectors/selector.is-point-after-selection.ts +11 -19
  96. package/src/selectors/selector.is-point-before-selection.ts +11 -19
  97. package/src/selectors/selectors.ts +23 -39
  98. package/src/utils/util.block-offset.ts +6 -7
  99. package/src/utils/util.child-selection-point-to-block-offset.ts +6 -7
  100. package/src/utils/util.selection-point-to-block-offset.ts +5 -6
  101. package/src/utils/util.slice-blocks.ts +11 -20
  102. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
  103. package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
  104. package/src/internal-utils/inline-object-selection.ts +0 -115
@@ -230,9 +230,6 @@ function parseObject({
230
230
  ...values
231
231
  };
232
232
  }
233
- function isKeyedSegment(segment) {
234
- return typeof segment == "object" && segment !== null && "_key" in segment;
235
- }
236
233
  function blockOffsetToSpanSelectionPoint({
237
234
  context,
238
235
  blockOffset,
@@ -289,7 +286,7 @@ function spanSelectionPointToBlockOffset({
289
286
  selectionPoint
290
287
  }) {
291
288
  let offset = 0;
292
- const blockKey = isKeyedSegment(selectionPoint.path[0]) ? selectionPoint.path[0]._key : void 0, spanKey = isKeyedSegment(selectionPoint.path[2]) ? selectionPoint.path[2]._key : void 0;
289
+ const blockKey = getBlockKeyFromSelectionPoint(selectionPoint), spanKey = getChildKeyFromSelectionPoint(selectionPoint);
293
290
  if (!(!blockKey || !spanKey)) {
294
291
  for (const block of context.value)
295
292
  if (block._key === blockKey && isTextBlock(context, block)) {
@@ -321,23 +318,21 @@ function getBlockStartPoint({
321
318
  offset: 0
322
319
  };
323
320
  }
321
+ function getSelectionEndPoint(selection) {
322
+ return selection ? selection.backward ? selection.anchor : selection.focus : null;
323
+ }
324
+ function getSelectionStartPoint(selection) {
325
+ return selection ? selection.backward ? selection.focus : selection.anchor : null;
326
+ }
324
327
  function getTextBlockText(block) {
325
328
  return block.children.map((child) => child.text ?? "").join("");
326
329
  }
330
+ function isKeyedSegment(segment) {
331
+ return typeof segment == "object" && segment !== null && "_key" in segment;
332
+ }
327
333
  function isSpan(context, child) {
328
334
  return child._type === context.schema.span.name;
329
335
  }
330
- function reverseSelection(selection) {
331
- return selection && (selection.backward ? {
332
- anchor: selection.focus,
333
- focus: selection.anchor,
334
- backward: !1
335
- } : {
336
- anchor: selection.focus,
337
- focus: selection.anchor,
338
- backward: !0
339
- });
340
- }
341
336
  function sliceBlocks({
342
337
  context,
343
338
  blocks
@@ -348,7 +343,7 @@ function sliceBlocks({
348
343
  let startBlock;
349
344
  const middleBlocks = [];
350
345
  let endBlock;
351
- const startPoint = context.selection.backward ? context.selection.focus : context.selection.anchor, endPoint = context.selection.backward ? context.selection.anchor : context.selection.focus, startBlockKey = isKeyedSegment(startPoint.path[0]) ? startPoint.path[0]._key : void 0, endBlockKey = isKeyedSegment(endPoint.path[0]) ? endPoint.path[0]._key : void 0, startChildKey = isKeyedSegment(startPoint.path[2]) ? startPoint.path[2]._key : void 0, endChildKey = isKeyedSegment(endPoint.path[2]) ? endPoint.path[2]._key : void 0;
346
+ const startPoint = getSelectionStartPoint(context.selection), endPoint = getSelectionEndPoint(context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint);
352
347
  if (!startBlockKey || !endBlockKey)
353
348
  return slice;
354
349
  for (const block of blocks) {
@@ -426,8 +421,22 @@ function sliceBlocks({
426
421
  }
427
422
  return [...startBlock ? [startBlock] : [], ...middleBlocks, ...endBlock ? [endBlock] : []];
428
423
  }
424
+ function getBlockKeyFromSelectionPoint(point) {
425
+ const blockPathSegment = point.path.at(0);
426
+ if (isKeyedSegment(blockPathSegment))
427
+ return blockPathSegment._key;
428
+ }
429
+ function getChildKeyFromSelectionPoint(point) {
430
+ const childPathSegment = point.path.at(2);
431
+ if (isKeyedSegment(childPathSegment))
432
+ return childPathSegment._key;
433
+ }
429
434
  exports.blockOffsetToSpanSelectionPoint = blockOffsetToSpanSelectionPoint;
435
+ exports.getBlockKeyFromSelectionPoint = getBlockKeyFromSelectionPoint;
430
436
  exports.getBlockStartPoint = getBlockStartPoint;
437
+ exports.getChildKeyFromSelectionPoint = getChildKeyFromSelectionPoint;
438
+ exports.getSelectionEndPoint = getSelectionEndPoint;
439
+ exports.getSelectionStartPoint = getSelectionStartPoint;
431
440
  exports.getTextBlockText = getTextBlockText;
432
441
  exports.isKeyedSegment = isKeyedSegment;
433
442
  exports.isListBlock = isListBlock;
@@ -441,7 +450,6 @@ exports.parseBlockObject = parseBlockObject;
441
450
  exports.parseBlocks = parseBlocks;
442
451
  exports.parseInlineObject = parseInlineObject;
443
452
  exports.parseTextBlock = parseTextBlock;
444
- exports.reverseSelection = reverseSelection;
445
453
  exports.sliceBlocks = sliceBlocks;
446
454
  exports.spanSelectionPointToBlockOffset = spanSelectionPointToBlockOffset;
447
- //# sourceMappingURL=util.slice-blocks.cjs.map
455
+ //# sourceMappingURL=selection-point.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection-point.cjs","sources":["../../src/internal-utils/asserters.ts","../../src/internal-utils/parse-blocks.ts","../../src/utils/util.block-offset.ts","../../src/utils/util.get-block-start-point.ts","../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.get-text-block-text.ts","../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.is-span.ts","../../src/utils/util.slice-blocks.ts","../../src/selection/selection-point.ts"],"sourcesContent":["import type {TypedObject} from '@sanity/types'\n\nexport function isTypedObject(object: unknown): object is TypedObject {\n return isRecord(object) && typeof object._type === 'string'\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n","import type {\n PortableTextBlock,\n PortableTextListBlock,\n PortableTextObject,\n PortableTextSpan,\n PortableTextTextBlock,\n TypedObject,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\n\nexport function parseBlocks({\n context,\n blocks,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n blocks: unknown\n options: {\n refreshKeys: boolean\n validateFields: boolean\n }\n}): Array<PortableTextBlock> {\n if (!Array.isArray(blocks)) {\n return []\n }\n\n return blocks.flatMap((block) => {\n const parsedBlock = parseBlock({context, block, options})\n\n return parsedBlock ? [parsedBlock] : []\n })\n}\n\nexport function parseBlock({\n context,\n block,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n block: unknown\n options: {\n refreshKeys: boolean\n validateFields: boolean\n }\n}): PortableTextBlock | undefined {\n return (\n parseTextBlock({block, context, options}) ??\n parseBlockObject({blockObject: block, context, options})\n )\n}\n\nexport function parseBlockObject({\n blockObject,\n context,\n options,\n}: {\n blockObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(blockObject)) {\n return undefined\n }\n\n const schemaType = context.schema.blockObjects.find(\n ({name}) => name === blockObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: blockObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function isListBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextListBlock {\n return (\n isTextBlock(context, block) &&\n block.level !== undefined &&\n block.listItem !== undefined\n )\n}\n\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextTextBlock {\n return (\n parseTextBlock({\n block,\n context: {schema: context.schema, keyGenerator: () => ''},\n options: {refreshKeys: false, validateFields: false},\n }) !== undefined\n )\n}\n\nexport function parseTextBlock({\n block,\n context,\n options,\n}: {\n block: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextTextBlock | undefined {\n if (!isTypedObject(block)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(block)) {\n if (\n key !== '_type' &&\n key !== '_key' &&\n key !== 'children' &&\n key !== 'markDefs' &&\n key !== 'style' &&\n key !== 'listItem' &&\n key !== 'level'\n ) {\n customFields[key] = block[key]\n }\n }\n\n if (block._type !== context.schema.block.name) {\n return undefined\n }\n\n const _key = options.refreshKeys\n ? context.keyGenerator()\n : typeof block._key === 'string'\n ? block._key\n : context.keyGenerator()\n\n const unparsedMarkDefs: Array<unknown> = Array.isArray(block.markDefs)\n ? block.markDefs\n : []\n const markDefKeyMap = new Map<string, string>()\n const markDefs = unparsedMarkDefs.flatMap((markDef) => {\n if (!isTypedObject(markDef)) {\n return []\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === markDef._type,\n )\n\n if (!schemaType) {\n return []\n }\n\n if (typeof markDef._key !== 'string') {\n // If the `markDef` doesn't have a `_key` then we don't know what spans\n // it belongs to and therefore we have to discard it.\n return []\n }\n\n const parsedAnnotation = parseObject({\n object: markDef,\n context: {\n schemaType,\n keyGenerator: context.keyGenerator,\n },\n options,\n })\n\n if (!parsedAnnotation) {\n return []\n }\n\n markDefKeyMap.set(markDef._key, parsedAnnotation._key)\n\n return [parsedAnnotation]\n })\n\n const unparsedChildren: Array<unknown> = Array.isArray(block.children)\n ? block.children\n : []\n\n const children = unparsedChildren\n .map(\n (child) =>\n parseSpan({span: child, context, markDefKeyMap, options}) ??\n parseInlineObject({inlineObject: child, context, options}),\n )\n .filter((child) => child !== undefined)\n\n const parsedBlock: PortableTextTextBlock = {\n _type: context.schema.block.name,\n _key,\n children:\n children.length > 0\n ? children\n : [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs,\n ...(options.validateFields ? {} : customFields),\n }\n\n if (\n typeof block.style === 'string' &&\n context.schema.styles.find((style) => style.name === block.style)\n ) {\n parsedBlock.style = block.style\n } else {\n const defaultStyle = context.schema.styles.at(0)?.name\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n console.error('Expected default style')\n }\n }\n\n if (\n typeof block.listItem === 'string' &&\n context.schema.lists.find((list) => list.name === block.listItem)\n ) {\n parsedBlock.listItem = block.listItem\n }\n\n if (typeof block.level === 'number') {\n parsedBlock.level = block.level\n }\n\n return parsedBlock\n}\n\nexport function isSpan(\n context: Pick<EditorContext, 'schema'>,\n child: unknown,\n): child is PortableTextSpan {\n return (\n parseSpan({\n span: child,\n markDefKeyMap: new Map(),\n context: {schema: context.schema, keyGenerator: () => ''},\n options: {refreshKeys: false, validateFields: false},\n }) !== undefined\n )\n}\n\nexport function parseSpan({\n span,\n context,\n markDefKeyMap,\n options,\n}: {\n span: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n markDefKeyMap: Map<string, string>\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextSpan | undefined {\n if (!isTypedObject(span)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(span)) {\n if (\n key !== '_type' &&\n key !== '_key' &&\n key !== 'text' &&\n key !== 'marks'\n ) {\n customFields[key] = span[key]\n }\n }\n\n // In reality, the span schema name is always 'span', but we only the check here anyway\n if (span._type !== context.schema.span.name || span._type !== 'span') {\n return undefined\n }\n\n const unparsedMarks: Array<unknown> = Array.isArray(span.marks)\n ? span.marks\n : []\n const marks = unparsedMarks.flatMap((mark) => {\n if (typeof mark !== 'string') {\n return []\n }\n\n const markDefKey = markDefKeyMap.get(mark)\n\n if (markDefKey !== undefined) {\n return [markDefKey]\n }\n\n if (\n context.schema.decorators.some((decorator) => decorator.name === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return {\n _type: 'span',\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof span._key === 'string'\n ? span._key\n : context.keyGenerator(),\n text: typeof span.text === 'string' ? span.text : '',\n marks,\n ...(options.validateFields ? {} : customFields),\n }\n}\n\nexport function parseInlineObject({\n inlineObject,\n context,\n options,\n}: {\n inlineObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(inlineObject)) {\n return undefined\n }\n\n const schemaType = context.schema.inlineObjects.find(\n ({name}) => name === inlineObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: inlineObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function parseAnnotation({\n annotation,\n context,\n options,\n}: {\n annotation: TypedObject\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(annotation)) {\n return undefined\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === annotation._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: annotation,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nfunction parseObject({\n object,\n context,\n options,\n}: {\n object: TypedObject\n context: Pick<EditorContext, 'keyGenerator'> & {\n schemaType: EditorSchema['blockObjects'][0]\n }\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextObject {\n const {_type, _key, ...customFields} = object\n\n // Validates all props on the object and only takes those that match\n // the name of a field\n const values = options.validateFields\n ? context.schemaType.fields.reduce<Record<string, unknown>>(\n (fieldValues, field) => {\n const fieldValue = object[field.name]\n\n if (fieldValue !== undefined) {\n fieldValues[field.name] = fieldValue\n }\n\n return fieldValues\n },\n {},\n )\n : customFields\n\n return {\n _type: context.schemaType.name,\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof object._key === 'string'\n ? object._key\n : context.keyGenerator(),\n ...values,\n }\n}\n","import type {KeyedSegment} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\n let skippedInlineObject = false\n\n for (const block of context.value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (direction === 'forward') {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n\n continue\n }\n\n if (!isSpan(context, child)) {\n skippedInlineObject = true\n continue\n }\n\n if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {\n if (skippedInlineObject) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n }\n break\n }\n\n if (offsetLeft > child.text.length) {\n offsetLeft -= child.text.length\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n\n offsetLeft -= child.text.length\n\n if (offsetLeft !== 0) {\n break\n }\n }\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n const spanKey = getChildKeyFromSelectionPoint(selectionPoint)\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n return {\n path: [...block.path, 'children', {_key: block.node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionStartPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.focus : selection.anchor\n ) as TEditorSelectionPoint\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","import type {KeyedSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: unknown): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {PortableTextChild, PortableTextSpan} from '@sanity/types'\nimport type {EditorContext} from '..'\n\n/**\n * @public\n */\nexport function isSpan(\n context: Pick<EditorContext, 'schema'>,\n child: PortableTextChild,\n): child is PortableTextSpan {\n return child._type === context.schema.span.name\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport {getSelectionEndPoint, getSelectionStartPoint} from '../utils'\n\n/**\n * @public\n */\nexport function sliceBlocks({\n context,\n blocks,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n blocks: Array<PortableTextBlock>\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!context.selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (!isTextBlock(context, block)) {\n if (block._key === startBlockKey && block._key === endBlockKey) {\n startBlock = block\n break\n }\n }\n\n if (block._key === startBlockKey) {\n if (!isTextBlock(context, block)) {\n startBlock = block\n continue\n }\n\n if (startChildKey) {\n for (const child of block.children) {\n if (child._key === startChildKey) {\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n startBlock = {\n ...block,\n children: [\n {\n ...child,\n text,\n },\n ],\n }\n } else {\n startBlock = {\n ...block,\n children: [child],\n }\n }\n\n if (startChildKey === endChildKey) {\n break\n }\n continue\n }\n\n if (startBlock && isTextBlock(context, startBlock)) {\n if (\n endChildKey &&\n child._key === endChildKey &&\n isSpan(context, child)\n ) {\n startBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n startBlock.children.push(child)\n }\n\n if (\n block._key === endBlockKey &&\n endChildKey &&\n child._key === endChildKey\n ) {\n break\n }\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n startBlock = block\n\n if (startBlockKey === endBlockKey) {\n break\n }\n }\n\n if (block._key === endBlockKey) {\n if (!isTextBlock(context, block)) {\n endBlock = block\n break\n }\n\n if (endChildKey) {\n endBlock = {\n ...block,\n children: [],\n }\n\n for (const child of block.children) {\n if (endBlock && isTextBlock(context, endBlock)) {\n if (child._key === endChildKey && isSpan(context, child)) {\n endBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n\n break\n }\n\n endBlock.children.push(child)\n\n if (endChildKey && child._key === endChildKey) {\n break\n }\n }\n }\n\n break\n }\n\n endBlock = block\n\n break\n }\n\n if (startBlock) {\n middleBlocks.push(block)\n }\n }\n\n return [\n ...(startBlock ? [startBlock] : []),\n ...middleBlocks,\n ...(endBlock ? [endBlock] : []),\n ]\n}\n","import type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from '../utils'\n\nexport function getBlockKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const blockPathSegment = point.path.at(0)\n\n if (isKeyedSegment(blockPathSegment)) {\n return blockPathSegment._key\n }\n\n return undefined\n}\n\nexport function getChildKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const childPathSegment = point.path.at(2)\n\n if (isKeyedSegment(childPathSegment)) {\n return childPathSegment._key\n }\n\n return undefined\n}\n"],"names":["isTypedObject","object","isRecord","_type","value","parseBlocks","context","blocks","options","Array","isArray","flatMap","block","parsedBlock","parseBlock","parseTextBlock","parseBlockObject","blockObject","schemaType","schema","blockObjects","find","name","parseObject","keyGenerator","isListBlock","isTextBlock","level","undefined","listItem","refreshKeys","validateFields","customFields","key","Object","keys","_key","unparsedMarkDefs","markDefs","markDefKeyMap","Map","markDef","annotations","parsedAnnotation","set","children","map","child","parseSpan","span","parseInlineObject","inlineObject","filter","length","text","marks","style","styles","defaultStyle","at","console","error","lists","list","isSpan","mark","markDefKey","get","decorators","some","decorator","inlineObjects","parseAnnotation","annotation","values","fields","reduce","fieldValues","field","fieldValue","blockOffsetToSpanSelectionPoint","blockOffset","direction","offsetLeft","offset","selectionPoint","skippedInlineObject","path","spanSelectionPointToBlockOffset","blockKey","getBlockKeyFromSelectionPoint","spanKey","getChildKeyFromSelectionPoint","getBlockStartPoint","node","getSelectionEndPoint","selection","backward","anchor","focus","getSelectionStartPoint","getTextBlockText","join","isKeyedSegment","segment","sliceBlocks","slice","startBlock","middleBlocks","endBlock","startPoint","endPoint","startBlockKey","startChildKey","endBlockKey","endChildKey","push","point","blockPathSegment","childPathSegment"],"mappings":";AAEO,SAASA,cAAcC,QAAwC;AACpE,SAAOC,SAASD,MAAM,KAAK,OAAOA,OAAOE,SAAU;AACrD;AAEA,SAASD,SAASE,OAAkD;AAClE,SAAO,CAAC,CAACA,UAAU,OAAOA,SAAU,YAAY,OAAOA,SAAU;AACnE;ACIO,SAASC,YAAY;AAAA,EAC1BC;AAAAA,EACAC;AAAAA,EACAC;AAQF,GAA6B;AAC3B,SAAKC,MAAMC,QAAQH,MAAM,IAIlBA,OAAOI,QAASC,CAAU,UAAA;AAC/B,UAAMC,cAAcC,WAAW;AAAA,MAACR;AAAAA,MAASM;AAAAA,MAAOJ;AAAAA,IAAAA,CAAQ;AAExD,WAAOK,cAAc,CAACA,WAAW,IAAI,CAAE;AAAA,EACxC,CAAA,IAPQ,CAAE;AAQb;AAEO,SAASC,WAAW;AAAA,EACzBR;AAAAA,EACAM;AAAAA,EACAJ;AAQF,GA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,eAAepE,MAAMX,SAAS+E;AAChC;AAAA,UAAA;AAKN;AAAA,MAAA;AAGSvG,iBAAAA;AAEX;AAAA,IAAA;AAGE+F,kBACFC,aAAaQ,KAAKxG,KAAK;AAAA,EAAA;AAI3B,SAAO,CACL,GAAI+F,aAAa,CAACA,UAAU,IAAI,CAAA,GAChC,GAAGC,cACH,GAAIC,WAAW,CAACA,QAAQ,IAAI,CAAA,CAAG;AAEnC;ACzKO,SAASnB,8BAA8B2B,OAA6B;AACzE,QAAMC,mBAAmBD,MAAM9B,KAAK5B,GAAG,CAAC;AAExC,MAAI4C,eAAee,gBAAgB;AACjC,WAAOA,iBAAiBlF;AAI5B;AAEO,SAASwD,8BAA8ByB,OAA6B;AACzE,QAAME,mBAAmBF,MAAM9B,KAAK5B,GAAG,CAAC;AAExC,MAAI4C,eAAegB,gBAAgB;AACjC,WAAOA,iBAAiBnF;AAI5B;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,26 +1,29 @@
1
1
  "use strict";
2
- var util_sliceBlocks = require("./util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./selector.is-selection-expanded.cjs");
2
+ var selectionPoint = require("./selection-point.cjs"), selector_isSelectionExpanded = require("./selector.is-selection-expanded.cjs");
3
3
  const getBlockTextBefore = (snapshot) => {
4
4
  if (!snapshot.context.selection)
5
5
  return "";
6
- 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;
6
+ const startPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), block = selector_isSelectionExpanded.getFocusBlock({
7
+ context: {
8
+ ...snapshot.context,
9
+ selection: {
10
+ anchor: startPoint,
11
+ focus: startPoint
12
+ }
13
+ }
14
+ });
7
15
  if (!block)
8
16
  return "";
9
- const startOfBlock = util_sliceBlocks.getBlockStartPoint({
17
+ const startOfBlock = selectionPoint.getBlockStartPoint({
10
18
  context: snapshot.context,
11
- block: {
12
- node: block,
13
- path: [{
14
- _key: block._key
15
- }]
16
- }
19
+ block
17
20
  });
18
21
  return selector_isSelectionExpanded.getSelectionText({
19
22
  context: {
20
23
  ...snapshot.context,
21
24
  selection: {
22
25
  anchor: startOfBlock,
23
- focus: point
26
+ focus: startPoint
24
27
  }
25
28
  }
26
29
  });
@@ -1 +1 @@
1
- {"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {reverseSelection} from '../utils/util.reverse-selection'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const selection = snapshot.context.selection.backward\n ? reverseSelection(snapshot.context.selection)\n : snapshot.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 ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block: {\n node: block,\n path: [{_key: block._key}],\n },\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: point,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","point","backward","reverseSelection","anchor","key","isKeyedSegment","path","_key","undefined","block","value","find","startOfBlock","getBlockStartPoint","node","getSelectionText","focus"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAa,aAAA;AAClE,MAAA,CAACA,SAASC,QAAQC;AACb,WAAA;AAMT,QAAMC,SAHYH,SAASC,QAAQC,UAAUE,WACzCC,kCAAiBL,SAASC,QAAQC,SAAS,IAC3CF,SAASC,QAAQC,WACGI,QAClBC,MAAMC,iBAAAA,eAAeL,MAAMM,KAAK,CAAC,CAAC,IAAIN,MAAMM,KAAK,CAAC,EAAEC,OAAOC,QAE3DC,QAAQL,MACVP,SAASC,QAAQY,MAAMC,KAAMF,CAAAA,WAAUA,OAAMF,SAASH,GAAG,IACzDI;AAEJ,MAAI,CAACC;AACI,WAAA;AAGT,QAAMG,eAAeC,iBAAAA,mBAAmB;AAAA,IACtCf,SAASD,SAASC;AAAAA,IAClBW,OAAO;AAAA,MACLK,MAAML;AAAAA,MACNH,MAAM,CAAC;AAAA,QAACC,MAAME,MAAMF;AAAAA,MAAK,CAAA;AAAA,IAAA;AAAA,EAC3B,CACD;AAED,SAAOQ,8CAAiB;AAAA,IAEtBjB,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTI,QAAQS;AAAAA,QACRI,OAAOhB;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;;"}
1
+ {"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionStartPoint} from '../utils'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {getFocusBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","startPoint","getSelectionStartPoint","block","getFocusBlock","anchor","focus","startOfBlock","getBlockStartPoint","getSelectionText"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAa,aAAA;AAClE,MAAA,CAACA,SAASC,QAAQC;AACb,WAAA;AAGT,QAAMC,aAAaC,eAAAA,uBAAuBJ,SAASC,QAAQC,SAAS,GAC9DG,QAAQC,2CAAc;AAAA,IAE1BL,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQJ;AAAAA,QACRK,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACE;AACI,WAAA;AAGT,QAAMI,eAAeC,eAAAA,mBAAmB;AAAA,IACtCT,SAASD,SAASC;AAAAA,IAClBI;AAAAA,EAAAA,CACD;AAED,SAAOM,8CAAiB;AAAA,IAEtBV,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQE;AAAAA,QACRD,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;;"}
@@ -1,18 +1,24 @@
1
1
  "use strict";
2
- var util_sliceBlocks = require("./util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./selector.is-selection-expanded.cjs"), util_isEqualSelectionPoints = require("./util.is-equal-selection-points.cjs"), types = require("@sanity/types");
3
- const getSelectedSpans = (snapshot) => {
2
+ var selectionPoint = require("./selection-point.cjs"), selector_isSelectionExpanded = require("./selector.is-selection-expanded.cjs"), util_isEqualSelectionPoints = require("./util.is-equal-selection-points.cjs"), types = require("@sanity/types");
3
+ const getSelectionEndPoint = (snapshot) => {
4
+ if (snapshot.context.selection)
5
+ return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
6
+ }, getSelectedSpans = (snapshot) => {
4
7
  if (!snapshot.context.selection)
5
8
  return [];
6
- const selectedSpans = [], startPoint = snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor, endPoint = snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus, startBlockKey = util_sliceBlocks.isKeyedSegment(startPoint.path[0]) ? startPoint.path[0]._key : void 0, endBlockKey = util_sliceBlocks.isKeyedSegment(endPoint.path[0]) ? endPoint.path[0]._key : void 0;
9
+ const selectedSpans = [], startPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
10
+ if (!startPoint || !endPoint)
11
+ return selectedSpans;
12
+ const startBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(endPoint);
7
13
  if (!startBlockKey || !endBlockKey)
8
14
  return selectedSpans;
9
- const startSpanKey = util_sliceBlocks.isKeyedSegment(startPoint.path[2]) ? startPoint.path[2]._key : void 0, endSpanKey = util_sliceBlocks.isKeyedSegment(endPoint.path[2]) ? endPoint.path[2]._key : void 0;
15
+ const startSpanKey = selectionPoint.getChildKeyFromSelectionPoint(startPoint), endSpanKey = selectionPoint.getChildKeyFromSelectionPoint(endPoint);
10
16
  let startBlockFound = !1;
11
17
  for (const block of snapshot.context.value)
12
- if (block._key === startBlockKey && (startBlockFound = !0), !!util_sliceBlocks.isTextBlock(snapshot.context, block)) {
18
+ if (block._key === startBlockKey && (startBlockFound = !0), !!selectionPoint.isTextBlock(snapshot.context, block)) {
13
19
  if (block._key === startBlockKey) {
14
20
  for (const child of block.children)
15
- if (util_sliceBlocks.isSpan$1(snapshot.context, child)) {
21
+ if (selectionPoint.isSpan$1(snapshot.context, child)) {
16
22
  if (startSpanKey && child._key === startSpanKey) {
17
23
  if (startPoint.offset < child.text.length && selectedSpans.push({
18
24
  node: child,
@@ -51,7 +57,7 @@ const getSelectedSpans = (snapshot) => {
51
57
  }
52
58
  if (block._key === endBlockKey) {
53
59
  for (const child of block.children)
54
- if (util_sliceBlocks.isSpan$1(snapshot.context, child)) {
60
+ if (selectionPoint.isSpan$1(snapshot.context, child)) {
55
61
  if (endSpanKey && child._key === endSpanKey) {
56
62
  endPoint.offset > 0 && selectedSpans.push({
57
63
  node: child,
@@ -76,7 +82,7 @@ const getSelectedSpans = (snapshot) => {
76
82
  }
77
83
  if (startBlockFound)
78
84
  for (const child of block.children)
79
- util_sliceBlocks.isSpan$1(snapshot.context, child) && selectedSpans.push({
85
+ selectionPoint.isSpan$1(snapshot.context, child) && selectedSpans.push({
80
86
  node: child,
81
87
  path: [{
82
88
  _key: block._key
@@ -99,11 +105,11 @@ const getSelectedSpans = (snapshot) => {
99
105
  return [];
100
106
  }
101
107
  const activeAnnotations = snapshot.beta.activeAnnotations;
102
- return selectedBlocks.flatMap((block) => util_sliceBlocks.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => activeAnnotations.includes(markDef._key));
108
+ return selectedBlocks.flatMap((block) => selectionPoint.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => activeAnnotations.includes(markDef._key));
103
109
  }, getActiveListItem = (snapshot) => {
104
110
  if (!snapshot.context.selection)
105
111
  return;
106
- const selectedTextBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => util_sliceBlocks.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
112
+ const selectedTextBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => selectionPoint.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
107
113
  if (!firstTextBlock)
108
114
  return;
109
115
  const firstListItem = firstTextBlock.listItem;
@@ -112,15 +118,12 @@ const getSelectedSpans = (snapshot) => {
112
118
  }, getActiveStyle = (snapshot) => {
113
119
  if (!snapshot.context.selection)
114
120
  return;
115
- const selectedTextBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => util_sliceBlocks.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
121
+ const selectedTextBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => selectionPoint.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
116
122
  if (!firstTextBlock)
117
123
  return;
118
124
  const firstStyle = firstTextBlock.style;
119
125
  if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
120
126
  return firstStyle;
121
- }, getSelectionEndPoint = (snapshot) => {
122
- if (snapshot.context.selection)
123
- return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
124
127
  }, getNextInlineObject = (snapshot) => {
125
128
  const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
126
129
  if (!focusTextBlock || !selectionEndPointChildKey)
@@ -131,7 +134,7 @@ const getSelectedSpans = (snapshot) => {
131
134
  endPointChildFound = !0;
132
135
  continue;
133
136
  }
134
- if (!util_sliceBlocks.isSpan(snapshot.context, child) && endPointChildFound) {
137
+ if (!selectionPoint.isSpan(snapshot.context, child) && endPointChildFound) {
135
138
  inlineObject = {
136
139
  node: child,
137
140
  path: [...focusTextBlock.path, "children", {
@@ -145,13 +148,13 @@ const getSelectedSpans = (snapshot) => {
145
148
  }, getCaretWordSelection = (snapshot) => {
146
149
  if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
147
150
  return null;
148
- const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? util_sliceBlocks.spanSelectionPointToBlockOffset({
151
+ const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? selectionPoint.spanSelectionPointToBlockOffset({
149
152
  context: snapshot.context,
150
153
  selectionPoint: selectionStartPoint
151
154
  }) : void 0;
152
155
  if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset)
153
156
  return null;
154
- const previousInlineObject = selector_isSelectionExpanded.getPreviousInlineObject(snapshot), blockStartPoint = util_sliceBlocks.getBlockStartPoint({
157
+ const previousInlineObject = selector_isSelectionExpanded.getPreviousInlineObject(snapshot), blockStartPoint = selectionPoint.getBlockStartPoint({
155
158
  context: snapshot.context,
156
159
  block: focusTextBlock
157
160
  }), textDirectlyBefore = selector_isSelectionExpanded.getSelectionText({
@@ -188,11 +191,11 @@ const getSelectedSpans = (snapshot) => {
188
191
  } : selectionStartOffset, caretWordEndOffset = textDirectlyAfter ? {
189
192
  ...selectionStartOffset,
190
193
  offset: selectionStartOffset.offset + textDirectlyAfter.length
191
- } : selectionStartOffset, caretWordStartSelectionPoint = util_sliceBlocks.blockOffsetToSpanSelectionPoint({
194
+ } : selectionStartOffset, caretWordStartSelectionPoint = selectionPoint.blockOffsetToSpanSelectionPoint({
192
195
  context: snapshot.context,
193
196
  blockOffset: caretWordStartOffset,
194
197
  direction: "backward"
195
- }), caretWordEndSelectionPoint = util_sliceBlocks.blockOffsetToSpanSelectionPoint({
198
+ }), caretWordEndSelectionPoint = selectionPoint.blockOffsetToSpanSelectionPoint({
196
199
  context: snapshot.context,
197
200
  blockOffset: caretWordEndOffset,
198
201
  direction: "forward"
@@ -218,22 +221,22 @@ const getSelectedSpans = (snapshot) => {
218
221
  }, getSelectedTextBlocks = (snapshot) => {
219
222
  if (!snapshot.context.selection)
220
223
  return [];
221
- const selectedTextBlocks = [], startKey = snapshot.context.selection.backward ? util_sliceBlocks.isKeyedSegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : util_sliceBlocks.isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, endKey = snapshot.context.selection.backward ? util_sliceBlocks.isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : util_sliceBlocks.isKeyedSegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0;
222
- if (!startKey || !endKey)
224
+ const selectedTextBlocks = [], startPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), endPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection), startBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(endPoint);
225
+ if (!startBlockKey || !endBlockKey)
223
226
  return selectedTextBlocks;
224
227
  for (const block of snapshot.context.value) {
225
- if (block._key === startKey) {
226
- if (util_sliceBlocks.isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
228
+ if (block._key === startBlockKey) {
229
+ if (selectionPoint.isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
227
230
  node: block,
228
231
  path: [{
229
232
  _key: block._key
230
233
  }]
231
- }), startKey === endKey)
234
+ }), startBlockKey === endBlockKey)
232
235
  break;
233
236
  continue;
234
237
  }
235
- if (block._key === endKey) {
236
- util_sliceBlocks.isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
238
+ if (block._key === endBlockKey) {
239
+ selectionPoint.isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
237
240
  node: block,
238
241
  path: [{
239
242
  _key: block._key
@@ -241,7 +244,7 @@ const getSelectedSpans = (snapshot) => {
241
244
  });
242
245
  break;
243
246
  }
244
- selectedTextBlocks.length > 0 && util_sliceBlocks.isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
247
+ selectedTextBlocks.length > 0 && selectionPoint.isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
245
248
  node: block,
246
249
  path: [{
247
250
  _key: block._key
@@ -252,19 +255,16 @@ const getSelectedSpans = (snapshot) => {
252
255
  }, getTrimmedSelection = (snapshot) => {
253
256
  if (!snapshot.context.selection)
254
257
  return snapshot.context.selection;
255
- const startPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
256
- if (!startPoint || !endPoint)
257
- return snapshot.context.selection;
258
- const startBlockKey = util_sliceBlocks.isKeyedSegment(startPoint.path[0]) ? startPoint.path[0]._key : null, startChildKey = util_sliceBlocks.isKeyedSegment(startPoint.path[2]) ? startPoint.path[2]._key : null, endBlockKey = util_sliceBlocks.isKeyedSegment(endPoint.path[0]) ? endPoint.path[0]._key : null, endChildKey = util_sliceBlocks.isKeyedSegment(endPoint.path[2]) ? endPoint.path[2]._key : null;
258
+ const startPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), endPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection), startBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(startPoint), startChildKey = selectionPoint.getChildKeyFromSelectionPoint(startPoint), endBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(endPoint), endChildKey = selectionPoint.getChildKeyFromSelectionPoint(endPoint);
259
259
  if (!startBlockKey || !endBlockKey)
260
260
  return snapshot.context.selection;
261
261
  let startBlockFound = !1, adjustedStartPoint, trimStartPoint = !1, adjustedEndPoint, trimEndPoint = !1, previousPotentialEndpoint;
262
262
  for (const block of snapshot.context.value)
263
- if (!(block._key === startBlockKey && (startBlockFound = !0, util_sliceBlocks.isTextBlock(snapshot.context, block) && util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, block))) && startBlockFound && util_sliceBlocks.isTextBlock(snapshot.context, block)) {
263
+ if (!(block._key === startBlockKey && (startBlockFound = !0, selectionPoint.isTextBlock(snapshot.context, block) && util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, block))) && startBlockFound && selectionPoint.isTextBlock(snapshot.context, block)) {
264
264
  if (block._key === endBlockKey && util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, block))
265
265
  break;
266
266
  for (const child of block.children) {
267
- if (child._key === endChildKey && (!util_sliceBlocks.isSpan$1(snapshot.context, child) || endPoint.offset === 0)) {
267
+ if (child._key === endChildKey && (!selectionPoint.isSpan$1(snapshot.context, child) || endPoint.offset === 0)) {
268
268
  adjustedEndPoint = previousPotentialEndpoint ? {
269
269
  path: [{
270
270
  _key: previousPotentialEndpoint.blockKey
@@ -276,8 +276,8 @@ const getSelectedSpans = (snapshot) => {
276
276
  break;
277
277
  }
278
278
  if (trimStartPoint) {
279
- const lonelySpan = util_sliceBlocks.isSpan$1(snapshot.context, child) && block.children.length === 1;
280
- (util_sliceBlocks.isSpan$1(snapshot.context, child) && child.text.length > 0 || lonelySpan) && (adjustedStartPoint = {
279
+ const lonelySpan = selectionPoint.isSpan$1(snapshot.context, child) && block.children.length === 1;
280
+ (selectionPoint.isSpan$1(snapshot.context, child) && child.text.length > 0 || lonelySpan) && (adjustedStartPoint = {
281
281
  path: [{
282
282
  _key: block._key
283
283
  }, "children", {
@@ -291,7 +291,7 @@ const getSelectedSpans = (snapshot) => {
291
291
  continue;
292
292
  }
293
293
  if (child._key === startChildKey) {
294
- if (!util_sliceBlocks.isSpan$1(snapshot.context, child)) {
294
+ if (!selectionPoint.isSpan$1(snapshot.context, child)) {
295
295
  trimStartPoint = !0;
296
296
  continue;
297
297
  }
@@ -303,7 +303,7 @@ const getSelectedSpans = (snapshot) => {
303
303
  continue;
304
304
  }
305
305
  }
306
- previousPotentialEndpoint = util_sliceBlocks.isSpan$1(snapshot.context, child) && child.text.length > 0 ? {
306
+ previousPotentialEndpoint = selectionPoint.isSpan$1(snapshot.context, child) && child.text.length > 0 ? {
307
307
  blockKey: block._key,
308
308
  span: child
309
309
  } : previousPotentialEndpoint;
@@ -337,7 +337,7 @@ const getSelectedSpans = (snapshot) => {
337
337
  return trimmedSelection;
338
338
  };
339
339
  function isActiveAnnotation(annotation) {
340
- return (snapshot) => selector_isSelectionExpanded.getSelectedBlocks(snapshot).flatMap((block) => util_sliceBlocks.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => markDef._type === annotation && snapshot.beta.activeAnnotations.includes(markDef._key)).length > 0;
340
+ return (snapshot) => selector_isSelectionExpanded.getSelectedBlocks(snapshot).flatMap((block) => selectionPoint.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => markDef._type === annotation && snapshot.beta.activeAnnotations.includes(markDef._key)).length > 0;
341
341
  }
342
342
  function isActiveDecorator(decorator) {
343
343
  return (snapshot) => {
@@ -369,7 +369,7 @@ function isAtTheStartOfBlock(block) {
369
369
  return (snapshot) => {
370
370
  if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
371
371
  return !1;
372
- const blockStartPoint = util_sliceBlocks.getBlockStartPoint({
372
+ const blockStartPoint = selectionPoint.getBlockStartPoint({
373
373
  context: snapshot.context,
374
374
  block
375
375
  });
@@ -380,7 +380,7 @@ function isPointAfterSelection(point) {
380
380
  return (snapshot) => {
381
381
  if (!snapshot.context.selection)
382
382
  return !1;
383
- const selection = snapshot.context.selection.backward ? util_sliceBlocks.reverseSelection(snapshot.context.selection) : snapshot.context.selection, pointBlockKey = util_sliceBlocks.isKeyedSegment(point.path[0]) ? point.path[0]._key : void 0, pointChildKey = util_sliceBlocks.isKeyedSegment(point.path[2]) ? point.path[2]._key : void 0, endBlockKey = util_sliceBlocks.isKeyedSegment(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0, endChildKey = util_sliceBlocks.isKeyedSegment(selection.focus.path[2]) ? selection.focus.path[2]._key : void 0;
383
+ const endPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection), endBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(endPoint), endChildKey = selectionPoint.getChildKeyFromSelectionPoint(endPoint), pointBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(point), pointChildKey = selectionPoint.getChildKeyFromSelectionPoint(point);
384
384
  if (!pointBlockKey || !endBlockKey)
385
385
  return !1;
386
386
  let after = !1;
@@ -390,7 +390,7 @@ function isPointAfterSelection(point) {
390
390
  after = !0;
391
391
  break;
392
392
  }
393
- if (!util_sliceBlocks.isTextBlock(snapshot.context, block) || !pointChildKey || !endChildKey)
393
+ if (!selectionPoint.isTextBlock(snapshot.context, block) || !pointChildKey || !endChildKey)
394
394
  break;
395
395
  for (const child of block.children) {
396
396
  if (child._key === endChildKey) {
@@ -398,7 +398,7 @@ function isPointAfterSelection(point) {
398
398
  after = !0;
399
399
  break;
400
400
  }
401
- after = point.offset > selection.focus.offset;
401
+ after = point.offset > endPoint.offset;
402
402
  break;
403
403
  }
404
404
  if (child._key === pointChildKey)
@@ -415,7 +415,7 @@ function isPointBeforeSelection(point) {
415
415
  return (snapshot) => {
416
416
  if (!snapshot.context.selection)
417
417
  return !1;
418
- const selection = snapshot.context.selection.backward ? util_sliceBlocks.reverseSelection(snapshot.context.selection) : snapshot.context.selection, pointBlockKey = util_sliceBlocks.isKeyedSegment(point.path[0]) ? point.path[0]._key : void 0, pointChildKey = util_sliceBlocks.isKeyedSegment(point.path[2]) ? point.path[2]._key : void 0, startBlockKey = util_sliceBlocks.isKeyedSegment(selection.anchor.path[0]) ? selection.anchor.path[0]._key : void 0, startChildKey = util_sliceBlocks.isKeyedSegment(selection.anchor.path[2]) ? selection.anchor.path[2]._key : void 0;
418
+ const startPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), startBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(startPoint), startChildKey = selectionPoint.getChildKeyFromSelectionPoint(startPoint), pointBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(point), pointChildKey = selectionPoint.getChildKeyFromSelectionPoint(point);
419
419
  if (!pointBlockKey || !startBlockKey)
420
420
  return !1;
421
421
  let before = !1;
@@ -425,7 +425,7 @@ function isPointBeforeSelection(point) {
425
425
  before = !0;
426
426
  break;
427
427
  }
428
- if (!util_sliceBlocks.isTextBlock(snapshot.context, block) || !pointChildKey || !startChildKey)
428
+ if (!selectionPoint.isTextBlock(snapshot.context, block) || !pointChildKey || !startChildKey)
429
429
  break;
430
430
  for (const child of block.children) {
431
431
  if (child._key === pointChildKey) {
@@ -433,7 +433,7 @@ function isPointBeforeSelection(point) {
433
433
  before = !0;
434
434
  break;
435
435
  }
436
- before = point.offset < selection.anchor.offset;
436
+ before = point.offset < startPoint.offset;
437
437
  break;
438
438
  }
439
439
  if (child._key === startChildKey)
@@ -509,7 +509,7 @@ const isSelectingEntireBlocks = (snapshot) => {
509
509
  const startPoint = snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor, endPoint = snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus, startBlock = selector_isSelectionExpanded.getSelectionStartBlock(snapshot), endBlock = selector_isSelectionExpanded.getSelectionEndBlock(snapshot);
510
510
  if (!startBlock || !endBlock)
511
511
  return !1;
512
- const startBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
512
+ const startBlockStartPoint = selectionPoint.getBlockStartPoint({
513
513
  context: snapshot.context,
514
514
  block: startBlock
515
515
  }), endBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({