@portabletext/editor 2.13.2 → 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 (191) 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 +273 -273
  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 +429 -363
  36. package/lib/index.cjs.map +1 -1
  37. package/lib/index.js +225 -159
  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.d.cts +4 -1
  48. package/lib/selectors/index.d.ts +4 -1
  49. package/lib/selectors/index.js +5 -5
  50. package/lib/selectors/index.js.map +1 -1
  51. package/lib/utils/index.cjs +14 -14
  52. package/lib/utils/index.cjs.map +1 -1
  53. package/lib/utils/index.d.ts +2 -2
  54. package/lib/utils/index.js +3 -3
  55. package/lib/utils/index.js.map +1 -1
  56. package/package.json +12 -12
  57. package/src/behaviors/behavior.abstract.annotation.ts +3 -3
  58. package/src/behaviors/behavior.abstract.decorator.ts +2 -2
  59. package/src/behaviors/behavior.abstract.delete.ts +25 -16
  60. package/src/behaviors/behavior.abstract.deserialize.ts +4 -3
  61. package/src/behaviors/behavior.abstract.insert.ts +6 -7
  62. package/src/behaviors/behavior.abstract.keyboard.ts +7 -8
  63. package/src/behaviors/behavior.abstract.list-item.ts +2 -1
  64. package/src/behaviors/behavior.abstract.move.ts +2 -1
  65. package/src/behaviors/behavior.abstract.select.ts +4 -2
  66. package/src/behaviors/behavior.abstract.split.ts +33 -24
  67. package/src/behaviors/behavior.abstract.style.ts +2 -1
  68. package/src/behaviors/behavior.abstract.ts +8 -7
  69. package/src/behaviors/behavior.core.annotations.ts +8 -7
  70. package/src/behaviors/behavior.core.block-element.ts +7 -5
  71. package/src/behaviors/behavior.core.block-objects.ts +25 -27
  72. package/src/behaviors/behavior.core.dnd.ts +10 -8
  73. package/src/behaviors/behavior.core.insert-break.ts +45 -36
  74. package/src/behaviors/behavior.core.lists.ts +31 -25
  75. package/src/behaviors/behavior.decorator-pair.ts +26 -23
  76. package/src/behaviors/behavior.markdown.ts +26 -21
  77. package/src/converters/converter.portable-text.ts +3 -3
  78. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  79. package/src/converters/converter.text-html.ts +3 -3
  80. package/src/converters/converter.text-plain.test.ts +1 -1
  81. package/src/converters/converter.text-plain.ts +3 -3
  82. package/src/editor/Editable.tsx +18 -78
  83. package/src/editor/components/render-span.tsx +3 -5
  84. package/src/editor/create-editor.ts +2 -2
  85. package/src/editor/create-slate-editor.tsx +1 -4
  86. package/src/editor/editor-dom.ts +2 -2
  87. package/src/editor/plugins/createWithEditableAPI.ts +5 -10
  88. package/src/editor/plugins/createWithMaxBlocks.ts +2 -2
  89. package/src/editor/plugins/createWithObjectKeys.ts +2 -2
  90. package/src/editor/plugins/createWithPatches.ts +3 -10
  91. package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -2
  92. package/src/editor/plugins/createWithPortableTextMarkModel.ts +2 -2
  93. package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
  94. package/src/editor/plugins/createWithUndoRedo.ts +6 -6
  95. package/src/editor/plugins/slate-plugin.update-selection.ts +1 -1
  96. package/src/editor/sync-machine.ts +2 -5
  97. package/src/editor/validate-selection-machine.test.ts +47 -0
  98. package/src/editor/validate-selection-machine.ts +149 -0
  99. package/src/{internal-utils → editor}/weakMaps.ts +1 -1
  100. package/src/editor/with-undo-step.ts +1 -1
  101. package/src/index.ts +1 -1
  102. package/src/internal-utils/applyPatch.ts +2 -2
  103. package/src/internal-utils/build-index-maps.test.ts +1 -1
  104. package/src/internal-utils/create-test-snapshot.ts +1 -1
  105. package/src/internal-utils/event-position.ts +11 -9
  106. package/src/internal-utils/operation-to-patches.test.ts +1 -1
  107. package/src/internal-utils/portable-text-node.ts +1 -1
  108. package/src/internal-utils/selection-block-keys.ts +1 -1
  109. package/src/internal-utils/selection-focus-text.ts +1 -1
  110. package/src/internal-utils/to-slate-range.ts +4 -4
  111. package/src/operations/behavior.operation.annotation.add.ts +1 -1
  112. package/src/operations/behavior.operation.block.set.ts +1 -1
  113. package/src/operations/behavior.operation.block.unset.ts +2 -2
  114. package/src/operations/behavior.operation.decorator.add.ts +11 -9
  115. package/src/operations/behavior.operation.delete.ts +1 -1
  116. package/src/operations/behavior.operation.insert.block.ts +2 -2
  117. package/src/operations/behavior.operation.insert.child.ts +1 -1
  118. package/src/operations/behavior.operation.move.block.ts +1 -1
  119. package/src/plugins/plugin.behavior.tsx +1 -1
  120. package/src/plugins/plugin.decorator-shortcut.ts +3 -3
  121. package/src/plugins/plugin.internal.auto-close-brackets.ts +2 -1
  122. package/src/plugins/plugin.one-line.tsx +11 -11
  123. package/src/priority/priority.types.ts +1 -1
  124. package/src/{internal-utils → selectors}/drag-selection.test.ts +1 -1
  125. package/src/{internal-utils → selectors}/drag-selection.ts +26 -19
  126. package/src/selectors/index.ts +1 -1
  127. package/src/selectors/selector.get-anchor-block.ts +1 -1
  128. package/src/selectors/selector.get-anchor-child.ts +1 -1
  129. package/src/selectors/selector.get-block-offsets.ts +3 -3
  130. package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
  131. package/src/selectors/selector.get-focus-block.ts +1 -1
  132. package/src/selectors/selector.get-focus-child.ts +1 -1
  133. package/src/selectors/selector.get-focus-list-block.ts +1 -1
  134. package/src/selectors/selector.get-list-state.test.ts +1 -1
  135. package/src/selectors/selector.get-mark-state.ts +4 -1
  136. package/src/selectors/selector.get-next-inline-object.ts +1 -1
  137. package/src/selectors/selector.get-next-span.ts +1 -1
  138. package/src/selectors/selector.get-previous-inline-object.ts +1 -1
  139. package/src/selectors/selector.get-previous-span.ts +1 -1
  140. package/src/selectors/selector.get-selected-blocks.ts +1 -1
  141. package/src/selectors/selector.get-selected-spans.test.ts +1 -1
  142. package/src/selectors/selector.get-selected-spans.ts +2 -2
  143. package/src/selectors/selector.get-selected-text-blocks.ts +3 -2
  144. package/src/selectors/selector.get-selected-value.test.ts +87 -1
  145. package/src/selectors/selector.get-selected-value.ts +4 -6
  146. package/src/selectors/selector.get-selection-end-point.ts +1 -1
  147. package/src/selectors/selector.get-selection-start-point.ts +1 -1
  148. package/src/selectors/selector.get-selection-text.test.ts +1 -1
  149. package/src/selectors/selector.get-selection.ts +1 -1
  150. package/src/selectors/selector.get-text-before.ts +1 -1
  151. package/src/selectors/selector.get-trimmed-selection.test.ts +1 -1
  152. package/src/selectors/selector.get-trimmed-selection.ts +5 -7
  153. package/src/selectors/selector.is-active-decorator.test.ts +2 -1
  154. package/src/selectors/selector.is-at-the-end-of-block.ts +4 -3
  155. package/src/selectors/selector.is-at-the-start-of-block.ts +4 -3
  156. package/src/selectors/selector.is-overlapping-selection.test.ts +1 -1
  157. package/src/selectors/selector.is-overlapping-selection.ts +1 -1
  158. package/src/selectors/selector.is-point-after-selection.ts +3 -3
  159. package/src/selectors/selector.is-point-before-selection.ts +3 -3
  160. package/src/selectors/selector.is-selecting-entire-blocks.ts +7 -5
  161. package/src/test/gherkin-parameter-types.ts +1 -1
  162. package/src/test/vitest/step-definitions.tsx +19 -9
  163. package/src/types/paths.ts +4 -1
  164. package/src/utils/util.at-the-beginning-of-block.ts +1 -1
  165. package/src/utils/util.block-offset.ts +4 -4
  166. package/src/utils/util.block-offsets-to-selection.ts +1 -1
  167. package/src/utils/util.child-selection-point-to-block-offset.ts +3 -3
  168. package/src/utils/util.get-selection-end-point.ts +1 -1
  169. package/src/utils/util.get-selection-start-point.ts +1 -1
  170. package/src/utils/util.merge-text-blocks.ts +2 -2
  171. package/src/utils/util.selection-point-to-block-offset.ts +1 -1
  172. package/src/{selection/selection-point.ts → utils/util.selection-point.ts} +1 -1
  173. package/src/utils/util.slice-blocks.ts +6 -6
  174. package/src/utils/util.slice-text-block.test.ts +3 -1
  175. package/src/utils/util.slice-text-block.ts +3 -3
  176. package/src/utils/util.split-text-block.ts +1 -1
  177. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +0 -1
  178. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
  179. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +0 -1
  180. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
  181. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
  182. package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
  183. package/lib/_chunks-es/util.is-selection-collapsed.js.map +0 -1
  184. package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
  185. /package/src/{internal-utils → editor}/withChanges.ts +0 -0
  186. /package/src/{internal-utils → editor}/withUndoRedo.ts +0 -0
  187. /package/src/{internal-utils → editor}/withoutPatching.ts +0 -0
  188. /package/src/{internal-utils → utils}/asserters.ts +0 -0
  189. /package/src/{editor → utils}/key-generator.ts +0 -0
  190. /package/src/{internal-utils → utils}/parse-blocks.test.ts +0 -0
  191. /package/src/{internal-utils → utils}/parse-blocks.ts +0 -0
