@portabletext/editor 1.48.8 → 1.48.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.48.8",
3
+ "version": "1.48.10",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -79,8 +79,8 @@
79
79
  "slate-react": "0.114.2",
80
80
  "use-effect-event": "^1.0.2",
81
81
  "xstate": "^5.19.2",
82
- "@portabletext/block-tools": "1.1.22",
83
- "@portabletext/patches": "1.1.3"
82
+ "@portabletext/patches": "1.1.3",
83
+ "@portabletext/block-tools": "1.1.22"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@portabletext/toolkit": "^2.0.17",
@@ -115,6 +115,7 @@
115
115
  },
116
116
  "peerDependencies": {
117
117
  "@sanity/schema": "^3.87.0",
118
+ "@sanity/types": "^3.87.0",
118
119
  "react": "^16.9 || ^17 || ^18 || ^19",
119
120
  "rxjs": "^7.8.2"
120
121
  },
@@ -179,7 +179,10 @@ export type InternalEditorEvent =
179
179
  type: 'done normalizing'
180
180
  }
181
181
  | {
182
- type: 'done syncing initial value'
182
+ type: 'done syncing value'
183
+ }
184
+ | {
185
+ type: 'syncing value'
183
186
  }
184
187
  | {
185
188
  type: 'behavior event'
@@ -219,6 +222,7 @@ export const editorMachine = setup({
219
222
  getLegacySchema: () => PortableTextMemberSchemaTypes
220
223
  keyGenerator: () => string
221
224
  pendingEvents: Array<InternalPatchEvent | MutationEvent>
225
+ pendingIncomingPatchesEvents: Array<PatchesEvent>
222
226
  schema: EditorSchema
223
227
  initialReadOnly: boolean
224
228
  maxBlocks: number | undefined
@@ -305,6 +309,21 @@ export const editorMachine = setup({
305
309
  'clear pending events': assign({
306
310
  pendingEvents: [],
307
311
  }),
312
+ 'defer incoming patches': assign({
313
+ pendingIncomingPatchesEvents: ({context, event}) => {
314
+ return event.type === 'patches'
315
+ ? [...context.pendingIncomingPatchesEvents, event]
316
+ : context.pendingIncomingPatchesEvents
317
+ },
318
+ }),
319
+ 'emit pending incoming patches': enqueueActions(({context, enqueue}) => {
320
+ for (const event of context.pendingIncomingPatchesEvents) {
321
+ enqueue.emit(event)
322
+ }
323
+ }),
324
+ 'clear pending incoming patches': assign({
325
+ pendingIncomingPatchesEvents: [],
326
+ }),
308
327
  'handle blur': ({event}) => {
309
328
  assertEvent(event, 'blur')
310
329
 
@@ -372,6 +391,7 @@ export const editorMachine = setup({
372
391
  getLegacySchema: input.getLegacySchema,
373
392
  keyGenerator: input.keyGenerator,
374
393
  pendingEvents: [],
394
+ pendingIncomingPatchesEvents: [],
375
395
  schema: input.schema,
376
396
  selection: null,
377
397
  initialReadOnly: input.readOnly ?? false,
@@ -404,7 +424,6 @@ export const editorMachine = setup({
404
424
 
405
425
  'add behavior': {actions: 'add behavior to context'},
406
426
  'remove behavior': {actions: 'remove behavior from context'},
407
- 'patches': {actions: emit(({event}) => event)},
408
427
  'update behaviors': {actions: 'assign behaviors'},
409
428
  'update key generator': {
410
429
  actions: assign({keyGenerator: ({event}) => event.keyGenerator}),
@@ -439,7 +458,7 @@ export const editorMachine = setup({
439
458
  states: {
440
459
  'determine initial edit mode': {
441
460
  on: {
442
- 'done syncing initial value': [
461
+ 'done syncing value': [
443
462
  {
444
463
  target: '#editor.edit mode.read only.read only',
445
464
  guard: ({context}) => context.initialReadOnly,
@@ -553,7 +572,11 @@ export const editorMachine = setup({
553
572
  initial: 'setting up',
554
573
  states: {
555
574
  'setting up': {
556
- exit: ['emit ready'],
575
+ exit: [
576
+ 'emit ready',
577
+ 'emit pending incoming patches',
578
+ 'clear pending incoming patches',
579
+ ],
557
580
  on: {
558
581
  'internal.patch': {
559
582
  actions: 'defer event',
@@ -561,55 +584,97 @@ export const editorMachine = setup({
561
584
  'mutation': {
562
585
  actions: 'defer event',
563
586
  },
564
- 'done syncing initial value': {
565
- target: 'pristine',
587
+ 'done syncing value': {
588
+ target: 'set up',
589
+ },
590
+ 'patches': {
591
+ actions: ['defer incoming patches'],
566
592
  },
567
593
  },
568
594
  },
569
- 'pristine': {
570
- initial: 'idle',
595
+ 'set up': {
596
+ type: 'parallel',
571
597
  states: {
572
- idle: {
573
- on: {
574
- 'normalizing': {
575
- target: 'normalizing',
576
- },
577
- 'internal.patch': {
578
- actions: 'defer event',
579
- target: '#editor.setup.dirty',
598
+ 'value sync': {
599
+ initial: 'idle',
600
+ states: {
601
+ 'idle': {
602
+ on: {
603
+ 'patches': {
604
+ actions: [emit(({event}) => event)],
605
+ },
606
+ 'syncing value': {
607
+ target: 'syncing value',
608
+ },
609
+ },
580
610
  },
581
- 'mutation': {
582
- actions: 'defer event',
583
- target: '#editor.setup.dirty',
611
+ 'syncing value': {
612
+ exit: [
613
+ 'emit pending incoming patches',
614
+ 'clear pending incoming patches',
615
+ ],
616
+ on: {
617
+ 'patches': {
618
+ actions: ['defer incoming patches'],
619
+ },
620
+ 'done syncing value': {
621
+ target: 'idle',
622
+ },
623
+ },
584
624
  },
585
625
  },
586
626
  },
587
- normalizing: {
588
- on: {
589
- 'done normalizing': {
590
- target: 'idle',
591
- },
592
- 'internal.patch': {
593
- actions: 'defer event',
627
+ 'writing': {
628
+ initial: 'pristine',
629
+ states: {
630
+ pristine: {
631
+ initial: 'idle',
632
+ states: {
633
+ idle: {
634
+ on: {
635
+ 'normalizing': {
636
+ target: 'normalizing',
637
+ },
638
+ 'internal.patch': {
639
+ actions: 'defer event',
640
+ target: '#editor.setup.set up.writing.dirty',
641
+ },
642
+ 'mutation': {
643
+ actions: 'defer event',
644
+ target: '#editor.setup.set up.writing.dirty',
645
+ },
646
+ },
647
+ },
648
+ normalizing: {
649
+ on: {
650
+ 'done normalizing': {
651
+ target: 'idle',
652
+ },
653
+ 'internal.patch': {
654
+ actions: 'defer event',
655
+ },
656
+ 'mutation': {
657
+ actions: 'defer event',
658
+ },
659
+ },
660
+ },
661
+ },
594
662
  },
595
- 'mutation': {
596
- actions: 'defer event',
663
+ dirty: {
664
+ entry: ['emit pending events', 'clear pending events'],
665
+ on: {
666
+ 'internal.patch': {
667
+ actions: 'emit patch event',
668
+ },
669
+ 'mutation': {
670
+ actions: 'emit mutation event',
671
+ },
672
+ },
597
673
  },
598
674
  },
599
675
  },
600
676
  },
601
677
  },
602
- 'dirty': {
603
- entry: ['emit pending events', 'clear pending events'],
604
- on: {
605
- 'internal.patch': {
606
- actions: 'emit patch event',
607
- },
608
- 'mutation': {
609
- actions: 'emit mutation event',
610
- },
611
- },
612
- },
613
678
  },
614
679
  },
615
680
  },
@@ -126,7 +126,8 @@ export const syncMachine = setup({
126
126
  'type',
127
127
  'invalid value' | 'patch' | 'value changed'
128
128
  >
129
- | {type: 'done syncing initial value'},
129
+ | {type: 'done syncing value'}
130
+ | {type: 'syncing value'},
130
131
  },
131
132
  actions: {
132
133
  'assign initial value synced': assign({
@@ -153,8 +154,11 @@ export const syncMachine = setup({
153
154
  return event.value
154
155
  },
155
156
  }),
156
- 'emit done syncing initial value': emit({
157
- type: 'done syncing initial value',
157
+ 'emit done syncing value': emit({
158
+ type: 'done syncing value',
159
+ }),
160
+ 'emit syncing value': emit({
161
+ type: 'syncing value',
158
162
  }),
159
163
  },
160
164
  guards: {
@@ -230,7 +234,7 @@ export const syncMachine = setup({
230
234
  },
231
235
  'done syncing initial value': {
232
236
  entry: [
233
- 'emit done syncing initial value',
237
+ 'emit done syncing value',
234
238
  () => {
235
239
  debug('entry: done syncing initial value')
236
240
  },
@@ -313,11 +317,13 @@ export const syncMachine = setup({
313
317
  () => {
314
318
  debug('entry: syncing->syncing')
315
319
  },
320
+ 'emit syncing value',
316
321
  ],
317
322
  exit: [
318
323
  () => {
319
324
  debug('exit: syncing->syncing')
320
325
  },
326
+ 'emit done syncing value',
321
327
  ],
322
328
  always: {
323
329
  guard: 'pending value equals previous value',