@fgbg/mdocs 1.3.29 → 1.3.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +12 -0
  3. package/dist/server/agent/Agent/run-pi-agent.js +27 -0
  4. package/dist/server/agent/Agent/run-pi-agent.js.map +1 -1
  5. package/dist/server/agent/Agent/system-prompt.js +7 -5
  6. package/dist/server/agent/Agent/system-prompt.js.map +1 -1
  7. package/dist/server/agent/Agent/tool-call-ui.js +145 -0
  8. package/dist/server/agent/Agent/tool-call-ui.js.map +1 -0
  9. package/dist/server/agent/Agent/tool-call-ui.test.js +43 -0
  10. package/dist/server/agent/Agent/tool-call-ui.test.js.map +1 -0
  11. package/dist/server/agent/Agent/tool-ui-effects.js +3 -23
  12. package/dist/server/agent/Agent/tool-ui-effects.js.map +1 -1
  13. package/dist/server/agent/Agent/tools-registry.js +5 -3
  14. package/dist/server/agent/Agent/tools-registry.js.map +1 -1
  15. package/dist/server/agent/Agent/tools-registry.test.js +4 -0
  16. package/dist/server/agent/Agent/tools-registry.test.js.map +1 -1
  17. package/dist/server/agent/Agent/tools-template.js +5 -0
  18. package/dist/server/agent/Agent/tools-template.js.map +1 -1
  19. package/dist/server/agent/Agent/tools-time.js +42 -0
  20. package/dist/server/agent/Agent/tools-time.js.map +1 -0
  21. package/dist/server/agent/Agent/tools-time.test.js +20 -0
  22. package/dist/server/agent/Agent/tools-time.test.js.map +1 -0
  23. package/dist/web/assets/AgentChatPanel-e1h0rqbg.js +42 -0
  24. package/dist/web/assets/{AiWriteWorkbench-B0r87dOu.js → AiWriteWorkbench-Dq0aCk5c.js} +3 -3
  25. package/dist/web/assets/{DiagramEditor-NtNY3sZL-zENSuUSW.js → DiagramEditor-NtNY3sZL-DHC7qgkW.js} +1 -1
  26. package/dist/web/assets/{DocChrome-B-5PeA3Z.js → DocChrome-7KIXAHsE.js} +8 -3
  27. package/dist/web/assets/{DocumentEditor-CeH1smor.js → DocumentEditor-CmIk_VBn.js} +1 -1
  28. package/dist/web/assets/{HtmlEditor-DEwBOS1N.js → HtmlEditor-REIKOoam.js} +1 -1
  29. package/dist/web/assets/{MergeView-Bzk9R2GH.js → MergeView-DCgxAslc.js} +1 -1
  30. package/dist/web/assets/{PlaygroundPage-Bmq4l_R3.js → PlaygroundPage-Cz9TMo7h.js} +1 -1
  31. package/dist/web/assets/SettingsPage-DsLbUPt-.js +21 -0
  32. package/dist/web/assets/SheetEditor-Bkxxf3ly.js +26 -0
  33. package/dist/web/assets/SheetEditor-DbT_K_Ia.css +1 -0
  34. package/dist/web/assets/{Toolbar-SoiYp0SC.js → Toolbar-ClbpubYi.js} +1 -1
  35. package/dist/web/assets/VisitorPickerModal-D4xmZbNY.js +6 -0
  36. package/dist/web/assets/{check-CnsclxvV.js → check-CuLfkkz7.js} +1 -1
  37. package/dist/web/assets/{copy-CI3NmTJZ.js → copy-CjAdouag.js} +1 -1
  38. package/dist/web/assets/docPlainCharCount-DO5lb3Wt.js +1 -0
  39. package/dist/web/assets/index-C1Mc0Svw.css +1 -0
  40. package/dist/web/assets/index-DAhW-QRN.js +299 -0
  41. package/dist/web/assets/{italic-BljxX8Uj.js → italic-cqqPz-_Q.js} +1 -1
  42. package/dist/web/assets/{meta2dEngine-BD2XbzaV-BuKVYpuY.js → meta2dEngine-BD2XbzaV-CNHknbe2.js} +1 -1
  43. package/dist/web/assets/{plus-BAqdJ6N2.js → plus-DkLh2brQ.js} +1 -1
  44. package/dist/web/assets/{react-C7YGEhUS.js → react-Dj2vqPq5.js} +3 -3
  45. package/dist/web/index.html +2 -2
  46. package/package.json +1 -1
  47. package/dist/server/agent/Agent/tools-account.js +0 -25
  48. package/dist/server/agent/Agent/tools-account.js.map +0 -1
  49. package/dist/server/db/repositories/diagram.repo.js +0 -21
  50. package/dist/server/db/repositories/diagram.repo.js.map +0 -1
  51. package/dist/server/diagrams/diagram.service.js +0 -156
  52. package/dist/server/diagrams/diagram.service.js.map +0 -1
  53. package/dist/server/routes/diagrams.routes.js +0 -122
  54. package/dist/server/routes/diagrams.routes.js.map +0 -1
  55. package/dist/shared/types/diagram.js +0 -2
  56. package/dist/shared/types/diagram.js.map +0 -1
  57. package/dist/web/assets/AgentChatPanel-BD1oyUQ2.js +0 -42
  58. package/dist/web/assets/SettingsPage-B3-GANlD.js +0 -1
  59. package/dist/web/assets/SheetEditor-DYVKW2RD.js +0 -16
  60. package/dist/web/assets/SheetEditor-gXD-sRv2.css +0 -1
  61. package/dist/web/assets/VisitorPickerModal-BTmTrqrT.js +0 -1
  62. package/dist/web/assets/docPlainCharCount-C7aeeOM1.js +0 -11
  63. package/dist/web/assets/index-CSZ-Z1RJ.css +0 -1
  64. package/dist/web/assets/index-DNb6Q69l.js +0 -299
