@portabletext/editor 1.40.2 → 1.40.3

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 (58) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +37 -16
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +22 -10
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/editor-provider.cjs +27 -67
  6. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +26 -0
  8. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -0
  9. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +1 -0
  10. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  11. package/lib/_chunks-es/behavior.core.js +37 -16
  12. package/lib/_chunks-es/behavior.core.js.map +1 -1
  13. package/lib/_chunks-es/behavior.markdown.js +22 -10
  14. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  15. package/lib/_chunks-es/editor-provider.js +27 -67
  16. package/lib/_chunks-es/editor-provider.js.map +1 -1
  17. package/lib/_chunks-es/util.merge-text-blocks.js +27 -0
  18. package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -0
  19. package/lib/_chunks-es/util.selection-point-to-block-offset.js +1 -0
  20. package/lib/behaviors/index.d.cts +3881 -5053
  21. package/lib/behaviors/index.d.ts +3881 -5053
  22. package/lib/index.d.cts +3402 -4440
  23. package/lib/index.d.ts +3402 -4440
  24. package/lib/plugins/index.cjs +9 -127
  25. package/lib/plugins/index.cjs.map +1 -1
  26. package/lib/plugins/index.d.cts +3404 -4441
  27. package/lib/plugins/index.d.ts +3404 -4441
  28. package/lib/plugins/index.js +11 -129
  29. package/lib/plugins/index.js.map +1 -1
  30. package/lib/selectors/index.d.cts +3401 -4440
  31. package/lib/selectors/index.d.ts +3401 -4440
  32. package/lib/utils/index.cjs +45 -4
  33. package/lib/utils/index.cjs.map +1 -1
  34. package/lib/utils/index.d.cts +3402 -4441
  35. package/lib/utils/index.d.ts +3402 -4441
  36. package/lib/utils/index.js +45 -3
  37. package/lib/utils/index.js.map +1 -1
  38. package/package.json +7 -7
  39. package/src/behavior-actions/behavior.action.delete.block.ts +2 -2
  40. package/src/behavior-actions/behavior.actions.ts +0 -18
  41. package/src/behaviors/behavior.core.block-objects.ts +57 -7
  42. package/src/behaviors/behavior.core.insert-break.ts +0 -4
  43. package/src/behaviors/behavior.default.ts +1 -1
  44. package/src/behaviors/behavior.markdown.ts +22 -10
  45. package/src/behaviors/behavior.types.ts +171 -138
  46. package/src/editor/create-editor.ts +2 -0
  47. package/src/editor/editor-machine.ts +28 -28
  48. package/src/editor/plugins/create-with-event-listeners.ts +15 -0
  49. package/src/editor/plugins/createWithEditableAPI.ts +4 -4
  50. package/src/plugins/plugin.one-line.tsx +10 -128
  51. package/src/types/block-with-optional-key.ts +13 -0
  52. package/src/utils/util.is-text-block.ts +4 -3
  53. package/lib/_chunks-cjs/util.split-text-block.cjs +0 -68
  54. package/lib/_chunks-cjs/util.split-text-block.cjs.map +0 -1
  55. package/lib/_chunks-es/util.split-text-block.js +0 -70
  56. package/lib/_chunks-es/util.split-text-block.js.map +0 -1
  57. package/src/behavior-actions/behavior.action.insert.block-object.ts +0 -20
  58. package/src/behavior-actions/behavior.action.insert.text-block.ts +0 -33
@@ -1,139 +1,175 @@
1
- import type {
2
- KeyedSegment,
3
- PortableTextBlock,
4
- PortableTextTextBlock,
5
- } from '@sanity/types'
1
+ import type {KeyedSegment, PortableTextBlock} from '@sanity/types'
6
2
  import type {TextUnit} from 'slate'
7
3
  import type {TextInsertTextOptions} from 'slate/dist/interfaces/transforms/text'
8
- import type {ConverterEvent} from '../converters/converter.types'
9
4
  import type {EditorContext, EditorSnapshot} from '../editor/editor-snapshot'
