chore: update mdx-components

This commit is contained in:
2024-01-08 11:58:04 +01:00
parent 0b6ce93831
commit fb5383775b

View File

@@ -38,7 +38,7 @@ export const TableOfContents = ({ tocMap }: Props) => {
const headingsObserver = headingsObserverRef.current const headingsObserver = headingsObserverRef.current
setTimeout(() => { setTimeout(() => {
document.querySelectorAll('article :is(h1,h2,h3)').forEach(h => headingsObserver.observe(h)) document.querySelectorAll('article :is(h2,h3,h4)').forEach(h => headingsObserver.observe(h))
}, 100) }, 100)
return () => { return () => {
@@ -53,13 +53,22 @@ export const TableOfContents = ({ tocMap }: Props) => {
// Disconnect and reconnect the observer to refresh it // Disconnect and reconnect the observer to refresh it
headingsObserver.disconnect() headingsObserver.disconnect()
setTimeout(() => { setTimeout(() => {
document.querySelectorAll('article :is(h1,h2,h3)').forEach(h => headingsObserver.observe(h)) document.querySelectorAll('article :is(h2,h3,h4)').forEach(h => headingsObserver.observe(h))
}, 100) }, 100)
} }
}, [tocMap]) }, [tocMap])
const onLinkClick = (e: MouseEvent<HTMLAnchorElement>) => { const onLinkClick = (e: MouseEvent<HTMLAnchorElement>) => {
setCurrentHeading(e.currentTarget.getAttribute('href')!.replace('#', '')) setCurrentHeading(e.currentTarget.getAttribute('href')!.replace('#', ''))
if (headingsObserverRef.current) {
const headingsObserver = headingsObserverRef.current
// Disconnect and reconnect the observer to refresh it
headingsObserver.disconnect()
setTimeout(() => {
document.querySelectorAll('article :is(h2,h3,h4)').forEach(h => headingsObserver.observe(h))
}, 100)
}
} }
return ( return (