import { Infinity as InfinityIcon, PanelLeftClose, PanelLeftOpen } from "lucide-react"; import { Fragment, useEffect, useRef, useState, type ReactNode } from "react"; import { Link, useLocation, useNavigate } from "react-router"; import { ModelSetupGuide } from "@/components/layout/model-setup-guide"; import { WorkspaceSidebarFooter } from "@/components/layout/workspace-sidebar-footer"; import { navigationTools, type NavigationToolSlug } from "@/constant/navigation-tools"; import { cn } from "@/lib/utils"; import { isSpatialWorkbenchPath } from "@/lib/workspace-routes"; export function AppWorkspaceShell({ children }: { children: ReactNode }) { const { pathname } = useLocation(); const navigate = useNavigate(); const [mobileSidebarExpanded, setMobileSidebarExpanded] = useState(false); const scrollRef = useRef(null); const [scrollState, setScrollState] = useState({ hasTopFade: false, hasBottomFade: false, }); const hideChrome = pathname.startsWith("/admin") || /^\/canvas\/[^/]+/.test(pathname); const spatialWorkbench = isSpatialWorkbenchPath(pathname); const creationWorkspace = pathname === "/create"; const slug = pathname.split("/").filter(Boolean)[0]; const activeToolSlug = navigationTools.some((tool) => tool.slug === slug) ? (slug as NavigationToolSlug) : undefined; const visibleNavigationTools = spatialWorkbench ? navigationTools : navigationTools.filter((tool) => tool.section === "创作空间"); const handleScroll = () => { const element = scrollRef.current; if (!element) return; const { scrollTop, scrollHeight, clientHeight } = element; setScrollState({ hasTopFade: scrollTop > 0, hasBottomFade: scrollTop + clientHeight < scrollHeight - 1, }); }; useEffect(() => { const handleWorkspaceNavigation = (rawEvent: Event) => { const event = rawEvent as CustomEvent<{ to?: string }>; if (!event.detail?.to) return; event.preventDefault(); navigate(event.detail.to); }; window.addEventListener("workspace:navigate", handleWorkspaceNavigation); return () => window.removeEventListener("workspace:navigate", handleWorkspaceNavigation); }, [navigate]); useEffect(() => { handleScroll(); }, [visibleNavigationTools.length, mobileSidebarExpanded]); return ( <>
{!hideChrome && mobileSidebarExpanded ? ) : null} {children}