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.
@@ -2000,12 +2000,6 @@
2000
2000
  }
2001
2001
  };
2002
2002
 
2003
- /**
2004
- * Prevent warning on SSR by falling back to useEffect when DOM isn't available
2005
- */
2006
-
2007
- var useIsomorphicLayoutEffect = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
2008
-
2009
2003
  var _excluded$3 = ["anchor", "focus"],
2010
2004
  _excluded2$1 = ["anchor", "focus"];
2011
2005
  var shallowCompare = function shallowCompare(obj1, obj2) {
@@ -2574,6 +2568,12 @@
2574
2568
  return ResizeObserver;
2575
2569
  }());
2576
2570
 
2571
+ /**
2572
+ * Prevent warning on SSR by falling back to useEffect when DOM isn't available
2573
+ */
2574
+
2575
+ var useIsomorphicLayoutEffect = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
2576
+
2577
2577
  /**
2578
2578
  * Leaf content strings.
2579
2579
  */
@@ -2863,21 +2863,27 @@
2863
2863
  } // Update element-related weak maps with the DOM element ref.
2864
2864
 
2865
2865
 
2866
- useIsomorphicLayoutEffect(function () {
2866
+ var callbackRef = React.useCallback(function (span) {
2867
2867
  var KEY_TO_ELEMENT = EDITOR_TO_KEY_TO_ELEMENT.get(editor);
2868
2868
 
2869
- if (ref.current) {
2870
- KEY_TO_ELEMENT === null || KEY_TO_ELEMENT === void 0 ? void 0 : KEY_TO_ELEMENT.set(key, ref.current);
2871
- NODE_TO_ELEMENT.set(text, ref.current);
2872
- ELEMENT_TO_NODE.set(ref.current, text);
2869
+ if (span) {
2870
+ KEY_TO_ELEMENT === null || KEY_TO_ELEMENT === void 0 ? void 0 : KEY_TO_ELEMENT.set(key, span);
2871
+ NODE_TO_ELEMENT.set(text, span);
2872
+ ELEMENT_TO_NODE.set(span, text);
2873
2873
  } else {
2874
2874
  KEY_TO_ELEMENT === null || KEY_TO_ELEMENT === void 0 ? void 0 : KEY_TO_ELEMENT["delete"](key);
2875
2875
  NODE_TO_ELEMENT["delete"](text);
2876
+
2877
+ if (ref.current) {
2878
+ ELEMENT_TO_NODE["delete"](ref.current);
2879
+ }
2876
2880
  }
2877
- });
2881
+
2882
+ ref.current = span;
2883
+ }, [ref, editor, key, text]);
2878
2884
  return /*#__PURE__*/React__default['default'].createElement("span", {
2879
2885
  "data-slate-node": "text",
2880
- ref: ref
2886
+ ref: callbackRef
2881
2887
  }, children);
2882
2888
  };
2883
2889
 
@@ -5592,7 +5598,20 @@
5592
5598
  slate.Transforms.select(editor, toRestore);
5593
5599
  }
5594
5600
  }
5595
- }, [readOnly, propsOnDOMBeforeInput]); // Attach a native DOM event handler for `beforeinput` events, because React's
5601
+ }, [readOnly, propsOnDOMBeforeInput]);
5602
+ var callbackRef = React.useCallback(function (node) {
5603
+ if (node == null) {
5604
+ EDITOR_TO_ELEMENT["delete"](editor);
5605
+ NODE_TO_ELEMENT["delete"](editor);
5606
+
5607
+ if (HAS_BEFORE_INPUT_SUPPORT) {
5608
+ // @ts-ignore The `beforeinput` event isn't recognized.
5609
+ ref.current.removeEventListener('beforeinput', onDOMBeforeInput);
5610
+ }
5611
+ }
5612
+
5613
+ ref.current = node;
5614
+ }, [ref, onDOMBeforeInput]); // Attach a native DOM event handler for `beforeinput` events, because React's
5596
5615
  // built-in `onBeforeInput` is actually a leaky polyfill that doesn't expose
5597
5616
  // real `beforeinput` events sadly... (2019/11/04)
5598
5617
  // https://github.com/facebook/react/issues/11211
@@ -5710,7 +5729,7 @@
5710
5729
  // this magic zIndex="-1" will fix it
5711
5730
  zindex: -1,
5712
5731
  suppressContentEditableWarning: true,
5713
- ref: ref,
5732
+ ref: callbackRef,
5714
5733
  style: _objectSpread$1(_objectSpread$1({}, disableDefaultStyles ? {} : _objectSpread$1({
5715
5734
  // Allow positioning relative to the editable element.
5716
5735
  position: 'relative',