@fgbg/mdocs 0.8.21 → 0.8.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +17 -1
  3. package/agent-skills/index.json +1 -1
  4. package/bin/mdocs.js +1 -1
  5. package/dist/server/cli/main.js +22 -1
  6. package/dist/server/cli/main.js.map +1 -1
  7. package/dist/server/cli/self-update.js +4 -0
  8. package/dist/server/cli/self-update.js.map +1 -1
  9. package/dist/server/documents/tree-and-folders.test.js +54 -3
  10. package/dist/server/documents/tree-and-folders.test.js.map +1 -1
  11. package/dist/server/documents/tree.service.js +66 -5
  12. package/dist/server/documents/tree.service.js.map +1 -1
  13. package/dist/server/routes/documents.routes.js +16 -0
  14. package/dist/server/routes/documents.routes.js.map +1 -1
  15. package/dist/web/assets/{AgentChatPanel-D95hI02c.js → AgentChatPanel-CtdLYtSw.js} +1 -1
  16. package/dist/web/assets/{AgentSkillFormCard-BtJ0QjLG.js → AgentSkillFormCard-DeZnOTQg.js} +2 -2
  17. package/dist/web/assets/AiWriteWorkbench-hUYjin2m.js +7 -0
  18. package/dist/web/assets/DiagramEditor-NtNY3sZL-C9hL71kf.js +2 -0
  19. package/dist/web/assets/DocumentEditor-BmmnuieO.js +21 -0
  20. package/dist/web/assets/{MergeView-DgFQHD5_.js → MergeView-CjhCBNPa.js} +1 -1
  21. package/dist/web/assets/{PlaygroundPage-Dg57Xxpl.js → PlaygroundPage-CgaNgQEp.js} +1 -1
  22. package/dist/web/assets/SettingsPage-Fl5Tu7u3.js +1 -0
  23. package/dist/web/assets/{Toolbar-0Y2wmGwe.js → Toolbar-BaKuyXey.js} +1 -1
  24. package/dist/web/assets/{VisitorPickerModal-COxtOvc4.js → VisitorPickerModal-DPyg6mIt.js} +1 -1
  25. package/dist/web/assets/{copy-nOl0d3Th.js → copy-UkvgEfIg.js} +1 -1
  26. package/dist/web/assets/diagram-BLCqfrbF.js +6257 -0
  27. package/dist/web/assets/index-Ct5Vt4tz.js +185 -0
  28. package/dist/web/assets/index-Dt_PAYaR.css +1 -0
  29. package/dist/web/assets/meta2d-D3b5RRN8.js +110 -0
  30. package/dist/web/assets/{meta2dEngine-BD2XbzaV-e28q005B.js → meta2dEngine-BD2XbzaV-2ovN6JHu.js} +1 -1
  31. package/dist/web/assets/{motion-D-I76zAi.js → motion-Bz_inm1R.js} +1 -1
  32. package/dist/web/assets/{plus-DvBbg6jL.js → plus-B-uEAM2g.js} +1 -1
  33. package/dist/web/assets/react-6CQL39Gs.js +2382 -0
  34. package/dist/web/assets/react-vendor-BJFXgntS.js +242 -0
  35. package/dist/web/assets/{ui-C3xtW1w8.js → ui-TwLH91RV.js} +133 -133
  36. package/dist/web/index.html +5 -5
  37. package/package.json +2 -2
  38. package/dist/web/assets/AiWriteWorkbench-Qam8cfY6.js +0 -6
  39. package/dist/web/assets/DiagramEditor-BTRe45TX-Did98cnP.js +0 -2
  40. package/dist/web/assets/DocumentEditor-DtSzkl6A.js +0 -21
  41. package/dist/web/assets/SettingsPage-CkYpe5v7.js +0 -1
  42. package/dist/web/assets/diagram-BJFhx-27.js +0 -3016
  43. package/dist/web/assets/index-B-XJ-ScV.js +0 -185
  44. package/dist/web/assets/index-CGvsjO9f.css +0 -1
  45. package/dist/web/assets/meta2d-C8Z4cn-d.js +0 -110
  46. package/dist/web/assets/react-BsVOIHR8.js +0 -2126
  47. package/dist/web/assets/react-vendor-BNpqFP9B.js +0 -242
