@fgbg/mdocs 1.3.31 → 1.4.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 (83) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +31 -0
  3. package/agent-skills/usage-onboarding-ai/SKILL.md +17 -5
  4. package/agent-skills/usage-settings/SKILL.md +1 -1
  5. package/dist/server/agent/Agent/run-manager.js +316 -0
  6. package/dist/server/agent/Agent/run-manager.js.map +1 -0
  7. package/dist/server/agent/Agent/run-manager.test.js +122 -0
  8. package/dist/server/agent/Agent/run-manager.test.js.map +1 -0
  9. package/dist/server/agent/Agent/run-store.js +141 -0
  10. package/dist/server/agent/Agent/run-store.js.map +1 -0
  11. package/dist/server/agent/Agent/run-store.test.js +64 -0
  12. package/dist/server/agent/Agent/run-store.test.js.map +1 -0
  13. package/dist/server/agent/Agent/run.js +2 -2
  14. package/dist/server/agent/Agent/run.js.map +1 -1
  15. package/dist/server/agent/Agent/system-prompt.js +9 -7
  16. package/dist/server/agent/Agent/system-prompt.js.map +1 -1
  17. package/dist/server/agent/Agent/tool-call-ui.js +1 -0
  18. package/dist/server/agent/Agent/tool-call-ui.js.map +1 -1
  19. package/dist/server/agent/Agent/tool-ui-effects.js +28 -7
  20. package/dist/server/agent/Agent/tool-ui-effects.js.map +1 -1
  21. package/dist/server/agent/Agent/tools-registry.js +2 -2
  22. package/dist/server/agent/Agent/tools-registry.js.map +1 -1
  23. package/dist/server/agent/Agent/tools-registry.test.js +2 -1
  24. package/dist/server/agent/Agent/tools-registry.test.js.map +1 -1
  25. package/dist/server/agent/Agent/tools-template.js +3 -2
  26. package/dist/server/agent/Agent/tools-template.js.map +1 -1
  27. package/dist/server/agent/Agent/tools-thinking.js +33 -0
  28. package/dist/server/agent/Agent/tools-thinking.js.map +1 -0
  29. package/dist/server/agent/Agent/tools-user-skills.js +50 -39
  30. package/dist/server/agent/Agent/tools-user-skills.js.map +1 -1
  31. package/dist/server/agent/Agent/user-skills.js +11 -5
  32. package/dist/server/agent/Agent/user-skills.js.map +1 -1
  33. package/dist/server/agent/Config/config.js +47 -0
  34. package/dist/server/agent/Config/config.js.map +1 -1
  35. package/dist/server/agent/Config/config.test.js +29 -0
  36. package/dist/server/agent/Config/config.test.js.map +1 -1
  37. package/dist/server/app.js +3 -0
  38. package/dist/server/app.js.map +1 -1
  39. package/dist/server/db/repositories/agent-model-config.repo.js +6 -4
  40. package/dist/server/db/repositories/agent-model-config.repo.js.map +1 -1
  41. package/dist/server/db/repositories/agent-user-skill.repo.js +7 -5
  42. package/dist/server/db/repositories/agent-user-skill.repo.js.map +1 -1
  43. package/dist/server/db/repositories/agent-user-skill.repo.test.js +31 -0
  44. package/dist/server/db/repositories/agent-user-skill.repo.test.js.map +1 -0
  45. package/dist/server/db/schema.js +20 -0
  46. package/dist/server/db/schema.js.map +1 -1
  47. package/dist/server/routes/agent.routes.js +108 -18
  48. package/dist/server/routes/agent.routes.js.map +1 -1
  49. package/dist/server/search/document-index-manager.js +51 -8
  50. package/dist/server/search/document-index-manager.js.map +1 -1
  51. package/dist/server/search/document-index-manager.test.js +78 -2
  52. package/dist/server/search/document-index-manager.test.js.map +1 -1
  53. package/dist/shared/file-type-policy.js +1 -1
  54. package/dist/shared/file-type-policy.js.map +1 -1
  55. package/dist/shared/file-type-policy.test.js +3 -2
  56. package/dist/shared/file-type-policy.test.js.map +1 -1
  57. package/dist/web/assets/AgentChatPanel-_IV-LAS4.js +42 -0
  58. package/dist/web/assets/{AiWriteWorkbench-Dq0aCk5c.js → AiWriteWorkbench-DzJAmRHY.js} +3 -3
  59. package/dist/web/assets/{DiagramEditor-NtNY3sZL-DHC7qgkW.js → DiagramEditor-NtNY3sZL-KWdKFFEL.js} +1 -1
  60. package/dist/web/assets/{DocChrome-7KIXAHsE.js → DocChrome-CtT7xOl6.js} +4 -4
  61. package/dist/web/assets/{DocumentEditor-CmIk_VBn.js → DocumentEditor-CrU6HKmU.js} +1 -1
  62. package/dist/web/assets/{HtmlEditor-REIKOoam.js → HtmlEditor-BBcreXJD.js} +1 -1
  63. package/dist/web/assets/{MergeView-DCgxAslc.js → MergeView-LV_hny8a.js} +1 -1
  64. package/dist/web/assets/{PlaygroundPage-Cz9TMo7h.js → PlaygroundPage-Bo9rM8MY.js} +1 -1
  65. package/dist/web/assets/SettingsPage-D09P0j48.js +21 -0
  66. package/dist/web/assets/SheetEditor-BPTMQ2s5.css +1 -0
  67. package/dist/web/assets/SheetEditor-Dyk-jpRL.js +26 -0
  68. package/dist/web/assets/{Toolbar-ClbpubYi.js → Toolbar-C1HmC2Qc.js} +1 -1
  69. package/dist/web/assets/{VisitorPickerModal-D4xmZbNY.js → VisitorPickerModal-Cx03Papl.js} +1 -1
  70. package/dist/web/assets/{check-CuLfkkz7.js → check-BAYRiedE.js} +1 -1
  71. package/dist/web/assets/{copy-CjAdouag.js → copy-J9XXv57X.js} +1 -1
  72. package/dist/web/assets/{file-type-policy-C6Nun42Q.js → file-type-policy-aRrzC4LZ.js} +1 -1
  73. package/dist/web/assets/{index-DAhW-QRN.js → index-Btfv_3-Q.js} +46 -46
  74. package/dist/web/assets/{italic-cqqPz-_Q.js → italic-BfR6fH81.js} +1 -1
  75. package/dist/web/assets/{meta2dEngine-BD2XbzaV-CNHknbe2.js → meta2dEngine-BD2XbzaV-MY1Hyyeh.js} +1 -1
  76. package/dist/web/assets/{plus-DkLh2brQ.js → plus-DvWl4lHk.js} +1 -1
  77. package/dist/web/assets/{react-Dj2vqPq5.js → react-C7aGt3wN.js} +3 -3
  78. package/dist/web/index.html +1 -1
  79. package/package.json +1 -1
  80. package/dist/web/assets/AgentChatPanel-e1h0rqbg.js +0 -42
  81. package/dist/web/assets/SettingsPage-DsLbUPt-.js +0 -21
  82. package/dist/web/assets/SheetEditor-Bkxxf3ly.js +0 -26
  83. package/dist/web/assets/SheetEditor-DbT_K_Ia.css +0 -1
