import type { Header } from '@rspress/core'; import { Link, parseInlineMarkdownText, renderInlineMarkdown, } from '@rspress/core/theme'; import clsx from 'clsx'; import './TocItem.scss'; import { useEffect, useRef } from 'react'; import scrollIntoView from 'scroll-into-view-if-needed'; export const TocItem = ({ header, baseHeaderLevel, active, }: { header: Header; baseHeaderLevel: number; active: boolean; }) => { const ref = useRef(null); useEffect(() => { if (active && ref.current) { scrollIntoView(ref.current, { behavior: 'smooth', block: 'center', inline: 'center', boundary: element => { const isBoundary = element.classList.contains('rp-doc-layout__outline') || element.classList.contains('rspress-doc'); return !isBoundary; }, }); } }, [active]); return ( ); };