@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.js
CHANGED
|
@@ -3062,21 +3062,16 @@ async function updateValue({
|
|
|
3062
3062
|
const slateValueFromProps = toSlateValue(value, {
|
|
3063
3063
|
schemaTypes: context.schema
|
|
3064
3064
|
});
|
|
3065
|
-
await new Promise((resolve) => {
|
|
3065
|
+
streamBlocks ? await new Promise((resolve) => {
|
|
3066
3066
|
Editor.withoutNormalizing(slateEditor, () => {
|
|
3067
3067
|
withRemoteChanges(slateEditor, () => {
|
|
3068
3068
|
withoutPatching(slateEditor, async () => {
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
isChanged = !0;
|
|
3076
|
-
}
|
|
3077
|
-
for await (const [currentBlock, currentBlockIndex] of getBlocks({
|
|
3078
|
-
slateValue: slateValueFromProps,
|
|
3079
|
-
streamBlocks
|
|
3069
|
+
isChanged = removeExtraBlocks({
|
|
3070
|
+
slateEditor,
|
|
3071
|
+
slateValueFromProps
|
|
3072
|
+
});
|
|
3073
|
+
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
3074
|
+
slateValue: slateValueFromProps
|
|
3080
3075
|
})) {
|
|
3081
3076
|
const {
|
|
3082
3077
|
blockChanged,
|
|
@@ -3095,6 +3090,30 @@ async function updateValue({
|
|
|
3095
3090
|
});
|
|
3096
3091
|
});
|
|
3097
3092
|
});
|
|
3093
|
+
}) : Editor.withoutNormalizing(slateEditor, () => {
|
|
3094
|
+
withRemoteChanges(slateEditor, () => {
|
|
3095
|
+
withoutPatching(slateEditor, () => {
|
|
3096
|
+
isChanged = removeExtraBlocks({
|
|
3097
|
+
slateEditor,
|
|
3098
|
+
slateValueFromProps
|
|
3099
|
+
});
|
|
3100
|
+
let index = 0;
|
|
3101
|
+
for (const currentBlock of slateValueFromProps) {
|
|
3102
|
+
const {
|
|
3103
|
+
blockChanged,
|
|
3104
|
+
blockValid
|
|
3105
|
+
} = syncBlock({
|
|
3106
|
+
context,
|
|
3107
|
+
sendBack,
|
|
3108
|
+
block: currentBlock,
|
|
3109
|
+
index,
|
|
3110
|
+
slateEditor,
|
|
3111
|
+
value
|
|
3112
|
+
});
|
|
3113
|
+
isChanged = blockChanged || isChanged, isValid = isValid && blockValid, index++;
|
|
3114
|
+
}
|
|
3115
|
+
});
|
|
3116
|
+
});
|
|
3098
3117
|
});
|
|
3099
3118
|
}
|
|
3100
3119
|
if (!isValid) {
|
|
@@ -3139,13 +3158,27 @@ async function updateValue({
|
|
|
3139
3158
|
value
|
|
3140
3159
|
});
|
|
3141
3160
|
}
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3161
|
+
function removeExtraBlocks({
|
|
3162
|
+
slateEditor,
|
|
3163
|
+
slateValueFromProps
|
|
3164
|
+
}) {
|
|
3165
|
+
let isChanged = !1;
|
|
3166
|
+
const childrenLength = slateEditor.children.length;
|
|
3167
|
+
if (slateValueFromProps.length < childrenLength) {
|
|
3168
|
+
for (let i = childrenLength - 1; i > slateValueFromProps.length - 1; i--)
|
|
3169
|
+
Transforms.removeNodes(slateEditor, {
|
|
3170
|
+
at: [i]
|
|
3171
|
+
});
|
|
3172
|
+
isChanged = !0;
|
|
3173
|
+
}
|
|
3174
|
+
return isChanged;
|
|
3175
|
+
}
|
|
3176
|
+
async function* getStreamedBlocks({
|
|
3177
|
+
slateValue
|
|
3145
3178
|
}) {
|
|
3146
3179
|
let index = 0;
|
|
3147
3180
|
for await (const block of slateValue)
|
|
3148
|
-
|
|
3181
|
+
index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
3149
3182
|
}
|
|
3150
3183
|
function syncBlock({
|
|
3151
3184
|
context,
|