Skip to content

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

:sparkles: Support compact mode in tablet desktop interfaces https://github.com/siyuan-note/siyuan/issues/20503

Daniel236ba56db9dc
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-axh6q1d.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-axh6q1d.sy
index 6f6f8649d0..e3a27b4172 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-axh6q1d.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-axh6q1d.sy
@@ -7,7 +7,7 @@
"id": "20210808180303-axh6q1d",
"title": "Custom Appearance",
"type": "doc",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -50,7 +50,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20261013113128-1if2gvn",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -64,7 +64,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261013113128-l0hhnte",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -105,7 +105,7 @@
},
{
"Type": "NodeText",
- "Data": " to reduce spacing in desktop toolbars, tabs, navigation lists, menus and dialogs. The change takes effect immediately and is off by default. Editor text size, document and database content, exports and the mobile interface are unchanged."
+ "Data": " to reduce spacing in desktop toolbars, tabs, navigation lists, menus and dialogs, including when using the desktop interface in the tablet app. The change takes effect immediately and is off by default. Editor text size, document and database content, exports and the mobile interface are unchanged."
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-qgr0b3q.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-qgr0b3q.sy
index 30f9d86294..c2260b0941 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-qgr0b3q.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-qgr0b3q.sy
@@ -7,7 +7,7 @@
"id": "20210808180320-qgr0b3q",
"title": "自定义外观",
"type": "doc",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -57,7 +57,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20261013113128-3apehkq",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -71,7 +71,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261013113128-8do51zi",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -112,7 +112,7 @@
},
{
"Type": "NodeText",
- "Data": " 后,桌面端的工具栏、页签、导航列表、菜单和对话框会缩小间距。此选项默认关闭,切换后立即生效;不会改变编辑器文字大小、文档和数据库内容布局、导出结果或移动端界面。"
+ "Data": " 后,桌面界面的工具栏、页签、导航列表、菜单和对话框会缩小间距,平板 App 的桌面模式同样适用。此选项默认关闭,切换后立即生效;不会改变编辑器文字大小、文档和数据库内容布局、导出结果或移动界面。"
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121109-f060fkg.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121109-f060fkg.sy
index 7d1ebf16c8..35093958ba 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121109-f060fkg.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121109-f060fkg.sy
@@ -7,7 +7,7 @@
"id": "20211226121109-f060fkg",
"title": "自定義外觀",
"type": "doc",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -50,7 +50,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20261013113128-r6s9loi",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -64,7 +64,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261013113128-tpz11qw",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -105,7 +105,7 @@
},
{
"Type": "NodeText",
- "Data": " 後,桌面端的工具列、頁籤、導覽清單、選單和對話方塊會縮小間距。此選項預設關閉,切換後立即生效;不會改變編輯器文字大小、文件和資料庫內容版面、匯出結果或行動端介面。"
+ "Data": " 後,桌面介面的工具列、頁籤、導覽清單、選單和對話方塊會縮小間距,平板 App 的桌面模式同樣適用。此選項預設關閉,切換後立即生效;不會改變編輯器文字大小、文件和資料庫內容版面、匯出結果或行動介面。"
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-xr22qn8.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-xr22qn8.sy
index 5a2e11bef2..e833f86d74 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-xr22qn8.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-xr22qn8.sy
@@ -8,7 +8,7 @@
"id": "20240530101000-xr22qn8",
"title": "外観のカスタマイズ",
"type": "doc",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -53,7 +53,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20261013113128-e2px19z",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -67,7 +67,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261013113128-3hus3mv",
- "updated": "20261013113128"
+ "updated": "20261021001451"
},
"Children": [
{
@@ -104,7 +104,7 @@
},
{
"Type": "NodeText",
- "Data": " を有効にすると、デスクトップのツールバー、タブ、ナビゲーションリスト、メニュー、ダイアログの間隔が狭くなります。初期設定では無効で、切り替えるとすぐに反映されます。エディターの文字サイズ、文書やデータベースの内容のレイアウト、エクスポート結果、モバイル画面は変わりません。"
+ "Data": " を有効にすると、デスクトップ画面のツールバー、タブ、ナビゲーションリスト、メニュー、ダイアログの間隔が狭くなります。タブレットアプリのデスクトップモードでも利用できます。初期設定では無効で、切り替えるとすぐに反映されます。エディターの文字サイズ、文書やデータベースの内容のレイアウト、エクスポート結果、モバイル画面は変わりません。"
}
]
},
diff --git a/app/src/assets/scss/main/_main.scss b/app/src/assets/scss/main/_main.scss
index 8cafd6bf87..02c8fa07b8 100644
--- a/app/src/assets/scss/main/_main.scss
+++ b/app/src/assets/scss/main/_main.scss
@@ -106,9 +106,9 @@ body.body--harmony {
padding-bottom: var(--ios-window-safe-bottom, 0px);
}
-// 融合页签沿用原有的 42px 顶栏,仅增加横向占位,避免按钮与页签使用不同的纵向基准。
+// 融合页签与当前界面密度使用相同高度,仅增加横向占位,避免按钮与页签使用不同的纵向基准。
:root[data-ios-window-controls] .body--toolbar-hide #toolbar {
- height: 42px;
+ height: var(--b3-ui-panel-height, 42px);
padding-top: 0;
}
diff --git a/app/src/config/tabs/compactMode.test.ts b/app/src/config/tabs/compactMode.test.ts
index 97aa710b48..433b009826 100644
--- a/app/src/config/tabs/compactMode.test.ts
+++ b/app/src/config/tabs/compactMode.test.ts
@@ -4,7 +4,7 @@ import {test} from "node:test";
import {runInNewContext} from "node:vm";
import {ModuleKind, transpileModule} from "typescript";
-const fixture = (frontend = "desktop", mobileApp = false) => {
+const fixture = (frontend = "desktop", nativeBridge = {}) => {
const appearance = {compactMode: false};
const siyuan = {config: {appearance, readonly: false}, isPublish: false, isReady: true,
storage: {"local-compact-mode": true, "local-menu-mouse-scroll": true}};
@@ -16,18 +16,19 @@ const fixture = (frontend = "desktop", mobileApp = false) => {
runInNewContext(transpileModule(readFileSync("src/config/tabs/compactMode.ts", "utf8"), {
compilerOptions: {module: ModuleKind.CommonJS},
}).outputText, {exports, Event,
- window: {siyuan, dispatchEvent: (event: Event) => events.push(event.type)},
+ window: {...nativeBridge, siyuan, dispatchEvent: (event: Event) => events.push(event.type)},
document: {querySelectorAll: () => [input], documentElement: {
hasAttribute: (key: string) => attributes.has(key),
setAttribute: (key: string, value: string) => attributes.set(key, value),
removeAttribute: (key: string) => attributes.delete(key),
}},
- require: () => ({getFrontend: () => frontend, isInMobileApp: () => mobileApp,
+ require: () => ({getFrontend: () => frontend,
Constants: {ATTRIBUTE_UI_DENSITY: "data-ui-density"},
appearanceConfigApi: {patch: async (path: string, value: boolean) => {saved.push([path, value]);}},
}),
});
- return {api: exports, appearance, siyuan, saved, events, input, attributes};
+ return {api: exports, appearance, siyuan, saved, events, input, attributes,
+ setFrontend: (value: string) => {frontend = value;}};
};
test("compactMode ignores retired KV values and reads confirmed configuration updates", () => {
@@ -50,11 +51,48 @@ test("compactMode saves through the appearance namespace without optimistic conf
});
test("compactMode rejects readonly, published and mobile writes", async () => {
- for (const kind of ["readonly", "publish", "mobile", "browser-mobile", "mobile-app"]) {
- const f = fixture(kind.includes("mobile") && kind !== "mobile-app" ? kind : "desktop", kind === "mobile-app");
+ for (const kind of ["readonly", "publish", "mobile", "browser-mobile"]) {
+ const f = fixture(kind.includes("mobile") ? kind : "desktop");
f.siyuan.config.readonly = kind === "readonly";
f.siyuan.isPublish = kind === "publish";
await f.api.setCompactModeEnabled(true);
assert.deepEqual(f.saved, [], kind);
}
});
+
+test("compactMode supports desktop forms in browsers and native tablet apps", async () => {
+ for (const frontend of ["desktop", "desktop-window", "browser-desktop"]) {
+ for (const nativeBridge of [{}, {JSAndroid: {}}, {webkit: {messageHandlers: {}}}, {JSHarmony: {}}]) {
+ const f = fixture(frontend, nativeBridge);
+ assert.equal(f.api.isCompactModeAvailable(), true);
+ await f.api.setCompactModeEnabled(true);
+ assert.deepEqual(f.saved, [["compactMode", true]]);
+ f.appearance.compactMode = true;
+ f.api.applyCompactMode();
+ assert.equal(f.input.checked, true);
+ assert.equal(f.attributes.get("data-ui-density"), "compact");
+ assert.deepEqual(f.events, ["resize"]);
+ f.api.applyCompactMode();
+ assert.deepEqual(f.events, ["resize"], "unchanged density does not resize again");
+ }
+ }
+});
+
+test("compactMode preserves the preference across desktop and mobile interface changes", () => {
+ for (const frontend of ["mobile", "browser-mobile"]) {
+ const f = fixture();
+ f.appearance.compactMode = true;
+ f.api.applyCompactMode();
+ f.setFrontend(frontend);
+ assert.equal(f.api.isCompactModeAvailable(), false);
+ f.api.applyCompactMode();
+ assert.equal(f.input.checked, false);
+ assert.equal(f.attributes.has("data-ui-density"), false);
+ assert.equal(f.appearance.compactMode, true);
+ f.setFrontend("desktop");
+ f.api.applyCompactMode();
+ assert.equal(f.input.checked, true);
+ assert.equal(f.attributes.get("data-ui-density"), "compact");
+ assert.deepEqual(f.events, ["resize", "resize", "resize"]);
+ }
+});
diff --git a/app/src/config/tabs/compactMode.ts b/app/src/config/tabs/compactMode.ts
index 7b37a0635a..76550b5a63 100644
--- a/app/src/config/tabs/compactMode.ts
+++ b/app/src/config/tabs/compactMode.ts
@@ -1,10 +1,9 @@
import {Constants} from "../../constants";
-import {isInMobileApp} from "../../protyle/util/compatibility";
import {getFrontend} from "../../util/functions";
import {appearanceConfigApi} from "./appearanceRuntime";
export const isCompactModeAvailable = () =>
- !isInMobileApp() && ["desktop", "desktop-window", "browser-desktop"].includes(getFrontend());
+ ["desktop", "desktop-window", "browser-desktop"].includes(getFrontend());
export const isCompactModeEnabled = () =>
isCompactModeAvailable() && window.siyuan.config.appearance?.compactMode === true;
diff --git a/app/tests/compactModeLayout.test.js b/app/tests/compactModeLayout.test.js
index f133305117..72927087aa 100644
--- a/app/tests/compactModeLayout.test.js
+++ b/app/tests/compactModeLayout.test.js
@@ -19,7 +19,7 @@ const browserCases = ({css, desktop, community}) => {
document.body.style.fontSize = "14px";
const item = '<li class="b3-list-item"><span class="b3-list-item__text">Document title</span></li>';
document.body.innerHTML = `
- <div class="toolbar fn__flex"><div id="drag" class="fn__flex-1">SiYuan</div>
+ <div id="toolbar" class="toolbar fn__flex"><div id="drag" class="fn__flex-1">SiYuan</div>
<div class="toolbar__item toolbar__item--close"><svg><use href="#iconClose"></use></svg></div></div>
<div class="dock" id="dockLeft"><span class="dock__item"><svg><use href="#iconFiles"></use></svg></span></div>
<div class="layout__dockl"><div class="block__icons">Files</div><ul class="b3-list" id="navigation">${item}</ul></div>
@@ -120,14 +120,48 @@ const browserCases = ({css, desktop, community}) => {
}
near(height("#statusHelp svg"), 15.5, "status icon size is preserved");
near(number(".status__counter", "fontSize"), 12, "status text size is preserved");
+ for (const platform of ["android", "harmony", "ios"]) {
+ document.body.classList.add(`body--${platform}`);
+ check.deepEqual(snapshot(), compact, `${platform} desktop interface uses compact density`);
+ document.body.classList.remove(`body--${platform}`);
+ }
+ document.body.classList.add("body--ios");
document.documentElement.setAttribute("data-ios-window-controls", "");
+ document.documentElement.style.setProperty("--ios-window-controls-left", "80px");
+ document.documentElement.style.setProperty("--ios-window-controls-right", "60px");
+ document.documentElement.style.setProperty("--ios-window-controls-height", "50px");
+ document.documentElement.style.setProperty("--ios-window-safe-top", "24px");
document.documentElement.style.setProperty("--ios-window-safe-bottom", "20px");
+ near(height("#toolbar"), 56, "separate iOS toolbar retains its safe top area");
+ near(number("#toolbar", "paddingTop"), 24, "iOS safe top padding");
+ document.documentElement.style.setProperty("--ios-window-safe-top", "0px");
+ near(height("#toolbar"), 50, "separate iOS toolbar retains the native control height");
+ document.documentElement.style.setProperty("--ios-window-safe-top", "24px");
+ for (const density of ["compact", "normal"]) {
+ if (density === "normal") document.documentElement.removeAttribute("data-ui-density");
+ document.body.classList.add("body--toolbar-hide");
+ settle();
+ const expected = density === "compact" ? 34 : 42;
+ near(height("#toolbar"), expected, `${density} fused iOS toolbar height`);
+ near(height("#tabs"), expected, `${density} fused iOS tabs align`);
+ near(number(".layout__dockl", "marginTop"), expected, `${density} iOS side panel offset`);
+ near(number("#dockLeft", "marginTop"), expected, `${density} iOS dock offset`);
+ near(number("#toolbar", "paddingLeft"), 85, `${density} native left controls remain reserved`);
+ near(number("#toolbar", "paddingRight"), 65, `${density} native right controls remain reserved`);
+ near(number("#toolbar", "paddingTop"), 0, `${density} fused toolbar keeps its vertical baseline`);
+ checkTabEdge();
+ document.body.classList.remove("body--toolbar-hide");
+ }
+ document.documentElement.setAttribute("data-ui-density", "compact");
near(height("#status"), 48, "compact status bar retains the iOS safe area");
document.documentElement.removeAttribute("data-ui-density");
near(height("#status"), 52, "normal status bar retains the iOS safe area");
document.documentElement.setAttribute("data-ui-density", "compact");
document.documentElement.removeAttribute("data-ios-window-controls");
- document.documentElement.style.removeProperty("--ios-window-safe-bottom");
+ for (const name of ["controls-left", "controls-right", "controls-height", "safe-top", "safe-bottom"]) {
+ document.documentElement.style.removeProperty(`--ios-window-${name}`);
+ }
+ document.body.classList.remove("body--ios");
near(compact.panel.height, 34, "panel height");
near(compact.list.height, 24, "list height");
near(compact.menu.height, 26, "menu height");