@portabletext/editor 2.13.3 → 2.13.4

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 (187) hide show
  1. package/lib/_chunks-cjs/{selector.is-selection-expanded.cjs → selector.get-selection-text.cjs} +25 -25
  2. package/lib/_chunks-cjs/selector.get-selection-text.cjs.map +1 -0
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +4 -4
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/{selector.is-selecting-entire-blocks.cjs → selector.is-active-style.cjs} +408 -399
  6. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
  7. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +3 -3
  8. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
  9. package/lib/_chunks-cjs/{util.slice-blocks.cjs → util.get-text-block-text.cjs} +25 -26
  10. package/lib/_chunks-cjs/util.get-text-block-text.cjs.map +1 -0
  11. package/lib/_chunks-cjs/{util.is-selection-collapsed.cjs → util.is-empty-text-block.cjs} +9 -9
  12. package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -0
  13. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +2 -2
  14. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  15. package/lib/_chunks-cjs/util.slice-text-block.cjs +5 -5
  16. package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -1
  17. package/lib/_chunks-dts/behavior.types.action.d.cts +270 -270
  18. package/lib/_chunks-dts/behavior.types.action.d.ts +315 -315
  19. package/lib/_chunks-es/{selector.is-selection-expanded.js → selector.get-selection-text.js} +20 -20
  20. package/lib/_chunks-es/selector.get-selection-text.js.map +1 -0
  21. package/lib/_chunks-es/selector.get-text-before.js +2 -2
  22. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  23. package/lib/_chunks-es/{selector.is-selecting-entire-blocks.js → selector.is-active-style.js} +385 -376
  24. package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
  25. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +1 -1
  26. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
  27. package/lib/_chunks-es/{util.slice-blocks.js → util.get-text-block-text.js} +25 -26
  28. package/lib/_chunks-es/util.get-text-block-text.js.map +1 -0
  29. package/lib/_chunks-es/{util.is-selection-collapsed.js → util.is-empty-text-block.js} +8 -8
  30. package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
  31. package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
  32. package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
  33. package/lib/_chunks-es/util.slice-text-block.js +1 -1
  34. package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
  35. package/lib/index.cjs +225 -225
  36. package/lib/index.cjs.map +1 -1
  37. package/lib/index.js +18 -18
  38. package/lib/index.js.map +1 -1
  39. package/lib/plugins/index.cjs +21 -21
  40. package/lib/plugins/index.cjs.map +1 -1
  41. package/lib/plugins/index.d.cts +4 -4
  42. package/lib/plugins/index.d.ts +4 -4
  43. package/lib/plugins/index.js +3 -3
  44. package/lib/plugins/index.js.map +1 -1
  45. package/lib/selectors/index.cjs +52 -52
  46. package/lib/selectors/index.cjs.map +1 -1
  47. package/lib/selectors/index.js +5 -5
  48. package/lib/selectors/index.js.map +1 -1
  49. package/lib/utils/index.cjs +14 -14
  50. package/lib/utils/index.cjs.map +1 -1
  51. package/lib/utils/index.d.cts +2 -2
  52. package/lib/utils/index.d.ts +2 -2
  53. package/lib/utils/index.js +3 -3
  54. package/lib/utils/index.js.map +1 -1
  55. package/package.json +12 -12
  56. package/src/behaviors/behavior.abstract.annotation.ts +3 -3
  57. package/src/behaviors/behavior.abstract.decorator.ts +2 -2
  58. package/src/behaviors/behavior.abstract.delete.ts +25 -16
  59. package/src/behaviors/behavior.abstract.deserialize.ts +4 -3
  60. package/src/behaviors/behavior.abstract.insert.ts +6 -7
  61. package/src/behaviors/behavior.abstract.keyboard.ts +7 -8
  62. package/src/behaviors/behavior.abstract.list-item.ts +2 -1
  63. package/src/behaviors/behavior.abstract.move.ts +2 -1
  64. package/src/behaviors/behavior.abstract.select.ts +4 -2
  65. package/src/behaviors/behavior.abstract.split.ts +33 -24
  66. package/src/behaviors/behavior.abstract.style.ts +2 -1
  67. package/src/behaviors/behavior.abstract.ts +8 -7
  68. package/src/behaviors/behavior.core.annotations.ts +8 -7
  69. package/src/behaviors/behavior.core.block-element.ts +7 -5
  70. package/src/behaviors/behavior.core.block-objects.ts +25 -27
  71. package/src/behaviors/behavior.core.dnd.ts +10 -8
  72. package/src/behaviors/behavior.core.insert-break.ts +45 -36
  73. package/src/behaviors/behavior.core.lists.ts +31 -25
  74. package/src/behaviors/behavior.decorator-pair.ts +26 -23
  75. package/src/behaviors/behavior.markdown.ts +26 -21
  76. package/src/converters/converter.portable-text.ts +3 -3
  77. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  78. package/src/converters/converter.text-html.ts +3 -3
  79. package/src/converters/converter.text-plain.test.ts +1 -1
  80. package/src/converters/converter.text-plain.ts +3 -3
  81. package/src/editor/Editable.tsx +2 -2
  82. package/src/editor/components/render-span.tsx +3 -5
  83. package/src/editor/create-editor.ts +2 -2
  84. package/src/editor/create-slate-editor.tsx +1 -4
  85. package/src/editor/editor-dom.ts +2 -2
  86. package/src/editor/plugins/createWithEditableAPI.ts +5 -10
  87. package/src/editor/plugins/createWithMaxBlocks.ts +2 -2
  88. package/src/editor/plugins/createWithObjectKeys.ts +2 -2
  89. package/src/editor/plugins/createWithPatches.ts +3 -10
  90. package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -2
  91. package/src/editor/plugins/createWithPortableTextMarkModel.ts +2 -2
  92. package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
  93. package/src/editor/plugins/createWithUndoRedo.ts +6 -6
  94. package/src/editor/plugins/slate-plugin.update-selection.ts +1 -1
  95. package/src/editor/sync-machine.ts +2 -5
  96. package/src/{internal-utils → editor}/weakMaps.ts +1 -1
  97. package/src/editor/with-undo-step.ts +1 -1
  98. package/src/index.ts +1 -1
  99. package/src/internal-utils/applyPatch.ts +2 -2
  100. package/src/internal-utils/build-index-maps.test.ts +1 -1
  101. package/src/internal-utils/create-test-snapshot.ts +1 -1
  102. package/src/internal-utils/event-position.ts +11 -9
  103. package/src/internal-utils/operation-to-patches.test.ts +1 -1
  104. package/src/internal-utils/portable-text-node.ts +1 -1
  105. package/src/internal-utils/selection-block-keys.ts +1 -1
  106. package/src/internal-utils/selection-focus-text.ts +1 -1
  107. package/src/internal-utils/to-slate-range.ts +4 -4
  108. package/src/operations/behavior.operation.annotation.add.ts +1 -1
  109. package/src/operations/behavior.operation.block.set.ts +1 -1
  110. package/src/operations/behavior.operation.block.unset.ts +2 -2
  111. package/src/operations/behavior.operation.decorator.add.ts +11 -9
  112. package/src/operations/behavior.operation.delete.ts +1 -1
  113. package/src/operations/behavior.operation.insert.block.ts +2 -2
  114. package/src/operations/behavior.operation.insert.child.ts +1 -1
  115. package/src/operations/behavior.operation.move.block.ts +1 -1
  116. package/src/plugins/plugin.behavior.tsx +1 -1
  117. package/src/plugins/plugin.decorator-shortcut.ts +3 -3
  118. package/src/plugins/plugin.internal.auto-close-brackets.ts +2 -1
  119. package/src/plugins/plugin.one-line.tsx +11 -11
  120. package/src/priority/priority.types.ts +1 -1
  121. package/src/{internal-utils → selectors}/drag-selection.test.ts +1 -1
  122. package/src/{internal-utils → selectors}/drag-selection.ts +26 -19
  123. package/src/selectors/selector.get-anchor-block.ts +1 -1
  124. package/src/selectors/selector.get-anchor-child.ts +1 -1
  125. package/src/selectors/selector.get-block-offsets.ts +3 -3
  126. package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
  127. package/src/selectors/selector.get-focus-block.ts +1 -1
  128. package/src/selectors/selector.get-focus-child.ts +1 -1
  129. package/src/selectors/selector.get-focus-list-block.ts +1 -1
  130. package/src/selectors/selector.get-list-state.test.ts +1 -1
  131. package/src/selectors/selector.get-mark-state.ts +1 -1
  132. package/src/selectors/selector.get-next-inline-object.ts +1 -1
  133. package/src/selectors/selector.get-next-span.ts +1 -1
  134. package/src/selectors/selector.get-previous-inline-object.ts +1 -1
  135. package/src/selectors/selector.get-previous-span.ts +1 -1
  136. package/src/selectors/selector.get-selected-blocks.ts +1 -1
  137. package/src/selectors/selector.get-selected-spans.test.ts +1 -1
  138. package/src/selectors/selector.get-selected-spans.ts +2 -2
  139. package/src/selectors/selector.get-selected-text-blocks.ts +3 -2
  140. package/src/selectors/selector.get-selected-value.test.ts +87 -1
  141. package/src/selectors/selector.get-selected-value.ts +4 -6
  142. package/src/selectors/selector.get-selection-end-point.ts +1 -1
  143. package/src/selectors/selector.get-selection-start-point.ts +1 -1
  144. package/src/selectors/selector.get-selection-text.test.ts +1 -1
  145. package/src/selectors/selector.get-selection.ts +1 -1
  146. package/src/selectors/selector.get-text-before.ts +1 -1
  147. package/src/selectors/selector.get-trimmed-selection.test.ts +1 -1
  148. package/src/selectors/selector.get-trimmed-selection.ts +5 -7
  149. package/src/selectors/selector.is-active-decorator.test.ts +2 -1
  150. package/src/selectors/selector.is-at-the-end-of-block.ts +4 -3
  151. package/src/selectors/selector.is-at-the-start-of-block.ts +4 -3
  152. package/src/selectors/selector.is-overlapping-selection.test.ts +1 -1
  153. package/src/selectors/selector.is-overlapping-selection.ts +1 -1
  154. package/src/selectors/selector.is-point-after-selection.ts +3 -3
  155. package/src/selectors/selector.is-point-before-selection.ts +3 -3
  156. package/src/selectors/selector.is-selecting-entire-blocks.ts +7 -5
  157. package/src/test/gherkin-parameter-types.ts +1 -1
  158. package/src/test/vitest/step-definitions.tsx +19 -9
  159. package/src/types/paths.ts +4 -1
  160. package/src/utils/util.at-the-beginning-of-block.ts +1 -1
  161. package/src/utils/util.block-offset.ts +4 -4
  162. package/src/utils/util.block-offsets-to-selection.ts +1 -1
  163. package/src/utils/util.child-selection-point-to-block-offset.ts +3 -3
  164. package/src/utils/util.get-selection-end-point.ts +1 -1
  165. package/src/utils/util.get-selection-start-point.ts +1 -1
  166. package/src/utils/util.merge-text-blocks.ts +2 -2
  167. package/src/utils/util.selection-point-to-block-offset.ts +1 -1
  168. package/src/{selection/selection-point.ts → utils/util.selection-point.ts} +1 -1
  169. package/src/utils/util.slice-blocks.ts +6 -6
  170. package/src/utils/util.slice-text-block.test.ts +3 -1
  171. package/src/utils/util.slice-text-block.ts +3 -3
  172. package/src/utils/util.split-text-block.ts +1 -1
  173. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +0 -1
  174. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
  175. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +0 -1
  176. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
  177. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
  178. package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
  179. package/lib/_chunks-es/util.is-selection-collapsed.js.map +0 -1
  180. package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
  181. /package/src/{internal-utils → editor}/withChanges.ts +0 -0
  182. /package/src/{internal-utils → editor}/withUndoRedo.ts +0 -0
  183. /package/src/{internal-utils → editor}/withoutPatching.ts +0 -0
  184. /package/src/{internal-utils → utils}/asserters.ts +0 -0
  185. /package/src/{editor → utils}/key-generator.ts +0 -0
  186. /package/src/{internal-utils → utils}/parse-blocks.test.ts +0 -0
  187. /package/src/{internal-utils → utils}/parse-blocks.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"util.slice-text-block.cjs","sources":["../../src/utils/util.selection-point-to-block-offset.ts","../../src/utils/util.slice-text-block.ts"],"sourcesContent":["import type {EditorContext} from '../editor/editor-snapshot'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'\n\n/**\n * @public\n */\nexport function selectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n\n if (selectionPoint.path.length === 1 && blockKey !== undefined) {\n return {\n path: [{_key: blockKey}],\n offset: selectionPoint.offset,\n }\n }\n\n return childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n })\n}\n","import {isSpan} from '@portabletext/schema'\nimport type {PortableTextChild, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport {getSelectionEndPoint} from './util.get-selection-end-point'\nimport {getSelectionStartPoint} from './util.get-selection-start-point'\n\nexport function sliceTextBlock({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n block: PortableTextTextBlock\n}): PortableTextTextBlock {\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n\n if (!startPoint || !endPoint) {\n return block\n }\n\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (startBlockKey !== endBlockKey || startBlockKey !== block._key) {\n return block\n }\n\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startChildKey || !endChildKey) {\n return block\n }\n\n let startChildFound = false\n const children: Array<PortableTextChild> = []\n\n for (const child of block.children) {\n if (child._key === startChildKey) {\n startChildFound = true\n\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 children.push({\n ...child,\n text,\n })\n } else {\n children.push(child)\n }\n\n if (startChildKey === endChildKey) {\n break\n }\n\n continue\n }\n\n if (child._key === endChildKey) {\n if (isSpan(context, child)) {\n children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n children.push(child)\n }\n\n break\n }\n\n if (startChildFound) {\n children.push(child)\n }\n }\n\n return {\n ...block,\n children,\n }\n}\n"],"names":["selectionPointToBlockOffset","context","selectionPoint","blockKey","getBlockKeyFromSelectionPoint","path","length","undefined","_key","offset","childSelectionPointToBlockOffset","sliceTextBlock","block","startPoint","getSelectionStartPoint","selection","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startChildKey","getChildKeyFromSelectionPoint","endChildKey","startChildFound","children","child","isSpan","text","slice","push"],"mappings":";;AASO,SAASA,4BAA4B;AAAA,EAC1CC;AAAAA,EACAC;AAIF,GAA4B;AAC1B,QAAMC,WAAWC,iBAAAA,8BAA8BF,cAAc;AAE7D,SAAIA,eAAeG,KAAKC,WAAW,KAAKH,aAAaI,SAC5C;AAAA,IACLF,MAAM,CAAC;AAAA,MAACG,MAAML;AAAAA,IAAAA,CAAS;AAAA,IACvBM,QAAQP,eAAeO;AAAAA,EAAAA,IAIpBC,uEAAiC;AAAA,IACtCT;AAAAA,IACAC;AAAAA,EAAAA,CACD;AACH;ACnBO,SAASS,eAAe;AAAA,EAC7BV;AAAAA,EACAW;AAIF,GAA0B;AACxB,QAAMC,aAAaC,iBAAAA,uBAAuBb,QAAQc,SAAS,GACrDC,WAAWC,iBAAAA,qBAAqBhB,QAAQc,SAAS;AAEvD,MAAI,CAACF,cAAc,CAACG;AAClB,WAAOJ;AAGT,QAAMM,gBAAgBd,iBAAAA,8BAA8BS,UAAU,GACxDM,cAAcf,iBAAAA,8BAA8BY,QAAQ;AAE1D,MAAIE,kBAAkBC,eAAeD,kBAAkBN,MAAMJ;AAC3D,WAAOI;AAGT,QAAMQ,gBAAgBC,iBAAAA,8BAA8BR,UAAU,GACxDS,cAAcD,iBAAAA,8BAA8BL,QAAQ;AAE1D,MAAI,CAACI,iBAAiB,CAACE;AACrB,WAAOV;AAGT,MAAIW,kBAAkB;AACtB,QAAMC,WAAqC,CAAA;AAE3C,aAAWC,SAASb,MAAMY,UAAU;AAClC,QAAIC,MAAMjB,SAASY,eAAe;AAGhC,UAFAG,kBAAkB,IAEdG,OAAAA,OAAOzB,SAASwB,KAAK,GAAG;AAC1B,cAAME,OACJF,MAAMjB,SAASc,cACXG,MAAME,KAAKC,MAAMf,WAAWJ,QAAQO,SAASP,MAAM,IACnDgB,MAAME,KAAKC,MAAMf,WAAWJ,MAAM;AAExCe,iBAASK,KAAK;AAAA,UACZ,GAAGJ;AAAAA,UACHE;AAAAA,QAAAA,CACD;AAAA,MACH;AACEH,iBAASK,KAAKJ,KAAK;AAGrB,UAAIL,kBAAkBE;AACpB;AAGF;AAAA,IACF;AAEA,QAAIG,MAAMjB,SAASc,aAAa;AAC1BI,aAAAA,OAAOzB,SAASwB,KAAK,IACvBD,SAASK,KAAK;AAAA,QACZ,GAAGJ;AAAAA,QACHE,MAAMF,MAAME,KAAKC,MAAM,GAAGZ,SAASP,MAAM;AAAA,MAAA,CAC1C,IAEDe,SAASK,KAAKJ,KAAK;AAGrB;AAAA,IACF;AAEIF,uBACFC,SAASK,KAAKJ,KAAK;AAAA,EAEvB;AAEA,SAAO;AAAA,IACL,GAAGb;AAAAA,IACHY;AAAAA,EAAAA;AAEJ;;;"}
