@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
@@ -1,12 +1,14 @@
1
1
  import { getSelectionEndPoint } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
2
2
  import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFocusInlineObject, getNextInlineObject, getSelectedSpans, getSelectedTextBlocks, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
3
- import { isKeyedSegment, isTextBlock, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
3
+ import { getBlockKeyFromSelectionPoint, isTextBlock, getChildKeyFromSelectionPoint, spanSelectionPointToBlockOffset } from "../_chunks-es/selection-point.js";
4
4
  import { isPortableTextSpan } from "@sanity/types";
5
5
  import { getSelectionStartPoint, getFocusTextBlock, getPreviousBlock } from "../_chunks-es/selector.is-selection-expanded.js";
6
6
  import { getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getLastBlock, getNextBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-selection-expanded.js";
7
7
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
8
8
  const getAnchorBlock = (snapshot) => {
9
- const key = snapshot.context.selection && isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
9
+ if (!snapshot.context.selection)
10
+ return;
11
+ const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor), node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
10
12
  return node && key ? {
11
13
  node,
12
14
  path: [{
@@ -20,10 +22,12 @@ const getAnchorBlock = (snapshot) => {
20
22
  path: anchorBlock.path
21
23
  } : void 0;
22
24
  }, getAnchorChild = (snapshot) => {
25
+ if (!snapshot.context.selection)
26
+ return;
23
27
  const anchorBlock = getAnchorTextBlock(snapshot);
24
28
  if (!anchorBlock)
25
29
  return;
26
- const key = snapshot.context.selection && isKeyedSegment(snapshot.context.selection.anchor.path[2]) ? snapshot.context.selection.anchor.path[2]._key : void 0, node = key ? anchorBlock.node.children.find((span) => span._key === key) : void 0;
30
+ const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor), node = key ? anchorBlock.node.children.find((span) => span._key === key) : void 0;
27
31
  return node && key ? {
28
32
  node,
29
33
  path: [...anchorBlock.path, "children", {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock, getPreviousBlock} from './selectors'\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const previousListItem = getPreviousListItem({\n listItem: focusTextBlock.node.listItem,\n level: focusTextBlock.node.level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!previousListItem) {\n return 1\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return 1\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return 1\n }\n\n const previousListItemListState = getListIndex({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return 1\n }\n\n return previousListItemListState + 1\n }\n}\n\nfunction getPreviousListItem({\n listItem,\n level,\n}: {\n listItem: string\n level: number\n}): EditorSelector<\n | {\n node: PortableTextTextBlock\n path: [{_key: string}]\n }\n | undefined\n> {\n return (snapshot) => {\n const previousBlock = getPreviousBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n },\n })\n\n if (!previousBlock) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, previousBlock.node)) {\n return undefined\n }\n\n if (\n previousBlock.node.listItem === undefined ||\n previousBlock.node.level === undefined\n ) {\n return undefined\n }\n\n if (previousBlock.node.listItem !== listItem) {\n return undefined\n }\n\n if (previousBlock.node.level === level) {\n return {\n node: previousBlock.node,\n path: previousBlock.path,\n }\n }\n\n if (previousBlock.node.level < level) {\n return undefined\n }\n\n return getPreviousListItem({\n listItem,\n level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: {\n path: previousBlock.path,\n offset: 0,\n },\n focus: {\n path: previousBlock.path,\n offset: 0,\n },\n },\n },\n })\n }\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","previousListItemListState","previousBlock","getPreviousBlock","getSelection","getValue"],"mappings":";;;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCbaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,YAAYf,SAASE,SAASY,YAAYL,IAAI,IAChE;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCPaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMb,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTa,YAAYL,KAAKQ,SAASN,KAAMO,CAAAA,SAASA,KAAKX,SAASN,GAAG,IAC1DO;AAEJ,SAAOC,QAAQR,MACX;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC,GAAGQ,YAAYR,MAAM,YAAY;AAAA,MAACC,MAAMN;AAAAA,IAAI,C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QAAQ;AAAA,cACV;AAAA,cACAC,OAAO;AAAA,gBACL3B,MAAMmC,cAAcnC;AAAAA,gBACpB0B,QAAQ;AAAA,cAAA;AAAA,YACV;AAAA,UACF;AAAA,QACF,CACD;AAAA,IAAA;AAAA,EACH;AACF;ACtJaW,MAAAA,eAAiD3C,CACrDA,aAAAA,SAASE,QAAQC,WCDbyC,WACX5C,CAEOA,aAAAA,SAASE,QAAQQ;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock, getPreviousBlock} from './selectors'\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const previousListItem = getPreviousListItem({\n listItem: focusTextBlock.node.listItem,\n level: focusTextBlock.node.level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!previousListItem) {\n return 1\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return 1\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return 1\n }\n\n const previousListItemListState = getListIndex({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return 1\n }\n\n return previousListItemListState + 1\n }\n}\n\nfunction getPreviousListItem({\n listItem,\n level,\n}: {\n listItem: string\n level: number\n}): EditorSelector<\n | {\n node: PortableTextTextBlock\n path: [{_key: string}]\n }\n | undefined\n> {\n return (snapshot) => {\n const previousBlock = getPreviousBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n },\n })\n\n if (!previousBlock) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, previousBlock.node)) {\n return undefined\n }\n\n if (\n previousBlock.node.listItem === undefined ||\n previousBlock.node.level === undefined\n ) {\n return undefined\n }\n\n if (previousBlock.node.listItem !== listItem) {\n return undefined\n }\n\n if (previousBlock.node.level === level) {\n return {\n node: previousBlock.node,\n path: previousBlock.path,\n }\n }\n\n if (previousBlock.node.level < level) {\n return undefined\n }\n\n return getPreviousListItem({\n listItem,\n level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: {\n path: previousBlock.path,\n offset: 0,\n },\n focus: {\n path: previousBlock.path,\n offset: 0,\n },\n },\n },\n })\n }\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","node","value","find","block","_key","undefined","path","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","previousListItemListState","previousBlock","getPreviousBlock","getSelection","getValue"],"mappings":";;;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GAErEC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PyC,WAAAA,8BAA8B9B,SACzB,IAGF8B,4BAA4B;AAAA,EACrC;AACF;AAEA,SAASD,oBAAoB;AAAA,EAC3BH;AAAAA,EACAC;AAIF,GAME;AACA,SAAQtC,CAAa,aAAA;AACnB,UAAM0C,gBAAgBC,iBAAiB;AAAA,MAErC1C,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,MAAAA;AAAAA,IACd,CACD;AAED,QAAKyC,iBAIA3B,YAAYf,SAASC,SAASyC,cAAcpC,IAAI,KAKnDoC,EAAcpC,cAAAA,KAAK+B,aAAa1B,UAChC+B,cAAcpC,KAAKgC,UAAU3B,WAK3B+B,cAAcpC,KAAK+B,aAAaA,UAIpC;AAAIK,UAAAA,cAAcpC,KAAKgC,UAAUA;AACxB,eAAA;AAAA,UACLhC,MAAMoC,cAAcpC;AAAAA,UACpBM,MAAM8B,cAAc9B;AAAAA,QACtB;AAGE8B,UAAAA,EAAAA,cAAcpC,KAAKgC,QAAQA;AAI/B,eAAOE,oBAAoB;AAAA,UACzBH;AAAAA,UACAC;AAAAA,QAAAA,CACD,EAAE;AAAA,UACD,GAAGtC;AAAAA,UACHC,SAAS;AAAA,YACP,GAAGD,SAASC;AAAAA,YACZC,WAAW;AAAA,cACTG,QAAQ;AAAA,gBACNO,MAAM8B,cAAc9B;AAAAA,gBACpBqB,QAAQ;AAAA,cACV;AAAA,cACAC,OAAO;AAAA,gBACLtB,MAAM8B,cAAc9B;AAAAA,gBACpBqB,QAAQ;AAAA,cAAA;AAAA,YACV;AAAA,UACF;AAAA,QACF,CACD;AAAA,IAAA;AAAA,EACH;AACF;ACtJaW,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASC,QAAQC,WCDb2C,WACX7C,CAEOA,aAAAA,SAASC,QAAQM;"}
@@ -1,9 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_isEqualSelectionPoints = require("../_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("../_chunks-cjs/util.selection-point-to-block-offset.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
3
+ var selectionPoint = require("../_chunks-cjs/selection-point.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_isEqualSelectionPoints = require("../_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("../_chunks-cjs/util.selection-point-to-block-offset.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
4
4
  function isEqualSelections(a, b) {
5
5
  return !a && !b ? !0 : !a || !b ? !1 : util_isEqualSelectionPoints.isEqualSelectionPoints(a.anchor, b.anchor) && util_isEqualSelectionPoints.isEqualSelectionPoints(a.focus, b.focus);
6
6
  }
7
+ function reverseSelection(selection) {
8
+ return selection && (selection.backward ? {
9
+ anchor: selection.focus,
10
+ focus: selection.anchor,
11
+ backward: !1
12
+ } : {
13
+ anchor: selection.focus,
14
+ focus: selection.anchor,
15
+ backward: !0
16
+ });
17
+ }
7
18
  function splitTextBlock({
8
19
  context,
9
20
  block,
@@ -12,7 +23,7 @@ function splitTextBlock({
12
23
  const firstChild = block.children.at(0), lastChild = block.children.at(block.children.length - 1);
13
24
  if (!firstChild || !lastChild)
14
25
  return;
15
- const before = util_sliceBlocks.sliceBlocks({
26
+ const before = selectionPoint.sliceBlocks({
16
27
  context: {
17
28
  schema: context.schema,
18
29
  selection: {
@@ -28,7 +39,7 @@ function splitTextBlock({
28
39
  }
29
40
  },
30
41
  blocks: [block]
31
- }).at(0), after = util_sliceBlocks.sliceBlocks({
42
+ }).at(0), after = selectionPoint.sliceBlocks({
32
43
  context: {
33
44
  schema: context.schema,
34
45
  selection: {
@@ -39,7 +50,7 @@ function splitTextBlock({
39
50
  }, "children", {
40
51
  _key: lastChild._key
41
52
  }],
42
- offset: util_sliceBlocks.isSpan(context, lastChild) ? lastChild.text.length : 0
53
+ offset: selectionPoint.isSpan(context, lastChild) ? lastChild.text.length : 0
43
54
  }
44
55
  }
45
56
  },
@@ -51,14 +62,15 @@ function splitTextBlock({
51
62
  after
52
63
  };
53
64
  }
54
- exports.blockOffsetToSpanSelectionPoint = util_sliceBlocks.blockOffsetToSpanSelectionPoint;
55
- exports.getBlockStartPoint = util_sliceBlocks.getBlockStartPoint;
56
- exports.getTextBlockText = util_sliceBlocks.getTextBlockText;
57
- exports.isKeyedSegment = util_sliceBlocks.isKeyedSegment;
58
- exports.isSpan = util_sliceBlocks.isSpan;
59
- exports.reverseSelection = util_sliceBlocks.reverseSelection;
60
- exports.sliceBlocks = util_sliceBlocks.sliceBlocks;
61
- exports.spanSelectionPointToBlockOffset = util_sliceBlocks.spanSelectionPointToBlockOffset;
65
+ exports.blockOffsetToSpanSelectionPoint = selectionPoint.blockOffsetToSpanSelectionPoint;
66
+ exports.getBlockStartPoint = selectionPoint.getBlockStartPoint;
67
+ exports.getSelectionEndPoint = selectionPoint.getSelectionEndPoint;
68
+ exports.getSelectionStartPoint = selectionPoint.getSelectionStartPoint;
69
+ exports.getTextBlockText = selectionPoint.getTextBlockText;
70
+ exports.isKeyedSegment = selectionPoint.isKeyedSegment;
71
+ exports.isSpan = selectionPoint.isSpan;
72
+ exports.sliceBlocks = selectionPoint.sliceBlocks;
73
+ exports.spanSelectionPointToBlockOffset = selectionPoint.spanSelectionPointToBlockOffset;
62
74
  exports.blockOffsetToBlockSelectionPoint = util_childSelectionPointToBlockOffset.blockOffsetToBlockSelectionPoint;
63
75
  exports.blockOffsetToSelectionPoint = util_childSelectionPointToBlockOffset.blockOffsetToSelectionPoint;
64
76
  exports.blockOffsetsToSelection = util_childSelectionPointToBlockOffset.blockOffsetsToSelection;
@@ -66,12 +78,11 @@ exports.childSelectionPointToBlockOffset = util_childSelectionPointToBlockOffset
66
78
  exports.getBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint;
67
79
  exports.isEmptyTextBlock = util_isEqualSelectionPoints.isEmptyTextBlock;
68
80
  exports.isEqualSelectionPoints = util_isEqualSelectionPoints.isEqualSelectionPoints;
69
- exports.getSelectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint;
70
- exports.getSelectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint;
71
81
  exports.isSelectionCollapsed = util_selectionPointToBlockOffset.isSelectionCollapsed;
72
82
  exports.selectionPointToBlockOffset = util_selectionPointToBlockOffset.selectionPointToBlockOffset;
73
83
  exports.isTextBlock = util_mergeTextBlocks.isTextBlock;
74
84
  exports.mergeTextBlocks = util_mergeTextBlocks.mergeTextBlocks;
75
85
  exports.isEqualSelections = isEqualSelections;
86
+ exports.reverseSelection = reverseSelection;
76
87
  exports.splitTextBlock = splitTextBlock;
77
88
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n blocks: [block],\n }).at(0)\n const after = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n blocks: [block],\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","schema","selection","path","_key","offset","blocks","after","isSpan","text","isTextBlock"],"mappings":";;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,4BAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,mDAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACTO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,iBAAAA,YAAY;AAAA,IACzBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBC,WAAW;AAAA,QACTd,QAAQ;AAAA,UACNe,MAAM,CAAC;AAAA,YAACC,MAAMZ,MAAMY;AAAAA,aAAO,YAAY;AAAA,YAACA,MAAMV,WAAWU;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QACV;AAAA,QACAhB,OAAOI;AAAAA,MAAAA;AAAAA,IAEX;AAAA,IACAa,QAAQ,CAACd,KAAK;AAAA,EACf,CAAA,EAAEI,GAAG,CAAC,GACDW,QAAQP,iBAAAA,YAAY;AAAA,IACxBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBC,WAAW;AAAA,QACTd,QAAQK;AAAAA,QACRJ,OAAO;AAAA,UACLc,MAAM,CAAC;AAAA,YAACC,MAAMZ,MAAMY;AAAAA,aAAO,YAAY;AAAA,YAACA,MAAMP,UAAUO;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQG,iBAAOjB,OAAAA,SAASM,SAAS,IAAIA,UAAUY,KAAKX,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IAEJ;AAAA,IACAQ,QAAQ,CAACd,KAAK;AAAA,EAAA,CACf,EAAEI,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACQ,UAIZ,EAACG,CAAAA,qBAAAA,YAAYnB,SAASQ,MAAM,KAAK,CAACW,qBAAYnB,YAAAA,SAASgB,KAAK;AAIzD,WAAA;AAAA,MAACR;AAAAA,MAAQQ;AAAAA,IAAK;AACvB;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n blocks: [block],\n }).at(0)\n const after = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n blocks: [block],\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","schema","path","_key","offset","blocks","after","isSpan","text","isTextBlock"],"mappings":";;;AAMgBA,SAAAA,kBAAk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