@@ -1,4 +1,4 @@
1
- import{o}from"./index-DAhW-QRN.js";/**
1
+ import{o}from"./index-Btfv_3-Q.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{T as D,W as _}from"./react-Dj2vqPq5.js";import{r as p,a as A,b as u,c as z,i as N,M as O,C,f as k,d as q,e as L,g as V,h as j,s as B,j as G,k as H,l as J,m as W,n as K,o as Q}from"./meta2d-DP4Vt_ZE.js";import"./react-vendor-BVS1XoFi.js";import"./editor-DBWWidi3.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./index-DAhW-QRN.js";import"./plus-DkLh2brQ.js";import"./copy-CjAdouag.js";import"./check-CuLfkkz7.js";let E=!1;function U(){E||(p(k()),A(q()),p(L()),u(V()),p(j()),p(B()),u(G()),z(),u(H()),u(J()),p(W()),u(K()),A(Q()),E=!0)}let F=!1;function Z(){F||(U(),F=!0)}function Y(e,r){try{e==null||e.destroy()}catch{}try{r.remove()}catch{}}function X(e){let r=e.font;Object.defineProperty(e,"font",{configurable:!0,get:()=>r,set:t=>{r=typeof t=="string"?t.replace(/(\d+(?:\.\d+)?(?:px|pt|pc|em|ex|%|in|cm|mm))\s*\/\s*(\d+(?:\.\d+)?)(?=\s|$)/,"$1/normal"):t,e.__ctx&&(e.__ctx.font=r)}})}function ee(e){typeof e.ellipse!="function"&&(e.ellipse=(r,t,n,a,s=0,o=0,m=Math.PI*2,i=!1)=>{var M;if(n<0||a<0)throw new Error("IndexSizeError: The radius provided is negative.");((M=e.__currentElement)==null?void 0:M.nodeName)!=="path"&&e.beginPath();const h=Math.PI*2,f=Math.abs(m-o),y=f>=h-1e-4||f===0,w=s*180/Math.PI,v=i?0:1,c=g=>{const l=Math.cos(g),S=Math.sin(g),b=Math.cos(s),x=Math.sin(s);return{x:r+n*l*b-a*S*x,y:t+n*l*x+a*S*b}},d=(g,l)=>{e.__addPathCommand(`A ${n} ${a} ${w} ${g} ${v} ${l.x} ${l.y}`),e.__currentPosition=l},P=c(o);if(e.moveTo(P.x,P.y),y){d(1,c(o+Math.PI)),d(1,P);return}const T=c(m);d(f>Math.PI?1:0,T)})}function $(){return new Promise(e=>{requestAnimationFrame(()=>e())})}async function I(){await $(),await $()}function R(){const e=C.default??C.C2S??C;if(typeof e=="function")return e;const r=window.C2S;return typeof r=="function"?r:null}async function te(e,r=R()){var f,y,w,v;if(!r)return console.error("[meta2d] preview failed: canvas2svg constructor missing"),"";D(e.data()),e.render(!0),await I();const t=e.store,n=(f=t==null?void 0:t.data)==null?void 0:f.pens,a=Array.isArray(n)?n.length:0,s=10,o=e.getRect();if(!o||!Number.isFinite(o.width)||!Number.isFinite(o.height)||o.width<=0||o.height<=0)return a===0?_:(console.error("[meta2d] preview failed: invalid bounds",o),"");const m={...o,x:o.x-s,y:o.y-s},i=new r(Math.ceil(o.width+s*2),Math.ceil(o.height+s*2));if(i.textBaseline="middle",i.strokeStyle=((y=t==null?void 0:t.styles)==null?void 0:y.color)||"#1f1f1f",X(i),ee(i),Array.isArray(n)&&t){for(const c of n)if(!((c==null?void 0:c.visible)===!1||!N(c,t)))try{e.renderPenRaw(i,c,m,!0)}catch(d){console.error("[meta2d] preview failed: render pen",c,d)}}const h=((v=(w=i.getSerializedSvg)==null?void 0:w.call(i))==null?void 0:v.replace(/--le5le--/g,"&#x"))??"";return h.trim()?h:a===0?_:(console.error("[meta2d] preview failed: serialized SVG is empty",{pensCount:a}),"")}async function ue(e){const r=R();if(!r)return console.error("[meta2d] preview failed: canvas2svg constructor missing"),"";Z();const t=document.createElement("div");t.style.cssText="position:fixed;left:-20000px;top:0;width:1200px;height:800px;pointer-events:none;z-index:-1;",document.body.append(t);let n=null;try{let a;try{a=JSON.parse(e)}catch(s){return console.error("[meta2d] preview failed: invalid diagram JSON",s,e),""}return n=new O(t,{background:"#fff",grid:!1,rule:!1}),D(a),n.open(a),n.render(!0),await I(),te(n,r)}catch(a){return console.error("[meta2d] preview failed: unexpected error",a),""}finally{Y(n,t)}}export{Z as ensureMeta2dShapes,ue as generateSvgFromDiagram,te as generateSvgFromMeta2d};
1
+ import{T as D,W as _}from"./react-C7aGt3wN.js";import{r as p,a as A,b as u,c as z,i as N,M as O,C,f as k,d as q,e as L,g as V,h as j,s as B,j as G,k as H,l as J,m as W,n as K,o as Q}from"./meta2d-DP4Vt_ZE.js";import"./react-vendor-BVS1XoFi.js";import"./editor-DBWWidi3.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./index-Btfv_3-Q.js";import"./plus-DvWl4lHk.js";import"./copy-J9XXv57X.js";import"./check-BAYRiedE.js";let E=!1;function U(){E||(p(k()),A(q()),p(L()),u(V()),p(j()),p(B()),u(G()),z(),u(H()),u(J()),p(W()),u(K()),A(Q()),E=!0)}let F=!1;function Z(){F||(U(),F=!0)}function Y(e,r){try{e==null||e.destroy()}catch{}try{r.remove()}catch{}}function X(e){let r=e.font;Object.defineProperty(e,"font",{configurable:!0,get:()=>r,set:t=>{r=typeof t=="string"?t.replace(/(\d+(?:\.\d+)?(?:px|pt|pc|em|ex|%|in|cm|mm))\s*\/\s*(\d+(?:\.\d+)?)(?=\s|$)/,"$1/normal"):t,e.__ctx&&(e.__ctx.font=r)}})}function ee(e){typeof e.ellipse!="function"&&(e.ellipse=(r,t,n,a,s=0,o=0,m=Math.PI*2,i=!1)=>{var M;if(n<0||a<0)throw new Error("IndexSizeError: The radius provided is negative.");((M=e.__currentElement)==null?void 0:M.nodeName)!=="path"&&e.beginPath();const h=Math.PI*2,f=Math.abs(m-o),y=f>=h-1e-4||f===0,w=s*180/Math.PI,v=i?0:1,c=g=>{const l=Math.cos(g),S=Math.sin(g),b=Math.cos(s),x=Math.sin(s);return{x:r+n*l*b-a*S*x,y:t+n*l*x+a*S*b}},d=(g,l)=>{e.__addPathCommand(`A ${n} ${a} ${w} ${g} ${v} ${l.x} ${l.y}`),e.__currentPosition=l},P=c(o);if(e.moveTo(P.x,P.y),y){d(1,c(o+Math.PI)),d(1,P);return}const T=c(m);d(f>Math.PI?1:0,T)})}function $(){return new Promise(e=>{requestAnimationFrame(()=>e())})}async function I(){await $(),await $()}function R(){const e=C.default??C.C2S??C;if(typeof e=="function")return e;const r=window.C2S;return typeof r=="function"?r:null}async function te(e,r=R()){var f,y,w,v;if(!r)return console.error("[meta2d] preview failed: canvas2svg constructor missing"),"";D(e.data()),e.render(!0),await I();const t=e.store,n=(f=t==null?void 0:t.data)==null?void 0:f.pens,a=Array.isArray(n)?n.length:0,s=10,o=e.getRect();if(!o||!Number.isFinite(o.width)||!Number.isFinite(o.height)||o.width<=0||o.height<=0)return a===0?_:(console.error("[meta2d] preview failed: invalid bounds",o),"");const m={...o,x:o.x-s,y:o.y-s},i=new r(Math.ceil(o.width+s*2),Math.ceil(o.height+s*2));if(i.textBaseline="middle",i.strokeStyle=((y=t==null?void 0:t.styles)==null?void 0:y.color)||"#1f1f1f",X(i),ee(i),Array.isArray(n)&&t){for(const c of n)if(!((c==null?void 0:c.visible)===!1||!N(c,t)))try{e.renderPenRaw(i,c,m,!0)}catch(d){console.error("[meta2d] preview failed: render pen",c,d)}}const h=((v=(w=i.getSerializedSvg)==null?void 0:w.call(i))==null?void 0:v.replace(/--le5le--/g,"&#x"))??"";return h.trim()?h:a===0?_:(console.error("[meta2d] preview failed: serialized SVG is empty",{pensCount:a}),"")}async function ue(e){const r=R();if(!r)return console.error("[meta2d] preview failed: canvas2svg constructor missing"),"";Z();const t=document.createElement("div");t.style.cssText="position:fixed;left:-20000px;top:0;width:1200px;height:800px;pointer-events:none;z-index:-1;",document.body.append(t);let n=null;try{let a;try{a=JSON.parse(e)}catch(s){return console.error("[meta2d] preview failed: invalid diagram JSON",s,e),""}return n=new O(t,{background:"#fff",grid:!1,rule:!1}),D(a),n.open(a),n.render(!0),await I(),te(n,r)}catch(a){return console.error("[meta2d] preview failed: unexpected error",a),""}finally{Y(n,t)}}export{Z as ensureMeta2dShapes,ue as generateSvgFromDiagram,te as generateSvgFromMeta2d};
@@ -1,4 +1,4 @@
1
- import{o}from"./index-DAhW-QRN.js";/**
1
+ import{o}from"./index-Btfv_3-Q.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/html-GMplVEZG.js","assets/javascript-wDzz0qaB.js","assets/css-DPfMkruS.js","assets/scss-OYdSNvt2.js","assets/vue-DVfSmUF7.js","assets/typescript-BPQ3VLAy.js","assets/json-Cp-IABpG.js","assets/svelte-DZMnMd3x.js","assets/xml-sdJ4AIDG.js","assets/java-CylS5w8V.js","assets/cpp-BRuaLJcg.js","assets/c-BIGW1oBm.js","assets/sql-BLtJtn59.js","assets/ruby-BGX7qA9Y.js","assets/graphql-ChdNCCLP.js","assets/jsx-g9-lgVsj.js","assets/tsx-COt5Ahok.js","assets/shellscript-Yzrsuije.js","assets/lua-BaeVxFsk.js","assets/yaml-Buea-lGh.js","assets/php-Dhbhpdrm.js","assets/shellsession-BADoaaVG.js","assets/nginx-BpAMiNFr.js","assets/meta2dEngine-BD2XbzaV-CNHknbe2.js","assets/meta2d-DP4Vt_ZE.js","assets/react-vendor-BVS1XoFi.js","assets/editor-DBWWidi3.js","assets/ui-CEFkTVnG.js","assets/motion-BAXVQJfN.js","assets/diagram-BF8g9yg4.js","assets/index-DAhW-QRN.js","assets/index-C1Mc0Svw.css","assets/plus-DkLh2brQ.js","assets/copy-CjAdouag.js","assets/check-CuLfkkz7.js","assets/DiagramEditor-NtNY3sZL-DHC7qgkW.js"])))=>i.map(i=>d[i]);
2
- var x7=Object.defineProperty;var k7=(e,t,n)=>t in e?x7(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Mn=(e,t,n)=>k7(e,typeof t!="symbol"?t+"":t,n);import{B as eb,_ as Oe,r as E,af as w7,ag as v7,ah as S7,ai as Dn,aj as Xh,ak as Em,al as C7,j as O,b as Pi,am as _7,an as E7,ao as T7,ap as A7,z as M7,C as Jh,aq as N7,ar as D7,as as I7,at as L7}from"./react-vendor-BVS1XoFi.js";import{P as ze,e as Yh,A as ru,a as Ut,b as tb,w as de,c as fn,k as Cn,n as lt,F as Wr,p as Bi,$ as ce,O as Ln,G as pr,d as gs,l as gd,z as Sn,r as gt,v as nb,B as je,X as Fn,T as rb,M as Il,L as Ai,W as ml,f as hi,g as bs,h as So,C as Zh,Y as ib,y as Pt,i as Ll,H as Xe,j as F7,t as O7,m as Lo,J as bn,o as sb,R as fi,S as iu,Q as Zn,q as ob,s as z7,u as Aa,x as mt,E as R7,D as yc,I as P7,K as B7,_ as $7,N as su,U as bd,Z as ys,a0 as Co,a1 as Tt,a2 as ab,a3 as yn,a4 as j7,a5 as q7,a6 as Hr,a7 as Li,a8 as Fl,a9 as _n,aa as yd,ab as H7,ac as ub,ad as xd,ae as kd,af as _o,V as hn,ag as lb,ah as Qh,ai as U7,aj as cb,ak as W7,al as K7,am as V7,an as G7,ao as hb,ap as Qn,aq as X7,ar as jr,as as qn,at as xs,au as Tm,av as Am,aw as J7,ax as Y7,ay as Z7,az as Q7,aA as Ma,aB as fb,aC as db,aD as aa,aE as Na,aF as ou,aG as ek,aH as ef,aI as Mm,aJ as tk,aK as nk,aL as pb,aM as rk,aN as ik,aO as sk,aP as wd,aQ as Rr,aR as Eo,aS as vd,aT as ma,aU as fs,aV as Da,aW as tf,aX as Nm,aY as ga,aZ as gl,a_ as Ol,a$ as ok,b0 as ak,b1 as uk,b2 as lk,b3 as ck,b4 as Pr,b5 as hk,b6 as fk,b7 as dk,b8 as Dm,b9 as bl,ba as Im,bb as pk,bc as mk,bd as gk,be as bk,bf as ks,bg as Lm,bh as nf,bi as yk,bj as xk,bk as kk,bl as wk,bm as Fm,bn as ii,bo as Ia,bp as rf,bq as vk,br as ua,bs as mb,bt as gb,bu as bb,bv as yb,bw as xb,bx as Sk,by as Ck,bz as Sd,bA as kb,bB as _k,bC as Ek,bD as Cd,bE as Tk,bF as sf,bG as wb,bH as vb,bI as Ak,bJ as Mk,bK as Ju,bL as Sb,bM as Nk,bN as Dk,bO as Ik,bP as Cb,bQ as Lk,bR as Fk,bS as _b,bT as zl,bU as Ok,bV as zk,bW as Rk}from"./editor-DBWWidi3.js";import{as as tt,at,au as Pk,av as La,aw as Bk,ax as Rl,ay as $k,az as wi,aA as Zo,aB as jk,aC as qk,aD as Hk,aE as Uk,aF as Wk,aG as Kk,aH as Vk,aI as Gk,ad as _d,aJ as Xk,aK as It,ac as qr,aL as of,aM as Fa,aN as Ue,aO as Pl,aP as Eb,aQ as Jk,aR as zn,aS as Yk,aT as Zk,aU as Qk,aV as au,aW as Ed,aX as af,aY as Bl,aZ as Tb,a_ as ew,a$ as Om,b0 as tw,b1 as nw,t as uf,b2 as Ab,b3 as rw,b4 as iw,b5 as Mb,b6 as Nb,b7 as sw}from"./ui-CEFkTVnG.js";import{i as B0,j as ow,k as aw,l as uw,n as zm,e as Qo,s as lw,y as cw,h as Rm,m as Pm,r as hw,u as fw,v as dw,o as pw,w as mw,x as Db}from"./diagram-BF8g9yg4.js";import{o as xn,bc as gw,aY as Td,aK as bw}from"./index-DAhW-QRN.js";import{P as Bm}from"./plus-DkLh2brQ.js";import{a as yw,C as xw}from"./copy-CjAdouag.js";import{C as kw}from"./check-CuLfkkz7.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/html-GMplVEZG.js","assets/javascript-wDzz0qaB.js","assets/css-DPfMkruS.js","assets/scss-OYdSNvt2.js","assets/vue-DVfSmUF7.js","assets/typescript-BPQ3VLAy.js","assets/json-Cp-IABpG.js","assets/svelte-DZMnMd3x.js","assets/xml-sdJ4AIDG.js","assets/java-CylS5w8V.js","assets/cpp-BRuaLJcg.js","assets/c-BIGW1oBm.js","assets/sql-BLtJtn59.js","assets/ruby-BGX7qA9Y.js","assets/graphql-ChdNCCLP.js","assets/jsx-g9-lgVsj.js","assets/tsx-COt5Ahok.js","assets/shellscript-Yzrsuije.js","assets/lua-BaeVxFsk.js","assets/yaml-Buea-lGh.js","assets/php-Dhbhpdrm.js","assets/shellsession-BADoaaVG.js","assets/nginx-BpAMiNFr.js","assets/meta2dEngine-BD2XbzaV-MY1Hyyeh.js","assets/meta2d-DP4Vt_ZE.js","assets/react-vendor-BVS1XoFi.js","assets/editor-DBWWidi3.js","assets/ui-CEFkTVnG.js","assets/motion-BAXVQJfN.js","assets/diagram-BF8g9yg4.js","assets/index-Btfv_3-Q.js","assets/index-C1Mc0Svw.css","assets/plus-DvWl4lHk.js","assets/copy-J9XXv57X.js","assets/check-BAYRiedE.js","assets/DiagramEditor-NtNY3sZL-KWdKFFEL.js"])))=>i.map(i=>d[i]);
2
+ var x7=Object.defineProperty;var k7=(e,t,n)=>t in e?x7(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Mn=(e,t,n)=>k7(e,typeof t!="symbol"?t+"":t,n);import{B as eb,_ as Oe,r as E,af as w7,ag as v7,ah as S7,ai as Dn,aj as Xh,ak as Em,al as C7,j as O,b as Pi,am as _7,an as E7,ao as T7,ap as A7,z as M7,C as Jh,aq as N7,ar as D7,as as I7,at as L7}from"./react-vendor-BVS1XoFi.js";import{P as ze,e as Yh,A as ru,a as Ut,b as tb,w as de,c as fn,k as Cn,n as lt,F as Wr,p as Bi,$ as ce,O as Ln,G as pr,d as gs,l as gd,z as Sn,r as gt,v as nb,B as je,X as Fn,T as rb,M as Il,L as Ai,W as ml,f as hi,g as bs,h as So,C as Zh,Y as ib,y as Pt,i as Ll,H as Xe,j as F7,t as O7,m as Lo,J as bn,o as sb,R as fi,S as iu,Q as Zn,q as ob,s as z7,u as Aa,x as mt,E as R7,D as yc,I as P7,K as B7,_ as $7,N as su,U as bd,Z as ys,a0 as Co,a1 as Tt,a2 as ab,a3 as yn,a4 as j7,a5 as q7,a6 as Hr,a7 as Li,a8 as Fl,a9 as _n,aa as yd,ab as H7,ac as ub,ad as xd,ae as kd,af as _o,V as hn,ag as lb,ah as Qh,ai as U7,aj as cb,ak as W7,al as K7,am as V7,an as G7,ao as hb,ap as Qn,aq as X7,ar as jr,as as qn,at as xs,au as Tm,av as Am,aw as J7,ax as Y7,ay as Z7,az as Q7,aA as Ma,aB as fb,aC as db,aD as aa,aE as Na,aF as ou,aG as ek,aH as ef,aI as Mm,aJ as tk,aK as nk,aL as pb,aM as rk,aN as ik,aO as sk,aP as wd,aQ as Rr,aR as Eo,aS as vd,aT as ma,aU as fs,aV as Da,aW as tf,aX as Nm,aY as ga,aZ as gl,a_ as Ol,a$ as ok,b0 as ak,b1 as uk,b2 as lk,b3 as ck,b4 as Pr,b5 as hk,b6 as fk,b7 as dk,b8 as Dm,b9 as bl,ba as Im,bb as pk,bc as mk,bd as gk,be as bk,bf as ks,bg as Lm,bh as nf,bi as yk,bj as xk,bk as kk,bl as wk,bm as Fm,bn as ii,bo as Ia,bp as rf,bq as vk,br as ua,bs as mb,bt as gb,bu as bb,bv as yb,bw as xb,bx as Sk,by as Ck,bz as Sd,bA as kb,bB as _k,bC as Ek,bD as Cd,bE as Tk,bF as sf,bG as wb,bH as vb,bI as Ak,bJ as Mk,bK as Ju,bL as Sb,bM as Nk,bN as Dk,bO as Ik,bP as Cb,bQ as Lk,bR as Fk,bS as _b,bT as zl,bU as Ok,bV as zk,bW as Rk}from"./editor-DBWWidi3.js";import{as as tt,at,au as Pk,av as La,aw as Bk,ax as Rl,ay as $k,az as wi,aA as Zo,aB as jk,aC as qk,aD as Hk,aE as Uk,aF as Wk,aG as Kk,aH as Vk,aI as Gk,ad as _d,aJ as Xk,aK as It,ac as qr,aL as of,aM as Fa,aN as Ue,aO as Pl,aP as Eb,aQ as Jk,aR as zn,aS as Yk,aT as Zk,aU as Qk,aV as au,aW as Ed,aX as af,aY as Bl,aZ as Tb,a_ as ew,a$ as Om,b0 as tw,b1 as nw,t as uf,b2 as Ab,b3 as rw,b4 as iw,b5 as Mb,b6 as Nb,b7 as sw}from"./ui-CEFkTVnG.js";import{i as B0,j as ow,k as aw,l as uw,n as zm,e as Qo,s as lw,y as cw,h as Rm,m as Pm,r as hw,u as fw,v as dw,o as pw,w as mw,x as Db}from"./diagram-BF8g9yg4.js";import{o as xn,be as gw,aZ as Td,aK as bw}from"./index-Btfv_3-Q.js";import{P as Bm}from"./plus-DvWl4lHk.js";import{a as yw,C as xw}from"./copy-J9XXv57X.js";import{C as kw}from"./check-BAYRiedE.js";/**
3
3
  * @license lucide-react v0.562.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -1729,7 +1729,7 @@ ${this.__markdown}
1729
1729
  ## 分支 2`,style:{border:"none",flex:1,fontFamily:"monospace",fontSize:14,lineHeight:1.6,outline:"none",padding:16,resize:"none"},value:r})]}),O.jsx("div",{style:{display:"flex",flexDirection:"column",width:"50%"},children:O.jsx(Wx,{markdown:r})})]})]})}function Oq({className:e,editor:t,node:n}){const[r,i]=E.useState(!1),s=n.__markdown;E.useLayoutEffect(()=>{const u=n.getKey();let l=!1;t.getEditorState().read(()=>{const h=ze(u);h&&j4(h)&&h.__autoOpenEditor&&(l=!0)}),l&&(i(!0),t.update(()=>{const h=ze(u);h&&j4(h)&&h.__autoOpenEditor&&h.clearAutoOpenEditor()}))},[t,n.getKey()]);const o=E.useCallback(()=>{t.update(()=>{const u=n.getLatest(),l=u.getNextSibling(),h=u.getPreviousSibling();if(u.remove(),l){l.selectStart();return}h&&h.selectEnd()})},[t,n]),a=E.useCallback(u=>{t.update(()=>{n.updateMarkdown(u)}),i(!1)},[t,n]);return r?O.jsx("div",{className:e,children:O.jsx(Fq,{markdown:s,onClose:()=>i(!1),onSave:a})}):O.jsxs("div",{className:e,style:{margin:"8px 0",position:"relative"},children:[O.jsxs("div",{style:{bottom:8,display:"flex",gap:4,position:"absolute",right:8,zIndex:10},children:[O.jsx("button",{onClick:()=>i(!0),style:{background:"rgba(0,0,0,0.5)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:12,padding:"4px 8px"},type:"button",children:"编辑"}),O.jsx("button",{onClick:o,style:{background:"rgba(255,77,79,0.7)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:12,padding:"4px 8px"},type:"button",children:"删除"})]}),O.jsx("div",{style:{border:"1px solid #f0f0f0",borderRadius:8,height:350},children:O.jsx(Wx,{markdown:s})})]})}function yU({className:e,theme:t}){const[n]=_t(),r=E.useCallback((s,o)=>O.jsx(Oq,{className:e,editor:o,node:s}),[e]),i=E.useRef(!1);return i.current||(i.current=!0,n.registerPlugin(Lq,{decorator:r,theme:t})),null}const zq=lt("INSERT_MATH_COMMAND"),Kx=lt("UPDATE_MATH_COMMAND"),Nl=lt("SELECT_MATH_SIDE_COMMAND");function Rq(e){return gt(e.registerCommand(zq,t=>{const{code:n}=t;return e.update(()=>{const r=cu(n);_n([r]),qn(r.getParentOrThrow())&&xs(r,hn).selectEnd()}),!0},Fn),e.registerCommand(Kx,t=>{const{code:n,key:r}=t;return e.update(()=>{const i=ze(r);i&&(i.updateCode(n),i.selectNext())}),!0},Fn),e.registerCommand(Nl,t=>{const{key:n,prev:r}=t;return e.update(()=>{const i=ze(n);i&&(r?i.selectPrevious():i.selectNext())}),!0},Fn))}function Pq(e){const t=e.trim();return t?!!(/\\[A-Za-z]/.test(t)||/[\d!()*+,/<=>^_{|}-]/.test(t)||/^[A-Za-z]$/.test(t)):!1}rn();Bt();Ot();var wo;const Bq=(wo=class extends zt{constructor(t,n){super(),this.kernel=t,this.config=n,this.logger=Qe("plugin","math"),t.registerNodes([xa,Fi]),n!=null&&n.theme&&t.registerThemes(n==null?void 0:n.theme),this.registerDecorator(t,xa.getType(),(r,i)=>n!=null&&n.decorator?n.decorator(r,i):null),this.registerDecorator(t,Fi.getType(),(r,i)=>n!=null&&n.decorator?n.decorator(r,i):null)}onInit(t){this.register(Rq(t)),this.registerMarkdown()}registerMarkdown(){const t=this.kernel.requireService(Lt);t==null||t.registerMarkdownShortCut({regExp:/\$([^\s$](?:[^$]*[^\s$])?)\$\s?$/,replace:(n,r)=>{const[,i]=r;if(!Pq(i))return;const s=cu(i);this.logger.debug("Math node inserted:",s),n.insertBefore(s),n.setTextContent(""),n.select()},trigger:"$",type:"text-match"}),t==null||t.registerMarkdownShortCut({regExp:/^(\$\$)$/,replace:(n,r,i,s)=>{const o=wc();s||n.getNextSibling()?n.replace(o):n.insertBefore(o);const a=bn();a.add(o.getKey()),je(a)},trigger:"enter",type:"element"}),t==null||t.registerMarkdownWriter(xa.getType(),(n,r)=>(n.appendLine(r.getTextContent()),!0)),t==null||t.registerMarkdownWriter(Fi.getType(),(n,r)=>(n.appendLine(r.getTextContent()),!0)),t==null||t.registerMarkdownReader("inlineMath",n=>ke.createElementNode("math",{code:n.value,version:1})),t==null||t.registerMarkdownReader("math",n=>ke.createElementNode("mathBlock",{code:n.value,version:1}))}},wo.pluginName="MathPlugin",wo),Vx=E.memo(({children:e,isBlockMode:t,mathDOM:n,onFocus:r,prev:i})=>{const s=E.useRef(null),[o,a]=E.useState(void 0),u=E.useRef(void 0),l=E.useCallback(m=>{const y=typeof m=="number"?Math.round(m):void 0;u.current!==y&&(u.current=y,a(y))},[]),h=E.useCallback(()=>{if(!t){l(void 0);return}const m=n==null?void 0:n.closest('[contenteditable="true"]');m&&l(m.getBoundingClientRect().width)},[t,n,l]),d=E.useCallback(()=>Zc({callback:()=>{!s.current||!n||(r==null||r(),h())},floating:s.current,placement:t?"bottom-start":"bottom",reference:n}),[t,n,r,h]),g=E.useCallback(()=>{n&&d()},[n,d]);return E.useEffect(()=>{if(!n||!s.current)return;const m=s.current,y=new ResizeObserver(()=>{h()});y.observe(m);let w=null;return t&&(w=n.closest('[contenteditable="true"]'),w&&y.observe(w)),d(),window.addEventListener("resize",d),()=>{y.disconnect(),window.removeEventListener("resize",d)}},[n,i,t,d]),E.useEffect(()=>{n||!s.current||tu(s.current)},[n]),O.jsx(au,{arrow:!1,content:O.jsx(It,{className:zi.mathEditor,"data-math-editor-container":!0,style:o?{width:o}:void 0,children:e}),open:!!n,placement:t?"bottomLeft":"bottom",styles:{content:{borderRadius:"6px",padding:0}},children:O.jsx("span",{className:zi.mathEditorAnchor,onClick:g,ref:s})})});Vx.displayName="MathEditorContainer";Hb();const Gx=E.memo(({focusRef:e,mathNode:t,onArrowLeft:n,onArrowRight:r,onCancel:i,onDelete:s,onSubmit:o,onValidationChange:a,onValueChange:u,value:l})=>{const h=nr(),d=E.useRef(null),[g,m]=E.useState("");E.useEffect(()=>{e==null||e(d.current)},[e]),E.useEffect(()=>{if(!t)return;if(!l.trim()){m(""),a==null||a(!0);return}const w=setTimeout(()=>{try{tw(l,{displayMode:!0,throwOnError:!0}),m(""),a==null||a(!0)}catch(_){m(_ instanceof Error?_.message:"LaTeX Parse Error"),a==null||a(!1)}},50);return()=>clearTimeout(w)},[l,t,a]);const y=E.useCallback(w=>{if(t){if(ob(w,qb)&&w.key==="Enter"){w.preventDefault(),o();return}if(w.key==="Escape"){w.preventDefault(),i();return}if(w.key==="Backspace"&&!l.trim()){w.preventDefault(),s();return}w.key==="ArrowLeft"&&w.currentTarget.selectionStart===0&&(w.preventDefault(),n()),w.key==="ArrowRight"&&w.currentTarget.selectionStart===w.currentTarget.value.length&&(w.preventDefault(),r())}},[t,o,i,s,n,r,l]);return O.jsxs(O.Fragment,{children:[O.jsx(nw,{autoFocus:!0,autoSize:{maxRows:6,minRows:1},className:zi.mathEditorTextArea,onChange:w=>{u(w.target.value)},onKeyDown:y,placeholder:`${h("math.placeholder")}...`,ref:d,resize:!1,value:l,variant:"borderless"}),g&&O.jsx(It,{className:zi.mathEditorFooter,horizontal:!0,paddingBlock:4,paddingInline:12,width:"100%",children:O.jsx(qr,{fontSize:13,type:"danger",children:g})}),O.jsx(It,{className:zi.mathEditorFooter,horizontal:!0,justify:"flex-end",padding:4,width:"100%",children:O.jsxs(Pl,{onClick:w=>{w.preventDefault(),o()},size:"small",type:"text",variant:"filled",children:[h("confirm"),O.jsx(Eb,{compact:!0,keys:"mod+enter",variant:"borderless"})]})})]})});Gx.displayName="MathEditorContent";kr();const $q=E.memo(({renderComp:e})=>{const t=E.useRef(null),n=E.useRef(!1),[r,i]=E.useState(null),[s,o]=E.useState(""),a=E.useRef(""),u=E.useRef(!0),[l,h]=E.useState(null),[d,g]=E.useState(!1),[m,y]=E.useState(!1),[w,_]=E.useState(!1),[v]=_t();E.useEffect(()=>{if(!r||!u.current)return;const z=setTimeout(()=>{const V=v.getLexicalEditor();if(V&&!n.current){const X=r.code;if(s&&X&&X===s)return;n.current=!0,V.update(()=>{if(V.getEditorState().read(()=>V.getElementByKey(r.getKey()))){const ee=r.getWritable();ee.__code=s}}),setTimeout(()=>{n.current=!1},50)}},50);return()=>clearTimeout(z)},[s,r,v]);const M=E.useCallback(()=>{if(!r)return;const z=v.getLexicalEditor();if(z){const V=u.current?s:a.current;z.dispatchCommand(Kx,{code:V,key:r.getKey()})}},[v,r,s]),T=E.useCallback(()=>{if(!r)return;const z=v.getLexicalEditor();z&&(z.dispatchCommand(Nl,{key:r.getKey(),prev:!1}),z.focus())},[r,v]),D=E.useCallback(()=>{if(!r)return;const z=v.getLexicalEditor();z&&z.update(()=>{r.remove()})},[r,v]),R=E.useCallback(()=>{r&&v.dispatchCommand(Nl,{key:r.getKey(),prev:!0})},[r,v]),F=E.useCallback(()=>{r&&v.dispatchCommand(Nl,{key:r.getKey(),prev:!1})},[r,v]),j=E.useCallback(()=>{var z,V,X,ee;(z=t.current)==null||z.focus(),d&&((ee=(X=(V=t.current)==null?void 0:V.resizableTextArea)==null?void 0:X.textArea)==null||ee.setSelectionRange(0,0))},[d]),K=E.useCallback(z=>{t.current=z},[]);br(z=>gt(z.registerUpdateListener(({prevEditorState:V})=>{if(n.current)return;const X=z.getEditorState().read(()=>{const ee=ce();if(!Ln(ee))return!1;const Q=ee.getNodes()[0];if(!x3(Q))return!1;const ae=r&&r.getKey()===Q.getKey();return i(Q),!ae&&Q.code!==s&&(o(Q.code),a.current=Q.code,u.current=!0),h(z.getElementByKey(Q.getKey())),y(Q instanceof Fi),Q});if(X){const ee=V.read(()=>{const Q=V._selection;return de(Q)?Q.anchor.key:!1});z.getEditorState().read(()=>{const Q=ee?ze(ee):null;Q&&h9(Q,X)<0?g(!0):g(!1)}),_(!0)}X||(i(null),h(null),o(""),a.current="",u.current=!0,y(!1),_(!1))})),[r,s]);const U=O.jsx(Gx,{focusRef:K,mathNode:r,onArrowLeft:R,onArrowRight:F,onCancel:T,onDelete:D,onSubmit:M,onValidationChange:z=>{u.current=z,z&&(a.current=s)},onValueChange:o,value:s});return E.useEffect(()=>{if(!w)return;const z=V=>{const X=V.target;X&&(Array.from(document.querySelectorAll("[data-math-editor-container]")).some(ee=>ee&&ee.contains(X))||T())};return document.addEventListener("mousedown",z),document.addEventListener("touchstart",z),()=>{document.removeEventListener("mousedown",z),document.removeEventListener("touchstart",z)}},[w,T]),e?O.jsx(O.Fragment,{children:e({children:O.jsx("div",{"data-math-editor-container":!0,children:U}),open:w})}):O.jsx(Yc,{children:O.jsx(Vx,{isBlockMode:m,mathDOM:l,onFocus:j,prev:d,children:U})})}),jq=({mathBlock:e})=>{const t=nr(),n=O.jsx(qr,{as:"span",className:at("katex",zi.mathPlaceholder),fontSize:e?"1.2em":"1em",type:"secondary",children:t("math.placeholder")});return e?O.jsx(af,{padding:18,width:"100%",children:n}):n};Ot();const qq=Qe("plugin","math"),Hq=({editor:e,node:t,className:n})=>{const r=E.useRef(null),[i,s,o]=zo(t.getKey()),[a,u]=E.useState(!1),l=t instanceof Fi;return E.useEffect(()=>{r.current&&t.code&&Yk.render(t.code,r.current,{displayMode:t instanceof Fi,throwOnError:!1})},[t.code]),E.useEffect(()=>{const h=e.getElementByKey(t.getKey());if(h){const d=setTimeout(()=>{a?(Ut(h,"editing"),ua(h,"selected")):i?(Ut(h,"selected"),ua(h,"editing")):(ua(h,"selected"),ua(h,"editing"))},10);return()=>clearTimeout(d)}},[i,a,e,t]),br(h=>h.registerUpdateListener(()=>{h.getEditorState().read(()=>{const d=ce();if(!Ln(d)){u(!1);return}const g=d.getNodes()[0];if(!x3(g)){u(!1);return}g.getKey()===t.getKey()?u(!0):u(!1)})}),[t]),O.jsx("span",{className:n,onClick:E.useCallback(h=>{qq.debug("📊 Math click event:",h.target===r.current),h.preventDefault(),h.stopPropagation(),i&&o(),s(!0),e.focus()},[o,e,i,s]),ref:r,children:t.code?t.code:O.jsx(jq,{mathBlock:l})})},Uq=({className:e,renderComp:t,theme:n})=>{const[r]=_t();return E.useLayoutEffect(()=>{r.registerPlugin(Vi),r.registerPlugin(Bq,{decorator:(i,s)=>O.jsx(Hq,{className:e,editor:s,node:i}),theme:n||zi})},[r,e,n,zi]),O.jsx($q,{renderComp:t})};Uq.displayName="ReactMathPlugin";var Gs=class Dl extends Wr{static getType(){return"meta2d"}static clone(t){return new Dl(t.__diagram,t.__svg,t.__key,t.__autoOpenEditor)}static importJSON(t){return new Dl(t.diagram,t.svg)}constructor(t="",n="",r,i=!1){super(r),this.__diagram=t,this.__svg=n,this.__autoOpenEditor=i}clearAutoOpenEditor(){const t=this.getWritable();t.__autoOpenEditor=!1}createDOM(t){const n=document.createElement("div");return Ut(n,t.theme.meta2d??"editor-meta2d"),n}decorate(t){var r;const n=(r=Hi(t))==null?void 0:r.getDecorator(Dl.getType());return n?typeof n=="function"?n(this,t):{queryDOM:n.queryDOM,render:n.render(this,t)}:null}exportJSON(){return{...super.exportJSON(),diagram:this.__diagram,svg:this.__svg}}getTextContent(){return`---meta2d---
1730
1730
  ${this.__diagram}
1731
1731
  ---/meta2d---
1732
- `}isInline(){return!1}updateDiagram(t,n){const r=this.getWritable();r.__diagram=t,r.__svg=n}updateDOM(){return!1}};function Xx(e="",t="",n){return Cn(new Gs(e,t,void 0,(n==null?void 0:n.autoOpenEditor)??!1))}function H4(e){return e instanceof Gs}const Wq=lt("INSERT_META2D_COMMAND");function Kq(e){return e.registerCommand(Wq,t=>(e.update(()=>{var n;_n([Xx(((n=t==null?void 0:t.diagram)==null?void 0:n.trim())||Cl,(t==null?void 0:t.svg)!==void 0&&t.svg.trim()!==""?t.svg:nc,{autoOpenEditor:(t==null?void 0:t.autoOpenEditor)??!0})])}),!0),Tt)}rn();Bt();const Vq=/^---meta2d---$/i,Gq=/---meta2d---(\\n?)([\S\s]*?)\n?---\/meta2d---/i;function Xq(e){return(e.children||[]).map(t=>"value"in t&&typeof t.value=="string"?t.value:"").join("")}var vo;const Jq=(vo=class extends zt{constructor(t,n){super(),this.kernel=t,this.config=n,t.registerNodes([Gs]),n!=null&&n.theme&&t.registerThemes(n.theme),this.registerDecorator(t,Gs.getType(),(r,i)=>n!=null&&n.decorator?n.decorator(r,i):null)}onInit(t){this.register(Kq(t)),this.registerMarkdown()}registerMarkdown(){const t=this.kernel.requireService(Lt);t&&(t.registerMarkdownShortCut({regExp:Vq,replace:n=>{const r=Xx(Cl,nc,{autoOpenEditor:!0});n.replace(r);const i=bn();i.add(r.getKey()),je(i)},trigger:"enter",type:"element"}),t.registerMarkdownWriter(Gs.getType(),(n,r)=>{const i=r;return n.appendLine("---meta2d---"),n.appendLine(i.__diagram||Cl),n.appendLine("---/meta2d---"),!0}),t.registerMarkdownReader("paragraph",n=>{var s;const r=Xq(n).match(Gq);if(!r)return!1;const i=((s=r[2])==null?void 0:s.trim())||Cl;return ke.createTypeNode(Gs.getType(),{diagram:i,svg:yD(i)})},1))}},vo.pluginName="Meta2dPlugin",vo);let U4=null;function Yq(){return U4??(U4=Oe(()=>import("./meta2dEngine-BD2XbzaV-CNHknbe2.js"),__vite__mapDeps([23,24,25,26,27,28,29,30,31,32,33,34]))),U4}async function Zq(e){return(await Yq()).generateSvgFromDiagram(e)}function Qq(e){const t=e.trimStart();return t.startsWith("<svg")?t.replace(/^<svg\b/,'<svg style="max-width:100%;height:auto;display:block;margin:0 auto" '):e}function W4({color:e,label:t,onClick:n,title:r}){return O.jsx("button",{onClick:i=>{i.preventDefault(),i.stopPropagation(),n()},style:{alignItems:"center",background:"#fff",border:"1px solid #e5e5e5",borderRadius:6,color:e,cursor:"pointer",display:"inline-flex",height:28,justifyContent:"center",width:28},title:r,type:"button",children:t})}function eH({diagram:e,onDelete:t,onEdit:n,onSvgReady:r,svg:i}){const[s,o]=E.useState(!1),[a,u]=E.useState(null),[l,h]=E.useState(!1),[d,g]=E.useState(!1),m=E.useRef(null);return E.useEffect(()=>{u(null),g(!1)},[e]),E.useEffect(()=>{if(!e||d||s)return;if(i){m.current=e;return}let y=!0;const w=window.setTimeout(()=>{y&&(u("Preview timeout (still loading). Double-click to open editor."),g(!0),o(!1))},5e3);return o(!0),Zq(e).then(_=>{if(y){if(window.clearTimeout(w),_){m.current=e,r(_);return}u("Preview generation failed. Double-click to open editor."),g(!0)}}).finally(()=>{y&&o(!1)}),()=>{y=!1,window.clearTimeout(w)}},[e,d,r,i]),O.jsxs("div",{onDoubleClick:y=>{y.stopPropagation(),n()},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),style:{background:"#fff",border:"1px solid #efefef",borderRadius:10,cursor:"pointer",minHeight:140,overflow:"hidden",padding:10,position:"relative"},children:[l&&!!i&&O.jsxs("div",{style:{display:"flex",gap:8,position:"absolute",right:10,top:10,zIndex:1},children:[O.jsx(W4,{color:"#1677ff",label:"✎",onClick:n,title:"Edit diagram"}),O.jsx(W4,{color:"#ff4d4f",label:"🗑",onClick:t,title:"Delete diagram"})]}),i?O.jsx("div",{style:{alignItems:"center",display:"flex",justifyContent:"center",maxHeight:400,overflow:"auto",width:"100%"},children:O.jsx("div",{dangerouslySetInnerHTML:{__html:Qq(i)},style:{lineHeight:0,maxWidth:"100%",width:"100%"}})}):O.jsx("div",{style:{alignItems:"center",color:a?"#cf1322":"#999",display:"flex",justifyContent:"center",minHeight:120,textAlign:"center"},children:s?"Generating preview...":a||"Double-click to edit diagram"})]})}const tH=E.memo(eH),nH=E.lazy(async()=>({default:(await Oe(async()=>{const{DiagramEditor:e}=await import("./DiagramEditor-NtNY3sZL-DHC7qgkW.js");return{DiagramEditor:e}},__vite__mapDeps([35,25,23,24,26,27,28,29,30,31,32,33,34]))).DiagramEditor}));function rH({className:e,editor:t,node:n}){const[r,i]=E.useState(!1),s=n.__diagram,o=n.__svg;E.useLayoutEffect(()=>{const l=n.getKey();let h=!1;t.getEditorState().read(()=>{const d=ze(l);d&&H4(d)&&d.__autoOpenEditor&&(h=!0)}),h&&i(!0),h&&t.update(()=>{const d=ze(l);d&&H4(d)&&d.__autoOpenEditor&&d.clearAutoOpenEditor()})},[t,n.getKey()]);const a=E.useCallback(()=>{t.update(()=>{const l=n.getLatest(),h=l.getNextSibling(),d=l.getPreviousSibling();if(l.remove(),h){h.selectStart();return}d&&d.selectEnd()})},[t,n]),u=E.useCallback((l,h)=>{t.update(()=>{n.updateDiagram(l,h)}),i(!1)},[t,n]);return O.jsxs("div",{className:e,style:{margin:0},children:[O.jsx(tH,{diagram:s,onDelete:a,onEdit:()=>i(!0),onSvgReady:E.useCallback(l=>{t.update(()=>{n.updateDiagram(n.__diagram,l)})},[t,n]),svg:o}),r&&O.jsx(E.Suspense,{fallback:null,children:O.jsx(nH,{diagram:s,onClose:()=>i(!1),onSave:u})})]})}function xU({className:e,theme:t}){const[n]=_t(),r=E.useCallback((i,s)=>O.jsx(rH,{className:e,editor:s,node:i}),[e]);return E.useLayoutEffect(()=>{n.registerPlugin(Jq,{decorator:r,theme:t})},[r,n,t]),null}const Jx=E.createContext(null),iH=({children:e,defaultVisible:t=!0})=>{const[n,r]=E.useState(t),i=E.useCallback(()=>r(o=>!o),[]),s=E.useMemo(()=>({setVisible:r,toggle:i,visible:n}),[i,n]);return O.jsx(Jx.Provider,{value:s,children:e})};iH.displayName="OutlineProvider";function Y1(){return E.useContext(Jx)}function kU(){const e=Y1();if(!e)throw new Error("useOutlineVisibility must be used within <OutlineProvider>.");return e}function sH(e){const t=Y1(),n=(e==null?void 0:e.visible)!==void 0&&(e==null?void 0:e.onVisibleChange)!==void 0;return E.useMemo(()=>n&&(e!=null&&e.onVisibleChange)?{ready:!0,toggle:()=>e.onVisibleChange(!e.visible),visible:e.visible}:t?{ready:!0,toggle:t.toggle,visible:t.visible}:{ready:!1},[e==null?void 0:e.onVisibleChange,e==null?void 0:e.visible,t,n])}kr();const wU=({editor:e,visible:t})=>{const n=Y1(),r=E.useMemo(()=>t!==void 0?t:(n==null?void 0:n.visible)??!0,[t,n==null?void 0:n.visible]),[i,s]=E.useState([]),o=E.useCallback(()=>{const u=[],l=Sn(),h=d=>{for(const g of d){if(_o(g)){const m=g.getTextContent().trim();m&&u.push({key:g.getKey(),level:parseInt(g.getTag()[1],10),text:m})}if(fn(g)){const m=g.getChildren();m.length>0&&h(m)}}};h(l.getChildren()),s(u)},[]);E.useEffect(()=>{const u=e.getLexicalEditor();let l=Fo;const h=d=>(l=d.registerUpdateListener(({editorState:g})=>{g.read(o)}),d.getEditorState().read(o),l);return u?h(u):(e.on("initialized",h),()=>{l(),e.off("initialized",h)})},[e,o]);const a=E.useCallback(u=>{const l=e.getLexicalEditor();l&&(l.update(()=>{const h=bn();h.add(u),je(h)}),requestAnimationFrame(()=>{const h=l.getElementByKey(u);h&&h.scrollIntoView({behavior:"smooth",block:"center"})}))},[e]);return!r||i.length===0?null:O.jsxs("div",{style:{borderLeft:"1px solid rgba(0, 0, 0, 0.08)",paddingLeft:12},children:[O.jsx("div",{style:{color:"rgba(0,0,0,0.45)",fontSize:12,fontWeight:600,marginBottom:8},children:"OUTLINE"}),i.map(u=>O.jsx("div",{onClick:()=>a(u.key),onMouseEnter:l=>{l.currentTarget.style.background="rgba(0,0,0,0.04)"},onMouseLeave:l=>{l.currentTarget.style.background="transparent"},style:{borderRadius:4,color:"rgba(0,0,0,0.75)",cursor:"pointer",fontSize:13,lineHeight:"28px",overflow:"hidden",paddingLeft:(u.level-1)*16+8,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.text},u.key))]})},oH="Hide outline",aH="Show outline",uH="outline";function vU(e){const{collapseTitle:t=oH,expandTitle:n=aH,onVisibleChange:r,visible:i}=e??{},s=sH(i!==void 0&&r!==void 0?{onVisibleChange:r,visible:i}:void 0);return E.useMemo(()=>{if(!s.ready)return null;const{toggle:o,visible:a}=s;return{active:a,icon:a?zb:Fw,key:uH,label:a?t:n,onClick:o}},[t,n,s])}kr();function lH(e,t){const{domRows:n}=e;for(const[r,i]of n.entries())if(i)for(const[s,o]of i.entries()){if(!o)continue;const a=jr(o.elem);a!==null&&t(o,a,{x:s,y:r})}}function cH(e,t){const n=t.elem,r=e._config.theme;xc(hi(jr(n)),"Expected to find LexicalNode from Table Cell DOMNode"),Ut(n,r.tableCellSelected)}function hH(e,t){const n=t.elem;xc(hi(jr(n)),"Expected to find LexicalNode from Table Cell DOMNode");const r=e._config.theme;ua(n,r.tableCellSelected)}function fH(e,t,n){const r=new Set(n?n.getNodes():[]);lH(t,(i,s)=>{const o=i.elem;r.has(s)?(i.highlighted=!0,cH(e,i)):(i.highlighted=!1,hH(e,i),o.getAttribute("style")||o.removeAttribute("style"))})}function K4(e){const t=e.getShape();return{columns:t.toX-t.fromX+1,rows:t.toY-t.fromY+1}}function dH(){const e=ce();if(de(e)&&!e.isCollapsed()||fi(e)&&!e.anchor.is(e.focus)||!de(e)&&!fi(e))return!1;const[t]=Cb(e.anchor);return t.__colSpan>1||t.__rowSpan>1}function pH(e){const t=e.getLastDescendant();Pt(t)?t.select():fn(t)?t.selectEnd():t!==null&&t.selectNext()}function V4(e){return e.getEditorState().read(()=>{const t=ce();if(de(t)||fi(t)){const[n]=Cb(t.anchor);if(hi(n))return n.getBackgroundColor()}return null})}const Yx=E.memo(({editor:e,tableCellNode:t,cellMerge:n,children:r})=>{const[i,s]=E.useState(t),[o,a]=E.useState({columns:1,rows:1}),[u,l]=E.useState(!1),[h,d]=E.useState(!1),[,g]=E.useState(()=>V4(e)||""),m=nr();E.useEffect(()=>e.registerMutationListener(nf,K=>{K.get(i.getKey())==="updated"&&(e.getEditorState().read(()=>{s(i.getLatest())}),g(V4(e)||""))},{skipInitialization:!0}),[e,i]),E.useEffect(()=>{e.getEditorState().read(()=>{const K=ce();if(fi(K)){const U=K4(K);a(K4(K)),l(U.columns>1||U.rows>1)}d(dH())})},[e]);const y=E.useCallback(()=>{e.update(()=>{if(i.isAttached()){const K=ii(i),U=Ia(K,e.getElementByKey(K.getKey()));if(U===null)throw new Error("TableActionMenu: Expected to find tableElement in DOM");const z=rf(U);z!==null&&z.$clearHighlight(),K.markDirty(),s(i.getLatest())}je(null)})},[e,i]),w=()=>{e.update(()=>{const K=ce();if(!fi(K))return;const U=Lk(K.getNodes().filter(hi));U&&pH(U)})},_=()=>{e.update(()=>{Fk()})},v=E.useCallback(K=>{e.update(()=>{for(let U=0;U<o.rows;U++)wb(K)})},[e,o.rows]),M=E.useCallback(K=>{e.update(()=>{for(let U=0;U<o.columns;U++)vb(K)})},[e,o.columns]),T=E.useCallback(()=>{e.update(()=>{Ak()})},[e]),D=E.useCallback(()=>{e.update(()=>{ii(i).remove(),y()})},[e,i,y]),R=E.useCallback(()=>{e.update(()=>{Mk()})},[e]),F=E.useCallback(()=>{e.update(()=>{const K=ii(i),U=Cd(i),[z]=sf(K,null,null),V=new Set,X=i.getHeaderStyles()^Ju.ROW;for(let ee=0;ee<z[U].length;ee++){const Q=z[U][ee];Q!=null&&Q.cell&&(V.has(Q.cell)||(V.add(Q.cell),Q.cell.setHeaderStyles(X,Ju.ROW)))}y()})},[e,i,y]),j=E.useCallback(()=>{e.update(()=>{const K=ii(i),U=Sb(i),[z]=sf(K,null,null),V=new Set,X=i.getHeaderStyles()^Ju.COLUMN;for(const ee of z){const Q=ee[U];Q!=null&&Q.cell&&(V.has(Q.cell)||(V.add(Q.cell),Q.cell.setHeaderStyles(X,Ju.COLUMN)))}y()})},[e,i,y]);return O.jsx(Ed,{menu:{items:E.useMemo(()=>[{icon:Bw,key:"table-insert-row-above",label:m("table.insertRowAbove",{count:o.rows}),onClick:()=>v(!1)},{icon:zw,key:"table-insert-row-below",label:m("table.insertRowBelow",{count:o.rows}),onClick:()=>v(!0)},{type:"divider"},{icon:bw,key:"table-insert-column-before",label:m("table.insertColumnLeft",{count:o.columns}),onClick:()=>M(!1)},{icon:zb,key:"table-insert-column-after",label:m("table.insertColumnRight",{count:o.columns}),onClick:()=>M(!0)},{type:"divider"},{icon:Hw,key:"table-delete-columns",label:m("table.deleteColumn"),onClick:()=>R()},{icon:Ww,key:"table-delete-rows",label:m("table.deleteRow"),onClick:()=>T()},{type:"divider"},{icon:Dw,key:"table-delete",label:m("table.delete"),onClick:()=>D()}],[n,u,h,o.rows,o.columns,i.__headerState,w,_,v,M,R,T,D,F,j])},children:r})});Yx.displayName="TableActionMenu";const G4=tt(({css:e})=>({actionIcon:e`
1732
+ `}isInline(){return!1}updateDiagram(t,n){const r=this.getWritable();r.__diagram=t,r.__svg=n}updateDOM(){return!1}};function Xx(e="",t="",n){return Cn(new Gs(e,t,void 0,(n==null?void 0:n.autoOpenEditor)??!1))}function H4(e){return e instanceof Gs}const Wq=lt("INSERT_META2D_COMMAND");function Kq(e){return e.registerCommand(Wq,t=>(e.update(()=>{var n;_n([Xx(((n=t==null?void 0:t.diagram)==null?void 0:n.trim())||Cl,(t==null?void 0:t.svg)!==void 0&&t.svg.trim()!==""?t.svg:nc,{autoOpenEditor:(t==null?void 0:t.autoOpenEditor)??!0})])}),!0),Tt)}rn();Bt();const Vq=/^---meta2d---$/i,Gq=/---meta2d---(\\n?)([\S\s]*?)\n?---\/meta2d---/i;function Xq(e){return(e.children||[]).map(t=>"value"in t&&typeof t.value=="string"?t.value:"").join("")}var vo;const Jq=(vo=class extends zt{constructor(t,n){super(),this.kernel=t,this.config=n,t.registerNodes([Gs]),n!=null&&n.theme&&t.registerThemes(n.theme),this.registerDecorator(t,Gs.getType(),(r,i)=>n!=null&&n.decorator?n.decorator(r,i):null)}onInit(t){this.register(Kq(t)),this.registerMarkdown()}registerMarkdown(){const t=this.kernel.requireService(Lt);t&&(t.registerMarkdownShortCut({regExp:Vq,replace:n=>{const r=Xx(Cl,nc,{autoOpenEditor:!0});n.replace(r);const i=bn();i.add(r.getKey()),je(i)},trigger:"enter",type:"element"}),t.registerMarkdownWriter(Gs.getType(),(n,r)=>{const i=r;return n.appendLine("---meta2d---"),n.appendLine(i.__diagram||Cl),n.appendLine("---/meta2d---"),!0}),t.registerMarkdownReader("paragraph",n=>{var s;const r=Xq(n).match(Gq);if(!r)return!1;const i=((s=r[2])==null?void 0:s.trim())||Cl;return ke.createTypeNode(Gs.getType(),{diagram:i,svg:yD(i)})},1))}},vo.pluginName="Meta2dPlugin",vo);let U4=null;function Yq(){return U4??(U4=Oe(()=>import("./meta2dEngine-BD2XbzaV-MY1Hyyeh.js"),__vite__mapDeps([23,24,25,26,27,28,29,30,31,32,33,34]))),U4}async function Zq(e){return(await Yq()).generateSvgFromDiagram(e)}function Qq(e){const t=e.trimStart();return t.startsWith("<svg")?t.replace(/^<svg\b/,'<svg style="max-width:100%;height:auto;display:block;margin:0 auto" '):e}function W4({color:e,label:t,onClick:n,title:r}){return O.jsx("button",{onClick:i=>{i.preventDefault(),i.stopPropagation(),n()},style:{alignItems:"center",background:"#fff",border:"1px solid #e5e5e5",borderRadius:6,color:e,cursor:"pointer",display:"inline-flex",height:28,justifyContent:"center",width:28},title:r,type:"button",children:t})}function eH({diagram:e,onDelete:t,onEdit:n,onSvgReady:r,svg:i}){const[s,o]=E.useState(!1),[a,u]=E.useState(null),[l,h]=E.useState(!1),[d,g]=E.useState(!1),m=E.useRef(null);return E.useEffect(()=>{u(null),g(!1)},[e]),E.useEffect(()=>{if(!e||d||s)return;if(i){m.current=e;return}let y=!0;const w=window.setTimeout(()=>{y&&(u("Preview timeout (still loading). Double-click to open editor."),g(!0),o(!1))},5e3);return o(!0),Zq(e).then(_=>{if(y){if(window.clearTimeout(w),_){m.current=e,r(_);return}u("Preview generation failed. Double-click to open editor."),g(!0)}}).finally(()=>{y&&o(!1)}),()=>{y=!1,window.clearTimeout(w)}},[e,d,r,i]),O.jsxs("div",{onDoubleClick:y=>{y.stopPropagation(),n()},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),style:{background:"#fff",border:"1px solid #efefef",borderRadius:10,cursor:"pointer",minHeight:140,overflow:"hidden",padding:10,position:"relative"},children:[l&&!!i&&O.jsxs("div",{style:{display:"flex",gap:8,position:"absolute",right:10,top:10,zIndex:1},children:[O.jsx(W4,{color:"#1677ff",label:"✎",onClick:n,title:"Edit diagram"}),O.jsx(W4,{color:"#ff4d4f",label:"🗑",onClick:t,title:"Delete diagram"})]}),i?O.jsx("div",{style:{alignItems:"center",display:"flex",justifyContent:"center",maxHeight:400,overflow:"auto",width:"100%"},children:O.jsx("div",{dangerouslySetInnerHTML:{__html:Qq(i)},style:{lineHeight:0,maxWidth:"100%",width:"100%"}})}):O.jsx("div",{style:{alignItems:"center",color:a?"#cf1322":"#999",display:"flex",justifyContent:"center",minHeight:120,textAlign:"center"},children:s?"Generating preview...":a||"Double-click to edit diagram"})]})}const tH=E.memo(eH),nH=E.lazy(async()=>({default:(await Oe(async()=>{const{DiagramEditor:e}=await import("./DiagramEditor-NtNY3sZL-KWdKFFEL.js");return{DiagramEditor:e}},__vite__mapDeps([35,25,23,24,26,27,28,29,30,31,32,33,34]))).DiagramEditor}));function rH({className:e,editor:t,node:n}){const[r,i]=E.useState(!1),s=n.__diagram,o=n.__svg;E.useLayoutEffect(()=>{const l=n.getKey();let h=!1;t.getEditorState().read(()=>{const d=ze(l);d&&H4(d)&&d.__autoOpenEditor&&(h=!0)}),h&&i(!0),h&&t.update(()=>{const d=ze(l);d&&H4(d)&&d.__autoOpenEditor&&d.clearAutoOpenEditor()})},[t,n.getKey()]);const a=E.useCallback(()=>{t.update(()=>{const l=n.getLatest(),h=l.getNextSibling(),d=l.getPreviousSibling();if(l.remove(),h){h.selectStart();return}d&&d.selectEnd()})},[t,n]),u=E.useCallback((l,h)=>{t.update(()=>{n.updateDiagram(l,h)}),i(!1)},[t,n]);return O.jsxs("div",{className:e,style:{margin:0},children:[O.jsx(tH,{diagram:s,onDelete:a,onEdit:()=>i(!0),onSvgReady:E.useCallback(l=>{t.update(()=>{n.updateDiagram(n.__diagram,l)})},[t,n]),svg:o}),r&&O.jsx(E.Suspense,{fallback:null,children:O.jsx(nH,{diagram:s,onClose:()=>i(!1),onSave:u})})]})}function xU({className:e,theme:t}){const[n]=_t(),r=E.useCallback((i,s)=>O.jsx(rH,{className:e,editor:s,node:i}),[e]);return E.useLayoutEffect(()=>{n.registerPlugin(Jq,{decorator:r,theme:t})},[r,n,t]),null}const Jx=E.createContext(null),iH=({children:e,defaultVisible:t=!0})=>{const[n,r]=E.useState(t),i=E.useCallback(()=>r(o=>!o),[]),s=E.useMemo(()=>({setVisible:r,toggle:i,visible:n}),[i,n]);return O.jsx(Jx.Provider,{value:s,children:e})};iH.displayName="OutlineProvider";function Y1(){return E.useContext(Jx)}function kU(){const e=Y1();if(!e)throw new Error("useOutlineVisibility must be used within <OutlineProvider>.");return e}function sH(e){const t=Y1(),n=(e==null?void 0:e.visible)!==void 0&&(e==null?void 0:e.onVisibleChange)!==void 0;return E.useMemo(()=>n&&(e!=null&&e.onVisibleChange)?{ready:!0,toggle:()=>e.onVisibleChange(!e.visible),visible:e.visible}:t?{ready:!0,toggle:t.toggle,visible:t.visible}:{ready:!1},[e==null?void 0:e.onVisibleChange,e==null?void 0:e.visible,t,n])}kr();const wU=({editor:e,visible:t})=>{const n=Y1(),r=E.useMemo(()=>t!==void 0?t:(n==null?void 0:n.visible)??!0,[t,n==null?void 0:n.visible]),[i,s]=E.useState([]),o=E.useCallback(()=>{const u=[],l=Sn(),h=d=>{for(const g of d){if(_o(g)){const m=g.getTextContent().trim();m&&u.push({key:g.getKey(),level:parseInt(g.getTag()[1],10),text:m})}if(fn(g)){const m=g.getChildren();m.length>0&&h(m)}}};h(l.getChildren()),s(u)},[]);E.useEffect(()=>{const u=e.getLexicalEditor();let l=Fo;const h=d=>(l=d.registerUpdateListener(({editorState:g})=>{g.read(o)}),d.getEditorState().read(o),l);return u?h(u):(e.on("initialized",h),()=>{l(),e.off("initialized",h)})},[e,o]);const a=E.useCallback(u=>{const l=e.getLexicalEditor();l&&(l.update(()=>{const h=bn();h.add(u),je(h)}),requestAnimationFrame(()=>{const h=l.getElementByKey(u);h&&h.scrollIntoView({behavior:"smooth",block:"center"})}))},[e]);return!r||i.length===0?null:O.jsxs("div",{style:{borderLeft:"1px solid rgba(0, 0, 0, 0.08)",paddingLeft:12},children:[O.jsx("div",{style:{color:"rgba(0,0,0,0.45)",fontSize:12,fontWeight:600,marginBottom:8},children:"OUTLINE"}),i.map(u=>O.jsx("div",{onClick:()=>a(u.key),onMouseEnter:l=>{l.currentTarget.style.background="rgba(0,0,0,0.04)"},onMouseLeave:l=>{l.currentTarget.style.background="transparent"},style:{borderRadius:4,color:"rgba(0,0,0,0.75)",cursor:"pointer",fontSize:13,lineHeight:"28px",overflow:"hidden",paddingLeft:(u.level-1)*16+8,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.text},u.key))]})},oH="Hide outline",aH="Show outline",uH="outline";function vU(e){const{collapseTitle:t=oH,expandTitle:n=aH,onVisibleChange:r,visible:i}=e??{},s=sH(i!==void 0&&r!==void 0?{onVisibleChange:r,visible:i}:void 0);return E.useMemo(()=>{if(!s.ready)return null;const{toggle:o,visible:a}=s;return{active:a,icon:a?zb:Fw,key:uH,label:a?t:n,onClick:o}},[t,n,s])}kr();function lH(e,t){const{domRows:n}=e;for(const[r,i]of n.entries())if(i)for(const[s,o]of i.entries()){if(!o)continue;const a=jr(o.elem);a!==null&&t(o,a,{x:s,y:r})}}function cH(e,t){const n=t.elem,r=e._config.theme;xc(hi(jr(n)),"Expected to find LexicalNode from Table Cell DOMNode"),Ut(n,r.tableCellSelected)}function hH(e,t){const n=t.elem;xc(hi(jr(n)),"Expected to find LexicalNode from Table Cell DOMNode");const r=e._config.theme;ua(n,r.tableCellSelected)}function fH(e,t,n){const r=new Set(n?n.getNodes():[]);lH(t,(i,s)=>{const o=i.elem;r.has(s)?(i.highlighted=!0,cH(e,i)):(i.highlighted=!1,hH(e,i),o.getAttribute("style")||o.removeAttribute("style"))})}function K4(e){const t=e.getShape();return{columns:t.toX-t.fromX+1,rows:t.toY-t.fromY+1}}function dH(){const e=ce();if(de(e)&&!e.isCollapsed()||fi(e)&&!e.anchor.is(e.focus)||!de(e)&&!fi(e))return!1;const[t]=Cb(e.anchor);return t.__colSpan>1||t.__rowSpan>1}function pH(e){const t=e.getLastDescendant();Pt(t)?t.select():fn(t)?t.selectEnd():t!==null&&t.selectNext()}function V4(e){return e.getEditorState().read(()=>{const t=ce();if(de(t)||fi(t)){const[n]=Cb(t.anchor);if(hi(n))return n.getBackgroundColor()}return null})}const Yx=E.memo(({editor:e,tableCellNode:t,cellMerge:n,children:r})=>{const[i,s]=E.useState(t),[o,a]=E.useState({columns:1,rows:1}),[u,l]=E.useState(!1),[h,d]=E.useState(!1),[,g]=E.useState(()=>V4(e)||""),m=nr();E.useEffect(()=>e.registerMutationListener(nf,K=>{K.get(i.getKey())==="updated"&&(e.getEditorState().read(()=>{s(i.getLatest())}),g(V4(e)||""))},{skipInitialization:!0}),[e,i]),E.useEffect(()=>{e.getEditorState().read(()=>{const K=ce();if(fi(K)){const U=K4(K);a(K4(K)),l(U.columns>1||U.rows>1)}d(dH())})},[e]);const y=E.useCallback(()=>{e.update(()=>{if(i.isAttached()){const K=ii(i),U=Ia(K,e.getElementByKey(K.getKey()));if(U===null)throw new Error("TableActionMenu: Expected to find tableElement in DOM");const z=rf(U);z!==null&&z.$clearHighlight(),K.markDirty(),s(i.getLatest())}je(null)})},[e,i]),w=()=>{e.update(()=>{const K=ce();if(!fi(K))return;const U=Lk(K.getNodes().filter(hi));U&&pH(U)})},_=()=>{e.update(()=>{Fk()})},v=E.useCallback(K=>{e.update(()=>{for(let U=0;U<o.rows;U++)wb(K)})},[e,o.rows]),M=E.useCallback(K=>{e.update(()=>{for(let U=0;U<o.columns;U++)vb(K)})},[e,o.columns]),T=E.useCallback(()=>{e.update(()=>{Ak()})},[e]),D=E.useCallback(()=>{e.update(()=>{ii(i).remove(),y()})},[e,i,y]),R=E.useCallback(()=>{e.update(()=>{Mk()})},[e]),F=E.useCallback(()=>{e.update(()=>{const K=ii(i),U=Cd(i),[z]=sf(K,null,null),V=new Set,X=i.getHeaderStyles()^Ju.ROW;for(let ee=0;ee<z[U].length;ee++){const Q=z[U][ee];Q!=null&&Q.cell&&(V.has(Q.cell)||(V.add(Q.cell),Q.cell.setHeaderStyles(X,Ju.ROW)))}y()})},[e,i,y]),j=E.useCallback(()=>{e.update(()=>{const K=ii(i),U=Sb(i),[z]=sf(K,null,null),V=new Set,X=i.getHeaderStyles()^Ju.COLUMN;for(const ee of z){const Q=ee[U];Q!=null&&Q.cell&&(V.has(Q.cell)||(V.add(Q.cell),Q.cell.setHeaderStyles(X,Ju.COLUMN)))}y()})},[e,i,y]);return O.jsx(Ed,{menu:{items:E.useMemo(()=>[{icon:Bw,key:"table-insert-row-above",label:m("table.insertRowAbove",{count:o.rows}),onClick:()=>v(!1)},{icon:zw,key:"table-insert-row-below",label:m("table.insertRowBelow",{count:o.rows}),onClick:()=>v(!0)},{type:"divider"},{icon:bw,key:"table-insert-column-before",label:m("table.insertColumnLeft",{count:o.columns}),onClick:()=>M(!1)},{icon:zb,key:"table-insert-column-after",label:m("table.insertColumnRight",{count:o.columns}),onClick:()=>M(!0)},{type:"divider"},{icon:Hw,key:"table-delete-columns",label:m("table.deleteColumn"),onClick:()=>R()},{icon:Ww,key:"table-delete-rows",label:m("table.deleteRow"),onClick:()=>T()},{type:"divider"},{icon:Dw,key:"table-delete",label:m("table.delete"),onClick:()=>D()}],[n,u,h,o.rows,o.columns,i.__headerState,w,_,v,M,R,T,D,F,j])},children:r})});Yx.displayName="TableActionMenu";const G4=tt(({css:e})=>({actionIcon:e`
1733
1733
  transform: translateX(2px);
1734
1734
  `,root:e`
1735
1735
  will-change: transform;
@@ -27,7 +27,7 @@
27
27
  opacity: 0.65;
28
28
  }
29
29
  </style>
30
- <script type="module" crossorigin src="/assets/index-DAhW-QRN.js"></script>
30
+ <script type="module" crossorigin src="/assets/index-Btfv_3-Q.js"></script>
31
31
  <link rel="modulepreload" crossorigin href="/assets/react-vendor-BVS1XoFi.js">
32
32
  <link rel="modulepreload" crossorigin href="/assets/motion-BAXVQJfN.js">
33
33
  <link rel="modulepreload" crossorigin href="/assets/ui-CEFkTVnG.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgbg/mdocs",
3
- "version": "1.3.31",
3
+ "version": "1.4.0",
4
4
  "description": "A Markdown knowledge base for small teams",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,42 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diagram-BF8g9yg4.js","assets/ui-CEFkTVnG.js","assets/react-vendor-BVS1XoFi.js","assets/motion-BAXVQJfN.js"])))=>i.map(i=>d[i]);
2
- import{r as i,j as e,_ as Yt,b as Vt}from"./react-vendor-BVS1XoFi.js";import{o as X,av as Zt,aR as Jt,aS as bt,aT as Qt,N as vt,C as es,aU as wt,X as be,aV as ht,aW as ts,aX as ie,Z as ft,aY as ss,aZ as gt,aF as ns,a_ as as,a$ as is,b0 as rs,b1 as os,b2 as St,b3 as ls,b4 as cs,b5 as ds,b6 as us,b7 as ms}from"./index-DAhW-QRN.js";import{C as Ct}from"./check-CuLfkkz7.js";import{C as At,a as It}from"./copy-CjAdouag.js";import{P as ps}from"./plus-DkLh2brQ.js";import{ar as hs,ah as fs}from"./ui-CEFkTVnG.js";import"./diagram-BF8g9yg4.js";import"./motion-BAXVQJfN.js";/**
3
- * @license lucide-react v0.562.0 - ISC
4
- *
5
- * This source code is licensed under the ISC license.
6
- * See the LICENSE file in the root directory of this source tree.
7
- */const gs=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],xs=X("arrow-down",gs);/**
8
- * @license lucide-react v0.562.0 - ISC
9
- *
10
- * This source code is licensed under the ISC license.
11
- * See the LICENSE file in the root directory of this source tree.
12
- */const ys=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],js=X("history",ys);/**
13
- * @license lucide-react v0.562.0 - ISC
14
- *
15
- * This source code is licensed under the ISC license.
16
- * See the LICENSE file in the root directory of this source tree.
17
- */const ks=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],Ns=X("maximize-2",ks);/**
18
- * @license lucide-react v0.562.0 - ISC
19
- *
20
- * This source code is licensed under the ISC license.
21
- * See the LICENSE file in the root directory of this source tree.
22
- */const bs=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],vs=X("minimize-2",bs);/**
23
- * @license lucide-react v0.562.0 - ISC
24
- *
25
- * This source code is licensed under the ISC license.
26
- * See the LICENSE file in the root directory of this source tree.
27
- */const ws=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],Ss=X("pencil",ws);/**
28
- * @license lucide-react v0.562.0 - ISC
29
- *
30
- * This source code is licensed under the ISC license.
31
- * See the LICENSE file in the root directory of this source tree.
32
- */const Cs=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]],As=X("pin",Cs);/**
33
- * @license lucide-react v0.562.0 - ISC
34
- *
35
- * This source code is licensed under the ISC license.
36
- * See the LICENSE file in the root directory of this source tree.
37
- */const Is=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],_s=X("zoom-in",Is);/**
38
- * @license lucide-react v0.562.0 - ISC
39
- *
40
- * This source code is licensed under the ISC license.
41
- * See the LICENSE file in the root directory of this source tree.
42
- */const Ms=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Es=X("zoom-out",Ms),ze=5;function Rs(n){const s=i.useRef(!0),r=i.useRef(null),[o,h]=i.useState([]),[x,C]=i.useState(!1),[k,_]=i.useState(null);i.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),i.useEffect(()=>{(async()=>{try{const p=await Zt();if(!s.current)return;h(p)}catch(p){if(!s.current)return;_(p instanceof Error?p.message:String(p))}})()},[]),i.useEffect(()=>{if(!x)return;function p(g){const A=r.current;!A||A.contains(g.target)||C(!1)}function l(g){g.key==="Escape"&&C(!1)}return document.addEventListener("mousedown",p),document.addEventListener("keydown",l),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",l)}},[x]);const f=o.filter(p=>n.selectedNames.includes(p.name));function M(p){if(n.disabled)return;const l=new Set(n.selectedNames);if(l.has(p))l.delete(p);else{if(l.size>=ze)return;l.add(p)}n.onChange([...l])}return o.length===0&&!k?null:e.jsxs("div",{className:"mdocs-agent-skill-ref",ref:r,children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-bar",children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-anchor",children:[x&&o.length>0?e.jsxs("div",{className:"mdocs-agent-skill-popover",role:"listbox","aria-label":"选择 Skill",children:[e.jsxs("div",{className:"mdocs-agent-skill-popover-hint",children:["选择要引用的 Skill(最多 ",ze," 个)"]}),e.jsx("ul",{className:"mdocs-agent-skill-popover-list",children:o.map(p=>{const l=n.selectedNames.includes(p.name),g=!l&&n.selectedNames.length>=ze;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:n.disabled||g,onClick:()=>M(p.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:p.name}),p.description?e.jsx("span",{className:"mdocs-agent-skill-popover-desc",children:p.description}):e.jsx("span",{className:"mdocs-agent-skill-popover-desc mdocs-agent-skill-popover-desc-muted",children:"无简介"})]})]})},p.id)})})]}):null,e.jsxs("button",{type:"button",className:"mdocs-agent-skill-ref-toggle"+(x?" mdocs-agent-skill-ref-toggle-open":""),disabled:n.disabled||o.length===0,onClick:()=>C(p=>!p),"aria-expanded":x,"aria-haspopup":"listbox",title:"引用 Skill",children:["Skill",f.length>0?` · ${f.length}`:""]})]}),f.map(p=>e.jsxs("button",{type:"button",className:"mdocs-agent-skill-chip mdocs-agent-skill-chip-on",disabled:n.disabled,onClick:()=>M(p.name),title:"移除引用",children:[p.name,e.jsx("span",{"aria-hidden":!0,children:" ×"})]},p.name))]}),k?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:k}):null]})}const Ds=/^[A-Za-z0-9_]+$/;function $s(n){const{block:s,onResolved:r}=n,[o,h]=i.useState(s.initialName),[x,C]=i.useState(s.initialDescription),[k,_]=i.useState(s.initialBody),[f,M]=i.useState(!1),[p,l]=i.useState(null),[g,A]=i.useState(1),$=i.useRef(!1),v=i.useRef(r);v.current=r;const S=s.status==="open",F=i.useRef(0);i.useEffect(()=>{if(!S)return;$.current=!1;const R=new Date(s.expiresAt).getTime(),ve=Date.now(),re=Math.max(R-ve,1);F.current=re,A(1);const Z=()=>{const ee=R-Date.now(),P=Math.max(0,Math.min(1,ee/re));A(P),ee<=0&&!$.current&&($.current=!0,Jt(s.requestId).catch(()=>{}).finally(()=>{v.current(s.requestId,"expired")}))};Z();const oe=window.setInterval(Z,100);return()=>window.clearInterval(oe)},[S,s.expiresAt,s.requestId]);async function T(){if(f||!S)return;const R=o.trim();if(!R){l("名称不能为空");return}if(!Ds.test(R)){l("名称仅允许英文、数字、下划线");return}if(!k.trim()){l("正文不能为空");return}M(!0),l(null);try{await Qt(s.requestId,{name:R,description:x.trim(),body:k}),r(s.requestId,"submitted",R)}catch{r(s.requestId,"failed")}finally{M(!1)}}async function W(){if(!(f||!S)){M(!0),l(null),$.current=!0;try{await bt(s.requestId),r(s.requestId,"cancelled")}catch{r(s.requestId,"failed")}finally{M(!1)}}}const z=Math.max(0,Math.ceil(g*F.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card mdocs-agent-skill-form-card"+(S?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),S?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[z,"s"]}):null]}),S?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(g*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${g})`}})}):null,s.status==="submitted"?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已提交",s.submittedName?`:${s.submittedName}`:""]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,表单已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,S?e.jsxs("div",{className:"mdocs-agent-skill-form-fields",children:[e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"名称(英文数字下划线)"}),e.jsx("input",{type:"text",value:o,onChange:R=>h(R.target.value),maxLength:64,disabled:f,autoComplete:"off",spellCheck:!1})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"简介"}),e.jsx("input",{type:"text",value:x,onChange:R=>C(R.target.value),maxLength:200,disabled:f})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:k,onChange:R=>_(R.target.value),rows:8,disabled:f})]}),p?e.jsx("p",{className:"mdocs-agent-skill-form-error",children:p}):null,e.jsxs("div",{className:"mdocs-agent-skill-form-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-skill-form-cancel",disabled:f,onClick:()=>void W(),children:"取消"}),e.jsx("button",{type:"button",disabled:f,onClick:()=>void T(),children:f?"提交中…":s.mode==="create"?"创建":"保存"})]})]}):null]})}function Fe(n){var s;return n==null||typeof n=="boolean"?"":typeof n=="string"||typeof n=="number"?String(n):Array.isArray(n)?n.map(Fe).join(""):typeof n=="object"&&"props"in n?Fe((s=n.props)==null?void 0:s.children):""}function zs(n){return n?/\blanguage-mermaid\b|\bmermaid\b/i.test(n):!1}function Ts(n){const s=Array.isArray(n)?n:[n];for(const r of s){if(r==null||typeof r!="object"||!("props"in r))continue;const o=r.props;if(!(!o||!zs(o.className)))return Fe(o.children).replace(/\n$/,"")}return null}const qs=.4,Fs=4,Ne=.2;let Te=null;function Ls(){return Te||(Te=Yt(()=>import("./diagram-BF8g9yg4.js").then(n=>n.z),__vite__mapDeps([0,1,2,3])).then(n=>{const s=n.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral",fontFamily:"ui-sans-serif, system-ui, sans-serif"}),s})),Te}const Ps=32,V=new Map;function xt(n){return V.get(n)??null}function Bs(n,s){for(V.has(n)&&V.delete(n),V.set(n,s);V.size>Ps;){const r=V.keys().next().value;if(r==null)break;V.delete(r)}}function qe(n){return Math.min(Fs,Math.max(qs,n))}function Os(n){const[s,r]=i.useState(1),[o,h]=i.useState({x:0,y:0}),x=i.useRef(null),[C,k]=i.useState(!1);i.useEffect(()=>{const l=A=>{A.key==="Escape"&&n.onClose()};window.addEventListener("keydown",l);const g=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",l),document.body.style.overflow=g}},[n.onClose]);function _(l){l.button===0&&(l.currentTarget.setPointerCapture(l.pointerId),x.current={pointerId:l.pointerId,startX:l.clientX,startY:l.clientY,originX:o.x,originY:o.y},k(!0))}function f(l){const g=x.current;!g||g.pointerId!==l.pointerId||h({x:g.originX+(l.clientX-g.startX),y:g.originY+(l.clientY-g.startY)})}function M(l){const g=x.current;if(!(!g||g.pointerId!==l.pointerId)){x.current=null,k(!1);try{l.currentTarget.releasePointerCapture(l.pointerId)}catch{}}}function p(l){l.preventDefault();const g=l.deltaY>0?-Ne:Ne;r(A=>qe(Number((A+g).toFixed(2))))}return Vt.createPortal(e.jsxs("div",{className:"mdocs-agent-mermaid-float",role:"dialog","aria-modal":"true","aria-label":"Mermaid 图预览",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-backdrop","aria-label":"关闭预览",onClick:n.onClose}),e.jsxs("div",{className:"mdocs-agent-mermaid-float-chrome",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-float-tools",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>r(l=>qe(Number((l-Ne).toFixed(2)))),title:"缩小","aria-label":"缩小",children:e.jsx(Es,{size:16,"aria-hidden":!0})}),e.jsxs("span",{className:"mdocs-agent-mermaid-float-scale",children:[Math.round(s*100),"%"]}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>r(l=>qe(Number((l+Ne).toFixed(2)))),title:"放大","aria-label":"放大",children:e.jsx(_s,{size:16,"aria-hidden":!0})}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>{r(1),h({x:0,y:0})},title:"重置",children:"重置"}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:n.onClose,title:"关闭","aria-label":"关闭",children:e.jsx(be,{size:16,"aria-hidden":!0})})]}),e.jsx("div",{className:C?"mdocs-agent-mermaid-float-stage is-dragging":"mdocs-agent-mermaid-float-stage",onPointerDown:_,onPointerMove:f,onPointerUp:M,onPointerCancel:M,onWheel:p,children:e.jsx("div",{className:"mdocs-agent-mermaid-float-canvas",style:{transform:`translate(calc(-50% + ${o.x}px), calc(-50% + ${o.y}px)) scale(${s})`},dangerouslySetInnerHTML:{__html:n.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function Ws(n){const s=i.useId().replace(/:/g,""),[r,o]=i.useState("diagram"),[h,x]=i.useState(()=>xt(n.source.trim())),[C,k]=i.useState(null),[_,f]=i.useState(!1),[M,p]=i.useState(!1),l=i.useRef(null),g=n.source.trim(),A=i.useMemo(()=>g,[g]);i.useEffect(()=>()=>{l.current!=null&&window.clearTimeout(l.current)},[]),i.useEffect(()=>{if(r!=="diagram")return;if(!A){x(null),k(null);return}const v=xt(A);if(v){x(v),k(null);return}let S=!1;const F=window.setTimeout(()=>{(async()=>{try{const T=await Ls();if(S)return;const W=`mdocs-agent-mmd-${s}-${Date.now()}`,{svg:z}=await T.render(W,A);if(S)return;Bs(A,z),x(z),k(null)}catch(T){if(S)return;x(null),k(T instanceof Error?T.message:"Mermaid 渲染失败")}})()},200);return()=>{S=!0,window.clearTimeout(F)}},[r,A,s]);async function $(){!g||!await wt(g)||(f(!0),l.current!=null&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>f(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-mermaid",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toolbar",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toggle",role:"group","aria-label":"Mermaid 显示模式",children:[e.jsxs("button",{type:"button",className:r==="diagram"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>o("diagram"),"aria-pressed":r==="diagram",title:"图谱",children:[e.jsx(vt,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"图谱"})]}),e.jsxs("button",{type:"button",className:r==="code"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>o("code"),"aria-pressed":r==="code",title:"代码",children:[e.jsx(es,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"代码"})]})]}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy mdocs-agent-mermaid-copy",onClick:()=>void $(),"aria-label":_?"已复制":"复制代码",title:_?"已复制":"复制",children:_?e.jsx(Ct,{size:14,"aria-hidden":!0}):e.jsx(At,{size:14,"aria-hidden":!0})})]}),r==="diagram"?e.jsx("div",{className:"mdocs-agent-mermaid-diagram",children:C?e.jsxs("div",{className:"mdocs-agent-mermaid-error",role:"alert",children:[e.jsx("p",{children:"无法渲染该图,可切换到代码查看源码。"}),e.jsx("pre",{children:C})]}):h?e.jsx("div",{className:"mdocs-agent-mermaid-svg mdocs-agent-mermaid-svg-hit",role:"button",tabIndex:0,onClick:()=>p(!0),onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),p(!0))},title:"点击放大预览","aria-label":"点击放大预览 Mermaid 图",children:e.jsx("span",{className:"mdocs-agent-mermaid-svg-inner",dangerouslySetInnerHTML:{__html:h}})}):e.jsx("div",{className:"mdocs-agent-mermaid-loading",children:"渲染中…"})}):e.jsx("div",{className:"mdocs-agent-panel-md-pre-wrap mdocs-agent-mermaid-code",children:e.jsx("pre",{children:n.codeChildren??e.jsx("code",{className:"language-mermaid",children:g})})}),M&&h?e.jsx(Os,{svg:h,onClose:()=>p(!1)}):null]})}const Hs=i.memo(Ws,(n,s)=>n.source===s.source);function Ks(n){const[s,r]=i.useState(()=>Date.now());return i.useEffect(()=>{if(!n)return;const o=window.setInterval(()=>r(Date.now()),1e3);return()=>window.clearInterval(o)},[n]),s}function Us(n,s){if(!n.startedAt)return null;const r=n.endedAt??s;return Math.max(1,Math.round((r-n.startedAt)/1e3))}function Pe(n,s=Date.now()){let r=!1;const o=n.map(h=>h.type==="thinking"&&h.startedAt&&!h.endedAt?(r=!0,{...h,endedAt:s}):h);return r?o:n}function Xs(n){const{block:s,live:r,now:o}=n;if(!s.text)return null;const h=Us(s,o),x=h!=null?r?`思考中 ${h}s`:`思考 ${h}s`:"思考";return e.jsxs("details",{className:"mdocs-agent-panel-think-fold",children:[e.jsxs("summary",{children:[e.jsx("span",{className:"mdocs-agent-think-label"+(r?" live":""),children:x}),e.jsx(It,{size:14,strokeWidth:1.8,className:"mdocs-agent-think-chevron"})]}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:s.text})]})}function Le(n){var s;return n==null||typeof n=="boolean"?"":typeof n=="string"||typeof n=="number"?String(n):Array.isArray(n)?n.map(Le).join(""):typeof n=="object"&&"props"in n?Le((s=n.props)==null?void 0:s.children):""}function Gs(n){const[s,r]=i.useState(!1),o=i.useRef(null),h=i.useRef(null),x=Le(n.children).replace(/\n$/,"");i.useEffect(()=>()=>{o.current!=null&&window.clearTimeout(o.current)},[]);async function C(k){var p,l,g;k.preventDefault(),k.stopPropagation();const f=(((g=(l=(p=h.current)==null?void 0:p.querySelector("pre"))==null?void 0:l.innerText)==null?void 0:g.replace(/\n$/,""))??"")||x;!f||!await wt(f)||(r(!0),o.current!=null&&window.clearTimeout(o.current),o.current=window.setTimeout(()=>r(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-panel-md-pre-wrap",ref:h,children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy",onClick:k=>void C(k),"aria-label":s?"已复制":"复制代码",title:s?"已复制":"复制",children:s?e.jsx(Ct,{size:14,"aria-hidden":!0}):e.jsx(At,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:n.children})]})}function Ys(n){const s=Ts(n.children);return s!=null?e.jsx(Hs,{source:s,codeChildren:n.children}):e.jsx(Gs,{children:n.children})}const Vs={pre:({children:n})=>e.jsx(Ys,{children:n})},yt=i.memo(function(s){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(hs,{remarkPlugins:[fs],components:Vs,children:s.children})})}),Zs=["如何发布文档?","草稿是什么?","如何创建工作空间?"],Js=["润色当前文稿","补写开头引言","把这段改得更简洁"];function jt(n,s){return s.map((r,o)=>{const h=r.skillNames&&r.skillNames.length>0?r.skillNames:r.skillIds&&r.skillIds.length>0?r.skillIds:void 0;return{id:`h-${n}-${o}-${r.role}`,role:r.role,content:r.content,skillNames:h}})}function Qs(n,s){const r=Pe(n).slice(),o=r[r.length-1];return(o==null?void 0:o.type)==="text"?r[r.length-1]={type:"text",text:o.text+s}:r.push({type:"text",text:s}),r}function en(n,s){const r=Date.now(),o=n.slice(),h=o[o.length-1];return(h==null?void 0:h.type)==="thinking"&&!h.endedAt?o[o.length-1]={type:"thinking",text:h.text+s,startedAt:h.startedAt??r}:o.push({type:"thinking",text:s,startedAt:r}),o}function tn(n,s){const r=Pe(n).slice(),o=r.findIndex(h=>h.type==="tool_call"&&h.toolCallId===s.toolCallId);if(o>=0){const h=r[o];r[o]={...h,...s,detail:s.detail??h.detail}}else r.push(s);return r}function kt(n){return n!=null&&n.length?n.filter(s=>s.type==="text").map(s=>s.text).join(""):""}function sn(n){return!!(n!=null&&n.some(s=>s.type==="thinking"&&s.text.length>0))}function nn(n){const s=new Date(n);if(Number.isNaN(s.getTime()))return"";const r=new Date;return s.getFullYear()===r.getFullYear()&&s.getMonth()===r.getMonth()&&s.getDate()===r.getDate()?s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function Nt(n){if(n>=1e3){const s=n/1e3;return`${s>=10?Math.round(s):Math.round(s*10)/10}K`}return String(n)}function an(n){const{block:s,onResolved:r}=n,[o,h]=i.useState(""),[x,C]=i.useState(!1),[k,_]=i.useState(1),f=i.useRef(!1),M=i.useRef(r);M.current=r;const p=s.status==="open",l=i.useRef(0);i.useEffect(()=>{if(!p)return;f.current=!1;const v=new Date(s.expiresAt).getTime(),S=Date.now(),F=Math.max(v-S,1);l.current=F,_(1);const T=()=>{const z=v-Date.now(),R=Math.max(0,Math.min(1,z/F));_(R),z<=0&&!f.current&&(f.current=!0,us(s.requestId).catch(()=>{}).finally(()=>{M.current(s.requestId,"","expired")}))};T();const W=window.setInterval(T,100);return()=>window.clearInterval(W)},[p,s.expiresAt,s.requestId]);async function g(v){const S=v.trim();if(!(!S||x||!p)){C(!0);try{await ms(s.requestId,S),r(s.requestId,S,"selected")}catch{r(s.requestId,S,"failed")}finally{C(!1)}}}async function A(){if(!(x||!p)){C(!0),f.current=!0;try{await St(s.requestId),r(s.requestId,"","cancelled")}catch{r(s.requestId,"","failed")}finally{C(!1)}}}const $=Math.max(0,Math.ceil(k*l.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(p?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),p?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[$,"s"]}):null]}),p?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(k*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${k})`}})}):null,s.status==="selected"&&s.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",s.selected]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,p?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:s.options.map(v=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:x,onClick:()=>void g(v),children:v},v))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:o,disabled:x,placeholder:"或输入自己的内容…",onChange:v=>h(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),g(o))}}),e.jsx("button",{type:"button",disabled:x||!o.trim(),onClick:()=>void g(o),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:x,onClick:()=>void A(),children:"取消"})})]}):null]})}function rn(n){const h=2*Math.PI*8.75,x=Math.min(100,Math.max(0,n.percent)),C=h*(1-x/100),k=x>=90?"danger":x>=70?"warn":"ok",_=`上下文 ${x}% · 已用 ${Nt(n.used)} / ${Nt(n.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+k,"data-tooltip":_,"aria-label":_,role:"img",tabIndex:0,children:e.jsxs("svg",{width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,children:[e.jsx("circle",{className:"mdocs-agent-panel-context-track",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5}),e.jsx("circle",{className:"mdocs-agent-panel-context-value",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:h,strokeDashoffset:C,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function on(n){var s;for(const r of n)if(!(r.role!=="assistant"||!((s=r.blocks)!=null&&s.length))){for(const o of r.blocks)if((o.type==="choice_card"||o.type==="skill_form_card")&&o.status==="open")return!0}return!1}const gn=i.forwardRef(function(s,r){const{open:o,onClose:h,visitorName:x,anchorStyle:C,fullscreen:k,onToggleFullscreen:_,domainId:f,domains:M=[],localizeDomainName:p,documentId:l,documentTitle:g,documentPath:A,graphFileId:$,graphLabel:v,onOpenDocument:S,onTreeChanged:F,onDocumentOverwritten:T,onOpenCoding:W,embedded:z=!1,mode:R="normal",workingMarkdown:ve,baseMarkdown:re,onMarkdownSet:Z,onSendingChange:oe,onSessionId:ee}=s,P=R==="coding"?"coding":"normal",q=P==="coding",_t=((x==null?void 0:x.trim().charAt(0))||"我").toUpperCase(),[J,H]=i.useState(!1),[G,Be]=i.useState("current"),[Oe,Mt]=i.useState({}),[Et,te]=i.useState(null),[We,He]=i.useState(""),[b,le]=i.useState(null),[Rt,ce]=i.useState(null),[K,E]=i.useState([]),[se,de]=i.useState(null),[ue,Ke]=i.useState([]),[Dt,Ue]=i.useState(!1),[me,pe]=i.useState(""),[ne,Xe]=i.useState([]),[Ge,we]=i.useState(!1),[w,he]=i.useState(!1),[Ye,B]=i.useState(null),[fe,Ve]=i.useState(null),[Se,Y]=i.useState(!1),[U,Ze]=i.useState(!1),$t=i.useRef(null),ge=i.useRef(null),O=i.useRef(null),Je=i.useRef(0),Q=i.useRef(!0),[zt,Ce]=i.useState(!1),Tt=Ks(w),Ae=i.useRef(K);Ae.current=K;const Qe=!!(l!=null&&l.trim())&&!Ge,qt=(g==null?void 0:g.trim())||"当前文档",et=(A==null?void 0:A.trim())||"",Ie=!!($!=null&&$.trim())&&!Ge,Ft=(v==null?void 0:v.trim())||"当前图谱";i.useEffect(()=>{we(!1)},[l,$]);function tt(t){return Je.current+=1,`${t}-${Je.current}`}const st=120;function nt(t){return t.scrollHeight-t.scrollTop-t.clientHeight}function xe(){const t=ge.current;t&&(t.scrollTop=t.scrollHeight,Ce(!1))}function L(){Q.current&&xe()}function Lt(){const t=ge.current;if(!t)return;const u=nt(t);Q.current=u<=48,Ce(u>st)}function Pt(){Q.current=!0,xe()}i.useLayoutEffect(()=>{L();const t=ge.current;t&&Ce(nt(t)>st)},[K]);async function at(){Ue(!0);try{const t=await is(P,q?l:void 0);Ke(t.sessions),se||de(t.lastOpenedSessionId)}catch{}finally{Ue(!1)}}async function _e(){try{const t=await as();Ve(t)}catch{}}async function it(){try{const t=await ht();le(t),ce(null)}catch(t){le(null),ce(t instanceof Error?t.message:String(t))}}const ye=i.useRef(oe);ye.current=oe;const je=i.useRef(ee);je.current=ee,i.useEffect(()=>{var t;(t=ye.current)==null||t.call(ye,w)},[w]),i.useEffect(()=>{var t;(t=je.current)==null||t.call(je,se)},[se]),i.useEffect(()=>{var u;if(!o){H(!1),(u=O.current)==null||u.abort(),O.current=null,he(!1);return}let t=!1;return(async()=>{try{const a=await ht();t||(le(a),ce(null))}catch(a){t||(le(null),ce(a instanceof Error?a.message:String(a)))}})(),_e(),()=>{t=!0}},[o]);const ke=q?`coding:${l??""}`:"normal",rt=i.useRef(ke);i.useEffect(()=>{if(!o)return;const t=rt.current!==ke;rt.current=ke;let u=!1;return(async()=>{try{const a=await ts(P,q?l:void 0);if(u)return;de(a.sessionId),E(y=>!t&&y.length>0?y:jt(a.sessionId,a.messages))}catch{}})(),()=>{u=!0}},[o,ke]),i.useEffect(()=>{!o||!J||at()},[o,J]);function Me(){if(!U){if(on(Ae.current)){Y(!0);return}Y(!1),h()}}async function Bt(){var a;if(U)return;Ze(!0);const t=Ae.current,u=[];for(const y of t)if(!(y.role!=="assistant"||!y.blocks))for(const m of y.blocks)m.type==="choice_card"&&m.status==="open"&&u.push(St(m.requestId).catch(()=>{})),m.type==="skill_form_card"&&m.status==="open"&&u.push(bt(m.requestId).catch(()=>{}));await Promise.all(u),(a=O.current)==null||a.abort(),E(y=>y.map(m=>m.role!=="assistant"||!m.blocks?m:{...m,blocks:m.blocks.map(I=>I.type==="choice_card"&&I.status==="open"?{...I,status:"cancelled"}:I.type==="skill_form_card"&&I.status==="open"?{...I,status:"cancelled"}:I)})),Y(!1),Ze(!1),h()}const Ee=i.useRef(Me);Ee.current=Me,i.useImperativeHandle(r,()=>({requestClose:()=>Ee.current()}),[]),i.useEffect(()=>{if(!o){Y(!1);return}const t=u=>{if(u.key==="Escape"){if(Se){U||Y(!1);return}if(J){H(!1);return}Ee.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[o,J,Se,U]);async function Re(t){var I;const u=t.trim();if(!u||w)return;if(!(b!=null&&b.enabled)){B((b==null?void 0:b.reason)==="missing_api_key"?"请先配置 API Key":(b==null?void 0:b.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(I=O.current)==null||I.abort();const a=new AbortController;O.current=a;const y={id:tt("u"),role:"user",content:u,skillNames:ne.length>0?[...ne]:void 0},m=tt("a");Q.current=!0,E(D=>[...D,y,{id:m,role:"assistant",content:""}]),pe(""),he(!0),B(null),H(!1),requestAnimationFrame(()=>{xe(),requestAnimationFrame(xe)});try{let D=!1;await os(u,{mode:P,skillNames:ne.length>0?ne:void 0,...q?{documentId:l??null,workingMarkdown:ve,baseMarkdown:re}:{references:{domainId:(f==null?void 0:f.trim())||void 0,documentId:!Ie&&Qe?l.trim():void 0,graphFileId:Ie?$.trim():void 0}},signal:a.signal,onEvent:d=>{d.type==="text_delta"?(E(N=>N.map(c=>{if(c.id!==m)return c;const j=Qs(c.blocks??[],d.text);return{...c,blocks:j,content:kt(j)}})),requestAnimationFrame(()=>L())):d.type==="thinking_delta"?(E(N=>N.map(c=>{if(c.id!==m)return c;const j=en(c.blocks??[],d.text);return{...c,blocks:j}})),requestAnimationFrame(()=>L())):d.type==="sources"?(E(N=>N.map(c=>{if(c.id!==m)return c;const j=(c.blocks??[]).slice(),$e=j[j.length-1];return($e==null?void 0:$e.type)==="sources"?j[j.length-1]={type:"sources",items:d.items}:j.push({type:"sources",items:d.items}),{...c,blocks:j}})),requestAnimationFrame(()=>L())):d.type==="document_table"?(E(N=>N.map(c=>{if(c.id!==m)return c;const j=[...c.blocks??[],{type:"document_table",title:d.title,rows:d.rows}];return{...c,blocks:j}})),requestAnimationFrame(()=>L())):d.type==="document_card"?(E(N=>N.map(c=>{if(c.id!==m)return c;const j=[...c.blocks??[],{type:"document_card",documentId:d.documentId,title:d.title,path:d.path,preview:d.preview}];return{...c,blocks:j}})),requestAnimationFrame(()=>L())):d.type==="tool_notice"?(E(N=>N.map(c=>{if(c.id!==m)return c;const j=[...c.blocks??[],{type:"tool_notice",toolName:d.toolName,text:d.text}];return{...c,blocks:j}})),requestAnimationFrame(()=>L())):d.type==="tool_call"?(E(N=>N.map(c=>{if(c.id!==m)return c;const j=tn(c.blocks??[],{type:"tool_call",toolCallId:d.toolCallId,toolName:d.toolName,label:d.label,status:d.status,detail:d.detail});return{...c,blocks:j}})),requestAnimationFrame(()=>L())):d.type==="choice_card"?(E(N=>N.map(c=>{if(c.id!==m)return c;const j=[...c.blocks??[],{type:"choice_card",requestId:d.requestId,title:d.title,options:d.options,expiresAt:d.expiresAt,status:"open"}];return{...c,blocks:j}})),requestAnimationFrame(()=>L())):d.type==="choice_expired"?E(N=>N.map(c=>c.id!==m||!c.blocks?c:{...c,blocks:c.blocks.map(j=>j.type==="choice_card"&&j.requestId===d.requestId&&j.status==="open"?{...j,status:"expired"}:j)})):d.type==="skill_form_card"?(E(N=>N.map(c=>{if(c.id!==m)return c;const j=[...c.blocks??[],{type:"skill_form_card",requestId:d.requestId,mode:d.mode,title:d.title,currentName:d.currentName,initialName:d.initialName,initialDescription:d.initialDescription,initialBody:d.initialBody,expiresAt:d.expiresAt,status:"open"}];return{...c,blocks:j}})),requestAnimationFrame(()=>L())):d.type==="skill_form_expired"?E(N=>N.map(c=>c.id!==m||!c.blocks?c:{...c,blocks:c.blocks.map(j=>j.type==="skill_form_card"&&j.requestId===d.requestId&&j.status==="open"?{...j,status:"expired"}:j)})):d.type==="markdown_set"?Z==null||Z(d.markdown):d.type==="tree_changed"?F==null||F():d.type==="document_overwritten"?T==null||T({documentId:d.documentId,headCommitId:d.headCommitId}):d.type==="open_coding"?W==null||W({documentId:d.documentId,displayName:d.displayName}):d.type==="context_usage"?Ve({percent:d.percent,used:d.used,limit:d.limit}):d.type==="error"&&(D=!0,B(d.message))}}),!a.signal.aborted&&!D&&Xe([])}catch(D){if(a.signal.aborted)return;B(D instanceof Error?D.message:String(D))}finally{E(D=>D.map(d=>d.id===m&&d.blocks?{...d,blocks:Pe(d.blocks)}:d)),O.current===a&&(O.current=null),he(!1)}}async function Ot(){var t;if(!w){(t=O.current)==null||t.abort(),B(null),H(!1),he(!1);try{const u=await rs(P,q?l:void 0,f??null);de(u.sessionId),E([]),pe(""),Q.current=!0,_e(),at()}catch(u){B(u instanceof Error?u.message:String(u))}}}async function Wt(t){var u;if(!w){if(t===se){H(!1);return}(u=O.current)==null||u.abort(),B(null);try{const a=await ls(t,P,q?l:void 0);de(a.sessionId),E(jt(a.sessionId,a.messages)),pe(""),H(!1),te(null),Q.current=!0,requestAnimationFrame(()=>L()),_e()}catch(a){B(a instanceof Error?a.message:String(a))}}}function ot(t){Ke(u=>{const a=u.map(y=>y.id===t.id?{...y,...t}:y);return a.sort((y,m)=>{const I=y.pinned===!0,D=m.pinned===!0;return I!==D?I?-1:1:y.updatedAt<m.updatedAt?1:y.updatedAt>m.updatedAt?-1:0}),a})}async function Ht(t){if(!w)try{const u=await cs(t.id,t.pinned!==!0,P);ot(u)}catch(u){B(u instanceof Error?u.message:String(u))}}function Kt(t){te(t.id),He(t.title)}async function lt(t){const u=We.trim();if(te(null),!!u)try{const a=await ds(t,u,P);ot(a)}catch(a){B(a instanceof Error?a.message:String(a))}}const Ut=t=>{const u=M.find(a=>a.domainId===t);return u?p?p(u.domainName):u.domainName:t===ie?"default":t},ae=i.useMemo(()=>G==="all"||!f?ue:ue.filter(t=>(t.domainId||ie)===f),[ue,G,f]),ct=i.useMemo(()=>ae.filter(t=>t.pinned===!0),[ae]),Xt=i.useMemo(()=>{var a;const t=new Map;for(const y of ae){const m=((a=y.domainId)==null?void 0:a.trim())||ie,I=t.get(m);I?I.push(y):t.set(m,[y])}const u=(f==null?void 0:f.trim())||ie;return Array.from(t.entries()).map(([y,m])=>({id:y,items:m,label:Ut(y)})).sort((y,m)=>y.id===u?-1:m.id===u?1:y.label.localeCompare(m.label,"zh"))},[ae,M,p,f]);function dt(t){return Oe[t]!==void 0?!Oe[t]:G==="all"?t===((f==null?void 0:f.trim())||ie):!0}function Gt(t){Mt(u=>{const a=dt(t);return{...u,[t]:a}})}function ut(t){!t||!S||S(t)}function mt(t){const u=Et===t.id;return e.jsxs("div",{className:"mdocs-agent-panel-history-item"+(t.id===se?" active":""),children:[u?e.jsx("input",{className:"mdocs-agent-panel-history-rename",value:We,autoFocus:!0,maxLength:80,"aria-label":"重命名会话",onChange:a=>He(a.target.value),onClick:a=>a.stopPropagation(),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),lt(t.id)):a.key==="Escape"&&te(null)},onBlur:()=>void lt(t.id)}):e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-open",disabled:w,onClick:()=>void Wt(t.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:t.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:nn(t.updatedAt)})]}),e.jsxs("div",{className:"mdocs-agent-panel-history-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-action"+(t.pinned?" pinned":""),title:t.pinned?"取消置顶":"置顶","aria-label":t.pinned?"取消置顶":"置顶",disabled:w,onClick:a=>{a.stopPropagation(),Ht(t)},children:e.jsx(As,{size:14,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-action",title:"重命名","aria-label":"重命名",disabled:w||u,onClick:a=>{a.stopPropagation(),Kt(t)},children:e.jsx(Ss,{size:14,strokeWidth:1.8})})]})]})}if(!o)return null;const De=(b==null?void 0:b.reason)==="missing_api_key",pt=Rt??(b&&!b.enabled&&!De?b.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:$t,className:"mdocs-agent-panel"+(z?" mdocs-agent-panel--embedded":k?" mdocs-agent-panel--fullscreen":""),role:z?void 0:"dialog","aria-label":q?"mdocs 帮写助手":"mdocs 智能助手","aria-modal":z?void 0:k?!0:void 0,style:z||k?void 0:C,children:[e.jsxs("header",{className:"mdocs-agent-panel-header",children:[e.jsxs("div",{className:"mdocs-agent-panel-title",children:[e.jsx("img",{src:ft,alt:"",className:"mdocs-agent-panel-title-logo"}),e.jsx("span",{children:q?"mdocs 帮写助手":"mdocs 智能助手"})]}),e.jsxs("div",{className:"mdocs-agent-panel-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:w,onClick:()=>void Ot(),children:e.jsx(ps,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(J?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>H(t=>!t),children:e.jsx(js,{size:16,strokeWidth:1.8})}),z||!_?null:e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:k?"退出全屏":"全屏","aria-label":k?"退出全屏":"全屏",onClick:_,children:k?e.jsx(vs,{size:16,strokeWidth:1.8}):e.jsx(Ns,{size:16,strokeWidth:1.8})}),z?null:e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:Me,children:e.jsx(be,{size:16,strokeWidth:1.8})})]})]}),J?e.jsxs("div",{className:"mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>{H(!1),te(null)},children:"返回对话"})]}),e.jsxs("div",{className:"mdocs-agent-panel-history-filters",role:"tablist","aria-label":"按工作空间筛选",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":G==="current",className:"mdocs-agent-panel-history-filter"+(G==="current"?" active":""),onClick:()=>Be("current"),children:"当前工作空间"}),e.jsx("button",{type:"button",role:"tab","aria-selected":G==="all",className:"mdocs-agent-panel-history-filter"+(G==="all"?" active":""),onClick:()=>Be("all"),children:"全部"})]}),Dt?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):ue.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):ae.length===0?e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"此工作空间暂无会话"}):e.jsxs("div",{className:"mdocs-agent-panel-history-list",children:[ct.length>0?e.jsxs("section",{className:"mdocs-agent-panel-history-section",children:[e.jsx("div",{className:"mdocs-agent-panel-history-section-label",children:"Pinned"}),e.jsx("ul",{children:ct.map(t=>e.jsx("li",{children:mt(t)},t.id))})]}):null,Xt.map(t=>{const u=dt(t.id);return e.jsxs("section",{className:"mdocs-agent-panel-history-folder",children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-folder-head","aria-expanded":u,onClick:()=>Gt(t.id),children:[u?e.jsx(ss,{size:14,strokeWidth:1.8}):e.jsx(It,{size:14,strokeWidth:1.8}),e.jsx("span",{className:"mdocs-agent-panel-history-folder-name",children:t.label}),e.jsx("span",{className:"mdocs-agent-panel-history-folder-count",children:t.items.length})]}),u?e.jsx("ul",{children:t.items.map(a=>e.jsx("li",{children:mt(a)},a.id))}):null]},t.id)})]})]}):e.jsxs("div",{className:"mdocs-agent-panel-body",children:[e.jsxs("div",{className:"mdocs-agent-panel-scroll-wrap",children:[e.jsx("div",{className:"mdocs-agent-panel-welcome",ref:ge,onScroll:Lt,children:K.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-hello",children:q?"你好,我是 mdocs 帮写助手":"你好,我是 mdocs 智能助手"}),e.jsx("p",{className:"mdocs-agent-panel-desc",children:q?"这里专注改稿:你说怎么写,我更新右侧提案;按段接受或拒绝后,再点「完成并写回」。答疑、建目录、搜文档请用右下角「智能助手」。":"我能答疑、搜文档、整理结构,也能帮你写全文;需要按段精细改稿,请点文档顶栏「帮写」。"}),De?e.jsx(gt,{onConfigured:it}):pt?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:pt}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:(q?Js:Zs).map(t=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void Re(t),disabled:w||!(b!=null&&b.enabled),children:t},t))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:K.map(t=>{var u;return e.jsxs("div",{className:"mdocs-agent-panel-msg"+(t.role==="user"?" mdocs-agent-panel-msg-user":" mdocs-agent-panel-msg-assistant"),children:[t.role==="assistant"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-ai","aria-hidden":!0,children:e.jsx("img",{src:ft,alt:""})}):null,e.jsxs("div",{className:"mdocs-agent-panel-msg-bubble",children:[t.role==="user"&&t.skillNames&&t.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",t.skillNames.length]}):null,t.role==="assistant"?t.blocks&&t.blocks.length>0?e.jsxs("div",{className:"mdocs-agent-panel-timeline",children:[t.blocks.map((a,y)=>{if(a.type==="thinking")return e.jsx(Xs,{block:a,live:w&&!a.endedAt,now:Tt},`${t.id}-th-${y}`);if(a.type==="text")return a.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(yt,{children:a.text})},`${t.id}-t-${y}`):null;if(a.type==="sources")return 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(m=>e.jsx("li",{children:e.jsx("a",{href:m.url,target:"_blank",rel:"noreferrer",children:m.name})},m.id))})]})},`${t.id}-s-${y}`);if(a.type==="tool_call"){const m=a.status==="running"?"进行中":a.status==="error"?"失败":"完成";return e.jsxs("div",{className:`mdocs-agent-panel-block mdocs-agent-tool-call mdocs-agent-tool-call-${a.status}`,children:[e.jsxs("div",{className:"mdocs-agent-tool-call-head",children:[e.jsx("span",{className:"mdocs-agent-tool-call-status","aria-hidden":!0}),e.jsx("span",{className:"mdocs-agent-tool-call-label",children:a.label}),e.jsx("span",{className:"mdocs-agent-tool-call-badge",children:m})]}),a.detail?e.jsx("p",{className:"mdocs-agent-tool-call-detail",children:a.detail}):null]},`${t.id}-tc-${a.toolCallId}`)}return 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})},`${t.id}-n-${y}`):a.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(an,{block:a,onResolved:(m,I,D)=>{E(d=>d.map(N=>N.id!==t.id||!N.blocks?N:{...N,blocks:N.blocks.map(c=>c.type==="choice_card"&&c.requestId===m?{...c,status:D,selected:D==="selected"?I:c.selected}:c)}))}})},`${t.id}-ch-${y}`):a.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx($s,{block:a,onResolved:(m,I,D)=>{E(d=>d.map(N=>N.id!==t.id||!N.blocks?N:{...N,blocks:N.blocks.map(c=>c.type==="skill_form_card"&&c.requestId===m?{...c,status:I,submittedName:I==="submitted"?D:c.submittedName}:c)}))}})},`${t.id}-sf-${y}`):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:m=>{m.preventDefault(),m.stopPropagation(),ut(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:"(无正文预览)"})]})]})},`${t.id}-c-${y}`):e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[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(m=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>ut(m.documentId),children:m.title})}),e.jsx("td",{children:m.summary||"-"})]},m.documentId))})]})})]})},`${t.id}-d-${y}`)}),w&&t.id===((u=K[K.length-1])==null?void 0:u.id)&&!kt(t.blocks)&&!sn(t.blocks)?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null]}):t.content?e.jsx(yt,{children:t.content}):w?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null:t.content]}),t.role==="user"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-user","aria-hidden":!0,children:_t}):null]},t.id)})})}),zt?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:Pt,title:"回到底部","aria-label":"回到底部",children:[e.jsx(xs,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),Ye?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Ye}):null,De&&K.length>0?e.jsx(gt,{onConfigured:it}):null,e.jsx(Rs,{selectedNames:ne,onChange:Xe,disabled:w||!(b!=null&&b.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap",children:[q?null:Ie?e.jsxs("div",{className:"mdocs-agent-doc-ref mdocs-agent-graph-ref",children:[e.jsx(vt,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:Ft}),e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:"图谱(只读)"})]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前图谱",disabled:w,onClick:()=>we(!0),children:e.jsx(be,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):Qe?e.jsxs("div",{className:"mdocs-agent-doc-ref",children:[e.jsx(ns,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:qt}),et?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:et}):null]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前文档",disabled:w,onClick:()=>we(!0),children:e.jsx(be,{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:b!=null&&b.enabled?q?"说说要写什么…":"把你的问题告诉我…":"请先配置 API Key",value:me,disabled:w||!(b!=null&&b.enabled),onChange:t=>pe(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),Re(me))}}),fe?e.jsx(rn,{percent:fe.percent,used:fe.used,limit:fe.limit}):null,e.jsx("button",{type:"button",className:w?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:w?!1:!(b!=null&&b.enabled)||!me.trim(),onClick:()=>{var t;if(w){(t=O.current)==null||t.abort();return}Re(me)},title:w?"停止":"发送","aria-label":w?"停止":"发送",children:w?"■":"↑"})]})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),Se?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{U||Y(!1)},children:e.jsxs("div",{className:"mdocs-message-dialog mdocs-agent-close-confirm",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-agent-close-confirm-title",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{id:"mdocs-agent-close-confirm-title",className:"mdocs-message-dialog-title",children:"有待处理的倒计时"}),e.jsx("p",{className:"mdocs-message-dialog-body",children:"当前还有选择卡或 Skill 表单在倒计时。强制关闭会取消这些操作并退出助手;也可以继续等待完成后再关。"}),e.jsxs("div",{className:"mdocs-message-dialog-actions mdocs-agent-close-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",disabled:U,onClick:()=>Y(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:U,onClick:()=>void Bt(),children:U?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{gn as AgentChatPanel};