Something went wrong. Try again.
A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
Something went wrong. Try again.
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import {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(); }}