@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selector.is-active-style.cjs","sources":["../../src/selectors/selector.get-focus-inline-object.ts","../../src/selectors/selector.get-selected-blocks.ts","../../src/selectors/selector.get-selection-end-block.ts","../../src/selectors/selector.get-selection-start-block.ts","../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts","../../src/selectors/selector.is-overlapping-selection.ts","../../src/selectors/selector.is-selecting-entire-blocks.ts","../../src/types/paths.ts","../../src/utils/util.is-selection-expanded.ts","../../src/selectors/selector.get-next-span.ts","../../src/selectors/selector.get-previous-span.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.get-mark-state.ts","../../src/selectors/selector.get-active-decorators.ts","../../src/selectors/selector.get-trimmed-selection.ts","../../src/selectors/selector.get-next-inline-object.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.get-active-annotation-marks.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.get-focus-block-object.ts","../../src/selectors/selector.get-next-block.ts","../../src/selectors/selector.get-previous-block.ts","../../src/selectors/selector.get-first-block.ts","../../src/selectors/selector.get-last-block.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts","../../src/selectors/selector.get-focus-list-block.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-selected-text-blocks.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.is-active-style.ts"],"sourcesContent":["import {isPortableTextSpan, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getFocusInlineObject: EditorSelector<\n {node: PortableTextObject; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && !isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: BlockPath}>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: BlockPath}> = []\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const startKey = getBlockKeyFromSelectionPoint(startPoint)\n const endKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return selectedBlocks\n }\n\n const slicedValue = snapshot.context.value.slice(\n startBlockIndex,\n endBlockIndex + 1,\n )\n\n for (const block of slicedValue) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: BlockPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: BlockPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelectionEndPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n const pointBlockKey = getBlockKeyFromSelectionPoint(point)\n const pointChildKey = getChildKeyFromSelectionPoint(point)\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n const pointBlockIndex = snapshot.blockIndexMap.get(pointBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (pointBlockIndex === undefined || endBlockIndex === undefined) {\n return false\n }\n\n if (pointBlockIndex > endBlockIndex) {\n // The point block is after the end block.\n return true\n }\n\n if (pointBlockIndex < endBlockIndex) {\n // The point block is before the end block.\n return false\n }\n\n // The point block is the same as the end block.\n const pointBlock = snapshot.context.value.at(pointBlockIndex)\n\n if (!pointBlock) {\n // The point block is not in the value.\n return false\n }\n\n if (!isTextBlock(snapshot.context, pointBlock)) {\n // The point block is not a text block.\n // Since the point block is the same as the end block, the point is not\n // after the selection.\n return false\n }\n\n let pointChildIndex: number | undefined\n let endChildIndex: number | undefined\n\n let childIndex = -1\n\n // The point block is the same as the end block, so we need to find the\n // child indices and compare them.\n for (const child of pointBlock.children) {\n childIndex++\n\n if (child._key === pointChildKey && child._key === endChildKey) {\n return point.offset > endPoint.offset\n }\n\n if (child._key === pointChildKey) {\n pointChildIndex = childIndex\n }\n\n if (child._key === endChildKey) {\n endChildIndex = childIndex\n }\n\n if (pointChildIndex !== undefined && endChildIndex !== undefined) {\n break\n }\n }\n\n if (pointChildIndex === undefined || endChildIndex === undefined) {\n return false\n }\n\n return pointChildIndex > endChildIndex\n }\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n\n const pointBlockKey = getBlockKeyFromSelectionPoint(point)\n const pointChildKey = getChildKeyFromSelectionPoint(point)\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const pointBlockIndex = snapshot.blockIndexMap.get(pointBlockKey)\n\n if (startBlockIndex === undefined || pointBlockIndex === undefined) {\n return false\n }\n\n if (pointBlockIndex < startBlockIndex) {\n // The point block is before the start block.\n return true\n }\n\n if (pointBlockIndex > startBlockIndex) {\n // The point block is after the start block.\n return false\n }\n\n // The point block is the same as the start block.\n const pointBlock = snapshot.context.value.at(pointBlockIndex)\n\n if (!pointBlock) {\n // The point block is not in the value.\n return false\n }\n\n if (!isTextBlock(snapshot.context, pointBlock)) {\n // The point block is not a text block.\n // Since the point block is the same as the start block, the point is not\n // before the selection.\n return false\n }\n\n let pointChildIndex: number | undefined\n let startChildIndex: number | undefined\n\n let childIndex = -1\n\n // The point block is the same as the start block, so we need to find the\n // child indices and compare them.\n for (const child of pointBlock.children) {\n childIndex++\n\n if (child._key === pointChildKey && child._key === startChildKey) {\n return point.offset < startPoint.offset\n }\n\n if (child._key === pointChildKey) {\n pointChildIndex = childIndex\n }\n\n if (child._key === startChildKey) {\n startChildIndex = childIndex\n }\n\n if (pointChildIndex !== undefined && startChildIndex !== undefined) {\n break\n }\n }\n\n if (pointChildIndex === undefined || startChildIndex === undefined) {\n return false\n }\n\n return pointChildIndex < startChildIndex\n }\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport type {EditorSelector} from './../editor/editor-selector'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {isPointAfterSelection} from './selector.is-point-after-selection'\nimport {isPointBeforeSelection} from './selector.is-point-before-selection'\n\n/**\n * @public\n */\nexport function isOverlappingSelection(\n selection: EditorSelection,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!selection || !snapshot.context.selection) {\n return false\n }\n\n const selectionStartPoint = getSelectionStartPoint({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n const selectionEndPoint = getSelectionEndPoint({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n const originalSelectionStartPoint = getSelectionStartPoint(snapshot)\n const originalSelectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (\n !selectionStartPoint ||\n !selectionEndPoint ||\n !originalSelectionStartPoint ||\n !originalSelectionEndPoint\n ) {\n return false\n }\n\n const startPointEqualToOriginalStartPoint = isEqualSelectionPoints(\n selectionStartPoint,\n originalSelectionStartPoint,\n )\n const endPointEqualToOriginalEndPoint = isEqualSelectionPoints(\n selectionEndPoint,\n originalSelectionEndPoint,\n )\n\n if (\n startPointEqualToOriginalStartPoint &&\n endPointEqualToOriginalEndPoint\n ) {\n return true\n }\n\n const startPointBeforeSelection =\n isPointBeforeSelection(selectionStartPoint)(snapshot)\n const startPointAfterSelection =\n isPointAfterSelection(selectionStartPoint)(snapshot)\n const endPointBeforeSelection =\n isPointBeforeSelection(selectionEndPoint)(snapshot)\n const endPointAfterSelection =\n isPointAfterSelection(selectionEndPoint)(snapshot)\n\n const originalStartPointBeforeStartPoint = isPointBeforeSelection(\n originalSelectionStartPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const originalStartPointAfterStartPoint = isPointAfterSelection(\n originalSelectionStartPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n\n const originalEndPointBeforeEndPoint = isPointBeforeSelection(\n originalSelectionEndPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionEndPoint,\n focus: selectionEndPoint,\n },\n },\n })\n const originalEndPointAfterEndPoint = isPointAfterSelection(\n originalSelectionEndPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionEndPoint,\n focus: selectionEndPoint,\n },\n },\n })\n\n const startPointEqualToOriginalEndPoint = isEqualSelectionPoints(\n selectionStartPoint,\n originalSelectionEndPoint,\n )\n const endPointEqualToOriginalStartPoint = isEqualSelectionPoints(\n selectionEndPoint,\n originalSelectionStartPoint,\n )\n\n // If all checks fail then we can deduce that the selection does not exist\n // and there doesn't overlap with the snapshot selection\n if (\n !endPointEqualToOriginalStartPoint &&\n !startPointEqualToOriginalEndPoint &&\n !originalStartPointBeforeStartPoint &&\n !originalStartPointAfterStartPoint &&\n !originalEndPointBeforeEndPoint &&\n !originalEndPointAfterEndPoint\n ) {\n return false\n }\n\n if (endPointBeforeSelection && !endPointEqualToOriginalStartPoint) {\n return false\n }\n\n if (startPointAfterSelection && !startPointEqualToOriginalEndPoint) {\n return false\n }\n\n if (\n !originalStartPointBeforeStartPoint &&\n originalStartPointAfterStartPoint &&\n !originalEndPointBeforeEndPoint &&\n originalEndPointAfterEndPoint\n ) {\n return !endPointEqualToOriginalStartPoint\n }\n\n if (\n originalStartPointBeforeStartPoint &&\n !originalStartPointAfterStartPoint &&\n originalEndPointBeforeEndPoint &&\n !originalEndPointAfterEndPoint\n ) {\n return !startPointEqualToOriginalEndPoint\n }\n\n if (\n !startPointAfterSelection ||\n !startPointBeforeSelection ||\n !endPointAfterSelection ||\n !endPointBeforeSelection\n ) {\n return true\n }\n\n return false\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport {getSelectionEndBlock} from './selector.get-selection-end-block'\nimport {getSelectionStartBlock} from './selector.get-selection-start-block'\n\n/**\n * @public\n */\nexport const isSelectingEntireBlocks: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n const endPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n\n const startBlock = getSelectionStartBlock(snapshot)\n const endBlock = getSelectionEndBlock(snapshot)\n\n if (!startBlock || !endBlock) {\n return false\n }\n\n const startBlockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block: startBlock,\n })\n const endBlockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block: endBlock,\n })\n\n return (\n isEqualSelectionPoints(startBlockStartPoint, startPoint) &&\n isEqualSelectionPoints(endBlockEndPoint, endPoint)\n )\n}\n","import type {Path} from '@sanity/types'\n\n/**\n * @public\n */\nexport type BlockPath = [{_key: string}]\n\n/**\n * @public\n */\nexport function isBlockPath(path: Path): path is BlockPath {\n const firstSegment = path.at(0)\n\n return (\n path.length === 1 &&\n firstSegment !== undefined &&\n isRecord(firstSegment) &&\n '_key' in firstSegment &&\n typeof firstSegment._key === 'string'\n )\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n\n/**\n * @public\n */\nexport type AnnotationPath = [{_key: string}, 'markDefs', {_key: string}]\n\n/**\n * @public\n */\nexport type ChildPath = [{_key: string}, 'children', {_key: string}]\n","import type {EditorSelection} from '../types/editor'\nimport {isSelectionCollapsed} from './util.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isSelectionExpanded(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return !isSelectionCollapsed(selection)\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {KeyedSegment, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getSelectionEndBlock} from './selector.get-selection-end-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextSpan: EditorSelector<\n | {\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const selectionEndBlock = getSelectionEndBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionEndBlock || !selectionEndPoint) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, selectionEndBlock.node)) {\n return undefined\n }\n\n const selectionEndPointChildKey =\n getChildKeyFromSelectionPoint(selectionEndPoint)\n\n let endPointChildFound = false\n let nextSpan:\n | {\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of selectionEndBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (isSpan(snapshot.context, child) && endPointChildFound) {\n nextSpan = {\n node: child,\n path: [...selectionEndBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return nextSpan\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {KeyedSegment, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getSelectionStartBlock} from './selector.get-selection-start-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousSpan: EditorSelector<\n | {\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const selectionStartBlock = getSelectionStartBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n\n if (!selectionStartBlock || !selectionStartPoint) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, selectionStartBlock.node)) {\n return undefined\n }\n\n const selectionStartPointChildKey =\n getChildKeyFromSelectionPoint(selectionStartPoint)\n\n let previousSpan:\n | {\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of selectionStartBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (isSpan(snapshot.context, child)) {\n previousSpan = {\n node: child,\n path: [...selectionStartBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return previousSpan\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../utils/util.selection-point'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: ChildPath\n }>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: ChildPath\n }> = []\n\n const startPoint = getSelectionStartPoint(snapshot)\n const endPoint = getSelectionEndPoint(snapshot)\n\n if (!startPoint || !endPoint) {\n return selectedSpans\n }\n\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const startSpanKey = getChildKeyFromSelectionPoint(startPoint)\n const endSpanKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return selectedSpans\n }\n\n const slicedValue = snapshot.context.value.slice(\n startBlockIndex,\n endBlockIndex + 1,\n )\n\n let startBlockFound = false\n\n for (const block of slicedValue) {\n if (block._key === startBlockKey) {\n startBlockFound = true\n }\n\n if (!isTextBlock(snapshot.context, block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isSpan(snapshot.context, child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n if (startPoint.offset < child.text.length) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n if (endPoint.offset > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isSpan(snapshot.context, child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n if (endPoint.offset > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (startBlockFound) {\n for (const child of block.children) {\n if (!isSpan(snapshot.context, child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isBlockPath} from '../types/paths'\nimport {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'\nimport {isSelectionExpanded} from '../utils/util.is-selection-expanded'\nimport {getFocusSpan} from './selector.get-focus-span'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getNextSpan} from './selector.get-next-span'\nimport {getPreviousSpan} from './selector.get-previous-span'\nimport {getSelectedSpans} from './selector.get-selected-spans'\n\n/**\n * @beta\n */\nexport type MarkState =\n | {\n state: 'unchanged'\n marks: Array<string>\n }\n | {\n state: 'changed'\n marks: Array<string>\n previousMarks: Array<string>\n }\n\n/**\n * Given that text is inserted at the current position, what marks should\n * be applied?\n * @beta\n */\nexport const getMarkState: EditorSelector<MarkState | undefined> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n let selection = snapshot.context.selection\n const focusTextBlock = getFocusTextBlock(snapshot)\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (isBlockPath(selection.anchor.path)) {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: {\n path: selection.anchor.path,\n offset: selection.anchor.offset,\n },\n direction: selection.backward ? 'backward' : 'forward',\n })\n\n selection = spanSelectionPoint\n ? {\n ...selection,\n anchor: spanSelectionPoint,\n }\n : selection\n }\n\n if (isBlockPath(selection.focus.path)) {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: {\n path: selection.focus.path,\n offset: selection.focus.offset,\n },\n direction: selection.backward ? 'backward' : 'forward',\n })\n\n selection = spanSelectionPoint\n ? {\n ...selection,\n focus: spanSelectionPoint,\n }\n : selection\n }\n\n const focusSpan = getFocusSpan({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusSpan) {\n return undefined\n }\n\n if (isSelectionExpanded(selection)) {\n const selectedSpans = getSelectedSpans({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n let index = 0\n let marks: Array<string> = []\n\n for (const span of selectedSpans) {\n if (index === 0) {\n marks = span.node.marks ?? []\n } else {\n if (span.node.marks?.length === 0) {\n marks = []\n continue\n }\n\n marks = marks.filter((mark) =>\n (span.node.marks ?? []).some((spanMark) => spanMark === mark),\n )\n }\n\n index++\n }\n\n return {\n state: 'unchanged',\n marks,\n }\n }\n\n const decorators = snapshot.context.schema.decorators.map(\n (decorator) => decorator.name,\n )\n const marks = focusSpan.node.marks ?? []\n const marksWithoutAnnotations = marks.filter((mark) =>\n decorators.includes(mark),\n )\n\n const spanHasAnnotations = marks.length > marksWithoutAnnotations.length\n\n const spanIsEmpty = focusSpan.node.text.length === 0\n\n const atTheBeginningOfSpan = snapshot.context.selection.anchor.offset === 0\n const atTheEndOfSpan =\n snapshot.context.selection.anchor.offset === focusSpan.node.text.length\n\n const previousSpan = getPreviousSpan({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n const nextSpan = getNextSpan({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n const nextSpanAnnotations =\n nextSpan?.node?.marks?.filter((mark) => !decorators.includes(mark)) ?? []\n const spanAnnotations = marks.filter((mark) => !decorators.includes(mark))\n\n const previousSpanHasAnnotations = previousSpan\n ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark))\n : false\n const previousSpanHasSameAnnotations = previousSpan\n ? previousSpan.node.marks\n ?.filter((mark) => !decorators.includes(mark))\n .every((mark) => marks.includes(mark))\n : false\n const previousSpanHasSameAnnotation = previousSpan\n ? previousSpan.node.marks?.some(\n (mark) => !decorators.includes(mark) && marks.includes(mark),\n )\n : false\n\n const previousSpanHasSameMarks = previousSpan\n ? previousSpan.node.marks?.every((mark) => marks.includes(mark))\n : false\n const nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) =>\n nextSpanAnnotations?.includes(mark),\n )\n\n if (spanHasAnnotations && !spanIsEmpty) {\n if (atTheBeginningOfSpan) {\n if (previousSpanHasSameMarks) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: previousSpan?.node.marks ?? [],\n }\n } else if (previousSpanHasSameAnnotations) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: previousSpan?.node.marks ?? [],\n }\n } else if (previousSpanHasSameAnnotation) {\n return {\n state: 'unchanged',\n previousMarks: marks,\n marks: focusSpan.node.marks ?? [],\n }\n } else if (!previousSpan) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: [],\n }\n }\n }\n\n if (atTheEndOfSpan) {\n if (\n (nextSpan &&\n nextSpanSharesSomeAnnotations &&\n nextSpanAnnotations.length < spanAnnotations.length) ||\n !nextSpanSharesSomeAnnotations\n ) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: nextSpan?.node.marks ?? [],\n }\n }\n\n if (!nextSpan) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: [],\n }\n }\n }\n }\n\n if (atTheBeginningOfSpan && !spanIsEmpty && !!previousSpan) {\n if (previousSpanHasAnnotations) {\n return {\n state: 'changed',\n previousMarks: previousSpan.node.marks ?? [],\n marks: [],\n }\n } else {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: (previousSpan?.node.marks ?? []).filter((mark) =>\n decorators.includes(mark),\n ),\n }\n }\n }\n\n return {\n state: 'unchanged',\n marks,\n }\n}\n","import type {EditorSnapshot} from '../editor/editor-snapshot'\nimport {getMarkState} from './selector.get-mark-state'\n\nexport function getActiveDecorators(snapshot: EditorSnapshot) {\n const schema = snapshot.context.schema\n const decoratorState = snapshot.decoratorState\n const markState = getMarkState(snapshot)\n const decorators = schema.decorators.map((decorator) => decorator.name)\n\n const markStateDecorators = (markState?.marks ?? []).filter((mark) =>\n decorators.includes(mark),\n )\n\n let activeDecorators: Array<string> = markStateDecorators\n\n for (const decorator in decoratorState) {\n if (decoratorState[decorator] === false) {\n activeDecorators = activeDecorators.filter(\n (activeDecorator) => activeDecorator !== decorator,\n )\n } else if (decoratorState[decorator] === true) {\n if (!activeDecorators.includes(decorator)) {\n activeDecorators.push(decorator)\n }\n }\n }\n\n return activeDecorators\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection, EditorSelectionPoint} from '../types/editor'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {isEmptyTextBlock} from '../utils/util.is-empty-text-block'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../utils/util.selection-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const getTrimmedSelection: EditorSelector<EditorSelection> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return snapshot.context.selection\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return snapshot.context.selection\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return snapshot.context.selection\n }\n\n const slicedValue = snapshot.context.value.slice(\n startBlockIndex,\n endBlockIndex + 1,\n )\n\n let startBlockFound = false\n let adjustedStartPoint: EditorSelectionPoint | undefined\n let trimStartPoint = false\n let adjustedEndPoint: EditorSelectionPoint | undefined\n let trimEndPoint = false\n let previousPotentialEndpoint:\n | {blockKey: string; span: PortableTextSpan}\n | undefined\n\n for (const block of slicedValue) {\n if (block._key === startBlockKey) {\n startBlockFound = true\n\n if (\n isTextBlock(snapshot.context, block) &&\n isEmptyTextBlock(snapshot.context, block)\n ) {\n continue\n }\n }\n\n if (!startBlockFound) {\n continue\n }\n\n if (!isTextBlock(snapshot.context, block)) {\n continue\n }\n\n if (\n block._key === endBlockKey &&\n isEmptyTextBlock(snapshot.context, block)\n ) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (!isSpan(snapshot.context, child) || endPoint.offset === 0) {\n adjustedEndPoint = previousPotentialEndpoint\n ? {\n path: [\n {_key: previousPotentialEndpoint.blockKey},\n 'children',\n {_key: previousPotentialEndpoint.span._key},\n ],\n offset: previousPotentialEndpoint.span.text.length,\n }\n : undefined\n\n trimEndPoint = true\n break\n }\n }\n\n if (trimStartPoint) {\n const lonelySpan =\n isSpan(snapshot.context, child) && block.children.length === 1\n\n if (\n (isSpan(snapshot.context, child) && child.text.length > 0) ||\n lonelySpan\n ) {\n adjustedStartPoint = {\n path: [{_key: block._key}, 'children', {_key: child._key}],\n offset: 0,\n }\n previousPotentialEndpoint = {blockKey: block._key, span: child}\n trimStartPoint = false\n }\n\n continue\n }\n\n if (child._key === startChildKey) {\n if (!isSpan(snapshot.context, child)) {\n trimStartPoint = true\n continue\n }\n\n if (startPoint.offset === child.text.length) {\n trimStartPoint = true\n previousPotentialEndpoint =\n child.text.length > 0\n ? {blockKey: block._key, span: child}\n : previousPotentialEndpoint\n continue\n }\n }\n\n previousPotentialEndpoint =\n isSpan(snapshot.context, child) && child.text.length > 0\n ? {blockKey: block._key, span: child}\n : previousPotentialEndpoint\n }\n\n if (block._key === endBlockKey) {\n break\n }\n }\n\n const trimmedSelection = snapshot.context.selection.backward\n ? {\n anchor: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,\n focus: adjustedStartPoint ?? startPoint,\n backward: true,\n }\n : {\n anchor: adjustedStartPoint ?? startPoint,\n focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,\n }\n\n if (\n isSelectionCollapsed({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: trimmedSelection,\n },\n })\n ) {\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: trimmedSelection,\n },\n })\n\n if (\n focusTextBlock &&\n !isEmptyTextBlock(snapshot.context, focusTextBlock.node)\n ) {\n return null\n }\n }\n\n return trimmedSelection\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return undefined\n }\n\n let endPointChildFound = false\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(snapshot.context, child) && endPointChildFound) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return inlineObject\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {\n blockOffsetToSpanSelectionPoint,\n spanSelectionPointToBlockOffset,\n} from '../utils/util.block-offset'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getNextInlineObject} from './selector.get-next-inline-object'\nimport {getPreviousInlineObject} from './selector.get-previous-inline-object'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n * Returns the selection of the of the word the caret is placed in.\n * Note: Only returns a word selection if the current selection is collapsed\n */\nexport const getCaretWordSelection: EditorSelector<EditorSelection> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return null\n }\n\n if (!isSelectionCollapsed(snapshot)) {\n return null\n }\n\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartOffset = selectionStartPoint\n ? spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {\n return null\n }\n\n const previousInlineObject = getPreviousInlineObject(snapshot)\n const blockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block: focusTextBlock,\n })\n const textBefore = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: previousInlineObject\n ? {path: previousInlineObject.path, offset: 0}\n : blockStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const textDirectlyBefore = textBefore.split(/\\s+/).at(-1)\n\n const nextInlineObject = getNextInlineObject(snapshot)\n const blockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block: focusTextBlock,\n })\n const textAfter = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: nextInlineObject\n ? {path: nextInlineObject.path, offset: 0}\n : blockEndPoint,\n },\n },\n })\n const textDirectlyAfter = textAfter.split(/\\s+/).at(0)\n\n if (\n (textDirectlyBefore === undefined || textDirectlyBefore === '') &&\n (textDirectlyAfter === undefined || textDirectlyAfter === '')\n ) {\n return null\n }\n\n const caretWordStartOffset: BlockOffset = textDirectlyBefore\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset - textDirectlyBefore.length,\n }\n : selectionStartOffset\n const caretWordEndOffset: BlockOffset = textDirectlyAfter\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset + textDirectlyAfter.length,\n }\n : selectionStartOffset\n\n const caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: caretWordStartOffset,\n direction: 'backward',\n })\n const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: caretWordEndOffset,\n direction: 'forward',\n })\n\n if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint) {\n return null\n }\n\n const caretWordSelection = {\n anchor: caretWordStartSelectionPoint,\n focus: caretWordEndSelectionPoint,\n }\n\n return isSelectionExpanded({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: caretWordSelection,\n },\n })\n ? caretWordSelection\n : null\n}\n","import type {EditorSnapshot} from '../editor/editor-snapshot'\nimport {getMarkState} from './selector.get-mark-state'\n\nexport function getActiveAnnotationsMarks(snapshot: EditorSnapshot) {\n const schema = snapshot.context.schema\n const markState = getMarkState(snapshot)\n\n return (markState?.marks ?? []).filter(\n (mark) =>\n !schema.decorators.map((decorator) => decorator.name).includes(mark),\n )\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveAnnotationsMarks} from './selector.get-active-annotation-marks'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * Check whether an annotation is active in the given `snapshot`.\n *\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n options?: {\n /**\n * Choose whether the annotation has to take up the entire selection in the\n * `snapshot` or if the annotation can be partially selected.\n *\n * Defaults to 'full'\n */\n mode?: 'partial' | 'full'\n },\n): EditorSelector<boolean> {\n return (snapshot) => {\n const mode = options?.mode ?? 'full'\n\n if (mode === 'partial') {\n const selectedValue = getSelectedValue(snapshot)\n\n const selectionMarkDefs = selectedValue.flatMap((block) =>\n isTextBlock(snapshot.context, block) ? (block.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.some((markDef) => markDef._type === annotation)\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isTextBlock(snapshot.context, block.node)\n ? (block.node.markDefs ?? [])\n : [],\n )\n const activeAnnotations = getActiveAnnotationsMarks(snapshot)\n const activeMarkDefs = selectionMarkDefs.filter(\n (markDef) =>\n markDef._type === annotation &&\n activeAnnotations.includes(markDef._key),\n )\n\n return activeMarkDefs.length > 0\n }\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && !isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndBlock} from './selector.get-selection-end-block'\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selectionEndBlock = getSelectionEndBlock(snapshot)\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n const index = snapshot.blockIndexMap.get(selectionEndBlock.node._key)\n\n if (index === undefined || index === snapshot.context.value.length - 1) {\n return undefined\n }\n\n const nextBlock = snapshot.context.value.at(index + 1)\n\n return nextBlock\n ? {node: nextBlock, path: [{_key: nextBlock._key}]}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionStartBlock} from './selector.get-selection-start-block'\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selectionStartBlock = getSelectionStartBlock(snapshot)\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n const index = snapshot.blockIndexMap.get(selectionStartBlock.node._key)\n\n if (index === undefined || index === 0) {\n return undefined\n }\n\n const previousBlock = snapshot.context.value.at(index - 1)\n\n return previousBlock\n ? {node: previousBlock, path: [{_key: previousBlock._key}]}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[snapshot.context.value.length - 1]\n ? snapshot.context.value[snapshot.context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: BlockPath\n}): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection || !isSelectionCollapsed(snapshot)) {\n return false\n }\n\n const blockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockEndPoint,\n )\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: BlockPath\n}): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection || !isSelectionCollapsed(snapshot)) {\n return false\n }\n\n const blockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockStartPoint,\n )\n }\n}\n","import type {PortableTextListBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {isListBlock} from '../utils/parse-blocks'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n\n return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node)\n ? {node: focusTextBlock.node, path: focusTextBlock.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveDecorators} from './selector.get-active-decorators'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n const activeDecorators = getActiveDecorators(snapshot)\n\n return activeDecorators.includes(decorator)\n }\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getMarkState} from './selector.get-mark-state'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const markState = getMarkState(snapshot)\n\n const activeAnnotations = (markState?.marks ?? []).filter(\n (mark) =>\n !snapshot.context.schema.decorators\n .map((decorator) => decorator.name)\n .includes(mark),\n )\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isTextBlock(snapshot.context, block.node)\n ? (block.node.markDefs ?? [])\n : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n activeAnnotations.includes(markDef._key),\n )\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getSelectedTextBlocks: EditorSelector<\n Array<{node: PortableTextTextBlock; path: BlockPath}>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedTextBlocks: Array<{\n node: PortableTextTextBlock\n path: BlockPath\n }> = []\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return selectedTextBlocks\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return selectedTextBlocks\n }\n\n const slicedValue = snapshot.context.value.slice(\n startBlockIndex,\n endBlockIndex + 1,\n )\n\n for (const block of slicedValue) {\n if (block._key === startBlockKey) {\n if (isTextBlock(snapshot.context, block)) {\n selectedTextBlocks.push({node: block, path: [{_key: block._key}]})\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n continue\n }\n\n if (block._key === endBlockKey) {\n if (isTextBlock(snapshot.context, block)) {\n selectedTextBlocks.push({node: block, path: [{_key: block._key}]})\n }\n\n break\n }\n\n if (selectedTextBlocks.length > 0) {\n if (isTextBlock(snapshot.context, block)) {\n selectedTextBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n }\n\n return selectedTextBlocks\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextListBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter((block) =>\n isTextBlock(snapshot.context, block),\n )\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter((block) =>\n isTextBlock(snapshot.context, block),\n )\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n"],"names":["getFocusInlineObject","snapshot","focusChild","getFocusChild","isPortableTextSpan","node","path","undefined","getSelectedBlocks","context","selection","selectedBlocks","startPoint","getSelectionStartPoint","endPoint","getSelectionEndPoint","startKey","getBlockKeyFromSelectionPoint","endKey","startBlockIndex","blockIndexMap","get","endBlockIndex","slicedValue","value","slice","block","_key","push","length","getSelectionEndBlock","getFocusBlock","anchor","focus","getSelectionStartBlock","backward","isPointAfterSelection","point","endBlockKey","endChildKey","getChildKeyFromSelectionPoint","pointBlockKey","pointChildKey","pointBlockIndex","pointBlock","at","isTextBlock","pointChildIndex","endChildIndex","childIndex","child","children","offset","isPointBeforeSelection","startBlockKey","startChildKey","startChildIndex","isOverlappingSelection","selectionStartPoint","selectionEndPoint","originalSelectionStartPoint","originalSelectionEndPoint","startPointEqualToOriginalStartPoint","isEqualSelectionPoints","endPointEqualToOriginalEndPoint","startPointBeforeSelection","startPointAfterSelection","endPointBeforeSelection","endPointAfterSelection","originalStartPointBeforeStartPoint","originalStartPointAfterStartPoint","originalEndPointBeforeEndPoint","originalEndPointAfterEndPoint","startPointEqualToOriginalEndPoint","endPointEqualToOriginalStartPoint","isSelectingEntireBlocks","startBlock","endBlock","startBlockStartPoint","getBlockStartPoint","endBlockEndPoint","getBlockEndPoint","isBlockPath","firstSegment","isRecord","isSelectionExpanded","isSelectionCollapsed","getNextSpan","selectionEndBlock","selectionEndPointChildKey","endPointChildFound","nextSpan","isSpan","getPreviousSpan","selectionStartBlock","selectionStartPointChildKey","previousSpan","getSelectedSpans","selectedSpans","startSpanKey","endSpanKey","startBlockFound","text","getMarkState","getFocusTextBlock","spanSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","direction","focusSpan","getFocusSpan","index","marks","span","filter","mark","some","spanMark","state","decorators","schema","map","decorator","name","marksWithoutAnnotations","includes","spanHasAnnotations","spanIsEmpty","atTheBeginningOfSpan","atTheEndOfSpan","nextSpanAnnotations","spanAnnotations","previousSpanHasAnnotations","previousSpanHasSameAnnotations","every","previousSpanHasSameAnnotation","previousSpanHasSameMarks","nextSpanSharesSomeAnnotations","previousMarks","getActiveDecorators","decoratorState","markState","activeDecorators","activeDecorator","getTrimmedSelection","adjustedStartPoint","trimStartPoint","adjustedEndPoint","trimEndPoint","previousPotentialEndpoint","isEmptyTextBlock","blockKey","lonelySpan","trimmedSelection","focusTextBlock","getNextInlineObject","isKeySegment","inlineObject","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","getPreviousInlineObject","blockStartPoint","textDirectlyBefore","getSelectionText","split","nextInlineObject","blockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","caretWordEndSelectionPoint","caretWordSelection","getActiveAnnotationsMarks","isActiveAnnotation","annotation","options","mode","getSelectedValue","flatMap","markDefs","markDef","_type","selectionMarkDefs","activeAnnotations","getFocusBlockObject","focusBlock","getNextBlock","nextBlock","getPreviousBlock","previousBlock","getFirstBlock","getLastBlock","isAtTheEndOfBlock","isAtTheStartOfBlock","getFocusListBlock","isListBlock","isActiveDecorator","getActiveAnnotations","getSelectedTextBlocks","selectedTextBlocks","getActiveListItem","firstTextBlock","firstListItem","listItem","isActiveListItem","getActiveStyle","firstStyle","style","isActiveStyle"],"mappings":";;AAQO,MAAMA,uBAERC,CAAAA,aAAa;AAChB,QAAMC,aAAaC,0BAAAA,cAAcF,QAAQ;AAEzC,SAAOC,cAAc,CAACE,MAAAA,mBAAmBF,WAAWG,I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+ var util_getTextBlockText = require("./util.get-text-block-text.cjs"), schema = require("@portabletext/schema");
3
3
  function blockOffsetToBlockSelectionPoint({
4
4
  context,
5
5
  blockOffset
@@ -22,7 +22,7 @@ function blockOffsetToSelectionPoint({
22
22
  blockOffset,
23
23
  direction
24
24
  }) {
25
- return util_sliceBlocks.blockOffsetToSpanSelectionPoint({
25
+ return util_getTextBlockText.blockOffsetToSpanSelectionPoint({
26
26
  context,
27
27
  blockOffset,
28
28
  direction
@@ -56,7 +56,7 @@ function childSelectionPointToBlockOffset({
56
56
  selectionPoint
57
57
  }) {
58
58
  let offset = 0;
59
- const blockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(selectionPoint), childKey = util_sliceBlocks.getChildKeyFromSelectionPoint(selectionPoint);
59
+ const blockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(selectionPoint), childKey = util_getTextBlockText.getChildKeyFromSelectionPoint(selectionPoint);
60
60
  if (!(!blockKey || !childKey)) {
61
61
  for (const block of context.value)
62
62
  if (block._key === blockKey && schema.isTextBlock(context, block))
@@ -1 +1 @@
1
- {"version":3,"file":"util.child-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"],"sourcesContent":["import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function blockOffsetToBlockSelectionPoint({\n context,\n blockOffset,\n}: {\n context: Pick<EditorContext, 'value'>\n blockOffset: BlockOffset\n}): EditorSelectionPoint | undefined {\n let selectionPoint: EditorSelectionPoint | undefined\n\n for (const block of context.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 {EditorContext} from '../editor/editor-snapshot'\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 context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}): EditorSelectionPoint | undefined {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n })\n\n if (!spanSelectionPoint) {\n return blockOffsetToBlockSelectionPoint({\n context,\n blockOffset,\n })\n }\n\n return spanSelectionPoint\n}\n","import type {EditorSelection} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\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 context,\n offsets,\n backward,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSelectionPoint({\n context,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSelectionPoint({\n context,\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 {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n const childKey = getChildKeyFromSelectionPoint(selectionPoint)\n\n if (!blockKey || !childKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (child._key === childKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n if (isSpan(context, child)) {\n offset += child.text.length\n }\n }\n }\n}\n"],"names":["blockOffsetToBlockSelectionPoint","context","blockOffset","selectionPoint","block","value","_key","path","offset","blockOffsetToSelectionPoint","direction","blockOffsetToSpanSelectionPoint","blockOffsetsToSelection","offsets","backward","anchor","focus","childSelectionPointToBlockOffset","blockKey","getBlockKeyFromSelectionPoint","childKey","getChildKeyFromSelectionPoint","isTextBlock","child","children","isSpan","text","length"],"mappings":";;AAOO,SAASA,iCAAiC;AAAA,EAC/CC;AAAAA,EACAC;AAIF,GAAqC;AACnC,MAAIC;AAEJ,aAAWC,SAASH,QAAQI;AAC1B,QAAID,MAAME,SAASJ,YAAYK,KAAK,CAAC,EAAED,MAAM;AAC3CH,uBAAiB;AAAA,QACfI,MAAM,CAAC;AAAA,UAACD,MAAMF,MAAME;AAAAA,QAAAA,CAAK;AAAA,QACzBE,QAAQN,YAAYM;AAAAA,MAAAA;AAEtB;AAAA,IACF;AAGF,SAAOL;AACT;AClBO,SAASM,4BAA4B;AAAA,EAC1CR;AAAAA,EACAC;AAAAA,EACAQ;AAKF,GAAqC;AAOnC,SAN2BC,iBAAAA,gCAAgC;AAAA,IACzDV;AAAAA,IACAC;AAAAA,IACAQ;AAAAA,EAAAA,CACD,KAGQV,iCAAiC;AAAA,IACtCC;AAAAA,IACAC;AAAAA,EAAAA,CACD;AAIL;ACxBO,SAASU,wBAAwB;AAAA,EACtCX;AAAAA,EACAY;AAAAA,EACAC;AAKF,GAAoB;AAClB,QAAMC,SAASN,4BAA4B;AAAA,IACzCR;AAAAA,IACAC,aAAaW,QAAQE;AAAAA,IACrBL,WAAWI,WAAW,aAAa;AAAA,EAAA,CACpC,GACKE,QAAQP,4BAA4B;AAAA,IACxCR;AAAAA,IACAC,aAAaW,QAAQG;AAAAA,IACrBN,WAAWI,WAAW,YAAY;AAAA,EAAA,CACnC;AAED,SAAI,CAACC,UAAU,CAACC,QACP,OAGF;AAAA,IACLD;AAAAA,IACAC;AAAAA,IACAF;AAAAA,EAAAA;AAEJ;ACzBO,SAASG,iCAAiC;AAAA,EAC/ChB;AAAAA,EACAE;AAIF,GAA4B;AAC1B,MAAIK,SAAS;AAEb,QAAMU,WAAWC,iBAAAA,8BAA8BhB,cAAc,GACvDiB,WAAWC,iBAAAA,8BAA8BlB,cAAc;AAE7D,MAAI,EAAA,CAACe,YAAY,CAACE;AAIlB,eAAWhB,SAASH,QAAQI;AAC1B,UAAID,MAAME,SAASY,YAIdI,OAAAA,YAAYrB,SAASG,KAAK;AAI/B,mBAAWmB,SAASnB,MAAMoB,UAAU;AAClC,cAAID,MAAMjB,SAASc;AACjB,mBAAO;AAAA,cACLb,MAAM,CAAC;AAAA,gBAACD,MAAMF,MAAME;AAAAA,cAAAA,CAAK;AAAA,cACzBE,QAAQA,SAASL,eAAeK;AAAAA,YAAAA;AAIhCiB,iBAAAA,OAAOxB,SAASsB,KAAK,MACvBf,UAAUe,MAAMG,KAAKC;AAAAA,QAEzB;AAAA;AAEJ;;;;;"}
1
+ {"version":3,"file":"util.child-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"],"sourcesContent":["import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function blockOffsetToBlockSelectionPoint({\n context,\n blockOffset,\n}: {\n context: Pick<EditorContext, 'value'>\n blockOffset: BlockOffset\n}): EditorSelectionPoint | undefined {\n let selectionPoint: EditorSelectionPoint | undefined\n\n for (const block of context.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 {EditorContext} from '../editor/editor-snapshot'\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 context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}): EditorSelectionPoint | undefined {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n })\n\n if (!spanSelectionPoint) {\n return blockOffsetToBlockSelectionPoint({\n context,\n blockOffset,\n })\n }\n\n return spanSelectionPoint\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n context,\n offsets,\n backward,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSelectionPoint({\n context,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSelectionPoint({\n context,\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 {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n const childKey = getChildKeyFromSelectionPoint(selectionPoint)\n\n if (!blockKey || !childKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (child._key === childKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n if (isSpan(context, child)) {\n offset += child.text.length\n }\n }\n }\n}\n"],"names":["blockOffsetToBlockSelectionPoint","context","blockOffset","selectionPoint","block","value","_key","path","offset","blockOffsetToSelectionPoint","direction","blockOffsetToSpanSelectionPoint","blockOffsetsToSelection","offsets","backward","anchor","focus","childSelectionPointToBlockOffset","blockKey","getBlockKeyFromSelectionPoint","childKey","getChildKeyFromSelectionPoint","isTextBlock","child","children","isSpan","text","length"],"mappings":";;AAOO,SAASA,iCAAiC;AAAA,EAC/CC;AAAAA,EACAC;AAIF,GAAqC;AACnC,MAAIC;AAEJ,aAAWC,SAASH,QAAQI;AAC1B,QAAID,MAAME,SAASJ,YAAYK,KAAK,CAAC,EAAED,MAAM;AAC3CH,uBAAiB;AAAA,QACfI,MAAM,CAAC;AAAA,UAACD,MAAMF,MAAME;AAAAA,QAAAA,CAAK;AAAA,QACzBE,QAAQN,YAAYM;AAAAA,MAAAA;AAEtB;AAAA,IACF;AAGF,SAAOL;AACT;AClBO,SAASM,4BAA4B;AAAA,E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@@ function _interopDefaultCompat(e) {
4
4
  return e && typeof e == "object" && "default" in e ? e : { default: e };
5
5
  }
6
6
  var getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
7
+ function getBlockStartPoint({
8
+ context,
9
+ block
10
+ }) {
11
+ return schema.isTextBlock(context, block.node) ? {
12
+ path: [...block.path, "children", {
13
+ _key: block.node.children[0]._key
14
+ }],
15
+ offset: 0
16
+ } : {
17
+ path: block.path,
18
+ offset: 0
19
+ };
20
+ }
7
21
  function isKeyedSegment(segment) {
8
22
  return typeof segment == "object" && segment !== null && "_key" in segment;
9
23
  }
@@ -91,29 +105,6 @@ function spanSelectionPointToBlockOffset({
91
105
  }
92
106
  }
93
107
  }
94
- function getBlockStartPoint({
95
- context,
96
- block
97
- }) {
98
- return schema.isTextBlock(context, block.node) ? {
99
- path: [...block.path, "children", {
100
- _key: block.node.children[0]._key
101
- }],
102
- offset: 0
103
- } : {
104
- path: block.path,
105
- offset: 0
106
- };
107
- }
108
- function getSelectionEndPoint(selection) {
109
- return selection ? selection.backward ? selection.anchor : selection.focus : null;
110
- }
111
- function getSelectionStartPoint(selection) {
112
- return selection ? selection.backward ? selection.focus : selection.anchor : null;
113
- }
114
- function getTextBlockText(block) {
115
- return block.children.map((child) => child.text ?? "").join("");
116
- }
117
108
  function isTypedObject(object) {
118
109
  return isRecord(object) && typeof object._type == "string";
119
110
  }
@@ -337,6 +328,12 @@ function randomKey(length) {
337
328
  const table = getByteHexTable();
338
329
  return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
339
330
  }
331
+ function getSelectionEndPoint(selection) {
332
+ return selection ? selection.backward ? selection.anchor : selection.focus : null;
333
+ }
334
+ function getSelectionStartPoint(selection) {
335
+ return selection ? selection.backward ? selection.focus : selection.anchor : null;
336
+ }
340
337
  function sliceBlocks({
341
338
  context,
342
339
  blocks
@@ -377,7 +374,7 @@ function sliceBlocks({
377
374
  ...block,
378
375
  children: [child]
379
376
  };
380
- if (startChildKey === endChildKey)
377
+ if (block._key === endBlockKey && startChildKey === endChildKey)
381
378
  break;
382
379
  continue;
383
380
  }
@@ -456,6 +453,9 @@ function sliceBlocks({
456
453
  }) : void 0;
457
454
  return [...parsedStartBlock ? [parsedStartBlock] : [], ...middleBlocks, ...parsedEndBlock ? [parsedEndBlock] : []];
458
455
  }
456
+ function getTextBlockText(block) {
457
+ return block.children.map((child) => child.text ?? "").join("");
458
+ }
459
459
  exports.blockOffsetToSpanSelectionPoint = blockOffsetToSpanSelectionPoint;
460
460
  exports.defaultKeyGenerator = defaultKeyGenerator;
461
461
  exports.getBlockKeyFromSelectionPoint = getBlockKeyFromSelectionPoint;
@@ -466,7 +466,6 @@ exports.getSelectionStartPoint = getSelectionStartPoint;
466
466
  exports.getTextBlockText = getTextBlockText;
467
467
  exports.isKeyedSegment = isKeyedSegment;
468
468
  exports.isListBlock = isListBlock;
469
- exports.isRecord = isRecord;
470
469
  exports.isTypedObject = isTypedObject;
471
470
  exports.parseAnnotation = parseAnnotation;
472
471
  exports.parseBlock = parseBlock;
@@ -475,4 +474,4 @@ exports.parseInlineObject = parseInlineObject;
475
474
  exports.parseSpan = parseSpan;
476
475
  exports.sliceBlocks = sliceBlocks;
477
476
  exports.spanSelectionPointToBlockOffset = spanSelectionPointToBlockOffset;
478
- //# sourceMappingURL=util.slice-blocks.cjs.map
477
+ //# sourceMappingURL=util.get-text-block-text.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.get-text-block-text.cjs","sources":["../../src/utils/util.get-block-start-point.ts","../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.selection-point.ts","../../src/utils/util.block-offset.ts","../../src/utils/asserters.ts","../../src/utils/parse-blocks.ts","../../src/utils/key-generator.ts","../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.slice-blocks.ts","../../src/utils/util.get-text-block-text.ts"],"sourcesContent":["import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: BlockPath\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n return {\n path: [...block.path, 'children', {_key: block.node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {KeyedSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: unknown): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\nexport function getBlockKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const blockPathSegment = point.path.at(0)\n\n if (isKeyedSegment(blockPathSegment)) {\n return blockPathSegment._key\n }\n\n return undefined\n}\n\nexport function getChildKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const childPathSegment = point.path.at(2)\n\n if (isKeyedSegment(childPathSegment)) {\n return childPathSegment._key\n }\n\n return undefined\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {ChildPath} from '../types/paths'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint: {path: ChildPath; offset: number} | undefined\n let skippedInlineObject = false\n\n for (const block of context.value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (direction === 'forward') {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n\n continue\n }\n\n if (!isSpan(context, child)) {\n skippedInlineObject = true\n continue\n }\n\n if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {\n if (skippedInlineObject) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n }\n break\n }\n\n if (offsetLeft > child.text.length) {\n offsetLeft -= child.text.length\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n\n offsetLeft -= child.text.length\n\n if (offsetLeft !== 0) {\n break\n }\n }\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n const spanKey = getChildKeyFromSelectionPoint(selectionPoint)\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import type {TypedObject} from '@sanity/types'\n\nexport function isTypedObject(object: unknown): object is TypedObject {\n return isRecord(object) && typeof object._type === 'string'\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {\n PortableTextBlock,\n PortableTextListBlock,\n PortableTextObject,\n PortableTextSpan,\n PortableTextTextBlock,\n TypedObject,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\n\nexport function parseBlocks({\n context,\n blocks,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n blocks: unknown\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): Array<PortableTextBlock> {\n if (!Array.isArray(blocks)) {\n return []\n }\n\n return blocks.flatMap((block) => {\n const parsedBlock = parseBlock({context, block, options})\n\n return parsedBlock ? [parsedBlock] : []\n })\n}\n\nexport function parseBlock({\n context,\n block,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n block: unknown\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextBlock | undefined {\n return (\n parseTextBlock({block, context, options}) ??\n parseBlockObject({blockObject: block, context, options})\n )\n}\n\nexport function parseBlockObject({\n blockObject,\n context,\n options,\n}: {\n blockObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(blockObject)) {\n return undefined\n }\n\n const schemaType = context.schema.blockObjects.find(\n ({name}) => name === blockObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: blockObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function isListBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextListBlock {\n return (\n isTextBlock(context, block) &&\n block.level !== undefined &&\n block.listItem !== undefined\n )\n}\n\nexport function parseTextBlock({\n block,\n context,\n options,\n}: {\n block: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextTextBlock | undefined {\n if (!isTypedObject(block)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(block)) {\n if (\n key === '_type' ||\n key === '_key' ||\n key === 'children' ||\n key === 'markDefs' ||\n key === 'style' ||\n key === 'listItem' ||\n key === 'level'\n ) {\n continue\n }\n\n if (options.validateFields) {\n if (context.schema.block.fields?.some((field) => field.name === key)) {\n customFields[key] = block[key]\n }\n } else {\n customFields[key] = block[key]\n }\n }\n\n if (block._type !== context.schema.block.name) {\n return undefined\n }\n\n const _key =\n typeof block._key === 'string' ? block._key : context.keyGenerator()\n\n const unparsedMarkDefs: Array<unknown> = Array.isArray(block.markDefs)\n ? block.markDefs\n : []\n const markDefKeyMap = new Map<string, string>()\n const markDefs = unparsedMarkDefs.flatMap((markDef) => {\n if (!isTypedObject(markDef)) {\n return []\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === markDef._type,\n )\n\n if (!schemaType) {\n return []\n }\n\n if (typeof markDef._key !== 'string') {\n // If the `markDef` doesn't have a `_key` then we don't know what spans\n // it belongs to and therefore we have to discard it.\n return []\n }\n\n const parsedAnnotation = parseObject({\n object: markDef,\n context: {\n schemaType,\n keyGenerator: context.keyGenerator,\n },\n options,\n })\n\n if (!parsedAnnotation) {\n return []\n }\n\n markDefKeyMap.set(markDef._key, parsedAnnotation._key)\n\n return [parsedAnnotation]\n })\n\n const unparsedChildren: Array<unknown> = Array.isArray(block.children)\n ? block.children\n : []\n\n const children = unparsedChildren\n .map(\n (child) =>\n parseSpan({span: child, context, markDefKeyMap, options}) ??\n parseInlineObject({inlineObject: child, context, options}),\n )\n .filter((child) => child !== undefined)\n const marks = children.flatMap((child) => child.marks ?? [])\n\n const parsedBlock: PortableTextTextBlock = {\n _type: context.schema.block.name,\n _key,\n children:\n children.length > 0\n ? children\n : [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs: options.removeUnusedMarkDefs\n ? markDefs.filter((markDef) => marks.includes(markDef._key))\n : markDefs,\n ...customFields,\n }\n\n if (\n typeof block.style === 'string' &&\n context.schema.styles.find((style) => style.name === block.style)\n ) {\n parsedBlock.style = block.style\n } else {\n const defaultStyle = context.schema.styles.at(0)?.name\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n console.error('Expected default style')\n }\n }\n\n if (\n typeof block.listItem === 'string' &&\n context.schema.lists.find((list) => list.name === block.listItem)\n ) {\n parsedBlock.listItem = block.listItem\n }\n\n if (typeof block.level === 'number') {\n parsedBlock.level = block.level\n }\n\n return parsedBlock\n}\n\nexport function parseSpan({\n span,\n context,\n markDefKeyMap,\n options,\n}: {\n span: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n markDefKeyMap: Map<string, string>\n options: {validateFields: boolean}\n}): PortableTextSpan | undefined {\n if (!isTypedObject(span)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(span)) {\n if (\n key !== '_type' &&\n key !== '_key' &&\n key !== 'text' &&\n key !== 'marks'\n ) {\n customFields[key] = span[key]\n }\n }\n\n // In reality, the span schema name is always 'span', but we only the check here anyway\n if (span._type !== context.schema.span.name || span._type !== 'span') {\n return undefined\n }\n\n const unparsedMarks: Array<unknown> = Array.isArray(span.marks)\n ? span.marks\n : []\n const marks = unparsedMarks.flatMap((mark) => {\n if (typeof mark !== 'string') {\n return []\n }\n\n const markDefKey = markDefKeyMap.get(mark)\n\n if (markDefKey !== undefined) {\n return [markDefKey]\n }\n\n if (\n context.schema.decorators.some((decorator) => decorator.name === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return {\n _type: 'span',\n _key: typeof span._key === 'string' ? span._key : context.keyGenerator(),\n text: typeof span.text === 'string' ? span.text : '',\n marks,\n ...(options.validateFields ? {} : customFields),\n }\n}\n\nexport function parseInlineObject({\n inlineObject,\n context,\n options,\n}: {\n inlineObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(inlineObject)) {\n return undefined\n }\n\n const schemaType = context.schema.inlineObjects.find(\n ({name}) => name === inlineObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: inlineObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function parseAnnotation({\n annotation,\n context,\n options,\n}: {\n annotation: TypedObject\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(annotation)) {\n return undefined\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === annotation._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: annotation,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nfunction parseObject({\n object,\n context,\n options,\n}: {\n object: TypedObject\n context: Pick<EditorContext, 'keyGenerator'> & {\n schemaType: EditorSchema['blockObjects'][0]\n }\n options: {validateFields: boolean}\n}): PortableTextObject {\n const {_type, _key, ...customFields} = object\n\n // Validates all props on the object and only takes those that match\n // the name of a field\n const values = options.validateFields\n ? context.schemaType.fields.reduce<Record<string, unknown>>(\n (fieldValues, field) => {\n const fieldValue = object[field.name]\n\n if (fieldValue !== undefined) {\n fieldValues[field.name] = fieldValue\n }\n\n return fieldValues\n },\n {},\n )\n : customFields\n\n return {\n _type: context.schemaType.name,\n _key:\n typeof object._key === 'string' ? object._key : context.keyGenerator(),\n ...values,\n }\n}\n","import getRandomValues from 'get-random-values-esm'\n\n/**\n * @public\n */\nexport const defaultKeyGenerator = (): string => randomKey(12)\n\nconst getByteHexTable = (() => {\n let table: any[]\n return () => {\n if (table) {\n return table\n }\n\n table = []\n for (let i = 0; i < 256; ++i) {\n table[i] = (i + 0x100).toString(16).slice(1)\n }\n return table\n }\n})()\n\n// WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html\nfunction whatwgRNG(length = 16) {\n const rnds8 = new Uint8Array(length)\n getRandomValues(rnds8)\n return rnds8\n}\n\nfunction randomKey(length?: number): string {\n const table = getByteHexTable()\n return whatwgRNG(length)\n .reduce((str, n) => str + table[n], '')\n .slice(0, length)\n}\n","import type {EditorSelection, EditorSelectionPoint} from '../types/editor'\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 '../types/editor'\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 {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {defaultKeyGenerator} from './key-generator'\nimport {parseBlock} from './parse-blocks'\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\n/**\n * @public\n */\nexport function sliceBlocks({\n context,\n blocks,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n blocks: Array<PortableTextBlock>\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!context.selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (!isTextBlock(context, block)) {\n if (block._key === startBlockKey && block._key === endBlockKey) {\n startBlock = block\n break\n }\n }\n\n if (block._key === startBlockKey) {\n if (!isTextBlock(context, block)) {\n startBlock = block\n continue\n }\n\n if (startChildKey) {\n for (const child of block.children) {\n if (child._key === startChildKey) {\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n startBlock = {\n ...block,\n children: [\n {\n ...child,\n text,\n },\n ],\n }\n } else {\n startBlock = {\n ...block,\n children: [child],\n }\n }\n\n if (block._key === endBlockKey && startChildKey === endChildKey) {\n break\n }\n continue\n }\n\n if (startBlock && isTextBlock(context, startBlock)) {\n if (\n endChildKey &&\n child._key === endChildKey &&\n isSpan(context, child)\n ) {\n startBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n startBlock.children.push(child)\n }\n\n if (\n block._key === endBlockKey &&\n endChildKey &&\n child._key === endChildKey\n ) {\n break\n }\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n startBlock = block\n\n if (startBlockKey === endBlockKey) {\n break\n }\n }\n\n if (block._key === endBlockKey) {\n if (!isTextBlock(context, block)) {\n endBlock = block\n break\n }\n\n if (endChildKey) {\n endBlock = {\n ...block,\n children: [],\n }\n\n for (const child of block.children) {\n if (endBlock && isTextBlock(context, endBlock)) {\n if (child._key === endChildKey && isSpan(context, child)) {\n endBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n\n break\n }\n\n endBlock.children.push(child)\n\n if (endChildKey && child._key === endChildKey) {\n break\n }\n }\n }\n\n break\n }\n\n endBlock = block\n\n break\n }\n\n if (startBlock) {\n middleBlocks.push(\n parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n }) ?? block,\n )\n }\n }\n\n const parsedStartBlock = startBlock\n ? parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block: startBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n : undefined\n\n const parsedEndBlock = endBlock\n ? parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block: endBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n : undefined\n\n return [\n ...(parsedStartBlock ? [parsedStartBlock] : []),\n ...middleBlocks,\n ...(parsedEndBlock ? [parsedEndBlock] : []),\n ]\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n"],"names":["getBlockStartPoint","context","block","isTextBlock","node","path","_key","children","offset","isKeyedSegment","segment","getBlockKeyFromSelectionPoint","point","blockPathSegment","at","getChildKeyFromSelectionPoint","childPathSegment","blockOffsetToSpanSelectionPoint","blockOffset","direction","offsetLeft","selectionPoint","skippedInlineObject","value","child","isSpan","text","length","spanSelectionPointToBlockOffset","blockKey","spanKey","isTypedObject","object","isRecord","_type","parseBlocks","blocks","options","Array","isArray","flatMap","parsedBlock","parseBlock","parseTextBlock","parseBlockObject","blockObject","schemaType","schema","blockObjects","find","name","parseObject","keyGenerator","isListBlock","level","undefined","listItem","customFields","key","Object","keys","validateFields","fields","some","field","unparsedMarkDefs","markDefs","markDefKeyMap","Map","markDef","annotations","parsedAnnotation","set","map","parseSpan","span","parseInlineObject","inlineObject","filter","marks","removeUnusedMarkDefs","includes","style","styles","defaultStyle","console","error","lists","list","mark","markDefKey","get","decorators","decorator","inlineObjects","parseAnnotation","annotation","values","reduce","fieldValues","fieldValue","defaultKeyGenerator","randomKey","getByteHexTable","table","i","toString","slice","whatwgRNG","rnds8","Uint8Array","getRandomValues","str","n","getSelectionEndPoint","selection","backward","anchor","focus","getSelectionStartPoint","sliceBlocks","startBlock","middleBlocks","endBlock","startPoint","endPoint","startBlockKey","startChildKey","endBlockKey","endChildKey","push","parsedStartBlock","parsedEndBlock","getTextBlockText","join"],"mappings":";;;;;;AASO,SAASA,mBAAmB;AAAA,EACjCC;AAAAA,EACAC;AAOF,GAAyB;AACvB,SAAIC,mBAAYF,SAASC,MAAME,IAAI,IAC1B;AAAA,IACLC,MAAM,CAAC,GAAGH,MAAMG,MAAM,YAAY;AAAA,MAACC,MAAMJ,MAAME,KAAKG,SAAS,CAAC,EAAED;AAAAA,IAAAA,CAAK;AAAA,IACrEE,QAAQ;AAAA,EAAA,IAIL;AAAA,IACLH,MAAMH,MAAMG;AAAAA,IACZG,QAAQ;AAAA,EAAA;AAEZ;ACzBO,SAASC,eAAeC,SAA2C;AACxE,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;ACJO,SAASC,8BAA8BC,OAA6B;AACzE,QAAMC,mBAAmBD,MAAMP,KAAKS,GAAG,CAAC;AAExC,MAAIL,eAAeI,gBAAgB;AACjC,WAAOA,iBAAiBP;AAI5B;AAEO,SAASS,8BAA8BH,OAA6B;AACzE,QAAMI,mBAAmBJ,MAAMP,KAAKS,GAAG,CAAC;AAExC,MAAIL,eAAeO,gBAAgB;AACjC,WAAOA,iBAAiBV;AAI5B;ACRO,SAASW,gCAAgC;AAAA,EAC9ChB;AAAAA,EACAiB;AAAAA,EACAC;AAKF,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E/C;ACzMO,SAASC,iBAAiBnI,OAA8B;AAC7D,SAAOA,MAAMK,SAASkE,IAAKjD,CAAAA,UAAUA,MAAME,QAAQ,EAAE,EAAE4G,KAAK,EAAE;AAChE;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var schema = require("@portabletext/schema"), util_sliceBlocks = require("./util.slice-blocks.cjs");
2
+ var schema = require("@portabletext/schema"), util_getTextBlockText = require("./util.get-text-block-text.cjs");
3
3
  function getBlockEndPoint({
4
4
  context,
5
5
  block
@@ -19,20 +19,20 @@ function getBlockEndPoint({
19
19
  offset: 0
20
20
  };
21
21
  }
22
- function isEmptyTextBlock(context, block) {
23
- if (!schema.isTextBlock(context, block))
24
- return !1;
25
- const onlyText = block.children.every((child) => schema.isSpan(context, child)), blockText = util_sliceBlocks.getTextBlockText(block);
26
- return onlyText && blockText === "";
22
+ function isSelectionCollapsed(selection) {
23
+ return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
27
24
  }
28
25
  function isEqualSelectionPoints(a, b) {
29
26
  return a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path);
30
27
  }
31
- function isSelectionCollapsed(selection) {
32
- return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
28
+ function isEmptyTextBlock(context, block) {
29
+ if (!schema.isTextBlock(context, block))
30
+ return !1;
31
+ const onlyText = block.children.every((child) => schema.isSpan(context, child)), blockText = util_getTextBlockText.getTextBlockText(block);
32
+ return onlyText && blockText === "";
33
33
  }
34
34
  exports.getBlockEndPoint = getBlockEndPoint;
35
35
  exports.isEmptyTextBlock = isEmptyTextBlock;
36
36
  exports.isEqualSelectionPoints = isEqualSelectionPoints;
37
37
  exports.isSelectionCollapsed = isSelectionCollapsed;
38
- //# sourceMappingURL=util.is-selection-collapsed.cjs.map
38
+ //# sourceMappingURL=util.is-empty-text-block.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.is-empty-text-block.cjs","sources":["../../src/utils/util.get-block-end-point.ts","../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.is-equal-selection-points.ts","../../src/utils/util.is-empty-text-block.ts"],"sourcesContent":["import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: BlockPath\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n const lastChild = block.node.children[block.node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...block.path, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\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 JSON.stringify(selection.anchor.path) ===\n JSON.stringify(selection.focus.path) &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock,\n) {\n if (!isTextBlock(context, block)) {\n return false\n }\n\n const onlyText = block.children.every((child) => isSpan(context, child))\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n"],"names":["getBlockEndPoint","context","block","isTextBlock","node","lastChild","children","length","path","_key","offset","isSpan","text","isSelectionCollapsed","selection","JSON","stringify","anchor","focus","isEqualSelectionPoints","a","b","isEmptyTextBlock","onlyText","every","child","blockText","getTextBlockText"],"mappings":";;AASO,SAASA,iBAAiB;AAAA,EAC/BC;AAAAA,EACAC;AAOF,GAAyB;AACvB,MAAIC,mBAAYF,SAASC,MAAME,IAAI,GAAG;AACpC,UAAMC,YAAYH,MAAME,KAAKE,SAASJ,MAAME,KAAKE,SAASC,SAAS,CAAC;AAEpE,QAAIF;AACF,aAAO;AAAA,QACLG,MAAM,CAAC,GAAGN,MAAMM,MAAM,YAAY;AAAA,UAACC,MAAMJ,UAAUI;AAAAA,QAAAA,CAAK;AAAA,QACxDC,QAAQC,OAAAA,OAAOV,SAASI,SAAS,IAAIA,UAAUO,KAAKL,SAAS;AAAA,MAAA;AAAA,EAGnE;AAEA,SAAO;AAAA,IACLC,MAAMN,MAAMM;AAAAA,IACZE,QAAQ;AAAA,EAAA;AAEZ;AC7BO,SAASG,qBAAqBC,WAA4B;AAC/D,SAAKA,YAKHC,KAAKC,UAAUF,UAAUG,OAAOT,IAAI,MAClCO,KAAKC,UAAUF,UAAUI,MAAMV,IAAI,KACrCM,UAAUG,OAAOP,WAAWI,UAAUI,MAAMR,SANrC;AAQX;ACVO,SAASS,uBACdC,GACAC,GACA;AACA,SACED,EAAEV,WAAWW,EAAEX,UAAUK,KAAKC,UAAUI,EAAEZ,IAAI,MAAMO,KAAKC,UAAUK,EAAEb,IAAI;AAE7E;ACJO,SAASc,iBACdrB,SACAC,OACA;AACA,MAAI,CAACC,OAAAA,YAAYF,SAASC,KAAK;AAC7B,WAAO;AAGT,QAAMqB,WAAWrB,MAAMI,SAASkB,MAAOC,CAAAA,UAAUd,cAAOV,SAASwB,KAAK,CAAC,GACjEC,YAAYC,sBAAAA,iBAAiBzB,KAAK;AAExC,SAAOqB,YAAYG,cAAc;AACnC;;;;;"}
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
- var schema = require("@portabletext/schema"), util_sliceBlocks = require("./util.slice-blocks.cjs");
2
+ var schema = require("@portabletext/schema"), util_getTextBlockText = require("./util.get-text-block-text.cjs");
3
3
  function mergeTextBlocks({
4
4
  context,
5
5
  targetBlock,
6
6
  incomingBlock
7
7
  }) {
8
- const parsedIncomingBlock = util_sliceBlocks.parseBlock({
8
+ const parsedIncomingBlock = util_getTextBlockText.parseBlock({
9
9
  context,
10
10
  block: incomingBlock,
11
11
  options: {
@@ -1 +1 @@
1
- {"version":3,"file":"util.merge-text-blocks.cjs","sources":["../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n"],"names":["mergeTextBlocks","context","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","block","options","removeUnusedMarkDefs","validateFields","isTextBlock","children","markDefs"],"mappings":";;AAQO,SAASA,gBAAgB;AAAA,EAC9BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,iBAAAA,WAAW;AAAA,IACrCJ;AAAAA,IACAK,OAAOH;AAAAA,IACPI,SAAS;AAAA,MAACC,sBAAsB;AAAA,MAAMC,gBAAgB;AAAA,IAAA;AAAA,EAAK,CAC5D;AAED,SAAI,CAACL,uBAAuB,CAACM,OAAAA,YAAYT,SAASG,mBAAmB,IAC5DF,cAGF;AAAA,IACL,GAAGA;AAAAA,IACHS,UAAU,CAAC,GAAGT,YAAYS,UAAU,GAAGP,oBAAoBO,QAAQ;AAAA,IACnEC,UAAU,CACR,GAAIV,YAAYU,YAAY,CAAA,GAC5B,GAAIR,oBAAoBQ,YAAY,CAAA,CAAG;AAAA,EAAA;AAG7C;;"}
1
+ {"version":3,"file":"util.merge-text-blocks.cjs","sources":["../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {parseBlock} from './parse-blocks'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n"],"names":["mergeTextBlocks","context","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","block","options","removeUnusedMarkDefs","validateFields","isTextBlock","children","markDefs"],"mappings":";;AAQO,SAASA,gBAAgB;AAAA,EAC9BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,sBAAAA,WAAW;AAAA,IACrCJ;AAAAA,IACAK,OAAOH;AAAAA,IACPI,SAAS;AAAA,MAACC,sBAAsB;AAAA,MAAMC,gBAAgB;AAAA,IAAA;AAAA,EAAK,CAC5D;AAED,SAAI,CAACL,uBAAuB,CAACM,OAAAA,YAAYT,SAASG,mBAAmB,IAC5DF,cAGF;AAAA,IACL,GAAGA;AAAAA,IACHS,UAAU,CAAC,GAAGT,YAAYS,UAAU,GAAGP,oBAAoBO,QAAQ;AAAA,IACnEC,UAAU,CACR,GAAIV,YAAYU,YAAY,CAAA,GAC5B,GAAIR,oBAAoBQ,YAAY,CAAA,CAAG;AAAA,EAAA;AAG7C;;"}
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
- var util_sliceBlocks = require("./util.slice-blocks.cjs"), util_childSelectionPointToBlockOffset = require("./util.child-selection-point-to-block-offset.cjs"), schema = require("@portabletext/schema");
2
+ var util_childSelectionPointToBlockOffset = require("./util.child-selection-point-to-block-offset.cjs"), util_getTextBlockText = require("./util.get-text-block-text.cjs"), schema = require("@portabletext/schema");
3
3
  function selectionPointToBlockOffset({
4
4
  context,
5
5
  selectionPoint
6
6
  }) {
7
- const blockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(selectionPoint);
7
+ const blockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(selectionPoint);
8
8
  return selectionPoint.path.length === 1 && blockKey !== void 0 ? {
9
9
  path: [{
10
10
  _key: blockKey
@@ -19,13 +19,13 @@ function sliceTextBlock({
19
19
  context,
20
20
  block
21
21
  }) {
22
- const startPoint = util_sliceBlocks.getSelectionStartPoint(context.selection), endPoint = util_sliceBlocks.getSelectionEndPoint(context.selection);
22
+ const startPoint = util_getTextBlockText.getSelectionStartPoint(context.selection), endPoint = util_getTextBlockText.getSelectionEndPoint(context.selection);
23
23
  if (!startPoint || !endPoint)
24
24
  return block;
25
- const startBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(endPoint);
25
+ const startBlockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(endPoint);
26
26
  if (startBlockKey !== endBlockKey || startBlockKey !== block._key)
27
27
  return block;
28
- const startChildKey = util_sliceBlocks.getChildKeyFromSelectionPoint(startPoint), endChildKey = util_sliceBlocks.getChildKeyFromSelectionPoint(endPoint);
28
+ const startChildKey = util_getTextBlockText.getChildKeyFromSelectionPoint(startPoint), endChildKey = util_getTextBlockText.getChildKeyFromSelectionPoint(endPoint);
29
29
  if (!startChildKey || !endChildKey)
30
30
  return block;
31
31
  let startChildFound = !1;