@fgbg/mdocs 1.3.22 → 1.3.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 +13 -0
- package/agent-skills/getting-started-installation/SKILL.md +8 -2
- package/dist/server/agent/Agent/run-pi-agent.js +7 -0
- package/dist/server/agent/Agent/run-pi-agent.js.map +1 -1
- package/dist/server/agent/Agent/session-manager.js +354 -144
- package/dist/server/agent/Agent/session-manager.js.map +1 -1
- package/dist/server/agent/Agent/session-manager.queue.test.js +65 -0
- package/dist/server/agent/Agent/session-manager.queue.test.js.map +1 -0
- package/dist/server/agent/Agent/session-meta-lock.js +73 -0
- package/dist/server/agent/Agent/session-meta-lock.js.map +1 -0
- package/dist/server/agent/Agent/session-meta-lock.test.js +44 -0
- package/dist/server/agent/Agent/session-meta-lock.test.js.map +1 -0
- package/dist/server/agent/Agent/session-repair.test.js +40 -0
- package/dist/server/agent/Agent/session-repair.test.js.map +1 -0
- package/dist/server/agent/Agent/system-prompt.js +3 -3
- package/dist/server/agent/Agent/tool-ui-effects.js +41 -0
- package/dist/server/agent/Agent/tool-ui-effects.js.map +1 -1
- package/dist/server/agent/Agent/tools-documents.js +62 -12
- package/dist/server/agent/Agent/tools-documents.js.map +1 -1
- package/dist/server/agent/Agent/tools-overwrite.js +1 -1
- package/dist/server/agent/Agent/tools-overwrite.js.map +1 -1
- package/dist/server/agent/Agent/tools-registry.test.js +16 -0
- package/dist/server/agent/Agent/tools-registry.test.js.map +1 -1
- package/dist/server/agent/Agent/tools-sheet.js +918 -0
- package/dist/server/agent/Agent/tools-sheet.js.map +1 -0
- package/dist/server/agent/Agent/tools-sheet.test.js +202 -0
- package/dist/server/agent/Agent/tools-sheet.test.js.map +1 -0
- package/dist/server/agent/Agent/tools-template.js +4 -1
- package/dist/server/agent/Agent/tools-template.js.map +1 -1
- package/dist/server/cli/main.js +81 -4
- package/dist/server/cli/main.js.map +1 -1
- package/dist/server/cli/self-update.js +49 -20
- package/dist/server/cli/self-update.js.map +1 -1
- package/dist/server/cli/self-update.test.js +21 -2
- package/dist/server/cli/self-update.test.js.map +1 -1
- package/dist/server/config/index.js +2 -1
- package/dist/server/config/index.js.map +1 -1
- package/dist/server/documents/document.service.integration.test.js +67 -1
- package/dist/server/documents/document.service.integration.test.js.map +1 -1
- package/dist/server/documents/document.service.js +80 -5
- package/dist/server/documents/document.service.js.map +1 -1
- package/dist/server/main.js +6 -0
- package/dist/server/main.js.map +1 -1
- package/dist/server/routes/documents.routes.js +6 -2
- package/dist/server/routes/documents.routes.js.map +1 -1
- package/dist/server/search/embedding-model.js +33 -11
- package/dist/server/search/embedding-model.js.map +1 -1
- package/dist/shared/docPath.js +5 -2
- package/dist/shared/docPath.js.map +1 -1
- package/dist/shared/file-type-policy.js +15 -0
- package/dist/shared/file-type-policy.js.map +1 -1
- package/dist/shared/file-type-policy.test.js +17 -1
- package/dist/shared/file-type-policy.test.js.map +1 -1
- package/dist/shared/file-types.js +2 -0
- package/dist/shared/file-types.js.map +1 -1
- package/dist/shared/sheetDocument.js +781 -0
- package/dist/shared/sheetDocument.js.map +1 -0
- package/dist/shared/sheetDocument.test.js +179 -0
- package/dist/shared/sheetDocument.test.js.map +1 -0
- package/dist/shared/storagePath.js +15 -8
- package/dist/shared/storagePath.js.map +1 -1
- package/dist/web/assets/AgentChatPanel-NcsMAhWM.js +22 -0
- package/dist/web/assets/{AgentSkillFormCard-CzJG8FK4.js → AgentSkillFormCard-B99CncJO.js} +3 -3
- package/dist/web/assets/{AiWriteWorkbench-DiSDDAee.js → AiWriteWorkbench-DomEbwzU.js} +6 -6
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-DfkpQX3P.js → DiagramEditor-NtNY3sZL-BhsjOCtK.js} +1 -1
- package/dist/web/assets/DocChrome-wfHrPEB7.js +11 -0
- package/dist/web/assets/DocumentEditor-CCuqHlmF.js +1 -0
- package/dist/web/assets/HtmlEditor-g2NNYmv2.js +1 -0
- package/dist/web/assets/{MergeView-CbFSN3Bi.js → MergeView-GL7xdFM4.js} +4 -4
- package/dist/web/assets/PlaygroundPage-Bb4X1bvp.js +8 -0
- package/dist/web/assets/SettingsPage-B4INgMK-.js +1 -0
- package/dist/web/assets/SheetEditor-Cka57s62.js +16 -0
- package/dist/web/assets/SheetEditor-gXD-sRv2.css +1 -0
- package/dist/web/assets/{Toolbar-D9FcRwg3.js → Toolbar-Bk3LKZfg.js} +19 -29
- package/dist/web/assets/VisitorPickerModal-zafJ6beK.js +1 -0
- package/dist/web/assets/{check-Bf8YbzH7.js → check-BMeXlsHC.js} +1 -1
- package/dist/web/assets/{copy-SBghRY2T.js → copy-CCsiKd_j.js} +1 -1
- package/dist/web/assets/{diagram-CgEd0hrk.js → diagram-BF8g9yg4.js} +3 -3
- package/dist/web/assets/docPlainCharCount-BjBZaoHy.js +11 -0
- package/dist/web/assets/{editor-CL03se2B.js → editor-DBWWidi3.js} +1 -1
- package/dist/web/assets/file-type-policy-C6Nun42Q.js +1 -0
- package/dist/web/assets/index-3B7_9QOQ.js +299 -0
- package/dist/web/assets/index-BF754bDB.css +1 -0
- package/dist/web/assets/italic-B6bGjo1_.js +11 -0
- package/dist/web/assets/{meta2d-1-g23JOU.js → meta2d-DP4Vt_ZE.js} +1 -1
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-ulfRZEvk.js → meta2dEngine-BD2XbzaV-9HAADQ7Y.js} +1 -1
- package/dist/web/assets/{motion-Dyy8pB0Q.js → motion-BAXVQJfN.js} +1 -1
- package/dist/web/assets/{plus-CEapsZwl.js → plus-BD44y7Zf.js} +1 -1
- package/dist/web/assets/{react-BkX5Koku.js → react-2y9P8xJn.js} +171 -168
- package/dist/web/assets/{react-vendor-BuABiQkA.js → react-vendor-BVS1XoFi.js} +1 -1
- package/dist/web/assets/{ui-ZPt_BNBg.js → ui-CEFkTVnG.js} +200 -181
- package/dist/web/index.html +6 -6
- package/package.json +30 -21
- package/dist/web/assets/AgentChatPanel-BZlAgyrV.js +0 -22
- package/dist/web/assets/DocChrome-QTGER_Af.js +0 -21
- package/dist/web/assets/DocumentEditor-DYSRZnJa.js +0 -1
- package/dist/web/assets/HtmlEditor-oDPrhq3o.js +0 -1
- package/dist/web/assets/PlaygroundPage-DuMH_V-7.js +0 -8
- package/dist/web/assets/SettingsPage-C_RMO-5M.js +0 -1
- package/dist/web/assets/VisitorPickerModal-CM13Y6jQ.js +0 -1
- package/dist/web/assets/file-type-policy-GUk904tm.js +0 -1
- package/dist/web/assets/index-CIgmAX2Q.css +0 -1
- package/dist/web/assets/index-Cwy87sZC.js +0 -293
package/dist/web/index.html
CHANGED
|
@@ -27,12 +27,12 @@
|
|
|
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="modulepreload" crossorigin href="/assets/diagram-
|
|
35
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
30
|
+
<script type="module" crossorigin src="/assets/index-3B7_9QOQ.js"></script>
|
|
31
|
+
<link rel="modulepreload" crossorigin href="/assets/react-vendor-BVS1XoFi.js">
|
|
32
|
+
<link rel="modulepreload" crossorigin href="/assets/motion-BAXVQJfN.js">
|
|
33
|
+
<link rel="modulepreload" crossorigin href="/assets/ui-CEFkTVnG.js">
|
|
34
|
+
<link rel="modulepreload" crossorigin href="/assets/diagram-BF8g9yg4.js">
|
|
35
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BF754bDB.css">
|
|
36
36
|
</head>
|
|
37
37
|
<body>
|
|
38
38
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgbg/mdocs",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.24",
|
|
4
4
|
"description": "A Markdown knowledge base for small teams",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,6 +14,25 @@
|
|
|
14
14
|
"README.md",
|
|
15
15
|
"LICENSE"
|
|
16
16
|
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"skills:build": "node ./scripts/build-agent-skills.mjs",
|
|
19
|
+
"predev": "pnpm skills:build",
|
|
20
|
+
"prepack": "pnpm skills:build && pnpm build",
|
|
21
|
+
"dev:server": "tsx watch src/server/main.ts",
|
|
22
|
+
"dev:web": "vite",
|
|
23
|
+
"dev:web:fresh": "vite --force",
|
|
24
|
+
"dev": "pnpm dev:server & pnpm dev:web",
|
|
25
|
+
"dev:demo": "VITE_DEMO_MODE=true vite",
|
|
26
|
+
"build:web": "vite build",
|
|
27
|
+
"build:gh-pages": "VITE_DEMO_MODE=true VITE_BASE_PATH=/mdocs/ vite build",
|
|
28
|
+
"build:server": "tsc -p tsconfig.server.json",
|
|
29
|
+
"build": "pnpm build:web && pnpm build:server",
|
|
30
|
+
"start": "node dist/server/main.js",
|
|
31
|
+
"mdocs": "tsx src/server/cli/main.ts",
|
|
32
|
+
"typecheck": "tsc -p tsconfig.server.json --noEmit && tsc -p tsconfig.web.json --noEmit",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest"
|
|
35
|
+
},
|
|
17
36
|
"dependencies": {
|
|
18
37
|
"@codemirror/commands": "^6.10.3",
|
|
19
38
|
"@codemirror/language": "^6.12.3",
|
|
@@ -23,7 +42,7 @@
|
|
|
23
42
|
"@earendil-works/pi-agent-core": "^0.82.1",
|
|
24
43
|
"@earendil-works/pi-ai": "^0.82.1",
|
|
25
44
|
"@lexical/rich-text": "0.42.0",
|
|
26
|
-
"@lobehub/editor": "npm:@fgbg/lobe-editor@1.0.0-fork.
|
|
45
|
+
"@lobehub/editor": "npm:@fgbg/lobe-editor@1.0.0-fork.22",
|
|
27
46
|
"@lobehub/ui": "^5.0.0",
|
|
28
47
|
"@node-rs/jieba": "^2.0.1",
|
|
29
48
|
"@shikijs/langs": "4.0.2",
|
|
@@ -51,6 +70,14 @@
|
|
|
51
70
|
"remark-math": "^6.0.0",
|
|
52
71
|
"zod": "^3.23.8"
|
|
53
72
|
},
|
|
73
|
+
"pnpm": {
|
|
74
|
+
"onlyBuiltDependencies": [
|
|
75
|
+
"@fgbg/lobe-editor",
|
|
76
|
+
"better-sqlite3",
|
|
77
|
+
"esbuild",
|
|
78
|
+
"node-llama-cpp"
|
|
79
|
+
]
|
|
80
|
+
},
|
|
54
81
|
"devDependencies": {
|
|
55
82
|
"@types/better-sqlite3": "^7.6.11",
|
|
56
83
|
"@types/compression": "^1.8.1",
|
|
@@ -69,23 +96,5 @@
|
|
|
69
96
|
"typescript": "^5.6.2",
|
|
70
97
|
"vite": "^5.4.8",
|
|
71
98
|
"vitest": "2.1.9"
|
|
72
|
-
},
|
|
73
|
-
"scripts": {
|
|
74
|
-
"skills:build": "node ./scripts/build-agent-skills.mjs",
|
|
75
|
-
"predev": "pnpm skills:build",
|
|
76
|
-
"dev:server": "tsx watch src/server/main.ts",
|
|
77
|
-
"dev:web": "vite",
|
|
78
|
-
"dev:web:fresh": "vite --force",
|
|
79
|
-
"dev": "pnpm dev:server & pnpm dev:web",
|
|
80
|
-
"dev:demo": "VITE_DEMO_MODE=true vite",
|
|
81
|
-
"build:web": "vite build",
|
|
82
|
-
"build:gh-pages": "VITE_DEMO_MODE=true VITE_BASE_PATH=/mdocs/ vite build",
|
|
83
|
-
"build:server": "tsc -p tsconfig.server.json",
|
|
84
|
-
"build": "pnpm build:web && pnpm build:server",
|
|
85
|
-
"start": "node dist/server/main.js",
|
|
86
|
-
"mdocs": "tsx src/server/cli/main.ts",
|
|
87
|
-
"typecheck": "tsc -p tsconfig.server.json --noEmit && tsc -p tsconfig.web.json --noEmit",
|
|
88
|
-
"test": "vitest run",
|
|
89
|
-
"test:watch": "vitest"
|
|
90
99
|
}
|
|
91
|
-
}
|
|
100
|
+
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diagram-CgEd0hrk.js","assets/ui-ZPt_BNBg.js","assets/react-vendor-BuABiQkA.js","assets/motion-Dyy8pB0Q.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as i,j as e,_ as ct,b as dt}from"./react-vendor-BuABiQkA.js";import{o as ae,N as Ke,C as ut,aq as Xe,Y as ne,ar as qe,as as mt,q as Fe,at as Pe,au as pt,av as ft,aw as ht,ax as gt,ay as xt,az as yt,aA as Ue,aB as jt,aC as kt,aD as Nt}from"./index-Cwy87sZC.js";import{H as bt,S as vt,A as wt,a as Ct}from"./AgentSkillFormCard-CzJG8FK4.js";import{C as Ye}from"./check-Bf8YbzH7.js";import{C as Ge}from"./copy-SBghRY2T.js";import{P as St}from"./plus-CEapsZwl.js";import{an as At,ao as _t}from"./ui-ZPt_BNBg.js";import"./diagram-CgEd0hrk.js";import"./motion-Dyy8pB0Q.js";/**
|
|
3
|
-
* @license lucide-react v0.562.0 - ISC
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the ISC license.
|
|
6
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/const It=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],Mt=ae("maximize-2",It);/**
|
|
8
|
-
* @license lucide-react v0.562.0 - ISC
|
|
9
|
-
*
|
|
10
|
-
* This source code is licensed under the ISC license.
|
|
11
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
12
|
-
*/const Et=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],Rt=ae("minimize-2",Et);/**
|
|
13
|
-
* @license lucide-react v0.562.0 - ISC
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the ISC license.
|
|
16
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/const $t=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Tt=ae("zoom-in",$t);/**
|
|
18
|
-
* @license lucide-react v0.562.0 - ISC
|
|
19
|
-
*
|
|
20
|
-
* This source code is licensed under the ISC license.
|
|
21
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
22
|
-
*/const zt=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Dt=ae("zoom-out",zt);function je(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(je).join(""):typeof s=="object"&&"props"in s?je((n=s.props)==null?void 0:n.children):""}function qt(s){return s?/\blanguage-mermaid\b|\bmermaid\b/i.test(s):!1}function Ft(s){const n=Array.isArray(s)?s:[s];for(const a of n){if(a==null||typeof a!="object"||!("props"in a))continue;const c=a.props;if(!(!c||!qt(c.className)))return je(c.children).replace(/\n$/,"")}return null}const Pt=.4,Bt=4,se=.2;let xe=null;function Lt(){return xe||(xe=ct(()=>import("./diagram-CgEd0hrk.js").then(s=>s.z),__vite__mapDeps([0,1,2,3])).then(s=>{const n=s.default;return n.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral",fontFamily:"ui-sans-serif, system-ui, sans-serif"}),n})),xe}const Ot=32,W=new Map;function Be(s){return W.get(s)??null}function Wt(s,n){for(W.has(s)&&W.delete(s),W.set(s,n);W.size>Ot;){const a=W.keys().next().value;if(a==null)break;W.delete(a)}}function ye(s){return Math.min(Bt,Math.max(Pt,s))}function Ht(s){const[n,a]=i.useState(1),[c,b]=i.useState({x:0,y:0}),h=i.useRef(null),[A,y]=i.useState(!1);i.useEffect(()=>{const u=I=>{I.key==="Escape"&&s.onClose()};window.addEventListener("keydown",u);const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",u),document.body.style.overflow=m}},[s.onClose]);function _(u){u.button===0&&(u.currentTarget.setPointerCapture(u.pointerId),h.current={pointerId:u.pointerId,startX:u.clientX,startY:u.clientY,originX:c.x,originY:c.y},y(!0))}function C(u){const m=h.current;!m||m.pointerId!==u.pointerId||b({x:m.originX+(u.clientX-m.startX),y:m.originY+(u.clientY-m.startY)})}function E(u){const m=h.current;if(!(!m||m.pointerId!==u.pointerId)){h.current=null,y(!1);try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}}}function N(u){u.preventDefault();const m=u.deltaY>0?-se:se;a(I=>ye(Number((I+m).toFixed(2))))}return dt.createPortal(e.jsxs("div",{className:"mdocs-agent-mermaid-float",role:"dialog","aria-modal":"true","aria-label":"Mermaid 图预览",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-backdrop","aria-label":"关闭预览",onClick:s.onClose}),e.jsxs("div",{className:"mdocs-agent-mermaid-float-chrome",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-float-tools",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>a(u=>ye(Number((u-se).toFixed(2)))),title:"缩小","aria-label":"缩小",children:e.jsx(Dt,{size:16,"aria-hidden":!0})}),e.jsxs("span",{className:"mdocs-agent-mermaid-float-scale",children:[Math.round(n*100),"%"]}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>a(u=>ye(Number((u+se).toFixed(2)))),title:"放大","aria-label":"放大",children:e.jsx(Tt,{size:16,"aria-hidden":!0})}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>{a(1),b({x:0,y:0})},title:"重置",children:"重置"}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:s.onClose,title:"关闭","aria-label":"关闭",children:e.jsx(ne,{size:16,"aria-hidden":!0})})]}),e.jsx("div",{className:A?"mdocs-agent-mermaid-float-stage is-dragging":"mdocs-agent-mermaid-float-stage",onPointerDown:_,onPointerMove:C,onPointerUp:E,onPointerCancel:E,onWheel:N,children:e.jsx("div",{className:"mdocs-agent-mermaid-float-canvas",style:{transform:`translate(calc(-50% + ${c.x}px), calc(-50% + ${c.y}px)) scale(${n})`},dangerouslySetInnerHTML:{__html:s.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function Kt(s){const n=i.useId().replace(/:/g,""),[a,c]=i.useState("diagram"),[b,h]=i.useState(()=>Be(s.source.trim())),[A,y]=i.useState(null),[_,C]=i.useState(!1),[E,N]=i.useState(!1),u=i.useRef(null),m=s.source.trim(),I=i.useMemo(()=>m,[m]);i.useEffect(()=>()=>{u.current!=null&&window.clearTimeout(u.current)},[]),i.useEffect(()=>{if(a!=="diagram")return;if(!I){h(null),y(null);return}const j=Be(I);if(j){h(j),y(null);return}let M=!1;const P=window.setTimeout(()=>{(async()=>{try{const F=await Lt();if(M)return;const T=`mdocs-agent-mmd-${n}-${Date.now()}`,{svg:R}=await F.render(T,I);if(M)return;Wt(I,R),h(R),y(null)}catch(F){if(M)return;h(null),y(F instanceof Error?F.message:"Mermaid 渲染失败")}})()},200);return()=>{M=!0,window.clearTimeout(P)}},[a,I,n]);async function H(){!m||!await Xe(m)||(C(!0),u.current!=null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>C(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-mermaid",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toolbar",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toggle",role:"group","aria-label":"Mermaid 显示模式",children:[e.jsxs("button",{type:"button",className:a==="diagram"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("diagram"),"aria-pressed":a==="diagram",title:"图谱",children:[e.jsx(Ke,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"图谱"})]}),e.jsxs("button",{type:"button",className:a==="code"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("code"),"aria-pressed":a==="code",title:"代码",children:[e.jsx(ut,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"代码"})]})]}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy mdocs-agent-mermaid-copy",onClick:()=>void H(),"aria-label":_?"已复制":"复制代码",title:_?"已复制":"复制",children:_?e.jsx(Ye,{size:14,"aria-hidden":!0}):e.jsx(Ge,{size:14,"aria-hidden":!0})})]}),a==="diagram"?e.jsx("div",{className:"mdocs-agent-mermaid-diagram",children:A?e.jsxs("div",{className:"mdocs-agent-mermaid-error",role:"alert",children:[e.jsx("p",{children:"无法渲染该图,可切换到代码查看源码。"}),e.jsx("pre",{children:A})]}):b?e.jsx("div",{className:"mdocs-agent-mermaid-svg mdocs-agent-mermaid-svg-hit",role:"button",tabIndex:0,onClick:()=>N(!0),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),N(!0))},title:"点击放大预览","aria-label":"点击放大预览 Mermaid 图",children:e.jsx("span",{className:"mdocs-agent-mermaid-svg-inner",dangerouslySetInnerHTML:{__html:b}})}):e.jsx("div",{className:"mdocs-agent-mermaid-loading",children:"渲染中…"})}):e.jsx("div",{className:"mdocs-agent-panel-md-pre-wrap mdocs-agent-mermaid-code",children:e.jsx("pre",{children:s.codeChildren??e.jsx("code",{className:"language-mermaid",children:m})})}),E&&b?e.jsx(Ht,{svg:b,onClose:()=>N(!1)}):null]})}const Xt=i.memo(Kt,(s,n)=>s.source===n.source);function ke(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(ke).join(""):typeof s=="object"&&"props"in s?ke((n=s.props)==null?void 0:n.children):""}function Ut(s){const[n,a]=i.useState(!1),c=i.useRef(null),b=i.useRef(null),h=ke(s.children).replace(/\n$/,"");i.useEffect(()=>()=>{c.current!=null&&window.clearTimeout(c.current)},[]);async function A(y){var N,u,m;y.preventDefault(),y.stopPropagation();const C=(((m=(u=(N=b.current)==null?void 0:N.querySelector("pre"))==null?void 0:u.innerText)==null?void 0:m.replace(/\n$/,""))??"")||h;!C||!await Xe(C)||(a(!0),c.current!=null&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>a(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-panel-md-pre-wrap",ref:b,children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy",onClick:y=>void A(y),"aria-label":n?"已复制":"复制代码",title:n?"已复制":"复制",children:n?e.jsx(Ye,{size:14,"aria-hidden":!0}):e.jsx(Ge,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:s.children})]})}function Yt(s){const n=Ft(s.children);return n!=null?e.jsx(Xt,{source:n,codeChildren:s.children}):e.jsx(Ut,{children:s.children})}const Gt={pre:({children:s})=>e.jsx(Yt,{children:s})},Le=i.memo(function(n){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(At,{remarkPlugins:[_t],components:Gt,children:n.children})})}),Vt=["如何发布文档?","草稿是什么?","如何创建工作空间?"];function Oe(s,n){return n.map((a,c)=>{const b=a.skillNames&&a.skillNames.length>0?a.skillNames:a.skillIds&&a.skillIds.length>0?a.skillIds:void 0;return{id:`h-${s}-${c}-${a.role}`,role:a.role,content:a.content,skillNames:b}})}function Jt(s,n){const a=s.slice(),c=a[a.length-1];return(c==null?void 0:c.type)==="text"?a[a.length-1]={type:"text",text:c.text+n}:a.push({type:"text",text:n}),a}function Zt(s,n){const a=s.slice(),c=a[a.length-1];return(c==null?void 0:c.type)==="thinking"?a[a.length-1]={type:"thinking",text:c.text+n}:a.push({type:"thinking",text:n}),a}function We(s){return s!=null&&s.length?s.filter(n=>n.type==="text").map(n=>n.text).join(""):""}function Qt(s){return!!(s!=null&&s.some(n=>n.type==="thinking"&&n.text.length>0))}function es(s){const n=new Date(s);if(Number.isNaN(n.getTime()))return"";const a=new Date;return n.getFullYear()===a.getFullYear()&&n.getMonth()===a.getMonth()&&n.getDate()===a.getDate()?n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function He(s){if(s>=1e3){const n=s/1e3;return`${n>=10?Math.round(n):Math.round(n*10)/10}K`}return String(s)}function ts(s){const{block:n,onResolved:a}=s,[c,b]=i.useState(""),[h,A]=i.useState(!1),[y,_]=i.useState(1),C=i.useRef(!1),E=i.useRef(a);E.current=a;const N=n.status==="open",u=i.useRef(0);i.useEffect(()=>{if(!N)return;C.current=!1;const j=new Date(n.expiresAt).getTime(),M=Date.now(),P=Math.max(j-M,1);u.current=P,_(1);const F=()=>{const R=j-Date.now(),p=Math.max(0,Math.min(1,R/P));_(p),R<=0&&!C.current&&(C.current=!0,kt(n.requestId).catch(()=>{}).finally(()=>{E.current(n.requestId,"","expired")}))};F();const T=window.setInterval(F,100);return()=>window.clearInterval(T)},[N,n.expiresAt,n.requestId]);async function m(j){const M=j.trim();if(!(!M||h||!N)){A(!0);try{await Nt(n.requestId,M),a(n.requestId,M,"selected")}catch{a(n.requestId,M,"failed")}finally{A(!1)}}}async function I(){if(!(h||!N)){A(!0),C.current=!0;try{await Ue(n.requestId),a(n.requestId,"","cancelled")}catch{a(n.requestId,"","failed")}finally{A(!1)}}}const H=Math.max(0,Math.ceil(y*u.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(N?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:n.title}),N?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[H,"s"]}):null]}),N?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(y*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${y})`}})}):null,n.status==="selected"&&n.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",n.selected]}):null,n.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,n.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,n.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,N?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:n.options.map(j=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:h,onClick:()=>void m(j),children:j},j))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:c,disabled:h,placeholder:"或输入自己的内容…",onChange:j=>b(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),m(c))}}),e.jsx("button",{type:"button",disabled:h||!c.trim(),onClick:()=>void m(c),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:h,onClick:()=>void I(),children:"取消"})})]}):null]})}function ss(s){const b=2*Math.PI*8.75,h=Math.min(100,Math.max(0,s.percent)),A=b*(1-h/100),y=h>=90?"danger":h>=70?"warn":"ok",_=`上下文 ${h}% · 已用 ${He(s.used)} / ${He(s.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+y,"data-tooltip":_,"aria-label":_,role:"img",tabIndex:0,children:e.jsxs("svg",{width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,children:[e.jsx("circle",{className:"mdocs-agent-panel-context-track",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5}),e.jsx("circle",{className:"mdocs-agent-panel-context-value",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:b,strokeDashoffset:A,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function ns(s){var n;for(const a of s)if(!(a.role!=="assistant"||!((n=a.blocks)!=null&&n.length))){for(const c of a.blocks)if((c.type==="choice_card"||c.type==="skill_form_card")&&c.status==="open")return!0}return!1}const ps=i.forwardRef(function(n,a){const{open:c,onClose:b,visitorName:h,anchorStyle:A,fullscreen:y,onToggleFullscreen:_,domainId:C,documentId:E,documentTitle:N,documentPath:u,graphFileId:m,graphLabel:I,onOpenDocument:H,onTreeChanged:j,onDocumentOverwritten:M,onOpenCoding:P}=n,F=((h==null?void 0:h.trim().charAt(0))||"我").toUpperCase(),[T,R]=i.useState(!1),[p,U]=i.useState(null),[Ve,Y]=i.useState(null),[z,w]=i.useState([]),[re,G]=i.useState(null),[Ne,Je]=i.useState([]),[Ze,be]=i.useState(!1),[V,J]=i.useState(""),[X,ve]=i.useState([]),[we,ie]=i.useState(!1),[v,Z]=i.useState(!1),[Ce,B]=i.useState(null),[Q,Se]=i.useState(null),[oe,O]=i.useState(!1),[L,Ae]=i.useState(!1),Qe=i.useRef(null),ee=i.useRef(null),D=i.useRef(null),_e=i.useRef(0),K=i.useRef(!0),[et,le]=i.useState(!1),ce=i.useRef(z);ce.current=z;const Ie=!!(E!=null&&E.trim())&&!we,tt=(N==null?void 0:N.trim())||"当前文档",Me=(u==null?void 0:u.trim())||"",de=!!(m!=null&&m.trim())&&!we,st=(I==null?void 0:I.trim())||"当前图谱";i.useEffect(()=>{ie(!1)},[E,m]);function Ee(t){return _e.current+=1,`${t}-${_e.current}`}const Re=120;function $e(t){return t.scrollHeight-t.scrollTop-t.clientHeight}function te(){const t=ee.current;t&&(t.scrollTop=t.scrollHeight,le(!1))}function q(){K.current&&te()}function nt(){const t=ee.current;if(!t)return;const f=$e(t);K.current=f<=48,le(f>Re)}function at(){K.current=!0,te()}i.useLayoutEffect(()=>{q();const t=ee.current;t&&le($e(t)>Re)},[z]);async function rt(){be(!0);try{const t=await ht();Je(t.sessions),re||G(t.lastOpenedSessionId)}catch{}finally{be(!1)}}async function ue(){try{const t=await ft();Se(t)}catch{}}async function Te(){try{const t=await qe();U(t),Y(null)}catch(t){U(null),Y(t instanceof Error?t.message:String(t))}}i.useEffect(()=>{var f;if(!c){R(!1),(f=D.current)==null||f.abort(),D.current=null,Z(!1);return}let t=!1;return(async()=>{try{const o=await qe();t||(U(o),Y(null))}catch(o){t||(U(null),Y(o instanceof Error?o.message:String(o)))}})(),ue(),()=>{t=!0}},[c]),i.useEffect(()=>{if(!c)return;let t=!1;return(async()=>{try{const f=await mt();if(t)return;G(f.sessionId),w(o=>o.length>0?o:Oe(f.sessionId,f.messages))}catch{}})(),()=>{t=!0}},[c]),i.useEffect(()=>{!c||!T||rt()},[c,T]);function me(){if(!L){if(ns(ce.current)){O(!0);return}O(!1),b()}}async function it(){var o;if(L)return;Ae(!0);const t=ce.current,f=[];for(const S of t)if(!(S.role!=="assistant"||!S.blocks))for(const g of S.blocks)g.type==="choice_card"&&g.status==="open"&&f.push(Ue(g.requestId).catch(()=>{})),g.type==="skill_form_card"&&g.status==="open"&&f.push(jt(g.requestId).catch(()=>{}));await Promise.all(f),(o=D.current)==null||o.abort(),w(S=>S.map(g=>g.role!=="assistant"||!g.blocks?g:{...g,blocks:g.blocks.map(x=>x.type==="choice_card"&&x.status==="open"?{...x,status:"cancelled"}:x.type==="skill_form_card"&&x.status==="open"?{...x,status:"cancelled"}:x)})),O(!1),Ae(!1),b()}const pe=i.useRef(me);pe.current=me,i.useImperativeHandle(a,()=>({requestClose:()=>pe.current()}),[]),i.useEffect(()=>{if(!c){O(!1);return}const t=f=>{if(f.key==="Escape"){if(oe){L||O(!1);return}if(T){R(!1);return}pe.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[c,T,oe,L]);async function fe(t){var x;const f=t.trim();if(!f||v)return;if(!(p!=null&&p.enabled)){B((p==null?void 0:p.reason)==="missing_api_key"?"请先配置 API Key":(p==null?void 0:p.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(x=D.current)==null||x.abort();const o=new AbortController;D.current=o;const S={id:Ee("u"),role:"user",content:f,skillNames:X.length>0?[...X]:void 0},g=Ee("a");K.current=!0,w($=>[...$,S,{id:g,role:"assistant",content:""}]),J(""),Z(!0),B(null),R(!1),requestAnimationFrame(()=>{te(),requestAnimationFrame(te)});try{let $=!1;await yt(f,{skillNames:X.length>0?X:void 0,references:{domainId:(C==null?void 0:C.trim())||void 0,documentId:!de&&Ie?E.trim():void 0,graphFileId:de?m.trim():void 0},signal:o.signal,onEvent:l=>{l.type==="text_delta"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=Jt(r.blocks??[],l.text);return{...r,blocks:d,content:We(d)}})),requestAnimationFrame(()=>q())):l.type==="thinking_delta"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=Zt(r.blocks??[],l.text);return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="sources"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=(r.blocks??[]).slice(),ge=d[d.length-1];return(ge==null?void 0:ge.type)==="sources"?d[d.length-1]={type:"sources",items:l.items}:d.push({type:"sources",items:l.items}),{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="document_table"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"document_table",title:l.title,rows:l.rows}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="document_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"document_card",documentId:l.documentId,title:l.title,path:l.path,preview:l.preview}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="tool_notice"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"tool_notice",toolName:l.toolName,text:l.text}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="choice_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"choice_card",requestId:l.requestId,title:l.title,options:l.options,expiresAt:l.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="choice_expired"?w(k=>k.map(r=>r.id!==g||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===l.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):l.type==="skill_form_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"skill_form_card",requestId:l.requestId,mode:l.mode,title:l.title,currentName:l.currentName,initialName:l.initialName,initialDescription:l.initialDescription,initialBody:l.initialBody,expiresAt:l.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="skill_form_expired"?w(k=>k.map(r=>r.id!==g||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===l.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):l.type==="tree_changed"?j==null||j():l.type==="document_overwritten"?M==null||M({documentId:l.documentId,headCommitId:l.headCommitId}):l.type==="open_coding"?P==null||P({documentId:l.documentId,displayName:l.displayName}):l.type==="context_usage"?Se({percent:l.percent,used:l.used,limit:l.limit}):l.type==="error"&&($=!0,B(l.message))}}),!o.signal.aborted&&!$&&ve([])}catch($){if(o.signal.aborted)return;B($ instanceof Error?$.message:String($))}finally{D.current===o&&(D.current=null),Z(!1)}}async function ot(){var t;if(!v){(t=D.current)==null||t.abort(),B(null),R(!1),Z(!1);try{const f=await gt();G(f.sessionId),w([]),J(""),K.current=!0,ue()}catch(f){B(f instanceof Error?f.message:String(f))}}}async function lt(t){var f;if(!v){if(t===re){R(!1);return}(f=D.current)==null||f.abort(),B(null);try{const o=await xt(t);G(o.sessionId),w(Oe(o.sessionId,o.messages)),J(""),R(!1),K.current=!0,requestAnimationFrame(()=>q()),ue()}catch(o){B(o instanceof Error?o.message:String(o))}}}function ze(t){!t||!H||H(t)}if(!c)return null;const he=(p==null?void 0:p.reason)==="missing_api_key",De=Ve??(p&&!p.enabled&&!he?p.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:Qe,className:"mdocs-agent-panel"+(y?" mdocs-agent-panel--fullscreen":""),role:"dialog","aria-label":"mdocs 智能助手","aria-modal":y?!0:void 0,style:y?void 0:A,children:[e.jsxs("header",{className:"mdocs-agent-panel-header",children:[e.jsxs("div",{className:"mdocs-agent-panel-title",children:[e.jsx("img",{src:Fe,alt:"",className:"mdocs-agent-panel-title-logo"}),e.jsx("span",{children:"mdocs 智能助手"})]}),e.jsxs("div",{className:"mdocs-agent-panel-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:v,onClick:()=>void ot(),children:e.jsx(St,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(T?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>R(t=>!t),children:e.jsx(bt,{size:16,strokeWidth:1.8})}),_?e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:y?"退出全屏":"全屏","aria-label":y?"退出全屏":"全屏",onClick:_,children:y?e.jsx(Rt,{size:16,strokeWidth:1.8}):e.jsx(Mt,{size:16,strokeWidth:1.8})}):null,e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:me,children:e.jsx(ne,{size:16,strokeWidth:1.8})})]})]}),T?e.jsxs("div",{className:"mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>R(!1),children:"返回对话"})]}),Ze?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):Ne.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):e.jsx("ul",{className:"mdocs-agent-panel-history-list",children:Ne.map(t=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(t.id===re?" active":""),disabled:v,onClick:()=>void lt(t.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:t.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:es(t.updatedAt)})]})},t.id))})]}):e.jsxs("div",{className:"mdocs-agent-panel-body",children:[e.jsxs("div",{className:"mdocs-agent-panel-scroll-wrap",children:[e.jsx("div",{className:"mdocs-agent-panel-welcome",ref:ee,onScroll:nt,children:z.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-hello",children:"你好,我是 mdocs 智能助手"}),e.jsx("p",{className:"mdocs-agent-panel-desc",children:"我能答疑、搜文档、整理结构,也能帮你写全文;需要精细改稿请点文档顶栏「帮写」。"}),he?e.jsx(Pe,{onConfigured:Te}):De?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:De}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:Vt.map(t=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void fe(t),disabled:v||!(p!=null&&p.enabled),children:t},t))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:z.map(t=>{var f;return e.jsxs("div",{className:"mdocs-agent-panel-msg"+(t.role==="user"?" mdocs-agent-panel-msg-user":" mdocs-agent-panel-msg-assistant"),children:[t.role==="assistant"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-ai","aria-hidden":!0,children:e.jsx("img",{src:Fe,alt:""})}):null,e.jsxs("div",{className:"mdocs-agent-panel-msg-bubble",children:[t.role==="user"&&t.skillNames&&t.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",t.skillNames.length]}):null,t.role==="assistant"?t.blocks&&t.blocks.length>0?e.jsxs("div",{className:"mdocs-agent-panel-timeline",children:[t.blocks.map((o,S)=>{var g;return o.type==="thinking"?o.text?e.jsxs("details",{className:"mdocs-agent-panel-think-fold",open:v&&t.id===((g=z[z.length-1])==null?void 0:g.id),children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:o.text})]},`${t.id}-th-${S}`):null:o.type==="text"?o.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Le,{children:o.text})},`${t.id}-t-${S}`):null:o.type==="sources"?o.items.length===0?null:e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:["已阅读 ",o.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:o.items.map(x=>e.jsx("li",{children:e.jsx("a",{href:x.url,target:"_blank",rel:"noreferrer",children:x.name})},x.id))})]})},`${t.id}-s-${S}`):o.type==="tool_notice"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:o.text})},`${t.id}-n-${S}`):o.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(ts,{block:o,onResolved:(x,$,l)=>{w(k=>k.map(r=>r.id!==t.id||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===x?{...d,status:l,selected:l==="selected"?$:d.selected}:d)}))}})},`${t.id}-ch-${S}`):o.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(vt,{block:o,onResolved:(x,$,l)=>{w(k=>k.map(r=>r.id!==t.id||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===x?{...d,status:$,submittedName:$==="submitted"?l:d.submittedName}:d)}))}})},`${t.id}-sf-${S}`):o.type==="document_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:x=>{x.preventDefault(),x.stopPropagation(),ze(o.documentId)},children:["《",o.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"文档预览"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[o.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:o.path}):null,o.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:o.preview}):e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview muted",children:"(无正文预览)"})]})]})},`${t.id}-c-${S}`):e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[o.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:o.rows.length===0?"无结果":`${o.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:o.rows.length===0?e.jsx("p",{className:"mdocs-agent-panel-doc-table-empty",children:"无结果"}):e.jsxs("table",{className:"mdocs-agent-panel-doc-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"文章名字"}),e.jsx("th",{children:"文章内容"})]})}),e.jsx("tbody",{children:o.rows.map(x=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>ze(x.documentId),children:x.title})}),e.jsx("td",{children:x.summary||"-"})]},x.documentId))})]})})]})},`${t.id}-d-${S}`)}),v&&t.id===((f=z[z.length-1])==null?void 0:f.id)&&!We(t.blocks)&&!Qt(t.blocks)?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null]}):t.content?e.jsx(Le,{children:t.content}):v?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null:t.content]}),t.role==="user"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-user","aria-hidden":!0,children:F}):null]},t.id)})})}),et?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:at,title:"回到底部","aria-label":"回到底部",children:[e.jsx(wt,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),Ce?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Ce}):null,he&&z.length>0?e.jsx(Pe,{onConfigured:Te}):null,e.jsx(Ct,{selectedNames:X,onChange:ve,disabled:v||!(p!=null&&p.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap",children:[de?e.jsxs("div",{className:"mdocs-agent-doc-ref mdocs-agent-graph-ref",children:[e.jsx(Ke,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:st}),e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:"图谱(只读)"})]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前图谱",disabled:v,onClick:()=>ie(!0),children:e.jsx(ne,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):Ie?e.jsxs("div",{className:"mdocs-agent-doc-ref",children:[e.jsx(pt,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:tt}),Me?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:Me}):null]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前文档",disabled:v,onClick:()=>ie(!0),children:e.jsx(ne,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):null,e.jsxs("div",{className:"mdocs-agent-panel-input-body",children:[e.jsx("textarea",{className:"mdocs-agent-panel-input",rows:2,placeholder:p!=null&&p.enabled?"把你的问题告诉我…":"请先配置 API Key",value:V,disabled:v||!(p!=null&&p.enabled),onChange:t=>J(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),fe(V))}}),Q?e.jsx(ss,{percent:Q.percent,used:Q.used,limit:Q.limit}):null,e.jsx("button",{type:"button",className:v?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:v?!1:!(p!=null&&p.enabled)||!V.trim(),onClick:()=>{var t;if(v){(t=D.current)==null||t.abort();return}fe(V)},title:v?"停止":"发送","aria-label":v?"停止":"发送",children:v?"■":"↑"})]})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),oe?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{L||O(!1)},children:e.jsxs("div",{className:"mdocs-message-dialog mdocs-agent-close-confirm",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-agent-close-confirm-title",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{id:"mdocs-agent-close-confirm-title",className:"mdocs-message-dialog-title",children:"有待处理的倒计时"}),e.jsx("p",{className:"mdocs-message-dialog-body",children:"当前还有选择卡或 Skill 表单在倒计时。强制关闭会取消这些操作并退出助手;也可以继续等待完成后再关。"}),e.jsxs("div",{className:"mdocs-message-dialog-actions mdocs-agent-close-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",disabled:L,onClick:()=>O(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:L,onClick:()=>void it(),children:L?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{ps as AgentChatPanel};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import{o as d,c as v,F as D,P as M,p as x,l as k,R as j,E as B,q as P,S as E,M as S}from"./index-Cwy87sZC.js";import{r as I,j as n}from"./react-vendor-BuABiQkA.js";import{g as W}from"./file-type-policy-GUk904tm.js";/**
|
|
2
|
-
* @license lucide-react v0.562.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const w=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],z=d("chevron-up",w);/**
|
|
7
|
-
* @license lucide-react v0.562.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const A=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M6.376 18.91a6 6 0 0 1 11.249.003",key:"hnjrf2"}],["circle",{cx:"12",cy:"11",r:"4",key:"1gt34v"}]],L=d("shield-user",A);/**
|
|
12
|
-
* @license lucide-react v0.562.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const O=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],R=d("text-align-justify",O);/**
|
|
17
|
-
* @license lucide-react v0.562.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const _=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],$=d("users",_);function q(e){const{t,lang:m}=v(),l=W(e.fileType||"md"),f=!!(l!=null&&l.aiWrite&&e.onAiWrite),C=!!(l!=null&&l.comments&&e.onToggleComments);e.canEdit&&(e.editing||e.actionsAlwaysVisible);const[o,N]=I.useState(!1),r=e.domains.length?e.domains:[D],c="mdocs-editor-toolbar"+(e.readerChrome?e.readerHeaderDocked?" mdocs-editor-toolbar--docked":" mdocs-editor-toolbar--float":""),s=e.readerChrome&&!e.readerHeaderDocked&&e.readerDragOffset?{transform:`translateY(${e.readerDragOffset}px)`}:void 0;if(e.readerChrome){const a=n.jsxs("div",{className:"mdocs-editor-toolbar-leading",onPointerDown:e.onReaderHeaderPointerDown,onPointerMove:e.onReaderHeaderPointerMove,onPointerUp:e.onReaderHeaderPointerUp,onPointerCancel:e.onReaderHeaderPointerUp,children:[n.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>{var i;return(i=e.onOpenMobileNav)==null?void 0:i.call(e)},"aria-label":t("expandSidebar"),children:n.jsx(M,{size:18,strokeWidth:1.75})}),n.jsx("input",{className:"mdocs-editor-title-input",value:e.displayName,onChange:i=>e.onDisplayNameChange(i.target.value),onBlur:e.onDisplayNameBlur,placeholder:t("displayNamePlaceholder"),disabled:!e.editing,readOnly:!e.editing})]}),u=n.jsx(x,{domains:r,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:t("currentDomainAria"),localizeName:i=>k(i,m,t)}),h=e.canEdit&&e.onPublish?n.jsx("button",{type:"button",className:"primary mdocs-reader-action-btn",disabled:e.busy,onClick:()=>{var i,g;e.editing||(i=e.onEnterEdit)==null||i.call(e),(g=e.onPublish)==null||g.call(e)},children:e.busy?t("publishing"):t("publish")}):null,y=e.onSyncClick?n.jsx("button",{type:"button",className:"mdocs-sync-btn mdocs-reader-sync-btn"+(e.syncBehind?" behind":""),"aria-label":e.syncBehind?t("syncBehindHint"):t("syncPull"),onClick:()=>{var i;return void((i=e.onSyncClick)==null?void 0:i.call(e))},children:n.jsx(j,{size:16,strokeWidth:1.75})}):null,b=e.readerMoreMenu!=null?n.jsxs("div",{ref:e.readerMoreMenuRef,className:"mdocs-reader-more-menu",children:[n.jsx("button",{type:"button",className:"mdocs-reader-more-btn","aria-label":"更多","aria-expanded":e.readerMoreOpen,onClick:()=>{var i;return(i=e.onToggleReaderMore)==null?void 0:i.call(e)},children:n.jsx(B,{size:18,strokeWidth:1.75})}),e.readerMoreOpen?n.jsx("div",{className:"mdocs-reader-more-dropdown card",children:e.readerMoreMenu}):null]}):null;return e.readerActionsCollapsible?n.jsxs("div",{className:c+" mdocs-editor-toolbar--stacked",style:s,children:[n.jsxs("div",{className:"mdocs-reader-top-row",children:[a,y,n.jsx("button",{type:"button",className:"mdocs-reader-expand-btn",onClick:()=>N(i=>!i),"aria-label":o?"收起操作栏":"展开操作栏",children:n.jsx(z,{size:16,strokeWidth:2,style:{transform:o?"rotate(0deg)":"rotate(180deg)",transition:"transform 0.2s"}})}),b]}),o&&n.jsxs("div",{className:"mdocs-reader-actions-row",children:[u,e.leadingExtra,h,e.trailingExtra]})]}):n.jsxs("div",{className:c,style:s,children:[a,u,e.leadingExtra,y,h,b,e.trailingExtra]})}return n.jsxs("div",{className:c,style:s,children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",children:[n.jsx("input",{className:"mdocs-editor-title-input",value:e.displayName,onChange:a=>e.onDisplayNameChange(a.target.value),onBlur:e.onDisplayNameBlur,placeholder:t("displayNamePlaceholder"),disabled:!e.editing}),n.jsx(x,{domains:r,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:t("currentDomainAria"),localizeName:a=>k(a,m,t)}),f?n.jsxs("button",{type:"button",className:"secondary",onClick:()=>{var a;return(a=e.onAiWrite)==null?void 0:a.call(e)},style:{padding:"4px 10px",whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",gap:6},children:[n.jsx("img",{src:P,alt:"",width:16,height:16,style:{display:"block"}}),"帮写"]}):null,e.leadingExtra]}),n.jsx("span",{className:"mdocs-editor-toolbar-spacer","aria-hidden":!0}),n.jsxs("div",{className:"mdocs-editor-toolbar-trailing",children:[e.onToggleBookmark?n.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var a;return(a=e.onToggleBookmark)==null?void 0:a.call(e)},disabled:e.bookmarkBusy,"data-tooltip":e.isBookmarked?"取消收藏":"收藏",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,opacity:e.bookmarkBusy?.5:1},children:[n.jsx(E,{size:18,strokeWidth:1.5,style:{color:e.isBookmarked?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:e.isBookmarked?"#faad14":"none"}}),e.isBookmarked?n.jsx("span",{children:"已收藏"}):null]}):null,n.jsxs("div",{className:"mdocs-editor-toolbar-actions",children:[e.onSyncClick?n.jsxs("button",{type:"button",className:"mdocs-sync-btn mdocs-tooltip mdocs-tooltip-bottom"+(e.syncBehind?" behind":""),"data-tooltip":e.syncBehind?t("syncBehindHint"):t("syncPull"),onClick:()=>{var a;return void((a=e.onSyncClick)==null?void 0:a.call(e))},style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx(j,{size:16,strokeWidth:1.5}),n.jsx("span",{children:t("syncPull")})]}):null,e.editing?n.jsxs(n.Fragment,{children:[localStorage.getItem("mdocs.autoPublish")!=="true"&&n.jsxs("span",{className:"mdocs-save-indicator",children:[n.jsx("span",{className:"mdocs-save-dot "+(e.busy?"saving":e.draftExists?"unsaved":"saved")}),n.jsx("span",{children:e.busy?t("publishing"):e.draftExists?t("unsaved"):t("published")})]}),e.onPublish?n.jsx("button",{type:"button",className:"primary",disabled:e.busy,onClick:()=>{var a;return(a=e.onPublish)==null?void 0:a.call(e)},children:e.busy?t("publishing"):t("publish")}):null,e.onDelete?n.jsx("button",{type:"button",className:"danger",disabled:e.busy,onClick:()=>{var a;return(a=e.onDelete)==null?void 0:a.call(e)},children:t("delete")}):null]}):null,!e.editing&&e.canEdit&&e.onEnterEdit?n.jsx("button",{type:"button",className:"primary",onClick:()=>{var a;return(a=e.onEnterEdit)==null?void 0:a.call(e)},children:t("edit")}):null,e.trailingExtra,C?n.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var a;return(a=e.onToggleComments)==null?void 0:a.call(e)},"data-tooltip":"评论",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:e.commentPanelOpen?"var(--mdocs-hover-bg, #f0f0f0)":void 0},children:[n.jsx(S,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}}),e.commentCount&&e.commentCount>0?n.jsx("span",{style:{fontSize:"0.85rem"},children:e.commentCount}):null]}):null,e.onToggleDocInfo?n.jsxs("div",{ref:e.docInfoMenuRef,className:"mdocs-tooltip mdocs-tooltip-bottom","data-tooltip":t("docInfo"),style:{position:"relative"},children:[n.jsx("button",{type:"button",className:"secondary",onClick:()=>{var a;return(a=e.onToggleDocInfo)==null?void 0:a.call(e)},style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx(R,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}})}),e.docInfoOpen?n.jsx("div",{className:"mdocs-doc-info-dropdown",children:e.docInfoMenu}):null]}):null]})]})]})}export{q as D,L as S,$ as U};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as n,j as a}from"./react-vendor-BuABiQkA.js";import{ad as ge}from"./ui-ZPt_BNBg.js";import{g as be,u as we,a as ye,s as Ue,d as qe,b as ve,c as Ve,f as We,e as Ye,h as Ge,N as Je,S as $e,l as Ke,r as Xe,i as Qe,j as Ze,D as Z,k as pe,m as et,n as xe}from"./index-Cwy87sZC.js";import{z as tt,A as nt,m as se,n as at,o as it,p as rt,r as ot,s as st,t as ct,v as lt,x as ut,B as dt,R as mt,a as ft,b as Ie,c as ht,d as gt,e as yt,f as vt,g as xt,h as It,i as kt,w as ce,j as St,O as Et,E as bt,q as wt,l as Mt,C as Ct,D as Dt}from"./react-BkX5Koku.js";import{H as Rt,a as jt,b as At,M as Nt,T as Pt,S as Tt,W as Bt,o as Lt,c as ke}from"./Toolbar-D9FcRwg3.js";import{D as Ot,U as _t,S as Ht}from"./DocChrome-QTGER_Af.js";import{V as zt}from"./VisitorPickerModal-CM13Y6jQ.js";import"./motion-Dyy8pB0Q.js";import"./diagram-CgEd0hrk.js";import"./editor-CL03se2B.js";import"./plus-CEapsZwl.js";import"./check-Bf8YbzH7.js";import"./copy-SBghRY2T.js";import"./file-type-policy-GUk904tm.js";const Ft=48;function p(e){try{const i=e.getDocument("markdown");return typeof i=="string"?i:""}catch{return null}}function Ut(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function qt({editor:e,documentId:i,displayName:c,debounceMs:I=1e3,enabled:g=!0,localBaseCommitIdAtEditStart:R,snapshotMeta:b,seedDraftExists:z=!1}){const[F,L]=n.useState(!1),[ee,j]=n.useState(z),[A,S]=n.useState(null),d=n.useRef(null),f=n.useRef(null),k=n.useRef(!1),x=n.useRef(""),v=n.useRef(!1),O=n.useRef(i),U=n.useRef(c),N=n.useRef(R),J=n.useRef(b);O.current=i,U.current=c,N.current=R,J.current=b;const E=n.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const s=Ut(e);s!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",O.current,"content preview:",s.slice(0,80)),await be(O.current).execute(()=>we({documentId:O.current,content:s,displayName:U.current,localBaseCommitIdAtEditStart:N.current,snapshotMeta:J.current})),x.current=p(e)??x.current,j(!0),L(!1),S(Date.now()),k.current=!0,v.current=!1)},[e]);n.useEffect(()=>{let s=!1;const m=ve();return ye(i).then(h=>{if(s||ve()!==m)return;const y=!!(h&&!h.published);j(y),y&&h?(S(h.updatedAt),k.current=!0):(S(null),k.current=!1,v.current=!1)}),()=>{s=!0}},[i]),n.useEffect(()=>Ue((s,m)=>{s===O.current&&(j(m),m||(S(null),k.current=!1))}),[]),n.useEffect(()=>{var H,q;if(!g){(H=f.current)==null||H.call(f),f.current=null;return}if(!e)return;const s=e.getLexicalEditor();if(!s)return;(q=f.current)==null||q.call(f);let m=!1,h=0,y=0;const _=()=>{if(m)return;const P=p(e);if(P===null){if(y+=1,y>Ft)return;h=requestAnimationFrame(_);return}x.current=P;const ne=s.registerUpdateListener(()=>{const M=p(e);M!==null&&M!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",i,"oldLen:",x.current.length,"newLen:",M.length),x.current=M,L(!0),v.current=!0,k.current=!1,d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,E()},I))});f.current=()=>{ne(),d.current&&(clearTimeout(d.current),d.current=null)}};return queueMicrotask(()=>{m||(h=requestAnimationFrame(_))}),()=>{var P;m=!0,cancelAnimationFrame(h),(P=f.current)==null||P.call(f)}},[g,e,i,c,I,R,b,E]),n.useEffect(()=>{var h;if(!g||!e)return;const s=(h=e.getLexicalEditor())==null?void 0:h.getRootElement();if(!s)return;const m=()=>{d.current&&(clearTimeout(d.current),d.current=null),v.current&&E()};return s.addEventListener("blur",m),()=>s.removeEventListener("blur",m)},[g,e,E]),n.useEffect(()=>{if(!g)return;const s=()=>{document.visibilityState==="hidden"&&(d.current&&(clearTimeout(d.current),d.current=null),v.current&&E())},m=()=>{v.current&&(d.current&&(clearTimeout(d.current),d.current=null),E())};return document.addEventListener("visibilitychange",s),window.addEventListener("beforeunload",m),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("beforeunload",m)}},[g,E]);async function $(){await qe(i),j(!1),L(!1),v.current=!1,k.current=!1,x.current=""}async function te(){const s=await ye(i);return s?s.content:null}function w(){j(!0),L(!1),v.current=!1,S(Date.now()),k.current=!0,e&&(x.current=p(e)??"")}return{isDirty:F,draftExists:ee,lastSavedAt:A,clearDraft:$,loadDraftContent:te,markDraftSaved:w}}function Vt({isDirty:e,draftExists:i}){const c=e&&!i;n.useEffect(()=>{if(!c)return;const I=g=>{g.preventDefault()};return window.addEventListener("beforeunload",I),()=>window.removeEventListener("beforeunload",I)},[c])}function le(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Se='{"root":{"direction":"ltr","format":"","indent":0,"version":1,"type":"root","children":[{"direction":"ltr","format":"","indent":0,"version":1,"textFormat":0,"textStyle":"","children":[],"type":"paragraph"}]}}';function Ee(e){const c=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(c)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(c)?"不支持的文件类型":/^not an image$/i.test(c)?"不是有效的图片文件":c||"上传失败"}function Wt(e,i){if(!e)return i==="json"?Se:e;if(i!=="json")return e;try{const c=JSON.parse(e);if(c!=null&&c.root&&Array.isArray(c.root.children)&&c.root.children.length===0)return Se}catch{}return e}function Yt({editor:e}){const{visible:i}=Ct();return a.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:i?200:0},children:a.jsx("div",{style:{width:200},children:a.jsx(Dt,{editor:e})})})}function sn(e){const{t:i,lang:c}=Ve(),[I,g]=n.useState(!1),[R,b]=n.useState(!1),z=n.useRef(null),F=n.useRef(null),[L,ee]=n.useState([]),[j,A]=n.useState(!1),[S,d]=n.useState(e.meta.permission),[f,k]=n.useState(!1),[x,v]=n.useState(!1),[O,U]=n.useState(!1),[N,J]=n.useState(new Map),[E,$]=n.useState(!1);n.useEffect(()=>{const t=r=>{z.current&&!z.current.contains(r.target)&&g(!1),F.current&&!F.current.contains(r.target)&&b(!1)};return(I||R)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[I,R]),n.useEffect(()=>{let t=!0;return We().then(r=>{t&&ee(r)}).catch(()=>{}),()=>{t=!1}},[]);function te(t){const r=L.find(l=>l.visitorId===t);return(r==null?void 0:r.visitorName)??t.slice(0,8)}const[w,s]=n.useState(e.initialDisplayName),[m,h]=n.useState(!1),[y,_]=n.useState(!1),[H,q]=n.useState(!1),[P,ne]=n.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),M=e.canEdit&&P,[u,ue]=n.useState(null),[Me,de]=n.useState(!1),ae=n.useRef(null);n.useLayoutEffect(()=>{de(!1),ue(null),ae.current=null},[e.meta.documentId]),n.useEffect(()=>{const t=requestAnimationFrame(()=>de(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]);const C=n.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const r=JSON.parse(e.initialContent);return Array.isArray((t=r==null?void 0:r.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),V=n.useMemo(()=>Wt(e.initialContent||"",C),[e.initialContent,C,e.contentRevision]),{isDirty:me,draftExists:K,markDraftSaved:Ce}=qt({editor:u,documentId:e.meta.documentId,displayName:w,enabled:e.canEdit,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId},seedDraftExists:e.hasLocalDraft});n.useEffect(()=>{var t;(t=e.onDraftExistsChange)==null||t.call(e,K)},[K,e.onDraftExistsChange]),Vt({isDirty:me,draftExists:K}),n.useEffect(()=>{if(u)try{u.setDocument(C,V)}catch{}},[u,e.meta.documentId,e.contentRevision,V,C]),n.useEffect(()=>{u==null||u.setLocale(c==="zh"?tt:nt)},[u,c]),n.useEffect(()=>{s(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),n.useEffect(()=>{d(e.meta.permission)},[e.meta.permission,e.meta.documentId]),n.useEffect(()=>{let t=!0;return(async()=>{try{const r=await Ye(e.meta.documentId);t&&_(r.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function ie(){var t,r;if(!H){q(!0);try{y?(await Xe(e.meta.documentId),_(!1),(t=e.onShowToast)==null||t.call(e,i("bookmarkRemoved"))):(await Qe(e.meta.documentId),_(!0),(r=e.onShowToast)==null||r.call(e,i("bookmarkAdded")))}finally{q(!1)}}}n.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=Be),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),n.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ae.current;if(!t)return"";try{const r=t.getDocument("markdown");return typeof r=="string"?r:String(r??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function De(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const Re=n.useCallback(t=>{ae.current=t,ue(t);const r=V;if(!r)return;const l=()=>{try{t.setDocument(C,r)}catch{requestAnimationFrame(()=>{try{t.setDocument(C,r)}catch{}})}};queueMicrotask(()=>{queueMicrotask(l)})},[C,V]);async function fe(){if(!(!u||!e.canEdit)){h(!0);try{const t=le(u);if(!t)return;await e.onPublish(t,w,e.meta.documentId)}catch(t){throw t}finally{h(!1)}}}async function je(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(w.trim()!==t)try{await fe()}catch{}}const D=n.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),Ae=n.useMemo(()=>{const t=(D==null?void 0:D.permission)??"public";return Ge(t)},[D==null?void 0:D.permission]);function Ne(t){return t===Z.PRIVATE?i("permissionPrivate"):t===Z.DOMAIN_READ?i("permissionInvite"):t===Z.DOMAIN_WRITE?i("permissionDomainWrite"):t===Z.PUBLIC_READ?i("permissionPublicRead"):i("permissionPublicEdit")}async function Pe(){var t;if(f||S===e.meta.permission){A(!1);return}k(!0);try{const l=(u?le(u):null)??e.initialContent;await e.onPublish(l,w,e.meta.documentId,S),A(!1),(t=e.onShowToast)==null||t.call(e,i("docInfoPermissionUpdated"))}finally{k(!1)}}async function Te(t){var r;if(!E){$(!0);try{const l=new Set(t.map(o=>o.visitorId)),B=new Map(t.map(o=>[o.visitorId,o.permission]));for(const[o]of N)l.has(o)||await pe(e.meta.documentId,o);for(const{visitorId:o,permission:Y}of t){const G=N.get(o);(!G||G!==Y)&&await et(e.meta.documentId,o,Y)}v(!1),(r=e.onShowToast)==null||r.call(e,i("docInfoInviteSuccess",{count:t.length}))}finally{$(!1)}}}async function Be(){if(!u||!e.canEdit)return;if(!me){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=le(u);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),Ce(),await be(e.meta.documentId).execute(()=>we({documentId:e.meta.documentId,content:t,displayName:w,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const Le=n.useMemo(()=>[{icon:Rt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(se,{tag:"h1"})}},{icon:jt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(se,{tag:"h2"})}},{icon:At,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(se,{tag:"h3"})}},{type:"divider"},{icon:Nt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(at,{})}},{icon:Pt,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(it,{columns:"3",rows:"3"})}},{icon:Tt,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(rt,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{Lt(r=>{for(const l of r)t.dispatchCommand(wt,{file:l})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(ot,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(st,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(ct,void 0),queueMicrotask(()=>t.focus())}},{icon:Bt,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(lt,void 0),queueMicrotask(()=>t.focus())}},{icon:Je,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ut,void 0),queueMicrotask(()=>t.focus())}}].map(t=>"type"in t&&t.type==="divider"?t:{...t,extra:a.jsx("span",{style:{color:"var(--mdocs-text-muted)",fontFamily:"monospace",fontSize:12},children:t.key})}),[]),Oe=n.useMemo(()=>[dt,mt,ft,Ie,ht,gt,yt,vt,xt,It,kt,ce(St,{children:u?a.jsx(ke,{editor:u,floating:!0,outlineCollapseTitle:i("outlineHide"),outlineExpandTitle:i("outlineShow"),outlineToggle:!0}):null}),ce(Mt,{handleUpload:async t=>{var r;try{return{url:await xe(t,e.meta.documentId)}}catch(l){throw(r=e.onShowError)==null||r.call(e,Ee(l)),l}}}),ce(Ie,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var r;try{const B=await(await fetch(t)).blob(),o=new File([B],"image.png",{type:B.type});return{url:await xe(o,e.meta.documentId)}}catch(l){throw(r=e.onShowError)==null||r.call(e,Ee(l)),l}}})],[u,i,e.meta.documentId,e.onShowError]),T=!!e.readerChrome,[W,re]=n.useState(!1),X=n.useRef(null),[_e,oe]=n.useState(0);n.useEffect(()=>{if(!T){re(!1),oe(0);return}if(W)return;const t=window.setTimeout(()=>re(!0),2800);return()=>window.clearTimeout(t)},[T,W,e.meta.documentId]),n.useEffect(()=>{b(!1),g(!1)},[e.meta.documentId]);function He(t){!T||W||t.target.closest("button, a, input, textarea, select")||(X.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function ze(t){const r=X.current;if(!(r!=null&&r.dragging))return;const l=t.clientY-r.startY;oe(Math.max(-72,Math.min(0,l)))}function Fe(t){const r=X.current;if(!(r!=null&&r.dragging))return;X.current=null;const l=t.clientY-r.startY;oe(0),l<-36&&re(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function Q(){g(!1),b(!1)}function he(t,r){const l=(r==null?void 0:r.includeBookmark)??!0,B={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoCreator")}),a.jsx("span",{children:te(e.meta.ownerVisitorId)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoCreatedAt")}),a.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(c==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoSize")}),a.jsx("span",{children:De(new Blob([e.initialContent]).size)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoUpdatedAt")}),a.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(c==="zh"?"zh-CN":"en-US")})]})]}),a.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),l?a.jsxs("button",{type:"button",style:B,onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},onClick:()=>{ie(),t()},children:[a.jsx("span",{children:y?"⭐":"☆"}),a.jsx("span",{children:i(y?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?a.jsxs("button",{type:"button",style:B,onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{U(!0);try{const o=await Ze(e.meta.documentId),Y=new Map(o.map(G=>[G.visitorId,G.permission]));J(Y),v(!0)}finally{U(!1)}})()},children:[a.jsx(_t,{size:14}),a.jsx("span",{children:i("docInfoInviteMember")})]}):null,a.jsxs("button",{type:"button",style:B,onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},onClick:()=>{t(),d(e.meta.permission),A(!0)},children:[a.jsx(Ht,{size:14}),a.jsx("span",{children:i("docInfoChangePermission")})]})]})}return a.jsxs("div",{className:"mdocs-editor"+(T?" mdocs-editor--reader":"")+(T&&W?" mdocs-editor--reader-docked":""),children:[a.jsx(Ot,{fileType:e.meta.fileType||"md",displayName:w,onDisplayNameChange:s,onDisplayNameBlur:()=>void je(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:M,onEnterEdit:()=>ne(!0),onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:m,draftExists:K,onPublish:()=>{fe().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:y,bookmarkBusy:H,onToggleBookmark:()=>void ie(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:he(Q),docInfoOpen:I,onToggleDocInfo:()=>g(!I),docInfoMenuRef:z,readerChrome:T,onOpenMobileNav:e.onOpenMobileNav,readerHeaderDocked:W,readerDragOffset:_e,onReaderHeaderPointerDown:He,onReaderHeaderPointerMove:ze,onReaderHeaderPointerUp:Fe,readerMoreOpen:R,onToggleReaderMore:()=>b(t=>!t),readerMoreMenuRef:F,readerMoreMenu:a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:H,onClick:()=>{ie(),Q()},children:[a.jsx($e,{size:16,strokeWidth:1.5,style:{color:y?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:y?"#faad14":"none"}}),a.jsx("span",{children:i(y?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?a.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:m,onClick:()=>{Q(),e.onDelete()},children:a.jsx("span",{children:i("delete")})}):null,a.jsx("div",{className:"mdocs-reader-more-divider"}),he(Q,{includeBookmark:!1})]})}),j&&a.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&A(!1)},children:a.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[a.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:i("docInfoChangePermission")}),a.jsxs("div",{className:"muted",style:{marginBottom:12},children:[i("domainPermission"),":",D?Ke(D.domainName,c,i):e.meta.domainId]}),a.jsx("div",{style:{display:"grid",gap:8},children:Ae.map(t=>a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[a.jsx("input",{type:"radio",name:"doc-permission",value:t,checked:S===t,onChange:()=>d(t)}),a.jsx("span",{children:Ne(t)})]},t))}),a.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[a.jsx("button",{type:"button",onClick:()=>A(!1),children:i("cancel")}),a.jsx("button",{type:"button",className:"primary",disabled:f,onClick:()=>void Pe(),children:i(f?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&a.jsx(zt,{open:x,title:i("docInfoInviteMember"),initialSelectedIds:[...N.keys()],initialPermissions:N,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:i("invitePermissionRead")},{value:"edit",label:i("invitePermissionEdit")}],onClose:()=>v(!1),onConfirm:t=>{Te(t)}}),a.jsx(Et,{children:a.jsx(ge,{flex:1,style:{minHeight:0},children:a.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[M&&u&&!T?a.jsx(ke,{editor:u,outlineCollapseTitle:i("outlineHide"),outlineExpandTitle:i("outlineShow"),outlineToggle:!0}):null,a.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:a.jsxs(ge,{variant:"outlined",horizontal:!0,style:{background:"var(--mdocs-surface)",flex:1,minHeight:0,minWidth:0,borderRadius:0,outline:"none"},children:[a.jsx("div",{className:"mdocs-editor-scroll-host",children:Me?a.jsx(bt,{content:V,type:C,confirmPasteMarkdown:!0,editable:M,onInit:Re,plugins:Oe,lineEmptyPlaceholder:i("displayNamePlaceholder"),placeholder:i("displayNamePlaceholder"),slashOption:{items:Le},className:"mdocs-document-editor-root"},e.meta.documentId):null}),u&&a.jsx(Yt,{editor:u})]})})]})})})]})}export{sn as DocumentEditor};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as i,j as n}from"./react-vendor-BuABiQkA.js";import{c as ue,f as fe,e as he,a as xe,s as ve,g as ge,u as ye,h as be,S as ke,l as je,r as Ce,i as Ie,j as De,D as C,k as we,m as Se,b as q}from"./index-Cwy87sZC.js";import{D as Ee,U as Ne,S as Me}from"./DocChrome-QTGER_Af.js";import{V as Pe}from"./VisitorPickerModal-CM13Y6jQ.js";import"./ui-ZPt_BNBg.js";import"./motion-Dyy8pB0Q.js";import"./diagram-CgEd0hrk.js";import"./file-type-policy-GUk904tm.js";function Ue(e){const{t:a,lang:I}=ue(),r=e.meta.documentId,[x,D]=i.useState(e.initialContent),[f,w]=i.useState(e.initialDisplayName),[c,g]=i.useState(!0),[H,$]=i.useState(!1),[J,y]=i.useState(e.hasLocalDraft??!1),[m,S]=i.useState(!1),[E,_]=i.useState(!1),[b,N]=i.useState(!1),[M,P]=i.useState(!1),[X,Z]=i.useState([]),[p,v]=i.useState(!1),[B,A]=i.useState(e.meta.permission),[R,K]=i.useState(!1),[ee,T]=i.useState(!1),[k,te]=i.useState(new Map),z=i.useRef(null),O=i.useRef(null),d=i.useRef(null),V=i.useRef(x),L=i.useRef(f);V.current=x,L.current=f;const ne=e.canEdit&&!c;i.useEffect(()=>{D(e.initialContent),w(e.initialDisplayName),g(!0)},[r]),i.useEffect(()=>{e.contentRevision&&(D(e.initialContent),w(e.initialDisplayName))},[e.contentRevision]),i.useEffect(()=>{let t=!0;return fe().then(s=>{t&&Z(s)}).catch(()=>{}),()=>{t=!1}},[]),i.useEffect(()=>{let t=!0;return he(r).then(s=>{t&&S(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),i.useEffect(()=>{let t=!1;const s=q();return xe(r).then(o=>{var j;if(t||q()!==s)return;const u=!!(o&&!o.published);y(u),(j=e.onDraftExistsChange)==null||j.call(e,u)}),()=>{t=!0}},[r,e.onDraftExistsChange]),i.useEffect(()=>ve((t,s)=>{var o;t===r&&(y(s),(o=e.onDraftExistsChange)==null||o.call(e,s))}),[r,e.onDraftExistsChange]),i.useEffect(()=>{A(e.meta.permission)},[e.meta.permission,r]),i.useEffect(()=>{const t=s=>{z.current&&!z.current.contains(s.target)&&N(!1),O.current&&!O.current.contains(s.target)&&P(!1)};return(b||M)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[b,M]);const U=i.useCallback(async()=>{var t;await ge(r).execute(()=>ye({documentId:r,content:V.current,displayName:L.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),y(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),G=i.useCallback(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{U()},1e3)},[U]);i.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);async function F(t){var s;if(e.canEdit){$(!0);try{d.current&&(clearTimeout(d.current),d.current=null),await U(),await e.onPublish(V.current,L.current.trim()||f,r,t),y(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{$(!1)}}}async function ie(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(f.trim()!==t)try{await F()}catch{}}async function W(){var t,s;if(!E){_(!0);try{m?(await Ce(r),S(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Ie(r),S(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{_(!1)}}}function ae(t){const s=X.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function se(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const l=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),oe=i.useMemo(()=>{const t=(l==null?void 0:l.permission)??"public";return be(t)},[l==null?void 0:l.permission]);function re(t){return t===C.PRIVATE?a("permissionPrivate"):t===C.DOMAIN_READ?a("permissionInvite"):t===C.DOMAIN_WRITE?a("permissionDomainWrite"):t===C.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function de(){if(R||B===e.meta.permission){v(!1);return}K(!0);try{await F(B),v(!1)}finally{K(!1)}}async function le(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of k)s.has(o)||await we(r,o);for(const o of t)k.get(o.visitorId)!==o.permission&&await Se(r,o.visitorId,o.permission);T(!1)}function h(){N(!1),P(!1)}function Q(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,u={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreator")}),n.jsx("span",{children:ae(e.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreatedAt")}),n.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(I==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:se(new Blob([x]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(I==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?n.jsxs("button",{type:"button",style:u,onClick:()=>{W(),t()},children:[n.jsx("span",{children:m?"⭐":"☆"}),n.jsx("span",{children:a(m?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:u,onClick:()=>{t(),(async()=>{const j=await De(r);te(new Map(j.map(Y=>[Y.visitorId,Y.permission]))),T(!0)})()},children:[n.jsx(Ne,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:u,onClick:()=>{t(),A(e.meta.permission),v(!0)},children:[n.jsx(Me,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}const ce=i.useCallback(t=>{var o;const s=t.target.value;D(s),(o=e.onContentChange)==null||o.call(e,s),G()},[e,G]),me=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${x}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(Ee,{fileType:"html",displayName:f,onDisplayNameChange:w,onDisplayNameBlur:()=>void ie(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:ne,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:H,draftExists:J,onPublish:()=>{F().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:m,bookmarkBusy:E,onToggleBookmark:()=>void W(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:Q(h),docInfoOpen:b,onToggleDocInfo:()=>N(!b),docInfoMenuRef:z,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:M,onToggleReaderMore:()=>P(t=>!t),readerMoreMenuRef:O,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:E,onClick:()=>{W(),h()},children:[n.jsx(ke,{size:16,strokeWidth:1.5,style:{color:m?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:m?"#faad14":"none"}}),n.jsx("span",{children:a(m?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!c,onClick:()=>{g(!1),h()},children:a("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:c,onClick:()=>{g(!0),h()},children:a("preview")}),n.jsx("div",{className:"mdocs-reader-more-divider"}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:H,onClick:()=>{h(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),Q(h,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":a(c?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:c,onChange:()=>g(t=>!t)}),n.jsxs("span",{className:"mdocs-editor-mode-toggle-slider",children:[n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--left",children:a("edit")}),n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--right",children:a("preview")})]})]}):null}),n.jsxs("div",{className:"mdocs-html-editor-body",children:[!c&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:x,onChange:ce,spellCheck:!1,placeholder:"在此处编写 HTML 代码"}):null,n.jsx("div",{className:"mdocs-html-editor-preview",style:!c&&e.canEdit?{width:"50%"}:{width:"100%"},children:n.jsx("iframe",{className:"mdocs-html-editor-iframe",srcDoc:me,sandbox:"",title:f})})]}),p&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&v(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",l?je(l.domainName,I,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:oe.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"html-doc-permission",value:t,checked:B===t,onChange:()=>A(t)}),n.jsx("span",{children:re(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>v(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:R,onClick:()=>void de(),children:a(R?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Pe,{open:ee,title:a("docInfoInviteMember"),initialSelectedIds:[...k.keys()],initialPermissions:k,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>T(!1),onConfirm:t=>{le(t)}})]})}export{Ue as HtmlEditor};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import{r as n,j as o,ad as C}from"./react-vendor-BuABiQkA.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-BkX5Koku.js";import{a7 as Q,a8 as X,a9 as ee,aa as te,ab as k,ac as oe}from"./ui-ZPt_BNBg.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,c as R,o as ce}from"./Toolbar-D9FcRwg3.js";import{N as me}from"./index-Cwy87sZC.js";import"./editor-CL03se2B.js";import"./diagram-CgEd0hrk.js";import"./plus-CEapsZwl.js";import"./check-Bf8YbzH7.js";import"./copy-SBghRY2T.js";import"./motion-Dyy8pB0Q.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[g,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:g,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,g]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");g(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(J,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(W,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{ce(l=>{for(const u of l)e.dispatchCommand(z,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
|
|
2
|
-
123`),queueMicrotask(()=>{e.focus()})}},{key:"insert-link",label:"InsertLink",onSelect:e=>{e.dispatchCommand(B,{url:"https://example.com"}),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeInline",label:"InsertCodeInline",onSelect:e=>{e.dispatchCommand($,void 0),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeBlock",label:"InsertCodeBlock",onSelect:e=>{e.dispatchCommand(K,void 0),queueMicrotask(()=>{e.focus()})}},{icon:de,key:"meta2d",label:"Meta2d",onSelect:e=>{e.dispatchCommand(Y,void 0),queueMicrotask(()=>{e.focus()})}},{icon:me,key:"markmap",label:"Markmap",onSelect:e=>{e.dispatchCommand(G,void 0),queueMicrotask(()=>{e.focus()})}}].map(e=>e.type==="divider"?e:{...e,extra:o.jsx(oe,{code:!0,fontSize:12,type:"secondary",children:e.key})}),[]);return o.jsxs(ue,{json:m,markdown:p,onJSONChange:s,...h,children:[o.jsx(R,{editor:r}),o.jsx(T,{className:"mdocs-playground-editor",content:ye,editor:r,lineEmptyPlaceholder:"Start typing here...",mentionOption:{items:d,markdownWriter:t=>{var e;return`
|
|
3
|
-
<mention>${t.label}[${((e=t.metadata)==null?void 0:e.id)||t.label}]</mention>
|
|
4
|
-
`},onSelect:(t,e)=>{t.dispatchCommand(U,{label:String(e.label),metadata:{id:e.key}})},searchKeys:["label"]},onInit:x,onTextChange:c,pasteVSCodeAsCodeBlock:!0,placeholder:"Type something...",plugins:[I,E,M,j,O,P,A,_,D,L,f(H,{children:o.jsx(R,{editor:r,floating:!0})}),f(F,{delay:1e3,onAutoComplete:async({input:t,afterText:e,selectionType:l,abortSignal:u})=>{console.log("Auto-complete triggered:",{afterText:e,input:t,selectionType:l});try{const v=await fetch(`${location.origin}/nodeserver/completion`,{body:JSON.stringify({prompt:`Please complete the following text:
|
|
5
|
-
|
|
6
|
-
${t}`}),headers:{"Content-Type":"application/json"},method:"POST",signal:u});if(u.aborted)return console.log("Auto-complete aborted"),null;const i=await v.json();if(i)return typeof i.content=="string"&&i.content.startsWith(t)?i.content.replace(t,""):i.content}catch{}return null}}),f(M,{defaultBlockImage:!0,handleRehost:async t=>{const l=await(await fetch(t)).blob();return await new Promise((u,v)=>{const i=new FileReader;i.onloadend=()=>u({url:i.result}),i.onerror=v,i.readAsDataURL(l)})},needRehost:t=>(console.debug("needRehost",t),t.startsWith("blob:"))}),f(q,{handleUpload:async t=>(console.debug("Files uploaded:",t),new Promise(e=>{setTimeout(()=>{const l=URL.createObjectURL(t);a.current.push(l),e({url:l})},1e3)})),markdownWriter:t=>`
|
|
7
|
-
<file>${t.fileUrl}</file>
|
|
8
|
-
`})],slashOption:{items:w}})]})};function Ne(){return o.jsxs("div",{className:"mdocs-playground-page",children:[o.jsx("header",{className:"mdocs-playground-header",children:o.jsx(C,{className:"mdocs-playground-back",to:"/",children:"← mdocs"})}),o.jsx(pe,{})]})}export{Ne as PlaygroundPage};
|