@portabletext/editor 1.49.3 → 1.49.4
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 +49 -16
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +49 -16
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/sync-machine.ts +70 -29
package/lib/index.cjs
CHANGED
|
@@ -3034,21 +3034,16 @@ async function updateValue({
|
|
|
3034
3034
|
const slateValueFromProps = toSlateValue(value, {
|
|
3035
3035
|
schemaTypes: context.schema
|
|
3036
3036
|
});
|
|
3037
|
-
await new Promise((resolve) => {
|
|
3037
|
+
streamBlocks ? await new Promise((resolve) => {
|
|
3038
3038
|
slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
3039
3039
|
withRemoteChanges(slateEditor, () => {
|
|
3040
3040
|
withoutPatching(slateEditor, async () => {
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
isChanged = !0;
|
|
3048
|
-
}
|
|
3049
|
-
for await (const [currentBlock, currentBlockIndex] of getBlocks({
|
|
3050
|
-
slateValue: slateValueFromProps,
|
|
3051
|
-
streamBlocks
|
|
3041
|
+
isChanged = removeExtraBlocks({
|
|
3042
|
+
slateEditor,
|
|
3043
|
+
slateValueFromProps
|
|
3044
|
+
});
|
|
3045
|
+
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
3046
|
+
slateValue: slateValueFromProps
|
|
3052
3047
|
})) {
|
|
3053
3048
|
const {
|
|
3054
3049
|
blockChanged,
|
|
@@ -3067,6 +3062,30 @@ async function updateValue({
|
|
|
3067
3062
|
});
|
|
3068
3063
|
});
|
|
3069
3064
|
});
|
|
3065
|
+
}) : slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
3066
|
+
withRemoteChanges(slateEditor, () => {
|
|
3067
|
+
withoutPatching(slateEditor, () => {
|
|
3068
|
+
isChanged = removeExtraBlocks({
|
|
3069
|
+
slateEditor,
|
|
3070
|
+
slateValueFromProps
|
|
3071
|
+
});
|
|
3072
|
+
let index = 0;
|
|
3073
|
+
for (const currentBlock of slateValueFromProps) {
|
|
3074
|
+
const {
|
|
3075
|
+
blockChanged,
|
|
3076
|
+
blockValid
|
|
3077
|
+
} = syncBlock({
|
|
3078
|
+
context,
|
|
3079
|
+
sendBack,
|
|
3080
|
+
block: currentBlock,
|
|
3081
|
+
index,
|
|
3082
|
+
slateEditor,
|
|
3083
|
+
value
|
|
3084
|
+
});
|
|
3085
|
+
isChanged = blockChanged || isChanged, isValid = isValid && blockValid, index++;
|
|
3086
|
+
}
|
|
3087
|
+
});
|
|
3088
|
+
});
|
|
3070
3089
|
});
|
|
3071
3090
|
}
|
|
3072
3091
|
if (!isValid) {
|
|
@@ -3111,13 +3130,27 @@ async function updateValue({
|
|
|
3111
3130
|
value
|
|
3112
3131
|
});
|
|
3113
3132
|
}
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3133
|
+
function removeExtraBlocks({
|
|
3134
|
+
slateEditor,
|
|
3135
|
+
slateValueFromProps
|
|
3136
|
+
}) {
|
|
3137
|
+
let isChanged = !1;
|
|
3138
|
+
const childrenLength = slateEditor.children.length;
|
|
3139
|
+
if (slateValueFromProps.length < childrenLength) {
|
|
3140
|
+
for (let i = childrenLength - 1; i > slateValueFromProps.length - 1; i--)
|
|
3141
|
+
slate.Transforms.removeNodes(slateEditor, {
|
|
3142
|
+
at: [i]
|
|
3143
|
+
});
|
|
3144
|
+
isChanged = !0;
|
|
3145
|
+
}
|
|
3146
|
+
return isChanged;
|
|
3147
|
+
}
|
|
3148
|
+
async function* getStreamedBlocks({
|
|
3149
|
+
slateValue
|
|
3117
3150
|
}) {
|
|
3118
3151
|
let index = 0;
|
|
3119
3152
|
for await (const block of slateValue)
|
|
3120
|
-
|
|
3153
|
+
index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
3121
3154
|
}
|
|
3122
3155
|
function syncBlock({
|
|
3123
3156
|
context,
|