@fgbg/mdocs 1.4.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-skills/changelog/SKILL.md +19 -0
- package/dist/server/agent/Agent/run-manager.js +1 -0
- package/dist/server/agent/Agent/run-manager.js.map +1 -1
- package/dist/server/agent/Agent/run-pi-agent.js +22 -7
- package/dist/server/agent/Agent/run-pi-agent.js.map +1 -1
- package/dist/server/agent/Agent/run.js +29 -4
- package/dist/server/agent/Agent/run.js.map +1 -1
- package/dist/server/agent/Agent/session-manager.js +45 -5
- package/dist/server/agent/Agent/session-manager.js.map +1 -1
- package/dist/server/agent/Agent/system-prompt.js +5 -3
- package/dist/server/agent/Agent/system-prompt.js.map +1 -1
- package/dist/server/agent/Agent/tools-documents.js +13 -4
- package/dist/server/agent/Agent/tools-documents.js.map +1 -1
- package/dist/server/agent/Agent/tools-registry.test.js +1 -1
- package/dist/server/agent/Agent/tools-registry.test.js.map +1 -1
- package/dist/server/agent/Agent/tools-template.js +2 -1
- package/dist/server/agent/Agent/tools-template.js.map +1 -1
- package/dist/server/agent/Config/config.test.js +21 -0
- package/dist/server/agent/Config/config.test.js.map +1 -1
- package/dist/server/agent/attachments/capabilities.js +52 -0
- package/dist/server/agent/attachments/capabilities.js.map +1 -0
- package/dist/server/agent/attachments/capabilities.test.js +33 -0
- package/dist/server/agent/attachments/capabilities.test.js.map +1 -0
- package/dist/server/agent/attachments/index.js +6 -0
- package/dist/server/agent/attachments/index.js.map +1 -0
- package/dist/server/agent/attachments/inject.js +67 -0
- package/dist/server/agent/attachments/inject.js.map +1 -0
- package/dist/server/agent/attachments/inject.test.js +41 -0
- package/dist/server/agent/attachments/inject.test.js.map +1 -0
- package/dist/server/agent/attachments/object-fs.js +44 -0
- package/dist/server/agent/attachments/object-fs.js.map +1 -0
- package/dist/server/agent/attachments/parse/image.js +22 -0
- package/dist/server/agent/attachments/parse/image.js.map +1 -0
- package/dist/server/agent/attachments/parse/pdf.js +19 -0
- package/dist/server/agent/attachments/parse/pdf.js.map +1 -0
- package/dist/server/agent/attachments/parse/plain-text.js +18 -0
- package/dist/server/agent/attachments/parse/plain-text.js.map +1 -0
- package/dist/server/agent/attachments/prepare-turn.js +32 -0
- package/dist/server/agent/attachments/prepare-turn.js.map +1 -0
- package/dist/server/agent/attachments/store.js +120 -0
- package/dist/server/agent/attachments/store.js.map +1 -0
- package/dist/server/agent/attachments/tools-read-attachment.js +95 -0
- package/dist/server/agent/attachments/tools-read-attachment.js.map +1 -0
- package/dist/server/agent/attachments/types.js +6 -0
- package/dist/server/agent/attachments/types.js.map +1 -0
- package/dist/server/agent/attachments/upload-filename.test.js +39 -0
- package/dist/server/agent/attachments/upload-filename.test.js.map +1 -0
- package/dist/server/agent/attachments/upload.js +11 -0
- package/dist/server/agent/attachments/upload.js.map +1 -0
- package/dist/server/app.js +9 -1
- package/dist/server/app.js.map +1 -1
- package/dist/server/config/index.js +1 -0
- package/dist/server/config/index.js.map +1 -1
- package/dist/server/db/repositories/agent-attachment.repo.js +51 -0
- package/dist/server/db/repositories/agent-attachment.repo.js.map +1 -0
- package/dist/server/db/repositories/document.repo.js +9 -9
- package/dist/server/db/repositories/document.repo.js.map +1 -1
- package/dist/server/db/schema.js +64 -3
- package/dist/server/db/schema.js.map +1 -1
- package/dist/server/documents/document.service.js +2 -3
- package/dist/server/documents/document.service.js.map +1 -1
- package/dist/server/documents/graph.integration.test.js +1 -0
- package/dist/server/documents/graph.integration.test.js.map +1 -1
- package/dist/server/documents/tree-and-folders.test.js +1 -0
- package/dist/server/documents/tree-and-folders.test.js.map +1 -1
- package/dist/server/domains/change-domain-permission.test.js +12 -0
- package/dist/server/domains/change-domain-permission.test.js.map +1 -1
- package/dist/server/routes/agent.routes.js +85 -2
- package/dist/server/routes/agent.routes.js.map +1 -1
- package/dist/server/routes/visitors.routes.js +2 -0
- package/dist/server/routes/visitors.routes.js.map +1 -1
- package/dist/server/search/document-index-manager.js +13 -4
- package/dist/server/search/document-index-manager.js.map +1 -1
- package/dist/server/search/document-index-manager.test.js +14 -3
- package/dist/server/search/document-index-manager.test.js.map +1 -1
- package/dist/server/search/embedding-store.js +9 -0
- package/dist/server/search/embedding-store.js.map +1 -1
- package/dist/server/search/embedding-store.test.js +27 -3
- package/dist/server/search/embedding-store.test.js.map +1 -1
- package/dist/shared/file-type-policy.js +1 -1
- package/dist/shared/file-type-policy.js.map +1 -1
- package/dist/shared/file-type-policy.test.js +2 -1
- package/dist/shared/file-type-policy.test.js.map +1 -1
- package/dist/web/assets/AgentChatPanel-Bhv57WUW.js +47 -0
- package/dist/web/assets/{AiWriteWorkbench-ob4AeDFt.js → AiWriteWorkbench-DOse9-oQ.js} +4 -4
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-BuZCaqLT.js → DiagramEditor-NtNY3sZL-D7sapmVz.js} +1 -1
- package/dist/web/assets/{DocChrome-DwSYxHOP.js → DocChrome-Dj5rSAvl.js} +1 -1
- package/dist/web/assets/{DocumentEditor-C_TFaCan.js → DocumentEditor-BTxsH3UT.js} +1 -1
- package/dist/web/assets/{HtmlEditor-CYPTi1_L.js → HtmlEditor-OEfTnjjz.js} +1 -1
- package/dist/web/assets/MergeView-CGz2CWUZ.js +10 -0
- package/dist/web/assets/{PlaygroundPage-Bt53Sr06.js → PlaygroundPage-BsekHU2o.js} +1 -1
- package/dist/web/assets/{SettingsPage-C2SYz-8K.js → SettingsPage-cVFmyADe.js} +5 -5
- package/dist/web/assets/SheetEditor-1LMR2jA1.js +26 -0
- package/dist/web/assets/SheetEditor-DJOs2u-u.css +1 -0
- package/dist/web/assets/{Toolbar-LRioFemr.js → Toolbar-CPIpQgP1.js} +1 -1
- package/dist/web/assets/VisitorPickerModal-aRuuDomz.js +6 -0
- package/dist/web/assets/{check-65pb-o1o.js → check-NyVbPIj8.js} +1 -1
- package/dist/web/assets/{copy-BT35-MU9.js → copy-C_H9wgwB.js} +1 -1
- package/dist/web/assets/file-type-policy-5jFXMeIz.js +1 -0
- package/dist/web/assets/index-CervldVc.css +1 -0
- package/dist/web/assets/{index-92xZ1zjh.js → index-Kp5r4mc7.js} +48 -48
- package/dist/web/assets/{italic-BmGXEOKX.js → italic-BqrahN0G.js} +1 -1
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-DeIPntMM.js → meta2dEngine-BD2XbzaV-CUKxedXW.js} +1 -1
- package/dist/web/assets/{plus-Ss1czARp.js → plus-D8tCpRfA.js} +1 -1
- package/dist/web/assets/{react-DHtvOuT-.js → react-DsdrF7vh.js} +3 -3
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/AgentChatPanel-BMOzVvwA.js +0 -42
- package/dist/web/assets/MergeView-FPF3k11v.js +0 -10
- package/dist/web/assets/SheetEditor-BOF-OgqU.js +0 -26
- package/dist/web/assets/SheetEditor-BPTMQ2s5.css +0 -1
- package/dist/web/assets/VisitorPickerModal-iK2QsYfY.js +0 -6
- package/dist/web/assets/file-type-policy-aRrzC4LZ.js +0 -1
- package/dist/web/assets/index-DE_nAopH.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-type-policy.js","sourceRoot":"","sources":["../../src/shared/file-type-policy.ts"],"names":[],"mappings":"AA8CA,mCAAmC;AAEnC,MAAM,YAAY,GAAqC;IACrD,EAAE,EAAE;QACF,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;QAClB,eAAe,EAAE,KAAK;QACtB,OAAO,EAAE,KAAK;QACd,WAAW,EAAE,SAAS;QACtB,cAAc,EAAE,YAAY;QAC5B,SAAS,EAAE,SAAS;QACpB,aAAa,EAAE,mBAAmB;QAClC,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf;IACD,IAAI,EAAE;QACJ,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,KAAK;QACnB,eAAe,EAAE,KAAK;QACtB,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,KAAK;QAClB,cAAc,EAAE,KAAK;QACrB,SAAS,EAAE,MAAM;QACjB,aAAa,EAAE,UAAU;QACzB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf;IACD,KAAK,EAAE;QACL,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,KAAK;QACnB,eAAe,EAAE,KAAK;QACtB,OAAO,EAAE,QAAQ;QACjB,WAAW,EAAE,KAAK;QAClB,cAAc,EAAE,KAAK;QACrB,SAAS,EAAE,OAAO;QAClB,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"file-type-policy.js","sourceRoot":"","sources":["../../src/shared/file-type-policy.ts"],"names":[],"mappings":"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"}
|
|
@@ -37,7 +37,7 @@ describe("file-type-policy", () => {
|
|
|
37
37
|
FILE_TYPE.SHEET,
|
|
38
38
|
]);
|
|
39
39
|
});
|
|
40
|
-
it("sheet:可见、可移动;aiWrite 关;.sheet +
|
|
40
|
+
it("sheet:可见、可移动;aiWrite 关;.sheet + whole-document merge", () => {
|
|
41
41
|
const p = getPolicy(FILE_TYPE.SHEET);
|
|
42
42
|
expect(p.treeVisible).toBe(true);
|
|
43
43
|
expect(p.movable).toBe(true);
|
|
@@ -45,6 +45,7 @@ describe("file-type-policy", () => {
|
|
|
45
45
|
expect(p.ftsIndex).toBe(true);
|
|
46
46
|
expect(p.writeNormalize).toBe("raw");
|
|
47
47
|
expect(p.draftKind).toBe("sheet");
|
|
48
|
+
expect(p.mergePipeline).toBe("whole-document");
|
|
48
49
|
expect(p.aiWrite).toBe(false);
|
|
49
50
|
expect(p.comments).toBe(true);
|
|
50
51
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-type-policy.test.js","sourceRoot":"","sources":["../../src/shared/file-type-policy.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACzC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9B,MAAM,CAAE,CAA0B,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACxC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9B,MAAM,CAAE,CAA0B,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QACvE,MAAM,CAAC,qBAAqB,EAAE,CAAC,CAAC,OAAO,CAAC;YACtC,SAAS,CAAC,QAAQ;YAClB,SAAS,CAAC,MAAM;YAChB,SAAS,CAAC,WAAW;SACtB,CAAC,CAAC;QACH,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACrD,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACtD,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC;YAChC,SAAS,CAAC,QAAQ;YAClB,SAAS,CAAC,IAAI;YACd,SAAS,CAAC,KAAK;SAChB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"file-type-policy.test.js","sourceRoot":"","sources":["../../src/shared/file-type-policy.test.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diagram-BF8g9yg4.js","assets/ui-CEFkTVnG.js","assets/react-vendor-BVS1XoFi.js","assets/motion-BAXVQJfN.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as o,j as e,_ as Tn,b as Qt}from"./react-vendor-BVS1XoFi.js";import{o as B,aw as Fn,aS as Pn,aT as en,aU as qn,N as tn,C as Wn,aV as nn,X as me,aW as Un,aX as qt,aY as On,aZ as Bn,a_ as ue,_ as Wt,a$ as Ut,b0 as Ot,b1 as _e,b2 as Je,b3 as Hn,b4 as Xn,b5 as Kn,b6 as Bt,b7 as Gn,b8 as sn,b9 as Yn,ba as Vn,bb as Zn,bc as Jn,bd as Qn,be as es}from"./index-Kp5r4mc7.js";import{C as an}from"./check-NyVbPIj8.js";import{C as rn,a as nt}from"./copy-C_H9wgwB.js";import{P as Ht}from"./plus-D8tCpRfA.js";import{ar as ts,ah as ns}from"./ui-CEFkTVnG.js";import"./diagram-BF8g9yg4.js";import"./motion-BAXVQJfN.js";/**
|
|
3
|
+
* @license lucide-react v0.562.0 - ISC
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the ISC license.
|
|
6
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/const ss=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],as=B("arrow-down",ss);/**
|
|
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 rs=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],is=B("history",rs);/**
|
|
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 os=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],on=B("link-2",os);/**
|
|
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 ls=[["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"}]],cs=B("maximize-2",ls);/**
|
|
23
|
+
* @license lucide-react v0.562.0 - ISC
|
|
24
|
+
*
|
|
25
|
+
* This source code is licensed under the ISC license.
|
|
26
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
27
|
+
*/const ds=[["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"}]],us=B("minimize-2",ds);/**
|
|
28
|
+
* @license lucide-react v0.562.0 - ISC
|
|
29
|
+
*
|
|
30
|
+
* This source code is licensed under the ISC license.
|
|
31
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
32
|
+
*/const ms=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],fs=B("pencil",ms);/**
|
|
33
|
+
* @license lucide-react v0.562.0 - ISC
|
|
34
|
+
*
|
|
35
|
+
* This source code is licensed under the ISC license.
|
|
36
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
37
|
+
*/const ps=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]],hs=B("pin",ps);/**
|
|
38
|
+
* @license lucide-react v0.562.0 - ISC
|
|
39
|
+
*
|
|
40
|
+
* This source code is licensed under the ISC license.
|
|
41
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
42
|
+
*/const gs=[["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"}]],xs=B("zoom-in",gs);/**
|
|
43
|
+
* @license lucide-react v0.562.0 - ISC
|
|
44
|
+
*
|
|
45
|
+
* This source code is licensed under the ISC license.
|
|
46
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
47
|
+
*/const ys=[["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"}]],js=B("zoom-out",ys),bs={"image/png":".png","image/jpeg":".jpg","image/jpg":".jpg","image/webp":".webp","image/gif":".gif","text/plain":".txt","text/markdown":".md","text/csv":".csv","application/json":".json","application/pdf":".pdf"};function ks(n,s=new Date){const i=n.name.trim();if(i&&/\.[A-Za-z0-9]{1,8}$/.test(i))return n;const c=bs[n.type]??"";if(!c)return n;const f=String(s.getHours()).padStart(2,"0"),p=String(s.getMinutes()).padStart(2,"0"),x=String(s.getSeconds()).padStart(2,"0"),b=i.replace(/\.+$/,"")||`paste-${f}${p}${x}`;return new File([n],`${b}${c}`,{type:n.type})}function vs(n,s){if(!s.has(n))return n;const i=n.lastIndexOf("."),c=i>0?n.slice(0,i):n,f=i>0?n.slice(i):"";let p=1,x=`${c}_${p}${f}`;for(;s.has(x);)p+=1,x=`${c}_${p}${f}`;return x}function Ns(n,s,i=new Date){const c=new Set(s);return n.map(f=>{const p=ks(f,i),x=vs(p.name,c);return c.add(x),x===p.name?p:new File([p],x,{type:p.type})})}function ws(n){return n?Array.from(n.types).includes("Files"):!1}function Xt(n){if(!n)return[];if(n.files.length>0)return Array.from(n.files);const s=[],i=n.items;if(!i)return s;for(let c=0;c<i.length;c++){const f=i[c];if(!f||f.kind!=="file")continue;const p=f.getAsFile();p&&s.push(p)}return s}const Ss=/(?:^|#\/|\/)doc\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/?$/i;function Cs(n){var c;if(!n)return null;const s=n.trim();let i=s;if(s.startsWith("http://")||s.startsWith("https://"))try{const f=new URL(s);i=`${f.pathname}${f.hash}`}catch{i=s}return((c=i.match(Ss))==null?void 0:c[1])??null}const As={image:"IMG",pdf:"PDF",md:"MD",txt:"TXT",csv:"CSV",json:"JSON",html:"HTM",sheet:"SHT",file:"FILE"};function Is(n){return As[n]}function ln(n,s=""){var f;const i=s.toLowerCase(),c=((f=n.toLowerCase().match(/\.([a-z0-9]+)$/))==null?void 0:f[1])??"";return i.startsWith("image/")||["png","jpg","jpeg","webp","gif"].includes(c)?"image":i==="application/pdf"||c==="pdf"?"pdf":i==="text/markdown"||c==="md"||c==="markdown"?"md":i==="text/csv"||c==="csv"?"csv":i==="application/json"||c==="json"?"json":i==="text/plain"||c==="txt"?"txt":i==="text/html"||c==="html"||c==="htm"?"html":c==="sheet"?"sheet":"file"}const Qe=5;function Rs(n){const s=o.useRef(!0),i=o.useRef(null),[c,f]=o.useState([]),[p,x]=o.useState(!1),[b,I]=o.useState(null);o.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),o.useEffect(()=>{(async()=>{try{const h=await Fn();if(!s.current)return;f(h)}catch(h){if(!s.current)return;I(h instanceof Error?h.message:String(h))}})()},[]),o.useEffect(()=>{if(!p)return;function h(j){const C=i.current;!C||C.contains(j.target)||x(!1)}function m(j){j.key==="Escape"&&x(!1)}return document.addEventListener("mousedown",h),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",m)}},[p]);const y=c.filter(h=>n.selectedNames.includes(h.name));function R(h){if(n.disabled)return;const m=new Set(n.selectedNames);if(m.has(h))m.delete(h);else{if(m.size>=Qe)return;m.add(h)}n.onChange([...m])}return c.length===0&&!b?null:e.jsxs("div",{className:"mdocs-agent-skill-ref",ref:i,children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-bar",children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-anchor",children:[p&&c.length>0?e.jsxs("div",{className:"mdocs-agent-skill-popover",role:"listbox","aria-label":"选择 Skill",children:[e.jsxs("div",{className:"mdocs-agent-skill-popover-hint",children:["选择要引用的 Skill(最多 ",Qe," 个)"]}),e.jsx("ul",{className:"mdocs-agent-skill-popover-list",children:c.map(h=>{const m=n.selectedNames.includes(h.name),j=!m&&n.selectedNames.length>=Qe;return e.jsx("li",{children:e.jsxs("button",{type:"button",role:"option","aria-selected":m,className:"mdocs-agent-skill-popover-item"+(m?" mdocs-agent-skill-popover-item-on":""),disabled:n.disabled||j,onClick:()=>R(h.name),children:[e.jsx("span",{className:"mdocs-agent-skill-popover-check","aria-hidden":!0,children:m?"✓":""}),e.jsxs("span",{className:"mdocs-agent-skill-popover-text",children:[e.jsx("span",{className:"mdocs-agent-skill-popover-name",children:h.name}),h.description?e.jsx("span",{className:"mdocs-agent-skill-popover-desc",children:h.description}):e.jsx("span",{className:"mdocs-agent-skill-popover-desc mdocs-agent-skill-popover-desc-muted",children:"无简介"})]})]})},h.id)})})]}):null,e.jsxs("button",{type:"button",className:"mdocs-agent-skill-ref-toggle"+(p?" mdocs-agent-skill-ref-toggle-open":""),disabled:n.disabled||c.length===0,onClick:()=>x(h=>!h),"aria-expanded":p,"aria-haspopup":"listbox",title:"引用 Skill",children:["Skill",y.length>0?` · ${y.length}`:""]})]}),y.map(h=>e.jsxs("button",{type:"button",className:"mdocs-agent-skill-chip mdocs-agent-skill-chip-on",disabled:n.disabled,onClick:()=>R(h.name),title:"移除引用",children:[h.name,e.jsx("span",{"aria-hidden":!0,children:" ×"})]},h.name))]}),b?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:b}):null]})}const _s=/^[A-Za-z0-9_]+$/;function Es(n){const{block:s,onResolved:i}=n,[c,f]=o.useState(s.initialName),[p,x]=o.useState(s.initialDescription),[b,I]=o.useState(s.initialBody),[y,R]=o.useState(!1),[h,m]=o.useState(null),[j,C]=o.useState(1),L=o.useRef(!1),N=o.useRef(i);N.current=i;const S=s.status==="open",q=o.useRef(0);o.useEffect(()=>{if(!S)return;L.current=!1;const E=new Date(s.expiresAt).getTime(),De=Date.now(),fe=Math.max(E-De,1);q.current=fe,C(1);const ne=()=>{const re=E-Date.now(),W=Math.max(0,Math.min(1,re/fe));C(W),re<=0&&!L.current&&(L.current=!0,Pn(s.requestId).catch(()=>{}).finally(()=>{N.current(s.requestId,"expired")}))};ne();const pe=window.setInterval(ne,100);return()=>window.clearInterval(pe)},[S,s.expiresAt,s.requestId]);async function T(){if(y||!S)return;const E=c.trim();if(!E){m("名称不能为空");return}if(!_s.test(E)){m("名称仅允许英文、数字、下划线");return}if(!b.trim()){m("正文不能为空");return}R(!0),m(null);try{await qn(s.requestId,{name:E,description:p.trim(),body:b}),i(s.requestId,"submitted",E)}catch{i(s.requestId,"failed")}finally{R(!1)}}async function O(){if(!(y||!S)){R(!0),m(null),L.current=!0;try{await en(s.requestId),i(s.requestId,"cancelled")}catch{i(s.requestId,"failed")}finally{R(!1)}}}const M=Math.max(0,Math.ceil(j*q.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card mdocs-agent-skill-form-card"+(S?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),S?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[M,"s"]}):null]}),S?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(j*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${j})`}})}):null,s.status==="submitted"?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已提交",s.submittedName?`:${s.submittedName}`:""]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,表单已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,S?e.jsxs("div",{className:"mdocs-agent-skill-form-fields",children:[e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"名称(英文数字下划线)"}),e.jsx("input",{type:"text",value:c,onChange:E=>f(E.target.value),maxLength:64,disabled:y,autoComplete:"off",spellCheck:!1})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"简介"}),e.jsx("input",{type:"text",value:p,onChange:E=>x(E.target.value),maxLength:200,disabled:y})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:b,onChange:E=>I(E.target.value),rows:8,disabled:y})]}),h?e.jsx("p",{className:"mdocs-agent-skill-form-error",children:h}):null,e.jsxs("div",{className:"mdocs-agent-skill-form-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-skill-form-cancel",disabled:y,onClick:()=>void O(),children:"取消"}),e.jsx("button",{type:"button",disabled:y,onClick:()=>void T(),children:y?"提交中…":s.mode==="create"?"创建":"保存"})]})]}):null]})}function st(n){var s;return n==null||typeof n=="boolean"?"":typeof n=="string"||typeof n=="number"?String(n):Array.isArray(n)?n.map(st).join(""):typeof n=="object"&&"props"in n?st((s=n.props)==null?void 0:s.children):""}function Ms(n){return n?/\blanguage-mermaid\b|\bmermaid\b/i.test(n):!1}function Ds(n){const s=Array.isArray(n)?n:[n];for(const i of s){if(i==null||typeof i!="object"||!("props"in i))continue;const c=i.props;if(!(!c||!Ms(c.className)))return st(c.children).replace(/\n$/,"")}return null}const $s=.4,zs=4,Ee=.2;let et=null;function Ls(){return et||(et=Tn(()=>import("./diagram-BF8g9yg4.js").then(n=>n.z),__vite__mapDeps([0,1,2,3])).then(n=>{const s=n.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral",fontFamily:"ui-sans-serif, system-ui, sans-serif"}),s})),et}const Ts=32,te=new Map;function Kt(n){return te.get(n)??null}function Fs(n,s){for(te.has(n)&&te.delete(n),te.set(n,s);te.size>Ts;){const i=te.keys().next().value;if(i==null)break;te.delete(i)}}function tt(n){return Math.min(zs,Math.max($s,n))}function Ps(n){const[s,i]=o.useState(1),[c,f]=o.useState({x:0,y:0}),p=o.useRef(null),[x,b]=o.useState(!1);o.useEffect(()=>{const m=C=>{C.key==="Escape"&&n.onClose()};window.addEventListener("keydown",m);const j=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",m),document.body.style.overflow=j}},[n.onClose]);function I(m){m.button===0&&(m.currentTarget.setPointerCapture(m.pointerId),p.current={pointerId:m.pointerId,startX:m.clientX,startY:m.clientY,originX:c.x,originY:c.y},b(!0))}function y(m){const j=p.current;!j||j.pointerId!==m.pointerId||f({x:j.originX+(m.clientX-j.startX),y:j.originY+(m.clientY-j.startY)})}function R(m){const j=p.current;if(!(!j||j.pointerId!==m.pointerId)){p.current=null,b(!1);try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}}}function h(m){m.preventDefault();const j=m.deltaY>0?-Ee:Ee;i(C=>tt(Number((C+j).toFixed(2))))}return Qt.createPortal(e.jsxs("div",{className:"mdocs-agent-mermaid-float",role:"dialog","aria-modal":"true","aria-label":"Mermaid 图预览",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-backdrop","aria-label":"关闭预览",onClick:n.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:()=>i(m=>tt(Number((m-Ee).toFixed(2)))),title:"缩小","aria-label":"缩小",children:e.jsx(js,{size:16,"aria-hidden":!0})}),e.jsxs("span",{className:"mdocs-agent-mermaid-float-scale",children:[Math.round(s*100),"%"]}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>i(m=>tt(Number((m+Ee).toFixed(2)))),title:"放大","aria-label":"放大",children:e.jsx(xs,{size:16,"aria-hidden":!0})}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>{i(1),f({x:0,y:0})},title:"重置",children:"重置"}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:n.onClose,title:"关闭","aria-label":"关闭",children:e.jsx(me,{size:16,"aria-hidden":!0})})]}),e.jsx("div",{className:x?"mdocs-agent-mermaid-float-stage is-dragging":"mdocs-agent-mermaid-float-stage",onPointerDown:I,onPointerMove:y,onPointerUp:R,onPointerCancel:R,onWheel:h,children:e.jsx("div",{className:"mdocs-agent-mermaid-float-canvas",style:{transform:`translate(calc(-50% + ${c.x}px), calc(-50% + ${c.y}px)) scale(${s})`},dangerouslySetInnerHTML:{__html:n.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function qs(n){const s=o.useId().replace(/:/g,""),[i,c]=o.useState("diagram"),[f,p]=o.useState(()=>Kt(n.source.trim())),[x,b]=o.useState(null),[I,y]=o.useState(!1),[R,h]=o.useState(!1),m=o.useRef(null),j=n.source.trim(),C=o.useMemo(()=>j,[j]);o.useEffect(()=>()=>{m.current!=null&&window.clearTimeout(m.current)},[]),o.useEffect(()=>{if(i!=="diagram")return;if(!C){p(null),b(null);return}const N=Kt(C);if(N){p(N),b(null);return}let S=!1;const q=window.setTimeout(()=>{(async()=>{try{const T=await Ls();if(S)return;const O=`mdocs-agent-mmd-${s}-${Date.now()}`,{svg:M}=await T.render(O,C);if(S)return;Fs(C,M),p(M),b(null)}catch(T){if(S)return;p(null),b(T instanceof Error?T.message:"Mermaid 渲染失败")}})()},200);return()=>{S=!0,window.clearTimeout(q)}},[i,C,s]);async function L(){!j||!await nn(j)||(y(!0),m.current!=null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>y(!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:i==="diagram"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("diagram"),"aria-pressed":i==="diagram",title:"图谱",children:[e.jsx(tn,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"图谱"})]}),e.jsxs("button",{type:"button",className:i==="code"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("code"),"aria-pressed":i==="code",title:"代码",children:[e.jsx(Wn,{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 L(),"aria-label":I?"已复制":"复制代码",title:I?"已复制":"复制",children:I?e.jsx(an,{size:14,"aria-hidden":!0}):e.jsx(rn,{size:14,"aria-hidden":!0})})]}),i==="diagram"?e.jsx("div",{className:"mdocs-agent-mermaid-diagram",children:x?e.jsxs("div",{className:"mdocs-agent-mermaid-error",role:"alert",children:[e.jsx("p",{children:"无法渲染该图,可切换到代码查看源码。"}),e.jsx("pre",{children:x})]}):f?e.jsx("div",{className:"mdocs-agent-mermaid-svg mdocs-agent-mermaid-svg-hit",role:"button",tabIndex:0,onClick:()=>h(!0),onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),h(!0))},title:"点击放大预览","aria-label":"点击放大预览 Mermaid 图",children:e.jsx("span",{className:"mdocs-agent-mermaid-svg-inner",dangerouslySetInnerHTML:{__html:f}})}):e.jsx("div",{className:"mdocs-agent-mermaid-loading",children:"渲染中…"})}):e.jsx("div",{className:"mdocs-agent-panel-md-pre-wrap mdocs-agent-mermaid-code",children:e.jsx("pre",{children:n.codeChildren??e.jsx("code",{className:"language-mermaid",children:j})})}),R&&f?e.jsx(Ps,{svg:f,onClose:()=>h(!1)}):null]})}const Ws=o.memo(qs,(n,s)=>n.source===s.source);function Us(n){const[s,i]=o.useState(()=>Date.now());return o.useEffect(()=>{if(!n)return;const c=window.setInterval(()=>i(Date.now()),1e3);return()=>window.clearInterval(c)},[n]),s}function Os(n,s){if(!n.startedAt)return null;const i=n.endedAt??s;return Math.max(1,Math.round((i-n.startedAt)/1e3))}function Me(n,s=Date.now()){let i=!1;const c=n.map(f=>f.type==="thinking"&&f.startedAt&&!f.endedAt?(i=!0,{...f,endedAt:s}):f);return i?c:n}function Bs(n){const{block:s,live:i,now:c}=n;if(!s.text)return null;const f=Os(s,c),p=f!=null?i?`思考中 ${f}s`:`思考 ${f}s`:"思考";return e.jsxs("details",{className:"mdocs-agent-panel-think-fold",children:[e.jsxs("summary",{children:[e.jsx("span",{className:"mdocs-agent-think-label"+(i?" live":""),children:p}),e.jsx(nt,{size:14,strokeWidth:1.8,className:"mdocs-agent-think-chevron"})]}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:s.text})]})}function at(n){var s;return n==null||typeof n=="boolean"?"":typeof n=="string"||typeof n=="number"?String(n):Array.isArray(n)?n.map(at).join(""):typeof n=="object"&&"props"in n?at((s=n.props)==null?void 0:s.children):""}function Hs(n){const[s,i]=o.useState(!1),c=o.useRef(null),f=o.useRef(null),p=at(n.children).replace(/\n$/,"");o.useEffect(()=>()=>{c.current!=null&&window.clearTimeout(c.current)},[]);async function x(b){var h,m,j;b.preventDefault(),b.stopPropagation();const y=(((j=(m=(h=f.current)==null?void 0:h.querySelector("pre"))==null?void 0:m.innerText)==null?void 0:j.replace(/\n$/,""))??"")||p;!y||!await nn(y)||(i(!0),c.current!=null&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>i(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-panel-md-pre-wrap",ref:f,children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy",onClick:b=>void x(b),"aria-label":s?"已复制":"复制代码",title:s?"已复制":"复制",children:s?e.jsx(an,{size:14,"aria-hidden":!0}):e.jsx(rn,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:n.children})]})}function Xs(n){const s=Ds(n.children);return s!=null?e.jsx(Ws,{source:s,codeChildren:n.children}):e.jsx(Hs,{children:n.children})}const cn={current:()=>{}};function dn(n){return typeof n=="string"||typeof n=="number"?String(n):Array.isArray(n)?n.map(dn).join(""):""}function un(n){const s=ln(n.name,n.mime??"");return n.inline&&s==="file"?null:e.jsx("span",{className:"mdocs-agent-file-mark mdocs-agent-file-mark-"+s+(n.inline?" is-inline":""),"aria-hidden":!0,children:Is(s)})}function Ks(n){return o.useEffect(()=>{function s(i){i.key==="Escape"&&n.onClose()}return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n.onClose]),Qt.createPortal(e.jsxs("div",{className:"mdocs-agent-image-preview",role:"dialog","aria-modal":"true","aria-label":n.name,children:[e.jsx("button",{type:"button",className:"mdocs-agent-image-preview-backdrop","aria-label":"关闭预览",onClick:n.onClose}),e.jsxs("div",{className:"mdocs-agent-image-preview-frame",children:[e.jsx("button",{type:"button",className:"mdocs-agent-image-preview-close","aria-label":"关闭",onClick:n.onClose,children:e.jsx(me,{size:16,"aria-hidden":!0})}),e.jsx("img",{src:n.src,alt:n.name}),e.jsx("p",{children:n.name})]})]}),document.body)}function Gt(n){const[s,i]=o.useState(!1),[c,f]=o.useState(!1),x=ln(n.name,n.mime)==="image"&&!s?n.previewUrl||`/api/agent/attachments/${n.id}`:"";return e.jsxs("span",{className:"mdocs-agent-msg-asset-chip"+(x?" has-thumb":""),title:n.name,children:[x?e.jsx("button",{type:"button",className:"mdocs-agent-file-thumb-btn","aria-label":`预览 ${n.name}`,title:"点击查看大图",onClick:()=>f(!0),children:e.jsx("img",{className:"mdocs-agent-file-thumb",src:x,alt:"",onError:()=>i(!0)})}):e.jsx(un,{name:n.name,mime:n.mime}),e.jsx("span",{className:"mdocs-agent-msg-asset-chip-name",children:n.name}),n.onRemove?e.jsx("button",{type:"button",className:"mdocs-agent-pending-asset-remove","aria-label":`移除 ${n.name}`,disabled:n.removeDisabled,onClick:n.onRemove,children:e.jsx(me,{size:12,"aria-hidden":!0})}):null,c&&x?e.jsx(Ks,{src:x,name:n.name,onClose:()=>f(!1)}):null]})}function Gs(n){var f,p;const s=Cs(n.href),i=dn(n.children),c=i?e.jsx(un,{name:i,inline:!0}):null;if(!s){const x=((f=n.href)==null?void 0:f.startsWith("http://"))||((p=n.href)==null?void 0:p.startsWith("https://"));return e.jsxs("a",{href:n.href,...x?{target:"_blank",rel:"noreferrer"}:{},children:[c,n.children]})}return e.jsxs("a",{href:`#/doc/${s}`,className:"mdocs-agent-panel-doc-link",onClick:x=>{x.preventDefault(),cn.current(s)},children:[c,n.children]})}const Ys={pre:({children:n})=>e.jsx(Xs,{children:n}),a:Gs},Yt=o.memo(function(s){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(ts,{remarkPlugins:[ns],components:Ys,children:s.children})})}),Vs=["如何发布文档?","草稿是什么?","如何创建工作空间?"],Zs=["润色当前文稿","补写开头引言","把这段改得更简洁"];function Vt(n,s){return s.map((i,c)=>{const f=i.skillNames&&i.skillNames.length>0?i.skillNames:i.skillIds&&i.skillIds.length>0?i.skillIds:void 0;return{id:`h-${n}-${c}-${i.role}`,role:i.role,content:i.content,skillNames:f,assets:i.assets&&i.assets.length>0?i.assets:void 0}})}function Js(n,s){const i=Me(n).slice(),c=i[i.length-1];return(c==null?void 0:c.type)==="text"?i[i.length-1]={type:"text",text:c.text+s}:i.push({type:"text",text:s}),i}function Qs(n,s){const i=Date.now(),c=n.slice(),f=c[c.length-1];return(f==null?void 0:f.type)==="thinking"&&!f.endedAt?c[c.length-1]={type:"thinking",text:f.text+s,startedAt:f.startedAt??i}:c.push({type:"thinking",text:s,startedAt:i}),c}function ea(n,s){const i=Me(n).slice(),c=i.findIndex(f=>f.type==="tool_call"&&f.toolCallId===s.toolCallId);if(c>=0){const f=i[c];i[c]={...f,...s,detail:s.detail??f.detail}}else i.push(s);return i}function Zt(n){return n!=null&&n.length?n.filter(s=>s.type==="text").map(s=>s.text).join(""):""}function ta(n){return!!(n!=null&&n.some(s=>s.type==="thinking"&&s.text.length>0))}function na(n){const s=new Date(n);if(Number.isNaN(s.getTime()))return"";const i=new Date;return s.getFullYear()===i.getFullYear()&&s.getMonth()===i.getMonth()&&s.getDate()===i.getDate()?s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function Jt(n){if(n>=1e3){const s=n/1e3;return`${s>=10?Math.round(s):Math.round(s*10)/10}K`}return String(n)}function sa(n){const{block:s,onResolved:i}=n,[c,f]=o.useState(""),[p,x]=o.useState(!1),[b,I]=o.useState(1),y=o.useRef(!1),R=o.useRef(i);R.current=i;const h=s.status==="open",m=o.useRef(0);o.useEffect(()=>{if(!h)return;y.current=!1;const N=new Date(s.expiresAt).getTime(),S=Date.now(),q=Math.max(N-S,1);m.current=q,I(1);const T=()=>{const M=N-Date.now(),E=Math.max(0,Math.min(1,M/q));I(E),M<=0&&!y.current&&(y.current=!0,Qn(s.requestId).catch(()=>{}).finally(()=>{R.current(s.requestId,"","expired")}))};T();const O=window.setInterval(T,100);return()=>window.clearInterval(O)},[h,s.expiresAt,s.requestId]);async function j(N){const S=N.trim();if(!(!S||p||!h)){x(!0);try{await es(s.requestId,S),i(s.requestId,S,"selected")}catch{i(s.requestId,S,"failed")}finally{x(!1)}}}async function C(){if(!(p||!h)){x(!0),y.current=!0;try{await sn(s.requestId),i(s.requestId,"","cancelled")}catch{i(s.requestId,"","failed")}finally{x(!1)}}}const L=Math.max(0,Math.ceil(b*m.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(h?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),h?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[L,"s"]}):null]}),h?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(b*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${b})`}})}):null,s.status==="selected"&&s.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",s.selected]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,h?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:s.options.map(N=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:p,onClick:()=>void j(N),children:N},N))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:c,disabled:p,placeholder:"或输入自己的内容…",onChange:N=>f(N.target.value),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),j(c))}}),e.jsx("button",{type:"button",disabled:p||!c.trim(),onClick:()=>void j(c),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:p,onClick:()=>void C(),children:"取消"})})]}):null]})}function aa(n){const f=2*Math.PI*8.75,p=Math.min(100,Math.max(0,n.percent)),x=f*(1-p/100),b=p>=90?"danger":p>=70?"warn":"ok",I=`上下文 ${p}% · 已用 ${Jt(n.used)} / ${Jt(n.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+b,"data-tooltip":I,"aria-label":I,role:"img",tabIndex:0,children:e.jsxs("svg",{width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,children:[e.jsx("circle",{className:"mdocs-agent-panel-context-track",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5}),e.jsx("circle",{className:"mdocs-agent-panel-context-value",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:f,strokeDashoffset:x,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function ra(n){const s=n.item.variant==="graph"?tn:on;return e.jsxs("div",{className:"mdocs-agent-page-chip",title:n.item.title,children:[e.jsx(s,{className:"mdocs-agent-page-chip-icon"+(n.item.variant==="graph"?" mdocs-agent-page-chip-icon-graph":""),size:14,strokeWidth:2,"aria-hidden":!0}),e.jsxs("span",{className:"mdocs-agent-page-chip-text",children:[e.jsx("span",{className:"mdocs-agent-page-chip-kind",children:n.item.kind}),e.jsx("span",{className:"mdocs-agent-page-chip-dot","aria-hidden":!0,children:"·"}),e.jsx("span",{className:"mdocs-agent-page-chip-name",children:n.item.name})]}),e.jsx("button",{type:"button",className:"mdocs-agent-page-chip-x",title:"取消引用","aria-label":`取消引用 ${n.item.name}`,disabled:n.disabled,onClick:n.onDismiss,children:e.jsx(me,{size:14,strokeWidth:2,"aria-hidden":!0})})]})}function ia(n){var s;for(const i of n)if(!(i.role!=="assistant"||!((s=i.blocks)!=null&&s.length))){for(const c of i.blocks)if((c.type==="choice_card"||c.type==="skill_form_card")&&c.status==="open")return!0}return!1}const ha=o.forwardRef(function(s,i){const{open:c,onClose:f,visitorName:p,anchorStyle:x,fullscreen:b,onToggleFullscreen:I,domainId:y,domains:R=[],localizeDomainName:h,documentId:m,documentTitle:j,documentPath:C,graphFileId:L,graphLabel:N,onOpenDocument:S,onTreeChanged:q,onDocumentOverwritten:T,onOpenCoding:O,embedded:M=!1,mode:E="normal",workingMarkdown:De,baseMarkdown:fe,onMarkdownSet:ne,onSendingChange:pe,onSessionId:re}=s,W=E==="coding"?"coding":"normal",D=W==="coding",mn=((p==null?void 0:p.trim().charAt(0))||"我").toUpperCase(),[se,H]=o.useState(!1),[Y,rt]=o.useState("current"),[it,fn]=o.useState({}),[pn,ie]=o.useState(null),[ot,lt]=o.useState(""),[k,he]=o.useState(null),[hn,ge]=o.useState(null),[X,A]=o.useState([]),[V,ae]=o.useState(null),[xe,ct]=o.useState([]),[gn,dt]=o.useState(!1),[oe,ye]=o.useState(""),[le,$e]=o.useState([]),[Z,ze]=o.useState([]),ut=o.useRef([]);o.useEffect(()=>{const t=ut.current;return()=>{for(const a of t)URL.revokeObjectURL(a)}},[]);const[mt,ft]=o.useState(!1),[pt,Le]=o.useState(!1),je=o.useRef(null),ht=o.useRef(null),[gt,xt]=o.useState(!1),[Te,yt]=o.useState(!1),[ce,xn]=o.useState(Un),[jt,bt]=o.useState(null),Fe=o.useRef(ce);Fe.current=ce;const be=o.useRef(null),[w,K]=o.useState(!1),[kt,$]=o.useState(null),[ke,vt]=o.useState(null),[Pe,J]=o.useState(!1),[G,Nt]=o.useState(!1),wt=o.useRef(null),ve=o.useRef(null),z=o.useRef(null),F=o.useRef(null),Ne=o.useRef(null),St=o.useRef(0),Q=o.useRef(!0),[yn,qe]=o.useState(!1),jn=Us(w),We=o.useRef(X);We.current=X;const Ue=!!(m!=null&&m.trim())&&!gt,Oe=(j==null?void 0:j.trim())||"当前文档",Be=(C==null?void 0:C.trim())||"",we=!!(L!=null&&L.trim())&&!gt,Ct=(N==null?void 0:N.trim())||"当前图谱",ee=o.useMemo(()=>{var t;if(D)return[];if(we)return[{key:"graph",variant:"graph",kind:"图谱引用",name:Ct,title:"图谱 · 只读"}];if(Ue){const a=((t=Be.split("/").pop())==null?void 0:t.trim())||Oe;return[{key:(m==null?void 0:m.trim())||"doc",variant:"page",kind:"文章引用",name:a,title:Be||Oe}]}return[]},[D,we,Ue,Ct,Oe,Be,m]);o.useEffect(()=>{xt(!1)},[m,L]),o.useEffect(()=>{ee.length<2&&yt(!1)},[ee.length]),o.useEffect(()=>{bt(null)},[x==null?void 0:x.left,x==null?void 0:x.bottom]),o.useLayoutEffect(()=>{const t=ht.current;if(!t)return;const a=t.closest(".mdocs-agent-panel-input-body");t.style.height="auto";const r=t.scrollHeight>44;t.style.height=r?`${Math.min(160,t.scrollHeight)}px`:"",a==null||a.classList.toggle("is-tall",r)},[oe]),o.useEffect(()=>{function t(r){const d=be.current;if(!d)return;const l=r.clientX-d.startX;let u=d.edge==="right"?d.startW+l:d.startW-l;u=Je(u);let g=d.edge==="left"?d.startLeft+(d.startW-u):d.startLeft;g<8&&(u=Je(u-(8-g)),g=8);const P=g+u-(window.innerWidth-8);P>0&&(d.edge==="right"?g=Math.max(8,g-P):u=Je(u-P)),Fe.current=u,xn(u),bt(g)}function a(){be.current&&(be.current=null,document.body.style.cursor="",document.body.style.userSelect="",Hn(Fe.current))}return window.addEventListener("pointermove",t),window.addEventListener("pointerup",a),()=>{window.removeEventListener("pointermove",t),window.removeEventListener("pointerup",a),document.body.style.cursor="",document.body.style.userSelect=""}},[]);function At(t,a){var d;if(M||b)return;a.preventDefault();const r=(d=wt.current)==null?void 0:d.getBoundingClientRect();r&&(be.current={edge:t,startX:a.clientX,startW:r.width,startLeft:r.left},document.body.style.cursor="col-resize",document.body.style.userSelect="none")}function He(t){return St.current+=1,`${t}-${St.current}`}const It=120;function Rt(t){return t.scrollHeight-t.scrollTop-t.clientHeight}function Se(){const t=ve.current;t&&(t.scrollTop=t.scrollHeight,qe(!1))}function U(){Q.current&&Se()}function bn(){const t=ve.current;if(!t)return;const a=Rt(t);Q.current=a<=48,qe(a>It)}function kn(){Q.current=!0,Se()}o.useLayoutEffect(()=>{U();const t=ve.current;t&&qe(Rt(t)>It)},[X]);async function _t(){dt(!0);try{const t=await Kn(W,D?m:void 0);ct(t.sessions),V||ae(t.lastOpenedSessionId)}catch{}finally{dt(!1)}}async function Xe(){try{const t=await Xn();vt(t)}catch{}}async function Et(){try{const t=await qt();he(t),ge(null)}catch(t){he(null),ge(t instanceof Error?t.message:String(t))}}const Ce=o.useRef(pe);Ce.current=pe;const Ae=o.useRef(re);Ae.current=re,o.useEffect(()=>{var t;(t=Ce.current)==null||t.call(Ce,w)},[w]),o.useEffect(()=>{var t;(t=Ae.current)==null||t.call(Ae,V)},[V]),o.useEffect(()=>{var a;if(!c){H(!1),(a=z.current)==null||a.abort(),z.current=null;return}let t=!1;return(async()=>{try{const r=await qt();t||(he(r),ge(null))}catch(r){t||(he(null),ge(r instanceof Error?r.message:String(r)))}})(),Xe(),()=>{t=!0}},[c]);const Ie=D?`coding:${m??""}`:"normal",Mt=o.useRef(Ie);o.useEffect(()=>{if(!c)return;const t=Mt.current!==Ie;Mt.current=Ie;let a=!1;return(async()=>{try{const r=await On(W,D?m:void 0);if(a)return;ae(r.sessionId),A(d=>!t&&d.length>0&&!r.activeRun?d:Vt(r.sessionId,r.messages)),r.activeRun&&(r.activeRun.status==="running"||r.activeRun.status==="waiting_user")&&Nn(r.activeRun)}catch{}})(),()=>{a=!0}},[c,Ie]),o.useEffect(()=>{!c||!se||_t()},[c,se]),o.useEffect(()=>()=>{var t;(t=z.current)==null||t.abort()},[]);function Ke(){if(!G){if(ia(We.current)){J(!0);return}J(!1),f()}}async function vn(){var d;if(G)return;Nt(!0);const t=We.current,a=[];for(const l of t)if(!(l.role!=="assistant"||!l.blocks))for(const u of l.blocks)u.type==="choice_card"&&u.status==="open"&&a.push(sn(u.requestId).catch(()=>{})),u.type==="skill_form_card"&&u.status==="open"&&a.push(en(u.requestId).catch(()=>{}));const r=F.current;r&&a.push(_e(r).catch(()=>{})),await Promise.all(a),(d=z.current)==null||d.abort(),F.current=null,K(!1),A(l=>l.map(u=>u.role!=="assistant"||!u.blocks?u:{...u,blocks:u.blocks.map(g=>g.type==="choice_card"&&g.status==="open"?{...g,status:"cancelled"}:g.type==="skill_form_card"&&g.status==="open"?{...g,status:"cancelled"}:g)})),J(!1),Nt(!1),f()}const Ge=o.useRef(Ke);Ge.current=Ke,o.useImperativeHandle(i,()=>({requestClose:()=>Ge.current()}),[]),o.useEffect(()=>{if(!c){J(!1);return}const t=a=>{if(a.key==="Escape"){if(Pe){G||J(!1);return}if(se){H(!1);return}Ge.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[c,se,Pe,G]);function Dt(t,a){let r=!1;return a.type==="run_started"?(F.current=a.runId,ae(a.sessionId),!1):(a.type==="text_delta"?(A(d=>d.map(l=>{if(l.id!==t)return l;const u=Js(l.blocks??[],a.text);return{...l,blocks:u,content:Zt(u)}})),requestAnimationFrame(()=>U())):a.type==="thinking_delta"?(A(d=>d.map(l=>{if(l.id!==t)return l;const u=Qs(l.blocks??[],a.text);return{...l,blocks:u}})),requestAnimationFrame(()=>U())):a.type==="sources"?(A(d=>d.map(l=>{if(l.id!==t)return l;const u=(l.blocks??[]).slice(),g=u[u.length-1];return(g==null?void 0:g.type)==="sources"?u[u.length-1]={type:"sources",items:a.items}:u.push({type:"sources",items:a.items}),{...l,blocks:u}})),requestAnimationFrame(()=>U())):a.type==="document_table"?(A(d=>d.map(l=>{if(l.id!==t)return l;const u=[...l.blocks??[],{type:"document_table",title:a.title,rows:a.rows}];return{...l,blocks:u}})),requestAnimationFrame(()=>U())):a.type==="document_card"?(A(d=>d.map(l=>{if(l.id!==t)return l;const u=[...l.blocks??[],{type:"document_card",documentId:a.documentId,title:a.title,path:a.path,preview:a.preview}];return{...l,blocks:u}})),requestAnimationFrame(()=>U())):a.type==="tool_notice"?(A(d=>d.map(l=>{if(l.id!==t)return l;const u=[...l.blocks??[],{type:"tool_notice",toolName:a.toolName,text:a.text}];return{...l,blocks:u}})),requestAnimationFrame(()=>U())):a.type==="tool_call"?(A(d=>d.map(l=>{if(l.id!==t)return l;const u=ea(l.blocks??[],{type:"tool_call",toolCallId:a.toolCallId,toolName:a.toolName,label:a.label,status:a.status,detail:a.detail});return{...l,blocks:u}})),requestAnimationFrame(()=>U())):a.type==="choice_card"?(A(d=>d.map(l=>{if(l.id!==t)return l;const u=[...l.blocks??[],{type:"choice_card",requestId:a.requestId,title:a.title,options:a.options,expiresAt:a.expiresAt,status:"open"}];return{...l,blocks:u}})),requestAnimationFrame(()=>U())):a.type==="choice_expired"?A(d=>d.map(l=>l.id!==t||!l.blocks?l:{...l,blocks:l.blocks.map(u=>u.type==="choice_card"&&u.requestId===a.requestId&&u.status==="open"?{...u,status:"expired"}:u)})):a.type==="skill_form_card"?(A(d=>d.map(l=>{if(l.id!==t)return l;const u=[...l.blocks??[],{type:"skill_form_card",requestId:a.requestId,mode:a.mode,title:a.title,currentName:a.currentName,initialName:a.initialName,initialDescription:a.initialDescription,initialBody:a.initialBody,expiresAt:a.expiresAt,status:"open"}];return{...l,blocks:u}})),requestAnimationFrame(()=>U())):a.type==="skill_form_expired"?A(d=>d.map(l=>l.id!==t||!l.blocks?l:{...l,blocks:l.blocks.map(u=>u.type==="skill_form_card"&&u.requestId===a.requestId&&u.status==="open"?{...u,status:"expired"}:u)})):a.type==="markdown_set"?ne==null||ne(a.markdown):a.type==="tree_changed"?q==null||q():a.type==="document_overwritten"?T==null||T({documentId:a.documentId,headCommitId:a.headCommitId}):a.type==="open_coding"?O==null||O({documentId:a.documentId,displayName:a.displayName}):a.type==="context_usage"?vt({percent:a.percent,used:a.used,limit:a.limit}):a.type==="error"?(r=!0,$(a.message)):a.type==="done"&&(F.current=null),r)}async function Nn(t){var l;(l=z.current)==null||l.abort();const a=new AbortController;z.current=a,F.current=t.runId;const r=He("a");Ne.current=r,Q.current=!0,A(u=>{var P;const g=u[u.length-1];return(g==null?void 0:g.role)==="assistant"&&!g.content&&!((P=g.blocks)!=null&&P.length)?(Ne.current=g.id,u):[...u,{id:r,role:"assistant",content:""}]});const d=Ne.current??r;K(!0),$(null);try{let u=!1;await Bn(t.runId,{afterSeq:0,signal:a.signal,onEvent:g=>{Dt(d,g)&&(u=!0)}}),!a.signal.aborted&&!u&&$e([])}catch(u){if(a.signal.aborted)return;$(u instanceof Error?u.message:String(u))}finally{A(u=>u.map(g=>g.id===d&&g.blocks?{...g,blocks:Me(g.blocks)}:g)),z.current===a&&(z.current=null),F.current||K(!1)}}async function wn(){if(V)return V;try{const t=await Bt(W,D?m??null:void 0);return ae(t.sessionId),t.sessionId}catch(t){return $(t instanceof Error?t.message:String(t)),null}}async function Ye(t){const a=Ns(t,Z.map(d=>d.name));if(a.length===0||w||mt||!(k!=null&&k.enabled))return;const r=await wn();if(r){ft(!0),$(null);try{for(const d of a){const l=await Yn(r,d),u=d.type.startsWith("image/")?URL.createObjectURL(d):void 0;u&&ut.current.push(u),ze(g=>[...g,{...l,previewUrl:u}])}}catch(d){$(d instanceof Error?d.message:String(d))}finally{ft(!1),je.current&&(je.current.value="")}}}function Sn(t){Ye(t?Array.from(t):[])}function Cn(t){const a=Xt(t.clipboardData);a.length!==0&&(t.preventDefault(),Ye(a))}function An(t){ws(t.dataTransfer)&&(t.preventDefault(),t.dataTransfer.dropEffect="copy",Le(!0))}function In(t){const a=t.relatedTarget;a instanceof Node&&t.currentTarget.contains(a)||Le(!1)}function Rn(t){t.preventDefault(),Le(!1),Ye(Xt(t.dataTransfer))}async function Ve(t){var P;const a=t.trim(),r=Z.map(v=>v.id);if(!a&&r.length===0||w)return;if(!(k!=null&&k.enabled)){$((k==null?void 0:k.reason)==="missing_api_key"?"请先配置 API Key":(k==null?void 0:k.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(P=z.current)==null||P.abort();const d=new AbortController;z.current=d;const l=Z.map(v=>({id:v.id,name:v.name,mime:v.mime,bytes:v.bytes,previewUrl:v.previewUrl})),u={id:He("u"),role:"user",content:a||(l[0]?`(附件 ${l.map(v=>v.name).join(", ")})`:""),skillNames:le.length>0?[...le]:void 0,assets:l.length>0?l:void 0},g=He("a");Ne.current=g,Q.current=!0,A(v=>[...v,u,{id:g,role:"assistant",content:""}]),ye(""),ze([]),K(!0),$(null),H(!1),requestAnimationFrame(()=>{Se(),requestAnimationFrame(Se)});try{let v=!1;await Gn(a,{mode:W,skillNames:le.length>0?le:void 0,assetIds:r.length>0?r:void 0,...D?{documentId:m??null,workingMarkdown:De,baseMarkdown:fe}:{references:{domainId:(y==null?void 0:y.trim())||void 0,documentId:!we&&Ue?m.trim():void 0,graphFileId:we?L.trim():void 0}},signal:d.signal,onEvent:_=>{Dt(g,_)&&(v=!0)}}),!d.signal.aborted&&!v&&$e([])}catch(v){if(d.signal.aborted)return;$(v instanceof Error?v.message:String(v))}finally{A(v=>v.map(_=>_.id===g&&_.blocks?{..._,blocks:Me(_.blocks)}:_)),z.current===d&&(z.current=null),F.current||K(!1)}}async function _n(){var a;(a=z.current)==null||a.abort();const t=F.current;F.current=null,K(!1),t&&_e(t).catch(()=>{}),$(null),H(!1);try{const r=await Bt(W,D?m:void 0,y??null);ae(r.sessionId),A([]),ye(""),Q.current=!0,Xe(),_t()}catch(r){$(r instanceof Error?r.message:String(r))}}async function En(t){var r;if(t===V){H(!1);return}(r=z.current)==null||r.abort();const a=F.current;F.current=null,K(!1),a&&_e(a).catch(()=>{}),$(null);try{const d=await Vn(t,W,D?m:void 0);ae(d.sessionId),A(Vt(d.sessionId,d.messages)),ye(""),H(!1),ie(null),Q.current=!0,requestAnimationFrame(()=>U()),Xe()}catch(d){$(d instanceof Error?d.message:String(d))}}function $t(t){ct(a=>{const r=a.map(d=>d.id===t.id?{...d,...t}:d);return r.sort((d,l)=>{const u=d.pinned===!0,g=l.pinned===!0;return u!==g?u?-1:1:d.updatedAt<l.updatedAt?1:d.updatedAt>l.updatedAt?-1:0}),r})}async function Mn(t){if(!w)try{const a=await Zn(t.id,t.pinned!==!0,W);$t(a)}catch(a){$(a instanceof Error?a.message:String(a))}}function Dn(t){ie(t.id),lt(t.title)}async function zt(t){const a=ot.trim();if(ie(null),!!a)try{const r=await Jn(t,a,W);$t(r)}catch(r){$(r instanceof Error?r.message:String(r))}}const $n=t=>{const a=R.find(r=>r.domainId===t);return a?h?h(a.domainName):a.domainName:t===ue?"default":t},de=o.useMemo(()=>Y==="all"||!y?xe:xe.filter(t=>(t.domainId||ue)===y),[xe,Y,y]),Lt=o.useMemo(()=>de.filter(t=>t.pinned===!0),[de]),zn=o.useMemo(()=>{var r;const t=new Map;for(const d of de){const l=((r=d.domainId)==null?void 0:r.trim())||ue,u=t.get(l);u?u.push(d):t.set(l,[d])}const a=(y==null?void 0:y.trim())||ue;return Array.from(t.entries()).map(([d,l])=>({id:d,items:l,label:$n(d)})).sort((d,l)=>d.id===a?-1:l.id===a?1:d.label.localeCompare(l.label,"zh"))},[de,R,h,y]);function Tt(t){return it[t]!==void 0?!it[t]:Y==="all"?t===((y==null?void 0:y.trim())||ue):!0}function Ln(t){fn(a=>{const r=Tt(t);return{...a,[t]:r}})}function Re(t){!t||!S||S(t)}cn.current=Re;function Ft(t){const a=pn===t.id;return e.jsxs("div",{className:"mdocs-agent-panel-history-item"+(t.id===V?" active":""),children:[a?e.jsx("input",{className:"mdocs-agent-panel-history-rename",value:ot,autoFocus:!0,maxLength:80,"aria-label":"重命名会话",onChange:r=>lt(r.target.value),onClick:r=>r.stopPropagation(),onKeyDown:r=>{r.key==="Enter"?(r.preventDefault(),zt(t.id)):r.key==="Escape"&&ie(null)},onBlur:()=>void zt(t.id)}):e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-open",disabled:w,onClick:()=>void En(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:na(t.updatedAt)})]}),e.jsxs("div",{className:"mdocs-agent-panel-history-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-action"+(t.pinned?" pinned":""),title:t.pinned?"取消置顶":"置顶","aria-label":t.pinned?"取消置顶":"置顶",disabled:w,onClick:r=>{r.stopPropagation(),Mn(t)},children:e.jsx(hs,{size:14,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-action",title:"重命名","aria-label":"重命名",disabled:w||a,onClick:r=>{r.stopPropagation(),Dn(t)},children:e.jsx(fs,{size:14,strokeWidth:1.8})})]})]})}if(!c)return null;const Ze=(k==null?void 0:k.reason)==="missing_api_key",Pt=hn??(k&&!k.enabled&&!Ze?k.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:wt,className:"mdocs-agent-panel"+(M?" mdocs-agent-panel--embedded":b?" mdocs-agent-panel--fullscreen":""),role:M?void 0:"dialog","aria-label":D?"mdocs 帮写助手":"mdocs 智能助手","aria-modal":M?void 0:b?!0:void 0,style:M||b?void 0:{...x,width:ce,...jt!=null?{left:jt}:{}},children:[M||b?null:e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-panel-resize mdocs-agent-panel-resize-left",role:"separator","aria-orientation":"vertical","aria-label":"调整面板宽度","aria-valuenow":ce,"aria-valuemin":400,"aria-valuemax":960,onPointerDown:t=>At("left",t)}),e.jsx("div",{className:"mdocs-agent-panel-resize mdocs-agent-panel-resize-right",role:"separator","aria-orientation":"vertical","aria-label":"调整面板宽度","aria-valuenow":ce,"aria-valuemin":400,"aria-valuemax":960,onPointerDown:t=>At("right",t)})]}),e.jsxs("header",{className:"mdocs-agent-panel-header",children:[e.jsxs("div",{className:"mdocs-agent-panel-title",children:[e.jsx("img",{src:Wt,alt:"",className:"mdocs-agent-panel-title-logo"}),e.jsx("span",{children:D?"mdocs 帮写助手":"mdocs 智能助手"})]}),e.jsxs("div",{className:"mdocs-agent-panel-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:w,onClick:()=>void _n(),children:e.jsx(Ht,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(se?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>H(t=>!t),children:e.jsx(is,{size:16,strokeWidth:1.8})}),M||!I?null:e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:b?"退出全屏":"全屏","aria-label":b?"退出全屏":"全屏",onClick:I,children:b?e.jsx(us,{size:16,strokeWidth:1.8}):e.jsx(cs,{size:16,strokeWidth:1.8})}),M?null:e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:Ke,children:e.jsx(me,{size:16,strokeWidth:1.8})})]})]}),se?e.jsxs("div",{className:"mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>{H(!1),ie(null)},children:"返回对话"})]}),e.jsxs("div",{className:"mdocs-agent-panel-history-filters",role:"tablist","aria-label":"按工作空间筛选",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":Y==="current",className:"mdocs-agent-panel-history-filter"+(Y==="current"?" active":""),onClick:()=>rt("current"),children:"当前工作空间"}),e.jsx("button",{type:"button",role:"tab","aria-selected":Y==="all",className:"mdocs-agent-panel-history-filter"+(Y==="all"?" active":""),onClick:()=>rt("all"),children:"全部"})]}),gn?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):xe.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:"发一条消息后会出现在这里"})]}):de.length===0?e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"此工作空间暂无会话"}):e.jsxs("div",{className:"mdocs-agent-panel-history-list",children:[Lt.length>0?e.jsxs("section",{className:"mdocs-agent-panel-history-section",children:[e.jsx("div",{className:"mdocs-agent-panel-history-section-label",children:"Pinned"}),e.jsx("ul",{children:Lt.map(t=>e.jsx("li",{children:Ft(t)},t.id))})]}):null,zn.map(t=>{const a=Tt(t.id);return e.jsxs("section",{className:"mdocs-agent-panel-history-folder",children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-folder-head","aria-expanded":a,onClick:()=>Ln(t.id),children:[a?e.jsx(Ut,{size:14,strokeWidth:1.8}):e.jsx(nt,{size:14,strokeWidth:1.8}),e.jsx("span",{className:"mdocs-agent-panel-history-folder-name",children:t.label}),e.jsx("span",{className:"mdocs-agent-panel-history-folder-count",children:t.items.length})]}),a?e.jsx("ul",{children:t.items.map(r=>e.jsx("li",{children:Ft(r)},r.id))}):null]},t.id)})]})]}):e.jsxs("div",{className:"mdocs-agent-panel-body",onPaste:Cn,onDragOver:An,onDragLeave:In,onDrop:Rn,children:[e.jsxs("div",{className:"mdocs-agent-panel-scroll-wrap",children:[e.jsx("div",{className:"mdocs-agent-panel-welcome",ref:ve,onScroll:bn,children:X.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-hello",children:D?"你好,我是 mdocs 帮写助手":"你好,我是 mdocs 智能助手"}),e.jsx("p",{className:"mdocs-agent-panel-desc",children:D?"这里专注改稿:你说怎么写,我更新右侧提案;按段接受或拒绝后,再点「完成并写回」。答疑、建目录、搜文档请用右下角「智能助手」。":"我能答疑、搜文档、整理结构,也能帮你写全文;需要按段精细改稿,请点文档顶栏「帮写」。"}),Ze?e.jsx(Ot,{onConfigured:Et}):Pt?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Pt}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:(D?Zs:Vs).map(t=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void Ve(t),disabled:w||!(k!=null&&k.enabled),children:t},t))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:X.map(t=>{var a;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:Wt,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==="user"&&t.assets&&t.assets.length>0?e.jsx("div",{className:"mdocs-agent-msg-assets",children:t.assets.map(r=>e.jsx(Gt,{id:r.id,name:r.name,mime:r.mime,previewUrl:r.previewUrl},r.id))}):null,t.role==="assistant"?t.blocks&&t.blocks.length>0?e.jsxs("div",{className:"mdocs-agent-panel-timeline",children:[t.blocks.map((r,d)=>{if(r.type==="thinking")return e.jsx(Bs,{block:r,live:w&&!r.endedAt,now:jn},`${t.id}-th-${d}`);if(r.type==="text")return r.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Yt,{children:r.text})},`${t.id}-t-${d}`):null;if(r.type==="sources")return r.items.length===0?null:e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:["已阅读 ",r.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:r.items.map(l=>e.jsx("li",{children:e.jsx("a",{href:l.url,target:"_blank",rel:"noreferrer",children:l.name})},l.id))})]})},`${t.id}-s-${d}`);if(r.type==="tool_call"){const l=r.status==="running"?"进行中":r.status==="error"?"失败":"完成";return e.jsxs("div",{className:`mdocs-agent-panel-block mdocs-agent-tool-call mdocs-agent-tool-call-${r.status}`,children:[e.jsxs("div",{className:"mdocs-agent-tool-call-head",children:[e.jsx("span",{className:"mdocs-agent-tool-call-status","aria-hidden":!0}),e.jsx("span",{className:"mdocs-agent-tool-call-label",children:r.label}),e.jsx("span",{className:"mdocs-agent-tool-call-badge",children:l})]}),r.detail?e.jsx("p",{className:"mdocs-agent-tool-call-detail",children:r.detail}):null]},`${t.id}-tc-${r.toolCallId}`)}if(r.type==="tool_notice")return e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:r.text})},`${t.id}-n-${d}`);if(r.type==="choice_card")return e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(sa,{block:r,onResolved:(l,u,g)=>{A(P=>P.map(v=>v.id!==t.id||!v.blocks?v:{...v,blocks:v.blocks.map(_=>_.type==="choice_card"&&_.requestId===l?{..._,status:g,selected:g==="selected"?u:_.selected}:_)}))}})},`${t.id}-ch-${d}`);if(r.type==="skill_form_card")return e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Es,{block:r,onResolved:(l,u,g)=>{A(P=>P.map(v=>v.id!==t.id||!v.blocks?v:{...v,blocks:v.blocks.map(_=>_.type==="skill_form_card"&&_.requestId===l?{..._,status:u,submittedName:u==="submitted"?g:_.submittedName}:_)}))}})},`${t.id}-sf-${d}`);if(r.type==="document_card"){const l=`${window.location.origin}${window.location.pathname}#/doc/${r.documentId}`;return e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",open:!0,children:[e.jsxs("summary",{children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:u=>{u.preventDefault(),u.stopPropagation(),Re(r.documentId)},children:["《",r.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"打开文档"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[r.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:r.path}):null,e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:e.jsx("a",{href:l,className:"mdocs-agent-panel-doc-link",onClick:u=>{u.preventDefault(),Re(r.documentId)},children:l})}),r.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:r.preview}):e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview muted",children:"(无正文预览)"})]})]})},`${t.id}-c-${d}`)}return e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[r.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:r.rows.length===0?"无结果":`${r.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:r.rows.length===0?e.jsx("p",{className:"mdocs-agent-panel-doc-table-empty",children:"无结果"}):e.jsxs("table",{className:"mdocs-agent-panel-doc-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"文章名字"}),e.jsx("th",{children:"文章内容"})]})}),e.jsx("tbody",{children:r.rows.map(l=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>Re(l.documentId),children:l.title})}),e.jsx("td",{children:l.summary||"-"})]},l.documentId))})]})})]})},`${t.id}-d-${d}`)}),w&&t.id===((a=X[X.length-1])==null?void 0:a.id)&&!Zt(t.blocks)&&!ta(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(Yt,{children:t.content}):w?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:mn}):null]},t.id)})})}),yn?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:kn,title:"回到底部","aria-label":"回到底部",children:[e.jsx(as,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),kt?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:kt}):null,Ze&&X.length>0?e.jsx(Ot,{onConfigured:Et}):null,e.jsx(Rs,{selectedNames:le,onChange:$e,disabled:w||!(k!=null&&k.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap"+(pt?" is-dragover":""),children:[pt?e.jsx("div",{className:"mdocs-agent-composer-drop",children:"松开以添加"}):null,ee.length>0||Z.length>0?e.jsxs("div",{className:"mdocs-agent-composer-refs",children:[ee.length>1?e.jsxs("button",{type:"button",className:"mdocs-agent-page-refs-summary","aria-expanded":Te,onClick:()=>yt(t=>!t),children:[e.jsx(on,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsxs("span",{children:["已引用 ",ee.length," 篇文章"]}),Te?e.jsx(Ut,{size:14,strokeWidth:2,"aria-hidden":!0}):e.jsx(nt,{size:14,strokeWidth:2,"aria-hidden":!0})]}):null,ee.length<2||Te?ee.map(t=>e.jsx(ra,{item:t,disabled:w,onDismiss:()=>xt(!0)},t.key)):null,Z.length>0?e.jsx("div",{className:"mdocs-agent-composer-files",children:Z.map(t=>e.jsx(Gt,{id:t.id,name:t.name,mime:t.mime,previewUrl:t.previewUrl,removeDisabled:w,onRemove:()=>{t.previewUrl&&URL.revokeObjectURL(t.previewUrl),ze(a=>a.filter(r=>r.id!==t.id))}},t.id))}):null]}):null,e.jsxs("div",{className:"mdocs-agent-panel-input-body",children:[e.jsx("input",{ref:je,type:"file",accept:".png,.jpg,.jpeg,.webp,.gif,.txt,.md,.csv,.json,.pdf",hidden:!0,onChange:t=>void Sn(t.target.files)}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-attach",disabled:w||mt||!(k!=null&&k.enabled),title:"上传附件,也可粘贴或拖入","aria-label":"上传附件",onClick:()=>{var t;return(t=je.current)==null?void 0:t.click()},children:e.jsx(Ht,{size:18,strokeWidth:2,"aria-hidden":!0})}),e.jsx("textarea",{ref:ht,className:"mdocs-agent-panel-input",rows:1,placeholder:k!=null&&k.enabled?D?"说说要写什么…":"告诉 Agent 你想做什么…":"请先配置 API Key",value:oe,disabled:w||!(k!=null&&k.enabled),onChange:t=>ye(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),Ve(oe))}}),e.jsxs("div",{className:"mdocs-agent-panel-input-actions",children:[ke?e.jsx(aa,{percent:ke.percent,used:ke.used,limit:ke.limit}):null,e.jsx("button",{type:"button",className:w?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:w?!1:!(k!=null&&k.enabled)||!oe.trim()&&Z.length===0,onClick:()=>{var t;if(w){const a=F.current;(t=z.current)==null||t.abort(),F.current=null,K(!1),a&&_e(a).catch(()=>{});return}Ve(oe)},title:w?"停止":"发送","aria-label":w?"停止":"发送",children:w?"■":"↑"})]})]})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),Pe?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{G||J(!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:G,onClick:()=>J(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:G,onClick:()=>void vn(),children:G?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{ha as AgentChatPanel};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{r as d,j as i}from"./react-vendor-BVS1XoFi.js";import{_ as
|
|
1
|
+
import{r as d,j as i}from"./react-vendor-BVS1XoFi.js";import{_ as Q,M as X,aR as Y}from"./index-Kp5r4mc7.js";import{AgentChatPanel as Z}from"./AgentChatPanel-Bhv57WUW.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./check-NyVbPIj8.js";import"./copy-C_H9wgwB.js";import"./plus-D8tCpRfA.js";function V(e){return e===""?[]:e.split(`
|
|
2
2
|
`)}function ee(e){return e.join(`
|
|
3
|
-
`)}function
|
|
3
|
+
`)}function _(e,s){const r=V(e),n=V(s),o=r.length,a=n.length,l=Array.from({length:o+1},()=>Array.from({length:a+1},()=>0));for(let k=o-1;k>=0;k--)for(let g=a-1;g>=0;g--)r[k]===n[g]?l[k][g]=l[k+1][g+1]+1:l[k][g]=Math.max(l[k+1][g],l[k][g+1]);const x=[];let u=0,h=0;for(;u<o||h<a;)if(u<o&&h<a&&r[u]===n[h])x.push({kind:"eq",oi:u,ni:h}),u++,h++;else if(h<a&&(u===o||l[u][h+1]>=l[u+1][h]))x.push({kind:"ins",oi:u,ni:h}),h++;else if(u<o)x.push({kind:"del",oi:u,ni:h}),u++;else break;const M=[];let c=0,y=0;for(;c<x.length;){if(x[c].kind==="eq"){c++;continue}const k=x[c].oi,g=x[c].ni,T=[],m=[];let E=k,I=g;for(;c<x.length&&x[c].kind!=="eq";){const L=x[c];L.kind==="del"?(T.push(r[L.oi]),E=L.oi+1):(m.push(n[L.ni]),I=L.ni+1),c++}M.push({id:`h${y++}`,oldStart:k,oldEnd:E,newStart:g,newEnd:I,oldLines:T,newLines:m})}return M}function ne(e,s){const r=V(e);return ee([...r.slice(0,s.oldStart),...s.newLines,...r.slice(s.oldEnd)])}function J(e){const s=[];for(const r of e){const n=s[s.length-1];r.kind==="same"&&(n==null?void 0:n.kind)==="same"?s[s.length-1]={kind:"same",lines:[...n.lines,...r.lines],key:n.key}:s.push(r)}return s}function K(e){let s=0;return e.map(r=>{if(r.kind!=="hunk")return r;const n={...r,hunkIndex:s,key:`h-${r.hunk.id}-${s}`};return s+=1,n})}function te(e,s){const r=e.map(n=>n.kind!=="hunk"||n.hunk.id!==s?n:{kind:"same",lines:n.hunk.oldLines.slice(),key:`s-rej-${n.hunk.id}`});return K(J(r))}function se(e,s,r){let n=0,o=!1;const a=[];for(const l of e){if(l.kind==="same"){a.push(l);continue}if(l.hunk.id===s){o=!0,n=r.length-l.hunk.oldLines.length,a.push({kind:"same",lines:r.slice(),key:`s-acc-${l.hunk.id}`});continue}if(!o||n===0){a.push(l);continue}a.push({...l,hunk:{...l.hunk,oldStart:l.hunk.oldStart+n,oldEnd:l.hunk.oldEnd+n}})}return K(J(a))}function A(e){return e===""?[]:e.split(`
|
|
4
4
|
`)}function H(e){return e.join(`
|
|
5
|
-
`)}function ie(e,s){const r=A(e),n=[];let o=0;return s.forEach((a,l)=>{a.oldStart>o&&n.push({kind:"same",lines:r.slice(o,a.oldStart),key:`s-${o}-${a.oldStart}`}),n.push({kind:"hunk",hunk:a,hunkIndex:l,key:`h-${a.id}-${l}`}),o=a.oldEnd}),o<r.length?n.push({kind:"same",lines:r.slice(o),key:`s-${o}-end`}):s.length===0&&r.length===0&&n.push({kind:"same",lines:[],key:"s-empty"}),n}function
|
|
5
|
+
`)}function ie(e,s){const r=A(e),n=[];let o=0;return s.forEach((a,l)=>{a.oldStart>o&&n.push({kind:"same",lines:r.slice(o,a.oldStart),key:`s-${o}-${a.oldStart}`}),n.push({kind:"hunk",hunk:a,hunkIndex:l,key:`h-${a.id}-${l}`}),o=a.oldEnd}),o<r.length?n.push({kind:"same",lines:r.slice(o),key:`s-${o}-end`}):s.length===0&&r.length===0&&n.push({kind:"same",lines:[],key:"s-empty"}),n}function U(e){const s=[],r=[];for(const n of e)n.kind==="same"?s.push(H(n.lines)):r.push(H(n.hunk.newLines));return{sameTexts:s,newTexts:r}}function z(e,s){const r=[];let n=0,o=0;for(const a of e)if(a.kind==="same"){const l=s.sameTexts[n++]??"";r.push(...A(l))}else{const l=s.newTexts[o++]??"";r.push(...A(l))}return H(r)}function re(e){return e.oldLines.length===0?"add":e.newLines.length===0?"del":"mod"}function G(e){const s=Math.max(1,A(e.value).length);return i.jsxs("div",{className:`mdocs-ai-write-line ${e.className}`,children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("textarea",{className:"mdocs-ai-write-inline-edit",value:e.value,rows:s,spellCheck:!1,"aria-label":e["aria-label"],onChange:r=>e.onChange(r.target.value),onBlur:()=>e.onBlurFlush()})]})}function le(e){const s=!!e.sending,[r,n]=d.useState(0),[o,a]=d.useState(null),[l,x]=d.useState({sameTexts:[],newTexts:[]}),[u,h]=d.useState([]),M=d.useRef(!1),c=d.useRef(!1),y=d.useRef([]),k=d.useRef(l);k.current=l,y.current=u;const g=d.useMemo(()=>e.proposedMd==null||e.proposedMd===e.currentMd?[]:_(e.currentMd,e.proposedMd),[e.currentMd,e.proposedMd]),T=!s&&(u.length>0?u.some(t=>t.kind==="hunk"):g.length>0);d.useEffect(()=>{if(s){h([]),M.current=!1,c.current=!1;return}if(e.proposedMd==null||e.proposedMd===e.currentMd){h([]),M.current=!1,c.current=!1;return}if(c.current){c.current=!1;return}const t=_(e.currentMd,e.proposedMd);if(t.length===0){h([]);return}const f=ie(e.currentMd,t);h(f),M.current=!1,x(U(f))},[s,e.proposedMd,e.currentMd]);const m=d.useMemo(()=>u.filter(t=>t.kind==="hunk").map(t=>t.hunk),[u]);d.useEffect(()=>{if(m.length===0){n(0);return}n(t=>Math.min(t,m.length-1))},[m.length]);const E=o??r;function I(){return z(y.current,k.current)}function L(){if(!T||y.current.length===0)return e.proposedMd;const t=I();return M.current=!1,t===e.currentMd?(c.current=!1,e.onProposedChange(null),null):(t!==e.proposedMd&&(c.current=!0,e.onProposedChange(t)),t)}function $(t){const f=y.current.find(F=>F.kind==="hunk"&&F.hunk.id===t.id);if(!f)return;const b=k.current.newTexts[f.hunkIndex],j=b!=null?A(b):t.newLines.slice(),P={...t,newLines:j},C=I();if(M.current=!1,C===e.currentMd){c.current=!1,h([]),e.onProposedChange(null);return}const v=ne(e.currentMd,P),p=se(y.current,t.id,j),O=p.some(F=>F.kind==="hunk");c.current=!0,h(p),x(U(p)),e.onCurrentChange(v),!O||C===v?(c.current=!1,e.onProposedChange(null)):e.onProposedChange(C)}function R(t){const f=y.current.find(v=>v.kind==="hunk"&&v.hunk.id===t.id);if(!f)return;const b={sameTexts:k.current.sameTexts.slice(),newTexts:k.current.newTexts.slice()};b.newTexts[f.hunkIndex]=H(t.oldLines);const j=z(y.current,b),P=te(y.current,t.id),C=P.some(v=>v.kind==="hunk");M.current=!1,c.current=!0,h(P),x(U(P)),!C||j===e.currentMd?(c.current=!1,e.onProposedChange(null)):e.onProposedChange(j)}function q(){const t=I();M.current=!1,c.current=!1,e.onCurrentChange(t),e.onProposedChange(null)}function D(){M.current=!1,c.current=!1,e.onProposedChange(null)}function N(t){m.length!==0&&n(f=>{const b=(f+t+m.length)%m.length,j=document.getElementById(`mdocs-ai-hunk-${b}`);return j==null||j.scrollIntoView({block:"center",behavior:"smooth"}),b})}function S(t,f){M.current=!0,x(b=>{const j=b.sameTexts.slice();return j[t]=f,{...b,sameTexts:j}})}function W(t,f){M.current=!0,x(b=>{const j=b.newTexts.slice();return j[t]=f,{...b,newTexts:j}})}const w=m[E]??null;let B=0;return i.jsxs("div",{className:"mdocs-ai-write-md-pane",children:[i.jsxs("div",{className:"mdocs-ai-write-diff-toolbar",children:[i.jsx("span",{className:"mdocs-ai-write-diff-count",children:s?"接收中·编辑我的稿":m.length===0?e.proposedMd?"与提案一致(可编辑)":"Markdown 源码(可编辑)":`${m.length} 处变更(可改提案)`}),!s&&m.length>0?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-diff-accept-all",onClick:q,children:"全部接受"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-diff-reject-all",onClick:D,children:"全部拒绝"})]}):null]}),T&&u.length>0?i.jsxs("div",{className:"mdocs-ai-write-inline",role:"document",children:[u.map(t=>{if(t.kind==="same"){const C=B++,v=l.sameTexts[C]??H(t.lines);return i.jsx("div",{className:"mdocs-ai-write-inline-same",children:i.jsx(G,{className:"ctx",value:v,"aria-label":"提案相同行",onChange:p=>S(C,p),onBlurFlush:()=>L()})},t.key)}const f=t.hunk,b=re(f),j=t.hunkIndex===E,P=l.newTexts[t.hunkIndex]??H(f.newLines);return i.jsxs("div",{id:`mdocs-ai-hunk-${t.hunkIndex}`,className:`mdocs-ai-write-inline-hunk mdocs-ai-write-inline-hunk-${b}`+(j?" is-active":""),onMouseEnter:()=>a(t.hunkIndex),onMouseLeave:()=>a(null),onClick:()=>n(t.hunkIndex),children:[i.jsxs("div",{className:"mdocs-ai-write-hunk-hover",hidden:o!==t.hunkIndex,children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:C=>{C.stopPropagation(),R(f)},children:"拒绝"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:C=>{C.stopPropagation(),$(f)},children:"接受"})]}),i.jsx("pre",{className:"mdocs-ai-write-hunk-pre",children:f.oldLines.map((C,v)=>i.jsxs("div",{className:"mdocs-ai-write-line del mdocs-ai-write-line-readonly",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:C||" "})]},`o${v}`))}),f.newLines.length>0||P!==""||b!=="del"?i.jsx(G,{className:"add",value:P,"aria-label":"提案新增行",onChange:C=>W(t.hunkIndex,C),onBlurFlush:()=>L()}):null]},t.key)}),w?i.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"变更导航",children:[i.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>N(-1),children:"↑"}),i.jsxs("span",{children:[E+1," / ",m.length]}),i.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>N(1),children:"↓"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>R(w),children:"拒绝"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>$(w),children:"接受"})]}):null]}):i.jsx("textarea",{className:"mdocs-ai-write-editor",value:e.currentMd,onChange:t=>e.onCurrentChange(t.target.value),spellCheck:!1,placeholder:`# 标题
|
|
6
6
|
|
|
7
|
-
在此编辑 Markdown 源码…`})]})}function xe(e){const[s,r]=d.useState(e.initialMarkdown),[n,o]=d.useState(null),[a]=d.useState(e.initialMarkdown),[l,x]=d.useState(e.displayName||"未命名"),[u,h]=d.useState(null),[M,c]=d.useState(!1),[y,k]=d.useState(null),[g,T]=d.useState(!1),[m,E]=d.useState(null),I=d.useRef(null);if(d.useEffect(()=>{e.open&&(r(e.initialMarkdown),o(null),x(e.displayName||"未命名"),k(null))},[e.open,e.initialMarkdown,e.displayName,e.documentId]),!e.open)return null;const L=n!=null&&n!==s?
|
|
7
|
+
在此编辑 Markdown 源码…`})]})}function xe(e){const[s,r]=d.useState(e.initialMarkdown),[n,o]=d.useState(null),[a]=d.useState(e.initialMarkdown),[l,x]=d.useState(e.displayName||"未命名"),[u,h]=d.useState(null),[M,c]=d.useState(!1),[y,k]=d.useState(null),[g,T]=d.useState(!1),[m,E]=d.useState(null),I=d.useRef(null);if(d.useEffect(()=>{e.open&&(r(e.initialMarkdown),o(null),x(e.displayName||"未命名"),k(null))},[e.open,e.initialMarkdown,e.displayName,e.documentId]),!e.open)return null;const L=n!=null&&n!==s?_(s,n):[];function $(N){return new Promise(S=>{I.current=S,E({message:N.message,confirmLabel:N.confirmLabel??"确定",cancelLabel:N.cancelLabel??"返回",danger:N.danger??!1})})}function R(N){const S=I.current;I.current=null,E(null),S==null||S(N)}async function q(){if(!await $({message:"是否回写",confirmLabel:"确认",cancelLabel:"返回"}))return;let S=s;L.length>0&&(S=n??s,r(S),o(null)),T(!0);const W=!e.documentId;try{const w=await e.onComplete({markdown:S,documentId:e.documentId,displayName:l.trim()||"未命名"}),B=w&&typeof w=="object"&&typeof w.documentId=="string"?w.documentId.trim():"";if(W&&B&&u)try{await Y(u,B)}catch{}e.onClose()}catch(w){if(w!=null&&w.silent||w instanceof Error&&w.message==="cancelled")return;k(w instanceof Error?w.message:String(w))}finally{T(!1)}}async function D(){(s!==a||n!=null)&&!await $({message:"取消帮写?未写回的修改将丢失。",confirmLabel:"放弃修改",danger:!0})||e.onClose()}return i.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[i.jsxs("header",{className:"mdocs-ai-write-header",children:[i.jsxs("div",{className:"mdocs-ai-write-header-left",children:[i.jsx("img",{src:Q,alt:"",className:"mdocs-ai-write-title-logo"}),i.jsx("strong",{children:"帮写"}),i.jsx("input",{className:"mdocs-ai-write-title",value:l,onChange:N=>x(N.target.value),"aria-label":"文档标题"})]}),i.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[i.jsx("button",{type:"button",onClick:()=>void D(),disabled:g||m!=null,children:"取消"}),i.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void q(),disabled:g||m!=null,children:g?"写回中…":"完成并写回"})]})]}),y?i.jsx("p",{className:"mdocs-ai-write-error",children:y}):null,i.jsxs("div",{className:"mdocs-ai-write-body",children:[i.jsx("section",{className:"mdocs-ai-write-chat",children:i.jsx(Z,{embedded:!0,open:!0,mode:"coding",documentId:e.documentId,workingMarkdown:s,baseMarkdown:a,onMarkdownSet:o,onSendingChange:c,onSessionId:h,onClose:e.onClose})}),i.jsx(le,{currentMd:s,proposedMd:n,sending:M,onCurrentChange:r,onProposedChange:o})]}),m?i.jsx(X,{message:m.message,confirmLabel:m.confirmLabel,cancelLabel:m.cancelLabel,danger:m.danger,onConfirm:()=>R(!0),onCancel:()=>R(!1)}):null]})}export{xe as AiWriteWorkbench};
|
package/dist/web/assets/{DiagramEditor-NtNY3sZL-BuZCaqLT.js → DiagramEditor-NtNY3sZL-D7sapmVz.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Q as I,S as H,T as F,U as O,V as G}from"./react-
|
|
1
|
+
import{Q as I,S as H,T as F,U as O,V as G}from"./react-DsdrF7vh.js";import{r as c,j as e}from"./react-vendor-BVS1XoFi.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-CUKxedXW.js";import{M as _}from"./meta2d-DP4Vt_ZE.js";import"./editor-DBWWidi3.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./index-Kp5r4mc7.js";import"./plus-D8tCpRfA.js";import"./copy-C_H9wgwB.js";import"./check-NyVbPIj8.js";let q=0;const P=new Set;function $(n){return P.add(n),()=>{P.delete(n)}}function M(){return q}function J(){q++,P.forEach(n=>n())}function z(n){let t=null;try{const[r]=I();t=r}catch{}const i=t;if(!i)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore($,M,M),{setLocale:c.useCallback(r=>{i.setLocale(r),J()},[i]),t:c.useCallback((r,u)=>i.t(r,u),[i])}}const K={Activity:"meta2d.palette.groups.activity",Basic:"meta2d.palette.groups.basic","Fault tree":"meta2d.palette.groups.faultTree",Flow:"meta2d.palette.groups.flow","Sequence & class":"meta2d.palette.groups.sequenceClass"};function W(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function U(){return[{group:"Basic",key:"square",label:"Square",pen:{...s,height:100,name:"square",text:"",width:100}},{group:"Basic",key:"rect",label:"Rectangle",pen:{...s,name:"rectangle",text:"Rectangle"}},{group:"Basic",key:"roundRect",label:"Rounded",pen:{...s,borderRadius:.2,name:"rectangle",text:"Rounded"}},{group:"Basic",key:"circle",label:"Circle",pen:{...s,height:80,name:"circle",text:"Circle",width:80}},{group:"Basic",key:"triangle",label:"Triangle",pen:{...s,height:90,name:"triangle",text:"Triangle",width:100}},{group:"Basic",key:"diamond",label:"Diamond",pen:{...s,height:100,name:"diamond",text:"Decision",width:100}},{group:"Basic",key:"pentagon",label:"Pentagon",pen:{...s,height:100,name:"pentagon",text:"Pentagon",width:100}},{group:"Basic",key:"hexagon",label:"Hexagon",pen:{...s,height:100,name:"hexagon",text:"Hexagon",width:100}},{group:"Basic",key:"pentagram",label:"Star",pen:{...s,height:100,name:"pentagram",text:"",width:100}},{group:"Basic",key:"leftArrow",label:"Left arrow",pen:{height:60,name:"leftArrow",width:120}},{group:"Basic",key:"rightArrow",label:"Right arrow",pen:{height:60,name:"rightArrow",width:120}},{group:"Basic",key:"twowayArrow",label:"Two-way",pen:{height:60,name:"twowayArrow",width:150}},{group:"Basic",key:"cloud",label:"Cloud",pen:{height:100,name:"cloud",width:100}},{group:"Basic",key:"message",label:"Message",pen:{height:100,name:"message",textTop:-.1,width:100}},{group:"Basic",key:"file",label:"File",pen:{height:100,name:"file",width:80}},{group:"Basic",key:"cube",label:"Cube",pen:{height:100,name:"cube",width:60,z:.25}},{group:"Basic",key:"people",label:"Actor",pen:{height:100,name:"people",width:70}},{group:"Basic",key:"text",label:"Text",pen:{...s,background:"transparent",color:"transparent",height:32,name:"text",text:"text",width:120}},{group:"Basic",key:"line",label:"Line",pen:{color:"#1f1f1f",height:1,lineWidth:1,name:"line",width:160}},{group:"Flow",key:"flowTerminal",label:"Terminal",pen:{...s,borderRadius:.5,height:40,name:"rectangle",text:"Start / End",width:120}},{group:"Flow",key:"flowProcess",label:"Process",pen:{...s,height:40,name:"rectangle",text:"Process",width:120}},{group:"Flow",key:"flowDecision",label:"Decision",pen:{...s,height:60,name:"diamond",text:"Decision",width:120}},{group:"Flow",key:"flowData",label:"Data",pen:{...s,name:"flowData",offsetX:.14,text:"Data"}},{group:"Flow",key:"flowPrepare",label:"Prepare",pen:{...s,height:50,name:"hexagon",text:"Prepare",width:120}},{group:"Flow",key:"flowSubprocess",label:"Subprocess",pen:{...s,height:50,name:"flowSubprocess",text:"Subprocess",width:120}},{group:"Flow",key:"flowDb",label:"Database",pen:{...s,height:100,name:"flowDb",text:"DB",width:80}},{group:"Flow",key:"flowDocument",label:"Document",pen:{...s,height:100,name:"flowDocument",text:"Document",width:120}},{group:"Flow",key:"flowInternalStorage",label:"Int. storage",pen:{...s,height:80,name:"flowInternalStorage",text:"Internal",width:120}},{group:"Flow",key:"flowExternStorage",label:"Ext. storage",pen:{...s,height:80,name:"flowExternStorage",text:"External",width:120}},{group:"Flow",key:"flowQueue",label:"Queue",pen:{...s,height:100,name:"flowQueue",text:"Queue",width:100}},{group:"Flow",key:"flowManually",label:"Manual input",pen:{...s,height:80,name:"flowManually",text:"Manual",width:120}},{group:"Flow",key:"flowDisplay",label:"Display",pen:{...s,height:80,name:"flowDisplay",text:"Display",width:120}},{group:"Flow",key:"flowParallel",label:"Parallel",pen:{...s,height:50,name:"flowParallel",text:"Parallel",width:120}},{group:"Flow",key:"flowComment",label:"Comment",pen:{...s,height:100,name:"flowComment",text:"Note",width:100}},{group:"Activity",key:"actStart",label:"Start",pen:{background:"#555",height:30,lineWidth:0,name:"circle",text:"",width:30}},{group:"Activity",key:"actFinal",label:"Final",pen:{height:30,name:"activityFinal",width:30}},{group:"Activity",key:"actStep",label:"Action",pen:{...s,borderRadius:.25,height:50,name:"rectangle",text:"Action",width:120}},{group:"Activity",key:"actMerge",label:"Merge",pen:{...s,height:50,name:"diamond",text:"Merge",width:120}},{group:"Activity",key:"swimlaneV",label:"Swimlane V",pen:{height:500,lineTop:.08,name:"swimlaneV",text:"Swimlane",textBaseline:"top",textTop:20,width:200}},{group:"Activity",key:"swimlaneH",label:"Swimlane H",pen:{height:200,lineLeft:.08,name:"swimlaneH",text:"Swimlane",textAlign:"left",textLeft:.04,textWidth:.01,width:500}},{group:"Activity",key:"forkV",label:"Fork V",pen:{fillStyle:"#555",height:150,name:"forkV",strokeStyle:"transparent",text:"",width:10}},{group:"Activity",key:"forkH",label:"Fork H",pen:{fillStyle:"#555",height:10,name:"forkH",strokeStyle:"transparent",text:"",width:150}},{group:"Sequence & class",key:"lifeline",label:"Lifeline",pen:{height:400,name:"lifeline",text:"Object",textHeight:50,width:150}},{group:"Sequence & class",key:"sequenceFocus",label:"Activation",pen:{height:200,name:"sequenceFocus",text:"",width:12}},{group:"Sequence & class",key:"simpleClass",label:"Simple class",pen:{height:200,list:[{text:`- name: string
|
|
2
2
|
+ setName(name: string): void`}],name:"simpleClass",text:"ClassName",textAlign:"center",textBaseline:"top",textHeight:200,textTop:10,width:270}},{group:"Sequence & class",key:"interfaceClass",label:"Class",pen:{height:200,list:[{text:"- name: string"},{text:"+ setName(name: string): void"}],name:"interfaceClass",text:"ClassName",textAlign:"center",textBaseline:"top",textHeight:200,textTop:10,width:270}},{group:"Fault tree",key:"andGate",label:"AND gate",pen:{height:150,name:"andGate",width:100}},{group:"Fault tree",key:"orGate",label:"OR gate",pen:{height:150,name:"orGate",width:100}},{group:"Fault tree",key:"basicEvent",label:"Basic event",pen:{height:150,name:"basicEvent",width:100}},{group:"Fault tree",key:"xorGate",label:"XOR gate",pen:{height:150,name:"xorGate",width:100}},{group:"Fault tree",key:"votingGate",label:"Voting gate",pen:{height:150,name:"votingGate",width:100}}]}function V(n){return G(structuredClone(n))}function Z(n){const t=new Map;for(const i of n){const r=t.get(i.group)??[];r.push(i),t.set(i.group,r)}return Array.from(t.entries())}function ee({name:n}){const t={fill:"#fff",stroke:"#1f1f1f",strokeWidth:1.2};return n==="circle"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("circle",{cx:"14",cy:"14",r:"10",...t})}):n==="diamond"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 25,14 14,25 3,14",...t})}):n==="triangle"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,4 25,24 3,24",...t})}):n==="pentagon"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 25,12 21,25 7,25 3,12",...t})}):n==="hexagon"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"8,4 20,4 25,14 20,24 8,24 3,14",...t})}):n==="pentagram"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 17,11 26,11 18,16 21,25 14,20 7,25 10,16 2,11 11,11",...t})}):n==="line"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("line",{x1:"4",x2:"24",y1:"14",y2:"14",...t})}):n==="text"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("text",{dominantBaseline:"middle",fill:"#1f1f1f",fontSize:"14",textAnchor:"middle",x:"14",y:"15",children:"T"})}):e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("rect",{height:"14",rx:"2",width:"20",x:"4",y:"7",...t})})}function te({disabled:n,engineRef:t,item:i,t:r}){const u=()=>{const a=t.current;if(!(!a||n))try{a.canvas.addCaches=[V(i.pen)]}catch{}};return e.jsxs("div",{draggable:!n,onClick:a=>{a.stopPropagation(),u()},onDragStart:a=>{if(n){a.preventDefault();return}const f=JSON.stringify(V(i.pen));a.dataTransfer.setData("Meta2d",f),a.dataTransfer.setData("Text",f),a.dataTransfer.effectAllowed="copy"},onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),u())},role:"button",style:{alignItems:"center",border:"1px solid #efefef",borderRadius:6,cursor:n?"not-allowed":"grab",display:"flex",flexDirection:"column",gap:4,justifyContent:"center",minHeight:56,opacity:n?.5:1,outline:"none",padding:6},tabIndex:n?-1:0,title:`${r(W(i.key))||i.label} — drag or click to add`,children:[e.jsx(ee,{name:String(i.pen.name??"rectangle")}),e.jsx("span",{style:{fontSize:11},children:r(W(i.key))||i.label})]})}function ne({disabled:n,engineRef:t}){const{t:i}=z(),r=c.useMemo(()=>Z(U()),[]);return e.jsxs("aside",{style:{borderRight:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",padding:12,touchAction:"pan-y",width:240},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,marginBottom:4},children:i("meta2d.palette.title")}),e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:12},children:i("meta2d.palette.hint")}),r.map(([u,a])=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:6},children:i(K[u]||u)}),e.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"repeat(2, minmax(0, 1fr))"},children:a.map(f=>e.jsx(te,{disabled:n,engineRef:t,item:f,t:i},f.key))})]},u))]})}const N={borderLeft:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",touchAction:"pan-y",width:220},A={color:"#8c8c8c",fontSize:12,marginBottom:4},D={borderBottom:"1px solid #f0f0f0",padding:"10px 12px"},y={alignItems:"center",display:"flex",gap:6,marginBottom:6},w={background:"#fafafa",border:"1px solid #e5e5e5",borderRadius:4,fontSize:12,height:28,outline:"none",padding:"0 6px"},b={color:"#8c8c8c",fontSize:11,minWidth:22},T={background:"#fff",border:"1px solid #d9d9d9",borderRadius:4,cursor:"pointer",fontSize:11,minWidth:48,padding:"4px 8px"},le=120;function ie({engine:n}){const{t}=z(),[i,r]=c.useState(null),[u,a]=c.useState(null),[f,v]=c.useState(""),p=c.useRef(null),j=c.useRef(null),B=c.useCallback((l,d)=>{!n||l===null||l===void 0||n.setValue({id:l,text:d},{render:!0})},[n]),k=c.useCallback(l=>{if(!l||l.length!==1){p.current&&(clearTimeout(p.current),p.current=null),r(null),a(null),v(""),j.current=null;return}const d=l[0];if((d.globalAlpha===null||d.globalAlpha===void 0)&&(d.globalAlpha=1),d.id!==j.current&&(p.current&&(clearTimeout(p.current),p.current=null),j.current=d.id,v(d.text??"")),r(d),n)try{a(n.getPenRect(d))}catch{a(null)}},[n]),C=c.useCallback(()=>{p.current&&(clearTimeout(p.current),p.current=null),r(null),a(null),v(""),j.current=null},[]);if(c.useEffect(()=>{if(n)return n.on("active",k),n.on("inactive",C),()=>{n.off("active",k),n.off("inactive",C),p.current&&(clearTimeout(p.current),p.current=null)}},[n,k,C]),!i||!n)return e.jsx("aside",{style:N,children:e.jsx("div",{style:{color:"#bbb",fontSize:12,padding:16,textAlign:"center"},children:t("meta2d.props.empty")})});const h=(l,d)=>{const m={id:i.id};m[l]=d,l==="dash"&&(m.lineDash=[void 0,[5,5]][d]),l!=="text"&&r(S=>S&&{...S,...m}),n.setValue(m,{render:!0})},o=l=>{v(l);const d=i.id;p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{p.current=null,B(d,l)},le)},x=()=>{p.current&&(clearTimeout(p.current),p.current=null),B(i.id,f)},g=(l,d)=>{if(!u)return;const m={id:i.id};m[l]=d,n.setValue(m,{render:!0}),a(S=>S?{...S,[l]:d}:null)},R=l=>{l(n),n.render(!0)};return e.jsxs("aside",{style:N,children:[e.jsxs("div",{style:D,children:[e.jsx("div",{style:A,children:t("meta2d.props.text")}),e.jsx("div",{style:y,children:e.jsx("input",{onBlur:x,onChange:l=>o(l.target.value),onKeyDown:l=>{l.stopPropagation(),l.key==="Enter"&&(l.preventDefault(),l.target.blur())},style:{...w,flex:1,width:"100%"},type:"text",value:f})})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.appearance")}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.color")}),e.jsx("input",{onChange:l=>h("color",l.target.value),style:{...w,flex:1},type:"color",value:i.color||"#1f1f1f"})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.bg")}),e.jsx("input",{onChange:l=>h("background",l.target.value),style:{...w,flex:1},type:"color",value:i.background||"#ffffff"})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.dash")}),e.jsxs("select",{onChange:l=>h("dash",Number(l.target.value)),style:{...w,flex:1},value:String(i.dash??0),children:[e.jsx("option",{value:"0",children:t("meta2d.props.solid")}),e.jsx("option",{value:"1",children:t("meta2d.props.dashLine")})]})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.radius")}),e.jsx("input",{max:1,min:0,onChange:l=>h("borderRadius",Number(l.target.value)),step:.01,style:{...w,flex:1},type:"range",value:String(i.borderRadius??0)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:i.borderRadius??0})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.alpha")}),e.jsx("input",{max:1,min:0,onChange:l=>h("globalAlpha",Number(l.target.value)),step:.01,style:{...w,flex:1},type:"range",value:String(i.globalAlpha??1)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:(i.globalAlpha??1).toFixed(2)})]})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.position")}),[["X","x"],["Y","y"],["W","width"],["H","height"]].map(([l,d])=>e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:l}),e.jsx("input",{onChange:m=>g(d,Number(m.target.value)),style:{...w,flex:1},type:"number",value:u?u[d]:0})]},d))]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.textAlign")}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.h")}),e.jsxs("select",{onChange:l=>h("textAlign",l.target.value),style:{...w,flex:1},value:i.textAlign||"center",children:[e.jsx("option",{value:"left",children:t("meta2d.props.left")}),e.jsx("option",{value:"center",children:t("meta2d.props.center")}),e.jsx("option",{value:"right",children:t("meta2d.props.right")})]})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.v")}),e.jsxs("select",{onChange:l=>h("textBaseline",l.target.value),style:{...w,flex:1},value:i.textBaseline||"middle",children:[e.jsx("option",{value:"top",children:t("meta2d.props.topAlign")}),e.jsx("option",{value:"middle",children:t("meta2d.props.middle")}),e.jsx("option",{value:"bottom",children:t("meta2d.props.bottomAlign")})]})]})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.layer")}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[e.jsx("button",{onClick:()=>R(l=>l.top()),style:T,type:"button",children:t("meta2d.props.top")}),e.jsx("button",{onClick:()=>R(l=>l.up()),style:T,type:"button",children:t("meta2d.props.up")}),e.jsx("button",{onClick:()=>R(l=>l.down()),style:T,type:"button",children:t("meta2d.props.down")}),e.jsx("button",{onClick:()=>R(l=>l.bottom()),style:T,type:"button",children:t("meta2d.props.bottom")})]})]})]})}const L={background:"#fff",border:"1px solid #d9d9d9",borderRadius:6,cursor:"pointer",minWidth:68,padding:"6px 12px"},E={...L,fontSize:12,minWidth:52,padding:"4px 10px"};function re(n){c.useEffect(()=>{const t=document.documentElement,i=document.body,r=t.style.overflow,u=i.style.overflow;return t.style.overflow="hidden",i.style.overflow="hidden",()=>{t.style.overflow=r,i.style.overflow=u}},[n])}function ye({diagram:n,onClose:t,onSave:i}){const{t:r}=z(),u=c.useRef(null),a=c.useRef(null),f=c.useRef(n),v=c.useRef(t),[p,j]=c.useState(null),[B,k]=c.useState(!1);re(!0),c.useLayoutEffect(()=>{v.current=t}),c.useEffect(()=>{if(!u.current)return;X();const o=new _(u.current,{grid:!0,rule:!1});a.current=o,j(o);try{const g=f.current;g!=null&&g.trim()?o.open(JSON.parse(g)):o.open(H()),F(o.data()),o.render(!0)}catch{o.open(H()),F(o.data()),o.render(!0)}const x=g=>{g.key==="Escape"&&v.current()};return window.addEventListener("keydown",x),()=>{window.removeEventListener("keydown",x);try{o.destroy()}catch{}a.current=null}},[]);const C=async()=>{const o=a.current;if(o){k(!0);try{F(o.data()),o.render(!0);const x=O(o.data()),g=JSON.stringify(x);i(g,await Q(o)||await Y(g)||'<svg xmlns="http://www.w3.org/2000/svg" width="320" height="180" viewBox="0 0 320 180"><rect width="100%" height="100%" fill="#fafafa" stroke="#eee"/></svg>')}finally{k(!1)}}},h=o=>{const x=a.current;x&&o(x)};return e.jsx("div",{onClick:t,style:{alignItems:"center",background:"rgb(0 0 0 / 35%)",display:"flex",inset:0,justifyContent:"center",overflow:"hidden",position:"fixed",zIndex:1e3},children:e.jsxs("div",{onClick:o=>o.stopPropagation(),onWheel:o=>o.stopPropagation(),style:{background:"#fff",borderRadius:10,boxShadow:"0 12px 30px rgb(0 0 0 / 20%)",display:"flex",flexDirection:"column",height:"86vh",maxHeight:"100%",maxWidth:"1200px",overflow:"hidden",width:"92vw"},children:[e.jsxs("div",{style:{alignItems:"center",borderBottom:"1px solid #f0f0f0",display:"flex",flexWrap:"wrap",gap:8,justifyContent:"space-between",padding:"10px 14px"},children:[e.jsx("span",{style:{fontWeight:600},children:r("meta2d.editor.title")}),e.jsxs("div",{style:{alignItems:"center",display:"flex",flexWrap:"wrap",gap:8},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:[e.jsx("button",{onClick:()=>h(o=>o.undo()),style:E,title:`${r("meta2d.editor.undo")} (Ctrl+Z)`,type:"button",children:r("meta2d.editor.undo")}),e.jsx("button",{onClick:()=>h(o=>o.redo()),style:E,title:`${r("meta2d.editor.redo")} (Ctrl+Y)`,type:"button",children:r("meta2d.editor.redo")}),e.jsx("button",{onClick:()=>h(o=>o.delete()),style:E,title:r("meta2d.editor.delete"),type:"button",children:r("meta2d.editor.delete")}),e.jsx("button",{onClick:()=>h(o=>o.fitView(!0)),style:E,title:r("meta2d.editor.fit"),type:"button",children:r("meta2d.editor.fit")}),e.jsx("button",{onClick:()=>h(o=>{o.scale(1),o.centerView()}),style:E,title:r("meta2d.editor.zoom100"),type:"button",children:r("meta2d.editor.zoom100")})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:t,style:L,type:"button",children:r("meta2d.editor.close")}),e.jsx("button",{disabled:B,onClick:()=>void C(),style:{...L,background:"#1677ff",border:"none",color:"#fff"},type:"button",children:r(B?"meta2d.editor.saving":"meta2d.editor.save")})]})]})]}),e.jsxs("div",{style:{display:"flex",flex:1,minHeight:0,overflow:"hidden"},children:[e.jsx(ne,{engineRef:a}),e.jsx("div",{ref:u,style:{flex:1,minHeight:0,minWidth:0}}),e.jsx(ie,{engine:p})]})]})})}export{ye as DiagramEditor};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as m,c as B,U as A,V as S,W as k,l as j,Y as v,Z as I,_ as W,S as z,$ as H}from"./index-
|
|
1
|
+
import{o as m,c as B,U as A,V as S,W as k,l as j,Y as v,Z as I,_ as W,S as z,$ as H}from"./index-Kp5r4mc7.js";import{r as C,j as n}from"./react-vendor-BVS1XoFi.js";import{g as O}from"./file-type-policy-5jFXMeIz.js";/**
|
|
2
2
|
* @license lucide-react v0.562.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as n,j as a}from"./react-vendor-BVS1XoFi.js";import{ad as ge}from"./ui-CEFkTVnG.js";import{g as be,u as Ee,a as ve,s as We,d as Ge,b as xe,c as Ye,f as Je,e as $e,h as Ke,N as Xe,S as Qe,l as Ze,r as pe,i as et,j as tt,D as ee,k as nt,m as at,n as Ie}from"./index-92xZ1zjh.js";import{z as it,A as rt,m as ce,n as ot,o as st,p as ct,r as lt,s as ut,t as dt,v as mt,x as ft,B as ht,R as yt,a as gt,b as ke,c as vt,d as xt,e as It,f as kt,g as St,h as Ct,i as wt,w as le,j as bt,O as Et,E as Mt,q as Dt,l as Rt,C as jt,D as At}from"./react-DHtvOuT-.js";import{H as Nt,a as Tt,b as Pt,M as Bt,T as Lt,S as Ot,W as _t,o as zt,c as Se}from"./Toolbar-LRioFemr.js";import{D as Ft,S as Ht}from"./DocChrome-DwSYxHOP.js";import{V as Ut,U as qt}from"./VisitorPickerModal-iK2QsYfY.js";import{c as Vt}from"./docPlainCharCount-DO5lb3Wt.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./editor-DBWWidi3.js";import"./plus-Ss1czARp.js";import"./copy-BT35-MU9.js";import"./check-65pb-o1o.js";import"./italic-BmGXEOKX.js";import"./file-type-policy-aRrzC4LZ.js";const Wt=48;function te(e){try{const r=e.getDocument("markdown");return typeof r=="string"?r:""}catch{return null}}function Gt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function Yt({editor:e,documentId:r,displayName:l,debounceMs:g=1e3,enabled:y=!0,localBaseCommitIdAtEditStart:C,snapshotMeta:D,seedDraftExists:F=!1}){const[H,_]=n.useState(!1),[ne,T]=n.useState(F),[P,w]=n.useState(null),d=n.useRef(null),h=n.useRef(null),I=n.useRef(!1),x=n.useRef(""),v=n.useRef(!1),z=n.useRef(r),U=n.useRef(l),B=n.useRef(C),J=n.useRef(D);z.current=r,U.current=l,B.current=C,J.current=D;const b=n.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const c=Gt(e);c!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",z.current,"content preview:",c.slice(0,80)),await be(z.current).execute(()=>Ee({documentId:z.current,content:c,displayName:U.current,localBaseCommitIdAtEditStart:B.current,snapshotMeta:J.current})),x.current=te(e)??x.current,T(!0),_(!1),w(Date.now()),I.current=!0,v.current=!1)},[e]);n.useEffect(()=>{let c=!1;const f=xe();return ve(r).then(m=>{if(c||xe()!==f)return;const R=!!(m&&!m.published);T(R),R&&m?(w(m.updatedAt),I.current=!0):(w(null),I.current=!1,v.current=!1)}),()=>{c=!0}},[r]),n.useEffect(()=>We((c,f)=>{c===z.current&&(T(f),f||(w(null),I.current=!1))}),[]),n.useEffect(()=>{var W,k;if(!y){(W=h.current)==null||W.call(h),h.current=null;return}if(!e)return;const c=e.getLexicalEditor();if(!c)return;(k=h.current)==null||k.call(h);let f=!1,m=0,R=0;const V=()=>{if(f)return;const E=te(e);if(E===null){if(R+=1,R>Wt)return;m=requestAnimationFrame(V);return}x.current=E;const G=c.registerUpdateListener(()=>{const L=te(e);L!==null&&L!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",r,"oldLen:",x.current.length,"newLen:",L.length),x.current=L,_(!0),v.current=!0,I.current=!1,d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,b()},g))});h.current=()=>{G(),d.current&&(clearTimeout(d.current),d.current=null)}};return queueMicrotask(()=>{f||(m=requestAnimationFrame(V))}),()=>{var E;f=!0,cancelAnimationFrame(m),(E=h.current)==null||E.call(h)}},[y,e,r,l,g,C,D,b]),n.useEffect(()=>{var m;if(!y||!e)return;const c=(m=e.getLexicalEditor())==null?void 0:m.getRootElement();if(!c)return;const f=()=>{d.current&&(clearTimeout(d.current),d.current=null),v.current&&b()};return c.addEventListener("blur",f),()=>c.removeEventListener("blur",f)},[y,e,b]),n.useEffect(()=>{if(!y)return;const c=()=>{document.visibilityState==="hidden"&&(d.current&&(clearTimeout(d.current),d.current=null),v.current&&b())},f=()=>{v.current&&(d.current&&(clearTimeout(d.current),d.current=null),b())};return document.addEventListener("visibilitychange",c),window.addEventListener("beforeunload",f),()=>{document.removeEventListener("visibilitychange",c),window.removeEventListener("beforeunload",f)}},[y,b]);async function $(){await Ge(r),T(!1),_(!1),v.current=!1,I.current=!1,x.current=""}async function K(){const c=await ve(r);return c?c.content:null}function q(){T(!0),_(!1),v.current=!1,w(Date.now()),I.current=!0,e&&(x.current=te(e)??"")}return{isDirty:H,draftExists:ne,lastSavedAt:P,clearDraft:$,loadDraftContent:K,markDraftSaved:q}}function Jt({isDirty:e,draftExists:r}){const l=e&&!r;n.useEffect(()=>{if(!l)return;const g=y=>{y.preventDefault()};return window.addEventListener("beforeunload",g),()=>window.removeEventListener("beforeunload",g)},[l])}function ue(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Ce='{"root":{"direction":"ltr","format":"","indent":0,"version":1,"type":"root","children":[{"direction":"ltr","format":"","indent":0,"version":1,"textFormat":0,"textStyle":"","children":[],"type":"paragraph"}]}}';function we(e){const l=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(l)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(l)?"不支持的文件类型":/^not an image$/i.test(l)?"不是有效的图片文件":l||"上传失败"}function $t(e,r){if(!e)return r==="json"?Ce:e;if(r!=="json")return e;try{const l=JSON.parse(e);if(l!=null&&l.root&&Array.isArray(l.root.children)&&l.root.children.length===0)return Ce}catch{}return e}function Kt({editor:e}){const{visible:r}=jt();return a.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:r?200:0},children:a.jsx("div",{style:{width:200},children:a.jsx(At,{editor:e})})})}function fn(e){const{t:r,lang:l}=Ye(),[g,y]=n.useState(!1),[C,D]=n.useState(!1),F=n.useRef(null),H=n.useRef(null),[_,ne]=n.useState([]),[T,P]=n.useState(!1),[w,d]=n.useState(e.meta.permission),[h,I]=n.useState(!1),[x,v]=n.useState(!1),[z,U]=n.useState(!1),[B,J]=n.useState(new Map),[b,$]=n.useState(!1),[K,q]=n.useState(null),c=n.useRef(0);n.useEffect(()=>{const t=i=>{F.current&&!F.current.contains(i.target)&&y(!1),H.current&&!H.current.contains(i.target)&&D(!1)};return(g||C)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[g,C]),n.useEffect(()=>{let t=!0;return Je().then(i=>{t&&ne(i)}).catch(()=>{}),()=>{t=!1}},[]);function f(t){const i=_.find(o=>o.visitorId===t);return(i==null?void 0:i.visitorName)??t.slice(0,8)}const[m,R]=n.useState(e.initialDisplayName),[V,W]=n.useState(!1),[k,E]=n.useState(!1),[G,L]=n.useState(!1),[Me,De]=n.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),ae=e.canEdit&&Me,[u,de]=n.useState(null),[Re,me]=n.useState(!1),ie=n.useRef(null);n.useLayoutEffect(()=>{me(!1),de(null),ie.current=null},[e.meta.documentId]),n.useEffect(()=>{const t=requestAnimationFrame(()=>me(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]),n.useEffect(()=>{if(!g&&!C)return;const t=++c.current;q(null);const i=()=>{if(t===c.current)try{let s=e.initialContent||"";if(u)try{const N=u.getDocument("markdown");typeof N=="string"&&(s=N)}catch{}const S=Vt("md",s);t===c.current&&q(S)}catch{t===c.current&&q(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const s=o.requestIdleCallback(i);return()=>{var S;return(S=o.cancelIdleCallback)==null?void 0:S.call(o,s)}}const M=window.setTimeout(i,0);return()=>window.clearTimeout(M)},[g,C,u,e.initialContent,e.meta.documentId,e.contentRevision]);const j=n.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const i=JSON.parse(e.initialContent);return Array.isArray((t=i==null?void 0:i.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),X=n.useMemo(()=>$t(e.initialContent||"",j),[e.initialContent,j,e.contentRevision]),{isDirty:fe,draftExists:Q,markDraftSaved:je}=Yt({editor:u,documentId:e.meta.documentId,displayName:m,enabled:e.canEdit,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId},seedDraftExists:e.hasLocalDraft});n.useEffect(()=>{var t;(t=e.onDraftExistsChange)==null||t.call(e,Q)},[Q,e.onDraftExistsChange]),Jt({isDirty:fe,draftExists:Q}),n.useEffect(()=>{if(u)try{u.setDocument(j,X)}catch{}},[u,e.meta.documentId,e.contentRevision,j]),n.useEffect(()=>{u==null||u.setLocale(l==="zh"?it:rt)},[u,l]),n.useEffect(()=>{R(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),n.useEffect(()=>{d(e.meta.permission)},[e.meta.permission,e.meta.documentId]),n.useEffect(()=>{let t=!0;return(async()=>{try{const i=await $e(e.meta.documentId);t&&E(i.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function re(){var t,i;if(!G){L(!0);try{k?(await pe(e.meta.documentId),E(!1),(t=e.onShowToast)==null||t.call(e,r("bookmarkRemoved"))):(await et(e.meta.documentId),E(!0),(i=e.onShowToast)==null||i.call(e,r("bookmarkAdded")))}finally{L(!1)}}}n.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=_e),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),n.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ie.current;if(!t)return"";try{const i=t.getDocument("markdown");return typeof i=="string"?i:String(i??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function Ae(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const Ne=n.useCallback(t=>{ie.current=t,de(t);const i=X;if(!i)return;const o=()=>{try{t.setDocument(j,i)}catch{requestAnimationFrame(()=>{try{t.setDocument(j,i)}catch{}})}};queueMicrotask(()=>{queueMicrotask(o)})},[j,X]);async function he(){if(!u||!e.canEdit)return;const t=document.querySelector(".mdocs-editor-scroll-host"),i=(t==null?void 0:t.scrollTop)??null;W(!0);try{const o=ue(u);if(!o)return;await e.onPublish(o,m,e.meta.documentId)}catch(o){throw o}finally{W(!1),t&&i!=null&&(t.scrollTop=i,requestAnimationFrame(()=>{t.scrollTop=i}))}}async function Te(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(m.trim()!==t)try{await he()}catch{}}const A=n.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),Pe=n.useMemo(()=>{const t=(A==null?void 0:A.permission)??"public";return Ke(t)},[A==null?void 0:A.permission]);function Be(t){return t===ee.PRIVATE?r("permissionPrivate"):t===ee.DOMAIN_READ?r("permissionInvite"):t===ee.DOMAIN_WRITE?r("permissionDomainWrite"):t===ee.PUBLIC_READ?r("permissionPublicRead"):r("permissionPublicEdit")}async function Le(){var t;if(h||w===e.meta.permission){P(!1);return}I(!0);try{const o=(u?ue(u):null)??e.initialContent;await e.onPublish(o,m,e.meta.documentId,w),P(!1),(t=e.onShowToast)==null||t.call(e,r("docInfoPermissionUpdated"))}finally{I(!1)}}async function Oe(t){var i;if(!b){$(!0);try{const o=new Set(t.map(s=>s.visitorId)),M=new Map(t.map(s=>[s.visitorId,s.permission]));for(const[s]of B)o.has(s)||await nt(e.meta.documentId,s);for(const{visitorId:s,permission:S}of t){const N=B.get(s);(!N||N!==S)&&await at(e.meta.documentId,s,S)}v(!1),(i=e.onShowToast)==null||i.call(e,r("docInfoInviteSuccess",{count:t.length}))}finally{$(!1)}}}async function _e(){if(!u||!e.canEdit)return;if(!fe){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=ue(u);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),je(),await be(e.meta.documentId).execute(()=>Ee({documentId:e.meta.documentId,content:t,displayName:m,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const ze=n.useMemo(()=>[{icon:Nt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(ce,{tag:"h1"})}},{icon:Tt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(ce,{tag:"h2"})}},{icon:Pt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(ce,{tag:"h3"})}},{type:"divider"},{icon:Bt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(ot,{})}},{icon:Lt,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(st,{columns:"3",rows:"3"})}},{icon:Ot,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(ct,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{zt(i=>{for(const o of i)t.dispatchCommand(Dt,{file:o})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(lt,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(ut,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(dt,void 0),queueMicrotask(()=>t.focus())}},{icon:_t,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(mt,void 0),queueMicrotask(()=>t.focus())}},{icon:Xe,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ft,void 0),queueMicrotask(()=>t.focus())}}].map(t=>"type"in t&&t.type==="divider"?t:{...t,extra:a.jsx("span",{style:{color:"var(--mdocs-text-muted)",fontFamily:"monospace",fontSize:12},children:t.key})}),[]),Fe=n.useMemo(()=>[ht,yt,gt,ke,vt,xt,It,kt,St,Ct,wt,le(bt,{children:u?a.jsx(Se,{editor:u,floating:!0,outlineCollapseTitle:r("outlineHide"),outlineExpandTitle:r("outlineShow"),outlineToggle:!0}):null}),le(Rt,{handleUpload:async t=>{var i;try{return{url:await Ie(t,e.meta.documentId)}}catch(o){throw(i=e.onShowError)==null||i.call(e,we(o)),o}}}),le(ke,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var i;try{const M=await(await fetch(t)).blob(),s=new File([M],"image.png",{type:M.type});return{url:await Ie(s,e.meta.documentId)}}catch(o){throw(i=e.onShowError)==null||i.call(e,we(o)),o}}})],[u,r,e.meta.documentId,e.onShowError]),O=!!e.readerChrome,[Y,oe]=n.useState(!1),Z=n.useRef(null),[He,se]=n.useState(0);n.useEffect(()=>{if(!O){oe(!1),se(0);return}if(Y)return;const t=window.setTimeout(()=>oe(!0),2800);return()=>window.clearTimeout(t)},[O,Y,e.meta.documentId]),n.useEffect(()=>{D(!1),y(!1)},[e.meta.documentId]);function Ue(t){!O||Y||t.target.closest("button, a, input, textarea, select")||(Z.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function qe(t){const i=Z.current;if(!(i!=null&&i.dragging))return;const o=t.clientY-i.startY;se(Math.max(-72,Math.min(0,o)))}function Ve(t){const i=Z.current;if(!(i!=null&&i.dragging))return;Z.current=null;const o=t.clientY-i.startY;se(0),o<-36&&oe(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function p(){y(!1),D(!1)}function ye(t,i){const o=(i==null?void 0:i.includeBookmark)??!0,M={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCreator")}),a.jsx("span",{children:f(e.meta.ownerVisitorId)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCreatedAt")}),a.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(l==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoSize")}),a.jsx("span",{children:Ae(new Blob([e.initialContent]).size)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCharCount")}),a.jsx("span",{children:K===null?"…":K.toLocaleString(l==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoUpdatedAt")}),a.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(l==="zh"?"zh-CN":"en-US")})]})]}),a.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{re(),t()},children:[a.jsx("span",{children:k?"⭐":"☆"}),a.jsx("span",{children:r(k?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{U(!0);try{const s=await tt(e.meta.documentId),S=new Map(s.map(N=>[N.visitorId,N.permission]));J(S),v(!0)}finally{U(!1)}})()},children:[a.jsx(qt,{size:14}),a.jsx("span",{children:r("docInfoInviteMember")})]}):null,a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),d(e.meta.permission),P(!0)},children:[a.jsx(Ht,{size:14}),a.jsx("span",{children:r("docInfoChangePermission")})]})]})}return a.jsxs("div",{className:"mdocs-editor"+(O?" mdocs-editor--reader":"")+(O&&Y?" mdocs-editor--reader-docked":""),children:[a.jsx(Ft,{fileType:e.meta.fileType||"md",displayName:m,onDisplayNameChange:R,onDisplayNameBlur:()=>void Te(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:ae,onEnterEdit:()=>De(!0),onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:V,draftExists:Q,onPublish:()=>{he().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:k,bookmarkBusy:G,onToggleBookmark:()=>void re(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:ye(p),docInfoOpen:g,onToggleDocInfo:()=>y(!g),docInfoMenuRef:F,readerChrome:O,onOpenMobileNav:e.onOpenMobileNav,readerHeaderDocked:Y,readerDragOffset:He,onReaderHeaderPointerDown:Ue,onReaderHeaderPointerMove:qe,onReaderHeaderPointerUp:Ve,readerMoreOpen:C,onToggleReaderMore:()=>D(t=>!t),readerMoreMenuRef:H,readerMoreMenu:a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:G,onClick:()=>{re(),p()},children:[a.jsx(Qe,{size:16,strokeWidth:1.5,style:{color:k?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:k?"#faad14":"none"}}),a.jsx("span",{children:r(k?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?a.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:V,onClick:()=>{p(),e.onDelete()},children:a.jsx("span",{children:r("delete")})}):null,a.jsx("div",{className:"mdocs-reader-more-divider"}),ye(p,{includeBookmark:!1})]})}),T&&a.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&P(!1)},children:a.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[a.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:r("docInfoChangePermission")}),a.jsxs("div",{className:"muted",style:{marginBottom:12},children:[r("domainPermission"),":",A?Ze(A.domainName,l,r):e.meta.domainId]}),a.jsx("div",{style:{display:"grid",gap:8},children:Pe.map(t=>a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[a.jsx("input",{type:"radio",name:"doc-permission",value:t,checked:w===t,onChange:()=>d(t)}),a.jsx("span",{children:Be(t)})]},t))}),a.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[a.jsx("button",{type:"button",onClick:()=>P(!1),children:r("cancel")}),a.jsx("button",{type:"button",className:"primary",disabled:h,onClick:()=>void Le(),children:r(h?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&a.jsx(Ut,{open:x,title:r("docInfoInviteMember"),initialSelectedIds:[...B.keys()],initialPermissions:B,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:r("invitePermissionRead")},{value:"edit",label:r("invitePermissionEdit")}],onClose:()=>v(!1),onConfirm:t=>{Oe(t)}}),a.jsx(Et,{children:a.jsx(ge,{flex:1,style:{minHeight:0},children:a.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[ae&&u&&!O?a.jsx(Se,{editor:u,outlineCollapseTitle:r("outlineHide"),outlineExpandTitle:r("outlineShow"),outlineToggle:!0}):null,a.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:a.jsxs(ge,{variant:"outlined",horizontal:!0,style:{background:"var(--mdocs-surface)",flex:1,minHeight:0,minWidth:0,borderRadius:0,outline:"none"},children:[a.jsx("div",{className:"mdocs-editor-scroll-host",children:Re?a.jsx(Mt,{content:X,type:j,confirmPasteMarkdown:!0,editable:ae,onInit:Ne,plugins:Fe,lineEmptyPlaceholder:r("displayNamePlaceholder"),placeholder:r("displayNamePlaceholder"),slashOption:{items:ze},className:"mdocs-document-editor-root"},e.meta.documentId):null}),u&&a.jsx(Kt,{editor:u})]})})]})})})]})}export{fn as DocumentEditor};
|
|
1
|
+
import{r as n,j as a}from"./react-vendor-BVS1XoFi.js";import{ad as ge}from"./ui-CEFkTVnG.js";import{g as be,u as Ee,a as ve,s as We,d as Ge,b as xe,c as Ye,f as Je,e as $e,h as Ke,N as Xe,S as Qe,l as Ze,r as pe,i as et,j as tt,D as ee,k as nt,m as at,n as Ie}from"./index-Kp5r4mc7.js";import{z as it,A as rt,m as ce,n as ot,o as st,p as ct,r as lt,s as ut,t as dt,v as mt,x as ft,B as ht,R as yt,a as gt,b as ke,c as vt,d as xt,e as It,f as kt,g as St,h as Ct,i as wt,w as le,j as bt,O as Et,E as Mt,q as Dt,l as Rt,C as jt,D as At}from"./react-DsdrF7vh.js";import{H as Nt,a as Tt,b as Pt,M as Bt,T as Lt,S as Ot,W as _t,o as zt,c as Se}from"./Toolbar-CPIpQgP1.js";import{D as Ft,S as Ht}from"./DocChrome-Dj5rSAvl.js";import{V as Ut,U as qt}from"./VisitorPickerModal-aRuuDomz.js";import{c as Vt}from"./docPlainCharCount-DO5lb3Wt.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./editor-DBWWidi3.js";import"./plus-D8tCpRfA.js";import"./copy-C_H9wgwB.js";import"./check-NyVbPIj8.js";import"./italic-BqrahN0G.js";import"./file-type-policy-5jFXMeIz.js";const Wt=48;function te(e){try{const r=e.getDocument("markdown");return typeof r=="string"?r:""}catch{return null}}function Gt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function Yt({editor:e,documentId:r,displayName:l,debounceMs:g=1e3,enabled:y=!0,localBaseCommitIdAtEditStart:C,snapshotMeta:D,seedDraftExists:F=!1}){const[H,_]=n.useState(!1),[ne,T]=n.useState(F),[P,w]=n.useState(null),d=n.useRef(null),h=n.useRef(null),I=n.useRef(!1),x=n.useRef(""),v=n.useRef(!1),z=n.useRef(r),U=n.useRef(l),B=n.useRef(C),J=n.useRef(D);z.current=r,U.current=l,B.current=C,J.current=D;const b=n.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const c=Gt(e);c!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",z.current,"content preview:",c.slice(0,80)),await be(z.current).execute(()=>Ee({documentId:z.current,content:c,displayName:U.current,localBaseCommitIdAtEditStart:B.current,snapshotMeta:J.current})),x.current=te(e)??x.current,T(!0),_(!1),w(Date.now()),I.current=!0,v.current=!1)},[e]);n.useEffect(()=>{let c=!1;const f=xe();return ve(r).then(m=>{if(c||xe()!==f)return;const R=!!(m&&!m.published);T(R),R&&m?(w(m.updatedAt),I.current=!0):(w(null),I.current=!1,v.current=!1)}),()=>{c=!0}},[r]),n.useEffect(()=>We((c,f)=>{c===z.current&&(T(f),f||(w(null),I.current=!1))}),[]),n.useEffect(()=>{var W,k;if(!y){(W=h.current)==null||W.call(h),h.current=null;return}if(!e)return;const c=e.getLexicalEditor();if(!c)return;(k=h.current)==null||k.call(h);let f=!1,m=0,R=0;const V=()=>{if(f)return;const E=te(e);if(E===null){if(R+=1,R>Wt)return;m=requestAnimationFrame(V);return}x.current=E;const G=c.registerUpdateListener(()=>{const L=te(e);L!==null&&L!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",r,"oldLen:",x.current.length,"newLen:",L.length),x.current=L,_(!0),v.current=!0,I.current=!1,d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,b()},g))});h.current=()=>{G(),d.current&&(clearTimeout(d.current),d.current=null)}};return queueMicrotask(()=>{f||(m=requestAnimationFrame(V))}),()=>{var E;f=!0,cancelAnimationFrame(m),(E=h.current)==null||E.call(h)}},[y,e,r,l,g,C,D,b]),n.useEffect(()=>{var m;if(!y||!e)return;const c=(m=e.getLexicalEditor())==null?void 0:m.getRootElement();if(!c)return;const f=()=>{d.current&&(clearTimeout(d.current),d.current=null),v.current&&b()};return c.addEventListener("blur",f),()=>c.removeEventListener("blur",f)},[y,e,b]),n.useEffect(()=>{if(!y)return;const c=()=>{document.visibilityState==="hidden"&&(d.current&&(clearTimeout(d.current),d.current=null),v.current&&b())},f=()=>{v.current&&(d.current&&(clearTimeout(d.current),d.current=null),b())};return document.addEventListener("visibilitychange",c),window.addEventListener("beforeunload",f),()=>{document.removeEventListener("visibilitychange",c),window.removeEventListener("beforeunload",f)}},[y,b]);async function $(){await Ge(r),T(!1),_(!1),v.current=!1,I.current=!1,x.current=""}async function K(){const c=await ve(r);return c?c.content:null}function q(){T(!0),_(!1),v.current=!1,w(Date.now()),I.current=!0,e&&(x.current=te(e)??"")}return{isDirty:H,draftExists:ne,lastSavedAt:P,clearDraft:$,loadDraftContent:K,markDraftSaved:q}}function Jt({isDirty:e,draftExists:r}){const l=e&&!r;n.useEffect(()=>{if(!l)return;const g=y=>{y.preventDefault()};return window.addEventListener("beforeunload",g),()=>window.removeEventListener("beforeunload",g)},[l])}function ue(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Ce='{"root":{"direction":"ltr","format":"","indent":0,"version":1,"type":"root","children":[{"direction":"ltr","format":"","indent":0,"version":1,"textFormat":0,"textStyle":"","children":[],"type":"paragraph"}]}}';function we(e){const l=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(l)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(l)?"不支持的文件类型":/^not an image$/i.test(l)?"不是有效的图片文件":l||"上传失败"}function $t(e,r){if(!e)return r==="json"?Ce:e;if(r!=="json")return e;try{const l=JSON.parse(e);if(l!=null&&l.root&&Array.isArray(l.root.children)&&l.root.children.length===0)return Ce}catch{}return e}function Kt({editor:e}){const{visible:r}=jt();return a.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:r?200:0},children:a.jsx("div",{style:{width:200},children:a.jsx(At,{editor:e})})})}function fn(e){const{t:r,lang:l}=Ye(),[g,y]=n.useState(!1),[C,D]=n.useState(!1),F=n.useRef(null),H=n.useRef(null),[_,ne]=n.useState([]),[T,P]=n.useState(!1),[w,d]=n.useState(e.meta.permission),[h,I]=n.useState(!1),[x,v]=n.useState(!1),[z,U]=n.useState(!1),[B,J]=n.useState(new Map),[b,$]=n.useState(!1),[K,q]=n.useState(null),c=n.useRef(0);n.useEffect(()=>{const t=i=>{F.current&&!F.current.contains(i.target)&&y(!1),H.current&&!H.current.contains(i.target)&&D(!1)};return(g||C)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[g,C]),n.useEffect(()=>{let t=!0;return Je().then(i=>{t&&ne(i)}).catch(()=>{}),()=>{t=!1}},[]);function f(t){const i=_.find(o=>o.visitorId===t);return(i==null?void 0:i.visitorName)??t.slice(0,8)}const[m,R]=n.useState(e.initialDisplayName),[V,W]=n.useState(!1),[k,E]=n.useState(!1),[G,L]=n.useState(!1),[Me,De]=n.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),ae=e.canEdit&&Me,[u,de]=n.useState(null),[Re,me]=n.useState(!1),ie=n.useRef(null);n.useLayoutEffect(()=>{me(!1),de(null),ie.current=null},[e.meta.documentId]),n.useEffect(()=>{const t=requestAnimationFrame(()=>me(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]),n.useEffect(()=>{if(!g&&!C)return;const t=++c.current;q(null);const i=()=>{if(t===c.current)try{let s=e.initialContent||"";if(u)try{const N=u.getDocument("markdown");typeof N=="string"&&(s=N)}catch{}const S=Vt("md",s);t===c.current&&q(S)}catch{t===c.current&&q(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const s=o.requestIdleCallback(i);return()=>{var S;return(S=o.cancelIdleCallback)==null?void 0:S.call(o,s)}}const M=window.setTimeout(i,0);return()=>window.clearTimeout(M)},[g,C,u,e.initialContent,e.meta.documentId,e.contentRevision]);const j=n.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const i=JSON.parse(e.initialContent);return Array.isArray((t=i==null?void 0:i.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),X=n.useMemo(()=>$t(e.initialContent||"",j),[e.initialContent,j,e.contentRevision]),{isDirty:fe,draftExists:Q,markDraftSaved:je}=Yt({editor:u,documentId:e.meta.documentId,displayName:m,enabled:e.canEdit,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId},seedDraftExists:e.hasLocalDraft});n.useEffect(()=>{var t;(t=e.onDraftExistsChange)==null||t.call(e,Q)},[Q,e.onDraftExistsChange]),Jt({isDirty:fe,draftExists:Q}),n.useEffect(()=>{if(u)try{u.setDocument(j,X)}catch{}},[u,e.meta.documentId,e.contentRevision,j]),n.useEffect(()=>{u==null||u.setLocale(l==="zh"?it:rt)},[u,l]),n.useEffect(()=>{R(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),n.useEffect(()=>{d(e.meta.permission)},[e.meta.permission,e.meta.documentId]),n.useEffect(()=>{let t=!0;return(async()=>{try{const i=await $e(e.meta.documentId);t&&E(i.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function re(){var t,i;if(!G){L(!0);try{k?(await pe(e.meta.documentId),E(!1),(t=e.onShowToast)==null||t.call(e,r("bookmarkRemoved"))):(await et(e.meta.documentId),E(!0),(i=e.onShowToast)==null||i.call(e,r("bookmarkAdded")))}finally{L(!1)}}}n.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=_e),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),n.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ie.current;if(!t)return"";try{const i=t.getDocument("markdown");return typeof i=="string"?i:String(i??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function Ae(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const Ne=n.useCallback(t=>{ie.current=t,de(t);const i=X;if(!i)return;const o=()=>{try{t.setDocument(j,i)}catch{requestAnimationFrame(()=>{try{t.setDocument(j,i)}catch{}})}};queueMicrotask(()=>{queueMicrotask(o)})},[j,X]);async function he(){if(!u||!e.canEdit)return;const t=document.querySelector(".mdocs-editor-scroll-host"),i=(t==null?void 0:t.scrollTop)??null;W(!0);try{const o=ue(u);if(!o)return;await e.onPublish(o,m,e.meta.documentId)}catch(o){throw o}finally{W(!1),t&&i!=null&&(t.scrollTop=i,requestAnimationFrame(()=>{t.scrollTop=i}))}}async function Te(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(m.trim()!==t)try{await he()}catch{}}const A=n.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),Pe=n.useMemo(()=>{const t=(A==null?void 0:A.permission)??"public";return Ke(t)},[A==null?void 0:A.permission]);function Be(t){return t===ee.PRIVATE?r("permissionPrivate"):t===ee.DOMAIN_READ?r("permissionInvite"):t===ee.DOMAIN_WRITE?r("permissionDomainWrite"):t===ee.PUBLIC_READ?r("permissionPublicRead"):r("permissionPublicEdit")}async function Le(){var t;if(h||w===e.meta.permission){P(!1);return}I(!0);try{const o=(u?ue(u):null)??e.initialContent;await e.onPublish(o,m,e.meta.documentId,w),P(!1),(t=e.onShowToast)==null||t.call(e,r("docInfoPermissionUpdated"))}finally{I(!1)}}async function Oe(t){var i;if(!b){$(!0);try{const o=new Set(t.map(s=>s.visitorId)),M=new Map(t.map(s=>[s.visitorId,s.permission]));for(const[s]of B)o.has(s)||await nt(e.meta.documentId,s);for(const{visitorId:s,permission:S}of t){const N=B.get(s);(!N||N!==S)&&await at(e.meta.documentId,s,S)}v(!1),(i=e.onShowToast)==null||i.call(e,r("docInfoInviteSuccess",{count:t.length}))}finally{$(!1)}}}async function _e(){if(!u||!e.canEdit)return;if(!fe){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=ue(u);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),je(),await be(e.meta.documentId).execute(()=>Ee({documentId:e.meta.documentId,content:t,displayName:m,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const ze=n.useMemo(()=>[{icon:Nt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(ce,{tag:"h1"})}},{icon:Tt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(ce,{tag:"h2"})}},{icon:Pt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(ce,{tag:"h3"})}},{type:"divider"},{icon:Bt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(ot,{})}},{icon:Lt,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(st,{columns:"3",rows:"3"})}},{icon:Ot,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(ct,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{zt(i=>{for(const o of i)t.dispatchCommand(Dt,{file:o})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(lt,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(ut,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(dt,void 0),queueMicrotask(()=>t.focus())}},{icon:_t,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(mt,void 0),queueMicrotask(()=>t.focus())}},{icon:Xe,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ft,void 0),queueMicrotask(()=>t.focus())}}].map(t=>"type"in t&&t.type==="divider"?t:{...t,extra:a.jsx("span",{style:{color:"var(--mdocs-text-muted)",fontFamily:"monospace",fontSize:12},children:t.key})}),[]),Fe=n.useMemo(()=>[ht,yt,gt,ke,vt,xt,It,kt,St,Ct,wt,le(bt,{children:u?a.jsx(Se,{editor:u,floating:!0,outlineCollapseTitle:r("outlineHide"),outlineExpandTitle:r("outlineShow"),outlineToggle:!0}):null}),le(Rt,{handleUpload:async t=>{var i;try{return{url:await Ie(t,e.meta.documentId)}}catch(o){throw(i=e.onShowError)==null||i.call(e,we(o)),o}}}),le(ke,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var i;try{const M=await(await fetch(t)).blob(),s=new File([M],"image.png",{type:M.type});return{url:await Ie(s,e.meta.documentId)}}catch(o){throw(i=e.onShowError)==null||i.call(e,we(o)),o}}})],[u,r,e.meta.documentId,e.onShowError]),O=!!e.readerChrome,[Y,oe]=n.useState(!1),Z=n.useRef(null),[He,se]=n.useState(0);n.useEffect(()=>{if(!O){oe(!1),se(0);return}if(Y)return;const t=window.setTimeout(()=>oe(!0),2800);return()=>window.clearTimeout(t)},[O,Y,e.meta.documentId]),n.useEffect(()=>{D(!1),y(!1)},[e.meta.documentId]);function Ue(t){!O||Y||t.target.closest("button, a, input, textarea, select")||(Z.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function qe(t){const i=Z.current;if(!(i!=null&&i.dragging))return;const o=t.clientY-i.startY;se(Math.max(-72,Math.min(0,o)))}function Ve(t){const i=Z.current;if(!(i!=null&&i.dragging))return;Z.current=null;const o=t.clientY-i.startY;se(0),o<-36&&oe(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function p(){y(!1),D(!1)}function ye(t,i){const o=(i==null?void 0:i.includeBookmark)??!0,M={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCreator")}),a.jsx("span",{children:f(e.meta.ownerVisitorId)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCreatedAt")}),a.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(l==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoSize")}),a.jsx("span",{children:Ae(new Blob([e.initialContent]).size)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCharCount")}),a.jsx("span",{children:K===null?"…":K.toLocaleString(l==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoUpdatedAt")}),a.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(l==="zh"?"zh-CN":"en-US")})]})]}),a.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{re(),t()},children:[a.jsx("span",{children:k?"⭐":"☆"}),a.jsx("span",{children:r(k?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{U(!0);try{const s=await tt(e.meta.documentId),S=new Map(s.map(N=>[N.visitorId,N.permission]));J(S),v(!0)}finally{U(!1)}})()},children:[a.jsx(qt,{size:14}),a.jsx("span",{children:r("docInfoInviteMember")})]}):null,a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),d(e.meta.permission),P(!0)},children:[a.jsx(Ht,{size:14}),a.jsx("span",{children:r("docInfoChangePermission")})]})]})}return a.jsxs("div",{className:"mdocs-editor"+(O?" mdocs-editor--reader":"")+(O&&Y?" mdocs-editor--reader-docked":""),children:[a.jsx(Ft,{fileType:e.meta.fileType||"md",displayName:m,onDisplayNameChange:R,onDisplayNameBlur:()=>void Te(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:ae,onEnterEdit:()=>De(!0),onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:V,draftExists:Q,onPublish:()=>{he().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:k,bookmarkBusy:G,onToggleBookmark:()=>void re(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:ye(p),docInfoOpen:g,onToggleDocInfo:()=>y(!g),docInfoMenuRef:F,readerChrome:O,onOpenMobileNav:e.onOpenMobileNav,readerHeaderDocked:Y,readerDragOffset:He,onReaderHeaderPointerDown:Ue,onReaderHeaderPointerMove:qe,onReaderHeaderPointerUp:Ve,readerMoreOpen:C,onToggleReaderMore:()=>D(t=>!t),readerMoreMenuRef:H,readerMoreMenu:a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:G,onClick:()=>{re(),p()},children:[a.jsx(Qe,{size:16,strokeWidth:1.5,style:{color:k?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:k?"#faad14":"none"}}),a.jsx("span",{children:r(k?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?a.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:V,onClick:()=>{p(),e.onDelete()},children:a.jsx("span",{children:r("delete")})}):null,a.jsx("div",{className:"mdocs-reader-more-divider"}),ye(p,{includeBookmark:!1})]})}),T&&a.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&P(!1)},children:a.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[a.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:r("docInfoChangePermission")}),a.jsxs("div",{className:"muted",style:{marginBottom:12},children:[r("domainPermission"),":",A?Ze(A.domainName,l,r):e.meta.domainId]}),a.jsx("div",{style:{display:"grid",gap:8},children:Pe.map(t=>a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[a.jsx("input",{type:"radio",name:"doc-permission",value:t,checked:w===t,onChange:()=>d(t)}),a.jsx("span",{children:Be(t)})]},t))}),a.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[a.jsx("button",{type:"button",onClick:()=>P(!1),children:r("cancel")}),a.jsx("button",{type:"button",className:"primary",disabled:h,onClick:()=>void Le(),children:r(h?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&a.jsx(Ut,{open:x,title:r("docInfoInviteMember"),initialSelectedIds:[...B.keys()],initialPermissions:B,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:r("invitePermissionRead")},{value:"edit",label:r("invitePermissionEdit")}],onClose:()=>v(!1),onConfirm:t=>{Oe(t)}}),a.jsx(Et,{children:a.jsx(ge,{flex:1,style:{minHeight:0},children:a.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[ae&&u&&!O?a.jsx(Se,{editor:u,outlineCollapseTitle:r("outlineHide"),outlineExpandTitle:r("outlineShow"),outlineToggle:!0}):null,a.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:a.jsxs(ge,{variant:"outlined",horizontal:!0,style:{background:"var(--mdocs-surface)",flex:1,minHeight:0,minWidth:0,borderRadius:0,outline:"none"},children:[a.jsx("div",{className:"mdocs-editor-scroll-host",children:Re?a.jsx(Mt,{content:X,type:j,confirmPasteMarkdown:!0,editable:ae,onInit:Ne,plugins:Fe,lineEmptyPlaceholder:r("displayNamePlaceholder"),placeholder:r("displayNamePlaceholder"),slashOption:{items:ze},className:"mdocs-document-editor-root"},e.meta.documentId):null}),u&&a.jsx(Kt,{editor:u})]})})]})})})]})}export{fn as DocumentEditor};
|