Skip to content

Commit 3922ca0

Browse files
authored
🎨 Improve #commonMenu menu (#16147)
1 parent 2c23d05 commit 3922ca0

File tree

7 files changed

+17
-11
lines changed

7 files changed

+17
-11
lines changed

app/src/block/Panel.ts

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

app/src/constants.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,15 @@ export abstract class Constants {
236236
public static readonly MENU_BLOCK_SINGLE = "block-single"; // 单选块菜单
237237
public static readonly MENU_BLOCK_MULTI = "block-multi"; // 多选块菜单
238238
public static readonly MENU_TITLE = "titleMenu"; // 文档块菜单
239+
public static readonly MENU_FROM_TITLE_PROTYLE = "title-protyle"; // 在 Protyle 触发的文档块菜单
240+
public static readonly MENU_FROM_TITLE_BREADCRUMB = "title-breadcrumb"; // 在面包屑触发的文档块菜单
239241
public static readonly MENU_BREADCRUMB_MORE = "breadcrumbMore"; // 面包屑更多菜单
240242
public static readonly MENU_BREADCRUMB_MOBILE_PATH = "breadcrumb-mobile-path"; // 移动端面包屑菜单
241243

242244
public static readonly MENU_DOC_TREE_MORE = "docTreeMore"; // 侧栏文档树右键菜单
243-
public static readonly MENU_DOC_TREE_MORE_NOTEBOOK = "docTreeMore-notebook"; // 侧栏文档树右键菜单,单个笔记本
244-
public static readonly MENU_DOC_TREE_MORE_DOC = "docTreeMore-doc"; // 侧栏文档树右键菜单,单个文档
245-
public static readonly MENU_DOC_TREE_MORE_DOCS = "docTreeMore-docs"; // 侧栏文档树右键菜单,多个文档
245+
public static readonly MENU_FROM_DOC_TREE_MORE_NOTEBOOK = "tree-notebook"; // 侧栏文档树右键菜单,单个笔记本
246+
public static readonly MENU_FROM_DOC_TREE_MORE_DOC = "tree-doc"; // 侧栏文档树右键菜单,单个文档
247+
public static readonly MENU_FROM_DOC_TREE_MORE_DOCS = "tree-docs"; // 侧栏文档树右键菜单,多个文档
246248
public static readonly MENU_TAG = "tagMenu"; // 侧栏标签菜单
247249
public static readonly MENU_BOOKMARK = "bookmarkMenu"; // 侧栏书签菜单
248250
public static readonly MENU_OUTLINE_CONTEXT = "outline-context"; // 大纲标题右键菜单

app/src/menus/Menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class Menu {
120120
this.element.classList.remove("b3-menu--list", "b3-menu--fullscreen");
121121
this.element.removeAttribute("style"); // zIndex
122122
this.element.removeAttribute("data-name"); // 标识再次点击不消失
123-
this.element.removeAttribute("data-from"); // 标识是否在浮窗内打开
123+
this.element.removeAttribute("data-from"); // 标识菜单入口
124124
this.data = undefined; // 移除数据
125125
}
126126

app/src/menus/navigation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {openByMobile} from "../protyle/util/compatibility";
3232
import {addFilesToDatabase} from "../protyle/render/av/addToDatabase";
3333

3434
const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
35+
window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_DOCS);
3536
const fileItemElement = Array.from(selectItemElements).find(item => {
3637
if (item.getAttribute("data-type") === "navigation-file") {
3738
return true;
@@ -203,6 +204,8 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
203204
const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus");
204205
if (selectItemElements.length > 1) {
205206
return initMultiMenu(selectItemElements, app);
207+
} else {
208+
window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_NOTEBOOK);
206209
}
207210
const notebookId = liElement.parentElement.getAttribute("data-url");
208211
const name = getNotebookName(notebookId);
@@ -708,6 +711,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
708711
separatorPosition: "top",
709712
});
710713
}
714+
window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_DOC);
711715
return window.siyuan.menus.menu;
712716
};
713717

app/src/protyle/breadcrumb/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ ${padHTML}
9797
});
9898
} else {
9999
const targetRect = target.getBoundingClientRect();
100-
openTitleMenu(protyle, {x: targetRect.right, y: targetRect.bottom, isLeft: true});
100+
openTitleMenu(protyle, {x: targetRect.right, y: targetRect.bottom, isLeft: true}, Constants.MENU_FROM_TITLE_BREADCRUMB);
101101
}
102102
event.stopPropagation();
103103
event.preventDefault();

app/src/protyle/header/Title.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ export class Title {
194194
});
195195
} else {
196196
const iconRect = iconElement.getBoundingClientRect();
197-
openTitleMenu(protyle, {x: iconRect.left, y: iconRect.bottom});
197+
openTitleMenu(protyle, {x: iconRect.left, y: iconRect.bottom}, Constants.MENU_FROM_TITLE_PROTYLE);
198198
}
199199
});
200200
this.element.addEventListener("contextmenu", (event) => {
201201
if (event.shiftKey) {
202202
return;
203203
}
204204
if (getSelection().rangeCount === 0 || iconElement.contains((event.target as HTMLElement))) {
205-
openTitleMenu(protyle, {x: event.clientX, y: event.clientY});
205+
openTitleMenu(protyle, {x: event.clientX, y: event.clientY}, Constants.MENU_FROM_TITLE_PROTYLE);
206206
return;
207207
}
208208
protyle.toolbar?.element.classList.add("fn__none");

app/src/protyle/header/openTitleMenu.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {addEditorToDatabase} from "../render/av/addToDatabase";
2626
import {openFileById} from "../../editor/util";
2727
import {hasTopClosestByClassName} from "../util/hasClosest";
2828

29-
export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
29+
export const openTitleMenu = (protyle: IProtyle, position: IPosition, from: string) => {
3030
hideTooltip();
3131
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
3232
window.siyuan.menus.menu.element.getAttribute("data-name") === Constants.MENU_TITLE) {
@@ -38,6 +38,8 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
3838
}, (response) => {
3939
window.siyuan.menus.menu.remove();
4040
window.siyuan.menus.menu.element.setAttribute("data-name", Constants.MENU_TITLE);
41+
const popoverElement = hasTopClosestByClassName(protyle.element, "block__popover", true);
42+
window.siyuan.menus.menu.element.setAttribute("data-from", popoverElement ? popoverElement.dataset.level + "popover-" + from : "app-" + from);
4143
window.siyuan.menus.menu.append(new MenuItem({
4244
id: "copy",
4345
label: window.siyuan.languages.copy,
@@ -293,7 +295,5 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
293295
/// #else
294296
window.siyuan.menus.menu.popup(position);
295297
/// #endif
296-
const popoverElement = hasTopClosestByClassName(protyle.element, "block__popover", true);
297-
window.siyuan.menus.menu.element.setAttribute("data-from", popoverElement ? popoverElement.dataset.level + "popover" : "app");
298298
});
299299
};

0 commit comments

Comments
 (0)