浏览代码

:art: fix https://github.com/siyuan-note/siyuan/issues/8343

Vanessa 2 年之前
父节点
当前提交
ac7e646fde
共有 2 个文件被更改,包括 21 次插入13 次删除
  1. 20 13
      app/src/menus/Menu.ts
  2. 1 0
      app/src/types/index.d.ts

+ 20 - 13
app/src/menus/Menu.ts

@@ -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");

+ 1 - 0
app/src/types/index.d.ts

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