From ebadfb968bf21399b47aec80d71736a36ded2fb5 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 20 Jun 2026 23:37:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(webui):=20replace=20=E3=80=8C=E4=BE=A7?= =?UTF-8?q?=E6=A0=8F=E9=BB=98=E8=AE=A4=E6=8A=98=E5=8F=A0=E3=80=8D=20with?= =?UTF-8?q?=20=E3=80=8C=E9=92=89=E4=BD=8F=E4=BE=A7=E6=A0=8F=E5=B1=95?= =?UTF-8?q?=E5=BC=80=E3=80=8D=20pin=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old default-collapsed pref went inert once the sidebar became a hover-expand rail with no collapse button. Repurpose it as an explicit opt-out: when 「钉住侧栏展开」 is on, the sidebar stays permanently expanded and no longer collapses to the rail or reacts to hover. Renamed the appearance field sidebarDefaultCollapsed -> sidebarPinned across the webui types/defaults/settings UI and the core ui-config interface, defaults and validator (kept in lock-step so persistence round-trips). Wired into main-layout: effectiveCollapsed = !editing && !sidebarPinned. --- packages/core/src/webui/ui-config.ts | 6 +++--- packages/webui/src/components/layout/main-layout.tsx | 7 ++++--- packages/webui/src/components/pages/settings-page.tsx | 4 ++-- packages/webui/src/contexts/ThemeContext.tsx | 2 +- packages/webui/src/types.ts | 3 ++- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/core/src/webui/ui-config.ts b/packages/core/src/webui/ui-config.ts index efd2404f..6fcf68a8 100644 --- a/packages/core/src/webui/ui-config.ts +++ b/packages/core/src/webui/ui-config.ts @@ -100,7 +100,7 @@ export interface UiAppearance { /** Hard-disable all UI animations (stronger than reduceMotion). */ disableMotion: boolean; highContrast: boolean; - sidebarDefaultCollapsed: boolean; + sidebarPinned: boolean; timeFormat: TimeFormat; /** Dashboard poll interval (ms); 0 = paused. */ pollInterval: number; @@ -226,7 +226,7 @@ const DEFAULT_APPEARANCE: UiAppearance = { reduceMotion: false, disableMotion: false, highContrast: false, - sidebarDefaultCollapsed: false, + sidebarPinned: false, timeFormat: '24h', pollInterval: 3000, customCss: '', @@ -531,7 +531,7 @@ export function normalizeAppearance(value: unknown, imageState: ServerImageState reduceMotion: boolOr(v.reduceMotion, DEFAULT_APPEARANCE.reduceMotion), disableMotion: boolOr(v.disableMotion, DEFAULT_APPEARANCE.disableMotion), highContrast: boolOr(v.highContrast, DEFAULT_APPEARANCE.highContrast), - sidebarDefaultCollapsed: boolOr(v.sidebarDefaultCollapsed, DEFAULT_APPEARANCE.sidebarDefaultCollapsed), + sidebarPinned: boolOr(v.sidebarPinned, DEFAULT_APPEARANCE.sidebarPinned), timeFormat: oneOf(v.timeFormat, ['12h', '24h'], DEFAULT_APPEARANCE.timeFormat), pollInterval: clampNum(v.pollInterval, 0, 60_000, DEFAULT_APPEARANCE.pollInterval), customCss: typeof v.customCss === 'string' ? v.customCss.slice(0, 50_000) : DEFAULT_APPEARANCE.customCss, diff --git a/packages/webui/src/components/layout/main-layout.tsx b/packages/webui/src/components/layout/main-layout.tsx index 42e5cceb..512abe9f 100644 --- a/packages/webui/src/components/layout/main-layout.tsx +++ b/packages/webui/src/components/layout/main-layout.tsx @@ -29,9 +29,10 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) { const { editing } = useLayout(); const { kiosk, exit: exitKiosk } = useKiosk(); // The sidebar rests as a slim icon rail and auto-expands on hover/focus (the - // peek logic below) — there's no collapse button. Layout-edit mode force- - // expands it so the drag-to-reorder list has room. - const effectiveCollapsed = !editing; + // peek logic below) — there's no collapse button. Two cases force it fully + // expanded: layout-edit mode (the drag-to-reorder list needs room) and the + // 「钉住侧栏展开」 appearance pref (operator opted out of the rail entirely). + const effectiveCollapsed = !editing && !appearance.sidebarPinned; // Hover/focus peek: while collapsed, hovering (or keyboard-focusing) the rail // temporarily expands it. The rail lives in the flex flow, so the page // content is pushed right rather than overlaid. The pinned `collapsed` pref diff --git a/packages/webui/src/components/pages/settings-page.tsx b/packages/webui/src/components/pages/settings-page.tsx index f0ff89b2..8b8c86e0 100644 --- a/packages/webui/src/components/pages/settings-page.tsx +++ b/packages/webui/src/components/pages/settings-page.tsx @@ -486,8 +486,8 @@ function AppearancePanel() { setAppearance({ highContrast })} ariaLabel="高对比模式" /> - - setAppearance({ sidebarDefaultCollapsed })} ariaLabel="侧栏默认折叠" /> + + setAppearance({ sidebarPinned })} ariaLabel="钉住侧栏展开" /> diff --git a/packages/webui/src/contexts/ThemeContext.tsx b/packages/webui/src/contexts/ThemeContext.tsx index 4d8caa90..e7d73367 100644 --- a/packages/webui/src/contexts/ThemeContext.tsx +++ b/packages/webui/src/contexts/ThemeContext.tsx @@ -111,7 +111,7 @@ export const DEFAULT_APPEARANCE: UiAppearance = { reduceMotion: false, disableMotion: false, highContrast: false, - sidebarDefaultCollapsed: false, + sidebarPinned: false, timeFormat: '24h', pollInterval: 3000, customCss: '', diff --git a/packages/webui/src/types.ts b/packages/webui/src/types.ts index 07d327c8..79253613 100644 --- a/packages/webui/src/types.ts +++ b/packages/webui/src/types.ts @@ -300,7 +300,8 @@ export interface UiAppearance { reduceMotion: boolean; disableMotion: boolean; highContrast: boolean; - sidebarDefaultCollapsed: boolean; + /** Pin the sidebar permanently expanded, opting out of the hover-expand rail. */ + sidebarPinned: boolean; timeFormat: TimeFormat; pollInterval: number; /** Operator custom CSS (applied post-auth only; stripped from /api/ui/public). */