1
+ {"version":3,"file":"util.slice-text-block.cjs","sources":["../../src/utils/util.selection-point-to-block-offset.ts","../../src/utils/util.slice-text-block.ts"],"sourcesContent":["import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'\nimport {getBlockKeyFromSelectionPoint} from './util.selection-point'\n\n/**\n * @public\n */\nexport function selectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n\n if (selectionPoint.path.length === 1 && blockKey !== undefined) {\n return {\n path: [{_key: blockKey}],\n offset: selectionPoint.offset,\n }\n }\n\n return childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n })\n}\n","import {isSpan} from '@portabletext/schema'\nimport type {PortableTextChild, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {getSelectionEndPoint} from './util.get-selection-end-point'\nimport {getSelectionStartPoint} from './util.get-selection-start-point'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\nexport function sliceTextBlock({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n block: PortableTextTextBlock\n}): PortableTextTextBlock {\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n\n if (!startPoint || !endPoint) {\n return block\n }\n\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (startBlockKey !== endBlockKey || startBlockKey !== block._key) {\n return block\n }\n\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startChildKey || !endChildKey) {\n return block\n }\n\n let startChildFound = false\n const children: Array<PortableTextChild> = []\n\n for (const child of block.children) {\n if (child._key === startChildKey) {\n startChildFound = true\n\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 children.push({\n ...child,\n text,\n })\n } else {\n children.push(child)\n }\n\n if (startChildKey === endChildKey) {\n break\n }\n\n continue\n }\n\n if (child._key === endChildKey) {\n if (isSpan(context, child)) {\n children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n children.push(child)\n }\n\n break\n }\n\n if (startChildFound) {\n children.push(child)\n }\n }\n\n return {\n ...block,\n children,\n }\n}\n"],"names":["selectionPointToBlockOffset","context","selectionPoint","blockKey","getBlockKeyFromSelectionPoint","path","length","undefined","_key","offset","childSelectionPointToBlockOffset","sliceTextBlock","block","startPoint","getSelectionStartPoint","selection","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startChildKey","getChildKeyFromSelectionPoint","endChildKey","startChildFound","children","child","isSpan","text","slice","push"],"mappings":";;AASO,SAASA,4BAA4B;AAAA,EAC1CC;AAAAA,EACAC;AAIF,GAA4B;AAC1B,QAAMC,WAAWC,sBAAAA,8BAA8BF,cAAc;AAE7D,SAAIA,eAAeG,KAAKC,WAAW,KAAKH,aAAaI,SAC5C;AAAA,IACLF,MAAM,CAAC;AAAA,MAACG,MAAML;AAAAA,IAAAA,CAAS;AAAA,IACvBM,QAAQP,eAAeO;AAAAA,EAAAA,IAIpBC,uEAAiC;AAAA,IACtCT;AAAAA,IACAC;AAAAA,EAAAA,CACD;AACH;ACnBO,SAASS,eAAe;AAAA,EAC7BV;AAAAA,EACAW;AAIF,GAA0B;AACxB,QAAMC,aAAaC,sBAAAA,uBAAuBb,QAAQc,SAAS,GACrDC,WAAWC,sBAAAA,qBAAqBhB,QAAQc,SAAS;AAEvD,MAAI,CAACF,cAAc,CAACG;AAClB,WAAOJ;AAGT,QAAMM,gBAAgBd,sBAAAA,8BAA8BS,UAAU,GACxDM,cAAcf,sBAAAA,8BAA8BY,QAAQ;AAE1D,MAAIE,kBAAkBC,eAAeD,kBAAkBN,MAAMJ;AAC3D,WAAOI;AAGT,QAAMQ,gBAAgBC,sBAAAA,8BAA8BR,UAAU,GACxDS,cAAcD,sBAAAA,8BAA8BL,QAAQ;AAE1D,MAAI,CAACI,iBAAiB,CAACE;AACrB,WAAOV;AAGT,MAAIW,kBAAkB;AACtB,QAAMC,WAAqC,CAAA;AAE3C,aAAWC,SAASb,MAAMY,UAAU;AAClC,QAAIC,MAAMjB,SAASY,eAAe;AAGhC,UAFAG,kBAAkB,IAEdG,OAAAA,OAAOzB,SAASwB,KAAK,GAAG;AAC1B,cAAME,OACJF,MAAMjB,SAASc,cACXG,MAAME,KAAKC,MAAMf,WAAWJ,QAAQO,SAASP,MAAM,IACnDgB,MAAME,KAAKC,MAAMf,WAAWJ,MAAM;AAExCe,iBAASK,KAAK;AAAA,UACZ,GAAGJ;AAAAA,UACHE;AAAAA,QAAAA,CACD;AAAA,MACH;AACEH,iBAASK,KAAKJ,KAAK;AAGrB,UAAIL,kBAAkBE;AACpB;AAGF;AAAA,IACF;AAEA,QAAIG,MAAMjB,SAASc,aAAa;AAC1BI,aAAAA,OAAOzB,SAASwB,KAAK,IACvBD,SAASK,KAAK;AAAA,QACZ,GAAGJ;AAAAA,QACHE,MAAMF,MAAME,KAAKC,MAAM,GAAGZ,SAASP,MAAM;AAAA,MAAA,CAC1C,IAEDe,SAASK,KAAKJ,KAAK;AAGrB;AAAA,IACF;AAEIF,uBACFC,SAASK,KAAKJ,KAAK;AAAA,EAEvB;AAEA,SAAO;AAAA,IACL,GAAGb;AAAAA,IACHY;AAAAA,EAAAA;AAEJ;;;"}
@@ -1,17 +1,18 @@
1
- import { Patch, Patch as Patch$1 } from "@portabletext/patches";
2
1
  import * as _sanity_types5 from "@sanity/types";
