@portabletext/editor 1.53.0 → 1.54.0

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 (94) hide show
  1. package/lib/_chunks-cjs/selection-point.cjs.map +1 -1
  2. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +144 -6
  4. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +6 -140
  6. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
  8. package/lib/_chunks-es/selection-point.js.map +1 -1
  9. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  10. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +148 -10
  11. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  12. package/lib/_chunks-es/selector.is-selection-expanded.js +6 -140
  13. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
  14. package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -1
  15. package/lib/behaviors/index.cjs.map +1 -1
  16. package/lib/behaviors/index.d.cts +68 -9
  17. package/lib/behaviors/index.d.ts +68 -9
  18. package/lib/behaviors/index.js.map +1 -1
  19. package/lib/index.cjs +553 -313
  20. package/lib/index.cjs.map +1 -1
  21. package/lib/index.d.cts +69 -13
  22. package/lib/index.d.ts +69 -13
  23. package/lib/index.js +534 -294
  24. package/lib/index.js.map +1 -1
  25. package/lib/plugins/index.d.cts +69 -9
  26. package/lib/plugins/index.d.ts +69 -9
  27. package/lib/selectors/index.cjs +10 -10
  28. package/lib/selectors/index.cjs.map +1 -1
  29. package/lib/selectors/index.d.cts +42 -27
  30. package/lib/selectors/index.d.ts +42 -27
  31. package/lib/selectors/index.js +4 -4
  32. package/lib/selectors/index.js.map +1 -1
  33. package/lib/utils/index.d.cts +27 -5
  34. package/lib/utils/index.d.ts +27 -5
  35. package/package.json +14 -14
  36. package/src/behaviors/behavior.abstract.annotation.ts +51 -0
  37. package/src/behaviors/behavior.abstract.delete.ts +55 -0
  38. package/src/behaviors/behavior.perform-event.ts +6 -15
  39. package/src/behaviors/behavior.types.action.ts +1 -1
  40. package/src/behaviors/behavior.types.event.ts +32 -8
  41. package/src/behaviors/behavior.types.guard.ts +1 -1
  42. package/src/editor/Editable.tsx +3 -0
  43. package/src/editor/PortableTextEditor.tsx +1 -6
  44. package/src/editor/create-editor.ts +5 -0
  45. package/src/{internal-utils/selection-elements.ts → editor/editor-dom.ts} +29 -21
  46. package/src/editor/editor-provider.tsx +1 -6
  47. package/src/editor/hooks/usePortableTextEditorSelection.tsx +6 -46
  48. package/src/editor/plugins/createWithPatches.ts +1 -5
  49. package/src/editor.ts +2 -0
  50. package/src/index.ts +2 -0
  51. package/src/operations/behavior.operation.child.set.ts +103 -0
  52. package/src/operations/behavior.operation.child.unset.ts +89 -0
  53. package/src/operations/behavior.operations.ts +18 -0
  54. package/src/selectors/index.ts +13 -1
  55. package/src/selectors/selector.get-active-annotations.ts +2 -1
  56. package/src/selectors/selector.get-active-list-item.ts +1 -1
  57. package/src/selectors/selector.get-active-style.ts +1 -1
  58. package/src/selectors/selector.get-anchor-block.ts +3 -2
  59. package/src/selectors/selector.get-anchor-child.ts +2 -2
  60. package/src/selectors/selector.get-anchor-span.ts +2 -3
  61. package/src/selectors/selector.get-anchor-text-block.ts +3 -2
  62. package/src/selectors/selector.get-caret-word-selection.ts +1 -1
  63. package/src/selectors/selector.get-first-block.ts +14 -0
  64. package/src/selectors/selector.get-focus-block-object.ts +18 -0
  65. package/src/selectors/selector.get-focus-block.ts +23 -0
  66. package/src/selectors/selector.get-focus-child.ts +36 -0
  67. package/src/selectors/selector.get-focus-inline-object.ts +4 -8
  68. package/src/selectors/selector.get-focus-list-block.ts +18 -0
  69. package/src/selectors/selector.get-focus-span.ts +18 -0
  70. package/src/selectors/selector.get-focus-text-block.ts +18 -0
  71. package/src/selectors/selector.get-last-block.ts +16 -0
  72. package/src/selectors/selector.get-list-state.ts +2 -1
  73. package/src/selectors/selector.get-next-block.ts +38 -0
  74. package/src/selectors/selector.get-next-inline-object.ts +5 -8
  75. package/src/selectors/selector.get-previous-block.ts +35 -0
  76. package/src/selectors/selector.get-previous-inline-object.ts +5 -8
  77. package/src/selectors/selector.get-selected-blocks.ts +49 -0
  78. package/src/selectors/selector.get-selected-spans.test.ts +96 -0
  79. package/src/selectors/selector.get-selected-spans.ts +4 -3
  80. package/src/selectors/selector.get-selected-text-blocks.ts +4 -3
  81. package/src/selectors/selector.get-selection-end-block.ts +4 -1
  82. package/src/selectors/selector.get-selection-start-block.ts +4 -1
  83. package/src/selectors/selector.get-text-before.ts +1 -1
  84. package/src/selectors/selector.get-trimmed-selection.ts +1 -1
  85. package/src/selectors/selector.is-active-annotation.ts +1 -1
  86. package/src/selectors/selector.is-at-the-end-of-block.ts +3 -2
  87. package/src/selectors/selector.is-at-the-start-of-block.ts +3 -2
  88. package/src/selectors/selector.is-selecting-entire-blocks.ts +2 -1
  89. package/src/types/block-offset.ts +2 -2
  90. package/src/types/paths.ts +13 -0
  91. package/src/utils/util.block-offset.ts +2 -4
  92. package/src/utils/util.get-block-end-point.ts +3 -2
  93. package/src/utils/util.get-block-start-point.ts +3 -2
  94. package/src/selectors/selectors.ts +0 -299
