@lexical/react 0.1.9 → 0.1.12

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.
Files changed (95) hide show
  1. package/DEPRECATED_useLexical.dev.js +5 -44
  2. package/DEPRECATED_useLexical.prod.js +1 -2
  3. package/DEPRECATED_useLexicalAutoFormatter.dev.js +87 -41
  4. package/DEPRECATED_useLexicalAutoFormatter.prod.js +20 -18
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +22 -19
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
  7. package/DEPRECATED_useLexicalEditor.dev.js +1 -25
  8. package/DEPRECATED_useLexicalEditor.prod.js +1 -1
  9. package/DEPRECATED_useLexicalHistory.dev.js +1 -1
  10. package/DEPRECATED_useLexicalHistory.prod.js +2 -2
  11. package/DEPRECATED_useLexicalList.dev.js +6 -0
  12. package/DEPRECATED_useLexicalList.prod.js +1 -1
  13. package/DEPRECATED_useLexicalPlainText.dev.js +81 -89
  14. package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
  15. package/DEPRECATED_useLexicalRichText.dev.js +98 -592
  16. package/DEPRECATED_useLexicalRichText.prod.js +17 -29
  17. package/LexicalAutoFormatterPlugin.d.ts +9 -0
  18. package/LexicalAutoFormatterPlugin.dev.js +87 -41
  19. package/LexicalAutoFormatterPlugin.js.flow +10 -0
  20. package/LexicalAutoFormatterPlugin.prod.js +21 -19
  21. package/LexicalAutoLinkPlugin.d.ts +20 -0
  22. package/LexicalAutoLinkPlugin.js.flow +23 -0
  23. package/LexicalCharacterLimitPlugin.d.ts +11 -0
  24. package/LexicalCharacterLimitPlugin.dev.js +22 -19
  25. package/LexicalCharacterLimitPlugin.js.flow +12 -0
  26. package/LexicalCharacterLimitPlugin.prod.js +9 -8
  27. package/LexicalClearEditorPlugin.d.ts +14 -0
  28. package/LexicalClearEditorPlugin.dev.js +73 -0
  29. package/LexicalClearEditorPlugin.js +9 -0
  30. package/LexicalClearEditorPlugin.js.flow +14 -0
  31. package/LexicalClearEditorPlugin.prod.js +8 -0
  32. package/LexicalCollaborationPlugin.d.ts +49 -0
  33. package/LexicalCollaborationPlugin.dev.js +21 -11
  34. package/LexicalCollaborationPlugin.js.flow +55 -0
  35. package/LexicalCollaborationPlugin.prod.js +7 -7
  36. package/LexicalComposer.d.ts +22 -0
  37. package/LexicalComposer.dev.js +29 -5
  38. package/LexicalComposer.js.flow +24 -0
  39. package/LexicalComposer.prod.js +3 -3
  40. package/LexicalComposerContext.d.ts +24 -0
  41. package/LexicalComposerContext.js.flow +27 -0
  42. package/LexicalContentEditable.d.ts +32 -0
  43. package/LexicalContentEditable.dev.js +35 -8
  44. package/LexicalContentEditable.js.flow +35 -0
  45. package/LexicalContentEditable.prod.js +3 -3
  46. package/LexicalHashtagPlugin.d.ts +9 -0
  47. package/LexicalHashtagPlugin.js.flow +10 -0
  48. package/LexicalHistoryPlugin.d.ts +29 -0
  49. package/LexicalHistoryPlugin.dev.js +1 -1
  50. package/LexicalHistoryPlugin.js.flow +34 -0
  51. package/LexicalHistoryPlugin.prod.js +2 -2
  52. package/LexicalHorizontalRuleNode.d.ts +23 -0
  53. package/LexicalHorizontalRuleNode.js.flow +25 -0
  54. package/LexicalLinkPlugin.d.ts +9 -0
  55. package/LexicalLinkPlugin.js.flow +10 -0
  56. package/LexicalListPlugin.d.ts +9 -0
  57. package/LexicalListPlugin.dev.js +6 -0
  58. package/LexicalListPlugin.js.flow +10 -0
  59. package/LexicalListPlugin.prod.js +2 -2
  60. package/LexicalNestedComposer.d.ts +20 -0
  61. package/LexicalNestedComposer.js.flow +21 -0
  62. package/LexicalOnChangePlugin.d.ts +12 -0
  63. package/LexicalOnChangePlugin.js.flow +14 -0
  64. package/LexicalPlainTextPlugin.d.ts +15 -0
  65. package/LexicalPlainTextPlugin.dev.js +77 -84
  66. package/LexicalPlainTextPlugin.js.flow +18 -0
  67. package/LexicalPlainTextPlugin.prod.js +12 -12
  68. package/LexicalRichTextPlugin.d.ts +15 -0
  69. package/LexicalRichTextPlugin.dev.js +93 -586
  70. package/LexicalRichTextPlugin.js.flow +18 -0
  71. package/LexicalRichTextPlugin.prod.js +13 -25
  72. package/LexicalTablePlugin.d.ts +9 -0
  73. package/LexicalTablePlugin.dev.js +23 -1
  74. package/LexicalTablePlugin.js.flow +10 -0
  75. package/LexicalTablePlugin.prod.js +4 -3
  76. package/LexicalTreeView.d.ts +17 -0
  77. package/LexicalTreeView.dev.js +10 -2
  78. package/LexicalTreeView.js.flow +19 -0
  79. package/LexicalTreeView.prod.js +9 -8
  80. package/README.md +0 -1
  81. package/package.json +6 -5
  82. package/useLexicalDecoratorMap.d.ts +14 -0
  83. package/useLexicalDecoratorMap.js.flow +16 -0
  84. package/useLexicalIsTextContentEmpty.d.ts +13 -0
  85. package/useLexicalIsTextContentEmpty.js.flow +15 -0
  86. package/useLexicalNodeSelection.d.ts +12 -0
  87. package/useLexicalNodeSelection.dev.js +70 -0
  88. package/useLexicalNodeSelection.js +9 -0
  89. package/useLexicalNodeSelection.js.flow +14 -0
  90. package/useLexicalNodeSelection.prod.js +8 -0
  91. package/withSubscriptions.d.ts +12 -0
  92. package/withSubscriptions.js.flow +13 -0
  93. package/LexicalBootstrapPlugin.dev.js +0 -122
  94. package/LexicalBootstrapPlugin.js +0 -9
  95. package/LexicalBootstrapPlugin.prod.js +0 -8
