slate-react 0.76.0 → 0.76.1-20223315597

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.
@@ -1 +1 @@
1
- {"version":3,"file":"with-react.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/plugin/with-react.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAc5C;;;;;;;GAOG;AAEH,eAAO,MAAM,SAAS,uDAkOrB,CAAA"}
1
+ {"version":3,"file":"with-react.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/plugin/with-react.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAe5C;;;;;;;GAOG;AAEH,eAAO,MAAM,SAAS,uDAyOrB,CAAA"}
@@ -1071,6 +1071,7 @@
1071
1071
  var IS_FOCUSED = new WeakMap();
1072
1072
  var IS_COMPOSING = new WeakMap();
1073
1073
  var IS_ON_COMPOSITION_END = new WeakMap();
1074
+ var EDITOR_TO_USER_SELECTION = new WeakMap();
1074
1075
  /**
1075
1076
  * Weak maps for saving text on composition stage.
1076
1077
  */
@@ -2335,6 +2336,8 @@
2335
2336
 
2336
2337
  var onDOMBeforeInput = React.useCallback(function (event) {
2337
2338
  if (!readOnly && hasEditableTarget(editor, event.target) && !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
2339
+ var _EDITOR_TO_USER_SELEC;
2340
+
2338
2341
  // Some IMEs/Chrome extensions like e.g. Grammarly set the selection immediately before
2339
2342
  // triggering a `beforeinput` expecting the change to be applied to the immediately before
2340
2343
  // set selection.
@@ -2405,7 +2408,12 @@
2405
2408
  });
2406
2409
 
2407
2410
  if (!selection || !slate.Range.equals(selection, range)) {
2411
+ var selectionRef = editor.selection && slate.Editor.rangeRef(editor, editor.selection);
2408
2412
  slate.Transforms.select(editor, range);
2413
+
2414
+ if (selectionRef) {
2415
+ EDITOR_TO_USER_SELECTION.set(editor, selectionRef);
2416
+ }
2409
2417
  }
2410
2418
  }
2411
2419
  } // COMPAT: If the selection is expanded, even if the command seems like
@@ -2555,6 +2563,14 @@
2555
2563
 
2556
2564
  break;
2557
2565
  }
2566
+ } // Restore the actual user section if nothing manually set it.
2567
+
2568
+
2569
+ var toRestore = (_EDITOR_TO_USER_SELEC = EDITOR_TO_USER_SELECTION.get(editor)) === null || _EDITOR_TO_USER_SELEC === void 0 ? void 0 : _EDITOR_TO_USER_SELEC.unref();
2570
+ EDITOR_TO_USER_SELECTION["delete"](editor);
2571
+
2572
+ if (toRestore && (!editor.selection || !slate.Range.equals(editor.selection, toRestore))) {
2573
+ slate.Transforms.select(editor, toRestore);
2558
2574
  }
2559
2575
  }
2560
2576
  }, [readOnly, propsOnDOMBeforeInput]); // Attach a native DOM event handler for `beforeinput` events, because React's
@@ -2949,7 +2965,7 @@
2949
2965
  }
2950
2966
  }, [readOnly, attributes.onFocus]),
2951
2967
  onKeyDown: React.useCallback(function (event) {
2952
- if (!readOnly && !state.isComposing && hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onKeyDown)) {
2968
+ if (!readOnly && hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onKeyDown) && !state.isComposing) {
2953
2969
  var nativeEvent = event.nativeEvent;
2954
2970
  var selection = editor.selection;
2955
2971
  var element = editor.children[selection !== null ? selection.focus.path[0] : 0];
@@ -3279,6 +3295,7 @@
3279
3295
  * Check if the target is in the editor.
3280
3296
  */
3281
3297
 
3298
+
3282
3299
  var hasTarget = function hasTarget(editor, target) {
3283
3300
  return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target);
3284
3301
  };
@@ -5237,7 +5254,10 @@
5237
5254
  handleSelectorChange = _getSelectorContext.onChange;
5238
5255
 
5239
5256
  var onContextChange = React.useCallback(function () {
5240
- onChange(editor.children);
5257
+ if (onChange) {
5258
+ onChange(editor.children);
5259
+ }
5260
+
5241
5261
  setContext([editor]);
5242
5262
  handleSelectorChange(editor);
5243
5263
  }, [onChange]);
@@ -32849,6 +32869,16 @@
32849
32869
  break;
32850
32870
  }
32851
32871
 
32872
+ case 'set_selection':
32873
+ {
32874
+ var _EDITOR_TO_USER_SELEC;
32875
+
32876
+ // Selection was manually set, don't restore the user selection after the change.
32877
+ (_EDITOR_TO_USER_SELEC = EDITOR_TO_USER_SELECTION.get(editor)) === null || _EDITOR_TO_USER_SELEC === void 0 ? void 0 : _EDITOR_TO_USER_SELEC.unref();
32878
+ EDITOR_TO_USER_SELECTION["delete"](editor);
32879
+ break;
32880
+ }
32881
+
32852
32882
  case 'insert_node':
32853
32883
  case 'remove_node':
32854
32884
  {