An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve #commonMenu menu (#16147)
Jeffrey Chen3922ca0cd4a7
diff --git a/app/src/block/Panel.ts b/app/src/block/Panel.tsindex c72ebf302e..c1087d7057 100644--- a/app/src/block/Panel.ts+++ b/app/src/block/Panel.ts@@ -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();}diff --git a/app/src/constants.ts b/app/src/constants.tsindex c70af26719..aed6de001a 100644--- a/app/src/constants.ts+++ b/app/src/constants.ts@@ -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"; // 大纲标题右键菜单diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.tsindex 209c91cc7d..8d7915b9ec 100644--- a/app/src/menus/Menu.ts+++ b/app/src/menus/Menu.ts@@ -120,7 +120,7 @@ export class Menu {this.element.classList.remove("b3-menu--list", "b3-menu--fullscreen");this.element.removeAttribute("style"); // zIndexthis.element.removeAttribute("data-name"); // 标识再次点击不消失- this.element.removeAttribute("data-from"); // 标识是否在浮窗内打开+ this.element.removeAttribute("data-from"); // 标识菜单入口this.data = undefined; // 移除数据}diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.tsindex da764a800a..aa3ec72d8f 100644--- a/app/src/menus/navigation.ts+++ b/app/src/menus/navigation.ts@@ -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, lseparatorPosition: "top",});}+ window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_DOC);return window.siyuan.menus.menu;};diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.tsindex 48d55556e0..70e09aa80c 100644--- a/app/src/protyle/breadcrumb/index.ts+++ b/app/src/protyle/breadcrumb/index.ts@@ -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();diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.tsindex 5aa47dbbda..a2008d0593 100644--- a/app/src/protyle/header/Title.ts+++ b/app/src/protyle/header/Title.ts@@ -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");diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.tsindex 8bf1cc2bbb..fd20af0db9 100644--- a/app/src/protyle/header/openTitleMenu.ts+++ b/app/src/protyle/header/openTitleMenu.ts@@ -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) => {/// #elsewindow.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");});};