@@ -0,0 +1 @@
1
+ import{r as a,j as e}from"./react-vendor-BJFXgntS.js";import{b as Z,q as Ge,s as Ze,D as Je,l as ce,t as Qe,v as Xe,w as H,x as le,y as Ye,z as es,A as ss,a as ts,d as ke,B as Ce,C as De,E as as,G as ns,H as is,I as cs,J as ls,K as Ie,L as ne,N as rs,O as os,Q as ds,R as ms,T as us,f as hs,U as gs,V as ps,W as fs,X as xs,Y as js,i as bs,Z as Ns,_ as ys,$ as vs,a0 as ks,a1 as ws,a2 as Ss,a3 as Cs,a4 as Ds,a5 as Is,a6 as Ts,a7 as As,P as Es,a8 as Ps,a9 as Ms,aa as Ls,ab as Rs,r as zs,j as Bs,ac as Fs,n as Os,o as Vs}from"./index-Ct5Vt4tz.js";import{V as Te,a as Ks,M as $s}from"./VisitorPickerModal-DPyg6mIt.js";import"./ui-TwLH91RV.js";import"./motion-Bz_inm1R.js";function Ws({draft:t,onClose:s,onSuccess:v}){const{t:u,lang:h}=Z(),[R,o]=a.useState([]),[k,j]=a.useState(t.domainId??""),[b,i]=a.useState([]),[N,g]=a.useState(""),[C,w]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[p,f]=a.useState(!1),[A,E]=a.useState(null),T=a.useRef(null),P=a.useRef(!0);a.useEffect(()=>(P.current=!0,()=>{P.current=!1}),[]),a.useEffect(()=>{Ge().then(x=>{P.current&&o(x)})},[]),a.useEffect(()=>{k&&(i([]),g(""),Ze(k).then(x=>{P.current&&i(x)}).catch(()=>{P.current&&i([])}))},[k]),a.useEffect(()=>{const x=window.setTimeout(()=>{var L;return(L=T.current)==null?void 0:L.focus()},0);return()=>window.clearTimeout(x)},[]),a.useEffect(()=>{const x=L=>{L.key==="Escape"&&s()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[s]);function O(x,L){for(const y of x){if(y.type==="folder"&&y.path===L)return y.documentId;if(y.type==="folder"){const D=O(y.children,L);if(D)return D}}return null}async function M(x){x.preventDefault(),f(!0),E(null);const L=C.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),y=L.endsWith(".md")?L:L+".md",D=y.replace(/\.md$/i,"");try{const l=N?`${N}/${y}`:y,c=N?O(b,N)??void 0:void 0;await Xe({fileName:y,displayName:D,content:t.content,domainId:k,parentId:c}),v()}catch(l){E(H(u,l))}finally{f(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:x=>{x.target===x.currentTarget&&!p&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:u("recoverDraft")}),e.jsx("p",{className:"muted",children:u("recoverDraftDesc",{name:t.displayName||u("unknownTitle")})}),e.jsxs("form",{onSubmit:M,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[u("domainLabel"),R.length>0&&e.jsx(Je,{domains:R,value:k,onChange:j,onDomainsChange:o,ariaLabel:u("domainLabel"),localizeName:x=>ce(x,h,u)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[u("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(Qe,{nodes:b,activeDocumentId:null,selectedParentPath:N,onOpen:()=>{},onOpenFolder:x=>g(x),onContextMenu:()=>{},onDeselect:()=>g("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[u("fileNameLabel"),e.jsx("input",{ref:T,value:C,onChange:x=>w(x.target.value),placeholder:"recovered.md",maxLength:200,disabled:p})]}),A&&e.jsx("div",{className:"mdocs-dialog-error",children:A}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!p&&s(),disabled:p,children:u("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:p,children:u(p?"creating":"create")})]})]})]})})}function Us({onPublish:t,onClose:s,onCountChange:v,onRecover:u}){const{t:h}=Z(),[R,o]=a.useState([]),[k,j]=a.useState(new Set),[b,i]=a.useState(!1),[N,g]=a.useState(null),[C,w]=a.useState(null),[p,f]=a.useState(null),A=a.useRef(null),E=a.useRef(!0);a.useEffect(()=>(E.current=!0,le().then(c=>{if(!E.current)return;const d=c.filter(S=>!S.published);o(d),v==null||v(d.length)}),()=>{E.current=!1,A.current&&(clearTimeout(A.current),A.current=null)}),[]),a.useEffect(()=>{const c=d=>{d.key==="Escape"&&s()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s]);const T=a.useCallback((c,d)=>{f({message:c,type:d}),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>f(null),3e3)},[]);async function P(c){await es(c),j(d=>new Set(d).add(c));try{await t(c),o(d=>{const S=d.filter(B=>B.documentId!==c);return v==null||v(S.length),S}),T(h("published"),"success")}catch(d){d instanceof ss||T(h("publishFailed"),"error");const S=await ts(c);S&&o(B=>B.map(K=>K.documentId===c?S:K))}finally{j(d=>{const S=new Set(d);return S.delete(c),S})}}async function O(c){g(null),await ke(c),o(d=>{const S=d.filter(B=>B.documentId!==c);return v==null||v(S.length),S}),T(h("draftDeleted"),"success")}function M(c){const d=R.find(S=>S.documentId===c);d&&w(d)}function x(c){w(null),ke(c),o(d=>{const S=d.filter(B=>B.documentId!==c);return v==null||v(S.length),S}),u==null||u(R.find(d=>d.documentId===c)),T(h("published"),"success")}async function L(){i(!0);let c=0,d=0;for(const K of R)try{await t(K.documentId),c++}catch{d++}const B=(await le()).filter(K=>!K.published);o(B),v==null||v(B.length),d===0?T(h("publishAll"),"success"):T(`${c} published, ${d} failed`,"error"),i(!1)}const y=c=>new Date(c).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),D=c=>Ye(h,c,c.publishError??"UNKNOWN"),l=R;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:[h("unpublishedDrafts"),l.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:l.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:h("draftCount",{count:String(l.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":h("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:h("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:l.map(c=>{const d=!!c.publishError;return e.jsxs("div",{className:d?"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||h("unknownTitle")}),d?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[y(c.publishErrorAt)," · ",D(c)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[y(c.updatedAt)," · ",h("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[d?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:b,onClick:()=>M(c.documentId),children:h("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:k.has(c.documentId)||b,onClick:()=>void P(c.documentId),children:k.has(c.documentId)?h("publishing"):h("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:b,onClick:()=>g(c.documentId),children:h("delete")})]})]},c.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:h("close")}),e.jsx("button",{type:"button",className:"primary",disabled:l.length===0||b,onClick:()=>void L(),children:b?h("publishing"):`${h("publishAll")} (${l.length})`})]}),p&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+p.type,role:"status",children:p.message})]}),N&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:c=>{c.target===c.currentTarget&&g(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:h("delete")}),e.jsx("p",{className:"muted",children:h("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>g(null),children:h("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void O(N),children:h("delete")})]})]})}),C&&e.jsx(Ws,{draft:C,onClose:()=>w(null),onSuccess:()=>x(C.documentId)})]})}function _s(){const{t,lang:s}=Z(),v=Ce(),u=a.useRef(!1),[h,R]=a.useState([]),[o,k]=a.useState(!1),[j,b]=a.useState(""),[i,N]=a.useState("restricted"),[g,C]=a.useState(!1),[w,p]=a.useState(null),[f,A]=a.useState(null),[E,T]=a.useState(""),[P,O]=a.useState(""),[M,x]=a.useState("all"),[L,y]=a.useState(null);a.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const D=a.useCallback(async()=>{k(!0),p(null);try{const m=await De();if(!u.current)return;R(m)}catch(m){if(!u.current)return;p(H(t,m))}finally{u.current&&k(!1)}},[t]);a.useEffect(()=>{D()},[D]);async function l(m){if(m.preventDefault(),!j.trim()){p(t("domainNameRequired"));return}C(!0),p(null);try{if(await ls({domainName:j.trim(),permission:i}),!u.current)return;b(""),N("restricted"),await D()}catch(V){if(!u.current)return;p(H(t,V))}finally{u.current&&C(!1)}}async function c(m){if(E.trim()){p(null);try{if(await cs(m,E.trim()),!u.current)return;A(null),y(null),await D()}catch(V){if(!u.current)return;p(H(t,V))}}}function d(m){A(m.domainId),T(m.domainName),y(null)}function S(){A(null),y(null)}async function B(m,V){p(null);try{if(await is(m,V),!u.current)return;y(null),await D()}catch(W){if(!u.current)return;p(H(t,W))}}async function K(m){if(window.confirm(t("deleteDomainConfirmDetail",{name:m.domainName,count:String(m.docCount)}))){p(null);try{if(await ns(m.domainId),!u.current)return;await D()}catch(V){if(!u.current)return;p(H(t,V))}}}const $=a.useCallback(m=>as(m,t),[t]),q=a.useCallback(m=>ce(m.domainName,s,t),[s,t]),G=a.useMemo(()=>{const m=P.trim().toLowerCase();return h.filter(V=>M!=="all"&&V.permission!==M?!1:m?ce(V.domainName,s,t).toLowerCase().includes(m)||V.domainName.toLowerCase().includes(m):!0)},[h,P,M,s,t]),I=a.useCallback((m,V)=>{const W=$(m.permission);return V?`${W} ${t("domainTypeBuiltinSuffix")}`:W},[$,t]);return{domains:h,loadingDomains:o,domainError:w,newDomainName:j,setNewDomainName:b,newDomainPermission:i,setNewDomainPermission:N,creating:g,handleCreateDomain:l,renamingId:f,setRenamingId:A,renameDraft:E,setRenameDraft:T,startRename:d,cancelRename:S,handleRename:c,changeTypeForId:L,setChangeTypeForId:y,handlePermissionChange:B,handleDelete:K,domainSearch:P,setDomainSearch:O,domainFilter:M,setDomainFilter:x,filteredDomains:G,visitorId:v,plabel:$,localizeDomain:q,domainTypeLabel:I}}function Hs(){const{t}=Z(),s=_s(),[v,u]=a.useState([]),[h,R]=a.useState(null),[o,k]=a.useState(null),j=a.useCallback(async()=>{try{const i=await Ie();u(i)}catch{u([])}},[]);a.useEffect(()=>{j()},[j]);async function b(i){R(null);try{const N=await us(i.domainId);k({domainId:i.domainId,creatorVisitorId:i.creatorVisitorId,initialIds:N.map(g=>g.visitorId),memberRows:N})}catch(N){R({kind:"err",text:H(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")})]})]}),h&&e.jsx("div",{className:"mdocs-settings-card",style:{color:h.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:h.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=rs(i,s.visitorId),g=os(i.domainId),C=ds(i),w=C?t("domainTooltipTypeLocked",{count:String(i.docCount)}):void 0;return e.jsxs("tr",{className:g?"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:p=>s.setRenameDraft(p.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(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)}),g&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!N&&!g&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsxs("span",{className:"mdocs-domain-table-type",title:w,children:[e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":i.permission,children:s.domainTypeLabel(i,g)}),C&&!g&&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:[g&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!g&&!N&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!g&&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(p=>e.jsx("button",{type:"button",className:i.permission===p?"active":"",onClick:()=>void s.handlePermissionChange(i.domainId,p),children:s.plabel(p)},p))}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>s.setChangeTypeForId(null),children:t("cancel")})]}),!g&&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:C?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(i)},disabled:C,children:t("rename")}),e.jsx("button",{type:"button",className:"secondary",title:C?w:void 0,onClick:()=>{s.setRenamingId(null),s.setChangeTypeForId(i.domainId)},disabled:C,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"secondary",title:C?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(i),disabled:C,children:t("deleteDomain")}),i.permission==="restricted"&&!g&&e.jsx("button",{type:"button",className:"secondary",onClick:()=>void b(i),children:t("domainMembersManageButton")})]})]})]},i.domainId)})})]})})]}),e.jsx(Te,{open:o!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(o==null?void 0:o.initialIds)??[],lockedIds:o?[o.creatorVisitorId]:[],seedMembers:o==null?void 0:o.memberRows,templates:v,onClose:()=>k(null),onConfirm:async i=>{o&&(await ms(o.domainId,i),R({kind:"ok",text:t("domainMembersSaved",{count:String(i.length)})}))}})]})}function we(t){return t.length<=6?t:`${t.slice(0,6)}…`}function qs(){const{t}=Z(),s=a.useRef(!0),[v,u]=a.useState([]),[h,R]=a.useState(!0),[o,k]=a.useState(null),[j,b]=a.useState(1),[i,N]=a.useState(null),[g,C]=a.useState(""),[w,p]=a.useState([]),[f,A]=a.useState(!1),[E,T]=a.useState(null),[P,O]=a.useState(!1),M=Ce(),[x,L]=a.useState([]),[y,D]=a.useState("idle"),[l,c]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{D("loading"),hs().then(r=>{s.current&&(L(r),D("ok"))}).catch(()=>{s.current&&D("err")})},[]);const d=a.useMemo(()=>{const r=new Map;for(const z of x)r.set(z.visitorId,z.visitorName);return r},[x]),S=a.useCallback(async()=>{R(!0),T(null);try{const r=await Ie();s.current&&u(r)}catch(r){s.current&&T(H(t,r))}finally{s.current&&R(!1)}},[t]);a.useEffect(()=>{S()},[S]);const B=a.useMemo(()=>w.map(r=>{const z=x.find(U=>U.visitorId===r);return{visitorId:r,name:z?z.visitorName:t("visitorPickerUnknownVisitor"),muted:!z}}),[w,x,t]);function K(r){p(z=>z.includes(r)?z.filter(U=>U!==r):[...z,r])}const $=j===1?g.trim().length>0:j===2?w.length>0:!0;function q(){if(!(j>=3)){if(!$){O(!0);return}O(!1),b(j+1),c("")}}function G(){j<=1||(O(!1),b(j-1))}function I(){k(null),N(null),C(""),p(M?[M]:[]),T(null),b(1),c(""),O(!1)}function m(r){k(null),N(r.id),C(r.displayName);const z=M&&!r.visitorIds.includes(M)?[...r.visitorIds,M]:[...r.visitorIds];p(z),T(null),b(1),c(""),O(!1)}async function V(){if(!(!g.trim()||w.length===0)){A(!0),T(null);try{if(i===null?await gs({displayName:g.trim(),visitorIds:w}):await ps(i,{displayName:g.trim(),visitorIds:w}),!s.current)return;I(),await S()}catch(r){if(!s.current)return;T(H(t,r))}finally{s.current&&A(!1)}}}async function W(r){A(!0),T(null);try{if(await fs(r),!s.current)return;k(null),i===r&&I(),await S()}catch(z){if(!s.current)return;T(H(t,z))}finally{s.current&&A(!1)}}const Q=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],X=`${(j-1)/2*100}%`;return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:t(i!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),i!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:I,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:X}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:Q.map(r=>{const z=j===r.key,U=j>r.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${z?" current":""}${U?" done":""}`,children:U?"✓":r.key}),e.jsx("span",{className:`mdocs-wizard-step-label${z?" current":""}${U?" done":""}`,children:r.label})]},r.key)})})]}),E&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:E}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[j===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:g,onChange:r=>C(r.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:f,autoFocus:!0,"aria-invalid":P&&!g.trim()}),P&&!g.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),j===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Ks,{visitors:x,loadState:y,searchFilter:l,onSearchChange:c,selectedIds:new Set(w),onToggle:K,selectedRows:B,myVisitorId:M}),e.jsx("p",{className:`mdocs-wizard-hint${P&&w.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),j===3&&e.jsx("div",{className:"mdocs-wizard-step-content",children:e.jsxs("div",{className:"mdocs-wizard-preview-card",children:[e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:g})]}),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(w.length)})})]}),w.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[w.slice(0,15).map(r=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:we(r)},r)),w.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",w.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:G,children:["← ",t("memberTemplateWizardBack")]}),j<3?e.jsxs("button",{type:"button",className:"primary",onClick:q,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void V(),children:t(f?"saving":i===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),h?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):v.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),i===null&&e.jsx("button",{type:"button",className:"primary",onClick:I,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:v.map(r=>e.jsx("li",{className:"mdocs-member-template-row",children:o===r.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:t("memberTemplateConfirmDeleteDesc",{name:r.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 W(r.id),children:t(f?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>k(null),children:t("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:r.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateCount",{count:String(r.visitorIds.length)})}),r.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:r.visitorIds.map(z=>e.jsx("span",{className:"mdocs-member-template-tag",children:d.get(z)??we(z)},z))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>m(r),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>k(r.id),children:t("memberTemplateDelete")})]})]})},r.id))})]})]})]})}const Gs=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}];function Zs(){const{t}=Z(),s=a.useRef(!0),[v,u]=a.useState(""),[h,R]=a.useState(null),[o,k]=a.useState(""),[j,b]=a.useState("deepseek-v4-flash"),[i,N]=a.useState(128e3),[g,C]=a.useState(""),[w,p]=a.useState(!1),[f,A]=a.useState(null),[E,T]=a.useState(!0),[P,O]=a.useState(!1),[M,x]=a.useState(null),[L,y]=a.useState(!1),[D,l]=a.useState(!1),[c,d]=a.useState(!1),[S,B]=a.useState(null);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const[I,m]=await Promise.all([xs(),js()]);if(!s.current)return;u(I.visitorName),m?(R(m.id),k(m.name),b(m.modelId),N(m.contextWindow||128e3),p(m.hasApiKey),A(m.apiKeyMasked),l(!1)):l(!0)}catch(I){if(!s.current)return;x(I instanceof Error?I.message:String(I)),l(!0)}finally{s.current&&T(!1)}})()},[]);function K(){B({name:o,modelId:j,contextWindow:i}),C(""),d(!1),y(!1),x(null),l(!0)}function $(){S&&(k(S.name),b(S.modelId),N(S.contextWindow)),C(""),d(!1),x(null),y(!1),l(!1),B(null)}async function q(){O(!0),x(null),y(!1);try{const I={modelId:j,name:o,contextWindow:i};g.trim()&&(I.apiKey=g.trim());const m=await Ns(I);if(!s.current)return;R(m.id),k(m.name),b(m.modelId),N(m.contextWindow||128e3),p(m.hasApiKey),A(m.apiKeyMasked),C(""),d(!1),y(!0),l(!1),B(null)}catch(I){if(!s.current)return;x(I instanceof Error?I.message:String(I))}finally{s.current&&O(!1)}}const G=t("agentConfigNameDefault").replace("{{name}}",v||"…");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:bs,alt:"DeepSeek",className:"mdocs-agent-config-logo"}),t("agentConfig")]}),!E&&h&&!D?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")}),E?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:o,onChange:I=>k(I.target.value),placeholder:G,disabled:!D,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")}),D?e.jsx("div",{className:"mdocs-agent-config-select",children:e.jsx($s,{options:Gs,value:j,onChange:I=>b(I)})}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:j})]}),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")}),D?e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:i,onChange:I=>N(Number(I.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")}),D?e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:c?"text":"password",value:g,onChange:I=>C(I.target.value),placeholder:w?t("agentConfigApiKeyConfigured").replace("{{masked}}",f??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(c?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>d(I=>!I),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:w?f??"…":t("agentConfigApiKeyPlaceholder")})]}),h?e.jsxs("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:[t("agentConfigId"),": ",h]}):null,M?e.jsx("p",{style:{color:"var(--mdocs-danger, #c00)",marginBottom:12},children:M}):null,L&&!D?e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("saved")}):null,D?e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void q(),disabled:P,children:t(P?"saving":"save")}),h?e.jsx("button",{type:"button",className:"secondary",onClick:$,disabled:P,children:t("cancel")}):null]}):null]})]})})]})}const Js=/^[A-Za-z0-9_]+$/;function ie(t){return Js.test(t.trim())}function Qs(){const t=a.useRef(!0),[s,v]=a.useState([]),[u,h]=a.useState(!0),[R,o]=a.useState(null),[k,j]=a.useState(null),[b,i]=a.useState(!1),[N,g]=a.useState(""),[C,w]=a.useState(""),[p,f]=a.useState(""),[A,E]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function T(){h(!0),o(null);try{const l=await ys();if(!t.current)return;v(l)}catch(l){if(!t.current)return;o(l instanceof Error?l.message:String(l))}finally{t.current&&h(!1)}}a.useEffect(()=>{T()},[]);function P(){i(!0),j(null),g(""),w(""),f(""),o(null)}function O(l){i(!1),j(l.id),g(l.name),w(l.description),f(l.body),o(null)}function M(){i(!1),j(null),g(""),w(""),f("")}async function x(){const l=N.trim();if(!ie(l)){o("名称仅允许英文、数字、下划线");return}if(!p.trim()){o("正文不能为空");return}E(!0),o(null);try{if(b?await vs({name:l,description:C,body:p}):k&&await ks(k,{name:l,description:C,body:p}),!t.current)return;M(),await T()}catch(c){if(!t.current)return;o(c instanceof Error?c.message:String(c))}finally{t.current&&E(!1)}}async function L(l){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){o(null);try{if(await ws(l),!t.current)return;k===l&&M(),await T()}catch(c){if(!t.current)return;o(c instanceof Error?c.message:String(c))}}}const y=b||k!==null,D=!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",!u&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),y?null:e.jsx("button",{type:"button",className:"secondary",onClick:P,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),R?e.jsx("p",{className:"mdocs-agent-skills-error",children:R}):null,y?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:b?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:N,onChange:l=>g(l.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:D?void 0:"mdocs-agent-skills-input-invalid"}),D?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:C,onChange:l=>w(l.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:p,onChange:l=>f(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:A||!D||!N.trim()||!p.trim(),children:A?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:M,disabled:A,children:"取消"})]})]}):null,u?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!u&&s.length===0&&!y?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:P,children:"新建第一个"})]}):null,!u&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(l=>{const c=ie(l.name),d=k===l.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(d?" 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:()=>O(l),disabled:y&&!d,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void L(l.id),disabled:y,children:"删除"})]})]},l.id)})}):null]})})]})}function Se(t,s){const v=localStorage.getItem(t);return v===null?s:v==="true"}function at(t){const{t:s,lang:v,setLang:u}=Z(),{onBack:h,onPublishDraft:R}=t,o=Ss(),[k,j]=a.useState(!1),b=a.useRef(!0);a.useEffect(()=>(b.current=!0,()=>{b.current=!1}),[]),a.useEffect(()=>{o||j(!1)},[o]);const[i,N]=a.useState(()=>Se("mdocs.autoPublish",!1)),[g,C]=a.useState(()=>Se("mdocs.autoEdit",!0)),[w,p]=a.useState(!1),[f,A]=a.useState("general");function E(n){A(n),o&&j(!1)}const T=s(f==="general"?"general":f==="bookmarks"?"bookmarkTitle":f==="myDocuments"?"myDocuments":f==="domainManagement"?"domainManagement":f==="memberTemplates"?"memberTemplates":f==="agentConfig"?"agentConfig":"saveAndPublish"),[P,O]=a.useState([]),[M,x]=a.useState(!0),[L,y]=a.useState(null),[D,l]=a.useState(!1),[c,d]=a.useState(!1),[S,B]=a.useState(!1),[K,$]=a.useState(!1),[q,G]=a.useState(null),[I,m]=a.useState(!1),[V,W]=a.useState(!1),[Q,X]=a.useState(!1),[r,z]=a.useState(""),[U,re]=a.useState(!1),[Ae,oe]=a.useState(!1),[de,me]=a.useState(0),[Ee,ue]=a.useState([]),[Pe,he]=a.useState(!1),[Y,Me]=a.useState(""),[Le,Re]=a.useState([]),[ze,ge]=a.useState(!1),[ee,Be]=a.useState(""),[Fe,Oe]=a.useState([]),[Ve,se]=a.useState(!1),[te,pe]=a.useState(null),[ae,fe]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(i))},[i]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(g))},[g]),a.useEffect(()=>{f==="savePublish"&&le().then(n=>{b.current&&me(n.filter(F=>!F.published).length)})},[f]),a.useEffect(()=>{f==="bookmarks"&&Ke(),f==="myDocuments"&&be()},[f]),a.useEffect(()=>{je()},[]),a.useEffect(()=>{De().then(n=>{b.current&&Oe(n)}).catch(()=>{})},[]);const xe=new Map(Fe.map(n=>[n.domainId,n.domainName]));async function je(){try{x(!0);const n=await Cs();if(!b.current)return;O(n)}catch{}finally{b.current&&x(!1)}}async function Ke(){try{he(!0);const n=await Ds();if(!b.current)return;ue(n)}catch{}finally{b.current&&he(!1)}}async function be(){try{ge(!0);const n=await Is();if(!b.current)return;Re(n)}catch{}finally{b.current&&ge(!1)}}async function $e(n){try{await zs(n),ue(F=>F.filter(J=>J.documentId!==n))}catch{}}function We(){if(P.some(F=>!F.revoked)){d(!0);return}Ne()}async function Ne(){try{l(!0);const n=await Fs();y({token:n.token,name:n.name}),await je()}finally{l(!1)}}async function Ue(){try{X(!0);const n=await Ls();G(n.recoveryCode)}finally{X(!1)}}async function _e(n){n.preventDefault();const F=r.trim();if(!(F&&F.length<4))try{re(!0),await Rs(F),z(""),oe(!0),setTimeout(()=>oe(!1),3e3)}finally{re(!1)}}async function He(n){pe(n);try{const F=await Bs(n),J=new Map;F.forEach(_=>{J.set(_.visitorId,_.permission)}),fe(J)}catch{fe(new Map)}se(!0)}async function qe(n){if(te)try{const F=new Set(n.map(_=>_.visitorId)),J=new Set(ae.keys());for(const _ of J)F.has(_)||await Os(te,_);for(const _ of n)await Vs(te,_.visitorId,_.permission);await be()}finally{se(!1),pe(null)}}const ye=Ee.filter(n=>{if(!Y.trim())return!0;const F=Y.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(F)||(n.ownerVisitorName||"").toLowerCase().includes(F)||(n.domainId||"").toLowerCase().includes(F)}),ve=Le.filter(n=>{if(!ee.trim())return!0;const F=ee.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(F)||(n.domainId||"").toLowerCase().includes(F)});return e.jsxs("div",{className:"mdocs-layout"+(o?" mdocs-layout--reader mdocs-layout--settings":""),children:[o&&k?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>j(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(o?k?" mdocs-sidebar--drawer-open":" mdocs-sidebar--drawer":""),children:[e.jsxs("header",{className:"mdocs-sidebar-header",children:[e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:Ts,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),o?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>j(!1),"aria-label":s("collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(As,{size:18})}):null]}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(f==="general"?" active":""),onClick:()=>E("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(f==="bookmarks"?" active":""),onClick:()=>E("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(f==="myDocuments"?" active":""),onClick:()=>E("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(f==="domainManagement"?" active":""),onClick:()=>E("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(f==="memberTemplates"?" active":""),onClick:()=>E("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(f==="agentConfig"?" active":""),onClick:()=>E("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(f==="savePublish"?" active":""),onClick:()=>E("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:h,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[o?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>j(!0),"aria-label":s("expandSidebar"),children:e.jsx(Es,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:T})]}):null,Ps(),f==="general"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("general")})}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsx("span",{className:"mdocs-settings-item-info",children:e.jsx("span",{className:"mdocs-settings-card-title",children:s("language")})}),e.jsxs("span",{className:"mdocs-settings-lang",children:[e.jsx("button",{type:"button",className:v==="en"?"active":"",onClick:()=>u("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:v==="zh"?"active":"",onClick:()=>u("zh"),children:"中"})]})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoEdit")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoEditDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(g?" active":""),role:"switch","aria-checked":g,onClick:()=>C(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")}),!M&&P.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:P.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:We,disabled:D||M,children:D?"…":P.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),L&&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:L.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(L.token),$(!1),B(!0),window.setTimeout(()=>B(!1),2e3)}catch{B(!1),$(!0),window.setTimeout(()=>$(!1),3e3)}})()},children:s(S?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>y(null),children:s("close")})]}),S&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),K&&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:Ue,disabled:Q,children:Q?"…":"生成恢复码"})]}),q&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--warn",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 你的恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8},children:"请立即复制保存,关闭后不可再查看。"}),e.jsx("div",{className:"mdocs-settings-secret-code",children:q})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(q),W(!1),m(!0),window.setTimeout(()=>m(!1),2e3)}catch{m(!1),W(!0),window.setTimeout(()=>W(!1),3e3)}})()},children:I?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>G(null),children:s("close")})]}),I&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),V&&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:_e,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:r,onChange:n=>z(n.target.value),minLength:0,style:{marginBottom:8}}),Ae&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:U,children:U?"设置中…":"保存密码"})]})]})]})]}):f==="bookmarks"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("bookmarkTitle")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:s("bookmarkSearch"),value:Y,onChange:n=>Me(n.target.value)}),Pe?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:ye.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(Y?"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:ye.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:"已删除"}):xe.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:()=>$e(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})]})]}):f==="myDocuments"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("myDocuments")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:"搜索文章…",value:ee,onChange:n=>Be(n.target.value)}),ze?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:ve.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(ee?"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:ve.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:xe.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:()=>He(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))})]})})]})]}):f==="domainManagement"?e.jsx(Hs,{}):f==="memberTemplates"?e.jsx(qs,{}):f==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Zs,{}),e.jsx(Qs,{})]}):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:h,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"+(i?" active":""),role:"switch","aria-checked":i,onClick:()=>N(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),de>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>p(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",de,")"]}),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")})})]})]}),w&&e.jsx(Us,{onPublish:R,onClose:()=>p(!1),onCountChange:me,onRecover:t.onRecoverDraft})]}),c&&e.jsx(Ms,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:D,onConfirm:()=>{d(!1),Ne()},onCancel:()=>d(!1)}),e.jsx(Te,{open:Ve,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=>{qe(n)}})]})}export{at as SettingsPage};
@@ -1,4 +1,4 @@
1
- import{c as o}from"./index-B-XJ-ScV.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-BsVOIHR8.js";import{z as g,V as b}from"./editor-ONzd_YnO.js";/**
1
+ import{c as o}from"./index-Ct5Vt4tz.js";import{r as u,j as r}from"./react-vendor-BJFXgntS.js";import{F as _,G as C,L as v,H as c,J as l,K as N,M as L,q as j,N as z,P as w}from"./react-6CQL39Gs.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-BJFXgntS.js";import{b as G,B as ee,f as se,w as z}from"./index-Ct5Vt4tz.js";function ie({options:v,value:a,onChange:b}){const[d,f]=r.useState(!1),y=r.useRef(null),x=r.useRef(null),p=v.find(o=>o.value===a);r.useEffect(()=>{if(!d)return;const o=u=>{var N,k;!((N=y.current)!=null&&N.contains(u.target))&&!((k=x.current)!=null&&k.contains(u.target))&&f(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[d]),r.useEffect(()=>{if(!d)return;const o=u=>{var N;u.key==="Escape"&&(f(!1),(N=y.current)==null||N.focus())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[d]);function j(o){b(o),f(!1)}return e.jsxs("div",{className:"mdocs-mini-select",style:{position:"relative"},children:[e.jsxs("button",{ref:y,type:"button",className:"mdocs-mini-select-trigger","aria-expanded":d,"aria-haspopup":"listbox",onClick:()=>f(o=>!o),children:[e.jsx("span",{children:p==null?void 0:p.label}),e.jsx("svg",{className:"mdocs-mini-select-chevron"+(d?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),d&&e.jsx("div",{ref:x,className:"mdocs-mini-select-menu card",role:"listbox",children:v.map(o=>e.jsx("button",{type:"button",className:"mdocs-mini-select-option"+(o.value===a?" active":""),role:"option","aria-selected":o.value===a,onClick:()=>j(o.value),children:o.label},o.value))})]})}function te(v){return v.length<=6?v:`${v.slice(0,6)}…`}function re(v){const{visitors:a,loadState:b,searchFilter:d,onSearchChange:f,selectedIds:y,onToggle:x,selectedRows:p,lockedIds:j=new Set,myVisitorId:o,showPermissionSelect:u=!1,permissionOptions:N=[],onPermissionChange:k}=v,{t:i}=G(),w=r.useMemo(()=>{const t=d.trim().toLowerCase();let g=t?a.filter(m=>m.visitorName.toLowerCase().includes(t)||m.visitorId.toLowerCase().includes(t)):a;return o&&(g=[...g].sort((m,R)=>m.visitorId===o?-1:R.visitorId===o?1:0)),g},[a,d,o]);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"search",className:"mdocs-visitor-picker-search",placeholder:i("visitorPickerSearchPlaceholder"),value:d,onChange:t=>f(t.target.value),disabled:b!=="ok"}),b==="loading"&&e.jsx("div",{className:"mdocs-visitor-picker-loading",children:i("loading")}),b==="err"&&e.jsx("div",{className:"mdocs-visitor-picker-error",children:i("visitorPickerLoadError")}),b==="ok"&&e.jsxs("div",{className:"mdocs-visitor-picker-columns",children:[e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnAll")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdShort")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col",children:i("visitorPickerColPick")})]})}),e.jsx("tbody",{children:w.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"mdocs-visitor-picker-empty-cell",children:a.length===0?i("visitorPickerEmptyDirectory"):i("domainNoMatch")})}):w.map(t=>{const g=j.has(t.visitorId),m=y.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-short",children:te(t.visitorId)})}),e.jsxs("td",{children:[t.visitorName,t.visitorId===o&&e.jsx("span",{className:"mdocs-visitor-picker-self-marker",children:i("visitorPickerSelfMarker")})]}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:e.jsx("input",{type:"checkbox",checked:m,disabled:g,onChange:()=>x(t.visitorId),"aria-label":t.visitorName})})]},t.visitorId)})})]})})]}),e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnSelected")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdFull")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),u&&e.jsx("th",{scope:"col",children:i("permissionLabel")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col"})]})}),e.jsx("tbody",{children:p.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:u?4:3,className:"mdocs-visitor-picker-empty-cell",children:i("visitorPickerNoSelection")})}):p.map(t=>{const g=j.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-full",children:t.visitorId})}),e.jsx("td",{className:t.muted?"mdocs-visitor-picker-name-muted":void 0,children:t.name}),u&&e.jsx("td",{children:e.jsx(ie,{options:N,value:t.permission??"read",onChange:m=>k==null?void 0:k(t.visitorId,m)})}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:g?e.jsx("span",{className:"mdocs-visitor-picker-locked",title:i("visitorPickerLockedHint"),children:"—"}):e.jsx("button",{type:"button",className:"mdocs-visitor-picker-remove",onClick:()=>x(t.visitorId),"aria-label":i("visitorPickerRemove"),children:"×"})})]},t.visitorId)})})]})})]})]})]})}function ne(v){var U;const{open:a,title:b,initialSelectedIds:d,lockedIds:f=[],seedMembers:y,excludeTemplateId:x,templates:p,onClose:j,onConfirm:o,showPermissionSelect:u=!1,permissionOptions:N=[],initialPermissions:k}=v,{t:i}=G(),w=r.useRef(i);w.current=i;const t=r.useMemo(()=>new Set(f),[f]),g=ee(),[m,R]=r.useState([]),[E,T]=r.useState("idle"),[P,V]=r.useState(()=>new Set),[O,L]=r.useState(()=>new Map),[J,F]=r.useState(""),[C,A]=r.useState(""),[M,B]=r.useState(!1),$=r.useRef(null),[K,W]=r.useState(!1),[q,I]=r.useState(null),D=r.useMemo(()=>p.filter(s=>x==null||s.id!==x),[p,x]),H=r.useMemo(()=>new Map((y??[]).map(s=>[s.visitorId,s])),[y]);r.useEffect(()=>{a&&(V(new Set(d)),L(k?new Map(k):new Map),F(""),A(""),I(null))},[a,d,k]),r.useEffect(()=>{if(!a)return;let s=!1;return T("loading"),se().then(n=>{s||(R(n),T("ok"))}).catch(n=>{s||(T("err"),I(z(w.current,n)))}),()=>{s=!0}},[a]),r.useEffect(()=>{if(!M)return;const s=n=>{var c;(c=$.current)!=null&&c.contains(n.target)||B(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[M]);const Q=r.useMemo(()=>{const s=new Map(m.map(c=>[c.visitorId,c])),n=[];for(const c of P){const l=O.get(c),h=s.get(c);if(h){n.push({visitorId:c,name:h.visitorName,muted:!1,permission:l});continue}const S=H.get(c);if(S){S.missing?n.push({visitorId:c,name:i("visitorPickerMemberMissing"),muted:!0,permission:l}):S.disabled?n.push({visitorId:c,name:`${S.visitorName} · ${i("visitorPickerDisabledTag")}`,muted:!0,permission:l}):n.push({visitorId:c,name:S.visitorName,muted:!1,permission:l});continue}n.push({visitorId:c,name:i("visitorPickerUnknownVisitor"),muted:!0,permission:l})}return n.sort((c,l)=>c.name.localeCompare(l.name,void 0,{sensitivity:"base"})),n},[m,P,H,O,i]),X=r.useCallback(s=>{t.has(s)||V(n=>{const c=new Set(n);return c.has(s)?(c.delete(s),L(l=>{const h=new Map(l);return h.delete(s),h})):(c.add(s),L(l=>{const h=new Map(l);return h.set(s,"read"),h})),c})},[t]),Y=r.useCallback((s,n)=>{L(c=>{const l=new Map(c);return l.set(s,n),l})},[]),Z=r.useCallback(()=>{const s=Number(C);if(!Number.isInteger(s)||s<1)return;const n=p.find(l=>l.id===s);if(!n)return;const c=new Set(m.map(l=>l.visitorId));V(l=>{const h=new Set(l);for(const S of n.visitorIds)c.has(S)&&h.add(S);return h})},[C,p,m]);async function _(){I(null),W(!0);try{if(u){const s=[...P].sort().map(n=>({visitorId:n,permission:O.get(n)??"read"}));await o(s)}else{const s=[...P].sort();await o(s)}j()}catch(s){I(z(i,s))}finally{W(!1)}}return a?e.jsx("div",{className:"mdocs-visitor-picker-overlay",role:"presentation",onMouseDown:s=>s.target===s.currentTarget&&j(),children:e.jsxs("div",{className:"mdocs-visitor-picker-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-visitor-picker-title",children:[e.jsxs("header",{className:"mdocs-visitor-picker-header",children:[e.jsx("h2",{id:"mdocs-visitor-picker-title",className:"mdocs-visitor-picker-title",children:b}),e.jsx("button",{type:"button",className:"mdocs-visitor-picker-close",onClick:j,"aria-label":i("close"),children:"×"})]}),D.length>0&&e.jsx("div",{className:"mdocs-visitor-picker-toolbar",children:e.jsxs("div",{className:"mdocs-visitor-picker-template-bar",children:[e.jsxs("div",{ref:$,className:"mdocs-template-picker",children:[e.jsxs("button",{type:"button",className:"mdocs-template-picker-trigger",onClick:()=>B(s=>!s),disabled:E!=="ok","aria-haspopup":"listbox","aria-expanded":M,children:[e.jsx("span",{className:"mdocs-template-picker-text",children:C?(U=D.find(s=>String(s.id)===C))==null?void 0:U.displayName:i("visitorPickerPickTemplate")}),e.jsx("svg",{className:"mdocs-template-picker-chevron"+(M?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),M&&e.jsx("div",{className:"mdocs-template-picker-menu card",role:"listbox",children:D.map(s=>e.jsx("button",{type:"button",className:"mdocs-template-picker-option"+(String(s.id)===C?" active":""),role:"option","aria-selected":String(s.id)===C,onClick:()=>{A(String(s.id)),B(!1)},children:s.displayName},s.id))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}if(!C){I(i("visitorPickerPickTemplate"));return}Z()},children:i("visitorPickerApplyTemplate")})]})}),q&&e.jsx("div",{className:"mdocs-visitor-picker-error",role:"alert",children:q}),e.jsx("div",{style:{padding:"8px 18px 12px"},children:e.jsx(re,{visitors:m,loadState:E,searchFilter:J,onSearchChange:F,selectedIds:P,onToggle:X,selectedRows:Q,lockedIds:t,myVisitorId:g,showPermissionSelect:u,permissionOptions:N,onPermissionChange:Y})}),e.jsxs("footer",{className:"mdocs-visitor-picker-footer",children:[e.jsx("button",{type:"button",className:"secondary",onClick:j,children:i("cancel")}),e.jsx("button",{type:"button",className:"primary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}_()},children:i(K?"saving":"visitorPickerConfirm")})]})]})}):null}export{ie as M,ne as V,re as a};
@@ -1,4 +1,4 @@
1
- import{c}from"./index-B-XJ-ScV.js";/**
1
+ import{c}from"./index-Ct5Vt4tz.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.