slate-react 0.91.1 → 0.91.2-2023120155438

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/dist/index.js CHANGED
@@ -1347,12 +1347,6 @@ var ReactEditor = {
1347
1347
  }
1348
1348
  };
1349
1349
 
1350
- /**
1351
- * Prevent warning on SSR by falling back to useEffect when DOM isn't available
1352
- */
1353
-
1354
- var useIsomorphicLayoutEffect = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
1355
-
1356
1350
  var _excluded$3 = ["anchor", "focus"],
1357
1351
  _excluded2$1 = ["anchor", "focus"];
1358
1352
  var shallowCompare = function shallowCompare(obj1, obj2) {
@@ -1422,6 +1416,12 @@ var isTextDecorationsEqual = function isTextDecorationsEqual(list, another) {
1422
1416
  return true;
1423
1417
  };
1424
1418
 
1419
+ /**
1420
+ * Prevent warning on SSR by falling back to useEffect when DOM isn't available
1421
+ */
1422
+
1423
+ var useIsomorphicLayoutEffect = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
1424
+
1425
1425
  /**
1426
1426
  * Leaf content strings.
1427
1427
  */
@@ -1711,21 +1711,27 @@ var Text = function Text(props) {
1711
1711
  } // Update element-related weak maps with the DOM element ref.
1712
1712
 
1713
1713
 
1714
- useIsomorphicLayoutEffect(function () {
1714
+ var callbackRef = React.useCallback(function (span) {
1715
1715
  var KEY_TO_ELEMENT = EDITOR_TO_KEY_TO_ELEMENT.get(editor);
1716
1716
 
1717
- if (ref.current) {
1718
- KEY_TO_ELEMENT === null || KEY_TO_ELEMENT === void 0 ? void 0 : KEY_TO_ELEMENT.set(key, ref.current);
1719
- NODE_TO_ELEMENT.set(text, ref.current);
1720
- ELEMENT_TO_NODE.set(ref.current, text);
1717
+ if (span) {
1718
+ KEY_TO_ELEMENT === null || KEY_TO_ELEMENT === void 0 ? void 0 : KEY_TO_ELEMENT.set(key, span);
1719
+ NODE_TO_ELEMENT.set(text, span);
1720
+ ELEMENT_TO_NODE.set(span, text);
1721
1721
  } else {
1722
1722
  KEY_TO_ELEMENT === null || KEY_TO_ELEMENT === void 0 ? void 0 : KEY_TO_ELEMENT["delete"](key);
1723
1723
  NODE_TO_ELEMENT["delete"](text);
1724
+
1725
+ if (ref.current) {
1726
+ ELEMENT_TO_NODE["delete"](ref.current);
1727
+ }
1724
1728
  }
1725
- });
1729
+
1730
+ ref.current = span;
1731
+ }, [ref, editor, key, text]);
1726
1732
  return /*#__PURE__*/React__default['default'].createElement("span", {
1727
1733
  "data-slate-node": "text",
1728
- ref: ref
1734
+ ref: callbackRef
1729
1735
  }, children);
1730
1736
  };
1731
1737
 
@@ -4184,7 +4190,20 @@ var Editable = function Editable(props) {
4184
4190
  slate.Transforms.select(editor, toRestore);
4185
4191
  }
4186
4192
  }
4187
- }, [readOnly, propsOnDOMBeforeInput]); // Attach a native DOM event handler for `beforeinput` events, because React's
4193
+ }, [readOnly, propsOnDOMBeforeInput]);
4194
+ var callbackRef = React.useCallback(function (node) {
4195
+ if (node == null) {
4196
+ EDITOR_TO_ELEMENT["delete"](editor);
4197
+ NODE_TO_ELEMENT["delete"](editor);
4198
+
4199
+ if (HAS_BEFORE_INPUT_SUPPORT) {
4200
+ // @ts-ignore The `beforeinput` event isn't recognized.
4201
+ ref.current.removeEventListener('beforeinput', onDOMBeforeInput);
4202
+ }
4203
+ }
4204
+
4205
+ ref.current = node;
4206
+ }, [ref, onDOMBeforeInput]); // Attach a native DOM event handler for `beforeinput` events, because React's
4188
4207
  // built-in `onBeforeInput` is actually a leaky polyfill that doesn't expose
4189
4208
  // real `beforeinput` events sadly... (2019/11/04)
4190
4209
  // https://github.com/facebook/react/issues/11211
@@ -4302,7 +4321,7 @@ var Editable = function Editable(props) {
4302
4321
  // this magic zIndex="-1" will fix it
4303
4322
  zindex: -1,
4304
4323
  suppressContentEditableWarning: true,
4305
- ref: ref,
4324
+ ref: callbackRef,
4306
4325
  style: _objectSpread$1(_objectSpread$1({}, disableDefaultStyles ? {} : _objectSpread$1({
4307
4326
  // Allow positioning relative to the editable element.
4308
4327
  position: 'relative',