🎨 Improve #commonMenu menu (#16147)

This commit is contained in:
Jeffrey Chen 2025-10-18 22:09:56 +08:00 committed by GitHub
parent 2c23d05c7c
commit 3922ca0cd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 17 additions and 11 deletions

View file

@ -228,7 +228,7 @@ export class BlockPanel {
this.targetElement = undefined;
// 移除弹出上使用右键菜单
const menuLevel = parseInt(window.siyuan.menus.menu.element.dataset.from);
if (window.siyuan.menus.menu.element.dataset.from !== "app" && menuLevel && menuLevel >= level) {
if (menuLevel && menuLevel >= level && window.siyuan.menus.menu.element.dataset.from.includes("popover")) {
// https://github.com/siyuan-note/siyuan/issues/9854 右键菜单不是从浮窗中弹出的则不进行移除
window.siyuan.menus.menu.remove();
}

View file

@ -236,13 +236,15 @@ export abstract class Constants {
public static readonly MENU_BLOCK_SINGLE = "block-single"; // 单选块菜单
public static readonly MENU_BLOCK_MULTI = "block-multi"; // 多选块菜单
public static readonly MENU_TITLE = "titleMenu"; // 文档块菜单
public static readonly MENU_FROM_TITLE_PROTYLE = "title-protyle"; // 在 Protyle 触发的文档块菜单
public static readonly MENU_FROM_TITLE_BREADCRUMB = "title-breadcrumb"; // 在面包屑触发的文档块菜单
public static readonly MENU_BREADCRUMB_MORE = "breadcrumbMore"; // 面包屑更多菜单
public static readonly MENU_BREADCRUMB_MOBILE_PATH = "breadcrumb-mobile-path"; // 移动端面包屑菜单
public static readonly MENU_DOC_TREE_MORE = "docTreeMore"; // 侧栏文档树右键菜单
public static readonly MENU_DOC_TREE_MORE_NOTEBOOK = "docTreeMore-notebook"; // 侧栏文档树右键菜单,单个笔记本
public static readonly MENU_DOC_TREE_MORE_DOC = "docTreeMore-doc"; // 侧栏文档树右键菜单,单个文档
public static readonly MENU_DOC_TREE_MORE_DOCS = "docTreeMore-docs"; // 侧栏文档树右键菜单,多个文档
public static readonly MENU_FROM_DOC_TREE_MORE_NOTEBOOK = "tree-notebook"; // 侧栏文档树右键菜单,单个笔记本
public static readonly MENU_FROM_DOC_TREE_MORE_DOC = "tree-doc"; // 侧栏文档树右键菜单,单个文档
public static readonly MENU_FROM_DOC_TREE_MORE_DOCS = "tree-docs"; // 侧栏文档树右键菜单,多个文档
public static readonly MENU_TAG = "tagMenu"; // 侧栏标签菜单
public static readonly MENU_BOOKMARK = "bookmarkMenu"; // 侧栏书签菜单
public static readonly MENU_OUTLINE_CONTEXT = "outline-context"; // 大纲标题右键菜单

View file

@ -120,7 +120,7 @@ export class Menu {
this.element.classList.remove("b3-menu--list", "b3-menu--fullscreen");
this.element.removeAttribute("style"); // zIndex
this.element.removeAttribute("data-name"); // 标识再次点击不消失
this.element.removeAttribute("data-from"); // 标识是否在浮窗内打开
this.element.removeAttribute("data-from"); // 标识菜单入口
this.data = undefined; // 移除数据
}

View file

@ -32,6 +32,7 @@ import {openByMobile} from "../protyle/util/compatibility";
import {addFilesToDatabase} from "../protyle/render/av/addToDatabase";
const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_DOCS);
const fileItemElement = Array.from(selectItemElements).find(item => {
if (item.getAttribute("data-type") === "navigation-file") {
return true;
@ -203,6 +204,8 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus");
if (selectItemElements.length > 1) {
return initMultiMenu(selectItemElements, app);
} else {
window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_NOTEBOOK);
}
const notebookId = liElement.parentElement.getAttribute("data-url");
const name = getNotebookName(notebookId);
@ -708,6 +711,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
separatorPosition: "top",
});
}
window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_DOC);
return window.siyuan.menus.menu;
};

View file

@ -97,7 +97,7 @@ ${padHTML}
});
} else {
const targetRect = target.getBoundingClientRect();
openTitleMenu(protyle, {x: targetRect.right, y: targetRect.bottom, isLeft: true});
openTitleMenu(protyle, {x: targetRect.right, y: targetRect.bottom, isLeft: true}, Constants.MENU_FROM_TITLE_BREADCRUMB);
}
event.stopPropagation();
event.preventDefault();

View file

@ -194,7 +194,7 @@ export class Title {
});
} else {
const iconRect = iconElement.getBoundingClientRect();
openTitleMenu(protyle, {x: iconRect.left, y: iconRect.bottom});
openTitleMenu(protyle, {x: iconRect.left, y: iconRect.bottom}, Constants.MENU_FROM_TITLE_PROTYLE);
}
});
this.element.addEventListener("contextmenu", (event) => {
@ -202,7 +202,7 @@ export class Title {
return;
}
if (getSelection().rangeCount === 0 || iconElement.contains((event.target as HTMLElement))) {
openTitleMenu(protyle, {x: event.clientX, y: event.clientY});
openTitleMenu(protyle, {x: event.clientX, y: event.clientY}, Constants.MENU_FROM_TITLE_PROTYLE);
return;
}
protyle.toolbar?.element.classList.add("fn__none");

View file

@ -26,7 +26,7 @@ import {addEditorToDatabase} from "../render/av/addToDatabase";
import {openFileById} from "../../editor/util";
import {hasTopClosestByClassName} from "../util/hasClosest";
export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
export const openTitleMenu = (protyle: IProtyle, position: IPosition, from: string) => {
hideTooltip();
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
window.siyuan.menus.menu.element.getAttribute("data-name") === Constants.MENU_TITLE) {
@ -38,6 +38,8 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
}, (response) => {
window.siyuan.menus.menu.remove();
window.siyuan.menus.menu.element.setAttribute("data-name", Constants.MENU_TITLE);
const popoverElement = hasTopClosestByClassName(protyle.element, "block__popover", true);
window.siyuan.menus.menu.element.setAttribute("data-from", popoverElement ? popoverElement.dataset.level + "popover-" + from : "app-" + from);
window.siyuan.menus.menu.append(new MenuItem({
id: "copy",
label: window.siyuan.languages.copy,
@ -293,7 +295,5 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
/// #else
window.siyuan.menus.menu.popup(position);
/// #endif
const popoverElement = hasTopClosestByClassName(protyle.element, "block__popover", true);
window.siyuan.menus.menu.element.setAttribute("data-from", popoverElement ? popoverElement.dataset.level + "popover" : "app");
});
};