@portabletext/editor 4.0.3 → 4.1.0

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 CHANGED
@@ -4774,6 +4774,9 @@ function createApplyPatch(context) {
4774
4774
  case "set":
4775
4775
  changed = setPatch(editor, patch);
4776
4776
  break;
4777
+ case "setIfMissing":
4778
+ changed = setPatch(editor, patch);
4779
+ break;
4777
4780
  case "diffMatchPatch":
4778
4781
  changed = diffMatchPatch(editor, patch);
4779
4782
  break;
@@ -4899,6 +4902,8 @@ function setPatch(editor, patch) {
4899
4902
  if (isTextBlock2 && child) {
4900
4903
  if (Text.isText(child.node))
4901
4904
  if (Text.isText(value)) {
4905
+ if (patch.type === "setIfMissing")
4906
+ return !1;
4902
4907
  const oldText = child.node.text, newText = value.text;
4903
4908
  oldText !== newText && (editor.apply({
4904
4909
  type: "remove_text",
@@ -4939,38 +4944,6 @@ function setPatch(editor, patch) {
4939
4944
  });
4940
4945
  }
4941
4946
  return !0;
4942
- } else if (Element$1.isElement(block.node) && patch.path.length === 1) {
4943
- const {
4944
- children,
4945
- ...nextRest
4946
- } = value, {
4947
- children: _prevChildren,
4948
- ...prevRest
4949
- } = block.node || {
4950
- children: void 0
4951
- };
4952
- editor.apply({
4953
- type: "set_node",
4954
- path: [block.index],
4955
- properties: {
4956
- ...prevRest
4957
- },
4958
- newProperties: nextRest
4959
- });
4960
- const blockNode = block.node;
4961
- blockNode.children.forEach((child2, childIndex) => {
4962
- editor.apply({
4963
- type: "remove_node",
4964
- path: [block.index, blockNode.children.length - 1 - childIndex],
4965
- node: child2
4966
- });
4967
- }), Array.isArray(children) && children.forEach((child2, childIndex) => {
4968
- editor.apply({
4969
- type: "insert_node",
4970
- path: [block.index, childIndex],
4971
- node: child2
4972
- });
4973
- });
4974
4947
  } else if (block && "value" in block.node)
4975
4948
  if (patch.path.length > 1 && patch.path[1] !== "children") {
4976
4949
  const newVal = applyAll(block.node.value, [{