slate-react 0.76.0 → 0.76.1-20223315597
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/components/editable.d.ts +0 -4
- package/dist/components/editable.d.ts.map +1 -1
- package/dist/components/slate.d.ts +1 -1
- package/dist/components/slate.d.ts.map +1 -1
- package/dist/index.es.js +32 -2
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +32 -2
- package/dist/index.js.map +1 -1
- package/dist/plugin/with-react.d.ts.map +1 -1
- package/dist/slate-react.js +32 -2
- package/dist/slate-react.min.js +1 -1
- package/dist/utils/weak-maps.d.ts +2 -1
- package/dist/utils/weak-maps.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -417,6 +417,7 @@ var IS_READ_ONLY = new WeakMap();
|
|
|
417
417
|
var IS_FOCUSED = new WeakMap();
|
|
418
418
|
var IS_COMPOSING = new WeakMap();
|
|
419
419
|
var IS_ON_COMPOSITION_END = new WeakMap();
|
|
420
|
+
var EDITOR_TO_USER_SELECTION = new WeakMap();
|
|
420
421
|
/**
|
|
421
422
|
* Weak maps for saving text on composition stage.
|
|
422
423
|
*/
|
|
@@ -1425,6 +1426,8 @@ var Editable$1 = function Editable(props) {
|
|
|
1425
1426
|
|
|
1426
1427
|
var onDOMBeforeInput = React.useCallback(function (event) {
|
|
1427
1428
|
if (!readOnly && hasEditableTarget(editor, event.target) && !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
|
|
1429
|
+
var _EDITOR_TO_USER_SELEC;
|
|
1430
|
+
|
|
1428
1431
|
// Some IMEs/Chrome extensions like e.g. Grammarly set the selection immediately before
|
|
1429
1432
|
// triggering a `beforeinput` expecting the change to be applied to the immediately before
|
|
1430
1433
|
// set selection.
|
|
@@ -1495,7 +1498,12 @@ var Editable$1 = function Editable(props) {
|
|
|
1495
1498
|
});
|
|
1496
1499
|
|
|
1497
1500
|
if (!selection || !slate.Range.equals(selection, range)) {
|
|
1501
|
+
var selectionRef = editor.selection && slate.Editor.rangeRef(editor, editor.selection);
|
|
1498
1502
|
slate.Transforms.select(editor, range);
|
|
1503
|
+
|
|
1504
|
+
if (selectionRef) {
|
|
1505
|
+
EDITOR_TO_USER_SELECTION.set(editor, selectionRef);
|
|
1506
|
+
}
|
|
1499
1507
|
}
|
|
1500
1508
|
}
|
|
1501
1509
|
} // COMPAT: If the selection is expanded, even if the command seems like
|
|
@@ -1645,6 +1653,14 @@ var Editable$1 = function Editable(props) {
|
|
|
1645
1653
|
|
|
1646
1654
|
break;
|
|
1647
1655
|
}
|
|
1656
|
+
} // Restore the actual user section if nothing manually set it.
|
|
1657
|
+
|
|
1658
|
+
|
|
1659
|
+
var toRestore = (_EDITOR_TO_USER_SELEC = EDITOR_TO_USER_SELECTION.get(editor)) === null || _EDITOR_TO_USER_SELEC === void 0 ? void 0 : _EDITOR_TO_USER_SELEC.unref();
|
|
1660
|
+
EDITOR_TO_USER_SELECTION["delete"](editor);
|
|
1661
|
+
|
|
1662
|
+
if (toRestore && (!editor.selection || !slate.Range.equals(editor.selection, toRestore))) {
|
|
1663
|
+
slate.Transforms.select(editor, toRestore);
|
|
1648
1664
|
}
|
|
1649
1665
|
}
|
|
1650
1666
|
}, [readOnly, propsOnDOMBeforeInput]); // Attach a native DOM event handler for `beforeinput` events, because React's
|
|
@@ -2039,7 +2055,7 @@ var Editable$1 = function Editable(props) {
|
|
|
2039
2055
|
}
|
|
2040
2056
|
}, [readOnly, attributes.onFocus]),
|
|
2041
2057
|
onKeyDown: React.useCallback(function (event) {
|
|
2042
|
-
if (!readOnly &&
|
|
2058
|
+
if (!readOnly && hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onKeyDown) && !state.isComposing) {
|
|
2043
2059
|
var nativeEvent = event.nativeEvent;
|
|
2044
2060
|
var selection = editor.selection;
|
|
2045
2061
|
var element = editor.children[selection !== null ? selection.focus.path[0] : 0];
|
|
@@ -2369,6 +2385,7 @@ var defaultScrollSelectionIntoView = function defaultScrollSelectionIntoView(edi
|
|
|
2369
2385
|
* Check if the target is in the editor.
|
|
2370
2386
|
*/
|
|
2371
2387
|
|
|
2388
|
+
|
|
2372
2389
|
var hasTarget = function hasTarget(editor, target) {
|
|
2373
2390
|
return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target);
|
|
2374
2391
|
};
|
|
@@ -4327,7 +4344,10 @@ var Slate = function Slate(props) {
|
|
|
4327
4344
|
handleSelectorChange = _getSelectorContext.onChange;
|
|
4328
4345
|
|
|
4329
4346
|
var onContextChange = React.useCallback(function () {
|
|
4330
|
-
onChange
|
|
4347
|
+
if (onChange) {
|
|
4348
|
+
onChange(editor.children);
|
|
4349
|
+
}
|
|
4350
|
+
|
|
4331
4351
|
setContext([editor]);
|
|
4332
4352
|
handleSelectorChange(editor);
|
|
4333
4353
|
}, [onChange]);
|
|
@@ -4515,6 +4535,16 @@ var withReact = function withReact(editor) {
|
|
|
4515
4535
|
break;
|
|
4516
4536
|
}
|
|
4517
4537
|
|
|
4538
|
+
case 'set_selection':
|
|
4539
|
+
{
|
|
4540
|
+
var _EDITOR_TO_USER_SELEC;
|
|
4541
|
+
|
|
4542
|
+
// Selection was manually set, don't restore the user selection after the change.
|
|
4543
|
+
(_EDITOR_TO_USER_SELEC = EDITOR_TO_USER_SELECTION.get(editor)) === null || _EDITOR_TO_USER_SELEC === void 0 ? void 0 : _EDITOR_TO_USER_SELEC.unref();
|
|
4544
|
+
EDITOR_TO_USER_SELECTION["delete"](editor);
|
|
4545
|
+
break;
|
|
4546
|
+
}
|
|
4547
|
+
|
|
4518
4548
|
case 'insert_node':
|
|
4519
4549
|
case 'remove_node':
|
|
4520
4550
|
{
|