@san-siva/blogkit 1.1.24 → 1.1.25
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.
- package/dist/cjs/dynamicComponents/BlogDynamic.js +2 -1
- package/dist/cjs/dynamicComponents/BlogDynamic.js.map +1 -1
- package/dist/esm/dynamicComponents/BlogDynamic.js +2 -1
- package/dist/esm/dynamicComponents/BlogDynamic.js.map +1 -1
- package/dist/types/dynamicComponents/BlogDynamic.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/dynamicComponents/BlogDynamic.tsx +3 -1
|
@@ -11,10 +11,11 @@ var useCategoryTitles = require('../hooks/useCategoryTitles.js');
|
|
|
11
11
|
var useSectionObserver = require('../hooks/useSectionObserver.js');
|
|
12
12
|
var TocNodeStatic = require('../staticComponents/TocNodeStatic.js');
|
|
13
13
|
|
|
14
|
+
const MAX_TOC_DEPTH = 2;
|
|
14
15
|
const buildTocTree = (entries) => {
|
|
15
16
|
const roots = [];
|
|
16
17
|
const stack = [];
|
|
17
|
-
for (const [id, { title, depth }] of entries) {
|
|
18
|
+
for (const [id, { title, depth }] of entries.filter(([, { depth }]) => depth <= MAX_TOC_DEPTH)) {
|
|
18
19
|
const node = { id, title, depth, children: [] };
|
|
19
20
|
while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
|
|
20
21
|
stack.pop();
|
|
@@ -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\tuseState,\n} from 'react';\nimport { useSpring, animated, config } from '@react-spring/web';\n\nimport type { ReactNode, RefAttributes } from 'react';\nimport type { Thing, WithContext } from 'schema-dts';\n\nimport styles from '../styles/Blog.module.scss';\nimport { useCategoryTitles } from '../hooks/useCategoryTitles';\nimport { useSectionObserver } from '../hooks/useSectionObserver';\nimport type { CategoryTitleValue } from '../hooks/useCategoryTitles';\nimport TocNodeStatic from '../staticComponents/TocNodeStatic';\nimport type { TocNode } from '../staticComponents/TocNodeStatic';\n\ninterface BlogProperties {\n\tchildren: ReactNode;\n\ttitle?: string;\n\tjsonLd?: WithContext<Thing>;\n}\n\nexport interface ForwardedReference {\n\tparentRef: HTMLDivElement;\n\tchildRefs: ForwardedReference[];\n}\n\nconst buildTocTree = (entries: [string, CategoryTitleValue][]): TocNode[] => {\n\tconst roots: TocNode[] = [];\n\tconst stack: TocNode[] = [];\n\tfor (const [id, { title, depth }] of entries) {\n\t\tconst node: TocNode = { id, title, depth, children: [] };\n\t\twhile (stack.length > 0 && stack[stack.length - 1].depth >= depth) {\n\t\t\tstack.pop();\n\t\t}\n\t\tif (stack.length === 0) {\n\t\t\troots.push(node);\n\t\t} else {\n\t\t\tstack[stack.length - 1].children.push(node);\n\t\t}\n\t\tstack.push(node);\n\t}\n\treturn roots;\n};\n\nconst Blog = ({\n\tchildren,\n\ttitle = 'In this article',\n\tjsonLd,\n}: BlogProperties) => {\n\tconst [visibleTitle, setVisibleTitle] = useState<string | null>(null);\n\tconst [showTOC, setShowTOC] = useState(false);\n\n\tconst { categoryTitles, handleSectionReference } = useCategoryTitles({\n\t\tvisibleTitle,\n\t\tsetVisibleTitle,\n\t\tsetShowTOC,\n\t});\n\n\tconst { handleClickCategoryTitle } = useSectionObserver({\n\t\tcategoryTitles,\n\t\tsetVisibleTitle,\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{buildTocTree([...categoryTitles]).map((node, i) => (\n\t\t\t\t\t<TocNodeStatic\n\t\t\t\t\t\tkey={node.id}\n\t\t\t\t\t\tnode={node}\n\t\t\t\t\t\tindex={i}\n\t\t\t\t\t\tvisibleTitle={visibleTitle}\n\t\t\t\t\t\tonClick={handleClickCategoryTitle}\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":["useState","useCategoryTitles","useSectionObserver","useSpring","config","_jsxs","styles","_jsx","Children","isValidElement","cloneElement","animated","TocNodeStatic"],"mappings":";;;;;;;;;;;;AA+BA,MAAM,YAAY,GAAG,CAAC,OAAuC,KAAe;IAC3E,MAAM,KAAK,GAAc,EAAE;IAC3B,MAAM,KAAK,GAAc,EAAE;AAC3B,IAAA,KAAK,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,OAAO,EAAE;
|
|
1
|
+
{"version":3,"file":"BlogDynamic.js","sources":["../../../src/dynamicComponents/BlogDynamic.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tChildren,\n\tcloneElement,\n\tisValidElement,\n\tuseState,\n} from 'react';\nimport { useSpring, animated, config } from '@react-spring/web';\n\nimport type { ReactNode, RefAttributes } from 'react';\nimport type { Thing, WithContext } from 'schema-dts';\n\nimport styles from '../styles/Blog.module.scss';\nimport { useCategoryTitles } from '../hooks/useCategoryTitles';\nimport { useSectionObserver } from '../hooks/useSectionObserver';\nimport type { CategoryTitleValue } from '../hooks/useCategoryTitles';\nimport TocNodeStatic from '../staticComponents/TocNodeStatic';\nimport type { TocNode } from '../staticComponents/TocNodeStatic';\n\ninterface BlogProperties {\n\tchildren: ReactNode;\n\ttitle?: string;\n\tjsonLd?: WithContext<Thing>;\n}\n\nexport interface ForwardedReference {\n\tparentRef: HTMLDivElement;\n\tchildRefs: ForwardedReference[];\n}\n\nconst MAX_TOC_DEPTH = 2;\n\nconst buildTocTree = (entries: [string, CategoryTitleValue][]): TocNode[] => {\n\tconst roots: TocNode[] = [];\n\tconst stack: TocNode[] = [];\n\tfor (const [id, { title, depth }] of entries.filter(([, { depth }]) => depth <= MAX_TOC_DEPTH)) {\n\t\tconst node: TocNode = { id, title, depth, children: [] };\n\t\twhile (stack.length > 0 && stack[stack.length - 1].depth >= depth) {\n\t\t\tstack.pop();\n\t\t}\n\t\tif (stack.length === 0) {\n\t\t\troots.push(node);\n\t\t} else {\n\t\t\tstack[stack.length - 1].children.push(node);\n\t\t}\n\t\tstack.push(node);\n\t}\n\treturn roots;\n};\n\nconst Blog = ({\n\tchildren,\n\ttitle = 'In this article',\n\tjsonLd,\n}: BlogProperties) => {\n\tconst [visibleTitle, setVisibleTitle] = useState<string | null>(null);\n\tconst [showTOC, setShowTOC] = useState(false);\n\n\tconst { categoryTitles, handleSectionReference } = useCategoryTitles({\n\t\tvisibleTitle,\n\t\tsetVisibleTitle,\n\t\tsetShowTOC,\n\t});\n\n\tconst { handleClickCategoryTitle } = useSectionObserver({\n\t\tcategoryTitles,\n\t\tsetVisibleTitle,\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{buildTocTree([...categoryTitles]).map((node, i) => (\n\t\t\t\t\t<TocNodeStatic\n\t\t\t\t\t\tkey={node.id}\n\t\t\t\t\t\tnode={node}\n\t\t\t\t\t\tindex={i}\n\t\t\t\t\t\tvisibleTitle={visibleTitle}\n\t\t\t\t\t\tonClick={handleClickCategoryTitle}\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":["useState","useCategoryTitles","useSectionObserver","useSpring","config","_jsxs","styles","_jsx","Children","isValidElement","cloneElement","animated","TocNodeStatic"],"mappings":";;;;;;;;;;;;AA+BA,MAAM,aAAa,GAAG,CAAC;AAEvB,MAAM,YAAY,GAAG,CAAC,OAAuC,KAAe;IAC3E,MAAM,KAAK,GAAc,EAAE;IAC3B,MAAM,KAAK,GAAc,EAAE;AAC3B,IAAA,KAAK,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,KAAK,KAAK,IAAI,aAAa,CAAC,EAAE;AAC/F,QAAA,MAAM,IAAI,GAAY,EAAE,EAAE,EAAE,KAAK,EAAE,K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M,KACNC,cAAA,CAAA,QAAA,EAAA,EACC,IAAI,EAAC,qBAAqB,EAC1B,uBAAuB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,EAAA,CAC1D,CACF,EACDA,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAED,mBAAM,CAAC,eAAe,CAAC,EAAA,QAAA,EACrCE,cAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,IAAG;AAC/B,oBAAA,IAAI,CAACC,oBAAc,CAAC,KAAK,CAAC;AAAE,wBAAA,OAAO,KAAK;oBACxC,OAAOC,kBAAY,CAAC,KAAK,EAAE;AAC1B,wBAAA,GAAG,EAAE,sBAAsB;AACU,qBAAA,CAAC;AACxC,gBAAA,CAAC,CAAC,EAAA,CACG,EACNL,eAAA,CAACM,YAAQ,CAAC,GAAG,EAAA,EAAC,SAAS,EAAEL,mBAAM,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,YAAY,EAAA,QAAA,EAAA,CACpEC,cAAA,CAAA,GAAA,EAAA,EACC,SAAS,EAAE,CAAA,EAAGD,mBAAM,CAAC,kBAAkB,CAAC,IAAIA,mBAAM,CAAC,kBAAkB,CAAC,EAAE,EAAA,QAAA,EAEvE,KAAK,GACH,EACH,YAAY,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,MAC9CC,cAAA,CAACK,qBAAa,IAEb,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,CAAC,EACR,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,wBAAwB,EAAA,EAJ5B,IAAI,CAAC,EAAE,CAKX,CACF,CAAC,CAAA,EAAA,CACY,CAAA,EAAA,CACV;AAER;;;;"}
|
|
@@ -7,10 +7,11 @@ import { useCategoryTitles } from '../hooks/useCategoryTitles.js';
|
|
|
7
7
|
import { useSectionObserver } from '../hooks/useSectionObserver.js';
|
|
8
8
|
import TocNode from '../staticComponents/TocNodeStatic.js';
|
|
9
9
|
|
|
10
|
+
const MAX_TOC_DEPTH = 2;
|
|
10
11
|
const buildTocTree = (entries) => {
|
|
11
12
|
const roots = [];
|
|
12
13
|
const stack = [];
|
|
13
|
-
for (const [id, { title, depth }] of entries) {
|
|
14
|
+
for (const [id, { title, depth }] of entries.filter(([, { depth }]) => depth <= MAX_TOC_DEPTH)) {
|
|
14
15
|
const node = { id, title, depth, children: [] };
|
|
15
16
|
while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
|
|
16
17
|
stack.pop();
|
|
@@ -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\tuseState,\n} from 'react';\nimport { useSpring, animated, config } from '@react-spring/web';\n\nimport type { ReactNode, RefAttributes } from 'react';\nimport type { Thing, WithContext } from 'schema-dts';\n\nimport styles from '../styles/Blog.module.scss';\nimport { useCategoryTitles } from '../hooks/useCategoryTitles';\nimport { useSectionObserver } from '../hooks/useSectionObserver';\nimport type { CategoryTitleValue } from '../hooks/useCategoryTitles';\nimport TocNodeStatic from '../staticComponents/TocNodeStatic';\nimport type { TocNode } from '../staticComponents/TocNodeStatic';\n\ninterface BlogProperties {\n\tchildren: ReactNode;\n\ttitle?: string;\n\tjsonLd?: WithContext<Thing>;\n}\n\nexport interface ForwardedReference {\n\tparentRef: HTMLDivElement;\n\tchildRefs: ForwardedReference[];\n}\n\nconst buildTocTree = (entries: [string, CategoryTitleValue][]): TocNode[] => {\n\tconst roots: TocNode[] = [];\n\tconst stack: TocNode[] = [];\n\tfor (const [id, { title, depth }] of entries) {\n\t\tconst node: TocNode = { id, title, depth, children: [] };\n\t\twhile (stack.length > 0 && stack[stack.length - 1].depth >= depth) {\n\t\t\tstack.pop();\n\t\t}\n\t\tif (stack.length === 0) {\n\t\t\troots.push(node);\n\t\t} else {\n\t\t\tstack[stack.length - 1].children.push(node);\n\t\t}\n\t\tstack.push(node);\n\t}\n\treturn roots;\n};\n\nconst Blog = ({\n\tchildren,\n\ttitle = 'In this article',\n\tjsonLd,\n}: BlogProperties) => {\n\tconst [visibleTitle, setVisibleTitle] = useState<string | null>(null);\n\tconst [showTOC, setShowTOC] = useState(false);\n\n\tconst { categoryTitles, handleSectionReference } = useCategoryTitles({\n\t\tvisibleTitle,\n\t\tsetVisibleTitle,\n\t\tsetShowTOC,\n\t});\n\n\tconst { handleClickCategoryTitle } = useSectionObserver({\n\t\tcategoryTitles,\n\t\tsetVisibleTitle,\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{buildTocTree([...categoryTitles]).map((node, i) => (\n\t\t\t\t\t<TocNodeStatic\n\t\t\t\t\t\tkey={node.id}\n\t\t\t\t\t\tnode={node}\n\t\t\t\t\t\tindex={i}\n\t\t\t\t\t\tvisibleTitle={visibleTitle}\n\t\t\t\t\t\tonClick={handleClickCategoryTitle}\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","TocNodeStatic"],"mappings":";;;;;;;;AA+BA,MAAM,YAAY,GAAG,CAAC,OAAuC,KAAe;IAC3E,MAAM,KAAK,GAAc,EAAE;IAC3B,MAAM,KAAK,GAAc,EAAE;AAC3B,IAAA,KAAK,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,OAAO,EAAE;
|
|
1
|
+
{"version":3,"file":"BlogDynamic.js","sources":["../../../src/dynamicComponents/BlogDynamic.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tChildren,\n\tcloneElement,\n\tisValidElement,\n\tuseState,\n} from 'react';\nimport { useSpring, animated, config } from '@react-spring/web';\n\nimport type { ReactNode, RefAttributes } from 'react';\nimport type { Thing, WithContext } from 'schema-dts';\n\nimport styles from '../styles/Blog.module.scss';\nimport { useCategoryTitles } from '../hooks/useCategoryTitles';\nimport { useSectionObserver } from '../hooks/useSectionObserver';\nimport type { CategoryTitleValue } from '../hooks/useCategoryTitles';\nimport TocNodeStatic from '../staticComponents/TocNodeStatic';\nimport type { TocNode } from '../staticComponents/TocNodeStatic';\n\ninterface BlogProperties {\n\tchildren: ReactNode;\n\ttitle?: string;\n\tjsonLd?: WithContext<Thing>;\n}\n\nexport interface ForwardedReference {\n\tparentRef: HTMLDivElement;\n\tchildRefs: ForwardedReference[];\n}\n\nconst MAX_TOC_DEPTH = 2;\n\nconst buildTocTree = (entries: [string, CategoryTitleValue][]): TocNode[] => {\n\tconst roots: TocNode[] = [];\n\tconst stack: TocNode[] = [];\n\tfor (const [id, { title, depth }] of entries.filter(([, { depth }]) => depth <= MAX_TOC_DEPTH)) {\n\t\tconst node: TocNode = { id, title, depth, children: [] };\n\t\twhile (stack.length > 0 && stack[stack.length - 1].depth >= depth) {\n\t\t\tstack.pop();\n\t\t}\n\t\tif (stack.length === 0) {\n\t\t\troots.push(node);\n\t\t} else {\n\t\t\tstack[stack.length - 1].children.push(node);\n\t\t}\n\t\tstack.push(node);\n\t}\n\treturn roots;\n};\n\nconst Blog = ({\n\tchildren,\n\ttitle = 'In this article',\n\tjsonLd,\n}: BlogProperties) => {\n\tconst [visibleTitle, setVisibleTitle] = useState<string | null>(null);\n\tconst [showTOC, setShowTOC] = useState(false);\n\n\tconst { categoryTitles, handleSectionReference } = useCategoryTitles({\n\t\tvisibleTitle,\n\t\tsetVisibleTitle,\n\t\tsetShowTOC,\n\t});\n\n\tconst { handleClickCategoryTitle } = useSectionObserver({\n\t\tcategoryTitles,\n\t\tsetVisibleTitle,\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{buildTocTree([...categoryTitles]).map((node, i) => (\n\t\t\t\t\t<TocNodeStatic\n\t\t\t\t\t\tkey={node.id}\n\t\t\t\t\t\tnode={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C,GAAA,CAAA,GAAA,EAAA,EACC,SAAS,EAAE,CAAA,EAAG,MAAM,CAAC,kBAAkB,CAAC,IAAI,MAAM,CAAC,kBAAkB,CAAC,EAAE,EAAA,QAAA,EAEvE,KAAK,GACH,EACH,YAAY,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,MAC9CA,GAAA,CAACC,OAAa,IAEb,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,CAAC,EACR,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,wBAAwB,EAAA,EAJ5B,IAAI,CAAC,EAAE,CAKX,CACF,CAAC,CAAA,EAAA,CACY,CAAA,EAAA,CACV;AAER;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlogDynamic.d.ts","sourceRoot":"","sources":["../../../src/dynamicComponents/BlogDynamic.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AASrD,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,kBAAkB,EAAE,CAAC;CAChC;
|
|
1
|
+
{"version":3,"file":"BlogDynamic.d.ts","sourceRoot":"","sources":["../../../src/dynamicComponents/BlogDynamic.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AASrD,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,kBAAkB,EAAE,CAAC;CAChC;AAsBD,QAAA,MAAM,IAAI,GAAI,8BAIX,cAAc,4CAuDhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@san-siva/blogkit",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.25",
|
|
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",
|
|
@@ -29,10 +29,12 @@ export interface ForwardedReference {
|
|
|
29
29
|
childRefs: ForwardedReference[];
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
const MAX_TOC_DEPTH = 2;
|
|
33
|
+
|
|
32
34
|
const buildTocTree = (entries: [string, CategoryTitleValue][]): TocNode[] => {
|
|
33
35
|
const roots: TocNode[] = [];
|
|
34
36
|
const stack: TocNode[] = [];
|
|
35
|
-
for (const [id, { title, depth }] of entries) {
|
|
37
|
+
for (const [id, { title, depth }] of entries.filter(([, { depth }]) => depth <= MAX_TOC_DEPTH)) {
|
|
36
38
|
const node: TocNode = { id, title, depth, children: [] };
|
|
37
39
|
while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
|
|
38
40
|
stack.pop();
|