@portabletext/editor 1.1.4 → 1.1.5

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 (32) hide show
  1. package/lib/index.d.mts +228 -30
  2. package/lib/index.d.ts +228 -30
  3. package/lib/index.esm.js +88 -100
  4. package/lib/index.esm.js.map +1 -1
  5. package/lib/index.js +88 -100
  6. package/lib/index.js.map +1 -1
  7. package/lib/index.mjs +88 -100
  8. package/lib/index.mjs.map +1 -1
  9. package/package.json +24 -19
  10. package/src/editor/Editable.tsx +6 -11
  11. package/src/editor/PortableTextEditor.tsx +26 -30
  12. package/src/editor/__tests__/self-solving.test.tsx +1 -1
  13. package/src/editor/components/SlateContainer.tsx +2 -13
  14. package/src/editor/components/Synchronizer.tsx +0 -3
  15. package/src/editor/editor-machine.ts +7 -2
  16. package/src/editor/hooks/useSyncValue.ts +3 -5
  17. package/src/editor/key-generator.ts +6 -0
  18. package/src/editor/plugins/createWithEditableAPI.ts +8 -5
  19. package/src/editor/plugins/createWithHotKeys.ts +1 -0
  20. package/src/editor/plugins/createWithInsertBreak.ts +6 -2
  21. package/src/editor/plugins/createWithInsertData.ts +7 -4
  22. package/src/editor/plugins/createWithObjectKeys.ts +12 -5
  23. package/src/editor/plugins/createWithPatches.ts +0 -1
  24. package/src/editor/plugins/createWithPortableTextMarkModel.ts +4 -5
  25. package/src/editor/plugins/createWithSchemaTypes.ts +3 -4
  26. package/src/editor/plugins/createWithUtils.ts +5 -4
  27. package/src/editor/plugins/index.ts +5 -13
  28. package/src/index.ts +2 -2
  29. package/src/types/options.ts +0 -1
  30. package/src/utils/__tests__/operationToPatches.test.ts +0 -2
  31. package/src/utils/__tests__/patchToOperations.test.ts +1 -2
  32. 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,13 +39,24 @@ 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
 
@@ -153,7 +163,6 @@ export declare type ConnectionChange = {
153
163
  * @internal
154
164
  */
155
165
  export declare type createEditorOptions = {
156
- keyGenerator: () => string
157
166
  patches$?: PatchObservable
158
167
  portableTextEditor: PortableTextEditor
159
168
  readOnly: boolean
@@ -265,6 +274,7 @@ export declare type EditorChanges = Subject<EditorChange>
265
274
  */
266
275
  export declare const editorMachine: StateMachine<
267
276
  {
277
+ keyGenerator: () => string
268
278
  pendingEvents: Array<PatchEvent | MutationEvent_2>
269
279
  },
270
280
  | PatchEvent
@@ -362,7 +372,9 @@ export declare const editorMachine: StateMachine<
362
372
  pristine: 'normalizing' | 'idle'
363
373
  },
364
374
  string,
365
- NonReducibleUnknown,
375
+ {
376
+ keyGenerator: () => string
377
+ },
366
378
  NonReducibleUnknown,
367
379
  | PatchEvent
368
380
  | MutationEvent_2
@@ -415,8 +427,205 @@ export declare const editorMachine: StateMachine<
415
427
  MetaObject,
416
428
  {
417
429
  readonly id: 'editor'
418
- readonly context: {
419
- readonly pendingEvents: []
430
+ readonly context: ({
431
+ input,
432
+ }: {
433
+ spawn: {
434
+ <TSrc extends 'networkLogic'>(
435
+ logic: TSrc,
436
+ ...[options]: {
437
+ src: 'networkLogic'
438
+ logic: CallbackActorLogic<
439
+ EventObject,
440
+ NonReducibleUnknown,
441
+ EventObject
442
+ >
443
+ id: string | undefined
444
+ } extends infer T
445
+ ? T extends {
446
+ src: 'networkLogic'
447
+ logic: CallbackActorLogic<
448
+ EventObject,
449
+ NonReducibleUnknown,
450
+ EventObject
451
+ >
452
+ id: string | undefined
453
+ }
454
+ ? T extends {
455
+ src: TSrc
456
+ }
457
+ ? ConditionalRequired<
458
+ [
459
+ options?:
460
+ | ({
461
+ id?: T['id'] | undefined
462
+ systemId?: string
463
+ input?: InputFrom<T['logic']> | undefined
464
+ syncSnapshot?: boolean
465
+ } & {[K in RequiredActorOptions<T>]: unknown})
466
+ | undefined,
467
+ ],
468
+ IsNotNever<RequiredActorOptions<T>>
469
+ >
470
+ : never
471
+ : never
472
+ : never
473
+ ): ActorRefFromLogic<
474
+ GetConcreteByKey<
475
+ {
476
+ src: 'networkLogic'
477
+ logic: CallbackActorLogic<
478
+ EventObject,
479
+ NonReducibleUnknown,
480
+ EventObject
481
+ >
482
+ id: string | undefined
483
+ },
484
+ 'src',
485
+ TSrc
486
+ >['logic']
487
+ >
488
+ <TLogic extends AnyActorLogic>(
489
+ src: TLogic,
490
+ options?:
491
+ | {
492
+ id?: never
493
+ systemId?: string
494
+ input?: InputFrom<TLogic> | undefined
495
+ syncSnapshot?: boolean
496
+ }
497
+ | undefined,
498
+ ): ActorRefFromLogic<TLogic>
499
+ }
500
+ input: {
501
+ keyGenerator: () => string
502
+ }
503
+ self: ActorRef<
504
+ MachineSnapshot<
505
+ {
506
+ keyGenerator: () => string
507
+ pendingEvents: Array<PatchEvent | MutationEvent_2>
508
+ },
509
+ | PatchEvent
510
+ | MutationEvent_2
511
+ | {
512
+ type: 'normalizing'
513
+ }
514
+ | {
515
+ type: 'done normalizing'
516
+ }
517
+ | {
518
+ type: 'ready'
519
+ }
520
+ | {
521
+ type: 'unset'
522
+ previousValue: Array<PortableTextBlock>
523
+ }
524
+ | {
525
+ type: 'value changed'
526
+ value: Array<PortableTextBlock> | undefined
527
+ }
528
+ | {
529
+ type: 'invalid value'
530
+ resolution: InvalidValueResolution | null
531
+ value: Array<PortableTextBlock> | undefined
532
+ }
533
+ | {
534
+ type: 'error'
535
+ name: string
536
+ description: string
537
+ data: unknown
538
+ }
539
+ | {
540
+ type: 'selection'
541
+ selection: EditorSelection
542
+ }
543
+ | {
544
+ type: 'blur'
545
+ event: FocusEvent_2<HTMLDivElement, Element>
546
+ }
547
+ | {
548
+ type: 'focus'
549
+ event: FocusEvent_2<HTMLDivElement, Element>
550
+ }
551
+ | {
552
+ type: 'online'
553
+ }
554
+ | {
555
+ type: 'offline'
556
+ }
557
+ | {
558
+ type: 'loading'
559
+ }
560
+ | {
561
+ type: 'done loading'
562
+ },
563
+ Record<string, AnyActorRef | undefined>,
564
+ StateValue,
565
+ string,
566
+ unknown,
567
+ any,
568
+ any
569
+ >,
570
+ | PatchEvent
571
+ | MutationEvent_2
572
+ | {
573
+ type: 'normalizing'
574
+ }
575
+ | {
576
+ type: 'done normalizing'
577
+ }
578
+ | {
579
+ type: 'ready'
580
+ }
581
+ | {
582
+ type: 'unset'
583
+ previousValue: Array<PortableTextBlock>
584
+ }
585
+ | {
586
+ type: 'value changed'
587
+ value: Array<PortableTextBlock> | undefined
588
+ }
589
+ | {
590
+ type: 'invalid value'
591
+ resolution: InvalidValueResolution | null
592
+ value: Array<PortableTextBlock> | undefined
593
+ }
594
+ | {
595
+ type: 'error'
596
+ name: string
597
+ description: string
598
+ data: unknown
599
+ }
600
+ | {
601
+ type: 'selection'
602
+ selection: EditorSelection
603
+ }
604
+ | {
605
+ type: 'blur'
606
+ event: FocusEvent_2<HTMLDivElement, Element>
607
+ }
608
+ | {
609
+ type: 'focus'
610
+ event: FocusEvent_2<HTMLDivElement, Element>
611
+ }
612
+ | {
613
+ type: 'online'
614
+ }
615
+ | {
616
+ type: 'offline'
617
+ }
618
+ | {
619
+ type: 'loading'
620
+ }
621
+ | {
622
+ type: 'done loading'
623
+ },
624
+ AnyEventObject
625
+ >
626
+ }) => {
627
+ keyGenerator: () => string
628
+ pendingEvents: never[]
420
629
  }
421
630
  readonly invoke: {
422
631
  readonly id: 'networkLogic'
@@ -426,6 +635,7 @@ export declare const editorMachine: StateMachine<
426
635
  readonly 'ready': {
427
636
  readonly actions: ActionFunction<
428
637
  {
638
+ keyGenerator: () => string
429
639
  pendingEvents: Array<PatchEvent | MutationEvent_2>
430
640
  },
431
641
  {
@@ -543,6 +753,7 @@ export declare const editorMachine: StateMachine<
543
753
  readonly 'unset': {
544
754
  readonly actions: ActionFunction<
545
755
  {
756
+ keyGenerator: () => string
546
757
  pendingEvents: Array<PatchEvent | MutationEvent_2>
547
758
  },
548
759
  {
@@ -661,6 +872,7 @@ export declare const editorMachine: StateMachine<
661
872
  readonly 'value changed': {
662
873
  readonly actions: ActionFunction<
663
874
  {
875
+ keyGenerator: () => string
664
876
  pendingEvents: Array<PatchEvent | MutationEvent_2>
665
877
  },
666
878
  {
@@ -779,6 +991,7 @@ export declare const editorMachine: StateMachine<
779
991
  readonly 'invalid value': {
780
992
  readonly actions: ActionFunction<
781
993
  {
994
+ keyGenerator: () => string
782
995
  pendingEvents: Array<PatchEvent | MutationEvent_2>
783
996
  },
784
997
  {
@@ -898,6 +1111,7 @@ export declare const editorMachine: StateMachine<
898
1111
  readonly 'error': {
899
1112
  readonly actions: ActionFunction<
900
1113
  {
1114
+ keyGenerator: () => string
901
1115
  pendingEvents: Array<PatchEvent | MutationEvent_2>
902
1116
  },
903
1117
  {
@@ -1018,6 +1232,7 @@ export declare const editorMachine: StateMachine<
1018
1232
  readonly 'selection': {
1019
1233
  readonly actions: ActionFunction<
1020
1234
  {
1235
+ keyGenerator: () => string
1021
1236
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1022
1237
  },
1023
1238
  {
@@ -1136,6 +1351,7 @@ export declare const editorMachine: StateMachine<
1136
1351
  readonly 'blur': {
1137
1352
  readonly actions: ActionFunction<
1138
1353
  {
1354
+ keyGenerator: () => string
1139
1355
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1140
1356
  },
1141
1357
  {
@@ -1254,6 +1470,7 @@ export declare const editorMachine: StateMachine<
1254
1470
  readonly 'focus': {
1255
1471
  readonly actions: ActionFunction<
1256
1472
  {
1473
+ keyGenerator: () => string
1257
1474
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1258
1475
  },
1259
1476
  {
@@ -1372,6 +1589,7 @@ export declare const editorMachine: StateMachine<
1372
1589
  readonly 'online': {
1373
1590
  readonly actions: ActionFunction<
1374
1591
  {
1592
+ keyGenerator: () => string
1375
1593
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1376
1594
  },
1377
1595
  {
@@ -1489,6 +1707,7 @@ export declare const editorMachine: StateMachine<
1489
1707
  readonly 'offline': {
1490
1708
  readonly actions: ActionFunction<
1491
1709
  {
1710
+ keyGenerator: () => string
1492
1711
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1493
1712
  },
1494
1713
  {
@@ -1606,6 +1825,7 @@ export declare const editorMachine: StateMachine<
1606
1825
  readonly 'loading': {
1607
1826
  readonly actions: ActionFunction<
1608
1827
  {
1828
+ keyGenerator: () => string
1609
1829
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1610
1830
  },
1611
1831
  {
@@ -1723,6 +1943,7 @@ export declare const editorMachine: StateMachine<
1723
1943
  readonly 'done loading': {
1724
1944
  readonly actions: ActionFunction<
1725
1945
  {
1946
+ keyGenerator: () => string
1726
1947
  pendingEvents: Array<PatchEvent | MutationEvent_2>
1727
1948
  },
1728
1949
  {
@@ -2082,31 +2303,8 @@ export declare type PatchObservable = Observable<{
2082
2303
  * @public
2083
2304
  */
2084
2305
  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>
2306
+ Omit<PortableTextEditableProps, 'ref'> &
2307
+ RefAttributes<Omit<HTMLDivElement, 'onPaste' | 'onBeforeInput' | 'as'>>
2110
2308
  >
2111
2309
 
2112
2310
  /**