10
5
  import type {EventPosition} from '../internal-utils/event-position'
11
6
  import type {MIMEType} from '../internal-utils/mime-type'
12
7
  import type {OmitFromUnion, PickFromUnion} from '../type-utils'
13
8
  import type {BlockOffset} from '../types/block-offset'
9
+ import type {BlockWithOptionalKey} from '../types/block-with-optional-key'
14
10
  import type {EditorSelection, PortableTextSlateEditor} from '../types/editor'
15
11
 
12
+ export type BehaviorEventTypeNamespace =
13
+ | 'annotation'
14
+ | 'block'
15
+ | 'blur'
16
+ | 'clipboard'
17
+ | 'custom'
18
+ | 'data transfer'
19
+ | 'decorator'
20
+ | 'delete'
21
+ | 'deserialization'
22
+ | 'deserialize'
23
+ | 'drag'
24
+ | 'focus'
25
+ | 'history'
26
+ | 'input'
27
+ | 'insert'
28
+ | 'keyboard'
29
+ | 'list item'
30
+ | 'mouse'
31
+ | 'move'
32
+ | 'select'
33
+ | 'serialization'
34
+ | 'serialize'
35
+ | 'style'
36
+
37
+ export type BehaviorEventType<
38
+ TNamespace extends BehaviorEventTypeNamespace,
39
+ TType extends string = '',
40
+ > = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
41
+
42
+ export type NamespacedBehaviorEventType<
43
+ TNamespace extends BehaviorEventTypeNamespace | '',
44
+ > = TNamespace extends ''
45
+ ? BehaviorEvent['type']
46
+ : Extract<BehaviorEvent['type'], TNamespace | `${TNamespace}.${string}`>
47
+
48
+ /**
49
+ * @beta
50
+ */
51
+ export type ExternalBehaviorEvent = {
52
+ type: BehaviorEventType<'insert', 'block object'>
53
+ placement: InsertPlacement
54
+ blockObject: {
55
+ name: string
56
+ value?: {[prop: string]: unknown}
57
+ }
58
+ }
59
+
16
60
  /**
17
61
  * @beta
18
62
  */
19
63
  export type SyntheticBehaviorEvent =
20
64
  | {
21
- type: 'annotation.add'
65
+ type: BehaviorEventType<'annotation', 'add'>
22
66
  annotation: {
23
67
  name: string
24
68
  value: {[prop: string]: unknown}
25
69
  }
26
70
  }
27
71
  | {
28
- type: 'annotation.remove'
72
+ type: BehaviorEventType<'annotation', 'remove'>
29
73
  annotation: {
30
74
  name: string
31
75
  }
32
76
  }
33
77
  | {
34
- type: 'annotation.toggle'
78
+ type: BehaviorEventType<'annotation', 'toggle'>
35
79
  annotation: {
36
80
  name: string
37
81
  value: {[prop: string]: unknown}
38
82
  }
39
83
  }
40
84
  | {
41
- type: 'block.set'
85
+ type: BehaviorEventType<'block', 'set'>
42
86
  at: [KeyedSegment]
43
87
  props: Record<string, unknown>
44
88
  }
45
89
  | {
46
- type: 'block.unset'
90
+ type: BehaviorEventType<'block', 'unset'>
47
91
  at: [KeyedSegment]
48
92
  props: Array<string>
49
93
  }
50
94
  | {
51
- type: 'blur'
95
+ type: BehaviorEventType<'blur'>
52
96
  }
53
97
  | {
54
- type: 'data transfer.set'
98
+ type: BehaviorEventType<'data transfer', 'set'>
55
99
  data: string
56
100
  dataTransfer: DataTransfer
57
101
  mimeType: MIMEType
58
102
  }
59
103
  | {
60
- type: 'decorator.add'
104
+ type: BehaviorEventType<'decorator', 'add'>
61
105
  decorator: string
62
106
  offsets?: {anchor: BlockOffset; focus: BlockOffset}
63
107
  }
