@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,716 +1,31 @@
1
- import type {Patch} from '@portabletext/patches'
2
- import type {
3
- Path,
4
- PortableTextBlock,
5
- PortableTextChild,
6
- PortableTextObject,
7
- PortableTextTextBlock,
8
- } from '@sanity/types'
9
- import type {FocusEvent as FocusEvent_2} from 'react'
10
- import {JSX, default as React_2} from 'react'
11
- import type {ActorRef, EventObject, Snapshot} from 'xstate'
12
-
13
- declare type AbstractBehaviorEvent =
14
- | {
15
- type: StrictExtract<SyntheticBehaviorEventType, 'annotation.set'>
16
- at: AnnotationPath
17
- props: Record<string, unknown>
18
- }
19
- | {
20
- type: StrictExtract<SyntheticBehaviorEventType, 'annotation.toggle'>
21
- annotation: {
22
- name: string
23
- value: {
24
- [prop: string]: unknown
25
- }
26
- }
27
- }
28
- | {
29
- type: StrictExtract<SyntheticBehaviorEventType, 'decorator.toggle'>
30
- decorator: string
31
- at?: {
32
- anchor: BlockOffset
33
- focus: BlockOffset
34
- }
35
- }
36
- | {
37
- type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>
38
- unit: 'character' | 'word' | 'line' | 'block'
39
- }
40
- | {
41
- type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
42
- at: BlockPath
43
- }
44
- | {
45
- type: StrictExtract<SyntheticBehaviorEventType, 'delete.child'>
46
- at: ChildPath
47
- }
48
- | {
49
- type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
50
- unit: 'character' | 'word' | 'line' | 'block'
51
- }
52
- | {
53
- type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
54
- at: {
55
- anchor: BlockOffset
56
- focus: BlockOffset
57
- }
58
- }
59
- | {
60
- type: StrictExtract<SyntheticBehaviorEventType, 'deserialize'>
61
- originEvent:
62
- | PickFromUnion<
63
- NativeBehaviorEvent,
64
- 'type',
65
- 'drag.drop' | 'clipboard.paste'
66
- >
67
- | InputBehaviorEvent
68
- }
69
- | {
70
- type: StrictExtract<SyntheticBehaviorEventType, 'serialize'>
71
- originEvent: PickFromUnion<
72
- NativeBehaviorEvent,
73
- 'type',
74
- 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
75
- >
76
- }
77
- | {
78
- type: StrictExtract<SyntheticBehaviorEventType, 'deserialization.success'>
79
- mimeType: MIMEType
80
- data: Array<PortableTextBlock>
81
- originEvent:
82
- | PickFromUnion<
83
- NativeBehaviorEvent,
84
- 'type',
85
- 'drag.drop' | 'clipboard.paste'
86
- >
87
- | InputBehaviorEvent
88
- }
89
- | {
90
- type: StrictExtract<SyntheticBehaviorEventType, 'deserialization.failure'>
91
- mimeType: MIMEType
92
- reason: string
93
- originEvent:
94
- | PickFromUnion<
95
- NativeBehaviorEvent,
96
- 'type',
97
- 'drag.drop' | 'clipboard.paste'
98
- >
99
- | InputBehaviorEvent
100
- }
101
- | {
102
- type: StrictExtract<SyntheticBehaviorEventType, 'serialization.success'>
103
- mimeType: MIMEType
104
- data: string
105
- originEvent: PickFromUnion<
106
- NativeBehaviorEvent,
107
- 'type',
108
- 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
109
- >
110
- }
111
- | {
112
- type: StrictExtract<SyntheticBehaviorEventType, 'serialization.failure'>
113
- mimeType: MIMEType
114
- reason: string
115
- originEvent: PickFromUnion<
116
- NativeBehaviorEvent,
117
- 'type',
118
- 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
119
- >
120
- }
121
- | {
122
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
123
- blocks: Array<BlockWithOptionalKey>
124
- placement: InsertPlacement
125
- select?: 'start' | 'end' | 'none'
126
- }
127
- | {
128
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>
129
- }
130
- | {
131
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.soft break'>
132
- }
133
- | {
134
- type: StrictExtract<SyntheticBehaviorEventType, 'list item.add'>
135
- listItem: string
136
- }
137
- | {
138
- type: StrictExtract<SyntheticBehaviorEventType, 'list item.remove'>
139
- listItem: string
140
- }
141
- | {
142
- type: StrictExtract<SyntheticBehaviorEventType, 'list item.toggle'>
143
- listItem: string
144
- }
145
- | {
146
- type: StrictExtract<SyntheticBehaviorEventType, 'move.block down'>
147
- at: BlockPath
148
- }
149
- | {
150
- type: StrictExtract<SyntheticBehaviorEventType, 'move.block up'>
151
- at: BlockPath
152
- }
153
- | {
154
- type: StrictExtract<SyntheticBehaviorEventType, 'select.previous block'>
155
- select?: 'start' | 'end'
156
- }
157
- | {
158
- type: StrictExtract<SyntheticBehaviorEventType, 'select.next block'>
159
- select?: 'start' | 'end'
160
- }
161
- | {
162
- type: StrictExtract<SyntheticBehaviorEventType, 'split'>
163
- }
164
- | {
165
- type: StrictExtract<SyntheticBehaviorEventType, 'style.add'>
166
- style: string
167
- }
168
- | {
169
- type: StrictExtract<SyntheticBehaviorEventType, 'style.remove'>
170
- style: string
171
- }
172
- | {
173
- type: StrictExtract<SyntheticBehaviorEventType, 'style.toggle'>
174
- style: string
175
- }
176
-
177
- /**************************************
178
- * Abstract events
179
- **************************************/
180
- declare const abstractBehaviorEventTypes: readonly [
181
- 'annotation.set',
182
- 'annotation.toggle',
183
- 'decorator.toggle',
184
- 'delete.backward',
185
- 'delete.block',
186
- 'delete.child',
187
- 'delete.forward',
188
- 'delete.text',
189
- 'deserialize',
190
- 'deserialization.success',
191
- 'deserialization.failure',
192
- 'insert.blocks',
193
- 'insert.break',
194
- 'insert.soft break',
195
- 'list item.add',
196
- 'list item.remove',
197
- 'list item.toggle',
198
- 'move.block down',
199
- 'move.block up',
200
- 'select.previous block',
201
- 'select.next block',
202
- 'serialize',
203
- 'serialization.success',
204
- 'serialization.failure',
205
- 'split',
206
- 'style.add',
207
- 'style.remove',
208
- 'style.toggle',
209
- ]
210
-
211
- /**
212
- * @public
213
- */
214
- declare type AnnotationPath = [
215
- {
216
- _key: string
217
- },
218
- 'markDefs',
219
- {
220
- _key: string
221
- },
222
- ]
223
-
224
- /**
225
- * @public
226
- */
227
- declare type AnnotationSchemaType = BaseDefinition & {
228
- fields: ReadonlyArray<FieldDefinition>
229
- }
230
-
231
- /**
232
- * @public
233
- */
234
- declare type BaseDefinition = {
235
- name: string
236
- title?: string
237
- }
238
-
239
- /**
240
- * @beta
241
- */
242
- declare type Behavior<
243
- TBehaviorEventType extends
244
- | '*'
245
- | `${BehaviorEventTypeNamespace}.*`
246
- | BehaviorEvent['type'] =
247
- | '*'
248
- | `${BehaviorEventTypeNamespace}.*`
249
- | BehaviorEvent['type'],
250
- TGuardResponse = true,
251
- TBehaviorEvent extends
252
- ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>,
253
- > = {
254
- /**
255
- * Editor Event that triggers this Behavior.
256
- */
257
- on: TBehaviorEventType
258
- /**
259
- * Predicate function that determines if the Behavior should be executed.
260
- * Returning a non-nullable value from the guard will pass the value to the
261
- * actions and execute them.
262
- */
263
- guard?: BehaviorGuard<TBehaviorEvent, TGuardResponse>
264
- /**
265
- * Array of Behavior Action sets.
266
- * Each set represents a step in the history stack.
267
- */
268
- actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
269
- }
270
-
271
- /**
272
- * @beta
273
- */
274
- declare type BehaviorAction =
275
- | {
276
- type: 'execute'
277
- event: SyntheticBehaviorEvent
278
- }
279
- | {
280
- type: 'forward'
281
- event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent
282
- }
283
- | {
284
- type: 'raise'
285
- event: SyntheticBehaviorEvent | CustomBehaviorEvent
286
- }
287
- | {
288
- type: 'effect'
289
- effect: () => void
290
- }
291
-
292
- /**
293
- * @beta
294
- */
295
- declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
296
- payload: {
297
- snapshot: EditorSnapshot
298
- event: TBehaviorEvent
299
- dom: EditorDom
300
- },
301
- guardResponse: TGuardResponse,
302
- ) => Array<BehaviorAction>
303
-
304
- /**
305
- * @beta
306
- */
307
- declare type BehaviorEvent =
308
- | SyntheticBehaviorEvent
309
- | NativeBehaviorEvent
310
- | CustomBehaviorEvent
311
-
312
- declare type BehaviorEventTypeNamespace =
313
- | SyntheticBehaviorEventNamespace
314
- | NativeBehaviorEventNamespace
315
- | CustomBehaviorEventNamespace
316
-
317
- /**
318
- * @beta
319
- */
320
- declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
321
- snapshot: EditorSnapshot
322
- event: TBehaviorEvent
323
- dom: EditorDom
324
- }) => TGuardResponse | false
325
-
326
- /**
327
- * @beta
328
- */
329
- export declare function BehaviorPlugin(props: {
330
- behaviors: Array<Behavior>
331
- }): null
332
-
333
- /**
334
- * @public
335
- */
336
- declare type BlockObjectSchemaType = BaseDefinition & {
337
- fields: ReadonlyArray<FieldDefinition>
338
- }
339
-
340
- /**
341
- * @beta
342
- */
343
- declare type BlockOffset = {
344
- path: BlockPath
345
- offset: number
346
- }
347
-
348
- /**
349
- * @public
350
- */
351
- declare type BlockPath = [
352
- {
353
- _key: string
354
- },
355
- ]
356
-
357
- declare type BlockWithOptionalKey =
358
- | TextBlockWithOptionalKey
359
- | ObjectBlockWithOptionalKey
360
-
361
- /**
362
- * @public
363
- */
364
- declare type ChildPath = [
365
- {
366
- _key: string
367
- },
368
- 'children',
369
- {
370
- _key: string
371
- },
372
- ]
373
-
374
- declare type ClipboardBehaviorEvent =
375
- | {
376
- type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
377
- originEvent: {
378
- dataTransfer: DataTransfer
379
- }
380
- position: Pick<EventPosition, 'selection'>
381
- }
382
- | {
383
- type: StrictExtract<NativeBehaviorEventType, 'clipboard.cut'>
384
- originEvent: {
385
- dataTransfer: DataTransfer
386
- }
387
- position: Pick<EventPosition, 'selection'>
388
- }
389
- | {
390
- type: StrictExtract<NativeBehaviorEventType, 'clipboard.paste'>
391
- originEvent: {
392
- dataTransfer: DataTransfer
393
- }
394
- position: Pick<EventPosition, 'selection'>
395
- }
396
-
397
- declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
398
- mimeType: TMIMEType
399
- serialize: Serializer<TMIMEType>
400
- deserialize: Deserializer<TMIMEType>
401
- }
402
-
403
- declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
404
- | {
405
- type: 'serialize'
406
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
407
- }
408
- | {
409
- type: 'serialization.failure'
410
- mimeType: TMIMEType
411
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
412
- reason: string
413
- }
414
- | {
415
- type: 'serialization.success'
416
- data: string
417
- mimeType: TMIMEType
418
- originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
419
- }
420
- | {
421
- type: 'deserialize'
422
- data: string
423
- }
424
- | {
425
- type: 'deserialization.failure'
426
- mimeType: TMIMEType
427
- reason: string
428
- }
429
- | {
430
- type: 'deserialization.success'
431
- data: Array<PortableTextBlock>
432
- mimeType: TMIMEType
433
- }
434
-
1
+ import { Behavior, Editor, EditorEmittedEvent, EditorSchema } from "../_chunks-dts/behavior.types.action.cjs";
2
+ import * as react12 from "react";
3
+ import React from "react";
435
4
  /**
436
5
  * @beta
437
6
  */
438
- declare type CustomBehaviorEvent<
439
- TPayload extends Record<string, unknown> = Record<string, unknown>,
440
- TType extends string = string,
441
- TInternalType extends CustomBehaviorEventType<
442
- 'custom',
443
- TType
444
- > = CustomBehaviorEventType<'custom', TType>,
445
- > = {
446
- type: TInternalType
447
- } & TPayload
448
-
449
- /**************************************
450
- * Custom events
451
- **************************************/
452
- declare type CustomBehaviorEventNamespace = 'custom'
453
-
454
- declare type CustomBehaviorEventType<
455
- TNamespace extends CustomBehaviorEventNamespace,
456
- TType extends string = '',
457
- > = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
458
-
459
- /**
460
- * @public
461
- */
462
- declare type DecoratorSchemaType = BaseDefinition & {
463
- /**
464
- * @deprecated
465
- * Use `name` instead
466
- */
467
- value: string
468
- }
469
-
7
+ declare function BehaviorPlugin(props: {
8
+ behaviors: Array<Behavior>;
9
+ }): null;
470
10
  /**
471
11
  * @beta
472
12
  * @deprecated Install the plugin from `@portabletext/plugin-character-pair-decorator`
473
13
  */
474
- export declare function DecoratorShortcutPlugin(config: {
475
- decorator: ({schema}: {schema: EditorSchema}) => string | undefined
476
- pair: {
477
- char: string
478
- amount: number
479
- }
480
- }): null
481
-
482
- declare type Deserializer<TMIMEType extends MIMEType> = ({
483
- snapshot,
484
- event,
485
- }: {
486
- snapshot: EditorSnapshot
487
- event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>
488
- }) => PickFromUnion<
489
- ConverterEvent<TMIMEType>,
490
- 'type',
491
- 'deserialization.success' | 'deserialization.failure'
492
- >
493
-
494
- declare type DragBehaviorEvent =
495
- | {
496
- type: StrictExtract<NativeBehaviorEventType, 'drag.dragstart'>
497
- originEvent: {
498
- clientX: number
499
- clientY: number
500
- dataTransfer: DataTransfer
501
- }
502
- position: Pick<EventPosition, 'selection'>
503
- }
504
- | {
505
- type: StrictExtract<NativeBehaviorEventType, 'drag.drag'>
506
- originEvent: {
507
- dataTransfer: DataTransfer
508
- }
509
- }
510
- | {
511
- type: StrictExtract<NativeBehaviorEventType, 'drag.dragend'>
512
- originEvent: {
513
- dataTransfer: DataTransfer
514
- }
515
- }
516
- | {
517
- type: StrictExtract<NativeBehaviorEventType, 'drag.dragenter'>
518
- originEvent: {
519
- dataTransfer: DataTransfer
520
- }
521
- position: EventPosition
522
- }
523
- | {
524
- type: StrictExtract<NativeBehaviorEventType, 'drag.dragover'>
525
- originEvent: {
526
- dataTransfer: DataTransfer
527
- }
528
- dragOrigin?: Pick<EventPosition, 'selection'>
529
- position: EventPosition
530
- }
531
- | {
532
- type: StrictExtract<NativeBehaviorEventType, 'drag.drop'>
533
- originEvent: {
534
- dataTransfer: DataTransfer
535
- }
536
- dragOrigin?: Pick<EventPosition, 'selection'>
537
- position: EventPosition
538
- }
539
- | {
540
- type: StrictExtract<NativeBehaviorEventType, 'drag.dragleave'>
541
- originEvent: {
542
- dataTransfer: DataTransfer
543
- }
544
- }
545
-
546
- /**
547
- * @public
548
- */
549
- declare type Editor = {
550
- dom: EditorDom
551
- getSnapshot: () => EditorSnapshot
552
- /**
553
- * @beta
554
- */
555
- registerBehavior: (config: {behavior: Behavior}) => () => void
556
- send: (event: EditorEvent) => void
557
- on: ActorRef<Snapshot<unknown>, EventObject, EditorEmittedEvent>['on']
558
- }
559
-
560
- /**
561
- * @public
562
- */
563
- declare type EditorContext = {
564
- converters: Array<Converter>
565
- keyGenerator: () => string
566
- readOnly: boolean
567
- schema: EditorSchema
568
- selection: EditorSelection
569
- value: Array<PortableTextBlock>
570
- }
571
-
572
- declare type EditorDom = {
573
- getBlockNodes: (snapshot: EditorSnapshot) => Array<Node>
574
- getChildNodes: (snapshot: EditorSnapshot) => Array<Node>
575
- /**
576
- * Let the Editor set the drag ghost. This is to be sure that it will get
577
- * properly removed again when the drag ends.
578
- */
579
- setDragGhost: ({
580
- event,
581
- ghost,
14
+ declare function DecoratorShortcutPlugin(config: {
15
+ decorator: ({
16
+ schema
582
17
  }: {
583
- event: PickFromUnion<BehaviorEvent, 'type', 'drag.dragstart'>
584
- ghost: {
585
- element: HTMLElement
586
- x: number
587
- y: number
588
- }
589
- }) => void
590
- }
591
-
592
- /**
593
- * @public
594
- */
595
- declare type EditorEmittedEvent =
596
- | {
597
- type: 'blurred'
598
- event: FocusEvent_2<HTMLDivElement, Element>
599
- }
600
- | {
601
- /**
602
- * @deprecated Will be removed in the next major version
603
- */
604
- type: 'done loading'
605
- }
606
- | {
607
- type: 'editable'
608
- }
609
- | ErrorEvent_2
610
- | {
611
- type: 'focused'
612
- event: FocusEvent_2<HTMLDivElement, Element>
613
- }
614
- | {
615
- type: 'invalid value'
616
- resolution: InvalidValueResolution | null
617
- value: Array<PortableTextBlock> | undefined
618
- }
619
- | {
620
- /**
621
- * @deprecated Will be removed in the next major version
622
- */
623
- type: 'loading'
624
- }
625
- | MutationEvent
626
- | PatchEvent
627
- | {
628
- type: 'read only'
629
- }
630
- | {
631
- type: 'ready'
632
- }
633
- | {
634
- type: 'selection'
635
- selection: EditorSelection
636
- }
637
- | {
638
- type: 'value changed'
639
- value: Array<PortableTextBlock> | undefined
640
- }
641
-
642
- /**
643
- * @public
644
- */
645
- declare type EditorEvent =
646
- | ExternalEditorEvent
647
- | ExternalBehaviorEvent
648
- | {
649
- type: 'update value'
650
- value: Array<PortableTextBlock> | undefined
651
- }
652
-
18
+ schema: EditorSchema;
19
+ }) => string | undefined;
20
+ pair: {
21
+ char: string;
22
+ amount: number;
23
+ };
24
+ }): null;
653
25
  /**
654
26
  * @beta
655
27
  */
