Skip to content

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

:art: Improve mobile sidebar density and swipe performance https://github.com/siyuan-note/siyuan/issues/19011

Daniel84f434502a2b
diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scss
index b6f88a67ad..b86c180dfc 100644
--- a/app/src/assets/scss/main/_mobile.scss
+++ b/app/src/assets/scss/main/_mobile.scss
@@ -289,6 +289,77 @@ body.mobile-keyboard--open {
}
}
+#sidebar,
+#sidebarRight {
+ .toolbar {
+ &__icon {
+ width: 18px;
+ height: 18px;
+ padding: 11px;
+ margin: 2px;
+ }
+
+ &__text {
+ font-size: 15px;
+ }
+ }
+
+ .b3-list--mobile {
+ .b3-list-item {
+ font-size: 14px;
+
+ &__icon,
+ &__switch {
+ svg, img {
+ width: 18px;
+ height: 18px;
+ }
+ }
+
+ &__graphic {
+ width: 16px;
+ height: 16px;
+ margin-inline-end: 6px;
+ font-size: 16px;
+ line-height: 16px;
+ }
+
+ &__arrow {
+ width: 14px;
+ height: 14px;
+ }
+
+ &__action {
+ height: 16px;
+ padding: 8px;
+ margin-left: 0;
+ margin-inline-start: 2px;
+
+ svg {
+ width: 16px;
+ height: 16px;
+ }
+ }
+ }
+
+ .counter {
+ box-sizing: border-box;
+ flex-shrink: 0;
+ min-width: 24px;
+ height: 20px;
+ margin-left: 0;
+ margin-inline-start: 2px;
+ padding: 0 6px;
+ font-size: 12px;
+ font-variant-numeric: tabular-nums;
+ line-height: 20px;
+ text-align: end;
+ unicode-bidi: isolate;
+ white-space: nowrap;
+ }
+ }
+}
+
.mobile-safe-area {
position: relative;
z-index: 4;
@@ -587,6 +658,11 @@ body.mobile-topbar--merged {
transform: translateX(100vw);
}
+ &--swiping {
+ transition: none;
+ will-change: transform;
+ }
+
// 窄屏下 Dock 图标过多时可横向滚动,关闭按钮固定在工具栏末端始终可触达
& > .toolbar--border > .toolbar__scroll {
flex: 1;
@@ -614,6 +690,11 @@ body.mobile-topbar--merged {
background-color: #000;
opacity: 0;
transition: opacity 150ms linear;
+
+ &--swiping {
+ transition: none;
+ will-change: opacity;
+ }
}
#model,
diff --git a/app/src/mobile/dock/MobileFiles.ts b/app/src/mobile/dock/MobileFiles.ts
index 100ae0a21a..244fda909c 100644
--- a/app/src/mobile/dock/MobileFiles.ts
+++ b/app/src/mobile/dock/MobileFiles.ts
@@ -1,5 +1,6 @@
import {hasClosestByClassName, hasClosestByTag, hasTopClosestByTag} from "../../protyle/util/hasClosest";
import {escapeHtml} from "../../util/escape";
+import {getTreeItemTailHTML} from "../../util/treeItemTail";
import {Model} from "../../layout/Model";
import {Constants} from "../../constants";
import {getDocDisplayName, isMoveTargetAllowed, pathPosix, setNoteBook} from "../../util/pathName";
@@ -1445,6 +1446,12 @@ export class MobileFiles extends Model {
const paddingLeft = (item.path.split("/").length - 1) * 20;
const editingPublishAccess = this.actionsElement.querySelector('[data-type="publish-access"]').classList.contains("block__icon--active");
const defaultIcon = item.subFileCount === 0 ? "file" : "folder";
+ const actionHTML = `<span data-type="more-file" class="b3-list-item__action b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.more}">
+ <svg><use xlink:href="#iconMore"></use></svg>
+ </span>
+ <span data-type="new" class="b3-list-item__action b3-tooltips b3-tooltips__nw${window.siyuan.config.readonly ? " fn__none" : ""}" aria-label="${window.siyuan.languages.newSubDoc}">
+ <svg><use xlink:href="#iconAdd"></use></svg>
+ </span>`;
return `<li data-node-id="${item.id}" data-name="${Lute.EscapeHTMLStr(item.name)}" data-count="${item.subFileCount}" ${FILE_TREE_CHILDREN_SORT_MODE}="${item.childrenSortMode ?? ""}" data-type="navigation-file"
class="b3-list-item" data-path="${item.path}" style="--file-toggle-width:${paddingLeft + 20}px"${getFileTreeDefaultIconAttr(item.icon, defaultIcon)}>
<span style="padding-left: ${paddingLeft}px" class="b3-list-item__toggle${item.subFileCount === 0 ? " fn__hidden" : ""}">
@@ -1453,13 +1460,7 @@ class="b3-list-item" data-path="${item.path}" style="--file-toggle-width:${paddi
<span class="b3-list-item__icon"${editingPublishAccess ? " fn__none" : ""}>${getFileTreeIconHTML(item.icon, defaultIcon)}</span>
<span class="b3-list-item__switch${editingPublishAccess ? "" : " fn__none"}">${getPublishAccessOptionByLevel("public").iconHTML}</span>
<span class="b3-list-item__text">${getDocDisplayName(item.name, item.titleEmpty, true)}</span>
- <span data-type="more-file" class="b3-list-item__action b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.more}">
- <svg><use xlink:href="#iconMore"></use></svg>
- </span>
- <span data-type="new" class="b3-list-item__action b3-tooltips b3-tooltips__nw${window.siyuan.config.readonly ? " fn__none" : ""}" aria-label="${window.siyuan.languages.newSubDoc}">
- <svg><use xlink:href="#iconAdd"></use></svg>
- </span>
- ${countHTML}
+ ${getTreeItemTailHTML(countHTML, actionHTML, true)}
</li>`;
};
diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts
index 85a989683f..3740d37482 100644
--- a/app/src/mobile/util/touch.ts
+++ b/app/src/mobile/util/touch.ts
@@ -26,6 +26,7 @@ import {
getSidebarOpeningOffset,
type MobileSidebarSide,
type MobileSwipeDirection,
+ setSidebarSwipeState,
shouldCloseGlobalMenu,
shouldDragOpenSidebar,
} from "./touchPanelGesture";
@@ -49,6 +50,15 @@ const getSidebarElement = (side: MobileSidebarSide) => {
return document.getElementById(side === "left" ? "sidebar" : "sidebarRight");
};
+const sideMaskElement = document.querySelector(".side-mask") as HTMLElement;
+
+const updateSidebarSwipeState = (activeSide?: MobileSidebarSide) => {
+ setSidebarSwipeState({
+ left: getSidebarElement("left"),
+ right: getSidebarElement("right"),
+ }, sideMaskElement, activeSide);
+};
+
const getTargetSidebar = (target: HTMLElement): MobileSidebarSide | undefined => {
if (hasClosestByAttribute(target, "id", "sidebar", true)) {
return "left";
@@ -153,6 +163,7 @@ const restoreInvisibleLongPressSelection = () => {
};
export const handleTouchUp = () => {
+ updateSidebarSwipeState();
resetAndroidBoundedSelectionGesture();
if (Date.now() - time < Constants.TIMEOUT_MULTIPLE_SELECT) {
clearLongPress();
@@ -171,6 +182,7 @@ export const handleTouchSelectionChange = () => {
};
export const handleTouchEnd = (event: TouchEvent) => {
+ updateSidebarSwipeState();
const target = event.target as HTMLElement;
const currentTime = Date.now();
const editor = getCurrentEditor();
@@ -320,6 +332,7 @@ export const handleTouchEnd = (event: TouchEvent) => {
};
export const handleTouchStart = (event: TouchEvent) => {
+ updateSidebarSwipeState();
time = Date.now();
longPressBlockElement = undefined;
longPressTouchRange = undefined;
@@ -414,8 +427,6 @@ export const handleTouchStart = (event: TouchEvent) => {
};
let previousClientX: number;
-const sideMaskElement = document.querySelector(".side-mask") as HTMLElement;
-
const isHorizontalScrollable = (target: HTMLElement, xDiff: number) => {
let element: HTMLElement = target;
while (element && element.id !== "model") {
@@ -561,6 +572,7 @@ export const handleTouchMove = (event: TouchEvent) => {
}
sideMaskElement.style.zIndex = (++window.siyuan.zIndex).toString();
const activeSidebar = getTargetSidebar(target) || openingSidebar;
+ updateSidebarSwipeState(activeSidebar);
getSidebarElement(activeSidebar).style.zIndex = (++window.siyuan.zIndex).toString();
isFirstMove = false;
}
diff --git a/app/src/mobile/util/touchPanelGesture.test.ts b/app/src/mobile/util/touchPanelGesture.test.ts
index f7e35ead8c..887228dc28 100644
--- a/app/src/mobile/util/touchPanelGesture.test.ts
+++ b/app/src/mobile/util/touchPanelGesture.test.ts
@@ -6,10 +6,30 @@ import {
getSidebarClosingDirection,
getSidebarClosingOffset,
getSidebarOpeningOffset,
+ MOBILE_SIDEBAR_MASK_SWIPING_CLASS,
+ MOBILE_SIDEBAR_SWIPING_CLASS,
+ setSidebarSwipeState,
shouldCloseGlobalMenu,
shouldDragOpenSidebar,
} from "./touchPanelGesture";
+const createClassTarget = () => {
+ const classes = new Set<string>();
+ return {
+ classes,
+ target: {
+ classList: {
+ add(className: string) {
+ classes.add(className);
+ },
+ remove(className: string) {
+ classes.delete(className);
+ },
+ },
+ },
+ };
+};
+
describe("mobile sidebar touch gesture", () => {
it("opens the sidebar opposite the finger movement", () => {
assert.equal(getOpeningSidebar("toRight"), "left");
@@ -55,4 +75,34 @@ describe("mobile sidebar touch gesture", () => {
assert.equal(getSidebarOpeningOffset("right", -20, 300), 300);
assert.equal(getSidebarOpeningOffset("right", 400, 300), 0);
});
+
+ it("keeps only the active sidebar in the swiping state", () => {
+ const left = createClassTarget();
+ const right = createClassTarget();
+ const mask = createClassTarget();
+ const sidebars = {left: left.target, right: right.target};
+
+ setSidebarSwipeState(sidebars, mask.target, "left");
+ assert.equal(left.classes.has(MOBILE_SIDEBAR_SWIPING_CLASS), true);
+ assert.equal(right.classes.has(MOBILE_SIDEBAR_SWIPING_CLASS), false);
+ assert.equal(mask.classes.has(MOBILE_SIDEBAR_MASK_SWIPING_CLASS), true);
+
+ setSidebarSwipeState(sidebars, mask.target, "right");
+ assert.equal(left.classes.has(MOBILE_SIDEBAR_SWIPING_CLASS), false);
+ assert.equal(right.classes.has(MOBILE_SIDEBAR_SWIPING_CLASS), true);
+ assert.equal(mask.classes.has(MOBILE_SIDEBAR_MASK_SWIPING_CLASS), true);
+ });
+
+ it("clears the swiping state when a gesture finishes", () => {
+ const left = createClassTarget();
+ const right = createClassTarget();
+ const mask = createClassTarget();
+ const sidebars = {left: left.target, right: right.target};
+
+ setSidebarSwipeState(sidebars, mask.target, "left");
+ setSidebarSwipeState(sidebars, mask.target);
+ assert.equal(left.classes.has(MOBILE_SIDEBAR_SWIPING_CLASS), false);
+ assert.equal(right.classes.has(MOBILE_SIDEBAR_SWIPING_CLASS), false);
+ assert.equal(mask.classes.has(MOBILE_SIDEBAR_MASK_SWIPING_CLASS), false);
+ });
});
diff --git a/app/src/mobile/util/touchPanelGesture.ts b/app/src/mobile/util/touchPanelGesture.ts
index 25df9f4b9d..eee91ae028 100644
--- a/app/src/mobile/util/touchPanelGesture.ts
+++ b/app/src/mobile/util/touchPanelGesture.ts
@@ -2,6 +2,31 @@ export type MobileSidebarSide = "left" | "right";
export type MobileSwipeDirection = "toLeft" | "toRight";
export type MobileSidebarReleaseAction = "close" | "open";
+export const MOBILE_SIDEBAR_SWIPING_CLASS = "side-panel--swiping";
+export const MOBILE_SIDEBAR_MASK_SWIPING_CLASS = "side-mask--swiping";
+
+interface IMobileSidebarSwipeClassTarget {
+ classList: {
+ add(className: string): void;
+ remove(className: string): void;
+ };
+}
+
+export const setSidebarSwipeState = (
+ sidebars: Partial<Record<MobileSidebarSide, IMobileSidebarSwipeClassTarget | null>>,
+ mask: IMobileSidebarSwipeClassTarget | null,
+ activeSide?: MobileSidebarSide,
+) => {
+ Object.values(sidebars).forEach(item => item?.classList.remove(MOBILE_SIDEBAR_SWIPING_CLASS));
+ mask?.classList.remove(MOBILE_SIDEBAR_MASK_SWIPING_CLASS);
+ const activeSidebar = activeSide ? sidebars[activeSide] : undefined;
+ if (!activeSidebar) {
+ return;
+ }
+ activeSidebar.classList.add(MOBILE_SIDEBAR_SWIPING_CLASS);
+ mask?.classList.add(MOBILE_SIDEBAR_MASK_SWIPING_CLASS);
+};
+
export const getOpeningSidebar = (direction: MobileSwipeDirection): MobileSidebarSide => {
return direction === "toRight" ? "left" : "right";
};
diff --git a/app/src/util/Tree.ts b/app/src/util/Tree.ts
index d201a839c9..48ebd7b430 100644
--- a/app/src/util/Tree.ts
+++ b/app/src/util/Tree.ts
@@ -6,6 +6,7 @@ import {Constants} from "../constants";
import {escapeAriaLabel, escapeHtml} from "./escape";
import {hasClosestByTag} from "../protyle/util/hasClosest";
import {headingNumberNeedsSpacing} from "../protyle/util/headingNumberCore";
+import {getTreeItemTailHTML} from "./treeItemTail";
const genOutlineNumberHTML = (number?: string) => {
if (!number) {
@@ -98,7 +99,7 @@ export class Tree {
iconHTML = `<svg class="b3-list-item__graphic popover__block" data-id="${item.id}"><use xlink:href="#${getIconByType(item.nodeType, item.subType)}"></use></svg>`;
} else if (item.type === "outline") {
titleTip = ` aria-label="${escapeAriaLabel(Lute.BlockDOM2Content(item.name))}"`;
- iconHTML = `<svg class="b3-list-item__graphic popover__block" data-id="${item.id}" style="height: 22px;width: ${isM ? 20 : 16}px;"><use xlink:href="#${getIconByType(item.nodeType, item.subType)}"></use></svg>`;
+ iconHTML = `<svg class="b3-list-item__graphic popover__block" data-id="${item.id}" style="height: ${isM ? 16 : 22}px;width: 16px;"><use xlink:href="#${getIconByType(item.nodeType, item.subType)}"></use></svg>`;
}
let countHTML = "";
if (item.count) {
@@ -130,8 +131,7 @@ ${item.label !== undefined && item.label !== null ? `data-label='${item.label}'`
${iconHTML}
${numberHTML}
<span class="b3-list-item__text ariaLabel" data-position="${this.titleTooltipPosition}"${titleTip}>${item.name}</span>
- ${this.topExtHTML || ""}
- ${countHTML}
+ ${getTreeItemTailHTML(countHTML, this.topExtHTML || "", isM)}
</li>`;
if (item.children && item.children.length > 0) {
html += this.genHTML(item.children) + "</ul>";
@@ -161,7 +161,7 @@ ${item.label !== undefined && item.label !== null ? `data-label='${item.label}'`
const numberHTML = type === "outline" ? genOutlineNumberHTML(item.number) : "";
let iconHTML;
if (type === "outline") {
- iconHTML = `<svg data-showref="true" class="b3-list-item__graphic popover__block" data-id="${item.id}" style="height: 22px;width: ${isM?20:16}px;"><use xlink:href="#${getIconByType(item.type, item.subType)}"></use></svg>`;
+ iconHTML = `<svg data-showref="true" class="b3-list-item__graphic popover__block" data-id="${item.id}" style="height: ${isM ? 16 : 22}px;width: 16px;"><use xlink:href="#${getIconByType(item.type, item.subType)}"></use></svg>`;
} else {
if (item.type === "NodeDocument") {
iconHTML = `<span data-showref="true" class="b3-list-item__graphic popover__block" data-id="${item.id}">${unicode2Emoji(item.ial.icon || window.siyuan.storage[Constants.LOCAL_IMAGES].file)}</span>`;
@@ -192,8 +192,7 @@ data-def-path="${item.defPath}">
${iconHTML}
${numberHTML}
<span class="b3-list-item__text ariaLabel" data-position="${this.titleTooltipPosition}" ${type === "outline" ? ' aria-label="' + escapeAriaLabel(Lute.BlockDOM2Content(item.content)) + '"' : ""}>${item.content}</span>
- ${this.blockExtHTML || ""}
- ${countHTML}
+ ${getTreeItemTailHTML(countHTML, this.blockExtHTML || "", isM)}
</li>`;
if (item.children && item.children.length > 0) {
html += this.genBlockHTML(item.children, type === "outline" ? !item.folded : false, type) + "</ul>";
diff --git a/app/src/util/treeItemTail.test.ts b/app/src/util/treeItemTail.test.ts
new file mode 100644
index 0000000000..cb0dce2f96
--- /dev/null
+++ b/app/src/util/treeItemTail.test.ts
@@ -0,0 +1,21 @@
+import {describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import {getTreeItemTailHTML} from "./treeItemTail";
+
+describe("tree item tail", () => {
+ const countHTML = '<span class="counter">121</span>';
+ const actionHTML = '<span class="b3-list-item__action"></span>';
+
+ it("places mobile counters before actions", () => {
+ assert.equal(getTreeItemTailHTML(countHTML, actionHTML, true), `${countHTML}${actionHTML}`);
+ });
+
+ it("preserves the desktop action order", () => {
+ assert.equal(getTreeItemTailHTML(countHTML, actionHTML, false), `${actionHTML}${countHTML}`);
+ });
+
+ it("handles items without counters or actions", () => {
+ assert.equal(getTreeItemTailHTML("", actionHTML, true), actionHTML);
+ assert.equal(getTreeItemTailHTML(countHTML, "", true), countHTML);
+ });
+});
diff --git a/app/src/util/treeItemTail.ts b/app/src/util/treeItemTail.ts
new file mode 100644
index 0000000000..01b7c50310
--- /dev/null
+++ b/app/src/util/treeItemTail.ts
@@ -0,0 +1,3 @@
+export const getTreeItemTailHTML = (countHTML: string, actionHTML: string, mobile: boolean) => {
+ return mobile ? `${countHTML}${actionHTML}` : `${actionHTML}${countHTML}`;
+};