64
108
  | {
65
- type: 'decorator.remove'
109
+ type: BehaviorEventType<'decorator', 'remove'>
66
110
  decorator: string
67
111
  }
68
112
  | {
69
- type: 'decorator.toggle'
113
+ type: BehaviorEventType<'decorator', 'toggle'>
70
114
  decorator: string
71
115
  offsets?: {anchor: BlockOffset; focus: BlockOffset}
72
116
  }
73
117
  | {
74
- type: 'delete'
118
+ type: BehaviorEventType<'delete'>
75
119
  selection: NonNullable<EditorSelection>
76
120
  }
77
121
  | {
78
- type: 'delete.backward'
122
+ type: BehaviorEventType<'delete', 'backward'>
79
123
  unit: TextUnit
80
124
  }
81
125
  | {
82
- type: 'delete.block'
83
- blockPath: [KeyedSegment]
126
+ type: BehaviorEventType<'delete', 'block'>
127
+ at: [KeyedSegment]
84
128
  }
85
129
  | {
86
- type: 'delete.forward'
130
+ type: BehaviorEventType<'delete', 'forward'>
87
131
  unit: TextUnit
88
132
  }
89
133
  | {
90
- type: 'delete.text'
134
+ type: BehaviorEventType<'delete', 'text'>
91
135
  anchor: BlockOffset
92
136
  focus: BlockOffset
93
137
  }
94
138
  | {
95
- type: 'focus'
139
+ type: BehaviorEventType<'focus'>
96
140
  }
97
141
  | {
98
- type: 'history.redo'
142
+ type: BehaviorEventType<'history', 'redo'>
99
143
  }
100
144
  | {
101
- type: 'history.undo'
145
+ type: BehaviorEventType<'history', 'undo'>
102
146
  }
103
147
  | {
104
- type: 'insert.blocks'
148
+ type: BehaviorEventType<'insert', 'blocks'>
105
149
  blocks: Array<PortableTextBlock>
106
150
  placement: InsertPlacement
107
151
  }
108
152
  | {
109
- type: 'insert.block object'
110
- placement: InsertPlacement
111
- blockObject: {
112
- name: string
113
- value?: {[prop: string]: unknown}
114
- }
115
- }
116
- | {
117
- type: 'insert.inline object'
153
+ type: BehaviorEventType<'insert', 'inline object'>
118
154
  inlineObject: {
119
155
  name: string
120
156
  value?: {[prop: string]: unknown}
121
157
  }
122
158
  }
123
159
  | {
124
- type: 'insert.break'
160
+ type: BehaviorEventType<'insert', 'break'>
125
161
  }
126
162
  | {
127
- type: 'insert.soft break'
163
+ type: BehaviorEventType<'insert', 'soft break'>
128
164
  }
129
165
  | {
130
- type: 'insert.block'
131
- block: PortableTextBlock
166
+ type: BehaviorEventType<'insert', 'block'>
167
+ block: BlockWithOptionalKey
132
168
  placement: InsertPlacement
133
169
  select?: 'start' | 'end' | 'none'
134
170
  }
