Skip to content

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

:sparkles: Support plugin docks in mobile navigation https://github.com/siyuan-note/siyuan/issues/14542

Daniel200d477838b8
diff --git a/app/src/config/entryVisibility/catalog.ts b/app/src/config/entryVisibility/catalog.ts
index 8ede964b01..ad11370a43 100644
--- a/app/src/config/entryVisibility/catalog.ts
+++ b/app/src/config/entryVisibility/catalog.ts
@@ -6,6 +6,9 @@ import {
TOOLBAR_ENTRY_ROOT_PATH,
} from "../../protyle/toolbar/defaults";
import {mergeEntryOrderPreservingUnknown} from "./order";
+import {getPluginDockEntryKey} from "../../plugin/dockKey";
+
+export {getPluginDockEntryKey} from "../../plugin/dockKey";
export interface IEntryCatalogNode {
key: string;
@@ -986,11 +989,6 @@ interface IDockCatalogPlugin {
}>;
}
-const encodeDockEntryKeyPart = (value: string) => encodeURIComponent(value).replace(/\./g, "%2E");
-
-export const getPluginDockEntryKey = (pluginName: string, dockID: string) =>
- `plugin:${encodeDockEntryKeyPart(pluginName)}:${encodeDockEntryKeyPart(dockID)}`;
-
let dockCatalogSignature = "[]";
export const refreshDockCatalog = (plugins: IDockCatalogPlugin[]) => {
diff --git a/app/src/mobile/dock/pluginDockState.test.ts b/app/src/mobile/dock/pluginDockState.test.ts
index cb0165d0f8..0d5837e22e 100644
--- a/app/src/mobile/dock/pluginDockState.test.ts
+++ b/app/src/mobile/dock/pluginDockState.test.ts
@@ -23,12 +23,16 @@ describe("mobile plugin dock state", () => {
const mobileModel = () => ({}) as never;
const app = {
plugins: [{
+ name: "sample-plugin",
+ displayName: "Sample plugin",
docks: {
pluginSecond: {
+ id: "second",
config: {position: "BottomRight", index: 20, title: "Second", icon: "iconSecond"},
mobileModel,
},
pluginFirst: {
+ id: "first",
config: {position: "LeftBottom", index: 10, title: "First", icon: "iconFirst"},
mobileModel,
},
@@ -38,6 +42,22 @@ describe("mobile plugin dock state", () => {
const entries = getMobilePluginDockEntries(app as never);
assert.deepEqual(entries.map(entry => entry.type), ["pluginFirst", "pluginSecond"]);
+ assert.deepEqual(entries.map(entry => ({
+ key: entry.key,
+ dockID: entry.dockID,
+ pluginName: entry.pluginName,
+ pluginDisplayName: entry.pluginDisplayName,
+ })), [{
+ key: "plugin:sample-plugin:first",
+ dockID: "first",
+ pluginName: "sample-plugin",
+ pluginDisplayName: "Sample plugin",
+ }, {
+ key: "plugin:sample-plugin:second",
+ dockID: "second",
+ pluginName: "sample-plugin",
+ pluginDisplayName: "Sample plugin",
+ }]);
assert.deepEqual(getMobilePluginDockLayouts(entries), [
{id: "pluginFirst", side: "left", index: 10},
{id: "pluginSecond", side: "right", index: 20},
diff --git a/app/src/mobile/dock/pluginDockState.ts b/app/src/mobile/dock/pluginDockState.ts
index f4f17cbff7..71cf75bdeb 100644
--- a/app/src/mobile/dock/pluginDockState.ts
+++ b/app/src/mobile/dock/pluginDockState.ts
@@ -1,6 +1,7 @@
import {MobileCustom} from "./MobileCustom";
import type {App} from "../../index";
import type {IMobileSidePanelPluginDock} from "../util/mobileSidePanelConfig";
+import {getPluginDockEntryKey, type PluginDockEntryKey} from "../../plugin/dockKey";
export const MOBILE_PLUGIN_DOCKS_CHANGE_EVENT = "siyuan-mobile-plugin-docks-change";
@@ -11,6 +12,10 @@ export const getMobilePluginDockSide = (position: TPluginDockPosition) => {
};
export interface IMobilePluginDockEntry {
+ key: PluginDockEntryKey,
+ dockID: string,
+ pluginName: string,
+ pluginDisplayName: string,
type: string,
config: IPluginDockTab,
mobileModel: (element: Element) => MobileCustom,
@@ -22,6 +27,10 @@ export const getMobilePluginDockEntries = (app: App = window.siyuan.ws.app) => {
app.plugins.forEach((plugin) => {
Object.entries(plugin.docks).forEach(([type, dock]) => {
entries.push({
+ key: getPluginDockEntryKey(plugin.name, dock.id),
+ dockID: dock.id,
+ pluginName: plugin.name,
+ pluginDisplayName: plugin.displayName?.trim() || plugin.name,
type,
config: dock.config,
mobileModel: dock.mobileModel,
diff --git a/app/src/mobile/menu/index.ts b/app/src/mobile/menu/index.ts
index 34af017804..5ebc7d39df 100644
--- a/app/src/mobile/menu/index.ts
+++ b/app/src/mobile/menu/index.ts
@@ -27,6 +27,8 @@ import {clearSyncTabElement} from "../../config/tabs/syncRuntime";
import {clearAccessTabElement} from "../../config/tabs/accessRuntime";
import {isMobileMenuSearchMatch} from "./searchFilter";
import {unmountAssetsTab} from "../../config/assets";
+import {escapeAttr, escapeHtml} from "../../util/escape";
+import {getMobilePluginDockEntries, MOBILE_PLUGIN_DOCKS_CHANGE_EVENT} from "../dock/pluginDockState";
const getSettingTabFromMenuTarget = (target: HTMLElement): ISettingTabShell<TSettingTab> | undefined => {
const item = target.closest(".b3-menu__item") as HTMLElement | null;
@@ -342,6 +344,20 @@ export const popMenu = () => {
menuElement.style.transform = "translateX(0px)";
};
+const renderMobilePluginDockMenu = (app: App, menuElement: HTMLElement) => {
+ menuElement.querySelectorAll('[data-type="mobile-plugin-dock"]').forEach(item => item.remove());
+ const markerElement = menuElement.querySelector("#menuPluginDocks");
+ if (!markerElement) {
+ return;
+ }
+ const html = getMobilePluginDockEntries(app).map((entry) =>
+ `<div class="b3-menu__item" data-type="mobile-plugin-dock" data-plugin-dock-key="${escapeAttr(entry.key)}">
+ <svg class="b3-menu__icon"><use xlink:href="#${escapeAttr(entry.config.icon)}"></use></svg>
+ <span class="b3-menu__label">${escapeHtml(`${entry.pluginDisplayName} - ${entry.config.title}`)}</span>
+ </div>`).join("");
+ markerElement.insertAdjacentHTML("beforebegin", html);
+};
+
export const initRightMenu = (app: App) => {
const menuElement = document.getElementById("menu");
menuElement.innerHTML = `<div class="b3-menu__title">
@@ -439,6 +455,7 @@ export const initRightMenu = (app: App) => {
<svg class="b3-menu__icon"><use xlink:href="#iconPlugin"></use></svg><span class="b3-menu__label">${window.siyuan.languages.plugin}</span>
</div>
<div id="menuPluginTopBar" class="fn__none"></div>
+ <div id="menuPluginDocks" class="fn__none"></div>
</div>
</div>
<div class="b3-menu__group">
@@ -457,6 +474,10 @@ export const initRightMenu = (app: App) => {
<div class="b3-list--empty fn__none" data-type="menu-search-empty">${window.siyuan.languages.emptyContent}</div>
${getSettingTabResultsHTML()}
</div>`;
+ renderMobilePluginDockMenu(app, menuElement);
+ window.addEventListener(MOBILE_PLUGIN_DOCKS_CHANGE_EVENT, () => {
+ renderMobilePluginDockMenu(app, menuElement);
+ });
const searchElement = menuElement.querySelector(".mobile-main-menu__search input") as HTMLInputElement;
const groupsElement = menuElement.querySelector(".mobile-main-menu__groups") as HTMLElement;
const searchMountQueue = createSettingSearchMountQueue(app);
@@ -661,6 +682,16 @@ export const initRightMenu = (app: App) => {
event.stopPropagation();
exitSiYuan();
break;
+ } else if (target.dataset.type === "mobile-plugin-dock") {
+ const pluginDockEntry = getMobilePluginDockEntries(app)
+ .find(entry => entry.key === target.dataset.pluginDockKey);
+ closePanel();
+ if (pluginDockEntry) {
+ openDock(pluginDockEntry.type);
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ break;
} else if (target.id === "menuPlugin") {
openTopBarMenu(app);
event.preventDefault();
diff --git a/app/src/mobile/util/mobileBottomBar.ts b/app/src/mobile/util/mobileBottomBar.ts
index ef510d50d2..3179ea9569 100644
--- a/app/src/mobile/util/mobileBottomBar.ts
+++ b/app/src/mobile/util/mobileBottomBar.ts
@@ -13,16 +13,26 @@ import {activeBlur} from "./keyboardToolbar";
import {isMobileBlockSelecting} from "./mobileBars";
import {newDailyNote, newDailyNoteFromLastNotebook} from "../../util/mount";
import {
+ getMobilePluginDockEntries,
+ MOBILE_PLUGIN_DOCKS_CHANGE_EVENT,
+ type IMobilePluginDockEntry,
+} from "../dock/pluginDockState";
+import {
+ isMobileBottomBarAction,
+ isMobileBottomBarBuiltInAction,
MOBILE_BOTTOM_BAR_ACTIONS,
normalizeMobileBottomBarConfig,
reduceMobileBottomBarConfig,
resolveMobileBottomBarAvailability,
type IMobileBottomBarConfig,
type MobileBottomBarAction,
+ type MobileBottomBarBuiltInAction,
type MobileBottomBarSlot,
} from "./mobileBottomBarConfig";
-const getActionLabel = (action: MobileBottomBarAction) => {
+let bottomBarSettingPluginDocksChangeHandler: (() => void) | undefined;
+
+const getActionLabel = (action: MobileBottomBarBuiltInAction) => {
switch (action) {
case "back":
return window.siyuan.languages.goBack;
@@ -61,8 +71,16 @@ const getActionLabel = (action: MobileBottomBarAction) => {
}
};
-const getBottomBarConfig = () => {
- const config = normalizeMobileBottomBarConfig(window.siyuan.storage[Constants.LOCAL_MOBILE_BOTTOM_BAR]);
+const getPluginDockLabel = (entry: IMobilePluginDockEntry) =>
+ `${entry.pluginDisplayName} - ${entry.config.title}`;
+
+const getStoredBottomBarConfig = () =>
+ normalizeMobileBottomBarConfig(window.siyuan.storage[Constants.LOCAL_MOBILE_BOTTOM_BAR]);
+
+const resolveBottomBarConfig = (
+ config: IMobileBottomBarConfig,
+ pluginDockEntries: readonly IMobilePluginDockEntry[],
+) => {
const unavailableActions = new Set<MobileBottomBarAction>();
if (window.siyuan.config.readonly) {
unavailableActions.add("newDoc");
@@ -79,6 +97,12 @@ const getBottomBarConfig = () => {
if (isDisabledFeature("ai")) {
unavailableActions.add("agent");
}
+ const pluginDockKeys = new Set(pluginDockEntries.map(entry => entry.key));
+ config.actions.forEach((action) => {
+ if (!isMobileBottomBarBuiltInAction(action) && !pluginDockKeys.has(action)) {
+ unavailableActions.add(action);
+ }
+ });
if (unavailableActions.size === 0) {
return config;
}
@@ -103,7 +127,10 @@ export const renderMobileBottomBar = () => {
return;
}
- const config = getBottomBarConfig();
+ const pluginDockEntries = getMobilePluginDockEntries();
+ const pluginDockEntriesByKey = new Map(pluginDockEntries.map(entry => [entry.key, entry]));
+ const config = resolveBottomBarConfig(getStoredBottomBarConfig(), pluginDockEntries);
+ bottomBarElement.querySelectorAll("[data-mobile-plugin-dock]").forEach(item => item.remove());
MOBILE_BOTTOM_BAR_ACTIONS.forEach((action) => {
const element = bottomBarElement.querySelector<HTMLElement>(`[data-action="${action}"]`);
if (!element) {
@@ -114,11 +141,26 @@ export const renderMobileBottomBar = () => {
updateActionLabel(element, getActionLabel(action));
});
config.actions.forEach((action, slot) => {
- const element = bottomBarElement.querySelector<HTMLElement>(`[data-action="${action}"]`);
+ let element: HTMLElement | null;
+ if (isMobileBottomBarBuiltInAction(action)) {
+ element = bottomBarElement.querySelector<HTMLElement>(`[data-action="${action}"]`);
+ element?.classList.remove("fn__none");
+ } else {
+ const pluginDockEntry = pluginDockEntriesByKey.get(action);
+ if (!pluginDockEntry) {
+ return;
+ }
+ element = document.createElement("button");
+ element.className = "mobile-bottom-bar__item";
+ element.setAttribute("type", "button");
+ element.dataset.action = action;
+ element.dataset.mobilePluginDock = pluginDockEntry.type;
+ element.innerHTML = `<svg><use xlink:href="#${escapeAttr(pluginDockEntry.config.icon)}"></use></svg>`;
+ updateActionLabel(element, getPluginDockLabel(pluginDockEntry));
+ }
if (!element) {
return;
}
- element.classList.remove("fn__none");
element.dataset.slot = slot.toString();
bottomBarElement.insertBefore(element, moreElement);
});
@@ -146,6 +188,21 @@ export const initMobileBottomBar = (app: App) => {
}
bottomBarElement.classList.remove("fn__none");
bottomBarElement.dataset.bound = "true";
+ window.addEventListener(MOBILE_PLUGIN_DOCKS_CHANGE_EVENT, renderMobileBottomBar);
+ bottomBarElement.addEventListener("click", (event) => {
+ const target = event.target;
+ if (!(target instanceof Element)) {
+ return;
+ }
+ const pluginDockElement = target.closest<HTMLElement>("[data-mobile-plugin-dock]");
+ if (!pluginDockElement || !bottomBarElement.contains(pluginDockElement) || isMobileBlockSelecting()) {
+ return;
+ }
+ const type = pluginDockElement.dataset.mobilePluginDock;
+ if (type) {
+ openDock(type);
+ }
+ });
bindBottomBarAction("mobileBottomBarBack", () => {
if (isMobileBlockSelecting()) {
return;
@@ -248,16 +305,20 @@ export const initMobileBottomBar = (app: App) => {
});
};
-const genBottomBarOptions = () => MOBILE_BOTTOM_BAR_ACTIONS.map((action) =>
- `<option value="${action}"${action === "agent" && isDisabledFeature("ai") ? " disabled" : ""}>${escapeHtml(getActionLabel(action))}</option>`
-).join("");
+const genBottomBarOptions = (pluginDockEntries: readonly IMobilePluginDockEntry[]) => [
+ ...MOBILE_BOTTOM_BAR_ACTIONS.map((action) =>
+ `<option value="${action}"${action === "agent" && isDisabledFeature("ai") ? " disabled" : ""}>${escapeHtml(getActionLabel(action))}</option>`),
+ ...pluginDockEntries.map((entry) =>
+ `<option value="${escapeAttr(entry.key)}">${escapeHtml(getPluginDockLabel(entry))}</option>`),
+].join("");
export const genMobileBottomBarSettingHTML = () => {
const title = window.siyuan.languages.mobileBottomBar;
const disabled = window.siyuan.config.readonly || window.siyuan.isPublish ? " disabled" : "";
+ const options = genBottomBarOptions(getMobilePluginDockEntries());
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>
+ <select class="b3-select fn__flex-1" data-bottom-bar-slot="${slot}" aria-label="${escapeAttr(`${title} ${slot + 1}`)}"${disabled}>${options}</select>
</label>`).join("");
return `<div id="mobileBottomBarSetting" class="b3-label config-item mobile-bottom-bar-setting">
<div class="fn__flex">
@@ -275,11 +336,17 @@ export const mountMobileBottomBarSetting = (root: HTMLElement) => {
if (!settingElement) {
return;
}
- let config = getBottomBarConfig();
- const syncSelects = () => {
+ let config = getStoredBottomBarConfig();
+ let pluginDockEntries = getMobilePluginDockEntries();
+ const syncSelects = (refreshOptions = false) => {
+ const resolvedConfig = resolveBottomBarConfig(config, pluginDockEntries);
+ const options = refreshOptions ? genBottomBarOptions(pluginDockEntries) : "";
settingElement.querySelectorAll<HTMLSelectElement>("[data-bottom-bar-slot]").forEach((selectElement) => {
const slot = Number(selectElement.dataset.bottomBarSlot) as MobileBottomBarSlot;
- selectElement.value = config.actions[slot];
+ if (refreshOptions) {
+ selectElement.innerHTML = options;
+ }
+ selectElement.value = resolvedConfig.actions[slot];
});
};
settingElement.addEventListener("change", (event) => {
@@ -288,8 +355,10 @@ export const mountMobileBottomBarSetting = (root: HTMLElement) => {
return;
}
const slot = Number(selectElement.dataset.bottomBarSlot);
- const action = selectElement.value as MobileBottomBarAction;
- if (![0, 1, 2, 3, 4].includes(slot) || !MOBILE_BOTTOM_BAR_ACTIONS.includes(action)) {
+ const action = selectElement.value;
+ const pluginDockKeys = new Set(pluginDockEntries.map(entry => entry.key));
+ if (![0, 1, 2, 3, 4].includes(slot) || !isMobileBottomBarAction(action) ||
+ (!isMobileBottomBarBuiltInAction(action) && !pluginDockKeys.has(action))) {
syncSelects();
return;
}
@@ -306,5 +375,21 @@ export const mountMobileBottomBarSetting = (root: HTMLElement) => {
setBottomBarConfig(config);
syncSelects();
});
+ const onPluginDocksChange = () => {
+ if (!settingElement.isConnected) {
+ window.removeEventListener(MOBILE_PLUGIN_DOCKS_CHANGE_EVENT, onPluginDocksChange);
+ if (bottomBarSettingPluginDocksChangeHandler === onPluginDocksChange) {
+ bottomBarSettingPluginDocksChangeHandler = undefined;
+ }
+ return;
+ }
+ pluginDockEntries = getMobilePluginDockEntries();
+ syncSelects(true);
+ };
+ if (bottomBarSettingPluginDocksChangeHandler) {
+ window.removeEventListener(MOBILE_PLUGIN_DOCKS_CHANGE_EVENT, bottomBarSettingPluginDocksChangeHandler);
+ }
+ bottomBarSettingPluginDocksChangeHandler = onPluginDocksChange;
+ window.addEventListener(MOBILE_PLUGIN_DOCKS_CHANGE_EVENT, onPluginDocksChange);
syncSelects();
};
diff --git a/app/src/mobile/util/mobileBottomBarConfig.test.ts b/app/src/mobile/util/mobileBottomBarConfig.test.ts
index 67cc9683d2..975eaac291 100644
--- a/app/src/mobile/util/mobileBottomBarConfig.test.ts
+++ b/app/src/mobile/util/mobileBottomBarConfig.test.ts
@@ -3,12 +3,13 @@ import * as assert from "node:assert/strict";
import {
createDefaultMobileBottomBarConfig,
DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS,
- MOBILE_BOTTOM_BAR_ACTIONS,
+ isMobileBottomBarBuiltInAction,
MOBILE_BOTTOM_BAR_CONFIG_VERSION,
normalizeMobileBottomBarConfig,
reduceMobileBottomBarConfig,
resolveMobileBottomBarAvailability,
} from "./mobileBottomBarConfig";
+import {getPluginDockEntryKey} from "../../plugin/dockKey";
describe("mobile bottom bar config", () => {
it("falls back to the default for malformed storage values", () => {
@@ -17,7 +18,7 @@ describe("mobile bottom bar config", () => {
false,
"not json",
[],
- {version: 3, actions: ["recent", "outline", "bookmark", "tag", "back"]},
+ {version: 4, actions: ["recent", "outline", "bookmark", "tag", "back"]},
{version: MOBILE_BOTTOM_BAR_CONFIG_VERSION, actions: "documents"},
].forEach((storedValue) => {
assert.deepEqual(normalizeMobileBottomBarConfig(storedValue), createDefaultMobileBottomBarConfig());
@@ -37,6 +38,16 @@ describe("mobile bottom bar config", () => {
assert.deepEqual(config, createDefaultMobileBottomBarConfig());
});
+ it("migrates version 2 configs without changing their slots", () => {
+ const config = normalizeMobileBottomBarConfig({
+ version: 2,
+ actions: ["recent", "outline", "bookmark", "tag", "back"],
+ });
+
+ assert.equal(config.version, MOBILE_BOTTOM_BAR_CONFIG_VERSION);
+ assert.deepEqual(config.actions, ["recent", "outline", "bookmark", "tag", "back"]);
+ });
+
it("preserves customized legacy slots and appends back", () => {
const config = normalizeMobileBottomBarConfig({
version: 1,
@@ -55,7 +66,7 @@ describe("mobile bottom bar config", () => {
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);
+ assert.equal(config.actions.every(isMobileBottomBarBuiltInAction), true);
});
it("swaps slots when selecting an action already in the bottom bar", () => {
@@ -103,7 +114,7 @@ describe("mobile bottom bar config", () => {
});
const config = reduceMobileBottomBarConfig(customized, {type: "reset"});
- assert.equal(config.version, 2);
+ assert.equal(config.version, MOBILE_BOTTOM_BAR_CONFIG_VERSION);
assert.deepEqual(config.actions, DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS);
assert.notEqual(config.actions, DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS);
});
@@ -144,4 +155,57 @@ describe("mobile bottom bar config", () => {
assert.deepEqual(config.actions, ["forward", "search", "documents", "tabs", "back"]);
});
+
+ it("accepts stable plugin dock keys and rejects malformed keys", () => {
+ const pluginAction = getPluginDockEntryKey("plugin.one", "dock.one");
+ const config = normalizeMobileBottomBarConfig({
+ version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
+ actions: [pluginAction, "plugin::dock", "plugin:name:", "plugin:name:dock:extra", "search"],
+ });
+
+ assert.deepEqual(config.actions, [pluginAction, "back", "forward", "documents", "search"]);
+ });
+
+ it("swaps stable plugin dock actions between slots", () => {
+ const pluginAction = getPluginDockEntryKey("sample-plugin", "sample-dock");
+ const state = normalizeMobileBottomBarConfig({
+ version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
+ actions: [pluginAction, "forward", "documents", "tabs", "search"],
+ });
+ const config = reduceMobileBottomBarConfig(state, {
+ type: "select-action",
+ slot: 3,
+ action: pluginAction,
+ });
+
+ assert.deepEqual(config.actions, ["tabs", "forward", "documents", pluginAction, "search"]);
+ });
+
+ it("temporarily replaces a missing plugin without changing the stored config", () => {
+ const pluginAction = getPluginDockEntryKey("sample-plugin", "sample-dock");
+ const storedConfig = normalizeMobileBottomBarConfig({
+ version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
+ actions: [pluginAction, "forward", "documents", "tabs", "search"],
+ });
+ const resolvedConfig = resolveMobileBottomBarAvailability(storedConfig, [pluginAction]);
+
+ assert.deepEqual(resolvedConfig.actions, ["back", "forward", "documents", "tabs", "search"]);
+ assert.equal(storedConfig.actions[0], pluginAction);
+ assert.deepEqual(resolveMobileBottomBarAvailability(storedConfig, []).actions, storedConfig.actions);
+ });
+
+ it("keeps a missing plugin action when another stored slot changes", () => {
+ const pluginAction = getPluginDockEntryKey("sample-plugin", "sample-dock");
+ const storedConfig = normalizeMobileBottomBarConfig({
+ version: MOBILE_BOTTOM_BAR_CONFIG_VERSION,
+ actions: [pluginAction, "forward", "documents", "tabs", "search"],
+ });
+ const config = reduceMobileBottomBarConfig(storedConfig, {
+ type: "select-action",
+ slot: 1,
+ action: "outline",
+ });
+
+ assert.deepEqual(config.actions, [pluginAction, "outline", "documents", "tabs", "search"]);
+ });
});
diff --git a/app/src/mobile/util/mobileBottomBarConfig.ts b/app/src/mobile/util/mobileBottomBarConfig.ts
index d70cc9ff5c..f067e87a00 100644
--- a/app/src/mobile/util/mobileBottomBarConfig.ts
+++ b/app/src/mobile/util/mobileBottomBarConfig.ts
@@ -1,4 +1,6 @@
-export const MOBILE_BOTTOM_BAR_CONFIG_VERSION = 2 as const;
+import {isPluginDockEntryKey, type PluginDockEntryKey} from "../../plugin/dockKey";
+
+export const MOBILE_BOTTOM_BAR_CONFIG_VERSION = 3 as const;
export const MOBILE_BOTTOM_BAR_ACTIONS = [
"back",
@@ -20,7 +22,8 @@ export const MOBILE_BOTTOM_BAR_ACTIONS = [
"command",
] as const;
-export type MobileBottomBarAction = typeof MOBILE_BOTTOM_BAR_ACTIONS[number];
+export type MobileBottomBarBuiltInAction = typeof MOBILE_BOTTOM_BAR_ACTIONS[number];
+export type MobileBottomBarAction = MobileBottomBarBuiltInAction | PluginDockEntryKey;
export type MobileBottomBarSlot = 0 | 1 | 2 | 3 | 4;
export type MobileBottomBarSlots = readonly [
MobileBottomBarAction,
@@ -43,13 +46,13 @@ export type MobileBottomBarConfigEvent = {
type: "reset",
};
-export const DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS: MobileBottomBarSlots = [
+export const DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS = [
"back",
"forward",
"documents",
"tabs",
"search",
-];
+] as const satisfies MobileBottomBarSlots;
const LEGACY_DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS = ["documents", "search", "newDoc", "tabs"];
@@ -60,10 +63,14 @@ export const DEFAULT_MOBILE_BOTTOM_BAR_CONFIG: IMobileBottomBarConfig = {
const mobileBottomBarActionSet = new Set<string>(MOBILE_BOTTOM_BAR_ACTIONS);
-export const isMobileBottomBarAction = (value: unknown): value is MobileBottomBarAction => {
+export const isMobileBottomBarBuiltInAction = (value: unknown): value is MobileBottomBarBuiltInAction => {
return typeof value === "string" && mobileBottomBarActionSet.has(value);
};
+export const isMobileBottomBarAction = (value: unknown): value is MobileBottomBarAction => {
+ return isMobileBottomBarBuiltInAction(value) || isPluginDockEntryKey(value);
+};
+
const toMobileBottomBarSlots = (actions: MobileBottomBarAction[]): MobileBottomBarSlots => {
return [actions[0], actions[1], actions[2], actions[3], actions[4]];
};
@@ -80,7 +87,7 @@ const normalizeMobileBottomBarActions = (storedActions: unknown[]): MobileBottom
}
}
- const fallbackActions: readonly MobileBottomBarAction[] = [
+ const fallbackActions: readonly MobileBottomBarBuiltInAction[] = [
...DEFAULT_MOBILE_BOTTOM_BAR_ACTIONS,
...MOBILE_BOTTOM_BAR_ACTIONS,
];
@@ -118,7 +125,8 @@ export const normalizeMobileBottomBarConfig = (storedValue: unknown): IMobileBot
}
const record = value as Record<string, unknown>;
- if ((record.version !== 1 && record.version !== MOBILE_BOTTOM_BAR_CONFIG_VERSION) || !Array.isArray(record.actions)) {
+ if ((record.version !== 1 && record.version !== 2 && 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 &&
diff --git a/app/src/plugin/dockKey.ts b/app/src/plugin/dockKey.ts
new file mode 100644
index 0000000000..8c39018ad7
--- /dev/null
+++ b/app/src/plugin/dockKey.ts
@@ -0,0 +1,9 @@
+export type PluginDockEntryKey = `plugin:${string}:${string}`;
+
+const encodeDockEntryKeyPart = (value: string) => encodeURIComponent(value).replace(/\./g, "%2E");
+
+export const getPluginDockEntryKey = (pluginName: string, dockID: string): PluginDockEntryKey =>
+ `plugin:${encodeDockEntryKeyPart(pluginName)}:${encodeDockEntryKeyPart(dockID)}`;
+
+export const isPluginDockEntryKey = (value: unknown): value is PluginDockEntryKey =>
+ typeof value === "string" && /^plugin:[^:]+:[^:]+$/.test(value);