@fgbg/mdocs 0.8.21 → 0.8.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +17 -1
  3. package/agent-skills/index.json +1 -1
  4. package/bin/mdocs.js +1 -1
  5. package/dist/server/cli/main.js +22 -1
  6. package/dist/server/cli/main.js.map +1 -1
  7. package/dist/server/cli/self-update.js +4 -0
  8. package/dist/server/cli/self-update.js.map +1 -1
  9. package/dist/server/documents/tree-and-folders.test.js +54 -3
  10. package/dist/server/documents/tree-and-folders.test.js.map +1 -1
  11. package/dist/server/documents/tree.service.js +66 -5
  12. package/dist/server/documents/tree.service.js.map +1 -1
  13. package/dist/server/routes/documents.routes.js +16 -0
  14. package/dist/server/routes/documents.routes.js.map +1 -1
  15. package/dist/web/assets/{AgentChatPanel-D95hI02c.js → AgentChatPanel-CtdLYtSw.js} +1 -1
  16. package/dist/web/assets/{AgentSkillFormCard-BtJ0QjLG.js → AgentSkillFormCard-DeZnOTQg.js} +2 -2
  17. package/dist/web/assets/AiWriteWorkbench-hUYjin2m.js +7 -0
  18. package/dist/web/assets/DiagramEditor-NtNY3sZL-C9hL71kf.js +2 -0
  19. package/dist/web/assets/DocumentEditor-BmmnuieO.js +21 -0
  20. package/dist/web/assets/{MergeView-DgFQHD5_.js → MergeView-CjhCBNPa.js} +1 -1
  21. package/dist/web/assets/{PlaygroundPage-Dg57Xxpl.js → PlaygroundPage-CgaNgQEp.js} +1 -1
  22. package/dist/web/assets/SettingsPage-Fl5Tu7u3.js +1 -0
  23. package/dist/web/assets/{Toolbar-0Y2wmGwe.js → Toolbar-BaKuyXey.js} +1 -1
  24. package/dist/web/assets/{VisitorPickerModal-COxtOvc4.js → VisitorPickerModal-DPyg6mIt.js} +1 -1
  25. package/dist/web/assets/{copy-nOl0d3Th.js → copy-UkvgEfIg.js} +1 -1
  26. package/dist/web/assets/diagram-BLCqfrbF.js +6257 -0
  27. package/dist/web/assets/index-Ct5Vt4tz.js +185 -0
  28. package/dist/web/assets/index-Dt_PAYaR.css +1 -0
  29. package/dist/web/assets/meta2d-D3b5RRN8.js +110 -0
  30. package/dist/web/assets/{meta2dEngine-BD2XbzaV-e28q005B.js → meta2dEngine-BD2XbzaV-2ovN6JHu.js} +1 -1
  31. package/dist/web/assets/{motion-D-I76zAi.js → motion-Bz_inm1R.js} +1 -1
  32. package/dist/web/assets/{plus-DvBbg6jL.js → plus-B-uEAM2g.js} +1 -1
  33. package/dist/web/assets/react-6CQL39Gs.js +2382 -0
  34. package/dist/web/assets/react-vendor-BJFXgntS.js +242 -0
  35. package/dist/web/assets/{ui-C3xtW1w8.js → ui-TwLH91RV.js} +133 -133
  36. package/dist/web/index.html +5 -5
  37. package/package.json +2 -2
  38. package/dist/web/assets/AiWriteWorkbench-Qam8cfY6.js +0 -6
  39. package/dist/web/assets/DiagramEditor-BTRe45TX-Did98cnP.js +0 -2
  40. package/dist/web/assets/DocumentEditor-DtSzkl6A.js +0 -21
  41. package/dist/web/assets/SettingsPage-CkYpe5v7.js +0 -1
  42. package/dist/web/assets/diagram-BJFhx-27.js +0 -3016
  43. package/dist/web/assets/index-B-XJ-ScV.js +0 -185
  44. package/dist/web/assets/index-CGvsjO9f.css +0 -1
  45. package/dist/web/assets/meta2d-C8Z4cn-d.js +0 -110
  46. package/dist/web/assets/react-BsVOIHR8.js +0 -2126
  47. package/dist/web/assets/react-vendor-BNpqFP9B.js +0 -242
@@ -27,11 +27,11 @@
27
27
  opacity: 0.65;
28
28
  }
29
29
  </style>
30
- <script type="module" crossorigin src="/assets/index-B-XJ-ScV.js"></script>
31
- <link rel="modulepreload" crossorigin href="/assets/react-vendor-BNpqFP9B.js">
32
- <link rel="modulepreload" crossorigin href="/assets/motion-D-I76zAi.js">
33
- <link rel="modulepreload" crossorigin href="/assets/ui-C3xtW1w8.js">
34
- <link rel="stylesheet" crossorigin href="/assets/index-CGvsjO9f.css">
30
+ <script type="module" crossorigin src="/assets/index-Ct5Vt4tz.js"></script>
31
+ <link rel="modulepreload" crossorigin href="/assets/react-vendor-BJFXgntS.js">
32
+ <link rel="modulepreload" crossorigin href="/assets/motion-Bz_inm1R.js">
33
+ <link rel="modulepreload" crossorigin href="/assets/ui-TwLH91RV.js">
34
+ <link rel="stylesheet" crossorigin href="/assets/index-Dt_PAYaR.css">
35
35
  </head>
36
36
  <body>
37
37
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgbg/mdocs",
3
- "version": "0.8.21",
3
+ "version": "0.8.23",
4
4
  "description": "A Markdown knowledge base for small teams",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -42,7 +42,7 @@
42
42
  "@earendil-works/pi-agent-core": "^0.82.1",
43
43
  "@earendil-works/pi-ai": "^0.82.1",
44
44
  "@lexical/rich-text": "0.42.0",
45
- "@lobehub/editor": "npm:@fgbg/lobe-editor@1.0.0-fork.19",
45
+ "@lobehub/editor": "npm:@fgbg/lobe-editor@1.0.0-fork.20",
46
46
  "@lobehub/ui": "^5.0.0",
47
47
  "@node-rs/jieba": "^2.0.1",
48
48
  "@shikijs/langs": "4.0.2",
