Vanessa 2023-05-24 10:47:53 +08:00
parent d26bb04110
commit 852d5fbe52
3 changed files with 20 additions and 5 deletions

View file

@ -609,25 +609,36 @@ export class Dock {
return max;
}
public genButton(data: IDockTab[], index: number, append = false) {
public genButton(data: IDockTab[], index: number, tabIndex?: number) {
let html = "";
data.forEach(item => {
if (typeof tabIndex === "undefined" && !TYPES.includes(item.type)) {
return;
}
html += `<span data-height="${item.size.height}" data-width="${item.size.width}" data-type="${item.type}" data-index="${index}" data-hotkey="${item.hotkey || ""}" data-hotkeyLangId="${item.hotkeyLangId || ""}" data-title="${item.title}" class="dock__item${item.show ? " dock__item--active" : ""} b3-tooltips b3-tooltips__${this.getClassDirect(index)}" aria-label="${item.title} ${item.hotkey ? updateHotkeyTip(item.hotkey) : ""}${window.siyuan.languages.dockTip}">
<svg><use xlink:href="#${item.icon}"></use></svg>
</span>`;
this.data[item.type] = true;
});
if (index === 0) {
if (append) {
this.element.firstElementChild.lastElementChild.insertAdjacentHTML("beforebegin", html);
if (typeof tabIndex === "number") {
if (this.element.firstElementChild.children[tabIndex]) {
this.element.firstElementChild.children[tabIndex].insertAdjacentHTML("beforebegin", html);
} else {
this.element.firstElementChild.lastElementChild.insertAdjacentHTML("beforebegin", html);
}
} else {
this.element.firstElementChild.innerHTML = `${html}<span class="dock__item dock__item--pin b3-tooltips b3-tooltips__${this.getClassDirect(index)}" aria-label="${this.pin ? window.siyuan.languages.unpin : window.siyuan.languages.pin}">
<svg><use xlink:href="#iconPin"></use></svg>
</span>`;
}
} else {
if (append) {
this.element.lastElementChild.insertAdjacentHTML("beforeend", html);
if (typeof tabIndex === "number") {
if (this.element.lastElementChild.children[tabIndex]) {
this.element.lastElementChild.children[tabIndex].insertAdjacentHTML("beforebegin", html);
} else {
this.element.lastElementChild.insertAdjacentHTML("beforeend", html);
}
} else {
this.element.lastElementChild.innerHTML = html;
}