Skip to content

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

:art: Refine mobile navigation behavior https://github.com/siyuan-note/siyuan/issues/14542

Daniel84f28d695a6c
diff --git a/app/appearance/icons/index.html b/app/appearance/icons/index.html
index 034fa7b040..f91f2967bd 100644
--- a/app/appearance/icons/index.html
+++ b/app/appearance/icons/index.html
@@ -496,6 +496,12 @@
</svg>
iconCalendar
</div>
+ <div>
+ <svg>
+ <use xlink:href="#iconCalendarPlus"></use>
+ </svg>
+ iconCalendarPlus
+ </div>
<div>
<svg>
<use xlink:href="#iconNumber"></use>
diff --git a/app/appearance/icons/litheness/icon.js b/app/appearance/icons/litheness/icon.js
index b8c340ee00..a1bf3d5f93 100644
--- a/app/appearance/icons/litheness/icon.js
+++ b/app/appearance/icons/litheness/icon.js
@@ -236,7 +236,10 @@ document.body.insertAdjacentHTML('afterbegin', `<svg id="iconsLitheness" style="
</symbol>
<symbol id="iconCalendar" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
<path d="M8 2v4"/><path d="M16 2v4"/><rect width="18" height="18" x="3" y="4" rx="2"/><path d="M3 10h18"/>
- </symbol>
+ </symbol>
+ <symbol id="iconCalendarPlus" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
+ <path d="M16 18h6"/><path d="M16 2v3"/><path d="M19 15v6"/><path d="M21 11.5V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8.3"/><path d="M3 9h18"/><path d="M8 2v3"/>
+ </symbol>
<symbol id="iconNumber" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
<line x1="4" x2="20" y1="9" y2="9"/><line x1="4" x2="20" y1="15" y2="15"/><line x1="10" x2="8" y1="3" y2="21"/><line x1="16" x2="14" y1="3" y2="21"/>
</symbol>
diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scss
index 21557cf267..d9358201ea 100644
--- a/app/src/assets/scss/main/_mobile.scss
+++ b/app/src/assets/scss/main/_mobile.scss
@@ -371,8 +371,8 @@ body.mobile-keyboard--open {
display: flex;
align-items: center;
justify-content: center;
- min-width: 20px;
- height: 20px;
+ min-width: 19px;
+ height: 19px;
padding: 0 2px;
border: 1.5px solid currentColor;
border-radius: 4px;
@@ -430,13 +430,18 @@ body.mobile-topbar--merged {
}
}
-.mobile-keyboard--open .mobile-bottom-bar {
+.mobile-keyboard--open .mobile-bottom-bar,
+.mobile-selection--active .mobile-bottom-bar {
opacity: 0;
pointer-events: none;
transform: translateY(100%);
visibility: hidden;
}
+.mobile-keyboard--open .mobile-bottom-bar {
+ transition: none;
+}
+
.mobile-bottom-bar-setting {
display: block;
diff --git a/app/src/assets/template/mobile/index.tpl b/app/src/assets/template/mobile/index.tpl
index 565c11f004..9e44b92dc9 100644
--- a/app/src/assets/template/mobile/index.tpl
+++ b/app/src/assets/template/mobile/index.tpl
@@ -28,7 +28,6 @@
<svg data-type="sidebar-bookmark-tab" class="toolbar__icon"><use xlink:href="#iconBookmark"></use></svg>
<svg data-type="sidebar-tag-tab" class="toolbar__icon"><use xlink:href="#iconTag"></use></svg>
<svg data-type="sidebar-inbox-tab" class="toolbar__icon"><use xlink:href="#iconInbox"></use></svg>
- <svg data-menu="true" data-type="sidebar-plugin-tab" class="toolbar__icon fn__none"><use xlink:href="#iconPlugin"></use></svg>
</div>
<svg class="toolbar__icon"><use xlink:href="#iconRight"></use></svg>
</div>
@@ -37,7 +36,6 @@
<div class="fn__flex-column fn__none" data-type="sidebar-bookmark"></div>
<div class="fn__flex-column fn__none" data-type="sidebar-tag"></div>
<div class="fn__flex-column fn__none" data-type="sidebar-inbox"></div>
- <div class="fn__flex-column fn__none" data-type="sidebar-plugin"></div>
</div>
</div>
<div id="sidebarRight" class="side-panel side-panel--right fn__flex-column">
@@ -114,6 +112,12 @@
<button id="mobileBottomBarSpacedRepetition" class="mobile-bottom-bar__item fn__none" data-action="spacedRepetition" type="button">
<svg><use xlink:href="#iconRiffCard"></use></svg>
</button>
+ <button id="mobileBottomBarDailyNote" class="mobile-bottom-bar__item fn__none" data-action="dailyNote" type="button">
+ <svg><use xlink:href="#iconCalendar"></use></svg>
+ </button>
+ <button id="mobileBottomBarNewDailyNote" class="mobile-bottom-bar__item fn__none" data-action="newDailyNote" type="button">
+ <svg><use xlink:href="#iconCalendarPlus"></use></svg>
+ </button>
<button id="mobileBottomBarCommand" class="mobile-bottom-bar__item fn__none" data-action="command" type="button">
<svg><use xlink:href="#iconTerminal"></use></svg>
</button>
diff --git a/app/src/mobile/dock/pluginDockState.test.ts b/app/src/mobile/dock/pluginDockState.test.ts
index 7ff89efe12..4cb3566cf4 100644
--- a/app/src/mobile/dock/pluginDockState.test.ts
+++ b/app/src/mobile/dock/pluginDockState.test.ts
@@ -1,51 +1,73 @@
import * as assert from "node:assert/strict";
-import test from "node:test";
-import {openMobilePluginDock, removeMobilePluginDock} from "./pluginDockState";
+import {describe, it} from "node:test";
+import {
+ getMobilePluginDock,
+ getMobilePluginDockSide,
+ openMobilePluginDock,
+ removeMobilePluginDock,
+} from "./pluginDockState";
-test("mobile plugin docks replace and remove the active model", () => {
- const windowDescriptor = Object.getOwnPropertyDescriptor(globalThis, "window");
- const docks: Record<string, unknown> = {};
- Object.defineProperty(globalThis, "window", {
- configurable: true,
- value: {siyuan: {mobile: {docks}}},
+describe("mobile plugin dock state", () => {
+ it("maps desktop dock positions to the corresponding mobile side", () => {
+ assert.equal(getMobilePluginDockSide("LeftTop"), "left");
+ assert.equal(getMobilePluginDockSide("LeftBottom"), "left");
+ assert.equal(getMobilePluginDockSide("BottomLeft"), "left");
+ assert.equal(getMobilePluginDockSide("RightTop"), "right");
+ assert.equal(getMobilePluginDockSide("RightBottom"), "right");
+ assert.equal(getMobilePluginDockSide("BottomRight"), "right");
});
- let firstDestroyed = 0;
- let secondDestroyed = 0;
- let duplicateCreated = false;
- const first = {
- type: "first",
- element: {innerHTML: "first"},
- destroy: () => firstDestroyed++,
- };
- const second = {
- type: "second",
- element: {innerHTML: "second"},
- destroy: () => secondDestroyed++,
- };
- try {
- openMobilePluginDock("first", () => first as never);
- openMobilePluginDock("first", () => {
- duplicateCreated = true;
- return first as never;
+
+ it("keeps plugin docks independent and removes only the requested model", () => {
+ const windowDescriptor = Object.getOwnPropertyDescriptor(globalThis, "window");
+ const docks: Record<string, unknown> = {};
+ Object.defineProperty(globalThis, "window", {
+ configurable: true,
+ value: {siyuan: {mobile: {docks}}},
});
- openMobilePluginDock("second", () => second as never);
+ let firstDestroyed = 0;
+ let secondDestroyed = 0;
+ let duplicateCreated = false;
+ const first = {
+ type: "first",
+ element: {innerHTML: "first"},
+ destroy: () => firstDestroyed++,
+ };
+ const second = {
+ type: "second",
+ element: {innerHTML: "second"},
+ destroy: () => secondDestroyed++,
+ };
+ try {
+ openMobilePluginDock("first", () => first as never);
+ openMobilePluginDock("first", () => {
+ duplicateCreated = true;
+ return first as never;
+ });
+ openMobilePluginDock("second", () => second as never);
- assert.equal(duplicateCreated, false);
- assert.equal(firstDestroyed, 1);
- assert.equal(docks.first, undefined);
- assert.equal(docks.second, second);
+ assert.equal(duplicateCreated, false);
+ assert.equal(firstDestroyed, 0);
+ assert.equal(getMobilePluginDock("first"), first);
+ assert.equal(getMobilePluginDock("second"), second);
+ assert.equal(docks.first, first);
+ assert.equal(docks.second, second);
- removeMobilePluginDock("second");
- assert.equal(secondDestroyed, 1);
- assert.equal(second.element.innerHTML, "");
- assert.equal(docks.second, undefined);
- } finally {
- removeMobilePluginDock("first");
- removeMobilePluginDock("second");
- if (windowDescriptor) {
- Object.defineProperty(globalThis, "window", windowDescriptor);
- } else {
- Reflect.deleteProperty(globalThis, "window");
+ removeMobilePluginDock("first");
+ assert.equal(firstDestroyed, 1);
+ assert.equal(first.element.innerHTML, "");
+ assert.equal(secondDestroyed, 0);
+ assert.equal(getMobilePluginDock("first"), undefined);
+ assert.equal(getMobilePluginDock("second"), second);
+ assert.equal(docks.first, undefined);
+ assert.equal(docks.second, second);
+ } finally {
+ removeMobilePluginDock("first");
+ removeMobilePluginDock("second");
+ if (windowDescriptor) {
+ Object.defineProperty(globalThis, "window", windowDescriptor);
+ } else {
+ Reflect.deleteProperty(globalThis, "window");
+ }
}
- }
+ });
});
diff --git a/app/src/mobile/dock/pluginDockState.ts b/app/src/mobile/dock/pluginDockState.ts
index f4ddcdf19b..6847f6105a 100644
--- a/app/src/mobile/dock/pluginDockState.ts
+++ b/app/src/mobile/dock/pluginDockState.ts
@@ -1,30 +1,34 @@
import {MobileCustom} from "./MobileCustom";
-let custom: MobileCustom | undefined;
+export const MOBILE_PLUGIN_DOCKS_CHANGE_EVENT = "siyuan-mobile-plugin-docks-change";
-export const getMobilePluginDock = () => custom;
+const customs = new Map<string, MobileCustom>();
+
+export const getMobilePluginDockSide = (position: TPluginDockPosition) => {
+ return position === "LeftTop" || position === "LeftBottom" || position === "BottomLeft" ? "left" : "right";
+};
+
+export const dispatchMobilePluginDocksChange = () => {
+ window.dispatchEvent(new CustomEvent(MOBILE_PLUGIN_DOCKS_CHANGE_EVENT));
+};
+
+export const getMobilePluginDock = (type: string) => customs.get(type);
export const openMobilePluginDock = (type: string, create: () => MobileCustom) => {
- if (custom?.type === type) {
+ if (customs.has(type)) {
return;
}
- const previousType = custom?.type;
- custom?.destroy?.();
- if (previousType) {
- delete window.siyuan.mobile.docks[previousType];
- }
- custom = create();
+ const custom = create();
+ customs.set(type, custom);
window.siyuan.mobile.docks[type] = custom;
};
export const removeMobilePluginDock = (type: string) => {
- const dock = window.siyuan.mobile.docks[type] as MobileCustom;
- if (custom?.type === type) {
+ const custom = customs.get(type) || window.siyuan.mobile.docks[type] as MobileCustom;
+ if (custom) {
custom.destroy?.();
custom.element.innerHTML = "";
- custom = undefined;
- } else {
- dock?.destroy?.();
}
+ customs.delete(type);
delete window.siyuan.mobile.docks[type];
};
diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.ts
index 4fbe4061ef..ffe12c3461 100644
--- a/app/src/mobile/util/initFramework.ts
+++ b/app/src/mobile/util/initFramework.ts
@@ -21,8 +21,6 @@ import {syncGuide} from "../../sync/syncGuide";
import {Inbox} from "../../layout/dock/Inbox";
import type {App} from "../../index";
import {checkFold} from "../../util/noRelyPCFunction";
-import {Menu} from "../../plugin/Menu";
-import {showMessage} from "../../dialog/message";
import {setTitle} from "../../util/processTitle";
import {activateQueuedAVLocate, queueAVLocateRequest} from "../../protyle/render/av/locate";
import {MobileTabs} from "../tabs/MobileTabs";
@@ -32,24 +30,123 @@ import {openDock} from "../dock/util";
import {
MOBILE_SIDE_PANEL_CONFIG_CHANGE_EVENT,
type IMobileSidePanelConfig,
- type MobileSidePanelDockId,
} from "./mobileSidePanelConfig";
import {getMobileSidePanelConfig} from "./mobileSidePanelSetting";
-import {getMobilePluginDock, openMobilePluginDock} from "../dock/pluginDockState";
-const getDockTabElement = (type: MobileSidePanelDockId) => {
- return document.querySelector(`[data-type="sidebar-${type}-tab"]`) as HTMLElement;
+import {
+ getMobilePluginDock,
+ getMobilePluginDockSide,
+ MOBILE_PLUGIN_DOCKS_CHANGE_EVENT,
+ openMobilePluginDock,
+ removeMobilePluginDock,
+} from "../dock/pluginDockState";
+import type {MobileCustom} from "../dock/MobileCustom";
+
+const getDockTabElement = (type: string) => {
+ return document.querySelector(`[data-type="${CSS.escape(`sidebar-${type}-tab`)}"]`) as HTMLElement;
+};
+
+const getDockContentElement = (type: string) => {
+ return document.querySelector(`[data-type="${CSS.escape(`sidebar-${type}`)}"]`) as HTMLElement;
};
-const getDockContentElement = (type: MobileSidePanelDockId) => {
- return document.querySelector(`[data-type="sidebar-${type}"]`) as HTMLElement;
+const getDockIdFromTabElement = (element: HTMLElement) => {
+ return element.dataset.mobilePluginDockTab ||
+ element.getAttribute("data-type")?.replace(/^sidebar-/, "").replace(/-tab$/, "");
};
const getActiveDockId = (sidePanelElement: HTMLElement) => {
- const activeElement = sidePanelElement.firstElementChild.querySelector("[data-type$='-tab'].toolbar__icon--active");
- return activeElement?.getAttribute("data-type")?.replace("sidebar-", "").replace("-tab", "") as MobileSidePanelDockId;
+ const activeElement = sidePanelElement.firstElementChild.querySelector<HTMLElement>(
+ "[data-type$='-tab'].toolbar__icon--active");
+ return activeElement ? getDockIdFromTabElement(activeElement) : undefined;
};
-export const renderMobileSidePanelLayout = (config: IMobileSidePanelConfig = getMobileSidePanelConfig()) => {
+const getMobilePluginDockEntries = (app: App) => {
+ const entries: Array<{
+ type: string,
+ config: IPluginDockTab,
+ mobileModel: (element: Element) => MobileCustom,
+ order: number,
+ }> = [];
+ app.plugins.forEach((plugin) => {
+ Object.entries(plugin.docks).forEach(([type, dock]) => {
+ entries.push({
+ type,
+ config: dock.config,
+ mobileModel: dock.mobileModel,
+ order: entries.length,
+ });
+ });
+ });
+ return entries.sort((first, second) =>
+ (first.config.index ?? 1000) - (second.config.index ?? 1000) || first.order - second.order);
+};
+
+const syncMobilePluginDockElements = (
+ app: App,
+ sidePanelElements: Record<"left" | "right", HTMLElement>,
+) => {
+ const entries = getMobilePluginDockEntries(app);
+ const entryTypes = new Set(entries.map(item => item.type));
+ const tabElements = new Map<string, SVGElement>();
+ const contentElements = new Map<string, HTMLElement>();
+ document.querySelectorAll<SVGElement>("[data-mobile-plugin-dock-tab]").forEach((element) => {
+ const type = element.dataset.mobilePluginDockTab;
+ if (type) {
+ tabElements.set(type, element);
+ }
+ });
+ document.querySelectorAll<HTMLElement>("[data-mobile-plugin-dock-content]").forEach((element) => {
+ const type = element.dataset.mobilePluginDockContent;
+ if (type) {
+ contentElements.set(type, element);
+ }
+ });
+ tabElements.forEach((element, type) => {
+ if (!entryTypes.has(type)) {
+ element.remove();
+ contentElements.get(type)?.remove();
+ removeMobilePluginDock(type);
+ }
+ });
+
+ const dockIds: Record<"left" | "right", string[]> = {left: [], right: []};
+ entries.forEach((entry) => {
+ const side = getMobilePluginDockSide(entry.config.position);
+ const sidePanelElement = sidePanelElements[side];
+ const toolbarScrollElement = sidePanelElement.firstElementChild.firstElementChild;
+ const contentContainerElement = sidePanelElement.lastElementChild;
+ let tabElement = tabElements.get(entry.type);
+ if (!tabElement) {
+ tabElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
+ tabElement.classList.add("toolbar__icon");
+ tabElement.dataset.type = `sidebar-${entry.type}-tab`;
+ tabElement.dataset.mobilePluginDockTab = entry.type;
+ tabElement.append(document.createElementNS("http://www.w3.org/2000/svg", "use"));
+ }
+ tabElement.setAttribute("aria-label", entry.config.title);
+ tabElement.setAttribute("title", entry.config.title);
+ const useElement = tabElement.firstElementChild;
+ useElement.setAttribute("href", `#${entry.config.icon}`);
+ useElement.setAttribute("xlink:href", `#${entry.config.icon}`);
+ toolbarScrollElement.append(tabElement);
+
+ let contentElement = contentElements.get(entry.type);
+ if (!contentElement) {
+ contentElement = document.createElement("div");
+ contentElement.className = "fn__flex-column fn__none";
+ contentElement.dataset.type = `sidebar-${entry.type}`;
+ contentElement.dataset.mobilePluginDockContent = entry.type;
+ }
+ contentContainerElement.append(contentElement);
+ dockIds[side].push(entry.type);
+ });
+ return dockIds;
+};
+
+export const renderMobileSidePanelLayout = (
+ app: App,
+ config: IMobileSidePanelConfig = getMobileSidePanelConfig(),
+) => {
getDockTabElement("agent").classList.toggle("fn__none",
window.siyuan.config.readonly || window.siyuan.isPublish || isDisabledFeature("ai"));
const sidePanelElements = {
@@ -70,11 +167,17 @@ export const renderMobileSidePanelLayout = (config: IMobileSidePanelConfig = get
toolbarScrollElement.append(getDockTabElement(type));
contentElement.append(getDockContentElement(type));
});
+ });
+ const pluginDockIds = syncMobilePluginDockElements(app, sidePanelElements);
+
+ (["left", "right"] as const).forEach(side => {
+ const sidePanelElement = sidePanelElements[side];
+ const sideDockIds = [...config[side], ...pluginDockIds[side]];
- const visibleDockIds = config[side].filter(type => !getDockTabElement(type).classList.contains("fn__none"));
- const activeDockId = visibleDockIds.includes(previousActive[side]) ? previousActive[side] :
+ const visibleDockIds = sideDockIds.filter(type => !getDockTabElement(type).classList.contains("fn__none"));
+ const activeDockId = previousActive[side] && visibleDockIds.includes(previousActive[side]) ? previousActive[side] :
visibleDockIds.find(type => previouslyActive.has(type)) || visibleDockIds[0];
- config[side].forEach(type => {
+ sideDockIds.forEach(type => {
getDockTabElement(type).classList.toggle("toolbar__icon--active", type === activeDockId);
getDockContentElement(type).classList.toggle("fn__none", type !== activeDockId);
});
@@ -84,29 +187,7 @@ export const renderMobileSidePanelLayout = (config: IMobileSidePanelConfig = get
});
};
-const openDockMenu = (app: App, element: HTMLElement) => {
- const menu = new Menu(Constants.MENU_DOCK_MOBILE);
- if (menu.isOpen) {
- return;
- }
- app.plugins.forEach((plugin) => {
- Object.keys(plugin.docks).forEach((dockId) => {
- menu.addItem({
- label: plugin.docks[dockId].config.title,
- icon: plugin.docks[dockId].config.icon,
- click() {
- openMobilePluginDock(dockId, () => plugin.docks[dockId].mobileModel(element));
- }
- });
- });
- });
- menu.fullscreen();
- if (menu.element.lastElementChild.innerHTML === "") {
- showMessage(window.siyuan.languages._kernel[122]);
- }
-};
-
-const updateDock = (app: App, type: MobileSidePanelDockId, element: HTMLElement, openPluginMenu = false) => {
+const updateDock = (app: App, type: string, element: HTMLElement) => {
if (type === "outline") {
if (!window.siyuan.mobile.docks.outline) {
window.siyuan.mobile.docks.outline = new MobileOutline({
@@ -143,19 +224,32 @@ const updateDock = (app: App, type: MobileSidePanelDockId, element: HTMLElement,
void import("../agent/MobileAgentChat").then(({activateMobileAgent}) => {
activateMobileAgent(app, element);
});
- } else if (type === "plugin") {
- const custom = getMobilePluginDock();
- if (!custom || openPluginMenu) {
- if (!custom) {
- element.innerHTML = `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`;
- }
- openDockMenu(app, element);
- } else if (custom.update) {
+ } else {
+ const pluginDock = getMobilePluginDockEntries(app).find(item => item.type === type);
+ if (!pluginDock) {
+ return;
+ }
+ const custom = getMobilePluginDock(type);
+ if (custom?.update) {
custom.update();
+ } else if (!custom) {
+ openMobilePluginDock(type, () => pluginDock.mobileModel(element));
}
}
};
+const updateOpenSidePanelDocks = (app: App, sidePanelElements: HTMLElement[]) => {
+ sidePanelElements.forEach(sidePanelElement => {
+ if (sidePanelElement.style.transform !== "translateX(0px)") {
+ return;
+ }
+ const activeDockId = getActiveDockId(sidePanelElement);
+ if (activeDockId) {
+ updateDock(app, activeDockId, getDockContentElement(activeDockId));
+ }
+ });
+};
+
const initSidePanelTabs = (app: App, sidePanelElement: HTMLElement) => {
// 不能使用 getEventName,否则点击返回会展开右侧栏
const toolbarElement = sidePanelElement.firstElementChild as HTMLElement;
@@ -164,7 +258,7 @@ const initSidePanelTabs = (app: App, sidePanelElement: HTMLElement) => {
const isProgrammatic = typeof event.detail === "string";
let svgElement: HTMLElement;
if (isProgrammatic) {
- svgElement = toolbarElement.querySelector(`svg[data-type="sidebar-${event.detail}-tab"]`) as HTMLElement;
+ svgElement = getDockTabElement(event.detail);
} else {
svgElement = hasTopClosestByTag(target, "svg") as HTMLElement;
}
@@ -176,19 +270,23 @@ const initSidePanelTabs = (app: App, sidePanelElement: HTMLElement) => {
closePanel();
return;
}
- const type = tabType.replace("sidebar-", "").replace("-tab", "") as MobileSidePanelDockId;
+ const type = getDockIdFromTabElement(svgElement);
+ if (!type) {
+ return;
+ }
if (svgElement.classList.contains("toolbar__icon--active")) {
if (isProgrammatic) {
updateDock(app, type, getDockContentElement(type));
- } else if (type === "plugin") {
- openDockMenu(app, getDockContentElement(type));
}
return;
}
updateDock(app, type, getDockContentElement(type));
toolbarElement.querySelectorAll(".toolbar__icon[data-type]").forEach(item => {
- const itemType = item.getAttribute("data-type").replace("sidebar-", "").replace("-tab", "") as MobileSidePanelDockId;
+ const itemType = getDockIdFromTabElement(item as HTMLElement);
+ if (!itemType) {
+ return;
+ }
item.classList.toggle("toolbar__icon--active", itemType === type);
getDockContentElement(itemType).classList.toggle("fn__none", itemType !== type);
});
@@ -203,20 +301,16 @@ export const initFramework = async (app: App, isStart: boolean) => {
initMobileBars();
const sidebarElement = document.getElementById("sidebar");
const sidebarRightElement = document.getElementById("sidebarRight");
- renderMobileSidePanelLayout();
+ renderMobileSidePanelLayout(app);
initSidePanelTabs(app, sidebarElement);
initSidePanelTabs(app, sidebarRightElement);
window.addEventListener(MOBILE_SIDE_PANEL_CONFIG_CHANGE_EVENT, () => {
- renderMobileSidePanelLayout();
- [sidebarElement, sidebarRightElement].forEach(sidePanelElement => {
- if (sidePanelElement.style.transform !== "translateX(0px)") {
- return;
- }
- const activeDockId = getActiveDockId(sidePanelElement);
- if (activeDockId) {
- updateDock(app, activeDockId, getDockContentElement(activeDockId));
- }
- });
+ renderMobileSidePanelLayout(app);
+ updateOpenSidePanelDocks(app, [sidebarElement, sidebarRightElement]);
+ });
+ window.addEventListener(MOBILE_PLUGIN_DOCKS_CHANGE_EVENT, () => {
+ renderMobileSidePanelLayout(app);
+ updateOpenSidePanelDocks(app, [sidebarElement, sidebarRightElement]);
});
await snippetReady;
window.siyuan.mobile.docks.file = new MobileFiles(app, getDockContentElement("file"));
diff --git a/app/src/mobile/util/mobileBars.ts b/app/src/mobile/util/mobileBars.ts
index 89e1960bc6..8ccf6d0ab3 100644
--- a/app/src/mobile/util/mobileBars.ts
+++ b/app/src/mobile/util/mobileBars.ts
@@ -95,12 +95,13 @@ const startBarsTransition = () => {
const renderMobileBars = () => {
const visibility = getMobileBarsVisibility(barsState);
- const immersive = !visibility.readingBarsVisible && !visibility.editingBarVisible;
+ const immersive = !visibility.topbarVisible;
if (document.body.classList.contains("mobile-chrome--hidden") !== immersive) {
startBarsTransition();
}
document.body.classList.toggle("mobile-chrome--hidden", immersive);
document.body.classList.toggle("mobile-keyboard--open", visibility.editingBarVisible);
+ document.body.classList.toggle("mobile-selection--active", barsState.selecting);
const topbarElement = document.getElementById("mobileTopBar");
if (topbarElement) {
@@ -109,8 +110,8 @@ const renderMobileBars = () => {
}
const bottomBarElement = document.getElementById("mobileBottomBar");
if (bottomBarElement) {
- bottomBarElement.toggleAttribute("inert", !visibility.readingBarsVisible);
- bottomBarElement.setAttribute("aria-hidden", visibility.readingBarsVisible ? "false" : "true");
+ bottomBarElement.toggleAttribute("inert", !visibility.bottomBarVisible);
+ bottomBarElement.setAttribute("aria-hidden", visibility.bottomBarVisible ? "false" : "true");
}
};
diff --git a/app/src/mobile/util/mobileBarsState.test.ts b/app/src/mobile/util/mobileBarsState.test.ts
index 9641ba910f..0c2deb6b64 100644
--- a/app/src/mobile/util/mobileBarsState.test.ts
+++ b/app/src/mobile/util/mobileBarsState.test.ts
@@ -35,7 +35,8 @@ describe("mobile bars state", () => {
it("shows reading bars initially and supports explicit visibility changes", () => {
let state = createMobileBarsState();
assert.deepEqual(getMobileBarsVisibility(state), {
- readingBarsVisible: true,
+ topbarVisible: true,
+ bottomBarVisible: true,
editingBarVisible: false,
scrollPaused: false,
});
@@ -90,45 +91,57 @@ describe("mobile bars state", () => {
assert.equal(state.scrollDistance, 0);
});
- it("gives the editing bar priority and restores reading bars after editing", () => {
+ it("keeps the visible title state while editing", () => {
let state = createMobileBarsState(100);
state = update(state, {type: "set-editing", active: true});
assert.deepEqual(getMobileBarsVisibility(state), {
- readingBarsVisible: false,
+ topbarVisible: true,
+ bottomBarVisible: false,
editingBarVisible: true,
scrollPaused: true,
});
- state = update(state, {type: "set-reading-bars", visible: true});
state = update(state, {type: "scroll", scrollTop: 180});
- assert.equal(state.readingBarsVisible, false);
+ assert.equal(state.readingBarsVisible, true);
assert.equal(state.scrollTop, 180);
state = update(state, {type: "set-editing", active: false, scrollTop: 180});
assert.deepEqual(getMobileBarsVisibility(state), {
- readingBarsVisible: true,
+ topbarVisible: true,
+ bottomBarVisible: true,
editingBarVisible: false,
scrollPaused: false,
});
});
- it("preserves hidden reading bars when the keyboard is already closed", () => {
+ it("keeps the hidden title state while editing", () => {
let state = createMobileBarsState(100);
state = update(state, {type: "set-reading-bars", visible: false});
+ state = update(state, {type: "set-editing", active: true, scrollTop: 100});
+
+ assert.deepEqual(getMobileBarsVisibility(state), {
+ topbarVisible: false,
+ bottomBarVisible: false,
+ editingBarVisible: true,
+ scrollPaused: true,
+ });
+
state = update(state, {type: "set-editing", active: false, scrollTop: 100});
assert.deepEqual(getMobileBarsVisibility(state), {
- readingBarsVisible: false,
+ topbarVisible: false,
+ bottomBarVisible: false,
editingBarVisible: false,
scrollPaused: false,
});
});
- it("gives selection priority and restores reading bars after selection", () => {
+ it("keeps the visible title state while selecting", () => {
let state = createMobileBarsState(100);
state = update(state, {type: "set-selecting", active: true});
assert.deepEqual(getMobileBarsVisibility(state), {
- readingBarsVisible: false,
+ topbarVisible: true,
+ bottomBarVisible: false,
editingBarVisible: false,
scrollPaused: true,
});
@@ -137,7 +150,28 @@ describe("mobile bars state", () => {
assert.equal(state.scrollDistance, 0);
state = update(state, {type: "set-selecting", active: false, scrollTop: 180});
assert.deepEqual(getMobileBarsVisibility(state), {
- readingBarsVisible: true,
+ topbarVisible: true,
+ bottomBarVisible: true,
+ editingBarVisible: false,
+ scrollPaused: false,
+ });
+ });
+
+ it("keeps the hidden title state while selecting", () => {
+ let state = createMobileBarsState(100);
+ state = update(state, {type: "set-reading-bars", visible: false});
+ state = update(state, {type: "set-selecting", active: true});
+ assert.deepEqual(getMobileBarsVisibility(state), {
+ topbarVisible: false,
+ bottomBarVisible: false,
+ editingBarVisible: false,
+ scrollPaused: true,
+ });
+
+ state = update(state, {type: "set-selecting", active: false, scrollTop: 100});
+ assert.deepEqual(getMobileBarsVisibility(state), {
+ topbarVisible: false,
+ bottomBarVisible: false,
editingBarVisible: false,
scrollPaused: false,
});
@@ -146,14 +180,14 @@ describe("mobile bars state", () => {
it("preserves visible reading bars while a panel opens and closes", () => {
let state = createMobileBarsState(100);
state = update(state, {type: "set-panel-open", open: true});
- assert.equal(getMobileBarsVisibility(state).readingBarsVisible, true);
+ assert.equal(getMobileBarsVisibility(state).topbarVisible, true);
assert.equal(getMobileBarsVisibility(state).scrollPaused, true);
state = update(state, {type: "scroll", scrollTop: 200});
assert.equal(state.readingBarsVisible, true);
assert.equal(state.scrollDistance, 0);
state = update(state, {type: "set-panel-open", open: false, scrollTop: 200});
- assert.equal(getMobileBarsVisibility(state).readingBarsVisible, true);
+ assert.equal(getMobileBarsVisibility(state).topbarVisible, true);
state = update(state, {type: "scroll", scrollTop: 220});
assert.equal(state.readingBarsVisible, true);
state = update(state, {type: "scroll", scrollTop: 231});
@@ -164,11 +198,11 @@ describe("mobile bars state", () => {
let state = createMobileBarsState(100);
state = update(state, {type: "set-reading-bars", visible: false});
state = update(state, {type: "set-panel-open", open: true, scrollTop: 0});
- assert.equal(getMobileBarsVisibility(state).readingBarsVisible, false);
+ assert.equal(getMobileBarsVisibility(state).topbarVisible, false);
assert.equal(getMobileBarsVisibility(state).scrollPaused, true);
state = update(state, {type: "set-panel-open", open: false, scrollTop: 0});
- assert.equal(getMobileBarsVisibility(state).readingBarsVisible, false);
+ assert.equal(getMobileBarsVisibility(state).topbarVisible, false);
assert.equal(getMobileBarsVisibility(state).scrollPaused, false);
});
diff --git a/app/src/mobile/util/mobileBarsState.ts b/app/src/mobile/util/mobileBarsState.ts
index 95ffef0aa5..a4ab3207ef 100644
--- a/app/src/mobile/util/mobileBarsState.ts
+++ b/app/src/mobile/util/mobileBarsState.ts
@@ -19,7 +19,8 @@ export interface IMobileBarsState {
}
export interface IMobileBarsVisibility {
- readingBarsVisible: boolean,
+ topbarVisible: boolean,
+ bottomBarVisible: boolean,
editingBarVisible: boolean,
scrollPaused: boolean,
}
@@ -97,7 +98,8 @@ export const isMobileBarsScrollPaused = (state: IMobileBarsState) => {
};
export const getMobileBarsVisibility = (state: IMobileBarsState): IMobileBarsVisibility => ({
- readingBarsVisible: state.readingBarsVisible && !state.editing && !state.selecting,
+ topbarVisible: state.readingBarsVisible,
+ bottomBarVisible: state.readingBarsVisible && !state.editing && !state.selecting,
editingBarVisible: state.editing,
scrollPaused: isMobileBarsScrollPaused(state),
});
@@ -116,14 +118,13 @@ export const reduceMobileBarsState = (
if (action.type === "set-reading-bars") {
return {
...resetScrollTracking(state),
- readingBarsVisible: state.editing ? false : action.visible,
+ readingBarsVisible: action.visible,
};
}
if (action.type === "set-editing") {
return {
...resetScrollTracking(state, action.scrollTop),
- readingBarsVisible: action.active ? false : state.editing ? true : state.readingBarsVisible,
editing: action.active,
};
}
@@ -131,7 +132,6 @@ export const reduceMobileBarsState = (
if (action.type === "set-selecting") {
return {
...resetScrollTracking(state, action.scrollTop),
- readingBarsVisible: action.active ? state.readingBarsVisible : true,
selecting: action.active,
};
}
diff --git a/app/src/mobile/util/mobileBottomBar.ts b/app/src/mobile/util/mobileBottomBar.ts
index 1ce2e3121d..f733074a15 100644
--- a/app/src/mobile/util/mobileBottomBar.ts
+++ b/app/src/mobile/util/mobileBottomBar.ts
@@ -11,6 +11,7 @@ import {openDock} from "../dock/util";
import {closePanel} from "./closePanel";
import {activeBlur} from "./keyboardToolbar";
import {isMobileBlockSelecting} from "./mobileBars";
+import {newDailyNote, newDailyNoteFromLastNotebook} from "../../util/mount";
import {
MOBILE_BOTTOM_BAR_ACTIONS,
normalizeMobileBottomBarConfig,
@@ -47,6 +48,10 @@ const getActionLabel = (action: MobileBottomBarAction) => {
return window.siyuan.languages.agentChat;
case "spacedRepetition":
return window.siyuan.languages.spaceRepetition;
+ case "dailyNote":
+ return window.siyuan.languages.dailyNote;
+ case "newDailyNote":
+ return window.siyuan.languages.fileTree11;
case "command":
return window.siyuan.languages.commandPanel;
}
@@ -57,10 +62,14 @@ const getBottomBarConfig = () => {
const unavailableActions = new Set<MobileBottomBarAction>();
if (window.siyuan.config.readonly) {
unavailableActions.add("newDoc");
+ unavailableActions.add("dailyNote");
+ unavailableActions.add("newDailyNote");
unavailableActions.add("agent");
unavailableActions.add("spacedRepetition");
} else if (window.siyuan.isPublish) {
unavailableActions.add("newDoc");
+ unavailableActions.add("dailyNote");
+ unavailableActions.add("newDailyNote");
unavailableActions.add("agent");
}
if (isDisabledFeature("ai")) {
@@ -111,8 +120,10 @@ export const renderMobileBottomBar = () => {
});
updateActionLabel(moreElement, window.siyuan.languages.more);
bottomBarElement.setAttribute("aria-label", window.siyuan.languages.mobileBottomBar);
- (document.getElementById("mobileBottomBarNewDoc") as HTMLButtonElement).disabled =
- window.siyuan.config.readonly || window.siyuan.isPublish;
+ ["mobileBottomBarNewDoc", "mobileBottomBarDailyNote", "mobileBottomBarNewDailyNote"].forEach((id) => {
+ (document.getElementById(id) as HTMLButtonElement).disabled =
+ window.siyuan.config.readonly || window.siyuan.isPublish;
+ });
};
const bindBottomBarAction = (id: string, callback: () => void) => {
@@ -193,6 +204,22 @@ export const initMobileBottomBar = (app: App) => {
openCard(app);
closePanel();
});
+ bindBottomBarAction("mobileBottomBarDailyNote", () => {
+ if (isMobileBlockSelecting()) {
+ return;
+ }
+ activeBlur();
+ newDailyNote(app);
+ closePanel();
+ });
+ bindBottomBarAction("mobileBottomBarNewDailyNote", () => {
+ if (isMobileBlockSelecting()) {
+ return;
+ }
+ activeBlur();
+ newDailyNoteFromLastNotebook(app);
+ closePanel();
+ });
bindBottomBarAction("mobileBottomBarCommand", () => {
if (isMobileBlockSelecting()) {
return;
diff --git a/app/src/mobile/util/mobileBottomBarConfig.test.ts b/app/src/mobile/util/mobileBottomBarConfig.test.ts
index 988bcfe1fe..40f75e5a02 100644
--- a/app/src/mobile/util/mobileBottomBarConfig.test.ts
+++ b/app/src/mobile/util/mobileBottomBarConfig.test.ts
@@ -55,6 +55,15 @@ describe("mobile bottom bar config", () => {
assert.deepEqual(config.actions, ["inbox", "backlink", "agent", "spacedRepetition"]);
});
+ it("supports selecting and quickly creating daily notes", () => {
+ const config = normalizeMobileBottomBarConfig({
+ version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
+ actions: ["dailyNote", "newDailyNote", "documents", "tabs"],
+ });
+
+ assert.deepEqual(config.actions, ["dailyNote", "newDailyNote", "documents", "tabs"]);
+ });
+
it("replaces a slot when selecting an unused action", () => {
const config = reduceMobileBottomBarConfig(createDefaultMobileBottomBarConfig(), {
type: "select-action",
@@ -101,4 +110,13 @@ describe("mobile bottom bar config", () => {
assert.deepEqual(config.actions, ["documents", "newDoc", "search", "tabs"]);
});
+
+ it("replaces daily note actions when document creation is unavailable", () => {
+ const config = resolveMobileBottomBarAvailability({
+ version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
+ actions: ["dailyNote", "newDailyNote", "documents", "tabs"],
+ }, ["dailyNote", "newDailyNote"]);
+
+ assert.deepEqual(config.actions, ["search", "newDoc", "documents", "tabs"]);
+ });
});
diff --git a/app/src/mobile/util/mobileBottomBarConfig.ts b/app/src/mobile/util/mobileBottomBarConfig.ts
index d3ccb6d992..c4dfeecab6 100644
--- a/app/src/mobile/util/mobileBottomBarConfig.ts
+++ b/app/src/mobile/util/mobileBottomBarConfig.ts
@@ -13,6 +13,8 @@ export const MOBILE_BOTTOM_BAR_ACTIONS = [
"inbox",
"agent",
"spacedRepetition",
+ "dailyNote",
+ "newDailyNote",
"command",
] as const;
diff --git a/app/src/mobile/util/mobileSidePanelConfig.test.ts b/app/src/mobile/util/mobileSidePanelConfig.test.ts
index 18a0e516c5..feb6a61a75 100644
--- a/app/src/mobile/util/mobileSidePanelConfig.test.ts
+++ b/app/src/mobile/util/mobileSidePanelConfig.test.ts
@@ -27,7 +27,7 @@ describe("mobile side panel config", () => {
false,
"not json",
[],
- {version: 2, left: ["file"], right: ["outline"]},
+ {version: 3, left: ["file"], right: ["outline"]},
{version: MOBILE_SIDE_PANEL_CONFIG_VERSION, left: "file", right: ["outline"]},
{version: MOBILE_SIDE_PANEL_CONFIG_VERSION, left: ["file"], right: null},
].forEach((storedValue) => {
@@ -41,23 +41,23 @@ describe("mobile side panel config", () => {
it("accepts a serialized config and preserves the configured order", () => {
const config = normalizeMobileSidePanelConfig(JSON.stringify({
version: MOBILE_SIDE_PANEL_CONFIG_VERSION,
- left: ["plugin", "file", "tag"],
+ left: ["file", "tag"],
right: ["backlink", "outline", "bookmark", "inbox"],
}));
- assert.deepEqual(config.left, ["plugin", "file", "tag"]);
+ assert.deepEqual(config.left, ["file", "tag"]);
assert.deepEqual(config.right, ["backlink", "outline", "bookmark", "inbox", "agent"]);
assertCompleteConfig(config);
});
- it("adds the Agent dock to legacy version 1 layouts", () => {
+ it("removes the combined plugin dock and adds the Agent when migrating version 1 layouts", () => {
const config = normalizeMobileSidePanelConfig({
- version: MOBILE_SIDE_PANEL_CONFIG_VERSION,
+ version: 1,
left: ["file", "bookmark", "tag", "inbox", "plugin"],
right: ["backlink", "outline"],
});
- assert.deepEqual(config.left, ["file", "bookmark", "tag", "inbox", "plugin"]);
+ assert.deepEqual(config.left, ["file", "bookmark", "tag", "inbox"]);
assert.deepEqual(config.right, ["backlink", "outline", "agent"]);
assertCompleteConfig(config);
});
@@ -69,7 +69,7 @@ describe("mobile side panel config", () => {
right: ["outline", "file", "unknown"],
});
- assert.deepEqual(config.left, ["tag", "outline", "bookmark", "inbox", "plugin"]);
+ assert.deepEqual(config.left, ["tag", "outline", "bookmark", "inbox"]);
assert.deepEqual(config.right, ["file", "backlink", "agent"]);
assertCompleteConfig(config);
});
@@ -82,7 +82,7 @@ describe("mobile side panel config", () => {
});
assert.deepEqual(config.left, ["file"]);
- assert.deepEqual(config.right, ["outline", "bookmark", "tag", "backlink", "inbox", "agent", "plugin"]);
+ assert.deepEqual(config.right, ["outline", "bookmark", "tag", "backlink", "inbox", "agent"]);
assertCompleteConfig(config);
});
@@ -93,7 +93,7 @@ describe("mobile side panel config", () => {
right: [],
});
- assert.deepEqual(config.left, ["file", "bookmark", "tag", "backlink", "inbox", "agent", "plugin"]);
+ assert.deepEqual(config.left, ["file", "bookmark", "tag", "backlink", "inbox", "agent"]);
assert.deepEqual(config.right, ["outline"]);
assertCompleteConfig(config);
});
@@ -106,7 +106,7 @@ describe("mobile side panel config", () => {
index: 1,
});
- assert.deepEqual(config.left, ["file", "tag", "inbox", "plugin"]);
+ assert.deepEqual(config.left, ["file", "tag", "inbox"]);
assert.deepEqual(config.right, ["outline", "bookmark", "backlink", "agent"]);
assertCompleteConfig(config);
});
@@ -115,7 +115,7 @@ describe("mobile side panel config", () => {
const state = normalizeMobileSidePanelConfig({
version: MOBILE_SIDE_PANEL_CONFIG_VERSION,
left: ["file"],
- right: ["outline", "bookmark", "tag", "backlink", "inbox", "agent", "plugin"],
+ right: ["outline", "bookmark", "tag", "backlink", "inbox", "agent"],
});
const config = reduceMobileSidePanelConfig(state, {
type: "move",
@@ -131,11 +131,11 @@ describe("mobile side panel config", () => {
const config = reduceMobileSidePanelConfig(createDefaultMobileSidePanelConfig(), {
type: "reorder",
side: "left",
- fromIndex: 4,
+ fromIndex: 3,
toIndex: 1,
});
- assert.deepEqual(config.left, ["file", "plugin", "bookmark", "tag", "inbox"]);
+ assert.deepEqual(config.left, ["file", "inbox", "bookmark", "tag"]);
assert.deepEqual(config.right, DEFAULT_MOBILE_SIDE_PANEL_RIGHT);
assertCompleteConfig(config);
});
@@ -156,7 +156,7 @@ describe("mobile side panel config", () => {
it("resets customized panels to a fresh default config", () => {
const customized = normalizeMobileSidePanelConfig({
version: MOBILE_SIDE_PANEL_CONFIG_VERSION,
- left: ["plugin", "file", "outline"],
+ left: ["file", "outline"],
right: ["backlink", "bookmark", "tag", "inbox"],
});
const config = reduceMobileSidePanelConfig(customized, {type: "reset"});
diff --git a/app/src/mobile/util/mobileSidePanelConfig.ts b/app/src/mobile/util/mobileSidePanelConfig.ts
index 68c06573c4..1d89c49731 100644
--- a/app/src/mobile/util/mobileSidePanelConfig.ts
+++ b/app/src/mobile/util/mobileSidePanelConfig.ts
@@ -1,4 +1,4 @@
-export const MOBILE_SIDE_PANEL_CONFIG_VERSION = 1 as const;
+export const MOBILE_SIDE_PANEL_CONFIG_VERSION = 2 as const;
export const MOBILE_SIDE_PANEL_CONFIG_CHANGE_EVENT = "siyuan-mobile-side-panel-config-change";
export const MOBILE_SIDE_PANEL_DOCK_IDS = [
@@ -9,7 +9,6 @@ export const MOBILE_SIDE_PANEL_DOCK_IDS = [
"backlink",
"inbox",
"agent",
- "plugin",
] as const;
export type MobileSidePanelDockId = typeof MOBILE_SIDE_PANEL_DOCK_IDS[number];
@@ -40,7 +39,6 @@ export const DEFAULT_MOBILE_SIDE_PANEL_LEFT: readonly MobileSidePanelDockId[] =
"bookmark",
"tag",
"inbox",
- "plugin",
];
export const DEFAULT_MOBILE_SIDE_PANEL_RIGHT: readonly MobileSidePanelDockId[] = [
@@ -108,7 +106,7 @@ export const normalizeMobileSidePanelConfig = (storedValue: unknown): IMobileSid
}
const record = value as Record<string, unknown>;
- if (record.version !== MOBILE_SIDE_PANEL_CONFIG_VERSION ||
+ if ((record.version !== 1 && record.version !== MOBILE_SIDE_PANEL_CONFIG_VERSION) ||
!Array.isArray(record.left) || !Array.isArray(record.right)) {
return createDefaultMobileSidePanelConfig();
}
diff --git a/app/src/mobile/util/mobileSidePanelSetting.ts b/app/src/mobile/util/mobileSidePanelSetting.ts
index a8a5647d59..ee416fb47f 100644
--- a/app/src/mobile/util/mobileSidePanelSetting.ts
+++ b/app/src/mobile/util/mobileSidePanelSetting.ts
@@ -26,8 +26,6 @@ const getDockLabel = (dockId: MobileSidePanelDockId) => {
return window.siyuan.languages.inbox;
case "agent":
return window.siyuan.languages.agentChat;
- case "plugin":
- return window.siyuan.languages.plugin;
}
};
@@ -47,8 +45,6 @@ const getDockIcon = (dockId: MobileSidePanelDockId) => {
return "iconInbox";
case "agent":
return "iconSparkles";
- case "plugin":
- return "iconPlugin";
}
};
diff --git a/app/src/plugin/loader.ts b/app/src/plugin/loader.ts
index 781ea68e5e..38c2632cb5 100644
--- a/app/src/plugin/loader.ts
+++ b/app/src/plugin/loader.ts
@@ -5,7 +5,10 @@ import {Plugin} from "./index";
import {resizeTopBar, saveLayout} from "../layout/util";
import {getDockByType} from "../layout/tabUtil";
/// #else
-import {removeMobilePluginDock} from "../mobile/dock/pluginDockState";
+import {
+ dispatchMobilePluginDocksChange,
+ removeMobilePluginDock,
+} from "../mobile/dock/pluginDockState";
/// #endif
import {API} from "./API";
import {getFrontend, isMobile, isWindow} from "../util/functions";
@@ -221,9 +224,7 @@ export const removePluginDock = (plugin: Plugin, id: string) => {
refreshDockCatalog(plugins);
applyDockEntryVisibility();
/// #if MOBILE
- if (plugins.every((item) => Object.keys(item.docks).length === 0)) {
- document.querySelector("[data-type='sidebar-plugin-tab']")?.classList.add("fn__none");
- }
+ dispatchMobilePluginDocksChange();
/// #endif
};
@@ -231,10 +232,7 @@ export const addPluginDock = (plugin: Plugin) => {
const plugins = getPluginCatalogPlugins(plugin);
refreshDockCatalog(plugins);
/// #if MOBILE
- // 移动端只有存在插件 dock 时才显示插件入口图标
- if (Object.keys(plugin.docks).length > 0) {
- document.querySelector("[data-type='sidebar-plugin-tab']")?.classList.remove("fn__none");
- }
+ dispatchMobilePluginDocksChange();
/// #else
if (isWindow() || !window.siyuan.layout.leftDock) {
return;
diff --git a/app/src/util/dailyNote.test.ts b/app/src/util/dailyNote.test.ts
new file mode 100644
index 0000000000..9712f27a51
--- /dev/null
+++ b/app/src/util/dailyNote.test.ts
@@ -0,0 +1,20 @@
+import {describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import {getLastDailyNoteNotebookId} from "./dailyNote";
+
+describe("daily note notebook selection", () => {
+ const notebooks = [
+ {id: "open", closed: false},
+ {id: "closed", closed: true},
+ ];
+
+ it("reuses the last open notebook", () => {
+ assert.equal(getLastDailyNoteNotebookId(notebooks, "open"), "open");
+ });
+
+ it("falls back when the notebook is missing or closed", () => {
+ assert.equal(getLastDailyNoteNotebookId(notebooks, "closed"), undefined);
+ assert.equal(getLastDailyNoteNotebookId(notebooks, "missing"), undefined);
+ assert.equal(getLastDailyNoteNotebookId(notebooks, undefined), undefined);
+ });
+});
diff --git a/app/src/util/dailyNote.ts b/app/src/util/dailyNote.ts
new file mode 100644
index 0000000000..90f6e921e4
--- /dev/null
+++ b/app/src/util/dailyNote.ts
@@ -0,0 +1,9 @@
+export const getLastDailyNoteNotebookId = (
+ notebooks: readonly {id: string, closed: boolean}[],
+ storedNotebookId: unknown,
+) => {
+ if (typeof storedNotebookId !== "string" || !storedNotebookId) {
+ return undefined;
+ }
+ return notebooks.some(item => item.id === storedNotebookId && !item.closed) ? storedNotebookId : undefined;
+};
diff --git a/app/src/util/mount.ts b/app/src/util/mount.ts
index 16c1256b62..49e69b5a48 100644
--- a/app/src/util/mount.ts
+++ b/app/src/util/mount.ts
@@ -10,6 +10,7 @@ import {setStorageVal} from "../protyle/util/compatibility";
import {openFileById} from "../editor/util";
import {openMobileFileById} from "../mobile/editor";
import type {App} from "../index";
+import {getLastDailyNoteNotebookId} from "./dailyNote";
/// #if !BROWSER
import {ipcRenderer} from "electron";
import {importObsidianVault} from "../menus/importObsidian";
@@ -29,7 +30,7 @@ export const fetchNewDailyNote = (app: App, notebook: string) => {
});
};
-export const newDailyNote = (app: App) => {
+const openDailyNote = (app: App, useLastNotebook: boolean) => {
const exit = window.siyuan.dialogs.find(item => {
if (item.element.getAttribute("data-key") === Constants.DIALOG_DIALYNOTE) {
item.destroy();
@@ -55,13 +56,9 @@ export const newDailyNote = (app: App) => {
return;
}
const localNotebookId = window.siyuan.storage[Constants.LOCAL_DAILYNOTEID];
- const localNotebookIsOpen = window.siyuan.notebooks.find((item) => {
- if (item.id === localNotebookId && !item.closed) {
- return true;
- }
- });
- if (localNotebookId && localNotebookIsOpen && !isMobile()) {
- fetchNewDailyNote(app, localNotebookId);
+ const lastNotebookId = getLastDailyNoteNotebookId(window.siyuan.notebooks, localNotebookId);
+ if (lastNotebookId && useLastNotebook) {
+ fetchNewDailyNote(app, lastNotebookId);
} else {
let optionsHTML = "";
window.siyuan.notebooks.forEach(item => {
@@ -98,6 +95,14 @@ export const newDailyNote = (app: App) => {
}
};
+export const newDailyNote = (app: App) => {
+ openDailyNote(app, !isMobile());
+};
+
+export const newDailyNoteFromLastNotebook = (app: App) => {
+ openDailyNote(app, true);
+};
+
export const mountHelp = () => {
const notebookId = Constants.HELP_PATH[window.siyuan.config.appearance.lang];
fetchPost("/api/notebook/removeNotebook", {notebook: notebookId}, () => {