656
- export declare const EditorRefPlugin: React_2.ForwardRefExoticComponent<
657
- React_2.RefAttributes<Editor | null>
658
- >
659
-
660
- /**
661
- * @public
662
- */
663
- declare type EditorSchema = {
664
- annotations: ReadonlyArray<AnnotationSchemaType>
665
- block: {
666
- name: string
667
- }
668
- blockObjects: ReadonlyArray<BlockObjectSchemaType>
669
- decorators: ReadonlyArray<DecoratorSchemaType>
670
- inlineObjects: ReadonlyArray<InlineObjectSchemaType>
671
- span: {
672
- name: string
673
- }
674
- styles: ReadonlyArray<StyleSchemaType>
675
- lists: ReadonlyArray<ListSchemaType>
676
- }
677
-
678
- /** @public */
679
- declare type EditorSelection = {
680
- anchor: EditorSelectionPoint
681
- focus: EditorSelectionPoint
682
- backward?: boolean
683
- } | null
684
-
685
- /** @public */
686
- declare type EditorSelectionPoint = {
687
- path: Path
688
- offset: number
689
- }
690
-
691
- /**
692
- * @public
693
- */
694
- declare type EditorSnapshot = {
695
- context: EditorContext
696
- blockIndexMap: Map<string, number>
697
- /**
698
- * @beta
699
- * Subject to change
700
- */
701
- decoratorState: Record<string, boolean | undefined>
702
- }
703
-
704
- /**
705
- * @deprecated The event is no longer emitted
706
- */
707
- declare type ErrorEvent_2 = {
708
- type: 'error'
709
- name: string
710
- description: string
711
- data: unknown
712
- }
713
-
28
+ declare const EditorRefPlugin: React.ForwardRefExoticComponent<React.RefAttributes<Editor | null>>;
714
29
  /**
715
30
  * @public
716
31
  * Listen for events emitted by the editor. Must be used inside `EditorProvider`. Events available include:
@@ -760,172 +75,60 @@ declare type ErrorEvent_2 = {
760
75
  * ```
761
76
  * @group Components
762
77
  */
763
- export declare function EventListenerPlugin(props: {
764
- on: (event: EditorEmittedEvent) => void
765
- }): null
766
-
767
- declare type EventPosition = {
768
- block: 'start' | 'end'
769
- /**
770
- * Did the event origin from the editor DOM node itself or from a child node?
771
- */
772
- isEditor: boolean
773
- selection: NonNullable<EditorSelection>
774
- }
775
-
776
- declare type ExternalBehaviorEvent =
777
- | {
778
- type: ExternalBehaviorEventType<'blur'>
779
- }
780
- | {
781
- type: ExternalBehaviorEventType<'focus'>
782
- }
783
- | {
784
- type: ExternalBehaviorEventType<'insert', 'block object'>
785
- placement: InsertPlacement
786
- blockObject: {
787
- name: string
788
- value?: {
789
- [prop: string]: unknown
790
- }
791
- }
792
- }
793
- | SyntheticBehaviorEvent
794
- | CustomBehaviorEvent
795
-
796
- /**************************************
797
- * External events
798
- **************************************/
799
- declare type ExternalBehaviorEventNamespace = 'blur' | 'focus' | 'insert'
800
-
801
- declare type ExternalBehaviorEventType<
802
- TNamespace extends ExternalBehaviorEventNamespace,
803
- TType extends string = '',
804
- > = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
805
-
806
- /**
807
- * @public
808
- */
809
- declare type ExternalEditorEvent =
810
- | {
811
- type: 'update readOnly'
812
- readOnly: boolean
813
- }
814
- | {
815
- type: 'update maxBlocks'
816
- maxBlocks: number | undefined
817
- }
818
- | PatchesEvent
819
-
820
- declare type ExtractNamespace<TType extends string> =
821
- TType extends `${infer Namespace}.${string}` ? Namespace : TType
822
-
823
- /**
824
- * @public
825
- */
826
- declare type FieldDefinition = BaseDefinition & {
827
- type: 'string' | 'number' | 'boolean' | 'array' | 'object'
828
- }
829
-
830
- /**
831
- * @public
832
- */
833
- declare type InlineObjectSchemaType = BaseDefinition & {
834
- fields: ReadonlyArray<FieldDefinition>
835
- }
836
-
837
- /**
838
- * Used to represent native InputEvents that hold a DataTransfer object.
839
- *
840
- * These can either be one of:
841
- *
842
- * - insertFromPaste
843
- * - insertFromPasteAsQuotation
844
- * - insertFromDrop
845
- * - insertReplacementText
846
- * - insertFromYank
847
- */
848
- declare type InputBehaviorEvent = {
849
- type: StrictExtract<NativeBehaviorEventType, 'input.*'>
850
- originEvent: {
851
- dataTransfer: DataTransfer
852
- }
853
- }
854
-
855
- /**
856
- * @beta
857
- */
858
- declare type InsertPlacement = 'auto' | 'after' | 'before'
859
-
860
- /**
861
- * The editor has invalid data in the value that can be resolved by the user
862
- * @beta */
863
- declare type InvalidValueResolution = {
864
- autoResolve?: boolean
865
- patches: Patch[]
866
- description: string
867
- action: string
868
- item: PortableTextBlock[] | PortableTextBlock | PortableTextChild | undefined
869
- /**
870
- * i18n keys for the description and action
871
- *
872
- * These are in addition to the description and action properties, to decouple the editor from
873
- * the i18n system, and allow usage without it. The i18n keys take precedence over the
874
- * description and action properties, if i18n framework is available.
875
- */
876
- i18n: {
877
- description: `inputs.portable-text.invalid-value.${Lowercase<string>}.description`
878
- action: `inputs.portable-text.invalid-value.${Lowercase<string>}.action`
879
- values?: Record<string, string | number | string[]>
880
- }
881
- }
882
-
883
- declare type KeyboardBehaviorEvent =
884
- | {
885
- type: StrictExtract<NativeBehaviorEventType, 'keyboard.keydown'>
886
- originEvent: Pick<
887
- KeyboardEvent,
888
- 'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'
889
- >
890
- }
891
- | {
892
- type: StrictExtract<NativeBehaviorEventType, 'keyboard.keyup'>
893
- originEvent: Pick<
894
- KeyboardEvent,
895
- 'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'
896
- >
897
- }
898
-
899
- /**
900
- * @public
901
- */
902
- declare type ListSchemaType = BaseDefinition & {
903
- /**
904
- * @deprecated
905
- * Use `name` instead
906
- */
907
- value: string
908
- }
909
-
910
- declare type MarkdownBehaviorsConfig = {
911
- horizontalRuleObject?: (context: {schema: EditorSchema}) =>
912
- | {
913
- name: string
914
- value?: {
915
- [prop: string]: unknown
916
- }
917
- }
918
- | undefined
919
- defaultStyle?: (context: {schema: EditorSchema}) => string | undefined
78
+ declare function EventListenerPlugin(props: {
79
+ on: (event: EditorEmittedEvent) => void;
80
+ }): null;
81
+ type MarkdownBehaviorsConfig = {
82
+ horizontalRuleObject?: (context: {
83
+ schema: EditorSchema;
84
+ }) => {
85
+ name: string;
86
+ value?: {
87
+ [prop: string]: unknown;
88
+ };
89
+ } | undefined;
90
+ defaultStyle?: (context: {
91
+ schema: EditorSchema;
92
+ }) => string | undefined;
920
93
  headingStyle?: (context: {
921
- schema: EditorSchema
922
- level: number
923
- }) => string | undefined
924
- blockquoteStyle?: (context: {schema: EditorSchema}) => string | undefined
925
- unorderedListStyle?: (context: {schema: EditorSchema}) => string | undefined
926
- orderedListStyle?: (context: {schema: EditorSchema}) => string | undefined
927
- }
928
-
94
+ schema: EditorSchema;
95
+ level: number;
96
+ }) => string | undefined;
97
+ blockquoteStyle?: (context: {
98
+ schema: EditorSchema;
99
+ }) => string | undefined;
100
+ unorderedListStyle?: (context: {
101
+ schema: EditorSchema;
102
+ }) => string | undefined;
103
+ orderedListStyle?: (context: {
104
+ schema: EditorSchema;
105
+ }) => string | undefined;
106
+ };
107
+ /**
108
+ * @beta
109
+ */
110
+ type MarkdownPluginConfig = MarkdownBehaviorsConfig & {
111
+ boldDecorator?: ({
112
+ schema
113
+ }: {
114
+ schema: EditorSchema;
115
+ }) => string | undefined;
116
+ codeDecorator?: ({
117
+ schema
118
+ }: {
119
+ schema: EditorSchema;
120
+ }) => string | undefined;
121
+ italicDecorator?: ({
122
+ schema
123
+ }: {
124
+ schema: EditorSchema;
125
+ }) => string | undefined;
126
+ strikeThroughDecorator?: ({
127
+ schema
128
+ }: {
129
+ schema: EditorSchema;
130
+ }) => string | undefined;
131
+ };
929
132
  /**
930
133
  * @beta
931
134
  * Add markdown behaviors for common markdown actions such as converting ### to headings, --- to HRs, and more.
@@ -976,89 +179,9 @@ declare type MarkdownBehaviorsConfig = {
976
179
  *
977
180
  * @deprecated Install the plugin from `@portabletext/plugin-markdown-shortcuts`
978
181
  */
