@lexical/markdown 0.31.3-nightly.20250602.0 → 0.32.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.
@@ -1060,11 +1060,13 @@ const CODE_SINGLE_LINE_REGEX = /^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[
1060
1060
  const TABLE_ROW_REG_EXP = /^(?:\|)(.+)(?:\|)\s?$/;
1061
1061
  const TABLE_ROW_DIVIDER_REG_EXP = /^(\| ?:?-*:? ?)+\|\s?$/;
1062
1062
  const createBlockNode = createNode => {
1063
- return (parentNode, children, match) => {
1063
+ return (parentNode, children, match, isImport) => {
1064
1064
  const node = createNode(match);
1065
1065
  node.append(...children);
1066
1066
  parentNode.replace(node);
1067
- node.select(0, 0);
1067
+ if (!isImport) {
1068
+ node.select(0, 0);
1069
+ }
1068
1070
  };
1069
1071
  };
1070
1072
 
@@ -1084,7 +1086,7 @@ function getIndent(whitespaces) {
1084
1086
  return indent;
1085
1087
  }
1086
1088
  const listReplace = listType => {
1087
- return (parentNode, children, match) => {
1089
+ return (parentNode, children, match, isImport) => {
1088
1090
  const previousNode = parentNode.getPreviousSibling();
1089
1091
  const nextNode = parentNode.getNextSibling();
1090
1092
  const listItem = list.$createListItemNode(listType === 'check' ? match[3] === 'x' : undefined);
@@ -1106,7 +1108,9 @@ const listReplace = listType => {
1106
1108
  parentNode.replace(list$1);
1107
1109
  }
1108
1110
  listItem.append(...children);
1109
- listItem.select(0, 0);
1111
+ if (!isImport) {
1112
+ listItem.select(0, 0);
1113
+ }
1110
1114
  const indent = getIndent(match[1]);
1111
1115
  if (indent) {
1112
1116
  listItem.setIndent(indent);
@@ -1170,7 +1174,6 @@ const QUOTE = {
1170
1174
  const previousNode = parentNode.getPreviousSibling();
1171
1175
  if (richText.$isQuoteNode(previousNode)) {
1172
1176
  previousNode.splice(previousNode.getChildrenSize(), 0, [lexical.$createLineBreakNode(), ...children]);
1173
- previousNode.select(0, 0);
1174
1177
  parentNode.remove();
1175
1178
  return;
1176
1179
  }
@@ -1178,7 +1181,9 @@ const QUOTE = {
1178
1181
  const node = richText.$createQuoteNode();
1179
1182
  node.append(...children);
1180
1183
  parentNode.replace(node);
1181
- node.select(0, 0);
1184
+ if (!isImport) {
1185
+ node.select(0, 0);
1186
+ }
1182
1187
  },
1183
1188
  type: 'element'
1184
1189
  };
@@ -1058,11 +1058,13 @@ const CODE_SINGLE_LINE_REGEX = /^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[
1058
1058
  const TABLE_ROW_REG_EXP = /^(?:\|)(.+)(?:\|)\s?$/;
1059
1059
  const TABLE_ROW_DIVIDER_REG_EXP = /^(\| ?:?-*:? ?)+\|\s?$/;
1060
1060
  const createBlockNode = createNode => {
1061
- return (parentNode, children, match) => {
1061
+ return (parentNode, children, match, isImport) => {
1062
1062
  const node = createNode(match);
1063
1063
  node.append(...children);
1064
1064
  parentNode.replace(node);
1065
- node.select(0, 0);
1065
+ if (!isImport) {
1066
+ node.select(0, 0);
1067
+ }
1066
1068
  };
1067
1069
  };
1068
1070
 
@@ -1082,7 +1084,7 @@ function getIndent(whitespaces) {
1082
1084
  return indent;
1083
1085
  }
1084
1086
  const listReplace = listType => {
1085
- return (parentNode, children, match) => {
1087
+ return (parentNode, children, match, isImport) => {
1086
1088
  const previousNode = parentNode.getPreviousSibling();
1087
1089
  const nextNode = parentNode.getNextSibling();
1088
1090
  const listItem = $createListItemNode(listType === 'check' ? match[3] === 'x' : undefined);
@@ -1104,7 +1106,9 @@ const listReplace = listType => {
1104
1106
  parentNode.replace(list);
1105
1107
  }
1106
1108
  listItem.append(...children);
1107
- listItem.select(0, 0);
1109
+ if (!isImport) {
1110
+ listItem.select(0, 0);
1111
+ }
1108
1112
  const indent = getIndent(match[1]);
1109
1113
  if (indent) {
1110
1114
  listItem.setIndent(indent);
@@ -1168,7 +1172,6 @@ const QUOTE = {
1168
1172
  const previousNode = parentNode.getPreviousSibling();
1169
1173
  if ($isQuoteNode(previousNode)) {
1170
1174
  previousNode.splice(previousNode.getChildrenSize(), 0, [$createLineBreakNode(), ...children]);
1171
- previousNode.select(0, 0);
1172
1175
  parentNode.remove();
1173
1176
  return;
1174
1177
  }
@@ -1176,7 +1179,9 @@ const QUOTE = {
1176
1179
  const node = $createQuoteNode();
1177
1180
  node.append(...children);
1178
1181
  parentNode.replace(node);
1179
- node.select(0, 0);
1182
+ if (!isImport) {
1183
+ node.select(0, 0);
1184
+ }
1180
1185
  },
1181
1186
  type: 'element'
1182
1187
  };
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("lexical"),t=require("@lexical/list"),n=require("@lexical/rich-text"),o=require("@lexical/utils"),r=require("@lexical/code"),i=require("@lexical/link");function s(e,t){const n={};for(const o of e){const e=t(o);e&&(n[e]?n[e].push(o):n[e]=[o])}return n}function c(e){const t=s(e,(e=>e.type));return{element:t.element||[],multilineElement:t["multiline-element"]||[],textFormat:t["text-format"]||[],textMatch:t["text-match"]||[]}}const l=/[!-/:-@[-`{-~\s]/,a=/^\s{0,3}$/;function f(t){if(!e.$isParagraphNode(t))return!1;const n=t.getFirstChild();return null==n||1===t.getChildrenSize()&&e.$isTextNode(n)&&a.test(n.getTextContent())}function d(t,n,o,r){for(const e of n){if(!e.export)continue;const n=e.export(t,(e=>u(e,o,r)));if(null!=n)return n}return e.$isElementNode(t)?u(t,o,r):e.$isDecoratorNode(t)?t.getTextContent():null}function u(t,n,o,r,i){const s=[],c=t.getChildren();r||(r=[]),i||(i=[]);e:for(const t of c){for(const e of o){if(!e.export)continue;const c=e.export(t,(e=>u(e,n,o,r,[...i,...r])),((e,t)=>g(e,t,n,r,i)));if(null!=c){s.push(c);continue e}}e.$isLineBreakNode(t)?s.push("\n"):e.$isTextNode(t)?s.push(g(t,t.getTextContent(),n,r,i)):e.$isElementNode(t)?s.push(u(t,n,o,r,i)):e.$isDecoratorNode(t)&&s.push(t.getTextContent())}return s.join("")}function g(e,t,n,o,r){let i=0===e.getFormat()?t:function(e){return e.replace(/^\s+|\s+$/g,(e=>[...e].map((e=>"&#"+e.codePointAt(0)+";")).join("")))}(t);e.hasFormat("code")||(i=i.replace(/([*_`~\\])/g,"\\$1"));let s="",c="",l="";const a=p(e,!0),f=p(e,!1),d=new Set;for(const t of n){const n=t.format[0],r=t.tag;x(e,n)&&!d.has(n)&&(d.add(n),x(a,n)&&o.find((e=>e.tag===r))||(o.push({format:n,tag:r}),s+=r))}for(let t=0;t<o.length;t++){const n=x(e,o[t].format),i=x(f,o[t].format);if(n&&i)continue;const s=[...o];for(;s.length>t;){const e=s.pop();r&&e&&r.find((t=>t.tag===e.tag))||(e&&"string"==typeof e.tag&&(n?i||(l+=e.tag):c+=e.tag),o.pop())}break}return i=s+i+l,c+i}function p(t,n){let o=n?t.getPreviousSibling():t.getNextSibling();if(!o){const e=t.getParentOrThrow();e.isInline()&&(o=n?e.getPreviousSibling():e.getNextSibling())}for(;o;){if(e.$isElementNode(o)){if(!o.isInline())break;const t=n?o.getLastDescendant():o.getFirstDescendant();if(e.$isTextNode(t))return t;o=n?o.getPreviousSibling():o.getNextSibling()}if(e.$isTextNode(o))return o;if(!e.$isElementNode(o))return null}return null}function x(t,n){return e.$isTextNode(t)&&t.hasFormat(n)}function h(e,t){const n=function(e,t){const n=e.match(t.openTagsRegExp);if(null==n)return null;for(const o of n){const n=o.replace(/^\s/,""),r=t.fullMatchRegExpByTag[n];if(null==r)continue;const i=e.match(r),s=t.transformersByTag[n];if(null!=i&&null!=s){if(!1!==s.intraword)return i;const{index:t=0}=i,n=e[t-1],o=e[t+i[0].length];if((!n||l.test(n))&&(!o||l.test(o)))return i}}return null}(e.getTextContent(),t);if(!n)return null;const o=n.index||0;return{endIndex:o+n[0].length,match:n,startIndex:o,transformer:t.transformersByTag[n[1]]}}function m(t){return e.$isTextNode(t)&&!t.hasFormat("code")}function $(e,t,n){let o=h(e,t),r=function(e,t){const n=e;let o,r,i,s;for(const e of t){if(!e.replace||!e.importRegExp)continue;const t=n.getTextContent().match(e.importRegExp);if(!t)continue;const c=t.index||0,l=e.getEndIndex?e.getEndIndex(n,t):c+t[0].length;!1!==l&&(void 0===o||void 0===r||c<o&&l>r)&&(o=c,r=l,i=e,s=t)}return void 0===o||void 0===r||void 0===i||void 0===s?null:{endIndex:r,match:s,startIndex:o,transformer:i}}(e,n);if(o&&r&&(o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex?r=null:o=null),o){const r=function(e,t,n,o,r){const i=e.getTextContent();let s,c,l;if(r[0]===i?s=e:0===t?[s,c]=e.splitText(n):[l,s,c]=e.splitText(t,n),s.setTextContent(r[2]),o)for(const e of o.format)s.hasFormat(e)||s.toggleFormat(e);return{nodeAfter:c,nodeBefore:l,transformedNode:s}}(e,o.startIndex,o.endIndex,o.transformer,o.match);m(r.nodeAfter)&&$(r.nodeAfter,t,n),m(r.nodeBefore)&&$(r.nodeBefore,t,n),m(r.transformedNode)&&$(r.transformedNode,t,n)}else if(r){const o=function(e,t,n,o,r){let i,s,c;return 0===t?[i,s]=e.splitText(n):[c,i,s]=e.splitText(t,n),o.replace?{nodeAfter:s,nodeBefore:c,transformedNode:o.replace(i,r)||void 0}:null}(e,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;m(o.nodeAfter)&&$(o.nodeAfter,t,n),m(o.nodeBefore)&&$(o.nodeBefore,t,n),m(o.transformedNode)&&$(o.transformedNode,t,n)}const i=e.getTextContent().replace(/\\([*_`~\\])/g,"$1").replace(/&#(\d+);/g,((e,t)=>String.fromCodePoint(t)));e.setTextContent(i)}function N(t,n=!1){const o=c(t),r=function(e){const t={},n={},o=[],r="(?<![\\\\])";for(const r of e){const{tag:e}=r;t[e]=r;const i=e.replace(/(\*|\^|\+)/g,"\\$1");o.push(i),1===e.length?n[e]=new RegExp(`(?<![\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?![\\\\${i}])`):n[e]=new RegExp(`(?<!\\\\)(${i})((\\\\${i})?.*?[^\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`${r}(${o.join("|")})`,"g"),transformersByTag:t}}(o.textFormat);return(t,i)=>{const s=t.split("\n"),c=s.length,l=i||e.$getRoot();l.clear();for(let e=0;e<c;e++){const t=s[e],[i,c]=T(s,e,o.multilineElement,l);i?e=c:E(t,l,o.element,r,o.textMatch,n)}const a=l.getChildren();for(const e of a)!n&&f(e)&&l.getChildrenSize()>1&&e.remove();null!==e.$getSelection()&&l.selectStart()}}function T(e,t,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:i,regExpStart:s,replace:c}=r,l=e[t].match(s);if(!l)continue;if(n){const i=n({lines:e,rootNode:o,startLineIndex:t,startMatch:l,transformer:r});if(null===i)continue;if(i)return i}const a="object"==typeof i&&"regExp"in i?i.regExp:i,f=i&&"object"==typeof i&&"optional"in i?i.optional:!i;let d=t;const u=e.length;for(;d<u;){const n=a?e[d].match(a):null;if(!n&&(!f||f&&d<u-1)){d++;continue}if(n&&t===d&&n.index===l.index){d++;continue}const r=[];if(n&&t===d)r.push(e[t].slice(l[0].length,-n[0].length));else for(let o=t;o<=d;o++)if(o===t){const t=e[o].slice(l[0].length);r.push(t)}else if(o===d&&n){const t=e[o].slice(0,-n[0].length);r.push(t)}else r.push(e[o]);if(!1!==c(o,null,l,n,r,!0))return[!0,d];break}}return[!1,t]}function E(r,i,s,c,l,a){const f=e.$createTextNode(r),d=e.$createParagraphNode();d.append(f),i.append(d);for(const{regExp:e,replace:t}of s){const n=r.match(e);if(n&&(f.setTextContent(r.slice(n[0].length)),!1!==t(d,[f],n,!0)))break}if($(f,c,l),d.isAttached()&&r.length>0){const r=d.getPreviousSibling();if(!a&&(e.$isParagraphNode(r)||n.$isQuoteNode(r)||t.$isListNode(r))){let n=r;if(t.$isListNode(r)){const e=r.getLastDescendant();n=null==e?null:o.$findMatchingParent(e,t.$isListItemNode)}null!=n&&n.getTextContentSize()>0&&(n.splice(n.getChildrenSize(),0,[e.$createLineBreakNode(),...d.getChildren()]),d.remove())}}}function S(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function C(e,t,n){const o=n.length;for(let r=t;r>=o;r--){const t=r-o;if(L(e,t,n,0,o)&&" "!==e[t+o])return t}return-1}function L(e,t,n,o,r){for(let i=0;i<r;i++)if(e[t+i]!==n[o+i])return!1;return!0}const R=/^(\s*)(\d{1,})\.\s/,I=/^(\s*)[-*+]\s/,y=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,v=/^(#{1,6})\s/,_=/^>\s/,b=/^[ \t]*```(\w+)?/,A=/[ \t]*```$/,F=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,O=/^(?:\|)(.+)(?:\|)\s?$/,k=/^(\| ?:?-*:? ?)+\|\s?$/,M=e=>(t,n,o)=>{const r=e(o);r.append(...n),t.replace(r),r.select(0,0)};const w=e=>(n,o,r)=>{const i=n.getPreviousSibling(),s=n.getNextSibling(),c=t.$createListItemNode("check"===e?"x"===r[3]:void 0);if(t.$isListNode(s)&&s.getListType()===e){const e=s.getFirstChild();null!==e?e.insertBefore(c):s.append(c),n.remove()}else if(t.$isListNode(i)&&i.getListType()===e)i.append(c),n.remove();else{const o=t.$createListNode(e,"number"===e?Number(r[2]):void 0);o.append(c),n.replace(o)}c.append(...o),c.select(0,0);const l=function(e){const t=e.match(/\t/g),n=e.match(/ /g);let o=0;return t&&(o+=t.length),n&&(o+=Math.floor(n.length/4)),o}(r[1]);l&&c.setIndent(l)},B=(e,n,o)=>{const r=[],i=e.getChildren();let s=0;for(const c of i)if(t.$isListItemNode(c)){if(1===c.getChildrenSize()){const e=c.getFirstChild();if(t.$isListNode(e)){r.push(B(e,n,o+1));continue}}const i=" ".repeat(4*o),l=e.getListType(),a="number"===l?`${e.getStart()+s}. `:"check"===l?`- [${c.getChecked()?"x":" "}] `:"- ";r.push(i+a+n(c)),s++}return r.join("\n")},D={dependencies:[n.HeadingNode],export:(e,t)=>{if(!n.$isHeadingNode(e))return null;const o=Number(e.getTag().slice(1));return"#".repeat(o)+" "+t(e)},regExp:v,replace:M((e=>{const t="h"+e[1].length;return n.$createHeadingNode(t)})),type:"element"},P={dependencies:[n.QuoteNode],export:(e,t)=>{if(!n.$isQuoteNode(e))return null;const o=t(e).split("\n"),r=[];for(const e of o)r.push("> "+e);return r.join("\n")},regExp:_,replace:(t,o,r,i)=>{if(i){const r=t.getPreviousSibling();if(n.$isQuoteNode(r))return r.splice(r.getChildrenSize(),0,[e.$createLineBreakNode(),...o]),r.select(0,0),void t.remove()}const s=n.$createQuoteNode();s.append(...o),t.replace(s),s.select(0,0)},type:"element"},H={dependencies:[r.CodeNode],export:e=>{if(!r.$isCodeNode(e))return null;const t=e.getTextContent();return"```"+(e.getLanguage()||"")+(t?"\n"+t:"")+"\n```"},regExpEnd:{optional:!0,regExp:A},regExpStart:b,replace:(t,n,o,i,s,c)=>{let l,a;if(!n&&s){if(1===s.length)i?(l=r.$createCodeNode(),a=o[1]+s[0]):(l=r.$createCodeNode(o[1]),a=s[0].startsWith(" ")?s[0].slice(1):s[0]);else{if(l=r.$createCodeNode(o[1]),0===s[0].trim().length)for(;s.length>0&&!s[0].length;)s.shift();else s[0]=s[0].startsWith(" ")?s[0].slice(1):s[0];for(;s.length>0&&!s[s.length-1].length;)s.pop();a=s.join("\n")}const n=e.$createTextNode(a);l.append(n),t.append(l)}else n&&M((e=>r.$createCodeNode(e?e[1]:void 0)))(t,n,o,c)},type:"multiline-element"},U={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?B(e,n,0):null,regExp:I,replace:w("bullet"),type:"element"},j={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?B(e,n,0):null,regExp:y,replace:w("check"),type:"element"},q={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?B(e,n,0):null,regExp:R,replace:w("number"),type:"element"},z={format:["code"],tag:"`",type:"text-format"},G={format:["highlight"],tag:"==",type:"text-format"},Q={format:["bold","italic"],tag:"***",type:"text-format"},W={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},K={format:["bold"],tag:"**",type:"text-format"},X={format:["bold"],intraword:!1,tag:"__",type:"text-format"},J={format:["strikethrough"],tag:"~~",type:"text-format"},V={format:["italic"],tag:"*",type:"text-format"},Y={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Z={dependencies:[i.LinkNode],export:(e,t,n)=>{if(!i.$isLinkNode(e)||i.$isAutoLinkNode(e))return null;const o=e.getTitle(),r=t(e);return o?`[${r}](${e.getURL()} "${o}")`:`[${r}](${e.getURL()})`},importRegExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,n)=>{const[,o,r,s]=n,c=i.$createLinkNode(r,{title:s}),l=e.$createTextNode(o);return l.setFormat(t.getFormat()),c.append(l),t.replace(c),l},trigger:")",type:"text-match"};const ee=[D,P,U,q],te=[H],ne=[z,Q,W,K,X,G,V,Y,J],oe=[Z],re=[...ee,...te,...ne,...oe];exports.$convertFromMarkdownString=function(e,t=re,n,o=!1,r=!1){const i=o?e:function(e,t=!1){const n=e.split("\n");let o=!1;const r=[];for(let e=0;e<n.length;e++){const i=n[e],s=r[r.length-1];F.test(i)?r.push(i):b.test(i)||A.test(i)?(o=!o,r.push(i)):o||""===i||""===s||!s||v.test(s)||v.test(i)||_.test(i)||R.test(i)||I.test(i)||y.test(i)||O.test(i)||k.test(i)||!t?r.push(i):r[r.length-1]=s+i}return r.join("\n")}(e,r);return N(t,o)(i,n)},exports.$convertToMarkdownString=function(t=re,n,o=!1){return function(t,n=!1){const o=c(t),r=[...o.multilineElement,...o.element],i=!n,s=o.textFormat.filter((e=>1===e.format.length)).sort(((e,t)=>Number(e.format.includes("code"))-Number(t.format.includes("code"))));return t=>{const n=[],c=(t||e.$getRoot()).getChildren();for(let e=0;e<c.length;e++){const t=c[e],l=d(t,r,s,o.textMatch);null!=l&&n.push(i&&e>0&&!f(t)&&!f(c[e-1])?"\n".concat(l):l)}return n.join("\n")}}(t,o)(n)},exports.BOLD_ITALIC_STAR=Q,exports.BOLD_ITALIC_UNDERSCORE=W,exports.BOLD_STAR=K,exports.BOLD_UNDERSCORE=X,exports.CHECK_LIST=j,exports.CODE=H,exports.ELEMENT_TRANSFORMERS=ee,exports.HEADING=D,exports.HIGHLIGHT=G,exports.INLINE_CODE=z,exports.ITALIC_STAR=V,exports.ITALIC_UNDERSCORE=Y,exports.LINK=Z,exports.MULTILINE_ELEMENT_TRANSFORMERS=te,exports.ORDERED_LIST=q,exports.QUOTE=P,exports.STRIKETHROUGH=J,exports.TEXT_FORMAT_TRANSFORMERS=ne,exports.TEXT_MATCH_TRANSFORMERS=oe,exports.TRANSFORMERS=re,exports.UNORDERED_LIST=U,exports.registerMarkdownShortcuts=function(t,n=re){const o=c(n),i=s(o.textFormat,(({tag:e})=>e[e.length-1])),a=s(o.textMatch,(({trigger:e})=>e));for(const e of n){const n=e.type;if("element"===n||"text-match"===n||"multiline-element"===n){const n=e.dependencies;for(const e of n)t.hasNode(e)||S(173,e.getType())}}const f=(t,n,r)=>{(function(t,n,o,r){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const s=n.getTextContent();if(" "!==s[o-1])return!1;for(const{regExp:e,replace:i}of r){const r=s.match(e);if(r&&r[0].length===(r[0].endsWith(" ")?o:o-1)){const e=n.getNextSiblings(),[s,c]=n.splitText(o);if(!1!==i(t,c?[c,...e]:e,r,!1))return s.remove(),!0}}return!1})(t,n,r,o.element)||function(t,n,o,r){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const s=n.getTextContent();if(" "!==s[o-1])return!1;for(const{regExpStart:e,replace:i,regExpEnd:c}of r){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const r=s.match(e);if(r&&r[0].length===(r[0].endsWith(" ")?o:o-1)){const e=n.getNextSiblings(),[s,c]=n.splitText(o);if(!1!==i(t,c?[c,...e]:e,r,null,null,!1))return s.remove(),!0}}return!1}(t,n,r,o.multilineElement)||function(e,t,n){let o=e.getTextContent();const r=n[o[t-1]];if(null==r)return!1;t<o.length&&(o=o.slice(0,t));for(const t of r){if(!t.replace||!t.regExp)continue;const n=o.match(t.regExp);if(null===n)continue;const r=n.index||0,i=r+n[0].length;let s;return 0===r?[s]=e.splitText(i):[,s]=e.splitText(r,i),s.selectNext(0,0),t.replace(s,n),!0}return!1}(n,r,a)||function(t,n,o){const r=t.getTextContent(),i=n-1,s=r[i],c=o[s];if(!c)return!1;for(const n of c){const{tag:o}=n,c=o.length,a=i-c+1;if(c>1&&!L(r,a,o,0,c))continue;if(" "===r[a-1])continue;const f=r[i+1];if(!1===n.intraword&&f&&!l.test(f))continue;const d=t;let u=d,g=C(r,a,o),p=u;for(;g<0&&(p=p.getPreviousSibling())&&!e.$isLineBreakNode(p);)if(e.$isTextNode(p)){if(p.hasFormat("code"))continue;const e=p.getTextContent();u=p,g=C(e,e.length,o)}if(g<0)continue;if(u===d&&g+c===a)continue;const x=u.getTextContent();if(g>0&&x[g-1]===s)continue;const h=x[g-1];if(!1===n.intraword&&h&&!l.test(h))continue;const m=d.getTextContent(),$=m.slice(0,a)+m.slice(i+1);d.setTextContent($);const N=u===d?$:x;u.setTextContent(N.slice(0,g)+N.slice(g+c));const T=e.$getSelection(),E=e.$createRangeSelection();e.$setSelection(E);const S=i-c*(u===d?2:1)+1;E.anchor.set(u.__key,g,"text"),E.focus.set(d.__key,S,"text");for(const e of n.format)E.hasFormat(e)||E.formatText(e);E.anchor.set(E.focus.key,E.focus.offset,E.focus.type);for(const e of n.format)E.hasFormat(e)&&E.toggleFormat(e);return e.$isRangeSelection(T)&&(E.format=T.format),!0}}(n,r,i)};return t.registerUpdateListener((({tags:n,dirtyLeaves:o,editorState:i,prevEditorState:s})=>{if(n.has(e.COLLABORATION_TAG)||n.has(e.HISTORIC_TAG))return;if(t.isComposing())return;const c=i.read(e.$getSelection),l=s.read(e.$getSelection);if(!e.$isRangeSelection(l)||!e.$isRangeSelection(c)||!c.isCollapsed()||c.is(l))return;const a=c.anchor.key,d=c.anchor.offset,u=i._nodeMap.get(a);!e.$isTextNode(u)||!o.has(a)||1!==d&&d>l.anchor.offset+1||t.update((()=>{if(!m(u))return;const e=u.getParent();null===e||r.$isCodeNode(e)||f(e,u,c.anchor.offset)}))}))};
9
+ "use strict";var e=require("lexical"),t=require("@lexical/list"),n=require("@lexical/rich-text"),o=require("@lexical/utils"),r=require("@lexical/code"),i=require("@lexical/link");function s(e,t){const n={};for(const o of e){const e=t(o);e&&(n[e]?n[e].push(o):n[e]=[o])}return n}function c(e){const t=s(e,(e=>e.type));return{element:t.element||[],multilineElement:t["multiline-element"]||[],textFormat:t["text-format"]||[],textMatch:t["text-match"]||[]}}const l=/[!-/:-@[-`{-~\s]/,a=/^\s{0,3}$/;function f(t){if(!e.$isParagraphNode(t))return!1;const n=t.getFirstChild();return null==n||1===t.getChildrenSize()&&e.$isTextNode(n)&&a.test(n.getTextContent())}function d(t,n,o,r){for(const e of n){if(!e.export)continue;const n=e.export(t,(e=>u(e,o,r)));if(null!=n)return n}return e.$isElementNode(t)?u(t,o,r):e.$isDecoratorNode(t)?t.getTextContent():null}function u(t,n,o,r,i){const s=[],c=t.getChildren();r||(r=[]),i||(i=[]);e:for(const t of c){for(const e of o){if(!e.export)continue;const c=e.export(t,(e=>u(e,n,o,r,[...i,...r])),((e,t)=>g(e,t,n,r,i)));if(null!=c){s.push(c);continue e}}e.$isLineBreakNode(t)?s.push("\n"):e.$isTextNode(t)?s.push(g(t,t.getTextContent(),n,r,i)):e.$isElementNode(t)?s.push(u(t,n,o,r,i)):e.$isDecoratorNode(t)&&s.push(t.getTextContent())}return s.join("")}function g(e,t,n,o,r){let i=0===e.getFormat()?t:function(e){return e.replace(/^\s+|\s+$/g,(e=>[...e].map((e=>"&#"+e.codePointAt(0)+";")).join("")))}(t);e.hasFormat("code")||(i=i.replace(/([*_`~\\])/g,"\\$1"));let s="",c="",l="";const a=p(e,!0),f=p(e,!1),d=new Set;for(const t of n){const n=t.format[0],r=t.tag;x(e,n)&&!d.has(n)&&(d.add(n),x(a,n)&&o.find((e=>e.tag===r))||(o.push({format:n,tag:r}),s+=r))}for(let t=0;t<o.length;t++){const n=x(e,o[t].format),i=x(f,o[t].format);if(n&&i)continue;const s=[...o];for(;s.length>t;){const e=s.pop();r&&e&&r.find((t=>t.tag===e.tag))||(e&&"string"==typeof e.tag&&(n?i||(l+=e.tag):c+=e.tag),o.pop())}break}return i=s+i+l,c+i}function p(t,n){let o=n?t.getPreviousSibling():t.getNextSibling();if(!o){const e=t.getParentOrThrow();e.isInline()&&(o=n?e.getPreviousSibling():e.getNextSibling())}for(;o;){if(e.$isElementNode(o)){if(!o.isInline())break;const t=n?o.getLastDescendant():o.getFirstDescendant();if(e.$isTextNode(t))return t;o=n?o.getPreviousSibling():o.getNextSibling()}if(e.$isTextNode(o))return o;if(!e.$isElementNode(o))return null}return null}function x(t,n){return e.$isTextNode(t)&&t.hasFormat(n)}function h(e,t){const n=function(e,t){const n=e.match(t.openTagsRegExp);if(null==n)return null;for(const o of n){const n=o.replace(/^\s/,""),r=t.fullMatchRegExpByTag[n];if(null==r)continue;const i=e.match(r),s=t.transformersByTag[n];if(null!=i&&null!=s){if(!1!==s.intraword)return i;const{index:t=0}=i,n=e[t-1],o=e[t+i[0].length];if((!n||l.test(n))&&(!o||l.test(o)))return i}}return null}(e.getTextContent(),t);if(!n)return null;const o=n.index||0;return{endIndex:o+n[0].length,match:n,startIndex:o,transformer:t.transformersByTag[n[1]]}}function m(t){return e.$isTextNode(t)&&!t.hasFormat("code")}function $(e,t,n){let o=h(e,t),r=function(e,t){const n=e;let o,r,i,s;for(const e of t){if(!e.replace||!e.importRegExp)continue;const t=n.getTextContent().match(e.importRegExp);if(!t)continue;const c=t.index||0,l=e.getEndIndex?e.getEndIndex(n,t):c+t[0].length;!1!==l&&(void 0===o||void 0===r||c<o&&l>r)&&(o=c,r=l,i=e,s=t)}return void 0===o||void 0===r||void 0===i||void 0===s?null:{endIndex:r,match:s,startIndex:o,transformer:i}}(e,n);if(o&&r&&(o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex?r=null:o=null),o){const r=function(e,t,n,o,r){const i=e.getTextContent();let s,c,l;if(r[0]===i?s=e:0===t?[s,c]=e.splitText(n):[l,s,c]=e.splitText(t,n),s.setTextContent(r[2]),o)for(const e of o.format)s.hasFormat(e)||s.toggleFormat(e);return{nodeAfter:c,nodeBefore:l,transformedNode:s}}(e,o.startIndex,o.endIndex,o.transformer,o.match);m(r.nodeAfter)&&$(r.nodeAfter,t,n),m(r.nodeBefore)&&$(r.nodeBefore,t,n),m(r.transformedNode)&&$(r.transformedNode,t,n)}else if(r){const o=function(e,t,n,o,r){let i,s,c;return 0===t?[i,s]=e.splitText(n):[c,i,s]=e.splitText(t,n),o.replace?{nodeAfter:s,nodeBefore:c,transformedNode:o.replace(i,r)||void 0}:null}(e,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;m(o.nodeAfter)&&$(o.nodeAfter,t,n),m(o.nodeBefore)&&$(o.nodeBefore,t,n),m(o.transformedNode)&&$(o.transformedNode,t,n)}const i=e.getTextContent().replace(/\\([*_`~\\])/g,"$1").replace(/&#(\d+);/g,((e,t)=>String.fromCodePoint(t)));e.setTextContent(i)}function N(t,n=!1){const o=c(t),r=function(e){const t={},n={},o=[],r="(?<![\\\\])";for(const r of e){const{tag:e}=r;t[e]=r;const i=e.replace(/(\*|\^|\+)/g,"\\$1");o.push(i),1===e.length?n[e]=new RegExp(`(?<![\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?![\\\\${i}])`):n[e]=new RegExp(`(?<!\\\\)(${i})((\\\\${i})?.*?[^\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`${r}(${o.join("|")})`,"g"),transformersByTag:t}}(o.textFormat);return(t,i)=>{const s=t.split("\n"),c=s.length,l=i||e.$getRoot();l.clear();for(let e=0;e<c;e++){const t=s[e],[i,c]=T(s,e,o.multilineElement,l);i?e=c:E(t,l,o.element,r,o.textMatch,n)}const a=l.getChildren();for(const e of a)!n&&f(e)&&l.getChildrenSize()>1&&e.remove();null!==e.$getSelection()&&l.selectStart()}}function T(e,t,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:i,regExpStart:s,replace:c}=r,l=e[t].match(s);if(!l)continue;if(n){const i=n({lines:e,rootNode:o,startLineIndex:t,startMatch:l,transformer:r});if(null===i)continue;if(i)return i}const a="object"==typeof i&&"regExp"in i?i.regExp:i,f=i&&"object"==typeof i&&"optional"in i?i.optional:!i;let d=t;const u=e.length;for(;d<u;){const n=a?e[d].match(a):null;if(!n&&(!f||f&&d<u-1)){d++;continue}if(n&&t===d&&n.index===l.index){d++;continue}const r=[];if(n&&t===d)r.push(e[t].slice(l[0].length,-n[0].length));else for(let o=t;o<=d;o++)if(o===t){const t=e[o].slice(l[0].length);r.push(t)}else if(o===d&&n){const t=e[o].slice(0,-n[0].length);r.push(t)}else r.push(e[o]);if(!1!==c(o,null,l,n,r,!0))return[!0,d];break}}return[!1,t]}function E(r,i,s,c,l,a){const f=e.$createTextNode(r),d=e.$createParagraphNode();d.append(f),i.append(d);for(const{regExp:e,replace:t}of s){const n=r.match(e);if(n&&(f.setTextContent(r.slice(n[0].length)),!1!==t(d,[f],n,!0)))break}if($(f,c,l),d.isAttached()&&r.length>0){const r=d.getPreviousSibling();if(!a&&(e.$isParagraphNode(r)||n.$isQuoteNode(r)||t.$isListNode(r))){let n=r;if(t.$isListNode(r)){const e=r.getLastDescendant();n=null==e?null:o.$findMatchingParent(e,t.$isListItemNode)}null!=n&&n.getTextContentSize()>0&&(n.splice(n.getChildrenSize(),0,[e.$createLineBreakNode(),...d.getChildren()]),d.remove())}}}function S(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function C(e,t,n){const o=n.length;for(let r=t;r>=o;r--){const t=r-o;if(L(e,t,n,0,o)&&" "!==e[t+o])return t}return-1}function L(e,t,n,o,r){for(let i=0;i<r;i++)if(e[t+i]!==n[o+i])return!1;return!0}const R=/^(\s*)(\d{1,})\.\s/,I=/^(\s*)[-*+]\s/,y=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,v=/^(#{1,6})\s/,_=/^>\s/,b=/^[ \t]*```(\w+)?/,A=/[ \t]*```$/,F=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,O=/^(?:\|)(.+)(?:\|)\s?$/,k=/^(\| ?:?-*:? ?)+\|\s?$/,M=e=>(t,n,o,r)=>{const i=e(o);i.append(...n),t.replace(i),r||i.select(0,0)};const w=e=>(n,o,r,i)=>{const s=n.getPreviousSibling(),c=n.getNextSibling(),l=t.$createListItemNode("check"===e?"x"===r[3]:void 0);if(t.$isListNode(c)&&c.getListType()===e){const e=c.getFirstChild();null!==e?e.insertBefore(l):c.append(l),n.remove()}else if(t.$isListNode(s)&&s.getListType()===e)s.append(l),n.remove();else{const o=t.$createListNode(e,"number"===e?Number(r[2]):void 0);o.append(l),n.replace(o)}l.append(...o),i||l.select(0,0);const a=function(e){const t=e.match(/\t/g),n=e.match(/ /g);let o=0;return t&&(o+=t.length),n&&(o+=Math.floor(n.length/4)),o}(r[1]);a&&l.setIndent(a)},B=(e,n,o)=>{const r=[],i=e.getChildren();let s=0;for(const c of i)if(t.$isListItemNode(c)){if(1===c.getChildrenSize()){const e=c.getFirstChild();if(t.$isListNode(e)){r.push(B(e,n,o+1));continue}}const i=" ".repeat(4*o),l=e.getListType(),a="number"===l?`${e.getStart()+s}. `:"check"===l?`- [${c.getChecked()?"x":" "}] `:"- ";r.push(i+a+n(c)),s++}return r.join("\n")},D={dependencies:[n.HeadingNode],export:(e,t)=>{if(!n.$isHeadingNode(e))return null;const o=Number(e.getTag().slice(1));return"#".repeat(o)+" "+t(e)},regExp:v,replace:M((e=>{const t="h"+e[1].length;return n.$createHeadingNode(t)})),type:"element"},P={dependencies:[n.QuoteNode],export:(e,t)=>{if(!n.$isQuoteNode(e))return null;const o=t(e).split("\n"),r=[];for(const e of o)r.push("> "+e);return r.join("\n")},regExp:_,replace:(t,o,r,i)=>{if(i){const r=t.getPreviousSibling();if(n.$isQuoteNode(r))return r.splice(r.getChildrenSize(),0,[e.$createLineBreakNode(),...o]),void t.remove()}const s=n.$createQuoteNode();s.append(...o),t.replace(s),i||s.select(0,0)},type:"element"},H={dependencies:[r.CodeNode],export:e=>{if(!r.$isCodeNode(e))return null;const t=e.getTextContent();return"```"+(e.getLanguage()||"")+(t?"\n"+t:"")+"\n```"},regExpEnd:{optional:!0,regExp:A},regExpStart:b,replace:(t,n,o,i,s,c)=>{let l,a;if(!n&&s){if(1===s.length)i?(l=r.$createCodeNode(),a=o[1]+s[0]):(l=r.$createCodeNode(o[1]),a=s[0].startsWith(" ")?s[0].slice(1):s[0]);else{if(l=r.$createCodeNode(o[1]),0===s[0].trim().length)for(;s.length>0&&!s[0].length;)s.shift();else s[0]=s[0].startsWith(" ")?s[0].slice(1):s[0];for(;s.length>0&&!s[s.length-1].length;)s.pop();a=s.join("\n")}const n=e.$createTextNode(a);l.append(n),t.append(l)}else n&&M((e=>r.$createCodeNode(e?e[1]:void 0)))(t,n,o,c)},type:"multiline-element"},U={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?B(e,n,0):null,regExp:I,replace:w("bullet"),type:"element"},j={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?B(e,n,0):null,regExp:y,replace:w("check"),type:"element"},q={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?B(e,n,0):null,regExp:R,replace:w("number"),type:"element"},z={format:["code"],tag:"`",type:"text-format"},G={format:["highlight"],tag:"==",type:"text-format"},Q={format:["bold","italic"],tag:"***",type:"text-format"},W={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},K={format:["bold"],tag:"**",type:"text-format"},X={format:["bold"],intraword:!1,tag:"__",type:"text-format"},J={format:["strikethrough"],tag:"~~",type:"text-format"},V={format:["italic"],tag:"*",type:"text-format"},Y={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Z={dependencies:[i.LinkNode],export:(e,t,n)=>{if(!i.$isLinkNode(e)||i.$isAutoLinkNode(e))return null;const o=e.getTitle(),r=t(e);return o?`[${r}](${e.getURL()} "${o}")`:`[${r}](${e.getURL()})`},importRegExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,n)=>{const[,o,r,s]=n,c=i.$createLinkNode(r,{title:s}),l=e.$createTextNode(o);return l.setFormat(t.getFormat()),c.append(l),t.replace(c),l},trigger:")",type:"text-match"};const ee=[D,P,U,q],te=[H],ne=[z,Q,W,K,X,G,V,Y,J],oe=[Z],re=[...ee,...te,...ne,...oe];exports.$convertFromMarkdownString=function(e,t=re,n,o=!1,r=!1){const i=o?e:function(e,t=!1){const n=e.split("\n");let o=!1;const r=[];for(let e=0;e<n.length;e++){const i=n[e],s=r[r.length-1];F.test(i)?r.push(i):b.test(i)||A.test(i)?(o=!o,r.push(i)):o||""===i||""===s||!s||v.test(s)||v.test(i)||_.test(i)||R.test(i)||I.test(i)||y.test(i)||O.test(i)||k.test(i)||!t?r.push(i):r[r.length-1]=s+i}return r.join("\n")}(e,r);return N(t,o)(i,n)},exports.$convertToMarkdownString=function(t=re,n,o=!1){return function(t,n=!1){const o=c(t),r=[...o.multilineElement,...o.element],i=!n,s=o.textFormat.filter((e=>1===e.format.length)).sort(((e,t)=>Number(e.format.includes("code"))-Number(t.format.includes("code"))));return t=>{const n=[],c=(t||e.$getRoot()).getChildren();for(let e=0;e<c.length;e++){const t=c[e],l=d(t,r,s,o.textMatch);null!=l&&n.push(i&&e>0&&!f(t)&&!f(c[e-1])?"\n".concat(l):l)}return n.join("\n")}}(t,o)(n)},exports.BOLD_ITALIC_STAR=Q,exports.BOLD_ITALIC_UNDERSCORE=W,exports.BOLD_STAR=K,exports.BOLD_UNDERSCORE=X,exports.CHECK_LIST=j,exports.CODE=H,exports.ELEMENT_TRANSFORMERS=ee,exports.HEADING=D,exports.HIGHLIGHT=G,exports.INLINE_CODE=z,exports.ITALIC_STAR=V,exports.ITALIC_UNDERSCORE=Y,exports.LINK=Z,exports.MULTILINE_ELEMENT_TRANSFORMERS=te,exports.ORDERED_LIST=q,exports.QUOTE=P,exports.STRIKETHROUGH=J,exports.TEXT_FORMAT_TRANSFORMERS=ne,exports.TEXT_MATCH_TRANSFORMERS=oe,exports.TRANSFORMERS=re,exports.UNORDERED_LIST=U,exports.registerMarkdownShortcuts=function(t,n=re){const o=c(n),i=s(o.textFormat,(({tag:e})=>e[e.length-1])),a=s(o.textMatch,(({trigger:e})=>e));for(const e of n){const n=e.type;if("element"===n||"text-match"===n||"multiline-element"===n){const n=e.dependencies;for(const e of n)t.hasNode(e)||S(173,e.getType())}}const f=(t,n,r)=>{(function(t,n,o,r){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const s=n.getTextContent();if(" "!==s[o-1])return!1;for(const{regExp:e,replace:i}of r){const r=s.match(e);if(r&&r[0].length===(r[0].endsWith(" ")?o:o-1)){const e=n.getNextSiblings(),[s,c]=n.splitText(o);if(!1!==i(t,c?[c,...e]:e,r,!1))return s.remove(),!0}}return!1})(t,n,r,o.element)||function(t,n,o,r){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const s=n.getTextContent();if(" "!==s[o-1])return!1;for(const{regExpStart:e,replace:i,regExpEnd:c}of r){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const r=s.match(e);if(r&&r[0].length===(r[0].endsWith(" ")?o:o-1)){const e=n.getNextSiblings(),[s,c]=n.splitText(o);if(!1!==i(t,c?[c,...e]:e,r,null,null,!1))return s.remove(),!0}}return!1}(t,n,r,o.multilineElement)||function(e,t,n){let o=e.getTextContent();const r=n[o[t-1]];if(null==r)return!1;t<o.length&&(o=o.slice(0,t));for(const t of r){if(!t.replace||!t.regExp)continue;const n=o.match(t.regExp);if(null===n)continue;const r=n.index||0,i=r+n[0].length;let s;return 0===r?[s]=e.splitText(i):[,s]=e.splitText(r,i),s.selectNext(0,0),t.replace(s,n),!0}return!1}(n,r,a)||function(t,n,o){const r=t.getTextContent(),i=n-1,s=r[i],c=o[s];if(!c)return!1;for(const n of c){const{tag:o}=n,c=o.length,a=i-c+1;if(c>1&&!L(r,a,o,0,c))continue;if(" "===r[a-1])continue;const f=r[i+1];if(!1===n.intraword&&f&&!l.test(f))continue;const d=t;let u=d,g=C(r,a,o),p=u;for(;g<0&&(p=p.getPreviousSibling())&&!e.$isLineBreakNode(p);)if(e.$isTextNode(p)){if(p.hasFormat("code"))continue;const e=p.getTextContent();u=p,g=C(e,e.length,o)}if(g<0)continue;if(u===d&&g+c===a)continue;const x=u.getTextContent();if(g>0&&x[g-1]===s)continue;const h=x[g-1];if(!1===n.intraword&&h&&!l.test(h))continue;const m=d.getTextContent(),$=m.slice(0,a)+m.slice(i+1);d.setTextContent($);const N=u===d?$:x;u.setTextContent(N.slice(0,g)+N.slice(g+c));const T=e.$getSelection(),E=e.$createRangeSelection();e.$setSelection(E);const S=i-c*(u===d?2:1)+1;E.anchor.set(u.__key,g,"text"),E.focus.set(d.__key,S,"text");for(const e of n.format)E.hasFormat(e)||E.formatText(e);E.anchor.set(E.focus.key,E.focus.offset,E.focus.type);for(const e of n.format)E.hasFormat(e)&&E.toggleFormat(e);return e.$isRangeSelection(T)&&(E.format=T.format),!0}}(n,r,i)};return t.registerUpdateListener((({tags:n,dirtyLeaves:o,editorState:i,prevEditorState:s})=>{if(n.has(e.COLLABORATION_TAG)||n.has(e.HISTORIC_TAG))return;if(t.isComposing())return;const c=i.read(e.$getSelection),l=s.read(e.$getSelection);if(!e.$isRangeSelection(l)||!e.$isRangeSelection(c)||!c.isCollapsed()||c.is(l))return;const a=c.anchor.key,d=c.anchor.offset,u=i._nodeMap.get(a);!e.$isTextNode(u)||!o.has(a)||1!==d&&d>l.anchor.offset+1||t.update((()=>{if(!m(u))return;const e=u.getParent();null===e||r.$isCodeNode(e)||f(e,u,c.anchor.offset)}))}))};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{$isParagraphNode as t,$isTextNode as e,$getRoot as n,$isElementNode as o,$isDecoratorNode as r,$isLineBreakNode as i,$getSelection as s,$createTextNode as l,$createParagraphNode as c,$createLineBreakNode as f,COLLABORATION_TAG as a,HISTORIC_TAG as u,$isRangeSelection as g,$isRootOrShadowRoot as p,$createRangeSelection as d,$setSelection as m}from"lexical";import{$isListNode as h,$isListItemNode as x,ListNode as T,ListItemNode as C,$createListItemNode as E,$createListNode as y}from"@lexical/list";import{$isQuoteNode as v,HeadingNode as S,$isHeadingNode as $,QuoteNode as b,$createQuoteNode as F,$createHeadingNode as I}from"@lexical/rich-text";import{$findMatchingParent as N}from"@lexical/utils";import{$isCodeNode as w,CodeNode as k,$createCodeNode as L}from"@lexical/code";import{LinkNode as P,$isLinkNode as R,$isAutoLinkNode as _,$createLinkNode as B}from"@lexical/link";function M(t,e){const n={};for(const o of t){const t=e(o);t&&(n[t]?n[t].push(o):n[t]=[o])}return n}function j(t){const e=M(t,(t=>t.type));return{element:e.element||[],multilineElement:e["multiline-element"]||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const A=/[!-/:-@[-`{-~\s]/,z=/^\s{0,3}$/;function U(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&z.test(o.getTextContent())}function W(t,e,n,i){for(const o of e){if(!o.export)continue;const e=o.export(t,(t=>D(t,n,i)));if(null!=e)return e}return o(t)?D(t,n,i):r(t)?t.getTextContent():null}function D(t,n,s,l,c){const f=[],a=t.getChildren();l||(l=[]),c||(c=[]);t:for(const t of a){for(const e of s){if(!e.export)continue;const o=e.export(t,(t=>D(t,n,s,l,[...c,...l])),((t,e)=>O(t,e,n,l,c)));if(null!=o){f.push(o);continue t}}i(t)?f.push("\n"):e(t)?f.push(O(t,t.getTextContent(),n,l,c)):o(t)?f.push(D(t,n,s,l,c)):r(t)&&f.push(t.getTextContent())}return f.join("")}function O(t,e,n,o,r){let i=0===t.getFormat()?e:function(t){return t.replace(/^\s+|\s+$/g,(t=>[...t].map((t=>"&#"+t.codePointAt(0)+";")).join("")))}(e);t.hasFormat("code")||(i=i.replace(/([*_`~\\])/g,"\\$1"));let s="",l="",c="";const f=q(t,!0),a=q(t,!1),u=new Set;for(const e of n){const n=e.format[0],r=e.tag;G(t,n)&&!u.has(n)&&(u.add(n),G(f,n)&&o.find((t=>t.tag===r))||(o.push({format:n,tag:r}),s+=r))}for(let e=0;e<o.length;e++){const n=G(t,o[e].format),i=G(a,o[e].format);if(n&&i)continue;const s=[...o];for(;s.length>e;){const t=s.pop();r&&t&&r.find((e=>e.tag===t.tag))||(t&&"string"==typeof t.tag&&(n?i||(c+=t.tag):l+=t.tag),o.pop())}break}return i=s+i+c,l+i}function q(t,n){let r=n?t.getPreviousSibling():t.getNextSibling();if(!r){const e=t.getParentOrThrow();e.isInline()&&(r=n?e.getPreviousSibling():e.getNextSibling())}for(;r;){if(o(r)){if(!r.isInline())break;const t=n?r.getLastDescendant():r.getFirstDescendant();if(e(t))return t;r=n?r.getPreviousSibling():r.getNextSibling()}if(e(r))return r;if(!o(r))return null}return null}function G(t,n){return e(t)&&t.hasFormat(n)}function H(t,e){const n=function(t,e){const n=t.match(e.openTagsRegExp);if(null==n)return null;for(const o of n){const n=o.replace(/^\s/,""),r=e.fullMatchRegExpByTag[n];if(null==r)continue;const i=t.match(r),s=e.transformersByTag[n];if(null!=i&&null!=s){if(!1!==s.intraword)return i;const{index:e=0}=i,n=t[e-1],o=t[e+i[0].length];if((!n||A.test(n))&&(!o||A.test(o)))return i}}return null}(t.getTextContent(),e);if(!n)return null;const o=n.index||0;return{endIndex:o+n[0].length,match:n,startIndex:o,transformer:e.transformersByTag[n[1]]}}function J(t){return e(t)&&!t.hasFormat("code")}function K(t,e,n){let o=H(t,e),r=function(t,e){const n=t;let o,r,i,s;for(const t of e){if(!t.replace||!t.importRegExp)continue;const e=n.getTextContent().match(t.importRegExp);if(!e)continue;const l=e.index||0,c=t.getEndIndex?t.getEndIndex(n,e):l+e[0].length;!1!==c&&(void 0===o||void 0===r||l<o&&c>r)&&(o=l,r=c,i=t,s=e)}return void 0===o||void 0===r||void 0===i||void 0===s?null:{endIndex:r,match:s,startIndex:o,transformer:i}}(t,n);if(o&&r&&(o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex?r=null:o=null),o){const r=function(t,e,n,o,r){const i=t.getTextContent();let s,l,c;if(r[0]===i?s=t:0===e?[s,l]=t.splitText(n):[c,s,l]=t.splitText(e,n),s.setTextContent(r[2]),o)for(const t of o.format)s.hasFormat(t)||s.toggleFormat(t);return{nodeAfter:l,nodeBefore:c,transformedNode:s}}(t,o.startIndex,o.endIndex,o.transformer,o.match);J(r.nodeAfter)&&K(r.nodeAfter,e,n),J(r.nodeBefore)&&K(r.nodeBefore,e,n),J(r.transformedNode)&&K(r.transformedNode,e,n)}else if(r){const o=function(t,e,n,o,r){let i,s,l;return 0===e?[i,s]=t.splitText(n):[l,i,s]=t.splitText(e,n),o.replace?{nodeAfter:s,nodeBefore:l,transformedNode:o.replace(i,r)||void 0}:null}(t,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;J(o.nodeAfter)&&K(o.nodeAfter,e,n),J(o.nodeBefore)&&K(o.nodeBefore,e,n),J(o.transformedNode)&&K(o.transformedNode,e,n)}const i=t.getTextContent().replace(/\\([*_`~\\])/g,"$1").replace(/&#(\d+);/g,((t,e)=>String.fromCodePoint(e)));t.setTextContent(i)}function Q(t,e=!1){const o=j(t),r=function(t){const e={},n={},o=[],r="(?<![\\\\])";for(const r of t){const{tag:t}=r;e[t]=r;const i=t.replace(/(\*|\^|\+)/g,"\\$1");o.push(i),1===t.length?n[t]=new RegExp(`(?<![\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?![\\\\${i}])`):n[t]=new RegExp(`(?<!\\\\)(${i})((\\\\${i})?.*?[^\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`${r}(${o.join("|")})`,"g"),transformersByTag:e}}(o.textFormat);return(t,i)=>{const l=t.split("\n"),c=l.length,f=i||n();f.clear();for(let t=0;t<c;t++){const n=l[t],[i,s]=V(l,t,o.multilineElement,f);i?t=s:X(n,f,o.element,r,o.textMatch,e)}const a=f.getChildren();for(const t of a)!e&&U(t)&&f.getChildrenSize()>1&&t.remove();null!==s()&&f.selectStart()}}function V(t,e,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:i,regExpStart:s,replace:l}=r,c=t[e].match(s);if(!c)continue;if(n){const i=n({lines:t,rootNode:o,startLineIndex:e,startMatch:c,transformer:r});if(null===i)continue;if(i)return i}const f="object"==typeof i&&"regExp"in i?i.regExp:i,a=i&&"object"==typeof i&&"optional"in i?i.optional:!i;let u=e;const g=t.length;for(;u<g;){const n=f?t[u].match(f):null;if(!n&&(!a||a&&u<g-1)){u++;continue}if(n&&e===u&&n.index===c.index){u++;continue}const r=[];if(n&&e===u)r.push(t[e].slice(c[0].length,-n[0].length));else for(let o=e;o<=u;o++)if(o===e){const e=t[o].slice(c[0].length);r.push(e)}else if(o===u&&n){const e=t[o].slice(0,-n[0].length);r.push(e)}else r.push(t[o]);if(!1!==l(o,null,c,n,r,!0))return[!0,u];break}}return[!1,e]}function X(e,n,o,r,i,s){const a=l(e),u=c();u.append(a),n.append(u);for(const{regExp:t,replace:n}of o){const o=e.match(t);if(o&&(a.setTextContent(e.slice(o[0].length)),!1!==n(u,[a],o,!0)))break}if(K(a,r,i),u.isAttached()&&e.length>0){const e=u.getPreviousSibling();if(!s&&(t(e)||v(e)||h(e))){let t=e;if(h(e)){const n=e.getLastDescendant();t=null==n?null:N(n,x)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[f(),...u.getChildren()]),u.remove())}}}function Y(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Z(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(tt(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function tt(t,e,n,o,r){for(let i=0;i<r;i++)if(t[e+i]!==n[o+i])return!1;return!0}function et(t,n=Bt){const o=j(n),r=M(o.textFormat,(({tag:t})=>t[t.length-1])),l=M(o.textMatch,(({trigger:t})=>t));for(const e of n){const n=e.type;if("element"===n||"text-match"===n||"multiline-element"===n){const n=e.dependencies;for(const e of n)t.hasNode(e)||Y(173,e.getType())}}const c=(t,n,c)=>{(function(t,e,n,o){const r=t.getParent();if(!p(r)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(" "!==i[n-1])return!1;for(const{regExp:r,replace:s}of o){const o=i.match(r);if(o&&o[0].length===(o[0].endsWith(" ")?n:n-1)){const r=e.getNextSiblings(),[i,l]=e.splitText(n);if(!1!==s(t,l?[l,...r]:r,o,!1))return i.remove(),!0}}return!1})(t,n,c,o.element)||function(t,e,n,o){const r=t.getParent();if(!p(r)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(" "!==i[n-1])return!1;for(const{regExpStart:r,replace:s,regExpEnd:l}of o){if(l&&!("optional"in l)||l&&"optional"in l&&!l.optional)continue;const o=i.match(r);if(o&&o[0].length===(o[0].endsWith(" ")?n:n-1)){const r=e.getNextSiblings(),[i,l]=e.splitText(n);if(!1!==s(t,l?[l,...r]:r,o,null,null,!1))return i.remove(),!0}}return!1}(t,n,c,o.multilineElement)||function(t,e,n){let o=t.getTextContent();const r=n[o[e-1]];if(null==r)return!1;e<o.length&&(o=o.slice(0,e));for(const e of r){if(!e.replace||!e.regExp)continue;const n=o.match(e.regExp);if(null===n)continue;const r=n.index||0,i=r+n[0].length;let s;return 0===r?[s]=t.splitText(i):[,s]=t.splitText(r,i),s.selectNext(0,0),e.replace(s,n),!0}return!1}(n,c,l)||function(t,n,o){const r=t.getTextContent(),l=n-1,c=r[l],f=o[c];if(!f)return!1;for(const n of f){const{tag:o}=n,f=o.length,a=l-f+1;if(f>1&&!tt(r,a,o,0,f))continue;if(" "===r[a-1])continue;const u=r[l+1];if(!1===n.intraword&&u&&!A.test(u))continue;const p=t;let h=p,x=Z(r,a,o),T=h;for(;x<0&&(T=T.getPreviousSibling())&&!i(T);)if(e(T)){if(T.hasFormat("code"))continue;const t=T.getTextContent();h=T,x=Z(t,t.length,o)}if(x<0)continue;if(h===p&&x+f===a)continue;const C=h.getTextContent();if(x>0&&C[x-1]===c)continue;const E=C[x-1];if(!1===n.intraword&&E&&!A.test(E))continue;const y=p.getTextContent(),v=y.slice(0,a)+y.slice(l+1);p.setTextContent(v);const S=h===p?v:C;h.setTextContent(S.slice(0,x)+S.slice(x+f));const $=s(),b=d();m(b);const F=l-f*(h===p?2:1)+1;b.anchor.set(h.__key,x,"text"),b.focus.set(p.__key,F,"text");for(const t of n.format)b.hasFormat(t)||b.formatText(t);b.anchor.set(b.focus.key,b.focus.offset,b.focus.type);for(const t of n.format)b.hasFormat(t)&&b.toggleFormat(t);return g($)&&(b.format=$.format),!0}}(n,c,r)};return t.registerUpdateListener((({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:i})=>{if(n.has(a)||n.has(u))return;if(t.isComposing())return;const l=r.read(s),f=i.read(s);if(!g(f)||!g(l)||!l.isCollapsed()||l.is(f))return;const p=l.anchor.key,d=l.anchor.offset,m=r._nodeMap.get(p);!e(m)||!o.has(p)||1!==d&&d>f.anchor.offset+1||t.update((()=>{if(!J(m))return;const t=m.getParent();null===t||w(t)||c(t,m,l.anchor.offset)}))}))}const nt=/^(\s*)(\d{1,})\.\s/,ot=/^(\s*)[-*+]\s/,rt=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,it=/^(#{1,6})\s/,st=/^>\s/,lt=/^[ \t]*```(\w+)?/,ct=/[ \t]*```$/,ft=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,at=/^(?:\|)(.+)(?:\|)\s?$/,ut=/^(\| ?:?-*:? ?)+\|\s?$/,gt=t=>(e,n,o)=>{const r=t(o);r.append(...n),e.replace(r),r.select(0,0)};const pt=t=>(e,n,o)=>{const r=e.getPreviousSibling(),i=e.getNextSibling(),s=E("check"===t?"x"===o[3]:void 0);if(h(i)&&i.getListType()===t){const t=i.getFirstChild();null!==t?t.insertBefore(s):i.append(s),e.remove()}else if(h(r)&&r.getListType()===t)r.append(s),e.remove();else{const n=y(t,"number"===t?Number(o[2]):void 0);n.append(s),e.replace(n)}s.append(...n),s.select(0,0);const l=function(t){const e=t.match(/\t/g),n=t.match(/ /g);let o=0;return e&&(o+=e.length),n&&(o+=Math.floor(n.length/4)),o}(o[1]);l&&s.setIndent(l)},dt=(t,e,n)=>{const o=[],r=t.getChildren();let i=0;for(const s of r)if(x(s)){if(1===s.getChildrenSize()){const t=s.getFirstChild();if(h(t)){o.push(dt(t,e,n+1));continue}}const r=" ".repeat(4*n),l=t.getListType(),c="number"===l?`${t.getStart()+i}. `:"check"===l?`- [${s.getChecked()?"x":" "}] `:"- ";o.push(r+c+e(s)),i++}return o.join("\n")},mt={dependencies:[S],export:(t,e)=>{if(!$(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:it,replace:gt((t=>{const e="h"+t[1].length;return I(e)})),type:"element"},ht={dependencies:[b],export:(t,e)=>{if(!v(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:st,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(v(n))return n.splice(n.getChildrenSize(),0,[f(),...e]),n.select(0,0),void t.remove()}const r=F();r.append(...e),t.replace(r),r.select(0,0)},type:"element"},xt={dependencies:[k],export:t=>{if(!w(t))return null;const e=t.getTextContent();return"```"+(t.getLanguage()||"")+(e?"\n"+e:"")+"\n```"},regExpEnd:{optional:!0,regExp:ct},regExpStart:lt,replace:(t,e,n,o,r,i)=>{let s,c;if(!e&&r){if(1===r.length)o?(s=L(),c=n[1]+r[0]):(s=L(n[1]),c=r[0].startsWith(" ")?r[0].slice(1):r[0]);else{if(s=L(n[1]),0===r[0].trim().length)for(;r.length>0&&!r[0].length;)r.shift();else r[0]=r[0].startsWith(" ")?r[0].slice(1):r[0];for(;r.length>0&&!r[r.length-1].length;)r.pop();c=r.join("\n")}const e=l(c);s.append(e),t.append(s)}else e&&gt((t=>L(t?t[1]:void 0)))(t,e,n,i)},type:"multiline-element"},Tt={dependencies:[T,C],export:(t,e)=>h(t)?dt(t,e,0):null,regExp:ot,replace:pt("bullet"),type:"element"},Ct={dependencies:[T,C],export:(t,e)=>h(t)?dt(t,e,0):null,regExp:rt,replace:pt("check"),type:"element"},Et={dependencies:[T,C],export:(t,e)=>h(t)?dt(t,e,0):null,regExp:nt,replace:pt("number"),type:"element"},yt={format:["code"],tag:"`",type:"text-format"},vt={format:["highlight"],tag:"==",type:"text-format"},St={format:["bold","italic"],tag:"***",type:"text-format"},$t={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},bt={format:["bold"],tag:"**",type:"text-format"},Ft={format:["bold"],intraword:!1,tag:"__",type:"text-format"},It={format:["strikethrough"],tag:"~~",type:"text-format"},Nt={format:["italic"],tag:"*",type:"text-format"},wt={format:["italic"],intraword:!1,tag:"_",type:"text-format"},kt={dependencies:[P],export:(t,e,n)=>{if(!R(t)||_(t))return null;const o=t.getTitle(),r=e(t);return o?`[${r}](${t.getURL()} "${o}")`:`[${r}](${t.getURL()})`},importRegExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,e)=>{const[,n,o,r]=e,i=B(o,{title:r}),s=l(n);return s.setFormat(t.getFormat()),i.append(s),t.replace(i),s},trigger:")",type:"text-match"};const Lt=[mt,ht,Tt,Et],Pt=[xt],Rt=[yt,St,$t,bt,Ft,vt,Nt,wt,It],_t=[kt],Bt=[...Lt,...Pt,...Rt,..._t];function Mt(t,e=Bt,n,o=!1,r=!1){const i=o?t:function(t,e=!1){const n=t.split("\n");let o=!1;const r=[];for(let t=0;t<n.length;t++){const i=n[t],s=r[r.length-1];ft.test(i)?r.push(i):lt.test(i)||ct.test(i)?(o=!o,r.push(i)):o||""===i||""===s||!s||it.test(s)||it.test(i)||st.test(i)||nt.test(i)||ot.test(i)||rt.test(i)||at.test(i)||ut.test(i)||!e?r.push(i):r[r.length-1]=s+i}return r.join("\n")}(t,r);return Q(e,o)(i,n)}function jt(t=Bt,e,o=!1){const r=function(t,e=!1){const o=j(t),r=[...o.multilineElement,...o.element],i=!e,s=o.textFormat.filter((t=>1===t.format.length)).sort(((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code"))));return t=>{const e=[],l=(t||n()).getChildren();for(let t=0;t<l.length;t++){const n=l[t],c=W(n,r,s,o.textMatch);null!=c&&e.push(i&&t>0&&!U(n)&&!U(l[t-1])?"\n".concat(c):c)}return e.join("\n")}}(t,o);return r(e)}export{Mt as $convertFromMarkdownString,jt as $convertToMarkdownString,St as BOLD_ITALIC_STAR,$t as BOLD_ITALIC_UNDERSCORE,bt as BOLD_STAR,Ft as BOLD_UNDERSCORE,Ct as CHECK_LIST,xt as CODE,Lt as ELEMENT_TRANSFORMERS,mt as HEADING,vt as HIGHLIGHT,yt as INLINE_CODE,Nt as ITALIC_STAR,wt as ITALIC_UNDERSCORE,kt as LINK,Pt as MULTILINE_ELEMENT_TRANSFORMERS,Et as ORDERED_LIST,ht as QUOTE,It as STRIKETHROUGH,Rt as TEXT_FORMAT_TRANSFORMERS,_t as TEXT_MATCH_TRANSFORMERS,Bt as TRANSFORMERS,Tt as UNORDERED_LIST,et as registerMarkdownShortcuts};
9
+ import{$isParagraphNode as t,$isTextNode as e,$getRoot as n,$isElementNode as o,$isDecoratorNode as r,$isLineBreakNode as i,$getSelection as s,$createTextNode as l,$createParagraphNode as c,$createLineBreakNode as f,COLLABORATION_TAG as a,HISTORIC_TAG as u,$isRangeSelection as g,$isRootOrShadowRoot as p,$createRangeSelection as d,$setSelection as m}from"lexical";import{$isListNode as h,$isListItemNode as x,ListNode as T,ListItemNode as C,$createListItemNode as E,$createListNode as y}from"@lexical/list";import{$isQuoteNode as v,HeadingNode as S,$isHeadingNode as $,QuoteNode as b,$createQuoteNode as F,$createHeadingNode as I}from"@lexical/rich-text";import{$findMatchingParent as N}from"@lexical/utils";import{$isCodeNode as w,CodeNode as k,$createCodeNode as L}from"@lexical/code";import{LinkNode as P,$isLinkNode as R,$isAutoLinkNode as _,$createLinkNode as B}from"@lexical/link";function M(t,e){const n={};for(const o of t){const t=e(o);t&&(n[t]?n[t].push(o):n[t]=[o])}return n}function j(t){const e=M(t,(t=>t.type));return{element:e.element||[],multilineElement:e["multiline-element"]||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const A=/[!-/:-@[-`{-~\s]/,z=/^\s{0,3}$/;function U(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&z.test(o.getTextContent())}function W(t,e,n,i){for(const o of e){if(!o.export)continue;const e=o.export(t,(t=>D(t,n,i)));if(null!=e)return e}return o(t)?D(t,n,i):r(t)?t.getTextContent():null}function D(t,n,s,l,c){const f=[],a=t.getChildren();l||(l=[]),c||(c=[]);t:for(const t of a){for(const e of s){if(!e.export)continue;const o=e.export(t,(t=>D(t,n,s,l,[...c,...l])),((t,e)=>O(t,e,n,l,c)));if(null!=o){f.push(o);continue t}}i(t)?f.push("\n"):e(t)?f.push(O(t,t.getTextContent(),n,l,c)):o(t)?f.push(D(t,n,s,l,c)):r(t)&&f.push(t.getTextContent())}return f.join("")}function O(t,e,n,o,r){let i=0===t.getFormat()?e:function(t){return t.replace(/^\s+|\s+$/g,(t=>[...t].map((t=>"&#"+t.codePointAt(0)+";")).join("")))}(e);t.hasFormat("code")||(i=i.replace(/([*_`~\\])/g,"\\$1"));let s="",l="",c="";const f=q(t,!0),a=q(t,!1),u=new Set;for(const e of n){const n=e.format[0],r=e.tag;G(t,n)&&!u.has(n)&&(u.add(n),G(f,n)&&o.find((t=>t.tag===r))||(o.push({format:n,tag:r}),s+=r))}for(let e=0;e<o.length;e++){const n=G(t,o[e].format),i=G(a,o[e].format);if(n&&i)continue;const s=[...o];for(;s.length>e;){const t=s.pop();r&&t&&r.find((e=>e.tag===t.tag))||(t&&"string"==typeof t.tag&&(n?i||(c+=t.tag):l+=t.tag),o.pop())}break}return i=s+i+c,l+i}function q(t,n){let r=n?t.getPreviousSibling():t.getNextSibling();if(!r){const e=t.getParentOrThrow();e.isInline()&&(r=n?e.getPreviousSibling():e.getNextSibling())}for(;r;){if(o(r)){if(!r.isInline())break;const t=n?r.getLastDescendant():r.getFirstDescendant();if(e(t))return t;r=n?r.getPreviousSibling():r.getNextSibling()}if(e(r))return r;if(!o(r))return null}return null}function G(t,n){return e(t)&&t.hasFormat(n)}function H(t,e){const n=function(t,e){const n=t.match(e.openTagsRegExp);if(null==n)return null;for(const o of n){const n=o.replace(/^\s/,""),r=e.fullMatchRegExpByTag[n];if(null==r)continue;const i=t.match(r),s=e.transformersByTag[n];if(null!=i&&null!=s){if(!1!==s.intraword)return i;const{index:e=0}=i,n=t[e-1],o=t[e+i[0].length];if((!n||A.test(n))&&(!o||A.test(o)))return i}}return null}(t.getTextContent(),e);if(!n)return null;const o=n.index||0;return{endIndex:o+n[0].length,match:n,startIndex:o,transformer:e.transformersByTag[n[1]]}}function J(t){return e(t)&&!t.hasFormat("code")}function K(t,e,n){let o=H(t,e),r=function(t,e){const n=t;let o,r,i,s;for(const t of e){if(!t.replace||!t.importRegExp)continue;const e=n.getTextContent().match(t.importRegExp);if(!e)continue;const l=e.index||0,c=t.getEndIndex?t.getEndIndex(n,e):l+e[0].length;!1!==c&&(void 0===o||void 0===r||l<o&&c>r)&&(o=l,r=c,i=t,s=e)}return void 0===o||void 0===r||void 0===i||void 0===s?null:{endIndex:r,match:s,startIndex:o,transformer:i}}(t,n);if(o&&r&&(o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex?r=null:o=null),o){const r=function(t,e,n,o,r){const i=t.getTextContent();let s,l,c;if(r[0]===i?s=t:0===e?[s,l]=t.splitText(n):[c,s,l]=t.splitText(e,n),s.setTextContent(r[2]),o)for(const t of o.format)s.hasFormat(t)||s.toggleFormat(t);return{nodeAfter:l,nodeBefore:c,transformedNode:s}}(t,o.startIndex,o.endIndex,o.transformer,o.match);J(r.nodeAfter)&&K(r.nodeAfter,e,n),J(r.nodeBefore)&&K(r.nodeBefore,e,n),J(r.transformedNode)&&K(r.transformedNode,e,n)}else if(r){const o=function(t,e,n,o,r){let i,s,l;return 0===e?[i,s]=t.splitText(n):[l,i,s]=t.splitText(e,n),o.replace?{nodeAfter:s,nodeBefore:l,transformedNode:o.replace(i,r)||void 0}:null}(t,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;J(o.nodeAfter)&&K(o.nodeAfter,e,n),J(o.nodeBefore)&&K(o.nodeBefore,e,n),J(o.transformedNode)&&K(o.transformedNode,e,n)}const i=t.getTextContent().replace(/\\([*_`~\\])/g,"$1").replace(/&#(\d+);/g,((t,e)=>String.fromCodePoint(e)));t.setTextContent(i)}function Q(t,e=!1){const o=j(t),r=function(t){const e={},n={},o=[],r="(?<![\\\\])";for(const r of t){const{tag:t}=r;e[t]=r;const i=t.replace(/(\*|\^|\+)/g,"\\$1");o.push(i),1===t.length?n[t]=new RegExp(`(?<![\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?![\\\\${i}])`):n[t]=new RegExp(`(?<!\\\\)(${i})((\\\\${i})?.*?[^\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`${r}(${o.join("|")})`,"g"),transformersByTag:e}}(o.textFormat);return(t,i)=>{const l=t.split("\n"),c=l.length,f=i||n();f.clear();for(let t=0;t<c;t++){const n=l[t],[i,s]=V(l,t,o.multilineElement,f);i?t=s:X(n,f,o.element,r,o.textMatch,e)}const a=f.getChildren();for(const t of a)!e&&U(t)&&f.getChildrenSize()>1&&t.remove();null!==s()&&f.selectStart()}}function V(t,e,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:i,regExpStart:s,replace:l}=r,c=t[e].match(s);if(!c)continue;if(n){const i=n({lines:t,rootNode:o,startLineIndex:e,startMatch:c,transformer:r});if(null===i)continue;if(i)return i}const f="object"==typeof i&&"regExp"in i?i.regExp:i,a=i&&"object"==typeof i&&"optional"in i?i.optional:!i;let u=e;const g=t.length;for(;u<g;){const n=f?t[u].match(f):null;if(!n&&(!a||a&&u<g-1)){u++;continue}if(n&&e===u&&n.index===c.index){u++;continue}const r=[];if(n&&e===u)r.push(t[e].slice(c[0].length,-n[0].length));else for(let o=e;o<=u;o++)if(o===e){const e=t[o].slice(c[0].length);r.push(e)}else if(o===u&&n){const e=t[o].slice(0,-n[0].length);r.push(e)}else r.push(t[o]);if(!1!==l(o,null,c,n,r,!0))return[!0,u];break}}return[!1,e]}function X(e,n,o,r,i,s){const a=l(e),u=c();u.append(a),n.append(u);for(const{regExp:t,replace:n}of o){const o=e.match(t);if(o&&(a.setTextContent(e.slice(o[0].length)),!1!==n(u,[a],o,!0)))break}if(K(a,r,i),u.isAttached()&&e.length>0){const e=u.getPreviousSibling();if(!s&&(t(e)||v(e)||h(e))){let t=e;if(h(e)){const n=e.getLastDescendant();t=null==n?null:N(n,x)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[f(),...u.getChildren()]),u.remove())}}}function Y(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Z(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(tt(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function tt(t,e,n,o,r){for(let i=0;i<r;i++)if(t[e+i]!==n[o+i])return!1;return!0}function et(t,n=Bt){const o=j(n),r=M(o.textFormat,(({tag:t})=>t[t.length-1])),l=M(o.textMatch,(({trigger:t})=>t));for(const e of n){const n=e.type;if("element"===n||"text-match"===n||"multiline-element"===n){const n=e.dependencies;for(const e of n)t.hasNode(e)||Y(173,e.getType())}}const c=(t,n,c)=>{(function(t,e,n,o){const r=t.getParent();if(!p(r)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(" "!==i[n-1])return!1;for(const{regExp:r,replace:s}of o){const o=i.match(r);if(o&&o[0].length===(o[0].endsWith(" ")?n:n-1)){const r=e.getNextSiblings(),[i,l]=e.splitText(n);if(!1!==s(t,l?[l,...r]:r,o,!1))return i.remove(),!0}}return!1})(t,n,c,o.element)||function(t,e,n,o){const r=t.getParent();if(!p(r)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(" "!==i[n-1])return!1;for(const{regExpStart:r,replace:s,regExpEnd:l}of o){if(l&&!("optional"in l)||l&&"optional"in l&&!l.optional)continue;const o=i.match(r);if(o&&o[0].length===(o[0].endsWith(" ")?n:n-1)){const r=e.getNextSiblings(),[i,l]=e.splitText(n);if(!1!==s(t,l?[l,...r]:r,o,null,null,!1))return i.remove(),!0}}return!1}(t,n,c,o.multilineElement)||function(t,e,n){let o=t.getTextContent();const r=n[o[e-1]];if(null==r)return!1;e<o.length&&(o=o.slice(0,e));for(const e of r){if(!e.replace||!e.regExp)continue;const n=o.match(e.regExp);if(null===n)continue;const r=n.index||0,i=r+n[0].length;let s;return 0===r?[s]=t.splitText(i):[,s]=t.splitText(r,i),s.selectNext(0,0),e.replace(s,n),!0}return!1}(n,c,l)||function(t,n,o){const r=t.getTextContent(),l=n-1,c=r[l],f=o[c];if(!f)return!1;for(const n of f){const{tag:o}=n,f=o.length,a=l-f+1;if(f>1&&!tt(r,a,o,0,f))continue;if(" "===r[a-1])continue;const u=r[l+1];if(!1===n.intraword&&u&&!A.test(u))continue;const p=t;let h=p,x=Z(r,a,o),T=h;for(;x<0&&(T=T.getPreviousSibling())&&!i(T);)if(e(T)){if(T.hasFormat("code"))continue;const t=T.getTextContent();h=T,x=Z(t,t.length,o)}if(x<0)continue;if(h===p&&x+f===a)continue;const C=h.getTextContent();if(x>0&&C[x-1]===c)continue;const E=C[x-1];if(!1===n.intraword&&E&&!A.test(E))continue;const y=p.getTextContent(),v=y.slice(0,a)+y.slice(l+1);p.setTextContent(v);const S=h===p?v:C;h.setTextContent(S.slice(0,x)+S.slice(x+f));const $=s(),b=d();m(b);const F=l-f*(h===p?2:1)+1;b.anchor.set(h.__key,x,"text"),b.focus.set(p.__key,F,"text");for(const t of n.format)b.hasFormat(t)||b.formatText(t);b.anchor.set(b.focus.key,b.focus.offset,b.focus.type);for(const t of n.format)b.hasFormat(t)&&b.toggleFormat(t);return g($)&&(b.format=$.format),!0}}(n,c,r)};return t.registerUpdateListener((({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:i})=>{if(n.has(a)||n.has(u))return;if(t.isComposing())return;const l=r.read(s),f=i.read(s);if(!g(f)||!g(l)||!l.isCollapsed()||l.is(f))return;const p=l.anchor.key,d=l.anchor.offset,m=r._nodeMap.get(p);!e(m)||!o.has(p)||1!==d&&d>f.anchor.offset+1||t.update((()=>{if(!J(m))return;const t=m.getParent();null===t||w(t)||c(t,m,l.anchor.offset)}))}))}const nt=/^(\s*)(\d{1,})\.\s/,ot=/^(\s*)[-*+]\s/,rt=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,it=/^(#{1,6})\s/,st=/^>\s/,lt=/^[ \t]*```(\w+)?/,ct=/[ \t]*```$/,ft=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,at=/^(?:\|)(.+)(?:\|)\s?$/,ut=/^(\| ?:?-*:? ?)+\|\s?$/,gt=t=>(e,n,o,r)=>{const i=t(o);i.append(...n),e.replace(i),r||i.select(0,0)};const pt=t=>(e,n,o,r)=>{const i=e.getPreviousSibling(),s=e.getNextSibling(),l=E("check"===t?"x"===o[3]:void 0);if(h(s)&&s.getListType()===t){const t=s.getFirstChild();null!==t?t.insertBefore(l):s.append(l),e.remove()}else if(h(i)&&i.getListType()===t)i.append(l),e.remove();else{const n=y(t,"number"===t?Number(o[2]):void 0);n.append(l),e.replace(n)}l.append(...n),r||l.select(0,0);const c=function(t){const e=t.match(/\t/g),n=t.match(/ /g);let o=0;return e&&(o+=e.length),n&&(o+=Math.floor(n.length/4)),o}(o[1]);c&&l.setIndent(c)},dt=(t,e,n)=>{const o=[],r=t.getChildren();let i=0;for(const s of r)if(x(s)){if(1===s.getChildrenSize()){const t=s.getFirstChild();if(h(t)){o.push(dt(t,e,n+1));continue}}const r=" ".repeat(4*n),l=t.getListType(),c="number"===l?`${t.getStart()+i}. `:"check"===l?`- [${s.getChecked()?"x":" "}] `:"- ";o.push(r+c+e(s)),i++}return o.join("\n")},mt={dependencies:[S],export:(t,e)=>{if(!$(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:it,replace:gt((t=>{const e="h"+t[1].length;return I(e)})),type:"element"},ht={dependencies:[b],export:(t,e)=>{if(!v(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:st,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(v(n))return n.splice(n.getChildrenSize(),0,[f(),...e]),void t.remove()}const r=F();r.append(...e),t.replace(r),o||r.select(0,0)},type:"element"},xt={dependencies:[k],export:t=>{if(!w(t))return null;const e=t.getTextContent();return"```"+(t.getLanguage()||"")+(e?"\n"+e:"")+"\n```"},regExpEnd:{optional:!0,regExp:ct},regExpStart:lt,replace:(t,e,n,o,r,i)=>{let s,c;if(!e&&r){if(1===r.length)o?(s=L(),c=n[1]+r[0]):(s=L(n[1]),c=r[0].startsWith(" ")?r[0].slice(1):r[0]);else{if(s=L(n[1]),0===r[0].trim().length)for(;r.length>0&&!r[0].length;)r.shift();else r[0]=r[0].startsWith(" ")?r[0].slice(1):r[0];for(;r.length>0&&!r[r.length-1].length;)r.pop();c=r.join("\n")}const e=l(c);s.append(e),t.append(s)}else e&&gt((t=>L(t?t[1]:void 0)))(t,e,n,i)},type:"multiline-element"},Tt={dependencies:[T,C],export:(t,e)=>h(t)?dt(t,e,0):null,regExp:ot,replace:pt("bullet"),type:"element"},Ct={dependencies:[T,C],export:(t,e)=>h(t)?dt(t,e,0):null,regExp:rt,replace:pt("check"),type:"element"},Et={dependencies:[T,C],export:(t,e)=>h(t)?dt(t,e,0):null,regExp:nt,replace:pt("number"),type:"element"},yt={format:["code"],tag:"`",type:"text-format"},vt={format:["highlight"],tag:"==",type:"text-format"},St={format:["bold","italic"],tag:"***",type:"text-format"},$t={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},bt={format:["bold"],tag:"**",type:"text-format"},Ft={format:["bold"],intraword:!1,tag:"__",type:"text-format"},It={format:["strikethrough"],tag:"~~",type:"text-format"},Nt={format:["italic"],tag:"*",type:"text-format"},wt={format:["italic"],intraword:!1,tag:"_",type:"text-format"},kt={dependencies:[P],export:(t,e,n)=>{if(!R(t)||_(t))return null;const o=t.getTitle(),r=e(t);return o?`[${r}](${t.getURL()} "${o}")`:`[${r}](${t.getURL()})`},importRegExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,e)=>{const[,n,o,r]=e,i=B(o,{title:r}),s=l(n);return s.setFormat(t.getFormat()),i.append(s),t.replace(i),s},trigger:")",type:"text-match"};const Lt=[mt,ht,Tt,Et],Pt=[xt],Rt=[yt,St,$t,bt,Ft,vt,Nt,wt,It],_t=[kt],Bt=[...Lt,...Pt,...Rt,..._t];function Mt(t,e=Bt,n,o=!1,r=!1){const i=o?t:function(t,e=!1){const n=t.split("\n");let o=!1;const r=[];for(let t=0;t<n.length;t++){const i=n[t],s=r[r.length-1];ft.test(i)?r.push(i):lt.test(i)||ct.test(i)?(o=!o,r.push(i)):o||""===i||""===s||!s||it.test(s)||it.test(i)||st.test(i)||nt.test(i)||ot.test(i)||rt.test(i)||at.test(i)||ut.test(i)||!e?r.push(i):r[r.length-1]=s+i}return r.join("\n")}(t,r);return Q(e,o)(i,n)}function jt(t=Bt,e,o=!1){const r=function(t,e=!1){const o=j(t),r=[...o.multilineElement,...o.element],i=!e,s=o.textFormat.filter((t=>1===t.format.length)).sort(((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code"))));return t=>{const e=[],l=(t||n()).getChildren();for(let t=0;t<l.length;t++){const n=l[t],c=W(n,r,s,o.textMatch);null!=c&&e.push(i&&t>0&&!U(n)&&!U(l[t-1])?"\n".concat(c):c)}return e.join("\n")}}(t,o);return r(e)}export{Mt as $convertFromMarkdownString,jt as $convertToMarkdownString,St as BOLD_ITALIC_STAR,$t as BOLD_ITALIC_UNDERSCORE,bt as BOLD_STAR,Ft as BOLD_UNDERSCORE,Ct as CHECK_LIST,xt as CODE,Lt as ELEMENT_TRANSFORMERS,mt as HEADING,vt as HIGHLIGHT,yt as INLINE_CODE,Nt as ITALIC_STAR,wt as ITALIC_UNDERSCORE,kt as LINK,Pt as MULTILINE_ELEMENT_TRANSFORMERS,Et as ORDERED_LIST,ht as QUOTE,It as STRIKETHROUGH,Rt as TEXT_FORMAT_TRANSFORMERS,_t as TEXT_MATCH_TRANSFORMERS,Bt as TRANSFORMERS,Tt as UNORDERED_LIST,et as registerMarkdownShortcuts};
package/package.json CHANGED
@@ -8,17 +8,17 @@
8
8
  "markdown"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.31.3-nightly.20250602.0",
11
+ "version": "0.32.0",
12
12
  "main": "LexicalMarkdown.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/code": "0.31.3-nightly.20250602.0",
16
- "@lexical/link": "0.31.3-nightly.20250602.0",
17
- "@lexical/list": "0.31.3-nightly.20250602.0",
18
- "@lexical/rich-text": "0.31.3-nightly.20250602.0",
19
- "@lexical/text": "0.31.3-nightly.20250602.0",
20
- "@lexical/utils": "0.31.3-nightly.20250602.0",
21
- "lexical": "0.31.3-nightly.20250602.0"
15
+ "@lexical/code": "0.32.0",
16
+ "@lexical/link": "0.32.0",
17
+ "@lexical/list": "0.32.0",
18
+ "@lexical/rich-text": "0.32.0",
19
+ "@lexical/text": "0.32.0",
20
+ "@lexical/utils": "0.32.0",
21
+ "lexical": "0.32.0"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",