@portabletext/editor 1.49.5 → 1.49.7

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.49.5",
3
+ "version": "1.49.7",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -383,6 +383,7 @@ async function updateValue({
383
383
  streamBlocks: boolean
384
384
  value: PortableTextBlock[] | undefined
385
385
  }) {
386
+ let doneSyncing = false
386
387
  let isChanged = false
387
388
  let isValid = true
388
389
 
@@ -394,6 +395,10 @@ async function updateValue({
394
395
  Editor.withoutNormalizing(slateEditor, () => {
395
396
  withoutSaving(slateEditor, () => {
396
397
  withoutPatching(slateEditor, () => {
398
+ if (doneSyncing) {
399
+ return
400
+ }
401
+
397
402
  if (hadSelection) {
398
403
  Transforms.deselect(slateEditor)
399
404
  }
@@ -427,32 +432,41 @@ async function updateValue({
427
432
  await new Promise<void>((resolve) => {
428
433
  Editor.withoutNormalizing(slateEditor, () => {
429
434
  withRemoteChanges(slateEditor, () => {
430
- withoutPatching(slateEditor, async () => {
435
+ withoutPatching(slateEditor, () => {
436
+ if (doneSyncing) {
437
+ resolve()
438
+ return
439
+ }
440
+
431
441
  isChanged = removeExtraBlocks({
432
442
  slateEditor,
433
443
  slateValueFromProps,
434
444
  })
435
445
 
436
- for await (const [
437
- currentBlock,
438
- currentBlockIndex,
439
- ] of getStreamedBlocks({
440
- slateValue: slateValueFromProps,
441
- })) {
442
- const {blockChanged, blockValid} = syncBlock({
443
- context,
444
- sendBack,
445
- block: currentBlock,
446
- index: currentBlockIndex,
447
- slateEditor,
448
- value,
449
- })
446
+ const processBlocks = async () => {
447
+ for await (const [
448
+ currentBlock,
449
+ currentBlockIndex,
450
+ ] of getStreamedBlocks({
451
+ slateValue: slateValueFromProps,
452
+ })) {
453
+ const {blockChanged, blockValid} = syncBlock({
454
+ context,
455
+ sendBack,
456
+ block: currentBlock,
457
+ index: currentBlockIndex,
458
+ slateEditor,
459
+ value,
460
+ })
461
+
462
+ isChanged = blockChanged || isChanged
463
+ isValid = isValid && blockValid
464
+ }
450
465
 
451
- isChanged = blockChanged || isChanged
452
- isValid = isValid && blockValid
466
+ resolve()
453
467
  }
454
468
 
455
- resolve()
469
+ processBlocks()
456
470
  })
457
471
  })
458
472
  })
@@ -461,6 +475,10 @@ async function updateValue({
461
475
  Editor.withoutNormalizing(slateEditor, () => {
462
476
  withRemoteChanges(slateEditor, () => {
463
477
  withoutPatching(slateEditor, () => {
478
+ if (doneSyncing) {
479
+ return
480
+ }
481
+
464
482
  isChanged = removeExtraBlocks({
465
483
  slateEditor,
466
484
  slateValueFromProps,
@@ -490,6 +508,7 @@ async function updateValue({
490
508
 
491
509
  if (!isValid) {
492
510
  debug('Invalid value, returning')
511
+ doneSyncing = true
493
512
  sendBack({type: 'done syncing', value})
494
513
  return
495
514
  }
@@ -505,6 +524,7 @@ async function updateValue({
505
524
  resolution: null,
506
525
  value,
507
526
  })
527
+ doneSyncing = true
508
528
  sendBack({type: 'done syncing', value})
509
529
  return
510
530
  }
@@ -520,6 +540,7 @@ async function updateValue({
520
540
  debug('Server value and editor value is equal, no need to sync.')
521
541
  }
522
542
 
543
+ doneSyncing = true
523
544
  sendBack({type: 'done syncing', value})
524
545
  }
525
546