@rasenganjs/mdx 1.0.5 → 1.1.0-beta.0
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/CHANGELOG.md +3 -0
- package/README.md +9 -9
- package/lib/components/codeblock.d.ts +2 -2
- package/lib/components/codeblock.js +16 -17
- package/lib/components/codeblock.js.map +1 -1
- package/lib/components/codeblock2.d.ts +14 -0
- package/lib/components/codeblock2.js +46 -0
- package/lib/components/codeblock2.js.map +1 -0
- package/lib/components/heading.d.ts +1 -1
- package/lib/components/heading.js +12 -26
- package/lib/components/heading.js.map +1 -1
- package/lib/components/index.d.ts +4 -12
- package/lib/components/index.js +6 -25
- package/lib/components/index.js.map +1 -1
- package/lib/components/markdown.d.ts +6 -0
- package/lib/components/markdown.js +29 -0
- package/lib/components/markdown.js.map +1 -0
- package/lib/components/renderer.d.ts +12 -0
- package/lib/components/renderer.js +27 -0
- package/lib/components/renderer.js.map +1 -0
- package/lib/components/table.d.ts +2 -2
- package/lib/components/table.js +1 -1
- package/lib/components/table.js.map +1 -1
- package/lib/components/toc.d.ts +7 -0
- package/lib/components/toc.js +72 -0
- package/lib/components/toc.js.map +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +5 -2
- package/lib/index.js.map +1 -1
- package/lib/styles/rasengan-mdx.min.css +1 -1
- package/lib/types/index.d.ts +39 -2
- package/lib/utils/create-filter.js +1 -1
- package/lib/utils/create-filter.js.map +1 -1
- package/lib/utils/define-mdx-config.d.ts +2 -0
- package/lib/utils/define-mdx-config.js +4 -0
- package/lib/utils/define-mdx-config.js.map +1 -0
- package/lib/utils/extract-toc.d.ts +16 -1
- package/lib/utils/extract-toc.js +64 -10
- package/lib/utils/extract-toc.js.map +1 -1
- package/lib/utils/generate-navigation.d.ts +0 -0
- package/lib/utils/generate-navigation.js +75 -0
- package/lib/utils/generate-navigation.js.map +1 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +3 -2
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mark-to-html.js +5 -5
- package/lib/utils/mark-to-html.js.map +1 -1
- package/lib/utils/plugin.d.ts +1 -13
- package/lib/utils/plugin.js +19 -18
- package/lib/utils/plugin.js.map +1 -1
- package/lib/utils/polyfill.js +4 -4
- package/lib/utils/polyfill.js.map +1 -1
- package/package.json +69 -64
- package/tsconfig.json +2 -12
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -31,8 +31,8 @@ Here is an example of how you can use the `@rasenganjs/mdx` package:
|
|
|
31
31
|
Import the `mdx` plugin into the `rasengan.config.js` file.
|
|
32
32
|
|
|
33
33
|
```javascript
|
|
34
|
-
import { defineConfig } from
|
|
35
|
-
import mdx from
|
|
34
|
+
import { defineConfig } from 'rasengan';
|
|
35
|
+
import mdx from '@rasenganjs/mdx';
|
|
36
36
|
|
|
37
37
|
export default defineConfig({
|
|
38
38
|
vite: {
|
|
@@ -53,7 +53,7 @@ metadata:
|
|
|
53
53
|
description: Discover our new blog posts
|
|
54
54
|
---
|
|
55
55
|
|
|
56
|
-
import Button from
|
|
56
|
+
import Button from '@/components/Button';
|
|
57
57
|
|
|
58
58
|
# Blog page
|
|
59
59
|
|
|
@@ -67,10 +67,10 @@ This is a `blog` page.
|
|
|
67
67
|
Inside the `app.router.ts` file, import your Markdown Component and the `MDXRenderer` component from `@rasenganjs/mdx` and add it to `defineRouter` option like this:
|
|
68
68
|
|
|
69
69
|
```typescript
|
|
70
|
-
import { RouterComponent, defineRouter } from
|
|
71
|
-
import AppLayout from
|
|
72
|
-
import Blog from
|
|
73
|
-
import { MDXRenderer } from
|
|
70
|
+
import { RouterComponent, defineRouter } from 'rasengan';
|
|
71
|
+
import AppLayout from '@app/app.layout';
|
|
72
|
+
import Blog from '@app/blog.page.mdx';
|
|
73
|
+
import { MDXRenderer } from '@rasenganjs/mdx';
|
|
74
74
|
|
|
75
75
|
class AppRouter extends RouterComponent {}
|
|
76
76
|
|
|
@@ -78,7 +78,7 @@ export default defineRouter({
|
|
|
78
78
|
imports: [],
|
|
79
79
|
layout: AppLayout,
|
|
80
80
|
pages: [Blog],
|
|
81
|
-
MDXRenderer
|
|
81
|
+
MDXRenderer,
|
|
82
82
|
})(AppRouter);
|
|
83
83
|
```
|
|
84
84
|
|
|
@@ -112,4 +112,4 @@ We also have a [Twitter](https://twitter.com/rasenganjs) account where you can f
|
|
|
112
112
|
|
|
113
113
|
Here is the authors list:
|
|
114
114
|
|
|
115
|
-
- Dilane Kombou ([**@dilanekombou**](https://twitter.com/dilanekombou))
|
|
115
|
+
- Dilane Kombou ([**@dilanekombou**](https://twitter.com/dilanekombou))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { CodeBlockProps, ComponentWithTextChildrenProps } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CodeBlockProps, ComponentWithTextChildrenProps } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
5
5
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React from
|
|
3
|
-
import { renderToString } from
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { renderToString } from 'react-dom/server';
|
|
4
4
|
/**
|
|
5
5
|
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
6
6
|
*
|
|
@@ -12,10 +12,9 @@ import { renderToString } from "react-dom/server";
|
|
|
12
12
|
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
13
13
|
* @returns {React.ReactElement} - The rendered code block component.
|
|
14
14
|
*/
|
|
15
|
-
export const CodeBlock = ({ children, className =
|
|
16
|
-
const language = rest[
|
|
17
|
-
const numbers = rest[
|
|
18
|
-
// const theme = rest["data-theme"] || "github-dark-dimmed";
|
|
15
|
+
export const CodeBlock = ({ children, className = '', ...rest }) => {
|
|
16
|
+
const language = rest['data-language'] || '';
|
|
17
|
+
const numbers = rest['data-line-numbers'];
|
|
19
18
|
const [hover, setHover] = React.useState(false);
|
|
20
19
|
const [copied, setCopied] = React.useState(false);
|
|
21
20
|
React.useEffect(() => {
|
|
@@ -40,24 +39,24 @@ export const CodeBlock = ({ children, className = "", ...rest }) => {
|
|
|
40
39
|
setCopied(true);
|
|
41
40
|
};
|
|
42
41
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
* Extracts the text content from an HTML string.
|
|
43
|
+
*
|
|
44
|
+
* This function takes an HTML string as input and returns the plain text content of the HTML, excluding any HTML tags or markup.
|
|
45
|
+
*
|
|
46
|
+
* @param htmlString - The HTML string to extract text from.
|
|
47
|
+
* @returns The plain text content of the HTML string.
|
|
48
|
+
*/
|
|
50
49
|
const extractTextFromHTML = (htmlString) => {
|
|
51
50
|
const parser = new DOMParser();
|
|
52
|
-
const doc = parser.parseFromString(htmlString,
|
|
53
|
-
return doc.body.textContent ||
|
|
51
|
+
const doc = parser.parseFromString(htmlString, 'text/html');
|
|
52
|
+
return doc.body.textContent || '';
|
|
54
53
|
};
|
|
55
54
|
if (!language) {
|
|
56
55
|
return _jsx(SimpleBlock, { children: children });
|
|
57
56
|
}
|
|
58
|
-
return (_jsxs("div", { onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), children: [hover ? (_jsx("button", { className:
|
|
57
|
+
return (_jsxs("div", { onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), children: [hover ? (_jsx("button", { className: "copy-button", onClick: handleCopy, children: copied ? (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "16", height: "16", color: "#f0f0f0", fill: "none", children: [_jsx("path", { d: "M22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12Z", stroke: "currentColor", strokeWidth: "1.5" }), _jsx("path", { d: "M8 12.5L10.5 15L16 9", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] })) : (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "16", height: "16", color: "#f0f0f0", fill: "none", children: [_jsx("path", { d: "M9 15C9 12.1716 9 10.7574 9.87868 9.87868C10.7574 9 12.1716 9 15 9L16 9C18.8284 9 20.2426 9 21.1213 9.87868C22 10.7574 22 12.1716 22 15V16C22 18.8284 22 20.2426 21.1213 21.1213C20.2426 22 18.8284 22 16 22H15C12.1716 22 10.7574 22 9.87868 21.1213C9 20.2426 9 18.8284 9 16L9 15Z", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M16.9999 9C16.9975 6.04291 16.9528 4.51121 16.092 3.46243C15.9258 3.25989 15.7401 3.07418 15.5376 2.90796C14.4312 2 12.7875 2 9.5 2C6.21252 2 4.56878 2 3.46243 2.90796C3.25989 3.07417 3.07418 3.25989 2.90796 3.46243C2 4.56878 2 6.21252 2 9.5C2 12.7875 2 14.4312 2.90796 15.5376C3.07417 15.7401 3.25989 15.9258 3.46243 16.092C4.51121 16.9528 6.04291 16.9975 9 16.9999", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] })) })) : (_jsx("span", { className: "lang", children: language })), _jsx("code", { className: `${className} code-block`, "data-line-numbers": numbers !== undefined ? '' : undefined, children: children })] }));
|
|
59
58
|
};
|
|
60
59
|
export const SimpleBlock = ({ children, }) => {
|
|
61
|
-
return _jsx("code", { className:
|
|
60
|
+
return _jsx("code", { className: "simple-block", children: children });
|
|
62
61
|
};
|
|
63
62
|
//# sourceMappingURL=codeblock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeblock.js","sourceRoot":"","sources":["../../src/components/codeblock.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;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EX,eACE,CAAC,EAAC,sRAAsR,EACxR,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,EACF,eACE,CAAC,EAAC,gXAAgX,EAClX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,IACE,CACP,GACM,CACV,CAAC,CAAC,CAAC,CACF,eAAM,SAAS,EAAC,MAAM,YAAE,QAAQ,GAAQ,CACzC,EACD,eACE,SAAS,EAAE,GAAG,SAAS,aAAa,uBACjB,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,YAExD,QAAQ,GACJ,IACH,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAC1B,QAAQ,GACuB,EAAsB,EAAE;IACvD,OAAO,eAAM,SAAS,EAAC,cAAc,YAAE,QAAQ,GAAQ,CAAC;AAC1D,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CodeBlockProps } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
5
|
+
*
|
|
6
|
+
* The component uses the `prism-react-renderer` library to provide syntax highlighting for the code block.
|
|
7
|
+
* It also includes a copy button that allows the user to copy the code to their clipboard.
|
|
8
|
+
*
|
|
9
|
+
* @param {object} props - The component props.
|
|
10
|
+
* @param {string} props.children - The code content to be displayed in the code block.
|
|
11
|
+
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
12
|
+
* @returns {React.ReactElement} - The rendered code block component.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CodeBlock2: ({ children, className, }: CodeBlockProps) => React.ReactElement;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { themes, Highlight } from 'prism-react-renderer';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { SimpleBlock } from './codeblock.js';
|
|
5
|
+
/**
|
|
6
|
+
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
7
|
+
*
|
|
8
|
+
* The component uses the `prism-react-renderer` library to provide syntax highlighting for the code block.
|
|
9
|
+
* It also includes a copy button that allows the user to copy the code to their clipboard.
|
|
10
|
+
*
|
|
11
|
+
* @param {object} props - The component props.
|
|
12
|
+
* @param {string} props.children - The code content to be displayed in the code block.
|
|
13
|
+
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
14
|
+
* @returns {React.ReactElement} - The rendered code block component.
|
|
15
|
+
*/
|
|
16
|
+
export const CodeBlock2 = ({ children, className = '', }) => {
|
|
17
|
+
const language = className.replace(/language-/, '');
|
|
18
|
+
const [hover, setHover] = React.useState(false);
|
|
19
|
+
if (!language) {
|
|
20
|
+
return _jsx(SimpleBlock, { children: children });
|
|
21
|
+
}
|
|
22
|
+
return (_jsx(Highlight, { theme: themes.oneDark, code: children.trim(), language: language, children: ({ className, tokens, getLineProps, getTokenProps, ...rest }) => {
|
|
23
|
+
const [copied, setCopied] = React.useState(false);
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
/**
|
|
26
|
+
* Sets the `copied` state to `false` after 2 seconds, effectively hiding the "copied" indicator.
|
|
27
|
+
* This function is called after the user's clipboard is updated with the code content.
|
|
28
|
+
*/
|
|
29
|
+
const timer = setTimeout(() => {
|
|
30
|
+
setCopied(false);
|
|
31
|
+
}, 2000);
|
|
32
|
+
return () => clearTimeout(timer);
|
|
33
|
+
}, [copied]);
|
|
34
|
+
/**
|
|
35
|
+
* Copies the trimmed text content of the `children` prop to the user's clipboard.
|
|
36
|
+
* This function is called when the "Copy" button is clicked in the code block component.
|
|
37
|
+
* It sets the `copied` state to `true` for 2 seconds to display a "copied" indicator.
|
|
38
|
+
*/
|
|
39
|
+
const handleCopy = () => {
|
|
40
|
+
navigator.clipboard.writeText((children ?? '').trim());
|
|
41
|
+
setCopied(true);
|
|
42
|
+
};
|
|
43
|
+
return (_jsx("figure", { children: _jsx("pre", { onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), "data-language": language, children: _jsxs("div", { children: [hover ? (_jsx("button", { className: "copy-button", onClick: handleCopy, children: copied ? (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "20", height: "20", color: "#f0f0f0", fill: "none", children: [_jsx("path", { d: "M22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12Z", stroke: "currentColor", strokeWidth: "1.5" }), _jsx("path", { d: "M8 12.5L10.5 15L16 9", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] })) : (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "20", height: "20", color: "#f0f0f0", fill: "none", children: [_jsx("path", { d: "M9 15C9 12.1716 9 10.7574 9.87868 9.87868C10.7574 9 12.1716 9 15 9L16 9C18.8284 9 20.2426 9 21.1213 9.87868C22 10.7574 22 12.1716 22 15V16C22 18.8284 22 20.2426 21.1213 21.1213C20.2426 22 18.8284 22 16 22H15C12.1716 22 10.7574 22 9.87868 21.1213C9 20.2426 9 18.8284 9 16L9 15Z", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M16.9999 9C16.9975 6.04291 16.9528 4.51121 16.092 3.46243C15.9258 3.25989 15.7401 3.07418 15.5376 2.90796C14.4312 2 12.7875 2 9.5 2C6.21252 2 4.56878 2 3.46243 2.90796C3.25989 3.07417 3.07418 3.25989 2.90796 3.46243C2 4.56878 2 6.21252 2 9.5C2 12.7875 2 14.4312 2.90796 15.5376C3.07417 15.7401 3.25989 15.9258 3.46243 16.092C4.51121 16.9528 6.04291 16.9975 9 16.9999", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] })) })) : (_jsx("span", { className: "lang", children: language })), _jsx("code", { className: `${className} code-block`, "data-line-numbers": true, children: tokens.map((line, i) => (_jsxs("span", { "data-line": true, ...getLineProps({ line }), children: [_jsx("span", { children: " " }), line.map((token, key) => (_jsx("span", { ...getTokenProps({ token }) }, key)))] }, i))) })] }) }) }));
|
|
44
|
+
} }));
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=codeblock2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeblock2.js","sourceRoot":"","sources":["../../src/components/codeblock2.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EACzB,QAAQ,EACR,SAAS,GAAG,EAAE,GACC,EAAsB,EAAE;IACvC,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACpD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEhD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,KAAC,WAAW,cAAE,QAAQ,GAAe,CAAC;IAC/C,CAAC;IAED,OAAO,CACL,KAAC,SAAS,IACR,KAAK,EAAE,MAAM,CAAC,OAAO,EACrB,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,EACrB,QAAQ,EAAE,QAAQ,YAEjB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,IAAI,EAAO,EAAE,EAAE;YACpE,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,IACE,CACP,CAAC,CAAC,CAAC,CACF,eACE,KAAK,EAAC,4BAA4B,EAClC,OAAO,EAAC,WAAW,EACnB,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,KAAK,EAAC,SAAS,EACf,IAAI,EAAC,MAAM,aAEX,eACE,CAAC,EAAC,sRAAsR,EACxR,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,EACF,eACE,CAAC,EAAC,gXAAgX,EAClX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,IACE,CACP,GACM,CACV,CAAC,CAAC,CAAC,CACF,eAAM,SAAS,EAAC,MAAM,YAAE,QAAQ,GAAQ,CACzC,EAED,eAAM,SAAS,EAAE,GAAG,SAAS,aAAa,uCACvC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CACpC,sCAA4B,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,aAChD,+BAAc,EACb,IAAI,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,GAAW,EAAE,EAAE,CAAC,CACrC,kBAAoB,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,IAAjC,GAAG,CAAkC,CACjD,CAAC,KAJiB,CAAC,CAKf,CACR,CAAC,GACG,IACH,GACF,GACC,CACV,CAAC;QACJ,CAAC,GACS,CACb,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { HeadingProps, HeadingProps2 } from
|
|
1
|
+
import { HeadingProps, HeadingProps2 } from '../types/index.js';
|
|
2
2
|
export declare const Heading: ({ variant }: HeadingProps) => ({ children }: HeadingProps2) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,40 +1,26 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { createElement, useMemo } from
|
|
2
|
+
import { createElement, useMemo } from 'react';
|
|
3
|
+
import { generateAnchor } from '../utils/extract-toc.js';
|
|
3
4
|
export const Heading = ({ variant }) => {
|
|
4
5
|
return ({ children }) => {
|
|
5
6
|
const { text, id } = useMemo(() => {
|
|
6
|
-
|
|
7
|
-
const regex = new RegExp("^\\[#.+\\]");
|
|
8
|
-
// split the children into an array of strings based on space
|
|
9
|
-
const childrenArray = children.split(" [#");
|
|
10
|
-
let lastWord = "";
|
|
11
|
-
let restOfTheWords = "";
|
|
12
|
-
let link = "";
|
|
13
|
-
// Check if we have more than one word and if the last word is a link
|
|
14
|
-
if (childrenArray.length > 1 &&
|
|
15
|
-
childrenArray.at(-1).includes("]") &&
|
|
16
|
-
regex.test(`[#${childrenArray.at(-1)}`)) {
|
|
17
|
-
lastWord = childrenArray.pop();
|
|
18
|
-
}
|
|
19
|
-
if (lastWord) {
|
|
20
|
-
link = lastWord.replace("]", "").split(" ").join("-").toLowerCase();
|
|
21
|
-
restOfTheWords = childrenArray[0];
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
link = children.split(" ").join("-").toLowerCase();
|
|
25
|
-
restOfTheWords = children;
|
|
26
|
-
}
|
|
7
|
+
const { id, text } = generateAnchor(children);
|
|
27
8
|
return {
|
|
28
|
-
id: variant ===
|
|
29
|
-
text
|
|
9
|
+
id: variant === 'h1' ? undefined : id,
|
|
10
|
+
text,
|
|
30
11
|
};
|
|
31
12
|
}, [children]);
|
|
32
13
|
const heading = createElement(variant, {
|
|
33
14
|
id,
|
|
34
|
-
className:
|
|
15
|
+
className: 'heading',
|
|
35
16
|
children: text,
|
|
36
17
|
});
|
|
37
|
-
|
|
18
|
+
const handleClick = (e, id) => {
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
const element = document.getElementById(id);
|
|
21
|
+
element?.scrollIntoView({ behavior: 'smooth' });
|
|
22
|
+
};
|
|
23
|
+
return (_jsxs("div", { className: "ra-heading-wrapper", children: [heading, id && (_jsx("a", { href: `#${id}`, onClick: (e) => handleClick(e, id), children: _jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24", color: "#ffffff", fill: "none", children: [_jsx("path", { d: "M10 13.229C10.1416 13.4609 10.3097 13.6804 10.5042 13.8828C11.7117 15.1395 13.5522 15.336 14.9576 14.4722C15.218 14.3121 15.4634 14.1157 15.6872 13.8828L18.9266 10.5114C20.3578 9.02184 20.3578 6.60676 18.9266 5.11718C17.4953 3.6276 15.1748 3.62761 13.7435 5.11718L13.03 5.85978", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }), _jsx("path", { d: "M10.9703 18.14L10.2565 18.8828C8.82526 20.3724 6.50471 20.3724 5.07345 18.8828C3.64218 17.3932 3.64218 14.9782 5.07345 13.4886L8.31287 10.1172C9.74413 8.62761 12.0647 8.6276 13.4959 10.1172C13.6904 10.3195 13.8584 10.539 14 10.7708", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })] }) }))] }));
|
|
38
24
|
};
|
|
39
25
|
};
|
|
40
26
|
//# sourceMappingURL=heading.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heading.js","sourceRoot":"","sources":["../../src/components/heading.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"heading.js","sourceRoot":"","sources":["../../src/components/heading.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,OAAO,EAAgB,EAAE,EAAE;IACnD,OAAO,CAAC,EAAE,QAAQ,EAAiB,EAAE,EAAE;QACrC,MAAM,EAAE,IAAI,EAAE,E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GACrB,IACE,GACJ,CACL,IACG,CACP,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* @param {MDXRendererProps} props - The props for the MDX renderer.
|
|
7
|
-
* @param {React.ReactNode} props.children - The MDX content to render.
|
|
8
|
-
* @param {string} [props.className] - An optional CSS class name to apply to the rendered section.
|
|
9
|
-
* @returns {React.ReactElement} - The rendered MDX content with the custom code block component.
|
|
10
|
-
*/
|
|
11
|
-
declare const MDXRenderer: ({ children: MDXContent, className }: MDXRendererProps) => React.ReactElement;
|
|
12
|
-
export { MDXRenderer };
|
|
1
|
+
import { MDXRenderer } from './renderer.js';
|
|
2
|
+
import { Markdown } from './markdown.js';
|
|
3
|
+
import { TableOfContents } from './toc.js';
|
|
4
|
+
export { Markdown, MDXRenderer, TableOfContents };
|
package/lib/components/index.js
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* @param {MDXRendererProps} props - The props for the MDX renderer.
|
|
9
|
-
* @param {React.ReactNode} props.children - The MDX content to render.
|
|
10
|
-
* @param {string} [props.className] - An optional CSS class name to apply to the rendered section.
|
|
11
|
-
* @returns {React.ReactElement} - The rendered MDX content with the custom code block component.
|
|
12
|
-
*/
|
|
13
|
-
const MDXRenderer = ({ children: MDXContent, className }) => {
|
|
14
|
-
return (_jsx("section", { className: "rasengan-markdown-body " + className, children: _jsx(MDXContent, { components: {
|
|
15
|
-
code: CodeBlock,
|
|
16
|
-
table: Table,
|
|
17
|
-
h1: Heading({ variant: "h1" }),
|
|
18
|
-
h2: Heading({ variant: "h2" }),
|
|
19
|
-
h3: Heading({ variant: "h3" }),
|
|
20
|
-
h4: Heading({ variant: "h4" }),
|
|
21
|
-
h5: Heading({ variant: "h5" }),
|
|
22
|
-
h6: Heading({ variant: "h6" }),
|
|
23
|
-
} }) }));
|
|
24
|
-
};
|
|
25
|
-
export { MDXRenderer };
|
|
1
|
+
// Import statements
|
|
2
|
+
import { MDXRenderer } from './renderer.js';
|
|
3
|
+
import { Markdown } from './markdown.js';
|
|
4
|
+
import { TableOfContents } from './toc.js';
|
|
5
|
+
// Export statements
|
|
6
|
+
export { Markdown, MDXRenderer, TableOfContents };
|
|
26
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,oBAAoB;AACpB,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Table } from './table.js';
|
|
3
|
+
import { Heading } from './heading.js';
|
|
4
|
+
import MarkdownComponent from 'react-markdown';
|
|
5
|
+
import remarkGfm from 'remark-gfm';
|
|
6
|
+
import rehypeStringify from 'rehype-stringify';
|
|
7
|
+
import remarkParse from 'remark-parse';
|
|
8
|
+
import remarkRehype from 'remark-rehype';
|
|
9
|
+
// import rehypePrettyCode from "rehype-pretty-code";
|
|
10
|
+
import { CodeBlock2 } from './codeblock2.js';
|
|
11
|
+
function Markdown({ content, className, }) {
|
|
12
|
+
return (_jsx("section", { className: 'rasengan-markdown-body ' + className, children: _jsx(MarkdownComponent, { children: content, remarkPlugins: [remarkParse, remarkGfm], rehypePlugins: [
|
|
13
|
+
remarkRehype,
|
|
14
|
+
rehypeStringify,
|
|
15
|
+
// [rehypePrettyCode, {
|
|
16
|
+
// }]
|
|
17
|
+
], components: {
|
|
18
|
+
code: CodeBlock2,
|
|
19
|
+
table: Table,
|
|
20
|
+
h1: Heading({ variant: 'h1' }),
|
|
21
|
+
h2: Heading({ variant: 'h2' }),
|
|
22
|
+
h3: Heading({ variant: 'h3' }),
|
|
23
|
+
h4: Heading({ variant: 'h4' }),
|
|
24
|
+
h5: Heading({ variant: 'h5' }),
|
|
25
|
+
h6: Heading({ variant: 'h6' }),
|
|
26
|
+
} }) }));
|
|
27
|
+
}
|
|
28
|
+
export { Markdown };
|
|
29
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/components/markdown.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,iBAAiB,MAAM,gBAAgB,CAAC;AAC/C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,qDAAqD;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,SAAS,QAAQ,CAAC,EAChB,OAAO,EACP,SAAS,GAIV;IACC,OAAO,CACL,kBAAS,SAAS,EAAE,yBAAyB,GAAG,SAAS,YACvD,KAAC,iBAAiB,IAChB,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC,EACvC,aAAa,EAAE;gBACb,YAAY;gBACZ,eAAe;gBACf,uBAAuB;gBAEvB,KAAK;aACN,EACD,UAAU,EAAE;gBACV,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,KAAK;gBACZ,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;aAC/B,GACD,GACM,CACX,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MDXRendererProps } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Renders an MDX content component with a custom code block component.
|
|
5
|
+
*
|
|
6
|
+
* @param {MDXRendererProps} props - The props for the MDX renderer.
|
|
7
|
+
* @param {React.ReactNode} props.children - The MDX content to render.
|
|
8
|
+
* @param {string} [props.className] - An optional CSS class name to apply to the rendered section.
|
|
9
|
+
* @returns {React.ReactElement} - The rendered MDX content with the custom code block component.
|
|
10
|
+
*/
|
|
11
|
+
declare const MDXRenderer: ({ children: MDXContent, className, }: MDXRendererProps) => React.ReactElement;
|
|
12
|
+
export { MDXRenderer };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CodeBlock } from './codeblock.js';
|
|
3
|
+
import { Table } from './table.js';
|
|
4
|
+
import { Heading } from './heading.js';
|
|
5
|
+
import TableOfContents from './toc.js';
|
|
6
|
+
/**
|
|
7
|
+
* Renders an MDX content component with a custom code block component.
|
|
8
|
+
*
|
|
9
|
+
* @param {MDXRendererProps} props - The props for the MDX renderer.
|
|
10
|
+
* @param {React.ReactNode} props.children - The MDX content to render.
|
|
11
|
+
* @param {string} [props.className] - An optional CSS class name to apply to the rendered section.
|
|
12
|
+
* @returns {React.ReactElement} - The rendered MDX content with the custom code block component.
|
|
13
|
+
*/
|
|
14
|
+
const MDXRenderer = ({ children: MDXContent, className, }) => {
|
|
15
|
+
return (_jsxs("section", { className: MDXContent.toc ? 'rasengan-wrapper-with-toc' : 'rasengan-wrapper', children: [_jsx("section", { className: 'rasengan-markdown-body ' + className, children: _jsx(MDXContent, { components: {
|
|
16
|
+
code: CodeBlock,
|
|
17
|
+
table: Table,
|
|
18
|
+
h1: Heading({ variant: 'h1' }),
|
|
19
|
+
h2: Heading({ variant: 'h2' }),
|
|
20
|
+
h3: Heading({ variant: 'h3' }),
|
|
21
|
+
h4: Heading({ variant: 'h4' }),
|
|
22
|
+
h5: Heading({ variant: 'h5' }),
|
|
23
|
+
h6: Heading({ variant: 'h6' }),
|
|
24
|
+
} }) }), MDXContent.toc && (_jsx("aside", { className: "rasengan-toc", children: _jsx(TableOfContents, { items: MDXContent.toc }) }))] }));
|
|
25
|
+
};
|
|
26
|
+
export { MDXRenderer };
|
|
27
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/components/renderer.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,eAAe,MAAM,UAAU,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,WAAW,GAAG,CAAC,EACnB,QAAQ,EAAE,UAAU,EACpB,SAAS,GACQ,EAAsB,EAAE;IACzC,OAAO,CACL,mBACE,SAAS,EACP,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,kBAAkB,aAGnE,kBAAS,SAAS,EAAE,yBAAyB,GAAG,SAAS,YACvD,KAAC,UAAU,IACT,UAAU,EAAE;wBACV,IAAI,EAAE,SAAS;wBACf,KAAK,EAAE,KAAK;wBACZ,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;wBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;wBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;wBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;wBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;wBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qBAC/B,GACD,GACM,EAET,UAAU,CAAC,GAAG,IAAI,CACjB,gBAAO,SAAS,EAAC,cAAc,YAC7B,KAAC,eAAe,IAAC,KAAK,EAAE,UAAU,CAAC,GAAG,GAAI,GACpC,CACT,IACO,CACX,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { ComponentWithTextChildrenProps } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentWithTextChildrenProps } from '../types/index.js';
|
|
3
3
|
export declare const Table: ({ children, }: ComponentWithTextChildrenProps) => React.ReactElement;
|
package/lib/components/table.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
export const Table = ({ children, }) => {
|
|
3
|
-
return (_jsx("div", { className:
|
|
3
|
+
return (_jsx("div", { className: "ra-table-wrapper", children: _jsx("table", { children: children }) }));
|
|
4
4
|
};
|
|
5
5
|
//# sourceMappingURL=table.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/components/table.tsx"],"names":[],"mappings":";AAGA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/components/table.tsx"],"names":[],"mappings":";AAGA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EACpB,QAAQ,GACuB,EAAsB,EAAE;IACvD,OAAO,CACL,cAAK,SAAS,EAAC,kBAAkB,YAC/B,0BAAQ,QAAQ,GAAS,GACrB,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
|
3
|
+
export const TableOfContents = ({ items }) => {
|
|
4
|
+
const [activeId, setActiveId] = useState(null);
|
|
5
|
+
const observerRef = useRef(null);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
// Create an Intersection Observer to track which section is in view
|
|
8
|
+
const observerOptions = {
|
|
9
|
+
root: null,
|
|
10
|
+
rootMargin: '0px',
|
|
11
|
+
threshold: 0.4, // Trigger when 40% of the section is visible
|
|
12
|
+
};
|
|
13
|
+
observerRef.current = new IntersectionObserver((entries) => {
|
|
14
|
+
entries.forEach((entry) => {
|
|
15
|
+
if (entry.isIntersecting) {
|
|
16
|
+
const rect = entry.boundingClientRect;
|
|
17
|
+
if (rect.top >= 0) {
|
|
18
|
+
// Scrolling Down: Set the first intersecting element as active
|
|
19
|
+
setActiveId(entry.target.id);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
// Sort entries by bottom position when scrolling down
|
|
24
|
+
const sortedEntries = entries
|
|
25
|
+
.filter((entry) => entry.isIntersecting)
|
|
26
|
+
.sort((a, b) => b.boundingClientRect.top - a.boundingClientRect.top);
|
|
27
|
+
if (sortedEntries.length > 0) {
|
|
28
|
+
setActiveId(sortedEntries[0].target.id);
|
|
29
|
+
}
|
|
30
|
+
}, observerOptions);
|
|
31
|
+
// Observe all sections with IDs matching TOC anchors
|
|
32
|
+
items.forEach((item) => {
|
|
33
|
+
// Observe items of level 2
|
|
34
|
+
const element = document.getElementById(item.anchor.id);
|
|
35
|
+
if (element && observerRef.current) {
|
|
36
|
+
observerRef.current.observe(element);
|
|
37
|
+
}
|
|
38
|
+
// Observe items of level 3
|
|
39
|
+
item.children.forEach((item) => {
|
|
40
|
+
const element = document.getElementById(item.anchor.id);
|
|
41
|
+
if (element && observerRef.current) {
|
|
42
|
+
observerRef.current.observe(element);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
// Cleanup observer on unmount
|
|
47
|
+
return () => {
|
|
48
|
+
if (observerRef.current) {
|
|
49
|
+
observerRef.current.disconnect();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}, [items]);
|
|
53
|
+
const renderTOCItems = useCallback((items) => {
|
|
54
|
+
return items.map((item, index) => (_jsxs(React.Fragment, { children: [_jsx(Item, { item: item, activeId: activeId, onActive: setActiveId }), item.children && item.children.length > 0 && (_jsx("div", { className: "toc-item--children", children: renderTOCItems(item.children) }))] }, index)));
|
|
55
|
+
}, [items, activeId]);
|
|
56
|
+
return (_jsxs("div", { className: "table-of-contents", children: [_jsx("h2", { className: "title", children: "ON THIS PAGE" }), _jsx("div", { className: "items-container", children: renderTOCItems(items) }), _jsx("div", { className: "w-full h-[500px] mt-10 bg-red-200", style: { height: 500 } })] }));
|
|
57
|
+
};
|
|
58
|
+
const Item = ({ item, activeId, onActive }) => {
|
|
59
|
+
const handleClick = (e, id) => {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
onActive(id);
|
|
62
|
+
const element = document.getElementById(id);
|
|
63
|
+
element?.scrollIntoView({ behavior: 'smooth' });
|
|
64
|
+
};
|
|
65
|
+
return (_jsx("div", { className: `
|
|
66
|
+
toc-item
|
|
67
|
+
${item.level === 2 ? 'level2' : 'level3'}
|
|
68
|
+
${activeId === item.anchor.id ? 'active' : ''}
|
|
69
|
+
`, children: _jsx("a", { href: `#${item.anchor.id}`, onClick: (e) => handleClick(e, item.anchor.id), children: _jsx("div", { className: "toc-item--title", children: item.anchor.text }) }) }, item.anchor.id));
|
|
70
|
+
};
|
|
71
|
+
export default TableOfContents;
|
|
72
|
+
//# sourceMappingURL=toc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc.js","sourceRoot":"","sources":["../../src/components/toc.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAOxE,MAAM,CAAC,MAAM,eAAe,GAAmC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC3E,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAC9D,MAAM,WAAW,GAAG,MAAM,CAA8B,IAAI,CAAC,CAAC;IAE9D,SAAS,CAAC,GAAG,EAAE;QACb,oEAAoE;QACpE,MAAM,eAAe,GAAG;YACtB,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,KAAK;YACjB,SAAS,EAAE,GAAG,EAAE,6CAA6C;SAC9D,CAAC;QAEF,WAAW,CAAC,OAAO,GAAG,IAAI,oBAAoB,CAAC,CAAC,OAAO,EAAE,EAAE;YACzD,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;gBACxB,IAAI,KAAK,CAAC,cAAc,EAAE,CAAC;oBACzB,MAAM,IAAI,GAAG,KAAK,CAAC,kBAAkB,CAAC;oBAEtC,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;wBAClB,+DAA+D;wBAC/D,WAAW,CAAC,KAAK,CA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CAAC,EAAE,CAAC,CAAC;QAC5C,OAAO,EAAE,cAAc,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;IAClD,CAAC,CAAC;IAEF,OAAO,CACL,cAEE,SAAS,EAAE;;YAEL,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;YACtC,QAAQ,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;SAC9C,YAEH,YACE,IAAI,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAC1B,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,YAE9C,cAAK,SAAS,EAAC,iBAAiB,YAAE,IAAI,CAAC,MAAM,CAAC,IAAI,GAAO,GACvD,IAZC,IAAI,CAAC,MAAM,CAAC,EAAE,CAaf,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* This package is inspired by @mdx-js/rollup to provide a custom implement of the MDX plugin for RasenganJs.
|
|
7
7
|
*/
|
|
8
|
+
import { extractTOC } from './utils/extract-toc.js';
|
|
8
9
|
export * from './types/index.js';
|
|
9
10
|
export * from './components/index.js';
|
|
10
|
-
|
|
11
|
-
export default plugin;
|
|
11
|
+
export { extractTOC };
|
package/lib/index.js
CHANGED
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
*
|
|
6
6
|
* This package is inspired by @mdx-js/rollup to provide a custom implement of the MDX plugin for RasenganJs.
|
|
7
7
|
*/
|
|
8
|
+
// Import statements
|
|
9
|
+
import { extractTOC } from './utils/extract-toc.js';
|
|
10
|
+
// import { defineMDXConfig } from "./utils/define-mdx-config.js";
|
|
11
|
+
// Export statements
|
|
8
12
|
export * from './types/index.js';
|
|
9
13
|
export * from './components/index.js';
|
|
10
|
-
|
|
11
|
-
export default plugin;
|
|
14
|
+
export { extractTOC };
|
|
12
15
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,oBAAoB;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,kEAAkE;AAElE,oBAAoB;AACpB,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,CAAC"}
|