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/index.js
CHANGED
|
@@ -221,6 +221,7 @@ var useSlateStatic = function useSlateStatic() {
|
|
|
221
221
|
return editor;
|
|
222
222
|
};
|
|
223
223
|
|
|
224
|
+
var _navigator$userAgent$, _navigator$userAgent$2;
|
|
224
225
|
var REACT_MAJOR_VERSION = parseInt(React.version.split('.')[0], 10);
|
|
225
226
|
var IS_IOS = typeof navigator !== 'undefined' && typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
226
227
|
var IS_APPLE = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent);
|
|
@@ -243,6 +244,8 @@ var IS_WECHATBROWSER = typeof navigator !== 'undefined' && /.*Wechat/.test(navig
|
|
|
243
244
|
// Check if DOM is available as React does internally.
|
|
244
245
|
// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
|
|
245
246
|
var CAN_USE_DOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
|
|
247
|
+
// Check if the browser is Safari and older than 17
|
|
248
|
+
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);
|
|
246
249
|
// COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
|
|
247
250
|
// Chrome Legacy doesn't support `beforeinput` correctly
|
|
248
251
|
var HAS_BEFORE_INPUT_SUPPORT = (!IS_CHROME_LEGACY || !IS_ANDROID_CHROME_LEGACY) && !IS_EDGE_LEGACY &&
|
|
@@ -556,6 +559,17 @@ var isTrackedMutation = function isTrackedMutation(editor, mutation, batch) {
|
|
|
556
559
|
// Target add/remove is tracked. Track the mutation if we track the parent mutation.
|
|
557
560
|
return isTrackedMutation(editor, parentMutation, batch);
|
|
558
561
|
};
|
|
562
|
+
/**
|
|
563
|
+
* Retrieves the deepest active element in the DOM, considering nested shadow DOMs.
|
|
564
|
+
*/
|
|
565
|
+
var getActiveElement = function getActiveElement() {
|
|
566
|
+
var activeElement = document.activeElement;
|
|
567
|
+
while ((_activeElement = activeElement) !== null && _activeElement !== void 0 && _activeElement.shadowRoot && (_activeElement$shadow = activeElement.shadowRoot) !== null && _activeElement$shadow !== void 0 && _activeElement$shadow.activeElement) {
|
|
568
|
+
var _activeElement, _activeElement$shadow, _activeElement2;
|
|
569
|
+
activeElement = (_activeElement2 = activeElement) === null || _activeElement2 === void 0 || (_activeElement2 = _activeElement2.shadowRoot) === null || _activeElement2 === void 0 ? void 0 : _activeElement2.activeElement;
|
|
570
|
+
}
|
|
571
|
+
return activeElement;
|
|
572
|
+
};
|
|
559
573
|
|
|
560
574
|
var createClass = createCommonjsModule(function (module) {
|
|
561
575
|
function _defineProperties(target, props) {
|
|
@@ -3252,6 +3266,7 @@ var Editable = function Editable(props) {
|
|
|
3252
3266
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
3253
3267
|
placeholderHeight = _useState4[0],
|
|
3254
3268
|
setPlaceholderHeight = _useState4[1];
|
|
3269
|
+
var processing = React.useRef(false);
|
|
3255
3270
|
var _useTrackUserInput = useTrackUserInput(),
|
|
3256
3271
|
onUserInput = _useTrackUserInput.onUserInput,
|
|
3257
3272
|
receivedUserInput = _useTrackUserInput.receivedUserInput;
|
|
@@ -3293,13 +3308,26 @@ var Editable = function Editable(props) {
|
|
|
3293
3308
|
// while a selection is being dragged.
|
|
3294
3309
|
var onDOMSelectionChange = React.useMemo(function () {
|
|
3295
3310
|
return throttle(function () {
|
|
3311
|
+
var el = ReactEditor.toDOMNode(editor, editor);
|
|
3312
|
+
var root = el.getRootNode();
|
|
3313
|
+
if (IS_SAFARI_LEGACY && !processing.current && IS_WEBKIT && root instanceof ShadowRoot) {
|
|
3314
|
+
processing.current = true;
|
|
3315
|
+
var active = getActiveElement();
|
|
3316
|
+
if (active) {
|
|
3317
|
+
document.execCommand('indent');
|
|
3318
|
+
} else {
|
|
3319
|
+
slate.Transforms.deselect(editor);
|
|
3320
|
+
}
|
|
3321
|
+
processing.current = false;
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3296
3324
|
var androidInputManager = androidInputManagerRef.current;
|
|
3297
3325
|
if ((IS_ANDROID || !ReactEditor.isComposing(editor)) && (!state.isUpdatingSelection || androidInputManager !== null && androidInputManager !== void 0 && androidInputManager.isFlushing()) && !state.isDraggingInternally) {
|
|
3298
|
-
var
|
|
3299
|
-
var activeElement =
|
|
3300
|
-
var
|
|
3301
|
-
var domSelection =
|
|
3302
|
-
if (activeElement ===
|
|
3326
|
+
var _root = ReactEditor.findDocumentOrShadowRoot(editor);
|
|
3327
|
+
var activeElement = _root.activeElement;
|
|
3328
|
+
var _el = ReactEditor.toDOMNode(editor, editor);
|
|
3329
|
+
var domSelection = _root.getSelection();
|
|
3330
|
+
if (activeElement === _el) {
|
|
3303
3331
|
state.latestElement = activeElement;
|
|
3304
3332
|
IS_FOCUSED.set(editor, true);
|
|
3305
3333
|
} else {
|
|
@@ -3485,6 +3513,24 @@ var Editable = function Editable(props) {
|
|
|
3485
3513
|
// to the real event sadly. (2019/11/01)
|
|
3486
3514
|
// https://github.com/facebook/react/issues/11211
|
|
3487
3515
|
var onDOMBeforeInput = React.useCallback(function (event) {
|
|
3516
|
+
var el = ReactEditor.toDOMNode(editor, editor);
|
|
3517
|
+
var root = el.getRootNode();
|
|
3518
|
+
if (IS_SAFARI_LEGACY && processing !== null && processing !== void 0 && processing.current && IS_WEBKIT && root instanceof ShadowRoot) {
|
|
3519
|
+
var ranges = event.getTargetRanges();
|
|
3520
|
+
var range = ranges[0];
|
|
3521
|
+
var newRange = new window.Range();
|
|
3522
|
+
newRange.setStart(range.startContainer, range.startOffset);
|
|
3523
|
+
newRange.setEnd(range.endContainer, range.endOffset);
|
|
3524
|
+
// Translate the DOM Range into a Slate Range
|
|
3525
|
+
var slateRange = ReactEditor.toSlateRange(editor, newRange, {
|
|
3526
|
+
exactMatch: false,
|
|
3527
|
+
suppressThrow: false
|
|
3528
|
+
});
|
|
3529
|
+
slate.Transforms.select(editor, slateRange);
|
|
3530
|
+
event.preventDefault();
|
|
3531
|
+
event.stopImmediatePropagation();
|
|
3532
|
+
return;
|
|
3533
|
+
}
|
|
3488
3534
|
onUserInput();
|
|
3489
3535
|
if (!readOnly && ReactEditor.hasEditableTarget(editor, event.target) && !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
|
|
3490
3536
|
var _EDITOR_TO_USER_SELEC;
|
|
@@ -3531,18 +3577,18 @@ var Editable = function Editable(props) {
|
|
|
3531
3577
|
node = _ReactEditor$toDOMPoi2[0],
|
|
3532
3578
|
offset = _ReactEditor$toDOMPoi2[1];
|
|
3533
3579
|
var anchorNode = (_node$parentElement = node.parentElement) === null || _node$parentElement === void 0 ? void 0 : _node$parentElement.closest('a');
|
|
3534
|
-
var
|
|
3580
|
+
var _window = ReactEditor.getWindow(editor);
|
|
3535
3581
|
if (_native && anchorNode && ReactEditor.hasDOMNode(editor, anchorNode)) {
|
|
3536
3582
|
var _lastText$textContent;
|
|
3537
3583
|
// Find the last text node inside the anchor.
|
|
3538
|
-
var lastText =
|
|
3584
|
+
var lastText = _window === null || _window === void 0 ? void 0 : _window.document.createTreeWalker(anchorNode, NodeFilter.SHOW_TEXT).lastChild();
|
|
3539
3585
|
if (lastText === node && ((_lastText$textContent = lastText.textContent) === null || _lastText$textContent === void 0 ? void 0 : _lastText$textContent.length) === offset) {
|
|
3540
3586
|
_native = false;
|
|
3541
3587
|
}
|
|
3542
3588
|
}
|
|
3543
3589
|
// Chrome has issues with the presence of tab characters inside elements with whiteSpace = 'pre'
|
|
3544
3590
|
// causing abnormal insert behavior: https://bugs.chromium.org/p/chromium/issues/detail?id=1219139
|
|
3545
|
-
if (_native && node.parentElement && (
|
|
3591
|
+
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') {
|
|
3546
3592
|
var block = slate.Editor.above(editor, {
|
|
3547
3593
|
at: anchor.path,
|
|
3548
3594
|
match: function match(n) {
|
|
@@ -3562,14 +3608,14 @@ var Editable = function Editable(props) {
|
|
|
3562
3608
|
_event$getTargetRange2 = _slicedToArray(_event$getTargetRange, 1),
|
|
3563
3609
|
targetRange = _event$getTargetRange2[0];
|
|
3564
3610
|
if (targetRange) {
|
|
3565
|
-
var
|
|
3611
|
+
var _range = ReactEditor.toSlateRange(editor, targetRange, {
|
|
3566
3612
|
exactMatch: false,
|
|
3567
3613
|
suppressThrow: false
|
|
3568
3614
|
});
|
|
3569
|
-
if (!selection || !slate.Range.equals(selection,
|
|
3615
|
+
if (!selection || !slate.Range.equals(selection, _range)) {
|
|
3570
3616
|
_native = false;
|
|
3571
3617
|
var selectionRef = !isCompositionChange && editor.selection && slate.Editor.rangeRef(editor, editor.selection);
|
|
3572
|
-
slate.Transforms.select(editor,
|
|
3618
|
+
slate.Transforms.select(editor, _range);
|
|
3573
3619
|
if (selectionRef) {
|
|
3574
3620
|
EDITOR_TO_USER_SELECTION.set(editor, selectionRef);
|
|
3575
3621
|
}
|
|
@@ -3967,8 +4013,8 @@ var Editable = function Editable(props) {
|
|
|
3967
4013
|
at: end
|
|
3968
4014
|
});
|
|
3969
4015
|
if (startVoid && endVoid && slate.Path.equals(startVoid[1], endVoid[1])) {
|
|
3970
|
-
var
|
|
3971
|
-
slate.Transforms.select(editor,
|
|
4016
|
+
var _range2 = slate.Editor.range(editor, _start);
|
|
4017
|
+
slate.Transforms.select(editor, _range2);
|
|
3972
4018
|
}
|
|
3973
4019
|
}
|
|
3974
4020
|
}, [editor, attributes.onClick, readOnly]),
|