fumadocs-core 15.0.15 → 15.0.16
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.
|
@@ -9,9 +9,11 @@ import {
|
|
|
9
9
|
useId,
|
|
10
10
|
useMemo,
|
|
11
11
|
useRef,
|
|
12
|
-
|
|
12
|
+
use,
|
|
13
|
+
useState,
|
|
14
|
+
useLayoutEffect
|
|
13
15
|
} from "react";
|
|
14
|
-
import {
|
|
16
|
+
import { jsx } from "react/jsx-runtime";
|
|
15
17
|
var jsEngine;
|
|
16
18
|
function getHighlightOptions(from) {
|
|
17
19
|
if (from.engine) return from;
|
|
@@ -30,7 +32,7 @@ function useShiki(code, {
|
|
|
30
32
|
withPrerenderScript = false,
|
|
31
33
|
...options
|
|
32
34
|
}, deps) {
|
|
33
|
-
const
|
|
35
|
+
const markupId = useId();
|
|
34
36
|
const key = useMemo(
|
|
35
37
|
() => deps ? JSON.stringify(deps) : `${options.lang}:${code}`,
|
|
36
38
|
[code, deps, options.lang]
|
|
@@ -42,27 +44,19 @@ function useShiki(code, {
|
|
|
42
44
|
});
|
|
43
45
|
const [rendered, setRendered] = useState(() => {
|
|
44
46
|
if (defaultValue) return defaultValue;
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
] });
|
|
47
|
+
const element = withPrerenderScript && typeof document !== "undefined" ? document.querySelector(`[data-markup-id="${markupId}"]`) : null;
|
|
48
|
+
const attr = element?.getAttribute("data-markup");
|
|
49
|
+
if (attr) {
|
|
50
|
+
const hast = JSON.parse(attr);
|
|
51
|
+
return renderHighlightWithMarkup(markupId, hast, shikiOptions, attr);
|
|
51
52
|
}
|
|
52
53
|
currentTask.current = void 0;
|
|
53
54
|
const Pre = options.components?.pre ?? "pre";
|
|
54
55
|
const Code = options.components?.code ?? "code";
|
|
55
56
|
return /* @__PURE__ */ jsx(Pre, { children: /* @__PURE__ */ jsx(Code, { children: code }) });
|
|
56
57
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
60
|
-
withPrerenderScript && /* @__PURE__ */ jsx(PrerenderScript, { scriptKey, tree }),
|
|
61
|
-
_renderHighlight(tree, shikiOptions)
|
|
62
|
-
] });
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
if (!currentTask.current || currentTask.current.key !== key) {
|
|
58
|
+
useLayoutEffect(() => {
|
|
59
|
+
if (currentTask.current?.key === key) return;
|
|
66
60
|
if (currentTask.current) {
|
|
67
61
|
currentTask.current.aborted = true;
|
|
68
62
|
}
|
|
@@ -74,15 +68,32 @@ function useShiki(code, {
|
|
|
74
68
|
void highlight(code, shikiOptions).then((result) => {
|
|
75
69
|
if (!task.aborted) setRendered(result);
|
|
76
70
|
});
|
|
71
|
+
}, [key]);
|
|
72
|
+
if (typeof window === "undefined") {
|
|
73
|
+
return use(
|
|
74
|
+
_highlight(code, shikiOptions).then(
|
|
75
|
+
(tree) => renderHighlightWithMarkup(markupId, tree, shikiOptions)
|
|
76
|
+
)
|
|
77
|
+
);
|
|
77
78
|
}
|
|
78
79
|
return rendered;
|
|
79
80
|
}
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
tree
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
function renderHighlightWithMarkup(id, tree, shikiOptions, rawAttr) {
|
|
82
|
+
const Pre = shikiOptions.components?.pre ?? "pre";
|
|
83
|
+
return _renderHighlight(tree, {
|
|
84
|
+
...shikiOptions,
|
|
85
|
+
components: {
|
|
86
|
+
...shikiOptions.components,
|
|
87
|
+
pre: (props) => /* @__PURE__ */ jsx(
|
|
88
|
+
Pre,
|
|
89
|
+
{
|
|
90
|
+
...props,
|
|
91
|
+
"data-markup-id": id,
|
|
92
|
+
"data-markup": rawAttr ?? JSON.stringify(tree)
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
});
|
|
86
97
|
}
|
|
87
98
|
|
|
88
99
|
export {
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { ReactNode, DependencyList } from 'react';
|
|
2
2
|
import { HighlightOptions } from './index.js';
|
|
3
|
-
import { Root } from 'hast';
|
|
4
3
|
import 'shiki';
|
|
5
4
|
import 'shiki/themes';
|
|
6
5
|
import 'hast-util-to-jsx-runtime';
|
|
7
6
|
|
|
8
|
-
declare global {
|
|
9
|
-
interface Window {
|
|
10
|
-
_use_shiki?: Map<string, Root>;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
7
|
declare function useShiki(code: string, { defaultValue, withPrerenderScript, ...options }: HighlightOptions & {
|
|
14
8
|
withPrerenderScript?: boolean;
|
|
15
9
|
defaultValue?: ReactNode;
|
package/dist/highlight/client.js
CHANGED
package/dist/utils/use-shiki.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-core",
|
|
3
|
-
"version": "15.0.
|
|
3
|
+
"version": "15.0.16",
|
|
4
4
|
"description": "The library for building a documentation website in Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -90,12 +90,12 @@
|
|
|
90
90
|
],
|
|
91
91
|
"dependencies": {
|
|
92
92
|
"@formatjs/intl-localematcher": "^0.6.0",
|
|
93
|
-
"@orama/orama": "^3.1.
|
|
93
|
+
"@orama/orama": "^3.1.2",
|
|
94
94
|
"@shikijs/rehype": "^3.1.0",
|
|
95
95
|
"@shikijs/transformers": "^3.1.0",
|
|
96
96
|
"github-slugger": "^2.0.0",
|
|
97
|
-
"hast-util-to-estree": "^3.1.
|
|
98
|
-
"hast-util-to-jsx-runtime": "^2.3.
|
|
97
|
+
"hast-util-to-estree": "^3.1.3",
|
|
98
|
+
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
99
99
|
"image-size": "^2.0.0",
|
|
100
100
|
"negotiator": "^1.0.0",
|
|
101
101
|
"react-remove-scroll": "^2.6.3",
|
|
@@ -113,13 +113,13 @@
|
|
|
113
113
|
"@types/hast": "^3.0.4",
|
|
114
114
|
"@types/mdast": "^4.0.3",
|
|
115
115
|
"@types/negotiator": "^0.6.3",
|
|
116
|
-
"@types/node": "22.13.
|
|
116
|
+
"@types/node": "22.13.10",
|
|
117
117
|
"@types/react": "^19.0.10",
|
|
118
118
|
"@types/react-dom": "^19.0.4",
|
|
119
119
|
"algoliasearch": "4.24.0",
|
|
120
120
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
121
121
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
122
|
-
"next": "^15.2.
|
|
122
|
+
"next": "^15.2.1",
|
|
123
123
|
"remark-mdx": "^3.1.0",
|
|
124
124
|
"remark-rehype": "^11.1.1",
|
|
125
125
|
"typescript": "^5.8.2",
|