@@ -19,7 +19,7 @@ declare type BaseDefinition = {
19
19
  * @beta
20
20
  */
21
21
  declare type BlockOffset = {
22
- path: [KeyedSegment]
22
+ path: BlockPath
23
23
  offset: number
24
24
  }
25
25
 
@@ -76,11 +76,33 @@ export declare function blockOffsetToSpanSelectionPoint({
76
76
  direction: 'forward' | 'backward'
77
77
  }):
78
78
  | {
79
- path: [KeyedSegment, 'children', KeyedSegment]
79
+ path: ChildPath
80
80
  offset: number
81
81
  }
82
82
  | undefined
83
83
 
84
+ /**
85
+ * @public
86
+ */
87
+ declare type BlockPath = [
88
+ {
89
+ _key: string
90
+ },
91
+ ]
92
+
93
+ /**
94
+ * @public
95
+ */
96
+ declare type ChildPath = [
97
+ {
98
+ _key: string
99
+ },
100
+ 'children',
101
+ {
102
+ _key: string
103
+ },
104
+ ]
105
+
84
106
  /**
85
107
  * @public
86
108
  */
@@ -255,7 +277,7 @@ export declare function getBlockEndPoint({
255
277
  context: Pick<EditorContext, 'schema'>
256
278
  block: {
257
279
  node: PortableTextBlock
258
- path: [KeyedSegment]
280
+ path: BlockPath
259
281
  }
260
282
  }): EditorSelectionPoint
261
283
 
@@ -269,7 +291,7 @@ export declare function getBlockStartPoint({
269
291
  context: Pick<EditorContext, 'schema'>
270
292
  block: {
271
293
  node: PortableTextBlock
272
- path: [KeyedSegment]
294
+ path: BlockPath
273
295
  }
274
296
  }): EditorSelectionPoint
275
297
 
@@ -365,7 +387,7 @@ export declare function mergeTextBlocks({
365
387
  context: Pick<EditorContext, 'keyGenerator' | 'schema'>
366
388
  targetBlock: PortableTextTextBlock
367
389
  incomingBlock: PortableTextTextBlock
368
- }): PortableTextTextBlock<PortableTextObject | PortableTextSpan>
390
+ }): PortableTextTextBlock<PortableTextSpan | PortableTextObject>
369
391
 
370
392
  declare type MIMEType = `${string}/${string}`
371
393
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.53.0",
3
+ "version": "1.54.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -74,35 +74,35 @@
74
74
  "immer": "^10.1.1",
75
75
  "lodash": "^4.17.21",
76
76
  "lodash.startcase": "^4.4.0",
77
- "react-compiler-runtime": "19.1.0-rc.1",
77
+ "react-compiler-runtime": "19.1.0-rc.2",
78
78
  "slate": "0.115.1",
79
79
  "slate-dom": "^0.114.0",
80
80
  "slate-react": "0.114.2",
81
81
  "use-effect-event": "^1.0.2",
82
82
  "xstate": "^5.19.4",
83
- "@portabletext/block-tools": "1.1.30",
83
+ "@portabletext/block-tools": "1.1.31",
84
84
  "@portabletext/patches": "1.1.4"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@portabletext/toolkit": "^2.0.17",
88
88
  "@sanity/diff-match-patch": "^3.2.0",
89
- "@sanity/pkg-utils": "^7.2.4",
90
- "@sanity/schema": "^3.92.0",
91
- "@sanity/types": "^3.92.0",
89
+ "@sanity/pkg-utils": "^7.6.1",
90
+ "@sanity/schema": "^3.93.0",
91
+ "@sanity/types": "^3.93.0",
92
92
  "@testing-library/react": "^16.3.0",
93
93
  "@types/debug": "^4.1.12",
94
94
  "@types/lodash": "^4.17.16",
95
95
  "@types/lodash.startcase": "^4.4.9",
96
96
  "@types/react": "^19.1.8",
97
97
  "@types/react-dom": "^19.1.6",
98
- "@typescript-eslint/eslint-plugin": "^8.33.0",
99
- "@typescript-eslint/parser": "^8.33.0",
98
+ "@typescript-eslint/eslint-plugin": "^8.34.0",
99
+ "@typescript-eslint/parser": "^8.34.0",
100
100
  "@vitejs/plugin-react": "^4.5.2",
101
101
  "@vitest/browser": "^3.2.3",
102
102
  "@vitest/coverage-istanbul": "^3.2.3",
103
- "babel-plugin-react-compiler": "19.1.0-rc.1",
103
+ "babel-plugin-react-compiler": "19.1.0-rc.2",
104
104
  "eslint": "8.57.1",
105
- "eslint-plugin-react-hooks": "0.0.0-experimental-f9ae0a4c-20250527",
105
+ "eslint-plugin-react-hooks": "0.0.0-experimental-12bc60f5-20250613",
106
106
  "jsdom": "^26.0.0",
107
107
  "react": "^19.1.0",
108
108
  "react-dom": "^19.1.0",
@@ -110,12 +110,12 @@
110
110
  "typescript": "5.8.3",
111
111
  "vite": "^6.2.5",
112
112
  "vitest": "^3.2.3",
113
- "vitest-browser-react": "^0.2.0",
114
- "racejar": "1.2.6"
113
+ "vitest-browser-react": "^0.3.0",
114
+ "racejar": "1.2.7"
115
115
  },
116
116
  "peerDependencies": {
117
- "@sanity/schema": "^3.92.0",
118
- "@sanity/types": "^3.92.0",
117
+ "@sanity/schema": "^3.93.0",
118
+ "@sanity/types": "^3.93.0",
119
119
  "react": "^16.9 || ^17 || ^18 || ^19",
120
120
  "rxjs": "^7.8.2"
121
121
  },
@@ -1,8 +1,59 @@
1
1
  import {isActiveAnnotation} from '../selectors'
2
+ import * as selectors from '../selectors'
2
3
  import {raise} from './behavior.types.action'
3
4
  import {defineBehavior} from './behavior.types.behavior'
4
5
 
