@portabletext/editor 1.47.9 → 1.47.11

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 (37) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +105 -73
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +0 -4
  4. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -1
  5. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +8 -0
  6. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  7. package/lib/_chunks-es/editor-provider.js +108 -76
  8. package/lib/_chunks-es/editor-provider.js.map +1 -1
  9. package/lib/_chunks-es/util.is-selection-collapsed.js +0 -4
  10. package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -1
  11. package/lib/_chunks-es/util.selection-point-to-block-offset.js +8 -0
  12. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  13. package/lib/behaviors/index.d.cts +359 -339
  14. package/lib/behaviors/index.d.ts +359 -339
  15. package/lib/behaviors/index.js +1 -1
  16. package/lib/index.cjs +3 -3
  17. package/lib/index.cjs.map +1 -1
  18. package/lib/index.d.cts +4 -4
  19. package/lib/index.d.ts +4 -4
  20. package/lib/index.js +2 -1
  21. package/lib/index.js.map +1 -1
  22. package/lib/plugins/index.d.cts +4 -4
  23. package/lib/plugins/index.d.ts +4 -4
  24. package/lib/selectors/index.d.cts +4 -4
  25. package/lib/selectors/index.d.ts +4 -4
  26. package/lib/utils/index.cjs +2 -5
  27. package/lib/utils/index.cjs.map +1 -1
  28. package/lib/utils/index.d.cts +4 -4
  29. package/lib/utils/index.d.ts +4 -4
  30. package/lib/utils/index.js +2 -5
  31. package/lib/utils/index.js.map +1 -1
  32. package/package.json +4 -4
  33. package/src/behavior-actions/behavior.actions.ts +0 -9
  34. package/src/behaviors/behavior.abstract.split.ts +162 -0
  35. package/src/behaviors/behavior.default.ts +2 -0
  36. package/src/behaviors/behavior.types.event.ts +4 -4
  37. package/src/behavior-actions/behavior.action.split.block.ts +0 -146
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- function getSelectionEndPoint(selection) {
3
- return selection ? selection.backward ? selection.anchor : selection.focus : null;
4
- }
5
2
  function isSelectionCollapsed(selection) {
6
3
  return selection ? selection.anchor.path.join() === selection.focus.path.join() && selection.anchor.offset === selection.focus.offset : !1;
7
4
  }
8
- exports.getSelectionEndPoint = getSelectionEndPoint;
9
5
  exports.isSelectionCollapsed = isSelectionCollapsed;
10
6
  //# sourceMappingURL=util.is-selection-collapsed.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.is-selection-collapsed.cjs","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["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} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","isSelectionCollapsed","path","join","offset"],"mappings":";AAKO,SAASA,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,SAASF,UAAUG,QAJ3C;AAMX;ACdO,SAASC,qBAAqBJ,WAA4B;AAC/D,SAAKA,YAKHA,UAAUE,OAAOG,KAAKC,KAAAA,MAAWN,UAAUG,MAAME,KAAKC,KAAAA,KACtDN,UAAUE,OAAOK,WAAWP,UAAUG,MAAMI,SALrC;AAOX;;;"}