3
2
  import { ArrayDefinition, ArraySchemaType, BlockDecoratorDefinition, BlockListDefinition, BlockStyleDefinition, ObjectSchemaType, Path, PortableTextBlock, PortableTextBlock as PortableTextBlock$1, PortableTextChild, PortableTextChild as PortableTextChild$1, PortableTextListBlock, PortableTextObject, PortableTextObject as PortableTextObject$2, PortableTextSpan, PortableTextSpan as PortableTextSpan$2, PortableTextTextBlock, PortableTextTextBlock as PortableTextTextBlock$2, TypedObject } from "@sanity/types";
4
- import * as _portabletext_schema5 from "@portabletext/schema";
5
- import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, DecoratorDefinition, DecoratorSchemaType, FieldDefinition, InlineObjectDefinition, InlineObjectSchemaType, ListDefinition, ListSchemaType, PortableTextObject as PortableTextObject$1, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, defineSchema } from "@portabletext/schema";
3
+ import { BaseRange, Descendant, Operation } from "slate";
6
4
  import * as xstate227 from "xstate";
7
5
  import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
8
- import { BaseRange, Descendant, Operation } from "slate";
9
- import * as react22 from "react";
6
+ import * as react20 from "react";
10
7
  import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, KeyboardEvent as KeyboardEvent$1, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