@@ -1,10 +1,12 @@
1
1
  import {Editor, Range, Text, Transforms} from 'slate'
2
+ import {KEY_TO_VALUE_ELEMENT} from '../editor/weakMaps'
2
3
  import {slateRangeToSelection} from '../internal-utils/slate-utils'
3
4
  import {toSlateRange} from '../internal-utils/to-slate-range'
4
5
  import {fromSlateValue} from '../internal-utils/values'
5
- import {KEY_TO_VALUE_ELEMENT} from '../internal-utils/weakMaps'
6
- import * as selectors from '../selectors'
7
- import * as utils from '../utils'
6
+ import {getTrimmedSelection} from '../selectors/selector.get-trimmed-selection'
7
+ import {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'
8
+ import {blockOffsetsToSelection} from '../utils/util.block-offsets-to-selection'
9
+ import {selectionPointToBlockOffset} from '../utils/util.selection-point-to-block-offset'
8
10
  import type {BehaviorOperationImplementation} from './behavior.operations'
9
11
 
10
12
  export const decoratorAddOperationImplementation: BehaviorOperationImplementation<
@@ -19,7 +21,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
19
21
  )
20
22
 
21
23
  const manualAnchor = operation.at?.anchor
22
- ? utils.blockOffsetToSpanSelectionPoint({
24
+ ? blockOffsetToSpanSelectionPoint({
23
25
  context: {
24
26
  ...context,
25
27
  value,
@@ -29,7 +31,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
29
31
  })
30
32
  : undefined
31
33
  const manualFocus = operation.at?.focus
32
- ? utils.blockOffsetToSpanSelectionPoint({
34
+ ? blockOffsetToSpanSelectionPoint({
33
35
  context: {
34
36
  ...context,
35
37
  value,
@@ -67,7 +69,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
67
69
  range: selection,
68
70
  })
69
71
  const anchorOffset = editorSelection
70
- ? utils.selectionPointToBlockOffset({
72
+ ? selectionPointToBlockOffset({
71
73
  context: {
72
74
  ...context,
73
75
  value,
@@ -76,7 +78,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
76
78
  })
77
79
  : undefined
78
80
  const focusOffset = editorSelection
79
- ? utils.selectionPointToBlockOffset({
81
+ ? selectionPointToBlockOffset({
80
82
  context: {
81
83
  ...context,
82
84
  value,
@@ -105,7 +107,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
105
107
  )
106
108
  // We need to find the new selection from the original offsets because the
107
109
  // split operation might have changed the value.
108
- const newSelection = utils.blockOffsetsToSelection({
110
+ const newSelection = blockOffsetsToSelection({
109
111
  context: {
110
112
  ...context,
111
113
  value: newValue,
@@ -114,7 +116,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
114
116
  backward: editorSelection?.backward,
115
117
  })
116
118
 
117
- const trimmedSelection = selectors.getTrimmedSelection({
119
+ const trimmedSelection = getTrimmedSelection({
118
120
  blockIndexMap: editor.blockIndexMap,
119
121
  context: {
120
122
  converters: [],
@@ -10,8 +10,8 @@ import {
10
10
  import {DOMEditor} from 'slate-dom'
11
11
  import {createPlaceholderBlock} from '../internal-utils/create-placeholder-block'
12
12
  import {toSlateRange} from '../internal-utils/to-slate-range'
13
- import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
14
13
  import type {PortableTextSlateEditor} from '../types/editor'
14
+ import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
15
15
  import type {BehaviorOperationImplementation} from './behavior.operations'
16
16
 
17
17
  export const deleteOperationImplementation: BehaviorOperationImplementation<
@@ -2,7 +2,6 @@ import {isSpan} from '@portabletext/schema'
2
2
  import {isEqual} from 'lodash'
3
3
  import {Editor, Path, Point, Range, Transforms, type Descendant} from 'slate'
4
4
  import {DOMEditor} from 'slate-dom'
5
- import {parseBlock} from '../internal-utils/parse-blocks'
6
5
  import {
7
6
  getFocusBlock,
8
7
  getFocusChild,
@@ -12,7 +11,8 @@ import {
12
11
  } from '../internal-utils/slate-utils'
13
12
  import {isEqualToEmptyEditor, toSlateValue} from '../internal-utils/values'
14
13
  import type {PortableTextSlateEditor} from '../types/editor'
15
- import {isEmptyTextBlock} from '../utils'
14
+ import {parseBlock} from '../utils/parse-blocks'
15
+ import {isEmptyTextBlock} from '../utils/util.is-empty-text-block'
16
16
  import type {
17
17
  BehaviorOperationImplementation,
18
18
  BehaviorOperationImplementationContext,
@@ -1,9 +1,9 @@
1
1
  import {isTextBlock} from '@portabletext/schema'
2
2
  import {Transforms} from 'slate'
3
3
  import {EDITOR_TO_PENDING_SELECTION} from 'slate-dom'
4
- import {parseInlineObject, parseSpan} from '../internal-utils/parse-blocks'
5
4
  import {getFocusBlock, getFocusSpan} from '../internal-utils/slate-utils'
6
5
  import {VOID_CHILD_KEY} from '../internal-utils/values'
6
+ import {parseInlineObject, parseSpan} from '../utils/parse-blocks'
7
7
  import type {BehaviorOperationImplementation} from './behavior.operations'
8
8
 
9
9
  export const insertChildOperationImplementation: BehaviorOperationImplementation<
@@ -1,5 +1,5 @@
1
1
  import {Transforms} from 'slate'
2
- import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
2
+ import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
3
3
  import type {BehaviorOperationImplementation} from './behavior.operations'
4
4
 
5
5
  export const moveBlockOperationImplementation: BehaviorOperationImplementation<
@@ -1,5 +1,5 @@
1
1
  import {useEffect} from 'react'
2
- import type {Behavior} from '../behaviors'
2
+ import type {Behavior} from '../behaviors/behavior.types.behavior'
3
3
  import {useEditor} from '../editor/use-editor'
4
4
 
5
5
  /**
@@ -14,7 +14,7 @@ import type {Editor} from '../editor'
14
14
  import type {EditorSchema} from '../editor/editor-schema'
15
15
  import {useEditor} from '../editor/use-editor'
16
16
  import type {BlockOffset} from '../types/block-offset'
17
- import * as utils from '../utils'
17
+ import {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'
18
18
 
19
19
  /**
20
20
  * @beta
@@ -88,11 +88,11 @@ const selectionListenerCallback: CallbackLogicFunction<
88
88
  return {blockOffsets: undefined}
89
89
  }
90
90
 
91
- const anchor = utils.spanSelectionPointToBlockOffset({
91
+ const anchor = spanSelectionPointToBlockOffset({
92
92
  context: snapshot.context,
93
93
  selectionPoint: event.at.anchor,
94
94
  })
95
- const focus = utils.spanSelectionPointToBlockOffset({
95
+ const focus = spanSelectionPointToBlockOffset({
96
96
  context: snapshot.context,
97
97
  selectionPoint: event.at.focus,
98
98
  })
@@ -1,5 +1,6 @@
1
1
  import {useEffect} from 'react'
2
- import {defineBehavior, execute} from '../behaviors'
2
+ import {execute} from '../behaviors/behavior.types.action'
3
+ import {defineBehavior} from '../behaviors/behavior.types.behavior'
3
4
  import {useEditor} from '../editor/use-editor'
4
5
 
5
6
  export function AutoCloseBracketsPlugin() {
@@ -1,6 +1,9 @@
1
- import {defineBehavior, execute, raise} from '../behaviors'
2
- import * as selectors from '../selectors'
3
- import * as utils from '../utils'
1
+ import {isTextBlock} from '@portabletext/schema'
2
+ import {execute, raise} from '../behaviors/behavior.types.action'
3
+ import {defineBehavior} from '../behaviors/behavior.types.behavior'
4
+ import {getFocusTextBlock} from '../selectors/selector.get-focus-text-block'
5
+ import {isSelectionExpanded} from '../selectors/selector.is-selection-expanded'
6
+ import {mergeTextBlocks} from '../utils/util.merge-text-blocks'
4
7
  import {BehaviorPlugin} from './plugin.behavior'
5
8
 
6
9
  const oneLineBehaviors = [
@@ -11,7 +14,7 @@ const oneLineBehaviors = [
11
14
  defineBehavior({
12
15
  on: 'insert.break',
13
16
  guard: ({snapshot}) =>
14
- snapshot.context.selection && selectors.isSelectionExpanded(snapshot)
17
+ snapshot.context.selection && isSelectionExpanded(snapshot)
15
18
  ? {selection: snapshot.context.selection}
16
19
  : false,
17
20
  actions: [(_, {selection}) => [execute({type: 'delete', at: selection})]],
@@ -39,12 +42,9 @@ const oneLineBehaviors = [
39
42
  defineBehavior({
40
43
  on: 'insert.block',
41
44
  guard: ({snapshot, event}) => {
42
- const focusTextBlock = selectors.getFocusTextBlock(snapshot)
45
+ const focusTextBlock = getFocusTextBlock(snapshot)
43
46
 
44
- if (
45
- !focusTextBlock ||
46
- !utils.isTextBlock(snapshot.context, event.block)
47
- ) {
47
+ if (!focusTextBlock || !isTextBlock(snapshot.context, event.block)) {
48
48
  return false
49
49
  }
50
50
 
@@ -77,7 +77,7 @@ const oneLineBehaviors = [
77
77
  on: 'insert.blocks',
78
78
  guard: ({snapshot, event}) => {
79
79
  const textBlocks = event.blocks.filter((block) =>
80
- utils.isTextBlock(snapshot.context, block),
80
+ isTextBlock(snapshot.context, block),
81
81
  )
82
82
 
83
83
  if (textBlocks.length === 0) {
@@ -85,7 +85,7 @@ const oneLineBehaviors = [
85
85
  }
86
86
 
87
87
  return textBlocks.reduce((targetBlock, incomingBlock) => {
88
- return utils.mergeTextBlocks({
88
+ return mergeTextBlocks({
89
89
  context: snapshot.context,
90
90
  targetBlock,
91
91
  incomingBlock,
@@ -1,4 +1,4 @@
1
- import {defaultKeyGenerator} from '../editor/key-generator'
1
+ import {defaultKeyGenerator} from '../utils/key-generator'
2
2
 
3
3
  export type EditorPriority = {
4
4
  id: string
@@ -1,8 +1,8 @@
1
1
  import {compileSchema, defineSchema} from '@portabletext/schema'
2
2
  import {createTestKeyGenerator} from '@portabletext/test'
3
3
  import {describe, expect, test} from 'vitest'
4
+ import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
4
5
  import type {EditorSelection} from '../types/editor'
5
- import {createTestSnapshot} from './create-test-snapshot'
6
6
  import {getDragSelection} from './drag-selection'
7
7
 
8
8
  describe(getDragSelection.name, () => {
@@ -1,7 +1,16 @@
1
- import type {EditorSnapshot} from '..'
2
- import * as selectors from '../selectors'
3
- import * as utils from '../utils'
4
- import type {EventPosition} from './event-position'
1
+ import type {EditorSnapshot} from '../editor/editor-snapshot'
2
+ import type {EventPosition} from '../internal-utils/event-position'
3
+ import {getBlockEndPoint} from '../utils/util.get-block-end-point'
4
+ import {getBlockStartPoint} from '../utils/util.get-block-start-point'
5
+ import {getFocusInlineObject} from './selector.get-focus-inline-object'
6
+ import {getFocusSpan} from './selector.get-focus-span'
7
+ import {getFocusTextBlock} from './selector.get-focus-text-block'
8
+ import {getSelectedBlocks} from './selector.get-selected-blocks'
9
+ import {getSelectionEndBlock} from './selector.get-selection-end-block'
10
+ import {getSelectionStartBlock} from './selector.get-selection-start-block'
11
+ import {isOverlappingSelection} from './selector.is-overlapping-selection'
12
+ import {isSelectionCollapsed} from './selector.is-selection-collapsed'
13
+ import {isSelectionExpanded} from './selector.is-selection-expanded'
5
14
 
6
15
  /**
7
16
  * Given the current editor `snapshot` and an `eventSelection` representing
@@ -17,7 +26,7 @@ export function getDragSelection({
17
26
  }) {
18
27
  let dragSelection = eventSelection
19
28
 
20
- const draggedInlineObject = selectors.getFocusInlineObject({
29
+ const draggedInlineObject = getFocusInlineObject({
21
30
  ...snapshot,
22
31
  context: {
23
32
  ...snapshot.context,
@@ -29,21 +38,21 @@ export function getDragSelection({
29
38
  return dragSelection
30
39
  }
31
40
 
32
- const draggingCollapsedSelection = selectors.isSelectionCollapsed({
41
+ const draggingCollapsedSelection = isSelectionCollapsed({
33
42
  ...snapshot,
34
43
  context: {
35
44
  ...snapshot.context,
36
45
  selection: eventSelection,
37
46
  },
38
47
  })
39
- const draggedTextBlock = selectors.getFocusTextBlock({
48
+ const draggedTextBlock = getFocusTextBlock({
40
49
  ...snapshot,
41
50
  context: {
42
51
  ...snapshot.context,
43
52
  selection: eventSelection,
44
53
  },
45
54
  })
46
- const draggedSpan = selectors.getFocusSpan({
55
+ const draggedSpan = getFocusSpan({
47
56
  ...snapshot,
48
57
  context: {
49
58
  ...snapshot.context,
@@ -55,43 +64,41 @@ export function getDragSelection({
55
64
  // Looks like we are dragging an empty span
56
65
  // Let's drag the entire block instead
57
66
  dragSelection = {
58
- anchor: utils.getBlockStartPoint({
67
+ anchor: getBlockStartPoint({
59
68
  context: snapshot.context,
60
69
  block: draggedTextBlock,
61
70
  }),
62
- focus: utils.getBlockEndPoint({
71
+ focus: getBlockEndPoint({
63
72
  context: snapshot.context,
64
73
  block: draggedTextBlock,
65
74
  }),
66
75
  }
67
76
  }
68
77
 
69
- const selectedBlocks = selectors.getSelectedBlocks(snapshot)
78
+ const selectedBlocks = getSelectedBlocks(snapshot)
70
79
 
71
80
  if (
72
81
  snapshot.context.selection &&
73
- selectors.isSelectionExpanded(snapshot) &&
82
+ isSelectionExpanded(snapshot) &&
74
83
  selectedBlocks.length > 1
75
84
  ) {
76
- const selectionStartBlock = selectors.getSelectionStartBlock(snapshot)
77
- const selectionEndBlock = selectors.getSelectionEndBlock(snapshot)
85
+ const selectionStartBlock = getSelectionStartBlock(snapshot)
86
+ const selectionEndBlock = getSelectionEndBlock(snapshot)
78
87
 
79
88
  if (!selectionStartBlock || !selectionEndBlock) {
80
89
  return dragSelection
81
90
  }
82
91
 
83
- const selectionStartPoint = utils.getBlockStartPoint({
92
+ const selectionStartPoint = getBlockStartPoint({
84
93
  context: snapshot.context,
85
94
  block: selectionStartBlock,
86
95
  })
87
- const selectionEndPoint = utils.getBlockEndPoint({
96
+ const selectionEndPoint = getBlockEndPoint({
88
97
  context: snapshot.context,
89
98
  block: selectionEndBlock,
90
99
  })
91
100
 
92
- const eventSelectionInsideBlocks = selectors.isOverlappingSelection(
93
- eventSelection,
94
- )({
101
+ const eventSelectionInsideBlocks = isOverlappingSelection(eventSelection)({
95
102
  ...snapshot,
96
103
  context: {
97
104
  ...snapshot.context,
@@ -17,7 +17,7 @@ export {getFocusSpan} from './selector.get-focus-span'
17
17
  export {getFocusTextBlock} from './selector.get-focus-text-block'
18
18
  export {getLastBlock} from './selector.get-last-block'
19
19
  export {getListIndex} from './selector.get-list-state'
20
- export {getMarkState} from './selector.get-mark-state'
20
+ export {getMarkState, type MarkState} from './selector.get-mark-state'
21
21
  export {getNextBlock} from './selector.get-next-block'
22
22
  export {getNextInlineObject} from './selector.get-next-inline-object'
23
23
  export {getPreviousBlock} from './selector.get-previous-block'
@@ -1,7 +1,7 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
- import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
4
3
  import type {BlockPath} from '../types/paths'
4
+ import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
5
5
 
6
6
  /**
7
7
  * @public
@@ -1,7 +1,7 @@
1
1
  import type {PortableTextObject, PortableTextSpan} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
- import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
4
3
  import type {ChildPath} from '../types/paths'
4
+ import {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'
5
5
  import {getAnchorTextBlock} from './selector.get-anchor-text-block'
6
6
 
7
7
  /**
@@ -1,6 +1,6 @@
1
1
  import type {EditorSelector} from '../editor/editor-selector'
2
2
  import type {BlockOffset} from '../types/block-offset'
3
- import * as utils from '../utils'
3
+ import {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'
4
4
  import {getSelectionEndPoint} from './selector.get-selection-end-point'
5
5
  import {getSelectionStartPoint} from './selector.get-selection-start-point'
6
6
 
@@ -21,11 +21,11 @@ export const getBlockOffsets: EditorSelector<
21
21
  return undefined
22
22
  }
23
23
 
24
- const start = utils.spanSelectionPointToBlockOffset({
24
+ const start = spanSelectionPointToBlockOffset({
25
25
  context: snapshot.context,
26
26
  selectionPoint: selectionStartPoint,
27
27
  })
28
- const end = utils.spanSelectionPointToBlockOffset({
28
+ const end = spanSelectionPointToBlockOffset({
29
29
  context: snapshot.context,
30
30
  selectionPoint: selectionEndPoint,
31
31
  })
@@ -1,8 +1,8 @@
1
1
  import {createTestKeyGenerator} from '@portabletext/test'
2
2
  import type {PortableTextBlock} from '@sanity/types'
3
3
  import {describe, expect, test} from 'vitest'
4
- import type {EditorSelection} from '..'
5
4
  import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
5
+ import type {EditorSelection} from '../types/editor'
6
6
  import {getCaretWordSelection} from './selector.get-caret-word-selection'
7
7
 
8
8
  const keyGenerator = createTestKeyGenerator()
@@ -1,7 +1,7 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
- import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
4
3
  import type {BlockPath} from '../types/paths'
4
+ import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
5
5
 
6
6
  /**
7
7
  * @public
@@ -1,7 +1,7 @@
1
1
  import type {PortableTextObject, PortableTextSpan} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
- import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
4
3
  import type {ChildPath} from '../types/paths'
4
+ import {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'
5
5
  import {getFocusTextBlock} from './selector.get-focus-text-block'
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  import type {PortableTextListBlock} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
- import {isListBlock} from '../internal-utils/parse-blocks'
4
3
  import type {BlockPath} from '../types/paths'
4
+ import {isListBlock} from '../utils/parse-blocks'
5
5
  import {getFocusTextBlock} from './selector.get-focus-text-block'
6
6
 
7
7
  /**
@@ -1,8 +1,8 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
2
  import {describe, expect, test} from 'vitest'
3
3
  import type {EditorSelector} from '../editor/editor-selector'
4
- import {defaultKeyGenerator} from '../editor/key-generator'
5
4
  import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
5
+ import {defaultKeyGenerator} from '../utils/key-generator'
6
6
  import {getListIndex} from './selector.get-list-state'
7
7
 
8
8
  function blockObject(_key: string, name: string) {
@@ -1,6 +1,6 @@
1
1
  import type {EditorSelector} from '../editor/editor-selector'
2
2
  import {isBlockPath} from '../types/paths'
3
- import {blockOffsetToSpanSelectionPoint} from '../utils'
3
+ import {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'
4
4
  import {isSelectionExpanded} from '../utils/util.is-selection-expanded'
5
5
  import {getFocusSpan} from './selector.get-focus-span'
6
6
  import {getFocusTextBlock} from './selector.get-focus-text-block'
@@ -8,6 +8,9 @@ import {getNextSpan} from './selector.get-next-span'
8
8
  import {getPreviousSpan} from './selector.get-previous-span'
9
9
  import {getSelectedSpans} from './selector.get-selected-spans'
10
10
 
11
+ /**
12
+ * @beta
13
+ */
11
14
  export type MarkState =
12
15
  | {
13
16
  state: 'unchanged'
@@ -1,7 +1,7 @@
1
+ import {isSpan} from '@portabletext/schema'
1
2
  import {isKeySegment, type PortableTextObject} from '@sanity/types'
2
3
  import type {EditorSelector} from '../editor/editor-selector'
3
4
  import type {ChildPath} from '../types/paths'
4
- import {isSpan} from '../utils'
5
5
  import {getFocusTextBlock} from './selector.get-focus-text-block'
6
6
  import {getSelectionEndPoint} from './selector.get-selection-end-point'
7
7
 
@@ -1,7 +1,7 @@
1
1
  import {isSpan, isTextBlock} from '@portabletext/schema'
2
2
  import type {KeyedSegment, PortableTextSpan} from '@sanity/types'
3
3
  import type {EditorSelector} from '../editor/editor-selector'
4
- import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
4
+ import {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'
5
5
  import {getSelectionEndBlock} from './selector.get-selection-end-block'
6
6
  import {getSelectionEndPoint} from './selector.get-selection-end-point'
7
7
 
@@ -1,7 +1,7 @@
1
+ import {isSpan} from '@portabletext/schema'
1
2
  import {isKeySegment, type PortableTextObject} from '@sanity/types'
2
3
  import type {EditorSelector} from '../editor/editor-selector'
3
4
  import type {ChildPath} from '../types/paths'
4
- import {isSpan} from '../utils'
5
5
  import {getFocusTextBlock} from './selector.get-focus-text-block'
6
6
  import {getSelectionStartPoint} from './selector.get-selection-start-point'
7
7
 
@@ -1,7 +1,7 @@
1
1
  import {isSpan, isTextBlock} from '@portabletext/schema'
2
2
  import type {KeyedSegment, PortableTextSpan} from '@sanity/types'
3
3
  import type {EditorSelector} from '../editor/editor-selector'
4
- import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
4
+ import {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'
5
5
  import {getSelectionStartBlock} from './selector.get-selection-start-block'
6
6
  import {getSelectionStartPoint} from './selector.get-selection-start-point'
7
7
 
@@ -1,9 +1,9 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
- import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
4
3
  import type {BlockPath} from '../types/paths'
5
4
  import {getSelectionEndPoint} from '../utils/util.get-selection-end-point'
6
5
  import {getSelectionStartPoint} from '../utils/util.get-selection-start-point'
6
+ import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
7
7
 
8
8
  /**
9
9
  * @public
@@ -1,7 +1,7 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
2
  import {describe, expect, test} from 'vitest'
3
- import type {EditorSelection} from '..'
4
3
  import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
4
+ import type {EditorSelection} from '../types/editor'
5
5
  import {getSelectedSpans} from './selector.get-selected-spans'
6
6
 
7
7
  const fooBar = {
@@ -1,11 +1,11 @@
1
1
  import {isSpan, isTextBlock} from '@portabletext/schema'
2
2
  import type {PortableTextSpan} from '@sanity/types'
3
3
  import type {EditorSelector} from '../editor/editor-selector'
4
+ import type {ChildPath} from '../types/paths'
4
5
  import {
5
6
  getBlockKeyFromSelectionPoint,
6
7
  getChildKeyFromSelectionPoint,
7
- } from '../selection/selection-point'
8
- import type {ChildPath} from '../types/paths'
8
+ } from '../utils/util.selection-point'
9
9
  import {getSelectionEndPoint} from './selector.get-selection-end-point'
10
10
  import {getSelectionStartPoint} from './selector.get-selection-start-point'
11
11
 
@@ -1,9 +1,10 @@
1
1
  import {isTextBlock} from '@portabletext/schema'
2
2
  import type {PortableTextTextBlock} from '@sanity/types'
3
3
  import type {EditorSelector} from '../editor/editor-selector'
4
- import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
5
4
  import type {BlockPath} from '../types/paths'
6
- import {getSelectionEndPoint, getSelectionStartPoint} from '../utils'
5
+ import {getSelectionEndPoint} from '../utils/util.get-selection-end-point'
6
+ import {getSelectionStartPoint} from '../utils/util.get-selection-start-point'
7
+ import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
7
8
 
8
9
  /**
9
10
  * @public