This commit is contained in:
Vanessa 2022-09-20 22:30:41 +08:00
parent 152665335e
commit ca0a9d4ba4
4 changed files with 43 additions and 3 deletions

View file

@ -76,6 +76,10 @@
&--current {
background-color: var(--b3-list-hover);
.b3-menu__action {
opacity: 1;
}
}
&--readonly {
@ -95,6 +99,22 @@
}
}
&__action {
opacity: 0;
color: var(--b3-theme-on-surface);
width: 8px;
height: 8px;
align-self: center;
margin-left: 8px;
padding: 4px;
border-radius: 8px;
&:hover {
color: var(--b3-theme-on-background);
background: var(--b3-theme-background-light);
}
}
&__label {
flex: 1;
min-width: 84px;

View file

@ -28,6 +28,7 @@ import {saveScroll} from "../protyle/scroll/saveScroll";
import {Asset} from "../asset";
import {newFile} from "../util/newFile";
import {MenuItem} from "../menus/Menu";
import {escapeHtml} from "../util/escape";
export class Wnd {
public id: string;
@ -463,11 +464,26 @@ export class Wnd {
const iconElement = item.querySelector(".item__icon");
const graphicElement = item.querySelector(".item__graphic");
window.siyuan.menus.menu.append(new MenuItem({
label: item.querySelector(".item__text").textContent,
label: escapeHtml(item.querySelector(".item__text").textContent),
action: "iconClose",
iconHTML: iconElement ? `<span class="b3-menu__icon">${iconElement.innerHTML}</span>` : "",
icon: graphicElement ? graphicElement.firstElementChild.getAttribute("xlink:href").substring(1) : "",
click: () => {
this.switchTab(item, true);
bind: (element) => {
element.addEventListener("click", (event) => {
if (hasClosestByTag(event.target as Element, "svg")) {
this.removeTab(item.getAttribute("data-id"));
if (element.previousElementSibling || element.nextElementSibling) {
element.remove();
} else {
window.siyuan.menus.menu.remove();
}
} else {
this.switchTab(item, true);
window.siyuan.menus.menu.remove();
}
event.preventDefault()
event.stopPropagation();
});
},
current: item.classList.contains("item--focus")
}).element);

View file

@ -136,6 +136,9 @@ export class MenuItem {
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);
}

View file

@ -484,6 +484,7 @@ declare interface IMenu {
click?: (element: HTMLElement) => void,
type?: "separator" | "submenu" | "readonly",
accelerator?: string,
action?: string,
id?: string,
submenu?: IMenu[]
disabled?: boolean