@san-siva/blogkit 1.1.31 → 1.1.33

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.
Files changed (38) hide show
  1. package/dist/cjs/components/CheckList.js +1 -4
  2. package/dist/cjs/components/CheckList.js.map +1 -1
  3. package/dist/cjs/dynamicComponents/BlogSectionDynamic.js +1 -1
  4. package/dist/cjs/dynamicComponents/BlogSectionDynamic.js.map +1 -1
  5. package/dist/cjs/dynamicComponents/CheckListDynamic.js +11 -14
  6. package/dist/cjs/dynamicComponents/CheckListDynamic.js.map +1 -1
  7. package/dist/cjs/index.css +1 -1
  8. package/dist/cjs/index.css.map +1 -1
  9. package/dist/cjs/staticComponents/BlogSectionStatic.js +1 -1
  10. package/dist/cjs/staticComponents/BlogSectionStatic.js.map +1 -1
  11. package/dist/cjs/utils/index.js +14 -0
  12. package/dist/cjs/utils/index.js.map +1 -1
  13. package/dist/esm/components/CheckList.js +1 -4
  14. package/dist/esm/components/CheckList.js.map +1 -1
  15. package/dist/esm/dynamicComponents/BlogSectionDynamic.js +2 -2
  16. package/dist/esm/dynamicComponents/BlogSectionDynamic.js.map +1 -1
  17. package/dist/esm/dynamicComponents/CheckListDynamic.js +11 -14
  18. package/dist/esm/dynamicComponents/CheckListDynamic.js.map +1 -1
  19. package/dist/esm/index.css +1 -1
  20. package/dist/esm/index.css.map +1 -1
  21. package/dist/esm/staticComponents/BlogSectionStatic.js +2 -2
  22. package/dist/esm/staticComponents/BlogSectionStatic.js.map +1 -1
  23. package/dist/esm/utils/index.js +14 -1
  24. package/dist/esm/utils/index.js.map +1 -1
  25. package/dist/types/components/CheckList.d.ts.map +1 -1
  26. package/dist/types/utils/index.d.ts +2 -0
  27. package/dist/types/utils/index.d.ts.map +1 -1
  28. package/dist/types/utils/index.test.d.ts +2 -0
  29. package/dist/types/utils/index.test.d.ts.map +1 -0
  30. package/package.json +4 -2
  31. package/src/components/CheckList.tsx +8 -13
  32. package/src/dynamicComponents/BlogSectionDynamic.tsx +2 -2
  33. package/src/staticComponents/BlogSectionStatic.tsx +2 -2
  34. package/src/styles/CheckList.module.scss +2 -2
  35. package/src/styles/CodeBlock.module.scss +2 -3
  36. package/src/utils/index.test.tsx +63 -0
  37. package/src/utils/index.ts +11 -0
  38. package/src/dynamicComponents/CheckListDynamic.tsx +0 -66
@@ -1,9 +1,9 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import styles from '../styles/BlogSection.module.scss.js';
3
- import { generateIdForBlogTitle } from '../utils/index.js';
3
+ import { extractTextFromReactNode, generateIdForBlogTitle } from '../utils/index.js';
4
4
 
5
5
  const BlogSectionStatic = ({ title = '', category = '', children = null, }) => {
6
- const titleString = typeof title === 'string' ? title : '';
6
+ const titleString = typeof title === 'string' ? title : extractTextFromReactNode(title);
7
7
  const titleWithCategory = category ? `${category} - ${titleString}` : titleString;
8
8
  const id = generateIdForBlogTitle(titleWithCategory);
9
9
  return (jsxs("div", { className: styles['blog-section'], "data-title": titleString, "data-id": id, children: [title ? (jsx("h3", { className: styles['blog-section__title'], children: title })) : null, children] }));
@@ -1 +1 @@
1
- {"version":3,"file":"BlogSectionStatic.js","sources":["../../../src/staticComponents/BlogSectionStatic.tsx"],"sourcesContent":["import type { HTMLAttributes, ReactElement, ReactNode } from 'react';\nimport styles from '../styles/BlogSection.module.scss';\nimport { generateIdForBlogTitle } from '../utils';\n\ninterface BlogSectionStaticProperties {\n\ttitle?: string | ReactElement<HTMLAttributes<HTMLParagraphElement>, 'p'>;\n\tcategory?: string;\n\tchildren?: ReactNode;\n}\n\nconst BlogSectionStatic = ({\n\ttitle = '',\n\tcategory = '',\n\tchildren = null,\n}: BlogSectionStaticProperties) => {\n\tconst titleString = typeof title === 'string' ? title : '';\n\tconst titleWithCategory = category ? `${category} - ${titleString}` : titleString;\n\tconst id = generateIdForBlogTitle(titleWithCategory);\n\n\treturn (\n\t\t<div className={styles['blog-section']} data-title={titleString} data-id={id}>\n\t\t\t{title ? (\n\t\t\t\t<h3 className={styles['blog-section__title']}>{title}</h3>\n\t\t\t) : null}\n\t\t\t{children}\n\t\t</div>\n\t);\n};\n\nexport default BlogSectionStatic;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;AAUA,MAAM,iBAAiB,GAAG,CAAC,EAC1B,KAAK,GAAG,EAAE,EACV,QAAQ,GAAG,EAAE,EACb,QAAQ,GAAG,IAAI,GACc,KAAI;AACjC,IAAA,MAAM,WAAW,GAAG,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK,GAAG,EAAE;AAC1D,IAAA,MAAM,iBAAiB,GAAG,QAAQ,GAAG,CAAA,EAAG,QAAQ,CAAA,GAAA,EAAM,WAAW,CAAA,CAAE,GAAG,WAAW;AACjF,IAAA,MAAM,EAAE,GAAG,sBAAsB,CAAC,iBAAiB,CAAC;AAEpD,IAAA,QACCA,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,MAAM,CAAC,cAAc,CAAC,EAAA,YAAA,EAAc,WAAW,aAAW,EAAE,EAAA,QAAA,EAAA,CAC1E,KAAK,IACLC,GAAA,CAAA,IAAA,EAAA,EAAI,SAAS,EAAE,MAAM,CAAC,qBAAqB,CAAC,YAAG,KAAK,EAAA,CAAM,IACvD,IAAI,EACP,QAAQ,CAAA,EAAA,CACJ;AAER;;;;"}
1
+ {"version":3,"file":"BlogSectionStatic.js","sources":["../../../src/staticComponents/BlogSectionStatic.tsx"],"sourcesContent":["import type { HTMLAttributes, ReactElement, ReactNode } from 'react';\nimport styles from '../styles/BlogSection.module.scss';\nimport { extractTextFromReactNode, generateIdForBlogTitle } from '../utils';\n\ninterface BlogSectionStaticProperties {\n\ttitle?: string | ReactElement<HTMLAttributes<HTMLParagraphElement>, 'p'>;\n\tcategory?: string;\n\tchildren?: ReactNode;\n}\n\nconst BlogSectionStatic = ({\n\ttitle = '',\n\tcategory = '',\n\tchildren = null,\n}: BlogSectionStaticProperties) => {\n\tconst titleString = typeof title === 'string' ? title : extractTextFromReactNode(title);\n\tconst titleWithCategory = category ? `${category} - ${titleString}` : titleString;\n\tconst id = generateIdForBlogTitle(titleWithCategory);\n\n\treturn (\n\t\t<div className={styles['blog-section']} data-title={titleString} data-id={id}>\n\t\t\t{title ? (\n\t\t\t\t<h3 className={styles['blog-section__title']}>{title}</h3>\n\t\t\t) : null}\n\t\t\t{children}\n\t\t</div>\n\t);\n};\n\nexport default BlogSectionStatic;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;AAUA,MAAM,iBAAiB,GAAG,CAAC,EAC1B,KAAK,GAAG,EAAE,EACV,QAAQ,GAAG,EAAE,EACb,QAAQ,GAAG,IAAI,GACc,KAAI;AACjC,IAAA,MAAM,WAAW,GAAG,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK,GAAG,wBAAwB,CAAC,KAAK,CAAC;AACvF,IAAA,MAAM,iBAAiB,GAAG,QAAQ,GAAG,CAAA,EAAG,QAAQ,CAAA,GAAA,EAAM,WAAW,CAAA,CAAE,GAAG,WAAW;AACjF,IAAA,MAAM,EAAE,GAAG,sBAAsB,CAAC,iBAAiB,CAAC;AAEpD,IAAA,QACCA,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,MAAM,CAAC,cAAc,CAAC,EAAA,YAAA,EAAc,WAAW,aAAW,EAAE,EAAA,QAAA,EAAA,CAC1E,KAAK,IACLC,GAAA,CAAA,IAAA,EAAA,EAAI,SAAS,EAAE,MAAM,CAAC,qBAAqB,CAAC,YAAG,KAAK,EAAA,CAAM,IACvD,IAAI,EACP,QAAQ,CAAA,EAAA,CACJ;AAER;;;;"}
@@ -1,6 +1,19 @@
1
+ import { isValidElement } from 'react';
2
+
3
+ const extractTextFromReactNode = (node) => {
4
+ if (node === null || node === undefined || typeof node === 'boolean')
5
+ return '';
6
+ if (typeof node === 'string' || typeof node === 'number')
7
+ return String(node);
8
+ if (isValidElement(node))
9
+ return extractTextFromReactNode(node.props.children);
10
+ if (Array.isArray(node))
11
+ return node.map(extractTextFromReactNode).join('');
12
+ return '';
13
+ };
1
14
  const generateIdForBlogTitle = (title) => title.toLowerCase().replace(/[^\w\d]/g, '-');
2
15
  const generateUrlForBlogTitle = (title) => encodeURIComponent(title.replace(/[^\w]+/g, '-').toLowerCase());
3
16
  const generateSectionHref = (id) => `?section=${id}`;
4
17
 
5
- export { generateIdForBlogTitle, generateSectionHref, generateUrlForBlogTitle };
18
+ export { extractTextFromReactNode, generateIdForBlogTitle, generateSectionHref, generateUrlForBlogTitle };
6
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/utils/index.ts"],"sourcesContent":["export const generateIdForBlogTitle = (title: string) => title.toLowerCase().replace(/[^\\w\\d]/g, '-');\n\nexport const generateUrlForBlogTitle = (title: string) => encodeURIComponent(title.replace(/[^\\w]+/g, '-').toLowerCase());\n\nexport const generateSectionHref = (id: string) => `?section=${id}`;\n"],"names":[],"mappings":"MAAa,sBAAsB,GAAG,CAAC,KAAa,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG;MAEvF,uBAAuB,GAAG,CAAC,KAAa,KAAK,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE;AAEjH,MAAM,mBAAmB,GAAG,CAAC,EAAU,KAAK,CAAA,SAAA,EAAY,EAAE,CAAA;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/utils/index.ts"],"sourcesContent":["import { isValidElement } from 'react';\nimport type { ReactNode } from 'react';\n\nexport const extractTextFromReactNode = (node: ReactNode): string => {\n\tif (node === null || node === undefined || typeof node === 'boolean') return '';\n\tif (typeof node === 'string' || typeof node === 'number') return String(node);\n\tif (isValidElement(node)) return extractTextFromReactNode((node.props as { children?: ReactNode }).children);\n\tif (Array.isArray(node)) return node.map(extractTextFromReactNode).join('');\n\treturn '';\n};\n\nexport const generateIdForBlogTitle = (title: string) => title.toLowerCase().replace(/[^\\w\\d]/g, '-');\n\nexport const generateUrlForBlogTitle = (title: string) => encodeURIComponent(title.replace(/[^\\w]+/g, '-').toLowerCase());\n\nexport const generateSectionHref = (id: string) => `?section=${id}`;\n"],"names":[],"mappings":";;AAGO,MAAM,wBAAwB,GAAG,CAAC,IAAe,KAAY;IACnE,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,SAAS;AAAE,QAAA,OAAO,EAAE;IAC/E,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,QAAQ;AAAE,QAAA,OAAO,MAAM,CAAC,IAAI,CAAC;IAC7E,IAAI,cAAc,CAAC,IAAI,CAAC;QAAE,OAAO,wBAAwB,CAAE,IAAI,CAAC,KAAkC,CAAC,QAAQ,CAAC;AAC5G,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AAC3E,IAAA,OAAO,EAAE;AACV;MAEa,sBAAsB,GAAG,CAAC,KAAa,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG;MAEvF,uBAAuB,GAAG,CAAC,KAAa,KAAK,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE;AAEjH,MAAM,mBAAmB,GAAG,CAAC,EAAU,KAAK,CAAA,SAAA,EAAY,EAAE,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"CheckList.d.ts","sourceRoot":"","sources":["../../../src/components/CheckList.tsx"],"names":[],"mappings":"AAGA,OAAwB,EAAE,KAAK,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAI1F,UAAU,mBAAmB;IAC5B,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,QAAA,MAAM,SAAS,GAAI,wCAIhB,mBAAmB,4CAUrB,CAAC;AAEF,OAAO,EAAE,KAAK,aAAa,EAAE,CAAC;AAC9B,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"CheckList.d.ts","sourceRoot":"","sources":["../../../src/components/CheckList.tsx"],"names":[],"mappings":"AAAA,OAAwB,EACvB,KAAK,aAAa,EAClB,MAAM,qCAAqC,CAAC;AAE7C,UAAU,mBAAmB;IAC5B,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,QAAA,MAAM,SAAS,GAAI,wCAIhB,mBAAmB,4CAQrB,CAAC;AAEF,OAAO,EAAE,KAAK,aAAa,EAAE,CAAC;AAC9B,eAAe,SAAS,CAAC"}
@@ -1,3 +1,5 @@
1
+ import type { ReactNode } from 'react';
2
+ export declare const extractTextFromReactNode: (node: ReactNode) => string;
1
3
  export declare const generateIdForBlogTitle: (title: string) => string;
2
4
  export declare const generateUrlForBlogTitle: (title: string) => string;
3
5
  export declare const generateSectionHref: (id: string) => string;
@@ -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;AAE1H,eAAO,MAAM,mBAAmB,GAAI,IAAI,MAAM,WAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,eAAO,MAAM,wBAAwB,GAAI,MAAM,SAAS,KAAG,MAM1D,CAAC;AAEF,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/utils/index.test.tsx"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@san-siva/blogkit",
3
- "version": "1.1.31",
3
+ "version": "1.1.33",
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",
@@ -24,6 +24,7 @@
24
24
  "scripts": {
25
25
  "build": "rollup -c && tsc --emitDeclarationOnly --outDir dist/types && cp -r src/assets dist/",
26
26
  "dev": "rollup -c -w",
27
+ "test": "vitest run",
27
28
  "lint": "tsc --noEmit",
28
29
  "prepublishOnly": "npm ci && npm run lint && npm run build"
29
30
  },
@@ -70,6 +71,7 @@
70
71
  "rollup-plugin-url": "^3.0.1",
71
72
  "sass": "^1.77.8",
72
73
  "tslib": "^2.8.1",
73
- "typescript": "^5.7.2"
74
+ "typescript": "^5.7.2",
75
+ "vitest": "^4.1.2"
74
76
  }
75
77
  }
@@ -1,9 +1,6 @@
1
- 'use client';
2
-
3
- import { lazy, Suspense } from 'react';
4
- import CheckListStatic, { type CheckListItem } from '../staticComponents/CheckListStatic';
5
-
6
- const CheckListDynamic = lazy(() => import('../dynamicComponents/CheckListDynamic'));
1
+ import CheckListStatic, {
2
+ type CheckListItem,
3
+ } from '../staticComponents/CheckListStatic';
7
4
 
8
5
  interface CheckListProperties {
9
6
  items: CheckListItem[];
@@ -17,13 +14,11 @@ const CheckList = ({
17
14
  hasMarginDown = false,
18
15
  }: CheckListProperties) => {
19
16
  return (
20
- <Suspense
21
- fallback={
22
- <CheckListStatic items={items} hasMarginUp={hasMarginUp} hasMarginDown={hasMarginDown} />
23
- }
24
- >
25
- <CheckListDynamic items={items} hasMarginUp={hasMarginUp} hasMarginDown={hasMarginDown} />
26
- </Suspense>
17
+ <CheckListStatic
18
+ items={items}
19
+ hasMarginUp={hasMarginUp}
20
+ hasMarginDown={hasMarginDown}
21
+ />
27
22
  );
28
23
  };
29
24
 
@@ -15,7 +15,7 @@ import type { HTMLAttributes, ReactElement, ReactNode, RefAttributes } from 'rea
15
15
  import styles from '../styles/BlogSection.module.scss';
16
16
 
17
17
  import type { ForwardedReference } from './BlogDynamic';
18
- import { generateIdForBlogTitle, generateSectionHref } from '../utils';
18
+ import { extractTextFromReactNode, generateIdForBlogTitle, generateSectionHref } from '../utils';
19
19
 
20
20
  interface BlogProperties {
21
21
  title?: string | ReactElement<HTMLAttributes<HTMLParagraphElement>, 'p'>;
@@ -28,7 +28,7 @@ const BlogSection = forwardRef<ForwardedReference, BlogProperties>(
28
28
  { title = '', category = '', children = null }: BlogProperties,
29
29
  forwardedReference
30
30
  ) => {
31
- const titleString = typeof title === 'string' ? title : '';
31
+ const titleString = typeof title === 'string' ? title : extractTextFromReactNode(title);
32
32
  const titleWithCategory = category ? `${category} - ${titleString}` : titleString;
33
33
  const id = generateIdForBlogTitle(titleWithCategory);
34
34
 
@@ -1,6 +1,6 @@
1
1
  import type { HTMLAttributes, ReactElement, ReactNode } from 'react';
2
2
  import styles from '../styles/BlogSection.module.scss';
3
- import { generateIdForBlogTitle } from '../utils';
3
+ import { extractTextFromReactNode, generateIdForBlogTitle } from '../utils';
4
4
 
5
5
  interface BlogSectionStaticProperties {
6
6
  title?: string | ReactElement<HTMLAttributes<HTMLParagraphElement>, 'p'>;
@@ -13,7 +13,7 @@ const BlogSectionStatic = ({
13
13
  category = '',
14
14
  children = null,
15
15
  }: BlogSectionStaticProperties) => {
16
- const titleString = typeof title === 'string' ? title : '';
16
+ const titleString = typeof title === 'string' ? title : extractTextFromReactNode(title);
17
17
  const titleWithCategory = category ? `${category} - ${titleString}` : titleString;
18
18
  const id = generateIdForBlogTitle(titleWithCategory);
19
19
 
@@ -8,7 +8,7 @@
8
8
  &__item {
9
9
  display: flex;
10
10
  flex-direction: row;
11
- align-items: center;
11
+ align-items: flex-start;
12
12
  justify-content: flex-start;
13
13
 
14
14
  &__input {
@@ -17,6 +17,7 @@
17
17
  border: 1px solid stylekit.$color--grey-medium;
18
18
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07);
19
19
  margin-right: stylekit.space(1);
20
+ margin-top: stylekit.rem(6);
20
21
  flex-shrink: 0;
21
22
 
22
23
  &--checked {
@@ -30,7 +31,6 @@
30
31
  }
31
32
 
32
33
  > p {
33
- font-size: stylekit.$font-size--small;
34
34
  margin: 0;
35
35
  }
36
36
  }
@@ -83,7 +83,6 @@ $code-block-background-color: #282a36;
83
83
  &__title {
84
84
  font-size: stylekit.$font-size--small;
85
85
  color: stylekit.$color--code;
86
- text-transform: capitalize;
87
86
  }
88
87
 
89
88
  &__copy {
@@ -119,6 +118,6 @@ $code-block-background-color: #282a36;
119
118
 
120
119
  .code-block--static code {
121
120
  color: stylekit.$color--base !important;
122
- font-family: stylekit.$font-family--code !important;
123
- font-size: stylekit.$font-size--small !important;
121
+ font-family: stylekit.$font-family--code !important;
122
+ font-size: stylekit.$font-size--small !important;
124
123
  }
@@ -0,0 +1,63 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createElement } from 'react';
3
+ import { extractTextFromReactNode } from './index';
4
+
5
+ describe('extractTextFromReactNode', () => {
6
+ it('returns empty string for null', () => {
7
+ expect(extractTextFromReactNode(null)).toBe('');
8
+ });
9
+
10
+ it('returns empty string for undefined', () => {
11
+ expect(extractTextFromReactNode(undefined)).toBe('');
12
+ });
13
+
14
+ it('returns empty string for boolean', () => {
15
+ expect(extractTextFromReactNode(true)).toBe('');
16
+ expect(extractTextFromReactNode(false)).toBe('');
17
+ });
18
+
19
+ it('returns string as-is', () => {
20
+ expect(extractTextFromReactNode('Hello')).toBe('Hello');
21
+ });
22
+
23
+ it('converts number to string', () => {
24
+ expect(extractTextFromReactNode(42)).toBe('42');
25
+ });
26
+
27
+ it('extracts text from a simple element', () => {
28
+ const node = createElement('p', null, 'Section title');
29
+ expect(extractTextFromReactNode(node)).toBe('Section title');
30
+ });
31
+
32
+ it('extracts text from nested elements', () => {
33
+ const node = createElement('p', null,
34
+ 'Hello ',
35
+ createElement('strong', null, 'world'),
36
+ );
37
+ expect(extractTextFromReactNode(node)).toBe('Hello world');
38
+ });
39
+
40
+ it('extracts text from deeply nested elements', () => {
41
+ const node = createElement('p', null,
42
+ createElement('em', null,
43
+ createElement('strong', null, 'deep'),
44
+ ),
45
+ );
46
+ expect(extractTextFromReactNode(node)).toBe('deep');
47
+ });
48
+
49
+ it('extracts text from an array of nodes', () => {
50
+ const nodes = ['foo', ' ', createElement('span', null, 'bar')];
51
+ expect(extractTextFromReactNode(nodes)).toBe('foo bar');
52
+ });
53
+
54
+ it('handles mixed content with numbers and elements', () => {
55
+ const node = createElement('p', null, 'Step ', 3, ': done');
56
+ expect(extractTextFromReactNode(node)).toBe('Step 3: done');
57
+ });
58
+
59
+ it('returns empty string for element with no children', () => {
60
+ const node = createElement('p', null);
61
+ expect(extractTextFromReactNode(node)).toBe('');
62
+ });
63
+ });
@@ -1,3 +1,14 @@
1
+ import { isValidElement } from 'react';
2
+ import type { ReactNode } from 'react';
3
+
4
+ export const extractTextFromReactNode = (node: ReactNode): string => {
5
+ if (node === null || node === undefined || typeof node === 'boolean') return '';
6
+ if (typeof node === 'string' || typeof node === 'number') return String(node);
7
+ if (isValidElement(node)) return extractTextFromReactNode((node.props as { children?: ReactNode }).children);
8
+ if (Array.isArray(node)) return node.map(extractTextFromReactNode).join('');
9
+ return '';
10
+ };
11
+
1
12
  export const generateIdForBlogTitle = (title: string) => title.toLowerCase().replace(/[^\w\d]/g, '-');
2
13
 
3
14
  export const generateUrlForBlogTitle = (title: string) => encodeURIComponent(title.replace(/[^\w]+/g, '-').toLowerCase());
@@ -1,66 +0,0 @@
1
- 'use client';
2
-
3
- import { useEffect, useRef, useState } from 'react';
4
-
5
- import type { CheckListItem } from '../staticComponents/CheckListStatic';
6
- import styles from '../styles/CheckList.module.scss';
7
-
8
- interface Properties {
9
- items: CheckListItem[];
10
- hasMarginUp?: boolean;
11
- hasMarginDown?: boolean;
12
- }
13
-
14
- const CHECKBOX_SIZE = 12;
15
- const P_TAG_FONT_SIZE = 16;
16
-
17
- const CheckListDynamic = ({
18
- items,
19
- hasMarginUp = false,
20
- hasMarginDown = false,
21
- }: Properties) => {
22
- const [checkboxMarginTop, setCheckboxMarginTop] = useState(0);
23
- const measureRef = useRef<HTMLDivElement>(null);
24
-
25
- useEffect(() => {
26
- if (!measureRef.current) return;
27
- const p = measureRef.current.querySelector('p');
28
- if (!p) return;
29
- const rawLineHeight = getComputedStyle(p).lineHeight;
30
- const lineHeight =
31
- rawLineHeight === 'normal'
32
- ? P_TAG_FONT_SIZE * 1.2
33
- : parseFloat(rawLineHeight);
34
- if (!isNaN(lineHeight)) {
35
- setCheckboxMarginTop(Math.max(0, (lineHeight - CHECKBOX_SIZE) / 2));
36
- }
37
- }, []);
38
-
39
- return (
40
- <div
41
- className={`${styles['check-list']} ${hasMarginUp ? styles['margin-top--1'] : ''} ${
42
- hasMarginDown ? styles['margin-bottom--2'] : ''
43
- }`}
44
- >
45
- {items.map((item, index) => (
46
- <div
47
- key={item.id}
48
- className={styles['check-list__item']}
49
- style={{ alignItems: 'flex-start' }}
50
- data-id={item.id}
51
- ref={index === 0 ? measureRef : undefined}
52
- >
53
- <div
54
- className={`${styles['check-list__item__input']} ${
55
- item.isChecked ? styles['check-list__item__input--checked'] : ''
56
- }`}
57
- style={{ marginTop: `${checkboxMarginTop}px` }}
58
- />
59
- {item.children}
60
- </div>
61
- ))}
62
- </div>
63
- );
64
- };
65
-
66
- export default CheckListDynamic;