@portabletext/editor 1.0.17 → 1.0.18
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.esm.js +22 -8
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +22 -8
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +22 -8
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/utils/operationToPatches.ts +58 -14
package/lib/index.esm.js
CHANGED
|
@@ -870,24 +870,38 @@ function createOperationToPatches(types) {
|
|
|
870
870
|
return [unset([{ _key: block._key }])];
|
|
871
871
|
throw new Error("Block not found");
|
|
872
872
|
} else if (editor.isTextBlock(block) && operation.path.length === 2) {
|
|
873
|
-
const spanToRemove =
|
|
874
|
-
return spanToRemove ?
|
|
873
|
+
const spanToRemove = block.children[operation.path[1]];
|
|
874
|
+
return spanToRemove ? block.children.filter((span) => span._key === operation.node._key).length > 1 ? (console.warn(
|
|
875
|
+
`Multiple spans have \`_key\` ${operation.node._key}. It's ambiguous which one to remove.`,
|
|
876
|
+
JSON.stringify(block, null, 2)
|
|
877
|
+
), []) : [unset([{ _key: block._key }, "children", { _key: spanToRemove._key }])] : (debug$k("Span not found in editor trying to remove node"), []);
|
|
875
878
|
} else
|
|
876
879
|
return debug$k("Not creating patch inside object block"), [];
|
|
877
880
|
}
|
|
878
881
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
879
|
-
const patches = [], block = beforeValue[operation.path[0]],
|
|
882
|
+
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
880
883
|
if (operation.path.length === 1)
|
|
881
884
|
if (block?._key) {
|
|
882
885
|
const newBlock = fromSlateValue([editor.children[operation.path[0] - 1]], textBlockName)[0];
|
|
883
886
|
patches.push(set(newBlock, [{ _key: newBlock._key }])), patches.push(unset([{ _key: block._key }]));
|
|
884
887
|
} else
|
|
885
888
|
throw new Error("Target key not found!");
|
|
886
|
-
else if (operation.path.length === 2
|
|
887
|
-
const
|
|
888
|
-
|
|
889
|
-
set(
|
|
890
|
-
|
|
889
|
+
else if (editor.isTextBlock(block) && editor.isTextBlock(updatedBlock) && operation.path.length === 2) {
|
|
890
|
+
const updatedSpan = updatedBlock.children[operation.path[1] - 1] && editor.isTextSpan(updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && editor.isTextSpan(block.children[operation.path[1]]) ? block.children[operation.path[1]] : void 0;
|
|
891
|
+
updatedSpan && (block.children.filter((span) => span._key === updatedSpan._key).length === 1 ? patches.push(
|
|
892
|
+
set(updatedSpan.text, [
|
|
893
|
+
{ _key: block._key },
|
|
894
|
+
"children",
|
|
895
|
+
{ _key: updatedSpan._key },
|
|
896
|
+
"text"
|
|
897
|
+
])
|
|
898
|
+
) : console.warn(
|
|
899
|
+
`Multiple spans have \`_key\` ${updatedSpan._key}. It's ambiguous which one to update.`,
|
|
900
|
+
JSON.stringify(block, null, 2)
|
|
901
|
+
)), removedSpan && (block.children.filter((span) => span._key === removedSpan._key).length === 1 ? patches.push(unset([{ _key: block._key }, "children", { _key: removedSpan._key }])) : console.warn(
|
|
902
|
+
`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`,
|
|
903
|
+
JSON.stringify(block, null, 2)
|
|
904
|
+
));
|
|
891
905
|
} else
|
|
892
906
|
debug$k("Void nodes can't be merged, not creating any patches");
|
|
893
907
|
return patches;
|