// RĂ´le : structure le layout global avec sidebar, topbar, navigation et contenu. import { useEffect, useRef } from "react"; import { Icon } from "./Icon.jsx"; import { ImportButton } from "./ImportButton.jsx"; import { Tooltip } from "./Tooltip.jsx"; export function Shell({ route, content, games, drawerGameId = "", drawerVisible = false, compactGameLayout = false, reducedSidebar = false, actions, onOpenAutoBackup, children }) { const gameId = route.split("/")[1] === "games" ? route.split("/")[2] || "" : ""; const game = games.find((item) => item.id === gameId); const topbarLabel = route === "/design-system" && import.meta.env.DEV ? "Design system" : route.startsWith("/toolbox") ? content.topbar.toolbox : route.startsWith("/games") ? content.topbar.games : route === "/library" ? content.topbar.library : content.topbar.dashboard; const toolboxOpen = Boolean(game && drawerGameId === game.id && drawerVisible); const toolboxLabel = toolboxOpen ? "Masquer la toolbox" : "Afficher la toolbox"; const compactSidebar = Boolean(reducedSidebar || (!compactGameLayout && toolboxOpen)); const compactToolboxVisible = Boolean(compactGameLayout && toolboxOpen); const guideTabRef = useRef(null); const toolboxTabRef = useRef(null); const wideToolboxButtonRef = useRef(null); const focusedViewControlRef = useRef(""); const previousCompactLayoutRef = useRef(compactGameLayout); useEffect(() => { const trackFocus = (event) => { if (event.target.closest?.(".compact-game-view-switch")) focusedViewControlRef.current = "compact"; else if (event.target.closest?.(".toolbox-button")) focusedViewControlRef.current = "wide"; else focusedViewControlRef.current = ""; }; document.addEventListener("focusin", trackFocus); return () => document.removeEventListener("focusin", trackFocus); }, []); useEffect(() => { const activeElement = document.activeElement; const layoutChanged = previousCompactLayoutRef.current !== compactGameLayout; previousCompactLayoutRef.current = compactGameLayout; if (layoutChanged && compactGameLayout && focusedViewControlRef.current === "wide") { (compactToolboxVisible ? toolboxTabRef.current : guideTabRef.current)?.focus(); } else if (compactGameLayout && !compactToolboxVisible && activeElement?.closest?.("#toolbox-drawer")) { guideTabRef.current?.focus(); } else if (layoutChanged && !compactGameLayout && focusedViewControlRef.current === "compact") { wideToolboxButtonRef.current?.focus(); } }, [compactGameLayout, compactToolboxVisible]); return (
{topbarLabel}
{game && (
{compactGameLayout ?
: }
)}
{children}
); }