mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 00:20:12 +01:00
🎨 https://github.com/siyuan-note/siyuan/issues/5066 add index for menu
This commit is contained in:
parent
981c6688b8
commit
19dd0cd796
4 changed files with 15 additions and 8 deletions
|
|
@ -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") {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 }) {
|
||||
|
|
|
|||
1
app/src/types/index.d.ts
vendored
1
app/src/types/index.d.ts
vendored
|
|
@ -724,6 +724,7 @@ declare interface IMenu {
|
|||
iconHTML?: string
|
||||
current?: boolean
|
||||
bind?: (element: HTMLElement) => void
|
||||
index?: number
|
||||
}
|
||||
|
||||
declare interface IBazaarItem {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue