import { Bug, Check, Eye, EyeOff, GripVertical, LayoutDashboard, Lock, Pin, PinOff, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal, } from 'lucide-react'; import { motion, Reorder, useDragControls } from 'motion/react'; import { Link, useRouterState } from '@tanstack/react-router'; import { ScrollArea } from '@/components/ui/scroll-area'; import { cn } from '@/lib/utils'; import { APP_NAME, APP_VERSION } from '@/types'; import { useAppState } from '@/contexts/AppStateContext'; import { useTheme } from '@/contexts/ThemeContext'; import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext'; import { useDesktopSidebar } from '@/hooks/use-media-query'; import type { AppPath } from '@/router'; import type { UiLayoutItem } from '@/types'; export interface NavItem { to: AppPath; label: string; icon: typeof LayoutDashboard; description: string; } export const NAV_ITEMS: NavItem[] = [ { to: '/', label: '总览', icon: LayoutDashboard, description: '主机与服务状态' }, { to: '/processes', label: '进程注入', icon: PlugZap, description: '加载 / 卸载 / 登录' }, { to: '/config', label: '节点配置', icon: Settings, description: 'OneBot 协议端点' }, { to: '/logs', label: '日志', icon: Terminal, description: '实时事件流' }, { to: '/debug', label: '调试', icon: Bug, description: '测试台与实时活动' }, { to: '/settings', label: '系统设置', icon: SlidersHorizontal, description: '主题与账号' }, ]; // Anti-self-lock: these nav items can be reordered but never hidden. // '/' — hosts the 「编辑布局」 entry point; hiding it would strand the // user with no way back to un-hide anything. // '/settings'— account + appearance. export const PINNED_NAV: AppPath[] = ['/', '/settings']; function NavReorderRow({ item, meta, onToggle, }: { item: UiLayoutItem; meta: NavItem; onToggle: (id: string) => void; }) { const controls = useDragControls(); const Icon = meta.icon; const itemPinned = (PINNED_NAV as string[]).includes(item.id); return ( {meta.label} {itemPinned ? ( ) : ( )} ); } interface SidebarProps { collapsed?: boolean; onItemClick?: () => void; } export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { const pathname = useRouterState({ select: (s) => s.location.pathname }); const { updateInfo } = useAppState(); const { navItems, setNavItems, editing, setEditing } = useLayout(); const { appearance, setAppearance } = useTheme(); const isDesktop = useDesktopSidebar(); const pinned = appearance.sidebarPinned; // 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 — logo sits in a fixed 48px column centred in the collapsed rail; the wordmark to its right is clipped (never unmounted) when the rail narrows. */}
SnowLuma
{APP_NAME} v{APP_VERSION}
OneBot v11 控制台
{/* Nav */} {editing ? (
编辑导航
i.id)} onReorder={reorderNav} className="flex flex-col gap-1" > {reconciled.map((item) => { const meta = NAV_ITEMS.find((n) => n.to === item.id); if (!meta) { return null; } return ( ); })}
) : ( )}
{updateInfo?.hasUpdate && (
{/* Background as an absolute layer so the collapsed rail shows a centred squircle, not a full-width bar cut off with a hard edge. */} 有新版本可用 v{updateInfo.latest} · 点击查看
)} {/* Footer: © + the pin toggle (desktop only). Pinning keeps the rail expanded; unpinning returns it to the hover-to-peek rail. Mirrors the 「钉住侧栏展开」 appearance setting. */}
© {new Date().getFullYear()} SnowLuma {isDesktop && ( )}
); }