@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,11 +1,11 @@
1
- import{n as E,a6 as L,az as D,av as _,aA as F}from"./index-vbUbFD-2.js";import{r as a,j as e}from"./react-vendor-BuABiQkA.js";/**
1
+ import{o as E,a8 as L,aB as D,ax as _,aC as B}from"./index-OmOf_og0.js";import{r as a,j as e}from"./react-vendor-BuABiQkA.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const $=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],X=E("arrow-down",$);/**
6
+ */const F=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],X=E("arrow-down",F);/**
7
7
  * @license lucide-react v0.562.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const B=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],K=E("history",B),j=5;function P(i){const t=a.useRef(!0),r=a.useRef(null),[d,k]=a.useState([]),[u,p]=a.useState(!1),[h,v]=a.useState(null);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const s=await L();if(!t.current)return;k(s)}catch(s){if(!t.current)return;v(s instanceof Error?s.message:String(s))}})()},[]),a.useEffect(()=>{if(!u)return;function s(o){const g=r.current;!g||g.contains(o.target)||p(!1)}function n(o){o.key==="Escape"&&p(!1)}return document.addEventListener("mousedown",s),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",s),document.removeEventListener("keydown",n)}},[u]);const c=d.filter(s=>i.selectedNames.includes(s.name));function f(s){if(i.disabled)return;const n=new Set(i.selectedNames);if(n.has(s))n.delete(s);else{if(n.size>=j)return;n.add(s)}i.onChange([...n])}return d.length===0&&!h?null:e.jsxs("div",{className:"mdocs-agent-skill-ref",ref:r,children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-bar",children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-anchor",children:[u&&d.length>0?e.jsxs("div",{className:"mdocs-agent-skill-popover",role:"listbox","aria-label":"选择 Skill",children:[e.jsxs("div",{className:"mdocs-agent-skill-popover-hint",children:["选择要引用的 Skill(最多 ",j," 个)"]}),e.jsx("ul",{className:"mdocs-agent-skill-popover-list",children:d.map(s=>{const n=i.selectedNames.includes(s.name),o=!n&&i.selectedNames.length>=j;return e.jsx("li",{children:e.jsxs("button",{type:"button",role:"option","aria-selected":n,className:"mdocs-agent-skill-popover-item"+(n?" mdocs-agent-skill-popover-item-on":""),disabled:i.disabled||o,onClick:()=>f(s.name),children:[e.jsx("span",{className:"mdocs-agent-skill-popover-check","aria-hidden":!0,children:n?"✓":""}),e.jsxs("span",{className:"mdocs-agent-skill-popover-text",children:[e.jsx("span",{className:"mdocs-agent-skill-popover-name",children:s.name}),s.description?e.jsx("span",{className:"mdocs-agent-skill-popover-desc",children:s.description}):e.jsx("span",{className:"mdocs-agent-skill-popover-desc mdocs-agent-skill-popover-desc-muted",children:"无简介"})]})]})},s.id)})})]}):null,e.jsxs("button",{type:"button",className:"mdocs-agent-skill-ref-toggle"+(u?" mdocs-agent-skill-ref-toggle-open":""),disabled:i.disabled||d.length===0,onClick:()=>p(s=>!s),"aria-expanded":u,"aria-haspopup":"listbox",title:"引用 Skill",children:["Skill",c.length>0?` · ${c.length}`:""]})]}),c.map(s=>e.jsxs("button",{type:"button",className:"mdocs-agent-skill-chip mdocs-agent-skill-chip-on",disabled:i.disabled,onClick:()=>f(s.name),title:"移除引用",children:[s.name,e.jsx("span",{"aria-hidden":!0,children:" ×"})]},s.name))]}),h?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:h}):null]})}const z=/^[A-Za-z0-9_]+$/;function T(i){const{block:t,onResolved:r}=i,[d,k]=a.useState(t.initialName),[u,p]=a.useState(t.initialDescription),[h,v]=a.useState(t.initialBody),[c,f]=a.useState(!1),[s,n]=a.useState(null),[o,g]=a.useState(1),x=a.useRef(!1),N=a.useRef(r);N.current=r;const m=t.status==="open",b=a.useRef(0);a.useEffect(()=>{if(!m)return;x.current=!1;const l=new Date(t.expiresAt).getTime(),C=Date.now(),y=Math.max(l-C,1);b.current=y,g(1);const S=()=>{const w=l-Date.now(),q=Math.max(0,Math.min(1,w/y));g(q),w<=0&&!x.current&&(x.current=!0,D(t.requestId).catch(()=>{}).finally(()=>{N.current(t.requestId,"expired")}))};S();const I=window.setInterval(S,100);return()=>window.clearInterval(I)},[m,t.expiresAt,t.requestId]);async function R(){if(c||!m)return;const l=d.trim();if(!l){n("名称不能为空");return}if(!z.test(l)){n("名称仅允许英文、数字、下划线");return}if(!h.trim()){n("正文不能为空");return}f(!0),n(null);try{await F(t.requestId,{name:l,description:u.trim(),body:h}),r(t.requestId,"submitted",l)}catch{r(t.requestId,"failed")}finally{f(!1)}}async function A(){if(!(c||!m)){f(!0),n(null),x.current=!0;try{await _(t.requestId),r(t.requestId,"cancelled")}catch{r(t.requestId,"failed")}finally{f(!1)}}}const M=Math.max(0,Math.ceil(o*b.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card mdocs-agent-skill-form-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:t.title}),m?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[M,"s"]}):null]}),m?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(o*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${o})`}})}):null,t.status==="submitted"?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已提交",t.submittedName?`:${t.submittedName}`:""]}):null,t.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,t.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,表单已失效"}):null,t.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,m?e.jsxs("div",{className:"mdocs-agent-skill-form-fields",children:[e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"名称(英文数字下划线)"}),e.jsx("input",{type:"text",value:d,onChange:l=>k(l.target.value),maxLength:64,disabled:c,autoComplete:"off",spellCheck:!1})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"简介"}),e.jsx("input",{type:"text",value:u,onChange:l=>p(l.target.value),maxLength:200,disabled:c})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:h,onChange:l=>v(l.target.value),rows:8,disabled:c})]}),s?e.jsx("p",{className:"mdocs-agent-skill-form-error",children:s}):null,e.jsxs("div",{className:"mdocs-agent-skill-form-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-skill-form-cancel",disabled:c,onClick:()=>void A(),children:"取消"}),e.jsx("button",{type:"button",disabled:c,onClick:()=>void R(),children:c?"提交中…":t.mode==="create"?"创建":"保存"})]})]}):null]})}export{X as A,K as H,T as S,P as a};
11
+ */const $=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],K=E("history",$),j=5;function P(i){const t=a.useRef(!0),r=a.useRef(null),[d,k]=a.useState([]),[u,p]=a.useState(!1),[h,v]=a.useState(null);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const s=await L();if(!t.current)return;k(s)}catch(s){if(!t.current)return;v(s instanceof Error?s.message:String(s))}})()},[]),a.useEffect(()=>{if(!u)return;function s(o){const g=r.current;!g||g.contains(o.target)||p(!1)}function n(o){o.key==="Escape"&&p(!1)}return document.addEventListener("mousedown",s),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",s),document.removeEventListener("keydown",n)}},[u]);const c=d.filter(s=>i.selectedNames.includes(s.name));function f(s){if(i.disabled)return;const n=new Set(i.selectedNames);if(n.has(s))n.delete(s);else{if(n.size>=j)return;n.add(s)}i.onChange([...n])}return d.length===0&&!h?null:e.jsxs("div",{className:"mdocs-agent-skill-ref",ref:r,children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-bar",children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-anchor",children:[u&&d.length>0?e.jsxs("div",{className:"mdocs-agent-skill-popover",role:"listbox","aria-label":"选择 Skill",children:[e.jsxs("div",{className:"mdocs-agent-skill-popover-hint",children:["选择要引用的 Skill(最多 ",j," 个)"]}),e.jsx("ul",{className:"mdocs-agent-skill-popover-list",children:d.map(s=>{const n=i.selectedNames.includes(s.name),o=!n&&i.selectedNames.length>=j;return e.jsx("li",{children:e.jsxs("button",{type:"button",role:"option","aria-selected":n,className:"mdocs-agent-skill-popover-item"+(n?" mdocs-agent-skill-popover-item-on":""),disabled:i.disabled||o,onClick:()=>f(s.name),children:[e.jsx("span",{className:"mdocs-agent-skill-popover-check","aria-hidden":!0,children:n?"✓":""}),e.jsxs("span",{className:"mdocs-agent-skill-popover-text",children:[e.jsx("span",{className:"mdocs-agent-skill-popover-name",children:s.name}),s.description?e.jsx("span",{className:"mdocs-agent-skill-popover-desc",children:s.description}):e.jsx("span",{className:"mdocs-agent-skill-popover-desc mdocs-agent-skill-popover-desc-muted",children:"无简介"})]})]})},s.id)})})]}):null,e.jsxs("button",{type:"button",className:"mdocs-agent-skill-ref-toggle"+(u?" mdocs-agent-skill-ref-toggle-open":""),disabled:i.disabled||d.length===0,onClick:()=>p(s=>!s),"aria-expanded":u,"aria-haspopup":"listbox",title:"引用 Skill",children:["Skill",c.length>0?` · ${c.length}`:""]})]}),c.map(s=>e.jsxs("button",{type:"button",className:"mdocs-agent-skill-chip mdocs-agent-skill-chip-on",disabled:i.disabled,onClick:()=>f(s.name),title:"移除引用",children:[s.name,e.jsx("span",{"aria-hidden":!0,children:" ×"})]},s.name))]}),h?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:h}):null]})}const z=/^[A-Za-z0-9_]+$/;function T(i){const{block:t,onResolved:r}=i,[d,k]=a.useState(t.initialName),[u,p]=a.useState(t.initialDescription),[h,v]=a.useState(t.initialBody),[c,f]=a.useState(!1),[s,n]=a.useState(null),[o,g]=a.useState(1),x=a.useRef(!1),N=a.useRef(r);N.current=r;const m=t.status==="open",b=a.useRef(0);a.useEffect(()=>{if(!m)return;x.current=!1;const l=new Date(t.expiresAt).getTime(),M=Date.now(),y=Math.max(l-M,1);b.current=y,g(1);const S=()=>{const w=l-Date.now(),q=Math.max(0,Math.min(1,w/y));g(q),w<=0&&!x.current&&(x.current=!0,D(t.requestId).catch(()=>{}).finally(()=>{N.current(t.requestId,"expired")}))};S();const I=window.setInterval(S,100);return()=>window.clearInterval(I)},[m,t.expiresAt,t.requestId]);async function R(){if(c||!m)return;const l=d.trim();if(!l){n("名称不能为空");return}if(!z.test(l)){n("名称仅允许英文、数字、下划线");return}if(!h.trim()){n("正文不能为空");return}f(!0),n(null);try{await B(t.requestId,{name:l,description:u.trim(),body:h}),r(t.requestId,"submitted",l)}catch{r(t.requestId,"failed")}finally{f(!1)}}async function A(){if(!(c||!m)){f(!0),n(null),x.current=!0;try{await _(t.requestId),r(t.requestId,"cancelled")}catch{r(t.requestId,"failed")}finally{f(!1)}}}const C=Math.max(0,Math.ceil(o*b.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card mdocs-agent-skill-form-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:t.title}),m?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[C,"s"]}):null]}),m?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(o*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${o})`}})}):null,t.status==="submitted"?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已提交",t.submittedName?`:${t.submittedName}`:""]}):null,t.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,t.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,表单已失效"}):null,t.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,m?e.jsxs("div",{className:"mdocs-agent-skill-form-fields",children:[e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"名称(英文数字下划线)"}),e.jsx("input",{type:"text",value:d,onChange:l=>k(l.target.value),maxLength:64,disabled:c,autoComplete:"off",spellCheck:!1})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"简介"}),e.jsx("input",{type:"text",value:u,onChange:l=>p(l.target.value),maxLength:200,disabled:c})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:h,onChange:l=>v(l.target.value),rows:8,disabled:c})]}),s?e.jsx("p",{className:"mdocs-agent-skill-form-error",children:s}):null,e.jsxs("div",{className:"mdocs-agent-skill-form-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-skill-form-cancel",disabled:c,onClick:()=>void A(),children:"取消"}),e.jsx("button",{type:"button",disabled:c,onClick:()=>void R(),children:c?"提交中…":t.mode==="create"?"创建":"保存"})]})]}):null]})}export{X as A,K as H,T as S,P as a};
@@ -0,0 +1,7 @@
1
+ import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{ay as Se,az as Ie,aw as ve,an as de,ao as Me,q as Ae,ap as ue,a4 as Te,as as Le,aA as Re,at as $e,au as Ee,av as _e}from"./index-OmOf_og0.js";import{H as qe,S as Pe,A as De,a as Be}from"./AgentSkillFormCard-TFpdC5LM.js";import{P as Fe}from"./plus-DKKQ-AoS.js";import{ae as He,af as Ke}from"./ui-CvA4pq3d.js";import"./diagram-Bk84WZto.js";import"./motion-DFABYlwt.js";function Oe(t){const{block:s,onResolved:i}=t,[r,f]=c.useState(""),[g,p]=c.useState(!1),[N,k]=c.useState(1),h=c.useRef(!1),j=c.useRef(i);j.current=i;const u=s.status==="open",E=c.useRef(0);c.useEffect(()=>{if(!u)return;h.current=!1;const m=new Date(s.expiresAt).getTime(),b=Date.now(),P=Math.max(m-b,1);E.current=P,k(1);const $=()=>{const K=m-Date.now(),A=Math.max(0,Math.min(1,K/P));k(A),K<=0&&!h.current&&(h.current=!0,Se(s.requestId).catch(()=>{}).finally(()=>{j.current(s.requestId,"","expired")}))};$();const H=window.setInterval($,100);return()=>window.clearInterval(H)},[u,s.expiresAt,s.requestId]);async function y(m){const b=m.trim();if(!(!b||g||!u)){p(!0);try{await Ie(s.requestId,b),i(s.requestId,b,"selected")}catch{i(s.requestId,b,"failed")}finally{p(!1)}}}async function R(){if(!(g||!u)){p(!0),h.current=!0;try{await ve(s.requestId),i(s.requestId,"","cancelled")}catch{i(s.requestId,"","failed")}finally{p(!1)}}}const F=Math.max(0,Math.ceil(N*E.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(u?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),u?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[F,"s"]}):null]}),u?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(N*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${N})`}})}):null,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,u?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:s.options.map(m=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:g,onClick:()=>void y(m),children:m},m))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:r,disabled:g,placeholder:"或输入自己的内容…",onChange:m=>f(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),y(r))}}),e.jsx("button",{type:"button",disabled:g||!r.trim(),onClick:()=>void y(r),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:g,onClick:()=>void R(),children:"取消"})})]}):null]})}function te(t){return t===""?[]:t.split(`
2
+ `)}function We(t){return t.join(`
3
+ `)}function ne(t,s){const i=te(t),r=te(s),f=i.length,g=r.length,p=Array.from({length:f+1},()=>Array.from({length:g+1},()=>0));for(let y=f-1;y>=0;y--)for(let R=g-1;R>=0;R--)i[y]===r[R]?p[y][R]=p[y+1][R+1]+1:p[y][R]=Math.max(p[y+1][R],p[y][R+1]);const N=[];let k=0,h=0;for(;k<f||h<g;)if(k<f&&h<g&&i[k]===r[h])N.push({kind:"eq",oi:k,ni:h}),k++,h++;else if(h<g&&(k===f||p[k][h+1]>=p[k+1][h]))N.push({kind:"ins",oi:k,ni:h}),h++;else if(k<f)N.push({kind:"del",oi:k,ni:h}),k++;else break;const j=[];let u=0,E=0;for(;u<N.length;){if(N[u].kind==="eq"){u++;continue}const y=N[u].oi,R=N[u].ni,F=[],m=[];let b=y,P=R;for(;u<N.length&&N[u].kind!=="eq";){const $=N[u];$.kind==="del"?(F.push(i[$.oi]),b=$.oi+1):(m.push(r[$.ni]),P=$.ni+1),u++}j.push({id:`h${E++}`,oldStart:y,oldEnd:b,newStart:R,newEnd:P,oldLines:F,newLines:m})}return j}function ze(t,s){const i=te(t);return We([...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 Je(t,s){const i=U(t),r=[];let f=0;return s.forEach((g,p)=>{g.oldStart>f&&r.push({kind:"same",lines:i.slice(f,g.oldStart),key:`s-${f}-${g.oldStart}`}),r.push({kind:"hunk",hunk:g,hunkIndex:p,key:`h-${g.id}-${p}`}),f=g.oldEnd}),f<i.length?r.push({kind:"same",lines:i.slice(f),key:`s-${f}-end`}):s.length===0&&i.length===0&&r.push({kind:"same",lines:[],key:"s-empty"}),r}function Ge(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 me(t,s){const i=[];let r=0,f=0;for(const g of t)if(g.kind==="same"){const p=s.sameTexts[r++]??"";i.push(...U(p))}else{const p=s.newTexts[f++]??"";i.push(...U(p))}return z(i)}function Ue(t){return t.oldLines.length===0?"add":t.newLines.length===0?"del":"mod"}function he(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 Ve(t){const s=!!t.sending,[i,r]=c.useState(0),[f,g]=c.useState(null),[p,N]=c.useState({sameTexts:[],newTexts:[]}),[k,h]=c.useState([]),j=c.useRef(!1),u=c.useRef(!1),E=c.useRef([]),y=c.useRef(p);y.current=p,E.current=k;const R=c.useMemo(()=>t.proposedMd==null||t.proposedMd===t.currentMd?[]:ne(t.currentMd,t.proposedMd),[t.currentMd,t.proposedMd]),F=!s&&(k.length>0?k.some(l=>l.kind==="hunk"):R.length>0);c.useEffect(()=>{if(s){h([]),j.current=!1,u.current=!1;return}if(t.proposedMd==null||t.proposedMd===t.currentMd){h([]),j.current=!1,u.current=!1;return}if(u.current){u.current=!1;return}const l=ne(t.currentMd,t.proposedMd);if(l.length===0){h([]);return}const x=Je(t.currentMd,l);h(x),j.current=!1,N(Ge(x))},[s,t.proposedMd,t.currentMd]);const m=c.useMemo(()=>k.filter(l=>l.kind==="hunk").map(l=>l.hunk),[k]);c.useEffect(()=>{if(m.length===0){r(0);return}r(l=>Math.min(l,m.length-1))},[m.length]);const b=f??i;function P(){return me(E.current,y.current)}function $(){if(!F||E.current.length===0)return t.proposedMd;const l=P();return j.current=!1,l===t.currentMd?(u.current=!1,t.onProposedChange(null),null):(l!==t.proposedMd&&(u.current=!0,t.onProposedChange(l)),l)}function H(l){const x=E.current.find(D=>D.kind==="hunk"&&D.hunk.id===l.id);if(!x)return;const S=y.current.newTexts[x.hunkIndex],I={...l,newLines:S!=null?U(S):l.newLines},v=P();if(j.current=!1,u.current=!1,v===t.currentMd){t.onProposedChange(null);return}const T=ze(t.currentMd,I);t.onCurrentChange(T),v===T?t.onProposedChange(null):t.onProposedChange(v)}function K(l){const x=E.current.find(v=>v.kind==="hunk"&&v.hunk.id===l.id);if(!x)return;const S={sameTexts:y.current.sameTexts.slice(),newTexts:y.current.newTexts.slice()};S.newTexts[x.hunkIndex]=z(l.oldLines);const I=me(E.current,S);j.current=!1,u.current=!1,I===t.currentMd?t.onProposedChange(null):t.onProposedChange(I)}function A(){const l=P();j.current=!1,u.current=!1,t.onCurrentChange(l),t.onProposedChange(null)}function J(){j.current=!1,u.current=!1,t.onProposedChange(null)}function C(l){m.length!==0&&r(x=>{const S=(x+l+m.length)%m.length,I=document.getElementById(`mdocs-ai-hunk-${S}`);return I==null||I.scrollIntoView({block:"center",behavior:"smooth"}),S})}function W(l,x){j.current=!0,N(S=>{const I=S.sameTexts.slice();return I[l]=x,{...S,sameTexts:I}})}function V(l,x){j.current=!0,N(S=>{const I=S.newTexts.slice();return I[l]=x,{...S,newTexts:I}})}const _=m[b]??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?"接收中·编辑我的稿":m.length===0?t.proposedMd?"与提案一致(可编辑)":"Markdown 源码(可编辑)":`${m.length} 处变更(可改提案)`}),!s&&m.length>0?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"mdocs-ai-write-diff-accept-all",onClick:A,children:"全部接受"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-diff-reject-all",onClick:J,children:"全部拒绝"})]}):null]}),F&&k.length>0?e.jsxs("div",{className:"mdocs-ai-write-inline",role:"document",children:[k.map(l=>{if(l.kind==="same"){const T=G++,D=p.sameTexts[T]??z(l.lines);return e.jsx("div",{className:"mdocs-ai-write-inline-same",children:e.jsx(he,{className:"ctx",value:D,"aria-label":"提案相同行",onChange:Z=>W(T,Z),onBlurFlush:()=>$()})},l.key)}const x=l.hunk,S=Ue(x),I=l.hunkIndex===b,v=p.newTexts[l.hunkIndex]??z(x.newLines);return e.jsxs("div",{id:`mdocs-ai-hunk-${l.hunkIndex}`,className:`mdocs-ai-write-inline-hunk mdocs-ai-write-inline-hunk-${S}`+(I?" is-active":""),onMouseEnter:()=>g(l.hunkIndex),onMouseLeave:()=>g(null),onClick:()=>r(l.hunkIndex),children:[e.jsxs("div",{className:"mdocs-ai-write-hunk-hover",hidden:f!==l.hunkIndex,children:[e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:T=>{T.stopPropagation(),K(x)},children:"拒绝"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:T=>{T.stopPropagation(),H(x)},children:"接受"})]}),e.jsx("pre",{className:"mdocs-ai-write-hunk-pre",children:x.oldLines.map((T,D)=>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${D}`))}),x.newLines.length>0||v!==""||S!=="del"?e.jsx(he,{className:"add",value:v,"aria-label":"提案新增行",onChange:T=>V(l.hunkIndex,T),onBlurFlush:()=>$()}):null]},l.key)}),_?e.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"变更导航",children:[e.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>C(-1),children:"↑"}),e.jsxs("span",{children:[b+1," / ",m.length]}),e.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>C(1),children:"↓"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>K(_),children:"拒绝"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>H(_),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 fe=0;function ge(t){return fe+=1,`${t}-${Date.now()}-${fe}`}function Ye(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 Xe(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 Q(t,s){const i=s.trim();return i?[...t,{type:"tool",text:i}]:t}function Qe(t){return t.some(s=>s.type==="text"||s.type==="thinking"?s.text.length>0:!0)}function Ze(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 xe(t,s){return s.map((i,r)=>{const f=`h-${t}-${r}-${i.role}`;if(i.role==="user"){const g=i.skillNames&&i.skillNames.length>0?i.skillNames:i.skillIds&&i.skillIds.length>0?i.skillIds:void 0;return{id:f,role:"user",content:i.content,skillNames:g}}return{id:f,role:"assistant",blocks:i.content?[{type:"text",text:i.content}]:[]}})}function rt(t){const[s,i]=c.useState(t.initialMarkdown),[r,f]=c.useState(null),[g]=c.useState(t.initialMarkdown),[p,N]=c.useState(t.displayName||"未命名"),[k,h]=c.useState([]),[j,u]=c.useState(null),[E,y]=c.useState([]),[R,F]=c.useState(!1),[m,b]=c.useState(!1),[P,$]=c.useState(""),[H,K]=c.useState([]),[A,J]=c.useState(!1),[C,W]=c.useState(null),[V,_]=c.useState(null),[G,l]=c.useState(!1),[x,S]=c.useState(null),I=c.useRef(null),v=c.useRef(null),T=c.useRef(null),D=c.useRef(!0),[Z,ee]=c.useState(!1),se=120;function ie(n){return n.scrollHeight-n.scrollTop-n.clientHeight}function Y(){const n=T.current;n&&(n.scrollTop=n.scrollHeight,ee(!1))}function ke(){D.current&&Y()}function pe(){const n=T.current;if(!n)return;const o=ie(n);D.current=o<=48,ee(o>se)}function ye(){D.current=!0,Y()}c.useLayoutEffect(()=>{if(!t.open)return;ke();const n=T.current;n&&ee(ie(n)>se)},[k,t.open]);async function X(){F(!0);try{const n=await Le("coding",t.documentId);y(n.sessions),j||u(n.lastOpenedSessionId)}catch{}finally{F(!1)}}async function ae(){try{const n=await de();W(n)}catch{W({enabled:!1,skillsReady:!1,model:null})}}if(c.useEffect(()=>{var o;if(!t.open){b(!1),(o=v.current)==null||o.abort();return}i(t.initialMarkdown),f(null),N(t.displayName||"未命名"),$(""),_(null),b(!1);let n=!1;return(async()=>{try{const w=await de();n||W(w)}catch{n||W({enabled:!1,skillsReady:!1,model:null})}try{const w=await Me("coding",t.documentId);if(n)return;u(w.sessionId),h(xe(w.sessionId,w.messages))}catch{n||(u(null),h([]))}X()})(),()=>{n=!0}},[t.open,t.initialMarkdown,t.displayName,t.documentId]),c.useEffect(()=>()=>{var n;return(n=v.current)==null?void 0:n.abort()},[]),c.useEffect(()=>{t.open&&m&&X()},[m,t.open,t.documentId]),!t.open)return null;const le=(C==null?void 0:C.reason)==="missing_api_key",we=r!=null&&r!==s?ne(s,r):[];async function je(){var n;if(!A){(n=v.current)==null||n.abort(),_(null),b(!1),J(!1);try{const o=await $e("coding",t.documentId);u(o.sessionId),h([]),$(""),X()}catch(o){_(o instanceof Error?o.message:String(o))}}}async function Ne(n){var o;if(!A){if(n===j){b(!1);return}(o=v.current)==null||o.abort(),_(null);try{const w=await Ee(n,"coding",t.documentId);u(w.sessionId),h(xe(w.sessionId,w.messages)),$(""),b(!1)}catch(w){_(w instanceof Error?w.message:String(w))}}}async function re(){var O;const n=P.trim();if(!n||A)return;if(!(C!=null&&C.enabled)){_("请先配置 API Key");return}(O=v.current)==null||O.abort();const o=new AbortController;v.current=o;const w=ge("u"),M=ge("a");D.current=!0,h(q=>[...q,{id:w,role:"user",content:n,skillNames:H.length>0?[...H]:void 0},{id:M,role:"assistant",blocks:[]}]),$(""),J(!0),_(null),requestAnimationFrame(()=>{Y(),requestAnimationFrame(Y)});const L=q=>{h(a=>a.map(d=>d.id===M&&d.role==="assistant"?{...d,blocks:q(d.blocks)}:d))};try{let q=!1;await _e(n,{mode:"coding",skillNames:H.length>0?H:void 0,documentId:t.documentId,workingMarkdown:s,baseMarkdown:g,signal:o.signal,onEvent:a=>{a.type==="text_delta"?L(d=>Ye(d,a.text)):a.type==="thinking_delta"?L(d=>Xe(d,a.text)):a.type==="markdown_set"?f(a.markdown):a.type==="tool_notice"?L(d=>Q(d,a.text)):a.type==="document_table"?L(d=>Q(d,a.title)):a.type==="document_card"?L(d=>Q(d,`读取文档「${a.title}」`)):a.type==="sources"?a.items.length>0&&L(d=>Q(d,`已阅读 ${a.items.length} 个手册页面`)):a.type==="skill_form_card"?L(d=>[...d,{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"?(D.current=!0,L(d=>[...d,{type:"choice_card",requestId:a.requestId,title:a.title,options:a.options,expiresAt:a.expiresAt,status:"open"}])):a.type==="choice_expired"?L(d=>d.map(B=>B.type==="choice_card"&&B.requestId===a.requestId&&B.status==="open"?{...B,status:"expired"}:B)):a.type==="skill_form_expired"?L(d=>d.map(B=>B.type==="skill_form_card"&&B.requestId===a.requestId&&B.status==="open"?{...B,status:"expired"}:B)):a.type==="error"&&(q=!0,_(a.message))}}),!o.signal.aborted&&!q&&K([]),X()}catch(q){o.signal.aborted||_(q instanceof Error?q.message:String(q))}finally{v.current===o&&(v.current=null),J(!1)}}function oe(n){return new Promise(o=>{I.current=o,S({message:n.message,confirmLabel:n.confirmLabel??"确定",cancelLabel:n.cancelLabel??"返回",danger:n.danger??!1})})}function ce(n){const o=I.current;I.current=null,S(null),o==null||o(n)}async function be(){if(!await oe({message:"是否回写",confirmLabel:"确认",cancelLabel:"返回"}))return;let o=s;we.length>0&&(o=r??s,i(o),f(null)),l(!0);const w=!t.documentId;try{const M=await t.onComplete({markdown:o,documentId:t.documentId,displayName:p.trim()||"未命名"}),L=M&&typeof M=="object"&&typeof M.documentId=="string"?M.documentId.trim():"";if(w&&L&&j)try{await Re(j,L)}catch{}t.onClose()}catch(M){if(M!=null&&M.silent||M instanceof Error&&M.message==="cancelled")return;_(M instanceof Error?M.message:String(M))}finally{l(!1)}}async function Ce(){var n;(s!==g||r!=null)&&!await oe({message:"取消帮写?未写回的修改将丢失。",confirmLabel:"放弃修改",danger:!0})||((n=v.current)==null||n.abort(),t.onClose())}return e.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[e.jsxs("header",{className:"mdocs-ai-write-header",children:[e.jsxs("div",{className:"mdocs-ai-write-header-left",children:[e.jsx("img",{src:Ae,alt:"",className:"mdocs-ai-write-title-logo"}),e.jsx("strong",{children:"帮写"}),e.jsx("input",{className:"mdocs-ai-write-title",value:p,onChange:n=>N(n.target.value),"aria-label":"文档标题"})]}),e.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[e.jsx("button",{type:"button",onClick:()=>void Ce(),disabled:G||x!=null,children:"取消"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void be(),disabled:G||x!=null,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:A,onClick:()=>void je(),children:e.jsx(Fe,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(m?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>b(n=>!n),children:e.jsx(qe,{size:16,strokeWidth:1.8})})]})]}),m?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:()=>b(!1),children:"返回对话"})]}),R?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):E.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:E.map(n=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(n.id===j?" active":""),disabled:A,onClick:()=>void Ne(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:Ze(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:T,onScroll:pe,children:k.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-ai-write-hint",children:"描述你想写或改的内容。助手可读取右侧当前稿与进场快照,再更新提案;请按段接受或拒绝后完成写回。"}),le?e.jsx(ue,{onConfigured:ae}):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]}):Qe(n.blocks)?e.jsx("div",{className:"mdocs-ai-write-timeline",children:n.blocks.map((o,w)=>o.type==="thinking"?o.text?e.jsxs("details",{className:"mdocs-ai-write-thinking",open:A,children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-ai-write-thinking-body",children:o.text})]},`${n.id}-think-${w}`):null:o.type==="tool"?e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:o.text},`${n.id}-tool-${w}`):o.type==="skill_form_card"?e.jsx(Pe,{block:o,onResolved:(M,L,O)=>{h(q=>q.map(a=>a.id!==n.id||a.role!=="assistant"?a:{...a,blocks:a.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===M?{...d,status:L,submittedName:L==="submitted"?O:d.submittedName}:d)}))}},`${n.id}-sf-${w}`):o.type==="choice_card"?e.jsx(Oe,{block:o,onResolved:(M,L,O)=>{h(q=>q.map(a=>a.id!==n.id||a.role!=="assistant"?a:{...a,blocks:a.blocks.map(d=>d.type==="choice_card"&&d.requestId===M?{...d,status:O,selected:O==="selected"?L:d.selected}:d)}))}},`${n.id}-ch-${w}`):o.type==="text"&&o.text?e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(He,{remarkPlugins:[Ke],children:o.text})},`${n.id}-text-${w}`):null)}):A?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null},n.id))}),Z?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:ye,title:"回到底部","aria-label":"回到底部",children:[e.jsx(De,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),V?e.jsx("p",{className:"mdocs-ai-write-error",children:V}):null,le&&k.length>0?e.jsx(ue,{onConfigured:ae}):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(Be,{selectedNames:H,onChange:K,disabled:A||!(C!=null&&C.enabled)}),e.jsx("textarea",{rows:2,value:P,disabled:A||!(C!=null&&C.enabled),placeholder:C!=null&&C.enabled?"说说要写什么…":"请先配置 API Key",onChange:n=>$(n.target.value),onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),re())}})]}),e.jsx("button",{type:"button",className:A?"mdocs-ai-write-stop":void 0,disabled:A?!1:!(C!=null&&C.enabled),onClick:()=>{var n;if(A){(n=v.current)==null||n.abort();return}re()},children:A?"停止":"发送"})]})]})]}),e.jsx(Ve,{currentMd:s,proposedMd:r,sending:A,onCurrentChange:i,onProposedChange:f})]}),x?e.jsx(Te,{message:x.message,confirmLabel:x.confirmLabel,cancelLabel:x.cancelLabel,danger:x.danger,onConfirm:()=>ce(!0),onCancel:()=>ce(!1)}):null]})}export{rt as AiWriteWorkbench};
@@ -1,2 +1,2 @@
1
- import{Q as I,S as H,T as F,U as O,V as G}from"./react-DCTIdd3e.js";import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-DLBNOz_m.js";import{M as _}from"./meta2d-1-g23JOU.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 q=0;const P=new Set;function $(n){return P.add(n),()=>{P.delete(n)}}function M(){return q}function J(){q++,P.forEach(n=>n())}function z(n){let t=null;try{const[r]=I();t=r}catch{}const i=t;if(!i)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore($,M,M),{setLocale:c.useCallback(r=>{i.setLocale(r),J()},[i]),t:c.useCallback((r,u)=>i.t(r,u),[i])}}const K={Activity:"meta2d.palette.groups.activity",Basic:"meta2d.palette.groups.basic","Fault tree":"meta2d.palette.groups.faultTree",Flow:"meta2d.palette.groups.flow","Sequence & class":"meta2d.palette.groups.sequenceClass"};function W(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function U(){return[{group:"Basic",key:"square",label:"Square",pen:{...s,height:100,name:"square",text:"",width:100}},{group:"Basic",key:"rect",label:"Rectangle",pen:{...s,name:"rectangle",text:"Rectangle"}},{group:"Basic",key:"roundRect",label:"Rounded",pen:{...s,borderRadius:.2,name:"rectangle",text:"Rounded"}},{group:"Basic",key:"circle",label:"Circle",pen:{...s,height:80,name:"circle",text:"Circle",width:80}},{group:"Basic",key:"triangle",label:"Triangle",pen:{...s,height:90,name:"triangle",text:"Triangle",width:100}},{group:"Basic",key:"diamond",label:"Diamond",pen:{...s,height:100,name:"diamond",text:"Decision",width:100}},{group:"Basic",key:"pentagon",label:"Pentagon",pen:{...s,height:100,name:"pentagon",text:"Pentagon",width:100}},{group:"Basic",key:"hexagon",label:"Hexagon",pen:{...s,height:100,name:"hexagon",text:"Hexagon",width:100}},{group:"Basic",key:"pentagram",label:"Star",pen:{...s,height:100,name:"pentagram",text:"",width:100}},{group:"Basic",key:"leftArrow",label:"Left arrow",pen:{height:60,name:"leftArrow",width:120}},{group:"Basic",key:"rightArrow",label:"Right arrow",pen:{height:60,name:"rightArrow",width:120}},{group:"Basic",key:"twowayArrow",label:"Two-way",pen:{height:60,name:"twowayArrow",width:150}},{group:"Basic",key:"cloud",label:"Cloud",pen:{height:100,name:"cloud",width:100}},{group:"Basic",key:"message",label:"Message",pen:{height:100,name:"message",textTop:-.1,width:100}},{group:"Basic",key:"file",label:"File",pen:{height:100,name:"file",width:80}},{group:"Basic",key:"cube",label:"Cube",pen:{height:100,name:"cube",width:60,z:.25}},{group:"Basic",key:"people",label:"Actor",pen:{height:100,name:"people",width:70}},{group:"Basic",key:"text",label:"Text",pen:{...s,background:"transparent",color:"transparent",height:32,name:"text",text:"text",width:120}},{group:"Basic",key:"line",label:"Line",pen:{color:"#1f1f1f",height:1,lineWidth:1,name:"line",width:160}},{group:"Flow",key:"flowTerminal",label:"Terminal",pen:{...s,borderRadius:.5,height:40,name:"rectangle",text:"Start / End",width:120}},{group:"Flow",key:"flowProcess",label:"Process",pen:{...s,height:40,name:"rectangle",text:"Process",width:120}},{group:"Flow",key:"flowDecision",label:"Decision",pen:{...s,height:60,name:"diamond",text:"Decision",width:120}},{group:"Flow",key:"flowData",label:"Data",pen:{...s,name:"flowData",offsetX:.14,text:"Data"}},{group:"Flow",key:"flowPrepare",label:"Prepare",pen:{...s,height:50,name:"hexagon",text:"Prepare",width:120}},{group:"Flow",key:"flowSubprocess",label:"Subprocess",pen:{...s,height:50,name:"flowSubprocess",text:"Subprocess",width:120}},{group:"Flow",key:"flowDb",label:"Database",pen:{...s,height:100,name:"flowDb",text:"DB",width:80}},{group:"Flow",key:"flowDocument",label:"Document",pen:{...s,height:100,name:"flowDocument",text:"Document",width:120}},{group:"Flow",key:"flowInternalStorage",label:"Int. storage",pen:{...s,height:80,name:"flowInternalStorage",text:"Internal",width:120}},{group:"Flow",key:"flowExternStorage",label:"Ext. storage",pen:{...s,height:80,name:"flowExternStorage",text:"External",width:120}},{group:"Flow",key:"flowQueue",label:"Queue",pen:{...s,height:100,name:"flowQueue",text:"Queue",width:100}},{group:"Flow",key:"flowManually",label:"Manual input",pen:{...s,height:80,name:"flowManually",text:"Manual",width:120}},{group:"Flow",key:"flowDisplay",label:"Display",pen:{...s,height:80,name:"flowDisplay",text:"Display",width:120}},{group:"Flow",key:"flowParallel",label:"Parallel",pen:{...s,height:50,name:"flowParallel",text:"Parallel",width:120}},{group:"Flow",key:"flowComment",label:"Comment",pen:{...s,height:100,name:"flowComment",text:"Note",width:100}},{group:"Activity",key:"actStart",label:"Start",pen:{background:"#555",height:30,lineWidth:0,name:"circle",text:"",width:30}},{group:"Activity",key:"actFinal",label:"Final",pen:{height:30,name:"activityFinal",width:30}},{group:"Activity",key:"actStep",label:"Action",pen:{...s,borderRadius:.25,height:50,name:"rectangle",text:"Action",width:120}},{group:"Activity",key:"actMerge",label:"Merge",pen:{...s,height:50,name:"diamond",text:"Merge",width:120}},{group:"Activity",key:"swimlaneV",label:"Swimlane V",pen:{height:500,lineTop:.08,name:"swimlaneV",text:"Swimlane",textBaseline:"top",textTop:20,width:200}},{group:"Activity",key:"swimlaneH",label:"Swimlane H",pen:{height:200,lineLeft:.08,name:"swimlaneH",text:"Swimlane",textAlign:"left",textLeft:.04,textWidth:.01,width:500}},{group:"Activity",key:"forkV",label:"Fork V",pen:{fillStyle:"#555",height:150,name:"forkV",strokeStyle:"transparent",text:"",width:10}},{group:"Activity",key:"forkH",label:"Fork H",pen:{fillStyle:"#555",height:10,name:"forkH",strokeStyle:"transparent",text:"",width:150}},{group:"Sequence & class",key:"lifeline",label:"Lifeline",pen:{height:400,name:"lifeline",text:"Object",textHeight:50,width:150}},{group:"Sequence & class",key:"sequenceFocus",label:"Activation",pen:{height:200,name:"sequenceFocus",text:"",width:12}},{group:"Sequence & class",key:"simpleClass",label:"Simple class",pen:{height:200,list:[{text:`- name: string
1
+ import{Q as I,S as H,T as F,U as O,V as G}from"./react-CI5PDFXT.js";import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-Bq3HuUfD.js";import{M as _}from"./meta2d-1-g23JOU.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 q=0;const P=new Set;function $(n){return P.add(n),()=>{P.delete(n)}}function M(){return q}function J(){q++,P.forEach(n=>n())}function z(n){let t=null;try{const[r]=I();t=r}catch{}const i=t;if(!i)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore($,M,M),{setLocale:c.useCallback(r=>{i.setLocale(r),J()},[i]),t:c.useCallback((r,u)=>i.t(r,u),[i])}}const K={Activity:"meta2d.palette.groups.activity",Basic:"meta2d.palette.groups.basic","Fault tree":"meta2d.palette.groups.faultTree",Flow:"meta2d.palette.groups.flow","Sequence & class":"meta2d.palette.groups.sequenceClass"};function W(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function U(){return[{group:"Basic",key:"square",label:"Square",pen:{...s,height:100,name:"square",text:"",width:100}},{group:"Basic",key:"rect",label:"Rectangle",pen:{...s,name:"rectangle",text:"Rectangle"}},{group:"Basic",key:"roundRect",label:"Rounded",pen:{...s,borderRadius:.2,name:"rectangle",text:"Rounded"}},{group:"Basic",key:"circle",label:"Circle",pen:{...s,height:80,name:"circle",text:"Circle",width:80}},{group:"Basic",key:"triangle",label:"Triangle",pen:{...s,height:90,name:"triangle",text:"Triangle",width:100}},{group:"Basic",key:"diamond",label:"Diamond",pen:{...s,height:100,name:"diamond",text:"Decision",width:100}},{group:"Basic",key:"pentagon",label:"Pentagon",pen:{...s,height:100,name:"pentagon",text:"Pentagon",width:100}},{group:"Basic",key:"hexagon",label:"Hexagon",pen:{...s,height:100,name:"hexagon",text:"Hexagon",width:100}},{group:"Basic",key:"pentagram",label:"Star",pen:{...s,height:100,name:"pentagram",text:"",width:100}},{group:"Basic",key:"leftArrow",label:"Left arrow",pen:{height:60,name:"leftArrow",width:120}},{group:"Basic",key:"rightArrow",label:"Right arrow",pen:{height:60,name:"rightArrow",width:120}},{group:"Basic",key:"twowayArrow",label:"Two-way",pen:{height:60,name:"twowayArrow",width:150}},{group:"Basic",key:"cloud",label:"Cloud",pen:{height:100,name:"cloud",width:100}},{group:"Basic",key:"message",label:"Message",pen:{height:100,name:"message",textTop:-.1,width:100}},{group:"Basic",key:"file",label:"File",pen:{height:100,name:"file",width:80}},{group:"Basic",key:"cube",label:"Cube",pen:{height:100,name:"cube",width:60,z:.25}},{group:"Basic",key:"people",label:"Actor",pen:{height:100,name:"people",width:70}},{group:"Basic",key:"text",label:"Text",pen:{...s,background:"transparent",color:"transparent",height:32,name:"text",text:"text",width:120}},{group:"Basic",key:"line",label:"Line",pen:{color:"#1f1f1f",height:1,lineWidth:1,name:"line",width:160}},{group:"Flow",key:"flowTerminal",label:"Terminal",pen:{...s,borderRadius:.5,height:40,name:"rectangle",text:"Start / End",width:120}},{group:"Flow",key:"flowProcess",label:"Process",pen:{...s,height:40,name:"rectangle",text:"Process",width:120}},{group:"Flow",key:"flowDecision",label:"Decision",pen:{...s,height:60,name:"diamond",text:"Decision",width:120}},{group:"Flow",key:"flowData",label:"Data",pen:{...s,name:"flowData",offsetX:.14,text:"Data"}},{group:"Flow",key:"flowPrepare",label:"Prepare",pen:{...s,height:50,name:"hexagon",text:"Prepare",width:120}},{group:"Flow",key:"flowSubprocess",label:"Subprocess",pen:{...s,height:50,name:"flowSubprocess",text:"Subprocess",width:120}},{group:"Flow",key:"flowDb",label:"Database",pen:{...s,height:100,name:"flowDb",text:"DB",width:80}},{group:"Flow",key:"flowDocument",label:"Document",pen:{...s,height:100,name:"flowDocument",text:"Document",width:120}},{group:"Flow",key:"flowInternalStorage",label:"Int. storage",pen:{...s,height:80,name:"flowInternalStorage",text:"Internal",width:120}},{group:"Flow",key:"flowExternStorage",label:"Ext. storage",pen:{...s,height:80,name:"flowExternStorage",text:"External",width:120}},{group:"Flow",key:"flowQueue",label:"Queue",pen:{...s,height:100,name:"flowQueue",text:"Queue",width:100}},{group:"Flow",key:"flowManually",label:"Manual input",pen:{...s,height:80,name:"flowManually",text:"Manual",width:120}},{group:"Flow",key:"flowDisplay",label:"Display",pen:{...s,height:80,name:"flowDisplay",text:"Display",width:120}},{group:"Flow",key:"flowParallel",label:"Parallel",pen:{...s,height:50,name:"flowParallel",text:"Parallel",width:120}},{group:"Flow",key:"flowComment",label:"Comment",pen:{...s,height:100,name:"flowComment",text:"Note",width:100}},{group:"Activity",key:"actStart",label:"Start",pen:{background:"#555",height:30,lineWidth:0,name:"circle",text:"",width:30}},{group:"Activity",key:"actFinal",label:"Final",pen:{height:30,name:"activityFinal",width:30}},{group:"Activity",key:"actStep",label:"Action",pen:{...s,borderRadius:.25,height:50,name:"rectangle",text:"Action",width:120}},{group:"Activity",key:"actMerge",label:"Merge",pen:{...s,height:50,name:"diamond",text:"Merge",width:120}},{group:"Activity",key:"swimlaneV",label:"Swimlane V",pen:{height:500,lineTop:.08,name:"swimlaneV",text:"Swimlane",textBaseline:"top",textTop:20,width:200}},{group:"Activity",key:"swimlaneH",label:"Swimlane H",pen:{height:200,lineLeft:.08,name:"swimlaneH",text:"Swimlane",textAlign:"left",textLeft:.04,textWidth:.01,width:500}},{group:"Activity",key:"forkV",label:"Fork V",pen:{fillStyle:"#555",height:150,name:"forkV",strokeStyle:"transparent",text:"",width:10}},{group:"Activity",key:"forkH",label:"Fork H",pen:{fillStyle:"#555",height:10,name:"forkH",strokeStyle:"transparent",text:"",width:150}},{group:"Sequence & class",key:"lifeline",label:"Lifeline",pen:{height:400,name:"lifeline",text:"Object",textHeight:50,width:150}},{group:"Sequence & class",key:"sequenceFocus",label:"Activation",pen:{height:200,name:"sequenceFocus",text:"",width:12}},{group:"Sequence & class",key:"simpleClass",label:"Simple class",pen:{height:200,list:[{text:`- name: string
2
2
  + setName(name: string): void`}],name:"simpleClass",text:"ClassName",textAlign:"center",textBaseline:"top",textHeight:200,textTop:10,width:270}},{group:"Sequence & class",key:"interfaceClass",label:"Class",pen:{height:200,list:[{text:"- name: string"},{text:"+ setName(name: string): void"}],name:"interfaceClass",text:"ClassName",textAlign:"center",textBaseline:"top",textHeight:200,textTop:10,width:270}},{group:"Fault tree",key:"andGate",label:"AND gate",pen:{height:150,name:"andGate",width:100}},{group:"Fault tree",key:"orGate",label:"OR gate",pen:{height:150,name:"orGate",width:100}},{group:"Fault tree",key:"basicEvent",label:"Basic event",pen:{height:150,name:"basicEvent",width:100}},{group:"Fault tree",key:"xorGate",label:"XOR gate",pen:{height:150,name:"xorGate",width:100}},{group:"Fault tree",key:"votingGate",label:"Voting gate",pen:{height:150,name:"votingGate",width:100}}]}function V(n){return G(structuredClone(n))}function Z(n){const t=new Map;for(const i of n){const r=t.get(i.group)??[];r.push(i),t.set(i.group,r)}return Array.from(t.entries())}function ee({name:n}){const t={fill:"#fff",stroke:"#1f1f1f",strokeWidth:1.2};return n==="circle"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("circle",{cx:"14",cy:"14",r:"10",...t})}):n==="diamond"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 25,14 14,25 3,14",...t})}):n==="triangle"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,4 25,24 3,24",...t})}):n==="pentagon"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 25,12 21,25 7,25 3,12",...t})}):n==="hexagon"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"8,4 20,4 25,14 20,24 8,24 3,14",...t})}):n==="pentagram"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 17,11 26,11 18,16 21,25 14,20 7,25 10,16 2,11 11,11",...t})}):n==="line"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("line",{x1:"4",x2:"24",y1:"14",y2:"14",...t})}):n==="text"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("text",{dominantBaseline:"middle",fill:"#1f1f1f",fontSize:"14",textAnchor:"middle",x:"14",y:"15",children:"T"})}):e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("rect",{height:"14",rx:"2",width:"20",x:"4",y:"7",...t})})}function te({disabled:n,engineRef:t,item:i,t:r}){const u=()=>{const a=t.current;if(!(!a||n))try{a.canvas.addCaches=[V(i.pen)]}catch{}};return e.jsxs("div",{draggable:!n,onClick:a=>{a.stopPropagation(),u()},onDragStart:a=>{if(n){a.preventDefault();return}const f=JSON.stringify(V(i.pen));a.dataTransfer.setData("Meta2d",f),a.dataTransfer.setData("Text",f),a.dataTransfer.effectAllowed="copy"},onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),u())},role:"button",style:{alignItems:"center",border:"1px solid #efefef",borderRadius:6,cursor:n?"not-allowed":"grab",display:"flex",flexDirection:"column",gap:4,justifyContent:"center",minHeight:56,opacity:n?.5:1,outline:"none",padding:6},tabIndex:n?-1:0,title:`${r(W(i.key))||i.label} — drag or click to add`,children:[e.jsx(ee,{name:String(i.pen.name??"rectangle")}),e.jsx("span",{style:{fontSize:11},children:r(W(i.key))||i.label})]})}function ne({disabled:n,engineRef:t}){const{t:i}=z(),r=c.useMemo(()=>Z(U()),[]);return e.jsxs("aside",{style:{borderRight:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",padding:12,touchAction:"pan-y",width:240},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,marginBottom:4},children:i("meta2d.palette.title")}),e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:12},children:i("meta2d.palette.hint")}),r.map(([u,a])=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:6},children:i(K[u]||u)}),e.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"repeat(2, minmax(0, 1fr))"},children:a.map(f=>e.jsx(te,{disabled:n,engineRef:t,item:f,t:i},f.key))})]},u))]})}const N={borderLeft:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",touchAction:"pan-y",width:220},A={color:"#8c8c8c",fontSize:12,marginBottom:4},D={borderBottom:"1px solid #f0f0f0",padding:"10px 12px"},y={alignItems:"center",display:"flex",gap:6,marginBottom:6},w={background:"#fafafa",border:"1px solid #e5e5e5",borderRadius:4,fontSize:12,height:28,outline:"none",padding:"0 6px"},b={color:"#8c8c8c",fontSize:11,minWidth:22},T={background:"#fff",border:"1px solid #d9d9d9",borderRadius:4,cursor:"pointer",fontSize:11,minWidth:48,padding:"4px 8px"},le=120;function ie({engine:n}){const{t}=z(),[i,r]=c.useState(null),[u,a]=c.useState(null),[f,v]=c.useState(""),p=c.useRef(null),j=c.useRef(null),B=c.useCallback((l,d)=>{!n||l===null||l===void 0||n.setValue({id:l,text:d},{render:!0})},[n]),k=c.useCallback(l=>{if(!l||l.length!==1){p.current&&(clearTimeout(p.current),p.current=null),r(null),a(null),v(""),j.current=null;return}const d=l[0];if((d.globalAlpha===null||d.globalAlpha===void 0)&&(d.globalAlpha=1),d.id!==j.current&&(p.current&&(clearTimeout(p.current),p.current=null),j.current=d.id,v(d.text??"")),r(d),n)try{a(n.getPenRect(d))}catch{a(null)}},[n]),C=c.useCallback(()=>{p.current&&(clearTimeout(p.current),p.current=null),r(null),a(null),v(""),j.current=null},[]);if(c.useEffect(()=>{if(n)return n.on("active",k),n.on("inactive",C),()=>{n.off("active",k),n.off("inactive",C),p.current&&(clearTimeout(p.current),p.current=null)}},[n,k,C]),!i||!n)return e.jsx("aside",{style:N,children:e.jsx("div",{style:{color:"#bbb",fontSize:12,padding:16,textAlign:"center"},children:t("meta2d.props.empty")})});const h=(l,d)=>{const m={id:i.id};m[l]=d,l==="dash"&&(m.lineDash=[void 0,[5,5]][d]),l!=="text"&&r(S=>S&&{...S,...m}),n.setValue(m,{render:!0})},o=l=>{v(l);const d=i.id;p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{p.current=null,B(d,l)},le)},x=()=>{p.current&&(clearTimeout(p.current),p.current=null),B(i.id,f)},g=(l,d)=>{if(!u)return;const m={id:i.id};m[l]=d,n.setValue(m,{render:!0}),a(S=>S?{...S,[l]:d}:null)},R=l=>{l(n),n.render(!0)};return e.jsxs("aside",{style:N,children:[e.jsxs("div",{style:D,children:[e.jsx("div",{style:A,children:t("meta2d.props.text")}),e.jsx("div",{style:y,children:e.jsx("input",{onBlur:x,onChange:l=>o(l.target.value),onKeyDown:l=>{l.stopPropagation(),l.key==="Enter"&&(l.preventDefault(),l.target.blur())},style:{...w,flex:1,width:"100%"},type:"text",value:f})})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.appearance")}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.color")}),e.jsx("input",{onChange:l=>h("color",l.target.value),style:{...w,flex:1},type:"color",value:i.color||"#1f1f1f"})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.bg")}),e.jsx("input",{onChange:l=>h("background",l.target.value),style:{...w,flex:1},type:"color",value:i.background||"#ffffff"})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.dash")}),e.jsxs("select",{onChange:l=>h("dash",Number(l.target.value)),style:{...w,flex:1},value:String(i.dash??0),children:[e.jsx("option",{value:"0",children:t("meta2d.props.solid")}),e.jsx("option",{value:"1",children:t("meta2d.props.dashLine")})]})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.radius")}),e.jsx("input",{max:1,min:0,onChange:l=>h("borderRadius",Number(l.target.value)),step:.01,style:{...w,flex:1},type:"range",value:String(i.borderRadius??0)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:i.borderRadius??0})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.alpha")}),e.jsx("input",{max:1,min:0,onChange:l=>h("globalAlpha",Number(l.target.value)),step:.01,style:{...w,flex:1},type:"range",value:String(i.globalAlpha??1)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:(i.globalAlpha??1).toFixed(2)})]})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.position")}),[["X","x"],["Y","y"],["W","width"],["H","height"]].map(([l,d])=>e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:l}),e.jsx("input",{onChange:m=>g(d,Number(m.target.value)),style:{...w,flex:1},type:"number",value:u?u[d]:0})]},d))]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.textAlign")}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.h")}),e.jsxs("select",{onChange:l=>h("textAlign",l.target.value),style:{...w,flex:1},value:i.textAlign||"center",children:[e.jsx("option",{value:"left",children:t("meta2d.props.left")}),e.jsx("option",{value:"center",children:t("meta2d.props.center")}),e.jsx("option",{value:"right",children:t("meta2d.props.right")})]})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.v")}),e.jsxs("select",{onChange:l=>h("textBaseline",l.target.value),style:{...w,flex:1},value:i.textBaseline||"middle",children:[e.jsx("option",{value:"top",children:t("meta2d.props.topAlign")}),e.jsx("option",{value:"middle",children:t("meta2d.props.middle")}),e.jsx("option",{value:"bottom",children:t("meta2d.props.bottomAlign")})]})]})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.layer")}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[e.jsx("button",{onClick:()=>R(l=>l.top()),style:T,type:"button",children:t("meta2d.props.top")}),e.jsx("button",{onClick:()=>R(l=>l.up()),style:T,type:"button",children:t("meta2d.props.up")}),e.jsx("button",{onClick:()=>R(l=>l.down()),style:T,type:"button",children:t("meta2d.props.down")}),e.jsx("button",{onClick:()=>R(l=>l.bottom()),style:T,type:"button",children:t("meta2d.props.bottom")})]})]})]})}const L={background:"#fff",border:"1px solid #d9d9d9",borderRadius:6,cursor:"pointer",minWidth:68,padding:"6px 12px"},E={...L,fontSize:12,minWidth:52,padding:"4px 10px"};function re(n){c.useEffect(()=>{const t=document.documentElement,i=document.body,r=t.style.overflow,u=i.style.overflow;return t.style.overflow="hidden",i.style.overflow="hidden",()=>{t.style.overflow=r,i.style.overflow=u}},[n])}function ye({diagram:n,onClose:t,onSave:i}){const{t:r}=z(),u=c.useRef(null),a=c.useRef(null),f=c.useRef(n),v=c.useRef(t),[p,j]=c.useState(null),[B,k]=c.useState(!1);re(!0),c.useLayoutEffect(()=>{v.current=t}),c.useEffect(()=>{if(!u.current)return;X();const o=new _(u.current,{grid:!0,rule:!1});a.current=o,j(o);try{const g=f.current;g!=null&&g.trim()?o.open(JSON.parse(g)):o.open(H()),F(o.data()),o.render(!0)}catch{o.open(H()),F(o.data()),o.render(!0)}const x=g=>{g.key==="Escape"&&v.current()};return window.addEventListener("keydown",x),()=>{window.removeEventListener("keydown",x);try{o.destroy()}catch{}a.current=null}},[]);const C=async()=>{const o=a.current;if(o){k(!0);try{F(o.data()),o.render(!0);const x=O(o.data()),g=JSON.stringify(x);i(g,await Q(o)||await Y(g)||'<svg xmlns="http://www.w3.org/2000/svg" width="320" height="180" viewBox="0 0 320 180"><rect width="100%" height="100%" fill="#fafafa" stroke="#eee"/></svg>')}finally{k(!1)}}},h=o=>{const x=a.current;x&&o(x)};return e.jsx("div",{onClick:t,style:{alignItems:"center",background:"rgb(0 0 0 / 35%)",display:"flex",inset:0,justifyContent:"center",overflow:"hidden",position:"fixed",zIndex:1e3},children:e.jsxs("div",{onClick:o=>o.stopPropagation(),onWheel:o=>o.stopPropagation(),style:{background:"#fff",borderRadius:10,boxShadow:"0 12px 30px rgb(0 0 0 / 20%)",display:"flex",flexDirection:"column",height:"86vh",maxHeight:"100%",maxWidth:"1200px",overflow:"hidden",width:"92vw"},children:[e.jsxs("div",{style:{alignItems:"center",borderBottom:"1px solid #f0f0f0",display:"flex",flexWrap:"wrap",gap:8,justifyContent:"space-between",padding:"10px 14px"},children:[e.jsx("span",{style:{fontWeight:600},children:r("meta2d.editor.title")}),e.jsxs("div",{style:{alignItems:"center",display:"flex",flexWrap:"wrap",gap:8},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:[e.jsx("button",{onClick:()=>h(o=>o.undo()),style:E,title:`${r("meta2d.editor.undo")} (Ctrl+Z)`,type:"button",children:r("meta2d.editor.undo")}),e.jsx("button",{onClick:()=>h(o=>o.redo()),style:E,title:`${r("meta2d.editor.redo")} (Ctrl+Y)`,type:"button",children:r("meta2d.editor.redo")}),e.jsx("button",{onClick:()=>h(o=>o.delete()),style:E,title:r("meta2d.editor.delete"),type:"button",children:r("meta2d.editor.delete")}),e.jsx("button",{onClick:()=>h(o=>o.fitView(!0)),style:E,title:r("meta2d.editor.fit"),type:"button",children:r("meta2d.editor.fit")}),e.jsx("button",{onClick:()=>h(o=>{o.scale(1),o.centerView()}),style:E,title:r("meta2d.editor.zoom100"),type:"button",children:r("meta2d.editor.zoom100")})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:t,style:L,type:"button",children:r("meta2d.editor.close")}),e.jsx("button",{disabled:B,onClick:()=>void C(),style:{...L,background:"#1677ff",border:"none",color:"#fff"},type:"button",children:r(B?"meta2d.editor.saving":"meta2d.editor.save")})]})]})]}),e.jsxs("div",{style:{display:"flex",flex:1,minHeight:0,overflow:"hidden"},children:[e.jsx(ne,{engineRef:a}),e.jsx("div",{ref:u,style:{flex:1,minHeight:0,minWidth:0}}),e.jsx(ie,{engine:p})]})]})})}export{ye as DiagramEditor};
@@ -0,0 +1,21 @@
1
+ import{o as d,c as v,F as D,P as M,p as x,l as k,R as j,E as B,q as P,S as E,M as S}from"./index-OmOf_og0.js";import{r as I,j as n}from"./react-vendor-BuABiQkA.js";import{g as W}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"}]],z=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 A=[["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"}]],L=d("shield-user",A);/**
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 O=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],R=d("text-align-justify",O);/**
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 _=[["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"}]],$=d("users",_);function q(e){const{t,lang:m}=v(),l=W(e.fileType||"md"),f=!!(l!=null&&l.aiWrite&&e.onAiWrite),C=!!(l!=null&&l.comments&&e.onToggleComments);e.canEdit&&(e.editing||e.actionsAlwaysVisible);const[o,N]=I.useState(!1),r=e.domains.length?e.domains:[D],c="mdocs-editor-toolbar"+(e.readerChrome?e.readerHeaderDocked?" mdocs-editor-toolbar--docked":" mdocs-editor-toolbar--float":""),s=e.readerChrome&&!e.readerHeaderDocked&&e.readerDragOffset?{transform:`translateY(${e.readerDragOffset}px)`}:void 0;if(e.readerChrome){const a=n.jsxs("div",{className:"mdocs-editor-toolbar-leading",onPointerDown:e.onReaderHeaderPointerDown,onPointerMove:e.onReaderHeaderPointerMove,onPointerUp:e.onReaderHeaderPointerUp,onPointerCancel:e.onReaderHeaderPointerUp,children:[n.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:n.jsx(M,{size:18,strokeWidth:1.75})}),n.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=n.jsx(x,{domains:r,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:t("currentDomainAria"),localizeName:i=>k(i,m,t)}),h=e.canEdit&&e.onPublish?n.jsx("button",{type:"button",className:"primary mdocs-reader-action-btn",disabled:e.busy,onClick:()=>{var i,g;e.editing||(i=e.onEnterEdit)==null||i.call(e),(g=e.onPublish)==null||g.call(e)},children:e.busy?t("publishing"):t("publish")}):null,y=e.onSyncClick?n.jsx("button",{type:"button",className:"mdocs-sync-btn mdocs-reader-sync-btn"+(e.syncBehind?" behind":""),"aria-label":e.syncBehind?t("syncBehindHint"):t("syncPull"),onClick:()=>{var i;return void((i=e.onSyncClick)==null?void 0:i.call(e))},children:n.jsx(j,{size:16,strokeWidth:1.75})}):null,b=e.readerMoreMenu!=null?n.jsxs("div",{ref:e.readerMoreMenuRef,className:"mdocs-reader-more-menu",children:[n.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:n.jsx(B,{size:18,strokeWidth:1.75})}),e.readerMoreOpen?n.jsx("div",{className:"mdocs-reader-more-dropdown card",children:e.readerMoreMenu}):null]}):null;return e.readerActionsCollapsible?n.jsxs("div",{className:c+" mdocs-editor-toolbar--stacked",style:s,children:[n.jsxs("div",{className:"mdocs-reader-top-row",children:[a,y,n.jsx("button",{type:"button",className:"mdocs-reader-expand-btn",onClick:()=>N(i=>!i),"aria-label":o?"收起操作栏":"展开操作栏",children:n.jsx(z,{size:16,strokeWidth:2,style:{transform:o?"rotate(0deg)":"rotate(180deg)",transition:"transform 0.2s"}})}),b]}),o&&n.jsxs("div",{className:"mdocs-reader-actions-row",children:[u,e.leadingExtra,h,e.trailingExtra]})]}):n.jsxs("div",{className:c,style:s,children:[a,u,e.leadingExtra,y,h,b,e.trailingExtra]})}return n.jsxs("div",{className:c,style:s,children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",children:[n.jsx("input",{className:"mdocs-editor-title-input",value:e.displayName,onChange:a=>e.onDisplayNameChange(a.target.value),onBlur:e.onDisplayNameBlur,placeholder:t("displayNamePlaceholder"),disabled:!e.editing}),n.jsx(x,{domains:r,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:t("currentDomainAria"),localizeName:a=>k(a,m,t)}),f?n.jsxs("button",{type:"button",className:"secondary",onClick:()=>{var a;return(a=e.onAiWrite)==null?void 0:a.call(e)},style:{padding:"4px 10px",whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",gap:6},children:[n.jsx("img",{src:P,alt:"",width:16,height:16,style:{display:"block"}}),"帮写"]}):null,e.leadingExtra]}),n.jsx("span",{className:"mdocs-editor-toolbar-spacer","aria-hidden":!0}),n.jsxs("div",{className:"mdocs-editor-toolbar-trailing",children:[e.onToggleBookmark?n.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var a;return(a=e.onToggleBookmark)==null?void 0:a.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:[n.jsx(E,{size:18,strokeWidth:1.5,style:{color:e.isBookmarked?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:e.isBookmarked?"#faad14":"none"}}),e.isBookmarked?n.jsx("span",{children:"已收藏"}):null]}):null,n.jsxs("div",{className:"mdocs-editor-toolbar-actions",children:[e.onSyncClick?n.jsxs("button",{type:"button",className:"mdocs-sync-btn mdocs-tooltip mdocs-tooltip-bottom"+(e.syncBehind?" behind":""),"data-tooltip":e.syncBehind?t("syncBehindHint"):t("syncPull"),onClick:()=>{var a;return void((a=e.onSyncClick)==null?void 0:a.call(e))},style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx(j,{size:16,strokeWidth:1.5}),n.jsx("span",{children:t("syncPull")})]}):null,e.editing?n.jsxs(n.Fragment,{children:[localStorage.getItem("mdocs.autoPublish")!=="true"&&n.jsxs("span",{className:"mdocs-save-indicator",children:[n.jsx("span",{className:"mdocs-save-dot "+(e.busy?"saving":e.draftExists?"unsaved":"saved")}),n.jsx("span",{children:e.busy?t("publishing"):e.draftExists?t("unsaved"):t("published")})]}),e.onPublish?n.jsx("button",{type:"button",className:"primary",disabled:e.busy,onClick:()=>{var a;return(a=e.onPublish)==null?void 0:a.call(e)},children:e.busy?t("publishing"):t("publish")}):null,e.onDelete?n.jsx("button",{type:"button",className:"danger",disabled:e.busy,onClick:()=>{var a;return(a=e.onDelete)==null?void 0:a.call(e)},children:t("delete")}):null]}):null,!e.editing&&e.canEdit&&e.onEnterEdit?n.jsx("button",{type:"button",className:"primary",onClick:()=>{var a;return(a=e.onEnterEdit)==null?void 0:a.call(e)},children:t("edit")}):null,e.trailingExtra,C?n.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var a;return(a=e.onToggleComments)==null?void 0:a.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:[n.jsx(S,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}}),e.commentCount&&e.commentCount>0?n.jsx("span",{style:{fontSize:"0.85rem"},children:e.commentCount}):null]}):null,e.onToggleDocInfo?n.jsxs("div",{ref:e.docInfoMenuRef,className:"mdocs-tooltip mdocs-tooltip-bottom","data-tooltip":t("docInfo"),style:{position:"relative"},children:[n.jsx("button",{type:"button",className:"secondary",onClick:()=>{var a;return(a=e.onToggleDocInfo)==null?void 0:a.call(e)},style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx(R,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}})}),e.docInfoOpen?n.jsx("div",{className:"mdocs-doc-info-dropdown",children:e.docInfoMenu}):null]}):null]})]})]})}export{q as D,L as S,$ as U};
@@ -0,0 +1 @@
1
+ import{r as n,j as a}from"./react-vendor-BuABiQkA.js";import{ad as ge}from"./ui-CvA4pq3d.js";import{g as be,u as we,a as ye,s as Ue,d as qe,b as ve,c as Ve,f as We,e as Ye,h as Ge,N as Je,S as $e,l as Ke,r as Xe,i as Qe,j as Ze,D as Z,k as pe,m as et,n as xe}from"./index-OmOf_og0.js";import{z as tt,A as nt,m as se,n as at,o as it,p as rt,r as ot,s as st,t as ct,v as lt,x as ut,B as dt,R as mt,a as ft,b as Ie,c as ht,d as gt,e as yt,f as vt,g as xt,h as It,i as kt,w as ce,j as St,O as Et,E as bt,q as wt,l as Mt,C as Ct,D as Dt}from"./react-CI5PDFXT.js";import{H as Rt,a as jt,b as At,M as Nt,T as Pt,S as Tt,W as Bt,o as Lt,c as ke}from"./Toolbar-Hsam79hu.js";import{D as Ot,U as _t,S as Ht}from"./DocChrome-BWMgRxlr.js";import{V as zt}from"./VisitorPickerModal-CqHzml8s.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./editor-CL03se2B.js";import"./plus-DKKQ-AoS.js";import"./check-soiTDN2u.js";import"./copy-B4fvX0p8.js";import"./file-type-policy-GUk904tm.js";const Ft=48;function p(e){try{const i=e.getDocument("markdown");return typeof i=="string"?i:""}catch{return null}}function Ut(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function qt({editor:e,documentId:i,displayName:c,debounceMs:I=1e3,enabled:g=!0,localBaseCommitIdAtEditStart:R,snapshotMeta:b,seedDraftExists:z=!1}){const[F,L]=n.useState(!1),[ee,j]=n.useState(z),[A,S]=n.useState(null),d=n.useRef(null),f=n.useRef(null),k=n.useRef(!1),x=n.useRef(""),v=n.useRef(!1),O=n.useRef(i),U=n.useRef(c),N=n.useRef(R),J=n.useRef(b);O.current=i,U.current=c,N.current=R,J.current=b;const E=n.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const s=Ut(e);s!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",O.current,"content preview:",s.slice(0,80)),await be(O.current).execute(()=>we({documentId:O.current,content:s,displayName:U.current,localBaseCommitIdAtEditStart:N.current,snapshotMeta:J.current})),x.current=p(e)??x.current,j(!0),L(!1),S(Date.now()),k.current=!0,v.current=!1)},[e]);n.useEffect(()=>{let s=!1;const m=ve();return ye(i).then(h=>{if(s||ve()!==m)return;const y=!!(h&&!h.published);j(y),y&&h?(S(h.updatedAt),k.current=!0):(S(null),k.current=!1,v.current=!1)}),()=>{s=!0}},[i]),n.useEffect(()=>Ue((s,m)=>{s===O.current&&(j(m),m||(S(null),k.current=!1))}),[]),n.useEffect(()=>{var H,q;if(!g){(H=f.current)==null||H.call(f),f.current=null;return}if(!e)return;const s=e.getLexicalEditor();if(!s)return;(q=f.current)==null||q.call(f);let m=!1,h=0,y=0;const _=()=>{if(m)return;const P=p(e);if(P===null){if(y+=1,y>Ft)return;h=requestAnimationFrame(_);return}x.current=P;const ne=s.registerUpdateListener(()=>{const M=p(e);M!==null&&M!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",i,"oldLen:",x.current.length,"newLen:",M.length),x.current=M,L(!0),v.current=!0,k.current=!1,d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,E()},I))});f.current=()=>{ne(),d.current&&(clearTimeout(d.current),d.current=null)}};return queueMicrotask(()=>{m||(h=requestAnimationFrame(_))}),()=>{var P;m=!0,cancelAnimationFrame(h),(P=f.current)==null||P.call(f)}},[g,e,i,c,I,R,b,E]),n.useEffect(()=>{var h;if(!g||!e)return;const s=(h=e.getLexicalEditor())==null?void 0:h.getRootElement();if(!s)return;const m=()=>{d.current&&(clearTimeout(d.current),d.current=null),v.current&&E()};return s.addEventListener("blur",m),()=>s.removeEventListener("blur",m)},[g,e,E]),n.useEffect(()=>{if(!g)return;const s=()=>{document.visibilityState==="hidden"&&(d.current&&(clearTimeout(d.current),d.current=null),v.current&&E())},m=()=>{v.current&&(d.current&&(clearTimeout(d.current),d.current=null),E())};return document.addEventListener("visibilitychange",s),window.addEventListener("beforeunload",m),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("beforeunload",m)}},[g,E]);async function $(){await qe(i),j(!1),L(!1),v.current=!1,k.current=!1,x.current=""}async function te(){const s=await ye(i);return s?s.content:null}function w(){j(!0),L(!1),v.current=!1,S(Date.now()),k.current=!0,e&&(x.current=p(e)??"")}return{isDirty:F,draftExists:ee,lastSavedAt:A,clearDraft:$,loadDraftContent:te,markDraftSaved:w}}function Vt({isDirty:e,draftExists:i}){const c=e&&!i;n.useEffect(()=>{if(!c)return;const I=g=>{g.preventDefault()};return window.addEventListener("beforeunload",I),()=>window.removeEventListener("beforeunload",I)},[c])}function le(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Se='{"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 Ee(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 Wt(e,i){if(!e)return i==="json"?Se: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 Se}catch{}return e}function Yt({editor:e}){const{visible:i}=Ct();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(Dt,{editor:e})})})}function sn(e){const{t:i,lang:c}=Ve(),[I,g]=n.useState(!1),[R,b]=n.useState(!1),z=n.useRef(null),F=n.useRef(null),[L,ee]=n.useState([]),[j,A]=n.useState(!1),[S,d]=n.useState(e.meta.permission),[f,k]=n.useState(!1),[x,v]=n.useState(!1),[O,U]=n.useState(!1),[N,J]=n.useState(new Map),[E,$]=n.useState(!1);n.useEffect(()=>{const t=r=>{z.current&&!z.current.contains(r.target)&&g(!1),F.current&&!F.current.contains(r.target)&&b(!1)};return(I||R)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[I,R]),n.useEffect(()=>{let t=!0;return We().then(r=>{t&&ee(r)}).catch(()=>{}),()=>{t=!1}},[]);function te(t){const r=L.find(l=>l.visitorId===t);return(r==null?void 0:r.visitorName)??t.slice(0,8)}const[w,s]=n.useState(e.initialDisplayName),[m,h]=n.useState(!1),[y,_]=n.useState(!1),[H,q]=n.useState(!1),[P,ne]=n.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),M=e.canEdit&&P,[u,ue]=n.useState(null),[Me,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 C=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]),V=n.useMemo(()=>Wt(e.initialContent||"",C),[e.initialContent,C,e.contentRevision]),{isDirty:me,draftExists:K,markDraftSaved:Ce}=qt({editor:u,documentId:e.meta.documentId,displayName:w,enabled:e.canEdit,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId},seedDraftExists:e.hasLocalDraft});n.useEffect(()=>{var t;(t=e.onDraftExistsChange)==null||t.call(e,K)},[K,e.onDraftExistsChange]),Vt({isDirty:me,draftExists:K}),n.useEffect(()=>{if(u)try{u.setDocument(C,V)}catch{}},[u,e.meta.documentId,e.contentRevision,V,C]),n.useEffect(()=>{u==null||u.setLocale(c==="zh"?tt:nt)},[u,c]),n.useEffect(()=>{s(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),n.useEffect(()=>{d(e.meta.permission)},[e.meta.permission,e.meta.documentId]),n.useEffect(()=>{let t=!0;return(async()=>{try{const r=await Ye(e.meta.documentId);t&&_(r.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function ie(){var t,r;if(!H){q(!0);try{y?(await Xe(e.meta.documentId),_(!1),(t=e.onShowToast)==null||t.call(e,i("bookmarkRemoved"))):(await Qe(e.meta.documentId),_(!0),(r=e.onShowToast)==null||r.call(e,i("bookmarkAdded")))}finally{q(!1)}}}n.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=Be),()=>{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 De(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const Re=n.useCallback(t=>{ae.current=t,ue(t);const r=V;if(!r)return;const l=()=>{try{t.setDocument(C,r)}catch{requestAnimationFrame(()=>{try{t.setDocument(C,r)}catch{}})}};queueMicrotask(()=>{queueMicrotask(l)})},[C,V]);async function fe(){if(!(!u||!e.canEdit)){h(!0);try{const t=le(u);if(!t)return;await e.onPublish(t,w,e.meta.documentId)}catch(t){throw t}finally{h(!1)}}}async function je(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(w.trim()!==t)try{await fe()}catch{}}const D=n.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),Ae=n.useMemo(()=>{const t=(D==null?void 0:D.permission)??"public";return Ge(t)},[D==null?void 0:D.permission]);function Ne(t){return t===Z.PRIVATE?i("permissionPrivate"):t===Z.DOMAIN_READ?i("permissionInvite"):t===Z.DOMAIN_WRITE?i("permissionDomainWrite"):t===Z.PUBLIC_READ?i("permissionPublicRead"):i("permissionPublicEdit")}async function Pe(){var t;if(f||S===e.meta.permission){A(!1);return}k(!0);try{const l=(u?le(u):null)??e.initialContent;await e.onPublish(l,w,e.meta.documentId,S),A(!1),(t=e.onShowToast)==null||t.call(e,i("docInfoPermissionUpdated"))}finally{k(!1)}}async function Te(t){var r;if(!E){$(!0);try{const l=new Set(t.map(o=>o.visitorId)),B=new Map(t.map(o=>[o.visitorId,o.permission]));for(const[o]of N)l.has(o)||await pe(e.meta.documentId,o);for(const{visitorId:o,permission:Y}of t){const G=N.get(o);(!G||G!==Y)&&await et(e.meta.documentId,o,Y)}v(!1),(r=e.onShowToast)==null||r.call(e,i("docInfoInviteSuccess",{count:t.length}))}finally{$(!1)}}}async function Be(){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)),Ce(),await be(e.meta.documentId).execute(()=>we({documentId:e.meta.documentId,content:t,displayName:w,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const Le=n.useMemo(()=>[{icon:Rt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(se,{tag:"h1"})}},{icon:jt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(se,{tag:"h2"})}},{icon:At,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(se,{tag:"h3"})}},{type:"divider"},{icon:Nt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(at,{})}},{icon:Pt,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(it,{columns:"3",rows:"3"})}},{icon:Tt,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(rt,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{Lt(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(ot,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(st,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(ct,void 0),queueMicrotask(()=>t.focus())}},{icon:Bt,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(lt,void 0),queueMicrotask(()=>t.focus())}},{icon:Je,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ut,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})}),[]),Oe=n.useMemo(()=>[dt,mt,ft,Ie,ht,gt,yt,vt,xt,It,kt,ce(St,{children:u?a.jsx(ke,{editor:u,floating:!0,outlineCollapseTitle:i("outlineHide"),outlineExpandTitle:i("outlineShow"),outlineToggle:!0}):null}),ce(Mt,{handleUpload:async t=>{var r;try{return{url:await xe(t,e.meta.documentId)}}catch(l){throw(r=e.onShowError)==null||r.call(e,Ee(l)),l}}}),ce(Ie,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var r;try{const B=await(await fetch(t)).blob(),o=new File([B],"image.png",{type:B.type});return{url:await xe(o,e.meta.documentId)}}catch(l){throw(r=e.onShowError)==null||r.call(e,Ee(l)),l}}})],[u,i,e.meta.documentId,e.onShowError]),T=!!e.readerChrome,[W,re]=n.useState(!1),X=n.useRef(null),[_e,oe]=n.useState(0);n.useEffect(()=>{if(!T){re(!1),oe(0);return}if(W)return;const t=window.setTimeout(()=>re(!0),2800);return()=>window.clearTimeout(t)},[T,W,e.meta.documentId]),n.useEffect(()=>{b(!1),g(!1)},[e.meta.documentId]);function He(t){!T||W||t.target.closest("button, a, input, textarea, select")||(X.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function ze(t){const r=X.current;if(!(r!=null&&r.dragging))return;const l=t.clientY-r.startY;oe(Math.max(-72,Math.min(0,l)))}function Fe(t){const r=X.current;if(!(r!=null&&r.dragging))return;X.current=null;const l=t.clientY-r.startY;oe(0),l<-36&&re(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function Q(){g(!1),b(!1)}function he(t,r){const l=(r==null?void 0:r.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 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:te(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:De(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:B,onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},onClick:()=>{ie(),t()},children:[a.jsx("span",{children:y?"⭐":"☆"}),a.jsx("span",{children:i(y?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?a.jsxs("button",{type:"button",style:B,onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{U(!0);try{const o=await Ze(e.meta.documentId),Y=new Map(o.map(G=>[G.visitorId,G.permission]));J(Y),v(!0)}finally{U(!1)}})()},children:[a.jsx(_t,{size:14}),a.jsx("span",{children:i("docInfoInviteMember")})]}):null,a.jsxs("button",{type:"button",style:B,onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},onClick:()=>{t(),d(e.meta.permission),A(!0)},children:[a.jsx(Ht,{size:14}),a.jsx("span",{children:i("docInfoChangePermission")})]})]})}return a.jsxs("div",{className:"mdocs-editor"+(T?" mdocs-editor--reader":"")+(T&&W?" mdocs-editor--reader-docked":""),children:[a.jsx(Ot,{fileType:e.meta.fileType||"md",displayName:w,onDisplayNameChange:s,onDisplayNameBlur:()=>void je(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:M,onEnterEdit:()=>ne(!0),onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:m,draftExists:K,onPublish:()=>{fe().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:y,bookmarkBusy:H,onToggleBookmark:()=>void ie(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:he(Q),docInfoOpen:I,onToggleDocInfo:()=>g(!I),docInfoMenuRef:z,readerChrome:T,onOpenMobileNav:e.onOpenMobileNav,readerHeaderDocked:W,readerDragOffset:_e,onReaderHeaderPointerDown:He,onReaderHeaderPointerMove:ze,onReaderHeaderPointerUp:Fe,readerMoreOpen:R,onToggleReaderMore:()=>b(t=>!t),readerMoreMenuRef:F,readerMoreMenu:a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:H,onClick:()=>{ie(),Q()},children:[a.jsx($e,{size:16,strokeWidth:1.5,style:{color:y?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:y?"#faad14":"none"}}),a.jsx("span",{children:i(y?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?a.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:m,onClick:()=>{Q(),e.onDelete()},children:a.jsx("span",{children:i("delete")})}):null,a.jsx("div",{className:"mdocs-reader-more-divider"}),he(Q,{includeBookmark:!1})]})}),j&&a.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&A(!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"),":",D?Ke(D.domainName,c,i):e.meta.domainId]}),a.jsx("div",{style:{display:"grid",gap:8},children:Ae.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:S===t,onChange:()=>d(t)}),a.jsx("span",{children:Ne(t)})]},t))}),a.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[a.jsx("button",{type:"button",onClick:()=>A(!1),children:i("cancel")}),a.jsx("button",{type:"button",className:"primary",disabled:f,onClick:()=>void Pe(),children:i(f?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&a.jsx(zt,{open:x,title:i("docInfoInviteMember"),initialSelectedIds:[...N.keys()],initialPermissions:N,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:i("invitePermissionRead")},{value:"edit",label:i("invitePermissionEdit")}],onClose:()=>v(!1),onConfirm:t=>{Te(t)}}),a.jsx(Et,{children:a.jsx(ge,{flex:1,style:{minHeight:0},children:a.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[M&&u&&!T?a.jsx(ke,{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:Me?a.jsx(bt,{content:V,type:C,confirmPasteMarkdown:!0,editable:M,onInit:Re,plugins:Oe,lineEmptyPlaceholder:i("displayNamePlaceholder"),placeholder:i("displayNamePlaceholder"),slashOption:{items:Le},className:"mdocs-document-editor-root"},e.meta.documentId):null}),u&&a.jsx(Yt,{editor:u})]})})]})})})]})}export{sn as DocumentEditor};
@@ -0,0 +1 @@
1
+ import{r as i,j as n}from"./react-vendor-BuABiQkA.js";import{c as ue,f as fe,e as he,a as xe,s as ve,g as ge,u as ye,h as be,S as ke,l as je,r as Ce,i as Ie,j as De,D as C,k as we,m as Se,b as q}from"./index-OmOf_og0.js";import{D as Ee,U as Ne,S as Me}from"./DocChrome-BWMgRxlr.js";import{V as Pe}from"./VisitorPickerModal-CqHzml8s.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./file-type-policy-GUk904tm.js";function Ue(e){const{t:a,lang:I}=ue(),r=e.meta.documentId,[x,D]=i.useState(e.initialContent),[f,w]=i.useState(e.initialDisplayName),[c,g]=i.useState(!0),[H,$]=i.useState(!1),[J,y]=i.useState(e.hasLocalDraft??!1),[m,S]=i.useState(!1),[E,_]=i.useState(!1),[b,N]=i.useState(!1),[M,P]=i.useState(!1),[X,Z]=i.useState([]),[p,v]=i.useState(!1),[B,A]=i.useState(e.meta.permission),[R,K]=i.useState(!1),[ee,T]=i.useState(!1),[k,te]=i.useState(new Map),z=i.useRef(null),O=i.useRef(null),d=i.useRef(null),V=i.useRef(x),L=i.useRef(f);V.current=x,L.current=f;const ne=e.canEdit&&!c;i.useEffect(()=>{D(e.initialContent),w(e.initialDisplayName),g(!0)},[r]),i.useEffect(()=>{e.contentRevision&&(D(e.initialContent),w(e.initialDisplayName))},[e.contentRevision]),i.useEffect(()=>{let t=!0;return fe().then(s=>{t&&Z(s)}).catch(()=>{}),()=>{t=!1}},[]),i.useEffect(()=>{let t=!0;return he(r).then(s=>{t&&S(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),i.useEffect(()=>{let t=!1;const s=q();return xe(r).then(o=>{var j;if(t||q()!==s)return;const u=!!(o&&!o.published);y(u),(j=e.onDraftExistsChange)==null||j.call(e,u)}),()=>{t=!0}},[r,e.onDraftExistsChange]),i.useEffect(()=>ve((t,s)=>{var o;t===r&&(y(s),(o=e.onDraftExistsChange)==null||o.call(e,s))}),[r,e.onDraftExistsChange]),i.useEffect(()=>{A(e.meta.permission)},[e.meta.permission,r]),i.useEffect(()=>{const t=s=>{z.current&&!z.current.contains(s.target)&&N(!1),O.current&&!O.current.contains(s.target)&&P(!1)};return(b||M)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[b,M]);const U=i.useCallback(async()=>{var t;await ge(r).execute(()=>ye({documentId:r,content:V.current,displayName:L.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),y(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),G=i.useCallback(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{U()},1e3)},[U]);i.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);async function F(t){var s;if(e.canEdit){$(!0);try{d.current&&(clearTimeout(d.current),d.current=null),await U(),await e.onPublish(V.current,L.current.trim()||f,r,t),y(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{$(!1)}}}async function ie(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(f.trim()!==t)try{await F()}catch{}}async function W(){var t,s;if(!E){_(!0);try{m?(await Ce(r),S(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Ie(r),S(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{_(!1)}}}function ae(t){const s=X.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function se(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const l=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),oe=i.useMemo(()=>{const t=(l==null?void 0:l.permission)??"public";return be(t)},[l==null?void 0:l.permission]);function re(t){return t===C.PRIVATE?a("permissionPrivate"):t===C.DOMAIN_READ?a("permissionInvite"):t===C.DOMAIN_WRITE?a("permissionDomainWrite"):t===C.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function de(){if(R||B===e.meta.permission){v(!1);return}K(!0);try{await F(B),v(!1)}finally{K(!1)}}async function le(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of k)s.has(o)||await we(r,o);for(const o of t)k.get(o.visitorId)!==o.permission&&await Se(r,o.visitorId,o.permission);T(!1)}function h(){N(!1),P(!1)}function Q(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,u={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreator")}),n.jsx("span",{children:ae(e.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreatedAt")}),n.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(I==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:se(new Blob([x]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(I==="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:u,onClick:()=>{W(),t()},children:[n.jsx("span",{children:m?"⭐":"☆"}),n.jsx("span",{children:a(m?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:u,onClick:()=>{t(),(async()=>{const j=await De(r);te(new Map(j.map(Y=>[Y.visitorId,Y.permission]))),T(!0)})()},children:[n.jsx(Ne,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:u,onClick:()=>{t(),A(e.meta.permission),v(!0)},children:[n.jsx(Me,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}const ce=i.useCallback(t=>{var o;const s=t.target.value;D(s),(o=e.onContentChange)==null||o.call(e,s),G()},[e,G]),me=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${x}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(Ee,{fileType:"html",displayName:f,onDisplayNameChange:w,onDisplayNameBlur:()=>void ie(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:ne,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:H,draftExists:J,onPublish:()=>{F().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:m,bookmarkBusy:E,onToggleBookmark:()=>void W(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:Q(h),docInfoOpen:b,onToggleDocInfo:()=>N(!b),docInfoMenuRef:z,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:M,onToggleReaderMore:()=>P(t=>!t),readerMoreMenuRef:O,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:E,onClick:()=>{W(),h()},children:[n.jsx(ke,{size:16,strokeWidth:1.5,style:{color:m?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:m?"#faad14":"none"}}),n.jsx("span",{children:a(m?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!c,onClick:()=>{g(!1),h()},children:a("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:c,onClick:()=>{g(!0),h()},children:a("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:H,onClick:()=>{h(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),Q(h,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":a(c?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:c,onChange:()=>g(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:a("edit")}),n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--right",children:a("preview")})]})]}):null}),n.jsxs("div",{className:"mdocs-html-editor-body",children:[!c&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:x,onChange:ce,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:me,sandbox:"",title:f})})]}),p&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&v(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",l?je(l.domainName,I,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:oe.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:B===t,onChange:()=>A(t)}),n.jsx("span",{children:re(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>v(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:R,onClick:()=>void de(),children:a(R?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Pe,{open:ee,title:a("docInfoInviteMember"),initialSelectedIds:[...k.keys()],initialPermissions:k,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>T(!1),onConfirm:t=>{le(t)}})]})}export{Ue as HtmlEditor};
@@ -1,4 +1,4 @@
1
- import{r as x,j as i}from"./react-vendor-BuABiQkA.js";import{b as K,aB as H,aC as Y,aD as Z,aE as ee}from"./index-vbUbFD-2.js";import{E as te,B as ne}from"./react-DCTIdd3e.js";import{g as le}from"./file-type-policy-GUk904tm.js";import"./ui-CvA4pq3d.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";function U({lexicalJson:e,onMarkdown:n,onError:c}){const[s,l]=x.useState(null),o=x.useRef(!1);return x.useEffect(()=>{o.current=!1},[e]),x.useEffect(()=>{if(!(!s||o.current))try{s.setDocument("json",e);const a=s.getDocument("markdown");typeof a=="string"&&(o.current=!0,n(a))}catch{c==null||c()}},[s,e,n,c]),i.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:i.jsx(te,{content:e,type:"json",editable:!1,onInit:l,plugins:[ne]})})}function se(e){const{t:n}=K(),[c,s]=x.useState(0),l=e.segments.filter(t=>t.kind==="conflict"),o=e.unresolvedCount>0;x.useEffect(()=>{if(l.length===0){s(0);return}s(t=>Math.min(t,l.length-1))},[l.length]);function a(t){l.length!==0&&s(d=>{var m;const u=(d+t+l.length)%l.length;return(m=document.getElementById(`mdocs-merge-hunk-${u}`))==null||m.scrollIntoView({block:"center",behavior:"smooth"}),u})}let r=-1;return i.jsxs("div",{className:"mdocs-merge-inline-pane",children:[i.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[i.jsx("span",{className:"mdocs-merge-inline-hint",children:o?n("mergeReviewHint"):l.length===0?n("mergeNoConflicts"):n("mergeEditAfterResolve")}),l.length>0?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",onClick:e.onUseAllMine,children:n("mergeUseAllMine")}),i.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:n("mergeUseAllTheirs")})]}):null]}),o?i.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((t,d)=>{if(t.kind==="unchanged")return i.jsx("pre",{className:"mdocs-merge-inline-same",children:t.lines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},C))},`u-${d}`);r+=1;const u=r,m=t.resolution!=="unresolved",f=u===c;return i.jsxs("div",{id:`mdocs-merge-hunk-${u}`,className:"mdocs-merge-inline-hunk"+(f?" is-active":"")+(m?" is-resolved":""),onClick:()=>s(u),children:[m?i.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:t.resolution==="remote"?n("mergeReceive"):n("mergeReject")}):i.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:g=>{g.stopPropagation(),e.onReject(t.id)},children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:g=>{g.stopPropagation(),e.onReceive(t.id)},children:n("mergeReceive")})]}),i.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[t.localLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line del",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`l${C}`)),t.remoteLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line add",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`r${C}`))]})]},t.id)}),l.length>0?i.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[i.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>a(-1),children:"↑"}),i.jsxs("span",{children:[c+1," / ",l.length]}),i.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>a(1),children:"↓"}),l[c]&&l[c].resolution==="unresolved"?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(l[c].id),children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(l[c].id),children:n("mergeReceive")})]}):null]}):null]}):i.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:t=>e.onEditableChange(t.target.value),spellCheck:!1})]})}function ie(e,n){let c={};for(let o=0;o<n.length;o++){const a=n[o];c[a]?c[a].push(o):c[a]=[o]}let l=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let o=0;o<e.length;o++){const a=e[o],r=c[a]||[];let t=0,d=l[0];for(let u=0;u<r.length;u++){const m=r[u];let f;for(f=t;f<l.length&&!(l[f].buffer2index<m&&(f===l.length-1||l[f+1].buffer2index>m));f++);if(f<l.length){const g={buffer1index:o,buffer2index:m,chain:l[f]};if(t===l.length?l.push(d):l[t]=d,t=f+1,d=g,t===l.length)break}}l[t]=d}return l[l.length-1]}function O(e,n){const c=ie(e,n);let s=[],l=e.length,o=n.length;for(let a=c;a!==null;a=a.chain){const r=l-a.buffer1index-1,t=o-a.buffer2index-1;l=a.buffer1index,o=a.buffer2index,(r||t)&&s.push({buffer1:[l+1,r],buffer1Content:e.slice(l+1,l+1+r),buffer2:[o+1,t],buffer2Content:n.slice(o+1,o+1+t)})}return s.reverse(),s}function oe(e,n,c){let s=[];function l(t,d){s.push({ab:d,oStart:t.buffer1[0],oLength:t.buffer1[1],abStart:t.buffer2[0],abLength:t.buffer2[1]})}O(n,e).forEach(t=>l(t,"a")),O(n,c).forEach(t=>l(t,"b")),s.sort((t,d)=>t.oStart-d.oStart);let o=[],a=0;function r(t){t>a&&(o.push({stable:!0,buffer:"o",bufferStart:a,bufferLength:t-a,bufferContent:n.slice(a,t)}),a=t)}for(;s.length;){let t=s.shift(),d=t.oStart,u=t.oStart+t.oLength,m=[t];for(r(d);s.length;){const f=s[0],g=f.oStart;if(g>u)break;u=Math.max(u,g+f.oLength),m.push(s.shift())}if(m.length===1){if(t.abLength>0){const f=t.ab==="a"?e:c;o.push({stable:!0,buffer:t.ab,bufferStart:t.abStart,bufferLength:t.abLength,bufferContent:f.slice(t.abStart,t.abStart+t.abLength)})}}else{let f={a:[e.length,-1,n.length,-1],b:[c.length,-1,n.length,-1]};for(;m.length;){t=m.shift();const b=t.oStart,w=b+t.oLength,L=t.abStart,y=L+t.abLength;let v=f[t.ab];v[0]=Math.min(L,v[0]),v[1]=Math.max(y,v[1]),v[2]=Math.min(b,v[2]),v[3]=Math.max(w,v[3])}const g=f.a[0]+(d-f.a[2]),C=f.a[1]+(u-f.a[3]),k=f.b[0]+(d-f.b[2]),h=f.b[1]+(u-f.b[3]);let p={stable:!1,aStart:g,aLength:C-g,aContent:e.slice(g,C),oStart:d,oLength:u-d,oContent:n.slice(d,u),bStart:k,bLength:h-k,bContent:c.slice(k,h)};o.push(p)}a=u}return r(n.length),o}function ce(e,n,c,s){s=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},s),typeof e=="string"&&(e=e.split(s.stringSeparator)),typeof n=="string"&&(n=n.split(s.stringSeparator)),typeof c=="string"&&(c=c.split(s.stringSeparator));let o=[];const a=oe(e,n,c);let r=[];function t(){r.length&&o.push({ok:r}),r=[]}function d(u,m){if(u.length!==m.length)return!1;for(let f=0;f<u.length;f++)if(u[f]!==m[f])return!1;return!0}return a.forEach(u=>{u.stable?r.push(...u.bufferContent):s.excludeFalseConflicts&&d(u.aContent,u.bContent)?r.push(...u.aContent):(t(),o.push({conflict:{a:u.aContent,aIndex:u.aStart,o:u.oContent,oIndex:u.oStart,b:u.bContent,bIndex:u.bStart}}))}),t(),o}const ae=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function re(e){return`<!-- mdocs-merge-conflict:${e} -->`}function ue(e){const n=e.trim().match(ae);return(n==null?void 0:n[1])??null}function E(e){return e===""?[]:e.split(`
1
+ import{r as x,j as i}from"./react-vendor-BuABiQkA.js";import{c as G,aD as H,aE as Y,aF as Z,aG as ee}from"./index-OmOf_og0.js";import{E as te,B as ne}from"./react-CI5PDFXT.js";import{g as le}from"./file-type-policy-GUk904tm.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./editor-CL03se2B.js";import"./plus-DKKQ-AoS.js";import"./check-soiTDN2u.js";import"./copy-B4fvX0p8.js";function U({lexicalJson:e,onMarkdown:n,onError:c}){const[s,l]=x.useState(null),o=x.useRef(!1);return x.useEffect(()=>{o.current=!1},[e]),x.useEffect(()=>{if(!(!s||o.current))try{s.setDocument("json",e);const a=s.getDocument("markdown");typeof a=="string"&&(o.current=!0,n(a))}catch{c==null||c()}},[s,e,n,c]),i.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:i.jsx(te,{content:e,type:"json",editable:!1,onInit:l,plugins:[ne]})})}function se(e){const{t:n}=G(),[c,s]=x.useState(0),l=e.segments.filter(t=>t.kind==="conflict"),o=e.unresolvedCount>0;x.useEffect(()=>{if(l.length===0){s(0);return}s(t=>Math.min(t,l.length-1))},[l.length]);function a(t){l.length!==0&&s(d=>{var m;const u=(d+t+l.length)%l.length;return(m=document.getElementById(`mdocs-merge-hunk-${u}`))==null||m.scrollIntoView({block:"center",behavior:"smooth"}),u})}let r=-1;return i.jsxs("div",{className:"mdocs-merge-inline-pane",children:[i.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[i.jsx("span",{className:"mdocs-merge-inline-hint",children:o?n("mergeReviewHint"):l.length===0?n("mergeNoConflicts"):n("mergeEditAfterResolve")}),l.length>0?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",onClick:e.onUseAllMine,children:n("mergeUseAllMine")}),i.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:n("mergeUseAllTheirs")})]}):null]}),o?i.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((t,d)=>{if(t.kind==="unchanged")return i.jsx("pre",{className:"mdocs-merge-inline-same",children:t.lines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},C))},`u-${d}`);r+=1;const u=r,m=t.resolution!=="unresolved",f=u===c;return i.jsxs("div",{id:`mdocs-merge-hunk-${u}`,className:"mdocs-merge-inline-hunk"+(f?" is-active":"")+(m?" is-resolved":""),onClick:()=>s(u),children:[m?i.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:t.resolution==="remote"?n("mergeReceive"):n("mergeReject")}):i.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:g=>{g.stopPropagation(),e.onReject(t.id)},children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:g=>{g.stopPropagation(),e.onReceive(t.id)},children:n("mergeReceive")})]}),i.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[t.localLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line del",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`l${C}`)),t.remoteLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line add",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`r${C}`))]})]},t.id)}),l.length>0?i.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[i.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>a(-1),children:"↑"}),i.jsxs("span",{children:[c+1," / ",l.length]}),i.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>a(1),children:"↓"}),l[c]&&l[c].resolution==="unresolved"?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(l[c].id),children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(l[c].id),children:n("mergeReceive")})]}):null]}):null]}):i.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:t=>e.onEditableChange(t.target.value),spellCheck:!1})]})}function ie(e,n){let c={};for(let o=0;o<n.length;o++){const a=n[o];c[a]?c[a].push(o):c[a]=[o]}let l=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let o=0;o<e.length;o++){const a=e[o],r=c[a]||[];let t=0,d=l[0];for(let u=0;u<r.length;u++){const m=r[u];let f;for(f=t;f<l.length&&!(l[f].buffer2index<m&&(f===l.length-1||l[f+1].buffer2index>m));f++);if(f<l.length){const g={buffer1index:o,buffer2index:m,chain:l[f]};if(t===l.length?l.push(d):l[t]=d,t=f+1,d=g,t===l.length)break}}l[t]=d}return l[l.length-1]}function O(e,n){const c=ie(e,n);let s=[],l=e.length,o=n.length;for(let a=c;a!==null;a=a.chain){const r=l-a.buffer1index-1,t=o-a.buffer2index-1;l=a.buffer1index,o=a.buffer2index,(r||t)&&s.push({buffer1:[l+1,r],buffer1Content:e.slice(l+1,l+1+r),buffer2:[o+1,t],buffer2Content:n.slice(o+1,o+1+t)})}return s.reverse(),s}function oe(e,n,c){let s=[];function l(t,d){s.push({ab:d,oStart:t.buffer1[0],oLength:t.buffer1[1],abStart:t.buffer2[0],abLength:t.buffer2[1]})}O(n,e).forEach(t=>l(t,"a")),O(n,c).forEach(t=>l(t,"b")),s.sort((t,d)=>t.oStart-d.oStart);let o=[],a=0;function r(t){t>a&&(o.push({stable:!0,buffer:"o",bufferStart:a,bufferLength:t-a,bufferContent:n.slice(a,t)}),a=t)}for(;s.length;){let t=s.shift(),d=t.oStart,u=t.oStart+t.oLength,m=[t];for(r(d);s.length;){const f=s[0],g=f.oStart;if(g>u)break;u=Math.max(u,g+f.oLength),m.push(s.shift())}if(m.length===1){if(t.abLength>0){const f=t.ab==="a"?e:c;o.push({stable:!0,buffer:t.ab,bufferStart:t.abStart,bufferLength:t.abLength,bufferContent:f.slice(t.abStart,t.abStart+t.abLength)})}}else{let f={a:[e.length,-1,n.length,-1],b:[c.length,-1,n.length,-1]};for(;m.length;){t=m.shift();const b=t.oStart,w=b+t.oLength,L=t.abStart,y=L+t.abLength;let v=f[t.ab];v[0]=Math.min(L,v[0]),v[1]=Math.max(y,v[1]),v[2]=Math.min(b,v[2]),v[3]=Math.max(w,v[3])}const g=f.a[0]+(d-f.a[2]),C=f.a[1]+(u-f.a[3]),k=f.b[0]+(d-f.b[2]),h=f.b[1]+(u-f.b[3]);let p={stable:!1,aStart:g,aLength:C-g,aContent:e.slice(g,C),oStart:d,oLength:u-d,oContent:n.slice(d,u),bStart:k,bLength:h-k,bContent:c.slice(k,h)};o.push(p)}a=u}return r(n.length),o}function ce(e,n,c,s){s=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},s),typeof e=="string"&&(e=e.split(s.stringSeparator)),typeof n=="string"&&(n=n.split(s.stringSeparator)),typeof c=="string"&&(c=c.split(s.stringSeparator));let o=[];const a=oe(e,n,c);let r=[];function t(){r.length&&o.push({ok:r}),r=[]}function d(u,m){if(u.length!==m.length)return!1;for(let f=0;f<u.length;f++)if(u[f]!==m[f])return!1;return!0}return a.forEach(u=>{u.stable?r.push(...u.bufferContent):s.excludeFalseConflicts&&d(u.aContent,u.bContent)?r.push(...u.aContent):(t(),o.push({conflict:{a:u.aContent,aIndex:u.aStart,o:u.oContent,oIndex:u.oStart,b:u.bContent,bIndex:u.bStart}}))}),t(),o}const ae=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function re(e){return`<!-- mdocs-merge-conflict:${e} -->`}function ue(e){const n=e.trim().match(ae);return(n==null?void 0:n[1])??null}function E(e){return e===""?[]:e.split(`
2
2
  `)}function V(e,n){return e.length===n.length&&e.every((c,s)=>c===n[s])}function de(e,n,c){const s=E(e),l=E(n),o=E(c);if(l.length===0&&n==="")return me(e,c);const a=ce(s,l,o),r=[];let t=0,d=0,u=0,m=0;const f=(C,k,h,p)=>{r.push({kind:"conflict",id:`conflict-${t}`,conflictKind:p,baseLines:C,localLines:k,remoteLines:h,resolution:"unresolved"}),t+=1},g=(C,k,h)=>{if(k.length===0&&C.length===0&&h.length===0)return;if(V(C,k)&&V(h,k)){k.length>0&&r.push({kind:"unchanged",lines:[...k]});return}if(C.length===k.length&&h.length===k.length){let b=[];const w=()=>{b.length>0&&(r.push({kind:"unchanged",lines:b}),b=[])};for(let L=0;L<k.length;L+=1){const y=k[L],v=C[L],I=h[L];v===y&&I===y?b.push(y):(w(),f([y],[v],[I],v!==y&&I!==y&&v!==I?"true_conflict":"change"))}w();return}const p=C.join(`
3
3
  `)!==k.join(`
4
4
  `)&&h.join(`
@@ -7,4 +7,4 @@ import{r as x,j as i}from"./react-vendor-BuABiQkA.js";import{b as K,aB as H,aC a
7
7
  `)!==h.join(`
8
8
  `)?"true_conflict":"change";f(k,C,h,p)};for(let C=0;C<a.length;C+=1){const k=a[C],h=k.conflict;if(h){g(s.slice(d,h.aIndex),l.slice(u,h.oIndex),o.slice(m,h.bIndex)),f(h.o,h.a,h.b,"true_conflict"),d=h.aIndex+h.a.length,u=h.oIndex+h.o.length,m=h.bIndex+h.b.length;continue}if(k.ok){const p=a[C+1],b=p==null?void 0:p.conflict;b?(g(s.slice(d,b.aIndex),l.slice(u,b.oIndex),o.slice(m,b.bIndex)),d=b.aIndex,u=b.oIndex,m=b.bIndex):(g(s.slice(d),l.slice(u),o.slice(m)),d=s.length,u=l.length,m=o.length)}}return r}function fe(e,n){const c=e.length,s=n.length,l=Array.from({length:c+1},()=>new Array(s+1).fill(0));for(let t=1;t<=c;t+=1)for(let d=1;d<=s;d+=1)e[t-1]===n[d-1]?l[t][d]=l[t-1][d-1]+1:l[t][d]=Math.max(l[t-1][d],l[t][d-1]);const o=[];let a=c,r=s;for(;a>0||r>0;)a>0&&r>0&&e[a-1]===n[r-1]?(o.push({type:"equal",line:e[a-1]}),a-=1,r-=1):r>0&&(a===0||l[a][r-1]>=l[a-1][r])?(o.push({type:"add",line:n[r-1]}),r-=1):(o.push({type:"del",line:e[a-1]}),a-=1);return o.reverse()}function me(e,n){const c=E(e),s=E(n),l=fe(c,s),o=[];let a=0,r=0;for(;r<l.length;){if(l[r].type==="equal"){const m=[];for(;r<l.length&&l[r].type==="equal";)m.push(l[r].line),r+=1;o.push({kind:"unchanged",lines:m});continue}const d=[],u=[];for(;r<l.length&&l[r].type!=="equal";){const m=l[r];m.type==="del"&&d.push(m.line),m.type==="add"&&u.push(m.line),r+=1}o.push({kind:"conflict",id:`conflict-${a}`,conflictKind:"true_conflict",baseLines:[],localLines:d,remoteLines:u,resolution:"unresolved"}),a+=1}return o}function he(e){return e.filter(n=>n.kind==="conflict").length}function ge(e){return e.filter(n=>n.kind==="conflict"&&n.resolution==="unresolved").length}function be(e){switch(e.resolution){case"local":return e.localLines;case"remote":return e.remoteLines;case"both":return[...e.localLines,...e.remoteLines];case"manual":return e.manualLines??[];default:return[]}}function xe(e){const n=[];for(const c of e)c.kind==="unchanged"?n.push(...c.lines):c.resolution==="unresolved"?n.push(re(c.id)):n.push(...be(c));return n.join(`
9
9
  `)}function W(e){return E(e).filter(n=>!ue(n)).join(`
10
- `)}function F(e,n,c,s){return e.map(l=>l.kind!=="conflict"||l.id!==n?l:{...l,resolution:c,manualLines:c==="manual"?l.manualLines??[]:void 0})}function Ee(e){var _;const{t:n}=K(),s=(((_=le(e.fileType??"md"))==null?void 0:_.mergePipeline)??"lexical-md-bridge")==="raw-text",[l,o]=x.useState(""),[a,r]=x.useState(""),[t,d]=x.useState(null),[u,m]=x.useState(!1),[f,g]=x.useState(!1),[C,k]=x.useState(null),[h,p]=x.useState(""),[b,w]=x.useState(null),[L,y]=x.useState(null),[v,I]=x.useState(!1),[A,M]=x.useState(!0);x.useEffect(()=>{let S=!1;return M(!0),k(null),p(""),w(null),y(null),(async()=>{try{const j=await H(e.documentId);if(S)return;s?(p(j.content),M(!1)):k(j.content)}catch{S||e.onError(n("mergeLoadRemoteFailed")),S||M(!1)}})(),()=>{S=!0}},[e.documentId,e.onError,n,s]),x.useEffect(()=>{let S=!1;return d(null),r(""),m(!1),g(!1),(async()=>{try{const j=await Y(e.documentId,e.conflict.localBaseCommitId,e.conflict.remoteCommitId);if(S)return;if(j.mode==="three_way"&&j.mergeBaseContent){s?(r(j.mergeBaseContent),g(!0)):d(j.mergeBaseContent);return}m(!0),g(!0)}catch{if(S)return;m(!0),g(!0)}})(),()=>{S=!0}},[e.documentId,e.conflict.localBaseCommitId,e.conflict.remoteCommitId,s]),x.useEffect(()=>{s&&o(e.conflict.localSnapshotContent)},[s,e.conflict.localSnapshotContent]);const z=x.useCallback(S=>{p(S),M(!1)},[]),G=x.useCallback(S=>{o(S)},[]),J=x.useCallback(S=>{r(S),g(!0)},[]),Q=x.useCallback(()=>{m(!0),r(""),g(!0)},[]);x.useEffect(()=>{!l||!h||A||!f||(w(de(l,a,h)),y(null))},[l,h,a,f,A,e.conflict.remoteCommitId]);const P=x.useMemo(()=>b?W(xe(b)):"",[b]),B=b?he(b):0,N=b?ge(b):0,$=L??P;x.useEffect(()=>{N===0&&b&&L===null&&y(P)},[N,b,P,L]);function D(S){w(j=>{if(!j)return j;let R=j;for(const q of j)q.kind==="conflict"&&(R=F(R,q.id,S));return R}),y(null)}async function X(){if(N>0){e.onError(n("mergeConflictsUnresolved",{count:String(N)}));return}const S=W($);I(!0);try{const j=s?S:(await Z({content:S,from:"markdown",to:"lexical"})).content;await ee(e.documentId,{content:j,displayName:e.displayName,version:{localBaseCommitId:e.conflict.localBaseCommitId,merge:{remoteCommitId:e.conflict.remoteCommitId,localSnapshotContent:e.conflict.localSnapshotContent}}});const R=await H(e.documentId);e.onSuccess(R)}catch(j){e.onError(j instanceof Error?j.message:String(j))}finally{I(!1)}}const T=!!(l&&h&&b&&!A&&f);return i.jsxs("div",{className:"mdocs-merge-overlay",children:[s?null:i.jsxs(i.Fragment,{children:[i.jsx(U,{lexicalJson:e.conflict.localSnapshotContent,onMarkdown:G,onError:()=>e.onError(n("mergeLoadLocalFailed"))}),t?i.jsx(U,{lexicalJson:t,onMarkdown:J,onError:Q}):null,C?i.jsx(U,{lexicalJson:C,onMarkdown:z,onError:()=>{M(!1),e.onError(n("mergeLoadRemoteFailed"))}}):null]}),i.jsxs("header",{className:"mdocs-merge-toolbar",children:[i.jsxs("div",{className:"mdocs-merge-toolbar-title",children:[i.jsx("h2",{children:n("mergeTitle")}),T&&B>0?i.jsx("span",{className:`mdocs-merge-conflict-pill ${N>0?"pending":"resolved"}`,children:N>0?n("mergeConflictsPending",{unresolved:String(N),total:String(B)}):n("mergeConflictsResolved",{total:String(B)})}):null,u?i.jsx("span",{className:"mdocs-merge-base-warning",children:n("mergeBaseMissing")}):null]}),i.jsxs("div",{className:"mdocs-merge-toolbar-actions",children:[i.jsx("button",{type:"button",className:"secondary",disabled:v,onClick:e.onClose,children:n("cancel")}),i.jsx("button",{type:"button",className:"primary",disabled:v||!T||N>0,onClick:()=>void X(),children:n(v?"publishing":"mergeComplete")})]})]}),i.jsx("div",{className:"mdocs-merge-body mdocs-merge-body--inline",children:T?i.jsx(se,{segments:b,unresolvedCount:N,onReceive:S=>{w(j=>j&&F(j,S,"remote")),y(null)},onReject:S=>{w(j=>j&&F(j,S,"local")),y(null)},onUseAllMine:()=>D("local"),onUseAllTheirs:()=>D("remote"),editableMarkdown:$,onEditableChange:y}):i.jsx("p",{className:"mdocs-merge-loading",children:n("mergeLoadingRemote")})})]})}export{Ee as MergeView};
10
+ `)}function B(e,n,c,s){return e.map(l=>l.kind!=="conflict"||l.id!==n?l:{...l,resolution:c,manualLines:c==="manual"?l.manualLines??[]:void 0})}function Ee(e){var _;const{t:n}=G(),s=(((_=le(e.fileType??"md"))==null?void 0:_.mergePipeline)??"lexical-md-bridge")==="raw-text",[l,o]=x.useState(""),[a,r]=x.useState(""),[t,d]=x.useState(null),[u,m]=x.useState(!1),[f,g]=x.useState(!1),[C,k]=x.useState(null),[h,p]=x.useState(""),[b,w]=x.useState(null),[L,y]=x.useState(null),[v,I]=x.useState(!1),[A,M]=x.useState(!0);x.useEffect(()=>{let S=!1;return M(!0),k(null),p(""),w(null),y(null),(async()=>{try{const j=await H(e.documentId);if(S)return;s?(p(j.content),M(!1)):k(j.content)}catch{S||e.onError(n("mergeLoadRemoteFailed")),S||M(!1)}})(),()=>{S=!0}},[e.documentId,e.onError,n,s]),x.useEffect(()=>{let S=!1;return d(null),r(""),m(!1),g(!1),(async()=>{try{const j=await Y(e.documentId,e.conflict.localBaseCommitId,e.conflict.remoteCommitId);if(S)return;if(j.mode==="three_way"&&j.mergeBaseContent){s?(r(j.mergeBaseContent),g(!0)):d(j.mergeBaseContent);return}m(!0),g(!0)}catch{if(S)return;m(!0),g(!0)}})(),()=>{S=!0}},[e.documentId,e.conflict.localBaseCommitId,e.conflict.remoteCommitId,s]),x.useEffect(()=>{s&&o(e.conflict.localSnapshotContent)},[s,e.conflict.localSnapshotContent]);const K=x.useCallback(S=>{p(S),M(!1)},[]),z=x.useCallback(S=>{o(S)},[]),J=x.useCallback(S=>{r(S),g(!0)},[]),Q=x.useCallback(()=>{m(!0),r(""),g(!0)},[]);x.useEffect(()=>{!l||!h||A||!f||(w(de(l,a,h)),y(null))},[l,h,a,f,A,e.conflict.remoteCommitId]);const P=x.useMemo(()=>b?W(xe(b)):"",[b]),F=b?he(b):0,N=b?ge(b):0,$=L??P;x.useEffect(()=>{N===0&&b&&L===null&&y(P)},[N,b,P,L]);function D(S){w(j=>{if(!j)return j;let R=j;for(const q of j)q.kind==="conflict"&&(R=B(R,q.id,S));return R}),y(null)}async function X(){if(N>0){e.onError(n("mergeConflictsUnresolved",{count:String(N)}));return}const S=W($);I(!0);try{const j=s?S:(await Z({content:S,from:"markdown",to:"lexical"})).content;await ee(e.documentId,{content:j,displayName:e.displayName,version:{localBaseCommitId:e.conflict.localBaseCommitId,merge:{remoteCommitId:e.conflict.remoteCommitId,localSnapshotContent:e.conflict.localSnapshotContent}}});const R=await H(e.documentId);e.onSuccess(R)}catch(j){e.onError(j instanceof Error?j.message:String(j))}finally{I(!1)}}const T=!!(l&&h&&b&&!A&&f);return i.jsxs("div",{className:"mdocs-merge-overlay",children:[s?null:i.jsxs(i.Fragment,{children:[i.jsx(U,{lexicalJson:e.conflict.localSnapshotContent,onMarkdown:z,onError:()=>e.onError(n("mergeLoadLocalFailed"))}),t?i.jsx(U,{lexicalJson:t,onMarkdown:J,onError:Q}):null,C?i.jsx(U,{lexicalJson:C,onMarkdown:K,onError:()=>{M(!1),e.onError(n("mergeLoadRemoteFailed"))}}):null]}),i.jsxs("header",{className:"mdocs-merge-toolbar",children:[i.jsxs("div",{className:"mdocs-merge-toolbar-title",children:[i.jsx("h2",{children:n("mergeTitle")}),T&&F>0?i.jsx("span",{className:`mdocs-merge-conflict-pill ${N>0?"pending":"resolved"}`,children:N>0?n("mergeConflictsPending",{unresolved:String(N),total:String(F)}):n("mergeConflictsResolved",{total:String(F)})}):null,u?i.jsx("span",{className:"mdocs-merge-base-warning",children:n("mergeBaseMissing")}):null]}),i.jsxs("div",{className:"mdocs-merge-toolbar-actions",children:[i.jsx("button",{type:"button",className:"secondary",disabled:v,onClick:e.onClose,children:n("cancel")}),i.jsx("button",{type:"button",className:"primary",disabled:v||!T||N>0,onClick:()=>void X(),children:n(v?"publishing":"mergeComplete")})]})]}),i.jsx("div",{className:"mdocs-merge-body mdocs-merge-body--inline",children:T?i.jsx(se,{segments:b,unresolvedCount:N,onReceive:S=>{w(j=>j&&B(j,S,"remote")),y(null)},onReject:S=>{w(j=>j&&B(j,S,"local")),y(null)},onUseAllMine:()=>D("local"),onUseAllTheirs:()=>D("remote"),editableMarkdown:$,onEditableChange:y}):i.jsx("p",{className:"mdocs-merge-loading",children:n("mergeLoadingRemote")})})]})}export{Ee as MergeView};
@@ -1,4 +1,4 @@
1
- import{r as n,j as o,ad as C}from"./react-vendor-BuABiQkA.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-DCTIdd3e.js";import{a7 as Q,a8 as X,a9 as ee,aa as te,ab as k,ac as oe}from"./ui-CvA4pq3d.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,c as R,o as ce}from"./Toolbar-D5TrWh7K.js";import{N as me}from"./index-vbUbFD-2.js";import"./editor-CL03se2B.js";import"./diagram-Bk84WZto.js";import"./plus-BR1kwsYl.js";import"./check-s9DVK_zH.js";import"./copy-D_-gX8nM.js";import"./motion-DFABYlwt.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[g,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:g,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,g]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");g(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(J,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(W,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{ce(l=>{for(const u of l)e.dispatchCommand(z,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
1
+ import{r as n,j as o,ad as C}from"./react-vendor-BuABiQkA.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-CI5PDFXT.js";import{a7 as Q,a8 as X,a9 as ee,aa as te,ab as k,ac as oe}from"./ui-CvA4pq3d.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,c as R,o as ce}from"./Toolbar-Hsam79hu.js";import{N as me}from"./index-OmOf_og0.js";import"./editor-CL03se2B.js";import"./diagram-Bk84WZto.js";import"./plus-DKKQ-AoS.js";import"./check-soiTDN2u.js";import"./copy-B4fvX0p8.js";import"./motion-DFABYlwt.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[g,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:g,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,g]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");g(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(J,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(W,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{ce(l=>{for(const u of l)e.dispatchCommand(z,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
2
2
  123`),queueMicrotask(()=>{e.focus()})}},{key:"insert-link",label:"InsertLink",onSelect:e=>{e.dispatchCommand(B,{url:"https://example.com"}),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeInline",label:"InsertCodeInline",onSelect:e=>{e.dispatchCommand($,void 0),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeBlock",label:"InsertCodeBlock",onSelect:e=>{e.dispatchCommand(K,void 0),queueMicrotask(()=>{e.focus()})}},{icon:de,key:"meta2d",label:"Meta2d",onSelect:e=>{e.dispatchCommand(Y,void 0),queueMicrotask(()=>{e.focus()})}},{icon:me,key:"markmap",label:"Markmap",onSelect:e=>{e.dispatchCommand(G,void 0),queueMicrotask(()=>{e.focus()})}}].map(e=>e.type==="divider"?e:{...e,extra:o.jsx(oe,{code:!0,fontSize:12,type:"secondary",children:e.key})}),[]);return o.jsxs(ue,{json:m,markdown:p,onJSONChange:s,...h,children:[o.jsx(R,{editor:r}),o.jsx(T,{className:"mdocs-playground-editor",content:ye,editor:r,lineEmptyPlaceholder:"Start typing here...",mentionOption:{items:d,markdownWriter:t=>{var e;return`
3
3
  <mention>${t.label}[${((e=t.metadata)==null?void 0:e.id)||t.label}]</mention>
4
4
  `},onSelect:(t,e)=>{t.dispatchCommand(U,{label:String(e.label),metadata:{id:e.key}})},searchKeys:["label"]},onInit:x,onTextChange:c,pasteVSCodeAsCodeBlock:!0,placeholder:"Type something...",plugins:[I,E,M,j,O,P,A,_,D,L,f(H,{children:o.jsx(R,{editor:r,floating:!0})}),f(F,{delay:1e3,onAutoComplete:async({input:t,afterText:e,selectionType:l,abortSignal:u})=>{console.log("Auto-complete triggered:",{afterText:e,input:t,selectionType:l});try{const v=await fetch(`${location.origin}/nodeserver/completion`,{body:JSON.stringify({prompt:`Please complete the following text: