"use client"; import { useEffect, useState } from "react"; import { cn, formatDate2 } from "@/lib/utils"; import { History } from "lucide-react"; import { ScrollArea } from "@/components/ui/scroll-area"; interface VersionTocProps { versions: Array<{ version: string; date: string; }>; } export function VersionToc({ versions }: VersionTocProps) { const [activeId, setActiveId] = useState(null); useEffect(() => { // Handle initial hash const hash = window.location.hash.slice(1); if (hash) { setActiveId(hash); } // Set up intersection observer const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { const id = entry.target.id; setActiveId(id); // Use pushState instead of replaceState to maintain history window.history.pushState(null, '', `#${id}`); } }); }, { threshold: 0.2, rootMargin: '-20% 0px -60% 0px' } ); // Observe version elements versions.forEach(({ version }) => { const element = document.getElementById(`v${version}`); if (element) observer.observe(element); }); return () => observer.disconnect(); }, [versions]); return ( ); }