@san-siva/blogkit 1.1.16 → 1.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,9 +16,9 @@ const Blog = ({ children, title = 'In this article', jsonLd, }) => {
16
16
  const [showTOC, setShowTOC] = react.useState(false);
17
17
  const updateTimerRef = react.useRef(null);
18
18
  const showTOCTimerRef = react.useRef(null);
19
- const hasScrolledToInitialSection = react.useRef(false);
20
19
  const isClickScrolling = react.useRef(false);
21
20
  const scrollEndHandlerRef = react.useRef(null);
21
+ const intersectionObserversRef = react.useRef(new Map());
22
22
  const sortByDomPosition = react.useCallback(([, a], [, b]) => {
23
23
  const position = a.el.compareDocumentPosition(b.el);
24
24
  if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
@@ -66,13 +66,14 @@ const Blog = ({ children, title = 'In this article', jsonLd, }) => {
66
66
  }, 200);
67
67
  }, [updateCategoryTitles]);
68
68
  react.useEffect(() => {
69
- const observers = new Map();
70
69
  for (const [id, { el }] of categoryTitles) {
71
70
  const observer = new IntersectionObserver(([entry]) => {
72
71
  if (!entry.isIntersecting)
73
72
  return;
74
73
  if (isClickScrolling.current)
75
74
  return;
75
+ if (document.body.scrollTop === 0)
76
+ return;
76
77
  setVisibleTitle(visibleId => {
77
78
  if (visibleId === id && !entry.isIntersecting)
78
79
  return null;
@@ -80,15 +81,13 @@ const Blog = ({ children, title = 'In this article', jsonLd, }) => {
80
81
  return id;
81
82
  return visibleId;
82
83
  });
84
+ const url = new URL(window.location.href);
85
+ url.searchParams.set('section', id);
86
+ window.history.replaceState({}, '', url.toString());
83
87
  }, { threshold: 0.1 });
84
- observers.set(id, observer);
88
+ intersectionObserversRef.current.set(id, observer);
85
89
  observer.observe(el);
86
90
  }
87
- return () => {
88
- for (const observer of observers.values()) {
89
- observer.disconnect();
90
- }
91
- };
92
91
  }, [categoryTitles.size]);
93
92
  react.useEffect(() => {
94
93
  return () => {
@@ -101,26 +100,46 @@ const Blog = ({ children, title = 'In this article', jsonLd, }) => {
101
100
  if (scrollEndHandlerRef.current) {
102
101
  document.body.removeEventListener('scrollend', scrollEndHandlerRef.current);
103
102
  }
103
+ if (intersectionObserversRef.current) {
104
+ for (const observer of intersectionObserversRef.current.values()) {
105
+ observer.disconnect();
106
+ }
107
+ }
104
108
  };
105
109
  }, []);
110
+ const getSectionFromUrl = () => {
111
+ const url = new URL(window.location.href);
112
+ const section = url.searchParams.get('section');
113
+ if (!section)
114
+ return null;
115
+ return section;
116
+ };
117
+ const updateUrl = (id) => {
118
+ const url = new URL(window.location.href);
119
+ url.searchParams.set('section', id);
120
+ window.history.replaceState({}, '', url.toString());
121
+ };
122
+ const scrollIntoView = (element) => {
123
+ if (!element)
124
+ return;
125
+ const top = element.getBoundingClientRect().top + document.body.scrollTop - 100;
126
+ document.body.scrollTo({ top, behavior: 'smooth' });
127
+ };
106
128
  // On initial load, scroll to section specified in URL
107
129
  react.useEffect(() => {
108
- if (hasScrolledToInitialSection.current)
109
- return;
110
130
  if (categoryTitles.size === 0)
111
131
  return;
112
- const url = new URL(window.location.href);
113
- const section = url.searchParams.get('section');
114
- if (!section)
132
+ const section = getSectionFromUrl();
133
+ if (!section) {
115
134
  return;
135
+ }
116
136
  const entry = categoryTitles.get(section);
117
- if (!entry)
137
+ if (!entry) {
118
138
  return;
119
- hasScrolledToInitialSection.current = true;
120
- const top = entry.el.getBoundingClientRect().top + document.body.scrollTop - 100;
121
- document.body.scrollTo({ top, behavior: 'smooth' });
139
+ }
140
+ scrollIntoView(entry.el);
122
141
  lockScrollUpdates.default(section, isClickScrolling, scrollEndHandlerRef, setVisibleTitle);
123
- }, [categoryTitles]);
142
+ }, [categoryTitles.size]);
124
143
  const handleSectionReference = react.useCallback((element) => {
125
144
  if (!element)
126
145
  return;
@@ -163,14 +182,8 @@ const Blog = ({ children, title = 'In this article', jsonLd, }) => {
163
182
  const { el } = categoryTitles.get(id) || {};
164
183
  if (!el)
165
184
  return;
166
- const top = el.getBoundingClientRect().top + document.body.scrollTop - 100;
167
- const url = new URL(window.location.href);
168
- url.searchParams.set('section', id);
169
- window.history.replaceState({}, '', url.toString());
170
- document.body.scrollTo({
171
- top,
172
- behavior: 'smooth',
173
- });
185
+ updateUrl(id);
186
+ scrollIntoView(el);
174
187
  lockScrollUpdates.default(id, isClickScrolling, scrollEndHandlerRef, setVisibleTitle);
175
188
  };
176
189
  const sidebarStyle = web.useSpring({
@@ -1 +1 @@
1
- {"version":3,"file":"BlogDynamic.js","sources":["../../../src/dynamicComponents/BlogDynamic.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tChildren,\n\tcloneElement,\n\tisValidElement,\n\tuseCallback,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport { useSpring, animated, config } from '@react-spring/web';\n\nimport type { MouseEvent, ReactNode, RefAttributes } from 'react';\nimport type { Thing, WithContext } from 'schema-dts';\n\nimport styles from '../styles/Blog.module.scss';\nimport lockScrollUpdates from '../utils/lockScrollUpdates';\n\ninterface BlogProperties {\n\tchildren: ReactNode;\n\ttitle?: string;\n\tjsonLd?: WithContext<Thing>;\n}\n\nexport interface ForwardedReference {\n\tparentRef: HTMLDivElement;\n\tchildRefs: HTMLDivElement[];\n}\n\ninterface SectionReferenceValue {\n\tel: HTMLElement;\n\ttitle: string;\n\tisSubSection: boolean;\n}\n\ntype SectionReference = Map<string, SectionReferenceValue>;\n\ninterface CategoryTitleValue extends SectionReferenceValue {\n\tlastUpdatedAt: number;\n}\n\ntype CategoryTitle = Map<string, CategoryTitleValue>;\n\nconst Blog = ({\n\tchildren,\n\ttitle = 'In this article',\n\tjsonLd,\n}: BlogProperties) => {\n\tconst sectionReferences = useRef<SectionReference>(new Map());\n\tconst [categoryTitles, setCategoryTitles] = useState<CategoryTitle>(\n\t\tnew Map()\n\t);\n\tconst [visibleTitle, setVisibleTitle] = useState<string | null>(null);\n\tconst [showTOC, setShowTOC] = useState(false);\n\n\tconst updateTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\tconst showTOCTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\tconst hasScrolledToInitialSection = useRef(false);\n\tconst isClickScrolling = useRef(false);\n\tconst scrollEndHandlerRef = useRef<(() => void) | null>(null);\n\n\tconst sortByDomPosition = useCallback(\n\t\t(\n\t\t\t[, a]: [string, SectionReferenceValue],\n\t\t\t[, b]: [string, SectionReferenceValue]\n\t\t) => {\n\t\t\tconst position = a.el.compareDocumentPosition(b.el);\n\t\t\tif (position & Node.DOCUMENT_POSITION_FOLLOWING) {\n\t\t\t\treturn -1; // a comes before b\n\t\t\t} else if (position & Node.DOCUMENT_POSITION_PRECEDING) {\n\t\t\t\treturn 1; // b comes before a\n\t\t\t}\n\t\t\treturn 0;\n\t\t},\n\t\t[]\n\t);\n\n\tconst updateCategoryTitles = useCallback(() => {\n\t\tconst now = Date.now();\n\t\tconst newCategoryTitles = new Map<string, CategoryTitleValue>();\n\n\t\t// Sort sections by their DOM position to maintain correct order\n\t\tconst sectionsArray = Array.from(sectionReferences.current.entries());\n\t\tsectionsArray.sort(sortByDomPosition);\n\n\t\tlet firstSectionId: string | null = null;\n\t\tfor (const [id, { title, el, isSubSection }] of sectionsArray) {\n\t\t\tif (!firstSectionId) {\n\t\t\t\tfirstSectionId = id;\n\t\t\t}\n\t\t\tnewCategoryTitles.set(id, {\n\t\t\t\tel,\n\t\t\t\ttitle,\n\t\t\t\tlastUpdatedAt: now,\n\t\t\t\tisSubSection,\n\t\t\t});\n\t\t}\n\n\t\tif (newCategoryTitles.size === 0) return;\n\n\t\tsetCategoryTitles(newCategoryTitles);\n\t\tif (!showTOC) setShowTOC(true);\n\n\t\tif (visibleTitle) return;\n\t\tsetVisibleTitle(firstSectionId);\n\t}, [visibleTitle, sortByDomPosition, showTOC, setShowTOC]);\n\n\tconst debounceUpdateCategoryTitles = useCallback(() => {\n\t\t// Clear existing timer and set a new one to batch updates\n\t\tif (updateTimerRef.current) {\n\t\t\tclearTimeout(updateTimerRef.current);\n\t\t}\n\t\tupdateTimerRef.current = setTimeout(() => {\n\t\t\tupdateCategoryTitles();\n\t\t}, 200);\n\t}, [updateCategoryTitles]);\n\n\tuseEffect(() => {\n\t\tconst observers = new Map<string, IntersectionObserver>();\n\t\tfor (const [id, { el }] of categoryTitles) {\n\t\t\tconst observer = new IntersectionObserver(\n\t\t\t\t([entry]) => {\n\t\t\t\t\tif (!entry.isIntersecting) return;\n\t\t\t\t\tif (isClickScrolling.current) return;\n\t\t\t\t\tsetVisibleTitle(visibleId => {\n\t\t\t\t\t\tif (visibleId === id && !entry.isIntersecting) return null;\n\t\t\t\t\t\tif (entry.isIntersecting) return id;\n\t\t\t\t\t\treturn visibleId;\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t{ threshold: 0.1 }\n\t\t\t);\n\t\t\tobservers.set(id, observer);\n\t\t\tobserver.observe(el);\n\t\t}\n\t\treturn () => {\n\t\t\tfor (const observer of observers.values()) {\n\t\t\t\tobserver.disconnect();\n\t\t\t}\n\t\t};\n\t}, [categoryTitles.size]);\n\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\tif (updateTimerRef.current) {\n\t\t\t\tclearTimeout(updateTimerRef.current);\n\t\t\t}\n\t\t\tif (showTOCTimerRef.current) {\n\t\t\t\tclearTimeout(showTOCTimerRef.current);\n\t\t\t}\n\t\t\tif (scrollEndHandlerRef.current) {\n\t\t\t\tdocument.body.removeEventListener('scrollend', scrollEndHandlerRef.current);\n\t\t\t}\n\t\t};\n\t}, []);\n\n\t// On initial load, scroll to section specified in URL\n\tuseEffect(() => {\n\t\tif (hasScrolledToInitialSection.current) return;\n\t\tif (categoryTitles.size === 0) return;\n\t\tconst url = new URL(window.location.href);\n\t\tconst section = url.searchParams.get('section');\n\t\tif (!section) return;\n\t\tconst entry = categoryTitles.get(section);\n\t\tif (!entry) return;\n\t\thasScrolledToInitialSection.current = true;\n\t\tconst top =\n\t\t\tentry.el.getBoundingClientRect().top + document.body.scrollTop - 100;\n\t\tdocument.body.scrollTo({ top, behavior: 'smooth' });\n\t\tlockScrollUpdates(section, isClickScrolling, scrollEndHandlerRef, setVisibleTitle);\n\t}, [categoryTitles]);\n\n\tconst handleSectionReference = useCallback(\n\t\t(element: ForwardedReference) => {\n\t\t\tif (!element) return;\n\t\t\tconst { parentRef, childRefs } = element;\n\n\t\t\t// Add parent section reference\n\t\t\tif (parentRef) {\n\t\t\t\tconst id = parentRef.dataset.id;\n\t\t\t\tconst title = parentRef.dataset.title;\n\t\t\t\tif (id && title) {\n\t\t\t\t\tsectionReferences.current.set(id, {\n\t\t\t\t\t\tel: parentRef,\n\t\t\t\t\t\ttitle,\n\t\t\t\t\t\tisSubSection: false,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add child section references\n\t\t\tif (Array.isArray(childRefs)) {\n\t\t\t\tfor (const childRef of childRefs) {\n\t\t\t\t\tif (!childRef) continue;\n\t\t\t\t\tconst id = childRef.dataset.id;\n\t\t\t\t\tconst title = childRef.dataset.title;\n\t\t\t\t\tif (id && title) {\n\t\t\t\t\t\tsectionReferences.current.set(id, {\n\t\t\t\t\t\t\tel: childRef,\n\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\tisSubSection: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdebounceUpdateCategoryTitles();\n\t\t},\n\t\t[debounceUpdateCategoryTitles]\n\t);\n\n\tconst handleClickCategoryTitle = (\n\t\terror: MouseEvent<HTMLParagraphElement>\n\t) => {\n\t\tconst id = error.currentTarget.dataset.id;\n\t\tconst index = error.currentTarget.dataset.idx;\n\t\tif (!id || !index) return;\n\n\t\tconst { el } = categoryTitles.get(id) || {};\n\t\tif (!el) return;\n\n\t\tconst top = el.getBoundingClientRect().top + document.body.scrollTop - 100;\n\n\t\tconst url = new URL(window.location.href);\n\t\turl.searchParams.set('section', id);\n\t\twindow.history.replaceState({}, '', url.toString());\n\n\t\tdocument.body.scrollTo({\n\t\t\ttop,\n\t\t\tbehavior: 'smooth',\n\t\t});\n\n\t\tlockScrollUpdates(id, isClickScrolling, scrollEndHandlerRef, setVisibleTitle);\n\t};\n\n\tconst sidebarStyle = useSpring({\n\t\topacity: showTOC ? 1 : 0,\n\t\ttransform: showTOC ? 'translateX(0)' : 'translateX(40px)',\n\t\tconfig: config.gentle,\n\t});\n\n\treturn (\n\t\t<div className={styles.blog}>\n\t\t\t{jsonLd && (\n\t\t\t\t<script\n\t\t\t\t\ttype=\"application/ld+json\"\n\t\t\t\t\tdangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t<div className={styles['blog__content']}>\n\t\t\t\t{Children.map(children, child => {\n\t\t\t\t\tif (!isValidElement(child)) return child;\n\t\t\t\t\treturn cloneElement(child, {\n\t\t\t\t\t\tref: handleSectionReference,\n\t\t\t\t\t} as RefAttributes<ForwardedReference>);\n\t\t\t\t})}\n\t\t\t</div>\n\t\t\t<animated.div className={styles['blog__sidebar']} style={sidebarStyle}>\n\t\t\t\t<p\n\t\t\t\t\tclassName={`${styles['margin-bottom--3']} ${styles['category__header']}`}\n\t\t\t\t>\n\t\t\t\t\t{title}\n\t\t\t\t</p>\n\t\t\t\t{[...categoryTitles].map(\n\t\t\t\t\t([id, { title, isSubSection }], index, array) => {\n\t\t\t\t\t\tconst isNextSectionSubSection = array[index + 1]?.[1]?.isSubSection;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\tkey={id}\n\t\t\t\t\t\t\t\tdata-idx={index}\n\t\t\t\t\t\t\t\tdata-id={id}\n\t\t\t\t\t\t\t\tclassName={`${styles['category__title']} ${\n\t\t\t\t\t\t\t\t\tid === visibleTitle ? styles['category__title--active'] : ''\n\t\t\t\t\t\t\t\t} ${isSubSection ? styles['category__title--sub'] : ''} ${\n\t\t\t\t\t\t\t\t\tisSubSection && !isNextSectionSubSection\n\t\t\t\t\t\t\t\t\t\t? styles['margin-bottom-imp--2']\n\t\t\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t\t}`}\n\t\t\t\t\t\t\t\tonClick={handleClickCategoryTitle}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{title}\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t)}\n\t\t\t</animated.div>\n\t\t</div>\n\t);\n};\n\nexport default Blog;\n"],"names":["useRef","useState","useCallback","useEffect","lockScrollUpdates","useSpring","config","_jsxs","styles","_jsx","Children","isValidElement","cloneElement","animated"],"mappings":";;;;;;;;;;AA4CA,MAAM,IAAI,GAAG,CAAC,EACb,QAAQ,EACR,KAAK,GAAG,iBAAiB,EACzB,MAAM,GACU,KAAI;IACpB,MAAM,iBAAiB,GAAGA,YAAM,CAAmB,IAAI,GAAG,EAAE,CAAC;AAC7D,IAAA,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAGC,cAAQ,CACnD,IAAI,GAAG,EAAE,CACT;IACD,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGA,cAAQ,CAAgB,IAAI,CAAC;IACrE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;AAE7C,IAAA,MAAM,cAAc,GAAGD,YAAM,CAAuC,IAAI,CAAC;AACzE,IAAA,MAAM,eAAe,GAAGA,YAAM,CAAuC,IAAI,CAAC;AAC1E,IAAA,MAAM,2BAA2B,GAAGA,YAAM,CAAC,KAAK,CAAC;AACjD,IAAA,MAAM,gBAAgB,GAAGA,YAAM,CAAC,KAAK,CAAC;AACtC,IAAA,MAAM,mBAAmB,GAAGA,YAAM,CAAsB,IAAI,CAAC;AAE7D,IAAA,MAAM,iBAAiB,GAAGE,iBAAW,CACpC,CACC,GAAG,CAAC,CAAkC,EACtC,GAAG,CAAC,CAAkC,KACnC;AACH,QAAA,MAAM,QAA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,OAAO,EAAE,wBAAwB,EAAA,QAAA,EAEhC,KAAK,EAAA,EAZD,EAAE,CAaJ;AAEN,oBAAA,CAAC,CACD,CAAA,EAAA,CACa,CAAA,EAAA,CACV;AAER;;;;"}
1
+ {"version":3,"file":"BlogDynamic.js","sources":["../../../src/dynamicComponents/BlogDynamic.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tChildren,\n\tcloneElement,\n\tisValidElement,\n\tuseCallback,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport { useSpring, animated, config } from '@react-spring/web';\n\nimport type { MouseEvent, ReactNode, RefAttributes } from 'react';\nimport type { Thing, WithContext } from 'schema-dts';\n\nimport styles from '../styles/Blog.module.scss';\nimport lockScrollUpdates from '../utils/lockScrollUpdates';\n\ninterface BlogProperties {\n\tchildren: ReactNode;\n\ttitle?: string;\n\tjsonLd?: WithContext<Thing>;\n}\n\nexport interface ForwardedReference {\n\tparentRef: HTMLDivElement;\n\tchildRefs: HTMLDivElement[];\n}\n\ninterface SectionReferenceValue {\n\tel: HTMLElement;\n\ttitle: string;\n\tisSubSection: boolean;\n}\n\ntype SectionReference = Map<string, SectionReferenceValue>;\n\ninterface CategoryTitleValue extends SectionReferenceValue {\n\tlastUpdatedAt: number;\n}\n\ntype CategoryTitle = Map<string, CategoryTitleValue>;\n\nconst Blog = ({\n\tchildren,\n\ttitle = 'In this article',\n\tjsonLd,\n}: BlogProperties) => {\n\tconst sectionReferences = useRef<SectionReference>(new Map());\n\tconst [categoryTitles, setCategoryTitles] = useState<CategoryTitle>(\n\t\tnew Map()\n\t);\n\tconst [visibleTitle, setVisibleTitle] = useState<string | null>(null);\n\tconst [showTOC, setShowTOC] = useState(false);\n\n\tconst updateTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\tconst showTOCTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\tconst isClickScrolling = useRef(false);\n\tconst scrollEndHandlerRef = useRef<(() => void) | null>(null);\n\tconst intersectionObserversRef = useRef<Map<string, IntersectionObserver>>(\n\t\tnew Map()\n\t);\n\n\tconst sortByDomPosition = useCallback(\n\t\t(\n\t\t\t[, a]: [string, SectionReferenceValue],\n\t\t\t[, b]: [string, SectionReferenceValue]\n\t\t) => {\n\t\t\tconst position = a.el.compareDocumentPosition(b.el);\n\t\t\tif (position & Node.DOCUMENT_POSITION_FOLLOWING) {\n\t\t\t\treturn -1; // a comes before b\n\t\t\t} else if (position & Node.DOCUMENT_POSITION_PRECEDING) {\n\t\t\t\treturn 1; // b comes before a\n\t\t\t}\n\t\t\treturn 0;\n\t\t},\n\t\t[]\n\t);\n\n\tconst updateCategoryTitles = useCallback(() => {\n\t\tconst now = Date.now();\n\t\tconst newCategoryTitles = new Map<string, CategoryTitleValue>();\n\n\t\t// Sort sections by their DOM position to maintain correct order\n\t\tconst sectionsArray = Array.from(sectionReferences.current.entries());\n\t\tsectionsArray.sort(sortByDomPosition);\n\n\t\tlet firstSectionId: string | null = null;\n\t\tfor (const [id, { title, el, isSubSection }] of sectionsArray) {\n\t\t\tif (!firstSectionId) {\n\t\t\t\tfirstSectionId = id;\n\t\t\t}\n\t\t\tnewCategoryTitles.set(id, {\n\t\t\t\tel,\n\t\t\t\ttitle,\n\t\t\t\tlastUpdatedAt: now,\n\t\t\t\tisSubSection,\n\t\t\t});\n\t\t}\n\n\t\tif (newCategoryTitles.size === 0) return;\n\n\t\tsetCategoryTitles(newCategoryTitles);\n\t\tif (!showTOC) setShowTOC(true);\n\n\t\tif (visibleTitle) return;\n\t\tsetVisibleTitle(firstSectionId);\n\t}, [visibleTitle, sortByDomPosition, showTOC, setShowTOC]);\n\n\tconst debounceUpdateCategoryTitles = useCallback(() => {\n\t\t// Clear existing timer and set a new one to batch updates\n\t\tif (updateTimerRef.current) {\n\t\t\tclearTimeout(updateTimerRef.current);\n\t\t}\n\t\tupdateTimerRef.current = setTimeout(() => {\n\t\t\tupdateCategoryTitles();\n\t\t}, 200);\n\t}, [updateCategoryTitles]);\n\n\tuseEffect(() => {\n\t\tfor (const [id, { el }] of categoryTitles) {\n\t\t\tconst observer = new IntersectionObserver(\n\t\t\t\t([entry]) => {\n\t\t\t\t\tif (!entry.isIntersecting) return;\n\t\t\t\t\tif (isClickScrolling.current) return;\n\t\t\t\t\tif (document.body.scrollTop === 0) return;\n\t\t\t\t\tsetVisibleTitle(visibleId => {\n\t\t\t\t\t\tif (visibleId === id && !entry.isIntersecting) return null;\n\t\t\t\t\t\tif (entry.isIntersecting) return id;\n\t\t\t\t\t\treturn visibleId;\n\t\t\t\t\t});\n\t\t\t\t\tconst url = new URL(window.location.href);\n\t\t\t\t\turl.searchParams.set('section', id);\n\t\t\t\t\twindow.history.replaceState({}, '', url.toString());\n\t\t\t\t},\n\t\t\t\t{ threshold: 0.1 }\n\t\t\t);\n\t\t\tintersectionObserversRef.current.set(id, observer);\n\t\t\tobserver.observe(el as HTMLElement);\n\t\t}\n\t}, [categoryTitles.size]);\n\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\tif (updateTimerRef.current) {\n\t\t\t\tclearTimeout(updateTimerRef.current);\n\t\t\t}\n\t\t\tif (showTOCTimerRef.current) {\n\t\t\t\tclearTimeout(showTOCTimerRef.current);\n\t\t\t}\n\t\t\tif (scrollEndHandlerRef.current) {\n\t\t\t\tdocument.body.removeEventListener(\n\t\t\t\t\t'scrollend',\n\t\t\t\t\tscrollEndHandlerRef.current\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (intersectionObserversRef.current) {\n\t\t\t\tfor (const observer of intersectionObserversRef.current.values()) {\n\t\t\t\t\tobserver.disconnect();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}, []);\n\n\tconst getSectionFromUrl = () => {\n\t\tconst url = new URL(window.location.href);\n\t\tconst section = url.searchParams.get('section');\n\t\tif (!section) return null;\n\t\treturn section;\n\t};\n\n\tconst updateUrl = (id: string) => {\n\t\tconst url = new URL(window.location.href);\n\t\turl.searchParams.set('section', id);\n\t\twindow.history.replaceState({}, '', url.toString());\n\t};\n\n\tconst scrollIntoView = (element: HTMLElement) => {\n\t\tif (!element) return;\n\t\tconst top =\n\t\t\telement.getBoundingClientRect().top + document.body.scrollTop - 100;\n\t\tdocument.body.scrollTo({ top, behavior: 'smooth' });\n\t};\n\n\t// On initial load, scroll to section specified in URL\n\tuseEffect(() => {\n\t\tif (categoryTitles.size === 0) return;\n\t\tconst section = getSectionFromUrl();\n\t\tif (!section) {\n\t\t\treturn;\n\t\t}\n\t\tconst entry = categoryTitles.get(section);\n\t\tif (!entry) {\n\t\t\treturn;\n\t\t}\n\t\tscrollIntoView(entry.el);\n\t\tlockScrollUpdates(\n\t\t\tsection,\n\t\t\tisClickScrolling,\n\t\t\tscrollEndHandlerRef,\n\t\t\tsetVisibleTitle\n\t\t);\n\t}, [categoryTitles.size]);\n\n\tconst handleSectionReference = useCallback(\n\t\t(element: ForwardedReference) => {\n\t\t\tif (!element) return;\n\t\t\tconst { parentRef, childRefs } = element;\n\n\t\t\t// Add parent section reference\n\t\t\tif (parentRef) {\n\t\t\t\tconst id = parentRef.dataset.id;\n\t\t\t\tconst title = parentRef.dataset.title;\n\t\t\t\tif (id && title) {\n\t\t\t\t\tsectionReferences.current.set(id, {\n\t\t\t\t\t\tel: parentRef,\n\t\t\t\t\t\ttitle,\n\t\t\t\t\t\tisSubSection: false,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add child section references\n\t\t\tif (Array.isArray(childRefs)) {\n\t\t\t\tfor (const childRef of childRefs) {\n\t\t\t\t\tif (!childRef) continue;\n\t\t\t\t\tconst id = childRef.dataset.id;\n\t\t\t\t\tconst title = childRef.dataset.title;\n\t\t\t\t\tif (id && title) {\n\t\t\t\t\t\tsectionReferences.current.set(id, {\n\t\t\t\t\t\t\tel: childRef,\n\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\tisSubSection: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdebounceUpdateCategoryTitles();\n\t\t},\n\t\t[debounceUpdateCategoryTitles]\n\t);\n\n\tconst handleClickCategoryTitle = (\n\t\terror: MouseEvent<HTMLParagraphElement>\n\t) => {\n\t\tconst id = error.currentTarget.dataset.id;\n\t\tconst index = error.currentTarget.dataset.idx;\n\t\tif (!id || !index) return;\n\n\t\tconst { el } = categoryTitles.get(id) || {};\n\t\tif (!el) return;\n\n\t\tupdateUrl(id);\n\n\t\tscrollIntoView(el);\n\n\t\tlockScrollUpdates(\n\t\t\tid,\n\t\t\tisClickScrolling,\n\t\t\tscrollEndHandlerRef,\n\t\t\tsetVisibleTitle\n\t\t);\n\t};\n\n\tconst sidebarStyle = useSpring({\n\t\topacity: showTOC ? 1 : 0,\n\t\ttransform: showTOC ? 'translateX(0)' : 'translateX(40px)',\n\t\tconfig: config.gentle,\n\t});\n\n\treturn (\n\t\t<div className={styles.blog}>\n\t\t\t{jsonLd && (\n\t\t\t\t<script\n\t\t\t\t\ttype=\"application/ld+json\"\n\t\t\t\t\tdangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t<div className={styles['blog__content']}>\n\t\t\t\t{Children.map(children, child => {\n\t\t\t\t\tif (!isValidElement(child)) return child;\n\t\t\t\t\treturn cloneElement(child, {\n\t\t\t\t\t\tref: handleSectionReference,\n\t\t\t\t\t} as RefAttributes<ForwardedReference>);\n\t\t\t\t})}\n\t\t\t</div>\n\t\t\t<animated.div className={styles['blog__sidebar']} style={sidebarStyle}>\n\t\t\t\t<p\n\t\t\t\t\tclassName={`${styles['margin-bottom--3']} ${styles['category__header']}`}\n\t\t\t\t>\n\t\t\t\t\t{title}\n\t\t\t\t</p>\n\t\t\t\t{[...categoryTitles].map(\n\t\t\t\t\t([id, { title, isSubSection }], index, array) => {\n\t\t\t\t\t\tconst isNextSectionSubSection = array[index + 1]?.[1]?.isSubSection;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\tkey={id}\n\t\t\t\t\t\t\t\tdata-idx={index}\n\t\t\t\t\t\t\t\tdata-id={id}\n\t\t\t\t\t\t\t\tclassName={`${styles['category__title']} ${\n\t\t\t\t\t\t\t\t\tid === visibleTitle ? styles['category__title--active'] : ''\n\t\t\t\t\t\t\t\t} ${isSubSection ? styles['category__title--sub'] : ''} ${\n\t\t\t\t\t\t\t\t\tisSubSection && !isNextSectionSubSection\n\t\t\t\t\t\t\t\t\t\t? styles['margin-bottom-imp--2']\n\t\t\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t\t}`}\n\t\t\t\t\t\t\t\tonClick={handleClickCategoryTitle}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{title}\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t)}\n\t\t\t</animated.div>\n\t\t</div>\n\t);\n};\n\nexport default Blog;\n"],"names":["useRef","useState","useCallback","useEffect","lockScrollUpdates","useSpring","config","_jsxs","styles","_jsx","Children","isValidElement","cloneElement","animated"],"mappings":";;;;;;;;;;AA4CA,MAAM,IAAI,GAAG,CAAC,EACb,QAAQ,EACR,KAAK,GAAG,iBAAiB,EACzB,MAAM,GACU,KAAI;IACpB,MAAM,iBAAiB,GAAGA,YAAM,CAAmB,IAAI,GAAG,EAAE,CAAC;AAC7D,IAAA,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAGC,cAAQ,CACnD,IAAI,GAAG,EAAE,CACT;IACD,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGA,cAAQ,CAAgB,IAAI,CAAC;IACrE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;AAE7C,IAAA,MAAM,cAAc,GAAGD,YAAM,CAAuC,IAAI,CAAC;AACzE,IAAA,MAAM,eAAe,GAAGA,YAAM,CAAuC,IAAI,CAAC;AAC1E,IAAA,MAAM,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AA,EAAGD,mBAAM,CAAC,kBAAkB,CAAC,CAAA,CAAA,EAAIA,mBAAM,CAAC,kBAAkB,CAAC,CAAA,CAAE,EAAA,QAAA,EAEvE,KAAK,EAAA,CACH,EACH,CAAC,GAAG,cAAc,CAAC,CAAC,GAAG,CACvB,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,KAAI;AAC/C,wBAAA,MAAM,uBAAuB,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY;wBACnE,QACCC,kCAEW,KAAK,EAAA,SAAA,EACN,EAAE,EACX,SAAS,EAAE,CAAA,EAAGD,mBAAM,CAAC,iBAAiB,CAAC,IACtC,EAAE,KAAK,YAAY,GAAGA,mBAAM,CAAC,yBAAyB,CAAC,GAAG,EAC3D,IAAI,YAAY,GAAGA,mBAAM,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAA,CAAA,EACrD,YAAY,IAAI,CAAC;AAChB,kCAAEA,mBAAM,CAAC,sBAAsB;AAC/B,kCAAE,EACJ,CAAA,CAAE,EACF,OAAO,EAAE,wBAAwB,EAAA,QAAA,EAEhC,KAAK,EAAA,EAZD,EAAE,CAaJ;AAEN,oBAAA,CAAC,CACD,CAAA,EAAA,CACa,CAAA,EAAA,CACV;AAER;;;;"}
@@ -12,9 +12,9 @@ const Blog = ({ children, title = 'In this article', jsonLd, }) => {
12
12
  const [showTOC, setShowTOC] = useState(false);
13
13
  const updateTimerRef = useRef(null);
14
14
  const showTOCTimerRef = useRef(null);
15
- const hasScrolledToInitialSection = useRef(false);
16
15
  const isClickScrolling = useRef(false);
17
16
  const scrollEndHandlerRef = useRef(null);
17
+ const intersectionObserversRef = useRef(new Map());
18
18
  const sortByDomPosition = useCallback(([, a], [, b]) => {
19
19
  const position = a.el.compareDocumentPosition(b.el);
20
20
  if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
@@ -62,13 +62,14 @@ const Blog = ({ children, title = 'In this article', jsonLd, }) => {
62
62
  }, 200);
63
63
  }, [updateCategoryTitles]);
64
64
  useEffect(() => {
65
- const observers = new Map();
66
65
  for (const [id, { el }] of categoryTitles) {
67
66
  const observer = new IntersectionObserver(([entry]) => {
68
67
  if (!entry.isIntersecting)
69
68
  return;
70
69
  if (isClickScrolling.current)
71
70
  return;
71
+ if (document.body.scrollTop === 0)
72
+ return;
72
73
  setVisibleTitle(visibleId => {
73
74
  if (visibleId === id && !entry.isIntersecting)
74
75
  return null;
@@ -76,15 +77,13 @@ const Blog = ({ children, title = 'In this article', jsonLd, }) => {
76
77
  return id;
77
78
  return visibleId;
78
79
  });
80
+ const url = new URL(window.location.href);
81
+ url.searchParams.set('section', id);
82
+ window.history.replaceState({}, '', url.toString());
79
83
  }, { threshold: 0.1 });
80
- observers.set(id, observer);
84
+ intersectionObserversRef.current.set(id, observer);
81
85
  observer.observe(el);
82
86
  }
83
- return () => {
84
- for (const observer of observers.values()) {
85
- observer.disconnect();
86
- }
87
- };
88
87
  }, [categoryTitles.size]);
89
88
  useEffect(() => {
90
89
  return () => {
@@ -97,26 +96,46 @@ const Blog = ({ children, title = 'In this article', jsonLd, }) => {
97
96
  if (scrollEndHandlerRef.current) {
98
97
  document.body.removeEventListener('scrollend', scrollEndHandlerRef.current);
99
98
  }
99
+ if (intersectionObserversRef.current) {
100
+ for (const observer of intersectionObserversRef.current.values()) {
101
+ observer.disconnect();
102
+ }
103
+ }
100
104
  };
101
105
  }, []);
106
+ const getSectionFromUrl = () => {
107
+ const url = new URL(window.location.href);
108
+ const section = url.searchParams.get('section');
109
+ if (!section)
110
+ return null;
111
+ return section;
112
+ };
113
+ const updateUrl = (id) => {
114
+ const url = new URL(window.location.href);
115
+ url.searchParams.set('section', id);
116
+ window.history.replaceState({}, '', url.toString());
117
+ };
118
+ const scrollIntoView = (element) => {
119
+ if (!element)
120
+ return;
121
+ const top = element.getBoundingClientRect().top + document.body.scrollTop - 100;
122
+ document.body.scrollTo({ top, behavior: 'smooth' });
123
+ };
102
124
  // On initial load, scroll to section specified in URL
103
125
  useEffect(() => {
104
- if (hasScrolledToInitialSection.current)
105
- return;
106
126
  if (categoryTitles.size === 0)
107
127
  return;
108
- const url = new URL(window.location.href);
109
- const section = url.searchParams.get('section');
110
- if (!section)
128
+ const section = getSectionFromUrl();
129
+ if (!section) {
111
130
  return;
131
+ }
112
132
  const entry = categoryTitles.get(section);
113
- if (!entry)
133
+ if (!entry) {
114
134
  return;
115
- hasScrolledToInitialSection.current = true;
116
- const top = entry.el.getBoundingClientRect().top + document.body.scrollTop - 100;
117
- document.body.scrollTo({ top, behavior: 'smooth' });
135
+ }
136
+ scrollIntoView(entry.el);
118
137
  lockScrollUpdates(section, isClickScrolling, scrollEndHandlerRef, setVisibleTitle);
119
- }, [categoryTitles]);
138
+ }, [categoryTitles.size]);
120
139
  const handleSectionReference = useCallback((element) => {
121
140
  if (!element)
122
141
  return;
@@ -159,14 +178,8 @@ const Blog = ({ children, title = 'In this article', jsonLd, }) => {
159
178
  const { el } = categoryTitles.get(id) || {};
160
179
  if (!el)
161
180
  return;
162
- const top = el.getBoundingClientRect().top + document.body.scrollTop - 100;
163
- const url = new URL(window.location.href);
164
- url.searchParams.set('section', id);
165
- window.history.replaceState({}, '', url.toString());
166
- document.body.scrollTo({
167
- top,
168
- behavior: 'smooth',
169
- });
181
+ updateUrl(id);
182
+ scrollIntoView(el);
170
183
  lockScrollUpdates(id, isClickScrolling, scrollEndHandlerRef, setVisibleTitle);
171
184
  };
172
185
  const sidebarStyle = useSpring({
@@ -1 +1 @@
1
- {"version":3,"file":"BlogDynamic.js","sources":["../../../src/dynamicComponents/BlogDynamic.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tChildren,\n\tcloneElement,\n\tisValidElement,\n\tuseCallback,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport { useSpring, animated, config } from '@react-spring/web';\n\nimport type { MouseEvent, ReactNode, RefAttributes } from 'react';\nimport type { Thing, WithContext } from 'schema-dts';\n\nimport styles from '../styles/Blog.module.scss';\nimport lockScrollUpdates from '../utils/lockScrollUpdates';\n\ninterface BlogProperties {\n\tchildren: ReactNode;\n\ttitle?: string;\n\tjsonLd?: WithContext<Thing>;\n}\n\nexport interface ForwardedReference {\n\tparentRef: HTMLDivElement;\n\tchildRefs: HTMLDivElement[];\n}\n\ninterface SectionReferenceValue {\n\tel: HTMLElement;\n\ttitle: string;\n\tisSubSection: boolean;\n}\n\ntype SectionReference = Map<string, SectionReferenceValue>;\n\ninterface CategoryTitleValue extends SectionReferenceValue {\n\tlastUpdatedAt: number;\n}\n\ntype CategoryTitle = Map<string, CategoryTitleValue>;\n\nconst Blog = ({\n\tchildren,\n\ttitle = 'In this article',\n\tjsonLd,\n}: BlogProperties) => {\n\tconst sectionReferences = useRef<SectionReference>(new Map());\n\tconst [categoryTitles, setCategoryTitles] = useState<CategoryTitle>(\n\t\tnew Map()\n\t);\n\tconst [visibleTitle, setVisibleTitle] = useState<string | null>(null);\n\tconst [showTOC, setShowTOC] = useState(false);\n\n\tconst updateTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\tconst showTOCTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\tconst hasScrolledToInitialSection = useRef(false);\n\tconst isClickScrolling = useRef(false);\n\tconst scrollEndHandlerRef = useRef<(() => void) | null>(null);\n\n\tconst sortByDomPosition = useCallback(\n\t\t(\n\t\t\t[, a]: [string, SectionReferenceValue],\n\t\t\t[, b]: [string, SectionReferenceValue]\n\t\t) => {\n\t\t\tconst position = a.el.compareDocumentPosition(b.el);\n\t\t\tif (position & Node.DOCUMENT_POSITION_FOLLOWING) {\n\t\t\t\treturn -1; // a comes before b\n\t\t\t} else if (position & Node.DOCUMENT_POSITION_PRECEDING) {\n\t\t\t\treturn 1; // b comes before a\n\t\t\t}\n\t\t\treturn 0;\n\t\t},\n\t\t[]\n\t);\n\n\tconst updateCategoryTitles = useCallback(() => {\n\t\tconst now = Date.now();\n\t\tconst newCategoryTitles = new Map<string, CategoryTitleValue>();\n\n\t\t// Sort sections by their DOM position to maintain correct order\n\t\tconst sectionsArray = Array.from(sectionReferences.current.entries());\n\t\tsectionsArray.sort(sortByDomPosition);\n\n\t\tlet firstSectionId: string | null = null;\n\t\tfor (const [id, { title, el, isSubSection }] of sectionsArray) {\n\t\t\tif (!firstSectionId) {\n\t\t\t\tfirstSectionId = id;\n\t\t\t}\n\t\t\tnewCategoryTitles.set(id, {\n\t\t\t\tel,\n\t\t\t\ttitle,\n\t\t\t\tlastUpdatedAt: now,\n\t\t\t\tisSubSection,\n\t\t\t});\n\t\t}\n\n\t\tif (newCategoryTitles.size === 0) return;\n\n\t\tsetCategoryTitles(newCategoryTitles);\n\t\tif (!showTOC) setShowTOC(true);\n\n\t\tif (visibleTitle) return;\n\t\tsetVisibleTitle(firstSectionId);\n\t}, [visibleTitle, sortByDomPosition, showTOC, setShowTOC]);\n\n\tconst debounceUpdateCategoryTitles = useCallback(() => {\n\t\t// Clear existing timer and set a new one to batch updates\n\t\tif (updateTimerRef.current) {\n\t\t\tclearTimeout(updateTimerRef.current);\n\t\t}\n\t\tupdateTimerRef.current = setTimeout(() => {\n\t\t\tupdateCategoryTitles();\n\t\t}, 200);\n\t}, [updateCategoryTitles]);\n\n\tuseEffect(() => {\n\t\tconst observers = new Map<string, IntersectionObserver>();\n\t\tfor (const [id, { el }] of categoryTitles) {\n\t\t\tconst observer = new IntersectionObserver(\n\t\t\t\t([entry]) => {\n\t\t\t\t\tif (!entry.isIntersecting) return;\n\t\t\t\t\tif (isClickScrolling.current) return;\n\t\t\t\t\tsetVisibleTitle(visibleId => {\n\t\t\t\t\t\tif (visibleId === id && !entry.isIntersecting) return null;\n\t\t\t\t\t\tif (entry.isIntersecting) return id;\n\t\t\t\t\t\treturn visibleId;\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t{ threshold: 0.1 }\n\t\t\t);\n\t\t\tobservers.set(id, observer);\n\t\t\tobserver.observe(el);\n\t\t}\n\t\treturn () => {\n\t\t\tfor (const observer of observers.values()) {\n\t\t\t\tobserver.disconnect();\n\t\t\t}\n\t\t};\n\t}, [categoryTitles.size]);\n\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\tif (updateTimerRef.current) {\n\t\t\t\tclearTimeout(updateTimerRef.current);\n\t\t\t}\n\t\t\tif (showTOCTimerRef.current) {\n\t\t\t\tclearTimeout(showTOCTimerRef.current);\n\t\t\t}\n\t\t\tif (scrollEndHandlerRef.current) {\n\t\t\t\tdocument.body.removeEventListener('scrollend', scrollEndHandlerRef.current);\n\t\t\t}\n\t\t};\n\t}, []);\n\n\t// On initial load, scroll to section specified in URL\n\tuseEffect(() => {\n\t\tif (hasScrolledToInitialSection.current) return;\n\t\tif (categoryTitles.size === 0) return;\n\t\tconst url = new URL(window.location.href);\n\t\tconst section = url.searchParams.get('section');\n\t\tif (!section) return;\n\t\tconst entry = categoryTitles.get(section);\n\t\tif (!entry) return;\n\t\thasScrolledToInitialSection.current = true;\n\t\tconst top =\n\t\t\tentry.el.getBoundingClientRect().top + document.body.scrollTop - 100;\n\t\tdocument.body.scrollTo({ top, behavior: 'smooth' });\n\t\tlockScrollUpdates(section, isClickScrolling, scrollEndHandlerRef, setVisibleTitle);\n\t}, [categoryTitles]);\n\n\tconst handleSectionReference = useCallback(\n\t\t(element: ForwardedReference) => {\n\t\t\tif (!element) return;\n\t\t\tconst { parentRef, childRefs } = element;\n\n\t\t\t// Add parent section reference\n\t\t\tif (parentRef) {\n\t\t\t\tconst id = parentRef.dataset.id;\n\t\t\t\tconst title = parentRef.dataset.title;\n\t\t\t\tif (id && title) {\n\t\t\t\t\tsectionReferences.current.set(id, {\n\t\t\t\t\t\tel: parentRef,\n\t\t\t\t\t\ttitle,\n\t\t\t\t\t\tisSubSection: false,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add child section references\n\t\t\tif (Array.isArray(childRefs)) {\n\t\t\t\tfor (const childRef of childRefs) {\n\t\t\t\t\tif (!childRef) continue;\n\t\t\t\t\tconst id = childRef.dataset.id;\n\t\t\t\t\tconst title = childRef.dataset.title;\n\t\t\t\t\tif (id && title) {\n\t\t\t\t\t\tsectionReferences.current.set(id, {\n\t\t\t\t\t\t\tel: childRef,\n\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\tisSubSection: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdebounceUpdateCategoryTitles();\n\t\t},\n\t\t[debounceUpdateCategoryTitles]\n\t);\n\n\tconst handleClickCategoryTitle = (\n\t\terror: MouseEvent<HTMLParagraphElement>\n\t) => {\n\t\tconst id = error.currentTarget.dataset.id;\n\t\tconst index = error.currentTarget.dataset.idx;\n\t\tif (!id || !index) return;\n\n\t\tconst { el } = categoryTitles.get(id) || {};\n\t\tif (!el) return;\n\n\t\tconst top = el.getBoundingClientRect().top + document.body.scrollTop - 100;\n\n\t\tconst url = new URL(window.location.href);\n\t\turl.searchParams.set('section', id);\n\t\twindow.history.replaceState({}, '', url.toString());\n\n\t\tdocument.body.scrollTo({\n\t\t\ttop,\n\t\t\tbehavior: 'smooth',\n\t\t});\n\n\t\tlockScrollUpdates(id, isClickScrolling, scrollEndHandlerRef, setVisibleTitle);\n\t};\n\n\tconst sidebarStyle = useSpring({\n\t\topacity: showTOC ? 1 : 0,\n\t\ttransform: showTOC ? 'translateX(0)' : 'translateX(40px)',\n\t\tconfig: config.gentle,\n\t});\n\n\treturn (\n\t\t<div className={styles.blog}>\n\t\t\t{jsonLd && (\n\t\t\t\t<script\n\t\t\t\t\ttype=\"application/ld+json\"\n\t\t\t\t\tdangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t<div className={styles['blog__content']}>\n\t\t\t\t{Children.map(children, child => {\n\t\t\t\t\tif (!isValidElement(child)) return child;\n\t\t\t\t\treturn cloneElement(child, {\n\t\t\t\t\t\tref: handleSectionReference,\n\t\t\t\t\t} as RefAttributes<ForwardedReference>);\n\t\t\t\t})}\n\t\t\t</div>\n\t\t\t<animated.div className={styles['blog__sidebar']} style={sidebarStyle}>\n\t\t\t\t<p\n\t\t\t\t\tclassName={`${styles['margin-bottom--3']} ${styles['category__header']}`}\n\t\t\t\t>\n\t\t\t\t\t{title}\n\t\t\t\t</p>\n\t\t\t\t{[...categoryTitles].map(\n\t\t\t\t\t([id, { title, isSubSection }], index, array) => {\n\t\t\t\t\t\tconst isNextSectionSubSection = array[index + 1]?.[1]?.isSubSection;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\tkey={id}\n\t\t\t\t\t\t\t\tdata-idx={index}\n\t\t\t\t\t\t\t\tdata-id={id}\n\t\t\t\t\t\t\t\tclassName={`${styles['category__title']} ${\n\t\t\t\t\t\t\t\t\tid === visibleTitle ? styles['category__title--active'] : ''\n\t\t\t\t\t\t\t\t} ${isSubSection ? styles['category__title--sub'] : ''} ${\n\t\t\t\t\t\t\t\t\tisSubSection && !isNextSectionSubSection\n\t\t\t\t\t\t\t\t\t\t? styles['margin-bottom-imp--2']\n\t\t\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t\t}`}\n\t\t\t\t\t\t\t\tonClick={handleClickCategoryTitle}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{title}\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t)}\n\t\t\t</animated.div>\n\t\t</div>\n\t);\n};\n\nexport default Blog;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;AA4CA,MAAM,IAAI,GAAG,CAAC,EACb,QAAQ,EACR,KAAK,GAAG,iBAAiB,EACzB,MAAM,GACU,KAAI;IACpB,MAAM,iBAAiB,GAAG,MAAM,CAAmB,IAAI,GAAG,EAAE,CAAC;AAC7D,IAAA,MAAM,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AA,CACH,EACH,CAAC,GAAG,cAAc,CAAC,CAAC,GAAG,CACvB,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,KAAI;AAC/C,wBAAA,MAAM,uBAAuB,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY;wBACnE,QACCA,uBAEW,KAAK,EAAA,SAAA,EACN,EAAE,EACX,SAAS,EAAE,CAAA,EAAG,MAAM,CAAC,iBAAiB,CAAC,IACtC,EAAE,KAAK,YAAY,GAAG,MAAM,CAAC,yBAAyB,CAAC,GAAG,EAC3D,IAAI,YAAY,GAAG,MAAM,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAA,CAAA,EACrD,YAAY,IAAI,CAAC;AAChB,kCAAE,MAAM,CAAC,sBAAsB;AAC/B,kCAAE,EACJ,CAAA,CAAE,EACF,OAAO,EAAE,wBAAwB,EAAA,QAAA,EAEhC,KAAK,EAAA,EAZD,EAAE,CAaJ;AAEN,oBAAA,CAAC,CACD,CAAA,EAAA,CACa,CAAA,EAAA,CACV;AAER;;;;"}
1
+ {"version":3,"file":"BlogDynamic.js","sources":["../../../src/dynamicComponents/BlogDynamic.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tChildren,\n\tcloneElement,\n\tisValidElement,\n\tuseCallback,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport { useSpring, animated, config } from '@react-spring/web';\n\nimport type { MouseEvent, ReactNode, RefAttributes } from 'react';\nimport type { Thing, WithContext } from 'schema-dts';\n\nimport styles from '../styles/Blog.module.scss';\nimport lockScrollUpdates from '../utils/lockScrollUpdates';\n\ninterface BlogProperties {\n\tchildren: ReactNode;\n\ttitle?: string;\n\tjsonLd?: WithContext<Thing>;\n}\n\nexport interface ForwardedReference {\n\tparentRef: HTMLDivElement;\n\tchildRefs: HTMLDivElement[];\n}\n\ninterface SectionReferenceValue {\n\tel: HTMLElement;\n\ttitle: string;\n\tisSubSection: boolean;\n}\n\ntype SectionReference = Map<string, SectionReferenceValue>;\n\ninterface CategoryTitleValue extends SectionReferenceValue {\n\tlastUpdatedAt: number;\n}\n\ntype CategoryTitle = Map<string, CategoryTitleValue>;\n\nconst Blog = ({\n\tchildren,\n\ttitle = 'In this article',\n\tjsonLd,\n}: BlogProperties) => {\n\tconst sectionReferences = useRef<SectionReference>(new Map());\n\tconst [categoryTitles, setCategoryTitles] = useState<CategoryTitle>(\n\t\tnew Map()\n\t);\n\tconst [visibleTitle, setVisibleTitle] = useState<string | null>(null);\n\tconst [showTOC, setShowTOC] = useState(false);\n\n\tconst updateTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\tconst showTOCTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\tconst isClickScrolling = useRef(false);\n\tconst scrollEndHandlerRef = useRef<(() => void) | null>(null);\n\tconst intersectionObserversRef = useRef<Map<string, IntersectionObserver>>(\n\t\tnew Map()\n\t);\n\n\tconst sortByDomPosition = useCallback(\n\t\t(\n\t\t\t[, a]: [string, SectionReferenceValue],\n\t\t\t[, b]: [string, SectionReferenceValue]\n\t\t) => {\n\t\t\tconst position = a.el.compareDocumentPosition(b.el);\n\t\t\tif (position & Node.DOCUMENT_POSITION_FOLLOWING) {\n\t\t\t\treturn -1; // a comes before b\n\t\t\t} else if (position & Node.DOCUMENT_POSITION_PRECEDING) {\n\t\t\t\treturn 1; // b comes before a\n\t\t\t}\n\t\t\treturn 0;\n\t\t},\n\t\t[]\n\t);\n\n\tconst updateCategoryTitles = useCallback(() => {\n\t\tconst now = Date.now();\n\t\tconst newCategoryTitles = new Map<string, CategoryTitleValue>();\n\n\t\t// Sort sections by their DOM position to maintain correct order\n\t\tconst sectionsArray = Array.from(sectionReferences.current.entries());\n\t\tsectionsArray.sort(sortByDomPosition);\n\n\t\tlet firstSectionId: string | null = null;\n\t\tfor (const [id, { title, el, isSubSection }] of sectionsArray) {\n\t\t\tif (!firstSectionId) {\n\t\t\t\tfirstSectionId = id;\n\t\t\t}\n\t\t\tnewCategoryTitles.set(id, {\n\t\t\t\tel,\n\t\t\t\ttitle,\n\t\t\t\tlastUpdatedAt: now,\n\t\t\t\tisSubSection,\n\t\t\t});\n\t\t}\n\n\t\tif (newCategoryTitles.size === 0) return;\n\n\t\tsetCategoryTitles(newCategoryTitles);\n\t\tif (!showTOC) setShowTOC(true);\n\n\t\tif (visibleTitle) return;\n\t\tsetVisibleTitle(firstSectionId);\n\t}, [visibleTitle, sortByDomPosition, showTOC, setShowTOC]);\n\n\tconst debounceUpdateCategoryTitles = useCallback(() => {\n\t\t// Clear existing timer and set a new one to batch updates\n\t\tif (updateTimerRef.current) {\n\t\t\tclearTimeout(updateTimerRef.current);\n\t\t}\n\t\tupdateTimerRef.current = setTimeout(() => {\n\t\t\tupdateCategoryTitles();\n\t\t}, 200);\n\t}, [updateCategoryTitles]);\n\n\tuseEffect(() => {\n\t\tfor (const [id, { el }] of categoryTitles) {\n\t\t\tconst observer = new IntersectionObserver(\n\t\t\t\t([entry]) => {\n\t\t\t\t\tif (!entry.isIntersecting) return;\n\t\t\t\t\tif (isClickScrolling.current) return;\n\t\t\t\t\tif (document.body.scrollTop === 0) return;\n\t\t\t\t\tsetVisibleTitle(visibleId => {\n\t\t\t\t\t\tif (visibleId === id && !entry.isIntersecting) return null;\n\t\t\t\t\t\tif (entry.isIntersecting) return id;\n\t\t\t\t\t\treturn visibleId;\n\t\t\t\t\t});\n\t\t\t\t\tconst url = new URL(window.location.href);\n\t\t\t\t\turl.searchParams.set('section', id);\n\t\t\t\t\twindow.history.replaceState({}, '', url.toString());\n\t\t\t\t},\n\t\t\t\t{ threshold: 0.1 }\n\t\t\t);\n\t\t\tintersectionObserversRef.current.set(id, observer);\n\t\t\tobserver.observe(el as HTMLElement);\n\t\t}\n\t}, [categoryTitles.size]);\n\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\tif (updateTimerRef.current) {\n\t\t\t\tclearTimeout(updateTimerRef.current);\n\t\t\t}\n\t\t\tif (showTOCTimerRef.current) {\n\t\t\t\tclearTimeout(showTOCTimerRef.current);\n\t\t\t}\n\t\t\tif (scrollEndHandlerRef.current) {\n\t\t\t\tdocument.body.removeEventListener(\n\t\t\t\t\t'scrollend',\n\t\t\t\t\tscrollEndHandlerRef.current\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (intersectionObserversRef.current) {\n\t\t\t\tfor (const observer of intersectionObserversRef.current.values()) {\n\t\t\t\t\tobserver.disconnect();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}, []);\n\n\tconst getSectionFromUrl = () => {\n\t\tconst url = new URL(window.location.href);\n\t\tconst section = url.searchParams.get('section');\n\t\tif (!section) return null;\n\t\treturn section;\n\t};\n\n\tconst updateUrl = (id: string) => {\n\t\tconst url = new URL(window.location.href);\n\t\turl.searchParams.set('section', id);\n\t\twindow.history.replaceState({}, '', url.toString());\n\t};\n\n\tconst scrollIntoView = (element: HTMLElement) => {\n\t\tif (!element) return;\n\t\tconst top =\n\t\t\telement.getBoundingClientRect().top + document.body.scrollTop - 100;\n\t\tdocument.body.scrollTo({ top, behavior: 'smooth' });\n\t};\n\n\t// On initial load, scroll to section specified in URL\n\tuseEffect(() => {\n\t\tif (categoryTitles.size === 0) return;\n\t\tconst section = getSectionFromUrl();\n\t\tif (!section) {\n\t\t\treturn;\n\t\t}\n\t\tconst entry = categoryTitles.get(section);\n\t\tif (!entry) {\n\t\t\treturn;\n\t\t}\n\t\tscrollIntoView(entry.el);\n\t\tlockScrollUpdates(\n\t\t\tsection,\n\t\t\tisClickScrolling,\n\t\t\tscrollEndHandlerRef,\n\t\t\tsetVisibleTitle\n\t\t);\n\t}, [categoryTitles.size]);\n\n\tconst handleSectionReference = useCallback(\n\t\t(element: ForwardedReference) => {\n\t\t\tif (!element) return;\n\t\t\tconst { parentRef, childRefs } = element;\n\n\t\t\t// Add parent section reference\n\t\t\tif (parentRef) {\n\t\t\t\tconst id = parentRef.dataset.id;\n\t\t\t\tconst title = parentRef.dataset.title;\n\t\t\t\tif (id && title) {\n\t\t\t\t\tsectionReferences.current.set(id, {\n\t\t\t\t\t\tel: parentRef,\n\t\t\t\t\t\ttitle,\n\t\t\t\t\t\tisSubSection: false,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add child section references\n\t\t\tif (Array.isArray(childRefs)) {\n\t\t\t\tfor (const childRef of childRefs) {\n\t\t\t\t\tif (!childRef) continue;\n\t\t\t\t\tconst id = childRef.dataset.id;\n\t\t\t\t\tconst title = childRef.dataset.title;\n\t\t\t\t\tif (id && title) {\n\t\t\t\t\t\tsectionReferences.current.set(id, {\n\t\t\t\t\t\t\tel: childRef,\n\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\tisSubSection: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdebounceUpdateCategoryTitles();\n\t\t},\n\t\t[debounceUpdateCategoryTitles]\n\t);\n\n\tconst handleClickCategoryTitle = (\n\t\terror: MouseEvent<HTMLParagraphElement>\n\t) => {\n\t\tconst id = error.currentTarget.dataset.id;\n\t\tconst index = error.currentTarget.dataset.idx;\n\t\tif (!id || !index) return;\n\n\t\tconst { el } = categoryTitles.get(id) || {};\n\t\tif (!el) return;\n\n\t\tupdateUrl(id);\n\n\t\tscrollIntoView(el);\n\n\t\tlockScrollUpdates(\n\t\t\tid,\n\t\t\tisClickScrolling,\n\t\t\tscrollEndHandlerRef,\n\t\t\tsetVisibleTitle\n\t\t);\n\t};\n\n\tconst sidebarStyle = useSpring({\n\t\topacity: showTOC ? 1 : 0,\n\t\ttransform: showTOC ? 'translateX(0)' : 'translateX(40px)',\n\t\tconfig: config.gentle,\n\t});\n\n\treturn (\n\t\t<div className={styles.blog}>\n\t\t\t{jsonLd && (\n\t\t\t\t<script\n\t\t\t\t\ttype=\"application/ld+json\"\n\t\t\t\t\tdangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t<div className={styles['blog__content']}>\n\t\t\t\t{Children.map(children, child => {\n\t\t\t\t\tif (!isValidElement(child)) return child;\n\t\t\t\t\treturn cloneElement(child, {\n\t\t\t\t\t\tref: handleSectionReference,\n\t\t\t\t\t} as RefAttributes<ForwardedReference>);\n\t\t\t\t})}\n\t\t\t</div>\n\t\t\t<animated.div className={styles['blog__sidebar']} style={sidebarStyle}>\n\t\t\t\t<p\n\t\t\t\t\tclassName={`${styles['margin-bottom--3']} ${styles['category__header']}`}\n\t\t\t\t>\n\t\t\t\t\t{title}\n\t\t\t\t</p>\n\t\t\t\t{[...categoryTitles].map(\n\t\t\t\t\t([id, { title, isSubSection }], index, array) => {\n\t\t\t\t\t\tconst isNextSectionSubSection = array[index + 1]?.[1]?.isSubSection;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\tkey={id}\n\t\t\t\t\t\t\t\tdata-idx={index}\n\t\t\t\t\t\t\t\tdata-id={id}\n\t\t\t\t\t\t\t\tclassName={`${styles['category__title']} ${\n\t\t\t\t\t\t\t\t\tid === visibleTitle ? styles['category__title--active'] : ''\n\t\t\t\t\t\t\t\t} ${isSubSection ? styles['category__title--sub'] : ''} ${\n\t\t\t\t\t\t\t\t\tisSubSection && !isNextSectionSubSection\n\t\t\t\t\t\t\t\t\t\t? styles['margin-bottom-imp--2']\n\t\t\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t\t}`}\n\t\t\t\t\t\t\t\tonClick={handleClickCategoryTitle}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{title}\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t)}\n\t\t\t</animated.div>\n\t\t</div>\n\t);\n};\n\nexport default Blog;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;AA4CA,MAAM,IAAI,GA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,EAAE,CAaJ;AAEN,oBAAA,CAAC,CACD,CAAA,EAAA,CACa,CAAA,EAAA,CACV;AAER;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"BlogDynamic.d.ts","sourceRoot":"","sources":["../../../src/dynamicComponents/BlogDynamic.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAc,SAAS,EAAiB,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAKrD,UAAU,cAAc;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IAClC,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,EAAE,cAAc,EAAE,CAAC;CAC5B;AAgBD,QAAA,MAAM,IAAI,GAAI,8BAIX,cAAc,4CAiPhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"BlogDynamic.d.ts","sourceRoot":"","sources":["../../../src/dynamicComponents/BlogDynamic.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAc,SAAS,EAAiB,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAKrD,UAAU,cAAc;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IAClC,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,EAAE,cAAc,EAAE,CAAC;CAC5B;AAgBD,QAAA,MAAM,IAAI,GAAI,8BAIX,cAAc,4CAoPhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"BlogSectionDynamic.d.ts","sourceRoot":"","sources":["../../../src/dynamicComponents/BlogSectionDynamic.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAItD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGxD,UAAU,cAAc;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,QAAA,MAAM,WAAW,+FA8DhB,CAAC;AAIF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"BlogSectionDynamic.d.ts","sourceRoot":"","sources":["../../../src/dynamicComponents/BlogSectionDynamic.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAItD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGxD,UAAU,cAAc;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,QAAA,MAAM,WAAW,+FAkEhB,CAAC;AAIF,eAAe,WAAW,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export declare const generateIdForBlogTitle: (title: string) => string;
2
2
  export declare const generateUrlForBlogTitle: (title: string) => string;
3
+ export declare const generateSectionHref: (id: string) => string;
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,GAAI,OAAO,MAAM,WAAiD,CAAC;AAEtG,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,WAAoE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,GAAI,OAAO,MAAM,WAAiD,CAAC;AAEtG,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,WAAoE,CAAC;AAE1H,eAAO,MAAM,mBAAmB,GAAI,IAAI,MAAM,WAAqB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { MutableRefObject } from 'react';
2
+ declare const lockScrollUpdates: (id: string, isClickScrolling: MutableRefObject<boolean>, scrollEndHandlerRef: MutableRefObject<(() => void) | null>, setVisibleTitle: (id: string) => void) => void;
3
+ export default lockScrollUpdates;
4
+ //# sourceMappingURL=lockScrollUpdates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockScrollUpdates.d.ts","sourceRoot":"","sources":["../../../src/utils/lockScrollUpdates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAE9C,QAAA,MAAM,iBAAiB,GACtB,IAAI,MAAM,EACV,kBAAkB,gBAAgB,CAAC,OAAO,CAAC,EAC3C,qBAAqB,gBAAgB,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,EAC1D,iBAAiB,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,SAoBrC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@san-siva/blogkit",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "description": "A reusable blog component library for React/Next.js applications with code highlighting, diagrams, and rich content features",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -56,9 +56,11 @@ const Blog = ({
56
56
 
57
57
  const updateTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
58
58
  const showTOCTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
59
- const hasScrolledToInitialSection = useRef(false);
60
59
  const isClickScrolling = useRef(false);
61
60
  const scrollEndHandlerRef = useRef<(() => void) | null>(null);
61
+ const intersectionObserversRef = useRef<Map<string, IntersectionObserver>>(
62
+ new Map()
63
+ );
62
64
 
63
65
  const sortByDomPosition = useCallback(
64
66
  (
@@ -117,28 +119,26 @@ const Blog = ({
117
119
  }, [updateCategoryTitles]);
118
120
 
119
121
  useEffect(() => {
120
- const observers = new Map<string, IntersectionObserver>();
121
122
  for (const [id, { el }] of categoryTitles) {
122
123
  const observer = new IntersectionObserver(
123
124
  ([entry]) => {
124
125
  if (!entry.isIntersecting) return;
125
126
  if (isClickScrolling.current) return;
127
+ if (document.body.scrollTop === 0) return;
126
128
  setVisibleTitle(visibleId => {
127
129
  if (visibleId === id && !entry.isIntersecting) return null;
128
130
  if (entry.isIntersecting) return id;
129
131
  return visibleId;
130
132
  });
133
+ const url = new URL(window.location.href);
134
+ url.searchParams.set('section', id);
135
+ window.history.replaceState({}, '', url.toString());
131
136
  },
132
137
  { threshold: 0.1 }
133
138
  );
134
- observers.set(id, observer);
135
- observer.observe(el);
139
+ intersectionObserversRef.current.set(id, observer);
140
+ observer.observe(el as HTMLElement);
136
141
  }
137
- return () => {
138
- for (const observer of observers.values()) {
139
- observer.disconnect();
140
- }
141
- };
142
142
  }, [categoryTitles.size]);
143
143
 
144
144
  useEffect(() => {
@@ -150,26 +150,58 @@ const Blog = ({
150
150
  clearTimeout(showTOCTimerRef.current);
151
151
  }
152
152
  if (scrollEndHandlerRef.current) {
153
- document.body.removeEventListener('scrollend', scrollEndHandlerRef.current);
153
+ document.body.removeEventListener(
154
+ 'scrollend',
155
+ scrollEndHandlerRef.current
156
+ );
157
+ }
158
+ if (intersectionObserversRef.current) {
159
+ for (const observer of intersectionObserversRef.current.values()) {
160
+ observer.disconnect();
161
+ }
154
162
  }
155
163
  };
156
164
  }, []);
157
165
 
158
- // On initial load, scroll to section specified in URL
159
- useEffect(() => {
160
- if (hasScrolledToInitialSection.current) return;
161
- if (categoryTitles.size === 0) return;
166
+ const getSectionFromUrl = () => {
162
167
  const url = new URL(window.location.href);
163
168
  const section = url.searchParams.get('section');
164
- if (!section) return;
165
- const entry = categoryTitles.get(section);
166
- if (!entry) return;
167
- hasScrolledToInitialSection.current = true;
169
+ if (!section) return null;
170
+ return section;
171
+ };
172
+
173
+ const updateUrl = (id: string) => {
174
+ const url = new URL(window.location.href);
175
+ url.searchParams.set('section', id);
176
+ window.history.replaceState({}, '', url.toString());
177
+ };
178
+
179
+ const scrollIntoView = (element: HTMLElement) => {
180
+ if (!element) return;
168
181
  const top =
169
- entry.el.getBoundingClientRect().top + document.body.scrollTop - 100;
182
+ element.getBoundingClientRect().top + document.body.scrollTop - 100;
170
183
  document.body.scrollTo({ top, behavior: 'smooth' });
171
- lockScrollUpdates(section, isClickScrolling, scrollEndHandlerRef, setVisibleTitle);
172
- }, [categoryTitles]);
184
+ };
185
+
186
+ // On initial load, scroll to section specified in URL
187
+ useEffect(() => {
188
+ if (categoryTitles.size === 0) return;
189
+ const section = getSectionFromUrl();
190
+ if (!section) {
191
+ return;
192
+ }
193
+ const entry = categoryTitles.get(section);
194
+ if (!entry) {
195
+ return;
196
+ }
197
+ scrollIntoView(entry.el);
198
+ lockScrollUpdates(
199
+ section,
200
+ isClickScrolling,
201
+ scrollEndHandlerRef,
202
+ setVisibleTitle
203
+ );
204
+ }, [categoryTitles.size]);
173
205
 
174
206
  const handleSectionReference = useCallback(
175
207
  (element: ForwardedReference) => {
@@ -220,18 +252,16 @@ const Blog = ({
220
252
  const { el } = categoryTitles.get(id) || {};
221
253
  if (!el) return;
222
254
 
223
- const top = el.getBoundingClientRect().top + document.body.scrollTop - 100;
224
-
225
- const url = new URL(window.location.href);
226
- url.searchParams.set('section', id);
227
- window.history.replaceState({}, '', url.toString());
255
+ updateUrl(id);
228
256
 
229
- document.body.scrollTo({
230
- top,
231
- behavior: 'smooth',
232
- });
257
+ scrollIntoView(el);
233
258
 
234
- lockScrollUpdates(id, isClickScrolling, scrollEndHandlerRef, setVisibleTitle);
259
+ lockScrollUpdates(
260
+ id,
261
+ isClickScrolling,
262
+ scrollEndHandlerRef,
263
+ setVisibleTitle
264
+ );
235
265
  };
236
266
 
237
267
  const sidebarStyle = useSpring({
@@ -1,6 +1,7 @@
1
1
  declare const styles: {
2
2
  readonly 'blog-section': string;
3
3
  readonly 'blog-section__title': string;
4
+ readonly 'blog-section__title-link': string;
4
5
  readonly 'margin-bottom--6': string;
5
6
  readonly 'margin-bottom--9': string;
6
7
  };