slate-react 0.91.4 → 0.91.5-2023124214647

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.
@@ -1 +1 @@
1
- {"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/components/editable.tsx"],"names":[],"mappings":"AAGA,OAAO,KAON,MAAM,OAAO,CAAA;AAEd,OAAO,EAEL,OAAO,EAEP,SAAS,EAET,KAAK,EACL,IAAI,EAEL,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAOpD,OAAO,EAGL,QAAQ,EAMT,MAAM,cAAc,CAAA;AAwCrB;;GAEG;AAEH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,GAAG,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE;QACV,iBAAiB,EAAE,SAAS,CAAA;QAC5B,mBAAmB,CAAC,EAAE,IAAI,CAAA;QAC1B,iBAAiB,CAAC,EAAE,IAAI,CAAA;QACxB,GAAG,CAAC,EAAE,KAAK,CAAA;QACX,GAAG,EAAE,GAAG,CAAA;KACT,CAAA;CACF;AAED;;GAEG;AAEH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,GAAG,CAAA;IACb,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;IACV,UAAU,EAAE;QACV,iBAAiB,EAAE,IAAI,CAAA;KACxB,CAAA;CACF;AAED;;GAEG;AAEH,oBAAY,aAAa,GAAG;IAC1B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,KAAK,EAAE,CAAA;IACxC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAA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C,KAAK,EAAE,eAAe,KAAK,GAAG,CAAC,OAAO,CAAA;IACpD,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,GAAG,CAAC,OAAO,CAAA;IAClE,uBAAuB,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAA;IAC3E,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,GAAG,KAAK,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAAA;AAEhD;;GAEG;AAEH,eAAO,MAAM,QAAQ,UAAW,aAAa,gBAi+C5C,CAAA;AAED;;GAEG;AACH,oBAAY,sBAAsB,GAAG;IACnC,QAAQ,EAAE,GAAG,CAAA;IACb,UAAU,EAAE;QACV,wBAAwB,EAAE,OAAO,CAAA;QACjC,GAAG,CAAC,EAAE,KAAK,CAAA;QACX,eAAe,EAAE,OAAO,CAAA;QACxB,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QACzB,KAAK,EAAE,KAAK,CAAC,aAAa,CAAA;KAC3B,CAAA;CACF,CAAA;AAED;;GAEG;AAEH,eAAO,MAAM,kBAAkB,8BAG5B,sBAAsB,gBAOxB,CAAA;AAED;;GAEG;AAEH,eAAO,MAAM,eAAe,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,KAAK,EAAa,CAAA;AA4BtE;;GAEG;AAEH,eAAO,MAAM,cAAc,gHAIO,IAAI,GAAG,OAAO,yBAc/C,CAAA;AAED;;GAEG;AAEH,eAAO,MAAM,iBAAiB,uDAEJ,IAAI,GAAG,OAAO,yBAevC,CAAA"}
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import getDirection from 'direction';
2
2
  import debounce from 'lodash/debounce';
3
3
  import throttle from 'lodash/throttle';
4
- import React, { useLayoutEffect, useEffect, useRef, createContext, useContext, useCallback, Component, useState, useReducer, useMemo } from 'react';
4
+ import React, { useLayoutEffect, useEffect, useRef, useState, memo, forwardRef, createContext, useContext, useCallback, Component, useReducer, useMemo } from 'react';
5
5
  import scrollIntoView from 'scroll-into-view-if-needed';
6
6
  import { Editor, Scrubber, Transforms, Range, Element as Element$1, Path, Node, Text as Text$1, Point } from 'slate';
7
7
  import { ResizeObserver } from '@juggle/resize-observer';
@@ -1247,7 +1247,9 @@ var TextString = props => {
1247
1247
 
1248
1248
  var getTextContent = () => {
1249
1249
  return "".concat(text !== null && text !== void 0 ? text : '').concat(isTrailing ? '\n' : '');
1250
- }; // This is the actual text rendering boundary where we interface with the DOM
1250
+ };
1251
+
1252
+ var [initialText] = useState(getTextContent); // This is the actual text rendering boundary where we interface with the DOM
1251
1253
  // The text is not rendered as part of the virtual DOM, as since we handle basic character insertions natively,
1252
1254
  // updating the DOM is not a one way dataflow anymore. What we need here is not reconciliation and diffing
1253
1255
  // with previous version of the virtual DOM, but rather diffing with the actual DOM element, and replace the DOM <span> content