1
+ {"version":3,"file":"util.is-selection-collapsed.cjs","sources":["../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["isSelectionCollapsed","selection","anchor","path","join","focus","offset"],"mappings":";AAKO,SAASA,qBAAqBC,WAA4B;AAC/D,SAAKA,YAKHA,UAAUC,OAAOC,KAAKC,KAAAA,MAAWH,UAAUI,MAAMF,KAAKC,KAAAA,KACtDH,UAAUC,OAAOI,WAAWL,UAAUI,MAAMC,SALrC;AAOX;;"}
@@ -72,6 +72,12 @@ function childSelectionPointToBlockOffset({
72
72
  }
73
73
  }
74
74
  }
75
+ function getSelectionEndPoint(selection) {
76
+ return selection ? selection.backward ? selection.anchor : selection.focus : null;
77
+ }
78
+ function getSelectionStartPoint(selection) {
79
+ return selection ? selection.backward ? selection.focus : selection.anchor : null;
80
+ }
75
81
  function selectionPointToBlockOffset({
76
82
  value,
77
83
  selectionPoint
@@ -90,5 +96,7 @@ exports.blockOffsetToBlockSelectionPoint = blockOffsetToBlockSelectionPoint;
90
96
  exports.blockOffsetToSelectionPoint = blockOffsetToSelectionPoint;
91
97
  exports.blockOffsetsToSelection = blockOffsetsToSelection;
92
98
  exports.childSelectionPointToBlockOffset = childSelectionPointToBlockOffset;
99
+ exports.getSelectionEndPoint = getSelectionEndPoint;
100
+ exports.getSelectionStartPoint = getSelectionStartPoint;
93
101
  exports.selectionPointToBlockOffset = selectionPointToBlockOffset;
94
102
  //# sourceMappingURL=util.selection-point-to-block-offset.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.selection-point-to-block-offset.cjs","sources":["../../src/utils/util.block-offset-to-block-selection-point.ts","../../src/utils/util.block-offset-to-selection-point.ts","../../src/utils/util.block-offsets-to-selection.ts","../../src/utils/util.child-selection-point-to-block-offset.ts","../../src/utils/util.selection-point-to-block-offset.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function blockOffsetToBlockSelectionPoint({\n value,\n blockOffset,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n}): EditorSelectionPoint | undefined {\n let selectionPoint: EditorSelectionPoint | undefined\n\n for (const block of value) {\n if (block._key === blockOffset.path[0]._key) {\n selectionPoint = {\n path: [{_key: block._key}],\n offset: blockOffset.offset,\n }\n break\n }\n }\n\n return selectionPoint\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {blockOffsetToSpanSelectionPoint} from './util.block-offset'\nimport {blockOffsetToBlockSelectionPoint} from './util.block-offset-to-block-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetToSelectionPoint({\n value,\n blockOffset,\n direction,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}): EditorSelectionPoint | undefined {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset,\n direction,\n })\n\n if (!spanSelectionPoint) {\n return blockOffsetToBlockSelectionPoint({\n value,\n blockOffset,\n })\n }\n\n return spanSelectionPoint\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelection} from '..'\nimport type {BlockOffset} from '../types/block-offset'\nimport {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n value,\n offsets,\n backward,\n}: {\n value: Array<PortableTextBlock>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSelectionPoint({\n value,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSelectionPoint({\n value,\n blockOffset: offsets.focus,\n direction: backward ? 'forward' : 'backward',\n })\n\n if (!anchor || !focus) {\n return null\n }\n\n return {\n anchor,\n focus,\n backward,\n }\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function childSelectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = isKeyedSegment(selectionPoint.path[0])\n ? selectionPoint.path[0]._key\n : undefined\n const childKey = isKeyedSegment(selectionPoint.path[2])\n ? selectionPoint.path[2]._key\n : undefined\n\n if (!blockKey || !childKey) {\n return undefined\n }\n\n for (const block of value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (child._key === childKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n if (isPortableTextSpan(child)) {\n offset += child.text.length\n }\n }\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function selectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n if (\n selectionPoint.path.length === 1 &&\n isKeyedSegment(selectionPoint.path[0])\n ) {\n return {\n path: [{_key: selectionPoint.path[0]._key}],\n offset: selectionPoint.offset,\n }\n }\n\n return childSelectionPointToBlockOffset({\n value,\n selectionPoint,\n })\n}\n"],"names":["blockOffsetToBlockSelectionPoint","value","blockOffset","selectionPoint","block","_key","path","offset","blockOffsetToSelectionPoint","direction","blockOffsetToSpanSelectionPoint","blockOffsetsToSelection","offsets","backward","anchor","focus","childSelectionPointToBlockOffset","blockKey","isKeyedSegment","undefined","childKey","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","selectionPointToBlockOffset"],"mappings":";;AAOO,SAASA,iCAAiC;AAAA,EAC/CC;AAAAA,EACAC;AAIF,GAAqC;AAC/BC,MAAAA;AAEJ,aAAWC,SAASH;AAClB,QAAIG,MAAMC,SAASH,YAAYI,KAAK,CAAC,EAAED,MAAM;AAC1B,uBAAA;AAAA,QACfC,MAAM,CAAC;AAAA,UAACD,MAAMD,MAAMC;AAAAA,QAAAA,CAAK;AAAA,QACzBE,QAAQL,YAAYK;AAAAA,MACtB;AACA;AAAA,IAAA;AAIGJ,SAAAA;AACT;AClBO,SAASK,4BAA4B;AAAA,EAC1CP;AAAAA,EACAC;AAAAA,EACAO;AAKF,GAAqC;AAOnC,SAN2BC,iBAAAA,gCAAgC;AAAA,IACzDT;AAAAA,IACAC;AAAAA,IACAO;AAAAA,EAAAA,CACD,KAGQT,iCAAiC;AAAA,IACtCC;AAAAA,IACAC;AAAAA,EAAAA,CACD;AAIL;ACxBO,SAASS,wBAAwB;AAAA,EACtCV;AAAAA,EACAW;AAAAA,EACAC;AAKF,GAAoB;AAClB,QAAMC,SAASN,4BAA4B;AAAA,IACzCP;AAAAA,IACAC,aAAaU,QAAQE;AAAAA,IACrBL,WAAWI,WAAW,aAAa;AAAA,EAAA,CACpC,GACKE,QAAQP,4BAA4B;AAAA,IACxCP;AAAAA,IACAC,aAAaU,QAAQG;AAAAA,IACrBN,WAAWI,WAAW,YAAY;AAAA,EAAA,CACnC;AAED,SAAI,CAACC,UAAU,CAACC,QACP,OAGF;AAAA,IACLD;AAAAA,IACAC;AAAAA,IACAF;AAAAA,EACF;AACF;ACzBO,SAASG,iCAAiC;AAAA,EAC/Cf;AAAAA,EACAE;AAIF,GAA4B;AAC1B,MAAII,SAAS;AAEPU,QAAAA,WAAWC,iBAAAA,eAAef,eAAeG,KAAK,CAAC,CAAC,IAClDH,eAAeG,KAAK,CAAC,EAAED,OACvBc,QACEC,WAAWF,iBAAAA,eAAef,eAAeG,KAAK,CAAC,CAAC,IAClDH,eAAeG,KAAK,CAAC,EAAED,OACvBc;AAEA,MAAA,EAAA,CAACF,YAAY,CAACG;AAIlB,eAAWhB,SAASH;AAClB,UAAIG,MAAMC,SAASY,YAIdI,MAAAA,wBAAwBjB,KAAK;AAIvBkB,mBAAAA,SAASlB,MAAMmB,UAAU;AAClC,cAAID,MAAMjB,SAASe;AACV,mBAAA;AAAA,cACLd,MAAM,CAAC;AAAA,gBAACD,MAAMD,MAAMC;AAAAA,cAAAA,CAAK;AAAA,cACzBE,QAAQA,SAASJ,eAAeI;AAAAA,YAClC;AAGEiB,gBAAmBF,mBAAAA,KAAK,MAC1Bf,UAAUe,MAAMG,KAAKC;AAAAA,QAAAA;AAAAA;AAI7B;AC7CO,SAASC,4BAA4B;AAAA,EAC1C1B;AAAAA,EACAE;AAIF,GAA4B;AAExBA,SAAAA,eAAeG,KAAKoB,WAAW,KAC/BR,gCAAef,eAAeG,KAAK,CAAC,CAAC,IAE9B;AAAA,IACLA,MAAM,CAAC;AAAA,MAACD,MAAMF,eAAeG,KAAK,CAAC,EAAED;AAAAA,IAAAA,CAAK;AAAA,IAC1CE,QAAQJ,eAAeI;AAAAA,MAIpBS,iCAAiC;AAAA,IACtCf;AAAAA,IACAE;AAAAA,EAAAA,CACD;AACH;;;;;;"}
1
+ {"version":3,"file":"util.selection-point-to-block-offset.cjs","sources":["../../src/utils/util.block-offset-to-block-selection-point.ts","../../src/utils/util.block-offset-to-selection-point.ts","../../src/utils/util.block-offsets-to-selection.ts","../../src/utils/util.child-selection-point-to-block-offset.ts","../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.selection-point-to-block-offset.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function blockOffsetToBlockSelectionPoint({\n value,\n blockOffset,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n}): EditorSelectionPoint | undefined {\n let selectionPoint: EditorSelectionPoint | undefined\n\n for (const block of value) {\n if (block._key === blockOffset.path[0]._key) {\n selectionPoint = {\n path: [{_key: block._key}],\n offset: blockOffset.offset,\n }\n break\n }\n }\n\n return selectionPoint\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {blockOffsetToSpanSelectionPoint} from './util.block-offset'\nimport {blockOffsetToBlockSelectionPoint} from './util.block-offset-to-block-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetToSelectionPoint({\n value,\n blockOffset,\n direction,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}): EditorSelectionPoint | undefined {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset,\n direction,\n })\n\n if (!spanSelectionPoint) {\n return blockOffsetToBlockSelectionPoint({\n value,\n blockOffset,\n })\n }\n\n return spanSelectionPoint\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelection} from '..'\nimport type {BlockOffset} from '../types/block-offset'\nimport {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n value,\n offsets,\n backward,\n}: {\n value: Array<PortableTextBlock>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSelectionPoint({\n value,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSelectionPoint({\n value,\n blockOffset: offsets.focus,\n direction: backward ? 'forward' : 'backward',\n })\n\n if (!anchor || !focus) {\n return null\n }\n\n return {\n anchor,\n focus,\n backward,\n }\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function childSelectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = isKeyedSegment(selectionPoint.path[0])\n ? selectionPoint.path[0]._key\n : undefined\n const childKey = isKeyedSegment(selectionPoint.path[2])\n ? selectionPoint.path[2]._key\n : undefined\n\n if (!blockKey || !childKey) {\n return undefined\n }\n\n for (const block of value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (child._key === childKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n if (isPortableTextSpan(child)) {\n offset += child.text.length\n }\n }\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 {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function selectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n if (\n selectionPoint.path.length === 1 &&\n isKeyedSegment(selectionPoint.path[0])\n ) {\n return {\n path: [{_key: selectionPoint.path[0]._key}],\n offset: selectionPoint.offset,\n }\n }\n\n return childSelectionPointToBlockOffset({\n value,\n selectionPoint,\n })\n}\n"],"names":["blockOffsetToBlockSelectionPoint","value","blockOffset","selectionPoint","block","_key","path","offset","blockOffsetToSelectionPoint","direction","blockOffsetToSpanSelectionPoint","blockOffsetsToSelection","offsets","backward","anchor","focus","childSelectionPointToBlockOffset","blockKey","isKeyedSegment","undefined","childKey","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","getSelectionEndPoint","selection","getSelectionStartPoint","selectionPointToBlockOffset"],"mappings":";;AAOO,SAASA,iCAAiC;AAAA,EAC/CC;AAAAA,EACAC;AAIF,GAAqC;AAC/BC,MAAAA;AAEJ,aAAWC,SAASH;AAClB,QAAIG,MAAMC,SAASH,YAAYI,KAAK,CAAC,EAAED,MAAM;AAC1B,uBAAA;AAAA,QACfC,MAAM,CAAC;AAAA,UAACD,MAAMD,MAAMC;AAAAA,QAAAA,CAAK;AAAA,QACzBE,QAAQL,YAAYK;AAAAA,MACtB;AACA;AAAA,IAAA;AAIGJ,SAAAA;AACT;AClBO,SAASK,4BAA4B;AAAA,EAC1CP;AAAAA,EACAC;AAAAA,EACAO;AAKF,GAAqC;AAOnC,SAN2BC,iBAAAA,gCAAgC;AAAA,IACzDT;AAAAA,IACAC;AAAAA,IACAO;AAAAA,EAAAA,CACD,KAGQT,iCAAiC;AAAA,IACtCC;AAAAA,IACAC;AAAAA,EAAAA,CACD;AAIL;ACxBO,SAASS,wBAAwB;AAAA,EACtCV;AAAAA,EACAW;AAAAA,EACAC;AAKF,GAAoB;AAClB,QAAMC,SAASN,4BAA4B;AAAA,IACzCP;AAAAA,IACAC,aAAaU,QAAQE;AAAAA,IACrBL,WAAWI,WAAW,aAAa;AAAA,EAAA,CACpC,GACKE,QAAQP,4BAA4B;AAAA,IACxCP;AAAAA,IACAC,aAAaU,QAAQG;AAAAA,IACrBN,WAAWI,WAAW,YAAY;AAAA,EAAA,CACnC;AAED,SAAI,CAACC,UAAU,CAACC,QACP,OAGF;AAAA,IACLD;AAAAA,IACAC;AAAAA,IACAF;AAAAA,EACF;AACF;ACzBO,SAASG,iCAAiC;AAAA,EAC/Cf;AAAAA,EACAE;AAIF,GAA4B;AAC1B,MAAII,SAAS;AAEPU,QAAAA,WAAWC,iBAAAA,eAAef,eAAeG,KAAK,CAAC,CAAC,IAClDH,eAAeG,KAAK,CAAC,EAAED,OACvBc,QACEC,WAAWF,iBAAAA,eAAef,eAAeG,KAAK,CAAC,CAAC,IAClDH,eAAeG,KAAK,CAAC,EAAED,OACvBc;AAEA,MAAA,EAAA,CAACF,YAAY,CAACG;AAIlB,eAAWhB,SAASH;AAClB,UAAIG,MAAMC,SAASY,YAIdI,MAAAA,wBAAwBjB,KAAK;AAIvBkB,mBAAAA,SAASlB,MAAMmB,UAAU;AAClC,cAAID,MAAMjB,SAASe;AACV,mBAAA;AAAA,cACLd,MAAM,CAAC;AAAA,gBAACD,MAAMD,MAAMC;AAAAA,cAAAA,CAAK;AAAA,cACzBE,QAAQA,SAASJ,eAAeI;AAAAA,YAClC;AAGEiB,gBAAmBF,mBAAAA,KAAK,MAC1Bf,UAAUe,MAAMG,KAAKC;AAAAA,QAAAA;AAAAA;AAI7B;ACjDO,SAASC,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUf,WAAWe,UAAUd,SAASc,UAAUb,QAJ3C;AAMX;ACdO,SAASc,uBAMdD,WAAoD;AACpD,SAAKA,YAKHA,UAAUf,WAAWe,UAAUb,QAAQa,UAAUd,SAJ1C;AAMX;ACVO,SAASgB,4BAA4B;AAAA,EAC1C7B;AAAAA,EACAE;AAIF,GAA4B;AAExBA,SAAAA,eAAeG,KAAKoB,WAAW,KAC/BR,gCAAef,eAAeG,KAAK,CAAC,CAAC,IAE9B;AAAA,IACLA,MAAM,CAAC;AAAA,MAACD,MAAMF,eAAeG,KAAK,CAAC,EAAED;AAAAA,IAAAA,CAAK;AAAA,IAC1CE,QAAQJ,eAAeI;AAAAA,MAIpBS,iCAAiC;AAAA,IACtCf;AAAAA,IACAE;AAAAA,EAAAA,CACD;AACH;;;;;;;;"}
@@ -14,7 +14,7 @@ import isPlainObject from "lodash/isPlainObject.js";
14
14
  import uniq from "lodash/uniq.js";
15
15
  import getRandomValues from "get-random-values-esm";
16
16
  import { parseBlock, parseAnnotation, isTextBlock, parseInlineObject } from "./parse-blocks.js";
17
- import { sliceBlocks, blockOffsetToSpanSelectionPoint, isEmptyTextBlock, getBlockEndPoint, getBlockStartPoint, getTextBlockText } from "./util.slice-blocks.js";
17
+ import { sliceBlocks, blockOffsetToSpanSelectionPoint, isEmptyTextBlock, getBlockEndPoint, getBlockStartPoint, isEqualSelectionPoints, getTextBlockText } from "./util.slice-blocks.js";
18
18
  import { htmlToBlocks } from "@portabletext/block-tools";
19
19
  import { toHTML } from "@portabletext/to-html";
20
20
  import { Schema } from "@sanity/schema";
@@ -22,12 +22,12 @@ import get from "lodash/get.js";
22
22
  import isUndefined from "lodash/isUndefined.js";
23
23
  import omitBy from "lodash/omitBy.js";
24
24
  import omit from "lodash/omit.js";
25
- import { selectionPointToBlockOffset, blockOffsetsToSelection } from "./util.selection-point-to-block-offset.js";
25
+ import { selectionPointToBlockOffset, blockOffsetsToSelection, getSelectionStartPoint, getSelectionEndPoint } from "./util.selection-point-to-block-offset.js";
26
26
  import { getTrimmedSelection, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, isSelectingEntireBlocks, getActiveAnnotations } from "./selector.is-selecting-entire-blocks.js";
27
27
  import { DOMEditor } from "slate-dom";
28
28
  import startCase from "lodash.startcase";
29
29
  import { defineBehavior, raise, coreBehaviors } from "./behavior.core.js";
30
- import { getFocusTextBlock, getPreviousBlock, getNextBlock, getFocusSpan, isSelectionCollapsed, isOverlappingSelection, getSelectedBlocks, isSelectionExpanded } from "./selector.is-overlapping-selection.js";
30
+ import { getFocusTextBlock, getPreviousBlock, getNextBlock, isSelectionExpanded, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusBlockObject, getFocusSpan, isSelectionCollapsed, isOverlappingSelection, getSelectedBlocks } from "./selector.is-overlapping-selection.js";
31
31
  import { Subject } from "rxjs";
32
32
  import { useEffectEvent } from "use-effect-event";
33
33
  const rootName = "sanity-pte:";
@@ -3991,69 +3991,6 @@ const moveBackwardActionImplementation = ({
3991
3991
  }) => {
3992
3992
  const newSelection = toSlateRange(action.at, action.editor);
3993
3993
  newSelection ? Transforms.select(action.editor, newSelection) : Transforms.deselect(action.editor);
3994
- }, splitBlockActionImplementation = ({
3995
- context,
3996
- action
3997
- }) => {
3998
- const keyGenerator = context.keyGenerator, schema = context.schema, editor = action.editor;
3999
- if (!editor.selection)
4000
- return;
4001
- const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
4002
- if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
4003
- Transforms.splitNodes(editor, {
4004
- at: editor.selection,
4005
- always: !0
4006
- });
4007
- const [nextBlock, nextBlockPath] = Editor.node(editor, Path.next(focusBlockPath), {
4008
- depth: 1
4009
- }), nextChild = Node.child(nextBlock, 0);
4010
- if (!editor.isTextSpan(nextChild) && Transforms.insertNodes(editor, {
4011
- _key: context.keyGenerator(),
4012
- _type: "span",
4013
- text: "",
4014
- marks: []
4015
- }, {
4016
- at: [nextBlockPath[0], 0]
4017
- }), Transforms.setSelection(editor, {
4018
- anchor: {
4019
- path: [...nextBlockPath, 0],
4020
- offset: 0
4021
- },
4022
- focus: {
4023
- path: [...nextBlockPath, 0],
4024
- offset: 0
4025
- }
4026
- }), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
4027
- const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = Node.children(editor, nextBlockPath);
4028
- for (const [child, childPath] of children) {
4029
- if (!editor.isTextSpan(child))
4030
- continue;
4031
- const marks = child.marks ?? [];
4032
- for (const mark of marks)
4033
- schema.decorators.some((decorator) => decorator.name === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
4034
- const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
4035
- isEqual(marks, newMarks) || Transforms.setNodes(editor, {
4036
- marks: newMarks
4037
- }, {
4038
- at: childPath
4039
- });
4040
- }
4041
- const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
4042
- ...markDef,
4043
- _key: newMarkDefKeys.get(markDef._key) ?? markDef._key
4044
- }));
4045
- isEqual(nextBlock.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
4046
- markDefs: newMarkDefs
4047
- }, {
4048
- at: nextBlockPath,
4049
- match: (node) => editor.isTextBlock(node)
4050
- });
4051
- }
4052
- return;
4053
- }
4054
- Transforms.splitNodes(editor, {
4055
- always: !0
4056
- });
4057
3994
  }, debug$a = debugWithName("behaviors:action"), behaviorActionImplementations = {
4058
3995
  "annotation.add": addAnnotationActionImplementation,
4059
3996
  "annotation.remove": removeAnnotationActionImplementation,
@@ -4076,8 +4013,7 @@ const moveBackwardActionImplementation = ({
4076
4013
  "move.block": moveBlockActionImplementation,
4077
4014
  "move.forward": moveForwardActionImplementation,
4078
4015
  noop: noopActionImplementation,
4079
- select: selectActionImplementation,
4080
- "split.block": splitBlockActionImplementation
4016
+ select: selectActionImplementation
4081
4017
  };
4082
4018
  function performAction({
4083
4019
  context,
@@ -4226,13 +4162,6 @@ function performAction({
4226
4162
  }
4227
4163
  case "noop":
4228
4164
  break;
4229
- case "split.block": {
4230
- behaviorActionImplementations["split.block"]({
4231
- context,
4232
- action
4233
- });
4234
- break;
4235
- }
4236
4165
  default: {
4237
4166
  behaviorActionImplementations.select({
4238
4167
  context,
@@ -6183,6 +6112,108 @@ const EditorActorContext = createContext({}), abstractAnnotationBehaviors = [def
6183
6112
  type: "select",
6184
6113
  at: selection
6185
6114
  })]]
6115
+ })], abstractSplitBehaviors = [defineBehavior({
6116
+ on: "split.block",
6117
+ guard: ({
6118
+ snapshot
6119
+ }) => {
6120
+ if (!snapshot.context.selection || !isSelectionExpanded(snapshot))
6121
+ return !1;
6122
+ const firstBlock = getFirstBlock$1(snapshot), lastBlock = getLastBlock$1(snapshot);
6123
+ if (!firstBlock || !lastBlock)
6124
+ return !1;
6125
+ const firstBlockStartPoint = getBlockStartPoint(firstBlock), selectionStartPoint = getSelectionStartPoint(snapshot.context.selection), lastBlockEndPoint = getBlockEndPoint(lastBlock), selectionEndPoint = getSelectionEndPoint(snapshot.context.selection);
6126
+ return isEqualSelectionPoints(firstBlockStartPoint, selectionStartPoint) && isEqualSelectionPoints(lastBlockEndPoint, selectionEndPoint) ? {
6127
+ selection: snapshot.context.selection
6128
+ } : !1;
6129
+ },
6130
+ actions: [(_, {
6131
+ selection
6132
+ }) => [raise({
6133
+ type: "delete",
6134
+ at: selection
6135
+ })]]
6136
+ }), defineBehavior({
6137
+ on: "split.block",
6138
+ guard: ({
6139
+ snapshot
6140
+ }) => {
6141
+ if (!snapshot.context.selection)
6142
+ return !1;
6143
+ const selectionStartPoint = getSelectionStartPoint(snapshot.context.selection), selectionEndPoint = getSelectionEndPoint(snapshot.context.selection), focusTextBlock = getFocusTextBlock({
6144
+ context: {
6145
+ ...snapshot.context,
6146
+ selection: {
6147
+ anchor: selectionStartPoint,
6148
+ focus: selectionEndPoint
6149
+ }
6150
+ }
6151
+ });
6152
+ if (focusTextBlock) {
6153
+ const blockEndPoint = getBlockEndPoint(focusTextBlock), newTextBlockSelection = {
6154
+ anchor: selectionEndPoint,
6155
+ focus: blockEndPoint
6156
+ }, newTextBlock = parseBlock({
6157
+ block: sliceBlocks({
6158
+ blocks: [focusTextBlock.node],
6159
+ selection: newTextBlockSelection
6160
+ }).at(0),
6161
+ context: snapshot.context,
6162
+ options: {
6163
+ refreshKeys: !0
6164
+ }
6165
+ });
6166
+ return !newTextBlock || !isTextBlock(snapshot.context.schema, newTextBlock) ? !1 : {
6167
+ newTextBlock,
6168
+ newTextBlockSelection,
6169
+ selection: {
6170
+ anchor: selectionStartPoint,
6171
+ focus: blockEndPoint
6172
+ }
6173
+ };
6174
+ }
6175
+ if (getFocusBlockObject({
6176
+ context: {
6177
+ ...snapshot.context,
6178
+ selection: {
6179
+ anchor: selectionStartPoint,
6180
+ focus: selectionEndPoint
6181
+ }
6182
+ }
6183
+ })) {
6184
+ const newTextBlock = parseBlock({
6185
+ block: {
6186
+ _type: snapshot.context.schema.block.name,
6187
+ children: []
6188
+ },
6189
+ context: snapshot.context,
6190
+ options: {
6191
+ refreshKeys: !0
6192
+ }
6193
+ });
6194
+ return newTextBlock ? {
6195
+ newTextBlock,
6196
+ newTextBlockSelection: {
6197
+ anchor: selectionEndPoint,
6198
+ focus: selectionEndPoint
6199
+ },
6200
+ selection: snapshot.context.selection
6201
+ } : !1;
6202
+ }
6203
+ return !1;
6204
+ },
6205
+ actions: [(_, {
6206
+ newTextBlock,
6207
+ selection
6208
+ }) => [raise({
6209
+ type: "delete",
6210
+ at: selection
6211
+ }), raise({
6212
+ type: "insert.block",
6213
+ block: newTextBlock,
6214
+ placement: "after",
6215
+ select: "start"
6216
+ })]]
6186
6217
  })], abstractStyleBehaviors = [defineBehavior({
6187
6218
  on: "style.add",
6188
6219
  guard: ({
@@ -6594,10 +6625,11 @@ const EditorActorContext = createContext({}), abstractAnnotationBehaviors = [def
6594
6625
  ...abstractMoveBehaviors,
6595
6626
  ...abstractStyleBehaviors,
6596
6627
  ...abstractSelectBehaviors,
6628
+ ...abstractSplitBehaviors,
6597
6629
  raiseDeserializationSuccessOrFailure,
6598
6630
  raiseSerializationSuccessOrFailure,
6599
6631
  raiseInsertSoftBreak
6600
- ], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "style.add", "style.remove", "style.toggle"];
6632
+ ], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "split.block", "style.add", "style.remove", "style.toggle"];
6601
6633
  function isAbstractBehaviorEvent(event) {
6602
6634
  return abstractBehaviorEventTypes.includes(event.type);
6603
6635
  }