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