slate-react 0.97.2 → 0.98.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
@@ -1146,15 +1146,37 @@ var ReactEditor = {
1146
1146
 
1147
1147
  if (el) {
1148
1148
  if (isDOMSelection(domRange)) {
1149
- anchorNode = domRange.anchorNode;
1150
- anchorOffset = domRange.anchorOffset;
1151
- focusNode = domRange.focusNode;
1152
- focusOffset = domRange.focusOffset; // COMPAT: There's a bug in chrome that always returns `true` for
1149
+ // COMPAT: In firefox the normal seletion way does not work
1150
+ // (https://github.com/ianstormtaylor/slate/pull/5486#issue-1820720223)
1151
+ if (IS_FIREFOX && domRange.rangeCount > 1) {
1152
+ focusNode = domRange.focusNode; // Focus node works fine
1153
+
1154
+ var firstRange = domRange.getRangeAt(0);
1155
+ var lastRange = domRange.getRangeAt(domRange.rangeCount - 1); // Right to left
1156
+
1157
+ if (firstRange.startContainer === focusNode) {
1158
+ anchorNode = lastRange.endContainer;
1159
+ anchorOffset = lastRange.endOffset;
1160
+ focusOffset = firstRange.startOffset;
1161
+ } else {
1162
+ // Left to right
1163
+ anchorNode = firstRange.startContainer;
1164
+ anchorOffset = firstRange.endOffset;
1165
+ focusOffset = lastRange.startOffset;
1166
+ }
1167
+ } else {
1168
+ anchorNode = domRange.anchorNode;
1169
+ anchorOffset = domRange.anchorOffset;
1170
+ focusNode = domRange.focusNode;
1171
+ focusOffset = domRange.focusOffset;
1172
+ } // COMPAT: There's a bug in chrome that always returns `true` for
1153
1173
  // `isCollapsed` for a Selection that comes from a ShadowRoot.
1154
1174
  // (2020/08/08)
1155
1175
  // https://bugs.chromium.org/p/chromium/issues/detail?id=447523
1176
+ // IsCollapsed might not work in firefox, but this will
1177
+
1156
1178
 
1157
- if (IS_CHROME && hasShadowRoot(anchorNode)) {
1179
+ if (IS_CHROME && hasShadowRoot(anchorNode) || IS_FIREFOX) {
1158
1180
  isCollapsed = domRange.anchorNode === domRange.focusNode && domRange.anchorOffset === domRange.focusOffset;
1159
1181
  } else {
1160
1182
  isCollapsed = domRange.isCollapsed;
@@ -1199,46 +1221,6 @@ var ReactEditor = {
1199
1221
  if (!focus) {
1200
1222
  return null;
1201
1223
  }
1202
- /**
1203
- * suppose we have this document:
1204
- *
1205
- * { type: 'paragraph',
1206
- * children: [
1207
- * { text: 'foo ' },
1208
- * { text: 'bar' },
1209
- * { text: ' baz' }
1210
- * ]
1211
- * }
1212
- *
1213
- * a double click on "bar" on chrome will create this range:
1214
- *
1215
- * anchor -> [0,1] offset 0
1216
- * focus -> [0,1] offset 3
1217
- *
1218
- * while on firefox will create this range:
1219
- *
1220
- * anchor -> [0,0] offset 4
1221
- * focus -> [0,2] offset 0
1222
- *
1223
- * let's try to fix it...
1224
- */
1225
-
1226
-
1227
- if (IS_FIREFOX && !isCollapsed && anchorNode !== focusNode) {
1228
- var isEnd = slate.Editor.isEnd(editor, anchor, anchor.path);
1229
- var isStart = slate.Editor.isStart(editor, focus, focus.path);
1230
-
1231
- if (isEnd) {
1232
- var after = slate.Editor.after(editor, anchor); // Editor.after() might return undefined
1233
-
1234
- anchor = after || anchor;
1235
- }
1236
-
1237
- if (isStart) {
1238
- var before = slate.Editor.before(editor, focus);
1239
- focus = before || focus;
1240
- }
1241
- }
1242
1224
 
1243
1225
  var range = {
1244
1226
  anchor: anchor,
@@ -3806,13 +3788,32 @@ var Editable = function Editable(props) {
3806
3788
 
3807
3789
  if (!selection && !hasDomSelection) {
3808
3790
  return;
3791
+ } // Get anchorNode and focusNode
3792
+
3793
+
3794
+ var focusNode = domSelection.focusNode;
3795
+ var anchorNode; // COMPAT: In firefox the normal seletion way does not work
3796
+ // (https://github.com/ianstormtaylor/slate/pull/5486#issue-1820720223)
3797
+
3798
+ if (IS_FIREFOX && domSelection.rangeCount > 1) {
3799
+ var firstRange = domSelection.getRangeAt(0);
3800
+ var lastRange = domSelection.getRangeAt(domSelection.rangeCount - 1); // Right to left
3801
+
3802
+ if (firstRange.startContainer === focusNode) {
3803
+ anchorNode = lastRange.endContainer;
3804
+ } else {
3805
+ // Left to right
3806
+ anchorNode = firstRange.startContainer;
3807
+ }
3808
+ } else {
3809
+ anchorNode = domSelection.anchorNode;
3809
3810
  } // verify that the dom selection is in the editor
3810
3811
 
3811
3812
 
3812
3813
  var editorElement = EDITOR_TO_ELEMENT.get(editor);
3813
3814
  var hasDomSelectionInEditor = false;
3814
3815
 
3815
- if (editorElement.contains(domSelection.anchorNode) && editorElement.contains(domSelection.focusNode)) {
3816
+ if (editorElement.contains(anchorNode) && editorElement.contains(focusNode)) {
3816
3817
  hasDomSelectionInEditor = true;
3817
3818
  } // If the DOM selection is in the editor and the editor selection is already correct, we're done.
3818
3819
 
@@ -3826,16 +3827,14 @@ var Editable = function Editable(props) {
3826
3827
  });
3827
3828
 
3828
3829
  if (slateRange && slate.Range.equals(slateRange, selection)) {
3829
- var _anchorNode$parentEle;
3830
+ var _anchorNode, _anchorNode$parentEle;
3830
3831
 
3831
3832
  if (!state.hasMarkPlaceholder) {
3832
3833
  return;
3833
3834
  } // Ensure selection is inside the mark placeholder
3834
3835
 
3835
3836
 
3836
- var anchorNode = domSelection.anchorNode;
3837
-
3838
- if (anchorNode !== null && anchorNode !== void 0 && (_anchorNode$parentEle = anchorNode.parentElement) !== null && _anchorNode$parentEle !== void 0 && _anchorNode$parentEle.hasAttribute('data-slate-mark-placeholder')) {
3837
+ if ((_anchorNode = anchorNode) !== null && _anchorNode !== void 0 && (_anchorNode$parentEle = _anchorNode.parentElement) !== null && _anchorNode$parentEle !== void 0 && _anchorNode$parentEle.hasAttribute('data-slate-mark-placeholder')) {
3839
3838
  return;
3840
3839
  }
3841
3840
  }
@@ -3872,20 +3871,17 @@ var Editable = function Editable(props) {
3872
3871
  }
3873
3872
 
3874
3873
  return newDomRange;
3875
- };
3874
+ }; // In firefox if there is more then 1 range and we call setDomSelection we remove the ability to select more cells in a table
3875
+
3876
+
3877
+ if (domSelection.rangeCount <= 1) {
3878
+ setDomSelection();
3879
+ }
3876
3880
 
3877
- var newDomRange = setDomSelection();
3878
3881
  var ensureSelection = ((_androidInputManagerR2 = androidInputManagerRef.current) === null || _androidInputManagerR2 === void 0 ? void 0 : _androidInputManagerR2.isFlushing()) === 'action';
3879
3882
 
3880
3883
  if (!IS_ANDROID || !ensureSelection) {
3881
3884
  setTimeout(function () {
3882
- // COMPAT: In Firefox, it's not enough to create a range, you also need
3883
- // to focus the contenteditable element too. (2016/11/16)
3884
- if (newDomRange && IS_FIREFOX) {
3885
- var el = ReactEditor.toDOMNode(editor, editor);
3886
- el.focus();
3887
- }
3888
-
3889
3885
  state.isUpdatingSelection = false;
3890
3886
  });
3891
3887
  return;