@portabletext/editor 1.1.4 → 1.1.6

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 (38) hide show
  1. package/README.md +4 -0
  2. package/lib/index.d.mts +631 -30
  3. package/lib/index.d.ts +631 -30
  4. package/lib/index.esm.js +303 -200
  5. package/lib/index.esm.js.map +1 -1
  6. package/lib/index.js +295 -192
  7. package/lib/index.js.map +1 -1
  8. package/lib/index.mjs +303 -200
  9. package/lib/index.mjs.map +1 -1
  10. package/package.json +30 -25
  11. package/src/editor/Editable.tsx +11 -11
  12. package/src/editor/PortableTextEditor.tsx +37 -32
  13. package/src/editor/__tests__/self-solving.test.tsx +1 -1
  14. package/src/editor/behavior/behavior.actions.ts +39 -0
  15. package/src/editor/behavior/behavior.core.ts +37 -0
  16. package/src/editor/behavior/behavior.types.ts +106 -0
  17. package/src/editor/behavior/behavior.utils.ts +34 -0
  18. package/src/editor/components/SlateContainer.tsx +2 -13
  19. package/src/editor/components/Synchronizer.tsx +0 -3
  20. package/src/editor/editor-machine.ts +120 -3
  21. package/src/editor/hooks/useSyncValue.ts +3 -5
  22. package/src/editor/key-generator.ts +6 -0
  23. package/src/editor/plugins/createWithEditableAPI.ts +8 -5
  24. package/src/editor/plugins/createWithHotKeys.ts +1 -32
  25. package/src/editor/plugins/createWithInsertBreak.ts +6 -2
  26. package/src/editor/plugins/createWithInsertData.ts +7 -4
  27. package/src/editor/plugins/createWithObjectKeys.ts +12 -5
  28. package/src/editor/plugins/createWithPatches.ts +0 -1
  29. package/src/editor/plugins/createWithPortableTextMarkModel.ts +85 -114
  30. package/src/editor/plugins/createWithSchemaTypes.ts +3 -4
  31. package/src/editor/plugins/createWithUtils.ts +5 -4
  32. package/src/editor/plugins/index.ts +5 -13
  33. package/src/index.ts +11 -2
  34. package/src/types/options.ts +0 -1
  35. package/src/utils/__tests__/operationToPatches.test.ts +0 -2
  36. package/src/utils/__tests__/patchToOperations.test.ts +1 -2
  37. package/src/utils/sibling-utils.ts +55 -0
  38. package/src/editor/hooks/usePortableTextEditorKeyGenerator.ts +0 -27
