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.
package/dist/index.js CHANGED
@@ -1279,7 +1279,6 @@ var Editable$1 = function Editable(props) {
1279
1279
 
1280
1280
  var state = React.useMemo(function () {
1281
1281
  return {
1282
- isComposing: false,
1283
1282
  hasInsertPrefixInCompositon: false,
1284
1283
  isDraggingInternally: false,
1285
1284
  isUpdatingSelection: false,
@@ -1305,7 +1304,7 @@ var Editable$1 = function Editable(props) {
1305
1304
  var root = ReactEditor.findDocumentOrShadowRoot(editor);
1306
1305
  var domSelection = root.getSelection();
1307
1306
 
1308
- if (state.isComposing || !domSelection || !ReactEditor.isFocused(editor)) {
1307
+ if (ReactEditor.isComposing(editor) || !domSelection || !ReactEditor.isFocused(editor)) {
1309
1308
  return;
1310
1309
  }
1311
1310
 
@@ -1389,7 +1388,7 @@ var Editable$1 = function Editable(props) {
1389
1388
  // while a selection is being dragged.
1390
1389
 
1391
1390
  var onDOMSelectionChange = React.useCallback(throttle__default['default'](function () {
1392
- if (!state.isComposing && !state.isUpdatingSelection && !state.isDraggingInternally) {
1391
+ if (!ReactEditor.isComposing(editor) && !state.isUpdatingSelection && !state.isDraggingInternally) {
1393
1392
  var root = ReactEditor.findDocumentOrShadowRoot(editor);
1394
1393
  var activeElement = root.activeElement;
1395
1394
  var el = ReactEditor.toDOMNode(editor, editor);
@@ -1641,8 +1640,10 @@ var Editable$1 = function Editable(props) {
1641
1640
  // then we will abort because we're still composing and the selection
1642
1641
  // won't be updated properly.
1643
1642
  // https://www.w3.org/TR/input-events-2/
1644
- state.isComposing && setIsComposing(false);
1645
- state.isComposing = false;
1643
+ if (ReactEditor.isComposing(editor)) {
1644
+ setIsComposing(false);
1645
+ IS_COMPOSING.set(editor, false);
1646
+ }
1646
1647
  } // use a weak comparison instead of 'instanceof' to allow
1647
1648
  // programmatic access of paste events coming from external windows
1648
1649
  // like cypress where cy.window does not work realibly
@@ -1762,7 +1763,7 @@ var Editable$1 = function Editable(props) {
1762
1763
  if (!HAS_BEFORE_INPUT_SUPPORT && !readOnly && !isEventHandled(event, attributes.onBeforeInput) && hasEditableTarget(editor, event.target)) {
1763
1764
  event.preventDefault();
1764
1765
 
1765
- if (!state.isComposing) {
1766
+ if (!ReactEditor.isComposing(editor)) {
1766
1767
  var text = event.data;
1767
1768
  slate.Editor.insertText(editor, text);
1768
1769
  }
@@ -1895,12 +1896,15 @@ var Editable$1 = function Editable(props) {
1895
1896
  }, [readOnly, attributes.onClick]),
1896
1897
  onCompositionEnd: React.useCallback(function (event) {
1897
1898
  if (hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onCompositionEnd)) {
1898
- state.isComposing && setIsComposing(false);
1899
- state.isComposing = false; // COMPAT: In Chrome, `beforeinput` events for compositions
1899
+ if (ReactEditor.isComposing(editor)) {
1900
+ setIsComposing(false);
1901
+ IS_COMPOSING.set(editor, false);
1902
+ } // COMPAT: In Chrome, `beforeinput` events for compositions
1900
1903
  // aren't correct and never fire the "insertFromComposition"
1901
1904
  // type that we need. So instead, insert whenever a composition
1902
1905
  // ends since it will already have been committed to the DOM.
1903
1906
 
1907
+
1904
1908
  if (!IS_SAFARI && !IS_FIREFOX_LEGACY && !IS_IOS && !IS_QQBROWSER && !IS_WECHATBROWSER && !IS_UC_MOBILE && event.data) {
1905
1909
  slate.Editor.insertText(editor, event.data);
1906
1910
  }
@@ -1926,8 +1930,10 @@ var Editable$1 = function Editable(props) {
1926
1930
  }, [attributes.onCompositionEnd]),
1927
1931
  onCompositionUpdate: React.useCallback(function (event) {
1928
1932
  if (hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onCompositionUpdate)) {
1929
- !state.isComposing && setIsComposing(true);
1930
- state.isComposing = true;
1933
+ if (!ReactEditor.isComposing(editor)) {
1934
+ setIsComposing(true);
1935
+ IS_COMPOSING.set(editor, true);
1936
+ }
1931
1937
  }
1932
1938
  }, [attributes.onCompositionUpdate]),
1933
1939
  onCompositionStart: React.useCallback(function (event) {
@@ -2094,12 +2100,12 @@ var Editable$1 = function Editable(props) {
2094
2100
  // so we sometimes might end up stuck in a composition state even though we
2095
2101
  // aren't composing any more.
2096
2102
 
2097
- if (state.isComposing && nativeEvent.isComposing === false) {
2098
- state.isComposing = false;
2103
+ if (ReactEditor.isComposing(editor) && nativeEvent.isComposing === false) {
2104
+ IS_COMPOSING.set(editor, false);
2099
2105
  setIsComposing(false);
2100
2106
  }
2101
2107
 
2102
- if (isEventHandled(event, attributes.onKeyDown) || state.isComposing) {
2108
+ if (isEventHandled(event, attributes.onKeyDown) || ReactEditor.isComposing(editor)) {
2103
2109
  return;
2104
2110
  }
2105
2111
 
@@ -2744,6 +2750,13 @@ var Key = function Key() {
2744
2750
  };
2745
2751
 
2746
2752
  var ReactEditor = {
2753
+ /**
2754
+ * Check if the user is currently composing inside the editor.
2755
+ */
2756
+ isComposing: function isComposing(editor) {
2757
+ return !!IS_COMPOSING.get(editor);
2758
+ },
2759
+
2747
2760
  /**
2748
2761
  * Return the host window of the current editor.
2749
2762
  */
@@ -3517,7 +3530,7 @@ var AndroidInputManager = function AndroidInputManager(editor, restoreDOM) {
3517
3530
  var selection = _this.editor.selection; // If it is in composing or after `onCompositionend`, set `EDITOR_ON_COMPOSITION_TEXT` and return.
3518
3531
  // Text will be inserted on compositionend event.
3519
3532
 
3520
- if (IS_COMPOSING.get(_this.editor) || IS_ON_COMPOSITION_END.get(_this.editor)) {
3533
+ if (ReactEditor.isComposing(_this.editor) || IS_ON_COMPOSITION_END.get(_this.editor)) {
3521
3534
  EDITOR_ON_COMPOSITION_TEXT.set(_this.editor, insertedText);
3522
3535
  IS_ON_COMPOSITION_END.set(_this.editor, false);
3523
3536
  return;