@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
@@ -6,8 +6,8 @@ import type {
6
6
  } from '@sanity/types'
7
7
  import {Editor, Transforms, type Element} from 'slate'
8
8
  import {debugWithName} from '../../internal-utils/debug'
9
- import {isListBlock} from '../../internal-utils/parse-blocks'
10
9
  import type {PortableTextSlateEditor} from '../../types/editor'
10
+ import {isListBlock} from '../../utils/parse-blocks'
11
11
  import type {EditorActor} from '../editor-machine'
12
12
 
13
13
  const debug = debugWithName('plugin:withSchemaTypes')
@@ -22,7 +22,11 @@ import {
22
22
  } from 'slate'
23
23
  import {debugWithName} from '../../internal-utils/debug'
24
24
  import {fromSlateValue} from '../../internal-utils/values'
25
- import {isChangingRemotely} from '../../internal-utils/withChanges'
25
+ import type {BehaviorOperationImplementation} from '../../operations/behavior.operations'
26
+ import type {PortableTextSlateEditor} from '../../types/editor'
27
+ import type {EditorActor} from '../editor-machine'
28
+ import {getCurrentUndoStepId} from '../with-undo-step'
29
+ import {isChangingRemotely} from '../withChanges'
26
30
  import {
27
31
  isRedoing,
28
32
  isUndoing,
@@ -30,11 +34,7 @@ import {
30
34
  setIsUndoing,
31
35
  withRedoing,
32
36
  withUndoing,
33
- } from '../../internal-utils/withUndoRedo'
34
- import type {BehaviorOperationImplementation} from '../../operations/behavior.operations'
35
- import type {PortableTextSlateEditor} from '../../types/editor'
36
- import type {EditorActor} from '../editor-machine'
37
- import {getCurrentUndoStepId} from '../with-undo-step'
37
+ } from '../withUndoRedo'
38
38
 
39
39
  const debug = debugWithName('plugin:withUndoRedo')
40
40
  const debugVerbose = debug.enabled && false
@@ -1,7 +1,7 @@
1
1
  import {slateRangeToSelection} from '../../internal-utils/slate-utils'
2
- import {SLATE_TO_PORTABLE_TEXT_RANGE} from '../../internal-utils/weakMaps'
3
2
  import type {PortableTextSlateEditor} from '../../types/editor'
4
3
  import type {EditorActor} from '../editor-machine'
4
+ import {SLATE_TO_PORTABLE_TEXT_RANGE} from '../weakMaps'
5
5
 
