@portabletext/editor 4.3.3 → 4.3.5
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.js +18 -8
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -283,7 +283,7 @@ function isEqualToEmptyEditor(initialValue, blocks, schemaTypes) {
|
|
|
283
283
|
if (!Element$1.isElement(firstBlock) || firstBlock._type !== schemaTypes.block.name || "listItem" in firstBlock || !("style" in firstBlock) || firstBlock.style !== schemaTypes.styles.at(0)?.name || !Array.isArray(firstBlock.children) || firstBlock.children.length !== 1)
|
|
284
284
|
return !1;
|
|
285
285
|
const firstChild = firstBlock.children.at(0);
|
|
286
|
-
return !(!firstChild || !Text.isText(firstChild) || !("_type" in firstChild) || firstChild._type !== schemaTypes.span.name || firstChild.text !== "" || firstChild.marks?.join("") || Object.keys(firstBlock).some((key) => key !== "_type" && key !== "_key" && key !== "children" && key !== "markDefs" && key !== "style") || isEqualValues({
|
|
286
|
+
return !(!firstChild || !Text.isText(firstChild) || !("_type" in firstChild) || firstChild._type !== schemaTypes.span.name || firstChild.text !== "" || firstChild.marks?.join("") || "markDefs" in firstBlock && Array.isArray(firstBlock.markDefs) && firstBlock.markDefs.length > 0 || Object.keys(firstBlock).some((key) => key !== "_type" && key !== "_key" && key !== "children" && key !== "markDefs" && key !== "style") || isEqualValues({
|
|
287
287
|
schema: schemaTypes
|
|
288
288
|
}, initialValue, [firstBlock]));
|
|
289
289
|
}
|
|
@@ -5218,11 +5218,21 @@ function mergeNodePatch(schema, children, operation, beforeValue) {
|
|
|
5218
5218
|
}, updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && isSpan({
|
|
5219
5219
|
schema
|
|
5220
5220
|
}, block.children[operation.path[1]]) ? block.children[operation.path[1]] : void 0;
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5221
|
+
if (updatedSpan) {
|
|
5222
|
+
const spansMatchingKey = block.children.filter((span) => span._key === updatedSpan._key);
|
|
5223
|
+
if (spansMatchingKey.length === 1) {
|
|
5224
|
+
const prevSpan = spansMatchingKey[0];
|
|
5225
|
+
isSpan({
|
|
5226
|
+
schema
|
|
5227
|
+
}, prevSpan) && prevSpan.text !== updatedSpan.text && patches.push(set(updatedSpan.text, [{
|
|
5228
|
+
_key: block._key
|
|
5229
|
+
}, "children", {
|
|
5230
|
+
_key: updatedSpan._key
|
|
5231
|
+
}, "text"]));
|
|
5232
|
+
} else
|
|
5233
|
+
console.warn(`Multiple spans have \`_key\` ${updatedSpan._key}. It's ambiguous which one to update.`, JSON.stringify(block, null, 2));
|
|
5234
|
+
}
|
|
5235
|
+
removedSpan && (block.children.filter((span) => span._key === removedSpan._key).length === 1 ? patches.push(unset([{
|
|
5226
5236
|
_key: block._key
|
|
5227
5237
|
}, "children", {
|
|
5228
5238
|
_key: removedSpan._key
|
|
@@ -12907,7 +12917,7 @@ function syncBlock({
|
|
|
12907
12917
|
type: "patch",
|
|
12908
12918
|
patch
|
|
12909
12919
|
});
|
|
12910
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key ? (debug.syncValue("Updating block", oldBlock, block), Editor.withoutNormalizing(slateEditor, () => {
|
|
12920
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key && oldBlock._type === block._type ? (debug.syncValue("Updating block", oldBlock, block), Editor.withoutNormalizing(slateEditor, () => {
|
|
12911
12921
|
withRemoteChanges(slateEditor, () => {
|
|
12912
12922
|
withoutPatching(slateEditor, () => {
|
|
12913
12923
|
updateBlock({
|
|
@@ -12979,7 +12989,7 @@ function updateBlock({
|
|
|
12979
12989
|
}), slateBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
12980
12990
|
const oldBlockChild = oldSlateBlock.children.at(currentBlockChildIndex), isChildChanged = !oldBlockChild || !isEqualChild(currentBlockChild, oldBlockChild), isTextChanged = oldBlockChild && Text.isText(oldBlockChild) && currentBlockChild.text !== oldBlockChild.text, path = [index, currentBlockChildIndex];
|
|
12981
12991
|
if (isChildChanged)
|
|
12982
|
-
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
12992
|
+
if (currentBlockChild._key === oldBlockChild?._key && currentBlockChild._type === oldBlockChild?._type) {
|
|
12983
12993
|
debug.syncValue("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
12984
12994
|
at: path
|
|
12985
12995
|
});
|