@fgbg/mdocs 1.1.2 → 1.2.0

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 (41) hide show
  1. package/agent-skills/changelog/SKILL.md +15 -0
  2. package/agent-skills/usage-knowledge-graph/SKILL.md +0 -2
  3. package/dist/server/agent/Agent/run.js.map +1 -1
  4. package/dist/server/agent/Agent/system-prompt.js +13 -6
  5. package/dist/server/agent/Agent/system-prompt.js.map +1 -1
  6. package/dist/server/agent/Agent/tools-overwrite.js +10 -0
  7. package/dist/server/agent/Agent/tools-overwrite.js.map +1 -1
  8. package/dist/server/documents/document.service.js +16 -4
  9. package/dist/server/documents/document.service.js.map +1 -1
  10. package/dist/server/routes/agent.routes.js +3 -0
  11. package/dist/server/routes/agent.routes.js.map +1 -1
  12. package/dist/shared/file-type-policy.js +120 -0
  13. package/dist/shared/file-type-policy.js.map +1 -0
  14. package/dist/shared/file-types.js +4 -2
  15. package/dist/shared/file-types.js.map +1 -1
  16. package/dist/web/assets/AgentChatPanel-Dd8Xnyia.js +27 -0
  17. package/dist/web/assets/{AgentSkillFormCard-CtfWIf7Y.js → AgentSkillFormCard-dsAy12lL.js} +1 -1
  18. package/dist/web/assets/{AiWriteWorkbench-Boie5E_-.js → AiWriteWorkbench-i9ZoyX3p.js} +1 -1
  19. package/dist/web/assets/{DiagramEditor-NtNY3sZL-CZy-tmEe.js → DiagramEditor-NtNY3sZL-CAQtZY2E.js} +1 -1
  20. package/dist/web/assets/{DocumentEditor-1A6lpvV-.js → DocumentEditor-oFGmAxnV.js} +2 -2
  21. package/dist/web/assets/{MergeView-Dip0aW7s.js → MergeView-DgEbzTVh.js} +1 -1
  22. package/dist/web/assets/PlaygroundPage-BLEC6-Uf.js +8 -0
  23. package/dist/web/assets/{SettingsPage-nlnmzNZK.js → SettingsPage-BcCvamXH.js} +1 -1
  24. package/dist/web/assets/{Toolbar-BHLX-ug4.js → Toolbar-Dz9Cn_hv.js} +24 -29
  25. package/dist/web/assets/{VisitorPickerModal-BPyEWlQo.js → VisitorPickerModal-eagVdEZA.js} +1 -1
  26. package/dist/web/assets/code-xml-CZsyEkCa.js +6 -0
  27. package/dist/web/assets/{copy-BE64wQqi.js → copy-BUUKT-QO.js} +1 -1
  28. package/dist/web/assets/{diagram-CT58wBdU.js → diagram-DtU2xxz3.js} +1081 -1081
  29. package/dist/web/assets/index-DI_31upJ.js +248 -0
  30. package/dist/web/assets/index-YRgNGXBI.css +1 -0
  31. package/dist/web/assets/{meta2dEngine-BD2XbzaV-z-eR7E_V.js → meta2dEngine-BD2XbzaV-nAmL0RaW.js} +1 -1
  32. package/dist/web/assets/{motion-DX3HNq_4.js → motion-BgtuAqBE.js} +1 -1
  33. package/dist/web/assets/{plus-ECzYbQfA.js → plus-BkiPFt2u.js} +1 -1
  34. package/dist/web/assets/{react-GP8hKHRA.js → react--aHzEjEz.js} +3 -3
  35. package/dist/web/assets/{ui-BQStT3dY.js → ui-RahDNce8.js} +4 -4
  36. package/dist/web/index.html +5 -5
  37. package/package.json +2 -1
  38. package/dist/web/assets/AgentChatPanel-Bt38gm3b.js +0 -6
  39. package/dist/web/assets/PlaygroundPage-C4X6Lj-Q.js +0 -8
  40. package/dist/web/assets/index-BkKvQv2F.js +0 -248
  41. package/dist/web/assets/index-DKshvHIN.css +0 -1