package/lib/index.d.mts CHANGED
@@ -27,7 +27,6 @@ import type {
27
27
  import {
28
28
  Component,
29
29
  ForwardRefExoticComponent,
30
- HTMLProps,
31
30
  JSX as JSX_2,
32
31
  MutableRefObject,
33
32
  PropsWithChildren,
@@ -40,16 +39,87 @@ import type {ReactEditor} from 'slate-react'
40
39
  import type {DOMNode} from 'slate-react/dist/utils/dom'
41
40
  import {
42
41
  ActionFunction,
42
+ ActorRef,
43
43
  ActorRefFrom,
44
44
  ActorRefFromLogic,
45
+ AnyActorLogic,
46
+ AnyActorRef,
47
+ AnyEventObject,
45
48
  CallbackActorLogic,
49
+ ConditionalRequired,
46
50
  EventObject,
51
+ GetConcreteByKey,
52
+ InputFrom,
53
+ IsNotNever,
54
+ MachineSnapshot,
47
55
  MetaObject,
48
56
  NonReducibleUnknown,
57
+ RequiredActorOptions,
49
58
  StateMachine,
59
+ StateValue,
50
60
  Values,
51
61
  } from 'xstate'
52
62
 
63
+ /**
64
+ * @alpha
65
+ */
66
+ export declare type Behavior<
67
+ TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
68
+ TGuardResponse = true,
69
+ > = {
70
+ on: TBehaviorEventType
71
+ guard?: BehaviorGuard<
72
+ PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>,
73
+ TGuardResponse
74
+ >
75
+ actions: Array<RaiseBehaviorActionIntend<TBehaviorEventType, TGuardResponse>>
76
+ }
77
+
78
+ /**
79
+ * @alpha
80
+ */
81
+ export declare type BehaviorActionIntend =
82
+ | {
83
+ type: 'insert text'
84
+ text: string
85
+ }
86
+ | {
87
+ type: 'insert text block'
88
+ decorators: Array<string>
89
+ }
90
+
91
+ /**
92
+ * @alpha
93
+ */
94
+ export declare type BehaviorContext = {
95
+ schema: PortableTextMemberSchemaTypes
96
+ value: Array<PortableTextBlock>
97
+ selection: NonNullable<EditorSelection>
98
+ }
99
+
100
+ /**
101
+ * @alpha
102
+ */
103
+ export declare type BehaviorEvent = {
104
+ type: 'key down'
105
+ nativeEvent: KeyboardEvent
106
+ editor: PortableTextSlateEditor
107
+ }
108
+
109
+ /**
110
+ * @alpha
111
+ */
112
+ export declare type BehaviorGuard<
113
+ TBehaviorEvent extends BehaviorEvent,
114
+ TGuardResponse,
115
+ > = ({
116
+ context,
117
+ event,
118
+ }: {
119
+ event: TBehaviorEvent
120
+ context: BehaviorContext
121
+ }) => TGuardResponse | false
122
+
53
123
  /** @beta */
54
124
  export declare interface BlockAnnotationRenderProps {
55
125
  block: PortableTextBlock
@@ -153,7 +223,6 @@ export declare type ConnectionChange = {
153
223
  * @internal
154
224
  */
155
225
  export declare type createEditorOptions = {
156
- keyGenerator: () => string
157
226
  patches$?: PatchObservable
158
227
  portableTextEditor: PortableTextEditor
159
228
  readOnly: boolean
@@ -265,8 +334,24 @@ export declare type EditorChanges = Subject<EditorChange>
265
334
  */
266
335
  export declare const editorMachine: StateMachine<
267
336
  {
337
+ behaviors: Array<Behavior>
338
+ keyGenerator: () => string
268
339
  pendingEvents: Array<PatchEvent | MutationEvent_2>
340
+ schema: PortableTextMemberSchemaTypes
269
341
  },
342
+ | BehaviorEvent
343
+ | ({
344
+ type: 'insert text'
345
+ text: string
346
+ } & {
347
+ editor: PortableTextSlateEditor
348
+ })
349
+ | ({
350
+ type: 'insert text block'
351
+ decorators: Array<string>
352
+ } & {
353
+ editor: PortableTextSlateEditor
354
+ })
270
355
  | PatchEvent
271
356
  | MutationEvent_2
272
357
  | {
@@ -275,6 +360,10 @@ export declare const editorMachine: StateMachine<
275
360
  | {
276
361
  type: 'done normalizing'
277
362
  }
363
+ | {
364
+ type: 'update schema'
365
+ schema: PortableTextMemberSchemaTypes
366
+ }
278
367
  | {
279
368
  type: 'ready'
280
369
  }
@@ -334,6 +423,18 @@ export declare const editorMachine: StateMachine<
334
423
  id: string | undefined
335
424
  },
336
425
  Values<{
426
+ 'apply:insert text': {
427
+ type: 'apply:insert text'
428
+ params: unknown
429
+ }
430
+ 'apply:insert text block': {
431
+ type: 'apply:insert text block'
432
+ params: unknown
433
+ }
434
+ 'assign schema': {
435
+ type: 'assign schema'
436
+ params: NonReducibleUnknown
437
+ }
337
438
  'emit patch event': {
338
439
  type: 'emit patch event'
339
440
  params: NonReducibleUnknown
@@ -354,6 +455,10 @@ export declare const editorMachine: StateMachine<
354
455
  type: 'clear pending events'
355
456
  params: NonReducibleUnknown
356
457
  }
458
+ 'handle behavior event': {
459
+ type: 'handle behavior event'
460
+ params: NonReducibleUnknown
461
+ }
357
462
  }>,
358
463
  never,
359
464
  never,
@@ -362,7 +467,11 @@ export declare const editorMachine: StateMachine<
362
467
  pristine: 'normalizing' | 'idle'
363
468
  },
364
469
  string,
365
- NonReducibleUnknown,
470
+ {
471
+ behaviors: Array<Behavior>
472
+ keyGenerator: () => string
473
+ schema: PortableTextMemberSchemaTypes
474
+ },
366
475
  NonReducibleUnknown,
367
476
  | PatchEvent
368
477
  | MutationEvent_2
@@ -415,8 +524,245 @@ export declare const editorMachine: StateMachine<
415
524
  MetaObject,
416
525
  {
417
526
  readonly id: 'editor'
418
- readonly context: {
419
- readonly pendingEvents: []
527
+ readonly context: ({
528
+ input,
529
+ }: {
530
+ spawn: {
531
+ <TSrc extends 'networkLogic'>(
532
+ logic: TSrc,
533
+ ...[options]: {
534
+ src: 'networkLogic'
535
+ logic: CallbackActorLogic<
536
+ EventObject,
537
+ NonReducibleUnknown,
538
+ EventObject
539
+ >
540
+ id: string | undefined
541
+ } extends infer T
542
+ ? T extends {
543
+ src: 'networkLogic'
544
+ logic: CallbackActorLogic<
545
+ EventObject,
546
+ NonReducibleUnknown,
547
+ EventObject
548
+ >
549
+ id: string | undefined
550
+ }
551
+ ? T extends {
552
+ src: TSrc
553
+ }
554
+ ? ConditionalRequired<
555
+ [
556
+ options?:
557
+ | ({
558
+ id?: T['id'] | undefined
559
+ systemId?: string
560
+ input?: InputFrom<T['logic']> | undefined
561
+ syncSnapshot?: boolean
562
+ } & {[K in RequiredActorOptions<T>]: unknown})
563
+ | undefined,
564
+ ],
565
+ IsNotNever<RequiredActorOptions<T>>
566
+ >
567
+ : never
568
+ : never
569
+ : never
570
+ ): ActorRefFromLogic<
571
+ GetConcreteByKey<
572
+ {
573
+ src: 'networkLogic'
574
+ logic: CallbackActorLogic<
575
+ EventObject,
576
+ NonReducibleUnknown,
577
+ EventObject
578
+ >
579
+ id: string | undefined
580
+ },
581
+ 'src',
582
+ TSrc
583
+ >['logic']
584
+ >
585
+ <TLogic extends AnyActorLogic>(
586
+ src: TLogic,
587
+ options?:
588
+ | {
589
+ id?: never
590
+ systemId?: string
591
+ input?: InputFrom<TLogic> | undefined
592
+ syncSnapshot?: boolean
593
+ }
594
+ | undefined,
595
+ ): ActorRefFromLogic<TLogic>
596
+ }
597
+ input: {
598
+ behaviors: Array<Behavior>
599
+ keyGenerator: () => string
600
+ schema: PortableTextMemberSchemaTypes
601
+ }
602
+ self: ActorRef<
603
+ MachineSnapshot<
604
+ {
605
+ behaviors: Array<Behavior>
606
+ keyGenerator: () => string
607
+ pendingEvents: Array<PatchEvent | MutationEvent_2>
608
+ schema: PortableTextMemberSchemaTypes
609
+ },
610
+ | BehaviorEvent
611
+ | ({
612
+ type: 'insert text'
613
+ text: string
614
+ } & {
615
+ editor: PortableTextSlateEditor
616
+ })
617
+ | ({
618
+ type: 'insert text block'
619
+ decorators: Array<string>
620
+ } & {
621
+ editor: PortableTextSlateEditor
622
+ })
623
+ | PatchEvent
624
+ | MutationEvent_2
625
+ | {
626
+ type: 'normalizing'
627
+ }
628
+ | {
629
+ type: 'done normalizing'
630
+ }
631
+ | {
632
+ type: 'update schema'
633
+ schema: PortableTextMemberSchemaTypes
634
+ }
635
+ | {
636
+ type: 'ready'
637
+ }
638
+ | {
639
+ type: 'unset'
640
+ previousValue: Array<PortableTextBlock>
641
+ }
642
+ | {
643
+ type: 'value changed'
644
+ value: Array<PortableTextBlock> | undefined
645
+ }
646
+ | {
647
+ type: 'invalid value'
648
+ resolution: InvalidValueResolution | null
649
+ value: Array<PortableTextBlock> | undefined
650
+ }
651
+ | {
652
+ type: 'error'
653
+ name: string
654
+ description: string
655
+ data: unknown
656
+ }
657
+ | {
658
+ type: 'selection'
659
+ selection: EditorSelection
660
+ }
661
+ | {
662
+ type: 'blur'
663
+ event: FocusEvent_2<HTMLDivElement, Element>
664
+ }
665
+ | {
666
+ type: 'focus'
667
+ event: FocusEvent_2<HTMLDivElement, Element>
668
+ }
669
+ | {
670
+ type: 'online'
671
+ }
672
+ | {
673
+ type: 'offline'
674
+ }
675
+ | {
676
+ type: 'loading'
677
+ }
678
+ | {
679
+ type: 'done loading'
680
+ },
681
+ Record<string, AnyActorRef | undefined>,
682
+ StateValue,
683
+ string,
684
+ unknown,
685
+ any,
686
+ any
687
+ >,
688
+ | BehaviorEvent
689
+ | ({
690
+ type: 'insert text'
691
+ text: string
692
+ } & {
693
+ editor: PortableTextSlateEditor
694
+ })
695
+ | ({
696
+ type: 'insert text block'
697
+ decorators: Array<string>
698
+ } & {
699
+ editor: PortableTextSlateEditor
700
+ })
701
+ | PatchEvent
702
+ | MutationEvent_2
703
+ | {
704
+ type: 'normalizing'
705
+ }
706
+ | {
707
+ type: 'done normalizing'
708
+ }
709
+ | {
710
+ type: 'update schema'
711
+ schema: PortableTextMemberSchemaTypes
712
+ }
713
+ | {
714
+ type: 'ready'
715
+ }
716
+ | {
717
+ type: 'unset'
718
+ previousValue: Array<PortableTextBlock>
719
+ }
720
+ | {
721
+ type: 'value changed'
722
+ value: Array<PortableTextBlock> | undefined
723
+ }
724
+ | {
725
+ type: 'invalid value'
726
+ resolution: InvalidValueResolution | null
727
+ value: Array<PortableTextBlock> | undefined
728
+ }
729
+ | {
730
+ type: 'error'
731
+ name: string
732
+ description: string
733
+ data: unknown
734
+ }
735
+ | {
736
+ type: 'selection'
737
+ selection: EditorSelection
738
+ }
739
+ | {
740
+ type: 'blur'
741
+ event: FocusEvent_2<HTMLDivElement, Element>
742
+ }
743
+ | {
744
+ type: 'focus'
745
+ event: FocusEvent_2<HTMLDivElement, Element>
746
+ }
747
+ | {
748
+ type: 'online'
749
+ }
750
+ | {
751
+ type: 'offline'
752
+ }
753
+ | {
754
+ type: 'loading'
755
+ }
756
+ | {
757
+ type: 'done loading'
758
+ },
759
+ AnyEventObject
760
+ >
761
+ }) => {
762
+ behaviors: Behavior[]
763
+ keyGenerator: () => string
764
+ pendingEvents: never[]
765
+ schema: PortableTextMemberSchemaTypes
420
766
  }
421
767
  readonly invoke: {
422
768
  readonly id: 'networkLogic'
@@ -426,11 +772,27 @@ export declare const editorMachine: StateMachine<
426
772
  readonly 'ready': {
427
773
  readonly actions: ActionFunction<
428
774
  {
775
+ behaviors: Array<Behavior>
776
+ keyGenerator: () => string
429
777
  pendingEvents: Array<PatchEvent | MutationEvent_2>
778
+ schema: PortableTextMemberSchemaTypes
430
779
  },
431
780
  {
432
781
  type: 'ready'
433
782
  },
783
+ | BehaviorEvent
784
+ | ({
785
+ type: 'insert text'
786
+ text: string
787
+ } & {
788
+ editor: PortableTextSlateEditor
789
+ })
790
+ | ({
791
+ type: 'insert text block'
792
+ decorators: Array<string>
793
+ } & {
794
+ editor: PortableTextSlateEditor
795
+ })
434
796
  | PatchEvent
435
797
  | MutationEvent_2
436
798
  | {
@@ -439,6 +801,10 @@ export declare const editorMachine: StateMachine<
439
801
  | {
440
802
  type: 'done normalizing'
441
803
  }
804
+ | {
805
+ type: 'update schema'
806
+ schema: PortableTextMemberSchemaTypes
807
+ }
442
808
  | {
443
809
  type: 'ready'
444
810
  }
@@ -543,12 +909,28 @@ export declare const editorMachine: StateMachine<
543
909
  readonly 'unset': {
544
910
  readonly actions: ActionFunction<
545
911
  {
912
+ behaviors: Array<Behavior>
913
+ keyGenerator: () => string
546
914
  pendingEvents: Array<PatchEvent | MutationEvent_2>
915
+ schema: PortableTextMemberSchemaTypes
547
916
  },
548
917
  {
549
918
  type: 'unset'
550
919
  previousValue: Array<PortableTextBlock>
551
920
  },
921
+ | BehaviorEvent
922
+ | ({
923
+ type: 'insert text'
924
+ text: string
925
+ } & {
926
+ editor: PortableTextSlateEditor
927
+ })
928
+ | ({
929
+ type: 'insert text block'
930
+ decorators: Array<string>
931
+ } & {
932
+ editor: PortableTextSlateEditor
933
+ })
552
934
  | PatchEvent
553
935
  | MutationEvent_2
554
936
  | {
@@ -557,6 +939,10 @@ export declare const editorMachine: StateMachine<
557
939
  | {
558
940
  type: 'done normalizing'
559
941
  }
942
+ | {
943
+ type: 'update schema'
944
+ schema: PortableTextMemberSchemaTypes
945
+ }
560
946
  | {
561
947
  type: 'ready'
562
948
  }
@@ -661,12 +1047,28 @@ export declare const editorMachine: StateMachine<
661
1047
  readonly 'value changed': {
662
1048
  readonly actions: ActionFunction<
663
1049
  {
1050
+ behaviors: Array<Behavior>
1051
+ keyGenerator: () => string
664
1052
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1053
+ schema: PortableTextMemberSchemaTypes
665
1054
  },
666
1055
  {
667
1056
  type: 'value changed'
668
1057
  value: Array<PortableTextBlock> | undefined
669
1058
  },
1059
+ | BehaviorEvent
1060
+ | ({
1061
+ type: 'insert text'
1062
+ text: string
1063
+ } & {
1064
+ editor: PortableTextSlateEditor
1065
+ })
1066
+ | ({
1067
+ type: 'insert text block'
1068
+ decorators: Array<string>
1069
+ } & {
1070
+ editor: PortableTextSlateEditor
1071
+ })
670
1072
  | PatchEvent
671
1073
  | MutationEvent_2
672
1074
  | {
@@ -675,6 +1077,10 @@ export declare const editorMachine: StateMachine<
675
1077
  | {
676
1078
  type: 'done normalizing'
677
1079
  }
1080
+ | {
1081
+ type: 'update schema'
1082
+ schema: PortableTextMemberSchemaTypes
1083
+ }
678
1084
  | {
679
1085
  type: 'ready'
680
1086
  }
@@ -779,13 +1185,29 @@ export declare const editorMachine: StateMachine<
779
1185
  readonly 'invalid value': {
780
1186
  readonly actions: ActionFunction<
781
1187
  {
1188
+ behaviors: Array<Behavior>
1189
+ keyGenerator: () => string
782
1190
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1191
+ schema: PortableTextMemberSchemaTypes
783
1192
  },
784
1193
  {
785
1194
  type: 'invalid value'
786
1195
  resolution: InvalidValueResolution | null
787
1196
  value: Array<PortableTextBlock> | undefined
788
1197
  },
1198
+ | BehaviorEvent
1199
+ | ({
1200
+ type: 'insert text'
1201
+ text: string
1202
+ } & {
1203
+ editor: PortableTextSlateEditor
1204
+ })
1205
+ | ({
1206
+ type: 'insert text block'
1207
+ decorators: Array<string>
1208
+ } & {
1209
+ editor: PortableTextSlateEditor
1210
+ })
789
1211
  | PatchEvent
790
1212
  | MutationEvent_2
791
1213
  | {
@@ -794,6 +1216,10 @@ export declare const editorMachine: StateMachine<
794
1216
  | {
795
1217
  type: 'done normalizing'
796
1218
  }
1219
+ | {
1220
+ type: 'update schema'
1221
+ schema: PortableTextMemberSchemaTypes
1222
+ }
797
1223
  | {
798
1224
  type: 'ready'
799
1225
  }
@@ -898,7 +1324,10 @@ export declare const editorMachine: StateMachine<
898
1324
  readonly 'error': {
899
1325
  readonly actions: ActionFunction<
900
1326
  {
1327
+ behaviors: Array<Behavior>
1328
+ keyGenerator: () => string
901
1329
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1330
+ schema: PortableTextMemberSchemaTypes
902
1331
  },
903
1332
  {
904
1333
  type: 'error'
@@ -906,6 +1335,19 @@ export declare const editorMachine: StateMachine<
906
1335
  description: string
907
1336
  data: unknown
908
1337
  },
1338
+ | BehaviorEvent
1339
+ | ({
1340
+ type: 'insert text'
1341
+ text: string
1342
+ } & {
1343
+ editor: PortableTextSlateEditor
1344
+ })
1345
+ | ({
1346
+ type: 'insert text block'
1347
+ decorators: Array<string>
1348
+ } & {
1349
+ editor: PortableTextSlateEditor
1350
+ })
909
1351
  | PatchEvent
910
1352
  | MutationEvent_2
911
1353
  | {
@@ -914,6 +1356,10 @@ export declare const editorMachine: StateMachine<
914
1356
  | {
915
1357
  type: 'done normalizing'
916
1358
  }
1359
+ | {
1360
+ type: 'update schema'
1361
+ schema: PortableTextMemberSchemaTypes
1362
+ }
917
1363
  | {
918
1364
  type: 'ready'
919
1365
  }
@@ -1018,12 +1464,28 @@ export declare const editorMachine: StateMachine<
1018
1464
  readonly 'selection': {
1019
1465
  readonly actions: ActionFunction<
1020
1466
  {
1467
+ behaviors: Array<Behavior>
1468
+ keyGenerator: () => string
1021
1469
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1470
+ schema: PortableTextMemberSchemaTypes
1022
1471
  },
1023
1472
  {
1024
1473
  type: 'selection'
1025
1474
  selection: EditorSelection
1026
1475
  },
1476
+ | BehaviorEvent
1477
+ | ({
1478
+ type: 'insert text'
1479
+ text: string
1480
+ } & {
1481
+ editor: PortableTextSlateEditor
1482
+ })
1483
+ | ({
1484
+ type: 'insert text block'
1485
+ decorators: Array<string>
1486
+ } & {
1487
+ editor: PortableTextSlateEditor
1488
+ })
1027
1489
  | PatchEvent
1028
1490
  | MutationEvent_2
1029
1491
  | {
@@ -1032,6 +1494,10 @@ export declare const editorMachine: StateMachine<
1032
1494
  | {
1033
1495
  type: 'done normalizing'
1034
1496
  }
1497
+ | {
1498
+ type: 'update schema'
1499
+ schema: PortableTextMemberSchemaTypes
1500
+ }
1035
1501
  | {
1036
1502
  type: 'ready'
1037
1503
  }
@@ -1136,12 +1602,28 @@ export declare const editorMachine: StateMachine<
1136
1602
  readonly 'blur': {
1137
1603
  readonly actions: ActionFunction<
1138
1604
  {
1605
+ behaviors: Array<Behavior>
1606
+ keyGenerator: () => string
1139
1607
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1608
+ schema: PortableTextMemberSchemaTypes
1140
1609
  },
1141
1610
  {
1142
1611
  type: 'blur'
1143
1612
  event: FocusEvent_2<HTMLDivElement, Element>
1144
1613
  },
1614
+ | BehaviorEvent
1615
+ | ({
1616
+ type: 'insert text'
1617
+ text: string
1618
+ } & {
1619
+ editor: PortableTextSlateEditor
1620
+ })
1621
+ | ({
1622
+ type: 'insert text block'
1623
+ decorators: Array<string>
1624
+ } & {
1625
+ editor: PortableTextSlateEditor
1626
+ })
1145
1627
  | PatchEvent
1146
1628
  | MutationEvent_2
1147
1629
  | {
@@ -1150,6 +1632,10 @@ export declare const editorMachine: StateMachine<
1150
1632
  | {
1151
1633
  type: 'done normalizing'
1152
1634
  }
1635
+ | {
1636
+ type: 'update schema'
1637
+ schema: PortableTextMemberSchemaTypes
1638
+ }
1153
1639
  | {
1154
1640
  type: 'ready'
1155
1641
  }
@@ -1254,12 +1740,28 @@ export declare const editorMachine: StateMachine<
1254
1740
  readonly 'focus': {
1255
1741
  readonly actions: ActionFunction<
1256
1742
  {
1743
+ behaviors: Array<Behavior>
1744
+ keyGenerator: () => string
1257
1745
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1746
+ schema: PortableTextMemberSchemaTypes
1258
1747
  },
1259
1748
  {
1260
1749
  type: 'focus'
1261
1750
  event: FocusEvent_2<HTMLDivElement, Element>
1262
1751
  },
1752
+ | BehaviorEvent
1753
+ | ({
1754
+ type: 'insert text'
1755
+ text: string
1756
+ } & {
1757
+ editor: PortableTextSlateEditor
1758
+ })
1759
+ | ({
1760
+ type: 'insert text block'
1761
+ decorators: Array<string>
1762
+ } & {
1763
+ editor: PortableTextSlateEditor
1764
+ })
1263
1765
  | PatchEvent
1264
1766
  | MutationEvent_2
1265
1767
  | {
@@ -1268,6 +1770,10 @@ export declare const editorMachine: StateMachine<
1268
1770
  | {
1269
1771
  type: 'done normalizing'
1270
1772
  }
1773
+ | {
1774
+ type: 'update schema'
1775
+ schema: PortableTextMemberSchemaTypes
1776
+ }
1271
1777
  | {
1272
1778
  type: 'ready'
1273
1779
  }
@@ -1372,11 +1878,27 @@ export declare const editorMachine: StateMachine<
1372
1878
  readonly 'online': {
1373
1879
  readonly actions: ActionFunction<
1374
1880
  {
1881
+ behaviors: Array<Behavior>
1882
+ keyGenerator: () => string
1375
1883
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1884
+ schema: PortableTextMemberSchemaTypes
1376
1885
  },
1377
1886
  {
1378
1887
  type: 'online'
1379
1888
  },
1889
+ | BehaviorEvent
1890
+ | ({
1891
+ type: 'insert text'
1892
+ text: string
1893
+ } & {
1894
+ editor: PortableTextSlateEditor
1895
+ })
1896
+ | ({
1897
+ type: 'insert text block'
1898
+ decorators: Array<string>
1899
+ } & {
1900
+ editor: PortableTextSlateEditor
1901
+ })
1380
1902
  | PatchEvent
1381
1903
  | MutationEvent_2
1382
1904
  | {
@@ -1385,6 +1907,10 @@ export declare const editorMachine: StateMachine<
1385
1907
  | {
1386
1908
  type: 'done normalizing'
1387
1909
  }
1910
+ | {
1911
+ type: 'update schema'
1912
+ schema: PortableTextMemberSchemaTypes
1913
+ }
1388
1914
  | {
1389
1915
  type: 'ready'
1390
1916
  }
@@ -1489,11 +2015,27 @@ export declare const editorMachine: StateMachine<
1489
2015
  readonly 'offline': {
1490
2016
  readonly actions: ActionFunction<
1491
2017
  {
2018
+ behaviors: Array<Behavior>
2019
+ keyGenerator: () => string
1492
2020
  pendingEvents: Array<PatchEvent | MutationEvent_2>
2021
+ schema: PortableTextMemberSchemaTypes
1493
2022
  },
1494
2023
  {
1495
2024
  type: 'offline'
1496
2025
  },
2026
+ | BehaviorEvent
2027
+ | ({
2028
+ type: 'insert text'
2029
+ text: string
2030
+ } & {
2031
+ editor: PortableTextSlateEditor
2032
+ })
2033
+ | ({
2034
+ type: 'insert text block'
2035
+ decorators: Array<string>
2036
+ } & {
2037
+ editor: PortableTextSlateEditor
2038
+ })
1497
2039
  | PatchEvent
1498
2040
  | MutationEvent_2
1499
2041
  | {
@@ -1502,6 +2044,10 @@ export declare const editorMachine: StateMachine<
1502
2044
  | {
1503
2045
  type: 'done normalizing'
1504
2046
  }
2047
+ | {
2048
+ type: 'update schema'
2049
+ schema: PortableTextMemberSchemaTypes
2050
+ }
1505
2051
  | {
1506
2052
  type: 'ready'
1507
2053
  }
@@ -1606,11 +2152,27 @@ export declare const editorMachine: StateMachine<
1606
2152
  readonly 'loading': {
1607
2153
  readonly actions: ActionFunction<
1608
2154
  {
2155
+ behaviors: Array<Behavior>
2156
+ keyGenerator: () => string
1609
2157
  pendingEvents: Array<PatchEvent | MutationEvent_2>
2158
+ schema: PortableTextMemberSchemaTypes
1610
2159
  },
1611
2160
  {
1612
2161
  type: 'loading'
1613
2162
  },
2163
+ | BehaviorEvent
2164
+ | ({
2165
+ type: 'insert text'
2166
+ text: string
2167
+ } & {
2168
+ editor: PortableTextSlateEditor
2169
+ })
2170
+ | ({
2171
+ type: 'insert text block'
2172
+ decorators: Array<string>
2173
+ } & {
2174
+ editor: PortableTextSlateEditor
2175
+ })
1614
2176
  | PatchEvent
1615
2177
  | MutationEvent_2
1616
2178
  | {
@@ -1619,6 +2181,10 @@ export declare const editorMachine: StateMachine<
1619
2181
  | {
1620
2182
  type: 'done normalizing'
1621
2183
  }
2184
+ | {
2185
+ type: 'update schema'
2186
+ schema: PortableTextMemberSchemaTypes
2187
+ }
1622
2188
  | {
1623
2189
  type: 'ready'
1624
2190
  }
@@ -1723,11 +2289,27 @@ export declare const editorMachine: StateMachine<
1723
2289
  readonly 'done loading': {
1724
2290
  readonly actions: ActionFunction<
1725
2291
  {
2292
+ behaviors: Array<Behavior>
2293
+ keyGenerator: () => string
1726
2294
  pendingEvents: Array<PatchEvent | MutationEvent_2>
2295
+ schema: PortableTextMemberSchemaTypes
1727
2296
  },
1728
2297
  {
1729
2298
  type: 'done loading'
1730
2299
  },
2300
+ | BehaviorEvent
2301
+ | ({
2302
+ type: 'insert text'
2303
+ text: string
2304
+ } & {
2305
+ editor: PortableTextSlateEditor
2306
+ })
2307
+ | ({
2308
+ type: 'insert text block'
2309
+ decorators: Array<string>
2310
+ } & {
2311
+ editor: PortableTextSlateEditor
2312
+ })
1731
2313
  | PatchEvent
1732
2314
  | MutationEvent_2
1733
2315
  | {
@@ -1736,6 +2318,10 @@ export declare const editorMachine: StateMachine<
1736
2318
  | {
1737
2319
  type: 'done normalizing'
1738
2320
  }
2321
+ | {
2322
+ type: 'update schema'
2323
+ schema: PortableTextMemberSchemaTypes
2324
+ }
1739
2325
  | {
1740
2326
  type: 'ready'
1741
2327
  }
@@ -1837,6 +2423,18 @@ export declare const editorMachine: StateMachine<
1837
2423
  }
1838
2424
  >
1839
2425
  }
2426
+ readonly 'update schema': {
2427
+ readonly actions: 'assign schema'
2428
+ }
2429
+ readonly 'key down': {
2430
+ readonly actions: readonly ['handle behavior event']
2431
+ }
2432
+ readonly 'insert text': {
2433
+ readonly actions: readonly ['apply:insert text']
2434
+ }
2435
+ readonly 'insert text block': {
2436
+ readonly actions: readonly ['apply:insert text block']
2437
+ }
1840
2438
  }
1841
2439
  readonly initial: 'pristine'
1842
2440
  readonly states: {
@@ -2078,35 +2676,21 @@ export declare type PatchObservable = Observable<{
2078
2676
  snapshot: PortableTextBlock[] | undefined
2079
2677
  }>
2080
2678
 
2679
+ /**
2680
+ * @alpha
2681
+ */
2682
+ export declare type PickFromUnion<
2683
+ TUnion,
2684
+ TTagKey extends keyof TUnion,
2685
+ TPickedTags extends TUnion[TTagKey],
2686
+ > = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never
2687
+
2081
2688
  /**
2082
2689
  * @public
2083
2690
  */
2084
2691
  export declare const PortableTextEditable: ForwardRefExoticComponent<
2085
- Omit<
2086
- Omit<
2087
- TextareaHTMLAttributes<HTMLDivElement>,
2088
- 'onPaste' | 'onCopy' | 'onBeforeInput'
2089
- > & {
2090
- hotkeys?: HotkeyOptions
2091
- onBeforeInput?: (event: InputEvent) => void
2092
- onPaste?: OnPasteFn
2093
- onCopy?: OnCopyFn
2094
- ref: MutableRefObject<HTMLDivElement | null>
2095
- rangeDecorations?: RangeDecoration[]
2096
- renderAnnotation?: RenderAnnotationFunction
2097
- renderBlock?: RenderBlockFunction
2098
- renderChild?: RenderChildFunction
2099
- renderDecorator?: RenderDecoratorFunction
2100
- renderListItem?: RenderListItemFunction
2101
- renderPlaceholder?: RenderPlaceholderFunction
2102
- renderStyle?: RenderStyleFunction
2103
- scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
2104
- selection?: EditorSelection
2105
- spellCheck?: boolean
2106
- } & Omit<HTMLProps<HTMLDivElement>, 'onPaste' | 'onBeforeInput' | 'as'>,
2107
- 'ref'
2108
- > &
2109
- RefAttributes<HTMLDivElement>
2692
+ Omit<PortableTextEditableProps, 'ref'> &
2693
+ RefAttributes<Omit<HTMLDivElement, 'onPaste' | 'onBeforeInput' | 'as'>>
2110
2694
  >
2111
2695
 
2112
2696
  /**
@@ -2447,6 +3031,23 @@ export declare interface PortableTextSlateEditor extends ReactEditor {
2447
3031
  redo: () => void
2448
3032
  }
2449
3033
 
3034
+ /**
3035
+ * @alpha
3036
+ */
3037
+ export declare type RaiseBehaviorActionIntend<
3038
+ TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
3039
+ TGuardResponse = true,
3040
+ > = (
3041
+ {
3042
+ context,
3043
+ event,
3044
+ }: {
3045
+ context: BehaviorContext
3046
+ event: PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
3047
+ },
3048
+ guardResponse: TGuardResponse,
3049
+ ) => BehaviorActionIntend | void
3050
+
2450
3051
  /**
2451
3052
  * A range decoration is a UI affordance that wraps a given selection range in the editor
2452
3053
  * with a custom component. This can be used to highlight search results,