@@ -18,35 +18,11 @@ var useLexicalCanShowPlaceholder = require('@lexical/react/DEPRECATED_useLexical
18
18
  *
19
19
  *
20
20
  */
21
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
22
-
23
- /**
24
- * Copyright (c) Meta Platforms, Inc. and affiliates.
25
- *
26
- * This source code is licensed under the MIT license found in the
27
- * LICENSE file in the root directory of this source tree.
28
- *
29
- *
30
- */
31
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
32
- var useLayoutEffect = useLayoutEffectImpl;
33
-
34
- /**
35
- * Copyright (c) Meta Platforms, Inc. and affiliates.
36
- *
37
- * This source code is licensed under the MIT license found in the
38
- * LICENSE file in the root directory of this source tree.
39
- *
40
- *
41
- */
42
- function useLexicalEditor(editor, onError) {
21
+ function useLexicalEditor(editor) {
43
22
  const showPlaceholder = useLexicalCanShowPlaceholder(editor);
44
23
  const rootElementRef = react.useCallback(rootElement => {
45
24
  editor.setRootElement(rootElement);
46
25
  }, [editor]);
47
- useLayoutEffect(() => {
48
- return editor.addListener('error', onError);
49
- }, [editor, onError]);
50
26
  return [rootElementRef, showPlaceholder];
51
27
  }
52
28
 
@@ -58,26 +34,11 @@ function useLexicalEditor(editor, onError) {
58
34
  *
59
35
  *
60
36
  */
61
-
62
- function defaultOnErrorHandler(e) {
63
- throw e;
64
- }
65
-
66
37
  function useLexical(editorConfig) {
67
- const onError = editorConfig !== undefined && editorConfig.onError || defaultOnErrorHandler;
68
- const editor = react.useMemo(() => {
69
- if (editorConfig !== undefined) {
70
- // eslint-disable-next-line no-unused-vars
71
- const {
72
- onError: _onError,
73
- ...config
74
- } = editorConfig;
75
- return lexical.createEditor(config);
76
- }
77
-
78
- return lexical.createEditor(editorConfig);
79
- }, [editorConfig]);
80
- const [rootElementRef, showPlaceholder] = useLexicalEditor(editor, onError);
38
+ const editor = react.useMemo(() => lexical.createEditor(editorConfig), // Init
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ []);
41
+ const [rootElementRef, showPlaceholder] = useLexicalEditor(editor);
81
42
  return [editor, rootElementRef, showPlaceholder];
82
43
  }
83
44
 
@@ -4,5 +4,4 @@
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
- var b=require("lexical"),g=require("react"),h=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function l(a,c){const d=h(a),f=g.useCallback(e=>{a.setRootElement(e)},[a]);k(()=>a.addListener("error",c),[a,c]);return[f,d]}function m(a){throw a;}
8
- module.exports=function(a){const c=void 0!==a&&a.onError||m,d=g.useMemo(()=>{if(void 0!==a){const {onError:p,...n}=a;return b.createEditor(n)}return b.createEditor(a)},[a]),[f,e]=l(d,c);return[d,f,e]};
7
+ var d=require("lexical"),e=require("react"),f=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder");function g(a){const b=f(a);return[e.useCallback(c=>{a.setRootElement(c)},[a]),b]}module.exports=function(a){const b=e.useMemo(()=>d.createEditor(a),[]),[c,h]=g(b);return[b,c,h]};
@@ -132,31 +132,31 @@ const paragraphStartBase = { ...autoFormatBase,
132
132
  };
133
133
  const markdownHeader1 = { ...paragraphStartBase,
134
134
  nodeTransformationKind: 'paragraphH1',
135
- regEx: /(?:# )/
135
+ regEx: /^(?:# )/
136
136
  };
137
137
  const markdownHeader2 = { ...paragraphStartBase,
138
138
  nodeTransformationKind: 'paragraphH2',
139
- regEx: /(?:## )/
139
+ regEx: /^(?:## )/
140
140
  };
141
141
  const markdownHeader3 = { ...paragraphStartBase,
142
142
  nodeTransformationKind: 'paragraphH2',
143
- regEx: /(?:### )/
143
+ regEx: /^(?:### )/
144
144
  };
145
145
  const markdownBlockQuote = { ...paragraphStartBase,
146
146
  nodeTransformationKind: 'paragraphBlockQuote',
147
- regEx: /(?:> )/
147
+ regEx: /^(?:> )/
148
148
  };
149
149
  const markdownUnorderedListDash = { ...paragraphStartBase,
150
150
  nodeTransformationKind: 'paragraphUnorderedList',
151
- regEx: /(?:- )/
151
+ regEx: /^(?:- )/
152
152
  };
153
153
  const markdownUnorderedListAsterisk = { ...paragraphStartBase,
154
154
  nodeTransformationKind: 'paragraphUnorderedList',
155
- regEx: /(?:\* )/
155
+ regEx: /^(?:\* )/
156
156
  };
157
157
  const markdownCodeBlock = { ...paragraphStartBase,
158
158
  nodeTransformationKind: 'paragraphCodeBlock',
159
- regEx: /(?:``` )/
159
+ regEx: /^(```)([a-z]*)( )/
160
160
  };
161
161
  const markdownOrderedList = { ...paragraphStartBase,
162
162
  nodeTransformationKind: 'paragraphOrderedList',
@@ -164,20 +164,39 @@ const markdownOrderedList = { ...paragraphStartBase,
164
164
  };
165
165
  const markdownHorizontalRule = { ...paragraphStartBase,
166
166
  nodeTransformationKind: 'horizontalRule',
167
- regEx: /(?:\*\*\* )/
167
+ regEx: /^(?:\*\*\* )/
168
168
  };
169
169
  const markdownHorizontalRuleUsingDashes = { ...paragraphStartBase,
170
170
  nodeTransformationKind: 'horizontalRule',
171
- regEx: /(?:--- )/
171
+ regEx: /^(?:--- )/
172
+ };
173
+ const markdownItalic = { ...autoFormatBase,
174
+ nodeTransformationKind: 'italic',
175
+ regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/
172
176
  };
173
177
  const markdownBold = { ...autoFormatBase,
174
- nodeTransformationKind: 'textBold',
175
- // regEx: /(\*)(?:\s*\b)(?:[^\*]*)(?:\b\s*)(\*\s)$/, // The $ will find the target at the end of the string.
176
- regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/ // Remove the first and last capture groups. Remeber, the 0th capture group is the entire string.
177
- // e.g. "*Hello* " requires removing both "*" as well as bolding "Hello".
178
-
178
+ nodeTransformationKind: 'bold',
179
+ regEx: /(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/
180
+ };
181
+ const markdownBoldWithUnderlines = { ...autoFormatBase,
182
+ nodeTransformationKind: 'bold',
183
+ regEx: /(__)(\s*)([^__]*)(\s*)(__\s)$/
184
+ };
185
+ const markdownBoldItalic = { ...autoFormatBase,
186
+ nodeTransformationKind: 'bold_italic',
187
+ regEx: /(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/
188
+ }; // Markdown does not support underline, but we can allow folks to use
189
+ // the HTML tags for underline.
190
+
191
+ const fakeMarkdownUnderline = { ...autoFormatBase,
192
+ nodeTransformationKind: 'underline',
193
+ regEx: /(\<u\>)(\s*\b)([^\<]*)(\b\s*)(\<\/u\>\s)$/
179
194
  };
180
- const allAutoFormatCriteriaForTextNodes = [markdownBold];
195
+ const markdownStrikethrough = { ...autoFormatBase,
196
+ nodeTransformationKind: 'strikethrough',
197
+ regEx: /(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/
198
+ };
199
+ const allAutoFormatCriteriaForTextNodes = [markdownBoldItalic, markdownItalic, markdownBold, markdownBoldWithUnderlines, fakeMarkdownUnderline, markdownStrikethrough];
181
200
  const allAutoFormatCriteria = [markdownHeader1, markdownHeader2, markdownHeader3, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, markdownHorizontalRule, markdownHorizontalRuleUsingDashes, ...allAutoFormatCriteriaForTextNodes];
182
201
  function getAllAutoFormatCriteriaForTextNodes() {
183
202
  return allAutoFormatCriteriaForTextNodes;
@@ -258,17 +277,14 @@ function getMatchResultContextForText(autoFormatCriteria, scanningContext) {
258
277
  // Lazy calculate the text to search.
259
278
  scanningContext.joinedText = $joinTextNodesInElementNode(parentNode, SEPARATOR_BETWEEN_TEXT_AND_NON_TEXT_NODES, scanningContext.textNodeWithOffset);
260
279
  }
261
-
262
- return getMatchResultContextWithRegEx(scanningContext.joinedText, false, true, autoFormatCriteria.regEx);
263
280
  } else {
264
281
  {
265
282
  throw Error(`Expected node ${parentNode.__key} to to be a ElementNode.`);
266
283
  }
267
284
  }
268
- } // This is a placeholder function for following PR's related to character based transformations.
269
-
285
+ }
270
286
 
271
- return null;
287
+ return getMatchResultContextWithRegEx(scanningContext.joinedText, false, true, autoFormatCriteria.regEx);
272
288
  }
273
289
 
274
290
  function getMatchResultContextForCriteria(autoFormatCriteria, scanningContext) {
@@ -342,6 +358,11 @@ function getNewNodeForCriteria(scanningContext, element) {
342
358
  newNode = lexical.$createParagraphNode();
343
359
  } else {
344
360
  newNode = CodeNode.$createCodeNode();
361
+ const codingLanguage = matchResultContext.regExCaptureGroups.length >= 3 ? matchResultContext.regExCaptureGroups[2].text : null;
362
+
363
+ if (codingLanguage != null && codingLanguage.length > 0) {
364
+ newNode.setLanguage(codingLanguage);
365
+ }
345
366
  }
346
367
 
347
368
  newNode.append(...children);
@@ -390,28 +411,50 @@ function transformTextNodeForParagraphs(scanningContext) {
390
411
  }
391
412
  }
392
413
 
414
+ function getTextFormatType(nodeTransformationKind) {
415
+ switch (nodeTransformationKind) {
416
+ case 'italic':
417
+ case 'bold':
418
+ case 'underline':
419
+ case 'strikethrough':
420
+ return [nodeTransformationKind];
421
+
422
+ case 'bold_italic':
423
+ {
424
+ return ['bold', 'italic'];
425
+ }
426
+ }
427
+
428
+ return null;
429
+ }
430
+
393
431
  function transformTextNodeForText(scanningContext) {
394
432
  const autoFormatCriteria = scanningContext.autoFormatCriteria;
395
433
  const matchResultContext = scanningContext.matchResultContext;
396
434
 
397
435
  if (autoFormatCriteria.nodeTransformationKind != null) {
398
- switch (autoFormatCriteria.nodeTransformationKind) {
399
- case 'textBold':
400
- {
401
- if (matchResultContext.regExCaptureGroups.length !== 6) {
402
- // The expected reg ex pattern for bold should have 6 groups.
403
- // If it does not, then break and fail silently.
404
- // e2e tests validate the regEx pattern.
405
- break;
406
- }
436
+ if (matchResultContext.regExCaptureGroups.length !== 6) {
437
+ // For BIUS and other formatts which have a pattern + text + pattern,
438
+ // the expected reg ex pattern should have 6 groups.
439
+ // If it does not, then break and fail silently.
440
+ // e2e tests validate the regEx pattern.
441
+ return;
442
+ }
407
443
 
408
- matchResultContext.regExCaptureGroups = getCaptureGroupsByResolvingAllDetails(scanningContext); // Remove unwanted text in reg ex pattern.
444
+ const formatting = getTextFormatType(autoFormatCriteria.nodeTransformationKind);
409
445
 
410
- removeTextInCaptureGroups([1, 5], matchResultContext);
411
- formatTextInCaptureGroupIndex('bold', 3, matchResultContext);
412
- makeCollapsedSelectionAtOffsetInJoinedText(matchResultContext.offsetInJoinedTextForCollapsedSelection, matchResultContext.offsetInJoinedTextForCollapsedSelection + 1, scanningContext.textNodeWithOffset.node.getParentOrThrow());
413
- break;
414
- }
446
+ if (formatting != null) {
447
+ const captureGroupsToDelete = [1, 5];
448
+ const formatCaptureGroup = 3;
449
+ matchResultContext.regExCaptureGroups = getCaptureGroupsByResolvingAllDetails(scanningContext);
450
+
451
+ if (captureGroupsToDelete.length > 0) {
452
+ // Remove unwanted text in reg ex pattern.
453
+ removeTextInCaptureGroups(captureGroupsToDelete, matchResultContext);
454
+ }
455
+
456
+ formatTextInCaptureGroupIndex(formatting, formatCaptureGroup, matchResultContext);
457
+ makeCollapsedSelectionAtOffsetInJoinedText(matchResultContext.offsetInJoinedTextForCollapsedSelection, matchResultContext.offsetInJoinedTextForCollapsedSelection + 1, scanningContext.textNodeWithOffset.node.getParentOrThrow());
415
458
  }
416
459
  }
417
460
  } // Some Capture Group Details were left lazily unresolved as their calculation
@@ -468,7 +511,7 @@ function removeTextInCaptureGroups(regExCaptureGroupsToDelete, matchResultContex
468
511
  lexical.$setSelection(newSelection);
469
512
  const currentSelection = lexical.$getSelection();
470
513
 
471
- if (currentSelection != null) {
514
+ if (lexical.$isRangeSelection(currentSelection)) {
472
515
  currentSelection.removeText(); // Shift offsets for capture groups which are within the same node
473
516
 
474
517
  if (anchorTextNodeWithOffset.node.getKey() === focusTextNodeWithOffset.node.getKey()) {
@@ -515,7 +558,7 @@ function shiftCaptureGroupOffsets(delta, applyAtOrAfterOffset, node, startingCap
515
558
  }
516
559
  }
517
560
 
518
- function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResultContext) {
561
+ function formatTextInCaptureGroupIndex(formatTypes, captureGroupIndex, matchResultContext) {
519
562
  const regExCaptureGroups = matchResultContext.regExCaptureGroups;
520
563
  const regExCaptureGroupsCount = regExCaptureGroups.length;
521
564
 
@@ -534,8 +577,11 @@ function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResul
534
577
  lexical.$setSelection(newSelection);
535
578
  const currentSelection = lexical.$getSelection();
536
579
 
537
- if (currentSelection != null) {
538
- currentSelection.formatText(formatType);
580
+ if (lexical.$isRangeSelection(currentSelection)) {
581
+ for (let i = 0; i < formatTypes.length; i++) {
582
+ currentSelection.formatText(formatTypes[i]);
583
+ }
584
+
539
585
  const finalSelection = lexical.$createRangeSelection();
540
586
  finalSelection.anchor.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
541
587
  finalSelection.focus.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
@@ -590,7 +636,7 @@ function getCriteriaWithMatchResultContext(autoFormatCriteriaArray, scanningCont
590
636
  }
591
637
 
592
638
  function getTextNodeForAutoFormatting(selection) {
593
- if (selection == null) {
639
+ if (!lexical.$isRangeSelection(selection)) {
594
640
  return null;
595
641
  }
596
642
 
@@ -664,7 +710,7 @@ function getTriggerState(editorState) {
664
710
  editorState.read(() => {
665
711
  const selection = lexical.$getSelection();
666
712
 
667
- if (selection == null || !selection.isCollapsed()) {
713
+ if (!lexical.$isRangeSelection(selection) || !selection.isCollapsed()) {
668
714
  return;
669
715
  }
670
716
 
@@ -4,22 +4,24 @@
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
- var l=require("@lexical/list"),p=require("lexical"),q=require("lexical/CodeNode"),r=require("react"),v=require("@lexical/react/LexicalHorizontalRuleNode"),w=require("lexical/HeadingNode"),A=require("lexical/QuoteNode");function B(g){throw Error(`Minified Lexical error #${g}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- function C(g,f,a,b){g=g.getChildren();const c=g.length;let d=0,e=!1;for(let n=0;n<c&&!(d>f);++n){const h=g[n],m=p.$isTextNode(h);var k=m?h.getTextContent().length:b;k=d+k;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=k)&&p.$isTextNode(h))return{node:h,offset:a-d};d=k;e=m}return null}
9
- const D={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},E={...D,requiresParagraphStart:!0},G=[{...D,nodeTransformationKind:"textBold",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/}],H=[{...E,nodeTransformationKind:"paragraphH1",regEx:/(?:# )/},{...E,nodeTransformationKind:"paragraphH2",regEx:/(?:## )/},{...E,nodeTransformationKind:"paragraphH2",regEx:/(?:### )/},{...E,nodeTransformationKind:"paragraphBlockQuote",regEx:/(?:> )/},{...E,nodeTransformationKind:"paragraphUnorderedList",
10
- regEx:/(?:- )/},{...E,nodeTransformationKind:"paragraphUnorderedList",regEx:/(?:\* )/},{...E,nodeTransformationKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/},{...E,nodeTransformationKind:"paragraphCodeBlock",regEx:/(?:``` )/},{...E,nodeTransformationKind:"horizontalRule",regEx:/(?:\*\*\* )/},{...E,nodeTransformationKind:"horizontalRule",regEx:/(?:--- )/},...G];
11
- function I(g,f,a,b){const c={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};b=g.match(b);if(null!==b&&0<b.length&&(!1===f||0===b.index)&&(!1===a||b.index+b[0].length===g.length)){c.offsetInJoinedTextForCollapsedSelection=g.length;g=b.length;f=b.index;for(a=0;a<g;a++){const d=b[a];c.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return c}return null}
12
- function J(g,f,a,b,c){c.offsetInJoinedTextForCollapsedSelection+=g;0<c.offsetInJoinedTextForCollapsedSelection||B(67);c=c.regExCaptureGroups;const d=c.length;for(b+=1;b<d;b++){const e=c[b];null!=e.anchorTextNodeWithOffset&&e.anchorTextNodeWithOffset.offset>=f&&e.anchorTextNodeWithOffset.node.is(a)&&(e.anchorTextNodeWithOffset.offset+=g);null!=e.focusTextNodeWithOffset&&e.focusTextNodeWithOffset.offset>=f&&e.focusTextNodeWithOffset.node.is(a)&&(e.focusTextNodeWithOffset.offset+=g)}}
13
- function K(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,b=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var c=b;a=null;var d=c.getChildren(),e=f.autoFormatCriteria,k=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=w.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
14
- w.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=w.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=A.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=l.$createListNode("ul");c=l.$createListItemNode();c.append(...d);a.append(c);break;case "paragraphOrderedList":a=parseInt(1<k.regExCaptureGroups.length?k.regExCaptureGroups[k.regExCaptureGroups.length-1].text:"1",10);a=l.$createListNode("ol",a);c=l.$createListItemNode();c.append(...d);
15
- a.append(c);break;case "paragraphCodeBlock":a=null!=f.triggerState&&f.triggerState.isCodeBlock?p.$createParagraphNode():q.$createCodeNode();a.append(...d);break;case "horizontalRule":d=v.$createHorizontalRuleNode(),c.insertBefore(d)}null!==a&&b.replace(a)}else if(a=f.autoFormatCriteria,b=f.matchResultContext,null!=a.nodeTransformationKind)switch(a.nodeTransformationKind){case "textBold":if(6===b.regExCaptureGroups.length){a=f.autoFormatCriteria;d=f.matchResultContext.regExCaptureGroups;c=d.length;
16
- e=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&B(62);k=f.joinedText.length;for(var n=1;n<c;n++){var h=d[n];h.anchorTextNodeWithOffset=C(e,k,h.offsetInParent,1);h.focusTextNodeWithOffset=C(e,k,h.offsetInParent+h.textLength,1);0>h.textLength&&B(63,a.nodeTransformationKind)}b.regExCaptureGroups=d;a=[1,5];d=b.regExCaptureGroups;c=d.length;for(e=a.length-1;0<=e;e--)if(e<c){k=a[e];var m=d[k];h=m.anchorTextNodeWithOffset;n=m.focusTextNodeWithOffset;null!=h&&null!=n&&0<m.textLength&&(m=
17
- p.$createRangeSelection(),m.anchor.set(h.node.getKey(),h.offset,"text"),m.focus.set(n.node.getKey(),n.offset,"text"),p.$setSelection(m),m=p.$getSelection(),null!=m&&(m.removeText(),h.node.getKey()===n.node.getKey()?(m=n.offset-h.offset,0<m||B(64),J(-m,n.offset,h.node,k,b)):(h=n.offset,0<h&&J(-h,h,n.node,k,b))))}a=b.regExCaptureGroups;3<a.length||B(65);c=a[3];d=c.anchorTextNodeWithOffset;a=c.focusTextNodeWithOffset;null!=d&&null!=a&&0<c.textLength&&(c=p.$createRangeSelection(),c.anchor.set(d.node.getKey(),
18
- d.offset,"text"),c.focus.set(a.node.getKey(),a.offset,"text"),p.$setSelection(c),d=p.$getSelection(),null!=d&&(d.formatText("bold"),d=p.$createRangeSelection(),d.anchor.set(a.node.getKey(),a.offset+1,"text"),d.focus.set(a.node.getKey(),a.offset+1,"text"),p.$setSelection(d)));a=f.textNodeWithOffset.node.getParentOrThrow();b=C(a,b.offsetInJoinedTextForCollapsedSelection+1,b.offsetInJoinedTextForCollapsedSelection,1);null!=b&&(a=p.$createRangeSelection(),a.anchor.set(b.node.getKey(),b.offset,"text"),
19
- a.focus.set(b.node.getKey(),b.offset,"text"),p.$setSelection(a))}}},{tag:"history-push"})}
20
- function L(g,f){let a=null;g.read(()=>{var b=p.$getSelection();if(null==b)b=null;else{var c=b.anchor.getNode();b=p.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}if(null!==b){b={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:b,triggerState:f};a:{c=!1===f.isParentAListItemNode?H:G;const m=b.triggerState,M=c.length;for(let x=
21
- 0;x<M;x++){const y=c[x];if(null!=m&&!1===m.isCodeBlock||"paragraphCodeBlock"===y.nodeTransformationKind){var d=y,e=b;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=I(e,!0,!1,d.regEx)):d=null;else b:{if(null==e.joinedText){var k=e.textNodeWithOffset.node.getParentOrThrow();if(p.$isElementNode(k)){if(null==e.joinedText){var n=e,h=e.textNodeWithOffset;let u="";k=k.getChildren();const N=
22
- k.length;for(let z=0;z<N;++z){const t=k[z];if(p.$isTextNode(t)){const F=t.getTextContent();if(t.is(h.node)){h.offset>F.length&&B(50,t.__key);u+=t.getTextContent().substr(0,h.offset);break}else u+=F}else u+="\u0004"}n.joinedText=u}d=I(e.joinedText,!1,!0,d.regEx);break b}B(52,k.__key)}d=null}if(null!=d){c={autoFormatCriteria:y,matchResultContext:d};break a}}}c={autoFormatCriteria:null,matchResultContext:null}}null!==c.autoFormatCriteria&&null!==c.matchResultContext&&(a=b,a.autoFormatCriteria=c.autoFormatCriteria,
23
- a.matchResultContext=c.matchResultContext)}});return a}function O(g){let f=null;g.read(()=>{const a=p.$getSelection();if(null!=a&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),d=null!==c&&l.$isListItemNode(c);f={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:q.$isCodeNode(b),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:p.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return f}
24
- function P(g){r.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var b=g.getEditorState();a=O(b);if(null==a)b=null;else{var c=a,d=f;if(null==c||null==d)b=null;else{var e=c.textContent.length,k=c.anchorOffset-1;b=!1===(!0===c.hasParentNode&&c.isSimpleText&&c.isSelectionCollapsed&&c.nodeKey===d.nodeKey&&c.anchorOffset!==d.anchorOffset&&0<=k&&k+1<=e&&" "===c.textContent.substr(k,1)&&c.textContent!==d.textContent)?null:L(b,c)}}null!=b&&K(g,b);f=a}else f=
7
+ var k=require("@lexical/list"),q=require("lexical"),r=require("lexical/CodeNode"),t=require("react"),u=require("@lexical/react/LexicalHorizontalRuleNode"),x=require("lexical/HeadingNode"),y=require("lexical/QuoteNode");function C(g){throw Error(`Minified Lexical error #${g}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
+ function D(g,f,a,c){g=g.getChildren();const b=g.length;let d=0,e=!1;for(let p=0;p<b&&!(d>f);++p){const m=g[p],n=q.$isTextNode(m);var h=n?m.getTextContent().length:c;h=d+h;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=h)&&q.$isTextNode(m))return{node:m,offset:a-d};d=h;e=n}return null}
9
+ const E={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},F={...E,requiresParagraphStart:!0},H=[{...E,nodeTransformationKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/},{...E,nodeTransformationKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/},{...E,nodeTransformationKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/},{...E,nodeTransformationKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__\s)$/},{...E,nodeTransformationKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>\s)$/},
10
+ {...E,nodeTransformationKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/}],I=[{...F,nodeTransformationKind:"paragraphH1",regEx:/^(?:# )/},{...F,nodeTransformationKind:"paragraphH2",regEx:/^(?:## )/},{...F,nodeTransformationKind:"paragraphH2",regEx:/^(?:### )/},{...F,nodeTransformationKind:"paragraphBlockQuote",regEx:/^(?:> )/},{...F,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:- )/},{...F,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:\* )/},{...F,nodeTransformationKind:"paragraphOrderedList",
11
+ regEx:/^(\d+)\.\s/},{...F,nodeTransformationKind:"paragraphCodeBlock",regEx:/^(```)([a-z]*)( )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/^(?:--- )/},...H];
12
+ function J(g,f,a,c){const b={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};c=g.match(c);if(null!==c&&0<c.length&&(!1===f||0===c.index)&&(!1===a||c.index+c[0].length===g.length)){b.offsetInJoinedTextForCollapsedSelection=g.length;g=c.length;f=c.index;for(a=0;a<g;a++){const d=c[a];b.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return b}return null}
13
+ function K(g,f,a,c,b){b.offsetInJoinedTextForCollapsedSelection+=g;0<b.offsetInJoinedTextForCollapsedSelection||C(67);b=b.regExCaptureGroups;const d=b.length;for(c+=1;c<d;c++){const e=b[c];null!=e.anchorTextNodeWithOffset&&e.anchorTextNodeWithOffset.offset>=f&&e.anchorTextNodeWithOffset.node.is(a)&&(e.anchorTextNodeWithOffset.offset+=g);null!=e.focusTextNodeWithOffset&&e.focusTextNodeWithOffset.offset>=f&&e.focusTextNodeWithOffset.node.is(a)&&(e.focusTextNodeWithOffset.offset+=g)}}
14
+ function L(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,c=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var b=c;a=null;var d=b.getChildren(),e=f.autoFormatCriteria,h=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=x.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
15
+ x.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=x.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=y.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=k.$createListNode("ul");b=k.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=k.$createListNode("ol",a);b=k.$createListItemNode();b.append(...d);
16
+ a.append(b);break;case "paragraphCodeBlock":null!=f.triggerState&&f.triggerState.isCodeBlock?a=q.$createParagraphNode():(a=r.$createCodeNode(),b=3<=h.regExCaptureGroups.length?h.regExCaptureGroups[2].text:null,null!=b&&0<b.length&&a.setLanguage(b));a.append(...d);break;case "horizontalRule":d=u.$createHorizontalRuleNode(),b.insertBefore(d)}null!==a&&c.replace(a)}else if(a=f.autoFormatCriteria,c=f.matchResultContext,null!=a.nodeTransformationKind&&6===c.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;
17
+ switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=["bold","italic"];break a}a=null}if(null!=a){d=[1,5];b=f.autoFormatCriteria;e=f.matchResultContext.regExCaptureGroups;h=e.length;var p=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&C(62);var m=f.joinedText.length;for(var n=1;n<h;n++){var l=e[n];l.anchorTextNodeWithOffset=D(p,m,l.offsetInParent,1);l.focusTextNodeWithOffset=D(p,m,l.offsetInParent+l.textLength,1);0>l.textLength&&
18
+ C(63,b.nodeTransformationKind)}c.regExCaptureGroups=e;if(0<d.length)for(b=c.regExCaptureGroups,e=b.length,h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=b[p],n=l.anchorTextNodeWithOffset,m=l.focusTextNodeWithOffset,null!=n&&null!=m&&0<l.textLength&&(l=q.$createRangeSelection(),l.anchor.set(n.node.getKey(),n.offset,"text"),l.focus.set(m.node.getKey(),m.offset,"text"),q.$setSelection(l),l=q.$getSelection(),q.$isRangeSelection(l)&&(l.removeText(),n.node.getKey()===m.node.getKey()?(l=m.offset-n.offset,0<l||C(64),
19
+ K(-l,m.offset,n.node,p,c)):(n=m.offset,0<n&&K(-n,n,m.node,p,c)))));d=c.regExCaptureGroups;3<d.length||C(65);e=d[3];b=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=b&&null!=d&&0<e.textLength&&(e=q.$createRangeSelection(),e.anchor.set(b.node.getKey(),b.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),q.$setSelection(e),b=q.$getSelection(),q.$isRangeSelection(b))){for(e=0;e<a.length;e++)b.formatText(a[e]);a=q.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+
20
+ 1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");q.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();c=D(a,c.offsetInJoinedTextForCollapsedSelection+1,c.offsetInJoinedTextForCollapsedSelection,1);null!=c&&(a=q.$createRangeSelection(),a.anchor.set(c.node.getKey(),c.offset,"text"),a.focus.set(c.node.getKey(),c.offset,"text"),q.$setSelection(a))}}},{tag:"history-push"})}
21
+ function M(g,f){let a=null;g.read(()=>{var c=q.$getSelection();if(q.$isRangeSelection(c)){var b=c.anchor.getNode();c=q.$isTextNode(b)?{node:b,offset:c.anchor.offset}:null}else c=null;if(null!==c){c={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:c,triggerState:f};a:{b=!1===f.isParentAListItemNode?I:H;const n=c.triggerState,
22
+ l=b.length;for(let z=0;z<l;z++){const A=b[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,e=c;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=J(e,!0,!1,d.regEx)):d=null;else{if(null==e.joinedText){var h=e.textNodeWithOffset.node.getParentOrThrow();if(q.$isElementNode(h)){if(null==e.joinedText){var p=e,m=e.textNodeWithOffset;let w="";h=
23
+ h.getChildren();const N=h.length;for(let B=0;B<N;++B){const v=h[B];if(q.$isTextNode(v)){const G=v.getTextContent();if(v.is(m.node)){m.offset>G.length&&C(50,v.__key);w+=v.getTextContent().substr(0,m.offset);break}else w+=G}else w+="\u0004"}p.joinedText=w}}else C(52,h.__key)}d=J(e.joinedText,!1,!0,d.regEx)}if(null!=d){b={autoFormatCriteria:A,matchResultContext:d};break a}}}b={autoFormatCriteria:null,matchResultContext:null}}null!==b.autoFormatCriteria&&null!==b.matchResultContext&&(a=c,a.autoFormatCriteria=
24
+ b.autoFormatCriteria,a.matchResultContext=b.matchResultContext)}});return a}
25
+ function O(g){let f=null;g.read(()=>{const a=q.$getSelection();if(q.$isRangeSelection(a)&&a.isCollapsed()){var c=a.anchor.getNode(),b=c.getParent(),d=null!==b&&k.$isListItemNode(b);f={anchorOffset:a.anchor.offset,hasParentNode:null!==b,isCodeBlock:r.$isCodeNode(c),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:q.$isTextNode(c)&&c.isSimpleText(),nodeKey:c.getKey(),textContent:c.getTextContent()}}});return f}
26
+ function P(g){t.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var c=g.getEditorState();a=O(c);if(null==a)c=null;else{var b=a,d=f;if(null==b||null==d)c=null;else{var e=b.textContent.length,h=b.anchorOffset-1;c=!1===(!0===b.hasParentNode&&b.isSimpleText&&b.isSelectionCollapsed&&b.nodeKey===d.nodeKey&&b.anchorOffset!==d.anchorOffset&&0<=h&&h+1<=e&&" "===b.textContent.substr(h,1)&&b.textContent!==d.textContent)?null:M(c,b)}}null!=c&&L(g,c);f=a}else f=
25
27
  null})},[g])}module.exports=function(g){P(g)};
@@ -19,11 +19,15 @@ var react = require('react');
19
19
  *
20
20
  *
21
21
  */
22
- function $dfs__DEPRECATED(startingNode, nextNode) {
23
- let node = startingNode;
24
- nextNode(node);
22
+ function $dfs(startingNode, endingNode) {
23
+ const nodes = [];
24
+ const start = (startingNode || lexical.$getRoot()).getLatest();
25
+ const end = endingNode || (lexical.$isElementNode(start) ? start.getLastDescendant() : start);
26
+ let node = start;
27
+
28
+ while (node !== null && !node.is(end)) {
29
+ nodes.push(node);
25
30
 
26
- while (node !== null) {
27
31
  if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) {
28
32
  node = node.getFirstChild();
29
33
  } else {
@@ -40,11 +44,13 @@ function $dfs__DEPRECATED(startingNode, nextNode) {
40
44
  }
41
45
  }
42
46
  }
47
+ }
43
48
 
44
- if (node !== null) {
45
- node = nextNode(node);
46
- }
49
+ if (node !== null && node.is(end)) {
50
+ nodes.push(node);
47
51
  }
52
+
53
+ return nodes;
48
54
  }
49
55
 
50
56
  /**
@@ -158,10 +164,13 @@ function findOffset(text, maxCharacters, strlen) {
158
164
  }
159
165
 
160
166
  function $wrapOverflowedNodes(offset) {
161
- const root = lexical.$getRoot();
167
+ const dfsNodes = $dfs();
168
+ const dfsNodesLength = dfsNodes.length;
162
169
  let accumulatedLength = 0;
163
- let previousNode = root;
164
- $dfs__DEPRECATED(root, node => {
170
+
171
+ for (let i = 0; i < dfsNodesLength; i += 1) {
172
+ const node = dfsNodes[i];
173
+
165
174
  if (OverflowNode.$isOverflowNode(node)) {
166
175
  const previousLength = accumulatedLength;
167
176
  const nextLength = accumulatedLength + node.getTextContentSize();
@@ -173,7 +182,7 @@ function $wrapOverflowedNodes(offset) {
173
182
  $unwrapNode(node);
174
183
  const selection = lexical.$getSelection(); // Restore selection when the overflow children are removed
175
184
 
176
- if (selection !== null && (!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
185
+ if (lexical.$isRangeSelection(selection) && (!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
177
186
  if (lexical.$isTextNode(previousSibling)) {
178
187
  previousSibling.select();
179
188
  } else if (lexical.$isTextNode(nextSibling)) {
@@ -182,8 +191,6 @@ function $wrapOverflowedNodes(offset) {
182
191
  parent.select();
183
192
  }
184
193
  }
185
-
186
- return previousNode;
187
194
  } else if (previousLength < offset) {
188
195
  const descendant = node.getFirstDescendant();
189
196
  const descendantLength = descendant !== null ? descendant.getTextContentSize() : 0;
@@ -195,7 +202,6 @@ function $wrapOverflowedNodes(offset) {
195
202
 
196
203
  if (firstDescendantIsSimpleText || firstDescendantDoesNotOverflow) {
197
204
  $unwrapNode(node);
198
- return previousNode;
199
205
  }
200
206
  }
201
207
  } else if (lexical.$isLeafNode(node)) {
@@ -221,10 +227,7 @@ function $wrapOverflowedNodes(offset) {
221
227
  mergePrevious(overflowNode);
222
228
  }
223
229
  }
224
-
225
- previousNode = node;
226
- return node;
227
- });
230
+ }
228
231
  }
229
232
 
230
233
  function $wrapNode(node) {
@@ -267,7 +270,7 @@ function mergePrevious(overflowNode) {
267
270
 
268
271
  const selection = lexical.$getSelection();
269
272
 
270
- if (selection !== null) {
273
+ if (lexical.$isRangeSelection(selection)) {
271
274
  const anchor = selection.anchor;
272
275
  const anchorNode = anchor.getNode();
273
276
  const focus = selection.focus;
@@ -4,11 +4,11 @@
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
- var k=require("lexical"),l=require("@lexical/react/withSubscriptions"),n=require("lexical/OverflowNode"),p=require("react");function q(a,e){for(e(a);null!==a;){if(k.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let d=null;for(;null===d&&null!==a;)d=a.getNextSibling(),a=null===d?a.getParent():d}null!==a&&(a=e(a))}}function r(){return k.$getRoot().getTextContent()}
8
- function t(a,e,d){var g=Intl.Segmenter;let c=0;var b=0;if("function"===typeof g){a=(new g).segment(a);for(var {segment:f}of a){b+=d(f);if(b>e)break;c+=f.length}}else for(f=Array.from(a),a=f.length,g=0;g<a;g++){const h=f[g];b+=d(h);if(b>e)break;c+=h.length}return c}
9
- function u(a){const e=k.$getRoot();let d=0,g=e;q(e,c=>{if(n.$isOverflowNode(c)){var b=d;if(d+c.getTextContentSize()<=a){var f=c.getParent();b=c.getPreviousSibling();var h=c.getNextSibling();v(c);c=k.$getSelection();null===c||c.anchor.getNode().isAttached()&&c.focus.getNode().isAttached()||(k.$isTextNode(b)?b.select():k.$isTextNode(h)?h.select():null!==f&&f.select());return g}if(b<a&&(f=c.getFirstDescendant(),h=null!==f?f.getTextContentSize():0,b+=h,f=k.$isTextNode(f)&&f.isSimpleText(),b=b<=a,f||b))return v(c),
10
- g}else k.$isLeafNode(c)&&(b=d,d+=c.getTextContentSize(),d>a&&!n.$isOverflowNode(c.getParent())&&(f=k.$getSelection(),b<a&&k.$isTextNode(c)&&c.isSimpleText()?([,b]=c.splitText(a-b),b=w(b)):b=w(c),null!==f&&k.$setSelection(f),x(b)));return g=c})}function w(a){const e=n.$createOverflowNode();a.insertBefore(e);e.append(a);return e}function v(a){const e=a.getChildren(),d=e.length;for(let g=0;g<d;g++)a.insertBefore(e[g]);a.remove();return 0<d?e[d-1]:null}
11
- function x(a){const e=a.getPreviousSibling();if(n.$isOverflowNode(e)){var d=a.getFirstChild(),g=e.getChildren(),c=g.length;if(null===d)a.append(...g);else for(var b=0;b<c;b++)d.insertBefore(g[b]);b=k.$getSelection();if(null!==b){d=b.anchor;g=d.getNode();b=b.focus;const f=d.getNode();g.is(e)?d.set(a.getKey(),d.offset,"element"):g.is(a)&&d.set(a.getKey(),c+d.offset,"element");f.is(e)?b.set(a.getKey(),b.offset,"element"):f.is(a)&&b.set(a.getKey(),c+b.offset,"element")}e.remove()}}
12
- exports.mergePrevious=x;
13
- exports.useCharacterLimit=function(a,e,d=Object.freeze({})){const {strlen:g=b=>b.length,remainingCharacters:c=()=>{}}=d;p.useEffect(()=>{if(!a.hasNodes([n.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[a]);p.useEffect(()=>{let b=a.getEditorState().read(r),f=0;return l(a.addListener("textcontent",h=>{b=h}),a.addListener("update",({dirtyLeaves:h})=>{var m=a.isComposing();
14
- h=0<h.size;if(!m&&h){m=g(b);h=m>e||null!==f&&f>e;c(e-m);if(null===f||h){const y=t(b,e,g);a.update(()=>{u(y)},{tag:"history-merge"})}f=m}}))},[a,e,c,g])};
7
+ var h=require("lexical"),t=require("@lexical/react/withSubscriptions"),y=require("lexical/OverflowNode"),z=require("react");function A(){return h.$getRoot().getTextContent()}function B(a,e,g){var f=Intl.Segmenter;let n=0;var c=0;if("function"===typeof f){a=(new f).segment(a);for(var {segment:k}of a){c+=g(k);if(c>e)break;n+=k.length}}else for(k=Array.from(a),a=k.length,f=0;f<a;f++){const p=k[f];c+=g(p);if(c>e)break;n+=p.length}return n}
8
+ function C(a){const e=y.$createOverflowNode();a.insertBefore(e);e.append(a);return e}function D(a){const e=a.getChildren(),g=e.length;for(let f=0;f<g;f++)a.insertBefore(e[f]);a.remove();return 0<g?e[g-1]:null}
9
+ function E(a){const e=a.getPreviousSibling();if(y.$isOverflowNode(e)){var g=a.getFirstChild(),f=e.getChildren(),n=f.length;if(null===g)a.append(...f);else for(var c=0;c<n;c++)g.insertBefore(f[c]);c=h.$getSelection();if(h.$isRangeSelection(c)){g=c.anchor;f=g.getNode();c=c.focus;const k=g.getNode();f.is(e)?g.set(a.getKey(),g.offset,"element"):f.is(a)&&g.set(a.getKey(),n+g.offset,"element");k.is(e)?c.set(a.getKey(),c.offset,"element"):k.is(a)&&c.set(a.getKey(),n+c.offset,"element")}e.remove()}}
10
+ exports.mergePrevious=E;
11
+ exports.useCharacterLimit=function(a,e,g=Object.freeze({})){const {strlen:f=c=>c.length,remainingCharacters:n=()=>{}}=g;z.useEffect(()=>{if(!a.hasNodes([y.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[a]);z.useEffect(()=>{let c=a.getEditorState().read(A),k=0;return t(a.addListener("textcontent",p=>{c=p}),a.addListener("update",({dirtyLeaves:p})=>{var u=a.isComposing();
12
+ p=0<p.size;if(!u&&p){u=f(c);p=u>e||null!==k&&k>e;n(e-u);if(null===k||p){const r=B(c,e,f);a.update(()=>{const v=[];for(var d=h.$getRoot().getLatest(),w=h.$isElementNode(d)?d.getLastDescendant():d;null!==d&&!d.is(w);)if(v.push(d),h.$isElementNode(d)&&0<d.getChildrenSize())d=d.getFirstChild();else for(var q=null;null===q&&null!==d;)q=d.getNextSibling(),d=null===q?d.getParent():q;null!==d&&d.is(w)&&v.push(d);w=v.length;d=0;for(q=0;q<w;q+=1){var b=v[q];if(y.$isOverflowNode(b)){var m=d;if(d+b.getTextContentSize()<=
13
+ r){var l=b.getParent();m=b.getPreviousSibling();var x=b.getNextSibling();D(b);b=h.$getSelection();!h.$isRangeSelection(b)||b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()||(h.$isTextNode(m)?m.select():h.$isTextNode(x)?x.select():null!==l&&l.select())}else m<r&&(l=b.getFirstDescendant(),x=null!==l?l.getTextContentSize():0,m+=x,l=h.$isTextNode(l)&&l.isSimpleText(),m=m<=r,(l||m)&&D(b))}else h.$isLeafNode(b)&&(m=d,d+=b.getTextContentSize(),d>r&&!y.$isOverflowNode(b.getParent())&&(l=h.$getSelection(),
14
+ m<r&&h.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(r-m),b=C(b)):b=C(b),null!==l&&h.$setSelection(l),E(b)))}},{tag:"history-merge"})}k=u}}))},[a,e,n,f])};
@@ -17,35 +17,11 @@ var react = require('react');
17
17
  *
18
18
  *
19
19
  */
20
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
21
-
22
- /**
23
- * Copyright (c) Meta Platforms, Inc. and affiliates.
24
- *
25
- * This source code is licensed under the MIT license found in the
26
- * LICENSE file in the root directory of this source tree.
27
- *
28
- *
29
- */
30
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
31
- var useLayoutEffect = useLayoutEffectImpl;
32
-
33
- /**
34
- * Copyright (c) Meta Platforms, Inc. and affiliates.
35
- *
36
- * This source code is licensed under the MIT license found in the
37
- * LICENSE file in the root directory of this source tree.
38
- *
39
- *
40
- */
41
- function useLexicalEditor(editor, onError) {
20
+ function useLexicalEditor(editor) {
42
21
  const showPlaceholder = useLexicalCanShowPlaceholder(editor);
43
22
  const rootElementRef = react.useCallback(rootElement => {
44
23
  editor.setRootElement(rootElement);
45
24
  }, [editor]);
46
- useLayoutEffect(() => {
47
- return editor.addListener('error', onError);
48
- }, [editor, onError]);
49
25
  return [rootElementRef, showPlaceholder];
50
26
  }
51
27
 
@@ -4,4 +4,4 @@
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
- var b=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;module.exports=function(a,c){const f=b(a),h=d.useCallback(g=>{a.setRootElement(g)},[a]);e(()=>a.addListener("error",c),[a,c]);return[h,f]};
7
+ var b=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),c=require("react");module.exports=function(a){const d=b(a);return[c.useCallback(e=>{a.setRootElement(e)},[a]),d]};
@@ -73,7 +73,7 @@ function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyEl
73
73
  return COMPOSING_CHARACTER;
74
74
  }
75
75
 
76
- if (nextSelection === null || prevSelection === null || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
76
+ if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
77
77
  return OTHER;
78
78
  }
79
79
 
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var n=require("@lexical/react/withSubscriptions"),t=require("lexical"),v=require("react");
8
- function w(b,d,k,a,h){if(null===b||0===k.size&&0===a.size)return 0;var g=d._selection,c=b._selection;if(h)return 1;if(null===g||null===c||!c.isCollapsed()||!g.isCollapsed())return 0;var e=Array.from(k);a=Array.from(a);k=d._nodeMap;h=[];for(var f=0;f<e.length;f++){const l=k.get(e[f]);void 0!==l&&h.push(l)}for(e=0;e<a.length;e++)a[e][1]&&(f=k.get(a[e][0]),void 0===f||t.$isRootNode(f)||h.push(f));if(0===h.length)return 0;if(1<h.length)return a=d._nodeMap,d=a.get(g.anchor.key),c=a.get(c.anchor.key),d&&
9
- c&&!b._nodeMap.has(d.__key)&&t.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=h[0];b=b._nodeMap.get(d.__key);if(!t.$isTextNode(b)||!t.$isTextNode(d)||b.__mode!==d.__mode)return 0;b=b.__text;d=d.__text;if(b===d)return 0;g=g.anchor;c=c.anchor;if(g.key!==c.key||"text"!==g.type)return 0;g=g.offset;c=c.offset;b=d.length-b.length;return 1===b&&c===g-1?2:-1===b&&c===g+1?3:-1===b&&c===g?4:0}
8
+ function w(b,d,k,a,h){if(null===b||0===k.size&&0===a.size)return 0;var g=d._selection,c=b._selection;if(h)return 1;if(!(t.$isRangeSelection(g)&&t.$isRangeSelection(c)&&c.isCollapsed()&&g.isCollapsed()))return 0;var e=Array.from(k);a=Array.from(a);k=d._nodeMap;h=[];for(var f=0;f<e.length;f++){const l=k.get(e[f]);void 0!==l&&h.push(l)}for(e=0;e<a.length;e++)a[e][1]&&(f=k.get(a[e][0]),void 0===f||t.$isRootNode(f)||h.push(f));if(0===h.length)return 0;if(1<h.length)return a=d._nodeMap,d=a.get(g.anchor.key),
9
+ c=a.get(c.anchor.key),d&&c&&!b._nodeMap.has(d.__key)&&t.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=h[0];b=b._nodeMap.get(d.__key);if(!t.$isTextNode(b)||!t.$isTextNode(d)||b.__mode!==d.__mode)return 0;b=b.__text;d=d.__text;if(b===d)return 0;g=g.anchor;c=c.anchor;if(g.key!==c.key||"text"!==g.type)return 0;g=g.offset;c=c.offset;b=d.length-b.length;return 1===b&&c===g-1?2:-1===b&&c===g+1?3:-1===b&&c===g?4:0}
10
10
  function x(b,d){let k=Date.now(),a=0;return(h,g,c,e,f,l)=>{const p=Date.now();if(l.has("historic"))return a=0,k=p,2;const m=w(h,g,e,f,b.isComposing()),u=(()=>{const r=l.has("history-push");if(!r&&l.has("history-merge"))return 0;if(null===h)return 1;var q=g._selection;const z=h._selection;if(!(0<e.size||0<f.size))return null===z&&null!==q?0:2;q=null===c||c.editor===b;return!1===r&&0!==m&&m===a&&p<k+d&&q?0:1})();k=p;a=m;return u}}
11
11
  function y(b,d,k=1E3){const a=v.useMemo(()=>d||A(),[d]),h=v.useCallback(()=>{a.undoStack=[];a.redoStack=[];a.current=null},[a]);v.useEffect(()=>{const g=x(b,k);return n(b.addListener("command",c=>{switch(c){case "undo":c=a.redoStack;var e=a.undoStack;if(0!==e.length){var f=a.current;const l=e.pop();null!==f&&(c.push(f),b.execCommand("canRedo",!0));0===e.length&&b.execCommand("canUndo",!1);a.current=l;l.editor.setEditorState(l.editorState.clone(l.undoSelection),{tag:"historic"})}return!0;case "redo":return c=
12
12
  a.redoStack,e=a.undoStack,0!==c.length&&(f=a.current,null!==f&&(e.push(f),b.execCommand("canUndo",!0)),e=c.pop(),0===c.length&&b.execCommand("canRedo",!1),a.current=e,e.editor.setEditorState(e.editorState,{tag:"historic"})),!0;case "clearEditor":return h(),!1;case "clearHistory":return h(),!0;default:return!1}},0),b.addListener("update",({editorState:c,prevEditorState:e,dirtyLeaves:f,dirtyElements:l,tags:p})=>{const m=a.current,u=a.redoStack,r=a.undoStack,q=null===m?null:m.editorState;if(null===m||
@@ -42,6 +42,12 @@ function useList(editor) {
42
42
  } else if (type === 'removeList') {
43
43
  list.removeList(editor);
44
44
  return true;
45
+ } else if (type === 'insertParagraph') {
46
+ const hasHandledInsertParagraph = list.$handleListInsertParagraph();
47
+
48
+ if (hasHandledInsertParagraph) {
49
+ return true;
50
+ }
45
51
  }
46
52
 
47
53
  return false;