@lexical/markdown 0.51.1-nightly.20260925.0 → 0.52.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.
- package/dist/LexicalMarkdown.prod.js +1 -1
- package/package.json +10 -10
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$isParagraphNode as t,$isTextNode as e,$setState as n,$createTextNode as r,$getState as o,$findMatchingParent as s,$createLineBreakNode as i,createState as l,$isLineBreakNode as c,$getRoot as f,$isElementNode as a,$isDecoratorNode as u,$isTabNode as d,$createTabNode as g,$createParagraphNode as h,mergeRegister as p,COLLABORATION_TAG as m,HISTORIC_TAG as x,COMPOSITION_END_TAG as C,$getSelection as T,$isRangeSelection as I,$addUpdateTag as $,HISTORY_PUSH_TAG as v,KEY_ENTER_COMMAND as y,COMMAND_PRIORITY_LOW as S,$isRootOrShadowRoot as E,$createRangeSelection as b,$setSelection as w,TEXT_TYPE_TO_FORMAT as k,ArtificialNode__DO_NOT_USE as N}from"lexical";import{$sliceSelectedTextNodeContent as F}from"@lexical/selection";import{CodeNode as O,$createCodeNode as P,$isCodeNode as M}from"@lexical/code-core";import{LinkNode as B,$isLinkNode as L,$createLinkNode as _,$isAutoLinkNode as R}from"@lexical/link";import{ListNode as j,ListItemNode as z,$isListNode as A,$createListItemNode as W,$createListNode as U,$isListItemNode as D}from"@lexical/list";import{HeadingNode as Z,QuoteNode as H,$isHeadingNode as K,$isQuoteNode as X,$createQuoteNode as q,$createHeadingNode as G}from"@lexical/rich-text";function J(t,e){const n={};for(const r of t){const t=e(r);t&&(n[t]?n[t].push(r):n[t]=[r])}return n}function Q(t){const e=J(t,t=>t.type);return{element:e.element||[],multilineElement:e["multiline-element"]||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const V=/[!-/:-@[-`{-~\s]/,Y=/\s/,tt=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,et=/^\s{0,3}$/;function nt(n){if(!t(n))return!1;const r=n.getFirstChild();return null==r||1===n.getChildrenSize()&&e(r)&&et.test(r.getTextContent())}function rt(t){return t.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(t,e)=>String.fromCodePoint(Number(e)))}const ot=/^(\s*)(\d{1,})\.\s/,st=/^(\s*)[-*+]\s/,it=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,lt=/^(#{1,6})\s/,ct=/^>\s/,ft=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,at=/^[ \t]*`{3,}$/,ut=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,dt=/^(?:\|)(.+)(?:\|)\s?$/;function gt(t){if("|"!==t[0])return!1;const{length:e}=t;let n=1,r=0;for(;n<e;){let e=n;for(" "===t[e]&&e++,":"===t[e]&&e++;"-"===t[e];)e++;if(":"===t[e]&&e++," "===t[e]&&e++,"|"!==t[e])break;r++,n=e+1}return r>0&&(n===e||n===e-1&&/\s/.test(t[n]))}const ht=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,pt=/^<\/[a-z_][\w-]*\s*>/i,mt=t=>new RegExp(`(?:${t.source})$`,t.flags),xt=/* @__PURE__ */l("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),Ct=/* @__PURE__ */l("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),Tt=/* @__PURE__ */l("mdCodeMeta",{parse:t=>"string"==typeof t?t:"",resetOnCopyNode:!0}),It=/* @__PURE__ */l("mdHardLineBreak",{parse:t=>"string"==typeof t&&/^(\\| {2,})$/.test(t)?t:"",resetOnCopyNode:!0});function $t(t){if(t.endsWith("\\")){let e=0;for(let n=t.length-1;n>=0&&"\\"===t[n];n--)e++;return e%2==1?[t.slice(0,-1),"\\"]:null}const e=t.match(/^(.*?\S)( {2,})$/);return e?[e[1],e[2]]:null}function vt(t){const r=i(),o=function(t){const n=t.getChildren(),r=n.length-1,o=n[r];if(!e(o))return null;const s=o.getTextContent(),i=$t(s);if(null!==i){const[t,e]=i;return o.setTextContent(t),e}return/^ {2,}$/.test(s)&&function(t,e){for(let n=e-1;n>=0;n--){if(c(t[n]))return!1;if(/\S/.test(t[n].getTextContent()))return!0}return!1}(n,r)?(o.setTextContent(""),s):null}(t);return null!==o&&n(r,It,o),r}function yt(t){return X(t)}function St(t,e){let n=0;for(;n<e&&(" "===t[n]||"\t"===t[n]);)n++;return t.slice(n)}function Et(t,e){const r=t.getLastChild();e&&M(r)&&n(r,Tt,e)}const bt=t=>(e,n,r,o)=>{const s=t(r);s.append(...n),e.replace(s),o||s.select(0,0)};function wt(t){let e=0;for(const n of t)e+="\t"===n?4-e%4:1;return e}let kt=null,Nt=!1;const Ft=t=>(e,r,o,s)=>{if(K(e)||!s&&yt(e))return!1;const i=e.getPreviousSibling(),l=e.getNextSibling(),c=W("check"===t?/^x$/i.test(o[3]||""):void 0),f=o[0].trim()[0],a="bullet"!==t&&"check"!==t||f!==xt.parse(f)?void 0:f,u=kt;let d=i;if(null!==u){if(Nt)for(;null!==d&&nt(d);)d=d.getPreviousSibling();A(d)||(u.length=0)}const g=null===u||0===u.length?function(t){const e=t.match(/\t/g),n=t.match(/ /g);let r=0;return e&&(r+=e.length),n&&(r+=Math.floor(n.length/4)),r}(o[1]):function(t,e){const n=wt(e);for(let e=t.length-1;e>=0;e--)if(n>=t[e])return e+1;return 0}(u,o[1]);if(A(l)&&l.getListType()===t){const n=l.getFirstChild();null!==n?n.insertBefore(c):l.append(c),"number"===t&&0===g&&l.setStart(Number(o[2])),e.remove()}else if(A(d)&&(d.getListType()===t||g>0))d.append(c),e.remove();else{const n=U(t,"number"===t?Number(o[2]):void 0);n.append(c),e.replace(n)}c.append(...r),s||c.select(0,0),g&&(c.setIndent(g),function(t,e,n){const r=t.getParent();if(!A(r)||r.getListType()===e)return;const o=r.getParent();if(!D(o))return;const s=U(e,"number"===e?Number(n[2]):void 0),i=null===t.getPreviousSibling();s.append(t);const l=W();l.append(s),i?o.insertBefore(l):o.insertAfter(l),0===r.getChildrenSize()&&o.remove()}(c,t,o));const h=c.getParent();a&&A(h)&&n(h,xt,a),null!==u&&function(t,e,n,r){for(let n=t.length;n<e;n++)t[n]=4*(n+1);t.length=e,t[e]=function(t,e){let n=t[0];if("check"===e){const e=n.slice(t[1].length).match(/^[-*+]\s/);e&&(n=t[1]+e[0])}return Math.min(wt(n),wt(t[1])+4)}(n,r)}(u,g,o,t)},Ot=(t,e,n,r)=>{const s=[],i=t.getChildren();let l=0;for(const c of i)if(D(c)){if(1===c.getChildrenSize()){const t=c.getFirstChild();if(A(t)){const o=Ot(t,e,n+1,r);o&&s.push(o);continue}}if(r&&!c.getChildren().some(t=>t.isSelected(r)))continue;const i=" ".repeat(4*n),f=t.getListType(),a=o(t,xt),u="number"===f?`${t.getStart()+l}. `:"check"===f?`${a} [${c.getChecked()?"x":" "}] `:a+" ";let d=e(c);"number"!==f&&(d=d.replace(/^(\s{0,3}\d+)(\.\s)/,"$1\\$2")),s.push(i+u+d),l++}return s.join("\n")},Pt=/* @__PURE__ */bt(t=>{const e="h"+t[1].length;return G(e)}),Mt={dependencies:[Z],export:(t,e)=>{if(!K(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:lt,replace:(t,e,n,r)=>!(!r&&yt(t))&&Pt(t,e,n,r),triggerOnEnter:!0,type:"element"},Bt={dependencies:[H],export:(t,e)=>{if(!X(t))return null;const n=e(t).split("\n"),r=[];for(const t of n)r.push("> "+t);return r.join("\n")},regExp:ct,replace:(t,e,n,r)=>{if(r){const n=t.getPreviousSibling();if(X(n))return n.splice(n.getChildrenSize(),0,[vt(n),...e]),void t.remove()}const o=q();o.append(...e),t.replace(o),r||o.select(0,0)},triggerOnEnter:!0,type:"element"},Lt={dependencies:[O],export:t=>{if(!M(t))return null;const e=t.getTextContent();let n=o(t,Ct);if(e.indexOf(n)>-1){const t=e.match(/`{3,}/g);if(t){const e=Math.max(...t.map(t=>t.length));n="`".repeat(e+1)}}const r=t.getLanguage()||"",s=r?o(t,Tt):"";return n+r+(s?" "+s:"")+(e?"\n"+e:"")+"\n"+n},handleImportAfterStartMatch:({lines:t,rootNode:e,startLineIndex:n,startMatch:r})=>{const o=r[1],s=o.trim().length,i=t[n],l=r.index+o.length,c=i.slice(l),f=new RegExp(`\`{${s},}$`);if(f.test(c)){const t=c.match(f),o=c.slice(0,c.lastIndexOf(t[0])),s=[...r];return s[2]="",Lt.replace(e,null,s,t,[o],!0),[!0,n]}const a=new RegExp(`^[ \\t]*\`{${s},}$`);for(let o=n+1;o<t.length;o++){const s=t[o];if(a.test(s)){const l=s.match(a),c=t.slice(n+1,o),f=r[2]?i.slice(r[0].length).trim():"";return c.unshift(f?"":i.slice(r[0].length)),Lt.replace(e,null,r,l,c,!0),Et(e,f),[!0,o]}}const u=t.slice(n+1);return u.unshift(i.slice(r[0].length)),Lt.replace(e,null,r,null,u,!0),[!0,t.length-1]},regExpEnd:{optional:!0,regExp:at},regExpStart:ft,replace:(t,e,o,s,i,l)=>{let c,f;const a=o[1]?o[1].trim():"```",u=o[2]||void 0,d=o[1]?o[1].length-o[1].trimStart().length:0;if(!e&&i){if(1===i.length)s?(c=P(u),f=St(i[0],d)):(c=P(u),f=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(c=P(u),i.length>0&&(0===i[0].trim().length?i.shift():i[0].startsWith(" ")&&(i[0]=i[0].slice(1)));i.length>0&&!i[i.length-1].length;)i.pop();f=i.map(t=>St(t,d)).join("\n")}n(c,Ct,a);const e=r(f);c.append(e),t.append(c)}else if(e){if(!l&&yt(t))return!1;bt(t=>P(t?t[2]:void 0))(t,e,o,l)}},type:"multiline-element"},_t={dependencies:[j,z],export:(t,e,n)=>A(t)?Ot(t,e,0,n):null,regExp:st,replace:/* @__PURE__ */Ft("bullet"),triggerOnEnter:!0,type:"element"},Rt={dependencies:[j,z],export:(t,e,n)=>A(t)?Ot(t,e,0,n):null,regExp:it,replace:/* @__PURE__ */Ft("check"),triggerOnEnter:!0,type:"element"},jt={dependencies:[j,z],export:(t,e,n)=>A(t)?Ot(t,e,0,n):null,regExp:ot,replace:/* @__PURE__ */Ft("number"),triggerOnEnter:!0,type:"element"},zt={format:["code"],tag:"`",type:"text-format"},At={format:["highlight"],tag:"==",type:"text-format"},Wt={format:["bold","italic"],tag:"***",type:"text-format"},Ut={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Dt={format:["bold"],tag:"**",type:"text-format"},Zt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Ht={format:["strikethrough"],tag:"~~",type:"text-format"},Kt={format:["italic"],tag:"*",type:"text-format"},Xt={format:["italic"],intraword:!1,tag:"_",type:"text-format"};function qt(t){return t.replace(/&(?=#\d+;|#[Xx][\dA-Fa-f]+;|[A-Za-z][\dA-Za-z]*;)/g,"&")}const Gt={dependencies:[B],export:(t,e,n)=>{if(!L(t)||R(t))return null;const r=e(t);let o=t.getTitle();null!=o&&(o=qt(o).replace(/([\\"])/g,"\\$1"));const s=t.getURL(),i=qt(s),l=""===s||/\s/.test(s)?`<${i.replace(/([\\<>])/g,"\\$1").replace(/\r/g," ").replace(/\n/g," ")}>`:i.replace(/([\\()])/g,"\\$1").replace(/^</,"\\<");return o?`[${r}](${l} "${o}")`:`[${r}](${l})`},importRegExp:/(?:\[(.+?)\])(?:\(\s*(?:(?:<((?:\\.|[^<>\n\\])*)>|((?!<)(?:\\[^\s]|\\(?=\s)|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\])*\))*\))*\)|[^\s()\\])+))(?:\s+(?:"((?:[^"]*\\")*[^"]*)"|'((?:[^']*\\')*[^']*)'|\(((?:\\.|[^()\\])*)\)))?\s*)?\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\(\s*(?:(?:<((?:\\.|[^<>\n\\])*)>|((?!<)(?:\\[^\s]|\\(?=\s)|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\])*\))*\))*\)|[^\s()\\])+))(?:\s+(?:"((?:[^"]*\\")*[^"]*)"|'((?:[^']*\\')*[^']*)'|\(((?:\\.|[^()\\])*)\)))?\s*)?\))$/,replace:(t,e)=>{if(s(t,L))return;const[,n,o,i,l,c,f]=e,a=rt(o??i??""),u=l??c??f,d=null!=u?rt(u):void 0,g=_(a,{title:d}),h=n.split("[").length-1,p=n.split("]").length-1;let m=n,x="";if(h<p)return;if(h>p){const t=n.split("[");x="["+t[0],m=t.slice(1).join("[")}const C=t.getFormat(),T=r(m);return T.setFormat(C),g.append(T),t.replace(g),x&&g.insertBefore(r(x).setFormat(C)),T},trigger:")",type:"text-match"},Jt=[Mt,Bt,_t,jt],Qt=[Lt],Vt=[zt,Wt,Ut,Dt,Zt,At,Kt,Xt,Ht],Yt=[Gt];function te(...t){return t.flat()}const ee=/* @__PURE__ */te(Jt,Qt,Vt,Yt);function ne(t,e=!1){const n=t.split("\n");let r=0;const o=[];for(let t=0;t<n.length;t++){const s=n[t],i=s.trimEnd(),l=o[o.length-1],c=t<n.length-1?$t(s):null,f=void 0!==l&&null!==$t(l);if(ut.test(i))o.push(i);else if(0===r){{const t=i.match(ft);if(t){r=t[1].trim().length,o.push(i);continue}}""===i||""===l||!l||lt.test(l)||lt.test(i)||ct.test(i)||ot.test(i)||st.test(i)||it.test(i)||dt.test(i)||gt(i)||f||!e||ht.test(i)||pt.test(i)||mt(pt).test(l)||mt(ht).test(l)||at.test(l)?o.push(!e&&""!==i||null!==c?s:i):o[o.length-1]=l+" "+(null===c?i:s).trimStart()}else{if(at.test(i)&&i.trim().length>=r){r=0,o.push(i);continue}o.push(s)}}return o.join("\n")}function re(t,e,n,r,o,s){let i=t.isSelected(e);for(const l of n){if(!l.export)continue;const n=l.export(t,t=>oe(t,e,r,o,s).markdown,e);if(null!=n)return!i&&a(t)&&oe(t,e,r,o,s).shouldInclude&&(i=!0),{markdown:n,shouldInclude:i}}if(a(t)){const n=oe(t,e,r,o,s);return{markdown:n.markdown,shouldInclude:i||n.shouldInclude}}return u(t)?{markdown:t.getTextContent(),shouldInclude:i}:{markdown:null,shouldInclude:i}}function oe(t,n,r,o,s,i,l){const f=[],d=t.getChildren();let g=!1;i||(i=[]),l||(l=[]);t:for(const t of d){let d=t.isSelected(n);for(const e of o){if(!e.export)continue;const c=e.export(t,t=>oe(t,n,r,o,s,i,[...l,...i]).markdown,(t,e)=>ce(t,F(n,t,"clone").getTextContent(),r,i,l,s));if(null!=c){!d&&a(t)&&t.getChildren().some(t=>t.isSelected(n))&&t.extractWithChild(t,n,"html")&&(d=!0),d&&(f.push(c),g=!0);continue t}}if(c(t))d&&(f.push(le(t)),g=!0);else if(e(t)){if(d){const e=F(n,t,"clone");f.push(ce(t,e.getTextContent(),r,i,l,s)),g=!0}}else if(a(t)){const e=oe(t,n,r,o,s,i,l);!d&&e.shouldInclude&&t.extractWithChild(t,n,"html")&&(d=!0),(d||e.shouldInclude)&&(f.push(e.markdown),g=!0)}else u(t)&&d&&(f.push(t.getTextContent()),g=!0)}return{markdown:f.join(""),shouldInclude:g}}function se(t,e,n,r,o){for(const s of e){if(!s.export)continue;const e=s.export(t,t=>ie(t,n,r,void 0,void 0,o));if(null!=e)return e}return a(t)?ie(t,n,r,void 0,void 0,o):u(t)?t.getTextContent():null}function ie(t,n,r,o,s,i=!1){const l=[],f=t.getChildren();o||(o=[]),s||(s=[]);t:for(const t of f){for(const e of r){if(!e.export)continue;const c=e.export(t,t=>ie(t,n,r,o,[...s,...o],i),(t,e)=>ce(t,e,n,o,s,i));if(null!=c){l.push(c);continue t}}c(t)?l.push(le(t)):e(t)?l.push(ce(t,t.getTextContent(),n,o,s,i)):a(t)?l.push(ie(t,n,r,o,s,i)):u(t)&&l.push(t.getTextContent())}return l.join("")}function le(t){return o(t,It)+"\n"}function ce(t,e,n,r,o,s=!1){const i=t.hasFormat("code");let l,c,f,a,u=e;if(i||(u=s?u.replace(/([*_`~])/g,"\\$1"):u.replace(/([*_`~\\])/g,"\\$1")),i){const{fence:t,padded:n}=function(t){const e=t.match(/`+/g),n=e?Math.max(...e.map(t=>t.length)):0;return{fence:"`".repeat(n+1),padded:0===t.length||t.includes("`")||/^\s/.test(t)&&/\s$/.test(t)?` ${t} `:t}}(e);l="",f="",c=t+n+t,a=!1}else{const t=u.match(/^(\s*)(.*?)(\s*)$/s)||["","",u,""];l=t[1],c=t[2],f=t[3],a=""===c}let d="",g="",h="";const p=fe(t,!0),m=fe(t,!1),x=new Set;for(const e of n){const n=e.format[0],o=e.tag;"code"!==n&&(a||!ue(t,n)||x.has(n)||(x.add(n),ue(p,n)&&r.find(t=>t.tag===o)||(r.push({format:n,tag:o}),d+=o)))}for(let e=0;e<r.length;e++){const n=ae(t,r[e].format),s=ae(m,r[e].format);if(n&&s)continue;const i=[...r];for(;i.length>e;){const t=i.pop();o&&t&&o.find(e=>e.tag===t.tag)||(t&&"string"==typeof t.tag&&(n?s||(h+=t.tag):g+=t.tag),r.pop())}break}return a&&!t.hasFormat("code")?g+u:g+l+d+c+h+f}function fe(t,n){const r=n?t.getPreviousSibling():t.getNextSibling();return e(r)?r:null}function ae(t,n){return e(t)&&t.hasFormat(n)}function ue(t,e){return!(!ae(t,e)||"code"!==e&&t&&/^\s*$/.test(t.getTextContent()))}function de(t,e,n,r,o){if(!ge(e,n,r,o))return!1;if("*"===t)return!0;if("_"===t){if(!ge(e,n,r,!o))return!0;const t=o?e[n-1]:e[n+r];return void 0!==t&&tt.test(t)}return!0}function ge(t,e,n,r){const o=t[e-1],s=t[e+n],[i,l]=r?[s,o]:[o,s];return void 0!==i&&!Y.test(i)&&(!tt.test(i)||void 0===l||Y.test(l)||tt.test(l))}function he(t){return e(t)&&!t.hasFormat("code")}function pe(t,e,n){let r=function(t,e){const n=t.getTextContent(),r=e.transformersByTag["`"],o=[];let s=null;if(r){const t=function(t){const e=e=>{let n=0;for(let r=e-1;r>=0&&"\\"===t[r];r--)n++;return n%2==1},n=[];let r=0;for(;r<t.length;)if("`"===t[r]){let e=1;for(;r+e<t.length&&"`"===t[r+e];)e++;n.push({index:r,length:e}),r+=e}else r++;const o=[];let s=0;for(;s<n.length;){const r=n[s];if(e(r.index)){s++;continue}let i=-1;for(let t=s+1;t<n.length;t++)if(n[t].length===r.length){i=t;break}if(-1===i){s++;continue}const l=n[i];let c=t.slice(r.index+r.length,l.index);c.length>=2&&c.startsWith(" ")&&c.endsWith(" ")&&/[^ ]/.test(c)&&(c=c.slice(1,-1)),o.push({content:c,endIndex:l.index+l.length,startIndex:r.index}),s=i+1}return o}(n);for(const e of t)s||(s={content:e.content,endIndex:e.endIndex,startIndex:e.startIndex,tag:"`"}),o.push({end:e.endIndex,start:e.startIndex})}const i=function(t,e,n=[]){const r=[],o=new Set(Object.keys(e.transformersByTag).filter(t=>"`"!==t[0]).map(t=>t[0])),s=e=>{let n=0;for(let r=e-1;r>=0&&"\\"===t[r];r--)n++;return n%2==1},i=t=>n.some(e=>t>=e.start&&t<e.end);let l=0;for(;l<t.length;){const e=t[l];if(!o.has(e)||s(l)||i(l)){l++;continue}let n=1;for(;l+n<t.length&&t[l+n]===e;)n++;const c=de(e,t,l,n,!0),f=de(e,t,l,n,!1);(c||f)&&r.push({active:!0,canClose:f,canOpen:c,char:e,index:l,length:n}),l+=n}return r}(n,e,o),l=i.length>0?function(t,e,n){const r={};let o=0,s=null;for(;o<e.length;){const i=e[o];if(!i.active||!i.canClose||0===i.length){o++;continue}const l=`${i.char}${i.canOpen}${i.length%3}`,c=r[l]??-1;let f=!1;for(let r=o-1;r>c;r--){const l=e[r];if(!l.active||!l.canOpen||0===l.length||l.char!==i.char)continue;if((l.canClose||i.canOpen)&&(l.length+i.length)%3==0&&l.length%3!=0&&i.length%3!=0)continue;const c=Math.min(l.length,i.length),a=Object.keys(n.transformersByTag).filter(t=>t[0]===l.char&&t.length<=c).sort((t,e)=>e.length-t.length)[0];if(!a)continue;f=!0;const u=a.length,d={content:t.slice(l.index+l.length,i.index),endIndex:i.index+u,startIndex:l.index+(l.length-u),tag:a};(!s||d.startIndex<s.startIndex||d.startIndex===s.startIndex&&d.endIndex>s.endIndex)&&(s=d);for(let t=r+1;t<o;t++)e[t].active=!1;l.length-=u,i.length-=u,l.active=l.length>0,i.length>0?i.index+=u:(i.active=!1,o++);break}f||(r[l]=o-1,i.canOpen||(i.active=!1),o++)}return s}(n,i,e):null;let c=null,f=null;if(s&&l?l.startIndex<=s.startIndex&&l.endIndex>=s.endIndex?(c=l,f=e.transformersByTag[l.tag]):(c=s,f=r):s?(c=s,f=r):l&&(c=l,f=e.transformersByTag[l.tag]),!c||!f)return null;const a=[n.slice(c.startIndex,c.endIndex),c.tag,c.content];return a.index=c.startIndex,a.input=n,{endIndex:c.endIndex,isCodeSpan:f===r,match:a,startIndex:c.startIndex,transformer:f}}(t,e),o=function(t,e){const n=t;let r,o,s,i;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===r||void 0===o||l<r&&(c>o||c<=r))&&(r=l,o=c,s=t,i=e)}return void 0===r||void 0===o||void 0===s||void 0===i?null:{endIndex:o,match:i,startIndex:r,transformer:s}}(t,n);if(r&&o&&(r.isCodeSpan?o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex?r=null:o=null:r.startIndex<=o.startIndex&&r.endIndex>=o.endIndex||o.startIndex>r.endIndex?o=null:r=null),r){const o=function(t,e,n,r,o){const s=t.getTextContent();let i,l,c;if(o[0]===s?i=t:0===e?[i,l]=t.splitText(n):[c,i,l]=t.splitText(e,n),i.setTextContent(o[2]),r)for(const t of r.format)i.hasFormat(t)||i.toggleFormat(t);return{nodeAfter:l,nodeBefore:c,transformedNode:i}}(t,r.startIndex,r.endIndex,r.transformer,r.match);he(o.nodeAfter)&&pe(o.nodeAfter,e,n),he(o.nodeBefore)&&pe(o.nodeBefore,e,n),he(o.transformedNode)&&pe(o.transformedNode,e,n)}else if(o){const r=function(t,e,n,r,o){let s,i,l;return 0===e?[s,i]=t.splitText(n):[l,s,i]=t.splitText(e,n),r.replace?{nodeAfter:i,nodeBefore:l,transformedNode:r.replace(s,o)||void 0}:null}(t,o.startIndex,o.endIndex,o.transformer,o.match);if(!r)return;he(r.nodeAfter)&&pe(r.nodeAfter,e,n),he(r.nodeBefore)&&pe(r.nodeBefore,e,n),he(r.transformedNode)&&pe(r.transformedNode,e,n)}const s=rt(t.getTextContent());t.setTextContent(s)}function me(t,e,n,r=!1){const o=Q(n),s=function(t){const e={},n={},r=[];for(const o of t){const{tag:t}=o;e[t]=o;const s=t.replace(/(\*|\^|\+)/g,"\\$1");r.push(s),1===t.length?n[t]="`"===t?new RegExp("(^|[^\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(^|[^\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)(${s})(?![\\\\${s}])`):n[t]=new RegExp(`(^|[^\\\\])(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`(${r.join("|")})`,"g"),transformersByTag:e}}(o.textFormat),i=t.split("\n"),l=i.length;!function(t){const n=kt,c=Nt;kt=[],Nt=t;try{return(()=>{for(let t=0;t<l;t++){const n=i[t],[l,c]=xe(i,t,o.multilineElement,e);l?t=c:Ce(n,e,o.element,s,o.textMatch,r)}})()}finally{kt=n,Nt=c}}(!r);const c=e.getChildren();for(const t of c)if(!r&&nt(t)&&e.getChildrenSize()>1)t.remove();else if(a(t))for(const e of t.getAllTextNodes())Te(e)}function xe(t,e,n,r){for(const o of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:l}=o,c=t[e].match(i);if(!c)continue;if(n){const s=n({lines:t,rootNode:r,startLineIndex:e,startMatch:c,transformer:o});if(null===s)continue;if(s)return s}const f="object"==typeof s&&"regExp"in s?s.regExp:s,a=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let u=e;const d=t.length;for(;u<d;){const n=f?t[u].match(f):null;if(!n&&(!a||a&&u<d-1)){u++;continue}if(n&&e===u&&n.index===c.index){u++;continue}const o=[];if(n&&e===u)o.push(t[e].slice(c[0].length,-n[0].length));else for(let r=e;r<=u;r++)if(r===e){const e=t[r].slice(c[0].length);o.push(e)}else if(r===u&&n){const e=t[r].slice(0,-n[0].length);o.push(e)}else o.push(t[r]);if(!1!==l(r,null,c,n,o,!0))return[!0,u];break}}return[!1,e]}function Ce(e,n,o,i,l,c){const f=r(e),a=h();a.append(f),n.append(a);for(const{regExp:t,replace:n}of o){const r=e.match(t);if(r&&(f.setTextContent(e.slice(r[0].length)),!1!==n(a,[f],r,!0)))break}if(pe(f,i,l),null!==a.getParent()&&e.length>0){const e=a.getPreviousSibling();if(!c&&(t(e)||X(e)||A(e))){let t=e;if(A(e)){const n=e.getLastDescendant();t=null==n?null:s(n,D)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[vt(t),...a.getChildren()]),a.remove())}}}function Te(t){if(d(t))return;const e=t.getTextContent();if(!e.includes("\t"))return;const n=t.getFormat(),o=t.getStyle(),s=[];let i=0;for(let t=e.indexOf("\t");-1!==t;t=e.indexOf("\t",t+1))t>i&&s.push(r(e.slice(i,t)).setFormat(n).setStyle(o)),s.push(g()),i=t+1;i<e.length&&s.push(r(e.slice(i)).setFormat(n).setStyle(o)),t.getParentOrThrow().splice(t.getIndexWithinParent(),1,s)}function Ie(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.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 $e(t,e,n,r,o){const s=t.getParent();if(!E(s)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(!o&&" "!==i[n-1])return!1;for(const{regExp:s,replace:l}of r){const r=i.match(s),c=o||r&&r[0].endsWith(" ")?n:n-1;if(r&&r[0].length===c){const o=e.getNextSiblings(),[s,i]=e.splitText(n);if(!1!==l(t,i?[i,...o]:o,r,!1))return s.remove(),!0}}return!1}function ve(t,e,n,r,o){const s=t.getParent();if(!E(s)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(!o&&" "!==i[n-1])return!1;for(const{regExpStart:s,replace:l,regExpEnd:c}of r){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const r=i.match(s);if(r){const s=o||r[0].endsWith(" ")?n:n-1;if(r[0].length!==s)continue;const i=e.getNextSiblings(),[c,f]=e.splitText(n);if(!1!==l(t,f?[f,...i]:i,r,null,null,!1))return c.remove(),!0}}return!1}function ye(t,e){let n=0;const r=t.getTextContent();for(let t=0;t<e;t++)"`"===r[t]&&n++;return n%2!=0}function Se(t,e,n){const r=n.length;for(let o=e;o>=r;o--){const e=o-r;if(be(t,e,n,0,r)&&" "!==t[e+r])return e}return-1}function Ee(t){const n=t.getNode();let r=0;if(e(n))r=t.offset;else if(a(n))for(const e of n.getChildren().slice(0,t.offset))r+=e.getTextContentSize();for(let t=n.getPreviousSibling();null!==t;t=t.getPreviousSibling())r+=t.getTextContentSize();return r}function be(t,e,n,r,o){for(let s=0;s<o;s++)if(t[e+s]!==n[r+s])return!1;return!0}function we(t,n=ee){const r=Q(n),o=r.element.filter(t=>t.triggerOnEnter),s=J(r.textFormat,({tag:t})=>t[t.length-1]),i=J(r.textMatch,({trigger:t})=>t),l=new Set([" "]);for(const t of r.textFormat)l.add(t.tag.slice(-1));for(const t of r.textMatch)void 0!==t.trigger&&l.add(t.trigger);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)||Ie(173,e.getType())}}return p(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:f,prevEditorState:a})=>{if(n.has(m)||n.has(x))return;if(t.isComposing())return;const u=n.has(C),d=f.read(T),g=a.read(T);if(!I(g)||!I(d)||!d.isCollapsed()||d.is(g)&&!u)return;const h=d.anchor.key,p=d.anchor.offset,y=f._nodeMap.get(h);if(e(y)&&o.has(h)&&(u||1===p||!(f.read(()=>Ee(d.anchor))>a.read(()=>Ee(g.anchor))+1))){if(u){const t=f.read(()=>y.getTextContent())[p-1];if(!l.has(t))return}t.update(()=>{if(!he(y))return;const t=y.getParent();null===t||M(t)||((t,n,o)=>!!($e(t,n,o,r.element)||ve(t,n,o,r.multilineElement)||function(t,e,n){let r=t.getTextContent();const o=n[r[e-1]];if(null==o)return!1;e<r.length&&(r=r.slice(0,e));for(const e of o){if(!e.replace||!e.regExp)continue;const n=r.match(e.regExp);if(null===n)continue;const o=n.index||0,s=o+n[0].length;let i;return 0===o?[i]=t.splitText(s):[,i]=t.splitText(o,s),i.selectNext(0,0),e.replace(i,n),!0}return!1}(n,o,i)||function(t,n,r){const o=t.getTextContent(),s=n-1,i=o[s],l=r[i];if(!l)return!1;for(const n of l){const{tag:r}=n,l=r.length,f=s-l+1;if(l>1&&!be(o,f,r,0,l))continue;if(" "===o[f-1])continue;const a=o[s+1];if(!1===n.intraword&&a&&!V.test(a))continue;const u=t;let d=u,g=Se(o,f,r),h=d;for(;g<0&&(h=h.getPreviousSibling())&&!c(h);)if(e(h)){if(h.hasFormat("code"))continue;const t=h.getTextContent();d=h,g=Se(t,t.length,r)}if(g<0)continue;if(d===u&&g+l===f)continue;const p=d.getTextContent();if(g>0&&p[g-1]===i)continue;const m=p[g-1];if(!1===n.intraword&&m&&!V.test(m))continue;if(!n.format.includes("code")&&ye(d,g))continue;const x=u.getTextContent(),C=x.slice(0,f)+x.slice(s+1);u.setTextContent(C);const $=d===u?C:p;d.setTextContent($.slice(0,g)+$.slice(g+l));const v=T(),y=b();w(y);const S=s-l*(d===u?2:1)+1;y.anchor.set(d.__key,g,"text"),y.focus.set(u.__key,S,"text");for(const t of n.format)y.formatText(t,k[t]);y.anchor.set(y.focus.key,y.focus.offset,y.focus.type);for(const t of n.format)y.hasFormat(t)&&y.toggleFormat(t);return I(v)&&(y.format=v.format),!0}return!1}(n,o,s)))(t,y,d.anchor.offset)&&$(v)})}}),t.registerCommand(y,t=>{if(null!==t&&t.shiftKey)return!1;const n=T();if(!I(n)||!n.isCollapsed())return!1;const s=n.anchor.offset,i=n.anchor.getNode();if(!e(i)||!he(i))return!1;const l=i.getParent();return null!==l&&!M(l)&&!(s!==i.getTextContent().length||!ve(l,i,s,r.multilineElement,!0)&&!$e(l,i,s,o,!0)||(null!==t&&t.preventDefault(),0))},S))}function ke(t,e=ee,n,r=!1,o=!1){const s=r?t:ne(t,o),i=n||f();i.clear(),me(s,i,e,r),null!==T()&&i.selectStart()}function Ne(t,e=ee,n=!1,r=!1){const o=n?t:ne(t,r),s=new N;return me(o,s,e,n),s.getChildren()}function Fe(t=ee,e,n=!1){const r=function(t,e=!1){const n=Q(t),r=[...n.multilineElement,...n.element],o=!e,s=n.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const i=[],l=(t||f()).getChildren();for(let t=0;t<l.length;t++){const c=l[t],f=se(c,r,s,n.textMatch,e);null!=f&&i.push(o&&t>0&&!nt(c)&&!nt(l[t-1])?"\n".concat(f):f)}return i.join("\n")}}(t,n);return r(e)}function Oe(t=ee,e,n=!1){if(!e||I(e)&&e.isCollapsed())return"";const r=function(t,e=!1){const n=Q(t),r=[...n.multilineElement,...n.element],o=!e,s=n.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const i=[];let l=null;for(const c of f().getChildren()){const{shouldInclude:f,markdown:a}=re(c,t,r,s,n.textMatch,e);f&&null!=a&&(i.push(!o||null===l||nt(c)||nt(l)?a:"\n".concat(a)),l=c)}return i.join("\n")}}(t,n);return r(e)}export{ke as $convertFromMarkdownString,Oe as $convertSelectionToMarkdownString,Fe as $convertToMarkdownString,Ne as $generateNodesFromMarkdownString,Wt as BOLD_ITALIC_STAR,Ut as BOLD_ITALIC_UNDERSCORE,Dt as BOLD_STAR,Zt as BOLD_UNDERSCORE,Rt as CHECK_LIST,Lt as CODE,Jt as ELEMENT_TRANSFORMERS,Mt as HEADING,At as HIGHLIGHT,zt as INLINE_CODE,Kt as ITALIC_STAR,Xt as ITALIC_UNDERSCORE,Gt as LINK,Qt as MULTILINE_ELEMENT_TRANSFORMERS,jt as ORDERED_LIST,Bt as QUOTE,Ht as STRIKETHROUGH,Vt as TEXT_FORMAT_TRANSFORMERS,Yt as TEXT_MATCH_TRANSFORMERS,ee as TRANSFORMERS,_t as UNORDERED_LIST,gt as isTableRowDivider,we as registerMarkdownShortcuts};
|
|
9
|
+
import{$isParagraphNode as t,$isTextNode as e,$setState as n,$createTextNode as r,$getState as o,$findMatchingParent as s,$createLineBreakNode as i,createState as l,$isLineBreakNode as c,$getRoot as f,$isElementNode as u,$isDecoratorNode as a,$isTabNode as d,$createTabNode as g,$createParagraphNode as h,mergeRegister as p,COLLABORATION_TAG as m,HISTORIC_TAG as x,COMPOSITION_END_TAG as C,$getSelection as T,$isRangeSelection as I,$addUpdateTag as $,HISTORY_PUSH_TAG as v,KEY_ENTER_COMMAND as y,COMMAND_PRIORITY_LOW as S,$isRootOrShadowRoot as E,$createRangeSelection as b,$setSelection as w,TEXT_TYPE_TO_FORMAT as k,ArtificialNode__DO_NOT_USE as N}from"lexical";import{$sliceSelectedTextNodeContent as F}from"@lexical/selection";import{CodeNode as O,$createCodeNode as P,$isCodeNode as M}from"@lexical/code-core";import{LinkNode as B,$isLinkNode as L,$createLinkNode as _,$isAutoLinkNode as R}from"@lexical/link";import{ListNode as j,ListItemNode as z,$isListNode as A,$createListItemNode as W,$createListNode as U,$isListItemNode as D}from"@lexical/list";import{HeadingNode as Z,QuoteNode as H,$isHeadingNode as K,$isQuoteNode as X,$createQuoteNode as q,$createHeadingNode as G}from"@lexical/rich-text";function J(t,e){const n={};for(const r of t){const t=e(r);t&&(n[t]?n[t].push(r):n[t]=[r])}return n}function Q(t){const e=J(t,t=>t.type);return{element:e.element||[],multilineElement:e["multiline-element"]||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const V=/[!-/:-@[-`{-~\s]/,Y=/\s/,tt=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,et=/^\s{0,3}$/;function nt(n){if(!t(n))return!1;const r=n.getFirstChild();return null==r||1===n.getChildrenSize()&&e(r)&&et.test(r.getTextContent())}function rt(t){return t.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(t,e)=>String.fromCodePoint(Number(e)))}const ot=/^(\s*)(\d{1,})\.\s/,st=/^(\s*)[-*+]\s/,it=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,lt=/^(#{1,6})\s/,ct=/^>\s/,ft=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,ut=/^[ \t]*`{3,}$/,at=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,dt=/^(?:\|)(.+)(?:\|)\s?$/;function gt(t){if("|"!==t[0])return!1;const{length:e}=t;let n=1,r=0;for(;n<e;){let e=n;for(" "===t[e]&&e++,":"===t[e]&&e++;"-"===t[e];)e++;if(":"===t[e]&&e++," "===t[e]&&e++,"|"!==t[e])break;r++,n=e+1}return r>0&&(n===e||n===e-1&&/\s/.test(t[n]))}const ht=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,pt=/^<\/[a-z_][\w-]*\s*>/i,mt=t=>new RegExp(`(?:${t.source})$`,t.flags),xt=/* @__PURE__ */l("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),Ct=/* @__PURE__ */l("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),Tt=/* @__PURE__ */l("mdCodeMeta",{parse:t=>"string"==typeof t?t:"",resetOnCopyNode:!0}),It=/* @__PURE__ */l("mdHardLineBreak",{parse:t=>"string"==typeof t&&/^(\\| {2,})$/.test(t)?t:"",resetOnCopyNode:!0});function $t(t){if(t.endsWith("\\")){let e=0;for(let n=t.length-1;n>=0&&"\\"===t[n];n--)e++;return e%2==1?[t.slice(0,-1),"\\"]:null}const e=t.match(/^(.*?\S)( {2,})$/);return e?[e[1],e[2]]:null}function vt(t){const r=i(),o=function(t){const n=t.getChildren(),r=n.length-1,o=n[r];if(!e(o))return null;const s=o.getTextContent(),i=$t(s);if(null!==i){const[t,e]=i;return o.setTextContent(t),e}return/^ {2,}$/.test(s)&&function(t,e){for(let n=e-1;n>=0;n--){if(c(t[n]))return!1;if(/\S/.test(t[n].getTextContent()))return!0}return!1}(n,r)?(o.setTextContent(""),s):null}(t);return null!==o&&n(r,It,o),r}function yt(t){return X(t)}function St(t,e){let n=0;for(;n<e&&(" "===t[n]||"\t"===t[n]);)n++;return t.slice(n)}function Et(t,e){const r=t.getLastChild();e&&M(r)&&n(r,Tt,e)}const bt=t=>(e,n,r,o)=>{const s=t(r);s.append(...n),e.replace(s),o||s.select(0,0)};function wt(t){let e=0;for(const n of t)e+="\t"===n?4-e%4:1;return e}let kt=null,Nt=!1;const Ft=t=>(e,r,o,s)=>{if(K(e)||!s&&yt(e))return!1;const i=e.getPreviousSibling(),l=e.getNextSibling(),c=W("check"===t?/^x$/i.test(o[3]||""):void 0),f=o[0].trim()[0],u="bullet"!==t&&"check"!==t||f!==xt.parse(f)?void 0:f,a=kt;let d=i;if(null!==a){if(Nt)for(;null!==d&&nt(d);)d=d.getPreviousSibling();A(d)||(a.length=0)}const g=null===a||0===a.length?function(t){const e=t.match(/\t/g),n=t.match(/ /g);let r=0;return e&&(r+=e.length),n&&(r+=Math.floor(n.length/4)),r}(o[1]):function(t,e){const n=wt(e);for(let e=t.length-1;e>=0;e--)if(n>=t[e])return e+1;return 0}(a,o[1]);if(A(l)&&l.getListType()===t){const n=l.getFirstChild();null!==n?n.insertBefore(c):l.append(c),"number"===t&&0===g&&l.setStart(Number(o[2])),e.remove()}else if(A(d)&&(d.getListType()===t||g>0))d.append(c),e.remove();else{const n=U(t,"number"===t?Number(o[2]):void 0);n.append(c),e.replace(n)}c.append(...r),s||c.select(0,0),g&&(c.setIndent(g),function(t,e,n){const r=t.getParent();if(!A(r)||r.getListType()===e)return;const o=r.getParent();if(!D(o))return;const s=U(e,"number"===e?Number(n[2]):void 0),i=null===t.getPreviousSibling();s.append(t);const l=W();l.append(s),i?o.insertBefore(l):o.insertAfter(l),0===r.getChildrenSize()&&o.remove()}(c,t,o));const h=c.getParent();u&&A(h)&&n(h,xt,u),null!==a&&function(t,e,n,r){for(let n=t.length;n<e;n++)t[n]=4*(n+1);t.length=e,t[e]=function(t,e){let n=t[0];if("check"===e){const e=n.slice(t[1].length).match(/^[-*+]\s/);e&&(n=t[1]+e[0])}return Math.min(wt(n),wt(t[1])+4)}(n,r)}(a,g,o,t)},Ot=(t,e,n,r)=>{const s=[],i=t.getChildren();let l=0;for(const c of i)if(D(c)){if(1===c.getChildrenSize()){const t=c.getFirstChild();if(A(t)){const o=Ot(t,e,n+1,r);o&&s.push(o);continue}}if(r&&!c.getChildren().some(t=>t.isSelected(r)))continue;const i=" ".repeat(4*n),f=t.getListType(),u=o(t,xt),a="number"===f?`${t.getStart()+l}. `:"check"===f?`${u} [${c.getChecked()?"x":" "}] `:u+" ";let d=e(c);"number"!==f&&(d=d.replace(/^(\s{0,3}\d+)(\.\s)/,"$1\\$2")),s.push(i+a+d),l++}return s.join("\n")},Pt=/* @__PURE__ */bt(t=>{const e="h"+t[1].length;return G(e)}),Mt={dependencies:[Z],export:(t,e)=>{if(!K(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:lt,replace:(t,e,n,r)=>!(!r&&yt(t))&&Pt(t,e,n,r),triggerOnEnter:!0,type:"element"},Bt={dependencies:[H],export:(t,e)=>{if(!X(t))return null;const n=e(t).split("\n"),r=[];for(const t of n)r.push("> "+t);return r.join("\n")},regExp:ct,replace:(t,e,n,r)=>{if(r){const n=t.getPreviousSibling();if(X(n))return n.splice(n.getChildrenSize(),0,[vt(n),...e]),void t.remove()}const o=q();o.append(...e),t.replace(o),r||o.select(0,0)},triggerOnEnter:!0,type:"element"},Lt={dependencies:[O],export:t=>{if(!M(t))return null;const e=t.getTextContent();let n=o(t,Ct);if(e.indexOf(n)>-1){const t=e.match(/`{3,}/g);if(t){const e=Math.max(...t.map(t=>t.length));n="`".repeat(e+1)}}const r=t.getLanguage()||"",s=r?o(t,Tt):"";return n+r+(s?" "+s:"")+(e?"\n"+e:"")+"\n"+n},handleImportAfterStartMatch:({lines:t,rootNode:e,startLineIndex:n,startMatch:r})=>{const o=r[1],s=o.trim().length,i=t[n],l=r.index+o.length,c=i.slice(l),f=new RegExp(`\`{${s},}$`);if(f.test(c)){const t=c.match(f),o=c.slice(0,c.lastIndexOf(t[0])),s=[...r];return s[2]="",Lt.replace(e,null,s,t,[o],!0),[!0,n]}const u=new RegExp(`^[ \\t]*\`{${s},}$`);for(let o=n+1;o<t.length;o++){const s=t[o];if(u.test(s)){const l=s.match(u),c=t.slice(n+1,o),f=r[2]?i.slice(r[0].length).trim():"";return c.unshift(f?"":i.slice(r[0].length)),Lt.replace(e,null,r,l,c,!0),Et(e,f),[!0,o]}}const a=t.slice(n+1);return a.unshift(i.slice(r[0].length)),Lt.replace(e,null,r,null,a,!0),[!0,t.length-1]},regExpEnd:{optional:!0,regExp:ut},regExpStart:ft,replace:(t,e,o,s,i,l)=>{let c,f;const u=o[1]?o[1].trim():"```",a=o[2]||void 0,d=o[1]?o[1].length-o[1].trimStart().length:0;if(!e&&i){if(1===i.length)s?(c=P(a),f=St(i[0],d)):(c=P(a),f=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(c=P(a),i.length>0&&(0===i[0].trim().length?i.shift():i[0].startsWith(" ")&&(i[0]=i[0].slice(1)));i.length>0&&!i[i.length-1].length;)i.pop();f=i.map(t=>St(t,d)).join("\n")}n(c,Ct,u);const e=r(f);c.append(e),t.append(c)}else if(e){if(!l&&yt(t))return!1;bt(t=>P(t?t[2]:void 0))(t,e,o,l)}},type:"multiline-element"},_t={dependencies:[j,z],export:(t,e,n)=>A(t)?Ot(t,e,0,n):null,regExp:st,replace:/* @__PURE__ */Ft("bullet"),triggerOnEnter:!0,type:"element"},Rt={dependencies:[j,z],export:(t,e,n)=>A(t)?Ot(t,e,0,n):null,regExp:it,replace:/* @__PURE__ */Ft("check"),triggerOnEnter:!0,type:"element"},jt={dependencies:[j,z],export:(t,e,n)=>A(t)?Ot(t,e,0,n):null,regExp:ot,replace:/* @__PURE__ */Ft("number"),triggerOnEnter:!0,type:"element"},zt={format:["code"],tag:"`",type:"text-format"},At={format:["highlight"],tag:"==",type:"text-format"},Wt={format:["bold","italic"],tag:"***",type:"text-format"},Ut={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Dt={format:["bold"],tag:"**",type:"text-format"},Zt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Ht={format:["strikethrough"],tag:"~~",type:"text-format"},Kt={format:["italic"],tag:"*",type:"text-format"},Xt={format:["italic"],intraword:!1,tag:"_",type:"text-format"};function qt(t){return t.replace(/&(?=#\d+;|#[Xx][\dA-Fa-f]+;|[A-Za-z][\dA-Za-z]*;)/g,"&")}const Gt={dependencies:[B],export:(t,e,n)=>{if(!L(t)||R(t))return null;const r=e(t);let o=t.getTitle();null!=o&&(o=qt(o).replace(/([\\"])/g,"\\$1"));const s=t.getURL(),i=qt(s),l=""===s||/\s/.test(s)?`<${i.replace(/([\\<>])/g,"\\$1").replace(/\r/g," ").replace(/\n/g," ")}>`:i.replace(/([\\()])/g,"\\$1").replace(/^</,"\\<");return o?`[${r}](${l} "${o}")`:`[${r}](${l})`},importRegExp:/(?:\[(.+?)\])(?:\(\s*(?:(?:<((?:\\.|[^<>\n\\])*)>|((?!<)(?:\\[^\s]|\\(?=\s)|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\])*\))*\))*\)|[^\s()\\])+))(?:\s+(?:"((?:[^"]*\\")*[^"]*)"|'((?:[^']*\\')*[^']*)'|\(((?:\\.|[^()\\])*)\)))?\s*)?\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\(\s*(?:(?:<((?:\\.|[^<>\n\\])*)>|((?!<)(?:\\[^\s]|\\(?=\s)|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\])*\))*\))*\)|[^\s()\\])+))(?:\s+(?:"((?:[^"]*\\")*[^"]*)"|'((?:[^']*\\')*[^']*)'|\(((?:\\.|[^()\\])*)\)))?\s*)?\))$/,replace:(t,e)=>{if(s(t,L))return;const[,n,o,i,l,c,f]=e,u=rt(o??i??""),a=l??c??f,d=null!=a?rt(a):void 0,g=_(u,{title:d}),h=n.split("[").length-1,p=n.split("]").length-1;let m=n,x="";if(h<p)return;if(h>p){const t=n.split("[");x="["+t[0],m=t.slice(1).join("[")}const C=t.getFormat(),T=r(m);return T.setFormat(C),g.append(T),t.replace(g),x&&g.insertBefore(r(x).setFormat(C)),T},trigger:")",type:"text-match"},Jt=[Mt,Bt,_t,jt],Qt=[Lt],Vt=[zt,Wt,Ut,Dt,Zt,At,Kt,Xt,Ht],Yt=[Gt];function te(...t){return t.flat()}const ee=/* @__PURE__ */te(Jt,Qt,Vt,Yt);function ne(t,e=!1){const n=t.split("\n");let r=0;const o=[];for(let t=0;t<n.length;t++){const s=n[t],i=s.trimEnd(),l=o[o.length-1],c=t<n.length-1?$t(s):null,f=void 0!==l&&null!==$t(l);if(at.test(i))o.push(i);else if(0===r){{const t=i.match(ft);if(t){r=t[1].trim().length,o.push(i);continue}}""===i||""===l||!l||lt.test(l)||lt.test(i)||ct.test(i)||ot.test(i)||st.test(i)||it.test(i)||dt.test(i)||gt(i)||f||!e||ht.test(i)||pt.test(i)||mt(pt).test(l)||mt(ht).test(l)||ut.test(l)?o.push(!e&&""!==i||null!==c?s:i):o[o.length-1]=l+" "+(null===c?i:s).trimStart()}else{if(ut.test(i)&&i.trim().length>=r){r=0,o.push(i);continue}o.push(s)}}return o.join("\n")}function re(t,e,n,r,o,s){let i=t.isSelected(e);for(const l of n){if(!l.export)continue;const n=l.export(t,t=>oe(t,e,r,o,s).markdown,e);if(null!=n)return!i&&u(t)&&oe(t,e,r,o,s).shouldInclude&&(i=!0),{markdown:n,shouldInclude:i}}if(u(t)){const n=oe(t,e,r,o,s);return{markdown:n.markdown,shouldInclude:i||n.shouldInclude}}return a(t)?{markdown:t.getTextContent(),shouldInclude:i}:{markdown:null,shouldInclude:i}}function oe(t,n,r,o,s,i,l){const f=[],d=t.getChildren();let g=!1;i||(i=[]),l||(l=[]);t:for(const t of d){let d=t.isSelected(n);for(const e of o){if(!e.export)continue;const c=e.export(t,t=>oe(t,n,r,o,s,i,[...l,...i]).markdown,(t,e)=>ce(t,F(n,t,"clone").getTextContent(),r,i,l,s));if(null!=c){!d&&u(t)&&t.getChildren().some(t=>t.isSelected(n))&&t.extractWithChild(t,n,"html")&&(d=!0),d&&(f.push(c),g=!0);continue t}}if(c(t))d&&(f.push(le(t)),g=!0);else if(e(t)){if(d){const e=F(n,t,"clone");f.push(ce(t,e.getTextContent(),r,i,l,s)),g=!0}}else if(u(t)){const e=oe(t,n,r,o,s,i,l);!d&&e.shouldInclude&&t.extractWithChild(t,n,"html")&&(d=!0),(d||e.shouldInclude)&&(f.push(e.markdown),g=!0)}else a(t)&&d&&(f.push(t.getTextContent()),g=!0)}return{markdown:f.join(""),shouldInclude:g}}function se(t,e,n,r,o){for(const s of e){if(!s.export)continue;const e=s.export(t,t=>ie(t,n,r,void 0,void 0,o));if(null!=e)return e}return u(t)?ie(t,n,r,void 0,void 0,o):a(t)?t.getTextContent():null}function ie(t,n,r,o,s,i=!1){const l=[],f=t.getChildren();o||(o=[]),s||(s=[]);t:for(const t of f){for(const e of r){if(!e.export)continue;const c=e.export(t,t=>ie(t,n,r,o,[...s,...o],i),(t,e)=>ce(t,e,n,o,s,i));if(null!=c){l.push(c);continue t}}c(t)?l.push(le(t)):e(t)?l.push(ce(t,t.getTextContent(),n,o,s,i)):u(t)?l.push(ie(t,n,r,o,s,i)):a(t)&&l.push(t.getTextContent())}return l.join("")}function le(t){return o(t,It)+"\n"}function ce(t,e,n,r,o,s=!1){const i=t.hasFormat("code");let l,c,f,u,a=e;if(i||(a=s?a.replace(/([*_`~])/g,"\\$1"):a.replace(/([*_`~\\])/g,"\\$1")),i){const{fence:t,padded:n}=function(t){const e=t.match(/`+/g),n=e?Math.max(...e.map(t=>t.length)):0;return{fence:"`".repeat(n+1),padded:0===t.length||t.includes("`")||/^\s/.test(t)&&/\s$/.test(t)?` ${t} `:t}}(e);l="",f="",c=t+n+t,u=!1}else{const t=a.match(/^(\s*)(.*?)(\s*)$/s)||["","",a,""];l=t[1],c=t[2],f=t[3],u=""===c}let d="",g="",h="";const p=fe(t,!0),m=fe(t,!1),x=new Set;for(const e of n){const n=e.format[0],o=e.tag;"code"!==n&&(u||!ae(t,n)||x.has(n)||(x.add(n),ae(p,n)&&r.find(t=>t.tag===o)||(r.push({format:n,tag:o}),d+=o)))}for(let e=0;e<r.length;e++){const n=ue(t,r[e].format),s=ue(m,r[e].format);if(n&&s)continue;const i=[...r];for(;i.length>e;){const t=i.pop();o&&t&&o.find(e=>e.tag===t.tag)||(t&&"string"==typeof t.tag&&(n?s||(h+=t.tag):g+=t.tag),r.pop())}break}return u&&!t.hasFormat("code")?g+a:g+l+d+c+h+f}function fe(t,n){const r=n?t.getPreviousSibling():t.getNextSibling();return e(r)?r:null}function ue(t,n){return e(t)&&t.hasFormat(n)}function ae(t,e){return!(!ue(t,e)||"code"!==e&&t&&/^\s*$/.test(t.getTextContent()))}function de(t,e,n,r,o){if(!ge(e,n,r,o))return!1;if("*"===t)return!0;if("_"===t){if(!ge(e,n,r,!o))return!0;const t=o?e[n-1]:e[n+r];return void 0!==t&&tt.test(t)}return!0}function ge(t,e,n,r){const o=t[e-1],s=t[e+n],[i,l]=r?[s,o]:[o,s];return void 0!==i&&!Y.test(i)&&(!tt.test(i)||void 0===l||Y.test(l)||tt.test(l))}function he(t){return e(t)&&!t.hasFormat("code")}function pe(t,e,n){let r=function(t,e){const n=t.getTextContent(),r=e.transformersByTag["`"],o=[];let s=null;if(r){const t=function(t){const e=e=>{let n=0;for(let r=e-1;r>=0&&"\\"===t[r];r--)n++;return n%2==1},n=[];let r=0;for(;r<t.length;)if("`"===t[r]){let e=1;for(;r+e<t.length&&"`"===t[r+e];)e++;n.push({index:r,length:e}),r+=e}else r++;const o=[];let s=0;for(;s<n.length;){const r=n[s];if(e(r.index)){s++;continue}let i=-1;for(let t=s+1;t<n.length;t++)if(n[t].length===r.length){i=t;break}if(-1===i){s++;continue}const l=n[i];let c=t.slice(r.index+r.length,l.index);c.length>=2&&c.startsWith(" ")&&c.endsWith(" ")&&/[^ ]/.test(c)&&(c=c.slice(1,-1)),o.push({content:c,endIndex:l.index+l.length,startIndex:r.index}),s=i+1}return o}(n);for(const e of t)s||(s={content:e.content,endIndex:e.endIndex,startIndex:e.startIndex,tag:"`"}),o.push({end:e.endIndex,start:e.startIndex})}const i=function(t,e,n=[]){const r=[],o=new Set(Object.keys(e.transformersByTag).filter(t=>"`"!==t[0]).map(t=>t[0])),s=e=>{let n=0;for(let r=e-1;r>=0&&"\\"===t[r];r--)n++;return n%2==1},i=t=>n.some(e=>t>=e.start&&t<e.end);let l=0;for(;l<t.length;){const e=t[l];if(!o.has(e)||s(l)||i(l)){l++;continue}let n=1;for(;l+n<t.length&&t[l+n]===e;)n++;const c=de(e,t,l,n,!0),f=de(e,t,l,n,!1);(c||f)&&r.push({active:!0,canClose:f,canOpen:c,char:e,index:l,length:n}),l+=n}return r}(n,e,o),l=i.length>0?function(t,e,n){const r={};let o=0,s=null;for(;o<e.length;){const i=e[o];if(!i.active||!i.canClose||0===i.length){o++;continue}const l=`${i.char}${i.canOpen}${i.length%3}`,c=r[l]??-1;let f=!1;for(let r=o-1;r>c;r--){const l=e[r];if(!l.active||!l.canOpen||0===l.length||l.char!==i.char)continue;if((l.canClose||i.canOpen)&&(l.length+i.length)%3==0&&l.length%3!=0&&i.length%3!=0)continue;const c=Math.min(l.length,i.length),u=Object.keys(n.transformersByTag).filter(t=>t[0]===l.char&&t.length<=c).sort((t,e)=>e.length-t.length)[0];if(!u)continue;f=!0;const a=u.length,d={content:t.slice(l.index+l.length,i.index),endIndex:i.index+a,startIndex:l.index+(l.length-a),tag:u};(!s||d.startIndex<s.startIndex||d.startIndex===s.startIndex&&d.endIndex>s.endIndex)&&(s=d);for(let t=r+1;t<o;t++)e[t].active=!1;l.length-=a,i.length-=a,l.active=l.length>0,i.length>0?i.index+=a:(i.active=!1,o++);break}f||(r[l]=o-1,i.canOpen||(i.active=!1),o++)}return s}(n,i,e):null;let c=null,f=null;if(s&&l?l.startIndex<=s.startIndex&&l.endIndex>=s.endIndex?(c=l,f=e.transformersByTag[l.tag]):(c=s,f=r):s?(c=s,f=r):l&&(c=l,f=e.transformersByTag[l.tag]),!c||!f)return null;const u=[n.slice(c.startIndex,c.endIndex),c.tag,c.content];return u.index=c.startIndex,u.input=n,{endIndex:c.endIndex,isCodeSpan:f===r,match:u,startIndex:c.startIndex,transformer:f}}(t,e),o=function(t,e){const n=t;let r,o,s,i;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===r||void 0===o||l<r&&(c>o||c<=r))&&(r=l,o=c,s=t,i=e)}return void 0===r||void 0===o||void 0===s||void 0===i?null:{endIndex:o,match:i,startIndex:r,transformer:s}}(t,n);if(r&&o&&(r.isCodeSpan?o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex?r=null:o=null:r.startIndex<=o.startIndex&&r.endIndex>=o.endIndex||o.startIndex>r.endIndex?o=null:r=null),r){const o=function(t,e,n,r,o){const s=t.getTextContent();let i,l,c;if(o[0]===s?i=t:0===e?[i,l]=t.splitText(n):[c,i,l]=t.splitText(e,n),i.setTextContent(o[2]),r)for(const t of r.format)i.hasFormat(t)||i.toggleFormat(t);return{nodeAfter:l,nodeBefore:c,transformedNode:i}}(t,r.startIndex,r.endIndex,r.transformer,r.match);he(o.nodeAfter)&&pe(o.nodeAfter,e,n),he(o.nodeBefore)&&pe(o.nodeBefore,e,n),he(o.transformedNode)&&pe(o.transformedNode,e,n)}else if(o){const r=function(t,e,n,r,o){let s,i,l;return 0===e?[s,i]=t.splitText(n):[l,s,i]=t.splitText(e,n),r.replace?{nodeAfter:i,nodeBefore:l,transformedNode:r.replace(s,o)||void 0}:null}(t,o.startIndex,o.endIndex,o.transformer,o.match);if(!r)return;he(r.nodeAfter)&&pe(r.nodeAfter,e,n),he(r.nodeBefore)&&pe(r.nodeBefore,e,n),he(r.transformedNode)&&pe(r.transformedNode,e,n)}const s=rt(t.getTextContent());t.setTextContent(s)}function me(t,e,n,r=!1){const o=Q(n),s=function(t){const e={},n={},r=[];for(const o of t){const{tag:t}=o;e[t]=o;const s=t.replace(/(\*|\^|\+)/g,"\\$1");r.push(s),1===t.length?n[t]="`"===t?new RegExp("(^|[^\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(^|[^\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)(${s})(?![\\\\${s}])`):n[t]=new RegExp(`(^|[^\\\\])(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`(${r.join("|")})`,"g"),transformersByTag:e}}(o.textFormat),i=t.split("\n"),l=i.length;!function(t){const n=kt,c=Nt;kt=[],Nt=t;try{return(()=>{for(let t=0;t<l;t++){const n=i[t],[l,c]=xe(i,t,o.multilineElement,e);l?t=c:Ce(n,e,o.element,s,o.textMatch,r)}})()}finally{kt=n,Nt=c}}(!r);const c=e.getChildren();for(const t of c)if(!r&&nt(t)&&e.getChildrenSize()>1)t.remove();else if(u(t))for(const e of t.getAllTextNodes())Te(e)}function xe(t,e,n,r){for(const o of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:l}=o,c=t[e].match(i);if(!c)continue;if(n){const s=n({lines:t,rootNode:r,startLineIndex:e,startMatch:c,transformer:o});if(null===s)continue;if(s)return s}const f="object"==typeof s&&"regExp"in s?s.regExp:s,u=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let a=e;const d=t.length;for(;a<d;){const n=f?t[a].match(f):null;if(!n&&(!u||u&&a<d-1)){a++;continue}if(n&&e===a&&n.index===c.index){a++;continue}const o=[];if(n&&e===a)o.push(t[e].slice(c[0].length,-n[0].length));else for(let r=e;r<=a;r++)if(r===e){const e=t[r].slice(c[0].length);o.push(e)}else if(r===a&&n){const e=t[r].slice(0,-n[0].length);o.push(e)}else o.push(t[r]);if(!1!==l(r,null,c,n,o,!0))return[!0,a];break}}return[!1,e]}function Ce(e,n,o,i,l,c){const f=r(e),u=h();u.append(f),n.append(u);for(const{regExp:t,replace:n}of o){const r=e.match(t);if(r&&(f.setTextContent(e.slice(r[0].length)),!1!==n(u,[f],r,!0)))break}if(pe(f,i,l),null!==u.getParent()&&e.length>0){const e=u.getPreviousSibling();if(!c&&(t(e)||X(e)||A(e))){let t=e;if(A(e)){const n=e.getLastDescendant();t=null==n?null:s(n,D)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[vt(t),...u.getChildren()]),u.remove())}}}function Te(t){if(d(t))return;const e=t.getTextContent();if(!e.includes("\t"))return;const n=t.getFormat(),o=t.getStyle(),s=[];let i=0;for(let t=e.indexOf("\t");-1!==t;t=e.indexOf("\t",t+1))t>i&&s.push(r(e.slice(i,t)).setFormat(n).setStyle(o)),s.push(g()),i=t+1;i<e.length&&s.push(r(e.slice(i)).setFormat(n).setStyle(o)),t.getParentOrThrow().splice(t.getIndexWithinParent(),1,s)}function Ie(t,...e){throw function(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);return n.search=r.toString(),new 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.`)}(t,...e)}function $e(t,e,n,r,o){const s=t.getParent();if(!E(s)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(!o&&" "!==i[n-1])return!1;for(const{regExp:s,replace:l}of r){const r=i.match(s),c=o||r&&r[0].endsWith(" ")?n:n-1;if(r&&r[0].length===c){const o=e.getNextSiblings(),[s,i]=e.splitText(n);if(!1!==l(t,i?[i,...o]:o,r,!1))return s.remove(),!0}}return!1}function ve(t,e,n,r,o){const s=t.getParent();if(!E(s)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(!o&&" "!==i[n-1])return!1;for(const{regExpStart:s,replace:l,regExpEnd:c}of r){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const r=i.match(s);if(r){const s=o||r[0].endsWith(" ")?n:n-1;if(r[0].length!==s)continue;const i=e.getNextSiblings(),[c,f]=e.splitText(n);if(!1!==l(t,f?[f,...i]:i,r,null,null,!1))return c.remove(),!0}}return!1}function ye(t,e){let n=0;const r=t.getTextContent();for(let t=0;t<e;t++)"`"===r[t]&&n++;return n%2!=0}function Se(t,e,n){const r=n.length;for(let o=e;o>=r;o--){const e=o-r;if(be(t,e,n,0,r)&&" "!==t[e+r])return e}return-1}function Ee(t){const n=t.getNode();let r=0;if(e(n))r=t.offset;else if(u(n))for(const e of n.getChildren().slice(0,t.offset))r+=e.getTextContentSize();for(let t=n.getPreviousSibling();null!==t;t=t.getPreviousSibling())r+=t.getTextContentSize();return r}function be(t,e,n,r,o){for(let s=0;s<o;s++)if(t[e+s]!==n[r+s])return!1;return!0}function we(t,n=ee){const r=Q(n),o=r.element.filter(t=>t.triggerOnEnter),s=J(r.textFormat,({tag:t})=>t[t.length-1]),i=J(r.textMatch,({trigger:t})=>t),l=new Set([" "]);for(const t of r.textFormat)l.add(t.tag.slice(-1));for(const t of r.textMatch)void 0!==t.trigger&&l.add(t.trigger);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)||Ie(173,e.getType())}}return p(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:f,prevEditorState:u})=>{if(n.has(m)||n.has(x))return;if(t.isComposing())return;const a=n.has(C),d=f.read(T),g=u.read(T);if(!I(g)||!I(d)||!d.isCollapsed()||d.is(g)&&!a)return;const h=d.anchor.key,p=d.anchor.offset,y=f._nodeMap.get(h);if(e(y)&&o.has(h)&&(a||1===p||!(f.read(()=>Ee(d.anchor))>u.read(()=>Ee(g.anchor))+1))){if(a){const t=f.read(()=>y.getTextContent())[p-1];if(!l.has(t))return}t.update(()=>{if(!he(y))return;const t=y.getParent();null===t||M(t)||((t,n,o)=>!!($e(t,n,o,r.element)||ve(t,n,o,r.multilineElement)||function(t,e,n){let r=t.getTextContent();const o=n[r[e-1]];if(null==o)return!1;e<r.length&&(r=r.slice(0,e));for(const e of o){if(!e.replace||!e.regExp)continue;const n=r.match(e.regExp);if(null===n)continue;const o=n.index||0,s=o+n[0].length;let i;return 0===o?[i]=t.splitText(s):[,i]=t.splitText(o,s),i.selectNext(0,0),e.replace(i,n),!0}return!1}(n,o,i)||function(t,n,r){const o=t.getTextContent(),s=n-1,i=o[s],l=r[i];if(!l)return!1;for(const n of l){const{tag:r}=n,l=r.length,f=s-l+1;if(l>1&&!be(o,f,r,0,l))continue;if(" "===o[f-1])continue;const u=o[s+1];if(!1===n.intraword&&u&&!V.test(u))continue;const a=t;let d=a,g=Se(o,f,r),h=d;for(;g<0&&(h=h.getPreviousSibling())&&!c(h);)if(e(h)){if(h.hasFormat("code"))continue;const t=h.getTextContent();d=h,g=Se(t,t.length,r)}if(g<0)continue;if(d===a&&g+l===f)continue;const p=d.getTextContent();if(g>0&&p[g-1]===i)continue;const m=p[g-1];if(!1===n.intraword&&m&&!V.test(m))continue;if(!n.format.includes("code")&&ye(d,g))continue;const x=a.getTextContent(),C=x.slice(0,f)+x.slice(s+1);a.setTextContent(C);const $=d===a?C:p;d.setTextContent($.slice(0,g)+$.slice(g+l));const v=T(),y=b();w(y);const S=s-l*(d===a?2:1)+1;y.anchor.set(d.__key,g,"text"),y.focus.set(a.__key,S,"text");for(const t of n.format)y.formatText(t,k[t]);y.anchor.set(y.focus.key,y.focus.offset,y.focus.type);for(const t of n.format)y.hasFormat(t)&&y.toggleFormat(t);return I(v)&&(y.format=v.format),!0}return!1}(n,o,s)))(t,y,d.anchor.offset)&&$(v)})}}),t.registerCommand(y,t=>{if(null!==t&&t.shiftKey)return!1;const n=T();if(!I(n)||!n.isCollapsed())return!1;const s=n.anchor.offset,i=n.anchor.getNode();if(!e(i)||!he(i))return!1;const l=i.getParent();return null!==l&&!M(l)&&!(s!==i.getTextContent().length||!ve(l,i,s,r.multilineElement,!0)&&!$e(l,i,s,o,!0)||(null!==t&&t.preventDefault(),0))},S))}function ke(t,e=ee,n,r=!1,o=!1){const s=r?t:ne(t,o),i=n||f();i.clear(),me(s,i,e,r),null!==T()&&i.selectStart()}function Ne(t,e=ee,n=!1,r=!1){const o=n?t:ne(t,r),s=new N;return me(o,s,e,n),s.getChildren()}function Fe(t=ee,e,n=!1){const r=function(t,e=!1){const n=Q(t),r=[...n.multilineElement,...n.element],o=!e,s=n.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const i=[],l=(t||f()).getChildren();for(let t=0;t<l.length;t++){const c=l[t],f=se(c,r,s,n.textMatch,e);null!=f&&i.push(o&&t>0&&!nt(c)&&!nt(l[t-1])?"\n".concat(f):f)}return i.join("\n")}}(t,n);return r(e)}function Oe(t=ee,e,n=!1){if(!e||I(e)&&e.isCollapsed())return"";const r=function(t,e=!1){const n=Q(t),r=[...n.multilineElement,...n.element],o=!e,s=n.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const i=[];let l=null;for(const c of f().getChildren()){const{shouldInclude:f,markdown:u}=re(c,t,r,s,n.textMatch,e);f&&null!=u&&(i.push(!o||null===l||nt(c)||nt(l)?u:"\n".concat(u)),l=c)}return i.join("\n")}}(t,n);return r(e)}export{ke as $convertFromMarkdownString,Oe as $convertSelectionToMarkdownString,Fe as $convertToMarkdownString,Ne as $generateNodesFromMarkdownString,Wt as BOLD_ITALIC_STAR,Ut as BOLD_ITALIC_UNDERSCORE,Dt as BOLD_STAR,Zt as BOLD_UNDERSCORE,Rt as CHECK_LIST,Lt as CODE,Jt as ELEMENT_TRANSFORMERS,Mt as HEADING,At as HIGHLIGHT,zt as INLINE_CODE,Kt as ITALIC_STAR,Xt as ITALIC_UNDERSCORE,Gt as LINK,Qt as MULTILINE_ELEMENT_TRANSFORMERS,jt as ORDERED_LIST,Bt as QUOTE,Ht as STRIKETHROUGH,Vt as TEXT_FORMAT_TRANSFORMERS,Yt as TEXT_MATCH_TRANSFORMERS,ee as TRANSFORMERS,_t as UNORDERED_LIST,gt as isTableRowDivider,we as registerMarkdownShortcuts};
|
package/package.json
CHANGED
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
"markdown"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.52.0",
|
|
12
12
|
"main": "./dist/LexicalMarkdown.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/code-core": "0.
|
|
16
|
-
"@lexical/internal": "0.
|
|
17
|
-
"@lexical/link": "0.
|
|
18
|
-
"@lexical/list": "0.
|
|
19
|
-
"@lexical/rich-text": "0.
|
|
20
|
-
"@lexical/selection": "0.
|
|
21
|
-
"@lexical/text": "0.
|
|
22
|
-
"@lexical/utils": "0.
|
|
23
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/code-core": "0.52.0",
|
|
16
|
+
"@lexical/internal": "0.52.0",
|
|
17
|
+
"@lexical/link": "0.52.0",
|
|
18
|
+
"@lexical/list": "0.52.0",
|
|
19
|
+
"@lexical/rich-text": "0.52.0",
|
|
20
|
+
"@lexical/selection": "0.52.0",
|
|
21
|
+
"@lexical/text": "0.52.0",
|
|
22
|
+
"@lexical/utils": "0.52.0",
|
|
23
|
+
"lexical": "0.52.0"
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|