@portabletext/editor 2.21.1 → 2.21.3
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 +26 -0
- package/lib/index.js.map +1 -1
- package/package.json +7 -7
- package/src/internal-utils/applyPatch.ts +46 -1
- package/src/test/vitest/step-definitions.tsx +34 -9
package/lib/index.js
CHANGED
|
@@ -5661,6 +5661,32 @@ function setPatch(editor, patch) {
|
|
|
5661
5661
|
if (!block)
|
|
5662
5662
|
return !1;
|
|
5663
5663
|
const isTextBlock2 = editor.isTextBlock(block.node);
|
|
5664
|
+
if (patch.path.length === 1) {
|
|
5665
|
+
const updatedBlock = applyAll(block.node, [{
|
|
5666
|
+
...patch,
|
|
5667
|
+
path: patch.path.slice(1)
|
|
5668
|
+
}]);
|
|
5669
|
+
if (editor.isTextBlock(block.node) && Element$1.isElement(updatedBlock)) {
|
|
5670
|
+
Transforms.setNodes(editor, updatedBlock, {
|
|
5671
|
+
at: [block.index]
|
|
5672
|
+
});
|
|
5673
|
+
const previousSelection = editor.selection;
|
|
5674
|
+
for (const [_, childPath] of Editor.nodes(editor, {
|
|
5675
|
+
at: [block.index],
|
|
5676
|
+
reverse: !0,
|
|
5677
|
+
mode: "lowest"
|
|
5678
|
+
}))
|
|
5679
|
+
Transforms.removeNodes(editor, {
|
|
5680
|
+
at: childPath
|
|
5681
|
+
});
|
|
5682
|
+
return Transforms.insertNodes(editor, updatedBlock.children, {
|
|
5683
|
+
at: [block.index, 0]
|
|
5684
|
+
}), previousSelection && (Transforms.setSelection(editor, previousSelection), Transforms.select(editor, previousSelection)), !0;
|
|
5685
|
+
} else
|
|
5686
|
+
return Transforms.setNodes(editor, updatedBlock, {
|
|
5687
|
+
at: [block.index]
|
|
5688
|
+
}), !0;
|
|
5689
|
+
}
|
|
5664
5690
|
if (isTextBlock2 && patch.path[1] !== "children") {
|
|
5665
5691
|
const updatedBlock = applyAll(block.node, [{
|
|
5666
5692
|
...patch,
|