@fgbg/mdocs 1.3.14 → 1.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/agent-skills/changelog/SKILL.md +28 -1
- package/agent-skills/core-concepts-all-files/SKILL.md +3 -3
- package/agent-skills/core-concepts-domain/SKILL.md +49 -46
- package/agent-skills/core-concepts-invitation/SKILL.md +9 -9
- package/agent-skills/core-concepts-no-account/SKILL.md +1 -1
- package/agent-skills/deployment-requirements/SKILL.md +2 -2
- package/agent-skills/faq/SKILL.md +2 -2
- package/agent-skills/getting-started-first-kb/SKILL.md +2 -2
- package/agent-skills/getting-started-installation/SKILL.md +3 -3
- package/agent-skills/index/SKILL.md +2 -2
- package/agent-skills/index.json +8 -8
- package/agent-skills/usage-bookmarks/SKILL.md +5 -5
- package/agent-skills/usage-cli-token/SKILL.md +6 -6
- package/agent-skills/usage-comments/SKILL.md +1 -1
- package/agent-skills/usage-domain-members/SKILL.md +27 -27
- package/agent-skills/usage-html-documents/SKILL.md +1 -1
- package/agent-skills/usage-knowledge-graph/SKILL.md +5 -5
- package/agent-skills/usage-my-documents/SKILL.md +8 -8
- package/agent-skills/usage-onboarding-ai/SKILL.md +6 -6
- package/agent-skills/usage-search/SKILL.md +2 -2
- package/agent-skills/usage-settings/SKILL.md +8 -8
- package/bin/mdocs.js +0 -0
- package/dist/server/agent/Agent/system-prompt.js +3 -3
- package/dist/server/agent/Agent/system-prompt.js.map +1 -1
- package/dist/server/agent/Agent/tool-ui-effects.js +1 -1
- package/dist/server/agent/Agent/tools-documents.js +12 -12
- package/dist/server/agent/Agent/tools-documents.js.map +1 -1
- package/dist/server/agent/Agent/tools-domains.js +14 -14
- package/dist/server/agent/Agent/tools-domains.js.map +1 -1
- package/dist/server/agent/Agent/tools-visitors.js +1 -1
- package/dist/server/agent/Agent/tools-visitors.js.map +1 -1
- package/dist/server/cli/self-update.js +12 -0
- package/dist/server/cli/self-update.js.map +1 -1
- package/dist/server/cli/self-update.test.js +17 -1
- package/dist/server/cli/self-update.test.js.map +1 -1
- package/dist/server/documents/document.service.js +6 -6
- package/dist/server/documents/document.service.js.map +1 -1
- package/dist/server/documents/graph-task.js +1 -1
- package/dist/server/documents/graph-task.js.map +1 -1
- package/dist/server/documents/graph.service.js +1 -1
- package/dist/server/documents/graph.service.js.map +1 -1
- package/dist/server/domains/change-domain-permission.js +1 -1
- package/dist/server/domains/change-domain-permission.js.map +1 -1
- package/dist/server/routes/assets.routes.js +9 -7
- package/dist/server/routes/assets.routes.js.map +1 -1
- package/dist/server/routes/assets.routes.upload.test.js +2 -2
- package/dist/server/routes/assets.routes.upload.test.js.map +1 -1
- package/dist/server/routes/folders.routes.js +4 -4
- package/dist/server/routes/folders.routes.js.map +1 -1
- package/dist/web/assets/AgentChatPanel-Bsx3DwQ7.js +22 -0
- package/dist/web/assets/{AgentSkillFormCard-53eZ84xO.js → AgentSkillFormCard-TFpdC5LM.js} +3 -3
- package/dist/web/assets/AiWriteWorkbench-Jl0I9eM9.js +7 -0
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-YvQa1xOq.js → DiagramEditor-NtNY3sZL-CAEe_iNQ.js} +1 -1
- package/dist/web/assets/DocChrome-BWMgRxlr.js +21 -0
- package/dist/web/assets/DocumentEditor-DALklXO2.js +1 -0
- package/dist/web/assets/HtmlEditor-CX0e0ifD.js +1 -0
- package/dist/web/assets/{MergeView-DP-WJuEH.js → MergeView-DNu_ac5f.js} +2 -2
- package/dist/web/assets/{PlaygroundPage-BNBySSOX.js → PlaygroundPage-mv9P6czE.js} +1 -1
- package/dist/web/assets/{SettingsPage-B45LFCCd.js → SettingsPage-nT9hvcPA.js} +2 -2
- package/dist/web/assets/{Toolbar-PNBoGf83.js → Toolbar-Hsam79hu.js} +1 -1
- package/dist/web/assets/{VisitorPickerModal-Dxgj3Y61.js → VisitorPickerModal-CqHzml8s.js} +1 -1
- package/dist/web/assets/{check-BCinw6C1.js → check-soiTDN2u.js} +2 -2
- package/dist/web/assets/{copy-B4T4wJbp.js → copy-B4fvX0p8.js} +2 -2
- package/dist/web/assets/{index-B3TBoi2p.css → index-CuXb3X2-.css} +1 -1
- package/dist/web/assets/index-OmOf_og0.js +283 -0
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-CvZrtSgN.js → meta2dEngine-BD2XbzaV-Bq3HuUfD.js} +1 -1
- package/dist/web/assets/{plus-C5AB-V4P.js → plus-DKKQ-AoS.js} +2 -2
- package/dist/web/assets/{react-DKdyUY61.js → react-CI5PDFXT.js} +3 -3
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/AgentChatPanel-wBPfD1N6.js +0 -22
- package/dist/web/assets/AiWriteWorkbench-2tZtS8zc.js +0 -7
- package/dist/web/assets/DocChrome-Bp7n7acp.js +0 -21
- package/dist/web/assets/DocumentEditor-DmwHDhjB.js +0 -1
- package/dist/web/assets/HtmlEditor-DIZ-8-go.js +0 -1
- package/dist/web/assets/index-7ZIkBACf.js +0 -283
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as x,j as i}from"./react-vendor-BuABiQkA.js";import{
|
|
1
|
+
import{r as x,j as i}from"./react-vendor-BuABiQkA.js";import{c as G,aD as H,aE as Y,aF as Z,aG as ee}from"./index-OmOf_og0.js";import{E as te,B as ne}from"./react-CI5PDFXT.js";import{g as le}from"./file-type-policy-GUk904tm.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./editor-CL03se2B.js";import"./plus-DKKQ-AoS.js";import"./check-soiTDN2u.js";import"./copy-B4fvX0p8.js";function U({lexicalJson:e,onMarkdown:n,onError:c}){const[s,l]=x.useState(null),o=x.useRef(!1);return x.useEffect(()=>{o.current=!1},[e]),x.useEffect(()=>{if(!(!s||o.current))try{s.setDocument("json",e);const a=s.getDocument("markdown");typeof a=="string"&&(o.current=!0,n(a))}catch{c==null||c()}},[s,e,n,c]),i.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:i.jsx(te,{content:e,type:"json",editable:!1,onInit:l,plugins:[ne]})})}function se(e){const{t:n}=G(),[c,s]=x.useState(0),l=e.segments.filter(t=>t.kind==="conflict"),o=e.unresolvedCount>0;x.useEffect(()=>{if(l.length===0){s(0);return}s(t=>Math.min(t,l.length-1))},[l.length]);function a(t){l.length!==0&&s(d=>{var m;const u=(d+t+l.length)%l.length;return(m=document.getElementById(`mdocs-merge-hunk-${u}`))==null||m.scrollIntoView({block:"center",behavior:"smooth"}),u})}let r=-1;return i.jsxs("div",{className:"mdocs-merge-inline-pane",children:[i.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[i.jsx("span",{className:"mdocs-merge-inline-hint",children:o?n("mergeReviewHint"):l.length===0?n("mergeNoConflicts"):n("mergeEditAfterResolve")}),l.length>0?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",onClick:e.onUseAllMine,children:n("mergeUseAllMine")}),i.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:n("mergeUseAllTheirs")})]}):null]}),o?i.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((t,d)=>{if(t.kind==="unchanged")return i.jsx("pre",{className:"mdocs-merge-inline-same",children:t.lines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},C))},`u-${d}`);r+=1;const u=r,m=t.resolution!=="unresolved",f=u===c;return i.jsxs("div",{id:`mdocs-merge-hunk-${u}`,className:"mdocs-merge-inline-hunk"+(f?" is-active":"")+(m?" is-resolved":""),onClick:()=>s(u),children:[m?i.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:t.resolution==="remote"?n("mergeReceive"):n("mergeReject")}):i.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:g=>{g.stopPropagation(),e.onReject(t.id)},children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:g=>{g.stopPropagation(),e.onReceive(t.id)},children:n("mergeReceive")})]}),i.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[t.localLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line del",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`l${C}`)),t.remoteLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line add",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`r${C}`))]})]},t.id)}),l.length>0?i.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[i.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>a(-1),children:"↑"}),i.jsxs("span",{children:[c+1," / ",l.length]}),i.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>a(1),children:"↓"}),l[c]&&l[c].resolution==="unresolved"?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(l[c].id),children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(l[c].id),children:n("mergeReceive")})]}):null]}):null]}):i.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:t=>e.onEditableChange(t.target.value),spellCheck:!1})]})}function ie(e,n){let c={};for(let o=0;o<n.length;o++){const a=n[o];c[a]?c[a].push(o):c[a]=[o]}let l=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let o=0;o<e.length;o++){const a=e[o],r=c[a]||[];let t=0,d=l[0];for(let u=0;u<r.length;u++){const m=r[u];let f;for(f=t;f<l.length&&!(l[f].buffer2index<m&&(f===l.length-1||l[f+1].buffer2index>m));f++);if(f<l.length){const g={buffer1index:o,buffer2index:m,chain:l[f]};if(t===l.length?l.push(d):l[t]=d,t=f+1,d=g,t===l.length)break}}l[t]=d}return l[l.length-1]}function O(e,n){const c=ie(e,n);let s=[],l=e.length,o=n.length;for(let a=c;a!==null;a=a.chain){const r=l-a.buffer1index-1,t=o-a.buffer2index-1;l=a.buffer1index,o=a.buffer2index,(r||t)&&s.push({buffer1:[l+1,r],buffer1Content:e.slice(l+1,l+1+r),buffer2:[o+1,t],buffer2Content:n.slice(o+1,o+1+t)})}return s.reverse(),s}function oe(e,n,c){let s=[];function l(t,d){s.push({ab:d,oStart:t.buffer1[0],oLength:t.buffer1[1],abStart:t.buffer2[0],abLength:t.buffer2[1]})}O(n,e).forEach(t=>l(t,"a")),O(n,c).forEach(t=>l(t,"b")),s.sort((t,d)=>t.oStart-d.oStart);let o=[],a=0;function r(t){t>a&&(o.push({stable:!0,buffer:"o",bufferStart:a,bufferLength:t-a,bufferContent:n.slice(a,t)}),a=t)}for(;s.length;){let t=s.shift(),d=t.oStart,u=t.oStart+t.oLength,m=[t];for(r(d);s.length;){const f=s[0],g=f.oStart;if(g>u)break;u=Math.max(u,g+f.oLength),m.push(s.shift())}if(m.length===1){if(t.abLength>0){const f=t.ab==="a"?e:c;o.push({stable:!0,buffer:t.ab,bufferStart:t.abStart,bufferLength:t.abLength,bufferContent:f.slice(t.abStart,t.abStart+t.abLength)})}}else{let f={a:[e.length,-1,n.length,-1],b:[c.length,-1,n.length,-1]};for(;m.length;){t=m.shift();const b=t.oStart,w=b+t.oLength,L=t.abStart,y=L+t.abLength;let v=f[t.ab];v[0]=Math.min(L,v[0]),v[1]=Math.max(y,v[1]),v[2]=Math.min(b,v[2]),v[3]=Math.max(w,v[3])}const g=f.a[0]+(d-f.a[2]),C=f.a[1]+(u-f.a[3]),k=f.b[0]+(d-f.b[2]),h=f.b[1]+(u-f.b[3]);let p={stable:!1,aStart:g,aLength:C-g,aContent:e.slice(g,C),oStart:d,oLength:u-d,oContent:n.slice(d,u),bStart:k,bLength:h-k,bContent:c.slice(k,h)};o.push(p)}a=u}return r(n.length),o}function ce(e,n,c,s){s=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},s),typeof e=="string"&&(e=e.split(s.stringSeparator)),typeof n=="string"&&(n=n.split(s.stringSeparator)),typeof c=="string"&&(c=c.split(s.stringSeparator));let o=[];const a=oe(e,n,c);let r=[];function t(){r.length&&o.push({ok:r}),r=[]}function d(u,m){if(u.length!==m.length)return!1;for(let f=0;f<u.length;f++)if(u[f]!==m[f])return!1;return!0}return a.forEach(u=>{u.stable?r.push(...u.bufferContent):s.excludeFalseConflicts&&d(u.aContent,u.bContent)?r.push(...u.aContent):(t(),o.push({conflict:{a:u.aContent,aIndex:u.aStart,o:u.oContent,oIndex:u.oStart,b:u.bContent,bIndex:u.bStart}}))}),t(),o}const ae=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function re(e){return`<!-- mdocs-merge-conflict:${e} -->`}function ue(e){const n=e.trim().match(ae);return(n==null?void 0:n[1])??null}function E(e){return e===""?[]:e.split(`
|
|
2
2
|
`)}function V(e,n){return e.length===n.length&&e.every((c,s)=>c===n[s])}function de(e,n,c){const s=E(e),l=E(n),o=E(c);if(l.length===0&&n==="")return me(e,c);const a=ce(s,l,o),r=[];let t=0,d=0,u=0,m=0;const f=(C,k,h,p)=>{r.push({kind:"conflict",id:`conflict-${t}`,conflictKind:p,baseLines:C,localLines:k,remoteLines:h,resolution:"unresolved"}),t+=1},g=(C,k,h)=>{if(k.length===0&&C.length===0&&h.length===0)return;if(V(C,k)&&V(h,k)){k.length>0&&r.push({kind:"unchanged",lines:[...k]});return}if(C.length===k.length&&h.length===k.length){let b=[];const w=()=>{b.length>0&&(r.push({kind:"unchanged",lines:b}),b=[])};for(let L=0;L<k.length;L+=1){const y=k[L],v=C[L],I=h[L];v===y&&I===y?b.push(y):(w(),f([y],[v],[I],v!==y&&I!==y&&v!==I?"true_conflict":"change"))}w();return}const p=C.join(`
|
|
3
3
|
`)!==k.join(`
|
|
4
4
|
`)&&h.join(`
|
|
@@ -7,4 +7,4 @@ import{r as x,j as i}from"./react-vendor-BuABiQkA.js";import{b as K,aB as H,aC a
|
|
|
7
7
|
`)!==h.join(`
|
|
8
8
|
`)?"true_conflict":"change";f(k,C,h,p)};for(let C=0;C<a.length;C+=1){const k=a[C],h=k.conflict;if(h){g(s.slice(d,h.aIndex),l.slice(u,h.oIndex),o.slice(m,h.bIndex)),f(h.o,h.a,h.b,"true_conflict"),d=h.aIndex+h.a.length,u=h.oIndex+h.o.length,m=h.bIndex+h.b.length;continue}if(k.ok){const p=a[C+1],b=p==null?void 0:p.conflict;b?(g(s.slice(d,b.aIndex),l.slice(u,b.oIndex),o.slice(m,b.bIndex)),d=b.aIndex,u=b.oIndex,m=b.bIndex):(g(s.slice(d),l.slice(u),o.slice(m)),d=s.length,u=l.length,m=o.length)}}return r}function fe(e,n){const c=e.length,s=n.length,l=Array.from({length:c+1},()=>new Array(s+1).fill(0));for(let t=1;t<=c;t+=1)for(let d=1;d<=s;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 o=[];let a=c,r=s;for(;a>0||r>0;)a>0&&r>0&&e[a-1]===n[r-1]?(o.push({type:"equal",line:e[a-1]}),a-=1,r-=1):r>0&&(a===0||l[a][r-1]>=l[a-1][r])?(o.push({type:"add",line:n[r-1]}),r-=1):(o.push({type:"del",line:e[a-1]}),a-=1);return o.reverse()}function me(e,n){const c=E(e),s=E(n),l=fe(c,s),o=[];let a=0,r=0;for(;r<l.length;){if(l[r].type==="equal"){const m=[];for(;r<l.length&&l[r].type==="equal";)m.push(l[r].line),r+=1;o.push({kind:"unchanged",lines:m});continue}const d=[],u=[];for(;r<l.length&&l[r].type!=="equal";){const m=l[r];m.type==="del"&&d.push(m.line),m.type==="add"&&u.push(m.line),r+=1}o.push({kind:"conflict",id:`conflict-${a}`,conflictKind:"true_conflict",baseLines:[],localLines:d,remoteLines:u,resolution:"unresolved"}),a+=1}return o}function he(e){return e.filter(n=>n.kind==="conflict").length}function ge(e){return e.filter(n=>n.kind==="conflict"&&n.resolution==="unresolved").length}function be(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 xe(e){const n=[];for(const c of e)c.kind==="unchanged"?n.push(...c.lines):c.resolution==="unresolved"?n.push(re(c.id)):n.push(...be(c));return n.join(`
|
|
9
9
|
`)}function W(e){return E(e).filter(n=>!ue(n)).join(`
|
|
10
|
-
`)}function
|
|
10
|
+
`)}function B(e,n,c,s){return e.map(l=>l.kind!=="conflict"||l.id!==n?l:{...l,resolution:c,manualLines:c==="manual"?l.manualLines??[]:void 0})}function Ee(e){var _;const{t:n}=G(),s=(((_=le(e.fileType??"md"))==null?void 0:_.mergePipeline)??"lexical-md-bridge")==="raw-text",[l,o]=x.useState(""),[a,r]=x.useState(""),[t,d]=x.useState(null),[u,m]=x.useState(!1),[f,g]=x.useState(!1),[C,k]=x.useState(null),[h,p]=x.useState(""),[b,w]=x.useState(null),[L,y]=x.useState(null),[v,I]=x.useState(!1),[A,M]=x.useState(!0);x.useEffect(()=>{let S=!1;return M(!0),k(null),p(""),w(null),y(null),(async()=>{try{const j=await H(e.documentId);if(S)return;s?(p(j.content),M(!1)):k(j.content)}catch{S||e.onError(n("mergeLoadRemoteFailed")),S||M(!1)}})(),()=>{S=!0}},[e.documentId,e.onError,n,s]),x.useEffect(()=>{let S=!1;return d(null),r(""),m(!1),g(!1),(async()=>{try{const j=await Y(e.documentId,e.conflict.localBaseCommitId,e.conflict.remoteCommitId);if(S)return;if(j.mode==="three_way"&&j.mergeBaseContent){s?(r(j.mergeBaseContent),g(!0)):d(j.mergeBaseContent);return}m(!0),g(!0)}catch{if(S)return;m(!0),g(!0)}})(),()=>{S=!0}},[e.documentId,e.conflict.localBaseCommitId,e.conflict.remoteCommitId,s]),x.useEffect(()=>{s&&o(e.conflict.localSnapshotContent)},[s,e.conflict.localSnapshotContent]);const K=x.useCallback(S=>{p(S),M(!1)},[]),z=x.useCallback(S=>{o(S)},[]),J=x.useCallback(S=>{r(S),g(!0)},[]),Q=x.useCallback(()=>{m(!0),r(""),g(!0)},[]);x.useEffect(()=>{!l||!h||A||!f||(w(de(l,a,h)),y(null))},[l,h,a,f,A,e.conflict.remoteCommitId]);const P=x.useMemo(()=>b?W(xe(b)):"",[b]),F=b?he(b):0,N=b?ge(b):0,$=L??P;x.useEffect(()=>{N===0&&b&&L===null&&y(P)},[N,b,P,L]);function D(S){w(j=>{if(!j)return j;let R=j;for(const q of j)q.kind==="conflict"&&(R=B(R,q.id,S));return R}),y(null)}async function X(){if(N>0){e.onError(n("mergeConflictsUnresolved",{count:String(N)}));return}const S=W($);I(!0);try{const j=s?S:(await Z({content:S,from:"markdown",to:"lexical"})).content;await ee(e.documentId,{content:j,displayName:e.displayName,version:{localBaseCommitId:e.conflict.localBaseCommitId,merge:{remoteCommitId:e.conflict.remoteCommitId,localSnapshotContent:e.conflict.localSnapshotContent}}});const R=await H(e.documentId);e.onSuccess(R)}catch(j){e.onError(j instanceof Error?j.message:String(j))}finally{I(!1)}}const T=!!(l&&h&&b&&!A&&f);return i.jsxs("div",{className:"mdocs-merge-overlay",children:[s?null:i.jsxs(i.Fragment,{children:[i.jsx(U,{lexicalJson:e.conflict.localSnapshotContent,onMarkdown:z,onError:()=>e.onError(n("mergeLoadLocalFailed"))}),t?i.jsx(U,{lexicalJson:t,onMarkdown:J,onError:Q}):null,C?i.jsx(U,{lexicalJson:C,onMarkdown:K,onError:()=>{M(!1),e.onError(n("mergeLoadRemoteFailed"))}}):null]}),i.jsxs("header",{className:"mdocs-merge-toolbar",children:[i.jsxs("div",{className:"mdocs-merge-toolbar-title",children:[i.jsx("h2",{children:n("mergeTitle")}),T&&F>0?i.jsx("span",{className:`mdocs-merge-conflict-pill ${N>0?"pending":"resolved"}`,children:N>0?n("mergeConflictsPending",{unresolved:String(N),total:String(F)}):n("mergeConflictsResolved",{total:String(F)})}):null,u?i.jsx("span",{className:"mdocs-merge-base-warning",children:n("mergeBaseMissing")}):null]}),i.jsxs("div",{className:"mdocs-merge-toolbar-actions",children:[i.jsx("button",{type:"button",className:"secondary",disabled:v,onClick:e.onClose,children:n("cancel")}),i.jsx("button",{type:"button",className:"primary",disabled:v||!T||N>0,onClick:()=>void X(),children:n(v?"publishing":"mergeComplete")})]})]}),i.jsx("div",{className:"mdocs-merge-body mdocs-merge-body--inline",children:T?i.jsx(se,{segments:b,unresolvedCount:N,onReceive:S=>{w(j=>j&&B(j,S,"remote")),y(null)},onReject:S=>{w(j=>j&&B(j,S,"local")),y(null)},onUseAllMine:()=>D("local"),onUseAllTheirs:()=>D("remote"),editableMarkdown:$,onEditableChange:y}):i.jsx("p",{className:"mdocs-merge-loading",children:n("mergeLoadingRemote")})})]})}export{Ee as MergeView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as n,j as o,ad as C}from"./react-vendor-BuABiQkA.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-
|
|
1
|
+
import{r as n,j as o,ad as C}from"./react-vendor-BuABiQkA.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-CI5PDFXT.js";import{a7 as Q,a8 as X,a9 as ee,aa as te,ab as k,ac as oe}from"./ui-CvA4pq3d.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,c as R,o as ce}from"./Toolbar-Hsam79hu.js";import{N as me}from"./index-OmOf_og0.js";import"./editor-CL03se2B.js";import"./diagram-Bk84WZto.js";import"./plus-DKKQ-AoS.js";import"./check-soiTDN2u.js";import"./copy-B4fvX0p8.js";import"./motion-DFABYlwt.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[g,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:g,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,g]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");g(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(J,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(W,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{ce(l=>{for(const u of l)e.dispatchCommand(z,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
|
|
2
2
|
123`),queueMicrotask(()=>{e.focus()})}},{key:"insert-link",label:"InsertLink",onSelect:e=>{e.dispatchCommand(B,{url:"https://example.com"}),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeInline",label:"InsertCodeInline",onSelect:e=>{e.dispatchCommand($,void 0),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeBlock",label:"InsertCodeBlock",onSelect:e=>{e.dispatchCommand(K,void 0),queueMicrotask(()=>{e.focus()})}},{icon:de,key:"meta2d",label:"Meta2d",onSelect:e=>{e.dispatchCommand(Y,void 0),queueMicrotask(()=>{e.focus()})}},{icon:me,key:"markmap",label:"Markmap",onSelect:e=>{e.dispatchCommand(G,void 0),queueMicrotask(()=>{e.focus()})}}].map(e=>e.type==="divider"?e:{...e,extra:o.jsx(oe,{code:!0,fontSize:12,type:"secondary",children:e.key})}),[]);return o.jsxs(ue,{json:m,markdown:p,onJSONChange:s,...h,children:[o.jsx(R,{editor:r}),o.jsx(T,{className:"mdocs-playground-editor",content:ye,editor:r,lineEmptyPlaceholder:"Start typing here...",mentionOption:{items:d,markdownWriter:t=>{var e;return`
|
|
3
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,L,f(H,{children:o.jsx(R,{editor:r,floating:!0})}),f(F,{delay:1e3,onAutoComplete:async({input:t,afterText:e,selectionType:l,abortSignal:u})=>{console.log("Auto-complete triggered:",{afterText:e,input:t,selectionType:l});try{const v=await fetch(`${location.origin}/nodeserver/completion`,{body:JSON.stringify({prompt:`Please complete the following text:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{r as a,j as e}from"./react-vendor-BuABiQkA.js";import{
|
|
1
|
+
import{r as a,j as e}from"./react-vendor-BuABiQkA.js";import{o as bs,c as ie,t as Ns,v as vs,p as ks,l as Ae,w as ws,x as Ss,y as Q,z as Pe,A as Cs,B as Ds,G as Is,a as Ts,d as Oe,H as Ye,I as qe,J as As,K as Ps,L as Ms,O as Es,Q as Rs,T as Xe,U as Ie,V as Ls,W as Fs,X as zs,Y as Bs,Z as $s,_ as Ks,f as Qe,$ as Os,a0 as Vs,a1 as Us,a2 as Ws,a3 as _s,a4 as es,a5 as Gs,a6 as Hs,a7 as Js,a8 as Zs,a9 as Ys,aa as qs,ab as Xs,ac as Qs,ad as et,ae as st,af as tt,ag as at,ah as nt,P as it,ai as ct,aj as lt,ak as ot,r as rt,j as dt,al as mt,k as ut,m as ht}from"./index-OmOf_og0.js";import{V as ss,a as pt,M as Ve}from"./VisitorPickerModal-CqHzml8s.js";import{C as gt}from"./check-soiTDN2u.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";/**
|
|
2
2
|
* @license lucide-react v0.562.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const ft=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],xt=bs("search",ft);function jt({draft:t,onClose:s,onSuccess:j}){const{t:d,lang:p}=ie(),[B,u]=a.useState([]),[w,N]=a.useState(t.domainId??""),[g,k]=a.useState([]),[T,S]=a.useState(""),[c,x]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[o,h]=a.useState(!1),[I,A]=a.useState(null),y=a.useRef(null),M=a.useRef(!0);a.useEffect(()=>(M.current=!0,()=>{M.current=!1}),[]),a.useEffect(()=>{Ns().then(v=>{M.current&&u(v)})},[]),a.useEffect(()=>{w&&(k([]),S(""),vs(w).then(v=>{M.current&&k(v)}).catch(()=>{M.current&&k([])}))},[w]),a.useEffect(()=>{const v=window.setTimeout(()=>{var P;return(P=y.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(v)},[]),a.useEffect(()=>{const v=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[s]);function z(v,P){for(const C of v){if(C.type==="folder"&&C.path===P)return C.documentId;if(C.type==="folder"){const E=z(C.children,P);if(E)return E}}return null}async function F(v){v.preventDefault(),h(!0),A(null);const P=c.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),C=P.endsWith(".md")?P:P+".md",E=C.replace(/\.md$/i,"");try{const m=T?`${T}/${C}`:C,l=T?z(g,T)??void 0:void 0;await Ss({fileName:C,displayName:E,content:t.content,domainId:w,parentId:l}),j()}catch(m){A(X(d,m))}finally{h(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:v=>{v.target===v.currentTarget&&!o&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:d("recoverDraft")}),e.jsx("p",{className:"muted",children:d("recoverDraftDesc",{name:t.displayName||d("unknownTitle")})}),e.jsxs("form",{onSubmit:F,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[d("domainLabel"),B.length>0&&e.jsx(ks,{domains:B,value:w,onChange:N,onDomainsChange:u,ariaLabel:d("domainLabel"),localizeName:v=>Ae(v,p,d)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[d("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(ws,{nodes:g,activeDocumentId:null,selectedParentPath:T,onOpen:()=>{},onOpenFolder:v=>S(v),onContextMenu:()=>{},onDeselect:()=>S("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[d("fileNameLabel"),e.jsx("input",{ref:y,value:c,onChange:v=>x(v.target.value),placeholder:"recovered.md",maxLength:200,disabled:o})]}),I&&e.jsx("div",{className:"mdocs-dialog-error",children:I}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!o&&s(),disabled:o,children:d("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:o,children:d(o?"creating":"create")})]})]})]})})}function yt({onPublish:t,onClose:s,onCountChange:j,onRecover:d}){const{t:p}=ie(),[B,u]=a.useState([]),[w,N]=a.useState(new Set),[g,k]=a.useState(!1),[T,S]=a.useState(null),[c,x]=a.useState(null),[o,h]=a.useState(null),I=a.useRef(null),A=a.useRef(!0);a.useEffect(()=>(A.current=!0,Pe().then(l=>{if(!A.current)return;const f=l.filter(D=>!D.published);u(f),j==null||j(f.length)}),()=>{A.current=!1,I.current&&(clearTimeout(I.current),I.current=null)}),[]),a.useEffect(()=>{const l=f=>{f.key==="Escape"&&s()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[s]);const y=a.useCallback((l,f)=>{h({message:l,type:f}),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>h(null),3e3)},[]);async function M(l){await Ds(l),N(f=>new Set(f).add(l));try{await t(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),y(p("published"),"success")}catch(f){f instanceof Is||y(p("publishFailed"),"error");const D=await Ts(l);D&&u($=>$.map(U=>U.documentId===l?D:U))}finally{N(f=>{const D=new Set(f);return D.delete(l),D})}}async function z(l){S(null),await Oe(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),y(p("draftDeleted"),"success")}function F(l){const f=B.find(D=>D.documentId===l);f&&x(f)}function v(l){x(null),Oe(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),d==null||d(B.find(f=>f.documentId===l)),y(p("published"),"success")}async function P(){k(!0);let l=0,f=0;for(const U of B)try{await t(U.documentId),l++}catch{f++}const $=(await Pe()).filter(U=>!U.published);u($),j==null||j($.length),f===0?y(p("publishAll"),"success"):y(`${l} published, ${f} failed`,"error"),k(!1)}const C=l=>new Date(l).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),E=l=>Cs(p,l,l.publishError??"UNKNOWN"),m=B;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:[p("unpublishedDrafts"),m.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:m.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:p("draftCount",{count:String(m.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":p("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:m.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:p("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:m.map(l=>{const f=!!l.publishError;return e.jsxs("div",{className:f?"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:l.displayName||p("unknownTitle")}),f?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[C(l.publishErrorAt)," · ",E(l)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[C(l.updatedAt)," · ",p("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[f?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:g,onClick:()=>F(l.documentId),children:p("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:w.has(l.documentId)||g,onClick:()=>void M(l.documentId),children:w.has(l.documentId)?p("publishing"):p("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:g,onClick:()=>S(l.documentId),children:p("delete")})]})]},l.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:p("close")}),e.jsx("button",{type:"button",className:"primary",disabled:m.length===0||g,onClick:()=>void P(),children:g?p("publishing"):`${p("publishAll")} (${m.length})`})]}),o&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+o.type,role:"status",children:o.message})]}),T&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:l=>{l.target===l.currentTarget&&S(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:p("delete")}),e.jsx("p",{className:"muted",children:p("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>S(null),children:p("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void z(T),children:p("delete")})]})]})}),c&&e.jsx(jt,{draft:c,onClose:()=>x(null),onSuccess:()=>v(c.documentId)})]})}function bt(){const{t,lang:s}=ie(),j=qe(),d=a.useRef(!1),[p,B]=a.useState([]),[u,w]=a.useState(!1),[N,g]=a.useState(""),[k,T]=a.useState("restricted"),[S,c]=a.useState(!1),[x,o]=a.useState(null),[h,I]=a.useState(null),[A,y]=a.useState(""),[M,z]=a.useState(""),[F,v]=a.useState("all"),[P,C]=a.useState(null);a.useEffect(()=>(d.current=!0,()=>{d.current=!1}),[]);const E=a.useCallback(async()=>{w(!0),o(null);try{const b=await Ye();if(!d.current)return;B(b)}catch(b){if(!d.current)return;o(X(t,b))}finally{d.current&&w(!1)}},[t]);a.useEffect(()=>{E()},[E]);async function m(b){if(b.preventDefault(),!N.trim()){o(t("domainNameRequired"));return}c(!0),o(null);try{if(await Rs({domainName:N.trim(),permission:k}),!d.current)return;g(""),T("restricted"),await E()}catch(K){if(!d.current)return;o(X(t,K))}finally{d.current&&c(!1)}}async function l(b){if(A.trim()){o(null);try{if(await Es(b,A.trim()),!d.current)return;I(null),C(null),await E()}catch(K){if(!d.current)return;o(X(t,K))}}}function f(b){I(b.domainId),y(b.domainName),C(null)}function D(){I(null),C(null)}async function $(b,K){o(null);try{if(await Ms(b,K),!d.current)return;C(null),await E()}catch(W){if(!d.current)return;o(X(t,W))}}async function U(b){if(window.confirm(t("deleteDomainConfirmDetail",{name:b.domainName,count:String(b.docCount)}))){o(null);try{if(await Ps(b.domainId),!d.current)return;await E()}catch(K){if(!d.current)return;o(X(t,K))}}}const Z=a.useCallback(b=>As(b,t),[t]),q=a.useCallback(b=>Ae(b.domainName,s,t),[s,t]),Y=a.useMemo(()=>{const b=M.trim().toLowerCase();return p.filter(K=>F!=="all"&&K.permission!==F?!1:b?Ae(K.domainName,s,t).toLowerCase().includes(b)||K.domainName.toLowerCase().includes(b):!0)},[p,M,F,s,t]),_=a.useCallback((b,K)=>{const W=Z(b.permission);return K?`${W} ${t("domainTypeBuiltinSuffix")}`:W},[Z,t]);return{domains:p,loadingDomains:u,domainError:x,newDomainName:N,setNewDomainName:g,newDomainPermission:k,setNewDomainPermission:T,creating:S,handleCreateDomain:m,renamingId:h,setRenamingId:I,renameDraft:A,setRenameDraft:y,startRename:f,cancelRename:D,handleRename:l,changeTypeForId:P,setChangeTypeForId:C,handlePermissionChange:$,handleDelete:U,domainSearch:M,setDomainSearch:z,domainFilter:F,setDomainFilter:v,filteredDomains:Y,visitorId:j,plabel:Z,localizeDomain:q,domainTypeLabel:_}}const Ue={private:0,restricted:1,public:2};function We(t){return Object.prototype.hasOwnProperty.call(Ue,t)?Ue[t]:null}function _e(t,s){const j=We(t),d=We(s);return j===null||d===null?"invalid":d>j?"upgrade":d<j?"downgrade":"same"}function Nt(){const{t}=ie(),s=bt(),[j,d]=a.useState([]),[p,B]=a.useState(null),[u,w]=a.useState(""),N=a.useRef(null),[g,k]=a.useState(null),T=a.useCallback(async()=>{try{const c=await Qe();d(c)}catch{d([])}},[]);a.useEffect(()=>{T()},[T]),a.useEffect(()=>{if(!s.changeTypeForId)return;const c=x=>{var o;(o=N.current)!=null&&o.contains(x.target)||s.setChangeTypeForId(null)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s.changeTypeForId,s.setChangeTypeForId]);async function S(c){B(null);try{const x=await Ks(c.domainId);k({domainId:c.domainId,creatorVisitorId:c.creatorVisitorId,initialIds:x.map(o=>o.visitorId),memberRows:x})}catch(x){B({kind:"err",text:translateError(t,x)})}}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:c=>s.setNewDomainName(c.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:Ie.map(c=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===c,onChange:()=>s.setNewDomainPermission(c),disabled:s.creating}),e.jsx("span",{children:s.plabel(c)})]},c))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?t("creating"):t("create")})]})]}),p&&e.jsx("div",{className:"mdocs-settings-card",style:{color:p.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:p.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:c=>s.setDomainSearch(c.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",...Ie].map(c=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===c?" active":""),"aria-pressed":s.domainFilter===c,onClick:()=>s.setDomainFilter(c),children:c==="all"?t("domainFilterAll"):s.plabel(c)},c))})]}),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(c=>{const x=Ls(c,s.visitorId),o=Fs(c.domainId),h=zs(c),I=_e(c.permission,"public")==="upgrade",A=I?h?t("domainTooltipTypeLocked"):void 0:t("domainPermissionAlreadyTop");return e.jsxs("tr",{className:o?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===c.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:y=>s.setRenameDraft(y.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(c.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(c)}),o&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!x&&!o&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsx("span",{className:"mdocs-domain-table-type",title:A,children:e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":c.permission,children:s.domainTypeLabel(c,o)})})}),e.jsx("td",{className:"mdocs-domain-table-num",children:c.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[o&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!o&&!x&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!o&&x&&s.changeTypeForId===c.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",ref:N,children:[e.jsx("div",{className:"mdocs-domain-type-segment",role:"radiogroup","aria-label":t("domainChangeType"),children:Ie.map(y=>{const z=_e(c.permission,y)==="downgrade";return e.jsx("span",{title:z?t("domainPermissionNoDowngrade"):void 0,children:e.jsx("button",{type:"button",role:"radio","aria-checked":u===y,className:u===y?"active":"",disabled:z,onClick:()=>w(y),children:s.plabel(y)})},y)})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon confirm","aria-label":t("save"),disabled:u===""||u===c.permission,onClick:()=>{u&&u!==c.permission&&s.handlePermissionChange(c.domainId,u)},children:e.jsx(gt,{size:14,strokeWidth:2.5})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon cancel","aria-label":t("cancel"),onClick:()=>s.setChangeTypeForId(null),children:e.jsx(Bs,{size:14,strokeWidth:2.5})})]}),!o&&x&&s.renamingId!==c.domainId&&s.changeTypeForId!==c.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[c.permission==="restricted"&&e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--primary",onClick:()=>void S(c),children:t("domainMembersManageButton")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:h?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(c)},disabled:h,children:t("rename")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:A,onClick:()=>{s.setRenamingId(null),w(c.permission),s.setChangeTypeForId(c.domainId)},disabled:!I,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--danger",title:h?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(c),disabled:h,children:t("deleteDomain")})]})]})]},c.domainId)})})]})})]}),e.jsx(ss,{open:g!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(g==null?void 0:g.initialIds)??[],lockedIds:g?[g.creatorVisitorId]:[],seedMembers:g==null?void 0:g.memberRows,templates:j,onClose:()=>k(null),onConfirm:async c=>{g&&(await $s(g.domainId,c),B({kind:"ok",text:t("domainMembersSaved",{count:String(c.length)})}))}})]})}function Ge(t){return t.length<=6?t:`${t.slice(0,6)}…`}function vt(){const{t}=ie(),s=a.useRef(!0),[j,d]=a.useState([]),[p,B]=a.useState(!0),[u,w]=a.useState(null),[N,g]=a.useState(1),[k,T]=a.useState(null),[S,c]=a.useState(""),[x,o]=a.useState([]),[h,I]=a.useState(!1),[A,y]=a.useState(null),[M,z]=a.useState(!1),F=qe(),[v,P]=a.useState([]),[C,E]=a.useState("idle"),[m,l]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{E("loading"),Xe().then(r=>{s.current&&(P(r),E("ok"))}).catch(()=>{s.current&&E("err")})},[]);const f=a.useMemo(()=>{const r=new Map;for(const R of v)r.set(R.visitorId,R.visitorName);return r},[v]),D=a.useCallback(async()=>{B(!0),y(null);try{const r=await Qe();s.current&&d(r)}catch(r){s.current&&y(X(t,r))}finally{s.current&&B(!1)}},[t]);a.useEffect(()=>{D()},[D]);const $=a.useMemo(()=>x.map(r=>{const R=v.find(O=>O.visitorId===r);return{visitorId:r,name:R?R.visitorName:t("visitorPickerUnknownVisitor"),muted:!R}}),[x,v,t]);function U(r){o(R=>R.includes(r)?R.filter(O=>O!==r):[...R,r])}const Z=N===1?S.trim().length>0:N===2?x.length>0:!0;function q(){if(!(N>=3)){if(!Z){z(!0);return}z(!1),g(N+1),l("")}}function Y(){N<=1||(z(!1),g(N-1))}function _(){w(null),T(null),c(""),o(F?[F]:[]),y(null),g(1),l(""),z(!1)}function b(r){w(null),T(r.id),c(r.displayName);const R=F&&!r.visitorIds.includes(F)?[...r.visitorIds,F]:[...r.visitorIds];o(R),y(null),g(1),l(""),z(!1)}async function K(){if(!(!S.trim()||x.length===0)){I(!0),y(null);try{if(k===null?await Os({displayName:S.trim(),visitorIds:x}):await Vs(k,{displayName:S.trim(),visitorIds:x}),!s.current)return;_(),await D()}catch(r){if(!s.current)return;y(X(t,r))}finally{s.current&&I(!1)}}}async function W(r){I(!0),y(null);try{if(await Us(r),!s.current)return;w(null),k===r&&_(),await D()}catch(R){if(!s.current)return;y(X(t,R))}finally{s.current&&I(!1)}}const Q=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],ee=`${(N-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(k!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),k!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:_,style:{fontSize:12},children:t("memberTemplateCancelEdit")})]}),e.jsxs("div",{className:"mdocs-wizard-progress",children:[e.jsx("div",{className:"mdocs-wizard-progress-track",children:e.jsx("div",{className:"mdocs-wizard-progress-fill",style:{width:ee}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:Q.map(r=>{const R=N===r.key,O=N>r.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${R?" current":""}${O?" done":""}`,children:O?"✓":r.key}),e.jsx("span",{className:`mdocs-wizard-step-label${R?" current":""}${O?" done":""}`,children:r.label})]},r.key)})})]}),A&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:A}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[N===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:S,onChange:r=>c(r.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:h,autoFocus:!0,"aria-invalid":M&&!S.trim()}),M&&!S.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),N===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(pt,{visitors:v,loadState:C,searchFilter:m,onSearchChange:l,selectedIds:new Set(x),onToggle:U,selectedRows:$,myVisitorId:F}),e.jsx("p",{className:`mdocs-wizard-hint${M&&x.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),N===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:S})]}),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(x.length)})})]}),x.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[x.slice(0,15).map(r=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:Ge(r)},r)),x.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",x.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:Y,children:["← ",t("memberTemplateWizardBack")]}),N<3?e.jsxs("button",{type:"button",className:"primary",onClick:q,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void K(),children:t(h?"saving":k===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),p?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):j.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),k===null&&e.jsx("button",{type:"button",className:"primary",onClick:_,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:j.map(r=>e.jsx("li",{className:"mdocs-member-template-row",children:u===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(h?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(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(R=>e.jsx("span",{className:"mdocs-member-template-tag",children:f.get(R)??Ge(R)},R))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>b(r),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(r.id),children:t("memberTemplateDelete")})]})]})},r.id))})]})]})]})}const kt=[{value:"deepseek-flash",label:"deepseek-flash(V4.1 Flash)"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro(将路由至 Flash)"}],wt=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function St(t,s,j){return t==="deepseek"?"Deepseek":s||j}function He(t){return`${St(t.kind,t.providerId,t.name)} · ${t.modelId} · ${t.name}`}function Ct(){const{t}=ie(),s=a.useRef(!0),[j,d]=a.useState(""),[p,B]=a.useState([]),[u,w]=a.useState(null),[N,g]=a.useState(null),[k,T]=a.useState("deepseek"),[S,c]=a.useState(""),[x,o]=a.useState(""),[h,I]=a.useState(""),[A,y]=a.useState("openai-completions"),[M,z]=a.useState("deepseek-flash"),[F,v]=a.useState(1e6),[P,C]=a.useState(""),[E,m]=a.useState(!1),[l,f]=a.useState(null),[D,$]=a.useState(!1),[U,Z]=a.useState(!0),[q,Y]=a.useState(!1),[_,b]=a.useState(null),[K,W]=a.useState(!1),[Q,ee]=a.useState(!1),[r,R]=a.useState(!1),[O,ce]=a.useState(null),[ue,oe]=a.useState(null),re=a.useRef(!1);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const se=a.useCallback(async()=>{const i=await Ws();if(s.current)return B(i),i},[]);function te(){g(null),T("deepseek"),c(""),o(""),I(""),y("openai-completions"),z("deepseek-flash"),v(1e6),C(""),m(!1),f(null),$(!1),ee(!1),R(!1),b(null),W(!1)}function he(i){g(i.id),T(i.kind),c(i.name),o(i.providerId??""),I(i.baseUrl),y(i.apiType);const V=i.modelId.trim(),fe=new Set(["deepseek-flash","deepseek-v4-flash","deepseek-v4-flash-vision-exp","deepseek-v4.1-flash","deepseek-v4.1-flash-expires-on-0910"]);z(i.kind==="deepseek"?V==="deepseek-v4-pro"?"deepseek-v4-pro":fe.has(V)?"deepseek-flash":V||"deepseek-flash":V),v(i.contextWindow||1e6),m(i.hasApiKey),f(i.apiKeyMasked),C(""),$(i.isDefault)}a.useEffect(()=>{(async()=>{try{const i=await _s();if(!s.current)return;d(i.visitorName);const V=await se();if(!s.current||!V)return;V.length===0&&(te(),w("create"))}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i)),w("create")}finally{s.current&&Z(!1)}})()},[se]);function ye(){te(),w("create")}function pe(i){he(i),w("edit"),W(!1),b(null)}function ae(){te(),w(null)}async function be(i){if(!(i.isDefault||ue)){oe(i.id),b(null);try{await Gs(i.id),await se()}catch(V){if(!s.current)return;b(V instanceof Error?V.message:String(V))}finally{s.current&&oe(null)}}}async function ge(){if(O){Y(!0),b(null);try{await Js(O.id);const i=await se();if(!s.current)return;u==="edit"&&N===O.id&&ae(),((i==null?void 0:i.length)??0)===0&&(te(),w("create"))}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i))}finally{s.current&&(Y(!1),ce(null))}}}async function Ne(){Y(!0),b(null),W(!1);try{const i=k==="custom"?{...u==="edit"&&N?{id:N}:{},...u==="create"&&D?{isDefault:!0}:{},kind:k,baseUrl:h,modelId:M,providerId:x.trim()||void 0,apiType:A,name:S,contextWindow:F,...P.trim()?{apiKey:P.trim()}:{}}:{...u==="edit"&&N?{id:N}:{},...u==="create"&&D?{isDefault:!0}:{},kind:k,modelId:M,name:S,contextWindow:F,...P.trim()?{apiKey:P.trim()}:{}};if(await Hs(i),!s.current)return;await se(),W(!0),w(null),te()}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i))}finally{s.current&&Y(!1)}}const de=u!==null;return e.jsxs("div",{className:"mdocs-agent-config-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:t("agentConfig")}),!U&&!de?e.jsx("button",{type:"button",className:"secondary",onClick:ye,children:"添加配置"}):null]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!U&&p.length>0&&!de?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:"选择默认配置后,智能助手与帮写将使用该模型。"}),e.jsx("ul",{className:"mdocs-agent-config-list",children:p.map(i=>e.jsxs("li",{className:"mdocs-agent-config-item",children:[e.jsxs("label",{className:"mdocs-agent-config-item-default",children:[e.jsx("input",{type:"radio",name:"agent-default-config",checked:i.isDefault,disabled:ue!==null,onChange:()=>void be(i)}),e.jsx("span",{children:i.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:He(i)}),i.kind==="custom"?e.jsx("span",{className:"mdocs-agent-badge",children:"自定义"}):null,e.jsx("p",{className:"mdocs-agent-config-item-meta",children:i.hasApiKey?`Key ${i.apiKeyMasked??"已配置"}`:"未配置 Key"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>pe(i),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>ce(i),children:"删除"})]})]},i.id))}),K?e.jsx("p",{className:"mdocs-agent-config-ok",children:t("saved")}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null]}):null,de?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:u==="create"?"新建模型配置":"编辑模型配置"}),e.jsxs("div",{className:"mdocs-agent-form",children:[e.jsxs("div",{className:"mdocs-agent-kind-tabs",role:"tablist","aria-label":"配置方式",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":k==="deepseek",className:k==="deepseek"?"active":"",onClick:()=>T("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":k==="custom",className:k==="custom"?"active":"",onClick:()=>T("custom"),children:"自定义"})]}),k==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigModel")}),e.jsx(Ve,{options:[...kt],value:M,onChange:z})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:Q?"text":"password",value:P,onChange:i=>C(i.target.value),placeholder:E?t("agentConfigApiKeyConfigured").replace("{{masked}}",l??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(Q?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>ee(i=>!i),children:Q?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:h,onChange:i=>{const V=i.target.value;if(I(V),re.current)return;V.toLowerCase().includes("anthropic")?y("anthropic-messages"):y("openai-completions")},placeholder:"https://api.example.com/v1",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Model ID"}),e.jsx("input",{type:"text",value:M,onChange:i=>z(i.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:Q?"text":"password",value:P,onChange:i=>C(i.target.value),placeholder:E?t("agentConfigApiKeyConfigured").replace("{{masked}}",l??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(Q?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>ee(i=>!i),children:Q?"隐藏":"显示"})]})]})]}),e.jsxs("details",{className:"mdocs-agent-advanced",open:r,onToggle:i=>R(i.target.open),children:[e.jsx("summary",{children:"高级选项"}),k==="custom"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Provider ID(选填)"}),e.jsx("input",{type:"text",value:x,onChange:i=>o(i.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Ve,{options:[...wt],value:A,onChange:i=>{re.current=!0,y(i)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigName")}),e.jsx("input",{type:"text",value:S,onChange:i=>c(i.target.value),placeholder:t("agentConfigNameDefault").replace("{{name}}",j||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:F,onChange:i=>v(Number(i.target.value)||1e6)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:t("agentConfigContextWindowDesc")})]})]}),u==="create"&&p.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:i=>$(i.target.checked)}),e.jsx("span",{children:"保存后设为默认配置"})]}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null,e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void Ne(),disabled:q,children:t(q?"saving":"save")}),p.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:ae,disabled:q,children:t("cancel")}):null]})]})]}):U?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:t("loading")})}):null]}),O?e.jsx(es,{title:"删除配置",message:`确定删除「${He(O)}」?${O.isDefault&&p.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:t("cancel"),onConfirm:()=>void ge(),onCancel:()=>ce(null)}):null]})}const Dt=/^[A-Za-z0-9_]+$/;function Te(t){return Dt.test(t.trim())}function It(){const t=a.useRef(!0),[s,j]=a.useState([]),[d,p]=a.useState(!0),[B,u]=a.useState(null),[w,N]=a.useState(null),[g,k]=a.useState(!1),[T,S]=a.useState(""),[c,x]=a.useState(""),[o,h]=a.useState(""),[I,A]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function y(){p(!0),u(null);try{const m=await Zs();if(!t.current)return;j(m)}catch(m){if(!t.current)return;u(m instanceof Error?m.message:String(m))}finally{t.current&&p(!1)}}a.useEffect(()=>{y()},[]);function M(){k(!0),N(null),S(""),x(""),h(""),u(null)}function z(m){k(!1),N(m.id),S(m.name),x(m.description),h(m.body),u(null)}function F(){k(!1),N(null),S(""),x(""),h("")}async function v(){const m=T.trim();if(!Te(m)){u("名称仅允许英文、数字、下划线");return}if(!o.trim()){u("正文不能为空");return}A(!0),u(null);try{if(g?await qs({name:m,description:c,body:o}):w&&await Ys(w,{name:m,description:c,body:o}),!t.current)return;F(),await y()}catch(l){if(!t.current)return;u(l instanceof Error?l.message:String(l))}finally{t.current&&A(!1)}}async function P(m){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){u(null);try{if(await Qs(m),!t.current)return;w===m&&F(),await y()}catch(l){if(!t.current)return;u(l instanceof Error?l.message:String(l))}}}const C=g||w!==null,E=!T.trim()||Te(T);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",!d&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),C?null:e.jsx("button",{type:"button",className:"secondary",onClick:M,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),B?e.jsx("p",{className:"mdocs-agent-skills-error",children:B}):null,C?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:g?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:T,onChange:m=>S(m.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:E?void 0:"mdocs-agent-skills-input-invalid"}),E?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:m=>x(m.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:o,onChange:m=>h(m.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void v(),disabled:I||!E||!T.trim()||!o.trim(),children:I?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:F,disabled:I,children:"取消"})]})]}):null,d?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!d&&s.length===0&&!C?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:M,children:"新建第一个"})]}):null,!d&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(m=>{const l=Te(m.name),f=w===m.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(f?" 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:m.name}),l?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:m.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>z(m),disabled:C&&!f,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(m.id),disabled:C,children:"删除"})]})]},m.id)})}):null]})})]})}function Je(t,s){const j=localStorage.getItem(t);return j===null?s:j==="true"}function Ze(t){const s=new Date(t);if(Number.isNaN(s.getTime()))return"—";const j=String(s.getMonth()+1).padStart(2,"0"),d=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${j}-${d}`}function Ft(t){const{t:s,lang:j,setLang:d}=ie(),{onBack:p,onPublishDraft:B}=t,u=Xs(),[w,N]=a.useState(!1),g=a.useRef(!0);a.useEffect(()=>(g.current=!0,()=>{g.current=!1}),[]),a.useEffect(()=>{u||N(!1)},[u]);const[k,T]=a.useState(()=>Je("mdocs.autoPublish",!1)),[S,c]=a.useState(()=>Je("mdocs.autoEdit",!0)),[x,o]=a.useState(!1),[h,I]=a.useState("general");function A(n){I(n),u&&N(!1)}const y=s(h==="general"?"general":h==="bookmarks"?"bookmarkTitle":h==="myDocuments"?"myDocuments":h==="domainManagement"?"domainManagement":h==="memberTemplates"?"memberTemplates":h==="agentConfig"?"agentConfig":"saveAndPublish"),[M,z]=a.useState([]),[F,v]=a.useState(!0),[P,C]=a.useState(null),[E,m]=a.useState(!1),[l,f]=a.useState(!1),[D,$]=a.useState(!1),[U,Z]=a.useState(!1),[q,Y]=a.useState(null),[_,b]=a.useState(!1),[K,W]=a.useState(!1),[Q,ee]=a.useState(!1),[r,R]=a.useState(""),[O,ce]=a.useState(!1),[ue,oe]=a.useState(!1),[re,se]=a.useState(0),[te,he]=a.useState([]),[ye,pe]=a.useState(!1),[ae,be]=a.useState(""),[ge,Ne]=a.useState([]),[de,i]=a.useState(!1),[V,fe]=a.useState(""),[le,ts]=a.useState(0),[Me,Ee]=a.useState("1"),[Re,as]=a.useState(0),[ve,ns]=a.useState(""),[ke,is]=a.useState(""),[xe,cs]=a.useState(""),[ls,os]=a.useState(null),[rs,ds]=a.useState([]),we=20,[Le,ms]=a.useState([]),[us,Se]=a.useState(!1),[Ce,Fe]=a.useState(null),[De,ze]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(k))},[k]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(S))},[S]),a.useEffect(()=>{h==="savePublish"&&Pe().then(n=>{g.current&&se(n.filter(L=>!L.published).length)})},[h]),a.useEffect(()=>{h==="bookmarks"&&hs(),h==="myDocuments"&&(me(),Xe().then(n=>{g.current&&ds(n)}).catch(()=>{}))},[h,ve,ke,xe]),a.useEffect(()=>{Be()},[]),a.useEffect(()=>{Ye().then(n=>{g.current&&ms(n)}).catch(()=>{})},[]);const je=new Map(Le.map(n=>[n.domainId,n.domainName]));async function Be(){try{v(!0);const n=await et();if(!g.current)return;z(n)}catch{}finally{g.current&&v(!1)}}async function hs(){try{pe(!0);const n=await st();if(!g.current)return;he(n)}catch{}finally{g.current&&pe(!1)}}async function me(n=0){try{i(!0);const L=await tt({offset:n*we,limit:we,domainId:ve||void 0,creatorVisitorId:ke||void 0,groupBy:xe||void 0});if(!g.current)return;Ne(L.items),os(L.groups??null),as(L.total),ts(n),Ee(String(n+1))}catch{}finally{g.current&&i(!1)}}async function ps(n){try{await rt(n),he(L=>L.filter(H=>H.documentId!==n))}catch{}}function gs(){if(M.some(L=>!L.revoked)){f(!0);return}$e()}async function $e(){try{m(!0);const n=await mt();C({token:n.token,name:n.name}),await Be()}finally{m(!1)}}async function fs(){try{ee(!0);const n=await lt();Y(n.recoveryCode)}finally{ee(!1)}}async function xs(n){n.preventDefault();const L=r.trim();if(!(L&&L.length<4))try{ce(!0),await ot(L),R(""),oe(!0),setTimeout(()=>oe(!1),3e3)}finally{ce(!1)}}async function js(n){Fe(n);try{const L=await dt(n),H=new Map;L.forEach(G=>{H.set(G.visitorId,G.permission)}),ze(H)}catch{ze(new Map)}Se(!0)}async function ys(n){if(Ce)try{const L=new Set(n.map(G=>G.visitorId)),H=new Set(De.keys());for(const G of H)L.has(G)||await ut(Ce,G);for(const G of n)await ht(Ce,G.visitorId,G.permission);await me()}finally{Se(!1),Fe(null)}}const Ke=te.filter(n=>{if(!ae.trim())return!0;const L=ae.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(L)||(n.ownerVisitorName||"").toLowerCase().includes(L)||(n.domainId||"").toLowerCase().includes(L)}),ne=Math.ceil(Re/we);return e.jsxs("div",{className:"mdocs-layout"+(u?" mdocs-layout--reader mdocs-layout--settings":""),children:[u&&w?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>N(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(u?w?" 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:at,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),u?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>N(!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(nt,{size:18})}):null]}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(h==="general"?" active":""),onClick:()=>A("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(h==="bookmarks"?" active":""),onClick:()=>A("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(h==="myDocuments"?" active":""),onClick:()=>A("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(h==="domainManagement"?" active":""),onClick:()=>A("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(h==="memberTemplates"?" active":""),onClick:()=>A("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(h==="agentConfig"?" active":""),onClick:()=>A("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(h==="savePublish"?" active":""),onClick:()=>A("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:p,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[u?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>N(!0),"aria-label":s("expandSidebar"),children:e.jsx(it,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:y})]}):null,ct(),h==="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:j==="en"?"active":"",onClick:()=>d("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:j==="zh"?"active":"",onClick:()=>d("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"+(S?" active":""),role:"switch","aria-checked":S,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")}),!F&&M.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:M.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:gs,disabled:E||F,children:E?"…":M.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),P&&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:P.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(P.token),Z(!1),$(!0),window.setTimeout(()=>$(!1),2e3)}catch{$(!1),Z(!0),window.setTimeout(()=>Z(!1),3e3)}})()},children:s(D?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>C(null),children:s("close")})]}),D&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),U&&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:fs,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),b(!0),window.setTimeout(()=>b(!1),2e3)}catch{b(!1),W(!0),window.setTimeout(()=>W(!1),3e3)}})()},children:_?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>Y(null),children:s("close")})]}),_&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),K&&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:xs,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:r,onChange:n=>R(n.target.value),minLength:0,style:{marginBottom:8}}),ue&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:O,children:O?"设置中…":"保存密码"})]})]})]})]}):h==="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:ae,onChange:n=>be(n.target.value)}),ye?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Ke.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(ae?"bookmarkNoMatch":"bookmarkEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children: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:Ke.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:"已删除"}):je.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:()=>ps(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})})]})]}):h==="myDocuments"?e.jsxs("div",{className:"mdocs-settings mdocs-my-docs",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.jsxs("div",{className:"mdocs-my-docs-toolbar",children:[e.jsxs("div",{className:"mdocs-my-docs-search",children:[e.jsx(xt,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("input",{type:"text",placeholder:"搜索文章…",value:V,onChange:n=>fe(n.target.value)})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ve,"aria-label":s("myDocumentsFilterDomain"),onChange:n=>ns(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllDomains")}),Le.map(n=>e.jsx("option",{value:n.domainId,children:je.get(n.domainId)||n.domainName},n.domainId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ke,"aria-label":s("myDocumentsFilterCreator"),onChange:n=>is(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllCreators")}),rs.map(n=>e.jsx("option",{value:n.visitorId,children:n.visitorName},n.visitorId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:xe,"aria-label":s("myDocumentsGroupBy"),onChange:n=>cs(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsGroupNone")}),e.jsx("option",{value:"domain",children:s("myDocumentsGroupDomain")}),e.jsx("option",{value:"creator",children:s("myDocumentsGroupCreator")})]})]}),de?e.jsx("div",{className:"mdocs-my-docs-empty",children:s("loading")}):e.jsxs(e.Fragment,{children:[ge.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(V?"myDocumentsNoMatch":"myDocumentsEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children: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("myDocumentsColCreator")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:(ls??[{key:"",items:ge}]).flatMap(n=>{var G;const L=n.key?e.jsx("tr",{className:"mdocs-my-docs-group",children:e.jsx("td",{colSpan:6,children:xe==="domain"?je.get(n.key)||n.key:((G=n.items[0])==null?void 0:G.creatorName)||n.key})},`group-${n.key}`):null,H=n.items.map(J=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>t.onOpenDocument(J.documentId),children:J.displayName||J.relativePath||"Untitled"}),e.jsx("td",{children:je.get(J.domainId||"")||J.domainId||"—"}),e.jsx("td",{children:J.creatorName||J.creatorVisitorId||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ze(J.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ze(J.createdAt)}),e.jsxs("td",{className:"mdocs-my-docs-actions",children:[e.jsx("button",{type:"button",className:"ghost small",onClick:()=>js(J.documentId),children:s("docInfoInviteMember")}),e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(J.documentId),children:s("bookmarkOpen")})]})]},J.documentId));return L?[L,...H]:H})})]})}),e.jsxs("div",{className:"mdocs-my-docs-footer",children:[e.jsx("span",{className:"mdocs-settings-page-info",children:s("myDocumentsPageInfo",{current:String(ne>0?le+1:0),total:String(ne),count:String(Re)})}),ne>1&&e.jsxs("form",{className:"mdocs-my-docs-jump",onSubmit:n=>{n.preventDefault();const L=Number.parseInt(Me,10);if(!Number.isFinite(L))return;const H=Math.min(Math.max(L,1),ne)-1;H!==le&&me(H)},children:[e.jsx("span",{children:s("myDocumentsJumpTo")}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:ne,"aria-label":s("myDocumentsJumpTo"),value:Me,onChange:n=>Ee(n.target.value)}),e.jsx("button",{type:"submit",className:"secondary small",children:s("myDocumentsJump")})]}),ne>1&&e.jsxs("div",{className:"mdocs-settings-pagination",children:[e.jsx("button",{type:"button",className:"secondary small",disabled:le<=0,onClick:()=>me(le-1),children:s("myDocumentsPrev")}),e.jsx("button",{type:"button",className:"secondary small",disabled:le>=ne-1,onClick:()=>me(le+1),children:s("myDocumentsNext")})]})]})]})]})]}):h==="domainManagement"?e.jsx(Nt,{}):h==="memberTemplates"?e.jsx(vt,{}):h==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Ct,{}),e.jsx(It,{})]}):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:p,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"+(k?" active":""),role:"switch","aria-checked":k,onClick:()=>T(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),re>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>o(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",re,")"]}),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")})})]})]}),x&&e.jsx(yt,{onPublish:B,onClose:()=>o(!1),onCountChange:se,onRecover:t.onRecoverDraft})]}),l&&e.jsx(es,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:E,onConfirm:()=>{f(!1),$e()},onCancel:()=>f(!1)}),e.jsx(ss,{open:us,title:s("docInfoInviteMember"),initialSelectedIds:[...De.keys()],initialPermissions:De,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>Se(!1),onConfirm:n=>{ys(n)}})]})}export{Ft as SettingsPage};
|
|
6
|
+
*/const ft=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],xt=bs("search",ft);function jt({draft:t,onClose:s,onSuccess:j}){const{t:d,lang:p}=ie(),[B,u]=a.useState([]),[w,N]=a.useState(t.domainId??""),[g,k]=a.useState([]),[T,S]=a.useState(""),[c,x]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[o,h]=a.useState(!1),[I,A]=a.useState(null),y=a.useRef(null),M=a.useRef(!0);a.useEffect(()=>(M.current=!0,()=>{M.current=!1}),[]),a.useEffect(()=>{Ns().then(v=>{M.current&&u(v)})},[]),a.useEffect(()=>{w&&(k([]),S(""),vs(w).then(v=>{M.current&&k(v)}).catch(()=>{M.current&&k([])}))},[w]),a.useEffect(()=>{const v=window.setTimeout(()=>{var P;return(P=y.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(v)},[]),a.useEffect(()=>{const v=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[s]);function z(v,P){for(const C of v){if(C.type==="folder"&&C.path===P)return C.documentId;if(C.type==="folder"){const E=z(C.children,P);if(E)return E}}return null}async function F(v){v.preventDefault(),h(!0),A(null);const P=c.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),C=P.endsWith(".md")?P:P+".md",E=C.replace(/\.md$/i,"");try{const m=T?`${T}/${C}`:C,l=T?z(g,T)??void 0:void 0;await Ss({fileName:C,displayName:E,content:t.content,domainId:w,parentId:l}),j()}catch(m){A(Q(d,m))}finally{h(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:v=>{v.target===v.currentTarget&&!o&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:d("recoverDraft")}),e.jsx("p",{className:"muted",children:d("recoverDraftDesc",{name:t.displayName||d("unknownTitle")})}),e.jsxs("form",{onSubmit:F,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[d("domainLabel"),B.length>0&&e.jsx(ks,{domains:B,value:w,onChange:N,onDomainsChange:u,ariaLabel:d("domainLabel"),localizeName:v=>Ae(v,p,d)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[d("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(ws,{nodes:g,activeDocumentId:null,selectedParentPath:T,onOpen:()=>{},onOpenFolder:v=>S(v),onContextMenu:()=>{},onDeselect:()=>S("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[d("fileNameLabel"),e.jsx("input",{ref:y,value:c,onChange:v=>x(v.target.value),placeholder:"recovered.md",maxLength:200,disabled:o})]}),I&&e.jsx("div",{className:"mdocs-dialog-error",children:I}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!o&&s(),disabled:o,children:d("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:o,children:d(o?"creating":"create")})]})]})]})})}function yt({onPublish:t,onClose:s,onCountChange:j,onRecover:d}){const{t:p}=ie(),[B,u]=a.useState([]),[w,N]=a.useState(new Set),[g,k]=a.useState(!1),[T,S]=a.useState(null),[c,x]=a.useState(null),[o,h]=a.useState(null),I=a.useRef(null),A=a.useRef(!0);a.useEffect(()=>(A.current=!0,Pe().then(l=>{if(!A.current)return;const f=l.filter(D=>!D.published);u(f),j==null||j(f.length)}),()=>{A.current=!1,I.current&&(clearTimeout(I.current),I.current=null)}),[]),a.useEffect(()=>{const l=f=>{f.key==="Escape"&&s()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[s]);const y=a.useCallback((l,f)=>{h({message:l,type:f}),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>h(null),3e3)},[]);async function M(l){await Ds(l),N(f=>new Set(f).add(l));try{await t(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),y(p("published"),"success")}catch(f){f instanceof Is||y(p("publishFailed"),"error");const D=await Ts(l);D&&u($=>$.map(U=>U.documentId===l?D:U))}finally{N(f=>{const D=new Set(f);return D.delete(l),D})}}async function z(l){S(null),await Oe(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),y(p("draftDeleted"),"success")}function F(l){const f=B.find(D=>D.documentId===l);f&&x(f)}function v(l){x(null),Oe(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),d==null||d(B.find(f=>f.documentId===l)),y(p("published"),"success")}async function P(){k(!0);let l=0,f=0;for(const U of B)try{await t(U.documentId),l++}catch{f++}const $=(await Pe()).filter(U=>!U.published);u($),j==null||j($.length),f===0?y(p("publishAll"),"success"):y(`${l} published, ${f} failed`,"error"),k(!1)}const C=l=>new Date(l).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),E=l=>Cs(p,l,l.publishError??"UNKNOWN"),m=B;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:[p("unpublishedDrafts"),m.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:m.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:p("draftCount",{count:String(m.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":p("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:m.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:p("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:m.map(l=>{const f=!!l.publishError;return e.jsxs("div",{className:f?"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:l.displayName||p("unknownTitle")}),f?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[C(l.publishErrorAt)," · ",E(l)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[C(l.updatedAt)," · ",p("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[f?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:g,onClick:()=>F(l.documentId),children:p("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:w.has(l.documentId)||g,onClick:()=>void M(l.documentId),children:w.has(l.documentId)?p("publishing"):p("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:g,onClick:()=>S(l.documentId),children:p("delete")})]})]},l.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:p("close")}),e.jsx("button",{type:"button",className:"primary",disabled:m.length===0||g,onClick:()=>void P(),children:g?p("publishing"):`${p("publishAll")} (${m.length})`})]}),o&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+o.type,role:"status",children:o.message})]}),T&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:l=>{l.target===l.currentTarget&&S(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:p("delete")}),e.jsx("p",{className:"muted",children:p("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>S(null),children:p("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void z(T),children:p("delete")})]})]})}),c&&e.jsx(jt,{draft:c,onClose:()=>x(null),onSuccess:()=>v(c.documentId)})]})}function bt(){const{t,lang:s}=ie(),j=Ye(),d=a.useRef(!1),[p,B]=a.useState([]),[u,w]=a.useState(!1),[N,g]=a.useState(""),[k,T]=a.useState("restricted"),[S,c]=a.useState(!1),[x,o]=a.useState(null),[h,I]=a.useState(null),[A,y]=a.useState(""),[M,z]=a.useState(""),[F,v]=a.useState("all"),[P,C]=a.useState(null);a.useEffect(()=>(d.current=!0,()=>{d.current=!1}),[]);const E=a.useCallback(async()=>{w(!0),o(null);try{const b=await qe();if(!d.current)return;B(b)}catch(b){if(!d.current)return;o(Q(t,b))}finally{d.current&&w(!1)}},[t]);a.useEffect(()=>{E()},[E]);async function m(b){if(b.preventDefault(),!N.trim()){o(t("domainNameRequired"));return}c(!0),o(null);try{if(await Rs({domainName:N.trim(),permission:k}),!d.current)return;g(""),T("restricted"),await E()}catch(K){if(!d.current)return;o(Q(t,K))}finally{d.current&&c(!1)}}async function l(b){if(A.trim()){o(null);try{if(await Es(b,A.trim()),!d.current)return;I(null),C(null),await E()}catch(K){if(!d.current)return;o(Q(t,K))}}}function f(b){I(b.domainId),y(b.domainName),C(null)}function D(){I(null),C(null)}async function $(b,K){o(null);try{if(await Ms(b,K),!d.current)return;C(null),await E()}catch(W){if(!d.current)return;o(Q(t,W))}}async function U(b){if(window.confirm(t("deleteDomainConfirmDetail",{name:b.domainName,count:String(b.docCount)}))){o(null);try{if(await Ps(b.domainId),!d.current)return;await E()}catch(K){if(!d.current)return;o(Q(t,K))}}}const Z=a.useCallback(b=>As(b,t),[t]),Y=a.useCallback(b=>Ae(b.domainName,s,t),[s,t]),q=a.useMemo(()=>{const b=M.trim().toLowerCase();return p.filter(K=>F!=="all"&&K.permission!==F?!1:b?Ae(K.domainName,s,t).toLowerCase().includes(b)||K.domainName.toLowerCase().includes(b):!0)},[p,M,F,s,t]),_=a.useCallback((b,K)=>{const W=Z(b.permission);return K?`${W} ${t("domainTypeBuiltinSuffix")}`:W},[Z,t]);return{domains:p,loadingDomains:u,domainError:x,newDomainName:N,setNewDomainName:g,newDomainPermission:k,setNewDomainPermission:T,creating:S,handleCreateDomain:m,renamingId:h,setRenamingId:I,renameDraft:A,setRenameDraft:y,startRename:f,cancelRename:D,handleRename:l,changeTypeForId:P,setChangeTypeForId:C,handlePermissionChange:$,handleDelete:U,domainSearch:M,setDomainSearch:z,domainFilter:F,setDomainFilter:v,filteredDomains:q,visitorId:j,plabel:Z,localizeDomain:Y,domainTypeLabel:_}}const Ue={private:0,restricted:1,public:2};function We(t){return Object.prototype.hasOwnProperty.call(Ue,t)?Ue[t]:null}function _e(t,s){const j=We(t),d=We(s);return j===null||d===null?"invalid":d>j?"upgrade":d<j?"downgrade":"same"}function Nt(){const{t}=ie(),s=bt(),[j,d]=a.useState([]),[p,B]=a.useState(null),[u,w]=a.useState(""),N=a.useRef(null),[g,k]=a.useState(null),T=a.useCallback(async()=>{try{const c=await Xe();d(c)}catch{d([])}},[]);a.useEffect(()=>{T()},[T]),a.useEffect(()=>{if(!s.changeTypeForId)return;const c=x=>{var o;(o=N.current)!=null&&o.contains(x.target)||s.setChangeTypeForId(null)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s.changeTypeForId,s.setChangeTypeForId]);async function S(c){B(null);try{const x=await Ks(c.domainId);k({domainId:c.domainId,creatorVisitorId:c.creatorVisitorId,initialIds:x.map(o=>o.visitorId),memberRows:x})}catch(x){B({kind:"err",text:translateError(t,x)})}}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:c=>s.setNewDomainName(c.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:Ie.map(c=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===c,onChange:()=>s.setNewDomainPermission(c),disabled:s.creating}),e.jsx("span",{children:s.plabel(c)})]},c))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?t("creating"):t("create")})]})]}),p&&e.jsx("div",{className:"mdocs-settings-card",style:{color:p.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:p.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:c=>s.setDomainSearch(c.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",...Ie].map(c=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===c?" active":""),"aria-pressed":s.domainFilter===c,onClick:()=>s.setDomainFilter(c),children:c==="all"?t("domainFilterAll"):s.plabel(c)},c))})]}),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(c=>{const x=Ls(c,s.visitorId),o=Fs(c.domainId),h=zs(c),I=_e(c.permission,"public")==="upgrade",A=I?h?t("domainTooltipTypeLocked"):void 0:t("domainPermissionAlreadyTop");return e.jsxs("tr",{className:o?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===c.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:y=>s.setRenameDraft(y.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(c.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(c)}),o&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!x&&!o&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsx("span",{className:"mdocs-domain-table-type",title:A,children:e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":c.permission,children:s.domainTypeLabel(c,o)})})}),e.jsx("td",{className:"mdocs-domain-table-num",children:c.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[o&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!o&&!x&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!o&&x&&s.changeTypeForId===c.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",ref:N,children:[e.jsx("div",{className:"mdocs-domain-type-segment",role:"radiogroup","aria-label":t("domainChangeType"),children:Ie.map(y=>{const z=_e(c.permission,y)==="downgrade";return e.jsx("span",{title:z?t("domainPermissionNoDowngrade"):void 0,children:e.jsx("button",{type:"button",role:"radio","aria-checked":u===y,className:u===y?"active":"",disabled:z,onClick:()=>w(y),children:s.plabel(y)})},y)})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon confirm","aria-label":t("save"),disabled:u===""||u===c.permission,onClick:()=>{u&&u!==c.permission&&s.handlePermissionChange(c.domainId,u)},children:e.jsx(gt,{size:14,strokeWidth:2.5})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon cancel","aria-label":t("cancel"),onClick:()=>s.setChangeTypeForId(null),children:e.jsx(Bs,{size:14,strokeWidth:2.5})})]}),!o&&x&&s.renamingId!==c.domainId&&s.changeTypeForId!==c.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[c.permission==="restricted"&&e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--primary",onClick:()=>void S(c),children:t("domainMembersManageButton")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:h?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(c)},disabled:h,children:t("rename")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:A,onClick:()=>{s.setRenamingId(null),w(c.permission),s.setChangeTypeForId(c.domainId)},disabled:!I,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--danger",title:h?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(c),disabled:h,children:t("deleteDomain")})]})]})]},c.domainId)})})]})})]}),e.jsx(ss,{open:g!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(g==null?void 0:g.initialIds)??[],lockedIds:g?[g.creatorVisitorId]:[],seedMembers:g==null?void 0:g.memberRows,templates:j,onClose:()=>k(null),onConfirm:async c=>{g&&(await $s(g.domainId,c),B({kind:"ok",text:t("domainMembersSaved",{count:String(c.length)})}))}})]})}function Ge(t){return t.length<=6?t:`${t.slice(0,6)}…`}function vt(){const{t}=ie(),s=a.useRef(!0),[j,d]=a.useState([]),[p,B]=a.useState(!0),[u,w]=a.useState(null),[N,g]=a.useState(1),[k,T]=a.useState(null),[S,c]=a.useState(""),[x,o]=a.useState([]),[h,I]=a.useState(!1),[A,y]=a.useState(null),[M,z]=a.useState(!1),F=Ye(),[v,P]=a.useState([]),[C,E]=a.useState("idle"),[m,l]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{E("loading"),Qe().then(r=>{s.current&&(P(r),E("ok"))}).catch(()=>{s.current&&E("err")})},[]);const f=a.useMemo(()=>{const r=new Map;for(const R of v)r.set(R.visitorId,R.visitorName);return r},[v]),D=a.useCallback(async()=>{B(!0),y(null);try{const r=await Xe();s.current&&d(r)}catch(r){s.current&&y(Q(t,r))}finally{s.current&&B(!1)}},[t]);a.useEffect(()=>{D()},[D]);const $=a.useMemo(()=>x.map(r=>{const R=v.find(O=>O.visitorId===r);return{visitorId:r,name:R?R.visitorName:t("visitorPickerUnknownVisitor"),muted:!R}}),[x,v,t]);function U(r){o(R=>R.includes(r)?R.filter(O=>O!==r):[...R,r])}const Z=N===1?S.trim().length>0:N===2?x.length>0:!0;function Y(){if(!(N>=3)){if(!Z){z(!0);return}z(!1),g(N+1),l("")}}function q(){N<=1||(z(!1),g(N-1))}function _(){w(null),T(null),c(""),o(F?[F]:[]),y(null),g(1),l(""),z(!1)}function b(r){w(null),T(r.id),c(r.displayName);const R=F&&!r.visitorIds.includes(F)?[...r.visitorIds,F]:[...r.visitorIds];o(R),y(null),g(1),l(""),z(!1)}async function K(){if(!(!S.trim()||x.length===0)){I(!0),y(null);try{if(k===null?await Os({displayName:S.trim(),visitorIds:x}):await Vs(k,{displayName:S.trim(),visitorIds:x}),!s.current)return;_(),await D()}catch(r){if(!s.current)return;y(Q(t,r))}finally{s.current&&I(!1)}}}async function W(r){I(!0),y(null);try{if(await Us(r),!s.current)return;w(null),k===r&&_(),await D()}catch(R){if(!s.current)return;y(Q(t,R))}finally{s.current&&I(!1)}}const X=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],ee=`${(N-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(k!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),k!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:_,style:{fontSize:12},children:t("memberTemplateCancelEdit")})]}),e.jsxs("div",{className:"mdocs-wizard-progress",children:[e.jsx("div",{className:"mdocs-wizard-progress-track",children:e.jsx("div",{className:"mdocs-wizard-progress-fill",style:{width:ee}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:X.map(r=>{const R=N===r.key,O=N>r.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${R?" current":""}${O?" done":""}`,children:O?"✓":r.key}),e.jsx("span",{className:`mdocs-wizard-step-label${R?" current":""}${O?" done":""}`,children:r.label})]},r.key)})})]}),A&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:A}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[N===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:S,onChange:r=>c(r.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:h,autoFocus:!0,"aria-invalid":M&&!S.trim()}),M&&!S.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),N===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(pt,{visitors:v,loadState:C,searchFilter:m,onSearchChange:l,selectedIds:new Set(x),onToggle:U,selectedRows:$,myVisitorId:F}),e.jsx("p",{className:`mdocs-wizard-hint${M&&x.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),N===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:S})]}),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(x.length)})})]}),x.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[x.slice(0,15).map(r=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:Ge(r)},r)),x.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",x.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:q,children:["← ",t("memberTemplateWizardBack")]}),N<3?e.jsxs("button",{type:"button",className:"primary",onClick:Y,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void K(),children:t(h?"saving":k===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),p?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):j.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),k===null&&e.jsx("button",{type:"button",className:"primary",onClick:_,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:j.map(r=>e.jsx("li",{className:"mdocs-member-template-row",children:u===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(h?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(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(R=>e.jsx("span",{className:"mdocs-member-template-tag",children:f.get(R)??Ge(R)},R))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>b(r),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(r.id),children:t("memberTemplateDelete")})]})]})},r.id))})]})]})]})}const kt=[{value:"deepseek-flash",label:"deepseek-flash(V4.1 Flash)"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro(将路由至 Flash)"}],wt=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function St(t,s,j){return t==="deepseek"?"Deepseek":s||j}function He(t){return`${St(t.kind,t.providerId,t.name)} · ${t.modelId} · ${t.name}`}function Ct(){const{t}=ie(),s=a.useRef(!0),[j,d]=a.useState(""),[p,B]=a.useState([]),[u,w]=a.useState(null),[N,g]=a.useState(null),[k,T]=a.useState("deepseek"),[S,c]=a.useState(""),[x,o]=a.useState(""),[h,I]=a.useState(""),[A,y]=a.useState("openai-completions"),[M,z]=a.useState("deepseek-flash"),[F,v]=a.useState(1e6),[P,C]=a.useState(""),[E,m]=a.useState(!1),[l,f]=a.useState(null),[D,$]=a.useState(!1),[U,Z]=a.useState(!0),[Y,q]=a.useState(!1),[_,b]=a.useState(null),[K,W]=a.useState(!1),[X,ee]=a.useState(!1),[r,R]=a.useState(!1),[O,ce]=a.useState(null),[ue,oe]=a.useState(null),re=a.useRef(!1);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const se=a.useCallback(async()=>{const i=await Ws();if(s.current)return B(i),i},[]);function te(){g(null),T("deepseek"),c(""),o(""),I(""),y("openai-completions"),z("deepseek-flash"),v(1e6),C(""),m(!1),f(null),$(!1),ee(!1),R(!1),b(null),W(!1)}function he(i){g(i.id),T(i.kind),c(i.name),o(i.providerId??""),I(i.baseUrl),y(i.apiType);const V=i.modelId.trim(),fe=new Set(["deepseek-flash","deepseek-v4-flash","deepseek-v4-flash-vision-exp","deepseek-v4.1-flash","deepseek-v4.1-flash-expires-on-0910"]);z(i.kind==="deepseek"?V==="deepseek-v4-pro"?"deepseek-v4-pro":fe.has(V)?"deepseek-flash":V||"deepseek-flash":V),v(i.contextWindow||1e6),m(i.hasApiKey),f(i.apiKeyMasked),C(""),$(i.isDefault)}a.useEffect(()=>{(async()=>{try{const i=await _s();if(!s.current)return;d(i.visitorName);const V=await se();if(!s.current||!V)return;V.length===0&&(te(),w("create"))}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i)),w("create")}finally{s.current&&Z(!1)}})()},[se]);function ye(){te(),w("create")}function pe(i){he(i),w("edit"),W(!1),b(null)}function ae(){te(),w(null)}async function be(i){if(!(i.isDefault||ue)){oe(i.id),b(null);try{await Gs(i.id),await se()}catch(V){if(!s.current)return;b(V instanceof Error?V.message:String(V))}finally{s.current&&oe(null)}}}async function ge(){if(O){q(!0),b(null);try{await Js(O.id);const i=await se();if(!s.current)return;u==="edit"&&N===O.id&&ae(),((i==null?void 0:i.length)??0)===0&&(te(),w("create"))}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i))}finally{s.current&&(q(!1),ce(null))}}}async function Ne(){q(!0),b(null),W(!1);try{const i=k==="custom"?{...u==="edit"&&N?{id:N}:{},...u==="create"&&D?{isDefault:!0}:{},kind:k,baseUrl:h,modelId:M,providerId:x.trim()||void 0,apiType:A,name:S,contextWindow:F,...P.trim()?{apiKey:P.trim()}:{}}:{...u==="edit"&&N?{id:N}:{},...u==="create"&&D?{isDefault:!0}:{},kind:k,modelId:M,name:S,contextWindow:F,...P.trim()?{apiKey:P.trim()}:{}};if(await Hs(i),!s.current)return;await se(),W(!0),w(null),te()}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i))}finally{s.current&&q(!1)}}const de=u!==null;return e.jsxs("div",{className:"mdocs-agent-config-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:t("agentConfig")}),!U&&!de?e.jsx("button",{type:"button",className:"secondary",onClick:ye,children:"添加配置"}):null]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!U&&p.length>0&&!de?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:"选择默认配置后,智能助手与帮写将使用该模型。"}),e.jsx("ul",{className:"mdocs-agent-config-list",children:p.map(i=>e.jsxs("li",{className:"mdocs-agent-config-item",children:[e.jsxs("label",{className:"mdocs-agent-config-item-default",children:[e.jsx("input",{type:"radio",name:"agent-default-config",checked:i.isDefault,disabled:ue!==null,onChange:()=>void be(i)}),e.jsx("span",{children:i.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:He(i)}),i.kind==="custom"?e.jsx("span",{className:"mdocs-agent-badge",children:"自定义"}):null,e.jsx("p",{className:"mdocs-agent-config-item-meta",children:i.hasApiKey?`Key ${i.apiKeyMasked??"已配置"}`:"未配置 Key"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>pe(i),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>ce(i),children:"删除"})]})]},i.id))}),K?e.jsx("p",{className:"mdocs-agent-config-ok",children:t("saved")}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null]}):null,de?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:u==="create"?"新建模型配置":"编辑模型配置"}),e.jsxs("div",{className:"mdocs-agent-form",children:[e.jsxs("div",{className:"mdocs-agent-kind-tabs",role:"tablist","aria-label":"配置方式",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":k==="deepseek",className:k==="deepseek"?"active":"",onClick:()=>T("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":k==="custom",className:k==="custom"?"active":"",onClick:()=>T("custom"),children:"自定义"})]}),k==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigModel")}),e.jsx(Ve,{options:[...kt],value:M,onChange:z})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:X?"text":"password",value:P,onChange:i=>C(i.target.value),placeholder:E?t("agentConfigApiKeyConfigured").replace("{{masked}}",l??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(X?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>ee(i=>!i),children:X?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:h,onChange:i=>{const V=i.target.value;if(I(V),re.current)return;V.toLowerCase().includes("anthropic")?y("anthropic-messages"):y("openai-completions")},placeholder:"https://api.example.com/v1",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Model ID"}),e.jsx("input",{type:"text",value:M,onChange:i=>z(i.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:X?"text":"password",value:P,onChange:i=>C(i.target.value),placeholder:E?t("agentConfigApiKeyConfigured").replace("{{masked}}",l??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(X?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>ee(i=>!i),children:X?"隐藏":"显示"})]})]})]}),e.jsxs("details",{className:"mdocs-agent-advanced",open:r,onToggle:i=>R(i.target.open),children:[e.jsx("summary",{children:"高级选项"}),k==="custom"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Provider ID(选填)"}),e.jsx("input",{type:"text",value:x,onChange:i=>o(i.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Ve,{options:[...wt],value:A,onChange:i=>{re.current=!0,y(i)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigName")}),e.jsx("input",{type:"text",value:S,onChange:i=>c(i.target.value),placeholder:t("agentConfigNameDefault").replace("{{name}}",j||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:F,onChange:i=>v(Number(i.target.value)||1e6)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:t("agentConfigContextWindowDesc")})]})]}),u==="create"&&p.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:i=>$(i.target.checked)}),e.jsx("span",{children:"保存后设为默认配置"})]}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null,e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void Ne(),disabled:Y,children:t(Y?"saving":"save")}),p.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:ae,disabled:Y,children:t("cancel")}):null]})]})]}):U?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:t("loading")})}):null]}),O?e.jsx(es,{title:"删除配置",message:`确定删除「${He(O)}」?${O.isDefault&&p.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:t("cancel"),onConfirm:()=>void ge(),onCancel:()=>ce(null)}):null]})}const Dt=/^[A-Za-z0-9_]+$/;function Te(t){return Dt.test(t.trim())}function It(){const t=a.useRef(!0),[s,j]=a.useState([]),[d,p]=a.useState(!0),[B,u]=a.useState(null),[w,N]=a.useState(null),[g,k]=a.useState(!1),[T,S]=a.useState(""),[c,x]=a.useState(""),[o,h]=a.useState(""),[I,A]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function y(){p(!0),u(null);try{const m=await Zs();if(!t.current)return;j(m)}catch(m){if(!t.current)return;u(m instanceof Error?m.message:String(m))}finally{t.current&&p(!1)}}a.useEffect(()=>{y()},[]);function M(){k(!0),N(null),S(""),x(""),h(""),u(null)}function z(m){k(!1),N(m.id),S(m.name),x(m.description),h(m.body),u(null)}function F(){k(!1),N(null),S(""),x(""),h("")}async function v(){const m=T.trim();if(!Te(m)){u("名称仅允许英文、数字、下划线");return}if(!o.trim()){u("正文不能为空");return}A(!0),u(null);try{if(g?await Ys({name:m,description:c,body:o}):w&&await qs(w,{name:m,description:c,body:o}),!t.current)return;F(),await y()}catch(l){if(!t.current)return;u(l instanceof Error?l.message:String(l))}finally{t.current&&A(!1)}}async function P(m){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){u(null);try{if(await Xs(m),!t.current)return;w===m&&F(),await y()}catch(l){if(!t.current)return;u(l instanceof Error?l.message:String(l))}}}const C=g||w!==null,E=!T.trim()||Te(T);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",!d&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),C?null:e.jsx("button",{type:"button",className:"secondary",onClick:M,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),B?e.jsx("p",{className:"mdocs-agent-skills-error",children:B}):null,C?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:g?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:T,onChange:m=>S(m.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:E?void 0:"mdocs-agent-skills-input-invalid"}),E?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:m=>x(m.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:o,onChange:m=>h(m.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void v(),disabled:I||!E||!T.trim()||!o.trim(),children:I?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:F,disabled:I,children:"取消"})]})]}):null,d?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!d&&s.length===0&&!C?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:M,children:"新建第一个"})]}):null,!d&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(m=>{const l=Te(m.name),f=w===m.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(f?" 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:m.name}),l?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:m.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>z(m),disabled:C&&!f,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(m.id),disabled:C,children:"删除"})]})]},m.id)})}):null]})})]})}function Je(t,s){const j=localStorage.getItem(t);return j===null?s:j==="true"}function Ze(t){const s=new Date(t);if(Number.isNaN(s.getTime()))return"—";const j=String(s.getMonth()+1).padStart(2,"0"),d=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${j}-${d}`}function Ft(t){const{t:s,lang:j,setLang:d}=ie(),{onBack:p,onPublishDraft:B}=t,u=Qs(),[w,N]=a.useState(!1),g=a.useRef(!0);a.useEffect(()=>(g.current=!0,()=>{g.current=!1}),[]),a.useEffect(()=>{u||N(!1)},[u]);const[k,T]=a.useState(()=>Je("mdocs.autoPublish",!1)),[S,c]=a.useState(()=>Je("mdocs.autoEdit",!0)),[x,o]=a.useState(!1),[h,I]=a.useState("general");function A(n){I(n),u&&N(!1)}const y=s(h==="general"?"general":h==="bookmarks"?"bookmarkTitle":h==="myDocuments"?"myDocuments":h==="domainManagement"?"domainManagement":h==="memberTemplates"?"memberTemplates":h==="agentConfig"?"agentConfig":"saveAndPublish"),[M,z]=a.useState([]),[F,v]=a.useState(!0),[P,C]=a.useState(null),[E,m]=a.useState(!1),[l,f]=a.useState(!1),[D,$]=a.useState(!1),[U,Z]=a.useState(!1),[Y,q]=a.useState(null),[_,b]=a.useState(!1),[K,W]=a.useState(!1),[X,ee]=a.useState(!1),[r,R]=a.useState(""),[O,ce]=a.useState(!1),[ue,oe]=a.useState(!1),[re,se]=a.useState(0),[te,he]=a.useState([]),[ye,pe]=a.useState(!1),[ae,be]=a.useState(""),[ge,Ne]=a.useState([]),[de,i]=a.useState(!1),[V,fe]=a.useState(""),[le,ts]=a.useState(0),[Me,Ee]=a.useState("1"),[Re,as]=a.useState(0),[ve,ns]=a.useState(""),[ke,is]=a.useState(""),[xe,cs]=a.useState(""),[ls,os]=a.useState(null),[rs,ds]=a.useState([]),we=20,[Le,ms]=a.useState([]),[us,Se]=a.useState(!1),[Ce,Fe]=a.useState(null),[De,ze]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(k))},[k]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(S))},[S]),a.useEffect(()=>{h==="savePublish"&&Pe().then(n=>{g.current&&se(n.filter(L=>!L.published).length)})},[h]),a.useEffect(()=>{h==="bookmarks"&&hs(),h==="myDocuments"&&(me(),Qe().then(n=>{g.current&&ds(n)}).catch(()=>{}))},[h,ve,ke,xe]),a.useEffect(()=>{Be()},[]),a.useEffect(()=>{qe().then(n=>{g.current&&ms(n)}).catch(()=>{})},[]);const je=new Map(Le.map(n=>[n.domainId,n.domainName]));async function Be(){try{v(!0);const n=await et();if(!g.current)return;z(n)}catch{}finally{g.current&&v(!1)}}async function hs(){try{pe(!0);const n=await st();if(!g.current)return;he(n)}catch{}finally{g.current&&pe(!1)}}async function me(n=0){try{i(!0);const L=await tt({offset:n*we,limit:we,domainId:ve||void 0,creatorVisitorId:ke||void 0,groupBy:xe||void 0});if(!g.current)return;Ne(L.items),os(L.groups??null),as(L.total),ts(n),Ee(String(n+1))}catch{}finally{g.current&&i(!1)}}async function ps(n){try{await rt(n),he(L=>L.filter(H=>H.documentId!==n))}catch{}}function gs(){if(M.some(L=>!L.revoked)){f(!0);return}$e()}async function $e(){try{m(!0);const n=await mt();C({token:n.token,name:n.name}),await Be()}finally{m(!1)}}async function fs(){try{ee(!0);const n=await lt();q(n.recoveryCode)}finally{ee(!1)}}async function xs(n){n.preventDefault();const L=r.trim();if(!(L&&L.length<4))try{ce(!0),await ot(L),R(""),oe(!0),setTimeout(()=>oe(!1),3e3)}finally{ce(!1)}}async function js(n){Fe(n);try{const L=await dt(n),H=new Map;L.forEach(G=>{H.set(G.visitorId,G.permission)}),ze(H)}catch{ze(new Map)}Se(!0)}async function ys(n){if(Ce)try{const L=new Set(n.map(G=>G.visitorId)),H=new Set(De.keys());for(const G of H)L.has(G)||await ut(Ce,G);for(const G of n)await ht(Ce,G.visitorId,G.permission);await me()}finally{Se(!1),Fe(null)}}const Ke=te.filter(n=>{if(!ae.trim())return!0;const L=ae.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(L)||(n.ownerVisitorName||"").toLowerCase().includes(L)||(n.domainId||"").toLowerCase().includes(L)}),ne=Math.ceil(Re/we);return e.jsxs("div",{className:"mdocs-layout"+(u?" mdocs-layout--reader mdocs-layout--settings":""),children:[u&&w?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>N(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(u?w?" 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:at,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),u?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>N(!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(nt,{size:18})}):null]}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(h==="general"?" active":""),onClick:()=>A("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(h==="bookmarks"?" active":""),onClick:()=>A("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(h==="myDocuments"?" active":""),onClick:()=>A("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(h==="domainManagement"?" active":""),onClick:()=>A("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(h==="memberTemplates"?" active":""),onClick:()=>A("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(h==="agentConfig"?" active":""),onClick:()=>A("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(h==="savePublish"?" active":""),onClick:()=>A("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:p,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[u?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>N(!0),"aria-label":s("expandSidebar"),children:e.jsx(it,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:y})]}):null,ct(),h==="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:j==="en"?"active":"",onClick:()=>d("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:j==="zh"?"active":"",onClick:()=>d("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"+(S?" active":""),role:"switch","aria-checked":S,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")}),!F&&M.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:M.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:gs,disabled:E||F,children:E?"…":M.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),P&&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:P.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(P.token),Z(!1),$(!0),window.setTimeout(()=>$(!1),2e3)}catch{$(!1),Z(!0),window.setTimeout(()=>Z(!1),3e3)}})()},children:s(D?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>C(null),children:s("close")})]}),D&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),U&&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:fs,disabled:X,children:X?"…":"生成恢复码"})]}),Y&&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:Y})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(Y),W(!1),b(!0),window.setTimeout(()=>b(!1),2e3)}catch{b(!1),W(!0),window.setTimeout(()=>W(!1),3e3)}})()},children:_?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>q(null),children:s("close")})]}),_&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),K&&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:xs,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:r,onChange:n=>R(n.target.value),minLength:0,style:{marginBottom:8}}),ue&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:O,children:O?"设置中…":"保存密码"})]})]})]})]}):h==="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:ae,onChange:n=>be(n.target.value)}),ye?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Ke.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(ae?"bookmarkNoMatch":"bookmarkEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children: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:Ke.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:"已删除"}):je.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:()=>ps(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})})]})]}):h==="myDocuments"?e.jsxs("div",{className:"mdocs-settings mdocs-my-docs",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.jsxs("div",{className:"mdocs-my-docs-toolbar",children:[e.jsxs("div",{className:"mdocs-my-docs-search",children:[e.jsx(xt,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("input",{type:"text",placeholder:"搜索文章…",value:V,onChange:n=>fe(n.target.value)})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ve,"aria-label":s("myDocumentsFilterDomain"),onChange:n=>ns(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllDomains")}),Le.map(n=>e.jsx("option",{value:n.domainId,children:je.get(n.domainId)||n.domainName},n.domainId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ke,"aria-label":s("myDocumentsFilterCreator"),onChange:n=>is(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllCreators")}),rs.map(n=>e.jsx("option",{value:n.visitorId,children:n.visitorName},n.visitorId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:xe,"aria-label":s("myDocumentsGroupBy"),onChange:n=>cs(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsGroupNone")}),e.jsx("option",{value:"domain",children:s("myDocumentsGroupDomain")}),e.jsx("option",{value:"creator",children:s("myDocumentsGroupCreator")})]})]}),de?e.jsx("div",{className:"mdocs-my-docs-empty",children:s("loading")}):e.jsxs(e.Fragment,{children:[ge.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(V?"myDocumentsNoMatch":"myDocumentsEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children: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("myDocumentsColCreator")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:(ls??[{key:"",items:ge}]).flatMap(n=>{var G;const L=n.key?e.jsx("tr",{className:"mdocs-my-docs-group",children:e.jsx("td",{colSpan:6,children:xe==="domain"?je.get(n.key)||n.key:((G=n.items[0])==null?void 0:G.creatorName)||n.key})},`group-${n.key}`):null,H=n.items.map(J=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>t.onOpenDocument(J.documentId),children:J.displayName||J.relativePath||"Untitled"}),e.jsx("td",{children:je.get(J.domainId||"")||J.domainId||"—"}),e.jsx("td",{children:J.creatorName||J.creatorVisitorId||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ze(J.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ze(J.createdAt)}),e.jsxs("td",{className:"mdocs-my-docs-actions",children:[e.jsx("button",{type:"button",className:"ghost small",onClick:()=>js(J.documentId),children:s("docInfoInviteMember")}),e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(J.documentId),children:s("bookmarkOpen")})]})]},J.documentId));return L?[L,...H]:H})})]})}),e.jsxs("div",{className:"mdocs-my-docs-footer",children:[e.jsx("span",{className:"mdocs-settings-page-info",children:s("myDocumentsPageInfo",{current:String(ne>0?le+1:0),total:String(ne),count:String(Re)})}),ne>1&&e.jsxs("form",{className:"mdocs-my-docs-jump",onSubmit:n=>{n.preventDefault();const L=Number.parseInt(Me,10);if(!Number.isFinite(L))return;const H=Math.min(Math.max(L,1),ne)-1;H!==le&&me(H)},children:[e.jsx("span",{children:s("myDocumentsJumpTo")}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:ne,"aria-label":s("myDocumentsJumpTo"),value:Me,onChange:n=>Ee(n.target.value)}),e.jsx("button",{type:"submit",className:"secondary small",children:s("myDocumentsJump")})]}),ne>1&&e.jsxs("div",{className:"mdocs-settings-pagination",children:[e.jsx("button",{type:"button",className:"secondary small",disabled:le<=0,onClick:()=>me(le-1),children:s("myDocumentsPrev")}),e.jsx("button",{type:"button",className:"secondary small",disabled:le>=ne-1,onClick:()=>me(le+1),children:s("myDocumentsNext")})]})]})]})]})]}):h==="domainManagement"?e.jsx(Nt,{}):h==="memberTemplates"?e.jsx(vt,{}):h==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Ct,{}),e.jsx(It,{})]}):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:p,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"+(k?" active":""),role:"switch","aria-checked":k,onClick:()=>T(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),re>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>o(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",re,")"]}),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")})})]})]}),x&&e.jsx(yt,{onPublish:B,onClose:()=>o(!1),onCountChange:se,onRecover:t.onRecoverDraft})]}),l&&e.jsx(es,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:E,onConfirm:()=>{f(!1),$e()},onCancel:()=>f(!1)}),e.jsx(ss,{open:us,title:s("docInfoInviteMember"),initialSelectedIds:[...De.keys()],initialPermissions:De,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>Se(!1),onConfirm:n=>{ys(n)}})]})}export{Ft as SettingsPage};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{o as t,C as _}from"./index-OmOf_og0.js";import{r as u,j as r}from"./react-vendor-BuABiQkA.js";import{F as C,G as v,L as N,H as c,J as l,K as L,M as j,q as z,N as H,P as $}from"./react-CI5PDFXT.js";import{z as f,V as g}from"./editor-CL03se2B.js";/**
|
|
2
2
|
* @license lucide-react v0.562.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|