mirror of
https://github.com/ershisan99/md-preview-desktop.git
synced 2025-12-16 20:59:24 +00:00
chore: update mdx-components
This commit is contained in:
@@ -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 (
|
||||||
|
|||||||
Reference in New Issue
Block a user