Skip to content

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

:art: Add mobile navigation history to the bottom bar https://github.com/siyuan-note/siyuan/issues/14542

Daniel3b78e64d3c2b
diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scss
index 62918b8d0b..f424f6ec4e 100644
--- a/app/src/assets/scss/main/_mobile.scss
+++ b/app/src/assets/scss/main/_mobile.scss
@@ -315,7 +315,7 @@ body.mobile-keyboard--open {
box-sizing: border-box;
display: flex;
align-items: flex-start;
- width: min(72%, 420px);
+ width: min(88%, 420px);
height: var(--mobile-bottom-bar-height);
margin: 0 auto;
padding: 0;
diff --git a/app/src/assets/template/mobile/index.tpl b/app/src/assets/template/mobile/index.tpl
index 9e44b92dc9..bf2e72177b 100644
--- a/app/src/assets/template/mobile/index.tpl
+++ b/app/src/assets/template/mobile/index.tpl
@@ -76,6 +76,12 @@
<div id="tooltip" class="tooltip fn__none"></div>
<div id="status" class="status"></div>
<div id="mobileBottomBar" class="mobile-bottom-bar fn__none" role="group" aria-hidden="false" data-prevent-swipe>
+ <button id="mobileBottomBarBack" class="mobile-bottom-bar__item fn__none" data-action="back" type="button" disabled>
+ <svg><use xlink:href="#iconLeft"></use></svg>
+ </button>
+ <button id="mobileBottomBarForward" class="mobile-bottom-bar__item fn__none" data-action="forward" type="button" disabled>
+ <svg><use xlink:href="#iconRight"></use></svg>
+ </button>
<button id="toolbarFile" class="mobile-bottom-bar__item" data-action="documents" type="button">
<svg><use xlink:href="#iconFiles"></use></svg>
</button>
diff --git a/app/src/mobile/tabs/MobileTabs.ts b/app/src/mobile/tabs/MobileTabs.ts
index 5d7019b47f..47c00436f5 100644
--- a/app/src/mobile/tabs/MobileTabs.ts
+++ b/app/src/mobile/tabs/MobileTabs.ts
@@ -175,6 +175,7 @@ export class MobileTabs {
};
window.siyuan.storage[Constants.LOCAL_MOBILE_TABS] = persistedState;
setStorageVal(Constants.LOCAL_MOBILE_TABS, persistedState);
+ this.updateNavigationButtons();
}
private updateCounter() {
@@ -184,6 +185,17 @@ export class MobileTabs {
}
}
+ private updateNavigationButtons() {
+ const backElement = document.getElementById("mobileBottomBarBack") as HTMLButtonElement;
+ const forwardElement = document.getElementById("mobileBottomBarForward") as HTMLButtonElement;
+ if (backElement) {
+ backElement.disabled = !this.canGoBack();
+ }
+ if (forwardElement) {
+ forwardElement.disabled = !this.canGoForward();
+ }
+ }
+
private snapshot(tab = this.activeTab) {
if (!tab?.current || !window.siyuan.mobile.editor?.protyle) {
return;
@@ -556,6 +568,14 @@ export class MobileTabs {
return false;
}
+ canGoBack() {
+ return Boolean(this.activeTab?.backStack.length) || this.hasActivationTarget(this.activationBackStack);
+ }
+
+ canGoForward() {
+ return Boolean(this.activeTab?.forwardStack.length) || this.hasActivationTarget(this.activationForwardStack);
+ }
+
async goBack(): Promise<boolean> {
const tab = this.activeTab;
if (!tab?.backStack.length) {
@@ -760,14 +780,13 @@ export class MobileTabs {
</button>
</div>`;
}).join("");
- const tab = this.activeTab;
openModel({
title: `${window.siyuan.languages.mobileTabs} ${this.state.tabs.length}`,
html: `<div class="mobile-tabs">
<div class="mobile-tabs__list">${rows || `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`}</div>
<div class="mobile-tabs__actions">
- <button class="b3-button b3-button--outline" data-action="back"${tab?.backStack.length || this.hasActivationTarget(this.activationBackStack) ? "" : " disabled"}><svg><use xlink:href="#iconLeft"></use></svg>${window.siyuan.languages.goBack}</button>
- <button class="b3-button b3-button--outline" data-action="forward"${tab?.forwardStack.length || this.hasActivationTarget(this.activationForwardStack) ? "" : " disabled"}><svg><use xlink:href="#iconRight"></use></svg>${window.siyuan.languages.goForward}</button>
+ <button class="b3-button b3-button--outline" data-action="back"${this.canGoBack() ? "" : " disabled"}><svg><use xlink:href="#iconLeft"></use></svg>${window.siyuan.languages.goBack}</button>
+ <button class="b3-button b3-button--outline" data-action="forward"${this.canGoForward() ? "" : " disabled"}><svg><use xlink:href="#iconRight"></use></svg>${window.siyuan.languages.goForward}</button>
<button class="b3-button b3-button--outline" data-action="new-doc"><svg><use xlink:href="#iconAddDoc"></use></svg>${window.siyuan.languages.newFile}</button>
<button class="b3-button b3-button--outline" data-action="close-all"${this.state.tabs.length ? "" : " disabled"}><svg><use xlink:href="#iconTrashcan"></use></svg>${window.siyuan.languages.closeAll}</button>
</div>
diff --git a/app/src/mobile/util/mobileBottomBar.ts b/app/src/mobile/util/mobileBottomBar.ts
index f733074a15..ef510d50d2 100644
--- a/app/src/mobile/util/mobileBottomBar.ts
+++ b/app/src/mobile/util/mobileBottomBar.ts
@@ -24,6 +24,10 @@ import {
const getActionLabel = (action: MobileBottomBarAction) => {
switch (action) {
+ case "back":
+ return window.siyuan.languages.goBack;
+ case "forward":
+ return window.siyuan.languages.goForward;
case "documents":
return window.siyuan.languages.fileTree;
case "search":
@@ -142,6 +146,20 @@ export const initMobileBottomBar = (app: App) => {
}
bottomBarElement.classList.remove("fn__none");
bottomBarElement.dataset.bound = "true";
+ bindBottomBarAction("mobileBottomBarBack", () => {
+ if (isMobileBlockSelecting()) {
+ return;
+ }
+ activeBlur();
+ void window.siyuan.mobile.tabs?.goBack();
+ });
+ bindBottomBarAction("mobileBottomBarForward", () => {
+ if (isMobileBlockSelecting()) {
+ return;
+ }
+ activeBlur();
+ void window.siyuan.mobile.tabs?.goForward();
+ });
bindBottomBarAction("mobileBottomBarSearch", () => {
if (isMobileBlockSelecting()) {
return;
@@ -237,7 +255,7 @@ const genBottomBarOptions = () => MOBILE_BOTTOM_BAR_ACTIONS.map((action) =>
export const genMobileBottomBarSettingHTML = () => {
const title = window.siyuan.languages.mobileBottomBar;
const disabled = window.siyuan.config.readonly || window.siyuan.isPublish ? " disabled" : "";
- const selects = [0, 1, 2, 3].map((slot) => `<label class="mobile-bottom-bar-setting__slot">
+ const selects = [0, 1, 2, 3, 4].map((slot) => `<label class="mobile-bottom-bar-setting__slot">
<span>${slot + 1}</span>
<select class="b3-select fn__flex-1" data-bottom-bar-slot="${slot}" aria-label="${escapeAttr(`${title} ${slot + 1}`)}"${disabled}>${genBottomBarOptions()}</select>
</label>`).join("");
@@ -271,7 +289,7 @@ export const mountMobileBottomBarSetting = (root: HTMLElement) => {
}
const slot = Number(selectElement.dataset.bottomBarSlot);
const action = selectElement.value as MobileBottomBarAction;
- if (![0, 1, 2, 3].includes(slot) || !MOBILE_BOTTOM_BAR_ACTIONS.includes(action)) {
+ if (![0, 1, 2, 3, 4].includes(slot) || !MOBILE_BOTTOM_BAR_ACTIONS.includes(action)) {
syncSelects();
return;
}
diff --git a/app/src/mobile/util/mobileBottomBarConfig.test.ts b/app/src/mobile/util/mobileBottomBarConfig.test.ts
index 40f75e5a02..86b0a2d1cd 100644
--- a/app/src/mobile/util/mobileBottomBarConfig.test.ts
+++ b/app/src/mobile/util/mobileBottomBarConfig.test.ts
@@ -17,22 +17,44 @@ describe("mobile bottom bar config", () => {
false,
"not json",
[],
- {version: 2, actions: ["recent", "outline", "bookmark", "tag"]},
+ {version: 3, actions: ["recent", "outline", "bookmark", "tag", "back"]},
{version: MOBILE_BOTTOM_BAR_CONFIG_VERSION, actions: "documents"},
].forEach((storedValue) => {
assert.deepEqual(normalizeMobileBottomBarConfig(storedValue), createDefaultMobileBottomBarConfig());
});
});
+ it("uses back, forward, documents, search, and tabs by default", () => {
+ assert.deepEqual(DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS, ["back", "forward", "documents", "search", "tabs"]);
+ });
+
+ it("migrates the legacy default to the new five-slot default", () => {
+ const config = normalizeMobileBottomBarConfig({
+ version: 1,
+ actions: ["documents", "search", "newDoc", "tabs"],
+ });
+
+ assert.deepEqual(config, createDefaultMobileBottomBarConfig());
+ });
+
+ it("preserves customized legacy slots and appends back", () => {
+ const config = normalizeMobileBottomBarConfig({
+ version: 1,
+ actions: ["recent", "outline", "bookmark", "tag"],
+ });
+
+ assert.deepEqual(config.actions, ["recent", "outline", "bookmark", "tag", "back"]);
+ });
+
it("accepts serialized config and fills invalid or duplicate slots in order", () => {
const config = normalizeMobileBottomBarConfig(JSON.stringify({
version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
actions: ["recent", "recent", "unknown", "tag"],
}));
- assert.deepEqual(config.actions, ["recent", "documents", "search", "tag"]);
- assert.equal(config.actions.length, 4);
- assert.equal(new Set(config.actions).size, 4);
+ assert.deepEqual(config.actions, ["recent", "back", "forward", "tag", "documents"]);
+ assert.equal(config.actions.length, 5);
+ assert.equal(new Set(config.actions).size, 5);
assert.equal(config.actions.every((action) => MOBILE_BOTTOM_BAR_ACTIONS.includes(action)), true);
});
@@ -43,25 +65,25 @@ describe("mobile bottom bar config", () => {
action: "tabs",
});
- assert.deepEqual(config.actions, ["tabs", "search", "newDoc", "documents"]);
+ assert.deepEqual(config.actions, ["tabs", "forward", "documents", "search", "back"]);
});
- it("supports inbox, backlinks, the agent, and spaced repetition as configurable actions", () => {
+ it("supports inbox, backlinks, the agent, spaced repetition, and forward as configurable actions", () => {
const config = normalizeMobileBottomBarConfig({
version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
- actions: ["inbox", "backlink", "agent", "spacedRepetition"],
+ actions: ["inbox", "backlink", "agent", "spacedRepetition", "forward"],
});
- assert.deepEqual(config.actions, ["inbox", "backlink", "agent", "spacedRepetition"]);
+ assert.deepEqual(config.actions, ["inbox", "backlink", "agent", "spacedRepetition", "forward"]);
});
it("supports selecting and quickly creating daily notes", () => {
const config = normalizeMobileBottomBarConfig({
version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
- actions: ["dailyNote", "newDailyNote", "documents", "tabs"],
+ actions: ["dailyNote", "newDailyNote", "documents", "tabs", "back"],
});
- assert.deepEqual(config.actions, ["dailyNote", "newDailyNote", "documents", "tabs"]);
+ assert.deepEqual(config.actions, ["dailyNote", "newDailyNote", "documents", "tabs", "back"]);
});
it("replaces a slot when selecting an unused action", () => {
@@ -71,52 +93,55 @@ describe("mobile bottom bar config", () => {
action: "outline",
});
- assert.deepEqual(config.actions, ["documents", "outline", "newDoc", "tabs"]);
+ assert.deepEqual(config.actions, ["back", "outline", "documents", "search", "tabs"]);
});
it("resets customized actions to a fresh default config", () => {
const customized = normalizeMobileBottomBarConfig({
version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
- actions: ["recent", "outline", "bookmark", "command"],
+ actions: ["recent", "outline", "bookmark", "command", "back"],
});
const config = reduceMobileBottomBarConfig(customized, {type: "reset"});
- assert.equal(config.version, 1);
+ assert.equal(config.version, 2);
assert.deepEqual(config.actions, DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS);
assert.notEqual(config.actions, DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS);
});
it("replaces actions that are unavailable in the current mode", () => {
- const config = resolveMobileBottomBarAvailability(createDefaultMobileBottomBarConfig(), ["newDoc"]);
+ const config = resolveMobileBottomBarAvailability({
+ version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
+ actions: ["back", "forward", "documents", "newDoc", "tabs"],
+ }, ["newDoc"]);
- assert.deepEqual(config.actions, ["documents", "search", "recent", "tabs"]);
+ assert.deepEqual(config.actions, ["back", "forward", "documents", "search", "tabs"]);
assert.equal(config.actions.includes("newDoc"), false);
});
it("replaces the agent when AI is unavailable", () => {
const config = resolveMobileBottomBarAvailability({
version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
- actions: ["documents", "agent", "newDoc", "tabs"],
+ actions: ["documents", "agent", "newDoc", "tabs", "back"],
}, ["agent"]);
- assert.deepEqual(config.actions, ["documents", "search", "newDoc", "tabs"]);
+ assert.deepEqual(config.actions, ["documents", "forward", "newDoc", "tabs", "back"]);
});
it("replaces spaced repetition in read-only mode", () => {
const config = resolveMobileBottomBarAvailability({
version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
- actions: ["documents", "spacedRepetition", "search", "tabs"],
+ actions: ["documents", "spacedRepetition", "search", "tabs", "back"],
}, ["spacedRepetition"]);
- assert.deepEqual(config.actions, ["documents", "newDoc", "search", "tabs"]);
+ assert.deepEqual(config.actions, ["documents", "forward", "search", "tabs", "back"]);
});
it("replaces daily note actions when document creation is unavailable", () => {
const config = resolveMobileBottomBarAvailability({
version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
- actions: ["dailyNote", "newDailyNote", "documents", "tabs"],
+ actions: ["dailyNote", "newDailyNote", "documents", "tabs", "back"],
}, ["dailyNote", "newDailyNote"]);
- assert.deepEqual(config.actions, ["search", "newDoc", "documents", "tabs"]);
+ assert.deepEqual(config.actions, ["forward", "search", "documents", "tabs", "back"]);
});
});
diff --git a/app/src/mobile/util/mobileBottomBarConfig.ts b/app/src/mobile/util/mobileBottomBarConfig.ts
index c4dfeecab6..8d79ef9563 100644
--- a/app/src/mobile/util/mobileBottomBarConfig.ts
+++ b/app/src/mobile/util/mobileBottomBarConfig.ts
@@ -1,6 +1,8 @@
-export const MOBILE_BOTTOM_BAR_CONFIG_VERSION = 1 as const;
+export const MOBILE_BOTTOM_BAR_CONFIG_VERSION = 2 as const;
export const MOBILE_BOTTOM_BAR_ACTIONS = [
+ "back",
+ "forward",
"documents",
"search",
"newDoc",
@@ -19,12 +21,13 @@ export const MOBILE_BOTTOM_BAR_ACTIONS = [
] as const;
export type MobileBottomBarAction = typeof MOBILE_BOTTOM_BAR_ACTIONS[number];
-export type MobileBottomBarSlot = 0 | 1 | 2 | 3;
+export type MobileBottomBarSlot = 0 | 1 | 2 | 3 | 4;
export type MobileBottomBarSlots = readonly [
MobileBottomBarAction,
MobileBottomBarAction,
MobileBottomBarAction,
MobileBottomBarAction,
+ MobileBottomBarAction,
];
export interface IMobileBottomBarConfig {
@@ -41,12 +44,15 @@ export type MobileBottomBarConfigEvent = {
};
export const DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS: MobileBottomBarSlots = [
+ "back",
+ "forward",
"documents",
"search",
- "newDoc",
"tabs",
];
+const LEGACY_DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS = ["documents", "search", "newDoc", "tabs"];
+
export const DEFAULT_MOBILE_BOTTOM_BAR_CONFIG: IMobileBottomBarConfig = {
version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
actions: DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS,
@@ -59,11 +65,11 @@ export const isMobileBottomBarAction = (value: unknown): value is MobileBottomBa
};
const toMobileBottomBarSlots = (actions: MobileBottomBarAction[]): MobileBottomBarSlots => {
- return [actions[0], actions[1], actions[2], actions[3]];
+ return [actions[0], actions[1], actions[2], actions[3], actions[4]];
};
const normalizeMobileBottomBarActions = (storedActions: unknown[]): MobileBottomBarSlots => {
- const actions = new Array<MobileBottomBarAction>(4);
+ const actions = new Array<MobileBottomBarAction>(5);
const usedActions = new Set<MobileBottomBarAction>();
for (let slot = 0; slot < actions.length; slot++) {
@@ -112,7 +118,11 @@ export const normalizeMobileBottomBarConfig = (storedValue: unknown): IMobileBot
}
const record = value as Record<string, unknown>;
- if (record.version !== MOBILE_BOTTOM_BAR_CONFIG_VERSION || !Array.isArray(record.actions)) {
+ if ((record.version !== 1 && record.version !== MOBILE_BOTTOM_BAR_CONFIG_VERSION) || !Array.isArray(record.actions)) {
+ return createDefaultMobileBottomBarConfig();
+ }
+ if (record.version === 1 && record.actions.length === LEGACY_DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS.length &&
+ record.actions.every((action, index) => action === LEGACY_DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS[index])) {
return createDefaultMobileBottomBarConfig();
}
return {