@fgbg/mdocs 0.8.22 → 0.8.24
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 +16 -1
- package/agent-skills/index.json +1 -1
- package/dist/server/agent/Agent/run.js +2 -2
- package/dist/server/agent/Agent/run.js.map +1 -1
- package/dist/server/agent/Agent/system-prompt.js +13 -3
- package/dist/server/agent/Agent/system-prompt.js.map +1 -1
- package/dist/server/cli/self-update.js +4 -0
- package/dist/server/cli/self-update.js.map +1 -1
- package/dist/server/routes/agent.routes.js +10 -0
- package/dist/server/routes/agent.routes.js.map +1 -1
- package/dist/web/assets/AgentChatPanel-BTCyf9Ww.js +1 -0
- package/dist/web/assets/{AgentSkillFormCard-goRzD94F.js → AgentSkillFormCard-CAD6QqQ0.js} +2 -2
- package/dist/web/assets/{AiWriteWorkbench-CMe6iuR8.js → AiWriteWorkbench-PVv90TJS.js} +1 -1
- package/dist/web/assets/DiagramEditor-NtNY3sZL-DqPXDJHY.js +2 -0
- package/dist/web/assets/DocumentEditor-zNIJgxe0.js +21 -0
- package/dist/web/assets/MergeView-Y3zB8V5p.js +10 -0
- package/dist/web/assets/{PlaygroundPage-w1D9fzsK.js → PlaygroundPage-DAaEm887.js} +1 -1
- package/dist/web/assets/SettingsPage-DhdiNEhO.js +1 -0
- package/dist/web/assets/{Toolbar-DylP9gFR.js → Toolbar-B36NxaTc.js} +1 -1
- package/dist/web/assets/{VisitorPickerModal-D0i7oxrW.js → VisitorPickerModal-drnOuPLP.js} +1 -1
- package/dist/web/assets/{copy-Ba87S6Rg.js → copy-CX8GOyUb.js} +1 -1
- package/dist/web/assets/diagram-3lhA7FYR.js +6257 -0
- package/dist/web/assets/index-DgM2rYI-.js +185 -0
- package/dist/web/assets/index-S_lCknAk.css +1 -0
- package/dist/web/assets/meta2d-D3b5RRN8.js +110 -0
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-BFAQue19.js → meta2dEngine-BD2XbzaV-CCgjRlVJ.js} +1 -1
- package/dist/web/assets/{motion-C4pN8CfU.js → motion-92iQWeIW.js} +1 -1
- package/dist/web/assets/{plus-BlTVBbk-.js → plus-BWV299MC.js} +1 -1
- package/dist/web/assets/react-BUhFwPCj.js +2382 -0
- package/dist/web/assets/react-vendor-BJFXgntS.js +242 -0
- package/dist/web/assets/{ui-DxdLi_28.js → ui-06fxEgif.js} +133 -133
- package/dist/web/index.html +5 -5
- package/package.json +2 -2
- package/dist/web/assets/AgentChatPanel-IrNTGpzN.js +0 -1
- package/dist/web/assets/DiagramEditor-BTRe45TX-D1vc5s9F.js +0 -2
- package/dist/web/assets/DocumentEditor-CbksWmYP.js +0 -21
- package/dist/web/assets/MergeView-CMQVyBUA.js +0 -22
- package/dist/web/assets/SettingsPage-DzTINzaB.js +0 -1
- package/dist/web/assets/diagram-gfUK8OHx.js +0 -3016
- package/dist/web/assets/index-7HUca950.css +0 -1
- package/dist/web/assets/index-DOrcbEeP.js +0 -185
- package/dist/web/assets/meta2d-C8Z4cn-d.js +0 -110
- package/dist/web/assets/react-DedaIFYc.js +0 -2126
- package/dist/web/assets/react-vendor-BNpqFP9B.js +0 -242
package/dist/web/index.html
CHANGED
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
opacity: 0.65;
|
|
28
28
|
}
|
|
29
29
|
</style>
|
|
30
|
-
<script type="module" crossorigin src="/assets/index-
|
|
31
|
-
<link rel="modulepreload" crossorigin href="/assets/react-vendor-
|
|
32
|
-
<link rel="modulepreload" crossorigin href="/assets/motion-
|
|
33
|
-
<link rel="modulepreload" crossorigin href="/assets/ui-
|
|
34
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
30
|
+
<script type="module" crossorigin src="/assets/index-DgM2rYI-.js"></script>
|
|
31
|
+
<link rel="modulepreload" crossorigin href="/assets/react-vendor-BJFXgntS.js">
|
|
32
|
+
<link rel="modulepreload" crossorigin href="/assets/motion-92iQWeIW.js">
|
|
33
|
+
<link rel="modulepreload" crossorigin href="/assets/ui-06fxEgif.js">
|
|
34
|
+
<link rel="stylesheet" crossorigin href="/assets/index-S_lCknAk.css">
|
|
35
35
|
</head>
|
|
36
36
|
<body>
|
|
37
37
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgbg/mdocs",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.24",
|
|
4
4
|
"description": "A Markdown knowledge base for small teams",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@earendil-works/pi-agent-core": "^0.82.1",
|
|
43
43
|
"@earendil-works/pi-ai": "^0.82.1",
|
|
44
44
|
"@lexical/rich-text": "0.42.0",
|
|
45
|
-
"@lobehub/editor": "npm:@fgbg/lobe-editor@1.0.0-fork.
|
|
45
|
+
"@lobehub/editor": "npm:@fgbg/lobe-editor@1.0.0-fork.20",
|
|
46
46
|
"@lobehub/ui": "^5.0.0",
|
|
47
47
|
"@node-rs/jieba": "^2.0.1",
|
|
48
48
|
"@shikijs/langs": "4.0.2",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as d,j as e}from"./react-vendor-BNpqFP9B.js";import{aa as Ae,ab as Ce,i as me,ac as _e,ad as qe,ae as Re,af as $e,ag as Ee,ah as De,ai as xe,aj as Me,ak as Fe,al as Te}from"./index-DOrcbEeP.js";import{H as ze,S as Pe,A as Be}from"./AgentSkillFormCard-goRzD94F.js";import{P as Le}from"./plus-BlTVBbk-.js";import{M as He,r as Ke}from"./ui-DxdLi_28.js";import{C as Oe,a as Ue}from"./copy-Ba87S6Rg.js";import"./motion-C4pN8CfU.js";function te(r){var n;return r==null||typeof r=="boolean"?"":typeof r=="string"||typeof r=="number"?String(r):Array.isArray(r)?r.map(te).join(""):typeof r=="object"&&"props"in r?te((n=r.props)==null?void 0:n.children):""}function We(r){const[n,c]=d.useState(!1),o=d.useRef(null),b=te(r.children).replace(/\n$/,"");d.useEffect(()=>()=>{o.current!=null&&window.clearTimeout(o.current)},[]);async function x(){if(b)try{await navigator.clipboard.writeText(b),c(!0),o.current!=null&&window.clearTimeout(o.current),o.current=window.setTimeout(()=>c(!1),1500)}catch{}}return e.jsxs("div",{className:"mdocs-agent-panel-md-pre-wrap",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy",onClick:()=>void x(),"aria-label":n?"已复制":"复制代码",title:n?"已复制":"复制",children:n?e.jsx(Oe,{size:14,"aria-hidden":!0}):e.jsx(Ue,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:r.children})]})}function pe(r){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(He,{remarkPlugins:[Ke],components:{pre:({children:n})=>e.jsx(We,{children:n})},children:r.children})})}const Ge=["如何发布文档?","草稿是什么?","如何创建域?"];function he(r,n){return n.map((c,o)=>{const b=c.skillNames&&c.skillNames.length>0?c.skillNames:c.skillIds&&c.skillIds.length>0?c.skillIds:void 0;return{id:`h-${r}-${o}-${c.role}`,role:c.role,content:c.content,skillNames:b}})}function Xe(r,n){const c=r.slice(),o=c[c.length-1];return(o==null?void 0:o.type)==="text"?c[c.length-1]={type:"text",text:o.text+n}:c.push({type:"text",text:n}),c}function Ye(r,n){const c=r.slice(),o=c[c.length-1];return(o==null?void 0:o.type)==="thinking"?c[c.length-1]={type:"thinking",text:o.text+n}:c.push({type:"thinking",text:n}),c}function fe(r){return r!=null&&r.length?r.filter(n=>n.type==="text").map(n=>n.text).join(""):""}function Je(r){return!!(r!=null&&r.some(n=>n.type==="thinking"&&n.text.length>0))}function Qe(r){const n=new Date(r);if(Number.isNaN(n.getTime()))return"";const c=new Date;return n.getFullYear()===c.getFullYear()&&n.getMonth()===c.getMonth()&&n.getDate()===c.getDate()?n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function ge(r){if(r>=1e3){const n=r/1e3;return`${n>=10?Math.round(n):Math.round(n*10)/10}K`}return String(r)}function Ve(r){const{block:n,onResolved:c}=r,[o,b]=d.useState(""),[x,R]=d.useState(!1),[$,C]=d.useState(1),E=d.useRef(!1),z=d.useRef(c);z.current=c;const I=n.status==="open",_=d.useRef(0);d.useEffect(()=>{if(!I)return;E.current=!1;const k=new Date(n.expiresAt).getTime(),q=Date.now(),w=Math.max(k-q,1);_.current=w,C(1);const g=()=>{const F=k-Date.now(),K=Math.max(0,Math.min(1,F/w));C(K),F<=0&&!E.current&&(E.current=!0,Fe(n.requestId).catch(()=>{}).finally(()=>{z.current(n.requestId,"","expired")}))};g();const P=window.setInterval(g,100);return()=>window.clearInterval(P)},[I,n.expiresAt,n.requestId]);async function S(k){const q=k.trim();if(!(!q||x||!I)){R(!0);try{await Te(n.requestId,q),c(n.requestId,q,"selected")}catch{c(n.requestId,q,"failed")}finally{R(!1)}}}async function u(){if(!(x||!I)){R(!0),E.current=!0;try{await xe(n.requestId),c(n.requestId,"","cancelled")}catch{c(n.requestId,"","failed")}finally{R(!1)}}}const H=Math.max(0,Math.ceil($*_.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(I?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:n.title}),I?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[H,"s"]}):null]}),I?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round($*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${$})`}})}):null,n.status==="selected"&&n.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",n.selected]}):null,n.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,n.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,n.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,I?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:n.options.map(k=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:x,onClick:()=>void S(k),children:k},k))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:o,disabled:x,placeholder:"或输入自己的内容…",onChange:k=>b(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),S(o))}}),e.jsx("button",{type:"button",disabled:x||!o.trim(),onClick:()=>void S(o),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:x,onClick:()=>void u(),children:"取消"})})]}):null]})}function Ze(r){const b=2*Math.PI*8.75,x=Math.min(100,Math.max(0,r.percent)),R=b*(1-x/100),$=x>=90?"danger":x>=70?"warn":"ok",C=`上下文 ${x}% · 已用 ${ge(r.used)} / ${ge(r.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+$,"data-tooltip":C,"aria-label":C,role:"img",tabIndex:0,children:e.jsxs("svg",{width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,children:[e.jsx("circle",{className:"mdocs-agent-panel-context-track",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5}),e.jsx("circle",{className:"mdocs-agent-panel-context-value",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:b,strokeDashoffset:R,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function es(r){var n;for(const c of r)if(!(c.role!=="assistant"||!((n=c.blocks)!=null&&n.length))){for(const o of c.blocks)if((o.type==="choice_card"||o.type==="skill_form_card")&&o.status==="open")return!0}return!1}const cs=d.forwardRef(function(n,c){const{open:o,onClose:b,visitorName:x,anchorStyle:R,onOpenDocument:$,onTreeChanged:C,onDocumentOverwritten:E,onOpenCoding:z}=n,I=((x==null?void 0:x.trim().charAt(0))||"我").toUpperCase(),[_,S]=d.useState(!1),[u,H]=d.useState(null),[k,q]=d.useState(null),[w,g]=d.useState([]),[P,F]=d.useState(null),[K,ye]=d.useState([]),[je,ne]=d.useState(!1),[O,U]=d.useState(""),[B,ae]=d.useState([]),[y,W]=d.useState(!1),[ie,D]=d.useState(null),[G,re]=d.useState(null),[X,T]=d.useState(!1),[M,le]=d.useState(!1),ke=d.useRef(null),Y=d.useRef(null),v=d.useRef(null),ce=d.useRef(0),L=d.useRef(!0),J=d.useRef(w);J.current=w;function oe(s){return ce.current+=1,`${s}-${ce.current}`}function Ne(s,m=48){return s.scrollHeight-s.scrollTop-s.clientHeight<=m}function A(){const s=Y.current;!s||!L.current||(s.scrollTop=s.scrollHeight)}function be(){const s=Y.current;s&&(L.current=Ne(s))}async function Se(){ne(!0);try{const s=await Re();ye(s.sessions),P||F(s.lastOpenedSessionId)}catch{}finally{ne(!1)}}async function Q(){try{const s=await qe();re(s)}catch{}}d.useEffect(()=>{var m;if(!o){S(!1),(m=v.current)==null||m.abort(),v.current=null,W(!1);return}let s=!1;return(async()=>{try{const a=await Ae();s||(H(a),q(null))}catch(a){s||(H(null),q(a instanceof Error?a.message:String(a)))}})(),Q(),()=>{s=!0}},[o]),d.useEffect(()=>{if(!o)return;let s=!1;return(async()=>{try{const m=await Ce();if(s)return;F(m.sessionId),g(a=>a.length>0?a:he(m.sessionId,m.messages))}catch{}})(),()=>{s=!0}},[o]),d.useEffect(()=>{!o||!_||Se()},[o,_]);function V(){if(!M){if(es(J.current)){T(!0);return}T(!1),b()}}async function we(){var a;if(M)return;le(!0);const s=J.current,m=[];for(const j of s)if(!(j.role!=="assistant"||!j.blocks))for(const p of j.blocks)p.type==="choice_card"&&p.status==="open"&&m.push(xe(p.requestId).catch(()=>{})),p.type==="skill_form_card"&&p.status==="open"&&m.push(Me(p.requestId).catch(()=>{}));await Promise.all(m),(a=v.current)==null||a.abort(),g(j=>j.map(p=>p.role!=="assistant"||!p.blocks?p:{...p,blocks:p.blocks.map(h=>h.type==="choice_card"&&h.status==="open"?{...h,status:"cancelled"}:h.type==="skill_form_card"&&h.status==="open"?{...h,status:"cancelled"}:h)})),T(!1),le(!1),b()}const Z=d.useRef(V);Z.current=V,d.useImperativeHandle(c,()=>({requestClose:()=>Z.current()}),[]),d.useEffect(()=>{if(!o){T(!1);return}const s=m=>{if(m.key==="Escape"){if(X){M||T(!1);return}if(_){S(!1);return}Z.current()}};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[o,_,X,M]);async function ee(s){var h;const m=s.trim();if(!m||y)return;if(!(u!=null&&u.enabled)){D((u==null?void 0:u.reason)==="missing_api_key"?"请先在设置 → AI 配置 DeepSeek API Key":(u==null?void 0:u.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(h=v.current)==null||h.abort();const a=new AbortController;v.current=a;const j={id:oe("u"),role:"user",content:m,skillNames:B.length>0?[...B]:void 0},p=oe("a");L.current=!0,g(N=>[...N,j,{id:p,role:"assistant",content:""}]),U(""),W(!0),D(null),S(!1),requestAnimationFrame(()=>A());try{let N=!1;await De(m,{skillNames:B.length>0?B:void 0,signal:a.signal,onEvent:i=>{i.type==="text_delta"?(g(f=>f.map(t=>{if(t.id!==p)return t;const l=Xe(t.blocks??[],i.text);return{...t,blocks:l,content:fe(l)}})),requestAnimationFrame(()=>A())):i.type==="thinking_delta"?(g(f=>f.map(t=>{if(t.id!==p)return t;const l=Ye(t.blocks??[],i.text);return{...t,blocks:l}})),requestAnimationFrame(()=>A())):i.type==="sources"?(g(f=>f.map(t=>{if(t.id!==p)return t;const l=(t.blocks??[]).slice(),se=l[l.length-1];return(se==null?void 0:se.type)==="sources"?l[l.length-1]={type:"sources",items:i.items}:l.push({type:"sources",items:i.items}),{...t,blocks:l}})),requestAnimationFrame(()=>A())):i.type==="document_table"?(g(f=>f.map(t=>{if(t.id!==p)return t;const l=[...t.blocks??[],{type:"document_table",title:i.title,rows:i.rows}];return{...t,blocks:l}})),requestAnimationFrame(()=>A())):i.type==="document_card"?(g(f=>f.map(t=>{if(t.id!==p)return t;const l=[...t.blocks??[],{type:"document_card",documentId:i.documentId,title:i.title,path:i.path,preview:i.preview}];return{...t,blocks:l}})),requestAnimationFrame(()=>A())):i.type==="tool_notice"?(g(f=>f.map(t=>{if(t.id!==p)return t;const l=[...t.blocks??[],{type:"tool_notice",toolName:i.toolName,text:i.text}];return{...t,blocks:l}})),requestAnimationFrame(()=>A())):i.type==="choice_card"?(g(f=>f.map(t=>{if(t.id!==p)return t;const l=[...t.blocks??[],{type:"choice_card",requestId:i.requestId,title:i.title,options:i.options,expiresAt:i.expiresAt,status:"open"}];return{...t,blocks:l}})),requestAnimationFrame(()=>A())):i.type==="choice_expired"?g(f=>f.map(t=>t.id!==p||!t.blocks?t:{...t,blocks:t.blocks.map(l=>l.type==="choice_card"&&l.requestId===i.requestId&&l.status==="open"?{...l,status:"expired"}:l)})):i.type==="skill_form_card"?(g(f=>f.map(t=>{if(t.id!==p)return t;const l=[...t.blocks??[],{type:"skill_form_card",requestId:i.requestId,mode:i.mode,title:i.title,currentName:i.currentName,initialName:i.initialName,initialDescription:i.initialDescription,initialBody:i.initialBody,expiresAt:i.expiresAt,status:"open"}];return{...t,blocks:l}})),requestAnimationFrame(()=>A())):i.type==="skill_form_expired"?g(f=>f.map(t=>t.id!==p||!t.blocks?t:{...t,blocks:t.blocks.map(l=>l.type==="skill_form_card"&&l.requestId===i.requestId&&l.status==="open"?{...l,status:"expired"}:l)})):i.type==="tree_changed"?C==null||C():i.type==="document_overwritten"?E==null||E({documentId:i.documentId,headCommitId:i.headCommitId}):i.type==="open_coding"?z==null||z({documentId:i.documentId,displayName:i.displayName}):i.type==="context_usage"?re({percent:i.percent,used:i.used,limit:i.limit}):i.type==="error"&&(N=!0,D(i.message))}}),!a.signal.aborted&&!N&&ae([])}catch(N){if(a.signal.aborted)return;D(N instanceof Error?N.message:String(N))}finally{v.current===a&&(v.current=null),W(!1)}}async function Ie(){var s;if(!y){(s=v.current)==null||s.abort(),D(null),S(!1),W(!1);try{const m=await $e();F(m.sessionId),g([]),U(""),L.current=!0,Q()}catch(m){D(m instanceof Error?m.message:String(m))}}}async function ve(s){var m;if(!y){if(s===P){S(!1);return}(m=v.current)==null||m.abort(),D(null);try{const a=await Ee(s);F(a.sessionId),g(he(a.sessionId,a.messages)),U(""),S(!1),L.current=!0,requestAnimationFrame(()=>A()),Q()}catch(a){D(a instanceof Error?a.message:String(a))}}}function de(s){!s||!$||$(s)}if(!o)return null;const ue=k??(u&&!u.enabled?u.reason==="missing_api_key"?"未配置 API Key:请打开设置 → AI":u.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:ke,className:"mdocs-agent-panel",role:"dialog","aria-label":"mdocs 智能助手",style:R,children:[e.jsxs("header",{className:"mdocs-agent-panel-header",children:[e.jsxs("div",{className:"mdocs-agent-panel-title",children:[e.jsx("img",{src:me,alt:"",className:"mdocs-agent-panel-title-logo"}),e.jsx("span",{children:"mdocs 智能助手"})]}),e.jsxs("div",{className:"mdocs-agent-panel-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:y,onClick:()=>void Ie(),children:e.jsx(Le,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(_?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>S(s=>!s),children:e.jsx(ze,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:V,children:e.jsx(_e,{size:16,strokeWidth:1.8})})]})]}),_?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:()=>S(!1),children:"返回对话"})]}),je?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):K.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):e.jsx("ul",{className:"mdocs-agent-panel-history-list",children:K.map(s=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(s.id===P?" active":""),disabled:y,onClick:()=>void ve(s.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:s.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:Qe(s.updatedAt)})]})},s.id))})]}):e.jsxs("div",{className:"mdocs-agent-panel-body",children:[e.jsx("div",{className:"mdocs-agent-panel-welcome",ref:Y,onScroll:be,children:w.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-hello",children:"你好,我是 mdocs 智能助手"}),e.jsx("p",{className:"mdocs-agent-panel-desc",children:"我能答疑、搜文档、整理结构,也能帮你写全文;需要精细改稿请点文档顶栏「帮写」。"}),ue?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:ue}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:Ge.map(s=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void ee(s),disabled:y||!(u!=null&&u.enabled),children:s},s))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:w.map(s=>{var m;return e.jsxs("div",{className:"mdocs-agent-panel-msg"+(s.role==="user"?" mdocs-agent-panel-msg-user":" mdocs-agent-panel-msg-assistant"),children:[s.role==="assistant"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-ai","aria-hidden":!0,children:e.jsx("img",{src:me,alt:""})}):null,e.jsxs("div",{className:"mdocs-agent-panel-msg-bubble",children:[s.role==="user"&&s.skillNames&&s.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",s.skillNames.length]}):null,s.role==="assistant"?s.blocks&&s.blocks.length>0?e.jsxs("div",{className:"mdocs-agent-panel-timeline",children:[s.blocks.map((a,j)=>{var p;return a.type==="thinking"?a.text?e.jsxs("details",{className:"mdocs-agent-panel-think-fold",open:y&&s.id===((p=w[w.length-1])==null?void 0:p.id),children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:a.text})]},`${s.id}-th-${j}`):null:a.type==="text"?a.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(pe,{children:a.text})},`${s.id}-t-${j}`):null:a.type==="sources"?a.items.length===0?null:e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:["已阅读 ",a.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:a.items.map(h=>e.jsx("li",{children:e.jsx("a",{href:h.url,target:"_blank",rel:"noreferrer",children:h.name})},h.id))})]})},`${s.id}-s-${j}`):a.type==="tool_notice"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:a.text})},`${s.id}-n-${j}`):a.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Ve,{block:a,onResolved:(h,N,i)=>{g(f=>f.map(t=>t.id!==s.id||!t.blocks?t:{...t,blocks:t.blocks.map(l=>l.type==="choice_card"&&l.requestId===h?{...l,status:i,selected:i==="selected"?N:l.selected}:l)}))}})},`${s.id}-ch-${j}`):a.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Pe,{block:a,onResolved:(h,N,i)=>{g(f=>f.map(t=>t.id!==s.id||!t.blocks?t:{...t,blocks:t.blocks.map(l=>l.type==="skill_form_card"&&l.requestId===h?{...l,status:N,submittedName:N==="submitted"?i:l.submittedName}:l)}))}})},`${s.id}-sf-${j}`):a.type==="document_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:h=>{h.preventDefault(),h.stopPropagation(),de(a.documentId)},children:["《",a.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"文档预览"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[a.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:a.path}):null,a.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:a.preview}):e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview muted",children:"(无正文预览)"})]})]})},`${s.id}-c-${j}`):e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[a.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:a.rows.length===0?"无结果":`${a.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:a.rows.length===0?e.jsx("p",{className:"mdocs-agent-panel-doc-table-empty",children:"无结果"}):e.jsxs("table",{className:"mdocs-agent-panel-doc-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"文章名字"}),e.jsx("th",{children:"文章内容"})]})}),e.jsx("tbody",{children:a.rows.map(h=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>de(h.documentId),children:h.title})}),e.jsx("td",{children:h.summary||"-"})]},h.documentId))})]})})]})},`${s.id}-d-${j}`)}),y&&s.id===((m=w[w.length-1])==null?void 0:m.id)&&!fe(s.blocks)&&!Je(s.blocks)?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null]}):s.content?e.jsx(pe,{children:s.content}):y?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null:s.content]}),s.role==="user"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-user","aria-hidden":!0,children:I}):null]},s.id)})})}),ie?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:ie}):null,e.jsx(Be,{selectedNames:B,onChange:ae,disabled:y||!(u!=null&&u.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap",children:[e.jsx("textarea",{className:"mdocs-agent-panel-input",rows:2,placeholder:u!=null&&u.enabled?"把你的问题告诉我…":"请先配置 API Key",value:O,disabled:y||!(u!=null&&u.enabled),onChange:s=>U(s.target.value),onKeyDown:s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),ee(O))}}),G?e.jsx(Ze,{percent:G.percent,used:G.used,limit:G.limit}):null,e.jsx("button",{type:"button",className:y?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:y?!1:!(u!=null&&u.enabled)||!O.trim(),onClick:()=>{var s;if(y){(s=v.current)==null||s.abort();return}ee(O)},title:y?"停止":"发送","aria-label":y?"停止":"发送",children:y?"■":"↑"})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),X?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{M||T(!1)},children:e.jsxs("div",{className:"mdocs-message-dialog mdocs-agent-close-confirm",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-agent-close-confirm-title",onClick:s=>s.stopPropagation(),children:[e.jsx("h3",{id:"mdocs-agent-close-confirm-title",className:"mdocs-message-dialog-title",children:"有待处理的倒计时"}),e.jsx("p",{className:"mdocs-message-dialog-body",children:"当前还有选择卡或 Skill 表单在倒计时。强制关闭会取消这些操作并退出助手;也可以继续等待完成后再关。"}),e.jsxs("div",{className:"mdocs-message-dialog-actions mdocs-agent-close-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",disabled:M,onClick:()=>T(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:M,onClick:()=>void we(),children:M?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{cs as AgentChatPanel};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{Q as M,S as F,T as A,U as W,V}from"./react-DedaIFYc.js";import{r as c,j as e}from"./react-vendor-BNpqFP9B.js";import{ensureMeta2dShapes as N,generateSvgFromMeta2d as q,generateSvgFromDiagram as I}from"./meta2dEngine-BD2XbzaV-BFAQue19.js";import{M as G}from"./meta2d-C8Z4cn-d.js";import"./editor-ONzd_YnO.js";import"./ui-DxdLi_28.js";import"./motion-C4pN8CfU.js";import"./diagram-gfUK8OHx.js";import"./index-DOrcbEeP.js";import"./plus-BlTVBbk-.js";import"./copy-Ba87S6Rg.js";let T=0;const D=new Set;function O(n){return D.add(n),()=>{D.delete(n)}}function P(){return T}function Q(){T++,D.forEach(n=>n())}function E(n){let t=null;try{const[a]=M();t=a}catch{}const l=t;if(!l)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore(O,P,P),{setLocale:c.useCallback(a=>{l.setLocale(a),Q()},[l]),t:c.useCallback((a,p)=>l.t(a,p),[l])}}const X={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 L(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function Y(){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
|
-
+ 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 z(n){return V(structuredClone(n))}function $(n){const t=new Map;for(const l of n){const a=t.get(l.group)??[];a.push(l),t.set(l.group,a)}return Array.from(t.entries())}function J({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 K({disabled:n,engineRef:t,item:l,t:a}){const p=()=>{const r=t.current;if(!(!r||n))try{r.canvas.addCaches=[z(l.pen)]}catch{}};return e.jsxs("div",{draggable:!n,onClick:r=>{r.stopPropagation(),p()},onDragStart:r=>{if(n){r.preventDefault();return}const g=JSON.stringify(z(l.pen));r.dataTransfer.setData("Meta2d",g),r.dataTransfer.setData("Text",g),r.dataTransfer.effectAllowed="copy"},onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),p())},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:`${a(L(l.key))||l.label} — drag or click to add`,children:[e.jsx(J,{name:String(l.pen.name??"rectangle")}),e.jsx("span",{style:{fontSize:11},children:a(L(l.key))||l.label})]})}function U({disabled:n,engineRef:t}){const{t:l}=E(),a=c.useMemo(()=>$(Y()),[]);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:l("meta2d.palette.title")}),e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:12},children:l("meta2d.palette.hint")}),a.map(([p,r])=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:6},children:l(X[p]||p)}),e.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"repeat(2, minmax(0, 1fr))"},children:r.map(g=>e.jsx(K,{disabled:n,engineRef:t,item:g,t:l},g.key))})]},p))]})}const H={borderLeft:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",touchAction:"pan-y",width:220},j={color:"#8c8c8c",fontSize:12,marginBottom:4},k={borderBottom:"1px solid #f0f0f0",padding:"10px 12px"},f={alignItems:"center",display:"flex",gap:6,marginBottom:6},m={background:"#fafafa",border:"1px solid #e5e5e5",borderRadius:4,fontSize:12,height:28,outline:"none",padding:"0 6px"},y={color:"#8c8c8c",fontSize:11,minWidth:22},C={background:"#fff",border:"1px solid #d9d9d9",borderRadius:4,cursor:"pointer",fontSize:11,minWidth:48,padding:"4px 8px"};function _({engine:n}){const{t}=E(),[l,a]=c.useState(null),[p,r]=c.useState(null),g=c.useRef({}),b=c.useCallback(o=>{if(!o||o.length!==1){a(null),r(null);return}const d=o[0];if((d.globalAlpha===null||d.globalAlpha===void 0)&&(d.globalAlpha=1),a(d),n)try{r(n.getPenRect(d))}catch{r(null)}},[n]),v=c.useCallback(()=>{a(null),r(null)},[]);if(c.useEffect(()=>{if(n)return n.on("active",b),n.on("inactive",v),()=>{n.off("active",b),n.off("inactive",v)}},[n,b,v]),!l||!n)return e.jsx("aside",{style:H,children:e.jsx("div",{style:{color:"#bbb",fontSize:12,padding:16,textAlign:"center"},children:t("meta2d.props.empty")})});const h=(o,d)=>{g.current[o]=d;const i={id:l.id};i[o]=d,o==="dash"&&(i.lineDash=[void 0,[5,5]][d]),n.setValue(i,{render:!0})},B=(o,d)=>{if(!p)return;const i={id:l.id};i[o]=d,n.setValue(i,{render:!0}),r(u=>u?{...u,[o]:d}:null)},w=o=>{o(n),n.render(!0)};return e.jsxs("aside",{style:H,children:[e.jsxs("div",{style:k,children:[e.jsx("div",{style:j,children:t("meta2d.props.text")}),e.jsx("div",{style:f,children:e.jsx("input",{onChange:o=>h("text",o.target.value),style:m,type:"text",value:l.text??""})})]}),e.jsxs("div",{style:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.appearance")}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.color")}),e.jsx("input",{onChange:o=>h("color",o.target.value),style:{...m,flex:1},type:"color",value:l.color||"#1f1f1f"})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.bg")}),e.jsx("input",{onChange:o=>h("background",o.target.value),style:{...m,flex:1},type:"color",value:l.background||"#ffffff"})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.dash")}),e.jsxs("select",{onChange:o=>h("dash",Number(o.target.value)),style:{...m,flex:1},value:String(l.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:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.radius")}),e.jsx("input",{max:1,min:0,onChange:o=>h("borderRadius",Number(o.target.value)),step:.01,style:{...m,flex:1},type:"range",value:String(l.borderRadius??0)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:l.borderRadius??0})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.alpha")}),e.jsx("input",{max:1,min:0,onChange:o=>h("globalAlpha",Number(o.target.value)),step:.01,style:{...m,flex:1},type:"range",value:String(l.globalAlpha??1)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:(l.globalAlpha??1).toFixed(2)})]})]}),e.jsxs("div",{style:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.position")}),[["X","x"],["Y","y"],["W","width"],["H","height"]].map(([o,d])=>e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:o}),e.jsx("input",{onChange:i=>B(d,Number(i.target.value)),style:{...m,flex:1},type:"number",value:p?p[d]:0})]},d))]}),e.jsxs("div",{style:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.textAlign")}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.h")}),e.jsxs("select",{onChange:o=>h("textAlign",o.target.value),style:{...m,flex:1},value:l.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:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.v")}),e.jsxs("select",{onChange:o=>h("textBaseline",o.target.value),style:{...m,flex:1},value:l.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:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.layer")}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[e.jsx("button",{onClick:()=>w(o=>o.top()),style:C,type:"button",children:t("meta2d.props.top")}),e.jsx("button",{onClick:()=>w(o=>o.up()),style:C,type:"button",children:t("meta2d.props.up")}),e.jsx("button",{onClick:()=>w(o=>o.down()),style:C,type:"button",children:t("meta2d.props.down")}),e.jsx("button",{onClick:()=>w(o=>o.bottom()),style:C,type:"button",children:t("meta2d.props.bottom")})]})]})]})}const R={background:"#fff",border:"1px solid #d9d9d9",borderRadius:6,cursor:"pointer",minWidth:68,padding:"6px 12px"},S={...R,fontSize:12,minWidth:52,padding:"4px 10px"};function Z(n){c.useEffect(()=>{const t=document.documentElement,l=document.body,a=t.style.overflow,p=l.style.overflow;return t.style.overflow="hidden",l.style.overflow="hidden",()=>{t.style.overflow=a,l.style.overflow=p}},[n])}function pe({diagram:n,onClose:t,onSave:l}){const{t:a}=E(),p=c.useRef(null),r=c.useRef(null),g=c.useRef(n),b=c.useRef(t),[v,h]=c.useState(null),[B,w]=c.useState(!1);Z(!0),c.useLayoutEffect(()=>{b.current=t}),c.useEffect(()=>{if(!p.current)return;N();const i=new G(p.current,{grid:!0,rule:!1});r.current=i,h(i);try{const x=g.current;x!=null&&x.trim()?i.open(JSON.parse(x)):i.open(F()),A(i.data()),i.render(!0)}catch{i.open(F()),A(i.data()),i.render(!0)}const u=x=>{x.key==="Escape"&&b.current()};return window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u);try{i.destroy()}catch{}r.current=null}},[]);const o=async()=>{const i=r.current;if(i){w(!0);try{A(i.data()),i.render(!0);const u=W(i.data()),x=JSON.stringify(u);l(x,await q(i)||await I(x)||'<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{w(!1)}}},d=i=>{const u=r.current;u&&i(u)};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:i=>i.stopPropagation(),onWheel:i=>i.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:a("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:()=>d(i=>i.undo()),style:S,title:`${a("meta2d.editor.undo")} (Ctrl+Z)`,type:"button",children:a("meta2d.editor.undo")}),e.jsx("button",{onClick:()=>d(i=>i.redo()),style:S,title:`${a("meta2d.editor.redo")} (Ctrl+Y)`,type:"button",children:a("meta2d.editor.redo")}),e.jsx("button",{onClick:()=>d(i=>i.delete()),style:S,title:a("meta2d.editor.delete"),type:"button",children:a("meta2d.editor.delete")}),e.jsx("button",{onClick:()=>d(i=>i.fitView(!0)),style:S,title:a("meta2d.editor.fit"),type:"button",children:a("meta2d.editor.fit")}),e.jsx("button",{onClick:()=>d(i=>{i.scale(1),i.centerView()}),style:S,title:a("meta2d.editor.zoom100"),type:"button",children:a("meta2d.editor.zoom100")})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:t,style:R,type:"button",children:a("meta2d.editor.close")}),e.jsx("button",{disabled:B,onClick:()=>void o(),style:{...R,background:"#1677ff",border:"none",color:"#fff"},type:"button",children:a(B?"meta2d.editor.saving":"meta2d.editor.save")})]})]})]}),e.jsxs("div",{style:{display:"flex",flex:1,minHeight:0,overflow:"hidden"},children:[e.jsx(U,{engineRef:r}),e.jsx("div",{ref:p,style:{flex:1,minHeight:0,minWidth:0}}),e.jsx(_,{engine:v})]})]})})}export{pe as DiagramEditor};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import{r as i,j as n}from"./react-vendor-BNpqFP9B.js";import{B as oe}from"./ui-DxdLi_28.js";import{c as J,g as he,u as ye,a as re,d as Ne,b as Re,f as De,e as Ae,h as Pe,D as Te,F as Le,l as ce,i as Be,S as _e,M as Oe,j as ze,r as pe,k as Fe,m as V,n as He,o as Ue,p as le}from"./index-DOrcbEeP.js";import{z as We,A as qe,m as Q,n as Ve,o as $e,p as Je,r as Ge,s as Ke,t as Xe,v as Ye,x as Qe,B as Ze,R as et,a as tt,b as de,c as nt,d as at,e as it,f as st,g as ot,h as rt,i as ct,w as Z,j as lt,O as dt,E as ut,q as mt,l as ft,C as ht,D as yt}from"./react-DedaIFYc.js";import{H as gt,a as xt,b as vt,M as bt,T as kt,S as It,W as St,N as Ct,o as wt,c as ue}from"./Toolbar-DylP9gFR.js";import{V as jt}from"./VisitorPickerModal-D0i7oxrW.js";import"./motion-C4pN8CfU.js";import"./editor-ONzd_YnO.js";import"./diagram-gfUK8OHx.js";import"./plus-BlTVBbk-.js";import"./copy-Ba87S6Rg.js";/**
|
|
2
|
-
* @license lucide-react v0.562.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const Mt=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],Et=J("refresh-cw",Mt);/**
|
|
7
|
-
* @license lucide-react v0.562.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const Nt=[["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"}]],Rt=J("shield-user",Nt);/**
|
|
12
|
-
* @license lucide-react v0.562.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const Dt=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],At=J("text-align-justify",Dt);/**
|
|
17
|
-
* @license lucide-react v0.562.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const Pt=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],Tt=J("users",Pt),Lt=48;function $(e){try{const a=e.getDocument("markdown");return typeof a=="string"?a:""}catch{return null}}function Bt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function _t({editor:e,documentId:a,displayName:o,debounceMs:g=1e3,enabled:m=!0,localBaseCommitIdAtEditStart:N,snapshotMeta:L}){const[G,P]=i.useState(!1),[R,I]=i.useState(!1),[B,w]=i.useState(null),u=i.useRef(null),f=i.useRef(null),x=i.useRef(!1),v=i.useRef(""),y=i.useRef(!1),S=i.useRef(a),F=i.useRef(o),H=i.useRef(N),_=i.useRef(L);S.current=a,F.current=o,H.current=N,_.current=L;const C=i.useCallback(async()=>{if(!e)return;if(!v.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const c=Bt(e);c!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",S.current,"content preview:",c.slice(0,80)),await he(S.current).execute(()=>ye({documentId:S.current,content:c,displayName:F.current,localBaseCommitIdAtEditStart:H.current,snapshotMeta:_.current})),v.current=$(e)??v.current,I(!0),P(!1),w(Date.now()),x.current=!0,y.current=!1)},[e]);i.useEffect(()=>{let c=!1;return re(a).then(l=>{c||(l?(I(!0),w(l.updatedAt),x.current=!0):(I(!1),w(null),x.current=!1,y.current=!1))}),()=>{c=!0}},[a]),i.useEffect(()=>{var W,q;if(!m){(W=f.current)==null||W.call(f),f.current=null;return}if(!e)return;const c=e.getLexicalEditor();if(!c)return;(q=f.current)==null||q.call(f);let l=!1,b=0,T=0;const O=()=>{if(l)return;const k=$(e);if(k===null){if(T+=1,T>Lt)return;b=requestAnimationFrame(O);return}v.current=k;const r=c.registerUpdateListener(()=>{const A=$(e);A!==null&&A!==v.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",a,"oldLen:",v.current.length,"newLen:",A.length),v.current=A,P(!0),y.current=!0,x.current=!1,u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null,C()},g))});f.current=()=>{r(),u.current&&(clearTimeout(u.current),u.current=null)}};return queueMicrotask(()=>{l||(b=requestAnimationFrame(O))}),()=>{var k;l=!0,cancelAnimationFrame(b),(k=f.current)==null||k.call(f)}},[m,e,a,o,g,N,L,C]),i.useEffect(()=>{var b;if(!m||!e)return;const c=(b=e.getLexicalEditor())==null?void 0:b.getRootElement();if(!c)return;const l=()=>{u.current&&(clearTimeout(u.current),u.current=null),y.current&&C()};return c.addEventListener("blur",l),()=>c.removeEventListener("blur",l)},[m,e,C]),i.useEffect(()=>{if(!m)return;const c=()=>{document.visibilityState==="hidden"&&(u.current&&(clearTimeout(u.current),u.current=null),y.current&&C())},l=()=>{y.current&&(u.current&&(clearTimeout(u.current),u.current=null),C())};return document.addEventListener("visibilitychange",c),window.addEventListener("beforeunload",l),()=>{document.removeEventListener("visibilitychange",c),window.removeEventListener("beforeunload",l)}},[m,C]);async function j(){await Ne(a),I(!1),P(!1),y.current=!1,x.current=!1,v.current=""}async function U(){const c=await re(a);return c?c.content:null}function D(){I(!0),P(!1),y.current=!1,w(Date.now()),x.current=!0,e&&(v.current=$(e)??"")}return{isDirty:G,draftExists:R,lastSavedAt:B,clearDraft:j,loadDraftContent:U,markDraftSaved:D}}function Ot({isDirty:e,draftExists:a}){const o=e&&!a;i.useEffect(()=>{if(!o)return;const g=m=>{m.preventDefault()};return window.addEventListener("beforeunload",g),()=>window.removeEventListener("beforeunload",g)},[o])}function ee(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const me='{"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 fe(e){const o=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(o)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(o)?"不支持的文件类型":/^not an image$/i.test(o)?"不是有效的图片文件":o||"上传失败"}function zt(e,a){if(!e)return a==="json"?me:e;if(a!=="json")return e;try{const o=JSON.parse(e);if(o!=null&&o.root&&Array.isArray(o.root.children)&&o.root.children.length===0)return me}catch{}return e}function pt({editor:e}){const{visible:a}=ht();return n.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:a?200:0},children:n.jsx("div",{style:{width:200},children:n.jsx(yt,{editor:e})})})}function Yt(e){const{t:a,lang:o}=Re(),[g,m]=i.useState(!1),N=i.useRef(null),[L,G]=i.useState([]),[P,R]=i.useState(!1),[I,B]=i.useState(e.meta.permission),[w,u]=i.useState(!1),[f,x]=i.useState(!1),[v,y]=i.useState(!1),[S,F]=i.useState(new Map),[H,_]=i.useState(!1);i.useEffect(()=>{const t=s=>{N.current&&!N.current.contains(s.target)&&m(!1)};return g&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[g]),i.useEffect(()=>{let t=!0;return De().then(s=>{t&&G(s)}).catch(()=>{}),()=>{t=!1}},[]);function C(t){const s=L.find(d=>d.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}const[j,U]=i.useState(e.initialDisplayName),[D,c]=i.useState(!1),[l,b]=i.useState(!1),[T,O]=i.useState(!1),[W,q]=i.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),k=e.canEdit&&W,[r,A]=i.useState(null),[ge,te]=i.useState(!1),K=i.useRef(null);i.useLayoutEffect(()=>{te(!1),A(null),K.current=null},[e.meta.documentId]),i.useEffect(()=>{const t=requestAnimationFrame(()=>te(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]);const M=i.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const s=JSON.parse(e.initialContent);return Array.isArray((t=s==null?void 0:s.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),z=i.useMemo(()=>zt(e.initialContent||"",M),[e.initialContent,M,e.contentRevision]),{isDirty:ne,draftExists:p,markDraftSaved:xe}=_t({editor:r,documentId:e.meta.documentId,displayName:j,enabled:e.canEdit,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}});i.useEffect(()=>{var t;(t=e.onDraftExistsChange)==null||t.call(e,p)},[p,e.onDraftExistsChange]),Ot({isDirty:ne,draftExists:p}),i.useEffect(()=>{if(r)try{r.setDocument(M,z)}catch{}},[r,e.meta.documentId,e.contentRevision,z,M]),i.useEffect(()=>{r==null||r.setLocale(o==="zh"?We:qe)},[r,o]),i.useEffect(()=>{U(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),i.useEffect(()=>{B(e.meta.permission)},[e.meta.permission,e.meta.documentId]),i.useEffect(()=>{let t=!0;return(async()=>{try{const s=await Ae(e.meta.documentId);t&&b(s.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function ae(){var t,s;if(!T){O(!0);try{l?(await pe(e.meta.documentId),b(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Fe(e.meta.documentId),b(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{O(!1)}}}i.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=je),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),i.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=K.current;if(!t)return"";try{const s=t.getDocument("markdown");return typeof s=="string"?s:String(s??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function ve(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const be=i.useCallback(t=>{K.current=t,A(t);const s=z;if(!s)return;const d=()=>{try{t.setDocument(M,s)}catch{requestAnimationFrame(()=>{try{t.setDocument(M,s)}catch{}})}};queueMicrotask(()=>{queueMicrotask(d)})},[M,z]);async function ie(){if(!(!r||!e.canEdit)){c(!0);try{const t=ee(r);if(!t)return;await e.onPublish(t,j,e.meta.documentId)}catch(t){throw t}finally{c(!1)}}}async function ke(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(j.trim()!==t)try{await ie()}catch{}}const E=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),Ie=i.useMemo(()=>{const t=(E==null?void 0:E.permission)??"public";return Pe(t)},[E==null?void 0:E.permission]);function Se(t){return t===V.PRIVATE?a("permissionPrivate"):t===V.DOMAIN_READ?a("permissionInvite"):t===V.DOMAIN_WRITE?a("permissionDomainWrite"):t===V.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function Ce(){var t;if(w||I===e.meta.permission){R(!1);return}u(!0);try{const d=(r?ee(r):null)??e.initialContent;await e.onPublish(d,j,e.meta.documentId,I),R(!1),(t=e.onShowToast)==null||t.call(e,a("docInfoPermissionUpdated"))}finally{u(!1)}}async function we(t){var s;if(!H){_(!0);try{const d=new Set(t.map(h=>h.visitorId)),X=new Map(t.map(h=>[h.visitorId,h.permission]));for(const[h]of S)d.has(h)||await He(e.meta.documentId,h);for(const{visitorId:h,permission:Y}of t){const se=S.get(h);(!se||se!==Y)&&await Ue(e.meta.documentId,h,Y)}x(!1),(s=e.onShowToast)==null||s.call(e,a("docInfoInviteSuccess",{count:t.length}))}finally{_(!1)}}}async function je(){if(!r||!e.canEdit)return;if(!ne){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=ee(r);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),xe(),await he(e.meta.documentId).execute(()=>ye({documentId:e.meta.documentId,content:t,displayName:j,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const Me=i.useMemo(()=>[{icon:gt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(Q,{tag:"h1"})}},{icon:xt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(Q,{tag:"h2"})}},{icon:vt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(Q,{tag:"h3"})}},{type:"divider"},{icon:bt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(Ve,{})}},{icon:kt,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand($e,{columns:"3",rows:"3"})}},{icon:It,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(Je,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{wt(s=>{for(const d of s)t.dispatchCommand(mt,{file:d})})}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(Ge,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(Ke,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(Xe,void 0),queueMicrotask(()=>t.focus())}},{icon:St,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(Ye,void 0),queueMicrotask(()=>t.focus())}},{icon:Ct,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(Qe,void 0),queueMicrotask(()=>t.focus())}}].map(t=>"type"in t&&t.type==="divider"?t:{...t,extra:n.jsx("span",{style:{color:"var(--mdocs-text-muted)",fontFamily:"monospace",fontSize:12},children:t.key})}),[]),Ee=i.useMemo(()=>[Ze,et,tt,de,nt,at,it,st,ot,rt,ct,Z(lt,{children:r?n.jsx(ue,{editor:r,floating:!0,outlineCollapseTitle:a("outlineHide"),outlineExpandTitle:a("outlineShow"),outlineToggle:!0}):null}),Z(ft,{handleUpload:async t=>{var s;try{return{url:await le(t,e.meta.documentId)}}catch(d){throw(s=e.onShowError)==null||s.call(e,fe(d)),d}}}),Z(de,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var s;try{const X=await(await fetch(t)).blob(),h=new File([X],"image.png",{type:X.type});return{url:await le(h,e.meta.documentId)}}catch(d){throw(s=e.onShowError)==null||s.call(e,fe(d)),d}}})],[r,a,e.meta.documentId,e.onShowError]);return n.jsxs("div",{className:"mdocs-editor",children:[n.jsxs("div",{className:"mdocs-editor-toolbar",children:[n.jsx("input",{className:"mdocs-editor-title-input",value:j,onChange:t=>U(t.target.value),onBlur:()=>void ke(),placeholder:a("displayNamePlaceholder"),disabled:!k}),n.jsx(Te,{domains:e.domains.length?e.domains:[Le],value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:t=>ce(t,o,a)}),e.onAiWrite?n.jsxs("button",{type:"button",className:"secondary",onClick:()=>{var t;return(t=e.onAiWrite)==null?void 0:t.call(e)},style:{padding:"4px 10px",whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",gap:6},children:[n.jsx("img",{src:Be,alt:"",width:16,height:16,style:{display:"block"}}),"帮写"]}):null,n.jsxs("button",{type:"button",className:"secondary mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>void ae(),disabled:T,"data-tooltip":l?"取消收藏":"收藏",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,opacity:T?.5:1},children:[n.jsx(_e,{size:18,strokeWidth:1.5,style:{color:l?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:l?"#faad14":"none"}}),l&&n.jsx("span",{children:"已收藏"})]}),n.jsx("span",{className:"mdocs-editor-toolbar-spacer","aria-hidden":!0}),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(Et,{size:16,strokeWidth:1.5}),n.jsx("span",{children:a("syncPull")})]}),k?n.jsxs(n.Fragment,{children:[localStorage.getItem("mdocs.autoPublish")!=="true"&&n.jsxs("span",{className:"mdocs-save-indicator",children:[n.jsx("span",{className:"mdocs-save-dot "+(D?"saving":p?"unsaved":"saved")}),n.jsx("span",{children:a(D?"publishing":p?"unsaved":"published")})]}),n.jsx("button",{type:"button",className:"primary",disabled:D,onClick:()=>{ie().catch(()=>{})},children:a(D?"publishing":"publish")}),n.jsx("button",{type:"button",className:"danger",disabled:D,onClick:e.onDelete,children:a("delete")})]}):e.canEdit&&n.jsx("button",{type:"button",className:"primary",onClick:()=>q(!0),children:a("edit")}),n.jsxs("button",{type:"button",className:"secondary mdocs-tooltip mdocs-tooltip-bottom",onClick:e.onToggleComments,"data-tooltip":"评论",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:e.commentPanelOpen?"var(--mdocs-hover-bg, #f0f0f0)":void 0},children:[n.jsx(Oe,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}}),e.commentCount>0&&n.jsx("span",{style:{fontSize:"0.85rem"},children:e.commentCount})]}),n.jsxs("div",{ref:N,className:"mdocs-tooltip mdocs-tooltip-bottom","data-tooltip":a("docInfo"),style:{position:"relative"},children:[n.jsx("button",{type:"button",className:"secondary",onClick:()=>m(!g),style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx(At,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}})}),g&&n.jsxs("div",{style:{position:"absolute",top:"100%",right:0,marginTop:"4px",background:"var(--mdocs-surface, #fff)",border:"1px solid var(--mdocs-border, #e5e5e5)",borderRadius:"8px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)",minWidth:"220px",zIndex:100,padding:"8px 0"},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:C(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(o==="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:ve(new Blob([e.initialContent]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(o==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),n.jsxs("button",{type:"button",style:{width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:t=>{t.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:t=>{t.currentTarget.style.background="none"},onClick:()=>{ae()},children:[n.jsx("span",{children:l?"⭐":"☆"}),n.jsx("span",{children:a(l?"bookmarkRemove":"bookmarkAdd")})]}),e.canManageInvites&&n.jsxs("button",{type:"button",style:{width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:t=>{t.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:t=>{t.currentTarget.style.background="none"},onClick:()=>{m(!1),(async()=>{y(!0);try{const t=await ze(e.meta.documentId),s=new Map(t.map(d=>[d.visitorId,d.permission]));F(s),x(!0)}finally{y(!1)}})()},children:[n.jsx(Tt,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}),n.jsxs("button",{type:"button",style:{width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:t=>{t.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:t=>{t.currentTarget.style.background="none"},onClick:()=>{m(!1),B(e.meta.permission),R(!0)},children:[n.jsx(Rt,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})]})]})]}),P&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&R(!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"),":",E?ce(E.domainName,o,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:Ie.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"doc-permission",value:t,checked:I===t,onChange:()=>B(t)}),n.jsx("span",{children:Se(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>R(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:w,onClick:()=>void Ce(),children:a(w?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(jt,{open:f,title:a("docInfoInviteMember"),initialSelectedIds:[...S.keys()],initialPermissions:S,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>x(!1),onConfirm:t=>{we(t)}}),n.jsx(dt,{children:n.jsx(oe,{flex:1,style:{minHeight:0},children:n.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[k&&r&&n.jsx(ue,{editor:r,outlineCollapseTitle:a("outlineHide"),outlineExpandTitle:a("outlineShow"),outlineToggle:!0}),n.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:n.jsxs(oe,{variant:"outlined",horizontal:!0,style:{background:"var(--mdocs-surface)",flex:1,minHeight:0,minWidth:0,borderRadius:0,outline:"none"},children:[n.jsx("div",{className:"mdocs-editor-scroll-host",children:ge?n.jsx(ut,{content:z,type:M,confirmPasteMarkdown:!0,editable:k,onInit:be,plugins:Ee,lineEmptyPlaceholder:a("displayNamePlaceholder"),placeholder:a("displayNamePlaceholder"),slashOption:{items:Me},className:"mdocs-document-editor-root"},e.meta.documentId):null}),r&&n.jsx(pt,{editor:r})]})})]})})})]})}export{Yt as DocumentEditor};
|