Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Initialize all publishing dock menu titles https://github.com/siyuan-note/siyuan/issues/19801

Daniel470af5a83abc
diff --git a/app/src/layout/dock/initialization.test.ts b/app/src/layout/dock/initialization.test.ts
new file mode 100644
index 0000000000..47d6a863bf
--- /dev/null
+++ b/app/src/layout/dock/initialization.test.ts
@@ -0,0 +1,29 @@
+import * as assert from "node:assert/strict";
+import {readFileSync} from "node:fs";
+import {join} from "node:path";
+import {test} from "node:test";
+import {transpileModule, ScriptTarget} from "typescript";
+
+test("publishing removes unavailable docks without skipping adjacent titles", () => {
+ const source = readFileSync(join(__dirname, "../util.ts"), "utf8");
+ const start = source.indexOf("const initInternalDock =");
+ const end = source.indexOf("const JSONToDock =", start);
+ const compiled = transpileModule(source.slice(start, end), {
+ compilerOptions: {target: ScriptTarget.ES2020},
+ }).outputText;
+ const languages = {graphView: "Graph View", globalGraph: "Global Graph", bookmark: "Bookmarks"};
+ for (const isPublish of [true, false]) {
+ const init = new Function("window", "isDisabledFeature", compiled + "return initInternalDock;")(
+ {siyuan: {isPublish, languages}}, () => !isPublish);
+ const docks = [
+ {type: "agentChat", hotkeyLangId: "agentChat"},
+ ...(isPublish ? [{type: "inbox", hotkeyLangId: "inbox"}] : []),
+ {type: "graph", hotkeyLangId: "graphView"},
+ {type: "globalGraph", hotkeyLangId: "globalGraph"},
+ {type: "bookmark", hotkeyLangId: "bookmark"},
+ ];
+ init(docks);
+ assert.deepEqual(docks.map(item => item.type), ["graph", "globalGraph", "bookmark"]);
+ assert.deepEqual(docks.map(item => (item as {title?: string}).title), Object.values(languages));
+ }
+});
diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts
index 25bdac546c..b0fa139f54 100644
--- a/app/src/layout/util.ts
+++ b/app/src/layout/util.ts
@@ -331,16 +331,17 @@ const ensureAgentChatDock = (layout: Pick<Config.IUiLayout, "left" | "right" | "
};
const initInternalDock = (dockItem: Config.IUILayoutDockTab[]) => {
- dockItem.forEach((existSubItem, index) => {
+ for (let index = dockItem.length - 1; index >= 0; index--) {
+ const existSubItem = dockItem[index];
if ((window.siyuan.isPublish && (existSubItem.type === "inbox" || existSubItem.type === "agentChat")) ||
(isDisabledFeature("ai") && existSubItem.type === "agentChat")) {
dockItem.splice(index, 1);
- return;
+ continue;
}
if (existSubItem.hotkeyLangId) {
existSubItem.title = window.siyuan.languages[existSubItem.hotkeyLangId];
}
- });
+ }
};
const JSONToDock = (json: any, app: App) => {