@portabletext/editor 1.1.9 → 1.1.11

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.
package/lib/index.d.ts CHANGED
@@ -6,6 +6,7 @@ import type {
6
6
  BlockListDefinition,
7
7
  BlockSchemaType,
8
8
  BlockStyleDefinition,
9
+ KeyedSegment,
9
10
  ObjectSchemaType,
10
11
  Path,
11
12
  PortableTextBlock,
@@ -15,11 +16,7 @@ import type {
15
16
  SpanSchemaType,
16
17
  TypedObject,
17
18
  } from '@sanity/types'
18
- import {
19
- KeyedSegment,
20
- PortableTextSpan,
21
- PortableTextTextBlock,
22
- } from '@sanity/types'
19
+ import {PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
23
20
  import type {
24
21
  BaseSyntheticEvent,
25
22
  ClipboardEvent as ClipboardEvent_2,
@@ -38,10 +35,12 @@ import {
38
35
  TextareaHTMLAttributes,
39
36
  } from 'react'
40
37
  import type {Observable, Subject} from 'rxjs'
41
- import type {Descendant, Node as Node_2, Operation} from 'slate'
38
+ import type {Descendant, Node as Node_2, Operation, TextUnit} from 'slate'
42
39
  import type {ReactEditor} from 'slate-react'
43
40
  import type {DOMNode} from 'slate-react/dist/utils/dom'
41
+ import type {TextInsertTextOptions} from 'slate/dist/interfaces/transforms/text'
44
42
  import {
43
+ ActionArgs,
45
44
  ActionFunction,
46
45
  ActorRef,
47
46
  ActorRefFrom,
@@ -71,35 +70,71 @@ export declare type Behavior<
71
70
  TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
72
71
  TGuardResponse = true,
73
72
  > = {
73
+ /**
74
+ * The internal editor event that triggers this behavior.
75
+ */
74
76
  on: TBehaviorEventType
77
+ /**
78
+ * Predicate function that determines if the behavior should be executed.
79
+ * Returning a non-nullable value from the guard will pass the value to the
80
+ * actions and execute them.
81
+ */
75
82
  guard?: BehaviorGuard<
76
83
  PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>,
77
84
  TGuardResponse
78
85
  >
79
- actions: Array<RaiseBehaviorActionIntend<TBehaviorEventType, TGuardResponse>>
86
+ /**
87
+ * Array of behavior action sets.
88
+ */
89
+ actions: Array<BehaviorActionIntendSet<TBehaviorEventType, TGuardResponse>>
80
90
  }
81
91
 
82
92
  /**
83
93
  * @alpha
84
94
  */
85
95
  export declare type BehaviorActionIntend =
86
- | {
87
- type: 'insert text'
88
- text: string
89
- }
96
+ | BehaviorEvent
90
97
  | {
91
98
  type: 'insert text block'
92
99
  decorators: Array<string>
93
100
  }
94
101
  | {
95
- type: 'apply block style'
102
+ type: 'set block'
103
+ paths: Array<[KeyedSegment]>
104
+ style?: string
105
+ listItem?: string
106
+ level?: number
107
+ }
108
+ | {
109
+ type: 'unset block'
96
110
  paths: Array<[KeyedSegment]>
97
- style: string
111
+ props: Array<'style' | 'listItem' | 'level'>
98
112
  }
99
113
  | {
100
114
  type: 'delete text'
101
115
  selection: NonNullable<EditorSelection>
102
116
  }
117
+ | {
118
+ type: 'effect'
119
+ effect: () => void
120
+ }
121
+
122
+ /**
123
+ * @alpha
124
+ */
125
+ export declare type BehaviorActionIntendSet<
126
+ TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
127
+ TGuardResponse = true,
128
+ > = (
129
+ {
130
+ context,
131
+ event,
132
+ }: {
133
+ context: BehaviorContext
134
+ event: PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
135
+ },
136
+ guardResponse: TGuardResponse,
137
+ ) => Array<BehaviorActionIntend>
103
138
 
104
139
  /**
105
140
  * @alpha
@@ -115,14 +150,19 @@ export declare type BehaviorContext = {
115
150
  */
116
151
  export declare type BehaviorEvent =
117
152
  | {
118
- type: 'key down'
119
- nativeEvent: KeyboardEvent
120
- editor: PortableTextSlateEditor
153
+ type: 'delete backward'
154
+ unit: TextUnit
121
155
  }
122
156
  | {
123
- type: 'before insert text'
124
- nativeEvent: InputEvent
125
- editor: PortableTextSlateEditor
157
+ type: 'insert soft break'
158
+ }
159
+ | {
160
+ type: 'insert break'
161
+ }
162
+ | {
163
+ type: 'insert text'
164
+ text: string
165
+ options?: TextInsertTextOptions
126
166
  }
127
167
 
128
168
  /**
@@ -359,41 +399,6 @@ export declare const editorMachine: StateMachine<
359
399
  pendingEvents: Array<PatchEvent | MutationEvent_2>
360
400
  schema: PortableTextMemberSchemaTypes
361
401
  },
362
- | ({
363
- type: 'insert text'
364
- text: string
365
- } & {
366
- editor: PortableTextSlateEditor
367
- })
368
- | ({
369
- type: 'insert text block'
370
- decorators: Array<string>
371
- } & {
372
- editor: PortableTextSlateEditor
373
- })
374
- | ({
375
- type: 'apply block style'
376
- paths: Array<[KeyedSegment]>
377
- style: string
378
- } & {
379
- editor: PortableTextSlateEditor
380
- })
381
- | ({
382
- type: 'delete text'
383
- selection: NonNullable<EditorSelection>
384
- } & {
385
- editor: PortableTextSlateEditor
386
- })
387
- | {
388
- type: 'key down'
389
- nativeEvent: KeyboardEvent
390
- editor: PortableTextSlateEditor
391
- }
392
- | {
393
- type: 'before insert text'
394
- nativeEvent: InputEvent
395
- editor: PortableTextSlateEditor
396
- }
397
402
  | PatchEvent
398
403
  | MutationEvent_2
399
404
  | {
@@ -402,6 +407,16 @@ export declare const editorMachine: StateMachine<
402
407
  | {
403
408
  type: 'done normalizing'
404
409
  }
410
+ | {
411
+ type: 'behavior event'
412
+ behaviorEvent: BehaviorEvent
413
+ editor: PortableTextSlateEditor
414
+ }
415
+ | {
416
+ type: 'behavior action intends'
417
+ editor: PortableTextSlateEditor
418
+ actionIntends: Array<BehaviorActionIntend>
419
+ }
405
420
  | {
406
421
  type: 'update schema'
407
422
  schema: PortableTextMemberSchemaTypes
@@ -641,41 +656,6 @@ export declare const editorMachine: StateMachine<
641
656
  pendingEvents: Array<PatchEvent | MutationEvent_2>
642
657
  schema: PortableTextMemberSchemaTypes
643
658
  },
644
- | ({
645
- type: 'insert text'
646
- text: string
647
- } & {
648
- editor: PortableTextSlateEditor
649
- })
650
- | ({
651
- type: 'insert text block'
652
- decorators: Array<string>
653
- } & {
654
- editor: PortableTextSlateEditor
655
- })
656
- | ({
657
- type: 'apply block style'
658
- paths: Array<[KeyedSegment]>
659
- style: string
660
- } & {
661
- editor: PortableTextSlateEditor
662
- })
663
- | ({
664
- type: 'delete text'
665
- selection: NonNullable<EditorSelection>
666
- } & {
667
- editor: PortableTextSlateEditor
668
- })
669
- | {
670
- type: 'key down'
671
- nativeEvent: KeyboardEvent
672
- editor: PortableTextSlateEditor
673
- }
674
- | {
675
- type: 'before insert text'
676
- nativeEvent: InputEvent
677
- editor: PortableTextSlateEditor
678
- }
679
659
  | PatchEvent
680
660
  | MutationEvent_2
681
661
  | {
@@ -684,6 +664,16 @@ export declare const editorMachine: StateMachine<
684
664
  | {
685
665
  type: 'done normalizing'
686
666
  }
667
+ | {
668
+ type: 'behavior event'
669
+ behaviorEvent: BehaviorEvent
670
+ editor: PortableTextSlateEditor
671
+ }
672
+ | {
673
+ type: 'behavior action intends'
674
+ editor: PortableTextSlateEditor
675
+ actionIntends: Array<BehaviorActionIntend>
676
+ }
687
677
  | {
688
678
  type: 'update schema'
689
679
  schema: PortableTextMemberSchemaTypes
@@ -741,41 +731,6 @@ export declare const editorMachine: StateMachine<
741
731
  any,
742
732
  any
743
733
  >,
744
- | ({
745
- type: 'insert text'
746
- text: string
747
- } & {
748
- editor: PortableTextSlateEditor
749
- })
750
- | ({
751
- type: 'insert text block'
752
- decorators: Array<string>
753
- } & {
754
- editor: PortableTextSlateEditor
755
- })
756
- | ({
757
- type: 'apply block style'
758
- paths: Array<[KeyedSegment]>
759
- style: string
760
- } & {
761
- editor: PortableTextSlateEditor
762
- })
763
- | ({
764
- type: 'delete text'
765
- selection: NonNullable<EditorSelection>
766
- } & {
767
- editor: PortableTextSlateEditor
768
- })
769
- | {
770
- type: 'key down'
771
- nativeEvent: KeyboardEvent
772
- editor: PortableTextSlateEditor
773
- }
774
- | {
775
- type: 'before insert text'
776
- nativeEvent: InputEvent
777
- editor: PortableTextSlateEditor
778
- }
779
734
  | PatchEvent
780
735
  | MutationEvent_2
781
736
  | {
@@ -784,6 +739,16 @@ export declare const editorMachine: StateMachine<
784
739
  | {
785
740
  type: 'done normalizing'
786
741
  }
742
+ | {
743
+ type: 'behavior event'
744
+ behaviorEvent: BehaviorEvent
745
+ editor: PortableTextSlateEditor
746
+ }
747
+ | {
748
+ type: 'behavior action intends'
749
+ editor: PortableTextSlateEditor
750
+ actionIntends: Array<BehaviorActionIntend>
751
+ }
787
752
  | {
788
753
  type: 'update schema'
789
754
  schema: PortableTextMemberSchemaTypes
@@ -858,41 +823,6 @@ export declare const editorMachine: StateMachine<
858
823
  {
859
824
  type: 'ready'
860
825
  },
861
- | ({
862
- type: 'insert text'
863
- text: string
864
- } & {
865
- editor: PortableTextSlateEditor
866
- })
867
- | ({
868
- type: 'insert text block'
869
- decorators: Array<string>
870
- } & {
871
- editor: PortableTextSlateEditor
872
- })
873
- | ({
874
- type: 'apply block style'
875
- paths: Array<[KeyedSegment]>
876
- style: string
877
- } & {
878
- editor: PortableTextSlateEditor
879
- })
880
- | ({
881
- type: 'delete text'
882
- selection: NonNullable<EditorSelection>
883
- } & {
884
- editor: PortableTextSlateEditor
885
- })
886
- | {
887
- type: 'key down'
888
- nativeEvent: KeyboardEvent
889
- editor: PortableTextSlateEditor
890
- }
891
- | {
892
- type: 'before insert text'
893
- nativeEvent: InputEvent
894
- editor: PortableTextSlateEditor
895
- }
896
826
  | PatchEvent
897
827
  | MutationEvent_2
898
828
  | {
@@ -901,6 +831,16 @@ export declare const editorMachine: StateMachine<
901
831
  | {
902
832
  type: 'done normalizing'
903
833
  }
834
+ | {
835
+ type: 'behavior event'
836
+ behaviorEvent: BehaviorEvent
837
+ editor: PortableTextSlateEditor
838
+ }
839
+ | {
840
+ type: 'behavior action intends'
841
+ editor: PortableTextSlateEditor
842
+ actionIntends: Array<BehaviorActionIntend>
843
+ }
904
844
  | {
905
845
  type: 'update schema'
906
846
  schema: PortableTextMemberSchemaTypes
@@ -1018,41 +958,6 @@ export declare const editorMachine: StateMachine<
1018
958
  type: 'unset'
1019
959
  previousValue: Array<PortableTextBlock>
1020
960
  },
1021
- | ({
1022
- type: 'insert text'
1023
- text: string
1024
- } & {
1025
- editor: PortableTextSlateEditor
1026
- })
1027
- | ({
1028
- type: 'insert text block'
1029
- decorators: Array<string>
1030
- } & {
1031
- editor: PortableTextSlateEditor
1032
- })
1033
- | ({
1034
- type: 'apply block style'
1035
- paths: Array<[KeyedSegment]>
1036
- style: string
1037
- } & {
1038
- editor: PortableTextSlateEditor
1039
- })
1040
- | ({
1041
- type: 'delete text'
1042
- selection: NonNullable<EditorSelection>
1043
- } & {
1044
- editor: PortableTextSlateEditor
1045
- })
1046
- | {
1047
- type: 'key down'
1048
- nativeEvent: KeyboardEvent
1049
- editor: PortableTextSlateEditor
1050
- }
1051
- | {
1052
- type: 'before insert text'
1053
- nativeEvent: InputEvent
1054
- editor: PortableTextSlateEditor
1055
- }
1056
961
  | PatchEvent
1057
962
  | MutationEvent_2
1058
963
  | {
@@ -1061,6 +966,16 @@ export declare const editorMachine: StateMachine<
1061
966
  | {
1062
967
  type: 'done normalizing'
1063
968
  }
969
+ | {
970
+ type: 'behavior event'
971
+ behaviorEvent: BehaviorEvent
972
+ editor: PortableTextSlateEditor
973
+ }
974
+ | {
975
+ type: 'behavior action intends'
976
+ editor: PortableTextSlateEditor
977
+ actionIntends: Array<BehaviorActionIntend>
978
+ }
1064
979
  | {
1065
980
  type: 'update schema'
1066
981
  schema: PortableTextMemberSchemaTypes
@@ -1178,41 +1093,6 @@ export declare const editorMachine: StateMachine<
1178
1093
  type: 'value changed'
1179
1094
  value: Array<PortableTextBlock> | undefined
1180
1095
  },
1181
- | ({
1182
- type: 'insert text'
1183
- text: string
1184
- } & {
1185
- editor: PortableTextSlateEditor
1186
- })
1187
- | ({
1188
- type: 'insert text block'
1189
- decorators: Array<string>
1190
- } & {
1191
- editor: PortableTextSlateEditor
1192
- })
1193
- | ({
1194
- type: 'apply block style'
1195
- paths: Array<[KeyedSegment]>
1196
- style: string
1197
- } & {
1198
- editor: PortableTextSlateEditor
1199
- })
1200
- | ({
1201
- type: 'delete text'
1202
- selection: NonNullable<EditorSelection>
1203
- } & {
1204
- editor: PortableTextSlateEditor
1205
- })
1206
- | {
1207
- type: 'key down'
1208
- nativeEvent: KeyboardEvent
1209
- editor: PortableTextSlateEditor
1210
- }
1211
- | {
1212
- type: 'before insert text'
1213
- nativeEvent: InputEvent
1214
- editor: PortableTextSlateEditor
1215
- }
1216
1096
  | PatchEvent
1217
1097
  | MutationEvent_2
1218
1098
  | {
@@ -1221,6 +1101,16 @@ export declare const editorMachine: StateMachine<
1221
1101
  | {
1222
1102
  type: 'done normalizing'
1223
1103
  }
1104
+ | {
1105
+ type: 'behavior event'
1106
+ behaviorEvent: BehaviorEvent
1107
+ editor: PortableTextSlateEditor
1108
+ }
1109
+ | {
1110
+ type: 'behavior action intends'
1111
+ editor: PortableTextSlateEditor
1112
+ actionIntends: Array<BehaviorActionIntend>
1113
+ }
1224
1114
  | {
1225
1115
  type: 'update schema'
1226
1116
  schema: PortableTextMemberSchemaTypes
@@ -1339,41 +1229,6 @@ export declare const editorMachine: StateMachine<
1339
1229
  resolution: InvalidValueResolution | null
1340
1230
  value: Array<PortableTextBlock> | undefined
1341
1231
  },
1342
- | ({
1343
- type: 'insert text'
1344
- text: string
1345
- } & {
1346
- editor: PortableTextSlateEditor
1347
- })
1348
- | ({
1349
- type: 'insert text block'
1350
- decorators: Array<string>
1351
- } & {
1352
- editor: PortableTextSlateEditor
1353
- })
1354
- | ({
1355
- type: 'apply block style'
1356
- paths: Array<[KeyedSegment]>
1357
- style: string
1358
- } & {
1359
- editor: PortableTextSlateEditor
1360
- })
1361
- | ({
1362
- type: 'delete text'
1363
- selection: NonNullable<EditorSelection>
1364
- } & {
1365
- editor: PortableTextSlateEditor
1366
- })
1367
- | {
1368
- type: 'key down'
1369
- nativeEvent: KeyboardEvent
1370
- editor: PortableTextSlateEditor
1371
- }
1372
- | {
1373
- type: 'before insert text'
1374
- nativeEvent: InputEvent
1375
- editor: PortableTextSlateEditor
1376
- }
1377
1232
  | PatchEvent
1378
1233
  | MutationEvent_2
1379
1234
  | {
@@ -1382,6 +1237,16 @@ export declare const editorMachine: StateMachine<
1382
1237
  | {
1383
1238
  type: 'done normalizing'
1384
1239
  }
1240
+ | {
1241
+ type: 'behavior event'
1242
+ behaviorEvent: BehaviorEvent
1243
+ editor: PortableTextSlateEditor
1244
+ }
1245
+ | {
1246
+ type: 'behavior action intends'
1247
+ editor: PortableTextSlateEditor
1248
+ actionIntends: Array<BehaviorActionIntend>
1249
+ }
1385
1250
  | {
1386
1251
  type: 'update schema'
1387
1252
  schema: PortableTextMemberSchemaTypes
@@ -1501,41 +1366,6 @@ export declare const editorMachine: StateMachine<
1501
1366
  description: string
1502
1367
  data: unknown
1503
1368
  },
1504
- | ({
1505
- type: 'insert text'
1506
- text: string
1507
- } & {
1508
- editor: PortableTextSlateEditor
1509
- })
1510
- | ({
1511
- type: 'insert text block'
1512
- decorators: Array<string>
1513
- } & {
1514
- editor: PortableTextSlateEditor
1515
- })
1516
- | ({
1517
- type: 'apply block style'
1518
- paths: Array<[KeyedSegment]>
1519
- style: string
1520
- } & {
1521
- editor: PortableTextSlateEditor
1522
- })
1523
- | ({
1524
- type: 'delete text'
1525
- selection: NonNullable<EditorSelection>
1526
- } & {
1527
- editor: PortableTextSlateEditor
1528
- })
1529
- | {
1530
- type: 'key down'
1531
- nativeEvent: KeyboardEvent
1532
- editor: PortableTextSlateEditor
1533
- }
1534
- | {
1535
- type: 'before insert text'
1536
- nativeEvent: InputEvent
1537
- editor: PortableTextSlateEditor
1538
- }
1539
1369
  | PatchEvent
1540
1370
  | MutationEvent_2
1541
1371
  | {
@@ -1544,6 +1374,16 @@ export declare const editorMachine: StateMachine<
1544
1374
  | {
1545
1375
  type: 'done normalizing'
1546
1376
  }
1377
+ | {
1378
+ type: 'behavior event'
1379
+ behaviorEvent: BehaviorEvent
1380
+ editor: PortableTextSlateEditor
1381
+ }
1382
+ | {
1383
+ type: 'behavior action intends'
1384
+ editor: PortableTextSlateEditor
1385
+ actionIntends: Array<BehaviorActionIntend>
1386
+ }
1547
1387
  | {
1548
1388
  type: 'update schema'
1549
1389
  schema: PortableTextMemberSchemaTypes
@@ -1661,41 +1501,6 @@ export declare const editorMachine: StateMachine<
1661
1501
  type: 'selection'
1662
1502
  selection: EditorSelection
1663
1503
  },
1664
- | ({
1665
- type: 'insert text'
1666
- text: string
1667
- } & {
1668
- editor: PortableTextSlateEditor
1669
- })
1670
- | ({
1671
- type: 'insert text block'
1672
- decorators: Array<string>
1673
- } & {
1674
- editor: PortableTextSlateEditor
1675
- })
1676
- | ({
1677
- type: 'apply block style'
1678
- paths: Array<[KeyedSegment]>
1679
- style: string
1680
- } & {
1681
- editor: PortableTextSlateEditor
1682
- })
1683
- | ({
1684
- type: 'delete text'
1685
- selection: NonNullable<EditorSelection>
1686
- } & {
1687
- editor: PortableTextSlateEditor
1688
- })
1689
- | {
1690
- type: 'key down'
1691
- nativeEvent: KeyboardEvent
1692
- editor: PortableTextSlateEditor
1693
- }
1694
- | {
1695
- type: 'before insert text'
1696
- nativeEvent: InputEvent
1697
- editor: PortableTextSlateEditor
1698
- }
1699
1504
  | PatchEvent
1700
1505
  | MutationEvent_2
1701
1506
  | {
@@ -1704,6 +1509,16 @@ export declare const editorMachine: StateMachine<
1704
1509
  | {
1705
1510
  type: 'done normalizing'
1706
1511
  }
1512
+ | {
1513
+ type: 'behavior event'
1514
+ behaviorEvent: BehaviorEvent
1515
+ editor: PortableTextSlateEditor
1516
+ }
1517
+ | {
1518
+ type: 'behavior action intends'
1519
+ editor: PortableTextSlateEditor
1520
+ actionIntends: Array<BehaviorActionIntend>
1521
+ }
1707
1522
  | {
1708
1523
  type: 'update schema'
1709
1524
  schema: PortableTextMemberSchemaTypes
@@ -1821,41 +1636,6 @@ export declare const editorMachine: StateMachine<
1821
1636
  type: 'blur'
1822
1637
  event: FocusEvent_2<HTMLDivElement, Element>
1823
1638
  },
1824
- | ({
1825
- type: 'insert text'
1826
- text: string
1827
- } & {
1828
- editor: PortableTextSlateEditor
1829
- })
1830
- | ({
1831
- type: 'insert text block'
1832
- decorators: Array<string>
1833
- } & {
1834
- editor: PortableTextSlateEditor
1835
- })
1836
- | ({
1837
- type: 'apply block style'
1838
- paths: Array<[KeyedSegment]>
1839
- style: string
1840
- } & {
1841
- editor: PortableTextSlateEditor
1842
- })
1843
- | ({
1844
- type: 'delete text'
1845
- selection: NonNullable<EditorSelection>
1846
- } & {
1847
- editor: PortableTextSlateEditor
1848
- })
1849
- | {
1850
- type: 'key down'
1851
- nativeEvent: KeyboardEvent
1852
- editor: PortableTextSlateEditor
1853
- }
1854
- | {
1855
- type: 'before insert text'
1856
- nativeEvent: InputEvent
1857
- editor: PortableTextSlateEditor
1858
- }
1859
1639
  | PatchEvent
1860
1640
  | MutationEvent_2
1861
1641
  | {
@@ -1864,6 +1644,16 @@ export declare const editorMachine: StateMachine<
1864
1644
  | {
1865
1645
  type: 'done normalizing'
1866
1646
  }
1647
+ | {
1648
+ type: 'behavior event'
1649
+ behaviorEvent: BehaviorEvent
1650
+ editor: PortableTextSlateEditor
1651
+ }
1652
+ | {
1653
+ type: 'behavior action intends'
1654
+ editor: PortableTextSlateEditor
1655
+ actionIntends: Array<BehaviorActionIntend>
1656
+ }
1867
1657
  | {
1868
1658
  type: 'update schema'
1869
1659
  schema: PortableTextMemberSchemaTypes
@@ -1981,41 +1771,6 @@ export declare const editorMachine: StateMachine<
1981
1771
  type: 'focus'
1982
1772
  event: FocusEvent_2<HTMLDivElement, Element>
1983
1773
  },
1984
- | ({
1985
- type: 'insert text'
1986
- text: string
1987
- } & {
1988
- editor: PortableTextSlateEditor
1989
- })
1990
- | ({
1991
- type: 'insert text block'
1992
- decorators: Array<string>
1993
- } & {
1994
- editor: PortableTextSlateEditor
1995
- })
1996
- | ({
1997
- type: 'apply block style'
1998
- paths: Array<[KeyedSegment]>
1999
- style: string
2000
- } & {
2001
- editor: PortableTextSlateEditor
2002
- })
2003
- | ({
2004
- type: 'delete text'
2005
- selection: NonNullable<EditorSelection>
2006
- } & {
2007
- editor: PortableTextSlateEditor
2008
- })
2009
- | {
2010
- type: 'key down'
2011
- nativeEvent: KeyboardEvent
2012
- editor: PortableTextSlateEditor
2013
- }
2014
- | {
2015
- type: 'before insert text'
2016
- nativeEvent: InputEvent
2017
- editor: PortableTextSlateEditor
2018
- }
2019
1774
  | PatchEvent
2020
1775
  | MutationEvent_2
2021
1776
  | {
@@ -2024,6 +1779,16 @@ export declare const editorMachine: StateMachine<
2024
1779
  | {
2025
1780
  type: 'done normalizing'
2026
1781
  }
1782
+ | {
1783
+ type: 'behavior event'
1784
+ behaviorEvent: BehaviorEvent
1785
+ editor: PortableTextSlateEditor
1786
+ }
1787
+ | {
1788
+ type: 'behavior action intends'
1789
+ editor: PortableTextSlateEditor
1790
+ actionIntends: Array<BehaviorActionIntend>
1791
+ }
2027
1792
  | {
2028
1793
  type: 'update schema'
2029
1794
  schema: PortableTextMemberSchemaTypes
@@ -2140,41 +1905,6 @@ export declare const editorMachine: StateMachine<
2140
1905
  {
2141
1906
  type: 'online'
2142
1907
  },
2143
- | ({
2144
- type: 'insert text'
2145
- text: string
2146
- } & {
2147
- editor: PortableTextSlateEditor
2148
- })
2149
- | ({
2150
- type: 'insert text block'
2151
- decorators: Array<string>
2152
- } & {
2153
- editor: PortableTextSlateEditor
2154
- })
2155
- | ({
2156
- type: 'apply block style'
2157
- paths: Array<[KeyedSegment]>
2158
- style: string
2159
- } & {
2160
- editor: PortableTextSlateEditor
2161
- })
2162
- | ({
2163
- type: 'delete text'
2164
- selection: NonNullable<EditorSelection>
2165
- } & {
2166
- editor: PortableTextSlateEditor
2167
- })
2168
- | {
2169
- type: 'key down'
2170
- nativeEvent: KeyboardEvent
2171
- editor: PortableTextSlateEditor
2172
- }
2173
- | {
2174
- type: 'before insert text'
2175
- nativeEvent: InputEvent
2176
- editor: PortableTextSlateEditor
2177
- }
2178
1908
  | PatchEvent
2179
1909
  | MutationEvent_2
2180
1910
  | {
@@ -2183,6 +1913,16 @@ export declare const editorMachine: StateMachine<
2183
1913
  | {
2184
1914
  type: 'done normalizing'
2185
1915
  }
1916
+ | {
1917
+ type: 'behavior event'
1918
+ behaviorEvent: BehaviorEvent
1919
+ editor: PortableTextSlateEditor
1920
+ }
1921
+ | {
1922
+ type: 'behavior action intends'
1923
+ editor: PortableTextSlateEditor
1924
+ actionIntends: Array<BehaviorActionIntend>
1925
+ }
2186
1926
  | {
2187
1927
  type: 'update schema'
2188
1928
  schema: PortableTextMemberSchemaTypes
@@ -2299,41 +2039,6 @@ export declare const editorMachine: StateMachine<
2299
2039
  {
2300
2040
  type: 'offline'
2301
2041
  },
2302
- | ({
2303
- type: 'insert text'
2304
- text: string
2305
- } & {
2306
- editor: PortableTextSlateEditor
2307
- })
2308
- | ({
2309
- type: 'insert text block'
2310
- decorators: Array<string>
2311
- } & {
2312
- editor: PortableTextSlateEditor
2313
- })
2314
- | ({
2315
- type: 'apply block style'
2316
- paths: Array<[KeyedSegment]>
2317
- style: string
2318
- } & {
2319
- editor: PortableTextSlateEditor
2320
- })
2321
- | ({
2322
- type: 'delete text'
2323
- selection: NonNullable<EditorSelection>
2324
- } & {
2325
- editor: PortableTextSlateEditor
2326
- })
2327
- | {
2328
- type: 'key down'
2329
- nativeEvent: KeyboardEvent
2330
- editor: PortableTextSlateEditor
2331
- }
2332
- | {
2333
- type: 'before insert text'
2334
- nativeEvent: InputEvent
2335
- editor: PortableTextSlateEditor
2336
- }
2337
2042
  | PatchEvent
2338
2043
  | MutationEvent_2
2339
2044
  | {
@@ -2342,6 +2047,16 @@ export declare const editorMachine: StateMachine<
2342
2047
  | {
2343
2048
  type: 'done normalizing'
2344
2049
  }
2050
+ | {
2051
+ type: 'behavior event'
2052
+ behaviorEvent: BehaviorEvent
2053
+ editor: PortableTextSlateEditor
2054
+ }
2055
+ | {
2056
+ type: 'behavior action intends'
2057
+ editor: PortableTextSlateEditor
2058
+ actionIntends: Array<BehaviorActionIntend>
2059
+ }
2345
2060
  | {
2346
2061
  type: 'update schema'
2347
2062
  schema: PortableTextMemberSchemaTypes
@@ -2458,41 +2173,6 @@ export declare const editorMachine: StateMachine<
2458
2173
  {
2459
2174
  type: 'loading'
2460
2175
  },
2461
- | ({
2462
- type: 'insert text'
2463
- text: string
2464
- } & {
2465
- editor: PortableTextSlateEditor
2466
- })
2467
- | ({
2468
- type: 'insert text block'
2469
- decorators: Array<string>
2470
- } & {
2471
- editor: PortableTextSlateEditor
2472
- })
2473
- | ({
2474
- type: 'apply block style'
2475
- paths: Array<[KeyedSegment]>
2476
- style: string
2477
- } & {
2478
- editor: PortableTextSlateEditor
2479
- })
2480
- | ({
2481
- type: 'delete text'
2482
- selection: NonNullable<EditorSelection>
2483
- } & {
2484
- editor: PortableTextSlateEditor
2485
- })
2486
- | {
2487
- type: 'key down'
2488
- nativeEvent: KeyboardEvent
2489
- editor: PortableTextSlateEditor
2490
- }
2491
- | {
2492
- type: 'before insert text'
2493
- nativeEvent: InputEvent
2494
- editor: PortableTextSlateEditor
2495
- }
2496
2176
  | PatchEvent
2497
2177
  | MutationEvent_2
2498
2178
  | {
@@ -2501,6 +2181,16 @@ export declare const editorMachine: StateMachine<
2501
2181
  | {
2502
2182
  type: 'done normalizing'
2503
2183
  }
2184
+ | {
2185
+ type: 'behavior event'
2186
+ behaviorEvent: BehaviorEvent
2187
+ editor: PortableTextSlateEditor
2188
+ }
2189
+ | {
2190
+ type: 'behavior action intends'
2191
+ editor: PortableTextSlateEditor
2192
+ actionIntends: Array<BehaviorActionIntend>
2193
+ }
2504
2194
  | {
2505
2195
  type: 'update schema'
2506
2196
  schema: PortableTextMemberSchemaTypes
@@ -2617,41 +2307,6 @@ export declare const editorMachine: StateMachine<
2617
2307
  {
2618
2308
  type: 'done loading'
2619
2309
  },
2620
- | ({
2621
- type: 'insert text'
2622
- text: string
2623
- } & {
2624
- editor: PortableTextSlateEditor
2625
- })
2626
- | ({
2627
- type: 'insert text block'
2628
- decorators: Array<string>
2629
- } & {
2630
- editor: PortableTextSlateEditor
2631
- })
2632
- | ({
2633
- type: 'apply block style'
2634
- paths: Array<[KeyedSegment]>
2635
- style: string
2636
- } & {
2637
- editor: PortableTextSlateEditor
2638
- })
2639
- | ({
2640
- type: 'delete text'
2641
- selection: NonNullable<EditorSelection>
2642
- } & {
2643
- editor: PortableTextSlateEditor
2644
- })
2645
- | {
2646
- type: 'key down'
2647
- nativeEvent: KeyboardEvent
2648
- editor: PortableTextSlateEditor
2649
- }
2650
- | {
2651
- type: 'before insert text'
2652
- nativeEvent: InputEvent
2653
- editor: PortableTextSlateEditor
2654
- }
2655
2310
  | PatchEvent
2656
2311
  | MutationEvent_2
2657
2312
  | {
@@ -2660,6 +2315,16 @@ export declare const editorMachine: StateMachine<
2660
2315
  | {
2661
2316
  type: 'done normalizing'
2662
2317
  }
2318
+ | {
2319
+ type: 'behavior event'
2320
+ behaviorEvent: BehaviorEvent
2321
+ editor: PortableTextSlateEditor
2322
+ }
2323
+ | {
2324
+ type: 'behavior action intends'
2325
+ editor: PortableTextSlateEditor
2326
+ actionIntends: Array<BehaviorActionIntend>
2327
+ }
2663
2328
  | {
2664
2329
  type: 'update schema'
2665
2330
  schema: PortableTextMemberSchemaTypes
@@ -2768,87 +2433,95 @@ export declare const editorMachine: StateMachine<
2768
2433
  readonly 'update schema': {
2769
2434
  readonly actions: 'assign schema'
2770
2435
  }
2771
- readonly 'key down': {
2772
- readonly actions: readonly ['handle behavior event']
2773
- }
2774
- readonly 'before insert text': {
2775
- readonly actions: readonly ['handle behavior event']
2776
- }
2777
- readonly 'apply block style': {
2778
- readonly actions: readonly [
2779
- ({
2780
- context,
2781
- event,
2782
- }: {
2783
- context: {
2784
- keyGenerator: () => string
2785
- schema: PortableTextMemberSchemaTypes
2786
- }
2787
- event: {
2788
- type: 'apply block style'
2789
- paths: Array<[KeyedSegment]>
2790
- style: string
2791
- } & {
2792
- editor: PortableTextSlateEditor
2793
- }
2794
- }) => void,
2795
- ]
2436
+ readonly 'behavior event': {
2437
+ readonly actions: 'handle behavior event'
2796
2438
  }
2797
- readonly 'delete text': {
2439
+ readonly 'behavior action intends': {
2798
2440
  readonly actions: readonly [
2799
2441
  ({
2800
2442
  context,
2801
2443
  event,
2802
- }: {
2803
- context: {
2804
- keyGenerator: () => string
2805
- schema: PortableTextMemberSchemaTypes
2806
- }
2807
- event: {
2808
- type: 'delete text'
2809
- selection: NonNullable<EditorSelection>
2810
- } & {
2811
- editor: PortableTextSlateEditor
2812
- }
2813
- }) => void,
2814
- ]
2815
- }
2816
- readonly 'insert text': {
2817
- readonly actions: readonly [
2818
- ({
2819
- context,
2820
- event,
2821
- }: {
2822
- context: {
2823
- keyGenerator: () => string
2824
- schema: PortableTextMemberSchemaTypes
2825
- }
2826
- event: {
2827
- type: 'insert text'
2828
- text: string
2829
- } & {
2830
- editor: PortableTextSlateEditor
2831
- }
2832
- }) => void,
2833
- ]
2834
- }
2835
- readonly 'insert text block': {
2836
- readonly actions: readonly [
2837
- ({
2838
- context,
2839
- event,
2840
- }: {
2841
- context: {
2444
+ }: ActionArgs<
2445
+ {
2446
+ behaviors: Array<Behavior>
2842
2447
  keyGenerator: () => string
2448
+ pendingEvents: Array<PatchEvent | MutationEvent_2>
2843
2449
  schema: PortableTextMemberSchemaTypes
2844
- }
2845
- event: {
2846
- type: 'insert text block'
2847
- decorators: Array<string>
2848
- } & {
2450
+ },
2451
+ {
2452
+ type: 'behavior action intends'
2849
2453
  editor: PortableTextSlateEditor
2850
- }
2851
- }) => void,
2454
+ actionIntends: Array<BehaviorActionIntend>
2455
+ },
2456
+ | PatchEvent
2457
+ | MutationEvent_2
2458
+ | {
2459
+ type: 'normalizing'
2460
+ }
2461
+ | {
2462
+ type: 'done normalizing'
2463
+ }
2464
+ | {
2465
+ type: 'behavior event'
2466
+ behaviorEvent: BehaviorEvent
2467
+ editor: PortableTextSlateEditor
2468
+ }
2469
+ | {
2470
+ type: 'behavior action intends'
2471
+ editor: PortableTextSlateEditor
2472
+ actionIntends: Array<BehaviorActionIntend>
2473
+ }
2474
+ | {
2475
+ type: 'update schema'
2476
+ schema: PortableTextMemberSchemaTypes
2477
+ }
2478
+ | {
2479
+ type: 'ready'
2480
+ }
2481
+ | {
2482
+ type: 'unset'
2483
+ previousValue: Array<PortableTextBlock>
2484
+ }
2485
+ | {
2486
+ type: 'value changed'
2487
+ value: Array<PortableTextBlock> | undefined
2488
+ }
2489
+ | {
2490
+ type: 'invalid value'
2491
+ resolution: InvalidValueResolution | null
2492
+ value: Array<PortableTextBlock> | undefined
2493
+ }
2494
+ | {
2495
+ type: 'error'
2496
+ name: string
2497
+ description: string
2498
+ data: unknown
2499
+ }
2500
+ | {
2501
+ type: 'selection'
2502
+ selection: EditorSelection
2503
+ }
2504
+ | {
2505
+ type: 'blur'
2506
+ event: FocusEvent_2<HTMLDivElement, Element>
2507
+ }
2508
+ | {
2509
+ type: 'focus'
2510
+ event: FocusEvent_2<HTMLDivElement, Element>
2511
+ }
2512
+ | {
2513
+ type: 'online'
2514
+ }
2515
+ | {
2516
+ type: 'offline'
2517
+ }
2518
+ | {
2519
+ type: 'loading'
2520
+ }
2521
+ | {
2522
+ type: 'done loading'
2523
+ }
2524
+ >) => void,
2852
2525
  ]
2853
2526
  }
2854
2527
  }
@@ -3432,7 +3105,11 @@ export declare interface PortableTextSlateEditor extends ReactEditor {
3432
3105
  /**
3433
3106
  * Helper function that creates a text block
3434
3107
  */
3435
- pteCreateTextBlock: (options: {decorators: Array<string>}) => Descendant
3108
+ pteCreateTextBlock: (options: {
3109
+ decorators: Array<string>
3110
+ listItem?: string
3111
+ level?: number
3112
+ }) => Descendant
3436
3113
  /**
3437
3114
  * Undo
3438
3115
  */
@@ -3443,23 +3120,6 @@ export declare interface PortableTextSlateEditor extends ReactEditor {
3443
3120
  redo: () => void
3444
3121
  }
3445
3122
 
3446
- /**
3447
- * @alpha
3448
- */
3449
- export declare type RaiseBehaviorActionIntend<
3450
- TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
3451
- TGuardResponse = true,
3452
- > = (
3453
- {
3454
- context,
3455
- event,
3456
- }: {
3457
- context: BehaviorContext
3458
- event: PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
3459
- },
3460
- guardResponse: TGuardResponse,
3461
- ) => BehaviorActionIntend | void
3462
-
3463
3123
  /**
3464
3124
  * A range decoration is a UI affordance that wraps a given selection range in the editor
3465
3125
  * with a custom component. This can be used to highlight search results,