slate-react 0.72.6 → 0.72.7-202202811645
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/CHANGELOG.md +10 -0
- package/dist/components/editable.d.ts.map +1 -1
- package/dist/components/string.d.ts.map +1 -1
- package/dist/index.es.js +37 -19
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +37 -19
- package/dist/index.js.map +1 -1
- package/dist/plugin/react-editor.d.ts.map +1 -1
- package/dist/slate-react.js +37 -19
- package/dist/slate-react.min.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -293,7 +293,11 @@ var TextString = function TextString(props) {
|
|
|
293
293
|
var text = props.text,
|
|
294
294
|
_props$isTrailing = props.isTrailing,
|
|
295
295
|
isTrailing = _props$isTrailing === void 0 ? false : _props$isTrailing;
|
|
296
|
-
var ref = React.useRef(null);
|
|
296
|
+
var ref = React.useRef(null);
|
|
297
|
+
|
|
298
|
+
var getTextContent = function getTextContent() {
|
|
299
|
+
return "".concat(text !== null && text !== void 0 ? text : '').concat(isTrailing ? '\n' : '');
|
|
300
|
+
}; // This is the actual text rendering boundary where we interface with the DOM
|
|
297
301
|
// The text is not rendered as part of the virtual DOM, as since we handle basic character insertions natively,
|
|
298
302
|
// updating the DOM is not a one way dataflow anymore. What we need here is not reconciliation and diffing
|
|
299
303
|
// with previous version of the virtual DOM, but rather diffing with the actual DOM element, and replace the DOM <span> content
|
|
@@ -302,16 +306,26 @@ var TextString = function TextString(props) {
|
|
|
302
306
|
// eg makes native spellcheck opt out from checking the text node.
|
|
303
307
|
// useLayoutEffect: updating our span before browser paint
|
|
304
308
|
|
|
309
|
+
|
|
305
310
|
useIsomorphicLayoutEffect(function () {
|
|
306
311
|
// null coalescing text to make sure we're not outputing "null" as a string in the extreme case it is nullish at runtime
|
|
307
|
-
var textWithTrailing =
|
|
312
|
+
var textWithTrailing = getTextContent();
|
|
308
313
|
|
|
309
314
|
if (ref.current && ref.current.textContent !== textWithTrailing) {
|
|
310
315
|
ref.current.textContent = textWithTrailing;
|
|
311
316
|
} // intentionally not specifying dependencies, so that this effect runs on every render
|
|
312
317
|
// as this effectively replaces "specifying the text in the virtual DOM under the <span> below" on each render
|
|
313
318
|
|
|
314
|
-
}); //
|
|
319
|
+
}); // Render text content immediately if it's the first-time render
|
|
320
|
+
// Ensure that text content is rendered on server-side rendering
|
|
321
|
+
|
|
322
|
+
if (!ref.current) {
|
|
323
|
+
return /*#__PURE__*/React__default['default'].createElement("span", {
|
|
324
|
+
"data-slate-string": true,
|
|
325
|
+
ref: ref
|
|
326
|
+
}, getTextContent());
|
|
327
|
+
} // the span is intentionally same on every render in virtual DOM, actual rendering happens in the layout effect above
|
|
328
|
+
|
|
315
329
|
|
|
316
330
|
return /*#__PURE__*/React__default['default'].createElement("span", {
|
|
317
331
|
"data-slate-string": true,
|
|
@@ -1392,6 +1406,7 @@ var Editable$1 = function Editable(props) {
|
|
|
1392
1406
|
// triggering a `beforeinput` expecting the change to be applied to the immediately before
|
|
1393
1407
|
// set selection.
|
|
1394
1408
|
scheduleOnDOMSelectionChange.flush();
|
|
1409
|
+
onDOMSelectionChange.flush();
|
|
1395
1410
|
var selection = editor.selection;
|
|
1396
1411
|
var type = event.inputType;
|
|
1397
1412
|
var data = event.dataTransfer || event.data || undefined; // These two types occur while a user is composing text and can't be
|
|
@@ -3074,22 +3089,25 @@ var ReactEditor = {
|
|
|
3074
3089
|
|
|
3075
3090
|
if (leafNode) {
|
|
3076
3091
|
textNode = leafNode.closest('[data-slate-node="text"]');
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3092
|
+
|
|
3093
|
+
if (textNode) {
|
|
3094
|
+
var window = ReactEditor.getWindow(editor);
|
|
3095
|
+
var range = window.document.createRange();
|
|
3096
|
+
range.setStart(textNode, 0);
|
|
3097
|
+
range.setEnd(nearestNode, nearestOffset);
|
|
3098
|
+
var contents = range.cloneContents();
|
|
3099
|
+
var removals = [].concat(_toConsumableArray(Array.prototype.slice.call(contents.querySelectorAll('[data-slate-zero-width]'))), _toConsumableArray(Array.prototype.slice.call(contents.querySelectorAll('[contenteditable=false]'))));
|
|
3100
|
+
removals.forEach(function (el) {
|
|
3101
|
+
el.parentNode.removeChild(el);
|
|
3102
|
+
}); // COMPAT: Edge has a bug where Range.prototype.toString() will
|
|
3103
|
+
// convert \n into \r\n. The bug causes a loop when slate-react
|
|
3104
|
+
// attempts to reposition its cursor to match the native position. Use
|
|
3105
|
+
// textContent.length instead.
|
|
3106
|
+
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/
|
|
3107
|
+
|
|
3108
|
+
offset = contents.textContent.length;
|
|
3109
|
+
domNode = textNode;
|
|
3110
|
+
}
|
|
3093
3111
|
} else if (voidNode) {
|
|
3094
3112
|
// For void nodes, the element with the offset key will be a cousin, not an
|
|
3095
3113
|
// ancestor, so find it by going down from the nearest void parent.
|