Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Improve tabs controls, menus and title overflow https://github.com/siyuan-note/siyuan/issues/17642

Danield51fea91caa5
diff --git a/app/src/assets/scss/protyle/_tabs.scss b/app/src/assets/scss/protyle/_tabs.scss
index 3a77677346..f1e5e07e8e 100644
--- a/app/src/assets/scss/protyle/_tabs.scss
+++ b/app/src/assets/scss/protyle/_tabs.scss
@@ -20,7 +20,7 @@
.tabs-list {
display: flex;
align-items: center;
- flex: 1;
+ flex: 0 1 auto;
min-width: 0;
overflow: auto;
gap: 8px;
@@ -77,10 +77,21 @@
opacity: .36;
}
- .tabs-control svg {
- display: block;
- width: 1em;
- height: 1em;
+ .tabs-control {
+ width: 24px;
+ height: 24px;
+ min-height: 24px;
+ padding: 4px;
+
+ svg {
+ display: block;
+ width: 16px;
+ height: 16px;
+ }
+
+ &--more {
+ margin-left: auto;
+ }
}
.tab-item {
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 0032b39813..ff9a7a53f5 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -793,7 +793,7 @@ export class Gutter {
const type = buttonElement.getAttribute("data-type");
const id = buttonElement.getAttribute("data-node-id");
// 情况C:非有效块标(折叠箭头、数据库行等)→ 隐藏框线与+号
- if (type === "fold" || type === "NodeAttributeViewRow" || type === "NodeAttributeViewRowMenu" || !id) {
+ if (type === "fold" || type === "NodeTabItem" || type === "NodeAttributeViewRow" || type === "NodeAttributeViewRowMenu" || !id) {
hideInsert();
return;
}
@@ -2762,7 +2762,7 @@ export class Gutter {
}).element);
/// #endif
}
- if (allowStructuralMutation) {
+ if (allowStructuralMutation && nodeElement.getAttribute("data-type") !== "NodeTabItem") {
window.siyuan.menus.menu.append(new MenuItem({
id: "insertBefore",
icon: "iconBefore",
diff --git a/app/src/protyle/render/tabsRender.ts b/app/src/protyle/render/tabsRender.ts
index 528f63d598..01fb2d8497 100644
--- a/app/src/protyle/render/tabsRender.ts
+++ b/app/src/protyle/render/tabsRender.ts
@@ -1,5 +1,6 @@
import {resolveTabID, tabKeyboardTarget} from "./tabsState";
import {bindTabsDrag, cancelTabsDrag, isDraggingTabs} from "./tabsDrag";
+import {escapeHtml} from "../../util/escape";
export interface ITabsRenderOptions {
readonly?: (tabs?: Element) => boolean;
@@ -176,11 +177,12 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =
button.dataset.tabId = itemID(item);
button.id = `${state.instance}-tab-${index}`;
const title = getTabTitle(item);
- button.title = title?.textContent || controller.options.label || "Tab";
+ const label = title?.textContent || controller.options.label || "Tab";
if (title?.textContent) {
const clone = title.cloneNode(true) as HTMLElement;
clone.className = "tabs-tab-label";
clone.removeAttribute("contenteditable");
+ clone.querySelectorAll("br").forEach(br => br.replaceWith(" "));
clone.querySelectorAll("[contenteditable], [id], [data-node-id]").forEach(child => {
child.removeAttribute("contenteditable");
child.removeAttribute("id");
@@ -188,8 +190,10 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =
});
button.appendChild(clone);
} else {
- button.textContent = button.title;
+ button.innerHTML = '<span class="tabs-tab-label"></span>';
+ button.firstElementChild.textContent = label;
}
+ button.setAttribute("aria-label", escapeHtml(button.textContent));
button.addEventListener("click", event => {
event.preventDefault();
event.stopPropagation();
@@ -232,10 +236,9 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =
if (!readonly) {
const add = document.createElement("button");
add.type = "button";
- add.className = "tabs-control";
- add.textContent = "+";
- add.title = controller.options.addLabel || "+";
- add.setAttribute("aria-label", add.title);
+ add.className = "tabs-control ariaLabel";
+ add.innerHTML = '<svg><use xlink:href="#iconAdd"></use></svg>';
+ add.setAttribute("aria-label", escapeHtml(controller.options.addLabel || "+"));
add.addEventListener("click", event => {
event.stopPropagation();
controller.options.add?.(tabs);
@@ -243,13 +246,12 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =
header.appendChild(add);
const menu = document.createElement("button");
menu.type = "button";
- menu.className = "tabs-control";
+ menu.className = "tabs-control tabs-control--more ariaLabel";
menu.innerHTML = '<svg><use xlink:href="#iconMore"></use></svg>';
- menu.title = controller.options.menuLabel || "...";
- menu.setAttribute("aria-label", menu.title);
+ menu.setAttribute("aria-label", escapeHtml(controller.options.menuLabel || "..."));
menu.addEventListener("click", event => {
event.stopPropagation();
- controller.options.menu?.(tabs, items.find(item => itemID(item) === state.active), menu);
+ controller.options.menu?.(tabs, undefined, menu);
});
header.appendChild(menu);
}
@@ -286,6 +288,9 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =
}
});
tabs.setAttribute("data-tabs-ready", "true");
+ list.querySelectorAll<HTMLElement>(".tabs-tab-label").forEach(label => {
+ label.parentElement.classList.toggle("ariaLabel", label.scrollWidth > label.clientWidth);
+ });
controller.resize.observe(tabs);
if (!tabs.closest('.tab-item[data-tabs-hidden="true"]') && state.renderedActive !== state.active) {
state.renderedActive = state.active;
@@ -309,15 +314,7 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =
shown.forEach(item => controller.options.shown?.(item));
},
observer: new MutationObserver(schedule),
- resize: new ResizeObserver(entries => {
- if (entries.some(entry => {
- const tabs = entry.target;
- const vertical = tabs.getAttribute("tabs-position") === "left" && (tabs as HTMLElement).clientWidth >= 420;
- return tabs.getAttribute("data-tabs-orientation") !== (vertical ? "vertical" : "horizontal");
- })) {
- schedule();
- }
- }),
+ resize: new ResizeObserver(schedule),
destroy() {
cancelTabsDrag(element);
destroyed = true;
diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts
index 61edb7485e..e64899b1d8 100644
--- a/app/src/protyle/ui/initUI.ts
+++ b/app/src/protyle/ui/initUI.ts
@@ -234,6 +234,10 @@ export const initUI = (protyle: IProtyle) => {
const tabsHeader = hasClosestByClassName(event.target, "tabs-header");
const nodeElement = tabsHeader ? hasClosestBlock(tabsHeader.parentElement) : hasClosestBlock(event.target);
+ if (!tabsHeader && nodeElement && nodeElement.getAttribute("data-type") === "NodeTabItem") {
+ hideElements(["gutter"], protyle);
+ return;
+ }
if (protyle.options.render.gutter && nodeElement) {
if (!protyle.wysiwyg.element.contains(nodeElement)) {
hideElements(["gutter"], protyle);
diff --git a/app/src/protyle/wysiwyg/tabs.ts b/app/src/protyle/wysiwyg/tabs.ts
index 9402f73e06..1b39e381ba 100644
--- a/app/src/protyle/wysiwyg/tabs.ts
+++ b/app/src/protyle/wysiwyg/tabs.ts
@@ -139,50 +139,39 @@ export const openTabsMenu = (protyle: IProtyle, tabs: HTMLElement, item: HTMLEle
}
const lang = window.siyuan.languages;
const menu = new Menu();
- menu.addItem({icon: "iconEdit", label: lang.rename, click: () => renameTab(protyle, item)});
- menu.addItem({icon: "iconAdd", label: lang.tabItem, click: () => addTab(protyle, tabs)});
- const siblings = getTabItems(tabs);
- const index = siblings.indexOf(item);
- if (index > 0) {
- menu.addItem({icon: "iconLeft", label: lang.dragTipMoveTargetFront.replace("${x}",
- getTabTitle(siblings[index - 1]).textContent || lang.tabItem),
- click: () => moveTab(protyle, item, siblings[index - 1])});
- }
- if (index + 1 < siblings.length) {
- menu.addItem({icon: "iconRight", label: lang.dragTipMoveTargetBack.replace("${x}",
- getTabTitle(siblings[index + 1]).textContent || lang.tabItem),
- click: () => changeTabs(protyle, [tabs], () => siblings[index + 1].after(item))});
+ if (item) {
+ menu.addItem({icon: "iconEdit", label: lang.rename, click: () => renameTab(protyle, item)});
+ menu.addItem({icon: "iconCopy", label: lang.duplicateCopy, click: () => {
+ const copy = item.cloneNode(true) as HTMLElement;
+ const ids = new Map<string, string>();
+ [copy, ...Array.from(copy.querySelectorAll<HTMLElement>("[data-node-id]"))].forEach(block => {
+ const id = Lute.NewNodeID();
+ ids.set(block.dataset.nodeId, id);
+ block.dataset.nodeId = id;
+ block.setAttribute("updated", id.substring(0, 14));
+ });
+ remapTabsDOMIDs(copy, ids);
+ changeTabs(protyle, [tabs], () => {
+ item.after(copy);
+ tabs.setAttribute("tabs-active-id", copy.dataset.nodeId);
+ });
+ }});
+ menu.addItem({icon: "iconTrashcan", label: lang.delete, click: () => {
+ const ids = getTabItems(tabs).map(entry => entry.dataset.nodeId);
+ changeTabs(protyle, [tabs], () => {
+ item.remove();
+ repairActiveTab(tabs, ids, item.dataset.nodeId);
+ });
+ focusBlock(tabs);
+ }});
+ } else {
+ ["top", "left"].forEach(position => menu.addItem({
+ label: position === "top" ? lang.tabsPositionTop : lang.tabsPositionLeft,
+ icon: (tabs.getAttribute("tabs-position") || "top") === position ? "iconSelect" : undefined,
+ click: () => changeTabs(protyle, [tabs], () => tabs.setAttribute("tabs-position", position)),
+ }));
+ menu.addItem({icon: "iconSuper", label: lang.tabsUnwrap, click: () => unwrapTabs(protyle, tabs)});
}
- menu.addItem({icon: "iconCopy", label: lang.duplicateCopy, click: () => {
- const copy = item.cloneNode(true) as HTMLElement;
- const ids = new Map<string, string>();
- [copy, ...Array.from(copy.querySelectorAll<HTMLElement>("[data-node-id]"))].forEach(block => {
- const id = Lute.NewNodeID();
- ids.set(block.dataset.nodeId, id);
- block.dataset.nodeId = id;
- block.setAttribute("updated", id.substring(0, 14));
- });
- remapTabsDOMIDs(copy, ids);
- changeTabs(protyle, [tabs], () => {
- item.after(copy);
- tabs.setAttribute("tabs-active-id", copy.dataset.nodeId);
- });
- }});
- menu.addItem({icon: "iconTrashcan", label: lang.delete, click: () => {
- const ids = getTabItems(tabs).map(entry => entry.dataset.nodeId);
- changeTabs(protyle, [tabs], () => {
- item.remove();
- repairActiveTab(tabs, ids, item.dataset.nodeId);
- });
- focusBlock(tabs);
- }});
- menu.addSeparator();
- ["top", "left"].forEach(position => menu.addItem({
- label: position === "top" ? lang.tabsPositionTop : lang.tabsPositionLeft,
- icon: (tabs.getAttribute("tabs-position") || "top") === position ? "iconSelect" : undefined,
- click: () => changeTabs(protyle, [tabs], () => tabs.setAttribute("tabs-position", position)),
- }));
- menu.addItem({icon: "iconSuper", label: lang.tabsUnwrap, click: () => unwrapTabs(protyle, tabs)});
const rect = anchor.getBoundingClientRect();
menu.open({x: rect.left, y: rect.bottom});
};