@lexical/react 0.1.10 → 0.1.11

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 (59) hide show
  1. package/DEPRECATED_useLexicalAutoFormatter.dev.js +69 -28
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -18
  3. package/DEPRECATED_useLexicalCharacterLimit.dev.js +20 -17
  4. package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
  5. package/DEPRECATED_useLexicalList.dev.js +6 -0
  6. package/DEPRECATED_useLexicalList.prod.js +1 -1
  7. package/DEPRECATED_useLexicalPlainText.dev.js +61 -58
  8. package/DEPRECATED_useLexicalPlainText.prod.js +15 -15
  9. package/DEPRECATED_useLexicalRichText.dev.js +64 -61
  10. package/DEPRECATED_useLexicalRichText.prod.js +24 -25
  11. package/LexicalAutoFormatterPlugin.dev.js +69 -28
  12. package/LexicalAutoFormatterPlugin.js.flow +10 -0
  13. package/LexicalAutoFormatterPlugin.prod.js +20 -19
  14. package/LexicalAutoLinkPlugin.js.flow +23 -0
  15. package/LexicalCharacterLimitPlugin.dev.js +20 -17
  16. package/LexicalCharacterLimitPlugin.js.flow +12 -0
  17. package/LexicalCharacterLimitPlugin.prod.js +9 -8
  18. package/LexicalClearEditorPlugin.dev.js +52 -0
  19. package/LexicalClearEditorPlugin.js +9 -0
  20. package/LexicalClearEditorPlugin.js.flow +14 -0
  21. package/LexicalClearEditorPlugin.prod.js +7 -0
  22. package/LexicalCollaborationPlugin.dev.js +21 -11
  23. package/LexicalCollaborationPlugin.js.flow +55 -0
  24. package/LexicalCollaborationPlugin.prod.js +7 -7
  25. package/LexicalComposer.dev.js +7 -0
  26. package/LexicalComposer.js.flow +23 -0
  27. package/LexicalComposer.prod.js +3 -2
  28. package/LexicalComposerContext.js.flow +27 -0
  29. package/LexicalContentEditable.dev.js +14 -8
  30. package/LexicalContentEditable.js.flow +35 -0
  31. package/LexicalContentEditable.prod.js +3 -3
  32. package/LexicalHashtagPlugin.js.flow +20 -0
  33. package/LexicalHistoryPlugin.js.flow +34 -0
  34. package/LexicalHorizontalRuleNode.js.flow +25 -0
  35. package/LexicalLinkPlugin.js.flow +10 -0
  36. package/LexicalListPlugin.dev.js +6 -0
  37. package/LexicalListPlugin.js.flow +10 -0
  38. package/LexicalListPlugin.prod.js +2 -2
  39. package/LexicalNestedComposer.js.flow +21 -0
  40. package/LexicalOnChangePlugin.js.flow +14 -0
  41. package/LexicalPlainTextPlugin.dev.js +64 -60
  42. package/LexicalPlainTextPlugin.js.flow +18 -0
  43. package/LexicalPlainTextPlugin.prod.js +12 -12
  44. package/LexicalRichTextPlugin.dev.js +65 -61
  45. package/LexicalRichTextPlugin.js.flow +18 -0
  46. package/LexicalRichTextPlugin.prod.js +19 -20
  47. package/LexicalTablePlugin.dev.js +22 -0
  48. package/LexicalTablePlugin.js.flow +10 -0
  49. package/LexicalTablePlugin.prod.js +4 -3
  50. package/LexicalTreeView.js.flow +19 -0
  51. package/README.md +0 -1
  52. package/package.json +5 -5
  53. package/useLexicalDecoratorMap.js.flow +16 -0
  54. package/useLexicalIsTextContentEmpty.js.flow +15 -0
  55. package/useLexicalNodeSelection.js.flow +14 -0
  56. package/withSubscriptions.js.flow +13 -0
  57. package/LexicalBootstrapPlugin.dev.js +0 -122
  58. package/LexicalBootstrapPlugin.js +0 -9
  59. package/LexicalBootstrapPlugin.prod.js +0 -8
@@ -170,14 +170,33 @@ const markdownHorizontalRuleUsingDashes = { ...paragraphStartBase,
170
170
  nodeTransformationKind: 'horizontalRule',
171
171
  regEx: /(?:--- )/
172
172
  };
