lexical 0.14.2 → 0.14.4

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
@@ -999,9 +999,9 @@ function $shouldInsertTextAfterOrBeforeTextNode(selection, node) {
999
999
  const parent = node.getParentOrThrow();
1000
1000
  const isToken = node.isToken();
1001
1001
  if (offset === 0) {
1002
- return !node.canInsertTextBefore() || !parent.canInsertTextBefore() || isToken || $previousSiblingDoesNotAcceptText(node);
1002
+ return !node.canInsertTextBefore() || !parent.canInsertTextBefore() && !node.isComposing() || isToken || $previousSiblingDoesNotAcceptText(node);
1003
1003
  } else if (offset === node.getTextContentSize()) {
1004
- return !node.canInsertTextAfter() || !parent.canInsertTextAfter() || isToken;
1004
+ return !node.canInsertTextAfter() || !parent.canInsertTextAfter() && !node.isComposing() || isToken;
1005
1005
  } else {
1006
1006
  return false;
1007
1007
  }
@@ -1666,6 +1666,7 @@ function $garbageCollectDetachedNodes(prevEditorState, editorState, dirtyLeaves,
1666
1666
  */
1667
1667
  let subTreeTextContent = '';
1668
1668
  let subTreeDirectionedTextContent = '';
1669
+ let subTreeTextFormat = null;
1669
1670
  let editorTextContent = '';
1670
1671
  let activeEditorConfig;
1671
1672
  let activeEditor$1;
@@ -1836,6 +1837,10 @@ function createChildren(children, element, _startIndex, endIndex, dom, insertDOM
1836
1837
  let startIndex = _startIndex;
1837
1838
  for (; startIndex <= endIndex; ++startIndex) {
1838
1839
  createNode(children[startIndex], dom, insertDOM);
1840
+ const node = activeNextNodeMap.get(children[startIndex]);
1841
+ if (node !== null && subTreeTextFormat === null && $isTextNode(node)) {
1842
+ subTreeTextFormat = node.getFormat();
1843
+ }
1839
1844
  }
1840
1845
  if ($textContentRequiresDoubleLinebreakAtEnd(element)) {
1841
1846
  subTreeTextContent += DOUBLE_LINE_BREAK;
@@ -1871,6 +1876,11 @@ function reconcileElementTerminatingLineBreak(prevElement, nextElement, dom) {
1871
1876
  dom.appendChild(element);
1872
1877
  }
1873
1878
  }
1879
+ function reconcileParagraphFormat(element) {
1880
+ if ($isParagraphNode(element) && subTreeTextFormat != null && subTreeTextFormat !== element.__textFormat) {
1881
+ element.setTextFormat(subTreeTextFormat);
1882
+ }
1883
+ }
1874
1884
  function reconcileBlockDirection(element, dom) {
1875
1885
  const previousSubTreeDirectionTextContent =
1876
1886
  // @ts-expect-error: internal field
@@ -1930,9 +1940,12 @@ function reconcileBlockDirection(element, dom) {
1930
1940
  function reconcileChildrenWithDirection(prevElement, nextElement, dom) {
1931
1941
  const previousSubTreeDirectionTextContent = subTreeDirectionedTextContent;
1932
1942
  subTreeDirectionedTextContent = '';
1943
+ subTreeTextFormat = null;
1933
1944
  reconcileChildren(prevElement, nextElement, dom);
1934
1945
  reconcileBlockDirection(nextElement, dom);
1946
+ reconcileParagraphFormat(nextElement);
1935
1947
  subTreeDirectionedTextContent = previousSubTreeDirectionTextContent;
1948
+ subTreeTextFormat = null;
1936
1949
  }
1937
1950
  function createChildrenArray(element, nodeMap) {
1938
1951
  const children = [];
@@ -1965,6 +1978,10 @@ function reconcileChildren(prevElement, nextElement, dom) {
1965
1978
  dom.replaceChild(replacementDOM, lastDOM);
1966
1979
  destroyNode(prevFirstChildKey, null);
1967
1980
  }
1981
+ const nextChildNode = activeNextNodeMap.get(nextFrstChildKey);
1982
+ if (subTreeTextFormat === null && $isTextNode(nextChildNode)) {
1983
+ subTreeTextFormat = nextChildNode.getFormat();
1984
+ }
1968
1985
  } else {
1969
1986
  const prevChildren = createChildrenArray(prevElement, activePrevNodeMap);
1970
1987
  const nextChildren = createChildrenArray(nextElement, activeNextNodeMap);
@@ -2168,6 +2185,10 @@ function reconcileNodeChildren(nextElement, prevChildren, nextChildren, prevChil
2168
2185
  nextIndex++;
2169
2186
  }
2170
2187
  }
2188
+ const node = activeNextNodeMap.get(nextKey);
2189
+ if (node !== null && subTreeTextFormat === null && $isTextNode(node)) {
2190
+ subTreeTextFormat = node.getFormat();
2191
+ }
2171
2192
  }
2172
2193
  const appendNewChildren = prevIndex > prevEndIndex;
2173
2194
  const removeOldChildren = nextIndex > nextEndIndex;
@@ -2377,7 +2398,12 @@ function onSelectionChange(domSelection, editor, isActive) {
2377
2398
  selection.format = anchorNode.getFormat();
2378
2399
  selection.style = anchorNode.getStyle();
2379
2400
  } else if (anchor.type === 'element' && !isRootTextContentEmpty) {
2380
- selection.format = 0;
2401
+ const lastNode = anchor.getNode();
2402
+ if (lastNode instanceof ParagraphNode && lastNode.getChildrenSize() === 0) {
2403
+ selection.format = lastNode.getTextFormat();
2404
+ } else {
2405
+ selection.format = 0;
2406
+ }
2381
2407
  selection.style = '';
2382
2408
  }
2383
2409
  }
@@ -2729,7 +2755,6 @@ function onBeforeInput(event, editor) {
2729
2755
  }
2730
2756
  });
2731
2757
  }
