@portabletext/editor 1.58.0 → 2.0.0-canary.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.
@@ -1,998 +1,2 @@
1
- import type {
2
- Path,
3
- PortableTextBlock,
4
- PortableTextObject,
5
- PortableTextTextBlock,
6
- } from '@sanity/types'
7
-
8
- declare type AbstractBehaviorEvent =
9
- | {
10
- type: StrictExtract<SyntheticBehaviorEventType, 'annotation.set'>
11
- at: AnnotationPath
12
- props: Record<string, unknown>
13
- }
14
- | {
15
- type: StrictExtract<SyntheticBehaviorEventType, 'annotation.toggle'>
16
- annotation: {
17
- name: string
18
- value: {
19
- [prop: string]: unknown
20
- }
21
- }
22
- }
23
- | {
24
- type: StrictExtract<SyntheticBehaviorEventType, 'decorator.toggle'>
25
- decorator: string
26
- at?: {
27
- anchor: BlockOffset
28
- focus: BlockOffset
29
- }
30
- }
31
- | {
32
- type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>
33
- unit: 'character' | 'word' | 'line' | 'block'
34
- }
35
- | {
36
- type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
37
- at: BlockPath
38
- }
39
- | {
40
- type: StrictExtract<SyntheticBehaviorEventType, 'delete.child'>
41
- at: ChildPath
42
- }
43
- | {
44
- type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
45
- unit: 'character' | 'word' | 'line' | 'block'
46
- }
47
- | {
48
- type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
49
- at: {
50
- anchor: BlockOffset
51
- focus: BlockOffset
52
- }
53
- }
54
- | {
55
- type: StrictExtract<SyntheticBehaviorEventType, 'deserialize'>
56
- originEvent:
57
- | PickFromUnion<
58
- NativeBehaviorEvent,
59
- 'type',
60
- 'drag.drop' | 'clipboard.paste'
61
- >
62
- | InputBehaviorEvent
63
- }
64
- | {
65
- type: StrictExtract<SyntheticBehaviorEventType, 'serialize'>
66
- originEvent: PickFromUnion<
67
- NativeBehaviorEvent,
68
- 'type',
69
- 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
70
- >
71
- }
72
- | {
73
- type: StrictExtract<SyntheticBehaviorEventType, 'deserialization.success'>
74
- mimeType: MIMEType
75
- data: Array<PortableTextBlock>
76
- originEvent:
77
- | PickFromUnion<
78
- NativeBehaviorEvent,
79
- 'type',
80
- 'drag.drop' | 'clipboard.paste'
81
- >
82
- | InputBehaviorEvent
83
- }
84
- | {
85
- type: StrictExtract<SyntheticBehaviorEventType, 'deserialization.failure'>
86
- mimeType: MIMEType
87
- reason: string
88
- originEvent:
89
- | PickFromUnion<
90
- NativeBehaviorEvent,
91
- 'type',
92
- 'drag.drop' | 'clipboard.paste'
93
- >
94
- | InputBehaviorEvent
95
- }
96
- | {
97
- type: StrictExtract<SyntheticBehaviorEventType, 'serialization.success'>
98
- mimeType: MIMEType
99
- data: string
100
- originEvent: PickFromUnion<
101
- NativeBehaviorEvent,
102
- 'type',
103
- 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
104
- >
105
- }
106
- | {
107
- type: StrictExtract<SyntheticBehaviorEventType, 'serialization.failure'>
108
- mimeType: MIMEType
109
- reason: string
110
- originEvent: PickFromUnion<
111
- NativeBehaviorEvent,
112
- 'type',
113
- 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
114
- >
115
- }
116
- | {
117
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
118
- blocks: Array<BlockWithOptionalKey>
119
- placement: InsertPlacement
120
- select?: 'start' | 'end' | 'none'
121
- }
122
- | {
123
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>
124
- }
125
- | {
126
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.soft break'>
127
- }
128
- | {
129
- type: StrictExtract<SyntheticBehaviorEventType, 'list item.add'>
130
- listItem: string
131
- }
132
- | {
133
- type: StrictExtract<SyntheticBehaviorEventType, 'list item.remove'>
134
- listItem: string
135
- }
136
- | {
137
- type: StrictExtract<SyntheticBehaviorEventType, 'list item.toggle'>
138
- listItem: string
139
- }
140
- | {
141
- type: StrictExtract<SyntheticBehaviorEventType, 'move.block down'>
142
- at: BlockPath
143
- }
144
- | {
145
- type: StrictExtract<SyntheticBehaviorEventType, 'move.block up'>
146
- at: BlockPath
147
- }
148
- | {
149
- type: StrictExtract<SyntheticBehaviorEventType, 'select.previous block'>
150
- select?: 'start' | 'end'
151
- }
152
- | {
153
- type: StrictExtract<SyntheticBehaviorEventType, 'select.next block'>
154
- select?: 'start' | 'end'
155
- }
156
- | {
157
- type: StrictExtract<SyntheticBehaviorEventType, 'split'>
158
- }
159
- | {
160
- type: StrictExtract<SyntheticBehaviorEventType, 'style.add'>
161
- style: string
162
- }
163
- | {
164
- type: StrictExtract<SyntheticBehaviorEventType, 'style.remove'>
165
- style: string
166
- }
167
- | {
168
- type: StrictExtract<SyntheticBehaviorEventType, 'style.toggle'>
169
- style: string
170
- }
171
-
172
- /**************************************
173
- * Abstract events
174
- **************************************/
175
- declare const abstractBehaviorEventTypes: readonly [
176
- 'annotation.set',
177
- 'annotation.toggle',
178
- 'decorator.toggle',
179
- 'delete.backward',
180
- 'delete.block',
181
- 'delete.child',
182
- 'delete.forward',
183
- 'delete.text',
184
- 'deserialize',
185
- 'deserialization.success',
186
- 'deserialization.failure',
187
- 'insert.blocks',
188
- 'insert.break',
189
- 'insert.soft break',
190
- 'list item.add',
191
- 'list item.remove',
192
- 'list item.toggle',
193
- 'move.block down',
194
- 'move.block up',
195
- 'select.previous block',
196
- 'select.next block',
197
- 'serialize',
198
- 'serialization.success',
199
- 'serialization.failure',
200
- 'split',
201
- 'style.add',
202
- 'style.remove',
203
- 'style.toggle',
204
- ]
205
-
206
- /**
207
- * @public
208
- */
209
- declare type AnnotationPath = [
210
- {
211
- _key: string
212
- },
213
- 'markDefs',
214
- {
215
- _key: string
216
- },
217
- ]
218
-
219
- /**
220
- * @public
221
- */
222
- declare type AnnotationSchemaType = BaseDefinition & {
223
- fields: ReadonlyArray<FieldDefinition>
224
- }
225
-
226
- /**
227
- * @public
228
- */
229
- declare type BaseDefinition = {
230
- name: string
231
- title?: string
232
- }
233
-
234
- /**
235
- * @beta
236
- */
237
- export declare type Behavior<
238
- TBehaviorEventType extends
239
- | '*'
240
- | `${BehaviorEventTypeNamespace}.*`
241
- | BehaviorEvent['type'] =
242
- | '*'
243
- | `${BehaviorEventTypeNamespace}.*`
244
- | BehaviorEvent['type'],
245
- TGuardResponse = true,
246
- TBehaviorEvent extends
247
- ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>,
248
- > = {
249
- /**
250
- * Editor Event that triggers this Behavior.
251
- */
252
- on: TBehaviorEventType
253
- /**
254
- * Predicate function that determines if the Behavior should be executed.
255
- * Returning a non-nullable value from the guard will pass the value to the
256
- * actions and execute them.
257
- */
258
- guard?: BehaviorGuard<TBehaviorEvent, TGuardResponse>
259
- /**
260
- * Array of Behavior Action sets.
261
- * Each set represents a step in the history stack.
262
- */
263
- actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
264
- }
265
-
266
- /**
267
- * @beta
268
- */
269
- export declare type BehaviorAction =
270
- | {
271
- type: 'execute'
272
- event: SyntheticBehaviorEvent
273
- }
274
- | {
275
- type: 'forward'
276
- event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent
277
- }
278
- | {
279
- type: 'raise'
280
- event: SyntheticBehaviorEvent | CustomBehaviorEvent
281
- }
282
- | {
283
- type: 'effect'
284
- effect: () => void
285
- }
286
-
287
- /**
288
- * @beta
289
- */
290
- export declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
291
- payload: {
292
- snapshot: EditorSnapshot
293
- event: TBehaviorEvent
294
- dom: EditorDom
295
- },
296
- guardResponse: TGuardResponse,
297
- ) => Array<BehaviorAction>
298
-
299
- /**
300
- * @beta
301
- */
302
- export declare type BehaviorEvent =
303
- | SyntheticBehaviorEvent
304
- | NativeBehaviorEvent
305
- | CustomBehaviorEvent
306
-
307
- declare type BehaviorEventTypeNamespace =
308
- | SyntheticBehaviorEventNamespace
309
- | NativeBehaviorEventNamespace
310
- | CustomBehaviorEventNamespace
311
-
312
- /**
313
- * @beta
314
- */
315
- export declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
316
- snapshot: EditorSnapshot
317
- event: TBehaviorEvent
318
- dom: EditorDom
319
- }) => TGuardResponse | false
320
-
321
- /**
322
- * @public
323
- */
324
- declare type BlockObjectSchemaType = BaseDefinition & {
325
- fields: ReadonlyArray<FieldDefinition>
326
- }
327
-
328
- /**
329
- * @beta
330
- */
331
- declare type BlockOffset = {
332
- path: BlockPath
333
- offset: number
334
- }
335
-
336
- /**
337
- * @public
338
- */
339
- declare type BlockPath = [
340
- {
341
- _key: string
342
- },
343
- ]
344
-
345
- declare type BlockWithOptionalKey =
346
- | TextBlockWithOptionalKey
347
- | ObjectBlockWithOptionalKey
348
-
349
- /**
350
- * @public
351
- */
352
- declare type ChildPath = [
353
- {
354
- _key: string
355
- },
356
- 'children',
357
- {
358
- _key: string
359
- },
360
- ]
361
-
362
- declare type ClipboardBehaviorEvent =
363
- | {
364
- type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
365
- originEvent: {
366
- dataTransfer: DataTransfer
367
- }
368
- position: Pick<EventPosition, 'selection'>
369
- }
370
- | {
371
- type: StrictExtract<NativeBehaviorEventType, 'clipboard.cut'>
372
- originEvent: {
373
- dataTransfer: DataTransfer
374
- }
375
- position: Pick<EventPosition, 'selection'>
376
- }
377
- | {
378
- type: StrictExtract<NativeBehaviorEventType, 'clipboard.paste'>
379
- originEvent: {
380
- dataTransfer: DataTransfer
381
- }
382
- position: Pick<EventPosition, 'selection'>
383
- }
384
-
385
- declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
386
- mimeType: TMIMEType
387
- serialize: Serializer<TMIMEType>
388
- deserialize: Deserializer<TMIMEType>
389
- }
390
-
391
- declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
392
- | {
393
- type: 'serialize'
394
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
395
- }
396
- | {
397
- type: 'serialization.failure'
398
- mimeType: TMIMEType
399
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
400
- reason: string
401
- }
402
- | {
403
- type: 'serialization.success'
404
- data: string
405
- mimeType: TMIMEType
406
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
407
- }
408
- | {
409
- type: 'deserialize'
410
- data: string
411
- }
412
- | {
413
- type: 'deserialization.failure'
414
- mimeType: TMIMEType
415
- reason: string
416
- }
417
- | {
418
- type: 'deserialization.success'
419
- data: Array<PortableTextBlock>
420
- mimeType: TMIMEType
421
- }
422
-
423
- /**
424
- * @beta
425
- */
426
- export declare type CustomBehaviorEvent<
427
- TPayload extends Record<string, unknown> = Record<string, unknown>,
428
- TType extends string = string,
429
- TInternalType extends CustomBehaviorEventType<
430
- 'custom',
431
- TType
432
- > = CustomBehaviorEventType<'custom', TType>,
433
- > = {
434
- type: TInternalType
435
- } & TPayload
436
-
437
- /**************************************
438
- * Custom events
439
- **************************************/
440
- declare type CustomBehaviorEventNamespace = 'custom'
441
-
442
- declare type CustomBehaviorEventType<
443
- TNamespace extends CustomBehaviorEventNamespace,
444
- TType extends string = '',
445
- > = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
446
-
447
- /**
448
- * @public
449
- */
450
- declare type DecoratorSchemaType = BaseDefinition & {
451
- /**
452
- * @deprecated
453
- * Use `name` instead
454
- */
455
- value: string
456
- }
457
-
458
- /**
459
- * @beta
460
- *
461
- * @example
462
- *
463
- * ```tsx
464
- * const noLowerCaseA = defineBehavior({
465
- * on: 'insert.text',
466
- * guard: ({event, snapshot}) => event.text === 'a',
467
- * actions: [({event, snapshot}) => [{type: 'insert.text', text: 'A'}]],
468
- * })
469
- * ```
470
- *
471
- */
472
- export declare function defineBehavior<
473
- TPayload extends Record<string, unknown>,
474
- TBehaviorEventType extends
475
- | '*'
476
- | `${BehaviorEventTypeNamespace}.*`
477
- | BehaviorEvent['type'] = CustomBehaviorEvent['type'],
478
- TGuardResponse = true,
479
- >(
480
- behavior: Behavior<
481
- TBehaviorEventType,
482
- TGuardResponse,
483
- ResolveBehaviorEvent<TBehaviorEventType, TPayload>
484
- >,
485
- ): Behavior
486
-
487
- declare type Deserializer<TMIMEType extends MIMEType> = ({
488
- snapshot,
489
- event,
490
- }: {
491
- snapshot: EditorSnapshot
492
- event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>
493
- }) => PickFromUnion<
494
- ConverterEvent<TMIMEType>,
495
- 'type',
496
- 'deserialization.success' | 'deserialization.failure'
497
- >
498
-
499
- declare type DragBehaviorEvent =
500
- | {
501
- type: StrictExtract<NativeBehaviorEventType, 'drag.dragstart'>
502
- originEvent: {
503
- clientX: number
504
- clientY: number
505
- dataTransfer: DataTransfer
506
- }
507
- position: Pick<EventPosition, 'selection'>
508
- }
509
- | {
510
- type: StrictExtract<NativeBehaviorEventType, 'drag.drag'>
511
- originEvent: {
512
- dataTransfer: DataTransfer
513
- }
514
- }
515
- | {
516
- type: StrictExtract<NativeBehaviorEventType, 'drag.dragend'>
517
- originEvent: {
518
- dataTransfer: DataTransfer
519
- }
520
- }
521
- | {
522
- type: StrictExtract<NativeBehaviorEventType, 'drag.dragenter'>
523
- originEvent: {
524
- dataTransfer: DataTransfer
525
- }
526
- position: EventPosition
527
- }
528
- | {
529
- type: StrictExtract<NativeBehaviorEventType, 'drag.dragover'>
530
- originEvent: {
531
- dataTransfer: DataTransfer
532
- }
533
- dragOrigin?: Pick<EventPosition, 'selection'>
534
- position: EventPosition
535
- }
536
- | {
537
- type: StrictExtract<NativeBehaviorEventType, 'drag.drop'>
538
- originEvent: {
539
- dataTransfer: DataTransfer
540
- }
541
- dragOrigin?: Pick<EventPosition, 'selection'>
542
- position: EventPosition
543
- }
544
- | {
545
- type: StrictExtract<NativeBehaviorEventType, 'drag.dragleave'>
546
- originEvent: {
547
- dataTransfer: DataTransfer
548
- }
549
- }
550
-
551
- /**
552
- * @public
553
- */
554
- declare type EditorContext = {
555
- converters: Array<Converter>
556
- keyGenerator: () => string
557
- readOnly: boolean
558
- schema: EditorSchema
559
- selection: EditorSelection
560
- value: Array<PortableTextBlock>
561
- }
562
-
563
- declare type EditorDom = {
564
- getBlockNodes: (snapshot: EditorSnapshot) => Array<Node>
565
- getChildNodes: (snapshot: EditorSnapshot) => Array<Node>
566
- /**
567
- * Let the Editor set the drag ghost. This is to be sure that it will get
568
- * properly removed again when the drag ends.
569
- */
570
- setDragGhost: ({
571
- event,
572
- ghost,
573
- }: {
574
- event: PickFromUnion<BehaviorEvent, 'type', 'drag.dragstart'>
575
- ghost: {
576
- element: HTMLElement
577
- x: number
578
- y: number
579
- }
580
- }) => void
581
- }
582
-
583
- /**
584
- * @public
585
- */
586
- declare type EditorSchema = {
587
- annotations: ReadonlyArray<AnnotationSchemaType>
588
- block: {
589
- name: string
590
- }
591
- blockObjects: ReadonlyArray<BlockObjectSchemaType>
592
- decorators: ReadonlyArray<DecoratorSchemaType>
593
- inlineObjects: ReadonlyArray<InlineObjectSchemaType>
594
- span: {
595
- name: string
596
- }
597
- styles: ReadonlyArray<StyleSchemaType>
598
- lists: ReadonlyArray<ListSchemaType>
599
- }
600
-
601
- /** @public */
602
- declare type EditorSelection = {
603
- anchor: EditorSelectionPoint
604
- focus: EditorSelectionPoint
605
- backward?: boolean
606
- } | null
607
-
608
- /** @public */
609
- declare type EditorSelectionPoint = {
610
- path: Path
611
- offset: number
612
- }
613
-
614
- /**
615
- * @public
616
- */
617
- declare type EditorSnapshot = {
618
- context: EditorContext
619
- blockIndexMap: Map<string, number>
620
- /**
621
- * @beta
622
- * Subject to change
623
- */
624
- decoratorState: Record<string, boolean | undefined>
625
- }
626
-
627
- /**
628
- * @beta
629
- */
630
- export declare function effect(
631
- effect: () => void,
632
- ): PickFromUnion<BehaviorAction, 'type', 'effect'>
633
-
634
- declare type EventPosition = {
635
- block: 'start' | 'end'
636
- /**
637
- * Did the event origin from the editor DOM node itself or from a child node?
638
- */
639
- isEditor: boolean
640
- selection: NonNullable<EditorSelection>
641
- }
642
-
643
- /**
644
- * @beta
645
- */
646
- export declare function execute(
647
- event: SyntheticBehaviorEvent,
648
- ): PickFromUnion<BehaviorAction, 'type', 'execute'>
649
-
650
- declare type ExtractNamespace<TType extends string> =
651
- TType extends `${infer Namespace}.${string}` ? Namespace : TType
652
-
653
- /**
654
- * @public
655
- */
656
- declare type FieldDefinition = BaseDefinition & {
657
- type: 'string' | 'number' | 'boolean' | 'array' | 'object'
658
- }
659
-
660
- /**
661
- * @beta
662
- */
663
- export declare function forward(
664
- event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent,
665
- ): PickFromUnion<BehaviorAction, 'type', 'forward'>
666
-
667
- /**
668
- * @public
669
- */
670
- declare type InlineObjectSchemaType = BaseDefinition & {
671
- fields: ReadonlyArray<FieldDefinition>
672
- }
673
-
674
- /**
675
- * Used to represent native InputEvents that hold a DataTransfer object.
676
- *
677
- * These can either be one of:
678
- *
679
- * - insertFromPaste
680
- * - insertFromPasteAsQuotation
681
- * - insertFromDrop
682
- * - insertReplacementText
683
- * - insertFromYank
684
- */
685
- declare type InputBehaviorEvent = {
686
- type: StrictExtract<NativeBehaviorEventType, 'input.*'>
687
- originEvent: {
688
- dataTransfer: DataTransfer
689
- }
690
- }
691
-
692
- /**
693
- * @beta
694
- */
695
- export declare type InsertPlacement = 'auto' | 'after' | 'before'
696
-
697
- declare type KeyboardBehaviorEvent =
698
- | {
699
- type: StrictExtract<NativeBehaviorEventType, 'keyboard.keydown'>
700
- originEvent: Pick<
701
- KeyboardEvent,
702
- 'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'
703
- >
704
- }
705
- | {
706
- type: StrictExtract<NativeBehaviorEventType, 'keyboard.keyup'>
707
- originEvent: Pick<
708
- KeyboardEvent,
709
- 'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'
710
- >
711
- }
712
-
713
- /**
714
- * @public
715
- */
716
- declare type ListSchemaType = BaseDefinition & {
717
- /**
718
- * @deprecated
719
- * Use `name` instead
720
- */
721
- value: string
722
- }
723
-
724
- declare type MIMEType = `${string}/${string}`
725
-
726
- declare type MouseBehaviorEvent = {
727
- type: StrictExtract<NativeBehaviorEventType, 'mouse.click'>
728
- position: EventPosition
729
- }
730
-
731
- declare type NamespacedBehaviorEventType<
732
- TNamespace extends BehaviorEventTypeNamespace | '',
733
- > = TNamespace extends ''
734
- ? BehaviorEvent['type']
735
- : Extract<BehaviorEvent['type'], TNamespace | `${TNamespace}.${string}`>
736
-
737
- /**
738
- * @beta
739
- */
740
- export declare type NativeBehaviorEvent =
741
- | ClipboardBehaviorEvent
742
- | DragBehaviorEvent
743
- | InputBehaviorEvent
744
- | KeyboardBehaviorEvent
745
- | MouseBehaviorEvent
746
-
747
- declare type NativeBehaviorEventNamespace =
748
- ExtractNamespace<NativeBehaviorEventType>
749
-
750
- declare type NativeBehaviorEventType = (typeof nativeBehaviorEventTypes)[number]
751
-
752
- /**************************************
753
- * Native events
754
- **************************************/
755
- declare const nativeBehaviorEventTypes: readonly [
756
- 'clipboard.copy',
757
- 'clipboard.cut',
758
- 'clipboard.paste',
759
- 'drag.dragstart',
760
- 'drag.drag',
761
- 'drag.dragend',
762
- 'drag.dragenter',
763
- 'drag.dragover',
764
- 'drag.dragleave',
765
- 'drag.drop',
766
- 'input.*',
767
- 'keyboard.keydown',
768
- 'keyboard.keyup',
769
- 'mouse.click',
770
- ]
771
-
772
- declare type ObjectBlockWithOptionalKey = Omit<PortableTextObject, '_key'> & {
773
- _key?: PortableTextObject['_key']
774
- }
775
-
776
- /**
777
- * @internal
778
- */
779
- declare type PickFromUnion<
780
- TUnion,
781
- TTagKey extends keyof TUnion,
782
- TPickedTags extends TUnion[TTagKey],
783
- > = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never
784
-
785
- /**
786
- * @beta
787
- */
788
- export declare function raise(
789
- event: SyntheticBehaviorEvent | CustomBehaviorEvent,
790
- ): PickFromUnion<BehaviorAction, 'type', 'raise'>
791
-
792
- /**************************************
793
- * Resolve behavior event
794
- **************************************/
795
- declare type ResolveBehaviorEvent<
796
- TBehaviorEventType extends
797
- | '*'
798
- | `${BehaviorEventTypeNamespace}.*`
799
- | BehaviorEvent['type'],
800
- TPayload extends Record<string, unknown> = Record<string, unknown>,
801
- > = TBehaviorEventType extends '*'
802
- ? BehaviorEvent
803
- : TBehaviorEventType extends `${infer TNamespace}.*`
804
- ? TNamespace extends BehaviorEventTypeNamespace
805
- ? PickFromUnion<
806
- BehaviorEvent,
807
- 'type',
808
- NamespacedBehaviorEventType<TNamespace>
809
- >
810
- : never
811
- : TBehaviorEventType extends `custom.${infer TType}`
812
- ? CustomBehaviorEvent<TPayload, TType>
813
- : TBehaviorEventType extends BehaviorEvent['type']
814
- ? PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
815
- : never
816
-
817
- declare type Serializer<TMIMEType extends MIMEType> = ({
818
- snapshot,
819
- event,
820
- }: {
821
- snapshot: EditorSnapshot
822
- event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialize'>
823
- }) => PickFromUnion<
824
- ConverterEvent<TMIMEType>,
825
- 'type',
826
- 'serialization.success' | 'serialization.failure'
827
- >
828
-
829
- declare type StrictExtract<T, U extends T> = U
830
-
831
- /**
832
- * @public
833
- */
834
- declare type StyleSchemaType = BaseDefinition & {
835
- /**
836
- * @deprecated
837
- * Use `name` instead
838
- */
839
- value: string
840
- }
841
-
842
- /**
843
- * @beta
844
- */
845
- export declare type SyntheticBehaviorEvent =
846
- | {
847
- type: StrictExtract<SyntheticBehaviorEventType, 'annotation.add'>
848
- annotation: {
849
- name: string
850
- value: {
851
- [prop: string]: unknown
852
- }
853
- }
854
- }
855
- | {
856
- type: StrictExtract<SyntheticBehaviorEventType, 'annotation.remove'>
857
- annotation: {
858
- name: string
859
- }
860
- }
861
- | {
862
- type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
863
- at: BlockPath
864
- props: Record<string, unknown>
865
- }
866
- | {
867
- type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
868
- at: BlockPath
869
- props: Array<string>
870
- }
871
- | {
872
- type: StrictExtract<SyntheticBehaviorEventType, 'child.set'>
873
- at: ChildPath
874
- props: {
875
- [prop: string]: unknown
876
- }
877
- }
878
- | {
879
- type: StrictExtract<SyntheticBehaviorEventType, 'child.unset'>
880
- at: ChildPath
881
- props: Array<string>
882
- }
883
- | {
884
- type: StrictExtract<SyntheticBehaviorEventType, 'decorator.add'>
885
- decorator: string
886
- at?: {
887
- anchor: BlockOffset
888
- focus: BlockOffset
889
- }
890
- }
891
- | {
892
- type: StrictExtract<SyntheticBehaviorEventType, 'decorator.remove'>
893
- decorator: string
894
- }
895
- | {
896
- type: StrictExtract<SyntheticBehaviorEventType, 'delete'>
897
- at: NonNullable<EditorSelection>
898
- /**
899
- * Defaults to forward deletion.
900
- */
901
- direction?: 'backward' | 'forward'
902
- /**
903
- * Defaults to character deletion.
904
- */
905
- unit?: 'character' | 'word' | 'line' | 'block'
906
- }
907
- | {
908
- type: StrictExtract<SyntheticBehaviorEventType, 'history.redo'>
909
- }
910
- | {
911
- type: StrictExtract<SyntheticBehaviorEventType, 'history.undo'>
912
- }
913
- | {
914
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.inline object'>
915
- inlineObject: {
916
- name: string
917
- value?: {
918
- [prop: string]: unknown
919
- }
920
- }
921
- }
922
- | {
923
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.block'>
924
- block: BlockWithOptionalKey
925
- placement: InsertPlacement
926
- select?: 'start' | 'end' | 'none'
927
- }
928
- | {
929
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.span'>
930
- text: string
931
- annotations?: Array<{
932
- name: string
933
- value: {
934
- [prop: string]: unknown
935
- }
936
- }>
937
- decorators?: Array<string>
938
- }
939
- | {
940
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
941
- text: string
942
- }
943
- | {
944
- type: StrictExtract<SyntheticBehaviorEventType, 'move.backward'>
945
- distance: number
946
- }
947
- | {
948
- type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
949
- at: BlockPath
950
- to: BlockPath
951
- }
952
- | {
953
- type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
954
- distance: number
955
- }
956
- | {
957
- type: StrictExtract<SyntheticBehaviorEventType, 'select'>
958
- at: EditorSelection
959
- }
960
- | AbstractBehaviorEvent
961
-
962
- declare type SyntheticBehaviorEventNamespace =
963
- ExtractNamespace<SyntheticBehaviorEventType>
964
-
965
- declare type SyntheticBehaviorEventType =
966
- | (typeof syntheticBehaviorEventTypes)[number]
967
- | (typeof abstractBehaviorEventTypes)[number]
968
-
969
- /**************************************
970
- * Synthetic events
971
- **************************************/
972
- declare const syntheticBehaviorEventTypes: readonly [
973
- 'annotation.add',
974
- 'annotation.remove',
975
- 'block.set',
976
- 'block.unset',
977
- 'child.set',
978
- 'child.unset',
979
- 'decorator.add',
980
- 'decorator.remove',
981
- 'delete',
982
- 'history.redo',
983
- 'history.undo',
984
- 'insert.inline object',
985
- 'insert.block',
986
- 'insert.span',
987
- 'insert.text',
988
- 'move.backward',
989
- 'move.block',
990
- 'move.forward',
991
- 'select',
992
- ]
993
-
994
- declare type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
995
- _key?: PortableTextTextBlock['_key']
996
- }
997
-
998
- export {}
1
+ import { Behavior, BehaviorAction, BehaviorActionSet, BehaviorEvent, BehaviorGuard, CustomBehaviorEvent, InsertPlacement, NativeBehaviorEvent, SyntheticBehaviorEvent, defineBehavior, effect, execute, forward, raise } from "../_chunks-dts/behavior.types.action.cjs";
2
+ export { Behavior, BehaviorAction, BehaviorActionSet, BehaviorEvent, BehaviorGuard, CustomBehaviorEvent, InsertPlacement, NativeBehaviorEvent, SyntheticBehaviorEvent, defineBehavior, effect, execute, forward, raise };