lexical 0.14.4 → 0.15.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/Lexical.dev.js CHANGED
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
6
7
  */
8
+
7
9
  'use strict';
8
10
 
9
11
  /**
@@ -82,6 +84,7 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
82
84
  * LICENSE file in the root directory of this source tree.
83
85
  *
84
86
  */
87
+
85
88
  const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
86
89
  const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
87
90
  const IS_FIREFOX = CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
@@ -106,6 +109,7 @@ const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.user
106
109
  *
107
110
  */
108
111
 
112
+
109
113
  // DOM
110
114
  const DOM_ELEMENT_TYPE = 1;
111
115
  const DOM_TEXT_TYPE = 3;
@@ -231,6 +235,7 @@ function normalizeClassNames(...classNames) {
231
235
  * LICENSE file in the root directory of this source tree.
232
236
  *
233
237
  */
238
+
234
239
  // The time between a text entry event and the mutation observer firing.
235
240
  const TEXT_MUTATION_VARIANCE = 100;
236
241
  let isProcessingMutations = false;
@@ -260,7 +265,7 @@ function getLastSelection(editor) {
260
265
  return selection !== null ? selection.clone() : null;
261
266
  });
262
267
  }
263
- function handleTextMutation(target, node, editor) {
268
+ function $handleTextMutation(target, node, editor) {
264
269
  const domSelection = getDOMSelection(editor._window);
265
270
  let anchorOffset = null;
266
271
  let focusOffset = null;
@@ -308,7 +313,7 @@ function $flushMutations$1(editor, mutations, observer) {
308
313
  // Text mutations are deferred and passed to mutation listeners to be
309
314
  // processed outside of the Lexical engine.
310
315
  if (shouldFlushTextMutations && $isTextNode(targetNode) && shouldUpdateTextNodeFromMutation(selection, targetDOM, targetNode)) {
311
- handleTextMutation(
316
+ $handleTextMutation(
312
317
  // nodeType === DOM_TEXT_TYPE is a Text DOM node
313
318
  targetDOM, targetNode, editor);
314
319
  }
@@ -320,7 +325,7 @@ function $flushMutations$1(editor, mutations, observer) {
320
325
  const addedDOMs = mutation.addedNodes;
321
326
  for (let s = 0; s < addedDOMs.length; s++) {
322
327
  const addedDOM = addedDOMs[s];
323
- const node = getNodeFromDOMNode(addedDOM);
328
+ const node = $getNodeFromDOMNode(addedDOM);
324
329
  const parentDOM = addedDOM.parentNode;
325
330
  if (parentDOM != null && addedDOM !== blockCursorElement && node === null && (addedDOM.nodeName !== 'BR' || !isManagedLineBreak(addedDOM, parentDOM, editor))) {
326
331
  if (IS_FIREFOX) {
@@ -421,7 +426,7 @@ function $flushMutations$1(editor, mutations, observer) {
421
426
  isProcessingMutations = false;
422
427
  }
423
428
  }
424
- function flushRootMutations(editor) {
429
+ function $flushRootMutations(editor) {
425
430
  const observer = editor._observer;
426
431
  if (observer !== null) {
427
432
  const mutations = observer.takeRecords();
@@ -442,6 +447,7 @@ function initMutationObserver(editor) {
442
447
  * LICENSE file in the root directory of this source tree.
443
448
  *
444
449
  */
450
+
445
451
  function $canSimpleTextNodesBeMerged(node1, node2) {
446
452
  const node1Mode = node1.__mode;
447
453
  const node1Format = node1.__format;
@@ -526,6 +532,7 @@ function $normalizePoint(point) {
526
532
  * LICENSE file in the root directory of this source tree.
527
533
  *
528
534
  */
535
+
529
536
  let keyCounter = 1;
530
537
  function generateRandomKey() {
531
538
  return '' + keyCounter++;
@@ -654,6 +661,8 @@ function internalMarkParentElementsAsDirty(parentKey, nodeMap, dirtyElements) {
654
661
  nextParentKey = node.__parent;
655
662
  }
656
663
  }
664
+
665
+ // TODO #6031 this function or their callers have to adjust selection (i.e. insertBefore)
657
666
  function removeFromParent(node) {
658
667
  const oldParent = node.getParent();
659
668
  if (oldParent !== null) {
@@ -772,7 +781,7 @@ function $getNodeByKey(key, _editorState) {
772
781
  }
773
782
  return node;
774
783
  }
775
- function getNodeFromDOMNode(dom, editorState) {
784
+ function $getNodeFromDOMNode(dom, editorState) {
776
785
  const editor = getActiveEditor();
777
786
  // @ts-ignore We intentionally add this to the Node.
778
787
  const key = dom[`__lexicalKey_${editor._key}`];
@@ -784,7 +793,7 @@ function getNodeFromDOMNode(dom, editorState) {
784
793
  function $getNearestNodeFromDOMNode(startingDOM, editorState) {
785
794
  let dom = startingDOM;
786
795
  while (dom != null) {
787
- const node = getNodeFromDOMNode(dom, editorState);
796
+ const node = $getNodeFromDOMNode(dom, editorState);
788
797
  if (node !== null) {
789
798
  return node;
790
799
  }
@@ -845,9 +854,9 @@ function $setSelection(selection) {
845
854
  function $flushMutations() {
846
855
  errorOnReadOnly();
847
856
  const editor = getActiveEditor();
848
- flushRootMutations(editor);
857
+ $flushRootMutations(editor);
849
858
  }
850
- function getNodeFromDOM(dom) {
859
+ function $getNodeFromDOM(dom) {
851
860
  const editor = getActiveEditor();
852
861
  const nodeKey = getNodeKeyFromDOM(dom, editor);
853
862
  if (nodeKey === null) {
@@ -1006,20 +1015,20 @@ function $shouldInsertTextAfterOrBeforeTextNode(selection, node) {
1006
1015
  return false;
1007
1016
  }
1008
1017
  }
1009
- function isTab(keyCode, altKey, ctrlKey, metaKey) {
1010
- return keyCode === 9 && !altKey && !ctrlKey && !metaKey;
1018
+ function isTab(code, altKey, ctrlKey, metaKey) {
1019
+ return code === 'Tab' && !altKey && !ctrlKey && !metaKey;
1011
1020
  }
1012
- function isBold(keyCode, altKey, metaKey, ctrlKey) {
1013
- return keyCode === 66 && !altKey && controlOrMeta(metaKey, ctrlKey);
1021
+ function isBold(code, altKey, metaKey, ctrlKey) {
1022
+ return code === 'KeyB' && !altKey && controlOrMeta(metaKey, ctrlKey);
1014
1023
  }
1015
- function isItalic(keyCode, altKey, metaKey, ctrlKey) {
1016
- return keyCode === 73 && !altKey && controlOrMeta(metaKey, ctrlKey);
1024
+ function isItalic(code, altKey, metaKey, ctrlKey) {
1025
+ return code === 'KeyI' && !altKey && controlOrMeta(metaKey, ctrlKey);
1017
1026
  }
1018
- function isUnderline(keyCode, altKey, metaKey, ctrlKey) {
1019
- return keyCode === 85 && !altKey && controlOrMeta(metaKey, ctrlKey);
1027
+ function isUnderline(code, altKey, metaKey, ctrlKey) {
1028
+ return code === 'KeyU' && !altKey && controlOrMeta(metaKey, ctrlKey);
1020
1029
  }
1021
- function isParagraph(keyCode, shiftKey) {
1022
- return isReturn(keyCode) && !shiftKey;
1030
+ function isParagraph(code, shiftKey) {
1031
+ return isReturn(code) && !shiftKey;
1023
1032
  }
1024
1033
  function isLineBreak(keyCode, shiftKey) {
1025
1034
  return isReturn(keyCode) && shiftKey;
@@ -1027,108 +1036,108 @@ function isLineBreak(keyCode, shiftKey) {
1027
1036
 
1028
1037
  // Inserts a new line after the selection
1029
1038
 
1030
- function isOpenLineBreak(keyCode, ctrlKey) {
1039
+ function isOpenLineBreak(code, ctrlKey) {
1031
1040
  // 79 = KeyO
1032
- return IS_APPLE && ctrlKey && keyCode === 79;
1041
+ return IS_APPLE && ctrlKey && code === 'KeyO';
1033
1042
  }
1034
- function isDeleteWordBackward(keyCode, altKey, ctrlKey) {
1035
- return isBackspace(keyCode) && (IS_APPLE ? altKey : ctrlKey);
1043
+ function isDeleteWordBackward(code, altKey, ctrlKey) {
1044
+ return isBackspace(code) && (IS_APPLE ? altKey : ctrlKey);
1036
1045
  }
1037
- function isDeleteWordForward(keyCode, altKey, ctrlKey) {
1038
- return isDelete(keyCode) && (IS_APPLE ? altKey : ctrlKey);
1046
+ function isDeleteWordForward(code, altKey, ctrlKey) {
1047
+ return isDelete(code) && (IS_APPLE ? altKey : ctrlKey);
1039
1048
  }
1040
- function isDeleteLineBackward(keyCode, metaKey) {
1041
- return IS_APPLE && metaKey && isBackspace(keyCode);
1049
+ function isDeleteLineBackward(code, metaKey) {
1050
+ return IS_APPLE && metaKey && isBackspace(code);
1042
1051
  }
1043
- function isDeleteLineForward(keyCode, metaKey) {
1044
- return IS_APPLE && metaKey && isDelete(keyCode);
1052
+ function isDeleteLineForward(code, metaKey) {
1053
+ return IS_APPLE && metaKey && isDelete(code);
1045
1054
  }
1046
- function isDeleteBackward(keyCode, altKey, metaKey, ctrlKey) {
1055
+ function isDeleteBackward(code, altKey, metaKey, ctrlKey) {
1047
1056
  if (IS_APPLE) {
1048
1057
  if (altKey || metaKey) {
1049
1058
  return false;
1050
1059
  }
1051
- return isBackspace(keyCode) || keyCode === 72 && ctrlKey;
1060
+ return isBackspace(code) || code === 'KeyH' && ctrlKey;
1052
1061
  }
1053
1062
  if (ctrlKey || altKey || metaKey) {
1054
1063
  return false;
1055
1064
  }
1056
- return isBackspace(keyCode);
1065
+ return isBackspace(code);
1057
1066
  }
1058
- function isDeleteForward(keyCode, ctrlKey, shiftKey, altKey, metaKey) {
1067
+ function isDeleteForward(code, ctrlKey, shiftKey, altKey, metaKey) {
1059
1068
  if (IS_APPLE) {
1060
1069
  if (shiftKey || altKey || metaKey) {
1061
1070
  return false;
1062
1071
  }
1063
- return isDelete(keyCode) || keyCode === 68 && ctrlKey;
1072
+ return isDelete(code) || code === 'KeyD' && ctrlKey;
1064
1073
  }
1065
1074
  if (ctrlKey || altKey || metaKey) {
1066
1075
  return false;
1067
1076
  }
1068
- return isDelete(keyCode);
1077
+ return isDelete(code);
1069
1078
  }
1070
- function isUndo(keyCode, shiftKey, metaKey, ctrlKey) {
1071
- return keyCode === 90 && !shiftKey && controlOrMeta(metaKey, ctrlKey);
1079
+ function isUndo(code, shiftKey, metaKey, ctrlKey) {
1080
+ return code === 'KeyZ' && !shiftKey && controlOrMeta(metaKey, ctrlKey);
1072
1081
  }
1073
- function isRedo(keyCode, shiftKey, metaKey, ctrlKey) {
1082
+ function isRedo(code, shiftKey, metaKey, ctrlKey) {
1074
1083
  if (IS_APPLE) {
1075
- return keyCode === 90 && metaKey && shiftKey;
1084
+ return code === 'KeyZ' && metaKey && shiftKey;
1076
1085
  }
1077
- return keyCode === 89 && ctrlKey || keyCode === 90 && ctrlKey && shiftKey;
1086
+ return code === 'KeyY' && ctrlKey || code === 'KeyZ' && ctrlKey && shiftKey;
1078
1087
  }
1079
- function isCopy(keyCode, shiftKey, metaKey, ctrlKey) {
1088
+ function isCopy(code, shiftKey, metaKey, ctrlKey) {
1080
1089
  if (shiftKey) {
1081
1090
  return false;
1082
1091
  }
1083
- if (keyCode === 67) {
1092
+ if (code === 'KeyC') {
1084
1093
  return IS_APPLE ? metaKey : ctrlKey;
1085
1094
  }
1086
1095
  return false;
1087
1096
  }
1088
- function isCut(keyCode, shiftKey, metaKey, ctrlKey) {
1097
+ function isCut(code, shiftKey, metaKey, ctrlKey) {
1089
1098
  if (shiftKey) {
1090
1099
  return false;
1091
1100
  }
1092
- if (keyCode === 88) {
1101
+ if (code === 'KeyX') {
1093
1102
  return IS_APPLE ? metaKey : ctrlKey;
1094
1103
  }
1095
1104
  return false;
1096
1105
  }
1097
- function isArrowLeft(keyCode) {
1098
- return keyCode === 37;
1106
+ function isArrowLeft(code) {
1107
+ return code === 'ArrowLeft';
1099
1108
  }
1100
- function isArrowRight(keyCode) {
1101
- return keyCode === 39;
1109
+ function isArrowRight(code) {
1110
+ return code === 'ArrowRight';
1102
1111
  }
1103
- function isArrowUp(keyCode) {
1104
- return keyCode === 38;
1112
+ function isArrowUp(code) {
1113
+ return code === 'ArrowUp';
1105
1114
  }
1106
- function isArrowDown(keyCode) {
1107
- return keyCode === 40;
1115
+ function isArrowDown(code) {
1116
+ return code === 'ArrowDown';
1108
1117
  }
1109
- function isMoveBackward(keyCode, ctrlKey, altKey, metaKey) {
1110
- return isArrowLeft(keyCode) && !ctrlKey && !metaKey && !altKey;
1118
+ function isMoveBackward(code, ctrlKey, altKey, metaKey) {
1119
+ return isArrowLeft(code) && !ctrlKey && !metaKey && !altKey;
1111
1120
  }
1112
- function isMoveToStart(keyCode, ctrlKey, shiftKey, altKey, metaKey) {
1113
- return isArrowLeft(keyCode) && !altKey && !shiftKey && (ctrlKey || metaKey);
1121
+ function isMoveToStart(code, ctrlKey, shiftKey, altKey, metaKey) {
1122
+ return isArrowLeft(code) && !altKey && !shiftKey && (ctrlKey || metaKey);
1114
1123
  }
1115
- function isMoveForward(keyCode, ctrlKey, altKey, metaKey) {
1116
- return isArrowRight(keyCode) && !ctrlKey && !metaKey && !altKey;
1124
+ function isMoveForward(code, ctrlKey, altKey, metaKey) {
1125
+ return isArrowRight(code) && !ctrlKey && !metaKey && !altKey;
1117
1126
  }
1118
- function isMoveToEnd(keyCode, ctrlKey, shiftKey, altKey, metaKey) {
1119
- return isArrowRight(keyCode) && !altKey && !shiftKey && (ctrlKey || metaKey);
1127
+ function isMoveToEnd(code, ctrlKey, shiftKey, altKey, metaKey) {
1128
+ return isArrowRight(code) && !altKey && !shiftKey && (ctrlKey || metaKey);
1120
1129
  }
1121
- function isMoveUp(keyCode, ctrlKey, metaKey) {
1122
- return isArrowUp(keyCode) && !ctrlKey && !metaKey;
1130
+ function isMoveUp(code, ctrlKey, metaKey) {
1131
+ return isArrowUp(code) && !ctrlKey && !metaKey;
1123
1132
  }
1124
- function isMoveDown(keyCode, ctrlKey, metaKey) {
1125
- return isArrowDown(keyCode) && !ctrlKey && !metaKey;
1133
+ function isMoveDown(code, ctrlKey, metaKey) {
1134
+ return isArrowDown(code) && !ctrlKey && !metaKey;
1126
1135
  }
1127
1136
  function isModifier(ctrlKey, shiftKey, altKey, metaKey) {
1128
1137
  return ctrlKey || shiftKey || altKey || metaKey;
1129
1138
  }
1130
- function isSpace(keyCode) {
1131
- return keyCode === 32;
1139
+ function isSpace(code) {
1140
+ return code === 'Space';
1132
1141
  }
1133
1142
  function controlOrMeta(metaKey, ctrlKey) {
1134
1143
  if (IS_APPLE) {
@@ -1136,20 +1145,20 @@ function controlOrMeta(metaKey, ctrlKey) {
1136
1145
  }
1137
1146
  return ctrlKey;
1138
1147
  }
1139
- function isReturn(keyCode) {
1140
- return keyCode === 13;
1148
+ function isReturn(code) {
1149
+ return code === 'Enter';
1141
1150
  }
1142
- function isBackspace(keyCode) {
1143
- return keyCode === 8;
1151
+ function isBackspace(code) {
1152
+ return code === 'Backspace';
1144
1153
  }
1145
- function isEscape(keyCode) {
1146
- return keyCode === 27;
1154
+ function isEscape(code) {
1155
+ return code === 'Escape';
1147
1156
  }
1148
- function isDelete(keyCode) {
1149
- return keyCode === 46;
1157
+ function isDelete(code) {
1158
+ return code === 'Delete';
1150
1159
  }
1151
- function isSelectAll(keyCode, metaKey, ctrlKey) {
1152
- return keyCode === 65 && controlOrMeta(metaKey, ctrlKey);
1160
+ function isSelectAll(code, metaKey, ctrlKey) {
1161
+ return code === 'KeyA' && controlOrMeta(metaKey, ctrlKey);
1153
1162
  }
1154
1163
  function $selectAll() {
1155
1164
  const root = $getRoot();
@@ -1547,12 +1556,32 @@ function isHTMLElement(x) {
1547
1556
  return x.nodeType === 1;
1548
1557
  }
1549
1558
 
1559
+ /**
1560
+ *
1561
+ * @param node - the Dom Node to check
1562
+ * @returns if the Dom Node is an inline node
1563
+ */
1564
+ function isInlineDomNode(node) {
1565
+ const inlineNodes = new RegExp(/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var|#text)$/, 'i');
1566
+ return node.nodeName.match(inlineNodes) !== null;
1567
+ }
1568
+
1569
+ /**
1570
+ *
1571
+ * @param node - the Dom Node to check
1572
+ * @returns if the Dom Node is a block node
1573
+ */
1574
+ function isBlockDomNode(node) {
1575
+ const blockNodes = new RegExp(/^(address|article|aside|blockquote|canvas|dd|div|dl|dt|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hr|li|main|nav|noscript|ol|p|pre|section|table|td|tfoot|ul|video)$/, 'i');
1576
+ return node.nodeName.match(blockNodes) !== null;
1577
+ }
1578
+
1550
1579
  /**
1551
1580
  * This function is for internal use of the library.
1552
1581
  * Please do not use it as it may change in the future.
1553
1582
  */
1554
1583
  function INTERNAL_$isBlock(node) {
1555
- if ($isDecoratorNode(node) && !node.isInline()) {
1584
+ if ($isRootNode(node) || $isDecoratorNode(node) && !node.isInline()) {
1556
1585
  return true;
1557
1586
  }
1558
1587
  if (!$isElementNode(node) || $isRootOrShadowRoot(node)) {
@@ -1585,6 +1614,7 @@ function $getEditor() {
1585
1614
  * LICENSE file in the root directory of this source tree.
1586
1615
  *
1587
1616
  */
1617
+
1588
1618
  function $garbageCollectDetachedDecorators(editor, pendingEditorState) {
1589
1619
  const currentDecorators = editor._decorators;
1590
1620
  const pendingDecorators = editor._pendingDecorators;
@@ -1664,6 +1694,7 @@ function $garbageCollectDetachedNodes(prevEditorState, editorState, dirtyLeaves,
1664
1694
  * LICENSE file in the root directory of this source tree.
1665
1695
  *
1666
1696
  */
1697
+
1667
1698
  let subTreeTextContent = '';
1668
1699
  let subTreeDirectionedTextContent = '';
1669
1700
  let subTreeTextFormat = null;
@@ -1747,7 +1778,7 @@ function setElementFormat(dom, format) {
1747
1778
  setTextAlign(domStyle, 'end');
1748
1779
  }
1749
1780
  }
1750
- function createNode(key, parentDOM, insertDOM) {
1781
+ function $createNode(key, parentDOM, insertDOM) {
1751
1782
  const node = activeNextNodeMap.get(key);
1752
1783
  if (node === undefined) {
1753
1784
  {
@@ -1774,7 +1805,7 @@ function createNode(key, parentDOM, insertDOM) {
1774
1805
  if (childrenSize !== 0) {
1775
1806
  const endIndex = childrenSize - 1;
1776
1807
  const children = createChildrenArray(node, activeNextNodeMap);
1777
- createChildrenWithDirection(children, endIndex, node, dom);
1808
+ $createChildrenWithDirection(children, endIndex, node, dom);
1778
1809
  }
1779
1810
  const format = node.__format;
1780
1811
  if (format !== 0) {
@@ -1824,19 +1855,19 @@ function createNode(key, parentDOM, insertDOM) {
1824
1855
  setMutatedNode(mutatedNodes, activeEditorNodes, activeMutationListeners, node, 'created');
1825
1856
  return dom;
1826
1857
  }
1827
- function createChildrenWithDirection(children, endIndex, element, dom) {
1858
+ function $createChildrenWithDirection(children, endIndex, element, dom) {
1828
1859
  const previousSubTreeDirectionedTextContent = subTreeDirectionedTextContent;
1829
1860
  subTreeDirectionedTextContent = '';
1830
- createChildren(children, element, 0, endIndex, dom, null);
1861
+ $createChildren(children, element, 0, endIndex, dom, null);
1831
1862
  reconcileBlockDirection(element, dom);
1832
1863
  subTreeDirectionedTextContent = previousSubTreeDirectionedTextContent;
1833
1864
  }
1834
- function createChildren(children, element, _startIndex, endIndex, dom, insertDOM) {
1865
+ function $createChildren(children, element, _startIndex, endIndex, dom, insertDOM) {
1835
1866
  const previousSubTreeTextContent = subTreeTextContent;
1836
1867
  subTreeTextContent = '';
1837
1868
  let startIndex = _startIndex;
1838
1869
  for (; startIndex <= endIndex; ++startIndex) {
1839
- createNode(children[startIndex], dom, insertDOM);
1870
+ $createNode(children[startIndex], dom, insertDOM);
1840
1871
  const node = activeNextNodeMap.get(children[startIndex]);
1841
1872
  if (node !== null && subTreeTextFormat === null && $isTextNode(node)) {
1842
1873
  subTreeTextFormat = node.getFormat();
@@ -1937,11 +1968,11 @@ function reconcileBlockDirection(element, dom) {
1937
1968
  dom.__lexicalDir = direction;
1938
1969
  }
1939
1970
  }
1940
- function reconcileChildrenWithDirection(prevElement, nextElement, dom) {
1971
+ function $reconcileChildrenWithDirection(prevElement, nextElement, dom) {
1941
1972
  const previousSubTreeDirectionTextContent = subTreeDirectionedTextContent;
1942
1973
  subTreeDirectionedTextContent = '';
1943
1974
  subTreeTextFormat = null;
1944
- reconcileChildren(prevElement, nextElement, dom);
1975
+ $reconcileChildren(prevElement, nextElement, dom);
1945
1976
  reconcileBlockDirection(nextElement, dom);
1946
1977
  reconcileParagraphFormat(nextElement);
1947
1978
  subTreeDirectionedTextContent = previousSubTreeDirectionTextContent;
@@ -1962,7 +1993,7 @@ function createChildrenArray(element, nodeMap) {
1962
1993
  }
1963
1994
  return children;
1964
1995
  }
1965
- function reconcileChildren(prevElement, nextElement, dom) {
1996
+ function $reconcileChildren(prevElement, nextElement, dom) {
1966
1997
  const previousSubTreeTextContent = subTreeTextContent;
1967
1998
  const prevChildrenSize = prevElement.__size;
1968
1999
  const nextChildrenSize = nextElement.__size;
@@ -1971,10 +2002,10 @@ function reconcileChildren(prevElement, nextElement, dom) {
1971
2002
  const prevFirstChildKey = prevElement.__first;
1972
2003
  const nextFrstChildKey = nextElement.__first;
1973
2004
  if (prevFirstChildKey === nextFrstChildKey) {
1974
- reconcileNode(prevFirstChildKey, dom);
2005
+ $reconcileNode(prevFirstChildKey, dom);
1975
2006
  } else {
1976
2007
  const lastDOM = getPrevElementByKeyOrThrow(prevFirstChildKey);
1977
- const replacementDOM = createNode(nextFrstChildKey, null, null);
2008
+ const replacementDOM = $createNode(nextFrstChildKey, null, null);
1978
2009
  dom.replaceChild(replacementDOM, lastDOM);
1979
2010
  destroyNode(prevFirstChildKey, null);
1980
2011
  }
@@ -1987,7 +2018,7 @@ function reconcileChildren(prevElement, nextElement, dom) {
1987
2018
  const nextChildren = createChildrenArray(nextElement, activeNextNodeMap);
1988
2019
  if (prevChildrenSize === 0) {
1989
2020
  if (nextChildrenSize !== 0) {
1990
- createChildren(nextChildren, nextElement, 0, nextChildrenSize - 1, dom, null);
2021
+ $createChildren(nextChildren, nextElement, 0, nextChildrenSize - 1, dom, null);
1991
2022
  }
1992
2023
  } else if (nextChildrenSize === 0) {
1993
2024
  if (prevChildrenSize !== 0) {
@@ -2001,7 +2032,7 @@ function reconcileChildren(prevElement, nextElement, dom) {
2001
2032
  }
2002
2033
  }
2003
2034
  } else {
2004
- reconcileNodeChildren(nextElement, prevChildren, nextChildren, prevChildrenSize, nextChildrenSize, dom);
2035
+ $reconcileNodeChildren(nextElement, prevChildren, nextChildren, prevChildrenSize, nextChildrenSize, dom);
2005
2036
  }
2006
2037
  }
2007
2038
  if ($textContentRequiresDoubleLinebreakAtEnd(nextElement)) {
@@ -2012,7 +2043,7 @@ function reconcileChildren(prevElement, nextElement, dom) {
2012
2043
  dom.__lexicalTextContent = subTreeTextContent;
2013
2044
  subTreeTextContent = previousSubTreeTextContent + subTreeTextContent;
2014
2045
  }
2015
- function reconcileNode(key, parentDOM) {
2046
+ function $reconcileNode(key, parentDOM) {
2016
2047
  const prevNode = activePrevNodeMap.get(key);
2017
2048
  let nextNode = activeNextNodeMap.get(key);
2018
2049
  if (prevNode === undefined || nextNode === undefined) {
@@ -2058,7 +2089,7 @@ function reconcileNode(key, parentDOM) {
2058
2089
 
2059
2090
  // Update node. If it returns true, we need to unmount and re-create the node
2060
2091
  if (nextNode.updateDOM(prevNode, dom, activeEditorConfig)) {
2061
- const replacementDOM = createNode(key, null, null);
2092
+ const replacementDOM = $createNode(key, null, null);
2062
2093
  if (parentDOM === null) {
2063
2094
  {
2064
2095
  throw Error(`reconcileNode: parentDOM is null`);
@@ -2079,7 +2110,7 @@ function reconcileNode(key, parentDOM) {
2079
2110
  setElementFormat(dom, nextFormat);
2080
2111
  }
2081
2112
  if (isDirty) {
2082
- reconcileChildrenWithDirection(prevNode, nextNode, dom);
2113
+ $reconcileChildrenWithDirection(prevNode, nextNode, dom);
2083
2114
  if (!$isRootNode(nextNode) && !nextNode.isInline()) {
2084
2115
  reconcileElementTerminatingLineBreak(prevNode, nextNode, dom);
2085
2116
  }
@@ -2135,7 +2166,7 @@ function getNextSibling(element) {
2135
2166
  }
2136
2167
  return nextSibling;
2137
2168
  }
2138
- function reconcileNodeChildren(nextElement, prevChildren, nextChildren, prevChildrenLength, nextChildrenLength, dom) {
2169
+ function $reconcileNodeChildren(nextElement, prevChildren, nextChildren, prevChildrenLength, nextChildrenLength, dom) {
2139
2170
  const prevEndIndex = prevChildrenLength - 1;
2140
2171
  const nextEndIndex = nextChildrenLength - 1;
2141
2172
  let prevChildrenSet;
@@ -2147,7 +2178,7 @@ function reconcileNodeChildren(nextElement, prevChildren, nextChildren, prevChil
2147
2178
  const prevKey = prevChildren[prevIndex];
2148
2179
  const nextKey = nextChildren[nextIndex];
2149
2180
  if (prevKey === nextKey) {
2150
- siblingDOM = getNextSibling(reconcileNode(nextKey, dom));
2181
+ siblingDOM = getNextSibling($reconcileNode(nextKey, dom));
2151
2182
  prevIndex++;
2152
2183
  nextIndex++;
2153
2184
  } else {
@@ -2166,20 +2197,20 @@ function reconcileNodeChildren(nextElement, prevChildren, nextChildren, prevChil
2166
2197
  prevIndex++;
2167
2198
  } else if (!prevHasNextKey) {
2168
2199
  // Create next
2169
- createNode(nextKey, dom, siblingDOM);
2200
+ $createNode(nextKey, dom, siblingDOM);
2170
2201
  nextIndex++;
2171
2202
  } else {
2172
2203
  // Move next
2173
2204
  const childDOM = getElementByKeyOrThrow(activeEditor$1, nextKey);
2174
2205
  if (childDOM === siblingDOM) {
2175
- siblingDOM = getNextSibling(reconcileNode(nextKey, dom));
2206
+ siblingDOM = getNextSibling($reconcileNode(nextKey, dom));
2176
2207
  } else {
2177
2208
  if (siblingDOM != null) {
2178
2209
  dom.insertBefore(childDOM, siblingDOM);
2179
2210
  } else {
2180
2211
  dom.appendChild(childDOM);
2181
2212
  }
2182
- reconcileNode(nextKey, dom);
2213
+ $reconcileNode(nextKey, dom);
2183
2214
  }
2184
2215
  prevIndex++;
2185
2216
  nextIndex++;
@@ -2195,12 +2226,12 @@ function reconcileNodeChildren(nextElement, prevChildren, nextChildren, prevChil
2195
2226
  if (appendNewChildren && !removeOldChildren) {
2196
2227
  const previousNode = nextChildren[nextEndIndex + 1];
2197
2228
  const insertDOM = previousNode === undefined ? null : activeEditor$1.getElementByKey(previousNode);
2198
- createChildren(nextChildren, nextElement, nextIndex, nextEndIndex, dom, insertDOM);
2229
+ $createChildren(nextChildren, nextElement, nextIndex, nextEndIndex, dom, insertDOM);
2199
2230
  } else if (removeOldChildren && !appendNewChildren) {
2200
2231
  destroyChildren(prevChildren, prevIndex, prevEndIndex, dom);
2201
2232
  }
2202
2233
  }
2203
- function reconcileRoot(prevEditorState, nextEditorState, editor, dirtyType, dirtyElements, dirtyLeaves) {
2234
+ function $reconcileRoot(prevEditorState, nextEditorState, editor, dirtyType, dirtyElements, dirtyLeaves) {
2204
2235
  // We cache text content to make retrieval more efficient.
2205
2236
  // The cache must be rebuilt during reconciliation to account for any changes.
2206
2237
  subTreeTextContent = '';
@@ -2224,7 +2255,7 @@ function reconcileRoot(prevEditorState, nextEditorState, editor, dirtyType, dirt
2224
2255
  // listeners later in the update cycle.
2225
2256
  const currentMutatedNodes = new Map();
2226
2257
  mutatedNodes = currentMutatedNodes;
2227
- reconcileNode('root', null);
2258
+ $reconcileNode('root', null);
2228
2259
  // We don't want a bunch of void checks throughout the scope
2229
2260
  // so instead we make it seem that these values are always set.
2230
2261
  // We also want to make sure we clear them down, otherwise we
@@ -2272,6 +2303,7 @@ function getPrevElementByKeyOrThrow(key) {
2272
2303
  * LICENSE file in the root directory of this source tree.
2273
2304
  *
2274
2305
  */
2306
+
2275
2307
  const PASS_THROUGH_COMMAND = Object.freeze({});
2276
2308
  const ANDROID_COMPOSITION_LATENCY = 30;
2277
2309
  const rootElementEvents = [['keydown', onKeyDown], ['pointerdown', onPointerDown], ['compositionstart', onCompositionStart], ['compositionend', onCompositionEnd], ['input', onInput], ['click', onClick], ['cut', PASS_THROUGH_COMMAND], ['copy', PASS_THROUGH_COMMAND], ['dragstart', PASS_THROUGH_COMMAND], ['dragover', PASS_THROUGH_COMMAND], ['dragend', PASS_THROUGH_COMMAND], ['paste', PASS_THROUGH_COMMAND], ['focus', PASS_THROUGH_COMMAND], ['blur', PASS_THROUGH_COMMAND], ['drop', PASS_THROUGH_COMMAND]];
@@ -2279,7 +2311,7 @@ if (CAN_USE_BEFORE_INPUT) {
2279
2311
  rootElementEvents.push(['beforeinput', (event, editor) => onBeforeInput(event, editor)]);
2280
2312
  }
2281
2313
  let lastKeyDownTimeStamp = 0;
2282
- let lastKeyCode = 0;
2314
+ let lastKeyCode = null;
2283
2315
  let lastBeforeInputInsertTextTimeStamp = 0;
2284
2316
  let unprocessedBeforeInputData = null;
2285
2317
  const rootElementsRegistered = new WeakMap();
@@ -2484,7 +2516,7 @@ function onClick(event, editor) {
2484
2516
  // When we click on an empty paragraph node or the end of a paragraph that ends
2485
2517
  // with an image/poll, the nodeType will be ELEMENT_NODE
2486
2518
  if (nodeType === DOM_ELEMENT_TYPE || nodeType === DOM_TEXT_TYPE) {
2487
- const newSelection = internalCreateRangeSelection(lastSelection, domSelection, editor, event);
2519
+ const newSelection = $internalCreateRangeSelection(lastSelection, domSelection, editor, event);
2488
2520
  $setSelection(newSelection);
2489
2521
  }
2490
2522
  }
@@ -2521,7 +2553,7 @@ function $canRemoveText(anchorNode, focusNode) {
2521
2553
  return anchorNode !== focusNode || $isElementNode(anchorNode) || $isElementNode(focusNode) || !anchorNode.isToken() || !focusNode.isToken();
2522
2554
  }
2523
2555
  function isPossiblyAndroidKeyPress(timeStamp) {
2524
- return lastKeyCode === 229 && timeStamp < lastKeyDownTimeStamp + ANDROID_COMPOSITION_LATENCY;
2556
+ return lastKeyCode === 'Delete' && timeStamp < lastKeyDownTimeStamp + ANDROID_COMPOSITION_LATENCY;
2525
2557
  }
2526
2558
  function onBeforeInput(event, editor) {
2527
2559
  const inputType = event.inputType;
@@ -2767,7 +2799,7 @@ function onInput(event, editor) {
2767
2799
  // to ensure to disable composition before dispatching the
2768
2800
  // insertText command for when changing the sequence for FF.
2769
2801
  if (isFirefoxEndingComposition) {
2770
- onCompositionEndImpl(editor, data);
2802
+ $onCompositionEndImpl(editor, data);
2771
2803
  isFirefoxEndingComposition = false;
2772
2804
  }
2773
2805
  const anchor = selection.anchor;
@@ -2776,11 +2808,13 @@ function onInput(event, editor) {
2776
2808
  if (domSelection === null) {
2777
2809
  return;
2778
2810
  }
2779
- const offset = anchor.offset;
2811
+ const isBackward = selection.isBackward();
2812
+ const startOffset = isBackward ? selection.anchor.offset : selection.focus.offset;
2813
+ const endOffset = isBackward ? selection.focus.offset : selection.anchor.offset;
2780
2814
  // If the content is the same as inserted, then don't dispatch an insertion.
2781
2815
  // Given onInput doesn't take the current selection (it uses the previous)
2782
2816
  // we can compare that against what the DOM currently says.
2783
- if (!CAN_USE_BEFORE_INPUT || selection.isCollapsed() || !$isTextNode(anchorNode) || domSelection.anchorNode === null || anchorNode.getTextContent().slice(0, offset) + data + anchorNode.getTextContent().slice(offset + selection.focus.offset) !== getAnchorTextFromDOM(domSelection.anchorNode)) {
2817
+ if (!CAN_USE_BEFORE_INPUT || selection.isCollapsed() || !$isTextNode(anchorNode) || domSelection.anchorNode === null || anchorNode.getTextContent().slice(0, startOffset) + data + anchorNode.getTextContent().slice(startOffset + endOffset) !== getAnchorTextFromDOM(domSelection.anchorNode)) {
2784
2818
  dispatchCommand(editor, CONTROLLED_TEXT_INSERTION_COMMAND, data);
2785
2819
  }
2786
2820
  const textLength = data.length;
@@ -2802,7 +2836,7 @@ function onInput(event, editor) {
2802
2836
 
2803
2837
  // onInput always fires after onCompositionEnd for FF.
2804
2838
  if (isFirefoxEndingComposition) {
2805
- onCompositionEndImpl(editor, data || undefined);
2839
+ $onCompositionEndImpl(editor, data || undefined);
2806
2840
  isFirefoxEndingComposition = false;
2807
2841
  }
2808
2842
  }
@@ -2837,7 +2871,7 @@ function onCompositionStart(event, editor) {
2837
2871
  }
2838
2872
  });
2839
2873
  }
2840
- function onCompositionEndImpl(editor, data) {
2874
+ function $onCompositionEndImpl(editor, data) {
2841
2875
  const compositionKey = editor._compositionKey;
2842
2876
  $setCompositionKey(null);
2843
2877
 
@@ -2880,18 +2914,18 @@ function onCompositionEnd(event, editor) {
2880
2914
  isFirefoxEndingComposition = true;
2881
2915
  } else {
2882
2916
  updateEditor(editor, () => {
2883
- onCompositionEndImpl(editor, event.data);
2917
+ $onCompositionEndImpl(editor, event.data);
2884
2918
  });
2885
2919
  }
2886
2920
  }
2887
2921
  function onKeyDown(event, editor) {
2888
2922
  lastKeyDownTimeStamp = event.timeStamp;
2889
- lastKeyCode = event.keyCode;
2923
+ lastKeyCode = event.code;
2890
2924
  if (editor.isComposing()) {
2891
2925
  return;
2892
2926
  }
2893
2927
  const {
2894
- keyCode,
2928
+ code,
2895
2929
  shiftKey,
2896
2930
  ctrlKey,
2897
2931
  metaKey,
@@ -2900,90 +2934,90 @@ function onKeyDown(event, editor) {
2900
2934
  if (dispatchCommand(editor, KEY_DOWN_COMMAND, event)) {
2901
2935
  return;
2902
2936
  }
2903
- if (isMoveForward(keyCode, ctrlKey, altKey, metaKey)) {
2937
+ if (isMoveForward(code, ctrlKey, altKey, metaKey)) {
2904
2938
  dispatchCommand(editor, KEY_ARROW_RIGHT_COMMAND, event);
2905
- } else if (isMoveToEnd(keyCode, ctrlKey, shiftKey, altKey, metaKey)) {
2939
+ } else if (isMoveToEnd(code, ctrlKey, shiftKey, altKey, metaKey)) {
2906
2940
  dispatchCommand(editor, MOVE_TO_END, event);
2907
- } else if (isMoveBackward(keyCode, ctrlKey, altKey, metaKey)) {
2941
+ } else if (isMoveBackward(code, ctrlKey, altKey, metaKey)) {
2908
2942
  dispatchCommand(editor, KEY_ARROW_LEFT_COMMAND, event);
2909
- } else if (isMoveToStart(keyCode, ctrlKey, shiftKey, altKey, metaKey)) {
2943
+ } else if (isMoveToStart(code, ctrlKey, shiftKey, altKey, metaKey)) {
2910
2944
  dispatchCommand(editor, MOVE_TO_START, event);
2911
- } else if (isMoveUp(keyCode, ctrlKey, metaKey)) {
2945
+ } else if (isMoveUp(code, ctrlKey, metaKey)) {
2912
2946
  dispatchCommand(editor, KEY_ARROW_UP_COMMAND, event);
2913
- } else if (isMoveDown(keyCode, ctrlKey, metaKey)) {
2947
+ } else if (isMoveDown(code, ctrlKey, metaKey)) {
2914
2948
  dispatchCommand(editor, KEY_ARROW_DOWN_COMMAND, event);
2915
- } else if (isLineBreak(keyCode, shiftKey)) {
2949
+ } else if (isLineBreak(code, shiftKey)) {
2916
2950
  isInsertLineBreak = true;
2917
2951
  dispatchCommand(editor, KEY_ENTER_COMMAND, event);
2918
- } else if (isSpace(keyCode)) {
2952
+ } else if (isSpace(code)) {
2919
2953
  dispatchCommand(editor, KEY_SPACE_COMMAND, event);
2920
- } else if (isOpenLineBreak(keyCode, ctrlKey)) {
2954
+ } else if (isOpenLineBreak(code, ctrlKey)) {
2921
2955
  event.preventDefault();
2922
2956
  isInsertLineBreak = true;
2923
2957
  dispatchCommand(editor, INSERT_LINE_BREAK_COMMAND, true);
2924
- } else if (isParagraph(keyCode, shiftKey)) {
2958
+ } else if (isParagraph(code, shiftKey)) {
2925
2959
  isInsertLineBreak = false;
2926
2960
  dispatchCommand(editor, KEY_ENTER_COMMAND, event);
2927
- } else if (isDeleteBackward(keyCode, altKey, metaKey, ctrlKey)) {
2928
- if (isBackspace(keyCode)) {
2961
+ } else if (isDeleteBackward(code, altKey, metaKey, ctrlKey)) {
2962
+ if (isBackspace(code)) {
2929
2963
  dispatchCommand(editor, KEY_BACKSPACE_COMMAND, event);
2930
2964
  } else {
2931
2965
  event.preventDefault();
2932
2966
  dispatchCommand(editor, DELETE_CHARACTER_COMMAND, true);
2933
2967
  }
2934
- } else if (isEscape(keyCode)) {
2968
+ } else if (isEscape(code)) {
2935
2969
  dispatchCommand(editor, KEY_ESCAPE_COMMAND, event);
2936
- } else if (isDeleteForward(keyCode, ctrlKey, shiftKey, altKey, metaKey)) {
2937
- if (isDelete(keyCode)) {
2970
+ } else if (isDeleteForward(code, ctrlKey, shiftKey, altKey, metaKey)) {
2971
+ if (isDelete(code)) {
2938
2972
  dispatchCommand(editor, KEY_DELETE_COMMAND, event);
2939
2973
  } else {
2940
2974
  event.preventDefault();
2941
2975
  dispatchCommand(editor, DELETE_CHARACTER_COMMAND, false);
2942
2976
  }
2943
- } else if (isDeleteWordBackward(keyCode, altKey, ctrlKey)) {
2977
+ } else if (isDeleteWordBackward(code, altKey, ctrlKey)) {
2944
2978
  event.preventDefault();
2945
2979
  dispatchCommand(editor, DELETE_WORD_COMMAND, true);
2946
- } else if (isDeleteWordForward(keyCode, altKey, ctrlKey)) {
2980
+ } else if (isDeleteWordForward(code, altKey, ctrlKey)) {
2947
2981
  event.preventDefault();
2948
2982
  dispatchCommand(editor, DELETE_WORD_COMMAND, false);
2949
- } else if (isDeleteLineBackward(keyCode, metaKey)) {
2983
+ } else if (isDeleteLineBackward(code, metaKey)) {
2950
2984
  event.preventDefault();
2951
2985
  dispatchCommand(editor, DELETE_LINE_COMMAND, true);
2952
- } else if (isDeleteLineForward(keyCode, metaKey)) {
2986
+ } else if (isDeleteLineForward(code, metaKey)) {
2953
2987
  event.preventDefault();
2954
2988
  dispatchCommand(editor, DELETE_LINE_COMMAND, false);
2955
- } else if (isBold(keyCode, altKey, metaKey, ctrlKey)) {
2989
+ } else if (isBold(code, altKey, metaKey, ctrlKey)) {
2956
2990
  event.preventDefault();
2957
2991
  dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'bold');
2958
- } else if (isUnderline(keyCode, altKey, metaKey, ctrlKey)) {
2992
+ } else if (isUnderline(code, altKey, metaKey, ctrlKey)) {
2959
2993
  event.preventDefault();
2960
2994
  dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'underline');
2961
- } else if (isItalic(keyCode, altKey, metaKey, ctrlKey)) {
2995
+ } else if (isItalic(code, altKey, metaKey, ctrlKey)) {
2962
2996
  event.preventDefault();
2963
2997
  dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'italic');
2964
- } else if (isTab(keyCode, altKey, ctrlKey, metaKey)) {
2998
+ } else if (isTab(code, altKey, ctrlKey, metaKey)) {
2965
2999
  dispatchCommand(editor, KEY_TAB_COMMAND, event);
2966
- } else if (isUndo(keyCode, shiftKey, metaKey, ctrlKey)) {
3000
+ } else if (isUndo(code, shiftKey, metaKey, ctrlKey)) {
2967
3001
  event.preventDefault();
2968
3002
  dispatchCommand(editor, UNDO_COMMAND, undefined);
2969
- } else if (isRedo(keyCode, shiftKey, metaKey, ctrlKey)) {
3003
+ } else if (isRedo(code, shiftKey, metaKey, ctrlKey)) {
2970
3004
  event.preventDefault();
2971
3005
  dispatchCommand(editor, REDO_COMMAND, undefined);
2972
3006
  } else {
2973
3007
  const prevSelection = editor._editorState._selection;
2974
3008
  if ($isNodeSelection(prevSelection)) {
2975
- if (isCopy(keyCode, shiftKey, metaKey, ctrlKey)) {
3009
+ if (isCopy(code, shiftKey, metaKey, ctrlKey)) {
2976
3010
  event.preventDefault();
2977
3011
  dispatchCommand(editor, COPY_COMMAND, event);
2978
- } else if (isCut(keyCode, shiftKey, metaKey, ctrlKey)) {
3012
+ } else if (isCut(code, shiftKey, metaKey, ctrlKey)) {
2979
3013
  event.preventDefault();
2980
3014
  dispatchCommand(editor, CUT_COMMAND, event);
2981
- } else if (isSelectAll(keyCode, metaKey, ctrlKey)) {
3015
+ } else if (isSelectAll(code, metaKey, ctrlKey)) {
2982
3016
  event.preventDefault();
2983
3017
  dispatchCommand(editor, SELECT_ALL_COMMAND, event);
2984
3018
  }
2985
3019
  // FF does it well (no need to override behavior)
2986
- } else if (!IS_FIREFOX && isSelectAll(keyCode, metaKey, ctrlKey)) {
3020
+ } else if (!IS_FIREFOX && isSelectAll(code, metaKey, ctrlKey)) {
2987
3021
  event.preventDefault();
2988
3022
  dispatchCommand(editor, SELECT_ALL_COMMAND, event);
2989
3023
  }
@@ -3033,7 +3067,7 @@ function onDocumentSelectionChange(event) {
3033
3067
  if (nodeType !== DOM_ELEMENT_TYPE && nodeType !== DOM_TEXT_TYPE) {
3034
3068
  return;
3035
3069
  }
3036
- const newSelection = internalCreateRangeSelection(lastSelection, domSelection, nextActiveEditor, event);
3070
+ const newSelection = $internalCreateRangeSelection(lastSelection, domSelection, nextActiveEditor, event);
3037
3071
  $setSelection(newSelection);
3038
3072
  });
3039
3073
  }
@@ -3077,7 +3111,7 @@ function addRootElementEvents(rootElement, editor) {
3077
3111
  if (documentRootElementsCount === undefined || documentRootElementsCount < 1) {
3078
3112
  doc.addEventListener('selectionchange', onDocumentSelectionChange);
3079
3113
  }
3080
- rootElementsRegistered.set(doc, documentRootElementsCount || 0 + 1);
3114
+ rootElementsRegistered.set(doc, (documentRootElementsCount || 0) + 1);
3081
3115
 
3082
3116
  // @ts-expect-error: internal field
3083
3117
  rootElement.__lexicalEditor = editor;
@@ -3135,8 +3169,12 @@ function removeRootElementEvents(rootElement) {
3135
3169
  throw Error(`Root element not registered`);
3136
3170
  } // We only want to have a single global selectionchange event handler, shared
3137
3171
  // between all editor instances.
3138
- rootElementsRegistered.set(doc, documentRootElementsCount - 1);
3139
- if (rootElementsRegistered.get(doc) === 0) {
3172
+ const newCount = documentRootElementsCount - 1;
3173
+ if (!(newCount >= 0)) {
3174
+ throw Error(`Root element count less than 0`);
3175
+ }
3176
+ rootElementsRegistered.set(doc, newCount);
3177
+ if (newCount === 0) {
3140
3178
  doc.removeEventListener('selectionchange', onDocumentSelectionChange);
3141
3179
  }
3142
3180
 
@@ -3183,7 +3221,8 @@ function markCollapsedSelectionFormat(format, style, offset, key, timeStamp) {
3183
3221
  * LICENSE file in the root directory of this source tree.
3184
3222
  *
3185
3223
  */
3186
- function removeNode(nodeToRemove, restoreSelection, preserveEmptyParent) {
3224
+
3225
+ function $removeNode(nodeToRemove, restoreSelection, preserveEmptyParent) {
3187
3226
  errorOnReadOnly();
3188
3227
  const key = nodeToRemove.__key;
3189
3228
  const parent = nodeToRemove.getParent();
@@ -3215,7 +3254,7 @@ function removeNode(nodeToRemove, restoreSelection, preserveEmptyParent) {
3215
3254
  removeFromParent(nodeToRemove);
3216
3255
  }
3217
3256
  if (!preserveEmptyParent && !$isRootOrShadowRoot(parent) && !parent.canBeEmpty() && parent.isEmpty()) {
3218
- removeNode(parent, restoreSelection);
3257
+ $removeNode(parent, restoreSelection);
3219
3258
  }
3220
3259
  if (restoreSelection && $isRootNode(parent) && parent.isEmpty()) {
3221
3260
  parent.selectEnd();
@@ -3880,7 +3919,7 @@ class LexicalNode {
3880
3919
  * other node heuristics such as {@link ElementNode#canBeEmpty}
3881
3920
  * */
3882
3921
  remove(preserveEmptyParent) {
3883
- removeNode(this, true, preserveEmptyParent);
3922
+ $removeNode(this, true, preserveEmptyParent);
3884
3923
  }
3885
3924
 
3886
3925
  /**
@@ -3909,7 +3948,7 @@ class LexicalNode {
3909
3948
  const prevKey = self.__prev;
3910
3949
  const nextKey = self.__next;
3911
3950
  const parentKey = self.__parent;
3912
- removeNode(self, false, true);
3951
+ $removeNode(self, false, true);
3913
3952
  if (prevSibling === null) {
3914
3953
  writableParent.__first = key;
3915
3954
  } else {
@@ -4147,7 +4186,7 @@ function errorOnTypeKlassMismatch(type, klass) {
4147
4186
  * later sibling of FirstNode. If not provided, it will be its last sibling.
4148
4187
  */
4149
4188
  function insertRangeAfter(node, firstToInsert, lastToInsert) {
4150
- const lastToInsert2 = lastToInsert || firstToInsert.getParentOrThrow().getLastChild();
4189
+ const lastToInsert2 = firstToInsert.getParentOrThrow().getLastChild();
4151
4190
  let current = firstToInsert;
4152
4191
  const nodesToInsert = [firstToInsert];
4153
4192
  while (current !== lastToInsert2) {
@@ -4172,6 +4211,7 @@ function insertRangeAfter(node, firstToInsert, lastToInsert) {
4172
4211
  * LICENSE file in the root directory of this source tree.
4173
4212
  *
4174
4213
  */
4214
+
4175
4215
  /** @noInheritDoc */
4176
4216
  class LineBreakNode extends LexicalNode {
4177
4217
  static getType() {
@@ -4199,7 +4239,7 @@ class LineBreakNode extends LexicalNode {
4199
4239
  return null;
4200
4240
  }
4201
4241
  return {
4202
- conversion: convertLineBreakElement,
4242
+ conversion: $convertLineBreakElement,
4203
4243
  priority: 0
4204
4244
  };
4205
4245
  }
@@ -4215,7 +4255,7 @@ class LineBreakNode extends LexicalNode {
4215
4255
  };
4216
4256
  }
4217
4257
  }
4218
- function convertLineBreakElement(node) {
4258
+ function $convertLineBreakElement(node) {
4219
4259
  return {
4220
4260
  node: $createLineBreakNode()
4221
4261
  };
@@ -4250,6 +4290,7 @@ function isWhitespaceDomTextNode(node) {
4250
4290
  * LICENSE file in the root directory of this source tree.
4251
4291
  *
4252
4292
  */
4293
+
4253
4294
  function getElementOuterTag(node, format) {
4254
4295
  if (format & IS_CODE) {
4255
4296
  return 'code';
@@ -4624,7 +4665,7 @@ class TextNode extends LexicalNode {
4624
4665
  static importDOM() {
4625
4666
  return {
4626
4667
  '#text': () => ({
4627
- conversion: convertTextDOMNode,
4668
+ conversion: $convertTextDOMNode,
4628
4669
  priority: 0
4629
4670
  }),
4630
4671
  b: () => ({
@@ -4868,7 +4909,7 @@ class TextNode extends LexicalNode {
4868
4909
  focusOffset = 0;
4869
4910
  }
4870
4911
  if (!$isRangeSelection(selection)) {
4871
- return internalMakeRangeSelection(key, anchorOffset, key, focusOffset, 'text', 'text');
4912
+ return $internalMakeRangeSelection(key, anchorOffset, key, focusOffset, 'text', 'text');
4872
4913
  } else {
4873
4914
  const compositionKey = $getCompositionKey();
4874
4915
  if (compositionKey === selection.anchor.key || compositionKey === selection.focus.key) {
@@ -5105,14 +5146,15 @@ function convertSpanElement(domNode) {
5105
5146
  const span = domNode;
5106
5147
  const style = span.style;
5107
5148
  const fontWeight = style.fontWeight;
5149
+ const textDecoration = style.textDecoration.split(' ');
5108
5150
  // Google Docs uses span tags + font-weight for bold text
5109
5151
  const hasBoldFontWeight = fontWeight === '700' || fontWeight === 'bold';
5110
5152
  // Google Docs uses span tags + text-decoration: line-through for strikethrough text
5111
- const hasLinethroughTextDecoration = style.textDecoration === 'line-through';
5153
+ const hasLinethroughTextDecoration = textDecoration.includes('line-through');
5112
5154
  // Google Docs uses span tags + font-style for italic text
5113
5155
  const hasItalicFontStyle = style.fontStyle === 'italic';
5114
5156
  // Google Docs uses span tags + text-decoration: underline for underline text
5115
- const hasUnderlineTextDecoration = style.textDecoration === 'underline';
5157
+ const hasUnderlineTextDecoration = textDecoration.includes('underline');
5116
5158
  // Google Docs uses span tags + vertical-align to specify subscript and superscript
5117
5159
  const verticalAlign = style.verticalAlign;
5118
5160
  return {
@@ -5176,7 +5218,7 @@ function findParentPreDOMNode(node) {
5176
5218
  }
5177
5219
  return resultNode;
5178
5220
  }
5179
- function convertTextDOMNode(domNode) {
5221
+ function $convertTextDOMNode(domNode) {
5180
5222
  const domNode_ = domNode;
5181
5223
  const parentDom = domNode.parentElement;
5182
5224
  if (!(parentDom !== null)) {
@@ -5252,7 +5294,6 @@ function convertTextDOMNode(domNode) {
5252
5294
  node: $createTextNode(textContent)
5253
5295
  };
5254
5296
  }
5255
- const inlineParents = new RegExp(/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/, 'i');
5256
5297
  function findTextInLine(text, forward) {
5257
5298
  let node = text;
5258
5299
  // eslint-disable-next-line no-constant-condition
@@ -5268,7 +5309,7 @@ function findTextInLine(text, forward) {
5268
5309
  node = sibling;
5269
5310
  if (node.nodeType === DOM_ELEMENT_TYPE) {
5270
5311
  const display = node.style.display;
5271
- if (display === '' && node.nodeName.match(inlineParents) === null || display !== '' && !display.startsWith('inline')) {
5312
+ if (display === '' && !isInlineDomNode(node) || display !== '' && !display.startsWith('inline')) {
5272
5313
  return null;
5273
5314
  }
5274
5315
  }
@@ -5324,6 +5365,7 @@ function $isTextNode(node) {
5324
5365
  * LICENSE file in the root directory of this source tree.
5325
5366
  *
5326
5367
  */
5368
+
5327
5369
  /** @noInheritDoc */
5328
5370
  class TabNode extends TextNode {
5329
5371
  static getType() {
@@ -5393,6 +5435,7 @@ function $isTabNode(node) {
5393
5435
  * LICENSE file in the root directory of this source tree.
5394
5436
  *
5395
5437
  */
5438
+
5396
5439
  class Point {
5397
5440
  constructor(key, offset, type) {
5398
5441
  this._selection = null;
@@ -5788,7 +5831,7 @@ class RangeSelection {
5788
5831
  const editor = getActiveEditor();
5789
5832
  const currentEditorState = editor.getEditorState();
5790
5833
  const lastSelection = currentEditorState._selection;
5791
- const resolvedSelectionPoints = internalResolveSelectionPoints(range.startContainer, range.startOffset, range.endContainer, range.endOffset, editor, lastSelection);
5834
+ const resolvedSelectionPoints = $internalResolveSelectionPoints(range.startContainer, range.startOffset, range.endContainer, range.endOffset, editor, lastSelection);
5792
5835
  if (resolvedSelectionPoints === null) {
5793
5836
  return;
5794
5837
  }
@@ -5874,20 +5917,21 @@ class RangeSelection {
5874
5917
  insertText(text) {
5875
5918
  const anchor = this.anchor;
5876
5919
  const focus = this.focus;
5877
- const isBefore = this.isCollapsed() || anchor.isBefore(focus);
5878
5920
  const format = this.format;
5879
5921
  const style = this.style;
5880
- if (isBefore && anchor.type === 'element') {
5881
- $transferStartingElementPointToTextPoint(anchor, focus, format, style);
5882
- } else if (!isBefore && focus.type === 'element') {
5883
- $transferStartingElementPointToTextPoint(focus, anchor, format, style);
5922
+ let firstPoint = anchor;
5923
+ let endPoint = focus;
5924
+ if (!this.isCollapsed() && focus.isBefore(anchor)) {
5925
+ firstPoint = focus;
5926
+ endPoint = anchor;
5927
+ }
5928
+ if (firstPoint.type === 'element') {
5929
+ $transferStartingElementPointToTextPoint(firstPoint, endPoint, format, style);
5884
5930
  }
5931
+ const startOffset = firstPoint.offset;
5932
+ let endOffset = endPoint.offset;
5885
5933
  const selectedNodes = this.getNodes();
5886
5934
  const selectedNodesLength = selectedNodes.length;
5887
- const firstPoint = isBefore ? anchor : focus;
5888
- const endPoint = isBefore ? focus : anchor;
5889
- const startOffset = firstPoint.offset;
5890
- const endOffset = endPoint.offset;
5891
5935
  let firstNode = selectedNodes[0];
5892
5936
  if (!$isTextNode(firstNode)) {
5893
5937
  {
@@ -5899,6 +5943,10 @@ class RangeSelection {
5899
5943
  const firstNodeParent = firstNode.getParentOrThrow();
5900
5944
  const lastIndex = selectedNodesLength - 1;
5901
5945
  let lastNode = selectedNodes[lastIndex];
5946
+ if (selectedNodesLength === 1 && endPoint.type === 'element') {
5947
+ endOffset = firstNodeTextLength;
5948
+ endPoint.set(firstPoint.key, endOffset, 'text');
5949
+ }
5902
5950
  if (this.isCollapsed() && startOffset === firstNodeTextLength && (firstNode.isSegmented() || firstNode.isToken() || !firstNode.canInsertTextAfter() || !firstNodeParent.canInsertTextAfter() && firstNode.getNextSibling() === null)) {
5903
5951
  let nextSibling = firstNode.getNextSibling();
5904
5952
  if (!$isTextNode(nextSibling) || !nextSibling.canInsertTextBefore() || $isTokenOrSegmented(nextSibling)) {
@@ -5946,7 +5994,7 @@ class RangeSelection {
5946
5994
  const lastNodeParent = lastNode.getParent();
5947
5995
  if (!firstNodeParent.canInsertTextBefore() || !firstNodeParent.canInsertTextAfter() || $isElementNode(lastNodeParent) && (!lastNodeParent.canInsertTextBefore() || !lastNodeParent.canInsertTextAfter())) {
5948
5996
  this.insertText('');
5949
- normalizeSelectionPointsForBoundaries(this.anchor, this.focus, null);
5997
+ $normalizeSelectionPointsForBoundaries(this.anchor, this.focus, null);
5950
5998
  this.insertText(text);
5951
5999
  return;
5952
6000
  }
@@ -6276,7 +6324,7 @@ class RangeSelection {
6276
6324
  if ('__language' in nodes[0]) {
6277
6325
  this.insertText(nodes[0].getTextContent());
6278
6326
  } else {
6279
- const index = removeTextAndSplitBlock(this);
6327
+ const index = $removeTextAndSplitBlock(this);
6280
6328
  firstBlock.splice(index, 0, nodes);
6281
6329
  last.selectEnd();
6282
6330
  }
@@ -6289,7 +6337,7 @@ class RangeSelection {
6289
6337
  if (!$isElementNode(firstBlock)) {
6290
6338
  throw Error(`Expected 'firstBlock' to be an ElementNode`);
6291
6339
  }
6292
- const index = removeTextAndSplitBlock(this);
6340
+ const index = $removeTextAndSplitBlock(this);
6293
6341
  firstBlock.splice(index, 0, nodes);
6294
6342
  last.selectEnd();
6295
6343
  return;
@@ -6344,7 +6392,7 @@ class RangeSelection {
6344
6392
  paragraph.select();
6345
6393
  return paragraph;
6346
6394
  }
6347
- const index = removeTextAndSplitBlock(this);
6395
+ const index = $removeTextAndSplitBlock(this);
6348
6396
  const block = $getAncestor(this.anchor.getNode(), INTERNAL_$isBlock);
6349
6397
  if (!$isElementNode(block)) {
6350
6398
  throw Error(`Expected ancestor to be an ElementNode`);
@@ -6794,7 +6842,7 @@ function shouldResolveAncestor(resolvedElement, resolvedOffset, lastPoint) {
6794
6842
  const parent = resolvedElement.getParent();
6795
6843
  return lastPoint === null || parent === null || !parent.canBeEmpty() || parent !== lastPoint.getNode();
6796
6844
  }
6797
- function internalResolveSelectionPoint(dom, offset, lastPoint, editor) {
6845
+ function $internalResolveSelectionPoint(dom, offset, lastPoint, editor) {
6798
6846
  let resolvedOffset = offset;
6799
6847
  let resolvedNode;
6800
6848
  // If we have selection on an element, we will
@@ -6809,6 +6857,7 @@ function internalResolveSelectionPoint(dom, offset, lastPoint, editor) {
6809
6857
  // We use the anchor to find which child node to select
6810
6858
  const childNodes = dom.childNodes;
6811
6859
  const childNodesLength = childNodes.length;
6860
+ const blockCursorElement = editor._blockCursorElement;
6812
6861
  // If the anchor is the same as length, then this means we
6813
6862
  // need to select the very last text node.
6814
6863
  if (resolvedOffset === childNodesLength) {
@@ -6817,17 +6866,23 @@ function internalResolveSelectionPoint(dom, offset, lastPoint, editor) {
6817
6866
  }
6818
6867
  let childDOM = childNodes[resolvedOffset];
6819
6868
  let hasBlockCursor = false;
6820
- if (childDOM === editor._blockCursorElement) {
6869
+ if (childDOM === blockCursorElement) {
6821
6870
  childDOM = childNodes[resolvedOffset + 1];
6822
6871
  hasBlockCursor = true;
6823
- } else if (editor._blockCursorElement !== null) {
6824
- resolvedOffset--;
6872
+ } else if (blockCursorElement !== null) {
6873
+ const blockCursorElementParent = blockCursorElement.parentNode;
6874
+ if (dom === blockCursorElementParent) {
6875
+ const blockCursorOffset = Array.prototype.indexOf.call(blockCursorElementParent.children, blockCursorElement);
6876
+ if (offset > blockCursorOffset) {
6877
+ resolvedOffset--;
6878
+ }
6879
+ }
6825
6880
  }
6826
- resolvedNode = getNodeFromDOM(childDOM);
6881
+ resolvedNode = $getNodeFromDOM(childDOM);
6827
6882
  if ($isTextNode(resolvedNode)) {
6828
6883
  resolvedOffset = getTextNodeOffset(resolvedNode, moveSelectionToEnd);
6829
6884
  } else {
6830
- let resolvedElement = getNodeFromDOM(dom);
6885
+ let resolvedElement = $getNodeFromDOM(dom);
6831
6886
  // Ensure resolvedElement is actually a element.
6832
6887
  if (resolvedElement === null) {
6833
6888
  return null;
@@ -6839,11 +6894,11 @@ function internalResolveSelectionPoint(dom, offset, lastPoint, editor) {
6839
6894
  const descendant = moveSelectionToEnd ? child.getLastDescendant() : child.getFirstDescendant();
6840
6895
  if (descendant === null) {
6841
6896
  resolvedElement = child;
6842
- resolvedOffset = 0;
6843
6897
  } else {
6844
6898
  child = descendant;
6845
6899
  resolvedElement = $isElementNode(child) ? child : child.getParentOrThrow();
6846
6900
  }
6901
+ resolvedOffset = 0;
6847
6902
  }
6848
6903
  if ($isTextNode(child)) {
6849
6904
  resolvedNode = child;
@@ -6856,7 +6911,7 @@ function internalResolveSelectionPoint(dom, offset, lastPoint, editor) {
6856
6911
  const index = resolvedElement.getIndexWithinParent();
6857
6912
  // When selecting decorators, there can be some selection issues when using resolvedOffset,
6858
6913
  // and instead we should be checking if we're using the offset
6859
- if (offset === 0 && $isDecoratorNode(resolvedElement) && getNodeFromDOM(dom) === resolvedElement) {
6914
+ if (offset === 0 && $isDecoratorNode(resolvedElement) && $getNodeFromDOM(dom) === resolvedElement) {
6860
6915
  resolvedOffset = index;
6861
6916
  } else {
6862
6917
  resolvedOffset = index + 1;
@@ -6869,7 +6924,7 @@ function internalResolveSelectionPoint(dom, offset, lastPoint, editor) {
6869
6924
  }
6870
6925
  } else {
6871
6926
  // TextNode or null
6872
- resolvedNode = getNodeFromDOM(dom);
6927
+ resolvedNode = $getNodeFromDOM(dom);
6873
6928
  }
6874
6929
  if (!$isTextNode(resolvedNode)) {
6875
6930
  return null;
@@ -6916,7 +6971,7 @@ function resolveSelectionPointOnBoundary(point, isBackward, isCollapsed) {
6916
6971
  }
6917
6972
  }
6918
6973
  }
6919
- function normalizeSelectionPointsForBoundaries(anchor, focus, lastSelection) {
6974
+ function $normalizeSelectionPointsForBoundaries(anchor, focus, lastSelection) {
6920
6975
  if (anchor.type === 'text' && focus.type === 'text') {
6921
6976
  const isBackward = anchor.isBefore(focus);
6922
6977
  const isCollapsed = anchor.is(focus);
@@ -6939,21 +6994,21 @@ function normalizeSelectionPointsForBoundaries(anchor, focus, lastSelection) {
6939
6994
  }
6940
6995
  }
6941
6996
  }
6942
- function internalResolveSelectionPoints(anchorDOM, anchorOffset, focusDOM, focusOffset, editor, lastSelection) {
6997
+ function $internalResolveSelectionPoints(anchorDOM, anchorOffset, focusDOM, focusOffset, editor, lastSelection) {
6943
6998
  if (anchorDOM === null || focusDOM === null || !isSelectionWithinEditor(editor, anchorDOM, focusDOM)) {
6944
6999
  return null;
6945
7000
  }
6946
- const resolvedAnchorPoint = internalResolveSelectionPoint(anchorDOM, anchorOffset, $isRangeSelection(lastSelection) ? lastSelection.anchor : null, editor);
7001
+ const resolvedAnchorPoint = $internalResolveSelectionPoint(anchorDOM, anchorOffset, $isRangeSelection(lastSelection) ? lastSelection.anchor : null, editor);
6947
7002
  if (resolvedAnchorPoint === null) {
6948
7003
  return null;
6949
7004
  }
6950
- const resolvedFocusPoint = internalResolveSelectionPoint(focusDOM, focusOffset, $isRangeSelection(lastSelection) ? lastSelection.focus : null, editor);
7005
+ const resolvedFocusPoint = $internalResolveSelectionPoint(focusDOM, focusOffset, $isRangeSelection(lastSelection) ? lastSelection.focus : null, editor);
6951
7006
  if (resolvedFocusPoint === null) {
6952
7007
  return null;
6953
7008
  }
6954
7009
  if (resolvedAnchorPoint.type === 'element' && resolvedFocusPoint.type === 'element') {
6955
- const anchorNode = getNodeFromDOM(anchorDOM);
6956
- const focusNode = getNodeFromDOM(focusDOM);
7010
+ const anchorNode = $getNodeFromDOM(anchorDOM);
7011
+ const focusNode = $getNodeFromDOM(focusDOM);
6957
7012
  // Ensure if we're selecting the content of a decorator that we
6958
7013
  // return null for this point, as it's not in the controlled scope
6959
7014
  // of Lexical.
@@ -6963,7 +7018,7 @@ function internalResolveSelectionPoints(anchorDOM, anchorOffset, focusDOM, focus
6963
7018
  }
6964
7019
 
6965
7020
  // Handle normalization of selection when it is at the boundaries.
6966
- normalizeSelectionPointsForBoundaries(resolvedAnchorPoint, resolvedFocusPoint, lastSelection);
7021
+ $normalizeSelectionPointsForBoundaries(resolvedAnchorPoint, resolvedFocusPoint, lastSelection);
6967
7022
  return [resolvedAnchorPoint, resolvedFocusPoint];
6968
7023
  }
6969
7024
  function $isBlockElementNode(node) {
@@ -6974,7 +7029,7 @@ function $isBlockElementNode(node) {
6974
7029
  // selection is null, i.e. forcing selection on the editor
6975
7030
  // when it current exists outside the editor.
6976
7031
 
6977
- function internalMakeRangeSelection(anchorKey, anchorOffset, focusKey, focusOffset, anchorType, focusType) {
7032
+ function $internalMakeRangeSelection(anchorKey, anchorOffset, focusKey, focusOffset, anchorType, focusType) {
6978
7033
  const editorState = getActiveEditorState();
6979
7034
  const selection = new RangeSelection($createPoint(anchorKey, anchorOffset, anchorType), $createPoint(focusKey, focusOffset, focusType), 0, '');
6980
7035
  selection.dirty = true;
@@ -6989,19 +7044,19 @@ function $createRangeSelection() {
6989
7044
  function $createNodeSelection() {
6990
7045
  return new NodeSelection(new Set());
6991
7046
  }
6992
- function internalCreateSelection(editor) {
7047
+ function $internalCreateSelection(editor) {
6993
7048
  const currentEditorState = editor.getEditorState();
6994
7049
  const lastSelection = currentEditorState._selection;
6995
7050
  const domSelection = getDOMSelection(editor._window);
6996
7051
  if ($isRangeSelection(lastSelection) || lastSelection == null) {
6997
- return internalCreateRangeSelection(lastSelection, domSelection, editor, null);
7052
+ return $internalCreateRangeSelection(lastSelection, domSelection, editor, null);
6998
7053
  }
6999
7054
  return lastSelection.clone();
7000
7055
  }
7001
7056
  function $createRangeSelectionFromDom(domSelection, editor) {
7002
- return internalCreateRangeSelection(null, domSelection, editor, null);
7057
+ return $internalCreateRangeSelection(null, domSelection, editor, null);
7003
7058
  }
7004
- function internalCreateRangeSelection(lastSelection, domSelection, editor, event) {
7059
+ function $internalCreateRangeSelection(lastSelection, domSelection, editor, event) {
7005
7060
  const windowObj = editor._window;
7006
7061
  if (windowObj === null) {
7007
7062
  return null;
@@ -7041,7 +7096,7 @@ function internalCreateRangeSelection(lastSelection, domSelection, editor, event
7041
7096
  }
7042
7097
  // Let's resolve the text nodes from the offsets and DOM nodes we have from
7043
7098
  // native selection.
7044
- const resolvedSelectionPoints = internalResolveSelectionPoints(anchorDOM, anchorOffset, focusDOM, focusOffset, editor, lastSelection);
7099
+ const resolvedSelectionPoints = $internalResolveSelectionPoints(anchorDOM, anchorOffset, focusDOM, focusOffset, editor, lastSelection);
7045
7100
  if (resolvedSelectionPoints === null) {
7046
7101
  return null;
7047
7102
  }
@@ -7293,6 +7348,9 @@ function updateDOMSelection(prevSelection, nextSelection, editor, domSelection,
7293
7348
  // If we encounter an error, continue. This can sometimes
7294
7349
  // occur with FF and there's no good reason as to why it
7295
7350
  // should happen.
7351
+ {
7352
+ console.warn(error);
7353
+ }
7296
7354
  }
7297
7355
  if (!tags.has('skip-scroll-into-view') && nextSelection.isCollapsed() && rootElement !== null && rootElement === document.activeElement) {
7298
7356
  const selectionTarget = nextSelection instanceof RangeSelection && nextSelection.anchor.type === 'element' ? nextAnchorNode.childNodes[nextAnchorOffset] || null : domSelection.rangeCount > 0 ? domSelection.getRangeAt(0) : null;
@@ -7324,19 +7382,29 @@ function $getTextContent() {
7324
7382
  }
7325
7383
  return selection.getTextContent();
7326
7384
  }
7327
- function removeTextAndSplitBlock(selection) {
7385
+ function $removeTextAndSplitBlock(selection) {
7386
+ let selection_ = selection;
7328
7387
  if (!selection.isCollapsed()) {
7329
- selection.removeText();
7388
+ selection_.removeText();
7330
7389
  }
7331
- const anchor = selection.anchor;
7390
+ // A new selection can originate as a result of node replacement, in which case is registered via
7391
+ // $setSelection
7392
+ const newSelection = $getSelection();
7393
+ if ($isRangeSelection(newSelection)) {
7394
+ selection_ = newSelection;
7395
+ }
7396
+ if (!$isRangeSelection(selection_)) {
7397
+ throw Error(`Unexpected dirty selection to be null`);
7398
+ }
7399
+ const anchor = selection_.anchor;
7332
7400
  let node = anchor.getNode();
7333
7401
  let offset = anchor.offset;
7334
7402
  while (!INTERNAL_$isBlock(node)) {
7335
- [node, offset] = splitNodeAtPoint(node, offset);
7403
+ [node, offset] = $splitNodeAtPoint(node, offset);
7336
7404
  }
7337
7405
  return offset;
7338
7406
  }
7339
- function splitNodeAtPoint(node, offset) {
7407
+ function $splitNodeAtPoint(node, offset) {
7340
7408
  const parent = node.getParent();
7341
7409
  if (!parent) {
7342
7410
  const paragraph = $createParagraphNode();
@@ -7402,6 +7470,7 @@ function $wrapInlineNodes(nodes) {
7402
7470
  * LICENSE file in the root directory of this source tree.
7403
7471
  *
7404
7472
  */
7473
+
7405
7474
  let activeEditorState = null;
7406
7475
  let activeEditor = null;
7407
7476
  let isReadOnlyMode = false;
@@ -7657,7 +7726,7 @@ function handleDEVOnlyPendingUpdateGuarantees(pendingEditorState) {
7657
7726
  throw new Error('Cannot call delete() on a frozen Lexical node map');
7658
7727
  };
7659
7728
  }
7660
- function commitPendingUpdates(editor, recoveryEditorState) {
7729
+ function $commitPendingUpdates(editor, recoveryEditorState) {
7661
7730
  const pendingEditorState = editor._pendingEditorState;
7662
7731
  const rootElement = editor._rootElement;
7663
7732
  const shouldSkipDOM = editor._headless || rootElement === null;
@@ -7692,7 +7761,7 @@ function commitPendingUpdates(editor, recoveryEditorState) {
7692
7761
  const dirtyElements = editor._dirtyElements;
7693
7762
  const dirtyLeaves = editor._dirtyLeaves;
7694
7763
  observer.disconnect();
7695
- mutatedNodes = reconcileRoot(currentEditorState, pendingEditorState, editor, dirtyType, dirtyElements, dirtyLeaves);
7764
+ mutatedNodes = $reconcileRoot(currentEditorState, pendingEditorState, editor, dirtyType, dirtyElements, dirtyLeaves);
7696
7765
  } catch (error) {
7697
7766
  // Report errors
7698
7767
  if (error instanceof Error) {
@@ -7705,7 +7774,7 @@ function commitPendingUpdates(editor, recoveryEditorState) {
7705
7774
  initMutationObserver(editor);
7706
7775
  editor._dirtyType = FULL_RECONCILE;
7707
7776
  isAttemptingToRecoverFromReconcilerError = true;
7708
- commitPendingUpdates(editor, currentEditorState);
7777
+ $commitPendingUpdates(editor, currentEditorState);
7709
7778
  isAttemptingToRecoverFromReconcilerError = false;
7710
7779
  } else {
7711
7780
  // To avoid a possible situation of infinite loops, lets throw
@@ -7810,7 +7879,7 @@ function commitPendingUpdates(editor, recoveryEditorState) {
7810
7879
  tags
7811
7880
  });
7812
7881
  triggerDeferredUpdateCallbacks(editor, deferred);
7813
- triggerEnqueuedUpdates(editor);
7882
+ $triggerEnqueuedUpdates(editor);
7814
7883
  }
7815
7884
  function triggerTextContentListeners(editor, currentEditorState, pendingEditorState) {
7816
7885
  const currentTextContent = getEditorStateTextContent(currentEditorState);
@@ -7877,13 +7946,13 @@ function triggerCommandListeners(editor, type, payload) {
7877
7946
  }
7878
7947
  return false;
7879
7948
  }
7880
- function triggerEnqueuedUpdates(editor) {
7949
+ function $triggerEnqueuedUpdates(editor) {
7881
7950
  const queuedUpdates = editor._updates;
7882
7951
  if (queuedUpdates.length !== 0) {
7883
7952
  const queuedUpdate = queuedUpdates.shift();
7884
7953
  if (queuedUpdate) {
7885
7954
  const [updateFn, options] = queuedUpdate;
7886
- beginUpdate(editor, updateFn, options);
7955
+ $beginUpdate(editor, updateFn, options);
7887
7956
  }
7888
7957
  }
7889
7958
  }
@@ -7932,7 +8001,7 @@ function processNestedUpdates(editor, initialSkipTransforms) {
7932
8001
  }
7933
8002
  return skipTransforms;
7934
8003
  }
7935
- function beginUpdate(editor, updateFn, options) {
8004
+ function $beginUpdate(editor, updateFn, options) {
7936
8005
  const updateTags = editor._updateTags;
7937
8006
  let onUpdate;
7938
8007
  let tag;
@@ -7973,7 +8042,7 @@ function beginUpdate(editor, updateFn, options) {
7973
8042
  pendingEditorState._selection = currentEditorState._selection.clone();
7974
8043
  }
7975
8044
  } else {
7976
- pendingEditorState._selection = internalCreateSelection(editor);
8045
+ pendingEditorState._selection = $internalCreateSelection(editor);
7977
8046
  }
7978
8047
  }
7979
8048
  const startingCompositionKey = editor._compositionKey;
@@ -8021,7 +8090,7 @@ function beginUpdate(editor, updateFn, options) {
8021
8090
  editor._cloneNotNeeded.clear();
8022
8091
  editor._dirtyLeaves = new Set();
8023
8092
  editor._dirtyElements.clear();
8024
- commitPendingUpdates(editor);
8093
+ $commitPendingUpdates(editor);
8025
8094
  return;
8026
8095
  } finally {
8027
8096
  activeEditorState = previousActiveEditorState;
@@ -8034,10 +8103,10 @@ function beginUpdate(editor, updateFn, options) {
8034
8103
  if (shouldUpdate) {
8035
8104
  if (pendingEditorState._flushSync) {
8036
8105
  pendingEditorState._flushSync = false;
8037
- commitPendingUpdates(editor);
8106
+ $commitPendingUpdates(editor);
8038
8107
  } else if (editorStateWasCloned) {
8039
8108
  scheduleMicroTask(() => {
8040
- commitPendingUpdates(editor);
8109
+ $commitPendingUpdates(editor);
8041
8110
  });
8042
8111
  }
8043
8112
  } else {
@@ -8053,7 +8122,7 @@ function updateEditor(editor, updateFn, options) {
8053
8122
  if (editor._updating) {
8054
8123
  editor._updates.push([updateFn, options]);
8055
8124
  } else {
8056
- beginUpdate(editor, updateFn, options);
8125
+ $beginUpdate(editor, updateFn, options);
8057
8126
  }
8058
8127
  }
8059
8128
 
@@ -8065,6 +8134,7 @@ function updateEditor(editor, updateFn, options) {
8065
8134
  *
8066
8135
  */
8067
8136
 
8137
+
8068
8138
  /** @noInheritDoc */
8069
8139
  class DecoratorNode extends LexicalNode {
8070
8140
  constructor(key) {
@@ -8100,6 +8170,7 @@ function $isDecoratorNode(node) {
8100
8170
  * LICENSE file in the root directory of this source tree.
8101
8171
  *
8102
8172
  */
8173
+
8103
8174
  /** @noInheritDoc */
8104
8175
  class ElementNode extends LexicalNode {
8105
8176
  /** @internal */
@@ -8341,7 +8412,7 @@ class ElementNode extends LexicalNode {
8341
8412
  }
8342
8413
  const key = this.__key;
8343
8414
  if (!$isRangeSelection(selection)) {
8344
- return internalMakeRangeSelection(key, anchorOffset, key, focusOffset, 'element', 'element');
8415
+ return $internalMakeRangeSelection(key, anchorOffset, key, focusOffset, 'element', 'element');
8345
8416
  } else {
8346
8417
  selection.anchor.set(key, anchorOffset, 'element');
8347
8418
  selection.focus.set(key, focusOffset, 'element');
@@ -8575,6 +8646,7 @@ function isPointRemoved(point, nodesToRemoveKeySet, nodesToInsertKeySet) {
8575
8646
  * LICENSE file in the root directory of this source tree.
8576
8647
  *
8577
8648
  */
8649
+
8578
8650
  /** @noInheritDoc */
8579
8651
  class RootNode extends ElementNode {
8580
8652
  /** @internal */
@@ -8679,6 +8751,7 @@ function $isRootNode(node) {
8679
8751
  * LICENSE file in the root directory of this source tree.
8680
8752
  *
8681
8753
  */
8754
+
8682
8755
  function editorStateHasDirtySelection(editorState, editor) {
8683
8756
  const currentSelection = editor.getEditorState()._selection;
8684
8757
  const pendingSelection = editorState._selection;
@@ -8757,6 +8830,28 @@ class EditorState {
8757
8830
  * LICENSE file in the root directory of this source tree.
8758
8831
  *
8759
8832
  */
8833
+
8834
+
8835
+ // TODO: Cleanup ArtificialNode__DO_NOT_USE #5966
8836
+ class ArtificialNode__DO_NOT_USE extends ElementNode {
8837
+ static getType() {
8838
+ return 'artificial';
8839
+ }
8840
+ createDOM(config) {
8841
+ // this isnt supposed to be used and is not used anywhere but defining it to appease the API
8842
+ const dom = document.createElement('div');
8843
+ return dom;
8844
+ }
8845
+ }
8846
+
8847
+ /**
8848
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
8849
+ *
8850
+ * This source code is licensed under the MIT license found in the
8851
+ * LICENSE file in the root directory of this source tree.
8852
+ *
8853
+ */
8854
+
8760
8855
  /** @noInheritDoc */
8761
8856
  class ParagraphNode extends ElementNode {
8762
8857
  /** @internal */
@@ -8802,7 +8897,7 @@ class ParagraphNode extends ElementNode {
8802
8897
  static importDOM() {
8803
8898
  return {
8804
8899
  p: node => ({
8805
- conversion: convertParagraphElement,
8900
+ conversion: $convertParagraphElement,
8806
8901
  priority: 0
8807
8902
  })
8808
8903
  };
@@ -8881,7 +8976,7 @@ class ParagraphNode extends ElementNode {
8881
8976
  return false;
8882
8977
  }
8883
8978
  }
8884
- function convertParagraphElement(element) {
8979
+ function $convertParagraphElement(element) {
8885
8980
  const node = $createParagraphNode();
8886
8981
  if (element.style) {
8887
8982
  node.setFormat(element.style.textAlign);
@@ -8909,6 +9004,7 @@ function $isParagraphNode(node) {
8909
9004
  *
8910
9005
  */
8911
9006
 
9007
+
8912
9008
  // https://github.com/microsoft/TypeScript/issues/3841
8913
9009
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8914
9010
 
@@ -9018,7 +9114,7 @@ function createEditor(editorConfig) {
9018
9114
  const editorState = createEmptyEditorState();
9019
9115
  const namespace = config.namespace || (parentEditor !== null ? parentEditor._config.namespace : createUID());
9020
9116
  const initialEditorState = config.editorState;
9021
- const nodes = [RootNode, TextNode, LineBreakNode, TabNode, ParagraphNode, ...(config.nodes || [])];
9117
+ const nodes = [RootNode, TextNode, LineBreakNode, TabNode, ParagraphNode, ArtificialNode__DO_NOT_USE, ...(config.nodes || [])];
9022
9118
  const {
9023
9119
  onError,
9024
9120
  html
@@ -9490,7 +9586,7 @@ class LexicalEditor {
9490
9586
  this._dirtyType = FULL_RECONCILE;
9491
9587
  initMutationObserver(this);
9492
9588
  this._updateTags.add('history-merge');
9493
- commitPendingUpdates(this);
9589
+ $commitPendingUpdates(this);
9494
9590
 
9495
9591
  // TODO: remove this flag once we no longer use UEv2 internally
9496
9592
  if (!this._config.disableEvents) {
@@ -9538,7 +9634,7 @@ class LexicalEditor {
9538
9634
  throw Error(`setEditorState: the editor state is empty. Ensure the editor state's root node never becomes empty.`);
9539
9635
  }
9540
9636
  }
9541
- flushRootMutations(this);
9637
+ $flushRootMutations(this);
9542
9638
  const pendingEditorState = this._pendingEditorState;
9543
9639
  const tags = this._updateTags;
9544
9640
  const tag = options !== undefined ? options.tag : null;
@@ -9546,7 +9642,7 @@ class LexicalEditor {
9546
9642
  if (tag != null) {
9547
9643
  tags.add(tag);
9548
9644
  }
9549
- commitPendingUpdates(this);
9645
+ $commitPendingUpdates(this);
9550
9646
  }
9551
9647
  this._pendingEditorState = editorState;
9552
9648
  this._dirtyType = FULL_RECONCILE;
@@ -9555,7 +9651,7 @@ class LexicalEditor {
9555
9651
  if (tag != null) {
9556
9652
  tags.add(tag);
9557
9653
  }
9558
- commitPendingUpdates(this);
9654
+ $commitPendingUpdates(this);
9559
9655
  }
9560
9656
 
9561
9657
  /**
@@ -9722,6 +9818,7 @@ exports.$selectAll = $selectAll;
9722
9818
  exports.$setCompositionKey = $setCompositionKey;
9723
9819
  exports.$setSelection = $setSelection;
9724
9820
  exports.$splitNode = $splitNode;
9821
+ exports.ArtificialNode__DO_NOT_USE = ArtificialNode__DO_NOT_USE;
9725
9822
  exports.BLUR_COMMAND = BLUR_COMMAND;
9726
9823
  exports.CAN_REDO_COMMAND = CAN_REDO_COMMAND;
9727
9824
  exports.CAN_UNDO_COMMAND = CAN_UNDO_COMMAND;
@@ -9782,8 +9879,10 @@ exports.UNDO_COMMAND = UNDO_COMMAND;
9782
9879
  exports.createCommand = createCommand;
9783
9880
  exports.createEditor = createEditor;
9784
9881
  exports.getNearestEditorFromDOMNode = getNearestEditorFromDOMNode;
9882
+ exports.isBlockDomNode = isBlockDomNode;
9785
9883
  exports.isCurrentlyReadOnlyMode = isCurrentlyReadOnlyMode;
9786
9884
  exports.isHTMLAnchorElement = isHTMLAnchorElement;
9787
9885
  exports.isHTMLElement = isHTMLElement;
9886
+ exports.isInlineDomNode = isInlineDomNode;
9788
9887
  exports.isSelectionCapturedInDecoratorInput = isSelectionCapturedInDecoratorInput;
9789
9888
  exports.isSelectionWithinEditor = isSelectionWithinEditor;