mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-29 11:46:09 +01:00
This commit is contained in:
parent
dce9d4da54
commit
846fdf7c6e
6 changed files with 130 additions and 48 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import {MenuItem, subMenu} from "../menus/Menu";
|
||||
|
||||
export class EventBus<DetailType = any> {
|
||||
private eventTarget: EventTarget;
|
||||
|
||||
|
|
@ -21,3 +23,30 @@ export class EventBus<DetailType = any> {
|
|||
return this.eventTarget.dispatchEvent(new CustomEvent(type, {detail}));
|
||||
}
|
||||
}
|
||||
|
||||
export const emitOpenMenu = (options: {
|
||||
plugins: import("./index").Plugin[],
|
||||
type: TEventBus,
|
||||
detail: any,
|
||||
separatorPosition?: "top" | "bottom",
|
||||
}) => {
|
||||
const pluginSubMenu = new subMenu();
|
||||
options.detail.menu = pluginSubMenu;
|
||||
options.plugins.forEach((plugin) => {
|
||||
plugin.eventBus.emit(options.type, options.detail);
|
||||
});
|
||||
if (pluginSubMenu.menus.length > 0) {
|
||||
if (options.separatorPosition === "top") {
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
}
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.plugin,
|
||||
icon: "iconPlugin",
|
||||
type: "submenu",
|
||||
submenu: pluginSubMenu.menus,
|
||||
}).element);
|
||||
if (options.separatorPosition === "bottom") {
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue