@fgbg/mdocs 1.3.15 → 1.3.16

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 (68) hide show
  1. package/README.md +6 -6
  2. package/agent-skills/changelog/SKILL.md +16 -1
  3. package/agent-skills/core-concepts-all-files/SKILL.md +3 -3
  4. package/agent-skills/core-concepts-domain/SKILL.md +49 -46
  5. package/agent-skills/core-concepts-invitation/SKILL.md +9 -9
  6. package/agent-skills/core-concepts-no-account/SKILL.md +1 -1
  7. package/agent-skills/deployment-requirements/SKILL.md +2 -2
  8. package/agent-skills/faq/SKILL.md +2 -2
  9. package/agent-skills/getting-started-first-kb/SKILL.md +2 -2
  10. package/agent-skills/getting-started-installation/SKILL.md +3 -3
  11. package/agent-skills/index/SKILL.md +2 -2
  12. package/agent-skills/index.json +8 -8
  13. package/agent-skills/usage-bookmarks/SKILL.md +5 -5
  14. package/agent-skills/usage-cli-token/SKILL.md +6 -6
  15. package/agent-skills/usage-comments/SKILL.md +1 -1
  16. package/agent-skills/usage-domain-members/SKILL.md +27 -27
  17. package/agent-skills/usage-html-documents/SKILL.md +1 -1
  18. package/agent-skills/usage-knowledge-graph/SKILL.md +5 -5
  19. package/agent-skills/usage-my-documents/SKILL.md +8 -8
  20. package/agent-skills/usage-onboarding-ai/SKILL.md +6 -6
  21. package/agent-skills/usage-search/SKILL.md +2 -2
  22. package/agent-skills/usage-settings/SKILL.md +8 -8
  23. package/dist/server/agent/Agent/system-prompt.js +3 -3
  24. package/dist/server/agent/Agent/system-prompt.js.map +1 -1
  25. package/dist/server/agent/Agent/tool-ui-effects.js +1 -1
  26. package/dist/server/agent/Agent/tools-documents.js +12 -12
  27. package/dist/server/agent/Agent/tools-documents.js.map +1 -1
  28. package/dist/server/agent/Agent/tools-domains.js +14 -14
  29. package/dist/server/agent/Agent/tools-domains.js.map +1 -1
  30. package/dist/server/agent/Agent/tools-visitors.js +1 -1
  31. package/dist/server/agent/Agent/tools-visitors.js.map +1 -1
  32. package/dist/server/documents/document.service.js +6 -6
  33. package/dist/server/documents/document.service.js.map +1 -1
  34. package/dist/server/documents/graph-task.js +1 -1
  35. package/dist/server/documents/graph-task.js.map +1 -1
  36. package/dist/server/documents/graph.service.js +1 -1
  37. package/dist/server/documents/graph.service.js.map +1 -1
  38. package/dist/server/domains/change-domain-permission.js +1 -1
  39. package/dist/server/domains/change-domain-permission.js.map +1 -1
  40. package/dist/server/routes/folders.routes.js +4 -4
  41. package/dist/server/routes/folders.routes.js.map +1 -1
  42. package/dist/web/assets/AgentChatPanel-Bsx3DwQ7.js +22 -0
  43. package/dist/web/assets/{AgentSkillFormCard-llRkQdK_.js → AgentSkillFormCard-TFpdC5LM.js} +3 -3
  44. package/dist/web/assets/AiWriteWorkbench-Jl0I9eM9.js +7 -0
  45. package/dist/web/assets/{DiagramEditor-NtNY3sZL-D0FE-I9-.js → DiagramEditor-NtNY3sZL-CAEe_iNQ.js} +1 -1
  46. package/dist/web/assets/DocChrome-BWMgRxlr.js +21 -0
  47. package/dist/web/assets/DocumentEditor-DALklXO2.js +1 -0
  48. package/dist/web/assets/HtmlEditor-CX0e0ifD.js +1 -0
  49. package/dist/web/assets/{MergeView-DsVxYKKc.js → MergeView-DNu_ac5f.js} +2 -2
  50. package/dist/web/assets/{PlaygroundPage-BEqH8lAT.js → PlaygroundPage-mv9P6czE.js} +1 -1
  51. package/dist/web/assets/{SettingsPage-ClwYG9Q8.js → SettingsPage-nT9hvcPA.js} +2 -2
  52. package/dist/web/assets/{Toolbar-D5TrWh7K.js → Toolbar-Hsam79hu.js} +1 -1
  53. package/dist/web/assets/{VisitorPickerModal-B0fxKY7g.js → VisitorPickerModal-CqHzml8s.js} +1 -1
  54. package/dist/web/assets/{check-s9DVK_zH.js → check-soiTDN2u.js} +2 -2
  55. package/dist/web/assets/{copy-D_-gX8nM.js → copy-B4fvX0p8.js} +2 -2
  56. package/dist/web/assets/{index-B3TBoi2p.css → index-CuXb3X2-.css} +1 -1
  57. package/dist/web/assets/index-OmOf_og0.js +283 -0
  58. package/dist/web/assets/{meta2dEngine-BD2XbzaV-DLBNOz_m.js → meta2dEngine-BD2XbzaV-Bq3HuUfD.js} +1 -1
  59. package/dist/web/assets/{plus-BR1kwsYl.js → plus-DKKQ-AoS.js} +2 -2
  60. package/dist/web/assets/{react-DCTIdd3e.js → react-CI5PDFXT.js} +3 -3
  61. package/dist/web/index.html +2 -2
  62. package/package.json +1 -1
  63. package/dist/web/assets/AgentChatPanel-ePXffWJl.js +0 -22
  64. package/dist/web/assets/AiWriteWorkbench-DtD5xWmd.js +0 -7
  65. package/dist/web/assets/DocChrome-BkDnBqBu.js +0 -21
  66. package/dist/web/assets/DocumentEditor-CUdNMfU8.js +0 -1
  67. package/dist/web/assets/HtmlEditor-BFOWf-Xl.js +0 -1
  68. package/dist/web/assets/index-vbUbFD-2.js +0 -283
