@lexical/markdown 0.26.0 → 0.27.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.
@@ -732,6 +732,12 @@ function createTextFormatTransformersIndex(textTransformers) {
732
732
  *
733
733
  */
734
734
 
735
+ // Do not require this module directly! Use normal `invariant` calls.
736
+
737
+ function formatDevErrorMessage(message) {
738
+ throw new Error(message);
739
+ }
740
+
735
741
  function runElementTransformers(parentNode, anchorNode, anchorOffset, elementTransformers) {
736
742
  const grandParentNode = parentNode.getParent();
737
743
  if (!lexical.$isRootOrShadowRoot(grandParentNode) || parentNode.getFirstChild() !== anchorNode) {
@@ -983,7 +989,7 @@ function registerMarkdownShortcuts(editor, transformers = TRANSFORMERS) {
983
989
  for (const node of dependencies) {
984
990
  if (!editor.hasNode(node)) {
985
991
  {
986
- throw Error(`MarkdownShortcuts: missing dependency ${node.getType()} for transformer. Ensure node dependency is included in editor initial config.`);
992
+ formatDevErrorMessage(`MarkdownShortcuts: missing dependency ${node.getType()} for transformer. Ensure node dependency is included in editor initial config.`);
987
993
  }
988
994
  }
989
995
  }
@@ -730,6 +730,12 @@ function createTextFormatTransformersIndex(textTransformers) {
730
730
  *
731
731
  */
732
732
 
733
+ // Do not require this module directly! Use normal `invariant` calls.
734
+
735
+ function formatDevErrorMessage(message) {
736
+ throw new Error(message);
737
+ }
738
+
733
739
  function runElementTransformers(parentNode, anchorNode, anchorOffset, elementTransformers) {
734
740
  const grandParentNode = parentNode.getParent();
735
741
  if (!$isRootOrShadowRoot(grandParentNode) || parentNode.getFirstChild() !== anchorNode) {
@@ -981,7 +987,7 @@ function registerMarkdownShortcuts(editor, transformers = TRANSFORMERS) {
981
987
  for (const node of dependencies) {
982
988
  if (!editor.hasNode(node)) {
983
989
  {
984
- throw Error(`MarkdownShortcuts: missing dependency ${node.getType()} for transformer. Ensure node dependency is included in editor initial config.`);
990
+ formatDevErrorMessage(`MarkdownShortcuts: missing dependency ${node.getType()} for transformer. Ensure node dependency is included in editor initial config.`);
985
991
  }
986
992
  }
987
993
  }
@@ -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){const i=t.trim();let s=i,c="",l="",a="";const f=p(e,!0),d=p(e,!1),u=new Set;for(const t of n){const n=t.format[0],r=t.tag;x(e,n)&&!u.has(n)&&(u.add(n),x(f,n)&&o.find((e=>e.tag===r))||(o.push({format:n,tag:r}),c+=r))}for(let t=0;t<o.length;t++){const n=x(e,o[t].format),i=x(d,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||(a+=e.tag):l+=e.tag),o.pop())}break}return s=c+s+a,l+t.replace(i,(()=>s))}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)}const h="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,m=h&&"documentMode"in document?document.documentMode:null;h&&"InputEvent"in window&&!m&&new window.InputEvent("input");const N=h&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),$=h&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,T=h&&/^(?=.*Chrome).*/i.test(navigator.userAgent),E=h&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!T;function S(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 C(t){return e.$isTextNode(t)&&!t.hasFormat("code")}function L(e,t,n){let o=S(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);return C(r.nodeAfter)&&L(r.nodeAfter,t,n),C(r.nodeBefore)&&L(r.nodeBefore,t,n),void(C(r.transformedNode)&&L(r.transformedNode,t,n))}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;return C(o.nodeAfter)&&L(o.nodeAfter,t,n),C(o.nodeBefore)&&L(o.nodeBefore,t,n),void(C(o.transformedNode)&&L(o.transformedNode,t,n))}}function R(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),n[e]=N||$||E?new RegExp(`(${i})(?![${i}\\s])(.*?[^${i}\\s])${i}(?!${i})`):new RegExp(`(?<![\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?![\\\\${i}])`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp((N||$||E?"":`${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],[n,i]=I(s,e,o.multilineElement,l);n?e=i:v(t,l,o.element,r,o.textMatch)}const a=l.getChildren();for(const e of a)!n&&f(e)&&l.getChildrenSize()>1&&e.remove();null!==e.$getSelection()&&l.selectStart()}}function I(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 v(r,i,s,c,l){const a=e.$createTextNode(r),f=e.$createParagraphNode();f.append(a),i.append(f);for(const{regExp:e,replace:t}of s){const n=r.match(e);if(n&&(a.setTextContent(r.slice(n[0].length)),!1!==t(f,[a],n,!0)))break}if(L(a,c,l),f.isAttached()&&r.length>0){const r=f.getPreviousSibling();if(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(),...f.getChildren()]),f.remove())}}}function y(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var w=function(e){const t=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(let e=1;e<arguments.length;e++)n.append("v",arguments[e]);throw t.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)},b=y(w);function _(e,t,n){const o=n.length;for(let r=t;r>=o;r--){const t=r-o;if(M(e,t,n,0,o)&&" "!==e[t+o])return t}return-1}function M(e,t,n,o,r){for(let i=0;i<r;i++)if(e[t+i]!==n[o+i])return!1;return!0}const A=/^(\s*)(\d{1,})\.\s/,F=/^(\s*)[-*+]\s/,k=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,O=/^(#{1,6})\s/,B=/^>\s/,P=/^[ \t]*```(\w+)?/,D=/[ \t]*```$/,U=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,H=/^(?:\|)(.+)(?:\|)\s?$/,j=/^(\| ?:?-*:? ?)+\|\s?$/,q=e=>(t,n,o)=>{const r=e(o);r.append(...n),t.replace(r),r.select(0,0)};const z=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)},Q=(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(Q(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")},W={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:O,replace:q((e=>{const t="h"+e[1].length;return n.$createHeadingNode(t)})),type:"element"},G={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:B,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"},K={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:D},regExpStart:P,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&&q((e=>r.$createCodeNode(e?e[1]:void 0)))(t,n,o,c)},type:"multiline-element"},X={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?Q(e,n,0):null,regExp:F,replace:z("bullet"),type:"element"},V={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?Q(e,n,0):null,regExp:k,replace:z("check"),type:"element"},J={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?Q(e,n,0):null,regExp:A,replace:z("number"),type:"element"},Y={format:["code"],tag:"`",type:"text-format"},Z={format:["highlight"],tag:"==",type:"text-format"},ee={format:["bold","italic"],tag:"***",type:"text-format"},te={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},ne={format:["bold"],tag:"**",type:"text-format"},oe={format:["bold"],intraword:!1,tag:"__",type:"text-format"},re={format:["strikethrough"],tag:"~~",type:"text-format"},ie={format:["italic"],tag:"*",type:"text-format"},se={format:["italic"],intraword:!1,tag:"_",type:"text-format"},ce={dependencies:[i.LinkNode],export:(e,t,n)=>{if(!i.$isLinkNode(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 le=[W,G,X,J],ae=[K],fe=[Y,ee,te,ne,oe,Z,ie,se,re],de=[ce],ue=[...le,...ae,...fe,...de];exports.$convertFromMarkdownString=function(e,t=ue,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];U.test(i)?r.push(i):P.test(i)||D.test(i)?(o=!o,r.push(i)):o||""===i||""===s||!s||O.test(s)||O.test(i)||B.test(i)||A.test(i)||F.test(i)||k.test(i)||H.test(i)||j.test(i)||!t?r.push(i):r[r.length-1]=s+i}return r.join("\n")}(e,r);return R(t,o)(i,n)},exports.$convertToMarkdownString=function(t=ue,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=ee,exports.BOLD_ITALIC_UNDERSCORE=te,exports.BOLD_STAR=ne,exports.BOLD_UNDERSCORE=oe,exports.CHECK_LIST=V,exports.CODE=K,exports.ELEMENT_TRANSFORMERS=le,exports.HEADING=W,exports.HIGHLIGHT=Z,exports.INLINE_CODE=Y,exports.ITALIC_STAR=ie,exports.ITALIC_UNDERSCORE=se,exports.LINK=ce,exports.MULTILINE_ELEMENT_TRANSFORMERS=ae,exports.ORDERED_LIST=J,exports.QUOTE=G,exports.STRIKETHROUGH=re,exports.TEXT_FORMAT_TRANSFORMERS=fe,exports.TEXT_MATCH_TRANSFORMERS=de,exports.TRANSFORMERS=ue,exports.UNORDERED_LIST=X,exports.registerMarkdownShortcuts=function(t,n=ue){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)||b(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(s.remove(),!1!==i(t,c?[c,...e]:e,r,!1))return!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(s.remove(),!1!==i(t,c?[c,...e]:e,r,null,null,!1))return!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&&!M(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=_(r,a,o),p=u;for(;g<0&&(p=p.getPreviousSibling())&&!e.$isLineBreakNode(p);)if(e.$isTextNode(p)){const e=p.getTextContent();u=p,g=_(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(),N=m.slice(0,a)+m.slice(i+1);d.setTextContent(N);const $=u===d?N:x;u.setTextContent($.slice(0,g)+$.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("collaboration")||n.has("historic"))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(!C(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){const i=t.trim();let s=i,c="",l="",a="";const f=p(e,!0),d=p(e,!1),u=new Set;for(const t of n){const n=t.format[0],r=t.tag;x(e,n)&&!u.has(n)&&(u.add(n),x(f,n)&&o.find((e=>e.tag===r))||(o.push({format:n,tag:r}),c+=r))}for(let t=0;t<o.length;t++){const n=x(e,o[t].format),i=x(d,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||(a+=e.tag):l+=e.tag),o.pop())}break}return s=c+s+a,l+t.replace(i,(()=>s))}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)}const h="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,m=h&&"documentMode"in document?document.documentMode:null;h&&"InputEvent"in window&&!m&&new window.InputEvent("input");const N=h&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),$=h&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,T=h&&/^(?=.*Chrome).*/i.test(navigator.userAgent),E=h&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!T;function S(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 C(t){return e.$isTextNode(t)&&!t.hasFormat("code")}function L(e,t,n){let o=S(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);return C(r.nodeAfter)&&L(r.nodeAfter,t,n),C(r.nodeBefore)&&L(r.nodeBefore,t,n),void(C(r.transformedNode)&&L(r.transformedNode,t,n))}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;return C(o.nodeAfter)&&L(o.nodeAfter,t,n),C(o.nodeBefore)&&L(o.nodeBefore,t,n),void(C(o.transformedNode)&&L(o.transformedNode,t,n))}}function R(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),n[e]=N||$||E?new RegExp(`(${i})(?![${i}\\s])(.*?[^${i}\\s])${i}(?!${i})`):new RegExp(`(?<![\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?![\\\\${i}])`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp((N||$||E?"":`${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],[n,i]=I(s,e,o.multilineElement,l);n?e=i:v(t,l,o.element,r,o.textMatch)}const a=l.getChildren();for(const e of a)!n&&f(e)&&l.getChildrenSize()>1&&e.remove();null!==e.$getSelection()&&l.selectStart()}}function I(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 v(r,i,s,c,l){const a=e.$createTextNode(r),f=e.$createParagraphNode();f.append(a),i.append(f);for(const{regExp:e,replace:t}of s){const n=r.match(e);if(n&&(a.setTextContent(r.slice(n[0].length)),!1!==t(f,[a],n,!0)))break}if(L(a,c,l),f.isAttached()&&r.length>0){const r=f.getPreviousSibling();if(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(),...f.getChildren()]),f.remove())}}}function y(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 w(e,t,n){const o=n.length;for(let r=t;r>=o;r--){const t=r-o;if(b(e,t,n,0,o)&&" "!==e[t+o])return t}return-1}function b(e,t,n,o,r){for(let i=0;i<r;i++)if(e[t+i]!==n[o+i])return!1;return!0}const _=/^(\s*)(\d{1,})\.\s/,A=/^(\s*)[-*+]\s/,M=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,F=/^(#{1,6})\s/,k=/^>\s/,O=/^[ \t]*```(\w+)?/,B=/[ \t]*```$/,D=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,P=/^(?:\|)(.+)(?:\|)\s?$/,U=/^(\| ?:?-*:? ?)+\|\s?$/,H=e=>(t,n,o)=>{const r=e(o);r.append(...n),t.replace(r),r.select(0,0)};const j=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)},q=(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(q(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")},z={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:F,replace:H((e=>{const t="h"+e[1].length;return n.$createHeadingNode(t)})),type:"element"},Q={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:k,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"},W={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:B},regExpStart:O,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&&H((e=>r.$createCodeNode(e?e[1]:void 0)))(t,n,o,c)},type:"multiline-element"},G={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?q(e,n,0):null,regExp:A,replace:j("bullet"),type:"element"},K={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?q(e,n,0):null,regExp:M,replace:j("check"),type:"element"},X={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?q(e,n,0):null,regExp:_,replace:j("number"),type:"element"},V={format:["code"],tag:"`",type:"text-format"},J={format:["highlight"],tag:"==",type:"text-format"},Y={format:["bold","italic"],tag:"***",type:"text-format"},Z={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},ee={format:["bold"],tag:"**",type:"text-format"},te={format:["bold"],intraword:!1,tag:"__",type:"text-format"},ne={format:["strikethrough"],tag:"~~",type:"text-format"},oe={format:["italic"],tag:"*",type:"text-format"},re={format:["italic"],intraword:!1,tag:"_",type:"text-format"},ie={dependencies:[i.LinkNode],export:(e,t,n)=>{if(!i.$isLinkNode(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 se=[z,Q,G,X],ce=[W],le=[V,Y,Z,ee,te,J,oe,re,ne],ae=[ie],fe=[...se,...ce,...le,...ae];exports.$convertFromMarkdownString=function(e,t=fe,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];D.test(i)?r.push(i):O.test(i)||B.test(i)?(o=!o,r.push(i)):o||""===i||""===s||!s||F.test(s)||F.test(i)||k.test(i)||_.test(i)||A.test(i)||M.test(i)||P.test(i)||U.test(i)||!t?r.push(i):r[r.length-1]=s+i}return r.join("\n")}(e,r);return R(t,o)(i,n)},exports.$convertToMarkdownString=function(t=fe,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=Y,exports.BOLD_ITALIC_UNDERSCORE=Z,exports.BOLD_STAR=ee,exports.BOLD_UNDERSCORE=te,exports.CHECK_LIST=K,exports.CODE=W,exports.ELEMENT_TRANSFORMERS=se,exports.HEADING=z,exports.HIGHLIGHT=J,exports.INLINE_CODE=V,exports.ITALIC_STAR=oe,exports.ITALIC_UNDERSCORE=re,exports.LINK=ie,exports.MULTILINE_ELEMENT_TRANSFORMERS=ce,exports.ORDERED_LIST=X,exports.QUOTE=Q,exports.STRIKETHROUGH=ne,exports.TEXT_FORMAT_TRANSFORMERS=le,exports.TEXT_MATCH_TRANSFORMERS=ae,exports.TRANSFORMERS=fe,exports.UNORDERED_LIST=G,exports.registerMarkdownShortcuts=function(t,n=fe){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)||y(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(s.remove(),!1!==i(t,c?[c,...e]:e,r,!1))return!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(s.remove(),!1!==i(t,c?[c,...e]:e,r,null,null,!1))return!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&&!b(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=w(r,a,o),p=u;for(;g<0&&(p=p.getPreviousSibling())&&!e.$isLineBreakNode(p);)if(e.$isTextNode(p)){const e=p.getTextContent();u=p,g=w(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(),N=m.slice(0,a)+m.slice(i+1);d.setTextContent(N);const $=u===d?N:x;u.setTextContent($.slice(0,g)+$.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("collaboration")||n.has("historic"))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(!C(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,$isRangeSelection as a,$isRootOrShadowRoot as u,$createRangeSelection as g,$setSelection as p}from"lexical";import{$isListNode as d,$isListItemNode as m,ListNode as h,ListItemNode as x,$createListItemNode as v,$createListNode as E}from"@lexical/list";import{$isQuoteNode as T,HeadingNode as y,$isHeadingNode as C,QuoteNode as b,$createQuoteNode as S,$createHeadingNode as w}from"@lexical/rich-text";import{$findMatchingParent as $}from"@lexical/utils";import{$isCodeNode as I,CodeNode as F,$createCodeNode as N}from"@lexical/code";import{LinkNode as P,$isLinkNode as M,$createLinkNode as k}from"@lexical/link";function L(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 R(t){const e=L(t,(t=>t.type));return{element:e.element||[],multilineElement:e["multiline-element"]||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const A=/[!-/:-@[-`{-~\s]/,_=/^\s{0,3}$/;function B(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&_.test(o.getTextContent())}function j(t,e,n,i){for(const o of e){if(!o.export)continue;const e=o.export(t,(t=>z(t,n,i)));if(null!=e)return e}return o(t)?z(t,n,i):r(t)?t.getTextContent():null}function z(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=>z(t,n,s,l,[...c,...l])),((t,e)=>U(t,e,n,l,c)));if(null!=o){f.push(o);continue t}}i(t)?f.push("\n"):e(t)?f.push(U(t,t.getTextContent(),n,l,c)):o(t)?f.push(z(t,n,s,l,c)):r(t)&&f.push(t.getTextContent())}return f.join("")}function U(t,e,n,o,r){const i=e.trim();let s=i,l="",c="",f="";const a=W(t,!0),u=W(t,!1),g=new Set;for(const e of n){const n=e.format[0],r=e.tag;D(t,n)&&!g.has(n)&&(g.add(n),D(a,n)&&o.find((t=>t.tag===r))||(o.push({format:n,tag:r}),l+=r))}for(let e=0;e<o.length;e++){const n=D(t,o[e].format),i=D(u,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||(f+=t.tag):c+=t.tag),o.pop())}break}return s=l+s+f,c+e.replace(i,(()=>s))}function W(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 D(t,n){return e(t)&&t.hasFormat(n)}const O="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,K=O&&"documentMode"in document?document.documentMode:null;O&&"InputEvent"in window&&!K&&new window.InputEvent("input");const V=O&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),q=O&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,G=O&&/^(?=.*Chrome).*/i.test(navigator.userAgent),H=O&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!G;function J(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 Q(t){return e(t)&&!t.hasFormat("code")}function X(t,e,n){let o=J(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);return Q(r.nodeAfter)&&X(r.nodeAfter,e,n),Q(r.nodeBefore)&&X(r.nodeBefore,e,n),void(Q(r.transformedNode)&&X(r.transformedNode,e,n))}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;return Q(o.nodeAfter)&&X(o.nodeAfter,e,n),Q(o.nodeBefore)&&X(o.nodeBefore,e,n),void(Q(o.transformedNode)&&X(o.transformedNode,e,n))}}function Y(t,e=!1){const o=R(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),n[t]=V||q||H?new RegExp(`(${i})(?![${i}\\s])(.*?[^${i}\\s])${i}(?!${i})`):new RegExp(`(?<![\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?![\\\\${i}])`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp((V||q||H?"":`${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 e=l[t],[n,i]=Z(l,t,o.multilineElement,f);n?t=i:tt(e,f,o.element,r,o.textMatch)}const a=f.getChildren();for(const t of a)!e&&B(t)&&f.getChildrenSize()>1&&t.remove();null!==s()&&f.selectStart()}}function Z(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 tt(e,n,o,r,i){const s=l(e),a=c();a.append(s),n.append(a);for(const{regExp:t,replace:n}of o){const o=e.match(t);if(o&&(s.setTextContent(e.slice(o[0].length)),!1!==n(a,[s],o,!0)))break}if(X(s,r,i),a.isAttached()&&e.length>0){const e=a.getPreviousSibling();if(t(e)||T(e)||d(e)){let t=e;if(d(e)){const n=e.getLastDescendant();t=null==n?null:$(n,m)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[f(),...a.getChildren()]),a.remove())}}}function et(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var nt=et((function(t){const e=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",t);for(let t=1;t<arguments.length;t++)n.append("v",arguments[t]);throw e.search=n.toString(),Error(`Minified Lexical error #${t}; visit ${e.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function ot(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(rt(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function rt(t,e,n,o,r){for(let i=0;i<r;i++)if(t[e+i]!==n[o+i])return!1;return!0}function it(t,n=zt){const o=R(n),r=L(o.textFormat,(({tag:t})=>t[t.length-1])),l=L(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)||nt(173,e.getType())}}const c=(t,n,c)=>{(function(t,e,n,o){const r=t.getParent();if(!u(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(i.remove(),!1!==s(t,l?[l,...r]:r,o,!1))return!0}}return!1})(t,n,c,o.element)||function(t,e,n,o){const r=t.getParent();if(!u(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(i.remove(),!1!==s(t,l?[l,...r]:r,o,null,null,!1))return!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,u=l-f+1;if(f>1&&!rt(r,u,o,0,f))continue;if(" "===r[u-1])continue;const d=r[l+1];if(!1===n.intraword&&d&&!A.test(d))continue;const m=t;let h=m,x=ot(r,u,o),v=h;for(;x<0&&(v=v.getPreviousSibling())&&!i(v);)if(e(v)){const t=v.getTextContent();h=v,x=ot(t,t.length,o)}if(x<0)continue;if(h===m&&x+f===u)continue;const E=h.getTextContent();if(x>0&&E[x-1]===c)continue;const T=E[x-1];if(!1===n.intraword&&T&&!A.test(T))continue;const y=m.getTextContent(),C=y.slice(0,u)+y.slice(l+1);m.setTextContent(C);const b=h===m?C:E;h.setTextContent(b.slice(0,x)+b.slice(x+f));const S=s(),w=g();p(w);const $=l-f*(h===m?2:1)+1;w.anchor.set(h.__key,x,"text"),w.focus.set(m.__key,$,"text");for(const t of n.format)w.hasFormat(t)||w.formatText(t);w.anchor.set(w.focus.key,w.focus.offset,w.focus.type);for(const t of n.format)w.hasFormat(t)&&w.toggleFormat(t);return a(S)&&(w.format=S.format),!0}}(n,c,r)};return t.registerUpdateListener((({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:i})=>{if(n.has("collaboration")||n.has("historic"))return;if(t.isComposing())return;const l=r.read(s),f=i.read(s);if(!a(f)||!a(l)||!l.isCollapsed()||l.is(f))return;const u=l.anchor.key,g=l.anchor.offset,p=r._nodeMap.get(u);!e(p)||!o.has(u)||1!==g&&g>f.anchor.offset+1||t.update((()=>{if(!Q(p))return;const t=p.getParent();null===t||I(t)||c(t,p,l.anchor.offset)}))}))}const st=/^(\s*)(\d{1,})\.\s/,lt=/^(\s*)[-*+]\s/,ct=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,ft=/^(#{1,6})\s/,at=/^>\s/,ut=/^[ \t]*```(\w+)?/,gt=/[ \t]*```$/,pt=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,dt=/^(?:\|)(.+)(?:\|)\s?$/,mt=/^(\| ?:?-*:? ?)+\|\s?$/,ht=t=>(e,n,o)=>{const r=t(o);r.append(...n),e.replace(r),r.select(0,0)};const xt=t=>(e,n,o)=>{const r=e.getPreviousSibling(),i=e.getNextSibling(),s=v("check"===t?"x"===o[3]:void 0);if(d(i)&&i.getListType()===t){const t=i.getFirstChild();null!==t?t.insertBefore(s):i.append(s),e.remove()}else if(d(r)&&r.getListType()===t)r.append(s),e.remove();else{const n=E(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)},vt=(t,e,n)=>{const o=[],r=t.getChildren();let i=0;for(const s of r)if(m(s)){if(1===s.getChildrenSize()){const t=s.getFirstChild();if(d(t)){o.push(vt(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")},Et={dependencies:[y],export:(t,e)=>{if(!C(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:ft,replace:ht((t=>{const e="h"+t[1].length;return w(e)})),type:"element"},Tt={dependencies:[b],export:(t,e)=>{if(!T(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:at,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(T(n))return n.splice(n.getChildrenSize(),0,[f(),...e]),n.select(0,0),void t.remove()}const r=S();r.append(...e),t.replace(r),r.select(0,0)},type:"element"},yt={dependencies:[F],export:t=>{if(!I(t))return null;const e=t.getTextContent();return"```"+(t.getLanguage()||"")+(e?"\n"+e:"")+"\n```"},regExpEnd:{optional:!0,regExp:gt},regExpStart:ut,replace:(t,e,n,o,r,i)=>{let s,c;if(!e&&r){if(1===r.length)o?(s=N(),c=n[1]+r[0]):(s=N(n[1]),c=r[0].startsWith(" ")?r[0].slice(1):r[0]);else{if(s=N(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&&ht((t=>N(t?t[1]:void 0)))(t,e,n,i)},type:"multiline-element"},Ct={dependencies:[h,x],export:(t,e)=>d(t)?vt(t,e,0):null,regExp:lt,replace:xt("bullet"),type:"element"},bt={dependencies:[h,x],export:(t,e)=>d(t)?vt(t,e,0):null,regExp:ct,replace:xt("check"),type:"element"},St={dependencies:[h,x],export:(t,e)=>d(t)?vt(t,e,0):null,regExp:st,replace:xt("number"),type:"element"},wt={format:["code"],tag:"`",type:"text-format"},$t={format:["highlight"],tag:"==",type:"text-format"},It={format:["bold","italic"],tag:"***",type:"text-format"},Ft={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Nt={format:["bold"],tag:"**",type:"text-format"},Pt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Mt={format:["strikethrough"],tag:"~~",type:"text-format"},kt={format:["italic"],tag:"*",type:"text-format"},Lt={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Rt={dependencies:[P],export:(t,e,n)=>{if(!M(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=k(o,{title:r}),s=l(n);return s.setFormat(t.getFormat()),i.append(s),t.replace(i),s},trigger:")",type:"text-match"};const At=[Et,Tt,Ct,St],_t=[yt],Bt=[wt,It,Ft,Nt,Pt,$t,kt,Lt,Mt],jt=[Rt],zt=[...At,..._t,...Bt,...jt];function Ut(t,e=zt,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];pt.test(i)?r.push(i):ut.test(i)||gt.test(i)?(o=!o,r.push(i)):o||""===i||""===s||!s||ft.test(s)||ft.test(i)||at.test(i)||st.test(i)||lt.test(i)||ct.test(i)||dt.test(i)||mt.test(i)||!e?r.push(i):r[r.length-1]=s+i}return r.join("\n")}(t,r);return Y(e,o)(i,n)}function Wt(t=zt,e,o=!1){const r=function(t,e=!1){const o=R(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=j(n,r,s,o.textMatch);null!=c&&e.push(i&&t>0&&!B(n)&&!B(l[t-1])?"\n".concat(c):c)}return e.join("\n")}}(t,o);return r(e)}export{Ut as $convertFromMarkdownString,Wt as $convertToMarkdownString,It as BOLD_ITALIC_STAR,Ft as BOLD_ITALIC_UNDERSCORE,Nt as BOLD_STAR,Pt as BOLD_UNDERSCORE,bt as CHECK_LIST,yt as CODE,At as ELEMENT_TRANSFORMERS,Et as HEADING,$t as HIGHLIGHT,wt as INLINE_CODE,kt as ITALIC_STAR,Lt as ITALIC_UNDERSCORE,Rt as LINK,_t as MULTILINE_ELEMENT_TRANSFORMERS,St as ORDERED_LIST,Tt as QUOTE,Mt as STRIKETHROUGH,Bt as TEXT_FORMAT_TRANSFORMERS,jt as TEXT_MATCH_TRANSFORMERS,zt as TRANSFORMERS,Ct as UNORDERED_LIST,it 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 c,$createParagraphNode as l,$createLineBreakNode as f,$isRangeSelection as a,$isRootOrShadowRoot as u,$createRangeSelection as g,$setSelection as p}from"lexical";import{$isListNode as d,$isListItemNode as m,ListNode as h,ListItemNode as x,$createListItemNode as E,$createListNode as T}from"@lexical/list";import{$isQuoteNode as v,HeadingNode as C,$isHeadingNode as y,QuoteNode as S,$createQuoteNode as b,$createHeadingNode as w}from"@lexical/rich-text";import{$findMatchingParent as $}from"@lexical/utils";import{$isCodeNode as I,CodeNode as F,$createCodeNode as N}from"@lexical/code";import{LinkNode as P,$isLinkNode as k,$createLinkNode as L}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 R(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]/,B=/^\s{0,3}$/;function _(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&B.test(o.getTextContent())}function j(t,e,n,i){for(const o of e){if(!o.export)continue;const e=o.export(t,(t=>z(t,n,i)));if(null!=e)return e}return o(t)?z(t,n,i):r(t)?t.getTextContent():null}function z(t,n,s,c,l){const f=[],a=t.getChildren();c||(c=[]),l||(l=[]);t:for(const t of a){for(const e of s){if(!e.export)continue;const o=e.export(t,(t=>z(t,n,s,c,[...l,...c])),((t,e)=>U(t,e,n,c,l)));if(null!=o){f.push(o);continue t}}i(t)?f.push("\n"):e(t)?f.push(U(t,t.getTextContent(),n,c,l)):o(t)?f.push(z(t,n,s,c,l)):r(t)&&f.push(t.getTextContent())}return f.join("")}function U(t,e,n,o,r){const i=e.trim();let s=i,c="",l="",f="";const a=W(t,!0),u=W(t,!1),g=new Set;for(const e of n){const n=e.format[0],r=e.tag;D(t,n)&&!g.has(n)&&(g.add(n),D(a,n)&&o.find((t=>t.tag===r))||(o.push({format:n,tag:r}),c+=r))}for(let e=0;e<o.length;e++){const n=D(t,o[e].format),i=D(u,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||(f+=t.tag):l+=t.tag),o.pop())}break}return s=c+s+f,l+e.replace(i,(()=>s))}function W(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 D(t,n){return e(t)&&t.hasFormat(n)}const K="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,O=K&&"documentMode"in document?document.documentMode:null;K&&"InputEvent"in window&&!O&&new window.InputEvent("input");const V=K&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),q=K&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,G=K&&/^(?=.*Chrome).*/i.test(navigator.userAgent),H=K&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!G;function J(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 Q(t){return e(t)&&!t.hasFormat("code")}function X(t,e,n){let o=J(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 c=e.index||0,l=t.getEndIndex?t.getEndIndex(n,e):c+e[0].length;!1!==l&&(void 0===o||void 0===r||c<o&&l>r)&&(o=c,r=l,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,c,l;if(r[0]===i?s=t:0===e?[s,c]=t.splitText(n):[l,s,c]=t.splitText(e,n),s.setTextContent(r[2]),o)for(const t of o.format)s.hasFormat(t)||s.toggleFormat(t);return{nodeAfter:c,nodeBefore:l,transformedNode:s}}(t,o.startIndex,o.endIndex,o.transformer,o.match);return Q(r.nodeAfter)&&X(r.nodeAfter,e,n),Q(r.nodeBefore)&&X(r.nodeBefore,e,n),void(Q(r.transformedNode)&&X(r.transformedNode,e,n))}if(r){const o=function(t,e,n,o,r){let i,s,c;return 0===e?[i,s]=t.splitText(n):[c,i,s]=t.splitText(e,n),o.replace?{nodeAfter:s,nodeBefore:c,transformedNode:o.replace(i,r)||void 0}:null}(t,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;return Q(o.nodeAfter)&&X(o.nodeAfter,e,n),Q(o.nodeBefore)&&X(o.nodeBefore,e,n),void(Q(o.transformedNode)&&X(o.transformedNode,e,n))}}function Y(t,e=!1){const o=R(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),n[t]=V||q||H?new RegExp(`(${i})(?![${i}\\s])(.*?[^${i}\\s])${i}(?!${i})`):new RegExp(`(?<![\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?![\\\\${i}])`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp((V||q||H?"":`${r}`)+"("+o.join("|")+")","g"),transformersByTag:e}}(o.textFormat);return(t,i)=>{const c=t.split("\n"),l=c.length,f=i||n();f.clear();for(let t=0;t<l;t++){const e=c[t],[n,i]=Z(c,t,o.multilineElement,f);n?t=i:tt(e,f,o.element,r,o.textMatch)}const a=f.getChildren();for(const t of a)!e&&_(t)&&f.getChildrenSize()>1&&t.remove();null!==s()&&f.selectStart()}}function Z(t,e,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:i,regExpStart:s,replace:c}=r,l=t[e].match(s);if(!l)continue;if(n){const i=n({lines:t,rootNode:o,startLineIndex:e,startMatch:l,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===l.index){u++;continue}const r=[];if(n&&e===u)r.push(t[e].slice(l[0].length,-n[0].length));else for(let o=e;o<=u;o++)if(o===e){const e=t[o].slice(l[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!==c(o,null,l,n,r,!0))return[!0,u];break}}return[!1,e]}function tt(e,n,o,r,i){const s=c(e),a=l();a.append(s),n.append(a);for(const{regExp:t,replace:n}of o){const o=e.match(t);if(o&&(s.setTextContent(e.slice(o[0].length)),!1!==n(a,[s],o,!0)))break}if(X(s,r,i),a.isAttached()&&e.length>0){const e=a.getPreviousSibling();if(t(e)||v(e)||d(e)){let t=e;if(d(e)){const n=e.getLastDescendant();t=null==n?null:$(n,m)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[f(),...a.getChildren()]),a.remove())}}}function et(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 nt(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(ot(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function ot(t,e,n,o,r){for(let i=0;i<r;i++)if(t[e+i]!==n[o+i])return!1;return!0}function rt(t,n=jt){const o=R(n),r=M(o.textFormat,(({tag:t})=>t[t.length-1])),c=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)||et(173,e.getType())}}const l=(t,n,l)=>{(function(t,e,n,o){const r=t.getParent();if(!u(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,c]=e.splitText(n);if(i.remove(),!1!==s(t,c?[c,...r]:r,o,!1))return!0}}return!1})(t,n,l,o.element)||function(t,e,n,o){const r=t.getParent();if(!u(r)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(" "!==i[n-1])return!1;for(const{regExpStart:r,replace:s,regExpEnd:c}of o){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const o=i.match(r);if(o&&o[0].length===(o[0].endsWith(" ")?n:n-1)){const r=e.getNextSiblings(),[i,c]=e.splitText(n);if(i.remove(),!1!==s(t,c?[c,...r]:r,o,null,null,!1))return!0}}return!1}(t,n,l,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,l,c)||function(t,n,o){const r=t.getTextContent(),c=n-1,l=r[c],f=o[l];if(!f)return!1;for(const n of f){const{tag:o}=n,f=o.length,u=c-f+1;if(f>1&&!ot(r,u,o,0,f))continue;if(" "===r[u-1])continue;const d=r[c+1];if(!1===n.intraword&&d&&!A.test(d))continue;const m=t;let h=m,x=nt(r,u,o),E=h;for(;x<0&&(E=E.getPreviousSibling())&&!i(E);)if(e(E)){const t=E.getTextContent();h=E,x=nt(t,t.length,o)}if(x<0)continue;if(h===m&&x+f===u)continue;const T=h.getTextContent();if(x>0&&T[x-1]===l)continue;const v=T[x-1];if(!1===n.intraword&&v&&!A.test(v))continue;const C=m.getTextContent(),y=C.slice(0,u)+C.slice(c+1);m.setTextContent(y);const S=h===m?y:T;h.setTextContent(S.slice(0,x)+S.slice(x+f));const b=s(),w=g();p(w);const $=c-f*(h===m?2:1)+1;w.anchor.set(h.__key,x,"text"),w.focus.set(m.__key,$,"text");for(const t of n.format)w.hasFormat(t)||w.formatText(t);w.anchor.set(w.focus.key,w.focus.offset,w.focus.type);for(const t of n.format)w.hasFormat(t)&&w.toggleFormat(t);return a(b)&&(w.format=b.format),!0}}(n,l,r)};return t.registerUpdateListener((({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:i})=>{if(n.has("collaboration")||n.has("historic"))return;if(t.isComposing())return;const c=r.read(s),f=i.read(s);if(!a(f)||!a(c)||!c.isCollapsed()||c.is(f))return;const u=c.anchor.key,g=c.anchor.offset,p=r._nodeMap.get(u);!e(p)||!o.has(u)||1!==g&&g>f.anchor.offset+1||t.update((()=>{if(!Q(p))return;const t=p.getParent();null===t||I(t)||l(t,p,c.anchor.offset)}))}))}const it=/^(\s*)(\d{1,})\.\s/,st=/^(\s*)[-*+]\s/,ct=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,lt=/^(#{1,6})\s/,ft=/^>\s/,at=/^[ \t]*```(\w+)?/,ut=/[ \t]*```$/,gt=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,pt=/^(?:\|)(.+)(?:\|)\s?$/,dt=/^(\| ?:?-*:? ?)+\|\s?$/,mt=t=>(e,n,o)=>{const r=t(o);r.append(...n),e.replace(r),r.select(0,0)};const ht=t=>(e,n,o)=>{const r=e.getPreviousSibling(),i=e.getNextSibling(),s=E("check"===t?"x"===o[3]:void 0);if(d(i)&&i.getListType()===t){const t=i.getFirstChild();null!==t?t.insertBefore(s):i.append(s),e.remove()}else if(d(r)&&r.getListType()===t)r.append(s),e.remove();else{const n=T(t,"number"===t?Number(o[2]):void 0);n.append(s),e.replace(n)}s.append(...n),s.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&&s.setIndent(c)},xt=(t,e,n)=>{const o=[],r=t.getChildren();let i=0;for(const s of r)if(m(s)){if(1===s.getChildrenSize()){const t=s.getFirstChild();if(d(t)){o.push(xt(t,e,n+1));continue}}const r=" ".repeat(4*n),c=t.getListType(),l="number"===c?`${t.getStart()+i}. `:"check"===c?`- [${s.getChecked()?"x":" "}] `:"- ";o.push(r+l+e(s)),i++}return o.join("\n")},Et={dependencies:[C],export:(t,e)=>{if(!y(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:lt,replace:mt((t=>{const e="h"+t[1].length;return w(e)})),type:"element"},Tt={dependencies:[S],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:ft,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=b();r.append(...e),t.replace(r),r.select(0,0)},type:"element"},vt={dependencies:[F],export:t=>{if(!I(t))return null;const e=t.getTextContent();return"```"+(t.getLanguage()||"")+(e?"\n"+e:"")+"\n```"},regExpEnd:{optional:!0,regExp:ut},regExpStart:at,replace:(t,e,n,o,r,i)=>{let s,l;if(!e&&r){if(1===r.length)o?(s=N(),l=n[1]+r[0]):(s=N(n[1]),l=r[0].startsWith(" ")?r[0].slice(1):r[0]);else{if(s=N(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();l=r.join("\n")}const e=c(l);s.append(e),t.append(s)}else e&&mt((t=>N(t?t[1]:void 0)))(t,e,n,i)},type:"multiline-element"},Ct={dependencies:[h,x],export:(t,e)=>d(t)?xt(t,e,0):null,regExp:st,replace:ht("bullet"),type:"element"},yt={dependencies:[h,x],export:(t,e)=>d(t)?xt(t,e,0):null,regExp:ct,replace:ht("check"),type:"element"},St={dependencies:[h,x],export:(t,e)=>d(t)?xt(t,e,0):null,regExp:it,replace:ht("number"),type:"element"},bt={format:["code"],tag:"`",type:"text-format"},wt={format:["highlight"],tag:"==",type:"text-format"},$t={format:["bold","italic"],tag:"***",type:"text-format"},It={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Ft={format:["bold"],tag:"**",type:"text-format"},Nt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Pt={format:["strikethrough"],tag:"~~",type:"text-format"},kt={format:["italic"],tag:"*",type:"text-format"},Lt={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Mt={dependencies:[P],export:(t,e,n)=>{if(!k(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=L(o,{title:r}),s=c(n);return s.setFormat(t.getFormat()),i.append(s),t.replace(i),s},trigger:")",type:"text-match"};const Rt=[Et,Tt,Ct,St],At=[vt],Bt=[bt,$t,It,Ft,Nt,wt,kt,Lt,Pt],_t=[Mt],jt=[...Rt,...At,...Bt,..._t];function zt(t,e=jt,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];gt.test(i)?r.push(i):at.test(i)||ut.test(i)?(o=!o,r.push(i)):o||""===i||""===s||!s||lt.test(s)||lt.test(i)||ft.test(i)||it.test(i)||st.test(i)||ct.test(i)||pt.test(i)||dt.test(i)||!e?r.push(i):r[r.length-1]=s+i}return r.join("\n")}(t,r);return Y(e,o)(i,n)}function Ut(t=jt,e,o=!1){const r=function(t,e=!1){const o=R(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=[],c=(t||n()).getChildren();for(let t=0;t<c.length;t++){const n=c[t],l=j(n,r,s,o.textMatch);null!=l&&e.push(i&&t>0&&!_(n)&&!_(c[t-1])?"\n".concat(l):l)}return e.join("\n")}}(t,o);return r(e)}export{zt as $convertFromMarkdownString,Ut as $convertToMarkdownString,$t as BOLD_ITALIC_STAR,It as BOLD_ITALIC_UNDERSCORE,Ft as BOLD_STAR,Nt as BOLD_UNDERSCORE,yt as CHECK_LIST,vt as CODE,Rt as ELEMENT_TRANSFORMERS,Et as HEADING,wt as HIGHLIGHT,bt as INLINE_CODE,kt as ITALIC_STAR,Lt as ITALIC_UNDERSCORE,Mt as LINK,At as MULTILINE_ELEMENT_TRANSFORMERS,St as ORDERED_LIST,Tt as QUOTE,Pt as STRIKETHROUGH,Bt as TEXT_FORMAT_TRANSFORMERS,_t as TEXT_MATCH_TRANSFORMERS,jt as TRANSFORMERS,Ct as UNORDERED_LIST,rt as registerMarkdownShortcuts};
package/package.json CHANGED
@@ -8,17 +8,17 @@
8
8
  "markdown"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.26.0",
11
+ "version": "0.27.0",
12
12
  "main": "LexicalMarkdown.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/code": "0.26.0",
16
- "@lexical/link": "0.26.0",
17
- "@lexical/list": "0.26.0",
18
- "@lexical/rich-text": "0.26.0",
19
- "@lexical/text": "0.26.0",
20
- "@lexical/utils": "0.26.0",
21
- "lexical": "0.26.0"
15
+ "@lexical/code": "0.27.0",
16
+ "@lexical/link": "0.27.0",
17
+ "@lexical/list": "0.27.0",
18
+ "@lexical/rich-text": "0.27.0",
19
+ "@lexical/text": "0.27.0",
20
+ "@lexical/utils": "0.27.0",
21
+ "lexical": "0.27.0"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",