@portabletext/editor 1.44.0 → 1.44.2

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 (55) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +3 -3
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/editor-provider.cjs +323 -490
  4. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  5. package/lib/_chunks-es/behavior.core.js +3 -3
  6. package/lib/_chunks-es/behavior.core.js.map +1 -1
  7. package/lib/_chunks-es/editor-provider.js +325 -492
  8. package/lib/_chunks-es/editor-provider.js.map +1 -1
  9. package/lib/behaviors/index.cjs +2 -2
  10. package/lib/behaviors/index.cjs.map +1 -1
  11. package/lib/behaviors/index.d.cts +8390 -16283
  12. package/lib/behaviors/index.d.ts +8390 -16283
  13. package/lib/behaviors/index.js +4 -4
  14. package/lib/behaviors/index.js.map +1 -1
  15. package/lib/index.cjs +2 -2
  16. package/lib/index.cjs.map +1 -1
  17. package/lib/index.d.cts +2237 -15969
  18. package/lib/index.d.ts +2237 -15969
  19. package/lib/index.js +2 -2
  20. package/lib/index.js.map +1 -1
  21. package/lib/plugins/index.d.cts +2088 -15821
  22. package/lib/plugins/index.d.ts +2088 -15821
  23. package/lib/selectors/index.d.cts +1738 -15472
  24. package/lib/selectors/index.d.ts +1738 -15472
  25. package/lib/utils/index.d.cts +1738 -15472
  26. package/lib/utils/index.d.ts +1738 -15472
  27. package/package.json +2 -2
  28. package/src/behavior-actions/behavior.actions.ts +1 -39
  29. package/src/behaviors/behavior.abstract.annotation.ts +26 -0
  30. package/src/behaviors/behavior.abstract.decorator.ts +47 -0
  31. package/src/behaviors/{behavior.internal.insert.ts → behavior.abstract.insert.ts} +1 -1
  32. package/src/behaviors/{behavior.internal.list-item.ts → behavior.abstract.list-item.ts} +1 -1
  33. package/src/behaviors/behavior.abstract.move.ts +78 -0
  34. package/src/behaviors/{behavior.internal.select.ts → behavior.abstract.select.ts} +1 -1
  35. package/src/behaviors/{behavior.internal.style.ts → behavior.abstract.style.ts} +1 -1
  36. package/src/behaviors/behavior.code-editor.ts +13 -8
  37. package/src/behaviors/behavior.default.ts +15 -78
  38. package/src/behaviors/behavior.perform-event.ts +4 -4
  39. package/src/behaviors/behavior.types.action.ts +3 -3
  40. package/src/behaviors/behavior.types.behavior.ts +4 -3
  41. package/src/behaviors/behavior.types.event.ts +164 -160
  42. package/src/editor/components/Leaf.tsx +2 -2
  43. package/src/editor/create-editor.ts +37 -11
  44. package/src/editor/editor-machine.ts +4 -76
  45. package/src/editor/editor-selector.ts +5 -2
  46. package/src/editor/editor-snapshot.ts +2 -7
  47. package/src/editor/plugins/create-with-event-listeners.ts +1 -64
  48. package/src/editor/plugins/createWithEditableAPI.ts +0 -30
  49. package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -29
  50. package/src/editor/plugins/with-plugins.ts +1 -4
  51. package/src/internal-utils/slate-children-to-blocks.ts +49 -0
  52. package/src/internal-utils/slate-utils.ts +6 -8
  53. package/src/type-utils.ts +2 -0
  54. package/src/behavior-actions/behavior.action.move.block-down.ts +0 -48
  55. package/src/behavior-actions/behavior.action.move.block-up.ts +0 -53
@@ -2,7 +2,7 @@ import type {KeyedSegment, PortableTextBlock} from '@sanity/types'
2
2
  import type {TextUnit} from 'slate'
3
3
  import type {EventPosition} from '../internal-utils/event-position'
4
4
  import type {MIMEType} from '../internal-utils/mime-type'
5
- import type {PickFromUnion} from '../type-utils'
5
+ import type {PickFromUnion, StrictExtract} from '../type-utils'
6
6
  import type {BlockOffset} from '../types/block-offset'
7
7
  import type {BlockWithOptionalKey} from '../types/block-with-optional-key'
8
8
  import type {EditorSelection} from '../types/editor'
@@ -12,13 +12,13 @@ import type {EditorSelection} from '../types/editor'
12
12
  */
13
13
  export type BehaviorEvent =
14
14
  | SyntheticBehaviorEvent
15
- | InternalBehaviorEvent
15
+ | AbstractBehaviorEvent
16
16
  | NativeBehaviorEvent
17
17
  | CustomBehaviorEvent
18
18
 
19
19
  export type BehaviorEventTypeNamespace =
20
20
  | SyntheticBehaviorEventNamespace
21
- | InternalBehaviorEventNamespace
21
+ | AbstractBehaviorEventNamespace
22
22
  | NativeBehaviorEventNamespace
23
23
  | CustomBehaviorEventNamespace
24
24
 
@@ -49,8 +49,10 @@ export type ExternalBehaviorEvent =
49
49
  }
50
50
  }
51
51
  | PickFromUnion<
52
- InternalBehaviorEvent,
52
+ AbstractBehaviorEvent,
53
53
  'type',
54
+ | 'annotation.toggle'
55
+ | 'decorator.toggle'
54
56
  | 'insert.blocks'
55
57
  | 'list item.add'
56
58
  | 'list item.remove'
@@ -59,130 +61,134 @@ export type ExternalBehaviorEvent =
59
61
  | 'style.remove'
60
62
  | 'style.toggle'
61
63
  >
64
+ | SyntheticBehaviorEvent
65
+ | CustomBehaviorEvent
62
66
 
63
67
  /**************************************
64
68
  * Synthetic events
65
69
  **************************************/
66
70
 
67
- type SyntheticBehaviorEventType<
68
- TNamespace extends SyntheticBehaviorEventNamespace,
69
- TType extends string = '',
70
- > = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
71
+ const syntheticBehaviorEventTypes = [
72
+ 'annotation.add',
73
+ 'annotation.remove',
74
+ 'block.set',
75
+ 'block.unset',
76
+ 'blur',
77
+ 'decorator.add',
78
+ 'decorator.remove',
79
+ 'delete',
80
+ 'delete.backward',
81
+ 'delete.block',
82
+ 'delete.forward',
83
+ 'delete.text',
84
+ 'focus',
85
+ 'history.redo',
86
+ 'history.undo',
87
+ 'insert.inline object',
88
+ 'insert.break',
89
+ 'insert.soft break',
90
+ 'insert.block',
91
+ 'insert.span',
92
+ 'insert.text',
93
+ 'move.block',
94
+ 'select',
95
+ ] as const
96
+
97
+ type SyntheticBehaviorEventType = (typeof syntheticBehaviorEventTypes)[number]
71
98
 
72
99
  type SyntheticBehaviorEventNamespace =
73
- | 'annotation'
74
- | 'block'
75
- | 'blur'
76
- | 'decorator'
77
- | 'delete'
78
- | 'focus'
79
- | 'history'
80
- | 'insert'
81
- | 'move'
82
- | 'select'
100
+ ExtractNamespace<SyntheticBehaviorEventType>
83
101
 
84
102
  /**
85
103
  * @beta
86
104
  */
87
105
  export type SyntheticBehaviorEvent =
88
106
  | {
89
- type: SyntheticBehaviorEventType<'annotation', 'add'>
107
+ type: StrictExtract<SyntheticBehaviorEventType, 'annotation.add'>
90
108
  annotation: {
91
109
  name: string
92
110
  value: {[prop: string]: unknown}
93
111
  }
94
112
  }
95
113
  | {
96
- type: SyntheticBehaviorEventType<'annotation', 'remove'>
97
- annotation: {
98
- name: string
99
- }
100
- }
101
- | {
102
- type: SyntheticBehaviorEventType<'annotation', 'toggle'>
114
+ type: StrictExtract<SyntheticBehaviorEventType, 'annotation.remove'>
103
115
  annotation: {
104
116
  name: string
105
- value: {[prop: string]: unknown}
106
117
  }
107
118
  }
108
119
  | {
109
- type: SyntheticBehaviorEventType<'block', 'set'>
120
+ type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
110
121
  at: [KeyedSegment]
111
122
  props: Record<string, unknown>
112
123
  }
113
124
  | {
114
- type: SyntheticBehaviorEventType<'block', 'unset'>
125
+ type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
115
126
  at: [KeyedSegment]
116
127
  props: Array<string>
117
128
  }
