mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 01:20:12 +01:00
* 改进菜单的 data-name 属性值和选项的 data-id 属性值 fix https://github.com/siyuan-note/siyuan/issues/12506 https://github.com/siyuan-note/siyuan/issues/16133 * 改进菜单的 data-name 属性值和选项的 data-id 属性值 fix https://github.com/siyuan-note/siyuan/issues/12506 https://github.com/siyuan-note/siyuan/issues/16133 * 更新数据库排序菜单文案 * 改进菜单的 data-name 属性值和选项的 data-id 属性值 fix https://github.com/siyuan-note/siyuan/issues/12506 https://github.com/siyuan-note/siyuan/issues/16133 使用正则 (?:get|set)Attribute\("data-name"|new Menu\((?:"|Constants) 来搜索 * 改进菜单的 data-name 属性值和选项的 data-subname 属性值 fix https://github.com/siyuan-note/siyuan/issues/12506 https://github.com/siyuan-note/siyuan/issues/15075 * 改进菜单的 data-name 属性值和选项的 data-subname 属性值 fix https://github.com/siyuan-note/siyuan/issues/12506 https://github.com/siyuan-note/siyuan/issues/15075
79 lines
2 KiB
TypeScript
79 lines
2 KiB
TypeScript
import {Menu as SiyuanMenu} from "../menus/Menu";
|
|
|
|
export class Menu {
|
|
private menu: SiyuanMenu;
|
|
public isOpen: boolean;
|
|
public element: HTMLElement;
|
|
|
|
constructor(id?: string, closeCB?: () => void) {
|
|
this.menu = window.siyuan.menus.menu;
|
|
this.isOpen = false;
|
|
this.element = this.menu.element;
|
|
|
|
if (id) {
|
|
const dataName = this.menu.element.getAttribute("data-name");
|
|
if (dataName && dataName === id) {
|
|
this.isOpen = true;
|
|
}
|
|
}
|
|
this.menu.remove();
|
|
if (!this.isOpen) {
|
|
if (id) {
|
|
this.menu.element.setAttribute("data-name", id);
|
|
}
|
|
this.menu.removeCB = closeCB;
|
|
}
|
|
}
|
|
|
|
showSubMenu(subMenuElement: HTMLElement) {
|
|
this.menu.showSubMenu(subMenuElement);
|
|
}
|
|
|
|
addItem(option: IMenu) {
|
|
if (this.isOpen) {
|
|
return;
|
|
}
|
|
return this.menu.addItem(option);
|
|
}
|
|
|
|
addSeparator(options?: number | {
|
|
index?: number,
|
|
id?: string,
|
|
ignore?: boolean
|
|
}, ignoreParam = false) {
|
|
// 兼容 3.1.24 之前的版本 addSeparator(index?: number, ignore?: boolean): HTMLElement;
|
|
let id: string;
|
|
let index: number;
|
|
let ignore = false;
|
|
if (typeof options === "object") {
|
|
ignore = options.ignore || false;
|
|
index = options.index;
|
|
id = options.id;
|
|
} else if (typeof options === "number") {
|
|
index = options;
|
|
ignore = ignoreParam;
|
|
}
|
|
if (ignore || this.isOpen) {
|
|
return;
|
|
}
|
|
return this.menu.addItem({id, type: "separator", index});
|
|
}
|
|
|
|
open(options: IPosition) {
|
|
if (this.isOpen) {
|
|
return;
|
|
}
|
|
this.menu.popup(options);
|
|
}
|
|
|
|
fullscreen(position: "bottom" | "all" = "all") {
|
|
if (this.isOpen) {
|
|
return;
|
|
}
|
|
this.menu.fullscreen(position);
|
|
}
|
|
|
|
close() {
|
|
this.menu.remove();
|
|
}
|
|
}
|