@gt-editor/markdown-editor 0.1.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/index.cjs +24 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.js +3094 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown-editor.css +1 -0
- package/package.json +42 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";var ge=Object.defineProperty;var be=(e,t,n)=>t in e?ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var $=(e,t,n)=>be(e,typeof t!="symbol"?t+"":t,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const xe=require("react/jsx-runtime"),O=require("react"),g=require("@codemirror/view"),R=require("@codemirror/state"),Z=require("@codemirror/commands"),wt=require("@codemirror/search"),y=require("@codemirror/language"),Gt=(e=14,t=16,n=16)=>g.EditorView.theme({"&":{backgroundColor:"#1e1e2e",color:"#e8e8e8",height:"100%"},".cm-content":{fontFamily:'"SF Mono", "Fira Code", monospace',fontSize:`${e}px`,lineHeight:"1.6",padding:`${n}px ${t}px`},".cm-cursor":{borderLeftColor:"#f5e0dc"},".cm-cursor-secondary":{borderLeftColor:"#f5e0dc"},"&.cm-focused .cm-selectionBackground-secondary, .cm-selectionBackground-secondary":{backgroundColor:"rgba(69, 71, 90, 0.7)"},".cm-activeLine":{backgroundColor:"rgba(255, 255, 255, 0.02)",boxShadow:"inset 0 1px 0 0 rgba(255, 255, 255, 0.08), inset 0 -1px 0 0 rgba(255, 255, 255, 0.08)"},".cm-activeLineGutter":{backgroundColor:"rgba(255, 255, 255, 0.02)",color:"#e8e8e8",boxShadow:"inset 0 1px 0 0 rgba(255, 255, 255, 0.08), inset 0 -1px 0 0 rgba(255, 255, 255, 0.08)"},".cm-selectionBackground, &.cm-focused .cm-selectionBackground":{backgroundColor:"rgba(137, 180, 250, 0.35) !important"},".cm-selectionMatch":{backgroundColor:"rgba(137, 180, 250, 0.25)",borderRadius:"2px"},".cm-gutters":{backgroundColor:"#1e1e2e",color:"#6c7086",border:"none",paddingRight:"8px",fontSize:`${e}px`,fontFamily:'"SF Mono", "Fira Code", monospace',position:"relative"},"& .cm-foldGutter":{position:"absolute",right:"-24px",top:"0",width:"24px",zIndex:"5",backgroundColor:"transparent"},".cm-hidden-markup":{visibility:"hidden"},".cm-panels":{backgroundColor:"#181825",borderBottom:"1px solid #45475a"},".cm-panels input, .cm-panels button":{color:"#cdd6f4"},".cm-searchMatch":{backgroundColor:"rgba(249, 226, 175, 0.3)",borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"rgba(249, 226, 175, 0.5)"},".cm-md-bold":{color:"#ffa348",fontWeight:"bold"},".cm-md-italic":{color:"#69dbdb",fontStyle:"italic"},".cm-md-strike":{color:"#868e96",textDecoration:"line-through"},".cm-md-code":{color:"#50fa7b",backgroundColor:"rgba(80, 80, 80, 0.4)",borderRadius:"3px",padding:"1px 4px"},".cm-md-link":{color:"#89b4fa",textDecoration:"underline",cursor:"pointer"},".cm-md-heading":{fontWeight:"bold"},".cm-md-h1":{color:"#c678dd"},".cm-md-h2":{color:"#b197fc"},".cm-md-h3":{color:"#a78bfa"},".cm-md-h4":{color:"#9775fa"},".cm-md-h5":{color:"#8b5cf6"},".cm-md-h6":{color:"#7c3aed"},".cm-heading-tag-logs":{color:"#f5a3bb !important"},".cm-heading-tag-links":{color:"#74c7ec !important"},".cm-heading-tag-deprecated":{color:"#fab387 !important"},".cm-heading-size-1":{fontSize:"1.5em"},".cm-heading-size-2":{fontSize:"1.3em"},".cm-heading-size-3":{fontSize:"1.15em"},".cm-heading-size-4":{fontSize:"1.1em"},".cm-md-markup":{color:"#6c7086"},".cm-md-heading-muted":{color:"#9595c8",fontWeight:"normal"},".cm-list-bullet":{color:"#f9e2af"},".cm-md-list-marker":{color:"#f9e2af"},".cm-image-container":{display:"block",marginTop:"0",marginBottom:"0"},".cm-image-widget":{maxWidth:"100%",borderRadius:"4px",cursor:"pointer"},".cm-image-active .cm-image-widget":{outline:"2px solid #89b4fa",outlineOffset:"2px"},".cm-md-image-syntax":{opacity:.5},".cm-md-image-hidden":{visibility:"hidden"},".cm-md-image-line":{whiteSpace:"nowrap",overflow:"hidden",maxHeight:"1.6em"},".cm-image-error":{color:"#f38ba8",fontStyle:"italic",fontSize:"0.9em"},".cm-collapsible-header":{color:"#cdd6f4"},".cm-collapsible-header.cm-md-h1":{color:"#c678dd"},".cm-collapsible-header.cm-md-h2":{color:"#b197fc"},".cm-collapsible-header.cm-md-h3":{color:"#a78bfa"},".cm-collapsible-header.cm-md-h4":{color:"#9775fa"},".cm-collapsible-header.cm-md-h5":{color:"#8b5cf6"},".cm-collapsible-header.cm-md-h6":{color:"#7c3aed"},".cm-collapsible-header .cm-md-bold":{color:"#ffa348"},".cm-collapsible-header .cm-md-italic":{color:"#69dbdb"},".cm-collapsible-header .cm-md-code":{color:"#50fa7b"},".cm-collapsible-header .cm-md-strike":{color:"#868e96"},".cm-collapsible-marker":{display:"none"},"& .cm-fold-marker":{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",width:"100%",color:"#cdd6f4",fontSize:"20px",cursor:"pointer",opacity:"0.6",transition:"opacity 0.15s, color 0.15s"},"& .cm-fold-marker:hover":{opacity:"1",color:"#f38ba8"},".cm-gutterElement":{transition:"color 0.15s"},".cm-lineNumbers .cm-gutterElement":{cursor:"pointer"},".cm-lineNumbers .cm-gutterElement:hover":{color:"#f38ba8"},".cm-foldPlaceholder":{backgroundColor:"rgba(137, 180, 250, 0.2)",border:"1px solid rgba(137, 180, 250, 0.4)",borderRadius:"4px",padding:"2px 12px",margin:"0 8px",color:"#89b4fa",fontSize:"0.9em",fontWeight:"500",cursor:"pointer",verticalAlign:"middle",display:"inline-flex",alignItems:"center",height:"1.4em"},".cm-md-unclosed":{backgroundColor:"rgba(243, 139, 168, 0.25)",borderRadius:"2px"}},{dark:!0});function Pt(e,t=4){let n=0;for(let o=0;o<e.length;o++){const s=e.charCodeAt(o);if(s===9)n+=t-n%t;else if(s===32)n++;else break}return n}const Jt=y.foldService.of((e,t)=>{const n=e.doc.lineAt(t),o=n.text,s=o.trim();if(!s.startsWith(">>")&&!s.startsWith("^^"))return null;const c=Pt(o);let r=null;for(let i=n.number+1;i<=e.doc.lines;i++){const d=e.doc.line(i).text;if(d.trim()==="")continue;const f=Pt(d);if(d.trim()!==""&&f>c)r=i;else if(d.trim()!=="")break}return r!==null?{from:n.to,to:e.doc.line(r).to}:null});class tt extends g.WidgetType{toDOM(){const t=document.createElement("span");return t.className="cm-hidden-markup",t}}class ye extends g.WidgetType{toDOM(){const t=document.createElement("div");return t.className="cm-horizontal-rule",t}}class Qt extends g.WidgetType{constructor(t,n,o,s,c=!1){super(),this.src=t,this.alt=n,this.width=o,this.resolveImageUrl=s,this.isActive=c}eq(t){return t.src===this.src&&t.width===this.width}updateDOM(t){return this.isActive?t.classList.add("cm-image-active"):t.classList.remove("cm-image-active"),!0}toDOM(){const t=document.createElement("div");t.className="cm-image-container"+(this.isActive?" cm-image-active":"");const n=document.createElement("img"),o=this.resolveImageUrl?this.resolveImageUrl(this.src):this.src;return n.src=o,n.alt=this.alt,n.className="cm-image-widget",this.width&&(n.style.width=`${this.width}px`),n.onerror=()=>{t.innerHTML=`<span class="cm-image-error">Image not found: ${this.src}</span>`},t.appendChild(n),t}ignoreEvent(){return!1}}class Zt extends g.WidgetType{constructor(n,o=!1,s,c,r){super();$(this,"indent");$(this,"hasChildren");$(this,"view");$(this,"markerStart");$(this,"markerEnd");this.indent=n,this.hasChildren=o,this.view=s,this.markerStart=c,this.markerEnd=r}eq(n){return this.indent===n.indent&&this.hasChildren===n.hasChildren}toDOM(){const n=document.createElement("span");n.className=`cm-list-bullet ${this.hasChildren?"has-children":""}`;const o=document.createElement("span");o.className="bullet-indent",o.textContent=this.indent,n.appendChild(o);const s=document.createElement("span");return s.className="bullet-icon",s.textContent="• ",n.appendChild(s),n.addEventListener("mousedown",c=>{c.preventDefault(),c.stopPropagation();const r=s.getBoundingClientRect(),i=r.left+r.width/2,d=c.clientX<i?this.markerStart:this.markerEnd;this.view.dispatch({selection:{anchor:d}}),this.view.focus()}),n}ignoreEvent(){return!0}}class Ee extends g.WidgetType{constructor(n=""){super();$(this,"indent");this.indent=n}toDOM(){const n=document.createElement("span");if(n.className="cm-collapsible-marker",this.indent){const o=document.createElement("span");o.textContent=this.indent,n.appendChild(o)}return n}eq(n){return this.indent===n.indent}}const Tt={bold:"#ffa348",italic:"#69dbdb",code:"#50fa7b",strike:"#868e96",h1:"#c678dd",h2:"#b197fc",h3:"#a78bfa",h4:"#9775fa",h5:"#8b5cf6",h6:"#7c3aed"};class ke extends g.WidgetType{constructor(t,n,o,s,c=null,r=null){super(),this.indent=t,this.isOpen=n,this.isEmpty=o,this.lineFrom=s,this.formatType=c,this.view=r}toDOM(){const t=document.createElement("span");return t.className=`cm-collapsible-arrow ${this.isOpen?"open":"closed"}${this.isEmpty?" empty":""}`,t.textContent=this.isOpen?"▾":"▸",t.dataset.lineFrom=String(this.lineFrom),this.formatType&&Tt[this.formatType]&&(t.style.color=Tt[this.formatType]),t.addEventListener("click",n=>{if(n.preventDefault(),n.stopPropagation(),this.isEmpty||!this.view)return;const o=this.view.state.doc.lineAt(this.lineFrom),s=y.foldable(this.view.state,o.from,o.to);if(!s||s.to-s.from<=2)return;let c=null;if(y.foldedRanges(this.view.state).between(o.from,o.to,(r,i)=>{c={from:r,to:i}}),c){const r=this.createMarkerChange(o,"^^",">>");this.view.dispatch({effects:y.unfoldEffect.of(c),changes:r?[r]:void 0})}else{const r=this.createMarkerChange(o,">>","^^");this.view.dispatch({effects:y.foldEffect.of(s),changes:r?[r]:void 0})}}),t.addEventListener("mousedown",n=>{n.preventDefault(),n.stopPropagation()}),t}eq(t){return this.indent===t.indent&&this.isOpen===t.isOpen&&this.isEmpty===t.isEmpty&&this.lineFrom===t.lineFrom&&this.formatType===t.formatType&&this.view===t.view}createMarkerChange(t,n,o){const s=t.text.indexOf(n);return s===-1?null:{from:t.from+s,to:t.from+s+n.length,insert:o}}ignoreEvent(t){return t.type==="mousedown"||t.type==="click"||t.type==="dblclick"}}const Ce=[{regex:/\*\*(.+?)\*\*/g,class:"cm-md-bold",startLen:2,endLen:2},{regex:new RegExp("(?<!\\*)\\*(.+?)\\*(?!\\*)","g"),class:"cm-md-italic",startLen:1,endLen:1},{regex:/~~(.+?)~~/g,class:"cm-md-strike",startLen:2,endLen:2},{regex:/`([^`]*)`/g,class:"cm-md-code",startLen:1,endLen:1}],Ft=/^(\s*)(#{1,6})\s*(.+)$/,Rt=/\[(\w+)\]\s*$/,vt={logs:"cm-heading-tag-logs",log:"cm-heading-tag-logs",data:"cm-heading-tag-logs",links:"cm-heading-tag-links",link:"cm-heading-tag-links",sources:"cm-heading-tag-links",source:"cm-heading-tag-links",deprecated:"cm-heading-tag-deprecated",old:"cm-heading-tag-deprecated",obsolete:"cm-heading-tag-deprecated"},Wt=/^-{3,}$/,Le=/^(\s*)(-{3,})$/,Ht=/^```[\w-]*$/,$t=/^```$/,Se=/^(\s*)([*+-])\s+/,we=/^(\s*)(\d+\.)\s+/,Me=/^(\s*)(>>|\^\^)\s*(.*)$/,Ae=/\[([^\]]+)\]\(([^)]+)\)/g;function De(e){const t=e.match(/^(\s*)/),n=t?t[0]:"";return Math.floor(n.replace(/\t/g," ").length/4)}function te(e={}){return g.ViewPlugin.fromClass(class{constructor(t){$(this,"decorations");try{this.decorations=this.buildDecorations(t)}catch(n){console.error("[MarkdownSyntax] constructor failed:",n instanceof Error?n.message:n,{docLength:t.state.doc.length,docLines:t.state.doc.lines}),this.decorations=g.Decoration.none}}update(t){if(t.docChanged||t.viewportChanged||t.selectionSet||t.focusChanged)try{this.decorations=this.buildDecorations(t.view)}catch(n){if(console.error("[MarkdownSyntax] buildDecorations failed:",n instanceof Error?n.message:n,{docChanged:t.docChanged,docLength:t.state.doc.length,docLines:t.state.doc.lines}),t.docChanged)try{this.decorations=this.decorations.map(t.changes)}catch{this.decorations=g.Decoration.none}}}buildDecorations(t){const n=[],o=t.state.doc;let s=!1;const c=new Map,r=[],i=new Array(o.lines+1).fill(0);for(let m=1;m<=o.lines;m++){const h=o.line(m).text;h.trim()!==""&&(i[m]=De(h))}let l=0;for(let m=1;m<=o.lines;m++)if(o.line(m).text.trim()===""){let p=0;for(let k=m+1;k<=Math.min(m+5,o.lines);k++)if(o.line(k).text.trim()!==""){p=i[k];break}i[m]=Math.min(l,p)}else l=i[m];const d=new Set;if(t.hasFocus)for(const m of t.state.selection.ranges){const h=o.lineAt(m.from).number,p=o.lineAt(m.to).number;for(let k=h;k<=p;k++)d.add(k)}for(let m=1;m<=o.lines;m++){const h=o.line(m),p=h.text,k=d.has(m),T=i[m],I=Math.min(T,6),M=I>0?` cm-indent-L${I}`:"",j=p.trim();if(s&&$t.test(j)){s=!1,n.push({from:h.from,decoration:g.Decoration.line({class:"cm-code-block-line cm-code-block-end"+M})});continue}if(!s&&Ht.test(j)){s=!0,n.push({from:h.from,decoration:g.Decoration.line({class:"cm-code-block-line cm-code-block-start"+M})});continue}if(s){n.push({from:h.from,decoration:g.Decoration.line({class:"cm-code-block-line"+M})});continue}const _=p.match(Ft);if(_){const P=_[1].length,A=_[2].length,F=P,N=A+(p.charAt(F+A)===" "?1:0),Y=_[3].match(Rt),B=Y&&vt[Y[1].toLowerCase()]||"";n.push({from:h.from,decoration:g.Decoration.line({class:`cm-md-heading cm-md-h${A}${M}${B?" "+B:""}`})}),!k&&N>0?(n.push({from:h.from+F,to:h.from+F+N,decoration:g.Decoration.replace({widget:new tt})}),A<=4&&h.from+F+N<h.to&&n.push({from:h.from+F+N,to:h.to,decoration:g.Decoration.mark({class:`cm-heading-size-${A}`})})):A<=4&&n.push({from:h.from+F,to:h.to,decoration:g.Decoration.mark({class:`cm-heading-size-${A}`})});continue}const V=p.match(Le);if(V){const P=V[1].length,A=V[2].length;if(n.push({from:h.from,decoration:g.Decoration.line({class:"cm-hr-line"+M})}),!k){const F=h.from+P,N=F+A;n.push({from:F,to:N,decoration:g.Decoration.mark({class:"cm-hr-text-hidden"})})}continue}const q=p.match(Se),v=p.match(we),z=p.match(Me);if(q){const[P,A]=q,F=h.from+A.length,N=h.from+A.length+(P.length-A.length);n.push({from:h.from,decoration:g.Decoration.line({class:"cm-list-line"+M})}),k||n.push({from:h.from,to:N,decoration:g.Decoration.replace({widget:new Zt(A,!1,t,F,N)})})}else if(v)n.push({from:h.from,decoration:g.Decoration.line({class:"cm-list-line"+M})});else if(z){const P=z[1].length,A=2,F=P+A+(p.charAt(P+A)===" "?1:0),N=z[3]||"",J=N.match(/^(#{1,6})\s*(.+)$/);if(J){const Y=J[1].length,B=J[2].match(Rt),U=B&&vt[B[1].toLowerCase()]||"";if(n.push({from:h.from,decoration:g.Decoration.line({class:`cm-collapsible-header cm-md-heading cm-md-h${Y}${M}${U?" "+U:""}`})}),k)Y<=4&&n.push({from:h.from+F,to:h.to,decoration:g.Decoration.mark({class:`cm-heading-size-${Y}`})});else{const W=Y+(N.charAt(Y)===" "?1:0);n.push({from:h.from+F,to:h.from+F+W,decoration:g.Decoration.replace({widget:new tt})}),Y<=4&&h.from+F+W<h.to&&n.push({from:h.from+F+W,to:h.to,decoration:g.Decoration.mark({class:`cm-heading-size-${Y}`})})}}else n.push({from:h.from,decoration:g.Decoration.line({class:"cm-collapsible-header"+M})})}else{const P=M.trim();P&&n.push({from:h.from,decoration:g.Decoration.line({class:P})})}if(!_&&!Wt.test(j)){let P=p,A=0;if(z){const U=z[1].length+2,W=p.charAt(U)===" "?U+1:U;P=p.substring(W),A=W}const F=[];for(const B of Ce){const U=new RegExp(B.regex.source,"g");let W;for(;(W=U.exec(P))!==null;){const H=h.from+A+W.index,X=H+W[0].length;if(F.some(D=>H<D.to&&X>D.from))continue;const K=H+B.startLen,L=X-B.endLen;n.push({from:K,to:L,decoration:g.Decoration.mark({class:B.class})}),F.push({from:H,to:X}),r.push({from:H,to:X}),k||(n.push({from:H,to:K,decoration:g.Decoration.replace({widget:new tt})}),n.push({from:L,to:X,decoration:g.Decoration.replace({widget:new tt})}))}}const N=new RegExp(Ae.source,"g");let J;for(;(J=N.exec(P))!==null;){const B=J[0],U=J[1],W=h.from+A+J.index,H=W+B.length,X=W+1,K=X+U.length;n.push({from:X,to:K,decoration:g.Decoration.mark({class:"cm-md-link"})}),F.push({from:W,to:H}),r.push({from:W,to:H}),k||(n.push({from:W,to:X,decoration:g.Decoration.replace({widget:new tt})}),n.push({from:K,to:H,decoration:g.Decoration.replace({widget:new tt})}))}const Y=["**","~~","*","`"];for(const B of Y){const U=new RegExp(B.replace(/[*]/g,"\\*").replace(/[`]/g,"\\`"),"g");let W;for(;(W=U.exec(P))!==null;){const H=h.from+A+W.index;if(!F.some(K=>H>=K.from&&H<K.to)){if(B.length===1){const Q=P[W.index+1],rt=W.index>0?P[W.index-1]:"";if(Q===B||rt===B)continue}const K=P[W.index+B.length],L=W.index>0?P[W.index-1]:" ";(K&&K!==" "&&K!==" "||L!==" "&&L!==" ")&&c.set(H,B.length)}}}}}const f=[{marker:"**",class:"cm-md-bold"},{marker:"~~",class:"cm-md-strike"},{marker:"*",class:"cm-md-italic"},{marker:"`",class:"cm-md-code"}],u=5,a=[...r],b=new Set;let C=!1;for(let m=1;m<=o.lines;m++){const h=o.line(m).text.trim();C&&$t.test(h)?(b.add(m),C=!1):!C&&Ht.test(h)?(C=!0,b.add(m)):C&&b.add(m)}for(let m=1;m<=o.lines;m++){const h=o.line(m),p=h.text;if(!b.has(m)&&p.trim()!==""&&!Ft.test(p)&&!Wt.test(p.trim()))for(let k=0;k<p.length;k++){const T=h.from+k;if(!a.some(I=>T>=I.from&&T<I.to))for(const I of f){const M=I.marker;if(p.substr(k,M.length)!==M||M.length===1&&(k+1<p.length&&p[k+1]===M||k>0&&p[k-1]===M))continue;const j=k+M.length;if(j>=p.length)continue;const _=p[j];if(_===" "||_===" "||_===`
|
|
2
|
+
`)continue;let V=!1;for(let v=j;v<=p.length-M.length;v++){if(p.substr(v,M.length)!==M||M.length===1&&(v+1<p.length&&p[v+1]===M||v>0&&p[v-1]===M)||v>0&&(p[v-1]===" "||p[v-1]===" "))continue;const z=h.from+v;if(!r.some(P=>z>=P.from&&z<P.to)){V=!0,a.push({from:T,to:h.from+v+M.length});break}}if(V)break;let q=null;for(let v=m+1;v<=Math.min(m+u,o.lines);v++){const z=o.line(v),P=z.text;if(P.trim()===""||b.has(v))break;for(let A=0;A<=P.length-M.length;A++){if(P.substr(A,M.length)!==M||M.length===1&&(A+1<P.length&&P[A+1]===M||A>0&&P[A-1]===M)||A===0||P[A-1]===" "||P[A-1]===" ")continue;const F=z.from+A;if(!r.some(N=>F>=N.from&&F<N.to)){q={lineNum:v,charIdx:A,absolutePos:z.from+A};break}}if(q)break}if(q){const v=T,z=T+M.length,P=q.absolutePos,A=q.absolutePos+M.length;n.push({from:z,to:P,decoration:g.Decoration.mark({class:I.class})});const F=d.has(m),N=d.has(q.lineNum);F||n.push({from:v,to:z,decoration:g.Decoration.replace({widget:new tt})}),N||n.push({from:P,to:A,decoration:g.Decoration.replace({widget:new tt})}),a.push({from:v,to:A});break}else if(!V){c.set(T,M.length);break}}}}for(const[m,h]of c)a.some(k=>m>=k.from&&m<k.to)||n.push({from:m,to:m+h,decoration:g.Decoration.mark({class:"cm-md-unclosed"})});const E=o.length,w=n.filter(m=>!(m.to!==void 0&&m.from>=m.to||m.from<0||m.from>E||m.to!==void 0&&(m.to<0||m.to>E))).map(m=>m.to?m.decoration.range(m.from,m.to):m.decoration.range(m.from)),S=w.slice().sort((m,h)=>m.from-h.from||m.value.startSide-h.value.startSide);for(let m=1;m<S.length;m++){const h=S[m-1],p=S[m];if(h.from===p.from&&h.to!==void 0&&p.to!==void 0){const k=h.value.widget!==void 0&&h.from!==h.to,T=p.value.widget!==void 0&&p.from!==p.to;if(k&&T){const I=o.lineAt(p.from);console.warn("[MarkdownSyntax] CONFLICT: overlapping replaces at same from",{pos:p.from,line:I.number,lineText:I.text.substring(0,80),prev:{from:h.from,to:h.to,startSide:h.value.startSide},curr:{from:p.from,to:p.to,startSide:p.value.startSide}})}}if(h.to!==void 0&&p.from<h.to){const k=h.value.widget!==void 0&&h.from!==h.to,T=p.value.widget!==void 0&&p.from!==p.to;if(k||T){const I=o.lineAt(p.from);console.warn("[MarkdownSyntax] CONFLICT: overlapping ranges (one is replace)",{pos:p.from,line:I.number,lineText:I.text.substring(0,80),prev:{from:h.from,to:h.to,isReplace:k},curr:{from:p.from,to:p.to,isReplace:T}})}}}return g.Decoration.set(w,!0)}},{decorations:t=>t.decorations})}function Ie(){return g.EditorView.domEventHandlers({mousedown(e,t){if(e.button!==0||e.shiftKey||e.ctrlKey||e.metaKey||e.altKey)return!1;const n=e.clientX,o=e.clientY,s=t.posAtCoords({x:n,y:o});if(s===null)return!1;const c=t.state.doc.lineAt(s);let r=null;for(let i=c.to;i>=Math.max(c.from,c.to-8)&&(r=t.coordsAtPos(i)||t.coordsAtPos(i,-1),!r);i--);return r&&setTimeout(()=>{const i=t.state.selection.main;if(!i.empty)return;const l=i.head,d=t.state.doc.lineAt(l);l!==d.to&&n>=r.left-1&&o>=r.top&&o<=r.bottom&&t.dispatch({selection:R.EditorSelection.cursor(d.to)})},0),!1}})}const Pe=/^!\[([^\]|]*)?(?:\|(\d+))?\]\(([^)]+)\)$/,Te=(e={})=>R.StateField.define({create(t){return Ot(t,e)},update(t,n){return n.docChanged||n.selection?Ot(n.state,e):t},provide:t=>g.EditorView.decorations.from(t)});function Ot(e,t){const n=[],o=e.selection.main.head;for(let s=1;s<=e.doc.lines;s++){const c=e.doc.line(s),i=c.text.match(Pe);if(!i)continue;const[,l,d,f]=i,u=d?parseInt(d,10):null,a=o>=c.from&&o<=c.to;n.push({from:c.from,decoration:g.Decoration.line({class:"cm-md-image-line"})}),n.push({from:c.to,decoration:g.Decoration.widget({widget:new Qt(f,l||"",u,t.resolveImageUrl,a),block:!0,side:1})}),a?n.push({from:c.from,to:c.to,decoration:g.Decoration.mark({class:"cm-md-image-syntax"})}):n.push({from:c.from,to:c.to,decoration:g.Decoration.mark({class:"cm-md-image-hidden"})})}return n.sort((s,c)=>s.from-c.from),g.Decoration.set(n.map(s=>s.to!==void 0?s.decoration.range(s.from,s.to):s.decoration.range(s.from)),!0)}function Fe(e,t){var c,r;const n=e.split(`
|
|
3
|
+
`);if(n.length<=1)return e;let o=1/0;for(let i=0;i<n.length;i++){const l=n[i];if(l.trim()==="")continue;const d=((c=l.match(/^[ \t]*/))==null?void 0:c[0])||"",f=ft(d);f<o&&(o=f)}o===1/0&&(o=0);const s=[];for(let i=0;i<n.length;i++){const l=n[i];if(l.trim()===""){s.push(i===0?"":t);continue}const d=((r=l.match(/^[ \t]*/))==null?void 0:r[0])||"",u=ft(d)-o,a=i===0?" ".repeat(Math.max(0,u)):t+" ".repeat(Math.max(0,u));s.push(a+l.slice(d.length))}return s.join(`
|
|
4
|
+
`)}function ft(e){let t=0;for(const n of e)n===" "?t+=4-t%4:t++;return t}function Re(e){const t=e.state.selection.main.head,s=e.state.doc.lineAt(t).text.match(/^[ \t]*/);return s?s[0]:""}function jt(e,t){const n=e.state.selection.main,o=Re(e),s=Fe(t,o);e.dispatch({changes:{from:n.from,to:n.to,insert:s},selection:{anchor:n.from+s.length}})}function Bt(e){return navigator.clipboard.readText().then(t=>{var w,S;if(!t)return;const n=e.state.selection.main,o=e.state.doc,s=o.lineAt(n.head),c=((w=s.text.match(/^[ \t]*/))==null?void 0:w[0])||"",r=ft(c);let i=0;for(let m=s.number+1;m<=o.lines;m++){const h=o.line(m);if(h.text.trim()==="")continue;const p=ft(((S=h.text.match(/^[ \t]*/))==null?void 0:S[0])||"");if(p<=r)break;p>i&&(i=p)}const l=Math.max(r,i),d=" ".repeat(l),f=d+" ",u=t.length,a=`${d}^^ paste text [${u}]`,b=t.split(`
|
|
5
|
+
`).map(m=>f+m),C=a+`
|
|
6
|
+
`+b.join(`
|
|
7
|
+
`),E=s.from;e.dispatch({changes:{from:E,to:n.to,insert:C},selection:{anchor:E+a.length}});const x=e.state.doc.lineAt(E);if(x.text.trim().startsWith("^^")){let m=!1;if(y.foldedRanges(e.state).between(x.from,x.to,()=>{m=!0}),!m){const h=y.foldable(e.state,x.from,x.to);h&&h.to-h.from>2&&e.dispatch({effects:y.foldEffect.of(h)})}}}).catch(t=>console.error("[Clipboard]",t)),!0}function Nt(e,t){return navigator.clipboard.readText().then(n=>{var w,S;if(!n)return;const o=e.state.selection.main,s=e.state.doc,c=s.lineAt(o.head),r=((w=c.text.match(/^[ \t]*/))==null?void 0:w[0])||"",i=ft(r);let l=0;for(let m=c.number+1;m<=s.lines;m++){const h=s.line(m);if(h.text.trim()==="")continue;const p=ft(((S=h.text.match(/^[ \t]*/))==null?void 0:S[0])||"");if(p<=i)break;p>l&&(l=p)}const d=Math.max(i,l),f=" ".repeat(d),u=f+" ",a=`${f}^^ ⏳`,b=n.split(`
|
|
8
|
+
`).map(m=>u+m),C=a+`
|
|
9
|
+
`+b.join(`
|
|
10
|
+
`),E=c.from;e.dispatch({changes:{from:E,to:o.to,insert:C},selection:{anchor:E+a.length}});const x=e.state.doc.lineAt(E);if(x.text.trim().startsWith("^^")){let m=!1;if(y.foldedRanges(e.state).between(x.from,x.to,()=>{m=!0}),!m){const h=y.foldable(e.state,x.from,x.to);h&&h.to-h.from>2&&e.dispatch({effects:y.foldEffect.of(h)})}}t(n).then(m=>{const h=m&&m.trim()?m.trim():"paste text",p=e.state.doc;for(let k=1;k<=p.lines;k++){const T=p.line(k),I=T.text.match(/^(\s*)\^\^\s*⏳\s*$/);if(I){const j=`${I[1]}^^ ${h}`;e.dispatch({changes:{from:T.from,to:T.to,insert:j}});break}}}).catch(m=>{console.error("[Clipboard] AI title generation failed:",m);const h=e.state.doc;for(let p=1;p<=h.lines;p++){const k=h.line(p),T=k.text.match(/^(\s*)\^\^\s*⏳\s*$/);if(T){const M=`${T[1]}^^ paste text`;e.dispatch({changes:{from:k.from,to:k.to,insert:M}});break}}})}).catch(n=>console.error("[Clipboard]",n)),!0}let bt=!1,at=null;function ee(e,t){const n=e.state.selection.main.head,o=e.coordsAtPos(n)??e.coordsAtPos(n,-1);o&&(t.style.left=`${o.left}px`,t.style.top=`${o.bottom+6}px`,requestAnimationFrame(()=>{if(!t.parentElement)return;const s=t.getBoundingClientRect();s.right>window.innerWidth&&(t.style.left=`${window.innerWidth-s.width-10}px`)}))}function ve(e){bt=!0,At();const t=document.createElement("div");t.className="cm-ai-paste-indicator",t.setAttribute("data-ai-paste-indicator","true");const n=document.createElement("span");n.className="cm-ai-paste-badge",n.textContent="📋 AI Paste";const o=document.createElement("span");o.className="cm-ai-paste-cancel",o.textContent="✕",o.addEventListener("click",s=>{s.stopPropagation(),We()}),t.appendChild(n),t.appendChild(o),document.body.appendChild(t),at=t,ee(e,t)}function At(){at&&(at.remove(),at=null)}function We(){bt=!1,At()}const He=g.EditorView.updateListener.of(e=>{!bt||!at||(e.selectionSet||e.geometryChanged||e.viewportChanged)&&ee(e.view,at)});function ne(e={}){return g.keymap.of([{key:"Mod-c",run:t=>{const n=t.state.selection.main;if(n.empty)return!1;const o=t.state.sliceDoc(n.from,n.to);return navigator.clipboard.writeText(o).catch(s=>{console.error("[Editor] Copy failed:",s)}),!0}},{key:"Mod-x",run:t=>{const n=t.state.selection.main;if(n.empty)return!1;const o=t.state.sliceDoc(n.from,n.to);return navigator.clipboard.writeText(o).then(()=>{const s=t.state.selection.main;t.dispatch({changes:{from:s.from,to:s.to,insert:""},selection:{anchor:s.from}})}).catch(s=>{console.error("[Editor] Cut failed:",s)}),!0}},{key:"Mod-v",run:t=>bt&&e.onGenerateTitle?(At(),bt=!1,Nt(t,e.onGenerateTitle)):(navigator.clipboard.read().then(async n=>{for(const o of n){const s=o.types.find(c=>c.startsWith("image/"));if(s&&e.onImagePaste)try{const r=await(await o.getType(s)).arrayBuffer(),i=new Uint8Array(r);let l="";for(let u=0;u<i.length;u++)l+=String.fromCharCode(i[u]);const d=btoa(l),f=await e.onImagePaste(d);if(f){const u=`
|
|
11
|
+
`,a=t.state.selection.main.head;t.dispatch({changes:{from:a,insert:u},selection:{anchor:a+u.length}})}return}catch(c){console.error("[Clipboard] Image paste failed:",c)}}try{const o=await navigator.clipboard.readText();o&&jt(t,o)}catch(o){console.error("[Clipboard] Text paste failed:",o)}}).catch(n=>{console.warn("[Clipboard] read() failed, falling back to readText:",n),navigator.clipboard.readText().then(o=>{o&&jt(t,o)}).catch(o=>console.error("[Clipboard]",o))}),!0)},{key:"Alt-Mod-v",run:Bt},{key:"Shift-Mod-v",run:t=>e.onGenerateTitle?Nt(t,e.onGenerateTitle):Bt(t)}])}function oe(){const e={"*":"*",_:"_","`":"`",'"':'"',"'":"'","(":")","[":"]","{":"}","~":"~",ё:"`",Ё:"`"};return g.EditorView.domEventHandlers({keydown:(t,n)=>{const o=t.key,s=e[o];if(!s)return!1;const c=n.state.selection.main;if(c.empty)return!1;t.preventDefault();const r=n.state.sliceDoc(c.from,c.to),i=o==="ё"||o==="Ё"?"`":o;return n.dispatch({changes:{from:c.from,to:c.to,insert:i+r+s},selection:{anchor:c.from+1,head:c.from+1+r.length}}),!0}})}function se(e){return g.EditorView.domEventHandlers({paste:(t,n)=>{var s;if(!e.onImagePaste)return!1;const o=(s=t.clipboardData)==null?void 0:s.items;if(!o)return!1;for(const c of o)if(c.type.startsWith("image/")){t.preventDefault();const r=c.getAsFile();return r?((async()=>{try{const l=await r.arrayBuffer(),d=new Uint8Array(l);let f="";for(let b=0;b<d.length;b++)f+=String.fromCharCode(d[b]);const u=btoa(f),a=await e.onImagePaste(u);if(a){const b=`
|
|
12
|
+
`,C=n.state.selection.main.head;n.dispatch({changes:{from:C,insert:b},selection:{anchor:C+b.length}})}}catch(l){console.error("Error pasting image:",l)}})(),!0):!1}return!1}})}const Mt=e=>`md-editor-fold:${e}`,$e=/^\s*(>>|\^\^)/;function re(e,t){if(!e)return;const n=y.foldedRanges(t.state),o=[];n.between(0,t.state.doc.length,(c,r)=>{const i=t.state.doc.lineAt(c).number,l=t.state.doc.lineAt(r).number;o.push({fromLine:i,toLine:l})});const s=e.split("/").pop();o.length>0?(console.log("[Fold:save]",s,"saving",o.length,"folds:",o),localStorage.setItem(Mt(e),JSON.stringify(o))):(console.log("[Fold:save]",s,"no folds — removing from localStorage"),localStorage.removeItem(Mt(e)))}function ce(e,t){if(e)try{const n=Mt(e),o=localStorage.getItem(n),s=e.split("/").pop();if(console.log("[Fold:load]",s,"localStorage entry:",o?o.slice(0,120):"NULL"),!o)return;const c=JSON.parse(o),r=[];let i=0;for(const{fromLine:l,toLine:d}of c)if(l<=t.state.doc.lines&&d<=t.state.doc.lines){const f=t.state.doc.line(l);if(!$e.test(f.text)){i++;continue}const u=f.to,a=t.state.doc.line(d).to;r.push(y.foldEffect.of({from:u,to:a}))}i>0&&console.warn("[Fold:load] skipped",i,"stale folds (no collapsible marker at saved line)"),r.length>0&&(console.log("[Fold:load]",e==null?void 0:e.split("/").pop(),"restoring",r.length,"folds from saved:",c),t.dispatch({effects:r}))}catch(n){console.error("[Fold:load] Failed:",n)}}function ie(e){return e.some(t=>t.is(y.foldEffect)||t.is(y.unfoldEffect))}class Oe extends g.WidgetType{constructor(t,n){super(),this.path=t,this.onOpenFile=n}eq(t){return t.path===this.path}toDOM(){const t=document.createElement("span");t.className="cm-include-link";const n=document.createElement("span");n.className="cm-include-link-icon",n.textContent="📎",t.appendChild(n);const o=document.createElement("span");if(o.className="cm-include-link-path",o.textContent=this.path,t.appendChild(o),this.onOpenFile){const s=document.createElement("button");s.className="cm-include-link-open",s.textContent="↗",s.title="Open file",s.addEventListener("click",c=>{var r;c.stopPropagation(),c.preventDefault(),(r=this.onOpenFile)==null||r.call(this,this.path)}),t.appendChild(s),t.addEventListener("mousedown",c=>{var r;(c.metaKey||c.ctrlKey)&&(c.stopPropagation(),c.preventDefault(),(r=this.onOpenFile)==null||r.call(this,this.path))})}return t}ignoreEvent(t){return t.type==="mousedown"}}const Lt=/^<!--\s*@include:\s*(.+?)\s*-->$/;function je(e={}){return g.ViewPlugin.fromClass(class{constructor(t){$(this,"decorations");$(this,"cmdPressed",!1);this.decorations=this.buildDecorations(t),this.setupCmdListener(t)}setupCmdListener(t){const n=c=>{(c.key==="Meta"||c.key==="Control")&&(this.cmdPressed=!0,t.contentDOM.classList.add("cm-include-cmd-mode"))},o=c=>{(c.key==="Meta"||c.key==="Control")&&(this.cmdPressed=!1,t.contentDOM.classList.remove("cm-include-cmd-mode"))},s=()=>{this.cmdPressed=!1,t.contentDOM.classList.remove("cm-include-cmd-mode")};document.addEventListener("keydown",n),document.addEventListener("keyup",o),window.addEventListener("blur",s),t._includeLinkCleanup=()=>{document.removeEventListener("keydown",n),document.removeEventListener("keyup",o),window.removeEventListener("blur",s)}}destroy(){}update(t){(t.docChanged||t.selectionSet||t.focusChanged)&&(this.decorations=this.buildDecorations(t.view))}buildDecorations(t){const n=[],o=t.state.doc,s=new Set;if(t.hasFocus)for(const c of t.state.selection.ranges){const r=o.lineAt(c.from).number,i=o.lineAt(c.to).number;for(let l=r;l<=i;l++)s.add(l)}for(let c=1;c<=o.lines;c++){const r=o.line(c),i=r.text.match(Lt);if(i){if(s.has(c))continue;const l=i[1].trim(),d=new Oe(l,e.onOpenFile);n.push({from:r.from,to:r.to,decoration:g.Decoration.replace({widget:d})})}}n.sort((c,r)=>c.from-r.from);try{return g.Decoration.set(n.map(c=>c.decoration.range(c.from,c.to)),!0)}catch(c){return console.error("[IncludeLink] Error:",c),g.Decoration.none}}},{decorations:t=>t.decorations})}function Be(e={}){return R.Prec.highest(g.EditorView.domEventHandlers({mousedown(t,n){if(!t.metaKey&&!t.ctrlKey)return!1;const o=n.posAtCoords({x:t.clientX,y:t.clientY});if(o===null)return!1;const c=n.state.doc.lineAt(o).text.match(Lt);if(c&&e.onOpenFile){const r=c[1].trim();return t.preventDefault(),t.stopPropagation(),e.onOpenFile(r),!0}return!1}}))}async function Ne(e,t){const n=e.split(`
|
|
13
|
+
`),o=[];for(const s of n){const c=s.match(Lt);if(c){const r=c[1].trim();try{const i=await t(r);o.push(i)}catch{o.push(s)}}else o.push(s)}return o.join(`
|
|
14
|
+
`)}let Et=null;const ze=g.ViewPlugin.fromClass(class{update(e){const t=e.state.selection;t.main.empty||(Et=t)}});function mt(e){const t=e.match(/^[\t ]*/);return t?t[0]:""}function le(e){let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" ");)t++;if(t+1<e.length&&(e[t]===">"&&e[t+1]===">"||e[t]==="^"&&e[t+1]==="^")&&(t+=2,t<e.length&&e[t]===" "&&t++),t<e.length&&e[t]==="#"){let s=0;for(;t+s<e.length&&e[t+s]==="#"&&s<6;)s++;s>0&&(t+s>=e.length||e[t+s]===" ")&&(t+=s,t<e.length&&e[t]===" "&&t++)}const o=e.substring(t).match(/^([*+\-]|\d+\.)\s+/);return o&&(t+=o[0].length),t}function Ve(e,t){const{state:n}=e,o=n.selection.main,s=n.doc.lineAt(o.from),c=n.doc.lineAt(o.to),r=[];for(let i=s.number;i<=c.number;i++){const l=n.doc.line(i),d=l.text,f=mt(d);d.slice(f.length).startsWith(t)||r.push({from:l.from+f.length,to:l.from+f.length,insert:t})}r.length>0&&e.dispatch({changes:r})}function Dt(e,t){const{state:n}=e,o=n.selection.main,s=n.doc.lineAt(o.from),c=s.text,r=mt(c),i=c.slice(r.length);{let l=null;if(i.startsWith(">> ")?l=">> ":i.startsWith("^^ ")?l="^^ ":i.startsWith(">>")?l=">>":i.startsWith("^^")&&(l="^^"),l){let d=null;if(y.foldedRanges(n).between(s.from,n.doc.length,(f,u)=>{f>=s.to&&f<=s.to+1&&!d&&(d={from:f,to:u})}),d){const u=l.startsWith("^^")?{from:s.from+r.length,to:s.from+r.length+2,insert:">>"}:void 0;e.dispatch({effects:y.unfoldEffect.of(d),...u?{changes:[u]}:{}});const b=e.state.doc.lineAt(o.from),C=mt(b.text),E=b.text.slice(C.length);let x=null;E.startsWith(">> ")?x=">> ":E.startsWith("^^ ")?x="^^ ":E.startsWith(">>")?x=">>":E.startsWith("^^")&&(x="^^"),x&&e.dispatch({changes:[{from:b.from+C.length,to:b.from+C.length+x.length,insert:""}]})}else e.dispatch({changes:[{from:s.from+r.length,to:s.from+r.length+l.length,insert:""}]})}else if(i.trim()===""){const d="Bullet",f=s.from+r.length;e.dispatch({changes:[{from:f,to:s.to,insert:t+d}],selection:{anchor:f+t.length+d.length}})}else Ve(e,t);return}}function et(e,t,n){const{state:o}=e,s=o.selection.main,c=t;let r=s.from,i=s.to;if(s.empty){const w=o.doc.lineAt(r),S=w.text;if(S.trim()==="")return;const m=le(S),h=S.trimEnd().length;if(m>=h)return;r=w.from+m,i=w.from+h}const l=o.sliceDoc(r,i),d=l.length-l.trimStart().length,f=l.length-l.trimEnd().length,u=l.trim(),a=t.length,b=c.length;u.length>=a+b+1&&u.startsWith(t)&&u.endsWith(c)&&(r=r+d+a,i=i-f-b);const C=o.sliceDoc(r,i),E=r>=t.length?o.sliceDoc(r-t.length,r):"",x=i+c.length<=o.doc.length?o.sliceDoc(i,i+c.length):"";E===t&&x===c?e.dispatch({changes:[{from:r-t.length,to:r,insert:""},{from:i,to:i+c.length,insert:""}],selection:{anchor:r-t.length,head:i-t.length}}):e.dispatch({changes:[{from:r,to:i,insert:t+C+c}],selection:{anchor:r+t.length,head:r+t.length+C.length}})}function dt(e,t){const{state:n}=e,o=n.selection.main,s=n.doc.lineAt(o.from),c=n.doc.lineAt(o.to),r=[];for(let i=s.number;i<=c.number;i++){const l=n.doc.line(i),d=l.text;let u=mt(d).length,a=d.slice(u);const b=a.match(/^(>>|\^\^)\s?/);b&&(u+=b[0].length,a=d.slice(u));const C=a.match(/^#{1,6}\s*/),E=t>0?"#".repeat(t)+" ":"";r.push({from:l.from+u,to:l.from+u+(C?C[0].length:0),insert:E})}r.length>0&&e.dispatch({changes:r})}function _e(e){const{state:t}=e,n=t.selection.main.head,o=t.doc.lineAt(n),s=o.text,c=n-o.from,r=/`([^`]*)`/g;let i;for(;(i=r.exec(s))!==null;){const l=i.index,d=l+i[0].length;if(c>=l&&c<=d)return{content:i[1],from:o.from+l,to:o.from+d}}return null}async function zt(e){try{await navigator.clipboard.writeText(e)}catch{const n=document.createElement("textarea");n.value=e,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n)}}function ct(e,t){const{state:n}=e,o=n.selection.main;let s=o.from,c=o.to;if(o.empty){const E=n.doc.lineAt(s),x=E.text;if(x.trim()==="")return!1;const w=le(x),S=x.trimEnd().length;if(w>=S)return!1;s=E.from+w,c=E.from+S}const r=n.sliceDoc(s,c),i=r.length-r.trimStart().length,l=r.length-r.trimEnd().length,d=s+i,f=c-l,u=r.trim(),a=t.length;u.length>=a*2+1&&u.startsWith(t)&&u.endsWith(t)&&(s=d+a,c=f-a);const b=s>=t.length?n.sliceDoc(s-t.length,s):"",C=c+t.length<=n.doc.length?n.sliceDoc(c,c+t.length):"";return b===t&&C===t}function kt(e,t){const{state:n}=e,o=n.selection.main,c=n.doc.lineAt(o.from).text,r=mt(c);return c.slice(r.length).startsWith(t)}function ae(e){const{state:t}=e,n=t.selection.main,s=t.doc.lineAt(n.from).text,c=mt(s);let r=s.slice(c.length);const i=r.match(/^(>>|\^\^)\s?/);i&&(r=r.slice(i[0].length));const l=r.match(/^(#{1,6})\s/);return l?l[1].length:0}function Ue(e){return Lt.test(e)}function Ke(e,t){var f;const n=[],o=e?ct(e,"**"):!1,s=e?ct(e,"*")&&!o:!1,c=e?ct(e,"`"):!1,r=e?ct(e,"~~"):!1,i=e?kt(e,">> ")||kt(e,"^^ "):!1,l=e?ae(e):0;if(e){const u=_e(e);u&&(n.push({label:"Copy block",action:()=>{zt(u.content)}}),n.push({divider:!0,label:""}))}if(e&&(t!=null&&t.resolveInclude)){const u=e.state.doc.toString();Ue(u)&&(n.push({label:"Copy with includes",action:async()=>{try{const a=await Ne(u,t.resolveInclude);await zt(a)}catch(a){console.error("[ContextMenu] Failed to resolve includes:",a)}}}),n.push({divider:!0,label:""}))}n.push({label:"Transform",submenu:[{label:i?"✓ Collapsible Section":"Collapsible Section",action:u=>Dt(u,">> ")},{divider:!0,label:""},{label:l===1?"✓ Heading 1":"Heading 1",action:u=>dt(u,l===1?0:1)},{label:l===2?"✓ Heading 2":"Heading 2",action:u=>dt(u,l===2?0:2)},{label:l===3?"✓ Heading 3":"Heading 3",action:u=>dt(u,l===3?0:3)},{divider:!0,label:""},{label:o?"✓ Bold":"Bold",action:u=>et(u,"**")},{label:s?"✓ Italic":"Italic",action:u=>et(u,"*")},{label:c?"✓ Code":"Code",action:u=>et(u,"`")},{label:r?"✓ Strikethrough":"Strikethrough",action:u=>et(u,"~~")}]});const d=((f=t==null?void 0:t.getEmojiShortcuts)==null?void 0:f.call(t))??[];return d.length>0&&(n.push({divider:!0,label:""}),n.push({label:"Emoji",submenu:d.map(u=>({label:`${u.emoji} ${u.name||u.emoji}`,_emojiDescription:u.description,action:a=>{const b=a.state.selection.main.head;a.dispatch({changes:{from:b,insert:u.emoji}})}}))})),n}function qe(e,t,n,o,s){const c=Ke(e,s);yt();const r=document.createElement("div");r.className="cm-context-menu",r.style.left=`${t}px`,r.style.top=`${n}px`,r.setAttribute("data-context-menu","true");let i=null,l=null;function d(x,w){f();const S=document.createElement("div");S.className="cm-emoji-tooltip",S.textContent=w,document.body.appendChild(S);const m=x.getBoundingClientRect();S.style.left=`${m.right+8}px`,S.style.top=`${m.top}px`,requestAnimationFrame(()=>{const h=S.getBoundingClientRect();h.right>window.innerWidth&&(S.style.left=`${m.left-h.width-8}px`),h.bottom>window.innerHeight&&(S.style.top=`${window.innerHeight-h.height-8}px`)}),i=S}function f(){i&&(i.remove(),i=null)}const u=x=>{x.key==="Meta"&&l&&d(l.el,l.desc)},a=x=>{x.key==="Meta"&&f()};document.addEventListener("keydown",u),document.addEventListener("keyup",a),r._emojiCleanup=()=>{document.removeEventListener("keydown",u),document.removeEventListener("keyup",a),f(),l=null};function b(x,w,S=!1){w.forEach(m=>{if(m.divider){const p=document.createElement("div");p.className="cm-context-menu-divider",x.appendChild(p);return}const h=document.createElement("div");if(h.className="cm-context-menu-item",m.submenu){h.classList.add("has-submenu"),h.innerHTML=`<span>${m.label}</span><span class="submenu-arrow">▸</span>`;const p=document.createElement("div");p.className="cm-context-submenu";let k=null;p.addEventListener("mousemove",T=>{var j;let I=null;for(const _ of p.children){const V=_.getBoundingClientRect();if(T.clientY>=V.top&&T.clientY<=V.bottom){I=_;break}}if(I===k)return;k=I;const M=I==null?void 0:I.dataset.emojiDesc;console.log("[EmojiTooltip] Hover changed. Target:",(j=I==null?void 0:I.textContent)==null?void 0:j.trim(),"Desc:",M,"Meta:",T.metaKey),I&&M?(l={el:I,desc:M},T.metaKey&&d(I,M)):(l=null,f())}),p.addEventListener("mouseleave",()=>{k=null,l=null,f()}),b(p,m.submenu,!0),h.appendChild(p)}else h.textContent=m.label,h.addEventListener("click",p=>{var k;p.stopPropagation(),yt(),(k=m.action)==null||k.call(m,e),e.focus()}),m._emojiDescription&&(h.dataset.emojiDesc=m._emojiDescription,console.log("[EmojiTooltip] Set data-emoji-desc on item:",m.label,"desc:",m._emojiDescription));x.appendChild(h)})}b(r,c),console.log("[EmojiTooltip] Menu rendered. HTML:",r.innerHTML),document.body.appendChild(r),requestAnimationFrame(()=>{const x=r.getBoundingClientRect();let w=t,S=n;x.right>window.innerWidth&&(w=window.innerWidth-x.width-10);const m=window.innerHeight-n,h=n;x.height>m&&h>m?S=n-x.height:x.bottom>window.innerHeight&&(S=window.innerHeight-x.height-10),r.style.left=`${Math.max(10,w)}px`,r.style.top=`${Math.max(10,S)}px`});const C=x=>{x.target.closest("[data-context-menu]")||(yt(),document.removeEventListener("click",C))},E=x=>{x.key==="Escape"&&(yt(),document.removeEventListener("keydown",E))};setTimeout(()=>{document.addEventListener("click",C),document.addEventListener("keydown",E)},0)}function yt(){var t;const e=document.querySelector("[data-context-menu]");e&&((t=e._emojiCleanup)==null||t.call(e),e.remove())}function Ye(e){const t=ae(e),n=ct(e,"**"),o=ct(e,"*")&&!n,s=ct(e,"`");return[{label:kt(e,">>")||kt(e,"^^")?"✓ Collapsible":"Collapsible",color:"#868e96",action:r=>Dt(r,">> ")},{label:n?"✓ Bold":"Bold",color:"#ffa348",action:r=>et(r,"**")},{label:o?"✓ Italic":"Italic",color:"#69dbdb",action:r=>et(r,"*")},{label:s?"✓ Code":"Code",color:"#50fa7b",action:r=>et(r,"`")},{label:t===1?"✓ H1":"H1",color:"#c678dd",action:r=>dt(r,t===1?0:1)},{label:t===2?"✓ H2":"H2",color:"#b197fc",action:r=>dt(r,t===2?0:2)},{label:t===3?"✓ H3":"H3",color:"#a78bfa",action:r=>dt(r,t===3?0:3)},{label:"📋 AI Paste",color:"#4ecdc4",action:r=>ve(r)}]}let pt=null,gt=null;function lt(){const e=document.querySelector("[data-command-palette]");e&&e.remove(),pt&&(document.removeEventListener("keydown",pt,!0),pt=null),gt&&(document.removeEventListener("click",gt),gt=null)}function Xe(e,t){lt();let n=t??e.state.selection;!t&&n.main.empty&&Et&&!Et.main.empty&&(n=Et);const o=n.main;o.empty||e.dispatch({selection:n});const s=o.head,c=e.coordsAtPos(s)??e.coordsAtPos(s,-1);if(!c)return;const r=Ye(e),i=document.createElement("div");if(i.className="cm-command-palette",i.setAttribute("data-command-palette","true"),i.style.left=`${c.left}px`,i.style.top=`${c.bottom+4}px`,!o.empty){const a=e.state.sliceDoc(o.from,o.to),b=document.createElement("div");b.className="cm-command-palette-preview";const C=a.length>30?a.slice(0,30)+"...":a;b.textContent=C,i.appendChild(b)}const l=document.createElement("div");i.appendChild(l);let d=0;function f(){l.innerHTML="",r.forEach((a,b)=>{const C=document.createElement("div");C.className="cm-command-palette-item"+(b===d?" active":"");const E=document.createElement("span");E.className="palette-color",E.style.backgroundColor=a.color;const x=document.createElement("span");x.textContent=a.label,C.appendChild(E),C.appendChild(x),C.addEventListener("click",w=>{w.stopPropagation(),lt(),a.action(e),e.focus()}),l.appendChild(C)})}f(),document.body.appendChild(i),requestAnimationFrame(()=>{const a=i.getBoundingClientRect();a.right>window.innerWidth&&(i.style.left=`${window.innerWidth-a.width-10}px`),a.bottom>window.innerHeight&&(i.style.top=`${c.top-a.height-4}px`),i.style.left=`${Math.max(10,parseInt(i.style.left))}px`,i.style.top=`${Math.max(10,parseInt(i.style.top))}px`});const u=n;pt=a=>{if((a.key==="ArrowDown"||a.key==="ArrowUp"||a.key==="Enter"||a.key==="Escape")&&(a.preventDefault(),a.stopPropagation(),a.stopImmediatePropagation()),a.key==="ArrowDown")d=(d+1)%r.length,f();else if(a.key==="ArrowUp")d=(d-1+r.length)%r.length,f();else if(a.key==="Enter"){const b=r[d].action;lt(),e.dispatch({selection:u}),b(e),e.focus()}else a.key==="Escape"&&(lt(),e.dispatch({selection:u}),e.focus())},gt=a=>{a.target.closest("[data-command-palette]")||lt()},setTimeout(()=>{document.addEventListener("keydown",pt,!0),document.addEventListener("click",gt)},0)}function Ge(e){return R.Prec.highest(g.EditorView.domEventHandlers({contextmenu:(t,n)=>{t.preventDefault();const o=n.state.selection.main,s=n.posAtCoords({x:t.clientX,y:t.clientY});return s!==null&&(!o.empty&&s>=o.from&&s<=o.to||n.dispatch({selection:{anchor:s}})),qe(n,t.clientX,t.clientY,void 0,e),!0}}))}function Vt(e){const t=new R.RangeSetBuilder;for(const{from:n,to:o}of e.visibleRanges)for(let s=n;s<=o;){const c=e.state.doc.lineAt(s),r=c.text;let i=0;for(let l=0;l<r.length;l++)if(r[l]===" ")i++;else if(r[l]===" ")i+=4;else break;if(i>0){const l=g.Decoration.line({attributes:{style:`padding-left: calc(${i}ch + 6px); text-indent: -${i}ch;`}});t.add(c.from,c.from,l)}s=c.to+1}return t.finish()}const Je=g.ViewPlugin.fromClass(class{constructor(e){$(this,"decorations");this.decorations=Vt(e)}update(e){(e.docChanged||e.viewportChanged)&&(this.decorations=Vt(e.view))}},{decorations:e=>e.decorations});g.EditorView.domEventHandlers({mousedown(e,t){const o=e.target.closest(".cm-line");if(!o)return;const s=t.posAtDOM(o),c=t.state.doc.lineAt(s),r=c.text.trim();if(r.startsWith(">>")||r.startsWith("^^")){let i=!1,l=null;if(y.foldedRanges(t.state).between(c.from,c.to,(d,f)=>{i=!0,l={from:d,to:f}}),i&&l)t.dispatch({effects:y.unfoldEffect.of(l)});else{const d=y.foldable(t.state,c.from,c.to);d&&t.dispatch({effects:y.foldEffect.of(d)})}return e.preventDefault(),!0}return!1}});function de(e=[]){return g.lineNumbers({formatNumber:t=>{let n=t;for(const o of e)t>o.editorLine&&(n+=o.diskLines);return String(n)},domEventHandlers:{mousedown(t,n,o){const s=t.state.doc.lineAt(n.from),c=s.text.trim();if(c.startsWith(">>")||c.startsWith("^^")){let r=!1,i=null;y.foldedRanges(t.state).between(n.from,n.to,(f,u)=>{r=!0,i={from:f,to:u}});const l=s.text,d=(f,u)=>{const a=l.indexOf(f);return a===-1?null:{from:s.from+a,to:s.from+a+2,insert:u}};if(r&&i){const f=d("^^",">>");t.dispatch({effects:y.unfoldEffect.of(i),changes:f?[f]:void 0})}else{const f=y.foldable(t.state,n.from,n.to);if(f&&f.to-f.from>2){const u=d(">>","^^");t.dispatch({effects:y.foldEffect.of(f),changes:u?[u]:void 0})}}return o.preventDefault(),o.stopPropagation(),!0}return!1}}})}de([]);class It extends g.GutterMarker{constructor(t,n){super(),this.isOpen=t,this.isEmpty=n}toDOM(){const t=document.createElement("div");return t.className=`cm-fold-marker ${this.isOpen?"open":"closed"}${this.isEmpty?" empty":""}`,t.textContent=this.isOpen?"▾":"▸",t}}const Qe=new It(!0,!1),Ze=new It(!1,!1),tn=new It(!1,!0);function _t(e,t,n){const o=y.foldable(e.state,t,n);return o!==null&&o.to-o.from>2}function en(e,t,n){let o=!1;return y.foldedRanges(e.state).between(t,n,()=>{o=!0}),o}g.gutter({class:"cm-foldGutter",markers:e=>{const t=[];for(let n=1;n<=e.state.doc.lines;n++){const o=e.state.doc.line(n),s=o.text.trim();(s.startsWith(">>")||s.startsWith("^^"))&&(_t(e,o.from,o.to)?en(e,o.from,o.to)?t.push({from:o.from,marker:Ze}):t.push({from:o.from,marker:Qe}):t.push({from:o.from,marker:tn}))}return R.RangeSet.of(t.map(n=>n.marker.range(n.from)))},domEventHandlers:{mousedown(e,t,n){const s=e.state.doc.lineAt(t.from).text.trim();if(!s.startsWith(">>")&&!s.startsWith("^^"))return!1;if(!_t(e,t.from,t.to))return n.preventDefault(),!0;let r=null;if(y.foldedRanges(e.state).between(t.from,t.to,(i,l)=>{r={from:i,to:l}}),r)e.dispatch({effects:y.unfoldEffect.of(r)});else{const i=y.foldable(e.state,t.from,t.to);i&&e.dispatch({effects:y.foldEffect.of(i)})}return n.preventDefault(),!0}}});const st=/^(\s*)(>>|\^\^)/,ht={pendingFold:0,pendingUnfold:0};window.__foldDiag=ht;const nn=g.ViewPlugin.fromClass(class{constructor(e){$(this,"decorations");this.decorations=this.buildDecorations(e)}update(e){(e.docChanged||e.selectionSet||this.foldStateChanged(e))&&(this.decorations=this.buildDecorations(e.view)),e.docChanged&&(this.autoUnfoldStaleFolds(e.view),this.autoFoldCollapsedMarkers(e.view))}autoFoldCollapsedMarkers(e){const t=e.state.doc,n=[];for(let s=1;s<=t.lines;s++){const c=t.line(s);if(c.text.trim().startsWith("^^")){let i=!1;if(y.foldedRanges(e.state).between(c.from,c.to,()=>{i=!0}),!i){const l=y.foldable(e.state,c.from,c.to);l&&l.to-l.from>2&&n.push(y.foldEffect.of(l))}}}let o=0;for(let s=1;s<=t.lines;s++)t.line(s).text.trim().startsWith("^^")&&o++;if(n.length===0){o>0&&console.log("[Fold:autoFold] ran: 0 to fold, all",o,"^^ blocks already folded");return}console.log("[Fold:autoFold]",n.length,"/",o,"unfolded ^^ blocks found, scheduling fold"),ht.pendingFold++,n.length,setTimeout(()=>{ht.pendingFold--,e.dispatch({effects:n})},0)}autoUnfoldStaleFolds(e){const t=e.state.doc,n=[],o=[];y.foldedRanges(e.state).between(0,t.length,(s,c)=>{const r=t.lineAt(s),i=r.text.match(st);if(!i)return;const l=y.foldable(e.state,r.from,r.to);if((!l||l.to!==c)&&(n.push(y.unfoldEffect.of({from:s,to:c})),i[2]==="^^")){const d=r.from+i[1].length;o.push({from:d,to:d+2,insert:">>"})}}),n.length>0&&(ht.pendingUnfold++,setTimeout(()=>{ht.pendingUnfold--,e.dispatch({...o.length>0?{changes:o}:{},effects:n})},0))}foldStateChanged(e){for(const t of e.transactions||[])for(const n of t.effects)if(n.is(y.foldEffect)||n.is(y.unfoldEffect))return!0;return!1}buildDecorations(e){const t=[],n=e.state.doc;for(let o=1;o<=n.lines;o++){const s=n.line(o),c=s.text.match(st);if(c){const r=c[1].length,i=c[2].length,l=s.from+r,d=l+i,f=this.hasContent(e,s.from,s.to),u=this.isFolded(e,s.from,s.to),a=this.detectFormatting(s.text),b=new ke("",!u,!f,s.from,a,e);t.push({from:l,to:d,decoration:g.Decoration.replace({widget:b})})}}t.sort((o,s)=>o.from-s.from);try{return g.Decoration.set(t.map(o=>o.decoration.range(o.from,o.to)),!0)}catch(o){return console.error("[CollapsibleArrow] Error:",o),g.Decoration.none}}hasContent(e,t,n){const o=y.foldable(e.state,t,n);return o!==null&&o.to-o.from>2}isFolded(e,t,n){let o=!1;return y.foldedRanges(e.state).between(t,n,()=>{o=!0}),o}detectFormatting(e){const t=e.replace(/^\s*(>>|\^\^)\s*/,""),n=t.match(/^(#{1,6})\s/);return n?`h${n[1].length}`:/\*\*[^*]+\*\*/.test(t)?"bold":new RegExp("(?<!\\*)\\*[^*]+\\*(?!\\*)").test(t)?"italic":/`[^`]+`/.test(t)?"code":/~~[^~]+~~/.test(t)?"strike":null}},{decorations:e=>e.decorations});function on(){return g.EditorView.domEventHandlers({click(e,t){const n=e.target;if(!n.classList.contains("cm-collapsible-arrow"))return!1;const o=n.dataset.lineFrom;if(!o)return!1;const s=parseInt(o,10),c=t.state.doc.lineAt(s),r=y.foldable(t.state,c.from,c.to);if(!r||r.to-r.from<=2)return e.preventDefault(),!0;let i=null;return y.foldedRanges(t.state).between(c.from,c.to,(l,d)=>{i={from:l,to:d}}),i?t.dispatch({effects:y.unfoldEffect.of(i)}):t.dispatch({effects:y.foldEffect.of(r)}),e.preventDefault(),!0}})}function sn(){return R.Prec.high(g.keymap.of([{key:"Enter",run:e=>{var d,f,u;const{state:t}=e,n=t.selection.main;if(!n.empty)return!1;const o=n.head,s=t.doc.lineAt(o);if(o!==s.to)return!1;let c=null;if(y.foldedRanges(t).between(o,o,(a,b)=>{const C=t.doc.lineAt(a);C.text.match(st)&&(o===C.to||o===b)&&(c={from:a,to:b})}),c){const a=c,C=((d=t.doc.lineAt(a.from).text.match(/^\s*/))==null?void 0:d[0])??"",E=t.doc.lineAt(a.to);if(E.number<t.doc.lines){const x=t.doc.line(E.number+1).from,w=C+`
|
|
15
|
+
`;e.dispatch({changes:{from:x,insert:w},selection:{anchor:x+C.length}})}else{const x=`
|
|
16
|
+
`+C;e.dispatch({changes:{from:t.doc.length,insert:x},selection:{anchor:t.doc.length+x.length}})}return!0}const r=s.text.match(/^(\s*)(>>)\s/);if(r){const b=`
|
|
17
|
+
`+r[1]+" ";return e.dispatch(t.replaceSelection(b),{scrollIntoView:!0,userEvent:"input"}),!0}let i=((f=/^\s*/.exec(s.text))==null?void 0:f[0])??"";if(s.number<t.doc.lines){const a=t.doc.line(s.number+1),b=((u=/^\s*/.exec(a.text))==null?void 0:u[0])??"";b.length>i.length&&(i=b)}const l=`
|
|
18
|
+
`+i;return e.dispatch(t.replaceSelection(l),{scrollIntoView:!0,userEvent:"input"}),!0}},{key:"Mod-Enter",run:e=>{var l,d,f;const{state:t}=e,n=t.selection.main;if(!n.empty)return!1;const o=t.doc.lineAt(n.head);let s=null;if(y.foldedRanges(t).between(o.from,o.to,(u,a)=>{t.doc.lineAt(u).text.match(st)&&(s={from:u,to:a})}),s){const u=s,b=((l=t.doc.lineAt(u.from).text.match(/^\s*/))==null?void 0:l[0])??"",C=t.doc.lineAt(u.to);if(C.number<t.doc.lines){const E=t.doc.line(C.number+1).from,x=b+`
|
|
19
|
+
`;e.dispatch({changes:{from:E,insert:x},selection:{anchor:E+b.length},scrollIntoView:!0})}else{const E=`
|
|
20
|
+
`+b;e.dispatch({changes:{from:t.doc.length,insert:E},selection:{anchor:t.doc.length+E.length},scrollIntoView:!0})}return!0}const c=o.text.match(/^(\s*)(>>)\s/);if(c){const a=`
|
|
21
|
+
`+c[1]+" ";return e.dispatch({changes:{from:o.to,insert:a},selection:{anchor:o.to+a.length},scrollIntoView:!0,userEvent:"input"}),!0}let r=((d=/^\s*/.exec(o.text))==null?void 0:d[0])??"";if(o.number<t.doc.lines){const u=t.doc.line(o.number+1),a=((f=/^\s*/.exec(u.text))==null?void 0:f[0])??"";a.length>r.length&&(r=a)}const i=`
|
|
22
|
+
`+r;return e.dispatch({changes:{from:o.to,insert:i},selection:{anchor:o.to+i.length},scrollIntoView:!0,userEvent:"input"}),!0}}]))}function rn(){return R.Prec.high(g.keymap.of([{key:"Backspace",run:e=>{const{state:t}=e,n=t.selection.main;if(!n.empty)return!1;const o=n.head;if(o===0)return!1;const s=t.doc.lineAt(o);if(o!==s.from)return!1;let c=null;if(y.foldedRanges(t).between(o-1,o-1,(r,i)=>{t.doc.lineAt(r).text.match(st)&&(c={from:r,to:i})}),c){const r=c,i=t.doc.lineAt(r.from),l=Math.max(i.from,r.from-1);return e.dispatch({selection:{anchor:l},scrollIntoView:!0}),!0}return!1}}]))}function Ut(e,t,n){const o=e.text.match(st);if(!o||o[2]!==t)return null;const s=e.from+o[1].length;return{from:s,to:s+t.length,insert:n}}function Kt(e,t,n){let o=null;if(y.foldedRanges(e.state).between(t.from,t.to,(s,c)=>{o={from:s,to:c}}),o){const s=Ut(t,"^^",">>"),c=[y.unfoldEffect.of(o)];e.dispatch({...s?{changes:s}:{},effects:c,...n?{selection:n}:{}})}else{const s=y.foldable(e.state,t.from,t.to);if(!s||s.to-s.from<=2)return;const c=Ut(t,">>","^^"),r=[y.foldEffect.of(s)];e.dispatch({...c?{changes:c}:{},effects:r,...n?{selection:n}:{}})}}function cn(e,t){const n=e.doc.lineAt(t);for(let o=n.number-1;o>=1;o--){const s=e.doc.line(o);if(!s.text.match(st))continue;const r=y.foldable(e,s.from,s.to);if(r&&r.to>=t)return s;let i=null;if(y.foldedRanges(e).between(s.from,s.to,(l,d)=>{i={from:l,to:d}}),i&&i.to>=t)return s}return null}function ln(){return R.Prec.high(g.keymap.of([{key:"Mod-.",run:e=>{const{state:t}=e,n=t.selection.main.head,o=t.doc.lineAt(n);if(st.test(o.text))return Kt(e,o,{anchor:o.to}),!0;const s=cn(t,n);if(s){const c=e.lineBlockAt(n).top,r=e.lineBlockAt(s.from).top,i=e.scrollDOM.scrollTop;return Kt(e,s,{anchor:s.to}),e.scrollDOM.scrollTop=i+(r-c),!0}return!0}}]))}const an=/^(\s*)(>>|\^\^)/;function dn(e){const t=e.replace(/^\s*(>>|\^\^)\s*/,""),n=t.match(/^(#{1,6})\s/);return n?`h${n[1].length}`:/\*\*[^*]+\*\*/.test(t)?"bold":new RegExp("(?<!\\*)\\*[^*]+\\*(?!\\*)").test(t)?"italic":/`[^`]+`/.test(t)?"code":/~~[^~]+~~/.test(t)?"strike":null}function fn(e){const t=e.match(/^(\s*)/);if(!t)return 0;const n=t[1];let o=0,s=0;for(const c of n)c===" "?(o++,s=0):c===" "&&(s++,s>=4&&(o++,s=0));return o}const mn=g.ViewPlugin.fromClass(class{constructor(e){$(this,"decorations");this.decorations=this.buildDecorations(e)}update(e){e.docChanged&&(this.decorations=this.buildDecorations(e.view))}buildDecorations(e){const t=e.state.doc,n=new R.RangeSetBuilder,o=[],s=new Map;for(let r=1;r<=t.lines;r++){const l=t.line(r).text,d=fn(l),f=l.trim()==="";if(!f)for(;o.length>0;){const a=o[o.length-1];if(d<=a.headerIndentLevel)o.pop();else break}if(l.match(an)){const a=dn(l);a&&o.push({headerLine:r,headerIndentLevel:d,formatType:a,ownsLevel:d+1})}if(!f&&d>0){const a=new Set;for(const b of o)d>=b.ownsLevel&&a.add(`cm-scope-L${b.ownsLevel}-${b.formatType}`);a.size>0&&s.set(r,a)}if(f&&o.length>0){const a=new Set;for(const b of o)a.add(`cm-scope-L${b.ownsLevel}-${b.formatType}`);a.size>0&&s.set(r,a)}}const c=Array.from(s.keys()).sort((r,i)=>r-i);for(const r of c){const i=s.get(r),l=t.line(r),d=Array.from(i).join(" ");n.add(l.from,l.from,g.Decoration.line({class:d}))}return n.finish()}},{decorations:e=>e.decorations}),un=g.ViewPlugin.fromClass(class{constructor(e){$(this,"layer");$(this,"view");this.view=e,this.layer=document.createElement("div"),this.layer.className="cm-custom-selection-layer",this.layer.setAttribute("aria-hidden","true"),e.scrollDOM.appendChild(this.layer),this.measureAndDraw()}update(e){(e.docChanged||e.selectionSet||e.viewportChanged||e.geometryChanged)&&this.measureAndDraw()}destroy(){this.layer.remove()}measureAndDraw(){this.view.requestMeasure({read:e=>this.readSelections(e),write:e=>{e&&e.length>0?this.drawSelections(e):this.layer.textContent=""}})}readSelections(e){const{selection:t,doc:n}=e.state;if(t.main.empty)return[];const o=[];try{const s=e.scrollDOM.getBoundingClientRect(),c=e.scrollDOM.scrollLeft,r=e.scrollDOM.scrollTop,i=l=>({left:l.left-s.left+c,top:l.top-s.top+r,width:l.width,height:l.height});for(const l of t.ranges){if(l.empty)continue;const d=n.lineAt(l.from),f=n.lineAt(l.to);for(let u=d.number;u<=f.number;u++){const a=n.line(u);if(u===f.number&&l.to===a.from)continue;const b=l.from<=a.from,E=a.from+a.length===n.length?l.to>=a.to:l.to>a.to;if(b&&E)try{let w=e.domAtPos(a.from).node;for(;w&&w!==e.contentDOM&&!(w.nodeType===1&&w.classList.contains("cm-line"));)w=w.parentElement;if(w&&w.classList.contains("cm-line")){const S=w,m=S.getBoundingClientRect(),h=window.getComputedStyle(S),p=parseFloat(h.paddingLeft)||0,k=parseFloat(h.textIndent)||0,T=p+k,I=m.left+T-s.left+c,M=m.top-s.top+r,j=m.height;o.push({type:"full",top:M,height:j,left:I,width:0})}}catch{}else try{const x=Math.max(l.from,a.from),w=Math.min(l.to,a.to),S=e.domAtPos(x),m=e.domAtPos(w),h=document.createRange();h.setStart(S.node,S.offset),h.setEnd(m.node,m.offset);const p=h.getClientRects();for(let k=0;k<p.length;k++){const T=i(p[k]);o.push({type:"partial",top:T.top,height:T.height,left:T.left,width:T.width})}}catch{}}}}catch(s){return console.error("[FullLineSelection] readSelections failed:",{error:s instanceof Error?s.message:s,selectionRanges:t.ranges.length,mainRange:{from:t.main.from,to:t.main.to},docLength:n.length}),[]}return o}drawSelections(e){this.layer.textContent="";for(const t of e){const n=document.createElement("div");n.className="cm-custom-selection-rect",t.type==="full"?(n.classList.add("cm-full-line-selection"),n.style.top=`${t.top}px`,n.style.height=`${t.height}px`,n.style.left=`${t.left}px`,n.style.right="0"):(n.classList.add("cm-partial-selection"),n.style.top=`${t.top}px`,n.style.height=`${t.height}px`,n.style.left=`${t.left}px`,n.style.width=`${t.width}px`),this.layer.appendChild(n)}}}),qt=/[\w\-а-яёА-ЯЁ_]/;function fe(e,t){const o=e.state.doc.lineAt(t),s=o.text,c=Math.max(0,Math.min(t-o.from,o.length));let r=c,i=c;for(;r>0&&qt.test(s[r-1]);)r--;for(;i<s.length&&qt.test(s[i]);)i++;return{start:o.from+r,end:o.from+i}}function Yt(e,t,n){const o=fe(e,t);return n==="left"?o.start:o.end}const hn=g.EditorView.mouseSelectionStyle.of((e,t)=>{if(t.detail!==2)return null;const n=e.posAtCoords({x:t.clientX,y:t.clientY});if(n===null)return null;const o=fe(e,n);if(o.start===o.end)return null;const s=o.start,r=t.metaKey||t.ctrlKey?e.state.selection.ranges.slice():[];return{get(i,l,d){const f=e.posAtCoords({x:i.clientX,y:i.clientY});let u;if(f===null)u=R.EditorSelection.range(s,o.end);else if(f<o.start){const a=Yt(e,f,"left");u=R.EditorSelection.range(o.end,a)}else if(f>o.end){const a=Yt(e,f,"right");u=R.EditorSelection.range(s,a)}else u=R.EditorSelection.range(s,o.end);return r.length>0?R.EditorSelection.create([...r,u]):R.EditorSelection.create([u])},update(i){return!1}}});function it(e,t){let n=0;for(let o=0;o<e.length;o++){const s=e.charCodeAt(o);if(s===9)n+=t-n%t;else if(s===32)n++;else break}return n}function xt(e,t,n){const o=e.line(t),s=it(o.text,n);let c=t;for(let r=t+1;r<=e.lines;r++){const i=e.line(r).text;if(i.trim()==="")continue;if(it(i,n)>s)c=r;else break}return{startLine:t,endLine:c}}function pn(e,t,n,o){if(t<=1)return null;const s=t-1;for(let c=t-1;c>=1;c--){const r=e.line(c).text;if(r.trim()==="")continue;const i=it(r,o);if(i===n)return{startLine:c,endLine:s};if(i>n)continue;return null}return null}function nt(e,t,n,o,s){const c=e.state.doc,r=c.line(t.startLine).from,i=c.line(t.endLine).to,l=c.line(n.startLine).from,d=c.line(n.endLine).to,f=c.sliceString(r,i),a=c.sliceString(l,d)+`
|
|
23
|
+
`+f;let b;if(s==="lower"){const h=o-l;b=r+h}else{const h=d-l,p=o-r;b=r+h+1+p}const C=e.state.doc.length-(d-r)+a.length;b=Math.max(0,Math.min(b,C-1));const E=e.scrollDOM.scrollTop,x=e.lineBlockAt(c.line(t.startLine).from).top,w=e.lineBlockAt(c.line(n.startLine).from).top,S=w-x;let m;if(n.endLine<c.lines)m=e.lineBlockAt(c.line(n.endLine+1).from).top-w;else{const h=e.lineBlockAt(c.line(n.endLine).from);m=h.top+h.height-w}e.dispatch({changes:{from:r,to:d,insert:a},selection:R.EditorSelection.cursor(b)}),gn(e,r,d),s==="lower"?e.scrollDOM.scrollTop=E-S:e.scrollDOM.scrollTop=E+m}function gn(e,t,n){const o=e.state.doc,s=o.lineAt(t).number,c=o.lineAt(Math.min(n,o.length)).number,r=[];for(let i=s;i<=c;i++){const l=o.line(i);if(!l.text.trim().startsWith("^^"))continue;let d=!1;if(y.foldedRanges(e.state).between(l.from,l.to,()=>{d=!0}),!d){const f=y.foldable(e.state,l.from,l.to);f&&f.to-f.from>2&&r.push(y.foldEffect.of(f))}}r.length>0&&e.dispatch({effects:r})}function bn(e){const{state:t}=e,n=t.doc,o=t.tabSize,s=t.selection.main.head,c=n.lineAt(s),r=xt(n,c.number,o),i=it(c.text,o);if(r.startLine<=1)return!1;const l=n.line(r.startLine-1);if(l.text.trim()==="")return nt(e,{startLine:l.number,endLine:l.number},r,s,"lower"),!0;if(it(l.text,o)<i)return nt(e,{startLine:l.number,endLine:l.number},r,s,"lower"),!0;const f=pn(n,r.startLine,i,o);return f?(nt(e,f,r,s,"lower"),!0):(nt(e,{startLine:l.number,endLine:l.number},r,s,"lower"),!0)}function xn(e){const{state:t}=e,n=t.doc,o=t.tabSize,s=t.selection.main.head,c=n.lineAt(s),r=xt(n,c.number,o),i=it(c.text,o);if(r.endLine>=n.lines)return!1;const l=n.line(r.endLine+1);if(l.text.trim()==="")return nt(e,r,{startLine:l.number,endLine:l.number},s,"upper"),!0;const d=it(l.text,o);if(d<i)return nt(e,r,{startLine:l.number,endLine:l.number},s,"upper"),!0;if(d===i){const f=xt(n,l.number,o);return nt(e,r,f,s,"upper"),!0}return nt(e,r,{startLine:l.number,endLine:l.number},s,"upper"),!0}function ot(e,t){let n=0;for(let o=0;o<e.length;o++)if(e.charCodeAt(o)===9)n+=t-n%t;else if(e.charCodeAt(o)===32)n++;else break;return n}function Ct(e){const t=e.facet(y.indentUnit);return t===" "?e.tabSize:t.length}function ut(e){return" ".repeat(e)}const Xt=/^\s*(>>|\^\^)/,yn={key:"Tab",run:e=>{const{state:t}=e,n=Ct(t),o=t.selection.main;if(o.empty){const c=t.doc.lineAt(o.head);if(Xt.test(c.text))return me(e)}const s=t.changeByRange(c=>{const r=[];let i=-1;for(let d=c.from;d<=c.to;){const f=t.doc.lineAt(d);if(f.number>i&&(c.empty||c.to>f.from)){i=f.number;const u=/^\s*/.exec(f.text)[0],a=ot(u,t.tabSize),b=(Math.floor(a/n)+1)*n;r.push({from:f.from,to:f.from+u.length,insert:ut(b)})}d=f.to+1}const l=t.changes(r);return{changes:r,range:R.EditorSelection.range(l.mapPos(c.anchor,1),l.mapPos(c.head,1))}});return e.dispatch(s,{scrollIntoView:!0,userEvent:"input.indent"}),!0},shift:e=>{const{state:t}=e,n=Ct(t),o=t.selection.main;if(o.empty){const c=t.doc.lineAt(o.head);if(Xt.test(c.text))return ue(e)}const s=t.changeByRange(c=>{const r=[];let i=-1;for(let d=c.from;d<=c.to;){const f=t.doc.lineAt(d);if(f.number>i&&(c.empty||c.to>f.from)){i=f.number;const u=/^\s*/.exec(f.text)[0],a=ot(u,t.tabSize);if(a>0){const b=Math.max(0,Math.floor((a-1)/n)*n);r.push({from:f.from,to:f.from+u.length,insert:ut(b)})}}d=f.to+1}const l=t.changes(r);return{changes:r,range:R.EditorSelection.range(l.mapPos(c.anchor,1),l.mapPos(c.head,1))}});return e.dispatch(s,{scrollIntoView:!0,userEvent:"input.indent"}),!0},preventDefault:!0};function me(e){const{state:t}=e,n=Ct(t),o=t.tabSize,s=t.selection.main;if(s.empty){const d=t.doc.lineAt(s.head),f=xt(t.doc,d.number,o),u=/^\s*/.exec(d.text)[0],a=ot(u,o),C=(Math.floor(a/n)+1)*n-a,E=[];for(let w=f.startLine;w<=f.endLine;w++){const S=t.doc.line(w);if(S.text.trim()==="")continue;const m=/^\s*/.exec(S.text)[0],h=ot(m,o);E.push({from:S.from,to:S.from+m.length,insert:ut(h+C)})}if(E.length===0)return!0;const x=t.changes(E);return e.dispatch({changes:E,selection:R.EditorSelection.cursor(x.mapPos(s.head,1)),scrollIntoView:!0,userEvent:"input.indent"}),!0}const c=t.doc.lineAt(s.from).number,r=t.doc.lineAt(s.to).number,i=[];for(let d=c;d<=r;d++){const f=t.doc.line(d);if(f.text.trim()==="")continue;const u=/^\s*/.exec(f.text)[0],a=ot(u,o),b=(Math.floor(a/n)+1)*n;i.push({from:f.from,to:f.from+u.length,insert:ut(b)})}if(i.length===0)return!0;const l=t.changes(i);return e.dispatch({changes:i,selection:R.EditorSelection.range(l.mapPos(s.anchor,1),l.mapPos(s.head,1)),scrollIntoView:!0,userEvent:"input.indent"}),!0}function ue(e){const{state:t}=e,n=Ct(t),o=t.tabSize,s=t.selection.main;if(s.empty){const d=t.doc.lineAt(s.head),f=xt(t.doc,d.number,o),u=/^\s*/.exec(d.text)[0],a=ot(u,o);if(a===0)return!0;const C=Math.max(0,Math.floor((a-1)/n)*n)-a,E=[];for(let w=f.startLine;w<=f.endLine;w++){const S=t.doc.line(w);if(S.text.trim()==="")continue;const m=/^\s*/.exec(S.text)[0],h=ot(m,o),p=Math.max(0,h+C);p!==h&&E.push({from:S.from,to:S.from+m.length,insert:ut(p)})}if(E.length===0)return!0;const x=t.changes(E);return e.dispatch({changes:E,selection:R.EditorSelection.cursor(x.mapPos(s.head,1)),scrollIntoView:!0,userEvent:"input.indent"}),!0}const c=t.doc.lineAt(s.from).number,r=t.doc.lineAt(s.to).number,i=[];for(let d=c;d<=r;d++){const f=t.doc.line(d);if(f.text.trim()==="")continue;const u=/^\s*/.exec(f.text)[0],a=ot(u,o);if(a>0){const b=Math.max(0,Math.floor((a-1)/n)*n);i.push({from:f.from,to:f.from+u.length,insert:ut(b)})}}if(i.length===0)return!0;const l=t.changes(i);return e.dispatch({changes:i,selection:R.EditorSelection.range(l.mapPos(s.anchor,1),l.mapPos(s.head,1)),scrollIntoView:!0,userEvent:"input.indent"}),!0}function En(e){const t=new Intl.Segmenter(void 0,{granularity:"grapheme"});return g.ViewPlugin.fromClass(class{constructor(n){$(this,"tooltip",null);$(this,"currentEmoji",null);$(this,"lastMouseX",0);$(this,"lastMouseY",0);$(this,"cursorStyleEl",null);$(this,"metaDown",!1);$(this,"_onKeyDown");$(this,"_onKeyUp");$(this,"emojiMap",new Map);$(this,"lastShortcutsRef",null);this.view=n,this._onKeyDown=o=>{o.key==="Meta"&&(this.metaDown=!0,this.onMetaPress())},this._onKeyUp=o=>{o.key==="Meta"&&(this.metaDown=!1,this.hideTooltip())},document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp)}getEmojiMap(){const n=e.getEmojiShortcuts();if(n!==this.lastShortcutsRef){this.lastShortcutsRef=n,this.emojiMap=new Map;for(const o of n)o.description&&this.emojiMap.set(o.emoji,o.description)}return this.emojiMap}onMetaPress(){const n=this.view.posAtCoords({x:this.lastMouseX,y:this.lastMouseY});if(n===null)return;const o=this.matchEmojiAt(this.view,n,this.lastMouseX);o&&(this.currentEmoji=o.emoji,this.showTooltip(o.description,this.lastMouseX,this.lastMouseY))}showTooltip(n,o,s){this.hideTooltip();const c=document.createElement("div");c.className="cm-emoji-tooltip",c.textContent=n,c.style.left=`${o+12}px`,c.style.top=`${s+12}px`,document.body.appendChild(c),requestAnimationFrame(()=>{if(!c.isConnected)return;const r=c.getBoundingClientRect();r.right>window.innerWidth&&(c.style.left=`${o-r.width-4}px`),r.bottom>window.innerHeight&&(c.style.top=`${s-r.height-4}px`)}),this.tooltip=c}hideTooltip(){this.tooltip&&(this.tooltip.remove(),this.tooltip=null),this.currentEmoji=null}setCursorHover(n){n?this.cursorStyleEl||(this.cursorStyleEl=document.createElement("style"),this.cursorStyleEl.textContent=".cm-content { cursor: default !important; }",document.head.appendChild(this.cursorStyleEl)):this.cursorStyleEl&&(this.cursorStyleEl.remove(),this.cursorStyleEl=null)}matchEmojiAt(n,o,s){const c=this.getEmojiMap();if(c.size===0)return null;const r=n.state.doc,i=Math.max(0,o-8),l=Math.min(r.length,o+12),d=r.sliceString(i,l);for(const{segment:f,index:u}of t.segment(d)){const a=i+u,b=a+f.length;if(o>=a&&o<=b){const C=c.get(f);if(C){const E=n.coordsAtPos(a),x=n.coordsAtPos(b,-1);if(E&&x&&s>=E.left&&s<=x.right)return{emoji:f,description:C}}}}return null}destroy(){this.cursorStyleEl&&(this.cursorStyleEl.remove(),this.cursorStyleEl=null),this.hideTooltip(),document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp)}},{eventHandlers:{mousemove(n,o){this.lastMouseX=n.clientX,this.lastMouseY=n.clientY;const s=o.posAtCoords({x:n.clientX,y:n.clientY});if(s===null){this.setCursorHover(!1),this.hideTooltip();return}const c=this.matchEmojiAt(o,s,this.lastMouseX);if(this.setCursorHover(!!c),!(n.metaKey||this.metaDown)){this.tooltip&&this.hideTooltip();return}c?this.currentEmoji!==c.emoji&&(this.currentEmoji=c.emoji,this.showTooltip(c.description,n.clientX,n.clientY)):this.hideTooltip()},mouseleave(){this.setCursorHover(!1),this.hideTooltip()}}})}const kn=[];function he({content:e,onChange:t,fontSize:n=14,wordWrap:o=!0,onImagePaste:s,resolveImageUrl:c,foldStateKey:r,onEditorView:i,initialScrollTop:l=0,resolveInclude:d,onOpenInclude:f,onBlur:u,showLineNumbers:a=!0,compact:b=!1,readOnly:C=!1,contentPaddingX:E=16,contentPaddingY:x=16,includeOffsets:w,onGenerateTitle:S,emojiShortcuts:m}){const h=w??kn,p=O.useRef(null),k=O.useRef(null),T=O.useRef(t),I=O.useRef(s),M=O.useRef(c),j=O.useRef(i),_=O.useRef(d),V=O.useRef(f),q=O.useRef(u),v=O.useRef(S),z=O.useRef(m),P=O.useRef(l);return O.useEffect(()=>{T.current=t},[t]),O.useEffect(()=>{I.current=s},[s]),O.useEffect(()=>{M.current=c},[c]),O.useEffect(()=>{j.current=i},[i]),O.useEffect(()=>{_.current=d},[d]),O.useEffect(()=>{V.current=f},[f]),O.useEffect(()=>{q.current=u},[u]),O.useEffect(()=>{v.current=S},[S]),O.useEffect(()=>{z.current=m},[m]),O.useEffect(()=>{P.current=l},[l]),O.useEffect(()=>{var K;if(!p.current)return;const A=[{key:"Mod-d",run:wt.selectNextOccurrence,preventDefault:!0},{key:"Mod-Shift-l",run:wt.selectSelectionMatches,preventDefault:!0},{key:"Ctrl-Shift-ArrowUp",run:Z.addCursorAbove,preventDefault:!0},{key:"Ctrl-Shift-ArrowDown",run:Z.addCursorBelow,preventDefault:!0},{key:"Mod-Alt-ArrowUp",run:Z.addCursorAbove,preventDefault:!0},{key:"Mod-Alt-ArrowDown",run:Z.addCursorBelow,preventDefault:!0},{key:"Mod-ArrowUp",run:bn,preventDefault:!0},{key:"Mod-ArrowDown",run:xn,preventDefault:!0},{key:"Alt-Shift-ArrowUp",run:Z.copyLineUp,preventDefault:!0},{key:"Alt-Shift-ArrowDown",run:Z.copyLineDown,preventDefault:!0},{key:"Mod-]",run:me,preventDefault:!0},{key:"Mod-[",run:ue,preventDefault:!0}],F=g.EditorView.domEventHandlers({mousedown(L,D){const G=window.__foldDiag||{};if(G.pendingFold>0||G.pendingUnfold>0){const Q=[];y.foldedRanges(D.state).between(0,D.state.doc.length,(rt,St)=>{Q.push({from:rt,to:St})}),console.warn("[Fold:mousedown] PENDING OPS AT CLICK",{x:L.clientX,y:L.clientY,folds:Q.length,foldRanges:Q.slice(0,5),pending:{...G},docLen:D.state.doc.length})}},blur(L,D){var G;console.log("[Editor] blur",{scrollTop:D.scrollDOM.scrollTop,foldStateKey:r}),(G=q.current)==null||G.call(q)},focus(L,D){console.log("[Editor] focus",{scrollTop:D.scrollDOM.scrollTop,foldStateKey:r})}}),N=ln(),J=R.Prec.high(g.keymap.of([{key:"Mod-^",run:L=>(Dt(L,">> "),!0)}])),Y=R.Prec.highest(g.EditorView.domEventHandlers({keydown(L,D){if(!(L.metaKey||L.ctrlKey)||L.key!=="/")return!1;L.preventDefault(),L.stopPropagation();const Q=D.state.selection;return document.querySelector("[data-command-palette]")?(lt(),D.focus(),!0):(Xe(D,Q),!0)}})),B=R.Prec.highest(g.EditorView.domEventHandlers({keydown(L,D){if((L.metaKey||L.ctrlKey)&&!L.shiftKey&&(L.key==="8"||L.code==="Digit8")){L.preventDefault();const G=D.state.selection.main.head;return D.dispatch({selection:{anchor:G}}),et(D,"*"),!0}return!1}})),U=[ze,F,N,J,Y,B,Z.history(),R.EditorState.allowMultipleSelections.of(!0),g.drawSelection(),y.indentUnit.of(" "),ne({onImagePaste:L=>{var D;return((D=I.current)==null?void 0:D.call(I,L))??Promise.resolve(null)},onGenerateTitle:L=>v.current?v.current(L):Promise.resolve("paste text")}),He,g.keymap.of([yn,...y.foldKeymap,...A,...Z.defaultKeymap,...Z.historyKeymap,{key:"Mod-y",run:Z.redo,preventDefault:!0}]),Gt(n,E,x),Jt,y.codeFolding({placeholderDOM:()=>{const L=document.createElement("span");return L.style.display="none",L}}),nn,on(),sn(),rn(),mn,un,te({}),Ie(),Te({resolveImageUrl:L=>{var D;return((D=M.current)==null?void 0:D.call(M,L))??L}}),...a?[de(h),g.highlightActiveLineGutter()]:[],g.highlightActiveLine(),wt.highlightSelectionMatches(),g.EditorView.updateListener.of(L=>{L.docChanged&&T.current(L.state.doc.toString()),L.transactions.some(D=>ie(D.effects))&&re(r,L.view)}),...C?[R.EditorState.readOnly.of(!0),g.EditorView.editable.of(!1)]:[],...b?[]:[g.EditorView.contentAttributes.of({style:"padding-bottom: calc(100vh - 80px)"})],oe(),se({onImagePaste:L=>{var D;return((D=I.current)==null?void 0:D.call(I,L))??Promise.resolve(null)}}),je({onOpenFile:L=>{var D;return(D=V.current)==null?void 0:D.call(V,L)}}),Be({onOpenFile:L=>{var D;return(D=V.current)==null?void 0:D.call(V,L)}}),Ge({resolveInclude:L=>{var D;return((D=_.current)==null?void 0:D.call(_,L))??Promise.reject("No resolver")},getEmojiShortcuts:()=>z.current??[]}),En({getEmojiShortcuts:()=>z.current??[]}),hn];o&&(U.push(g.EditorView.lineWrapping),U.push(Je));const W=R.EditorState.create({doc:e,extensions:U}),H=new g.EditorView({state:W,parent:p.current});k.current=H,(K=j.current)==null||K.call(j,H);const X=L=>{var D,G;if((D=L.message)!=null&&D.includes("posBefore")||(G=L.message)!=null&&G.includes("Invalid child")){const Q=[];try{y.foldedRanges(H.state).between(0,H.state.doc.length,(rt,St)=>{const pe=H.state.doc.lineAt(rt);Q.push({from:rt,to:St,headerText:pe.text.slice(0,50)})})}catch{}console.error("[Fold:ERROR] posBefore — active folds:",Q,"docLen:",H.state.doc.length)}};return window.addEventListener("error",X),requestAnimationFrame(()=>{ce(r,H),requestAnimationFrame(()=>{const L=P.current;if(L>0){H.scrollDOM.scrollTop=L;const D=H.scrollDOM.scrollTop;console.log("[Editor] scroll restored:",{requested:L,actual:D,scrollHeight:H.scrollDOM.scrollHeight,foldStateKey:r})}})}),()=>{var L;window.removeEventListener("error",X),console.log("[Editor] DESTROYING editor",{foldStateKey:r,scrollTop:H.scrollDOM.scrollTop}),H.destroy(),(L=j.current)==null||L.call(j,null)}},[o,n,r,h,a,b,C,E,x]),O.useEffect(()=>{if(k.current){const A=k.current.state.doc.toString();A!==e&&(console.warn("[MarkdownEditor] External content sync:",{currentLength:A.length,newLength:e.length,foldStateKey:r}),k.current.dispatch({changes:{from:0,to:A.length,insert:e}}))}},[e]),xe.jsx("div",{ref:p,className:"markdown-editor"})}Object.defineProperty(exports,"foldEffect",{enumerable:!0,get:()=>y.foldEffect});Object.defineProperty(exports,"unfoldEffect",{enumerable:!0,get:()=>y.unfoldEffect});exports.BulletWidget=Zt;exports.CollapsibleHeaderWidget=Ee;exports.HiddenWidget=tt;exports.HorizontalRuleWidget=ye;exports.ImageWidget=Qt;exports.MarkdownEditor=he;exports.collapsibleFoldService=Jt;exports.createClipboardKeymap=ne;exports.createDarkTheme=Gt;exports.createImagePasteHandler=se;exports.createMarkdownSyntaxPlugin=te;exports.createWrapSelectionHandler=oe;exports.default=he;exports.hasFoldEffects=ie;exports.loadFoldState=ce;exports.saveFoldState=re;
|
|
24
|
+
//# sourceMappingURL=index.cjs.map
|