118
129
  | {
119
- type: SyntheticBehaviorEventType<'blur'>
130
+ type: StrictExtract<SyntheticBehaviorEventType, 'blur'>
120
131
  }
121
132
  | {
122
- type: SyntheticBehaviorEventType<'decorator', 'add'>
133
+ type: StrictExtract<SyntheticBehaviorEventType, 'decorator.add'>
123
134
  decorator: string
124
135
  offsets?: {anchor: BlockOffset; focus: BlockOffset}
125
136
  }
126
137
  | {
127
- type: SyntheticBehaviorEventType<'decorator', 'remove'>
138
+ type: StrictExtract<SyntheticBehaviorEventType, 'decorator.remove'>
128
139
  decorator: string
129
140
  }
130
141
  | {
131
- type: SyntheticBehaviorEventType<'decorator', 'toggle'>
132
- decorator: string
133
- offsets?: {anchor: BlockOffset; focus: BlockOffset}
134
- }
135
- | {
136
- type: SyntheticBehaviorEventType<'delete'>
142
+ type: StrictExtract<SyntheticBehaviorEventType, 'delete'>
137
143
  selection: NonNullable<EditorSelection>
138
144
  }
139
145
  | {
140
- type: SyntheticBehaviorEventType<'delete', 'backward'>
146
+ type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>
141
147
  unit: TextUnit
142
148
  }
143
149
  | {
144
- type: SyntheticBehaviorEventType<'delete', 'block'>
150
+ type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
145
151
  at: [KeyedSegment]
146
152
  }
147
153
  | {
148
- type: SyntheticBehaviorEventType<'delete', 'forward'>
154
+ type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
149
155
  unit: TextUnit
150
156
  }
151
157
  | {
152
- type: SyntheticBehaviorEventType<'delete', 'text'>
158
+ type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
153
159
  anchor: BlockOffset
154
160
  focus: BlockOffset
155
161
  }
156
162
  | {
157
- type: SyntheticBehaviorEventType<'focus'>
163
+ type: StrictExtract<SyntheticBehaviorEventType, 'focus'>
158
164
  }
159
165
  | {
160
- type: SyntheticBehaviorEventType<'history', 'redo'>
166
+ type: StrictExtract<SyntheticBehaviorEventType, 'history.redo'>
161
167
  }
162
168
  | {
163
- type: SyntheticBehaviorEventType<'history', 'undo'>
169
+ type: StrictExtract<SyntheticBehaviorEventType, 'history.undo'>
164
170
  }
165
171
  | {
166
- type: SyntheticBehaviorEventType<'insert', 'inline object'>
172
+ type: StrictExtract<SyntheticBehaviorEventType, 'insert.inline object'>
167
173
  inlineObject: {
168
174
  name: string
169
175
  value?: {[prop: string]: unknown}
170
176
  }
171
177
  }
172
178
  | {
173
- type: SyntheticBehaviorEventType<'insert', 'break'>
179
+ type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>
174
180
  }
175
181
  | {
176
- type: SyntheticBehaviorEventType<'insert', 'soft break'>
182
+ type: StrictExtract<SyntheticBehaviorEventType, 'insert.soft break'>
177
183
  }
178
184
  | {
179
- type: SyntheticBehaviorEventType<'insert', 'block'>
185
+ type: StrictExtract<SyntheticBehaviorEventType, 'insert.block'>
180
186
  block: BlockWithOptionalKey
181
187
  placement: InsertPlacement
182
188
  select?: 'start' | 'end' | 'none'
183
189
  }
