Skip to content

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

:sparkles: Support notebook IDs in document tree menu events https://github.com/siyuan-note/siyuan/issues/18759

Daniel73d5dd14f30e
diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts
index 60285dc3f2..734d6391cb 100644
--- a/app/src/menus/navigation.ts
+++ b/app/src/menus/navigation.ts
@@ -633,7 +633,7 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
detail: {
elements: selectItemElements,
type: "notebook",
- items: [{id: notebookId, path: "/"}],
+ items: [{id: notebookId, path: "/", notebookId}],
},
separatorPosition: "top",
});
@@ -945,7 +945,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
detail: {
elements: selectItemElements,
type: "doc",
- items: [{id, path: pathString}],
+ items: [{id, path: pathString, notebookId}],
},
separatorPosition: "top",
});
diff --git a/app/src/menus/navigationSelection.test.ts b/app/src/menus/navigationSelection.test.ts
index 0425764956..604f6e5be5 100644
--- a/app/src/menus/navigationSelection.test.ts
+++ b/app/src/menus/navigationSelection.test.ts
@@ -4,7 +4,7 @@ import {getDocTreeDeleteTargets, getDocTreeMenuItems, getDocTreeMenuType} from "
const createItem = (type: "navigation-file" | "navigation-root", options: {
id?: string,
- notebookId: string,
+ notebookId?: string,
path: string,
}) => ({
getAttribute(name: string) {
@@ -25,14 +25,14 @@ const createItem = (type: "navigation-file" | "navigation-root", options: {
}
return {
getAttribute(name: string) {
- return name === "data-url" ? options.notebookId : null;
+ return name === "data-url" ? options.notebookId || null : null;
}
};
},
}) as unknown as HTMLElement;
const doc1 = createItem("navigation-file", {id: "doc-1", notebookId: "notebook-1", path: "/doc-1.sy"});
-const doc2 = createItem("navigation-file", {id: "doc-2", notebookId: "notebook-1", path: "/doc-2.sy"});
+const doc2 = createItem("navigation-file", {id: "doc-2", notebookId: "notebook-2", path: "/doc-2.sy"});
const notebook1 = createItem("navigation-root", {id: "box-doc-1", notebookId: "notebook-1", path: "/"});
const notebook2 = createItem("navigation-root", {notebookId: "notebook-2", path: "/"});
@@ -45,16 +45,20 @@ test("document tree menu type distinguishes all selection kinds", () => {
});
test("document tree menu items contain document and notebook identifiers", () => {
- assert.deepEqual(getDocTreeMenuItems([doc1, notebook1, notebook2]), [
- {id: "doc-1", path: "/doc-1.sy"},
- {id: "notebook-1", path: "/"},
- {id: "notebook-2", path: "/"},
+ assert.deepEqual(getDocTreeMenuItems([doc1, doc2, notebook1, notebook2]), [
+ {id: "doc-1", path: "/doc-1.sy", notebookId: "notebook-1"},
+ {id: "doc-2", path: "/doc-2.sy", notebookId: "notebook-2"},
+ {id: "notebook-1", path: "/", notebookId: "notebook-1"},
+ {id: "notebook-2", path: "/", notebookId: "notebook-2"},
]);
});
test("document tree menu items omit incomplete elements", () => {
const missingID = createItem("navigation-file", {notebookId: "notebook-1", path: "/missing.sy"});
- assert.deepEqual(getDocTreeMenuItems([doc1, missingID]), [{id: "doc-1", path: "/doc-1.sy"}]);
+ const missingNotebookID = createItem("navigation-file", {id: "doc-3", path: "/doc-3.sy"});
+ assert.deepEqual(getDocTreeMenuItems([doc1, missingID, missingNotebookID]), [
+ {id: "doc-1", path: "/doc-1.sy", notebookId: "notebook-1"},
+ ]);
});
test("mixed document tree deletion includes documents and notebooks", () => {
diff --git a/app/src/menus/navigationSelection.ts b/app/src/menus/navigationSelection.ts
index 07faf589d4..eae33ca889 100644
--- a/app/src/menus/navigationSelection.ts
+++ b/app/src/menus/navigationSelection.ts
@@ -12,11 +12,15 @@ export const getDocTreeMenuType = (elements: Element[]): TDocTreeMenuType => {
return "items";
};
-export const getDocTreeMenuItems = (elements: Element[]) => elements.map((item) => ({
- id: item.getAttribute("data-type") === "navigation-root" ?
- item.closest("ul[data-url]")?.getAttribute("data-url") : item.getAttribute("data-node-id"),
- path: item.getAttribute("data-path"),
-})).filter((item): item is { id: string, path: string } => Boolean(item.id && item.path));
+export const getDocTreeMenuItems = (elements: Element[]) => elements.map((item) => {
+ const notebookId = item.closest("ul[data-url]")?.getAttribute("data-url");
+ return {
+ id: item.getAttribute("data-type") === "navigation-root" ? notebookId : item.getAttribute("data-node-id"),
+ path: item.getAttribute("data-path"),
+ notebookId,
+ };
+}).filter((item): item is { id: string, path: string, notebookId: string } =>
+ Boolean(item.id && item.path && item.notebookId));
export const getDocTreeDeleteTargets = (elements: Element[]) => {
const items = getDocTreeMenuItems(elements);