838eec30a8
- Implemented a new composable `useTheme` for managing theme state. - Added functions to read and write theme preference to local storage. - Applied theme styles to the DOM based on user preference. - Introduced a toggle function to switch between light and dark themes. refactor: enhance copilot plugin functionality - Improved request handling with sequence and document versioning. - Refactored ghost text handling to improve clarity and efficiency. - Updated markdown insertion logic to handle parsed content more robustly. - Enhanced error handling and logging for better debugging. style: update global styles for light and dark themes - Defined CSS variables for light and dark themes to streamline styling. - Improved overall styling consistency and responsiveness. - Added transitions for smoother theme changes and interactions.
30 lines
21 KiB
JavaScript
30 lines
21 KiB
JavaScript
import{r as D,b as H,o as Lt,e as zt,f as J,g as V,i as h,m as lt,k as Z,n as ut,t as dt,p as Dt,q as Et,v as Ut,x as Rt}from"./vue-6zEhjBZz.js";import{$ as Ot,a as Bt,b as _t,s as gt,p as Pt,C as E,e as U,r as At}from"./milkdown-CXOkeLLP.js";import{a as Ft,P as Nt,p as _,i as $t,l as qt,a5 as Gt,D as jt}from"./prosemirror-n4jms1hu.js";import{_ as Kt}from"./index-BIRQCwFK.js";import"./cm-language-data-Bcb4c2CO.js";import"./cm-language-CDsY7zq0.js";import"./vendor-lezer-common-tVQBIsvN.js";import"./cm-state-X9WpHEQO.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./cm-view-CiSFjroV.js";import"./vendor-style-mod-Bs6eFhZE.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-DuEf3ZFH.js";import"./cm-theme-one-dark-DcoGA4wl.js";import"./cm-commands-BSG2z_PK.js";import"./vendor-codemirror-C9Wn9KcM.js";import"./cm-search-CkNC9fvo.js";import"./cm-autocomplete-t9rzw_D0.js";import"./cm-lint-CJhfB2hN.js";import"./katex-ClxlXyPc.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-lodash-es-XiV8Prow.js";import"./vendor-unified-BIaImg-8.js";import"./vendor-bail-FqpXQuLt.js";import"./vendor-extend-fsBZP_1K.js";import"./vendor-is-plain-obj-C1gvLhAf.js";import"./vendor-trough-B_b8ryxu.js";import"./vendor-vfile-BCWrK60u.js";import"./vendor-vfile-message-DqhD22jI.js";import"./vendor-unist-util-stringify-position-Ch_qCilz.js";import"./vendor-remark-parse-CNDkPE6C.js";import"./vendor-mdast-util-from-markdown-CHHsmDpx.js";import"./vendor-micromark-util-decode-numeric-character-reference-CNs1qBpV.js";import"./vendor-micromark-util-decode-string-fHsnqYdj.js";import"./vendor-decode-named-character-reference-C3-224fz.js";import"./vendor-micromark-util-normalize-identifier-C9ANKk3v.js";import"./vendor-micromark-Dc687xHH.js";import"./vendor-micromark-util-combine-extensions-d8XJZrgA.js";import"./vendor-micromark-util-chunked-DrRIdSP-.js";import"./vendor-micromark-factory-space-BM4zcA-B.js";import"./vendor-micromark-util-character-Cn8n62xE.js";import"./vendor-micromark-core-commonmark-BEN53qso.js";import"./vendor-micromark-util-classify-character-Bc1Mydac.js";import"./vendor-micromark-util-resolve-all-PQCKh0dx.js";import"./vendor-micromark-util-subtokenize-BF1Jf29a.js";import"./vendor-micromark-factory-destination-QK-4WEtY.js";import"./vendor-micromark-factory-label-Bo_B4AwM.js";import"./vendor-micromark-factory-title-D-E2MfTG.js";import"./vendor-micromark-factory-whitespace-D8F2YPRT.js";import"./vendor-micromark-util-html-tag-name-DbKNfynz.js";import"./vendor-mdast-util-to-string-C_aolqmU.js";import"./vendor-remark-stringify-Bsh9PcD8.js";import"./vendor-mdast-util-to-markdown-CJxe-CWN.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-longest-streak-CtXnX3Xp.js";import"./vendor-unist-util-visit-8PRsQcuP.js";import"./vendor-unist-util-visit-parents-BHoKBdZX.js";import"./vendor-unist-util-is-BPZGFiMU.js";import"./vendor-mdast-util-phrasing-4oVbNLC3.js";import"./vendor-remark-inline-links-BH8JVns0.js";import"./vendor-mdast-util-definitions-CBjSIrGZ.js";import"./vendor-remark-gfm-Bh4u6bYx.js";import"./vendor-micromark-extension-gfm-CZUPGk5O.js";import"./vendor-micromark-extension-gfm-autolink-literal-zrBeIzAz.js";import"./vendor-micromark-extension-gfm-footnote-DC8zpk-O.js";import"./vendor-micromark-extension-gfm-strikethrough-r4kRFlAf.js";import"./vendor-micromark-extension-gfm-table-B99Gg4C5.js";import"./vendor-micromark-extension-gfm-task-list-item-BZuxQwYN.js";import"./vendor-mdast-util-gfm-CSyuX27B.js";import"./vendor-mdast-util-gfm-autolink-literal-BQrVEGHY.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-devlop-0Dp3JUBc.js";import"./vendor-mdast-util-find-and-replace-DrvwCOVl.js";import"./vendor-escape-string-regexp-BaJN9MlJ.js";import"./vendor-mdast-util-gfm-footnote-C-csI7OF.js";import"./vendor-mdast-util-gfm-strikethrough-Cj9qKt6Q.js";import"./vendor-mdast-util-gfm-table-H6nfZhjH.js";import"./vendor-markdown-table-DvhhVmnL.js";import"./vendor-mdast-util-gfm-task-list-item-C4T7uo9p.js";import"./vendor-dompurify-HRjpPm7y.js";import"./vendor-floating-ui-dom-Bo_IsNpa.js";import"./vendor-floating-ui-core-B-QvIi8c.js";import"./vendor-floating-ui-utils-CALKnY__.js";import"./vendor-remark-math--xuta7zy.js";import"./vendor-micromark-extension-math-05RmQtyV.js";import"./vendor-mdast-util-math-wB-IJCL0.js";import"./vendor-rope-sequence-nfUW61tr.js";import"./vendor-ocavue-utils-C1mApV17.js";import"./vendor-orderedmap-C4TimWWB.js";const Wt=64*1024,K=new Map;function ft(e,t){K.set(e,t)}function Yt(e){return K.get(e)||""}function Xt(e){K.delete(e)}function Ht(){K.clear()}const Jt=Wt;function Vt(e,t=100){if(!e)return"";const o=e.match(/TEXT:\s*([\s\S]*?)(?:KEY_DETAILS|LANGUAGE|SUMMARY|$)/i);let n=o?o[1].trim():e.trim();return n.toLowerCase()==="(none)"?"":n.length>t?n.substring(0,t)+"...":n}const T=new Ft("milkdown-copilot"),ht=1e3,ot=Jt,Zt=new Set(["image","image-block","imageBlock"]),q={from:0,to:0,suggestion:""},tt=new WeakMap,G=Ot({fetchSuggestion:async()=>"",debounceMs:ht},"copilotConfig"),Qt=Bt("copilot_ghost",()=>({excludes:"",inclusive:!0,parseDOM:[{tag:"span[data-copilot-ghost]"}],toDOM:()=>["span",{"data-copilot-ghost":"",class:"copilot-ghost-text"},0],parseMarkdown:{match:()=>!1,runner:()=>{}},toMarkdown:{match:e=>e.type.name==="copilot_ghost",runner:()=>{}}}));function et(e,t=!0){e.debounceTimer&&(clearTimeout(e.debounceTimer),e.debounceTimer=null),e.abortController&&(e.abortController.abort(),e.abortController=null),t&&(e.requestSeq+=1)}function te(e){const t=e.state.schema.marks.copilot_ghost;if(!t)return null;let o=Number.POSITIVE_INFINITY,n=-1;return e.state.doc.descendants((a,u)=>(a.isText&&a.marks.some(l=>l.type===t)&&(o=Math.min(o,u),n=Math.max(n,u+a.nodeSize)),!0)),!Number.isFinite(o)||n<=o?null:{from:o,to:n}}function B(e){const t=T.getState(e.state);return t&&t.from<t.to?{from:t.from,to:t.to}:te(e)}function N(e){return B(e)!==null}function j(e){const t=B(e);if(!t)return!1;const o=e.state.tr.delete(t.from,t.to).setMeta(T,{...q});return e.dispatch(o),!0}function ee(e){const t=T.getState(e);if(!t||!t.suggestion||t.from>=t.to)return null;const o=Math.max(0,Math.min(t.from,e.doc.content.size)),n=Math.max(o,Math.min(t.to,e.doc.content.size)),a=[];return e.doc.nodesBetween(o,n,(u,l)=>(!u.isBlock||u.nodeSize<=0||a.push($t.node(l,l+u.nodeSize,{class:"copilot-ghost-block"})),!0)),a.length===0?null:qt.create(e.doc,a)}function bt(e,t){const o=e.mapping.map(t,-1);return Math.max(0,Math.min(o,e.doc.content.size))}function oe(e,t,o,n){if(n.content.size<=0)return null;const a=e.mapping.map(o,-1),u=Gt.fromSchema(t).serializeFragment(n.content),l=jt.fromSchema(t).parseSlice(u);if(!l||l.size<=0)return null;e.replaceRange(a,a,l);const p=Math.min(a+l.size,e.doc.content.size);return p<=a?null:{from:a,to:p}}function ne(e,t,o,n){e.doc.nodesBetween(t,o,(a,u)=>(!a.isText||a.nodeSize<=0||e.doc.resolve(u).parent.type.allowsMarkType?.(n)&&e.addMark(u,u+a.nodeSize,n.create()),!0))}function re(e){if(!e)return e;let t=e.replace(/\r\n?/g,`
|
|
`);const o=t.trim();if(o.startsWith('"')&&o.endsWith('"'))try{const n=JSON.parse(o);typeof n=="string"&&(t=n.replace(/\r\n?/g,`
|
|
`))}catch{}return!t.includes(`
|
|
`)&&t.includes("\\n")&&(t=t.replace(/\\n/g,`
|
|
`)),t.includes("\\t")&&(t=t.replace(/\\t/g," ")),t}async function ae(e,t,o,n){if(!t)return;const a=e.state.schema,u=a.marks.copilot_ghost;if(!u){console.error("[Copilot] copilot_ghost mark not found in schema");return}try{const p=await n.get(Pt)(t);if(!p||p.content.size<=0){Q(e,t,o,u);return}const d=e.state.tr,r=oe(d,a,o,p);if(!r){console.warn("[Copilot] parsed markdown insertion failed, falling back to plain text"),Q(e,t,o,u);return}ne(d,r.from,r.to,u),d.setSelection(_.near(d.doc.resolve(bt(d,o)),-1)),d.setMeta(T,{from:r.from,to:r.to,suggestion:t}),e.dispatch(d)}catch(l){console.error("[Copilot] Parser error:",l),Q(e,t,o,u)}}function Q(e,t,o,n){const a=e.state.tr;a.insertText(t,o);const u=o+t.length;a.addMark(o,u,n.create()),a.setSelection(_.near(a.doc.resolve(bt(a,o)),-1)),a.setMeta(T,{from:o,to:u,suggestion:t}),e.dispatch(a)}function yt(e){const t=e.attrs?.src;return typeof t=="string"?t:""}function se(e){return Zt.has(e.type.name)&&!!yt(e)}function ie(e){const t=[e.attrs?.alt,e.attrs?.title,e.attrs?.caption];for(const o of t)if(typeof o=="string"&&o.trim())return o.trim();return"untitled"}function pt(e,t,o,n,a){if(t>=o)return"";const u=e.slice(t,o);if(u.content.size<=0)return"";const l=n.topNodeType.createAndFill(void 0,u.content);return l?a(l):e.textBetween(t,o,`
|
|
`,`
|
|
`)}function ce(e,t){const o=[];return e.nodesBetween(0,t,n=>{if(!se(n))return!0;const a=yt(n),u=Yt(a);if(!u)return!0;const l=Vt(u,100);if(!l)return!0;const p=ie(n);return o.push(` <OCR:${l}>`),!0}),o.length===0?"":`
|
|
|
|
${o.join(`
|
|
`)}`}function le(e,t,o,n,a,u,l){const p=t.ctx.get(G.key);t.abortController&&(t.abortController.abort(),t.abortController=null);const d=new AbortController;t.abortController=d,p.fetchSuggestion(n,a,d.signal).then(r=>{if(!t.enabled||t.requestSeq!==u||t.docVersion!==l||e.state.selection.from!==o||e.state.selection.to!==o)return;const m=re(r);m&&ae(e,m,o,t.ctx)}).catch(r=>{r?.name!=="AbortError"&&console.error("[Copilot] Error:",r)}).finally(()=>{t.abortController===d&&(t.abortController=null)})}function ue(e,t,o){if(!t.enabled)return;const n=e.state.doc,a=e.state.schema;if(n.content.size>ot){$(e,!1);return}const l=t.ctx.get(gt);let p="",d="";try{p=pt(n,0,o,a,l),p||(p=n.textBetween(0,o,`
|
|
`,`
|
|
`)),d=pt(n,o,n.content.size,a,l),d||(d=n.textBetween(o,n.content.size,`
|
|
`,`
|
|
`))}catch(y){console.error("[Copilot] Serializer error:",y),p=n.textBetween(0,o,`
|
|
`,`
|
|
`),d=n.textBetween(o,n.content.size,`
|
|
`,`
|
|
`)}const r=`${p}${ce(n,o)}`;console.log("[Copilot] ===== LLM Request ====="),console.log("[Copilot] PREFIX:",r),console.log("[Copilot] SUFFIX:",d),console.log("[Copilot] ======================"),t.debounceTimer&&(clearTimeout(t.debounceTimer),t.debounceTimer=null);const m=t.ctx.get(G.key).debounceMs??ht,b=t.requestSeq+1;t.requestSeq=b;const L=t.docVersion;t.debounceTimer=setTimeout(()=>{t.debounceTimer=null,le(e,t,o,r,d,b,L)},m)}function F(e){const t=B(e);if(!t)return!1;const o=e.state.tr,n=o.doc,a=t.from,u=t.to,l=e.state.schema.marks.copilot_ghost;if(!l)return!1;n.nodesBetween(a,u,(d,r)=>{d.marks.some(m=>m.type===l)&&o.removeMark(r,r+d.nodeSize,l)});const p=Math.min(u,o.doc.content.size);return o.setSelection(_.near(o.doc.resolve(p))),o.setMeta(T,{...q}),e.dispatch(o),!0}function mt(e){return N(e)?j(e):!1}function de(e){return j(e)}const fe=_t(e=>new Nt({key:T,state:{init:()=>({...q}),apply:(t,o)=>{const n=t.getMeta(T);return n!==void 0?n:t.docChanged&&o.suggestion?{...q}:o}},props:{decorations:t=>ee(t),handleKeyDown:(t,o)=>{const n=N(t);return o.key==="Tab"&&n?(o.preventDefault(),F(t)):o.key==="Escape"&&n?(o.preventDefault(),mt(t)):(n&&o.key!=="Shift"&&o.key!=="Control"&&o.key!=="Alt"&&o.key!=="Meta"&&j(t),!1)},handleClick:(t,o)=>{const n=B(t);return n?o>=n.from&&o<=n.to?F(t):(j(t),!1):!1}},view:t=>{let o=t,n=t.dom;const a={enabled:!0,debounceTimer:null,abortController:null,ctx:e,requestSeq:0,docVersion:0};tt.set(t,a);const u=r=>{if(N(o)){if(r.key==="Tab"){r.preventDefault(),r.stopPropagation(),r.stopImmediatePropagation?.(),F(o);return}r.key==="Escape"&&(r.preventDefault(),r.stopPropagation(),r.stopImmediatePropagation?.(),mt(o))}},l=r=>{if(!N(o))return;const m=r.target instanceof Node?r.target:null,b=m instanceof Element?m:m?.parentElement;b&&(b.closest("[data-copilot-ghost]")||b.closest(".copilot-ghost-block"))&&(r.preventDefault(),r.stopPropagation(),r.stopImmediatePropagation?.(),F(o))},p=r=>{r.addEventListener("keydown",u,!0),r.addEventListener("mousedown",l,!0)},d=r=>{r.removeEventListener("keydown",u,!0),r.removeEventListener("mousedown",l,!0)};return p(n),{update:(r,m)=>{r.dom!==n&&(d(n),n=r.dom,p(n)),o=r;const b=!r.state.doc.eq(m.doc),L=!r.state.selection.eq(m.selection);if(b&&(a.docVersion+=1),!b&&!L)return;const y=B(r);if(y){const{from:z,to:x}=r.state.selection,W=z<y.to&&x>y.from,P=z===x&&z===y.to;if(W&&!P){const Y=Math.min(y.to,r.state.doc.content.size),X=r.state.tr.setSelection(_.near(r.state.doc.resolve(Y),1));r.dispatch(X)}return}const{from:f,to:S}=r.state.selection;if(f!==S){et(a);return}ue(r,a,f)},destroy:()=>{d(n),et(a),tt.delete(t)}}}}));function $(e,t){const o=tt.get(e);o&&(o.enabled=t,t||et(o))}function pe(e){const t=e.state.doc.content.size;return{size:t,overLimit:t>ot}}const O=!1,kt="http://localhost:8000/v1/completions",me=e=>{if(typeof window>"u")return"http://localhost:8000/v1/ocr";try{const t=new URL(e,window.location.origin);return t.pathname="/v1/ocr",t.toString()}catch{return"http://localhost:8000/v1/ocr"}},ge=me(kt);async function he(e,t,o,n=kt){try{const a=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prefix:e,suffix:t,languageId:"markdown"}),signal:o});if(!a.ok){const d=await a.text();throw new Error(`HTTP ${a.status}: ${d}`)}const u=a.body?.getReader();if(!u)throw new Error("No reader available");let l="",p="";for(;;){const{done:d,value:r}=await u.read();if(d)break;p+=new TextDecoder().decode(r);const m=p.split(`
|
|
`);p=m.pop()||"";for(const b of m){if(!b.startsWith("data: "))continue;const L=b.slice(6).trim();if(L)try{const y=JSON.parse(L);if(y.content&&(l+=y.content),y.done||y.error)break}catch{}}}return l}catch(a){throw a.name,a}}const be={class:"editor-container"},ye={class:"action-buttons"},ke={class:"image-btn-wrapper"},ve={key:0,class:"image-dropdown"},we=["disabled","aria-label","title"],Se={class:"btn-tooltip"},Ce={class:"url-dialog"},Me={class:"url-dialog-buttons"},xe={__name:"MilkdownEditor",emits:["update:markdown"],setup(e,{emit:t}){const o=t,n=D(null),a=D(null),u=D(null),l=D(!0),p=D(0),d=D(!1),r=D(!1),m=D(""),b=H(()=>p.value>ot),L=H(()=>Math.floor(p.value/1024)),y=H(()=>b.value?"文档过大,AI已禁用":l.value?"禁用 AI":"启用 AI");let f=null,S=null,z=null;const x=new Set,W=new Set(["image","image-block","imageBlock"]),P=i=>{x.has(i)&&(URL.revokeObjectURL(i),x.delete(i),Xt(i))},Y=i=>{const s=new Set;return i.descendants(c=>{const g=typeof c.attrs?.src=="string"?c.attrs.src:"";W.has(c.type?.name)&&g.startsWith("blob:")&&s.add(g)}),s},X=i=>{const s=Y(i);for(const c of Array.from(x))s.has(c)||P(c)},nt=i=>{const s=i.get(U),{size:c,overLimit:g}=pe(s);p.value=c,g&&l.value&&(l.value=!1,$(s,!1))},rt=()=>{f&&(S&&(clearTimeout(S),S=null),S=setTimeout(async()=>{if(S=null,!!f)try{let i=!1;if(f.editor.action(c=>{const g=c.get(U),k=T.getState(g.state);i=!!(k?.suggestion&&k.from<k.to)}),i)return;const s=await f.getMarkdown();o("update:markdown",s)}catch{}},120))},vt=async()=>{if(f)try{const i=await f.getMarkdown();f.editor.action(s=>{const c=s.get(U),g=c.state.schema,{from:k,to:C}=c.state.selection,w=s.get(gt);let v="",M="";try{const I=c.state.doc.slice(0,k);if(I.content.size>0){const R=g.topNodeType.createAndFill(void 0,I.content);R&&(v=w(R))}v||(v=c.state.doc.textBetween(0,k,`
|
|
`,`
|
|
`));const A=c.state.doc.slice(C);if(A.content.size>0){const R=g.topNodeType.createAndFill(void 0,A.content);R&&(M=w(R))}M||(M=c.state.doc.textBetween(C,c.state.doc.content.size,`
|
|
`,`
|
|
`))}catch(I){console.error("[Debug] Serializer error:",I),v=c.state.doc.textBetween(0,k,`
|
|
`,`
|
|
`),M=c.state.doc.textBetween(C,c.state.doc.content.size,`
|
|
`,`
|
|
`)}console.log("[Debug] ===== Document State ====="),console.log("[Debug] PREFIX:",v),console.log("[Debug] SUFFIX:",M),console.log("[Debug] FULL MARKDOWN:",i),console.log("[Debug] ==========================")})}catch(i){console.error("[Debug] Log failed:",i)}},at=i=>{de(i)},st=async(i,s)=>{if(!l.value)return;const c=new FileReader;c.onload=async()=>{const g=typeof c.result=="string"?c.result:"",k=g.indexOf(",");if(k===-1)return;const C=g.slice(k+1);try{const w=await fetch(ge,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({image:C,filename:i.name,language:"auto"})});if(!w.ok){const M=await w.text();throw new Error(`HTTP ${w.status}: ${M}`)}const v=await w.json();v.text&&(ft(s,v.text),ft(i.name,v.text))}catch(w){console.error("[OCR] Error:",w)}},c.readAsDataURL(i)};Lt(async()=>{if(!n.value)throw new Error("root.value is null");f=new E({root:n.value,defaultValue:`# Welcome to LLM in text
|
|
|
|
Start writing your content here...`,features:{[E.Feature.Latex]:!0,[E.Feature.ImageBlock]:!0,[E.Feature.Table]:!0,[E.Feature.Diagram]:!0,[E.Feature.ListCheck]:!0},featureConfigs:{[E.Feature.Latex]:{katexOptions:{},inlineEditConfirm:"Escape"},[E.Feature.ImageBlock]:{onUpload:i=>{const s=URL.createObjectURL(i);return x.add(s),st(i,s),s}}},config:{showLineNumber:!1}}),f.editor.config(i=>{i.set(G.key,{fetchSuggestion:he,debounceMs:1e3})}),f.editor.use(G),f.editor.use(Qt),f.editor.use(fe),await f.create(),f.on(i=>{i.updated((s,c)=>{X(c),nt(s),rt()})}),f.editor.action(i=>{const s=i.get(U);$(s,l.value),nt(i)}),rt(),z=setInterval(vt,2e4)});const wt=async()=>{if(!f)return;f.editor.action(k=>{const C=k.get(U);at(C)});const i=await f.getMarkdown(),s=new Blob([i],{type:"text/markdown"}),c=URL.createObjectURL(s),g=document.createElement("a");g.href=c,g.download=`document-${Date.now()}.md`,document.body.appendChild(g),g.click(),g.remove(),URL.revokeObjectURL(c)},St=()=>{a.value?.click()},Ct=async i=>{const s=i.target.files?.[0];if(s){try{const c=await s.text();f&&f.editor&&f.editor.action(At(c))}catch(c){console.error("[Error] Upload failed:",c)}i.target.value=""}},Mt=async()=>{b.value||!f||(l.value=!l.value,f.editor.action(i=>{const s=i.get(U);$(s,l.value),l.value||at(s)}))},xt=()=>{d.value=!d.value},It=()=>{d.value=!1,u.value?.click()},it=i=>{!f||!i||f.editor.action(s=>{const c=s.get(U),{state:g}=c,{schema:k}=g,{from:C,to:w}=g.selection,v=k.nodes.image;if(!v)return;const M=v.create({src:i}),I=g.tr.replaceRangeWith(C,w,M),A=Math.min(C+M.nodeSize,I.doc.content.size);I.setSelection(_.near(I.doc.resolve(A),1)),c.dispatch(I.scrollIntoView())})},Tt=async i=>{const s=i.target.files?.[0];if(!s)return;const c=URL.createObjectURL(s);x.add(c),st(s,c),it(c),i.target.value=""},ct=()=>{const i=m.value.trim();i&&(it(i),m.value="",r.value=!1)};return zt(()=>{S&&(clearTimeout(S),S=null),z&&(clearInterval(z),z=null);for(const i of Array.from(x))P(i);Ht(),f&&(f.destroy(),f=null)}),(i,s)=>(V(),J("div",be,[h("div",{ref_key:"root",ref:n,class:"milkdown-editor"},null,512),h("div",ye,[h("button",{type:"button",class:"action-btn","aria-label":"导入 Markdown 文件",title:"导入 Markdown",onClick:St},[...s[4]||(s[4]=[Z('<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" data-v-f15fa1a6><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" data-v-f15fa1a6></path><polyline points="17 8 12 3 7 8" data-v-f15fa1a6></polyline><line x1="12" y1="3" x2="12" y2="15" data-v-f15fa1a6></line></svg><span class="btn-tooltip" data-v-f15fa1a6>导入 Markdown</span>',2)])]),h("input",{type:"file",ref_key:"fileInputRef",ref:a,onChange:Ct,accept:".md",style:{display:"none"}},null,544),h("button",{type:"button",class:"action-btn","aria-label":"导出 Markdown 文件",title:"导出 Markdown",onClick:wt},[...s[5]||(s[5]=[Z('<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" data-v-f15fa1a6><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" data-v-f15fa1a6></path><polyline points="7 10 12 15 17 10" data-v-f15fa1a6></polyline><line x1="12" y1="15" x2="12" y2="3" data-v-f15fa1a6></line></svg><span class="btn-tooltip" data-v-f15fa1a6>导出 Markdown</span>',2)])]),h("div",ke,[h("button",{type:"button",class:"action-btn","aria-label":"Insert Image",title:"Insert Image",onClick:xt},[...s[6]||(s[6]=[Z('<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" data-v-f15fa1a6><rect x="3" y="3" width="18" height="18" rx="2" ry="2" data-v-f15fa1a6></rect><circle cx="8.5" cy="8.5" r="1.5" data-v-f15fa1a6></circle><polyline points="21 15 16 10 5 21" data-v-f15fa1a6></polyline></svg><span class="btn-tooltip" data-v-f15fa1a6>Insert Image</span>',2)])]),d.value?(V(),J("div",ve,[h("button",{type:"button",onClick:It},"Upload Local Image"),h("button",{type:"button",onClick:s[0]||(s[0]=c=>{r.value=!0,d.value=!1})},"Insert from URL")])):lt("",!0)]),h("input",{type:"file",ref_key:"imageInputRef",ref:u,onChange:Tt,accept:"image/*",style:{display:"none"}},null,544),h("button",{type:"button",class:ut(["action-btn ai-toggle",{"ai-disabled":!l.value,"force-disabled":b.value}]),onClick:Mt,disabled:b.value,"aria-label":y.value,title:y.value},[s[7]||(s[7]=h("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[h("path",{d:"M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2z"}),h("path",{d:"M12 6v6l4 2"})],-1)),h("span",Se,dt(y.value),1)],10,we),h("div",{class:ut(["size-indicator",{"over-limit":b.value}]),"aria-live":"polite"},dt(L.value)+" KB ",3)]),r.value?(V(),J("div",{key:0,class:"url-dialog-overlay",onClick:s[3]||(s[3]=Dt(c=>r.value=!1,["self"]))},[h("div",Ce,[s[8]||(s[8]=h("h3",null,"Insert Image from URL",-1)),Et(h("input",{"onUpdate:modelValue":s[1]||(s[1]=c=>m.value=c),type:"url",placeholder:"Enter image URL",onKeyup:Rt(ct,["enter"])},null,544),[[Ut,m.value]]),h("div",Me,[h("button",{type:"button",class:"dialog-btn primary",onClick:ct},"Insert"),h("button",{type:"button",class:"dialog-btn",onClick:s[2]||(s[2]=c=>{r.value=!1,m.value=""})},"Cancel")])])])):lt("",!0)]))}},un=Kt(xe,[["__scopeId","data-v-f15fa1a6"]]);export{un as default};
|