@fgbg/mdocs 0.8.23 → 0.8.25

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 (36) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +12 -1
  3. package/agent-skills/index.json +1 -1
  4. package/dist/server/agent/Agent/run.js +2 -2
  5. package/dist/server/agent/Agent/run.js.map +1 -1
  6. package/dist/server/agent/Agent/system-prompt.js +13 -3
  7. package/dist/server/agent/Agent/system-prompt.js.map +1 -1
  8. package/dist/server/cli/self-update.js +50 -32
  9. package/dist/server/cli/self-update.js.map +1 -1
  10. package/dist/server/routes/agent.routes.js +10 -0
  11. package/dist/server/routes/agent.routes.js.map +1 -1
  12. package/dist/web/assets/AgentChatPanel-BTCyf9Ww.js +1 -0
  13. package/dist/web/assets/{AgentSkillFormCard-DeZnOTQg.js → AgentSkillFormCard-CAD6QqQ0.js} +1 -1
  14. package/dist/web/assets/{AiWriteWorkbench-hUYjin2m.js → AiWriteWorkbench-PVv90TJS.js} +1 -1
  15. package/dist/web/assets/{DiagramEditor-NtNY3sZL-C9hL71kf.js → DiagramEditor-NtNY3sZL-DqPXDJHY.js} +1 -1
  16. package/dist/web/assets/{DocumentEditor-BmmnuieO.js → DocumentEditor-zNIJgxe0.js} +1 -1
  17. package/dist/web/assets/MergeView-Y3zB8V5p.js +10 -0
  18. package/dist/web/assets/{PlaygroundPage-CgaNgQEp.js → PlaygroundPage-DAaEm887.js} +1 -1
  19. package/dist/web/assets/{SettingsPage-Fl5Tu7u3.js → SettingsPage-DhdiNEhO.js} +1 -1
  20. package/dist/web/assets/{Toolbar-BaKuyXey.js → Toolbar-B36NxaTc.js} +1 -1
  21. package/dist/web/assets/{VisitorPickerModal-DPyg6mIt.js → VisitorPickerModal-drnOuPLP.js} +1 -1
  22. package/dist/web/assets/{copy-UkvgEfIg.js → copy-CX8GOyUb.js} +1 -1
  23. package/dist/web/assets/{diagram-BLCqfrbF.js → diagram-3lhA7FYR.js} +638 -638
  24. package/dist/web/assets/index-DgM2rYI-.js +185 -0
  25. package/dist/web/assets/index-S_lCknAk.css +1 -0
  26. package/dist/web/assets/{meta2dEngine-BD2XbzaV-2ovN6JHu.js → meta2dEngine-BD2XbzaV-CCgjRlVJ.js} +1 -1
  27. package/dist/web/assets/{motion-Bz_inm1R.js → motion-92iQWeIW.js} +1 -1
  28. package/dist/web/assets/{plus-B-uEAM2g.js → plus-BWV299MC.js} +1 -1
  29. package/dist/web/assets/{react-6CQL39Gs.js → react-BUhFwPCj.js} +3 -3
  30. package/dist/web/assets/{ui-TwLH91RV.js → ui-06fxEgif.js} +3 -3
  31. package/dist/web/index.html +4 -4
  32. package/package.json +1 -1
  33. package/dist/web/assets/AgentChatPanel-CtdLYtSw.js +0 -1
  34. package/dist/web/assets/MergeView-CjhCBNPa.js +0 -22
  35. package/dist/web/assets/index-Ct5Vt4tz.js +0 -185
  36. package/dist/web/assets/index-Dt_PAYaR.css +0 -1
@@ -0,0 +1,10 @@
1
+ import{r as b,j as o}from"./react-vendor-BJFXgntS.js";import{b as V,as as _,at as J,au as Q,av as X}from"./index-DgM2rYI-.js";import{E as Y,B as Z}from"./react-BUhFwPCj.js";import"./ui-06fxEgif.js";import"./motion-92iQWeIW.js";import"./editor-ONzd_YnO.js";import"./diagram-3lhA7FYR.js";import"./plus-BWV299MC.js";import"./copy-CX8GOyUb.js";function B({lexicalJson:e,onMarkdown:n,onError:s}){const[u,l]=b.useState(null),i=b.useRef(!1);return b.useEffect(()=>{i.current=!1},[e]),b.useEffect(()=>{if(!(!u||i.current))try{u.setDocument("json",e);const c=u.getDocument("markdown");typeof c=="string"&&(i.current=!0,n(c))}catch{s==null||s()}},[u,e,n,s]),o.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:o.jsx(Y,{content:e,type:"json",editable:!1,onInit:l,plugins:[Z]})})}function ee(e){const{t:n}=V(),[s,u]=b.useState(0),l=e.segments.filter(t=>t.kind==="conflict"),i=e.unresolvedCount>0;b.useEffect(()=>{if(l.length===0){u(0);return}u(t=>Math.min(t,l.length-1))},[l.length]);function c(t){l.length!==0&&u(d=>{var f;const a=(d+t+l.length)%l.length;return(f=document.getElementById(`mdocs-merge-hunk-${a}`))==null||f.scrollIntoView({block:"center",behavior:"smooth"}),a})}let r=-1;return o.jsxs("div",{className:"mdocs-merge-inline-pane",children:[o.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[o.jsx("span",{className:"mdocs-merge-inline-hint",children:i?n("mergeReviewHint"):l.length===0?n("mergeNoConflicts"):n("mergeEditAfterResolve")}),l.length>0?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:e.onUseAllMine,children:n("mergeUseAllMine")}),o.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:n("mergeUseAllTheirs")})]}):null]}),i?o.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((t,d)=>{if(t.kind==="unchanged")return o.jsx("pre",{className:"mdocs-merge-inline-same",children:t.lines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},g))},`u-${d}`);r+=1;const a=r,f=t.resolution!=="unresolved",m=a===s;return o.jsxs("div",{id:`mdocs-merge-hunk-${a}`,className:"mdocs-merge-inline-hunk"+(m?" is-active":"")+(f?" is-resolved":""),onClick:()=>u(a),children:[f?o.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:t.resolution==="remote"?n("mergeReceive"):n("mergeReject")}):o.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:x=>{x.stopPropagation(),e.onReject(t.id)},children:n("mergeReject")}),o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:x=>{x.stopPropagation(),e.onReceive(t.id)},children:n("mergeReceive")})]}),o.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[t.localLines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line del",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},`l${g}`)),t.remoteLines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line add",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},`r${g}`))]})]},t.id)}),l.length>0?o.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[o.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>c(-1),children:"↑"}),o.jsxs("span",{children:[s+1," / ",l.length]}),o.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>c(1),children:"↓"}),l[s]&&l[s].resolution==="unresolved"?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(l[s].id),children:n("mergeReject")}),o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(l[s].id),children:n("mergeReceive")})]}):null]}):null]}):o.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:t=>e.onEditableChange(t.target.value),spellCheck:!1})]})}function te(e,n){let s={};for(let i=0;i<n.length;i++){const c=n[i];s[c]?s[c].push(i):s[c]=[i]}let l=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let i=0;i<e.length;i++){const c=e[i],r=s[c]||[];let t=0,d=l[0];for(let a=0;a<r.length;a++){const f=r[a];let m;for(m=t;m<l.length&&!(l[m].buffer2index<f&&(m===l.length-1||l[m+1].buffer2index>f));m++);if(m<l.length){const x={buffer1index:i,buffer2index:f,chain:l[m]};if(t===l.length?l.push(d):l[t]=d,t=m+1,d=x,t===l.length)break}}l[t]=d}return l[l.length-1]}function q(e,n){const s=te(e,n);let u=[],l=e.length,i=n.length;for(let c=s;c!==null;c=c.chain){const r=l-c.buffer1index-1,t=i-c.buffer2index-1;l=c.buffer1index,i=c.buffer2index,(r||t)&&u.push({buffer1:[l+1,r],buffer1Content:e.slice(l+1,l+1+r),buffer2:[i+1,t],buffer2Content:n.slice(i+1,i+1+t)})}return u.reverse(),u}function ne(e,n,s){let u=[];function l(t,d){u.push({ab:d,oStart:t.buffer1[0],oLength:t.buffer1[1],abStart:t.buffer2[0],abLength:t.buffer2[1]})}q(n,e).forEach(t=>l(t,"a")),q(n,s).forEach(t=>l(t,"b")),u.sort((t,d)=>t.oStart-d.oStart);let i=[],c=0;function r(t){t>c&&(i.push({stable:!0,buffer:"o",bufferStart:c,bufferLength:t-c,bufferContent:n.slice(c,t)}),c=t)}for(;u.length;){let t=u.shift(),d=t.oStart,a=t.oStart+t.oLength,f=[t];for(r(d);u.length;){const m=u[0],x=m.oStart;if(x>a)break;a=Math.max(a,x+m.oLength),f.push(u.shift())}if(f.length===1){if(t.abLength>0){const m=t.ab==="a"?e:s;i.push({stable:!0,buffer:t.ab,bufferStart:t.abStart,bufferLength:t.abLength,bufferContent:m.slice(t.abStart,t.abStart+t.abLength)})}}else{let m={a:[e.length,-1,n.length,-1],b:[s.length,-1,n.length,-1]};for(;f.length;){t=f.shift();const v=t.oStart,p=v+t.oLength,L=t.abStart,w=L+t.abLength;let S=m[t.ab];S[0]=Math.min(L,S[0]),S[1]=Math.max(w,S[1]),S[2]=Math.min(v,S[2]),S[3]=Math.max(p,S[3])}const x=m.a[0]+(d-m.a[2]),g=m.a[1]+(a-m.a[3]),j=m.b[0]+(d-m.b[2]),h=m.b[1]+(a-m.b[3]);let y={stable:!1,aStart:x,aLength:g-x,aContent:e.slice(x,g),oStart:d,oLength:a-d,oContent:n.slice(d,a),bStart:j,bLength:h-j,bContent:s.slice(j,h)};i.push(y)}c=a}return r(n.length),i}function le(e,n,s,u){u=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},u),typeof e=="string"&&(e=e.split(u.stringSeparator)),typeof n=="string"&&(n=n.split(u.stringSeparator)),typeof s=="string"&&(s=s.split(u.stringSeparator));let i=[];const c=ne(e,n,s);let r=[];function t(){r.length&&i.push({ok:r}),r=[]}function d(a,f){if(a.length!==f.length)return!1;for(let m=0;m<a.length;m++)if(a[m]!==f[m])return!1;return!0}return c.forEach(a=>{a.stable?r.push(...a.bufferContent):u.excludeFalseConflicts&&d(a.aContent,a.bContent)?r.push(...a.aContent):(t(),i.push({conflict:{a:a.aContent,aIndex:a.aStart,o:a.oContent,oIndex:a.oStart,b:a.bContent,bIndex:a.bStart}}))}),t(),i}const se=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function ie(e){return`<!-- mdocs-merge-conflict:${e} -->`}function oe(e){const n=e.trim().match(se);return(n==null?void 0:n[1])??null}function M(e){return e===""?[]:e.split(`
2
+ `)}function H(e,n){return e.length===n.length&&e.every((s,u)=>s===n[u])}function ce(e,n,s){const u=M(e),l=M(n),i=M(s);if(l.length===0&&n==="")return re(e,s);const c=le(u,l,i),r=[];let t=0,d=0,a=0,f=0;const m=(g,j,h,y)=>{r.push({kind:"conflict",id:`conflict-${t}`,conflictKind:y,baseLines:g,localLines:j,remoteLines:h,resolution:"unresolved"}),t+=1},x=(g,j,h)=>{if(j.length===0&&g.length===0&&h.length===0)return;if(H(g,j)&&H(h,j)){j.length>0&&r.push({kind:"unchanged",lines:[...j]});return}if(g.length===j.length&&h.length===j.length){let v=[];const p=()=>{v.length>0&&(r.push({kind:"unchanged",lines:v}),v=[])};for(let L=0;L<j.length;L+=1){const w=j[L],S=g[L],N=h[L];S===w&&N===w?v.push(w):(p(),m([w],[S],[N],S!==w&&N!==w&&S!==N?"true_conflict":"change"))}p();return}const y=g.join(`
3
+ `)!==j.join(`
4
+ `)&&h.join(`
5
+ `)!==j.join(`
6
+ `)&&g.join(`
7
+ `)!==h.join(`
8
+ `)?"true_conflict":"change";m(j,g,h,y)};for(let g=0;g<c.length;g+=1){const j=c[g],h=j.conflict;if(h){x(u.slice(d,h.aIndex),l.slice(a,h.oIndex),i.slice(f,h.bIndex)),m(h.o,h.a,h.b,"true_conflict"),d=h.aIndex+h.a.length,a=h.oIndex+h.o.length,f=h.bIndex+h.b.length;continue}if(j.ok){const y=c[g+1],v=y==null?void 0:y.conflict;v?(x(u.slice(d,v.aIndex),l.slice(a,v.oIndex),i.slice(f,v.bIndex)),d=v.aIndex,a=v.oIndex,f=v.bIndex):(x(u.slice(d),l.slice(a),i.slice(f)),d=u.length,a=l.length,f=i.length)}}return r}function ae(e,n){const s=e.length,u=n.length,l=Array.from({length:s+1},()=>new Array(u+1).fill(0));for(let t=1;t<=s;t+=1)for(let d=1;d<=u;d+=1)e[t-1]===n[d-1]?l[t][d]=l[t-1][d-1]+1:l[t][d]=Math.max(l[t-1][d],l[t][d-1]);const i=[];let c=s,r=u;for(;c>0||r>0;)c>0&&r>0&&e[c-1]===n[r-1]?(i.push({type:"equal",line:e[c-1]}),c-=1,r-=1):r>0&&(c===0||l[c][r-1]>=l[c-1][r])?(i.push({type:"add",line:n[r-1]}),r-=1):(i.push({type:"del",line:e[c-1]}),c-=1);return i.reverse()}function re(e,n){const s=M(e),u=M(n),l=ae(s,u),i=[];let c=0,r=0;for(;r<l.length;){if(l[r].type==="equal"){const f=[];for(;r<l.length&&l[r].type==="equal";)f.push(l[r].line),r+=1;i.push({kind:"unchanged",lines:f});continue}const d=[],a=[];for(;r<l.length&&l[r].type!=="equal";){const f=l[r];f.type==="del"&&d.push(f.line),f.type==="add"&&a.push(f.line),r+=1}i.push({kind:"conflict",id:`conflict-${c}`,conflictKind:"true_conflict",baseLines:[],localLines:d,remoteLines:a,resolution:"unresolved"}),c+=1}return i}function ue(e){return e.filter(n=>n.kind==="conflict").length}function de(e){return e.filter(n=>n.kind==="conflict"&&n.resolution==="unresolved").length}function fe(e){switch(e.resolution){case"local":return e.localLines;case"remote":return e.remoteLines;case"both":return[...e.localLines,...e.remoteLines];case"manual":return e.manualLines??[];default:return[]}}function me(e){const n=[];for(const s of e)s.kind==="unchanged"?n.push(...s.lines):s.resolution==="unresolved"?n.push(ie(s.id)):n.push(...fe(s));return n.join(`
9
+ `)}function O(e){return M(e).filter(n=>!oe(n)).join(`
10
+ `)}function F(e,n,s,u){return e.map(l=>l.kind!=="conflict"||l.id!==n?l:{...l,resolution:s,manualLines:s==="manual"?l.manualLines??[]:void 0})}function ye(e){const{t:n}=V(),[s,u]=b.useState(""),[l,i]=b.useState(""),[c,r]=b.useState(null),[t,d]=b.useState(!1),[a,f]=b.useState(!1),[m,x]=b.useState(null),[g,j]=b.useState(""),[h,y]=b.useState(null),[v,p]=b.useState(null),[L,w]=b.useState(!1),[S,N]=b.useState(!0);b.useEffect(()=>{let k=!1;return N(!0),x(null),j(""),y(null),p(null),(async()=>{try{const C=await _(e.documentId);if(k)return;x(C.content)}catch{k||e.onError(n("mergeLoadRemoteFailed")),k||N(!1)}})(),()=>{k=!0}},[e.documentId,e.onError,n]),b.useEffect(()=>{let k=!1;return r(null),i(""),d(!1),f(!1),(async()=>{try{const C=await J(e.documentId,e.conflict.localBaseCommitId,e.conflict.remoteCommitId);if(k)return;if(C.mode==="three_way"&&C.mergeBaseContent){r(C.mergeBaseContent);return}d(!0),f(!0)}catch{if(k)return;d(!0),f(!0)}})(),()=>{k=!0}},[e.documentId,e.conflict.localBaseCommitId,e.conflict.remoteCommitId]);const P=b.useCallback(k=>{j(k),N(!1)},[]),W=b.useCallback(k=>{u(k)},[]),K=b.useCallback(k=>{i(k),f(!0)},[]),z=b.useCallback(()=>{d(!0),i(""),f(!0)},[]);b.useEffect(()=>{!s||!g||S||!a||(y(ce(s,l,g)),p(null))},[s,g,l,a,S,e.conflict.remoteCommitId]);const R=b.useMemo(()=>h?O(me(h)):"",[h]),A=h?ue(h):0,I=h?de(h):0,T=v??R;b.useEffect(()=>{I===0&&h&&v===null&&p(R)},[I,h,R,v]);function $(k){y(C=>{if(!C)return C;let E=C;for(const D of C)D.kind==="conflict"&&(E=F(E,D.id,k));return E}),p(null)}async function G(){if(I>0){e.onError(n("mergeConflictsUnresolved",{count:String(I)}));return}const k=O(T);w(!0);try{const{content:C}=await Q({content:k,from:"markdown",to:"lexical"});await X(e.documentId,{content:C,displayName:e.displayName,version:{localBaseCommitId:e.conflict.localBaseCommitId,merge:{remoteCommitId:e.conflict.remoteCommitId,localSnapshotContent:e.conflict.localSnapshotContent}}});const E=await _(e.documentId);e.onSuccess(E)}catch(C){e.onError(C instanceof Error?C.message:String(C))}finally{w(!1)}}const U=!!(s&&g&&h&&!S&&a);return o.jsxs("div",{className:"mdocs-merge-overlay",children:[o.jsx(B,{lexicalJson:e.conflict.localSnapshotContent,onMarkdown:W,onError:()=>e.onError(n("mergeLoadLocalFailed"))}),c?o.jsx(B,{lexicalJson:c,onMarkdown:K,onError:z}):null,m?o.jsx(B,{lexicalJson:m,onMarkdown:P,onError:()=>{N(!1),e.onError(n("mergeLoadRemoteFailed"))}}):null,o.jsxs("header",{className:"mdocs-merge-toolbar",children:[o.jsxs("div",{className:"mdocs-merge-toolbar-title",children:[o.jsx("h2",{children:n("mergeTitle")}),U&&A>0?o.jsx("span",{className:`mdocs-merge-conflict-pill ${I>0?"pending":"resolved"}`,children:I>0?n("mergeConflictsPending",{unresolved:String(I),total:String(A)}):n("mergeConflictsResolved",{total:String(A)})}):null,t?o.jsx("span",{className:"mdocs-merge-base-warning",children:n("mergeBaseMissing")}):null]}),o.jsxs("div",{className:"mdocs-merge-toolbar-actions",children:[o.jsx("button",{type:"button",className:"secondary",disabled:L,onClick:e.onClose,children:n("cancel")}),o.jsx("button",{type:"button",className:"primary",disabled:L||!U||I>0,onClick:()=>void G(),children:n(L?"publishing":"mergeComplete")})]})]}),o.jsx("div",{className:"mdocs-merge-body mdocs-merge-body--inline",children:U?o.jsx(ee,{segments:h,unresolvedCount:I,onReceive:k=>{y(C=>C&&F(C,k,"remote")),p(null)},onReject:k=>{y(C=>C&&F(C,k,"local")),p(null)},onUseAllMine:()=>$("local"),onUseAllTheirs:()=>$("remote"),editableMarkdown:T,onEditableChange:p}):o.jsx("p",{className:"mdocs-merge-loading",children:n("mergeLoadingRemote")})})]})}export{ye as MergeView};
@@ -1,4 +1,4 @@
1
- import{r as n,j as o,ae as C}from"./react-vendor-BJFXgntS.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as H,w as g,j as L,k as F,l as q,I as U,m as b,n as V,o as z,p as J,q as W,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-6CQL39Gs.js";import{v as Q,x as X,H as ee,y as te,A as k,z as oe}from"./ui-TwLH91RV.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,N as ce,c as R,o as me}from"./Toolbar-BaKuyXey.js";import"./editor-ONzd_YnO.js";import"./diagram-BLCqfrbF.js";import"./index-Ct5Vt4tz.js";import"./motion-Bz_inm1R.js";import"./plus-B-uEAM2g.js";import"./copy-UkvgEfIg.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[f,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:f,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,f]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");f(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(z,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(J,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{me(l=>{for(const u of l)e.dispatchCommand(W,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
1
+ import{r as n,j as o,ae as C}from"./react-vendor-BJFXgntS.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as H,w as g,j as L,k as F,l as q,I as U,m as b,n as V,o as z,p as J,q as W,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-BUhFwPCj.js";import{v as Q,x as X,H as ee,y as te,A as k,z as oe}from"./ui-06fxEgif.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,N as ce,c as R,o as me}from"./Toolbar-B36NxaTc.js";import"./editor-ONzd_YnO.js";import"./diagram-3lhA7FYR.js";import"./index-DgM2rYI-.js";import"./motion-92iQWeIW.js";import"./plus-BWV299MC.js";import"./copy-CX8GOyUb.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[f,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:f,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,f]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");f(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(z,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(J,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{me(l=>{for(const u of l)e.dispatchCommand(W,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
2
2
  123`),queueMicrotask(()=>{e.focus()})}},{key:"insert-link",label:"InsertLink",onSelect:e=>{e.dispatchCommand(B,{url:"https://example.com"}),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeInline",label:"InsertCodeInline",onSelect:e=>{e.dispatchCommand($,void 0),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeBlock",label:"InsertCodeBlock",onSelect:e=>{e.dispatchCommand(K,void 0),queueMicrotask(()=>{e.focus()})}},{icon:de,key:"meta2d",label:"Meta2d",onSelect:e=>{e.dispatchCommand(Y,void 0),queueMicrotask(()=>{e.focus()})}},{icon:ce,key:"markmap",label:"Markmap",onSelect:e=>{e.dispatchCommand(G,void 0),queueMicrotask(()=>{e.focus()})}}].map(e=>e.type==="divider"?e:{...e,extra:o.jsx(oe,{code:!0,fontSize:12,type:"secondary",children:e.key})}),[]);return o.jsxs(ue,{json:m,markdown:p,onJSONChange:s,...h,children:[o.jsx(R,{editor:r}),o.jsx(T,{className:"mdocs-playground-editor",content:ye,editor:r,lineEmptyPlaceholder:"Start typing here...",mentionOption:{items:d,markdownWriter:t=>{var e;return`
3
3
  <mention>${t.label}[${((e=t.metadata)==null?void 0:e.id)||t.label}]</mention>
4
4
  `},onSelect:(t,e)=>{t.dispatchCommand(U,{label:String(e.label),metadata:{id:e.key}})},searchKeys:["label"]},onInit:x,onTextChange:c,pasteVSCodeAsCodeBlock:!0,placeholder:"Type something...",plugins:[I,E,M,j,O,P,A,_,D,H,g(L,{children:o.jsx(R,{editor:r,floating:!0})}),g(F,{delay:1e3,onAutoComplete:async({input:t,afterText:e,selectionType:l,abortSignal:u})=>{console.log("Auto-complete triggered:",{afterText:e,input:t,selectionType:l});try{const v=await fetch(`${location.origin}/nodeserver/completion`,{body:JSON.stringify({prompt:`Please complete the following text:
@@ -1 +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
+ 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-DgM2rYI-.js";import{V as Te,a as Ks,M as $s}from"./VisitorPickerModal-drnOuPLP.js";import"./ui-06fxEgif.js";import"./motion-92iQWeIW.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-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";/**
1
+ import{c as o}from"./index-DgM2rYI-.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-BUhFwPCj.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-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
+ 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-DgM2rYI-.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-Ct5Vt4tz.js";/**
1
+ import{c}from"./index-DgM2rYI-.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.