@fgbg/mdocs 1.1.0 → 1.1.2

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 (37) hide show
  1. package/agent-skills/changelog/SKILL.md +18 -0
  2. package/dist/server/routes/assets.routes.js +9 -4
  3. package/dist/server/routes/assets.routes.js.map +1 -1
  4. package/dist/server/routes/assets.routes.upload.test.js +1 -0
  5. package/dist/server/routes/assets.routes.upload.test.js.map +1 -1
  6. package/dist/web/assets/{AgentChatPanel-C8TMWDuE.js → AgentChatPanel-Bt38gm3b.js} +2 -2
  7. package/dist/web/assets/{AgentSkillFormCard-yk7PWF0W.js → AgentSkillFormCard-CtfWIf7Y.js} +1 -1
  8. package/dist/web/assets/AiWriteWorkbench-Boie5E_-.js +7 -0
  9. package/dist/web/assets/{DiagramEditor-NtNY3sZL-Bw4wHaBD.js → DiagramEditor-NtNY3sZL-CZy-tmEe.js} +1 -1
  10. package/dist/web/assets/DocumentEditor-1A6lpvV-.js +26 -0
  11. package/dist/web/assets/{MergeView-royv5YkB.js → MergeView-Dip0aW7s.js} +1 -1
  12. package/dist/web/assets/PlaygroundPage-C4X6Lj-Q.js +8 -0
  13. package/dist/web/assets/{SettingsPage-D8HfepZ8.js → SettingsPage-nlnmzNZK.js} +1 -1
  14. package/dist/web/assets/{Toolbar-BDJ6WABq.js → Toolbar-BHLX-ug4.js} +2 -2
  15. package/dist/web/assets/{VisitorPickerModal-DPKIoySi.js → VisitorPickerModal-BPyEWlQo.js} +1 -1
  16. package/dist/web/assets/{copy-UwfRYkpI.js → copy-BE64wQqi.js} +1 -1
  17. package/dist/web/assets/diagram-CT58wBdU.js +5772 -0
  18. package/dist/web/assets/{editor-ONzd_YnO.js → editor-CL03se2B.js} +1 -1
  19. package/dist/web/assets/{index-4TuRcE3b.js → index-BkKvQv2F.js} +24 -24
  20. package/dist/web/assets/index-DKshvHIN.css +1 -0
  21. package/dist/web/assets/{meta2d-D3b5RRN8.js → meta2d-1-g23JOU.js} +1 -1
  22. package/dist/web/assets/{meta2dEngine-BD2XbzaV-D1J2-XNv.js → meta2dEngine-BD2XbzaV-z-eR7E_V.js} +1 -1
  23. package/dist/web/assets/{motion-DddvD-ez.js → motion-DX3HNq_4.js} +2 -2
  24. package/dist/web/assets/{plus-CiGwts52.js → plus-ECzYbQfA.js} +1 -1
  25. package/dist/web/assets/react-GP8hKHRA.js +2122 -0
  26. package/dist/web/assets/react-vendor-BuABiQkA.js +242 -0
  27. package/dist/web/assets/ui-BQStT3dY.js +3116 -0
  28. package/dist/web/index.html +6 -6
  29. package/package.json +2 -2
  30. package/dist/web/assets/AiWriteWorkbench-ChCJt24m.js +0 -7
  31. package/dist/web/assets/DocumentEditor-B3Dsq02C.js +0 -26
  32. package/dist/web/assets/PlaygroundPage-B-_1l4Ix.js +0 -8
  33. package/dist/web/assets/diagram--gCCJK__.js +0 -6257
  34. package/dist/web/assets/index-C4ESYs7f.css +0 -1
  35. package/dist/web/assets/react-B99eF5mm.js +0 -2377
  36. package/dist/web/assets/react-vendor-BJFXgntS.js +0 -242
  37. package/dist/web/assets/ui-BHvBMRFE.js +0 -3126
