@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.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$g = require("debug"), slateDom = require("slate-dom"), util_isEmptyTextBlock = require("./_chunks-cjs/util.is-empty-text-block.cjs"), util_getTextBlockText = require("./_chunks-cjs/util.get-text-block-text.cjs"), isEqual = require("lodash/isEqual.js"), schema = require("@portabletext/schema"), selector_isAtTheStartOfBlock = require("./_chunks-cjs/selector.is-at-the-start-of-block.cjs"), selector_getSelectionText = require("./_chunks-cjs/selector.get-selection-text.cjs"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), xstate = require("xstate"), sanityBridge = require("@portabletext/sanity-bridge"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema$1 = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_sliceTextBlock = require("./_chunks-cjs/util.slice-text-block.cjs"), get = require("lodash/get.js"), immer = require("immer"), keyboardShortcuts = require("@portabletext/keyboard-shortcuts"), isPlainObject = require("lodash/isPlainObject.js"), rxjs = require("rxjs");
3
+ var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$g = require("debug"), slateDom = require("slate-dom"), util_isEmptyTextBlock = require("./_chunks-cjs/util.is-empty-text-block.cjs"), util_getTextBlockText = require("./_chunks-cjs/util.get-text-block-text.cjs"), isEqual = require("lodash/isEqual.js"), schema = require("@portabletext/schema"), selector_isAtTheStartOfBlock = require("./_chunks-cjs/selector.is-at-the-start-of-block.cjs"), selector_getSelectionText = require("./_chunks-cjs/selector.get-selection-text.cjs"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), xstate = require("xstate"), sanityBridge = require("@portabletext/sanity-bridge"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema$1 = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_sliceTextBlock = require("./_chunks-cjs/util.slice-text-block.cjs"), immer = require("immer"), keyboardShortcuts = require("@portabletext/keyboard-shortcuts"), isPlainObject = require("lodash/isPlainObject.js"), rxjs = require("rxjs");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
7
- var noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$g), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
7
+ var noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$g), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
8
8
  function EditorEventListener(props) {
9
9
  const $ = reactCompilerRuntime.c(4), editor = useEditor.useEditor();
10
10
  let t0, t1;
@@ -4429,15 +4429,9 @@ const addAnnotationOperationImplementation = ({
4429
4429
  if (!child || !childPath)
4430
4430
  throw new Error(`Unable to find child at ${JSON.stringify(operation.at)}`);
4431
4431
  if (operation.editor.isTextSpan(child)) {
4432
- operation.props.includes("text") && operation.editor.apply({
4433
- type: "remove_text",
4434
- path: childPath,
4435
- offset: 0,
4436
- text: child.text
4437
- });
4438
4432
  const newNode = {};
4439
4433
  for (const prop of operation.props)
4440
- if (prop !== "_type") {
4434
+ if (prop !== "text" && prop !== "_type") {
4441
4435
  if (prop === "_key") {
4442
4436
  newNode._key = context.keyGenerator();
4443
4437
  continue;
@@ -4446,6 +4440,11 @@ const addAnnotationOperationImplementation = ({
4446
4440
  }
4447
4441
  slate.Transforms.setNodes(operation.editor, newNode, {
4448
4442
  at: childPath
4443
+ }), operation.props.includes("text") && operation.editor.apply({
4444
+ type: "remove_text",
4445
+ path: childPath,
4446
+ offset: 0,
4447
+ text: child.text
4449
4448
  });
4450
4449
  return;
4451
4450
  }
@@ -5996,17 +5995,26 @@ function setNodePatch(schema$12, children, operation) {
5996
5995
  _key: block._key
5997
5996
  }, key]));
5998
5997
  }
5998
+ for (const key of Object.keys(operation.properties))
5999
+ key in operation.newProperties || patches$1.push(patches.unset([{
6000
+ _key: block._key
6001
+ }, key]));
5999
6002
  return patches$1;
6000
6003
  } else {
6001
6004
  const patches$1 = [], _key = operation.newProperties._key;
6002
6005
  _key !== void 0 && patches$1.push(patches.set(_key, [blockIndex, "_key"]));
6003
- const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys = Object.keys(properties);
6006
+ const newValue = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys = Object.keys(newValue);
6004
6007
  for (const key of keys) {
6005
- const value = properties[key];
6006
- patches$1.push(patches.set(value, [{
6008
+ const value2 = newValue[key];
6009
+ patches$1.push(patches.set(value2, [{
6007
6010
  _key: block._key
6008
6011
  }, key]));
6009
6012
  }
6013
+ const value = "value" in operation.properties && typeof operation.properties.value == "object" ? operation.properties.value : {};
6014
+ for (const key of Object.keys(value))
6015
+ key in newValue || patches$1.push(patches.unset([{
6016
+ _key: block._key
6017
+ }, key]));
6010
6018
  return patches$1;
6011
6019
  }
6012
6020
  } else if (operation.path.length === 2) {
@@ -6022,8 +6030,8 @@ function setNodePatch(schema$12, children, operation) {
6022
6030
  _key !== void 0 && patches$1.push(patches.set(_key, [{
6023
6031
  _key: blockKey
6024
6032
  }, "children", block.children.indexOf(child), "_key"]));
6025
- const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys2 = Object.keys(properties);
6026
- for (const key of keys2) {
6033
+ const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys = Object.keys(properties);
6034
+ for (const key of keys) {
6027
6035
  const value = properties[key];
6028
6036
  patches$1.push(patches.set(value, [{
6029
6037
  _key: blockKey
@@ -6033,22 +6041,29 @@ function setNodePatch(schema$12, children, operation) {
6033
6041
  }
6034
6042
  return patches$1;
6035
6043
  }
6036
- const keys = Object.keys(operation.newProperties);
6037
- return keys.forEach((keyName) => {
6038
- if (keys.length === 1 && keyName === "_key") {
6039
- const val = get__default.default(operation.newProperties, keyName);
6040
- patches$1.push(patches.set(val, [{
6044
+ const newPropNames = Object.keys(operation.newProperties);
6045
+ for (const keyName of newPropNames) {
6046
+ const value = operation.newProperties[keyName];
6047
+ if (keyName === "_key") {
6048
+ patches$1.push(patches.set(value, [{
6041
6049
  _key: blockKey
6042
6050
  }, "children", block.children.indexOf(child), keyName]));
6043
- } else {
6044
- const val = get__default.default(operation.newProperties, keyName);
6045
- patches$1.push(patches.set(val, [{
6046
- _key: blockKey
6047
- }, "children", {
6048
- _key: childKey
6049
- }, keyName]));
6051
+ continue;
6050
6052
  }
6051
- }), patches$1;
6053
+ patches$1.push(patches.set(value, [{
6054
+ _key: blockKey
6055
+ }, "children", {
6056
+ _key: childKey
6057
+ }, keyName]));
6058
+ }
6059
+ const propNames = Object.keys(operation.properties);
6060
+ for (const keyName of propNames)
6061
+ keyName in operation.newProperties || patches$1.push(patches.unset([{
6062
+ _key: blockKey
6063
+ }, "children", {
6064
+ _key: childKey
6065
+ }, keyName]));
6066
+ return patches$1;
6052
6067
  }
6053
6068
  throw new Error("Could not find a valid child");
6054
6069
  }