@portabletext/editor 2.15.3 → 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
  }
@@ -6058,8 +6056,8 @@ function setNodePatch(schema, children, operation) {
6058
6056
  _key !== void 0 && patches.push(set(_key, [{
6059
6057
  _key: blockKey
6060
6058
  }, "children", block.children.indexOf(child), "_key"]));
6061
- const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys2 = Object.keys(properties);
6062
- 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) {
6063
6061
  const value = properties[key];
6064
6062
  patches.push(set(value, [{
6065
6063
  _key: blockKey
@@ -6069,22 +6067,29 @@ function setNodePatch(schema, children, operation) {
6069
6067
  }
6070
6068
  return patches;
6071
6069
  }
6072
- const keys = Object.keys(operation.newProperties);
6073
- return keys.forEach((keyName) => {
6074
- if (keys.length === 1 && keyName === "_key") {
6075
- const val = get(operation.newProperties, keyName);
6076
- 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, [{
6077
6075
  _key: blockKey
6078
6076
  }, "children", block.children.indexOf(child), keyName]));
6079
- } else {
6080
- const val = get(operation.newProperties, keyName);
6081
- patches.push(set(val, [{
6082
- _key: blockKey
6083
- }, "children", {
6084
- _key: childKey
6085
- }, keyName]));
6077
+ continue;
6086
6078
  }
6087
- }), 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;
6088
6093
  }
6089
6094
  throw new Error("Could not find a valid child");
6090
6095
  }