slate-react 0.91.11 → 0.92.0-202321717544
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 +4 -0
- package/dist/components/editable.d.ts.map +1 -1
- package/dist/hooks/android-input-manager/use-android-input-manager.d.ts +1 -1
- package/dist/hooks/android-input-manager/use-android-input-manager.d.ts.map +1 -1
- package/dist/hooks/use-slate-selector.d.ts +1 -1
- package/dist/hooks/use-slate-selector.d.ts.map +1 -1
- package/dist/index.es.js +69 -44
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +108 -79
- package/dist/index.js.map +1 -1
- package/dist/slate-react.js +108 -79
- package/dist/slate-react.min.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1639,7 +1639,7 @@ var Leaf = function Leaf(props) {
|
|
|
1639
1639
|
return function () {
|
|
1640
1640
|
EDITOR_TO_PLACEHOLDER_ELEMENT["delete"](editor);
|
|
1641
1641
|
};
|
|
1642
|
-
}, [placeholderRef, leaf]);
|
|
1642
|
+
}, [placeholderRef, leaf, editor]);
|
|
1643
1643
|
var children = /*#__PURE__*/React__default['default'].createElement(String, {
|
|
1644
1644
|
isLast: isLast,
|
|
1645
1645
|
leaf: leaf,
|
|
@@ -3636,7 +3636,7 @@ function useMutationObserver(node, callback, options) {
|
|
|
3636
3636
|
return function () {
|
|
3637
3637
|
return mutationObserver.disconnect();
|
|
3638
3638
|
};
|
|
3639
|
-
}, []);
|
|
3639
|
+
}, [mutationObserver, node, options]);
|
|
3640
3640
|
}
|
|
3641
3641
|
|
|
3642
3642
|
var _excluded$2 = ["node"];
|
|
@@ -3649,7 +3649,9 @@ var MUTATION_OBSERVER_CONFIG = {
|
|
|
3649
3649
|
childList: true,
|
|
3650
3650
|
characterData: true
|
|
3651
3651
|
};
|
|
3652
|
-
function
|
|
3652
|
+
var useAndroidInputManager = !IS_ANDROID ? function () {
|
|
3653
|
+
return null;
|
|
3654
|
+
} : function (_ref) {
|
|
3653
3655
|
var node = _ref.node,
|
|
3654
3656
|
options = _objectWithoutProperties(_ref, _excluded$2);
|
|
3655
3657
|
|
|
@@ -3676,7 +3678,7 @@ function useAndroidInputManager(_ref) {
|
|
|
3676
3678
|
}
|
|
3677
3679
|
|
|
3678
3680
|
return inputManager;
|
|
3679
|
-
}
|
|
3681
|
+
};
|
|
3680
3682
|
|
|
3681
3683
|
function useTrackUserInput() {
|
|
3682
3684
|
var editor = useSlateStatic();
|
|
@@ -3693,7 +3695,7 @@ function useTrackUserInput() {
|
|
|
3693
3695
|
animationFrameIdRef.current = window.requestAnimationFrame(function () {
|
|
3694
3696
|
receivedUserInput.current = false;
|
|
3695
3697
|
});
|
|
3696
|
-
}, []);
|
|
3698
|
+
}, [editor]);
|
|
3697
3699
|
React.useEffect(function () {
|
|
3698
3700
|
return function () {
|
|
3699
3701
|
return cancelAnimationFrame(animationFrameIdRef.current);
|
|
@@ -3792,65 +3794,79 @@ var Editable = function Editable(props) {
|
|
|
3792
3794
|
if (ref.current && autoFocus) {
|
|
3793
3795
|
ref.current.focus();
|
|
3794
3796
|
}
|
|
3795
|
-
}, [autoFocus]);
|
|
3797
|
+
}, [autoFocus]);
|
|
3798
|
+
/**
|
|
3799
|
+
* The AndroidInputManager object has a cyclical dependency on onDOMSelectionChange
|
|
3800
|
+
*
|
|
3801
|
+
* It is defined as a reference to simplify hook dependencies and clarify that
|
|
3802
|
+
* it needs to be initialized.
|
|
3803
|
+
*/
|
|
3804
|
+
|
|
3805
|
+
var androidInputManagerRef = React.useRef(); // Listen on the native `selectionchange` event to be able to update any time
|
|
3796
3806
|
// the selection changes. This is required because React's `onSelect` is leaky
|
|
3797
3807
|
// and non-standard so it doesn't fire until after a selection has been
|
|
3798
3808
|
// released. This causes issues in situations where another change happens
|
|
3799
3809
|
// while a selection is being dragged.
|
|
3800
3810
|
|
|
3801
|
-
var onDOMSelectionChange = React.
|
|
3802
|
-
|
|
3803
|
-
var
|
|
3804
|
-
var activeElement = root.activeElement;
|
|
3805
|
-
var el = ReactEditor.toDOMNode(editor, editor);
|
|
3806
|
-
var domSelection = root.getSelection();
|
|
3811
|
+
var onDOMSelectionChange = React.useMemo(function () {
|
|
3812
|
+
return throttle__default['default'](function () {
|
|
3813
|
+
var androidInputManager = androidInputManagerRef.current;
|
|
3807
3814
|
|
|
3808
|
-
if (
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
}
|
|
3815
|
+
if ((IS_ANDROID || !ReactEditor.isComposing(editor)) && (!state.isUpdatingSelection || androidInputManager !== null && androidInputManager !== void 0 && androidInputManager.isFlushing()) && !state.isDraggingInternally) {
|
|
3816
|
+
var root = ReactEditor.findDocumentOrShadowRoot(editor);
|
|
3817
|
+
var activeElement = root.activeElement;
|
|
3818
|
+
var el = ReactEditor.toDOMNode(editor, editor);
|
|
3819
|
+
var domSelection = root.getSelection();
|
|
3814
3820
|
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3821
|
+
if (activeElement === el) {
|
|
3822
|
+
state.latestElement = activeElement;
|
|
3823
|
+
IS_FOCUSED.set(editor, true);
|
|
3824
|
+
} else {
|
|
3825
|
+
IS_FOCUSED["delete"](editor);
|
|
3826
|
+
}
|
|
3818
3827
|
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
var focusNodeSelectable = ReactEditor.hasEditableTarget(editor, focusNode) || ReactEditor.isTargetInsideNonReadonlyVoid(editor, focusNode);
|
|
3828
|
+
if (!domSelection) {
|
|
3829
|
+
return slate.Transforms.deselect(editor);
|
|
3830
|
+
}
|
|
3823
3831
|
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
});
|
|
3832
|
+
var anchorNode = domSelection.anchorNode,
|
|
3833
|
+
focusNode = domSelection.focusNode;
|
|
3834
|
+
var anchorNodeSelectable = ReactEditor.hasEditableTarget(editor, anchorNode) || ReactEditor.isTargetInsideNonReadonlyVoid(editor, anchorNode);
|
|
3835
|
+
var focusNodeSelectable = ReactEditor.hasEditableTarget(editor, focusNode) || ReactEditor.isTargetInsideNonReadonlyVoid(editor, focusNode);
|
|
3829
3836
|
|
|
3830
|
-
if (
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3837
|
+
if (anchorNodeSelectable && focusNodeSelectable) {
|
|
3838
|
+
var range = ReactEditor.toSlateRange(editor, domSelection, {
|
|
3839
|
+
exactMatch: false,
|
|
3840
|
+
suppressThrow: true
|
|
3841
|
+
});
|
|
3842
|
+
|
|
3843
|
+
if (range) {
|
|
3844
|
+
if (!ReactEditor.isComposing(editor) && !(androidInputManager !== null && androidInputManager !== void 0 && androidInputManager.hasPendingChanges()) && !(androidInputManager !== null && androidInputManager !== void 0 && androidInputManager.isFlushing())) {
|
|
3845
|
+
slate.Transforms.select(editor, range);
|
|
3846
|
+
} else {
|
|
3847
|
+
androidInputManager === null || androidInputManager === void 0 ? void 0 : androidInputManager.handleUserSelect(range);
|
|
3848
|
+
}
|
|
3835
3849
|
}
|
|
3836
|
-
}
|
|
3837
|
-
} // Deselect the editor if the dom selection is not selectable in readonly mode
|
|
3850
|
+
} // Deselect the editor if the dom selection is not selectable in readonly mode
|
|
3838
3851
|
|
|
3839
3852
|
|
|
3840
|
-
|
|
3841
|
-
|
|
3853
|
+
if (readOnly && (!anchorNodeSelectable || !focusNodeSelectable)) {
|
|
3854
|
+
slate.Transforms.deselect(editor);
|
|
3855
|
+
}
|
|
3842
3856
|
}
|
|
3843
|
-
}
|
|
3844
|
-
},
|
|
3857
|
+
}, 100);
|
|
3858
|
+
}, [editor, readOnly, state]);
|
|
3845
3859
|
var scheduleOnDOMSelectionChange = React.useMemo(function () {
|
|
3846
3860
|
return debounce__default['default'](onDOMSelectionChange, 0);
|
|
3847
3861
|
}, [onDOMSelectionChange]);
|
|
3848
|
-
|
|
3862
|
+
androidInputManagerRef.current = useAndroidInputManager({
|
|
3849
3863
|
node: ref,
|
|
3850
3864
|
onDOMSelectionChange: onDOMSelectionChange,
|
|
3851
3865
|
scheduleOnDOMSelectionChange: scheduleOnDOMSelectionChange
|
|
3852
3866
|
});
|
|
3853
3867
|
useIsomorphicLayoutEffect(function () {
|
|
3868
|
+
var _androidInputManagerR, _androidInputManagerR2;
|
|
3869
|
+
|
|
3854
3870
|
// Update element-related weak maps with the DOM element ref.
|
|
3855
3871
|
var window;
|
|
3856
3872
|
|
|
@@ -3868,7 +3884,7 @@ var Editable = function Editable(props) {
|
|
|
3868
3884
|
var root = ReactEditor.findDocumentOrShadowRoot(editor);
|
|
3869
3885
|
var domSelection = root.getSelection();
|
|
3870
3886
|
|
|
3871
|
-
if (!domSelection || !ReactEditor.isFocused(editor) ||
|
|
3887
|
+
if (!domSelection || !ReactEditor.isFocused(editor) || (_androidInputManagerR = androidInputManagerRef.current) !== null && _androidInputManagerR !== void 0 && _androidInputManagerR.hasPendingAction()) {
|
|
3872
3888
|
return;
|
|
3873
3889
|
}
|
|
3874
3890
|
|
|
@@ -3944,7 +3960,7 @@ var Editable = function Editable(props) {
|
|
|
3944
3960
|
};
|
|
3945
3961
|
|
|
3946
3962
|
var newDomRange = setDomSelection();
|
|
3947
|
-
var ensureSelection = (
|
|
3963
|
+
var ensureSelection = ((_androidInputManagerR2 = androidInputManagerRef.current) === null || _androidInputManagerR2 === void 0 ? void 0 : _androidInputManagerR2.isFlushing()) === 'action';
|
|
3948
3964
|
|
|
3949
3965
|
if (!IS_ANDROID || !ensureSelection) {
|
|
3950
3966
|
setTimeout(function () {
|
|
@@ -4005,8 +4021,8 @@ var Editable = function Editable(props) {
|
|
|
4005
4021
|
var _EDITOR_TO_USER_SELEC;
|
|
4006
4022
|
|
|
4007
4023
|
// COMPAT: BeforeInput events aren't cancelable on android, so we have to handle them differently using the android input manager.
|
|
4008
|
-
if (
|
|
4009
|
-
return
|
|
4024
|
+
if (androidInputManagerRef.current) {
|
|
4025
|
+
return androidInputManagerRef.current.handleDOMBeforeInput(event);
|
|
4010
4026
|
} // Some IMEs/Chrome extensions like e.g. Grammarly set the selection immediately before
|
|
4011
4027
|
// triggering a `beforeinput` expecting the change to be applied to the immediately before
|
|
4012
4028
|
// set selection.
|
|
@@ -4266,7 +4282,7 @@ var Editable = function Editable(props) {
|
|
|
4266
4282
|
slate.Transforms.select(editor, toRestore);
|
|
4267
4283
|
}
|
|
4268
4284
|
}
|
|
4269
|
-
}, [readOnly,
|
|
4285
|
+
}, [editor, onDOMSelectionChange, onUserInput, propsOnDOMBeforeInput, readOnly, scheduleOnDOMSelectionChange]);
|
|
4270
4286
|
var callbackRef = React.useCallback(function (node) {
|
|
4271
4287
|
if (node == null) {
|
|
4272
4288
|
onDOMSelectionChange.cancel();
|
|
@@ -4290,7 +4306,7 @@ var Editable = function Editable(props) {
|
|
|
4290
4306
|
}
|
|
4291
4307
|
|
|
4292
4308
|
ref.current = node;
|
|
4293
|
-
}, [
|
|
4309
|
+
}, [onDOMSelectionChange, scheduleOnDOMSelectionChange, editor, onDOMBeforeInput]); // Attach a native DOM event handler for `selectionchange`, because React's
|
|
4294
4310
|
// built-in `onSelect` handler doesn't fire for all selection changes. It's a
|
|
4295
4311
|
// leaky polyfill that only fires on keypresses or clicks. Instead, we want to
|
|
4296
4312
|
// fire for any change to the selection inside the editor. (2019/11/04)
|
|
@@ -4416,14 +4432,14 @@ var Editable = function Editable(props) {
|
|
|
4416
4432
|
slate.Editor.insertText(editor, _text2);
|
|
4417
4433
|
}
|
|
4418
4434
|
}
|
|
4419
|
-
}, [readOnly]),
|
|
4435
|
+
}, [attributes.onBeforeInput, editor, readOnly]),
|
|
4420
4436
|
onInput: React.useCallback(function (event) {
|
|
4421
4437
|
if (isEventHandled(event, attributes.onInput)) {
|
|
4422
4438
|
return;
|
|
4423
4439
|
}
|
|
4424
4440
|
|
|
4425
|
-
if (
|
|
4426
|
-
|
|
4441
|
+
if (androidInputManagerRef.current) {
|
|
4442
|
+
androidInputManagerRef.current.handleInput();
|
|
4427
4443
|
return;
|
|
4428
4444
|
} // Flush native operations, as native events will have propogated
|
|
4429
4445
|
// and we can correctly compare DOM text values in components
|
|
@@ -4446,7 +4462,7 @@ var Editable = function Editable(props) {
|
|
|
4446
4462
|
}
|
|
4447
4463
|
|
|
4448
4464
|
deferredOperations.current = [];
|
|
4449
|
-
}, []),
|
|
4465
|
+
}, [attributes.onInput]),
|
|
4450
4466
|
onBlur: React.useCallback(function (event) {
|
|
4451
4467
|
if (readOnly || state.isUpdatingSelection || !ReactEditor.hasSelectableTarget(editor, event.target) || isEventHandled(event, attributes.onBlur)) {
|
|
4452
4468
|
return;
|
|
@@ -4497,7 +4513,7 @@ var Editable = function Editable(props) {
|
|
|
4497
4513
|
}
|
|
4498
4514
|
|
|
4499
4515
|
IS_FOCUSED["delete"](editor);
|
|
4500
|
-
}, [readOnly, attributes.onBlur]),
|
|
4516
|
+
}, [readOnly, state.isUpdatingSelection, state.latestElement, editor, attributes.onBlur]),
|
|
4501
4517
|
onClick: React.useCallback(function (event) {
|
|
4502
4518
|
if (ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onClick) && isDOMNode(event.target)) {
|
|
4503
4519
|
var node = ReactEditor.toSlateNode(editor, event.target);
|
|
@@ -4550,15 +4566,17 @@ var Editable = function Editable(props) {
|
|
|
4550
4566
|
slate.Transforms.select(editor, _range);
|
|
4551
4567
|
}
|
|
4552
4568
|
}
|
|
4553
|
-
}, [
|
|
4569
|
+
}, [editor, attributes.onClick, readOnly]),
|
|
4554
4570
|
onCompositionEnd: React.useCallback(function (event) {
|
|
4555
4571
|
if (ReactEditor.hasSelectableTarget(editor, event.target)) {
|
|
4572
|
+
var _androidInputManagerR3;
|
|
4573
|
+
|
|
4556
4574
|
if (ReactEditor.isComposing(editor)) {
|
|
4557
4575
|
setIsComposing(false);
|
|
4558
4576
|
IS_COMPOSING.set(editor, false);
|
|
4559
4577
|
}
|
|
4560
4578
|
|
|
4561
|
-
|
|
4579
|
+
(_androidInputManagerR3 = androidInputManagerRef.current) === null || _androidInputManagerR3 === void 0 ? void 0 : _androidInputManagerR3.handleCompositionEnd(event);
|
|
4562
4580
|
|
|
4563
4581
|
if (isEventHandled(event, attributes.onCompositionEnd) || IS_ANDROID) {
|
|
4564
4582
|
return;
|
|
@@ -4586,7 +4604,7 @@ var Editable = function Editable(props) {
|
|
|
4586
4604
|
}
|
|
4587
4605
|
}
|
|
4588
4606
|
}
|
|
4589
|
-
}, [attributes.onCompositionEnd]),
|
|
4607
|
+
}, [attributes.onCompositionEnd, editor]),
|
|
4590
4608
|
onCompositionUpdate: React.useCallback(function (event) {
|
|
4591
4609
|
if (ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onCompositionUpdate)) {
|
|
4592
4610
|
if (!ReactEditor.isComposing(editor)) {
|
|
@@ -4594,10 +4612,12 @@ var Editable = function Editable(props) {
|
|
|
4594
4612
|
IS_COMPOSING.set(editor, true);
|
|
4595
4613
|
}
|
|
4596
4614
|
}
|
|
4597
|
-
}, [attributes.onCompositionUpdate]),
|
|
4615
|
+
}, [attributes.onCompositionUpdate, editor]),
|
|
4598
4616
|
onCompositionStart: React.useCallback(function (event) {
|
|
4599
4617
|
if (ReactEditor.hasSelectableTarget(editor, event.target)) {
|
|
4600
|
-
|
|
4618
|
+
var _androidInputManagerR4;
|
|
4619
|
+
|
|
4620
|
+
(_androidInputManagerR4 = androidInputManagerRef.current) === null || _androidInputManagerR4 === void 0 ? void 0 : _androidInputManagerR4.handleCompositionStart(event);
|
|
4601
4621
|
|
|
4602
4622
|
if (isEventHandled(event, attributes.onCompositionStart) || IS_ANDROID) {
|
|
4603
4623
|
return;
|
|
@@ -4633,15 +4653,15 @@ var Editable = function Editable(props) {
|
|
|
4633
4653
|
}
|
|
4634
4654
|
}
|
|
4635
4655
|
}
|
|
4636
|
-
}, [attributes.onCompositionStart]),
|
|
4656
|
+
}, [attributes.onCompositionStart, editor]),
|
|
4637
4657
|
onCopy: React.useCallback(function (event) {
|
|
4638
|
-
if (ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onCopy)) {
|
|
4658
|
+
if (ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onCopy) && !isDOMEventTargetInput(event)) {
|
|
4639
4659
|
event.preventDefault();
|
|
4640
4660
|
ReactEditor.setFragmentData(editor, event.clipboardData, 'copy');
|
|
4641
4661
|
}
|
|
4642
|
-
}, [attributes.onCopy]),
|
|
4662
|
+
}, [attributes.onCopy, editor]),
|
|
4643
4663
|
onCut: React.useCallback(function (event) {
|
|
4644
|
-
if (!readOnly && ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onCut)) {
|
|
4664
|
+
if (!readOnly && ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onCut) && !isDOMEventTargetInput(event)) {
|
|
4645
4665
|
event.preventDefault();
|
|
4646
4666
|
ReactEditor.setFragmentData(editor, event.clipboardData, 'cut');
|
|
4647
4667
|
var selection = editor.selection;
|
|
@@ -4658,7 +4678,7 @@ var Editable = function Editable(props) {
|
|
|
4658
4678
|
}
|
|
4659
4679
|
}
|
|
4660
4680
|
}
|
|
4661
|
-
}, [readOnly, attributes.onCut]),
|
|
4681
|
+
}, [readOnly, editor, attributes.onCut]),
|
|
4662
4682
|
onDragOver: React.useCallback(function (event) {
|
|
4663
4683
|
if (ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragOver)) {
|
|
4664
4684
|
// Only when the target is void, call `preventDefault` to signal
|
|
@@ -4670,7 +4690,7 @@ var Editable = function Editable(props) {
|
|
|
4670
4690
|
event.preventDefault();
|
|
4671
4691
|
}
|
|
4672
4692
|
}
|
|
4673
|
-
}, [attributes.onDragOver]),
|
|
4693
|
+
}, [attributes.onDragOver, editor]),
|
|
4674
4694
|
onDragStart: React.useCallback(function (event) {
|
|
4675
4695
|
if (!readOnly && ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragStart)) {
|
|
4676
4696
|
var node = ReactEditor.toSlateNode(editor, event.target);
|
|
@@ -4689,7 +4709,7 @@ var Editable = function Editable(props) {
|
|
|
4689
4709
|
state.isDraggingInternally = true;
|
|
4690
4710
|
ReactEditor.setFragmentData(editor, event.dataTransfer, 'drag');
|
|
4691
4711
|
}
|
|
4692
|
-
}, [readOnly, attributes.onDragStart]),
|
|
4712
|
+
}, [readOnly, editor, attributes.onDragStart, state]),
|
|
4693
4713
|
onDrop: React.useCallback(function (event) {
|
|
4694
4714
|
if (!readOnly && ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDrop)) {
|
|
4695
4715
|
event.preventDefault(); // Keep a reference to the dragged range before updating selection
|
|
@@ -4720,7 +4740,7 @@ var Editable = function Editable(props) {
|
|
|
4720
4740
|
}
|
|
4721
4741
|
|
|
4722
4742
|
state.isDraggingInternally = false;
|
|
4723
|
-
}, [readOnly, attributes.onDrop]),
|
|
4743
|
+
}, [readOnly, editor, attributes.onDrop, state]),
|
|
4724
4744
|
onDragEnd: React.useCallback(function (event) {
|
|
4725
4745
|
if (!readOnly && state.isDraggingInternally && attributes.onDragEnd && ReactEditor.hasTarget(editor, event.target)) {
|
|
4726
4746
|
attributes.onDragEnd(event);
|
|
@@ -4730,7 +4750,7 @@ var Editable = function Editable(props) {
|
|
|
4730
4750
|
|
|
4731
4751
|
|
|
4732
4752
|
state.isDraggingInternally = false;
|
|
4733
|
-
}, [readOnly, attributes
|
|
4753
|
+
}, [readOnly, state, attributes, editor]),
|
|
4734
4754
|
onFocus: React.useCallback(function (event) {
|
|
4735
4755
|
if (!readOnly && !state.isUpdatingSelection && ReactEditor.hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onFocus)) {
|
|
4736
4756
|
var el = ReactEditor.toDOMNode(editor, editor);
|
|
@@ -4746,10 +4766,12 @@ var Editable = function Editable(props) {
|
|
|
4746
4766
|
|
|
4747
4767
|
IS_FOCUSED.set(editor, true);
|
|
4748
4768
|
}
|
|
4749
|
-
}, [readOnly, attributes.onFocus]),
|
|
4769
|
+
}, [readOnly, state, editor, attributes.onFocus]),
|
|
4750
4770
|
onKeyDown: React.useCallback(function (event) {
|
|
4751
4771
|
if (!readOnly && ReactEditor.hasEditableTarget(editor, event.target)) {
|
|
4752
|
-
|
|
4772
|
+
var _androidInputManagerR5;
|
|
4773
|
+
|
|
4774
|
+
(_androidInputManagerR5 = androidInputManagerRef.current) === null || _androidInputManagerR5 === void 0 ? void 0 : _androidInputManagerR5.handleKeyDown(event);
|
|
4753
4775
|
var nativeEvent = event.nativeEvent; // COMPAT: The composition end event isn't fired reliably in all browsers,
|
|
4754
4776
|
// so we sometimes might end up stuck in a composition state even though we
|
|
4755
4777
|
// aren't composing any more.
|
|
@@ -5033,7 +5055,7 @@ var Editable = function Editable(props) {
|
|
|
5033
5055
|
}
|
|
5034
5056
|
}
|
|
5035
5057
|
}
|
|
5036
|
-
}, [readOnly, attributes.onKeyDown]),
|
|
5058
|
+
}, [readOnly, editor, attributes.onKeyDown]),
|
|
5037
5059
|
onPaste: React.useCallback(function (event) {
|
|
5038
5060
|
if (!readOnly && ReactEditor.hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onPaste)) {
|
|
5039
5061
|
// COMPAT: Certain browsers don't support the `beforeinput` event, so we
|
|
@@ -5048,7 +5070,7 @@ var Editable = function Editable(props) {
|
|
|
5048
5070
|
ReactEditor.insertData(editor, event.clipboardData);
|
|
5049
5071
|
}
|
|
5050
5072
|
}
|
|
5051
|
-
}, [readOnly, attributes.onPaste])
|
|
5073
|
+
}, [readOnly, editor, attributes.onPaste])
|
|
5052
5074
|
}), /*#__PURE__*/React__default['default'].createElement(Children, {
|
|
5053
5075
|
decorations: decorations,
|
|
5054
5076
|
node: editor,
|
|
@@ -5116,6 +5138,13 @@ var isEventHandled = function isEventHandled(event, handler) {
|
|
|
5116
5138
|
|
|
5117
5139
|
return event.isDefaultPrevented() || event.isPropagationStopped();
|
|
5118
5140
|
};
|
|
5141
|
+
/**
|
|
5142
|
+
* Check if the event's target is an input element
|
|
5143
|
+
*/
|
|
5144
|
+
|
|
5145
|
+
var isDOMEventTargetInput = function isDOMEventTargetInput(event) {
|
|
5146
|
+
return isDOMNode(event.target) && (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement);
|
|
5147
|
+
};
|
|
5119
5148
|
/**
|
|
5120
5149
|
* Check if a DOM event is overrided by a handler.
|
|
5121
5150
|
*/
|
|
@@ -5250,7 +5279,7 @@ function useSlateSelector(selector) {
|
|
|
5250
5279
|
* Create selector context with editor updating on every editor change
|
|
5251
5280
|
*/
|
|
5252
5281
|
|
|
5253
|
-
function
|
|
5282
|
+
function useSelectorContext(editor) {
|
|
5254
5283
|
var eventListeners = React.useRef([]).current;
|
|
5255
5284
|
var slateRef = React.useRef({
|
|
5256
5285
|
editor: editor
|
|
@@ -5260,7 +5289,7 @@ function getSelectorContext(editor) {
|
|
|
5260
5289
|
eventListeners.forEach(function (listener) {
|
|
5261
5290
|
return listener(editor);
|
|
5262
5291
|
});
|
|
5263
|
-
}, []);
|
|
5292
|
+
}, [eventListeners, slateRef]);
|
|
5264
5293
|
var selectorContext = React.useMemo(function () {
|
|
5265
5294
|
return {
|
|
5266
5295
|
getSlate: function getSlate() {
|
|
@@ -5315,9 +5344,9 @@ var Slate = function Slate(props) {
|
|
|
5315
5344
|
context = _React$useState2[0],
|
|
5316
5345
|
setContext = _React$useState2[1];
|
|
5317
5346
|
|
|
5318
|
-
var
|
|
5319
|
-
selectorContext =
|
|
5320
|
-
handleSelectorChange =
|
|
5347
|
+
var _useSelectorContext = useSelectorContext(editor),
|
|
5348
|
+
selectorContext = _useSelectorContext.selectorContext,
|
|
5349
|
+
handleSelectorChange = _useSelectorContext.onChange;
|
|
5321
5350
|
|
|
5322
5351
|
var onContextChange = React.useCallback(function () {
|
|
5323
5352
|
if (onChange) {
|
|
@@ -5331,14 +5360,14 @@ var Slate = function Slate(props) {
|
|
|
5331
5360
|
};
|
|
5332
5361
|
});
|
|
5333
5362
|
handleSelectorChange(editor);
|
|
5334
|
-
}, [onChange]);
|
|
5363
|
+
}, [editor, handleSelectorChange, onChange]);
|
|
5335
5364
|
React.useEffect(function () {
|
|
5336
5365
|
EDITOR_TO_ON_CHANGE.set(editor, onContextChange);
|
|
5337
5366
|
return function () {
|
|
5338
5367
|
EDITOR_TO_ON_CHANGE.set(editor, function () {});
|
|
5339
5368
|
unmountRef.current = true;
|
|
5340
5369
|
};
|
|
5341
|
-
}, [onContextChange]);
|
|
5370
|
+
}, [editor, onContextChange]);
|
|
5342
5371
|
|
|
5343
5372
|
var _useState = React.useState(ReactEditor.isFocused(editor)),
|
|
5344
5373
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -5347,7 +5376,7 @@ var Slate = function Slate(props) {
|
|
|
5347
5376
|
|
|
5348
5377
|
React.useEffect(function () {
|
|
5349
5378
|
setIsFocused(ReactEditor.isFocused(editor));
|
|
5350
|
-
});
|
|
5379
|
+
}, [editor]);
|
|
5351
5380
|
useIsomorphicLayoutEffect(function () {
|
|
5352
5381
|
var fn = function fn() {
|
|
5353
5382
|
return setIsFocused(ReactEditor.isFocused(editor));
|