diff --git a/packages/webui/src/components/layout/main-layout.tsx b/packages/webui/src/components/layout/main-layout.tsx
index 0006f9dc..2c8b96df 100644
--- a/packages/webui/src/components/layout/main-layout.tsx
+++ b/packages/webui/src/components/layout/main-layout.tsx
@@ -7,6 +7,7 @@ import { Sidebar } from '@/components/layout/sidebar';
import { TopBar } from '@/components/layout/top-bar';
import { useMediaQuery } from '@/hooks/use-media-query';
import { useTheme } from '@/contexts/ThemeContext';
+import { useLayout } from '@/contexts/LayoutContext';
import { cn } from '@/lib/utils';
interface MainLayoutProps {
@@ -27,6 +28,10 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
return appearance.sidebarDefaultCollapsed;
});
const customBg = appearance.background.type !== 'none';
+ const { editing } = useLayout();
+ // Force the sidebar open while editing layout so its drag-to-reorder list
+ // has room (it returns to the user's collapsed pref on 完成).
+ const effectiveCollapsed = collapsed && !editing;
const [mobileOpen, setMobileOpen] = useState(false);
const pathname = useRouterState({ select: (s) => s.location.pathname });
@@ -40,11 +45,11 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
{!isMobile && (
-
+
)}
@@ -66,11 +71,12 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
setCollapsed((v) => !v)}
onOpenMobile={() => setMobileOpen(true)}
onLogout={onLogout}
isMobile={isMobile}
+ editing={editing}
/>
diff --git a/packages/webui/src/components/layout/sidebar.tsx b/packages/webui/src/components/layout/sidebar.tsx
index 37024a0b..e92f30dd 100644
--- a/packages/webui/src/components/layout/sidebar.tsx
+++ b/packages/webui/src/components/layout/sidebar.tsx
@@ -1,5 +1,5 @@
-import { LayoutDashboard, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react';
-import { motion } from 'motion/react';
+import { Check, Eye, EyeOff, GripVertical, LayoutDashboard, Lock, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react';
+import { motion, Reorder } from 'motion/react';
import { Link, useRouterState } from '@tanstack/react-router';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Separator } from '@/components/ui/separator';
@@ -38,15 +38,23 @@ interface SidebarProps {
export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
const pathname = useRouterState({ select: (s) => s.location.pathname });
const { updateInfo } = useAppState();
- const { navItems } = useLayout();
+ const { navItems, setNavItems, editing, setEditing } = useLayout();
- // Render nav in the operator's configured order, hidden items removed,
- // pinned items forced on, and forward-compatible with future routes.
- const orderedNav = reconcileLayoutItems(navItems, NAV_ITEMS.map((i) => i.to), PINNED_NAV)
+ // Full reconciled nav (incl. hidden) — pinned forced visible, forward-compat.
+ const reconciled = reconcileLayoutItems(navItems, NAV_ITEMS.map((i) => i.to), PINNED_NAV);
+ // View mode: configured order, hidden removed.
+ const orderedNav = reconciled
.filter((i) => i.visible)
.map((i) => NAV_ITEMS.find((n) => n.to === i.id))
.filter((n): n is NavItem => !!n);
+ const reorderNav = (ids: string[]) => {
+ const byId = new Map(reconciled.map((i) => [i.id, i]));
+ setNavItems(ids.map((id) => byId.get(id)).filter((x): x is NonNullable => !!x));
+ };
+ const toggleNav = (id: string) =>
+ setNavItems(reconciled.map((i) => (i.id === id ? { ...i, visible: !i.visible } : i)));
+
return (
{/* Brand */}
@@ -67,42 +75,94 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
{/* Nav */}
-
+ ) : (
+
+ )}
diff --git a/packages/webui/src/components/layout/top-bar.tsx b/packages/webui/src/components/layout/top-bar.tsx
index b5198cbe..e86993ee 100644
--- a/packages/webui/src/components/layout/top-bar.tsx
+++ b/packages/webui/src/components/layout/top-bar.tsx
@@ -15,6 +15,8 @@ interface TopBarProps {
onOpenMobile: () => void;
onLogout: () => void;
isMobile: boolean;
+ /** Layout edit mode force-expands the sidebar, so collapsing is disabled. */
+ editing?: boolean;
}
export function TopBar({
@@ -24,6 +26,7 @@ export function TopBar({
onOpenMobile,
onLogout,
isMobile,
+ editing = false,
}: TopBarProps) {
const [confirmLogout, setConfirmLogout] = useState(false);
const pathname = useRouterState({ select: (s) => s.location.pathname });
@@ -43,8 +46,9 @@ export function TopBar({
variant="ghost"
size="icon-sm"
onClick={onToggleCollapse}
+ disabled={editing}
aria-label={collapsed ? '展开侧边栏' : '收起侧边栏'}
- title={collapsed ? '展开侧边栏' : '收起侧边栏'}
+ title={editing ? '编辑布局时侧栏保持展开' : collapsed ? '展开侧边栏' : '收起侧边栏'}
>
{collapsed ? : }
diff --git a/packages/webui/src/components/pages/dashboard-grid.tsx b/packages/webui/src/components/pages/dashboard-grid.tsx
index b6282d44..9a94261a 100644
--- a/packages/webui/src/components/pages/dashboard-grid.tsx
+++ b/packages/webui/src/components/pages/dashboard-grid.tsx
@@ -1,6 +1,7 @@
import { useLayoutEffect, useRef, useState, type ReactNode } from 'react';
import { createPortal } from 'react-dom';
import { GridStack, type GridStackWidget } from 'gridstack';
+import { Eye, EyeOff, GripVertical, Settings2 } from 'lucide-react';
import 'gridstack/dist/gridstack.css';
import { GRID_CELL_HEIGHT, GRID_MARGIN, minSizeOf } from '@/lib/dashboard-layout';
import { cn } from '@/lib/utils';
@@ -9,7 +10,8 @@ import type { UiLayoutItem } from '@/types';
export interface GridCoord { id: string; x: number; y: number; w: number; h: number }
interface DashboardGridProps {
- /** Visible blocks, each with x/y/w/h (already migrated/positioned). */
+ /** Blocks to render — visible-only in view mode, ALL (incl. hidden) in edit
+ * mode so hidden widgets show as re-enableable ghosts. Each has x/y/w/h. */
blocks: UiLayoutItem[];
editing: boolean;
/** Column count — 12 on desktop, 1 on narrow screens (auto single-column). */
@@ -17,6 +19,11 @@ interface DashboardGridProps {
/** Fired (debounced upstream) after a drag/resize settles. */
onChange: (coords: GridCoord[]) => void;
renderWidget: (block: UiLayoutItem) => ReactNode;
+ // ── edit overlay ──
+ labelFor: (id: string) => string;
+ configurableIds: ReadonlySet;
+ onToggleVisible: (id: string) => void;
+ onConfigOpen: (id: string) => void;
}
/**
@@ -27,7 +34,10 @@ interface DashboardGridProps {
* coord change (gridstack already moved the item; the coord round-trips back
* through `onChange` → state and matches what gridstack has).
*/
-export function DashboardGrid({ blocks, editing, cols, onChange, renderWidget }: DashboardGridProps) {
+export function DashboardGrid({
+ blocks, editing, cols, onChange, renderWidget,
+ labelFor, configurableIds, onToggleVisible, onConfigOpen,
+}: DashboardGridProps) {
const elRef = useRef(null);
const gridRef = useRef(null);
const [contentEls, setContentEls] = useState>({});
@@ -53,7 +63,11 @@ export function DashboardGrid({ blocks, editing, cols, onChange, renderWidget }:
float: true, // free placement — items stay where dropped (no auto-compact)
disableDrag: !editing,
disableResize: !editing,
- handle: '.grid-stack-item-content',
+ // Default handle (.grid-stack-item-content) = the whole card is a drag
+ // target in edit mode — forgiving + discoverable. The card body is
+ // pointer-events-none in edit mode so widget controls don't fire, and
+ // the eye/gear are