@lexical/markdown 0.1.21 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,7 +41,7 @@ const SEPARATOR_LENGTH = SEPARATOR_BETWEEN_TEXT_AND_NON_TEXT_NODES.length;
41
41
  const spaceTrigger = {
42
42
  triggerKind: 'space_trigger',
43
43
  triggerString: '\u0020'
44
- }; // TODO: add support for ``` + carriage return either inside or not inside code block. Should toggle between.
44
+ }; // Future todo: add support for ``` + carriage return either inside or not inside code block. Should toggle between.
45
45
  // const codeBlockTrigger : AutoFormatTrigger = {
46
46
  // triggerKind: 'codeBlock_trigger',
47
47
  // triggerString: '```', // + new paragraph element or new code block element.
@@ -49,7 +49,7 @@ const spaceTrigger = {
49
49
 
50
50
  const triggers = [spaceTrigger
51
51
  /*, codeBlockTrigger*/
52
- ]; // Todo: speed up performance by having non-capture group variations of the regex.
52
+ ]; // Future Todo: speed up performance by having non-capture group variations of the regex.
53
53
 
54
54
  const autoFormatBase = {
55
55
  markdownFormatKind: null,
@@ -62,33 +62,33 @@ const paragraphStartBase = { ...autoFormatBase,
62
62
  };
63
63
  const markdownHeader1 = { ...paragraphStartBase,
64
64
  markdownFormatKind: 'paragraphH1',
65
- regEx: /^(?:#)/,
65
+ regEx: /^(?:# )/,
66
66
  regExForAutoFormatting: /^(?:# )/
67
67
  };
68
68
  const markdownHeader2 = { ...paragraphStartBase,
69
69
  markdownFormatKind: 'paragraphH2',
70
- regEx: /^(?:##)/,
70
+ regEx: /^(?:## )/,
71
71
  regExForAutoFormatting: /^(?:## )/
72
72
  };
73
73
  const markdownHeader3 = { ...paragraphStartBase,
74
74
  markdownFormatKind: 'paragraphH2',
75
- regEx: /^(?:###)/,
75
+ regEx: /^(?:### )/,
76
76
  regExForAutoFormatting: /^(?:### )/
77
77
  };
78
78
  const markdownBlockQuote = { ...paragraphStartBase,
79
79
  markdownFormatKind: 'paragraphBlockQuote',
80
- regEx: /^(?:>)/,
80
+ regEx: /^(?:> )/,
81
81
  regExForAutoFormatting: /^(?:> )/
82
82
  };
83
83
  const markdownUnorderedListDash = { ...paragraphStartBase,
84
84
  markdownFormatKind: 'paragraphUnorderedList',
85
- regEx: /^(?:- )/,
86
- regExForAutoFormatting: /^(?:- )/
85
+ regEx: /^(\s{0,10})(?:- )/,
86
+ regExForAutoFormatting: /^(\s{0,10})(?:- )/
87
87
  };
88
88
  const markdownUnorderedListAsterisk = { ...paragraphStartBase,
89
89
  markdownFormatKind: 'paragraphUnorderedList',
90
- regEx: /^(?:\* )/,
91
- regExForAutoFormatting: /^(?:\* )/
90
+ regEx: /^(\s{0,10})(?:\* )/,
91
+ regExForAutoFormatting: /^(\s{0,10})(?:\* )/
92
92
  };
93
93
  const markdownCodeBlock = { ...paragraphStartBase,
94
94
  markdownFormatKind: 'paragraphCodeBlock',
@@ -97,8 +97,8 @@ const markdownCodeBlock = { ...paragraphStartBase,
97
97
  };
98
98
  const markdownOrderedList = { ...paragraphStartBase,
99
99
  markdownFormatKind: 'paragraphOrderedList',
100
- regEx: /^(\d+)\.\s/,
101
- regExForAutoFormatting: /^(\d+)\.\s/
100
+ regEx: /^(\s{0,10})(\d+)\.\s/,
101
+ regExForAutoFormatting: /^(\s{0,10})(\d+)\.\s/
102
102
  };
103
103
  const markdownHorizontalRule = { ...paragraphStartBase,
104
104
  markdownFormatKind: 'horizontalRule',
@@ -110,25 +110,31 @@ const markdownHorizontalRuleUsingDashes = { ...paragraphStartBase,
110
110
  regEx: /^(?:---)$/,
111
111
  regExForAutoFormatting: /^(?:--- )/
112
112
  };
113
+ const markdownInlineCode = { ...autoFormatBase,
114
+ markdownFormatKind: 'code',
115
+ regEx: /(`)([^`]*)(`)/,
116
+ regExForAutoFormatting: /(`)(\s*\b)([^`]*)(\b\s*)(`)(\s)$/
117
+ };
113
118
  const markdownItalic = { ...autoFormatBase,
114
119
  markdownFormatKind: 'italic',
115
- regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*)/,
120
+ regEx: /(\*)([^\*]*)(\*)/,
116
121
  regExForAutoFormatting: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/
117
122
  };
118
123
  const markdownBold = { ...autoFormatBase,
119
124
  markdownFormatKind: 'bold',
120
- regEx: /(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)/,
125
+ regEx: /(\*\*)([^\*\*]*)(\*\*)/,
121
126
  regExForAutoFormatting: /(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/
122
127
  };
123
- const markdownBoldWithUnderlines = { ...autoFormatBase,
128
+ const markdownBold2 = { ...autoFormatBase,
124
129
  markdownFormatKind: 'bold',
125
130
  regEx: /(__)(\s*)([^__]*)(\s*)(__)/,
126
131
  regExForAutoFormatting: /(__)(\s*)([^__]*)(\s*)(__)(\s)$/
127
132
  };
128
- const markdownBoldItalic = { ...autoFormatBase,
129
- markdownFormatKind: 'bold_italic',
130
- regEx: /(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)/,
131
- regExForAutoFormatting: /(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)(\s)$/
133
+ const markdownItalic2 = { ...autoFormatBase,
134
+ markdownFormatKind: 'italic',
135
+ regEx: /(_)([^_]*)(_)/,
136
+ regExForAutoFormatting: /(_)()([^_]*)()(_)(\s)$/ // Maintain 7 groups.
137
+
132
138
  }; // Markdown does not support underline, but we can allow folks to use
133
139
  // the HTML tags for underline.
134
140
 
@@ -139,15 +145,39 @@ const fakeMarkdownUnderline = { ...autoFormatBase,
139
145
  };
140
146
  const markdownStrikethrough = { ...autoFormatBase,
141
147
  markdownFormatKind: 'strikethrough',
142
- regEx: /(~~)(\s*\b)([^~~]*)(\b\s*)(~~)/,
148
+ regEx: /(~~)([^~~]*)(~~)/,
143
149
  regExForAutoFormatting: /(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/
144
150
  };
151
+ const markdownStrikethroughItalicBold = { ...autoFormatBase,
152
+ markdownFormatKind: 'strikethrough_italic_bold',
153
+ regEx: /(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)/,
154
+ regExForAutoFormatting: /(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)(\s)$/
155
+ };
156
+ const markdownItalicbold = { ...autoFormatBase,
157
+ markdownFormatKind: 'italic_bold',
158
+ regEx: /(_\*\*)(\s*\b)([^_\*\*][^\*\*_]*)(\b\s*)(\*\*_)/,
159
+ regExForAutoFormatting: /(_\*\*)(\s*\b)([^_\*\*][^\*\*_]*)(\b\s*)(\*\*_)(\s)$/
160
+ };
161
+ const markdownStrikethroughItalic = { ...autoFormatBase,
162
+ markdownFormatKind: 'strikethrough_italic',
163
+ regEx: /(~~_)(\s*)([^~~_][^_~~]*)(\s*)(_~~)/,
164
+ regExForAutoFormatting: /(~~_)(\s*)([^~~_][^_~~]*)(\s*)(_~~)(\s)$/
165
+ };
166
+ const markdownStrikethroughBold = { ...autoFormatBase,
167
+ markdownFormatKind: 'strikethrough_bold',
168
+ regEx: /(~~\*\*)(\s*\b)([^~~\*\*][^\*\*~~]*)(\b\s*)(\*\*~~)/,
169
+ regExForAutoFormatting: /(~~\*\*)(\s*\b)([^~~\*\*][^\*\*~~]*)(\b\s*)(\*\*~~)(\s)$/
170
+ };
145
171
  const markdownLink = { ...autoFormatBase,
146
172
  markdownFormatKind: 'link',
147
173
  regEx: /(\[)(.+)(\]\()([^ ]+)(?: \"(?:.+)\")?(\))/,
148
174
  regExForAutoFormatting: /(\[)(.+)(\]\()([^ ]+)(?: \"(?:.+)\")?(\))(\s)$/
149
175
  };
150
- const allMarkdownCriteriaForTextNodes = [markdownBoldItalic, markdownItalic, markdownBold, markdownBoldWithUnderlines, fakeMarkdownUnderline, markdownStrikethrough, markdownLink];
176
+ const allMarkdownCriteriaForTextNodes = [// Place the combination formats ahead of the individual formats.
177
+ // Combos
178
+ markdownStrikethroughItalicBold, markdownItalicbold, markdownStrikethroughItalic, markdownStrikethroughBold, // Individuals
179
+ markdownInlineCode, markdownItalic, markdownBold, markdownBold2, markdownItalic2, // Must appear after markdownBold2.
180
+ fakeMarkdownUnderline, markdownStrikethrough, markdownLink];
151
181
  const allMarkdownCriteria = [markdownHeader1, markdownHeader2, markdownHeader3, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, markdownHorizontalRule, markdownHorizontalRuleUsingDashes, ...allMarkdownCriteriaForTextNodes];
152
182
  function getInitialScanningContext(editor, isAutoFormatting, textNodeWithOffset, triggerState) {
153
183
  return {
@@ -226,6 +256,9 @@ function getPatternMatchResultsWithRegEx(textToSearch, matchMustAppearAtStartOfS
226
256
  return null;
227
257
  }
228
258
 
259
+ function hasPatternMatchResults(scanningContext) {
260
+ return scanningContext.patternMatchResults.regExCaptureGroups.length > 0;
261
+ }
229
262
  function getTextNodeWithOffsetOrThrow(scanningContext) {
230
263
  const textNodeWithOffset = scanningContext.textNodeWithOffset;
231
264
 
@@ -317,27 +350,24 @@ function getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNod
317
350
 
318
351
  case 'paragraphUnorderedList':
319
352
  {
320
- newNode = list.$createListNode('ul');
321
- const listItem = list.$createListItemNode();
322
- listItem.append(...children);
323
- newNode.append(listItem);
353
+ createListOrMergeWithPrevious(element, children, patternMatchResults, 'ul');
324
354
  return {
325
- newNode,
326
- shouldDelete
355
+ newNode: null,
356
+ shouldDelete: false
327
357
  };
328
358
  }
329
359
 
330
360
  case 'paragraphOrderedList':
331
361
  {
332
- const startAsString = patternMatchResults.regExCaptureGroups.length > 1 ? patternMatchResults.regExCaptureGroups[patternMatchResults.regExCaptureGroups.length - 1].text : '1';
333
- const start = parseInt(startAsString, 10);
334
- newNode = list.$createListNode('ol', start);
335
- const listItem = list.$createListItemNode();
336
- listItem.append(...children);
337
- newNode.append(listItem);
362
+ const startAsString = patternMatchResults.regExCaptureGroups.length > 1 ? patternMatchResults.regExCaptureGroups[patternMatchResults.regExCaptureGroups.length - 1].text : '1'; // For conversion, don't use start number.
363
+ // For short-cuts aka autoFormatting, use start number.
364
+ // Later, this should be surface dependent and externalized.
365
+
366
+ const start = scanningContext.isAutoFormatting ? parseInt(startAsString, 10) : undefined;
367
+ createListOrMergeWithPrevious(element, children, patternMatchResults, 'ol', start);
338
368
  return {
339
- newNode,
340
- shouldDelete
369
+ newNode: null,
370
+ shouldDelete: false
341
371
  };
342
372
  }
343
373
 
@@ -345,7 +375,7 @@ function getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNod
345
375
  {
346
376
  // Toggle code and paragraph nodes.
347
377
  if (scanningContext.isAutoFormatting === false) {
348
- const shouldToggle = scanningContext.patternMatchResults.regExCaptureGroups.length > 0;
378
+ const shouldToggle = hasPatternMatchResults(scanningContext);
349
379
 
350
380
  if (shouldToggle) {
351
381
  scanningContext.isWithinCodeBlock = scanningContext.isWithinCodeBlock !== true; // When toggling, always clear the code block element node.
@@ -374,6 +404,11 @@ function getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNod
374
404
  const codeBlockNode = scanningContext.currentElementNode;
375
405
  const lineBreakNode = lexical.$createLineBreakNode();
376
406
  codeBlockNode.append(lineBreakNode);
407
+
408
+ if (children.length) {
409
+ codeBlockNode.append(lineBreakNode);
410
+ }
411
+
377
412
  codeBlockNode.append(...children);
378
413
  }
379
414
  }
@@ -421,18 +456,42 @@ function getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNod
421
456
  };
422
457
  }
423
458
 
424
- function transformTextNodeForParagraphs(scanningContext, createHorizontalRuleNode) {
425
- const textNodeWithOffset = getTextNodeWithOffsetOrThrow(scanningContext);
426
- const element = textNodeWithOffset.node.getParentOrThrow();
459
+ function createListOrMergeWithPrevious(element, children, patternMatchResults, tag, start) {
460
+ const listItem = list.$createListItemNode();
461
+ const indentMatch = patternMatchResults.regExCaptureGroups[0].text.match(/^\s*/);
462
+ const indent = indentMatch ? Math.floor(indentMatch[0].length / 4) : 0;
463
+ listItem.append(...children); // Checking if previous element is a list, and if so append
464
+ // new list item inside instead of creating new list
427
465
 
428
- if (scanningContext.patternMatchResults.regExCaptureGroups.length > 0) {
429
- const text = scanningContext.patternMatchResults.regExCaptureGroups[0].text; // Remove the text which we matched.
466
+ const prevElement = element.getPreviousSibling();
430
467
 
431
- const textNode = textNodeWithOffset.node.spliceText(0, text.length, '', true);
468
+ if (list.$isListNode(prevElement) && prevElement.getTag() === tag) {
469
+ prevElement.append(listItem);
470
+ element.remove();
471
+ } else {
472
+ const list$1 = list.$createListNode(tag, start);
473
+ list$1.append(listItem);
474
+ element.replace(list$1);
475
+ }
476
+
477
+ if (indent) {
478
+ listItem.setIndent(indent);
479
+ }
480
+ }
432
481
 
433
- if (textNode.getTextContent() === '') {
434
- textNode.selectPrevious();
435
- textNode.remove();
482
+ function transformTextNodeForElementNode(elementNode, scanningContext, createHorizontalRuleNode) {
483
+ if (scanningContext.textNodeWithOffset != null) {
484
+ const textNodeWithOffset = getTextNodeWithOffsetOrThrow(scanningContext);
485
+
486
+ if (hasPatternMatchResults(scanningContext)) {
487
+ const text = scanningContext.patternMatchResults.regExCaptureGroups[0].text; // Remove the text which we matched.
488
+
489
+ const textNode = textNodeWithOffset.node.spliceText(0, text.length, '', true);
490
+
491
+ if (textNode.getTextContent() === '') {
492
+ textNode.selectPrevious();
493
+ textNode.remove();
494
+ }
436
495
  }
437
496
  } // Transform the current element kind to the new element kind.
438
497
 
@@ -440,12 +499,12 @@ function transformTextNodeForParagraphs(scanningContext, createHorizontalRuleNod
440
499
  const {
441
500
  newNode,
442
501
  shouldDelete
443
- } = getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNode);
502
+ } = getNewNodeForCriteria(scanningContext, elementNode, createHorizontalRuleNode);
444
503
 
445
504
  if (shouldDelete) {
446
- element.remove();
505
+ elementNode.remove();
447
506
  } else if (newNode !== null) {
448
- element.replace(newNode);
507
+ elementNode.replace(newNode);
449
508
  }
450
509
  }
451
510
  function transformTextNodeForText(scanningContext) {
@@ -557,11 +616,27 @@ function getTextFormatType(markdownFormatKind) {
557
616
  case 'bold':
558
617
  case 'underline':
559
618
  case 'strikethrough':
619
+ case 'code':
560
620
  return [markdownFormatKind];
561
621
 
562
- case 'bold_italic':
622
+ case 'strikethrough_italic_bold':
563
623
  {
564
- return ['bold', 'italic'];
624
+ return ['strikethrough', 'italic', 'bold'];
625
+ }
626
+
627
+ case 'italic_bold':
628
+ {
629
+ return ['italic', 'bold'];
630
+ }
631
+
632
+ case 'strikethrough_italic':
633
+ {
634
+ return ['strikethrough', 'italic'];
635
+ }
636
+
637
+ case 'strikethrough_bold':
638
+ {
639
+ return ['strikethrough', 'bold'];
565
640
  }
566
641
  }
567
642
 
@@ -728,7 +803,8 @@ function getAllMarkdownCriteria() {
728
803
  }
729
804
  function transformTextNodeForMarkdownCriteria(scanningContext, createHorizontalRuleNode) {
730
805
  if (scanningContext.markdownCriteria.requiresParagraphStart === true) {
731
- transformTextNodeForParagraphs(scanningContext, createHorizontalRuleNode);
806
+ const elementNode = getTextNodeWithOffsetOrThrow(scanningContext).node.getParentOrThrow();
807
+ transformTextNodeForElementNode(elementNode, scanningContext, createHorizontalRuleNode);
732
808
  } else {
733
809
  transformTextNodeForText(scanningContext);
734
810
  }
@@ -908,58 +984,59 @@ function convertStringToLexical(text, editor) {
908
984
  function convertElementNodeContainingMarkdown(scanningContext, elementNode, createHorizontalRuleNode) {
909
985
  const textContent = elementNode.getTextContent(); // Handle paragraph nodes below.
910
986
 
911
- if (lexical.$isParagraphNode(elementNode) && elementNode.getChildren().length) {
987
+ if (lexical.$isParagraphNode(elementNode)) {
912
988
  const paragraphNode = elementNode;
913
989
  const firstChild = paragraphNode.getFirstChild();
914
990
  const firstChildIsTextNode = lexical.$isTextNode(firstChild); // Handle conversion to code block.
915
991
 
916
992
  if (scanningContext.isWithinCodeBlock === true) {
917
- if (!(firstChild != null && firstChildIsTextNode)) {
918
- throw Error(`Expect paragraph containing only text nodes.`);
919
- }
920
-
921
- scanningContext.textNodeWithOffset = {
922
- node: firstChild,
923
- offset: 0
924
- };
925
- const patternMatchResults = getPatternMatchResultsForCodeBlock(scanningContext, textContent);
993
+ if (firstChild != null && firstChildIsTextNode) {
994
+ // Test if we encounter ending code block.
995
+ scanningContext.textNodeWithOffset = {
996
+ node: firstChild,
997
+ offset: 0
998
+ };
999
+ const patternMatchResults = getPatternMatchResultsForCodeBlock(scanningContext, textContent);
926
1000
 
927
- if (patternMatchResults != null) {
928
- // Toggle transform to or from code block.
929
- scanningContext.patternMatchResults = patternMatchResults;
1001
+ if (patternMatchResults != null) {
1002
+ // Toggle transform to or from code block.
1003
+ scanningContext.patternMatchResults = patternMatchResults;
1004
+ }
930
1005
  }
931
1006
 
932
1007
  scanningContext.markdownCriteria = getCodeBlockCriteria(); // Perform text transformation here.
933
1008
 
934
- transformTextNodeForParagraphs(scanningContext, createHorizontalRuleNode);
1009
+ transformTextNodeForElementNode(elementNode, scanningContext, createHorizontalRuleNode);
935
1010
  return;
936
1011
  }
937
1012
 
938
- const allCriteria = getAllMarkdownCriteria();
939
- const count = allCriteria.length;
1013
+ if (elementNode.getChildren().length) {
1014
+ const allCriteria = getAllMarkdownCriteria();
1015
+ const count = allCriteria.length;
940
1016
 
941
- for (let i = 0; i < count; i++) {
942
- const criteria = allCriteria[i];
1017
+ for (let i = 0; i < count; i++) {
1018
+ const criteria = allCriteria[i];
943
1019
 
944
- if (criteria.requiresParagraphStart === true) {
945
- if (!(firstChild != null && firstChildIsTextNode)) {
946
- throw Error(`Expect paragraph containing only text nodes.`);
947
- }
1020
+ if (criteria.requiresParagraphStart === true) {
1021
+ if (!(firstChild != null && firstChildIsTextNode)) {
1022
+ throw Error(`Expect paragraph containing only text nodes.`);
1023
+ }
948
1024
 
949
- scanningContext.textNodeWithOffset = {
950
- node: firstChild,
951
- offset: 0
952
- };
953
- scanningContext.joinedText = paragraphNode.getTextContent();
954
- const patternMatchResults = getPatternMatchResultsForParagraphs(criteria, scanningContext);
1025
+ scanningContext.textNodeWithOffset = {
1026
+ node: firstChild,
1027
+ offset: 0
1028
+ };
1029
+ scanningContext.joinedText = paragraphNode.getTextContent();
1030
+ const patternMatchResults = getPatternMatchResultsForParagraphs(criteria, scanningContext);
955
1031
 
956
- if (patternMatchResults != null) {
957
- // Lazy fill-in the particular format criteria and any matching result information.
958
- scanningContext.markdownCriteria = criteria;
959
- scanningContext.patternMatchResults = patternMatchResults; // Perform text transformation here.
1032
+ if (patternMatchResults != null) {
1033
+ // Lazy fill-in the particular format criteria and any matching result information.
1034
+ scanningContext.markdownCriteria = criteria;
1035
+ scanningContext.patternMatchResults = patternMatchResults; // Perform text transformation here.
960
1036
 
961
- transformTextNodeForParagraphs(scanningContext, createHorizontalRuleNode);
962
- return;
1037
+ transformTextNodeForElementNode(elementNode, scanningContext, createHorizontalRuleNode);
1038
+ return;
1039
+ }
963
1040
  }
964
1041
  }
965
1042
  }
@@ -4,29 +4,33 @@
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/code"),p=require("@lexical/list"),q=require("lexical"),t=require("@lexical/link"),u=require("@lexical/rich-text"),v=require("@lexical/text");function w(b){throw Error(`Minified Lexical error #${b}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- const y=[{triggerKind:"space_trigger",triggerString:" "}],z={markdownFormatKind:null,regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:!1},A={...z,requiresParagraphStart:!0},B={...A,markdownFormatKind:"paragraphCodeBlock",regEx:/^(```)$/,regExForAutoFormatting:/^(```)([a-z]*)( )/},C=[{...z,markdownFormatKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)/,regExForAutoFormatting:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)(\s)$/},{...z,markdownFormatKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*)/,
9
- regExForAutoFormatting:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/},{...z,markdownFormatKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)/,regExForAutoFormatting:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/},{...z,markdownFormatKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__)/,regExForAutoFormatting:/(__)(\s*)([^__]*)(\s*)(__)(\s)$/},{...z,markdownFormatKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)/,regExForAutoFormatting:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},{...z,markdownFormatKind:"strikethrough",
10
- regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~)/,regExForAutoFormatting:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/},{...z,markdownFormatKind:"link",regEx:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))/,regExForAutoFormatting:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))(\s)$/}],D=[{...A,markdownFormatKind:"paragraphH1",regEx:/^(?:#)/,regExForAutoFormatting:/^(?:# )/},{...A,markdownFormatKind:"paragraphH2",regEx:/^(?:##)/,regExForAutoFormatting:/^(?:## )/},{...A,markdownFormatKind:"paragraphH2",regEx:/^(?:###)/,regExForAutoFormatting:/^(?:### )/},
11
- {...A,markdownFormatKind:"paragraphBlockQuote",regEx:/^(?:>)/,regExForAutoFormatting:/^(?:> )/},{...A,markdownFormatKind:"paragraphUnorderedList",regEx:/^(?:- )/,regExForAutoFormatting:/^(?:- )/},{...A,markdownFormatKind:"paragraphUnorderedList",regEx:/^(?:\* )/,regExForAutoFormatting:/^(?:\* )/},{...A,markdownFormatKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/,regExForAutoFormatting:/^(\d+)\.\s/},B,{...A,markdownFormatKind:"horizontalRule",regEx:/^(?:\*\*\*)$/,regExForAutoFormatting:/^(?:\*\*\* )/},
12
- {...A,markdownFormatKind:"horizontalRule",regEx:/^(?:---)$/,regExForAutoFormatting:/^(?:--- )/},...C];function E(b,e,d,c){return{currentElementNode:null,editor:b,isAutoFormatting:e,isWithinCodeBlock:!1,joinedText:null,markdownCriteria:{markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null},patternMatchResults:{regExCaptureGroups:[]},textNodeWithOffset:d,triggerState:c}}
13
- function F(b,e,d,c){const a={regExCaptureGroups:[]};c=b.match(c);if(null!==c&&0<c.length&&(!1===e||0===c.index)&&(!1===d||c.index+c[0].length===b.length)){b=c.length;e=c.index;for(d=0;d<b;d++){const f=c[d];a.regExCaptureGroups.push({offsetInParent:e,text:f});0<d&&(e+=f.length)}return a}return null}function I(b){b=b.textNodeWithOffset;null==b&&w(82);return b}
14
- function J(b,e){var d=I(e);return null===d.node.getPreviousSibling()?(d=d.node.getTextContent(),F(d,!0,!1,e.isAutoFormatting?b.regExForAutoFormatting:b.regEx)):null}
15
- function K(b,e){var d=I(b);const c=d.node.getParentOrThrow();0<b.patternMatchResults.regExCaptureGroups.length&&(d=d.node.spliceText(0,b.patternMatchResults.regExCaptureGroups[0].text.length,"",!0),""===d.getTextContent()&&(d.selectPrevious(),d.remove()));a:{var a=null;d=c.getChildren();const g=b.markdownCriteria,l=b.patternMatchResults;if(null!=g.markdownFormatKind)switch(g.markdownFormatKind){case "paragraphH1":a=u.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=u.$createHeadingNode("h2");
16
- a.append(...d);break;case "paragraphH3":a=u.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=u.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=p.$createListNode("ul");b=p.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphOrderedList":a=parseInt(1<l.regExCaptureGroups.length?l.regExCaptureGroups[l.regExCaptureGroups.length-1].text:"1",10);a=p.$createListNode("ol",a);b=p.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphCodeBlock":if(!1===
17
- b.isAutoFormatting){if(0<b.patternMatchResults.regExCaptureGroups.length){b.isWithinCodeBlock=!0!==b.isWithinCodeBlock;b.currentElementNode=null;d={newNode:null,shouldDelete:!0};break a}if(b.isWithinCodeBlock){if(null==b.currentElementNode){a=k.$createCodeNode();a.append(...d);b.currentElementNode=a;d={newNode:a,shouldDelete:!1};break a}null!=b.currentElementNode&&(a=b.currentElementNode,b=q.$createLineBreakNode(),a.append(b),a.append(...d))}d={newNode:null,shouldDelete:!0};break a}null!=b.triggerState&&
18
- b.triggerState.isCodeBlock?a=q.$createParagraphNode():(a=k.$createCodeNode(),b=3<=l.regExCaptureGroups.length?l.regExCaptureGroups[2].text:null,null!=b&&0<b.length&&a.setLanguage(b));a.append(...d);break;case "horizontalRule":null!=e&&(d=e(),c.insertBefore(d))}d={newNode:a,shouldDelete:!1}}const {newNode:f,shouldDelete:h}=d;h?c.remove():null!==f&&c.replace(f)}
19
- function L(b,e,d,c,a){var f=a.patternMatchResults;const h=f.regExCaptureGroups;var g=h.length;if(b>=g||e>=g)return null;a=I(a).node.getParentOrThrow();g=f.regExCaptureGroups.length;2>g?f=0:(--g,f=f.regExCaptureGroups[g].offsetInParent+f.regExCaptureGroups[g].text.length);b=h[b];e=h[e];c=c?e.offsetInParent+e.text.length:e.offsetInParent;d=v.$findNodeWithOffsetFromJoinedText(d?b.offsetInParent+b.text.length:b.offsetInParent,f,1,a);c=v.$findNodeWithOffsetFromJoinedText(c,f,1,a);if(null==d||null==c)return null;
20
- a=q.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset,"text");a.focus.set(c.node.getKey(),c.offset,"text");return a}function M(b,e,d){const c=d.patternMatchResults.regExCaptureGroups;d=L(b,e,!1,!0,d);if(null!=d&&(q.$setSelection(d),d=q.$getSelection(),null!=d&&q.$isRangeSelection(d)&&!1===d.isCollapsed())){d.removeText();d=0;const a=c.length;for(let f=b;f<a;f++){const h=c[f];f>b&&(h.offsetInParent-=d);f<=e&&(d+=h.text.length,h.text="")}}}
21
- function P(b){var e=b.patternMatchResults.regExCaptureGroups.length;2>e||(--e,b=L(e,e,!0,!0,b),null!=b&&q.$setSelection(b))}
22
- function Q(b,e,d){b.update(()=>{if(!0===e.markdownCriteria.requiresParagraphStart)K(e,d);else{var c=e.markdownCriteria;if(null!=c.markdownFormatKind){a:{var a=c.markdownFormatKind;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){if(c=a,7===e.patternMatchResults.regExCaptureGroups.length){M(5,5,e);M(1,1,e);a=e.patternMatchResults.regExCaptureGroups;3<a.length||w(65);if(0!==a[3].text.length&&(a=
23
- L(3,3,!1,!0,e),null!=a&&(q.$setSelection(a),a=q.$getSelection(),q.$isRangeSelection(a))))for(var f=0;f<c.length;f++)a.formatText(c[f]);P(e)}}else if("link"===c.markdownFormatKind&&(c=e.patternMatchResults.regExCaptureGroups,7===c.length&&(f=c[2].text,c=c[4].text,0!==f.length&&0!==c.length))){M(1,5,e);a=e.patternMatchResults.regExCaptureGroups;if(!(1>=a.length)){f={offsetInParent:a[1].offsetInParent,text:f};var h=L(1,1,!1,!1,e);if(null!=h&&(q.$setSelection(h),h=q.$getSelection(),null!=h&&q.$isRangeSelection(h)&&
24
- h.isCollapsed())){h.insertText(f.text);a.splice(1,0,f);f=f.text.length;h=a.length;for(let g=2;g<h;g++)a[g].offsetInParent+=f}}a=L(1,1,!1,!0,e);null!=a&&(q.$setSelection(a),e.editor.dispatchCommand(t.TOGGLE_LINK_COMMAND,c),P(e))}}}},{tag:"history-push"})}
25
- function R(b,e){let d=null;b.getEditorState().read(()=>{var c=q.$getSelection();if(q.$isRangeSelection(c)){var a=c.anchor.getNode();c=q.$isTextNode(a)?{node:a,offset:c.anchor.offset}:null}else c=null;if(null!==c){c=E(b,!0,c,e);a:{a=!1===e.isParentAListItemNode?D:C;const g=c.triggerState,l=a.length;for(let n=0;n<l;n++){const r=a[n];if(null!=g&&!1===g.isCodeBlock||"paragraphCodeBlock"===r.markdownFormatKind){var f=r,h=c;if(!0===f.requiresParagraphStart)f=J(f,h);else{if(null==h.joinedText){const m=I(h).node.getParentOrThrow();
26
- q.$isElementNode(m)?null==h.joinedText&&(h.joinedText=v.$joinTextNodesInElementNode(m,"\u0004",I(h))):w(52,m.__key)}f=F(h.joinedText,!1,!0,f.regExForAutoFormatting)}if(null!=f){a={markdownCriteria:r,patternMatchResults:f};break a}}}a={markdownCriteria:null,patternMatchResults:null}}null!==a.markdownCriteria&&null!==a.patternMatchResults&&(d=c,d.markdownCriteria=a.markdownCriteria,d.patternMatchResults=a.patternMatchResults)}});return d}
27
- function S(b){let e=null;b.read(()=>{const d=q.$getSelection();if(q.$isRangeSelection(d)&&d.isCollapsed()){var c=d.anchor.getNode(),a=c.getParent(),f=p.$isListItemNode(a);e={anchorOffset:d.anchor.offset,hasParentNode:null!==a,isCodeBlock:k.$isCodeNode(c),isParentAListItemNode:f,isSelectionCollapsed:!0,isSimpleText:q.$isTextNode(c)&&c.isSimpleText(),nodeKey:c.getKey(),textContent:c.getTextContent()}}});return e}
28
- exports.$convertFromMarkdownString=function(b,e,d){if(b.length){var c=[];b=b.split("\n");var a=b.length;for(var f=0;f<a;f++)0<b[f].length?c.push(q.$createParagraphNode().append(q.$createTextNode(b[f]))):c.push(q.$createParagraphNode());c.length?(b=q.$getRoot(),b.clear(),b.append(...c),c=b):c=null}else c=null;if(null!=c)for(e=E(e,!1,null,null),c=q.$getRoot(),b=!1,a=0;!b;){b=!0;f=c.getChildren();const r=f.length;for(let m=a;m<r;m++){var h=f[m];if(q.$isElementNode(h)){var g=e,l=h;h=d;var n=l.getTextContent();
29
- if(q.$isParagraphNode(l)&&l.getChildren().length){const x=l.getFirstChild(),N=q.$isTextNode(x);if(!0===g.isWithinCodeBlock)null!=x&&N||w(80),g.textNodeWithOffset={node:x,offset:0},l=F(n,!0,!1,g.isAutoFormatting?B.regExForAutoFormatting:B.regEx),null!=l&&(g.patternMatchResults=l),g.markdownCriteria=B,K(g,h);else{n=D.length;for(let G=0;G<n;G++){const H=D[G];if(!0===H.requiresParagraphStart){null!=x&&N||w(80);g.textNodeWithOffset={node:x,offset:0};g.joinedText=l.getTextContent();const O=J(H,g);if(null!=
30
- O){g.markdownCriteria=H;g.patternMatchResults=O;K(g,h);break}}}}}}g=e;g.joinedText="";g.markdownCriteria={markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null};g.patternMatchResults={regExCaptureGroups:[]};g.triggerState=null;g.textNodeWithOffset=null;if(c.getChildren().length!==r){a=m;b=!1;break}}}};
31
- exports.registerMarkdownShortcuts=function(b,e){let d=null;return b.registerUpdateListener(({tags:c})=>{if(!1===c.has("historic")){c=S(b.getEditorState());if(null==c)var a=null;else a:{a=c;var f=d;if(null==a||null==f)a=null;else{var h=y.length;for(let g=0;g<h;g++){const l=y[g].triggerString,n=l.length,r=a.textContent.length,m=a.anchorOffset-n;if(!1===(!0===a.hasParentNode&&a.isSimpleText&&a.isSelectionCollapsed&&a.anchorOffset!==f.anchorOffset&&0<=m&&m+n<=r&&a.textContent.substr(m,n)===l&&a.textContent!==
32
- f.textContent)){a=null;break a}}a=R(b,a)}}null!=a&&Q(b,a,e);d=c}else d=null})};
7
+ var k=require("@lexical/code"),m=require("@lexical/list"),p=require("lexical"),t=require("@lexical/link"),u=require("@lexical/rich-text"),v=require("@lexical/text");function w(b){throw Error(`Minified Lexical error #${b}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
+ const x=[{triggerKind:"space_trigger",triggerString:" "}],y={markdownFormatKind:null,regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:!1},A={...y,requiresParagraphStart:!0},B={...A,markdownFormatKind:"paragraphCodeBlock",regEx:/^(```)$/,regExForAutoFormatting:/^(```)([a-z]*)( )/},C=[{...y,markdownFormatKind:"strikethrough_italic_bold",regEx:/(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)/,regExForAutoFormatting:/(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)(\s)$/},
9
+ {...y,markdownFormatKind:"italic_bold",regEx:/(_\*\*)(\s*\b)([^_\*\*][^\*\*_]*)(\b\s*)(\*\*_)/,regExForAutoFormatting:/(_\*\*)(\s*\b)([^_\*\*][^\*\*_]*)(\b\s*)(\*\*_)(\s)$/},{...y,markdownFormatKind:"strikethrough_italic",regEx:/(~~_)(\s*)([^~~_][^_~~]*)(\s*)(_~~)/,regExForAutoFormatting:/(~~_)(\s*)([^~~_][^_~~]*)(\s*)(_~~)(\s)$/},{...y,markdownFormatKind:"strikethrough_bold",regEx:/(~~\*\*)(\s*\b)([^~~\*\*][^\*\*~~]*)(\b\s*)(\*\*~~)/,regExForAutoFormatting:/(~~\*\*)(\s*\b)([^~~\*\*][^\*\*~~]*)(\b\s*)(\*\*~~)(\s)$/},
10
+ {...y,markdownFormatKind:"code",regEx:/(`)([^`]*)(`)/,regExForAutoFormatting:/(`)(\s*\b)([^`]*)(\b\s*)(`)(\s)$/},{...y,markdownFormatKind:"italic",regEx:/(\*)([^\*]*)(\*)/,regExForAutoFormatting:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/},{...y,markdownFormatKind:"bold",regEx:/(\*\*)([^\*\*]*)(\*\*)/,regExForAutoFormatting:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/},{...y,markdownFormatKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__)/,regExForAutoFormatting:/(__)(\s*)([^__]*)(\s*)(__)(\s)$/},{...y,markdownFormatKind:"italic",
11
+ regEx:/(_)([^_]*)(_)/,regExForAutoFormatting:/(_)()([^_]*)()(_)(\s)$/},{...y,markdownFormatKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)/,regExForAutoFormatting:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},{...y,markdownFormatKind:"strikethrough",regEx:/(~~)([^~~]*)(~~)/,regExForAutoFormatting:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/},{...y,markdownFormatKind:"link",regEx:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))/,regExForAutoFormatting:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))(\s)$/}],D=[{...A,
12
+ markdownFormatKind:"paragraphH1",regEx:/^(?:# )/,regExForAutoFormatting:/^(?:# )/},{...A,markdownFormatKind:"paragraphH2",regEx:/^(?:## )/,regExForAutoFormatting:/^(?:## )/},{...A,markdownFormatKind:"paragraphH2",regEx:/^(?:### )/,regExForAutoFormatting:/^(?:### )/},{...A,markdownFormatKind:"paragraphBlockQuote",regEx:/^(?:> )/,regExForAutoFormatting:/^(?:> )/},{...A,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})(?:- )/,regExForAutoFormatting:/^(\s{0,10})(?:- )/},{...A,markdownFormatKind:"paragraphUnorderedList",
13
+ regEx:/^(\s{0,10})(?:\* )/,regExForAutoFormatting:/^(\s{0,10})(?:\* )/},{...A,markdownFormatKind:"paragraphOrderedList",regEx:/^(\s{0,10})(\d+)\.\s/,regExForAutoFormatting:/^(\s{0,10})(\d+)\.\s/},B,{...A,markdownFormatKind:"horizontalRule",regEx:/^(?:\*\*\*)$/,regExForAutoFormatting:/^(?:\*\*\* )/},{...A,markdownFormatKind:"horizontalRule",regEx:/^(?:---)$/,regExForAutoFormatting:/^(?:--- )/},...C];
14
+ function E(b,d,e,a){return{currentElementNode:null,editor:b,isAutoFormatting:d,isWithinCodeBlock:!1,joinedText:null,markdownCriteria:{markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null},patternMatchResults:{regExCaptureGroups:[]},textNodeWithOffset:e,triggerState:a}}
15
+ function F(b,d,e,a){const c={regExCaptureGroups:[]};a=b.match(a);if(null!==a&&0<a.length&&(!1===d||0===a.index)&&(!1===e||a.index+a[0].length===b.length)){b=a.length;d=a.index;for(e=0;e<b;e++){const f=a[e];c.regExCaptureGroups.push({offsetInParent:d,text:f});0<e&&(d+=f.length)}return c}return null}function I(b){b=b.textNodeWithOffset;null==b&&w(82);return b}
16
+ function J(b,d){var e=I(d);return null===e.node.getPreviousSibling()?(e=e.node.getTextContent(),F(e,!0,!1,d.isAutoFormatting?b.regExForAutoFormatting:b.regEx)):null}
17
+ function K(b,d,e){var a=null,c=d.getChildren();const f=b.markdownCriteria,g=b.patternMatchResults;if(null!=f.markdownFormatKind)switch(f.markdownFormatKind){case "paragraphH1":a=u.$createHeadingNode("h1");a.append(...c);break;case "paragraphH2":a=u.$createHeadingNode("h2");a.append(...c);break;case "paragraphH3":a=u.$createHeadingNode("h3");a.append(...c);break;case "paragraphBlockQuote":a=u.$createQuoteNode();a.append(...c);break;case "paragraphUnorderedList":return L(d,c,g,"ul"),{newNode:null,shouldDelete:!1};
18
+ case "paragraphOrderedList":return a=1<g.regExCaptureGroups.length?g.regExCaptureGroups[g.regExCaptureGroups.length-1].text:"1",b=b.isAutoFormatting?parseInt(a,10):void 0,L(d,c,g,"ol",b),{newNode:null,shouldDelete:!1};case "paragraphCodeBlock":if(!1===b.isAutoFormatting){if(0<b.patternMatchResults.regExCaptureGroups.length)return b.isWithinCodeBlock=!0!==b.isWithinCodeBlock,b.currentElementNode=null,{newNode:null,shouldDelete:!0};if(b.isWithinCodeBlock){if(null==b.currentElementNode)return d=k.$createCodeNode(),
19
+ d.append(...c),b.currentElementNode=d,{newNode:d,shouldDelete:!1};null!=b.currentElementNode&&(d=b.currentElementNode,b=p.$createLineBreakNode(),d.append(b),c.length&&d.append(b),d.append(...c))}return{newNode:null,shouldDelete:!0}}null!=b.triggerState&&b.triggerState.isCodeBlock?a=p.$createParagraphNode():(a=k.$createCodeNode(),d=3<=g.regExCaptureGroups.length?g.regExCaptureGroups[2].text:null,null!=d&&0<d.length&&a.setLanguage(d));a.append(...c);break;case "horizontalRule":null!=e&&(c=e(),d.insertBefore(c))}return{newNode:a,
20
+ shouldDelete:!1}}function L(b,d,e,a,c){const f=m.$createListItemNode();e=(e=e.regExCaptureGroups[0].text.match(/^\s*/))?Math.floor(e[0].length/4):0;f.append(...d);d=b.getPreviousSibling();m.$isListNode(d)&&d.getTag()===a?(d.append(f),b.remove()):(a=m.$createListNode(a,c),a.append(f),b.replace(a));e&&f.setIndent(e)}
21
+ function M(b,d,e){if(null!=d.textNodeWithOffset){var a=I(d);0<d.patternMatchResults.regExCaptureGroups.length&&(a=a.node.spliceText(0,d.patternMatchResults.regExCaptureGroups[0].text.length,"",!0),""===a.getTextContent()&&(a.selectPrevious(),a.remove()))}const {newNode:c,shouldDelete:f}=K(d,b,e);f?b.remove():null!==c&&b.replace(c)}
22
+ function N(b){switch(b){case "italic":case "bold":case "underline":case "strikethrough":case "code":return[b];case "strikethrough_italic_bold":return["strikethrough","italic","bold"];case "italic_bold":return["italic","bold"];case "strikethrough_italic":return["strikethrough","italic"];case "strikethrough_bold":return["strikethrough","bold"]}return null}
23
+ function Q(b,d,e,a,c){var f=c.patternMatchResults;const g=f.regExCaptureGroups;var h=g.length;if(b>=h||d>=h)return null;c=I(c).node.getParentOrThrow();h=f.regExCaptureGroups.length;2>h?f=0:(--h,f=f.regExCaptureGroups[h].offsetInParent+f.regExCaptureGroups[h].text.length);b=g[b];d=g[d];a=a?d.offsetInParent+d.text.length:d.offsetInParent;e=v.$findNodeWithOffsetFromJoinedText(e?b.offsetInParent+b.text.length:b.offsetInParent,f,1,c);a=v.$findNodeWithOffsetFromJoinedText(a,f,1,c);if(null==e||null==a)return null;
24
+ c=p.$createRangeSelection();c.anchor.set(e.node.getKey(),e.offset,"text");c.focus.set(a.node.getKey(),a.offset,"text");return c}function R(b,d,e){const a=e.patternMatchResults.regExCaptureGroups;e=Q(b,d,!1,!0,e);if(null!=e&&(p.$setSelection(e),e=p.$getSelection(),null!=e&&p.$isRangeSelection(e)&&!1===e.isCollapsed())){e.removeText();e=0;const c=a.length;for(let f=b;f<c;f++){const g=a[f];f>b&&(g.offsetInParent-=e);f<=d&&(e+=g.text.length,g.text="")}}}
25
+ function S(b){var d=b.patternMatchResults.regExCaptureGroups.length;2>d||(--d,b=Q(d,d,!0,!0,b),null!=b&&p.$setSelection(b))}
26
+ function T(b,d,e){b.update(()=>{if(!0===d.markdownCriteria.requiresParagraphStart){var a=I(d).node.getParentOrThrow();M(a,d,e)}else if(a=d.markdownCriteria,null!=a.markdownFormatKind){var c=N(a.markdownFormatKind);if(null!=c){if(a=c,7===d.patternMatchResults.regExCaptureGroups.length){R(5,5,d);R(1,1,d);c=d.patternMatchResults.regExCaptureGroups;3<c.length||w(65);if(0!==c[3].text.length&&(c=Q(3,3,!1,!0,d),null!=c&&(p.$setSelection(c),c=p.$getSelection(),p.$isRangeSelection(c))))for(var f=0;f<a.length;f++)c.formatText(a[f]);
27
+ S(d)}}else if("link"===a.markdownFormatKind&&(a=d.patternMatchResults.regExCaptureGroups,7===a.length&&(f=a[2].text,a=a[4].text,0!==f.length&&0!==a.length))){R(1,5,d);c=d.patternMatchResults.regExCaptureGroups;if(!(1>=c.length)){f={offsetInParent:c[1].offsetInParent,text:f};var g=Q(1,1,!1,!1,d);if(null!=g&&(p.$setSelection(g),g=p.$getSelection(),null!=g&&p.$isRangeSelection(g)&&g.isCollapsed())){g.insertText(f.text);c.splice(1,0,f);f=f.text.length;g=c.length;for(let h=2;h<g;h++)c[h].offsetInParent+=
28
+ f}}c=Q(1,1,!1,!0,d);null!=c&&(p.$setSelection(c),d.editor.dispatchCommand(t.TOGGLE_LINK_COMMAND,a),S(d))}}},{tag:"history-push"})}
29
+ function U(b,d){let e=null;b.getEditorState().read(()=>{var a=p.$getSelection();if(p.$isRangeSelection(a)){var c=a.anchor.getNode();a=p.$isTextNode(c)?{node:c,offset:a.anchor.offset}:null}else a=null;if(null!==a){a=E(b,!0,a,d);a:{c=!1===d.isParentAListItemNode?D:C;const h=a.triggerState,r=c.length;for(let n=0;n<r;n++){const l=c[n];if(null!=h&&!1===h.isCodeBlock||"paragraphCodeBlock"===l.markdownFormatKind){var f=l,g=a;if(!0===f.requiresParagraphStart)f=J(f,g);else{if(null==g.joinedText){const q=I(g).node.getParentOrThrow();
30
+ p.$isElementNode(q)?null==g.joinedText&&(g.joinedText=v.$joinTextNodesInElementNode(q,"\u0004",I(g))):w(52,q.__key)}f=F(g.joinedText,!1,!0,f.regExForAutoFormatting)}if(null!=f){c={markdownCriteria:l,patternMatchResults:f};break a}}}c={markdownCriteria:null,patternMatchResults:null}}null!==c.markdownCriteria&&null!==c.patternMatchResults&&(e=a,e.markdownCriteria=c.markdownCriteria,e.patternMatchResults=c.patternMatchResults)}});return e}
31
+ function V(b){let d=null;b.read(()=>{const e=p.$getSelection();if(p.$isRangeSelection(e)&&e.isCollapsed()){var a=e.anchor.getNode(),c=a.getParent(),f=m.$isListItemNode(c);d={anchorOffset:e.anchor.offset,hasParentNode:null!==c,isCodeBlock:k.$isCodeNode(a),isParentAListItemNode:f,isSelectionCollapsed:!0,isSimpleText:p.$isTextNode(a)&&a.isSimpleText(),nodeKey:a.getKey(),textContent:a.getTextContent()}}});return d}
32
+ exports.$convertFromMarkdownString=function(b,d,e){if(b.length){var a=[];b=b.split("\n");var c=b.length;for(var f=0;f<c;f++)0<b[f].length?a.push(p.$createParagraphNode().append(p.$createTextNode(b[f]))):a.push(p.$createParagraphNode());a.length?(b=p.$getRoot(),b.clear(),b.append(...a),a=b):a=null}else a=null;if(null!=a)for(d=E(d,!1,null,null),a=p.$getRoot(),b=!1,c=0;!b;){b=!0;f=a.getChildren();const q=f.length;for(let z=c;z<q;z++){var g=f[z];if(p.$isElementNode(g)){var h=d,r=e,n=g.getTextContent();
33
+ if(p.$isParagraphNode(g)){var l=g.getFirstChild();const O=p.$isTextNode(l);if(!0===h.isWithinCodeBlock)null!=l&&O&&(h.textNodeWithOffset={node:l,offset:0},l=F(n,!0,!1,h.isAutoFormatting?B.regExForAutoFormatting:B.regEx),null!=l&&(h.patternMatchResults=l)),h.markdownCriteria=B,M(g,h,r);else if(g.getChildren().length){n=D.length;for(let G=0;G<n;G++){const H=D[G];if(!0===H.requiresParagraphStart){null!=l&&O||w(80);h.textNodeWithOffset={node:l,offset:0};h.joinedText=g.getTextContent();const P=J(H,h);
34
+ if(null!=P){h.markdownCriteria=H;h.patternMatchResults=P;M(g,h,r);break}}}}}}h=d;h.joinedText="";h.markdownCriteria={markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null};h.patternMatchResults={regExCaptureGroups:[]};h.triggerState=null;h.textNodeWithOffset=null;if(a.getChildren().length!==q){c=z;b=!1;break}}}};
35
+ exports.registerMarkdownShortcuts=function(b,d){let e=null;return b.registerUpdateListener(({tags:a})=>{if(!1===a.has("historic")){a=V(b.getEditorState());if(null==a)var c=null;else a:{c=a;var f=e;if(null==c||null==f)c=null;else{var g=x.length;for(let h=0;h<g;h++){const r=x[h].triggerString,n=r.length,l=c.textContent.length,q=c.anchorOffset-n;if(!1===(!0===c.hasParentNode&&c.isSimpleText&&c.isSelectionCollapsed&&c.anchorOffset!==f.anchorOffset&&0<=q&&q+n<=l&&c.textContent.substr(q,n)===r&&c.textContent!==
36
+ f.textContent)){c=null;break a}}c=U(b,c)}}null!=c&&T(b,c,d);e=a}else e=null})};
package/package.json CHANGED
@@ -8,18 +8,18 @@
8
8
  "markdown"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.1.21",
11
+ "version": "0.2.0",
12
12
  "main": "LexicalMarkdown.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.1.21"
14
+ "lexical": "0.2.0"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.1.21",
18
- "@lexical/code": "0.1.21",
19
- "@lexical/text": "0.1.21",
20
- "@lexical/rich-text": "0.1.21",
21
- "@lexical/list": "0.1.21",
22
- "@lexical/link": "0.1.21"
17
+ "@lexical/utils": "0.2.0",
18
+ "@lexical/code": "0.2.0",
19
+ "@lexical/text": "0.2.0",
20
+ "@lexical/rich-text": "0.2.0",
21
+ "@lexical/list": "0.2.0",
22
+ "@lexical/link": "0.2.0"
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",