slate-react 0.91.5-2023124214650 → 0.91.5
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.es.js +13 -15
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +14 -13
- package/dist/index.js.map +1 -1
- package/dist/slate-react.js +14 -13
- package/dist/slate-react.min.js +1 -1
- package/package.json +1 -1
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,
|
|
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
|
-
};
|
|
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
|
-
}); //
|
|
1270
|
-
//
|
|
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,
|