@@ -1256,7 +1258,6 @@ var TextString = props => {
1256
1258
  // eg makes native spellcheck opt out from checking the text node.
1257
1259
  // useLayoutEffect: updating our span before browser paint
1258
1260
 
1259
-
1260
1261
  useIsomorphicLayoutEffect(() => {
1261
1262
  // null coalescing text to make sure we're not outputing "null" as a string in the extreme case it is nullish at runtime
1262
1263
  var textWithTrailing = getTextContent();
@@ -1266,27 +1267,24 @@ var TextString = props => {
1266
1267
  } // intentionally not specifying dependencies, so that this effect runs on every render
1267
1268
  // as this effectively replaces "specifying the text in the virtual DOM under the <span> below" on each render
1268
1269
 
1269
- }); // Render text content immediately if it's the first-time render
1270
- // Ensure that text content is rendered on server-side rendering
1271
-
1272
- if (!ref.current) {
1273
- return /*#__PURE__*/React.createElement("span", {
1274
- "data-slate-string": true,
1275
- ref: ref
1276
- }, getTextContent());
1277
- } // the span is intentionally same on every render in virtual DOM, actual rendering happens in the layout effect above
1270
+ }); // We intentionally render a memoized <span> that only receives the initial text content when the component is mounted.
1271
+ // We defer to the layout effect above to update the `textContent` of the span element when needed.
1278
1272
 
1273
+ return /*#__PURE__*/React.createElement(MemoizedText$1, {
1274
+ ref: ref
1275
+ }, initialText);
1276
+ };
1279
1277
 
1278
+ var MemoizedText$1 = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, ref) => {
1280
1279
  return /*#__PURE__*/React.createElement("span", {
1281
1280
  "data-slate-string": true,
1282
1281
  ref: ref
1283
- });
1284
- };
1282
+ }, props.children);
1283
+ }));
1285
1284
  /**
1286
1285
  * Leaf strings without text, render as zero-width strings.
1287
1286
  */
1288
1287
 
1289
-
1290
1288
  var ZeroWidthString = props => {
1291
1289
  var {
1292
1290
  length = 0,
@@ -3711,31 +3709,23 @@ var Editable = props => {
3711
3709
  EDITOR_TO_ELEMENT.delete(editor);
3712
3710
  NODE_TO_ELEMENT.delete(editor);
3713
3711
 
3714
- if (HAS_BEFORE_INPUT_SUPPORT) {
3712
+ if (ref.current && HAS_BEFORE_INPUT_SUPPORT) {
3715
3713
  // @ts-ignore The `beforeinput` event isn't recognized.
3716
3714
  ref.current.removeEventListener('beforeinput', onDOMBeforeInput);
3717
3715
  }
3716
+ } else {
3717
+ // Attach a native DOM event handler for `beforeinput` events, because React's
3718
+ // built-in `onBeforeInput` is actually a leaky polyfill that doesn't expose
3719
+ // real `beforeinput` events sadly... (2019/11/04)
3720
+ // https://github.com/facebook/react/issues/11211
3721
+ if (HAS_BEFORE_INPUT_SUPPORT) {
3722
+ // @ts-ignore The `beforeinput` event isn't recognized.
3723
+ node.addEventListener('beforeinput', onDOMBeforeInput);
3724
+ }
3718
3725
  }
3719
3726
 
3720
3727
  ref.current = node;
3721
- }, [ref, onDOMBeforeInput]); // Attach a native DOM event handler for `beforeinput` events, because React's
3722
- // built-in `onBeforeInput` is actually a leaky polyfill that doesn't expose
3723
- // real `beforeinput` events sadly... (2019/11/04)
3724
- // https://github.com/facebook/react/issues/11211
3725
-
3726
- useIsomorphicLayoutEffect(() => {
3727
- if (ref.current && HAS_BEFORE_INPUT_SUPPORT) {
3728
- // @ts-ignore The `beforeinput` event isn't recognized.
3729
- ref.current.addEventListener('beforeinput', onDOMBeforeInput);
3730
- }
3731
-
3732
- return () => {
3733
- if (ref.current && HAS_BEFORE_INPUT_SUPPORT) {
3734
- // @ts-ignore The `beforeinput` event isn't recognized.
3735
- ref.current.removeEventListener('beforeinput', onDOMBeforeInput);
3736
- }
3737
- };
3738
- }, [onDOMBeforeInput]); // Attach a native DOM event handler for `selectionchange`, because React's
3728
+ }, [ref, onDOMBeforeInput]); // Attach a native DOM event handler for `selectionchange`, because React's
3739
3729
  // built-in `onSelect` handler doesn't fire for all selection changes. It's a
3740
3730
  // leaky polyfill that only fires on keypresses or clicks. Instead, we want to
3741
3731
  // fire for any change to the selection inside the editor. (2019/11/04)