11
- import * as xstate_guards12 from "xstate/guards";
8
+ import { Patch, Patch as Patch$1 } from "@portabletext/patches";
9
+ import * as _portabletext_schema5 from "@portabletext/schema";
10
+ import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, DecoratorDefinition, DecoratorSchemaType, FieldDefinition, InlineObjectDefinition, InlineObjectSchemaType, ListDefinition, ListSchemaType, PortableTextObject as PortableTextObject$1, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, defineSchema } from "@portabletext/schema";
12
11
  import { Observable, Subject } from "rxjs";
13
12
  import { DOMNode } from "slate-dom";
14
13
  import { ReactEditor } from "slate-react";
14
+ import * as xstate_guards12 from "xstate/guards";
15
+ type MIMEType = `${string}/${string}`;
15
16
  /**
16
17
  * @internal
17
18
  */
@@ -20,30 +21,50 @@ type NamespaceEvent<TEvent, TNamespace extends string> = TEvent extends {
20
21
  type: infer TEventType;
21
22
  } ? { [K in keyof TEvent]: K extends 'type' ? `${TNamespace}.${TEventType & string}` : TEvent[K] } : never;
22
23
  type StrictExtract<T, U extends T> = U;
23
- type TextBlockWithOptionalKey = Omit<PortableTextTextBlock$1, '_key'> & {
24
- _key?: PortableTextTextBlock$1['_key'];
25
- };
26
- type ObjectBlockWithOptionalKey = Omit<PortableTextObject$1, '_key'> & {
27
- _key?: PortableTextObject$1['_key'];
28
- };
29
- type BlockWithOptionalKey = TextBlockWithOptionalKey | ObjectBlockWithOptionalKey;
30
- type SpanWithOptionalKey = Omit<PortableTextSpan$1, '_key'> & {
31
- _key?: PortableTextSpan$1['_key'];
32
- };
33
- type ChildWithOptionalKey = SpanWithOptionalKey | ObjectBlockWithOptionalKey;
34
- type MIMEType = `${string}/${string}`;
35
- type EditorPriority = {
36
- id: string;
37
- name?: string;
38
- reference?: {
39
- priority: EditorPriority;
40
- importance: 'higher' | 'lower';
41
- };
24
+ type Converter<TMIMEType extends MIMEType = MIMEType> = {
25
+ mimeType: TMIMEType;
26
+ serialize: Serializer<TMIMEType>;
27
+ deserialize: Deserializer<TMIMEType>;
42
28
  };
43
- type BehaviorConfig = {
44
- behavior: Behavior;
45
- priority: EditorPriority;
29
+ type ConverterEvent<TMIMEType extends MIMEType = MIMEType> = {
30
+ type: 'serialize';
31
+ originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart';
32
+ } | {
33
+ type: 'serialization.failure';
34
+ mimeType: TMIMEType;
35
+ originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart';
36
+ reason: string;
37
+ } | {
38
+ type: 'serialization.success';
39
+ data: string;
40
+ mimeType: TMIMEType;
41
+ originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart';
42
+ } | {
43
+ type: 'deserialize';
44
+ data: string;
45
+ } | {
46
+ type: 'deserialization.failure';
47
+ mimeType: TMIMEType;
48
+ reason: string;
49
+ } | {
50
+ type: 'deserialization.success';
51
+ data: Array<PortableTextBlock>;
52
+ mimeType: TMIMEType;
46
53
  };
54
+ type Serializer<TMIMEType extends MIMEType> = ({
55
+ snapshot,
56
+ event
57
+ }: {
58
+ snapshot: EditorSnapshot;
59
+ event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialize'>;
60
+ }) => PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialization.success' | 'serialization.failure'>;
61
+ type Deserializer<TMIMEType extends MIMEType> = ({
62
+ snapshot,
63
+ event
64
+ }: {
65
+ snapshot: EditorSnapshot;
66
+ event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>;
67
+ }) => PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialization.success' | 'deserialization.failure'>;
47
68
  /**
48
69
  * @public
49
70
  */
@@ -198,7 +219,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
198
219
  componentDidUpdate(prevProps: PortableTextEditorProps): void;
199
220
  componentWillUnmount(): void;
200
221
  setEditable: (editable: EditableAPI) => void;
201
- render(): react22.JSX.Element;
222
+ render(): react20.JSX.Element;
202
223
  /**
203
224
  * @deprecated
204
225
  * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
@@ -593,7 +614,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
593
614
  * ```
594
615
  * @group Components
595
616
  */
596
- declare const PortableTextEditable: react22.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react22.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
617
+ declare const PortableTextEditable: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
597
618
  type DecoratedRange = BaseRange & {
598
619
  rangeDecoration: RangeDecoration;
599
620
  };
@@ -1095,50 +1116,221 @@ type EditorSnapshot = {
1095
1116
  */
1096
1117
  decoratorState: Record<string, boolean | undefined>;
1097
1118
  };
1098
- type Converter<TMIMEType extends MIMEType = MIMEType> = {
1099
- mimeType: TMIMEType;
1100
- serialize: Serializer<TMIMEType>;
1101
- deserialize: Deserializer<TMIMEType>;
1119
+ /**
1120
+ * @beta
1121
+ */
1122
+ type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
1123
+ snapshot: EditorSnapshot;
1124
+ event: TBehaviorEvent;
1125
+ dom: EditorDom;
1126
+ }) => TGuardResponse | false;
1127
+ /**
1128
+ * @beta
1129
+ */
1130
+ type Behavior<TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'] = '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'], TGuardResponse = true, TBehaviorEvent extends ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>> = {
1131
+ /**
1132
+ * Editor Event that triggers this Behavior.
1133
+ */
1134
+ on: TBehaviorEventType;
1135
+ /**
1136
+ * Predicate function that determines if the Behavior should be executed.
1137
+ * Returning a non-nullable value from the guard will pass the value to the
1138
+ * actions and execute them.
1139
+ */
1140
+ guard?: BehaviorGuard<TBehaviorEvent, TGuardResponse>;
1141
+ /**
1142
+ * Array of Behavior Action sets.
1143
+ * Each set represents a step in the history stack.
1144
+ */
1145
+ actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>;
1146
+ };
1147
+ /**
1148
+ * @beta
1149
+ *
1150
+ * @example
1151
+ *
1152
+ * ```tsx
1153
+ * const noLowerCaseA = defineBehavior({
1154
+ * on: 'insert.text',
1155
+ * guard: ({event, snapshot}) => event.text === 'a',
1156
+ * actions: [({event, snapshot}) => [{type: 'insert.text', text: 'A'}]],
1157
+ * })
1158
+ * ```
1159
+ *
1160
+ */
1161
+ declare function defineBehavior<TPayload extends Record<string, unknown>, TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'] = CustomBehaviorEvent['type'], TGuardResponse = true>(behavior: Behavior<TBehaviorEventType, TGuardResponse, ResolveBehaviorEvent<TBehaviorEventType, TPayload>>): Behavior;
1162
+ /**
1163
+ * @public
1164
+ */
1165
+ type EditorConfig = {
1166
+ /**
1167
+ * @beta
1168
+ */
1169
+ keyGenerator?: () => string;
1170
+ /**
1171
+ * @deprecated Will be removed in the next major version
1172
+ */
1173
+ maxBlocks?: number;
1174
+ readOnly?: boolean;
1175
+ initialValue?: Array<PortableTextBlock>;
1176
+ } & ({
1177
+ schemaDefinition: SchemaDefinition;
1178
+ schema?: undefined;
1179
+ } | {
1180
+ schemaDefinition?: undefined;
1181
+ schema: ArraySchemaType<PortableTextBlock> | ArrayDefinition;
1182
+ });
1183
+ /**
1184
+ * @public
1185
+ */
1186
+ type EditorEvent = ExternalEditorEvent | ExternalBehaviorEvent | {
1187
+ type: 'update value';
1188
+ value: Array<PortableTextBlock> | undefined;
1189
+ };
1190
+ /**
1191
+ * @public
1192
+ */
1193
+ type Editor = {
1194
+ dom: EditorDom;
1195
+ getSnapshot: () => EditorSnapshot;
1196
+ /**
1197
+ * @beta
1198
+ */
1199
+ registerBehavior: (config: {
1200
+ behavior: Behavior;
1201
+ }) => () => void;
1202
+ send: (event: EditorEvent) => void;
1203
+ on: ActorRef<Snapshot<unknown>, EventObject, EditorEmittedEvent>['on'];
1204
+ };
1205
+ /**
1206
+ * @public
1207
+ * @deprecated
1208
+ * This component has been renamed. Use `EventListenerPlugin` instead.
1209
+ *
1210
+ * ```
1211
+ * import {EventListenerPlugin} from '@portabletext/editor/plugins'
1212
+ * ```
1213
+ */
1214
+ declare function EditorEventListener(props: {
1215
+ on: (event: EditorEmittedEvent) => void;
1216
+ }): null;
1217
+ /**
1218
+ * @public
1219
+ */
1220
+ type EditorProviderProps = {
1221
+ initialConfig: EditorConfig;
1222
+ children?: React$1.ReactNode;
1223
+ };
1224
+ /**
1225
+ * @public
1226
+ * The EditorProvider component is used to set up the editor context and configure the Portable Text Editor.
1227
+ * @example
1228
+ * ```tsx
1229
+ * import {EditorProvider} from '@portabletext/editor'
1230
+ *
1231
+ * function App() {
1232
+ * return (
1233
+ * <EditorProvider initialConfig={{ ... }} >
1234
+ * ...
1235
+ * </EditorProvider>
1236
+ * )
1237
+ * }
1238
+ *
1239
+ * ```
1240
+ * @group Components
1241
+ */
1242
+ declare function EditorProvider(props: EditorProviderProps): React$1.JSX.Element;
1243
+ /**
1244
+ * @public
1245
+ */
1246
+ type EditorSelector<TSelected> = (snapshot: EditorSnapshot) => TSelected;
1247
+ /**
1248
+ * @public
1249
+ * Hook to select a value from the editor state.
1250
+ * @example
1251
+ * Pass a selector as the second argument
1252
+ * ```tsx
1253
+ * import { useEditorSelector } from '@portabletext/editor'
1254
+ *
1255
+ * function MyComponent(editor) {
1256
+ * const value = useEditorSelector(editor, selector)
1257
+ * }
1258
+ * ```
1259
+ * @example
1260
+ * Pass an inline selector as the second argument.
1261
+ * In this case, use the editor context to obtain the schema.
1262
+ * ```tsx
1263
+ * import { useEditorSelector } from '@portabletext/editor'
1264
+ *
1265
+ * function MyComponent(editor) {
1266
+ * const schema = useEditorSelector(editor, (snapshot) => snapshot.context.schema)
1267
+ * }
1268
+ * ```
1269
+ * @group Hooks
1270
+ */
1271
+ declare function useEditorSelector<TSelected>(editor: Editor, selector: EditorSelector<TSelected>, compare?: (a: TSelected, b: TSelected) => boolean): TSelected;
1272
+ /**
1273
+ * @deprecated Use `useEditor` to get the current editor instance.
1274
+ * @public
1275
+ * Get the current editor object from the React context.
1276
+ */
1277
+ declare const usePortableTextEditor: () => PortableTextEditor;
1278
+ /**
1279
+ * @deprecated Use `useEditorSelector` to get the current editor selection.
1280
+ * @public
1281
+ * Get the current editor selection from the React context.
1282
+ */
1283
+ declare const usePortableTextEditorSelection: () => EditorSelection;
1284
+ /**
1285
+ * @public
1286
+ */
1287
+ declare const defaultKeyGenerator: () => string;
1288
+ /**
1289
+ * @public
1290
+ * Get the current editor context from the `EditorProvider`.
1291
+ * Must be used inside the `EditorProvider` component.
1292
+ * @returns The current editor object.
1293
+ * @example
1294
+ * ```tsx
1295
+ * import { useEditor } from '@portabletext/editor'
1296
+ *
1297
+ * function MyComponent() {
1298
+ * const editor = useEditor()
1299
+ * }
1300
+ * ```
1301
+ * @group Hooks
1302
+ */
1303
+ declare function useEditor(): Editor;
1304
+ /**
1305
+ * @beta
1306
+ */
1307
+ type BlockOffset = {
1308
+ path: BlockPath;
1309
+ offset: number;
1310
+ };
1311
+ type TextBlockWithOptionalKey = Omit<PortableTextTextBlock$1, '_key'> & {
1312
+ _key?: PortableTextTextBlock$1['_key'];
1102
1313
  };
