mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 01:20:12 +01:00
❤️ 完整开源界面和内核 https://github.com/siyuan-note/siyuan/issues/5013
This commit is contained in:
parent
e650b8100c
commit
f40ed985e1
1214 changed files with 345766 additions and 9 deletions
85
app/src/menus/index.ts
Normal file
85
app/src/menus/index.ts
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
import {initNavigationMenu, initFileMenu} from "./navigation";
|
||||
import {hasTopClosestByTag} from "../protyle/util/hasClosest";
|
||||
import {initTabMenu} from "./tab";
|
||||
import {getInstanceById} from "../layout/util";
|
||||
import {Tab} from "../layout/Tab";
|
||||
import {initSearchMenu} from "./search";
|
||||
import {initDockMenu} from "./dock";
|
||||
import {Menu} from "./Menu";
|
||||
import {isMobile} from "../util/functions";
|
||||
|
||||
export class Menus {
|
||||
public menu: Menu;
|
||||
|
||||
constructor() {
|
||||
this.menu = new Menu();
|
||||
if (isMobile()) {
|
||||
return;
|
||||
}
|
||||
window.addEventListener("contextmenu", (event) => {
|
||||
let target = event.target as HTMLElement;
|
||||
while (target && !target.parentElement.isEqualNode(document.querySelector("body"))) {
|
||||
event.preventDefault();
|
||||
const dataType = target.getAttribute("data-type");
|
||||
if (dataType === "tab-header") {
|
||||
this.unselect();
|
||||
initTabMenu(dataType, (getInstanceById(target.getAttribute("data-id")) as Tab).model).popup({
|
||||
x: event.clientX,
|
||||
y: event.clientY
|
||||
});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
}
|
||||
|
||||
if (dataType === "navigation-root" && !window.siyuan.config.readonly) {
|
||||
if (target.querySelector(".b3-list-item__text").classList.contains("ft__on-surface")) {
|
||||
return;
|
||||
}
|
||||
this.unselect();
|
||||
// navigation 根上:新建文档/文件夹/取消挂在/打开文件位置
|
||||
initNavigationMenu(target).popup({x: event.clientX, y: event.clientY});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
}
|
||||
|
||||
if (dataType === "navigation-file") {
|
||||
this.unselect();
|
||||
// navigation 文件上:删除/重命名/打开文件位置/导出
|
||||
initFileMenu(this.getDir(target), target.getAttribute("data-path"), target.getAttribute("data-node-id"), target.getAttribute("data-name")).popup({
|
||||
x: event.clientX,
|
||||
y: event.clientY
|
||||
});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
}
|
||||
|
||||
if (dataType === "search-item") {
|
||||
initSearchMenu(target.getAttribute("data-node-id")).popup({x: event.clientX, y: event.clientY});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
}
|
||||
|
||||
if (target.classList.contains("dock__item")) {
|
||||
initDockMenu(target).popup({x: event.clientX, y: event.clientY});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
}
|
||||
|
||||
target = target.parentElement;
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
private getDir(target: HTMLElement) {
|
||||
const rootElement = hasTopClosestByTag(target, "UL");
|
||||
if (rootElement) {
|
||||
return rootElement.getAttribute("data-url");
|
||||
}
|
||||
}
|
||||
|
||||
private unselect() {
|
||||
if (getSelection().rangeCount > 0) {
|
||||
getSelection().getRangeAt(0).collapse(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue