This commit is contained in:
Jeffrey Chen 2025-12-16 17:04:18 +08:00 committed by GitHub
commit 6258318728
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,24 +31,30 @@ import {emitOpenMenu} from "../plugin/EventBus";
import {openByMobile} from "../protyle/util/compatibility"; import {openByMobile} from "../protyle/util/compatibility";
import {addFilesToDatabase} from "../protyle/render/av/addToDatabase"; import {addFilesToDatabase} from "../protyle/render/av/addToDatabase";
const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => { const initMultiMenu = (selectItemElements: Element[], app: App) => {
window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_ITEMS); window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_ITEMS);
const fileItemElement = Array.from(selectItemElements).find(item => { const items: { id: string, path: string }[] = [];
if (item.getAttribute("data-type") === "navigation-file") {
return true;
}
});
if (!fileItemElement) {
return window.siyuan.menus.menu;
}
const blockIDs: string[] = []; const blockIDs: string[] = [];
selectItemElements.forEach(item => { const fileItemElements = selectItemElements.filter(item => {
if (item.getAttribute("data-type") === "navigation-file") {
const id = item.getAttribute("data-node-id"); const id = item.getAttribute("data-node-id");
if (id) { const path = item.getAttribute("data-path");
if (id && path) {
items.push({
id: id,
path: path,
});
blockIDs.push(id); blockIDs.push(id);
} }
return true;
}
return false;
}); });
if (fileItemElements.length === 0) {
return window.siyuan.menus.menu;
}
if (blockIDs.length > 0) { if (blockIDs.length > 0) {
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
id: "copy", id: "copy",
@ -70,11 +76,7 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
}]) }])
}).element); }).element);
} }
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(fileItemElements)));
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(
Array.from(selectItemElements)
)));
if (blockIDs.length > 0) { if (blockIDs.length > 0) {
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
id: "addToDatabase", id: "addToDatabase",
@ -82,7 +84,7 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom, accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
icon: "iconDatabase", icon: "iconDatabase",
click: () => { click: () => {
addFilesToDatabase(Array.from(selectItemElements)); addFilesToDatabase(fileItemElements);
} }
}).element); }).element);
} }
@ -92,13 +94,14 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
label: window.siyuan.languages.delete, label: window.siyuan.languages.delete,
accelerator: "⌦", accelerator: "⌦",
click: () => { click: () => {
deleteFiles(Array.from(selectItemElements)); deleteFiles(fileItemElements);
} }
}).element); }).element);
if (blockIDs.length === 0) { if (blockIDs.length === 0) {
return window.siyuan.menus.menu; return window.siyuan.menus.menu;
} }
window.siyuan.menus.menu.append(new MenuItem({id: "separator_1", type: "separator"}).element); window.siyuan.menus.menu.append(new MenuItem({id: "separator_1", type: "separator"}).element);
if (!window.siyuan.config.readonly) { if (!window.siyuan.config.readonly) {
const riffCardMenu = [{ const riffCardMenu = [{
@ -177,8 +180,9 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
plugins: app.plugins, plugins: app.plugins,
type: "open-menu-doctree", type: "open-menu-doctree",
detail: { detail: {
elements: selectItemElements, elements: fileItemElements,
type: "docs" type: "docs",
items,
}, },
separatorPosition: "top", separatorPosition: "top",
}); });
@ -201,7 +205,7 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
}); });
liElement.classList.add("b3-list-item--focus"); liElement.classList.add("b3-list-item--focus");
} }
const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus"); const selectItemElements = Array.from(fileElement.querySelectorAll(".b3-list-item--focus"));
if (selectItemElements.length > 1) { if (selectItemElements.length > 1) {
return initMultiMenu(selectItemElements, app); return initMultiMenu(selectItemElements, app);
} }
@ -410,7 +414,8 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
type: "open-menu-doctree", type: "open-menu-doctree",
detail: { detail: {
elements: selectItemElements, elements: selectItemElements,
type: "notebook" type: "notebook",
items: [{id: notebookId, path: "/"}],
}, },
separatorPosition: "top", separatorPosition: "top",
}); });
@ -433,11 +438,12 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
}); });
liElement.classList.add("b3-list-item--focus"); liElement.classList.add("b3-list-item--focus");
} }
const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus"); const selectItemElements = Array.from(fileElement.querySelectorAll(".b3-list-item--focus"));
if (selectItemElements.length > 1) { if (selectItemElements.length > 1) {
return initMultiMenu(selectItemElements, app); return initMultiMenu(selectItemElements, app);
} }
const id = liElement.getAttribute("data-node-id"); const id = liElement.getAttribute("data-node-id");
const path = liElement.getAttribute("data-path");
let name = liElement.getAttribute("data-name"); let name = liElement.getAttribute("data-name");
name = getDisplayName(name, false, true); name = getDisplayName(name, false, true);
if (!window.siyuan.config.readonly) { if (!window.siyuan.config.readonly) {
@ -705,7 +711,8 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
type: "open-menu-doctree", type: "open-menu-doctree",
detail: { detail: {
elements: selectItemElements, elements: selectItemElements,
type: "doc" type: "doc",
items: [{id, path}],
}, },
separatorPosition: "top", separatorPosition: "top",
}); });