@@ -11,6 +11,8 @@
11
11
  export const FILE_TYPE = {
12
12
  /** 普通 Markdown 文章(文档树中可见) */
13
13
  DOCUMENT: 'md',
14
+ /** HTML 文档(文档树中可见) */
15
+ HTML: 'html',
14
16
  /** 普通目录(文档树中可见) */
15
17
  FOLDER: 'dir',
16
18
  /** 目录描述文件 ___desc___.md(文档树中不可见,用于展示目录介绍) */
@@ -20,9 +22,9 @@ export const FILE_TYPE = {
20
22
  /** 图谱缓存目录 __graph__(文档树中不可见) */
21
23
  GRAPH_DIR: 'graph_dir',
22
24
  };
23
- /** 判断是否是文档树中可见的类型(普通 md 文件 + 目录) */
25
+ /** 判断是否是文档树中可见的类型 */
24
26
  export function isVisibleFileType(fileType) {
25
- return fileType === FILE_TYPE.DOCUMENT || fileType === FILE_TYPE.FOLDER;
27
+ return fileType === FILE_TYPE.DOCUMENT || fileType === FILE_TYPE.HTML || fileType === FILE_TYPE.FOLDER;
26
28
  }
27
29
  /** 判断是否是目录类型(普通目录或特殊目录) */
28
30
  export function isFolderFileType(fileType) {
@@ -1 +1 @@
1
- {"version":3,"file":"file-types.js","sourceRoot":"","sources":["../../src/shared/file-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,6BAA6B;IAC7B,QAAQ,EAAE,IAAI;IACd,mBAAmB;IACnB,MAAM,EAAE,KAAK;IACb,6CAA6C;IAC7C,WAAW,EAAE,aAAa;IAC1B,0BAA0B;IAC1B,UAAU,EAAE,YAAY;IACxB,gCAAgC;IAChC,SAAS,EAAE,WAAW;CACd,CAAC;AAIX,oCAAoC;AACpC,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,OAAO,QAAQ,KAAK,SAAS,CAAC,QAAQ,IAAI,QAAQ,KAAK,SAAS,CAAC,MAAM,CAAC;AAC1E,CAAC;AAED,2BAA2B;AAC3B,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,QAAQ,KAAK,SAAS,CAAC,MAAM,IAAI,QAAQ,KAAK,SAAS,CAAC,SAAS,CAAC;AAC3E,CAAC;AAED,qBAAqB;AACrB,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,QAAQ,KAAK,SAAS,CAAC,UAAU,IAAI,QAAQ,KAAK,SAAS,CAAC,SAAS,CAAC;AAC/E,CAAC"}
1
+ {"version":3,"file":"file-types.js","sourceRoot":"","sources":["../../src/shared/file-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,6BAA6B;IAC7B,QAAQ,EAAE,IAAI;IACd,sBAAsB;IACtB,IAAI,EAAE,MAAM;IACZ,mBAAmB;IACnB,MAAM,EAAE,KAAK;IACb,6CAA6C;IAC7C,WAAW,EAAE,aAAa;IAC1B,0BAA0B;IAC1B,UAAU,EAAE,YAAY;IACxB,gCAAgC;IAChC,SAAS,EAAE,WAAW;CACd,CAAC;AAIX,qBAAqB;AACrB,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,OAAO,QAAQ,KAAK,SAAS,CAAC,QAAQ,IAAI,QAAQ,KAAK,SAAS,CAAC,IAAI,IAAI,QAAQ,KAAK,SAAS,CAAC,MAAM,CAAC;AACzG,CAAC;AAED,2BAA2B;AAC3B,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,QAAQ,KAAK,SAAS,CAAC,MAAM,IAAI,QAAQ,KAAK,SAAS,CAAC,SAAS,CAAC;AAC3E,CAAC;AAED,qBAAqB;AACrB,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,QAAQ,KAAK,SAAS,CAAC,UAAU,IAAI,QAAQ,KAAK,SAAS,CAAC,SAAS,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,27 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diagram-DtU2xxz3.js","assets/ui-RahDNce8.js","assets/react-vendor-BuABiQkA.js","assets/motion-BgtuAqBE.js"])))=>i.map(i=>d[i]);
2
+ import{r as l,j as e,_ as tt,b as st}from"./react-vendor-BuABiQkA.js";import{c as X,N as Pe,ag as te,ah as Ee,ai as nt,i as $e,aj as at,ak as rt,al as it,am as ot,an as lt,ao as Le,ap as ct,aq as dt,ar as ut}from"./index-DI_31upJ.js";import{H as mt,A as ze,S as pt,a as ft}from"./AgentSkillFormCard-dsAy12lL.js";import{C as ht}from"./code-xml-CZsyEkCa.js";import{C as Be,a as He}from"./copy-BUUKT-QO.js";import{P as gt}from"./plus-BkiPFt2u.js";import{ae as xt,af as yt}from"./ui-RahDNce8.js";import"./diagram-DtU2xxz3.js";import"./motion-BgtuAqBE.js";/**
3
+ * @license lucide-react v0.562.0 - ISC
4
+ *
5
+ * This source code is licensed under the ISC license.
6
+ * See the LICENSE file in the root directory of this source tree.
7
+ */const jt=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],kt=X("file-text",jt);/**
8
+ * @license lucide-react v0.562.0 - ISC
9
+ *
10
+ * This source code is licensed under the ISC license.
11
+ * See the LICENSE file in the root directory of this source tree.
12
+ */const Nt=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],bt=X("maximize-2",Nt);/**
13
+ * @license lucide-react v0.562.0 - ISC
14
+ *
15
+ * This source code is licensed under the ISC license.
16
+ * See the LICENSE file in the root directory of this source tree.
17
+ */const vt=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],wt=X("minimize-2",vt);/**
18
+ * @license lucide-react v0.562.0 - ISC
19
+ *
20
+ * This source code is licensed under the ISC license.
21
+ * See the LICENSE file in the root directory of this source tree.
22
+ */const Ct=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],St=X("zoom-in",Ct);/**
23
+ * @license lucide-react v0.562.0 - ISC
24
+ *
25
+ * This source code is licensed under the ISC license.
26
+ * See the LICENSE file in the root directory of this source tree.
27
+ */const It=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],_t=X("zoom-out",It);function ge(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(ge).join(""):typeof s=="object"&&"props"in s?ge((n=s.props)==null?void 0:n.children):""}function At(s){return s?/\blanguage-mermaid\b|\bmermaid\b/i.test(s):!1}function Mt(s){const n=Array.isArray(s)?s:[s];for(const r of n){if(r==null||typeof r!="object"||!("props"in r))continue;const c=r.props;if(!(!c||!At(c.className)))return ge(c.children).replace(/\n$/,"")}return null}const Rt=.4,Et=4,ee=.2;let fe=null;function $t(){return fe||(fe=tt(()=>import("./diagram-DtU2xxz3.js").then(s=>s.A),__vite__mapDeps([0,1,2,3])).then(s=>{const n=s.default;return n.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral",fontFamily:"ui-sans-serif, system-ui, sans-serif"}),n})),fe}function he(s){return Math.min(Et,Math.max(Rt,s))}function zt(s){const[n,r]=l.useState(1),[c,k]=l.useState({x:0,y:0}),g=l.useRef(null),[_,N]=l.useState(!1);l.useEffect(()=>{const u=C=>{C.key==="Escape"&&s.onClose()};window.addEventListener("keydown",u);const f=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",u),document.body.style.overflow=f}},[s.onClose]);function I(u){u.button===0&&(u.currentTarget.setPointerCapture(u.pointerId),g.current={pointerId:u.pointerId,startX:u.clientX,startY:u.clientY,originX:c.x,originY:c.y},N(!0))}function A(u){const f=g.current;!f||f.pointerId!==u.pointerId||k({x:f.originX+(u.clientX-f.startX),y:f.originY+(u.clientY-f.startY)})}function M(u){const f=g.current;if(!(!f||f.pointerId!==u.pointerId)){g.current=null,N(!1);try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}}}function v(u){u.preventDefault();const f=u.deltaY>0?-ee:ee;r(C=>he(Number((C+f).toFixed(2))))}return st.createPortal(e.jsxs("div",{className:"mdocs-agent-mermaid-float",role:"dialog","aria-modal":"true","aria-label":"Mermaid 图预览",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-backdrop","aria-label":"关闭预览",onClick:s.onClose}),e.jsxs("div",{className:"mdocs-agent-mermaid-float-chrome",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-float-tools",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>r(u=>he(Number((u-ee).toFixed(2)))),title:"缩小","aria-label":"缩小",children:e.jsx(_t,{size:16,"aria-hidden":!0})}),e.jsxs("span",{className:"mdocs-agent-mermaid-float-scale",children:[Math.round(n*100),"%"]}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>r(u=>he(Number((u+ee).toFixed(2)))),title:"放大","aria-label":"放大",children:e.jsx(St,{size:16,"aria-hidden":!0})}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>{r(1),k({x:0,y:0})},title:"重置",children:"重置"}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:s.onClose,title:"关闭","aria-label":"关闭",children:e.jsx(te,{size:16,"aria-hidden":!0})})]}),e.jsx("div",{className:_?"mdocs-agent-mermaid-float-stage is-dragging":"mdocs-agent-mermaid-float-stage",onPointerDown:I,onPointerMove:A,onPointerUp:M,onPointerCancel:M,onWheel:v,children:e.jsx("div",{className:"mdocs-agent-mermaid-float-canvas",style:{transform:`translate(calc(-50% + ${c.x}px), calc(-50% + ${c.y}px)) scale(${n})`},dangerouslySetInnerHTML:{__html:s.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function Tt(s){const n=l.useId().replace(/:/g,""),[r,c]=l.useState("diagram"),[k,g]=l.useState(null),[_,N]=l.useState(null),[I,A]=l.useState(!1),[M,v]=l.useState(!1),u=l.useRef(null),f=l.useRef(0),C=s.source.trim();l.useEffect(()=>()=>{u.current!=null&&window.clearTimeout(u.current)},[]),l.useEffect(()=>{if(r!=="diagram")return;if(!C){g(null),N(null);return}const x=++f.current,E=window.setTimeout(()=>{(async()=>{try{const $=await $t();if(x!==f.current)return;const O=`mdocs-agent-mmd-${n}-${x}`,{svg:T}=await $.render(O,C);if(x!==f.current)return;g(T),N(null)}catch($){if(x!==f.current)return;g(null),N($ instanceof Error?$.message:"Mermaid 渲染失败")}})()},200);return()=>{window.clearTimeout(E),f.current+=1}},[r,C,n]);async function H(){if(C)try{await navigator.clipboard.writeText(C),A(!0),u.current!=null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>A(!1),1500)}catch{}}return e.jsxs("div",{className:"mdocs-agent-mermaid",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toolbar",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toggle",role:"group","aria-label":"Mermaid 显示模式",children:[e.jsxs("button",{type:"button",className:r==="diagram"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("diagram"),"aria-pressed":r==="diagram",title:"图谱",children:[e.jsx(Pe,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"图谱"})]}),e.jsxs("button",{type:"button",className:r==="code"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("code"),"aria-pressed":r==="code",title:"代码",children:[e.jsx(ht,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"代码"})]})]}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy mdocs-agent-mermaid-copy",onClick:()=>void H(),"aria-label":I?"已复制":"复制代码",title:I?"已复制":"复制",children:I?e.jsx(Be,{size:14,"aria-hidden":!0}):e.jsx(He,{size:14,"aria-hidden":!0})})]}),r==="diagram"?e.jsx("div",{className:"mdocs-agent-mermaid-diagram",children:_?e.jsxs("div",{className:"mdocs-agent-mermaid-error",role:"alert",children:[e.jsx("p",{children:"无法渲染该图,可切换到代码查看源码。"}),e.jsx("pre",{children:_})]}):k?e.jsx("div",{className:"mdocs-agent-mermaid-svg mdocs-agent-mermaid-svg-hit",role:"button",tabIndex:0,onClick:()=>v(!0),onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),v(!0))},title:"点击放大预览","aria-label":"点击放大预览 Mermaid 图",children:e.jsx("span",{className:"mdocs-agent-mermaid-svg-inner",dangerouslySetInnerHTML:{__html:k}})}):e.jsx("div",{className:"mdocs-agent-mermaid-loading",children:"渲染中…"})}):e.jsx("div",{className:"mdocs-agent-panel-md-pre-wrap mdocs-agent-mermaid-code",children:e.jsx("pre",{children:s.codeChildren??e.jsx("code",{className:"language-mermaid",children:C})})}),M&&k?e.jsx(zt,{svg:k,onClose:()=>v(!1)}):null]})}function xe(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(xe).join(""):typeof s=="object"&&"props"in s?xe((n=s.props)==null?void 0:n.children):""}function qt(s){const[n,r]=l.useState(!1),c=l.useRef(null),k=xe(s.children).replace(/\n$/,"");l.useEffect(()=>()=>{c.current!=null&&window.clearTimeout(c.current)},[]);async function g(){if(k)try{await navigator.clipboard.writeText(k),r(!0),c.current!=null&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>r(!1),1500)}catch{}}return e.jsxs("div",{className:"mdocs-agent-panel-md-pre-wrap",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy",onClick:()=>void g(),"aria-label":n?"已复制":"复制代码",title:n?"已复制":"复制",children:n?e.jsx(Be,{size:14,"aria-hidden":!0}):e.jsx(He,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:s.children})]})}function Dt(s){const n=Mt(s.children);return n!=null?e.jsx(Tt,{source:n,codeChildren:s.children}):e.jsx(qt,{children:s.children})}function Te(s){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(xt,{remarkPlugins:[yt],components:{pre:({children:n})=>e.jsx(Dt,{children:n})},children:s.children})})}const Ft=["如何发布文档?","草稿是什么?","如何创建域?"];function qe(s,n){return n.map((r,c)=>{const k=r.skillNames&&r.skillNames.length>0?r.skillNames:r.skillIds&&r.skillIds.length>0?r.skillIds:void 0;return{id:`h-${s}-${c}-${r.role}`,role:r.role,content:r.content,skillNames:k}})}function Pt(s,n){const r=s.slice(),c=r[r.length-1];return(c==null?void 0:c.type)==="text"?r[r.length-1]={type:"text",text:c.text+n}:r.push({type:"text",text:n}),r}function Lt(s,n){const r=s.slice(),c=r[r.length-1];return(c==null?void 0:c.type)==="thinking"?r[r.length-1]={type:"thinking",text:c.text+n}:r.push({type:"thinking",text:n}),r}function De(s){return s!=null&&s.length?s.filter(n=>n.type==="text").map(n=>n.text).join(""):""}function Bt(s){return!!(s!=null&&s.some(n=>n.type==="thinking"&&n.text.length>0))}function Ht(s){const n=new Date(s);if(Number.isNaN(n.getTime()))return"";const r=new Date;return n.getFullYear()===r.getFullYear()&&n.getMonth()===r.getMonth()&&n.getDate()===r.getDate()?n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function Fe(s){if(s>=1e3){const n=s/1e3;return`${n>=10?Math.round(n):Math.round(n*10)/10}K`}return String(s)}function Ot(s){const{block:n,onResolved:r}=s,[c,k]=l.useState(""),[g,_]=l.useState(!1),[N,I]=l.useState(1),A=l.useRef(!1),M=l.useRef(r);M.current=r;const v=n.status==="open",u=l.useRef(0);l.useEffect(()=>{if(!v)return;A.current=!1;const x=new Date(n.expiresAt).getTime(),E=Date.now(),$=Math.max(x-E,1);u.current=$,I(1);const O=()=>{const z=x-Date.now(),m=Math.max(0,Math.min(1,z/$));I(m),z<=0&&!A.current&&(A.current=!0,dt(n.requestId).catch(()=>{}).finally(()=>{M.current(n.requestId,"","expired")}))};O();const T=window.setInterval(O,100);return()=>window.clearInterval(T)},[v,n.expiresAt,n.requestId]);async function f(x){const E=x.trim();if(!(!E||g||!v)){_(!0);try{await ut(n.requestId,E),r(n.requestId,E,"selected")}catch{r(n.requestId,E,"failed")}finally{_(!1)}}}async function C(){if(!(g||!v)){_(!0),A.current=!0;try{await Le(n.requestId),r(n.requestId,"","cancelled")}catch{r(n.requestId,"","failed")}finally{_(!1)}}}const H=Math.max(0,Math.ceil(N*u.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(v?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:n.title}),v?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[H,"s"]}):null]}),v?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(N*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${N})`}})}):null,n.status==="selected"&&n.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",n.selected]}):null,n.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,n.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,n.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,v?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:n.options.map(x=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:g,onClick:()=>void f(x),children:x},x))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:c,disabled:g,placeholder:"或输入自己的内容…",onChange:x=>k(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),f(c))}}),e.jsx("button",{type:"button",disabled:g||!c.trim(),onClick:()=>void f(c),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:g,onClick:()=>void C(),children:"取消"})})]}):null]})}function Wt(s){const k=2*Math.PI*8.75,g=Math.min(100,Math.max(0,s.percent)),_=k*(1-g/100),N=g>=90?"danger":g>=70?"warn":"ok",I=`上下文 ${g}% · 已用 ${Fe(s.used)} / ${Fe(s.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+N,"data-tooltip":I,"aria-label":I,role:"img",tabIndex:0,children:e.jsxs("svg",{width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,children:[e.jsx("circle",{className:"mdocs-agent-panel-context-track",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5}),e.jsx("circle",{className:"mdocs-agent-panel-context-value",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:k,strokeDashoffset:_,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function Kt(s){var n;for(const r of s)if(!(r.role!=="assistant"||!((n=r.blocks)!=null&&n.length))){for(const c of r.blocks)if((c.type==="choice_card"||c.type==="skill_form_card")&&c.status==="open")return!0}return!1}const ts=l.forwardRef(function(n,r){const{open:c,onClose:k,visitorName:g,anchorStyle:_,fullscreen:N,onToggleFullscreen:I,domainId:A,documentId:M,documentTitle:v,documentPath:u,graphFileId:f,graphLabel:C,onOpenDocument:H,onTreeChanged:x,onDocumentOverwritten:E,onOpenCoding:$}=n,O=((g==null?void 0:g.trim().charAt(0))||"我").toUpperCase(),[T,z]=l.useState(!1),[m,U]=l.useState(null),[Oe,Y]=l.useState(null),[F,w]=l.useState([]),[se,G]=l.useState(null),[ye,We]=l.useState([]),[Ke,je]=l.useState(!1),[V,Z]=l.useState(""),[W,ke]=l.useState([]),[Ne,ne]=l.useState(!1),[b,J]=l.useState(!1),[be,P]=l.useState(null),[Q,ve]=l.useState(null),[ae,B]=l.useState(!1),[L,we]=l.useState(!1),Xe=l.useRef(null),re=l.useRef(null),q=l.useRef(null),Ce=l.useRef(0),K=l.useRef(!0),ie=l.useRef(F);ie.current=F;const Se=!!(M!=null&&M.trim())&&!Ne,Ue=(v==null?void 0:v.trim())||"当前文档",Ie=(u==null?void 0:u.trim())||"",oe=!!(f!=null&&f.trim())&&!Ne,Ye=(C==null?void 0:C.trim())||"当前图谱";l.useEffect(()=>{ne(!1)},[M,f]);function _e(t){return Ce.current+=1,`${t}-${Ce.current}`}function Ge(t,p=48){return t.scrollHeight-t.scrollTop-t.clientHeight<=p}function D(){const t=re.current;!t||!K.current||(t.scrollTop=t.scrollHeight)}function Ve(){const t=re.current;t&&(K.current=Ge(t))}async function Ze(){je(!0);try{const t=await rt();We(t.sessions),se||G(t.lastOpenedSessionId)}catch{}finally{je(!1)}}async function le(){try{const t=await at();ve(t)}catch{}}async function Ae(){try{const t=await Ee();U(t),Y(null)}catch(t){U(null),Y(t instanceof Error?t.message:String(t))}}l.useEffect(()=>{var p;if(!c){z(!1),(p=q.current)==null||p.abort(),q.current=null,J(!1);return}let t=!1;return(async()=>{try{const i=await Ee();t||(U(i),Y(null))}catch(i){t||(U(null),Y(i instanceof Error?i.message:String(i)))}})(),le(),()=>{t=!0}},[c]),l.useEffect(()=>{if(!c)return;let t=!1;return(async()=>{try{const p=await nt();if(t)return;G(p.sessionId),w(i=>i.length>0?i:qe(p.sessionId,p.messages))}catch{}})(),()=>{t=!0}},[c]),l.useEffect(()=>{!c||!T||Ze()},[c,T]);function ce(){if(!L){if(Kt(ie.current)){B(!0);return}B(!1),k()}}async function Je(){var i;if(L)return;we(!0);const t=ie.current,p=[];for(const S of t)if(!(S.role!=="assistant"||!S.blocks))for(const h of S.blocks)h.type==="choice_card"&&h.status==="open"&&p.push(Le(h.requestId).catch(()=>{})),h.type==="skill_form_card"&&h.status==="open"&&p.push(ct(h.requestId).catch(()=>{}));await Promise.all(p),(i=q.current)==null||i.abort(),w(S=>S.map(h=>h.role!=="assistant"||!h.blocks?h:{...h,blocks:h.blocks.map(y=>y.type==="choice_card"&&y.status==="open"?{...y,status:"cancelled"}:y.type==="skill_form_card"&&y.status==="open"?{...y,status:"cancelled"}:y)})),B(!1),we(!1),k()}const de=l.useRef(ce);de.current=ce,l.useImperativeHandle(r,()=>({requestClose:()=>de.current()}),[]),l.useEffect(()=>{if(!c){B(!1);return}const t=p=>{if(p.key==="Escape"){if(ae){L||B(!1);return}if(T){z(!1);return}de.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[c,T,ae,L]);async function ue(t){var y;const p=t.trim();if(!p||b)return;if(!(m!=null&&m.enabled)){P((m==null?void 0:m.reason)==="missing_api_key"?"请先配置 API Key":(m==null?void 0:m.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(y=q.current)==null||y.abort();const i=new AbortController;q.current=i;const S={id:_e("u"),role:"user",content:p,skillNames:W.length>0?[...W]:void 0},h=_e("a");K.current=!0,w(R=>[...R,S,{id:h,role:"assistant",content:""}]),Z(""),J(!0),P(null),z(!1),requestAnimationFrame(()=>D());try{let R=!1;await lt(p,{skillNames:W.length>0?W:void 0,references:{domainId:(A==null?void 0:A.trim())||void 0,documentId:!oe&&Se?M.trim():void 0,graphFileId:oe?f.trim():void 0},signal:i.signal,onEvent:o=>{o.type==="text_delta"?(w(j=>j.map(a=>{if(a.id!==h)return a;const d=Pt(a.blocks??[],o.text);return{...a,blocks:d,content:De(d)}})),requestAnimationFrame(()=>D())):o.type==="thinking_delta"?(w(j=>j.map(a=>{if(a.id!==h)return a;const d=Lt(a.blocks??[],o.text);return{...a,blocks:d}})),requestAnimationFrame(()=>D())):o.type==="sources"?(w(j=>j.map(a=>{if(a.id!==h)return a;const d=(a.blocks??[]).slice(),pe=d[d.length-1];return(pe==null?void 0:pe.type)==="sources"?d[d.length-1]={type:"sources",items:o.items}:d.push({type:"sources",items:o.items}),{...a,blocks:d}})),requestAnimationFrame(()=>D())):o.type==="document_table"?(w(j=>j.map(a=>{if(a.id!==h)return a;const d=[...a.blocks??[],{type:"document_table",title:o.title,rows:o.rows}];return{...a,blocks:d}})),requestAnimationFrame(()=>D())):o.type==="document_card"?(w(j=>j.map(a=>{if(a.id!==h)return a;const d=[...a.blocks??[],{type:"document_card",documentId:o.documentId,title:o.title,path:o.path,preview:o.preview}];return{...a,blocks:d}})),requestAnimationFrame(()=>D())):o.type==="tool_notice"?(w(j=>j.map(a=>{if(a.id!==h)return a;const d=[...a.blocks??[],{type:"tool_notice",toolName:o.toolName,text:o.text}];return{...a,blocks:d}})),requestAnimationFrame(()=>D())):o.type==="choice_card"?(w(j=>j.map(a=>{if(a.id!==h)return a;const d=[...a.blocks??[],{type:"choice_card",requestId:o.requestId,title:o.title,options:o.options,expiresAt:o.expiresAt,status:"open"}];return{...a,blocks:d}})),requestAnimationFrame(()=>D())):o.type==="choice_expired"?w(j=>j.map(a=>a.id!==h||!a.blocks?a:{...a,blocks:a.blocks.map(d=>d.type==="choice_card"&&d.requestId===o.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):o.type==="skill_form_card"?(w(j=>j.map(a=>{if(a.id!==h)return a;const d=[...a.blocks??[],{type:"skill_form_card",requestId:o.requestId,mode:o.mode,title:o.title,currentName:o.currentName,initialName:o.initialName,initialDescription:o.initialDescription,initialBody:o.initialBody,expiresAt:o.expiresAt,status:"open"}];return{...a,blocks:d}})),requestAnimationFrame(()=>D())):o.type==="skill_form_expired"?w(j=>j.map(a=>a.id!==h||!a.blocks?a:{...a,blocks:a.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===o.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):o.type==="tree_changed"?x==null||x():o.type==="document_overwritten"?E==null||E({documentId:o.documentId,headCommitId:o.headCommitId}):o.type==="open_coding"?$==null||$({documentId:o.documentId,displayName:o.displayName}):o.type==="context_usage"?ve({percent:o.percent,used:o.used,limit:o.limit}):o.type==="error"&&(R=!0,P(o.message))}}),!i.signal.aborted&&!R&&ke([])}catch(R){if(i.signal.aborted)return;P(R instanceof Error?R.message:String(R))}finally{q.current===i&&(q.current=null),J(!1)}}async function Qe(){var t;if(!b){(t=q.current)==null||t.abort(),P(null),z(!1),J(!1);try{const p=await it();G(p.sessionId),w([]),Z(""),K.current=!0,le()}catch(p){P(p instanceof Error?p.message:String(p))}}}async function et(t){var p;if(!b){if(t===se){z(!1);return}(p=q.current)==null||p.abort(),P(null);try{const i=await ot(t);G(i.sessionId),w(qe(i.sessionId,i.messages)),Z(""),z(!1),K.current=!0,requestAnimationFrame(()=>D()),le()}catch(i){P(i instanceof Error?i.message:String(i))}}}function Me(t){!t||!H||H(t)}if(!c)return null;const me=(m==null?void 0:m.reason)==="missing_api_key",Re=Oe??(m&&!m.enabled&&!me?m.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:Xe,className:"mdocs-agent-panel"+(N?" mdocs-agent-panel--fullscreen":""),role:"dialog","aria-label":"mdocs 智能助手","aria-modal":N?!0:void 0,style:N?void 0:_,children:[e.jsxs("header",{className:"mdocs-agent-panel-header",children:[e.jsxs("div",{className:"mdocs-agent-panel-title",children:[e.jsx("img",{src:$e,alt:"",className:"mdocs-agent-panel-title-logo"}),e.jsx("span",{children:"mdocs 智能助手"})]}),e.jsxs("div",{className:"mdocs-agent-panel-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:b,onClick:()=>void Qe(),children:e.jsx(gt,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(T?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>z(t=>!t),children:e.jsx(mt,{size:16,strokeWidth:1.8})}),I?e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:N?"退出全屏":"全屏","aria-label":N?"退出全屏":"全屏",onClick:I,children:N?e.jsx(wt,{size:16,strokeWidth:1.8}):e.jsx(bt,{size:16,strokeWidth:1.8})}):null,e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:ce,children:e.jsx(te,{size:16,strokeWidth:1.8})})]})]}),T?e.jsxs("div",{className:"mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>z(!1),children:"返回对话"})]}),Ke?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):ye.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:ye.map(t=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(t.id===se?" active":""),disabled:b,onClick:()=>void et(t.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:t.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:Ht(t.updatedAt)})]})},t.id))})]}):e.jsxs("div",{className:"mdocs-agent-panel-body",children:[e.jsx("div",{className:"mdocs-agent-panel-welcome",ref:re,onScroll:Ve,children:F.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-hello",children:"你好,我是 mdocs 智能助手"}),e.jsx("p",{className:"mdocs-agent-panel-desc",children:"我能答疑、搜文档、整理结构,也能帮你写全文;需要精细改稿请点文档顶栏「帮写」。"}),me?e.jsx(ze,{onConfigured:Ae}):Re?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Re}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:Ft.map(t=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void ue(t),disabled:b||!(m!=null&&m.enabled),children:t},t))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:F.map(t=>{var p;return e.jsxs("div",{className:"mdocs-agent-panel-msg"+(t.role==="user"?" mdocs-agent-panel-msg-user":" mdocs-agent-panel-msg-assistant"),children:[t.role==="assistant"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-ai","aria-hidden":!0,children:e.jsx("img",{src:$e,alt:""})}):null,e.jsxs("div",{className:"mdocs-agent-panel-msg-bubble",children:[t.role==="user"&&t.skillNames&&t.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",t.skillNames.length]}):null,t.role==="assistant"?t.blocks&&t.blocks.length>0?e.jsxs("div",{className:"mdocs-agent-panel-timeline",children:[t.blocks.map((i,S)=>{var h;return i.type==="thinking"?i.text?e.jsxs("details",{className:"mdocs-agent-panel-think-fold",open:b&&t.id===((h=F[F.length-1])==null?void 0:h.id),children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:i.text})]},`${t.id}-th-${S}`):null:i.type==="text"?i.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Te,{children:i.text})},`${t.id}-t-${S}`):null:i.type==="sources"?i.items.length===0?null:e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:["已阅读 ",i.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:i.items.map(y=>e.jsx("li",{children:e.jsx("a",{href:y.url,target:"_blank",rel:"noreferrer",children:y.name})},y.id))})]})},`${t.id}-s-${S}`):i.type==="tool_notice"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:i.text})},`${t.id}-n-${S}`):i.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Ot,{block:i,onResolved:(y,R,o)=>{w(j=>j.map(a=>a.id!==t.id||!a.blocks?a:{...a,blocks:a.blocks.map(d=>d.type==="choice_card"&&d.requestId===y?{...d,status:o,selected:o==="selected"?R:d.selected}:d)}))}})},`${t.id}-ch-${S}`):i.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(pt,{block:i,onResolved:(y,R,o)=>{w(j=>j.map(a=>a.id!==t.id||!a.blocks?a:{...a,blocks:a.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===y?{...d,status:R,submittedName:R==="submitted"?o:d.submittedName}:d)}))}})},`${t.id}-sf-${S}`):i.type==="document_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:y=>{y.preventDefault(),y.stopPropagation(),Me(i.documentId)},children:["《",i.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"文档预览"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[i.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:i.path}):null,i.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:i.preview}):e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview muted",children:"(无正文预览)"})]})]})},`${t.id}-c-${S}`):e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[i.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:i.rows.length===0?"无结果":`${i.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:i.rows.length===0?e.jsx("p",{className:"mdocs-agent-panel-doc-table-empty",children:"无结果"}):e.jsxs("table",{className:"mdocs-agent-panel-doc-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"文章名字"}),e.jsx("th",{children:"文章内容"})]})}),e.jsx("tbody",{children:i.rows.map(y=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>Me(y.documentId),children:y.title})}),e.jsx("td",{children:y.summary||"-"})]},y.documentId))})]})})]})},`${t.id}-d-${S}`)}),b&&t.id===((p=F[F.length-1])==null?void 0:p.id)&&!De(t.blocks)&&!Bt(t.blocks)?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null]}):t.content?e.jsx(Te,{children:t.content}):b?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null:t.content]}),t.role==="user"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-user","aria-hidden":!0,children:O}):null]},t.id)})})}),be?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:be}):null,me&&F.length>0?e.jsx(ze,{onConfigured:Ae}):null,e.jsx(ft,{selectedNames:W,onChange:ke,disabled:b||!(m!=null&&m.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap",children:[oe?e.jsxs("div",{className:"mdocs-agent-doc-ref mdocs-agent-graph-ref",children:[e.jsx(Pe,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:Ye}),e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:"图谱(只读)"})]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前图谱",disabled:b,onClick:()=>ne(!0),children:e.jsx(te,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):Se?e.jsxs("div",{className:"mdocs-agent-doc-ref",children:[e.jsx(kt,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:Ue}),Ie?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:Ie}):null]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前文档",disabled:b,onClick:()=>ne(!0),children:e.jsx(te,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):null,e.jsxs("div",{className:"mdocs-agent-panel-input-body",children:[e.jsx("textarea",{className:"mdocs-agent-panel-input",rows:2,placeholder:m!=null&&m.enabled?"把你的问题告诉我…":"请先配置 API Key",value:V,disabled:b||!(m!=null&&m.enabled),onChange:t=>Z(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),ue(V))}}),Q?e.jsx(Wt,{percent:Q.percent,used:Q.used,limit:Q.limit}):null,e.jsx("button",{type:"button",className:b?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:b?!1:!(m!=null&&m.enabled)||!V.trim(),onClick:()=>{var t;if(b){(t=q.current)==null||t.abort();return}ue(V)},title:b?"停止":"发送","aria-label":b?"停止":"发送",children:b?"■":"↑"})]})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),ae?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{L||B(!1)},children:e.jsxs("div",{className:"mdocs-message-dialog mdocs-agent-close-confirm",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-agent-close-confirm-title",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{id:"mdocs-agent-close-confirm-title",className:"mdocs-message-dialog-title",children:"有待处理的倒计时"}),e.jsx("p",{className:"mdocs-message-dialog-body",children:"当前还有选择卡或 Skill 表单在倒计时。强制关闭会取消这些操作并退出助手;也可以继续等待完成后再关。"}),e.jsxs("div",{className:"mdocs-message-dialog-actions mdocs-agent-close-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",disabled:L,onClick:()=>B(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:L,onClick:()=>void Je(),children:L?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{ts as AgentChatPanel};
@@ -1,4 +1,4 @@
1
- import{c as K,a2 as q,b as L,a0 as R,at as T,ap as B,au as P}from"./index-BkKvQv2F.js";import{r as n,j as e}from"./react-vendor-BuABiQkA.js";/**
1
+ import{c as K,a2 as q,b as L,a0 as R,at as T,ap as B,au as P}from"./index-DI_31upJ.js";import{r as n,j as e}from"./react-vendor-BuABiQkA.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{r as d,j as n}from"./react-vendor-BuABiQkA.js";import{ag as ne,ah as de,i as ue,ak as me,as as he,al as fe,am as ge,an as xe}from"./index-BkKvQv2F.js";import{H as ke,A as te,S as ye,a as we}from"./AgentSkillFormCard-CtfWIf7Y.js";import{P as pe}from"./plus-ECzYbQfA.js";import{ae as je,af as Ne}from"./ui-BQStT3dY.js";import"./diagram-CT58wBdU.js";import"./motion-DX3HNq_4.js";function X(e){return e===""?[]:e.split(`
1
+ import{r as d,j as n}from"./react-vendor-BuABiQkA.js";import{ah as ne,ai as de,i as ue,ak as me,as as he,al as fe,am as ge,an as xe}from"./index-DI_31upJ.js";import{H as ke,A as te,S as ye,a as we}from"./AgentSkillFormCard-dsAy12lL.js";import{P as pe}from"./plus-BkiPFt2u.js";import{ae as je,af as Ne}from"./ui-RahDNce8.js";import"./diagram-DtU2xxz3.js";import"./motion-BgtuAqBE.js";function X(e){return e===""?[]:e.split(`
2
2
  `)}function be(e){return e.join(`
3
3
  `)}function Z(e,i){const s=X(e),l=X(i),m=s.length,k=l.length,y=Array.from({length:m+1},()=>Array.from({length:k+1},()=>0));for(let N=m-1;N>=0;N--)for(let v=k-1;v>=0;v--)s[N]===l[v]?y[N][v]=y[N+1][v+1]+1:y[N][v]=Math.max(y[N+1][v],y[N][v+1]);const C=[];let g=0,x=0;for(;g<m||x<k;)if(g<m&&x<k&&s[g]===l[x])C.push({kind:"eq",oi:g,ni:x}),g++,x++;else if(x<k&&(g===m||y[g][x+1]>=y[g+1][x]))C.push({kind:"ins",oi:g,ni:x}),x++;else if(g<m)C.push({kind:"del",oi:g,ni:x}),g++;else break;const j=[];let f=0,P=0;for(;f<C.length;){if(C[f].kind==="eq"){f++;continue}const N=C[f].oi,v=C[f].ni,R=[],b=[];let A=N,D=v;for(;f<C.length&&C[f].kind!=="eq";){const $=C[f];$.kind==="del"?(R.push(s[$.oi]),A=$.oi+1):(b.push(l[$.ni]),D=$.ni+1),f++}j.push({id:`h${P++}`,oldStart:N,oldEnd:A,newStart:v,newEnd:D,oldLines:R,newLines:b})}return j}function Se(e,i){const s=X(e);return be([...s.slice(0,i.oldStart),...i.newLines,...s.slice(i.oldEnd)])}function Y(e){return e===""?[]:e.split(`
4
4
  `)}function K(e){return e.join(`
@@ -1,2 +1,2 @@
1
- import{Q as I,S as H,T as F,U as O,V as G}from"./react-GP8hKHRA.js";import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-z-eR7E_V.js";import{M as _}from"./meta2d-1-g23JOU.js";import"./editor-CL03se2B.js";import"./ui-BQStT3dY.js";import"./motion-DX3HNq_4.js";import"./diagram-CT58wBdU.js";import"./index-BkKvQv2F.js";import"./plus-ECzYbQfA.js";import"./copy-BE64wQqi.js";let q=0;const P=new Set;function $(n){return P.add(n),()=>{P.delete(n)}}function M(){return q}function J(){q++,P.forEach(n=>n())}function z(n){let t=null;try{const[r]=I();t=r}catch{}const i=t;if(!i)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore($,M,M),{setLocale:c.useCallback(r=>{i.setLocale(r),J()},[i]),t:c.useCallback((r,u)=>i.t(r,u),[i])}}const K={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 W(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function U(){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
1
+ import{Q as I,S as H,T as F,U as O,V as G}from"./react--aHzEjEz.js";import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-nAmL0RaW.js";import{M as _}from"./meta2d-1-g23JOU.js";import"./editor-CL03se2B.js";import"./ui-RahDNce8.js";import"./motion-BgtuAqBE.js";import"./diagram-DtU2xxz3.js";import"./index-DI_31upJ.js";import"./plus-BkiPFt2u.js";import"./copy-BUUKT-QO.js";let q=0;const P=new Set;function $(n){return P.add(n),()=>{P.delete(n)}}function M(){return q}function J(){q++,P.forEach(n=>n())}function z(n){let t=null;try{const[r]=I();t=r}catch{}const i=t;if(!i)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore($,M,M),{setLocale:c.useCallback(r=>{i.setLocale(r),J()},[i]),t:c.useCallback((r,u)=>i.t(r,u),[i])}}const K={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 W(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function U(){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
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 V(n){return G(structuredClone(n))}function Z(n){const t=new Map;for(const i of n){const r=t.get(i.group)??[];r.push(i),t.set(i.group,r)}return Array.from(t.entries())}function ee({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 te({disabled:n,engineRef:t,item:i,t:r}){const u=()=>{const a=t.current;if(!(!a||n))try{a.canvas.addCaches=[V(i.pen)]}catch{}};return e.jsxs("div",{draggable:!n,onClick:a=>{a.stopPropagation(),u()},onDragStart:a=>{if(n){a.preventDefault();return}const f=JSON.stringify(V(i.pen));a.dataTransfer.setData("Meta2d",f),a.dataTransfer.setData("Text",f),a.dataTransfer.effectAllowed="copy"},onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),u())},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:`${r(W(i.key))||i.label} — drag or click to add`,children:[e.jsx(ee,{name:String(i.pen.name??"rectangle")}),e.jsx("span",{style:{fontSize:11},children:r(W(i.key))||i.label})]})}function ne({disabled:n,engineRef:t}){const{t:i}=z(),r=c.useMemo(()=>Z(U()),[]);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:i("meta2d.palette.title")}),e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:12},children:i("meta2d.palette.hint")}),r.map(([u,a])=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:6},children:i(K[u]||u)}),e.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"repeat(2, minmax(0, 1fr))"},children:a.map(f=>e.jsx(te,{disabled:n,engineRef:t,item:f,t:i},f.key))})]},u))]})}const N={borderLeft:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",touchAction:"pan-y",width:220},A={color:"#8c8c8c",fontSize:12,marginBottom:4},D={borderBottom:"1px solid #f0f0f0",padding:"10px 12px"},y={alignItems:"center",display:"flex",gap:6,marginBottom:6},w={background:"#fafafa",border:"1px solid #e5e5e5",borderRadius:4,fontSize:12,height:28,outline:"none",padding:"0 6px"},b={color:"#8c8c8c",fontSize:11,minWidth:22},T={background:"#fff",border:"1px solid #d9d9d9",borderRadius:4,cursor:"pointer",fontSize:11,minWidth:48,padding:"4px 8px"},le=120;function ie({engine:n}){const{t}=z(),[i,r]=c.useState(null),[u,a]=c.useState(null),[f,v]=c.useState(""),p=c.useRef(null),j=c.useRef(null),B=c.useCallback((l,d)=>{!n||l===null||l===void 0||n.setValue({id:l,text:d},{render:!0})},[n]),k=c.useCallback(l=>{if(!l||l.length!==1){p.current&&(clearTimeout(p.current),p.current=null),r(null),a(null),v(""),j.current=null;return}const d=l[0];if((d.globalAlpha===null||d.globalAlpha===void 0)&&(d.globalAlpha=1),d.id!==j.current&&(p.current&&(clearTimeout(p.current),p.current=null),j.current=d.id,v(d.text??"")),r(d),n)try{a(n.getPenRect(d))}catch{a(null)}},[n]),C=c.useCallback(()=>{p.current&&(clearTimeout(p.current),p.current=null),r(null),a(null),v(""),j.current=null},[]);if(c.useEffect(()=>{if(n)return n.on("active",k),n.on("inactive",C),()=>{n.off("active",k),n.off("inactive",C),p.current&&(clearTimeout(p.current),p.current=null)}},[n,k,C]),!i||!n)return e.jsx("aside",{style:N,children:e.jsx("div",{style:{color:"#bbb",fontSize:12,padding:16,textAlign:"center"},children:t("meta2d.props.empty")})});const h=(l,d)=>{const m={id:i.id};m[l]=d,l==="dash"&&(m.lineDash=[void 0,[5,5]][d]),l!=="text"&&r(S=>S&&{...S,...m}),n.setValue(m,{render:!0})},o=l=>{v(l);const d=i.id;p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{p.current=null,B(d,l)},le)},x=()=>{p.current&&(clearTimeout(p.current),p.current=null),B(i.id,f)},g=(l,d)=>{if(!u)return;const m={id:i.id};m[l]=d,n.setValue(m,{render:!0}),a(S=>S?{...S,[l]:d}:null)},R=l=>{l(n),n.render(!0)};return e.jsxs("aside",{style:N,children:[e.jsxs("div",{style:D,children:[e.jsx("div",{style:A,children:t("meta2d.props.text")}),e.jsx("div",{style:y,children:e.jsx("input",{onBlur:x,onChange:l=>o(l.target.value),onKeyDown:l=>{l.stopPropagation(),l.key==="Enter"&&(l.preventDefault(),l.target.blur())},style:{...w,flex:1,width:"100%"},type:"text",value:f})})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.appearance")}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.color")}),e.jsx("input",{onChange:l=>h("color",l.target.value),style:{...w,flex:1},type:"color",value:i.color||"#1f1f1f"})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.bg")}),e.jsx("input",{onChange:l=>h("background",l.target.value),style:{...w,flex:1},type:"color",value:i.background||"#ffffff"})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.dash")}),e.jsxs("select",{onChange:l=>h("dash",Number(l.target.value)),style:{...w,flex:1},value:String(i.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:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.radius")}),e.jsx("input",{max:1,min:0,onChange:l=>h("borderRadius",Number(l.target.value)),step:.01,style:{...w,flex:1},type:"range",value:String(i.borderRadius??0)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:i.borderRadius??0})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.alpha")}),e.jsx("input",{max:1,min:0,onChange:l=>h("globalAlpha",Number(l.target.value)),step:.01,style:{...w,flex:1},type:"range",value:String(i.globalAlpha??1)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:(i.globalAlpha??1).toFixed(2)})]})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.position")}),[["X","x"],["Y","y"],["W","width"],["H","height"]].map(([l,d])=>e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:l}),e.jsx("input",{onChange:m=>g(d,Number(m.target.value)),style:{...w,flex:1},type:"number",value:u?u[d]:0})]},d))]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.textAlign")}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.h")}),e.jsxs("select",{onChange:l=>h("textAlign",l.target.value),style:{...w,flex:1},value:i.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:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.v")}),e.jsxs("select",{onChange:l=>h("textBaseline",l.target.value),style:{...w,flex:1},value:i.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:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.layer")}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[e.jsx("button",{onClick:()=>R(l=>l.top()),style:T,type:"button",children:t("meta2d.props.top")}),e.jsx("button",{onClick:()=>R(l=>l.up()),style:T,type:"button",children:t("meta2d.props.up")}),e.jsx("button",{onClick:()=>R(l=>l.down()),style:T,type:"button",children:t("meta2d.props.down")}),e.jsx("button",{onClick:()=>R(l=>l.bottom()),style:T,type:"button",children:t("meta2d.props.bottom")})]})]})]})}const L={background:"#fff",border:"1px solid #d9d9d9",borderRadius:6,cursor:"pointer",minWidth:68,padding:"6px 12px"},E={...L,fontSize:12,minWidth:52,padding:"4px 10px"};function re(n){c.useEffect(()=>{const t=document.documentElement,i=document.body,r=t.style.overflow,u=i.style.overflow;return t.style.overflow="hidden",i.style.overflow="hidden",()=>{t.style.overflow=r,i.style.overflow=u}},[n])}function me({diagram:n,onClose:t,onSave:i}){const{t:r}=z(),u=c.useRef(null),a=c.useRef(null),f=c.useRef(n),v=c.useRef(t),[p,j]=c.useState(null),[B,k]=c.useState(!1);re(!0),c.useLayoutEffect(()=>{v.current=t}),c.useEffect(()=>{if(!u.current)return;X();const o=new _(u.current,{grid:!0,rule:!1});a.current=o,j(o);try{const g=f.current;g!=null&&g.trim()?o.open(JSON.parse(g)):o.open(H()),F(o.data()),o.render(!0)}catch{o.open(H()),F(o.data()),o.render(!0)}const x=g=>{g.key==="Escape"&&v.current()};return window.addEventListener("keydown",x),()=>{window.removeEventListener("keydown",x);try{o.destroy()}catch{}a.current=null}},[]);const C=async()=>{const o=a.current;if(o){k(!0);try{F(o.data()),o.render(!0);const x=O(o.data()),g=JSON.stringify(x);i(g,await Q(o)||await Y(g)||'<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{k(!1)}}},h=o=>{const x=a.current;x&&o(x)};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:o=>o.stopPropagation(),onWheel:o=>o.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:r("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:()=>h(o=>o.undo()),style:E,title:`${r("meta2d.editor.undo")} (Ctrl+Z)`,type:"button",children:r("meta2d.editor.undo")}),e.jsx("button",{onClick:()=>h(o=>o.redo()),style:E,title:`${r("meta2d.editor.redo")} (Ctrl+Y)`,type:"button",children:r("meta2d.editor.redo")}),e.jsx("button",{onClick:()=>h(o=>o.delete()),style:E,title:r("meta2d.editor.delete"),type:"button",children:r("meta2d.editor.delete")}),e.jsx("button",{onClick:()=>h(o=>o.fitView(!0)),style:E,title:r("meta2d.editor.fit"),type:"button",children:r("meta2d.editor.fit")}),e.jsx("button",{onClick:()=>h(o=>{o.scale(1),o.centerView()}),style:E,title:r("meta2d.editor.zoom100"),type:"button",children:r("meta2d.editor.zoom100")})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:t,style:L,type:"button",children:r("meta2d.editor.close")}),e.jsx("button",{disabled:B,onClick:()=>void C(),style:{...L,background:"#1677ff",border:"none",color:"#fff"},type:"button",children:r(B?"meta2d.editor.saving":"meta2d.editor.save")})]})]})]}),e.jsxs("div",{style:{display:"flex",flex:1,minHeight:0,overflow:"hidden"},children:[e.jsx(ne,{engineRef:a}),e.jsx("div",{ref:u,style:{flex:1,minHeight:0,minWidth:0}}),e.jsx(ie,{engine:p})]})]})})}export{me as DiagramEditor};
@@ -1,4 +1,4 @@
1
- import{r as i,j as n}from"./react-vendor-BuABiQkA.js";import{ad as ke}from"./ui-BQStT3dY.js";import{c as Y,g as Re,u as Ae,a as Ie,d as $e,b as Ye,f as Je,e as Ge,h as Ke,N as Xe,P as Qe,D as je,F as Ce,l as le,S as Se,i as Ze,M as pe,r as et,j as tt,k as nt,m as X,n as at,o as it,p as we}from"./index-BkKvQv2F.js";import{z as ot,A as st,m as de,n as rt,o as ct,p as lt,r as dt,s as ut,t as mt,v as ft,x as ht,B as yt,R as gt,a as xt,b as Me,c as vt,d as bt,e as kt,f as It,g as jt,h as Ct,i as St,w as ue,j as wt,O as Mt,E as Et,q as Nt,l as Dt,C as Rt,D as At}from"./react-GP8hKHRA.js";import{H as Pt,a as Tt,b as Lt,M as Bt,T as _t,S as Ot,W as zt,o as Ht,c as Ee}from"./Toolbar-BHLX-ug4.js";import{V as Ft}from"./VisitorPickerModal-BPyEWlQo.js";import"./motion-DX3HNq_4.js";import"./diagram-CT58wBdU.js";import"./editor-CL03se2B.js";import"./plus-ECzYbQfA.js";import"./copy-BE64wQqi.js";/**
1
+ import{r as i,j as n}from"./react-vendor-BuABiQkA.js";import{ad as ke}from"./ui-RahDNce8.js";import{c as Y,g as Re,u as Ae,a as Ie,d as $e,b as Ye,f as Je,e as Ge,h as Ke,N as Xe,P as Qe,D as je,F as Ce,l as le,S as Se,i as Ze,M as pe,r as et,j as tt,k as nt,m as X,n as at,o as it,p as we}from"./index-DI_31upJ.js";import{z as ot,A as st,m as de,n as rt,o as ct,p as lt,r as dt,s as ut,t as mt,v as ft,x as ht,B as yt,R as gt,a as xt,b as Me,c as vt,d as bt,e as kt,f as It,g as jt,h as Ct,i as St,w as ue,j as wt,O as Mt,E as Et,q as Nt,l as Dt,C as Rt,D as At}from"./react--aHzEjEz.js";import{H as Pt,a as Tt,b as Lt,M as Bt,T as _t,S as Ot,W as zt,o as Ht,c as Ee}from"./Toolbar-Dz9Cn_hv.js";import{V as Ft}from"./VisitorPickerModal-eagVdEZA.js";import"./motion-BgtuAqBE.js";import"./diagram-DtU2xxz3.js";import"./editor-CL03se2B.js";import"./plus-BkiPFt2u.js";import"./copy-BUUKT-QO.js";import"./code-xml-CZsyEkCa.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -23,4 +23,4 @@ import{r as i,j as n}from"./react-vendor-BuABiQkA.js";import{ad as ke}from"./ui-
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const Kt=[["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"}]],Xt=Y("users",Kt),Qt=48;function Q(e){try{const a=e.getDocument("markdown");return typeof a=="string"?a:""}catch{return null}}function Zt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function pt({editor:e,documentId:a,displayName:c,debounceMs:v=1e3,enabled:y=!0,localBaseCommitIdAtEditStart:S,snapshotMeta:w}){const[H,M]=i.useState(!1),[Z,P]=i.useState(!1),[p,b]=i.useState(null),u=i.useRef(null),f=i.useRef(null),k=i.useRef(!1),x=i.useRef(""),I=i.useRef(!1),E=i.useRef(a),ee=i.useRef(c),F=i.useRef(S),T=i.useRef(w);E.current=a,ee.current=c,F.current=S,T.current=w;const j=i.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const s=Zt(e);s!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",E.current,"content preview:",s.slice(0,80)),await Re(E.current).execute(()=>Ae({documentId:E.current,content:s,displayName:ee.current,localBaseCommitIdAtEditStart:F.current,snapshotMeta:T.current})),x.current=Q(e)??x.current,P(!0),M(!1),b(Date.now()),k.current=!0,I.current=!1)},[e]);i.useEffect(()=>{let s=!1;return Ie(a).then(m=>{s||(m?(P(!0),b(m.updatedAt),k.current=!0):(P(!1),b(null),k.current=!1,I.current=!1))}),()=>{s=!0}},[a]),i.useEffect(()=>{var O,L;if(!y){(O=f.current)==null||O.call(f),f.current=null;return}if(!e)return;const s=e.getLexicalEditor();if(!s)return;(L=f.current)==null||L.call(f);let m=!1,h=0,U=0;const g=()=>{if(m)return;const N=Q(e);if(N===null){if(U+=1,U>Qt)return;h=requestAnimationFrame(g);return}x.current=N;const ae=s.registerUpdateListener(()=>{const B=Q(e);B!==null&&B!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",a,"oldLen:",x.current.length,"newLen:",B.length),x.current=B,M(!0),I.current=!0,k.current=!1,u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null,j()},v))});f.current=()=>{ae(),u.current&&(clearTimeout(u.current),u.current=null)}};return queueMicrotask(()=>{m||(h=requestAnimationFrame(g))}),()=>{var N;m=!0,cancelAnimationFrame(h),(N=f.current)==null||N.call(f)}},[y,e,a,c,v,S,w,j]),i.useEffect(()=>{var h;if(!y||!e)return;const s=(h=e.getLexicalEditor())==null?void 0:h.getRootElement();if(!s)return;const m=()=>{u.current&&(clearTimeout(u.current),u.current=null),I.current&&j()};return s.addEventListener("blur",m),()=>s.removeEventListener("blur",m)},[y,e,j]),i.useEffect(()=>{if(!y)return;const s=()=>{document.visibilityState==="hidden"&&(u.current&&(clearTimeout(u.current),u.current=null),I.current&&j())},m=()=>{I.current&&(u.current&&(clearTimeout(u.current),u.current=null),j())};return document.addEventListener("visibilitychange",s),window.addEventListener("beforeunload",m),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("beforeunload",m)}},[y,j]);async function te(){await $e(a),P(!1),M(!1),I.current=!1,k.current=!1,x.current=""}async function J(){const s=await Ie(a);return s?s.content:null}function ne(){P(!0),M(!1),I.current=!1,b(Date.now()),k.current=!0,e&&(x.current=Q(e)??"")}return{isDirty:H,draftExists:Z,lastSavedAt:p,clearDraft:te,loadDraftContent:J,markDraftSaved:ne}}function en({isDirty:e,draftExists:a}){const c=e&&!a;i.useEffect(()=>{if(!c)return;const v=y=>{y.preventDefault()};return window.addEventListener("beforeunload",v),()=>window.removeEventListener("beforeunload",v)},[c])}function me(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Ne='{"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 De(e){const c=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(c)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(c)?"不支持的文件类型":/^not an image$/i.test(c)?"不是有效的图片文件":c||"上传失败"}function tn(e,a){if(!e)return a==="json"?Ne:e;if(a!=="json")return e;try{const c=JSON.parse(e);if(c!=null&&c.root&&Array.isArray(c.root.children)&&c.root.children.length===0)return Ne}catch{}return e}function nn({editor:e}){const{visible:a}=Rt();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(At,{editor:e})})})}function yn(e){const{t:a,lang:c}=Ye(),[v,y]=i.useState(!1),[S,w]=i.useState(!1),H=i.useRef(null),M=i.useRef(null),[Z,P]=i.useState([]),[p,b]=i.useState(!1),[u,f]=i.useState(e.meta.permission),[k,x]=i.useState(!1),[I,E]=i.useState(!1),[ee,F]=i.useState(!1),[T,j]=i.useState(new Map),[te,J]=i.useState(!1);i.useEffect(()=>{const t=o=>{H.current&&!H.current.contains(o.target)&&y(!1),M.current&&!M.current.contains(o.target)&&w(!1)};return(v||S)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[v,S]),i.useEffect(()=>{let t=!0;return Je().then(o=>{t&&P(o)}).catch(()=>{}),()=>{t=!1}},[]);function ne(t){const o=Z.find(l=>l.visitorId===t);return(o==null?void 0:o.visitorName)??t.slice(0,8)}const[s,m]=i.useState(e.initialDisplayName),[h,U]=i.useState(!1),[g,O]=i.useState(!1),[L,N]=i.useState(!1),[ae,B]=i.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),D=e.canEdit&&ae,[d,fe]=i.useState(null),[Pe,he]=i.useState(!1),ie=i.useRef(null);i.useLayoutEffect(()=>{he(!1),fe(null),ie.current=null},[e.meta.documentId]),i.useEffect(()=>{const t=requestAnimationFrame(()=>he(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]);const R=i.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const o=JSON.parse(e.initialContent);return Array.isArray((t=o==null?void 0:o.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),W=i.useMemo(()=>tn(e.initialContent||"",R),[e.initialContent,R,e.contentRevision]),{isDirty:ye,draftExists:q,markDraftSaved:Te}=pt({editor:d,documentId:e.meta.documentId,displayName:s,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,q)},[q,e.onDraftExistsChange]),en({isDirty:ye,draftExists:q}),i.useEffect(()=>{if(d)try{d.setDocument(R,W)}catch{}},[d,e.meta.documentId,e.contentRevision,W,R]),i.useEffect(()=>{d==null||d.setLocale(c==="zh"?ot:st)},[d,c]),i.useEffect(()=>{m(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),i.useEffect(()=>{f(e.meta.permission)},[e.meta.permission,e.meta.documentId]),i.useEffect(()=>{let t=!0;return(async()=>{try{const o=await Ge(e.meta.documentId);t&&O(o.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function oe(){var t,o;if(!L){N(!0);try{g?(await et(e.meta.documentId),O(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await tt(e.meta.documentId),O(!0),(o=e.onShowToast)==null||o.call(e,a("bookmarkAdded")))}finally{N(!1)}}}i.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=Fe),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),i.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ie.current;if(!t)return"";try{const o=t.getDocument("markdown");return typeof o=="string"?o:String(o??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function Le(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=>{ie.current=t,fe(t);const o=W;if(!o)return;const l=()=>{try{t.setDocument(R,o)}catch{requestAnimationFrame(()=>{try{t.setDocument(R,o)}catch{}})}};queueMicrotask(()=>{queueMicrotask(l)})},[R,W]);async function se(){if(!(!d||!e.canEdit)){U(!0);try{const t=me(d);if(!t)return;await e.onPublish(t,s,e.meta.documentId)}catch(t){throw t}finally{U(!1)}}}async function ge(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(s.trim()!==t)try{await se()}catch{}}const A=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),_e=i.useMemo(()=>{const t=(A==null?void 0:A.permission)??"public";return Ke(t)},[A==null?void 0:A.permission]);function Oe(t){return t===X.PRIVATE?a("permissionPrivate"):t===X.DOMAIN_READ?a("permissionInvite"):t===X.DOMAIN_WRITE?a("permissionDomainWrite"):t===X.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function ze(){var t;if(k||u===e.meta.permission){b(!1);return}x(!0);try{const l=(d?me(d):null)??e.initialContent;await e.onPublish(l,s,e.meta.documentId,u),b(!1),(t=e.onShowToast)==null||t.call(e,a("docInfoPermissionUpdated"))}finally{x(!1)}}async function He(t){var o;if(!te){J(!0);try{const l=new Set(t.map(r=>r.visitorId)),_=new Map(t.map(r=>[r.visitorId,r.permission]));for(const[r]of T)l.has(r)||await at(e.meta.documentId,r);for(const{visitorId:r,permission:V}of t){const $=T.get(r);(!$||$!==V)&&await it(e.meta.documentId,r,V)}E(!1),(o=e.onShowToast)==null||o.call(e,a("docInfoInviteSuccess",{count:t.length}))}finally{J(!1)}}}async function Fe(){if(!d||!e.canEdit)return;if(!ye){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=me(d);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),Te(),await Re(e.meta.documentId).execute(()=>Ae({documentId:e.meta.documentId,content:t,displayName:s,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const Ue=i.useMemo(()=>[{icon:Pt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(de,{tag:"h1"})}},{icon:Tt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(de,{tag:"h2"})}},{icon:Lt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(de,{tag:"h3"})}},{type:"divider"},{icon:Bt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(rt,{})}},{icon:_t,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(ct,{columns:"3",rows:"3"})}},{icon:Ot,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(lt,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{Ht(o=>{for(const l of o)t.dispatchCommand(Nt,{file:l})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(dt,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(ut,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(mt,void 0),queueMicrotask(()=>t.focus())}},{icon:zt,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(ft,void 0),queueMicrotask(()=>t.focus())}},{icon:Xe,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ht,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})}),[]),We=i.useMemo(()=>[yt,gt,xt,Me,vt,bt,kt,It,jt,Ct,St,ue(wt,{children:d?n.jsx(Ee,{editor:d,floating:!0,outlineCollapseTitle:a("outlineHide"),outlineExpandTitle:a("outlineShow"),outlineToggle:!0}):null}),ue(Dt,{handleUpload:async t=>{var o;try{return{url:await we(t,e.meta.documentId)}}catch(l){throw(o=e.onShowError)==null||o.call(e,De(l)),l}}}),ue(Me,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var o;try{const _=await(await fetch(t)).blob(),r=new File([_],"image.png",{type:_.type});return{url:await we(r,e.meta.documentId)}}catch(l){throw(o=e.onShowError)==null||o.call(e,De(l)),l}}})],[d,a,e.meta.documentId,e.onShowError]),C=!!e.readerChrome,[z,re]=i.useState(!1),G=i.useRef(null),[xe,ce]=i.useState(0);i.useEffect(()=>{if(!C){re(!1),ce(0);return}if(z)return;const t=window.setTimeout(()=>re(!0),2800);return()=>window.clearTimeout(t)},[C,z,e.meta.documentId]),i.useEffect(()=>{w(!1),y(!1)},[e.meta.documentId]);function qe(t){!C||z||t.target.closest("button, a, input, textarea, select")||(G.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function Ve(t){const o=G.current;if(!(o!=null&&o.dragging))return;const l=t.clientY-o.startY;ce(Math.max(-72,Math.min(0,l)))}function ve(t){const o=G.current;if(!(o!=null&&o.dragging))return;G.current=null;const l=t.clientY-o.startY;ce(0),l<-36&&re(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function K(){y(!1),w(!1)}function be(t,o){const l=(o==null?void 0:o.includeBookmark)??!0,_={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{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:ne(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(c==="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:Le(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(c==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),l?n.jsxs("button",{type:"button",style:_,onMouseEnter:r=>{r.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:r=>{r.currentTarget.style.background="none"},onClick:()=>{oe(),t()},children:[n.jsx("span",{children:g?"⭐":"☆"}),n.jsx("span",{children:a(g?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:_,onMouseEnter:r=>{r.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:r=>{r.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{F(!0);try{const r=await nt(e.meta.documentId),V=new Map(r.map($=>[$.visitorId,$.permission]));j(V),E(!0)}finally{F(!1)}})()},children:[n.jsx(Xt,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:_,onMouseEnter:r=>{r.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:r=>{r.currentTarget.style.background="none"},onClick:()=>{t(),f(e.meta.permission),b(!0)},children:[n.jsx(Yt,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}return n.jsxs("div",{className:"mdocs-editor"+(C?" mdocs-editor--reader":"")+(C&&z?" mdocs-editor--reader-docked":""),children:[n.jsx("div",{className:"mdocs-editor-toolbar"+(C?z?" mdocs-editor-toolbar--docked":" mdocs-editor-toolbar--float":""),style:C&&!z&&xe!==0?{transform:`translateY(${xe}px)`}:void 0,children:C?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",onPointerDown:qe,onPointerMove:Ve,onPointerUp:ve,onPointerCancel:ve,children:[n.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>{var t;return(t=e.onOpenMobileNav)==null?void 0:t.call(e)},"aria-label":a("expandSidebar"),children:n.jsx(Qe,{size:18,strokeWidth:1.75})}),n.jsx("input",{className:"mdocs-editor-title-input",value:s,onChange:t=>m(t.target.value),onBlur:()=>void ge(),placeholder:a("displayNamePlaceholder"),disabled:!D,readOnly:!D})]}),n.jsx(je,{domains:e.domains.length?e.domains:[Ce],value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:t=>le(t,c,a)}),e.canEdit?n.jsx("button",{type:"button",className:"primary mdocs-reader-action-btn",disabled:h,onClick:()=>{D||B(!0),se().catch(()=>{})},children:a(h?"publishing":"publish")}):null,n.jsxs("div",{ref:M,className:"mdocs-reader-more-menu",children:[n.jsx("button",{type:"button",className:"mdocs-reader-more-btn","aria-label":"更多","aria-expanded":S,onClick:()=>w(t=>!t),children:n.jsx(Wt,{size:18,strokeWidth:1.75})}),S?n.jsxs("div",{className:"mdocs-reader-more-dropdown card",children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:L,onClick:()=>{oe(),K()},children:[n.jsx(Se,{size:16,strokeWidth:1.5,style:{color:g?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:g?"#faad14":"none"}}),n.jsx("span",{children:a(g?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:h,onClick:()=>{K(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),be(K,{includeBookmark:!1})]}):null]})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",children:[n.jsx("input",{className:"mdocs-editor-title-input",value:s,onChange:t=>m(t.target.value),onBlur:()=>void ge(),placeholder:a("displayNamePlaceholder"),disabled:!D}),n.jsx(je,{domains:e.domains.length?e.domains:[Ce],value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:t=>le(t,c,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:Ze,alt:"",width:16,height:16,style:{display:"block"}}),"帮写"]}):null]}),n.jsx("span",{className:"mdocs-editor-toolbar-spacer","aria-hidden":!0}),n.jsxs("div",{className:"mdocs-editor-toolbar-trailing",children:[n.jsxs("button",{type:"button",className:"secondary mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>void oe(),disabled:L,"data-tooltip":g?"取消收藏":"收藏",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,opacity:L?.5:1},children:[n.jsx(Se,{size:18,strokeWidth:1.5,style:{color:g?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:g?"#faad14":"none"}}),g?n.jsx("span",{children:"已收藏"}):null]}),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(Vt,{size:16,strokeWidth:1.5}),n.jsx("span",{children:a("syncPull")})]}):null,D?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 "+(h?"saving":q?"unsaved":"saved")}),n.jsx("span",{children:a(h?"publishing":q?"unsaved":"published")})]}),n.jsx("button",{type:"button",className:"primary",disabled:h,onClick:()=>{se().catch(()=>{})},children:a(h?"publishing":"publish")}),n.jsx("button",{type:"button",className:"danger",disabled:h,onClick:e.onDelete,children:a("delete")})]}):null,!D&&e.canEdit?n.jsx("button",{type:"button",className:"primary",onClick:()=>B(!0),children:a("edit")}):null,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(pe,{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}):null]}),n.jsxs("div",{ref:H,className:"mdocs-tooltip mdocs-tooltip-bottom","data-tooltip":a("docInfo"),style:{position:"relative"},children:[n.jsx("button",{type:"button",className:"secondary",onClick:()=>y(!v),style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx(Gt,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}})}),v?n.jsx("div",{className:"mdocs-doc-info-dropdown",children:be(K)}):null]})]})]})]})}),p&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&b(!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"),":",A?le(A.domainName,c,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:_e.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:u===t,onChange:()=>f(t)}),n.jsx("span",{children:Oe(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>b(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:k,onClick:()=>void ze(),children:a(k?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Ft,{open:I,title:a("docInfoInviteMember"),initialSelectedIds:[...T.keys()],initialPermissions:T,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>E(!1),onConfirm:t=>{He(t)}}),n.jsx(Mt,{children:n.jsx(ke,{flex:1,style:{minHeight:0},children:n.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[D&&d&&!C?n.jsx(Ee,{editor:d,outlineCollapseTitle:a("outlineHide"),outlineExpandTitle:a("outlineShow"),outlineToggle:!0}):null,n.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:n.jsxs(ke,{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:Pe?n.jsx(Et,{content:W,type:R,confirmPasteMarkdown:!0,editable:D,onInit:Be,plugins:We,lineEmptyPlaceholder:a("displayNamePlaceholder"),placeholder:a("displayNamePlaceholder"),slashOption:{items:Ue},className:"mdocs-document-editor-root"},e.meta.documentId):null}),d&&n.jsx(nn,{editor:d})]})})]})})})]})}export{yn as DocumentEditor};
26
+ */const Kt=[["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"}]],Xt=Y("users",Kt),Qt=48;function Q(e){try{const a=e.getDocument("markdown");return typeof a=="string"?a:""}catch{return null}}function Zt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function pt({editor:e,documentId:a,displayName:c,debounceMs:v=1e3,enabled:y=!0,localBaseCommitIdAtEditStart:S,snapshotMeta:w}){const[H,M]=i.useState(!1),[Z,P]=i.useState(!1),[p,b]=i.useState(null),u=i.useRef(null),f=i.useRef(null),k=i.useRef(!1),x=i.useRef(""),I=i.useRef(!1),E=i.useRef(a),ee=i.useRef(c),F=i.useRef(S),T=i.useRef(w);E.current=a,ee.current=c,F.current=S,T.current=w;const j=i.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const s=Zt(e);s!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",E.current,"content preview:",s.slice(0,80)),await Re(E.current).execute(()=>Ae({documentId:E.current,content:s,displayName:ee.current,localBaseCommitIdAtEditStart:F.current,snapshotMeta:T.current})),x.current=Q(e)??x.current,P(!0),M(!1),b(Date.now()),k.current=!0,I.current=!1)},[e]);i.useEffect(()=>{let s=!1;return Ie(a).then(m=>{s||(m?(P(!0),b(m.updatedAt),k.current=!0):(P(!1),b(null),k.current=!1,I.current=!1))}),()=>{s=!0}},[a]),i.useEffect(()=>{var O,L;if(!y){(O=f.current)==null||O.call(f),f.current=null;return}if(!e)return;const s=e.getLexicalEditor();if(!s)return;(L=f.current)==null||L.call(f);let m=!1,h=0,U=0;const g=()=>{if(m)return;const N=Q(e);if(N===null){if(U+=1,U>Qt)return;h=requestAnimationFrame(g);return}x.current=N;const ae=s.registerUpdateListener(()=>{const B=Q(e);B!==null&&B!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",a,"oldLen:",x.current.length,"newLen:",B.length),x.current=B,M(!0),I.current=!0,k.current=!1,u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null,j()},v))});f.current=()=>{ae(),u.current&&(clearTimeout(u.current),u.current=null)}};return queueMicrotask(()=>{m||(h=requestAnimationFrame(g))}),()=>{var N;m=!0,cancelAnimationFrame(h),(N=f.current)==null||N.call(f)}},[y,e,a,c,v,S,w,j]),i.useEffect(()=>{var h;if(!y||!e)return;const s=(h=e.getLexicalEditor())==null?void 0:h.getRootElement();if(!s)return;const m=()=>{u.current&&(clearTimeout(u.current),u.current=null),I.current&&j()};return s.addEventListener("blur",m),()=>s.removeEventListener("blur",m)},[y,e,j]),i.useEffect(()=>{if(!y)return;const s=()=>{document.visibilityState==="hidden"&&(u.current&&(clearTimeout(u.current),u.current=null),I.current&&j())},m=()=>{I.current&&(u.current&&(clearTimeout(u.current),u.current=null),j())};return document.addEventListener("visibilitychange",s),window.addEventListener("beforeunload",m),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("beforeunload",m)}},[y,j]);async function te(){await $e(a),P(!1),M(!1),I.current=!1,k.current=!1,x.current=""}async function J(){const s=await Ie(a);return s?s.content:null}function ne(){P(!0),M(!1),I.current=!1,b(Date.now()),k.current=!0,e&&(x.current=Q(e)??"")}return{isDirty:H,draftExists:Z,lastSavedAt:p,clearDraft:te,loadDraftContent:J,markDraftSaved:ne}}function en({isDirty:e,draftExists:a}){const c=e&&!a;i.useEffect(()=>{if(!c)return;const v=y=>{y.preventDefault()};return window.addEventListener("beforeunload",v),()=>window.removeEventListener("beforeunload",v)},[c])}function me(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Ne='{"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 De(e){const c=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(c)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(c)?"不支持的文件类型":/^not an image$/i.test(c)?"不是有效的图片文件":c||"上传失败"}function tn(e,a){if(!e)return a==="json"?Ne:e;if(a!=="json")return e;try{const c=JSON.parse(e);if(c!=null&&c.root&&Array.isArray(c.root.children)&&c.root.children.length===0)return Ne}catch{}return e}function nn({editor:e}){const{visible:a}=Rt();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(At,{editor:e})})})}function gn(e){const{t:a,lang:c}=Ye(),[v,y]=i.useState(!1),[S,w]=i.useState(!1),H=i.useRef(null),M=i.useRef(null),[Z,P]=i.useState([]),[p,b]=i.useState(!1),[u,f]=i.useState(e.meta.permission),[k,x]=i.useState(!1),[I,E]=i.useState(!1),[ee,F]=i.useState(!1),[T,j]=i.useState(new Map),[te,J]=i.useState(!1);i.useEffect(()=>{const t=o=>{H.current&&!H.current.contains(o.target)&&y(!1),M.current&&!M.current.contains(o.target)&&w(!1)};return(v||S)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[v,S]),i.useEffect(()=>{let t=!0;return Je().then(o=>{t&&P(o)}).catch(()=>{}),()=>{t=!1}},[]);function ne(t){const o=Z.find(l=>l.visitorId===t);return(o==null?void 0:o.visitorName)??t.slice(0,8)}const[s,m]=i.useState(e.initialDisplayName),[h,U]=i.useState(!1),[g,O]=i.useState(!1),[L,N]=i.useState(!1),[ae,B]=i.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),D=e.canEdit&&ae,[d,fe]=i.useState(null),[Pe,he]=i.useState(!1),ie=i.useRef(null);i.useLayoutEffect(()=>{he(!1),fe(null),ie.current=null},[e.meta.documentId]),i.useEffect(()=>{const t=requestAnimationFrame(()=>he(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]);const R=i.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const o=JSON.parse(e.initialContent);return Array.isArray((t=o==null?void 0:o.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),W=i.useMemo(()=>tn(e.initialContent||"",R),[e.initialContent,R,e.contentRevision]),{isDirty:ye,draftExists:q,markDraftSaved:Te}=pt({editor:d,documentId:e.meta.documentId,displayName:s,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,q)},[q,e.onDraftExistsChange]),en({isDirty:ye,draftExists:q}),i.useEffect(()=>{if(d)try{d.setDocument(R,W)}catch{}},[d,e.meta.documentId,e.contentRevision,W,R]),i.useEffect(()=>{d==null||d.setLocale(c==="zh"?ot:st)},[d,c]),i.useEffect(()=>{m(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),i.useEffect(()=>{f(e.meta.permission)},[e.meta.permission,e.meta.documentId]),i.useEffect(()=>{let t=!0;return(async()=>{try{const o=await Ge(e.meta.documentId);t&&O(o.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function oe(){var t,o;if(!L){N(!0);try{g?(await et(e.meta.documentId),O(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await tt(e.meta.documentId),O(!0),(o=e.onShowToast)==null||o.call(e,a("bookmarkAdded")))}finally{N(!1)}}}i.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=Fe),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),i.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ie.current;if(!t)return"";try{const o=t.getDocument("markdown");return typeof o=="string"?o:String(o??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function Le(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=>{ie.current=t,fe(t);const o=W;if(!o)return;const l=()=>{try{t.setDocument(R,o)}catch{requestAnimationFrame(()=>{try{t.setDocument(R,o)}catch{}})}};queueMicrotask(()=>{queueMicrotask(l)})},[R,W]);async function se(){if(!(!d||!e.canEdit)){U(!0);try{const t=me(d);if(!t)return;await e.onPublish(t,s,e.meta.documentId)}catch(t){throw t}finally{U(!1)}}}async function ge(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(s.trim()!==t)try{await se()}catch{}}const A=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),_e=i.useMemo(()=>{const t=(A==null?void 0:A.permission)??"public";return Ke(t)},[A==null?void 0:A.permission]);function Oe(t){return t===X.PRIVATE?a("permissionPrivate"):t===X.DOMAIN_READ?a("permissionInvite"):t===X.DOMAIN_WRITE?a("permissionDomainWrite"):t===X.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function ze(){var t;if(k||u===e.meta.permission){b(!1);return}x(!0);try{const l=(d?me(d):null)??e.initialContent;await e.onPublish(l,s,e.meta.documentId,u),b(!1),(t=e.onShowToast)==null||t.call(e,a("docInfoPermissionUpdated"))}finally{x(!1)}}async function He(t){var o;if(!te){J(!0);try{const l=new Set(t.map(r=>r.visitorId)),_=new Map(t.map(r=>[r.visitorId,r.permission]));for(const[r]of T)l.has(r)||await at(e.meta.documentId,r);for(const{visitorId:r,permission:V}of t){const $=T.get(r);(!$||$!==V)&&await it(e.meta.documentId,r,V)}E(!1),(o=e.onShowToast)==null||o.call(e,a("docInfoInviteSuccess",{count:t.length}))}finally{J(!1)}}}async function Fe(){if(!d||!e.canEdit)return;if(!ye){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=me(d);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),Te(),await Re(e.meta.documentId).execute(()=>Ae({documentId:e.meta.documentId,content:t,displayName:s,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const Ue=i.useMemo(()=>[{icon:Pt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(de,{tag:"h1"})}},{icon:Tt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(de,{tag:"h2"})}},{icon:Lt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(de,{tag:"h3"})}},{type:"divider"},{icon:Bt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(rt,{})}},{icon:_t,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(ct,{columns:"3",rows:"3"})}},{icon:Ot,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(lt,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{Ht(o=>{for(const l of o)t.dispatchCommand(Nt,{file:l})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(dt,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(ut,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(mt,void 0),queueMicrotask(()=>t.focus())}},{icon:zt,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(ft,void 0),queueMicrotask(()=>t.focus())}},{icon:Xe,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ht,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})}),[]),We=i.useMemo(()=>[yt,gt,xt,Me,vt,bt,kt,It,jt,Ct,St,ue(wt,{children:d?n.jsx(Ee,{editor:d,floating:!0,outlineCollapseTitle:a("outlineHide"),outlineExpandTitle:a("outlineShow"),outlineToggle:!0}):null}),ue(Dt,{handleUpload:async t=>{var o;try{return{url:await we(t,e.meta.documentId)}}catch(l){throw(o=e.onShowError)==null||o.call(e,De(l)),l}}}),ue(Me,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var o;try{const _=await(await fetch(t)).blob(),r=new File([_],"image.png",{type:_.type});return{url:await we(r,e.meta.documentId)}}catch(l){throw(o=e.onShowError)==null||o.call(e,De(l)),l}}})],[d,a,e.meta.documentId,e.onShowError]),C=!!e.readerChrome,[z,re]=i.useState(!1),G=i.useRef(null),[xe,ce]=i.useState(0);i.useEffect(()=>{if(!C){re(!1),ce(0);return}if(z)return;const t=window.setTimeout(()=>re(!0),2800);return()=>window.clearTimeout(t)},[C,z,e.meta.documentId]),i.useEffect(()=>{w(!1),y(!1)},[e.meta.documentId]);function qe(t){!C||z||t.target.closest("button, a, input, textarea, select")||(G.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function Ve(t){const o=G.current;if(!(o!=null&&o.dragging))return;const l=t.clientY-o.startY;ce(Math.max(-72,Math.min(0,l)))}function ve(t){const o=G.current;if(!(o!=null&&o.dragging))return;G.current=null;const l=t.clientY-o.startY;ce(0),l<-36&&re(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function K(){y(!1),w(!1)}function be(t,o){const l=(o==null?void 0:o.includeBookmark)??!0,_={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{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:ne(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(c==="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:Le(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(c==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),l?n.jsxs("button",{type:"button",style:_,onMouseEnter:r=>{r.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:r=>{r.currentTarget.style.background="none"},onClick:()=>{oe(),t()},children:[n.jsx("span",{children:g?"⭐":"☆"}),n.jsx("span",{children:a(g?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:_,onMouseEnter:r=>{r.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:r=>{r.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{F(!0);try{const r=await nt(e.meta.documentId),V=new Map(r.map($=>[$.visitorId,$.permission]));j(V),E(!0)}finally{F(!1)}})()},children:[n.jsx(Xt,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:_,onMouseEnter:r=>{r.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:r=>{r.currentTarget.style.background="none"},onClick:()=>{t(),f(e.meta.permission),b(!0)},children:[n.jsx(Yt,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}return n.jsxs("div",{className:"mdocs-editor"+(C?" mdocs-editor--reader":"")+(C&&z?" mdocs-editor--reader-docked":""),children:[n.jsx("div",{className:"mdocs-editor-toolbar"+(C?z?" mdocs-editor-toolbar--docked":" mdocs-editor-toolbar--float":""),style:C&&!z&&xe!==0?{transform:`translateY(${xe}px)`}:void 0,children:C?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",onPointerDown:qe,onPointerMove:Ve,onPointerUp:ve,onPointerCancel:ve,children:[n.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>{var t;return(t=e.onOpenMobileNav)==null?void 0:t.call(e)},"aria-label":a("expandSidebar"),children:n.jsx(Qe,{size:18,strokeWidth:1.75})}),n.jsx("input",{className:"mdocs-editor-title-input",value:s,onChange:t=>m(t.target.value),onBlur:()=>void ge(),placeholder:a("displayNamePlaceholder"),disabled:!D,readOnly:!D})]}),n.jsx(je,{domains:e.domains.length?e.domains:[Ce],value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:t=>le(t,c,a)}),e.canEdit?n.jsx("button",{type:"button",className:"primary mdocs-reader-action-btn",disabled:h,onClick:()=>{D||B(!0),se().catch(()=>{})},children:a(h?"publishing":"publish")}):null,n.jsxs("div",{ref:M,className:"mdocs-reader-more-menu",children:[n.jsx("button",{type:"button",className:"mdocs-reader-more-btn","aria-label":"更多","aria-expanded":S,onClick:()=>w(t=>!t),children:n.jsx(Wt,{size:18,strokeWidth:1.75})}),S?n.jsxs("div",{className:"mdocs-reader-more-dropdown card",children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:L,onClick:()=>{oe(),K()},children:[n.jsx(Se,{size:16,strokeWidth:1.5,style:{color:g?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:g?"#faad14":"none"}}),n.jsx("span",{children:a(g?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:h,onClick:()=>{K(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),be(K,{includeBookmark:!1})]}):null]})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",children:[n.jsx("input",{className:"mdocs-editor-title-input",value:s,onChange:t=>m(t.target.value),onBlur:()=>void ge(),placeholder:a("displayNamePlaceholder"),disabled:!D}),n.jsx(je,{domains:e.domains.length?e.domains:[Ce],value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:t=>le(t,c,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:Ze,alt:"",width:16,height:16,style:{display:"block"}}),"帮写"]}):null]}),n.jsx("span",{className:"mdocs-editor-toolbar-spacer","aria-hidden":!0}),n.jsxs("div",{className:"mdocs-editor-toolbar-trailing",children:[n.jsxs("button",{type:"button",className:"secondary mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>void oe(),disabled:L,"data-tooltip":g?"取消收藏":"收藏",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,opacity:L?.5:1},children:[n.jsx(Se,{size:18,strokeWidth:1.5,style:{color:g?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:g?"#faad14":"none"}}),g?n.jsx("span",{children:"已收藏"}):null]}),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(Vt,{size:16,strokeWidth:1.5}),n.jsx("span",{children:a("syncPull")})]}):null,D?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 "+(h?"saving":q?"unsaved":"saved")}),n.jsx("span",{children:a(h?"publishing":q?"unsaved":"published")})]}),n.jsx("button",{type:"button",className:"primary",disabled:h,onClick:()=>{se().catch(()=>{})},children:a(h?"publishing":"publish")}),n.jsx("button",{type:"button",className:"danger",disabled:h,onClick:e.onDelete,children:a("delete")})]}):null,!D&&e.canEdit?n.jsx("button",{type:"button",className:"primary",onClick:()=>B(!0),children:a("edit")}):null,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(pe,{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}):null]}),n.jsxs("div",{ref:H,className:"mdocs-tooltip mdocs-tooltip-bottom","data-tooltip":a("docInfo"),style:{position:"relative"},children:[n.jsx("button",{type:"button",className:"secondary",onClick:()=>y(!v),style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx(Gt,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}})}),v?n.jsx("div",{className:"mdocs-doc-info-dropdown",children:be(K)}):null]})]})]})]})}),p&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&b(!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"),":",A?le(A.domainName,c,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:_e.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:u===t,onChange:()=>f(t)}),n.jsx("span",{children:Oe(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>b(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:k,onClick:()=>void ze(),children:a(k?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Ft,{open:I,title:a("docInfoInviteMember"),initialSelectedIds:[...T.keys()],initialPermissions:T,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>E(!1),onConfirm:t=>{He(t)}}),n.jsx(Mt,{children:n.jsx(ke,{flex:1,style:{minHeight:0},children:n.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[D&&d&&!C?n.jsx(Ee,{editor:d,outlineCollapseTitle:a("outlineHide"),outlineExpandTitle:a("outlineShow"),outlineToggle:!0}):null,n.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:n.jsxs(ke,{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:Pe?n.jsx(Et,{content:W,type:R,confirmPasteMarkdown:!0,editable:D,onInit:Be,plugins:We,lineEmptyPlaceholder:a("displayNamePlaceholder"),placeholder:a("displayNamePlaceholder"),slashOption:{items:Ue},className:"mdocs-document-editor-root"},e.meta.documentId):null}),d&&n.jsx(nn,{editor:d})]})})]})})})]})}export{gn as DocumentEditor};
@@ -1,4 +1,4 @@
1
- import{r as b,j as o}from"./react-vendor-BuABiQkA.js";import{b as V,av as _,aw as J,ax as Q,ay as X}from"./index-BkKvQv2F.js";import{E as Y,B as Z}from"./react-GP8hKHRA.js";import"./ui-BQStT3dY.js";import"./motion-DX3HNq_4.js";import"./diagram-CT58wBdU.js";import"./editor-CL03se2B.js";import"./plus-ECzYbQfA.js";import"./copy-BE64wQqi.js";function B({lexicalJson:e,onMarkdown:n,onError:s}){const[u,l]=b.useState(null),i=b.useRef(!1);return b.useEffect(()=>{i.current=!1},[e]),b.useEffect(()=>{if(!(!u||i.current))try{u.setDocument("json",e);const c=u.getDocument("markdown");typeof c=="string"&&(i.current=!0,n(c))}catch{s==null||s()}},[u,e,n,s]),o.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:o.jsx(Y,{content:e,type:"json",editable:!1,onInit:l,plugins:[Z]})})}function ee(e){const{t:n}=V(),[s,u]=b.useState(0),l=e.segments.filter(t=>t.kind==="conflict"),i=e.unresolvedCount>0;b.useEffect(()=>{if(l.length===0){u(0);return}u(t=>Math.min(t,l.length-1))},[l.length]);function c(t){l.length!==0&&u(d=>{var f;const a=(d+t+l.length)%l.length;return(f=document.getElementById(`mdocs-merge-hunk-${a}`))==null||f.scrollIntoView({block:"center",behavior:"smooth"}),a})}let r=-1;return o.jsxs("div",{className:"mdocs-merge-inline-pane",children:[o.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[o.jsx("span",{className:"mdocs-merge-inline-hint",children:i?n("mergeReviewHint"):l.length===0?n("mergeNoConflicts"):n("mergeEditAfterResolve")}),l.length>0?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:e.onUseAllMine,children:n("mergeUseAllMine")}),o.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:n("mergeUseAllTheirs")})]}):null]}),i?o.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((t,d)=>{if(t.kind==="unchanged")return o.jsx("pre",{className:"mdocs-merge-inline-same",children:t.lines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},g))},`u-${d}`);r+=1;const a=r,f=t.resolution!=="unresolved",m=a===s;return o.jsxs("div",{id:`mdocs-merge-hunk-${a}`,className:"mdocs-merge-inline-hunk"+(m?" is-active":"")+(f?" is-resolved":""),onClick:()=>u(a),children:[f?o.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:t.resolution==="remote"?n("mergeReceive"):n("mergeReject")}):o.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:x=>{x.stopPropagation(),e.onReject(t.id)},children:n("mergeReject")}),o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:x=>{x.stopPropagation(),e.onReceive(t.id)},children:n("mergeReceive")})]}),o.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[t.localLines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line del",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},`l${g}`)),t.remoteLines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line add",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},`r${g}`))]})]},t.id)}),l.length>0?o.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[o.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>c(-1),children:"↑"}),o.jsxs("span",{children:[s+1," / ",l.length]}),o.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>c(1),children:"↓"}),l[s]&&l[s].resolution==="unresolved"?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(l[s].id),children:n("mergeReject")}),o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(l[s].id),children:n("mergeReceive")})]}):null]}):null]}):o.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:t=>e.onEditableChange(t.target.value),spellCheck:!1})]})}function te(e,n){let s={};for(let i=0;i<n.length;i++){const c=n[i];s[c]?s[c].push(i):s[c]=[i]}let l=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let i=0;i<e.length;i++){const c=e[i],r=s[c]||[];let t=0,d=l[0];for(let a=0;a<r.length;a++){const f=r[a];let m;for(m=t;m<l.length&&!(l[m].buffer2index<f&&(m===l.length-1||l[m+1].buffer2index>f));m++);if(m<l.length){const x={buffer1index:i,buffer2index:f,chain:l[m]};if(t===l.length?l.push(d):l[t]=d,t=m+1,d=x,t===l.length)break}}l[t]=d}return l[l.length-1]}function q(e,n){const s=te(e,n);let u=[],l=e.length,i=n.length;for(let c=s;c!==null;c=c.chain){const r=l-c.buffer1index-1,t=i-c.buffer2index-1;l=c.buffer1index,i=c.buffer2index,(r||t)&&u.push({buffer1:[l+1,r],buffer1Content:e.slice(l+1,l+1+r),buffer2:[i+1,t],buffer2Content:n.slice(i+1,i+1+t)})}return u.reverse(),u}function ne(e,n,s){let u=[];function l(t,d){u.push({ab:d,oStart:t.buffer1[0],oLength:t.buffer1[1],abStart:t.buffer2[0],abLength:t.buffer2[1]})}q(n,e).forEach(t=>l(t,"a")),q(n,s).forEach(t=>l(t,"b")),u.sort((t,d)=>t.oStart-d.oStart);let i=[],c=0;function r(t){t>c&&(i.push({stable:!0,buffer:"o",bufferStart:c,bufferLength:t-c,bufferContent:n.slice(c,t)}),c=t)}for(;u.length;){let t=u.shift(),d=t.oStart,a=t.oStart+t.oLength,f=[t];for(r(d);u.length;){const m=u[0],x=m.oStart;if(x>a)break;a=Math.max(a,x+m.oLength),f.push(u.shift())}if(f.length===1){if(t.abLength>0){const m=t.ab==="a"?e:s;i.push({stable:!0,buffer:t.ab,bufferStart:t.abStart,bufferLength:t.abLength,bufferContent:m.slice(t.abStart,t.abStart+t.abLength)})}}else{let m={a:[e.length,-1,n.length,-1],b:[s.length,-1,n.length,-1]};for(;f.length;){t=f.shift();const v=t.oStart,p=v+t.oLength,L=t.abStart,w=L+t.abLength;let S=m[t.ab];S[0]=Math.min(L,S[0]),S[1]=Math.max(w,S[1]),S[2]=Math.min(v,S[2]),S[3]=Math.max(p,S[3])}const x=m.a[0]+(d-m.a[2]),g=m.a[1]+(a-m.a[3]),j=m.b[0]+(d-m.b[2]),h=m.b[1]+(a-m.b[3]);let y={stable:!1,aStart:x,aLength:g-x,aContent:e.slice(x,g),oStart:d,oLength:a-d,oContent:n.slice(d,a),bStart:j,bLength:h-j,bContent:s.slice(j,h)};i.push(y)}c=a}return r(n.length),i}function le(e,n,s,u){u=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},u),typeof e=="string"&&(e=e.split(u.stringSeparator)),typeof n=="string"&&(n=n.split(u.stringSeparator)),typeof s=="string"&&(s=s.split(u.stringSeparator));let i=[];const c=ne(e,n,s);let r=[];function t(){r.length&&i.push({ok:r}),r=[]}function d(a,f){if(a.length!==f.length)return!1;for(let m=0;m<a.length;m++)if(a[m]!==f[m])return!1;return!0}return c.forEach(a=>{a.stable?r.push(...a.bufferContent):u.excludeFalseConflicts&&d(a.aContent,a.bContent)?r.push(...a.aContent):(t(),i.push({conflict:{a:a.aContent,aIndex:a.aStart,o:a.oContent,oIndex:a.oStart,b:a.bContent,bIndex:a.bStart}}))}),t(),i}const se=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function ie(e){return`<!-- mdocs-merge-conflict:${e} -->`}function oe(e){const n=e.trim().match(se);return(n==null?void 0:n[1])??null}function M(e){return e===""?[]:e.split(`
1
+ import{r as b,j as o}from"./react-vendor-BuABiQkA.js";import{b as V,av as _,aw as J,ax as Q,ay as X}from"./index-DI_31upJ.js";import{E as Y,B as Z}from"./react--aHzEjEz.js";import"./ui-RahDNce8.js";import"./motion-BgtuAqBE.js";import"./diagram-DtU2xxz3.js";import"./editor-CL03se2B.js";import"./plus-BkiPFt2u.js";import"./copy-BUUKT-QO.js";function B({lexicalJson:e,onMarkdown:n,onError:s}){const[u,l]=b.useState(null),i=b.useRef(!1);return b.useEffect(()=>{i.current=!1},[e]),b.useEffect(()=>{if(!(!u||i.current))try{u.setDocument("json",e);const c=u.getDocument("markdown");typeof c=="string"&&(i.current=!0,n(c))}catch{s==null||s()}},[u,e,n,s]),o.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:o.jsx(Y,{content:e,type:"json",editable:!1,onInit:l,plugins:[Z]})})}function ee(e){const{t:n}=V(),[s,u]=b.useState(0),l=e.segments.filter(t=>t.kind==="conflict"),i=e.unresolvedCount>0;b.useEffect(()=>{if(l.length===0){u(0);return}u(t=>Math.min(t,l.length-1))},[l.length]);function c(t){l.length!==0&&u(d=>{var f;const a=(d+t+l.length)%l.length;return(f=document.getElementById(`mdocs-merge-hunk-${a}`))==null||f.scrollIntoView({block:"center",behavior:"smooth"}),a})}let r=-1;return o.jsxs("div",{className:"mdocs-merge-inline-pane",children:[o.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[o.jsx("span",{className:"mdocs-merge-inline-hint",children:i?n("mergeReviewHint"):l.length===0?n("mergeNoConflicts"):n("mergeEditAfterResolve")}),l.length>0?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:e.onUseAllMine,children:n("mergeUseAllMine")}),o.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:n("mergeUseAllTheirs")})]}):null]}),i?o.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((t,d)=>{if(t.kind==="unchanged")return o.jsx("pre",{className:"mdocs-merge-inline-same",children:t.lines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},g))},`u-${d}`);r+=1;const a=r,f=t.resolution!=="unresolved",m=a===s;return o.jsxs("div",{id:`mdocs-merge-hunk-${a}`,className:"mdocs-merge-inline-hunk"+(m?" is-active":"")+(f?" is-resolved":""),onClick:()=>u(a),children:[f?o.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:t.resolution==="remote"?n("mergeReceive"):n("mergeReject")}):o.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:x=>{x.stopPropagation(),e.onReject(t.id)},children:n("mergeReject")}),o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:x=>{x.stopPropagation(),e.onReceive(t.id)},children:n("mergeReceive")})]}),o.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[t.localLines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line del",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},`l${g}`)),t.remoteLines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line add",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},`r${g}`))]})]},t.id)}),l.length>0?o.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[o.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>c(-1),children:"↑"}),o.jsxs("span",{children:[s+1," / ",l.length]}),o.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>c(1),children:"↓"}),l[s]&&l[s].resolution==="unresolved"?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(l[s].id),children:n("mergeReject")}),o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(l[s].id),children:n("mergeReceive")})]}):null]}):null]}):o.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:t=>e.onEditableChange(t.target.value),spellCheck:!1})]})}function te(e,n){let s={};for(let i=0;i<n.length;i++){const c=n[i];s[c]?s[c].push(i):s[c]=[i]}let l=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let i=0;i<e.length;i++){const c=e[i],r=s[c]||[];let t=0,d=l[0];for(let a=0;a<r.length;a++){const f=r[a];let m;for(m=t;m<l.length&&!(l[m].buffer2index<f&&(m===l.length-1||l[m+1].buffer2index>f));m++);if(m<l.length){const x={buffer1index:i,buffer2index:f,chain:l[m]};if(t===l.length?l.push(d):l[t]=d,t=m+1,d=x,t===l.length)break}}l[t]=d}return l[l.length-1]}function q(e,n){const s=te(e,n);let u=[],l=e.length,i=n.length;for(let c=s;c!==null;c=c.chain){const r=l-c.buffer1index-1,t=i-c.buffer2index-1;l=c.buffer1index,i=c.buffer2index,(r||t)&&u.push({buffer1:[l+1,r],buffer1Content:e.slice(l+1,l+1+r),buffer2:[i+1,t],buffer2Content:n.slice(i+1,i+1+t)})}return u.reverse(),u}function ne(e,n,s){let u=[];function l(t,d){u.push({ab:d,oStart:t.buffer1[0],oLength:t.buffer1[1],abStart:t.buffer2[0],abLength:t.buffer2[1]})}q(n,e).forEach(t=>l(t,"a")),q(n,s).forEach(t=>l(t,"b")),u.sort((t,d)=>t.oStart-d.oStart);let i=[],c=0;function r(t){t>c&&(i.push({stable:!0,buffer:"o",bufferStart:c,bufferLength:t-c,bufferContent:n.slice(c,t)}),c=t)}for(;u.length;){let t=u.shift(),d=t.oStart,a=t.oStart+t.oLength,f=[t];for(r(d);u.length;){const m=u[0],x=m.oStart;if(x>a)break;a=Math.max(a,x+m.oLength),f.push(u.shift())}if(f.length===1){if(t.abLength>0){const m=t.ab==="a"?e:s;i.push({stable:!0,buffer:t.ab,bufferStart:t.abStart,bufferLength:t.abLength,bufferContent:m.slice(t.abStart,t.abStart+t.abLength)})}}else{let m={a:[e.length,-1,n.length,-1],b:[s.length,-1,n.length,-1]};for(;f.length;){t=f.shift();const v=t.oStart,p=v+t.oLength,L=t.abStart,w=L+t.abLength;let S=m[t.ab];S[0]=Math.min(L,S[0]),S[1]=Math.max(w,S[1]),S[2]=Math.min(v,S[2]),S[3]=Math.max(p,S[3])}const x=m.a[0]+(d-m.a[2]),g=m.a[1]+(a-m.a[3]),j=m.b[0]+(d-m.b[2]),h=m.b[1]+(a-m.b[3]);let y={stable:!1,aStart:x,aLength:g-x,aContent:e.slice(x,g),oStart:d,oLength:a-d,oContent:n.slice(d,a),bStart:j,bLength:h-j,bContent:s.slice(j,h)};i.push(y)}c=a}return r(n.length),i}function le(e,n,s,u){u=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},u),typeof e=="string"&&(e=e.split(u.stringSeparator)),typeof n=="string"&&(n=n.split(u.stringSeparator)),typeof s=="string"&&(s=s.split(u.stringSeparator));let i=[];const c=ne(e,n,s);let r=[];function t(){r.length&&i.push({ok:r}),r=[]}function d(a,f){if(a.length!==f.length)return!1;for(let m=0;m<a.length;m++)if(a[m]!==f[m])return!1;return!0}return c.forEach(a=>{a.stable?r.push(...a.bufferContent):u.excludeFalseConflicts&&d(a.aContent,a.bContent)?r.push(...a.aContent):(t(),i.push({conflict:{a:a.aContent,aIndex:a.aStart,o:a.oContent,oIndex:a.oStart,b:a.bContent,bIndex:a.bStart}}))}),t(),i}const se=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function ie(e){return`<!-- mdocs-merge-conflict:${e} -->`}function oe(e){const n=e.trim().match(se);return(n==null?void 0:n[1])??null}function M(e){return e===""?[]:e.split(`
2
2
  `)}function H(e,n){return e.length===n.length&&e.every((s,u)=>s===n[u])}function ce(e,n,s){const u=M(e),l=M(n),i=M(s);if(l.length===0&&n==="")return re(e,s);const c=le(u,l,i),r=[];let t=0,d=0,a=0,f=0;const m=(g,j,h,y)=>{r.push({kind:"conflict",id:`conflict-${t}`,conflictKind:y,baseLines:g,localLines:j,remoteLines:h,resolution:"unresolved"}),t+=1},x=(g,j,h)=>{if(j.length===0&&g.length===0&&h.length===0)return;if(H(g,j)&&H(h,j)){j.length>0&&r.push({kind:"unchanged",lines:[...j]});return}if(g.length===j.length&&h.length===j.length){let v=[];const p=()=>{v.length>0&&(r.push({kind:"unchanged",lines:v}),v=[])};for(let L=0;L<j.length;L+=1){const w=j[L],S=g[L],N=h[L];S===w&&N===w?v.push(w):(p(),m([w],[S],[N],S!==w&&N!==w&&S!==N?"true_conflict":"change"))}p();return}const y=g.join(`
3
3
  `)!==j.join(`
4
4
  `)&&h.join(`
@@ -0,0 +1,8 @@
1
+ import{r as n,j as o,ad as C}from"./react-vendor-BuABiQkA.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react--aHzEjEz.js";import{a7 as Q,a8 as X,a9 as ee,aa as te,ab as k,ac as oe}from"./ui-RahDNce8.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,c as R,o as ce}from"./Toolbar-Dz9Cn_hv.js";import{N as me}from"./index-DI_31upJ.js";import"./editor-CL03se2B.js";import"./diagram-DtU2xxz3.js";import"./plus-BkiPFt2u.js";import"./copy-BUUKT-QO.js";import"./motion-BgtuAqBE.js";import"./code-xml-CZsyEkCa.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[g,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:g,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,g]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");g(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(J,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(W,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{ce(l=>{for(const u of l)e.dispatchCommand(z,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
2
+ 123`),queueMicrotask(()=>{e.focus()})}},{key:"insert-link",label:"InsertLink",onSelect:e=>{e.dispatchCommand(B,{url:"https://example.com"}),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeInline",label:"InsertCodeInline",onSelect:e=>{e.dispatchCommand($,void 0),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeBlock",label:"InsertCodeBlock",onSelect:e=>{e.dispatchCommand(K,void 0),queueMicrotask(()=>{e.focus()})}},{icon:de,key:"meta2d",label:"Meta2d",onSelect:e=>{e.dispatchCommand(Y,void 0),queueMicrotask(()=>{e.focus()})}},{icon:me,key:"markmap",label:"Markmap",onSelect:e=>{e.dispatchCommand(G,void 0),queueMicrotask(()=>{e.focus()})}}].map(e=>e.type==="divider"?e:{...e,extra:o.jsx(oe,{code:!0,fontSize:12,type:"secondary",children:e.key})}),[]);return o.jsxs(ue,{json:m,markdown:p,onJSONChange:s,...h,children:[o.jsx(R,{editor:r}),o.jsx(T,{className:"mdocs-playground-editor",content:ye,editor:r,lineEmptyPlaceholder:"Start typing here...",mentionOption:{items:d,markdownWriter:t=>{var e;return`
3
+ <mention>${t.label}[${((e=t.metadata)==null?void 0:e.id)||t.label}]</mention>
4
+ `},onSelect:(t,e)=>{t.dispatchCommand(U,{label:String(e.label),metadata:{id:e.key}})},searchKeys:["label"]},onInit:x,onTextChange:c,pasteVSCodeAsCodeBlock:!0,placeholder:"Type something...",plugins:[I,E,M,j,O,P,A,_,D,L,f(H,{children:o.jsx(R,{editor:r,floating:!0})}),f(F,{delay:1e3,onAutoComplete:async({input:t,afterText:e,selectionType:l,abortSignal:u})=>{console.log("Auto-complete triggered:",{afterText:e,input:t,selectionType:l});try{const v=await fetch(`${location.origin}/nodeserver/completion`,{body:JSON.stringify({prompt:`Please complete the following text:
5
+
6
+ ${t}`}),headers:{"Content-Type":"application/json"},method:"POST",signal:u});if(u.aborted)return console.log("Auto-complete aborted"),null;const i=await v.json();if(i)return typeof i.content=="string"&&i.content.startsWith(t)?i.content.replace(t,""):i.content}catch{}return null}}),f(M,{defaultBlockImage:!0,handleRehost:async t=>{const l=await(await fetch(t)).blob();return await new Promise((u,v)=>{const i=new FileReader;i.onloadend=()=>u({url:i.result}),i.onerror=v,i.readAsDataURL(l)})},needRehost:t=>(console.debug("needRehost",t),t.startsWith("blob:"))}),f(q,{handleUpload:async t=>(console.debug("Files uploaded:",t),new Promise(e=>{setTimeout(()=>{const l=URL.createObjectURL(t);a.current.push(l),e({url:l})},1e3)})),markdownWriter:t=>`
7
+ <file>${t.fileUrl}</file>
8
+ `})],slashOption:{items:w}})]})};function Ne(){return o.jsxs("div",{className:"mdocs-playground-page",children:[o.jsx("header",{className:"mdocs-playground-header",children:o.jsx(C,{className:"mdocs-playground-back",to:"/",children:"← mdocs"})}),o.jsx(pe,{})]})}export{Ne as PlaygroundPage};