Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,9 +1,9 @@
import { Link, useLocation } from "react-router";
import { useEffect, useRef, useState } from "react";
import UrlUtils from "~/utils/app/UrlUtils";
import { cloneElement, isValidElement, useEffect, useRef, useState } from "react";
import Tabs from "../tabs/Tabs";
import EntityIcon from "~/components/layouts/icons/EntityIcon";
import { SidebarInside } from "~/ui";
import { isRouteActive } from "~/utils/navigation/routeMatching";
export type IconDto = {
name: string;
@@ -18,12 +18,26 @@ export type IconDto = {
hidden?: boolean;
};
// Pro-User gemerkter Collapse-Zustand der Inner-Sidebar (Default: aufgeklappt).
const COLLAPSE_STORAGE_KEY = "hg.innerSidebar.collapsed";
const HOVER_OPEN_DELAY_MS = 300;
const HOVER_CLOSE_DELAY_MS = 350;
const POINTER_ROUTE_SETTLE_MS = 750;
let suppressPointerHoverUntil = 0;
let lastPointerInteractionAt = 0;
function pointerHoverIsSuppressed() {
const now = Date.now();
if (now < lastPointerInteractionAt) {
lastPointerInteractionAt = 0;
suppressPointerHoverUntil = 0;
return false;
}
return now < suppressPointerHoverUntil;
}
export default function SidebarIconsLayout({
children,
items,
sticky = false,
}: {
children: React.ReactNode;
items: IconDto[];
@@ -32,59 +46,75 @@ export default function SidebarIconsLayout({
align: "bottom" | "right";
};
scrollRestoration?: boolean;
sticky?: boolean;
}) {
const location = useLocation();
const mainElement = useRef<HTMLDivElement>(null);
// SSR-safe: Server rendert immer aufgeklappt, der gemerkte Zustand wird erst nach Hydration geladen.
const [collapsed, setCollapsed] = useState(false);
// Transitions erst NACH dem Restore aktivieren, sonst animiert der gemerkte Zustand bei jedem Seitenaufruf.
const [animate, setAnimate] = useState(false);
const [hovered, setHovered] = useState(false);
const [focusWithin, setFocusWithin] = useState(false);
const openDelayRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const closeDelayRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const pointerInteractionRef = useRef(false);
const suppressHoverUntilLeaveRef = useRef(false);
const expanded = hovered || focusWithin;
useEffect(() => {
try {
setCollapsed(window.localStorage.getItem(COLLAPSE_STORAGE_KEY) === "1");
} catch {
// localStorage nicht verfügbar (Privatmodus o.ä.) -> Default aufgeklappt
}
const id = window.requestAnimationFrame(() => setAnimate(true));
return () => window.cancelAnimationFrame(id);
}, []);
function toggleCollapsed() {
setCollapsed((prev) => {
const next = !prev;
try {
window.localStorage.setItem(COLLAPSE_STORAGE_KEY, next ? "1" : "0");
} catch {
// persistieren best-effort
}
return next;
});
function cancelScheduledOpen() {
if (openDelayRef.current === null) return;
clearTimeout(openDelayRef.current);
openDelayRef.current = null;
}
function cancelScheduledClose() {
if (closeDelayRef.current === null) return;
clearTimeout(closeDelayRef.current);
closeDelayRef.current = null;
}
function handleMouseEnter() {
cancelScheduledClose();
if (suppressHoverUntilLeaveRef.current || pointerHoverIsSuppressed()) return;
if (hovered || openDelayRef.current !== null) return;
openDelayRef.current = setTimeout(() => {
setHovered(true);
openDelayRef.current = null;
}, HOVER_OPEN_DELAY_MS);
}
function handleMouseLeave() {
suppressHoverUntilLeaveRef.current = false;
pointerInteractionRef.current = false;
cancelScheduledOpen();
cancelScheduledClose();
if (!hovered) return;
closeDelayRef.current = setTimeout(() => {
setHovered(false);
closeDelayRef.current = null;
}, HOVER_CLOSE_DELAY_MS);
}
useEffect(
() => () => {
if (openDelayRef.current !== null) clearTimeout(openDelayRef.current);
if (closeDelayRef.current !== null) clearTimeout(closeDelayRef.current);
},
[]
);
function findExactRoute(element: IconDto) {
const hrefWithoutQuery = element.href.split("?")[0];
if (element.exact) {
return UrlUtils.stripTrailingSlash(location.pathname) === UrlUtils.stripTrailingSlash(hrefWithoutQuery);
}
return (location.pathname + location.search).includes(hrefWithoutQuery);
return isRouteActive(location.pathname, element.href, { exact: element.exact });
}
const currentTab = items.find((element) => findExactRoute(element));
function renderItem(item: IconDto, idx: number) {
const current = currentTab?.name === item.name;
const iconNode =
item.textIcon !== undefined ? (
<EntityIcon className="h-5 w-5" icon={current ? item.textIconSelected ?? item.textIcon : item.textIcon} />
) : current ? (
item.iconSelected ?? item.icon
) : (
item.icon
);
// Collapsed: center the icon-only item in the narrow rail. Expanded: keep the regular label row.
const textIcon = current ? (item.textIconSelected ?? item.textIcon) : item.textIcon;
const icon = current ? (item.iconSelected ?? item.icon) : item.icon;
const iconNode = textIcon !== undefined ? <EntityIcon className="size-5" icon={textIcon} /> : normalizeIcon(icon);
// The icon stays left-anchored in both states (NavItem keeps a constant 32px icon column),
// so the icon never shifts horizontally between the collapsed rail and the expanded label row.
return (
<Link key={idx} prefetch={item.prefetch} to={item.href} className="flex w-full justify-center" title={item.name}>
<SidebarInside.NavItem icon={iconNode} selected={current} variant={collapsed ? "icon-only" : "icon-and-text"}>
<Link key={idx} prefetch={item.prefetch} to={item.href} className="flex w-full justify-start" title={item.name}>
<SidebarInside.NavItem icon={iconNode} selected={current} variant={expanded ? "icon-and-text" : "icon-only"}>
{item.name}
</SidebarInside.NavItem>
</Link>
@@ -96,14 +126,34 @@ export default function SidebarIconsLayout({
return (
<div className="sm:flex sm:flex-row">
{/* Desktop: Inner sidebar uses the same mechanical width-collapse as the main navigation. */}
<div className="relative hidden sm:flex">
<SidebarInside
visible={true}
variant={collapsed ? "closed" : "open"}
onToggleCollapse={toggleCollapsed}
className={`min-h-[calc(100svh-4rem)] ${animate ? "" : "transition-none"}`}
>
{/* Desktop: expand on pointer hover or keyboard focus; otherwise keep a compact icon rail. */}
<div
className={sticky ? "relative hidden sm:sticky sm:top-0 sm:flex sm:self-start" : "relative hidden sm:flex"}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onPointerDownCapture={() => {
const pointerInteractionAt = Date.now();
pointerInteractionRef.current = true;
suppressHoverUntilLeaveRef.current = true;
lastPointerInteractionAt = pointerInteractionAt;
suppressPointerHoverUntil = pointerInteractionAt + POINTER_ROUTE_SETTLE_MS;
cancelScheduledOpen();
setFocusWithin(false);
}}
onPointerUpCapture={() => {
pointerInteractionRef.current = false;
}}
onPointerCancelCapture={() => {
pointerInteractionRef.current = false;
}}
onFocusCapture={() => {
if (!pointerInteractionRef.current) setFocusWithin(true);
}}
onBlurCapture={(event) => {
if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setFocusWithin(false);
}}
>
<SidebarInside visible={true} variant={expanded ? "open" : "closed"} className="min-h-[calc(100svh-3.5rem)]">
{topItems.map(renderItem)}
{bottomItems.length > 0 && (
<div className="mt-auto flex w-full flex-col">
@@ -121,7 +171,7 @@ export default function SidebarIconsLayout({
tabs={items
.filter((f) => !f.hidden)
.map((i) => {
return { name: i.name, routePath: i.href };
return { name: i.name, routePath: i.href, exact: i.exact };
})}
className="grow"
/>
@@ -129,9 +179,16 @@ export default function SidebarIconsLayout({
</div>
{/* Hauptbereich */}
<div ref={mainElement} className="w-full overflow-x-hidden">
<div ref={mainElement} className="w-full overflow-x-hidden" data-route-transition-content="true">
{children}
</div>
</div>
);
}
function normalizeIcon(icon: React.ReactNode) {
if (!isValidElement<{ className?: string }>(icon)) return icon;
return cloneElement(icon, {
className: `${icon.props.className ?? ""} inline-flex size-5 items-center justify-center [&_svg]:size-5`,
});
}