slate-react 0.102.0 → 0.104.0
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.map +1 -1
- package/dist/index.es.js +59 -13
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +59 -13
- package/dist/index.js.map +1 -1
- package/dist/slate-react.js +59 -13
- package/dist/slate-react.min.js +1 -1
- package/dist/utils/dom.d.ts +4 -0
- package/dist/utils/dom.d.ts.map +1 -1
- package/dist/utils/environment.d.ts +1 -0
- package/dist/utils/environment.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/slate-react.js
CHANGED
|
@@ -822,6 +822,7 @@
|
|
|
822
822
|
return editor;
|
|
823
823
|
};
|
|
824
824
|
|
|
825
|
+
var _navigator$userAgent$, _navigator$userAgent$2;
|
|
825
826
|
var REACT_MAJOR_VERSION = parseInt(React.version.split('.')[0], 10);
|
|
826
827
|
var IS_IOS = typeof navigator !== 'undefined' && typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
827
828
|
var IS_APPLE = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent);
|
|
@@ -844,6 +845,8 @@
|
|
|
844
845
|
// Check if DOM is available as React does internally.
|
|
845
846
|
// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
|
|
846
847
|
var CAN_USE_DOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
|
|
848
|
+
// Check if the browser is Safari and older than 17
|
|
849
|
+
var IS_SAFARI_LEGACY = typeof navigator !== 'undefined' && /Safari/.test(navigator.userAgent) && /Version\/(\d+)/.test(navigator.userAgent) && ((_navigator$userAgent$ = navigator.userAgent.match(/Version\/(\d+)/)) !== null && _navigator$userAgent$ !== void 0 && _navigator$userAgent$[1] ? parseInt((_navigator$userAgent$2 = navigator.userAgent.match(/Version\/(\d+)/)) === null || _navigator$userAgent$2 === void 0 ? void 0 : _navigator$userAgent$2[1], 10) < 17 : false);
|
|
847
850
|
// COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
|
|
848
851
|
// Chrome Legacy doesn't support `beforeinput` correctly
|
|
849
852
|
var HAS_BEFORE_INPUT_SUPPORT = (!IS_CHROME_LEGACY || !IS_ANDROID_CHROME_LEGACY) && !IS_EDGE_LEGACY &&
|
|
@@ -1157,6 +1160,17 @@
|
|
|
1157
1160
|
// Target add/remove is tracked. Track the mutation if we track the parent mutation.
|
|
1158
1161
|
return isTrackedMutation(editor, parentMutation, batch);
|
|
1159
1162
|
};
|
|
1163
|
+
/**
|
|
1164
|
+
* Retrieves the deepest active element in the DOM, considering nested shadow DOMs.
|
|
1165
|
+
*/
|
|
1166
|
+
var getActiveElement = function getActiveElement() {
|
|
1167
|
+
var activeElement = document.activeElement;
|
|
1168
|
+
while ((_activeElement = activeElement) !== null && _activeElement !== void 0 && _activeElement.shadowRoot && (_activeElement$shadow = activeElement.shadowRoot) !== null && _activeElement$shadow !== void 0 && _activeElement$shadow.activeElement) {
|
|
1169
|
+
var _activeElement, _activeElement$shadow, _activeElement2;
|
|
1170
|
+
activeElement = (_activeElement2 = activeElement) === null || _activeElement2 === void 0 || (_activeElement2 = _activeElement2.shadowRoot) === null || _activeElement2 === void 0 ? void 0 : _activeElement2.activeElement;
|
|
1171
|
+
}
|
|
1172
|
+
return activeElement;
|
|
1173
|
+
};
|
|
1160
1174
|
|
|
1161
1175
|
var createClass = createCommonjsModule(function (module) {
|
|
1162
1176
|
function _defineProperties(target, props) {
|
|
@@ -4612,6 +4626,7 @@
|
|
|
4612
4626
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
4613
4627
|
placeholderHeight = _useState4[0],
|
|
4614
4628
|
setPlaceholderHeight = _useState4[1];
|
|
4629
|
+
var processing = React.useRef(false);
|
|
4615
4630
|
var _useTrackUserInput = useTrackUserInput(),
|
|
4616
4631
|
onUserInput = _useTrackUserInput.onUserInput,
|
|
4617
4632
|
receivedUserInput = _useTrackUserInput.receivedUserInput;
|
|
@@ -4653,13 +4668,26 @@
|
|
|
4653
4668
|
// while a selection is being dragged.
|
|
4654
4669
|
var onDOMSelectionChange = React.useMemo(function () {
|
|
4655
4670
|
return throttle_1(function () {
|
|
4671
|
+
var el = ReactEditor.toDOMNode(editor, editor);
|
|
4672
|
+
var root = el.getRootNode();
|
|
4673
|
+
if (IS_SAFARI_LEGACY && !processing.current && IS_WEBKIT && root instanceof ShadowRoot) {
|
|
4674
|
+
processing.current = true;
|
|
4675
|
+
var active = getActiveElement();
|
|
4676
|
+
if (active) {
|
|
4677
|
+
document.execCommand('indent');
|
|
4678
|
+
} else {
|
|
4679
|
+
slate.Transforms.deselect(editor);
|
|
4680
|
+
}
|
|
4681
|
+
processing.current = false;
|
|
4682
|
+
return;
|
|
4683
|
+
}
|
|
4656
4684
|
var androidInputManager = androidInputManagerRef.current;
|
|
4657
4685
|
if ((IS_ANDROID || !ReactEditor.isComposing(editor)) && (!state.isUpdatingSelection || androidInputManager !== null && androidInputManager !== void 0 && androidInputManager.isFlushing()) && !state.isDraggingInternally) {
|
|
4658
|
-
var
|
|
4659
|
-
var activeElement =
|
|
4660
|
-
var
|
|
4661
|
-
var domSelection =
|
|
4662
|
-
if (activeElement ===
|
|
4686
|
+
var _root = ReactEditor.findDocumentOrShadowRoot(editor);
|
|
4687
|
+
var activeElement = _root.activeElement;
|
|
4688
|
+
var _el = ReactEditor.toDOMNode(editor, editor);
|
|
4689
|
+
var domSelection = _root.getSelection();
|
|
4690
|
+
if (activeElement === _el) {
|
|
4663
4691
|
state.latestElement = activeElement;
|
|
4664
4692
|
IS_FOCUSED.set(editor, true);
|
|
4665
4693
|
} else {
|
|
@@ -4845,6 +4873,24 @@
|
|
|
4845
4873
|
// to the real event sadly. (2019/11/01)
|
|
4846
4874
|
// https://github.com/facebook/react/issues/11211
|
|
4847
4875
|
var onDOMBeforeInput = React.useCallback(function (event) {
|
|
4876
|
+
var el = ReactEditor.toDOMNode(editor, editor);
|
|
4877
|
+
var root = el.getRootNode();
|
|
4878
|
+
if (IS_SAFARI_LEGACY && processing !== null && processing !== void 0 && processing.current && IS_WEBKIT && root instanceof ShadowRoot) {
|
|
4879
|
+
var ranges = event.getTargetRanges();
|
|
4880
|
+
var range = ranges[0];
|
|
4881
|
+
var newRange = new window.Range();
|
|
4882
|
+
newRange.setStart(range.startContainer, range.startOffset);
|
|
4883
|
+
newRange.setEnd(range.endContainer, range.endOffset);
|
|
4884
|
+
// Translate the DOM Range into a Slate Range
|
|
4885
|
+
var slateRange = ReactEditor.toSlateRange(editor, newRange, {
|
|
4886
|
+
exactMatch: false,
|
|
4887
|
+
suppressThrow: false
|
|
4888
|
+
});
|
|
4889
|
+
slate.Transforms.select(editor, slateRange);
|
|
4890
|
+
event.preventDefault();
|
|
4891
|
+
event.stopImmediatePropagation();
|
|
4892
|
+
return;
|
|
4893
|
+
}
|
|
4848
4894
|
onUserInput();
|
|
4849
4895
|
if (!readOnly && ReactEditor.hasEditableTarget(editor, event.target) && !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
|
|
4850
4896
|
var _EDITOR_TO_USER_SELEC;
|
|
@@ -4891,18 +4937,18 @@
|
|
|
4891
4937
|
node = _ReactEditor$toDOMPoi2[0],
|
|
4892
4938
|
offset = _ReactEditor$toDOMPoi2[1];
|
|
4893
4939
|
var anchorNode = (_node$parentElement = node.parentElement) === null || _node$parentElement === void 0 ? void 0 : _node$parentElement.closest('a');
|
|
4894
|
-
var
|
|
4940
|
+
var _window = ReactEditor.getWindow(editor);
|
|
4895
4941
|
if (_native && anchorNode && ReactEditor.hasDOMNode(editor, anchorNode)) {
|
|
4896
4942
|
var _lastText$textContent;
|
|
4897
4943
|
// Find the last text node inside the anchor.
|
|
4898
|
-
var lastText =
|
|
4944
|
+
var lastText = _window === null || _window === void 0 ? void 0 : _window.document.createTreeWalker(anchorNode, NodeFilter.SHOW_TEXT).lastChild();
|
|
4899
4945
|
if (lastText === node && ((_lastText$textContent = lastText.textContent) === null || _lastText$textContent === void 0 ? void 0 : _lastText$textContent.length) === offset) {
|
|
4900
4946
|
_native = false;
|
|
4901
4947
|
}
|
|
4902
4948
|
}
|
|
4903
4949
|
// Chrome has issues with the presence of tab characters inside elements with whiteSpace = 'pre'
|
|
4904
4950
|
// causing abnormal insert behavior: https://bugs.chromium.org/p/chromium/issues/detail?id=1219139
|
|
4905
|
-
if (_native && node.parentElement && (
|
|
4951
|
+
if (_native && node.parentElement && (_window === null || _window === void 0 || (_window$getComputedSt = _window.getComputedStyle(node.parentElement)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.whiteSpace) === 'pre') {
|
|
4906
4952
|
var block = slate.Editor.above(editor, {
|
|
4907
4953
|
at: anchor.path,
|
|
4908
4954
|
match: function match(n) {
|
|
@@ -4922,14 +4968,14 @@
|
|
|
4922
4968
|
_event$getTargetRange2 = _slicedToArray(_event$getTargetRange, 1),
|
|
4923
4969
|
targetRange = _event$getTargetRange2[0];
|
|
4924
4970
|
if (targetRange) {
|
|
4925
|
-
var
|
|
4971
|
+
var _range = ReactEditor.toSlateRange(editor, targetRange, {
|
|
4926
4972
|
exactMatch: false,
|
|
4927
4973
|
suppressThrow: false
|
|
4928
4974
|
});
|
|
4929
|
-
if (!selection || !slate.Range.equals(selection,
|
|
4975
|
+
if (!selection || !slate.Range.equals(selection, _range)) {
|
|
4930
4976
|
_native = false;
|
|
4931
4977
|
var selectionRef = !isCompositionChange && editor.selection && slate.Editor.rangeRef(editor, editor.selection);
|
|
4932
|
-
slate.Transforms.select(editor,
|
|
4978
|
+
slate.Transforms.select(editor, _range);
|
|
4933
4979
|
if (selectionRef) {
|
|
4934
4980
|
EDITOR_TO_USER_SELECTION.set(editor, selectionRef);
|
|
4935
4981
|
}
|
|
@@ -5327,8 +5373,8 @@
|
|
|
5327
5373
|
at: end
|
|
5328
5374
|
});
|
|
5329
5375
|
if (startVoid && endVoid && slate.Path.equals(startVoid[1], endVoid[1])) {
|
|
5330
|
-
var
|
|
5331
|
-
slate.Transforms.select(editor,
|
|
5376
|
+
var _range2 = slate.Editor.range(editor, _start);
|
|
5377
|
+
slate.Transforms.select(editor, _range2);
|
|
5332
5378
|
}
|
|
5333
5379
|
}
|
|
5334
5380
|
}, [editor, attributes.onClick, readOnly]),
|