@@ -0,0 +1,8 @@
1
+ import{r as n,j as o,ad as C}from"./react-vendor-BuABiQkA.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-GP8hKHRA.js";import{a7 as Q,a8 as X,a9 as ee,aa as te,ab as k,ac as oe}from"./ui-BQStT3dY.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,c as R,o as ce}from"./Toolbar-BHLX-ug4.js";import{N as me}from"./index-BkKvQv2F.js";import"./editor-CL03se2B.js";import"./diagram-CT58wBdU.js";import"./plus-ECzYbQfA.js";import"./copy-BE64wQqi.js";import"./motion-DX3HNq_4.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[g,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:g,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,g]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");g(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(J,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(W,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{ce(l=>{for(const u of l)e.dispatchCommand(z,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
2
+ 123`),queueMicrotask(()=>{e.focus()})}},{key:"insert-link",label:"InsertLink",onSelect:e=>{e.dispatchCommand(B,{url:"https://example.com"}),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeInline",label:"InsertCodeInline",onSelect:e=>{e.dispatchCommand($,void 0),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeBlock",label:"InsertCodeBlock",onSelect:e=>{e.dispatchCommand(K,void 0),queueMicrotask(()=>{e.focus()})}},{icon:de,key:"meta2d",label:"Meta2d",onSelect:e=>{e.dispatchCommand(Y,void 0),queueMicrotask(()=>{e.focus()})}},{icon:me,key:"markmap",label:"Markmap",onSelect:e=>{e.dispatchCommand(G,void 0),queueMicrotask(()=>{e.focus()})}}].map(e=>e.type==="divider"?e:{...e,extra:o.jsx(oe,{code:!0,fontSize:12,type:"secondary",children:e.key})}),[]);return o.jsxs(ue,{json:m,markdown:p,onJSONChange:s,...h,children:[o.jsx(R,{editor:r}),o.jsx(T,{className:"mdocs-playground-editor",content:ye,editor:r,lineEmptyPlaceholder:"Start typing here...",mentionOption:{items:d,markdownWriter:t=>{var e;return`
3
+ <mention>${t.label}[${((e=t.metadata)==null?void 0:e.id)||t.label}]</mention>
4
+ `},onSelect:(t,e)=>{t.dispatchCommand(U,{label:String(e.label),metadata:{id:e.key}})},searchKeys:["label"]},onInit:x,onTextChange:c,pasteVSCodeAsCodeBlock:!0,placeholder:"Type something...",plugins:[I,E,M,j,O,P,A,_,D,L,f(H,{children:o.jsx(R,{editor:r,floating:!0})}),f(F,{delay:1e3,onAutoComplete:async({input:t,afterText:e,selectionType:l,abortSignal:u})=>{console.log("Auto-complete triggered:",{afterText:e,input:t,selectionType:l});try{const v=await fetch(`${location.origin}/nodeserver/completion`,{body:JSON.stringify({prompt:`Please complete the following text:
5
+
6
+ ${t}`}),headers:{"Content-Type":"application/json"},method:"POST",signal:u});if(u.aborted)return console.log("Auto-complete aborted"),null;const i=await v.json();if(i)return typeof i.content=="string"&&i.content.startsWith(t)?i.content.replace(t,""):i.content}catch{}return null}}),f(M,{defaultBlockImage:!0,handleRehost:async t=>{const l=await(await fetch(t)).blob();return await new Promise((u,v)=>{const i=new FileReader;i.onloadend=()=>u({url:i.result}),i.onerror=v,i.readAsDataURL(l)})},needRehost:t=>(console.debug("needRehost",t),t.startsWith("blob:"))}),f(q,{handleUpload:async t=>(console.debug("Files uploaded:",t),new Promise(e=>{setTimeout(()=>{const l=URL.createObjectURL(t);a.current.push(l),e({url:l})},1e3)})),markdownWriter:t=>`
7
+ <file>${t.fileUrl}</file>
8
+ `})],slashOption:{items:w}})]})};function Ce(){return o.jsxs("div",{className:"mdocs-playground-page",children:[o.jsx("header",{className:"mdocs-playground-header",children:o.jsx(C,{className:"mdocs-playground-back",to:"/",children:"← mdocs"})}),o.jsx(pe,{})]})}export{Ce as PlaygroundPage};
@@ -1 +1 @@
1
- import{r as a,j as e}from"./react-vendor-BJFXgntS.js";import{b as te,q as Je,s as Qe,D as Xe,l as Ne,t as es,v as ss,w as J,x as ye,y as ts,z as as,A as ns,a as is,d as Ee,B as ze,C as Fe,E as ls,G as cs,H as rs,I as os,J as ds,K as Be,L as je,O as ms,Q as us,R as hs,T as ps,U as gs,f as fs,V as xs,W as js,X as bs,Y as Ns,Z as ys,_ as Ke,$ as vs,a0 as ks,a1 as ws,a2 as Ss,a3 as Cs,a4 as Ds,a5 as Is,a6 as Ts,a7 as As,a8 as Es,a9 as Ps,aa as Ms,ab as Ls,P as Rs,ac as zs,ad as Fs,ae as Bs,r as Ks,k as $s,af as Os,n as Vs,o as Us}from"./index-4TuRcE3b.js";import{V as $e,a as Ws,M as Pe}from"./VisitorPickerModal-DPKIoySi.js";import"./ui-BHvBMRFE.js";import"./motion-DddvD-ez.js";import"./diagram--gCCJK__.js";function _s({draft:t,onClose:s,onSuccess:v}){const{t:u,lang:m}=te(),[z,r]=a.useState([]),[N,j]=a.useState(t.domainId??""),[k,n]=a.useState([]),[y,h]=a.useState(""),[I,S]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[p,f]=a.useState(!1),[A,M]=a.useState(null),C=a.useRef(null),E=a.useRef(!0);a.useEffect(()=>(E.current=!0,()=>{E.current=!1}),[]),a.useEffect(()=>{Je().then(b=>{E.current&&r(b)})},[]),a.useEffect(()=>{N&&(n([]),h(""),Qe(N).then(b=>{E.current&&n(b)}).catch(()=>{E.current&&n([])}))},[N]),a.useEffect(()=>{const b=window.setTimeout(()=>{var T;return(T=C.current)==null?void 0:T.focus()},0);return()=>window.clearTimeout(b)},[]),a.useEffect(()=>{const b=T=>{T.key==="Escape"&&s()};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[s]);function B(b,T){for(const w of b){if(w.type==="folder"&&w.path===T)return w.documentId;if(w.type==="folder"){const P=B(w.children,T);if(P)return P}}return null}async function R(b){b.preventDefault(),f(!0),M(null);const T=I.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),w=T.endsWith(".md")?T:T+".md",P=w.replace(/\.md$/i,"");try{const d=y?`${y}/${w}`:w,c=y?B(k,y)??void 0:void 0;await ss({fileName:w,displayName:P,content:t.content,domainId:N,parentId:c}),v()}catch(d){M(J(u,d))}finally{f(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:b=>{b.target===b.currentTarget&&!p&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:u("recoverDraft")}),e.jsx("p",{className:"muted",children:u("recoverDraftDesc",{name:t.displayName||u("unknownTitle")})}),e.jsxs("form",{onSubmit:R,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[u("domainLabel"),z.length>0&&e.jsx(Xe,{domains:z,value:N,onChange:j,onDomainsChange:r,ariaLabel:u("domainLabel"),localizeName:b=>Ne(b,m,u)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[u("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(es,{nodes:k,activeDocumentId:null,selectedParentPath:y,onOpen:()=>{},onOpenFolder:b=>h(b),onContextMenu:()=>{},onDeselect:()=>h("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[u("fileNameLabel"),e.jsx("input",{ref:C,value:I,onChange:b=>S(b.target.value),placeholder:"recovered.md",maxLength:200,disabled:p})]}),A&&e.jsx("div",{className:"mdocs-dialog-error",children:A}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!p&&s(),disabled:p,children:u("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:p,children:u(p?"creating":"create")})]})]})]})})}function Hs({onPublish:t,onClose:s,onCountChange:v,onRecover:u}){const{t:m}=te(),[z,r]=a.useState([]),[N,j]=a.useState(new Set),[k,n]=a.useState(!1),[y,h]=a.useState(null),[I,S]=a.useState(null),[p,f]=a.useState(null),A=a.useRef(null),M=a.useRef(!0);a.useEffect(()=>(M.current=!0,ye().then(c=>{if(!M.current)return;const g=c.filter(D=>!D.published);r(g),v==null||v(g.length)}),()=>{M.current=!1,A.current&&(clearTimeout(A.current),A.current=null)}),[]),a.useEffect(()=>{const c=g=>{g.key==="Escape"&&s()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s]);const C=a.useCallback((c,g)=>{f({message:c,type:g}),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>f(null),3e3)},[]);async function E(c){await as(c),j(g=>new Set(g).add(c));try{await t(c),r(g=>{const D=g.filter(F=>F.documentId!==c);return v==null||v(D.length),D}),C(m("published"),"success")}catch(g){g instanceof ns||C(m("publishFailed"),"error");const D=await is(c);D&&r(F=>F.map(V=>V.documentId===c?D:V))}finally{j(g=>{const D=new Set(g);return D.delete(c),D})}}async function B(c){h(null),await Ee(c),r(g=>{const D=g.filter(F=>F.documentId!==c);return v==null||v(D.length),D}),C(m("draftDeleted"),"success")}function R(c){const g=z.find(D=>D.documentId===c);g&&S(g)}function b(c){S(null),Ee(c),r(g=>{const D=g.filter(F=>F.documentId!==c);return v==null||v(D.length),D}),u==null||u(z.find(g=>g.documentId===c)),C(m("published"),"success")}async function T(){n(!0);let c=0,g=0;for(const V of z)try{await t(V.documentId),c++}catch{g++}const F=(await ye()).filter(V=>!V.published);r(F),v==null||v(F.length),g===0?C(m("publishAll"),"success"):C(`${c} published, ${g} failed`,"error"),n(!1)}const w=c=>new Date(c).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),P=c=>ts(m,c,c.publishError??"UNKNOWN"),d=z;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-drawer-overlay",onClick:s}),e.jsxs("div",{className:"mdocs-drawer",role:"dialog","aria-modal":"true",children:[e.jsxs("header",{className:"mdocs-drawer-header",children:[e.jsxs("div",{className:"mdocs-drawer-header-text",children:[e.jsxs("h2",{className:"mdocs-drawer-title",children:[m("unpublishedDrafts"),d.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:d.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:m("draftCount",{count:String(d.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":m("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:d.length===0?e.jsxs("div",{className:"mdocs-drawer-empty",children:[e.jsx("div",{className:"mdocs-drawer-empty-icon","aria-hidden":"true",children:"✓"}),e.jsx("p",{className:"mdocs-drawer-empty-text",children:m("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:d.map(c=>{const g=!!c.publishError;return e.jsxs("div",{className:g?"mdocs-drawer-item mdocs-drawer-item-failed":"mdocs-drawer-item",children:[e.jsx("div",{className:"mdocs-drawer-item-icon","aria-hidden":"true",children:"📄"}),e.jsxs("div",{className:"mdocs-drawer-item-info",children:[e.jsx("span",{className:"mdocs-drawer-item-name",children:c.displayName||m("unknownTitle")}),g?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[w(c.publishErrorAt)," · ",P(c)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[w(c.updatedAt)," · ",m("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[g?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:k,onClick:()=>R(c.documentId),children:m("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:N.has(c.documentId)||k,onClick:()=>void E(c.documentId),children:N.has(c.documentId)?m("publishing"):m("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:k,onClick:()=>h(c.documentId),children:m("delete")})]})]},c.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:m("close")}),e.jsx("button",{type:"button",className:"primary",disabled:d.length===0||k,onClick:()=>void T(),children:k?m("publishing"):`${m("publishAll")} (${d.length})`})]}),p&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+p.type,role:"status",children:p.message})]}),y&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:c=>{c.target===c.currentTarget&&h(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:m("delete")}),e.jsx("p",{className:"muted",children:m("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>h(null),children:m("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void B(y),children:m("delete")})]})]})}),I&&e.jsx(_s,{draft:I,onClose:()=>S(null),onSuccess:()=>b(I.documentId)})]})}function qs(){const{t,lang:s}=te(),v=ze(),u=a.useRef(!1),[m,z]=a.useState([]),[r,N]=a.useState(!1),[j,k]=a.useState(""),[n,y]=a.useState("restricted"),[h,I]=a.useState(!1),[S,p]=a.useState(null),[f,A]=a.useState(null),[M,C]=a.useState(""),[E,B]=a.useState(""),[R,b]=a.useState("all"),[T,w]=a.useState(null);a.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const P=a.useCallback(async()=>{N(!0),p(null);try{const x=await Fe();if(!u.current)return;z(x)}catch(x){if(!u.current)return;p(J(t,x))}finally{u.current&&N(!1)}},[t]);a.useEffect(()=>{P()},[P]);async function d(x){if(x.preventDefault(),!j.trim()){p(t("domainNameRequired"));return}I(!0),p(null);try{if(await ds({domainName:j.trim(),permission:n}),!u.current)return;k(""),y("restricted"),await P()}catch($){if(!u.current)return;p(J(t,$))}finally{u.current&&I(!1)}}async function c(x){if(M.trim()){p(null);try{if(await os(x,M.trim()),!u.current)return;A(null),w(null),await P()}catch($){if(!u.current)return;p(J(t,$))}}}function g(x){A(x.domainId),C(x.domainName),w(null)}function D(){A(null),w(null)}async function F(x,$){p(null);try{if(await rs(x,$),!u.current)return;w(null),await P()}catch(U){if(!u.current)return;p(J(t,U))}}async function V(x){if(window.confirm(t("deleteDomainConfirmDetail",{name:x.domainName,count:String(x.docCount)}))){p(null);try{if(await cs(x.domainId),!u.current)return;await P()}catch($){if(!u.current)return;p(J(t,$))}}}const H=a.useCallback(x=>ls(x,t),[t]),q=a.useCallback(x=>Ne(x.domainName,s,t),[s,t]),G=a.useMemo(()=>{const x=E.trim().toLowerCase();return m.filter($=>R!=="all"&&$.permission!==R?!1:x?Ne($.domainName,s,t).toLowerCase().includes(x)||$.domainName.toLowerCase().includes(x):!0)},[m,E,R,s,t]),W=a.useCallback((x,$)=>{const U=H(x.permission);return $?`${U} ${t("domainTypeBuiltinSuffix")}`:U},[H,t]);return{domains:m,loadingDomains:r,domainError:S,newDomainName:j,setNewDomainName:k,newDomainPermission:n,setNewDomainPermission:y,creating:h,handleCreateDomain:d,renamingId:f,setRenamingId:A,renameDraft:M,setRenameDraft:C,startRename:g,cancelRename:D,handleRename:c,changeTypeForId:T,setChangeTypeForId:w,handlePermissionChange:F,handleDelete:V,domainSearch:E,setDomainSearch:B,domainFilter:R,setDomainFilter:b,filteredDomains:G,visitorId:v,plabel:H,localizeDomain:q,domainTypeLabel:W}}function Gs(){const{t}=te(),s=qs(),[v,u]=a.useState([]),[m,z]=a.useState(null),[r,N]=a.useState(null),j=a.useCallback(async()=>{try{const n=await Be();u(n)}catch{u([])}},[]);a.useEffect(()=>{j()},[j]);async function k(n){z(null);try{const y=await gs(n.domainId);N({domainId:n.domainId,creatorVisitorId:n.creatorVisitorId,initialIds:y.map(h=>h.visitorId),memberRows:y})}catch(y){z({kind:"err",text:J(t,y)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:t("domainManagement")})}),e.jsx("p",{className:"mdocs-domain-mgmt-restricted-hint",children:t("domainMgmtRestrictedMemberHint")}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-create",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("createDomain")}),e.jsxs("form",{onSubmit:s.handleCreateDomain,className:"mdocs-domain-mgmt-create-form",children:[e.jsxs("label",{className:"mdocs-domain-mgmt-field",children:[e.jsx("span",{className:"mdocs-domain-mgmt-label",children:t("domainName")}),e.jsx("input",{value:s.newDomainName,onChange:n=>s.setNewDomainName(n.target.value),placeholder:t("domainName"),maxLength:100,disabled:s.creating,className:"mdocs-domain-name-input"})]}),e.jsxs("fieldset",{className:"mdocs-domain-mgmt-fieldset",children:[e.jsx("legend",{className:"mdocs-domain-mgmt-label",children:t("domainPermission")}),e.jsx("div",{className:"mdocs-domain-mgmt-type-radios",children:je.map(n=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===n,onChange:()=>s.setNewDomainPermission(n),disabled:s.creating}),e.jsx("span",{children:s.plabel(n)})]},n))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?t("creating"):t("create")})]})]}),m&&e.jsx("div",{className:"mdocs-settings-card",style:{color:m.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:m.text})}),s.domainError&&e.jsx("div",{className:"mdocs-settings-card mdocs-domain-error",children:e.jsx("span",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)"},children:s.domainError})}),e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-toolbar",children:[e.jsx("input",{type:"search",value:s.domainSearch,onChange:n=>s.setDomainSearch(n.target.value),placeholder:t("domainSearchPlaceholder"),className:"mdocs-domain-mgmt-search","aria-label":t("domainSearchPlaceholder")}),e.jsx("div",{className:"mdocs-domain-mgmt-filters",role:"group","aria-label":t("domainPermission"),children:["all",...je].map(n=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===n?" active":""),"aria-pressed":s.domainFilter===n,onClick:()=>s.setDomainFilter(n),children:n==="all"?t("domainFilterAll"):s.plabel(n)},n))})]}),s.loadingDomains?e.jsx("div",{className:"mdocs-settings-card",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")})}):s.domains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("noDomains")})}):s.filteredDomains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("domainNoMatch")})}):e.jsx("div",{className:"mdocs-settings-card mdocs-domain-table-wrap",children:e.jsxs("table",{className:"mdocs-domain-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:t("domainColName")}),e.jsx("th",{scope:"col",children:t("domainColType")}),e.jsx("th",{scope:"col",className:"mdocs-domain-table-num",children:t("domainColDocCount")}),e.jsx("th",{scope:"col",children:t("domainColActions")})]})}),e.jsx("tbody",{children:s.filteredDomains.map(n=>{const y=ms(n,s.visitorId),h=us(n.domainId),I=hs(n),S=I?t("domainTooltipTypeLocked",{count:String(n.docCount)}):void 0;return e.jsxs("tr",{className:h?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===n.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:p=>s.setRenameDraft(p.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(n.domainId),children:t("save")}),e.jsx("button",{type:"button",onClick:s.cancelRename,children:t("cancel")})]}):e.jsxs("div",{className:"mdocs-domain-table-name-cell",children:[e.jsx("span",{className:"mdocs-domain-table-name",children:s.localizeDomain(n)}),h&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!y&&!h&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsxs("span",{className:"mdocs-domain-table-type",title:S,children:[e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":n.permission,children:s.domainTypeLabel(n,h)}),I&&!h&&e.jsx("span",{className:"mdocs-domain-type-lock","aria-hidden":"true",children:"🔒"})]})}),e.jsx("td",{className:"mdocs-domain-table-num",children:n.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[h&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!h&&!y&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!h&&y&&s.changeTypeForId===n.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",children:[e.jsx("div",{className:"mdocs-domain-permission-select",children:je.map(p=>e.jsx("button",{type:"button",className:n.permission===p?"active":"",onClick:()=>void s.handlePermissionChange(n.domainId,p),children:s.plabel(p)},p))}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>s.setChangeTypeForId(null),children:t("cancel")})]}),!h&&y&&s.renamingId!==n.domainId&&s.changeTypeForId!==n.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[e.jsx("button",{type:"button",className:"secondary",title:I?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(n)},disabled:I,children:t("rename")}),e.jsx("button",{type:"button",className:"secondary",title:I?S:void 0,onClick:()=>{s.setRenamingId(null),s.setChangeTypeForId(n.domainId)},disabled:I,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"secondary",title:I?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(n),disabled:I,children:t("deleteDomain")}),n.permission==="restricted"&&!h&&e.jsx("button",{type:"button",className:"secondary",onClick:()=>void k(n),children:t("domainMembersManageButton")})]})]})]},n.domainId)})})]})})]}),e.jsx($e,{open:r!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(r==null?void 0:r.initialIds)??[],lockedIds:r?[r.creatorVisitorId]:[],seedMembers:r==null?void 0:r.memberRows,templates:v,onClose:()=>N(null),onConfirm:async n=>{r&&(await ps(r.domainId,n),z({kind:"ok",text:t("domainMembersSaved",{count:String(n.length)})}))}})]})}function Me(t){return t.length<=6?t:`${t.slice(0,6)}…`}function Zs(){const{t}=te(),s=a.useRef(!0),[v,u]=a.useState([]),[m,z]=a.useState(!0),[r,N]=a.useState(null),[j,k]=a.useState(1),[n,y]=a.useState(null),[h,I]=a.useState(""),[S,p]=a.useState([]),[f,A]=a.useState(!1),[M,C]=a.useState(null),[E,B]=a.useState(!1),R=ze(),[b,T]=a.useState([]),[w,P]=a.useState("idle"),[d,c]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{P("loading"),fs().then(o=>{s.current&&(T(o),P("ok"))}).catch(()=>{s.current&&P("err")})},[]);const g=a.useMemo(()=>{const o=new Map;for(const L of b)o.set(L.visitorId,L.visitorName);return o},[b]),D=a.useCallback(async()=>{z(!0),C(null);try{const o=await Be();s.current&&u(o)}catch(o){s.current&&C(J(t,o))}finally{s.current&&z(!1)}},[t]);a.useEffect(()=>{D()},[D]);const F=a.useMemo(()=>S.map(o=>{const L=b.find(O=>O.visitorId===o);return{visitorId:o,name:L?L.visitorName:t("visitorPickerUnknownVisitor"),muted:!L}}),[S,b,t]);function V(o){p(L=>L.includes(o)?L.filter(O=>O!==o):[...L,o])}const H=j===1?h.trim().length>0:j===2?S.length>0:!0;function q(){if(!(j>=3)){if(!H){B(!0);return}B(!1),k(j+1),c("")}}function G(){j<=1||(B(!1),k(j-1))}function W(){N(null),y(null),I(""),p(R?[R]:[]),C(null),k(1),c(""),B(!1)}function x(o){N(null),y(o.id),I(o.displayName);const L=R&&!o.visitorIds.includes(R)?[...o.visitorIds,R]:[...o.visitorIds];p(L),C(null),k(1),c(""),B(!1)}async function $(){if(!(!h.trim()||S.length===0)){A(!0),C(null);try{if(n===null?await xs({displayName:h.trim(),visitorIds:S}):await js(n,{displayName:h.trim(),visitorIds:S}),!s.current)return;W(),await D()}catch(o){if(!s.current)return;C(J(t,o))}finally{s.current&&A(!1)}}}async function U(o){A(!0),C(null);try{if(await bs(o),!s.current)return;N(null),n===o&&W(),await D()}catch(L){if(!s.current)return;C(J(t,L))}finally{s.current&&A(!1)}}const Z=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],Q=`${(j-1)/2*100}%`;return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:t(n!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),n!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:W,style:{fontSize:12},children:t("memberTemplateCancelEdit")})]}),e.jsxs("div",{className:"mdocs-wizard-progress",children:[e.jsx("div",{className:"mdocs-wizard-progress-track",children:e.jsx("div",{className:"mdocs-wizard-progress-fill",style:{width:Q}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:Z.map(o=>{const L=j===o.key,O=j>o.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${L?" current":""}${O?" done":""}`,children:O?"✓":o.key}),e.jsx("span",{className:`mdocs-wizard-step-label${L?" current":""}${O?" done":""}`,children:o.label})]},o.key)})})]}),M&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:M}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[j===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:h,onChange:o=>I(o.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:f,autoFocus:!0,"aria-invalid":E&&!h.trim()}),E&&!h.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),j===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Ws,{visitors:b,loadState:w,searchFilter:d,onSearchChange:c,selectedIds:new Set(S),onToggle:V,selectedRows:F,myVisitorId:R}),e.jsx("p",{className:`mdocs-wizard-hint${E&&S.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),j===3&&e.jsx("div",{className:"mdocs-wizard-step-content",children:e.jsxs("div",{className:"mdocs-wizard-preview-card",children:[e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:h})]}),e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateIdsLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:t("memberTemplateSelectedSummary",{count:String(S.length)})})]}),S.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[S.slice(0,15).map(o=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:Me(o)},o)),S.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",S.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:G,children:["← ",t("memberTemplateWizardBack")]}),j<3?e.jsxs("button",{type:"button",className:"primary",onClick:q,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void $(),children:t(f?"saving":n===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),m?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):v.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),n===null&&e.jsx("button",{type:"button",className:"primary",onClick:W,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:v.map(o=>e.jsx("li",{className:"mdocs-member-template-row",children:r===o.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:t("memberTemplateConfirmDeleteDesc",{name:o.displayName})}),e.jsxs("div",{className:"mdocs-member-template-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",style:{color:"var(--mdocs-danger)"},onClick:()=>void U(o.id),children:t(f?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>N(null),children:t("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:o.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateCount",{count:String(o.visitorIds.length)})}),o.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:o.visitorIds.map(L=>e.jsx("span",{className:"mdocs-member-template-tag",children:g.get(L)??Me(L)},L))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>x(o),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>N(o.id),children:t("memberTemplateDelete")})]})]})},o.id))})]})]})]})}const Ys=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}],Js=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function Qs(t,s,v){return t==="deepseek"?"Deepseek":s||v}function Le(t){return`${Qs(t.kind,t.providerId,t.name)} · ${t.modelId} · ${t.name}`}function Xs(){const{t}=te(),s=a.useRef(!0),[v,u]=a.useState(""),[m,z]=a.useState([]),[r,N]=a.useState(null),[j,k]=a.useState(null),[n,y]=a.useState("deepseek"),[h,I]=a.useState(""),[S,p]=a.useState(""),[f,A]=a.useState(""),[M,C]=a.useState("openai-completions"),[E,B]=a.useState("deepseek-v4-flash"),[R,b]=a.useState(128e3),[T,w]=a.useState(""),[P,d]=a.useState(!1),[c,g]=a.useState(null),[D,F]=a.useState(!1),[V,H]=a.useState(!0),[q,G]=a.useState(!1),[W,x]=a.useState(null),[$,U]=a.useState(!1),[Z,Q]=a.useState(!1),[o,L]=a.useState(!1),[O,ae]=a.useState(null),[re,ie]=a.useState(null),le=a.useRef(!1);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const X=a.useCallback(async()=>{const l=await Ns();if(s.current)return z(l),l},[]);function ee(){k(null),y("deepseek"),I(""),p(""),A(""),C("openai-completions"),B("deepseek-v4-flash"),b(128e3),w(""),d(!1),g(null),F(!1),Q(!1),L(!1),x(null),U(!1)}function oe(l){k(l.id),y(l.kind),I(l.name),p(l.providerId??""),A(l.baseUrl),C(l.apiType),B(l.modelId),b(l.contextWindow||128e3),d(l.hasApiKey),g(l.apiKeyMasked),w(""),F(l.isDefault)}a.useEffect(()=>{(async()=>{try{const l=await ys();if(!s.current)return;u(l.visitorName);const _=await X();if(!s.current||!_)return;_.length===0&&(ee(),N("create"))}catch(l){if(!s.current)return;x(l instanceof Error?l.message:String(l)),N("create")}finally{s.current&&H(!1)}})()},[X]);function me(){ee(),N("create")}function de(l){oe(l),N("edit"),U(!1),x(null)}function se(){ee(),N(null)}async function ue(l){if(!(l.isDefault||re)){ie(l.id),x(null);try{await vs(l.id),await X()}catch(_){if(!s.current)return;x(_ instanceof Error?_.message:String(_))}finally{s.current&&ie(null)}}}async function he(){if(O){G(!0),x(null);try{await ws(O.id);const l=await X();if(!s.current)return;r==="edit"&&j===O.id&&se(),((l==null?void 0:l.length)??0)===0&&(ee(),N("create"))}catch(l){if(!s.current)return;x(l instanceof Error?l.message:String(l))}finally{s.current&&(G(!1),ae(null))}}}async function pe(){G(!0),x(null),U(!1);try{const l=n==="custom"?{...r==="edit"&&j?{id:j}:{},...r==="create"&&D?{isDefault:!0}:{},kind:n,baseUrl:f,modelId:E,providerId:S.trim()||void 0,apiType:M,name:h,contextWindow:R,...T.trim()?{apiKey:T.trim()}:{}}:{...r==="edit"&&j?{id:j}:{},...r==="create"&&D?{isDefault:!0}:{},kind:n,modelId:E,name:h,contextWindow:R,...T.trim()?{apiKey:T.trim()}:{}};if(await ks(l),!s.current)return;await X(),U(!0),N(null),ee()}catch(l){if(!s.current)return;x(l instanceof Error?l.message:String(l))}finally{s.current&&G(!1)}}const ce=r!==null;return e.jsxs("div",{className:"mdocs-agent-config-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:t("agentConfig")}),!V&&!ce?e.jsx("button",{type:"button",className:"secondary",onClick:me,children:"添加配置"}):null]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!V&&m.length>0&&!ce?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:"选择默认配置后,智能助手与帮写将使用该模型。"}),e.jsx("ul",{className:"mdocs-agent-config-list",children:m.map(l=>e.jsxs("li",{className:"mdocs-agent-config-item",children:[e.jsxs("label",{className:"mdocs-agent-config-item-default",children:[e.jsx("input",{type:"radio",name:"agent-default-config",checked:l.isDefault,disabled:re!==null,onChange:()=>void ue(l)}),e.jsx("span",{children:l.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:Le(l)}),l.kind==="custom"?e.jsx("span",{className:"mdocs-agent-badge",children:"自定义"}):null,e.jsx("p",{className:"mdocs-agent-config-item-meta",children:l.hasApiKey?`Key ${l.apiKeyMasked??"已配置"}`:"未配置 Key"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>de(l),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>ae(l),children:"删除"})]})]},l.id))}),$?e.jsx("p",{className:"mdocs-agent-config-ok",children:t("saved")}):null,W?e.jsx("p",{className:"mdocs-agent-config-error",children:W}):null]}):null,ce?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:r==="create"?"新建模型配置":"编辑模型配置"}),e.jsxs("div",{className:"mdocs-agent-form",children:[e.jsxs("div",{className:"mdocs-agent-kind-tabs",role:"tablist","aria-label":"配置方式",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":n==="deepseek",className:n==="deepseek"?"active":"",onClick:()=>y("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":n==="custom",className:n==="custom"?"active":"",onClick:()=>y("custom"),children:"自定义"})]}),n==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigModel")}),e.jsx(Pe,{options:[...Ys],value:E,onChange:B})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:Z?"text":"password",value:T,onChange:l=>w(l.target.value),placeholder:P?t("agentConfigApiKeyConfigured").replace("{{masked}}",c??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(Z?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>Q(l=>!l),children:Z?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:f,onChange:l=>{const _=l.target.value;if(A(_),le.current)return;_.toLowerCase().includes("anthropic")?C("anthropic-messages"):C("openai-completions")},placeholder:"https://api.example.com/v1",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Model ID"}),e.jsx("input",{type:"text",value:E,onChange:l=>B(l.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:Z?"text":"password",value:T,onChange:l=>w(l.target.value),placeholder:P?t("agentConfigApiKeyConfigured").replace("{{masked}}",c??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(Z?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>Q(l=>!l),children:Z?"隐藏":"显示"})]})]})]}),e.jsxs("details",{className:"mdocs-agent-advanced",open:o,onToggle:l=>L(l.target.open),children:[e.jsx("summary",{children:"高级选项"}),n==="custom"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Provider ID(选填)"}),e.jsx("input",{type:"text",value:S,onChange:l=>p(l.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Pe,{options:[...Js],value:M,onChange:l=>{le.current=!0,C(l)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigName")}),e.jsx("input",{type:"text",value:h,onChange:l=>I(l.target.value),placeholder:t("agentConfigNameDefault").replace("{{name}}",v||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:R,onChange:l=>b(Number(l.target.value)||128e3)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:t("agentConfigContextWindowDesc")})]})]}),r==="create"&&m.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>F(l.target.checked)}),e.jsx("span",{children:"保存后设为默认配置"})]}):null,W?e.jsx("p",{className:"mdocs-agent-config-error",children:W}):null,e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void pe(),disabled:q,children:t(q?"saving":"save")}),m.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:se,disabled:q,children:t("cancel")}):null]})]})]}):V?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:t("loading")})}):null]}),O?e.jsx(Ke,{title:"删除配置",message:`确定删除「${Le(O)}」?${O.isDefault&&m.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:t("cancel"),onConfirm:()=>void he(),onCancel:()=>ae(null)}):null]})}const et=/^[A-Za-z0-9_]+$/;function be(t){return et.test(t.trim())}function st(){const t=a.useRef(!0),[s,v]=a.useState([]),[u,m]=a.useState(!0),[z,r]=a.useState(null),[N,j]=a.useState(null),[k,n]=a.useState(!1),[y,h]=a.useState(""),[I,S]=a.useState(""),[p,f]=a.useState(""),[A,M]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function C(){m(!0),r(null);try{const d=await Ss();if(!t.current)return;v(d)}catch(d){if(!t.current)return;r(d instanceof Error?d.message:String(d))}finally{t.current&&m(!1)}}a.useEffect(()=>{C()},[]);function E(){n(!0),j(null),h(""),S(""),f(""),r(null)}function B(d){n(!1),j(d.id),h(d.name),S(d.description),f(d.body),r(null)}function R(){n(!1),j(null),h(""),S(""),f("")}async function b(){const d=y.trim();if(!be(d)){r("名称仅允许英文、数字、下划线");return}if(!p.trim()){r("正文不能为空");return}M(!0),r(null);try{if(k?await Cs({name:d,description:I,body:p}):N&&await Ds(N,{name:d,description:I,body:p}),!t.current)return;R(),await C()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}finally{t.current&&M(!1)}}async function T(d){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){r(null);try{if(await Is(d),!t.current)return;N===d&&R(),await C()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}}}const w=k||N!==null,P=!y.trim()||be(y);return e.jsxs("div",{className:"mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!u&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),w?null:e.jsx("button",{type:"button",className:"secondary",onClick:E,children:"新建"})]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc mdocs-agent-skills-lead",children:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),z?e.jsx("p",{className:"mdocs-agent-skills-error",children:z}):null,w?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:k?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:y,onChange:d=>h(d.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:P?void 0:"mdocs-agent-skills-input-invalid"}),P?e.jsx("span",{className:"mdocs-agent-skills-hint",children:"引用与索引键,保存后按此名称使用"}):e.jsx("span",{className:"mdocs-agent-skills-hint-bad",children:"仅允许 A–Z、a–z、0–9、_"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"简介(可选)"}),e.jsx("input",{type:"text",value:I,onChange:d=>S(d.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:p,onChange:d=>f(d.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void b(),disabled:A||!P||!y.trim()||!p.trim(),children:A?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:R,disabled:A,children:"取消"})]})]}):null,u?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!u&&s.length===0&&!w?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:E,children:"新建第一个"})]}):null,!u&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(d=>{const c=be(d.name),g=N===d.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(g?" mdocs-agent-skills-item-active":""),children:[e.jsxs("div",{className:"mdocs-agent-skills-item-main",children:[e.jsxs("div",{className:"mdocs-agent-skills-item-title-row",children:[e.jsx("code",{className:"mdocs-agent-skills-name",children:d.name}),c?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:d.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>B(d),disabled:w&&!g,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void T(d.id),disabled:w,children:"删除"})]})]},d.id)})}):null]})})]})}function Re(t,s){const v=localStorage.getItem(t);return v===null?s:v==="true"}function rt(t){const{t:s,lang:v,setLang:u}=te(),{onBack:m,onPublishDraft:z}=t,r=Ts(),[N,j]=a.useState(!1),k=a.useRef(!0);a.useEffect(()=>(k.current=!0,()=>{k.current=!1}),[]),a.useEffect(()=>{r||j(!1)},[r]);const[n,y]=a.useState(()=>Re("mdocs.autoPublish",!1)),[h,I]=a.useState(()=>Re("mdocs.autoEdit",!0)),[S,p]=a.useState(!1),[f,A]=a.useState("general");function M(i){A(i),r&&j(!1)}const C=s(f==="general"?"general":f==="bookmarks"?"bookmarkTitle":f==="myDocuments"?"myDocuments":f==="domainManagement"?"domainManagement":f==="memberTemplates"?"memberTemplates":f==="agentConfig"?"agentConfig":"saveAndPublish"),[E,B]=a.useState([]),[R,b]=a.useState(!0),[T,w]=a.useState(null),[P,d]=a.useState(!1),[c,g]=a.useState(!1),[D,F]=a.useState(!1),[V,H]=a.useState(!1),[q,G]=a.useState(null),[W,x]=a.useState(!1),[$,U]=a.useState(!1),[Z,Q]=a.useState(!1),[o,L]=a.useState(""),[O,ae]=a.useState(!1),[re,ie]=a.useState(!1),[le,X]=a.useState(0),[ee,oe]=a.useState([]),[me,de]=a.useState(!1),[se,ue]=a.useState(""),[he,pe]=a.useState([]),[ce,l]=a.useState(!1),[_,ve]=a.useState(""),[Oe,Ve]=a.useState([]),[Ue,ge]=a.useState(!1),[fe,ke]=a.useState(null),[xe,we]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(n))},[n]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(h))},[h]),a.useEffect(()=>{f==="savePublish"&&ye().then(i=>{k.current&&X(i.filter(K=>!K.published).length)})},[f]),a.useEffect(()=>{f==="bookmarks"&&We(),f==="myDocuments"&&De()},[f]),a.useEffect(()=>{Ce()},[]),a.useEffect(()=>{Fe().then(i=>{k.current&&Ve(i)}).catch(()=>{})},[]);const Se=new Map(Oe.map(i=>[i.domainId,i.domainName]));async function Ce(){try{b(!0);const i=await As();if(!k.current)return;B(i)}catch{}finally{k.current&&b(!1)}}async function We(){try{de(!0);const i=await Es();if(!k.current)return;oe(i)}catch{}finally{k.current&&de(!1)}}async function De(){try{l(!0);const i=await Ps();if(!k.current)return;pe(i)}catch{}finally{k.current&&l(!1)}}async function _e(i){try{await Ks(i),oe(K=>K.filter(ne=>ne.documentId!==i))}catch{}}function He(){if(E.some(K=>!K.revoked)){g(!0);return}Ie()}async function Ie(){try{d(!0);const i=await Os();w({token:i.token,name:i.name}),await Ce()}finally{d(!1)}}async function qe(){try{Q(!0);const i=await Fs();G(i.recoveryCode)}finally{Q(!1)}}async function Ge(i){i.preventDefault();const K=o.trim();if(!(K&&K.length<4))try{ae(!0),await Bs(K),L(""),ie(!0),setTimeout(()=>ie(!1),3e3)}finally{ae(!1)}}async function Ze(i){ke(i);try{const K=await $s(i),ne=new Map;K.forEach(Y=>{ne.set(Y.visitorId,Y.permission)}),we(ne)}catch{we(new Map)}ge(!0)}async function Ye(i){if(fe)try{const K=new Set(i.map(Y=>Y.visitorId)),ne=new Set(xe.keys());for(const Y of ne)K.has(Y)||await Vs(fe,Y);for(const Y of i)await Us(fe,Y.visitorId,Y.permission);await De()}finally{ge(!1),ke(null)}}const Te=ee.filter(i=>{if(!se.trim())return!0;const K=se.toLowerCase();return(i.displayName||i.relativePath||"").toLowerCase().includes(K)||(i.ownerVisitorName||"").toLowerCase().includes(K)||(i.domainId||"").toLowerCase().includes(K)}),Ae=he.filter(i=>{if(!_.trim())return!0;const K=_.toLowerCase();return(i.displayName||i.relativePath||"").toLowerCase().includes(K)||(i.domainId||"").toLowerCase().includes(K)});return e.jsxs("div",{className:"mdocs-layout"+(r?" mdocs-layout--reader mdocs-layout--settings":""),children:[r&&N?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>j(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(r?N?" mdocs-sidebar--drawer-open":" mdocs-sidebar--drawer":""),children:[e.jsxs("header",{className:"mdocs-sidebar-header",children:[e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:Ms,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),r?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>j(!1),"aria-label":s("collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Ls,{size:18})}):null]}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(f==="general"?" active":""),onClick:()=>M("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(f==="bookmarks"?" active":""),onClick:()=>M("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(f==="myDocuments"?" active":""),onClick:()=>M("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(f==="domainManagement"?" active":""),onClick:()=>M("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(f==="memberTemplates"?" active":""),onClick:()=>M("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(f==="agentConfig"?" active":""),onClick:()=>M("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(f==="savePublish"?" active":""),onClick:()=>M("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:m,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[r?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>j(!0),"aria-label":s("expandSidebar"),children:e.jsx(Rs,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:C})]}):null,zs(),f==="general"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("general")})}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsx("span",{className:"mdocs-settings-item-info",children:e.jsx("span",{className:"mdocs-settings-card-title",children:s("language")})}),e.jsxs("span",{className:"mdocs-settings-lang",children:[e.jsx("button",{type:"button",className:v==="en"?"active":"",onClick:()=>u("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:v==="zh"?"active":"",onClick:()=>u("zh"),children:"中"})]})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoEdit")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoEditDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(h?" active":""),role:"switch","aria-checked":h,onClick:()=>I(i=>!i),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliToken")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("cliTokenDesc")}),!R&&E.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:E.map(i=>e.jsxs("span",{style:{display:"block"},children:[i.name," — ",new Date(i.createdAt).toLocaleString()," ",i.revoked?`(${s("cliTokenRevoked")})`:`(${s("cliTokenActive")})`]},i.tokenId))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:He,disabled:P||R,children:P?"…":E.some(i=>!i.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),T&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--ok",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliTokenGenerated")}),e.jsx("span",{className:"mdocs-settings-secret-value",children:T.token})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(T.token),H(!1),F(!0),window.setTimeout(()=>F(!1),2e3)}catch{F(!1),H(!0),window.setTimeout(()=>H(!1),3e3)}})()},children:s(D?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>w(null),children:s("close")})]}),D&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),V&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:s("cliTokenCopyFailed")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"当 Token 丢失时,可用恢复码找回身份。生成后请立即保存,仅显示一次。"})]}),e.jsx("button",{type:"button",className:"secondary",onClick:qe,disabled:Z,children:Z?"…":"生成恢复码"})]}),q&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--warn",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 你的恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8},children:"请立即复制保存,关闭后不可再查看。"}),e.jsx("div",{className:"mdocs-settings-secret-code",children:q})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(q),U(!1),x(!0),window.setTimeout(()=>x(!1),2e3)}catch{x(!1),U(!0),window.setTimeout(()=>U(!1),3e3)}})()},children:W?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>G(null),children:s("close")})]}),W&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),$&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:"复制失败,请手动选中上方内容复制"})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-item",children:e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔐 登录密码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"设置密码后,可在其他浏览器或设备用「用户名+密码」登录。"})]})}),e.jsxs("form",{onSubmit:Ge,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:o,onChange:i=>L(i.target.value),minLength:0,style:{marginBottom:8}}),re&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:O,children:O?"设置中…":"保存密码"})]})]})]})]}):f==="bookmarks"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("bookmarkTitle")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:s("bookmarkSearch"),value:se,onChange:i=>ue(i.target.value)}),me?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Te.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(se?"bookmarkNoMatch":"bookmarkEmpty")}):e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("bookmarkColTitle")}),e.jsx("th",{children:s("bookmarkColDomain")}),e.jsx("th",{children:s("bookmarkColAuthor")}),e.jsx("th",{children:s("bookmarkColTime")}),e.jsx("th",{style:{textAlign:"right"}})]})}),e.jsx("tbody",{children:Te.map(i=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(i.documentId),children:i.displayName||i.relativePath||"Untitled"}),e.jsx("td",{children:i.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):Se.get(i.domainId||"")||i.domainId||"—"}),e.jsx("td",{children:i.ownerVisitorName||"—"}),e.jsx("td",{children:new Date(i.bookmarkedAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>_e(i.documentId),children:s("bookmarkRemove")})})]},i.documentId))})]})})]})]}):f==="myDocuments"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("myDocuments")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:"搜索文章…",value:_,onChange:i=>ve(i.target.value)}),ce?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Ae.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(_?"myDocumentsNoMatch":"myDocumentsEmpty")}):e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("myDocumentsColTitle")}),e.jsx("th",{children:s("myDocumentsColDomain")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{colSpan:2})]})}),e.jsx("tbody",{children:Ae.map(i=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(i.documentId),children:i.displayName||i.relativePath||"Untitled"}),e.jsx("td",{children:Se.get(i.domainId||"")||i.domainId||"—"}),e.jsx("td",{children:new Date(i.updatedAt).toLocaleDateString()}),e.jsx("td",{children:new Date(i.createdAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Ze(i.documentId),children:s("docInfoInviteMember")})}),e.jsx("td",{style:{textAlign:"right",paddingLeft:0},children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(i.documentId),children:s("bookmarkOpen")})})]},i.documentId))})]})})]})]}):f==="domainManagement"?e.jsx(Gs,{}):f==="memberTemplates"?e.jsx(Zs,{}):f==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Xs,{}),e.jsx(st,{})]}):e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:s("saveAndPublish")}),e.jsx("button",{type:"button",className:"secondary",onClick:m,children:s("backToDocs")})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoSave")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoSaveAlwaysOnDesc")})]}),e.jsx("span",{className:"mdocs-toggle active",role:"switch","aria-checked":"true","aria-disabled":"true",style:{opacity:.6,cursor:"not-allowed"},children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoPublish")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoPublishDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(n?" active":""),role:"switch","aria-checked":n,onClick:()=>y(i=>!i),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),le>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>p(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",le,")"]}),e.jsx("span",{className:"mdocs-settings-draft-arrow","aria-hidden":"true",children:"›"})]}):e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:s("noDrafts")})})]})]}),S&&e.jsx(Hs,{onPublish:z,onClose:()=>p(!1),onCountChange:X,onRecover:t.onRecoverDraft})]}),c&&e.jsx(Ke,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:P,onConfirm:()=>{g(!1),Ie()},onCancel:()=>g(!1)}),e.jsx($e,{open:Ue,title:s("docInfoInviteMember"),initialSelectedIds:[...xe.keys()],initialPermissions:xe,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>ge(!1),onConfirm:i=>{Ye(i)}})]})}export{rt as SettingsPage};
1
+ import{r as a,j as e}from"./react-vendor-BuABiQkA.js";import{b as te,q as Je,s as Qe,D as Xe,l as Ne,t as es,v as ss,w as J,x as ye,y as ts,z as as,A as ns,a as is,d as Ee,B as ze,C as Fe,E as ls,G as cs,H as rs,I as os,J as ds,K as Be,L as je,O as ms,Q as us,R as hs,T as ps,U as gs,f as fs,V as xs,W as js,X as bs,Y as Ns,Z as ys,_ as Ke,$ as vs,a0 as ks,a1 as ws,a2 as Ss,a3 as Cs,a4 as Ds,a5 as Is,a6 as Ts,a7 as As,a8 as Es,a9 as Ps,aa as Ms,ab as Ls,P as Rs,ac as zs,ad as Fs,ae as Bs,r as Ks,k as $s,af as Os,n as Vs,o as Us}from"./index-BkKvQv2F.js";import{V as $e,a as Ws,M as Pe}from"./VisitorPickerModal-BPyEWlQo.js";import"./ui-BQStT3dY.js";import"./motion-DX3HNq_4.js";import"./diagram-CT58wBdU.js";function _s({draft:t,onClose:s,onSuccess:v}){const{t:u,lang:m}=te(),[z,r]=a.useState([]),[N,j]=a.useState(t.domainId??""),[k,n]=a.useState([]),[y,h]=a.useState(""),[I,S]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[p,f]=a.useState(!1),[A,M]=a.useState(null),C=a.useRef(null),E=a.useRef(!0);a.useEffect(()=>(E.current=!0,()=>{E.current=!1}),[]),a.useEffect(()=>{Je().then(b=>{E.current&&r(b)})},[]),a.useEffect(()=>{N&&(n([]),h(""),Qe(N).then(b=>{E.current&&n(b)}).catch(()=>{E.current&&n([])}))},[N]),a.useEffect(()=>{const b=window.setTimeout(()=>{var T;return(T=C.current)==null?void 0:T.focus()},0);return()=>window.clearTimeout(b)},[]),a.useEffect(()=>{const b=T=>{T.key==="Escape"&&s()};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[s]);function B(b,T){for(const w of b){if(w.type==="folder"&&w.path===T)return w.documentId;if(w.type==="folder"){const P=B(w.children,T);if(P)return P}}return null}async function R(b){b.preventDefault(),f(!0),M(null);const T=I.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),w=T.endsWith(".md")?T:T+".md",P=w.replace(/\.md$/i,"");try{const d=y?`${y}/${w}`:w,c=y?B(k,y)??void 0:void 0;await ss({fileName:w,displayName:P,content:t.content,domainId:N,parentId:c}),v()}catch(d){M(J(u,d))}finally{f(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:b=>{b.target===b.currentTarget&&!p&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:u("recoverDraft")}),e.jsx("p",{className:"muted",children:u("recoverDraftDesc",{name:t.displayName||u("unknownTitle")})}),e.jsxs("form",{onSubmit:R,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[u("domainLabel"),z.length>0&&e.jsx(Xe,{domains:z,value:N,onChange:j,onDomainsChange:r,ariaLabel:u("domainLabel"),localizeName:b=>Ne(b,m,u)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[u("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(es,{nodes:k,activeDocumentId:null,selectedParentPath:y,onOpen:()=>{},onOpenFolder:b=>h(b),onContextMenu:()=>{},onDeselect:()=>h("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[u("fileNameLabel"),e.jsx("input",{ref:C,value:I,onChange:b=>S(b.target.value),placeholder:"recovered.md",maxLength:200,disabled:p})]}),A&&e.jsx("div",{className:"mdocs-dialog-error",children:A}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!p&&s(),disabled:p,children:u("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:p,children:u(p?"creating":"create")})]})]})]})})}function Hs({onPublish:t,onClose:s,onCountChange:v,onRecover:u}){const{t:m}=te(),[z,r]=a.useState([]),[N,j]=a.useState(new Set),[k,n]=a.useState(!1),[y,h]=a.useState(null),[I,S]=a.useState(null),[p,f]=a.useState(null),A=a.useRef(null),M=a.useRef(!0);a.useEffect(()=>(M.current=!0,ye().then(c=>{if(!M.current)return;const g=c.filter(D=>!D.published);r(g),v==null||v(g.length)}),()=>{M.current=!1,A.current&&(clearTimeout(A.current),A.current=null)}),[]),a.useEffect(()=>{const c=g=>{g.key==="Escape"&&s()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s]);const C=a.useCallback((c,g)=>{f({message:c,type:g}),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>f(null),3e3)},[]);async function E(c){await as(c),j(g=>new Set(g).add(c));try{await t(c),r(g=>{const D=g.filter(F=>F.documentId!==c);return v==null||v(D.length),D}),C(m("published"),"success")}catch(g){g instanceof ns||C(m("publishFailed"),"error");const D=await is(c);D&&r(F=>F.map(V=>V.documentId===c?D:V))}finally{j(g=>{const D=new Set(g);return D.delete(c),D})}}async function B(c){h(null),await Ee(c),r(g=>{const D=g.filter(F=>F.documentId!==c);return v==null||v(D.length),D}),C(m("draftDeleted"),"success")}function R(c){const g=z.find(D=>D.documentId===c);g&&S(g)}function b(c){S(null),Ee(c),r(g=>{const D=g.filter(F=>F.documentId!==c);return v==null||v(D.length),D}),u==null||u(z.find(g=>g.documentId===c)),C(m("published"),"success")}async function T(){n(!0);let c=0,g=0;for(const V of z)try{await t(V.documentId),c++}catch{g++}const F=(await ye()).filter(V=>!V.published);r(F),v==null||v(F.length),g===0?C(m("publishAll"),"success"):C(`${c} published, ${g} failed`,"error"),n(!1)}const w=c=>new Date(c).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),P=c=>ts(m,c,c.publishError??"UNKNOWN"),d=z;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-drawer-overlay",onClick:s}),e.jsxs("div",{className:"mdocs-drawer",role:"dialog","aria-modal":"true",children:[e.jsxs("header",{className:"mdocs-drawer-header",children:[e.jsxs("div",{className:"mdocs-drawer-header-text",children:[e.jsxs("h2",{className:"mdocs-drawer-title",children:[m("unpublishedDrafts"),d.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:d.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:m("draftCount",{count:String(d.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":m("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:d.length===0?e.jsxs("div",{className:"mdocs-drawer-empty",children:[e.jsx("div",{className:"mdocs-drawer-empty-icon","aria-hidden":"true",children:"✓"}),e.jsx("p",{className:"mdocs-drawer-empty-text",children:m("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:d.map(c=>{const g=!!c.publishError;return e.jsxs("div",{className:g?"mdocs-drawer-item mdocs-drawer-item-failed":"mdocs-drawer-item",children:[e.jsx("div",{className:"mdocs-drawer-item-icon","aria-hidden":"true",children:"📄"}),e.jsxs("div",{className:"mdocs-drawer-item-info",children:[e.jsx("span",{className:"mdocs-drawer-item-name",children:c.displayName||m("unknownTitle")}),g?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[w(c.publishErrorAt)," · ",P(c)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[w(c.updatedAt)," · ",m("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[g?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:k,onClick:()=>R(c.documentId),children:m("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:N.has(c.documentId)||k,onClick:()=>void E(c.documentId),children:N.has(c.documentId)?m("publishing"):m("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:k,onClick:()=>h(c.documentId),children:m("delete")})]})]},c.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:m("close")}),e.jsx("button",{type:"button",className:"primary",disabled:d.length===0||k,onClick:()=>void T(),children:k?m("publishing"):`${m("publishAll")} (${d.length})`})]}),p&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+p.type,role:"status",children:p.message})]}),y&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:c=>{c.target===c.currentTarget&&h(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:m("delete")}),e.jsx("p",{className:"muted",children:m("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>h(null),children:m("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void B(y),children:m("delete")})]})]})}),I&&e.jsx(_s,{draft:I,onClose:()=>S(null),onSuccess:()=>b(I.documentId)})]})}function qs(){const{t,lang:s}=te(),v=ze(),u=a.useRef(!1),[m,z]=a.useState([]),[r,N]=a.useState(!1),[j,k]=a.useState(""),[n,y]=a.useState("restricted"),[h,I]=a.useState(!1),[S,p]=a.useState(null),[f,A]=a.useState(null),[M,C]=a.useState(""),[E,B]=a.useState(""),[R,b]=a.useState("all"),[T,w]=a.useState(null);a.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const P=a.useCallback(async()=>{N(!0),p(null);try{const x=await Fe();if(!u.current)return;z(x)}catch(x){if(!u.current)return;p(J(t,x))}finally{u.current&&N(!1)}},[t]);a.useEffect(()=>{P()},[P]);async function d(x){if(x.preventDefault(),!j.trim()){p(t("domainNameRequired"));return}I(!0),p(null);try{if(await ds({domainName:j.trim(),permission:n}),!u.current)return;k(""),y("restricted"),await P()}catch($){if(!u.current)return;p(J(t,$))}finally{u.current&&I(!1)}}async function c(x){if(M.trim()){p(null);try{if(await os(x,M.trim()),!u.current)return;A(null),w(null),await P()}catch($){if(!u.current)return;p(J(t,$))}}}function g(x){A(x.domainId),C(x.domainName),w(null)}function D(){A(null),w(null)}async function F(x,$){p(null);try{if(await rs(x,$),!u.current)return;w(null),await P()}catch(U){if(!u.current)return;p(J(t,U))}}async function V(x){if(window.confirm(t("deleteDomainConfirmDetail",{name:x.domainName,count:String(x.docCount)}))){p(null);try{if(await cs(x.domainId),!u.current)return;await P()}catch($){if(!u.current)return;p(J(t,$))}}}const H=a.useCallback(x=>ls(x,t),[t]),q=a.useCallback(x=>Ne(x.domainName,s,t),[s,t]),G=a.useMemo(()=>{const x=E.trim().toLowerCase();return m.filter($=>R!=="all"&&$.permission!==R?!1:x?Ne($.domainName,s,t).toLowerCase().includes(x)||$.domainName.toLowerCase().includes(x):!0)},[m,E,R,s,t]),W=a.useCallback((x,$)=>{const U=H(x.permission);return $?`${U} ${t("domainTypeBuiltinSuffix")}`:U},[H,t]);return{domains:m,loadingDomains:r,domainError:S,newDomainName:j,setNewDomainName:k,newDomainPermission:n,setNewDomainPermission:y,creating:h,handleCreateDomain:d,renamingId:f,setRenamingId:A,renameDraft:M,setRenameDraft:C,startRename:g,cancelRename:D,handleRename:c,changeTypeForId:T,setChangeTypeForId:w,handlePermissionChange:F,handleDelete:V,domainSearch:E,setDomainSearch:B,domainFilter:R,setDomainFilter:b,filteredDomains:G,visitorId:v,plabel:H,localizeDomain:q,domainTypeLabel:W}}function Gs(){const{t}=te(),s=qs(),[v,u]=a.useState([]),[m,z]=a.useState(null),[r,N]=a.useState(null),j=a.useCallback(async()=>{try{const n=await Be();u(n)}catch{u([])}},[]);a.useEffect(()=>{j()},[j]);async function k(n){z(null);try{const y=await gs(n.domainId);N({domainId:n.domainId,creatorVisitorId:n.creatorVisitorId,initialIds:y.map(h=>h.visitorId),memberRows:y})}catch(y){z({kind:"err",text:J(t,y)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:t("domainManagement")})}),e.jsx("p",{className:"mdocs-domain-mgmt-restricted-hint",children:t("domainMgmtRestrictedMemberHint")}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-create",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("createDomain")}),e.jsxs("form",{onSubmit:s.handleCreateDomain,className:"mdocs-domain-mgmt-create-form",children:[e.jsxs("label",{className:"mdocs-domain-mgmt-field",children:[e.jsx("span",{className:"mdocs-domain-mgmt-label",children:t("domainName")}),e.jsx("input",{value:s.newDomainName,onChange:n=>s.setNewDomainName(n.target.value),placeholder:t("domainName"),maxLength:100,disabled:s.creating,className:"mdocs-domain-name-input"})]}),e.jsxs("fieldset",{className:"mdocs-domain-mgmt-fieldset",children:[e.jsx("legend",{className:"mdocs-domain-mgmt-label",children:t("domainPermission")}),e.jsx("div",{className:"mdocs-domain-mgmt-type-radios",children:je.map(n=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===n,onChange:()=>s.setNewDomainPermission(n),disabled:s.creating}),e.jsx("span",{children:s.plabel(n)})]},n))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?t("creating"):t("create")})]})]}),m&&e.jsx("div",{className:"mdocs-settings-card",style:{color:m.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:m.text})}),s.domainError&&e.jsx("div",{className:"mdocs-settings-card mdocs-domain-error",children:e.jsx("span",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)"},children:s.domainError})}),e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-toolbar",children:[e.jsx("input",{type:"search",value:s.domainSearch,onChange:n=>s.setDomainSearch(n.target.value),placeholder:t("domainSearchPlaceholder"),className:"mdocs-domain-mgmt-search","aria-label":t("domainSearchPlaceholder")}),e.jsx("div",{className:"mdocs-domain-mgmt-filters",role:"group","aria-label":t("domainPermission"),children:["all",...je].map(n=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===n?" active":""),"aria-pressed":s.domainFilter===n,onClick:()=>s.setDomainFilter(n),children:n==="all"?t("domainFilterAll"):s.plabel(n)},n))})]}),s.loadingDomains?e.jsx("div",{className:"mdocs-settings-card",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")})}):s.domains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("noDomains")})}):s.filteredDomains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("domainNoMatch")})}):e.jsx("div",{className:"mdocs-settings-card mdocs-domain-table-wrap",children:e.jsxs("table",{className:"mdocs-domain-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:t("domainColName")}),e.jsx("th",{scope:"col",children:t("domainColType")}),e.jsx("th",{scope:"col",className:"mdocs-domain-table-num",children:t("domainColDocCount")}),e.jsx("th",{scope:"col",children:t("domainColActions")})]})}),e.jsx("tbody",{children:s.filteredDomains.map(n=>{const y=ms(n,s.visitorId),h=us(n.domainId),I=hs(n),S=I?t("domainTooltipTypeLocked",{count:String(n.docCount)}):void 0;return e.jsxs("tr",{className:h?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===n.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:p=>s.setRenameDraft(p.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(n.domainId),children:t("save")}),e.jsx("button",{type:"button",onClick:s.cancelRename,children:t("cancel")})]}):e.jsxs("div",{className:"mdocs-domain-table-name-cell",children:[e.jsx("span",{className:"mdocs-domain-table-name",children:s.localizeDomain(n)}),h&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!y&&!h&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsxs("span",{className:"mdocs-domain-table-type",title:S,children:[e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":n.permission,children:s.domainTypeLabel(n,h)}),I&&!h&&e.jsx("span",{className:"mdocs-domain-type-lock","aria-hidden":"true",children:"🔒"})]})}),e.jsx("td",{className:"mdocs-domain-table-num",children:n.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[h&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!h&&!y&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!h&&y&&s.changeTypeForId===n.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",children:[e.jsx("div",{className:"mdocs-domain-permission-select",children:je.map(p=>e.jsx("button",{type:"button",className:n.permission===p?"active":"",onClick:()=>void s.handlePermissionChange(n.domainId,p),children:s.plabel(p)},p))}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>s.setChangeTypeForId(null),children:t("cancel")})]}),!h&&y&&s.renamingId!==n.domainId&&s.changeTypeForId!==n.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[e.jsx("button",{type:"button",className:"secondary",title:I?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(n)},disabled:I,children:t("rename")}),e.jsx("button",{type:"button",className:"secondary",title:I?S:void 0,onClick:()=>{s.setRenamingId(null),s.setChangeTypeForId(n.domainId)},disabled:I,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"secondary",title:I?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(n),disabled:I,children:t("deleteDomain")}),n.permission==="restricted"&&!h&&e.jsx("button",{type:"button",className:"secondary",onClick:()=>void k(n),children:t("domainMembersManageButton")})]})]})]},n.domainId)})})]})})]}),e.jsx($e,{open:r!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(r==null?void 0:r.initialIds)??[],lockedIds:r?[r.creatorVisitorId]:[],seedMembers:r==null?void 0:r.memberRows,templates:v,onClose:()=>N(null),onConfirm:async n=>{r&&(await ps(r.domainId,n),z({kind:"ok",text:t("domainMembersSaved",{count:String(n.length)})}))}})]})}function Me(t){return t.length<=6?t:`${t.slice(0,6)}…`}function Zs(){const{t}=te(),s=a.useRef(!0),[v,u]=a.useState([]),[m,z]=a.useState(!0),[r,N]=a.useState(null),[j,k]=a.useState(1),[n,y]=a.useState(null),[h,I]=a.useState(""),[S,p]=a.useState([]),[f,A]=a.useState(!1),[M,C]=a.useState(null),[E,B]=a.useState(!1),R=ze(),[b,T]=a.useState([]),[w,P]=a.useState("idle"),[d,c]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{P("loading"),fs().then(o=>{s.current&&(T(o),P("ok"))}).catch(()=>{s.current&&P("err")})},[]);const g=a.useMemo(()=>{const o=new Map;for(const L of b)o.set(L.visitorId,L.visitorName);return o},[b]),D=a.useCallback(async()=>{z(!0),C(null);try{const o=await Be();s.current&&u(o)}catch(o){s.current&&C(J(t,o))}finally{s.current&&z(!1)}},[t]);a.useEffect(()=>{D()},[D]);const F=a.useMemo(()=>S.map(o=>{const L=b.find(O=>O.visitorId===o);return{visitorId:o,name:L?L.visitorName:t("visitorPickerUnknownVisitor"),muted:!L}}),[S,b,t]);function V(o){p(L=>L.includes(o)?L.filter(O=>O!==o):[...L,o])}const H=j===1?h.trim().length>0:j===2?S.length>0:!0;function q(){if(!(j>=3)){if(!H){B(!0);return}B(!1),k(j+1),c("")}}function G(){j<=1||(B(!1),k(j-1))}function W(){N(null),y(null),I(""),p(R?[R]:[]),C(null),k(1),c(""),B(!1)}function x(o){N(null),y(o.id),I(o.displayName);const L=R&&!o.visitorIds.includes(R)?[...o.visitorIds,R]:[...o.visitorIds];p(L),C(null),k(1),c(""),B(!1)}async function $(){if(!(!h.trim()||S.length===0)){A(!0),C(null);try{if(n===null?await xs({displayName:h.trim(),visitorIds:S}):await js(n,{displayName:h.trim(),visitorIds:S}),!s.current)return;W(),await D()}catch(o){if(!s.current)return;C(J(t,o))}finally{s.current&&A(!1)}}}async function U(o){A(!0),C(null);try{if(await bs(o),!s.current)return;N(null),n===o&&W(),await D()}catch(L){if(!s.current)return;C(J(t,L))}finally{s.current&&A(!1)}}const Z=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],Q=`${(j-1)/2*100}%`;return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:t(n!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),n!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:W,style:{fontSize:12},children:t("memberTemplateCancelEdit")})]}),e.jsxs("div",{className:"mdocs-wizard-progress",children:[e.jsx("div",{className:"mdocs-wizard-progress-track",children:e.jsx("div",{className:"mdocs-wizard-progress-fill",style:{width:Q}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:Z.map(o=>{const L=j===o.key,O=j>o.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${L?" current":""}${O?" done":""}`,children:O?"✓":o.key}),e.jsx("span",{className:`mdocs-wizard-step-label${L?" current":""}${O?" done":""}`,children:o.label})]},o.key)})})]}),M&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:M}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[j===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:h,onChange:o=>I(o.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:f,autoFocus:!0,"aria-invalid":E&&!h.trim()}),E&&!h.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),j===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Ws,{visitors:b,loadState:w,searchFilter:d,onSearchChange:c,selectedIds:new Set(S),onToggle:V,selectedRows:F,myVisitorId:R}),e.jsx("p",{className:`mdocs-wizard-hint${E&&S.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),j===3&&e.jsx("div",{className:"mdocs-wizard-step-content",children:e.jsxs("div",{className:"mdocs-wizard-preview-card",children:[e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:h})]}),e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateIdsLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:t("memberTemplateSelectedSummary",{count:String(S.length)})})]}),S.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[S.slice(0,15).map(o=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:Me(o)},o)),S.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",S.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:G,children:["← ",t("memberTemplateWizardBack")]}),j<3?e.jsxs("button",{type:"button",className:"primary",onClick:q,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void $(),children:t(f?"saving":n===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),m?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):v.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),n===null&&e.jsx("button",{type:"button",className:"primary",onClick:W,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:v.map(o=>e.jsx("li",{className:"mdocs-member-template-row",children:r===o.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:t("memberTemplateConfirmDeleteDesc",{name:o.displayName})}),e.jsxs("div",{className:"mdocs-member-template-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",style:{color:"var(--mdocs-danger)"},onClick:()=>void U(o.id),children:t(f?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>N(null),children:t("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:o.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateCount",{count:String(o.visitorIds.length)})}),o.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:o.visitorIds.map(L=>e.jsx("span",{className:"mdocs-member-template-tag",children:g.get(L)??Me(L)},L))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>x(o),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>N(o.id),children:t("memberTemplateDelete")})]})]})},o.id))})]})]})]})}const Ys=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}],Js=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function Qs(t,s,v){return t==="deepseek"?"Deepseek":s||v}function Le(t){return`${Qs(t.kind,t.providerId,t.name)} · ${t.modelId} · ${t.name}`}function Xs(){const{t}=te(),s=a.useRef(!0),[v,u]=a.useState(""),[m,z]=a.useState([]),[r,N]=a.useState(null),[j,k]=a.useState(null),[n,y]=a.useState("deepseek"),[h,I]=a.useState(""),[S,p]=a.useState(""),[f,A]=a.useState(""),[M,C]=a.useState("openai-completions"),[E,B]=a.useState("deepseek-v4-flash"),[R,b]=a.useState(128e3),[T,w]=a.useState(""),[P,d]=a.useState(!1),[c,g]=a.useState(null),[D,F]=a.useState(!1),[V,H]=a.useState(!0),[q,G]=a.useState(!1),[W,x]=a.useState(null),[$,U]=a.useState(!1),[Z,Q]=a.useState(!1),[o,L]=a.useState(!1),[O,ae]=a.useState(null),[re,ie]=a.useState(null),le=a.useRef(!1);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const X=a.useCallback(async()=>{const l=await Ns();if(s.current)return z(l),l},[]);function ee(){k(null),y("deepseek"),I(""),p(""),A(""),C("openai-completions"),B("deepseek-v4-flash"),b(128e3),w(""),d(!1),g(null),F(!1),Q(!1),L(!1),x(null),U(!1)}function oe(l){k(l.id),y(l.kind),I(l.name),p(l.providerId??""),A(l.baseUrl),C(l.apiType),B(l.modelId),b(l.contextWindow||128e3),d(l.hasApiKey),g(l.apiKeyMasked),w(""),F(l.isDefault)}a.useEffect(()=>{(async()=>{try{const l=await ys();if(!s.current)return;u(l.visitorName);const _=await X();if(!s.current||!_)return;_.length===0&&(ee(),N("create"))}catch(l){if(!s.current)return;x(l instanceof Error?l.message:String(l)),N("create")}finally{s.current&&H(!1)}})()},[X]);function me(){ee(),N("create")}function de(l){oe(l),N("edit"),U(!1),x(null)}function se(){ee(),N(null)}async function ue(l){if(!(l.isDefault||re)){ie(l.id),x(null);try{await vs(l.id),await X()}catch(_){if(!s.current)return;x(_ instanceof Error?_.message:String(_))}finally{s.current&&ie(null)}}}async function he(){if(O){G(!0),x(null);try{await ws(O.id);const l=await X();if(!s.current)return;r==="edit"&&j===O.id&&se(),((l==null?void 0:l.length)??0)===0&&(ee(),N("create"))}catch(l){if(!s.current)return;x(l instanceof Error?l.message:String(l))}finally{s.current&&(G(!1),ae(null))}}}async function pe(){G(!0),x(null),U(!1);try{const l=n==="custom"?{...r==="edit"&&j?{id:j}:{},...r==="create"&&D?{isDefault:!0}:{},kind:n,baseUrl:f,modelId:E,providerId:S.trim()||void 0,apiType:M,name:h,contextWindow:R,...T.trim()?{apiKey:T.trim()}:{}}:{...r==="edit"&&j?{id:j}:{},...r==="create"&&D?{isDefault:!0}:{},kind:n,modelId:E,name:h,contextWindow:R,...T.trim()?{apiKey:T.trim()}:{}};if(await ks(l),!s.current)return;await X(),U(!0),N(null),ee()}catch(l){if(!s.current)return;x(l instanceof Error?l.message:String(l))}finally{s.current&&G(!1)}}const ce=r!==null;return e.jsxs("div",{className:"mdocs-agent-config-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:t("agentConfig")}),!V&&!ce?e.jsx("button",{type:"button",className:"secondary",onClick:me,children:"添加配置"}):null]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!V&&m.length>0&&!ce?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:"选择默认配置后,智能助手与帮写将使用该模型。"}),e.jsx("ul",{className:"mdocs-agent-config-list",children:m.map(l=>e.jsxs("li",{className:"mdocs-agent-config-item",children:[e.jsxs("label",{className:"mdocs-agent-config-item-default",children:[e.jsx("input",{type:"radio",name:"agent-default-config",checked:l.isDefault,disabled:re!==null,onChange:()=>void ue(l)}),e.jsx("span",{children:l.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:Le(l)}),l.kind==="custom"?e.jsx("span",{className:"mdocs-agent-badge",children:"自定义"}):null,e.jsx("p",{className:"mdocs-agent-config-item-meta",children:l.hasApiKey?`Key ${l.apiKeyMasked??"已配置"}`:"未配置 Key"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>de(l),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>ae(l),children:"删除"})]})]},l.id))}),$?e.jsx("p",{className:"mdocs-agent-config-ok",children:t("saved")}):null,W?e.jsx("p",{className:"mdocs-agent-config-error",children:W}):null]}):null,ce?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:r==="create"?"新建模型配置":"编辑模型配置"}),e.jsxs("div",{className:"mdocs-agent-form",children:[e.jsxs("div",{className:"mdocs-agent-kind-tabs",role:"tablist","aria-label":"配置方式",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":n==="deepseek",className:n==="deepseek"?"active":"",onClick:()=>y("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":n==="custom",className:n==="custom"?"active":"",onClick:()=>y("custom"),children:"自定义"})]}),n==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigModel")}),e.jsx(Pe,{options:[...Ys],value:E,onChange:B})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:Z?"text":"password",value:T,onChange:l=>w(l.target.value),placeholder:P?t("agentConfigApiKeyConfigured").replace("{{masked}}",c??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(Z?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>Q(l=>!l),children:Z?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:f,onChange:l=>{const _=l.target.value;if(A(_),le.current)return;_.toLowerCase().includes("anthropic")?C("anthropic-messages"):C("openai-completions")},placeholder:"https://api.example.com/v1",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Model ID"}),e.jsx("input",{type:"text",value:E,onChange:l=>B(l.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:Z?"text":"password",value:T,onChange:l=>w(l.target.value),placeholder:P?t("agentConfigApiKeyConfigured").replace("{{masked}}",c??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(Z?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>Q(l=>!l),children:Z?"隐藏":"显示"})]})]})]}),e.jsxs("details",{className:"mdocs-agent-advanced",open:o,onToggle:l=>L(l.target.open),children:[e.jsx("summary",{children:"高级选项"}),n==="custom"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Provider ID(选填)"}),e.jsx("input",{type:"text",value:S,onChange:l=>p(l.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Pe,{options:[...Js],value:M,onChange:l=>{le.current=!0,C(l)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigName")}),e.jsx("input",{type:"text",value:h,onChange:l=>I(l.target.value),placeholder:t("agentConfigNameDefault").replace("{{name}}",v||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:R,onChange:l=>b(Number(l.target.value)||128e3)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:t("agentConfigContextWindowDesc")})]})]}),r==="create"&&m.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>F(l.target.checked)}),e.jsx("span",{children:"保存后设为默认配置"})]}):null,W?e.jsx("p",{className:"mdocs-agent-config-error",children:W}):null,e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void pe(),disabled:q,children:t(q?"saving":"save")}),m.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:se,disabled:q,children:t("cancel")}):null]})]})]}):V?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:t("loading")})}):null]}),O?e.jsx(Ke,{title:"删除配置",message:`确定删除「${Le(O)}」?${O.isDefault&&m.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:t("cancel"),onConfirm:()=>void he(),onCancel:()=>ae(null)}):null]})}const et=/^[A-Za-z0-9_]+$/;function be(t){return et.test(t.trim())}function st(){const t=a.useRef(!0),[s,v]=a.useState([]),[u,m]=a.useState(!0),[z,r]=a.useState(null),[N,j]=a.useState(null),[k,n]=a.useState(!1),[y,h]=a.useState(""),[I,S]=a.useState(""),[p,f]=a.useState(""),[A,M]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function C(){m(!0),r(null);try{const d=await Ss();if(!t.current)return;v(d)}catch(d){if(!t.current)return;r(d instanceof Error?d.message:String(d))}finally{t.current&&m(!1)}}a.useEffect(()=>{C()},[]);function E(){n(!0),j(null),h(""),S(""),f(""),r(null)}function B(d){n(!1),j(d.id),h(d.name),S(d.description),f(d.body),r(null)}function R(){n(!1),j(null),h(""),S(""),f("")}async function b(){const d=y.trim();if(!be(d)){r("名称仅允许英文、数字、下划线");return}if(!p.trim()){r("正文不能为空");return}M(!0),r(null);try{if(k?await Cs({name:d,description:I,body:p}):N&&await Ds(N,{name:d,description:I,body:p}),!t.current)return;R(),await C()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}finally{t.current&&M(!1)}}async function T(d){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){r(null);try{if(await Is(d),!t.current)return;N===d&&R(),await C()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}}}const w=k||N!==null,P=!y.trim()||be(y);return e.jsxs("div",{className:"mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!u&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),w?null:e.jsx("button",{type:"button",className:"secondary",onClick:E,children:"新建"})]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc mdocs-agent-skills-lead",children:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),z?e.jsx("p",{className:"mdocs-agent-skills-error",children:z}):null,w?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:k?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:y,onChange:d=>h(d.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:P?void 0:"mdocs-agent-skills-input-invalid"}),P?e.jsx("span",{className:"mdocs-agent-skills-hint",children:"引用与索引键,保存后按此名称使用"}):e.jsx("span",{className:"mdocs-agent-skills-hint-bad",children:"仅允许 A–Z、a–z、0–9、_"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"简介(可选)"}),e.jsx("input",{type:"text",value:I,onChange:d=>S(d.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:p,onChange:d=>f(d.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void b(),disabled:A||!P||!y.trim()||!p.trim(),children:A?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:R,disabled:A,children:"取消"})]})]}):null,u?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!u&&s.length===0&&!w?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:E,children:"新建第一个"})]}):null,!u&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(d=>{const c=be(d.name),g=N===d.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(g?" mdocs-agent-skills-item-active":""),children:[e.jsxs("div",{className:"mdocs-agent-skills-item-main",children:[e.jsxs("div",{className:"mdocs-agent-skills-item-title-row",children:[e.jsx("code",{className:"mdocs-agent-skills-name",children:d.name}),c?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:d.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>B(d),disabled:w&&!g,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void T(d.id),disabled:w,children:"删除"})]})]},d.id)})}):null]})})]})}function Re(t,s){const v=localStorage.getItem(t);return v===null?s:v==="true"}function rt(t){const{t:s,lang:v,setLang:u}=te(),{onBack:m,onPublishDraft:z}=t,r=Ts(),[N,j]=a.useState(!1),k=a.useRef(!0);a.useEffect(()=>(k.current=!0,()=>{k.current=!1}),[]),a.useEffect(()=>{r||j(!1)},[r]);const[n,y]=a.useState(()=>Re("mdocs.autoPublish",!1)),[h,I]=a.useState(()=>Re("mdocs.autoEdit",!0)),[S,p]=a.useState(!1),[f,A]=a.useState("general");function M(i){A(i),r&&j(!1)}const C=s(f==="general"?"general":f==="bookmarks"?"bookmarkTitle":f==="myDocuments"?"myDocuments":f==="domainManagement"?"domainManagement":f==="memberTemplates"?"memberTemplates":f==="agentConfig"?"agentConfig":"saveAndPublish"),[E,B]=a.useState([]),[R,b]=a.useState(!0),[T,w]=a.useState(null),[P,d]=a.useState(!1),[c,g]=a.useState(!1),[D,F]=a.useState(!1),[V,H]=a.useState(!1),[q,G]=a.useState(null),[W,x]=a.useState(!1),[$,U]=a.useState(!1),[Z,Q]=a.useState(!1),[o,L]=a.useState(""),[O,ae]=a.useState(!1),[re,ie]=a.useState(!1),[le,X]=a.useState(0),[ee,oe]=a.useState([]),[me,de]=a.useState(!1),[se,ue]=a.useState(""),[he,pe]=a.useState([]),[ce,l]=a.useState(!1),[_,ve]=a.useState(""),[Oe,Ve]=a.useState([]),[Ue,ge]=a.useState(!1),[fe,ke]=a.useState(null),[xe,we]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(n))},[n]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(h))},[h]),a.useEffect(()=>{f==="savePublish"&&ye().then(i=>{k.current&&X(i.filter(K=>!K.published).length)})},[f]),a.useEffect(()=>{f==="bookmarks"&&We(),f==="myDocuments"&&De()},[f]),a.useEffect(()=>{Ce()},[]),a.useEffect(()=>{Fe().then(i=>{k.current&&Ve(i)}).catch(()=>{})},[]);const Se=new Map(Oe.map(i=>[i.domainId,i.domainName]));async function Ce(){try{b(!0);const i=await As();if(!k.current)return;B(i)}catch{}finally{k.current&&b(!1)}}async function We(){try{de(!0);const i=await Es();if(!k.current)return;oe(i)}catch{}finally{k.current&&de(!1)}}async function De(){try{l(!0);const i=await Ps();if(!k.current)return;pe(i)}catch{}finally{k.current&&l(!1)}}async function _e(i){try{await Ks(i),oe(K=>K.filter(ne=>ne.documentId!==i))}catch{}}function He(){if(E.some(K=>!K.revoked)){g(!0);return}Ie()}async function Ie(){try{d(!0);const i=await Os();w({token:i.token,name:i.name}),await Ce()}finally{d(!1)}}async function qe(){try{Q(!0);const i=await Fs();G(i.recoveryCode)}finally{Q(!1)}}async function Ge(i){i.preventDefault();const K=o.trim();if(!(K&&K.length<4))try{ae(!0),await Bs(K),L(""),ie(!0),setTimeout(()=>ie(!1),3e3)}finally{ae(!1)}}async function Ze(i){ke(i);try{const K=await $s(i),ne=new Map;K.forEach(Y=>{ne.set(Y.visitorId,Y.permission)}),we(ne)}catch{we(new Map)}ge(!0)}async function Ye(i){if(fe)try{const K=new Set(i.map(Y=>Y.visitorId)),ne=new Set(xe.keys());for(const Y of ne)K.has(Y)||await Vs(fe,Y);for(const Y of i)await Us(fe,Y.visitorId,Y.permission);await De()}finally{ge(!1),ke(null)}}const Te=ee.filter(i=>{if(!se.trim())return!0;const K=se.toLowerCase();return(i.displayName||i.relativePath||"").toLowerCase().includes(K)||(i.ownerVisitorName||"").toLowerCase().includes(K)||(i.domainId||"").toLowerCase().includes(K)}),Ae=he.filter(i=>{if(!_.trim())return!0;const K=_.toLowerCase();return(i.displayName||i.relativePath||"").toLowerCase().includes(K)||(i.domainId||"").toLowerCase().includes(K)});return e.jsxs("div",{className:"mdocs-layout"+(r?" mdocs-layout--reader mdocs-layout--settings":""),children:[r&&N?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>j(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(r?N?" mdocs-sidebar--drawer-open":" mdocs-sidebar--drawer":""),children:[e.jsxs("header",{className:"mdocs-sidebar-header",children:[e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:Ms,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),r?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>j(!1),"aria-label":s("collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Ls,{size:18})}):null]}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(f==="general"?" active":""),onClick:()=>M("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(f==="bookmarks"?" active":""),onClick:()=>M("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(f==="myDocuments"?" active":""),onClick:()=>M("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(f==="domainManagement"?" active":""),onClick:()=>M("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(f==="memberTemplates"?" active":""),onClick:()=>M("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(f==="agentConfig"?" active":""),onClick:()=>M("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(f==="savePublish"?" active":""),onClick:()=>M("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:m,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[r?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>j(!0),"aria-label":s("expandSidebar"),children:e.jsx(Rs,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:C})]}):null,zs(),f==="general"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("general")})}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsx("span",{className:"mdocs-settings-item-info",children:e.jsx("span",{className:"mdocs-settings-card-title",children:s("language")})}),e.jsxs("span",{className:"mdocs-settings-lang",children:[e.jsx("button",{type:"button",className:v==="en"?"active":"",onClick:()=>u("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:v==="zh"?"active":"",onClick:()=>u("zh"),children:"中"})]})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoEdit")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoEditDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(h?" active":""),role:"switch","aria-checked":h,onClick:()=>I(i=>!i),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliToken")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("cliTokenDesc")}),!R&&E.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:E.map(i=>e.jsxs("span",{style:{display:"block"},children:[i.name," — ",new Date(i.createdAt).toLocaleString()," ",i.revoked?`(${s("cliTokenRevoked")})`:`(${s("cliTokenActive")})`]},i.tokenId))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:He,disabled:P||R,children:P?"…":E.some(i=>!i.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),T&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--ok",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliTokenGenerated")}),e.jsx("span",{className:"mdocs-settings-secret-value",children:T.token})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(T.token),H(!1),F(!0),window.setTimeout(()=>F(!1),2e3)}catch{F(!1),H(!0),window.setTimeout(()=>H(!1),3e3)}})()},children:s(D?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>w(null),children:s("close")})]}),D&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),V&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:s("cliTokenCopyFailed")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"当 Token 丢失时,可用恢复码找回身份。生成后请立即保存,仅显示一次。"})]}),e.jsx("button",{type:"button",className:"secondary",onClick:qe,disabled:Z,children:Z?"…":"生成恢复码"})]}),q&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--warn",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 你的恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8},children:"请立即复制保存,关闭后不可再查看。"}),e.jsx("div",{className:"mdocs-settings-secret-code",children:q})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(q),U(!1),x(!0),window.setTimeout(()=>x(!1),2e3)}catch{x(!1),U(!0),window.setTimeout(()=>U(!1),3e3)}})()},children:W?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>G(null),children:s("close")})]}),W&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),$&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:"复制失败,请手动选中上方内容复制"})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-item",children:e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔐 登录密码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"设置密码后,可在其他浏览器或设备用「用户名+密码」登录。"})]})}),e.jsxs("form",{onSubmit:Ge,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:o,onChange:i=>L(i.target.value),minLength:0,style:{marginBottom:8}}),re&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:O,children:O?"设置中…":"保存密码"})]})]})]})]}):f==="bookmarks"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("bookmarkTitle")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:s("bookmarkSearch"),value:se,onChange:i=>ue(i.target.value)}),me?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Te.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(se?"bookmarkNoMatch":"bookmarkEmpty")}):e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("bookmarkColTitle")}),e.jsx("th",{children:s("bookmarkColDomain")}),e.jsx("th",{children:s("bookmarkColAuthor")}),e.jsx("th",{children:s("bookmarkColTime")}),e.jsx("th",{style:{textAlign:"right"}})]})}),e.jsx("tbody",{children:Te.map(i=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(i.documentId),children:i.displayName||i.relativePath||"Untitled"}),e.jsx("td",{children:i.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):Se.get(i.domainId||"")||i.domainId||"—"}),e.jsx("td",{children:i.ownerVisitorName||"—"}),e.jsx("td",{children:new Date(i.bookmarkedAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>_e(i.documentId),children:s("bookmarkRemove")})})]},i.documentId))})]})})]})]}):f==="myDocuments"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("myDocuments")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:"搜索文章…",value:_,onChange:i=>ve(i.target.value)}),ce?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Ae.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(_?"myDocumentsNoMatch":"myDocumentsEmpty")}):e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("myDocumentsColTitle")}),e.jsx("th",{children:s("myDocumentsColDomain")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{colSpan:2})]})}),e.jsx("tbody",{children:Ae.map(i=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(i.documentId),children:i.displayName||i.relativePath||"Untitled"}),e.jsx("td",{children:Se.get(i.domainId||"")||i.domainId||"—"}),e.jsx("td",{children:new Date(i.updatedAt).toLocaleDateString()}),e.jsx("td",{children:new Date(i.createdAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Ze(i.documentId),children:s("docInfoInviteMember")})}),e.jsx("td",{style:{textAlign:"right",paddingLeft:0},children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(i.documentId),children:s("bookmarkOpen")})})]},i.documentId))})]})})]})]}):f==="domainManagement"?e.jsx(Gs,{}):f==="memberTemplates"?e.jsx(Zs,{}):f==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Xs,{}),e.jsx(st,{})]}):e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:s("saveAndPublish")}),e.jsx("button",{type:"button",className:"secondary",onClick:m,children:s("backToDocs")})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoSave")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoSaveAlwaysOnDesc")})]}),e.jsx("span",{className:"mdocs-toggle active",role:"switch","aria-checked":"true","aria-disabled":"true",style:{opacity:.6,cursor:"not-allowed"},children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoPublish")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoPublishDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(n?" active":""),role:"switch","aria-checked":n,onClick:()=>y(i=>!i),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),le>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>p(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",le,")"]}),e.jsx("span",{className:"mdocs-settings-draft-arrow","aria-hidden":"true",children:"›"})]}):e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:s("noDrafts")})})]})]}),S&&e.jsx(Hs,{onPublish:z,onClose:()=>p(!1),onCountChange:X,onRecover:t.onRecoverDraft})]}),c&&e.jsx(Ke,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:P,onConfirm:()=>{g(!1),Ie()},onCancel:()=>g(!1)}),e.jsx($e,{open:Ue,title:s("docInfoInviteMember"),initialSelectedIds:[...xe.keys()],initialPermissions:xe,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>ge(!1),onConfirm:i=>{Ye(i)}})]})}export{rt as SettingsPage};
@@ -1,4 +1,4 @@
1
- import{c as o}from"./index-4TuRcE3b.js";import{r as u,j as r}from"./react-vendor-BJFXgntS.js";import{F as _,G as C,L as v,H as c,J as l,K as N,M as L,q as j,N as z,P as $}from"./react-B99eF5mm.js";import{z as g,V as f}from"./editor-ONzd_YnO.js";/**
1
+ import{c as o}from"./index-BkKvQv2F.js";import{r as u,j as r}from"./react-vendor-BuABiQkA.js";import{F as _,G as C,L as v,H as c,J as l,K as N,M as L,q as j,N as z,P as $}from"./react-GP8hKHRA.js";import{z as f,V as g}from"./editor-CL03se2B.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -118,4 +118,4 @@ import{c as o}from"./index-4TuRcE3b.js";import{r as u,j as r}from"./react-vendor
118
118
  *
119
119
  * This source code is licensed under the ISC license.
120
120
  * See the LICENSE file in the root directory of this source tree.
121
- */const Me=[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]],$e=o("workflow",Me);function m(e,n="*/*"){if(typeof document>"u")return;const a=document.createElement("input");a.type="file",a.accept=n,a.multiple=!1;const i=setTimeout(()=>a.remove(),5e3);a.onchange=s=>{var y;clearTimeout(i);const h=(y=s.target)==null?void 0:y.files;h&&h.length>0&&e(h),a.remove()},a.oncancel=()=>{clearTimeout(i),a.remove()},a.click()}function ge(e){const n=e.getLexicalEditor();n&&(n.update(()=>{const a=g(),i=f(),s=a.getFirstChild();s?s.insertBefore(i):a.append(i),i.selectStart()}),e.focus())}function fe(e){const n=e.getLexicalEditor();n&&(n.update(()=>{const a=g(),i=f();a.append(i),i.selectStart()}),e.focus())}function M(e,n){return[{active:e.isBold,icon:B,key:"bold",label:"Bold",onClick:e.bold,tooltipProps:{hotkey:c(l.Bold).keys}},{active:e.isItalic,icon:X,key:"italic",label:"Italic",onClick:e.italic,tooltipProps:{hotkey:c(l.Italic).keys}},{active:e.isUnderline,icon:pe,key:"underline",label:"Underline",onClick:e.underline,tooltipProps:{hotkey:c(l.Underline).keys}},{active:e.isStrikethrough,icon:he,key:"strikethrough",label:"Strikethrough",onClick:e.strikethrough,tooltipProps:{hotkey:c(l.Strikethrough).keys}},{type:"divider"},{active:!!e.textColor,editor:n,key:"textColor",label:"Text Color",onChange:e.setTextColor,type:"colorPicker",value:e.textColor},{active:!!e.bgColor,defaultColor:"#ffffff",editor:n,icon:D,key:"bgColor",label:"Background Color",onChange:e.setBgColor,type:"colorPicker",value:e.bgColor}]}const He=({editor:e,floating:n,outlineCollapseTitle:a,outlineExpandTitle:i,outlineToggle:s,style:h,className:y})=>{const t=_(e),d=C({collapseTitle:a,expandTitle:i}),b=u.useMemo(()=>[{disabled:!t.canUndo,icon:me,key:"undo",label:"Undo",onClick:t.undo,tooltipProps:{hotkey:c(l.Undo).keys}},{disabled:!t.canRedo,icon:ie,key:"redo",label:"Redo",onClick:t.redo,tooltipProps:{hotkey:c(l.Redo).keys}},{icon:I,key:"insertLineTop",label:"Insert line at top",onClick:()=>ge(e)},{icon:w,key:"insertLineBottom",label:"Insert line at end",onClick:()=>fe(e)},{type:"divider"},...M(t,e),{type:"divider"},{icon:ee,key:"bulletList",label:"Bullet List",onClick:t.bulletList,tooltipProps:{hotkey:c(l.BulletList).keys}},{icon:K,key:"numberlist",label:"Number list",onClick:t.numberList,tooltipProps:{hotkey:c(l.NumberList).keys}},{icon:Y,key:"tasklist",label:"Task list",onClick:t.checkList},{type:"divider"},{active:t.isBlockquote,icon:te,key:"blockquote",label:"Blockquote",onClick:t.blockquote},{icon:v,key:"link",label:"Link",onClick:t.insertLink,tooltipProps:{hotkey:c(l.Link).keys}},{icon:le,key:"math",label:"TeX",onClick:t.insertMath},{type:"divider"},{active:t.isCode,icon:A,key:"code",label:"Code",onClick:t.code,tooltipProps:{hotkey:c(l.CodeInline).keys}},{active:t.isCodeblock,icon:de,key:"codeblock",label:"Codeblock",onClick:t.codeblock},t.isCodeblock&&{children:r.jsx(N,{onSelect:k=>{console.log(k),t.updateCodeblockLang(k)},value:t.codeblockLang}),disabled:!t.isCodeblock,key:"codeblockLang"},{type:"divider"},{icon:G,key:"image",label:"Image",onClick:()=>{m(k=>{for(const p of k)e.dispatchCommand(L,{file:p})},"image/*")}},{icon:E,key:"file",label:"File",onClick:()=>{m(k=>{for(const p of k)e.dispatchCommand(j,{file:p})})}},...s&&d?[{type:"divider"},d]:[]].filter(Boolean),[e,t,d,s]),x=u.useMemo(()=>[...M(t,e),...s&&d?[{type:"divider"},d]:[]],[e,t,d,s]);return n?r.jsx(z,{items:x}):r.jsx("div",{className:["mdocs-toolbar",y].filter(Boolean).join(" "),style:h,children:r.jsx($,{items:b})})};export{ve as H,je as M,le as S,ze as T,$e as W,Ne as a,Le as b,He as c,m as o};
121
+ */const Me=[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]],$e=o("workflow",Me);function m(e,n="*/*"){if(typeof document>"u")return;const a=document.createElement("input");a.type="file",a.accept=n,a.multiple=!1;const i=setTimeout(()=>a.remove(),5e3);a.onchange=s=>{var y;clearTimeout(i);const h=(y=s.target)==null?void 0:y.files;h&&h.length>0&&e(h),a.remove()},a.oncancel=()=>{clearTimeout(i),a.remove()},a.click()}function fe(e){const n=e.getLexicalEditor();n&&(n.update(()=>{const a=f(),i=g(),s=a.getFirstChild();s?s.insertBefore(i):a.append(i),i.selectStart()}),e.focus())}function ge(e){const n=e.getLexicalEditor();n&&(n.update(()=>{const a=f(),i=g();a.append(i),i.selectStart()}),e.focus())}function M(e,n){return[{active:e.isBold,icon:B,key:"bold",label:"Bold",onClick:e.bold,tooltipProps:{hotkey:c(l.Bold).keys}},{active:e.isItalic,icon:X,key:"italic",label:"Italic",onClick:e.italic,tooltipProps:{hotkey:c(l.Italic).keys}},{active:e.isUnderline,icon:pe,key:"underline",label:"Underline",onClick:e.underline,tooltipProps:{hotkey:c(l.Underline).keys}},{active:e.isStrikethrough,icon:he,key:"strikethrough",label:"Strikethrough",onClick:e.strikethrough,tooltipProps:{hotkey:c(l.Strikethrough).keys}},{type:"divider"},{active:!!e.textColor,editor:n,key:"textColor",label:"Text Color",onChange:e.setTextColor,type:"colorPicker",value:e.textColor},{active:!!e.bgColor,defaultColor:"#ffffff",editor:n,icon:D,key:"bgColor",label:"Background Color",onChange:e.setBgColor,type:"colorPicker",value:e.bgColor}]}const He=({editor:e,floating:n,outlineCollapseTitle:a,outlineExpandTitle:i,outlineToggle:s,style:h,className:y})=>{const t=_(e),d=C({collapseTitle:a,expandTitle:i}),b=u.useMemo(()=>[{disabled:!t.canUndo,icon:me,key:"undo",label:"Undo",onClick:t.undo,tooltipProps:{hotkey:c(l.Undo).keys}},{disabled:!t.canRedo,icon:ie,key:"redo",label:"Redo",onClick:t.redo,tooltipProps:{hotkey:c(l.Redo).keys}},{icon:I,key:"insertLineTop",label:"Insert line at top",onClick:()=>fe(e)},{icon:w,key:"insertLineBottom",label:"Insert line at end",onClick:()=>ge(e)},{type:"divider"},...M(t,e),{type:"divider"},{icon:ee,key:"bulletList",label:"Bullet List",onClick:t.bulletList,tooltipProps:{hotkey:c(l.BulletList).keys}},{icon:K,key:"numberlist",label:"Number list",onClick:t.numberList,tooltipProps:{hotkey:c(l.NumberList).keys}},{icon:Y,key:"tasklist",label:"Task list",onClick:t.checkList},{type:"divider"},{active:t.isBlockquote,icon:te,key:"blockquote",label:"Blockquote",onClick:t.blockquote},{icon:v,key:"link",label:"Link",onClick:t.insertLink,tooltipProps:{hotkey:c(l.Link).keys}},{icon:le,key:"math",label:"TeX",onClick:t.insertMath},{type:"divider"},{active:t.isCode,icon:A,key:"code",label:"Code",onClick:t.code,tooltipProps:{hotkey:c(l.CodeInline).keys}},{active:t.isCodeblock,icon:de,key:"codeblock",label:"Codeblock",onClick:t.codeblock},t.isCodeblock&&{children:r.jsx(N,{onSelect:k=>{console.log(k),t.updateCodeblockLang(k)},value:t.codeblockLang}),disabled:!t.isCodeblock,key:"codeblockLang"},{type:"divider"},{icon:G,key:"image",label:"Image",onClick:()=>{m(k=>{for(const p of k)e.dispatchCommand(L,{file:p})},"image/*")}},{icon:E,key:"file",label:"File",onClick:()=>{m(k=>{for(const p of k)e.dispatchCommand(j,{file:p})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},...s&&d?[{type:"divider"},d]:[]].filter(Boolean),[e,t,d,s]),x=u.useMemo(()=>[...M(t,e),...s&&d?[{type:"divider"},d]:[]],[e,t,d,s]);return n?r.jsx(z,{items:x}):r.jsx("div",{className:["mdocs-toolbar",y].filter(Boolean).join(" "),style:h,children:r.jsx($,{items:b})})};export{ve as H,je as M,le as S,ze as T,$e as W,Ne as a,Le as b,He as c,m as o};
@@ -1 +1 @@
1
- import{r,j as e}from"./react-vendor-BJFXgntS.js";import{b as G,B as ee,f as se,w as z}from"./index-4TuRcE3b.js";function ie({options:v,value:a,onChange:b}){const[d,f]=r.useState(!1),y=r.useRef(null),x=r.useRef(null),p=v.find(o=>o.value===a);r.useEffect(()=>{if(!d)return;const o=u=>{var N,k;!((N=y.current)!=null&&N.contains(u.target))&&!((k=x.current)!=null&&k.contains(u.target))&&f(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[d]),r.useEffect(()=>{if(!d)return;const o=u=>{var N;u.key==="Escape"&&(f(!1),(N=y.current)==null||N.focus())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[d]);function j(o){b(o),f(!1)}return e.jsxs("div",{className:"mdocs-mini-select",style:{position:"relative"},children:[e.jsxs("button",{ref:y,type:"button",className:"mdocs-mini-select-trigger","aria-expanded":d,"aria-haspopup":"listbox",onClick:()=>f(o=>!o),children:[e.jsx("span",{children:p==null?void 0:p.label}),e.jsx("svg",{className:"mdocs-mini-select-chevron"+(d?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),d&&e.jsx("div",{ref:x,className:"mdocs-mini-select-menu card",role:"listbox",children:v.map(o=>e.jsx("button",{type:"button",className:"mdocs-mini-select-option"+(o.value===a?" active":""),role:"option","aria-selected":o.value===a,onClick:()=>j(o.value),children:o.label},o.value))})]})}function te(v){return v.length<=6?v:`${v.slice(0,6)}…`}function re(v){const{visitors:a,loadState:b,searchFilter:d,onSearchChange:f,selectedIds:y,onToggle:x,selectedRows:p,lockedIds:j=new Set,myVisitorId:o,showPermissionSelect:u=!1,permissionOptions:N=[],onPermissionChange:k}=v,{t:i}=G(),w=r.useMemo(()=>{const t=d.trim().toLowerCase();let g=t?a.filter(m=>m.visitorName.toLowerCase().includes(t)||m.visitorId.toLowerCase().includes(t)):a;return o&&(g=[...g].sort((m,R)=>m.visitorId===o?-1:R.visitorId===o?1:0)),g},[a,d,o]);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"search",className:"mdocs-visitor-picker-search",placeholder:i("visitorPickerSearchPlaceholder"),value:d,onChange:t=>f(t.target.value),disabled:b!=="ok"}),b==="loading"&&e.jsx("div",{className:"mdocs-visitor-picker-loading",children:i("loading")}),b==="err"&&e.jsx("div",{className:"mdocs-visitor-picker-error",children:i("visitorPickerLoadError")}),b==="ok"&&e.jsxs("div",{className:"mdocs-visitor-picker-columns",children:[e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnAll")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdShort")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col",children:i("visitorPickerColPick")})]})}),e.jsx("tbody",{children:w.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"mdocs-visitor-picker-empty-cell",children:a.length===0?i("visitorPickerEmptyDirectory"):i("domainNoMatch")})}):w.map(t=>{const g=j.has(t.visitorId),m=y.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-short",children:te(t.visitorId)})}),e.jsxs("td",{children:[t.visitorName,t.visitorId===o&&e.jsx("span",{className:"mdocs-visitor-picker-self-marker",children:i("visitorPickerSelfMarker")})]}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:e.jsx("input",{type:"checkbox",checked:m,disabled:g,onChange:()=>x(t.visitorId),"aria-label":t.visitorName})})]},t.visitorId)})})]})})]}),e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnSelected")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdFull")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),u&&e.jsx("th",{scope:"col",children:i("permissionLabel")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col"})]})}),e.jsx("tbody",{children:p.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:u?4:3,className:"mdocs-visitor-picker-empty-cell",children:i("visitorPickerNoSelection")})}):p.map(t=>{const g=j.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-full",children:t.visitorId})}),e.jsx("td",{className:t.muted?"mdocs-visitor-picker-name-muted":void 0,children:t.name}),u&&e.jsx("td",{children:e.jsx(ie,{options:N,value:t.permission??"read",onChange:m=>k==null?void 0:k(t.visitorId,m)})}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:g?e.jsx("span",{className:"mdocs-visitor-picker-locked",title:i("visitorPickerLockedHint"),children:"—"}):e.jsx("button",{type:"button",className:"mdocs-visitor-picker-remove",onClick:()=>x(t.visitorId),"aria-label":i("visitorPickerRemove"),children:"×"})})]},t.visitorId)})})]})})]})]})]})}function ne(v){var U;const{open:a,title:b,initialSelectedIds:d,lockedIds:f=[],seedMembers:y,excludeTemplateId:x,templates:p,onClose:j,onConfirm:o,showPermissionSelect:u=!1,permissionOptions:N=[],initialPermissions:k}=v,{t:i}=G(),w=r.useRef(i);w.current=i;const t=r.useMemo(()=>new Set(f),[f]),g=ee(),[m,R]=r.useState([]),[E,T]=r.useState("idle"),[P,V]=r.useState(()=>new Set),[O,L]=r.useState(()=>new Map),[J,F]=r.useState(""),[C,A]=r.useState(""),[M,B]=r.useState(!1),$=r.useRef(null),[K,W]=r.useState(!1),[q,I]=r.useState(null),D=r.useMemo(()=>p.filter(s=>x==null||s.id!==x),[p,x]),H=r.useMemo(()=>new Map((y??[]).map(s=>[s.visitorId,s])),[y]);r.useEffect(()=>{a&&(V(new Set(d)),L(k?new Map(k):new Map),F(""),A(""),I(null))},[a,d,k]),r.useEffect(()=>{if(!a)return;let s=!1;return T("loading"),se().then(n=>{s||(R(n),T("ok"))}).catch(n=>{s||(T("err"),I(z(w.current,n)))}),()=>{s=!0}},[a]),r.useEffect(()=>{if(!M)return;const s=n=>{var c;(c=$.current)!=null&&c.contains(n.target)||B(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[M]);const Q=r.useMemo(()=>{const s=new Map(m.map(c=>[c.visitorId,c])),n=[];for(const c of P){const l=O.get(c),h=s.get(c);if(h){n.push({visitorId:c,name:h.visitorName,muted:!1,permission:l});continue}const S=H.get(c);if(S){S.missing?n.push({visitorId:c,name:i("visitorPickerMemberMissing"),muted:!0,permission:l}):S.disabled?n.push({visitorId:c,name:`${S.visitorName} · ${i("visitorPickerDisabledTag")}`,muted:!0,permission:l}):n.push({visitorId:c,name:S.visitorName,muted:!1,permission:l});continue}n.push({visitorId:c,name:i("visitorPickerUnknownVisitor"),muted:!0,permission:l})}return n.sort((c,l)=>c.name.localeCompare(l.name,void 0,{sensitivity:"base"})),n},[m,P,H,O,i]),X=r.useCallback(s=>{t.has(s)||V(n=>{const c=new Set(n);return c.has(s)?(c.delete(s),L(l=>{const h=new Map(l);return h.delete(s),h})):(c.add(s),L(l=>{const h=new Map(l);return h.set(s,"read"),h})),c})},[t]),Y=r.useCallback((s,n)=>{L(c=>{const l=new Map(c);return l.set(s,n),l})},[]),Z=r.useCallback(()=>{const s=Number(C);if(!Number.isInteger(s)||s<1)return;const n=p.find(l=>l.id===s);if(!n)return;const c=new Set(m.map(l=>l.visitorId));V(l=>{const h=new Set(l);for(const S of n.visitorIds)c.has(S)&&h.add(S);return h})},[C,p,m]);async function _(){I(null),W(!0);try{if(u){const s=[...P].sort().map(n=>({visitorId:n,permission:O.get(n)??"read"}));await o(s)}else{const s=[...P].sort();await o(s)}j()}catch(s){I(z(i,s))}finally{W(!1)}}return a?e.jsx("div",{className:"mdocs-visitor-picker-overlay",role:"presentation",onMouseDown:s=>s.target===s.currentTarget&&j(),children:e.jsxs("div",{className:"mdocs-visitor-picker-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-visitor-picker-title",children:[e.jsxs("header",{className:"mdocs-visitor-picker-header",children:[e.jsx("h2",{id:"mdocs-visitor-picker-title",className:"mdocs-visitor-picker-title",children:b}),e.jsx("button",{type:"button",className:"mdocs-visitor-picker-close",onClick:j,"aria-label":i("close"),children:"×"})]}),D.length>0&&e.jsx("div",{className:"mdocs-visitor-picker-toolbar",children:e.jsxs("div",{className:"mdocs-visitor-picker-template-bar",children:[e.jsxs("div",{ref:$,className:"mdocs-template-picker",children:[e.jsxs("button",{type:"button",className:"mdocs-template-picker-trigger",onClick:()=>B(s=>!s),disabled:E!=="ok","aria-haspopup":"listbox","aria-expanded":M,children:[e.jsx("span",{className:"mdocs-template-picker-text",children:C?(U=D.find(s=>String(s.id)===C))==null?void 0:U.displayName:i("visitorPickerPickTemplate")}),e.jsx("svg",{className:"mdocs-template-picker-chevron"+(M?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),M&&e.jsx("div",{className:"mdocs-template-picker-menu card",role:"listbox",children:D.map(s=>e.jsx("button",{type:"button",className:"mdocs-template-picker-option"+(String(s.id)===C?" active":""),role:"option","aria-selected":String(s.id)===C,onClick:()=>{A(String(s.id)),B(!1)},children:s.displayName},s.id))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}if(!C){I(i("visitorPickerPickTemplate"));return}Z()},children:i("visitorPickerApplyTemplate")})]})}),q&&e.jsx("div",{className:"mdocs-visitor-picker-error",role:"alert",children:q}),e.jsx("div",{style:{padding:"8px 18px 12px"},children:e.jsx(re,{visitors:m,loadState:E,searchFilter:J,onSearchChange:F,selectedIds:P,onToggle:X,selectedRows:Q,lockedIds:t,myVisitorId:g,showPermissionSelect:u,permissionOptions:N,onPermissionChange:Y})}),e.jsxs("footer",{className:"mdocs-visitor-picker-footer",children:[e.jsx("button",{type:"button",className:"secondary",onClick:j,children:i("cancel")}),e.jsx("button",{type:"button",className:"primary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}_()},children:i(K?"saving":"visitorPickerConfirm")})]})]})}):null}export{ie as M,ne as V,re as a};
1
+ import{r,j as e}from"./react-vendor-BuABiQkA.js";import{b as G,B as ee,f as se,w as z}from"./index-BkKvQv2F.js";function ie({options:v,value:a,onChange:b}){const[d,f]=r.useState(!1),y=r.useRef(null),x=r.useRef(null),p=v.find(o=>o.value===a);r.useEffect(()=>{if(!d)return;const o=u=>{var N,k;!((N=y.current)!=null&&N.contains(u.target))&&!((k=x.current)!=null&&k.contains(u.target))&&f(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[d]),r.useEffect(()=>{if(!d)return;const o=u=>{var N;u.key==="Escape"&&(f(!1),(N=y.current)==null||N.focus())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[d]);function j(o){b(o),f(!1)}return e.jsxs("div",{className:"mdocs-mini-select",style:{position:"relative"},children:[e.jsxs("button",{ref:y,type:"button",className:"mdocs-mini-select-trigger","aria-expanded":d,"aria-haspopup":"listbox",onClick:()=>f(o=>!o),children:[e.jsx("span",{children:p==null?void 0:p.label}),e.jsx("svg",{className:"mdocs-mini-select-chevron"+(d?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),d&&e.jsx("div",{ref:x,className:"mdocs-mini-select-menu card",role:"listbox",children:v.map(o=>e.jsx("button",{type:"button",className:"mdocs-mini-select-option"+(o.value===a?" active":""),role:"option","aria-selected":o.value===a,onClick:()=>j(o.value),children:o.label},o.value))})]})}function te(v){return v.length<=6?v:`${v.slice(0,6)}…`}function re(v){const{visitors:a,loadState:b,searchFilter:d,onSearchChange:f,selectedIds:y,onToggle:x,selectedRows:p,lockedIds:j=new Set,myVisitorId:o,showPermissionSelect:u=!1,permissionOptions:N=[],onPermissionChange:k}=v,{t:i}=G(),w=r.useMemo(()=>{const t=d.trim().toLowerCase();let g=t?a.filter(m=>m.visitorName.toLowerCase().includes(t)||m.visitorId.toLowerCase().includes(t)):a;return o&&(g=[...g].sort((m,R)=>m.visitorId===o?-1:R.visitorId===o?1:0)),g},[a,d,o]);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"search",className:"mdocs-visitor-picker-search",placeholder:i("visitorPickerSearchPlaceholder"),value:d,onChange:t=>f(t.target.value),disabled:b!=="ok"}),b==="loading"&&e.jsx("div",{className:"mdocs-visitor-picker-loading",children:i("loading")}),b==="err"&&e.jsx("div",{className:"mdocs-visitor-picker-error",children:i("visitorPickerLoadError")}),b==="ok"&&e.jsxs("div",{className:"mdocs-visitor-picker-columns",children:[e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnAll")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdShort")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col",children:i("visitorPickerColPick")})]})}),e.jsx("tbody",{children:w.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"mdocs-visitor-picker-empty-cell",children:a.length===0?i("visitorPickerEmptyDirectory"):i("domainNoMatch")})}):w.map(t=>{const g=j.has(t.visitorId),m=y.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-short",children:te(t.visitorId)})}),e.jsxs("td",{children:[t.visitorName,t.visitorId===o&&e.jsx("span",{className:"mdocs-visitor-picker-self-marker",children:i("visitorPickerSelfMarker")})]}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:e.jsx("input",{type:"checkbox",checked:m,disabled:g,onChange:()=>x(t.visitorId),"aria-label":t.visitorName})})]},t.visitorId)})})]})})]}),e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnSelected")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdFull")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),u&&e.jsx("th",{scope:"col",children:i("permissionLabel")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col"})]})}),e.jsx("tbody",{children:p.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:u?4:3,className:"mdocs-visitor-picker-empty-cell",children:i("visitorPickerNoSelection")})}):p.map(t=>{const g=j.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-full",children:t.visitorId})}),e.jsx("td",{className:t.muted?"mdocs-visitor-picker-name-muted":void 0,children:t.name}),u&&e.jsx("td",{children:e.jsx(ie,{options:N,value:t.permission??"read",onChange:m=>k==null?void 0:k(t.visitorId,m)})}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:g?e.jsx("span",{className:"mdocs-visitor-picker-locked",title:i("visitorPickerLockedHint"),children:"—"}):e.jsx("button",{type:"button",className:"mdocs-visitor-picker-remove",onClick:()=>x(t.visitorId),"aria-label":i("visitorPickerRemove"),children:"×"})})]},t.visitorId)})})]})})]})]})]})}function ne(v){var U;const{open:a,title:b,initialSelectedIds:d,lockedIds:f=[],seedMembers:y,excludeTemplateId:x,templates:p,onClose:j,onConfirm:o,showPermissionSelect:u=!1,permissionOptions:N=[],initialPermissions:k}=v,{t:i}=G(),w=r.useRef(i);w.current=i;const t=r.useMemo(()=>new Set(f),[f]),g=ee(),[m,R]=r.useState([]),[E,T]=r.useState("idle"),[P,V]=r.useState(()=>new Set),[O,L]=r.useState(()=>new Map),[J,F]=r.useState(""),[C,A]=r.useState(""),[M,B]=r.useState(!1),$=r.useRef(null),[K,W]=r.useState(!1),[q,I]=r.useState(null),D=r.useMemo(()=>p.filter(s=>x==null||s.id!==x),[p,x]),H=r.useMemo(()=>new Map((y??[]).map(s=>[s.visitorId,s])),[y]);r.useEffect(()=>{a&&(V(new Set(d)),L(k?new Map(k):new Map),F(""),A(""),I(null))},[a,d,k]),r.useEffect(()=>{if(!a)return;let s=!1;return T("loading"),se().then(n=>{s||(R(n),T("ok"))}).catch(n=>{s||(T("err"),I(z(w.current,n)))}),()=>{s=!0}},[a]),r.useEffect(()=>{if(!M)return;const s=n=>{var c;(c=$.current)!=null&&c.contains(n.target)||B(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[M]);const Q=r.useMemo(()=>{const s=new Map(m.map(c=>[c.visitorId,c])),n=[];for(const c of P){const l=O.get(c),h=s.get(c);if(h){n.push({visitorId:c,name:h.visitorName,muted:!1,permission:l});continue}const S=H.get(c);if(S){S.missing?n.push({visitorId:c,name:i("visitorPickerMemberMissing"),muted:!0,permission:l}):S.disabled?n.push({visitorId:c,name:`${S.visitorName} · ${i("visitorPickerDisabledTag")}`,muted:!0,permission:l}):n.push({visitorId:c,name:S.visitorName,muted:!1,permission:l});continue}n.push({visitorId:c,name:i("visitorPickerUnknownVisitor"),muted:!0,permission:l})}return n.sort((c,l)=>c.name.localeCompare(l.name,void 0,{sensitivity:"base"})),n},[m,P,H,O,i]),X=r.useCallback(s=>{t.has(s)||V(n=>{const c=new Set(n);return c.has(s)?(c.delete(s),L(l=>{const h=new Map(l);return h.delete(s),h})):(c.add(s),L(l=>{const h=new Map(l);return h.set(s,"read"),h})),c})},[t]),Y=r.useCallback((s,n)=>{L(c=>{const l=new Map(c);return l.set(s,n),l})},[]),Z=r.useCallback(()=>{const s=Number(C);if(!Number.isInteger(s)||s<1)return;const n=p.find(l=>l.id===s);if(!n)return;const c=new Set(m.map(l=>l.visitorId));V(l=>{const h=new Set(l);for(const S of n.visitorIds)c.has(S)&&h.add(S);return h})},[C,p,m]);async function _(){I(null),W(!0);try{if(u){const s=[...P].sort().map(n=>({visitorId:n,permission:O.get(n)??"read"}));await o(s)}else{const s=[...P].sort();await o(s)}j()}catch(s){I(z(i,s))}finally{W(!1)}}return a?e.jsx("div",{className:"mdocs-visitor-picker-overlay",role:"presentation",onMouseDown:s=>s.target===s.currentTarget&&j(),children:e.jsxs("div",{className:"mdocs-visitor-picker-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-visitor-picker-title",children:[e.jsxs("header",{className:"mdocs-visitor-picker-header",children:[e.jsx("h2",{id:"mdocs-visitor-picker-title",className:"mdocs-visitor-picker-title",children:b}),e.jsx("button",{type:"button",className:"mdocs-visitor-picker-close",onClick:j,"aria-label":i("close"),children:"×"})]}),D.length>0&&e.jsx("div",{className:"mdocs-visitor-picker-toolbar",children:e.jsxs("div",{className:"mdocs-visitor-picker-template-bar",children:[e.jsxs("div",{ref:$,className:"mdocs-template-picker",children:[e.jsxs("button",{type:"button",className:"mdocs-template-picker-trigger",onClick:()=>B(s=>!s),disabled:E!=="ok","aria-haspopup":"listbox","aria-expanded":M,children:[e.jsx("span",{className:"mdocs-template-picker-text",children:C?(U=D.find(s=>String(s.id)===C))==null?void 0:U.displayName:i("visitorPickerPickTemplate")}),e.jsx("svg",{className:"mdocs-template-picker-chevron"+(M?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),M&&e.jsx("div",{className:"mdocs-template-picker-menu card",role:"listbox",children:D.map(s=>e.jsx("button",{type:"button",className:"mdocs-template-picker-option"+(String(s.id)===C?" active":""),role:"option","aria-selected":String(s.id)===C,onClick:()=>{A(String(s.id)),B(!1)},children:s.displayName},s.id))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}if(!C){I(i("visitorPickerPickTemplate"));return}Z()},children:i("visitorPickerApplyTemplate")})]})}),q&&e.jsx("div",{className:"mdocs-visitor-picker-error",role:"alert",children:q}),e.jsx("div",{style:{padding:"8px 18px 12px"},children:e.jsx(re,{visitors:m,loadState:E,searchFilter:J,onSearchChange:F,selectedIds:P,onToggle:X,selectedRows:Q,lockedIds:t,myVisitorId:g,showPermissionSelect:u,permissionOptions:N,onPermissionChange:Y})}),e.jsxs("footer",{className:"mdocs-visitor-picker-footer",children:[e.jsx("button",{type:"button",className:"secondary",onClick:j,children:i("cancel")}),e.jsx("button",{type:"button",className:"primary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}_()},children:i(K?"saving":"visitorPickerConfirm")})]})]})}):null}export{ie as M,ne as V,re as a};
@@ -1,4 +1,4 @@
1
- import{c}from"./index-4TuRcE3b.js";/**
1
+ import{c}from"./index-BkKvQv2F.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.