This commit is contained in:
Vanessa 2023-05-25 10:14:41 +08:00
parent b2ac7b54ea
commit ac7e646fde
2 changed files with 21 additions and 13 deletions

View File

@ -186,30 +186,37 @@ export class MenuItem {
window.siyuan.menus.menu.remove();
});
}
let html = `<span class="b3-menu__label">${options.label}</span>`;
if (typeof options.iconHTML === "string") {
html = options.iconHTML + html;
} else {
html = `<svg class="b3-menu__icon${["HTML (SiYuan)", window.siyuan.languages.template].includes(options.label) ? " ft__error" : ""}" style="${options.icon === "iconClose" ? "height:10px;" : ""}"><use xlink:href="#${options.icon || ""}"></use></svg>${html}`;
}
if (options.accelerator) {
html += `<span class="b3-menu__accelerator">${updateHotkeyTip(options.accelerator)}</span>`;
}
if (options.action) {
html += `<svg class="b3-menu__action"><use xlink:href="#${options.action}"></use></svg>`;
}
if (options.id) {
this.element.setAttribute("data-id", options.id);
}
if (options.type === "readonly") {
this.element.classList.add("b3-menu__item--readonly");
}
this.element.innerHTML = html;
if (options.element) {
this.element.append(options.element);
} else {
let html = `<span class="b3-menu__label">${options.label}</span>`;
if (typeof options.iconHTML === "string") {
html = options.iconHTML + html;
} else {
html = `<svg class="b3-menu__icon${["HTML (SiYuan)", window.siyuan.languages.template].includes(options.label) ? " ft__error" : ""}" style="${options.icon === "iconClose" ? "height:10px;" : ""}"><use xlink:href="#${options.icon || ""}"></use></svg>${html}`;
}
if (options.accelerator) {
html += `<span class="b3-menu__accelerator">${updateHotkeyTip(options.accelerator)}</span>`;
}
if (options.action) {
html += `<svg class="b3-menu__action"><use xlink:href="#${options.action}"></use></svg>`;
}
this.element.innerHTML = html;
}
if (options.bind) {
// 主题 rem craft 需要使用 b3-menu__item--custom 来区分自定义菜单 by 281261361
this.element.classList.add("b3-menu__item--custom");
options.bind(this.element);
}
if (options.submenu) {
const submenuElement = document.createElement("div");
submenuElement.classList.add("b3-menu__submenu");

View File

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