@@ -1,6 +0,0 @@
1
- import{r as m,j as e}from"./react-vendor-BNpqFP9B.js";import{aa as se,ab as ie,i as ae,ae as le,am as oe,af as re,ag as ce,ah as de}from"./index-B-XJ-ScV.js";import{H as ue,S as me,A as he}from"./AgentSkillFormCard-BtJ0QjLG.js";import{P as fe}from"./plus-DvBbg6jL.js";import{M as ge,r as xe}from"./ui-C3xtW1w8.js";import"./motion-D-I76zAi.js";function B(t){return t===""?[]:t.split(`
2
- `)}function X(t){return t.join(`
3
- `)}function K(t,i){const s=B(t),o=B(i),f=s.length,g=o.length,y=Array.from({length:f+1},()=>Array.from({length:g+1},()=>0));for(let w=f-1;w>=0;w--)for(let N=g-1;N>=0;N--)s[w]===o[N]?y[w][N]=y[w+1][N+1]+1:y[w][N]=Math.max(y[w+1][N],y[w][N+1]);const j=[];let r=0,x=0;for(;r<f||x<g;)if(r<f&&x<g&&s[r]===o[x])j.push({kind:"eq",oi:r,ni:x}),r++,x++;else if(x<g&&(r===f||y[r][x+1]>=y[r+1][x]))j.push({kind:"ins",oi:r,ni:x}),x++;else if(r<f)j.push({kind:"del",oi:r,ni:x}),r++;else break;const v=[];let p=0,P=0;for(;p<j.length;){if(j[p].kind==="eq"){p++;continue}const w=j[p].oi,N=j[p].ni,_=[],A=[];let S=w,d=N;for(;p<j.length&&j[p].kind!=="eq";){const h=j[p];h.kind==="del"?(_.push(s[h.oi]),S=h.oi+1):(A.push(o[h.ni]),d=h.ni+1),p++}v.push({id:`h${P++}`,oldStart:w,oldEnd:S,newStart:N,newEnd:d,oldLines:_,newLines:A})}return v}function ke(t,i){const s=B(t);return X([...s.slice(0,i.oldStart),...i.newLines,...s.slice(i.oldEnd)])}function pe(t,i){const s=B(t);return X([...s.slice(0,i.newStart),...i.oldLines,...s.slice(i.newEnd)])}function ye(t){return t===""?[]:t.split(`
4
- `)}function je(t,i){const s=ye(t),o=[];let f=0;return i.forEach((g,y)=>{g.oldStart>f&&o.push({kind:"same",lines:s.slice(f,g.oldStart),key:`s-${f}-${g.oldStart}`}),o.push({kind:"hunk",hunk:g,hunkIndex:y,key:`h-${g.id}-${y}`}),f=g.oldEnd}),f<s.length?o.push({kind:"same",lines:s.slice(f),key:`s-${f}-end`}):i.length===0&&s.length===0&&o.push({kind:"same",lines:[],key:"s-empty"}),o}function we(t){return t.oldLines.length===0?"add":t.newLines.length===0?"del":"mod"}function Ne(t){const i=!!t.sending,[s,o]=m.useState(!1),[f,g]=m.useState(0),[y,j]=m.useState(null),r=m.useMemo(()=>t.proposedMd==null||t.proposedMd===t.currentMd?[]:K(t.currentMd,t.proposedMd),[t.currentMd,t.proposedMd]),x=m.useMemo(()=>je(t.currentMd,r),[t.currentMd,r]);m.useEffect(()=>{if(r.length===0){g(0),o(!1);return}g(d=>Math.min(d,r.length-1))},[r.length]),m.useEffect(()=>{i&&o(!1)},[i]);const v=!i&&s&&r.length>0,p=y??f;function P(d){const h=ke(t.currentMd,d);t.onCurrentChange(h),t.proposedMd!=null&&K(h,t.proposedMd).length===0&&t.onProposedChange(null)}function w(d){if(t.proposedMd==null)return;const h=pe(t.proposedMd,d);h===t.currentMd?t.onProposedChange(null):t.onProposedChange(h)}function N(){t.proposedMd!=null&&(t.onCurrentChange(t.proposedMd),t.onProposedChange(null))}function _(){t.onProposedChange(null)}function A(d){r.length!==0&&g(h=>{const I=(h+d+r.length)%r.length,L=document.getElementById(`mdocs-ai-hunk-${I}`);return L==null||L.scrollIntoView({block:"center",behavior:"smooth"}),I})}const S=r[p]??null;return e.jsxs("div",{className:"mdocs-ai-write-md-pane",children:[e.jsxs("div",{className:"mdocs-ai-write-diff-toolbar",children:[e.jsx("span",{className:"mdocs-ai-write-diff-count",children:i?"接收中·编辑我的稿":r.length===0?t.proposedMd?"与提案一致(可编辑)":"Markdown 源码(可编辑)":s?`${r.length} 处变更`:`${r.length} 处变更(编辑中)`}),!i&&r.length>0?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:N,children:"全部接受"}),e.jsx("button",{type:"button",onClick:_,children:"全部拒绝"}),e.jsx("button",{type:"button",className:s?"active":"",onClick:()=>o(d=>!d),children:s?"编辑我的稿":"查看 diff"})]}):null]}),v?e.jsxs("div",{className:"mdocs-ai-write-inline",role:"document",children:[x.map(d=>{if(d.kind==="same")return e.jsx("pre",{className:"mdocs-ai-write-inline-same",children:d.lines.map((k,E)=>e.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[e.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),e.jsx("span",{className:"mdocs-ai-write-code",children:k||" "})]},E))},d.key);const h=d.hunk,I=we(h),L=d.hunkIndex===p;return e.jsxs("div",{id:`mdocs-ai-hunk-${d.hunkIndex}`,className:`mdocs-ai-write-inline-hunk mdocs-ai-write-inline-hunk-${I}`+(L?" is-active":""),onMouseEnter:()=>j(d.hunkIndex),onMouseLeave:()=>j(null),onClick:()=>g(d.hunkIndex),children:[e.jsxs("div",{className:"mdocs-ai-write-hunk-hover",hidden:y!==d.hunkIndex,children:[e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:k=>{k.stopPropagation(),w(h)},children:"拒绝"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:k=>{k.stopPropagation(),P(h)},children:"接受"})]}),e.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[h.oldLines.map((k,E)=>e.jsxs("div",{className:"mdocs-ai-write-line del",children:[e.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),e.jsx("span",{className:"mdocs-ai-write-code",children:k||" "})]},`o${E}`)),h.newLines.map((k,E)=>e.jsxs("div",{className:"mdocs-ai-write-line add",children:[e.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),e.jsx("span",{className:"mdocs-ai-write-code",children:k||" "})]},`n${E}`))]})]},d.key)}),S?e.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"变更导航",children:[e.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>A(-1),children:"↑"}),e.jsxs("span",{children:[p+1," / ",r.length]}),e.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>A(1),children:"↓"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>w(S),children:"拒绝"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>P(S),children:"接受"})]}):null]}):e.jsx("textarea",{className:"mdocs-ai-write-editor",value:t.currentMd,onChange:d=>t.onCurrentChange(d.target.value),spellCheck:!1,placeholder:`# 标题
5
-
6
- 在此编辑 Markdown 源码…`})]})}let U=0;function J(t){return U+=1,`${t}-${Date.now()}-${U}`}function be(t,i){const s=t.slice(),o=s[s.length-1];return(o==null?void 0:o.type)==="text"?s[s.length-1]={type:"text",text:o.text+i}:s.push({type:"text",text:i}),s}function Se(t,i){const s=t.slice(),o=s[s.length-1];return(o==null?void 0:o.type)==="thinking"?s[s.length-1]={type:"thinking",text:o.text+i}:s.push({type:"thinking",text:i}),s}function T(t,i){const s=i.trim();return s?[...t,{type:"tool",text:s}]:t}function Ce(t){return t.some(i=>i.type==="text"||i.type==="thinking"?i.text.length>0:!0)}function Ie(t){const i=new Date(t);if(Number.isNaN(i.getTime()))return"";const s=new Date;return i.getFullYear()===s.getFullYear()&&i.getMonth()===s.getMonth()&&i.getDate()===s.getDate()?i.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):i.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function Q(t,i){return i.map((s,o)=>{const f=`h-${t}-${o}-${s.role}`;if(s.role==="user"){const g=s.skillNames&&s.skillNames.length>0?s.skillNames:s.skillIds&&s.skillIds.length>0?s.skillIds:void 0;return{id:f,role:"user",content:s.content,skillNames:g}}return{id:f,role:"assistant",blocks:s.content?[{type:"text",text:s.content}]:[]}})}function Le(t){const[i,s]=m.useState(t.initialMarkdown),[o,f]=m.useState(null),[g]=m.useState(t.initialMarkdown),[y,j]=m.useState(t.displayName||"未命名"),[r,x]=m.useState([]),[v,p]=m.useState(null),[P,w]=m.useState([]),[N,_]=m.useState(!1),[A,S]=m.useState(!1),[d,h]=m.useState(""),[I,L]=m.useState([]),[k,E]=m.useState(!1),[b,O]=m.useState(null),[z,$]=m.useState(null),[W,V]=m.useState(!1),D=m.useRef(null);async function F(){_(!0);try{const n=await le("coding",t.documentId);w(n.sessions),v||p(n.lastOpenedSessionId)}catch{}finally{_(!1)}}if(m.useEffect(()=>{var c;if(!t.open){S(!1),(c=D.current)==null||c.abort();return}s(t.initialMarkdown),f(null),j(t.displayName||"未命名"),h(""),$(null),S(!1);let n=!1;return(async()=>{try{const l=await se();n||O(l)}catch{n||O({enabled:!1,skillsReady:!1,model:null})}try{const l=await ie("coding",t.documentId);if(n)return;p(l.sessionId),x(Q(l.sessionId,l.messages))}catch{n||(p(null),x([]))}F()})(),()=>{n=!0}},[t.open,t.initialMarkdown,t.displayName,t.documentId]),m.useEffect(()=>()=>{var n;return(n=D.current)==null?void 0:n.abort()},[]),m.useEffect(()=>{t.open&&A&&F()},[A,t.open,t.documentId]),!t.open)return null;const Y=o!=null&&o!==i?K(i,o):[];async function Z(){var n;if(!k){(n=D.current)==null||n.abort(),$(null),S(!1),E(!1);try{const c=await re("coding",t.documentId);p(c.sessionId),x([]),h(""),F()}catch(c){$(c instanceof Error?c.message:String(c))}}}async function ee(n){var c;if(!k){if(n===v){S(!1);return}(c=D.current)==null||c.abort(),$(null);try{const l=await ce(n,"coding",t.documentId);p(l.sessionId),x(Q(l.sessionId,l.messages)),h(""),S(!1)}catch(l){$(l instanceof Error?l.message:String(l))}}}async function G(){var R;const n=d.trim();if(!n||k)return;if(!(b!=null&&b.enabled)){$("请先在设置 → AI 配置 API Key");return}(R=D.current)==null||R.abort();const c=new AbortController;D.current=c;const l=J("u"),H=J("a");x(C=>[...C,{id:l,role:"user",content:n,skillNames:I.length>0?[...I]:void 0},{id:H,role:"assistant",blocks:[]}]),h(""),E(!0),$(null);const M=C=>{x(a=>a.map(u=>u.id===H&&u.role==="assistant"?{...u,blocks:C(u.blocks)}:u))};try{let C=!1;await de(n,{mode:"coding",skillNames:I.length>0?I:void 0,documentId:t.documentId,workingMarkdown:i,baseMarkdown:g,signal:c.signal,onEvent:a=>{a.type==="text_delta"?M(u=>be(u,a.text)):a.type==="thinking_delta"?M(u=>Se(u,a.text)):a.type==="markdown_set"?f(a.markdown):a.type==="tool_notice"?M(u=>T(u,a.text)):a.type==="document_table"?M(u=>T(u,a.title)):a.type==="document_card"?M(u=>T(u,`读取文档「${a.title}」`)):a.type==="sources"?a.items.length>0&&M(u=>T(u,`已阅读 ${a.items.length} 个手册页面`)):a.type==="skill_form_card"?M(u=>[...u,{type:"skill_form_card",requestId:a.requestId,mode:a.mode,title:a.title,currentName:a.currentName,initialName:a.initialName,initialDescription:a.initialDescription,initialBody:a.initialBody,expiresAt:a.expiresAt,status:"open"}]):a.type==="skill_form_expired"?M(u=>u.map(q=>q.type==="skill_form_card"&&q.requestId===a.requestId&&q.status==="open"?{...q,status:"expired"}:q)):a.type==="error"&&(C=!0,$(a.message))}}),!c.signal.aborted&&!C&&L([]),F()}catch(C){c.signal.aborted||$(C instanceof Error?C.message:String(C))}finally{D.current===c&&(D.current=null),E(!1)}}async function te(){let n=i;if(Y.length>0){if(!window.confirm(`还有 ${Y.length} 段未审阅,将全部接受后写回。继续?`))return;n=o??i,s(n),f(null)}V(!0);const c=!t.documentId;try{const l=await t.onComplete({markdown:n,documentId:t.documentId,displayName:y.trim()||"未命名"}),H=l&&typeof l=="object"&&typeof l.documentId=="string"?l.documentId.trim():"";if(c&&H&&v)try{await oe(v,H)}catch{}t.onClose()}catch(l){if(l!=null&&l.silent||l instanceof Error&&l.message==="cancelled")return;$(l instanceof Error?l.message:String(l))}finally{V(!1)}}function ne(){var n;(i!==g||o!=null)&&!window.confirm("取消帮写?未写回的修改将丢失。")||((n=D.current)==null||n.abort(),t.onClose())}return e.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[e.jsxs("header",{className:"mdocs-ai-write-header",children:[e.jsxs("div",{className:"mdocs-ai-write-header-left",children:[e.jsx("img",{src:ae,alt:"",className:"mdocs-ai-write-title-logo"}),e.jsx("strong",{children:"帮写"}),e.jsx("input",{className:"mdocs-ai-write-title",value:y,onChange:n=>j(n.target.value),"aria-label":"文档标题"})]}),e.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[e.jsx("button",{type:"button",onClick:ne,disabled:W,children:"取消"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void te(),disabled:W,children:W?"写回中…":"完成并写回"})]})]}),e.jsxs("div",{className:"mdocs-ai-write-body",children:[e.jsxs("section",{className:"mdocs-ai-write-chat",children:[e.jsxs("div",{className:"mdocs-ai-write-chat-toolbar",children:[e.jsx("span",{className:"mdocs-ai-write-chat-toolbar-label",children:"对话"}),e.jsxs("div",{className:"mdocs-ai-write-chat-toolbar-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:k,onClick:()=>void Z(),children:e.jsx(fe,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(A?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>S(n=>!n),children:e.jsx(ue,{size:16,strokeWidth:1.8})})]})]}),A?e.jsxs("div",{className:"mdocs-ai-write-history 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:()=>S(!1),children:"返回对话"})]}),N?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):P.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:"发一条消息后会出现在这里"})]}):e.jsx("ul",{className:"mdocs-agent-panel-history-list",children:P.map(n=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(n.id===v?" active":""),disabled:k,onClick:()=>void ee(n.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:n.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:Ie(n.updatedAt)})]})},n.id))})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-ai-write-chat-messages",children:r.length===0?e.jsx("p",{className:"mdocs-ai-write-hint",children:"描述你想写或改的内容。助手可读取右侧当前稿与进场快照,再更新提案;请按段接受或拒绝后完成写回。"}):r.map(n=>e.jsx("div",{className:"mdocs-ai-write-msg"+(n.role==="user"?" mdocs-ai-write-msg-user":""),children:n.role==="user"?e.jsxs(e.Fragment,{children:[n.skillNames&&n.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",n.skillNames.length]}):null,n.content]}):Ce(n.blocks)?e.jsx("div",{className:"mdocs-ai-write-timeline",children:n.blocks.map((c,l)=>c.type==="thinking"?c.text?e.jsxs("details",{className:"mdocs-ai-write-thinking",open:k,children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-ai-write-thinking-body",children:c.text})]},`${n.id}-think-${l}`):null:c.type==="tool"?e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:c.text},`${n.id}-tool-${l}`):c.type==="skill_form_card"?e.jsx(me,{block:c,onResolved:(H,M,R)=>{x(C=>C.map(a=>a.id!==n.id||a.role!=="assistant"?a:{...a,blocks:a.blocks.map(u=>u.type==="skill_form_card"&&u.requestId===H?{...u,status:M,submittedName:M==="submitted"?R:u.submittedName}:u)}))}},`${n.id}-sf-${l}`):c.text?e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(ge,{remarkPlugins:[xe],children:c.text})},`${n.id}-text-${l}`):null)}):k?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null},n.id))}),z?e.jsx("p",{className:"mdocs-ai-write-error",children:z}):null,e.jsxs("div",{className:"mdocs-ai-write-input-row",children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:[e.jsx(he,{selectedNames:I,onChange:L,disabled:k||!(b!=null&&b.enabled)}),e.jsx("textarea",{rows:2,value:d,disabled:k||!(b!=null&&b.enabled),placeholder:b!=null&&b.enabled?"说说要写什么…":"请先配置 API Key",onChange:n=>h(n.target.value),onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),G())}})]}),e.jsx("button",{type:"button",disabled:k||!(b!=null&&b.enabled),onClick:()=>void G(),children:"发送"})]})]})]}),e.jsx(Ne,{currentMd:i,proposedMd:o,sending:k,onCurrentChange:s,onProposedChange:f})]})]})}export{Le as AiWriteWorkbench};
@@ -1,2 +0,0 @@
1
- import{Q as M,S as F,T as A,U as W,V}from"./react-BsVOIHR8.js";import{r as c,j as e}from"./react-vendor-BNpqFP9B.js";import{ensureMeta2dShapes as N,generateSvgFromMeta2d as q,generateSvgFromDiagram as I}from"./meta2dEngine-BD2XbzaV-e28q005B.js";import{M as G}from"./meta2d-C8Z4cn-d.js";import"./editor-ONzd_YnO.js";import"./ui-C3xtW1w8.js";import"./motion-D-I76zAi.js";import"./diagram-BJFhx-27.js";import"./index-B-XJ-ScV.js";import"./plus-DvBbg6jL.js";import"./copy-nOl0d3Th.js";let T=0;const D=new Set;function O(n){return D.add(n),()=>{D.delete(n)}}function P(){return T}function Q(){T++,D.forEach(n=>n())}function E(n){let t=null;try{const[a]=M();t=a}catch{}const l=t;if(!l)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore(O,P,P),{setLocale:c.useCallback(a=>{l.setLocale(a),Q()},[l]),t:c.useCallback((a,p)=>l.t(a,p),[l])}}const X={Activity:"meta2d.palette.groups.activity",Basic:"meta2d.palette.groups.basic","Fault tree":"meta2d.palette.groups.faultTree",Flow:"meta2d.palette.groups.flow","Sequence & class":"meta2d.palette.groups.sequenceClass"};function L(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function Y(){return[{group:"Basic",key:"square",label:"Square",pen:{...s,height:100,name:"square",text:"",width:100}},{group:"Basic",key:"rect",label:"Rectangle",pen:{...s,name:"rectangle",text:"Rectangle"}},{group:"Basic",key:"roundRect",label:"Rounded",pen:{...s,borderRadius:.2,name:"rectangle",text:"Rounded"}},{group:"Basic",key:"circle",label:"Circle",pen:{...s,height:80,name:"circle",text:"Circle",width:80}},{group:"Basic",key:"triangle",label:"Triangle",pen:{...s,height:90,name:"triangle",text:"Triangle",width:100}},{group:"Basic",key:"diamond",label:"Diamond",pen:{...s,height:100,name:"diamond",text:"Decision",width:100}},{group:"Basic",key:"pentagon",label:"Pentagon",pen:{...s,height:100,name:"pentagon",text:"Pentagon",width:100}},{group:"Basic",key:"hexagon",label:"Hexagon",pen:{...s,height:100,name:"hexagon",text:"Hexagon",width:100}},{group:"Basic",key:"pentagram",label:"Star",pen:{...s,height:100,name:"pentagram",text:"",width:100}},{group:"Basic",key:"leftArrow",label:"Left arrow",pen:{height:60,name:"leftArrow",width:120}},{group:"Basic",key:"rightArrow",label:"Right arrow",pen:{height:60,name:"rightArrow",width:120}},{group:"Basic",key:"twowayArrow",label:"Two-way",pen:{height:60,name:"twowayArrow",width:150}},{group:"Basic",key:"cloud",label:"Cloud",pen:{height:100,name:"cloud",width:100}},{group:"Basic",key:"message",label:"Message",pen:{height:100,name:"message",textTop:-.1,width:100}},{group:"Basic",key:"file",label:"File",pen:{height:100,name:"file",width:80}},{group:"Basic",key:"cube",label:"Cube",pen:{height:100,name:"cube",width:60,z:.25}},{group:"Basic",key:"people",label:"Actor",pen:{height:100,name:"people",width:70}},{group:"Basic",key:"text",label:"Text",pen:{...s,background:"transparent",color:"transparent",height:32,name:"text",text:"text",width:120}},{group:"Basic",key:"line",label:"Line",pen:{color:"#1f1f1f",height:1,lineWidth:1,name:"line",width:160}},{group:"Flow",key:"flowTerminal",label:"Terminal",pen:{...s,borderRadius:.5,height:40,name:"rectangle",text:"Start / End",width:120}},{group:"Flow",key:"flowProcess",label:"Process",pen:{...s,height:40,name:"rectangle",text:"Process",width:120}},{group:"Flow",key:"flowDecision",label:"Decision",pen:{...s,height:60,name:"diamond",text:"Decision",width:120}},{group:"Flow",key:"flowData",label:"Data",pen:{...s,name:"flowData",offsetX:.14,text:"Data"}},{group:"Flow",key:"flowPrepare",label:"Prepare",pen:{...s,height:50,name:"hexagon",text:"Prepare",width:120}},{group:"Flow",key:"flowSubprocess",label:"Subprocess",pen:{...s,height:50,name:"flowSubprocess",text:"Subprocess",width:120}},{group:"Flow",key:"flowDb",label:"Database",pen:{...s,height:100,name:"flowDb",text:"DB",width:80}},{group:"Flow",key:"flowDocument",label:"Document",pen:{...s,height:100,name:"flowDocument",text:"Document",width:120}},{group:"Flow",key:"flowInternalStorage",label:"Int. storage",pen:{...s,height:80,name:"flowInternalStorage",text:"Internal",width:120}},{group:"Flow",key:"flowExternStorage",label:"Ext. storage",pen:{...s,height:80,name:"flowExternStorage",text:"External",width:120}},{group:"Flow",key:"flowQueue",label:"Queue",pen:{...s,height:100,name:"flowQueue",text:"Queue",width:100}},{group:"Flow",key:"flowManually",label:"Manual input",pen:{...s,height:80,name:"flowManually",text:"Manual",width:120}},{group:"Flow",key:"flowDisplay",label:"Display",pen:{...s,height:80,name:"flowDisplay",text:"Display",width:120}},{group:"Flow",key:"flowParallel",label:"Parallel",pen:{...s,height:50,name:"flowParallel",text:"Parallel",width:120}},{group:"Flow",key:"flowComment",label:"Comment",pen:{...s,height:100,name:"flowComment",text:"Note",width:100}},{group:"Activity",key:"actStart",label:"Start",pen:{background:"#555",height:30,lineWidth:0,name:"circle",text:"",width:30}},{group:"Activity",key:"actFinal",label:"Final",pen:{height:30,name:"activityFinal",width:30}},{group:"Activity",key:"actStep",label:"Action",pen:{...s,borderRadius:.25,height:50,name:"rectangle",text:"Action",width:120}},{group:"Activity",key:"actMerge",label:"Merge",pen:{...s,height:50,name:"diamond",text:"Merge",width:120}},{group:"Activity",key:"swimlaneV",label:"Swimlane V",pen:{height:500,lineTop:.08,name:"swimlaneV",text:"Swimlane",textBaseline:"top",textTop:20,width:200}},{group:"Activity",key:"swimlaneH",label:"Swimlane H",pen:{height:200,lineLeft:.08,name:"swimlaneH",text:"Swimlane",textAlign:"left",textLeft:.04,textWidth:.01,width:500}},{group:"Activity",key:"forkV",label:"Fork V",pen:{fillStyle:"#555",height:150,name:"forkV",strokeStyle:"transparent",text:"",width:10}},{group:"Activity",key:"forkH",label:"Fork H",pen:{fillStyle:"#555",height:10,name:"forkH",strokeStyle:"transparent",text:"",width:150}},{group:"Sequence & class",key:"lifeline",label:"Lifeline",pen:{height:400,name:"lifeline",text:"Object",textHeight:50,width:150}},{group:"Sequence & class",key:"sequenceFocus",label:"Activation",pen:{height:200,name:"sequenceFocus",text:"",width:12}},{group:"Sequence & class",key:"simpleClass",label:"Simple class",pen:{height:200,list:[{text:`- name: string
2
- + setName(name: string): void`}],name:"simpleClass",text:"ClassName",textAlign:"center",textBaseline:"top",textHeight:200,textTop:10,width:270}},{group:"Sequence & class",key:"interfaceClass",label:"Class",pen:{height:200,list:[{text:"- name: string"},{text:"+ setName(name: string): void"}],name:"interfaceClass",text:"ClassName",textAlign:"center",textBaseline:"top",textHeight:200,textTop:10,width:270}},{group:"Fault tree",key:"andGate",label:"AND gate",pen:{height:150,name:"andGate",width:100}},{group:"Fault tree",key:"orGate",label:"OR gate",pen:{height:150,name:"orGate",width:100}},{group:"Fault tree",key:"basicEvent",label:"Basic event",pen:{height:150,name:"basicEvent",width:100}},{group:"Fault tree",key:"xorGate",label:"XOR gate",pen:{height:150,name:"xorGate",width:100}},{group:"Fault tree",key:"votingGate",label:"Voting gate",pen:{height:150,name:"votingGate",width:100}}]}function z(n){return V(structuredClone(n))}function $(n){const t=new Map;for(const l of n){const a=t.get(l.group)??[];a.push(l),t.set(l.group,a)}return Array.from(t.entries())}function J({name:n}){const t={fill:"#fff",stroke:"#1f1f1f",strokeWidth:1.2};return n==="circle"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("circle",{cx:"14",cy:"14",r:"10",...t})}):n==="diamond"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 25,14 14,25 3,14",...t})}):n==="triangle"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,4 25,24 3,24",...t})}):n==="pentagon"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 25,12 21,25 7,25 3,12",...t})}):n==="hexagon"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"8,4 20,4 25,14 20,24 8,24 3,14",...t})}):n==="pentagram"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 17,11 26,11 18,16 21,25 14,20 7,25 10,16 2,11 11,11",...t})}):n==="line"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("line",{x1:"4",x2:"24",y1:"14",y2:"14",...t})}):n==="text"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("text",{dominantBaseline:"middle",fill:"#1f1f1f",fontSize:"14",textAnchor:"middle",x:"14",y:"15",children:"T"})}):e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("rect",{height:"14",rx:"2",width:"20",x:"4",y:"7",...t})})}function K({disabled:n,engineRef:t,item:l,t:a}){const p=()=>{const r=t.current;if(!(!r||n))try{r.canvas.addCaches=[z(l.pen)]}catch{}};return e.jsxs("div",{draggable:!n,onClick:r=>{r.stopPropagation(),p()},onDragStart:r=>{if(n){r.preventDefault();return}const g=JSON.stringify(z(l.pen));r.dataTransfer.setData("Meta2d",g),r.dataTransfer.setData("Text",g),r.dataTransfer.effectAllowed="copy"},onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),p())},role:"button",style:{alignItems:"center",border:"1px solid #efefef",borderRadius:6,cursor:n?"not-allowed":"grab",display:"flex",flexDirection:"column",gap:4,justifyContent:"center",minHeight:56,opacity:n?.5:1,outline:"none",padding:6},tabIndex:n?-1:0,title:`${a(L(l.key))||l.label} — drag or click to add`,children:[e.jsx(J,{name:String(l.pen.name??"rectangle")}),e.jsx("span",{style:{fontSize:11},children:a(L(l.key))||l.label})]})}function U({disabled:n,engineRef:t}){const{t:l}=E(),a=c.useMemo(()=>$(Y()),[]);return e.jsxs("aside",{style:{borderRight:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",padding:12,touchAction:"pan-y",width:240},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,marginBottom:4},children:l("meta2d.palette.title")}),e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:12},children:l("meta2d.palette.hint")}),a.map(([p,r])=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:6},children:l(X[p]||p)}),e.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"repeat(2, minmax(0, 1fr))"},children:r.map(g=>e.jsx(K,{disabled:n,engineRef:t,item:g,t:l},g.key))})]},p))]})}const H={borderLeft:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",touchAction:"pan-y",width:220},j={color:"#8c8c8c",fontSize:12,marginBottom:4},k={borderBottom:"1px solid #f0f0f0",padding:"10px 12px"},f={alignItems:"center",display:"flex",gap:6,marginBottom:6},m={background:"#fafafa",border:"1px solid #e5e5e5",borderRadius:4,fontSize:12,height:28,outline:"none",padding:"0 6px"},y={color:"#8c8c8c",fontSize:11,minWidth:22},C={background:"#fff",border:"1px solid #d9d9d9",borderRadius:4,cursor:"pointer",fontSize:11,minWidth:48,padding:"4px 8px"};function _({engine:n}){const{t}=E(),[l,a]=c.useState(null),[p,r]=c.useState(null),g=c.useRef({}),b=c.useCallback(o=>{if(!o||o.length!==1){a(null),r(null);return}const d=o[0];if((d.globalAlpha===null||d.globalAlpha===void 0)&&(d.globalAlpha=1),a(d),n)try{r(n.getPenRect(d))}catch{r(null)}},[n]),v=c.useCallback(()=>{a(null),r(null)},[]);if(c.useEffect(()=>{if(n)return n.on("active",b),n.on("inactive",v),()=>{n.off("active",b),n.off("inactive",v)}},[n,b,v]),!l||!n)return e.jsx("aside",{style:H,children:e.jsx("div",{style:{color:"#bbb",fontSize:12,padding:16,textAlign:"center"},children:t("meta2d.props.empty")})});const h=(o,d)=>{g.current[o]=d;const i={id:l.id};i[o]=d,o==="dash"&&(i.lineDash=[void 0,[5,5]][d]),n.setValue(i,{render:!0})},B=(o,d)=>{if(!p)return;const i={id:l.id};i[o]=d,n.setValue(i,{render:!0}),r(u=>u?{...u,[o]:d}:null)},w=o=>{o(n),n.render(!0)};return e.jsxs("aside",{style:H,children:[e.jsxs("div",{style:k,children:[e.jsx("div",{style:j,children:t("meta2d.props.text")}),e.jsx("div",{style:f,children:e.jsx("input",{onChange:o=>h("text",o.target.value),style:m,type:"text",value:l.text??""})})]}),e.jsxs("div",{style:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.appearance")}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.color")}),e.jsx("input",{onChange:o=>h("color",o.target.value),style:{...m,flex:1},type:"color",value:l.color||"#1f1f1f"})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.bg")}),e.jsx("input",{onChange:o=>h("background",o.target.value),style:{...m,flex:1},type:"color",value:l.background||"#ffffff"})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.dash")}),e.jsxs("select",{onChange:o=>h("dash",Number(o.target.value)),style:{...m,flex:1},value:String(l.dash??0),children:[e.jsx("option",{value:"0",children:t("meta2d.props.solid")}),e.jsx("option",{value:"1",children:t("meta2d.props.dashLine")})]})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.radius")}),e.jsx("input",{max:1,min:0,onChange:o=>h("borderRadius",Number(o.target.value)),step:.01,style:{...m,flex:1},type:"range",value:String(l.borderRadius??0)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:l.borderRadius??0})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.alpha")}),e.jsx("input",{max:1,min:0,onChange:o=>h("globalAlpha",Number(o.target.value)),step:.01,style:{...m,flex:1},type:"range",value:String(l.globalAlpha??1)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:(l.globalAlpha??1).toFixed(2)})]})]}),e.jsxs("div",{style:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.position")}),[["X","x"],["Y","y"],["W","width"],["H","height"]].map(([o,d])=>e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:o}),e.jsx("input",{onChange:i=>B(d,Number(i.target.value)),style:{...m,flex:1},type:"number",value:p?p[d]:0})]},d))]}),e.jsxs("div",{style:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.textAlign")}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.h")}),e.jsxs("select",{onChange:o=>h("textAlign",o.target.value),style:{...m,flex:1},value:l.textAlign||"center",children:[e.jsx("option",{value:"left",children:t("meta2d.props.left")}),e.jsx("option",{value:"center",children:t("meta2d.props.center")}),e.jsx("option",{value:"right",children:t("meta2d.props.right")})]})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.v")}),e.jsxs("select",{onChange:o=>h("textBaseline",o.target.value),style:{...m,flex:1},value:l.textBaseline||"middle",children:[e.jsx("option",{value:"top",children:t("meta2d.props.topAlign")}),e.jsx("option",{value:"middle",children:t("meta2d.props.middle")}),e.jsx("option",{value:"bottom",children:t("meta2d.props.bottomAlign")})]})]})]}),e.jsxs("div",{style:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.layer")}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[e.jsx("button",{onClick:()=>w(o=>o.top()),style:C,type:"button",children:t("meta2d.props.top")}),e.jsx("button",{onClick:()=>w(o=>o.up()),style:C,type:"button",children:t("meta2d.props.up")}),e.jsx("button",{onClick:()=>w(o=>o.down()),style:C,type:"button",children:t("meta2d.props.down")}),e.jsx("button",{onClick:()=>w(o=>o.bottom()),style:C,type:"button",children:t("meta2d.props.bottom")})]})]})]})}const R={background:"#fff",border:"1px solid #d9d9d9",borderRadius:6,cursor:"pointer",minWidth:68,padding:"6px 12px"},S={...R,fontSize:12,minWidth:52,padding:"4px 10px"};function Z(n){c.useEffect(()=>{const t=document.documentElement,l=document.body,a=t.style.overflow,p=l.style.overflow;return t.style.overflow="hidden",l.style.overflow="hidden",()=>{t.style.overflow=a,l.style.overflow=p}},[n])}function pe({diagram:n,onClose:t,onSave:l}){const{t:a}=E(),p=c.useRef(null),r=c.useRef(null),g=c.useRef(n),b=c.useRef(t),[v,h]=c.useState(null),[B,w]=c.useState(!1);Z(!0),c.useLayoutEffect(()=>{b.current=t}),c.useEffect(()=>{if(!p.current)return;N();const i=new G(p.current,{grid:!0,rule:!1});r.current=i,h(i);try{const x=g.current;x!=null&&x.trim()?i.open(JSON.parse(x)):i.open(F()),A(i.data()),i.render(!0)}catch{i.open(F()),A(i.data()),i.render(!0)}const u=x=>{x.key==="Escape"&&b.current()};return window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u);try{i.destroy()}catch{}r.current=null}},[]);const o=async()=>{const i=r.current;if(i){w(!0);try{A(i.data()),i.render(!0);const u=W(i.data()),x=JSON.stringify(u);l(x,await q(i)||await I(x)||'<svg xmlns="http://www.w3.org/2000/svg" width="320" height="180" viewBox="0 0 320 180"><rect width="100%" height="100%" fill="#fafafa" stroke="#eee"/></svg>')}finally{w(!1)}}},d=i=>{const u=r.current;u&&i(u)};return e.jsx("div",{onClick:t,style:{alignItems:"center",background:"rgb(0 0 0 / 35%)",display:"flex",inset:0,justifyContent:"center",overflow:"hidden",position:"fixed",zIndex:1e3},children:e.jsxs("div",{onClick:i=>i.stopPropagation(),onWheel:i=>i.stopPropagation(),style:{background:"#fff",borderRadius:10,boxShadow:"0 12px 30px rgb(0 0 0 / 20%)",display:"flex",flexDirection:"column",height:"86vh",maxHeight:"100%",maxWidth:"1200px",overflow:"hidden",width:"92vw"},children:[e.jsxs("div",{style:{alignItems:"center",borderBottom:"1px solid #f0f0f0",display:"flex",flexWrap:"wrap",gap:8,justifyContent:"space-between",padding:"10px 14px"},children:[e.jsx("span",{style:{fontWeight:600},children:a("meta2d.editor.title")}),e.jsxs("div",{style:{alignItems:"center",display:"flex",flexWrap:"wrap",gap:8},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:[e.jsx("button",{onClick:()=>d(i=>i.undo()),style:S,title:`${a("meta2d.editor.undo")} (Ctrl+Z)`,type:"button",children:a("meta2d.editor.undo")}),e.jsx("button",{onClick:()=>d(i=>i.redo()),style:S,title:`${a("meta2d.editor.redo")} (Ctrl+Y)`,type:"button",children:a("meta2d.editor.redo")}),e.jsx("button",{onClick:()=>d(i=>i.delete()),style:S,title:a("meta2d.editor.delete"),type:"button",children:a("meta2d.editor.delete")}),e.jsx("button",{onClick:()=>d(i=>i.fitView(!0)),style:S,title:a("meta2d.editor.fit"),type:"button",children:a("meta2d.editor.fit")}),e.jsx("button",{onClick:()=>d(i=>{i.scale(1),i.centerView()}),style:S,title:a("meta2d.editor.zoom100"),type:"button",children:a("meta2d.editor.zoom100")})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:t,style:R,type:"button",children:a("meta2d.editor.close")}),e.jsx("button",{disabled:B,onClick:()=>void o(),style:{...R,background:"#1677ff",border:"none",color:"#fff"},type:"button",children:a(B?"meta2d.editor.saving":"meta2d.editor.save")})]})]})]}),e.jsxs("div",{style:{display:"flex",flex:1,minHeight:0,overflow:"hidden"},children:[e.jsx(U,{engineRef:r}),e.jsx("div",{ref:p,style:{flex:1,minHeight:0,minWidth:0}}),e.jsx(_,{engine:v})]})]})})}export{pe as DiagramEditor};
@@ -1,21 +0,0 @@
1
- import{r as i,j as n}from"./react-vendor-BNpqFP9B.js";import{B as oe}from"./ui-C3xtW1w8.js";import{c as J,g as he,u as ye,a as re,d as Ne,b as Re,f as De,e as Ae,h as Pe,D as Te,F as Le,l as ce,i as Be,S as _e,M as Oe,j as ze,r as pe,k as Fe,m as V,n as He,o as Ue,p as le}from"./index-B-XJ-ScV.js";import{z as We,A as qe,m as Q,n as Ve,o as $e,p as Je,r as Ge,s as Ke,t as Xe,v as Ye,x as Qe,B as Ze,R as et,a as tt,b as de,c as nt,d as at,e as it,f as st,g as ot,h as rt,i as ct,w as Z,j as lt,O as dt,E as ut,q as mt,l as ft,C as ht,D as yt}from"./react-BsVOIHR8.js";import{H as gt,a as xt,b as vt,M as bt,T as kt,S as It,W as St,N as Ct,o as wt,c as ue}from"./Toolbar-0Y2wmGwe.js";import{V as jt}from"./VisitorPickerModal-COxtOvc4.js";import"./motion-D-I76zAi.js";import"./editor-ONzd_YnO.js";import"./diagram-BJFhx-27.js";import"./plus-DvBbg6jL.js";import"./copy-nOl0d3Th.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 Mt=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],Et=J("refresh-cw",Mt);/**
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 Nt=[["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"}]],Rt=J("shield-user",Nt);/**
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 Dt=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],At=J("text-align-justify",Dt);/**
17
- * @license lucide-react v0.562.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const Pt=[["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"}]],Tt=J("users",Pt),Lt=48;function $(e){try{const a=e.getDocument("markdown");return typeof a=="string"?a:""}catch{return null}}function Bt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function _t({editor:e,documentId:a,displayName:o,debounceMs:g=1e3,enabled:m=!0,localBaseCommitIdAtEditStart:N,snapshotMeta:L}){const[G,P]=i.useState(!1),[R,I]=i.useState(!1),[B,w]=i.useState(null),u=i.useRef(null),f=i.useRef(null),x=i.useRef(!1),v=i.useRef(""),y=i.useRef(!1),S=i.useRef(a),F=i.useRef(o),H=i.useRef(N),_=i.useRef(L);S.current=a,F.current=o,H.current=N,_.current=L;const C=i.useCallback(async()=>{if(!e)return;if(!v.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const c=Bt(e);c!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",S.current,"content preview:",c.slice(0,80)),await he(S.current).execute(()=>ye({documentId:S.current,content:c,displayName:F.current,localBaseCommitIdAtEditStart:H.current,snapshotMeta:_.current})),v.current=$(e)??v.current,I(!0),P(!1),w(Date.now()),x.current=!0,y.current=!1)},[e]);i.useEffect(()=>{let c=!1;return re(a).then(l=>{c||(l?(I(!0),w(l.updatedAt),x.current=!0):(I(!1),w(null),x.current=!1,y.current=!1))}),()=>{c=!0}},[a]),i.useEffect(()=>{var W,q;if(!m){(W=f.current)==null||W.call(f),f.current=null;return}if(!e)return;const c=e.getLexicalEditor();if(!c)return;(q=f.current)==null||q.call(f);let l=!1,b=0,T=0;const O=()=>{if(l)return;const k=$(e);if(k===null){if(T+=1,T>Lt)return;b=requestAnimationFrame(O);return}v.current=k;const r=c.registerUpdateListener(()=>{const A=$(e);A!==null&&A!==v.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",a,"oldLen:",v.current.length,"newLen:",A.length),v.current=A,P(!0),y.current=!0,x.current=!1,u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null,C()},g))});f.current=()=>{r(),u.current&&(clearTimeout(u.current),u.current=null)}};return queueMicrotask(()=>{l||(b=requestAnimationFrame(O))}),()=>{var k;l=!0,cancelAnimationFrame(b),(k=f.current)==null||k.call(f)}},[m,e,a,o,g,N,L,C]),i.useEffect(()=>{var b;if(!m||!e)return;const c=(b=e.getLexicalEditor())==null?void 0:b.getRootElement();if(!c)return;const l=()=>{u.current&&(clearTimeout(u.current),u.current=null),y.current&&C()};return c.addEventListener("blur",l),()=>c.removeEventListener("blur",l)},[m,e,C]),i.useEffect(()=>{if(!m)return;const c=()=>{document.visibilityState==="hidden"&&(u.current&&(clearTimeout(u.current),u.current=null),y.current&&C())},l=()=>{y.current&&(u.current&&(clearTimeout(u.current),u.current=null),C())};return document.addEventListener("visibilitychange",c),window.addEventListener("beforeunload",l),()=>{document.removeEventListener("visibilitychange",c),window.removeEventListener("beforeunload",l)}},[m,C]);async function j(){await Ne(a),I(!1),P(!1),y.current=!1,x.current=!1,v.current=""}async function U(){const c=await re(a);return c?c.content:null}function D(){I(!0),P(!1),y.current=!1,w(Date.now()),x.current=!0,e&&(v.current=$(e)??"")}return{isDirty:G,draftExists:R,lastSavedAt:B,clearDraft:j,loadDraftContent:U,markDraftSaved:D}}function Ot({isDirty:e,draftExists:a}){const o=e&&!a;i.useEffect(()=>{if(!o)return;const g=m=>{m.preventDefault()};return window.addEventListener("beforeunload",g),()=>window.removeEventListener("beforeunload",g)},[o])}function ee(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const me='{"root":{"direction":"ltr","format":"","indent":0,"version":1,"type":"root","children":[{"direction":"ltr","format":"","indent":0,"version":1,"textFormat":0,"textStyle":"","children":[],"type":"paragraph"}]}}';function fe(e){const o=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(o)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(o)?"不支持的文件类型":/^not an image$/i.test(o)?"不是有效的图片文件":o||"上传失败"}function zt(e,a){if(!e)return a==="json"?me:e;if(a!=="json")return e;try{const o=JSON.parse(e);if(o!=null&&o.root&&Array.isArray(o.root.children)&&o.root.children.length===0)return me}catch{}return e}function pt({editor:e}){const{visible:a}=ht();return n.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:a?200:0},children:n.jsx("div",{style:{width:200},children:n.jsx(yt,{editor:e})})})}function Yt(e){const{t:a,lang:o}=Re(),[g,m]=i.useState(!1),N=i.useRef(null),[L,G]=i.useState([]),[P,R]=i.useState(!1),[I,B]=i.useState(e.meta.permission),[w,u]=i.useState(!1),[f,x]=i.useState(!1),[v,y]=i.useState(!1),[S,F]=i.useState(new Map),[H,_]=i.useState(!1);i.useEffect(()=>{const t=s=>{N.current&&!N.current.contains(s.target)&&m(!1)};return g&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[g]),i.useEffect(()=>{let t=!0;return De().then(s=>{t&&G(s)}).catch(()=>{}),()=>{t=!1}},[]);function C(t){const s=L.find(d=>d.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}const[j,U]=i.useState(e.initialDisplayName),[D,c]=i.useState(!1),[l,b]=i.useState(!1),[T,O]=i.useState(!1),[W,q]=i.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),k=e.canEdit&&W,[r,A]=i.useState(null),[ge,te]=i.useState(!1),K=i.useRef(null);i.useLayoutEffect(()=>{te(!1),A(null),K.current=null},[e.meta.documentId]),i.useEffect(()=>{const t=requestAnimationFrame(()=>te(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]);const M=i.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const s=JSON.parse(e.initialContent);return Array.isArray((t=s==null?void 0:s.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),z=i.useMemo(()=>zt(e.initialContent||"",M),[e.initialContent,M,e.contentRevision]),{isDirty:ne,draftExists:p,markDraftSaved:xe}=_t({editor:r,documentId:e.meta.documentId,displayName:j,enabled:e.canEdit,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}});i.useEffect(()=>{var t;(t=e.onDraftExistsChange)==null||t.call(e,p)},[p,e.onDraftExistsChange]),Ot({isDirty:ne,draftExists:p}),i.useEffect(()=>{if(r)try{r.setDocument(M,z)}catch{}},[r,e.meta.documentId,e.contentRevision,z,M]),i.useEffect(()=>{r==null||r.setLocale(o==="zh"?We:qe)},[r,o]),i.useEffect(()=>{U(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),i.useEffect(()=>{B(e.meta.permission)},[e.meta.permission,e.meta.documentId]),i.useEffect(()=>{let t=!0;return(async()=>{try{const s=await Ae(e.meta.documentId);t&&b(s.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function ae(){var t,s;if(!T){O(!0);try{l?(await pe(e.meta.documentId),b(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Fe(e.meta.documentId),b(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{O(!1)}}}i.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=je),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),i.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=K.current;if(!t)return"";try{const s=t.getDocument("markdown");return typeof s=="string"?s:String(s??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function ve(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const be=i.useCallback(t=>{K.current=t,A(t);const s=z;if(!s)return;const d=()=>{try{t.setDocument(M,s)}catch{requestAnimationFrame(()=>{try{t.setDocument(M,s)}catch{}})}};queueMicrotask(()=>{queueMicrotask(d)})},[M,z]);async function ie(){if(!(!r||!e.canEdit)){c(!0);try{const t=ee(r);if(!t)return;await e.onPublish(t,j,e.meta.documentId)}catch(t){throw t}finally{c(!1)}}}async function ke(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(j.trim()!==t)try{await ie()}catch{}}const E=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),Ie=i.useMemo(()=>{const t=(E==null?void 0:E.permission)??"public";return Pe(t)},[E==null?void 0:E.permission]);function Se(t){return t===V.PRIVATE?a("permissionPrivate"):t===V.DOMAIN_READ?a("permissionInvite"):t===V.DOMAIN_WRITE?a("permissionDomainWrite"):t===V.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function Ce(){var t;if(w||I===e.meta.permission){R(!1);return}u(!0);try{const d=(r?ee(r):null)??e.initialContent;await e.onPublish(d,j,e.meta.documentId,I),R(!1),(t=e.onShowToast)==null||t.call(e,a("docInfoPermissionUpdated"))}finally{u(!1)}}async function we(t){var s;if(!H){_(!0);try{const d=new Set(t.map(h=>h.visitorId)),X=new Map(t.map(h=>[h.visitorId,h.permission]));for(const[h]of S)d.has(h)||await He(e.meta.documentId,h);for(const{visitorId:h,permission:Y}of t){const se=S.get(h);(!se||se!==Y)&&await Ue(e.meta.documentId,h,Y)}x(!1),(s=e.onShowToast)==null||s.call(e,a("docInfoInviteSuccess",{count:t.length}))}finally{_(!1)}}}async function je(){if(!r||!e.canEdit)return;if(!ne){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=ee(r);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),xe(),await he(e.meta.documentId).execute(()=>ye({documentId:e.meta.documentId,content:t,displayName:j,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const Me=i.useMemo(()=>[{icon:gt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(Q,{tag:"h1"})}},{icon:xt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(Q,{tag:"h2"})}},{icon:vt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(Q,{tag:"h3"})}},{type:"divider"},{icon:bt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(Ve,{})}},{icon:kt,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand($e,{columns:"3",rows:"3"})}},{icon:It,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(Je,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{wt(s=>{for(const d of s)t.dispatchCommand(mt,{file:d})})}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(Ge,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(Ke,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(Xe,void 0),queueMicrotask(()=>t.focus())}},{icon:St,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(Ye,void 0),queueMicrotask(()=>t.focus())}},{icon:Ct,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(Qe,void 0),queueMicrotask(()=>t.focus())}}].map(t=>"type"in t&&t.type==="divider"?t:{...t,extra:n.jsx("span",{style:{color:"var(--mdocs-text-muted)",fontFamily:"monospace",fontSize:12},children:t.key})}),[]),Ee=i.useMemo(()=>[Ze,et,tt,de,nt,at,it,st,ot,rt,ct,Z(lt,{children:r?n.jsx(ue,{editor:r,floating:!0,outlineCollapseTitle:a("outlineHide"),outlineExpandTitle:a("outlineShow"),outlineToggle:!0}):null}),Z(ft,{handleUpload:async t=>{var s;try{return{url:await le(t,e.meta.documentId)}}catch(d){throw(s=e.onShowError)==null||s.call(e,fe(d)),d}}}),Z(de,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var s;try{const X=await(await fetch(t)).blob(),h=new File([X],"image.png",{type:X.type});return{url:await le(h,e.meta.documentId)}}catch(d){throw(s=e.onShowError)==null||s.call(e,fe(d)),d}}})],[r,a,e.meta.documentId,e.onShowError]);return n.jsxs("div",{className:"mdocs-editor",children:[n.jsxs("div",{className:"mdocs-editor-toolbar",children:[n.jsx("input",{className:"mdocs-editor-title-input",value:j,onChange:t=>U(t.target.value),onBlur:()=>void ke(),placeholder:a("displayNamePlaceholder"),disabled:!k}),n.jsx(Te,{domains:e.domains.length?e.domains:[Le],value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:t=>ce(t,o,a)}),e.onAiWrite?n.jsxs("button",{type:"button",className:"secondary",onClick:()=>{var t;return(t=e.onAiWrite)==null?void 0:t.call(e)},style:{padding:"4px 10px",whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",gap:6},children:[n.jsx("img",{src:Be,alt:"",width:16,height:16,style:{display:"block"}}),"帮写"]}):null,n.jsxs("button",{type:"button",className:"secondary mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>void ae(),disabled:T,"data-tooltip":l?"取消收藏":"收藏",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,opacity:T?.5:1},children:[n.jsx(_e,{size:18,strokeWidth:1.5,style:{color:l?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:l?"#faad14":"none"}}),l&&n.jsx("span",{children:"已收藏"})]}),n.jsx("span",{className:"mdocs-editor-toolbar-spacer","aria-hidden":!0}),n.jsxs("div",{className:"mdocs-editor-toolbar-actions",children:[e.onSyncClick&&n.jsxs("button",{type:"button",className:"mdocs-sync-btn mdocs-tooltip mdocs-tooltip-bottom"+(e.syncBehind?" behind":""),"data-tooltip":e.syncBehind?a("syncBehindHint"):a("syncPull"),onClick:()=>{var t;return void((t=e.onSyncClick)==null?void 0:t.call(e))},style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx(Et,{size:16,strokeWidth:1.5}),n.jsx("span",{children:a("syncPull")})]}),k?n.jsxs(n.Fragment,{children:[localStorage.getItem("mdocs.autoPublish")!=="true"&&n.jsxs("span",{className:"mdocs-save-indicator",children:[n.jsx("span",{className:"mdocs-save-dot "+(D?"saving":p?"unsaved":"saved")}),n.jsx("span",{children:a(D?"publishing":p?"unsaved":"published")})]}),n.jsx("button",{type:"button",className:"primary",disabled:D,onClick:()=>{ie().catch(()=>{})},children:a(D?"publishing":"publish")}),n.jsx("button",{type:"button",className:"danger",disabled:D,onClick:e.onDelete,children:a("delete")})]}):e.canEdit&&n.jsx("button",{type:"button",className:"primary",onClick:()=>q(!0),children:a("edit")}),n.jsxs("button",{type:"button",className:"secondary mdocs-tooltip mdocs-tooltip-bottom",onClick:e.onToggleComments,"data-tooltip":"评论",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:e.commentPanelOpen?"var(--mdocs-hover-bg, #f0f0f0)":void 0},children:[n.jsx(Oe,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}}),e.commentCount>0&&n.jsx("span",{style:{fontSize:"0.85rem"},children:e.commentCount})]}),n.jsxs("div",{ref:N,className:"mdocs-tooltip mdocs-tooltip-bottom","data-tooltip":a("docInfo"),style:{position:"relative"},children:[n.jsx("button",{type:"button",className:"secondary",onClick:()=>m(!g),style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx(At,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}})}),g&&n.jsxs("div",{style:{position:"absolute",top:"100%",right:0,marginTop:"4px",background:"var(--mdocs-surface, #fff)",border:"1px solid var(--mdocs-border, #e5e5e5)",borderRadius:"8px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)",minWidth:"220px",zIndex:100,padding:"8px 0"},children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreator")}),n.jsx("span",{children:C(e.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreatedAt")}),n.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(o==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:ve(new Blob([e.initialContent]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(o==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),n.jsxs("button",{type:"button",style:{width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:t=>{t.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:t=>{t.currentTarget.style.background="none"},onClick:()=>{ae()},children:[n.jsx("span",{children:l?"⭐":"☆"}),n.jsx("span",{children:a(l?"bookmarkRemove":"bookmarkAdd")})]}),e.canManageInvites&&n.jsxs("button",{type:"button",style:{width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:t=>{t.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:t=>{t.currentTarget.style.background="none"},onClick:()=>{m(!1),(async()=>{y(!0);try{const t=await ze(e.meta.documentId),s=new Map(t.map(d=>[d.visitorId,d.permission]));F(s),x(!0)}finally{y(!1)}})()},children:[n.jsx(Tt,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}),n.jsxs("button",{type:"button",style:{width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:t=>{t.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:t=>{t.currentTarget.style.background="none"},onClick:()=>{m(!1),B(e.meta.permission),R(!0)},children:[n.jsx(Rt,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})]})]})]}),P&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&R(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",E?ce(E.domainName,o,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:Ie.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"doc-permission",value:t,checked:I===t,onChange:()=>B(t)}),n.jsx("span",{children:Se(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>R(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:w,onClick:()=>void Ce(),children:a(w?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(jt,{open:f,title:a("docInfoInviteMember"),initialSelectedIds:[...S.keys()],initialPermissions:S,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>x(!1),onConfirm:t=>{we(t)}}),n.jsx(dt,{children:n.jsx(oe,{flex:1,style:{minHeight:0},children:n.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[k&&r&&n.jsx(ue,{editor:r,outlineCollapseTitle:a("outlineHide"),outlineExpandTitle:a("outlineShow"),outlineToggle:!0}),n.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:n.jsxs(oe,{variant:"outlined",horizontal:!0,style:{background:"var(--mdocs-surface)",flex:1,minHeight:0,minWidth:0,borderRadius:0,outline:"none"},children:[n.jsx("div",{className:"mdocs-editor-scroll-host",children:ge?n.jsx(ut,{content:z,type:M,confirmPasteMarkdown:!0,editable:k,onInit:be,plugins:Ee,lineEmptyPlaceholder:a("displayNamePlaceholder"),placeholder:a("displayNamePlaceholder"),slashOption:{items:Me},className:"mdocs-document-editor-root"},e.meta.documentId):null}),r&&n.jsx(pt,{editor:r})]})})]})})})]})}export{Yt as DocumentEditor};
@@ -1 +0,0 @@
1
- import{r as a,j as e}from"./react-vendor-BNpqFP9B.js";import{b as Z,q as We,s as Ue,D as _e,l as ce,t as He,v as qe,w as _,x as le,y as Ge,z as Ze,A as Je,a as Qe,d as Ne,B as ve,C as ke,E as Xe,G as Ye,H as es,I as ss,J as ts,K as we,L as ne,N as as,O as ns,P as is,Q as cs,R as ls,f as rs,T as os,U as ds,V as ms,W as us,X as hs,i as gs,Y as ps,Z as fs,_ as xs,$ as js,a0 as Ns,a1 as ys,a2 as bs,a3 as vs,a4 as ks,a5 as ws,a6 as Ss,a7 as Cs,a8 as Ds,r as Is,j as Ts,a9 as As,n as Es,o as Ps}from"./index-B-XJ-ScV.js";import{V as Se,a as Ms,M as Ls}from"./VisitorPickerModal-COxtOvc4.js";import"./ui-C3xtW1w8.js";import"./motion-D-I76zAi.js";function Rs({draft:t,onClose:s,onSuccess:k}){const{t:h,lang:g}=Z(),[M,r]=a.useState([]),[y,b]=a.useState(t.domainId??""),[C,i]=a.useState([]),[N,f]=a.useState(""),[d,j]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[u,z]=a.useState(!1),[T,R]=a.useState(null),I=a.useRef(null),A=a.useRef(!0);a.useEffect(()=>(A.current=!0,()=>{A.current=!1}),[]),a.useEffect(()=>{We().then(x=>{A.current&&r(x)})},[]),a.useEffect(()=>{y&&(i([]),f(""),Ue(y).then(x=>{A.current&&i(x)}).catch(()=>{A.current&&i([])}))},[y]),a.useEffect(()=>{const x=window.setTimeout(()=>{var P;return(P=I.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(x)},[]),a.useEffect(()=>{const x=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[s]);function B(x,P){for(const v of x){if(v.type==="folder"&&v.path===P)return v.documentId;if(v.type==="folder"){const S=B(v.children,P);if(S)return S}}return null}async function E(x){x.preventDefault(),z(!0),R(null);const P=d.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),v=P.endsWith(".md")?P:P+".md",S=v.replace(/\.md$/i,"");try{const l=N?`${N}/${v}`:v,c=N?B(C,N)??void 0:void 0;await qe({fileName:v,displayName:S,content:t.content,domainId:y,parentId:c}),k()}catch(l){R(_(h,l))}finally{z(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:x=>{x.target===x.currentTarget&&!u&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:h("recoverDraft")}),e.jsx("p",{className:"muted",children:h("recoverDraftDesc",{name:t.displayName||h("unknownTitle")})}),e.jsxs("form",{onSubmit:E,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[h("domainLabel"),M.length>0&&e.jsx(_e,{domains:M,value:y,onChange:b,onDomainsChange:r,ariaLabel:h("domainLabel"),localizeName:x=>ce(x,g,h)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[h("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(He,{nodes:C,activeDocumentId:null,selectedParentPath:N,onOpen:()=>{},onOpenFolder:x=>f(x),onContextMenu:()=>{},onDeselect:()=>f("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[h("fileNameLabel"),e.jsx("input",{ref:I,value:d,onChange:x=>j(x.target.value),placeholder:"recovered.md",maxLength:200,disabled:u})]}),T&&e.jsx("div",{className:"mdocs-dialog-error",children:T}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!u&&s(),disabled:u,children:h("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:u,children:h(u?"creating":"create")})]})]})]})})}function zs({onPublish:t,onClose:s,onCountChange:k,onRecover:h}){const{t:g}=Z(),[M,r]=a.useState([]),[y,b]=a.useState(new Set),[C,i]=a.useState(!1),[N,f]=a.useState(null),[d,j]=a.useState(null),[u,z]=a.useState(null),T=a.useRef(null),R=a.useRef(!0);a.useEffect(()=>(R.current=!0,le().then(c=>{if(!R.current)return;const m=c.filter(w=>!w.published);r(m),k==null||k(m.length)}),()=>{R.current=!1,T.current&&(clearTimeout(T.current),T.current=null)}),[]),a.useEffect(()=>{const c=m=>{m.key==="Escape"&&s()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s]);const I=a.useCallback((c,m)=>{z({message:c,type:m}),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>z(null),3e3)},[]);async function A(c){await Ze(c),b(m=>new Set(m).add(c));try{await t(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),I(g("published"),"success")}catch(m){m instanceof Je||I(g("publishFailed"),"error");const w=await Qe(c);w&&r(F=>F.map(K=>K.documentId===c?w:K))}finally{b(m=>{const w=new Set(m);return w.delete(c),w})}}async function B(c){f(null),await Ne(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),I(g("draftDeleted"),"success")}function E(c){const m=M.find(w=>w.documentId===c);m&&j(m)}function x(c){j(null),Ne(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),h==null||h(M.find(m=>m.documentId===c)),I(g("published"),"success")}async function P(){i(!0);let c=0,m=0;for(const K of M)try{await t(K.documentId),c++}catch{m++}const F=(await le()).filter(K=>!K.published);r(F),k==null||k(F.length),m===0?I(g("publishAll"),"success"):I(`${c} published, ${m} failed`,"error"),i(!1)}const v=c=>new Date(c).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),S=c=>Ge(g,c,c.publishError??"UNKNOWN"),l=M;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-drawer-overlay",onClick:s}),e.jsxs("div",{className:"mdocs-drawer",role:"dialog","aria-modal":"true",children:[e.jsxs("header",{className:"mdocs-drawer-header",children:[e.jsxs("div",{className:"mdocs-drawer-header-text",children:[e.jsxs("h2",{className:"mdocs-drawer-title",children:[g("unpublishedDrafts"),l.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:l.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:g("draftCount",{count:String(l.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":g("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:l.length===0?e.jsxs("div",{className:"mdocs-drawer-empty",children:[e.jsx("div",{className:"mdocs-drawer-empty-icon","aria-hidden":"true",children:"✓"}),e.jsx("p",{className:"mdocs-drawer-empty-text",children:g("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:l.map(c=>{const m=!!c.publishError;return e.jsxs("div",{className:m?"mdocs-drawer-item mdocs-drawer-item-failed":"mdocs-drawer-item",children:[e.jsx("div",{className:"mdocs-drawer-item-icon","aria-hidden":"true",children:"📄"}),e.jsxs("div",{className:"mdocs-drawer-item-info",children:[e.jsx("span",{className:"mdocs-drawer-item-name",children:c.displayName||g("unknownTitle")}),m?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[v(c.publishErrorAt)," · ",S(c)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[v(c.updatedAt)," · ",g("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[m?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:C,onClick:()=>E(c.documentId),children:g("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:y.has(c.documentId)||C,onClick:()=>void A(c.documentId),children:y.has(c.documentId)?g("publishing"):g("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:C,onClick:()=>f(c.documentId),children:g("delete")})]})]},c.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:g("close")}),e.jsx("button",{type:"button",className:"primary",disabled:l.length===0||C,onClick:()=>void P(),children:C?g("publishing"):`${g("publishAll")} (${l.length})`})]}),u&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+u.type,role:"status",children:u.message})]}),N&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:c=>{c.target===c.currentTarget&&f(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:g("delete")}),e.jsx("p",{className:"muted",children:g("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>f(null),children:g("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void B(N),children:g("delete")})]})]})}),d&&e.jsx(Rs,{draft:d,onClose:()=>j(null),onSuccess:()=>x(d.documentId)})]})}function Bs(){const{t,lang:s}=Z(),k=ve(),h=a.useRef(!1),[g,M]=a.useState([]),[r,y]=a.useState(!1),[b,C]=a.useState(""),[i,N]=a.useState("restricted"),[f,d]=a.useState(!1),[j,u]=a.useState(null),[z,T]=a.useState(null),[R,I]=a.useState(""),[A,B]=a.useState(""),[E,x]=a.useState("all"),[P,v]=a.useState(null);a.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const S=a.useCallback(async()=>{y(!0),u(null);try{const p=await ke();if(!h.current)return;M(p)}catch(p){if(!h.current)return;u(_(t,p))}finally{h.current&&y(!1)}},[t]);a.useEffect(()=>{S()},[S]);async function l(p){if(p.preventDefault(),!b.trim()){u(t("domainNameRequired"));return}d(!0),u(null);try{if(await ts({domainName:b.trim(),permission:i}),!h.current)return;C(""),N("restricted"),await S()}catch(V){if(!h.current)return;u(_(t,V))}finally{h.current&&d(!1)}}async function c(p){if(R.trim()){u(null);try{if(await ss(p,R.trim()),!h.current)return;T(null),v(null),await S()}catch(V){if(!h.current)return;u(_(t,V))}}}function m(p){T(p.domainId),I(p.domainName),v(null)}function w(){T(null),v(null)}async function F(p,V){u(null);try{if(await es(p,V),!h.current)return;v(null),await S()}catch($){if(!h.current)return;u(_(t,$))}}async function K(p){if(window.confirm(t("deleteDomainConfirmDetail",{name:p.domainName,count:String(p.docCount)}))){u(null);try{if(await Ye(p.domainId),!h.current)return;await S()}catch(V){if(!h.current)return;u(_(t,V))}}}const H=a.useCallback(p=>Xe(p,t),[t]),q=a.useCallback(p=>ce(p.domainName,s,t),[s,t]),G=a.useMemo(()=>{const p=A.trim().toLowerCase();return g.filter(V=>E!=="all"&&V.permission!==E?!1:p?ce(V.domainName,s,t).toLowerCase().includes(p)||V.domainName.toLowerCase().includes(p):!0)},[g,A,E,s,t]),D=a.useCallback((p,V)=>{const $=H(p.permission);return V?`${$} ${t("domainTypeBuiltinSuffix")}`:$},[H,t]);return{domains:g,loadingDomains:r,domainError:j,newDomainName:b,setNewDomainName:C,newDomainPermission:i,setNewDomainPermission:N,creating:f,handleCreateDomain:l,renamingId:z,setRenamingId:T,renameDraft:R,setRenameDraft:I,startRename:m,cancelRename:w,handleRename:c,changeTypeForId:P,setChangeTypeForId:v,handlePermissionChange:F,handleDelete:K,domainSearch:A,setDomainSearch:B,domainFilter:E,setDomainFilter:x,filteredDomains:G,visitorId:k,plabel:H,localizeDomain:q,domainTypeLabel:D}}function Fs(){const{t}=Z(),s=Bs(),[k,h]=a.useState([]),[g,M]=a.useState(null),[r,y]=a.useState(null),b=a.useCallback(async()=>{try{const i=await we();h(i)}catch{h([])}},[]);a.useEffect(()=>{b()},[b]);async function C(i){M(null);try{const N=await ls(i.domainId);y({domainId:i.domainId,creatorVisitorId:i.creatorVisitorId,initialIds:N.map(f=>f.visitorId),memberRows:N})}catch(N){M({kind:"err",text:_(t,N)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:t("domainManagement")})}),e.jsx("p",{className:"mdocs-domain-mgmt-restricted-hint",children:t("domainMgmtRestrictedMemberHint")}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-create",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("createDomain")}),e.jsxs("form",{onSubmit:s.handleCreateDomain,className:"mdocs-domain-mgmt-create-form",children:[e.jsxs("label",{className:"mdocs-domain-mgmt-field",children:[e.jsx("span",{className:"mdocs-domain-mgmt-label",children:t("domainName")}),e.jsx("input",{value:s.newDomainName,onChange:i=>s.setNewDomainName(i.target.value),placeholder:t("domainName"),maxLength:100,disabled:s.creating,className:"mdocs-domain-name-input"})]}),e.jsxs("fieldset",{className:"mdocs-domain-mgmt-fieldset",children:[e.jsx("legend",{className:"mdocs-domain-mgmt-label",children:t("domainPermission")}),e.jsx("div",{className:"mdocs-domain-mgmt-type-radios",children:ne.map(i=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===i,onChange:()=>s.setNewDomainPermission(i),disabled:s.creating}),e.jsx("span",{children:s.plabel(i)})]},i))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?t("creating"):t("create")})]})]}),g&&e.jsx("div",{className:"mdocs-settings-card",style:{color:g.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:g.text})}),s.domainError&&e.jsx("div",{className:"mdocs-settings-card mdocs-domain-error",children:e.jsx("span",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)"},children:s.domainError})}),e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-toolbar",children:[e.jsx("input",{type:"search",value:s.domainSearch,onChange:i=>s.setDomainSearch(i.target.value),placeholder:t("domainSearchPlaceholder"),className:"mdocs-domain-mgmt-search","aria-label":t("domainSearchPlaceholder")}),e.jsx("div",{className:"mdocs-domain-mgmt-filters",role:"group","aria-label":t("domainPermission"),children:["all",...ne].map(i=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===i?" active":""),"aria-pressed":s.domainFilter===i,onClick:()=>s.setDomainFilter(i),children:i==="all"?t("domainFilterAll"):s.plabel(i)},i))})]}),s.loadingDomains?e.jsx("div",{className:"mdocs-settings-card",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")})}):s.domains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("noDomains")})}):s.filteredDomains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("domainNoMatch")})}):e.jsx("div",{className:"mdocs-settings-card mdocs-domain-table-wrap",children:e.jsxs("table",{className:"mdocs-domain-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:t("domainColName")}),e.jsx("th",{scope:"col",children:t("domainColType")}),e.jsx("th",{scope:"col",className:"mdocs-domain-table-num",children:t("domainColDocCount")}),e.jsx("th",{scope:"col",children:t("domainColActions")})]})}),e.jsx("tbody",{children:s.filteredDomains.map(i=>{const N=as(i,s.visitorId),f=ns(i.domainId),d=is(i),j=d?t("domainTooltipTypeLocked",{count:String(i.docCount)}):void 0;return e.jsxs("tr",{className:f?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===i.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:u=>s.setRenameDraft(u.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(i.domainId),children:t("save")}),e.jsx("button",{type:"button",onClick:s.cancelRename,children:t("cancel")})]}):e.jsxs("div",{className:"mdocs-domain-table-name-cell",children:[e.jsx("span",{className:"mdocs-domain-table-name",children:s.localizeDomain(i)}),f&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!N&&!f&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsxs("span",{className:"mdocs-domain-table-type",title:j,children:[e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":i.permission,children:s.domainTypeLabel(i,f)}),d&&!f&&e.jsx("span",{className:"mdocs-domain-type-lock","aria-hidden":"true",children:"🔒"})]})}),e.jsx("td",{className:"mdocs-domain-table-num",children:i.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[f&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!f&&!N&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!f&&N&&s.changeTypeForId===i.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",children:[e.jsx("div",{className:"mdocs-domain-permission-select",children:ne.map(u=>e.jsx("button",{type:"button",className:i.permission===u?"active":"",onClick:()=>void s.handlePermissionChange(i.domainId,u),children:s.plabel(u)},u))}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>s.setChangeTypeForId(null),children:t("cancel")})]}),!f&&N&&s.renamingId!==i.domainId&&s.changeTypeForId!==i.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[e.jsx("button",{type:"button",className:"secondary",title:d?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(i)},disabled:d,children:t("rename")}),e.jsx("button",{type:"button",className:"secondary",title:d?j:void 0,onClick:()=>{s.setRenamingId(null),s.setChangeTypeForId(i.domainId)},disabled:d,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"secondary",title:d?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(i),disabled:d,children:t("deleteDomain")}),i.permission==="restricted"&&!f&&e.jsx("button",{type:"button",className:"secondary",onClick:()=>void C(i),children:t("domainMembersManageButton")})]})]})]},i.domainId)})})]})})]}),e.jsx(Se,{open:r!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(r==null?void 0:r.initialIds)??[],lockedIds:r?[r.creatorVisitorId]:[],seedMembers:r==null?void 0:r.memberRows,templates:k,onClose:()=>y(null),onConfirm:async i=>{r&&(await cs(r.domainId,i),M({kind:"ok",text:t("domainMembersSaved",{count:String(i.length)})}))}})]})}function ye(t){return t.length<=6?t:`${t.slice(0,6)}…`}function Os(){const{t}=Z(),s=a.useRef(!0),[k,h]=a.useState([]),[g,M]=a.useState(!0),[r,y]=a.useState(null),[b,C]=a.useState(1),[i,N]=a.useState(null),[f,d]=a.useState(""),[j,u]=a.useState([]),[z,T]=a.useState(!1),[R,I]=a.useState(null),[A,B]=a.useState(!1),E=ve(),[x,P]=a.useState([]),[v,S]=a.useState("idle"),[l,c]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{S("loading"),rs().then(o=>{s.current&&(P(o),S("ok"))}).catch(()=>{s.current&&S("err")})},[]);const m=a.useMemo(()=>{const o=new Map;for(const L of x)o.set(L.visitorId,L.visitorName);return o},[x]),w=a.useCallback(async()=>{M(!0),I(null);try{const o=await we();s.current&&h(o)}catch(o){s.current&&I(_(t,o))}finally{s.current&&M(!1)}},[t]);a.useEffect(()=>{w()},[w]);const F=a.useMemo(()=>j.map(o=>{const L=x.find(W=>W.visitorId===o);return{visitorId:o,name:L?L.visitorName:t("visitorPickerUnknownVisitor"),muted:!L}}),[j,x,t]);function K(o){u(L=>L.includes(o)?L.filter(W=>W!==o):[...L,o])}const H=b===1?f.trim().length>0:b===2?j.length>0:!0;function q(){if(!(b>=3)){if(!H){B(!0);return}B(!1),C(b+1),c("")}}function G(){b<=1||(B(!1),C(b-1))}function D(){y(null),N(null),d(""),u(E?[E]:[]),I(null),C(1),c(""),B(!1)}function p(o){y(null),N(o.id),d(o.displayName);const L=E&&!o.visitorIds.includes(E)?[...o.visitorIds,E]:[...o.visitorIds];u(L),I(null),C(1),c(""),B(!1)}async function V(){if(!(!f.trim()||j.length===0)){T(!0),I(null);try{if(i===null?await os({displayName:f.trim(),visitorIds:j}):await ds(i,{displayName:f.trim(),visitorIds:j}),!s.current)return;D(),await w()}catch(o){if(!s.current)return;I(_(t,o))}finally{s.current&&T(!1)}}}async function $(o){T(!0),I(null);try{if(await ms(o),!s.current)return;y(null),i===o&&D(),await w()}catch(L){if(!s.current)return;I(_(t,L))}finally{s.current&&T(!1)}}const Q=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],ee=`${(b-1)/2*100}%`;return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:t(i!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),i!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:D,style:{fontSize:12},children:t("memberTemplateCancelEdit")})]}),e.jsxs("div",{className:"mdocs-wizard-progress",children:[e.jsx("div",{className:"mdocs-wizard-progress-track",children:e.jsx("div",{className:"mdocs-wizard-progress-fill",style:{width:ee}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:Q.map(o=>{const L=b===o.key,W=b>o.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${L?" current":""}${W?" done":""}`,children:W?"✓":o.key}),e.jsx("span",{className:`mdocs-wizard-step-label${L?" current":""}${W?" done":""}`,children:o.label})]},o.key)})})]}),R&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:R}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[b===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:f,onChange:o=>d(o.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:z,autoFocus:!0,"aria-invalid":A&&!f.trim()}),A&&!f.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),b===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Ms,{visitors:x,loadState:v,searchFilter:l,onSearchChange:c,selectedIds:new Set(j),onToggle:K,selectedRows:F,myVisitorId:E}),e.jsx("p",{className:`mdocs-wizard-hint${A&&j.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),b===3&&e.jsx("div",{className:"mdocs-wizard-step-content",children:e.jsxs("div",{className:"mdocs-wizard-preview-card",children:[e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:f})]}),e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateIdsLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:t("memberTemplateSelectedSummary",{count:String(j.length)})})]}),j.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[j.slice(0,15).map(o=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:ye(o)},o)),j.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",j.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:G,children:["← ",t("memberTemplateWizardBack")]}),b<3?e.jsxs("button",{type:"button",className:"primary",onClick:q,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void V(),children:t(z?"saving":i===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),g?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):k.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),i===null&&e.jsx("button",{type:"button",className:"primary",onClick:D,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:k.map(o=>e.jsx("li",{className:"mdocs-member-template-row",children:r===o.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:t("memberTemplateConfirmDeleteDesc",{name:o.displayName})}),e.jsxs("div",{className:"mdocs-member-template-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",style:{color:"var(--mdocs-danger)"},onClick:()=>void $(o.id),children:t(z?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>y(null),children:t("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:o.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateCount",{count:String(o.visitorIds.length)})}),o.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:o.visitorIds.map(L=>e.jsx("span",{className:"mdocs-member-template-tag",children:m.get(L)??ye(L)},L))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>p(o),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>y(o.id),children:t("memberTemplateDelete")})]})]})},o.id))})]})]})]})}const Vs=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}];function Ks(){const{t}=Z(),s=a.useRef(!0),[k,h]=a.useState(""),[g,M]=a.useState(null),[r,y]=a.useState(""),[b,C]=a.useState("deepseek-v4-flash"),[i,N]=a.useState(128e3),[f,d]=a.useState(""),[j,u]=a.useState(!1),[z,T]=a.useState(null),[R,I]=a.useState(!0),[A,B]=a.useState(!1),[E,x]=a.useState(null),[P,v]=a.useState(!1),[S,l]=a.useState(!1),[c,m]=a.useState(!1),[w,F]=a.useState(null);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const[D,p]=await Promise.all([us(),hs()]);if(!s.current)return;h(D.visitorName),p?(M(p.id),y(p.name),C(p.modelId),N(p.contextWindow||128e3),u(p.hasApiKey),T(p.apiKeyMasked),l(!1)):l(!0)}catch(D){if(!s.current)return;x(D instanceof Error?D.message:String(D)),l(!0)}finally{s.current&&I(!1)}})()},[]);function K(){F({name:r,modelId:b,contextWindow:i}),d(""),m(!1),v(!1),x(null),l(!0)}function H(){w&&(y(w.name),C(w.modelId),N(w.contextWindow)),d(""),m(!1),x(null),v(!1),l(!1),F(null)}async function q(){B(!0),x(null),v(!1);try{const D={modelId:b,name:r,contextWindow:i};f.trim()&&(D.apiKey=f.trim());const p=await ps(D);if(!s.current)return;M(p.id),y(p.name),C(p.modelId),N(p.contextWindow||128e3),u(p.hasApiKey),T(p.apiKeyMasked),d(""),m(!1),v(!0),l(!1),F(null)}catch(D){if(!s.current)return;x(D instanceof Error?D.message:String(D))}finally{s.current&&B(!1)}}const G=t("agentConfigNameDefault").replace("{{name}}",k||"…");return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title mdocs-agent-config-title",children:[e.jsx("img",{src:gs,alt:"DeepSeek",className:"mdocs-agent-config-logo"}),t("agentConfig")]}),!R&&g&&!S?e.jsx("button",{type:"button",className:"secondary",onClick:K,children:t("edit")}):null]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("agentConfigDesc")}),R?e.jsx("p",{children:t("loading")}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-settings-item",style:{display:"block",marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigName")}),e.jsx("input",{type:"text",value:r,onChange:D=>y(D.target.value),placeholder:G,disabled:!S,style:{width:"100%",marginTop:6}})]}),e.jsxs("div",{className:"mdocs-settings-item mdocs-agent-config-field",style:{marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigModel")}),S?e.jsx("div",{className:"mdocs-agent-config-select",children:e.jsx(Ls,{options:Vs,value:b,onChange:D=>C(D)})}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:b})]}),e.jsxs("label",{className:"mdocs-settings-item",style:{display:"block",marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigContextWindow")}),e.jsx("p",{className:"mdocs-settings-item-desc",style:{margin:"4px 0 6px"},children:t("agentConfigContextWindowDesc")}),S?e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:i,onChange:D=>N(Number(D.target.value)||128e3),style:{width:"100%"}}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:i})]}),e.jsxs("div",{className:"mdocs-settings-item mdocs-agent-config-field",style:{marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigApiKey")}),S?e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:c?"text":"password",value:f,onChange:D=>d(D.target.value),placeholder:j?t("agentConfigApiKeyConfigured").replace("{{masked}}",z??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(c?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>m(D=>!D),children:c?e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M3 3l18 18"}),e.jsx("path",{d:"M10.6 10.6a2 2 0 002.8 2.8"}),e.jsx("path",{d:"M9.9 5.1A10.5 10.5 0 0121 12c-.6 1.1-1.4 2.1-2.4 2.9"}),e.jsx("path",{d:"M6.1 6.1C4.5 7.4 3.2 9.1 2.5 12c1.5 3.5 5 7 9.5 7 1.4 0 2.7-.3 3.9-.8"})]}):e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M2.5 12C4 8.5 7.5 5 12 5s8 3.5 9.5 7c-1.5 3.5-5 7-9.5 7s-8-3.5-9.5-7z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:j?z??"…":t("agentConfigApiKeyPlaceholder")})]}),g?e.jsxs("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:[t("agentConfigId"),": ",g]}):null,E?e.jsx("p",{style:{color:"var(--mdocs-danger, #c00)",marginBottom:12},children:E}):null,P&&!S?e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("saved")}):null,S?e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void q(),disabled:A,children:t(A?"saving":"save")}),g?e.jsx("button",{type:"button",className:"secondary",onClick:H,disabled:A,children:t("cancel")}):null]}):null]})]})})]})}const $s=/^[A-Za-z0-9_]+$/;function ie(t){return $s.test(t.trim())}function Ws(){const t=a.useRef(!0),[s,k]=a.useState([]),[h,g]=a.useState(!0),[M,r]=a.useState(null),[y,b]=a.useState(null),[C,i]=a.useState(!1),[N,f]=a.useState(""),[d,j]=a.useState(""),[u,z]=a.useState(""),[T,R]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function I(){g(!0),r(null);try{const l=await fs();if(!t.current)return;k(l)}catch(l){if(!t.current)return;r(l instanceof Error?l.message:String(l))}finally{t.current&&g(!1)}}a.useEffect(()=>{I()},[]);function A(){i(!0),b(null),f(""),j(""),z(""),r(null)}function B(l){i(!1),b(l.id),f(l.name),j(l.description),z(l.body),r(null)}function E(){i(!1),b(null),f(""),j(""),z("")}async function x(){const l=N.trim();if(!ie(l)){r("名称仅允许英文、数字、下划线");return}if(!u.trim()){r("正文不能为空");return}R(!0),r(null);try{if(C?await xs({name:l,description:d,body:u}):y&&await js(y,{name:l,description:d,body:u}),!t.current)return;E(),await I()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}finally{t.current&&R(!1)}}async function P(l){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){r(null);try{if(await Ns(l),!t.current)return;y===l&&E(),await I()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}}}const v=C||y!==null,S=!N.trim()||ie(N);return e.jsxs("div",{className:"mdocs-settings mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!h&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),v?null:e.jsx("button",{type:"button",className:"secondary",onClick:A,children:"新建"})]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc mdocs-agent-skills-lead",children:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),M?e.jsx("p",{className:"mdocs-agent-skills-error",children:M}):null,v?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:C?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:N,onChange:l=>f(l.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:S?void 0:"mdocs-agent-skills-input-invalid"}),S?e.jsx("span",{className:"mdocs-agent-skills-hint",children:"引用与索引键,保存后按此名称使用"}):e.jsx("span",{className:"mdocs-agent-skills-hint-bad",children:"仅允许 A–Z、a–z、0–9、_"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"简介(可选)"}),e.jsx("input",{type:"text",value:d,onChange:l=>j(l.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:u,onChange:l=>z(l.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void x(),disabled:T||!S||!N.trim()||!u.trim(),children:T?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:E,disabled:T,children:"取消"})]})]}):null,h?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!h&&s.length===0&&!v?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:A,children:"新建第一个"})]}):null,!h&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(l=>{const c=ie(l.name),m=y===l.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(m?" mdocs-agent-skills-item-active":""),children:[e.jsxs("div",{className:"mdocs-agent-skills-item-main",children:[e.jsxs("div",{className:"mdocs-agent-skills-item-title-row",children:[e.jsx("code",{className:"mdocs-agent-skills-name",children:l.name}),c?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:l.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>B(l),disabled:v&&!m,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(l.id),disabled:v,children:"删除"})]})]},l.id)})}):null]})})]})}function be(t,s){const k=localStorage.getItem(t);return k===null?s:k==="true"}function Zs(t){const{t:s,lang:k,setLang:h}=Z(),{onBack:g,onPublishDraft:M}=t,r=a.useRef(!0);a.useEffect(()=>(r.current=!0,()=>{r.current=!1}),[]);const[y,b]=a.useState(()=>be("mdocs.autoPublish",!1)),[C,i]=a.useState(()=>be("mdocs.autoEdit",!0)),[N,f]=a.useState(!1),[d,j]=a.useState("general"),[u,z]=a.useState([]),[T,R]=a.useState(!0),[I,A]=a.useState(null),[B,E]=a.useState(!1),[x,P]=a.useState(!1),[v,S]=a.useState(!1),[l,c]=a.useState(!1),[m,w]=a.useState(null),[F,K]=a.useState(!1),[H,q]=a.useState(!1),[G,D]=a.useState(!1),[p,V]=a.useState(""),[$,Q]=a.useState(!1),[ee,o]=a.useState(!1),[L,W]=a.useState(0),[Ce,re]=a.useState([]),[De,oe]=a.useState(!1),[X,Ie]=a.useState(""),[Te,Ae]=a.useState([]),[Ee,de]=a.useState(!1),[Y,Pe]=a.useState(""),[Me,Le]=a.useState([]),[Re,se]=a.useState(!1),[te,me]=a.useState(null),[ae,ue]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(y))},[y]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(C))},[C]),a.useEffect(()=>{d==="savePublish"&&le().then(n=>{r.current&&W(n.filter(O=>!O.published).length)})},[d]),a.useEffect(()=>{d==="bookmarks"&&ze(),d==="myDocuments"&&pe()},[d]),a.useEffect(()=>{ge()},[]),a.useEffect(()=>{ke().then(n=>{r.current&&Le(n)}).catch(()=>{})},[]);const he=new Map(Me.map(n=>[n.domainId,n.domainName]));async function ge(){try{R(!0);const n=await ys();if(!r.current)return;z(n)}catch{}finally{r.current&&R(!1)}}async function ze(){try{oe(!0);const n=await bs();if(!r.current)return;re(n)}catch{}finally{r.current&&oe(!1)}}async function pe(){try{de(!0);const n=await vs();if(!r.current)return;Ae(n)}catch{}finally{r.current&&de(!1)}}async function Be(n){try{await Is(n),re(O=>O.filter(J=>J.documentId!==n))}catch{}}function Fe(){if(u.some(O=>!O.revoked)){P(!0);return}fe()}async function fe(){try{E(!0);const n=await As();A({token:n.token,name:n.name}),await ge()}finally{E(!1)}}async function Oe(){try{D(!0);const n=await Cs();w(n.recoveryCode)}finally{D(!1)}}async function Ve(n){n.preventDefault();const O=p.trim();if(!(O&&O.length<4))try{Q(!0),await Ds(O),V(""),o(!0),setTimeout(()=>o(!1),3e3)}finally{Q(!1)}}async function Ke(n){me(n);try{const O=await Ts(n),J=new Map;O.forEach(U=>{J.set(U.visitorId,U.permission)}),ue(J)}catch{ue(new Map)}se(!0)}async function $e(n){if(te)try{const O=new Set(n.map(U=>U.visitorId)),J=new Set(ae.keys());for(const U of J)O.has(U)||await Es(te,U);for(const U of n)await Ps(te,U.visitorId,U.permission);await pe()}finally{se(!1),me(null)}}const xe=Ce.filter(n=>{if(!X.trim())return!0;const O=X.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(O)||(n.ownerVisitorName||"").toLowerCase().includes(O)||(n.domainId||"").toLowerCase().includes(O)}),je=Te.filter(n=>{if(!Y.trim())return!0;const O=Y.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(O)||(n.domainId||"").toLowerCase().includes(O)});return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"mdocs-sidebar",children:[e.jsx("header",{className:"mdocs-sidebar-header",children:e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:ks,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]})}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(d==="general"?" active":""),onClick:()=>j("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(d==="bookmarks"?" active":""),onClick:()=>j("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(d==="myDocuments"?" active":""),onClick:()=>j("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(d==="domainManagement"?" active":""),onClick:()=>j("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(d==="memberTemplates"?" active":""),onClick:()=>j("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(d==="agentConfig"?" active":""),onClick:()=>j("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(d==="savePublish"?" active":""),onClick:()=>j("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:g,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[ws(),d==="general"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("general")})}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsx("span",{className:"mdocs-settings-item-info",children:e.jsx("span",{className:"mdocs-settings-card-title",children:s("language")})}),e.jsxs("span",{className:"mdocs-settings-lang",children:[e.jsx("button",{type:"button",className:k==="en"?"active":"",onClick:()=>h("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:k==="zh"?"active":"",onClick:()=>h("zh"),children:"中"})]})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoEdit")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoEditDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(C?" active":""),role:"switch","aria-checked":C,onClick:()=>i(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliToken")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("cliTokenDesc")}),!T&&u.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:u.map(n=>e.jsxs("span",{style:{display:"block"},children:[n.name," — ",new Date(n.createdAt).toLocaleString()," ",n.revoked?`(${s("cliTokenRevoked")})`:`(${s("cliTokenActive")})`]},n.tokenId))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:Fe,disabled:B||T,children:B?"…":u.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),I&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--ok",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliTokenGenerated")}),e.jsx("span",{className:"mdocs-settings-secret-value",children:I.token})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(I.token),c(!1),S(!0),window.setTimeout(()=>S(!1),2e3)}catch{S(!1),c(!0),window.setTimeout(()=>c(!1),3e3)}})()},children:s(v?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>A(null),children:s("close")})]}),v&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),l&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:s("cliTokenCopyFailed")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"当 Token 丢失时,可用恢复码找回身份。生成后请立即保存,仅显示一次。"})]}),e.jsx("button",{type:"button",className:"secondary",onClick:Oe,disabled:G,children:G?"…":"生成恢复码"})]}),m&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--warn",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 你的恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8},children:"请立即复制保存,关闭后不可再查看。"}),e.jsx("div",{className:"mdocs-settings-secret-code",children:m})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(m),q(!1),K(!0),window.setTimeout(()=>K(!1),2e3)}catch{K(!1),q(!0),window.setTimeout(()=>q(!1),3e3)}})()},children:F?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>w(null),children:s("close")})]}),F&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),H&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:"复制失败,请手动选中上方内容复制"})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-item",children:e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔐 登录密码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"设置密码后,可在其他浏览器或设备用「用户名+密码」登录。"})]})}),e.jsxs("form",{onSubmit:Ve,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:p,onChange:n=>V(n.target.value),minLength:0,style:{marginBottom:8}}),ee&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:$,children:$?"设置中…":"保存密码"})]})]})]})]}):d==="bookmarks"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("bookmarkTitle")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:s("bookmarkSearch"),value:X,onChange:n=>Ie(n.target.value)}),De?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:xe.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(X?"bookmarkNoMatch":"bookmarkEmpty")}):e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("bookmarkColTitle")}),e.jsx("th",{children:s("bookmarkColDomain")}),e.jsx("th",{children:s("bookmarkColAuthor")}),e.jsx("th",{children:s("bookmarkColTime")}),e.jsx("th",{style:{textAlign:"right"}})]})}),e.jsx("tbody",{children:xe.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:n.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):he.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{children:new Date(n.bookmarkedAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Be(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})]})]}):d==="myDocuments"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("myDocuments")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:"搜索文章…",value:Y,onChange:n=>Pe(n.target.value)}),Ee?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:je.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(Y?"myDocumentsNoMatch":"myDocumentsEmpty")}):e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("myDocumentsColTitle")}),e.jsx("th",{children:s("myDocumentsColDomain")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{colSpan:2})]})}),e.jsx("tbody",{children:je.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:he.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:new Date(n.updatedAt).toLocaleDateString()}),e.jsx("td",{children:new Date(n.createdAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Ke(n.documentId),children:s("docInfoInviteMember")})}),e.jsx("td",{style:{textAlign:"right",paddingLeft:0},children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(n.documentId),children:s("bookmarkOpen")})})]},n.documentId))})]})})]})]}):d==="domainManagement"?e.jsx(Fs,{}):d==="memberTemplates"?e.jsx(Os,{}):d==="agentConfig"?e.jsxs(e.Fragment,{children:[e.jsx(Ks,{}),e.jsx(Ws,{})]}):e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:s("saveAndPublish")}),e.jsx("button",{type:"button",className:"secondary",onClick:g,children:s("backToDocs")})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoSave")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoSaveAlwaysOnDesc")})]}),e.jsx("span",{className:"mdocs-toggle active",role:"switch","aria-checked":"true","aria-disabled":"true",style:{opacity:.6,cursor:"not-allowed"},children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoPublish")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoPublishDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(y?" active":""),role:"switch","aria-checked":y,onClick:()=>b(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),L>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>f(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",L,")"]}),e.jsx("span",{className:"mdocs-settings-draft-arrow","aria-hidden":"true",children:"›"})]}):e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:s("noDrafts")})})]})]}),N&&e.jsx(zs,{onPublish:M,onClose:()=>f(!1),onCountChange:W,onRecover:t.onRecoverDraft})]}),x&&e.jsx(Ss,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:B,onConfirm:()=>{P(!1),fe()},onCancel:()=>P(!1)}),e.jsx(Se,{open:Re,title:s("docInfoInviteMember"),initialSelectedIds:[...ae.keys()],initialPermissions:ae,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>se(!1),onConfirm:n=>{$e(n)}})]})}export{Zs as SettingsPage};