979
- export declare function MarkdownPlugin(props: {
980
- config: MarkdownPluginConfig
981
- }): JSX.Element
982
-
983
- /**
984
- * @beta
985
- */
986
- export declare type MarkdownPluginConfig = MarkdownBehaviorsConfig & {
987
- boldDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined
988
- codeDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined
989
- italicDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined
990
- strikeThroughDecorator?: ({
991
- schema,
992
- }: {
993
- schema: EditorSchema
994
- }) => string | undefined
995
- }
996
-
997
- declare type MIMEType = `${string}/${string}`
998
-
999
- declare type MouseBehaviorEvent = {
1000
- type: StrictExtract<NativeBehaviorEventType, 'mouse.click'>
1001
- position: EventPosition
1002
- }
1003
-
1004
- /**
1005
- * @public
1006
- */
1007
- declare type MutationEvent = {
1008
- type: 'mutation'
1009
- patches: Array<Patch>
1010
- /**
1011
- * @deprecated Use `value` instead
1012
- */
1013
- snapshot: Array<PortableTextBlock> | undefined
1014
- value: Array<PortableTextBlock> | undefined
1015
- }
1016
-
1017
- declare type NamespacedBehaviorEventType<
1018
- TNamespace extends BehaviorEventTypeNamespace | '',
1019
- > = TNamespace extends ''
1020
- ? BehaviorEvent['type']
1021
- : Extract<BehaviorEvent['type'], TNamespace | `${TNamespace}.${string}`>
1022
-
1023
- /**
1024
- * @beta
1025
- */
1026
- declare type NativeBehaviorEvent =
1027
- | ClipboardBehaviorEvent
1028
- | DragBehaviorEvent
1029
- | InputBehaviorEvent
1030
- | KeyboardBehaviorEvent
1031
- | MouseBehaviorEvent
1032
-
1033
- declare type NativeBehaviorEventNamespace =
1034
- ExtractNamespace<NativeBehaviorEventType>
1035
-
1036
- declare type NativeBehaviorEventType = (typeof nativeBehaviorEventTypes)[number]
1037
-
1038
- /**************************************
1039
- * Native events
1040
- **************************************/
1041
- declare const nativeBehaviorEventTypes: readonly [
1042
- 'clipboard.copy',
1043
- 'clipboard.cut',
1044
- 'clipboard.paste',
1045
- 'drag.dragstart',
1046
- 'drag.drag',
1047
- 'drag.dragend',
1048
- 'drag.dragenter',
1049
- 'drag.dragover',
1050
- 'drag.dragleave',
1051
- 'drag.drop',
1052
- 'input.*',
1053
- 'keyboard.keydown',
1054
- 'keyboard.keyup',
1055
- 'mouse.click',
1056
- ]
1057
-
1058
- declare type ObjectBlockWithOptionalKey = Omit<PortableTextObject, '_key'> & {
1059
- _key?: PortableTextObject['_key']
1060
- }
1061
-
182
+ declare function MarkdownPlugin(props: {
183
+ config: MarkdownPluginConfig;
184
+ }): react12.JSX.Element;
1062
185
  /**
1063
186
  * @beta
1064
187
  * Restrict the editor to one line. The plugin takes care of blocking
@@ -1069,235 +192,5 @@ declare type ObjectBlockWithOptionalKey = Omit<PortableTextObject, '_key'> & {
1069
192
  *
1070
193
  * @deprecated Install the plugin from `@portabletext/plugin-one-line`
1071
194
  */