184
190
  | {
185
- type: SyntheticBehaviorEventType<'insert', 'span'>
191
+ type: StrictExtract<SyntheticBehaviorEventType, 'insert.span'>
186
192
  text: string
187
193
  annotations?: Array<{
188
194
  name: string
@@ -191,24 +197,16 @@ export type SyntheticBehaviorEvent =
191
197
  decorators?: Array<string>
192
198
  }
193
199
  | {
194
- type: SyntheticBehaviorEventType<'insert', 'text'>
200
+ type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
195
201
  text: string
196
202
  }
197
203
  | {
198
- type: SyntheticBehaviorEventType<'move', 'block'>
204
+ type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
199
205
  at: [KeyedSegment]
200
206
  to: [KeyedSegment]
201
207
  }
202
208
  | {
203
- type: SyntheticBehaviorEventType<'move', 'block down'>
204
- at: [KeyedSegment]
205
- }
206
- | {
207
- type: SyntheticBehaviorEventType<'move', 'block up'>
208
- at: [KeyedSegment]
209
- }
210
- | {
211
- type: SyntheticBehaviorEventType<'select'>
209
+ type: StrictExtract<SyntheticBehaviorEventType, 'select'>
212
210
  selection: EditorSelection
213
211
  }
214
212
 
@@ -221,27 +219,51 @@ export function isKeyboardBehaviorEvent(
221
219
  }
222
220
 
223
221
  /**************************************
224
- * Internal events
222
+ * Abstract events
225
223
  **************************************/
226
224
 
227
- type InternalBehaviorEventNamespace =
228
- | 'deserialize'
229
- | 'deserialization'
230
- | 'list item'
231
- | 'insert'
232
- | 'select'
233
- | 'serialize'
234
- | 'serialization'
235
- | 'style'
236
-
237
- type InternalBehaviorEventType<
238
- TNamespace extends InternalBehaviorEventNamespace,
239
- TType extends string = '',
240
- > = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
241
-
242
- export type InternalBehaviorEvent =
225
+ const abstractBehaviorEventTypes = [
226
+ 'annotation.toggle',
227
+ 'decorator.toggle',
228
+ 'deserialize',
229
+ 'deserialization.success',
230
+ 'deserialization.failure',
231
+ 'insert.blocks',
232
+ 'list item.add',
233
+ 'list item.remove',
234
+ 'list item.toggle',
235
+ 'move.block down',
236
+ 'move.block up',
237
+ 'select.previous block',
238
+ 'select.next block',
239
+ 'serialize',
240
+ 'serialization.success',
241
+ 'serialization.failure',
242
+ 'style.add',
243
+ 'style.remove',
244
+ 'style.toggle',
245
+ ] as const
246
+
247
+ type AbstractBehaviorEventType = (typeof abstractBehaviorEventTypes)[number]
248
+
249
+ type AbstractBehaviorEventNamespace =
250
+ ExtractNamespace<AbstractBehaviorEventType>
251
+
252
+ export type AbstractBehaviorEvent =
253
+ | {
254
+ type: StrictExtract<AbstractBehaviorEventType, 'annotation.toggle'>
255
+ annotation: {
256
+ name: string
257
+ value: {[prop: string]: unknown}
258
+ }
259
+ }
243
260
  | {
244
- type: InternalBehaviorEventType<'deserialize'>
261
+ type: StrictExtract<AbstractBehaviorEventType, 'decorator.toggle'>
262
+ decorator: string
263
+ offsets?: {anchor: BlockOffset; focus: BlockOffset}
264
+ }
265
+ | {
266
+ type: StrictExtract<AbstractBehaviorEventType, 'deserialize'>
245
267
  originEvent:
246
268
  | PickFromUnion<
247
269
  NativeBehaviorEvent,
@@ -251,7 +273,7 @@ export type InternalBehaviorEvent =
251
273
  | InputBehaviorEvent
252
274
  }
253
275
  | {
254
- type: InternalBehaviorEventType<'serialize'>
276
+ type: StrictExtract<AbstractBehaviorEventType, 'serialize'>
255
277
  originEvent: PickFromUnion<
256
278
  NativeBehaviorEvent,
257
279
  'type',
@@ -259,7 +281,7 @@ export type InternalBehaviorEvent =
259
281
  >
260
282
  }
261
283
  | {
262
- type: InternalBehaviorEventType<'deserialization', 'success'>
284
+ type: StrictExtract<AbstractBehaviorEventType, 'deserialization.success'>
263
285
  mimeType: MIMEType
264
286
  data: Array<PortableTextBlock>
265
287
  originEvent:
@@ -271,7 +293,7 @@ export type InternalBehaviorEvent =
271
293
  | InputBehaviorEvent
272
294
  }
273
295
  | {
274
- type: InternalBehaviorEventType<'deserialization', 'failure'>
296
+ type: StrictExtract<AbstractBehaviorEventType, 'deserialization.failure'>
275
297
  mimeType: MIMEType
276
298
  reason: string
277
299
  originEvent:
@@ -283,7 +305,7 @@ export type InternalBehaviorEvent =
283
305
  | InputBehaviorEvent
284
306
  }
285
307
  | {
286
- type: InternalBehaviorEventType<'serialization', 'success'>
308
+ type: StrictExtract<AbstractBehaviorEventType, 'serialization.success'>
287
309
  mimeType: MIMEType
288
310
  data: string
289
311
  originEvent: PickFromUnion<
@@ -293,7 +315,7 @@ export type InternalBehaviorEvent =
293
315
  >
294
316
  }
295
317
  | {
296
- type: InternalBehaviorEventType<'serialization', 'failure'>
318
+ type: StrictExtract<AbstractBehaviorEventType, 'serialization.failure'>
297
319
  mimeType: MIMEType
298
320
  reason: string
299
321
  originEvent: PickFromUnion<
@@ -303,85 +325,86 @@ export type InternalBehaviorEvent =
303
325
  >
304
326
  }
305
327
  | {
306
- type: InternalBehaviorEventType<'insert', 'blocks'>
328
+ type: StrictExtract<AbstractBehaviorEventType, 'insert.blocks'>
307
329
  blocks: Array<PortableTextBlock>
308
330
  placement: InsertPlacement
309
331
  }
310
332
  | {
311
- type: InternalBehaviorEventType<'list item', 'add'>
333
+ type: StrictExtract<AbstractBehaviorEventType, 'list item.add'>
312
334
  listItem: string
313
335
  }
314
336
  | {
315
- type: InternalBehaviorEventType<'list item', 'remove'>
337
+ type: StrictExtract<AbstractBehaviorEventType, 'list item.remove'>
316
338
  listItem: string
317
339
  }
318
340
  | {
319
- type: InternalBehaviorEventType<'list item', 'toggle'>
341
+ type: StrictExtract<AbstractBehaviorEventType, 'list item.toggle'>
320
342
  listItem: string
321
343
  }
322
344
  | {
323
- type: InternalBehaviorEventType<'select', 'previous block'>
345
+ type: StrictExtract<AbstractBehaviorEventType, 'move.block down'>
346
+ at: [KeyedSegment]
347
+ }
348
+ | {
349
+ type: StrictExtract<AbstractBehaviorEventType, 'move.block up'>
350
+ at: [KeyedSegment]
351
+ }
352
+ | {
353
+ type: StrictExtract<AbstractBehaviorEventType, 'select.previous block'>
324
354
  select?: 'start' | 'end'
325
355
  }
326
356
  | {
327
- type: InternalBehaviorEventType<'select', 'next block'>
357
+ type: StrictExtract<AbstractBehaviorEventType, 'select.next block'>
328
358
  select?: 'start' | 'end'
329
359
  }
330
360
  | {
331
- type: InternalBehaviorEventType<'style', 'add'>
361
+ type: StrictExtract<AbstractBehaviorEventType, 'style.add'>
332
362
  style: string
333
363
  }
334
364
  | {
335
- type: InternalBehaviorEventType<'style', 'remove'>
365
+ type: StrictExtract<AbstractBehaviorEventType, 'style.remove'>
336
366
  style: string
337
367
  }
338
368
  | {
339
- type: InternalBehaviorEventType<'style', 'toggle'>
369
+ type: StrictExtract<AbstractBehaviorEventType, 'style.toggle'>
340
370
  style: string
341
371
  }
342
372
 
343
- export function isInternalBehaviorEvent(
373
+ export function isAbstractBehaviorEvent(
344
374
  event: BehaviorEvent,
345
- ): event is InternalBehaviorEvent {
346
- return (
347
- event.type === 'deserialize' ||
348
- event.type.startsWith('deserialization.') ||
349
- event.type === 'insert.blocks' ||
350
- event.type.startsWith('list item.') ||
351
- event.type === 'serialize' ||
352
- event.type.startsWith('serialization.') ||
353
- event.type === 'select.next block' ||
354
- event.type === 'select.previous block' ||
355
- event.type.startsWith('style.')
356
- )
375
+ ): event is AbstractBehaviorEvent {
376
+ return (abstractBehaviorEventTypes as readonly string[]).includes(event.type)
357
377
  }
358
378
 
359
379
  /**************************************
360
380
  * Native events
361
381
  **************************************/
362
382
 
363
- type NativeBehaviorEventNamespace =
364
- | 'clipboard'
365
- | 'drag'
366
- | 'input'
367
- | 'keyboard'
368
- | 'mouse'
369
-
370
- type NativeBehaviorEventType<
371
- TNamespace extends NativeBehaviorEventNamespace,
372
- TType extends string = '',
373
- > = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
383
+ const nativeBehaviorEventTypes = [
384
+ 'clipboard.copy',
385
+ 'clipboard.cut',
386
+ 'clipboard.paste',
387
+ 'drag.dragstart',
388
+ 'drag.drag',
389
+ 'drag.dragend',
390
+ 'drag.dragenter',
391
+ 'drag.dragover',
392
+ 'drag.dragleave',
393
+ 'drag.drop',
394
+ 'input.*',
395
+ 'keyboard.keydown',
396
+ 'keyboard.keyup',
397
+ 'mouse.click',
398
+ ] as const
399
+
400
+ type NativeBehaviorEventType = (typeof nativeBehaviorEventTypes)[number]
401
+
402
+ type NativeBehaviorEventNamespace = ExtractNamespace<NativeBehaviorEventType>
374
403
 
375
404
  export function isNativeBehaviorEvent(
376
405
  event: BehaviorEvent,
377
406
  ): event is NativeBehaviorEvent {
378
- return (
379
- isClipboardBehaviorEvent(event) ||
380
- isDragBehaviorEvent(event) ||
381
- isInputBehaviorEvent(event) ||
382
- isKeyboardBehaviorEvent(event) ||
383
- isMouseBehaviorEvent(event)
384
- )
407
+ return (nativeBehaviorEventTypes as readonly string[]).includes(event.type)
385
408
  }
386
409
 
387
410
  /**
@@ -396,85 +419,75 @@ export type NativeBehaviorEvent =
396
419
 
397
420
  type ClipboardBehaviorEvent =
398
421
  | {
399
- type: NativeBehaviorEventType<'clipboard', 'copy'>
422
+ type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
400
423
  originEvent: {
401
424
  dataTransfer: DataTransfer
402
425
  }
403
426
  position: Pick<EventPosition, 'selection'>
404
427
  }
405
428
  | {
406
- type: NativeBehaviorEventType<'clipboard', 'cut'>
429
+ type: StrictExtract<NativeBehaviorEventType, 'clipboard.cut'>
407
430
  originEvent: {
408
431
  dataTransfer: DataTransfer
409
432
  }
410
433
  position: Pick<EventPosition, 'selection'>
411
434
  }
412
435
  | {
413
- type: NativeBehaviorEventType<'clipboard', 'paste'>
436
+ type: StrictExtract<NativeBehaviorEventType, 'clipboard.paste'>
414
437
  originEvent: {
415
438
  dataTransfer: DataTransfer
416
439
  }
417
440
  position: Pick<EventPosition, 'selection'>
418
441
  }
419
442
 
420
- function isClipboardBehaviorEvent(
421
- event: BehaviorEvent,
422
- ): event is ClipboardBehaviorEvent {
423
- return event.type.startsWith('clipboard.')
424
- }
425
-
426
443
  type DragBehaviorEvent =
427
444
  | {
428
- type: NativeBehaviorEventType<'drag', 'dragstart'>
445
+ type: StrictExtract<NativeBehaviorEventType, 'drag.dragstart'>
429
446
  originEvent: {
430
447
  dataTransfer: DataTransfer
431
448
  }
432
449
  position: Pick<EventPosition, 'selection'>
433
450
  }
434
451
  | {
435
- type: NativeBehaviorEventType<'drag', 'drag'>
452
+ type: StrictExtract<NativeBehaviorEventType, 'drag.drag'>
436
453
  originEvent: {
437
454
  dataTransfer: DataTransfer
438
455
  }
439
456
  }
440
457
  | {
441
- type: NativeBehaviorEventType<'drag', 'dragend'>
458
+ type: StrictExtract<NativeBehaviorEventType, 'drag.dragend'>
442
459
  originEvent: {
443
460
  dataTransfer: DataTransfer
444
461
  }
445
462
  }
446
463
  | {
447
- type: NativeBehaviorEventType<'drag', 'dragenter'>
464
+ type: StrictExtract<NativeBehaviorEventType, 'drag.dragenter'>
448
465
  originEvent: {
449
466
  dataTransfer: DataTransfer
450
467
  }
451
468
  position: EventPosition
452
469
  }
453
470
  | {
454
- type: NativeBehaviorEventType<'drag', 'dragover'>
471
+ type: StrictExtract<NativeBehaviorEventType, 'drag.dragover'>
455
472
  originEvent: {
456
473
  dataTransfer: DataTransfer
457
474
  }
458
475
  position: EventPosition
459
476
  }
460
477
  | {
461
- type: NativeBehaviorEventType<'drag', 'drop'>
478
+ type: StrictExtract<NativeBehaviorEventType, 'drag.drop'>
462
479
  originEvent: {
463
480
  dataTransfer: DataTransfer
464
481
  }
465
482
  position: EventPosition
466
483
  }
467
484
  | {
468
- type: NativeBehaviorEventType<'drag', 'dragleave'>
485
+ type: StrictExtract<NativeBehaviorEventType, 'drag.dragleave'>
469
486
  originEvent: {
470
487
  dataTransfer: DataTransfer
471
488
  }
472
489
  }
473
490
 
474
- function isDragBehaviorEvent(event: BehaviorEvent): event is DragBehaviorEvent {
475
- return event.type.startsWith('drag.')
476
- }
477
-
478
491
  /**
479
492
  * Used to represent native InputEvents that hold a DataTransfer object.
480
493
  *
@@ -487,28 +500,22 @@ function isDragBehaviorEvent(event: BehaviorEvent): event is DragBehaviorEvent {
487
500
  * - insertFromYank
488
501
  */
489
502
  export type InputBehaviorEvent = {
490
- type: NativeBehaviorEventType<'input', '*'>
503
+ type: StrictExtract<NativeBehaviorEventType, 'input.*'>
491
504
  originEvent: {
492
505
  dataTransfer: DataTransfer
493
506
  }
494
507
  }
495
508
 
496
- function isInputBehaviorEvent(
497
- event: BehaviorEvent,
498
- ): event is InputBehaviorEvent {
499
- return event.type.startsWith('input.')
500
- }
501
-
502
509
  export type KeyboardBehaviorEvent =
503
510
  | {
504
- type: NativeBehaviorEventType<'keyboard', 'keydown'>
511
+ type: StrictExtract<NativeBehaviorEventType, 'keyboard.keydown'>
505
512
  originEvent: Pick<
506
513
  KeyboardEvent,
507
514
  'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'
508
515
  >
509
516
  }
510
517
  | {
511
- type: NativeBehaviorEventType<'keyboard', 'keyup'>
518
+ type: StrictExtract<NativeBehaviorEventType, 'keyboard.keyup'>
512
519
  originEvent: Pick<
513
520
  KeyboardEvent,
514
521
  'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'
@@ -516,16 +523,10 @@ export type KeyboardBehaviorEvent =
516
523
  }
517
524
 
518
525
  export type MouseBehaviorEvent = {
519
- type: NativeBehaviorEventType<'mouse', 'click'>
526
+ type: StrictExtract<NativeBehaviorEventType, 'mouse.click'>
520
527
  position: EventPosition
521
528
  }
522
529
 
523
- function isMouseBehaviorEvent(
524
- event: BehaviorEvent,
525
- ): event is MouseBehaviorEvent {
526
- return event.type.startsWith('mouse.')
527
- }
528
-
529
530
  /**************************************
530
531
  * Custom events
531
532
  **************************************/
@@ -582,3 +583,6 @@ export type ResolveBehaviorEvent<
582
583
  : TBehaviorEventType extends BehaviorEvent['type']
583
584
  ? PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
584
585
  : never
586
+
587
+ type ExtractNamespace<TType extends string> =
588
+ TType extends `${infer Namespace}.${string}` ? Namespace : TType
@@ -144,12 +144,12 @@ export const Leaf = (props: LeafProps) => {
144
144
  return undefined
145
145
  }
146
146
 
147
- const onBlur = editorActor.on('blur', () => {
147
+ const onBlur = editorActor.on('blurred', () => {
148
148
  setFocused(false)
149
149
  setSelected(false)
150
150
  })
151
151
 
152
- const onFocus = editorActor.on('focus', () => {
152
+ const onFocus = editorActor.on('focused', () => {
153
153
  const sel = PortableTextEditor.getSelection(portableTextEditor)
154
154
  if (
155
155
  sel &&