@fgbg/mdocs 0.8.18 → 0.8.19

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.
Files changed (26) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +7 -1
  3. package/agent-skills/index.json +1 -1
  4. package/dist/web/assets/{AgentChatPanel-DHy3KgSW.js → AgentChatPanel-CLKeiDeR.js} +1 -1
  5. package/dist/web/assets/{AiWriteWorkbench-Ce_OaED4.js → AiWriteWorkbench-Ecp214S5.js} +1 -1
  6. package/dist/web/assets/DiagramEditor-BTRe45TX-DzJEhM4C.js +2 -0
  7. package/dist/web/assets/{DocumentEditor-B2H3rHSg.js → DocumentEditor-NPbbAape.js} +1 -1
  8. package/dist/web/assets/{MergeView-Cy4Pi3Je.js → MergeView-BnWbq08U.js} +1 -1
  9. package/dist/web/assets/{PlaygroundPage-hHfIzPO5.js → PlaygroundPage-BSGipUkC.js} +1 -1
  10. package/dist/web/assets/{SettingsPage-BRAPdqW9.js → SettingsPage-OklrFCx7.js} +1 -1
  11. package/dist/web/assets/{Toolbar-DPkTtGNL.js → Toolbar-DjPuWk5G.js} +1 -1
  12. package/dist/web/assets/{VisitorPickerModal-CJ0K2gj8.js → VisitorPickerModal-BUS-cOq0.js} +1 -1
  13. package/dist/web/assets/{copy-DCKasK29.js → copy-hWOco_4c.js} +1 -1
  14. package/dist/web/assets/{diagram-BJFhx-27.js → diagram-gfUK8OHx.js} +332 -332
  15. package/dist/web/assets/{editor-BBXgdU3Q.js → editor-ONzd_YnO.js} +1 -1
  16. package/dist/web/assets/{history-BQkmetJ0.js → history-AMIEbyMc.js} +1 -1
  17. package/dist/web/assets/{index-CA7lpALZ.js → index-C46BU1-j.js} +3 -3
  18. package/dist/web/assets/meta2d-C8Z4cn-d.js +110 -0
  19. package/dist/web/assets/meta2dEngine-BD2XbzaV-D7hJ1H1g.js +1 -0
  20. package/dist/web/assets/{motion-D-I76zAi.js → motion-C4pN8CfU.js} +1 -1
  21. package/dist/web/assets/{plus-B2rZTPWV.js → plus-CnKbiP8x.js} +1 -1
  22. package/dist/web/assets/react-B7vrA7AR.js +2126 -0
  23. package/dist/web/assets/{ui-C3xtW1w8.js → ui-DxdLi_28.js} +3 -3
  24. package/dist/web/index.html +3 -3
  25. package/package.json +2 -2
  26. package/dist/web/assets/react-CQByW0Rg.js +0 -2236
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DocumentEditor-B2H3rHSg.js","assets/react-vendor-BNpqFP9B.js","assets/ui-C3xtW1w8.js","assets/motion-D-I76zAi.js","assets/react-CQByW0Rg.js","assets/editor-BBXgdU3Q.js","assets/diagram-BJFhx-27.js","assets/plus-B2rZTPWV.js","assets/copy-DCKasK29.js","assets/Toolbar-DPkTtGNL.js","assets/VisitorPickerModal-CJ0K2gj8.js","assets/SettingsPage-BRAPdqW9.js","assets/AgentChatPanel-DHy3KgSW.js","assets/history-BQkmetJ0.js","assets/AiWriteWorkbench-Ce_OaED4.js","assets/MergeView-Cy4Pi3Je.js","assets/PlaygroundPage-hHfIzPO5.js"])))=>i.map(i=>d[i]);
2
- var Vn=Object.defineProperty;var Wn=(e,t,i)=>t in e?Vn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var Ie=(e,t,i)=>Wn(e,typeof t!="symbol"?t+"":t,i);import{r as a,j as n,_ as Ce,a9 as zn,aa as qn,ab as Gn,ac as it,c as Yn,R as Jn,ad as Kn}from"./react-vendor-BNpqFP9B.js";import{C as Xn,T as Qn}from"./ui-C3xtW1w8.js";import{f as Zn}from"./motion-D-I76zAi.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const d of s)if(d.type==="childList")for(const l of d.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function i(s){const d={};return s.integrity&&(d.integrity=s.integrity),s.referrerPolicy&&(d.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?d.credentials="include":s.crossOrigin==="anonymous"?d.credentials="omit":d.credentials="same-origin",d}function r(s){if(s.ep)return;s.ep=!0;const d=i(s);fetch(s.href,d)}})();/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DocumentEditor-NPbbAape.js","assets/react-vendor-BNpqFP9B.js","assets/ui-DxdLi_28.js","assets/motion-C4pN8CfU.js","assets/react-B7vrA7AR.js","assets/editor-ONzd_YnO.js","assets/diagram-gfUK8OHx.js","assets/plus-CnKbiP8x.js","assets/copy-hWOco_4c.js","assets/Toolbar-DjPuWk5G.js","assets/VisitorPickerModal-BUS-cOq0.js","assets/SettingsPage-OklrFCx7.js","assets/AgentChatPanel-CLKeiDeR.js","assets/history-AMIEbyMc.js","assets/AiWriteWorkbench-Ecp214S5.js","assets/MergeView-BnWbq08U.js","assets/PlaygroundPage-BSGipUkC.js"])))=>i.map(i=>d[i]);
2
+ var Vn=Object.defineProperty;var Wn=(e,t,i)=>t in e?Vn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var Ie=(e,t,i)=>Wn(e,typeof t!="symbol"?t+"":t,i);import{r as a,j as n,_ as Ce,a9 as zn,aa as qn,ab as Gn,ac as it,c as Yn,R as Jn,ad as Kn}from"./react-vendor-BNpqFP9B.js";import{C as Xn,T as Qn}from"./ui-DxdLi_28.js";import{f as Zn}from"./motion-C4pN8CfU.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const d of s)if(d.type==="childList")for(const l of d.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function i(s){const d={};return s.integrity&&(d.integrity=s.integrity),s.referrerPolicy&&(d.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?d.credentials="include":s.crossOrigin==="anonymous"?d.credentials="omit":d.credentials="same-origin",d}function r(s){if(s.ep)return;s.ep=!0;const d=i(s);fetch(s.href,d)}})();/**
3
3
  * @license lucide-react v0.562.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -182,4 +182,4 @@ Demo 模式的核心设计:
182
182
  3. 用户无感知切换
183
183
 
184
184
  `,Yi=[{documentId:"doc-welcome",relativePath:"README.md",displayName:"README",content:Ut,contentHash:We(Ut),permission:1,ownerVisitorId:ne,domainId:"default",updatedBy:ne,updatedAt:new Date().toISOString(),createdAt:new Date().toISOString(),fileType:"md",parentId:null},{documentId:"doc-markdown-guide",relativePath:"指南/Markdown 语法.md",displayName:"Markdown 语法",content:Vt,contentHash:We(Vt),permission:1,ownerVisitorId:ne,domainId:"default",updatedBy:ne,updatedAt:new Date().toISOString(),createdAt:new Date().toISOString(),fileType:"md",parentId:null},{documentId:"doc-diagram-guide",relativePath:"指南/图表支持.md",displayName:"图表支持",content:Wt,contentHash:We(Wt),permission:1,ownerVisitorId:ne,domainId:"default",updatedBy:ne,updatedAt:new Date().toISOString(),createdAt:new Date().toISOString(),fileType:"md",parentId:null},{documentId:"doc-personal-note",relativePath:"个人笔记.md",displayName:"个人笔记",content:zt,contentHash:We(zt),permission:0,ownerVisitorId:ne,domainId:ne,updatedBy:ne,updatedAt:new Date().toISOString(),createdAt:new Date().toISOString(),fileType:"md",parentId:null}];const ht="mdocs.visitorId",ut="mdocs-api-error";function Lo(e){typeof window>"u"||window.dispatchEvent(new CustomEvent(ut,{detail:{status:e.status,code:e.code,message:e.message}}))}function rn(){return!1}function Ji(){return window.localStorage.getItem(ht)}function qe(e){window.localStorage.setItem(ht,e)}function Fo(){window.localStorage.removeItem(ht)}async function x(e,t={}){try{rn();const i=new Headers(t.headers);!i.has("Content-Type")&&t.body&&i.set("Content-Type","application/json");const r=await fetch(e,{...t,headers:i});if(r.status===204)return;const s=await r.text();let d;try{d=s?JSON.parse(s):null}catch{throw new oe(r.status,"BAD_RESPONSE","response is not valid JSON")}if(!r.ok){const l=d==null?void 0:d.error;throw new oe(r.status,(l==null?void 0:l.code)??"UNKNOWN",(l==null?void 0:l.message)??"request failed",l==null?void 0:l.details)}return d.data}catch(i){throw i instanceof oe&&Lo(i),i}}const Ge="default",Ki=["public","restricted","private"];function Xi(e){return e===Ge}function Qi(e,t){return t!==null&&e.creatorVisitorId===t}function Zi(e){return e.docCount>0}function _o(e,t){return x("/api/visitors/register",{method:"POST",body:JSON.stringify({visitorName:e,password:t})})}function Bo(e){return x("/api/visitors/recover",{method:"POST",body:JSON.stringify({recoveryCode:e})})}function $o(e,t){return x("/api/visitors/login",{method:"POST",body:JSON.stringify({visitorName:e,password:t})})}function er(e){return x("/api/visitors/set-password",{method:"POST",body:JSON.stringify({password:e})})}function tr(){return x("/api/visitors/recovery-code",{method:"POST"})}async function qt(){return(await x("/api/visitors/me")).visitor}function nr(){return x("/api/visitors").then(e=>e.visitors)}function Ho(){return x("/api/domains")}function or(e){return x("/api/domains",{method:"POST",body:JSON.stringify(e)})}function ir(e,t){return x(`/api/domains/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify({domainName:t})})}function rr(e,t){return x(`/api/domains/${encodeURIComponent(e)}/permission`,{method:"PUT",body:JSON.stringify({permission:t})})}function ar(e){return x(`/api/domains/${encodeURIComponent(e)}`,{method:"DELETE"})}function sr(e){return x(`/api/domains/${encodeURIComponent(e)}/members`).then(t=>t.members)}function dr(e,t){return x(`/api/domains/${encodeURIComponent(e)}/members`,{method:"PUT",body:JSON.stringify({visitorIds:t})})}function cr(){return x("/api/domain-member-templates")}function lr(e){return x("/api/domain-member-templates",{method:"POST",body:JSON.stringify(e)})}function mr(e,t){return x(`/api/domain-member-templates/${encodeURIComponent(String(e))}`,{method:"PUT",body:JSON.stringify(t)})}function ur(e){return x(`/api/domain-member-templates/${encodeURIComponent(String(e))}`,{method:"DELETE"})}function Uo(e){const t=e!=null&&e.trim()?`?domainId=${encodeURIComponent(e.trim())}`:"";return x(`/api/tree${t}`)}function Me(e){return x(`/api/documents/${encodeURIComponent(e)}`)}function an(e){return x("/api/documents",{method:"POST",body:JSON.stringify(e)})}function Gt(e,t){return x(`/api/documents/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify(t)})}function Vo(e,t){const i=t?`?localBaseCommitId=${encodeURIComponent(t)}`:"";return x(`/api/documents/${encodeURIComponent(e)}/sync-status${i}`)}function fr(e,t,i){const r=new URLSearchParams({localBaseCommitId:t,remoteCommitId:i});return x(`/api/documents/${encodeURIComponent(e)}/merge-context?${r}`)}function rt(e){return x("/api/documents/convert",{method:"POST",body:JSON.stringify(e)})}function Wo(e){return x(`/api/documents/${encodeURIComponent(e)}`,{method:"DELETE"})}function zo(e,t){return x(`/api/documents/${encodeURIComponent(e)}/move`,{method:"POST",body:JSON.stringify({parentId:t})})}function pr(e){return x(`/api/documents/${encodeURIComponent(e)}/invites`)}function hr(e,t,i){return x(`/api/documents/${encodeURIComponent(e)}/invites`,{method:"POST",body:JSON.stringify({targetVisitorId:t,targetPermission:i})})}function gr(e,t){return x(`/api/documents/${encodeURIComponent(e)}/invites/${encodeURIComponent(t)}`,{method:"DELETE"})}async function yr(e,t){var m;const i=new FormData;i.append("file[]",e),i.append("documentId",t);const r=new Headers,s=await fetch("/api/assets/upload",{method:"POST",headers:r,body:i}),d=await s.json(),l=d;if(!s.ok||l.code===1){const g=d==null?void 0:d.error;throw new oe(s.status,(g==null?void 0:g.code)??"UPLOAD_FAILED",(g==null?void 0:g.message)??l.msg??"upload failed")}const p=((m=l.data)==null?void 0:m.succMap)??{},h=Object.values(p);if(h.length===0)throw new Error("upload succeeded but no URL returned");return h[0]}function qo(e){return x("/api/folders",{method:"POST",body:JSON.stringify(e)})}function Go(e){return x(`/api/documents/folder/${encodeURIComponent(e)}`,{method:"DELETE"})}function vr(e){return x("/api/cli/tokens",{method:"POST",body:JSON.stringify({})})}function br(){return x("/api/cli/tokens")}function Yo(){return x("/api/bookmarks")}function wr(e){return x(`/api/bookmarks/${encodeURIComponent(e)}`)}function xr(e){return x(`/api/bookmarks/${encodeURIComponent(e)}`,{method:"POST"})}function Jo(e){return x(`/api/bookmarks/${encodeURIComponent(e)}`,{method:"DELETE"})}function Ir(){return x("/api/visitors/me/documents")}function Ko(e){return x(`/api/documents/${encodeURIComponent(e)}/comments`)}function Xo(e,t){return x(`/api/documents/${encodeURIComponent(e)}/comments`,{method:"POST",body:JSON.stringify(t)})}function Qo(e,t){return x(`/api/documents/${encodeURIComponent(e)}/comments/${encodeURIComponent(t)}`,{method:"DELETE"})}function Dr(){return x("/api/agent/config")}function Cr(e){return x("/api/agent/config",{method:"PUT",body:JSON.stringify(e)})}function Sr(){return x("/api/agent/status")}function kr(){return x("/api/agent/context-usage")}function Nr(e="normal",t){const i=new URLSearchParams;e==="coding"&&(i.set("mode","coding"),t&&i.set("documentId",t));const r=i.toString();return x(`/api/agent/session${r?`?${r}`:""}`)}function Pr(e="normal",t){const i=new URLSearchParams;e==="coding"&&(i.set("mode","coding"),t&&i.set("documentId",t));const r=i.toString();return x(`/api/agent/sessions${r?`?${r}`:""}`)}function Tr(e="normal",t){return x("/api/agent/sessions",{method:"POST",body:JSON.stringify({mode:e,...e==="coding"?{documentId:t??null}:{}})})}function Er(e,t="normal",i){return x("/api/agent/session/open",{method:"POST",body:JSON.stringify({sessionId:e,mode:t,...t==="coding"?{documentId:i??null}:{}})})}function Ar(e,t){return x("/api/agent/session/bind-document",{method:"POST",body:JSON.stringify({sessionId:e,documentId:t})})}function jr(e,t){return x("/api/agent/choice",{method:"POST",body:JSON.stringify({requestId:e,choice:t})})}function Mr(e){return x("/api/agent/choice",{method:"POST",body:JSON.stringify({requestId:e,expire:!0})})}async function Rr(e,t){var h;const i={message:e,mode:t.mode==="coding"?"coding":"normal"};t.mode==="coding"&&(t.documentId!==void 0&&(i.documentId=t.documentId),typeof t.workingMarkdown=="string"&&(i.workingMarkdown=t.workingMarkdown),typeof t.baseMarkdown=="string"&&(i.baseMarkdown=t.baseMarkdown));const r=await fetch("/api/agent/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i),signal:t.signal});if(!r.ok){let m=`HTTP ${r.status}`;try{const g=await r.json();(h=g.error)!=null&&h.message&&(m=g.error.message)}catch{}throw new Error(m)}if(!r.body)throw new Error("empty response body");const s=r.body.getReader(),d=new TextDecoder;let l="";for(;;){const{done:m,value:g}=await s.read();if(m)break;l+=d.decode(g,{stream:!0});const k=l.split(`
185
- `);l=k.pop()??"";for(const v of k){const C=v.trim();if(!C.startsWith("data:"))continue;const E=C.slice(5).trim();if(!(!E||E==="[DONE]"))try{t.onEvent(JSON.parse(E))}catch{}}}const p=l.trim();if(p.startsWith("data:")){const m=p.slice(5).trim();if(m&&m!=="[DONE]")try{t.onEvent(JSON.parse(m))}catch{}}}const Zo={domainId:Ge,domainName:"Default",permission:"public",creatorVisitorId:"",docCount:0};async function sn(){try{return await Ho()}catch{return[Zo]}}function ei(e,t){var i,r,s;return((i=e.find(d=>d.domainId===t))==null?void 0:i.domainId)??((r=e.find(d=>d.domainId===Ge))==null?void 0:r.domainId)??((s=e[0])==null?void 0:s.domainId)??Ge}function ti(e){const{t}=de(),[i,r]=a.useState(!1),[s,d]=a.useState(null),[l,p]=a.useState("register"),[h,m]=a.useState(1),[g,k]=a.useState(""),[v,C]=a.useState(""),[E,$]=a.useState("password"),[y,I]=a.useState(""),[b,A]=a.useState(""),[P,T]=a.useState("");function _(N){if(N.preventDefault(),!g.trim()){d(t("nameRequired"));return}d(null),m(2)}async function F(N){N.preventDefault(),r(!0),d(null);try{const M=v.trim();await e.onSubmit(g.trim(),M||void 0)}catch(M){d(M instanceof Error?M.message:String(M)),m(1)}finally{r(!1)}}async function H(N){N.preventDefault();const M=y.trim(),O=b.trim();if(!M||!O){d("请输入用户名和密码");return}r(!0),d(null);try{const J=await $o(M,O);qe(J.visitor.visitorId),await e.onRecover(J.visitor.visitorId)}catch(J){d(J instanceof Error?J.message:String(J))}finally{r(!1)}}async function Y(N){N.preventDefault();const M=P.trim();if(!M){d("请输入恢复码");return}r(!0),d(null);try{const O=await Bo(M);qe(O.visitor.visitorId),await e.onRecover(O.visitor.visitorId)}catch(O){d(O instanceof Error?O.message:String(O))}finally{r(!1)}}const R=s??e.error;function u(N){d(null),p(N)}return n.jsx("div",{className:"mdocs-dialog-backdrop",children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:420},children:[n.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--mdocs-border)",marginBottom:16},children:[n.jsx("button",{type:"button",onClick:()=>u("register"),style:{flex:1,padding:"12px",border:"none",background:l==="register"?"var(--mdocs-bg)":"none",color:l==="register"?"var(--mdocs-text)":"var(--mdocs-text-secondary)",cursor:"pointer",fontWeight:l==="register"?600:400,borderBottom:l==="register"?"2px solid var(--mdocs-accent)":"none"},children:"注册"}),n.jsx("button",{type:"button",onClick:()=>u("login"),style:{flex:1,padding:"12px",border:"none",background:l==="login"?"var(--mdocs-bg)":"none",color:l==="login"?"var(--mdocs-text)":"var(--mdocs-text-secondary)",cursor:"pointer",fontWeight:l==="login"?600:400,borderBottom:l==="login"?"2px solid var(--mdocs-accent)":"none"},children:"登录"})]}),l==="register"&&n.jsx(n.Fragment,{children:h===1?n.jsxs(n.Fragment,{children:[n.jsx("h1",{children:t("welcomeTitle")}),n.jsx("p",{children:t("welcomeDesc")}),n.jsxs("form",{onSubmit:_,children:[n.jsx("input",{autoFocus:!0,placeholder:t("visitorNamePlaceholder"),value:g,onChange:N=>k(N.target.value),maxLength:60}),R&&n.jsx("div",{className:"mdocs-dialog-error",children:R}),n.jsx("button",{type:"submit",className:"primary",disabled:i,children:"下一步"})]}),n.jsx("p",{style:{marginTop:16,textAlign:"center"},children:n.jsx("button",{type:"button",style:{background:"none",border:"none",color:"var(--mdocs-accent)",cursor:"pointer",fontSize:"0.875rem",textDecoration:"underline",padding:0},onClick:()=>u("login"),children:"已有账号?点击登录"})})]}):n.jsxs(n.Fragment,{children:[n.jsx("h1",{children:"设置密码(可选)"}),n.jsx("p",{style:{marginBottom:8},children:"设置密码后,你可以在其他浏览器或设备上使用「用户名+密码」登录。"}),n.jsx("p",{style:{color:"var(--mdocs-text-secondary)",fontSize:"0.875rem",marginBottom:16},children:"留空不设置密码也能正常使用,但只能在当前浏览器操作。"}),n.jsxs("form",{onSubmit:F,children:[n.jsx("input",{autoFocus:!0,type:"password",placeholder:"设置密码(至少 4 位)",value:v,onChange:N=>C(N.target.value),minLength:4}),R&&n.jsx("div",{className:"mdocs-dialog-error",children:R}),n.jsx("button",{type:"submit",className:"primary",disabled:i,style:{marginTop:8},children:i?t("creating"):"完成注册"})]}),n.jsx("p",{style:{marginTop:16,textAlign:"center"},children:n.jsx("button",{type:"button",style:{background:"none",border:"none",color:"var(--mdocs-text-secondary)",cursor:"pointer",fontSize:"0.875rem",padding:0},onClick:()=>m(1),children:"← 返回上一步"})})]})}),l==="login"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16,marginBottom:16,fontSize:"0.875rem"},children:[n.jsx("button",{type:"button",onClick:()=>{d(null),$("password")},style:{background:"none",border:"none",color:E==="password"?"var(--mdocs-accent)":"var(--mdocs-text-secondary)",cursor:"pointer",padding:"4px 0",borderBottom:E==="password"?"2px solid var(--mdocs-accent)":"none",fontWeight:E==="password"?600:400},children:"用户名+密码"}),n.jsx("button",{type:"button",onClick:()=>{d(null),$("recovery")},style:{background:"none",border:"none",color:E==="recovery"?"var(--mdocs-accent)":"var(--mdocs-text-secondary)",cursor:"pointer",padding:"4px 0",borderBottom:E==="recovery"?"2px solid var(--mdocs-accent)":"none",fontWeight:E==="recovery"?600:400},children:"恢复码"})]}),E==="password"?n.jsxs(n.Fragment,{children:[n.jsx("h1",{children:"🔑 使用密码登录"}),n.jsx("p",{children:"输入用户名和密码,在其他设备上找回你的身份。"}),n.jsxs("form",{onSubmit:H,children:[n.jsx("input",{autoFocus:!0,placeholder:"用户名",value:y,onChange:N=>I(N.target.value),maxLength:60,style:{marginBottom:8}}),n.jsx("input",{type:"password",placeholder:"密码",value:b,onChange:N=>A(N.target.value)}),R&&n.jsx("div",{className:"mdocs-dialog-error",children:R}),n.jsx("button",{type:"submit",className:"primary",disabled:i,children:i?"验证中…":"登录"})]}),n.jsx("p",{style:{marginTop:16,textAlign:"center"},children:n.jsx("button",{type:"button",style:{background:"none",border:"none",color:"var(--mdocs-accent)",cursor:"pointer",fontSize:"0.875rem",textDecoration:"underline",padding:0},onClick:()=>u("register"),children:"没有账号?去注册"})})]}):n.jsxs(n.Fragment,{children:[n.jsx("h1",{children:"🔑 使用恢复码找回"}),n.jsx("p",{children:"输入注册时保存的恢复码,系统将为您生成新的身份令牌。"}),n.jsxs("form",{onSubmit:Y,children:[n.jsx("input",{autoFocus:!0,placeholder:"ABCD-EFGH-IJKL-MNOP",value:P,onChange:N=>T(N.target.value),style:{fontFamily:"monospace",letterSpacing:"0.1em"},maxLength:30}),R&&n.jsx("div",{className:"mdocs-dialog-error",children:R}),n.jsx("button",{type:"submit",className:"primary",disabled:i,children:i?"验证中…":"找回身份"})]})]})]})]})})}function ni(e){const{t}=de();return n.jsxs("div",{className:"mdocs-notice card",children:[n.jsx("span",{children:t("visitorIdNotice",{id:e.visitorId})}),n.jsx("button",{type:"button",onClick:e.onDismiss,children:t("gotIt")})]})}const dn="application/x-mdocs-document-id",ft="mdocs-doc:";let ve=null;function cn(e,t,i=[]){for(const r of e){if(r.type==="document"){if(r.documentId===t)return{forceOpenFolderIds:i,scrollTreeId:r.documentId};continue}if(r.descDocumentId===t)return{forceOpenFolderIds:i,scrollTreeId:r.documentId};const s=cn(r.children,t,[...i,r.documentId]);if(s)return s}return null}function gt(e){if(ve)return ve;try{const t=e.getData(dn);if(t)return t;const i=e.getData("text/plain")||e.getData("Text");if(i.startsWith(ft))return i.slice(ft.length)}catch{}return""}function ue(e){return!!(e&&ve)}function oi(e){const{t}=de(),i=a.useRef(null),[r,s]=a.useState(null),[d,l]=a.useState(null),p=a.useMemo(()=>{var I;const y=(I=e.activeDocumentId)==null?void 0:I.trim();return y?cn(e.nodes,y):null},[e.nodes,e.activeDocumentId]),h=a.useMemo(()=>new Set((p==null?void 0:p.forceOpenFolderIds)??[]),[p]);a.useEffect(()=>{if(!(p!=null&&p.scrollTreeId))return;const y=p.scrollTreeId,I=()=>{var P;const A=(P=i.current)==null?void 0:P.querySelector(`[data-tree-id="${CSS.escape(y)}"]`);A==null||A.scrollIntoView({block:"nearest",behavior:"smooth"})},b=requestAnimationFrame(()=>{requestAnimationFrame(I)});return()=>cancelAnimationFrame(b)},[p==null?void 0:p.scrollTreeId,h,e.nodes]);function m(){s(null)}function g(){ve=null,l(null),m()}function k(y){ve=y,l(y),m()}function v(y){if(!ue(e.onMoveDocument))return;y.preventDefault(),y.dataTransfer.dropEffect="move",y.target.closest(".mdocs-tree-row")||s({kind:"root"})}function C(y){const I=y.relatedTarget;I&&y.currentTarget.contains(I)||s(b=>(b==null?void 0:b.kind)==="root"?null:b)}function E(y){if(!e.onMoveDocument||!ue(e.onMoveDocument))return;y.preventDefault(),y.stopPropagation();const b=y.target.closest(".mdocs-tree-row"),A=gt(y.dataTransfer);g(),!b&&A&&e.onMoveDocument(A,null)}const $="mdocs-sidebar-list"+((r==null?void 0:r.kind)==="root"?" mdocs-tree-drop-root":"");return e.nodes.length===0?n.jsx("div",{ref:i,className:$,onDragOver:v,onDragLeave:C,onDrop:E,children:n.jsx("div",{className:"muted",style:{padding:"8px 10px",fontSize:12},children:t("noDocumentsYet")})}):n.jsx("div",{ref:i,className:$,onClick:y=>{var b;y.target.closest(".mdocs-tree-row")||(b=e.onDeselect)==null||b.call(e)},onContextMenu:y=>{y.preventDefault(),e.onContextMenu({x:y.clientX,y:y.clientY,node:{type:"folder",name:"",path:"",documentId:"",children:e.nodes},parentPath:""})},onDragOver:v,onDragLeave:C,onDrop:E,children:e.nodes.map(y=>n.jsx(ln,{node:y,depth:0,parentPath:"",parentFolderId:null,activeDocumentId:e.activeDocumentId,selectedParentPath:e.selectedParentPath,forceOpenFolderIds:h,dropHighlight:r,setDropHighlight:s,clearDropHighlight:m,beginDragSession:k,endDragSession:g,draggingId:d,onOpen:e.onOpen,onOpenFolder:e.onOpenFolder,onContextMenu:e.onContextMenu,onMoveDocument:e.onMoveDocument},y.path))})}function ln(e){const t={paddingLeft:8+e.depth*16};return e.node.type==="folder"?n.jsx(ai,{folder:e.node,depth:e.depth,indent:t,activeDocumentId:e.activeDocumentId,selectedParentPath:e.selectedParentPath,forceOpenFolderIds:e.forceOpenFolderIds,dropHighlight:e.dropHighlight,setDropHighlight:e.setDropHighlight,clearDropHighlight:e.clearDropHighlight,beginDragSession:e.beginDragSession,endDragSession:e.endDragSession,draggingId:e.draggingId,onOpen:e.onOpen,onOpenFolder:e.onOpenFolder,onContextMenu:e.onContextMenu,onMoveDocument:e.onMoveDocument}):n.jsx(ii,{doc:e.node,indent:t,parentPath:e.parentPath,parentFolderId:e.parentFolderId,activeDocumentId:e.activeDocumentId,dropHighlight:e.dropHighlight,setDropHighlight:e.setDropHighlight,clearDropHighlight:e.clearDropHighlight,beginDragSession:e.beginDragSession,endDragSession:e.endDragSession,draggingId:e.draggingId,onOpen:e.onOpen,onContextMenu:e.onContextMenu,onMoveDocument:e.onMoveDocument})}function ii(e){var h;const t=e.doc,i=t.documentId===e.activeDocumentId,r=!!e.onMoveDocument,s=e.draggingId===t.documentId,d=((h=e.dropHighlight)==null?void 0:h.kind)==="doc"&&e.dropHighlight.id===t.documentId,[l,p]=a.useState(!1);return n.jsxs("div",{role:"button",tabIndex:0,className:"mdocs-tree-row mdocs-tree-doc"+(i?" active":"")+(s?" mdocs-tree-dragging":"")+(d?" mdocs-tree-drop-target":""),"data-tree-id":t.documentId,style:{...e.indent,cursor:r?"grab":void 0},draggable:r,onDragStart:m=>{e.onMoveDocument&&(p(!0),e.beginDragSession(t.documentId),m.dataTransfer.setData(dn,t.documentId),m.dataTransfer.setData("text/plain",ft+t.documentId),m.dataTransfer.effectAllowed="move")},onDragEnd:()=>{e.endDragSession(),queueMicrotask(()=>p(!1))},onDragEnter:m=>{!ue(e.onMoveDocument)||ve===t.documentId||(m.preventDefault(),m.stopPropagation(),e.setDropHighlight({kind:"doc",id:t.documentId}))},onDragOver:m=>{!ue(e.onMoveDocument)||ve===t.documentId||(m.preventDefault(),m.stopPropagation(),m.dataTransfer.dropEffect="move",e.setDropHighlight({kind:"doc",id:t.documentId}))},onDrop:m=>{if(!e.onMoveDocument||!ue(e.onMoveDocument))return;m.preventDefault(),m.stopPropagation();const g=gt(m.dataTransfer),k=e.parentFolderId;e.endDragSession(),!(!g||g===t.documentId)&&e.onMoveDocument(g,k)},onClick:()=>{l||e.onOpen(t)},onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),e.onOpen(t))},onContextMenu:m=>{m.preventDefault(),m.stopPropagation(),e.onContextMenu({x:m.clientX,y:m.clientY,node:t,parentPath:e.parentPath})},children:[n.jsx("span",{className:"mdocs-tree-caret-spacer","aria-hidden":!0}),n.jsx("span",{className:"mdocs-tree-icon",children:"md"}),n.jsx("span",{className:"mdocs-tree-label",children:t.displayName||t.name})]})}function ri(){return n.jsx("span",{className:"mdocs-tree-icon mdocs-tree-icon-dir","aria-hidden":!0,children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M2 4.5h4.2L7.3 6H14v8.5H2V4.5z",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"}),n.jsx("path",{d:"M2 4.5V3h4l1.1 1.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]})})}function ai(e){var g,k;const{t}=de(),i=e.forceOpenFolderIds.has(e.folder.documentId),[r,s]=a.useState(e.depth<1||i),d=r;a.useEffect(()=>{i&&s(!0)},[i,e.activeDocumentId]);const l=!!e.folder.descDocumentId&&e.folder.descDocumentId===e.activeDocumentId,p=e.selectedParentPath===e.folder.path,h=((g=e.dropHighlight)==null?void 0:g.kind)==="folder"&&e.dropHighlight.id===e.folder.documentId;function m(){e.onOpenFolder(e.folder.path,e.folder.descDocumentId)}return n.jsxs("div",{children:[n.jsxs("div",{className:"mdocs-tree-row mdocs-tree-folder mdocs-tree-folder-row"+(l?" active":p?" mdocs-tree-select-target":"")+(h?" mdocs-tree-drop-target":""),"data-tree-id":e.folder.documentId,style:e.indent,onClick:m,onContextMenu:v=>{v.preventDefault(),v.stopPropagation(),e.onContextMenu({x:v.clientX,y:v.clientY,node:e.folder,parentPath:e.folder.path})},onDragEnter:v=>{ue(e.onMoveDocument)&&(v.preventDefault(),v.stopPropagation(),e.setDropHighlight({kind:"folder",id:e.folder.documentId}),s(!0))},onDragOver:v=>{ue(e.onMoveDocument)&&(v.preventDefault(),v.stopPropagation(),v.dataTransfer.dropEffect="move",e.setDropHighlight({kind:"folder",id:e.folder.documentId}))},onDrop:v=>{if(!e.onMoveDocument||!ue(e.onMoveDocument))return;v.preventDefault(),v.stopPropagation();const C=gt(v.dataTransfer),E=e.folder.documentId;e.endDragSession(),C&&e.onMoveDocument(C,E)},children:[n.jsx("span",{className:"mdocs-tree-caret",role:"button",tabIndex:0,"aria-expanded":d,"aria-label":t(d?"collapseFolder":"expandFolder"),onClick:v=>{v.stopPropagation(),s(C=>!C),m()},onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),s(C=>!C),m())},children:d?"▾":"▸"}),n.jsx(ri,{}),n.jsx("span",{className:"mdocs-tree-folder-select",children:n.jsx("span",{className:"mdocs-tree-label",children:((k=e.folder.folderDisplayName)==null?void 0:k.trim())||e.folder.name})})]}),d&&e.folder.children.map(v=>n.jsx(ln,{node:v,depth:e.depth+1,parentPath:e.folder.path,parentFolderId:e.folder.documentId,activeDocumentId:e.activeDocumentId,selectedParentPath:e.selectedParentPath,forceOpenFolderIds:e.forceOpenFolderIds,dropHighlight:e.dropHighlight,setDropHighlight:e.setDropHighlight,clearDropHighlight:e.clearDropHighlight,beginDragSession:e.beginDragSession,endDragSession:e.endDragSession,draggingId:e.draggingId,onOpen:e.onOpen,onOpenFolder:e.onOpenFolder,onContextMenu:e.onContextMenu,onMoveDocument:e.onMoveDocument},v.path))]})}function si(e){var p;const{t}=de(),i=a.useRef(null);a.useEffect(()=>{function h(g){i.current&&!i.current.contains(g.target)&&e.onClose()}function m(g){g.key==="Escape"&&e.onClose()}return window.addEventListener("mousedown",h),window.addEventListener("keydown",m),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",m)}},[e.onClose]);const r=e.node.type==="folder";let s="";if(e.node.type==="folder"){const h=e.node;s=((p=h.folderDisplayName)==null?void 0:p.trim())||h.path||""}const d=r?s?t("newDocIn",{name:s}):t("newDocAtRoot"):t("newDocBeside"),l=r?s?t("newFolderIn",{name:s}):t("newFolderAtRoot"):t("newFolderBeside");return n.jsxs("div",{ref:i,className:"mdocs-context-menu card",style:{left:e.x,top:e.y},children:[n.jsx("button",{type:"button",className:"mdocs-context-item",onClick:()=>{const h=r?e.node.path:e.parentPath;e.onCreateChild(h),e.onClose()},children:d}),n.jsx("button",{type:"button",className:"mdocs-context-item",onClick:()=>{const h=r?e.node.path:e.parentPath;e.onCreateFolder(h),e.onClose()},children:l}),n.jsx("button",{type:"button",className:"mdocs-context-item danger",onClick:()=>{e.node.type==="document"?e.onDeleteDocument(e.node):e.onDeleteFolder(e.node),e.onClose()},children:e.node.type==="folder"?t("deleteFolder",{name:s||e.node.name}):t("deleteItem",{name:e.node.name})})]})}function di({domains:e,value:t,onChange:i,ariaLabel:r,localizeName:s,onDomainsChange:d}){const[l,p]=a.useState(!1),[h,m]=a.useState(e),g=a.useRef(null),k=a.useRef(null);a.useEffect(()=>{m(e)},[e]);const v=h.find(y=>y.domainId===t),C=(v==null?void 0:v.permission)==="private";a.useEffect(()=>{if(!l)return;const y=I=>{var b,A;!((b=g.current)!=null&&b.contains(I.target))&&!((A=k.current)!=null&&A.contains(I.target))&&p(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[l]),a.useEffect(()=>{if(!l)return;const y=I=>{var b;I.key==="Escape"&&(p(!1),(b=g.current)==null||b.focus())};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[l]);function E(y){i(y),p(!1)}function $(){if(l){p(!1);return}p(!0),sn().then(y=>{m(y),d==null||d(y)})}return n.jsxs("div",{className:"mdocs-domain-select-wrapper",children:[n.jsxs("button",{ref:g,type:"button",className:"mdocs-domain-select-trigger","aria-label":r,"aria-expanded":l,"aria-haspopup":"listbox",onClick:$,children:[n.jsx("span",{className:"mdocs-domain-select-text",children:v?s(v.domainName):""}),C&&n.jsxs("svg",{className:"mdocs-domain-lock",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--mdocs-text-muted)",strokeWidth:"2",children:[n.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),n.jsx("svg",{className:"mdocs-domain-select-chevron"+(l?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"var(--mdocs-text-muted)",strokeWidth:"1.5",children:n.jsx("path",{d:"M1 1l4 4 4-4"})})]}),l&&n.jsx("div",{ref:k,className:"mdocs-domain-select-menu card",role:"listbox","aria-label":r,children:h.map(y=>n.jsxs("button",{type:"button",className:"mdocs-domain-select-option"+(y.domainId===t?" active":""),role:"option","aria-selected":y.domainId===t,onClick:()=>E(y.domainId),children:[n.jsx("span",{children:s(y.domainName)}),y.permission==="private"&&n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--mdocs-text-muted)",strokeWidth:"2",children:[n.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})]},y.domainId))})]})}const mn="data:image/svg+xml,%3csvg%20fill='%234D6BFE'%20fill-rule='evenodd'%20height='1em'%20style='flex:none;line-height:1'%20viewBox='0%200%2024%2024'%20width='1em'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eDeepSeek%3c/title%3e%3cpath%20d='M23.748%204.482c-.254-.124-.364.113-.512.234-.051.039-.094.09-.137.136-.372.397-.806.657-1.373.626-.829-.046-1.537.214-2.163.848-.133-.782-.575-1.248-1.247-1.548-.352-.156-.708-.311-.955-.65-.172-.241-.219-.51-.305-.774-.055-.16-.11-.323-.293-.35-.2-.031-.278.136-.356.276-.313.572-.434%201.202-.422%201.84.027%201.436.633%202.58%201.838%203.393.137.093.172.187.129.323-.082.28-.18.552-.266.833-.055.179-.137.217-.329.14a5.526%205.526%200%2001-1.736-1.18c-.857-.828-1.631-1.742-2.597-2.458a11.365%2011.365%200%2000-.689-.471c-.985-.957.13-1.743.388-1.836.27-.098.093-.432-.779-.428-.872.004-1.67.295-2.687.684a3.055%203.055%200%2001-.465.137%209.597%209.597%200%2000-2.883-.102c-1.885.21-3.39%201.102-4.497%202.623C.082%208.606-.231%2010.684.152%2012.85c.403%202.284%201.569%204.175%203.36%205.653%201.858%201.533%203.997%202.284%206.438%202.14%201.482-.085%203.133-.284%204.994-1.86.47.234.962.327%201.78.397.63.059%201.236-.03%201.705-.128.735-.156.684-.837.419-.961-2.155-1.004-1.682-.595-2.113-.926%201.096-1.296%202.746-2.642%203.392-7.003.05-.347.007-.565%200-.845-.004-.17.035-.237.23-.256a4.173%204.173%200%20001.545-.475c1.396-.763%201.96-2.015%202.093-3.517.02-.23-.004-.467-.247-.588zM11.581%2018c-2.089-1.642-3.102-2.183-3.52-2.16-.392.024-.321.471-.235.763.09.288.207.486.371.739.114.167.192.416-.113.603-.673.416-1.842-.14-1.897-.167-1.361-.802-2.5-1.86-3.301-3.307-.774-1.393-1.224-2.887-1.298-4.482-.02-.386.093-.522.477-.592a4.696%204.696%200%20011.529-.039c2.132.312%203.946%201.265%205.468%202.774.868.86%201.525%201.887%202.202%202.891.72%201.066%201.494%202.082%202.48%202.914.348.292.625.514.891.677-.802.09-2.14.11-3.054-.614zm1-6.44a.306.306%200%2001.415-.287.302.302%200%2001.2.288.306.306%200%2001-.31.307.303.303%200%2001-.304-.308zm3.11%201.596c-.2.081-.399.151-.59.16a1.245%201.245%200%2001-.798-.254c-.274-.23-.47-.358-.552-.758a1.73%201.73%200%2001.016-.588c.07-.327-.008-.537-.239-.727-.187-.156-.426-.199-.688-.199a.559.559%200%2001-.254-.078c-.11-.054-.2-.19-.114-.358.028-.054.16-.186.192-.21.356-.202.767-.136%201.146.016.352.144.618.408%201.001.782.391.451.462.576.685.914.176.265.336.537.445.848.067.195-.019.354-.25.452z'%3e%3c/path%3e%3c/svg%3e",ae={left:12,bottom:64},yt="mdocs.agentFabPosition",Ye=36,Yt=3;function vt(e){const i=Math.max(8,window.innerWidth-Ye-8),r=Math.max(8,window.innerHeight-Ye-8);return{left:Math.min(i,Math.max(8,e.left)),bottom:Math.min(r,Math.max(8,e.bottom))}}function ci(e,t,i,r){const s=e-i,d=t-r,l=window.innerHeight-d-Ye;return vt({left:s,bottom:l})}function li(){try{const e=localStorage.getItem(yt);if(!e)return ae;const t=JSON.parse(e);return typeof t.left!="number"||typeof t.bottom!="number"?ae:vt({left:t.left,bottom:t.bottom})}catch{return ae}}function Jt(e){localStorage.setItem(yt,JSON.stringify(e))}function mi(e){return e.left===ae.left&&e.bottom===ae.bottom}function ui(e){const i=Math.min(480,window.innerWidth-72);let r=e.left+Ye+8;r+i>window.innerWidth-8&&(r=e.left-8-i),r=Math.max(8,r);const s=Math.max(8,e.bottom-8);return{left:r,bottom:s}}function fi(e){const{t}=de(),[i,r]=a.useState(!1),[s,d]=a.useState(e.position),l=a.useRef(null),p=a.useRef(null),h=a.useRef(s),m=a.useRef(e.onPositionChange),g=a.useRef(e.onToggle);h.current=s,m.current=e.onPositionChange,g.current=e.onToggle;const k=a.useRef(null),v=a.useRef(0),C=a.useRef(null);a.useEffect(()=>{k.current||(d(e.position),h.current=e.position)},[e.position]),a.useEffect(()=>{function I(){const b=vt(h.current);b.left===h.current.left&&b.bottom===h.current.bottom||(h.current=b,d(b),m.current(b),Jt(b))}return window.addEventListener("resize",I),()=>window.removeEventListener("resize",I)},[]),a.useEffect(()=>{function I(){v.current=0;const P=C.current;if(!P)return;C.current=null,h.current=P,d(P);const T=p.current;T&&(T.style.left=`${P.left}px`,T.style.bottom=`${P.bottom}px`),m.current(P)}function b(P){const T=k.current;if(!T||P.pointerId!==T.pointerId)return;P.preventDefault();const _=P.clientX-T.startX,F=P.clientY-T.startY;!T.didMove&&_*_+F*F>=Yt*Yt&&(T.didMove=!0,r(!0)),T.didMove&&(C.current=ci(P.clientX,P.clientY,T.offsetX,T.offsetY),v.current||(v.current=requestAnimationFrame(I)))}function A(P){var _;const T=k.current;if(!(!T||P.pointerId!==T.pointerId)){k.current=null,r(!1),v.current&&(cancelAnimationFrame(v.current),v.current=0),C.current&&(h.current=C.current,d(C.current),C.current=null);try{(_=l.current)==null||_.releasePointerCapture(P.pointerId)}catch{}if(T.didMove){const F=h.current;m.current(F),Jt(F);return}g.current()}}return window.addEventListener("pointermove",b,{passive:!1}),window.addEventListener("pointerup",A),window.addEventListener("pointercancel",A),()=>{window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",A),window.removeEventListener("pointercancel",A),v.current&&cancelAnimationFrame(v.current)}},[]);function E(I){if(I.button!==0)return;I.preventDefault();const b=I.currentTarget.getBoundingClientRect();k.current={pointerId:I.pointerId,offsetX:I.clientX-b.left,offsetY:I.clientY-b.top,startX:I.clientX,startY:I.clientY,didMove:!1},I.currentTarget.setPointerCapture(I.pointerId)}function $(){h.current=ae,d(ae),e.onPositionChange(ae),localStorage.removeItem(yt)}const y=!mi(s);return n.jsxs("div",{ref:p,className:"mdocs-agent-fab-wrap"+(i?" dragging":""),style:{left:s.left,bottom:s.bottom},children:[n.jsx("button",{ref:l,type:"button",className:"mdocs-agent-fab"+(e.open?" open":"")+(i?" dragging":""),"aria-label":t("agentFabOpen"),"aria-expanded":e.open,onPointerDown:E,children:n.jsx("img",{src:mn,alt:"",draggable:!1})}),y&&n.jsx("button",{type:"button",className:"mdocs-agent-fab-reset",onClick:$,"aria-label":t("agentFabReset"),children:t("agentFabReset")})]})}function pi(){const[e,t]=a.useState(()=>typeof window>"u"?ae:li());return[e,t]}function hi({title:e,message:t,onClose:i}){const{t:r}=de();return n.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:s=>{s.target===s.currentTarget&&i()},children:n.jsxs("div",{className:"mdocs-dialog card mdocs-message-dialog",role:"alertdialog","aria-modal":"true",children:[e&&n.jsx("h2",{className:"mdocs-message-dialog-title",children:e}),n.jsx("p",{className:"mdocs-message-dialog-body",children:t}),n.jsx("div",{className:"mdocs-message-dialog-actions",children:n.jsx("button",{type:"button",className:"primary",onClick:i,children:r("gotIt")})})]})})}function un({title:e,message:t,confirmLabel:i="确定",cancelLabel:r="取消",onConfirm:s,onCancel:d,busy:l=!1,danger:p=!1}){return n.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:h=>{h.target===h.currentTarget&&!l&&d()},children:n.jsxs("div",{className:"mdocs-dialog card mdocs-message-dialog",role:"alertdialog","aria-modal":"true",children:[e&&n.jsx("h2",{className:"mdocs-message-dialog-title",children:e}),n.jsx("p",{className:"mdocs-message-dialog-body",children:t}),n.jsxs("div",{className:"mdocs-message-dialog-actions",style:{gap:8},children:[n.jsx("button",{type:"button",onClick:d,disabled:l,children:r}),n.jsx("button",{type:"button",className:p?"danger":"primary",onClick:s,disabled:l,children:l?"…":i})]})]})})}const Kt={"relative path is required":"pathRequired","path must be relative":"pathMustBeRelative","use forward slashes":"useForwardSlashes","path must not contain ..":"pathNoDotDot","document path must end with .md":"pathMustEndWithMd","path contains unsupported characters":"pathUnsupportedChars","path escapes docs root":"pathEscapesRoot"},fn={"enter a folder name":"enterFolderName","use a single name, not a path":"singleNameNotPath","invalid folder name":"invalidFolderName","folder name is too long":"folderNameTooLong","enter a file name":"enterFileName","use a file name, not a path":"singleFileNameNotPath","invalid file name":"invalidFileName","file name is too long":"fileNameTooLong"};function me(e,t){if(t instanceof oe)return t.message;if(t instanceof le){const i=Kt[t.message];return i?e(i):t.message}if(t instanceof Error){const i=Kt[t.message]??fn[t.message];return i?e(i):t.message}return String(t)}function gi(e,t,i){if(e==="Default")return i("defaultDomain");const r="个人域";return e.endsWith(r)?e.slice(0,-r.length)+i("personalDomainSuffix"):e}function Or(e,t){return e==="public"?t("domainPublic"):e==="restricted"?t("domainRestricted"):e==="private"?t("domainPrivate"):e}function ze(e){const t=e.lastIndexOf("/");return t===-1?"":e.slice(0,t)}function yi(e){return JSON.stringify({root:{children:[{children:[{detail:0,format:0,mode:"normal",text:e,type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",tag:"h1",version:1}],direction:"ltr",type:"root",version:1}})}function Xt(e,t){const i=e.trim(),r=t.trim();return r?i?`${i}/${r}`:r:i}function pn(e,t=new Set){for(const i of e)i.type==="document"?t.add(i.path):(i.descDocumentId&&t.add(Po(i.path)),pn(i.children,t));return t}function pt(e,t){for(const i of e){if(i.type==="folder"&&i.path===t)return i.documentId;if(i.type==="folder"){const r=pt(i.children,t);if(r)return r}}return null}function Qt(e,t){const i=fn[t];return i?e(i):t}function vi(e){const{tree:t,currentDomainId:i,selectedCreateParentPath:r,t:s,onDocCreated:d,refreshTree:l}=e,[p,h]=a.useState(null),[m,g]=a.useState(null),[k,v]=a.useState(!1),C=a.useRef(null);a.useEffect(()=>{if(!p)return;const I=window.setTimeout(()=>{var b;return(b=C.current)==null?void 0:b.focus()},0);return()=>window.clearTimeout(I)},[p]);function E(I){const b=I!==void 0;g(null),h({kind:"document",parentMode:b?"fixed":"selection",parentPath:b?I:"",draft:"untitled.md"})}function $(I){const b=I!==void 0;g(null),h({kind:"folder",parentMode:b?"fixed":"selection",parentPath:b?I:"",draft:""})}async function y(I){if(I.preventDefault(),!p)return;v(!0),g(null);const b=pn(t),A=p.parentMode==="selection"?r:p.parentPath;try{if(p.kind==="document"){const H=jo(p.draft);if(!H.ok){g(Qt(s,H.message));return}const Y=H.displayFile,R=Y.replace(/\.md$/i,"");let u;try{u=Mo(Xt(A,Y))}catch(O){g(me(s,O));return}if(b.has(u)){g(s("pathExists"));return}const N=A?pt(t,A)??void 0:void 0,M=await an({fileName:Y,displayName:R,content:yi(R),domainId:i,parentId:N});await l(),d(M),h(null);return}const P=Ao(p.draft);if(!P.ok){g(Qt(s,P.message));return}const T=mt(P.display);if(!T){g(s("invalidFolderName"));return}const _=Xt(A,T);if(b.has(_)){g(s("folderExists"));return}const F=A?pt(t,A)??void 0:void 0;await qo({name:T,parentId:F,domainId:i}),await l(),h(null)}catch(P){g(me(s,P))}finally{v(!1)}}return{createModal:p,setCreateModal:h,createModalError:m,createModalBusy:k,createModalInputRef:C,openNewDocumentModal:E,openNewFolderModal:$,submitCreateModal:y}}function bi({open:e,onClose:t,onResolve:i}){const{t:r}=de();return e?n.jsx("div",{className:"mdocs-conflict-modal-root",role:"alertdialog","aria-modal":"true",children:n.jsxs("div",{className:"mdocs-conflict-modal-panel",children:[n.jsx("h2",{className:"mdocs-conflict-modal-title",children:r("conflictTitle")}),n.jsx("p",{className:"mdocs-conflict-modal-body",children:r("conflictBody")}),n.jsxs("div",{className:"mdocs-conflict-modal-actions",children:[n.jsx("button",{type:"button",className:"primary",onClick:i,children:r("conflictResolve")}),n.jsx("button",{type:"button",className:"secondary",onClick:t,children:r("conflictClose")})]})]})}):null}function wi({documentId:e,visitorId:t,visitorName:i,documentOwnerId:r,onClose:s}){const[d,l]=a.useState([]),[p,h]=a.useState(""),[m,g]=a.useState(null),[k,v]=a.useState(!0),[C,E]=a.useState(!1),[$,y]=a.useState(null),[I,b]=a.useState(null),[A,P]=a.useState(360),[T,_]=a.useState(80),F=a.useRef(!1),H=a.useRef(!1),Y=300,R=80,u=a.useRef(null);function N(){const D=u.current;if(!D)return;D.style.height="auto";const S=D.scrollHeight,z=Math.min(Math.max(S,R),Y);D.style.height=`${z}px`,_(z)}a.useEffect(()=>{setTimeout(()=>N(),0)},[m]);function M(D){return t?D.visitorId===t||r===t:!1}const{rootComments:O,repliesByParentId:J,totalCount:Je}=a.useMemo(()=>{const D=[],S=new Map;let z=0;for(const B of d)B.isDeleted||(z++,B.parentId?(S.has(B.parentId)||S.set(B.parentId,[]),S.get(B.parentId).push(B)):D.push(B));return{rootComments:D,repliesByParentId:S,totalCount:z}},[d]),ie=a.useRef(e);a.useEffect(()=>{ie.current=e,h(""),g(null),b(null),ce()},[e]);async function ce(){const D=ie.current;v(!0);try{const S=await Ko(e);if(ie.current!==D)return;l(S.comments)}catch(S){if(ie.current!==D)return;b("加载评论失败"),console.error("Failed to load comments:",S)}finally{ie.current===D&&v(!1)}}async function fe(){var D;if(!(!p.trim()||!t)){E(!0),b(null);try{await Xo(e,{content:p,parentId:(m==null?void 0:m.commentId)||null,replyToVisitorId:m?((D=d.find(S=>S.commentId===m.commentId))==null?void 0:D.visitorId)??null:null,replyToVisitorName:(m==null?void 0:m.visitorName)||null}),h(""),g(null),setTimeout(()=>N(),0),await ce()}catch(S){b(S.message||"发表失败,请重试")}finally{E(!1)}}}async function Ke(D){b(null);try{await Qo(e,D),await ce()}catch(S){b(S.message||"删除失败,请重试")}finally{y(null)}}function re(D){const S=Date.now()-new Date(D).getTime(),z=Math.floor(S/6e4),B=Math.floor(S/36e5),he=Math.floor(S/864e5);return z<1?"刚刚":z<60?`${z}分钟前`:B<24?`${B}小时前`:`${he}天前`}function ke(D){F.current=!0,D.preventDefault()}function pe(D){H.current=!0,D.preventDefault(),document.body.style.userSelect="none",document.body.style.cursor="row-resize"}return a.useEffect(()=>{function D(z){if(F.current){const B=Math.max(280,Math.min(600,window.innerWidth-z.clientX));P(B)}if(H.current){const B=-z.movementY;_(he=>Math.max(60,Math.min(600,he+B)))}}function S(){F.current=!1,H.current=!1,document.body.style.userSelect="",document.body.style.cursor=""}return window.addEventListener("mousemove",D),window.addEventListener("mouseup",S),()=>{window.removeEventListener("mousemove",D),window.removeEventListener("mouseup",S)}},[]),n.jsxs("div",{className:"mdocs-comments-panel",style:{width:A},children:[n.jsx("div",{className:"mdocs-comments-resize-handle",onMouseDown:ke}),n.jsxs("div",{className:"mdocs-comments-header",children:[n.jsxs("h3",{style:{margin:0,fontSize:"1rem",display:"flex",alignItems:"center",gap:6},children:[n.jsx(fo,{size:18}),"评论 (",Je,")"]}),n.jsx("button",{type:"button",onClick:s,className:"mdocs-comments-close-btn",children:n.jsx(Ae,{size:18})})]}),I&&n.jsxs("div",{className:"mdocs-comments-error",children:[I,n.jsx("button",{type:"button",onClick:()=>b(null),children:n.jsx(Ae,{size:14})})]}),n.jsx("div",{className:"mdocs-comments-list",children:k?n.jsx("div",{className:"mdocs-comments-empty",children:"加载中..."}):O.length===0?n.jsx("div",{className:"mdocs-comments-empty",children:"暂无评论,来发表第一条吧~"}):O.map(D=>n.jsxs("div",{className:"mdocs-comment-root",children:[n.jsxs("div",{className:"mdocs-comment-header",children:[n.jsx("span",{className:"mdocs-comment-avatar",children:D.visitorName.charAt(0).toUpperCase()}),n.jsx("span",{className:"mdocs-comment-author",children:D.visitorName}),n.jsx("span",{className:"mdocs-comment-time",children:re(D.createdAt)}),M(D)&&n.jsx("button",{type:"button",className:"mdocs-comment-delete",onClick:()=>y(D.commentId),title:"删除",children:n.jsx(Ae,{size:14})})]}),n.jsx("div",{className:"mdocs-comment-content",children:D.content}),t&&n.jsx("button",{type:"button",className:"mdocs-comment-reply-btn",onClick:()=>g({commentId:D.commentId,visitorName:D.visitorName}),children:"回复"}),(J.get(D.commentId)??[]).length>0&&n.jsx("div",{className:"mdocs-comment-replies",children:(J.get(D.commentId)??[]).map(S=>n.jsxs("div",{className:"mdocs-comment-reply",children:[n.jsxs("div",{className:"mdocs-comment-header",children:[n.jsx("span",{className:"mdocs-comment-avatar mdocs-comment-avatar-small",children:S.visitorName.charAt(0).toUpperCase()}),n.jsx("span",{className:"mdocs-comment-author",children:S.visitorName}),S.replyToVisitorName&&n.jsxs("span",{className:"mdocs-comment-reply-to",children:["回复 ",S.replyToVisitorName]}),n.jsx("span",{className:"mdocs-comment-time",children:re(S.createdAt)}),M(S)&&n.jsx("button",{type:"button",className:"mdocs-comment-delete",onClick:()=>y(S.commentId),title:"删除",children:n.jsx(Ae,{size:12})})]}),n.jsx("div",{className:"mdocs-comment-content",children:S.content}),t&&n.jsx("button",{type:"button",className:"mdocs-comment-reply-btn",onClick:()=>g({commentId:D.commentId,visitorName:S.visitorName}),children:"回复"})]},S.commentId))})]},D.commentId))}),t?n.jsxs("div",{className:"mdocs-comments-input-wrapper",children:[n.jsx("div",{className:"mdocs-comments-input-drag-handle",onMouseDown:pe}),m&&n.jsxs("div",{className:"mdocs-comment-reply-notice",children:[n.jsxs("span",{children:["回复 ",n.jsx("span",{className:"mdocs-comment-reply-to-name",children:m.visitorName})]}),n.jsxs("button",{type:"button",onClick:()=>g(null),children:[n.jsx(Ae,{size:14})," 取消"]})]}),n.jsx("textarea",{ref:u,value:p,onChange:D=>{h(D.target.value.slice(0,512)),setTimeout(()=>N(),0)},placeholder:m?`回复 ${m.visitorName}...`:"发表评论...",className:"mdocs-comments-input",style:{height:T},maxLength:512,onKeyDown:D=>{D.key==="Enter"&&(D.metaKey||D.ctrlKey)&&fe()}}),n.jsxs("div",{className:`mdocs-comments-char-count${p.length>=460?" mdocs-char-count--warn":""}`,children:[p.length,"/512"]}),n.jsx("div",{className:"mdocs-comments-input-actions",children:n.jsx("button",{type:"button",className:"mdocs-btn-primary",onClick:fe,disabled:C||!p.trim(),children:C?"发表中...":"发表"})})]}):n.jsx("div",{className:"mdocs-comments-input-wrapper",style:{textAlign:"center"},children:n.jsx("div",{style:{color:"#666",fontSize:"0.9rem"},children:"请先创建访客身份以发表评论"})}),$&&n.jsx(un,{title:"删除评论",message:"确定要删除这条评论吗?",confirmLabel:"删除",danger:!0,onConfirm:()=>Ke($),onCancel:()=>y(null)})]})}const xi="mdocs-drafts",Ii=4,W="drafts",De={DOC_NOT_FOUND:"DOC_NOT_FOUND",SYNC_HEAD_MISSING:"SYNC_HEAD_MISSING"};let at=null;function Se(){return at||(at=new Promise((e,t)=>{const i=indexedDB.open(xi,Ii);i.onupgradeneeded=r=>{const s=i.result;s.objectStoreNames.contains(W)||s.createObjectStore(W,{keyPath:"documentId"});const d=r.oldVersion;if(d>0&&d<4){const h=i.transaction.objectStore(W).openCursor();h.onsuccess=()=>{const m=h.result;if(!m)return;const g=m.value;typeof g.baseCommitId=="string"&&!g.localBaseCommitId&&(g.localBaseCommitId=g.baseCommitId,delete g.baseCommitId);const k=g.conflict;k&&(typeof k.baseCommitId=="string"&&!k.localBaseCommitId&&(k.localBaseCommitId=k.baseCommitId,delete k.baseCommitId),typeof k.expectedHeadCommitId=="string"&&!k.remoteCommitId&&(k.remoteCommitId=k.expectedHeadCommitId,delete k.expectedHeadCommitId)),m.update(g),m.continue()}}},i.onsuccess=()=>e(i.result),i.onerror=()=>t(i.error)})),at}async function Di(e){var r;const t=await G(e.documentId),i={documentId:e.documentId,content:e.content,displayName:e.displayName,updatedAt:Date.now(),published:!1};if(t!=null&&t.localBaseCommitId)i.localBaseCommitId=t.localBaseCommitId;else{const s=(r=e.localBaseCommitIdAtEditStart)==null?void 0:r.trim();s&&(i.localBaseCommitId=s)}(t==null?void 0:t.permission)!=null?i.permission=t.permission:e.snapshotMeta&&(i.permission=e.snapshotMeta.permission),t!=null&&t.ownerVisitorId?i.ownerVisitorId=t.ownerVisitorId:e.snapshotMeta&&(i.ownerVisitorId=e.snapshotMeta.ownerVisitorId),t!=null&&t.domainId?i.domainId=t.domainId:e.snapshotMeta&&(i.domainId=e.snapshotMeta.domainId),t!=null&&t.publishError&&(i.publishError=t.publishError,i.publishErrorAt=t.publishErrorAt),t!=null&&t.conflictStatus&&(i.conflictStatus=t.conflictStatus),t!=null&&t.conflict&&(i.conflict=t.conflict),await ye(i)}function bt(e){const t={documentId:e.documentId,content:e.content,displayName:e.displayName,updatedAt:e.updatedAt,published:e.published};return e.permission!=null&&(t.permission=e.permission),e.ownerVisitorId&&(t.ownerVisitorId=e.ownerVisitorId),e.domainId&&(t.domainId=e.domainId),e.publishError!=null&&(t.publishError=e.publishError),e.publishErrorAt!=null&&(t.publishErrorAt=e.publishErrorAt),e.localBaseCommitId&&(t.localBaseCommitId=e.localBaseCommitId),e.conflictStatus!=null&&(t.conflictStatus=e.conflictStatus),e.conflict!=null&&(t.conflict=e.conflict),t}async function ye(e){const t=await Se(),i=bt(e);return new Promise((r,s)=>{const d=t.transaction(W,"readwrite");d.objectStore(W).put(i),d.oncomplete=()=>r(),d.onerror=()=>s(d.error)})}async function G(e){const t=await Se();return new Promise((i,r)=>{const d=t.transaction(W,"readonly").objectStore(W).get(e);d.onsuccess=()=>i(d.result),d.onerror=()=>r(d.error)})}async function st(e){const t=await Se();return new Promise((i,r)=>{const s=t.transaction(W,"readwrite");s.objectStore(W).delete(e),s.oncomplete=()=>i(),s.onerror=()=>r(s.error)})}async function Ci(e){const t=await Se();return new Promise((i,r)=>{const d=t.transaction(W,"readonly").objectStore(W).getAll();d.onsuccess=()=>{let l=d.result;e!=null&&e.skipFailed&&(l=l.filter(p=>!p.publishError)),i(l)},d.onerror=()=>r(d.error)})}async function Si(e,t){const i=await Se();return new Promise((r,s)=>{const l=i.transaction(W,"readwrite").objectStore(W),p=l.get(e);p.onsuccess=()=>{const h=p.result;h&&l.put(bt({...h,publishError:t,publishErrorAt:Date.now()})),r()},p.onerror=()=>s(p.error)})}async function dt(e){const t=await Se();return new Promise((i,r)=>{const d=t.transaction(W,"readwrite").objectStore(W),l=d.get(e);l.onsuccess=()=>{const p=l.result;p&&d.put(bt({...p,publishError:void 0,publishErrorAt:void 0})),i()},l.onerror=()=>r(l.error)})}async function Zt(e,t){const i=await G(e);i&&await ye({...i,localBaseCommitId:t.localBaseCommitId,conflictStatus:t.conflictStatus,conflict:t.conflict})}async function ct(e){const t=await G(e);t&&await ye({...t,conflict:void 0,conflictStatus:"none"})}class Re extends Error{constructor(i,r){super(i);Ie(this,"code");Ie(this,"cause");this.name="DraftPublishAborted",this.code=i,this.cause=r==null?void 0:r.cause}}function ki(e){return e instanceof Re?e.code:e instanceof oe?e.status===404?De.DOC_NOT_FOUND:e.code||`HTTP_${e.status}`:e instanceof Error&&e.message.trim()?e.message.trim().slice(0,120):"UNKNOWN"}function Ni(e,t,i,r){const s=(t==null?void 0:t.displayName)||e("unknownTitle");if(i===De.SYNC_HEAD_MISSING)return e("draftPublishFailedSyncHead",{name:s});if(i===De.DOC_NOT_FOUND)return e("draftPublishFailedNotice",{name:s});const d=r instanceof oe||r instanceof Error&&r.message?r.message:i;return e("draftPublishFailedGeneric",{name:s,reason:d})}async function Pi(e,t,i){const r=ki(t);throw await Si(e,r),t instanceof Re?t:new Re(r,{cause:t})}function Ti(e,t){const i=a.useRef(t);i.current=t,a.useEffect(()=>{if(!e)return;const r=3e4,s=1e4,d=async()=>{const p=await Ci({skipFailed:!0}),h=Date.now();for(const m of p)if(!m.published&&!(h-m.updatedAt<r))try{await i.current(m.documentId)}catch(g){console.log("[autoPublish] scan publish failed:",g)}};d();const l=setInterval(d,s);return()=>clearInterval(l)},[e])}const Ei=1e4;function Ai(e,t){const[i,r]=a.useState(null),[s,d]=a.useState("up_to_date");return a.useEffect(()=>{if(!e){r(null),d("up_to_date");return}let p=!1;const h=e;async function m(){try{const k=await Vo(h,t??void 0);if(p)return;r(k.headCommitId),d(k.status)}catch{}}m();const g=window.setInterval(()=>void m(),Ei);return()=>{p=!0,window.clearInterval(g)}},[e,t]),{remoteCommitId:i,syncStatus:s,syncBehind:!!(t&&i&&t!==i)||s==="behind"}}const ji="/assets/mdocs-logo-Dsv_2t6v.svg",Mi=a.lazy(()=>Ce(()=>import("./DocumentEditor-B2H3rHSg.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(e=>({default:e.DocumentEditor}))),Ri=a.lazy(()=>Ce(()=>import("./SettingsPage-BRAPdqW9.js"),__vite__mapDeps([11,1,10,2,3])).then(e=>({default:e.SettingsPage}))),Oi=a.lazy(()=>Ce(()=>import("./AgentChatPanel-DHy3KgSW.js"),__vite__mapDeps([12,1,7,13,2,3,8])).then(e=>({default:e.AgentChatPanel}))),Li=a.lazy(()=>Ce(()=>import("./AiWriteWorkbench-Ce_OaED4.js"),__vite__mapDeps([14,1,7,13,2,3])).then(e=>({default:e.AiWriteWorkbench}))),Fi=a.lazy(()=>Ce(()=>import("./MergeView-Cy4Pi3Je.js"),__vite__mapDeps([15,1,4,5,2,3,6,7,8])).then(e=>({default:e.MergeView})));function _i(e,t){try{const i=new Intl.RelativeTimeFormat(t,{numeric:"auto"}),r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4),d=Math.floor(s/60),l=Math.floor(d/24);return l>30?i.format(-Math.floor(l/30),"month"):l>0?i.format(-l,"day"):d>0?i.format(-d,"hour"):s>0?i.format(-s,"minute"):i.format(-Math.floor(r/1e3),"second")}catch{return e.slice(0,10)}}async function lt(e,t,i,r){const s=await sn();t(s);const d=localStorage.getItem("mdocs.currentDomainId"),p=d&&s.some(h=>h.domainId===d)?d:ei(s,e);i(p),await r(p)}function en(){const{t:e,lang:t,setLang:i}=de(),[r,s]=a.useState("loading"),[d,l]=a.useState(()=>localStorage.getItem("mdocs.sidebarCollapsed")==="true"),p=()=>{const o=!d;l(o),localStorage.setItem("mdocs.sidebarCollapsed",String(o))},[h,m]=a.useState(!1),[g,k]=a.useState(0),v=a.useRef(null),[C,E]=a.useState(null),[$,y]=a.useState(null),[I,b]=a.useState(null),[A,P]=a.useState([]),[T,_]=a.useState([]),[F,H]=a.useState("default"),{documentId:Y}=zn(),R=qn(),[u,N]=a.useState(null),[M,O]=a.useState(null),J=a.useRef(M);J.current=M;const[Je,ie]=a.useState(0),[ce,fe]=a.useState(null),[Ke,re]=a.useState(!1),[ke,pe]=a.useState(!1),[D,S]=a.useState(!1),z=(u==null?void 0:u.documentId)??null,{syncBehind:B,remoteCommitId:he}=Ai(z,ce),[wt,Xe]=a.useState(null);a.useEffect(()=>{if(!ke||!u){Xe(null);return}(async()=>{const o=await G(u.documentId);if(o!=null&&o.conflict){Xe(o.conflict);return}if(o&&ce&&he){const f=o.localBaseCommitId??ce;if(!f)return;const c={localBaseCommitId:f,remoteCommitId:he,localSnapshotContent:o.content};await Zt(u.documentId,{localBaseCommitId:c.localBaseCommitId,conflictStatus:"diverged",conflict:c}),Xe(c)}})()},[ke,u,ce,he]),a.useEffect(()=>{!u||!B||!D||G(u.documentId).then(async o=>{!o||o.conflict||o.conflictStatus==="publish_conflict"||o.conflictStatus!=="diverged"&&await ye({...o,conflictStatus:"diverged"})})},[u==null?void 0:u.documentId,B,D]),a.useEffect(()=>{if(!u){fe(null);return}let o=!1;return G(u.documentId).then(f=>{o||(f&&!f.published&&f.localBaseCommitId?fe(f.localBaseCommitId):fe(u.headCommitId??null))}),()=>{o=!0}},[u==null?void 0:u.documentId,u==null?void 0:u.headCommitId,D]);const[Ne,U]=a.useState(null),[xt,K]=a.useState(null),[q,Oe]=a.useState(null),[Pe,It]=a.useState(null),[Dt,X]=a.useState(""),[gn,Le]=a.useState("docs"),[Qe,be]=a.useState(!1),[Ct,yn]=pi(),[vn,Fe]=a.useState(!1),[_e,Be]=a.useState(null),Q=a.useRef(void 0),$e=a.useRef(void 0);Ti(localStorage.getItem("mdocs.autoPublish")==="true",Mt);async function Z(o){var f;await((f=Q.current)==null?void 0:f.call(Q)),o()}function bn(o){const c=(o.trim()||"untitled").replace(/[\\/:*?"<>|]/g,"-").slice(0,80);return c.endsWith(".md")?c:`${c}.md`}async function wn(){var f,c;if(!u||!M)return;await((f=Q.current)==null?void 0:f.call(Q));let o=((c=$e.current)==null?void 0:c.call($e))??"";if(!o.trim())try{o=(await rt({content:M.content,from:"lexical",to:"markdown"})).content}catch{o=""}Be({markdown:o,documentId:u.documentId,displayName:M.displayName||u.displayName||"未命名"}),Fe(!0),be(!1)}function xn(){Be({markdown:"",documentId:null,displayName:"未命名"}),Fe(!0),be(!1)}async function In(o){var j,L;const f=o.documentId.trim();if(!f)return;await((j=Q.current)==null?void 0:j.call(Q));let c="",w=o.displayName.trim()||"未命名";try{const ee=await Me(f);w=((L=ee.displayName)==null?void 0:L.trim())||w;try{c=(await rt({content:ee.content,from:"lexical",to:"markdown"})).content}catch{c=""}}catch{}Be({markdown:c,documentId:f,displayName:w}),Fe(!0),be(!1),Le("docs"),Z(()=>R(`/doc/${f}`))}async function Dn(o){(u==null?void 0:u.documentId)===o.documentId&&await jt()}async function Cn(o){if(o.documentId){if(!window.confirm("将把帮写结果写入当前文档的本地草稿(不会自动发布)。继续?")){const L=new Error("cancelled");throw L.silent=!0,L}const w=await rt({content:o.markdown,from:"markdown",to:"lexical"}),j=(u==null?void 0:u.documentId)===o.documentId?u:null;return await Di({documentId:o.documentId,content:w.content,displayName:o.displayName,localBaseCommitIdAtEditStart:(j==null?void 0:j.headCommitId)??null,snapshotMeta:j?{permission:j.permission,ownerVisitorId:j.ownerVisitorId,domainId:j.domainId}:void 0}),(u==null?void 0:u.documentId)===o.documentId?(O({documentId:o.documentId,content:w.content,displayName:o.displayName}),ie(L=>L+1),S(!0)):await Te(o.documentId),U("帮写已写入草稿,可在编辑器中继续修改后发布"),{documentId:o.documentId}}const f=await an({fileName:bn(o.displayName),displayName:o.displayName,content:o.markdown,contentFormat:"markdown",domainId:F||void 0,parentId:void 0});return await V(),await Te(f.documentId),U("已创建文档"),{documentId:f.documentId}}a.useEffect(()=>{Sn()},[]),a.useEffect(()=>{if(!Ne)return;const o=()=>{U(null)};return window.addEventListener("pointerdown",o,!0),()=>window.removeEventListener("pointerdown",o,!0)},[Ne]),a.useEffect(()=>{const o=f=>{var j,L;const c=f;if(((j=c.detail)==null?void 0:j.status)===409)return;const w=(L=c.detail)==null?void 0:L.message;w&&K(w)};return window.addEventListener(ut,o),()=>window.removeEventListener(ut,o)},[]);async function Sn(){try{const o=await qt();E(o),qe(o.visitorId),await lt(o.visitorId,_,H,V),s("ready")}catch(o){if(o instanceof oe&&o.status===401){s("needsRegister");return}K(me(e,o)),s("needsRegister")}}async function kn(o,f){const c=await _o(o,f);E(c.visitor),y(c.visitor.visitorId),b(c.recoveryCode),qe(c.visitor.visitorId),await lt(c.visitor.visitorId,_,H,V),s("ready")}async function Nn(o){const f=await qt();E(f),await lt(f.visitorId,_,H,V),s("ready")}async function V(o){const c=await Uo(o??F);P(c)}function He(o){O({documentId:o.documentId,content:o.content,displayName:o.displayName}),ie(f=>f+1),S(!1)}function Pn(o,f){O({documentId:o,content:f.content,displayName:f.displayName}),ie(c=>c+1),S(!0)}async function St(o,f){await st(o);const c=await Me(o);if((u==null?void 0:u.documentId)===o&&v.current===o){N(je(c)),S(!1);const w=J.current,j=f!==void 0&&c.content===f,L=(w==null?void 0:w.documentId)===o&&w.content===c.content;j||L?(w==null?void 0:w.documentId)===o&&w.displayName!==c.displayName&&O({...w,displayName:c.displayName}):He(c)}return c}async function Te(o){v.current=o;try{const f=await G(o);if(v.current!==o)return;const c=await Me(o);if(v.current!==o||(c.domainId!==F&&(localStorage.setItem("mdocs.currentDomainId",c.domainId),H(c.domainId),V(c.domainId)),X(ze(c.relativePath)),c.headCommitId&&f&&!f.published&&(f.publishError===De.SYNC_HEAD_MISSING&&await dt(o),f.localBaseCommitId||await ye({...f,localBaseCommitId:c.headCommitId})),N(je(c)),v.current!==o))return;f&&!f.published?Pn(o,f):He(c)}catch(f){if(v.current!==o)return;K(me(e,f))}}a.useEffect(()=>{r==="ready"&&(Y?Te(Y):(N(null),O(null),fe(null)))},[r,Y]);const{createModal:we,setCreateModal:Ze,createModalError:kt,createModalBusy:xe,createModalInputRef:Tn,openNewDocumentModal:et,openNewFolderModal:tt,submitCreateModal:En}=vi({tree:A,currentDomainId:F,selectedCreateParentPath:Dt,t:e,onDocCreated:o=>{N(je(o)),He(o),X(ze(o.relativePath)),R(`/doc/${o.documentId}`)},refreshTree:V}),[An,Ue]=a.useState(!1),[jn,Ee]=a.useState(!1),[ge,Nt]=a.useState([]),[nt,Pt]=a.useState(""),[Ve,Tt]=a.useState(""),[Mn,Et]=a.useState(new Set);async function Rn(){try{const o=await Yo();Nt(o)}catch(o){K(me(e,o))}}const ot=a.useMemo(()=>{const o={};for(const f of T)o[f.domainId]=f.domainName;return o},[T]),At=a.useMemo(()=>{let o=ge;const f=nt.trim().toLowerCase();return f&&(o=o.filter(c=>{var w;return(w=c.displayName)==null?void 0:w.toLowerCase().includes(f)})),Ve&&(o=o.filter(c=>c.domainId===Ve)),o},[ge,nt,Ve]),On=a.useMemo(()=>{const o=new Set,f=[];for(const c of ge){const w=c.domainId;w&&!o.has(w)&&(o.add(w),f.push({id:w,name:ot[w]??w}))}return f},[ge,ot]);async function Ln(o,f,c,w,j){let L=await G(o);!L&&(u==null?void 0:u.documentId)===o&&(L={documentId:o,content:f,displayName:c,updatedAt:Date.now(),published:!1,localBaseCommitId:w,permission:u.permission,ownerVisitorId:u.ownerVisitorId,domainId:u.domainId},await ye(L)),L&&await Zt(o,{localBaseCommitId:w,conflictStatus:"publish_conflict",conflict:{localBaseCommitId:w,remoteCommitId:j.headCommitId,localSnapshotContent:f}}),re(!0)}async function Fn(o,f,c,w){return $t(c).execute(async()=>{const j=await G(c),L=(j==null?void 0:j.localBaseCommitId)??(u==null?void 0:u.headCommitId);if(!L)throw K(e("syncHeadMissing")),new Error("missing localBaseCommitId");try{await Gt(c,{content:o,displayName:f,permission:w,version:{localBaseCommitId:L}}),await ct(c),await St(c,o),await V(),re(!1),U(e("published")),window.setTimeout(()=>U(null),1200)}catch(ee){throw ee instanceof oe&&ee.status===409&&ee.code==="VERSION_CONFLICT"&&ee.details&&typeof ee.details=="object"&&await Ln(c,o,f,L,ee.details),ee}})}async function _n(){if(!u)return;const o=await Me(u.documentId);o.domainId!==F&&(localStorage.setItem("mdocs.currentDomainId",o.domainId),H(o.domainId),V(o.domainId)),X(ze(o.relativePath)),N(je(o)),He(o),U(e("syncPullDone")),window.setTimeout(()=>U(null),1200)}async function jt(){if(!u)return;const o=await G(u.documentId);if(o&&!o.published)return;if((o==null?void 0:o.conflictStatus)==="publish_conflict"||(o==null?void 0:o.conflictStatus)==="diverged"||!!(o!=null&&o.conflict)){pe(!0);return}await _n()}async function Bn(o){await ct(o.documentId),await st(o.documentId),S(!1),pe(!1),re(!1),await Te(o.documentId),V(o.domainId),U(e("published")),window.setTimeout(()=>U(null),1200)}async function $n(o,f,c){try{await Pi(o,f,c)}catch(w){if(!(w instanceof Re))throw w;const j=c??await G(o);throw U(Ni(e,j,w.code,w.cause??f)),window.setTimeout(()=>U(null),4e3),w}}async function Mt(o){let f;try{await $t(o).execute(async()=>{const c=await G(o);if(!c)return;f=c;let w=c.localBaseCommitId;if(w||(w=(await Me(o)).headCommitId??void 0,w&&(await ye({...c,localBaseCommitId:w}),c.publishError===De.SYNC_HEAD_MISSING&&await dt(o))),!w)throw new Re(De.SYNC_HEAD_MISSING);const j=await G(o);j&&(await Gt(o,{content:j.content,displayName:j.displayName,version:{localBaseCommitId:w}}),await ct(o),await dt(o),(u==null?void 0:u.documentId)===o?await St(o,j.content):await st(o),await V(),U(e("published")),window.setTimeout(()=>U(null),1200))})}catch(c){await $n(o,c,f)}}function Rt(o,f){Oe({type:"document",id:o,name:f})}function Ot(o,f){Oe({type:"folder",id:o,name:f})}async function Hn(o,f){try{const c=await zo(o,f);await V(c.domainId),(u==null?void 0:u.documentId)===o&&(N(je(c)),X(ze(c.relativePath)))}catch(c){c instanceof oe?c.status===409&&K(c.message):K(me(e,c))}}async function Un(){if(q)try{q.type==="document"?(await Wo(q.id),(u==null?void 0:u.documentId)===q.id&&(N(null),O(null),X(""),R("/"))):q.type==="folder"&&(await Go(q.id),u&&(N(null),O(null),X(""),R("/"))),await V(),U(q.type==="folder"?`已删除「${q.name}」及其下所有内容`:`已删除「${q.name}」`),window.setTimeout(()=>U(null),2e3)}catch(o){K(me(e,o))}finally{Oe(null)}}return r==="loading"?n.jsx("div",{className:"mdocs-loading muted",children:e("loading")}):r==="needsRegister"?n.jsx(ti,{onSubmit:kn,onRecover:Nn,error:Ne}):n.jsxs("div",{className:"mdocs-app-root",children:[rn(),n.jsxs("div",{className:"mdocs-shell",children:[$&&C&&n.jsx(ni,{visitorId:$,onDismiss:()=>y(null)}),I&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:o=>{o.target===o.currentTarget&&b(null)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480,textAlign:"center"},children:[n.jsx("h1",{style:{fontSize:"1.25rem",marginBottom:8},children:"🔑 保存你的恢复码"}),n.jsxs("p",{className:"muted",style:{marginBottom:16,lineHeight:1.5},children:["恢复码是你的唯一凭证,当 Token 丢失时可用它找回身份。",n.jsx("br",{}),n.jsx("strong",{children:"请立即复制保存,此弹窗关闭后不可再查看。"})]}),n.jsx("div",{style:{background:"#f5f5f5",borderRadius:8,padding:"12px 16px",fontFamily:"monospace",fontSize:"1.25rem",letterSpacing:"0.1em",marginBottom:20,userSelect:"all"},children:I}),n.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"center"},children:[n.jsx("button",{type:"button",className:"primary",onClick:()=>{navigator.clipboard.writeText(I)},children:"复制恢复码"}),n.jsx("button",{type:"button",onClick:()=>b(null),children:"已保存,关闭"})]})]})}),n.jsxs(n.Fragment,{children:[n.jsx(fi,{open:Qe,onToggle:()=>be(o=>!o),position:Ct,onPositionChange:yn}),Qe?n.jsx(a.Suspense,{fallback:null,children:n.jsx(Oi,{open:Qe,onClose:()=>be(!1),visitorName:C==null?void 0:C.visitorName,anchorStyle:ui(Ct),onOpenDocument:o=>{Le("docs"),Z(()=>R(`/doc/${o}`)),be(!1)},onTreeChanged:()=>void V(),onDocumentOverwritten:o=>void Dn(o),onOpenCoding:o=>void In(o)})}):null]}),_e?n.jsx(a.Suspense,{fallback:null,children:n.jsx(Li,{open:vn,initialMarkdown:_e.markdown,documentId:_e.documentId,displayName:_e.displayName,onClose:()=>{Fe(!1),Be(null)},onComplete:Cn})}):null,gn==="settings"?n.jsx(a.Suspense,{fallback:n.jsx("div",{className:"mdocs-main muted",style:{padding:24},children:"加载设置…"}),children:n.jsx(Ri,{onBack:()=>Le("docs"),onPublishDraft:Mt,onOpenDocument:Te,onRecoverDraft:()=>void V()})}):n.jsxs("div",{className:"mdocs-layout",children:[n.jsxs("aside",{className:`mdocs-sidebar ${d?"mdocs-sidebar-collapsed":""}`,children:[n.jsxs("header",{className:"mdocs-sidebar-header",children:[n.jsxs("div",{className:"mdocs-brand",children:[n.jsx("img",{src:ji,alt:e("brand"),className:"mdocs-brand-logo"}),n.jsx("span",{children:e("brand")})]}),n.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:p,"aria-label":e(d?"expandSidebar":"collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f0f0f0)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},children:d?n.jsx(yo,{size:18}):n.jsx(ho,{size:18})})]}),n.jsxs("div",{className:"mdocs-sidebar-actions",children:[n.jsx("span",{className:"mdocs-sidebar-icon mdocs-tooltip","data-tooltip":e("newDocument"),onClick:()=>et(),style:{color:"var(--mdocs-accent)"},children:n.jsx(Ft,{size:20})}),n.jsx("span",{className:"mdocs-sidebar-icon mdocs-tooltip","data-tooltip":e("newFolder"),onClick:()=>tt(),children:n.jsx(_t,{size:20})})]}),n.jsx(oi,{nodes:A,activeDocumentId:Y??null,selectedParentPath:Dt,onOpen:o=>{Z(()=>R(`/doc/${o.documentId}`))},onOpenFolder:(o,f)=>{Z(()=>{X(o),f&&R(`/doc/${f}`)})},onContextMenu:It,onMoveDocument:Hn,onDeselect:()=>{Z(()=>{X(""),R("/")})}}),n.jsxs("footer",{className:"mdocs-sidebar-footer",children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,cursor:"pointer"},onClick:()=>Z(()=>Le("settings")),children:[n.jsx("span",{className:"mdocs-visitor-avatar",children:C?C.visitorName.charAt(0).toUpperCase():"?"}),n.jsx("span",{className:"mdocs-visitor-footer-name",children:C?C.visitorName:""})]}),n.jsx("button",{type:"button",className:"mdocs-sidebar-bookmark mdocs-tooltip","data-tooltip":e("bookmark"),onClick:()=>{Ee(!0),Pt(""),Tt(""),Rn()},style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",fontSize:"1rem",lineHeight:1,borderRadius:4},children:n.jsx(bo,{size:16,strokeWidth:1.5})}),n.jsx("button",{type:"button",className:"mdocs-sidebar-logout mdocs-tooltip","data-tooltip":e("logout"),onClick:()=>Ue(!0),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",lineHeight:1,borderRadius:4},children:n.jsx(mo,{size:16,strokeWidth:1.5})})]})]}),n.jsxs("main",{className:"mdocs-main",children:[u&&M&&M.documentId===u.documentId?n.jsxs("div",{className:"mdocs-editor-with-comments",children:[n.jsx("div",{className:"mdocs-editor-container",children:n.jsx(a.Suspense,{fallback:n.jsx("div",{className:"muted",style:{padding:24},children:"加载编辑器…"}),children:n.jsx(Mi,{meta:u,initialContent:M.content,initialDisplayName:M.displayName,contentRevision:Je,canEdit:!!(C&&(u.ownerVisitorId===C.visitorId||No(u.permission)||u.invitedEdit===!0)),domains:T,currentDomainId:F,onDomainChange:o=>{Z(()=>{localStorage.setItem("mdocs.currentDomainId",o),H(o),N(null),O(null),X(""),R("/"),V(o)})},onDomainsChange:_,onPublish:Fn,syncBehind:B,onSyncClick:()=>void jt(),onDraftExistsChange:S,onConflictModalRequest:()=>re(!0),onMergeRequest:()=>pe(!0),canManageInvites:!!(C&&C.visitorId===u.ownerVisitorId),onDelete:async()=>{if(u.relativePath.endsWith("/___desc___.md")){const o=u.relativePath.replace(/\/___desc___\.md$/,"");Ot(u.documentId,o)}else Rt(u.documentId,u.relativePath)},saveBeforeNavRef:Q,exportMarkdownRef:$e,onShowToast:U,onShowError:K,onToggleComments:()=>m(!h),commentPanelOpen:h,commentCount:g,onAiWrite:()=>void wn()},u.documentId)})}),h&&n.jsx(wi,{documentId:u.documentId,visitorId:C==null?void 0:C.visitorId,visitorName:C==null?void 0:C.visitorName,documentOwnerId:u.ownerVisitorId,onClose:()=>m(!1)})]}):n.jsxs("div",{className:"mdocs-welcome",children:[n.jsx("h1",{children:e("brand")}),n.jsx("p",{className:"muted mdocs-welcome-lead",children:A.length===0?e("noDocsInDomain"):e("createDocToStart")}),n.jsxs("div",{className:"mdocs-welcome-domain",children:[n.jsx("label",{className:"muted mdocs-welcome-domain-label",children:e("domainLabel")}),n.jsx(di,{domains:T.length?T:[{domainId:"default",domainName:e("defaultDomain"),permission:"",creatorVisitorId:"",docCount:0}],value:F,onChange:o=>{Z(()=>{localStorage.setItem("mdocs.currentDomainId",o),H(o),N(null),O(null),X(""),R("/"),V(o)})},onDomainsChange:_,ariaLabel:e("domainLabel"),localizeName:o=>gi(o,t,e)})]}),n.jsxs("div",{className:"mdocs-welcome-actions",children:[n.jsxs("button",{type:"button",className:"primary",onClick:()=>et(),style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx(Ft,{size:16,strokeWidth:1.5}),e("newDocument")]}),n.jsxs("button",{type:"button",className:"secondary",onClick:()=>tt(),style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx(_t,{size:16,strokeWidth:1.5}),e("newFolder")]}),n.jsxs("button",{type:"button",className:"secondary",onClick:()=>xn(),style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("img",{src:mn,alt:"",width:16,height:16,style:{display:"block"}}),"AI 帮写"]})]})]}),n.jsx(bi,{open:Ke,onClose:()=>re(!1),onResolve:()=>{re(!1),pe(!0)}}),ke&&u&&wt&&n.jsx(a.Suspense,{fallback:n.jsx("div",{className:"merge-view-loading",children:e("mergeLoadingRemote")}),children:n.jsx(Fi,{documentId:u.documentId,displayName:u.displayName,conflict:wt,onClose:()=>pe(!1),onSuccess:Bn,onError:o=>K(o)})}),Ne&&n.jsx("div",{className:"mdocs-toast",role:"status",children:Ne}),xt&&n.jsx(hi,{title:e("error"),message:xt,onClose:()=>K(null)})]}),An&&n.jsx("div",{className:"mdocs-dialog-backdrop",onClick:o=>{o.target===o.currentTarget&&Ue(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:440},children:[n.jsx("h1",{style:{fontSize:"1.125rem",marginBottom:8},children:"退出当前登录身份?"}),n.jsx("p",{style:{lineHeight:1.6,color:"var(--mdocs-text-secondary, #666)",marginBottom:20},children:"这将会导致您无法修改以前的文章。如果想找回账号,需要恢复码或联系管理员执行合并用户脚本。"}),n.jsxs("div",{className:"mdocs-dialog-actions",style:{justifyContent:"flex-end"},children:[n.jsx("button",{type:"button",onClick:()=>Ue(!1),children:"取消"}),n.jsx("button",{type:"button",className:"primary",style:{background:"#d32f2f"},onClick:()=>{Fo(),N(null),O(null),E(null),P([]),Ue(!1),s("needsRegister")},children:"确认退出"})]})]})}),jn&&n.jsx("div",{className:"mdocs-dialog-backdrop",onClick:o=>{o.target===o.currentTarget&&Ee(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:640,width:"min(640px, 100%)",maxHeight:"70vh",display:"flex",flexDirection:"column"},children:[n.jsxs("h1",{style:{fontSize:"1.125rem",marginBottom:16},children:[e("bookmarkTitle"),"(",ge.length,")"]}),ge.length>0&&n.jsxs("div",{className:"mdocs-bookmark-filterbar",children:[n.jsx("input",{type:"text",placeholder:e("bookmarkSearch"),value:nt,onChange:o=>Pt(o.target.value)}),n.jsxs("select",{value:Ve,onChange:o=>Tt(o.target.value),children:[n.jsx("option",{value:"",children:e("bookmarkFilterAll")}),On.map(o=>n.jsx("option",{value:o.id,children:o.name},o.id))]})]}),ge.length===0?n.jsx("p",{style:{color:"var(--mdocs-text-muted, #999)",textAlign:"center",padding:"2rem 0"},children:e("bookmarkEmpty")}):At.length===0?n.jsx("p",{style:{color:"var(--mdocs-text-muted, #999)",textAlign:"center",padding:"2rem 0"},children:e("bookmarkNoMatch")}):n.jsx("div",{style:{overflowY:"auto",flex:1,margin:"0 -1rem",padding:"0 1rem"},children:n.jsxs("table",{className:"mdocs-bookmark-table",children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:e("bookmarkColTitle")}),n.jsx("th",{children:e("bookmarkColDomain")}),n.jsx("th",{children:e("bookmarkColAuthor")}),n.jsx("th",{children:e("bookmarkColTime")}),n.jsx("th",{className:"mdocs-bookmark-col-action"})]})}),n.jsx("tbody",{children:At.map(o=>{const f=Mn.has(o.documentId);return n.jsxs("tr",{className:`${f?"mdocs-bookmark-removing":""}`,style:{opacity:o.isDeleted?.6:1},children:[n.jsx("td",{className:"mdocs-bookmark-col-title",children:n.jsxs("div",{style:{cursor:o.isDeleted?"default":"pointer",display:"flex",alignItems:"center",gap:6,overflow:"hidden"},onClick:()=>{o.isDeleted||Z(()=>{Ee(!1),R(`/doc/${o.documentId}`)})},children:[n.jsx("span",{ref:c=>{if(c){const w=c.scrollWidth>c.clientWidth;c.title=w?o.displayName??"":""}},style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:o.displayName??"(无标题)"}),o.isDeleted&&n.jsx("span",{style:{fontSize:"0.7rem",color:"#d32f2f",background:"#ffebee",padding:"1px 6px",borderRadius:4,flexShrink:0},children:"已删除"})]})}),n.jsx("td",{children:o.isDeleted?"":ot[o.domainId??""]??o.domainId??""}),n.jsx("td",{children:o.isDeleted?"":o.ownerVisitorName??"-"}),n.jsx("td",{children:o.isDeleted?"":_i(o.bookmarkedAt,t)}),n.jsx("td",{className:"mdocs-bookmark-col-action",children:n.jsxs("div",{style:{display:"flex",gap:2,alignItems:"center",justifyContent:"flex-end"},children:[n.jsx("button",{type:"button",className:"mdocs-tooltip","data-tooltip":e("bookmarkOpen"),onClick:()=>{o.isDeleted||Z(()=>{Ee(!1),R(`/doc/${o.documentId}`)})},style:{background:"none",border:"none",cursor:o.isDeleted?"default":"pointer",padding:"4px",color:"var(--mdocs-text-muted, #999)",lineHeight:1,borderRadius:4,display:"inline-flex",alignItems:"center"},children:n.jsx(ao,{size:14,strokeWidth:1.5})}),n.jsx("button",{type:"button",className:"mdocs-tooltip","data-tooltip":e("bookmarkRemove"),onClick:async()=>{try{await Jo(o.documentId),Et(c=>new Set(c).add(o.documentId)),setTimeout(()=>{Nt(c=>c.filter(w=>w.documentId!==o.documentId)),Et(c=>{const w=new Set(c);return w.delete(o.documentId),w})},300)}catch(c){K(me(e,c))}},style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--mdocs-text-muted, #999)",fontSize:"1rem",lineHeight:1,borderRadius:4,display:"inline-flex",alignItems:"center"},onMouseEnter:c=>{c.currentTarget.style.color="#d32f2f"},onMouseLeave:c=>{c.currentTarget.style.color="var(--mdocs-text-muted, #999)"},children:"✕"})]})})]},o.documentId)})})]})}),n.jsx("div",{className:"mdocs-dialog-actions",style:{justifyContent:"flex-end",marginTop:16,paddingTop:16,borderTop:"1px solid var(--mdocs-border, #eee)"},children:n.jsx("button",{type:"button",onClick:()=>Ee(!1),children:e("close")})})]})}),Pe&&n.jsx(si,{x:Pe.x,y:Pe.y,node:Pe.node,parentPath:Pe.parentPath,onClose:()=>It(null),onCreateChild:o=>et(o),onCreateFolder:o=>tt(o),onDeleteDocument:o=>Rt(o.documentId,o.path),onDeleteFolder:o=>Ot(o.documentId,o.folderDisplayName||o.name)}),q&&n.jsx(un,{title:q.type==="folder"?"删除文件夹":"删除文档",message:q.type==="folder"?`确定要删除「${q.name}」及其下的所有文档和子文件夹吗?此操作不可撤销。`:`确定要删除「${q.name}」吗?`,confirmLabel:"删除",cancelLabel:"取消",onConfirm:Un,onCancel:()=>Oe(null),danger:!0}),we&&n.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:o=>{o.target===o.currentTarget&&!xe&&Ze(null)},children:n.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[n.jsx("h1",{children:we.kind==="document"?e("newDocumentTitle"):e("newFolderTitle")}),n.jsx("p",{className:"muted",children:we.kind==="document"?e("fileNameHint"):e("folderNameHint")}),n.jsxs("form",{onSubmit:En,className:"mdocs-dialog-form",children:[n.jsxs("label",{className:"mdocs-dialog-label",children:[we.kind==="document"?e("fileNameLabel"):e("folderNameLabel"),n.jsx("input",{ref:Tn,value:we.draft,onChange:o=>Ze(f=>f&&{...f,draft:o.target.value}),placeholder:we.kind==="document"?e("untitledPlaceholder"):e("folderExamplePlaceholder"),maxLength:200,disabled:xe})]}),kt&&n.jsx("div",{className:"mdocs-dialog-error",children:kt}),n.jsxs("div",{className:"mdocs-dialog-actions",children:[n.jsx("button",{type:"button",onClick:()=>!xe&&Ze(null),disabled:xe,children:e("cancel")}),n.jsx("button",{type:"submit",className:"primary",disabled:xe,children:e(xe?"creating":"create")})]})]})]})})]})]})]})}const Bi=a.lazy(()=>Ce(()=>import("./PlaygroundPage-hHfIzPO5.js"),__vite__mapDeps([16,1,4,5,2,3,6,7,8,9])).then(e=>({default:e.PlaygroundPage})));function $i(){return n.jsxs(Gn,{children:[n.jsx(it,{path:"/",element:n.jsx(en,{})}),n.jsx(it,{path:"/doc/:documentId",element:n.jsx(en,{})}),n.jsx(it,{path:"/playground",element:n.jsx(a.Suspense,{fallback:n.jsx("div",{style:{padding:24},children:"Loading playground…"}),children:n.jsx(Bi,{})})})]})}const hn=document.getElementById("root");if(!hn)throw new Error("root element missing");Yn.createRoot(hn).render(n.jsx(Jn.StrictMode,{children:n.jsx(Xn,{motion:Zn,children:n.jsx(Qn,{children:n.jsx(So,{children:n.jsx(Kn,{children:n.jsx($i,{})})})})})}));export{Ir as $,Re as A,Ji as B,Ho as C,di as D,Or as E,Zo as F,ar as G,rr as H,ir as I,or as J,cr as K,Ki as L,fo as M,Qi as N,Xi as O,Zi as P,dr as Q,sr as R,bo as S,lr as T,mr as U,ur as V,qt as W,Dr as X,Cr as Y,br as Z,Yo as _,G as a,ji as a0,rn as a1,un as a2,tr as a3,er as a4,vr as a5,Sr as a6,Nr as a7,Ae as a8,kr as a9,Pr as aa,Tr as ab,Er as ac,Rr as ad,Mr as ae,jr as af,Ar as ag,Me as ah,fr as ai,rt as aj,Gt as ak,ho as al,de as b,se as c,st as d,wr as e,nr as f,$t as g,qi as h,mn as i,pr as j,xr as k,gi as l,te as m,gr as n,hr as o,yr as p,sn as q,Jo as r,Uo as s,oi as t,Di as u,an as v,me as w,Ci as x,Ni as y,dt as z};
185
+ `);l=k.pop()??"";for(const v of k){const C=v.trim();if(!C.startsWith("data:"))continue;const E=C.slice(5).trim();if(!(!E||E==="[DONE]"))try{t.onEvent(JSON.parse(E))}catch{}}}const p=l.trim();if(p.startsWith("data:")){const m=p.slice(5).trim();if(m&&m!=="[DONE]")try{t.onEvent(JSON.parse(m))}catch{}}}const Zo={domainId:Ge,domainName:"Default",permission:"public",creatorVisitorId:"",docCount:0};async function sn(){try{return await Ho()}catch{return[Zo]}}function ei(e,t){var i,r,s;return((i=e.find(d=>d.domainId===t))==null?void 0:i.domainId)??((r=e.find(d=>d.domainId===Ge))==null?void 0:r.domainId)??((s=e[0])==null?void 0:s.domainId)??Ge}function ti(e){const{t}=de(),[i,r]=a.useState(!1),[s,d]=a.useState(null),[l,p]=a.useState("register"),[h,m]=a.useState(1),[g,k]=a.useState(""),[v,C]=a.useState(""),[E,$]=a.useState("password"),[y,I]=a.useState(""),[b,A]=a.useState(""),[P,T]=a.useState("");function _(N){if(N.preventDefault(),!g.trim()){d(t("nameRequired"));return}d(null),m(2)}async function F(N){N.preventDefault(),r(!0),d(null);try{const M=v.trim();await e.onSubmit(g.trim(),M||void 0)}catch(M){d(M instanceof Error?M.message:String(M)),m(1)}finally{r(!1)}}async function H(N){N.preventDefault();const M=y.trim(),O=b.trim();if(!M||!O){d("请输入用户名和密码");return}r(!0),d(null);try{const J=await $o(M,O);qe(J.visitor.visitorId),await e.onRecover(J.visitor.visitorId)}catch(J){d(J instanceof Error?J.message:String(J))}finally{r(!1)}}async function Y(N){N.preventDefault();const M=P.trim();if(!M){d("请输入恢复码");return}r(!0),d(null);try{const O=await Bo(M);qe(O.visitor.visitorId),await e.onRecover(O.visitor.visitorId)}catch(O){d(O instanceof Error?O.message:String(O))}finally{r(!1)}}const R=s??e.error;function u(N){d(null),p(N)}return n.jsx("div",{className:"mdocs-dialog-backdrop",children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:420},children:[n.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--mdocs-border)",marginBottom:16},children:[n.jsx("button",{type:"button",onClick:()=>u("register"),style:{flex:1,padding:"12px",border:"none",background:l==="register"?"var(--mdocs-bg)":"none",color:l==="register"?"var(--mdocs-text)":"var(--mdocs-text-secondary)",cursor:"pointer",fontWeight:l==="register"?600:400,borderBottom:l==="register"?"2px solid var(--mdocs-accent)":"none"},children:"注册"}),n.jsx("button",{type:"button",onClick:()=>u("login"),style:{flex:1,padding:"12px",border:"none",background:l==="login"?"var(--mdocs-bg)":"none",color:l==="login"?"var(--mdocs-text)":"var(--mdocs-text-secondary)",cursor:"pointer",fontWeight:l==="login"?600:400,borderBottom:l==="login"?"2px solid var(--mdocs-accent)":"none"},children:"登录"})]}),l==="register"&&n.jsx(n.Fragment,{children:h===1?n.jsxs(n.Fragment,{children:[n.jsx("h1",{children:t("welcomeTitle")}),n.jsx("p",{children:t("welcomeDesc")}),n.jsxs("form",{onSubmit:_,children:[n.jsx("input",{autoFocus:!0,placeholder:t("visitorNamePlaceholder"),value:g,onChange:N=>k(N.target.value),maxLength:60}),R&&n.jsx("div",{className:"mdocs-dialog-error",children:R}),n.jsx("button",{type:"submit",className:"primary",disabled:i,children:"下一步"})]}),n.jsx("p",{style:{marginTop:16,textAlign:"center"},children:n.jsx("button",{type:"button",style:{background:"none",border:"none",color:"var(--mdocs-accent)",cursor:"pointer",fontSize:"0.875rem",textDecoration:"underline",padding:0},onClick:()=>u("login"),children:"已有账号?点击登录"})})]}):n.jsxs(n.Fragment,{children:[n.jsx("h1",{children:"设置密码(可选)"}),n.jsx("p",{style:{marginBottom:8},children:"设置密码后,你可以在其他浏览器或设备上使用「用户名+密码」登录。"}),n.jsx("p",{style:{color:"var(--mdocs-text-secondary)",fontSize:"0.875rem",marginBottom:16},children:"留空不设置密码也能正常使用,但只能在当前浏览器操作。"}),n.jsxs("form",{onSubmit:F,children:[n.jsx("input",{autoFocus:!0,type:"password",placeholder:"设置密码(至少 4 位)",value:v,onChange:N=>C(N.target.value),minLength:4}),R&&n.jsx("div",{className:"mdocs-dialog-error",children:R}),n.jsx("button",{type:"submit",className:"primary",disabled:i,style:{marginTop:8},children:i?t("creating"):"完成注册"})]}),n.jsx("p",{style:{marginTop:16,textAlign:"center"},children:n.jsx("button",{type:"button",style:{background:"none",border:"none",color:"var(--mdocs-text-secondary)",cursor:"pointer",fontSize:"0.875rem",padding:0},onClick:()=>m(1),children:"← 返回上一步"})})]})}),l==="login"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16,marginBottom:16,fontSize:"0.875rem"},children:[n.jsx("button",{type:"button",onClick:()=>{d(null),$("password")},style:{background:"none",border:"none",color:E==="password"?"var(--mdocs-accent)":"var(--mdocs-text-secondary)",cursor:"pointer",padding:"4px 0",borderBottom:E==="password"?"2px solid var(--mdocs-accent)":"none",fontWeight:E==="password"?600:400},children:"用户名+密码"}),n.jsx("button",{type:"button",onClick:()=>{d(null),$("recovery")},style:{background:"none",border:"none",color:E==="recovery"?"var(--mdocs-accent)":"var(--mdocs-text-secondary)",cursor:"pointer",padding:"4px 0",borderBottom:E==="recovery"?"2px solid var(--mdocs-accent)":"none",fontWeight:E==="recovery"?600:400},children:"恢复码"})]}),E==="password"?n.jsxs(n.Fragment,{children:[n.jsx("h1",{children:"🔑 使用密码登录"}),n.jsx("p",{children:"输入用户名和密码,在其他设备上找回你的身份。"}),n.jsxs("form",{onSubmit:H,children:[n.jsx("input",{autoFocus:!0,placeholder:"用户名",value:y,onChange:N=>I(N.target.value),maxLength:60,style:{marginBottom:8}}),n.jsx("input",{type:"password",placeholder:"密码",value:b,onChange:N=>A(N.target.value)}),R&&n.jsx("div",{className:"mdocs-dialog-error",children:R}),n.jsx("button",{type:"submit",className:"primary",disabled:i,children:i?"验证中…":"登录"})]}),n.jsx("p",{style:{marginTop:16,textAlign:"center"},children:n.jsx("button",{type:"button",style:{background:"none",border:"none",color:"var(--mdocs-accent)",cursor:"pointer",fontSize:"0.875rem",textDecoration:"underline",padding:0},onClick:()=>u("register"),children:"没有账号?去注册"})})]}):n.jsxs(n.Fragment,{children:[n.jsx("h1",{children:"🔑 使用恢复码找回"}),n.jsx("p",{children:"输入注册时保存的恢复码,系统将为您生成新的身份令牌。"}),n.jsxs("form",{onSubmit:Y,children:[n.jsx("input",{autoFocus:!0,placeholder:"ABCD-EFGH-IJKL-MNOP",value:P,onChange:N=>T(N.target.value),style:{fontFamily:"monospace",letterSpacing:"0.1em"},maxLength:30}),R&&n.jsx("div",{className:"mdocs-dialog-error",children:R}),n.jsx("button",{type:"submit",className:"primary",disabled:i,children:i?"验证中…":"找回身份"})]})]})]})]})})}function ni(e){const{t}=de();return n.jsxs("div",{className:"mdocs-notice card",children:[n.jsx("span",{children:t("visitorIdNotice",{id:e.visitorId})}),n.jsx("button",{type:"button",onClick:e.onDismiss,children:t("gotIt")})]})}const dn="application/x-mdocs-document-id",ft="mdocs-doc:";let ve=null;function cn(e,t,i=[]){for(const r of e){if(r.type==="document"){if(r.documentId===t)return{forceOpenFolderIds:i,scrollTreeId:r.documentId};continue}if(r.descDocumentId===t)return{forceOpenFolderIds:i,scrollTreeId:r.documentId};const s=cn(r.children,t,[...i,r.documentId]);if(s)return s}return null}function gt(e){if(ve)return ve;try{const t=e.getData(dn);if(t)return t;const i=e.getData("text/plain")||e.getData("Text");if(i.startsWith(ft))return i.slice(ft.length)}catch{}return""}function ue(e){return!!(e&&ve)}function oi(e){const{t}=de(),i=a.useRef(null),[r,s]=a.useState(null),[d,l]=a.useState(null),p=a.useMemo(()=>{var I;const y=(I=e.activeDocumentId)==null?void 0:I.trim();return y?cn(e.nodes,y):null},[e.nodes,e.activeDocumentId]),h=a.useMemo(()=>new Set((p==null?void 0:p.forceOpenFolderIds)??[]),[p]);a.useEffect(()=>{if(!(p!=null&&p.scrollTreeId))return;const y=p.scrollTreeId,I=()=>{var P;const A=(P=i.current)==null?void 0:P.querySelector(`[data-tree-id="${CSS.escape(y)}"]`);A==null||A.scrollIntoView({block:"nearest",behavior:"smooth"})},b=requestAnimationFrame(()=>{requestAnimationFrame(I)});return()=>cancelAnimationFrame(b)},[p==null?void 0:p.scrollTreeId,h,e.nodes]);function m(){s(null)}function g(){ve=null,l(null),m()}function k(y){ve=y,l(y),m()}function v(y){if(!ue(e.onMoveDocument))return;y.preventDefault(),y.dataTransfer.dropEffect="move",y.target.closest(".mdocs-tree-row")||s({kind:"root"})}function C(y){const I=y.relatedTarget;I&&y.currentTarget.contains(I)||s(b=>(b==null?void 0:b.kind)==="root"?null:b)}function E(y){if(!e.onMoveDocument||!ue(e.onMoveDocument))return;y.preventDefault(),y.stopPropagation();const b=y.target.closest(".mdocs-tree-row"),A=gt(y.dataTransfer);g(),!b&&A&&e.onMoveDocument(A,null)}const $="mdocs-sidebar-list"+((r==null?void 0:r.kind)==="root"?" mdocs-tree-drop-root":"");return e.nodes.length===0?n.jsx("div",{ref:i,className:$,onDragOver:v,onDragLeave:C,onDrop:E,children:n.jsx("div",{className:"muted",style:{padding:"8px 10px",fontSize:12},children:t("noDocumentsYet")})}):n.jsx("div",{ref:i,className:$,onClick:y=>{var b;y.target.closest(".mdocs-tree-row")||(b=e.onDeselect)==null||b.call(e)},onContextMenu:y=>{y.preventDefault(),e.onContextMenu({x:y.clientX,y:y.clientY,node:{type:"folder",name:"",path:"",documentId:"",children:e.nodes},parentPath:""})},onDragOver:v,onDragLeave:C,onDrop:E,children:e.nodes.map(y=>n.jsx(ln,{node:y,depth:0,parentPath:"",parentFolderId:null,activeDocumentId:e.activeDocumentId,selectedParentPath:e.selectedParentPath,forceOpenFolderIds:h,dropHighlight:r,setDropHighlight:s,clearDropHighlight:m,beginDragSession:k,endDragSession:g,draggingId:d,onOpen:e.onOpen,onOpenFolder:e.onOpenFolder,onContextMenu:e.onContextMenu,onMoveDocument:e.onMoveDocument},y.path))})}function ln(e){const t={paddingLeft:8+e.depth*16};return e.node.type==="folder"?n.jsx(ai,{folder:e.node,depth:e.depth,indent:t,activeDocumentId:e.activeDocumentId,selectedParentPath:e.selectedParentPath,forceOpenFolderIds:e.forceOpenFolderIds,dropHighlight:e.dropHighlight,setDropHighlight:e.setDropHighlight,clearDropHighlight:e.clearDropHighlight,beginDragSession:e.beginDragSession,endDragSession:e.endDragSession,draggingId:e.draggingId,onOpen:e.onOpen,onOpenFolder:e.onOpenFolder,onContextMenu:e.onContextMenu,onMoveDocument:e.onMoveDocument}):n.jsx(ii,{doc:e.node,indent:t,parentPath:e.parentPath,parentFolderId:e.parentFolderId,activeDocumentId:e.activeDocumentId,dropHighlight:e.dropHighlight,setDropHighlight:e.setDropHighlight,clearDropHighlight:e.clearDropHighlight,beginDragSession:e.beginDragSession,endDragSession:e.endDragSession,draggingId:e.draggingId,onOpen:e.onOpen,onContextMenu:e.onContextMenu,onMoveDocument:e.onMoveDocument})}function ii(e){var h;const t=e.doc,i=t.documentId===e.activeDocumentId,r=!!e.onMoveDocument,s=e.draggingId===t.documentId,d=((h=e.dropHighlight)==null?void 0:h.kind)==="doc"&&e.dropHighlight.id===t.documentId,[l,p]=a.useState(!1);return n.jsxs("div",{role:"button",tabIndex:0,className:"mdocs-tree-row mdocs-tree-doc"+(i?" active":"")+(s?" mdocs-tree-dragging":"")+(d?" mdocs-tree-drop-target":""),"data-tree-id":t.documentId,style:{...e.indent,cursor:r?"grab":void 0},draggable:r,onDragStart:m=>{e.onMoveDocument&&(p(!0),e.beginDragSession(t.documentId),m.dataTransfer.setData(dn,t.documentId),m.dataTransfer.setData("text/plain",ft+t.documentId),m.dataTransfer.effectAllowed="move")},onDragEnd:()=>{e.endDragSession(),queueMicrotask(()=>p(!1))},onDragEnter:m=>{!ue(e.onMoveDocument)||ve===t.documentId||(m.preventDefault(),m.stopPropagation(),e.setDropHighlight({kind:"doc",id:t.documentId}))},onDragOver:m=>{!ue(e.onMoveDocument)||ve===t.documentId||(m.preventDefault(),m.stopPropagation(),m.dataTransfer.dropEffect="move",e.setDropHighlight({kind:"doc",id:t.documentId}))},onDrop:m=>{if(!e.onMoveDocument||!ue(e.onMoveDocument))return;m.preventDefault(),m.stopPropagation();const g=gt(m.dataTransfer),k=e.parentFolderId;e.endDragSession(),!(!g||g===t.documentId)&&e.onMoveDocument(g,k)},onClick:()=>{l||e.onOpen(t)},onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),e.onOpen(t))},onContextMenu:m=>{m.preventDefault(),m.stopPropagation(),e.onContextMenu({x:m.clientX,y:m.clientY,node:t,parentPath:e.parentPath})},children:[n.jsx("span",{className:"mdocs-tree-caret-spacer","aria-hidden":!0}),n.jsx("span",{className:"mdocs-tree-icon",children:"md"}),n.jsx("span",{className:"mdocs-tree-label",children:t.displayName||t.name})]})}function ri(){return n.jsx("span",{className:"mdocs-tree-icon mdocs-tree-icon-dir","aria-hidden":!0,children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M2 4.5h4.2L7.3 6H14v8.5H2V4.5z",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"}),n.jsx("path",{d:"M2 4.5V3h4l1.1 1.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})]})})}function ai(e){var g,k;const{t}=de(),i=e.forceOpenFolderIds.has(e.folder.documentId),[r,s]=a.useState(e.depth<1||i),d=r;a.useEffect(()=>{i&&s(!0)},[i,e.activeDocumentId]);const l=!!e.folder.descDocumentId&&e.folder.descDocumentId===e.activeDocumentId,p=e.selectedParentPath===e.folder.path,h=((g=e.dropHighlight)==null?void 0:g.kind)==="folder"&&e.dropHighlight.id===e.folder.documentId;function m(){e.onOpenFolder(e.folder.path,e.folder.descDocumentId)}return n.jsxs("div",{children:[n.jsxs("div",{className:"mdocs-tree-row mdocs-tree-folder mdocs-tree-folder-row"+(l?" active":p?" mdocs-tree-select-target":"")+(h?" mdocs-tree-drop-target":""),"data-tree-id":e.folder.documentId,style:e.indent,onClick:m,onContextMenu:v=>{v.preventDefault(),v.stopPropagation(),e.onContextMenu({x:v.clientX,y:v.clientY,node:e.folder,parentPath:e.folder.path})},onDragEnter:v=>{ue(e.onMoveDocument)&&(v.preventDefault(),v.stopPropagation(),e.setDropHighlight({kind:"folder",id:e.folder.documentId}),s(!0))},onDragOver:v=>{ue(e.onMoveDocument)&&(v.preventDefault(),v.stopPropagation(),v.dataTransfer.dropEffect="move",e.setDropHighlight({kind:"folder",id:e.folder.documentId}))},onDrop:v=>{if(!e.onMoveDocument||!ue(e.onMoveDocument))return;v.preventDefault(),v.stopPropagation();const C=gt(v.dataTransfer),E=e.folder.documentId;e.endDragSession(),C&&e.onMoveDocument(C,E)},children:[n.jsx("span",{className:"mdocs-tree-caret",role:"button",tabIndex:0,"aria-expanded":d,"aria-label":t(d?"collapseFolder":"expandFolder"),onClick:v=>{v.stopPropagation(),s(C=>!C),m()},onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),s(C=>!C),m())},children:d?"▾":"▸"}),n.jsx(ri,{}),n.jsx("span",{className:"mdocs-tree-folder-select",children:n.jsx("span",{className:"mdocs-tree-label",children:((k=e.folder.folderDisplayName)==null?void 0:k.trim())||e.folder.name})})]}),d&&e.folder.children.map(v=>n.jsx(ln,{node:v,depth:e.depth+1,parentPath:e.folder.path,parentFolderId:e.folder.documentId,activeDocumentId:e.activeDocumentId,selectedParentPath:e.selectedParentPath,forceOpenFolderIds:e.forceOpenFolderIds,dropHighlight:e.dropHighlight,setDropHighlight:e.setDropHighlight,clearDropHighlight:e.clearDropHighlight,beginDragSession:e.beginDragSession,endDragSession:e.endDragSession,draggingId:e.draggingId,onOpen:e.onOpen,onOpenFolder:e.onOpenFolder,onContextMenu:e.onContextMenu,onMoveDocument:e.onMoveDocument},v.path))]})}function si(e){var p;const{t}=de(),i=a.useRef(null);a.useEffect(()=>{function h(g){i.current&&!i.current.contains(g.target)&&e.onClose()}function m(g){g.key==="Escape"&&e.onClose()}return window.addEventListener("mousedown",h),window.addEventListener("keydown",m),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",m)}},[e.onClose]);const r=e.node.type==="folder";let s="";if(e.node.type==="folder"){const h=e.node;s=((p=h.folderDisplayName)==null?void 0:p.trim())||h.path||""}const d=r?s?t("newDocIn",{name:s}):t("newDocAtRoot"):t("newDocBeside"),l=r?s?t("newFolderIn",{name:s}):t("newFolderAtRoot"):t("newFolderBeside");return n.jsxs("div",{ref:i,className:"mdocs-context-menu card",style:{left:e.x,top:e.y},children:[n.jsx("button",{type:"button",className:"mdocs-context-item",onClick:()=>{const h=r?e.node.path:e.parentPath;e.onCreateChild(h),e.onClose()},children:d}),n.jsx("button",{type:"button",className:"mdocs-context-item",onClick:()=>{const h=r?e.node.path:e.parentPath;e.onCreateFolder(h),e.onClose()},children:l}),n.jsx("button",{type:"button",className:"mdocs-context-item danger",onClick:()=>{e.node.type==="document"?e.onDeleteDocument(e.node):e.onDeleteFolder(e.node),e.onClose()},children:e.node.type==="folder"?t("deleteFolder",{name:s||e.node.name}):t("deleteItem",{name:e.node.name})})]})}function di({domains:e,value:t,onChange:i,ariaLabel:r,localizeName:s,onDomainsChange:d}){const[l,p]=a.useState(!1),[h,m]=a.useState(e),g=a.useRef(null),k=a.useRef(null);a.useEffect(()=>{m(e)},[e]);const v=h.find(y=>y.domainId===t),C=(v==null?void 0:v.permission)==="private";a.useEffect(()=>{if(!l)return;const y=I=>{var b,A;!((b=g.current)!=null&&b.contains(I.target))&&!((A=k.current)!=null&&A.contains(I.target))&&p(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[l]),a.useEffect(()=>{if(!l)return;const y=I=>{var b;I.key==="Escape"&&(p(!1),(b=g.current)==null||b.focus())};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[l]);function E(y){i(y),p(!1)}function $(){if(l){p(!1);return}p(!0),sn().then(y=>{m(y),d==null||d(y)})}return n.jsxs("div",{className:"mdocs-domain-select-wrapper",children:[n.jsxs("button",{ref:g,type:"button",className:"mdocs-domain-select-trigger","aria-label":r,"aria-expanded":l,"aria-haspopup":"listbox",onClick:$,children:[n.jsx("span",{className:"mdocs-domain-select-text",children:v?s(v.domainName):""}),C&&n.jsxs("svg",{className:"mdocs-domain-lock",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--mdocs-text-muted)",strokeWidth:"2",children:[n.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),n.jsx("svg",{className:"mdocs-domain-select-chevron"+(l?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"var(--mdocs-text-muted)",strokeWidth:"1.5",children:n.jsx("path",{d:"M1 1l4 4 4-4"})})]}),l&&n.jsx("div",{ref:k,className:"mdocs-domain-select-menu card",role:"listbox","aria-label":r,children:h.map(y=>n.jsxs("button",{type:"button",className:"mdocs-domain-select-option"+(y.domainId===t?" active":""),role:"option","aria-selected":y.domainId===t,onClick:()=>E(y.domainId),children:[n.jsx("span",{children:s(y.domainName)}),y.permission==="private"&&n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--mdocs-text-muted)",strokeWidth:"2",children:[n.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})]},y.domainId))})]})}const mn="data:image/svg+xml,%3csvg%20fill='%234D6BFE'%20fill-rule='evenodd'%20height='1em'%20style='flex:none;line-height:1'%20viewBox='0%200%2024%2024'%20width='1em'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eDeepSeek%3c/title%3e%3cpath%20d='M23.748%204.482c-.254-.124-.364.113-.512.234-.051.039-.094.09-.137.136-.372.397-.806.657-1.373.626-.829-.046-1.537.214-2.163.848-.133-.782-.575-1.248-1.247-1.548-.352-.156-.708-.311-.955-.65-.172-.241-.219-.51-.305-.774-.055-.16-.11-.323-.293-.35-.2-.031-.278.136-.356.276-.313.572-.434%201.202-.422%201.84.027%201.436.633%202.58%201.838%203.393.137.093.172.187.129.323-.082.28-.18.552-.266.833-.055.179-.137.217-.329.14a5.526%205.526%200%2001-1.736-1.18c-.857-.828-1.631-1.742-2.597-2.458a11.365%2011.365%200%2000-.689-.471c-.985-.957.13-1.743.388-1.836.27-.098.093-.432-.779-.428-.872.004-1.67.295-2.687.684a3.055%203.055%200%2001-.465.137%209.597%209.597%200%2000-2.883-.102c-1.885.21-3.39%201.102-4.497%202.623C.082%208.606-.231%2010.684.152%2012.85c.403%202.284%201.569%204.175%203.36%205.653%201.858%201.533%203.997%202.284%206.438%202.14%201.482-.085%203.133-.284%204.994-1.86.47.234.962.327%201.78.397.63.059%201.236-.03%201.705-.128.735-.156.684-.837.419-.961-2.155-1.004-1.682-.595-2.113-.926%201.096-1.296%202.746-2.642%203.392-7.003.05-.347.007-.565%200-.845-.004-.17.035-.237.23-.256a4.173%204.173%200%20001.545-.475c1.396-.763%201.96-2.015%202.093-3.517.02-.23-.004-.467-.247-.588zM11.581%2018c-2.089-1.642-3.102-2.183-3.52-2.16-.392.024-.321.471-.235.763.09.288.207.486.371.739.114.167.192.416-.113.603-.673.416-1.842-.14-1.897-.167-1.361-.802-2.5-1.86-3.301-3.307-.774-1.393-1.224-2.887-1.298-4.482-.02-.386.093-.522.477-.592a4.696%204.696%200%20011.529-.039c2.132.312%203.946%201.265%205.468%202.774.868.86%201.525%201.887%202.202%202.891.72%201.066%201.494%202.082%202.48%202.914.348.292.625.514.891.677-.802.09-2.14.11-3.054-.614zm1-6.44a.306.306%200%2001.415-.287.302.302%200%2001.2.288.306.306%200%2001-.31.307.303.303%200%2001-.304-.308zm3.11%201.596c-.2.081-.399.151-.59.16a1.245%201.245%200%2001-.798-.254c-.274-.23-.47-.358-.552-.758a1.73%201.73%200%2001.016-.588c.07-.327-.008-.537-.239-.727-.187-.156-.426-.199-.688-.199a.559.559%200%2001-.254-.078c-.11-.054-.2-.19-.114-.358.028-.054.16-.186.192-.21.356-.202.767-.136%201.146.016.352.144.618.408%201.001.782.391.451.462.576.685.914.176.265.336.537.445.848.067.195-.019.354-.25.452z'%3e%3c/path%3e%3c/svg%3e",ae={left:12,bottom:64},yt="mdocs.agentFabPosition",Ye=36,Yt=3;function vt(e){const i=Math.max(8,window.innerWidth-Ye-8),r=Math.max(8,window.innerHeight-Ye-8);return{left:Math.min(i,Math.max(8,e.left)),bottom:Math.min(r,Math.max(8,e.bottom))}}function ci(e,t,i,r){const s=e-i,d=t-r,l=window.innerHeight-d-Ye;return vt({left:s,bottom:l})}function li(){try{const e=localStorage.getItem(yt);if(!e)return ae;const t=JSON.parse(e);return typeof t.left!="number"||typeof t.bottom!="number"?ae:vt({left:t.left,bottom:t.bottom})}catch{return ae}}function Jt(e){localStorage.setItem(yt,JSON.stringify(e))}function mi(e){return e.left===ae.left&&e.bottom===ae.bottom}function ui(e){const i=Math.min(480,window.innerWidth-72);let r=e.left+Ye+8;r+i>window.innerWidth-8&&(r=e.left-8-i),r=Math.max(8,r);const s=Math.max(8,e.bottom-8);return{left:r,bottom:s}}function fi(e){const{t}=de(),[i,r]=a.useState(!1),[s,d]=a.useState(e.position),l=a.useRef(null),p=a.useRef(null),h=a.useRef(s),m=a.useRef(e.onPositionChange),g=a.useRef(e.onToggle);h.current=s,m.current=e.onPositionChange,g.current=e.onToggle;const k=a.useRef(null),v=a.useRef(0),C=a.useRef(null);a.useEffect(()=>{k.current||(d(e.position),h.current=e.position)},[e.position]),a.useEffect(()=>{function I(){const b=vt(h.current);b.left===h.current.left&&b.bottom===h.current.bottom||(h.current=b,d(b),m.current(b),Jt(b))}return window.addEventListener("resize",I),()=>window.removeEventListener("resize",I)},[]),a.useEffect(()=>{function I(){v.current=0;const P=C.current;if(!P)return;C.current=null,h.current=P,d(P);const T=p.current;T&&(T.style.left=`${P.left}px`,T.style.bottom=`${P.bottom}px`),m.current(P)}function b(P){const T=k.current;if(!T||P.pointerId!==T.pointerId)return;P.preventDefault();const _=P.clientX-T.startX,F=P.clientY-T.startY;!T.didMove&&_*_+F*F>=Yt*Yt&&(T.didMove=!0,r(!0)),T.didMove&&(C.current=ci(P.clientX,P.clientY,T.offsetX,T.offsetY),v.current||(v.current=requestAnimationFrame(I)))}function A(P){var _;const T=k.current;if(!(!T||P.pointerId!==T.pointerId)){k.current=null,r(!1),v.current&&(cancelAnimationFrame(v.current),v.current=0),C.current&&(h.current=C.current,d(C.current),C.current=null);try{(_=l.current)==null||_.releasePointerCapture(P.pointerId)}catch{}if(T.didMove){const F=h.current;m.current(F),Jt(F);return}g.current()}}return window.addEventListener("pointermove",b,{passive:!1}),window.addEventListener("pointerup",A),window.addEventListener("pointercancel",A),()=>{window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",A),window.removeEventListener("pointercancel",A),v.current&&cancelAnimationFrame(v.current)}},[]);function E(I){if(I.button!==0)return;I.preventDefault();const b=I.currentTarget.getBoundingClientRect();k.current={pointerId:I.pointerId,offsetX:I.clientX-b.left,offsetY:I.clientY-b.top,startX:I.clientX,startY:I.clientY,didMove:!1},I.currentTarget.setPointerCapture(I.pointerId)}function $(){h.current=ae,d(ae),e.onPositionChange(ae),localStorage.removeItem(yt)}const y=!mi(s);return n.jsxs("div",{ref:p,className:"mdocs-agent-fab-wrap"+(i?" dragging":""),style:{left:s.left,bottom:s.bottom},children:[n.jsx("button",{ref:l,type:"button",className:"mdocs-agent-fab"+(e.open?" open":"")+(i?" dragging":""),"aria-label":t("agentFabOpen"),"aria-expanded":e.open,onPointerDown:E,children:n.jsx("img",{src:mn,alt:"",draggable:!1})}),y&&n.jsx("button",{type:"button",className:"mdocs-agent-fab-reset",onClick:$,"aria-label":t("agentFabReset"),children:t("agentFabReset")})]})}function pi(){const[e,t]=a.useState(()=>typeof window>"u"?ae:li());return[e,t]}function hi({title:e,message:t,onClose:i}){const{t:r}=de();return n.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:s=>{s.target===s.currentTarget&&i()},children:n.jsxs("div",{className:"mdocs-dialog card mdocs-message-dialog",role:"alertdialog","aria-modal":"true",children:[e&&n.jsx("h2",{className:"mdocs-message-dialog-title",children:e}),n.jsx("p",{className:"mdocs-message-dialog-body",children:t}),n.jsx("div",{className:"mdocs-message-dialog-actions",children:n.jsx("button",{type:"button",className:"primary",onClick:i,children:r("gotIt")})})]})})}function un({title:e,message:t,confirmLabel:i="确定",cancelLabel:r="取消",onConfirm:s,onCancel:d,busy:l=!1,danger:p=!1}){return n.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:h=>{h.target===h.currentTarget&&!l&&d()},children:n.jsxs("div",{className:"mdocs-dialog card mdocs-message-dialog",role:"alertdialog","aria-modal":"true",children:[e&&n.jsx("h2",{className:"mdocs-message-dialog-title",children:e}),n.jsx("p",{className:"mdocs-message-dialog-body",children:t}),n.jsxs("div",{className:"mdocs-message-dialog-actions",style:{gap:8},children:[n.jsx("button",{type:"button",onClick:d,disabled:l,children:r}),n.jsx("button",{type:"button",className:p?"danger":"primary",onClick:s,disabled:l,children:l?"…":i})]})]})})}const Kt={"relative path is required":"pathRequired","path must be relative":"pathMustBeRelative","use forward slashes":"useForwardSlashes","path must not contain ..":"pathNoDotDot","document path must end with .md":"pathMustEndWithMd","path contains unsupported characters":"pathUnsupportedChars","path escapes docs root":"pathEscapesRoot"},fn={"enter a folder name":"enterFolderName","use a single name, not a path":"singleNameNotPath","invalid folder name":"invalidFolderName","folder name is too long":"folderNameTooLong","enter a file name":"enterFileName","use a file name, not a path":"singleFileNameNotPath","invalid file name":"invalidFileName","file name is too long":"fileNameTooLong"};function me(e,t){if(t instanceof oe)return t.message;if(t instanceof le){const i=Kt[t.message];return i?e(i):t.message}if(t instanceof Error){const i=Kt[t.message]??fn[t.message];return i?e(i):t.message}return String(t)}function gi(e,t,i){if(e==="Default")return i("defaultDomain");const r="个人域";return e.endsWith(r)?e.slice(0,-r.length)+i("personalDomainSuffix"):e}function Or(e,t){return e==="public"?t("domainPublic"):e==="restricted"?t("domainRestricted"):e==="private"?t("domainPrivate"):e}function ze(e){const t=e.lastIndexOf("/");return t===-1?"":e.slice(0,t)}function yi(e){return JSON.stringify({root:{children:[{children:[{detail:0,format:0,mode:"normal",text:e,type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",tag:"h1",version:1}],direction:"ltr",type:"root",version:1}})}function Xt(e,t){const i=e.trim(),r=t.trim();return r?i?`${i}/${r}`:r:i}function pn(e,t=new Set){for(const i of e)i.type==="document"?t.add(i.path):(i.descDocumentId&&t.add(Po(i.path)),pn(i.children,t));return t}function pt(e,t){for(const i of e){if(i.type==="folder"&&i.path===t)return i.documentId;if(i.type==="folder"){const r=pt(i.children,t);if(r)return r}}return null}function Qt(e,t){const i=fn[t];return i?e(i):t}function vi(e){const{tree:t,currentDomainId:i,selectedCreateParentPath:r,t:s,onDocCreated:d,refreshTree:l}=e,[p,h]=a.useState(null),[m,g]=a.useState(null),[k,v]=a.useState(!1),C=a.useRef(null);a.useEffect(()=>{if(!p)return;const I=window.setTimeout(()=>{var b;return(b=C.current)==null?void 0:b.focus()},0);return()=>window.clearTimeout(I)},[p]);function E(I){const b=I!==void 0;g(null),h({kind:"document",parentMode:b?"fixed":"selection",parentPath:b?I:"",draft:"untitled.md"})}function $(I){const b=I!==void 0;g(null),h({kind:"folder",parentMode:b?"fixed":"selection",parentPath:b?I:"",draft:""})}async function y(I){if(I.preventDefault(),!p)return;v(!0),g(null);const b=pn(t),A=p.parentMode==="selection"?r:p.parentPath;try{if(p.kind==="document"){const H=jo(p.draft);if(!H.ok){g(Qt(s,H.message));return}const Y=H.displayFile,R=Y.replace(/\.md$/i,"");let u;try{u=Mo(Xt(A,Y))}catch(O){g(me(s,O));return}if(b.has(u)){g(s("pathExists"));return}const N=A?pt(t,A)??void 0:void 0,M=await an({fileName:Y,displayName:R,content:yi(R),domainId:i,parentId:N});await l(),d(M),h(null);return}const P=Ao(p.draft);if(!P.ok){g(Qt(s,P.message));return}const T=mt(P.display);if(!T){g(s("invalidFolderName"));return}const _=Xt(A,T);if(b.has(_)){g(s("folderExists"));return}const F=A?pt(t,A)??void 0:void 0;await qo({name:T,parentId:F,domainId:i}),await l(),h(null)}catch(P){g(me(s,P))}finally{v(!1)}}return{createModal:p,setCreateModal:h,createModalError:m,createModalBusy:k,createModalInputRef:C,openNewDocumentModal:E,openNewFolderModal:$,submitCreateModal:y}}function bi({open:e,onClose:t,onResolve:i}){const{t:r}=de();return e?n.jsx("div",{className:"mdocs-conflict-modal-root",role:"alertdialog","aria-modal":"true",children:n.jsxs("div",{className:"mdocs-conflict-modal-panel",children:[n.jsx("h2",{className:"mdocs-conflict-modal-title",children:r("conflictTitle")}),n.jsx("p",{className:"mdocs-conflict-modal-body",children:r("conflictBody")}),n.jsxs("div",{className:"mdocs-conflict-modal-actions",children:[n.jsx("button",{type:"button",className:"primary",onClick:i,children:r("conflictResolve")}),n.jsx("button",{type:"button",className:"secondary",onClick:t,children:r("conflictClose")})]})]})}):null}function wi({documentId:e,visitorId:t,visitorName:i,documentOwnerId:r,onClose:s}){const[d,l]=a.useState([]),[p,h]=a.useState(""),[m,g]=a.useState(null),[k,v]=a.useState(!0),[C,E]=a.useState(!1),[$,y]=a.useState(null),[I,b]=a.useState(null),[A,P]=a.useState(360),[T,_]=a.useState(80),F=a.useRef(!1),H=a.useRef(!1),Y=300,R=80,u=a.useRef(null);function N(){const D=u.current;if(!D)return;D.style.height="auto";const S=D.scrollHeight,z=Math.min(Math.max(S,R),Y);D.style.height=`${z}px`,_(z)}a.useEffect(()=>{setTimeout(()=>N(),0)},[m]);function M(D){return t?D.visitorId===t||r===t:!1}const{rootComments:O,repliesByParentId:J,totalCount:Je}=a.useMemo(()=>{const D=[],S=new Map;let z=0;for(const B of d)B.isDeleted||(z++,B.parentId?(S.has(B.parentId)||S.set(B.parentId,[]),S.get(B.parentId).push(B)):D.push(B));return{rootComments:D,repliesByParentId:S,totalCount:z}},[d]),ie=a.useRef(e);a.useEffect(()=>{ie.current=e,h(""),g(null),b(null),ce()},[e]);async function ce(){const D=ie.current;v(!0);try{const S=await Ko(e);if(ie.current!==D)return;l(S.comments)}catch(S){if(ie.current!==D)return;b("加载评论失败"),console.error("Failed to load comments:",S)}finally{ie.current===D&&v(!1)}}async function fe(){var D;if(!(!p.trim()||!t)){E(!0),b(null);try{await Xo(e,{content:p,parentId:(m==null?void 0:m.commentId)||null,replyToVisitorId:m?((D=d.find(S=>S.commentId===m.commentId))==null?void 0:D.visitorId)??null:null,replyToVisitorName:(m==null?void 0:m.visitorName)||null}),h(""),g(null),setTimeout(()=>N(),0),await ce()}catch(S){b(S.message||"发表失败,请重试")}finally{E(!1)}}}async function Ke(D){b(null);try{await Qo(e,D),await ce()}catch(S){b(S.message||"删除失败,请重试")}finally{y(null)}}function re(D){const S=Date.now()-new Date(D).getTime(),z=Math.floor(S/6e4),B=Math.floor(S/36e5),he=Math.floor(S/864e5);return z<1?"刚刚":z<60?`${z}分钟前`:B<24?`${B}小时前`:`${he}天前`}function ke(D){F.current=!0,D.preventDefault()}function pe(D){H.current=!0,D.preventDefault(),document.body.style.userSelect="none",document.body.style.cursor="row-resize"}return a.useEffect(()=>{function D(z){if(F.current){const B=Math.max(280,Math.min(600,window.innerWidth-z.clientX));P(B)}if(H.current){const B=-z.movementY;_(he=>Math.max(60,Math.min(600,he+B)))}}function S(){F.current=!1,H.current=!1,document.body.style.userSelect="",document.body.style.cursor=""}return window.addEventListener("mousemove",D),window.addEventListener("mouseup",S),()=>{window.removeEventListener("mousemove",D),window.removeEventListener("mouseup",S)}},[]),n.jsxs("div",{className:"mdocs-comments-panel",style:{width:A},children:[n.jsx("div",{className:"mdocs-comments-resize-handle",onMouseDown:ke}),n.jsxs("div",{className:"mdocs-comments-header",children:[n.jsxs("h3",{style:{margin:0,fontSize:"1rem",display:"flex",alignItems:"center",gap:6},children:[n.jsx(fo,{size:18}),"评论 (",Je,")"]}),n.jsx("button",{type:"button",onClick:s,className:"mdocs-comments-close-btn",children:n.jsx(Ae,{size:18})})]}),I&&n.jsxs("div",{className:"mdocs-comments-error",children:[I,n.jsx("button",{type:"button",onClick:()=>b(null),children:n.jsx(Ae,{size:14})})]}),n.jsx("div",{className:"mdocs-comments-list",children:k?n.jsx("div",{className:"mdocs-comments-empty",children:"加载中..."}):O.length===0?n.jsx("div",{className:"mdocs-comments-empty",children:"暂无评论,来发表第一条吧~"}):O.map(D=>n.jsxs("div",{className:"mdocs-comment-root",children:[n.jsxs("div",{className:"mdocs-comment-header",children:[n.jsx("span",{className:"mdocs-comment-avatar",children:D.visitorName.charAt(0).toUpperCase()}),n.jsx("span",{className:"mdocs-comment-author",children:D.visitorName}),n.jsx("span",{className:"mdocs-comment-time",children:re(D.createdAt)}),M(D)&&n.jsx("button",{type:"button",className:"mdocs-comment-delete",onClick:()=>y(D.commentId),title:"删除",children:n.jsx(Ae,{size:14})})]}),n.jsx("div",{className:"mdocs-comment-content",children:D.content}),t&&n.jsx("button",{type:"button",className:"mdocs-comment-reply-btn",onClick:()=>g({commentId:D.commentId,visitorName:D.visitorName}),children:"回复"}),(J.get(D.commentId)??[]).length>0&&n.jsx("div",{className:"mdocs-comment-replies",children:(J.get(D.commentId)??[]).map(S=>n.jsxs("div",{className:"mdocs-comment-reply",children:[n.jsxs("div",{className:"mdocs-comment-header",children:[n.jsx("span",{className:"mdocs-comment-avatar mdocs-comment-avatar-small",children:S.visitorName.charAt(0).toUpperCase()}),n.jsx("span",{className:"mdocs-comment-author",children:S.visitorName}),S.replyToVisitorName&&n.jsxs("span",{className:"mdocs-comment-reply-to",children:["回复 ",S.replyToVisitorName]}),n.jsx("span",{className:"mdocs-comment-time",children:re(S.createdAt)}),M(S)&&n.jsx("button",{type:"button",className:"mdocs-comment-delete",onClick:()=>y(S.commentId),title:"删除",children:n.jsx(Ae,{size:12})})]}),n.jsx("div",{className:"mdocs-comment-content",children:S.content}),t&&n.jsx("button",{type:"button",className:"mdocs-comment-reply-btn",onClick:()=>g({commentId:D.commentId,visitorName:S.visitorName}),children:"回复"})]},S.commentId))})]},D.commentId))}),t?n.jsxs("div",{className:"mdocs-comments-input-wrapper",children:[n.jsx("div",{className:"mdocs-comments-input-drag-handle",onMouseDown:pe}),m&&n.jsxs("div",{className:"mdocs-comment-reply-notice",children:[n.jsxs("span",{children:["回复 ",n.jsx("span",{className:"mdocs-comment-reply-to-name",children:m.visitorName})]}),n.jsxs("button",{type:"button",onClick:()=>g(null),children:[n.jsx(Ae,{size:14})," 取消"]})]}),n.jsx("textarea",{ref:u,value:p,onChange:D=>{h(D.target.value.slice(0,512)),setTimeout(()=>N(),0)},placeholder:m?`回复 ${m.visitorName}...`:"发表评论...",className:"mdocs-comments-input",style:{height:T},maxLength:512,onKeyDown:D=>{D.key==="Enter"&&(D.metaKey||D.ctrlKey)&&fe()}}),n.jsxs("div",{className:`mdocs-comments-char-count${p.length>=460?" mdocs-char-count--warn":""}`,children:[p.length,"/512"]}),n.jsx("div",{className:"mdocs-comments-input-actions",children:n.jsx("button",{type:"button",className:"mdocs-btn-primary",onClick:fe,disabled:C||!p.trim(),children:C?"发表中...":"发表"})})]}):n.jsx("div",{className:"mdocs-comments-input-wrapper",style:{textAlign:"center"},children:n.jsx("div",{style:{color:"#666",fontSize:"0.9rem"},children:"请先创建访客身份以发表评论"})}),$&&n.jsx(un,{title:"删除评论",message:"确定要删除这条评论吗?",confirmLabel:"删除",danger:!0,onConfirm:()=>Ke($),onCancel:()=>y(null)})]})}const xi="mdocs-drafts",Ii=4,W="drafts",De={DOC_NOT_FOUND:"DOC_NOT_FOUND",SYNC_HEAD_MISSING:"SYNC_HEAD_MISSING"};let at=null;function Se(){return at||(at=new Promise((e,t)=>{const i=indexedDB.open(xi,Ii);i.onupgradeneeded=r=>{const s=i.result;s.objectStoreNames.contains(W)||s.createObjectStore(W,{keyPath:"documentId"});const d=r.oldVersion;if(d>0&&d<4){const h=i.transaction.objectStore(W).openCursor();h.onsuccess=()=>{const m=h.result;if(!m)return;const g=m.value;typeof g.baseCommitId=="string"&&!g.localBaseCommitId&&(g.localBaseCommitId=g.baseCommitId,delete g.baseCommitId);const k=g.conflict;k&&(typeof k.baseCommitId=="string"&&!k.localBaseCommitId&&(k.localBaseCommitId=k.baseCommitId,delete k.baseCommitId),typeof k.expectedHeadCommitId=="string"&&!k.remoteCommitId&&(k.remoteCommitId=k.expectedHeadCommitId,delete k.expectedHeadCommitId)),m.update(g),m.continue()}}},i.onsuccess=()=>e(i.result),i.onerror=()=>t(i.error)})),at}async function Di(e){var r;const t=await G(e.documentId),i={documentId:e.documentId,content:e.content,displayName:e.displayName,updatedAt:Date.now(),published:!1};if(t!=null&&t.localBaseCommitId)i.localBaseCommitId=t.localBaseCommitId;else{const s=(r=e.localBaseCommitIdAtEditStart)==null?void 0:r.trim();s&&(i.localBaseCommitId=s)}(t==null?void 0:t.permission)!=null?i.permission=t.permission:e.snapshotMeta&&(i.permission=e.snapshotMeta.permission),t!=null&&t.ownerVisitorId?i.ownerVisitorId=t.ownerVisitorId:e.snapshotMeta&&(i.ownerVisitorId=e.snapshotMeta.ownerVisitorId),t!=null&&t.domainId?i.domainId=t.domainId:e.snapshotMeta&&(i.domainId=e.snapshotMeta.domainId),t!=null&&t.publishError&&(i.publishError=t.publishError,i.publishErrorAt=t.publishErrorAt),t!=null&&t.conflictStatus&&(i.conflictStatus=t.conflictStatus),t!=null&&t.conflict&&(i.conflict=t.conflict),await ye(i)}function bt(e){const t={documentId:e.documentId,content:e.content,displayName:e.displayName,updatedAt:e.updatedAt,published:e.published};return e.permission!=null&&(t.permission=e.permission),e.ownerVisitorId&&(t.ownerVisitorId=e.ownerVisitorId),e.domainId&&(t.domainId=e.domainId),e.publishError!=null&&(t.publishError=e.publishError),e.publishErrorAt!=null&&(t.publishErrorAt=e.publishErrorAt),e.localBaseCommitId&&(t.localBaseCommitId=e.localBaseCommitId),e.conflictStatus!=null&&(t.conflictStatus=e.conflictStatus),e.conflict!=null&&(t.conflict=e.conflict),t}async function ye(e){const t=await Se(),i=bt(e);return new Promise((r,s)=>{const d=t.transaction(W,"readwrite");d.objectStore(W).put(i),d.oncomplete=()=>r(),d.onerror=()=>s(d.error)})}async function G(e){const t=await Se();return new Promise((i,r)=>{const d=t.transaction(W,"readonly").objectStore(W).get(e);d.onsuccess=()=>i(d.result),d.onerror=()=>r(d.error)})}async function st(e){const t=await Se();return new Promise((i,r)=>{const s=t.transaction(W,"readwrite");s.objectStore(W).delete(e),s.oncomplete=()=>i(),s.onerror=()=>r(s.error)})}async function Ci(e){const t=await Se();return new Promise((i,r)=>{const d=t.transaction(W,"readonly").objectStore(W).getAll();d.onsuccess=()=>{let l=d.result;e!=null&&e.skipFailed&&(l=l.filter(p=>!p.publishError)),i(l)},d.onerror=()=>r(d.error)})}async function Si(e,t){const i=await Se();return new Promise((r,s)=>{const l=i.transaction(W,"readwrite").objectStore(W),p=l.get(e);p.onsuccess=()=>{const h=p.result;h&&l.put(bt({...h,publishError:t,publishErrorAt:Date.now()})),r()},p.onerror=()=>s(p.error)})}async function dt(e){const t=await Se();return new Promise((i,r)=>{const d=t.transaction(W,"readwrite").objectStore(W),l=d.get(e);l.onsuccess=()=>{const p=l.result;p&&d.put(bt({...p,publishError:void 0,publishErrorAt:void 0})),i()},l.onerror=()=>r(l.error)})}async function Zt(e,t){const i=await G(e);i&&await ye({...i,localBaseCommitId:t.localBaseCommitId,conflictStatus:t.conflictStatus,conflict:t.conflict})}async function ct(e){const t=await G(e);t&&await ye({...t,conflict:void 0,conflictStatus:"none"})}class Re extends Error{constructor(i,r){super(i);Ie(this,"code");Ie(this,"cause");this.name="DraftPublishAborted",this.code=i,this.cause=r==null?void 0:r.cause}}function ki(e){return e instanceof Re?e.code:e instanceof oe?e.status===404?De.DOC_NOT_FOUND:e.code||`HTTP_${e.status}`:e instanceof Error&&e.message.trim()?e.message.trim().slice(0,120):"UNKNOWN"}function Ni(e,t,i,r){const s=(t==null?void 0:t.displayName)||e("unknownTitle");if(i===De.SYNC_HEAD_MISSING)return e("draftPublishFailedSyncHead",{name:s});if(i===De.DOC_NOT_FOUND)return e("draftPublishFailedNotice",{name:s});const d=r instanceof oe||r instanceof Error&&r.message?r.message:i;return e("draftPublishFailedGeneric",{name:s,reason:d})}async function Pi(e,t,i){const r=ki(t);throw await Si(e,r),t instanceof Re?t:new Re(r,{cause:t})}function Ti(e,t){const i=a.useRef(t);i.current=t,a.useEffect(()=>{if(!e)return;const r=3e4,s=1e4,d=async()=>{const p=await Ci({skipFailed:!0}),h=Date.now();for(const m of p)if(!m.published&&!(h-m.updatedAt<r))try{await i.current(m.documentId)}catch(g){console.log("[autoPublish] scan publish failed:",g)}};d();const l=setInterval(d,s);return()=>clearInterval(l)},[e])}const Ei=1e4;function Ai(e,t){const[i,r]=a.useState(null),[s,d]=a.useState("up_to_date");return a.useEffect(()=>{if(!e){r(null),d("up_to_date");return}let p=!1;const h=e;async function m(){try{const k=await Vo(h,t??void 0);if(p)return;r(k.headCommitId),d(k.status)}catch{}}m();const g=window.setInterval(()=>void m(),Ei);return()=>{p=!0,window.clearInterval(g)}},[e,t]),{remoteCommitId:i,syncStatus:s,syncBehind:!!(t&&i&&t!==i)||s==="behind"}}const ji="/assets/mdocs-logo-Dsv_2t6v.svg",Mi=a.lazy(()=>Ce(()=>import("./DocumentEditor-NPbbAape.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(e=>({default:e.DocumentEditor}))),Ri=a.lazy(()=>Ce(()=>import("./SettingsPage-OklrFCx7.js"),__vite__mapDeps([11,1,10,2,3])).then(e=>({default:e.SettingsPage}))),Oi=a.lazy(()=>Ce(()=>import("./AgentChatPanel-CLKeiDeR.js"),__vite__mapDeps([12,1,7,13,2,3,8])).then(e=>({default:e.AgentChatPanel}))),Li=a.lazy(()=>Ce(()=>import("./AiWriteWorkbench-Ecp214S5.js"),__vite__mapDeps([14,1,7,13,2,3])).then(e=>({default:e.AiWriteWorkbench}))),Fi=a.lazy(()=>Ce(()=>import("./MergeView-BnWbq08U.js"),__vite__mapDeps([15,1,4,5,2,3,6,7,8])).then(e=>({default:e.MergeView})));function _i(e,t){try{const i=new Intl.RelativeTimeFormat(t,{numeric:"auto"}),r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4),d=Math.floor(s/60),l=Math.floor(d/24);return l>30?i.format(-Math.floor(l/30),"month"):l>0?i.format(-l,"day"):d>0?i.format(-d,"hour"):s>0?i.format(-s,"minute"):i.format(-Math.floor(r/1e3),"second")}catch{return e.slice(0,10)}}async function lt(e,t,i,r){const s=await sn();t(s);const d=localStorage.getItem("mdocs.currentDomainId"),p=d&&s.some(h=>h.domainId===d)?d:ei(s,e);i(p),await r(p)}function en(){const{t:e,lang:t,setLang:i}=de(),[r,s]=a.useState("loading"),[d,l]=a.useState(()=>localStorage.getItem("mdocs.sidebarCollapsed")==="true"),p=()=>{const o=!d;l(o),localStorage.setItem("mdocs.sidebarCollapsed",String(o))},[h,m]=a.useState(!1),[g,k]=a.useState(0),v=a.useRef(null),[C,E]=a.useState(null),[$,y]=a.useState(null),[I,b]=a.useState(null),[A,P]=a.useState([]),[T,_]=a.useState([]),[F,H]=a.useState("default"),{documentId:Y}=zn(),R=qn(),[u,N]=a.useState(null),[M,O]=a.useState(null),J=a.useRef(M);J.current=M;const[Je,ie]=a.useState(0),[ce,fe]=a.useState(null),[Ke,re]=a.useState(!1),[ke,pe]=a.useState(!1),[D,S]=a.useState(!1),z=(u==null?void 0:u.documentId)??null,{syncBehind:B,remoteCommitId:he}=Ai(z,ce),[wt,Xe]=a.useState(null);a.useEffect(()=>{if(!ke||!u){Xe(null);return}(async()=>{const o=await G(u.documentId);if(o!=null&&o.conflict){Xe(o.conflict);return}if(o&&ce&&he){const f=o.localBaseCommitId??ce;if(!f)return;const c={localBaseCommitId:f,remoteCommitId:he,localSnapshotContent:o.content};await Zt(u.documentId,{localBaseCommitId:c.localBaseCommitId,conflictStatus:"diverged",conflict:c}),Xe(c)}})()},[ke,u,ce,he]),a.useEffect(()=>{!u||!B||!D||G(u.documentId).then(async o=>{!o||o.conflict||o.conflictStatus==="publish_conflict"||o.conflictStatus!=="diverged"&&await ye({...o,conflictStatus:"diverged"})})},[u==null?void 0:u.documentId,B,D]),a.useEffect(()=>{if(!u){fe(null);return}let o=!1;return G(u.documentId).then(f=>{o||(f&&!f.published&&f.localBaseCommitId?fe(f.localBaseCommitId):fe(u.headCommitId??null))}),()=>{o=!0}},[u==null?void 0:u.documentId,u==null?void 0:u.headCommitId,D]);const[Ne,U]=a.useState(null),[xt,K]=a.useState(null),[q,Oe]=a.useState(null),[Pe,It]=a.useState(null),[Dt,X]=a.useState(""),[gn,Le]=a.useState("docs"),[Qe,be]=a.useState(!1),[Ct,yn]=pi(),[vn,Fe]=a.useState(!1),[_e,Be]=a.useState(null),Q=a.useRef(void 0),$e=a.useRef(void 0);Ti(localStorage.getItem("mdocs.autoPublish")==="true",Mt);async function Z(o){var f;await((f=Q.current)==null?void 0:f.call(Q)),o()}function bn(o){const c=(o.trim()||"untitled").replace(/[\\/:*?"<>|]/g,"-").slice(0,80);return c.endsWith(".md")?c:`${c}.md`}async function wn(){var f,c;if(!u||!M)return;await((f=Q.current)==null?void 0:f.call(Q));let o=((c=$e.current)==null?void 0:c.call($e))??"";if(!o.trim())try{o=(await rt({content:M.content,from:"lexical",to:"markdown"})).content}catch{o=""}Be({markdown:o,documentId:u.documentId,displayName:M.displayName||u.displayName||"未命名"}),Fe(!0),be(!1)}function xn(){Be({markdown:"",documentId:null,displayName:"未命名"}),Fe(!0),be(!1)}async function In(o){var j,L;const f=o.documentId.trim();if(!f)return;await((j=Q.current)==null?void 0:j.call(Q));let c="",w=o.displayName.trim()||"未命名";try{const ee=await Me(f);w=((L=ee.displayName)==null?void 0:L.trim())||w;try{c=(await rt({content:ee.content,from:"lexical",to:"markdown"})).content}catch{c=""}}catch{}Be({markdown:c,documentId:f,displayName:w}),Fe(!0),be(!1),Le("docs"),Z(()=>R(`/doc/${f}`))}async function Dn(o){(u==null?void 0:u.documentId)===o.documentId&&await jt()}async function Cn(o){if(o.documentId){if(!window.confirm("将把帮写结果写入当前文档的本地草稿(不会自动发布)。继续?")){const L=new Error("cancelled");throw L.silent=!0,L}const w=await rt({content:o.markdown,from:"markdown",to:"lexical"}),j=(u==null?void 0:u.documentId)===o.documentId?u:null;return await Di({documentId:o.documentId,content:w.content,displayName:o.displayName,localBaseCommitIdAtEditStart:(j==null?void 0:j.headCommitId)??null,snapshotMeta:j?{permission:j.permission,ownerVisitorId:j.ownerVisitorId,domainId:j.domainId}:void 0}),(u==null?void 0:u.documentId)===o.documentId?(O({documentId:o.documentId,content:w.content,displayName:o.displayName}),ie(L=>L+1),S(!0)):await Te(o.documentId),U("帮写已写入草稿,可在编辑器中继续修改后发布"),{documentId:o.documentId}}const f=await an({fileName:bn(o.displayName),displayName:o.displayName,content:o.markdown,contentFormat:"markdown",domainId:F||void 0,parentId:void 0});return await V(),await Te(f.documentId),U("已创建文档"),{documentId:f.documentId}}a.useEffect(()=>{Sn()},[]),a.useEffect(()=>{if(!Ne)return;const o=()=>{U(null)};return window.addEventListener("pointerdown",o,!0),()=>window.removeEventListener("pointerdown",o,!0)},[Ne]),a.useEffect(()=>{const o=f=>{var j,L;const c=f;if(((j=c.detail)==null?void 0:j.status)===409)return;const w=(L=c.detail)==null?void 0:L.message;w&&K(w)};return window.addEventListener(ut,o),()=>window.removeEventListener(ut,o)},[]);async function Sn(){try{const o=await qt();E(o),qe(o.visitorId),await lt(o.visitorId,_,H,V),s("ready")}catch(o){if(o instanceof oe&&o.status===401){s("needsRegister");return}K(me(e,o)),s("needsRegister")}}async function kn(o,f){const c=await _o(o,f);E(c.visitor),y(c.visitor.visitorId),b(c.recoveryCode),qe(c.visitor.visitorId),await lt(c.visitor.visitorId,_,H,V),s("ready")}async function Nn(o){const f=await qt();E(f),await lt(f.visitorId,_,H,V),s("ready")}async function V(o){const c=await Uo(o??F);P(c)}function He(o){O({documentId:o.documentId,content:o.content,displayName:o.displayName}),ie(f=>f+1),S(!1)}function Pn(o,f){O({documentId:o,content:f.content,displayName:f.displayName}),ie(c=>c+1),S(!0)}async function St(o,f){await st(o);const c=await Me(o);if((u==null?void 0:u.documentId)===o&&v.current===o){N(je(c)),S(!1);const w=J.current,j=f!==void 0&&c.content===f,L=(w==null?void 0:w.documentId)===o&&w.content===c.content;j||L?(w==null?void 0:w.documentId)===o&&w.displayName!==c.displayName&&O({...w,displayName:c.displayName}):He(c)}return c}async function Te(o){v.current=o;try{const f=await G(o);if(v.current!==o)return;const c=await Me(o);if(v.current!==o||(c.domainId!==F&&(localStorage.setItem("mdocs.currentDomainId",c.domainId),H(c.domainId),V(c.domainId)),X(ze(c.relativePath)),c.headCommitId&&f&&!f.published&&(f.publishError===De.SYNC_HEAD_MISSING&&await dt(o),f.localBaseCommitId||await ye({...f,localBaseCommitId:c.headCommitId})),N(je(c)),v.current!==o))return;f&&!f.published?Pn(o,f):He(c)}catch(f){if(v.current!==o)return;K(me(e,f))}}a.useEffect(()=>{r==="ready"&&(Y?Te(Y):(N(null),O(null),fe(null)))},[r,Y]);const{createModal:we,setCreateModal:Ze,createModalError:kt,createModalBusy:xe,createModalInputRef:Tn,openNewDocumentModal:et,openNewFolderModal:tt,submitCreateModal:En}=vi({tree:A,currentDomainId:F,selectedCreateParentPath:Dt,t:e,onDocCreated:o=>{N(je(o)),He(o),X(ze(o.relativePath)),R(`/doc/${o.documentId}`)},refreshTree:V}),[An,Ue]=a.useState(!1),[jn,Ee]=a.useState(!1),[ge,Nt]=a.useState([]),[nt,Pt]=a.useState(""),[Ve,Tt]=a.useState(""),[Mn,Et]=a.useState(new Set);async function Rn(){try{const o=await Yo();Nt(o)}catch(o){K(me(e,o))}}const ot=a.useMemo(()=>{const o={};for(const f of T)o[f.domainId]=f.domainName;return o},[T]),At=a.useMemo(()=>{let o=ge;const f=nt.trim().toLowerCase();return f&&(o=o.filter(c=>{var w;return(w=c.displayName)==null?void 0:w.toLowerCase().includes(f)})),Ve&&(o=o.filter(c=>c.domainId===Ve)),o},[ge,nt,Ve]),On=a.useMemo(()=>{const o=new Set,f=[];for(const c of ge){const w=c.domainId;w&&!o.has(w)&&(o.add(w),f.push({id:w,name:ot[w]??w}))}return f},[ge,ot]);async function Ln(o,f,c,w,j){let L=await G(o);!L&&(u==null?void 0:u.documentId)===o&&(L={documentId:o,content:f,displayName:c,updatedAt:Date.now(),published:!1,localBaseCommitId:w,permission:u.permission,ownerVisitorId:u.ownerVisitorId,domainId:u.domainId},await ye(L)),L&&await Zt(o,{localBaseCommitId:w,conflictStatus:"publish_conflict",conflict:{localBaseCommitId:w,remoteCommitId:j.headCommitId,localSnapshotContent:f}}),re(!0)}async function Fn(o,f,c,w){return $t(c).execute(async()=>{const j=await G(c),L=(j==null?void 0:j.localBaseCommitId)??(u==null?void 0:u.headCommitId);if(!L)throw K(e("syncHeadMissing")),new Error("missing localBaseCommitId");try{await Gt(c,{content:o,displayName:f,permission:w,version:{localBaseCommitId:L}}),await ct(c),await St(c,o),await V(),re(!1),U(e("published")),window.setTimeout(()=>U(null),1200)}catch(ee){throw ee instanceof oe&&ee.status===409&&ee.code==="VERSION_CONFLICT"&&ee.details&&typeof ee.details=="object"&&await Ln(c,o,f,L,ee.details),ee}})}async function _n(){if(!u)return;const o=await Me(u.documentId);o.domainId!==F&&(localStorage.setItem("mdocs.currentDomainId",o.domainId),H(o.domainId),V(o.domainId)),X(ze(o.relativePath)),N(je(o)),He(o),U(e("syncPullDone")),window.setTimeout(()=>U(null),1200)}async function jt(){if(!u)return;const o=await G(u.documentId);if(o&&!o.published)return;if((o==null?void 0:o.conflictStatus)==="publish_conflict"||(o==null?void 0:o.conflictStatus)==="diverged"||!!(o!=null&&o.conflict)){pe(!0);return}await _n()}async function Bn(o){await ct(o.documentId),await st(o.documentId),S(!1),pe(!1),re(!1),await Te(o.documentId),V(o.domainId),U(e("published")),window.setTimeout(()=>U(null),1200)}async function $n(o,f,c){try{await Pi(o,f,c)}catch(w){if(!(w instanceof Re))throw w;const j=c??await G(o);throw U(Ni(e,j,w.code,w.cause??f)),window.setTimeout(()=>U(null),4e3),w}}async function Mt(o){let f;try{await $t(o).execute(async()=>{const c=await G(o);if(!c)return;f=c;let w=c.localBaseCommitId;if(w||(w=(await Me(o)).headCommitId??void 0,w&&(await ye({...c,localBaseCommitId:w}),c.publishError===De.SYNC_HEAD_MISSING&&await dt(o))),!w)throw new Re(De.SYNC_HEAD_MISSING);const j=await G(o);j&&(await Gt(o,{content:j.content,displayName:j.displayName,version:{localBaseCommitId:w}}),await ct(o),await dt(o),(u==null?void 0:u.documentId)===o?await St(o,j.content):await st(o),await V(),U(e("published")),window.setTimeout(()=>U(null),1200))})}catch(c){await $n(o,c,f)}}function Rt(o,f){Oe({type:"document",id:o,name:f})}function Ot(o,f){Oe({type:"folder",id:o,name:f})}async function Hn(o,f){try{const c=await zo(o,f);await V(c.domainId),(u==null?void 0:u.documentId)===o&&(N(je(c)),X(ze(c.relativePath)))}catch(c){c instanceof oe?c.status===409&&K(c.message):K(me(e,c))}}async function Un(){if(q)try{q.type==="document"?(await Wo(q.id),(u==null?void 0:u.documentId)===q.id&&(N(null),O(null),X(""),R("/"))):q.type==="folder"&&(await Go(q.id),u&&(N(null),O(null),X(""),R("/"))),await V(),U(q.type==="folder"?`已删除「${q.name}」及其下所有内容`:`已删除「${q.name}」`),window.setTimeout(()=>U(null),2e3)}catch(o){K(me(e,o))}finally{Oe(null)}}return r==="loading"?n.jsx("div",{className:"mdocs-loading muted",children:e("loading")}):r==="needsRegister"?n.jsx(ti,{onSubmit:kn,onRecover:Nn,error:Ne}):n.jsxs("div",{className:"mdocs-app-root",children:[rn(),n.jsxs("div",{className:"mdocs-shell",children:[$&&C&&n.jsx(ni,{visitorId:$,onDismiss:()=>y(null)}),I&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:o=>{o.target===o.currentTarget&&b(null)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480,textAlign:"center"},children:[n.jsx("h1",{style:{fontSize:"1.25rem",marginBottom:8},children:"🔑 保存你的恢复码"}),n.jsxs("p",{className:"muted",style:{marginBottom:16,lineHeight:1.5},children:["恢复码是你的唯一凭证,当 Token 丢失时可用它找回身份。",n.jsx("br",{}),n.jsx("strong",{children:"请立即复制保存,此弹窗关闭后不可再查看。"})]}),n.jsx("div",{style:{background:"#f5f5f5",borderRadius:8,padding:"12px 16px",fontFamily:"monospace",fontSize:"1.25rem",letterSpacing:"0.1em",marginBottom:20,userSelect:"all"},children:I}),n.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"center"},children:[n.jsx("button",{type:"button",className:"primary",onClick:()=>{navigator.clipboard.writeText(I)},children:"复制恢复码"}),n.jsx("button",{type:"button",onClick:()=>b(null),children:"已保存,关闭"})]})]})}),n.jsxs(n.Fragment,{children:[n.jsx(fi,{open:Qe,onToggle:()=>be(o=>!o),position:Ct,onPositionChange:yn}),Qe?n.jsx(a.Suspense,{fallback:null,children:n.jsx(Oi,{open:Qe,onClose:()=>be(!1),visitorName:C==null?void 0:C.visitorName,anchorStyle:ui(Ct),onOpenDocument:o=>{Le("docs"),Z(()=>R(`/doc/${o}`)),be(!1)},onTreeChanged:()=>void V(),onDocumentOverwritten:o=>void Dn(o),onOpenCoding:o=>void In(o)})}):null]}),_e?n.jsx(a.Suspense,{fallback:null,children:n.jsx(Li,{open:vn,initialMarkdown:_e.markdown,documentId:_e.documentId,displayName:_e.displayName,onClose:()=>{Fe(!1),Be(null)},onComplete:Cn})}):null,gn==="settings"?n.jsx(a.Suspense,{fallback:n.jsx("div",{className:"mdocs-main muted",style:{padding:24},children:"加载设置…"}),children:n.jsx(Ri,{onBack:()=>Le("docs"),onPublishDraft:Mt,onOpenDocument:Te,onRecoverDraft:()=>void V()})}):n.jsxs("div",{className:"mdocs-layout",children:[n.jsxs("aside",{className:`mdocs-sidebar ${d?"mdocs-sidebar-collapsed":""}`,children:[n.jsxs("header",{className:"mdocs-sidebar-header",children:[n.jsxs("div",{className:"mdocs-brand",children:[n.jsx("img",{src:ji,alt:e("brand"),className:"mdocs-brand-logo"}),n.jsx("span",{children:e("brand")})]}),n.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:p,"aria-label":e(d?"expandSidebar":"collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f0f0f0)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},children:d?n.jsx(yo,{size:18}):n.jsx(ho,{size:18})})]}),n.jsxs("div",{className:"mdocs-sidebar-actions",children:[n.jsx("span",{className:"mdocs-sidebar-icon mdocs-tooltip","data-tooltip":e("newDocument"),onClick:()=>et(),style:{color:"var(--mdocs-accent)"},children:n.jsx(Ft,{size:20})}),n.jsx("span",{className:"mdocs-sidebar-icon mdocs-tooltip","data-tooltip":e("newFolder"),onClick:()=>tt(),children:n.jsx(_t,{size:20})})]}),n.jsx(oi,{nodes:A,activeDocumentId:Y??null,selectedParentPath:Dt,onOpen:o=>{Z(()=>R(`/doc/${o.documentId}`))},onOpenFolder:(o,f)=>{Z(()=>{X(o),f&&R(`/doc/${f}`)})},onContextMenu:It,onMoveDocument:Hn,onDeselect:()=>{Z(()=>{X(""),R("/")})}}),n.jsxs("footer",{className:"mdocs-sidebar-footer",children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,cursor:"pointer"},onClick:()=>Z(()=>Le("settings")),children:[n.jsx("span",{className:"mdocs-visitor-avatar",children:C?C.visitorName.charAt(0).toUpperCase():"?"}),n.jsx("span",{className:"mdocs-visitor-footer-name",children:C?C.visitorName:""})]}),n.jsx("button",{type:"button",className:"mdocs-sidebar-bookmark mdocs-tooltip","data-tooltip":e("bookmark"),onClick:()=>{Ee(!0),Pt(""),Tt(""),Rn()},style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",fontSize:"1rem",lineHeight:1,borderRadius:4},children:n.jsx(bo,{size:16,strokeWidth:1.5})}),n.jsx("button",{type:"button",className:"mdocs-sidebar-logout mdocs-tooltip","data-tooltip":e("logout"),onClick:()=>Ue(!0),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",lineHeight:1,borderRadius:4},children:n.jsx(mo,{size:16,strokeWidth:1.5})})]})]}),n.jsxs("main",{className:"mdocs-main",children:[u&&M&&M.documentId===u.documentId?n.jsxs("div",{className:"mdocs-editor-with-comments",children:[n.jsx("div",{className:"mdocs-editor-container",children:n.jsx(a.Suspense,{fallback:n.jsx("div",{className:"muted",style:{padding:24},children:"加载编辑器…"}),children:n.jsx(Mi,{meta:u,initialContent:M.content,initialDisplayName:M.displayName,contentRevision:Je,canEdit:!!(C&&(u.ownerVisitorId===C.visitorId||No(u.permission)||u.invitedEdit===!0)),domains:T,currentDomainId:F,onDomainChange:o=>{Z(()=>{localStorage.setItem("mdocs.currentDomainId",o),H(o),N(null),O(null),X(""),R("/"),V(o)})},onDomainsChange:_,onPublish:Fn,syncBehind:B,onSyncClick:()=>void jt(),onDraftExistsChange:S,onConflictModalRequest:()=>re(!0),onMergeRequest:()=>pe(!0),canManageInvites:!!(C&&C.visitorId===u.ownerVisitorId),onDelete:async()=>{if(u.relativePath.endsWith("/___desc___.md")){const o=u.relativePath.replace(/\/___desc___\.md$/,"");Ot(u.documentId,o)}else Rt(u.documentId,u.relativePath)},saveBeforeNavRef:Q,exportMarkdownRef:$e,onShowToast:U,onShowError:K,onToggleComments:()=>m(!h),commentPanelOpen:h,commentCount:g,onAiWrite:()=>void wn()},u.documentId)})}),h&&n.jsx(wi,{documentId:u.documentId,visitorId:C==null?void 0:C.visitorId,visitorName:C==null?void 0:C.visitorName,documentOwnerId:u.ownerVisitorId,onClose:()=>m(!1)})]}):n.jsxs("div",{className:"mdocs-welcome",children:[n.jsx("h1",{children:e("brand")}),n.jsx("p",{className:"muted mdocs-welcome-lead",children:A.length===0?e("noDocsInDomain"):e("createDocToStart")}),n.jsxs("div",{className:"mdocs-welcome-domain",children:[n.jsx("label",{className:"muted mdocs-welcome-domain-label",children:e("domainLabel")}),n.jsx(di,{domains:T.length?T:[{domainId:"default",domainName:e("defaultDomain"),permission:"",creatorVisitorId:"",docCount:0}],value:F,onChange:o=>{Z(()=>{localStorage.setItem("mdocs.currentDomainId",o),H(o),N(null),O(null),X(""),R("/"),V(o)})},onDomainsChange:_,ariaLabel:e("domainLabel"),localizeName:o=>gi(o,t,e)})]}),n.jsxs("div",{className:"mdocs-welcome-actions",children:[n.jsxs("button",{type:"button",className:"primary",onClick:()=>et(),style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx(Ft,{size:16,strokeWidth:1.5}),e("newDocument")]}),n.jsxs("button",{type:"button",className:"secondary",onClick:()=>tt(),style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx(_t,{size:16,strokeWidth:1.5}),e("newFolder")]}),n.jsxs("button",{type:"button",className:"secondary",onClick:()=>xn(),style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("img",{src:mn,alt:"",width:16,height:16,style:{display:"block"}}),"AI 帮写"]})]})]}),n.jsx(bi,{open:Ke,onClose:()=>re(!1),onResolve:()=>{re(!1),pe(!0)}}),ke&&u&&wt&&n.jsx(a.Suspense,{fallback:n.jsx("div",{className:"merge-view-loading",children:e("mergeLoadingRemote")}),children:n.jsx(Fi,{documentId:u.documentId,displayName:u.displayName,conflict:wt,onClose:()=>pe(!1),onSuccess:Bn,onError:o=>K(o)})}),Ne&&n.jsx("div",{className:"mdocs-toast",role:"status",children:Ne}),xt&&n.jsx(hi,{title:e("error"),message:xt,onClose:()=>K(null)})]}),An&&n.jsx("div",{className:"mdocs-dialog-backdrop",onClick:o=>{o.target===o.currentTarget&&Ue(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:440},children:[n.jsx("h1",{style:{fontSize:"1.125rem",marginBottom:8},children:"退出当前登录身份?"}),n.jsx("p",{style:{lineHeight:1.6,color:"var(--mdocs-text-secondary, #666)",marginBottom:20},children:"这将会导致您无法修改以前的文章。如果想找回账号,需要恢复码或联系管理员执行合并用户脚本。"}),n.jsxs("div",{className:"mdocs-dialog-actions",style:{justifyContent:"flex-end"},children:[n.jsx("button",{type:"button",onClick:()=>Ue(!1),children:"取消"}),n.jsx("button",{type:"button",className:"primary",style:{background:"#d32f2f"},onClick:()=>{Fo(),N(null),O(null),E(null),P([]),Ue(!1),s("needsRegister")},children:"确认退出"})]})]})}),jn&&n.jsx("div",{className:"mdocs-dialog-backdrop",onClick:o=>{o.target===o.currentTarget&&Ee(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:640,width:"min(640px, 100%)",maxHeight:"70vh",display:"flex",flexDirection:"column"},children:[n.jsxs("h1",{style:{fontSize:"1.125rem",marginBottom:16},children:[e("bookmarkTitle"),"(",ge.length,")"]}),ge.length>0&&n.jsxs("div",{className:"mdocs-bookmark-filterbar",children:[n.jsx("input",{type:"text",placeholder:e("bookmarkSearch"),value:nt,onChange:o=>Pt(o.target.value)}),n.jsxs("select",{value:Ve,onChange:o=>Tt(o.target.value),children:[n.jsx("option",{value:"",children:e("bookmarkFilterAll")}),On.map(o=>n.jsx("option",{value:o.id,children:o.name},o.id))]})]}),ge.length===0?n.jsx("p",{style:{color:"var(--mdocs-text-muted, #999)",textAlign:"center",padding:"2rem 0"},children:e("bookmarkEmpty")}):At.length===0?n.jsx("p",{style:{color:"var(--mdocs-text-muted, #999)",textAlign:"center",padding:"2rem 0"},children:e("bookmarkNoMatch")}):n.jsx("div",{style:{overflowY:"auto",flex:1,margin:"0 -1rem",padding:"0 1rem"},children:n.jsxs("table",{className:"mdocs-bookmark-table",children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:e("bookmarkColTitle")}),n.jsx("th",{children:e("bookmarkColDomain")}),n.jsx("th",{children:e("bookmarkColAuthor")}),n.jsx("th",{children:e("bookmarkColTime")}),n.jsx("th",{className:"mdocs-bookmark-col-action"})]})}),n.jsx("tbody",{children:At.map(o=>{const f=Mn.has(o.documentId);return n.jsxs("tr",{className:`${f?"mdocs-bookmark-removing":""}`,style:{opacity:o.isDeleted?.6:1},children:[n.jsx("td",{className:"mdocs-bookmark-col-title",children:n.jsxs("div",{style:{cursor:o.isDeleted?"default":"pointer",display:"flex",alignItems:"center",gap:6,overflow:"hidden"},onClick:()=>{o.isDeleted||Z(()=>{Ee(!1),R(`/doc/${o.documentId}`)})},children:[n.jsx("span",{ref:c=>{if(c){const w=c.scrollWidth>c.clientWidth;c.title=w?o.displayName??"":""}},style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:o.displayName??"(无标题)"}),o.isDeleted&&n.jsx("span",{style:{fontSize:"0.7rem",color:"#d32f2f",background:"#ffebee",padding:"1px 6px",borderRadius:4,flexShrink:0},children:"已删除"})]})}),n.jsx("td",{children:o.isDeleted?"":ot[o.domainId??""]??o.domainId??""}),n.jsx("td",{children:o.isDeleted?"":o.ownerVisitorName??"-"}),n.jsx("td",{children:o.isDeleted?"":_i(o.bookmarkedAt,t)}),n.jsx("td",{className:"mdocs-bookmark-col-action",children:n.jsxs("div",{style:{display:"flex",gap:2,alignItems:"center",justifyContent:"flex-end"},children:[n.jsx("button",{type:"button",className:"mdocs-tooltip","data-tooltip":e("bookmarkOpen"),onClick:()=>{o.isDeleted||Z(()=>{Ee(!1),R(`/doc/${o.documentId}`)})},style:{background:"none",border:"none",cursor:o.isDeleted?"default":"pointer",padding:"4px",color:"var(--mdocs-text-muted, #999)",lineHeight:1,borderRadius:4,display:"inline-flex",alignItems:"center"},children:n.jsx(ao,{size:14,strokeWidth:1.5})}),n.jsx("button",{type:"button",className:"mdocs-tooltip","data-tooltip":e("bookmarkRemove"),onClick:async()=>{try{await Jo(o.documentId),Et(c=>new Set(c).add(o.documentId)),setTimeout(()=>{Nt(c=>c.filter(w=>w.documentId!==o.documentId)),Et(c=>{const w=new Set(c);return w.delete(o.documentId),w})},300)}catch(c){K(me(e,c))}},style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--mdocs-text-muted, #999)",fontSize:"1rem",lineHeight:1,borderRadius:4,display:"inline-flex",alignItems:"center"},onMouseEnter:c=>{c.currentTarget.style.color="#d32f2f"},onMouseLeave:c=>{c.currentTarget.style.color="var(--mdocs-text-muted, #999)"},children:"✕"})]})})]},o.documentId)})})]})}),n.jsx("div",{className:"mdocs-dialog-actions",style:{justifyContent:"flex-end",marginTop:16,paddingTop:16,borderTop:"1px solid var(--mdocs-border, #eee)"},children:n.jsx("button",{type:"button",onClick:()=>Ee(!1),children:e("close")})})]})}),Pe&&n.jsx(si,{x:Pe.x,y:Pe.y,node:Pe.node,parentPath:Pe.parentPath,onClose:()=>It(null),onCreateChild:o=>et(o),onCreateFolder:o=>tt(o),onDeleteDocument:o=>Rt(o.documentId,o.path),onDeleteFolder:o=>Ot(o.documentId,o.folderDisplayName||o.name)}),q&&n.jsx(un,{title:q.type==="folder"?"删除文件夹":"删除文档",message:q.type==="folder"?`确定要删除「${q.name}」及其下的所有文档和子文件夹吗?此操作不可撤销。`:`确定要删除「${q.name}」吗?`,confirmLabel:"删除",cancelLabel:"取消",onConfirm:Un,onCancel:()=>Oe(null),danger:!0}),we&&n.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:o=>{o.target===o.currentTarget&&!xe&&Ze(null)},children:n.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[n.jsx("h1",{children:we.kind==="document"?e("newDocumentTitle"):e("newFolderTitle")}),n.jsx("p",{className:"muted",children:we.kind==="document"?e("fileNameHint"):e("folderNameHint")}),n.jsxs("form",{onSubmit:En,className:"mdocs-dialog-form",children:[n.jsxs("label",{className:"mdocs-dialog-label",children:[we.kind==="document"?e("fileNameLabel"):e("folderNameLabel"),n.jsx("input",{ref:Tn,value:we.draft,onChange:o=>Ze(f=>f&&{...f,draft:o.target.value}),placeholder:we.kind==="document"?e("untitledPlaceholder"):e("folderExamplePlaceholder"),maxLength:200,disabled:xe})]}),kt&&n.jsx("div",{className:"mdocs-dialog-error",children:kt}),n.jsxs("div",{className:"mdocs-dialog-actions",children:[n.jsx("button",{type:"button",onClick:()=>!xe&&Ze(null),disabled:xe,children:e("cancel")}),n.jsx("button",{type:"submit",className:"primary",disabled:xe,children:e(xe?"creating":"create")})]})]})]})})]})]})]})}const Bi=a.lazy(()=>Ce(()=>import("./PlaygroundPage-BSGipUkC.js"),__vite__mapDeps([16,1,4,5,2,3,6,7,8,9])).then(e=>({default:e.PlaygroundPage})));function $i(){return n.jsxs(Gn,{children:[n.jsx(it,{path:"/",element:n.jsx(en,{})}),n.jsx(it,{path:"/doc/:documentId",element:n.jsx(en,{})}),n.jsx(it,{path:"/playground",element:n.jsx(a.Suspense,{fallback:n.jsx("div",{style:{padding:24},children:"Loading playground…"}),children:n.jsx(Bi,{})})})]})}const hn=document.getElementById("root");if(!hn)throw new Error("root element missing");Yn.createRoot(hn).render(n.jsx(Jn.StrictMode,{children:n.jsx(Xn,{motion:Zn,children:n.jsx(Qn,{children:n.jsx(So,{children:n.jsx(Kn,{children:n.jsx($i,{})})})})})}));export{Ir as $,Re as A,Ji as B,Ho as C,di as D,Or as E,Zo as F,ar as G,rr as H,ir as I,or as J,cr as K,Ki as L,fo as M,Qi as N,Xi as O,Zi as P,dr as Q,sr as R,bo as S,lr as T,mr as U,ur as V,qt as W,Dr as X,Cr as Y,br as Z,Yo as _,G as a,ji as a0,rn as a1,un as a2,tr as a3,er as a4,vr as a5,Sr as a6,Nr as a7,Ae as a8,kr as a9,Pr as aa,Tr as ab,Er as ac,Rr as ad,Mr as ae,jr as af,Ar as ag,Me as ah,fr as ai,rt as aj,Gt as ak,ho as al,de as b,se as c,st as d,wr as e,nr as f,$t as g,qi as h,mn as i,pr as j,xr as k,gi as l,te as m,gr as n,hr as o,yr as p,sn as q,Jo as r,Uo as s,oi as t,Di as u,an as v,me as w,Ci as x,Ni as y,dt as z};