6
6
  export function pluginUpdateSelection({
7
7
  editor,
@@ -25,11 +25,6 @@ import type {ActorRefFrom} from 'xstate'
25
25
  import {debugWithName} from '../internal-utils/debug'
26
26
  import {validateValue} from '../internal-utils/validateValue'
27
27
  import {toSlateValue, VOID_CHILD_KEY} from '../internal-utils/values'
28
- import {
29
- isChangingRemotely,
30
- withRemoteChanges,
31
- } from '../internal-utils/withChanges'
32
- import {withoutPatching} from '../internal-utils/withoutPatching'
33
28
  import type {PickFromUnion} from '../type-utils'
34
29
  import type {
35
30
  InvalidValueResolution,
@@ -37,6 +32,8 @@ import type {
37
32
  } from '../types/editor'
38
33
  import type {EditorSchema} from './editor-schema'
39
34
  import {withoutSaving} from './plugins/createWithUndoRedo'
35
+ import {isChangingRemotely, withRemoteChanges} from './withChanges'
36
+ import {withoutPatching} from './withoutPatching'
40
37
 
41
38
  const debug = debugWithName('sync machine')
42
39
 
@@ -1,5 +1,5 @@
1
1
  import type {Editor, Range} from 'slate'
2
- import type {EditorSelection} from '..'
2
+ import type {EditorSelection} from '../types/editor'
3
3
 
4
4
  // Is the editor currently receiving remote changes that are being applied to the content?
5
5
  export const IS_PROCESSING_REMOTE_CHANGES: WeakMap<Editor, boolean> =
@@ -1,5 +1,5 @@
1
1
  import type {Editor} from 'slate'
2
- import {defaultKeyGenerator} from './key-generator'
2
+ import {defaultKeyGenerator} from '../utils/key-generator'
3
3
 
4
4
  const CURRENT_UNDO_STEP: WeakMap<Editor, {undoStepId: string} | undefined> =
5
5
  new WeakMap()
package/src/index.ts CHANGED
@@ -40,7 +40,7 @@ export {useEditorSelector, type EditorSelector} from './editor/editor-selector'
40
40
  export type {EditorContext, EditorSnapshot} from './editor/editor-snapshot'
41
41
  export {usePortableTextEditor} from './editor/hooks/usePortableTextEditor'
42
42
  export {usePortableTextEditorSelection} from './editor/hooks/usePortableTextEditorSelection'
43
- export {defaultKeyGenerator as keyGenerator} from './editor/key-generator'
43
+ export {defaultKeyGenerator as keyGenerator} from './utils/key-generator'
44
44
  export {PortableTextEditor} from './editor/PortableTextEditor'
45
45
  export type {PortableTextEditorProps} from './editor/PortableTextEditor'
46
46
  export type {EditorEmittedEvent, MutationEvent} from './editor/relay-machine'
@@ -18,10 +18,10 @@ import {
18
18
  import type {Path, PortableTextBlock, PortableTextChild} from '@sanity/types'
19
19
  import {Element, Node, Text, Transforms, type Descendant} from 'slate'
20
20
  import type {EditorSchema} from '../editor/editor-schema'
21
+ import {KEY_TO_SLATE_ELEMENT} from '../editor/weakMaps'
21
22
  import type {PortableTextSlateEditor} from '../types/editor'
22
- import {isKeyedSegment} from '../utils'
23
+ import {isKeyedSegment} from '../utils/util.is-keyed-segment'
23
24
  import {isEqualToEmptyEditor, toSlateValue} from './values'
24
- import {KEY_TO_SLATE_ELEMENT} from './weakMaps'
25
25
 
26
26
  /**
27
27
  * Creates a function that can apply a patch onto a PortableTextSlateEditor.
@@ -1,7 +1,7 @@
1
1
  import {compileSchema, defineSchema} from '@portabletext/schema'
2
2
  import type {PortableTextBlock} from '@sanity/types'
3
3
  import {describe, expect, test} from 'vitest'
4
- import {defaultKeyGenerator} from '../editor/key-generator'
4
+ import {defaultKeyGenerator} from '../utils/key-generator'
5
5
  import {buildIndexMaps} from './build-index-maps'
6
6
 
7
7
  function blockObject(_key: string, name: string) {
@@ -1,6 +1,6 @@
1
1
  import {compileSchema, defineSchema} from '@portabletext/schema'
2
2
  import {createTestKeyGenerator} from '@portabletext/test'
3
- import type {EditorSnapshot} from '..'
3
+ import type {EditorSnapshot} from '../editor/editor-snapshot'
4
4
 
5
5
  export function createTestSnapshot(snapshot: {
6
6
  context?: Partial<EditorSnapshot['context']>
@@ -1,10 +1,12 @@
1
1
  import {Editor, type BaseRange, type Node} from 'slate'
2
2
  import {DOMEditor, isDOMNode} from 'slate-dom'
3
- import type {EditorSchema, EditorSelection} from '..'
4
3
  import type {EditorActor} from '../editor/editor-machine'
5
- import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
6
- import type {PortableTextSlateEditor} from '../types/editor'
7
- import * as utils from '../utils'
4
+ import type {EditorSchema} from '../editor/editor-schema'
5
+ import type {EditorSelection, PortableTextSlateEditor} from '../types/editor'
6
+ import {getBlockEndPoint} from '../utils/util.get-block-end-point'
7
+ import {getBlockStartPoint} from '../utils/util.get-block-start-point'
8
+ import {isSelectionCollapsed} from '../utils/util.is-selection-collapsed'
9
+ import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
8
10
  import {
9
11
  getFirstBlock,
10
12
  getLastBlock,
@@ -69,14 +71,14 @@ export function getEventPosition({
69
71
  block: eventPositionBlock,
70
72
  isEditor: false,
71
73
  selection: {
72
- anchor: utils.getBlockStartPoint({
74
+ anchor: getBlockStartPoint({
73
75
  context: editorActor.getSnapshot().context,
74
76
  block: {
75
77
  node: eventBlock,
76
78
  path: [{_key: eventBlock._key}],
77
79
  },
78
80
  }),
79
- focus: utils.getBlockEndPoint({
81
+ focus: getBlockEndPoint({
80
82
  context: editorActor.getSnapshot().context,
81
83
  block: {
82
84
  node: eventBlock,
@@ -100,7 +102,7 @@ export function getEventPosition({
100
102
  }
101
103
 
102
104
  if (
103
- utils.isSelectionCollapsed(eventSelection) &&
105
+ isSelectionCollapsed(eventSelection) &&
104
106
  eventBlock &&
105
107
  eventSelectionFocusBlockKey !== eventBlock._key
106
108
  ) {
@@ -110,14 +112,14 @@ export function getEventPosition({
110
112
  block: eventPositionBlock,
111
113
  isEditor: false,
112
114
  selection: {
113
- anchor: utils.getBlockStartPoint({
115
+ anchor: getBlockStartPoint({
114
116
  context: editorActor.getSnapshot().context,
115
117
  block: {
116
118
  node: eventBlock,
117
119
  path: [{_key: eventBlock._key}],
118
120
  },
119
121
  }),
120
- focus: utils.getBlockEndPoint({
122
+ focus: getBlockEndPoint({
121
123
  context: editorActor.getSnapshot().context,
122
124
  block: {
123
125
  node: eventBlock,
@@ -5,9 +5,9 @@ import {createEditor, type Descendant} from 'slate'
5
5
  import {beforeEach, describe, expect, it} from 'vitest'
6
6
  import {createActor} from 'xstate'
7
7
  import {editorMachine} from '../editor/editor-machine'
8
- import {defaultKeyGenerator} from '../editor/key-generator'
9
8
  import {withPlugins} from '../editor/plugins/with-plugins'
10
9
  import {relayMachine} from '../editor/relay-machine'
10
+ import {defaultKeyGenerator} from '../utils/key-generator'
11
11
  import {
12
12
  insertNodePatch,
13
13
  insertTextPatch,
@@ -1,5 +1,5 @@
1
1
  import type {EditorSchema} from '../editor/editor-schema'
2
- import {isTypedObject} from './asserters'
2
+ import {isTypedObject} from '../utils/asserters'
3
3
 
4
4
  type Path = Array<number>
5
5
 
@@ -1,5 +1,5 @@
1
- import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
2
1
  import type {EditorSelection} from '../types/editor'
2
+ import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
3
3
 
4
4
  export function getSelectionBlockKeys(selection: EditorSelection) {
5
5
  if (!selection) {
@@ -3,7 +3,7 @@ import type {EditorContext} from '../editor/editor-snapshot'
3
3
  import {
4
4
  getBlockKeyFromSelectionPoint,
5
5
  getChildKeyFromSelectionPoint,
6
- } from '../selection/selection-point'
6
+ } from '../utils/util.selection-point'
7
7
 
8
8
  export function getSelectionFocusText(
9
9
  context: Pick<EditorContext, 'schema' | 'value' | 'selection'>,
@@ -2,13 +2,13 @@ import {isSpan, isTextBlock} from '@portabletext/schema'
2
2
  import type {PortableTextObject, PortableTextSpan} from '@sanity/types'
3
3
  import type {Path, Range} from 'slate'
4
4
  import type {EditorContext, EditorSnapshot} from '../editor/editor-snapshot'
5
+ import type {EditorSelectionPoint} from '../types/editor'
6
+ import {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'
7
+ import {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'
5
8
  import {
6
9
  getBlockKeyFromSelectionPoint,
7
10
  getChildKeyFromSelectionPoint,
8
- } from '../selection/selection-point'
9
- import type {EditorSelectionPoint} from '../types/editor'
10
- import {isEqualSelectionPoints} from '../utils'
11
- import {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'
11
+ } from '../utils/util.selection-point'
12
12
 
13
13
  export function toSlateRange(
14
14
  snapshot: {
@@ -1,5 +1,5 @@
1
1
  import {Editor, Node, Range, Text, Transforms} from 'slate'
2
- import {parseAnnotation} from '../internal-utils/parse-blocks'
2
+ import {parseAnnotation} from '../utils/parse-blocks'
3
3
  import type {BehaviorOperationImplementation} from './behavior.operations'
4
4
 
5
5
  export const addAnnotationOperationImplementation: BehaviorOperationImplementation<
@@ -1,6 +1,6 @@
1
1
  import {Transforms, type Element as SlateElement} from 'slate'
2
- import {parseBlock} from '../internal-utils/parse-blocks'
3
2
  import {toSlateValue} from '../internal-utils/values'
3
+ import {parseBlock} from '../utils/parse-blocks'
4
4
  import type {BehaviorOperationImplementation} from './behavior.operations'
5
5
 
6
6
  export const blockSetOperationImplementation: BehaviorOperationImplementation<
@@ -1,10 +1,10 @@
1
1
  import {isTextBlock} from '@portabletext/schema'
2
2
  import {omit} from 'lodash'
3
3
  import {Editor, Transforms} from 'slate'
4
- import {parseBlock} from '../internal-utils/parse-blocks'
4
+ import {KEY_TO_VALUE_ELEMENT} from '../editor/weakMaps'
5
5
  import {toSlateRange} from '../internal-utils/to-slate-range'
6
6
  import {fromSlateValue} from '../internal-utils/values'
7
- import {KEY_TO_VALUE_ELEMENT} from '../internal-utils/weakMaps'
7
+ import {parseBlock} from '../utils/parse-blocks'
8
8
  import type {BehaviorOperationImplementation} from './behavior.operations'
9
9
 
10
10
  export const blockUnsetOperationImplementation: BehaviorOperationImplementation<
@@ -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,
@@ -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
  /**