@fgbg/mdocs 1.3.32 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-skills/changelog/SKILL.md +25 -0
- package/agent-skills/usage-onboarding-ai/SKILL.md +17 -5
- package/agent-skills/usage-settings/SKILL.md +1 -1
- package/dist/server/agent/Agent/run-manager.js +316 -0
- package/dist/server/agent/Agent/run-manager.js.map +1 -0
- package/dist/server/agent/Agent/run-manager.test.js +122 -0
- package/dist/server/agent/Agent/run-manager.test.js.map +1 -0
- package/dist/server/agent/Agent/run-store.js +141 -0
- package/dist/server/agent/Agent/run-store.js.map +1 -0
- package/dist/server/agent/Agent/run-store.test.js +64 -0
- package/dist/server/agent/Agent/run-store.test.js.map +1 -0
- package/dist/server/agent/Agent/system-prompt.js +2 -2
- package/dist/server/agent/Agent/tools-registry.test.js +1 -0
- package/dist/server/agent/Agent/tools-registry.test.js.map +1 -1
- package/dist/server/agent/Agent/tools-user-skills.js +50 -39
- package/dist/server/agent/Agent/tools-user-skills.js.map +1 -1
- package/dist/server/agent/Agent/user-skills.js +11 -5
- package/dist/server/agent/Agent/user-skills.js.map +1 -1
- package/dist/server/agent/Config/config.js +16 -0
- package/dist/server/agent/Config/config.js.map +1 -1
- package/dist/server/agent/Config/config.test.js +29 -0
- package/dist/server/agent/Config/config.test.js.map +1 -1
- package/dist/server/app.js +3 -0
- package/dist/server/app.js.map +1 -1
- package/dist/server/db/repositories/agent-model-config.repo.js +4 -4
- package/dist/server/db/repositories/agent-model-config.repo.js.map +1 -1
- package/dist/server/db/repositories/agent-user-skill.repo.js +7 -5
- package/dist/server/db/repositories/agent-user-skill.repo.js.map +1 -1
- package/dist/server/db/repositories/agent-user-skill.repo.test.js +31 -0
- package/dist/server/db/repositories/agent-user-skill.repo.test.js.map +1 -0
- package/dist/server/db/schema.js +10 -0
- package/dist/server/db/schema.js.map +1 -1
- package/dist/server/routes/agent.routes.js +107 -18
- package/dist/server/routes/agent.routes.js.map +1 -1
- package/dist/server/search/document-index-manager.js +51 -8
- package/dist/server/search/document-index-manager.js.map +1 -1
- package/dist/server/search/document-index-manager.test.js +78 -2
- package/dist/server/search/document-index-manager.test.js.map +1 -1
- package/dist/shared/file-type-policy.js +1 -1
- package/dist/shared/file-type-policy.js.map +1 -1
- package/dist/shared/file-type-policy.test.js +3 -2
- package/dist/shared/file-type-policy.test.js.map +1 -1
- package/dist/web/assets/AgentChatPanel-_IV-LAS4.js +42 -0
- package/dist/web/assets/{AiWriteWorkbench-B7MnIKzJ.js → AiWriteWorkbench-DzJAmRHY.js} +3 -3
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-D12WH5JY.js → DiagramEditor-NtNY3sZL-KWdKFFEL.js} +1 -1
- package/dist/web/assets/{DocChrome-CjNrjXnZ.js → DocChrome-CtT7xOl6.js} +4 -4
- package/dist/web/assets/{DocumentEditor-BcktjJUV.js → DocumentEditor-CrU6HKmU.js} +1 -1
- package/dist/web/assets/{HtmlEditor-D-H5FPUP.js → HtmlEditor-BBcreXJD.js} +1 -1
- package/dist/web/assets/{MergeView-a2_gRrrh.js → MergeView-LV_hny8a.js} +1 -1
- package/dist/web/assets/{PlaygroundPage-BXmSDi40.js → PlaygroundPage-Bo9rM8MY.js} +1 -1
- package/dist/web/assets/SettingsPage-D09P0j48.js +21 -0
- package/dist/web/assets/SheetEditor-BPTMQ2s5.css +1 -0
- package/dist/web/assets/SheetEditor-Dyk-jpRL.js +26 -0
- package/dist/web/assets/{Toolbar-Caimz2EG.js → Toolbar-C1HmC2Qc.js} +1 -1
- package/dist/web/assets/{VisitorPickerModal-BiMxEHCX.js → VisitorPickerModal-Cx03Papl.js} +1 -1
- package/dist/web/assets/{check-IPzs2Va9.js → check-BAYRiedE.js} +1 -1
- package/dist/web/assets/{copy-Bp0JPDN6.js → copy-J9XXv57X.js} +1 -1
- package/dist/web/assets/{file-type-policy-C6Nun42Q.js → file-type-policy-aRrzC4LZ.js} +1 -1
- package/dist/web/assets/{index-DHKGh7I3.js → index-Btfv_3-Q.js} +46 -46
- package/dist/web/assets/{italic-BOhgURiY.js → italic-BfR6fH81.js} +1 -1
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-Bjx9jCbC.js → meta2dEngine-BD2XbzaV-MY1Hyyeh.js} +1 -1
- package/dist/web/assets/{plus-BMAfiGed.js → plus-DvWl4lHk.js} +1 -1
- package/dist/web/assets/{react-BiN5Ertc.js → react-C7aGt3wN.js} +3 -3
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/AgentChatPanel-BJ49TwV5.js +0 -42
- package/dist/web/assets/SettingsPage-xJkP4WaU.js +0 -21
- package/dist/web/assets/SheetEditor-BV3loL4j.js +0 -26
- package/dist/web/assets/SheetEditor-DbT_K_Ia.css +0 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diagram-BF8g9yg4.js","assets/ui-CEFkTVnG.js","assets/react-vendor-BVS1XoFi.js","assets/motion-BAXVQJfN.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as o,j as e,_ as Jt,b as Qt}from"./react-vendor-BVS1XoFi.js";import{o as G,av as es,aR as ts,aS as wt,aT as ss,N as St,C as ns,aU as Ct,X as we,aV as gt,aW as as,aX as rs,aY as oe,_ as xt,aZ as is,a_ as yt,aF as os,a$ as be,b0 as ls,b1 as cs,b2 as ds,b3 as us,b4 as At,b5 as ms,b6 as ps,b7 as fs,b8 as hs,b9 as gs}from"./index-Btfv_3-Q.js";import{C as It}from"./check-BAYRiedE.js";import{C as _t,a as Rt}from"./copy-J9XXv57X.js";import{P as xs}from"./plus-DvWl4lHk.js";import{ar as ys,ah as js}from"./ui-CEFkTVnG.js";import"./diagram-BF8g9yg4.js";import"./motion-BAXVQJfN.js";/**
|
|
3
|
+
* @license lucide-react v0.562.0 - ISC
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the ISC license.
|
|
6
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/const ks=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Ns=G("arrow-down",ks);/**
|
|
8
|
+
* @license lucide-react v0.562.0 - ISC
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the ISC license.
|
|
11
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/const bs=[["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"}]],vs=G("history",bs);/**
|
|
13
|
+
* @license lucide-react v0.562.0 - ISC
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the ISC license.
|
|
16
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/const ws=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],Ss=G("maximize-2",ws);/**
|
|
18
|
+
* @license lucide-react v0.562.0 - ISC
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the ISC license.
|
|
21
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
22
|
+
*/const Cs=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],As=G("minimize-2",Cs);/**
|
|
23
|
+
* @license lucide-react v0.562.0 - ISC
|
|
24
|
+
*
|
|
25
|
+
* This source code is licensed under the ISC license.
|
|
26
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
27
|
+
*/const Is=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],_s=G("pencil",Is);/**
|
|
28
|
+
* @license lucide-react v0.562.0 - ISC
|
|
29
|
+
*
|
|
30
|
+
* This source code is licensed under the ISC license.
|
|
31
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
32
|
+
*/const Rs=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]],Ms=G("pin",Rs);/**
|
|
33
|
+
* @license lucide-react v0.562.0 - ISC
|
|
34
|
+
*
|
|
35
|
+
* This source code is licensed under the ISC license.
|
|
36
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
37
|
+
*/const Es=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Ds=G("zoom-in",Es);/**
|
|
38
|
+
* @license lucide-react v0.562.0 - ISC
|
|
39
|
+
*
|
|
40
|
+
* This source code is licensed under the ISC license.
|
|
41
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
42
|
+
*/const $s=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],zs=G("zoom-out",$s),Pe=5;function Ts(a){const s=o.useRef(!0),l=o.useRef(null),[d,f]=o.useState([]),[y,w]=o.useState(!1),[j,A]=o.useState(null);o.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),o.useEffect(()=>{(async()=>{try{const p=await es();if(!s.current)return;f(p)}catch(p){if(!s.current)return;A(p instanceof Error?p.message:String(p))}})()},[]),o.useEffect(()=>{if(!y)return;function p(x){const S=l.current;!S||S.contains(x.target)||w(!1)}function u(x){x.key==="Escape"&&w(!1)}return document.addEventListener("mousedown",p),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",u)}},[y]);const g=d.filter(p=>a.selectedNames.includes(p.name));function I(p){if(a.disabled)return;const u=new Set(a.selectedNames);if(u.has(p))u.delete(p);else{if(u.size>=Pe)return;u.add(p)}a.onChange([...u])}return d.length===0&&!j?null:e.jsxs("div",{className:"mdocs-agent-skill-ref",ref:l,children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-bar",children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-anchor",children:[y&&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(最多 ",Pe," 个)"]}),e.jsx("ul",{className:"mdocs-agent-skill-popover-list",children:d.map(p=>{const u=a.selectedNames.includes(p.name),x=!u&&a.selectedNames.length>=Pe;return e.jsx("li",{children:e.jsxs("button",{type:"button",role:"option","aria-selected":u,className:"mdocs-agent-skill-popover-item"+(u?" mdocs-agent-skill-popover-item-on":""),disabled:a.disabled||x,onClick:()=>I(p.name),children:[e.jsx("span",{className:"mdocs-agent-skill-popover-check","aria-hidden":!0,children:u?"✓":""}),e.jsxs("span",{className:"mdocs-agent-skill-popover-text",children:[e.jsx("span",{className:"mdocs-agent-skill-popover-name",children:p.name}),p.description?e.jsx("span",{className:"mdocs-agent-skill-popover-desc",children:p.description}):e.jsx("span",{className:"mdocs-agent-skill-popover-desc mdocs-agent-skill-popover-desc-muted",children:"无简介"})]})]})},p.id)})})]}):null,e.jsxs("button",{type:"button",className:"mdocs-agent-skill-ref-toggle"+(y?" mdocs-agent-skill-ref-toggle-open":""),disabled:a.disabled||d.length===0,onClick:()=>w(p=>!p),"aria-expanded":y,"aria-haspopup":"listbox",title:"引用 Skill",children:["Skill",g.length>0?` · ${g.length}`:""]})]}),g.map(p=>e.jsxs("button",{type:"button",className:"mdocs-agent-skill-chip mdocs-agent-skill-chip-on",disabled:a.disabled,onClick:()=>I(p.name),title:"移除引用",children:[p.name,e.jsx("span",{"aria-hidden":!0,children:" ×"})]},p.name))]}),j?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:j}):null]})}const qs=/^[A-Za-z0-9_]+$/;function Fs(a){const{block:s,onResolved:l}=a,[d,f]=o.useState(s.initialName),[y,w]=o.useState(s.initialDescription),[j,A]=o.useState(s.initialBody),[g,I]=o.useState(!1),[p,u]=o.useState(null),[x,S]=o.useState(1),M=o.useRef(!1),N=o.useRef(l);N.current=l;const b=s.status==="open",F=o.useRef(0);o.useEffect(()=>{if(!b)return;M.current=!1;const _=new Date(s.expiresAt).getTime(),Ce=Date.now(),le=Math.max(_-Ce,1);F.current=le,S(1);const Q=()=>{const te=_-Date.now(),O=Math.max(0,Math.min(1,te/le));S(O),te<=0&&!M.current&&(M.current=!0,ts(s.requestId).catch(()=>{}).finally(()=>{N.current(s.requestId,"expired")}))};Q();const ce=window.setInterval(Q,100);return()=>window.clearInterval(ce)},[b,s.expiresAt,s.requestId]);async function $(){if(g||!b)return;const _=d.trim();if(!_){u("名称不能为空");return}if(!qs.test(_)){u("名称仅允许英文、数字、下划线");return}if(!j.trim()){u("正文不能为空");return}I(!0),u(null);try{await ss(s.requestId,{name:_,description:y.trim(),body:j}),l(s.requestId,"submitted",_)}catch{l(s.requestId,"failed")}finally{I(!1)}}async function W(){if(!(g||!b)){I(!0),u(null),M.current=!0;try{await wt(s.requestId),l(s.requestId,"cancelled")}catch{l(s.requestId,"failed")}finally{I(!1)}}}const E=Math.max(0,Math.ceil(x*F.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card mdocs-agent-skill-form-card"+(b?"":" 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}),b?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[E,"s"]}):null]}),b?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(x*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${x})`}})}):null,s.status==="submitted"?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已提交",s.submittedName?`:${s.submittedName}`:""]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,表单已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,b?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:_=>f(_.target.value),maxLength:64,disabled:g,autoComplete:"off",spellCheck:!1})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"简介"}),e.jsx("input",{type:"text",value:y,onChange:_=>w(_.target.value),maxLength:200,disabled:g})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:j,onChange:_=>A(_.target.value),rows:8,disabled:g})]}),p?e.jsx("p",{className:"mdocs-agent-skill-form-error",children:p}):null,e.jsxs("div",{className:"mdocs-agent-skill-form-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-skill-form-cancel",disabled:g,onClick:()=>void W(),children:"取消"}),e.jsx("button",{type:"button",disabled:g,onClick:()=>void $(),children:g?"提交中…":s.mode==="create"?"创建":"保存"})]})]}):null]})}function We(a){var s;return a==null||typeof a=="boolean"?"":typeof a=="string"||typeof a=="number"?String(a):Array.isArray(a)?a.map(We).join(""):typeof a=="object"&&"props"in a?We((s=a.props)==null?void 0:s.children):""}function Ls(a){return a?/\blanguage-mermaid\b|\bmermaid\b/i.test(a):!1}function Ps(a){const s=Array.isArray(a)?a:[a];for(const l of s){if(l==null||typeof l!="object"||!("props"in l))continue;const d=l.props;if(!(!d||!Ls(d.className)))return We(d.children).replace(/\n$/,"")}return null}const Bs=.4,Os=4,ve=.2;let Be=null;function Ws(){return Be||(Be=Jt(()=>import("./diagram-BF8g9yg4.js").then(a=>a.z),__vite__mapDeps([0,1,2,3])).then(a=>{const s=a.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral",fontFamily:"ui-sans-serif, system-ui, sans-serif"}),s})),Be}const Hs=32,J=new Map;function jt(a){return J.get(a)??null}function Ks(a,s){for(J.has(a)&&J.delete(a),J.set(a,s);J.size>Hs;){const l=J.keys().next().value;if(l==null)break;J.delete(l)}}function Oe(a){return Math.min(Os,Math.max(Bs,a))}function Us(a){const[s,l]=o.useState(1),[d,f]=o.useState({x:0,y:0}),y=o.useRef(null),[w,j]=o.useState(!1);o.useEffect(()=>{const u=S=>{S.key==="Escape"&&a.onClose()};window.addEventListener("keydown",u);const x=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",u),document.body.style.overflow=x}},[a.onClose]);function A(u){u.button===0&&(u.currentTarget.setPointerCapture(u.pointerId),y.current={pointerId:u.pointerId,startX:u.clientX,startY:u.clientY,originX:d.x,originY:d.y},j(!0))}function g(u){const x=y.current;!x||x.pointerId!==u.pointerId||f({x:x.originX+(u.clientX-x.startX),y:x.originY+(u.clientY-x.startY)})}function I(u){const x=y.current;if(!(!x||x.pointerId!==u.pointerId)){y.current=null,j(!1);try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}}}function p(u){u.preventDefault();const x=u.deltaY>0?-ve:ve;l(S=>Oe(Number((S+x).toFixed(2))))}return Qt.createPortal(e.jsxs("div",{className:"mdocs-agent-mermaid-float",role:"dialog","aria-modal":"true","aria-label":"Mermaid 图预览",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-backdrop","aria-label":"关闭预览",onClick:a.onClose}),e.jsxs("div",{className:"mdocs-agent-mermaid-float-chrome",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-float-tools",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>l(u=>Oe(Number((u-ve).toFixed(2)))),title:"缩小","aria-label":"缩小",children:e.jsx(zs,{size:16,"aria-hidden":!0})}),e.jsxs("span",{className:"mdocs-agent-mermaid-float-scale",children:[Math.round(s*100),"%"]}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>l(u=>Oe(Number((u+ve).toFixed(2)))),title:"放大","aria-label":"放大",children:e.jsx(Ds,{size:16,"aria-hidden":!0})}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>{l(1),f({x:0,y:0})},title:"重置",children:"重置"}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:a.onClose,title:"关闭","aria-label":"关闭",children:e.jsx(we,{size:16,"aria-hidden":!0})})]}),e.jsx("div",{className:w?"mdocs-agent-mermaid-float-stage is-dragging":"mdocs-agent-mermaid-float-stage",onPointerDown:A,onPointerMove:g,onPointerUp:I,onPointerCancel:I,onWheel:p,children:e.jsx("div",{className:"mdocs-agent-mermaid-float-canvas",style:{transform:`translate(calc(-50% + ${d.x}px), calc(-50% + ${d.y}px)) scale(${s})`},dangerouslySetInnerHTML:{__html:a.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function Xs(a){const s=o.useId().replace(/:/g,""),[l,d]=o.useState("diagram"),[f,y]=o.useState(()=>jt(a.source.trim())),[w,j]=o.useState(null),[A,g]=o.useState(!1),[I,p]=o.useState(!1),u=o.useRef(null),x=a.source.trim(),S=o.useMemo(()=>x,[x]);o.useEffect(()=>()=>{u.current!=null&&window.clearTimeout(u.current)},[]),o.useEffect(()=>{if(l!=="diagram")return;if(!S){y(null),j(null);return}const N=jt(S);if(N){y(N),j(null);return}let b=!1;const F=window.setTimeout(()=>{(async()=>{try{const $=await Ws();if(b)return;const W=`mdocs-agent-mmd-${s}-${Date.now()}`,{svg:E}=await $.render(W,S);if(b)return;Ks(S,E),y(E),j(null)}catch($){if(b)return;y(null),j($ instanceof Error?$.message:"Mermaid 渲染失败")}})()},200);return()=>{b=!0,window.clearTimeout(F)}},[l,S,s]);async function M(){!x||!await Ct(x)||(g(!0),u.current!=null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>g(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-mermaid",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toolbar",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toggle",role:"group","aria-label":"Mermaid 显示模式",children:[e.jsxs("button",{type:"button",className:l==="diagram"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>d("diagram"),"aria-pressed":l==="diagram",title:"图谱",children:[e.jsx(St,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"图谱"})]}),e.jsxs("button",{type:"button",className:l==="code"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>d("code"),"aria-pressed":l==="code",title:"代码",children:[e.jsx(ns,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"代码"})]})]}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy mdocs-agent-mermaid-copy",onClick:()=>void M(),"aria-label":A?"已复制":"复制代码",title:A?"已复制":"复制",children:A?e.jsx(It,{size:14,"aria-hidden":!0}):e.jsx(_t,{size:14,"aria-hidden":!0})})]}),l==="diagram"?e.jsx("div",{className:"mdocs-agent-mermaid-diagram",children:w?e.jsxs("div",{className:"mdocs-agent-mermaid-error",role:"alert",children:[e.jsx("p",{children:"无法渲染该图,可切换到代码查看源码。"}),e.jsx("pre",{children:w})]}):f?e.jsx("div",{className:"mdocs-agent-mermaid-svg mdocs-agent-mermaid-svg-hit",role:"button",tabIndex:0,onClick:()=>p(!0),onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),p(!0))},title:"点击放大预览","aria-label":"点击放大预览 Mermaid 图",children:e.jsx("span",{className:"mdocs-agent-mermaid-svg-inner",dangerouslySetInnerHTML:{__html:f}})}):e.jsx("div",{className:"mdocs-agent-mermaid-loading",children:"渲染中…"})}):e.jsx("div",{className:"mdocs-agent-panel-md-pre-wrap mdocs-agent-mermaid-code",children:e.jsx("pre",{children:a.codeChildren??e.jsx("code",{className:"language-mermaid",children:x})})}),I&&f?e.jsx(Us,{svg:f,onClose:()=>p(!1)}):null]})}const Gs=o.memo(Xs,(a,s)=>a.source===s.source);function Ys(a){const[s,l]=o.useState(()=>Date.now());return o.useEffect(()=>{if(!a)return;const d=window.setInterval(()=>l(Date.now()),1e3);return()=>window.clearInterval(d)},[a]),s}function Vs(a,s){if(!a.startedAt)return null;const l=a.endedAt??s;return Math.max(1,Math.round((l-a.startedAt)/1e3))}function Se(a,s=Date.now()){let l=!1;const d=a.map(f=>f.type==="thinking"&&f.startedAt&&!f.endedAt?(l=!0,{...f,endedAt:s}):f);return l?d:a}function Zs(a){const{block:s,live:l,now:d}=a;if(!s.text)return null;const f=Vs(s,d),y=f!=null?l?`思考中 ${f}s`:`思考 ${f}s`:"思考";return e.jsxs("details",{className:"mdocs-agent-panel-think-fold",children:[e.jsxs("summary",{children:[e.jsx("span",{className:"mdocs-agent-think-label"+(l?" live":""),children:y}),e.jsx(Rt,{size:14,strokeWidth:1.8,className:"mdocs-agent-think-chevron"})]}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:s.text})]})}function He(a){var s;return a==null||typeof a=="boolean"?"":typeof a=="string"||typeof a=="number"?String(a):Array.isArray(a)?a.map(He).join(""):typeof a=="object"&&"props"in a?He((s=a.props)==null?void 0:s.children):""}function Js(a){const[s,l]=o.useState(!1),d=o.useRef(null),f=o.useRef(null),y=He(a.children).replace(/\n$/,"");o.useEffect(()=>()=>{d.current!=null&&window.clearTimeout(d.current)},[]);async function w(j){var p,u,x;j.preventDefault(),j.stopPropagation();const g=(((x=(u=(p=f.current)==null?void 0:p.querySelector("pre"))==null?void 0:u.innerText)==null?void 0:x.replace(/\n$/,""))??"")||y;!g||!await Ct(g)||(l(!0),d.current!=null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>l(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-panel-md-pre-wrap",ref:f,children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy",onClick:j=>void w(j),"aria-label":s?"已复制":"复制代码",title:s?"已复制":"复制",children:s?e.jsx(It,{size:14,"aria-hidden":!0}):e.jsx(_t,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:a.children})]})}function Qs(a){const s=Ps(a.children);return s!=null?e.jsx(Gs,{source:s,codeChildren:a.children}):e.jsx(Js,{children:a.children})}const en={pre:({children:a})=>e.jsx(Qs,{children:a})},kt=o.memo(function(s){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(ys,{remarkPlugins:[js],components:en,children:s.children})})}),tn=["如何发布文档?","草稿是什么?","如何创建工作空间?"],sn=["润色当前文稿","补写开头引言","把这段改得更简洁"];function Nt(a,s){return s.map((l,d)=>{const f=l.skillNames&&l.skillNames.length>0?l.skillNames:l.skillIds&&l.skillIds.length>0?l.skillIds:void 0;return{id:`h-${a}-${d}-${l.role}`,role:l.role,content:l.content,skillNames:f}})}function nn(a,s){const l=Se(a).slice(),d=l[l.length-1];return(d==null?void 0:d.type)==="text"?l[l.length-1]={type:"text",text:d.text+s}:l.push({type:"text",text:s}),l}function an(a,s){const l=Date.now(),d=a.slice(),f=d[d.length-1];return(f==null?void 0:f.type)==="thinking"&&!f.endedAt?d[d.length-1]={type:"thinking",text:f.text+s,startedAt:f.startedAt??l}:d.push({type:"thinking",text:s,startedAt:l}),d}function rn(a,s){const l=Se(a).slice(),d=l.findIndex(f=>f.type==="tool_call"&&f.toolCallId===s.toolCallId);if(d>=0){const f=l[d];l[d]={...f,...s,detail:s.detail??f.detail}}else l.push(s);return l}function bt(a){return a!=null&&a.length?a.filter(s=>s.type==="text").map(s=>s.text).join(""):""}function on(a){return!!(a!=null&&a.some(s=>s.type==="thinking"&&s.text.length>0))}function ln(a){const s=new Date(a);if(Number.isNaN(s.getTime()))return"";const l=new Date;return s.getFullYear()===l.getFullYear()&&s.getMonth()===l.getMonth()&&s.getDate()===l.getDate()?s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function vt(a){if(a>=1e3){const s=a/1e3;return`${s>=10?Math.round(s):Math.round(s*10)/10}K`}return String(a)}function cn(a){const{block:s,onResolved:l}=a,[d,f]=o.useState(""),[y,w]=o.useState(!1),[j,A]=o.useState(1),g=o.useRef(!1),I=o.useRef(l);I.current=l;const p=s.status==="open",u=o.useRef(0);o.useEffect(()=>{if(!p)return;g.current=!1;const N=new Date(s.expiresAt).getTime(),b=Date.now(),F=Math.max(N-b,1);u.current=F,A(1);const $=()=>{const E=N-Date.now(),_=Math.max(0,Math.min(1,E/F));A(_),E<=0&&!g.current&&(g.current=!0,hs(s.requestId).catch(()=>{}).finally(()=>{I.current(s.requestId,"","expired")}))};$();const W=window.setInterval($,100);return()=>window.clearInterval(W)},[p,s.expiresAt,s.requestId]);async function x(N){const b=N.trim();if(!(!b||y||!p)){w(!0);try{await gs(s.requestId,b),l(s.requestId,b,"selected")}catch{l(s.requestId,b,"failed")}finally{w(!1)}}}async function S(){if(!(y||!p)){w(!0),g.current=!0;try{await At(s.requestId),l(s.requestId,"","cancelled")}catch{l(s.requestId,"","failed")}finally{w(!1)}}}const M=Math.max(0,Math.ceil(j*u.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(p?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),p?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[M,"s"]}):null]}),p?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(j*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${j})`}})}):null,s.status==="selected"&&s.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",s.selected]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,p?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:s.options.map(N=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:y,onClick:()=>void x(N),children:N},N))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:d,disabled:y,placeholder:"或输入自己的内容…",onChange:N=>f(N.target.value),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),x(d))}}),e.jsx("button",{type:"button",disabled:y||!d.trim(),onClick:()=>void x(d),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:y,onClick:()=>void S(),children:"取消"})})]}):null]})}function dn(a){const f=2*Math.PI*8.75,y=Math.min(100,Math.max(0,a.percent)),w=f*(1-y/100),j=y>=90?"danger":y>=70?"warn":"ok",A=`上下文 ${y}% · 已用 ${vt(a.used)} / ${vt(a.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+j,"data-tooltip":A,"aria-label":A,role:"img",tabIndex:0,children:e.jsxs("svg",{width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,children:[e.jsx("circle",{className:"mdocs-agent-panel-context-track",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5}),e.jsx("circle",{className:"mdocs-agent-panel-context-value",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:f,strokeDashoffset:w,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function un(a){var s;for(const l of a)if(!(l.role!=="assistant"||!((s=l.blocks)!=null&&s.length))){for(const d of l.blocks)if((d.type==="choice_card"||d.type==="skill_form_card")&&d.status==="open")return!0}return!1}const kn=o.forwardRef(function(s,l){const{open:d,onClose:f,visitorName:y,anchorStyle:w,fullscreen:j,onToggleFullscreen:A,domainId:g,domains:I=[],localizeDomainName:p,documentId:u,documentTitle:x,documentPath:S,graphFileId:M,graphLabel:N,onOpenDocument:b,onTreeChanged:F,onDocumentOverwritten:$,onOpenCoding:W,embedded:E=!1,mode:_="normal",workingMarkdown:Ce,baseMarkdown:le,onMarkdownSet:Q,onSendingChange:ce,onSessionId:te}=s,O=_==="coding"?"coding":"normal",z=O==="coding",Mt=((y==null?void 0:y.trim().charAt(0))||"我").toUpperCase(),[ee,H]=o.useState(!1),[Y,Ke]=o.useState("current"),[Ue,Et]=o.useState({}),[Dt,se]=o.useState(null),[Xe,Ge]=o.useState(""),[k,de]=o.useState(null),[$t,ue]=o.useState(null),[K,C]=o.useState([]),[ne,ae]=o.useState(null),[me,Ye]=o.useState([]),[zt,Ve]=o.useState(!1),[pe,fe]=o.useState(""),[re,Ae]=o.useState([]),[Ze,Ie]=o.useState(!1),[v,U]=o.useState(!1),[Je,q]=o.useState(null),[he,Qe]=o.useState(null),[_e,V]=o.useState(!1),[X,et]=o.useState(!1),Tt=o.useRef(null),ge=o.useRef(null),R=o.useRef(null),T=o.useRef(null),xe=o.useRef(null),tt=o.useRef(0),Z=o.useRef(!0),[qt,Re]=o.useState(!1),Ft=Ys(v),Me=o.useRef(K);Me.current=K;const st=!!(u!=null&&u.trim())&&!Ze,Lt=(x==null?void 0:x.trim())||"当前文档",nt=(S==null?void 0:S.trim())||"",Ee=!!(M!=null&&M.trim())&&!Ze,Pt=(N==null?void 0:N.trim())||"当前图谱";o.useEffect(()=>{Ie(!1)},[u,M]);function De(t){return tt.current+=1,`${t}-${tt.current}`}const at=120;function rt(t){return t.scrollHeight-t.scrollTop-t.clientHeight}function ye(){const t=ge.current;t&&(t.scrollTop=t.scrollHeight,Re(!1))}function L(){Z.current&&ye()}function Bt(){const t=ge.current;if(!t)return;const n=rt(t);Z.current=n<=48,Re(n>at)}function Ot(){Z.current=!0,ye()}o.useLayoutEffect(()=>{L();const t=ge.current;t&&Re(rt(t)>at)},[K]);async function it(){Ve(!0);try{const t=await cs(O,z?u:void 0);Ye(t.sessions),ne||ae(t.lastOpenedSessionId)}catch{}finally{Ve(!1)}}async function $e(){try{const t=await ls();Qe(t)}catch{}}async function ot(){try{const t=await gt();de(t),ue(null)}catch(t){de(null),ue(t instanceof Error?t.message:String(t))}}const je=o.useRef(ce);je.current=ce;const ke=o.useRef(te);ke.current=te,o.useEffect(()=>{var t;(t=je.current)==null||t.call(je,v)},[v]),o.useEffect(()=>{var t;(t=ke.current)==null||t.call(ke,ne)},[ne]),o.useEffect(()=>{var n;if(!d){H(!1),(n=R.current)==null||n.abort(),R.current=null;return}let t=!1;return(async()=>{try{const r=await gt();t||(de(r),ue(null))}catch(r){t||(de(null),ue(r instanceof Error?r.message:String(r)))}})(),$e(),()=>{t=!0}},[d]);const Ne=z?`coding:${u??""}`:"normal",lt=o.useRef(Ne);o.useEffect(()=>{if(!d)return;const t=lt.current!==Ne;lt.current=Ne;let n=!1;return(async()=>{try{const r=await as(O,z?u:void 0);if(n)return;ae(r.sessionId),C(m=>!t&&m.length>0&&!r.activeRun?m:Nt(r.sessionId,r.messages)),r.activeRun&&(r.activeRun.status==="running"||r.activeRun.status==="waiting_user")&&Ht(r.activeRun)}catch{}})(),()=>{n=!0}},[d,Ne]),o.useEffect(()=>{!d||!ee||it()},[d,ee]),o.useEffect(()=>()=>{var t;(t=R.current)==null||t.abort()},[]);function ze(){if(!X){if(un(Me.current)){V(!0);return}V(!1),f()}}async function Wt(){var m;if(X)return;et(!0);const t=Me.current,n=[];for(const i of t)if(!(i.role!=="assistant"||!i.blocks))for(const c of i.blocks)c.type==="choice_card"&&c.status==="open"&&n.push(At(c.requestId).catch(()=>{})),c.type==="skill_form_card"&&c.status==="open"&&n.push(wt(c.requestId).catch(()=>{}));const r=T.current;r&&n.push(be(r).catch(()=>{})),await Promise.all(n),(m=R.current)==null||m.abort(),T.current=null,U(!1),C(i=>i.map(c=>c.role!=="assistant"||!c.blocks?c:{...c,blocks:c.blocks.map(h=>h.type==="choice_card"&&h.status==="open"?{...h,status:"cancelled"}:h.type==="skill_form_card"&&h.status==="open"?{...h,status:"cancelled"}:h)})),V(!1),et(!1),f()}const Te=o.useRef(ze);Te.current=ze,o.useImperativeHandle(l,()=>({requestClose:()=>Te.current()}),[]),o.useEffect(()=>{if(!d){V(!1);return}const t=n=>{if(n.key==="Escape"){if(_e){X||V(!1);return}if(ee){H(!1);return}Te.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[d,ee,_e,X]);function ct(t,n){let r=!1;return n.type==="run_started"?(T.current=n.runId,ae(n.sessionId),!1):(n.type==="text_delta"?(C(m=>m.map(i=>{if(i.id!==t)return i;const c=nn(i.blocks??[],n.text);return{...i,blocks:c,content:bt(c)}})),requestAnimationFrame(()=>L())):n.type==="thinking_delta"?(C(m=>m.map(i=>{if(i.id!==t)return i;const c=an(i.blocks??[],n.text);return{...i,blocks:c}})),requestAnimationFrame(()=>L())):n.type==="sources"?(C(m=>m.map(i=>{if(i.id!==t)return i;const c=(i.blocks??[]).slice(),h=c[c.length-1];return(h==null?void 0:h.type)==="sources"?c[c.length-1]={type:"sources",items:n.items}:c.push({type:"sources",items:n.items}),{...i,blocks:c}})),requestAnimationFrame(()=>L())):n.type==="document_table"?(C(m=>m.map(i=>{if(i.id!==t)return i;const c=[...i.blocks??[],{type:"document_table",title:n.title,rows:n.rows}];return{...i,blocks:c}})),requestAnimationFrame(()=>L())):n.type==="document_card"?(C(m=>m.map(i=>{if(i.id!==t)return i;const c=[...i.blocks??[],{type:"document_card",documentId:n.documentId,title:n.title,path:n.path,preview:n.preview}];return{...i,blocks:c}})),requestAnimationFrame(()=>L())):n.type==="tool_notice"?(C(m=>m.map(i=>{if(i.id!==t)return i;const c=[...i.blocks??[],{type:"tool_notice",toolName:n.toolName,text:n.text}];return{...i,blocks:c}})),requestAnimationFrame(()=>L())):n.type==="tool_call"?(C(m=>m.map(i=>{if(i.id!==t)return i;const c=rn(i.blocks??[],{type:"tool_call",toolCallId:n.toolCallId,toolName:n.toolName,label:n.label,status:n.status,detail:n.detail});return{...i,blocks:c}})),requestAnimationFrame(()=>L())):n.type==="choice_card"?(C(m=>m.map(i=>{if(i.id!==t)return i;const c=[...i.blocks??[],{type:"choice_card",requestId:n.requestId,title:n.title,options:n.options,expiresAt:n.expiresAt,status:"open"}];return{...i,blocks:c}})),requestAnimationFrame(()=>L())):n.type==="choice_expired"?C(m=>m.map(i=>i.id!==t||!i.blocks?i:{...i,blocks:i.blocks.map(c=>c.type==="choice_card"&&c.requestId===n.requestId&&c.status==="open"?{...c,status:"expired"}:c)})):n.type==="skill_form_card"?(C(m=>m.map(i=>{if(i.id!==t)return i;const c=[...i.blocks??[],{type:"skill_form_card",requestId:n.requestId,mode:n.mode,title:n.title,currentName:n.currentName,initialName:n.initialName,initialDescription:n.initialDescription,initialBody:n.initialBody,expiresAt:n.expiresAt,status:"open"}];return{...i,blocks:c}})),requestAnimationFrame(()=>L())):n.type==="skill_form_expired"?C(m=>m.map(i=>i.id!==t||!i.blocks?i:{...i,blocks:i.blocks.map(c=>c.type==="skill_form_card"&&c.requestId===n.requestId&&c.status==="open"?{...c,status:"expired"}:c)})):n.type==="markdown_set"?Q==null||Q(n.markdown):n.type==="tree_changed"?F==null||F():n.type==="document_overwritten"?$==null||$({documentId:n.documentId,headCommitId:n.headCommitId}):n.type==="open_coding"?W==null||W({documentId:n.documentId,displayName:n.displayName}):n.type==="context_usage"?Qe({percent:n.percent,used:n.used,limit:n.limit}):n.type==="error"?(r=!0,q(n.message)):n.type==="done"&&(T.current=null),r)}async function Ht(t){var i;(i=R.current)==null||i.abort();const n=new AbortController;R.current=n,T.current=t.runId;const r=De("a");xe.current=r,Z.current=!0,C(c=>{var D;const h=c[c.length-1];return(h==null?void 0:h.role)==="assistant"&&!h.content&&!((D=h.blocks)!=null&&D.length)?(xe.current=h.id,c):[...c,{id:r,role:"assistant",content:""}]});const m=xe.current??r;U(!0),q(null);try{let c=!1;await rs(t.runId,{afterSeq:0,signal:n.signal,onEvent:h=>{ct(m,h)&&(c=!0)}}),!n.signal.aborted&&!c&&Ae([])}catch(c){if(n.signal.aborted)return;q(c instanceof Error?c.message:String(c))}finally{C(c=>c.map(h=>h.id===m&&h.blocks?{...h,blocks:Se(h.blocks)}:h)),R.current===n&&(R.current=null),T.current||U(!1)}}async function qe(t){var c;const n=t.trim();if(!n||v)return;if(!(k!=null&&k.enabled)){q((k==null?void 0:k.reason)==="missing_api_key"?"请先配置 API Key":(k==null?void 0:k.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(c=R.current)==null||c.abort();const r=new AbortController;R.current=r;const m={id:De("u"),role:"user",content:n,skillNames:re.length>0?[...re]:void 0},i=De("a");xe.current=i,Z.current=!0,C(h=>[...h,m,{id:i,role:"assistant",content:""}]),fe(""),U(!0),q(null),H(!1),requestAnimationFrame(()=>{ye(),requestAnimationFrame(ye)});try{let h=!1;await us(n,{mode:O,skillNames:re.length>0?re:void 0,...z?{documentId:u??null,workingMarkdown:Ce,baseMarkdown:le}:{references:{domainId:(g==null?void 0:g.trim())||void 0,documentId:!Ee&&st?u.trim():void 0,graphFileId:Ee?M.trim():void 0}},signal:r.signal,onEvent:D=>{ct(i,D)&&(h=!0)}}),!r.signal.aborted&&!h&&Ae([])}catch(h){if(r.signal.aborted)return;q(h instanceof Error?h.message:String(h))}finally{C(h=>h.map(D=>D.id===i&&D.blocks?{...D,blocks:Se(D.blocks)}:D)),R.current===r&&(R.current=null),T.current||U(!1)}}async function Kt(){var n;(n=R.current)==null||n.abort();const t=T.current;T.current=null,U(!1),t&&be(t).catch(()=>{}),q(null),H(!1);try{const r=await ds(O,z?u:void 0,g??null);ae(r.sessionId),C([]),fe(""),Z.current=!0,$e(),it()}catch(r){q(r instanceof Error?r.message:String(r))}}async function Ut(t){var r;if(t===ne){H(!1);return}(r=R.current)==null||r.abort();const n=T.current;T.current=null,U(!1),n&&be(n).catch(()=>{}),q(null);try{const m=await ms(t,O,z?u:void 0);ae(m.sessionId),C(Nt(m.sessionId,m.messages)),fe(""),H(!1),se(null),Z.current=!0,requestAnimationFrame(()=>L()),$e()}catch(m){q(m instanceof Error?m.message:String(m))}}function dt(t){Ye(n=>{const r=n.map(m=>m.id===t.id?{...m,...t}:m);return r.sort((m,i)=>{const c=m.pinned===!0,h=i.pinned===!0;return c!==h?c?-1:1:m.updatedAt<i.updatedAt?1:m.updatedAt>i.updatedAt?-1:0}),r})}async function Xt(t){if(!v)try{const n=await ps(t.id,t.pinned!==!0,O);dt(n)}catch(n){q(n instanceof Error?n.message:String(n))}}function Gt(t){se(t.id),Ge(t.title)}async function ut(t){const n=Xe.trim();if(se(null),!!n)try{const r=await fs(t,n,O);dt(r)}catch(r){q(r instanceof Error?r.message:String(r))}}const Yt=t=>{const n=I.find(r=>r.domainId===t);return n?p?p(n.domainName):n.domainName:t===oe?"default":t},ie=o.useMemo(()=>Y==="all"||!g?me:me.filter(t=>(t.domainId||oe)===g),[me,Y,g]),mt=o.useMemo(()=>ie.filter(t=>t.pinned===!0),[ie]),Vt=o.useMemo(()=>{var r;const t=new Map;for(const m of ie){const i=((r=m.domainId)==null?void 0:r.trim())||oe,c=t.get(i);c?c.push(m):t.set(i,[m])}const n=(g==null?void 0:g.trim())||oe;return Array.from(t.entries()).map(([m,i])=>({id:m,items:i,label:Yt(m)})).sort((m,i)=>m.id===n?-1:i.id===n?1:m.label.localeCompare(i.label,"zh"))},[ie,I,p,g]);function pt(t){return Ue[t]!==void 0?!Ue[t]:Y==="all"?t===((g==null?void 0:g.trim())||oe):!0}function Zt(t){Et(n=>{const r=pt(t);return{...n,[t]:r}})}function Fe(t){!t||!b||b(t)}function ft(t){const n=Dt===t.id;return e.jsxs("div",{className:"mdocs-agent-panel-history-item"+(t.id===ne?" active":""),children:[n?e.jsx("input",{className:"mdocs-agent-panel-history-rename",value:Xe,autoFocus:!0,maxLength:80,"aria-label":"重命名会话",onChange:r=>Ge(r.target.value),onClick:r=>r.stopPropagation(),onKeyDown:r=>{r.key==="Enter"?(r.preventDefault(),ut(t.id)):r.key==="Escape"&&se(null)},onBlur:()=>void ut(t.id)}):e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-open",disabled:v,onClick:()=>void Ut(t.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:t.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:ln(t.updatedAt)})]}),e.jsxs("div",{className:"mdocs-agent-panel-history-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-action"+(t.pinned?" pinned":""),title:t.pinned?"取消置顶":"置顶","aria-label":t.pinned?"取消置顶":"置顶",disabled:v,onClick:r=>{r.stopPropagation(),Xt(t)},children:e.jsx(Ms,{size:14,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-action",title:"重命名","aria-label":"重命名",disabled:v||n,onClick:r=>{r.stopPropagation(),Gt(t)},children:e.jsx(_s,{size:14,strokeWidth:1.8})})]})]})}if(!d)return null;const Le=(k==null?void 0:k.reason)==="missing_api_key",ht=$t??(k&&!k.enabled&&!Le?k.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:Tt,className:"mdocs-agent-panel"+(E?" mdocs-agent-panel--embedded":j?" mdocs-agent-panel--fullscreen":""),role:E?void 0:"dialog","aria-label":z?"mdocs 帮写助手":"mdocs 智能助手","aria-modal":E?void 0:j?!0:void 0,style:E||j?void 0:w,children:[e.jsxs("header",{className:"mdocs-agent-panel-header",children:[e.jsxs("div",{className:"mdocs-agent-panel-title",children:[e.jsx("img",{src:xt,alt:"",className:"mdocs-agent-panel-title-logo"}),e.jsx("span",{children:z?"mdocs 帮写助手":"mdocs 智能助手"})]}),e.jsxs("div",{className:"mdocs-agent-panel-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:v,onClick:()=>void Kt(),children:e.jsx(xs,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(ee?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>H(t=>!t),children:e.jsx(vs,{size:16,strokeWidth:1.8})}),E||!A?null:e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:j?"退出全屏":"全屏","aria-label":j?"退出全屏":"全屏",onClick:A,children:j?e.jsx(As,{size:16,strokeWidth:1.8}):e.jsx(Ss,{size:16,strokeWidth:1.8})}),E?null:e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:ze,children:e.jsx(we,{size:16,strokeWidth:1.8})})]})]}),ee?e.jsxs("div",{className:"mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>{H(!1),se(null)},children:"返回对话"})]}),e.jsxs("div",{className:"mdocs-agent-panel-history-filters",role:"tablist","aria-label":"按工作空间筛选",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":Y==="current",className:"mdocs-agent-panel-history-filter"+(Y==="current"?" active":""),onClick:()=>Ke("current"),children:"当前工作空间"}),e.jsx("button",{type:"button",role:"tab","aria-selected":Y==="all",className:"mdocs-agent-panel-history-filter"+(Y==="all"?" active":""),onClick:()=>Ke("all"),children:"全部"})]}),zt?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):me.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:"发一条消息后会出现在这里"})]}):ie.length===0?e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"此工作空间暂无会话"}):e.jsxs("div",{className:"mdocs-agent-panel-history-list",children:[mt.length>0?e.jsxs("section",{className:"mdocs-agent-panel-history-section",children:[e.jsx("div",{className:"mdocs-agent-panel-history-section-label",children:"Pinned"}),e.jsx("ul",{children:mt.map(t=>e.jsx("li",{children:ft(t)},t.id))})]}):null,Vt.map(t=>{const n=pt(t.id);return e.jsxs("section",{className:"mdocs-agent-panel-history-folder",children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-folder-head","aria-expanded":n,onClick:()=>Zt(t.id),children:[n?e.jsx(is,{size:14,strokeWidth:1.8}):e.jsx(Rt,{size:14,strokeWidth:1.8}),e.jsx("span",{className:"mdocs-agent-panel-history-folder-name",children:t.label}),e.jsx("span",{className:"mdocs-agent-panel-history-folder-count",children:t.items.length})]}),n?e.jsx("ul",{children:t.items.map(r=>e.jsx("li",{children:ft(r)},r.id))}):null]},t.id)})]})]}):e.jsxs("div",{className:"mdocs-agent-panel-body",children:[e.jsxs("div",{className:"mdocs-agent-panel-scroll-wrap",children:[e.jsx("div",{className:"mdocs-agent-panel-welcome",ref:ge,onScroll:Bt,children:K.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-hello",children:z?"你好,我是 mdocs 帮写助手":"你好,我是 mdocs 智能助手"}),e.jsx("p",{className:"mdocs-agent-panel-desc",children:z?"这里专注改稿:你说怎么写,我更新右侧提案;按段接受或拒绝后,再点「完成并写回」。答疑、建目录、搜文档请用右下角「智能助手」。":"我能答疑、搜文档、整理结构,也能帮你写全文;需要按段精细改稿,请点文档顶栏「帮写」。"}),Le?e.jsx(yt,{onConfigured:ot}):ht?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:ht}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:(z?sn:tn).map(t=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void qe(t),disabled:v||!(k!=null&&k.enabled),children:t},t))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:K.map(t=>{var n;return e.jsxs("div",{className:"mdocs-agent-panel-msg"+(t.role==="user"?" mdocs-agent-panel-msg-user":" mdocs-agent-panel-msg-assistant"),children:[t.role==="assistant"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-ai","aria-hidden":!0,children:e.jsx("img",{src:xt,alt:""})}):null,e.jsxs("div",{className:"mdocs-agent-panel-msg-bubble",children:[t.role==="user"&&t.skillNames&&t.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",t.skillNames.length]}):null,t.role==="assistant"?t.blocks&&t.blocks.length>0?e.jsxs("div",{className:"mdocs-agent-panel-timeline",children:[t.blocks.map((r,m)=>{if(r.type==="thinking")return e.jsx(Zs,{block:r,live:v&&!r.endedAt,now:Ft},`${t.id}-th-${m}`);if(r.type==="text")return r.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(kt,{children:r.text})},`${t.id}-t-${m}`):null;if(r.type==="sources")return r.items.length===0?null:e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:["已阅读 ",r.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:r.items.map(i=>e.jsx("li",{children:e.jsx("a",{href:i.url,target:"_blank",rel:"noreferrer",children:i.name})},i.id))})]})},`${t.id}-s-${m}`);if(r.type==="tool_call"){const i=r.status==="running"?"进行中":r.status==="error"?"失败":"完成";return e.jsxs("div",{className:`mdocs-agent-panel-block mdocs-agent-tool-call mdocs-agent-tool-call-${r.status}`,children:[e.jsxs("div",{className:"mdocs-agent-tool-call-head",children:[e.jsx("span",{className:"mdocs-agent-tool-call-status","aria-hidden":!0}),e.jsx("span",{className:"mdocs-agent-tool-call-label",children:r.label}),e.jsx("span",{className:"mdocs-agent-tool-call-badge",children:i})]}),r.detail?e.jsx("p",{className:"mdocs-agent-tool-call-detail",children:r.detail}):null]},`${t.id}-tc-${r.toolCallId}`)}if(r.type==="tool_notice")return e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:r.text})},`${t.id}-n-${m}`);if(r.type==="choice_card")return e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(cn,{block:r,onResolved:(i,c,h)=>{C(D=>D.map(P=>P.id!==t.id||!P.blocks?P:{...P,blocks:P.blocks.map(B=>B.type==="choice_card"&&B.requestId===i?{...B,status:h,selected:h==="selected"?c:B.selected}:B)}))}})},`${t.id}-ch-${m}`);if(r.type==="skill_form_card")return e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Fs,{block:r,onResolved:(i,c,h)=>{C(D=>D.map(P=>P.id!==t.id||!P.blocks?P:{...P,blocks:P.blocks.map(B=>B.type==="skill_form_card"&&B.requestId===i?{...B,status:c,submittedName:c==="submitted"?h:B.submittedName}:B)}))}})},`${t.id}-sf-${m}`);if(r.type==="document_card"){const i=`${window.location.origin}${window.location.pathname}#/doc/${r.documentId}`;return e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",open:!0,children:[e.jsxs("summary",{children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:c=>{c.preventDefault(),c.stopPropagation(),Fe(r.documentId)},children:["《",r.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"打开文档"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[r.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:r.path}):null,e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:e.jsx("a",{href:i,className:"mdocs-agent-panel-doc-link",onClick:c=>{c.preventDefault(),Fe(r.documentId)},children:i})}),r.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:r.preview}):e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview muted",children:"(无正文预览)"})]})]})},`${t.id}-c-${m}`)}return e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[r.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:r.rows.length===0?"无结果":`${r.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:r.rows.length===0?e.jsx("p",{className:"mdocs-agent-panel-doc-table-empty",children:"无结果"}):e.jsxs("table",{className:"mdocs-agent-panel-doc-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"文章名字"}),e.jsx("th",{children:"文章内容"})]})}),e.jsx("tbody",{children:r.rows.map(i=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>Fe(i.documentId),children:i.title})}),e.jsx("td",{children:i.summary||"-"})]},i.documentId))})]})})]})},`${t.id}-d-${m}`)}),v&&t.id===((n=K[K.length-1])==null?void 0:n.id)&&!bt(t.blocks)&&!on(t.blocks)?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null]}):t.content?e.jsx(kt,{children:t.content}):v?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null:t.content]}),t.role==="user"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-user","aria-hidden":!0,children:Mt}):null]},t.id)})})}),qt?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:Ot,title:"回到底部","aria-label":"回到底部",children:[e.jsx(Ns,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),Je?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Je}):null,Le&&K.length>0?e.jsx(yt,{onConfigured:ot}):null,e.jsx(Ts,{selectedNames:re,onChange:Ae,disabled:v||!(k!=null&&k.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap",children:[z?null:Ee?e.jsxs("div",{className:"mdocs-agent-doc-ref mdocs-agent-graph-ref",children:[e.jsx(St,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:Pt}),e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:"图谱(只读)"})]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前图谱",disabled:v,onClick:()=>Ie(!0),children:e.jsx(we,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):st?e.jsxs("div",{className:"mdocs-agent-doc-ref",children:[e.jsx(os,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:Lt}),nt?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:nt}):null]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前文档",disabled:v,onClick:()=>Ie(!0),children:e.jsx(we,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):null,e.jsxs("div",{className:"mdocs-agent-panel-input-body",children:[e.jsx("textarea",{className:"mdocs-agent-panel-input",rows:2,placeholder:k!=null&&k.enabled?z?"说说要写什么…":"把你的问题告诉我…":"请先配置 API Key",value:pe,disabled:v||!(k!=null&&k.enabled),onChange:t=>fe(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),qe(pe))}}),he?e.jsx(dn,{percent:he.percent,used:he.used,limit:he.limit}):null,e.jsx("button",{type:"button",className:v?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:v?!1:!(k!=null&&k.enabled)||!pe.trim(),onClick:()=>{var t;if(v){const n=T.current;(t=R.current)==null||t.abort(),T.current=null,U(!1),n&&be(n).catch(()=>{});return}qe(pe)},title:v?"停止":"发送","aria-label":v?"停止":"发送",children:v?"■":"↑"})]})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),_e?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{X||V(!1)},children:e.jsxs("div",{className:"mdocs-message-dialog mdocs-agent-close-confirm",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-agent-close-confirm-title",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{id:"mdocs-agent-close-confirm-title",className:"mdocs-message-dialog-title",children:"有待处理的倒计时"}),e.jsx("p",{className:"mdocs-message-dialog-body",children:"当前还有选择卡或 Skill 表单在倒计时。强制关闭会取消这些操作并退出助手;也可以继续等待完成后再关。"}),e.jsxs("div",{className:"mdocs-message-dialog-actions mdocs-agent-close-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",disabled:X,onClick:()=>V(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:X,onClick:()=>void Wt(),children:X?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{kn as AgentChatPanel};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{r as d,j as i}from"./react-vendor-BVS1XoFi.js";import{
|
|
1
|
+
import{r as d,j as i}from"./react-vendor-BVS1XoFi.js";import{_ as O,M as X,aQ as Y}from"./index-Btfv_3-Q.js";import{AgentChatPanel as Z}from"./AgentChatPanel-_IV-LAS4.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./check-BAYRiedE.js";import"./copy-J9XXv57X.js";import"./plus-DvWl4lHk.js";function U(e){return e===""?[]:e.split(`
|
|
2
2
|
`)}function ee(e){return e.join(`
|
|
3
3
|
`)}function V(e,s){const r=U(e),n=U(s),o=r.length,a=n.length,l=Array.from({length:o+1},()=>Array.from({length:a+1},()=>0));for(let k=o-1;k>=0;k--)for(let g=a-1;g>=0;g--)r[k]===n[g]?l[k][g]=l[k+1][g+1]+1:l[k][g]=Math.max(l[k+1][g],l[k][g+1]);const x=[];let u=0,h=0;for(;u<o||h<a;)if(u<o&&h<a&&r[u]===n[h])x.push({kind:"eq",oi:u,ni:h}),u++,h++;else if(h<a&&(u===o||l[u][h+1]>=l[u+1][h]))x.push({kind:"ins",oi:u,ni:h}),h++;else if(u<o)x.push({kind:"del",oi:u,ni:h}),u++;else break;const M=[];let c=0,y=0;for(;c<x.length;){if(x[c].kind==="eq"){c++;continue}const k=x[c].oi,g=x[c].ni,T=[],m=[];let E=k,I=g;for(;c<x.length&&x[c].kind!=="eq";){const L=x[c];L.kind==="del"?(T.push(r[L.oi]),E=L.oi+1):(m.push(n[L.ni]),I=L.ni+1),c++}M.push({id:`h${y++}`,oldStart:k,oldEnd:E,newStart:g,newEnd:I,oldLines:T,newLines:m})}return M}function ne(e,s){const r=U(e);return ee([...r.slice(0,s.oldStart),...s.newLines,...r.slice(s.oldEnd)])}function G(e){const s=[];for(const r of e){const n=s[s.length-1];r.kind==="same"&&(n==null?void 0:n.kind)==="same"?s[s.length-1]={kind:"same",lines:[...n.lines,...r.lines],key:n.key}:s.push(r)}return s}function J(e){let s=0;return e.map(r=>{if(r.kind!=="hunk")return r;const n={...r,hunkIndex:s,key:`h-${r.hunk.id}-${s}`};return s+=1,n})}function te(e,s){const r=e.map(n=>n.kind!=="hunk"||n.hunk.id!==s?n:{kind:"same",lines:n.hunk.oldLines.slice(),key:`s-rej-${n.hunk.id}`});return J(G(r))}function se(e,s,r){let n=0,o=!1;const a=[];for(const l of e){if(l.kind==="same"){a.push(l);continue}if(l.hunk.id===s){o=!0,n=r.length-l.hunk.oldLines.length,a.push({kind:"same",lines:r.slice(),key:`s-acc-${l.hunk.id}`});continue}if(!o||n===0){a.push(l);continue}a.push({...l,hunk:{...l.hunk,oldStart:l.hunk.oldStart+n,oldEnd:l.hunk.oldEnd+n}})}return J(G(a))}function A(e){return e===""?[]:e.split(`
|
|
4
4
|
`)}function H(e){return e.join(`
|
|
5
|
-
`)}function ie(e,s){const r=A(e),n=[];let o=0;return s.forEach((a,l)=>{a.oldStart>o&&n.push({kind:"same",lines:r.slice(o,a.oldStart),key:`s-${o}-${a.oldStart}`}),n.push({kind:"hunk",hunk:a,hunkIndex:l,key:`h-${a.id}-${l}`}),o=a.oldEnd}),o<r.length?n.push({kind:"same",lines:r.slice(o),key:`s-${o}-end`}):s.length===0&&r.length===0&&n.push({kind:"same",lines:[],key:"s-empty"}),n}function Q(e){const s=[],r=[];for(const n of e)n.kind==="same"?s.push(H(n.lines)):r.push(H(n.hunk.newLines));return{sameTexts:s,newTexts:r}}function
|
|
5
|
+
`)}function ie(e,s){const r=A(e),n=[];let o=0;return s.forEach((a,l)=>{a.oldStart>o&&n.push({kind:"same",lines:r.slice(o,a.oldStart),key:`s-${o}-${a.oldStart}`}),n.push({kind:"hunk",hunk:a,hunkIndex:l,key:`h-${a.id}-${l}`}),o=a.oldEnd}),o<r.length?n.push({kind:"same",lines:r.slice(o),key:`s-${o}-end`}):s.length===0&&r.length===0&&n.push({kind:"same",lines:[],key:"s-empty"}),n}function Q(e){const s=[],r=[];for(const n of e)n.kind==="same"?s.push(H(n.lines)):r.push(H(n.hunk.newLines));return{sameTexts:s,newTexts:r}}function _(e,s){const r=[];let n=0,o=0;for(const a of e)if(a.kind==="same"){const l=s.sameTexts[n++]??"";r.push(...A(l))}else{const l=s.newTexts[o++]??"";r.push(...A(l))}return H(r)}function re(e){return e.oldLines.length===0?"add":e.newLines.length===0?"del":"mod"}function z(e){const s=Math.max(1,A(e.value).length);return i.jsxs("div",{className:`mdocs-ai-write-line ${e.className}`,children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("textarea",{className:"mdocs-ai-write-inline-edit",value:e.value,rows:s,spellCheck:!1,"aria-label":e["aria-label"],onChange:r=>e.onChange(r.target.value),onBlur:()=>e.onBlurFlush()})]})}function le(e){const s=!!e.sending,[r,n]=d.useState(0),[o,a]=d.useState(null),[l,x]=d.useState({sameTexts:[],newTexts:[]}),[u,h]=d.useState([]),M=d.useRef(!1),c=d.useRef(!1),y=d.useRef([]),k=d.useRef(l);k.current=l,y.current=u;const g=d.useMemo(()=>e.proposedMd==null||e.proposedMd===e.currentMd?[]:V(e.currentMd,e.proposedMd),[e.currentMd,e.proposedMd]),T=!s&&(u.length>0?u.some(t=>t.kind==="hunk"):g.length>0);d.useEffect(()=>{if(s){h([]),M.current=!1,c.current=!1;return}if(e.proposedMd==null||e.proposedMd===e.currentMd){h([]),M.current=!1,c.current=!1;return}if(c.current){c.current=!1;return}const t=V(e.currentMd,e.proposedMd);if(t.length===0){h([]);return}const f=ie(e.currentMd,t);h(f),M.current=!1,x(Q(f))},[s,e.proposedMd,e.currentMd]);const m=d.useMemo(()=>u.filter(t=>t.kind==="hunk").map(t=>t.hunk),[u]);d.useEffect(()=>{if(m.length===0){n(0);return}n(t=>Math.min(t,m.length-1))},[m.length]);const E=o??r;function I(){return _(y.current,k.current)}function L(){if(!T||y.current.length===0)return e.proposedMd;const t=I();return M.current=!1,t===e.currentMd?(c.current=!1,e.onProposedChange(null),null):(t!==e.proposedMd&&(c.current=!0,e.onProposedChange(t)),t)}function $(t){const f=y.current.find(F=>F.kind==="hunk"&&F.hunk.id===t.id);if(!f)return;const b=k.current.newTexts[f.hunkIndex],j=b!=null?A(b):t.newLines.slice(),P={...t,newLines:j},C=I();if(M.current=!1,C===e.currentMd){c.current=!1,h([]),e.onProposedChange(null);return}const v=ne(e.currentMd,P),p=se(y.current,t.id,j),K=p.some(F=>F.kind==="hunk");c.current=!0,h(p),x(Q(p)),e.onCurrentChange(v),!K||C===v?(c.current=!1,e.onProposedChange(null)):e.onProposedChange(C)}function R(t){const f=y.current.find(v=>v.kind==="hunk"&&v.hunk.id===t.id);if(!f)return;const b={sameTexts:k.current.sameTexts.slice(),newTexts:k.current.newTexts.slice()};b.newTexts[f.hunkIndex]=H(t.oldLines);const j=_(y.current,b),P=te(y.current,t.id),C=P.some(v=>v.kind==="hunk");M.current=!1,c.current=!0,h(P),x(Q(P)),!C||j===e.currentMd?(c.current=!1,e.onProposedChange(null)):e.onProposedChange(j)}function q(){const t=I();M.current=!1,c.current=!1,e.onCurrentChange(t),e.onProposedChange(null)}function D(){M.current=!1,c.current=!1,e.onProposedChange(null)}function N(t){m.length!==0&&n(f=>{const b=(f+t+m.length)%m.length,j=document.getElementById(`mdocs-ai-hunk-${b}`);return j==null||j.scrollIntoView({block:"center",behavior:"smooth"}),b})}function S(t,f){M.current=!0,x(b=>{const j=b.sameTexts.slice();return j[t]=f,{...b,sameTexts:j}})}function W(t,f){M.current=!0,x(b=>{const j=b.newTexts.slice();return j[t]=f,{...b,newTexts:j}})}const w=m[E]??null;let B=0;return i.jsxs("div",{className:"mdocs-ai-write-md-pane",children:[i.jsxs("div",{className:"mdocs-ai-write-diff-toolbar",children:[i.jsx("span",{className:"mdocs-ai-write-diff-count",children:s?"接收中·编辑我的稿":m.length===0?e.proposedMd?"与提案一致(可编辑)":"Markdown 源码(可编辑)":`${m.length} 处变更(可改提案)`}),!s&&m.length>0?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-diff-accept-all",onClick:q,children:"全部接受"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-diff-reject-all",onClick:D,children:"全部拒绝"})]}):null]}),T&&u.length>0?i.jsxs("div",{className:"mdocs-ai-write-inline",role:"document",children:[u.map(t=>{if(t.kind==="same"){const C=B++,v=l.sameTexts[C]??H(t.lines);return i.jsx("div",{className:"mdocs-ai-write-inline-same",children:i.jsx(z,{className:"ctx",value:v,"aria-label":"提案相同行",onChange:p=>S(C,p),onBlurFlush:()=>L()})},t.key)}const f=t.hunk,b=re(f),j=t.hunkIndex===E,P=l.newTexts[t.hunkIndex]??H(f.newLines);return i.jsxs("div",{id:`mdocs-ai-hunk-${t.hunkIndex}`,className:`mdocs-ai-write-inline-hunk mdocs-ai-write-inline-hunk-${b}`+(j?" is-active":""),onMouseEnter:()=>a(t.hunkIndex),onMouseLeave:()=>a(null),onClick:()=>n(t.hunkIndex),children:[i.jsxs("div",{className:"mdocs-ai-write-hunk-hover",hidden:o!==t.hunkIndex,children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:C=>{C.stopPropagation(),R(f)},children:"拒绝"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:C=>{C.stopPropagation(),$(f)},children:"接受"})]}),i.jsx("pre",{className:"mdocs-ai-write-hunk-pre",children:f.oldLines.map((C,v)=>i.jsxs("div",{className:"mdocs-ai-write-line del mdocs-ai-write-line-readonly",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:C||" "})]},`o${v}`))}),f.newLines.length>0||P!==""||b!=="del"?i.jsx(z,{className:"add",value:P,"aria-label":"提案新增行",onChange:C=>W(t.hunkIndex,C),onBlurFlush:()=>L()}):null]},t.key)}),w?i.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"变更导航",children:[i.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>N(-1),children:"↑"}),i.jsxs("span",{children:[E+1," / ",m.length]}),i.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>N(1),children:"↓"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>R(w),children:"拒绝"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>$(w),children:"接受"})]}):null]}):i.jsx("textarea",{className:"mdocs-ai-write-editor",value:e.currentMd,onChange:t=>e.onCurrentChange(t.target.value),spellCheck:!1,placeholder:`# 标题
|
|
6
6
|
|
|
7
|
-
在此编辑 Markdown 源码…`})]})}function xe(e){const[s,r]=d.useState(e.initialMarkdown),[n,o]=d.useState(null),[a]=d.useState(e.initialMarkdown),[l,x]=d.useState(e.displayName||"未命名"),[u,h]=d.useState(null),[M,c]=d.useState(!1),[y,k]=d.useState(null),[g,T]=d.useState(!1),[m,E]=d.useState(null),I=d.useRef(null);if(d.useEffect(()=>{e.open&&(r(e.initialMarkdown),o(null),x(e.displayName||"未命名"),k(null))},[e.open,e.initialMarkdown,e.displayName,e.documentId]),!e.open)return null;const L=n!=null&&n!==s?V(s,n):[];function $(N){return new Promise(S=>{I.current=S,E({message:N.message,confirmLabel:N.confirmLabel??"确定",cancelLabel:N.cancelLabel??"返回",danger:N.danger??!1})})}function R(N){const S=I.current;I.current=null,E(null),S==null||S(N)}async function q(){if(!await $({message:"是否回写",confirmLabel:"确认",cancelLabel:"返回"}))return;let S=s;L.length>0&&(S=n??s,r(S),o(null)),T(!0);const W=!e.documentId;try{const w=await e.onComplete({markdown:S,documentId:e.documentId,displayName:l.trim()||"未命名"}),B=w&&typeof w=="object"&&typeof w.documentId=="string"?w.documentId.trim():"";if(W&&B&&u)try{await Y(u,B)}catch{}e.onClose()}catch(w){if(w!=null&&w.silent||w instanceof Error&&w.message==="cancelled")return;k(w instanceof Error?w.message:String(w))}finally{T(!1)}}async function D(){(s!==a||n!=null)&&!await $({message:"取消帮写?未写回的修改将丢失。",confirmLabel:"放弃修改",danger:!0})||e.onClose()}return i.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[i.jsxs("header",{className:"mdocs-ai-write-header",children:[i.jsxs("div",{className:"mdocs-ai-write-header-left",children:[i.jsx("img",{src:O,alt:"",className:"mdocs-ai-write-title-logo"}),i.jsx("strong",{children:"帮写"}),i.jsx("input",{className:"mdocs-ai-write-title",value:l,onChange:N=>x(N.target.value),"aria-label":"文档标题"})]}),i.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[i.jsx("button",{type:"button",onClick:()=>void D(),disabled:g||m!=null,children:"取消"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void q(),disabled:g||m!=null,children:g?"写回中…":"完成并写回"})]})]}),y?i.jsx("p",{className:"mdocs-ai-write-error",children:y}):null,i.jsxs("div",{className:"mdocs-ai-write-body",children:[i.jsx("section",{className:"mdocs-ai-write-chat",children:i.jsx(
|
|
7
|
+
在此编辑 Markdown 源码…`})]})}function xe(e){const[s,r]=d.useState(e.initialMarkdown),[n,o]=d.useState(null),[a]=d.useState(e.initialMarkdown),[l,x]=d.useState(e.displayName||"未命名"),[u,h]=d.useState(null),[M,c]=d.useState(!1),[y,k]=d.useState(null),[g,T]=d.useState(!1),[m,E]=d.useState(null),I=d.useRef(null);if(d.useEffect(()=>{e.open&&(r(e.initialMarkdown),o(null),x(e.displayName||"未命名"),k(null))},[e.open,e.initialMarkdown,e.displayName,e.documentId]),!e.open)return null;const L=n!=null&&n!==s?V(s,n):[];function $(N){return new Promise(S=>{I.current=S,E({message:N.message,confirmLabel:N.confirmLabel??"确定",cancelLabel:N.cancelLabel??"返回",danger:N.danger??!1})})}function R(N){const S=I.current;I.current=null,E(null),S==null||S(N)}async function q(){if(!await $({message:"是否回写",confirmLabel:"确认",cancelLabel:"返回"}))return;let S=s;L.length>0&&(S=n??s,r(S),o(null)),T(!0);const W=!e.documentId;try{const w=await e.onComplete({markdown:S,documentId:e.documentId,displayName:l.trim()||"未命名"}),B=w&&typeof w=="object"&&typeof w.documentId=="string"?w.documentId.trim():"";if(W&&B&&u)try{await Y(u,B)}catch{}e.onClose()}catch(w){if(w!=null&&w.silent||w instanceof Error&&w.message==="cancelled")return;k(w instanceof Error?w.message:String(w))}finally{T(!1)}}async function D(){(s!==a||n!=null)&&!await $({message:"取消帮写?未写回的修改将丢失。",confirmLabel:"放弃修改",danger:!0})||e.onClose()}return i.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[i.jsxs("header",{className:"mdocs-ai-write-header",children:[i.jsxs("div",{className:"mdocs-ai-write-header-left",children:[i.jsx("img",{src:O,alt:"",className:"mdocs-ai-write-title-logo"}),i.jsx("strong",{children:"帮写"}),i.jsx("input",{className:"mdocs-ai-write-title",value:l,onChange:N=>x(N.target.value),"aria-label":"文档标题"})]}),i.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[i.jsx("button",{type:"button",onClick:()=>void D(),disabled:g||m!=null,children:"取消"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void q(),disabled:g||m!=null,children:g?"写回中…":"完成并写回"})]})]}),y?i.jsx("p",{className:"mdocs-ai-write-error",children:y}):null,i.jsxs("div",{className:"mdocs-ai-write-body",children:[i.jsx("section",{className:"mdocs-ai-write-chat",children:i.jsx(Z,{embedded:!0,open:!0,mode:"coding",documentId:e.documentId,workingMarkdown:s,baseMarkdown:a,onMarkdownSet:o,onSendingChange:c,onSessionId:h,onClose:e.onClose})}),i.jsx(le,{currentMd:s,proposedMd:n,sending:M,onCurrentChange:r,onProposedChange:o})]}),m?i.jsx(X,{message:m.message,confirmLabel:m.confirmLabel,cancelLabel:m.cancelLabel,danger:m.danger,onConfirm:()=>R(!0),onCancel:()=>R(!1)}):null]})}export{xe as AiWriteWorkbench};
|
package/dist/web/assets/{DiagramEditor-NtNY3sZL-D12WH5JY.js → DiagramEditor-NtNY3sZL-KWdKFFEL.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Q as I,S as H,T as F,U as O,V as G}from"./react-
|
|
1
|
+
import{Q as I,S as H,T as F,U as O,V as G}from"./react-C7aGt3wN.js";import{r as c,j as e}from"./react-vendor-BVS1XoFi.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-MY1Hyyeh.js";import{M as _}from"./meta2d-DP4Vt_ZE.js";import"./editor-DBWWidi3.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./index-Btfv_3-Q.js";import"./plus-DvWl4lHk.js";import"./copy-J9XXv57X.js";import"./check-BAYRiedE.js";let 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};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import{o as m,c as B,
|
|
1
|
+
import{o as m,c as B,U as A,V as S,W as k,l as j,Y as v,Z as I,_ as W,S as z,$ as H}from"./index-Btfv_3-Q.js";import{r as C,j as n}from"./react-vendor-BVS1XoFi.js";import{g as O}from"./file-type-policy-aRrzC4LZ.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 R=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],
|
|
6
|
+
*/const R=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],L=m("chevron-up",R);/**
|
|
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
|
|
11
|
+
*/const T=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M6.376 18.91a6 6 0 0 1 11.249.003",key:"hnjrf2"}],["circle",{cx:"12",cy:"11",r:"4",key:"1gt34v"}]],q=m("shield-user",T);/**
|
|
12
12
|
* @license lucide-react v0.562.0 - ISC
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const _=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],K=m("text-align-justify",_);function N(){if(typeof navigator>"u")return!1;const e=navigator.userAgent||"",a=navigator.platform||"";return/Mac|iPhone|iPad|iPod/i.test(a)||/Mac OS X|Macintosh/i.test(e)}function U(){return N()?"⌘+Enter":"Alt+Enter"}function V(e){return e.key!=="Enter"||e.shiftKey||e.ctrlKey?!1:N()?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}function J(e){const{t:a,lang:u}=B(),l=O(e.fileType||"md"),D=!!(l!=null&&l.aiWrite&&e.onAiWrite),M=!!(l!=null&&l.comments&&e.onToggleComments),h=e.canEdit&&(e.editing||!!e.actionsAlwaysVisible),[c,P]=C.useState(!1),y=e.domains.length?e.domains:[A],b=!e.readerChrome&&!!e.onPublish&&h&&!e.busy;C.useEffect(()=>{if(!b)return;const t=o=>{var d;V(o)&&(o.preventDefault(),(d=e.onPublish)==null||d.call(e))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[b,e.onPublish]);const E=e.readerChrome?a("publish"):a("publishHotkeyHint",{hotkey:U()}),w=n.jsxs("span",{className:"mdocs-save-indicator","aria-live":"polite",children:[n.jsx("span",{className:"mdocs-save-dot "+(e.busy?"saving":e.draftExists?"unsaved":"saved")}),n.jsx("span",{children:e.busy?a("publishing"):e.draftExists?a("unsaved"):a("published")})]}),s="mdocs-editor-toolbar"+(e.readerChrome?e.readerHeaderDocked?" mdocs-editor-toolbar--docked":" mdocs-editor-toolbar--float":""),r=e.readerChrome&&!e.readerHeaderDocked&&e.readerDragOffset?{transform:`translateY(${e.readerDragOffset}px)`}:void 0;if(e.readerChrome){const t=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":a("expandSidebar"),children:n.jsx(S,{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:a("displayNamePlaceholder"),disabled:!e.editing,readOnly:!e.editing})]}),o=n.jsx(k,{domains:y,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:i=>j(i,u,a)}),d=e.canEdit&&e.onPublish?n.jsx("button",{type:"button",className:"primary mdocs-reader-action-btn",disabled:e.busy,onMouseDown:i=>i.preventDefault(),onClick:()=>{var i,f;e.editing||(i=e.onEnterEdit)==null||i.call(e),(f=e.onPublish)==null||f.call(e)},children:e.busy?a("publishing"):a("publish")}):null,g=e.onSyncClick?n.jsx("button",{type:"button",className:"mdocs-sync-btn mdocs-reader-sync-btn"+(e.syncBehind?" behind":""),"aria-label":e.syncBehind?a("syncBehindHint"):a("syncPull"),onClick:()=>{var i;return void((i=e.onSyncClick)==null?void 0:i.call(e))},children:n.jsx(v,{size:16,strokeWidth:1.75})}):null,x=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(I,{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:s+" mdocs-editor-toolbar--stacked",style:r,children:[n.jsxs("div",{className:"mdocs-reader-top-row",children:[t,g,n.jsx("button",{type:"button",className:"mdocs-reader-expand-btn",onClick:()=>P(i=>!i),"aria-label":c?"收起操作栏":"展开操作栏",children:n.jsx(
|
|
16
|
+
*/const _=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],K=m("text-align-justify",_);function N(){if(typeof navigator>"u")return!1;const e=navigator.userAgent||"",a=navigator.platform||"";return/Mac|iPhone|iPad|iPod/i.test(a)||/Mac OS X|Macintosh/i.test(e)}function U(){return N()?"⌘+Enter":"Alt+Enter"}function V(e){return e.key!=="Enter"||e.shiftKey||e.ctrlKey?!1:N()?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}function J(e){const{t:a,lang:u}=B(),l=O(e.fileType||"md"),D=!!(l!=null&&l.aiWrite&&e.onAiWrite),M=!!(l!=null&&l.comments&&e.onToggleComments),h=e.canEdit&&(e.editing||!!e.actionsAlwaysVisible),[c,P]=C.useState(!1),y=e.domains.length?e.domains:[A],b=!e.readerChrome&&!!e.onPublish&&h&&!e.busy;C.useEffect(()=>{if(!b)return;const t=o=>{var d;V(o)&&(o.preventDefault(),(d=e.onPublish)==null||d.call(e))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[b,e.onPublish]);const E=e.readerChrome?a("publish"):a("publishHotkeyHint",{hotkey:U()}),w=n.jsxs("span",{className:"mdocs-save-indicator","aria-live":"polite",children:[n.jsx("span",{className:"mdocs-save-dot "+(e.busy?"saving":e.draftExists?"unsaved":"saved")}),n.jsx("span",{children:e.busy?a("publishing"):e.draftExists?a("unsaved"):a("published")})]}),s="mdocs-editor-toolbar"+(e.readerChrome?e.readerHeaderDocked?" mdocs-editor-toolbar--docked":" mdocs-editor-toolbar--float":""),r=e.readerChrome&&!e.readerHeaderDocked&&e.readerDragOffset?{transform:`translateY(${e.readerDragOffset}px)`}:void 0;if(e.readerChrome){const t=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":a("expandSidebar"),children:n.jsx(S,{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:a("displayNamePlaceholder"),disabled:!e.editing,readOnly:!e.editing})]}),o=n.jsx(k,{domains:y,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:i=>j(i,u,a)}),d=e.canEdit&&e.onPublish?n.jsx("button",{type:"button",className:"primary mdocs-reader-action-btn",disabled:e.busy,onMouseDown:i=>i.preventDefault(),onClick:()=>{var i,f;e.editing||(i=e.onEnterEdit)==null||i.call(e),(f=e.onPublish)==null||f.call(e)},children:e.busy?a("publishing"):a("publish")}):null,g=e.onSyncClick?n.jsx("button",{type:"button",className:"mdocs-sync-btn mdocs-reader-sync-btn"+(e.syncBehind?" behind":""),"aria-label":e.syncBehind?a("syncBehindHint"):a("syncPull"),onClick:()=>{var i;return void((i=e.onSyncClick)==null?void 0:i.call(e))},children:n.jsx(v,{size:16,strokeWidth:1.75})}):null,x=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(I,{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:s+" mdocs-editor-toolbar--stacked",style:r,children:[n.jsxs("div",{className:"mdocs-reader-top-row",children:[t,g,n.jsx("button",{type:"button",className:"mdocs-reader-expand-btn",onClick:()=>P(i=>!i),"aria-label":c?"收起操作栏":"展开操作栏",children:n.jsx(L,{size:16,strokeWidth:2,style:{transform:c?"rotate(0deg)":"rotate(180deg)",transition:"transform 0.2s"}})}),x]}),c&&n.jsxs("div",{className:"mdocs-reader-actions-row",children:[o,e.leadingExtra,d,e.trailingExtra]})]}):n.jsxs("div",{className:s,style:r,children:[t,o,e.leadingExtra,g,d,x,e.trailingExtra]})}return n.jsxs("div",{className:s,style:r,children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",children:[n.jsx("input",{className:"mdocs-editor-title-input",value:e.displayName,onChange:t=>e.onDisplayNameChange(t.target.value),onBlur:e.onDisplayNameBlur,placeholder:a("displayNamePlaceholder"),disabled:!e.editing}),n.jsx(k,{domains:y,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:t=>j(t,u,a)}),D?n.jsxs("button",{type:"button",className:"secondary",onClick:()=>{var t;return(t=e.onAiWrite)==null?void 0:t.call(e)},style:{padding:"4px 10px",whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",gap:6},children:[n.jsx("img",{src:W,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 t;return(t=e.onToggleBookmark)==null?void 0:t.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(z,{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?a("syncBehindHint"):a("syncPull"),onClick:()=>{var t;return void((t=e.onSyncClick)==null?void 0:t.call(e))},style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx(v,{size:16,strokeWidth:1.5}),n.jsx("span",{children:a("syncPull")})]}):null,h?n.jsxs(n.Fragment,{children:[w,e.onPublish?n.jsx("button",{type:"button",className:"primary mdocs-tooltip mdocs-tooltip-bottom",disabled:e.busy,"data-tooltip":E,onMouseDown:t=>t.preventDefault(),onClick:()=>{var t;return(t=e.onPublish)==null?void 0:t.call(e)},children:e.busy?a("publishing"):a("publish")}):null,e.onDelete?n.jsx("button",{type:"button",className:"danger",disabled:e.busy,onClick:()=>{var t;return(t=e.onDelete)==null?void 0:t.call(e)},children:a("delete")}):null]}):null,!e.editing&&e.canEdit&&e.onEnterEdit&&!e.actionsAlwaysVisible?n.jsx("button",{type:"button",className:"primary",onClick:()=>{var t;return(t=e.onEnterEdit)==null?void 0:t.call(e)},children:a("edit")}):null,e.trailingExtra,M?n.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var t;return(t=e.onToggleComments)==null?void 0:t.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(H,{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":a("docInfo"),style:{position:"relative"},children:[n.jsx("button",{type:"button",className:"secondary",onClick:()=>{var t;return(t=e.onToggleDocInfo)==null?void 0:t.call(e)},style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx(K,{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{J as D,q as S};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as n,j as a}from"./react-vendor-BVS1XoFi.js";import{ad as ge}from"./ui-CEFkTVnG.js";import{g as be,u as Ee,a as ve,s as We,d as Ge,b as xe,c as Ye,f as Je,e as $e,h as Ke,N as Xe,S as Qe,l as Ze,r as pe,i as et,j as tt,D as ee,k as nt,m as at,n as Ie}from"./index-DHKGh7I3.js";import{z as it,A as rt,m as ce,n as ot,o as st,p as ct,r as lt,s as ut,t as dt,v as mt,x as ft,B as ht,R as yt,a as gt,b as ke,c as vt,d as xt,e as It,f as kt,g as St,h as Ct,i as wt,w as le,j as bt,O as Et,E as Mt,q as Dt,l as Rt,C as jt,D as At}from"./react-BiN5Ertc.js";import{H as Nt,a as Tt,b as Pt,M as Bt,T as Lt,S as Ot,W as _t,o as zt,c as Se}from"./Toolbar-Caimz2EG.js";import{D as Ft,S as Ht}from"./DocChrome-CjNrjXnZ.js";import{V as Ut,U as qt}from"./VisitorPickerModal-BiMxEHCX.js";import{c as Vt}from"./docPlainCharCount-DO5lb3Wt.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./editor-DBWWidi3.js";import"./plus-BMAfiGed.js";import"./copy-Bp0JPDN6.js";import"./check-IPzs2Va9.js";import"./italic-BOhgURiY.js";import"./file-type-policy-C6Nun42Q.js";const Wt=48;function te(e){try{const r=e.getDocument("markdown");return typeof r=="string"?r:""}catch{return null}}function Gt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function Yt({editor:e,documentId:r,displayName:l,debounceMs:g=1e3,enabled:y=!0,localBaseCommitIdAtEditStart:C,snapshotMeta:D,seedDraftExists:F=!1}){const[H,_]=n.useState(!1),[ne,T]=n.useState(F),[P,w]=n.useState(null),d=n.useRef(null),h=n.useRef(null),I=n.useRef(!1),x=n.useRef(""),v=n.useRef(!1),z=n.useRef(r),U=n.useRef(l),B=n.useRef(C),J=n.useRef(D);z.current=r,U.current=l,B.current=C,J.current=D;const b=n.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const c=Gt(e);c!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",z.current,"content preview:",c.slice(0,80)),await be(z.current).execute(()=>Ee({documentId:z.current,content:c,displayName:U.current,localBaseCommitIdAtEditStart:B.current,snapshotMeta:J.current})),x.current=te(e)??x.current,T(!0),_(!1),w(Date.now()),I.current=!0,v.current=!1)},[e]);n.useEffect(()=>{let c=!1;const f=xe();return ve(r).then(m=>{if(c||xe()!==f)return;const R=!!(m&&!m.published);T(R),R&&m?(w(m.updatedAt),I.current=!0):(w(null),I.current=!1,v.current=!1)}),()=>{c=!0}},[r]),n.useEffect(()=>We((c,f)=>{c===z.current&&(T(f),f||(w(null),I.current=!1))}),[]),n.useEffect(()=>{var W,k;if(!y){(W=h.current)==null||W.call(h),h.current=null;return}if(!e)return;const c=e.getLexicalEditor();if(!c)return;(k=h.current)==null||k.call(h);let f=!1,m=0,R=0;const V=()=>{if(f)return;const E=te(e);if(E===null){if(R+=1,R>Wt)return;m=requestAnimationFrame(V);return}x.current=E;const G=c.registerUpdateListener(()=>{const L=te(e);L!==null&&L!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",r,"oldLen:",x.current.length,"newLen:",L.length),x.current=L,_(!0),v.current=!0,I.current=!1,d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,b()},g))});h.current=()=>{G(),d.current&&(clearTimeout(d.current),d.current=null)}};return queueMicrotask(()=>{f||(m=requestAnimationFrame(V))}),()=>{var E;f=!0,cancelAnimationFrame(m),(E=h.current)==null||E.call(h)}},[y,e,r,l,g,C,D,b]),n.useEffect(()=>{var m;if(!y||!e)return;const c=(m=e.getLexicalEditor())==null?void 0:m.getRootElement();if(!c)return;const f=()=>{d.current&&(clearTimeout(d.current),d.current=null),v.current&&b()};return c.addEventListener("blur",f),()=>c.removeEventListener("blur",f)},[y,e,b]),n.useEffect(()=>{if(!y)return;const c=()=>{document.visibilityState==="hidden"&&(d.current&&(clearTimeout(d.current),d.current=null),v.current&&b())},f=()=>{v.current&&(d.current&&(clearTimeout(d.current),d.current=null),b())};return document.addEventListener("visibilitychange",c),window.addEventListener("beforeunload",f),()=>{document.removeEventListener("visibilitychange",c),window.removeEventListener("beforeunload",f)}},[y,b]);async function $(){await Ge(r),T(!1),_(!1),v.current=!1,I.current=!1,x.current=""}async function K(){const c=await ve(r);return c?c.content:null}function q(){T(!0),_(!1),v.current=!1,w(Date.now()),I.current=!0,e&&(x.current=te(e)??"")}return{isDirty:H,draftExists:ne,lastSavedAt:P,clearDraft:$,loadDraftContent:K,markDraftSaved:q}}function Jt({isDirty:e,draftExists:r}){const l=e&&!r;n.useEffect(()=>{if(!l)return;const g=y=>{y.preventDefault()};return window.addEventListener("beforeunload",g),()=>window.removeEventListener("beforeunload",g)},[l])}function ue(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Ce='{"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 we(e){const l=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(l)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(l)?"不支持的文件类型":/^not an image$/i.test(l)?"不是有效的图片文件":l||"上传失败"}function $t(e,r){if(!e)return r==="json"?Ce:e;if(r!=="json")return e;try{const l=JSON.parse(e);if(l!=null&&l.root&&Array.isArray(l.root.children)&&l.root.children.length===0)return Ce}catch{}return e}function Kt({editor:e}){const{visible:r}=jt();return a.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:r?200:0},children:a.jsx("div",{style:{width:200},children:a.jsx(At,{editor:e})})})}function fn(e){const{t:r,lang:l}=Ye(),[g,y]=n.useState(!1),[C,D]=n.useState(!1),F=n.useRef(null),H=n.useRef(null),[_,ne]=n.useState([]),[T,P]=n.useState(!1),[w,d]=n.useState(e.meta.permission),[h,I]=n.useState(!1),[x,v]=n.useState(!1),[z,U]=n.useState(!1),[B,J]=n.useState(new Map),[b,$]=n.useState(!1),[K,q]=n.useState(null),c=n.useRef(0);n.useEffect(()=>{const t=i=>{F.current&&!F.current.contains(i.target)&&y(!1),H.current&&!H.current.contains(i.target)&&D(!1)};return(g||C)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[g,C]),n.useEffect(()=>{let t=!0;return Je().then(i=>{t&&ne(i)}).catch(()=>{}),()=>{t=!1}},[]);function f(t){const i=_.find(o=>o.visitorId===t);return(i==null?void 0:i.visitorName)??t.slice(0,8)}const[m,R]=n.useState(e.initialDisplayName),[V,W]=n.useState(!1),[k,E]=n.useState(!1),[G,L]=n.useState(!1),[Me,De]=n.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),ae=e.canEdit&&Me,[u,de]=n.useState(null),[Re,me]=n.useState(!1),ie=n.useRef(null);n.useLayoutEffect(()=>{me(!1),de(null),ie.current=null},[e.meta.documentId]),n.useEffect(()=>{const t=requestAnimationFrame(()=>me(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]),n.useEffect(()=>{if(!g&&!C)return;const t=++c.current;q(null);const i=()=>{if(t===c.current)try{let s=e.initialContent||"";if(u)try{const N=u.getDocument("markdown");typeof N=="string"&&(s=N)}catch{}const S=Vt("md",s);t===c.current&&q(S)}catch{t===c.current&&q(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const s=o.requestIdleCallback(i);return()=>{var S;return(S=o.cancelIdleCallback)==null?void 0:S.call(o,s)}}const M=window.setTimeout(i,0);return()=>window.clearTimeout(M)},[g,C,u,e.initialContent,e.meta.documentId,e.contentRevision]);const j=n.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const i=JSON.parse(e.initialContent);return Array.isArray((t=i==null?void 0:i.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),X=n.useMemo(()=>$t(e.initialContent||"",j),[e.initialContent,j,e.contentRevision]),{isDirty:fe,draftExists:Q,markDraftSaved:je}=Yt({editor:u,documentId:e.meta.documentId,displayName:m,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,Q)},[Q,e.onDraftExistsChange]),Jt({isDirty:fe,draftExists:Q}),n.useEffect(()=>{if(u)try{u.setDocument(j,X)}catch{}},[u,e.meta.documentId,e.contentRevision,j]),n.useEffect(()=>{u==null||u.setLocale(l==="zh"?it:rt)},[u,l]),n.useEffect(()=>{R(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 i=await $e(e.meta.documentId);t&&E(i.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function re(){var t,i;if(!G){L(!0);try{k?(await pe(e.meta.documentId),E(!1),(t=e.onShowToast)==null||t.call(e,r("bookmarkRemoved"))):(await et(e.meta.documentId),E(!0),(i=e.onShowToast)==null||i.call(e,r("bookmarkAdded")))}finally{L(!1)}}}n.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=_e),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),n.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ie.current;if(!t)return"";try{const i=t.getDocument("markdown");return typeof i=="string"?i:String(i??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function Ae(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const Ne=n.useCallback(t=>{ie.current=t,de(t);const i=X;if(!i)return;const o=()=>{try{t.setDocument(j,i)}catch{requestAnimationFrame(()=>{try{t.setDocument(j,i)}catch{}})}};queueMicrotask(()=>{queueMicrotask(o)})},[j,X]);async function he(){if(!u||!e.canEdit)return;const t=document.querySelector(".mdocs-editor-scroll-host"),i=(t==null?void 0:t.scrollTop)??null;W(!0);try{const o=ue(u);if(!o)return;await e.onPublish(o,m,e.meta.documentId)}catch(o){throw o}finally{W(!1),t&&i!=null&&(t.scrollTop=i,requestAnimationFrame(()=>{t.scrollTop=i}))}}async function Te(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(m.trim()!==t)try{await he()}catch{}}const A=n.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),Pe=n.useMemo(()=>{const t=(A==null?void 0:A.permission)??"public";return Ke(t)},[A==null?void 0:A.permission]);function Be(t){return t===ee.PRIVATE?r("permissionPrivate"):t===ee.DOMAIN_READ?r("permissionInvite"):t===ee.DOMAIN_WRITE?r("permissionDomainWrite"):t===ee.PUBLIC_READ?r("permissionPublicRead"):r("permissionPublicEdit")}async function Le(){var t;if(h||w===e.meta.permission){P(!1);return}I(!0);try{const o=(u?ue(u):null)??e.initialContent;await e.onPublish(o,m,e.meta.documentId,w),P(!1),(t=e.onShowToast)==null||t.call(e,r("docInfoPermissionUpdated"))}finally{I(!1)}}async function Oe(t){var i;if(!b){$(!0);try{const o=new Set(t.map(s=>s.visitorId)),M=new Map(t.map(s=>[s.visitorId,s.permission]));for(const[s]of B)o.has(s)||await nt(e.meta.documentId,s);for(const{visitorId:s,permission:S}of t){const N=B.get(s);(!N||N!==S)&&await at(e.meta.documentId,s,S)}v(!1),(i=e.onShowToast)==null||i.call(e,r("docInfoInviteSuccess",{count:t.length}))}finally{$(!1)}}}async function _e(){if(!u||!e.canEdit)return;if(!fe){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=ue(u);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),je(),await be(e.meta.documentId).execute(()=>Ee({documentId:e.meta.documentId,content:t,displayName:m,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const ze=n.useMemo(()=>[{icon:Nt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(ce,{tag:"h1"})}},{icon:Tt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(ce,{tag:"h2"})}},{icon:Pt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(ce,{tag:"h3"})}},{type:"divider"},{icon:Bt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(ot,{})}},{icon:Lt,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(st,{columns:"3",rows:"3"})}},{icon:Ot,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(ct,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{zt(i=>{for(const o of i)t.dispatchCommand(Dt,{file:o})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(lt,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(ut,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(dt,void 0),queueMicrotask(()=>t.focus())}},{icon:_t,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(mt,void 0),queueMicrotask(()=>t.focus())}},{icon:Xe,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ft,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})}),[]),Fe=n.useMemo(()=>[ht,yt,gt,ke,vt,xt,It,kt,St,Ct,wt,le(bt,{children:u?a.jsx(Se,{editor:u,floating:!0,outlineCollapseTitle:r("outlineHide"),outlineExpandTitle:r("outlineShow"),outlineToggle:!0}):null}),le(Rt,{handleUpload:async t=>{var i;try{return{url:await Ie(t,e.meta.documentId)}}catch(o){throw(i=e.onShowError)==null||i.call(e,we(o)),o}}}),le(ke,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var i;try{const M=await(await fetch(t)).blob(),s=new File([M],"image.png",{type:M.type});return{url:await Ie(s,e.meta.documentId)}}catch(o){throw(i=e.onShowError)==null||i.call(e,we(o)),o}}})],[u,r,e.meta.documentId,e.onShowError]),O=!!e.readerChrome,[Y,oe]=n.useState(!1),Z=n.useRef(null),[He,se]=n.useState(0);n.useEffect(()=>{if(!O){oe(!1),se(0);return}if(Y)return;const t=window.setTimeout(()=>oe(!0),2800);return()=>window.clearTimeout(t)},[O,Y,e.meta.documentId]),n.useEffect(()=>{D(!1),y(!1)},[e.meta.documentId]);function Ue(t){!O||Y||t.target.closest("button, a, input, textarea, select")||(Z.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function qe(t){const i=Z.current;if(!(i!=null&&i.dragging))return;const o=t.clientY-i.startY;se(Math.max(-72,Math.min(0,o)))}function Ve(t){const i=Z.current;if(!(i!=null&&i.dragging))return;Z.current=null;const o=t.clientY-i.startY;se(0),o<-36&&oe(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function p(){y(!1),D(!1)}function ye(t,i){const o=(i==null?void 0:i.includeBookmark)??!0,M={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:r("docInfoCreator")}),a.jsx("span",{children:f(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:r("docInfoCreatedAt")}),a.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(l==="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:r("docInfoSize")}),a.jsx("span",{children:Ae(new Blob([e.initialContent]).size)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCharCount")}),a.jsx("span",{children:K===null?"…":K.toLocaleString(l==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoUpdatedAt")}),a.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(l==="zh"?"zh-CN":"en-US")})]})]}),a.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{re(),t()},children:[a.jsx("span",{children:k?"⭐":"☆"}),a.jsx("span",{children:r(k?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{U(!0);try{const s=await tt(e.meta.documentId),S=new Map(s.map(N=>[N.visitorId,N.permission]));J(S),v(!0)}finally{U(!1)}})()},children:[a.jsx(qt,{size:14}),a.jsx("span",{children:r("docInfoInviteMember")})]}):null,a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),d(e.meta.permission),P(!0)},children:[a.jsx(Ht,{size:14}),a.jsx("span",{children:r("docInfoChangePermission")})]})]})}return a.jsxs("div",{className:"mdocs-editor"+(O?" mdocs-editor--reader":"")+(O&&Y?" mdocs-editor--reader-docked":""),children:[a.jsx(Ft,{fileType:e.meta.fileType||"md",displayName:m,onDisplayNameChange:R,onDisplayNameBlur:()=>void Te(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:ae,onEnterEdit:()=>De(!0),onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:V,draftExists:Q,onPublish:()=>{he().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:k,bookmarkBusy:G,onToggleBookmark:()=>void re(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:ye(p),docInfoOpen:g,onToggleDocInfo:()=>y(!g),docInfoMenuRef:F,readerChrome:O,onOpenMobileNav:e.onOpenMobileNav,readerHeaderDocked:Y,readerDragOffset:He,onReaderHeaderPointerDown:Ue,onReaderHeaderPointerMove:qe,onReaderHeaderPointerUp:Ve,readerMoreOpen:C,onToggleReaderMore:()=>D(t=>!t),readerMoreMenuRef:H,readerMoreMenu:a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:G,onClick:()=>{re(),p()},children:[a.jsx(Qe,{size:16,strokeWidth:1.5,style:{color:k?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:k?"#faad14":"none"}}),a.jsx("span",{children:r(k?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?a.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:V,onClick:()=>{p(),e.onDelete()},children:a.jsx("span",{children:r("delete")})}):null,a.jsx("div",{className:"mdocs-reader-more-divider"}),ye(p,{includeBookmark:!1})]})}),T&&a.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&P(!1)},children:a.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[a.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:r("docInfoChangePermission")}),a.jsxs("div",{className:"muted",style:{marginBottom:12},children:[r("domainPermission"),":",A?Ze(A.domainName,l,r):e.meta.domainId]}),a.jsx("div",{style:{display:"grid",gap:8},children:Pe.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:w===t,onChange:()=>d(t)}),a.jsx("span",{children:Be(t)})]},t))}),a.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[a.jsx("button",{type:"button",onClick:()=>P(!1),children:r("cancel")}),a.jsx("button",{type:"button",className:"primary",disabled:h,onClick:()=>void Le(),children:r(h?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&a.jsx(Ut,{open:x,title:r("docInfoInviteMember"),initialSelectedIds:[...B.keys()],initialPermissions:B,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:r("invitePermissionRead")},{value:"edit",label:r("invitePermissionEdit")}],onClose:()=>v(!1),onConfirm:t=>{Oe(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:[ae&&u&&!O?a.jsx(Se,{editor:u,outlineCollapseTitle:r("outlineHide"),outlineExpandTitle:r("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:Re?a.jsx(Mt,{content:X,type:j,confirmPasteMarkdown:!0,editable:ae,onInit:Ne,plugins:Fe,lineEmptyPlaceholder:r("displayNamePlaceholder"),placeholder:r("displayNamePlaceholder"),slashOption:{items:ze},className:"mdocs-document-editor-root"},e.meta.documentId):null}),u&&a.jsx(Kt,{editor:u})]})})]})})})]})}export{fn as DocumentEditor};
|
|
1
|
+
import{r as n,j as a}from"./react-vendor-BVS1XoFi.js";import{ad as ge}from"./ui-CEFkTVnG.js";import{g as be,u as Ee,a as ve,s as We,d as Ge,b as xe,c as Ye,f as Je,e as $e,h as Ke,N as Xe,S as Qe,l as Ze,r as pe,i as et,j as tt,D as ee,k as nt,m as at,n as Ie}from"./index-Btfv_3-Q.js";import{z as it,A as rt,m as ce,n as ot,o as st,p as ct,r as lt,s as ut,t as dt,v as mt,x as ft,B as ht,R as yt,a as gt,b as ke,c as vt,d as xt,e as It,f as kt,g as St,h as Ct,i as wt,w as le,j as bt,O as Et,E as Mt,q as Dt,l as Rt,C as jt,D as At}from"./react-C7aGt3wN.js";import{H as Nt,a as Tt,b as Pt,M as Bt,T as Lt,S as Ot,W as _t,o as zt,c as Se}from"./Toolbar-C1HmC2Qc.js";import{D as Ft,S as Ht}from"./DocChrome-CtT7xOl6.js";import{V as Ut,U as qt}from"./VisitorPickerModal-Cx03Papl.js";import{c as Vt}from"./docPlainCharCount-DO5lb3Wt.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./editor-DBWWidi3.js";import"./plus-DvWl4lHk.js";import"./copy-J9XXv57X.js";import"./check-BAYRiedE.js";import"./italic-BfR6fH81.js";import"./file-type-policy-aRrzC4LZ.js";const Wt=48;function te(e){try{const r=e.getDocument("markdown");return typeof r=="string"?r:""}catch{return null}}function Gt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function Yt({editor:e,documentId:r,displayName:l,debounceMs:g=1e3,enabled:y=!0,localBaseCommitIdAtEditStart:C,snapshotMeta:D,seedDraftExists:F=!1}){const[H,_]=n.useState(!1),[ne,T]=n.useState(F),[P,w]=n.useState(null),d=n.useRef(null),h=n.useRef(null),I=n.useRef(!1),x=n.useRef(""),v=n.useRef(!1),z=n.useRef(r),U=n.useRef(l),B=n.useRef(C),J=n.useRef(D);z.current=r,U.current=l,B.current=C,J.current=D;const b=n.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const c=Gt(e);c!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",z.current,"content preview:",c.slice(0,80)),await be(z.current).execute(()=>Ee({documentId:z.current,content:c,displayName:U.current,localBaseCommitIdAtEditStart:B.current,snapshotMeta:J.current})),x.current=te(e)??x.current,T(!0),_(!1),w(Date.now()),I.current=!0,v.current=!1)},[e]);n.useEffect(()=>{let c=!1;const f=xe();return ve(r).then(m=>{if(c||xe()!==f)return;const R=!!(m&&!m.published);T(R),R&&m?(w(m.updatedAt),I.current=!0):(w(null),I.current=!1,v.current=!1)}),()=>{c=!0}},[r]),n.useEffect(()=>We((c,f)=>{c===z.current&&(T(f),f||(w(null),I.current=!1))}),[]),n.useEffect(()=>{var W,k;if(!y){(W=h.current)==null||W.call(h),h.current=null;return}if(!e)return;const c=e.getLexicalEditor();if(!c)return;(k=h.current)==null||k.call(h);let f=!1,m=0,R=0;const V=()=>{if(f)return;const E=te(e);if(E===null){if(R+=1,R>Wt)return;m=requestAnimationFrame(V);return}x.current=E;const G=c.registerUpdateListener(()=>{const L=te(e);L!==null&&L!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",r,"oldLen:",x.current.length,"newLen:",L.length),x.current=L,_(!0),v.current=!0,I.current=!1,d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,b()},g))});h.current=()=>{G(),d.current&&(clearTimeout(d.current),d.current=null)}};return queueMicrotask(()=>{f||(m=requestAnimationFrame(V))}),()=>{var E;f=!0,cancelAnimationFrame(m),(E=h.current)==null||E.call(h)}},[y,e,r,l,g,C,D,b]),n.useEffect(()=>{var m;if(!y||!e)return;const c=(m=e.getLexicalEditor())==null?void 0:m.getRootElement();if(!c)return;const f=()=>{d.current&&(clearTimeout(d.current),d.current=null),v.current&&b()};return c.addEventListener("blur",f),()=>c.removeEventListener("blur",f)},[y,e,b]),n.useEffect(()=>{if(!y)return;const c=()=>{document.visibilityState==="hidden"&&(d.current&&(clearTimeout(d.current),d.current=null),v.current&&b())},f=()=>{v.current&&(d.current&&(clearTimeout(d.current),d.current=null),b())};return document.addEventListener("visibilitychange",c),window.addEventListener("beforeunload",f),()=>{document.removeEventListener("visibilitychange",c),window.removeEventListener("beforeunload",f)}},[y,b]);async function $(){await Ge(r),T(!1),_(!1),v.current=!1,I.current=!1,x.current=""}async function K(){const c=await ve(r);return c?c.content:null}function q(){T(!0),_(!1),v.current=!1,w(Date.now()),I.current=!0,e&&(x.current=te(e)??"")}return{isDirty:H,draftExists:ne,lastSavedAt:P,clearDraft:$,loadDraftContent:K,markDraftSaved:q}}function Jt({isDirty:e,draftExists:r}){const l=e&&!r;n.useEffect(()=>{if(!l)return;const g=y=>{y.preventDefault()};return window.addEventListener("beforeunload",g),()=>window.removeEventListener("beforeunload",g)},[l])}function ue(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Ce='{"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 we(e){const l=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(l)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(l)?"不支持的文件类型":/^not an image$/i.test(l)?"不是有效的图片文件":l||"上传失败"}function $t(e,r){if(!e)return r==="json"?Ce:e;if(r!=="json")return e;try{const l=JSON.parse(e);if(l!=null&&l.root&&Array.isArray(l.root.children)&&l.root.children.length===0)return Ce}catch{}return e}function Kt({editor:e}){const{visible:r}=jt();return a.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:r?200:0},children:a.jsx("div",{style:{width:200},children:a.jsx(At,{editor:e})})})}function fn(e){const{t:r,lang:l}=Ye(),[g,y]=n.useState(!1),[C,D]=n.useState(!1),F=n.useRef(null),H=n.useRef(null),[_,ne]=n.useState([]),[T,P]=n.useState(!1),[w,d]=n.useState(e.meta.permission),[h,I]=n.useState(!1),[x,v]=n.useState(!1),[z,U]=n.useState(!1),[B,J]=n.useState(new Map),[b,$]=n.useState(!1),[K,q]=n.useState(null),c=n.useRef(0);n.useEffect(()=>{const t=i=>{F.current&&!F.current.contains(i.target)&&y(!1),H.current&&!H.current.contains(i.target)&&D(!1)};return(g||C)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[g,C]),n.useEffect(()=>{let t=!0;return Je().then(i=>{t&&ne(i)}).catch(()=>{}),()=>{t=!1}},[]);function f(t){const i=_.find(o=>o.visitorId===t);return(i==null?void 0:i.visitorName)??t.slice(0,8)}const[m,R]=n.useState(e.initialDisplayName),[V,W]=n.useState(!1),[k,E]=n.useState(!1),[G,L]=n.useState(!1),[Me,De]=n.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),ae=e.canEdit&&Me,[u,de]=n.useState(null),[Re,me]=n.useState(!1),ie=n.useRef(null);n.useLayoutEffect(()=>{me(!1),de(null),ie.current=null},[e.meta.documentId]),n.useEffect(()=>{const t=requestAnimationFrame(()=>me(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]),n.useEffect(()=>{if(!g&&!C)return;const t=++c.current;q(null);const i=()=>{if(t===c.current)try{let s=e.initialContent||"";if(u)try{const N=u.getDocument("markdown");typeof N=="string"&&(s=N)}catch{}const S=Vt("md",s);t===c.current&&q(S)}catch{t===c.current&&q(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const s=o.requestIdleCallback(i);return()=>{var S;return(S=o.cancelIdleCallback)==null?void 0:S.call(o,s)}}const M=window.setTimeout(i,0);return()=>window.clearTimeout(M)},[g,C,u,e.initialContent,e.meta.documentId,e.contentRevision]);const j=n.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const i=JSON.parse(e.initialContent);return Array.isArray((t=i==null?void 0:i.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),X=n.useMemo(()=>$t(e.initialContent||"",j),[e.initialContent,j,e.contentRevision]),{isDirty:fe,draftExists:Q,markDraftSaved:je}=Yt({editor:u,documentId:e.meta.documentId,displayName:m,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,Q)},[Q,e.onDraftExistsChange]),Jt({isDirty:fe,draftExists:Q}),n.useEffect(()=>{if(u)try{u.setDocument(j,X)}catch{}},[u,e.meta.documentId,e.contentRevision,j]),n.useEffect(()=>{u==null||u.setLocale(l==="zh"?it:rt)},[u,l]),n.useEffect(()=>{R(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 i=await $e(e.meta.documentId);t&&E(i.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function re(){var t,i;if(!G){L(!0);try{k?(await pe(e.meta.documentId),E(!1),(t=e.onShowToast)==null||t.call(e,r("bookmarkRemoved"))):(await et(e.meta.documentId),E(!0),(i=e.onShowToast)==null||i.call(e,r("bookmarkAdded")))}finally{L(!1)}}}n.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=_e),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),n.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ie.current;if(!t)return"";try{const i=t.getDocument("markdown");return typeof i=="string"?i:String(i??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function Ae(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const Ne=n.useCallback(t=>{ie.current=t,de(t);const i=X;if(!i)return;const o=()=>{try{t.setDocument(j,i)}catch{requestAnimationFrame(()=>{try{t.setDocument(j,i)}catch{}})}};queueMicrotask(()=>{queueMicrotask(o)})},[j,X]);async function he(){if(!u||!e.canEdit)return;const t=document.querySelector(".mdocs-editor-scroll-host"),i=(t==null?void 0:t.scrollTop)??null;W(!0);try{const o=ue(u);if(!o)return;await e.onPublish(o,m,e.meta.documentId)}catch(o){throw o}finally{W(!1),t&&i!=null&&(t.scrollTop=i,requestAnimationFrame(()=>{t.scrollTop=i}))}}async function Te(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(m.trim()!==t)try{await he()}catch{}}const A=n.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),Pe=n.useMemo(()=>{const t=(A==null?void 0:A.permission)??"public";return Ke(t)},[A==null?void 0:A.permission]);function Be(t){return t===ee.PRIVATE?r("permissionPrivate"):t===ee.DOMAIN_READ?r("permissionInvite"):t===ee.DOMAIN_WRITE?r("permissionDomainWrite"):t===ee.PUBLIC_READ?r("permissionPublicRead"):r("permissionPublicEdit")}async function Le(){var t;if(h||w===e.meta.permission){P(!1);return}I(!0);try{const o=(u?ue(u):null)??e.initialContent;await e.onPublish(o,m,e.meta.documentId,w),P(!1),(t=e.onShowToast)==null||t.call(e,r("docInfoPermissionUpdated"))}finally{I(!1)}}async function Oe(t){var i;if(!b){$(!0);try{const o=new Set(t.map(s=>s.visitorId)),M=new Map(t.map(s=>[s.visitorId,s.permission]));for(const[s]of B)o.has(s)||await nt(e.meta.documentId,s);for(const{visitorId:s,permission:S}of t){const N=B.get(s);(!N||N!==S)&&await at(e.meta.documentId,s,S)}v(!1),(i=e.onShowToast)==null||i.call(e,r("docInfoInviteSuccess",{count:t.length}))}finally{$(!1)}}}async function _e(){if(!u||!e.canEdit)return;if(!fe){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=ue(u);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),je(),await be(e.meta.documentId).execute(()=>Ee({documentId:e.meta.documentId,content:t,displayName:m,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const ze=n.useMemo(()=>[{icon:Nt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(ce,{tag:"h1"})}},{icon:Tt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(ce,{tag:"h2"})}},{icon:Pt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(ce,{tag:"h3"})}},{type:"divider"},{icon:Bt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(ot,{})}},{icon:Lt,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(st,{columns:"3",rows:"3"})}},{icon:Ot,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(ct,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{zt(i=>{for(const o of i)t.dispatchCommand(Dt,{file:o})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(lt,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(ut,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(dt,void 0),queueMicrotask(()=>t.focus())}},{icon:_t,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(mt,void 0),queueMicrotask(()=>t.focus())}},{icon:Xe,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ft,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})}),[]),Fe=n.useMemo(()=>[ht,yt,gt,ke,vt,xt,It,kt,St,Ct,wt,le(bt,{children:u?a.jsx(Se,{editor:u,floating:!0,outlineCollapseTitle:r("outlineHide"),outlineExpandTitle:r("outlineShow"),outlineToggle:!0}):null}),le(Rt,{handleUpload:async t=>{var i;try{return{url:await Ie(t,e.meta.documentId)}}catch(o){throw(i=e.onShowError)==null||i.call(e,we(o)),o}}}),le(ke,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var i;try{const M=await(await fetch(t)).blob(),s=new File([M],"image.png",{type:M.type});return{url:await Ie(s,e.meta.documentId)}}catch(o){throw(i=e.onShowError)==null||i.call(e,we(o)),o}}})],[u,r,e.meta.documentId,e.onShowError]),O=!!e.readerChrome,[Y,oe]=n.useState(!1),Z=n.useRef(null),[He,se]=n.useState(0);n.useEffect(()=>{if(!O){oe(!1),se(0);return}if(Y)return;const t=window.setTimeout(()=>oe(!0),2800);return()=>window.clearTimeout(t)},[O,Y,e.meta.documentId]),n.useEffect(()=>{D(!1),y(!1)},[e.meta.documentId]);function Ue(t){!O||Y||t.target.closest("button, a, input, textarea, select")||(Z.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function qe(t){const i=Z.current;if(!(i!=null&&i.dragging))return;const o=t.clientY-i.startY;se(Math.max(-72,Math.min(0,o)))}function Ve(t){const i=Z.current;if(!(i!=null&&i.dragging))return;Z.current=null;const o=t.clientY-i.startY;se(0),o<-36&&oe(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function p(){y(!1),D(!1)}function ye(t,i){const o=(i==null?void 0:i.includeBookmark)??!0,M={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:r("docInfoCreator")}),a.jsx("span",{children:f(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:r("docInfoCreatedAt")}),a.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(l==="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:r("docInfoSize")}),a.jsx("span",{children:Ae(new Blob([e.initialContent]).size)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCharCount")}),a.jsx("span",{children:K===null?"…":K.toLocaleString(l==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoUpdatedAt")}),a.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(l==="zh"?"zh-CN":"en-US")})]})]}),a.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{re(),t()},children:[a.jsx("span",{children:k?"⭐":"☆"}),a.jsx("span",{children:r(k?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{U(!0);try{const s=await tt(e.meta.documentId),S=new Map(s.map(N=>[N.visitorId,N.permission]));J(S),v(!0)}finally{U(!1)}})()},children:[a.jsx(qt,{size:14}),a.jsx("span",{children:r("docInfoInviteMember")})]}):null,a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),d(e.meta.permission),P(!0)},children:[a.jsx(Ht,{size:14}),a.jsx("span",{children:r("docInfoChangePermission")})]})]})}return a.jsxs("div",{className:"mdocs-editor"+(O?" mdocs-editor--reader":"")+(O&&Y?" mdocs-editor--reader-docked":""),children:[a.jsx(Ft,{fileType:e.meta.fileType||"md",displayName:m,onDisplayNameChange:R,onDisplayNameBlur:()=>void Te(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:ae,onEnterEdit:()=>De(!0),onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:V,draftExists:Q,onPublish:()=>{he().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:k,bookmarkBusy:G,onToggleBookmark:()=>void re(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:ye(p),docInfoOpen:g,onToggleDocInfo:()=>y(!g),docInfoMenuRef:F,readerChrome:O,onOpenMobileNav:e.onOpenMobileNav,readerHeaderDocked:Y,readerDragOffset:He,onReaderHeaderPointerDown:Ue,onReaderHeaderPointerMove:qe,onReaderHeaderPointerUp:Ve,readerMoreOpen:C,onToggleReaderMore:()=>D(t=>!t),readerMoreMenuRef:H,readerMoreMenu:a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:G,onClick:()=>{re(),p()},children:[a.jsx(Qe,{size:16,strokeWidth:1.5,style:{color:k?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:k?"#faad14":"none"}}),a.jsx("span",{children:r(k?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?a.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:V,onClick:()=>{p(),e.onDelete()},children:a.jsx("span",{children:r("delete")})}):null,a.jsx("div",{className:"mdocs-reader-more-divider"}),ye(p,{includeBookmark:!1})]})}),T&&a.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&P(!1)},children:a.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[a.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:r("docInfoChangePermission")}),a.jsxs("div",{className:"muted",style:{marginBottom:12},children:[r("domainPermission"),":",A?Ze(A.domainName,l,r):e.meta.domainId]}),a.jsx("div",{style:{display:"grid",gap:8},children:Pe.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:w===t,onChange:()=>d(t)}),a.jsx("span",{children:Be(t)})]},t))}),a.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[a.jsx("button",{type:"button",onClick:()=>P(!1),children:r("cancel")}),a.jsx("button",{type:"button",className:"primary",disabled:h,onClick:()=>void Le(),children:r(h?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&a.jsx(Ut,{open:x,title:r("docInfoInviteMember"),initialSelectedIds:[...B.keys()],initialPermissions:B,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:r("invitePermissionRead")},{value:"edit",label:r("invitePermissionEdit")}],onClose:()=>v(!1),onConfirm:t=>{Oe(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:[ae&&u&&!O?a.jsx(Se,{editor:u,outlineCollapseTitle:r("outlineHide"),outlineExpandTitle:r("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:Re?a.jsx(Mt,{content:X,type:j,confirmPasteMarkdown:!0,editable:ae,onInit:Ne,plugins:Fe,lineEmptyPlaceholder:r("displayNamePlaceholder"),placeholder:r("displayNamePlaceholder"),slashOption:{items:ze},className:"mdocs-document-editor-root"},e.meta.documentId):null}),u&&a.jsx(Kt,{editor:u})]})})]})})})]})}export{fn as DocumentEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as i,j as n}from"./react-vendor-BVS1XoFi.js";import{c as xe,f as ve,e as ge,a as ye,s as be,g as Ce,u as ke,h as je,S as Ie,l as we,r as De,i as Se,j as Ee,D as E,k as Ne,m as Pe,b as Z}from"./index-DHKGh7I3.js";import{D as Me,S as Be}from"./DocChrome-CjNrjXnZ.js";import{V as Re,U as Ae}from"./VisitorPickerModal-BiMxEHCX.js";import{c as Te}from"./docPlainCharCount-DO5lb3Wt.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./file-type-policy-C6Nun42Q.js";function _e(e){const{t:a,lang:k}=xe(),r=e.meta.documentId,[h,N]=i.useState(e.initialContent),[x,P]=i.useState(e.initialDisplayName),[u,j]=i.useState(!0),[q,G]=i.useState(!1),[p,I]=i.useState(e.hasLocalDraft??!1),[f,M]=i.useState(!1),[B,K]=i.useState(!1),[v,R]=i.useState(!1),[y,A]=i.useState(!1),[ee,te]=i.useState([]),[ne,b]=i.useState(!1),[T,z]=i.useState(e.meta.permission),[O,Q]=i.useState(!1),[ie,L]=i.useState(!1),[w,ae]=i.useState(new Map),[Y,V]=i.useState(null),D=i.useRef(0),U=i.useRef(null),F=i.useRef(null),c=i.useRef(null),S=i.useRef(h),W=i.useRef(x);S.current=h,W.current=x;const se=e.canEdit&&!u;i.useEffect(()=>{N(e.initialContent),P(e.initialDisplayName),j(!0)},[r]),i.useEffect(()=>{e.contentRevision&&(N(e.initialContent),P(e.initialDisplayName))},[e.contentRevision]),i.useEffect(()=>{let t=!0;return ve().then(s=>{t&&te(s)}).catch(()=>{}),()=>{t=!1}},[]),i.useEffect(()=>{let t=!0;return ge(r).then(s=>{t&&M(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),i.useEffect(()=>{let t=!1;const s=Z();return ye(r).then(o=>{var m;if(t||Z()!==s)return;const l=!!(o&&!o.published);I(l),(m=e.onDraftExistsChange)==null||m.call(e,l)}),()=>{t=!0}},[r,e.onDraftExistsChange]),i.useEffect(()=>be((t,s)=>{var o;t===r&&(I(s),(o=e.onDraftExistsChange)==null||o.call(e,s))}),[r,e.onDraftExistsChange]),i.useEffect(()=>{z(e.meta.permission)},[e.meta.permission,r]),i.useEffect(()=>{const t=s=>{U.current&&!U.current.contains(s.target)&&R(!1),F.current&&!F.current.contains(s.target)&&A(!1)};return(v||y)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[v,y]),i.useEffect(()=>{if(!v&&!y)return;const t=++D.current;V(null);const s=()=>{if(t===D.current)try{const m=Te("html",S.current||"");t===D.current&&V(m)}catch{t===D.current&&V(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const m=o.requestIdleCallback(s);return()=>{var C;return(C=o.cancelIdleCallback)==null?void 0:C.call(o,m)}}const l=window.setTimeout(s,0);return()=>window.clearTimeout(l)},[v,y,h,r,e.contentRevision]);const H=i.useCallback(async()=>{var t;await Ce(r).execute(()=>ke({documentId:r,content:S.current,displayName:W.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),I(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),J=i.useCallback(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{H()},1e3)},[H]);i.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);async function $(t){var s;if(e.canEdit){G(!0);try{c.current&&(clearTimeout(c.current),c.current=null),await H(),await e.onPublish(S.current,W.current.trim()||x,r,t),I(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{G(!1)}}}async function oe(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(x.trim()!==t)try{await $()}catch{}}async function _(){var t,s;if(!B){K(!0);try{f?(await De(r),M(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Se(r),M(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{K(!1)}}}function re(t){const s=ee.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function le(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const d=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),ce=i.useMemo(()=>{const t=(d==null?void 0:d.permission)??"public";return je(t)},[d==null?void 0:d.permission]);function de(t){return t===E.PRIVATE?a("permissionPrivate"):t===E.DOMAIN_READ?a("permissionInvite"):t===E.DOMAIN_WRITE?a("permissionDomainWrite"):t===E.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function me(){if(O||T===e.meta.permission){b(!1);return}Q(!0);try{await $(T),b(!1)}finally{Q(!1)}}async function ue(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of w)s.has(o)||await Ne(r,o);for(const o of t)w.get(o.visitorId)!==o.permission&&await Pe(r,o.visitorId,o.permission);L(!1)}function g(){R(!1),A(!1)}function X(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,l={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:re(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(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:le(new Blob([h]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCharCount")}),n.jsx("span",{children:Y===null?"…":Y.toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),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(k==="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:l,onClick:()=>{_(),t()},children:[n.jsx("span",{children:f?"⭐":"☆"}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),(async()=>{const m=await Ee(r);ae(new Map(m.map(C=>[C.visitorId,C.permission]))),L(!0)})()},children:[n.jsx(Ae,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),z(e.meta.permission),b(!0)},children:[n.jsx(Be,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}const fe=i.useCallback(t=>{var o;const s=t.target.value;N(s),(o=e.onContentChange)==null||o.call(e,s),J()},[e,J]),he=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${h}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(Me,{fileType:"html",displayName:x,onDisplayNameChange:P,onDisplayNameBlur:()=>void oe(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:se,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:q,draftExists:p,onPublish:()=>{$().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:f,bookmarkBusy:B,onToggleBookmark:()=>void _(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:X(g),docInfoOpen:v,onToggleDocInfo:()=>R(!v),docInfoMenuRef:U,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:y,onToggleReaderMore:()=>A(t=>!t),readerMoreMenuRef:F,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:B,onClick:()=>{_(),g()},children:[n.jsx(Ie,{size:16,strokeWidth:1.5,style:{color:f?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:f?"#faad14":"none"}}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!u,onClick:()=>{j(!1),g()},children:a("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:u,onClick:()=>{j(!0),g()},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:q,onClick:()=>{g(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),X(g,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":a(u?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:u,onChange:()=>j(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:[!u&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:h,onChange:fe,spellCheck:!1,placeholder:"在此处编写 HTML 代码"}):null,n.jsx("div",{className:"mdocs-html-editor-preview",style:!u&&e.canEdit?{width:"50%"}:{width:"100%"},children:n.jsx("iframe",{className:"mdocs-html-editor-iframe",srcDoc:he,sandbox:"",title:x})})]}),ne&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&b(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",d?we(d.domainName,k,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:ce.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:T===t,onChange:()=>z(t)}),n.jsx("span",{children:de(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>b(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:O,onClick:()=>void me(),children:a(O?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Re,{open:ie,title:a("docInfoInviteMember"),initialSelectedIds:[...w.keys()],initialPermissions:w,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>L(!1),onConfirm:t=>{ue(t)}})]})}export{_e as HtmlEditor};
|
|
1
|
+
import{r as i,j as n}from"./react-vendor-BVS1XoFi.js";import{c as xe,f as ve,e as ge,a as ye,s as be,g as Ce,u as ke,h as je,S as Ie,l as we,r as De,i as Se,j as Ee,D as E,k as Ne,m as Pe,b as Z}from"./index-Btfv_3-Q.js";import{D as Me,S as Be}from"./DocChrome-CtT7xOl6.js";import{V as Re,U as Ae}from"./VisitorPickerModal-Cx03Papl.js";import{c as Te}from"./docPlainCharCount-DO5lb3Wt.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./file-type-policy-aRrzC4LZ.js";function _e(e){const{t:a,lang:k}=xe(),r=e.meta.documentId,[h,N]=i.useState(e.initialContent),[x,P]=i.useState(e.initialDisplayName),[u,j]=i.useState(!0),[q,G]=i.useState(!1),[p,I]=i.useState(e.hasLocalDraft??!1),[f,M]=i.useState(!1),[B,K]=i.useState(!1),[v,R]=i.useState(!1),[y,A]=i.useState(!1),[ee,te]=i.useState([]),[ne,b]=i.useState(!1),[T,z]=i.useState(e.meta.permission),[O,Q]=i.useState(!1),[ie,L]=i.useState(!1),[w,ae]=i.useState(new Map),[Y,V]=i.useState(null),D=i.useRef(0),U=i.useRef(null),F=i.useRef(null),c=i.useRef(null),S=i.useRef(h),W=i.useRef(x);S.current=h,W.current=x;const se=e.canEdit&&!u;i.useEffect(()=>{N(e.initialContent),P(e.initialDisplayName),j(!0)},[r]),i.useEffect(()=>{e.contentRevision&&(N(e.initialContent),P(e.initialDisplayName))},[e.contentRevision]),i.useEffect(()=>{let t=!0;return ve().then(s=>{t&&te(s)}).catch(()=>{}),()=>{t=!1}},[]),i.useEffect(()=>{let t=!0;return ge(r).then(s=>{t&&M(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),i.useEffect(()=>{let t=!1;const s=Z();return ye(r).then(o=>{var m;if(t||Z()!==s)return;const l=!!(o&&!o.published);I(l),(m=e.onDraftExistsChange)==null||m.call(e,l)}),()=>{t=!0}},[r,e.onDraftExistsChange]),i.useEffect(()=>be((t,s)=>{var o;t===r&&(I(s),(o=e.onDraftExistsChange)==null||o.call(e,s))}),[r,e.onDraftExistsChange]),i.useEffect(()=>{z(e.meta.permission)},[e.meta.permission,r]),i.useEffect(()=>{const t=s=>{U.current&&!U.current.contains(s.target)&&R(!1),F.current&&!F.current.contains(s.target)&&A(!1)};return(v||y)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[v,y]),i.useEffect(()=>{if(!v&&!y)return;const t=++D.current;V(null);const s=()=>{if(t===D.current)try{const m=Te("html",S.current||"");t===D.current&&V(m)}catch{t===D.current&&V(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const m=o.requestIdleCallback(s);return()=>{var C;return(C=o.cancelIdleCallback)==null?void 0:C.call(o,m)}}const l=window.setTimeout(s,0);return()=>window.clearTimeout(l)},[v,y,h,r,e.contentRevision]);const H=i.useCallback(async()=>{var t;await Ce(r).execute(()=>ke({documentId:r,content:S.current,displayName:W.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),I(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),J=i.useCallback(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{H()},1e3)},[H]);i.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);async function $(t){var s;if(e.canEdit){G(!0);try{c.current&&(clearTimeout(c.current),c.current=null),await H(),await e.onPublish(S.current,W.current.trim()||x,r,t),I(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{G(!1)}}}async function oe(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(x.trim()!==t)try{await $()}catch{}}async function _(){var t,s;if(!B){K(!0);try{f?(await De(r),M(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Se(r),M(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{K(!1)}}}function re(t){const s=ee.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function le(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const d=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),ce=i.useMemo(()=>{const t=(d==null?void 0:d.permission)??"public";return je(t)},[d==null?void 0:d.permission]);function de(t){return t===E.PRIVATE?a("permissionPrivate"):t===E.DOMAIN_READ?a("permissionInvite"):t===E.DOMAIN_WRITE?a("permissionDomainWrite"):t===E.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function me(){if(O||T===e.meta.permission){b(!1);return}Q(!0);try{await $(T),b(!1)}finally{Q(!1)}}async function ue(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of w)s.has(o)||await Ne(r,o);for(const o of t)w.get(o.visitorId)!==o.permission&&await Pe(r,o.visitorId,o.permission);L(!1)}function g(){R(!1),A(!1)}function X(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,l={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:re(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(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:le(new Blob([h]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCharCount")}),n.jsx("span",{children:Y===null?"…":Y.toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),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(k==="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:l,onClick:()=>{_(),t()},children:[n.jsx("span",{children:f?"⭐":"☆"}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),(async()=>{const m=await Ee(r);ae(new Map(m.map(C=>[C.visitorId,C.permission]))),L(!0)})()},children:[n.jsx(Ae,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),z(e.meta.permission),b(!0)},children:[n.jsx(Be,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}const fe=i.useCallback(t=>{var o;const s=t.target.value;N(s),(o=e.onContentChange)==null||o.call(e,s),J()},[e,J]),he=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${h}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(Me,{fileType:"html",displayName:x,onDisplayNameChange:P,onDisplayNameBlur:()=>void oe(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:se,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:q,draftExists:p,onPublish:()=>{$().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:f,bookmarkBusy:B,onToggleBookmark:()=>void _(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:X(g),docInfoOpen:v,onToggleDocInfo:()=>R(!v),docInfoMenuRef:U,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:y,onToggleReaderMore:()=>A(t=>!t),readerMoreMenuRef:F,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:B,onClick:()=>{_(),g()},children:[n.jsx(Ie,{size:16,strokeWidth:1.5,style:{color:f?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:f?"#faad14":"none"}}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!u,onClick:()=>{j(!1),g()},children:a("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:u,onClick:()=>{j(!0),g()},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:q,onClick:()=>{g(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),X(g,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":a(u?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:u,onChange:()=>j(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:[!u&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:h,onChange:fe,spellCheck:!1,placeholder:"在此处编写 HTML 代码"}):null,n.jsx("div",{className:"mdocs-html-editor-preview",style:!u&&e.canEdit?{width:"50%"}:{width:"100%"},children:n.jsx("iframe",{className:"mdocs-html-editor-iframe",srcDoc:he,sandbox:"",title:x})})]}),ne&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&b(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",d?we(d.domainName,k,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:ce.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:T===t,onChange:()=>z(t)}),n.jsx("span",{children:de(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>b(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:O,onClick:()=>void me(),children:a(O?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Re,{open:ie,title:a("docInfoInviteMember"),initialSelectedIds:[...w.keys()],initialPermissions:w,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>L(!1),onConfirm:t=>{ue(t)}})]})}export{_e as HtmlEditor};
|