@portabletext/editor 2.13.3 → 2.13.5

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 (186) 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 +271 -271
  18. package/lib/_chunks-dts/behavior.types.action.d.ts +322 -322
  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.ts +2 -2
  52. package/lib/utils/index.js +3 -3
  53. package/lib/utils/index.js.map +1 -1
  54. package/package.json +14 -14
  55. package/src/behaviors/behavior.abstract.annotation.ts +3 -3
  56. package/src/behaviors/behavior.abstract.decorator.ts +2 -2
  57. package/src/behaviors/behavior.abstract.delete.ts +25 -16
  58. package/src/behaviors/behavior.abstract.deserialize.ts +4 -3
  59. package/src/behaviors/behavior.abstract.insert.ts +6 -7
  60. package/src/behaviors/behavior.abstract.keyboard.ts +7 -8
  61. package/src/behaviors/behavior.abstract.list-item.ts +2 -1
  62. package/src/behaviors/behavior.abstract.move.ts +2 -1
  63. package/src/behaviors/behavior.abstract.select.ts +4 -2
  64. package/src/behaviors/behavior.abstract.split.ts +33 -24
  65. package/src/behaviors/behavior.abstract.style.ts +2 -1
  66. package/src/behaviors/behavior.abstract.ts +8 -7
  67. package/src/behaviors/behavior.core.annotations.ts +8 -7
  68. package/src/behaviors/behavior.core.block-element.ts +7 -5
  69. package/src/behaviors/behavior.core.block-objects.ts +25 -27
  70. package/src/behaviors/behavior.core.dnd.ts +10 -8
  71. package/src/behaviors/behavior.core.insert-break.ts +45 -36
  72. package/src/behaviors/behavior.core.lists.ts +31 -25
  73. package/src/behaviors/behavior.decorator-pair.ts +26 -23
  74. package/src/behaviors/behavior.markdown.ts +26 -21
  75. package/src/converters/converter.portable-text.ts +3 -3
  76. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  77. package/src/converters/converter.text-html.ts +3 -3
  78. package/src/converters/converter.text-plain.test.ts +1 -1
  79. package/src/converters/converter.text-plain.ts +3 -3
  80. package/src/editor/Editable.tsx +2 -2
  81. package/src/editor/components/render-span.tsx +3 -5
  82. package/src/editor/create-editor.ts +2 -2
  83. package/src/editor/create-slate-editor.tsx +1 -4
  84. package/src/editor/editor-dom.ts +2 -2
  85. package/src/editor/plugins/createWithEditableAPI.ts +5 -10
  86. package/src/editor/plugins/createWithMaxBlocks.ts +2 -2
  87. package/src/editor/plugins/createWithObjectKeys.ts +2 -2
  88. package/src/editor/plugins/createWithPatches.ts +3 -10
  89. package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -2
  90. package/src/editor/plugins/createWithPortableTextMarkModel.ts +2 -2
  91. package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
  92. package/src/editor/plugins/createWithUndoRedo.ts +6 -6
  93. package/src/editor/plugins/slate-plugin.update-selection.ts +1 -1
  94. package/src/editor/sync-machine.ts +2 -5
  95. package/src/{internal-utils → editor}/weakMaps.ts +1 -1
  96. package/src/editor/with-undo-step.ts +1 -1
  97. package/src/index.ts +1 -1
  98. package/src/internal-utils/applyPatch.ts +2 -2
  99. package/src/internal-utils/build-index-maps.test.ts +1 -1
  100. package/src/internal-utils/create-test-snapshot.ts +1 -1
  101. package/src/internal-utils/event-position.ts +11 -9
  102. package/src/internal-utils/operation-to-patches.test.ts +1 -1
  103. package/src/internal-utils/portable-text-node.ts +1 -1
  104. package/src/internal-utils/selection-block-keys.ts +1 -1
  105. package/src/internal-utils/selection-focus-text.ts +1 -1
  106. package/src/internal-utils/to-slate-range.ts +4 -4
  107. package/src/operations/behavior.operation.annotation.add.ts +1 -1
  108. package/src/operations/behavior.operation.block.set.ts +1 -1
  109. package/src/operations/behavior.operation.block.unset.ts +2 -2
  110. package/src/operations/behavior.operation.decorator.add.ts +11 -9
  111. package/src/operations/behavior.operation.delete.ts +1 -1
  112. package/src/operations/behavior.operation.insert.block.ts +2 -2
  113. package/src/operations/behavior.operation.insert.child.ts +1 -1
  114. package/src/operations/behavior.operation.move.block.ts +1 -1
  115. package/src/plugins/plugin.behavior.tsx +1 -1
  116. package/src/plugins/plugin.decorator-shortcut.ts +3 -3
  117. package/src/plugins/plugin.internal.auto-close-brackets.ts +2 -1
  118. package/src/plugins/plugin.one-line.tsx +11 -11
  119. package/src/priority/priority.types.ts +1 -1
  120. package/src/{internal-utils → selectors}/drag-selection.test.ts +1 -1
  121. package/src/{internal-utils → selectors}/drag-selection.ts +26 -19
  122. package/src/selectors/selector.get-anchor-block.ts +1 -1
  123. package/src/selectors/selector.get-anchor-child.ts +1 -1
  124. package/src/selectors/selector.get-block-offsets.ts +3 -3
  125. package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
  126. package/src/selectors/selector.get-focus-block.ts +1 -1
  127. package/src/selectors/selector.get-focus-child.ts +1 -1
  128. package/src/selectors/selector.get-focus-list-block.ts +1 -1
  129. package/src/selectors/selector.get-list-state.test.ts +1 -1
  130. package/src/selectors/selector.get-mark-state.ts +1 -1
  131. package/src/selectors/selector.get-next-inline-object.ts +1 -1
  132. package/src/selectors/selector.get-next-span.ts +1 -1
  133. package/src/selectors/selector.get-previous-inline-object.ts +1 -1
  134. package/src/selectors/selector.get-previous-span.ts +1 -1
  135. package/src/selectors/selector.get-selected-blocks.ts +1 -1
  136. package/src/selectors/selector.get-selected-spans.test.ts +1 -1
  137. package/src/selectors/selector.get-selected-spans.ts +2 -2
  138. package/src/selectors/selector.get-selected-text-blocks.ts +3 -2
  139. package/src/selectors/selector.get-selected-value.test.ts +87 -1
  140. package/src/selectors/selector.get-selected-value.ts +4 -6
  141. package/src/selectors/selector.get-selection-end-point.ts +1 -1
  142. package/src/selectors/selector.get-selection-start-point.ts +1 -1
  143. package/src/selectors/selector.get-selection-text.test.ts +1 -1
  144. package/src/selectors/selector.get-selection.ts +1 -1
  145. package/src/selectors/selector.get-text-before.ts +1 -1
  146. package/src/selectors/selector.get-trimmed-selection.test.ts +1 -1
  147. package/src/selectors/selector.get-trimmed-selection.ts +5 -7
  148. package/src/selectors/selector.is-active-decorator.test.ts +2 -1
  149. package/src/selectors/selector.is-at-the-end-of-block.ts +4 -3
  150. package/src/selectors/selector.is-at-the-start-of-block.ts +4 -3
  151. package/src/selectors/selector.is-overlapping-selection.test.ts +1 -1
  152. package/src/selectors/selector.is-overlapping-selection.ts +1 -1
  153. package/src/selectors/selector.is-point-after-selection.ts +3 -3
  154. package/src/selectors/selector.is-point-before-selection.ts +3 -3
  155. package/src/selectors/selector.is-selecting-entire-blocks.ts +7 -5
  156. package/src/test/gherkin-parameter-types.ts +3 -3
  157. package/src/test/vitest/step-definitions.tsx +19 -9
  158. package/src/types/paths.ts +4 -1
  159. package/src/utils/util.at-the-beginning-of-block.ts +1 -1
  160. package/src/utils/util.block-offset.ts +4 -4
  161. package/src/utils/util.block-offsets-to-selection.ts +1 -1
  162. package/src/utils/util.child-selection-point-to-block-offset.ts +3 -3
  163. package/src/utils/util.get-selection-end-point.ts +1 -1
  164. package/src/utils/util.get-selection-start-point.ts +1 -1
  165. package/src/utils/util.merge-text-blocks.ts +2 -2
  166. package/src/utils/util.selection-point-to-block-offset.ts +1 -1
  167. package/src/{selection/selection-point.ts → utils/util.selection-point.ts} +1 -1
  168. package/src/utils/util.slice-blocks.ts +6 -6
  169. package/src/utils/util.slice-text-block.test.ts +3 -1
  170. package/src/utils/util.slice-text-block.ts +3 -3
  171. package/src/utils/util.split-text-block.ts +1 -1
  172. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +0 -1
  173. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
  174. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +0 -1
  175. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
  176. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
  177. package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
  178. package/lib/_chunks-es/util.is-selection-collapsed.js.map +0 -1
  179. package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
  180. /package/src/{internal-utils → editor}/withChanges.ts +0 -0
  181. /package/src/{internal-utils → editor}/withUndoRedo.ts +0 -0
  182. /package/src/{internal-utils → editor}/withoutPatching.ts +0 -0
  183. /package/src/{internal-utils → utils}/asserters.ts +0 -0
  184. /package/src/{editor → utils}/key-generator.ts +0 -0
  185. /package/src/{internal-utils → utils}/parse-blocks.test.ts +0 -0
  186. /package/src/{internal-utils → utils}/parse-blocks.ts +0 -0
@@ -1,5 +1,5 @@
1
1
  import { isTextBlock, isSpan } from "@portabletext/schema";
2
- import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint, sliceBlocks } from "./util.slice-blocks.js";
2
+ import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint, sliceBlocks } from "./util.get-text-block-text.js";
3
3
  import { isKeySegment } from "@sanity/types";
4
4
  const getFocusBlock = (snapshot) => {
5
5
  if (!snapshot.context.selection)
@@ -39,23 +39,7 @@ const getFocusBlock = (snapshot) => {
39
39
  }, getSelectionStartPoint = (snapshot) => {
40
40
  if (snapshot.context.selection)
41
41
  return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
42
- }, getPreviousInlineObject = (snapshot) => {
43
- const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
44
- if (!focusTextBlock || !selectionStartPointChildKey)
45
- return;
46
- let inlineObject;
47
- for (const child of focusTextBlock.node.children) {
48
- if (child._key === selectionStartPointChildKey)
49
- break;
50
- isSpan(snapshot.context, child) || (inlineObject = {
51
- node: child,
52
- path: [...focusTextBlock.path, "children", {
53
- _key: child._key
54
- }]
55
- });
56
- }
57
- return inlineObject;
58
- }, getSelectedValue = (snapshot) => {
42
+ }, isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, isSelectionExpanded = (snapshot) => !isSelectionCollapsed(snapshot), getSelectedValue = (snapshot) => {
59
43
  const selection = snapshot.context.selection;
60
44
  if (!selection)
61
45
  return [];
@@ -76,7 +60,23 @@ const getFocusBlock = (snapshot) => {
76
60
  blocks: [endBlock]
77
61
  }).at(0) : void 0, middleBlocks = snapshot.context.value.slice(startBlockIndex + 1, endBlockIndex);
78
62
  return [...slicedStartBlock ? [slicedStartBlock] : [], ...middleBlocks, ...slicedEndBlock ? [slicedEndBlock] : []];
79
- }, getSelectionText = (snapshot) => getSelectedValue(snapshot).reduce((text, block) => isTextBlock(snapshot.context, block) ? text + block.children.reduce((text2, child) => isSpan(snapshot.context, child) ? text2 + child.text : text2, "") : text, ""), isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, isSelectionExpanded = (snapshot) => !isSelectionCollapsed(snapshot);
63
+ }, getPreviousInlineObject = (snapshot) => {
64
+ const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
65
+ if (!focusTextBlock || !selectionStartPointChildKey)
66
+ return;
67
+ let inlineObject;
68
+ for (const child of focusTextBlock.node.children) {
69
+ if (child._key === selectionStartPointChildKey)
70
+ break;
71
+ isSpan(snapshot.context, child) || (inlineObject = {
72
+ node: child,
73
+ path: [...focusTextBlock.path, "children", {
74
+ _key: child._key
75
+ }]
76
+ });
77
+ }
78
+ return inlineObject;
79
+ }, getSelectionText = (snapshot) => getSelectedValue(snapshot).reduce((text, block) => isTextBlock(snapshot.context, block) ? text + block.children.reduce((text2, child) => isSpan(snapshot.context, child) ? text2 + child.text : text2, "") : text, "");
80
80
  export {
81
81
  getFocusBlock,
82
82
  getFocusChild,
@@ -89,4 +89,4 @@ export {
89
89
  isSelectionCollapsed,
90
90
  isSelectionExpanded
91
91
  };
92
- //# sourceMappingURL=selector.is-selection-expanded.js.map
92
+ //# sourceMappingURL=selector.get-selection-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selector.get-selection-text.js","sources":["../../src/selectors/selector.get-focus-block.ts","../../src/selectors/selector.get-focus-text-block.ts","../../src/selectors/selector.get-focus-child.ts","../../src/selectors/selector.get-focus-span.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-selected-value.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selection-text.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\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 {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; 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 {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isSpan} from '@portabletext/schema'\nimport type {PortableTextSpan} 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 getFocusSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: 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.focus\n : snapshot.context.selection.anchor\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {\n return !isSelectionCollapsed(snapshot)\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\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'\nimport {sliceBlocks} from '../utils/util.slice-blocks'\n\n/**\n * @public\n */\nexport const getSelectedValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return []\n }\n\n const startPoint = getSelectionStartPoint(selection)\n const endPoint = getSelectionEndPoint(selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return []\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 []\n }\n\n const startBlock = snapshot.context.value.at(startBlockIndex)\n const slicedStartBlock = startBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [startBlock],\n }).at(0)\n : undefined\n\n if (startBlockIndex === endBlockIndex) {\n return slicedStartBlock ? [slicedStartBlock] : []\n }\n\n const endBlock = snapshot.context.value.at(endBlockIndex)\n const slicedEndBlock = endBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [endBlock],\n }).at(0)\n : undefined\n\n const middleBlocks = snapshot.context.value.slice(\n startBlockIndex + 1,\n endBlockIndex,\n )\n\n return [\n ...(slicedStartBlock ? [slicedStartBlock] : []),\n ...middleBlocks,\n ...(slicedEndBlock ? [slicedEndBlock] : []),\n ]\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 {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\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 === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedValue = getSelectedValue(snapshot)\n\n return selectedValue.reduce((text, block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isSpan(snapshot.context, child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n"],"names":["getFocusBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","focus","index","blockIndexMap","get","undefined","node","value","at","path","_key","getFocusTextBlock","focusBlock","isTextBlock","getFocusChild","getChildKeyFromSelectionPoint","children","find","span","getFocusSpan","focusChild","isSpan","getSelectionStartPoint","backward","anchor","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","getSelectedValue","startPoint","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startBlockIndex","endBlockIndex","startBlock","slicedStartBlock","sliceBlocks","blocks","endBlock","slicedEndBlock","middleBlocks","slice","getPreviousInlineObject","focusTextBlock","selectionStartPoint","selectionStartPointChildKey","isKeySegment","inlineObject","child","getSelectionText","reduce","text","block"],"mappings":";;;AAQO,MAAMA,gBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC,QAAQC,UAAUG,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AAG,CAAC,IACPH,QAEEuC,eAAehD,SAASC,QAAQU,MAAMsC,MAC1CT,kBAAkB,GAClBC,aACF;AAEA,SAAO,CACL,GAAIE,mBAAmB,CAACA,gBAAgB,IAAI,CAAA,GAC5C,GAAGK,cACH,GAAID,iBAAiB,CAACA,cAAc,IAAI,CAAA,CAAG;AAE/C,GCvDaG,0BAMRlD,CAAAA,aAAa;AAChB,QAAMmD,iBAAiBpC,kBAAkBf,QAAQ,GAC3CoD,sBAAsB1B,uBAAuB1B,QAAQ,GACrDqD,8BACJD,uBAAuBE,aAAaF,oBAAoBvC,KAAK,CAAC,CAAC,IAC3DuC,oBAAoBvC,KAAK,CAAC,EAAEC,OAC5BL;AAEN,MAAI,CAAC0C,kBAAkB,CAACE;AACtB;AAGF,MAAIE;AAOJ,aAAWC,SAASL,eAAezC,KAAKU,UAAU;AAChD,QAAIoC,MAAM1C,SAASuC;AACjB;AAGG5B,WAAOzB,SAASC,SAASuD,KAAK,MACjCD,eAAe;AAAA,MACb7C,MAAM8C;AAAAA,MACN3C,MAAM,CAAC,GAAGsC,eAAetC,MAAM,YAAY;AAAA,QAACC,MAAM0C,MAAM1C;AAAAA,MAAAA,CAAK;AAAA,IAAA;AAAA,EAGnE;AAEA,SAAOyC;AACT,GC1CaE,mBAA4CzD,CAAAA,aACjCkC,iBAAiBlC,QAAQ,EAE1B0D,OAAO,CAACC,MAAMC,UAC5B3C,YAAYjB,SAASC,SAAS2D,KAAK,IAKtCD,OACAC,MAAMxC,SAASsC,OAAO,CAACC,OAAMH,UACvB/B,OAAOzB,SAASC,SAASuD,KAAK,IACzBG,QAAOH,MAAMG,OAGfA,OACN,EAAE,IAXEA,MAaR,EAAE;"}
@@ -1,5 +1,5 @@
1
- import { getSelectionStartPoint, getBlockStartPoint } from "./util.slice-blocks.js";
2
- import { getFocusBlock, getSelectionText } from "./selector.is-selection-expanded.js";
1
+ import { getSelectionStartPoint, getBlockStartPoint } from "./util.get-text-block-text.js";
2
+ import { getFocusBlock, getSelectionText } from "./selector.get-selection-text.js";
3
3
  const getBlockTextBefore = (snapshot) => {
4
4
  if (!snapshot.context.selection)
5
5
  return "";
@@ -1 +1 @@
1
- {"version":3,"file":"selector.get-text-before.js","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionStartPoint} from '../utils'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","startPoint","getSelectionStartPoint","block","getFocusBlock","anchor","focus","startOfBlock","getBlockStartPoint","getSelectionText"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAAA,aAAa;AACtE,MAAI,CAACA,SAASC,QAAQC;AACpB,WAAO;AAGT,QAAMC,aAAaC,uBAAuBJ,SAASC,QAAQC,SAAS,GAC9DG,QAAQC,cAAc;AAAA,IAC1B,GAAGN;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQJ;AAAAA,QACRK,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACE;AACH,WAAO;AAGT,QAAMI,eAAeC,mBAAmB;AAAA,IACtCT,SAASD,SAASC;AAAAA,IAClBI;AAAAA,EAAAA,CACD;AAED,SAAOM,iBAAiB;AAAA,IACtB,GAAGX;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQE;AAAAA,QACRD,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;"}
1
+ {"version":3,"file":"selector.get-text-before.js","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","startPoint","getSelectionStartPoint","block","getFocusBlock","anchor","focus","startOfBlock","getBlockStartPoint","getSelectionText"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAAA,aAAa;AACtE,MAAI,CAACA,SAASC,QAAQC;AACpB,WAAO;AAGT,QAAMC,aAAaC,uBAAuBJ,SAASC,QAAQC,SAAS,GAC9DG,QAAQC,cAAc;AAAA,IAC1B,GAAGN;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQJ;AAAAA,QACRK,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACE;AACH,WAAO;AAGT,QAAMI,eAAeC,mBAAmB;AAAA,IACtCT,SAASD,SAASC;AAAAA,IAClBI;AAAAA,EAAAA,CACD;AAED,SAAOM,iBAAiB;AAAA,IACtB,GAAGX;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQE;AAAAA,QACRD,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;"}