@@ -1 +1 @@
1
- import{T as D,W as _}from"./react-DCTIdd3e.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-1-g23JOU.js";import"./react-vendor-BuABiQkA.js";import"./editor-CL03se2B.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./index-vbUbFD-2.js";import"./plus-BR1kwsYl.js";import"./check-s9DVK_zH.js";import"./copy-D_-gX8nM.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-CI5PDFXT.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-1-g23JOU.js";import"./react-vendor-BuABiQkA.js";import"./editor-CL03se2B.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./index-OmOf_og0.js";import"./plus-DKKQ-AoS.js";import"./check-soiTDN2u.js";import"./copy-B4fvX0p8.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,6 +1,6 @@
1
- import{n as e}from"./index-vbUbFD-2.js";/**
1
+ import{o}from"./index-OmOf_og0.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const o=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],t=e("plus",o);export{t as P};
6
+ */const e=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],t=o("plus",e);export{t as P};
@@ -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-DLBNOz_m.js","assets/meta2d-1-g23JOU.js","assets/react-vendor-BuABiQkA.js","assets/editor-CL03se2B.js","assets/ui-CvA4pq3d.js","assets/motion-DFABYlwt.js","assets/diagram-Bk84WZto.js","assets/index-vbUbFD-2.js","assets/index-B3TBoi2p.css","assets/plus-BR1kwsYl.js","assets/check-s9DVK_zH.js","assets/copy-D_-gX8nM.js","assets/DiagramEditor-NtNY3sZL-D0FE-I9-.js"])))=>i.map(i=>d[i]);
2
- var y7=Object.defineProperty;var x7=(e,t,n)=>t in e?y7(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Mn=(e,t,n)=>x7(e,typeof t!="symbol"?t+"":t,n);import{B as eb,_ as Oe,r as E,ae as k7,af as w7,ag as v7,ah as Dn,ai as Xh,aj as _m,ak as S7,j as O,b as Ri,al as C7,am as _7,an as E7,ao as T7,z as A7,C as Jh,ap as M7,aq as N7,ar as D7,as as I7}from"./react-vendor-BuABiQkA.js";import{P as ze,e as Yh,A as nu,a as Ut,b as tb,w as de,c as fn,k as Cn,n as lt,F as Wr,p as Pi,$ as ce,O as jn,G as pr,d as ms,l as md,z as Sn,r as gt,v as nb,B as je,X as Ln,T as rb,M as Dl,L as Ai,W as pl,f as hi,g as gs,h as So,C as Zh,Y as ib,y as Pt,i as Il,H as Xe,j as L7,t as F7,m as Lo,J as yn,o as sb,R as fi,S as ru,Q as Zn,q as ob,s as O7,u as Ll,x as mt,E as z7,D as yc,I as R7,K as P7,_ as B7,N as iu,U as gd,Z as bs,a0 as Co,a1 as Tt,a2 as ab,a3 as $7,a4 as j7,a5 as Hr,a6 as Ii,a7 as Fl,a8 as vn,a9 as _n,aa as bd,ab as q7,ac as ub,ad as yd,ae as xd,af as _o,V as hn,ag as lb,ah as H7,ai as cb,aj as U7,ak as W7,al as K7,am as V7,an as hb,ao as Qn,ap as G7,aq as jr,ar as qn,as as ys,at as Em,au as Tm,av as X7,aw as J7,ax as Y7,ay as Z7,az as Aa,aA as fb,aB as db,aC as aa,aD as Ma,aE as su,aF as Q7,aG as Qh,aH as Am,aI as ek,aJ as tk,aK as pb,aL as nk,aM as rk,aN as ik,aO as kd,aP as Rr,aQ as Eo,aR as wd,aS as ma,aT as hs,aU as Na,aV as ef,aW as Mm,aX as ga,aY as ml,aZ as Ol,a_ as sk,a$ as ok,b0 as ak,b1 as uk,b2 as lk,b3 as Pr,b4 as ck,b5 as hk,b6 as fk,b7 as Nm,b8 as gl,b9 as Dm,ba as dk,bb as pk,bc as mk,bd as gk,be as xs,bf as Im,bg as tf,bh as bk,bi as yk,bj as xk,bk as kk,bl as Lm,bm as ii,bn as Da,bo as nf,bp as wk,bq as ua,br as mb,bs as gb,bt as bb,bu as yb,bv as xb,bw as vk,bx as Sk,by as vd,bz as kb,bA as Ck,bB as _k,bC as Sd,bD as Ek,bE as Fm,bF as rf,bG as wb,bH as vb,bI as Tk,bJ as Ak,bK as Xu,bL as Sb,bM as Mk,bN as Nk,bO as Dk,bP as Cb,bQ as Ik,bR as Lk,bS as _b,bT as zl,bU as Fk,bV as Ok,bW as zk}from"./editor-CL03se2B.js";import{ag as tt,ah as at,ai as Rk,aj as Ia,ak as Pk,al as Rl,am as Bk,an as wi,ao as Zo,ap as $k,aq as jk,ar as qk,as as Hk,at as Uk,au as Wk,av as Kk,aw as Vk,ad as Cd,ax as Gk,ay as It,ac as qr,az as sf,aA as La,aB as Ue,aC as Pl,aD as Eb,aE as Xk,aF as On,aG as Jk,aH as Yk,aI as Zk,aJ as ou,aK as _d,aL as of,aM as Bl,aN as Tb,aO as Qk,aP as Om,aQ as ew,aR as tw,t as af,aS as Ab,aT as nw,aU as rw,aV as Mb,aW as Nb,aX as iw}from"./ui-CvA4pq3d.js";import{i as B0,j as sw,k as ow,l as aw,n as zm,e as Qo,s as uw,y as lw,h as Rm,m as Pm,r as cw,u as hw,v as fw,o as dw,w as pw,x as Db}from"./diagram-Bk84WZto.js";import{n as pn,aF as mw,aG as Ed,af as gw}from"./index-vbUbFD-2.js";import{P as Bm}from"./plus-BR1kwsYl.js";import{C as bw}from"./check-s9DVK_zH.js";import{C as yw}from"./copy-D_-gX8nM.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-Bq3HuUfD.js","assets/meta2d-1-g23JOU.js","assets/react-vendor-BuABiQkA.js","assets/editor-CL03se2B.js","assets/ui-CvA4pq3d.js","assets/motion-DFABYlwt.js","assets/diagram-Bk84WZto.js","assets/index-OmOf_og0.js","assets/index-CuXb3X2-.css","assets/plus-DKKQ-AoS.js","assets/check-soiTDN2u.js","assets/copy-B4fvX0p8.js","assets/DiagramEditor-NtNY3sZL-CAEe_iNQ.js"])))=>i.map(i=>d[i]);
2
+ var y7=Object.defineProperty;var x7=(e,t,n)=>t in e?y7(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Mn=(e,t,n)=>x7(e,typeof t!="symbol"?t+"":t,n);import{B as eb,_ as Oe,r as E,ae as k7,af as w7,ag as v7,ah as Dn,ai as Xh,aj as _m,ak as S7,j as O,b as Ri,al as C7,am as _7,an as E7,ao as T7,z as A7,C as Jh,ap as M7,aq as N7,ar as D7,as as I7}from"./react-vendor-BuABiQkA.js";import{P as ze,e as Yh,A as nu,a as Ut,b as tb,w as de,c as fn,k as Cn,n as lt,F as Wr,p as Pi,$ as ce,O as jn,G as pr,d as ms,l as md,z as Sn,r as gt,v as nb,B as je,X as Ln,T as rb,M as Dl,L as Ai,W as pl,f as hi,g as gs,h as So,C as Zh,Y as ib,y as Pt,i as Il,H as Xe,j as L7,t as F7,m as Lo,J as yn,o as sb,R as fi,S as ru,Q as Zn,q as ob,s as O7,u as Ll,x as mt,E as z7,D as yc,I as R7,K as P7,_ as B7,N as iu,U as gd,Z as bs,a0 as Co,a1 as Tt,a2 as ab,a3 as $7,a4 as j7,a5 as Hr,a6 as Ii,a7 as Fl,a8 as vn,a9 as _n,aa as bd,ab as q7,ac as ub,ad as yd,ae as xd,af as _o,V as hn,ag as lb,ah as H7,ai as cb,aj as U7,ak as W7,al as K7,am as V7,an as hb,ao as Qn,ap as G7,aq as jr,ar as qn,as as ys,at as Em,au as Tm,av as X7,aw as J7,ax as Y7,ay as Z7,az as Aa,aA as fb,aB as db,aC as aa,aD as Ma,aE as su,aF as Q7,aG as Qh,aH as Am,aI as ek,aJ as tk,aK as pb,aL as nk,aM as rk,aN as ik,aO as kd,aP as Rr,aQ as Eo,aR as wd,aS as ma,aT as hs,aU as Na,aV as ef,aW as Mm,aX as ga,aY as ml,aZ as Ol,a_ as sk,a$ as ok,b0 as ak,b1 as uk,b2 as lk,b3 as Pr,b4 as ck,b5 as hk,b6 as fk,b7 as Nm,b8 as gl,b9 as Dm,ba as dk,bb as pk,bc as mk,bd as gk,be as xs,bf as Im,bg as tf,bh as bk,bi as yk,bj as xk,bk as kk,bl as Lm,bm as ii,bn as Da,bo as nf,bp as wk,bq as ua,br as mb,bs as gb,bt as bb,bu as yb,bv as xb,bw as vk,bx as Sk,by as vd,bz as kb,bA as Ck,bB as _k,bC as Sd,bD as Ek,bE as Fm,bF as rf,bG as wb,bH as vb,bI as Tk,bJ as Ak,bK as Xu,bL as Sb,bM as Mk,bN as Nk,bO as Dk,bP as Cb,bQ as Ik,bR as Lk,bS as _b,bT as zl,bU as Fk,bV as Ok,bW as zk}from"./editor-CL03se2B.js";import{ag as tt,ah as at,ai as Rk,aj as Ia,ak as Pk,al as Rl,am as Bk,an as wi,ao as Zo,ap as $k,aq as jk,ar as qk,as as Hk,at as Uk,au as Wk,av as Kk,aw as Vk,ad as Cd,ax as Gk,ay as It,ac as qr,az as sf,aA as La,aB as Ue,aC as Pl,aD as Eb,aE as Xk,aF as On,aG as Jk,aH as Yk,aI as Zk,aJ as ou,aK as _d,aL as of,aM as Bl,aN as Tb,aO as Qk,aP as Om,aQ as ew,aR as tw,t as af,aS as Ab,aT as nw,aU as rw,aV as Mb,aW as Nb,aX as iw}from"./ui-CvA4pq3d.js";import{i as B0,j as sw,k as ow,l as aw,n as zm,e as Qo,s as uw,y as lw,h as Rm,m as Pm,r as cw,u as hw,v as fw,o as dw,w as pw,x as Db}from"./diagram-Bk84WZto.js";import{o as pn,aH as mw,aI as Ed,ah as gw}from"./index-OmOf_og0.js";import{P as Bm}from"./plus-DKKQ-AoS.js";import{C as bw}from"./check-soiTDN2u.js";import{C as yw}from"./copy-B4fvX0p8.js";/**
3
3
  * @license lucide-react v0.562.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -1731,7 +1731,7 @@ ${this.__markdown}
1731
1731
  ## 分支 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(Ux,{markdown:r})})]})]})}function Nq({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(Mq,{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(Ux,{markdown:s})})]})}function fU({className:e,theme:t}){const[n]=_t(),r=E.useCallback((s,o)=>O.jsx(Nq,{className:e,editor:o,node:s}),[e]),i=E.useRef(!1);return i.current||(i.current=!0,n.registerPlugin(Aq,{decorator:r,theme:t})),null}const Dq=lt("INSERT_MATH_COMMAND"),Wx=lt("UPDATE_MATH_COMMAND"),Ml=lt("SELECT_MATH_SIDE_COMMAND");function Iq(e){return gt(e.registerCommand(Dq,t=>{const{code:n}=t;return e.update(()=>{const r=lu(n);_n([r]),qn(r.getParentOrThrow())&&ys(r,hn).selectEnd()}),!0},Ln),e.registerCommand(Wx,t=>{const{code:n,key:r}=t;return e.update(()=>{const i=ze(r);i&&(i.updateCode(n),i.selectNext())}),!0},Ln),e.registerCommand(Ml,t=>{const{key:n,prev:r}=t;return e.update(()=>{const i=ze(n);i&&(r?i.selectPrevious():i.selectNext())}),!0},Ln))}function Lq(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 Fq=(wo=class extends zt{constructor(t,n){super(),this.kernel=t,this.config=n,this.logger=Qe("plugin","math"),t.registerNodes([xa,Li]),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,Li.getType(),(r,i)=>n!=null&&n.decorator?n.decorator(r,i):null)}onInit(t){this.register(Iq(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(!Lq(i))return;const s=lu(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=yn();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(Li.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),Kx=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||eu(s.current)},[n]),O.jsx(ou,{arrow:!1,content:O.jsx(It,{className:Oi.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:Oi.mathEditorAnchor,onClick:g,ref:s})})});Kx.displayName="MathEditorContainer";Hb();const Vx=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{ew(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(tw,{autoFocus:!0,autoSize:{maxRows:6,minRows:1},className:Oi.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:Oi.mathEditorFooter,horizontal:!0,paddingBlock:4,paddingInline:12,width:"100%",children:O.jsx(qr,{fontSize:13,type:"danger",children:g})}),O.jsx(It,{className:Oi.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"})]})})]})});Vx.displayName="MathEditorContent";kr();const Oq=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(Wx,{code:V,key:r.getKey()})}},[v,r,s]),T=E.useCallback(()=>{if(!r)return;const z=v.getLexicalEditor();z&&(z.dispatchCommand(Ml,{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(Ml,{key:r.getKey(),prev:!0})},[r,v]),F=E.useCallback(()=>{r&&v.dispatchCommand(Ml,{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(!jn(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 Li),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(Vx,{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(Kx,{isBlockMode:m,mathDOM:l,onFocus:j,prev:d,children:U})})}),zq=({mathBlock:e})=>{const t=nr(),n=O.jsx(qr,{as:"span",className:at("katex",Oi.mathPlaceholder),fontSize:e?"1.2em":"1em",type:"secondary",children:t("math.placeholder")});return e?O.jsx(of,{padding:18,width:"100%",children:n}):n};Ot();const Rq=Qe("plugin","math"),Pq=({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 Li;return E.useEffect(()=>{r.current&&t.code&&Jk.render(t.code,r.current,{displayMode:t instanceof Li,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(!jn(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=>{Rq.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(zq,{mathBlock:l})})},Bq=({className:e,renderComp:t,theme:n})=>{const[r]=_t();return E.useLayoutEffect(()=>{r.registerPlugin(Ki),r.registerPlugin(Fq,{decorator:(i,s)=>O.jsx(Pq,{className:e,editor:s,node:i}),theme:n||Oi})},[r,e,n,Oi]),O.jsx(Oq,{renderComp:t})};Bq.displayName="ReactMathPlugin";var Gs=class Nl extends Wr{static getType(){return"meta2d"}static clone(t){return new Nl(t.__diagram,t.__svg,t.__key,t.__autoOpenEditor)}static importJSON(t){return new Nl(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=qi(t))==null?void 0:r.getDecorator(Nl.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---
1732
1732
  ${this.__diagram}
1733
1733
  ---/meta2d---
1734
- `}isInline(){return!1}updateDiagram(t,n){const r=this.getWritable();r.__diagram=t,r.__svg=n}updateDOM(){return!1}};function Gx(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 $q=lt("INSERT_META2D_COMMAND");function jq(e){return e.registerCommand($q,t=>(e.update(()=>{var n;_n([Gx(((n=t==null?void 0:t.diagram)==null?void 0:n.trim())||Sl,(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 qq=/^---meta2d---$/i,Hq=/---meta2d---(\\n?)([\S\s]*?)\n?---\/meta2d---/i;function Uq(e){return(e.children||[]).map(t=>"value"in t&&typeof t.value=="string"?t.value:"").join("")}var vo;const Wq=(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(jq(t)),this.registerMarkdown()}registerMarkdown(){const t=this.kernel.requireService(Lt);t&&(t.registerMarkdownShortCut({regExp:qq,replace:n=>{const r=Gx(Sl,nc,{autoOpenEditor:!0});n.replace(r);const i=yn();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||Sl),n.appendLine("---/meta2d---"),!0}),t.registerMarkdownReader("paragraph",n=>{var s;const r=Uq(n).match(Hq);if(!r)return!1;const i=((s=r[2])==null?void 0:s.trim())||Sl;return ke.createTypeNode(Gs.getType(),{diagram:i,svg:dD(i)})},1))}},vo.pluginName="Meta2dPlugin",vo);let U4=null;function Kq(){return U4??(U4=Oe(()=>import("./meta2dEngine-BD2XbzaV-DLBNOz_m.js"),__vite__mapDeps([23,24,25,26,27,28,29,30,31,32,33,34]))),U4}async function Vq(e){return(await Kq()).generateSvgFromDiagram(e)}function Gq(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 Xq({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),Vq(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:Gq(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 Jq=E.memo(Xq),Yq=E.lazy(async()=>({default:(await Oe(async()=>{const{DiagramEditor:e}=await import("./DiagramEditor-NtNY3sZL-D0FE-I9-.js");return{DiagramEditor:e}},__vite__mapDeps([35,25,23,24,26,27,28,29,30,31,32,33,34]))).DiagramEditor}));function Zq({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(Jq,{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(Yq,{diagram:s,onClose:()=>i(!1),onSave:u})})]})}function dU({className:e,theme:t}){const[n]=_t(),r=E.useCallback((i,s)=>O.jsx(Zq,{className:e,editor:s,node:i}),[e]);return E.useLayoutEffect(()=>{n.registerPlugin(Wq,{decorator:r,theme:t})},[r,n,t]),null}const Xx=E.createContext(null),Qq=({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(Xx.Provider,{value:s,children:e})};Qq.displayName="OutlineProvider";function J1(){return E.useContext(Xx)}function pU(){const e=J1();if(!e)throw new Error("useOutlineVisibility must be used within <OutlineProvider>.");return e}function eH(e){const t=J1(),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 mU=({editor:e,visible:t})=>{const n=J1(),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=yn();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))]})},tH="Hide outline",nH="Show outline",rH="outline";function gU(e){const{collapseTitle:t=tH,expandTitle:n=nH,onVisibleChange:r,visible:i}=e??{},s=eH(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:rH,label:a?t:n,onClick:o}},[t,n,s])}kr();function iH(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 sH(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 oH(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 aH(e,t,n){const r=new Set(n?n.getNodes():[]);iH(t,(i,s)=>{const o=i.elem;r.has(s)?(i.highlighted=!0,sH(e,i)):(i.highlighted=!1,oH(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 uH(){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 lH(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 Jx=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(tf,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(uH())})},[e]);const y=E.useCallback(()=>{e.update(()=>{if(i.isAttached()){const K=ii(i),U=Da(K,e.getElementByKey(K.getKey()));if(U===null)throw new Error("TableActionMenu: Expected to find tableElement in DOM");const z=nf(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=Ik(K.getNodes().filter(hi));U&&lH(U)})},_=()=>{e.update(()=>{Lk()})},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(()=>{Tk()})},[e]),D=E.useCallback(()=>{e.update(()=>{ii(i).remove(),y()})},[e,i,y]),R=E.useCallback(()=>{e.update(()=>{Ak()})},[e]),F=E.useCallback(()=>{e.update(()=>{const K=ii(i),U=Sd(i),[z]=rf(K,null,null),V=new Set,X=i.getHeaderStyles()^Xu.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,Xu.ROW)))}y()})},[e,i,y]),j=E.useCallback(()=>{e.update(()=>{const K=ii(i),U=Sb(i),[z]=rf(K,null,null),V=new Set,X=i.getHeaderStyles()^Xu.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,Xu.COLUMN)))}y()})},[e,i,y]);return O.jsx(_d,{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:gw,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})});Jx.displayName="TableActionMenu";const G4=tt(({css:e})=>({actionIcon:e`
1734
+ `}isInline(){return!1}updateDiagram(t,n){const r=this.getWritable();r.__diagram=t,r.__svg=n}updateDOM(){return!1}};function Gx(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 $q=lt("INSERT_META2D_COMMAND");function jq(e){return e.registerCommand($q,t=>(e.update(()=>{var n;_n([Gx(((n=t==null?void 0:t.diagram)==null?void 0:n.trim())||Sl,(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 qq=/^---meta2d---$/i,Hq=/---meta2d---(\\n?)([\S\s]*?)\n?---\/meta2d---/i;function Uq(e){return(e.children||[]).map(t=>"value"in t&&typeof t.value=="string"?t.value:"").join("")}var vo;const Wq=(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(jq(t)),this.registerMarkdown()}registerMarkdown(){const t=this.kernel.requireService(Lt);t&&(t.registerMarkdownShortCut({regExp:qq,replace:n=>{const r=Gx(Sl,nc,{autoOpenEditor:!0});n.replace(r);const i=yn();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||Sl),n.appendLine("---/meta2d---"),!0}),t.registerMarkdownReader("paragraph",n=>{var s;const r=Uq(n).match(Hq);if(!r)return!1;const i=((s=r[2])==null?void 0:s.trim())||Sl;return ke.createTypeNode(Gs.getType(),{diagram:i,svg:dD(i)})},1))}},vo.pluginName="Meta2dPlugin",vo);let U4=null;function Kq(){return U4??(U4=Oe(()=>import("./meta2dEngine-BD2XbzaV-Bq3HuUfD.js"),__vite__mapDeps([23,24,25,26,27,28,29,30,31,32,33,34]))),U4}async function Vq(e){return(await Kq()).generateSvgFromDiagram(e)}function Gq(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 Xq({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),Vq(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:Gq(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 Jq=E.memo(Xq),Yq=E.lazy(async()=>({default:(await Oe(async()=>{const{DiagramEditor:e}=await import("./DiagramEditor-NtNY3sZL-CAEe_iNQ.js");return{DiagramEditor:e}},__vite__mapDeps([35,25,23,24,26,27,28,29,30,31,32,33,34]))).DiagramEditor}));function Zq({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(Jq,{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(Yq,{diagram:s,onClose:()=>i(!1),onSave:u})})]})}function dU({className:e,theme:t}){const[n]=_t(),r=E.useCallback((i,s)=>O.jsx(Zq,{className:e,editor:s,node:i}),[e]);return E.useLayoutEffect(()=>{n.registerPlugin(Wq,{decorator:r,theme:t})},[r,n,t]),null}const Xx=E.createContext(null),Qq=({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(Xx.Provider,{value:s,children:e})};Qq.displayName="OutlineProvider";function J1(){return E.useContext(Xx)}function pU(){const e=J1();if(!e)throw new Error("useOutlineVisibility must be used within <OutlineProvider>.");return e}function eH(e){const t=J1(),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 mU=({editor:e,visible:t})=>{const n=J1(),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=yn();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))]})},tH="Hide outline",nH="Show outline",rH="outline";function gU(e){const{collapseTitle:t=tH,expandTitle:n=nH,onVisibleChange:r,visible:i}=e??{},s=eH(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:rH,label:a?t:n,onClick:o}},[t,n,s])}kr();function iH(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 sH(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 oH(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 aH(e,t,n){const r=new Set(n?n.getNodes():[]);iH(t,(i,s)=>{const o=i.elem;r.has(s)?(i.highlighted=!0,sH(e,i)):(i.highlighted=!1,oH(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 uH(){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 lH(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 Jx=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(tf,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(uH())})},[e]);const y=E.useCallback(()=>{e.update(()=>{if(i.isAttached()){const K=ii(i),U=Da(K,e.getElementByKey(K.getKey()));if(U===null)throw new Error("TableActionMenu: Expected to find tableElement in DOM");const z=nf(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=Ik(K.getNodes().filter(hi));U&&lH(U)})},_=()=>{e.update(()=>{Lk()})},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(()=>{Tk()})},[e]),D=E.useCallback(()=>{e.update(()=>{ii(i).remove(),y()})},[e,i,y]),R=E.useCallback(()=>{e.update(()=>{Ak()})},[e]),F=E.useCallback(()=>{e.update(()=>{const K=ii(i),U=Sd(i),[z]=rf(K,null,null),V=new Set,X=i.getHeaderStyles()^Xu.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,Xu.ROW)))}y()})},[e,i,y]),j=E.useCallback(()=>{e.update(()=>{const K=ii(i),U=Sb(i),[z]=rf(K,null,null),V=new Set,X=i.getHeaderStyles()^Xu.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,Xu.COLUMN)))}y()})},[e,i,y]);return O.jsx(_d,{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:gw,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})});Jx.displayName="TableActionMenu";const G4=tt(({css:e})=>({actionIcon:e`
1735
1735
  transform: translateX(2px);
1736
1736
  `,root:e`
1737
1737
  will-change: transform;
@@ -27,12 +27,12 @@
27
27
  opacity: 0.65;
28
28
  }
29
29
  </style>
30
- <script type="module" crossorigin src="/assets/index-vbUbFD-2.js"></script>
30
+ <script type="module" crossorigin src="/assets/index-OmOf_og0.js"></script>
31
31
  <link rel="modulepreload" crossorigin href="/assets/react-vendor-BuABiQkA.js">
32
32
  <link rel="modulepreload" crossorigin href="/assets/motion-DFABYlwt.js">
33
33
  <link rel="modulepreload" crossorigin href="/assets/ui-CvA4pq3d.js">
34
34
  <link rel="modulepreload" crossorigin href="/assets/diagram-Bk84WZto.js">
35
- <link rel="stylesheet" crossorigin href="/assets/index-B3TBoi2p.css">
35
+ <link rel="stylesheet" crossorigin href="/assets/index-CuXb3X2-.css">
36
36
  </head>
37
37
  <body>
38
38
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgbg/mdocs",
3
- "version": "1.3.15",
3
+ "version": "1.3.16",
4
4
  "description": "A Markdown knowledge base for small teams",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,22 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diagram-Bk84WZto.js","assets/ui-CvA4pq3d.js","assets/react-vendor-BuABiQkA.js","assets/motion-DFABYlwt.js"])))=>i.map(i=>d[i]);
2
- import{r as i,j as e,_ as ct,b as dt}from"./react-vendor-BuABiQkA.js";import{n as ae,N as Ke,C as ut,ak as Xe,X as ne,al as qe,am as mt,p as Fe,an as Pe,ao as pt,ap as ft,aq as ht,ar as gt,as as xt,at as yt,au as Ue,av as jt,aw as kt,ax as Nt}from"./index-vbUbFD-2.js";import{H as bt,S as vt,A as wt,a as Ct}from"./AgentSkillFormCard-llRkQdK_.js";import{C as Ye}from"./check-s9DVK_zH.js";import{C as Ge}from"./copy-D_-gX8nM.js";import{P as St}from"./plus-BR1kwsYl.js";import{ae as _t,af as At}from"./ui-CvA4pq3d.js";import"./diagram-Bk84WZto.js";import"./motion-DFABYlwt.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 It=[["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"}]],Mt=ae("maximize-2",It);/**
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 Et=[["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"}]],Rt=ae("minimize-2",Et);/**
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 $t=[["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"}]],Tt=ae("zoom-in",$t);/**
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 zt=[["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"}]],Dt=ae("zoom-out",zt);function je(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(je).join(""):typeof s=="object"&&"props"in s?je((n=s.props)==null?void 0:n.children):""}function qt(s){return s?/\blanguage-mermaid\b|\bmermaid\b/i.test(s):!1}function Ft(s){const n=Array.isArray(s)?s:[s];for(const a of n){if(a==null||typeof a!="object"||!("props"in a))continue;const c=a.props;if(!(!c||!qt(c.className)))return je(c.children).replace(/\n$/,"")}return null}const Pt=.4,Lt=4,se=.2;let xe=null;function Bt(){return xe||(xe=ct(()=>import("./diagram-Bk84WZto.js").then(s=>s.z),__vite__mapDeps([0,1,2,3])).then(s=>{const n=s.default;return n.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral",fontFamily:"ui-sans-serif, system-ui, sans-serif"}),n})),xe}const Ot=32,W=new Map;function Le(s){return W.get(s)??null}function Wt(s,n){for(W.has(s)&&W.delete(s),W.set(s,n);W.size>Ot;){const a=W.keys().next().value;if(a==null)break;W.delete(a)}}function ye(s){return Math.min(Lt,Math.max(Pt,s))}function Ht(s){const[n,a]=i.useState(1),[c,b]=i.useState({x:0,y:0}),h=i.useRef(null),[_,y]=i.useState(!1);i.useEffect(()=>{const u=I=>{I.key==="Escape"&&s.onClose()};window.addEventListener("keydown",u);const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",u),document.body.style.overflow=m}},[s.onClose]);function A(u){u.button===0&&(u.currentTarget.setPointerCapture(u.pointerId),h.current={pointerId:u.pointerId,startX:u.clientX,startY:u.clientY,originX:c.x,originY:c.y},y(!0))}function C(u){const m=h.current;!m||m.pointerId!==u.pointerId||b({x:m.originX+(u.clientX-m.startX),y:m.originY+(u.clientY-m.startY)})}function E(u){const m=h.current;if(!(!m||m.pointerId!==u.pointerId)){h.current=null,y(!1);try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}}}function N(u){u.preventDefault();const m=u.deltaY>0?-se:se;a(I=>ye(Number((I+m).toFixed(2))))}return dt.createPortal(e.jsxs("div",{className:"mdocs-agent-mermaid-float",role:"dialog","aria-modal":"true","aria-label":"Mermaid 图预览",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-backdrop","aria-label":"关闭预览",onClick:s.onClose}),e.jsxs("div",{className:"mdocs-agent-mermaid-float-chrome",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-float-tools",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>a(u=>ye(Number((u-se).toFixed(2)))),title:"缩小","aria-label":"缩小",children:e.jsx(Dt,{size:16,"aria-hidden":!0})}),e.jsxs("span",{className:"mdocs-agent-mermaid-float-scale",children:[Math.round(n*100),"%"]}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>a(u=>ye(Number((u+se).toFixed(2)))),title:"放大","aria-label":"放大",children:e.jsx(Tt,{size:16,"aria-hidden":!0})}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>{a(1),b({x:0,y:0})},title:"重置",children:"重置"}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:s.onClose,title:"关闭","aria-label":"关闭",children:e.jsx(ne,{size:16,"aria-hidden":!0})})]}),e.jsx("div",{className:_?"mdocs-agent-mermaid-float-stage is-dragging":"mdocs-agent-mermaid-float-stage",onPointerDown:A,onPointerMove:C,onPointerUp:E,onPointerCancel:E,onWheel:N,children:e.jsx("div",{className:"mdocs-agent-mermaid-float-canvas",style:{transform:`translate(calc(-50% + ${c.x}px), calc(-50% + ${c.y}px)) scale(${n})`},dangerouslySetInnerHTML:{__html:s.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function Kt(s){const n=i.useId().replace(/:/g,""),[a,c]=i.useState("diagram"),[b,h]=i.useState(()=>Le(s.source.trim())),[_,y]=i.useState(null),[A,C]=i.useState(!1),[E,N]=i.useState(!1),u=i.useRef(null),m=s.source.trim(),I=i.useMemo(()=>m,[m]);i.useEffect(()=>()=>{u.current!=null&&window.clearTimeout(u.current)},[]),i.useEffect(()=>{if(a!=="diagram")return;if(!I){h(null),y(null);return}const j=Le(I);if(j){h(j),y(null);return}let M=!1;const P=window.setTimeout(()=>{(async()=>{try{const F=await Bt();if(M)return;const T=`mdocs-agent-mmd-${n}-${Date.now()}`,{svg:R}=await F.render(T,I);if(M)return;Wt(I,R),h(R),y(null)}catch(F){if(M)return;h(null),y(F instanceof Error?F.message:"Mermaid 渲染失败")}})()},200);return()=>{M=!0,window.clearTimeout(P)}},[a,I,n]);async function H(){!m||!await Xe(m)||(C(!0),u.current!=null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>C(!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:a==="diagram"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("diagram"),"aria-pressed":a==="diagram",title:"图谱",children:[e.jsx(Ke,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"图谱"})]}),e.jsxs("button",{type:"button",className:a==="code"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("code"),"aria-pressed":a==="code",title:"代码",children:[e.jsx(ut,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"代码"})]})]}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy mdocs-agent-mermaid-copy",onClick:()=>void H(),"aria-label":A?"已复制":"复制代码",title:A?"已复制":"复制",children:A?e.jsx(Ye,{size:14,"aria-hidden":!0}):e.jsx(Ge,{size:14,"aria-hidden":!0})})]}),a==="diagram"?e.jsx("div",{className:"mdocs-agent-mermaid-diagram",children:_?e.jsxs("div",{className:"mdocs-agent-mermaid-error",role:"alert",children:[e.jsx("p",{children:"无法渲染该图,可切换到代码查看源码。"}),e.jsx("pre",{children:_})]}):b?e.jsx("div",{className:"mdocs-agent-mermaid-svg mdocs-agent-mermaid-svg-hit",role:"button",tabIndex:0,onClick:()=>N(!0),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),N(!0))},title:"点击放大预览","aria-label":"点击放大预览 Mermaid 图",children:e.jsx("span",{className:"mdocs-agent-mermaid-svg-inner",dangerouslySetInnerHTML:{__html:b}})}):e.jsx("div",{className:"mdocs-agent-mermaid-loading",children:"渲染中…"})}):e.jsx("div",{className:"mdocs-agent-panel-md-pre-wrap mdocs-agent-mermaid-code",children:e.jsx("pre",{children:s.codeChildren??e.jsx("code",{className:"language-mermaid",children:m})})}),E&&b?e.jsx(Ht,{svg:b,onClose:()=>N(!1)}):null]})}const Xt=i.memo(Kt,(s,n)=>s.source===n.source);function ke(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(ke).join(""):typeof s=="object"&&"props"in s?ke((n=s.props)==null?void 0:n.children):""}function Ut(s){const[n,a]=i.useState(!1),c=i.useRef(null),b=i.useRef(null),h=ke(s.children).replace(/\n$/,"");i.useEffect(()=>()=>{c.current!=null&&window.clearTimeout(c.current)},[]);async function _(y){var N,u,m;y.preventDefault(),y.stopPropagation();const C=(((m=(u=(N=b.current)==null?void 0:N.querySelector("pre"))==null?void 0:u.innerText)==null?void 0:m.replace(/\n$/,""))??"")||h;!C||!await Xe(C)||(a(!0),c.current!=null&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>a(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-panel-md-pre-wrap",ref:b,children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy",onClick:y=>void _(y),"aria-label":n?"已复制":"复制代码",title:n?"已复制":"复制",children:n?e.jsx(Ye,{size:14,"aria-hidden":!0}):e.jsx(Ge,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:s.children})]})}function Yt(s){const n=Ft(s.children);return n!=null?e.jsx(Xt,{source:n,codeChildren:s.children}):e.jsx(Ut,{children:s.children})}const Gt={pre:({children:s})=>e.jsx(Yt,{children:s})},Be=i.memo(function(n){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(_t,{remarkPlugins:[At],components:Gt,children:n.children})})}),Vt=["如何发布文档?","草稿是什么?","如何创建域?"];function Oe(s,n){return n.map((a,c)=>{const b=a.skillNames&&a.skillNames.length>0?a.skillNames:a.skillIds&&a.skillIds.length>0?a.skillIds:void 0;return{id:`h-${s}-${c}-${a.role}`,role:a.role,content:a.content,skillNames:b}})}function Jt(s,n){const a=s.slice(),c=a[a.length-1];return(c==null?void 0:c.type)==="text"?a[a.length-1]={type:"text",text:c.text+n}:a.push({type:"text",text:n}),a}function Zt(s,n){const a=s.slice(),c=a[a.length-1];return(c==null?void 0:c.type)==="thinking"?a[a.length-1]={type:"thinking",text:c.text+n}:a.push({type:"thinking",text:n}),a}function We(s){return s!=null&&s.length?s.filter(n=>n.type==="text").map(n=>n.text).join(""):""}function Qt(s){return!!(s!=null&&s.some(n=>n.type==="thinking"&&n.text.length>0))}function es(s){const n=new Date(s);if(Number.isNaN(n.getTime()))return"";const a=new Date;return n.getFullYear()===a.getFullYear()&&n.getMonth()===a.getMonth()&&n.getDate()===a.getDate()?n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function He(s){if(s>=1e3){const n=s/1e3;return`${n>=10?Math.round(n):Math.round(n*10)/10}K`}return String(s)}function ts(s){const{block:n,onResolved:a}=s,[c,b]=i.useState(""),[h,_]=i.useState(!1),[y,A]=i.useState(1),C=i.useRef(!1),E=i.useRef(a);E.current=a;const N=n.status==="open",u=i.useRef(0);i.useEffect(()=>{if(!N)return;C.current=!1;const j=new Date(n.expiresAt).getTime(),M=Date.now(),P=Math.max(j-M,1);u.current=P,A(1);const F=()=>{const R=j-Date.now(),p=Math.max(0,Math.min(1,R/P));A(p),R<=0&&!C.current&&(C.current=!0,kt(n.requestId).catch(()=>{}).finally(()=>{E.current(n.requestId,"","expired")}))};F();const T=window.setInterval(F,100);return()=>window.clearInterval(T)},[N,n.expiresAt,n.requestId]);async function m(j){const M=j.trim();if(!(!M||h||!N)){_(!0);try{await Nt(n.requestId,M),a(n.requestId,M,"selected")}catch{a(n.requestId,M,"failed")}finally{_(!1)}}}async function I(){if(!(h||!N)){_(!0),C.current=!0;try{await Ue(n.requestId),a(n.requestId,"","cancelled")}catch{a(n.requestId,"","failed")}finally{_(!1)}}}const H=Math.max(0,Math.ceil(y*u.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(N?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:n.title}),N?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[H,"s"]}):null]}),N?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(y*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${y})`}})}):null,n.status==="selected"&&n.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",n.selected]}):null,n.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,n.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,n.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,N?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:n.options.map(j=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:h,onClick:()=>void m(j),children:j},j))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:c,disabled:h,placeholder:"或输入自己的内容…",onChange:j=>b(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),m(c))}}),e.jsx("button",{type:"button",disabled:h||!c.trim(),onClick:()=>void m(c),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:h,onClick:()=>void I(),children:"取消"})})]}):null]})}function ss(s){const b=2*Math.PI*8.75,h=Math.min(100,Math.max(0,s.percent)),_=b*(1-h/100),y=h>=90?"danger":h>=70?"warn":"ok",A=`上下文 ${h}% · 已用 ${He(s.used)} / ${He(s.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+y,"data-tooltip":A,"aria-label":A,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:b,strokeDashoffset:_,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function ns(s){var n;for(const a of s)if(!(a.role!=="assistant"||!((n=a.blocks)!=null&&n.length))){for(const c of a.blocks)if((c.type==="choice_card"||c.type==="skill_form_card")&&c.status==="open")return!0}return!1}const ps=i.forwardRef(function(n,a){const{open:c,onClose:b,visitorName:h,anchorStyle:_,fullscreen:y,onToggleFullscreen:A,domainId:C,documentId:E,documentTitle:N,documentPath:u,graphFileId:m,graphLabel:I,onOpenDocument:H,onTreeChanged:j,onDocumentOverwritten:M,onOpenCoding:P}=n,F=((h==null?void 0:h.trim().charAt(0))||"我").toUpperCase(),[T,R]=i.useState(!1),[p,U]=i.useState(null),[Ve,Y]=i.useState(null),[z,w]=i.useState([]),[re,G]=i.useState(null),[Ne,Je]=i.useState([]),[Ze,be]=i.useState(!1),[V,J]=i.useState(""),[X,ve]=i.useState([]),[we,ie]=i.useState(!1),[v,Z]=i.useState(!1),[Ce,L]=i.useState(null),[Q,Se]=i.useState(null),[oe,O]=i.useState(!1),[B,_e]=i.useState(!1),Qe=i.useRef(null),ee=i.useRef(null),D=i.useRef(null),Ae=i.useRef(0),K=i.useRef(!0),[et,le]=i.useState(!1),ce=i.useRef(z);ce.current=z;const Ie=!!(E!=null&&E.trim())&&!we,tt=(N==null?void 0:N.trim())||"当前文档",Me=(u==null?void 0:u.trim())||"",de=!!(m!=null&&m.trim())&&!we,st=(I==null?void 0:I.trim())||"当前图谱";i.useEffect(()=>{ie(!1)},[E,m]);function Ee(t){return Ae.current+=1,`${t}-${Ae.current}`}const Re=120;function $e(t){return t.scrollHeight-t.scrollTop-t.clientHeight}function te(){const t=ee.current;t&&(t.scrollTop=t.scrollHeight,le(!1))}function q(){K.current&&te()}function nt(){const t=ee.current;if(!t)return;const f=$e(t);K.current=f<=48,le(f>Re)}function at(){K.current=!0,te()}i.useLayoutEffect(()=>{q();const t=ee.current;t&&le($e(t)>Re)},[z]);async function rt(){be(!0);try{const t=await ht();Je(t.sessions),re||G(t.lastOpenedSessionId)}catch{}finally{be(!1)}}async function ue(){try{const t=await ft();Se(t)}catch{}}async function Te(){try{const t=await qe();U(t),Y(null)}catch(t){U(null),Y(t instanceof Error?t.message:String(t))}}i.useEffect(()=>{var f;if(!c){R(!1),(f=D.current)==null||f.abort(),D.current=null,Z(!1);return}let t=!1;return(async()=>{try{const o=await qe();t||(U(o),Y(null))}catch(o){t||(U(null),Y(o instanceof Error?o.message:String(o)))}})(),ue(),()=>{t=!0}},[c]),i.useEffect(()=>{if(!c)return;let t=!1;return(async()=>{try{const f=await mt();if(t)return;G(f.sessionId),w(o=>o.length>0?o:Oe(f.sessionId,f.messages))}catch{}})(),()=>{t=!0}},[c]),i.useEffect(()=>{!c||!T||rt()},[c,T]);function me(){if(!B){if(ns(ce.current)){O(!0);return}O(!1),b()}}async function it(){var o;if(B)return;_e(!0);const t=ce.current,f=[];for(const S of t)if(!(S.role!=="assistant"||!S.blocks))for(const g of S.blocks)g.type==="choice_card"&&g.status==="open"&&f.push(Ue(g.requestId).catch(()=>{})),g.type==="skill_form_card"&&g.status==="open"&&f.push(jt(g.requestId).catch(()=>{}));await Promise.all(f),(o=D.current)==null||o.abort(),w(S=>S.map(g=>g.role!=="assistant"||!g.blocks?g:{...g,blocks:g.blocks.map(x=>x.type==="choice_card"&&x.status==="open"?{...x,status:"cancelled"}:x.type==="skill_form_card"&&x.status==="open"?{...x,status:"cancelled"}:x)})),O(!1),_e(!1),b()}const pe=i.useRef(me);pe.current=me,i.useImperativeHandle(a,()=>({requestClose:()=>pe.current()}),[]),i.useEffect(()=>{if(!c){O(!1);return}const t=f=>{if(f.key==="Escape"){if(oe){B||O(!1);return}if(T){R(!1);return}pe.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[c,T,oe,B]);async function fe(t){var x;const f=t.trim();if(!f||v)return;if(!(p!=null&&p.enabled)){L((p==null?void 0:p.reason)==="missing_api_key"?"请先配置 API Key":(p==null?void 0:p.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(x=D.current)==null||x.abort();const o=new AbortController;D.current=o;const S={id:Ee("u"),role:"user",content:f,skillNames:X.length>0?[...X]:void 0},g=Ee("a");K.current=!0,w($=>[...$,S,{id:g,role:"assistant",content:""}]),J(""),Z(!0),L(null),R(!1),requestAnimationFrame(()=>{te(),requestAnimationFrame(te)});try{let $=!1;await yt(f,{skillNames:X.length>0?X:void 0,references:{domainId:(C==null?void 0:C.trim())||void 0,documentId:!de&&Ie?E.trim():void 0,graphFileId:de?m.trim():void 0},signal:o.signal,onEvent:l=>{l.type==="text_delta"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=Jt(r.blocks??[],l.text);return{...r,blocks:d,content:We(d)}})),requestAnimationFrame(()=>q())):l.type==="thinking_delta"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=Zt(r.blocks??[],l.text);return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="sources"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=(r.blocks??[]).slice(),ge=d[d.length-1];return(ge==null?void 0:ge.type)==="sources"?d[d.length-1]={type:"sources",items:l.items}:d.push({type:"sources",items:l.items}),{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="document_table"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"document_table",title:l.title,rows:l.rows}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="document_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"document_card",documentId:l.documentId,title:l.title,path:l.path,preview:l.preview}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="tool_notice"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"tool_notice",toolName:l.toolName,text:l.text}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="choice_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"choice_card",requestId:l.requestId,title:l.title,options:l.options,expiresAt:l.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="choice_expired"?w(k=>k.map(r=>r.id!==g||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===l.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):l.type==="skill_form_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"skill_form_card",requestId:l.requestId,mode:l.mode,title:l.title,currentName:l.currentName,initialName:l.initialName,initialDescription:l.initialDescription,initialBody:l.initialBody,expiresAt:l.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="skill_form_expired"?w(k=>k.map(r=>r.id!==g||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===l.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):l.type==="tree_changed"?j==null||j():l.type==="document_overwritten"?M==null||M({documentId:l.documentId,headCommitId:l.headCommitId}):l.type==="open_coding"?P==null||P({documentId:l.documentId,displayName:l.displayName}):l.type==="context_usage"?Se({percent:l.percent,used:l.used,limit:l.limit}):l.type==="error"&&($=!0,L(l.message))}}),!o.signal.aborted&&!$&&ve([])}catch($){if(o.signal.aborted)return;L($ instanceof Error?$.message:String($))}finally{D.current===o&&(D.current=null),Z(!1)}}async function ot(){var t;if(!v){(t=D.current)==null||t.abort(),L(null),R(!1),Z(!1);try{const f=await gt();G(f.sessionId),w([]),J(""),K.current=!0,ue()}catch(f){L(f instanceof Error?f.message:String(f))}}}async function lt(t){var f;if(!v){if(t===re){R(!1);return}(f=D.current)==null||f.abort(),L(null);try{const o=await xt(t);G(o.sessionId),w(Oe(o.sessionId,o.messages)),J(""),R(!1),K.current=!0,requestAnimationFrame(()=>q()),ue()}catch(o){L(o instanceof Error?o.message:String(o))}}}function ze(t){!t||!H||H(t)}if(!c)return null;const he=(p==null?void 0:p.reason)==="missing_api_key",De=Ve??(p&&!p.enabled&&!he?p.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:Qe,className:"mdocs-agent-panel"+(y?" mdocs-agent-panel--fullscreen":""),role:"dialog","aria-label":"mdocs 智能助手","aria-modal":y?!0:void 0,style:y?void 0:_,children:[e.jsxs("header",{className:"mdocs-agent-panel-header",children:[e.jsxs("div",{className:"mdocs-agent-panel-title",children:[e.jsx("img",{src:Fe,alt:"",className:"mdocs-agent-panel-title-logo"}),e.jsx("span",{children:"mdocs 智能助手"})]}),e.jsxs("div",{className:"mdocs-agent-panel-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:v,onClick:()=>void ot(),children:e.jsx(St,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(T?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>R(t=>!t),children:e.jsx(bt,{size:16,strokeWidth:1.8})}),A?e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:y?"退出全屏":"全屏","aria-label":y?"退出全屏":"全屏",onClick:A,children:y?e.jsx(Rt,{size:16,strokeWidth:1.8}):e.jsx(Mt,{size:16,strokeWidth:1.8})}):null,e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:me,children:e.jsx(ne,{size:16,strokeWidth:1.8})})]})]}),T?e.jsxs("div",{className:"mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>R(!1),children:"返回对话"})]}),Ze?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):Ne.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):e.jsx("ul",{className:"mdocs-agent-panel-history-list",children:Ne.map(t=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(t.id===re?" active":""),disabled:v,onClick:()=>void lt(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:es(t.updatedAt)})]})},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:ee,onScroll:nt,children:z.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-hello",children:"你好,我是 mdocs 智能助手"}),e.jsx("p",{className:"mdocs-agent-panel-desc",children:"我能答疑、搜文档、整理结构,也能帮你写全文;需要精细改稿请点文档顶栏「帮写」。"}),he?e.jsx(Pe,{onConfigured:Te}):De?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:De}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:Vt.map(t=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void fe(t),disabled:v||!(p!=null&&p.enabled),children:t},t))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:z.map(t=>{var f;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:Fe,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((o,S)=>{var g;return o.type==="thinking"?o.text?e.jsxs("details",{className:"mdocs-agent-panel-think-fold",open:v&&t.id===((g=z[z.length-1])==null?void 0:g.id),children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:o.text})]},`${t.id}-th-${S}`):null:o.type==="text"?o.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Be,{children:o.text})},`${t.id}-t-${S}`):null:o.type==="sources"?o.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:["已阅读 ",o.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:o.items.map(x=>e.jsx("li",{children:e.jsx("a",{href:x.url,target:"_blank",rel:"noreferrer",children:x.name})},x.id))})]})},`${t.id}-s-${S}`):o.type==="tool_notice"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:o.text})},`${t.id}-n-${S}`):o.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(ts,{block:o,onResolved:(x,$,l)=>{w(k=>k.map(r=>r.id!==t.id||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===x?{...d,status:l,selected:l==="selected"?$:d.selected}:d)}))}})},`${t.id}-ch-${S}`):o.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(vt,{block:o,onResolved:(x,$,l)=>{w(k=>k.map(r=>r.id!==t.id||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===x?{...d,status:$,submittedName:$==="submitted"?l:d.submittedName}:d)}))}})},`${t.id}-sf-${S}`):o.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:x=>{x.preventDefault(),x.stopPropagation(),ze(o.documentId)},children:["《",o.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"文档预览"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[o.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:o.path}):null,o.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:o.preview}):e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview muted",children:"(无正文预览)"})]})]})},`${t.id}-c-${S}`):e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[o.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:o.rows.length===0?"无结果":`${o.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:o.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:o.rows.map(x=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>ze(x.documentId),children:x.title})}),e.jsx("td",{children:x.summary||"-"})]},x.documentId))})]})})]})},`${t.id}-d-${S}`)}),v&&t.id===((f=z[z.length-1])==null?void 0:f.id)&&!We(t.blocks)&&!Qt(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(Be,{children:t.content}):v?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:F}):null]},t.id)})})}),et?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:at,title:"回到底部","aria-label":"回到底部",children:[e.jsx(wt,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),Ce?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Ce}):null,he&&z.length>0?e.jsx(Pe,{onConfigured:Te}):null,e.jsx(Ct,{selectedNames:X,onChange:ve,disabled:v||!(p!=null&&p.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap",children:[de?e.jsxs("div",{className:"mdocs-agent-doc-ref mdocs-agent-graph-ref",children:[e.jsx(Ke,{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:st}),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:v,onClick:()=>ie(!0),children:e.jsx(ne,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):Ie?e.jsxs("div",{className:"mdocs-agent-doc-ref",children:[e.jsx(pt,{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:tt}),Me?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:Me}):null]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前文档",disabled:v,onClick:()=>ie(!0),children:e.jsx(ne,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):null,e.jsxs("div",{className:"mdocs-agent-panel-input-body",children:[e.jsx("textarea",{className:"mdocs-agent-panel-input",rows:2,placeholder:p!=null&&p.enabled?"把你的问题告诉我…":"请先配置 API Key",value:V,disabled:v||!(p!=null&&p.enabled),onChange:t=>J(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),fe(V))}}),Q?e.jsx(ss,{percent:Q.percent,used:Q.used,limit:Q.limit}):null,e.jsx("button",{type:"button",className:v?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:v?!1:!(p!=null&&p.enabled)||!V.trim(),onClick:()=>{var t;if(v){(t=D.current)==null||t.abort();return}fe(V)},title:v?"停止":"发送","aria-label":v?"停止":"发送",children:v?"■":"↑"})]})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),oe?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{B||O(!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:B,onClick:()=>O(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:B,onClick:()=>void it(),children:B?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{ps as AgentChatPanel};
@@ -1,7 +0,0 @@
1
- import{r as o,j as e}from"./react-vendor-BuABiQkA.js";import{aw as we,ax as je,au as Ne,al as le,am as be,p as Se,an as re,aq as Ce,ay as Ie,ar as ve,as as Me,at as Ae}from"./index-vbUbFD-2.js";import{H as Te,S as $e,A as Re,a as Ee}from"./AgentSkillFormCard-llRkQdK_.js";import{P as _e}from"./plus-BR1kwsYl.js";import{ae as qe,af as Le}from"./ui-CvA4pq3d.js";import"./diagram-Bk84WZto.js";import"./motion-DFABYlwt.js";function Pe(t){const{block:s,onResolved:i}=t,[r,g]=o.useState(""),[p,y]=o.useState(!1),[S,k]=o.useState(1),x=o.useRef(!1),j=o.useRef(i);j.current=i;const m=s.status==="open",R=o.useRef(0);o.useEffect(()=>{if(!m)return;x.current=!1;const h=new Date(s.expiresAt).getTime(),C=Date.now(),q=Math.max(h-C,1);R.current=q,k(1);const A=()=>{const K=h-Date.now(),v=Math.max(0,Math.min(1,K/q));k(v),K<=0&&!x.current&&(x.current=!0,we(s.requestId).catch(()=>{}).finally(()=>{j.current(s.requestId,"","expired")}))};A();const B=window.setInterval(A,100);return()=>window.clearInterval(B)},[m,s.expiresAt,s.requestId]);async function w(h){const C=h.trim();if(!(!C||p||!m)){y(!0);try{await je(s.requestId,C),i(s.requestId,C,"selected")}catch{i(s.requestId,C,"failed")}finally{y(!1)}}}async function M(){if(!(p||!m)){y(!0),x.current=!0;try{await Ne(s.requestId),i(s.requestId,"","cancelled")}catch{i(s.requestId,"","failed")}finally{y(!1)}}}const D=Math.max(0,Math.ceil(S*R.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(m?"":" 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}),m?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[D,"s"]}):null]}),m?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(S*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${S})`}})}):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,m?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:s.options.map(h=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:p,onClick:()=>void w(h),children:h},h))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:r,disabled:p,placeholder:"或输入自己的内容…",onChange:h=>g(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),w(r))}}),e.jsx("button",{type:"button",disabled:p||!r.trim(),onClick:()=>void w(r),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:p,onClick:()=>void M(),children:"取消"})})]}):null]})}function ee(t){return t===""?[]:t.split(`
2
- `)}function De(t){return t.join(`
3
- `)}function te(t,s){const i=ee(t),r=ee(s),g=i.length,p=r.length,y=Array.from({length:g+1},()=>Array.from({length:p+1},()=>0));for(let w=g-1;w>=0;w--)for(let M=p-1;M>=0;M--)i[w]===r[M]?y[w][M]=y[w+1][M+1]+1:y[w][M]=Math.max(y[w+1][M],y[w][M+1]);const S=[];let k=0,x=0;for(;k<g||x<p;)if(k<g&&x<p&&i[k]===r[x])S.push({kind:"eq",oi:k,ni:x}),k++,x++;else if(x<p&&(k===g||y[k][x+1]>=y[k+1][x]))S.push({kind:"ins",oi:k,ni:x}),x++;else if(k<g)S.push({kind:"del",oi:k,ni:x}),k++;else break;const j=[];let m=0,R=0;for(;m<S.length;){if(S[m].kind==="eq"){m++;continue}const w=S[m].oi,M=S[m].ni,D=[],h=[];let C=w,q=M;for(;m<S.length&&S[m].kind!=="eq";){const A=S[m];A.kind==="del"?(D.push(i[A.oi]),C=A.oi+1):(h.push(r[A.ni]),q=A.ni+1),m++}j.push({id:`h${R++}`,oldStart:w,oldEnd:C,newStart:M,newEnd:q,oldLines:D,newLines:h})}return j}function Be(t,s){const i=ee(t);return De([...i.slice(0,s.oldStart),...s.newLines,...i.slice(s.oldEnd)])}function U(t){return t===""?[]:t.split(`
4
- `)}function z(t){return t.join(`
5
- `)}function Fe(t,s){const i=U(t),r=[];let g=0;return s.forEach((p,y)=>{p.oldStart>g&&r.push({kind:"same",lines:i.slice(g,p.oldStart),key:`s-${g}-${p.oldStart}`}),r.push({kind:"hunk",hunk:p,hunkIndex:y,key:`h-${p.id}-${y}`}),g=p.oldEnd}),g<i.length?r.push({kind:"same",lines:i.slice(g),key:`s-${g}-end`}):s.length===0&&i.length===0&&r.push({kind:"same",lines:[],key:"s-empty"}),r}function He(t){const s=[],i=[];for(const r of t)r.kind==="same"?s.push(z(r.lines)):i.push(z(r.hunk.newLines));return{sameTexts:s,newTexts:i}}function oe(t,s){const i=[];let r=0,g=0;for(const p of t)if(p.kind==="same"){const y=s.sameTexts[r++]??"";i.push(...U(y))}else{const y=s.newTexts[g++]??"";i.push(...U(y))}return z(i)}function Ke(t){return t.oldLines.length===0?"add":t.newLines.length===0?"del":"mod"}function ce(t){const s=Math.max(1,U(t.value).length);return e.jsxs("div",{className:`mdocs-ai-write-line ${t.className}`,children:[e.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),e.jsx("textarea",{className:"mdocs-ai-write-inline-edit",value:t.value,rows:s,spellCheck:!1,"aria-label":t["aria-label"],onChange:i=>t.onChange(i.target.value),onBlur:()=>t.onBlurFlush()})]})}function Oe(t){const s=!!t.sending,[i,r]=o.useState(0),[g,p]=o.useState(null),[y,S]=o.useState({sameTexts:[],newTexts:[]}),[k,x]=o.useState([]),j=o.useRef(!1),m=o.useRef(!1),R=o.useRef([]),w=o.useRef(y);w.current=y,R.current=k;const M=o.useMemo(()=>t.proposedMd==null||t.proposedMd===t.currentMd?[]:te(t.currentMd,t.proposedMd),[t.currentMd,t.proposedMd]),D=!s&&(k.length>0?k.some(l=>l.kind==="hunk"):M.length>0);o.useEffect(()=>{if(s){x([]),j.current=!1,m.current=!1;return}if(t.proposedMd==null||t.proposedMd===t.currentMd){x([]),j.current=!1,m.current=!1;return}if(m.current){m.current=!1;return}const l=te(t.currentMd,t.proposedMd);if(l.length===0){x([]);return}const f=Fe(t.currentMd,l);x(f),j.current=!1,S(He(f))},[s,t.proposedMd,t.currentMd]);const h=o.useMemo(()=>k.filter(l=>l.kind==="hunk").map(l=>l.hunk),[k]);o.useEffect(()=>{if(h.length===0){r(0);return}r(l=>Math.min(l,h.length-1))},[h.length]);const C=g??i;function q(){return oe(R.current,w.current)}function A(){if(!D||R.current.length===0)return t.proposedMd;const l=q();return j.current=!1,l===t.currentMd?(m.current=!1,t.onProposedChange(null),null):(l!==t.proposedMd&&(m.current=!0,t.onProposedChange(l)),l)}function B(l){const f=R.current.find(F=>F.kind==="hunk"&&F.hunk.id===l.id);if(!f)return;const N=w.current.newTexts[f.hunkIndex],b={...l,newLines:N!=null?U(N):l.newLines},L=q();if(j.current=!1,m.current=!1,L===t.currentMd){t.onProposedChange(null);return}const T=Be(t.currentMd,b);t.onCurrentChange(T),L===T?t.onProposedChange(null):t.onProposedChange(L)}function K(l){const f=R.current.find(L=>L.kind==="hunk"&&L.hunk.id===l.id);if(!f)return;const N={sameTexts:w.current.sameTexts.slice(),newTexts:w.current.newTexts.slice()};N.newTexts[f.hunkIndex]=z(l.oldLines);const b=oe(R.current,N);j.current=!1,m.current=!1,b===t.currentMd?t.onProposedChange(null):t.onProposedChange(b)}function v(){const l=q();j.current=!1,m.current=!1,t.onCurrentChange(l),t.onProposedChange(null)}function J(){j.current=!1,m.current=!1,t.onProposedChange(null)}function I(l){h.length!==0&&r(f=>{const N=(f+l+h.length)%h.length,b=document.getElementById(`mdocs-ai-hunk-${N}`);return b==null||b.scrollIntoView({block:"center",behavior:"smooth"}),N})}function W(l,f){j.current=!0,S(N=>{const b=N.sameTexts.slice();return b[l]=f,{...N,sameTexts:b}})}function V(l,f){j.current=!0,S(N=>{const b=N.newTexts.slice();return b[l]=f,{...N,newTexts:b}})}const E=h[C]??null;let G=0;return e.jsxs("div",{className:"mdocs-ai-write-md-pane",children:[e.jsxs("div",{className:"mdocs-ai-write-diff-toolbar",children:[e.jsx("span",{className:"mdocs-ai-write-diff-count",children:s?"接收中·编辑我的稿":h.length===0?t.proposedMd?"与提案一致(可编辑)":"Markdown 源码(可编辑)":`${h.length} 处变更(可改提案)`}),!s&&h.length>0?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"mdocs-ai-write-diff-accept-all",onClick:v,children:"全部接受"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-diff-reject-all",onClick:J,children:"全部拒绝"})]}):null]}),D&&k.length>0?e.jsxs("div",{className:"mdocs-ai-write-inline",role:"document",children:[k.map(l=>{if(l.kind==="same"){const T=G++,F=y.sameTexts[T]??z(l.lines);return e.jsx("div",{className:"mdocs-ai-write-inline-same",children:e.jsx(ce,{className:"ctx",value:F,"aria-label":"提案相同行",onChange:Y=>W(T,Y),onBlurFlush:()=>A()})},l.key)}const f=l.hunk,N=Ke(f),b=l.hunkIndex===C,L=y.newTexts[l.hunkIndex]??z(f.newLines);return e.jsxs("div",{id:`mdocs-ai-hunk-${l.hunkIndex}`,className:`mdocs-ai-write-inline-hunk mdocs-ai-write-inline-hunk-${N}`+(b?" is-active":""),onMouseEnter:()=>p(l.hunkIndex),onMouseLeave:()=>p(null),onClick:()=>r(l.hunkIndex),children:[e.jsxs("div",{className:"mdocs-ai-write-hunk-hover",hidden:g!==l.hunkIndex,children:[e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:T=>{T.stopPropagation(),K(f)},children:"拒绝"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:T=>{T.stopPropagation(),B(f)},children:"接受"})]}),e.jsx("pre",{className:"mdocs-ai-write-hunk-pre",children:f.oldLines.map((T,F)=>e.jsxs("div",{className:"mdocs-ai-write-line del mdocs-ai-write-line-readonly",children:[e.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),e.jsx("span",{className:"mdocs-ai-write-code",children:T||" "})]},`o${F}`))}),f.newLines.length>0||L!==""||N!=="del"?e.jsx(ce,{className:"add",value:L,"aria-label":"提案新增行",onChange:T=>V(l.hunkIndex,T),onBlurFlush:()=>A()}):null]},l.key)}),E?e.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"变更导航",children:[e.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>I(-1),children:"↑"}),e.jsxs("span",{children:[C+1," / ",h.length]}),e.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>I(1),children:"↓"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>K(E),children:"拒绝"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>B(E),children:"接受"})]}):null]}):e.jsx("textarea",{className:"mdocs-ai-write-editor",value:t.currentMd,onChange:l=>t.onCurrentChange(l.target.value),spellCheck:!1,placeholder:`# 标题
6
-
7
- 在此编辑 Markdown 源码…`})]})}let de=0;function ue(t){return de+=1,`${t}-${Date.now()}-${de}`}function We(t,s){const i=t.slice(),r=i[i.length-1];return(r==null?void 0:r.type)==="text"?i[i.length-1]={type:"text",text:r.text+s}:i.push({type:"text",text:s}),i}function ze(t,s){const i=t.slice(),r=i[i.length-1];return(r==null?void 0:r.type)==="thinking"?i[i.length-1]={type:"thinking",text:r.text+s}:i.push({type:"thinking",text:s}),i}function Z(t,s){const i=s.trim();return i?[...t,{type:"tool",text:i}]:t}function Je(t){return t.some(s=>s.type==="text"||s.type==="thinking"?s.text.length>0:!0)}function Ge(t){const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const i=new Date;return s.getFullYear()===i.getFullYear()&&s.getMonth()===i.getMonth()&&s.getDate()===i.getDate()?s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function me(t,s){return s.map((i,r)=>{const g=`h-${t}-${r}-${i.role}`;if(i.role==="user"){const p=i.skillNames&&i.skillNames.length>0?i.skillNames:i.skillIds&&i.skillIds.length>0?i.skillIds:void 0;return{id:g,role:"user",content:i.content,skillNames:p}}return{id:g,role:"assistant",blocks:i.content?[{type:"text",text:i.content}]:[]}})}function tt(t){const[s,i]=o.useState(t.initialMarkdown),[r,g]=o.useState(null),[p]=o.useState(t.initialMarkdown),[y,S]=o.useState(t.displayName||"未命名"),[k,x]=o.useState([]),[j,m]=o.useState(null),[R,w]=o.useState([]),[M,D]=o.useState(!1),[h,C]=o.useState(!1),[q,A]=o.useState(""),[B,K]=o.useState([]),[v,J]=o.useState(!1),[I,W]=o.useState(null),[V,E]=o.useState(null),[G,l]=o.useState(!1),f=o.useRef(null),N=o.useRef(null),b=o.useRef(!0),[L,T]=o.useState(!1),F=120;function Y(n){return n.scrollHeight-n.scrollTop-n.clientHeight}function X(){const n=N.current;n&&(n.scrollTop=n.scrollHeight,T(!1))}function he(){b.current&&X()}function fe(){const n=N.current;if(!n)return;const d=Y(n);b.current=d<=48,T(d>F)}function xe(){b.current=!0,X()}o.useLayoutEffect(()=>{if(!t.open)return;he();const n=N.current;n&&T(Y(n)>F)},[k,t.open]);async function Q(){D(!0);try{const n=await Ce("coding",t.documentId);w(n.sessions),j||m(n.lastOpenedSessionId)}catch{}finally{D(!1)}}async function ne(){try{const n=await le();W(n)}catch{W({enabled:!1,skillsReady:!1,model:null})}}if(o.useEffect(()=>{var d;if(!t.open){C(!1),(d=f.current)==null||d.abort();return}i(t.initialMarkdown),g(null),S(t.displayName||"未命名"),A(""),E(null),C(!1);let n=!1;return(async()=>{try{const u=await le();n||W(u)}catch{n||W({enabled:!1,skillsReady:!1,model:null})}try{const u=await be("coding",t.documentId);if(n)return;m(u.sessionId),x(me(u.sessionId,u.messages))}catch{n||(m(null),x([]))}Q()})(),()=>{n=!0}},[t.open,t.initialMarkdown,t.displayName,t.documentId]),o.useEffect(()=>()=>{var n;return(n=f.current)==null?void 0:n.abort()},[]),o.useEffect(()=>{t.open&&h&&Q()},[h,t.open,t.documentId]),!t.open)return null;const se=(I==null?void 0:I.reason)==="missing_api_key",ie=r!=null&&r!==s?te(s,r):[];async function ge(){var n;if(!v){(n=f.current)==null||n.abort(),E(null),C(!1),J(!1);try{const d=await ve("coding",t.documentId);m(d.sessionId),x([]),A(""),Q()}catch(d){E(d instanceof Error?d.message:String(d))}}}async function pe(n){var d;if(!v){if(n===j){C(!1);return}(d=f.current)==null||d.abort(),E(null);try{const u=await Me(n,"coding",t.documentId);m(u.sessionId),x(me(u.sessionId,u.messages)),A(""),C(!1)}catch(u){E(u instanceof Error?u.message:String(u))}}}async function ae(){var O;const n=q.trim();if(!n||v)return;if(!(I!=null&&I.enabled)){E("请先配置 API Key");return}(O=f.current)==null||O.abort();const d=new AbortController;f.current=d;const u=ue("u"),H=ue("a");b.current=!0,x(_=>[..._,{id:u,role:"user",content:n,skillNames:B.length>0?[...B]:void 0},{id:H,role:"assistant",blocks:[]}]),A(""),J(!0),E(null),requestAnimationFrame(()=>{X(),requestAnimationFrame(X)});const $=_=>{x(a=>a.map(c=>c.id===H&&c.role==="assistant"?{...c,blocks:_(c.blocks)}:c))};try{let _=!1;await Ae(n,{mode:"coding",skillNames:B.length>0?B:void 0,documentId:t.documentId,workingMarkdown:s,baseMarkdown:p,signal:d.signal,onEvent:a=>{a.type==="text_delta"?$(c=>We(c,a.text)):a.type==="thinking_delta"?$(c=>ze(c,a.text)):a.type==="markdown_set"?g(a.markdown):a.type==="tool_notice"?$(c=>Z(c,a.text)):a.type==="document_table"?$(c=>Z(c,a.title)):a.type==="document_card"?$(c=>Z(c,`读取文档「${a.title}」`)):a.type==="sources"?a.items.length>0&&$(c=>Z(c,`已阅读 ${a.items.length} 个手册页面`)):a.type==="skill_form_card"?$(c=>[...c,{type:"skill_form_card",requestId:a.requestId,mode:a.mode,title:a.title,currentName:a.currentName,initialName:a.initialName,initialDescription:a.initialDescription,initialBody:a.initialBody,expiresAt:a.expiresAt,status:"open"}]):a.type==="choice_card"?(b.current=!0,$(c=>[...c,{type:"choice_card",requestId:a.requestId,title:a.title,options:a.options,expiresAt:a.expiresAt,status:"open"}])):a.type==="choice_expired"?$(c=>c.map(P=>P.type==="choice_card"&&P.requestId===a.requestId&&P.status==="open"?{...P,status:"expired"}:P)):a.type==="skill_form_expired"?$(c=>c.map(P=>P.type==="skill_form_card"&&P.requestId===a.requestId&&P.status==="open"?{...P,status:"expired"}:P)):a.type==="error"&&(_=!0,E(a.message))}}),!d.signal.aborted&&!_&&K([]),Q()}catch(_){d.signal.aborted||E(_ instanceof Error?_.message:String(_))}finally{f.current===d&&(f.current=null),J(!1)}}async function ke(){let n=s;if(ie.length>0){if(!window.confirm(`还有 ${ie.length} 段未审阅,将全部接受后写回。继续?`))return;n=r??s,i(n),g(null)}l(!0);const d=!t.documentId;try{const u=await t.onComplete({markdown:n,documentId:t.documentId,displayName:y.trim()||"未命名"}),H=u&&typeof u=="object"&&typeof u.documentId=="string"?u.documentId.trim():"";if(d&&H&&j)try{await Ie(j,H)}catch{}t.onClose()}catch(u){if(u!=null&&u.silent||u instanceof Error&&u.message==="cancelled")return;E(u instanceof Error?u.message:String(u))}finally{l(!1)}}function ye(){var n;(s!==p||r!=null)&&!window.confirm("取消帮写?未写回的修改将丢失。")||((n=f.current)==null||n.abort(),t.onClose())}return e.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[e.jsxs("header",{className:"mdocs-ai-write-header",children:[e.jsxs("div",{className:"mdocs-ai-write-header-left",children:[e.jsx("img",{src:Se,alt:"",className:"mdocs-ai-write-title-logo"}),e.jsx("strong",{children:"帮写"}),e.jsx("input",{className:"mdocs-ai-write-title",value:y,onChange:n=>S(n.target.value),"aria-label":"文档标题"})]}),e.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[e.jsx("button",{type:"button",onClick:ye,disabled:G,children:"取消"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void ke(),disabled:G,children:G?"写回中…":"完成并写回"})]})]}),e.jsxs("div",{className:"mdocs-ai-write-body",children:[e.jsxs("section",{className:"mdocs-ai-write-chat",children:[e.jsxs("div",{className:"mdocs-ai-write-chat-toolbar",children:[e.jsx("span",{className:"mdocs-ai-write-chat-toolbar-label",children:"对话"}),e.jsxs("div",{className:"mdocs-ai-write-chat-toolbar-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:v,onClick:()=>void ge(),children:e.jsx(_e,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(h?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>C(n=>!n),children:e.jsx(Te,{size:16,strokeWidth:1.8})})]})]}),h?e.jsxs("div",{className:"mdocs-ai-write-history mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>C(!1),children:"返回对话"})]}),M?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):R.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):e.jsx("ul",{className:"mdocs-agent-panel-history-list",children:R.map(n=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(n.id===j?" active":""),disabled:v,onClick:()=>void pe(n.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:n.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:Ge(n.updatedAt)})]})},n.id))})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-ai-write-chat-scroll-wrap",children:[e.jsx("div",{className:"mdocs-ai-write-chat-messages",ref:N,onScroll:fe,children:k.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-ai-write-hint",children:"描述你想写或改的内容。助手可读取右侧当前稿与进场快照,再更新提案;请按段接受或拒绝后完成写回。"}),se?e.jsx(re,{onConfigured:ne}):null]}):k.map(n=>e.jsx("div",{className:"mdocs-ai-write-msg"+(n.role==="user"?" mdocs-ai-write-msg-user":""),children:n.role==="user"?e.jsxs(e.Fragment,{children:[n.skillNames&&n.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",n.skillNames.length]}):null,n.content]}):Je(n.blocks)?e.jsx("div",{className:"mdocs-ai-write-timeline",children:n.blocks.map((d,u)=>d.type==="thinking"?d.text?e.jsxs("details",{className:"mdocs-ai-write-thinking",open:v,children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-ai-write-thinking-body",children:d.text})]},`${n.id}-think-${u}`):null:d.type==="tool"?e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:d.text},`${n.id}-tool-${u}`):d.type==="skill_form_card"?e.jsx($e,{block:d,onResolved:(H,$,O)=>{x(_=>_.map(a=>a.id!==n.id||a.role!=="assistant"?a:{...a,blocks:a.blocks.map(c=>c.type==="skill_form_card"&&c.requestId===H?{...c,status:$,submittedName:$==="submitted"?O:c.submittedName}:c)}))}},`${n.id}-sf-${u}`):d.type==="choice_card"?e.jsx(Pe,{block:d,onResolved:(H,$,O)=>{x(_=>_.map(a=>a.id!==n.id||a.role!=="assistant"?a:{...a,blocks:a.blocks.map(c=>c.type==="choice_card"&&c.requestId===H?{...c,status:O,selected:O==="selected"?$:c.selected}:c)}))}},`${n.id}-ch-${u}`):d.type==="text"&&d.text?e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(qe,{remarkPlugins:[Le],children:d.text})},`${n.id}-text-${u}`):null)}):v?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null},n.id))}),L?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:xe,title:"回到底部","aria-label":"回到底部",children:[e.jsx(Re,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),V?e.jsx("p",{className:"mdocs-ai-write-error",children:V}):null,se&&k.length>0?e.jsx(re,{onConfigured:ne}):null,e.jsxs("div",{className:"mdocs-ai-write-input-row",children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:[e.jsx(Ee,{selectedNames:B,onChange:K,disabled:v||!(I!=null&&I.enabled)}),e.jsx("textarea",{rows:2,value:q,disabled:v||!(I!=null&&I.enabled),placeholder:I!=null&&I.enabled?"说说要写什么…":"请先配置 API Key",onChange:n=>A(n.target.value),onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),ae())}})]}),e.jsx("button",{type:"button",className:v?"mdocs-ai-write-stop":void 0,disabled:v?!1:!(I!=null&&I.enabled),onClick:()=>{var n;if(v){(n=f.current)==null||n.abort();return}ae()},children:v?"停止":"发送"})]})]})]}),e.jsx(Oe,{currentMd:s,proposedMd:r,sending:v,onCurrentChange:i,onProposedChange:g})]})]})}export{tt as AiWriteWorkbench};
@@ -1,21 +0,0 @@
1
- import{n as d,b as C,F as N,P as v,o as g,l as x,E as D,p as M,S as E,R as P,M as B}from"./index-vbUbFD-2.js";import{r as I,j as a}from"./react-vendor-BuABiQkA.js";import{g as S}from"./file-type-policy-GUk904tm.js";/**
2
- * @license lucide-react v0.562.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const w=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],A=d("chevron-up",w);/**
7
- * @license lucide-react v0.562.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const W=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M6.376 18.91a6 6 0 0 1 11.249.003",key:"hnjrf2"}],["circle",{cx:"12",cy:"11",r:"4",key:"1gt34v"}]],H=d("shield-user",W);/**
12
- * @license lucide-react v0.562.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const z=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],O=d("text-align-justify",z);/**
17
- * @license lucide-react v0.562.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const R=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],L=d("users",R);function $(e){const{t,lang:m}=C(),l=S(e.fileType||"md"),k=!!(l!=null&&l.aiWrite&&e.onAiWrite),j=!!(l!=null&&l.comments&&e.onToggleComments);e.canEdit&&(e.editing||e.actionsAlwaysVisible);const[o,f]=I.useState(!1),r=e.domains.length?e.domains:[N],s="mdocs-editor-toolbar"+(e.readerChrome?e.readerHeaderDocked?" mdocs-editor-toolbar--docked":" mdocs-editor-toolbar--float":""),c=e.readerChrome&&!e.readerHeaderDocked&&e.readerDragOffset?{transform:`translateY(${e.readerDragOffset}px)`}:void 0;if(e.readerChrome){const n=a.jsxs("div",{className:"mdocs-editor-toolbar-leading",onPointerDown:e.onReaderHeaderPointerDown,onPointerMove:e.onReaderHeaderPointerMove,onPointerUp:e.onReaderHeaderPointerUp,onPointerCancel:e.onReaderHeaderPointerUp,children:[a.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>{var i;return(i=e.onOpenMobileNav)==null?void 0:i.call(e)},"aria-label":t("expandSidebar"),children:a.jsx(v,{size:18,strokeWidth:1.75})}),a.jsx("input",{className:"mdocs-editor-title-input",value:e.displayName,onChange:i=>e.onDisplayNameChange(i.target.value),onBlur:e.onDisplayNameBlur,placeholder:t("displayNamePlaceholder"),disabled:!e.editing,readOnly:!e.editing})]}),u=a.jsx(g,{domains:r,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:t("currentDomainAria"),localizeName:i=>x(i,m,t)}),h=e.canEdit&&e.onPublish?a.jsx("button",{type:"button",className:"primary mdocs-reader-action-btn",disabled:e.busy,onClick:()=>{var i,b;e.editing||(i=e.onEnterEdit)==null||i.call(e),(b=e.onPublish)==null||b.call(e)},children:e.busy?t("publishing"):t("publish")}):null,y=e.readerMoreMenu!=null?a.jsxs("div",{ref:e.readerMoreMenuRef,className:"mdocs-reader-more-menu",children:[a.jsx("button",{type:"button",className:"mdocs-reader-more-btn","aria-label":"更多","aria-expanded":e.readerMoreOpen,onClick:()=>{var i;return(i=e.onToggleReaderMore)==null?void 0:i.call(e)},children:a.jsx(D,{size:18,strokeWidth:1.75})}),e.readerMoreOpen?a.jsx("div",{className:"mdocs-reader-more-dropdown card",children:e.readerMoreMenu}):null]}):null;return e.readerActionsCollapsible?a.jsxs("div",{className:s+" mdocs-editor-toolbar--stacked",style:c,children:[a.jsxs("div",{className:"mdocs-reader-top-row",children:[n,a.jsx("button",{type:"button",className:"mdocs-reader-expand-btn",onClick:()=>f(i=>!i),"aria-label":o?"收起操作栏":"展开操作栏",children:a.jsx(A,{size:16,strokeWidth:2,style:{transform:o?"rotate(0deg)":"rotate(180deg)",transition:"transform 0.2s"}})}),y]}),o&&a.jsxs("div",{className:"mdocs-reader-actions-row",children:[u,e.leadingExtra,h,e.trailingExtra]})]}):a.jsxs("div",{className:s,style:c,children:[n,u,e.leadingExtra,h,y,e.trailingExtra]})}return a.jsxs("div",{className:s,style:c,children:[a.jsxs("div",{className:"mdocs-editor-toolbar-leading",children:[a.jsx("input",{className:"mdocs-editor-title-input",value:e.displayName,onChange:n=>e.onDisplayNameChange(n.target.value),onBlur:e.onDisplayNameBlur,placeholder:t("displayNamePlaceholder"),disabled:!e.editing}),a.jsx(g,{domains:r,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:t("currentDomainAria"),localizeName:n=>x(n,m,t)}),k?a.jsxs("button",{type:"button",className:"secondary",onClick:()=>{var n;return(n=e.onAiWrite)==null?void 0:n.call(e)},style:{padding:"4px 10px",whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",gap:6},children:[a.jsx("img",{src:M,alt:"",width:16,height:16,style:{display:"block"}}),"帮写"]}):null,e.leadingExtra]}),a.jsx("span",{className:"mdocs-editor-toolbar-spacer","aria-hidden":!0}),a.jsxs("div",{className:"mdocs-editor-toolbar-trailing",children:[e.onToggleBookmark?a.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var n;return(n=e.onToggleBookmark)==null?void 0:n.call(e)},disabled:e.bookmarkBusy,"data-tooltip":e.isBookmarked?"取消收藏":"收藏",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,opacity:e.bookmarkBusy?.5:1},children:[a.jsx(E,{size:18,strokeWidth:1.5,style:{color:e.isBookmarked?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:e.isBookmarked?"#faad14":"none"}}),e.isBookmarked?a.jsx("span",{children:"已收藏"}):null]}):null,a.jsxs("div",{className:"mdocs-editor-toolbar-actions",children:[e.onSyncClick?a.jsxs("button",{type:"button",className:"mdocs-sync-btn mdocs-tooltip mdocs-tooltip-bottom"+(e.syncBehind?" behind":""),"data-tooltip":e.syncBehind?t("syncBehindHint"):t("syncPull"),onClick:()=>{var n;return void((n=e.onSyncClick)==null?void 0:n.call(e))},style:{display:"flex",alignItems:"center",gap:4},children:[a.jsx(P,{size:16,strokeWidth:1.5}),a.jsx("span",{children:t("syncPull")})]}):null,e.editing?a.jsxs(a.Fragment,{children:[localStorage.getItem("mdocs.autoPublish")!=="true"&&a.jsxs("span",{className:"mdocs-save-indicator",children:[a.jsx("span",{className:"mdocs-save-dot "+(e.busy?"saving":e.draftExists?"unsaved":"saved")}),a.jsx("span",{children:e.busy?t("publishing"):e.draftExists?t("unsaved"):t("published")})]}),e.onPublish?a.jsx("button",{type:"button",className:"primary",disabled:e.busy,onClick:()=>{var n;return(n=e.onPublish)==null?void 0:n.call(e)},children:e.busy?t("publishing"):t("publish")}):null,e.onDelete?a.jsx("button",{type:"button",className:"danger",disabled:e.busy,onClick:()=>{var n;return(n=e.onDelete)==null?void 0:n.call(e)},children:t("delete")}):null]}):null,!e.editing&&e.canEdit&&e.onEnterEdit?a.jsx("button",{type:"button",className:"primary",onClick:()=>{var n;return(n=e.onEnterEdit)==null?void 0:n.call(e)},children:t("edit")}):null,e.trailingExtra,j?a.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var n;return(n=e.onToggleComments)==null?void 0:n.call(e)},"data-tooltip":"评论",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:e.commentPanelOpen?"var(--mdocs-hover-bg, #f0f0f0)":void 0},children:[a.jsx(B,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}}),e.commentCount&&e.commentCount>0?a.jsx("span",{style:{fontSize:"0.85rem"},children:e.commentCount}):null]}):null,e.onToggleDocInfo?a.jsxs("div",{ref:e.docInfoMenuRef,className:"mdocs-tooltip mdocs-tooltip-bottom","data-tooltip":t("docInfo"),style:{position:"relative"},children:[a.jsx("button",{type:"button",className:"secondary",onClick:()=>{var n;return(n=e.onToggleDocInfo)==null?void 0:n.call(e)},style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:a.jsx(O,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}})}),e.docInfoOpen?a.jsx("div",{className:"mdocs-doc-info-dropdown",children:e.docInfoMenu}):null]}):null]})]})]})}export{$ as D,H as S,L as U};
@@ -1 +0,0 @@
1
- import{r as n,j as a}from"./react-vendor-BuABiQkA.js";import{ad as ge}from"./ui-CvA4pq3d.js";import{g as we,u as Ee,a as ye,d as Fe,b as Ue,f as qe,c as Ve,e as We,N as Ye,S as Je,l as $e,r as Ge,h as Ke,i as Xe,D as G,j as Qe,k as Ze,m as ve}from"./index-vbUbFD-2.js";import{z as pe,A as et,m as se,n as tt,o as nt,p as at,r as it,s as rt,t as ot,v as st,x as ct,B as lt,R as ut,a as dt,b as xe,c as mt,d as ft,e as ht,f as gt,g as yt,h as vt,i as xt,w as ce,j as It,O as kt,E as St,q as wt,l as Et,C as bt,D as Mt}from"./react-DCTIdd3e.js";import{H as Ct,a as Dt,b as Rt,M as jt,T as At,S as Nt,W as Pt,o as Tt,c as Ie}from"./Toolbar-D5TrWh7K.js";import{D as Bt,U as Lt,S as Ot}from"./DocChrome-BkDnBqBu.js";import{V as _t}from"./VisitorPickerModal-B0fxKY7g.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./editor-CL03se2B.js";import"./plus-BR1kwsYl.js";import"./check-s9DVK_zH.js";import"./copy-D_-gX8nM.js";import"./file-type-policy-GUk904tm.js";const Ht=48;function K(e){try{const i=e.getDocument("markdown");return typeof i=="string"?i:""}catch{return null}}function zt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function Ft({editor:e,documentId:i,displayName:c,debounceMs:y=1e3,enabled:h=!0,localBaseCommitIdAtEditStart:j,snapshotMeta:E}){const[_,b]=n.useState(!1),[X,A]=n.useState(!1),[Q,v]=n.useState(null),d=n.useRef(null),m=n.useRef(null),x=n.useRef(!1),g=n.useRef(""),I=n.useRef(!1),M=n.useRef(i),Z=n.useRef(c),H=n.useRef(j),N=n.useRef(E);M.current=i,Z.current=c,H.current=j,N.current=E;const S=n.useCallback(async()=>{if(!e)return;if(!g.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const o=zt(e);o!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",M.current,"content preview:",o.slice(0,80)),await we(M.current).execute(()=>Ee({documentId:M.current,content:o,displayName:Z.current,localBaseCommitIdAtEditStart:H.current,snapshotMeta:N.current})),g.current=K(e)??g.current,A(!0),b(!1),v(Date.now()),x.current=!0,I.current=!1)},[e]);n.useEffect(()=>{let o=!1;return ye(i).then(f=>{o||(f?(A(!0),v(f.updatedAt),x.current=!0):(A(!1),v(null),x.current=!1,I.current=!1))}),()=>{o=!0}},[i]),n.useEffect(()=>{var B,L;if(!h){(B=m.current)==null||B.call(m),m.current=null;return}if(!e)return;const o=e.getLexicalEditor();if(!o)return;(L=m.current)==null||L.call(m);let f=!1,w=0,z=0;const k=()=>{if(f)return;const C=K(e);if(C===null){if(z+=1,z>Ht)return;w=requestAnimationFrame(k);return}g.current=C;const te=o.registerUpdateListener(()=>{const O=K(e);O!==null&&O!==g.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",i,"oldLen:",g.current.length,"newLen:",O.length),g.current=O,b(!0),I.current=!0,x.current=!1,d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,S()},y))});m.current=()=>{te(),d.current&&(clearTimeout(d.current),d.current=null)}};return queueMicrotask(()=>{f||(w=requestAnimationFrame(k))}),()=>{var C;f=!0,cancelAnimationFrame(w),(C=m.current)==null||C.call(m)}},[h,e,i,c,y,j,E,S]),n.useEffect(()=>{var w;if(!h||!e)return;const o=(w=e.getLexicalEditor())==null?void 0:w.getRootElement();if(!o)return;const f=()=>{d.current&&(clearTimeout(d.current),d.current=null),I.current&&S()};return o.addEventListener("blur",f),()=>o.removeEventListener("blur",f)},[h,e,S]),n.useEffect(()=>{if(!h)return;const o=()=>{document.visibilityState==="hidden"&&(d.current&&(clearTimeout(d.current),d.current=null),I.current&&S())},f=()=>{I.current&&(d.current&&(clearTimeout(d.current),d.current=null),S())};return document.addEventListener("visibilitychange",o),window.addEventListener("beforeunload",f),()=>{document.removeEventListener("visibilitychange",o),window.removeEventListener("beforeunload",f)}},[h,S]);async function p(){await Fe(i),A(!1),b(!1),I.current=!1,x.current=!1,g.current=""}async function W(){const o=await ye(i);return o?o.content:null}function ee(){A(!0),b(!1),I.current=!1,v(Date.now()),x.current=!0,e&&(g.current=K(e)??"")}return{isDirty:_,draftExists:X,lastSavedAt:Q,clearDraft:p,loadDraftContent:W,markDraftSaved:ee}}function Ut({isDirty:e,draftExists:i}){const c=e&&!i;n.useEffect(()=>{if(!c)return;const y=h=>{h.preventDefault()};return window.addEventListener("beforeunload",y),()=>window.removeEventListener("beforeunload",y)},[c])}function le(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const ke='{"root":{"direction":"ltr","format":"","indent":0,"version":1,"type":"root","children":[{"direction":"ltr","format":"","indent":0,"version":1,"textFormat":0,"textStyle":"","children":[],"type":"paragraph"}]}}';function Se(e){const c=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(c)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(c)?"不支持的文件类型":/^not an image$/i.test(c)?"不是有效的图片文件":c||"上传失败"}function qt(e,i){if(!e)return i==="json"?ke:e;if(i!=="json")return e;try{const c=JSON.parse(e);if(c!=null&&c.root&&Array.isArray(c.root.children)&&c.root.children.length===0)return ke}catch{}return e}function Vt({editor:e}){const{visible:i}=bt();return a.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:i?200:0},children:a.jsx("div",{style:{width:200},children:a.jsx(Mt,{editor:e})})})}function rn(e){const{t:i,lang:c}=Ue(),[y,h]=n.useState(!1),[j,E]=n.useState(!1),_=n.useRef(null),b=n.useRef(null),[X,A]=n.useState([]),[Q,v]=n.useState(!1),[d,m]=n.useState(e.meta.permission),[x,g]=n.useState(!1),[I,M]=n.useState(!1),[Z,H]=n.useState(!1),[N,S]=n.useState(new Map),[p,W]=n.useState(!1);n.useEffect(()=>{const t=r=>{_.current&&!_.current.contains(r.target)&&h(!1),b.current&&!b.current.contains(r.target)&&E(!1)};return(y||j)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[y,j]),n.useEffect(()=>{let t=!0;return qe().then(r=>{t&&A(r)}).catch(()=>{}),()=>{t=!1}},[]);function ee(t){const r=X.find(l=>l.visitorId===t);return(r==null?void 0:r.visitorName)??t.slice(0,8)}const[o,f]=n.useState(e.initialDisplayName),[w,z]=n.useState(!1),[k,B]=n.useState(!1),[L,C]=n.useState(!1),[te,O]=n.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),ne=e.canEdit&&te,[u,ue]=n.useState(null),[be,de]=n.useState(!1),ae=n.useRef(null);n.useLayoutEffect(()=>{de(!1),ue(null),ae.current=null},[e.meta.documentId]),n.useEffect(()=>{const t=requestAnimationFrame(()=>de(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]);const D=n.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const r=JSON.parse(e.initialContent);return Array.isArray((t=r==null?void 0:r.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),F=n.useMemo(()=>qt(e.initialContent||"",D),[e.initialContent,D,e.contentRevision]),{isDirty:me,draftExists:Y,markDraftSaved:Me}=Ft({editor:u,documentId:e.meta.documentId,displayName:o,enabled:e.canEdit,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}});n.useEffect(()=>{var t;(t=e.onDraftExistsChange)==null||t.call(e,Y)},[Y,e.onDraftExistsChange]),Ut({isDirty:me,draftExists:Y}),n.useEffect(()=>{if(u)try{u.setDocument(D,F)}catch{}},[u,e.meta.documentId,e.contentRevision,F,D]),n.useEffect(()=>{u==null||u.setLocale(c==="zh"?pe:et)},[u,c]),n.useEffect(()=>{f(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),n.useEffect(()=>{m(e.meta.permission)},[e.meta.permission,e.meta.documentId]),n.useEffect(()=>{let t=!0;return(async()=>{try{const r=await Ve(e.meta.documentId);t&&B(r.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function ie(){var t,r;if(!L){C(!0);try{k?(await Ge(e.meta.documentId),B(!1),(t=e.onShowToast)==null||t.call(e,i("bookmarkRemoved"))):(await Ke(e.meta.documentId),B(!0),(r=e.onShowToast)==null||r.call(e,i("bookmarkAdded")))}finally{C(!1)}}}n.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=Te),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),n.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ae.current;if(!t)return"";try{const r=t.getDocument("markdown");return typeof r=="string"?r:String(r??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function Ce(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const De=n.useCallback(t=>{ae.current=t,ue(t);const r=F;if(!r)return;const l=()=>{try{t.setDocument(D,r)}catch{requestAnimationFrame(()=>{try{t.setDocument(D,r)}catch{}})}};queueMicrotask(()=>{queueMicrotask(l)})},[D,F]);async function fe(){if(!(!u||!e.canEdit)){z(!0);try{const t=le(u);if(!t)return;await e.onPublish(t,o,e.meta.documentId)}catch(t){throw t}finally{z(!1)}}}async function Re(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(o.trim()!==t)try{await fe()}catch{}}const R=n.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),je=n.useMemo(()=>{const t=(R==null?void 0:R.permission)??"public";return We(t)},[R==null?void 0:R.permission]);function Ae(t){return t===G.PRIVATE?i("permissionPrivate"):t===G.DOMAIN_READ?i("permissionInvite"):t===G.DOMAIN_WRITE?i("permissionDomainWrite"):t===G.PUBLIC_READ?i("permissionPublicRead"):i("permissionPublicEdit")}async function Ne(){var t;if(x||d===e.meta.permission){v(!1);return}g(!0);try{const l=(u?le(u):null)??e.initialContent;await e.onPublish(l,o,e.meta.documentId,d),v(!1),(t=e.onShowToast)==null||t.call(e,i("docInfoPermissionUpdated"))}finally{g(!1)}}async function Pe(t){var r;if(!p){W(!0);try{const l=new Set(t.map(s=>s.visitorId)),T=new Map(t.map(s=>[s.visitorId,s.permission]));for(const[s]of N)l.has(s)||await Qe(e.meta.documentId,s);for(const{visitorId:s,permission:q}of t){const V=N.get(s);(!V||V!==q)&&await Ze(e.meta.documentId,s,q)}M(!1),(r=e.onShowToast)==null||r.call(e,i("docInfoInviteSuccess",{count:t.length}))}finally{W(!1)}}}async function Te(){if(!u||!e.canEdit)return;if(!me){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=le(u);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),Me(),await we(e.meta.documentId).execute(()=>Ee({documentId:e.meta.documentId,content:t,displayName:o,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const Be=n.useMemo(()=>[{icon:Ct,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(se,{tag:"h1"})}},{icon:Dt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(se,{tag:"h2"})}},{icon:Rt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(se,{tag:"h3"})}},{type:"divider"},{icon:jt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(tt,{})}},{icon:At,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(nt,{columns:"3",rows:"3"})}},{icon:Nt,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(at,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{Tt(r=>{for(const l of r)t.dispatchCommand(wt,{file:l})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(it,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(rt,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(ot,void 0),queueMicrotask(()=>t.focus())}},{icon:Pt,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(st,void 0),queueMicrotask(()=>t.focus())}},{icon:Ye,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ct,void 0),queueMicrotask(()=>t.focus())}}].map(t=>"type"in t&&t.type==="divider"?t:{...t,extra:a.jsx("span",{style:{color:"var(--mdocs-text-muted)",fontFamily:"monospace",fontSize:12},children:t.key})}),[]),Le=n.useMemo(()=>[lt,ut,dt,xe,mt,ft,ht,gt,yt,vt,xt,ce(It,{children:u?a.jsx(Ie,{editor:u,floating:!0,outlineCollapseTitle:i("outlineHide"),outlineExpandTitle:i("outlineShow"),outlineToggle:!0}):null}),ce(Et,{handleUpload:async t=>{var r;try{return{url:await ve(t,e.meta.documentId)}}catch(l){throw(r=e.onShowError)==null||r.call(e,Se(l)),l}}}),ce(xe,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var r;try{const T=await(await fetch(t)).blob(),s=new File([T],"image.png",{type:T.type});return{url:await ve(s,e.meta.documentId)}}catch(l){throw(r=e.onShowError)==null||r.call(e,Se(l)),l}}})],[u,i,e.meta.documentId,e.onShowError]),P=!!e.readerChrome,[U,re]=n.useState(!1),J=n.useRef(null),[Oe,oe]=n.useState(0);n.useEffect(()=>{if(!P){re(!1),oe(0);return}if(U)return;const t=window.setTimeout(()=>re(!0),2800);return()=>window.clearTimeout(t)},[P,U,e.meta.documentId]),n.useEffect(()=>{E(!1),h(!1)},[e.meta.documentId]);function _e(t){!P||U||t.target.closest("button, a, input, textarea, select")||(J.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function He(t){const r=J.current;if(!(r!=null&&r.dragging))return;const l=t.clientY-r.startY;oe(Math.max(-72,Math.min(0,l)))}function ze(t){const r=J.current;if(!(r!=null&&r.dragging))return;J.current=null;const l=t.clientY-r.startY;oe(0),l<-36&&re(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function $(){h(!1),E(!1)}function he(t,r){const l=(r==null?void 0:r.includeBookmark)??!0,T={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoCreator")}),a.jsx("span",{children:ee(e.meta.ownerVisitorId)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoCreatedAt")}),a.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(c==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoSize")}),a.jsx("span",{children:Ce(new Blob([e.initialContent]).size)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoUpdatedAt")}),a.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(c==="zh"?"zh-CN":"en-US")})]})]}),a.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),l?a.jsxs("button",{type:"button",style:T,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{ie(),t()},children:[a.jsx("span",{children:k?"⭐":"☆"}),a.jsx("span",{children:i(k?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?a.jsxs("button",{type:"button",style:T,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{H(!0);try{const s=await Xe(e.meta.documentId),q=new Map(s.map(V=>[V.visitorId,V.permission]));S(q),M(!0)}finally{H(!1)}})()},children:[a.jsx(Lt,{size:14}),a.jsx("span",{children:i("docInfoInviteMember")})]}):null,a.jsxs("button",{type:"button",style:T,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),m(e.meta.permission),v(!0)},children:[a.jsx(Ot,{size:14}),a.jsx("span",{children:i("docInfoChangePermission")})]})]})}return a.jsxs("div",{className:"mdocs-editor"+(P?" mdocs-editor--reader":"")+(P&&U?" mdocs-editor--reader-docked":""),children:[a.jsx(Bt,{fileType:e.meta.fileType||"md",displayName:o,onDisplayNameChange:f,onDisplayNameBlur:()=>void Re(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:ne,onEnterEdit:()=>O(!0),onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:w,draftExists:Y,onPublish:()=>{fe().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:k,bookmarkBusy:L,onToggleBookmark:()=>void ie(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:he($),docInfoOpen:y,onToggleDocInfo:()=>h(!y),docInfoMenuRef:_,readerChrome:P,onOpenMobileNav:e.onOpenMobileNav,readerHeaderDocked:U,readerDragOffset:Oe,onReaderHeaderPointerDown:_e,onReaderHeaderPointerMove:He,onReaderHeaderPointerUp:ze,readerMoreOpen:j,onToggleReaderMore:()=>E(t=>!t),readerMoreMenuRef:b,readerMoreMenu:a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:L,onClick:()=>{ie(),$()},children:[a.jsx(Je,{size:16,strokeWidth:1.5,style:{color:k?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:k?"#faad14":"none"}}),a.jsx("span",{children:i(k?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?a.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:w,onClick:()=>{$(),e.onDelete()},children:a.jsx("span",{children:i("delete")})}):null,a.jsx("div",{className:"mdocs-reader-more-divider"}),he($,{includeBookmark:!1})]})}),Q&&a.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&v(!1)},children:a.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[a.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:i("docInfoChangePermission")}),a.jsxs("div",{className:"muted",style:{marginBottom:12},children:[i("domainPermission"),":",R?$e(R.domainName,c,i):e.meta.domainId]}),a.jsx("div",{style:{display:"grid",gap:8},children:je.map(t=>a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[a.jsx("input",{type:"radio",name:"doc-permission",value:t,checked:d===t,onChange:()=>m(t)}),a.jsx("span",{children:Ae(t)})]},t))}),a.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[a.jsx("button",{type:"button",onClick:()=>v(!1),children:i("cancel")}),a.jsx("button",{type:"button",className:"primary",disabled:x,onClick:()=>void Ne(),children:i(x?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&a.jsx(_t,{open:I,title:i("docInfoInviteMember"),initialSelectedIds:[...N.keys()],initialPermissions:N,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:i("invitePermissionRead")},{value:"edit",label:i("invitePermissionEdit")}],onClose:()=>M(!1),onConfirm:t=>{Pe(t)}}),a.jsx(kt,{children:a.jsx(ge,{flex:1,style:{minHeight:0},children:a.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[ne&&u&&!P?a.jsx(Ie,{editor:u,outlineCollapseTitle:i("outlineHide"),outlineExpandTitle:i("outlineShow"),outlineToggle:!0}):null,a.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:a.jsxs(ge,{variant:"outlined",horizontal:!0,style:{background:"var(--mdocs-surface)",flex:1,minHeight:0,minWidth:0,borderRadius:0,outline:"none"},children:[a.jsx("div",{className:"mdocs-editor-scroll-host",children:be?a.jsx(St,{content:F,type:D,confirmPasteMarkdown:!0,editable:ne,onInit:De,plugins:Le,lineEmptyPlaceholder:i("displayNamePlaceholder"),placeholder:i("displayNamePlaceholder"),slashOption:{items:Be},className:"mdocs-document-editor-root"},e.meta.documentId):null}),u&&a.jsx(Vt,{editor:u})]})})]})})})]})}export{rn as DocumentEditor};
@@ -1 +0,0 @@
1
- import{r as a,j as n}from"./react-vendor-BuABiQkA.js";import{b as me,f as ue,c as fe,g as he,u as xe,e as ve,S as ge,l as ye,r as be,h as ke,i as je,D as k,j as Ce,k as Ie}from"./index-vbUbFD-2.js";import{D as we,U as De,S as Se}from"./DocChrome-BkDnBqBu.js";import{V as Ne}from"./VisitorPickerModal-B0fxKY7g.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./file-type-policy-GUk904tm.js";function Oe(e){const{t:i,lang:j}=me(),r=e.meta.documentId,[h,C]=a.useState(e.initialContent),[u,I]=a.useState(e.initialDisplayName),[c,v]=a.useState(!0),[F,W]=a.useState(!1),[q,H]=a.useState(!1),[m,w]=a.useState(!1),[D,$]=a.useState(!1),[g,S]=a.useState(!1),[N,E]=a.useState(!1),[G,J]=a.useState([]),[X,x]=a.useState(!1),[M,P]=a.useState(e.meta.permission),[B,_]=a.useState(!1),[Z,A]=a.useState(!1),[y,p]=a.useState(new Map),R=a.useRef(null),T=a.useRef(null),d=a.useRef(null),z=a.useRef(h),O=a.useRef(u);z.current=h,O.current=u;const ee=e.canEdit&&!c;a.useEffect(()=>{C(e.initialContent),I(e.initialDisplayName),v(!0)},[r]),a.useEffect(()=>{e.contentRevision&&(C(e.initialContent),I(e.initialDisplayName))},[e.contentRevision]),a.useEffect(()=>{let t=!0;return ue().then(s=>{t&&J(s)}).catch(()=>{}),()=>{t=!1}},[]),a.useEffect(()=>{let t=!0;return fe(r).then(s=>{t&&w(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),a.useEffect(()=>{P(e.meta.permission)},[e.meta.permission,r]),a.useEffect(()=>{const t=s=>{R.current&&!R.current.contains(s.target)&&S(!1),T.current&&!T.current.contains(s.target)&&E(!1)};return(g||N)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[g,N]);const V=a.useCallback(async()=>{var t;await he(r).execute(()=>xe({documentId:r,content:z.current,displayName:O.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),H(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),K=a.useCallback(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{V()},1e3)},[V]);a.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);async function L(t){var s;if(e.canEdit){W(!0);try{d.current&&(clearTimeout(d.current),d.current=null),await V(),await e.onPublish(z.current,O.current.trim()||u,r,t),H(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{W(!1)}}}async function te(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(u.trim()!==t)try{await L()}catch{}}async function U(){var t,s;if(!D){$(!0);try{m?(await be(r),w(!1),(t=e.onShowToast)==null||t.call(e,i("bookmarkRemoved"))):(await ke(r),w(!0),(s=e.onShowToast)==null||s.call(e,i("bookmarkAdded")))}finally{$(!1)}}}function ne(t){const s=G.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function ie(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const l=a.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),ae=a.useMemo(()=>{const t=(l==null?void 0:l.permission)??"public";return ve(t)},[l==null?void 0:l.permission]);function se(t){return t===k.PRIVATE?i("permissionPrivate"):t===k.DOMAIN_READ?i("permissionInvite"):t===k.DOMAIN_WRITE?i("permissionDomainWrite"):t===k.PUBLIC_READ?i("permissionPublicRead"):i("permissionPublicEdit")}async function oe(){if(B||M===e.meta.permission){x(!1);return}_(!0);try{await L(M),x(!1)}finally{_(!1)}}async function re(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of y)s.has(o)||await Ce(r,o);for(const o of t)y.get(o.visitorId)!==o.permission&&await Ie(r,o.visitorId,o.permission);A(!1)}function f(){S(!1),E(!1)}function Q(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,b={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoCreator")}),n.jsx("span",{children:ne(e.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoCreatedAt")}),n.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(j==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoSize")}),n.jsx("span",{children:ie(new Blob([h]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(j==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?n.jsxs("button",{type:"button",style:b,onClick:()=>{U(),t()},children:[n.jsx("span",{children:m?"⭐":"☆"}),n.jsx("span",{children:i(m?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:b,onClick:()=>{t(),(async()=>{const ce=await je(r);p(new Map(ce.map(Y=>[Y.visitorId,Y.permission]))),A(!0)})()},children:[n.jsx(De,{size:14}),n.jsx("span",{children:i("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:b,onClick:()=>{t(),P(e.meta.permission),x(!0)},children:[n.jsx(Se,{size:14}),n.jsx("span",{children:i("docInfoChangePermission")})]})]})}const de=a.useCallback(t=>{var o;const s=t.target.value;C(s),(o=e.onContentChange)==null||o.call(e,s),K()},[e,K]),le=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${h}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(we,{fileType:"html",displayName:u,onDisplayNameChange:I,onDisplayNameBlur:()=>void te(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:ee,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:F,draftExists:q,onPublish:()=>{L().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:m,bookmarkBusy:D,onToggleBookmark:()=>void U(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:Q(f),docInfoOpen:g,onToggleDocInfo:()=>S(!g),docInfoMenuRef:R,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:N,onToggleReaderMore:()=>E(t=>!t),readerMoreMenuRef:T,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:D,onClick:()=>{U(),f()},children:[n.jsx(ge,{size:16,strokeWidth:1.5,style:{color:m?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:m?"#faad14":"none"}}),n.jsx("span",{children:i(m?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!c,onClick:()=>{v(!1),f()},children:i("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:c,onClick:()=>{v(!0),f()},children:i("preview")}),n.jsx("div",{className:"mdocs-reader-more-divider"}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:F,onClick:()=>{f(),e.onDelete()},children:n.jsx("span",{children:i("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),Q(f,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":i(c?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:c,onChange:()=>v(t=>!t)}),n.jsxs("span",{className:"mdocs-editor-mode-toggle-slider",children:[n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--left",children:i("edit")}),n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--right",children:i("preview")})]})]}):null}),n.jsxs("div",{className:"mdocs-html-editor-body",children:[!c&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:h,onChange:de,spellCheck:!1,placeholder:"在此处编写 HTML 代码"}):null,n.jsx("div",{className:"mdocs-html-editor-preview",style:!c&&e.canEdit?{width:"50%"}:{width:"100%"},children:n.jsx("iframe",{className:"mdocs-html-editor-iframe",srcDoc:le,sandbox:"",title:u})})]}),X&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&x(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:i("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[i("domainPermission"),":",l?ye(l.domainName,j,i):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:ae.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"html-doc-permission",value:t,checked:M===t,onChange:()=>P(t)}),n.jsx("span",{children:se(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>x(!1),children:i("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:B,onClick:()=>void oe(),children:i(B?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Ne,{open:Z,title:i("docInfoInviteMember"),initialSelectedIds:[...y.keys()],initialPermissions:y,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:i("invitePermissionRead")},{value:"edit",label:i("invitePermissionEdit")}],onClose:()=>A(!1),onConfirm:t=>{re(t)}})]})}export{Oe as HtmlEditor};