This commit is contained in:
Vanessa 2023-05-19 10:14:28 +08:00
parent 981c6688b8
commit 19dd0cd796
4 changed files with 15 additions and 8 deletions

View file

@ -33,7 +33,7 @@ export class Asset extends Model {
this.element.addEventListener("click", (event) => {
setPanelFocus(this.element.parentElement.parentElement);
this.app.plugins.forEach(item => {
item.eventBus.emit("click-pdf", event);
item.eventBus.emit("click-pdf", {event});
});
});
if (typeof this.pdfId === "string") {

View file

@ -82,13 +82,13 @@ export class Menu {
}
}
public addSeparator() {
this.addItem({type: "separator"});
public addSeparator(index?: number) {
this.addItem({type: "separator", index});
}
public addItem(option: IMenu) {
const menuItem = new MenuItem(option);
this.append(menuItem.element);
this.append(menuItem.element, option.index);
return menuItem.element;
}
@ -111,10 +111,17 @@ export class Menu {
window.siyuan.menus.menu.element.removeAttribute("data-name"); // 标识再次点击不消失
}
public append(element?: HTMLElement) {
public append(element?: HTMLElement, index?: number) {
if (!element) {
return;
}
if (typeof index === "number") {
const insertElement = this.element.querySelectorAll(".b3-menu__items > .b3-menu__separator")[index]
if (insertElement) {
insertElement.before(element);
return;
}
}
this.element.lastElementChild.append(element);
}

View file

@ -2,7 +2,6 @@ import {confirmDialog} from "../dialog/confirmDialog";
import {Plugin} from "./index";
import {showMessage} from "../dialog/message";
import {Dialog} from "../dialog";
import {MenuItem} from "../menus/Menu";
import {Menu as SiyuanMenu} from "../menus/Menu";
import {fetchGet, fetchPost, fetchSyncPost} from "../util/fetch";
import {isMobile} from "../util/functions";
@ -42,11 +41,11 @@ export class Menu {
return this.menu.addItem(option);
}
addSeparator() {
addSeparator(index?: number) {
if (this.isOpen) {
return;
}
this.menu.addSeparator();
this.menu.addSeparator(index);
}
open(options: { x: number, y: number, h?: number, w?: number, isLeft: false }) {

View file

@ -724,6 +724,7 @@ declare interface IMenu {
iconHTML?: string
current?: boolean
bind?: (element: HTMLElement) => void
index?: number
}
declare interface IBazaarItem {