173
+ const markdownItalic = { ...autoFormatBase,
174
+ nodeTransformationKind: 'italic',
175
+ regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/
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) {
@@ -390,28 +406,50 @@ function transformTextNodeForParagraphs(scanningContext) {
390
406
  }
391
407
  }
392
408
 
409
+ function getTextFormatType(nodeTransformationKind) {
410
+ switch (nodeTransformationKind) {
411
+ case 'italic':
412
+ case 'bold':
413
+ case 'underline':
414
+ case 'strikethrough':
415
+ return [nodeTransformationKind];
416
+
417
+ case 'bold_italic':
418
+ {
419
+ return ['bold', 'italic'];
420
+ }
421
+ }
422
+
423
+ return null;
424
+ }
425
+
393
426
  function transformTextNodeForText(scanningContext) {
394
427
  const autoFormatCriteria = scanningContext.autoFormatCriteria;
395
428
  const matchResultContext = scanningContext.matchResultContext;
396
429
 
397
430
  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
- }
431
+ if (matchResultContext.regExCaptureGroups.length !== 6) {
432
+ // For BIUS and other formatts which have a pattern + text + pattern,
433
+ // the expected reg ex pattern should have 6 groups.
434
+ // If it does not, then break and fail silently.
435
+ // e2e tests validate the regEx pattern.
436
+ return;
437
+ }
407
438
 
408
- matchResultContext.regExCaptureGroups = getCaptureGroupsByResolvingAllDetails(scanningContext); // Remove unwanted text in reg ex pattern.
439
+ const formatting = getTextFormatType(autoFormatCriteria.nodeTransformationKind);
409
440
 
410
- removeTextInCaptureGroups([1, 5], matchResultContext);
411
- formatTextInCaptureGroupIndex('bold', 3, matchResultContext);
412
- makeCollapsedSelectionAtOffsetInJoinedText(matchResultContext.offsetInJoinedTextForCollapsedSelection, matchResultContext.offsetInJoinedTextForCollapsedSelection + 1, scanningContext.textNodeWithOffset.node.getParentOrThrow());
413
- break;
414
- }
441
+ if (formatting != null) {
442
+ const captureGroupsToDelete = [1, 5];
443
+ const formatCaptureGroup = 3;
444
+ matchResultContext.regExCaptureGroups = getCaptureGroupsByResolvingAllDetails(scanningContext);
445
+
446
+ if (captureGroupsToDelete.length > 0) {
447
+ // Remove unwanted text in reg ex pattern.
448
+ removeTextInCaptureGroups(captureGroupsToDelete, matchResultContext);
449
+ }
450
+
451
+ formatTextInCaptureGroupIndex(formatting, formatCaptureGroup, matchResultContext);
452
+ makeCollapsedSelectionAtOffsetInJoinedText(matchResultContext.offsetInJoinedTextForCollapsedSelection, matchResultContext.offsetInJoinedTextForCollapsedSelection + 1, scanningContext.textNodeWithOffset.node.getParentOrThrow());
415
453
  }
416
454
  }
417
455
  } // Some Capture Group Details were left lazily unresolved as their calculation
@@ -515,7 +553,7 @@ function shiftCaptureGroupOffsets(delta, applyAtOrAfterOffset, node, startingCap
515
553
  }
516
554
  }
517
555
 
518
- function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResultContext) {
556
+ function formatTextInCaptureGroupIndex(formatTypes, captureGroupIndex, matchResultContext) {
519
557
  const regExCaptureGroups = matchResultContext.regExCaptureGroups;
520
558
  const regExCaptureGroupsCount = regExCaptureGroups.length;
521
559
 
@@ -535,7 +573,10 @@ function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResul
535
573
  const currentSelection = lexical.$getSelection();
536
574
 
537
575
  if (lexical.$isRangeSelection(currentSelection)) {
538
- currentSelection.formatText(formatType);
576
+ for (let i = 0; i < formatTypes.length; i++) {
577
+ currentSelection.formatText(formatTypes[i]);
578
+ }
579
+
539
580
  const finalSelection = lexical.$createRangeSelection();
540
581
  finalSelection.anchor.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
541
582
  finalSelection.focus.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
@@ -4,23 +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(),p.$isRangeSelection(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(),p.$isRangeSelection(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,
19
- "text"),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(p.$isRangeSelection(b)){var c=b.anchor.getNode();b=p.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}else b=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,
21
- M=c.length;for(let x=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="";
22
- k=k.getChildren();const N=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=
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,b){g=g.getChildren();const c=g.length;let d=0,e=!1;for(let p=0;p<c&&!(d>f);++p){const m=g[p],n=q.$isTextNode(m);var h=n?m.getTextContent().length:b;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:/(?:``` )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/(?:\*\*\* )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/(?:--- )/},...H];
12
+ function J(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}
13
+ function K(g,f,a,b,c){c.offsetInJoinedTextForCollapsedSelection+=g;0<c.offsetInJoinedTextForCollapsedSelection||C(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)}}
14
+ function L(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,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");c=k.$createListItemNode();c.append(...d);a.append(c);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=k.$createListNode("ol",a);c=k.$createListItemNode();c.append(...d);
16
+ a.append(c);break;case "paragraphCodeBlock":a=null!=f.triggerState&&f.triggerState.isCodeBlock?q.$createParagraphNode():r.$createCodeNode();a.append(...d);break;case "horizontalRule":d=u.$createHorizontalRuleNode(),c.insertBefore(d)}null!==a&&b.replace(a)}else if(a=f.autoFormatCriteria,b=f.matchResultContext,null!=a.nodeTransformationKind&&6===b.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=
17
+ ["bold","italic"];break a}a=null}if(null!=a){d=[1,5];c=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&&C(63,c.nodeTransformationKind)}b.regExCaptureGroups=e;if(0<d.length)for(c=b.regExCaptureGroups,e=c.length,
18
+ h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=c[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),K(-l,m.offset,n.node,p,b)):(n=m.offset,0<n&&K(-n,n,m.node,p,b)))));d=b.regExCaptureGroups;3<d.length||C(65);
19
+ e=d[3];c=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=c&&null!=d&&0<e.textLength&&(e=q.$createRangeSelection(),e.anchor.set(c.node.getKey(),c.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),q.$setSelection(e),c=q.$getSelection(),q.$isRangeSelection(c))){for(e=0;e<a.length;e++)c.formatText(a[e]);a=q.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");q.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();
20
+ b=D(a,b.offsetInJoinedTextForCollapsedSelection+1,b.offsetInJoinedTextForCollapsedSelection,1);null!=b&&(a=q.$createRangeSelection(),a.anchor.set(b.node.getKey(),b.offset,"text"),a.focus.set(b.node.getKey(),b.offset,"text"),q.$setSelection(a))}}},{tag:"history-push"})}
21
+ function M(g,f){let a=null;g.read(()=>{var b=q.$getSelection();if(q.$isRangeSelection(b)){var c=b.anchor.getNode();b=q.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}else b=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?I:H;const n=b.triggerState,
22
+ l=c.length;for(let z=0;z<l;z++){const A=c[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,e=b;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){c={autoFormatCriteria:A,matchResultContext:d};break a}}}c={autoFormatCriteria:null,matchResultContext:null}}null!==c.autoFormatCriteria&&null!==c.matchResultContext&&(a=b,a.autoFormatCriteria=
23
24
  c.autoFormatCriteria,a.matchResultContext=c.matchResultContext)}});return a}
24
- function O(g){let f=null;g.read(()=>{const a=p.$getSelection();if(p.$isRangeSelection(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}
25
- 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=
25
+ function O(g){let f=null;g.read(()=>{const a=q.$getSelection();if(q.$isRangeSelection(a)&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),d=null!==c&&k.$isListItemNode(c);f={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:r.$isCodeNode(b),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:q.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return f}
26
+ function P(g){t.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,h=c.anchorOffset-1;b=!1===(!0===c.hasParentNode&&c.isSimpleText&&c.isSelectionCollapsed&&c.nodeKey===d.nodeKey&&c.anchorOffset!==d.anchorOffset&&0<=h&&h+1<=e&&" "===c.textContent.substr(h,1)&&c.textContent!==d.textContent)?null:M(b,c)}}null!=b&&L(g,b);f=a}else f=
26
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();
@@ -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) {
@@ -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();!k.$isRangeSelection(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(),
10
- b=b<=a,f||b))return v(c),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(k.$isRangeSelection(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])};
@@ -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;
@@ -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/list"),d=require("react");function e(a){d.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(b.indentList())return!0}else if("outdentContent"===c){if(b.outdentList())return!0}else{if("insertOrderedList"===c)return b.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return b.insertList(a,"ul"),!0;if("removeList"===c)return b.removeList(a),!0}return!1},1),[a])}module.exports=function(a){e(a)};
7
+ var b=require("@lexical/list"),d=require("react");function e(a){d.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(b.indentList())return!0}else if("outdentContent"===c){if(b.outdentList())return!0}else{if("insertOrderedList"===c)return b.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return b.insertList(a,"ul"),!0;if("removeList"===c)return b.removeList(a),!0;if("insertParagraph"===c&&b.$handleListInsertParagraph())return!0}return!1},1),[a])}module.exports=function(a){e(a)};
@@ -360,55 +360,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
360
360
  $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
361
361
  }
362
362
 
363
- /**
364
- * Copyright (c) Meta Platforms, Inc. and affiliates.
365
- *
366
- * This source code is licensed under the MIT license found in the
367
- * LICENSE file in the root directory of this source tree.
368
- *
369
- *
370
- */
371
- function resolveElement(element, isBackward, focusOffset) {
372
- const parent = element.getParent();
373
- let offset = focusOffset;
374
- let block = element;
375
-
376
- if (parent !== null) {
377
- if (isBackward && focusOffset === 0) {
378
- offset = block.getIndexWithinParent();
379
- block = parent;
380
- } else if (!isBackward && focusOffset === block.getChildrenSize()) {
381
- offset = block.getIndexWithinParent() + 1;
382
- block = parent;
383
- }
384
- }
385
-
386
- return block.getChildAtIndex(isBackward ? offset - 1 : offset);
387
- }
388
-
389
- function getPossibleDecoratorNode(focus, isBackward) {
390
- const focusOffset = focus.offset;
391
-
392
- if (focus.type === 'element') {
393
- const block = focus.getNode();
394
- return resolveElement(block, isBackward, focusOffset);
395
- } else {
396
- const focusNode = focus.getNode();
397
-
398
- if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
399
- const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
400
-
401
- if (possibleNode === null) {
402
- return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
403
- }
404
-
405
- return possibleNode;
406
- }
407
- }
408
-
409
- return null;
410
- }
411
-
412
363
  /**
413
364
  * Copyright (c) Meta Platforms, Inc. and affiliates.
414
365
  *
@@ -425,7 +376,7 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
425
376
  }
426
377
  }
427
378
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
428
- const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
379
+ const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
429
380
  return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
430
381
  }
431
382
  function onPasteForPlainText(event, editor) {
@@ -478,6 +429,62 @@ function onCopyForPlainText(event, editor) {
478
429
  });
479
430
  }
480
431
 
432
+ /**
433
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
434
+ *
435
+ * This source code is licensed under the MIT license found in the
436
+ * LICENSE file in the root directory of this source tree.
437
+ *
438
+ *
439
+ */
440
+ // Convoluted logic to make this work with Flow. Order matters.
441
+ const options = {
442
+ tag: 'history-merge'
443
+ };
444
+ const setEditorOptions = options;
445
+ const updateOptions = options;
446
+ function initializeEditor(editor, initialEditorState) {
447
+ if (initialEditorState === null) {
448
+ return;
449
+ } else if (initialEditorState === undefined) {
450
+ editor.update(() => {
451
+ const root = lexical.$getRoot();
452
+ const firstChild = root.getFirstChild();
453
+
454
+ if (firstChild === null) {
455
+ const paragraph = lexical.$createParagraphNode();
456
+ root.append(paragraph);
457
+ const activeElement = document.activeElement;
458
+
459
+ if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
460
+ paragraph.select();
461
+ }
462
+ }
463
+ }, updateOptions);
464
+ } else if (initialEditorState !== null) {
465
+ switch (typeof initialEditorState) {
466
+ case 'string':
467
+ {
468
+ const parsedEditorState = editor.parseEditorState(initialEditorState);
469
+ editor.setEditorState(parsedEditorState, setEditorOptions);
470
+ break;
471
+ }
472
+
473
+ case 'object':
474
+ {
475
+ editor.setEditorState(initialEditorState, setEditorOptions);
476
+ break;
477
+ }
478
+
479
+ case 'function':
480
+ {
481
+ editor.update(initialEditorState, updateOptions);
482
+ break;
483
+ }
484
+ }
485
+ }
486
+ }
487
+
481
488
  /**
482
489
  * Copyright (c) Meta Platforms, Inc. and affiliates.
483
490
  *
@@ -574,7 +581,7 @@ function useLexicalDragonSupport(editor) {
574
581
  *
575
582
  *
576
583
  */
577
- function usePlainTextSetup(editor) {
584
+ function usePlainTextSetup(editor, initialEditorState) {
578
585
  react.useEffect(() => {
579
586
  const removeListener = editor.addListener('command', (type, payload) => {
580
587
  const selection = lexical.$getSelection();
@@ -734,13 +741,9 @@ function usePlainTextSetup(editor) {
734
741
 
735
742
  return false;
736
743
  }, 0);
737
- const bootstrapCommandHandled = editor.execCommand('bootstrapEditor');
738
-
739
- if (!bootstrapCommandHandled) {
740
- console.warn('bootstrapEditor command was not handled. Did you forget to add <BootstrapPlugin />?');
741
- }
742
-
743
- return removeListener;
744
+ initializeEditor(editor, initialEditorState);
745
+ return removeListener; // We only do this for init
746
+ // eslint-disable-next-line react-hooks/exhaustive-deps
744
747
  }, [editor]);
745
748
  useLexicalDragonSupport(editor);
746
749
  }
@@ -4,18 +4,18 @@
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/react/withSubscriptions"),u=require("lexical"),v=require("react");
8
- function w(a,d,c,b,e){if(null===a||0===c.size&&0===b.size)return 0;var g=d._selection,f=a._selection;if(e)return 1;if(!(u.$isRangeSelection(g)&&u.$isRangeSelection(f)&&f.isCollapsed()&&g.isCollapsed()))return 0;var h=Array.from(c);b=Array.from(b);c=d._nodeMap;e=[];for(var k=0;k<h.length;k++){const n=c.get(h[k]);void 0!==n&&e.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(k=c.get(b[h][0]),void 0===k||u.$isRootNode(k)||e.push(k));if(0===e.length)return 0;if(1<e.length)return b=d._nodeMap,d=b.get(g.anchor.key),
9
- f=b.get(f.anchor.key),d&&f&&!a._nodeMap.has(d.__key)&&u.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=e[0];a=a._nodeMap.get(d.__key);if(!u.$isTextNode(a)||!u.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;g=g.anchor;f=f.anchor;if(g.key!==f.key||"text"!==g.type)return 0;g=g.offset;f=f.offset;a=d.length-a.length;return 1===a&&f===g-1?2:-1===a&&f===g+1?3:-1===a&&f===g?4:0}
10
- function x(a,d){let c=Date.now(),b=0;return(e,g,f,h,k,n)=>{const t=Date.now();if(n.has("historic"))return b=0,c=t,2;const m=w(e,g,h,k,a.isComposing()),r=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===e)return 1;var p=g._selection;const D=e._selection;if(!(0<h.size||0<k.size))return null===D&&null!==p?0:2;p=null===f||f.editor===a;return!1===q&&0!==m&&m===b&&t<c+d&&p?0:1})();c=t;b=m;return r}}
11
- function y(a,d,c=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),e=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const g=x(a,c);return l(a.addListener("command",f=>{switch(f){case "undo":f=b.redoStack;var h=b.undoStack;if(0!==h.length){var k=b.current;const n=h.pop();null!==k&&(f.push(k),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
12
- {tag:"historic"})}return!0;case "redo":return f=b.redoStack,h=b.undoStack,0!==f.length&&(k=b.current,null!==k&&(h.push(k),a.execCommand("canUndo",!0)),h=f.pop(),0===f.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return e(),!1;case "clearHistory":return e(),!0;default:return!1}},0),a.addListener("update",({editorState:f,prevEditorState:h,dirtyLeaves:k,dirtyElements:n,tags:t})=>{const m=b.current,r=b.redoStack,q=b.undoStack,
13
- p=null===m?null:m.editorState;if(null===m||f!==p){k=g(h,f,m,k,n,t);if(1===k)0!==r.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;b.current={editor:a,editorState:f}}}))},[e,c,a,b])}function z(a,d,c=1E3){return y(a,d,c)}function A(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
14
- function B(a,d,c){const b=a.getParent();let e=c;null!==b&&(d&&0===c?(e=a.getIndexWithinParent(),a=b):d||c!==a.getChildrenSize()||(e=a.getIndexWithinParent()+1,a=b));return a.getChildAtIndex(d?e-1:e)}function C(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}
15
- function E(a,d){var c=a.focus;a=c.offset;"element"===c.type?(c=c.getNode(),d=B(c,d,a)):(c=c.getNode(),d&&0===a||!d&&a===c.getTextContentSize()?(a=d?c.getPreviousSibling():c.getNextSibling(),d=null===a?B(c.getParentOrThrow(),d,c.getIndexWithinParent()+(d?0:1)):a):d=null);return u.$isDecoratorNode(d)&&!d.isIsolated()}function F(a,d){a.preventDefault();d.update(()=>{const c=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(c)&&C(b,c)})}
16
- function G(a,d){H(a,d);d.update(()=>{const c=u.$getSelection();u.$isRangeSelection(c)&&c.removeText()})}function H(a,d){a.preventDefault();d.update(()=>{const c=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=c){var e=window.getSelection();if(!e.isCollapsed){var g=e.getRangeAt(0);g&&(e=document.createElement("div"),g=g.cloneContents(),e.appendChild(g),c.setData("text/html",e.innerHTML));c.setData("text/plain",b.getTextContent())}}})}
17
- function I(a){v.useEffect(()=>{const d=c=>{var b=a.getRootElement();if(document.activeElement===b&&(b=c.data,"string"===typeof b)){try{var e=JSON.parse(b)}catch(g){return}if(e&&"nuanria_messaging"===e.protocol&&"request"===e.type&&(e=e.payload)&&"makeChanges"===e.functionId&&(e=e.args)){const [g,f,h,k,n]=e;a.update(()=>{const t=u.$getSelection();if(u.$isRangeSelection(t)){var m=t.anchor;let r=m.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=g&&0<=f&&(q=g,p=g+f,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
18
- h)t.insertRawText(h),r=m.getNode();u.$isTextNode(r)&&(q=k,p=k+n,m=r.getTextContentSize(),q=q>m?m:q,p=p>m?m:p,t.setTextNodeRange(r,q,r,p));c.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
19
- function J(a){v.useEffect(()=>{const d=a.addListener("command",(c,b)=>{const e=u.$getSelection();if(!u.$isRangeSelection(e))return!1;switch(c){case "deleteCharacter":return e.deleteCharacter(b),!0;case "deleteWord":return e.deleteWord(b),!0;case "deleteLine":return e.deleteLine(b),!0;case "insertText":return"string"===typeof b?e.insertText(b):(c=b.dataTransfer,null!=c?C(c,e):(b=b.data)&&e.insertText(b)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(b),
20
- !0;case "insertParagraph":return e.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(E(e,!0))return b.preventDefault(),b=c,c=A(e),e.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(E(e,!1))return b.preventDefault(),b=c,c=A(e),e.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),
21
- a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(b,a),!0;case "cut":return G(b,a),!0;case "paste":return F(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return d},[a]);I(a)}module.exports=function(a,d){J(a);z(a,d)};
7
+ var k=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react");
8
+ function w(a,d,f,b,c){if(null===a||0===f.size&&0===b.size)return 0;var e=d._selection,g=a._selection;if(c)return 1;if(!(u.$isRangeSelection(e)&&u.$isRangeSelection(g)&&g.isCollapsed()&&e.isCollapsed()))return 0;var h=Array.from(f);b=Array.from(b);f=d._nodeMap;c=[];for(var l=0;l<h.length;l++){const n=f.get(h[l]);void 0!==n&&c.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(l=f.get(b[h][0]),void 0===l||u.$isRootNode(l)||c.push(l));if(0===c.length)return 0;if(1<c.length)return b=d._nodeMap,d=b.get(e.anchor.key),
9
+ g=b.get(g.anchor.key),d&&g&&!a._nodeMap.has(d.__key)&&u.$isTextNode(d)&&1===d.__text.length&&1===e.anchor.offset?2:0;d=c[0];a=a._nodeMap.get(d.__key);if(!u.$isTextNode(a)||!u.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;e=e.anchor;g=g.anchor;if(e.key!==g.key||"text"!==e.type)return 0;e=e.offset;g=g.offset;a=d.length-a.length;return 1===a&&g===e-1?2:-1===a&&g===e+1?3:-1===a&&g===e?4:0}
10
+ function x(a,d){let f=Date.now(),b=0;return(c,e,g,h,l,n)=>{const t=Date.now();if(n.has("historic"))return b=0,f=t,2;const m=w(c,e,h,l,a.isComposing()),r=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===c)return 1;var p=e._selection;const D=c._selection;if(!(0<h.size||0<l.size))return null===D&&null!==p?0:2;p=null===g||g.editor===a;return!1===q&&0!==m&&m===b&&t<f+d&&p?0:1})();f=t;b=m;return r}}
11
+ function y(a,d,f=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),c=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const e=x(a,f);return k(a.addListener("command",g=>{switch(g){case "undo":g=b.redoStack;var h=b.undoStack;if(0!==h.length){var l=b.current;const n=h.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
12
+ {tag:"historic"})}return!0;case "redo":return g=b.redoStack,h=b.undoStack,0!==g.length&&(l=b.current,null!==l&&(h.push(l),a.execCommand("canUndo",!0)),h=g.pop(),0===g.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return c(),!1;case "clearHistory":return c(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:h,dirtyLeaves:l,dirtyElements:n,tags:t})=>{const m=b.current,r=b.redoStack,q=b.undoStack,
13
+ p=null===m?null:m.editorState;if(null===m||g!==p){l=e(h,g,m,l,n,t);if(1===l)0!==r.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;b.current={editor:a,editorState:g}}}))},[c,f,a,b])}function z(a,d,f=1E3){return y(a,d,f)}function A(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function B(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}
14
+ function C(a,d){a=u.$getDecoratorNode(a.focus,d);return u.$isDecoratorNode(a)&&!a.isIsolated()}function E(a,d){a.preventDefault();d.update(()=>{const f=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(f)&&B(b,f)})}function F(a,d){G(a,d);d.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}
15
+ function G(a,d){a.preventDefault();d.update(()=>{const f=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=f){var c=window.getSelection();if(!c.isCollapsed){var e=c.getRangeAt(0);e&&(c=document.createElement("div"),e=e.cloneContents(),c.appendChild(e),f.setData("text/html",c.innerHTML));f.setData("text/plain",b.getTextContent())}}})}const H={tag:"history-merge"};
16
+ function I(a,d){if(null!==d)if(void 0===d)a.update(()=>{var f=u.$getRoot();if(null===f.getFirstChild()){const b=u.$createParagraphNode();f.append(b);f=document.activeElement;(null!==u.$getSelection()||null!==f&&f===a.getRootElement())&&b.select()}},H);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,H);break;case "object":a.setEditorState(d,H);break;case "function":a.update(d,H)}}
17
+ function J(a){v.useEffect(()=>{const d=f=>{var b=a.getRootElement();if(document.activeElement===b&&(b=f.data,"string"===typeof b)){try{var c=JSON.parse(b)}catch(e){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [e,g,h,l,n]=c;a.update(()=>{const t=u.$getSelection();if(u.$isRangeSelection(t)){var m=t.anchor;let r=m.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=e&&0<=g&&(q=e,p=e+g,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
18
+ h)t.insertRawText(h),r=m.getNode();u.$isTextNode(r)&&(q=l,p=l+n,m=r.getTextContentSize(),q=q>m?m:q,p=p>m?m:p,t.setTextNodeRange(r,q,r,p));f.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
19
+ function K(a,d){v.useEffect(()=>{const f=a.addListener("command",(b,c)=>{const e=u.$getSelection();if(!u.$isRangeSelection(e))return!1;switch(b){case "deleteCharacter":return e.deleteCharacter(c),!0;case "deleteWord":return e.deleteWord(c),!0;case "deleteLine":return e.deleteLine(c),!0;case "insertText":return"string"===typeof c?e.insertText(c):(b=c.dataTransfer,null!=b?B(b,e):(c=c.data)&&e.insertText(c)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(c),
20
+ !0;case "insertParagraph":return e.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(C(e,!0))return c.preventDefault(),c=b,b=A(e),e.modify(c?"extend":"move",!b,"character"),!0;break;case "keyArrowRight":b=c.shiftKey;if(C(e,!1))return c.preventDefault(),c=b,b=A(e),e.modify(c?"extend":"move",b,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
21
+ a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return E(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);I(a,d);return f},[a]);J(a)}module.exports=function(a,d){K(a);z(a,d)};