5
6
  export const abstractAnnotationBehaviors = [
7
+ defineBehavior({
8
+ on: 'annotation.set',
9
+ guard: ({snapshot, event}) => {
10
+ const blockKey = event.at[0]._key
11
+ const markDefKey = event.at[2]._key
12
+
13
+ const block = selectors.getFocusTextBlock({
14
+ ...snapshot,
15
+ context: {
16
+ ...snapshot.context,
17
+ selection: {
18
+ anchor: {
19
+ path: [{_key: blockKey}],
20
+ offset: 0,
21
+ },
22
+ focus: {
23
+ path: [{_key: blockKey}],
24
+ offset: 0,
25
+ },
26
+ },
27
+ },
28
+ })
29
+
30
+ if (!block) {
31
+ return false
32
+ }
33
+
34
+ const updatedMarkDefs = block.node.markDefs?.map((markDef) => {
35
+ if (markDef._key === markDefKey) {
36
+ return {
37
+ ...markDef,
38
+ ...event.props,
39
+ }
40
+ }
41
+
42
+ return markDef
43
+ })
44
+
45
+ return {blockKey, updatedMarkDefs}
46
+ },
47
+ actions: [
48
+ (_, {blockKey, updatedMarkDefs}) => [
49
+ raise({
50
+ type: 'block.set',
51
+ at: [{_key: blockKey}],
52
+ props: {markDefs: updatedMarkDefs},
53
+ }),
54
+ ],
55
+ ],
56
+ }),
6
57
  defineBehavior({
7
58
  on: 'annotation.toggle',
8
59
  guard: ({snapshot, event}) =>
@@ -1,3 +1,4 @@
1
+ import {isSpan} from '../internal-utils/parse-blocks'
1
2
  import * as selectors from '../selectors'
2
3
  import * as utils from '../utils'
3
4
  import {raise} from './behavior.types.action'
@@ -64,6 +65,60 @@ export const abstractDeleteBehaviors = [
64
65
  ],
65
66
  ],
66
67
  }),
68
+ defineBehavior({
69
+ on: 'delete.child',
70
+ guard: ({snapshot, event}) => {
71
+ const focusChild = selectors.getFocusChild({
72
+ ...snapshot,
73
+ context: {
74
+ ...snapshot.context,
75
+ selection: {
76
+ anchor: {
77
+ path: event.at,
78
+ offset: 0,
79
+ },
80
+ focus: {
81
+ path: event.at,
82
+ offset: 0,
83
+ },
84
+ },
85
+ },
86
+ })
87
+
88
+ if (!focusChild) {
89
+ return false
90
+ }
91
+
92
+ if (isSpan(snapshot.context, focusChild.node)) {
93
+ return {
94
+ selection: {
95
+ anchor: {
96
+ path: event.at,
97
+ offset: 0,
98
+ },
99
+ focus: {
100
+ path: event.at,
101
+ offset: focusChild.node.text.length,
102
+ },
103
+ },
104
+ }
105
+ }
106
+
107
+ return {
108
+ selection: {
109
+ anchor: {
110
+ path: event.at,
111
+ offset: 0,
112
+ },
113
+ focus: {
114
+ path: event.at,
115
+ offset: 0,
116
+ },
117
+ },
118
+ }
119
+ },
120
+ actions: [(_, {selection}) => [raise({type: 'delete', at: selection})]],
121
+ }),
67
122
  defineBehavior({
68
123
  on: 'delete.text',
69
124
  guard: ({snapshot, event}) => {
@@ -1,9 +1,9 @@
1
+ import {createEditorDom} from '../editor/editor-dom'
1
2
  import type {EditorSchema} from '../editor/editor-schema'
2
3
  import type {EditorSnapshot} from '../editor/editor-snapshot'
3
4
  import {withApplyingBehaviorOperations} from '../editor/with-applying-behavior-operations'
4
5
  import {withUndoStep} from '../editor/with-undo-step'
5
6
  import {debugWithName} from '../internal-utils/debug'
6
- import {createEditorDom} from '../internal-utils/selection-elements'
7
7
  import {performOperation} from '../operations/behavior.operations'
8
8
  import type {PortableTextSlateEditor} from '../types/editor'
9
9
  import {abstractBehaviors} from './behavior.abstract'
@@ -116,8 +116,6 @@ export function performEvent({
116
116
  })
117
117
  })
118
118
 
119
- editor.onChange()
120
-
121
119
  return
122
120
  }
123
121
 
