@fgbg/mdocs 0.8.21 → 0.8.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-skills/changelog/SKILL.md +9 -1
- package/agent-skills/index.json +1 -1
- package/bin/mdocs.js +1 -1
- package/dist/server/cli/main.js +22 -1
- package/dist/server/cli/main.js.map +1 -1
- package/dist/server/documents/tree-and-folders.test.js +54 -3
- package/dist/server/documents/tree-and-folders.test.js.map +1 -1
- package/dist/server/documents/tree.service.js +66 -5
- package/dist/server/documents/tree.service.js.map +1 -1
- package/dist/server/routes/documents.routes.js +16 -0
- package/dist/server/routes/documents.routes.js.map +1 -1
- package/dist/web/assets/{AgentChatPanel-D95hI02c.js → AgentChatPanel-IrNTGpzN.js} +1 -1
- package/dist/web/assets/{AgentSkillFormCard-BtJ0QjLG.js → AgentSkillFormCard-goRzD94F.js} +1 -1
- package/dist/web/assets/AiWriteWorkbench-CMe6iuR8.js +7 -0
- package/dist/web/assets/{DiagramEditor-BTRe45TX-Did98cnP.js → DiagramEditor-BTRe45TX-D1vc5s9F.js} +1 -1
- package/dist/web/assets/{DocumentEditor-DtSzkl6A.js → DocumentEditor-CbksWmYP.js} +1 -1
- package/dist/web/assets/{MergeView-DgFQHD5_.js → MergeView-CMQVyBUA.js} +1 -1
- package/dist/web/assets/{PlaygroundPage-Dg57Xxpl.js → PlaygroundPage-w1D9fzsK.js} +1 -1
- package/dist/web/assets/{SettingsPage-CkYpe5v7.js → SettingsPage-DzTINzaB.js} +1 -1
- package/dist/web/assets/{Toolbar-0Y2wmGwe.js → Toolbar-DylP9gFR.js} +1 -1
- package/dist/web/assets/{VisitorPickerModal-COxtOvc4.js → VisitorPickerModal-D0i7oxrW.js} +1 -1
- package/dist/web/assets/{copy-nOl0d3Th.js → copy-Ba87S6Rg.js} +1 -1
- package/dist/web/assets/{diagram-BJFhx-27.js → diagram-gfUK8OHx.js} +332 -332
- package/dist/web/assets/index-7HUca950.css +1 -0
- package/dist/web/assets/{index-B-XJ-ScV.js → index-DOrcbEeP.js} +3 -3
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-e28q005B.js → meta2dEngine-BD2XbzaV-BFAQue19.js} +1 -1
- package/dist/web/assets/{motion-D-I76zAi.js → motion-C4pN8CfU.js} +1 -1
- package/dist/web/assets/{plus-DvBbg6jL.js → plus-BlTVBbk-.js} +1 -1
- package/dist/web/assets/{react-BsVOIHR8.js → react-DedaIFYc.js} +3 -3
- package/dist/web/assets/{ui-C3xtW1w8.js → ui-DxdLi_28.js} +3 -3
- package/dist/web/index.html +4 -4
- package/package.json +1 -1
- package/dist/web/assets/AiWriteWorkbench-Qam8cfY6.js +0 -6
- package/dist/web/assets/index-CGvsjO9f.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,j as e}from"./react-vendor-BNpqFP9B.js";import{b as Z,q as We,s as Ue,D as _e,l as ce,t as He,v as qe,w as _,x as le,y as Ge,z as Ze,A as Je,a as Qe,d as Ne,B as ve,C as ke,E as Xe,G as Ye,H as es,I as ss,J as ts,K as we,L as ne,N as as,O as ns,P as is,Q as cs,R as ls,f as rs,T as os,U as ds,V as ms,W as us,X as hs,i as gs,Y as ps,Z as fs,_ as xs,$ as js,a0 as Ns,a1 as ys,a2 as bs,a3 as vs,a4 as ks,a5 as ws,a6 as Ss,a7 as Cs,a8 as Ds,r as Is,j as Ts,a9 as As,n as Es,o as Ps}from"./index-B-XJ-ScV.js";import{V as Se,a as Ms,M as Ls}from"./VisitorPickerModal-COxtOvc4.js";import"./ui-C3xtW1w8.js";import"./motion-D-I76zAi.js";function Rs({draft:t,onClose:s,onSuccess:k}){const{t:h,lang:g}=Z(),[M,r]=a.useState([]),[y,b]=a.useState(t.domainId??""),[C,i]=a.useState([]),[N,f]=a.useState(""),[d,j]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[u,z]=a.useState(!1),[T,R]=a.useState(null),I=a.useRef(null),A=a.useRef(!0);a.useEffect(()=>(A.current=!0,()=>{A.current=!1}),[]),a.useEffect(()=>{We().then(x=>{A.current&&r(x)})},[]),a.useEffect(()=>{y&&(i([]),f(""),Ue(y).then(x=>{A.current&&i(x)}).catch(()=>{A.current&&i([])}))},[y]),a.useEffect(()=>{const x=window.setTimeout(()=>{var P;return(P=I.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(x)},[]),a.useEffect(()=>{const x=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[s]);function B(x,P){for(const v of x){if(v.type==="folder"&&v.path===P)return v.documentId;if(v.type==="folder"){const S=B(v.children,P);if(S)return S}}return null}async function E(x){x.preventDefault(),z(!0),R(null);const P=d.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),v=P.endsWith(".md")?P:P+".md",S=v.replace(/\.md$/i,"");try{const l=N?`${N}/${v}`:v,c=N?B(C,N)??void 0:void 0;await qe({fileName:v,displayName:S,content:t.content,domainId:y,parentId:c}),k()}catch(l){R(_(h,l))}finally{z(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:x=>{x.target===x.currentTarget&&!u&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:h("recoverDraft")}),e.jsx("p",{className:"muted",children:h("recoverDraftDesc",{name:t.displayName||h("unknownTitle")})}),e.jsxs("form",{onSubmit:E,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[h("domainLabel"),M.length>0&&e.jsx(_e,{domains:M,value:y,onChange:b,onDomainsChange:r,ariaLabel:h("domainLabel"),localizeName:x=>ce(x,g,h)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[h("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(He,{nodes:C,activeDocumentId:null,selectedParentPath:N,onOpen:()=>{},onOpenFolder:x=>f(x),onContextMenu:()=>{},onDeselect:()=>f("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[h("fileNameLabel"),e.jsx("input",{ref:I,value:d,onChange:x=>j(x.target.value),placeholder:"recovered.md",maxLength:200,disabled:u})]}),T&&e.jsx("div",{className:"mdocs-dialog-error",children:T}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!u&&s(),disabled:u,children:h("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:u,children:h(u?"creating":"create")})]})]})]})})}function zs({onPublish:t,onClose:s,onCountChange:k,onRecover:h}){const{t:g}=Z(),[M,r]=a.useState([]),[y,b]=a.useState(new Set),[C,i]=a.useState(!1),[N,f]=a.useState(null),[d,j]=a.useState(null),[u,z]=a.useState(null),T=a.useRef(null),R=a.useRef(!0);a.useEffect(()=>(R.current=!0,le().then(c=>{if(!R.current)return;const m=c.filter(w=>!w.published);r(m),k==null||k(m.length)}),()=>{R.current=!1,T.current&&(clearTimeout(T.current),T.current=null)}),[]),a.useEffect(()=>{const c=m=>{m.key==="Escape"&&s()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s]);const I=a.useCallback((c,m)=>{z({message:c,type:m}),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>z(null),3e3)},[]);async function A(c){await Ze(c),b(m=>new Set(m).add(c));try{await t(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),I(g("published"),"success")}catch(m){m instanceof Je||I(g("publishFailed"),"error");const w=await Qe(c);w&&r(F=>F.map(K=>K.documentId===c?w:K))}finally{b(m=>{const w=new Set(m);return w.delete(c),w})}}async function B(c){f(null),await Ne(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),I(g("draftDeleted"),"success")}function E(c){const m=M.find(w=>w.documentId===c);m&&j(m)}function x(c){j(null),Ne(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),h==null||h(M.find(m=>m.documentId===c)),I(g("published"),"success")}async function P(){i(!0);let c=0,m=0;for(const K of M)try{await t(K.documentId),c++}catch{m++}const F=(await le()).filter(K=>!K.published);r(F),k==null||k(F.length),m===0?I(g("publishAll"),"success"):I(`${c} published, ${m} failed`,"error"),i(!1)}const v=c=>new Date(c).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),S=c=>Ge(g,c,c.publishError??"UNKNOWN"),l=M;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:[g("unpublishedDrafts"),l.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:l.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:g("draftCount",{count:String(l.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":g("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:l.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:g("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:l.map(c=>{const m=!!c.publishError;return e.jsxs("div",{className:m?"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||g("unknownTitle")}),m?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[v(c.publishErrorAt)," · ",S(c)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[v(c.updatedAt)," · ",g("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[m?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:C,onClick:()=>E(c.documentId),children:g("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:y.has(c.documentId)||C,onClick:()=>void A(c.documentId),children:y.has(c.documentId)?g("publishing"):g("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:C,onClick:()=>f(c.documentId),children:g("delete")})]})]},c.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:g("close")}),e.jsx("button",{type:"button",className:"primary",disabled:l.length===0||C,onClick:()=>void P(),children:C?g("publishing"):`${g("publishAll")} (${l.length})`})]}),u&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+u.type,role:"status",children:u.message})]}),N&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:c=>{c.target===c.currentTarget&&f(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:g("delete")}),e.jsx("p",{className:"muted",children:g("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>f(null),children:g("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void B(N),children:g("delete")})]})]})}),d&&e.jsx(Rs,{draft:d,onClose:()=>j(null),onSuccess:()=>x(d.documentId)})]})}function Bs(){const{t,lang:s}=Z(),k=ve(),h=a.useRef(!1),[g,M]=a.useState([]),[r,y]=a.useState(!1),[b,C]=a.useState(""),[i,N]=a.useState("restricted"),[f,d]=a.useState(!1),[j,u]=a.useState(null),[z,T]=a.useState(null),[R,I]=a.useState(""),[A,B]=a.useState(""),[E,x]=a.useState("all"),[P,v]=a.useState(null);a.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const S=a.useCallback(async()=>{y(!0),u(null);try{const p=await ke();if(!h.current)return;M(p)}catch(p){if(!h.current)return;u(_(t,p))}finally{h.current&&y(!1)}},[t]);a.useEffect(()=>{S()},[S]);async function l(p){if(p.preventDefault(),!b.trim()){u(t("domainNameRequired"));return}d(!0),u(null);try{if(await ts({domainName:b.trim(),permission:i}),!h.current)return;C(""),N("restricted"),await S()}catch(V){if(!h.current)return;u(_(t,V))}finally{h.current&&d(!1)}}async function c(p){if(R.trim()){u(null);try{if(await ss(p,R.trim()),!h.current)return;T(null),v(null),await S()}catch(V){if(!h.current)return;u(_(t,V))}}}function m(p){T(p.domainId),I(p.domainName),v(null)}function w(){T(null),v(null)}async function F(p,V){u(null);try{if(await es(p,V),!h.current)return;v(null),await S()}catch($){if(!h.current)return;u(_(t,$))}}async function K(p){if(window.confirm(t("deleteDomainConfirmDetail",{name:p.domainName,count:String(p.docCount)}))){u(null);try{if(await Ye(p.domainId),!h.current)return;await S()}catch(V){if(!h.current)return;u(_(t,V))}}}const H=a.useCallback(p=>Xe(p,t),[t]),q=a.useCallback(p=>ce(p.domainName,s,t),[s,t]),G=a.useMemo(()=>{const p=A.trim().toLowerCase();return g.filter(V=>E!=="all"&&V.permission!==E?!1:p?ce(V.domainName,s,t).toLowerCase().includes(p)||V.domainName.toLowerCase().includes(p):!0)},[g,A,E,s,t]),D=a.useCallback((p,V)=>{const $=H(p.permission);return V?`${$} ${t("domainTypeBuiltinSuffix")}`:$},[H,t]);return{domains:g,loadingDomains:r,domainError:j,newDomainName:b,setNewDomainName:C,newDomainPermission:i,setNewDomainPermission:N,creating:f,handleCreateDomain:l,renamingId:z,setRenamingId:T,renameDraft:R,setRenameDraft:I,startRename:m,cancelRename:w,handleRename:c,changeTypeForId:P,setChangeTypeForId:v,handlePermissionChange:F,handleDelete:K,domainSearch:A,setDomainSearch:B,domainFilter:E,setDomainFilter:x,filteredDomains:G,visitorId:k,plabel:H,localizeDomain:q,domainTypeLabel:D}}function Fs(){const{t}=Z(),s=Bs(),[k,h]=a.useState([]),[g,M]=a.useState(null),[r,y]=a.useState(null),b=a.useCallback(async()=>{try{const i=await we();h(i)}catch{h([])}},[]);a.useEffect(()=>{b()},[b]);async function C(i){M(null);try{const N=await ls(i.domainId);y({domainId:i.domainId,creatorVisitorId:i.creatorVisitorId,initialIds:N.map(f=>f.visitorId),memberRows:N})}catch(N){M({kind:"err",text:_(t,N)})}}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:i=>s.setNewDomainName(i.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:ne.map(i=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===i,onChange:()=>s.setNewDomainPermission(i),disabled:s.creating}),e.jsx("span",{children:s.plabel(i)})]},i))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?t("creating"):t("create")})]})]}),g&&e.jsx("div",{className:"mdocs-settings-card",style:{color:g.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:g.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:i=>s.setDomainSearch(i.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",...ne].map(i=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===i?" active":""),"aria-pressed":s.domainFilter===i,onClick:()=>s.setDomainFilter(i),children:i==="all"?t("domainFilterAll"):s.plabel(i)},i))})]}),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(i=>{const N=as(i,s.visitorId),f=ns(i.domainId),d=is(i),j=d?t("domainTooltipTypeLocked",{count:String(i.docCount)}):void 0;return e.jsxs("tr",{className:f?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===i.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:u=>s.setRenameDraft(u.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(i.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(i)}),f&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!N&&!f&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsxs("span",{className:"mdocs-domain-table-type",title:j,children:[e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":i.permission,children:s.domainTypeLabel(i,f)}),d&&!f&&e.jsx("span",{className:"mdocs-domain-type-lock","aria-hidden":"true",children:"🔒"})]})}),e.jsx("td",{className:"mdocs-domain-table-num",children:i.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[f&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!f&&!N&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!f&&N&&s.changeTypeForId===i.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",children:[e.jsx("div",{className:"mdocs-domain-permission-select",children:ne.map(u=>e.jsx("button",{type:"button",className:i.permission===u?"active":"",onClick:()=>void s.handlePermissionChange(i.domainId,u),children:s.plabel(u)},u))}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>s.setChangeTypeForId(null),children:t("cancel")})]}),!f&&N&&s.renamingId!==i.domainId&&s.changeTypeForId!==i.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[e.jsx("button",{type:"button",className:"secondary",title:d?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(i)},disabled:d,children:t("rename")}),e.jsx("button",{type:"button",className:"secondary",title:d?j:void 0,onClick:()=>{s.setRenamingId(null),s.setChangeTypeForId(i.domainId)},disabled:d,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"secondary",title:d?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(i),disabled:d,children:t("deleteDomain")}),i.permission==="restricted"&&!f&&e.jsx("button",{type:"button",className:"secondary",onClick:()=>void C(i),children:t("domainMembersManageButton")})]})]})]},i.domainId)})})]})})]}),e.jsx(Se,{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:k,onClose:()=>y(null),onConfirm:async i=>{r&&(await cs(r.domainId,i),M({kind:"ok",text:t("domainMembersSaved",{count:String(i.length)})}))}})]})}function ye(t){return t.length<=6?t:`${t.slice(0,6)}…`}function Os(){const{t}=Z(),s=a.useRef(!0),[k,h]=a.useState([]),[g,M]=a.useState(!0),[r,y]=a.useState(null),[b,C]=a.useState(1),[i,N]=a.useState(null),[f,d]=a.useState(""),[j,u]=a.useState([]),[z,T]=a.useState(!1),[R,I]=a.useState(null),[A,B]=a.useState(!1),E=ve(),[x,P]=a.useState([]),[v,S]=a.useState("idle"),[l,c]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{S("loading"),rs().then(o=>{s.current&&(P(o),S("ok"))}).catch(()=>{s.current&&S("err")})},[]);const m=a.useMemo(()=>{const o=new Map;for(const L of x)o.set(L.visitorId,L.visitorName);return o},[x]),w=a.useCallback(async()=>{M(!0),I(null);try{const o=await we();s.current&&h(o)}catch(o){s.current&&I(_(t,o))}finally{s.current&&M(!1)}},[t]);a.useEffect(()=>{w()},[w]);const F=a.useMemo(()=>j.map(o=>{const L=x.find(W=>W.visitorId===o);return{visitorId:o,name:L?L.visitorName:t("visitorPickerUnknownVisitor"),muted:!L}}),[j,x,t]);function K(o){u(L=>L.includes(o)?L.filter(W=>W!==o):[...L,o])}const H=b===1?f.trim().length>0:b===2?j.length>0:!0;function q(){if(!(b>=3)){if(!H){B(!0);return}B(!1),C(b+1),c("")}}function G(){b<=1||(B(!1),C(b-1))}function D(){y(null),N(null),d(""),u(E?[E]:[]),I(null),C(1),c(""),B(!1)}function p(o){y(null),N(o.id),d(o.displayName);const L=E&&!o.visitorIds.includes(E)?[...o.visitorIds,E]:[...o.visitorIds];u(L),I(null),C(1),c(""),B(!1)}async function V(){if(!(!f.trim()||j.length===0)){T(!0),I(null);try{if(i===null?await os({displayName:f.trim(),visitorIds:j}):await ds(i,{displayName:f.trim(),visitorIds:j}),!s.current)return;D(),await w()}catch(o){if(!s.current)return;I(_(t,o))}finally{s.current&&T(!1)}}}async function $(o){T(!0),I(null);try{if(await ms(o),!s.current)return;y(null),i===o&&D(),await w()}catch(L){if(!s.current)return;I(_(t,L))}finally{s.current&&T(!1)}}const Q=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],ee=`${(b-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(i!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),i!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:D,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:ee}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:Q.map(o=>{const L=b===o.key,W=b>o.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${L?" current":""}${W?" done":""}`,children:W?"✓":o.key}),e.jsx("span",{className:`mdocs-wizard-step-label${L?" current":""}${W?" done":""}`,children:o.label})]},o.key)})})]}),R&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:R}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[b===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:f,onChange:o=>d(o.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:z,autoFocus:!0,"aria-invalid":A&&!f.trim()}),A&&!f.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),b===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Ms,{visitors:x,loadState:v,searchFilter:l,onSearchChange:c,selectedIds:new Set(j),onToggle:K,selectedRows:F,myVisitorId:E}),e.jsx("p",{className:`mdocs-wizard-hint${A&&j.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),b===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:f})]}),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(j.length)})})]}),j.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[j.slice(0,15).map(o=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:ye(o)},o)),j.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",j.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:G,children:["← ",t("memberTemplateWizardBack")]}),b<3?e.jsxs("button",{type:"button",className:"primary",onClick:q,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void V(),children:t(z?"saving":i===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),g?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):k.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),i===null&&e.jsx("button",{type:"button",className:"primary",onClick:D,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:k.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 $(o.id),children:t(z?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>y(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:m.get(L)??ye(L)},L))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>p(o),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>y(o.id),children:t("memberTemplateDelete")})]})]})},o.id))})]})]})]})}const Vs=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}];function Ks(){const{t}=Z(),s=a.useRef(!0),[k,h]=a.useState(""),[g,M]=a.useState(null),[r,y]=a.useState(""),[b,C]=a.useState("deepseek-v4-flash"),[i,N]=a.useState(128e3),[f,d]=a.useState(""),[j,u]=a.useState(!1),[z,T]=a.useState(null),[R,I]=a.useState(!0),[A,B]=a.useState(!1),[E,x]=a.useState(null),[P,v]=a.useState(!1),[S,l]=a.useState(!1),[c,m]=a.useState(!1),[w,F]=a.useState(null);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const[D,p]=await Promise.all([us(),hs()]);if(!s.current)return;h(D.visitorName),p?(M(p.id),y(p.name),C(p.modelId),N(p.contextWindow||128e3),u(p.hasApiKey),T(p.apiKeyMasked),l(!1)):l(!0)}catch(D){if(!s.current)return;x(D instanceof Error?D.message:String(D)),l(!0)}finally{s.current&&I(!1)}})()},[]);function K(){F({name:r,modelId:b,contextWindow:i}),d(""),m(!1),v(!1),x(null),l(!0)}function H(){w&&(y(w.name),C(w.modelId),N(w.contextWindow)),d(""),m(!1),x(null),v(!1),l(!1),F(null)}async function q(){B(!0),x(null),v(!1);try{const D={modelId:b,name:r,contextWindow:i};f.trim()&&(D.apiKey=f.trim());const p=await ps(D);if(!s.current)return;M(p.id),y(p.name),C(p.modelId),N(p.contextWindow||128e3),u(p.hasApiKey),T(p.apiKeyMasked),d(""),m(!1),v(!0),l(!1),F(null)}catch(D){if(!s.current)return;x(D instanceof Error?D.message:String(D))}finally{s.current&&B(!1)}}const G=t("agentConfigNameDefault").replace("{{name}}",k||"…");return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title mdocs-agent-config-title",children:[e.jsx("img",{src:gs,alt:"DeepSeek",className:"mdocs-agent-config-logo"}),t("agentConfig")]}),!R&&g&&!S?e.jsx("button",{type:"button",className:"secondary",onClick:K,children:t("edit")}):null]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("agentConfigDesc")}),R?e.jsx("p",{children:t("loading")}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-settings-item",style:{display:"block",marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigName")}),e.jsx("input",{type:"text",value:r,onChange:D=>y(D.target.value),placeholder:G,disabled:!S,style:{width:"100%",marginTop:6}})]}),e.jsxs("div",{className:"mdocs-settings-item mdocs-agent-config-field",style:{marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigModel")}),S?e.jsx("div",{className:"mdocs-agent-config-select",children:e.jsx(Ls,{options:Vs,value:b,onChange:D=>C(D)})}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:b})]}),e.jsxs("label",{className:"mdocs-settings-item",style:{display:"block",marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigContextWindow")}),e.jsx("p",{className:"mdocs-settings-item-desc",style:{margin:"4px 0 6px"},children:t("agentConfigContextWindowDesc")}),S?e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:i,onChange:D=>N(Number(D.target.value)||128e3),style:{width:"100%"}}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:i})]}),e.jsxs("div",{className:"mdocs-settings-item mdocs-agent-config-field",style:{marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigApiKey")}),S?e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:c?"text":"password",value:f,onChange:D=>d(D.target.value),placeholder:j?t("agentConfigApiKeyConfigured").replace("{{masked}}",z??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(c?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>m(D=>!D),children:c?e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M3 3l18 18"}),e.jsx("path",{d:"M10.6 10.6a2 2 0 002.8 2.8"}),e.jsx("path",{d:"M9.9 5.1A10.5 10.5 0 0121 12c-.6 1.1-1.4 2.1-2.4 2.9"}),e.jsx("path",{d:"M6.1 6.1C4.5 7.4 3.2 9.1 2.5 12c1.5 3.5 5 7 9.5 7 1.4 0 2.7-.3 3.9-.8"})]}):e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M2.5 12C4 8.5 7.5 5 12 5s8 3.5 9.5 7c-1.5 3.5-5 7-9.5 7s-8-3.5-9.5-7z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:j?z??"…":t("agentConfigApiKeyPlaceholder")})]}),g?e.jsxs("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:[t("agentConfigId"),": ",g]}):null,E?e.jsx("p",{style:{color:"var(--mdocs-danger, #c00)",marginBottom:12},children:E}):null,P&&!S?e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("saved")}):null,S?e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void q(),disabled:A,children:t(A?"saving":"save")}),g?e.jsx("button",{type:"button",className:"secondary",onClick:H,disabled:A,children:t("cancel")}):null]}):null]})]})})]})}const $s=/^[A-Za-z0-9_]+$/;function ie(t){return $s.test(t.trim())}function Ws(){const t=a.useRef(!0),[s,k]=a.useState([]),[h,g]=a.useState(!0),[M,r]=a.useState(null),[y,b]=a.useState(null),[C,i]=a.useState(!1),[N,f]=a.useState(""),[d,j]=a.useState(""),[u,z]=a.useState(""),[T,R]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function I(){g(!0),r(null);try{const l=await fs();if(!t.current)return;k(l)}catch(l){if(!t.current)return;r(l instanceof Error?l.message:String(l))}finally{t.current&&g(!1)}}a.useEffect(()=>{I()},[]);function A(){i(!0),b(null),f(""),j(""),z(""),r(null)}function B(l){i(!1),b(l.id),f(l.name),j(l.description),z(l.body),r(null)}function E(){i(!1),b(null),f(""),j(""),z("")}async function x(){const l=N.trim();if(!ie(l)){r("名称仅允许英文、数字、下划线");return}if(!u.trim()){r("正文不能为空");return}R(!0),r(null);try{if(C?await xs({name:l,description:d,body:u}):y&&await js(y,{name:l,description:d,body:u}),!t.current)return;E(),await I()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}finally{t.current&&R(!1)}}async function P(l){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){r(null);try{if(await Ns(l),!t.current)return;y===l&&E(),await I()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}}}const v=C||y!==null,S=!N.trim()||ie(N);return e.jsxs("div",{className:"mdocs-settings mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!h&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),v?null:e.jsx("button",{type:"button",className:"secondary",onClick:A,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),M?e.jsx("p",{className:"mdocs-agent-skills-error",children:M}):null,v?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:C?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:N,onChange:l=>f(l.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:S?void 0:"mdocs-agent-skills-input-invalid"}),S?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:d,onChange:l=>j(l.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:u,onChange:l=>z(l.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void x(),disabled:T||!S||!N.trim()||!u.trim(),children:T?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:E,disabled:T,children:"取消"})]})]}):null,h?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!h&&s.length===0&&!v?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:A,children:"新建第一个"})]}):null,!h&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(l=>{const c=ie(l.name),m=y===l.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(m?" 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:l.name}),c?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:l.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>B(l),disabled:v&&!m,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(l.id),disabled:v,children:"删除"})]})]},l.id)})}):null]})})]})}function be(t,s){const k=localStorage.getItem(t);return k===null?s:k==="true"}function Zs(t){const{t:s,lang:k,setLang:h}=Z(),{onBack:g,onPublishDraft:M}=t,r=a.useRef(!0);a.useEffect(()=>(r.current=!0,()=>{r.current=!1}),[]);const[y,b]=a.useState(()=>be("mdocs.autoPublish",!1)),[C,i]=a.useState(()=>be("mdocs.autoEdit",!0)),[N,f]=a.useState(!1),[d,j]=a.useState("general"),[u,z]=a.useState([]),[T,R]=a.useState(!0),[I,A]=a.useState(null),[B,E]=a.useState(!1),[x,P]=a.useState(!1),[v,S]=a.useState(!1),[l,c]=a.useState(!1),[m,w]=a.useState(null),[F,K]=a.useState(!1),[H,q]=a.useState(!1),[G,D]=a.useState(!1),[p,V]=a.useState(""),[$,Q]=a.useState(!1),[ee,o]=a.useState(!1),[L,W]=a.useState(0),[Ce,re]=a.useState([]),[De,oe]=a.useState(!1),[X,Ie]=a.useState(""),[Te,Ae]=a.useState([]),[Ee,de]=a.useState(!1),[Y,Pe]=a.useState(""),[Me,Le]=a.useState([]),[Re,se]=a.useState(!1),[te,me]=a.useState(null),[ae,ue]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(y))},[y]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(C))},[C]),a.useEffect(()=>{d==="savePublish"&&le().then(n=>{r.current&&W(n.filter(O=>!O.published).length)})},[d]),a.useEffect(()=>{d==="bookmarks"&&ze(),d==="myDocuments"&&pe()},[d]),a.useEffect(()=>{ge()},[]),a.useEffect(()=>{ke().then(n=>{r.current&&Le(n)}).catch(()=>{})},[]);const he=new Map(Me.map(n=>[n.domainId,n.domainName]));async function ge(){try{R(!0);const n=await ys();if(!r.current)return;z(n)}catch{}finally{r.current&&R(!1)}}async function ze(){try{oe(!0);const n=await bs();if(!r.current)return;re(n)}catch{}finally{r.current&&oe(!1)}}async function pe(){try{de(!0);const n=await vs();if(!r.current)return;Ae(n)}catch{}finally{r.current&&de(!1)}}async function Be(n){try{await Is(n),re(O=>O.filter(J=>J.documentId!==n))}catch{}}function Fe(){if(u.some(O=>!O.revoked)){P(!0);return}fe()}async function fe(){try{E(!0);const n=await As();A({token:n.token,name:n.name}),await ge()}finally{E(!1)}}async function Oe(){try{D(!0);const n=await Cs();w(n.recoveryCode)}finally{D(!1)}}async function Ve(n){n.preventDefault();const O=p.trim();if(!(O&&O.length<4))try{Q(!0),await Ds(O),V(""),o(!0),setTimeout(()=>o(!1),3e3)}finally{Q(!1)}}async function Ke(n){me(n);try{const O=await Ts(n),J=new Map;O.forEach(U=>{J.set(U.visitorId,U.permission)}),ue(J)}catch{ue(new Map)}se(!0)}async function $e(n){if(te)try{const O=new Set(n.map(U=>U.visitorId)),J=new Set(ae.keys());for(const U of J)O.has(U)||await Es(te,U);for(const U of n)await Ps(te,U.visitorId,U.permission);await pe()}finally{se(!1),me(null)}}const xe=Ce.filter(n=>{if(!X.trim())return!0;const O=X.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(O)||(n.ownerVisitorName||"").toLowerCase().includes(O)||(n.domainId||"").toLowerCase().includes(O)}),je=Te.filter(n=>{if(!Y.trim())return!0;const O=Y.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(O)||(n.domainId||"").toLowerCase().includes(O)});return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"mdocs-sidebar",children:[e.jsx("header",{className:"mdocs-sidebar-header",children:e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:ks,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]})}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(d==="general"?" active":""),onClick:()=>j("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(d==="bookmarks"?" active":""),onClick:()=>j("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(d==="myDocuments"?" active":""),onClick:()=>j("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(d==="domainManagement"?" active":""),onClick:()=>j("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(d==="memberTemplates"?" active":""),onClick:()=>j("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(d==="agentConfig"?" active":""),onClick:()=>j("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(d==="savePublish"?" active":""),onClick:()=>j("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:g,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[ws(),d==="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:k==="en"?"active":"",onClick:()=>h("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:k==="zh"?"active":"",onClick:()=>h("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"+(C?" active":""),role:"switch","aria-checked":C,onClick:()=>i(n=>!n),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")}),!T&&u.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:u.map(n=>e.jsxs("span",{style:{display:"block"},children:[n.name," — ",new Date(n.createdAt).toLocaleString()," ",n.revoked?`(${s("cliTokenRevoked")})`:`(${s("cliTokenActive")})`]},n.tokenId))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:Fe,disabled:B||T,children:B?"…":u.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),I&&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:I.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(I.token),c(!1),S(!0),window.setTimeout(()=>S(!1),2e3)}catch{S(!1),c(!0),window.setTimeout(()=>c(!1),3e3)}})()},children:s(v?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>A(null),children:s("close")})]}),v&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),l&&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:Oe,disabled:G,children:G?"…":"生成恢复码"})]}),m&&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:m})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(m),q(!1),K(!0),window.setTimeout(()=>K(!1),2e3)}catch{K(!1),q(!0),window.setTimeout(()=>q(!1),3e3)}})()},children:F?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>w(null),children:s("close")})]}),F&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),H&&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:Ve,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:p,onChange:n=>V(n.target.value),minLength:0,style:{marginBottom:8}}),ee&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:$,children:$?"设置中…":"保存密码"})]})]})]})]}):d==="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:X,onChange:n=>Ie(n.target.value)}),De?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:xe.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(X?"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:xe.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:n.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):he.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{children:new Date(n.bookmarkedAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Be(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})]})]}):d==="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:Y,onChange:n=>Pe(n.target.value)}),Ee?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:je.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(Y?"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:je.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:he.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:new Date(n.updatedAt).toLocaleDateString()}),e.jsx("td",{children:new Date(n.createdAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Ke(n.documentId),children:s("docInfoInviteMember")})}),e.jsx("td",{style:{textAlign:"right",paddingLeft:0},children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(n.documentId),children:s("bookmarkOpen")})})]},n.documentId))})]})})]})]}):d==="domainManagement"?e.jsx(Fs,{}):d==="memberTemplates"?e.jsx(Os,{}):d==="agentConfig"?e.jsxs(e.Fragment,{children:[e.jsx(Ks,{}),e.jsx(Ws,{})]}):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:g,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"+(y?" active":""),role:"switch","aria-checked":y,onClick:()=>b(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),L>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>f(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",L,")"]}),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")})})]})]}),N&&e.jsx(zs,{onPublish:M,onClose:()=>f(!1),onCountChange:W,onRecover:t.onRecoverDraft})]}),x&&e.jsx(Ss,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:B,onConfirm:()=>{P(!1),fe()},onCancel:()=>P(!1)}),e.jsx(Se,{open:Re,title:s("docInfoInviteMember"),initialSelectedIds:[...ae.keys()],initialPermissions:ae,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>se(!1),onConfirm:n=>{$e(n)}})]})}export{Zs as SettingsPage};
|
|
1
|
+
import{r as a,j as e}from"./react-vendor-BNpqFP9B.js";import{b as Z,q as We,s as Ue,D as _e,l as ce,t as He,v as qe,w as _,x as le,y as Ge,z as Ze,A as Je,a as Qe,d as Ne,B as ve,C as ke,E as Xe,G as Ye,H as es,I as ss,J as ts,K as we,L as ne,N as as,O as ns,P as is,Q as cs,R as ls,f as rs,T as os,U as ds,V as ms,W as us,X as hs,i as gs,Y as ps,Z as fs,_ as xs,$ as js,a0 as Ns,a1 as ys,a2 as bs,a3 as vs,a4 as ks,a5 as ws,a6 as Ss,a7 as Cs,a8 as Ds,r as Is,j as Ts,a9 as As,n as Es,o as Ps}from"./index-DOrcbEeP.js";import{V as Se,a as Ms,M as Ls}from"./VisitorPickerModal-D0i7oxrW.js";import"./ui-DxdLi_28.js";import"./motion-C4pN8CfU.js";function Rs({draft:t,onClose:s,onSuccess:k}){const{t:h,lang:g}=Z(),[M,r]=a.useState([]),[y,b]=a.useState(t.domainId??""),[C,i]=a.useState([]),[N,f]=a.useState(""),[d,j]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[u,z]=a.useState(!1),[T,R]=a.useState(null),I=a.useRef(null),A=a.useRef(!0);a.useEffect(()=>(A.current=!0,()=>{A.current=!1}),[]),a.useEffect(()=>{We().then(x=>{A.current&&r(x)})},[]),a.useEffect(()=>{y&&(i([]),f(""),Ue(y).then(x=>{A.current&&i(x)}).catch(()=>{A.current&&i([])}))},[y]),a.useEffect(()=>{const x=window.setTimeout(()=>{var P;return(P=I.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(x)},[]),a.useEffect(()=>{const x=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[s]);function B(x,P){for(const v of x){if(v.type==="folder"&&v.path===P)return v.documentId;if(v.type==="folder"){const S=B(v.children,P);if(S)return S}}return null}async function E(x){x.preventDefault(),z(!0),R(null);const P=d.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),v=P.endsWith(".md")?P:P+".md",S=v.replace(/\.md$/i,"");try{const l=N?`${N}/${v}`:v,c=N?B(C,N)??void 0:void 0;await qe({fileName:v,displayName:S,content:t.content,domainId:y,parentId:c}),k()}catch(l){R(_(h,l))}finally{z(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:x=>{x.target===x.currentTarget&&!u&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:h("recoverDraft")}),e.jsx("p",{className:"muted",children:h("recoverDraftDesc",{name:t.displayName||h("unknownTitle")})}),e.jsxs("form",{onSubmit:E,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[h("domainLabel"),M.length>0&&e.jsx(_e,{domains:M,value:y,onChange:b,onDomainsChange:r,ariaLabel:h("domainLabel"),localizeName:x=>ce(x,g,h)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[h("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(He,{nodes:C,activeDocumentId:null,selectedParentPath:N,onOpen:()=>{},onOpenFolder:x=>f(x),onContextMenu:()=>{},onDeselect:()=>f("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[h("fileNameLabel"),e.jsx("input",{ref:I,value:d,onChange:x=>j(x.target.value),placeholder:"recovered.md",maxLength:200,disabled:u})]}),T&&e.jsx("div",{className:"mdocs-dialog-error",children:T}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!u&&s(),disabled:u,children:h("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:u,children:h(u?"creating":"create")})]})]})]})})}function zs({onPublish:t,onClose:s,onCountChange:k,onRecover:h}){const{t:g}=Z(),[M,r]=a.useState([]),[y,b]=a.useState(new Set),[C,i]=a.useState(!1),[N,f]=a.useState(null),[d,j]=a.useState(null),[u,z]=a.useState(null),T=a.useRef(null),R=a.useRef(!0);a.useEffect(()=>(R.current=!0,le().then(c=>{if(!R.current)return;const m=c.filter(w=>!w.published);r(m),k==null||k(m.length)}),()=>{R.current=!1,T.current&&(clearTimeout(T.current),T.current=null)}),[]),a.useEffect(()=>{const c=m=>{m.key==="Escape"&&s()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s]);const I=a.useCallback((c,m)=>{z({message:c,type:m}),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>z(null),3e3)},[]);async function A(c){await Ze(c),b(m=>new Set(m).add(c));try{await t(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),I(g("published"),"success")}catch(m){m instanceof Je||I(g("publishFailed"),"error");const w=await Qe(c);w&&r(F=>F.map(K=>K.documentId===c?w:K))}finally{b(m=>{const w=new Set(m);return w.delete(c),w})}}async function B(c){f(null),await Ne(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),I(g("draftDeleted"),"success")}function E(c){const m=M.find(w=>w.documentId===c);m&&j(m)}function x(c){j(null),Ne(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),h==null||h(M.find(m=>m.documentId===c)),I(g("published"),"success")}async function P(){i(!0);let c=0,m=0;for(const K of M)try{await t(K.documentId),c++}catch{m++}const F=(await le()).filter(K=>!K.published);r(F),k==null||k(F.length),m===0?I(g("publishAll"),"success"):I(`${c} published, ${m} failed`,"error"),i(!1)}const v=c=>new Date(c).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),S=c=>Ge(g,c,c.publishError??"UNKNOWN"),l=M;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:[g("unpublishedDrafts"),l.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:l.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:g("draftCount",{count:String(l.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":g("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:l.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:g("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:l.map(c=>{const m=!!c.publishError;return e.jsxs("div",{className:m?"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||g("unknownTitle")}),m?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[v(c.publishErrorAt)," · ",S(c)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[v(c.updatedAt)," · ",g("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[m?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:C,onClick:()=>E(c.documentId),children:g("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:y.has(c.documentId)||C,onClick:()=>void A(c.documentId),children:y.has(c.documentId)?g("publishing"):g("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:C,onClick:()=>f(c.documentId),children:g("delete")})]})]},c.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:g("close")}),e.jsx("button",{type:"button",className:"primary",disabled:l.length===0||C,onClick:()=>void P(),children:C?g("publishing"):`${g("publishAll")} (${l.length})`})]}),u&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+u.type,role:"status",children:u.message})]}),N&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:c=>{c.target===c.currentTarget&&f(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:g("delete")}),e.jsx("p",{className:"muted",children:g("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>f(null),children:g("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void B(N),children:g("delete")})]})]})}),d&&e.jsx(Rs,{draft:d,onClose:()=>j(null),onSuccess:()=>x(d.documentId)})]})}function Bs(){const{t,lang:s}=Z(),k=ve(),h=a.useRef(!1),[g,M]=a.useState([]),[r,y]=a.useState(!1),[b,C]=a.useState(""),[i,N]=a.useState("restricted"),[f,d]=a.useState(!1),[j,u]=a.useState(null),[z,T]=a.useState(null),[R,I]=a.useState(""),[A,B]=a.useState(""),[E,x]=a.useState("all"),[P,v]=a.useState(null);a.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const S=a.useCallback(async()=>{y(!0),u(null);try{const p=await ke();if(!h.current)return;M(p)}catch(p){if(!h.current)return;u(_(t,p))}finally{h.current&&y(!1)}},[t]);a.useEffect(()=>{S()},[S]);async function l(p){if(p.preventDefault(),!b.trim()){u(t("domainNameRequired"));return}d(!0),u(null);try{if(await ts({domainName:b.trim(),permission:i}),!h.current)return;C(""),N("restricted"),await S()}catch(V){if(!h.current)return;u(_(t,V))}finally{h.current&&d(!1)}}async function c(p){if(R.trim()){u(null);try{if(await ss(p,R.trim()),!h.current)return;T(null),v(null),await S()}catch(V){if(!h.current)return;u(_(t,V))}}}function m(p){T(p.domainId),I(p.domainName),v(null)}function w(){T(null),v(null)}async function F(p,V){u(null);try{if(await es(p,V),!h.current)return;v(null),await S()}catch($){if(!h.current)return;u(_(t,$))}}async function K(p){if(window.confirm(t("deleteDomainConfirmDetail",{name:p.domainName,count:String(p.docCount)}))){u(null);try{if(await Ye(p.domainId),!h.current)return;await S()}catch(V){if(!h.current)return;u(_(t,V))}}}const H=a.useCallback(p=>Xe(p,t),[t]),q=a.useCallback(p=>ce(p.domainName,s,t),[s,t]),G=a.useMemo(()=>{const p=A.trim().toLowerCase();return g.filter(V=>E!=="all"&&V.permission!==E?!1:p?ce(V.domainName,s,t).toLowerCase().includes(p)||V.domainName.toLowerCase().includes(p):!0)},[g,A,E,s,t]),D=a.useCallback((p,V)=>{const $=H(p.permission);return V?`${$} ${t("domainTypeBuiltinSuffix")}`:$},[H,t]);return{domains:g,loadingDomains:r,domainError:j,newDomainName:b,setNewDomainName:C,newDomainPermission:i,setNewDomainPermission:N,creating:f,handleCreateDomain:l,renamingId:z,setRenamingId:T,renameDraft:R,setRenameDraft:I,startRename:m,cancelRename:w,handleRename:c,changeTypeForId:P,setChangeTypeForId:v,handlePermissionChange:F,handleDelete:K,domainSearch:A,setDomainSearch:B,domainFilter:E,setDomainFilter:x,filteredDomains:G,visitorId:k,plabel:H,localizeDomain:q,domainTypeLabel:D}}function Fs(){const{t}=Z(),s=Bs(),[k,h]=a.useState([]),[g,M]=a.useState(null),[r,y]=a.useState(null),b=a.useCallback(async()=>{try{const i=await we();h(i)}catch{h([])}},[]);a.useEffect(()=>{b()},[b]);async function C(i){M(null);try{const N=await ls(i.domainId);y({domainId:i.domainId,creatorVisitorId:i.creatorVisitorId,initialIds:N.map(f=>f.visitorId),memberRows:N})}catch(N){M({kind:"err",text:_(t,N)})}}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:i=>s.setNewDomainName(i.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:ne.map(i=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===i,onChange:()=>s.setNewDomainPermission(i),disabled:s.creating}),e.jsx("span",{children:s.plabel(i)})]},i))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?t("creating"):t("create")})]})]}),g&&e.jsx("div",{className:"mdocs-settings-card",style:{color:g.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:g.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:i=>s.setDomainSearch(i.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",...ne].map(i=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===i?" active":""),"aria-pressed":s.domainFilter===i,onClick:()=>s.setDomainFilter(i),children:i==="all"?t("domainFilterAll"):s.plabel(i)},i))})]}),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(i=>{const N=as(i,s.visitorId),f=ns(i.domainId),d=is(i),j=d?t("domainTooltipTypeLocked",{count:String(i.docCount)}):void 0;return e.jsxs("tr",{className:f?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===i.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:u=>s.setRenameDraft(u.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(i.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(i)}),f&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!N&&!f&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsxs("span",{className:"mdocs-domain-table-type",title:j,children:[e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":i.permission,children:s.domainTypeLabel(i,f)}),d&&!f&&e.jsx("span",{className:"mdocs-domain-type-lock","aria-hidden":"true",children:"🔒"})]})}),e.jsx("td",{className:"mdocs-domain-table-num",children:i.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[f&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!f&&!N&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!f&&N&&s.changeTypeForId===i.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",children:[e.jsx("div",{className:"mdocs-domain-permission-select",children:ne.map(u=>e.jsx("button",{type:"button",className:i.permission===u?"active":"",onClick:()=>void s.handlePermissionChange(i.domainId,u),children:s.plabel(u)},u))}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>s.setChangeTypeForId(null),children:t("cancel")})]}),!f&&N&&s.renamingId!==i.domainId&&s.changeTypeForId!==i.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[e.jsx("button",{type:"button",className:"secondary",title:d?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(i)},disabled:d,children:t("rename")}),e.jsx("button",{type:"button",className:"secondary",title:d?j:void 0,onClick:()=>{s.setRenamingId(null),s.setChangeTypeForId(i.domainId)},disabled:d,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"secondary",title:d?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(i),disabled:d,children:t("deleteDomain")}),i.permission==="restricted"&&!f&&e.jsx("button",{type:"button",className:"secondary",onClick:()=>void C(i),children:t("domainMembersManageButton")})]})]})]},i.domainId)})})]})})]}),e.jsx(Se,{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:k,onClose:()=>y(null),onConfirm:async i=>{r&&(await cs(r.domainId,i),M({kind:"ok",text:t("domainMembersSaved",{count:String(i.length)})}))}})]})}function ye(t){return t.length<=6?t:`${t.slice(0,6)}…`}function Os(){const{t}=Z(),s=a.useRef(!0),[k,h]=a.useState([]),[g,M]=a.useState(!0),[r,y]=a.useState(null),[b,C]=a.useState(1),[i,N]=a.useState(null),[f,d]=a.useState(""),[j,u]=a.useState([]),[z,T]=a.useState(!1),[R,I]=a.useState(null),[A,B]=a.useState(!1),E=ve(),[x,P]=a.useState([]),[v,S]=a.useState("idle"),[l,c]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{S("loading"),rs().then(o=>{s.current&&(P(o),S("ok"))}).catch(()=>{s.current&&S("err")})},[]);const m=a.useMemo(()=>{const o=new Map;for(const L of x)o.set(L.visitorId,L.visitorName);return o},[x]),w=a.useCallback(async()=>{M(!0),I(null);try{const o=await we();s.current&&h(o)}catch(o){s.current&&I(_(t,o))}finally{s.current&&M(!1)}},[t]);a.useEffect(()=>{w()},[w]);const F=a.useMemo(()=>j.map(o=>{const L=x.find(W=>W.visitorId===o);return{visitorId:o,name:L?L.visitorName:t("visitorPickerUnknownVisitor"),muted:!L}}),[j,x,t]);function K(o){u(L=>L.includes(o)?L.filter(W=>W!==o):[...L,o])}const H=b===1?f.trim().length>0:b===2?j.length>0:!0;function q(){if(!(b>=3)){if(!H){B(!0);return}B(!1),C(b+1),c("")}}function G(){b<=1||(B(!1),C(b-1))}function D(){y(null),N(null),d(""),u(E?[E]:[]),I(null),C(1),c(""),B(!1)}function p(o){y(null),N(o.id),d(o.displayName);const L=E&&!o.visitorIds.includes(E)?[...o.visitorIds,E]:[...o.visitorIds];u(L),I(null),C(1),c(""),B(!1)}async function V(){if(!(!f.trim()||j.length===0)){T(!0),I(null);try{if(i===null?await os({displayName:f.trim(),visitorIds:j}):await ds(i,{displayName:f.trim(),visitorIds:j}),!s.current)return;D(),await w()}catch(o){if(!s.current)return;I(_(t,o))}finally{s.current&&T(!1)}}}async function $(o){T(!0),I(null);try{if(await ms(o),!s.current)return;y(null),i===o&&D(),await w()}catch(L){if(!s.current)return;I(_(t,L))}finally{s.current&&T(!1)}}const Q=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],ee=`${(b-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(i!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),i!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:D,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:ee}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:Q.map(o=>{const L=b===o.key,W=b>o.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${L?" current":""}${W?" done":""}`,children:W?"✓":o.key}),e.jsx("span",{className:`mdocs-wizard-step-label${L?" current":""}${W?" done":""}`,children:o.label})]},o.key)})})]}),R&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:R}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[b===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:f,onChange:o=>d(o.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:z,autoFocus:!0,"aria-invalid":A&&!f.trim()}),A&&!f.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),b===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Ms,{visitors:x,loadState:v,searchFilter:l,onSearchChange:c,selectedIds:new Set(j),onToggle:K,selectedRows:F,myVisitorId:E}),e.jsx("p",{className:`mdocs-wizard-hint${A&&j.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),b===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:f})]}),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(j.length)})})]}),j.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[j.slice(0,15).map(o=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:ye(o)},o)),j.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",j.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:G,children:["← ",t("memberTemplateWizardBack")]}),b<3?e.jsxs("button",{type:"button",className:"primary",onClick:q,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void V(),children:t(z?"saving":i===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),g?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):k.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),i===null&&e.jsx("button",{type:"button",className:"primary",onClick:D,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:k.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 $(o.id),children:t(z?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>y(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:m.get(L)??ye(L)},L))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>p(o),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>y(o.id),children:t("memberTemplateDelete")})]})]})},o.id))})]})]})]})}const Vs=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}];function Ks(){const{t}=Z(),s=a.useRef(!0),[k,h]=a.useState(""),[g,M]=a.useState(null),[r,y]=a.useState(""),[b,C]=a.useState("deepseek-v4-flash"),[i,N]=a.useState(128e3),[f,d]=a.useState(""),[j,u]=a.useState(!1),[z,T]=a.useState(null),[R,I]=a.useState(!0),[A,B]=a.useState(!1),[E,x]=a.useState(null),[P,v]=a.useState(!1),[S,l]=a.useState(!1),[c,m]=a.useState(!1),[w,F]=a.useState(null);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const[D,p]=await Promise.all([us(),hs()]);if(!s.current)return;h(D.visitorName),p?(M(p.id),y(p.name),C(p.modelId),N(p.contextWindow||128e3),u(p.hasApiKey),T(p.apiKeyMasked),l(!1)):l(!0)}catch(D){if(!s.current)return;x(D instanceof Error?D.message:String(D)),l(!0)}finally{s.current&&I(!1)}})()},[]);function K(){F({name:r,modelId:b,contextWindow:i}),d(""),m(!1),v(!1),x(null),l(!0)}function H(){w&&(y(w.name),C(w.modelId),N(w.contextWindow)),d(""),m(!1),x(null),v(!1),l(!1),F(null)}async function q(){B(!0),x(null),v(!1);try{const D={modelId:b,name:r,contextWindow:i};f.trim()&&(D.apiKey=f.trim());const p=await ps(D);if(!s.current)return;M(p.id),y(p.name),C(p.modelId),N(p.contextWindow||128e3),u(p.hasApiKey),T(p.apiKeyMasked),d(""),m(!1),v(!0),l(!1),F(null)}catch(D){if(!s.current)return;x(D instanceof Error?D.message:String(D))}finally{s.current&&B(!1)}}const G=t("agentConfigNameDefault").replace("{{name}}",k||"…");return e.jsxs("div",{className:"mdocs-agent-config-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title mdocs-agent-config-title",children:[e.jsx("img",{src:gs,alt:"DeepSeek",className:"mdocs-agent-config-logo"}),t("agentConfig")]}),!R&&g&&!S?e.jsx("button",{type:"button",className:"secondary",onClick:K,children:t("edit")}):null]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("agentConfigDesc")}),R?e.jsx("p",{children:t("loading")}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-settings-item",style:{display:"block",marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigName")}),e.jsx("input",{type:"text",value:r,onChange:D=>y(D.target.value),placeholder:G,disabled:!S,style:{width:"100%",marginTop:6}})]}),e.jsxs("div",{className:"mdocs-settings-item mdocs-agent-config-field",style:{marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigModel")}),S?e.jsx("div",{className:"mdocs-agent-config-select",children:e.jsx(Ls,{options:Vs,value:b,onChange:D=>C(D)})}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:b})]}),e.jsxs("label",{className:"mdocs-settings-item",style:{display:"block",marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigContextWindow")}),e.jsx("p",{className:"mdocs-settings-item-desc",style:{margin:"4px 0 6px"},children:t("agentConfigContextWindowDesc")}),S?e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:i,onChange:D=>N(Number(D.target.value)||128e3),style:{width:"100%"}}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:i})]}),e.jsxs("div",{className:"mdocs-settings-item mdocs-agent-config-field",style:{marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigApiKey")}),S?e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:c?"text":"password",value:f,onChange:D=>d(D.target.value),placeholder:j?t("agentConfigApiKeyConfigured").replace("{{masked}}",z??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(c?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>m(D=>!D),children:c?e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M3 3l18 18"}),e.jsx("path",{d:"M10.6 10.6a2 2 0 002.8 2.8"}),e.jsx("path",{d:"M9.9 5.1A10.5 10.5 0 0121 12c-.6 1.1-1.4 2.1-2.4 2.9"}),e.jsx("path",{d:"M6.1 6.1C4.5 7.4 3.2 9.1 2.5 12c1.5 3.5 5 7 9.5 7 1.4 0 2.7-.3 3.9-.8"})]}):e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M2.5 12C4 8.5 7.5 5 12 5s8 3.5 9.5 7c-1.5 3.5-5 7-9.5 7s-8-3.5-9.5-7z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:j?z??"…":t("agentConfigApiKeyPlaceholder")})]}),g?e.jsxs("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:[t("agentConfigId"),": ",g]}):null,E?e.jsx("p",{style:{color:"var(--mdocs-danger, #c00)",marginBottom:12},children:E}):null,P&&!S?e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("saved")}):null,S?e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void q(),disabled:A,children:t(A?"saving":"save")}),g?e.jsx("button",{type:"button",className:"secondary",onClick:H,disabled:A,children:t("cancel")}):null]}):null]})]})})]})}const $s=/^[A-Za-z0-9_]+$/;function ie(t){return $s.test(t.trim())}function Ws(){const t=a.useRef(!0),[s,k]=a.useState([]),[h,g]=a.useState(!0),[M,r]=a.useState(null),[y,b]=a.useState(null),[C,i]=a.useState(!1),[N,f]=a.useState(""),[d,j]=a.useState(""),[u,z]=a.useState(""),[T,R]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function I(){g(!0),r(null);try{const l=await fs();if(!t.current)return;k(l)}catch(l){if(!t.current)return;r(l instanceof Error?l.message:String(l))}finally{t.current&&g(!1)}}a.useEffect(()=>{I()},[]);function A(){i(!0),b(null),f(""),j(""),z(""),r(null)}function B(l){i(!1),b(l.id),f(l.name),j(l.description),z(l.body),r(null)}function E(){i(!1),b(null),f(""),j(""),z("")}async function x(){const l=N.trim();if(!ie(l)){r("名称仅允许英文、数字、下划线");return}if(!u.trim()){r("正文不能为空");return}R(!0),r(null);try{if(C?await xs({name:l,description:d,body:u}):y&&await js(y,{name:l,description:d,body:u}),!t.current)return;E(),await I()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}finally{t.current&&R(!1)}}async function P(l){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){r(null);try{if(await Ns(l),!t.current)return;y===l&&E(),await I()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}}}const v=C||y!==null,S=!N.trim()||ie(N);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",!h&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),v?null:e.jsx("button",{type:"button",className:"secondary",onClick:A,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),M?e.jsx("p",{className:"mdocs-agent-skills-error",children:M}):null,v?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:C?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:N,onChange:l=>f(l.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:S?void 0:"mdocs-agent-skills-input-invalid"}),S?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:d,onChange:l=>j(l.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:u,onChange:l=>z(l.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void x(),disabled:T||!S||!N.trim()||!u.trim(),children:T?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:E,disabled:T,children:"取消"})]})]}):null,h?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!h&&s.length===0&&!v?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:A,children:"新建第一个"})]}):null,!h&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(l=>{const c=ie(l.name),m=y===l.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(m?" 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:l.name}),c?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:l.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>B(l),disabled:v&&!m,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(l.id),disabled:v,children:"删除"})]})]},l.id)})}):null]})})]})}function be(t,s){const k=localStorage.getItem(t);return k===null?s:k==="true"}function Zs(t){const{t:s,lang:k,setLang:h}=Z(),{onBack:g,onPublishDraft:M}=t,r=a.useRef(!0);a.useEffect(()=>(r.current=!0,()=>{r.current=!1}),[]);const[y,b]=a.useState(()=>be("mdocs.autoPublish",!1)),[C,i]=a.useState(()=>be("mdocs.autoEdit",!0)),[N,f]=a.useState(!1),[d,j]=a.useState("general"),[u,z]=a.useState([]),[T,R]=a.useState(!0),[I,A]=a.useState(null),[B,E]=a.useState(!1),[x,P]=a.useState(!1),[v,S]=a.useState(!1),[l,c]=a.useState(!1),[m,w]=a.useState(null),[F,K]=a.useState(!1),[H,q]=a.useState(!1),[G,D]=a.useState(!1),[p,V]=a.useState(""),[$,Q]=a.useState(!1),[ee,o]=a.useState(!1),[L,W]=a.useState(0),[Ce,re]=a.useState([]),[De,oe]=a.useState(!1),[X,Ie]=a.useState(""),[Te,Ae]=a.useState([]),[Ee,de]=a.useState(!1),[Y,Pe]=a.useState(""),[Me,Le]=a.useState([]),[Re,se]=a.useState(!1),[te,me]=a.useState(null),[ae,ue]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(y))},[y]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(C))},[C]),a.useEffect(()=>{d==="savePublish"&&le().then(n=>{r.current&&W(n.filter(O=>!O.published).length)})},[d]),a.useEffect(()=>{d==="bookmarks"&&ze(),d==="myDocuments"&&pe()},[d]),a.useEffect(()=>{ge()},[]),a.useEffect(()=>{ke().then(n=>{r.current&&Le(n)}).catch(()=>{})},[]);const he=new Map(Me.map(n=>[n.domainId,n.domainName]));async function ge(){try{R(!0);const n=await ys();if(!r.current)return;z(n)}catch{}finally{r.current&&R(!1)}}async function ze(){try{oe(!0);const n=await bs();if(!r.current)return;re(n)}catch{}finally{r.current&&oe(!1)}}async function pe(){try{de(!0);const n=await vs();if(!r.current)return;Ae(n)}catch{}finally{r.current&&de(!1)}}async function Be(n){try{await Is(n),re(O=>O.filter(J=>J.documentId!==n))}catch{}}function Fe(){if(u.some(O=>!O.revoked)){P(!0);return}fe()}async function fe(){try{E(!0);const n=await As();A({token:n.token,name:n.name}),await ge()}finally{E(!1)}}async function Oe(){try{D(!0);const n=await Cs();w(n.recoveryCode)}finally{D(!1)}}async function Ve(n){n.preventDefault();const O=p.trim();if(!(O&&O.length<4))try{Q(!0),await Ds(O),V(""),o(!0),setTimeout(()=>o(!1),3e3)}finally{Q(!1)}}async function Ke(n){me(n);try{const O=await Ts(n),J=new Map;O.forEach(U=>{J.set(U.visitorId,U.permission)}),ue(J)}catch{ue(new Map)}se(!0)}async function $e(n){if(te)try{const O=new Set(n.map(U=>U.visitorId)),J=new Set(ae.keys());for(const U of J)O.has(U)||await Es(te,U);for(const U of n)await Ps(te,U.visitorId,U.permission);await pe()}finally{se(!1),me(null)}}const xe=Ce.filter(n=>{if(!X.trim())return!0;const O=X.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(O)||(n.ownerVisitorName||"").toLowerCase().includes(O)||(n.domainId||"").toLowerCase().includes(O)}),je=Te.filter(n=>{if(!Y.trim())return!0;const O=Y.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(O)||(n.domainId||"").toLowerCase().includes(O)});return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"mdocs-sidebar",children:[e.jsx("header",{className:"mdocs-sidebar-header",children:e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:ks,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]})}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(d==="general"?" active":""),onClick:()=>j("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(d==="bookmarks"?" active":""),onClick:()=>j("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(d==="myDocuments"?" active":""),onClick:()=>j("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(d==="domainManagement"?" active":""),onClick:()=>j("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(d==="memberTemplates"?" active":""),onClick:()=>j("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(d==="agentConfig"?" active":""),onClick:()=>j("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(d==="savePublish"?" active":""),onClick:()=>j("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:g,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[ws(),d==="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:k==="en"?"active":"",onClick:()=>h("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:k==="zh"?"active":"",onClick:()=>h("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"+(C?" active":""),role:"switch","aria-checked":C,onClick:()=>i(n=>!n),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")}),!T&&u.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:u.map(n=>e.jsxs("span",{style:{display:"block"},children:[n.name," — ",new Date(n.createdAt).toLocaleString()," ",n.revoked?`(${s("cliTokenRevoked")})`:`(${s("cliTokenActive")})`]},n.tokenId))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:Fe,disabled:B||T,children:B?"…":u.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),I&&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:I.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(I.token),c(!1),S(!0),window.setTimeout(()=>S(!1),2e3)}catch{S(!1),c(!0),window.setTimeout(()=>c(!1),3e3)}})()},children:s(v?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>A(null),children:s("close")})]}),v&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),l&&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:Oe,disabled:G,children:G?"…":"生成恢复码"})]}),m&&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:m})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(m),q(!1),K(!0),window.setTimeout(()=>K(!1),2e3)}catch{K(!1),q(!0),window.setTimeout(()=>q(!1),3e3)}})()},children:F?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>w(null),children:s("close")})]}),F&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),H&&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:Ve,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:p,onChange:n=>V(n.target.value),minLength:0,style:{marginBottom:8}}),ee&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:$,children:$?"设置中…":"保存密码"})]})]})]})]}):d==="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:X,onChange:n=>Ie(n.target.value)}),De?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:xe.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(X?"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:xe.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:n.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):he.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{children:new Date(n.bookmarkedAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Be(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})]})]}):d==="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:Y,onChange:n=>Pe(n.target.value)}),Ee?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:je.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(Y?"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:je.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:he.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:new Date(n.updatedAt).toLocaleDateString()}),e.jsx("td",{children:new Date(n.createdAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Ke(n.documentId),children:s("docInfoInviteMember")})}),e.jsx("td",{style:{textAlign:"right",paddingLeft:0},children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(n.documentId),children:s("bookmarkOpen")})})]},n.documentId))})]})})]})]}):d==="domainManagement"?e.jsx(Fs,{}):d==="memberTemplates"?e.jsx(Os,{}):d==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Ks,{}),e.jsx(Ws,{})]}):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:g,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"+(y?" active":""),role:"switch","aria-checked":y,onClick:()=>b(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),L>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>f(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",L,")"]}),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")})})]})]}),N&&e.jsx(zs,{onPublish:M,onClose:()=>f(!1),onCountChange:W,onRecover:t.onRecoverDraft})]}),x&&e.jsx(Ss,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:B,onConfirm:()=>{P(!1),fe()},onCancel:()=>P(!1)}),e.jsx(Se,{open:Re,title:s("docInfoInviteMember"),initialSelectedIds:[...ae.keys()],initialPermissions:ae,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>se(!1),onConfirm:n=>{$e(n)}})]})}export{Zs as SettingsPage};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as o}from"./index-
|
|
1
|
+
import{c as o}from"./index-DOrcbEeP.js";import{r as u,j as r}from"./react-vendor-BNpqFP9B.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 w}from"./react-DedaIFYc.js";import{z as g,V as b}from"./editor-ONzd_YnO.js";/**
|
|
2
2
|
* @license lucide-react v0.562.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r,j as e}from"./react-vendor-BNpqFP9B.js";import{b as G,B as ee,f as se,w as z}from"./index-B-XJ-ScV.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-BNpqFP9B.js";import{b as G,B as ee,f as se,w as z}from"./index-DOrcbEeP.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};
|