@lexical/markdown 0.2.0 → 0.2.1

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.
@@ -71,10 +71,20 @@ const markdownHeader2 = { ...paragraphStartBase,
71
71
  regExForAutoFormatting: /^(?:## )/
72
72
  };
73
73
  const markdownHeader3 = { ...paragraphStartBase,
74
- markdownFormatKind: 'paragraphH2',
74
+ markdownFormatKind: 'paragraphH3',
75
75
  regEx: /^(?:### )/,
76
76
  regExForAutoFormatting: /^(?:### )/
77
77
  };
78
+ const markdownHeader4 = { ...paragraphStartBase,
79
+ markdownFormatKind: 'paragraphH4',
80
+ regEx: /^(?:#### )/,
81
+ regExForAutoFormatting: /^(?:#### )/
82
+ };
83
+ const markdownHeader5 = { ...paragraphStartBase,
84
+ markdownFormatKind: 'paragraphH5',
85
+ regEx: /^(?:##### )/,
86
+ regExForAutoFormatting: /^(?:##### )/
87
+ };
78
88
  const markdownBlockQuote = { ...paragraphStartBase,
79
89
  markdownFormatKind: 'paragraphBlockQuote',
80
90
  regEx: /^(?:> )/,
@@ -178,7 +188,7 @@ const allMarkdownCriteriaForTextNodes = [// Place the combination formats ahead
178
188
  markdownStrikethroughItalicBold, markdownItalicbold, markdownStrikethroughItalic, markdownStrikethroughBold, // Individuals
179
189
  markdownInlineCode, markdownItalic, markdownBold, markdownBold2, markdownItalic2, // Must appear after markdownBold2.
180
190
  fakeMarkdownUnderline, markdownStrikethrough, markdownLink];
181
- const allMarkdownCriteria = [markdownHeader1, markdownHeader2, markdownHeader3, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, markdownHorizontalRule, markdownHorizontalRuleUsingDashes, ...allMarkdownCriteriaForTextNodes];
191
+ const allMarkdownCriteria = [markdownHeader1, markdownHeader2, markdownHeader3, markdownHeader4, markdownHeader5, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, markdownHorizontalRule, markdownHorizontalRuleUsingDashes, ...allMarkdownCriteriaForTextNodes];
182
192
  function getInitialScanningContext(editor, isAutoFormatting, textNodeWithOffset, triggerState) {
183
193
  return {
184
194
  currentElementNode: null,
@@ -338,6 +348,26 @@ function getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNod
338
348
  };
339
349
  }
340
350
 
351
+ case 'paragraphH4':
352
+ {
353
+ newNode = richText.$createHeadingNode('h4');
354
+ newNode.append(...children);
355
+ return {
356
+ newNode,
357
+ shouldDelete
358
+ };
359
+ }
360
+
361
+ case 'paragraphH5':
362
+ {
363
+ newNode = richText.$createHeadingNode('h5');
364
+ newNode.append(...children);
365
+ return {
366
+ newNode,
367
+ shouldDelete
368
+ };
369
+ }
370
+
341
371
  case 'paragraphBlockQuote':
342
372
  {
343
373
  newNode = richText.$createQuoteNode();
@@ -4,33 +4,34 @@
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"),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.");}
7
+ var k=require("@lexical/code"),m=require("@lexical/list"),n=require("lexical"),t=require("@lexical/link"),u=require("@lexical/rich-text"),v=require("@lexical/text");function w(c){throw Error(`Minified Lexical error #${c}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
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
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
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
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})};
12
+ markdownFormatKind:"paragraphH1",regEx:/^(?:# )/,regExForAutoFormatting:/^(?:# )/},{...A,markdownFormatKind:"paragraphH2",regEx:/^(?:## )/,regExForAutoFormatting:/^(?:## )/},{...A,markdownFormatKind:"paragraphH3",regEx:/^(?:### )/,regExForAutoFormatting:/^(?:### )/},{...A,markdownFormatKind:"paragraphH4",regEx:/^(?:#### )/,regExForAutoFormatting:/^(?:#### )/},{...A,markdownFormatKind:"paragraphH5",regEx:/^(?:##### )/,regExForAutoFormatting:/^(?:##### )/},{...A,markdownFormatKind:"paragraphBlockQuote",
13
+ regEx:/^(?:> )/,regExForAutoFormatting:/^(?:> )/},{...A,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})(?:- )/,regExForAutoFormatting:/^(\s{0,10})(?:- )/},{...A,markdownFormatKind:"paragraphUnorderedList",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:/^(?:\*\*\* )/},
14
+ {...A,markdownFormatKind:"horizontalRule",regEx:/^(?:---)$/,regExForAutoFormatting:/^(?:--- )/},...C];function E(c,d,e,a){return{currentElementNode:null,editor:c,isAutoFormatting:d,isWithinCodeBlock:!1,joinedText:null,markdownCriteria:{markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null},patternMatchResults:{regExCaptureGroups:[]},textNodeWithOffset:e,triggerState:a}}
15
+ function F(c,d,e,a){const b={regExCaptureGroups:[]};a=c.match(a);if(null!==a&&0<a.length&&(!1===d||0===a.index)&&(!1===e||a.index+a[0].length===c.length)){c=a.length;d=a.index;for(e=0;e<c;e++){const f=a[e];b.regExCaptureGroups.push({offsetInParent:d,text:f});0<e&&(d+=f.length)}return b}return null}function I(c){c=c.textNodeWithOffset;null==c&&w(82);return c}
16
+ function J(c,d){var e=I(d);return null===e.node.getPreviousSibling()?(e=e.node.getTextContent(),F(e,!0,!1,d.isAutoFormatting?c.regExForAutoFormatting:c.regEx)):null}
17
+ function K(c,d,e){var a=null,b=d.getChildren();const f=c.markdownCriteria,g=c.patternMatchResults;if(null!=f.markdownFormatKind)switch(f.markdownFormatKind){case "paragraphH1":a=u.$createHeadingNode("h1");a.append(...b);break;case "paragraphH2":a=u.$createHeadingNode("h2");a.append(...b);break;case "paragraphH3":a=u.$createHeadingNode("h3");a.append(...b);break;case "paragraphH4":a=u.$createHeadingNode("h4");a.append(...b);break;case "paragraphH5":a=u.$createHeadingNode("h5");a.append(...b);break;
18
+ case "paragraphBlockQuote":a=u.$createQuoteNode();a.append(...b);break;case "paragraphUnorderedList":return L(d,b,g,"ul"),{newNode:null,shouldDelete:!1};case "paragraphOrderedList":return a=1<g.regExCaptureGroups.length?g.regExCaptureGroups[g.regExCaptureGroups.length-1].text:"1",c=c.isAutoFormatting?parseInt(a,10):void 0,L(d,b,g,"ol",c),{newNode:null,shouldDelete:!1};case "paragraphCodeBlock":if(!1===c.isAutoFormatting){if(0<c.patternMatchResults.regExCaptureGroups.length)return c.isWithinCodeBlock=
19
+ !0!==c.isWithinCodeBlock,c.currentElementNode=null,{newNode:null,shouldDelete:!0};if(c.isWithinCodeBlock){if(null==c.currentElementNode)return d=k.$createCodeNode(),d.append(...b),c.currentElementNode=d,{newNode:d,shouldDelete:!1};null!=c.currentElementNode&&(d=c.currentElementNode,c=n.$createLineBreakNode(),d.append(c),b.length&&d.append(c),d.append(...b))}return{newNode:null,shouldDelete:!0}}null!=c.triggerState&&c.triggerState.isCodeBlock?a=n.$createParagraphNode():(a=k.$createCodeNode(),d=3<=
20
+ g.regExCaptureGroups.length?g.regExCaptureGroups[2].text:null,null!=d&&0<d.length&&a.setLanguage(d));a.append(...b);break;case "horizontalRule":null!=e&&(b=e(),d.insertBefore(b))}return{newNode:a,shouldDelete:!1}}
21
+ function L(c,d,e,a,b){const f=m.$createListItemNode();e=(e=e.regExCaptureGroups[0].text.match(/^\s*/))?Math.floor(e[0].length/4):0;f.append(...d);d=c.getPreviousSibling();m.$isListNode(d)&&d.getTag()===a?(d.append(f),c.remove()):(a=m.$createListNode(a,b),a.append(f),c.replace(a));e&&f.setIndent(e)}
22
+ function M(c,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:b,shouldDelete:f}=K(d,c,e);f?c.remove():null!==b&&c.replace(b)}
23
+ function N(c){switch(c){case "italic":case "bold":case "underline":case "strikethrough":case "code":return[c];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}
24
+ function Q(c,d,e,a,b){var f=b.patternMatchResults;const g=f.regExCaptureGroups;var h=g.length;if(c>=h||d>=h)return null;b=I(b).node.getParentOrThrow();h=f.regExCaptureGroups.length;2>h?f=0:(--h,f=f.regExCaptureGroups[h].offsetInParent+f.regExCaptureGroups[h].text.length);c=g[c];d=g[d];a=a?d.offsetInParent+d.text.length:d.offsetInParent;e=v.$findNodeWithOffsetFromJoinedText(e?c.offsetInParent+c.text.length:c.offsetInParent,f,1,b);a=v.$findNodeWithOffsetFromJoinedText(a,f,1,b);if(null==e||null==a)return null;
25
+ b=n.$createRangeSelection();b.anchor.set(e.node.getKey(),e.offset,"text");b.focus.set(a.node.getKey(),a.offset,"text");return b}function R(c,d,e){const a=e.patternMatchResults.regExCaptureGroups;e=Q(c,d,!1,!0,e);if(null!=e&&(n.$setSelection(e),e=n.$getSelection(),null!=e&&n.$isRangeSelection(e)&&!1===e.isCollapsed())){e.removeText();e=0;const b=a.length;for(let f=c;f<b;f++){const g=a[f];f>c&&(g.offsetInParent-=e);f<=d&&(e+=g.text.length,g.text="")}}}
26
+ function S(c){var d=c.patternMatchResults.regExCaptureGroups.length;2>d||(--d,c=Q(d,d,!0,!0,c),null!=c&&n.$setSelection(c))}
27
+ function T(c,d,e){c.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 b=N(a.markdownFormatKind);if(null!=b){if(a=b,7===d.patternMatchResults.regExCaptureGroups.length){R(5,5,d);R(1,1,d);b=d.patternMatchResults.regExCaptureGroups;3<b.length||w(65);if(0!==b[3].text.length&&(b=Q(3,3,!1,!0,d),null!=b&&(n.$setSelection(b),b=n.$getSelection(),n.$isRangeSelection(b))))for(var f=0;f<a.length;f++)b.formatText(a[f]);
28
+ 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);b=d.patternMatchResults.regExCaptureGroups;if(!(1>=b.length)){f={offsetInParent:b[1].offsetInParent,text:f};var g=Q(1,1,!1,!1,d);if(null!=g&&(n.$setSelection(g),g=n.$getSelection(),null!=g&&n.$isRangeSelection(g)&&g.isCollapsed())){g.insertText(f.text);b.splice(1,0,f);f=f.text.length;g=b.length;for(let h=2;h<g;h++)b[h].offsetInParent+=
29
+ f}}b=Q(1,1,!1,!0,d);null!=b&&(n.$setSelection(b),d.editor.dispatchCommand(t.TOGGLE_LINK_COMMAND,a),S(d))}}},{tag:"history-push"})}
30
+ function U(c,d){let e=null;c.getEditorState().read(()=>{var a=n.$getSelection();if(n.$isRangeSelection(a)){var b=a.anchor.getNode();a=n.$isTextNode(b)?{node:b,offset:a.anchor.offset}:null}else a=null;if(null!==a){a=E(c,!0,a,d);a:{b=!1===d.isParentAListItemNode?D:C;const h=a.triggerState,r=b.length;for(let p=0;p<r;p++){const l=b[p];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();
31
+ n.$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){b={markdownCriteria:l,patternMatchResults:f};break a}}}b={markdownCriteria:null,patternMatchResults:null}}null!==b.markdownCriteria&&null!==b.patternMatchResults&&(e=a,e.markdownCriteria=b.markdownCriteria,e.patternMatchResults=b.patternMatchResults)}});return e}
32
+ function V(c){let d=null;c.read(()=>{const e=n.$getSelection();if(n.$isRangeSelection(e)&&e.isCollapsed()){var a=e.anchor.getNode(),b=a.getParent(),f=m.$isListItemNode(b);d={anchorOffset:e.anchor.offset,hasParentNode:null!==b,isCodeBlock:k.$isCodeNode(a),isParentAListItemNode:f,isSelectionCollapsed:!0,isSimpleText:n.$isTextNode(a)&&a.isSimpleText(),nodeKey:a.getKey(),textContent:a.getTextContent()}}});return d}
33
+ exports.$convertFromMarkdownString=function(c,d,e){if(c.length){var a=[];c=c.split("\n");var b=c.length;for(var f=0;f<b;f++)0<c[f].length?a.push(n.$createParagraphNode().append(n.$createTextNode(c[f]))):a.push(n.$createParagraphNode());a.length?(c=n.$getRoot(),c.clear(),c.append(...a),a=c):a=null}else a=null;if(null!=a)for(d=E(d,!1,null,null),a=n.$getRoot(),c=!1,b=0;!c;){c=!0;f=a.getChildren();const q=f.length;for(let z=b;z<q;z++){var g=f[z];if(n.$isElementNode(g)){var h=d,r=e,p=g.getTextContent();
34
+ if(n.$isParagraphNode(g)){var l=g.getFirstChild();const O=n.$isTextNode(l);if(!0===h.isWithinCodeBlock)null!=l&&O&&(h.textNodeWithOffset={node:l,offset:0},l=F(p,!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){p=D.length;for(let G=0;G<p;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);
35
+ 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){b=z;c=!1;break}}}};
36
+ exports.registerMarkdownShortcuts=function(c,d){let e=null;return c.registerUpdateListener(({tags:a})=>{if(!1===a.has("historic")){a=V(c.getEditorState());if(null==a)var b=null;else a:{b=a;var f=e;if(null==b||null==f)b=null;else{var g=x.length;for(let h=0;h<g;h++){const r=x[h].triggerString,p=r.length,l=b.textContent.length,q=b.anchorOffset-p;if(!1===(!0===b.hasParentNode&&b.isSimpleText&&b.isSelectionCollapsed&&b.anchorOffset!==f.anchorOffset&&0<=q&&q+p<=l&&b.textContent.substr(q,p)===r&&b.textContent!==
37
+ f.textContent)){b=null;break a}}b=U(c,b)}}null!=b&&T(c,b,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.2.0",
11
+ "version": "0.2.1",
12
12
  "main": "LexicalMarkdown.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.2.0"
14
+ "lexical": "0.2.1"
15
15
  },
16
16
  "dependencies": {
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"
17
+ "@lexical/utils": "0.2.1",
18
+ "@lexical/code": "0.2.1",
19
+ "@lexical/text": "0.2.1",
20
+ "@lexical/rich-text": "0.2.1",
21
+ "@lexical/list": "0.2.1",
22
+ "@lexical/link": "0.2.1"
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",