@portabletext/editor 2.15.2 → 2.15.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.js CHANGED
@@ -27,7 +27,6 @@ import omit from "lodash/omit.js";
27
27
  import { applyAll, unset, insert, set, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
28
28
  import { blockOffsetsToSelection } from "./_chunks-es/util.child-selection-point-to-block-offset.js";
29
29
  import { selectionPointToBlockOffset, sliceTextBlock } from "./_chunks-es/util.slice-text-block.js";
30
- import get from "lodash/get.js";
31
30
  import { createDraft, finishDraft } from "immer";
32
31
  import { createKeyboardShortcut, code, underline, italic, bold, undo, redo } from "@portabletext/keyboard-shortcuts";
33
32
  import isPlainObject from "lodash/isPlainObject.js";
@@ -4456,15 +4455,9 @@ const addAnnotationOperationImplementation = ({
4456
4455
  if (!child || !childPath)
4457
4456
  throw new Error(`Unable to find child at ${JSON.stringify(operation.at)}`);
4458
4457
  if (operation.editor.isTextSpan(child)) {
4459
- operation.props.includes("text") && operation.editor.apply({
4460
- type: "remove_text",
4461
- path: childPath,
4462
- offset: 0,
4463
- text: child.text
4464
- });
4465
4458
  const newNode = {};
4466
4459
  for (const prop of operation.props)
4467
- if (prop !== "_type") {
4460
+ if (prop !== "text" && prop !== "_type") {
4468
4461
  if (prop === "_key") {
4469
4462
  newNode._key = context.keyGenerator();
4470
4463
  continue;
@@ -4473,6 +4466,11 @@ const addAnnotationOperationImplementation = ({
4473
4466
  }
4474
4467
  Transforms.setNodes(operation.editor, newNode, {
4475
4468
  at: childPath
4469
+ }), operation.props.includes("text") && operation.editor.apply({
4470
+ type: "remove_text",
4471
+ path: childPath,
4472
+ offset: 0,
4473
+ text: child.text
4476
4474
  });
4477
4475
  return;
4478
4476
  }
@@ -6023,17 +6021,26 @@ function setNodePatch(schema, children, operation) {
6023
6021
  _key: block._key
6024
6022
  }, key]));
6025
6023
  }
6024
+ for (const key of Object.keys(operation.properties))
6025
+ key in operation.newProperties || patches.push(unset([{
6026
+ _key: block._key
6027
+ }, key]));
6026
6028
  return patches;
6027
6029
  } else {
6028
6030
  const patches = [], _key = operation.newProperties._key;
6029
6031
  _key !== void 0 && patches.push(set(_key, [blockIndex, "_key"]));
6030
- const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys = Object.keys(properties);
6032
+ const newValue = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys = Object.keys(newValue);
6031
6033
  for (const key of keys) {
6032
- const value = properties[key];
6033
- patches.push(set(value, [{
6034
+ const value2 = newValue[key];
6035
+ patches.push(set(value2, [{
6034
6036
  _key: block._key
6035
6037
  }, key]));
6036
6038
  }
6039
+ const value = "value" in operation.properties && typeof operation.properties.value == "object" ? operation.properties.value : {};
6040
+ for (const key of Object.keys(value))
6041
+ key in newValue || patches.push(unset([{
6042
+ _key: block._key
6043
+ }, key]));
6037
6044
  return patches;
6038
6045
  }
6039
6046
  } else if (operation.path.length === 2) {
@@ -6049,8 +6056,8 @@ function setNodePatch(schema, children, operation) {
6049
6056
  _key !== void 0 && patches.push(set(_key, [{
6050
6057
  _key: blockKey
6051
6058
  }, "children", block.children.indexOf(child), "_key"]));
6052
- const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys2 = Object.keys(properties);
6053
- for (const key of keys2) {
6059
+ const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys = Object.keys(properties);
6060
+ for (const key of keys) {
6054
6061
  const value = properties[key];
6055
6062
  patches.push(set(value, [{
6056
6063
  _key: blockKey
@@ -6060,22 +6067,29 @@ function setNodePatch(schema, children, operation) {
6060
6067
  }
6061
6068
  return patches;
6062
6069
  }
6063
- const keys = Object.keys(operation.newProperties);
6064
- return keys.forEach((keyName) => {
6065
- if (keys.length === 1 && keyName === "_key") {
6066
- const val = get(operation.newProperties, keyName);
6067
- patches.push(set(val, [{
6070
+ const newPropNames = Object.keys(operation.newProperties);
6071
+ for (const keyName of newPropNames) {
6072
+ const value = operation.newProperties[keyName];
6073
+ if (keyName === "_key") {
6074
+ patches.push(set(value, [{
6068
6075
  _key: blockKey
6069
6076
  }, "children", block.children.indexOf(child), keyName]));
6070
- } else {
6071
- const val = get(operation.newProperties, keyName);
6072
- patches.push(set(val, [{
6073
- _key: blockKey
6074
- }, "children", {
6075
- _key: childKey
6076
- }, keyName]));
6077
+ continue;
6077
6078
  }
6078
- }), patches;
6079
+ patches.push(set(value, [{
6080
+ _key: blockKey
6081
+ }, "children", {
6082
+ _key: childKey
6083
+ }, keyName]));
6084
+ }
6085
+ const propNames = Object.keys(operation.properties);
6086
+ for (const keyName of propNames)
6087
+ keyName in operation.newProperties || patches.push(unset([{
6088
+ _key: blockKey
6089
+ }, "children", {
6090
+ _key: childKey
6091
+ }, keyName]));
6092
+ return patches;
6079
6093
  }
6080
6094
  throw new Error("Could not find a valid child");
6081
6095
  }