import { assert, assertExists } from '@tldraw/tldraw' import { useEffect, useRef } from 'react' import { Link } from 'react-router-dom' import ExamplesTldrawLogo from './components/ExamplesTldrawLogo' import { ListLink } from './components/ListLink' import { Example, examples } from './examples' export function ExamplePage({ example, children, }: { example: Example children: React.ReactNode }) { const scrollElRef = useRef(null) const activeElRef = useRef(null) const isFirstScroll = useRef(true) useEffect(() => { const frame = requestAnimationFrame(() => { if (activeElRef.current) { const scrollEl = assertExists(scrollElRef.current) const activeEl = activeElRef.current assert(activeEl.offsetParent === scrollEl) const isScrolledIntoView = activeEl.offsetTop >= scrollEl.scrollTop && activeEl.offsetTop + activeEl.offsetHeight <= scrollEl.scrollTop + scrollEl.offsetHeight if (!isScrolledIntoView) { activeEl.scrollIntoView({ behavior: isFirstScroll.current ? 'auto' : 'smooth', block: isFirstScroll.current ? 'start' : 'center', }) } isFirstScroll.current = false } }) return () => cancelAnimationFrame(frame) }, [example]) return (
examples
    {examples .filter((e) => !e.hide) .filter((e) => e.order !== null) .map((e) => ( ))}

  • {examples .filter((e) => !e.hide) .filter((e) => e.order === null) .map((e) => ( ))}
{children}
) }