1072
- export declare function OneLinePlugin(): JSX.Element
1073
-
1074
- /**
1075
- * @public
1076
- */
1077
- declare type PatchesEvent = {
1078
- type: 'patches'
1079
- patches: Array<Patch>
1080
- snapshot: Array<PortableTextBlock> | undefined
1081
- }
1082
-
1083
- declare type PatchEvent = {
1084
- type: 'patch'
1085
- patch: Patch
1086
- }
1087
-
1088
- /**
1089
- * @internal
1090
- */
1091
- declare type PickFromUnion<
1092
- TUnion,
1093
- TTagKey extends keyof TUnion,
1094
- TPickedTags extends TUnion[TTagKey],
1095
- > = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never
1096
-
1097
- /**************************************
1098
- * Resolve behavior event
1099
- **************************************/
1100
- declare type ResolveBehaviorEvent<
1101
- TBehaviorEventType extends
1102
- | '*'
1103
- | `${BehaviorEventTypeNamespace}.*`
1104
- | BehaviorEvent['type'],
1105
- TPayload extends Record<string, unknown> = Record<string, unknown>,
1106
- > = TBehaviorEventType extends '*'
1107
- ? BehaviorEvent
1108
- : TBehaviorEventType extends `${infer TNamespace}.*`
1109
- ? TNamespace extends BehaviorEventTypeNamespace
1110
- ? PickFromUnion<
1111
- BehaviorEvent,
1112
- 'type',
1113
- NamespacedBehaviorEventType<TNamespace>
1114
- >
1115
- : never
1116
- : TBehaviorEventType extends `custom.${infer TType}`
1117
- ? CustomBehaviorEvent<TPayload, TType>
1118
- : TBehaviorEventType extends BehaviorEvent['type']
1119
- ? PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
1120
- : never
1121
-
1122
- declare type Serializer<TMIMEType extends MIMEType> = ({
1123
- snapshot,
1124
- event,
1125
- }: {
1126
- snapshot: EditorSnapshot
1127
- event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialize'>
1128
- }) => PickFromUnion<
1129
- ConverterEvent<TMIMEType>,
1130
- 'type',
1131
- 'serialization.success' | 'serialization.failure'
1132
- >
1133
-
1134
- declare type StrictExtract<T, U extends T> = U
1135
-
1136
- /**
1137
- * @public
1138
- */
1139
- declare type StyleSchemaType = BaseDefinition & {
1140
- /**
1141
- * @deprecated
1142
- * Use `name` instead
1143
- */
1144
- value: string
1145
- }
1146
-
1147
- /**
1148
- * @beta
1149
- */
1150
- declare type SyntheticBehaviorEvent =
1151
- | {
1152
- type: StrictExtract<SyntheticBehaviorEventType, 'annotation.add'>
1153
- annotation: {
1154
- name: string
1155
- value: {
1156
- [prop: string]: unknown
1157
- }
1158
- }
1159
- }
1160
- | {
1161
- type: StrictExtract<SyntheticBehaviorEventType, 'annotation.remove'>
1162
- annotation: {
1163
- name: string
1164
- }
1165
- }
1166
- | {
1167
- type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
1168
- at: BlockPath
1169
- props: Record<string, unknown>
1170
- }
1171
- | {
1172
- type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
1173
- at: BlockPath
1174
- props: Array<string>
1175
- }
1176
- | {
1177
- type: StrictExtract<SyntheticBehaviorEventType, 'child.set'>
1178
- at: ChildPath
1179
- props: {
1180
- [prop: string]: unknown
1181
- }
1182
- }
1183
- | {
1184
- type: StrictExtract<SyntheticBehaviorEventType, 'child.unset'>
1185
- at: ChildPath
1186
- props: Array<string>
1187
- }
1188
- | {
1189
- type: StrictExtract<SyntheticBehaviorEventType, 'decorator.add'>
1190
- decorator: string
1191
- at?: {
1192
- anchor: BlockOffset
1193
- focus: BlockOffset
1194
- }
1195
- }
1196
- | {
1197
- type: StrictExtract<SyntheticBehaviorEventType, 'decorator.remove'>
1198
- decorator: string
1199
- }
1200
- | {
1201
- type: StrictExtract<SyntheticBehaviorEventType, 'delete'>
1202
- at: NonNullable<EditorSelection>
1203
- /**
1204
- * Defaults to forward deletion.
1205
- */
1206
- direction?: 'backward' | 'forward'
1207
- /**
1208
- * Defaults to character deletion.
1209
- */
1210
- unit?: 'character' | 'word' | 'line' | 'block'
1211
- }
1212
- | {
1213
- type: StrictExtract<SyntheticBehaviorEventType, 'history.redo'>
1214
- }
1215
- | {
1216
- type: StrictExtract<SyntheticBehaviorEventType, 'history.undo'>
1217
- }
1218
- | {
1219
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.inline object'>
1220
- inlineObject: {
1221
- name: string
1222
- value?: {
1223
- [prop: string]: unknown
1224
- }
1225
- }
1226
- }
1227
- | {
1228
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.block'>
1229
- block: BlockWithOptionalKey
1230
- placement: InsertPlacement
1231
- select?: 'start' | 'end' | 'none'
1232
- }
1233
- | {
1234
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.span'>
1235
- text: string
1236
- annotations?: Array<{
1237
- name: string
1238
- value: {
1239
- [prop: string]: unknown
1240
- }
1241
- }>
1242
- decorators?: Array<string>
1243
- }
1244
- | {
1245
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
1246
- text: string
1247
- }
1248
- | {
1249
- type: StrictExtract<SyntheticBehaviorEventType, 'move.backward'>
1250
- distance: number
1251
- }
1252
- | {
1253
- type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
1254
- at: BlockPath
1255
- to: BlockPath
1256
- }
1257
- | {
1258
- type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
1259
- distance: number
1260
- }
1261
- | {
1262
- type: StrictExtract<SyntheticBehaviorEventType, 'select'>
1263
- at: EditorSelection
1264
- }
1265
- | AbstractBehaviorEvent
1266
-
1267
- declare type SyntheticBehaviorEventNamespace =
1268
- ExtractNamespace<SyntheticBehaviorEventType>
1269
-
1270
- declare type SyntheticBehaviorEventType =
1271
- | (typeof syntheticBehaviorEventTypes)[number]
1272
- | (typeof abstractBehaviorEventTypes)[number]
1273
-
1274
- /**************************************
1275
- * Synthetic events
1276
- **************************************/
1277
- declare const syntheticBehaviorEventTypes: readonly [
1278
- 'annotation.add',
1279
- 'annotation.remove',
1280
- 'block.set',
1281
- 'block.unset',
1282
- 'child.set',
1283
- 'child.unset',
1284
- 'decorator.add',
1285
- 'decorator.remove',
1286
- 'delete',
1287
- 'history.redo',
1288
- 'history.undo',
1289
- 'insert.inline object',
1290
- 'insert.block',
1291
- 'insert.span',
1292
- 'insert.text',
1293
- 'move.backward',
1294
- 'move.block',
1295
- 'move.forward',
1296
- 'select',
1297
- ]
1298
-
1299
- declare type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
1300
- _key?: PortableTextTextBlock['_key']
1301
- }
1302
-
1303
- export {}
195
+ declare function OneLinePlugin(): react12.JSX.Element;
196
+ export { BehaviorPlugin, DecoratorShortcutPlugin, EditorRefPlugin, EventListenerPlugin, MarkdownPlugin, type MarkdownPluginConfig, OneLinePlugin };