1103
- type ConverterEvent<TMIMEType extends MIMEType = MIMEType> = {
1104
- type: 'serialize';
1105
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart';
1106
- } | {
1107
- type: 'serialization.failure';
1108
- mimeType: TMIMEType;
1109
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart';
1110
- reason: string;
1111
- } | {
1112
- type: 'serialization.success';
1113
- data: string;
1114
- mimeType: TMIMEType;
1115
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart';
1116
- } | {
1117
- type: 'deserialize';
1118
- data: string;
1119
- } | {
1120
- type: 'deserialization.failure';
1121
- mimeType: TMIMEType;
1122
- reason: string;
1123
- } | {
1124
- type: 'deserialization.success';
1125
- data: Array<PortableTextBlock>;
1126
- mimeType: TMIMEType;
1314
+ type ObjectBlockWithOptionalKey = Omit<PortableTextObject$1, '_key'> & {
1315
+ _key?: PortableTextObject$1['_key'];
1316
+ };
1317
+ type BlockWithOptionalKey = TextBlockWithOptionalKey | ObjectBlockWithOptionalKey;
1318
+ type SpanWithOptionalKey = Omit<PortableTextSpan$1, '_key'> & {
1319
+ _key?: PortableTextSpan$1['_key'];
1320
+ };
1321
+ type ChildWithOptionalKey = SpanWithOptionalKey | ObjectBlockWithOptionalKey;
1322
+ type EditorPriority = {
1323
+ id: string;
1324
+ name?: string;
1325
+ reference?: {
1326
+ priority: EditorPriority;
1327
+ importance: 'higher' | 'lower';
1328
+ };
1329
+ };
1330
+ type BehaviorConfig = {
1331
+ behavior: Behavior;
1332
+ priority: EditorPriority;
1127
1333
  };
1128
- type Serializer<TMIMEType extends MIMEType> = ({
1129
- snapshot,
1130
- event
1131
- }: {
1132
- snapshot: EditorSnapshot;
1133
- event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialize'>;
1134
- }) => PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialization.success' | 'serialization.failure'>;
1135
- type Deserializer<TMIMEType extends MIMEType> = ({
1136
- snapshot,
1137
- event
1138
- }: {
1139
- snapshot: EditorSnapshot;
1140
- event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>;
1141
- }) => PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialization.success' | 'deserialization.failure'>;
1142
1334
  /**
1143
1335
  * @public
1144
1336
  */
@@ -1331,7 +1523,7 @@ declare const editorMachine: xstate227.StateMachine<{
1331
1523
  initialValue?: Array<PortableTextBlock>;
1332
1524
  }, xstate227.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
1333
1525
  type: "blurred";
1334
- event: react22.FocusEvent<HTMLDivElement, Element>;
1526
+ event: react20.FocusEvent<HTMLDivElement, Element>;
1335
1527
  } | {
1336
1528
  type: "done loading";
1337
1529
  } | {
@@ -1343,7 +1535,7 @@ declare const editorMachine: xstate227.StateMachine<{
1343
1535
  data: unknown;
1344
1536
  } | {
1345
1537
  type: "focused";
1346
- event: react22.FocusEvent<HTMLDivElement, Element>;
1538
+ event: react20.FocusEvent<HTMLDivElement, Element>;
1347
1539
  } | {
1348
1540
  type: "invalid value";
1349
1541
  resolution: InvalidValueResolution | null;
@@ -2006,7 +2198,7 @@ declare const editorMachine: xstate227.StateMachine<{
2006
2198
  type: "drop";
2007
2199
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2008
2200
  type: "blurred";
2009
- event: react22.FocusEvent<HTMLDivElement, Element>;
2201
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2010
2202
  } | {
2011
2203
  type: "done loading";
2012
2204
  } | {
@@ -2018,7 +2210,7 @@ declare const editorMachine: xstate227.StateMachine<{
2018
2210
  data: unknown;
2019
2211
  } | {
2020
2212
  type: "focused";
2021
- event: react22.FocusEvent<HTMLDivElement, Element>;
2213
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2022
2214
  } | {
2023
2215
  type: "invalid value";
2024
2216
  resolution: InvalidValueResolution | null;
@@ -2889,7 +3081,7 @@ declare const editorMachine: xstate227.StateMachine<{
2889
3081
  type: "drop";
2890
3082
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2891
3083
  type: "blurred";
2892
- event: react22.FocusEvent<HTMLDivElement, Element>;
3084
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2893
3085
  } | {
2894
3086
  type: "done loading";
2895
3087
  } | {
@@ -2901,7 +3093,7 @@ declare const editorMachine: xstate227.StateMachine<{
2901
3093
  data: unknown;
2902
3094
  } | {
2903
3095
  type: "focused";
2904
- event: react22.FocusEvent<HTMLDivElement, Element>;
3096
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2905
3097
  } | {
2906
3098
  type: "invalid value";
2907
3099
  resolution: InvalidValueResolution | null;
@@ -3007,13 +3199,6 @@ type EventPosition = {
3007
3199
  isEditor: boolean;
3008
3200
  selection: NonNullable<EditorSelection>;
3009
3201
  };
3010
- /**
3011
- * @beta
3012
- */
3013
- type BlockOffset = {
3014
- path: BlockPath;
3015
- offset: number;
3016
- };
3017
3202
  /**
3018
3203
  * @beta
3019
3204
  */
@@ -3390,191 +3575,6 @@ type CustomBehaviorEvent<TPayload extends Record<string, unknown> = Record<strin
3390
3575
  **************************************/
3391
3576
  type ResolveBehaviorEvent<TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'], TPayload extends Record<string, unknown> = Record<string, unknown>> = TBehaviorEventType extends '*' ? BehaviorEvent : TBehaviorEventType extends `${infer TNamespace}.*` ? TNamespace extends BehaviorEventTypeNamespace ? PickFromUnion<BehaviorEvent, 'type', NamespacedBehaviorEventType<TNamespace>> : never : TBehaviorEventType extends `custom.${infer TType}` ? CustomBehaviorEvent<TPayload, TType> : TBehaviorEventType extends BehaviorEvent['type'] ? PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType> : never;
3392
3577
  type ExtractNamespace<TType extends string> = TType extends `${infer Namespace}.${string}` ? Namespace : TType;
3393
- /**
3394
- * @beta
3395
- */
3396
- type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
3397
- snapshot: EditorSnapshot;
3398
- event: TBehaviorEvent;
3399
- dom: EditorDom;
3400
- }) => TGuardResponse | false;
3401
- /**
3402
- * @beta
3403
- */
3404
- type Behavior<TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'] = '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'], TGuardResponse = true, TBehaviorEvent extends ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>> = {
3405
- /**
3406
- * Editor Event that triggers this Behavior.
3407
- */
3408
- on: TBehaviorEventType;
3409
- /**
3410
- * Predicate function that determines if the Behavior should be executed.
3411
- * Returning a non-nullable value from the guard will pass the value to the
3412
- * actions and execute them.
3413
- */
3414
- guard?: BehaviorGuard<TBehaviorEvent, TGuardResponse>;
3415
- /**
3416
- * Array of Behavior Action sets.
3417
- * Each set represents a step in the history stack.
3418
- */
3419
- actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>;
3420
- };
3421
- /**
3422
- * @beta
3423
- *
3424
- * @example
3425
- *
3426
- * ```tsx
3427
- * const noLowerCaseA = defineBehavior({
3428
- * on: 'insert.text',
3429
- * guard: ({event, snapshot}) => event.text === 'a',
3430
- * actions: [({event, snapshot}) => [{type: 'insert.text', text: 'A'}]],
3431
- * })
3432
- * ```
3433
- *
3434
- */
3435
- declare function defineBehavior<TPayload extends Record<string, unknown>, TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'] = CustomBehaviorEvent['type'], TGuardResponse = true>(behavior: Behavior<TBehaviorEventType, TGuardResponse, ResolveBehaviorEvent<TBehaviorEventType, TPayload>>): Behavior;
3436
- /**
3437
- * @public
3438
- */
3439
- type EditorConfig = {
3440
- /**
3441
- * @beta
3442
- */
3443
- keyGenerator?: () => string;
3444
- /**
3445
- * @deprecated Will be removed in the next major version
3446
- */
3447
- maxBlocks?: number;
3448
- readOnly?: boolean;
3449
- initialValue?: Array<PortableTextBlock>;
3450
- } & ({
3451
- schemaDefinition: SchemaDefinition;
3452
- schema?: undefined;
3453
- } | {
3454
- schemaDefinition?: undefined;
3455
- schema: ArraySchemaType<PortableTextBlock> | ArrayDefinition;
3456
- });
3457
- /**
3458
- * @public
3459
- */
3460
- type EditorEvent = ExternalEditorEvent | ExternalBehaviorEvent | {
3461
- type: 'update value';
3462
- value: Array<PortableTextBlock> | undefined;
3463
- };
3464
- /**
3465
- * @public
3466
- */
3467
- type Editor = {
3468
- dom: EditorDom;
3469
- getSnapshot: () => EditorSnapshot;
3470
- /**
3471
- * @beta
3472
- */
3473
- registerBehavior: (config: {
3474
- behavior: Behavior;
3475
- }) => () => void;
3476
- send: (event: EditorEvent) => void;
3477
- on: ActorRef<Snapshot<unknown>, EventObject, EditorEmittedEvent>['on'];
3478
- };
3479
- /**
3480
- * @public
3481
- * @deprecated
3482
- * This component has been renamed. Use `EventListenerPlugin` instead.
3483
- *
3484
- * ```
3485
- * import {EventListenerPlugin} from '@portabletext/editor/plugins'
3486
- * ```
3487
- */
3488
- declare function EditorEventListener(props: {
3489
- on: (event: EditorEmittedEvent) => void;
3490
- }): null;
3491
- /**
3492
- * @public
3493
- */
3494
- type EditorProviderProps = {
3495
- initialConfig: EditorConfig;
3496
- children?: React$1.ReactNode;
3497
- };
3498
- /**
3499
- * @public
3500
- * The EditorProvider component is used to set up the editor context and configure the Portable Text Editor.
3501
- * @example
3502
- * ```tsx
3503
- * import {EditorProvider} from '@portabletext/editor'
3504
- *
3505
- * function App() {
3506
- * return (
3507
- * <EditorProvider initialConfig={{ ... }} >
3508
- * ...
3509
- * </EditorProvider>
3510
- * )
3511
- * }
3512
- *
3513
- * ```
3514
- * @group Components
3515
- */
3516
- declare function EditorProvider(props: EditorProviderProps): React$1.JSX.Element;
3517
- /**
3518
- * @public
3519
- */
3520
- type EditorSelector<TSelected> = (snapshot: EditorSnapshot) => TSelected;
3521
- /**
3522
- * @public
3523
- * Hook to select a value from the editor state.
3524
- * @example
3525
- * Pass a selector as the second argument
3526
- * ```tsx
3527
- * import { useEditorSelector } from '@portabletext/editor'
3528
- *
3529
- * function MyComponent(editor) {
3530
- * const value = useEditorSelector(editor, selector)
3531
- * }
3532
- * ```
3533
- * @example
3534
- * Pass an inline selector as the second argument.
3535
- * In this case, use the editor context to obtain the schema.
3536
- * ```tsx
3537
- * import { useEditorSelector } from '@portabletext/editor'
3538
- *
3539
- * function MyComponent(editor) {
3540
- * const schema = useEditorSelector(editor, (snapshot) => snapshot.context.schema)
3541
- * }
3542
- * ```
3543
- * @group Hooks
3544
- */
3545
- declare function useEditorSelector<TSelected>(editor: Editor, selector: EditorSelector<TSelected>, compare?: (a: TSelected, b: TSelected) => boolean): TSelected;
3546
- /**
3547
- * @deprecated Use `useEditor` to get the current editor instance.
3548
- * @public
3549
- * Get the current editor object from the React context.
3550
- */
3551
- declare const usePortableTextEditor: () => PortableTextEditor;
3552
- /**
3553
- * @deprecated Use `useEditorSelector` to get the current editor selection.
3554
- * @public
3555
- * Get the current editor selection from the React context.
3556
- */
3557
- declare const usePortableTextEditorSelection: () => EditorSelection;
3558
- /**
3559
- * @public
3560
- */
3561
- declare const defaultKeyGenerator: () => string;
3562
- /**
3563
- * @public
3564
- * Get the current editor context from the `EditorProvider`.
3565
- * Must be used inside the `EditorProvider` component.
3566
- * @returns The current editor object.
3567
- * @example
3568
- * ```tsx
3569
- * import { useEditor } from '@portabletext/editor'
3570
- *
3571
- * function MyComponent() {
3572
- * const editor = useEditor()
3573
- * }
3574
- * ```
3575
- * @group Hooks
3576
- */
3577
- declare function useEditor(): Editor;
3578
3578
  type EditorDom = {
3579
3579
  getBlockNodes: (snapshot: EditorSnapshot) => Array<Node>;
3580
3580
  getChildNodes: (snapshot: EditorSnapshot) => Array<Node>;