2732
-
2733
2758
  function onInput(event, editor) {
2734
2759
  // We don't want the onInput to bubble, in the case of nested editors.
2735
2760
  event.stopPropagation();
@@ -3049,7 +3074,7 @@ function addRootElementEvents(rootElement, editor) {
3049
3074
  // between all editor instances.
3050
3075
  const doc = rootElement.ownerDocument;
3051
3076
  const documentRootElementsCount = rootElementsRegistered.get(doc);
3052
- if (documentRootElementsCount === undefined) {
3077
+ if (documentRootElementsCount === undefined || documentRootElementsCount < 1) {
3053
3078
  doc.addEventListener('selectionchange', onDocumentSelectionChange);
3054
3079
  }
3055
3080
  rootElementsRegistered.set(doc, documentRootElementsCount || 0 + 1);
@@ -3111,7 +3136,7 @@ function removeRootElementEvents(rootElement) {
3111
3136
  } // We only want to have a single global selectionchange event handler, shared
3112
3137
  // between all editor instances.
3113
3138
  rootElementsRegistered.set(doc, documentRootElementsCount - 1);
3114
- if (documentRootElementsCount === 1) {
3139
+ if (rootElementsRegistered.get(doc) === 0) {
3115
3140
  doc.removeEventListener('selectionchange', onDocumentSelectionChange);
3116
3141
  }
3117
3142
 
@@ -3201,10 +3226,15 @@ class LexicalNode {
3201
3226
 
3202
3227
  /** @internal */
3203
3228
 
3204
- /** @internal */ //@ts-ignore We set the key in the constructor.
3205
3229
  /** @internal */
3230
+ //@ts-ignore We set the key in the constructor.
3231
+
3232
+ /** @internal */
3233
+
3206
3234
  /** @internal */
3235
+
3207
3236
  /** @internal */
3237
+
3208
3238
  // Flow doesn't support abstract classes unfortunately, so we can't _force_
3209
3239
  // subclasses of Node to implement statics. All subclasses of Node should have
3210
3240
  // a static getType and clone method though. We define getType and clone here so we can call it
@@ -3707,6 +3737,9 @@ class LexicalNode {
3707
3737
  mutableNode.__next = latestNode.__next;
3708
3738
  mutableNode.__prev = latestNode.__prev;
3709
3739
  if ($isElementNode(latestNode) && $isElementNode(mutableNode)) {
3740
+ if ($isParagraphNode(latestNode) && $isParagraphNode(mutableNode)) {
3741
+ mutableNode.__textFormat = latestNode.__textFormat;
3742
+ }
3710
3743
  mutableNode.__first = latestNode.__first;
3711
3744
  mutableNode.__last = latestNode.__last;
3712
3745
  mutableNode.__size = latestNode.__size;
@@ -4712,7 +4745,7 @@ class TextNode extends LexicalNode {
4712
4745
  * Sets the node detail to the provided TextDetailType or 32-bit integer. Note that the TextDetailType
4713
4746
  * version of the argument can only specify one detail value and doing so will remove all other detail values that
4714
4747
  * may be applied to the node. For toggling behavior, consider using {@link TextNode.toggleDirectionless}
4715
- * or {@link TextNode.togglerUnmergeable}
4748
+ * or {@link TextNode.toggleUnmergeable}
4716
4749
  *
4717
4750
  * @param detail - TextDetailType or 32-bit integer representing the node detail.
4718
4751
  *
@@ -5070,16 +5103,18 @@ class TextNode extends LexicalNode {
5070
5103
  function convertSpanElement(domNode) {
5071
5104
  // domNode is a <span> since we matched it by nodeName
5072
5105
  const span = domNode;
5106
+ const style = span.style;
5107
+ const fontWeight = style.fontWeight;
5073
5108
  // Google Docs uses span tags + font-weight for bold text
5074
- const hasBoldFontWeight = span.style.fontWeight === '700';
5109
+ const hasBoldFontWeight = fontWeight === '700' || fontWeight === 'bold';
5075
5110
  // Google Docs uses span tags + text-decoration: line-through for strikethrough text
5076
- const hasLinethroughTextDecoration = span.style.textDecoration === 'line-through';
5111
+ const hasLinethroughTextDecoration = style.textDecoration === 'line-through';
5077
5112
  // Google Docs uses span tags + font-style for italic text
5078
- const hasItalicFontStyle = span.style.fontStyle === 'italic';
5113
+ const hasItalicFontStyle = style.fontStyle === 'italic';
5079
5114
  // Google Docs uses span tags + text-decoration: underline for underline text
5080
- const hasUnderlineTextDecoration = span.style.textDecoration === 'underline';
5115
+ const hasUnderlineTextDecoration = style.textDecoration === 'underline';
5081
5116
  // Google Docs uses span tags + vertical-align to specify subscript and superscript
5082
- const verticalAlign = span.style.verticalAlign;
5117
+ const verticalAlign = style.verticalAlign;
5083
5118
  return {
5084
5119
  forChild: lexicalNode => {
5085
5120
  if (!$isTextNode(lexicalNode)) {
@@ -6798,6 +6833,7 @@ function internalResolveSelectionPoint(dom, offset, lastPoint, editor) {
6798
6833
  return null;
6799
6834
  }
6800
6835
  if ($isElementNode(resolvedElement)) {
6836
+ resolvedOffset = Math.min(resolvedElement.getChildrenSize(), resolvedOffset);
6801
6837
  let child = resolvedElement.getChildAtIndex(resolvedOffset);
6802
6838
  if ($isElementNode(child) && shouldResolveAncestor(child, resolvedOffset, lastPoint)) {
6803
6839
  const descendant = moveSelectionToEnd ? child.getLastDescendant() : child.getFirstDescendant();
@@ -6962,6 +6998,9 @@ function internalCreateSelection(editor) {
6962
6998
  }
6963
6999
  return lastSelection.clone();
6964
7000
  }
7001
+ function $createRangeSelectionFromDom(domSelection, editor) {
7002
+ return internalCreateRangeSelection(null, domSelection, editor, null);
7003
+ }
6965
7004
  function internalCreateRangeSelection(lastSelection, domSelection, editor, event) {
6966
7005
  const windowObj = editor._window;
6967
7006
  if (windowObj === null) {
@@ -8720,9 +8759,28 @@ class EditorState {
8720
8759
  */
8721
8760
  /** @noInheritDoc */
8722
8761
  class ParagraphNode extends ElementNode {
8762
+ /** @internal */
8763
+
8764
+ constructor(key) {
8765
+ super(key);
8766
+ this.__textFormat = 0;
8767
+ }
8723
8768
  static getType() {
8724
8769
  return 'paragraph';
8725
8770
  }
8771
+ getTextFormat() {
8772
+ const self = this.getLatest();
8773
+ return self.__textFormat;
8774
+ }
8775
+ setTextFormat(type) {
8776
+ const self = this.getWritable();
8777
+ self.__textFormat = type;
8778
+ return self;
8779
+ }
8780
+ hasTextFormat(type) {
8781
+ const formatFlag = TEXT_TYPE_TO_FORMAT[type];
8782
+ return (this.getTextFormat() & formatFlag) !== 0;
8783
+ }
8726
8784
  static clone(node) {
8727
8785
  return new ParagraphNode(node.__key);
8728
8786
  }
@@ -8779,11 +8837,13 @@ class ParagraphNode extends ElementNode {
8779
8837
  node.setFormat(serializedNode.format);
8780
8838
  node.setIndent(serializedNode.indent);
8781
8839
  node.setDirection(serializedNode.direction);
8840
+ node.setTextFormat(serializedNode.textFormat);
8782
8841
  return node;
8783
8842
  }
8784
8843
  exportJSON() {
8785
8844
  return {
8786
8845
  ...super.exportJSON(),
8846
+ textFormat: this.getTextFormat(),
8787
8847
  type: 'paragraph',
8788
8848
  version: 1
8789
8849
  };
@@ -8791,10 +8851,12 @@ class ParagraphNode extends ElementNode {
8791
8851
 
8792
8852
  // Mutation
8793
8853
 
8794
- insertNewAfter(_, restoreSelection) {
8854
+ insertNewAfter(rangeSelection, restoreSelection) {
8795
8855
  const newElement = $createParagraphNode();
8856
+ newElement.setTextFormat(rangeSelection.format);
8796
8857
  const direction = this.getDirection();
8797
8858
  newElement.setDirection(direction);
8859
+ newElement.setFormat(this.getFormatType());
8798
8860
  this.insertAfter(newElement, restoreSelection);
8799
8861
  return newElement;
8800
8862
  }
@@ -8849,7 +8911,9 @@ function $isParagraphNode(node) {
8849
8911
 
8850
8912
  // https://github.com/microsoft/TypeScript/issues/3841
8851
8913
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8914
+
8852
8915
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8916
+
8853
8917
  const COMMAND_PRIORITY_EDITOR = 0;
8854
8918
  const COMMAND_PRIORITY_LOW = 1;
8855
8919
  const COMMAND_PRIORITY_NORMAL = 2;
@@ -9622,6 +9686,7 @@ exports.$createNodeSelection = $createNodeSelection;
9622
9686
  exports.$createParagraphNode = $createParagraphNode;
9623
9687
  exports.$createPoint = $createPoint;
9624
9688
  exports.$createRangeSelection = $createRangeSelection;
9689
+ exports.$createRangeSelectionFromDom = $createRangeSelectionFromDom;
9625
9690
  exports.$createTabNode = $createTabNode;
9626
9691
  exports.$createTextNode = $createTextNode;
9627
9692
  exports.$getAdjacentNode = $getAdjacentNode;
@@ -997,9 +997,9 @@ function $shouldInsertTextAfterOrBeforeTextNode(selection, node) {
997
997
  const parent = node.getParentOrThrow();
998
998
  const isToken = node.isToken();
999
999
  if (offset === 0) {
1000
- return !node.canInsertTextBefore() || !parent.canInsertTextBefore() || isToken || $previousSiblingDoesNotAcceptText(node);
1000
+ return !node.canInsertTextBefore() || !parent.canInsertTextBefore() && !node.isComposing() || isToken || $previousSiblingDoesNotAcceptText(node);
1001
1001
  } else if (offset === node.getTextContentSize()) {
1002
- return !node.canInsertTextAfter() || !parent.canInsertTextAfter() || isToken;
1002
+ return !node.canInsertTextAfter() || !parent.canInsertTextAfter() && !node.isComposing() || isToken;
1003
1003
  } else {
1004
1004
  return false;
1005
1005
  }
@@ -1664,6 +1664,7 @@ function $garbageCollectDetachedNodes(prevEditorState, editorState, dirtyLeaves,
1664
1664
  */
1665
1665
  let subTreeTextContent = '';
1666
1666
  let subTreeDirectionedTextContent = '';
1667
+ let subTreeTextFormat = null;
1667
1668
  let editorTextContent = '';
1668
1669
  let activeEditorConfig;
1669
1670
  let activeEditor$1;
@@ -1834,6 +1835,10 @@ function createChildren(children, element, _startIndex, endIndex, dom, insertDOM
1834
1835
  let startIndex = _startIndex;
1835
1836
  for (; startIndex <= endIndex; ++startIndex) {
1836
1837
  createNode(children[startIndex], dom, insertDOM);
1838
+ const node = activeNextNodeMap.get(children[startIndex]);
1839
+ if (node !== null && subTreeTextFormat === null && $isTextNode(node)) {
1840
+ subTreeTextFormat = node.getFormat();
1841
+ }
1837
1842
  }
1838
1843
  if ($textContentRequiresDoubleLinebreakAtEnd(element)) {
1839
1844
  subTreeTextContent += DOUBLE_LINE_BREAK;
@@ -1869,6 +1874,11 @@ function reconcileElementTerminatingLineBreak(prevElement, nextElement, dom) {
1869
1874
  dom.appendChild(element);
1870
1875
  }
1871
1876
  }
1877
+ function reconcileParagraphFormat(element) {
1878
+ if ($isParagraphNode(element) && subTreeTextFormat != null && subTreeTextFormat !== element.__textFormat) {
1879
+ element.setTextFormat(subTreeTextFormat);
1880
+ }
1881
+ }
1872
1882
  function reconcileBlockDirection(element, dom) {
1873
1883
  const previousSubTreeDirectionTextContent =
1874
1884
  // @ts-expect-error: internal field
@@ -1928,9 +1938,12 @@ function reconcileBlockDirection(element, dom) {
1928
1938
  function reconcileChildrenWithDirection(prevElement, nextElement, dom) {
1929
1939
  const previousSubTreeDirectionTextContent = subTreeDirectionedTextContent;
1930
1940
  subTreeDirectionedTextContent = '';
1941
+ subTreeTextFormat = null;
1931
1942
  reconcileChildren(prevElement, nextElement, dom);
1932
1943
  reconcileBlockDirection(nextElement, dom);
1944
+ reconcileParagraphFormat(nextElement);
1933
1945
  subTreeDirectionedTextContent = previousSubTreeDirectionTextContent;
1946
+ subTreeTextFormat = null;
1934
1947
  }
1935
1948
  function createChildrenArray(element, nodeMap) {
1936
1949
  const children = [];
@@ -1963,6 +1976,10 @@ function reconcileChildren(prevElement, nextElement, dom) {
1963
1976
  dom.replaceChild(replacementDOM, lastDOM);
1964
1977
  destroyNode(prevFirstChildKey, null);
1965
1978
  }
1979
+ const nextChildNode = activeNextNodeMap.get(nextFrstChildKey);
1980
+ if (subTreeTextFormat === null && $isTextNode(nextChildNode)) {
1981
+ subTreeTextFormat = nextChildNode.getFormat();
1982
+ }
1966
1983
  } else {
1967
1984
  const prevChildren = createChildrenArray(prevElement, activePrevNodeMap);
1968
1985
  const nextChildren = createChildrenArray(nextElement, activeNextNodeMap);
@@ -2166,6 +2183,10 @@ function reconcileNodeChildren(nextElement, prevChildren, nextChildren, prevChil
2166
2183
  nextIndex++;
2167
2184
  }
2168
2185
  }
2186
+ const node = activeNextNodeMap.get(nextKey);
2187
+ if (node !== null && subTreeTextFormat === null && $isTextNode(node)) {
2188
+ subTreeTextFormat = node.getFormat();
2189
+ }
2169
2190
  }
2170
2191
  const appendNewChildren = prevIndex > prevEndIndex;
2171
2192
  const removeOldChildren = nextIndex > nextEndIndex;
@@ -2375,7 +2396,12 @@ function onSelectionChange(domSelection, editor, isActive) {
2375
2396
  selection.format = anchorNode.getFormat();
2376
2397
  selection.style = anchorNode.getStyle();
2377
2398
  } else if (anchor.type === 'element' && !isRootTextContentEmpty) {
2378
- selection.format = 0;
2399
+ const lastNode = anchor.getNode();
2400
+ if (lastNode instanceof ParagraphNode && lastNode.getChildrenSize() === 0) {
2401
+ selection.format = lastNode.getTextFormat();
2402
+ } else {
2403
+ selection.format = 0;
2404
+ }
2379
2405
  selection.style = '';
2380
2406
  }
2381
2407
  }
@@ -2727,7 +2753,6 @@ function onBeforeInput(event, editor) {
2727
2753
  }
2728
2754
  });
2729
2755
  }
2730
-
2731
2756
  function onInput(event, editor) {
2732
2757
  // We don't want the onInput to bubble, in the case of nested editors.
2733
2758
  event.stopPropagation();
@@ -3047,7 +3072,7 @@ function addRootElementEvents(rootElement, editor) {
3047
3072
  // between all editor instances.
3048
3073
  const doc = rootElement.ownerDocument;
3049
3074
  const documentRootElementsCount = rootElementsRegistered.get(doc);
3050
- if (documentRootElementsCount === undefined) {
3075
+ if (documentRootElementsCount === undefined || documentRootElementsCount < 1) {
3051
3076
  doc.addEventListener('selectionchange', onDocumentSelectionChange);
3052
3077
  }
3053
3078
  rootElementsRegistered.set(doc, documentRootElementsCount || 0 + 1);
@@ -3109,7 +3134,7 @@ function removeRootElementEvents(rootElement) {
3109
3134
  } // We only want to have a single global selectionchange event handler, shared
3110
3135
  // between all editor instances.
3111
3136
  rootElementsRegistered.set(doc, documentRootElementsCount - 1);
3112
- if (documentRootElementsCount === 1) {
3137
+ if (rootElementsRegistered.get(doc) === 0) {
3113
3138
  doc.removeEventListener('selectionchange', onDocumentSelectionChange);
3114
3139
  }
3115
3140
 
@@ -3199,10 +3224,15 @@ class LexicalNode {
3199
3224
 
3200
3225
  /** @internal */
3201
3226
 
3202
- /** @internal */ //@ts-ignore We set the key in the constructor.
3203
3227
  /** @internal */
3228
+ //@ts-ignore We set the key in the constructor.
3229
+
3230
+ /** @internal */
3231
+
3204
3232
  /** @internal */
3233
+
3205
3234
  /** @internal */
3235
+
3206
3236
  // Flow doesn't support abstract classes unfortunately, so we can't _force_
3207
3237
  // subclasses of Node to implement statics. All subclasses of Node should have
3208
3238
  // a static getType and clone method though. We define getType and clone here so we can call it
@@ -3705,6 +3735,9 @@ class LexicalNode {
3705
3735
  mutableNode.__next = latestNode.__next;
3706
3736
  mutableNode.__prev = latestNode.__prev;
3707
3737
  if ($isElementNode(latestNode) && $isElementNode(mutableNode)) {
3738
+ if ($isParagraphNode(latestNode) && $isParagraphNode(mutableNode)) {
3739
+ mutableNode.__textFormat = latestNode.__textFormat;
3740
+ }
3708
3741
  mutableNode.__first = latestNode.__first;
3709
3742
  mutableNode.__last = latestNode.__last;
3710
3743
  mutableNode.__size = latestNode.__size;
@@ -4710,7 +4743,7 @@ class TextNode extends LexicalNode {
4710
4743
  * Sets the node detail to the provided TextDetailType or 32-bit integer. Note that the TextDetailType
4711
4744
  * version of the argument can only specify one detail value and doing so will remove all other detail values that
4712
4745
  * may be applied to the node. For toggling behavior, consider using {@link TextNode.toggleDirectionless}
4713
- * or {@link TextNode.togglerUnmergeable}
4746
+ * or {@link TextNode.toggleUnmergeable}
4714
4747
  *
4715
4748
  * @param detail - TextDetailType or 32-bit integer representing the node detail.
4716
4749
  *
@@ -5068,16 +5101,18 @@ class TextNode extends LexicalNode {
5068
5101
  function convertSpanElement(domNode) {
5069
5102
  // domNode is a <span> since we matched it by nodeName
5070
5103
  const span = domNode;
5104
+ const style = span.style;
5105
+ const fontWeight = style.fontWeight;
5071
5106
  // Google Docs uses span tags + font-weight for bold text
5072
- const hasBoldFontWeight = span.style.fontWeight === '700';
5107
+ const hasBoldFontWeight = fontWeight === '700' || fontWeight === 'bold';
5073
5108
  // Google Docs uses span tags + text-decoration: line-through for strikethrough text
5074
- const hasLinethroughTextDecoration = span.style.textDecoration === 'line-through';
5109
+ const hasLinethroughTextDecoration = style.textDecoration === 'line-through';
5075
5110
  // Google Docs uses span tags + font-style for italic text
5076
- const hasItalicFontStyle = span.style.fontStyle === 'italic';
5111
+ const hasItalicFontStyle = style.fontStyle === 'italic';
5077
5112
  // Google Docs uses span tags + text-decoration: underline for underline text
5078
- const hasUnderlineTextDecoration = span.style.textDecoration === 'underline';
5113
+ const hasUnderlineTextDecoration = style.textDecoration === 'underline';
5079
5114
  // Google Docs uses span tags + vertical-align to specify subscript and superscript
5080
- const verticalAlign = span.style.verticalAlign;
5115
+ const verticalAlign = style.verticalAlign;
5081
5116
  return {
5082
5117
  forChild: lexicalNode => {
5083
5118
  if (!$isTextNode(lexicalNode)) {
@@ -6796,6 +6831,7 @@ function internalResolveSelectionPoint(dom, offset, lastPoint, editor) {
6796
6831
  return null;
6797
6832
  }
6798
6833
  if ($isElementNode(resolvedElement)) {
6834
+ resolvedOffset = Math.min(resolvedElement.getChildrenSize(), resolvedOffset);
6799
6835
  let child = resolvedElement.getChildAtIndex(resolvedOffset);
6800
6836
  if ($isElementNode(child) && shouldResolveAncestor(child, resolvedOffset, lastPoint)) {
6801
6837
  const descendant = moveSelectionToEnd ? child.getLastDescendant() : child.getFirstDescendant();
@@ -6960,6 +6996,9 @@ function internalCreateSelection(editor) {
6960
6996
  }
6961
6997
  return lastSelection.clone();
6962
6998
  }
6999
+ function $createRangeSelectionFromDom(domSelection, editor) {
7000
+ return internalCreateRangeSelection(null, domSelection, editor, null);
7001
+ }
6963
7002
  function internalCreateRangeSelection(lastSelection, domSelection, editor, event) {
6964
7003
  const windowObj = editor._window;
6965
7004
  if (windowObj === null) {
@@ -8718,9 +8757,28 @@ class EditorState {
8718
8757
  */
8719
8758
  /** @noInheritDoc */
8720
8759
  class ParagraphNode extends ElementNode {
8760
+ /** @internal */
8761
+
8762
+ constructor(key) {
8763
+ super(key);
8764
+ this.__textFormat = 0;
8765
+ }
8721
8766
  static getType() {
8722
8767
  return 'paragraph';
8723
8768
  }
8769
+ getTextFormat() {
8770
+ const self = this.getLatest();
8771
+ return self.__textFormat;
8772
+ }
8773
+ setTextFormat(type) {
8774
+ const self = this.getWritable();
8775
+ self.__textFormat = type;
8776
+ return self;
8777
+ }
8778
+ hasTextFormat(type) {
8779
+ const formatFlag = TEXT_TYPE_TO_FORMAT[type];
8780
+ return (this.getTextFormat() & formatFlag) !== 0;
8781
+ }
8724
8782
  static clone(node) {
8725
8783
  return new ParagraphNode(node.__key);
8726
8784
  }
@@ -8777,11 +8835,13 @@ class ParagraphNode extends ElementNode {
8777
8835
  node.setFormat(serializedNode.format);
8778
8836
  node.setIndent(serializedNode.indent);
8779
8837
  node.setDirection(serializedNode.direction);
8838
+ node.setTextFormat(serializedNode.textFormat);
8780
8839
  return node;
8781
8840
  }
8782
8841
  exportJSON() {
8783
8842
  return {
8784
8843
  ...super.exportJSON(),
8844
+ textFormat: this.getTextFormat(),
8785
8845
  type: 'paragraph',
8786
8846
  version: 1
8787
8847
  };
@@ -8789,10 +8849,12 @@ class ParagraphNode extends ElementNode {
8789
8849
 
8790
8850
  // Mutation
8791
8851
 
8792
- insertNewAfter(_, restoreSelection) {
8852
+ insertNewAfter(rangeSelection, restoreSelection) {
8793
8853
  const newElement = $createParagraphNode();
8854
+ newElement.setTextFormat(rangeSelection.format);
8794
8855
  const direction = this.getDirection();
8795
8856
  newElement.setDirection(direction);
8857
+ newElement.setFormat(this.getFormatType());
8796
8858
  this.insertAfter(newElement, restoreSelection);
8797
8859
  return newElement;
8798
8860
  }
@@ -8847,7 +8909,9 @@ function $isParagraphNode(node) {
8847
8909
 
8848
8910
  // https://github.com/microsoft/TypeScript/issues/3841
8849
8911
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8912
+
8850
8913
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8914
+
8851
8915
  const COMMAND_PRIORITY_EDITOR = 0;
8852
8916
  const COMMAND_PRIORITY_LOW = 1;
8853
8917
  const COMMAND_PRIORITY_NORMAL = 2;
@@ -9612,4 +9676,4 @@ class LexicalEditor {
9612
9676
  }
9613
9677
  }
9614
9678
 
9615
- export { $addUpdateTag, $applyNodeReplacement, $copyNode, $createLineBreakNode, $createNodeSelection, $createParagraphNode, $createPoint, $createRangeSelection, $createTabNode, $createTextNode, $getAdjacentNode, $getCharacterOffsets, $getEditor, $getNearestNodeFromDOMNode, $getNearestRootOrShadowRoot, $getNodeByKey, $getPreviousSelection, $getRoot, $getSelection, $getTextContent, $hasAncestor, $hasUpdateTag, $insertNodes, $isBlockElementNode, $isDecoratorNode, $isElementNode, $isInlineElementOrDecoratorNode, $isLeafNode, $isLineBreakNode, $isNodeSelection, $isParagraphNode, $isRangeSelection, $isRootNode, $isRootOrShadowRoot, $isTabNode, $isTextNode, $nodesOfType, $normalizeSelection as $normalizeSelection__EXPERIMENTAL, $parseSerializedNode, $selectAll, $setCompositionKey, $setSelection, $splitNode, BLUR_COMMAND, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, CLEAR_EDITOR_COMMAND, CLEAR_HISTORY_COMMAND, CLICK_COMMAND, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_LOW, COMMAND_PRIORITY_NORMAL, CONTROLLED_TEXT_INSERTION_COMMAND, COPY_COMMAND, CUT_COMMAND, DELETE_CHARACTER_COMMAND, DELETE_LINE_COMMAND, DELETE_WORD_COMMAND, DRAGEND_COMMAND, DRAGOVER_COMMAND, DRAGSTART_COMMAND, DROP_COMMAND, DecoratorNode, ElementNode, FOCUS_COMMAND, FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND, INDENT_CONTENT_COMMAND, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, INSERT_TAB_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_DOWN_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, KEY_MODIFIER_COMMAND, KEY_SPACE_COMMAND, KEY_TAB_COMMAND, LineBreakNode, MOVE_TO_END, MOVE_TO_START, OUTDENT_CONTENT_COMMAND, PASTE_COMMAND, ParagraphNode, REDO_COMMAND, REMOVE_TEXT_COMMAND, RootNode, SELECTION_CHANGE_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, SELECT_ALL_COMMAND, TabNode, TextNode, UNDO_COMMAND, createCommand, createEditor, getNearestEditorFromDOMNode, isCurrentlyReadOnlyMode, isHTMLAnchorElement, isHTMLElement, isSelectionCapturedInDecoratorInput, isSelectionWithinEditor };
9679
+ export { $addUpdateTag, $applyNodeReplacement, $copyNode, $createLineBreakNode, $createNodeSelection, $createParagraphNode, $createPoint, $createRangeSelection, $createRangeSelectionFromDom, $createTabNode, $createTextNode, $getAdjacentNode, $getCharacterOffsets, $getEditor, $getNearestNodeFromDOMNode, $getNearestRootOrShadowRoot, $getNodeByKey, $getPreviousSelection, $getRoot, $getSelection, $getTextContent, $hasAncestor, $hasUpdateTag, $insertNodes, $isBlockElementNode, $isDecoratorNode, $isElementNode, $isInlineElementOrDecoratorNode, $isLeafNode, $isLineBreakNode, $isNodeSelection, $isParagraphNode, $isRangeSelection, $isRootNode, $isRootOrShadowRoot, $isTabNode, $isTextNode, $nodesOfType, $normalizeSelection as $normalizeSelection__EXPERIMENTAL, $parseSerializedNode, $selectAll, $setCompositionKey, $setSelection, $splitNode, BLUR_COMMAND, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, CLEAR_EDITOR_COMMAND, CLEAR_HISTORY_COMMAND, CLICK_COMMAND, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_LOW, COMMAND_PRIORITY_NORMAL, CONTROLLED_TEXT_INSERTION_COMMAND, COPY_COMMAND, CUT_COMMAND, DELETE_CHARACTER_COMMAND, DELETE_LINE_COMMAND, DELETE_WORD_COMMAND, DRAGEND_COMMAND, DRAGOVER_COMMAND, DRAGSTART_COMMAND, DROP_COMMAND, DecoratorNode, ElementNode, FOCUS_COMMAND, FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND, INDENT_CONTENT_COMMAND, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, INSERT_TAB_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_DOWN_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, KEY_MODIFIER_COMMAND, KEY_SPACE_COMMAND, KEY_TAB_COMMAND, LineBreakNode, MOVE_TO_END, MOVE_TO_START, OUTDENT_CONTENT_COMMAND, PASTE_COMMAND, ParagraphNode, REDO_COMMAND, REMOVE_TEXT_COMMAND, RootNode, SELECTION_CHANGE_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, SELECT_ALL_COMMAND, TabNode, TextNode, UNDO_COMMAND, createCommand, createEditor, getNearestEditorFromDOMNode, isCurrentlyReadOnlyMode, isHTMLAnchorElement, isHTMLElement, isSelectionCapturedInDecoratorInput, isSelectionWithinEditor };
package/Lexical.js.flow CHANGED
@@ -782,7 +782,10 @@ declare export class ParagraphNode extends ElementNode {
782
782
  constructor(key?: NodeKey): void;
783
783
  createDOM(config: EditorConfig): HTMLElement;
784
784
  updateDOM(prevNode: ParagraphNode, dom: HTMLElement): boolean;
785
- insertNewAfter(): ParagraphNode;
785
+ insertNewAfter(
786
+ selection: RangeSelection,
787
+ restoreSelection?: boolean,
788
+ ): ParagraphNode;
786
789
  collapseAtStart(): boolean;
787
790
  static importJSON(
788
791
  serializedParagraphNode: SerializedParagraphNode,
@@ -4,8 +4,8 @@
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
- import * as modDev from './Lexical.dev.esm.js';
8
- import * as modProd from './Lexical.prod.esm.js';
7
+ import * as modDev from './Lexical.dev.mjs';
8
+ import * as modProd from './Lexical.prod.mjs';
9
9
  const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
10
  export const $addUpdateTag = mod.$addUpdateTag;
11
11
  export const $applyNodeReplacement = mod.$applyNodeReplacement;
@@ -15,6 +15,7 @@ export const $createNodeSelection = mod.$createNodeSelection;
15
15
  export const $createParagraphNode = mod.$createParagraphNode;
16
16
  export const $createPoint = mod.$createPoint;
17
17
  export const $createRangeSelection = mod.$createRangeSelection;
18
+ export const $createRangeSelectionFromDom = mod.$createRangeSelectionFromDom;
18
19
  export const $createTabNode = mod.$createTabNode;
19
20
  export const $createTextNode = mod.$createTextNode;
20
21
  export const $getAdjacentNode = mod.$getAdjacentNode;