@@ -1,42 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diagram-BF8g9yg4.js","assets/ui-CEFkTVnG.js","assets/react-vendor-BVS1XoFi.js","assets/motion-BAXVQJfN.js"])))=>i.map(i=>d[i]);
2
- import{r as a,j as e,_ as Gt,b as Vt}from"./react-vendor-BVS1XoFi.js";import{o as U,av as Zt,aP as Jt,aQ as bt,aR as Qt,N as Nt,C as es,aS as vt,X as Ne,aT as pt,aU as ts,aV as re,Z as ht,aW as ss,aX as ft,aY as ns,aZ as as,a_ as rs,a$ as is,b0 as os,b1 as wt,b2 as ls,b3 as cs,b4 as ds,b5 as us,b6 as ms}from"./index-DNb6Q69l.js";import{C as St}from"./check-CnsclxvV.js";import{C as Ct,a as At}from"./copy-CI3NmTJZ.js";import{P as ps}from"./plus-BAqdJ6N2.js";import{ar as hs,ah as fs}from"./ui-CEFkTVnG.js";import"./diagram-BF8g9yg4.js";import"./motion-BAXVQJfN.js";/**
3
- * @license lucide-react v0.562.0 - ISC
4
- *
5
- * This source code is licensed under the ISC license.
6
- * See the LICENSE file in the root directory of this source tree.
7
- */const gs=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],xs=U("arrow-down",gs);/**
8
- * @license lucide-react v0.562.0 - ISC
9
- *
10
- * This source code is licensed under the ISC license.
11
- * See the LICENSE file in the root directory of this source tree.
12
- */const ys=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],js=U("history",ys);/**
13
- * @license lucide-react v0.562.0 - ISC
14
- *
15
- * This source code is licensed under the ISC license.
16
- * See the LICENSE file in the root directory of this source tree.
17
- */const ks=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],bs=U("maximize-2",ks);/**
18
- * @license lucide-react v0.562.0 - ISC
19
- *
20
- * This source code is licensed under the ISC license.
21
- * See the LICENSE file in the root directory of this source tree.
22
- */const Ns=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],vs=U("minimize-2",Ns);/**
23
- * @license lucide-react v0.562.0 - ISC
24
- *
25
- * This source code is licensed under the ISC license.
26
- * See the LICENSE file in the root directory of this source tree.
27
- */const ws=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],Ss=U("pencil",ws);/**
28
- * @license lucide-react v0.562.0 - ISC
29
- *
30
- * This source code is licensed under the ISC license.
31
- * See the LICENSE file in the root directory of this source tree.
32
- */const Cs=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]],As=U("pin",Cs);/**
33
- * @license lucide-react v0.562.0 - ISC
34
- *
35
- * This source code is licensed under the ISC license.
36
- * See the LICENSE file in the root directory of this source tree.
37
- */const Is=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],_s=U("zoom-in",Is);/**
38
- * @license lucide-react v0.562.0 - ISC
39
- *
40
- * This source code is licensed under the ISC license.
41
- * See the LICENSE file in the root directory of this source tree.
42
- */const Ms=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Es=U("zoom-out",Ms),ze=5;function Rs(n){const s=a.useRef(!0),i=a.useRef(null),[l,h]=a.useState([]),[x,C]=a.useState(!1),[j,_]=a.useState(null);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const p=await Zt();if(!s.current)return;h(p)}catch(p){if(!s.current)return;_(p instanceof Error?p.message:String(p))}})()},[]),a.useEffect(()=>{if(!x)return;function p(g){const A=i.current;!A||A.contains(g.target)||C(!1)}function o(g){g.key==="Escape"&&C(!1)}return document.addEventListener("mousedown",p),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",o)}},[x]);const f=l.filter(p=>n.selectedNames.includes(p.name));function M(p){if(n.disabled)return;const o=new Set(n.selectedNames);if(o.has(p))o.delete(p);else{if(o.size>=ze)return;o.add(p)}n.onChange([...o])}return l.length===0&&!j?null:e.jsxs("div",{className:"mdocs-agent-skill-ref",ref:i,children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-bar",children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-anchor",children:[x&&l.length>0?e.jsxs("div",{className:"mdocs-agent-skill-popover",role:"listbox","aria-label":"选择 Skill",children:[e.jsxs("div",{className:"mdocs-agent-skill-popover-hint",children:["选择要引用的 Skill(最多 ",ze," 个)"]}),e.jsx("ul",{className:"mdocs-agent-skill-popover-list",children:l.map(p=>{const o=n.selectedNames.includes(p.name),g=!o&&n.selectedNames.length>=ze;return e.jsx("li",{children:e.jsxs("button",{type:"button",role:"option","aria-selected":o,className:"mdocs-agent-skill-popover-item"+(o?" mdocs-agent-skill-popover-item-on":""),disabled:n.disabled||g,onClick:()=>M(p.name),children:[e.jsx("span",{className:"mdocs-agent-skill-popover-check","aria-hidden":!0,children:o?"✓":""}),e.jsxs("span",{className:"mdocs-agent-skill-popover-text",children:[e.jsx("span",{className:"mdocs-agent-skill-popover-name",children:p.name}),p.description?e.jsx("span",{className:"mdocs-agent-skill-popover-desc",children:p.description}):e.jsx("span",{className:"mdocs-agent-skill-popover-desc mdocs-agent-skill-popover-desc-muted",children:"无简介"})]})]})},p.id)})})]}):null,e.jsxs("button",{type:"button",className:"mdocs-agent-skill-ref-toggle"+(x?" mdocs-agent-skill-ref-toggle-open":""),disabled:n.disabled||l.length===0,onClick:()=>C(p=>!p),"aria-expanded":x,"aria-haspopup":"listbox",title:"引用 Skill",children:["Skill",f.length>0?` · ${f.length}`:""]})]}),f.map(p=>e.jsxs("button",{type:"button",className:"mdocs-agent-skill-chip mdocs-agent-skill-chip-on",disabled:n.disabled,onClick:()=>M(p.name),title:"移除引用",children:[p.name,e.jsx("span",{"aria-hidden":!0,children:" ×"})]},p.name))]}),j?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:j}):null]})}const Ds=/^[A-Za-z0-9_]+$/;function $s(n){const{block:s,onResolved:i}=n,[l,h]=a.useState(s.initialName),[x,C]=a.useState(s.initialDescription),[j,_]=a.useState(s.initialBody),[f,M]=a.useState(!1),[p,o]=a.useState(null),[g,A]=a.useState(1),z=a.useRef(!1),v=a.useRef(i);v.current=i;const S=s.status==="open",q=a.useRef(0);a.useEffect(()=>{if(!S)return;z.current=!1;const R=new Date(s.expiresAt).getTime(),ve=Date.now(),ie=Math.max(R-ve,1);q.current=ie,A(1);const Z=()=>{const ee=R-Date.now(),F=Math.max(0,Math.min(1,ee/ie));A(F),ee<=0&&!z.current&&(z.current=!0,Jt(s.requestId).catch(()=>{}).finally(()=>{v.current(s.requestId,"expired")}))};Z();const oe=window.setInterval(Z,100);return()=>window.clearInterval(oe)},[S,s.expiresAt,s.requestId]);async function T(){if(f||!S)return;const R=l.trim();if(!R){o("名称不能为空");return}if(!Ds.test(R)){o("名称仅允许英文、数字、下划线");return}if(!j.trim()){o("正文不能为空");return}M(!0),o(null);try{await Qt(s.requestId,{name:R,description:x.trim(),body:j}),i(s.requestId,"submitted",R)}catch{i(s.requestId,"failed")}finally{M(!1)}}async function W(){if(!(f||!S)){M(!0),o(null),z.current=!0;try{await bt(s.requestId),i(s.requestId,"cancelled")}catch{i(s.requestId,"failed")}finally{M(!1)}}}const $=Math.max(0,Math.ceil(g*q.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card mdocs-agent-skill-form-card"+(S?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),S?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[$,"s"]}):null]}),S?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(g*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${g})`}})}):null,s.status==="submitted"?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已提交",s.submittedName?`:${s.submittedName}`:""]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,表单已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,S?e.jsxs("div",{className:"mdocs-agent-skill-form-fields",children:[e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"名称(英文数字下划线)"}),e.jsx("input",{type:"text",value:l,onChange:R=>h(R.target.value),maxLength:64,disabled:f,autoComplete:"off",spellCheck:!1})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"简介"}),e.jsx("input",{type:"text",value:x,onChange:R=>C(R.target.value),maxLength:200,disabled:f})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:j,onChange:R=>_(R.target.value),rows:8,disabled:f})]}),p?e.jsx("p",{className:"mdocs-agent-skill-form-error",children:p}):null,e.jsxs("div",{className:"mdocs-agent-skill-form-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-skill-form-cancel",disabled:f,onClick:()=>void W(),children:"取消"}),e.jsx("button",{type:"button",disabled:f,onClick:()=>void T(),children:f?"提交中…":s.mode==="create"?"创建":"保存"})]})]}):null]})}function Fe(n){var s;return n==null||typeof n=="boolean"?"":typeof n=="string"||typeof n=="number"?String(n):Array.isArray(n)?n.map(Fe).join(""):typeof n=="object"&&"props"in n?Fe((s=n.props)==null?void 0:s.children):""}function zs(n){return n?/\blanguage-mermaid\b|\bmermaid\b/i.test(n):!1}function Ts(n){const s=Array.isArray(n)?n:[n];for(const i of s){if(i==null||typeof i!="object"||!("props"in i))continue;const l=i.props;if(!(!l||!zs(l.className)))return Fe(l.children).replace(/\n$/,"")}return null}const qs=.4,Fs=4,be=.2;let Te=null;function Ps(){return Te||(Te=Gt(()=>import("./diagram-BF8g9yg4.js").then(n=>n.z),__vite__mapDeps([0,1,2,3])).then(n=>{const s=n.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral",fontFamily:"ui-sans-serif, system-ui, sans-serif"}),s})),Te}const Ls=32,V=new Map;function gt(n){return V.get(n)??null}function Bs(n,s){for(V.has(n)&&V.delete(n),V.set(n,s);V.size>Ls;){const i=V.keys().next().value;if(i==null)break;V.delete(i)}}function qe(n){return Math.min(Fs,Math.max(qs,n))}function Ws(n){const[s,i]=a.useState(1),[l,h]=a.useState({x:0,y:0}),x=a.useRef(null),[C,j]=a.useState(!1);a.useEffect(()=>{const o=A=>{A.key==="Escape"&&n.onClose()};window.addEventListener("keydown",o);const g=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",o),document.body.style.overflow=g}},[n.onClose]);function _(o){o.button===0&&(o.currentTarget.setPointerCapture(o.pointerId),x.current={pointerId:o.pointerId,startX:o.clientX,startY:o.clientY,originX:l.x,originY:l.y},j(!0))}function f(o){const g=x.current;!g||g.pointerId!==o.pointerId||h({x:g.originX+(o.clientX-g.startX),y:g.originY+(o.clientY-g.startY)})}function M(o){const g=x.current;if(!(!g||g.pointerId!==o.pointerId)){x.current=null,j(!1);try{o.currentTarget.releasePointerCapture(o.pointerId)}catch{}}}function p(o){o.preventDefault();const g=o.deltaY>0?-be:be;i(A=>qe(Number((A+g).toFixed(2))))}return Vt.createPortal(e.jsxs("div",{className:"mdocs-agent-mermaid-float",role:"dialog","aria-modal":"true","aria-label":"Mermaid 图预览",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-backdrop","aria-label":"关闭预览",onClick:n.onClose}),e.jsxs("div",{className:"mdocs-agent-mermaid-float-chrome",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-float-tools",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>i(o=>qe(Number((o-be).toFixed(2)))),title:"缩小","aria-label":"缩小",children:e.jsx(Es,{size:16,"aria-hidden":!0})}),e.jsxs("span",{className:"mdocs-agent-mermaid-float-scale",children:[Math.round(s*100),"%"]}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>i(o=>qe(Number((o+be).toFixed(2)))),title:"放大","aria-label":"放大",children:e.jsx(_s,{size:16,"aria-hidden":!0})}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>{i(1),h({x:0,y:0})},title:"重置",children:"重置"}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:n.onClose,title:"关闭","aria-label":"关闭",children:e.jsx(Ne,{size:16,"aria-hidden":!0})})]}),e.jsx("div",{className:C?"mdocs-agent-mermaid-float-stage is-dragging":"mdocs-agent-mermaid-float-stage",onPointerDown:_,onPointerMove:f,onPointerUp:M,onPointerCancel:M,onWheel:p,children:e.jsx("div",{className:"mdocs-agent-mermaid-float-canvas",style:{transform:`translate(calc(-50% + ${l.x}px), calc(-50% + ${l.y}px)) scale(${s})`},dangerouslySetInnerHTML:{__html:n.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function Os(n){const s=a.useId().replace(/:/g,""),[i,l]=a.useState("diagram"),[h,x]=a.useState(()=>gt(n.source.trim())),[C,j]=a.useState(null),[_,f]=a.useState(!1),[M,p]=a.useState(!1),o=a.useRef(null),g=n.source.trim(),A=a.useMemo(()=>g,[g]);a.useEffect(()=>()=>{o.current!=null&&window.clearTimeout(o.current)},[]),a.useEffect(()=>{if(i!=="diagram")return;if(!A){x(null),j(null);return}const v=gt(A);if(v){x(v),j(null);return}let S=!1;const q=window.setTimeout(()=>{(async()=>{try{const T=await Ps();if(S)return;const W=`mdocs-agent-mmd-${s}-${Date.now()}`,{svg:$}=await T.render(W,A);if(S)return;Bs(A,$),x($),j(null)}catch(T){if(S)return;x(null),j(T instanceof Error?T.message:"Mermaid 渲染失败")}})()},200);return()=>{S=!0,window.clearTimeout(q)}},[i,A,s]);async function z(){!g||!await vt(g)||(f(!0),o.current!=null&&window.clearTimeout(o.current),o.current=window.setTimeout(()=>f(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-mermaid",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toolbar",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toggle",role:"group","aria-label":"Mermaid 显示模式",children:[e.jsxs("button",{type:"button",className:i==="diagram"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>l("diagram"),"aria-pressed":i==="diagram",title:"图谱",children:[e.jsx(Nt,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"图谱"})]}),e.jsxs("button",{type:"button",className:i==="code"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>l("code"),"aria-pressed":i==="code",title:"代码",children:[e.jsx(es,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"代码"})]})]}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy mdocs-agent-mermaid-copy",onClick:()=>void z(),"aria-label":_?"已复制":"复制代码",title:_?"已复制":"复制",children:_?e.jsx(St,{size:14,"aria-hidden":!0}):e.jsx(Ct,{size:14,"aria-hidden":!0})})]}),i==="diagram"?e.jsx("div",{className:"mdocs-agent-mermaid-diagram",children:C?e.jsxs("div",{className:"mdocs-agent-mermaid-error",role:"alert",children:[e.jsx("p",{children:"无法渲染该图,可切换到代码查看源码。"}),e.jsx("pre",{children:C})]}):h?e.jsx("div",{className:"mdocs-agent-mermaid-svg mdocs-agent-mermaid-svg-hit",role:"button",tabIndex:0,onClick:()=>p(!0),onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),p(!0))},title:"点击放大预览","aria-label":"点击放大预览 Mermaid 图",children:e.jsx("span",{className:"mdocs-agent-mermaid-svg-inner",dangerouslySetInnerHTML:{__html:h}})}):e.jsx("div",{className:"mdocs-agent-mermaid-loading",children:"渲染中…"})}):e.jsx("div",{className:"mdocs-agent-panel-md-pre-wrap mdocs-agent-mermaid-code",children:e.jsx("pre",{children:n.codeChildren??e.jsx("code",{className:"language-mermaid",children:g})})}),M&&h?e.jsx(Ws,{svg:h,onClose:()=>p(!1)}):null]})}const Hs=a.memo(Os,(n,s)=>n.source===s.source);function Xs(n){const[s,i]=a.useState(()=>Date.now());return a.useEffect(()=>{if(!n)return;const l=window.setInterval(()=>i(Date.now()),1e3);return()=>window.clearInterval(l)},[n]),s}function Ks(n,s){if(!n.startedAt)return null;const i=n.endedAt??s;return Math.max(1,Math.round((i-n.startedAt)/1e3))}function It(n,s=Date.now()){let i=!1;const l=n.map(h=>h.type==="thinking"&&h.startedAt&&!h.endedAt?(i=!0,{...h,endedAt:s}):h);return i?l:n}function Us(n){const{block:s,live:i,now:l}=n;if(!s.text)return null;const h=Ks(s,l),x=h!=null?i?`思考中 ${h}s`:`思考 ${h}s`:"思考";return e.jsxs("details",{className:"mdocs-agent-panel-think-fold",children:[e.jsxs("summary",{children:[e.jsx("span",{className:"mdocs-agent-think-label"+(i?" live":""),children:x}),e.jsx(At,{size:14,strokeWidth:1.8,className:"mdocs-agent-think-chevron"})]}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:s.text})]})}function Pe(n){var s;return n==null||typeof n=="boolean"?"":typeof n=="string"||typeof n=="number"?String(n):Array.isArray(n)?n.map(Pe).join(""):typeof n=="object"&&"props"in n?Pe((s=n.props)==null?void 0:s.children):""}function Ys(n){const[s,i]=a.useState(!1),l=a.useRef(null),h=a.useRef(null),x=Pe(n.children).replace(/\n$/,"");a.useEffect(()=>()=>{l.current!=null&&window.clearTimeout(l.current)},[]);async function C(j){var p,o,g;j.preventDefault(),j.stopPropagation();const f=(((g=(o=(p=h.current)==null?void 0:p.querySelector("pre"))==null?void 0:o.innerText)==null?void 0:g.replace(/\n$/,""))??"")||x;!f||!await vt(f)||(i(!0),l.current!=null&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>i(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-panel-md-pre-wrap",ref:h,children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy",onClick:j=>void C(j),"aria-label":s?"已复制":"复制代码",title:s?"已复制":"复制",children:s?e.jsx(St,{size:14,"aria-hidden":!0}):e.jsx(Ct,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:n.children})]})}function Gs(n){const s=Ts(n.children);return s!=null?e.jsx(Hs,{source:s,codeChildren:n.children}):e.jsx(Ys,{children:n.children})}const Vs={pre:({children:n})=>e.jsx(Gs,{children:n})},xt=a.memo(function(s){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(hs,{remarkPlugins:[fs],components:Vs,children:s.children})})}),Zs=["如何发布文档?","草稿是什么?","如何创建工作空间?"];function yt(n,s){return s.map((i,l)=>{const h=i.skillNames&&i.skillNames.length>0?i.skillNames:i.skillIds&&i.skillIds.length>0?i.skillIds:void 0;return{id:`h-${n}-${l}-${i.role}`,role:i.role,content:i.content,skillNames:h}})}function Js(n,s){const i=It(n).slice(),l=i[i.length-1];return(l==null?void 0:l.type)==="text"?i[i.length-1]={type:"text",text:l.text+s}:i.push({type:"text",text:s}),i}function Qs(n,s){const i=Date.now(),l=n.slice(),h=l[l.length-1];return(h==null?void 0:h.type)==="thinking"&&!h.endedAt?l[l.length-1]={type:"thinking",text:h.text+s,startedAt:h.startedAt??i}:l.push({type:"thinking",text:s,startedAt:i}),l}function jt(n){return n!=null&&n.length?n.filter(s=>s.type==="text").map(s=>s.text).join(""):""}function en(n){return!!(n!=null&&n.some(s=>s.type==="thinking"&&s.text.length>0))}function tn(n){const s=new Date(n);if(Number.isNaN(s.getTime()))return"";const i=new Date;return s.getFullYear()===i.getFullYear()&&s.getMonth()===i.getMonth()&&s.getDate()===i.getDate()?s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function kt(n){if(n>=1e3){const s=n/1e3;return`${s>=10?Math.round(s):Math.round(s*10)/10}K`}return String(n)}function sn(n){const{block:s,onResolved:i}=n,[l,h]=a.useState(""),[x,C]=a.useState(!1),[j,_]=a.useState(1),f=a.useRef(!1),M=a.useRef(i);M.current=i;const p=s.status==="open",o=a.useRef(0);a.useEffect(()=>{if(!p)return;f.current=!1;const v=new Date(s.expiresAt).getTime(),S=Date.now(),q=Math.max(v-S,1);o.current=q,_(1);const T=()=>{const $=v-Date.now(),R=Math.max(0,Math.min(1,$/q));_(R),$<=0&&!f.current&&(f.current=!0,us(s.requestId).catch(()=>{}).finally(()=>{M.current(s.requestId,"","expired")}))};T();const W=window.setInterval(T,100);return()=>window.clearInterval(W)},[p,s.expiresAt,s.requestId]);async function g(v){const S=v.trim();if(!(!S||x||!p)){C(!0);try{await ms(s.requestId,S),i(s.requestId,S,"selected")}catch{i(s.requestId,S,"failed")}finally{C(!1)}}}async function A(){if(!(x||!p)){C(!0),f.current=!0;try{await wt(s.requestId),i(s.requestId,"","cancelled")}catch{i(s.requestId,"","failed")}finally{C(!1)}}}const z=Math.max(0,Math.ceil(j*o.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(p?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),p?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[z,"s"]}):null]}),p?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(j*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${j})`}})}):null,s.status==="selected"&&s.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",s.selected]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,p?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:s.options.map(v=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:x,onClick:()=>void g(v),children:v},v))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:l,disabled:x,placeholder:"或输入自己的内容…",onChange:v=>h(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),g(l))}}),e.jsx("button",{type:"button",disabled:x||!l.trim(),onClick:()=>void g(l),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:x,onClick:()=>void A(),children:"取消"})})]}):null]})}function nn(n){const h=2*Math.PI*8.75,x=Math.min(100,Math.max(0,n.percent)),C=h*(1-x/100),j=x>=90?"danger":x>=70?"warn":"ok",_=`上下文 ${x}% · 已用 ${kt(n.used)} / ${kt(n.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+j,"data-tooltip":_,"aria-label":_,role:"img",tabIndex:0,children:e.jsxs("svg",{width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,children:[e.jsx("circle",{className:"mdocs-agent-panel-context-track",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5}),e.jsx("circle",{className:"mdocs-agent-panel-context-value",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:h,strokeDashoffset:C,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function an(n){var s;for(const i of n)if(!(i.role!=="assistant"||!((s=i.blocks)!=null&&s.length))){for(const l of i.blocks)if((l.type==="choice_card"||l.type==="skill_form_card")&&l.status==="open")return!0}return!1}const hn=a.forwardRef(function(s,i){const{open:l,onClose:h,visitorName:x,anchorStyle:C,fullscreen:j,onToggleFullscreen:_,domainId:f,domains:M=[],localizeDomainName:p,documentId:o,documentTitle:g,documentPath:A,graphFileId:z,graphLabel:v,onOpenDocument:S,onTreeChanged:q,onDocumentOverwritten:T,onOpenCoding:W,embedded:$=!1,mode:R="normal",workingMarkdown:ve,baseMarkdown:ie,onMarkdownSet:Z,onSendingChange:oe,onSessionId:ee}=s,F=R==="coding"?"coding":"normal",O=F==="coding",_t=((x==null?void 0:x.trim().charAt(0))||"我").toUpperCase(),[J,H]=a.useState(!1),[Y,Le]=a.useState("current"),[Be,Mt]=a.useState({}),[Et,te]=a.useState(null),[We,Oe]=a.useState(""),[N,le]=a.useState(null),[Rt,ce]=a.useState(null),[X,E]=a.useState([]),[se,de]=a.useState(null),[ue,He]=a.useState([]),[Dt,Xe]=a.useState(!1),[me,pe]=a.useState(""),[ne,Ke]=a.useState([]),[Ue,we]=a.useState(!1),[w,he]=a.useState(!1),[Ye,P]=a.useState(null),[fe,Ge]=a.useState(null),[Se,G]=a.useState(!1),[K,Ve]=a.useState(!1),$t=a.useRef(null),ge=a.useRef(null),L=a.useRef(null),Ze=a.useRef(0),Q=a.useRef(!0),[zt,Ce]=a.useState(!1),Tt=Xs(w),Ae=a.useRef(X);Ae.current=X;const Je=!!(o!=null&&o.trim())&&!Ue,qt=(g==null?void 0:g.trim())||"当前文档",Qe=(A==null?void 0:A.trim())||"",Ie=!!(z!=null&&z.trim())&&!Ue,Ft=(v==null?void 0:v.trim())||"当前图谱";a.useEffect(()=>{we(!1)},[o,z]);function et(t){return Ze.current+=1,`${t}-${Ze.current}`}const tt=120;function st(t){return t.scrollHeight-t.scrollTop-t.clientHeight}function xe(){const t=ge.current;t&&(t.scrollTop=t.scrollHeight,Ce(!1))}function B(){Q.current&&xe()}function Pt(){const t=ge.current;if(!t)return;const u=st(t);Q.current=u<=48,Ce(u>tt)}function Lt(){Q.current=!0,xe()}a.useLayoutEffect(()=>{B();const t=ge.current;t&&Ce(st(t)>tt)},[X]);async function nt(){Xe(!0);try{const t=await rs(F,O?o:void 0);He(t.sessions),se||de(t.lastOpenedSessionId)}catch{}finally{Xe(!1)}}async function _e(){try{const t=await as();Ge(t)}catch{}}async function at(){try{const t=await pt();le(t),ce(null)}catch(t){le(null),ce(t instanceof Error?t.message:String(t))}}const ye=a.useRef(oe);ye.current=oe;const je=a.useRef(ee);je.current=ee,a.useEffect(()=>{var t;(t=ye.current)==null||t.call(ye,w)},[w]),a.useEffect(()=>{var t;(t=je.current)==null||t.call(je,se)},[se]),a.useEffect(()=>{var u;if(!l){H(!1),(u=L.current)==null||u.abort(),L.current=null,he(!1);return}let t=!1;return(async()=>{try{const r=await pt();t||(le(r),ce(null))}catch(r){t||(le(null),ce(r instanceof Error?r.message:String(r)))}})(),_e(),()=>{t=!0}},[l]);const ke=O?`coding:${o??""}`:"normal",rt=a.useRef(ke);a.useEffect(()=>{if(!l)return;const t=rt.current!==ke;rt.current=ke;let u=!1;return(async()=>{try{const r=await ts(F,O?o:void 0);if(u)return;de(r.sessionId),E(y=>!t&&y.length>0?y:yt(r.sessionId,r.messages))}catch{}})(),()=>{u=!0}},[l,ke]),a.useEffect(()=>{!l||!J||nt()},[l,J]);function Me(){if(!K){if(an(Ae.current)){G(!0);return}G(!1),h()}}async function Bt(){var r;if(K)return;Ve(!0);const t=Ae.current,u=[];for(const y of t)if(!(y.role!=="assistant"||!y.blocks))for(const m of y.blocks)m.type==="choice_card"&&m.status==="open"&&u.push(wt(m.requestId).catch(()=>{})),m.type==="skill_form_card"&&m.status==="open"&&u.push(bt(m.requestId).catch(()=>{}));await Promise.all(u),(r=L.current)==null||r.abort(),E(y=>y.map(m=>m.role!=="assistant"||!m.blocks?m:{...m,blocks:m.blocks.map(I=>I.type==="choice_card"&&I.status==="open"?{...I,status:"cancelled"}:I.type==="skill_form_card"&&I.status==="open"?{...I,status:"cancelled"}:I)})),G(!1),Ve(!1),h()}const Ee=a.useRef(Me);Ee.current=Me,a.useImperativeHandle(i,()=>({requestClose:()=>Ee.current()}),[]),a.useEffect(()=>{if(!l){G(!1);return}const t=u=>{if(u.key==="Escape"){if(Se){K||G(!1);return}if(J){H(!1);return}Ee.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[l,J,Se,K]);async function Re(t){var I;const u=t.trim();if(!u||w)return;if(!(N!=null&&N.enabled)){P((N==null?void 0:N.reason)==="missing_api_key"?"请先配置 API Key":(N==null?void 0:N.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(I=L.current)==null||I.abort();const r=new AbortController;L.current=r;const y={id:et("u"),role:"user",content:u,skillNames:ne.length>0?[...ne]:void 0},m=et("a");Q.current=!0,E(D=>[...D,y,{id:m,role:"assistant",content:""}]),pe(""),he(!0),P(null),H(!1),requestAnimationFrame(()=>{xe(),requestAnimationFrame(xe)});try{let D=!1;await os(u,{mode:F,skillNames:ne.length>0?ne:void 0,...O?{documentId:o??null,workingMarkdown:ve,baseMarkdown:ie}:{references:{domainId:(f==null?void 0:f.trim())||void 0,documentId:!Ie&&Je?o.trim():void 0,graphFileId:Ie?z.trim():void 0}},signal:r.signal,onEvent:d=>{d.type==="text_delta"?(E(b=>b.map(c=>{if(c.id!==m)return c;const k=Js(c.blocks??[],d.text);return{...c,blocks:k,content:jt(k)}})),requestAnimationFrame(()=>B())):d.type==="thinking_delta"?(E(b=>b.map(c=>{if(c.id!==m)return c;const k=Qs(c.blocks??[],d.text);return{...c,blocks:k}})),requestAnimationFrame(()=>B())):d.type==="sources"?(E(b=>b.map(c=>{if(c.id!==m)return c;const k=(c.blocks??[]).slice(),$e=k[k.length-1];return($e==null?void 0:$e.type)==="sources"?k[k.length-1]={type:"sources",items:d.items}:k.push({type:"sources",items:d.items}),{...c,blocks:k}})),requestAnimationFrame(()=>B())):d.type==="document_table"?(E(b=>b.map(c=>{if(c.id!==m)return c;const k=[...c.blocks??[],{type:"document_table",title:d.title,rows:d.rows}];return{...c,blocks:k}})),requestAnimationFrame(()=>B())):d.type==="document_card"?(E(b=>b.map(c=>{if(c.id!==m)return c;const k=[...c.blocks??[],{type:"document_card",documentId:d.documentId,title:d.title,path:d.path,preview:d.preview}];return{...c,blocks:k}})),requestAnimationFrame(()=>B())):d.type==="tool_notice"?(E(b=>b.map(c=>{if(c.id!==m)return c;const k=[...c.blocks??[],{type:"tool_notice",toolName:d.toolName,text:d.text}];return{...c,blocks:k}})),requestAnimationFrame(()=>B())):d.type==="choice_card"?(E(b=>b.map(c=>{if(c.id!==m)return c;const k=[...c.blocks??[],{type:"choice_card",requestId:d.requestId,title:d.title,options:d.options,expiresAt:d.expiresAt,status:"open"}];return{...c,blocks:k}})),requestAnimationFrame(()=>B())):d.type==="choice_expired"?E(b=>b.map(c=>c.id!==m||!c.blocks?c:{...c,blocks:c.blocks.map(k=>k.type==="choice_card"&&k.requestId===d.requestId&&k.status==="open"?{...k,status:"expired"}:k)})):d.type==="skill_form_card"?(E(b=>b.map(c=>{if(c.id!==m)return c;const k=[...c.blocks??[],{type:"skill_form_card",requestId:d.requestId,mode:d.mode,title:d.title,currentName:d.currentName,initialName:d.initialName,initialDescription:d.initialDescription,initialBody:d.initialBody,expiresAt:d.expiresAt,status:"open"}];return{...c,blocks:k}})),requestAnimationFrame(()=>B())):d.type==="skill_form_expired"?E(b=>b.map(c=>c.id!==m||!c.blocks?c:{...c,blocks:c.blocks.map(k=>k.type==="skill_form_card"&&k.requestId===d.requestId&&k.status==="open"?{...k,status:"expired"}:k)})):d.type==="markdown_set"?Z==null||Z(d.markdown):d.type==="tree_changed"?q==null||q():d.type==="document_overwritten"?T==null||T({documentId:d.documentId,headCommitId:d.headCommitId}):d.type==="open_coding"?W==null||W({documentId:d.documentId,displayName:d.displayName}):d.type==="context_usage"?Ge({percent:d.percent,used:d.used,limit:d.limit}):d.type==="error"&&(D=!0,P(d.message))}}),!r.signal.aborted&&!D&&Ke([])}catch(D){if(r.signal.aborted)return;P(D instanceof Error?D.message:String(D))}finally{E(D=>D.map(d=>d.id===m&&d.blocks?{...d,blocks:It(d.blocks)}:d)),L.current===r&&(L.current=null),he(!1)}}async function Wt(){var t;if(!w){(t=L.current)==null||t.abort(),P(null),H(!1),he(!1);try{const u=await is(F,O?o:void 0,f??null);de(u.sessionId),E([]),pe(""),Q.current=!0,_e(),nt()}catch(u){P(u instanceof Error?u.message:String(u))}}}async function Ot(t){var u;if(!w){if(t===se){H(!1);return}(u=L.current)==null||u.abort(),P(null);try{const r=await ls(t,F,O?o:void 0);de(r.sessionId),E(yt(r.sessionId,r.messages)),pe(""),H(!1),te(null),Q.current=!0,requestAnimationFrame(()=>B()),_e()}catch(r){P(r instanceof Error?r.message:String(r))}}}function it(t){He(u=>{const r=u.map(y=>y.id===t.id?{...y,...t}:y);return r.sort((y,m)=>{const I=y.pinned===!0,D=m.pinned===!0;return I!==D?I?-1:1:y.updatedAt<m.updatedAt?1:y.updatedAt>m.updatedAt?-1:0}),r})}async function Ht(t){if(!w)try{const u=await cs(t.id,t.pinned!==!0,F);it(u)}catch(u){P(u instanceof Error?u.message:String(u))}}function Xt(t){te(t.id),Oe(t.title)}async function ot(t){const u=We.trim();if(te(null),!!u)try{const r=await ds(t,u,F);it(r)}catch(r){P(r instanceof Error?r.message:String(r))}}const Kt=t=>{const u=M.find(r=>r.domainId===t);return u?p?p(u.domainName):u.domainName:t===re?"default":t},ae=a.useMemo(()=>Y==="all"||!f?ue:ue.filter(t=>(t.domainId||re)===f),[ue,Y,f]),lt=a.useMemo(()=>ae.filter(t=>t.pinned===!0),[ae]),Ut=a.useMemo(()=>{var r;const t=new Map;for(const y of ae){const m=((r=y.domainId)==null?void 0:r.trim())||re,I=t.get(m);I?I.push(y):t.set(m,[y])}const u=(f==null?void 0:f.trim())||re;return Array.from(t.entries()).map(([y,m])=>({id:y,items:m,label:Kt(y)})).sort((y,m)=>y.id===u?-1:m.id===u?1:y.label.localeCompare(m.label,"zh"))},[ae,M,p,f]);function ct(t){return Be[t]!==void 0?!Be[t]:Y==="all"?t===((f==null?void 0:f.trim())||re):!0}function Yt(t){Mt(u=>{const r=ct(t);return{...u,[t]:r}})}function dt(t){!t||!S||S(t)}function ut(t){const u=Et===t.id;return e.jsxs("div",{className:"mdocs-agent-panel-history-item"+(t.id===se?" active":""),children:[u?e.jsx("input",{className:"mdocs-agent-panel-history-rename",value:We,autoFocus:!0,maxLength:80,"aria-label":"重命名会话",onChange:r=>Oe(r.target.value),onClick:r=>r.stopPropagation(),onKeyDown:r=>{r.key==="Enter"?(r.preventDefault(),ot(t.id)):r.key==="Escape"&&te(null)},onBlur:()=>void ot(t.id)}):e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-open",disabled:w,onClick:()=>void Ot(t.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:t.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:tn(t.updatedAt)})]}),e.jsxs("div",{className:"mdocs-agent-panel-history-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-action"+(t.pinned?" pinned":""),title:t.pinned?"取消置顶":"置顶","aria-label":t.pinned?"取消置顶":"置顶",disabled:w,onClick:r=>{r.stopPropagation(),Ht(t)},children:e.jsx(As,{size:14,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-action",title:"重命名","aria-label":"重命名",disabled:w||u,onClick:r=>{r.stopPropagation(),Xt(t)},children:e.jsx(Ss,{size:14,strokeWidth:1.8})})]})]})}if(!l)return null;const De=(N==null?void 0:N.reason)==="missing_api_key",mt=Rt??(N&&!N.enabled&&!De?N.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:$t,className:"mdocs-agent-panel"+($?" mdocs-agent-panel--embedded":j?" mdocs-agent-panel--fullscreen":""),role:$?void 0:"dialog","aria-label":$?"对话":"mdocs 智能助手","aria-modal":$?void 0:j?!0:void 0,style:$||j?void 0:C,children:[e.jsxs("header",{className:"mdocs-agent-panel-header",children:[e.jsx("div",{className:"mdocs-agent-panel-title",children:$?e.jsx("span",{children:"对话"}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:ht,alt:"",className:"mdocs-agent-panel-title-logo"}),e.jsx("span",{children:"mdocs 智能助手"})]})}),e.jsxs("div",{className:"mdocs-agent-panel-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:w,onClick:()=>void Wt(),children:e.jsx(ps,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(J?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>H(t=>!t),children:e.jsx(js,{size:16,strokeWidth:1.8})}),$||!_?null:e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:j?"退出全屏":"全屏","aria-label":j?"退出全屏":"全屏",onClick:_,children:j?e.jsx(vs,{size:16,strokeWidth:1.8}):e.jsx(bs,{size:16,strokeWidth:1.8})}),$?null:e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:Me,children:e.jsx(Ne,{size:16,strokeWidth:1.8})})]})]}),J?e.jsxs("div",{className:"mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>{H(!1),te(null)},children:"返回对话"})]}),e.jsxs("div",{className:"mdocs-agent-panel-history-filters",role:"tablist","aria-label":"按工作空间筛选",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":Y==="current",className:"mdocs-agent-panel-history-filter"+(Y==="current"?" active":""),onClick:()=>Le("current"),children:"当前工作空间"}),e.jsx("button",{type:"button",role:"tab","aria-selected":Y==="all",className:"mdocs-agent-panel-history-filter"+(Y==="all"?" active":""),onClick:()=>Le("all"),children:"全部"})]}),Dt?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):ue.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):ae.length===0?e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"此工作空间暂无会话"}):e.jsxs("div",{className:"mdocs-agent-panel-history-list",children:[lt.length>0?e.jsxs("section",{className:"mdocs-agent-panel-history-section",children:[e.jsx("div",{className:"mdocs-agent-panel-history-section-label",children:"Pinned"}),e.jsx("ul",{children:lt.map(t=>e.jsx("li",{children:ut(t)},t.id))})]}):null,Ut.map(t=>{const u=ct(t.id);return e.jsxs("section",{className:"mdocs-agent-panel-history-folder",children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-folder-head","aria-expanded":u,onClick:()=>Yt(t.id),children:[u?e.jsx(ss,{size:14,strokeWidth:1.8}):e.jsx(At,{size:14,strokeWidth:1.8}),e.jsx("span",{className:"mdocs-agent-panel-history-folder-name",children:t.label}),e.jsx("span",{className:"mdocs-agent-panel-history-folder-count",children:t.items.length})]}),u?e.jsx("ul",{children:t.items.map(r=>e.jsx("li",{children:ut(r)},r.id))}):null]},t.id)})]})]}):e.jsxs("div",{className:"mdocs-agent-panel-body",children:[e.jsxs("div",{className:"mdocs-agent-panel-scroll-wrap",children:[e.jsx("div",{className:"mdocs-agent-panel-welcome",ref:ge,onScroll:Pt,children:X.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-hello",children:"你好,我是 mdocs 智能助手"}),e.jsx("p",{className:"mdocs-agent-panel-desc",children:O?"描述你想写或改的内容。助手会更新右侧提案;请按段接受或拒绝后完成写回。":"我能答疑、搜文档、整理结构,也能帮你写全文;需要精细改稿请点文档顶栏「帮写」。"}),De?e.jsx(ft,{onConfigured:at}):mt?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:mt}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:Zs.map(t=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void Re(t),disabled:w||!(N!=null&&N.enabled),children:t},t))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:X.map(t=>{var u;return e.jsxs("div",{className:"mdocs-agent-panel-msg"+(t.role==="user"?" mdocs-agent-panel-msg-user":" mdocs-agent-panel-msg-assistant"),children:[t.role==="assistant"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-ai","aria-hidden":!0,children:e.jsx("img",{src:ht,alt:""})}):null,e.jsxs("div",{className:"mdocs-agent-panel-msg-bubble",children:[t.role==="user"&&t.skillNames&&t.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",t.skillNames.length]}):null,t.role==="assistant"?t.blocks&&t.blocks.length>0?e.jsxs("div",{className:"mdocs-agent-panel-timeline",children:[t.blocks.map((r,y)=>r.type==="thinking"?e.jsx(Us,{block:r,live:w&&!r.endedAt,now:Tt},`${t.id}-th-${y}`):r.type==="text"?r.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(xt,{children:r.text})},`${t.id}-t-${y}`):null:r.type==="sources"?r.items.length===0?null:e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:["已阅读 ",r.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:r.items.map(m=>e.jsx("li",{children:e.jsx("a",{href:m.url,target:"_blank",rel:"noreferrer",children:m.name})},m.id))})]})},`${t.id}-s-${y}`):r.type==="tool_notice"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:r.text})},`${t.id}-n-${y}`):r.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(sn,{block:r,onResolved:(m,I,D)=>{E(d=>d.map(b=>b.id!==t.id||!b.blocks?b:{...b,blocks:b.blocks.map(c=>c.type==="choice_card"&&c.requestId===m?{...c,status:D,selected:D==="selected"?I:c.selected}:c)}))}})},`${t.id}-ch-${y}`):r.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx($s,{block:r,onResolved:(m,I,D)=>{E(d=>d.map(b=>b.id!==t.id||!b.blocks?b:{...b,blocks:b.blocks.map(c=>c.type==="skill_form_card"&&c.requestId===m?{...c,status:I,submittedName:I==="submitted"?D:c.submittedName}:c)}))}})},`${t.id}-sf-${y}`):r.type==="document_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:m=>{m.preventDefault(),m.stopPropagation(),dt(r.documentId)},children:["《",r.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"文档预览"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[r.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:r.path}):null,r.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:r.preview}):e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview muted",children:"(无正文预览)"})]})]})},`${t.id}-c-${y}`):e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[r.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:r.rows.length===0?"无结果":`${r.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:r.rows.length===0?e.jsx("p",{className:"mdocs-agent-panel-doc-table-empty",children:"无结果"}):e.jsxs("table",{className:"mdocs-agent-panel-doc-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"文章名字"}),e.jsx("th",{children:"文章内容"})]})}),e.jsx("tbody",{children:r.rows.map(m=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>dt(m.documentId),children:m.title})}),e.jsx("td",{children:m.summary||"-"})]},m.documentId))})]})})]})},`${t.id}-d-${y}`)),w&&t.id===((u=X[X.length-1])==null?void 0:u.id)&&!jt(t.blocks)&&!en(t.blocks)?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null]}):t.content?e.jsx(xt,{children:t.content}):w?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null:t.content]}),t.role==="user"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-user","aria-hidden":!0,children:_t}):null]},t.id)})})}),zt?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:Lt,title:"回到底部","aria-label":"回到底部",children:[e.jsx(xs,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),Ye?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Ye}):null,De&&X.length>0?e.jsx(ft,{onConfigured:at}):null,e.jsx(Rs,{selectedNames:ne,onChange:Ke,disabled:w||!(N!=null&&N.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap",children:[O?null:Ie?e.jsxs("div",{className:"mdocs-agent-doc-ref mdocs-agent-graph-ref",children:[e.jsx(Nt,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:Ft}),e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:"图谱(只读)"})]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前图谱",disabled:w,onClick:()=>we(!0),children:e.jsx(Ne,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):Je?e.jsxs("div",{className:"mdocs-agent-doc-ref",children:[e.jsx(ns,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:qt}),Qe?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:Qe}):null]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前文档",disabled:w,onClick:()=>we(!0),children:e.jsx(Ne,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):null,e.jsxs("div",{className:"mdocs-agent-panel-input-body",children:[e.jsx("textarea",{className:"mdocs-agent-panel-input",rows:2,placeholder:N!=null&&N.enabled?O?"说说要写什么…":"把你的问题告诉我…":"请先配置 API Key",value:me,disabled:w||!(N!=null&&N.enabled),onChange:t=>pe(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),Re(me))}}),fe?e.jsx(nn,{percent:fe.percent,used:fe.used,limit:fe.limit}):null,e.jsx("button",{type:"button",className:w?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:w?!1:!(N!=null&&N.enabled)||!me.trim(),onClick:()=>{var t;if(w){(t=L.current)==null||t.abort();return}Re(me)},title:w?"停止":"发送","aria-label":w?"停止":"发送",children:w?"■":"↑"})]})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),Se?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{K||G(!1)},children:e.jsxs("div",{className:"mdocs-message-dialog mdocs-agent-close-confirm",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-agent-close-confirm-title",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{id:"mdocs-agent-close-confirm-title",className:"mdocs-message-dialog-title",children:"有待处理的倒计时"}),e.jsx("p",{className:"mdocs-message-dialog-body",children:"当前还有选择卡或 Skill 表单在倒计时。强制关闭会取消这些操作并退出助手;也可以继续等待完成后再关。"}),e.jsxs("div",{className:"mdocs-message-dialog-actions mdocs-agent-close-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",disabled:K,onClick:()=>G(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:K,onClick:()=>void Bt(),children:K?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{hn as AgentChatPanel};
@@ -1 +0,0 @@
1
- import{r as t,j as e}from"./react-vendor-BVS1XoFi.js";import{c as ie,$ as Es,a0 as Rs,V as Fs,l as de,a1 as zs,a2 as Ls,a3 as ee,a4 as Oe,a5 as Bs,a6 as Os,a7 as Us,a as Ks,d as Ze,a8 as ls,a9 as os,aa as $s,ab as Vs,ac as Ws,ad as _s,ae as Gs,af as rs,ag as ze,ah as qs,ai as Hs,aj as Js,X as Zs,ak as Ys,al as Qs,f as ds,am as Xs,an as et,ao as st,ap as tt,aq as at,ar as ms,as as nt,at as it,au as ct,av as lt,aw as ot,ax as rt,ay as dt,az as us,aA as mt,aB as ut,aC as ht,aD as pt,aE as gt,aF as ft,aG as xt,aH as yt,aI as bt,U as jt,aJ as Nt,aK as vt,aL as kt,aM as St,r as wt,j as Ct,aN as Dt,k as It,m as Tt}from"./index-DNb6Q69l.js";import{V as hs,a as At,M as Ye}from"./VisitorPickerModal-BTmTrqrT.js";import{C as Mt}from"./check-CnsclxvV.js";import{ai as Le,aj as Pt,ak as Et,al as Rt,am as Ft,an as zt,ao as Qe,ap as Lt,aq as Xe}from"./ui-CEFkTVnG.js";import"./diagram-BF8g9yg4.js";import"./motion-BAXVQJfN.js";function Bt({draft:a,onClose:s,onSuccess:g}){const{t:u,lang:y}=ie(),[z,x]=t.useState([]),[S,v]=t.useState(a.domainId??""),[p,w]=t.useState([]),[A,I]=t.useState(""),[c,N]=t.useState(`${a.displayName||"untitled"}_recovered.md`),[f,m]=t.useState(!1),[D,M]=t.useState(null),b=t.useRef(null),R=t.useRef(!0);t.useEffect(()=>(R.current=!0,()=>{R.current=!1}),[]),t.useEffect(()=>{Es().then(k=>{R.current&&x(k)})},[]),t.useEffect(()=>{S&&(w([]),I(""),Rs(S).then(k=>{R.current&&w(k)}).catch(()=>{R.current&&w([])}))},[S]),t.useEffect(()=>{const k=window.setTimeout(()=>{var P;return(P=b.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(k)},[]),t.useEffect(()=>{const k=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[s]);function O(k,P){for(const C of k){if(C.type==="folder"&&C.path===P)return C.documentId;if(C.type==="folder"){const F=O(C.children,P);if(F)return F}}return null}async function L(k){k.preventDefault(),m(!0),M(null);const P=c.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),C=P.endsWith(".md")?P:P+".md",F=C.replace(/\.md$/i,"");try{const h=A?`${A}/${C}`:C,d=A?O(p,A)??void 0:void 0;await Ls({fileName:C,displayName:F,content:a.content,domainId:S,parentId:d}),g()}catch(h){M(ee(u,h))}finally{m(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:k=>{k.target===k.currentTarget&&!f&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:u("recoverDraft")}),e.jsx("p",{className:"muted",children:u("recoverDraftDesc",{name:a.displayName||u("unknownTitle")})}),e.jsxs("form",{onSubmit:L,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[u("domainLabel"),z.length>0&&e.jsx(Fs,{domains:z,value:S,onChange:v,onDomainsChange:x,ariaLabel:u("domainLabel"),localizeName:k=>de(k,y,u)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[u("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(zs,{nodes:p,activeDocumentId:null,selectedParentPath:A,onOpen:()=>{},onOpenFolder:k=>I(k),onContextMenu:()=>{},onDeselect:()=>I("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[u("fileNameLabel"),e.jsx("input",{ref:b,value:c,onChange:k=>N(k.target.value),placeholder:"recovered.md",maxLength:200,disabled:f})]}),D&&e.jsx("div",{className:"mdocs-dialog-error",children:D}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!f&&s(),disabled:f,children:u("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:f,children:u(f?"creating":"create")})]})]})]})})}function Ot({onPublish:a,onClose:s,onCountChange:g,onRecover:u}){const{t:y}=ie(),[z,x]=t.useState([]),[S,v]=t.useState(new Set),[p,w]=t.useState(!1),[A,I]=t.useState(null),[c,N]=t.useState(null),[f,m]=t.useState(null),D=t.useRef(null),M=t.useRef(!0);t.useEffect(()=>(M.current=!0,Oe().then(d=>{if(!M.current)return;const j=d.filter(T=>!T.published);x(j),g==null||g(j.length)}),()=>{M.current=!1,D.current&&(clearTimeout(D.current),D.current=null)}),[]),t.useEffect(()=>{const d=j=>{j.key==="Escape"&&s()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s]);const b=t.useCallback((d,j)=>{m({message:d,type:j}),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>m(null),3e3)},[]);async function R(d){await Os(d),v(j=>new Set(j).add(d));try{await a(d),x(j=>{const T=j.filter(K=>K.documentId!==d);return g==null||g(T.length),T}),b(y("published"),"success")}catch(j){j instanceof Us||b(y("publishFailed"),"error");const T=await Ks(d);T&&x(K=>K.map(G=>G.documentId===d?T:G))}finally{v(j=>{const T=new Set(j);return T.delete(d),T})}}async function O(d){I(null),await Ze(d),x(j=>{const T=j.filter(K=>K.documentId!==d);return g==null||g(T.length),T}),b(y("draftDeleted"),"success")}function L(d){const j=z.find(T=>T.documentId===d);j&&N(j)}function k(d){N(null),Ze(d),x(j=>{const T=j.filter(K=>K.documentId!==d);return g==null||g(T.length),T}),u==null||u(z.find(j=>j.documentId===d)),b(y("published"),"success")}async function P(){w(!0);let d=0,j=0;for(const G of z)try{await a(G.documentId),d++}catch{j++}const K=(await Oe()).filter(G=>!G.published);x(K),g==null||g(K.length),j===0?b(y("publishAll"),"success"):b(`${d} published, ${j} failed`,"error"),w(!1)}const C=d=>new Date(d).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),F=d=>Bs(y,d,d.publishError??"UNKNOWN"),h=z;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-drawer-overlay",onClick:s}),e.jsxs("div",{className:"mdocs-drawer",role:"dialog","aria-modal":"true",children:[e.jsxs("header",{className:"mdocs-drawer-header",children:[e.jsxs("div",{className:"mdocs-drawer-header-text",children:[e.jsxs("h2",{className:"mdocs-drawer-title",children:[y("unpublishedDrafts"),h.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:h.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:y("draftCount",{count:String(h.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":y("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:h.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:y("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:h.map(d=>{const j=!!d.publishError;return e.jsxs("div",{className:j?"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:d.displayName||y("unknownTitle")}),j?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[C(d.publishErrorAt)," · ",F(d)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[C(d.updatedAt)," · ",y("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[j?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:p,onClick:()=>L(d.documentId),children:y("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:S.has(d.documentId)||p,onClick:()=>void R(d.documentId),children:S.has(d.documentId)?y("publishing"):y("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:p,onClick:()=>I(d.documentId),children:y("delete")})]})]},d.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:y("close")}),e.jsx("button",{type:"button",className:"primary",disabled:h.length===0||p,onClick:()=>void P(),children:p?y("publishing"):`${y("publishAll")} (${h.length})`})]}),f&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+f.type,role:"status",children:f.message})]}),A&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:d=>{d.target===d.currentTarget&&I(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:y("delete")}),e.jsx("p",{className:"muted",children:y("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>I(null),children:y("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void O(A),children:y("delete")})]})]})}),c&&e.jsx(Bt,{draft:c,onClose:()=>N(null),onSuccess:()=>k(c.documentId)})]})}function Ut(){const{t:a,lang:s}=ie(),g=ls(),u=t.useRef(!1),[y,z]=t.useState([]),[x,S]=t.useState(!1),[v,p]=t.useState(""),[w,A]=t.useState("restricted"),[I,c]=t.useState(!1),[N,f]=t.useState(null),[m,D]=t.useState(null),[M,b]=t.useState(""),[R,O]=t.useState(""),[L,k]=t.useState("all"),[P,C]=t.useState(null);t.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const F=t.useCallback(async()=>{S(!0),f(null);try{const i=await os();if(!u.current)return;z(i)}catch(i){if(!u.current)return;f(ee(a,i))}finally{u.current&&S(!1)}},[a]);t.useEffect(()=>{F()},[F]);async function h(i){if(i.preventDefault(),!v.trim()){f(a("domainNameRequired"));return}c(!0),f(null);try{if(await Gs({domainName:v.trim(),permission:w}),!u.current)return;p(""),A("restricted"),await F()}catch(r){if(!u.current)return;f(ee(a,r))}finally{u.current&&c(!1)}}async function d(i){if(M.trim()){f(null);try{if(await _s(i,M.trim()),!u.current)return;D(null),C(null),await F()}catch(r){if(!u.current)return;f(ee(a,r))}}}function j(i){D(i.domainId),b(i.domainName),C(null)}function T(){D(null),C(null)}async function K(i,r){f(null);try{if(await Ws(i,r),!u.current)return;C(null),await F()}catch(U){if(!u.current)return;f(ee(a,U))}}async function G(i){if(window.confirm(a("deleteDomainConfirmDetail",{name:i.domainName,count:String(i.docCount)}))){f(null);try{if(await Vs(i.domainId),!u.current)return;await F()}catch(r){if(!u.current)return;f(ee(a,r))}}}const J=t.useCallback(i=>$s(i,a),[a]),Z=t.useCallback(i=>de(i.domainName,s,a),[s,a]),Q=t.useMemo(()=>{const i=R.trim().toLowerCase();return y.filter(r=>L!=="all"&&r.permission!==L?!1:i?de(r.domainName,s,a).toLowerCase().includes(i)||r.domainName.toLowerCase().includes(i):!0)},[y,R,L,s,a]),q=t.useCallback((i,r)=>{const U=J(i.permission);return r?`${U} ${a("domainTypeBuiltinSuffix")}`:U},[J,a]);return{domains:y,loadingDomains:x,domainError:N,newDomainName:v,setNewDomainName:p,newDomainPermission:w,setNewDomainPermission:A,creating:I,handleCreateDomain:h,renamingId:m,setRenamingId:D,renameDraft:M,setRenameDraft:b,startRename:j,cancelRename:T,handleRename:d,changeTypeForId:P,setChangeTypeForId:C,handlePermissionChange:K,handleDelete:G,domainSearch:R,setDomainSearch:O,domainFilter:L,setDomainFilter:k,filteredDomains:Q,visitorId:g,plabel:J,localizeDomain:Z,domainTypeLabel:q}}const es={private:0,restricted:1,public:2};function ss(a){return Object.prototype.hasOwnProperty.call(es,a)?es[a]:null}function ts(a,s){const g=ss(a),u=ss(s);return g===null||u===null?"invalid":u>g?"upgrade":u<g?"downgrade":"same"}function Kt(){const{t:a}=ie(),s=Ut(),[g,u]=t.useState([]),[y,z]=t.useState(null),[x,S]=t.useState(""),v=t.useRef(null),[p,w]=t.useState(null),A=t.useCallback(async()=>{try{const c=await rs();u(c)}catch{u([])}},[]);t.useEffect(()=>{A()},[A]),t.useEffect(()=>{if(!s.changeTypeForId)return;const c=N=>{var f;(f=v.current)!=null&&f.contains(N.target)||s.setChangeTypeForId(null)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s.changeTypeForId,s.setChangeTypeForId]);async function I(c){z(null);try{const N=await Qs(c.domainId);w({domainId:c.domainId,creatorVisitorId:c.creatorVisitorId,initialIds:N.map(f=>f.visitorId),memberRows:N})}catch(N){z({kind:"err",text:translateError(a,N)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:a("domainManagement")})}),e.jsx("p",{className:"mdocs-domain-mgmt-restricted-hint",children:a("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:a("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:a("domainName")}),e.jsx("input",{value:s.newDomainName,onChange:c=>s.setNewDomainName(c.target.value),placeholder:a("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:a("domainPermission")}),e.jsx("div",{className:"mdocs-domain-mgmt-type-radios",children:ze.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?a("creating"):a("create")})]})]}),y&&e.jsx("div",{className:"mdocs-settings-card",style:{color:y.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:y.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:a("domainSearchPlaceholder"),className:"mdocs-domain-mgmt-search","aria-label":a("domainSearchPlaceholder")}),e.jsx("div",{className:"mdocs-domain-mgmt-filters",role:"group","aria-label":a("domainPermission"),children:["all",...ze].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"?a("domainFilterAll"):s.plabel(c)},c))})]}),s.loadingDomains?e.jsx("div",{className:"mdocs-settings-card",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:a("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:a("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:a("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:a("domainColName")}),e.jsx("th",{scope:"col",children:a("domainColType")}),e.jsx("th",{scope:"col",className:"mdocs-domain-table-num",children:a("domainColDocCount")}),e.jsx("th",{scope:"col",children:a("domainColActions")})]})}),e.jsx("tbody",{children:s.filteredDomains.map(c=>{const N=qs(c,s.visitorId),f=Hs(c.domainId),m=Js(c),D=ts(c.permission,"public")==="upgrade",M=D?m?a("domainTooltipTypeLocked"):void 0:a("domainPermissionAlreadyTop");return e.jsxs("tr",{className:f?"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:b=>s.setRenameDraft(b.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:a("save")}),e.jsx("button",{type:"button",onClick:s.cancelRename,children:a("cancel")})]}):e.jsxs("div",{className:"mdocs-domain-table-name-cell",children:[e.jsx("span",{className:"mdocs-domain-table-name",children:s.localizeDomain(c)}),f&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:a("domainBuiltIn")}),!N&&!f&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:a("shared")})]})}),e.jsx("td",{children:e.jsx("span",{className:"mdocs-domain-table-type",title:M,children:e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":c.permission,children:s.domainTypeLabel(c,f)})})}),e.jsx("td",{className:"mdocs-domain-table-num",children:c.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[f&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:a("domainNotModifiable")}),!f&&!N&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:a("domainNotCreator")}),!f&&N&&s.changeTypeForId===c.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",ref:v,children:[e.jsx("div",{className:"mdocs-domain-type-segment",role:"radiogroup","aria-label":a("domainChangeType"),children:ze.map(b=>{const O=ts(c.permission,b)==="downgrade";return e.jsx("span",{title:O?a("domainPermissionNoDowngrade"):void 0,children:e.jsx("button",{type:"button",role:"radio","aria-checked":x===b,className:x===b?"active":"",disabled:O,onClick:()=>S(b),children:s.plabel(b)})},b)})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon confirm","aria-label":a("save"),disabled:x===""||x===c.permission,onClick:()=>{x&&x!==c.permission&&s.handlePermissionChange(c.domainId,x)},children:e.jsx(Mt,{size:14,strokeWidth:2.5})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon cancel","aria-label":a("cancel"),onClick:()=>s.setChangeTypeForId(null),children:e.jsx(Zs,{size:14,strokeWidth:2.5})})]}),!f&&N&&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 I(c),children:a("domainMembersManageButton")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:m?a("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(c)},disabled:m,children:a("rename")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:M,onClick:()=>{s.setRenamingId(null),S(c.permission),s.setChangeTypeForId(c.domainId)},disabled:!D,children:a("domainChangeType")}),e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--danger",title:m?a("domainLocked"):void 0,onClick:()=>void s.handleDelete(c),disabled:m,children:a("deleteDomain")})]})]})]},c.domainId)})})]})})]}),e.jsx(hs,{open:p!==null,title:a("domainMembersPickerTitle"),initialSelectedIds:(p==null?void 0:p.initialIds)??[],lockedIds:p?[p.creatorVisitorId]:[],seedMembers:p==null?void 0:p.memberRows,templates:g,onClose:()=>w(null),onConfirm:async c=>{p&&(await Ys(p.domainId,c),z({kind:"ok",text:a("domainMembersSaved",{count:String(c.length)})}))}})]})}function as(a){return a.length<=6?a:`${a.slice(0,6)}…`}function $t(){const{t:a}=ie(),s=t.useRef(!0),[g,u]=t.useState([]),[y,z]=t.useState(!0),[x,S]=t.useState(null),[v,p]=t.useState(1),[w,A]=t.useState(null),[I,c]=t.useState(""),[N,f]=t.useState([]),[m,D]=t.useState(!1),[M,b]=t.useState(null),[R,O]=t.useState(!1),L=ls(),[k,P]=t.useState([]),[C,F]=t.useState("idle"),[h,d]=t.useState("");t.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),t.useEffect(()=>{F("loading"),ds().then(o=>{s.current&&(P(o),F("ok"))}).catch(()=>{s.current&&F("err")})},[]);const j=t.useMemo(()=>{const o=new Map;for(const E of k)o.set(E.visitorId,E.visitorName);return o},[k]),T=t.useCallback(async()=>{z(!0),b(null);try{const o=await rs();s.current&&u(o)}catch(o){s.current&&b(ee(a,o))}finally{s.current&&z(!1)}},[a]);t.useEffect(()=>{T()},[T]);const K=t.useMemo(()=>N.map(o=>{const E=k.find(W=>W.visitorId===o);return{visitorId:o,name:E?E.visitorName:a("visitorPickerUnknownVisitor"),muted:!E}}),[N,k,a]);function G(o){f(E=>E.includes(o)?E.filter(W=>W!==o):[...E,o])}const J=v===1?I.trim().length>0:v===2?N.length>0:!0;function Z(){if(!(v>=3)){if(!J){O(!0);return}O(!1),p(v+1),d("")}}function Q(){v<=1||(O(!1),p(v-1))}function q(){S(null),A(null),c(""),f(L?[L]:[]),b(null),p(1),d(""),O(!1)}function i(o){S(null),A(o.id),c(o.displayName);const E=L&&!o.visitorIds.includes(L)?[...o.visitorIds,L]:[...o.visitorIds];f(E),b(null),p(1),d(""),O(!1)}async function r(){if(!(!I.trim()||N.length===0)){D(!0),b(null);try{if(w===null?await Xs({displayName:I.trim(),visitorIds:N}):await et(w,{displayName:I.trim(),visitorIds:N}),!s.current)return;q(),await T()}catch(o){if(!s.current)return;b(ee(a,o))}finally{s.current&&D(!1)}}}async function U(o){D(!0),b(null);try{if(await st(o),!s.current)return;S(null),w===o&&q(),await T()}catch(E){if(!s.current)return;b(ee(a,E))}finally{s.current&&D(!1)}}const V=[{key:1,label:a("memberTemplateStepName")},{key:2,label:a("memberTemplateStepMembers")},{key:3,label:a("memberTemplateStepSave")}],$=`${(v-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:a(w!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),w!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:q,style:{fontSize:12},children:a("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:$}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:V.map(o=>{const E=v===o.key,W=v>o.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${E?" current":""}${W?" done":""}`,children:W?"✓":o.key}),e.jsx("span",{className:`mdocs-wizard-step-label${E?" current":""}${W?" done":""}`,children:o.label})]},o.key)})})]}),M&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:M}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[v===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:I,onChange:o=>c(o.target.value),placeholder:a("memberTemplateNamePlaceholder"),maxLength:200,disabled:m,autoFocus:!0,"aria-invalid":R&&!I.trim()}),R&&!I.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:a("domainNameRequired")})]}),v===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(At,{visitors:k,loadState:C,searchFilter:h,onSearchChange:d,selectedIds:new Set(N),onToggle:G,selectedRows:K,myVisitorId:L}),e.jsx("p",{className:`mdocs-wizard-hint${R&&N.length===0?" danger":""}`,children:"💡 "+a("memberTemplateStep2Hint")})]}),v===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:a("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:I})]}),e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:a("memberTemplateIdsLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:a("memberTemplateSelectedSummary",{count:String(N.length)})})]}),N.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[N.slice(0,15).map(o=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:as(o)},o)),N.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",N.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:Q,children:["← ",a("memberTemplateWizardBack")]}),v<3?e.jsxs("button",{type:"button",className:"primary",onClick:Z,children:[a("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void r(),children:a(m?"saving":w===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:a("memberTemplateSavedList")}),y?e.jsx("span",{className:"mdocs-settings-item-desc",children:a("loading")}):g.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:a("memberTemplateEmpty")}),w===null&&e.jsx("button",{type:"button",className:"primary",onClick:q,children:a("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:g.map(o=>e.jsx("li",{className:"mdocs-member-template-row",children:x===o.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:a("memberTemplateConfirmDeleteDesc",{name:o.displayName})}),e.jsxs("div",{className:"mdocs-member-template-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",style:{color:"var(--mdocs-danger)"},onClick:()=>void U(o.id),children:a(m?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>S(null),children:a("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:o.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:a("memberTemplateCount",{count:String(o.visitorIds.length)})}),o.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:o.visitorIds.map(E=>e.jsx("span",{className:"mdocs-member-template-tag",children:j.get(E)??as(E)},E))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>i(o),children:a("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>S(o.id),children:a("memberTemplateDelete")})]})]})},o.id))})]})]})]})}const Vt=[{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 _t(a,s,g){return a==="deepseek"?"Deepseek":s||g}function ns(a){return`${_t(a.kind,a.providerId,a.name)} · ${a.modelId} · ${a.name}`}function Gt(){const{t:a}=ie(),s=t.useRef(!0),[g,u]=t.useState(""),[y,z]=t.useState([]),[x,S]=t.useState(null),[v,p]=t.useState(null),[w,A]=t.useState("deepseek"),[I,c]=t.useState(""),[N,f]=t.useState(""),[m,D]=t.useState(""),[M,b]=t.useState("openai-completions"),[R,O]=t.useState("deepseek-flash"),[L,k]=t.useState(1e6),[P,C]=t.useState(""),[F,h]=t.useState(!1),[d,j]=t.useState(null),[T,K]=t.useState(!1),[G,J]=t.useState(!0),[Z,Q]=t.useState(!1),[q,i]=t.useState(null),[r,U]=t.useState(!1),[V,$]=t.useState(!1),[o,E]=t.useState(!1),[W,se]=t.useState(null),[ce,ae]=t.useState(null),te=t.useRef(!1);t.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const ne=t.useCallback(async()=>{const l=await tt();if(s.current)return z(l),l},[]);function le(){p(null),A("deepseek"),c(""),f(""),D(""),b("openai-completions"),O("deepseek-flash"),k(1e6),C(""),h(!1),j(null),K(!1),$(!1),E(!1),i(null),U(!1)}function xe(l){p(l.id),A(l.kind),c(l.name),f(l.providerId??""),D(l.baseUrl),b(l.apiType);const _=l.modelId.trim(),je=new Set(["deepseek-flash","deepseek-v4-flash","deepseek-v4-flash-vision-exp","deepseek-v4.1-flash","deepseek-v4.1-flash-expires-on-0910"]);O(l.kind==="deepseek"?_==="deepseek-v4-pro"?"deepseek-v4-pro":je.has(_)?"deepseek-flash":_||"deepseek-flash":_),k(l.contextWindow||1e6),h(l.hasApiKey),j(l.apiKeyMasked),C(""),K(l.isDefault)}t.useEffect(()=>{(async()=>{try{const l=await at();if(!s.current)return;u(l.visitorName);const _=await ne();if(!s.current||!_)return;_.length===0&&(le(),S("create"))}catch(l){if(!s.current)return;i(l instanceof Error?l.message:String(l)),S("create")}finally{s.current&&J(!1)}})()},[ne]);function we(){le(),S("create")}function ye(l){xe(l),S("edit"),U(!1),i(null)}function oe(){le(),S(null)}async function Ce(l){if(!(l.isDefault||ce)){ae(l.id),i(null);try{await nt(l.id),await ne()}catch(_){if(!s.current)return;i(_ instanceof Error?_.message:String(_))}finally{s.current&&ae(null)}}}async function be(){if(W){Q(!0),i(null);try{await ct(W.id);const l=await ne();if(!s.current)return;x==="edit"&&v===W.id&&oe(),((l==null?void 0:l.length)??0)===0&&(le(),S("create"))}catch(l){if(!s.current)return;i(l instanceof Error?l.message:String(l))}finally{s.current&&(Q(!1),se(null))}}}async function De(){Q(!0),i(null),U(!1);try{const l=w==="custom"?{...x==="edit"&&v?{id:v}:{},...x==="create"&&T?{isDefault:!0}:{},kind:w,baseUrl:m,modelId:R,providerId:N.trim()||void 0,apiType:M,name:I,contextWindow:L,...P.trim()?{apiKey:P.trim()}:{}}:{...x==="edit"&&v?{id:v}:{},...x==="create"&&T?{isDefault:!0}:{},kind:w,modelId:R,name:I,contextWindow:L,...P.trim()?{apiKey:P.trim()}:{}};if(await it(l),!s.current)return;await ne(),U(!0),S(null),le()}catch(l){if(!s.current)return;i(l instanceof Error?l.message:String(l))}finally{s.current&&Q(!1)}}const Ie=x!==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:a("agentConfig")}),G?null:e.jsx("button",{type:"button",className:"secondary",onClick:we,children:"添加配置"})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!G&&y.length>0?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:y.map(l=>e.jsxs("li",{className:"mdocs-agent-config-item",children:[e.jsxs("label",{className:"mdocs-agent-config-item-default",children:[e.jsx("input",{type:"radio",name:"agent-default-config",checked:l.isDefault,disabled:ce!==null,onChange:()=>void Ce(l)}),e.jsx("span",{children:l.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:ns(l)}),l.kind==="custom"?e.jsx("span",{className:"mdocs-agent-badge",children:"自定义"}):null,e.jsx("p",{className:"mdocs-agent-config-item-meta",children:l.hasApiKey?`Key ${l.apiKeyMasked??"已配置"}`:"未配置 Key"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>ye(l),children:a("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>se(l),children:"删除"})]})]},l.id))}),r?e.jsx("p",{className:"mdocs-agent-config-ok",children:a("saved")}):null,q?e.jsx("p",{className:"mdocs-agent-config-error",children:q}):null]}):null,Ie?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsxs("p",{className:"mdocs-agent-config-lead",children:[x==="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":w==="deepseek",className:w==="deepseek"?"active":"",onClick:()=>A("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":w==="custom",className:w==="custom"?"active":"",onClick:()=>A("custom"),children:"自定义"})]}),w==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigModel")}),e.jsx(Ye,{options:[...Vt],value:R,onChange:O})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:V?"text":"password",value:P,onChange:l=>C(l.target.value),placeholder:F?a("agentConfigApiKeyConfigured").replace("{{masked}}",d??"…"):a("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":a(V?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>$(l=>!l),children:V?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:m,onChange:l=>{const _=l.target.value;if(D(_),te.current)return;_.toLowerCase().includes("anthropic")?b("anthropic-messages"):b("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:R,onChange:l=>O(l.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:V?"text":"password",value:P,onChange:l=>C(l.target.value),placeholder:F?a("agentConfigApiKeyConfigured").replace("{{masked}}",d??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":a(V?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>$(l=>!l),children:V?"隐藏":"显示"})]})]})]}),e.jsxs("details",{className:"mdocs-agent-advanced",open:o,onToggle:l=>E(l.target.open),children:[e.jsx("summary",{children:"高级选项"}),w==="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:N,onChange:l=>f(l.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Ye,{options:[...Wt],value:M,onChange:l=>{te.current=!0,b(l)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigName")}),e.jsx("input",{type:"text",value:I,onChange:l=>c(l.target.value),placeholder:a("agentConfigNameDefault").replace("{{name}}",g||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:L,onChange:l=>k(Number(l.target.value)||1e6)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:a("agentConfigContextWindowDesc")})]})]}),x==="create"&&y.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:T,onChange:l=>K(l.target.checked)}),e.jsx("span",{children:"保存后设为默认配置"})]}):null,q?e.jsx("p",{className:"mdocs-agent-config-error",children:q}):null,e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void De(),disabled:Z,children:a(Z?"saving":"save")}),y.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:oe,disabled:Z,children:a("cancel")}):null]})]})]}):G?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:a("loading")})}):null]}),W?e.jsx(ms,{title:"删除配置",message:`确定删除「${ns(W)}」?${W.isDefault&&y.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:a("cancel"),onConfirm:()=>void be(),onCancel:()=>se(null)}):null]})}const qt=/^[A-Za-z0-9_]+$/;function Be(a){return qt.test(a.trim())}function Ht(){const a=t.useRef(!0),[s,g]=t.useState([]),[u,y]=t.useState(!0),[z,x]=t.useState(null),[S,v]=t.useState(null),[p,w]=t.useState(!1),[A,I]=t.useState(""),[c,N]=t.useState(""),[f,m]=t.useState(""),[D,M]=t.useState(!1);t.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]);async function b(){y(!0),x(null);try{const h=await lt();if(!a.current)return;g(h)}catch(h){if(!a.current)return;x(h instanceof Error?h.message:String(h))}finally{a.current&&y(!1)}}t.useEffect(()=>{b()},[]);function R(){w(!0),v(null),I(""),N(""),m(""),x(null)}function O(h){w(!1),v(h.id),I(h.name),N(h.description),m(h.body),x(null)}function L(){w(!1),v(null),I(""),N(""),m("")}async function k(){const h=A.trim();if(!Be(h)){x("名称仅允许英文、数字、下划线");return}if(!f.trim()){x("正文不能为空");return}M(!0),x(null);try{if(p?await ot({name:h,description:c,body:f}):S&&await rt(S,{name:h,description:c,body:f}),!a.current)return;L(),await b()}catch(d){if(!a.current)return;x(d instanceof Error?d.message:String(d))}finally{a.current&&M(!1)}}async function P(h){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){x(null);try{if(await dt(h),!a.current)return;S===h&&L(),await b()}catch(d){if(!a.current)return;x(d instanceof Error?d.message:String(d))}}}const C=p||S!==null,F=!A.trim()||Be(A);return e.jsxs("div",{className:"mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!u&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),C?null:e.jsx("button",{type:"button",className:"secondary",onClick:R,children:"新建"})]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc mdocs-agent-skills-lead",children:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),z?e.jsx("p",{className:"mdocs-agent-skills-error",children:z}):null,C?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:p?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:A,onChange:h=>I(h.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:F?void 0:"mdocs-agent-skills-input-invalid"}),F?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:h=>N(h.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:f,onChange:h=>m(h.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void k(),disabled:D||!F||!A.trim()||!f.trim(),children:D?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:L,disabled:D,children:"取消"})]})]}):null,u?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!u&&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:R,children:"新建第一个"})]}):null,!u&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(h=>{const d=Be(h.name),j=S===h.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(j?" 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:h.name}),d?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:h.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>O(h),disabled:C&&!j,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(h.id),disabled:C,children:"删除"})]})]},h.id)})}):null]})})]})}const Jt={algorithm:Et.defaultAlgorithm,token:{colorPrimary:"#4CAF50",colorLink:"#4CAF50",colorInfo:"#4CAF50",colorSuccess:"#66BB6A",colorBgBase:"#ffffff",colorBgContainer:"#ffffff",colorText:"#212121",colorTextSecondary:"#616161",colorBorder:"#E0E0E0",colorFillSecondary:"#E8F5E9",borderRadius:8,fontFamily:"inherit"},components:{Table:{headerBg:"#F5F5F5",headerColor:"#212121",rowHoverBg:"#E8F5E9",borderColor:"#E0E0E0"},Button:{primaryShadow:"none"},Tag:{defaultBg:"#F5F5F5",defaultColor:"#616161"}}};function is(a,s){if(!a)return"—";const g=new Date(a);return Number.isNaN(g.getTime())?"—":g.toLocaleString(s==="zh"?"zh-CN":"en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function Zt(a){const{t:s,lang:g}=ie(),[u,y]=t.useState(!1),[z,x]=t.useState(!1),[S,v]=t.useState(!1),[p,w]=t.useState([]),[A,I]=t.useState([]),[c,N]=t.useState(null),[f,m]=t.useState(null),[D,M]=t.useState(""),[b,R]=t.useState("keyword"),[O,L]=t.useState(null),[k,P]=t.useState(!1),C=t.useRef(0),[F,h]=t.useState({current:1,pageSize:20}),[d,j]=t.useState(0);async function T(){y(!0),m(null);try{const i=await mt();v(i.modelReady),w(i.items),I([]),j(i.items.length),h(r=>({...r,current:1}))}catch(i){m(ee(s,i)||s("embeddingIndexLoadFailed"))}finally{y(!1)}}t.useEffect(()=>{T()},[]);const K=t.useMemo(()=>{const i=new Map;for(const r of p)i.has(r.domainId)||i.set(r.domainId,de(r.domainName,g,s));return Array.from(i.entries()).map(([r,U])=>({text:U,value:r}))},[p,g,s]),G=t.useMemo(()=>{const i=D.trim().toLowerCase();return i?p.filter(r=>(r.displayName||"").toLowerCase().includes(i)||(r.relativePath||"").toLowerCase().includes(i)||r.documentId.toLowerCase().includes(i)):p},[p,D]),J=b==="semantic"&&!!D.trim();t.useEffect(()=>{if(b!=="semantic")return;const i=D.trim();if(!i){C.current+=1,L(null);return}const r=++C.current;P(!0);const U=window.setTimeout(()=>{(async()=>{try{const V=await us({query:i,mode:"semantic",topN:50});if(r!==C.current)return;const $=new Map(p.map(o=>[o.documentId,o]));L(V.results.map(o=>{const E=$.get(o.documentId);return E?{...E,snippet:o.snippet}:{documentId:o.documentId,displayName:o.displayName,relativePath:o.relativePath,domainId:o.domainId,domainName:o.domainId,documentUpdatedAt:o.updatedAt,chunkCount:0,chunkUnknown:!0,embeddingUpdatedAt:null,snippet:o.snippet}}))}catch{r===C.current&&L([])}finally{r===C.current&&P(!1)}})()},300);return()=>window.clearTimeout(U)},[b,D,p]);const Z=J?O??[]:G;t.useEffect(()=>{j(Z.length),h(i=>({...i,current:1}))},[Z.length,b]);const Q=t.useMemo(()=>[{title:s("myDocumentsColTitle"),dataIndex:"displayName",key:"displayName",ellipsis:!0,sorter:(i,r)=>(i.displayName||i.relativePath).localeCompare(r.displayName||r.relativePath,g==="zh"?"zh":"en"),render:(i,r)=>e.jsxs("div",{style:{minWidth:0},children:[e.jsx("button",{type:"button",className:"mdocs-linkish",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontWeight:500,color:"inherit",textAlign:"left"},onClick:()=>a.onOpenDocument(r.documentId),children:r.displayName||r.relativePath||"Untitled"}),r.snippet&&e.jsx("div",{className:"mdocs-embedding-index-snippet",title:r.snippet,children:r.snippet})]})},{title:s("myDocumentsColDomain"),dataIndex:"domainId",key:"domainId",width:160,ellipsis:!0,filters:K,onFilter:(i,r)=>r.domainId===i,sorter:(i,r)=>de(i.domainName,g,s).localeCompare(de(r.domainName,g,s),g==="zh"?"zh":"en"),render:(i,r)=>de(r.domainName,g,s)},{title:s("embeddingIndexColDocUpdated"),dataIndex:"documentUpdatedAt",key:"documentUpdatedAt",width:160,sorter:(i,r)=>new Date(i.documentUpdatedAt).getTime()-new Date(r.documentUpdatedAt).getTime(),defaultSortOrder:"descend",render:i=>is(i,g)},{title:s("embeddingIndexColStatus"),dataIndex:"chunkCount",key:"buildStatus",width:140,filters:[{text:s("embeddingIndexFilterBuilt"),value:"built"},{text:s("embeddingIndexFilterMissing"),value:"missing"}],onFilter:(i,r)=>i==="built"?r.chunkCount>0:r.chunkCount===0,sorter:(i,r)=>i.chunkCount-r.chunkCount,render:(i,r)=>r.chunkUnknown?e.jsx(Le,{color:"success",children:s("embeddingIndexStatusBuiltUnknown")}):i>0?e.jsx(Le,{color:"success",children:s("embeddingIndexStatusReady",{chunks:String(i)})}):e.jsx(Le,{children:s("embeddingIndexStatusMissing")})},{title:s("embeddingIndexColBuiltAt"),dataIndex:"embeddingUpdatedAt",key:"embeddingUpdatedAt",width:160,sorter:(i,r)=>{const U=i.embeddingUpdatedAt?new Date(i.embeddingUpdatedAt).getTime():0,V=r.embeddingUpdatedAt?new Date(r.embeddingUpdatedAt).getTime():0;return U-V},render:i=>is(i,g)}],[K,g,a,s]);async function q(){const i=A.map(String);if(i.length!==0){x(!0),N(null),m(null);try{const r=await ut(i);v(r.modelReady),N(s("embeddingIndexRebuildResult",{ok:String(r.ok.length),skipped:String(r.skipped.length),failed:String(r.failed.length)})),await T()}catch(r){m(ee(s,r)||s("embeddingIndexRebuildFailed"))}finally{x(!1)}}}return e.jsx(Pt,{theme:Jt,children:e.jsxs("div",{className:"mdocs-settings mdocs-embedding-index",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("embeddingIndex")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"muted",style:{marginTop:0},children:s("embeddingIndexDesc")}),e.jsxs("p",{style:{margin:"0 0 12px",fontSize:13},children:[s("embeddingIndexModel"),":"," ",e.jsx("strong",{children:s(S?"embeddingIndexModelReady":"embeddingIndexModelPending")})]}),e.jsxs(Rt,{wrap:!0,style:{marginBottom:12},children:[e.jsx(Ft,{value:b,"aria-label":s("myDocumentsSearchMode"),onChange:i=>R(i),options:[{label:s("myDocumentsModeKeyword"),value:"keyword"},{label:s("myDocumentsModeSemantic"),value:"semantic"}]}),e.jsx(zt.Search,{allowClear:!0,placeholder:s(b==="semantic"?"embeddingIndexSearchSemanticPlaceholder":"embeddingIndexSearchPlaceholder"),"aria-label":s(b==="semantic"?"embeddingIndexSearchSemanticPlaceholder":"embeddingIndexSearchPlaceholder"),value:D,onChange:i=>M(i.target.value),style:{width:240},disabled:u||z}),e.jsx(Qe,{onClick:()=>void T(),disabled:u||z,children:s("embeddingIndexRefresh")}),e.jsx(Qe,{type:"primary",onClick:()=>void q(),disabled:z||A.length===0,loading:z,children:s("embeddingIndexRebuildSelected",{count:String(A.length)})})]}),c&&e.jsx("p",{style:{fontSize:13,color:"var(--mdocs-text-muted)"},children:c}),f&&e.jsx("p",{className:"mdocs-doc-search-error",style:{marginBottom:8},children:f}),J&&!S&&e.jsx("p",{className:"muted",style:{margin:"0 0 8px",fontSize:13},children:s("myDocumentsSemanticNotReady")}),(()=>{const i=Number(F.pageSize)||20,r=Number(F.current)||1,U=d,V=Math.max(1,Math.ceil(U/i)||1);return e.jsx(Lt,{size:"small",rowKey:"documentId",loading:u||J&&k,columns:Q,dataSource:Z,rowSelection:{selectedRowKeys:A,onChange:$=>I($)},pagination:{current:r,pageSize:i,total:U,showSizeChanger:!1,showQuickJumper:!1,showTotal:($,o)=>s("embeddingIndexPageTotal",{from:String(o[0]??0),to:String(o[1]??0),total:String($)})},onChange:($,o,E,W)=>{const se=$.pageSize??i,ce=W.currentDataSource.length,ae=Math.max(1,Math.ceil(ce/se)||1);let te=$.current??1;te>ae&&(te=ae),j(ce),h({current:te,pageSize:se})},locale:{emptyText:D.trim()?s("myDocumentsNoMatch"):s("embeddingIndexEmpty"),filterReset:s("embeddingIndexFilterReset"),filterConfirm:s("embeddingIndexFilterOk")},scroll:{x:900},footer:()=>e.jsxs("div",{className:"mdocs-embedding-index-pager",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"flex-end",gap:10},children:[e.jsx("span",{style:{fontSize:13},children:s("embeddingIndexPageSize")}),e.jsx(Xe,{size:"small",min:5,max:200,step:5,value:i,controls:!0,changeOnWheel:!0,disabled:u||z,"aria-label":s("embeddingIndexPageSize"),onChange:$=>{if($==null||!Number.isFinite(Number($)))return;const o=Math.min(200,Math.max(5,Math.floor(Number($))));h({current:1,pageSize:o})}}),e.jsx("span",{style:{fontSize:13},children:s("embeddingIndexGoPage")}),e.jsx(Xe,{size:"small",min:1,max:V,step:1,value:Math.min(r,V),controls:!0,changeOnWheel:!0,disabled:u||z||U===0,"aria-label":s("embeddingIndexGoPage"),onChange:$=>{if($==null||!Number.isFinite(Number($)))return;const o=Math.min(V,Math.max(1,Math.floor(Number($))));h(E=>({...E,current:o}))}}),e.jsxs("span",{style:{fontSize:13,color:"var(--mdocs-text-muted)"},children:["/ ",V]})]})})})()]})]})})}function cs(a,s){const g=localStorage.getItem(a);return g===null?s:g==="true"}function Se(a){const s=new Date(a);if(Number.isNaN(s.getTime()))return"—";const g=String(s.getMonth()+1).padStart(2,"0"),u=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${g}-${u}`}function na(a){const{t:s,lang:g,setLang:u}=ie(),{onBack:y,onPublishDraft:z}=a,x=ht(),[S,v]=t.useState(!1);pt(x&&!S,()=>v(!0));const p=t.useRef(!0);t.useEffect(()=>(p.current=!0,()=>{p.current=!1}),[]),t.useEffect(()=>{x||v(!1)},[x]);const[w,A]=t.useState(()=>cs("mdocs.autoPublish",!1)),[I,c]=t.useState(()=>cs("mdocs.autoEdit",!0)),[N,f]=t.useState(!1),[m,D]=t.useState("general");function M(n){D(n),x&&v(!1)}const b=s(m==="general"?"general":m==="bookmarks"?"bookmarkTitle":m==="myDocuments"?"myDocuments":m==="embeddingIndex"?"embeddingIndex":m==="domainManagement"?"domainManagement":m==="memberTemplates"?"memberTemplates":m==="agentConfig"?"agentConfig":"saveAndPublish"),[R,O]=t.useState([]),[L,k]=t.useState(!0),[P,C]=t.useState(null),[F,h]=t.useState(!1),[d,j]=t.useState(!1),[T,K]=t.useState(!1),[G,J]=t.useState(!1),[Z,Q]=t.useState(null),[q,i]=t.useState(!1),[r,U]=t.useState(!1),[V,$]=t.useState(!1),[o,E]=t.useState(""),[W,se]=t.useState(!1),[ce,ae]=t.useState(!1),[te,ne]=t.useState(0),[le,xe]=t.useState([]),[we,ye]=t.useState(!1),[oe,Ce]=t.useState(""),[be,De]=t.useState([]),[Ie,l]=t.useState(!1),[_,je]=t.useState(""),[ue,ps]=t.useState("auto"),[Ne,Te]=t.useState(null),[Ue,Ae]=t.useState(!0),[me,gs]=t.useState(0),[Ke,$e]=t.useState("1"),[Ve,fs]=t.useState(0),[he,xs]=t.useState(""),[Me,ys]=t.useState(""),[ve,bs]=t.useState(""),[js,Ns]=t.useState(null),[vs,ks]=t.useState([]),ke=t.useRef(0),Pe=20,pe=Ne!==null,[We,Ss]=t.useState([]),[ws,Ee]=t.useState(!1),[Re,_e]=t.useState(null),[Fe,Ge]=t.useState(new Map);t.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(w))},[w]),t.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(I))},[I]),t.useEffect(()=>{m==="savePublish"&&Oe().then(n=>{p.current&&ne(n.filter(B=>!B.published).length)})},[m]),t.useEffect(()=>{m==="bookmarks"&&Cs(),m==="myDocuments"&&(fe(),ds().then(n=>{p.current&&ks(n)}).catch(()=>{}))},[m,he,Me,ve]),t.useEffect(()=>{if(m!=="myDocuments")return;const n=_.trim();if(!n){ke.current+=1,Te(null),Ae(!0);return}const B=++ke.current,Y=window.setTimeout(()=>{(async()=>{try{const H=await us({query:n,mode:ue,domainId:he||void 0,topN:50});if(!p.current||B!==ke.current)return;Te(H.results),Ae(H.modelReady)}catch{if(!p.current||B!==ke.current)return;Te([]),Ae(!0)}})()},300);return()=>window.clearTimeout(Y)},[m,_,ue,he]),t.useEffect(()=>{qe()},[]),t.useEffect(()=>{os().then(n=>{p.current&&Ss(n)}).catch(()=>{})},[]);const ge=new Map(We.map(n=>[n.domainId,n.domainName]));async function qe(){try{k(!0);const n=await gt();if(!p.current)return;O(n)}catch{}finally{p.current&&k(!1)}}async function Cs(){try{ye(!0);const n=await ft();if(!p.current)return;xe(n)}catch{}finally{p.current&&ye(!1)}}async function fe(n=0){try{l(!0);const B=await xt({offset:n*Pe,limit:Pe,domainId:he||void 0,creatorVisitorId:Me||void 0,groupBy:ve||void 0});if(!p.current)return;De(B.items),Ns(B.groups??null),fs(B.total),gs(n),$e(String(n+1))}catch{}finally{p.current&&l(!1)}}async function Ds(n){try{await wt(n),xe(B=>B.filter(Y=>Y.documentId!==n))}catch{}}function Is(){if(R.some(B=>!B.revoked)){j(!0);return}He()}async function He(){try{h(!0);const n=await Dt();C({token:n.token,name:n.name}),await qe()}finally{h(!1)}}async function Ts(){try{$(!0);const n=await kt();Q(n.recoveryCode)}finally{$(!1)}}async function As(n){n.preventDefault();const B=o.trim();if(!(B&&B.length<4))try{se(!0),await St(B),E(""),ae(!0),setTimeout(()=>ae(!1),3e3)}finally{se(!1)}}async function Ms(n){_e(n);try{const B=await Ct(n),Y=new Map;B.forEach(H=>{Y.set(H.visitorId,H.permission)}),Ge(Y)}catch{Ge(new Map)}Ee(!0)}async function Ps(n){if(Re)try{const B=new Set(n.map(H=>H.visitorId)),Y=new Set(Fe.keys());for(const H of Y)B.has(H)||await It(Re,H);for(const H of n)await Tt(Re,H.visitorId,H.permission);await fe()}finally{Ee(!1),_e(null)}}const Je=le.filter(n=>{if(!oe.trim())return!0;const B=oe.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(B)||(n.ownerVisitorName||"").toLowerCase().includes(B)||(n.domainId||"").toLowerCase().includes(B)}),re=Math.ceil(Ve/Pe);return e.jsxs("div",{className:"mdocs-layout"+(x?" mdocs-layout--reader mdocs-layout--settings":""),children:[x&&S?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>v(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(x?S?" 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:yt,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),x?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>v(!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(bt,{size:18})}):null]}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(m==="general"?" active":""),onClick:()=>M("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(m==="bookmarks"?" active":""),onClick:()=>M("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(m==="myDocuments"?" active":""),onClick:()=>M("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(m==="embeddingIndex"?" active":""),onClick:()=>M("embeddingIndex"),children:s("embeddingIndex")}),e.jsx("div",{className:"mdocs-config-item"+(m==="domainManagement"?" active":""),onClick:()=>M("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(m==="memberTemplates"?" active":""),onClick:()=>M("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(m==="agentConfig"?" active":""),onClick:()=>M("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(m==="savePublish"?" active":""),onClick:()=>M("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:y,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[x?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>v(!0),"aria-label":s("expandSidebar"),children:e.jsx(jt,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:b})]}):null,Nt(),m==="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:g==="en"?"active":"",onClick:()=>u("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:g==="zh"?"active":"",onClick:()=>u("zh"),children:"中"})]})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoEdit")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoEditDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(I?" active":""),role:"switch","aria-checked":I,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")}),!L&&R.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:R.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:Is,disabled:F||L,children:F?"…":R.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),J(!1),K(!0),window.setTimeout(()=>K(!1),2e3)}catch{K(!1),J(!0),window.setTimeout(()=>J(!1),3e3)}})()},children:s(T?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>C(null),children:s("close")})]}),T&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),G&&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:Ts,disabled:V,children:V?"…":"生成恢复码"})]}),Z&&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:Z})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(Z),U(!1),i(!0),window.setTimeout(()=>i(!1),2e3)}catch{i(!1),U(!0),window.setTimeout(()=>U(!1),3e3)}})()},children:q?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>Q(null),children:s("close")})]}),q&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),r&&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:As,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:o,onChange:n=>E(n.target.value),minLength:0,style:{marginBottom:8}}),ce&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:W,children:W?"设置中…":"保存密码"})]})]})]})]}):m==="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:oe,onChange:n=>Ce(n.target.value)}),we?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Je.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(oe?"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:Je.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>a.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:n.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):ge.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:()=>Ds(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})})]})]}):m==="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(vt,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("input",{type:"text",placeholder:"搜索文章…",value:_,onChange:n=>je(n.target.value)})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:he,"aria-label":s("myDocumentsFilterDomain"),onChange:n=>xs(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllDomains")}),We.map(n=>e.jsx("option",{value:n.domainId,children:ge.get(n.domainId)||n.domainName},n.domainId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ue,"aria-label":s("myDocumentsSearchMode"),onChange:n=>ps(n.target.value),children:[e.jsx("option",{value:"auto",children:s("myDocumentsModeAuto")}),e.jsx("option",{value:"keyword",children:s("myDocumentsModeKeyword")}),e.jsx("option",{value:"semantic",children:s("myDocumentsModeSemantic")})]}),!pe&&e.jsxs("select",{className:"mdocs-my-docs-select",value:Me,"aria-label":s("myDocumentsFilterCreator"),onChange:n=>ys(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllCreators")}),vs.map(n=>e.jsx("option",{value:n.visitorId,children:n.visitorName},n.visitorId))]}),!pe&&e.jsxs("select",{className:"mdocs-my-docs-select",value:ve,"aria-label":s("myDocumentsGroupBy"),onChange:n=>bs(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")})]})]}),Ie&&!pe?e.jsx("div",{className:"mdocs-my-docs-empty",children:s("loading")}):pe?e.jsx(e.Fragment,{children:Ne.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(ue==="semantic"&&!Ue?"myDocumentsSemanticNotReady":"myDocumentsNoMatch")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-my-docs-search-meta",children:[s("myDocumentsResultCount",{count:String(Ne.length)}),ue==="semantic"&&!Ue?` · ${s("myDocumentsSemanticNotReadyShort")}`:""]}),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:Ne.map(n=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>a.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:ge.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Se(n.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:n.createdAt?Se(n.createdAt):"—"}),e.jsx("td",{className:"mdocs-my-docs-actions",children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>a.onOpenDocument(n.documentId),children:s("bookmarkOpen")})})]},n.documentId))})]})})]})}):e.jsxs(e.Fragment,{children:[be.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(_?"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:(js??[{key:"",items:be}]).flatMap(n=>{var H;const B=n.key?e.jsx("tr",{className:"mdocs-my-docs-group",children:e.jsx("td",{colSpan:6,children:ve==="domain"?ge.get(n.key)||n.key:((H=n.items[0])==null?void 0:H.creatorName)||n.key})},`group-${n.key}`):null,Y=n.items.map(X=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>a.onOpenDocument(X.documentId),children:X.displayName||X.relativePath||"Untitled"}),e.jsx("td",{children:ge.get(X.domainId||"")||X.domainId||"—"}),e.jsx("td",{children:X.creatorName||X.creatorVisitorId||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Se(X.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:Se(X.createdAt)}),e.jsxs("td",{className:"mdocs-my-docs-actions",children:[e.jsx("button",{type:"button",className:"ghost small",onClick:()=>Ms(X.documentId),children:s("docInfoInviteMember")}),e.jsx("button",{type:"button",className:"primary small",onClick:()=>a.onOpenDocument(X.documentId),children:s("bookmarkOpen")})]})]},X.documentId));return B?[B,...Y]:Y})})]})}),!pe&&e.jsxs("div",{className:"mdocs-my-docs-footer",children:[e.jsx("span",{className:"mdocs-settings-page-info",children:s("myDocumentsPageInfo",{current:String(re>0?me+1:0),total:String(re),count:String(Ve)})}),re>1&&e.jsxs("form",{className:"mdocs-my-docs-jump",onSubmit:n=>{n.preventDefault();const B=Number.parseInt(Ke,10);if(!Number.isFinite(B))return;const Y=Math.min(Math.max(B,1),re)-1;Y!==me&&fe(Y)},children:[e.jsx("span",{children:s("myDocumentsJumpTo")}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:re,"aria-label":s("myDocumentsJumpTo"),value:Ke,onChange:n=>$e(n.target.value)}),e.jsx("button",{type:"submit",className:"secondary small",children:s("myDocumentsJump")})]}),re>1&&e.jsxs("div",{className:"mdocs-settings-pagination",children:[e.jsx("button",{type:"button",className:"secondary small",disabled:me<=0,onClick:()=>fe(me-1),children:s("myDocumentsPrev")}),e.jsx("button",{type:"button",className:"secondary small",disabled:me>=re-1,onClick:()=>fe(me+1),children:s("myDocumentsNext")})]})]})]})]})]}):m==="embeddingIndex"?e.jsx(Zt,{onOpenDocument:a.onOpenDocument}):m==="domainManagement"?e.jsx(Kt,{}):m==="memberTemplates"?e.jsx($t,{}):m==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Gt,{}),e.jsx(Ht,{})]}):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:y,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"+(w?" active":""),role:"switch","aria-checked":w,onClick:()=>A(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),te>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>f(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",te,")"]}),e.jsx("span",{className:"mdocs-settings-draft-arrow","aria-hidden":"true",children:"›"})]}):e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:s("noDrafts")})})]})]}),N&&e.jsx(Ot,{onPublish:z,onClose:()=>f(!1),onCountChange:ne,onRecover:a.onRecoverDraft})]}),d&&e.jsx(ms,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:F,onConfirm:()=>{j(!1),He()},onCancel:()=>j(!1)}),e.jsx(hs,{open:ws,title:s("docInfoInviteMember"),initialSelectedIds:[...Fe.keys()],initialPermissions:Fe,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>Ee(!1),onConfirm:n=>{Ps(n)}})]})}export{na as SettingsPage};
@@ -1,16 +0,0 @@
1
- import{r as c,j as s}from"./react-vendor-BVS1XoFi.js";import{o as X,c as ke,p as H,q as ye,a as ve,s as Ce,e as Ie,g as je,u as we,t as $,v as K,w as Ne,x as Se,y as ne,z as Ee,A as De,B as Me,E as Be,F as Re,G as ze,H as Te,I as Ae,J as We,K as Pe,X as $e,L as Ke,M as Le,r as Ve,i as Fe,O as _e,P as qe,Q as Oe,R as Ue}from"./index-DNb6Q69l.js";import{D as Qe}from"./DocChrome-B-5PeA3Z.js";import{P as J}from"./plus-BAqdJ6N2.js";import{B as Ge,I as He}from"./italic-BljxX8Uj.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./file-type-policy-C6Nun42Q.js";/**
2
- * @license lucide-react v0.562.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const Je=[["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}],["path",{d:"M12 2v10.3a4 4 0 0 1-1.172 2.872L4 22",key:"1hyw0i"}],["path",{d:"m20 22-5-5",key:"1m27yz"}]],Xe=X("merge",Je);/**
7
- * @license lucide-react v0.562.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const Ye=[["path",{d:"M8 19H5c-1 0-2-1-2-2V7c0-1 1-2 2-2h3",key:"lubmu8"}],["path",{d:"M16 5h3c1 0 2 1 2 2v10c0 1-1 2-2 2h-3",key:"1ag34g"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]],Ze=X("square-split-horizontal",Ye);/**
12
- * @license lucide-react v0.562.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const pe=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],se=X("trash-2",pe);function L(t){return`${t.rowId}::${t.colId}`}function et(t,l,d){const r=t.rows.findIndex(u=>u.id===l.rowId),y=t.rows.findIndex(u=>u.id===d.rowId),b=t.columns.findIndex(u=>u.id===l.colId),C=t.columns.findIndex(u=>u.id===d.colId);if(r<0||y<0||b<0||C<0)return[l];const V=Math.min(r,y),R=Math.max(r,y),F=Math.min(b,C),j=Math.max(b,C),D=[];for(let u=V;u<=R;u+=1)for(let w=F;w<=j;w+=1)D.push({rowId:t.rows[u].id,colId:t.columns[w].id});return D}function tt(t){return t?{background:t.bg,color:t.color,fontWeight:t.bold?700:void 0,fontStyle:t.italic?"italic":void 0,fontSize:t.fontSize?`${t.fontSize}px`:void 0}:{}}function ut(t){const{t:l}=ke(),d=t.meta.documentId,[r,y]=c.useState(()=>H(t.initialContent)),[b,C]=c.useState(t.initialDisplayName),[V,R]=c.useState(!1),[F,j]=c.useState(t.hasLocalDraft??!1),[D,u]=c.useState(!1),[w,Y]=c.useState(!1),[oe,_]=c.useState(null),[Z,z]=c.useState(null),[N,M]=c.useState(null),[f,x]=c.useState(null),v=c.useRef(null),T=c.useRef(!1),I=c.useRef(null),q=c.useRef(r),O=c.useRef(b);q.current=r,O.current=b,I.current=N,c.useEffect(()=>{const e=()=>{T.current=!1};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]);const i=ye(r)??r.sheets[0],m=N&&f?et(i,N,f):[],U=new Set(m.map(L));c.useEffect(()=>{y(H(t.initialContent)),C(t.initialDisplayName),M(null),x(null),z(null)},[d,t.contentRevision,t.initialContent,t.initialDisplayName]),c.useEffect(()=>{let e=!1;return(async()=>{var n;const o=await ve(d);e||!o||o.contentKind!=="sheet"||(y(H(o.content)),o.displayName&&C(o.displayName),j(!0),(n=t.onDraftExistsChange)==null||n.call(t,!0))})(),()=>{e=!0}},[d]),c.useEffect(()=>Ce((e,o)=>{var n;e===d&&(j(o),(n=t.onDraftExistsChange)==null||n.call(t,o))}),[d]),c.useEffect(()=>{let e=!1;return Ie(d).then(o=>{e||u(!!(o!=null&&o.bookmarked))}),()=>{e=!0}},[d]);const Q=c.useCallback(async()=>{var e;await je(d).execute(()=>we({documentId:d,content:$(q.current),displayName:O.current,contentKind:"sheet",localBaseCommitIdAtEditStart:t.meta.headCommitId??null,snapshotMeta:{permission:t.meta.permission,ownerVisitorId:t.meta.ownerVisitorId,domainId:t.meta.domainId}})),j(!0),(e=t.onDraftExistsChange)==null||e.call(t,!0)},[d,t]),p=c.useCallback(()=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{Q()},1e3)},[Q]);c.useEffect(()=>()=>{v.current&&clearTimeout(v.current)},[]);function A(e){var o;t.canEdit&&(y(e),(o=t.onContentChange)==null||o.call(t,$(e)),p())}function k(e){A(_e(r,e))}function ae(e,o,n){if(o&&I.current){n.preventDefault(),x(e);return}T.current=!0,M(e),x(e),I.current=e}function ie(e){T.current&&x(e)}function G(e,o){M(e),x(o),I.current=e}function ce(e,o,n){n.preventDefault();const a=i.rows;if(a.length===0)return;const S=a[0].id,g=a[a.length-1].id;if(o&&I.current){x({rowId:g,colId:e});return}G({rowId:S,colId:e},{rowId:g,colId:e})}function le(e,o,n){n.preventDefault();const a=i.columns;if(a.length===0)return;const S=a[0].id,g=a[a.length-1].id;if(o&&I.current){x({rowId:e,colId:g});return}G({rowId:e,colId:S},{rowId:e,colId:g})}function de(e){e.preventDefault();const o=i.rows,n=i.columns;o.length===0||n.length===0||G({rowId:o[0].id,colId:n[0].id},{rowId:o[o.length-1].id,colId:n[n.length-1].id})}function B(e){if(!t.canEdit||m.length===0)return;let o=i;for(const n of m)o=qe(o,n.rowId,n.colId,e);k(o)}function re(){var n;const e=m[0];if(!e)return;const o=K((n=i.rows.find(a=>a.id===e.rowId))==null?void 0:n.cells[e.colId]);B({bold:!(o!=null&&o.bold)})}function ue(){var n;const e=m[0];if(!e)return;const o=K((n=i.rows.find(a=>a.id===e.rowId))==null?void 0:n.cells[e.colId]);B({italic:!(o!=null&&o.italic)})}function he(){if(!(!t.canEdit||!N||!f))try{k(Oe(i,{startRowId:N.rowId,startColId:N.colId,endRowId:f.rowId,endColId:f.colId}))}catch{}}function me(){if(!t.canEdit||!f)return;const{tab:e}=Ue(i,f.rowId,f.colId);k(e)}async function ee(){var a;if(!t.canEdit)return;const e=document.querySelector(".mdocs-sheet-scroll"),o=(e==null?void 0:e.scrollTop)??null,n=(e==null?void 0:e.scrollLeft)??null;R(!0);try{v.current&&(clearTimeout(v.current),v.current=null),await Q(),await t.onPublish($(q.current),O.current.trim()||b,d),j(!1),(a=t.onDraftExistsChange)==null||a.call(t,!1)}finally{R(!1),e&&o!=null&&(e.scrollTop=o,n!=null&&(e.scrollLeft=n),requestAnimationFrame(()=>{e.scrollTop=o,n!=null&&(e.scrollLeft=n)}))}}async function fe(){if(t.canEdit&&b.trim()!==t.initialDisplayName.trim())try{await ee()}catch{}}async function ge(){var e,o;if(!w){Y(!0);try{D?(await Ve(d),u(!1),(e=t.onShowToast)==null||e.call(t,l("bookmarkRemoved"))):(await Fe(d),u(!0),(o=t.onShowToast)==null||o.call(t,l("bookmarkAdded")))}finally{Y(!1)}}}const h=(()=>{var o;const e=m[0];if(e)return K((o=i.rows.find(n=>n.id===e.rowId))==null?void 0:o.cells[e.colId])})();return s.jsxs("div",{className:"mdocs-sheet-editor",children:[s.jsx(Qe,{fileType:"sheet",displayName:b,onDisplayNameChange:C,onDisplayNameBlur:()=>void fe(),domains:t.domains,currentDomainId:t.currentDomainId,onDomainChange:t.onDomainChange,onDomainsChange:t.onDomainsChange,canEdit:t.canEdit,editing:!0,actionsAlwaysVisible:!0,syncBehind:t.syncBehind,onSyncClick:t.onSyncClick,busy:V,draftExists:F,onPublish:()=>void ee(),onDelete:()=>void t.onDelete(),isBookmarked:D,bookmarkBusy:w,onToggleBookmark:()=>void ge(),onToggleComments:t.onToggleComments,commentPanelOpen:t.commentPanelOpen,commentCount:t.commentCount,readerChrome:t.readerChrome,onOpenMobileNav:t.onOpenMobileNav}),s.jsxs("div",{className:"mdocs-sheet-toolbar",children:[s.jsxs("div",{className:"mdocs-sheet-toolbar-left",children:[s.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit,onClick:()=>k(Ne(i)),children:[s.jsx(J,{size:13,strokeWidth:2.2}),s.jsx("span",{children:l("sheetAddRow")})]}),s.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit,onClick:()=>k(Se(i)),children:[s.jsx(J,{size:13,strokeWidth:2.2}),s.jsx("span",{children:l("sheetAddColumn")})]}),s.jsx("span",{className:"mdocs-sheet-toolbar-sep","aria-hidden":!0}),s.jsx("button",{type:"button",className:`mdocs-sheet-btn mdocs-sheet-btn-icon${h!=null&&h.bold?" is-active":""}`,disabled:!t.canEdit||m.length===0,title:l("sheetBold"),onClick:re,children:s.jsx(Ge,{size:13,strokeWidth:2.4})}),s.jsx("button",{type:"button",className:`mdocs-sheet-btn mdocs-sheet-btn-icon${h!=null&&h.italic?" is-active":""}`,disabled:!t.canEdit||m.length===0,title:l("sheetItalic"),onClick:ue,children:s.jsx(He,{size:13,strokeWidth:2.4})}),s.jsx("label",{className:"mdocs-sheet-style-label",title:l("sheetFontSize"),children:s.jsxs("select",{className:"mdocs-sheet-font-size",disabled:!t.canEdit||m.length===0,value:(h==null?void 0:h.fontSize)??"",onChange:e=>{const o=e.target.value;B(o?{fontSize:Number(o)}:{fontSize:void 0})},children:[s.jsx("option",{value:"",children:"Aa"}),[12,13,14,16,18,20,24].map(e=>s.jsx("option",{value:e,children:e},e))]})}),s.jsx("label",{className:"mdocs-sheet-style-label",title:l("sheetTextColor"),children:s.jsx("input",{type:"color",className:"mdocs-sheet-color",disabled:!t.canEdit||m.length===0,value:(h==null?void 0:h.color)??"#212121",onChange:e=>B({color:e.target.value})})}),s.jsx("label",{className:"mdocs-sheet-style-label",title:l("sheetBgColor"),children:s.jsx("input",{type:"color",className:"mdocs-sheet-color",disabled:!t.canEdit||m.length===0,value:(h==null?void 0:h.bg)??"#ffffff",onChange:e=>B({bg:e.target.value})})}),s.jsx("span",{className:"mdocs-sheet-toolbar-sep","aria-hidden":!0}),s.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit||m.length<2,title:`${l("sheetMerge")}(按住拖选,或 Shift+点第二格)`,onClick:he,children:[s.jsx(Xe,{size:13,strokeWidth:2.2}),s.jsx("span",{children:l("sheetMerge")})]}),s.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit||!f||!ne(i,f.rowId,f.colId),title:l("sheetUnmerge"),onClick:me,children:[s.jsx(Ze,{size:13,strokeWidth:2.2}),s.jsx("span",{children:l("sheetUnmerge")})]})]}),s.jsx("div",{className:"mdocs-sheet-toolbar-right",children:s.jsxs("span",{className:"mdocs-sheet-stats-badge",children:[i.name," · ",i.rows.length," 行 × ",i.columns.length," 列"]})})]}),s.jsx("div",{className:"mdocs-sheet-scroll",children:s.jsxs("table",{className:"mdocs-sheet-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{className:"mdocs-sheet-corner-cell",title:"全选",onMouseDown:de,children:"#"}),i.columns.map(e=>{const o=m.length>0&&i.rows.every(n=>U.has(L({rowId:n.id,colId:e.id})));return s.jsx("th",{className:`mdocs-sheet-th${o?" is-selected":""}`,onMouseDown:n=>{Z!==e.id&&(n.target.closest(".mdocs-sheet-col-del")||ce(e.id,n.shiftKey,n))},children:s.jsxs("div",{className:"mdocs-sheet-header-cell",children:[Z===e.id&&t.canEdit?s.jsx("input",{className:"mdocs-sheet-header-input",autoFocus:!0,defaultValue:e.name,title:"编辑列名",onClick:n=>n.stopPropagation(),onMouseDown:n=>n.stopPropagation(),onBlur:n=>{z(null);const a=n.target.value.trim();!a||a===e.name||k(Ee(i,e.id,a))},onKeyDown:n=>{n.key==="Enter"&&n.target.blur(),n.key==="Escape"&&z(null)}}):s.jsx("button",{type:"button",className:"mdocs-sheet-header-label",title:"单击全选列;双击重命名",onDoubleClick:n=>{n.preventDefault(),n.stopPropagation(),t.canEdit&&z(e.id)},children:e.name}),t.canEdit&&i.columns.length>1&&s.jsx("button",{type:"button",className:"mdocs-sheet-col-del",title:l("sheetDeleteColumn"),onMouseDown:n=>n.stopPropagation(),onClick:()=>{try{const{tab:n}=De(i,[e.id]);k(n)}catch{}},children:s.jsx(se,{size:12,strokeWidth:1.8})})]})},e.id)}),s.jsx("th",{className:"mdocs-sheet-actions-header"})]})}),s.jsx("tbody",{children:i.rows.map((e,o)=>{const n=m.length>0&&i.columns.every(a=>U.has(L({rowId:e.id,colId:a.id})));return s.jsxs("tr",{className:`mdocs-sheet-tr${n?" is-row-selected":""}`,children:[s.jsx("td",{className:`mdocs-sheet-rownum${n?" is-selected":""}`,title:"单击全选行",onMouseDown:a=>le(e.id,a.shiftKey,a),children:o+1}),i.columns.map(a=>{if(Me(i,e.id,a.id))return null;const S=e.cells[a.id],g=K(S),te=ne(i,e.id,a.id),be=Be(i,e.id,a.id),W=te&&be?Re(i,te):{rowSpan:1,colSpan:1},E={rowId:e.id,colId:a.id},xe=U.has(L(E));return s.jsx("td",{className:`mdocs-sheet-td${xe?" is-selected":""}`,rowSpan:W.rowSpan>1?W.rowSpan:void 0,colSpan:W.colSpan>1?W.colSpan:void 0,style:g!=null&&g.bg?{background:g.bg}:void 0,onMouseEnter:()=>ie(E),children:s.jsx("input",{className:"mdocs-sheet-cell-input",style:tt(g),value:Te(S),disabled:!t.canEdit,onMouseDown:P=>ae(E,P.shiftKey,P),onFocus:()=>{T.current||(M(E),x(E),I.current=E)},onChange:P=>k(ze(i,e.id,a.id,P.target.value))})},a.id)}),s.jsx("td",{className:"mdocs-sheet-actions-col",children:s.jsx("button",{type:"button",className:"mdocs-sheet-row-del",disabled:!t.canEdit,title:l("sheetDeleteRow"),onClick:()=>k(Ae(i,e.id)),children:s.jsx(se,{size:13,strokeWidth:1.8})})})]},e.id)})})]})}),s.jsxs("footer",{className:"mdocs-sheet-footer",children:[s.jsxs("div",{className:"mdocs-sheet-tabs",role:"tablist",children:[r.sheets.map(e=>{const o=e.id===i.id;return s.jsxs("div",{className:`mdocs-sheet-tab${o?" mdocs-sheet-tab--active":""}`,role:"tab","aria-selected":o,children:[oe===e.id&&t.canEdit?s.jsx("input",{className:"mdocs-sheet-tab-rename",autoFocus:!0,defaultValue:e.name,onBlur:n=>{_(null);const a=n.target.value.trim();if(!(!a||a===e.name))try{A(We(r,e.id,a))}catch{}},onKeyDown:n=>{n.key==="Enter"&&n.target.blur(),n.key==="Escape"&&_(null)}}):s.jsx("button",{type:"button",className:"mdocs-sheet-tab-btn",title:"双击可重命名工作表",onClick:()=>{var a;if(o)return;const n=Pe(r,e.id);y(n),M(null),x(null),t.canEdit&&((a=t.onContentChange)==null||a.call(t,$(n)),p())},onDoubleClick:()=>{t.canEdit&&_(e.id)},children:e.name}),t.canEdit&&r.sheets.length>1?s.jsx("button",{type:"button",className:"mdocs-sheet-tab-close",title:l("sheetDeleteSheet"),onClick:n=>{n.stopPropagation();try{A(Ke(r,e.id))}catch{}},children:s.jsx($e,{size:11,strokeWidth:2.4})}):null]},e.id)}),s.jsx("button",{type:"button",className:"mdocs-sheet-tab-add",disabled:!t.canEdit,title:l("sheetAddSheet"),onClick:()=>{const{doc:e}=Le(r);A(e)},children:s.jsx(J,{size:13,strokeWidth:2.2})})]}),s.jsx("div",{className:"mdocs-sheet-footer-info",children:s.jsxs("span",{children:["共 ",r.sheets.length," 个工作表"]})})]})]})}export{ut as SheetEditor};
@@ -1 +0,0 @@
1
- .mdocs-sheet-editor{display:flex;flex-direction:column;height:100%;min-height:0;background-color:var(--mdocs-bg, #f5f5f5);color:var(--mdocs-text, #212121);overflow:hidden;position:relative}.mdocs-sheet-toolbar{display:flex;align-items:center;justify-content:space-between;padding:0 16px;height:38px;min-height:38px;background:var(--mdocs-surface, #ffffff);border-bottom:1px solid var(--mdocs-border, #e0e0e0);gap:12px}.mdocs-sheet-toolbar-left{display:flex;align-items:center;gap:6px;flex-wrap:wrap}.mdocs-sheet-toolbar-sep{width:1px;height:18px;background:var(--mdocs-border, #e0e0e0);margin:0 4px}.mdocs-sheet-btn-icon{width:26px;padding:0;justify-content:center}.mdocs-sheet-btn.is-active{background:var(--mdocs-accent-soft, #e8f5e9);border-color:var(--mdocs-accent, #4caf50);color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-style-label{display:inline-flex;align-items:center;margin:0}.mdocs-sheet-font-size{height:26px;border:1px solid var(--mdocs-border, #e0e0e0);border-radius:var(--mdocs-radius-sm, 4px);background:var(--mdocs-surface, #fff);font-size:12px;color:var(--mdocs-text, #212121);padding:0 4px}.mdocs-sheet-color{width:26px;height:26px;padding:0;border:1px solid var(--mdocs-border, #e0e0e0);border-radius:4px;background:transparent;cursor:pointer}.mdocs-sheet-td.is-selected{outline:2px solid var(--mdocs-accent, #4caf50);outline-offset:-2px;z-index:1}.mdocs-sheet-toolbar-right{display:flex;align-items:center}.mdocs-sheet-btn{display:inline-flex;align-items:center;gap:5px;height:26px;padding:0 10px;font-size:12px;font-weight:500;color:var(--mdocs-text, #212121);background:var(--mdocs-surface, #ffffff);border:1px solid var(--mdocs-border, #e0e0e0);border-radius:var(--mdocs-radius-sm, 4px);cursor:pointer;transition:all .15s ease;-webkit-user-select:none;user-select:none}.mdocs-sheet-btn:hover:not(:disabled){background:var(--mdocs-accent-soft, #e8f5e9);border-color:var(--mdocs-accent-secondary, #81c784);color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-btn:disabled{opacity:.45;cursor:not-allowed}.mdocs-sheet-stats-badge{font-size:11.5px;color:var(--mdocs-accent-dark, #388e3c);background:var(--mdocs-accent-soft, #e8f5e9);padding:3px 10px;border-radius:12px;font-variant-numeric:tabular-nums;border:1px solid var(--mdocs-accent-secondary, #81c784)}.mdocs-sheet-scroll{flex:1;min-height:0;overflow:auto;position:relative;background:var(--mdocs-surface, #ffffff)}.mdocs-sheet-table{border-collapse:separate;border-spacing:0;min-width:100%;table-layout:fixed;font-size:13px}.mdocs-sheet-corner-cell{position:sticky;top:0;left:0;z-index:10;width:44px;min-width:44px;max-width:44px;height:30px;background:#f8fafc;color:var(--mdocs-text-muted, #616161);font-size:11.5px;font-weight:600;text-align:center;border-right:1px solid var(--mdocs-border, #e0e0e0);border-bottom:1.5px solid var(--mdocs-border, #e0e0e0);-webkit-user-select:none;user-select:none;cursor:pointer}.mdocs-sheet-corner-cell:hover{background:var(--mdocs-accent-soft, #e8f5e9);color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-th{position:sticky;top:0;z-index:5;height:30px;min-width:140px;background:#f8fafc;border-right:1px solid var(--mdocs-border, #e0e0e0);border-bottom:1.5px solid var(--mdocs-border, #e0e0e0);padding:0;-webkit-user-select:none;user-select:none;cursor:pointer}.mdocs-sheet-header-cell{display:flex;align-items:center;justify-content:space-between;height:100%;padding:0 6px 0 10px;gap:4px}.mdocs-sheet-th.is-selected,.mdocs-sheet-rownum.is-selected{background:var(--mdocs-accent-soft, #e8f5e9)!important;color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-header-label{flex:1;min-width:0;border:none;outline:none;background:transparent;font-size:12px;font-weight:600;color:inherit;padding:2px 4px;border-radius:3px;text-align:left;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mdocs-sheet-header-label:hover{background:var(--mdocs-accent-soft, #e8f5e9)}.mdocs-sheet-header-input{flex:1;min-width:0;border:none;outline:none;background:transparent;font-size:12px;font-weight:600;color:var(--mdocs-text, #212121);padding:2px 4px;border-radius:3px;transition:background-color .15s ease}.mdocs-sheet-header-input:hover:not(:disabled){background:var(--mdocs-accent-soft, #e8f5e9)}.mdocs-sheet-header-input:focus{background:var(--mdocs-surface, #ffffff);box-shadow:0 0 0 1.5px var(--mdocs-accent, #4caf50);color:var(--mdocs-text, #212121)}.mdocs-sheet-col-del{opacity:0;border:none;background:transparent;color:var(--mdocs-text-muted, #616161);cursor:pointer;padding:3px;border-radius:3px;display:flex;align-items:center;justify-content:center;transition:opacity .15s ease,background .15s ease,color .15s ease}.mdocs-sheet-th:hover .mdocs-sheet-col-del{opacity:1}.mdocs-sheet-col-del:hover{color:var(--mdocs-danger, #e53935);background:var(--mdocs-error-soft, #ffebee)}.mdocs-sheet-actions-header{position:sticky;top:0;z-index:5;width:36px;min-width:36px;max-width:36px;background:#f8fafc;border-bottom:1.5px solid var(--mdocs-border, #e0e0e0)}.mdocs-sheet-rownum{position:sticky;left:0;z-index:4;width:44px;min-width:44px;max-width:44px;height:28px;background:#f8fafc;color:var(--mdocs-text-muted, #616161);font-size:11px;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;text-align:center;border-right:1px solid var(--mdocs-border, #e0e0e0);border-bottom:1px solid var(--mdocs-border, #e0e0e0);-webkit-user-select:none;user-select:none;line-height:28px;cursor:pointer}.mdocs-sheet-tr:hover td{background-color:#f8fafc}.mdocs-sheet-tr:hover .mdocs-sheet-rownum{background-color:var(--mdocs-accent-soft, #e8f5e9);color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-td{height:28px;min-width:140px;padding:0;border-right:1px solid var(--mdocs-border, #e0e0e0);border-bottom:1px solid var(--mdocs-border, #e0e0e0);background:var(--mdocs-surface, #ffffff);position:relative;user-select:none;-webkit-user-select:none}.mdocs-sheet-td.is-selected .mdocs-sheet-cell-input{background:color-mix(in srgb,var(--mdocs-accent-soft, #e8f5e9) 70%,transparent)}.mdocs-sheet-cell-input:focus{user-select:text;-webkit-user-select:text}.mdocs-sheet-cell-input{width:100%;height:100%;min-height:28px;border:none;outline:none;background:transparent;padding:0 8px;font-size:12.5px;color:var(--mdocs-text, #212121);font-family:inherit;transition:box-shadow .1s ease}.mdocs-sheet-cell-input:focus{background:var(--mdocs-surface, #ffffff)!important;box-shadow:inset 0 0 0 2px var(--mdocs-accent, #4caf50);z-index:2;position:relative}.mdocs-sheet-actions-col{width:36px;min-width:36px;max-width:36px;border-bottom:1px solid var(--mdocs-border, #e0e0e0);text-align:center;vertical-align:middle;padding:0;background:var(--mdocs-surface, #ffffff)}.mdocs-sheet-row-del{opacity:0;border:none;background:transparent;color:var(--mdocs-text-muted, #616161);cursor:pointer;padding:4px;border-radius:4px;display:inline-flex;align-items:center;justify-content:center;transition:opacity .15s ease,background .15s ease,color .15s ease}.mdocs-sheet-tr:hover .mdocs-sheet-row-del{opacity:1}.mdocs-sheet-row-del:hover:not(:disabled){color:var(--mdocs-danger, #e53935);background:var(--mdocs-error-soft, #ffebee)}.mdocs-sheet-footer{height:36px;min-height:36px;display:flex;align-items:center;justify-content:space-between;border-top:1px solid var(--mdocs-border, #e0e0e0);background:var(--mdocs-bg, #f5f5f5);padding:0 12px;gap:16px;-webkit-user-select:none;user-select:none;z-index:10}.mdocs-sheet-tabs{display:flex;align-items:flex-end;height:100%;gap:2px;overflow-x:auto;overflow-y:hidden;scrollbar-width:none}.mdocs-sheet-tabs::-webkit-scrollbar{display:none}.mdocs-sheet-tab{display:flex;align-items:center;height:30px;padding:0 12px;border-radius:6px 6px 0 0;background:transparent;border:1px solid transparent;border-bottom:none;font-size:12px;color:var(--mdocs-text-muted, #616161);position:relative;transition:all .15s ease;white-space:nowrap}.mdocs-sheet-tab:hover:not(.mdocs-sheet-tab--active){background:var(--mdocs-border, #e0e0e0);color:var(--mdocs-text, #212121)}.mdocs-sheet-tab--active{background:var(--mdocs-surface, #ffffff);color:var(--mdocs-text, #212121);font-weight:600;border-color:var(--mdocs-border, #e0e0e0);border-bottom-color:var(--mdocs-surface, #ffffff);box-shadow:0 -1px 3px #0000000a}.mdocs-sheet-tab--active:after{content:"";position:absolute;bottom:-1px;left:0;right:0;height:2.5px;background:var(--mdocs-accent, #4caf50);border-radius:2px 2px 0 0}.mdocs-sheet-tab-btn{border:none;background:transparent;padding:0;font:inherit;color:inherit;cursor:pointer;white-space:nowrap;max-width:140px;overflow:hidden;text-overflow:ellipsis}.mdocs-sheet-tab-rename{border:1px solid var(--mdocs-accent, #4caf50);border-radius:3px;outline:none;font-size:12px;font-weight:500;padding:1px 4px;width:90px;background:var(--mdocs-surface, #ffffff);color:var(--mdocs-text, #212121)}.mdocs-sheet-tab-close{margin-left:6px;border:none;background:transparent;padding:2px;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;color:var(--mdocs-text-muted, #616161);opacity:.6;transition:all .15s ease}.mdocs-sheet-tab-close:hover{opacity:1;background:var(--mdocs-error-soft, #ffebee);color:var(--mdocs-danger, #e53935)}.mdocs-sheet-tab-add{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;border:none;background:transparent;border-radius:4px;cursor:pointer;color:var(--mdocs-text-muted, #616161);margin-left:4px;margin-bottom:3px;transition:all .15s ease}.mdocs-sheet-tab-add:hover:not(:disabled){background:var(--mdocs-accent-soft, #e8f5e9);color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-tab-add:disabled{opacity:.4;cursor:not-allowed}.mdocs-sheet-footer-info{font-size:11px;color:var(--mdocs-text-muted, #616161);white-space:nowrap}
@@ -1 +0,0 @@
1
- import{r,j as e}from"./react-vendor-BVS1XoFi.js";import{c as G,a8 as ee,f as se,a3 as z}from"./index-DNb6Q69l.js";function ie({options:v,value:a,onChange:b}){const[d,f]=r.useState(!1),y=r.useRef(null),x=r.useRef(null),p=v.find(o=>o.value===a);r.useEffect(()=>{if(!d)return;const o=u=>{var N,k;!((N=y.current)!=null&&N.contains(u.target))&&!((k=x.current)!=null&&k.contains(u.target))&&f(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[d]),r.useEffect(()=>{if(!d)return;const o=u=>{var N;u.key==="Escape"&&(f(!1),(N=y.current)==null||N.focus())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[d]);function j(o){b(o),f(!1)}return e.jsxs("div",{className:"mdocs-mini-select",style:{position:"relative"},children:[e.jsxs("button",{ref:y,type:"button",className:"mdocs-mini-select-trigger","aria-expanded":d,"aria-haspopup":"listbox",onClick:()=>f(o=>!o),children:[e.jsx("span",{children:p==null?void 0:p.label}),e.jsx("svg",{className:"mdocs-mini-select-chevron"+(d?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),d&&e.jsx("div",{ref:x,className:"mdocs-mini-select-menu card",role:"listbox",children:v.map(o=>e.jsx("button",{type:"button",className:"mdocs-mini-select-option"+(o.value===a?" active":""),role:"option","aria-selected":o.value===a,onClick:()=>j(o.value),children:o.label},o.value))})]})}function te(v){return v.length<=6?v:`${v.slice(0,6)}…`}function re(v){const{visitors:a,loadState:b,searchFilter:d,onSearchChange:f,selectedIds:y,onToggle:x,selectedRows:p,lockedIds:j=new Set,myVisitorId:o,showPermissionSelect:u=!1,permissionOptions:N=[],onPermissionChange:k}=v,{t:i}=G(),P=r.useMemo(()=>{const t=d.trim().toLowerCase();let g=t?a.filter(m=>m.visitorName.toLowerCase().includes(t)||m.visitorId.toLowerCase().includes(t)):a;return o&&(g=[...g].sort((m,R)=>m.visitorId===o?-1:R.visitorId===o?1:0)),g},[a,d,o]);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"search",className:"mdocs-visitor-picker-search",placeholder:i("visitorPickerSearchPlaceholder"),value:d,onChange:t=>f(t.target.value),disabled:b!=="ok"}),b==="loading"&&e.jsx("div",{className:"mdocs-visitor-picker-loading",children:i("loading")}),b==="err"&&e.jsx("div",{className:"mdocs-visitor-picker-error",children:i("visitorPickerLoadError")}),b==="ok"&&e.jsxs("div",{className:"mdocs-visitor-picker-columns",children:[e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnAll")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdShort")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col",children:i("visitorPickerColPick")})]})}),e.jsx("tbody",{children:P.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"mdocs-visitor-picker-empty-cell",children:a.length===0?i("visitorPickerEmptyDirectory"):i("domainNoMatch")})}):P.map(t=>{const g=j.has(t.visitorId),m=y.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-short",children:te(t.visitorId)})}),e.jsxs("td",{children:[t.visitorName,t.visitorId===o&&e.jsx("span",{className:"mdocs-visitor-picker-self-marker",children:i("visitorPickerSelfMarker")})]}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:e.jsx("input",{type:"checkbox",checked:m,disabled:g,onChange:()=>x(t.visitorId),"aria-label":t.visitorName})})]},t.visitorId)})})]})})]}),e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnSelected")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdFull")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),u&&e.jsx("th",{scope:"col",children:i("permissionLabel")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col"})]})}),e.jsx("tbody",{children:p.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:u?4:3,className:"mdocs-visitor-picker-empty-cell",children:i("visitorPickerNoSelection")})}):p.map(t=>{const g=j.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-full",children:t.visitorId})}),e.jsx("td",{className:t.muted?"mdocs-visitor-picker-name-muted":void 0,children:t.name}),u&&e.jsx("td",{children:e.jsx(ie,{options:N,value:t.permission??"read",onChange:m=>k==null?void 0:k(t.visitorId,m)})}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:g?e.jsx("span",{className:"mdocs-visitor-picker-locked",title:i("visitorPickerLockedHint"),children:"—"}):e.jsx("button",{type:"button",className:"mdocs-visitor-picker-remove",onClick:()=>x(t.visitorId),"aria-label":i("visitorPickerRemove"),children:"×"})})]},t.visitorId)})})]})})]})]})]})}function ne(v){var U;const{open:a,title:b,initialSelectedIds:d,lockedIds:f=[],seedMembers:y,excludeTemplateId:x,templates:p,onClose:j,onConfirm:o,showPermissionSelect:u=!1,permissionOptions:N=[],initialPermissions:k}=v,{t:i}=G(),P=r.useRef(i);P.current=i;const t=r.useMemo(()=>new Set(f),[f]),g=ee(),[m,R]=r.useState([]),[E,T]=r.useState("idle"),[w,V]=r.useState(()=>new Set),[O,L]=r.useState(()=>new Map),[J,A]=r.useState(""),[C,B]=r.useState(""),[M,D]=r.useState(!1),$=r.useRef(null),[K,W]=r.useState(!1),[q,I]=r.useState(null),F=r.useMemo(()=>p.filter(s=>x==null||s.id!==x),[p,x]),H=r.useMemo(()=>new Map((y??[]).map(s=>[s.visitorId,s])),[y]);r.useEffect(()=>{a&&(V(new Set(d)),L(k?new Map(k):new Map),A(""),B(""),I(null))},[a,d,k]),r.useEffect(()=>{if(!a)return;let s=!1;return T("loading"),se().then(n=>{s||(R(n),T("ok"))}).catch(n=>{s||(T("err"),I(z(P.current,n)))}),()=>{s=!0}},[a]),r.useEffect(()=>{if(!M)return;const s=n=>{var c;(c=$.current)!=null&&c.contains(n.target)||D(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[M]);const Q=r.useMemo(()=>{const s=new Map(m.map(c=>[c.visitorId,c])),n=[];for(const c of w){const l=O.get(c),h=s.get(c);if(h){n.push({visitorId:c,name:h.visitorName,muted:!1,permission:l});continue}const S=H.get(c);if(S){S.missing?n.push({visitorId:c,name:i("visitorPickerMemberMissing"),muted:!0,permission:l}):S.disabled?n.push({visitorId:c,name:`${S.visitorName} · ${i("visitorPickerDisabledTag")}`,muted:!0,permission:l}):n.push({visitorId:c,name:S.visitorName,muted:!1,permission:l});continue}n.push({visitorId:c,name:i("visitorPickerUnknownVisitor"),muted:!0,permission:l})}return n.sort((c,l)=>c.name.localeCompare(l.name,void 0,{sensitivity:"base"})),n},[m,w,H,O,i]),X=r.useCallback(s=>{t.has(s)||V(n=>{const c=new Set(n);return c.has(s)?(c.delete(s),L(l=>{const h=new Map(l);return h.delete(s),h})):(c.add(s),L(l=>{const h=new Map(l);return h.set(s,"read"),h})),c})},[t]),Y=r.useCallback((s,n)=>{L(c=>{const l=new Map(c);return l.set(s,n),l})},[]),Z=r.useCallback(()=>{const s=Number(C);if(!Number.isInteger(s)||s<1)return;const n=p.find(l=>l.id===s);if(!n)return;const c=new Set(m.map(l=>l.visitorId));V(l=>{const h=new Set(l);for(const S of n.visitorIds)c.has(S)&&h.add(S);return h})},[C,p,m]);async function _(){I(null),W(!0);try{if(u){const s=[...w].sort().map(n=>({visitorId:n,permission:O.get(n)??"read"}));await o(s)}else{const s=[...w].sort();await o(s)}j()}catch(s){I(z(i,s))}finally{W(!1)}}return a?e.jsx("div",{className:"mdocs-visitor-picker-overlay",role:"presentation",onMouseDown:s=>s.target===s.currentTarget&&j(),children:e.jsxs("div",{className:"mdocs-visitor-picker-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-visitor-picker-title",children:[e.jsxs("header",{className:"mdocs-visitor-picker-header",children:[e.jsx("h2",{id:"mdocs-visitor-picker-title",className:"mdocs-visitor-picker-title",children:b}),e.jsx("button",{type:"button",className:"mdocs-visitor-picker-close",onClick:j,"aria-label":i("close"),children:"×"})]}),F.length>0&&e.jsx("div",{className:"mdocs-visitor-picker-toolbar",children:e.jsxs("div",{className:"mdocs-visitor-picker-template-bar",children:[e.jsxs("div",{ref:$,className:"mdocs-template-picker",children:[e.jsxs("button",{type:"button",className:"mdocs-template-picker-trigger",onClick:()=>D(s=>!s),disabled:E!=="ok","aria-haspopup":"listbox","aria-expanded":M,children:[e.jsx("span",{className:"mdocs-template-picker-text",children:C?(U=F.find(s=>String(s.id)===C))==null?void 0:U.displayName:i("visitorPickerPickTemplate")}),e.jsx("svg",{className:"mdocs-template-picker-chevron"+(M?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),M&&e.jsx("div",{className:"mdocs-template-picker-menu card",role:"listbox",children:F.map(s=>e.jsx("button",{type:"button",className:"mdocs-template-picker-option"+(String(s.id)===C?" active":""),role:"option","aria-selected":String(s.id)===C,onClick:()=>{B(String(s.id)),D(!1)},children:s.displayName},s.id))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}if(!C){I(i("visitorPickerPickTemplate"));return}Z()},children:i("visitorPickerApplyTemplate")})]})}),q&&e.jsx("div",{className:"mdocs-visitor-picker-error",role:"alert",children:q}),e.jsx("div",{style:{padding:"8px 18px 12px"},children:e.jsx(re,{visitors:m,loadState:E,searchFilter:J,onSearchChange:A,selectedIds:w,onToggle:X,selectedRows:Q,lockedIds:t,myVisitorId:g,showPermissionSelect:u,permissionOptions:N,onPermissionChange:Y})}),e.jsxs("footer",{className:"mdocs-visitor-picker-footer",children:[e.jsx("button",{type:"button",className:"secondary",onClick:j,children:i("cancel")}),e.jsx("button",{type:"button",className:"primary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}_()},children:i(K?"saving":"visitorPickerConfirm")})]})]})}):null}export{ie as M,ne as V,re as a};
@@ -1,11 +0,0 @@
1
- import{o as i}from"./index-DNb6Q69l.js";import{ae as s,af as l,ag as u,ah as f}from"./ui-CEFkTVnG.js";/**
2
- * @license lucide-react v0.562.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const p=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M6.376 18.91a6 6 0 0 1 11.249.003",key:"hnjrf2"}],["circle",{cx:"12",cy:"11",r:"4",key:"1gt34v"}]],T=i("shield-user",p);/**
7
- * @license lucide-react v0.562.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const y=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],j=i("users",y);function h(t){const e=this;e.compiler=r;function r(n){return s(n,{...e.data("settings"),...t,extensions:e.data("toMarkdownExtensions")||[]})}}const m=l().use(u).use(h).freeze(),d=64;function g(t){let e;try{e=JSON.parse(t)}catch{return null}if(!e||typeof e!="object"||!("root"in e))return null;const r=[];return a(e.root,r,0),r.join("")}function a(t,e,r){if(r>d||!t||typeof t!="object")return;const n=t;if(n.type==="text"&&typeof n.text=="string"&&n.text.length>0&&e.push(n.text),Array.isArray(n.children))for(const o of n.children)a(o,e,r+1)}function c(t,e){if(!t)return;const r=t.type??"";if(!(r==="code"&&typeof t.lang=="string"&&/^(meta2|meta2d)$/i.test(t.lang.trim()))){if(r==="image"){typeof t.alt=="string"&&t.alt&&e.push(t.alt);return}if((r==="text"||r==="inlineCode"||r==="code"||r==="yaml")&&typeof t.value=="string"&&t.value.length>0&&e.push(t.value),Array.isArray(t.children))for(const n of t.children)c(n,e)}}function x(t){const e=m().use(f).parse(t),r=[];return c(e,r),r.join("")}function k(t){if(typeof document<"u"){const e=document.createElement("div");return e.innerHTML=t,e.textContent??""}return t.replace(/<script[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ")}function M(t,e){if(!e)return"";if(t==="html")return k(e);const r=g(e);return r!==null?r:x(e)}function C(t){return t.length}function A(t,e){return C(M(t,e))}export{T as S,j as U,A as c};