135
171
  | {
136
- type: 'insert.span'
172
+ type: BehaviorEventType<'insert', 'span'>
137
173
  text: string
138
174
  annotations?: Array<{
139
175
  name: string
@@ -142,71 +178,63 @@ export type SyntheticBehaviorEvent =
142
178
  decorators?: Array<string>
143
179
  }
144
180
  | {
145
- type: 'insert.text'
181
+ type: BehaviorEventType<'insert', 'text'>
146
182
  text: string
147
183
  options?: TextInsertTextOptions
148
184
  }
149
185
  | {
150
- type: 'insert.text block'
151
- placement: InsertPlacement
152
- textBlock?: {
153
- children?: PortableTextTextBlock['children']
154
- }
155
- }
156
- | {
157
- type: 'list item.add'
186
+ type: BehaviorEventType<'list item', 'add'>
158
187
  listItem: string
159
188
  }
160
189
  | {
161
- type: 'list item.remove'
190
+ type: BehaviorEventType<'list item', 'remove'>
162
191
  listItem: string
163
192
  }
164
193
  | {
165
- type: 'list item.toggle'
194
+ type: BehaviorEventType<'list item', 'toggle'>
166
195
  listItem: string
167
196
  }
168
197
  | {
169
- type: 'move.block'
198
+ type: BehaviorEventType<'move', 'block'>
170
199
  at: [KeyedSegment]
171
200
  to: [KeyedSegment]
172
201
  }
173
202
  | {
174
- type: 'move.block down'
203
+ type: BehaviorEventType<'move', 'block down'>
175
204
  at: [KeyedSegment]
176
205
  }
177
206
  | {
178
- type: 'move.block up'
207
+ type: BehaviorEventType<'move', 'block up'>
179
208
  at: [KeyedSegment]
180
209
  }
181
210
  | {
182
- type: 'select'
211
+ type: BehaviorEventType<'select'>
183
212
  selection: EditorSelection
184
213
  }
185
214
  | {
186
- type: 'select.previous block'
215
+ type: BehaviorEventType<'select', 'previous block'>
187
216
  select?: 'start' | 'end'
188
217
  }
189
218
  | {
190
- type: 'select.next block'
219
+ type: BehaviorEventType<'select', 'next block'>
191
220
  select?: 'start' | 'end'
192
221
  }
193
222
  | {
194
- type: 'style.add'
223
+ type: BehaviorEventType<'style', 'add'>
195
224
  style: string
196
225
  }
197
226
  | {
198
- type: 'style.remove'
227
+ type: BehaviorEventType<'style', 'remove'>
199
228
  style: string
200
229
  }
201
230
  | {
202
- type: 'style.toggle'
231
+ type: BehaviorEventType<'style', 'toggle'>
203
232
  style: string
204
233
  }
205
- | (PickFromUnion<
206
- ConverterEvent,
207
- 'type',
208
- 'deserialization.failure' | 'deserialization.success'
209
- > & {
234
+ | {
235
+ type: BehaviorEventType<'deserialization', 'success'>
236
+ mimeType: MIMEType
237
+ data: Array<PortableTextBlock>
210
238
  originEvent:
211
239
  | PickFromUnion<
212
240
  NativeBehaviorEvent,
@@ -214,9 +242,21 @@ export type SyntheticBehaviorEvent =
214
242
  'drag.drop' | 'clipboard.paste'
215
243
  >
216
244
  | InputBehaviorEvent
217
- })
245
+ }
218
246
  | {
219
- type: 'serialization.success'
247
+ type: BehaviorEventType<'deserialization', 'failure'>
248
+ mimeType: MIMEType
249
+ reason: string
250
+ originEvent:
251
+ | PickFromUnion<
252
+ NativeBehaviorEvent,
253
+ 'type',
254
+ 'drag.drop' | 'clipboard.paste'
255
+ >
256
+ | InputBehaviorEvent
257
+ }
258
+ | {
259
+ type: BehaviorEventType<'serialization', 'success'>
220
260
  mimeType: MIMEType
221
261
  data: string
222
262
  originEvent: PickFromUnion<
@@ -226,7 +266,7 @@ export type SyntheticBehaviorEvent =
226
266
  >
227
267
  }
228
268
  | {
229
- type: 'serialization.failure'
269
+ type: BehaviorEventType<'serialization', 'failure'>
230
270
  mimeType: MIMEType
231
271
  reason: string
232
272
  originEvent: PickFromUnion<
@@ -240,21 +280,21 @@ export type InsertPlacement = 'auto' | 'after' | 'before'
240
280
 
241
281
  type ClipboardBehaviorEvent =
242
282
  | {
243
- type: 'clipboard.copy'
283
+ type: BehaviorEventType<'clipboard', 'copy'>
244
284
  originEvent: {
245
285
  dataTransfer: DataTransfer
246
286
  }
247
287
  position: Pick<EventPosition, 'selection'>
248
288
  }
249
289
  | {
250
- type: 'clipboard.cut'
290
+ type: BehaviorEventType<'clipboard', 'cut'>
251
291
  originEvent: {
252
292
  dataTransfer: DataTransfer
253
293
  }
254
294
  position: Pick<EventPosition, 'selection'>
255
295
  }
256
296
  | {
257
- type: 'clipboard.paste'
297
+ type: BehaviorEventType<'clipboard', 'paste'>
258
298
  originEvent: {
259
299
  dataTransfer: DataTransfer
260
300
  }
@@ -269,47 +309,47 @@ export function isClipboardBehaviorEvent(
269
309
 
270
310
  type DragBehaviorEvent =
271
311
  | {
272
- type: 'drag.dragstart'
312
+ type: BehaviorEventType<'drag', 'dragstart'>
273
313
  originEvent: {
274
314
  dataTransfer: DataTransfer
275
315
  }
276
316
  position: Pick<EventPosition, 'selection'>
277
317
  }
278
318
  | {
279
- type: 'drag.drag'
319
+ type: BehaviorEventType<'drag', 'drag'>
280
320
  originEvent: {
281
321
  dataTransfer: DataTransfer
282
322
  }
283
323
  }
284
324
  | {
285
- type: 'drag.dragend'
325
+ type: BehaviorEventType<'drag', 'dragend'>
286
326
  originEvent: {
287
327
  dataTransfer: DataTransfer
288
328
  }
289
329
  }
290
330
  | {
291
- type: 'drag.dragenter'
331
+ type: BehaviorEventType<'drag', 'dragenter'>
292
332
  originEvent: {
293
333
  dataTransfer: DataTransfer
294
334
  }
295
335
  position: EventPosition
296
336
  }
297
337
  | {
298
- type: 'drag.dragover'
338
+ type: BehaviorEventType<'drag', 'dragover'>
299
339
  originEvent: {
300
340
  dataTransfer: DataTransfer
301
341
  }
302
342
  position: EventPosition
303
343
  }
304
344
  | {
305
- type: 'drag.drop'
345
+ type: BehaviorEventType<'drag', 'drop'>
306
346
  originEvent: {
307
347
  dataTransfer: DataTransfer
308
348
  }
309
349
  position: EventPosition
310
350
  }
311
351
  | {
312
- type: 'drag.dragleave'
352
+ type: BehaviorEventType<'drag', 'dragleave'>
313
353
  originEvent: {
314
354
  dataTransfer: DataTransfer
315
355
  }
@@ -333,7 +373,7 @@ export function isDragBehaviorEvent(
333
373
  * - insertFromYank
334
374
  */
335
375
  export type InputBehaviorEvent = {
336
- type: 'input.*'
376
+ type: BehaviorEventType<'input', '*'>
337
377
  originEvent: {
338
378
  dataTransfer: DataTransfer
339
379
  }
@@ -347,14 +387,14 @@ export function isInputBehaviorEvent(
347
387
 
348
388
  export type KeyboardBehaviorEvent =
349
389
  | {
350
- type: 'keyboard.keydown'
390
+ type: BehaviorEventType<'keyboard', 'keydown'>
351
391
  originEvent: Pick<
352
392
  KeyboardEvent,
353
393
  'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'
354
394
  >
355
395
  }
356
396
  | {
357
- type: 'keyboard.keyup'
397
+ type: BehaviorEventType<'keyboard', 'keyup'>
358
398
  originEvent: Pick<
359
399
  KeyboardEvent,
360
400
  'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'
@@ -369,7 +409,7 @@ export function isKeyboardBehaviorEvent(
369
409
 
370
410
  export type DataBehaviorEvent =
371
411
  | {
372
- type: 'deserialize'
412
+ type: BehaviorEventType<'deserialize'>
373
413
  originEvent:
374
414
  | PickFromUnion<
375
415
  NativeBehaviorEvent,
@@ -379,7 +419,7 @@ export type DataBehaviorEvent =
379
419
  | InputBehaviorEvent
380
420
  }
381
421
  | {
382
- type: 'serialize'
422
+ type: BehaviorEventType<'serialize'>
383
423
  originEvent: PickFromUnion<
384
424
  NativeBehaviorEvent,
385
425
  'type',
@@ -388,7 +428,7 @@ export type DataBehaviorEvent =
388
428
  }
389
429
 
390
430
  export type MouseBehaviorEvent = {
391
- type: 'mouse.click'
431
+ type: BehaviorEventType<'mouse', 'click'>
392
432
  position: EventPosition
393
433
  }
394
434
 
@@ -414,7 +454,10 @@ export type NativeBehaviorEvent =
414
454
  export type CustomBehaviorEvent<
415
455
  TPayload extends Record<string, unknown> = Record<string, unknown>,
416
456
  TType extends string = string,
417
- TInternalType extends `custom.${TType}` = `custom.${TType}`,
457
+ TInternalType extends BehaviorEventType<'custom', TType> = BehaviorEventType<
458
+ 'custom',
459
+ TType
460
+ >,
418
461
  > = {
419
462
  type: TInternalType
420
463
  } & TPayload
@@ -467,32 +510,43 @@ export type BehaviorEvent =
467
510
  | DataBehaviorEvent
468
511
  | NativeBehaviorEvent
469
512
  | CustomBehaviorEvent
470
- | {type: '*'}
471
- | {type: 'clipboard.*'}
472
- | {type: 'drag.*'}
473
- | {type: 'input.*'}
474
- | {type: 'keyboard.*'}
475
- | {type: 'mouse.*'}
513
+
514
+ type ResolveBehaviorEvent<
515
+ TBehaviorEventType extends
516
+ | '*'
517
+ | `${BehaviorEventTypeNamespace}.*`
518
+ | BehaviorEvent['type'],
519
+ TPayload extends Record<string, unknown> = Record<string, unknown>,
520
+ > = TBehaviorEventType extends '*'
521
+ ? BehaviorEvent
522
+ : TBehaviorEventType extends `${infer TNamespace}.*`
523
+ ? TNamespace extends BehaviorEventTypeNamespace
524
+ ? PickFromUnion<
525
+ BehaviorEvent,
526
+ 'type',
527
+ NamespacedBehaviorEventType<TNamespace>
528
+ >
529
+ : never
530
+ : TBehaviorEventType extends `custom.${infer TType}`
531
+ ? CustomBehaviorEvent<TPayload, TType>
532
+ : TBehaviorEventType extends BehaviorEvent['type']
533
+ ? PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
534
+ : never
476
535
 
477
536
  /**
478
537
  * @beta
479
538
  */
480
539
  export type Behavior<
481
- TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
540
+ TBehaviorEventType extends
541
+ | '*'
542
+ | `${BehaviorEventTypeNamespace}.*`
543
+ | BehaviorEvent['type'] =
544
+ | '*'
545
+ | `${BehaviorEventTypeNamespace}.*`
546
+ | BehaviorEvent['type'],
482
547
  TGuardResponse = true,
483
- TBehaviorEvent extends BehaviorEvent = TBehaviorEventType extends '*'
484
- ? BehaviorEvent
485
- : TBehaviorEventType extends 'clipboard.*'
486
- ? ClipboardBehaviorEvent
487
- : TBehaviorEventType extends 'drag.*'
488
- ? DragBehaviorEvent
489
- : TBehaviorEventType extends 'input.*'
490
- ? InputBehaviorEvent
491
- : TBehaviorEventType extends 'keyboard.*'
492
- ? KeyboardBehaviorEvent
493
- : TBehaviorEventType extends 'mouse.*'
494
- ? MouseBehaviorEvent
495
- : PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>,
548
+ TBehaviorEvent extends
549
+ ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>,
496
550
  > = {
497
551
  /**
498
552
  * The internal editor event that triggers this behavior.
@@ -560,49 +614,28 @@ export type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
560
614
  export function defineBehavior<
561
615
  TPayload extends Record<string, unknown>,
562
616
  TBehaviorEventType extends
563
- BehaviorEvent['type'] = CustomBehaviorEvent['type'],
617
+ | '*'
618
+ | `${BehaviorEventTypeNamespace}.*`
619
+ | BehaviorEvent['type'] = CustomBehaviorEvent['type'],
564
620
  TGuardResponse = true,
565
621
  >(
566
622
  behavior: Behavior<
567
623
  TBehaviorEventType,
568
624
  TGuardResponse,
569
- TBehaviorEventType extends `custom.${infer TType}`
570
- ? CustomBehaviorEvent<TPayload, TType>
571
- : TBehaviorEventType extends '*'
572
- ? OmitFromUnion<BehaviorEvent, 'type', '*'>
573
- : TBehaviorEventType extends `clipboard.*`
574
- ? ClipboardBehaviorEvent
575
- : TBehaviorEventType extends `drag.*`
576
- ? DragBehaviorEvent
577
- : TBehaviorEventType extends 'input.*'
578
- ? InputBehaviorEvent
579
- : TBehaviorEventType extends 'keyboard.*'
580
- ? KeyboardBehaviorEvent
581
- : TBehaviorEventType extends 'mouse.*'
582
- ? MouseBehaviorEvent
583
- : PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
625
+ ResolveBehaviorEvent<TBehaviorEventType, TPayload>
584
626
  >,
585
627
  ): Behavior
586
628
  export function defineBehavior<
587
629
  TPayload extends never = never,
588
- TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
630
+ TBehaviorEventType extends
631
+ | '*'
632
+ | `${BehaviorEventTypeNamespace}.*`
633
+ | BehaviorEvent['type'] = BehaviorEvent['type'],
589
634
  TGuardResponse = true,
590
- TBehaviorEvent extends
591
- BehaviorEvent = TBehaviorEventType extends `custom.${infer TType}`
592
- ? CustomBehaviorEvent<TPayload, TType>
593
- : TBehaviorEventType extends '*'
594
- ? OmitFromUnion<BehaviorEvent, 'type', '*'>
595
- : TBehaviorEventType extends `clipboard.*`
596
- ? ClipboardBehaviorEvent
597
- : TBehaviorEventType extends `drag.*`
598
- ? DragBehaviorEvent
599
- : TBehaviorEventType extends 'input.*'
600
- ? InputBehaviorEvent
601
- : TBehaviorEventType extends 'keyboard.*'
602
- ? KeyboardBehaviorEvent
603
- : TBehaviorEventType extends 'mouse.*'
604
- ? MouseBehaviorEvent
605
- : PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>,
635
+ TBehaviorEvent extends ResolveBehaviorEvent<
636
+ TBehaviorEventType,
637
+ TPayload
638
+ > = ResolveBehaviorEvent<TBehaviorEventType, TPayload>,
606
639
  >(
607
640
  behavior: Behavior<TBehaviorEventType, TGuardResponse, TBehaviorEvent>,
608
641
  ): Behavior {
@@ -14,6 +14,7 @@ import {
14
14
  import type {
15
15
  Behavior,
16
16
  CustomBehaviorEvent,
17
+ ExternalBehaviorEvent,
17
18
  SyntheticBehaviorEvent,
18
19
  } from '../behaviors/behavior.types'
19
20
  import {coreConverters} from '../converters/converters.core'
@@ -64,6 +65,7 @@ export type EditorConfig = {
64
65
  */
65
66
  export type EditorEvent =
66
67
  | ExternalEditorEvent
68
+ | ExternalBehaviorEvent
67
69
  | SyntheticBehaviorEvent
68
70
  | CustomBehaviorEvent
69
71