slate-react 0.78.1 → 0.79.0-20224219174

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.
@@ -12,6 +12,10 @@ export interface ReactEditor extends BaseEditor {
12
12
  hasRange: (editor: ReactEditor, range: Range) => boolean;
13
13
  }
14
14
  export declare const ReactEditor: {
15
+ /**
16
+ * Check if the user is currently composing inside the editor.
17
+ */
18
+ isComposing(editor: ReactEditor): boolean;
15
19
  /**
16
20
  * Return the host window of the current editor.
17
21
  */
@@ -1 +1 @@
1
- {"version":3,"file":"react-editor.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/plugin/react-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAc,UAAU,EAAE,MAAM,OAAO,CAAA;AAEhF,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAYlC,OAAO,EAEL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,cAAc,EAKf,MAAM,cAAc,CAAA;AAGrB;;GAEG;AAEH,MAAM,WAAW,WAAY,SAAQ,UAAU;IAC7C,UAAU,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAA;IACxC,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,CAAA;IACnD,cAAc,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,CAAA;IAC/C,eAAe,EAAE,CACf,IAAI,EAAE,YAAY,EAClB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,KAClC,IAAI,CAAA;IACT,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,CAAA;CACzD;AAED,eAAO,MAAM,WAAW;IACtB;;OAEG;sBAEe,WAAW,GAAG,MAAM;IAQtC;;OAEG;oBAEa,WAAW,QAAQ,IAAI,GAAG,GAAG;IA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EG;2BAEoB,WAAW,QAAQ,YAAY,GAAG,OAAO;IAIhE;;OAEG;4BAGO,WAAW,QACb,YAAY,sDAEjB,IAAI;IAIP;;OAEG;sBAEe,WAAW,QAAQ,IAAI,GAAG,WAAW;IAevD;;OAEG;uBAEgB,WAAW,SAAS,KAAK;IAgD5C;;;;;;;OAOG;uBAEgB,WAAW,SAAS,KAAK,GAAG,QAAQ;IA8BvD;;OAEG;wBAEiB,WAAW,WAAW,OAAO,GAAG,IAAI;IAgBxD;;OAEG;2BAEoB,WAAW,SAAS,GAAG,GAAG,KAAK;IAiEtD;;OAEG;4CAGO,WAAW;;;;IAmHrB;;OAEG;8CAGO,WAAW,YACT,QAAQ,GAAG,cAAc,GAAG,YAAY;;;;;;qBAyFnC,WAAW,SAAS,KAAK,GAAG,OAAO;CAMrD,CAAA"}
@@ -2189,7 +2189,6 @@
2189
2189
 
2190
2190
  var state = React.useMemo(function () {
2191
2191
  return {
2192
- isComposing: false,
2193
2192
  hasInsertPrefixInCompositon: false,
2194
2193
  isDraggingInternally: false,
2195
2194
  isUpdatingSelection: false,
@@ -2215,7 +2214,7 @@
2215
2214
  var root = ReactEditor.findDocumentOrShadowRoot(editor);
2216
2215
  var domSelection = root.getSelection();
2217
2216
 
2218
- if (state.isComposing || !domSelection || !ReactEditor.isFocused(editor)) {
2217
+ if (ReactEditor.isComposing(editor) || !domSelection || !ReactEditor.isFocused(editor)) {
2219
2218
  return;
2220
2219
  }
2221
2220
 
@@ -2299,7 +2298,7 @@
2299
2298
  // while a selection is being dragged.
2300
2299
 
2301
2300
  var onDOMSelectionChange = React.useCallback(throttle_1(function () {
2302
- if (!state.isComposing && !state.isUpdatingSelection && !state.isDraggingInternally) {
2301
+ if (!ReactEditor.isComposing(editor) && !state.isUpdatingSelection && !state.isDraggingInternally) {
2303
2302
  var root = ReactEditor.findDocumentOrShadowRoot(editor);
2304
2303
  var activeElement = root.activeElement;
2305
2304
  var el = ReactEditor.toDOMNode(editor, editor);
@@ -2551,8 +2550,10 @@
2551
2550
  // then we will abort because we're still composing and the selection
2552
2551
  // won't be updated properly.
2553
2552
  // https://www.w3.org/TR/input-events-2/
2554
- state.isComposing && setIsComposing(false);
2555
- state.isComposing = false;
2553
+ if (ReactEditor.isComposing(editor)) {
2554
+ setIsComposing(false);
2555
+ IS_COMPOSING.set(editor, false);
2556
+ }
2556
2557
  } // use a weak comparison instead of 'instanceof' to allow
2557
2558
  // programmatic access of paste events coming from external windows
2558
2559
  // like cypress where cy.window does not work realibly
@@ -2672,7 +2673,7 @@
2672
2673
  if (!HAS_BEFORE_INPUT_SUPPORT && !readOnly && !isEventHandled(event, attributes.onBeforeInput) && hasEditableTarget(editor, event.target)) {
2673
2674
  event.preventDefault();
2674
2675
 
2675
- if (!state.isComposing) {
2676
+ if (!ReactEditor.isComposing(editor)) {
2676
2677
  var text = event.data;
2677
2678
  slate.Editor.insertText(editor, text);
2678
2679
  }
@@ -2805,12 +2806,15 @@
2805
2806
  }, [readOnly, attributes.onClick]),
2806
2807
  onCompositionEnd: React.useCallback(function (event) {
2807
2808
  if (hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onCompositionEnd)) {
2808
- state.isComposing && setIsComposing(false);
2809
- state.isComposing = false; // COMPAT: In Chrome, `beforeinput` events for compositions
2809
+ if (ReactEditor.isComposing(editor)) {
2810
+ setIsComposing(false);
2811
+ IS_COMPOSING.set(editor, false);
2812
+ } // COMPAT: In Chrome, `beforeinput` events for compositions
2810
2813
  // aren't correct and never fire the "insertFromComposition"
2811
2814
  // type that we need. So instead, insert whenever a composition
2812
2815
  // ends since it will already have been committed to the DOM.
2813
2816
 
2817
+
2814
2818
  if (!IS_SAFARI && !IS_FIREFOX_LEGACY && !IS_IOS && !IS_QQBROWSER && !IS_WECHATBROWSER && !IS_UC_MOBILE && event.data) {
2815
2819
  slate.Editor.insertText(editor, event.data);
2816
2820
  }
@@ -2836,8 +2840,10 @@
2836
2840
  }, [attributes.onCompositionEnd]),
2837
2841
  onCompositionUpdate: React.useCallback(function (event) {
2838
2842
  if (hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onCompositionUpdate)) {
2839
- !state.isComposing && setIsComposing(true);
2840
- state.isComposing = true;
2843
+ if (!ReactEditor.isComposing(editor)) {
2844
+ setIsComposing(true);
2845
+ IS_COMPOSING.set(editor, true);
2846
+ }
2841
2847
  }
2842
2848
  }, [attributes.onCompositionUpdate]),
2843
2849
  onCompositionStart: React.useCallback(function (event) {
@@ -3004,12 +3010,12 @@
3004
3010
  // so we sometimes might end up stuck in a composition state even though we
3005
3011
  // aren't composing any more.
3006
3012
 
3007
- if (state.isComposing && nativeEvent.isComposing === false) {
3008
- state.isComposing = false;
3013
+ if (ReactEditor.isComposing(editor) && nativeEvent.isComposing === false) {
3014
+ IS_COMPOSING.set(editor, false);
3009
3015
  setIsComposing(false);
3010
3016
  }
3011
3017
 
3012
- if (isEventHandled(event, attributes.onKeyDown) || state.isComposing) {
3018
+ if (isEventHandled(event, attributes.onKeyDown) || ReactEditor.isComposing(editor)) {
3013
3019
  return;
3014
3020
  }
3015
3021
 
@@ -3654,6 +3660,13 @@
3654
3660
  };
3655
3661
 
3656
3662
  var ReactEditor = {
3663
+ /**
3664
+ * Check if the user is currently composing inside the editor.
3665
+ */
3666
+ isComposing: function isComposing(editor) {
3667
+ return !!IS_COMPOSING.get(editor);
3668
+ },
3669
+
3657
3670
  /**
3658
3671
  * Return the host window of the current editor.
3659
3672
  */
@@ -4427,7 +4440,7 @@
4427
4440
  var selection = _this.editor.selection; // If it is in composing or after `onCompositionend`, set `EDITOR_ON_COMPOSITION_TEXT` and return.
4428
4441
  // Text will be inserted on compositionend event.
4429
4442
 
4430
- if (IS_COMPOSING.get(_this.editor) || IS_ON_COMPOSITION_END.get(_this.editor)) {
4443
+ if (ReactEditor.isComposing(_this.editor) || IS_ON_COMPOSITION_END.get(_this.editor)) {
4431
4444
  EDITOR_ON_COMPOSITION_TEXT.set(_this.editor, insertedText);
4432
4445
  IS_ON_COMPOSITION_END.set(_this.editor, false);
4433
4446
  return;