@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/lib/index.cjs +32 -23
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +32 -23
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/sync-machine.ts +39 -18
package/package.json
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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
|
-
|
|
452
|
-
isValid = isValid && blockValid
|
|
466
|
+
resolve()
|
|
453
467
|
}
|
|
454
468
|
|
|
455
|
-
|
|
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
|
|