@@ -182,6 +180,11 @@ export function performEvent({
182
180
  continue
183
181
  }
184
182
 
183
+ nativeEventPrevented =
184
+ actions.some(
185
+ (action) => action.type === 'raise' || action.type === 'execute',
186
+ ) || !actions.some((action) => action.type === 'forward')
187
+
185
188
  if (actions.some((action) => action.type === 'execute')) {
186
189
  // Since at least one action is about to `execute` changes in the editor,
187
190
  // we set up a new undo step.
@@ -190,8 +193,6 @@ export function performEvent({
190
193
  withUndoStep(editor, () => {
191
194
  for (const action of actions) {
192
195
  if (action.type === 'effect') {
193
- nativeEventPrevented = true
194
-
195
196
  try {
196
197
  action.effect()
197
198
  } catch (error) {
@@ -227,8 +228,6 @@ export function performEvent({
227
228
  }
228
229
 
229
230
  if (action.type === 'raise') {
230
- nativeEventPrevented = true
231
-
232
231
  performEvent({
233
232
  mode: 'raise',
234
233
  behaviors,
@@ -245,8 +244,6 @@ export function performEvent({
245
244
  continue
246
245
  }
247
246
 
248
- nativeEventPrevented = true
249
-
250
247
  performEvent({
251
248
  mode: 'execute',
252
249
  behaviors,
@@ -269,8 +266,6 @@ export function performEvent({
269
266
 
270
267
  for (const action of actions) {
271
268
  if (action.type === 'effect') {
272
- nativeEventPrevented = true
273
-
274
269
  try {
275
270
  action.effect()
276
271
  } catch (error) {
@@ -306,8 +301,6 @@ export function performEvent({
306
301
  }
307
302
 
308
303
  if (action.type === 'raise') {
309
- nativeEventPrevented = true
310
-
311
304
  performEvent({
312
305
  mode: 'raise',
313
306
  behaviors,
@@ -347,8 +340,6 @@ export function performEvent({
347
340
  },
348
341
  })
349
342
  })
350
-
351
- editor.onChange()
352
343
  } else if (nativeEventPrevented) {
353
344
  nativeEvent?.preventDefault()
354
345
  }
@@ -1,5 +1,5 @@
1
+ import type {EditorDom} from '../editor/editor-dom'
1
2
  import type {EditorSnapshot} from '../editor/editor-snapshot'
2
- import type {EditorDom} from '../internal-utils/selection-elements'
3
3
  import type {PickFromUnion} from '../type-utils'
4
4
  import type {
5
5
  CustomBehaviorEvent,
@@ -1,10 +1,11 @@
1
- import type {KeyedSegment, PortableTextBlock} from '@sanity/types'
1
+ import type {PortableTextBlock} from '@sanity/types'
2
2
  import type {EventPosition} from '../internal-utils/event-position'
3
3
  import type {MIMEType} from '../internal-utils/mime-type'
4
4
  import type {OmitFromUnion, PickFromUnion, StrictExtract} from '../type-utils'
5
5
  import type {BlockOffset} from '../types/block-offset'
6
6
  import type {BlockWithOptionalKey} from '../types/block-with-optional-key'
7
7
  import type {EditorSelection} from '../types/editor'
8
+ import type {AnnotationPath, BlockPath, ChildPath} from '../types/paths'
8
9
 
9
10
  /**
10
11
  * @beta
@@ -63,6 +64,8 @@ const syntheticBehaviorEventTypes = [
63
64
  'annotation.remove',
64
65
  'block.set',
65
66
  'block.unset',
67
+ 'child.set',
68
+ 'child.unset',
66
69
  'decorator.add',
67
70
  'decorator.remove',
68
71
  'delete',
@@ -104,12 +107,22 @@ export type SyntheticBehaviorEvent =
104
107
  }
105
108
  | {
106
109
  type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
107
- at: [KeyedSegment]
110
+ at: BlockPath
108
111
  props: Record<string, unknown>
109
112
  }
110
113
  | {
111
114
  type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
112
- at: [KeyedSegment]
115
+ at: BlockPath
116
+ props: Array<string>
117
+ }
118
+ | {
119
+ type: StrictExtract<SyntheticBehaviorEventType, 'child.set'>
120
+ at: ChildPath
121
+ props: {[prop: string]: unknown}
122
+ }
123
+ | {
124
+ type: StrictExtract<SyntheticBehaviorEventType, 'child.unset'>
125
+ at: ChildPath
113
126
  props: Array<string>
114
127
  }
115
128
  | {
@@ -174,8 +187,8 @@ export type SyntheticBehaviorEvent =
174
187
  }
175
188
  | {
176
189
  type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
177
- at: [KeyedSegment]
178
- to: [KeyedSegment]
190
+ at: BlockPath
191
+ to: BlockPath
179
192
  }
180
193
  | {
181
194
  type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
@@ -208,10 +221,12 @@ export function isSyntheticBehaviorEvent(
208
221
  **************************************/
209
222
 
210
223
  const abstractBehaviorEventTypes = [
224
+ 'annotation.set',
211
225
  'annotation.toggle',
212
226
  'decorator.toggle',
213
227
  'delete.backward',
214
228
  'delete.block',
229
+ 'delete.child',
215
230
  'delete.forward',
216
231
  'delete.text',
217
232
  'deserialize',
@@ -240,6 +255,11 @@ export type AbstractBehaviorEventType =
240
255
  (typeof abstractBehaviorEventTypes)[number]
241
256
 
242
257
  type AbstractBehaviorEvent =
258
+ | {
259
+ type: StrictExtract<SyntheticBehaviorEventType, 'annotation.set'>
260
+ at: AnnotationPath
261
+ props: Record<string, unknown>
262
+ }
243
263
  | {
244
264
  type: StrictExtract<SyntheticBehaviorEventType, 'annotation.toggle'>
245
265
  annotation: {
@@ -258,7 +278,11 @@ type AbstractBehaviorEvent =
258
278
  }
259
279
  | {
260
280
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
261
- at: [KeyedSegment]
281
+ at: BlockPath
282
+ }
283
+ | {
284
+ type: StrictExtract<SyntheticBehaviorEventType, 'delete.child'>
285
+ at: ChildPath
262
286
  }
263
287
  | {
264
288
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
@@ -359,11 +383,11 @@ type AbstractBehaviorEvent =
359
383
  }
360
384
  | {
361
385
  type: StrictExtract<SyntheticBehaviorEventType, 'move.block down'>
362
- at: [KeyedSegment]
386
+ at: BlockPath
363
387
  }
364
388
  | {
365
389
  type: StrictExtract<SyntheticBehaviorEventType, 'move.block up'>
366
- at: [KeyedSegment]
390
+ at: BlockPath
367
391
  }
368
392
  | {
369
393
  type: StrictExtract<SyntheticBehaviorEventType, 'select.previous block'>
@@ -1,5 +1,5 @@
1
+ import type {EditorDom} from '../editor/editor-dom'
1
2
  import type {EditorSnapshot} from '../editor/editor-snapshot'
2
- import type {EditorDom} from '../internal-utils/selection-elements'
3
3
 
4
4
  /**
5
5
  * @beta
@@ -543,6 +543,9 @@ export const PortableTextEditable = forwardRef<
543
543
  )
544
544
  ) {
545
545
  Transforms.select(slateEditor, Editor.start(slateEditor, []))
546
+ }
547
+
548
+ if (slateEditor.selection) {
546
549
  slateEditor.onChange()
547
550
  }
548
551
  }
@@ -30,7 +30,6 @@ import {createInternalEditor, type InternalEditor} from './create-editor'
30
30
  import {EditorActorContext} from './editor-actor-context'
31
31
  import type {EditorActor} from './editor-machine'
32
32
  import {PortableTextEditorContext} from './hooks/usePortableTextEditor'
33
- import {PortableTextEditorSelectionProvider} from './hooks/usePortableTextEditorSelection'
34
33
  import type {MutationActor} from './mutation-machine'
35
34
  import {RelayActorContext} from './relay-actor-context'
36
35
  import type {RelayActor} from './relay-machine'
@@ -288,11 +287,7 @@ export class PortableTextEditor extends Component<
288
287
  initialValue={this.editor._internal.slateEditor.initialValue}
289
288
  >
290
289
  <PortableTextEditorContext.Provider value={this}>
291
- <PortableTextEditorSelectionProvider
292
- editorActor={this.editor._internal.editorActor}
293
- >
294
- {this.props.children}
295
- </PortableTextEditorSelectionProvider>
290
+ {this.props.children}
296
291
  </PortableTextEditorContext.Provider>
297
292
  </Slate>
298
293
  </RelayActorContext.Provider>
@@ -9,6 +9,7 @@ import {corePriority} from '../priority/priority.core'
9
9
  import {createEditorPriority} from '../priority/priority.types'
10
10
  import type {EditableAPI, PortableTextSlateEditor} from '../types/editor'
11
11
  import {createSlateEditor, type SlateEditor} from './create-slate-editor'
12
+ import {createEditorDom} from './editor-dom'
12
13
  import type {EditorActor} from './editor-machine'
13
14
  import {editorMachine} from './editor-machine'
14
15
  import {
@@ -64,6 +65,10 @@ export function createInternalEditor(config: EditorConfig): {
64
65
  })
65
66
 
66
67
  const editor = {
68
+ dom: createEditorDom(
69
+ (event) => editorActor.send(event),
70
+ slateEditor.instance,
71
+ ),
67
72
  getSnapshot: () =>
68
73
  getEditorSnapshot({
69
74
  editorActorSnapshot: editorActor.getSnapshot(),
@@ -2,9 +2,9 @@ import {Editor} from 'slate'
2
2
  import {DOMEditor} from 'slate-dom'
3
3
  import type {EditorSnapshot} from '..'
4
4
  import type {BehaviorEvent} from '../behaviors'
5
+ import {toSlateRange} from '../internal-utils/ranges'
5
6
  import type {PickFromUnion} from '../type-utils'
6
7
  import type {PortableTextSlateEditor} from '../types/editor'
7
- import {toSlateRange} from './ranges'
8
8
 
9
9
  export type EditorDom = {
10
10
  getBlockNodes: (snapshot: EditorSnapshot) => Array<Node>
@@ -51,17 +51,21 @@ function getBlockNodes(
51
51
  return []
52
52
  }
53
53
 
54
- const blockEntries = Array.from(
55
- Editor.nodes(slateEditor, {
56
- at: range,
57
- mode: 'highest',
58
- match: (n) => !Editor.isEditor(n),
59
- }),
60
- )
54
+ try {
55
+ const blockEntries = Array.from(
56
+ Editor.nodes(slateEditor, {
57
+ at: range,
58
+ mode: 'highest',
59
+ match: (n) => !Editor.isEditor(n),
60
+ }),
61
+ )
61
62
 
62
- return blockEntries.map(([blockNode]) =>
63
- DOMEditor.toDOMNode(slateEditor, blockNode),
64
- )
63
+ return blockEntries.map(([blockNode]) =>
64
+ DOMEditor.toDOMNode(slateEditor, blockNode),
65
+ )
66
+ } catch {
67
+ return []
68
+ }
65
69
  }
66
70
 
67
71
  function getChildNodes(
@@ -78,17 +82,21 @@ function getChildNodes(
78
82
  return []
79
83
  }
80
84
 
81
- const childEntries = Array.from(
82
- Editor.nodes(slateEditor, {
83
- at: range,
84
- mode: 'lowest',
85
- match: (n) => !Editor.isEditor(n),
86
- }),
87
- )
85
+ try {
86
+ const childEntries = Array.from(
87
+ Editor.nodes(slateEditor, {
88
+ at: range,
89
+ mode: 'lowest',
90
+ match: (n) => !Editor.isEditor(n),
91
+ }),
92
+ )
88
93
 
89
- return childEntries.map(([childNode]) =>
90
- DOMEditor.toDOMNode(slateEditor, childNode),
91
- )
94
+ return childEntries.map(([childNode]) =>
95
+ DOMEditor.toDOMNode(slateEditor, childNode),
96
+ )
97
+ } catch {
98
+ return []
99
+ }
92
100
  }
93
101
 
94
102
  export type SelectionDomNodes = {
@@ -8,7 +8,6 @@ import {createInternalEditor} from './create-editor'
8
8
  import {EditorActorContext} from './editor-actor-context'
9
9
  import {EditorContext} from './editor-context'
10
10
  import {PortableTextEditorContext} from './hooks/usePortableTextEditor'
11
- import {PortableTextEditorSelectionProvider} from './hooks/usePortableTextEditorSelection'
12
11
  import {
13
12
  PortableTextEditor,
14
13
  type PortableTextEditorProps,
@@ -93,11 +92,7 @@ export function EditorProvider(props: EditorProviderProps) {
93
92
  }
94
93
  >
95
94
  <PortableTextEditorContext.Provider value={portableTextEditor}>
96
- <PortableTextEditorSelectionProvider
97
- editorActor={internalEditor.actors.editorActor}
98
- >
99
- {props.children}
100
- </PortableTextEditorSelectionProvider>
95
+ {props.children}
101
96
  </PortableTextEditorContext.Provider>
102
97
  </Slate>
103
98
  </RelayActorContext.Provider>