slate-react 0.106.0 → 0.107.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/index.js CHANGED
@@ -506,6 +506,15 @@ var getSlateFragmentAttribute = function getSlateFragmentAttribute(dataTransfer)
506
506
  fragment = _ref2[1];
507
507
  return fragment;
508
508
  };
509
+ /**
510
+ * Get the dom selection from Shadow Root if possible, otherwise from the document
511
+ */
512
+ var getSelection = function getSelection(root) {
513
+ if (root.getSelection != null) {
514
+ return root.getSelection();
515
+ }
516
+ return document.getSelection();
517
+ };
509
518
  /**
510
519
  * Check whether a mutation originates from a editable element inside the editor.
511
520
  */
@@ -639,7 +648,7 @@ var ReactEditor = {
639
648
  deselect: function deselect(editor) {
640
649
  var selection = editor.selection;
641
650
  var root = ReactEditor.findDocumentOrShadowRoot(editor);
642
- var domSelection = root.getSelection();
651
+ var domSelection = getSelection(root);
643
652
  if (domSelection && domSelection.rangeCount > 0) {
644
653
  domSelection.removeAllRanges();
645
654
  }
@@ -650,7 +659,7 @@ var ReactEditor = {
650
659
  findDocumentOrShadowRoot: function findDocumentOrShadowRoot(editor) {
651
660
  var el = ReactEditor.toDOMNode(editor, editor);
652
661
  var root = el.getRootNode();
653
- if ((root instanceof Document || root instanceof ShadowRoot) && root.getSelection != null) {
662
+ if (root instanceof Document || root instanceof ShadowRoot) {
654
663
  return root;
655
664
  }
656
665
  return el.ownerDocument;
@@ -764,7 +773,7 @@ var ReactEditor = {
764
773
  if (root.activeElement !== el) {
765
774
  // Ensure that the DOM selection state is set to the editor's selection
766
775
  if (editor.selection && root instanceof Document) {
767
- var domSelection = root.getSelection();
776
+ var domSelection = getSelection(root);
768
777
  var domRange = ReactEditor.toDOMRange(editor, editor.selection);
769
778
  domSelection === null || domSelection === void 0 || domSelection.removeAllRanges();
770
779
  domSelection === null || domSelection === void 0 || domSelection.addRange(domRange);
@@ -3326,7 +3335,7 @@ var Editable = function Editable(props) {
3326
3335
  var _root = ReactEditor.findDocumentOrShadowRoot(editor);
3327
3336
  var activeElement = _root.activeElement;
3328
3337
  var _el = ReactEditor.toDOMNode(editor, editor);
3329
- var domSelection = _root.getSelection();
3338
+ var domSelection = getSelection(_root);
3330
3339
  if (activeElement === _el) {
3331
3340
  state.latestElement = activeElement;
3332
3341
  IS_FOCUSED.set(editor, true);
@@ -3383,7 +3392,7 @@ var Editable = function Editable(props) {
3383
3392
  // Make sure the DOM selection state is in sync.
3384
3393
  var selection = editor.selection;
3385
3394
  var root = ReactEditor.findDocumentOrShadowRoot(editor);
3386
- var domSelection = root.getSelection();
3395
+ var domSelection = getSelection(root);
3387
3396
  if (!domSelection || !ReactEditor.isFocused(editor) || (_androidInputManagerR = androidInputManagerRef.current) !== null && _androidInputManagerR !== void 0 && _androidInputManagerR.hasPendingAction()) {
3388
3397
  return;
3389
3398
  }
@@ -3979,7 +3988,7 @@ var Editable = function Editable(props) {
3979
3988
  // editable element no longer has focus. Refer to:
3980
3989
  // https://stackoverflow.com/questions/12353247/force-contenteditable-div-to-stop-accepting-input-after-it-loses-focus-under-web
3981
3990
  if (IS_WEBKIT) {
3982
- var domSelection = root.getSelection();
3991
+ var domSelection = getSelection(root);
3983
3992
  domSelection === null || domSelection === void 0 || domSelection.removeAllRanges();
3984
3993
  }
3985
3994
  IS_FOCUSED["delete"](editor);