@lexical/mdast 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.
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{createRenderState as t,$withRenderContext as e,contextValue as n,createImportState as r,$withImportContext as o,CoreImportExtension as i,DOMImportExtension as s,RenderContextExport as l,$getSessionDOMRenderConfig as a,sel as c,ImportTextFormat as d,ImportTextStyle as u,$generateNodesFromDOMViaExtension as p}from"@lexical/html";import{$sliceSelectedTextNodeContent as m,getCSSFromStyleObject as h}from"@lexical/selection";import{createState as f,$createParagraphNode as g,$setState as x,$createTextNode as y,IS_STRIKETHROUGH as k,$createLineBreakNode as C,$isParagraphNode as $,$getState as v,$isTextNode as S,$isLineBreakNode as w,IS_CODE as T,$isElementNode as b,$isDecoratorNode as M,IS_BOLD as E,IS_ITALIC as R,$getRoot as N,$isRangeSelection as I,$getSelection as L,iterStaticNodeConfigChain as A,getStaticNodeConfig as F,tokenizeRawText as O,$createTabNode as B,mergeRegister as z,COLLABORATION_TAG as _,HISTORIC_TAG as H,COMPOSITION_END_TAG as q,$getNodeByKey as D,$addUpdateTag as P,HISTORY_PUSH_TAG as Z,KEY_ENTER_COMMAND as U,COMMAND_PRIORITY_BEFORE_EDITOR as j,$isRootOrShadowRoot as G,ParagraphNode as K,TextNode as Q,LineBreakNode as W,shallowMergeConfig as X,$getEditor as J,isHTMLElement as V,isDocumentFragment as Y,$getSlot as tt,$getDocument as et}from"lexical";import{toMarkdown as nt,defaultHandlers as rt}from"mdast-util-to-markdown";import{toString as ot}from"mdast-util-to-string";import{$createCodeNode as it,$isCodeNode as st,CodeNode as lt}from"@lexical/code-core";import{$createLinkNode as at,$isLinkNode as ct,$isAutoLinkNode as dt,LinkNode as ut}from"@lexical/link";import{$createListNode as pt,$createListItemNode as mt,$isListNode as ht,$isListItemNode as ft,ListNode as gt,ListItemNode as xt}from"@lexical/list";import{$createHeadingNode as yt,$createQuoteNode as kt,$isHeadingNode as Ct,$isQuoteNode as $t,QuoteNode as vt,HeadingNode as St}from"@lexical/rich-text";import{$getExtensionOutput as wt}from"@lexical/extension/getExtensionDependency";import{HorizontalRuleExtension as Tt,HorizontalRuleNode as bt,$createHorizontalRuleNode as Mt,$isHorizontalRuleNode as Et}from"@lexical/extension/HorizontalRuleExtension";import{effect as Rt}from"@lexical/extension/signals";import{getExtensionDependencyFromEditor as Nt}from"@lexical/extension/getExtensionDependencyFromEditor";import{namedSignals as It}from"@lexical/extension/namedSignals";import{gfmAutolinkLiteralToMarkdown as Lt,gfmAutolinkLiteralFromMarkdown as At}from"mdast-util-gfm-autolink-literal";import{gfmStrikethroughToMarkdown as Ft,gfmStrikethroughFromMarkdown as Ot}from"mdast-util-gfm-strikethrough";import{gfmTaskListItemToMarkdown as Bt,gfmTaskListItemFromMarkdown as zt}from"mdast-util-gfm-task-list-item";import{gfmAutolinkLiteral as _t}from"micromark-extension-gfm-autolink-literal";import{gfmStrikethrough as Ht}from"micromark-extension-gfm-strikethrough";import{gfmTaskListItem as qt}from"micromark-extension-gfm-task-list-item";import{fromMarkdown as Dt}from"mdast-util-from-markdown";import{TableNode as Pt,TableRowNode as Zt,TableCellNode as Ut,$createTableNode as jt,$createTableRowNode as Gt,$createTableCellNode as Kt,TableCellHeaderStates as Qt,$isTableNode as Wt,$isTableRowNode as Xt,$isTableCellNode as Jt}from"@lexical/table";import{gfmTableToMarkdown as Vt,gfmTableFromMarkdown as Yt}from"mdast-util-gfm-table";import{gfmTable as te}from"micromark-extension-gfm-table";const ee=/* @__PURE__ */f("mdastListMarker",{parse:t=>"-"===t||"*"===t||"+"===t?t:"",resetOnCopyNode:!0}),ne=/* @__PURE__ */f("mdastOrderedMarker",{parse:t=>"."===t||")"===t?t:"",resetOnCopyNode:!0}),re=/* @__PURE__ */f("mdastEmphasisMarker",{parse:t=>"_"===t?"_":"",resetOnCopyNode:!0}),oe=/* @__PURE__ */f("mdastStrongMarker",{parse:t=>"_"===t?"_":"",resetOnCopyNode:!0}),ie=/* @__PURE__ */f("mdastSetext",{parse:t=>!0===t,resetOnCopyNode:!0}),se=/* @__PURE__ */f("mdastCodeFence",{parse:t=>"string"==typeof t&&/^(`{3,}|~{3,})$/.test(t)?t:"",resetOnCopyNode:!0}),le=/* @__PURE__ */f("mdastCodeMeta",{parse:t=>"string"==typeof t?t:"",resetOnCopyNode:!0}),ae=/* @__PURE__ */f("mdastHardLineBreak",{parse:t=>"string"==typeof t&&/^(\\| {2,})$/.test(t)?t:"",resetOnCopyNode:!0}),ce=/* @__PURE__ */f("mdastParagraphBreak",{parse:t=>!0===t,resetOnCopyNode:!0}),de=/* @__PURE__ */f("mdastHrMarker",{parse:t=>"-"===t||"*"===t||"_"===t?t:"",resetOnCopyNode:!0}),ue=/* @__PURE__ */f("mdastLinkStyle",{parse:t=>"inline"===t||"autolink"===t||"literal"===t?t:"",resetOnCopyNode:!0});function pe(t,e){return t.splice(t.getChildrenSize(),0,e)}function me(t){return(b(t)||M(t))&&!t.isInline()}function he(){return x(C(),ce,!0)}const fe=E,ge=R,xe=k,ye=T;function ke(){return fe|ge|xe|ye}const Ce=/* @__PURE__ */ke();function $e(t){if(t.ordered)return"number";for(const e of t.children)if("listItem"===e.type&&null!=e.checked)return"check";return"bullet"}function ve(t,e){return(n,r)=>{const o=r.importChildren(n,t);if("_"===function(t,e){if(t.source&&e.position&&null!=e.position.start.offset)return t.source[e.position.start.offset]}(r,n))for(const t of o)S(t)&&x(t,e,"_");return o}}const Se=/* @__PURE__ */ve(ge,re),we=/* @__PURE__ */ve(fe,oe),Te={h1:1,h2:2,h3:3,h4:4,h5:5,h6:6};function be(t,e){const n=t.getListType(),r={children:[],ordered:"number"===n,spread:!1,start:"number"===n?t.getStart():void 0,type:"list"};if("number"===n){const e=v(t,ne);e&&(r.data={mdastBulletOrdered:e})}else{const e=v(t,ee);e&&(r.data={mdastBullet:e})}let o=null;for(const i of t.getChildren()){if(!ft(i)||!e.isIncluded(i))continue;const t=i.getFirstChild();if(1===i.getChildrenSize()&&ht(t)){const n=be(t,e);o?o.children.push(n):r.children.push({children:[n],spread:!1,type:"listItem"});continue}const s={checked:"check"===n?i.getChecked()??!1:null,children:e.exportBlocks(i),spread:!1,type:"listItem"};r.children.push(s),o=s}return r}const Me=[[fe,"strong"],[ge,"emphasis"]];function Ee(t){const e=[];for(let n=0;n<t.length;){const{format:r,value:o}=t[n];let i=null,s=0,l=n+1;for(const[e,o]of Me){if(0===(r&e))continue;let a=n+1;for(;a<t.length&&t[a].format&e;)a++;(null===i||a>l)&&(i=o,s=e,l=a)}null===i?(e.push(r&ye?{type:"inlineCode",value:o}:{type:"text",value:o}),n++):(e.push({children:Ee(t.slice(n,l).map(t=>({format:t.format&~s,value:t.value}))),type:i}),n=l)}return e}const Re=t=>S(t)?function(t,e){let n=e&ye?{type:"inlineCode",value:t}:{type:"text",value:t};return e&ge&&(n={children:[n],type:"emphasis"}),e&fe&&(n={children:[n],type:"strong"}),e&xe&&(n={children:[n],type:"delete"}),n}(t.getTextContent(),t.getFormat()&Ce):null,Ne=t=>w(t)?{data:{mdastBreak:v(t,ae)},type:"break"}:null;function Ie(t,e,n){const{options:r}=t,o={};for(const t of Object.keys(e))o[t]=r[t],r[t]=e[t];try{return n()}finally{for(const t of Object.keys(o))r[t]=o[t]}}const Le={handlers:{break(t,e,n,r){const o=rt.break(t,e,n,r);if("\\\n"!==o)return o;const i=t.data&&t.data.mdastBreak;return i?/^ {2,}$/.test(i)?`${i}\n`:o:"\n"},code(t,e,n,r){const o=t.data&&t.data.mdastFence;return o?Ie(n,{fence:"~"===o[0]?"~":"`",fences:!0},()=>rt.code(t,e,n,r)):rt.code(t,e,n,r)},heading:(t,e,n,r)=>t.data&&!0===t.data.mdastSetext?Ie(n,{setext:!0},()=>rt.heading(t,e,n,r)):rt.heading(t,e,n,r),link(t,e,n,r){const o=t.data&&t.data.mdastLinkStyle;return"literal"===o&&null==t.title?ot(t):"inline"===o?Ie(n,{resourceLink:!0},()=>rt.link(t,e,n,r)):rt.link(t,e,n,r)},list(t,e,n,r){if(t.ordered){const o=t.data&&t.data.mdastBulletOrdered;return null==o?rt.list(t,e,n,r):Ie(n,{bulletOrdered:o},()=>rt.list(t,e,n,r))}const o=t.data&&t.data.mdastBullet;return null==o?rt.list(t,e,n,r):Ie(n,{bullet:o,bulletOther:"-"===o?"*":"-"},()=>rt.list(t,e,n,r))},thematicBreak(t,e,n){const r=t.data&&t.data.mdastRule;return"-"!==r&&"*"!==r&&"_"!==r?rt.thematicBreak(t,e,n):Ie(n,{rule:r},()=>rt.thematicBreak(t,e,n))}}};function Ae(t,e,n){if(Object.keys(t).some(t=>"type"!==t&&"value"!==t&&"children"!==t))return!1;if("text"===t.type||"inlineCode"===t.type)return n.push({format:e|("inlineCode"===t.type?T:0),value:t.value}),!0;const r="strong"===t.type?E:"emphasis"===t.type?R:"delete"===t.type?k:0;return 0!==r&&"children"in t&&t.children.every(t=>Ae(t,e|r,n))}class Fe{runs=[];push(t){return!!S(t)&&(this.pushRun(t.getTextContent(),t.getFormat()&Ce),!0)}pushRun(t,e){const n=this.runs[this.runs.length-1];void 0!==n&&n.format===e?n.value+=t:this.runs.push({format:e,value:t})}appendExported(t,e){const n=[];if(t.every(t=>Ae(t,0,n)))for(const t of n)this.pushRun(t.value,t.format);else this.flushInto(e),e.push(...t)}flushInto(t){this.runs.length>0&&(t.push(...function(t){const e=[];for(let n=0;n<t.length;){const r=0!==(t[n].format&xe);let o=n+1;for(;o<t.length&&0!==(t[o].format&xe)===r;)o++;const i=t.slice(n,o);r?e.push({children:Ee(i.map(t=>({format:t.format&~xe,value:t.value}))),type:"delete"}):e.push(...Ee(i)),n=o}return e}(this.runs)),this.runs=[])}}function Oe(t,e=null){const{exportHandlers:n}=t;let r=0;function o(t){const e=n.get(t.getType()),r=e&&e[0];return void 0===r||r===Re}function i(t){return null===e||b(t)?t:t.isSelected(e)?(r++,S(t)?m(e,t,"clone"):t):null}function s(t,n){const o=null!==e&&t.isSelected(e);o&&r++;const i=r,s=c(t);(null===e||o||r>i)&&n.push(...s)}function l(t){return Array.isArray(t)?t:t.getChildren()}const a={exportBlocks:t=>function(t){const e=[];let n=[];const r=new Fe,a=()=>{r.flushInto(n),n.length>0&&(e.push({children:n,type:"paragraph"}),n=[])};for(const d of l(t)){const t=i(d);if(null!==t)if(w(t)){const e=Ne(t);v(t,ce)||null===e?a():(r.flushInto(n),n.push(e))}else{if(o(t)&&r.push(t))continue;S(t)?r.appendExported(c(t),n):me(t)?(a(),b(t)?s(t,e):e.push(...c(t))):b(t)?(r.flushInto(n),s(t,n)):(r.flushInto(n),n.push(...c(t)))}}return a(),0===e.length&&e.push({children:[],type:"paragraph"}),e}(t),exportChildren:t=>{const e=[];for(const n of l(t)){const t=i(n);null!==t&&(b(t)?s(t,e):e.push(...c(t)))}return e},exportInline:t=>function(t){const e=[],n=new Fe;for(const r of l(t)){const t=i(r);if(!(null===t||o(t)&&n.push(t))){if(S(t)){n.appendExported(c(t),e);continue}n.flushInto(e),b(t)?s(t,e):e.push(...c(t))}}return n.flushInto(e),e}(t),isIncluded:function t(n){if(null===e||n.isSelected(e))return!0;if(b(n))for(const e of n.getChildren())if(t(e))return!0;return!1}};function c(t,e=n.get(t.getType()),r=0){const o=e&&e[r];if(o){const n=o(t,{...a,next:()=>c(t,e,r+1)});if(null!=n)return Array.isArray(n)?n:[n]}const i=Re(t);if(null!==i)return[i];const s=Ne(t);if(null!==s)return[s];if(b(t))return a.exportChildren(t);const l=t.getTextContent();return l?[{type:"text",value:l}]:[]}return{exportChildren:a.exportChildren}}const Be=/* @__PURE__ */t("markdownSelection",()=>null);function ze(t){if("string"==typeof t)return t;const{ownNodeType:e,ownNodeConfig:n,declaresOwnConfig:r}=F(t);return(void 0===e||!r&&void 0!==n)&&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);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.`)}(436),e}const _e=/* @__PURE__ */r("isMarkdownImport",Boolean);function He(t,e){const n=[];return O(t,{linebreak:()=>n.push(C()),tab:()=>n.push(B().setFormat(e)),text:t=>{const r=y(t);e&&r.setFormat(e),n.push(r)}}),n}const qe=new Map;function De(t,e="",r=qe){const{importHandlers:i}=t,s=new Map;function l(t){let n=s.get(t);return void 0===n&&(n={createText:(e,n)=>He(e,n??t),format:t,getDefinition:t=>r.get(t),importChildren:(e,n)=>c(e,t|(n||0)),importNode:(e,n)=>a(e,t|(n||0)),source:e},s.set(t,n)),n}function a(t,e,n=i.get(t.type),r=0){const o=n&&n[r];if(o){const i=o(t,{...l(e),next:()=>a(t,e,n,r+1)});return null==i?[]:Array.isArray(i)?i:[i]}return"children"in t?c(t,e):"value"in t&&"string"==typeof t.value?He(t.value,e):[]}function c(t,e){const n=[];for(const r of t.children)n.push(...a(r,e));return n}const d=t=>o([n(_e,!0)])(t);return{$importChildren:(t,e)=>d(()=>c(t,e)),$importNode:(t,e)=>d(()=>a(t,e))}}function Pe(t,e){let n=t;for(;;){if("heading"===n.type||"paragraph"===n.type){const t=n.children[0];return t&&t.position&&null!=t.position.start.offset?t.position.start.offset:e.length}if(!("children"in n)||0===n.children.length)return e.length;n=n.children[0]}}class Ze{compiled;importNode;supportsTaskListItems;constructor(t){this.compiled=t,this.importNode=De(t,"").$importNode;const e=this.parse("- [x] a").children[0];this.supportsTaskListItems=null!=e&&"list"===e.type&&!0===e.children[0].checked}get inlineTriggers(){return this.compiled.inlineShortcutTriggers}parse(t){return Dt(t,{extensions:this.compiled.micromarkExtensions,mdastExtensions:this.compiled.mdastExtensions})}importInline(t){return this.importNode(t,0)}scanBlock(t){if(""===t.trim())return null;const e=this.parse(t).children[0];if(!e||!this.compiled.importHandlers.has(e.type))return null;switch(e.type){case"heading":return{kind:"heading",markerLength:Pe(e,t),node:e};case"blockquote":return{kind:"blockquote",markerLength:Pe(e,t),node:e};case"list":return{kind:"list",markerLength:Pe(e,t),node:e};case"code":return{kind:"code",markerLength:t.length,node:e};default:return null}}scanInline(t){if(0===t.length)return null;const e=this.parse(t),n=e.children[e.children.length-1];if(!n||"paragraph"!==n.type)return null;const r=n.children[n.children.length-1];if(!r||!r.position||r.position.end.offset!==t.length||!this.compiled.inlineShortcutTypes.has(r.type))return null;const o=r.position.start.offset??0,i=t[o];return o>0&&t[o-1]===i&&this.compiled.inlineShortcutTriggers.has(i)?null:r}}function Ue(t,e){let n=e,r=t.getFirstChild();for(;n>0&&r&&S(r);){const t=r.getTextContent();if(t.length<=n){const e=r.getNextSibling();n-=t.length,r.remove(),r=e}else r.setTextContent(t.slice(n)),n=0}}function je(t,e){$t(t)?t.setIsShadowRoot(!0).append(e):t.replace(e)}function Ge(t,e){const n="code"===e.kind?t.getTextContent().match(/^[ \t]*(`{3,}|~{3,})/):null;Ue(t,e.markerLength);const r=t.getChildren();if("code"===e.kind){const o=it(e.node.lang||void 0);return n&&x(o,se,n[1]),e.node.meta&&x(o,le,e.node.meta),pe(o,r),je(t,o),o.selectStart(),!0}let o,i;if("heading"===e.kind){const t=pe(yt(`h${e.node.depth}`),r);o=t,i=t}else if("blockquote"===e.kind){const t=pe(kt(),r);o=t,i=t}else{const t=e.node,n=$e(t),s=t.ordered&&null!=t.start?t.start:1,l=pt(n,s),a=t.children[0],c=a&&"listItem"===a.type&&"boolean"==typeof a.checked?a.checked:void 0,d=pe(mt(c),r);pe(l,[d]),o=l,i=d}return je(t,o),i.selectStart(),!0}const Ke=/^\[([ xX])\]\s$/;function Qe(t,e){return $(t)&&G(t.getParent())&&t.getFirstChild()===e}function We(t,e){return Qe(t,e)||function(t,e){return $t(t)&&!t.isShadowRoot()&&G(t.getParent())&&t.getFirstChild()===e}(t,e)}const Xe=[{$import:(t,e)=>pe(g(),e.importChildren(t)),type:"paragraph"},{$import:(t,e)=>e.createText(t.value),type:"text"},{$import:(t,e)=>e.createText(t.value),type:"html"},{$import:(t,e)=>e.createText(t.value,e.format|ye),type:"inlineCode"},{$import:Se,type:"emphasis"},{$import:we,type:"strong"},{$import:(t,e)=>{let n="\\";if(e.source&&t.position){const{start:r,end:o}=t.position;if(null!=r.offset&&null!=o.offset){const t=e.source.slice(r.offset,o.offset).replace(/\n$/,"");/^ {2,}$/.test(t)&&(n=t)}}return[x(C(),ae,n)]},type:"break"}],Je=[{$export:(t,e)=>$(t)?{children:e.exportInline(t),type:"paragraph"}:null,type:K},{$export:Re,type:Q},{$export:Ne,type:W}],Ve={build(t,r){const o=function(t,e){const n=new Map;for(const t of e.importRules){const e=n.get(t.type);e?e.push(t.$import):n.set(t.type,[t.$import])}const r=new Map;for(const t of e.exportRules){const e=ze(t.type),n=r.get(e);n?n.push(t.$export):r.set(e,[t.$export])}const o=new Map(r);for(const[e,{klass:n}]of t._nodes){const t=[],i=new Set;for(const{ownNodeType:e}of A(n))void 0===e||i.has(e)||(i.add(e),t.push(...r.get(e)||[]));t.length>0&&o.set(e,t)}return{exportHandlers:o,importHandlers:n,inlineShortcutTriggers:new Set(e.inlineShortcutTriggers),inlineShortcutTypes:new Set(e.inlineShortcutTypes),mdastExtensions:[...e.mdastExtensions],micromarkExtensions:[...e.micromarkExtensions],toMarkdownExtensions:[...e.toMarkdownExtensions]}}(t,r),{$exportSelectionToMarkdown:i,$exportToMdast:s,$exportToMarkdown:l}=function(t){const r=Oe(t),o=(t,e)=>({children:e.exportChildren(t),type:"root"}),i=(e,n)=>{const{emphasis:r,strong:o}=function(t){let e,n;const r=t=>{for(const o of t.getChildren())if(S(o)?(void 0===e&&o.hasFormat("italic")&&"_"===v(o,re)&&(e="_"),void 0===n&&o.hasFormat("bold")&&"_"===v(o,oe)&&(n="_")):b(o)&&r(o),void 0!==e&&void 0!==n)return};return r(t),{emphasis:e,strong:n}}(n),i={bullet:"-"};return r&&(i.emphasis=r),o&&(i.strong=o),nt(e,{extensions:[i,...t.toMarkdownExtensions,Le]}).replace(/\n$/,"")};return{$exportSelectionToMarkdown:(r=L())=>{if(null===r||I(r)&&r.isCollapsed())return"";const s=N();return e([n(Be,r)])(()=>i(o(s,Oe(t,r)),s))},$exportToMarkdown:t=>{const e=t||N();return i(o(e,r),e)},$exportToMdast:t=>o(t||N(),r)}}(o),{$generateNodesFromMarkdown:a,$generateNodesFromMdast:c,$importMarkdown:d,$importMdast:u}=function(t){const e=(e,n)=>{const{$importNode:r}=De(t,n,function(t){const e=new Map,n=t=>{if("definition"===t.type&&(e.has(t.identifier)||e.set(t.identifier,{title:t.title,url:t.url})),"children"in t)for(const e of t.children)n(e)};return n(t),e}(e)),o=[];let i=null;const s=()=>{i&&(o.push(i),i=null)};for(const t of e.children)for(const e of r(t,0))me(e)?(s(),o.push(e)):(i||(i=g()),pe(i,[e]));return s(),o},n=n=>e(Dt(n,{extensions:t.micromarkExtensions,mdastExtensions:t.mdastExtensions}),n),r=t=>e(t,""),o=(t,e)=>{const n=e||N();var r,o;n.clear(),r=n,o=t.length>0?t:[g()],r.splice(0,0,o),null!==L()&&n.selectStart()};return{$generateNodesFromMarkdown:n,$generateNodesFromMdast:r,$importMarkdown:(t,e)=>o(n(t),e),$importMdast:(t,e)=>o(r(t),e)}}(o);return{$convertFromMarkdownString:d,$convertFromMdast:u,$convertSelectionToMarkdownString:i,$convertToMarkdownString:l,$convertToMdast:s,$generateNodesFromMarkdownString:a,$generateNodesFromMdast:c,registry:o}},config:{exportRules:Je,importRules:Xe,inlineShortcutTriggers:["*","_","`"],inlineShortcutTypes:["emphasis","inlineCode","strong"],mdastExtensions:[],micromarkExtensions:[],toMarkdownExtensions:[]},mergeConfig(t,e){function n(t,e){return t?[...t,...e]:e}return X(t,{exportRules:n(e.exportRules,t.exportRules),importRules:n(e.importRules,t.importRules),inlineShortcutTriggers:n(e.inlineShortcutTriggers,t.inlineShortcutTriggers),inlineShortcutTypes:n(e.inlineShortcutTypes,t.inlineShortcutTypes),mdastExtensions:n(e.mdastExtensions,t.mdastExtensions),micromarkExtensions:n(e.micromarkExtensions,t.micromarkExtensions),toMarkdownExtensions:n(e.toMarkdownExtensions,t.toMarkdownExtensions)})},name:"@lexical/mdast/Mdast"},Ye=Ve,tn={dependencies:[[Ve,{exportRules:[{$export:(t,e)=>{if(!Ct(t))return null;const n={children:e.exportInline(t),depth:Te[t.getTag()],type:"heading"};return v(t,ie)&&(n.data={mdastSetext:!0}),n},type:St}],importRules:[{$import:(t,e)=>{const n=yt(`h${t.depth}`);if(e.source&&t.position&&(1===t.depth||2===t.depth)){const r=t.position.start.offset;null==r||/^ {0,3}#{1,6}([ \t\r\n]|$)/.test(e.source.slice(r,r+10))||x(n,ie,!0)}return pe(n,e.importChildren(t))},type:"heading"}]}]],name:"@lexical/mdast/Heading",nodes:[St]},en={dependencies:[[Ve,{exportRules:[{$export:(t,e)=>$t(t)?{children:t.isShadowRoot()?e.exportChildren(t):e.exportBlocks(t),type:"blockquote"}:null,type:vt}],importRules:[{$import:(t,e)=>{const n=kt(),r=[];for(const n of t.children)"paragraph"===n.type?(r.length>0&&r.push(he()),r.push(...e.importChildren(n))):r.push(...e.importNode(n));return pe(n,r)},type:"blockquote"}]}]],name:"@lexical/mdast/Blockquote",nodes:[vt]},nn={dependencies:[tn,en],name:"@lexical/mdast/RichText"},rn={dependencies:[[Ve,{exportRules:[{$export:(t,e)=>ht(t)?be(t,e):null,type:gt}],importRules:[{$import:(t,e)=>{const n=$e(t),r=t.ordered&&null!=t.start?t.start:1,o=pt(n,r),i=t.children[0],s=e.source&&i&&i.position?i.position.start.offset:void 0;if(null!=s){const t=e.source.slice(s,s+16);if("number"===n){const e=t.match(/^\s*\d+([.)])/),n=e&&e[1];"."!==n&&")"!==n||x(o,ne,n)}else{const e=t.match(/^\s*([-*+])/),n=e&&e[1];"-"!==n&&"*"!==n&&"+"!==n||x(o,ee,n)}}return pe(o,t.children.flatMap(t=>e.importNode(t)))},type:"list"},{$import:(t,e)=>{const n=mt("boolean"==typeof t.checked?t.checked:void 0),r=[];for(const o of t.children)"list"===o.type?r.push(pe(mt(),e.importNode(o))):"paragraph"===o.type?(n.getChildrenSize()>0&&pe(n,[he()]),pe(n,e.importChildren(o))):pe(n,e.importNode(o));return[n,...r]},type:"listItem"}]}]],name:"@lexical/mdast/List",nodes:[gt,xt]},on={dependencies:[rn,[Ve,{mdastExtensions:[/* @__PURE__ */zt()],micromarkExtensions:[/* @__PURE__ */qt()],toMarkdownExtensions:[/* @__PURE__ */Bt()]}]],name:"@lexical/mdast/TaskList"},sn={dependencies:[[Ve,{exportRules:[{$export:t=>{if(!st(t))return null;const e={lang:t.getLanguage()||null,type:"code",value:t.getTextContent()},n=v(t,le);n&&(e.meta=n);const r=v(t,se);return r&&(e.data={mdastFence:r}),e},type:lt}],importRules:[{$import:(t,e)=>{const n=it(t.lang||void 0);if(e.source&&t.position&&null!=t.position.start.offset){const r=t.position.start.offset,o=e.source.indexOf("\n",r),i=e.source.slice(r,-1===o?void 0:o).match(/^[ \t]*(`{3,}|~{3,})/);i&&x(n,se,i[1])}return t.meta&&x(n,le,t.meta),t.value&&pe(n,[y(t.value)]),n},type:"code"}]}]],name:"@lexical/mdast/Code",nodes:[lt]},ln={dependencies:[[Ve,{exportRules:[{$export:(t,e)=>{if(!ct(t)||dt(t))return null;const n={children:e.exportInline(t),title:t.getTitle()??null,type:"link",url:t.getURL()},r=v(t,ue);return r&&(n.data={mdastLinkStyle:r}),n},type:ut}],importRules:[{$import:(t,e)=>{const n=pe(at(t.url,{title:null==t.title?void 0:t.title}),e.importChildren(t));if(e.source&&t.position&&null!=t.position.start.offset){const r=e.source[t.position.start.offset];x(n,ue,"["===r?"inline":"<"===r?"autolink":"literal")}return n},type:"link"},{$import:(t,e)=>{const n=e.getDefinition(t.identifier);if(n)return pe(at(n.url,{title:null==n.title?void 0:n.title}),e.importChildren(t));const{position:r}=t;return e.source&&r&&null!=r.start.offset?e.createText(e.source.slice(r.start.offset,r.end.offset)):[...e.createText("["),...e.importChildren(t),...e.createText("]")]},type:"linkReference"},{$import:()=>[],type:"definition"}],inlineShortcutTriggers:[")"],inlineShortcutTypes:["link"]}]],name:"@lexical/mdast/Link",nodes:[ut]},an={dependencies:[ln,[Ve,{mdastExtensions:[/* @__PURE__ */At()],micromarkExtensions:[/* @__PURE__ */_t()],toMarkdownExtensions:[/* @__PURE__ */Lt()]}]],name:"@lexical/mdast/AutolinkLiteral"},cn={dependencies:[en,[Ve,{importRules:[{$import:(t,e)=>pe(kt({shadowRoot:!0}),function(t,e){const n=[];let r=null;const o=()=>{r&&(n.push(r),r=null)};for(const i of t.children)for(const t of e.importNode(i))me(t)?(o(),n.push(t)):(r||(r=g()),pe(r,[t]));return o(),n}(t,e)),type:"blockquote"}]}]],name:"@lexical/mdast/ShadowRootQuote"},dn={dependencies:[Tt,[Ve,{exportRules:[{$export:t=>{if(!Et(t))return null;const e={type:"thematicBreak"},n=v(t,de);return n&&(e.data={mdastRule:n}),e},type:bt}],importRules:[{$import:(t,e)=>{const n=Mt();if(e.source&&t.position&&null!=t.position.start.offset){const r=e.source.slice(t.position.start.offset,t.position.start.offset+4).trimStart()[0];"-"!==r&&"*"!==r&&"_"!==r||x(n,de,r)}return n},type:"thematicBreak"}]}]],name:"@lexical/mdast/HorizontalRule"},un={dependencies:[[Ve,{importRules:[{$import:(t,e)=>e.importChildren(t,xe),type:"delete"}],inlineShortcutTriggers:["~"],inlineShortcutTypes:["delete"],mdastExtensions:[/* @__PURE__ */Ot()],micromarkExtensions:[/* @__PURE__ */Ht()],toMarkdownExtensions:[/* @__PURE__ */Ft()]}]],name:"@lexical/mdast/Strikethrough"},pn={dependencies:[nn,rn,sn,ln,dn],name:"@lexical/mdast/CommonMark"},mn={build:(t,e)=>It(e),config:{disabled:!1},dependencies:[Ve],name:"@lexical/mdast/Shortcuts",register:(t,e,n)=>{const{disabled:r}=n.getOutput();return Rt(()=>{if(r.value)return;const{registry:e}=Nt(t,Ve).output;return function(t,e){const n=new Ze(e),r=n.inlineTriggers,o=new Set([" ",...r]);return z(t.registerUpdateListener(({tags:e,dirtyLeaves:i,editorState:s,prevEditorState:l})=>{if(0===i.size||e.has(_)||e.has(H))return;if(t.isComposing())return;const a=e.has(q),c=s.read(L),d=l.read(L);if(!I(c)||!I(d)||!c.isCollapsed()||c.is(d)&&!a)return;const u=c.anchor.key,p=c.anchor.offset,m=s._nodeMap.get(u);if(!S(m)||!i.has(u))return;if(!a&&1!==p&&(d.anchor.key!==u||p!==d.anchor.offset+1))return;const h=s.read(()=>m.getTextContent()),f=h[p-1];var g,x;a&&!o.has(f)||(" "===f||r.has(f))&&(" "===f||(g=h.slice(0,p),")"===(x=f)?g.lastIndexOf("](")>0:-1!==g.lastIndexOf(x,g.length-2)))&&t.update(()=>{const t=D(u);if(!S(t)||t.hasFormat("code"))return;const e=t.getParent();if(null===e||st(e))return;let r=!1;if(" "===f){if(n.supportsTaskListItems&&function(t,e,n){if(e.getFirstChild()!==t)return!1;const r=e.getTextContent().slice(0,n).match(Ke);if(!r)return!1;const o="x"===r[1].toLowerCase();if(ft(e)){const t=e.getParent();return!(!ht(t)||"number"===t.getListType()||(Ue(e,r[0].length),t.setListType("check"),e.setChecked(o),0))}if(Qe(e,t)){Ue(e,r[0].length);const t=e.getChildren(),n=pt("check"),i=pe(mt(o),t);return pe(n,[i]),e.replace(n),i.selectStart(),!0}return!1}(t,e,p))r=!0;else if(p<=24&&We(e,t)){const o=n.scanBlock(t.getTextContent().slice(0,p));o&&"code"!==o.kind&&o.markerLength===p&&(r=Ge(e,o))}}else r=function(t,e,n){const r=t.getTextContent().slice(0,e),o=n.scanInline(r);if(!o||!o.position)return!1;const i=o.position.start.offset??0,s=e;let l;if(i<=0)[l]=t.splitText(s);else{const e=t.splitText(i,s);l=3===e.length?e[1]:e[e.length-1]}const a=n.importInline(o);if(0===a.length)return!1;let c=a[0];l.replace(c);for(let t=1;t<a.length;t++)c.insertAfter(a[t]),c=a[t];if(S(c)){const t=c.getTextContentSize();c.select(t,t)}else c.selectNext(0,0);return!0}(t,p,n);r&&P(Z)})}),t.registerCommand(U,t=>{if(null!==t&&t.shiftKey)return!1;const e=L();if(!I(e)||!e.isCollapsed())return!1;const r=e.anchor.getNode();if(!S(r)||r.hasFormat("code"))return!1;const o=r.getParent(),i=e.anchor.offset;if(null===o||st(o)||!We(o,r)||i!==r.getTextContentSize())return!1;const s=n.scanBlock(o.getTextContent());return!(!s||s.markerLength!==i||!Ge(o,s)||(null!==t&&t.preventDefault(),0))},j))}(t,e)})}};function hn(t,e){wt(Ve).$convertFromMarkdownString(t,e)}function fn(t,e){wt(Ve).$convertFromMdast(t,e)}function gn(t){return wt(Ve).$generateNodesFromMarkdownString(t)}function xn(t){return wt(Ve).$generateNodesFromMdast(t)}const yn=Ve;function kn(t){return wt(Ve).$convertToMarkdownString(t)}function Cn(t){return wt(Ve).$convertToMdast(t)}function $n(t){return wt(Ve).$convertSelectionToMarkdownString(t)}const vn=/* @__PURE__ */f("mdastTableAlign",{parse:t=>Array.isArray(t)?t.map(t=>"center"===t||"left"===t||"right"===t?t:null):[],resetOnCopyNode:!0}),Sn={dependencies:[[Ve,{exportRules:[{$export:(t,e)=>{if(!Wt(t))return null;const n=[];for(const r of t.getChildren()){if(!Xt(r)||!e.isIncluded(r))continue;const t=[];for(const n of r.getChildren()){if(!Jt(n))continue;const r=[];for(const t of n.getChildren())b(t)&&(r.length>0&&r.push({type:"break"}),r.push(...e.exportInline(t)));t.push({children:r,type:"tableCell"})}n.push({children:t,type:"tableRow"})}return{align:v(t,vn),children:n,type:"table"}},type:Pt}],importRules:[{$import:(t,e)=>{const n=jt();return t.align&&t.align.some(t=>null!=t)&&x(n,vn,t.align),t.children.forEach((t,r)=>{const o=Gt();for(const n of t.children){const t=Kt(0===r?Qt.ROW:Qt.NO_STATUS),i=g();pe(i,e.importChildren(n)),pe(t,[i]),pe(o,[t])}pe(n,[o])}),n},type:"table"}],mdastExtensions:[/* @__PURE__ */Yt()],micromarkExtensions:[/* @__PURE__ */te()],toMarkdownExtensions:[/* @__PURE__ */Vt()]}]],name:"@lexical/mdast/Table",nodes:[Pt,Zt,Ut]},wn={dependencies:[un,on,an,Sn],name:"@lexical/mdast/Gfm"},Tn=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),bn=/<!--[\s\S]*?-->/g,Mn=/<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:[^"'>]|"[^"]*"|'[^']*')*?)(\/?)>/g;function En(t){let e=0;for(const n of t.replace(bn,"").matchAll(Mn)){const[,t,r,,o]=n;Tn.has(r.toLowerCase())||(t?e-=1:o||(e+=1))}return e}function Rn(t){const e=t.replace(bn,"");return!e.matchAll(Mn).next().done||""===e.trim()}function Nn(t,e){const n=t.children[e];if("html"!==n.type||!Rn(n.value))return null;let r=n.value;const o=[];let i=1,s=En(n.value);if(s>0){let n=[],l=!1;for(let a=e+1;a<t.children.length;a++){const c=t.children[a];if("html"===c.type){for(const t of n)r+=`<template data-mdast-child="${o.length}"></template>`,o.push(t);if(n=[],r+="\n"+c.value,s+=En(c.value),s<=0){l=!0,i=a-e+1;break}}else n.push(c)}if(!l)return null}const l={children:o,type:"htmlBlock",value:r};return t.children.splice(e,i,l),l}function In(t,e){const n=t.children[e];if("html"!==n.type||!Rn(n.value))return null;let r=n.value;const o=[];let i=1,s=En(n.value);if(s>0){let n=[],l=!1;for(let a=e+1;a<t.children.length;a++){const c=t.children[a];if("html"===c.type){for(const t of n)r+=`<span data-mdast-child="${o.length}">&#8203;</span>`,o.push(t);if(n=[],r+=c.value,s+=En(c.value),s<=0){l=!0,i=a-e+1;break}}else n.push(c)}if(!l)return null}const l={children:o,type:"htmlInline",value:r};return t.children.splice(e,i,l),l}const Ln=new Set(["blockquote","footnoteDefinition","htmlBlock","listItem","root"]);function An(t){const e=t.children,n=Ln.has(t.type);for(let r=0;r<e.length;r++){const o=e[r];if("html"===o.type){const e=n?Nn(t,r):In(t,r);if(null!==e){An(e);continue}}"children"in o&&An(o)}}const Fn=new Set(["code","pre","script","style","textarea","title"]),On=new Set(["a","abbr","b","bdi","bdo","cite","data","del","dfn","em","i","ins","kbd","mark","q","rp","rt","ruby","s","samp","small","span","strong","sub","sup","time","u","var"]);function Bn(t){if(delete t.position,"children"in t)for(const e of t.children)Bn(e);return t}const zn=/* @__PURE__ */t("isMarkdownExport",Boolean),_n=/* @__PURE__ */r("mdastHtmlChildBatches",()=>[]),Hn=new Set(["font-weight","font-style","text-decoration","vertical-align"]);function qn(t,e,n){if(S(t)){if(0!==e&&t.setFormat(t.getFormat()|e),""!==n){const e=t.getStyle();t.setStyle(""===e?n:n+e)}}else if(b(t))for(const r of t.getChildren())qn(r,e,n)}const Dn={$import:(t,e)=>{const n=t.get(_n)[Number(e.getAttribute("data-mdast-child"))];if(!n)return[];const r=t.get(d),o=t.get(u),i={};for(const t in o)Hn.has(t)||(i[t]=o[t]);const s=h(i);if(0!==r||""!==s)for(const t of n)qn(t,r,s);return[...n]},match:/* @__PURE__ */c.tag("template","span").attr("data-mdast-child",!0),name:"@lexical/mdast/html-child-placeholder"},Pn={transforms:[t=>{An(t)}]};function Zn(t){const e=[];for(const n of t)b(n)&&!n.isInline()?e.push(...Zn(n.getChildren())):e.push(n);return e}const Un=/* @__PURE__ */r("mdastHtmlInlineResult",()=>({nodes:null})),jn={$import:(t,e)=>(t.get(Un).nodes=t.$importChildren(e),[]),match:/* @__PURE__ */c.tag("span").attr("data-mdast-inline-root",!0),name:"@lexical/mdast/html-inline-root"};function Gn(...t){let e="";const n=[],r=()=>`<template data-mdast-child="${n.length}"></template>`;for(const o of t)if("string"==typeof o)e+=o;else if(Array.isArray(o))e+=r(),n.push({children:o,type:"paragraph"});else{let t=!0;for(const i of o.flow)t||(e+="\n\n"),t=!1,e+=r(),n.push(i)}return{children:n,type:"htmlBlock",value:e}}const Kn="data-mdast-part";function Qn(){return new RegExp(`<template ${Kn}="(\\d+)"></template>`)}const Wn=/* @__PURE__ */Qn();function Xn(t){return new Set(t.split(" "))}const Jn=/* @__PURE__ */Xn("address article aside base basefont blockquote body caption center col colgroup dd details dialog dir div dl dt fieldset figcaption figure footer form frame frameset h1 h2 h3 h4 h5 h6 head header hr html iframe legend li link main menu menuitem nav noframes ol optgroup option p param search section summary table tbody td tfoot th thead title tr track ul");function Vn(t){return t.replace(/^(<\/?([a-zA-Z][a-zA-Z0-9-]*)[^>]*>)(?=<)/,(t,e,n)=>Jn.has(n.toLowerCase())?t:`${e}\n`)}function Yn(t){return t.replace(/(>)(<\/([a-zA-Z][a-zA-Z0-9-]*)>)$/,(t,e,n,r)=>Jn.has(r.toLowerCase())?t:`${e}\n${n}`)}function tr(t){const e=/^<\/?([a-zA-Z][a-zA-Z0-9-]*)/.exec(t);return null!==e&&!Jn.has(e[1].toLowerCase())}const er=(t,r)=>{const o=J(),i=[],s=[],c=t=>{const e=et().createElement("template");return e.setAttribute(Kn,String(i.length)),i.push(t),e},d=e([n(l,!0),n(zn,!0)],o)(()=>{const e=a(o).$exportDOM(t,o);let n=e.element;if(!n)return null;const i=Array.from(e.$getChildNodes?e.$getChildNodes():b(t)?t.getChildren():[]);if(i.length>0){const t=i.some(t=>(b(t)||M(t))&&!t.isInline()),o=c(t?"flow":"phrasing");s.push(t?{flow:r.exportChildren(i)}:r.exportInline(i)),e.append?e.append(o):V(n)&&n.append(o)}return e.after&&(n=e.after.call(t,n)??n),n});if(!d)return null;if(V(d)||Y(d))for(const e of Array.from(d.querySelectorAll("[data-lexical-slot]"))){if(!d.contains(e))continue;const n=e.getAttribute("data-lexical-slot"),o=null===n?null:tt(t,n);if(null===o)continue;e.removeAttribute("data-lexical-slot");const i=b(o)&&o.isShadowRoot(),l=c(i?"flow":"phrasing");s.push(i?{flow:r.exportChildren(o)}:r.exportInline(o)),e.replaceChildren(l)}let u;if(V(d))u=d.outerHTML;else{const t=et().createElement("div");t.append(d),u=t.innerHTML}u=u.replace(/ ([a-zA-Z-]+)=""/g," $1");const p=u.split(Wn),m=[];let h=!0,f=!1;for(let t=0;t<p.length;t++){if(t%2==0){let e=p[t];h&&(e=Vn(e)),t===p.length-1&&(e=Yn(e)),f&&(m.push(tr(e)?"\n\n":"\n"),f=!1),m.push(e);continue}const e=Number(p[t]),n="flow"===i[e];h=n,n?(m.push("\n\n",s[e]),f=!0):m.push("\n",s[e],"\n")}return Gn(...m)},nr=/<template data-mdast-child="(\d+)"><\/template>/,rr={dependencies:[i,[s,{rules:[Dn,jn]}],[Ve,{importRules:[{$import:(t,e)=>{const r=t.children.map(t=>e.importNode(t)),{registry:o}=wt(Ve),i=o.mdastExtensions.filter(t=>t!==Pn),s=function(t){const n=t.replace(bn,""),s=[];let l="",a=0;const c=t=>{if(s.some(t=>Fn.has(t))||s.length>0&&On.has(s[s.length-1])||""===t.trim())return void(l+=t);const[,n,a,c]=/^(\s*)([\s\S]*?)(\s*)$/.exec(t);l+=n+(t=>{const n=Bn(Dt(t,{extensions:o.micromarkExtensions,mdastExtensions:i})),s=r.length,l=n.children[0];return r.push(1===n.children.length&&"paragraph"===l.type?e.importChildren(l):n.children.flatMap(t=>e.importNode(t))),`<span data-mdast-child="${s}">&#8203;</span>`})(a)+c};for(const t of n.matchAll(Mn)){c(n.slice(a,t.index)),l+=t[0],a=t.index+t[0].length;const[,e,r,,o]=t,i=r.toLowerCase();if(!Tn.has(i)&&!o)if(e){const t=s.lastIndexOf(i);-1!==t&&(s.length=t)}else s.push(i)}return c(n.slice(a)),l}(t.value),l=(new DOMParser).parseFromString(s,"text/html");return p(l,{context:[n(_n,r)]})},type:"htmlBlock"},{$import:(t,e)=>{const r=t.children.map(t=>e.importNode(t)),o={nodes:null},i=(new DOMParser).parseFromString(`<span data-mdast-inline-root="true">${t.value}</span>`,"text/html");return p(i,{context:[n(_n,r),n(Un,o)]}),null===o.nodes?[]:Zn(o.nodes)},type:"htmlInline"}],mdastExtensions:[Pn],toMarkdownExtensions:[{handlers:{htmlBlock:(t,e,n,r)=>{const o=n.createTracker(r),i=t.value.split(nr);let s="";for(let e=0;e<i.length;e++){if(e%2==0){""!==i[e]&&(s+=o.move(i[e]));continue}const r=t.children[Number(i[e])];void 0!==r&&(s+=o.move(n.handle(r,t,n,{...o.current(),after:(i[e+1]||"\n")[0],before:""===s?"\n":s[s.length-1]})))}return s}}}]}]],name:"@lexical/mdast/Html"};export{hn as $convertFromMarkdownString,fn as $convertFromMdast,$n as $convertSelectionToMarkdownString,kn as $convertToMarkdownString,Cn as $convertToMdast,er as $exportViaDOM,gn as $generateNodesFromMarkdownString,xn as $generateNodesFromMdast,_e as ImportContextMarkdown,an as MdastAutolinkLiteralExtension,en as MdastBlockquoteExtension,sn as MdastCodeExtension,pn as MdastCommonMarkExtension,yn as MdastExportExtension,Ve as MdastExtension,wn as MdastGfmExtension,tn as MdastHeadingExtension,dn as MdastHorizontalRuleExtension,rr as MdastHtmlExtension,Ye as MdastImportExtension,ln as MdastLinkExtension,rn as MdastListExtension,nn as MdastRichTextExtension,cn as MdastShadowRootQuoteExtension,mn as MdastShortcutsExtension,un as MdastStrikethroughExtension,Sn as MdastTableExtension,on as MdastTaskListExtension,zn as RenderContextMarkdownExport,Be as RenderContextMarkdownSelection,Gn as rawHtmlBlock};
9
+ import{createRenderState as t,$withRenderContext as e,contextValue as n,createImportState as r,$withImportContext as o,CoreImportExtension as i,DOMImportExtension as s,RenderContextExport as l,$getSessionDOMRenderConfig as a,sel as c,ImportTextFormat as u,ImportTextStyle as d,$generateNodesFromDOMViaExtension as p}from"@lexical/html";import{$sliceSelectedTextNodeContent as m,getCSSFromStyleObject as f}from"@lexical/selection";import{createState as h,$createParagraphNode as g,$setState as x,$createTextNode as y,IS_STRIKETHROUGH as k,$createLineBreakNode as C,$isParagraphNode as $,$getState as v,$isTextNode as S,$isLineBreakNode as w,IS_CODE as T,$isElementNode as b,$isDecoratorNode as M,IS_BOLD as E,IS_ITALIC as R,$getRoot as N,$isRangeSelection as I,$getSelection as L,iterStaticNodeConfigChain as A,getStaticNodeConfig as F,tokenizeRawText as O,$createTabNode as B,mergeRegister as z,COLLABORATION_TAG as _,HISTORIC_TAG as H,COMPOSITION_END_TAG as q,$getNodeByKey as D,$addUpdateTag as P,HISTORY_PUSH_TAG as Z,KEY_ENTER_COMMAND as U,COMMAND_PRIORITY_BEFORE_EDITOR as j,$isRootOrShadowRoot as G,ParagraphNode as K,TextNode as Q,LineBreakNode as W,shallowMergeConfig as X,$getEditor as J,isHTMLElement as V,isDocumentFragment as Y,$getSlot as tt,$getDocument as et}from"lexical";import{toMarkdown as nt,defaultHandlers as rt}from"mdast-util-to-markdown";import{toString as ot}from"mdast-util-to-string";import{$createCodeNode as it,$isCodeNode as st,CodeNode as lt}from"@lexical/code-core";import{$createLinkNode as at,$isLinkNode as ct,$isAutoLinkNode as ut,LinkNode as dt}from"@lexical/link";import{$createListNode as pt,$createListItemNode as mt,$isListNode as ft,$isListItemNode as ht,ListNode as gt,ListItemNode as xt}from"@lexical/list";import{$createHeadingNode as yt,$createQuoteNode as kt,$isHeadingNode as Ct,$isQuoteNode as $t,QuoteNode as vt,HeadingNode as St}from"@lexical/rich-text";import{$getExtensionOutput as wt}from"@lexical/extension/getExtensionDependency";import{HorizontalRuleExtension as Tt,HorizontalRuleNode as bt,$createHorizontalRuleNode as Mt,$isHorizontalRuleNode as Et}from"@lexical/extension/HorizontalRuleExtension";import{effect as Rt}from"@lexical/extension/signals";import{getExtensionDependencyFromEditor as Nt}from"@lexical/extension/getExtensionDependencyFromEditor";import{namedSignals as It}from"@lexical/extension/namedSignals";import{gfmAutolinkLiteralToMarkdown as Lt,gfmAutolinkLiteralFromMarkdown as At}from"mdast-util-gfm-autolink-literal";import{gfmStrikethroughToMarkdown as Ft,gfmStrikethroughFromMarkdown as Ot}from"mdast-util-gfm-strikethrough";import{gfmTaskListItemToMarkdown as Bt,gfmTaskListItemFromMarkdown as zt}from"mdast-util-gfm-task-list-item";import{gfmAutolinkLiteral as _t}from"micromark-extension-gfm-autolink-literal";import{gfmStrikethrough as Ht}from"micromark-extension-gfm-strikethrough";import{gfmTaskListItem as qt}from"micromark-extension-gfm-task-list-item";import{fromMarkdown as Dt}from"mdast-util-from-markdown";import{TableNode as Pt,TableRowNode as Zt,TableCellNode as Ut,$createTableNode as jt,$createTableRowNode as Gt,$createTableCellNode as Kt,TableCellHeaderStates as Qt,$isTableNode as Wt,$isTableRowNode as Xt,$isTableCellNode as Jt}from"@lexical/table";import{gfmTableToMarkdown as Vt,gfmTableFromMarkdown as Yt}from"mdast-util-gfm-table";import{gfmTable as te}from"micromark-extension-gfm-table";const ee=/* @__PURE__ */h("mdastListMarker",{parse:t=>"-"===t||"*"===t||"+"===t?t:"",resetOnCopyNode:!0}),ne=/* @__PURE__ */h("mdastOrderedMarker",{parse:t=>"."===t||")"===t?t:"",resetOnCopyNode:!0}),re=/* @__PURE__ */h("mdastEmphasisMarker",{parse:t=>"_"===t?"_":"",resetOnCopyNode:!0}),oe=/* @__PURE__ */h("mdastStrongMarker",{parse:t=>"_"===t?"_":"",resetOnCopyNode:!0}),ie=/* @__PURE__ */h("mdastSetext",{parse:t=>!0===t,resetOnCopyNode:!0}),se=/* @__PURE__ */h("mdastCodeFence",{parse:t=>"string"==typeof t&&/^(`{3,}|~{3,})$/.test(t)?t:"",resetOnCopyNode:!0}),le=/* @__PURE__ */h("mdastCodeMeta",{parse:t=>"string"==typeof t?t:"",resetOnCopyNode:!0}),ae=/* @__PURE__ */h("mdastHardLineBreak",{parse:t=>"string"==typeof t&&/^(\\| {2,})$/.test(t)?t:"",resetOnCopyNode:!0}),ce=/* @__PURE__ */h("mdastParagraphBreak",{parse:t=>!0===t,resetOnCopyNode:!0}),ue=/* @__PURE__ */h("mdastHrMarker",{parse:t=>"-"===t||"*"===t||"_"===t?t:"",resetOnCopyNode:!0}),de=/* @__PURE__ */h("mdastLinkStyle",{parse:t=>"inline"===t||"autolink"===t||"literal"===t?t:"",resetOnCopyNode:!0});function pe(t,e){return t.splice(t.getChildrenSize(),0,e)}function me(t){return(b(t)||M(t))&&!t.isInline()}function fe(){return x(C(),ce,!0)}const he=E,ge=R,xe=k,ye=T;function ke(){return he|ge|xe|ye}const Ce=/* @__PURE__ */ke();function $e(t){if(t.ordered)return"number";for(const e of t.children)if("listItem"===e.type&&null!=e.checked)return"check";return"bullet"}function ve(t,e){return(n,r)=>{const o=r.importChildren(n,t);if("_"===function(t,e){if(t.source&&e.position&&null!=e.position.start.offset)return t.source[e.position.start.offset]}(r,n))for(const t of o)S(t)&&x(t,e,"_");return o}}const Se=/* @__PURE__ */ve(ge,re),we=/* @__PURE__ */ve(he,oe),Te={h1:1,h2:2,h3:3,h4:4,h5:5,h6:6};function be(t,e){const n=t.getListType(),r={children:[],ordered:"number"===n,spread:!1,start:"number"===n?t.getStart():void 0,type:"list"};if("number"===n){const e=v(t,ne);e&&(r.data={mdastBulletOrdered:e})}else{const e=v(t,ee);e&&(r.data={mdastBullet:e})}let o=null;for(const i of t.getChildren()){if(!ht(i)||!e.isIncluded(i))continue;const t=i.getFirstChild();if(1===i.getChildrenSize()&&ft(t)){const n=be(t,e);o?o.children.push(n):r.children.push({children:[n],spread:!1,type:"listItem"});continue}const s={checked:"check"===n?i.getChecked()??!1:null,children:e.exportBlocks(i),spread:!1,type:"listItem"};r.children.push(s),o=s}return r}const Me=[[he,"strong"],[ge,"emphasis"]];function Ee(t){const e=[];for(let n=0;n<t.length;){const{format:r,value:o}=t[n];let i=null,s=0,l=n+1;for(const[e,o]of Me){if(0===(r&e))continue;let a=n+1;for(;a<t.length&&t[a].format&e;)a++;(null===i||a>l)&&(i=o,s=e,l=a)}null===i?(e.push(r&ye?{type:"inlineCode",value:o}:{type:"text",value:o}),n++):(e.push({children:Ee(t.slice(n,l).map(t=>({format:t.format&~s,value:t.value}))),type:i}),n=l)}return e}const Re=t=>S(t)?function(t,e){let n=e&ye?{type:"inlineCode",value:t}:{type:"text",value:t};return e&ge&&(n={children:[n],type:"emphasis"}),e&he&&(n={children:[n],type:"strong"}),e&xe&&(n={children:[n],type:"delete"}),n}(t.getTextContent(),t.getFormat()&Ce):null,Ne=t=>w(t)?{data:{mdastBreak:v(t,ae)},type:"break"}:null;function Ie(t,e,n){const{options:r}=t,o={};for(const t of Object.keys(e))o[t]=r[t],r[t]=e[t];try{return n()}finally{for(const t of Object.keys(o))r[t]=o[t]}}const Le={handlers:{break(t,e,n,r){const o=rt.break(t,e,n,r);if("\\\n"!==o)return o;const i=t.data&&t.data.mdastBreak;return i?/^ {2,}$/.test(i)?`${i}\n`:o:"\n"},code(t,e,n,r){const o=t.data&&t.data.mdastFence;return o?Ie(n,{fence:"~"===o[0]?"~":"`",fences:!0},()=>rt.code(t,e,n,r)):rt.code(t,e,n,r)},heading:(t,e,n,r)=>t.data&&!0===t.data.mdastSetext?Ie(n,{setext:!0},()=>rt.heading(t,e,n,r)):rt.heading(t,e,n,r),link(t,e,n,r){const o=t.data&&t.data.mdastLinkStyle;return"literal"===o&&null==t.title?ot(t):"inline"===o?Ie(n,{resourceLink:!0},()=>rt.link(t,e,n,r)):rt.link(t,e,n,r)},list(t,e,n,r){if(t.ordered){const o=t.data&&t.data.mdastBulletOrdered;return null==o?rt.list(t,e,n,r):Ie(n,{bulletOrdered:o},()=>rt.list(t,e,n,r))}const o=t.data&&t.data.mdastBullet;return null==o?rt.list(t,e,n,r):Ie(n,{bullet:o,bulletOther:"-"===o?"*":"-"},()=>rt.list(t,e,n,r))},thematicBreak(t,e,n){const r=t.data&&t.data.mdastRule;return"-"!==r&&"*"!==r&&"_"!==r?rt.thematicBreak(t,e,n):Ie(n,{rule:r},()=>rt.thematicBreak(t,e,n))}}};function Ae(t,e,n){if(Object.keys(t).some(t=>"type"!==t&&"value"!==t&&"children"!==t))return!1;if("text"===t.type||"inlineCode"===t.type)return n.push({format:e|("inlineCode"===t.type?T:0),value:t.value}),!0;const r="strong"===t.type?E:"emphasis"===t.type?R:"delete"===t.type?k:0;return 0!==r&&"children"in t&&t.children.every(t=>Ae(t,e|r,n))}class Fe{runs=[];push(t){return!!S(t)&&(this.pushRun(t.getTextContent(),t.getFormat()&Ce),!0)}pushRun(t,e){const n=this.runs[this.runs.length-1];void 0!==n&&n.format===e?n.value+=t:this.runs.push({format:e,value:t})}appendExported(t,e){const n=[];if(t.every(t=>Ae(t,0,n)))for(const t of n)this.pushRun(t.value,t.format);else this.flushInto(e),e.push(...t)}flushInto(t){this.runs.length>0&&(t.push(...function(t){const e=[];for(let n=0;n<t.length;){const r=0!==(t[n].format&xe);let o=n+1;for(;o<t.length&&0!==(t[o].format&xe)===r;)o++;const i=t.slice(n,o);r?e.push({children:Ee(i.map(t=>({format:t.format&~xe,value:t.value}))),type:"delete"}):e.push(...Ee(i)),n=o}return e}(this.runs)),this.runs=[])}}function Oe(t,e=null){const{exportHandlers:n}=t;let r=0;function o(t){const e=n.get(t.getType()),r=e&&e[0];return void 0===r||r===Re}function i(t){return null===e||b(t)?t:t.isSelected(e)?(r++,S(t)?m(e,t,"clone"):t):null}function s(t,n){const o=null!==e&&t.isSelected(e);o&&r++;const i=r,s=c(t);(null===e||o||r>i)&&n.push(...s)}function l(t){return Array.isArray(t)?t:t.getChildren()}const a={exportBlocks:t=>function(t){const e=[];let n=[];const r=new Fe,a=()=>{r.flushInto(n),n.length>0&&(e.push({children:n,type:"paragraph"}),n=[])};for(const u of l(t)){const t=i(u);if(null!==t)if(w(t)){const e=Ne(t);v(t,ce)||null===e?a():(r.flushInto(n),n.push(e))}else{if(o(t)&&r.push(t))continue;S(t)?r.appendExported(c(t),n):me(t)?(a(),b(t)?s(t,e):e.push(...c(t))):b(t)?(r.flushInto(n),s(t,n)):(r.flushInto(n),n.push(...c(t)))}}return a(),0===e.length&&e.push({children:[],type:"paragraph"}),e}(t),exportChildren:t=>{const e=[];for(const n of l(t)){const t=i(n);null!==t&&(b(t)?s(t,e):e.push(...c(t)))}return e},exportInline:t=>function(t){const e=[],n=new Fe;for(const r of l(t)){const t=i(r);if(!(null===t||o(t)&&n.push(t))){if(S(t)){n.appendExported(c(t),e);continue}n.flushInto(e),b(t)?s(t,e):e.push(...c(t))}}return n.flushInto(e),e}(t),isIncluded:function t(n){if(null===e||n.isSelected(e))return!0;if(b(n))for(const e of n.getChildren())if(t(e))return!0;return!1}};function c(t,e=n.get(t.getType()),r=0){const o=e&&e[r];if(o){const n=o(t,{...a,next:()=>c(t,e,r+1)});if(null!=n)return Array.isArray(n)?n:[n]}const i=Re(t);if(null!==i)return[i];const s=Ne(t);if(null!==s)return[s];if(b(t))return a.exportChildren(t);const l=t.getTextContent();return l?[{type:"text",value:l}]:[]}return{exportChildren:a.exportChildren}}const Be=/* @__PURE__ */t("markdownSelection",()=>null);function ze(t){if("string"==typeof t)return t;const{ownNodeType:e,ownNodeConfig:n,declaresOwnConfig:r}=F(t);return(void 0===e||!r&&void 0!==n)&&function(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)}(441),e}const _e=/* @__PURE__ */r("isMarkdownImport",Boolean);function He(t,e){const n=[];return O(t,{linebreak:()=>n.push(C()),tab:()=>n.push(B().setFormat(e)),text:t=>{const r=y(t);e&&r.setFormat(e),n.push(r)}}),n}const qe=new Map;function De(t,e="",r=qe){const{importHandlers:i}=t,s=new Map;function l(t){let n=s.get(t);return void 0===n&&(n={createText:(e,n)=>He(e,n??t),format:t,getDefinition:t=>r.get(t),importChildren:(e,n)=>c(e,t|(n||0)),importNode:(e,n)=>a(e,t|(n||0)),source:e},s.set(t,n)),n}function a(t,e,n=i.get(t.type),r=0){const o=n&&n[r];if(o){const i=o(t,{...l(e),next:()=>a(t,e,n,r+1)});return null==i?[]:Array.isArray(i)?i:[i]}return"children"in t?c(t,e):"value"in t&&"string"==typeof t.value?He(t.value,e):[]}function c(t,e){const n=[];for(const r of t.children)n.push(...a(r,e));return n}const u=t=>o([n(_e,!0)])(t);return{$importChildren:(t,e)=>u(()=>c(t,e)),$importNode:(t,e)=>u(()=>a(t,e))}}function Pe(t,e){let n=t;for(;;){if("heading"===n.type||"paragraph"===n.type){const t=n.children[0];return t&&t.position&&null!=t.position.start.offset?t.position.start.offset:e.length}if(!("children"in n)||0===n.children.length)return e.length;n=n.children[0]}}class Ze{compiled;importNode;supportsTaskListItems;constructor(t){this.compiled=t,this.importNode=De(t,"").$importNode;const e=this.parse("- [x] a").children[0];this.supportsTaskListItems=null!=e&&"list"===e.type&&!0===e.children[0].checked}get inlineTriggers(){return this.compiled.inlineShortcutTriggers}parse(t){return Dt(t,{extensions:this.compiled.micromarkExtensions,mdastExtensions:this.compiled.mdastExtensions})}importInline(t){return this.importNode(t,0)}scanBlock(t){if(""===t.trim())return null;const e=this.parse(t).children[0];if(!e||!this.compiled.importHandlers.has(e.type))return null;switch(e.type){case"heading":return{kind:"heading",markerLength:Pe(e,t),node:e};case"blockquote":return{kind:"blockquote",markerLength:Pe(e,t),node:e};case"list":return{kind:"list",markerLength:Pe(e,t),node:e};case"code":return{kind:"code",markerLength:t.length,node:e};default:return null}}scanInline(t){if(0===t.length)return null;const e=this.parse(t),n=e.children[e.children.length-1];if(!n||"paragraph"!==n.type)return null;const r=n.children[n.children.length-1];if(!r||!r.position||r.position.end.offset!==t.length||!this.compiled.inlineShortcutTypes.has(r.type))return null;const o=r.position.start.offset??0,i=t[o];return o>0&&t[o-1]===i&&this.compiled.inlineShortcutTriggers.has(i)?null:r}}function Ue(t,e){let n=e,r=t.getFirstChild();for(;n>0&&r&&S(r);){const t=r.getTextContent();if(t.length<=n){const e=r.getNextSibling();n-=t.length,r.remove(),r=e}else r.setTextContent(t.slice(n)),n=0}}function je(t,e){$t(t)?t.setIsShadowRoot(!0).append(e):t.replace(e)}function Ge(t,e){const n="code"===e.kind?t.getTextContent().match(/^[ \t]*(`{3,}|~{3,})/):null;Ue(t,e.markerLength);const r=t.getChildren();if("code"===e.kind){const o=it(e.node.lang||void 0);return n&&x(o,se,n[1]),e.node.meta&&x(o,le,e.node.meta),pe(o,r),je(t,o),o.selectStart(),!0}let o,i;if("heading"===e.kind){const t=pe(yt(`h${e.node.depth}`),r);o=t,i=t}else if("blockquote"===e.kind){const t=pe(kt(),r);o=t,i=t}else{const t=e.node,n=$e(t),s=t.ordered&&null!=t.start?t.start:1,l=pt(n,s),a=t.children[0],c=a&&"listItem"===a.type&&"boolean"==typeof a.checked?a.checked:void 0,u=pe(mt(c),r);pe(l,[u]),o=l,i=u}return je(t,o),i.selectStart(),!0}const Ke=/^\[([ xX])\]\s$/;function Qe(t,e){return $(t)&&G(t.getParent())&&t.getFirstChild()===e}function We(t,e){return Qe(t,e)||function(t,e){return $t(t)&&!t.isShadowRoot()&&G(t.getParent())&&t.getFirstChild()===e}(t,e)}const Xe=[{$import:(t,e)=>pe(g(),e.importChildren(t)),type:"paragraph"},{$import:(t,e)=>e.createText(t.value),type:"text"},{$import:(t,e)=>e.createText(t.value),type:"html"},{$import:(t,e)=>e.createText(t.value,e.format|ye),type:"inlineCode"},{$import:Se,type:"emphasis"},{$import:we,type:"strong"},{$import:(t,e)=>{let n="\\";if(e.source&&t.position){const{start:r,end:o}=t.position;if(null!=r.offset&&null!=o.offset){const t=e.source.slice(r.offset,o.offset).replace(/\n$/,"");/^ {2,}$/.test(t)&&(n=t)}}return[x(C(),ae,n)]},type:"break"}],Je=[{$export:(t,e)=>$(t)?{children:e.exportInline(t),type:"paragraph"}:null,type:K},{$export:Re,type:Q},{$export:Ne,type:W}],Ve={build(t,r){const o=function(t,e){const n=new Map;for(const t of e.importRules){const e=n.get(t.type);e?e.push(t.$import):n.set(t.type,[t.$import])}const r=new Map;for(const t of e.exportRules){const e=ze(t.type),n=r.get(e);n?n.push(t.$export):r.set(e,[t.$export])}const o=new Map(r);for(const[e,{klass:n}]of t._nodes){const t=[],i=new Set;for(const{ownNodeType:e}of A(n))void 0===e||i.has(e)||(i.add(e),t.push(...r.get(e)||[]));t.length>0&&o.set(e,t)}return{exportHandlers:o,importHandlers:n,inlineShortcutTriggers:new Set(e.inlineShortcutTriggers),inlineShortcutTypes:new Set(e.inlineShortcutTypes),mdastExtensions:[...e.mdastExtensions],micromarkExtensions:[...e.micromarkExtensions],toMarkdownExtensions:[...e.toMarkdownExtensions]}}(t,r),{$exportSelectionToMarkdown:i,$exportToMdast:s,$exportToMarkdown:l}=function(t){const r=Oe(t),o=(t,e)=>({children:e.exportChildren(t),type:"root"}),i=(e,n)=>{const{emphasis:r,strong:o}=function(t){let e,n;const r=t=>{for(const o of t.getChildren())if(S(o)?(void 0===e&&o.hasFormat("italic")&&"_"===v(o,re)&&(e="_"),void 0===n&&o.hasFormat("bold")&&"_"===v(o,oe)&&(n="_")):b(o)&&r(o),void 0!==e&&void 0!==n)return};return r(t),{emphasis:e,strong:n}}(n),i={bullet:"-"};return r&&(i.emphasis=r),o&&(i.strong=o),nt(e,{extensions:[i,...t.toMarkdownExtensions,Le]}).replace(/\n$/,"")};return{$exportSelectionToMarkdown:(r=L())=>{if(null===r||I(r)&&r.isCollapsed())return"";const s=N();return e([n(Be,r)])(()=>i(o(s,Oe(t,r)),s))},$exportToMarkdown:t=>{const e=t||N();return i(o(e,r),e)},$exportToMdast:t=>o(t||N(),r)}}(o),{$generateNodesFromMarkdown:a,$generateNodesFromMdast:c,$importMarkdown:u,$importMdast:d}=function(t){const e=(e,n)=>{const{$importNode:r}=De(t,n,function(t){const e=new Map,n=t=>{if("definition"===t.type&&(e.has(t.identifier)||e.set(t.identifier,{title:t.title,url:t.url})),"children"in t)for(const e of t.children)n(e)};return n(t),e}(e)),o=[];let i=null;const s=()=>{i&&(o.push(i),i=null)};for(const t of e.children)for(const e of r(t,0))me(e)?(s(),o.push(e)):(i||(i=g()),pe(i,[e]));return s(),o},n=n=>e(Dt(n,{extensions:t.micromarkExtensions,mdastExtensions:t.mdastExtensions}),n),r=t=>e(t,""),o=(t,e)=>{const n=e||N();var r,o;n.clear(),r=n,o=t.length>0?t:[g()],r.splice(0,0,o),null!==L()&&n.selectStart()};return{$generateNodesFromMarkdown:n,$generateNodesFromMdast:r,$importMarkdown:(t,e)=>o(n(t),e),$importMdast:(t,e)=>o(r(t),e)}}(o);return{$convertFromMarkdownString:u,$convertFromMdast:d,$convertSelectionToMarkdownString:i,$convertToMarkdownString:l,$convertToMdast:s,$generateNodesFromMarkdownString:a,$generateNodesFromMdast:c,registry:o}},config:{exportRules:Je,importRules:Xe,inlineShortcutTriggers:["*","_","`"],inlineShortcutTypes:["emphasis","inlineCode","strong"],mdastExtensions:[],micromarkExtensions:[],toMarkdownExtensions:[]},mergeConfig(t,e){function n(t,e){return t?[...t,...e]:e}return X(t,{exportRules:n(e.exportRules,t.exportRules),importRules:n(e.importRules,t.importRules),inlineShortcutTriggers:n(e.inlineShortcutTriggers,t.inlineShortcutTriggers),inlineShortcutTypes:n(e.inlineShortcutTypes,t.inlineShortcutTypes),mdastExtensions:n(e.mdastExtensions,t.mdastExtensions),micromarkExtensions:n(e.micromarkExtensions,t.micromarkExtensions),toMarkdownExtensions:n(e.toMarkdownExtensions,t.toMarkdownExtensions)})},name:"@lexical/mdast/Mdast"},Ye=Ve,tn={dependencies:[[Ve,{exportRules:[{$export:(t,e)=>{if(!Ct(t))return null;const n={children:e.exportInline(t),depth:Te[t.getTag()],type:"heading"};return v(t,ie)&&(n.data={mdastSetext:!0}),n},type:St}],importRules:[{$import:(t,e)=>{const n=yt(`h${t.depth}`);if(e.source&&t.position&&(1===t.depth||2===t.depth)){const r=t.position.start.offset;null==r||/^ {0,3}#{1,6}([ \t\r\n]|$)/.test(e.source.slice(r,r+10))||x(n,ie,!0)}return pe(n,e.importChildren(t))},type:"heading"}]}]],name:"@lexical/mdast/Heading",nodes:[St]},en={dependencies:[[Ve,{exportRules:[{$export:(t,e)=>$t(t)?{children:t.isShadowRoot()?e.exportChildren(t):e.exportBlocks(t),type:"blockquote"}:null,type:vt}],importRules:[{$import:(t,e)=>{const n=kt(),r=[];for(const n of t.children)"paragraph"===n.type?(r.length>0&&r.push(fe()),r.push(...e.importChildren(n))):r.push(...e.importNode(n));return pe(n,r)},type:"blockquote"}]}]],name:"@lexical/mdast/Blockquote",nodes:[vt]},nn={dependencies:[tn,en],name:"@lexical/mdast/RichText"},rn={dependencies:[[Ve,{exportRules:[{$export:(t,e)=>ft(t)?be(t,e):null,type:gt}],importRules:[{$import:(t,e)=>{const n=$e(t),r=t.ordered&&null!=t.start?t.start:1,o=pt(n,r),i=t.children[0],s=e.source&&i&&i.position?i.position.start.offset:void 0;if(null!=s){const t=e.source.slice(s,s+16);if("number"===n){const e=t.match(/^\s*\d+([.)])/),n=e&&e[1];"."!==n&&")"!==n||x(o,ne,n)}else{const e=t.match(/^\s*([-*+])/),n=e&&e[1];"-"!==n&&"*"!==n&&"+"!==n||x(o,ee,n)}}return pe(o,t.children.flatMap(t=>e.importNode(t)))},type:"list"},{$import:(t,e)=>{const n=mt("boolean"==typeof t.checked?t.checked:void 0),r=[];for(const o of t.children)"list"===o.type?r.push(pe(mt(),e.importNode(o))):"paragraph"===o.type?(n.getChildrenSize()>0&&pe(n,[fe()]),pe(n,e.importChildren(o))):pe(n,e.importNode(o));return[n,...r]},type:"listItem"}]}]],name:"@lexical/mdast/List",nodes:[gt,xt]},on={dependencies:[rn,[Ve,{mdastExtensions:[/* @__PURE__ */zt()],micromarkExtensions:[/* @__PURE__ */qt()],toMarkdownExtensions:[/* @__PURE__ */Bt()]}]],name:"@lexical/mdast/TaskList"},sn={dependencies:[[Ve,{exportRules:[{$export:t=>{if(!st(t))return null;const e={lang:t.getLanguage()||null,type:"code",value:t.getTextContent()},n=v(t,le);n&&(e.meta=n);const r=v(t,se);return r&&(e.data={mdastFence:r}),e},type:lt}],importRules:[{$import:(t,e)=>{const n=it(t.lang||void 0);if(e.source&&t.position&&null!=t.position.start.offset){const r=t.position.start.offset,o=e.source.indexOf("\n",r),i=e.source.slice(r,-1===o?void 0:o).match(/^[ \t]*(`{3,}|~{3,})/);i&&x(n,se,i[1])}return t.meta&&x(n,le,t.meta),t.value&&pe(n,[y(t.value)]),n},type:"code"}]}]],name:"@lexical/mdast/Code",nodes:[lt]},ln={dependencies:[[Ve,{exportRules:[{$export:(t,e)=>{if(!ct(t)||ut(t))return null;const n={children:e.exportInline(t),title:t.getTitle()??null,type:"link",url:t.getURL()},r=v(t,de);return r&&(n.data={mdastLinkStyle:r}),n},type:dt}],importRules:[{$import:(t,e)=>{const n=pe(at(t.url,{title:null==t.title?void 0:t.title}),e.importChildren(t));if(e.source&&t.position&&null!=t.position.start.offset){const r=e.source[t.position.start.offset];x(n,de,"["===r?"inline":"<"===r?"autolink":"literal")}return n},type:"link"},{$import:(t,e)=>{const n=e.getDefinition(t.identifier);if(n)return pe(at(n.url,{title:null==n.title?void 0:n.title}),e.importChildren(t));const{position:r}=t;return e.source&&r&&null!=r.start.offset?e.createText(e.source.slice(r.start.offset,r.end.offset)):[...e.createText("["),...e.importChildren(t),...e.createText("]")]},type:"linkReference"},{$import:()=>[],type:"definition"}],inlineShortcutTriggers:[")"],inlineShortcutTypes:["link"]}]],name:"@lexical/mdast/Link",nodes:[dt]},an={dependencies:[ln,[Ve,{mdastExtensions:[/* @__PURE__ */At()],micromarkExtensions:[/* @__PURE__ */_t()],toMarkdownExtensions:[/* @__PURE__ */Lt()]}]],name:"@lexical/mdast/AutolinkLiteral"},cn={dependencies:[en,[Ve,{importRules:[{$import:(t,e)=>pe(kt({shadowRoot:!0}),function(t,e){const n=[];let r=null;const o=()=>{r&&(n.push(r),r=null)};for(const i of t.children)for(const t of e.importNode(i))me(t)?(o(),n.push(t)):(r||(r=g()),pe(r,[t]));return o(),n}(t,e)),type:"blockquote"}]}]],name:"@lexical/mdast/ShadowRootQuote"},un={dependencies:[Tt,[Ve,{exportRules:[{$export:t=>{if(!Et(t))return null;const e={type:"thematicBreak"},n=v(t,ue);return n&&(e.data={mdastRule:n}),e},type:bt}],importRules:[{$import:(t,e)=>{const n=Mt();if(e.source&&t.position&&null!=t.position.start.offset){const r=e.source.slice(t.position.start.offset,t.position.start.offset+4).trimStart()[0];"-"!==r&&"*"!==r&&"_"!==r||x(n,ue,r)}return n},type:"thematicBreak"}]}]],name:"@lexical/mdast/HorizontalRule"},dn={dependencies:[[Ve,{importRules:[{$import:(t,e)=>e.importChildren(t,xe),type:"delete"}],inlineShortcutTriggers:["~"],inlineShortcutTypes:["delete"],mdastExtensions:[/* @__PURE__ */Ot()],micromarkExtensions:[/* @__PURE__ */Ht()],toMarkdownExtensions:[/* @__PURE__ */Ft()]}]],name:"@lexical/mdast/Strikethrough"},pn={dependencies:[nn,rn,sn,ln,un],name:"@lexical/mdast/CommonMark"},mn={build:(t,e)=>It(e),config:{disabled:!1},dependencies:[Ve],name:"@lexical/mdast/Shortcuts",register:(t,e,n)=>{const{disabled:r}=n.getOutput();return Rt(()=>{if(r.value)return;const{registry:e}=Nt(t,Ve).output;return function(t,e){const n=new Ze(e),r=n.inlineTriggers,o=new Set([" ",...r]);return z(t.registerUpdateListener(({tags:e,dirtyLeaves:i,editorState:s,prevEditorState:l})=>{if(0===i.size||e.has(_)||e.has(H))return;if(t.isComposing())return;const a=e.has(q),c=s.read(L),u=l.read(L);if(!I(c)||!I(u)||!c.isCollapsed()||c.is(u)&&!a)return;const d=c.anchor.key,p=c.anchor.offset,m=s._nodeMap.get(d);if(!S(m)||!i.has(d))return;if(!a&&1!==p&&(u.anchor.key!==d||p!==u.anchor.offset+1))return;const f=s.read(()=>m.getTextContent()),h=f[p-1];var g,x;a&&!o.has(h)||(" "===h||r.has(h))&&(" "===h||(g=f.slice(0,p),")"===(x=h)?g.lastIndexOf("](")>0:-1!==g.lastIndexOf(x,g.length-2)))&&t.update(()=>{const t=D(d);if(!S(t)||t.hasFormat("code"))return;const e=t.getParent();if(null===e||st(e))return;let r=!1;if(" "===h){if(n.supportsTaskListItems&&function(t,e,n){if(e.getFirstChild()!==t)return!1;const r=e.getTextContent().slice(0,n).match(Ke);if(!r)return!1;const o="x"===r[1].toLowerCase();if(ht(e)){const t=e.getParent();return!(!ft(t)||"number"===t.getListType()||(Ue(e,r[0].length),t.setListType("check"),e.setChecked(o),0))}if(Qe(e,t)){Ue(e,r[0].length);const t=e.getChildren(),n=pt("check"),i=pe(mt(o),t);return pe(n,[i]),e.replace(n),i.selectStart(),!0}return!1}(t,e,p))r=!0;else if(p<=24&&We(e,t)){const o=n.scanBlock(t.getTextContent().slice(0,p));o&&"code"!==o.kind&&o.markerLength===p&&(r=Ge(e,o))}}else r=function(t,e,n){const r=t.getTextContent().slice(0,e),o=n.scanInline(r);if(!o||!o.position)return!1;const i=o.position.start.offset??0,s=e;let l;if(i<=0)[l]=t.splitText(s);else{const e=t.splitText(i,s);l=3===e.length?e[1]:e[e.length-1]}const a=n.importInline(o);if(0===a.length)return!1;let c=a[0];l.replace(c);for(let t=1;t<a.length;t++)c.insertAfter(a[t]),c=a[t];if(S(c)){const t=c.getTextContentSize();c.select(t,t)}else c.selectNext(0,0);return!0}(t,p,n);r&&P(Z)})}),t.registerCommand(U,t=>{if(null!==t&&t.shiftKey)return!1;const e=L();if(!I(e)||!e.isCollapsed())return!1;const r=e.anchor.getNode();if(!S(r)||r.hasFormat("code"))return!1;const o=r.getParent(),i=e.anchor.offset;if(null===o||st(o)||!We(o,r)||i!==r.getTextContentSize())return!1;const s=n.scanBlock(o.getTextContent());return!(!s||s.markerLength!==i||!Ge(o,s)||(null!==t&&t.preventDefault(),0))},j))}(t,e)})}};function fn(t,e){wt(Ve).$convertFromMarkdownString(t,e)}function hn(t,e){wt(Ve).$convertFromMdast(t,e)}function gn(t){return wt(Ve).$generateNodesFromMarkdownString(t)}function xn(t){return wt(Ve).$generateNodesFromMdast(t)}const yn=Ve;function kn(t){return wt(Ve).$convertToMarkdownString(t)}function Cn(t){return wt(Ve).$convertToMdast(t)}function $n(t){return wt(Ve).$convertSelectionToMarkdownString(t)}const vn=/* @__PURE__ */h("mdastTableAlign",{parse:t=>Array.isArray(t)?t.map(t=>"center"===t||"left"===t||"right"===t?t:null):[],resetOnCopyNode:!0}),Sn={dependencies:[[Ve,{exportRules:[{$export:(t,e)=>{if(!Wt(t))return null;const n=[];for(const r of t.getChildren()){if(!Xt(r)||!e.isIncluded(r))continue;const t=[];for(const n of r.getChildren()){if(!Jt(n))continue;const r=[];for(const t of n.getChildren())b(t)&&(r.length>0&&r.push({type:"break"}),r.push(...e.exportInline(t)));t.push({children:r,type:"tableCell"})}n.push({children:t,type:"tableRow"})}return{align:v(t,vn),children:n,type:"table"}},type:Pt}],importRules:[{$import:(t,e)=>{const n=jt();return t.align&&t.align.some(t=>null!=t)&&x(n,vn,t.align),t.children.forEach((t,r)=>{const o=Gt();for(const n of t.children){const t=Kt(0===r?Qt.ROW:Qt.NO_STATUS),i=g();pe(i,e.importChildren(n)),pe(t,[i]),pe(o,[t])}pe(n,[o])}),n},type:"table"}],mdastExtensions:[/* @__PURE__ */Yt()],micromarkExtensions:[/* @__PURE__ */te()],toMarkdownExtensions:[/* @__PURE__ */Vt()]}]],name:"@lexical/mdast/Table",nodes:[Pt,Zt,Ut]},wn={dependencies:[dn,on,an,Sn],name:"@lexical/mdast/Gfm"},Tn=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),bn=/<!--[\s\S]*?-->/g,Mn=/<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:[^"'>]|"[^"]*"|'[^']*')*?)(\/?)>/g;function En(t){let e=0;for(const n of t.replace(bn,"").matchAll(Mn)){const[,t,r,,o]=n;Tn.has(r.toLowerCase())||(t?e-=1:o||(e+=1))}return e}function Rn(t){const e=t.replace(bn,"");return!e.matchAll(Mn).next().done||""===e.trim()}function Nn(t,e){const n=t.children[e];if("html"!==n.type||!Rn(n.value))return null;let r=n.value;const o=[];let i=1,s=En(n.value);if(s>0){let n=[],l=!1;for(let a=e+1;a<t.children.length;a++){const c=t.children[a];if("html"===c.type){for(const t of n)r+=`<template data-mdast-child="${o.length}"></template>`,o.push(t);if(n=[],r+="\n"+c.value,s+=En(c.value),s<=0){l=!0,i=a-e+1;break}}else n.push(c)}if(!l)return null}const l={children:o,type:"htmlBlock",value:r};return t.children.splice(e,i,l),l}function In(t,e){const n=t.children[e];if("html"!==n.type||!Rn(n.value))return null;let r=n.value;const o=[];let i=1,s=En(n.value);if(s>0){let n=[],l=!1;for(let a=e+1;a<t.children.length;a++){const c=t.children[a];if("html"===c.type){for(const t of n)r+=`<span data-mdast-child="${o.length}">&#8203;</span>`,o.push(t);if(n=[],r+=c.value,s+=En(c.value),s<=0){l=!0,i=a-e+1;break}}else n.push(c)}if(!l)return null}const l={children:o,type:"htmlInline",value:r};return t.children.splice(e,i,l),l}const Ln=new Set(["blockquote","footnoteDefinition","htmlBlock","listItem","root"]);function An(t){const e=t.children,n=Ln.has(t.type);for(let r=0;r<e.length;r++){const o=e[r];if("html"===o.type){const e=n?Nn(t,r):In(t,r);if(null!==e){An(e);continue}}"children"in o&&An(o)}}const Fn=new Set(["code","pre","script","style","textarea","title"]),On=new Set(["a","abbr","b","bdi","bdo","cite","data","del","dfn","em","i","ins","kbd","mark","q","rp","rt","ruby","s","samp","small","span","strong","sub","sup","time","u","var"]);function Bn(t){if(delete t.position,"children"in t)for(const e of t.children)Bn(e);return t}const zn=/* @__PURE__ */t("isMarkdownExport",Boolean),_n=/* @__PURE__ */r("mdastHtmlChildBatches",()=>[]),Hn=new Set(["font-weight","font-style","text-decoration","vertical-align"]);function qn(t,e,n){if(S(t)){if(0!==e&&t.setFormat(t.getFormat()|e),""!==n){const e=t.getStyle();t.setStyle(""===e?n:n+e)}}else if(b(t))for(const r of t.getChildren())qn(r,e,n)}const Dn={$import:(t,e)=>{const n=t.get(_n)[Number(e.getAttribute("data-mdast-child"))];if(!n)return[];const r=t.get(u),o=t.get(d),i={};for(const t in o)Hn.has(t)||(i[t]=o[t]);const s=f(i);if(0!==r||""!==s)for(const t of n)qn(t,r,s);return[...n]},match:/* @__PURE__ */c.tag("template","span").attr("data-mdast-child",!0),name:"@lexical/mdast/html-child-placeholder"},Pn={transforms:[t=>{An(t)}]};function Zn(t){const e=[];for(const n of t)b(n)&&!n.isInline()?e.push(...Zn(n.getChildren())):e.push(n);return e}const Un=/* @__PURE__ */r("mdastHtmlInlineResult",()=>({nodes:null})),jn={$import:(t,e)=>(t.get(Un).nodes=t.$importChildren(e),[]),match:/* @__PURE__ */c.tag("span").attr("data-mdast-inline-root",!0),name:"@lexical/mdast/html-inline-root"};function Gn(...t){let e="";const n=[],r=()=>`<template data-mdast-child="${n.length}"></template>`;for(const o of t)if("string"==typeof o)e+=o;else if(Array.isArray(o))e+=r(),n.push({children:o,type:"paragraph"});else{let t=!0;for(const i of o.flow)t||(e+="\n\n"),t=!1,e+=r(),n.push(i)}return{children:n,type:"htmlBlock",value:e}}const Kn="data-mdast-part";function Qn(){return new RegExp(`<template ${Kn}="(\\d+)"></template>`)}const Wn=/* @__PURE__ */Qn();function Xn(t){return new Set(t.split(" "))}const Jn=/* @__PURE__ */Xn("address article aside base basefont blockquote body caption center col colgroup dd details dialog dir div dl dt fieldset figcaption figure footer form frame frameset h1 h2 h3 h4 h5 h6 head header hr html iframe legend li link main menu menuitem nav noframes ol optgroup option p param search section summary table tbody td tfoot th thead title tr track ul");function Vn(t){return t.replace(/^(<\/?([a-zA-Z][a-zA-Z0-9-]*)[^>]*>)(?=<)/,(t,e,n)=>Jn.has(n.toLowerCase())?t:`${e}\n`)}function Yn(t){return t.replace(/(>)(<\/([a-zA-Z][a-zA-Z0-9-]*)>)$/,(t,e,n,r)=>Jn.has(r.toLowerCase())?t:`${e}\n${n}`)}function tr(t){const e=/^<\/?([a-zA-Z][a-zA-Z0-9-]*)/.exec(t);return null!==e&&!Jn.has(e[1].toLowerCase())}const er=(t,r)=>{const o=J(),i=[],s=[],c=t=>{const e=et().createElement("template");return e.setAttribute(Kn,String(i.length)),i.push(t),e},u=e([n(l,!0),n(zn,!0)],o)(()=>{const e=a(o).$exportDOM(t,o);let n=e.element;if(!n)return null;const i=Array.from(e.$getChildNodes?e.$getChildNodes():b(t)?t.getChildren():[]);if(i.length>0){const t=i.some(t=>(b(t)||M(t))&&!t.isInline()),o=c(t?"flow":"phrasing");s.push(t?{flow:r.exportChildren(i)}:r.exportInline(i)),e.append?e.append(o):V(n)&&n.append(o)}return e.after&&(n=e.after.call(t,n)??n),n});if(!u)return null;if(V(u)||Y(u))for(const e of Array.from(u.querySelectorAll("[data-lexical-slot]"))){if(!u.contains(e))continue;const n=e.getAttribute("data-lexical-slot"),o=null===n?null:tt(t,n);if(null===o)continue;e.removeAttribute("data-lexical-slot");const i=b(o)&&o.isShadowRoot(),l=c(i?"flow":"phrasing");s.push(i?{flow:r.exportChildren(o)}:r.exportInline(o)),e.replaceChildren(l)}let d;if(V(u))d=u.outerHTML;else{const t=et().createElement("div");t.append(u),d=t.innerHTML}d=d.replace(/ ([a-zA-Z-]+)=""/g," $1");const p=d.split(Wn),m=[];let f=!0,h=!1;for(let t=0;t<p.length;t++){if(t%2==0){let e=p[t];f&&(e=Vn(e)),t===p.length-1&&(e=Yn(e)),h&&(m.push(tr(e)?"\n\n":"\n"),h=!1),m.push(e);continue}const e=Number(p[t]),n="flow"===i[e];f=n,n?(m.push("\n\n",s[e]),h=!0):m.push("\n",s[e],"\n")}return Gn(...m)},nr=/<template data-mdast-child="(\d+)"><\/template>/,rr={dependencies:[i,[s,{rules:[Dn,jn]}],[Ve,{importRules:[{$import:(t,e)=>{const r=t.children.map(t=>e.importNode(t)),{registry:o}=wt(Ve),i=o.mdastExtensions.filter(t=>t!==Pn),s=function(t){const n=t.replace(bn,""),s=[];let l="",a=0;const c=t=>{if(s.some(t=>Fn.has(t))||s.length>0&&On.has(s[s.length-1])||""===t.trim())return void(l+=t);const[,n,a,c]=/^(\s*)([\s\S]*?)(\s*)$/.exec(t);l+=n+(t=>{const n=Bn(Dt(t,{extensions:o.micromarkExtensions,mdastExtensions:i})),s=r.length,l=n.children[0];return r.push(1===n.children.length&&"paragraph"===l.type?e.importChildren(l):n.children.flatMap(t=>e.importNode(t))),`<span data-mdast-child="${s}">&#8203;</span>`})(a)+c};for(const t of n.matchAll(Mn)){c(n.slice(a,t.index)),l+=t[0],a=t.index+t[0].length;const[,e,r,,o]=t,i=r.toLowerCase();if(!Tn.has(i)&&!o)if(e){const t=s.lastIndexOf(i);-1!==t&&(s.length=t)}else s.push(i)}return c(n.slice(a)),l}(t.value),l=(new DOMParser).parseFromString(s,"text/html");return p(l,{context:[n(_n,r)]})},type:"htmlBlock"},{$import:(t,e)=>{const r=t.children.map(t=>e.importNode(t)),o={nodes:null},i=(new DOMParser).parseFromString(`<span data-mdast-inline-root="true">${t.value}</span>`,"text/html");return p(i,{context:[n(_n,r),n(Un,o)]}),null===o.nodes?[]:Zn(o.nodes)},type:"htmlInline"}],mdastExtensions:[Pn],toMarkdownExtensions:[{handlers:{htmlBlock:(t,e,n,r)=>{const o=n.createTracker(r),i=t.value.split(nr);let s="";for(let e=0;e<i.length;e++){if(e%2==0){""!==i[e]&&(s+=o.move(i[e]));continue}const r=t.children[Number(i[e])];void 0!==r&&(s+=o.move(n.handle(r,t,n,{...o.current(),after:(i[e+1]||"\n")[0],before:""===s?"\n":s[s.length-1]})))}return s}}}]}]],name:"@lexical/mdast/Html"};export{fn as $convertFromMarkdownString,hn as $convertFromMdast,$n as $convertSelectionToMarkdownString,kn as $convertToMarkdownString,Cn as $convertToMdast,er as $exportViaDOM,gn as $generateNodesFromMarkdownString,xn as $generateNodesFromMdast,_e as ImportContextMarkdown,an as MdastAutolinkLiteralExtension,en as MdastBlockquoteExtension,sn as MdastCodeExtension,pn as MdastCommonMarkExtension,yn as MdastExportExtension,Ve as MdastExtension,wn as MdastGfmExtension,tn as MdastHeadingExtension,un as MdastHorizontalRuleExtension,rr as MdastHtmlExtension,Ye as MdastImportExtension,ln as MdastLinkExtension,rn as MdastListExtension,nn as MdastRichTextExtension,cn as MdastShadowRootQuoteExtension,mn as MdastShortcutsExtension,dn as MdastStrikethroughExtension,Sn as MdastTableExtension,on as MdastTaskListExtension,zn as RenderContextMarkdownExport,Be as RenderContextMarkdownSelection,Gn as rawHtmlBlock};
package/package.json CHANGED
@@ -10,22 +10,22 @@
10
10
  "micromark"
11
11
  ],
12
12
  "license": "MIT",
13
- "version": "0.51.1-nightly.20260925.0",
13
+ "version": "0.52.0",
14
14
  "main": "./dist/LexicalMdast.js",
15
15
  "types": "./dist/typescript-too-old.d.ts",
16
16
  "dependencies": {
17
- "@lexical/code-core": "0.51.1-nightly.20260925.0",
18
- "@lexical/extension": "0.51.1-nightly.20260925.0",
19
- "@lexical/html": "0.51.1-nightly.20260925.0",
20
- "@lexical/internal": "0.51.1-nightly.20260925.0",
21
- "@lexical/link": "0.51.1-nightly.20260925.0",
22
- "@lexical/list": "0.51.1-nightly.20260925.0",
23
- "@lexical/rich-text": "0.51.1-nightly.20260925.0",
24
- "@lexical/selection": "0.51.1-nightly.20260925.0",
25
- "@lexical/table": "0.51.1-nightly.20260925.0",
26
- "@lexical/utils": "0.51.1-nightly.20260925.0",
17
+ "@lexical/code-core": "0.52.0",
18
+ "@lexical/extension": "0.52.0",
19
+ "@lexical/html": "0.52.0",
20
+ "@lexical/internal": "0.52.0",
21
+ "@lexical/link": "0.52.0",
22
+ "@lexical/list": "0.52.0",
23
+ "@lexical/rich-text": "0.52.0",
24
+ "@lexical/selection": "0.52.0",
25
+ "@lexical/table": "0.52.0",
26
+ "@lexical/utils": "0.52.0",
27
27
  "@types/mdast": "^4.0.4",
28
- "lexical": "0.51.1-nightly.20260925.0",
28
+ "lexical": "0.52.0",
29
29
  "mdast-util-from-markdown": "^2.0.3",
30
30
  "mdast-util-gfm-autolink-literal": "^2.0.1",
31
31
  "mdast-util-gfm-strikethrough": "^2.0.0",