@fgbg/mdocs 0.8.24 → 1.1.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 (148) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +47 -1
  3. package/agent-skills/index.json +8 -1
  4. package/agent-skills/usage-knowledge-graph/SKILL.md +126 -0
  5. package/agent-skills/usage-onboarding-ai/SKILL.md +36 -5
  6. package/dist/server/agent/Agent/run.js +60 -34
  7. package/dist/server/agent/Agent/run.js.map +1 -1
  8. package/dist/server/agent/Agent/tools-documents.js +1 -1
  9. package/dist/server/agent/Agent/tools-documents.js.map +1 -1
  10. package/dist/server/agent/Config/config.js +234 -64
  11. package/dist/server/agent/Config/config.js.map +1 -1
  12. package/dist/server/agent/Config/config.test.js +109 -0
  13. package/dist/server/agent/Config/config.test.js.map +1 -0
  14. package/dist/server/app.js +2 -0
  15. package/dist/server/app.js.map +1 -1
  16. package/dist/server/cli/self-update.js +50 -32
  17. package/dist/server/cli/self-update.js.map +1 -1
  18. package/dist/server/db/repositories/agent-model-config.repo.js +58 -27
  19. package/dist/server/db/repositories/agent-model-config.repo.js.map +1 -1
  20. package/dist/server/db/schema.js +96 -1
  21. package/dist/server/db/schema.js.map +1 -1
  22. package/dist/server/documents/build-graph.e2e.test.js +65 -0
  23. package/dist/server/documents/build-graph.e2e.test.js.map +1 -0
  24. package/dist/server/documents/document.service.js +34 -2
  25. package/dist/server/documents/document.service.js.map +1 -1
  26. package/dist/server/documents/graph/change-ratio.js +29 -0
  27. package/dist/server/documents/graph/change-ratio.js.map +1 -0
  28. package/dist/server/documents/graph/change-ratio.test.js +38 -0
  29. package/dist/server/documents/graph/change-ratio.test.js.map +1 -0
  30. package/dist/server/documents/graph/graph-agent.integration.test.js +95 -0
  31. package/dist/server/documents/graph/graph-agent.integration.test.js.map +1 -0
  32. package/dist/server/documents/graph/graph-agent.js +185 -0
  33. package/dist/server/documents/graph/graph-agent.js.map +1 -0
  34. package/dist/server/documents/graph/graph-file.js +58 -0
  35. package/dist/server/documents/graph/graph-file.js.map +1 -0
  36. package/dist/server/documents/graph/graph-file.test.js +28 -0
  37. package/dist/server/documents/graph/graph-file.test.js.map +1 -0
  38. package/dist/server/documents/graph/index.js +183 -0
  39. package/dist/server/documents/graph/index.js.map +1 -0
  40. package/dist/server/documents/graph/lifecycle.js +104 -0
  41. package/dist/server/documents/graph/lifecycle.js.map +1 -0
  42. package/dist/server/documents/graph/llm-chains.js +135 -0
  43. package/dist/server/documents/graph/llm-chains.js.map +1 -0
  44. package/dist/server/documents/graph/llm-utils.js +19 -0
  45. package/dist/server/documents/graph/llm-utils.js.map +1 -0
  46. package/dist/server/documents/graph/llm-utils.test.js +34 -0
  47. package/dist/server/documents/graph/llm-utils.test.js.map +1 -0
  48. package/dist/server/documents/graph/tools/concept-relations.tool.js +49 -0
  49. package/dist/server/documents/graph/tools/concept-relations.tool.js.map +1 -0
  50. package/dist/server/documents/graph/tools/extract-knowledge-points.tool.js +45 -0
  51. package/dist/server/documents/graph/tools/extract-knowledge-points.tool.js.map +1 -0
  52. package/dist/server/documents/graph/tools/generate-contains.tool.js +41 -0
  53. package/dist/server/documents/graph/tools/generate-contains.tool.js.map +1 -0
  54. package/dist/server/documents/graph/tools/induce-concepts.tool.js +43 -0
  55. package/dist/server/documents/graph/tools/induce-concepts.tool.js.map +1 -0
  56. package/dist/server/documents/graph/types.js +12 -0
  57. package/dist/server/documents/graph/types.js.map +1 -0
  58. package/dist/server/documents/graph/utils.js +41 -0
  59. package/dist/server/documents/graph/utils.js.map +1 -0
  60. package/dist/server/documents/graph/utils.test.js +87 -0
  61. package/dist/server/documents/graph/utils.test.js.map +1 -0
  62. package/dist/server/documents/graph-cache-io.js +254 -0
  63. package/dist/server/documents/graph-cache-io.js.map +1 -0
  64. package/dist/server/documents/graph-lifecycle.js +19 -0
  65. package/dist/server/documents/graph-lifecycle.js.map +1 -0
  66. package/dist/server/documents/graph-task.js +232 -0
  67. package/dist/server/documents/graph-task.js.map +1 -0
  68. package/dist/server/documents/graph.integration.test.js +213 -0
  69. package/dist/server/documents/graph.integration.test.js.map +1 -0
  70. package/dist/server/documents/graph.service.js +296 -0
  71. package/dist/server/documents/graph.service.js.map +1 -0
  72. package/dist/server/documents/markdown-to-lexical.js +111 -13
  73. package/dist/server/documents/markdown-to-lexical.js.map +1 -1
  74. package/dist/server/documents/markdown-to-lexical.test.js +37 -0
  75. package/dist/server/documents/markdown-to-lexical.test.js.map +1 -1
  76. package/dist/server/documents/tree.service.js +12 -6
  77. package/dist/server/documents/tree.service.js.map +1 -1
  78. package/dist/server/migrations/003-folder-desc-file-type.js +43 -0
  79. package/dist/server/migrations/003-folder-desc-file-type.js.map +1 -0
  80. package/dist/server/migrations/004-api-key-to-secrets.js +90 -0
  81. package/dist/server/migrations/004-api-key-to-secrets.js.map +1 -0
  82. package/dist/server/migrations/004-folder-desc-id.js +98 -0
  83. package/dist/server/migrations/004-folder-desc-id.js.map +1 -0
  84. package/dist/server/migrations/005-special-file-id-format.js +124 -0
  85. package/dist/server/migrations/005-special-file-id-format.js.map +1 -0
  86. package/dist/server/routes/agent.routes.js +69 -31
  87. package/dist/server/routes/agent.routes.js.map +1 -1
  88. package/dist/server/routes/assets.routes.js +68 -62
  89. package/dist/server/routes/assets.routes.js.map +1 -1
  90. package/dist/server/routes/assets.routes.upload.test.js +27 -0
  91. package/dist/server/routes/assets.routes.upload.test.js.map +1 -0
  92. package/dist/server/routes/documents.routes.js +1 -1
  93. package/dist/server/routes/documents.routes.js.map +1 -1
  94. package/dist/server/routes/folders.routes.js +2 -2
  95. package/dist/server/routes/folders.routes.js.map +1 -1
  96. package/dist/server/routes/graph.routes.js +112 -0
  97. package/dist/server/routes/graph.routes.js.map +1 -0
  98. package/dist/server/routes/tree.routes.js +1 -1
  99. package/dist/server/routes/tree.routes.js.map +1 -1
  100. package/dist/server/secrets/secrets-store.js +93 -0
  101. package/dist/server/secrets/secrets-store.js.map +1 -0
  102. package/dist/server/storage/paths.js +0 -1
  103. package/dist/server/storage/paths.js.map +1 -1
  104. package/dist/server/task-queue/TaskQueue.js +258 -0
  105. package/dist/server/task-queue/TaskQueue.js.map +1 -0
  106. package/dist/server/task-queue/TaskQueue.test.js +136 -0
  107. package/dist/server/task-queue/TaskQueue.test.js.map +1 -0
  108. package/dist/server/task-queue/index.js +18 -0
  109. package/dist/server/task-queue/index.js.map +1 -0
  110. package/dist/server/task-queue/log-store.js +84 -0
  111. package/dist/server/task-queue/log-store.js.map +1 -0
  112. package/dist/server/task-queue/types.js +5 -0
  113. package/dist/server/task-queue/types.js.map +1 -0
  114. package/dist/shared/docPath.js +3 -2
  115. package/dist/shared/docPath.js.map +1 -1
  116. package/dist/shared/file-types.js +35 -0
  117. package/dist/shared/file-types.js.map +1 -0
  118. package/dist/shared/graph-files.js +31 -0
  119. package/dist/shared/graph-files.js.map +1 -0
  120. package/dist/web/assets/AgentChatPanel-C8TMWDuE.js +6 -0
  121. package/dist/web/assets/AgentSkillFormCard-yk7PWF0W.js +6 -0
  122. package/dist/web/assets/AiWriteWorkbench-ChCJt24m.js +7 -0
  123. package/dist/web/assets/{DiagramEditor-NtNY3sZL-DqPXDJHY.js → DiagramEditor-NtNY3sZL-Bw4wHaBD.js} +1 -1
  124. package/dist/web/assets/DocumentEditor-B3Dsq02C.js +26 -0
  125. package/dist/web/assets/{MergeView-Y3zB8V5p.js → MergeView-royv5YkB.js} +1 -1
  126. package/dist/web/assets/PlaygroundPage-B-_1l4Ix.js +8 -0
  127. package/dist/web/assets/SettingsPage-D8HfepZ8.js +1 -0
  128. package/dist/web/assets/{Toolbar-B36NxaTc.js → Toolbar-BDJ6WABq.js} +16 -21
  129. package/dist/web/assets/{VisitorPickerModal-drnOuPLP.js → VisitorPickerModal-DPKIoySi.js} +1 -1
  130. package/dist/web/assets/{copy-CX8GOyUb.js → copy-UwfRYkpI.js} +1 -1
  131. package/dist/web/assets/{diagram-3lhA7FYR.js → diagram--gCCJK__.js} +545 -545
  132. package/dist/web/assets/index-4TuRcE3b.js +248 -0
  133. package/dist/web/assets/index-C4ESYs7f.css +1 -0
  134. package/dist/web/assets/{meta2dEngine-BD2XbzaV-CCgjRlVJ.js → meta2dEngine-BD2XbzaV-D1J2-XNv.js} +1 -1
  135. package/dist/web/assets/{motion-92iQWeIW.js → motion-DddvD-ez.js} +1 -1
  136. package/dist/web/assets/{plus-BWV299MC.js → plus-CiGwts52.js} +1 -1
  137. package/dist/web/assets/{react-BUhFwPCj.js → react-B99eF5mm.js} +146 -151
  138. package/dist/web/assets/{ui-06fxEgif.js → ui-BHvBMRFE.js} +3 -3
  139. package/dist/web/index.html +5 -4
  140. package/package.json +2 -1
  141. package/dist/web/assets/AgentChatPanel-BTCyf9Ww.js +0 -1
  142. package/dist/web/assets/AgentSkillFormCard-CAD6QqQ0.js +0 -6
  143. package/dist/web/assets/AiWriteWorkbench-PVv90TJS.js +0 -7
  144. package/dist/web/assets/DocumentEditor-zNIJgxe0.js +0 -21
  145. package/dist/web/assets/PlaygroundPage-DAaEm887.js +0 -8
  146. package/dist/web/assets/SettingsPage-DhdiNEhO.js +0 -1
  147. package/dist/web/assets/index-DgM2rYI-.js +0 -185
  148. package/dist/web/assets/index-S_lCknAk.css +0 -1
@@ -0,0 +1,6 @@
1
+ import{r as o,j as e}from"./react-vendor-BJFXgntS.js";import{c as Le,ag as be,ah as Ke,i as ve,ai as Se,aj as Oe,ak as Ue,al as We,am as Ge,an as Xe,ao as Re,ap as Ye,aq as Ve,ar as Je}from"./index-4TuRcE3b.js";import{H as Qe,A as we,S as Ze,a as es}from"./AgentSkillFormCard-yk7PWF0W.js";import{P as ss}from"./plus-CiGwts52.js";import{D as ts,E as ns}from"./ui-BHvBMRFE.js";import{C as as,a as is}from"./copy-UwfRYkpI.js";import"./diagram--gCCJK__.js";import"./motion-DddvD-ez.js";/**
2
+ * @license lucide-react v0.562.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const rs=[["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"}]],ls=Le("file-text",rs);function le(r){var n;return r==null||typeof r=="boolean"?"":typeof r=="string"||typeof r=="number"?String(r):Array.isArray(r)?r.map(le).join(""):typeof r=="object"&&"props"in r?le((n=r.props)==null?void 0:n.children):""}function cs(r){const[n,c]=o.useState(!1),d=o.useRef(null),v=le(r.children).replace(/\n$/,"");o.useEffect(()=>()=>{d.current!=null&&window.clearTimeout(d.current)},[]);async function x(){if(v)try{await navigator.clipboard.writeText(v),c(!0),d.current!=null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>c(!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 x(),"aria-label":n?"已复制":"复制代码",title:n?"已复制":"复制",children:n?e.jsx(as,{size:14,"aria-hidden":!0}):e.jsx(is,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:r.children})]})}function Ae(r){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(ts,{remarkPlugins:[ns],components:{pre:({children:n})=>e.jsx(cs,{children:n})},children:r.children})})}const os=["如何发布文档?","草稿是什么?","如何创建域?"];function Ce(r,n){return n.map((c,d)=>{const v=c.skillNames&&c.skillNames.length>0?c.skillNames:c.skillIds&&c.skillIds.length>0?c.skillIds:void 0;return{id:`h-${r}-${d}-${c.role}`,role:c.role,content:c.content,skillNames:v}})}function ds(r,n){const c=r.slice(),d=c[c.length-1];return(d==null?void 0:d.type)==="text"?c[c.length-1]={type:"text",text:d.text+n}:c.push({type:"text",text:n}),c}function us(r,n){const c=r.slice(),d=c[c.length-1];return(d==null?void 0:d.type)==="thinking"?c[c.length-1]={type:"thinking",text:d.text+n}:c.push({type:"thinking",text:n}),c}function Ie(r){return r!=null&&r.length?r.filter(n=>n.type==="text").map(n=>n.text).join(""):""}function ms(r){return!!(r!=null&&r.some(n=>n.type==="thinking"&&n.text.length>0))}function ps(r){const n=new Date(r);if(Number.isNaN(n.getTime()))return"";const c=new Date;return n.getFullYear()===c.getFullYear()&&n.getMonth()===c.getMonth()&&n.getDate()===c.getDate()?n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function _e(r){if(r>=1e3){const n=r/1e3;return`${n>=10?Math.round(n):Math.round(n*10)/10}K`}return String(r)}function hs(r){const{block:n,onResolved:c}=r,[d,v]=o.useState(""),[x,$]=o.useState(!1),[_,R]=o.useState(1),A=o.useRef(!1),F=o.useRef(c);F.current=c;const S=n.status==="open",B=o.useRef(0);o.useEffect(()=>{if(!S)return;A.current=!1;const k=new Date(n.expiresAt).getTime(),N=Date.now(),w=Math.max(k-N,1);B.current=w,R(1);const u=()=>{const U=k-Date.now(),P=Math.max(0,Math.min(1,U/w));R(P),U<=0&&!A.current&&(A.current=!0,Ve(n.requestId).catch(()=>{}).finally(()=>{F.current(n.requestId,"","expired")}))};u();const T=window.setInterval(u,100);return()=>window.clearInterval(T)},[S,n.expiresAt,n.requestId]);async function M(k){const N=k.trim();if(!(!N||x||!S)){$(!0);try{await Je(n.requestId,N),c(n.requestId,N,"selected")}catch{c(n.requestId,N,"failed")}finally{$(!1)}}}async function H(){if(!(x||!S)){$(!0),A.current=!0;try{await Re(n.requestId),c(n.requestId,"","cancelled")}catch{c(n.requestId,"","failed")}finally{$(!1)}}}const L=Math.max(0,Math.ceil(_*B.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(S?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:n.title}),S?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[L,"s"]}):null]}),S?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(_*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${_})`}})}):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,S?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:n.options.map(k=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:x,onClick:()=>void M(k),children:k},k))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:d,disabled:x,placeholder:"或输入自己的内容…",onChange:k=>v(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),M(d))}}),e.jsx("button",{type:"button",disabled:x||!d.trim(),onClick:()=>void M(d),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:x,onClick:()=>void H(),children:"取消"})})]}):null]})}function fs(r){const v=2*Math.PI*8.75,x=Math.min(100,Math.max(0,r.percent)),$=v*(1-x/100),_=x>=90?"danger":x>=70?"warn":"ok",R=`上下文 ${x}% · 已用 ${_e(r.used)} / ${_e(r.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+_,"data-tooltip":R,"aria-label":R,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:v,strokeDashoffset:$,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function gs(r){var n;for(const c of r)if(!(c.role!=="assistant"||!((n=c.blocks)!=null&&n.length))){for(const d of c.blocks)if((d.type==="choice_card"||d.type==="skill_form_card")&&d.status==="open")return!0}return!1}const ws=o.forwardRef(function(n,c){const{open:d,onClose:v,visitorName:x,anchorStyle:$,fullscreen:_,domainId:R,documentId:A,documentTitle:F,documentPath:S,onOpenDocument:B,onTreeChanged:M,onDocumentOverwritten:H,onOpenCoding:L}=n,k=((x==null?void 0:x.trim().charAt(0))||"我").toUpperCase(),[N,w]=o.useState(!1),[u,T]=o.useState(null),[U,P]=o.useState(null),[q,y]=o.useState([]),[J,W]=o.useState(null),[ce,qe]=o.useState([]),[$e,oe]=o.useState(!1),[G,X]=o.useState(""),[K,de]=o.useState([]),[Ee,ue]=o.useState(!1),[g,Y]=o.useState(!1),[me,E]=o.useState(null),[V,pe]=o.useState(null),[Q,z]=o.useState(!1),[D,he]=o.useState(!1),De=o.useRef(null),Z=o.useRef(null),C=o.useRef(null),fe=o.useRef(0),O=o.useRef(!0),ee=o.useRef(q);ee.current=q;const ge=!!(A!=null&&A.trim())&&!Ee,Me=(F==null?void 0:F.trim())||"当前文档",xe=(S==null?void 0:S.trim())||"";o.useEffect(()=>{ue(!1)},[A]);function ye(s){return fe.current+=1,`${s}-${fe.current}`}function ze(s,m=48){return s.scrollHeight-s.scrollTop-s.clientHeight<=m}function I(){const s=Z.current;!s||!O.current||(s.scrollTop=s.scrollHeight)}function Fe(){const s=Z.current;s&&(O.current=ze(s))}async function Te(){oe(!0);try{const s=await Ue();qe(s.sessions),J||W(s.lastOpenedSessionId)}catch{}finally{oe(!1)}}async function se(){try{const s=await Oe();pe(s)}catch{}}async function je(){try{const s=await be();T(s),P(null)}catch(s){T(null),P(s instanceof Error?s.message:String(s))}}o.useEffect(()=>{var m;if(!d){w(!1),(m=C.current)==null||m.abort(),C.current=null,Y(!1);return}let s=!1;return(async()=>{try{const a=await be();s||(T(a),P(null))}catch(a){s||(T(null),P(a instanceof Error?a.message:String(a)))}})(),se(),()=>{s=!0}},[d]),o.useEffect(()=>{if(!d)return;let s=!1;return(async()=>{try{const m=await Ke();if(s)return;W(m.sessionId),y(a=>a.length>0?a:Ce(m.sessionId,m.messages))}catch{}})(),()=>{s=!0}},[d]),o.useEffect(()=>{!d||!N||Te()},[d,N]);function te(){if(!D){if(gs(ee.current)){z(!0);return}z(!1),v()}}async function Pe(){var a;if(D)return;he(!0);const s=ee.current,m=[];for(const j of s)if(!(j.role!=="assistant"||!j.blocks))for(const p of j.blocks)p.type==="choice_card"&&p.status==="open"&&m.push(Re(p.requestId).catch(()=>{})),p.type==="skill_form_card"&&p.status==="open"&&m.push(Ye(p.requestId).catch(()=>{}));await Promise.all(m),(a=C.current)==null||a.abort(),y(j=>j.map(p=>p.role!=="assistant"||!p.blocks?p:{...p,blocks:p.blocks.map(h=>h.type==="choice_card"&&h.status==="open"?{...h,status:"cancelled"}:h.type==="skill_form_card"&&h.status==="open"?{...h,status:"cancelled"}:h)})),z(!1),he(!1),v()}const ne=o.useRef(te);ne.current=te,o.useImperativeHandle(c,()=>({requestClose:()=>ne.current()}),[]),o.useEffect(()=>{if(!d){z(!1);return}const s=m=>{if(m.key==="Escape"){if(Q){D||z(!1);return}if(N){w(!1);return}ne.current()}};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[d,N,Q,D]);async function ae(s){var h;const m=s.trim();if(!m||g)return;if(!(u!=null&&u.enabled)){E((u==null?void 0:u.reason)==="missing_api_key"?"请先配置 API Key":(u==null?void 0:u.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(h=C.current)==null||h.abort();const a=new AbortController;C.current=a;const j={id:ye("u"),role:"user",content:m,skillNames:K.length>0?[...K]:void 0},p=ye("a");O.current=!0,y(b=>[...b,j,{id:p,role:"assistant",content:""}]),X(""),Y(!0),E(null),w(!1),requestAnimationFrame(()=>I());try{let b=!1;await Xe(m,{skillNames:K.length>0?K:void 0,references:{domainId:(R==null?void 0:R.trim())||void 0,documentId:ge?A.trim():void 0},signal:a.signal,onEvent:i=>{i.type==="text_delta"?(y(f=>f.map(t=>{if(t.id!==p)return t;const l=ds(t.blocks??[],i.text);return{...t,blocks:l,content:Ie(l)}})),requestAnimationFrame(()=>I())):i.type==="thinking_delta"?(y(f=>f.map(t=>{if(t.id!==p)return t;const l=us(t.blocks??[],i.text);return{...t,blocks:l}})),requestAnimationFrame(()=>I())):i.type==="sources"?(y(f=>f.map(t=>{if(t.id!==p)return t;const l=(t.blocks??[]).slice(),re=l[l.length-1];return(re==null?void 0:re.type)==="sources"?l[l.length-1]={type:"sources",items:i.items}:l.push({type:"sources",items:i.items}),{...t,blocks:l}})),requestAnimationFrame(()=>I())):i.type==="document_table"?(y(f=>f.map(t=>{if(t.id!==p)return t;const l=[...t.blocks??[],{type:"document_table",title:i.title,rows:i.rows}];return{...t,blocks:l}})),requestAnimationFrame(()=>I())):i.type==="document_card"?(y(f=>f.map(t=>{if(t.id!==p)return t;const l=[...t.blocks??[],{type:"document_card",documentId:i.documentId,title:i.title,path:i.path,preview:i.preview}];return{...t,blocks:l}})),requestAnimationFrame(()=>I())):i.type==="tool_notice"?(y(f=>f.map(t=>{if(t.id!==p)return t;const l=[...t.blocks??[],{type:"tool_notice",toolName:i.toolName,text:i.text}];return{...t,blocks:l}})),requestAnimationFrame(()=>I())):i.type==="choice_card"?(y(f=>f.map(t=>{if(t.id!==p)return t;const l=[...t.blocks??[],{type:"choice_card",requestId:i.requestId,title:i.title,options:i.options,expiresAt:i.expiresAt,status:"open"}];return{...t,blocks:l}})),requestAnimationFrame(()=>I())):i.type==="choice_expired"?y(f=>f.map(t=>t.id!==p||!t.blocks?t:{...t,blocks:t.blocks.map(l=>l.type==="choice_card"&&l.requestId===i.requestId&&l.status==="open"?{...l,status:"expired"}:l)})):i.type==="skill_form_card"?(y(f=>f.map(t=>{if(t.id!==p)return t;const l=[...t.blocks??[],{type:"skill_form_card",requestId:i.requestId,mode:i.mode,title:i.title,currentName:i.currentName,initialName:i.initialName,initialDescription:i.initialDescription,initialBody:i.initialBody,expiresAt:i.expiresAt,status:"open"}];return{...t,blocks:l}})),requestAnimationFrame(()=>I())):i.type==="skill_form_expired"?y(f=>f.map(t=>t.id!==p||!t.blocks?t:{...t,blocks:t.blocks.map(l=>l.type==="skill_form_card"&&l.requestId===i.requestId&&l.status==="open"?{...l,status:"expired"}:l)})):i.type==="tree_changed"?M==null||M():i.type==="document_overwritten"?H==null||H({documentId:i.documentId,headCommitId:i.headCommitId}):i.type==="open_coding"?L==null||L({documentId:i.documentId,displayName:i.displayName}):i.type==="context_usage"?pe({percent:i.percent,used:i.used,limit:i.limit}):i.type==="error"&&(b=!0,E(i.message))}}),!a.signal.aborted&&!b&&de([])}catch(b){if(a.signal.aborted)return;E(b instanceof Error?b.message:String(b))}finally{C.current===a&&(C.current=null),Y(!1)}}async function Be(){var s;if(!g){(s=C.current)==null||s.abort(),E(null),w(!1),Y(!1);try{const m=await We();W(m.sessionId),y([]),X(""),O.current=!0,se()}catch(m){E(m instanceof Error?m.message:String(m))}}}async function He(s){var m;if(!g){if(s===J){w(!1);return}(m=C.current)==null||m.abort(),E(null);try{const a=await Ge(s);W(a.sessionId),y(Ce(a.sessionId,a.messages)),X(""),w(!1),O.current=!0,requestAnimationFrame(()=>I()),se()}catch(a){E(a instanceof Error?a.message:String(a))}}}function ke(s){!s||!B||B(s)}if(!d)return null;const ie=(u==null?void 0:u.reason)==="missing_api_key",Ne=U??(u&&!u.enabled&&!ie?u.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:De,className:"mdocs-agent-panel"+(_?" mdocs-agent-panel--fullscreen":""),role:"dialog","aria-label":"mdocs 智能助手","aria-modal":_?!0:void 0,style:_?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:ve,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:g,onClick:()=>void Be(),children:e.jsx(ss,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(N?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>w(s=>!s),children:e.jsx(Qe,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:te,children:e.jsx(Se,{size:16,strokeWidth:1.8})})]})]}),N?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:()=>w(!1),children:"返回对话"})]}),$e?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):ce.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:ce.map(s=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(s.id===J?" active":""),disabled:g,onClick:()=>void He(s.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:s.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:ps(s.updatedAt)})]})},s.id))})]}):e.jsxs("div",{className:"mdocs-agent-panel-body",children:[e.jsx("div",{className:"mdocs-agent-panel-welcome",ref:Z,onScroll:Fe,children:q.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:"我能答疑、搜文档、整理结构,也能帮你写全文;需要精细改稿请点文档顶栏「帮写」。"}),ie?e.jsx(we,{onConfigured:je}):Ne?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Ne}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:os.map(s=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void ae(s),disabled:g||!(u!=null&&u.enabled),children:s},s))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:q.map(s=>{var m;return e.jsxs("div",{className:"mdocs-agent-panel-msg"+(s.role==="user"?" mdocs-agent-panel-msg-user":" mdocs-agent-panel-msg-assistant"),children:[s.role==="assistant"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-ai","aria-hidden":!0,children:e.jsx("img",{src:ve,alt:""})}):null,e.jsxs("div",{className:"mdocs-agent-panel-msg-bubble",children:[s.role==="user"&&s.skillNames&&s.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",s.skillNames.length]}):null,s.role==="assistant"?s.blocks&&s.blocks.length>0?e.jsxs("div",{className:"mdocs-agent-panel-timeline",children:[s.blocks.map((a,j)=>{var p;return a.type==="thinking"?a.text?e.jsxs("details",{className:"mdocs-agent-panel-think-fold",open:g&&s.id===((p=q[q.length-1])==null?void 0:p.id),children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:a.text})]},`${s.id}-th-${j}`):null:a.type==="text"?a.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Ae,{children:a.text})},`${s.id}-t-${j}`):null:a.type==="sources"?a.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:["已阅读 ",a.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:a.items.map(h=>e.jsx("li",{children:e.jsx("a",{href:h.url,target:"_blank",rel:"noreferrer",children:h.name})},h.id))})]})},`${s.id}-s-${j}`):a.type==="tool_notice"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:a.text})},`${s.id}-n-${j}`):a.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(hs,{block:a,onResolved:(h,b,i)=>{y(f=>f.map(t=>t.id!==s.id||!t.blocks?t:{...t,blocks:t.blocks.map(l=>l.type==="choice_card"&&l.requestId===h?{...l,status:i,selected:i==="selected"?b:l.selected}:l)}))}})},`${s.id}-ch-${j}`):a.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Ze,{block:a,onResolved:(h,b,i)=>{y(f=>f.map(t=>t.id!==s.id||!t.blocks?t:{...t,blocks:t.blocks.map(l=>l.type==="skill_form_card"&&l.requestId===h?{...l,status:b,submittedName:b==="submitted"?i:l.submittedName}:l)}))}})},`${s.id}-sf-${j}`):a.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:h=>{h.preventDefault(),h.stopPropagation(),ke(a.documentId)},children:["《",a.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"文档预览"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[a.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:a.path}):null,a.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:a.preview}):e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview muted",children:"(无正文预览)"})]})]})},`${s.id}-c-${j}`):e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[a.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:a.rows.length===0?"无结果":`${a.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:a.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:a.rows.map(h=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>ke(h.documentId),children:h.title})}),e.jsx("td",{children:h.summary||"-"})]},h.documentId))})]})})]})},`${s.id}-d-${j}`)}),g&&s.id===((m=q[q.length-1])==null?void 0:m.id)&&!Ie(s.blocks)&&!ms(s.blocks)?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null]}):s.content?e.jsx(Ae,{children:s.content}):g?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null:s.content]}),s.role==="user"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-user","aria-hidden":!0,children:k}):null]},s.id)})})}),me?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:me}):null,ie&&q.length>0?e.jsx(we,{onConfigured:je}):null,e.jsx(es,{selectedNames:K,onChange:de,disabled:g||!(u!=null&&u.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap",children:[ge?e.jsxs("div",{className:"mdocs-agent-doc-ref",children:[e.jsx(ls,{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:Me}),xe?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:xe}):null]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前文档",disabled:g,onClick:()=>ue(!0),children:e.jsx(Se,{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:u!=null&&u.enabled?"把你的问题告诉我…":"请先配置 API Key",value:G,disabled:g||!(u!=null&&u.enabled),onChange:s=>X(s.target.value),onKeyDown:s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),ae(G))}}),V?e.jsx(fs,{percent:V.percent,used:V.used,limit:V.limit}):null,e.jsx("button",{type:"button",className:g?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:g?!1:!(u!=null&&u.enabled)||!G.trim(),onClick:()=>{var s;if(g){(s=C.current)==null||s.abort();return}ae(G)},title:g?"停止":"发送","aria-label":g?"停止":"发送",children:g?"■":"↑"})]})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),Q?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{D||z(!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:s=>s.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:D,onClick:()=>z(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:D,onClick:()=>void Pe(),children:D?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{ws as AgentChatPanel};
@@ -0,0 +1,6 @@
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-4TuRcE3b.js";import{r as n,j as e}from"./react-vendor-BJFXgntS.js";/**
2
+ * @license lucide-react v0.562.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const F=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],H=K("history",F),E=5;function O(o){const s=n.useRef(!0),i=n.useRef(null),[m,v]=n.useState([]),[p,x]=n.useState(!1),[g,b]=n.useState(null);n.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),n.useEffect(()=>{(async()=>{try{const t=await q();if(!s.current)return;v(t)}catch(t){if(!s.current)return;b(t instanceof Error?t.message:String(t))}})()},[]),n.useEffect(()=>{if(!p)return;function t(f){const r=i.current;!r||r.contains(f.target)||x(!1)}function l(f){f.key==="Escape"&&x(!1)}return document.addEventListener("mousedown",t),document.addEventListener("keydown",l),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",l)}},[p]);const c=m.filter(t=>o.selectedNames.includes(t.name));function h(t){if(o.disabled)return;const l=new Set(o.selectedNames);if(l.has(t))l.delete(t);else{if(l.size>=E)return;l.add(t)}o.onChange([...l])}return m.length===0&&!g?null:e.jsxs("div",{className:"mdocs-agent-skill-ref",ref:i,children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-bar",children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-anchor",children:[p&&m.length>0?e.jsxs("div",{className:"mdocs-agent-skill-popover",role:"listbox","aria-label":"选择 Skill",children:[e.jsxs("div",{className:"mdocs-agent-skill-popover-hint",children:["选择要引用的 Skill(最多 ",E," 个)"]}),e.jsx("ul",{className:"mdocs-agent-skill-popover-list",children:m.map(t=>{const l=o.selectedNames.includes(t.name),f=!l&&o.selectedNames.length>=E;return e.jsx("li",{children:e.jsxs("button",{type:"button",role:"option","aria-selected":l,className:"mdocs-agent-skill-popover-item"+(l?" mdocs-agent-skill-popover-item-on":""),disabled:o.disabled||f,onClick:()=>h(t.name),children:[e.jsx("span",{className:"mdocs-agent-skill-popover-check","aria-hidden":!0,children:l?"✓":""}),e.jsxs("span",{className:"mdocs-agent-skill-popover-text",children:[e.jsx("span",{className:"mdocs-agent-skill-popover-name",children:t.name}),t.description?e.jsx("span",{className:"mdocs-agent-skill-popover-desc",children:t.description}):e.jsx("span",{className:"mdocs-agent-skill-popover-desc mdocs-agent-skill-popover-desc-muted",children:"无简介"})]})]})},t.id)})})]}):null,e.jsxs("button",{type:"button",className:"mdocs-agent-skill-ref-toggle"+(p?" mdocs-agent-skill-ref-toggle-open":""),disabled:o.disabled||m.length===0,onClick:()=>x(t=>!t),"aria-expanded":p,"aria-haspopup":"listbox",title:"引用 Skill",children:["Skill",c.length>0?` · ${c.length}`:""]})]}),c.map(t=>e.jsxs("button",{type:"button",className:"mdocs-agent-skill-chip mdocs-agent-skill-chip-on",disabled:o.disabled,onClick:()=>h(t.name),title:"移除引用",children:[t.name,e.jsx("span",{"aria-hidden":!0,children:" ×"})]},t.name))]}),g?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:g}):null]})}const _=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function W(o){const{t:s}=L(),[i,m]=n.useState("deepseek"),[v,p]=n.useState(""),[x,g]=n.useState(""),[b,c]=n.useState("openai-completions"),[h,t]=n.useState(""),[l,f]=n.useState(!1),[r,y]=n.useState(!1),[S,u]=n.useState(null),w=n.useRef(!1);function C(a){if(p(a),w.current)return;a.toLowerCase().includes("anthropic")?c("anthropic-messages"):c("openai-completions")}function I(a){w.current=!0,c(a)}async function j(){var N;const a=h.trim();if(!a){u("请输入 API Key");return}y(!0),u(null);try{if(i==="deepseek")await R({kind:"deepseek",modelId:"deepseek-v4-flash",apiKey:a});else{const k=v.trim();if(!k){u("请输入 API 地址");return}const A=x.trim();if(!A){u("请输入 Model ID");return}await R({kind:"custom",baseUrl:k,modelId:A,apiType:b,apiKey:a})}t(""),p(""),g(""),await((N=o.onConfigured)==null?void 0:N.call(o))}catch(k){u(k instanceof Error?k.message:String(k))}finally{y(!1)}}const d=h.trim()&&(i==="deepseek"||v.trim()&&x.trim());return e.jsxs("div",{className:"mdocs-agent-apikey-inline",children:[e.jsx("p",{className:"mdocs-agent-apikey-inline-lead",children:"配置 AI 供应商后即可使用(仅本人可见,不会分享给其他访客)"}),e.jsxs("div",{className:"mdocs-agent-kind-tabs mdocs-agent-apikey-inline-tabs",role:"tablist","aria-label":"配置方式",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":i==="deepseek",className:i==="deepseek"?"active":"",onClick:()=>m("deepseek"),disabled:r,children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":i==="custom",className:i==="custom"?"active":"",onClick:()=>m("custom"),disabled:r,children:"自定义"})]}),i==="custom"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field mdocs-agent-apikey-inline-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:v,onChange:a=>C(a.target.value),placeholder:"https://api.example.com/v1",className:"mdocs-agent-mono",disabled:r,onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),j())}})]}),e.jsxs("label",{className:"mdocs-agent-field mdocs-agent-apikey-inline-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx("div",{className:"mdocs-agent-apikey-inline-protocol",children:_.map(a=>e.jsx("button",{type:"button",className:b===a.value?"active":"",onClick:()=>I(a.value),disabled:r,children:a.label},a.value))})]}),e.jsxs("label",{className:"mdocs-agent-field mdocs-agent-apikey-inline-field",children:[e.jsx("span",{children:"Model ID"}),e.jsx("input",{type:"text",value:x,onChange:a=>g(a.target.value),placeholder:"模型名称,如 gpt-4o / claude-3-5-sonnet",className:"mdocs-agent-mono",disabled:r,onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),j())}})]})]}):null,e.jsxs("div",{className:"mdocs-agent-config-apikey mdocs-agent-apikey-inline-field",children:[e.jsx("input",{type:l?"text":"password",value:h,onChange:a=>t(a.target.value),placeholder:s("agentConfigApiKeyPlaceholder"),autoComplete:"off",disabled:r,onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),j())}}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":s(l?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>f(a=>!a),disabled:r,children:l?e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M3 3l18 18"}),e.jsx("path",{d:"M10.6 10.6a2 2 0 002.8 2.8"}),e.jsx("path",{d:"M9.9 5.1A10.5 0 0121 12c-.6 1.1-1.4 2.1-2.4 2.9"}),e.jsx("path",{d:"M6.1 6.1C4.5 7.4 3.2 9.1 2.5 12c1.5 3.5 5 7 9.5 7 1.4 0 2.7-.3 3.9-.8"})]}):e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M2.5 12C4 8.5 7.5 5 12 5s8 3.5 9.5 7c-1.5 3.5-5 7-9.5 7s-8-3.5-9.5-7z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]}),S?e.jsx("p",{className:"mdocs-agent-apikey-inline-error",children:S}):null,e.jsx("button",{type:"button",className:"mdocs-agent-apikey-inline-save",onClick:()=>void j(),disabled:r||!d,children:r?s("saving"):"保存并启用"})]})}const U=/^[A-Za-z0-9_]+$/;function X(o){const{block:s,onResolved:i}=o,[m,v]=n.useState(s.initialName),[p,x]=n.useState(s.initialDescription),[g,b]=n.useState(s.initialBody),[c,h]=n.useState(!1),[t,l]=n.useState(null),[f,r]=n.useState(1),y=n.useRef(!1),S=n.useRef(i);S.current=i;const u=s.status==="open",w=n.useRef(0);n.useEffect(()=>{if(!u)return;y.current=!1;const d=new Date(s.expiresAt).getTime(),a=Date.now(),N=Math.max(d-a,1);w.current=N,r(1);const k=()=>{const M=d-Date.now(),D=Math.max(0,Math.min(1,M/N));r(D),M<=0&&!y.current&&(y.current=!0,T(s.requestId).catch(()=>{}).finally(()=>{S.current(s.requestId,"expired")}))};k();const A=window.setInterval(k,100);return()=>window.clearInterval(A)},[u,s.expiresAt,s.requestId]);async function C(){if(c||!u)return;const d=m.trim();if(!d){l("名称不能为空");return}if(!U.test(d)){l("名称仅允许英文、数字、下划线");return}if(!g.trim()){l("正文不能为空");return}h(!0),l(null);try{await P(s.requestId,{name:d,description:p.trim(),body:g}),i(s.requestId,"submitted",d)}catch{i(s.requestId,"failed")}finally{h(!1)}}async function I(){if(!(c||!u)){h(!0),l(null),y.current=!0;try{await B(s.requestId),i(s.requestId,"cancelled")}catch{i(s.requestId,"failed")}finally{h(!1)}}}const j=Math.max(0,Math.ceil(f*w.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card mdocs-agent-skill-form-card"+(u?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),u?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[j,"s"]}):null]}),u?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(f*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${f})`}})}):null,s.status==="submitted"?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已提交",s.submittedName?`:${s.submittedName}`:""]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,表单已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,u?e.jsxs("div",{className:"mdocs-agent-skill-form-fields",children:[e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"名称(英文数字下划线)"}),e.jsx("input",{type:"text",value:m,onChange:d=>v(d.target.value),maxLength:64,disabled:c,autoComplete:"off",spellCheck:!1})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"简介"}),e.jsx("input",{type:"text",value:p,onChange:d=>x(d.target.value),maxLength:200,disabled:c})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:g,onChange:d=>b(d.target.value),rows:8,disabled:c})]}),t?e.jsx("p",{className:"mdocs-agent-skill-form-error",children:t}):null,e.jsxs("div",{className:"mdocs-agent-skill-form-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-skill-form-cancel",disabled:c,onClick:()=>void I(),children:"取消"}),e.jsx("button",{type:"button",disabled:c,onClick:()=>void C(),children:c?"提交中…":s.mode==="create"?"创建":"保存"})]})]}):null]})}export{W as A,H,X as S,O as a};
@@ -0,0 +1,7 @@
1
+ import{r as u,j as n}from"./react-vendor-BJFXgntS.js";import{ag as Z,ah as de,i as ue,ak as me,as as he,al as fe,am as ge,an as xe}from"./index-4TuRcE3b.js";import{H as ke,A as ee,S as ye,a as we}from"./AgentSkillFormCard-yk7PWF0W.js";import{P as je}from"./plus-CiGwts52.js";import{D as pe,E as Ne}from"./ui-BHvBMRFE.js";import"./diagram--gCCJK__.js";import"./motion-DddvD-ez.js";function U(e){return e===""?[]:e.split(`
2
+ `)}function ae(e){return e.join(`
3
+ `)}function z(e,i){const s=U(e),a=U(i),m=s.length,k=a.length,y=Array.from({length:m+1},()=>Array.from({length:k+1},()=>0));for(let C=m-1;C>=0;C--)for(let I=k-1;I>=0;I--)s[C]===a[I]?y[C][I]=y[C+1][I+1]+1:y[C][I]=Math.max(y[C+1][I],y[C][I+1]);const S=[];let g=0,w=0;for(;g<m||w<k;)if(g<m&&w<k&&s[g]===a[w])S.push({kind:"eq",oi:g,ni:w}),g++,w++;else if(w<k&&(g===m||y[g][w+1]>=y[g+1][w]))S.push({kind:"ins",oi:g,ni:w}),w++;else if(g<m)S.push({kind:"del",oi:g,ni:w}),g++;else break;const E=[];let c=0,_=0;for(;c<S.length;){if(S[c].kind==="eq"){c++;continue}const C=S[c].oi,I=S[c].ni,T=[],L=[];let v=C,H=I;for(;c<S.length&&S[c].kind!=="eq";){const A=S[c];A.kind==="del"?(T.push(s[A.oi]),v=A.oi+1):(L.push(a[A.ni]),H=A.ni+1),c++}E.push({id:`h${_++}`,oldStart:C,oldEnd:v,newStart:I,newEnd:H,oldLines:T,newLines:L})}return E}function be(e,i){const s=U(e);return ae([...s.slice(0,i.oldStart),...i.newLines,...s.slice(i.oldEnd)])}function Ce(e,i){const s=U(e);return ae([...s.slice(0,i.newStart),...i.oldLines,...s.slice(i.newEnd)])}function J(e){return e===""?[]:e.split(`
4
+ `)}function V(e){return e.join(`
5
+ `)}function Se(e,i){const s=J(e),a=[];let m=0;return i.forEach((k,y)=>{k.oldStart>m&&a.push({kind:"same",lines:s.slice(m,k.oldStart),key:`s-${m}-${k.oldStart}`}),a.push({kind:"hunk",hunk:k,hunkIndex:y,key:`h-${k.id}-${y}`}),m=k.oldEnd}),m<s.length?a.push({kind:"same",lines:s.slice(m),key:`s-${m}-end`}):i.length===0&&s.length===0&&a.push({kind:"same",lines:[],key:"s-empty"}),a}function Ie(e){const i=[],s=[];for(const a of e)a.kind==="same"?i.push(V(a.lines)):s.push(V(a.hunk.newLines));return{sameTexts:i,newTexts:s}}function Me(e,i){const s=[];let a=0,m=0;for(const k of e)if(k.kind==="same"){const y=i.sameTexts[a++]??"";s.push(...J(y))}else{const y=i.newTexts[m++]??"";s.push(...J(y))}return V(s)}function ve(e){return e.oldLines.length===0?"add":e.newLines.length===0?"del":"mod"}function ne(e){const i=Math.max(1,J(e.value).length);return n.jsxs("div",{className:`mdocs-ai-write-line ${e.className}`,children:[n.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),n.jsx("textarea",{className:"mdocs-ai-write-inline-edit",value:e.value,rows:i,spellCheck:!1,"aria-label":e["aria-label"],onChange:s=>e.onChange(s.target.value),onBlur:()=>e.onBlurFlush()})]})}function Ae(e){const i=!!e.sending,[s,a]=u.useState(0),[m,k]=u.useState(null),[y,S]=u.useState({sameTexts:[],newTexts:[]}),g=u.useRef(!1),w=u.useRef([]),E=u.useRef(y);E.current=y;const c=u.useMemo(()=>e.proposedMd==null||e.proposedMd===e.currentMd?[]:z(e.currentMd,e.proposedMd),[e.currentMd,e.proposedMd]),_=u.useMemo(()=>Se(e.currentMd,c),[e.currentMd,c]);w.current=_;const C=!i&&c.length>0;u.useEffect(()=>{if(c.length===0){a(0);return}a(l=>Math.min(l,c.length-1))},[c.length]),u.useEffect(()=>{if(!C){g.current=!1;return}g.current||S(Ie(_))},[C,e.proposedMd,e.currentMd,_]);const I=m??s;function T(){return Me(w.current,E.current)}function L(){if(!C)return e.proposedMd;const l=T();return g.current=!1,l===e.currentMd?(e.onProposedChange(null),null):(l!==e.proposedMd&&e.onProposedChange(l),l)}function v(l){const h=c.indexOf(l),x=T();if(g.current=!1,x===e.currentMd){e.onProposedChange(null);return}const N=z(e.currentMd,x),b=N[h]??N.find(q=>q.id===l.id);if(!b){e.onProposedChange(x);return}const p=be(e.currentMd,b);e.onCurrentChange(p),z(p,x).length===0?e.onProposedChange(null):e.onProposedChange(x)}function H(l){const h=c.indexOf(l),x=T();if(g.current=!1,x===e.currentMd){e.onProposedChange(null);return}const N=z(e.currentMd,x),b=N[h]??N.find(D=>D.id===l.id);if(!b){e.onProposedChange(x);return}const p=Ce(x,b);p===e.currentMd?e.onProposedChange(null):e.onProposedChange(p)}function A(){const l=T();g.current=!1,e.onCurrentChange(l),e.onProposedChange(null)}function F(){g.current=!1,e.onProposedChange(null)}function K(l){c.length!==0&&a(h=>{const x=(h+l+c.length)%c.length,N=document.getElementById(`mdocs-ai-hunk-${x}`);return N==null||N.scrollIntoView({block:"center",behavior:"smooth"}),x})}function M(l,h){g.current=!0,S(x=>{const N=x.sameTexts.slice();return N[l]=h,{...x,sameTexts:N}})}function O(l,h){g.current=!0,S(x=>{const N=x.newTexts.slice();return N[l]=h,{...x,newTexts:N}})}const j=c[I]??null;let B=0;return n.jsxs("div",{className:"mdocs-ai-write-md-pane",children:[n.jsxs("div",{className:"mdocs-ai-write-diff-toolbar",children:[n.jsx("span",{className:"mdocs-ai-write-diff-count",children:i?"接收中·编辑我的稿":c.length===0?e.proposedMd?"与提案一致(可编辑)":"Markdown 源码(可编辑)":`${c.length} 处变更(可改提案)`}),!i&&c.length>0?n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",onClick:A,children:"全部接受"}),n.jsx("button",{type:"button",onClick:F,children:"全部拒绝"})]}):null]}),C?n.jsxs("div",{className:"mdocs-ai-write-inline",role:"document",children:[_.map(l=>{if(l.kind==="same"){const p=B++,D=y.sameTexts[p]??V(l.lines);return n.jsx("div",{className:"mdocs-ai-write-inline-same",children:n.jsx(ne,{className:"ctx",value:D,"aria-label":"提案相同行",onChange:q=>M(p,q),onBlurFlush:()=>L()})},l.key)}const h=l.hunk,x=ve(h),N=l.hunkIndex===I,b=y.newTexts[l.hunkIndex]??V(h.newLines);return n.jsxs("div",{id:`mdocs-ai-hunk-${l.hunkIndex}`,className:`mdocs-ai-write-inline-hunk mdocs-ai-write-inline-hunk-${x}`+(N?" is-active":""),onMouseEnter:()=>k(l.hunkIndex),onMouseLeave:()=>k(null),onClick:()=>a(l.hunkIndex),children:[n.jsxs("div",{className:"mdocs-ai-write-hunk-hover",hidden:m!==l.hunkIndex,children:[n.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:p=>{p.stopPropagation(),H(h)},children:"拒绝"}),n.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:p=>{p.stopPropagation(),v(h)},children:"接受"})]}),n.jsx("pre",{className:"mdocs-ai-write-hunk-pre",children:h.oldLines.map((p,D)=>n.jsxs("div",{className:"mdocs-ai-write-line del mdocs-ai-write-line-readonly",children:[n.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),n.jsx("span",{className:"mdocs-ai-write-code",children:p||" "})]},`o${D}`))}),h.newLines.length>0||b!==""||x!=="del"?n.jsx(ne,{className:"add",value:b,"aria-label":"提案新增行",onChange:p=>O(l.hunkIndex,p),onBlurFlush:()=>L()}):null]},l.key)}),j?n.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"变更导航",children:[n.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>K(-1),children:"↑"}),n.jsxs("span",{children:[I+1," / ",c.length]}),n.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>K(1),children:"↓"}),n.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>H(j),children:"拒绝"}),n.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>v(j),children:"接受"})]}):null]}):n.jsx("textarea",{className:"mdocs-ai-write-editor",value:e.currentMd,onChange:l=>e.onCurrentChange(l.target.value),spellCheck:!1,placeholder:`# 标题
6
+
7
+ 在此编辑 Markdown 源码…`})]})}let te=0;function se(e){return te+=1,`${e}-${Date.now()}-${te}`}function $e(e,i){const s=e.slice(),a=s[s.length-1];return(a==null?void 0:a.type)==="text"?s[s.length-1]={type:"text",text:a.text+i}:s.push({type:"text",text:i}),s}function Ee(e,i){const s=e.slice(),a=s[s.length-1];return(a==null?void 0:a.type)==="thinking"?s[s.length-1]={type:"thinking",text:a.text+i}:s.push({type:"thinking",text:i}),s}function G(e,i){const s=i.trim();return s?[...e,{type:"tool",text:s}]:e}function Pe(e){return e.some(i=>i.type==="text"||i.type==="thinking"?i.text.length>0:!0)}function Te(e){const i=new Date(e);if(Number.isNaN(i.getTime()))return"";const s=new Date;return i.getFullYear()===s.getFullYear()&&i.getMonth()===s.getMonth()&&i.getDate()===s.getDate()?i.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):i.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function ie(e,i){return i.map((s,a)=>{const m=`h-${e}-${a}-${s.role}`;if(s.role==="user"){const k=s.skillNames&&s.skillNames.length>0?s.skillNames:s.skillIds&&s.skillIds.length>0?s.skillIds:void 0;return{id:m,role:"user",content:s.content,skillNames:k}}return{id:m,role:"assistant",blocks:s.content?[{type:"text",text:s.content}]:[]}})}function qe(e){const[i,s]=u.useState(e.initialMarkdown),[a,m]=u.useState(null),[k]=u.useState(e.initialMarkdown),[y,S]=u.useState(e.displayName||"未命名"),[g,w]=u.useState([]),[E,c]=u.useState(null),[_,C]=u.useState([]),[I,T]=u.useState(!1),[L,v]=u.useState(!1),[H,A]=u.useState(""),[F,K]=u.useState([]),[M,O]=u.useState(!1),[j,B]=u.useState(null),[l,h]=u.useState(null),[x,N]=u.useState(!1),b=u.useRef(null);async function p(){T(!0);try{const t=await me("coding",e.documentId);C(t.sessions),E||c(t.lastOpenedSessionId)}catch{}finally{T(!1)}}async function D(){try{const t=await Z();B(t)}catch{B({enabled:!1,skillsReady:!1,model:null})}}if(u.useEffect(()=>{var d;if(!e.open){v(!1),(d=b.current)==null||d.abort();return}s(e.initialMarkdown),m(null),S(e.displayName||"未命名"),A(""),h(null),v(!1);let t=!1;return(async()=>{try{const r=await Z();t||B(r)}catch{t||B({enabled:!1,skillsReady:!1,model:null})}try{const r=await de("coding",e.documentId);if(t)return;c(r.sessionId),w(ie(r.sessionId,r.messages))}catch{t||(c(null),w([]))}p()})(),()=>{t=!0}},[e.open,e.initialMarkdown,e.displayName,e.documentId]),u.useEffect(()=>()=>{var t;return(t=b.current)==null?void 0:t.abort()},[]),u.useEffect(()=>{e.open&&L&&p()},[L,e.open,e.documentId]),!e.open)return null;const q=(j==null?void 0:j.reason)==="missing_api_key",Q=a!=null&&a!==i?z(i,a):[];async function le(){var t;if(!M){(t=b.current)==null||t.abort(),h(null),v(!1),O(!1);try{const d=await fe("coding",e.documentId);c(d.sessionId),w([]),A(""),p()}catch(d){h(d instanceof Error?d.message:String(d))}}}async function oe(t){var d;if(!M){if(t===E){v(!1);return}(d=b.current)==null||d.abort(),h(null);try{const r=await ge(t,"coding",e.documentId);c(r.sessionId),w(ie(r.sessionId,r.messages)),A(""),v(!1)}catch(r){h(r instanceof Error?r.message:String(r))}}}async function X(){var Y;const t=H.trim();if(!t||M)return;if(!(j!=null&&j.enabled)){h("请先配置 API Key");return}(Y=b.current)==null||Y.abort();const d=new AbortController;b.current=d;const r=se("u"),R=se("a");w($=>[...$,{id:r,role:"user",content:t,skillNames:F.length>0?[...F]:void 0},{id:R,role:"assistant",blocks:[]}]),A(""),O(!0),h(null);const P=$=>{w(o=>o.map(f=>f.id===R&&f.role==="assistant"?{...f,blocks:$(f.blocks)}:f))};try{let $=!1;await xe(t,{mode:"coding",skillNames:F.length>0?F:void 0,documentId:e.documentId,workingMarkdown:i,baseMarkdown:k,signal:d.signal,onEvent:o=>{o.type==="text_delta"?P(f=>$e(f,o.text)):o.type==="thinking_delta"?P(f=>Ee(f,o.text)):o.type==="markdown_set"?m(o.markdown):o.type==="tool_notice"?P(f=>G(f,o.text)):o.type==="document_table"?P(f=>G(f,o.title)):o.type==="document_card"?P(f=>G(f,`读取文档「${o.title}」`)):o.type==="sources"?o.items.length>0&&P(f=>G(f,`已阅读 ${o.items.length} 个手册页面`)):o.type==="skill_form_card"?P(f=>[...f,{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"}]):o.type==="skill_form_expired"?P(f=>f.map(W=>W.type==="skill_form_card"&&W.requestId===o.requestId&&W.status==="open"?{...W,status:"expired"}:W)):o.type==="error"&&($=!0,h(o.message))}}),!d.signal.aborted&&!$&&K([]),p()}catch($){d.signal.aborted||h($ instanceof Error?$.message:String($))}finally{b.current===d&&(b.current=null),O(!1)}}async function re(){let t=i;if(Q.length>0){if(!window.confirm(`还有 ${Q.length} 段未审阅,将全部接受后写回。继续?`))return;t=a??i,s(t),m(null)}N(!0);const d=!e.documentId;try{const r=await e.onComplete({markdown:t,documentId:e.documentId,displayName:y.trim()||"未命名"}),R=r&&typeof r=="object"&&typeof r.documentId=="string"?r.documentId.trim():"";if(d&&R&&E)try{await he(E,R)}catch{}e.onClose()}catch(r){if(r!=null&&r.silent||r instanceof Error&&r.message==="cancelled")return;h(r instanceof Error?r.message:String(r))}finally{N(!1)}}function ce(){var t;(i!==k||a!=null)&&!window.confirm("取消帮写?未写回的修改将丢失。")||((t=b.current)==null||t.abort(),e.onClose())}return n.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[n.jsxs("header",{className:"mdocs-ai-write-header",children:[n.jsxs("div",{className:"mdocs-ai-write-header-left",children:[n.jsx("img",{src:ue,alt:"",className:"mdocs-ai-write-title-logo"}),n.jsx("strong",{children:"帮写"}),n.jsx("input",{className:"mdocs-ai-write-title",value:y,onChange:t=>S(t.target.value),"aria-label":"文档标题"})]}),n.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[n.jsx("button",{type:"button",onClick:ce,disabled:x,children:"取消"}),n.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void re(),disabled:x,children:x?"写回中…":"完成并写回"})]})]}),n.jsxs("div",{className:"mdocs-ai-write-body",children:[n.jsxs("section",{className:"mdocs-ai-write-chat",children:[n.jsxs("div",{className:"mdocs-ai-write-chat-toolbar",children:[n.jsx("span",{className:"mdocs-ai-write-chat-toolbar-label",children:"对话"}),n.jsxs("div",{className:"mdocs-ai-write-chat-toolbar-actions",children:[n.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:M,onClick:()=>void le(),children:n.jsx(je,{size:16,strokeWidth:1.8})}),n.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(L?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>v(t=>!t),children:n.jsx(ke,{size:16,strokeWidth:1.8})})]})]}),L?n.jsxs("div",{className:"mdocs-ai-write-history mdocs-agent-panel-history",children:[n.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[n.jsx("span",{children:"历史会话"}),n.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>v(!1),children:"返回对话"})]}),I?n.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):_.length===0?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),n.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):n.jsx("ul",{className:"mdocs-agent-panel-history-list",children:_.map(t=>n.jsx("li",{children:n.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(t.id===E?" active":""),disabled:M,onClick:()=>void oe(t.id),children:[n.jsx("span",{className:"mdocs-agent-panel-history-title",children:t.title}),n.jsx("span",{className:"mdocs-agent-panel-history-time",children:Te(t.updatedAt)})]})},t.id))})]}):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"mdocs-ai-write-chat-messages",children:g.length===0?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"mdocs-ai-write-hint",children:"描述你想写或改的内容。助手可读取右侧当前稿与进场快照,再更新提案;请按段接受或拒绝后完成写回。"}),q?n.jsx(ee,{onConfigured:D}):null]}):g.map(t=>n.jsx("div",{className:"mdocs-ai-write-msg"+(t.role==="user"?" mdocs-ai-write-msg-user":""),children:t.role==="user"?n.jsxs(n.Fragment,{children:[t.skillNames&&t.skillNames.length>0?n.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",t.skillNames.length]}):null,t.content]}):Pe(t.blocks)?n.jsx("div",{className:"mdocs-ai-write-timeline",children:t.blocks.map((d,r)=>d.type==="thinking"?d.text?n.jsxs("details",{className:"mdocs-ai-write-thinking",open:M,children:[n.jsx("summary",{children:"思考中"}),n.jsx("pre",{className:"mdocs-ai-write-thinking-body",children:d.text})]},`${t.id}-think-${r}`):null:d.type==="tool"?n.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:d.text},`${t.id}-tool-${r}`):d.type==="skill_form_card"?n.jsx(ye,{block:d,onResolved:(R,P,Y)=>{w($=>$.map(o=>o.id!==t.id||o.role!=="assistant"?o:{...o,blocks:o.blocks.map(f=>f.type==="skill_form_card"&&f.requestId===R?{...f,status:P,submittedName:P==="submitted"?Y:f.submittedName}:f)}))}},`${t.id}-sf-${r}`):d.text?n.jsx("div",{className:"mdocs-agent-panel-md",children:n.jsx(pe,{remarkPlugins:[Ne],children:d.text})},`${t.id}-text-${r}`):null)}):M?n.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[n.jsx("span",{}),n.jsx("span",{}),n.jsx("span",{})]}):null},t.id))}),l?n.jsx("p",{className:"mdocs-ai-write-error",children:l}):null,q&&g.length>0?n.jsx(ee,{onConfigured:D}):null,n.jsxs("div",{className:"mdocs-ai-write-input-row",children:[n.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:[n.jsx(we,{selectedNames:F,onChange:K,disabled:M||!(j!=null&&j.enabled)}),n.jsx("textarea",{rows:2,value:H,disabled:M||!(j!=null&&j.enabled),placeholder:j!=null&&j.enabled?"说说要写什么…":"请先配置 API Key",onChange:t=>A(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),X())}})]}),n.jsx("button",{type:"button",className:M?"mdocs-ai-write-stop":void 0,disabled:M?!1:!(j!=null&&j.enabled),onClick:()=>{var t;if(M){(t=b.current)==null||t.abort();return}X()},children:M?"停止":"发送"})]})]})]}),n.jsx(Ae,{currentMd:i,proposedMd:a,sending:M,onCurrentChange:s,onProposedChange:m})]})]})}export{qe as AiWriteWorkbench};
@@ -1,2 +1,2 @@
1
- import{Q as I,S as H,T as F,U as O,V as G}from"./react-BUhFwPCj.js";import{r as c,j as e}from"./react-vendor-BJFXgntS.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-CCgjRlVJ.js";import{M as _}from"./meta2d-D3b5RRN8.js";import"./editor-ONzd_YnO.js";import"./ui-06fxEgif.js";import"./motion-92iQWeIW.js";import"./diagram-3lhA7FYR.js";import"./index-DgM2rYI-.js";import"./plus-BWV299MC.js";import"./copy-CX8GOyUb.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-B99eF5mm.js";import{r as c,j as e}from"./react-vendor-BJFXgntS.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-D1J2-XNv.js";import{M as _}from"./meta2d-D3b5RRN8.js";import"./editor-ONzd_YnO.js";import"./ui-BHvBMRFE.js";import"./motion-DddvD-ez.js";import"./diagram--gCCJK__.js";import"./index-4TuRcE3b.js";import"./plus-CiGwts52.js";import"./copy-UwfRYkpI.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};
@@ -0,0 +1,26 @@
1
+ import{r as i,j as n}from"./react-vendor-BJFXgntS.js";import{B as ke}from"./ui-BHvBMRFE.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-4TuRcE3b.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-B99eF5mm.js";import{H as Pt,a as Tt,b as Bt,M as Lt,T as _t,S as Ot,W as zt,o as Ht,c as Ee}from"./Toolbar-BDJ6WABq.js";import{V as Ft}from"./VisitorPickerModal-DPKIoySi.js";import"./motion-DddvD-ez.js";import"./diagram--gCCJK__.js";import"./editor-ONzd_YnO.js";import"./plus-CiGwts52.js";import"./copy-UwfRYkpI.js";/**
2
+ * @license lucide-react v0.562.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const Ut=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],Wt=Y("ellipsis-vertical",Ut);/**
7
+ * @license lucide-react v0.562.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const qt=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],Vt=Y("refresh-cw",qt);/**
12
+ * @license lucide-react v0.562.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const $t=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M6.376 18.91a6 6 0 0 1 11.249.003",key:"hnjrf2"}],["circle",{cx:"12",cy:"11",r:"4",key:"1gt34v"}]],Yt=Y("shield-user",$t);/**
17
+ * @license lucide-react v0.562.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const Jt=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],Gt=Y("text-align-justify",Jt);/**
22
+ * @license lucide-react v0.562.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
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,B;if(!y){(O=f.current)==null||O.call(f),f.current=null;return}if(!e)return;const s=e.getLexicalEditor();if(!s)return;(B=f.current)==null||B.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 L=Q(e);L!==null&&L!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",a,"oldLen:",x.current.length,"newLen:",L.length),x.current=L,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),[B,N]=i.useState(!1),[ae,L]=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(!B){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 Be(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const Le=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:Bt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(de,{tag:"h3"})}},{type:"divider"},{icon:Lt,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})})}},{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:Be(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||L(!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:B,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:B,"data-tooltip":g?"取消收藏":"收藏",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,opacity:B?.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:()=>L(!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:Le,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};
@@ -1,4 +1,4 @@
1
- import{r as b,j as o}from"./react-vendor-BJFXgntS.js";import{b as V,as as _,at as J,au as Q,av as X}from"./index-DgM2rYI-.js";import{E as Y,B as Z}from"./react-BUhFwPCj.js";import"./ui-06fxEgif.js";import"./motion-92iQWeIW.js";import"./editor-ONzd_YnO.js";import"./diagram-3lhA7FYR.js";import"./plus-BWV299MC.js";import"./copy-CX8GOyUb.js";function B({lexicalJson:e,onMarkdown:n,onError:s}){const[u,l]=b.useState(null),i=b.useRef(!1);return b.useEffect(()=>{i.current=!1},[e]),b.useEffect(()=>{if(!(!u||i.current))try{u.setDocument("json",e);const c=u.getDocument("markdown");typeof c=="string"&&(i.current=!0,n(c))}catch{s==null||s()}},[u,e,n,s]),o.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:o.jsx(Y,{content:e,type:"json",editable:!1,onInit:l,plugins:[Z]})})}function ee(e){const{t:n}=V(),[s,u]=b.useState(0),l=e.segments.filter(t=>t.kind==="conflict"),i=e.unresolvedCount>0;b.useEffect(()=>{if(l.length===0){u(0);return}u(t=>Math.min(t,l.length-1))},[l.length]);function c(t){l.length!==0&&u(d=>{var f;const a=(d+t+l.length)%l.length;return(f=document.getElementById(`mdocs-merge-hunk-${a}`))==null||f.scrollIntoView({block:"center",behavior:"smooth"}),a})}let r=-1;return o.jsxs("div",{className:"mdocs-merge-inline-pane",children:[o.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[o.jsx("span",{className:"mdocs-merge-inline-hint",children:i?n("mergeReviewHint"):l.length===0?n("mergeNoConflicts"):n("mergeEditAfterResolve")}),l.length>0?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:e.onUseAllMine,children:n("mergeUseAllMine")}),o.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:n("mergeUseAllTheirs")})]}):null]}),i?o.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((t,d)=>{if(t.kind==="unchanged")return o.jsx("pre",{className:"mdocs-merge-inline-same",children:t.lines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},g))},`u-${d}`);r+=1;const a=r,f=t.resolution!=="unresolved",m=a===s;return o.jsxs("div",{id:`mdocs-merge-hunk-${a}`,className:"mdocs-merge-inline-hunk"+(m?" is-active":"")+(f?" is-resolved":""),onClick:()=>u(a),children:[f?o.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:t.resolution==="remote"?n("mergeReceive"):n("mergeReject")}):o.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:x=>{x.stopPropagation(),e.onReject(t.id)},children:n("mergeReject")}),o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:x=>{x.stopPropagation(),e.onReceive(t.id)},children:n("mergeReceive")})]}),o.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[t.localLines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line del",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},`l${g}`)),t.remoteLines.map((x,g)=>o.jsxs("div",{className:"mdocs-ai-write-line add",children:[o.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),o.jsx("span",{className:"mdocs-ai-write-code",children:x||" "})]},`r${g}`))]})]},t.id)}),l.length>0?o.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[o.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>c(-1),children:"↑"}),o.jsxs("span",{children:[s+1," / ",l.length]}),o.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>c(1),children:"↓"}),l[s]&&l[s].resolution==="unresolved"?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(l[s].id),children:n("mergeReject")}),o.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(l[s].id),children:n("mergeReceive")})]}):null]}):null]}):o.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:t=>e.onEditableChange(t.target.value),spellCheck:!1})]})}function te(e,n){let s={};for(let i=0;i<n.length;i++){const c=n[i];s[c]?s[c].push(i):s[c]=[i]}let l=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let i=0;i<e.length;i++){const c=e[i],r=s[c]||[];let t=0,d=l[0];for(let a=0;a<r.length;a++){const f=r[a];let m;for(m=t;m<l.length&&!(l[m].buffer2index<f&&(m===l.length-1||l[m+1].buffer2index>f));m++);if(m<l.length){const x={buffer1index:i,buffer2index:f,chain:l[m]};if(t===l.length?l.push(d):l[t]=d,t=m+1,d=x,t===l.length)break}}l[t]=d}return l[l.length-1]}function q(e,n){const s=te(e,n);let u=[],l=e.length,i=n.length;for(let c=s;c!==null;c=c.chain){const r=l-c.buffer1index-1,t=i-c.buffer2index-1;l=c.buffer1index,i=c.buffer2index,(r||t)&&u.push({buffer1:[l+1,r],buffer1Content:e.slice(l+1,l+1+r),buffer2:[i+1,t],buffer2Content:n.slice(i+1,i+1+t)})}return u.reverse(),u}function ne(e,n,s){let u=[];function l(t,d){u.push({ab:d,oStart:t.buffer1[0],oLength:t.buffer1[1],abStart:t.buffer2[0],abLength:t.buffer2[1]})}q(n,e).forEach(t=>l(t,"a")),q(n,s).forEach(t=>l(t,"b")),u.sort((t,d)=>t.oStart-d.oStart);let i=[],c=0;function r(t){t>c&&(i.push({stable:!0,buffer:"o",bufferStart:c,bufferLength:t-c,bufferContent:n.slice(c,t)}),c=t)}for(;u.length;){let t=u.shift(),d=t.oStart,a=t.oStart+t.oLength,f=[t];for(r(d);u.length;){const m=u[0],x=m.oStart;if(x>a)break;a=Math.max(a,x+m.oLength),f.push(u.shift())}if(f.length===1){if(t.abLength>0){const m=t.ab==="a"?e:s;i.push({stable:!0,buffer:t.ab,bufferStart:t.abStart,bufferLength:t.abLength,bufferContent:m.slice(t.abStart,t.abStart+t.abLength)})}}else{let m={a:[e.length,-1,n.length,-1],b:[s.length,-1,n.length,-1]};for(;f.length;){t=f.shift();const v=t.oStart,p=v+t.oLength,L=t.abStart,w=L+t.abLength;let S=m[t.ab];S[0]=Math.min(L,S[0]),S[1]=Math.max(w,S[1]),S[2]=Math.min(v,S[2]),S[3]=Math.max(p,S[3])}const x=m.a[0]+(d-m.a[2]),g=m.a[1]+(a-m.a[3]),j=m.b[0]+(d-m.b[2]),h=m.b[1]+(a-m.b[3]);let y={stable:!1,aStart:x,aLength:g-x,aContent:e.slice(x,g),oStart:d,oLength:a-d,oContent:n.slice(d,a),bStart:j,bLength:h-j,bContent:s.slice(j,h)};i.push(y)}c=a}return r(n.length),i}function le(e,n,s,u){u=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},u),typeof e=="string"&&(e=e.split(u.stringSeparator)),typeof n=="string"&&(n=n.split(u.stringSeparator)),typeof s=="string"&&(s=s.split(u.stringSeparator));let i=[];const c=ne(e,n,s);let r=[];function t(){r.length&&i.push({ok:r}),r=[]}function d(a,f){if(a.length!==f.length)return!1;for(let m=0;m<a.length;m++)if(a[m]!==f[m])return!1;return!0}return c.forEach(a=>{a.stable?r.push(...a.bufferContent):u.excludeFalseConflicts&&d(a.aContent,a.bContent)?r.push(...a.aContent):(t(),i.push({conflict:{a:a.aContent,aIndex:a.aStart,o:a.oContent,oIndex:a.oStart,b:a.bContent,bIndex:a.bStart}}))}),t(),i}const se=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function ie(e){return`<!-- mdocs-merge-conflict:${e} -->`}function oe(e){const n=e.trim().match(se);return(n==null?void 0:n[1])??null}function M(e){return e===""?[]:e.split(`
1
+ import{r as b,j as o}from"./react-vendor-BJFXgntS.js";import{b as V,av as _,aw as J,ax as Q,ay as X}from"./index-4TuRcE3b.js";import{E as Y,B as Z}from"./react-B99eF5mm.js";import"./ui-BHvBMRFE.js";import"./motion-DddvD-ez.js";import"./diagram--gCCJK__.js";import"./editor-ONzd_YnO.js";import"./plus-CiGwts52.js";import"./copy-UwfRYkpI.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,ae as C}from"./react-vendor-BJFXgntS.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as H,w as f,j as L,k as F,l as q,I as U,m as b,n as V,o as z,p as J,q as W,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-B99eF5mm.js";import{v as Q,x as X,H as ee,y as te,A as k,z as oe}from"./ui-BHvBMRFE.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-BDJ6WABq.js";import{N as me}from"./index-4TuRcE3b.js";import"./editor-ONzd_YnO.js";import"./diagram--gCCJK__.js";import"./plus-CiGwts52.js";import"./copy-UwfRYkpI.js";import"./motion-DddvD-ez.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(z,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(J,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{ce(l=>{for(const u of l)e.dispatchCommand(W,{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,H,f(L,{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 Ce(){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{Ce as PlaygroundPage};