fumadocs-core 16.0.4 → 16.0.6
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/{chunk-H2GMUTQG.js → chunk-N2ZQXKIX.js} +3 -2
- package/dist/content/toc.d.ts +1 -1
- package/dist/dynamic-link.js +1 -1
- package/dist/i18n/middleware.js +1 -1
- package/dist/link.js +1 -1
- package/dist/mdx-plugins/index.js +4 -4
- package/dist/toc.d.ts +3 -4
- package/dist/toc.js +97 -76
- package/package.json +10 -10
|
@@ -12,6 +12,7 @@ var Link2 = forwardRef(
|
|
|
12
12
|
external = href.match(/^\w+:/) || // protocol relative URL
|
|
13
13
|
href.startsWith("//"),
|
|
14
14
|
prefetch,
|
|
15
|
+
children,
|
|
15
16
|
...props
|
|
16
17
|
}, ref) => {
|
|
17
18
|
if (external) {
|
|
@@ -23,11 +24,11 @@ var Link2 = forwardRef(
|
|
|
23
24
|
rel: "noreferrer noopener",
|
|
24
25
|
target: "_blank",
|
|
25
26
|
...props,
|
|
26
|
-
children
|
|
27
|
+
children
|
|
27
28
|
}
|
|
28
29
|
);
|
|
29
30
|
}
|
|
30
|
-
return /* @__PURE__ */ jsx(Link, { ref, href, prefetch, ...props });
|
|
31
|
+
return /* @__PURE__ */ jsx(Link, { ref, href, prefetch, ...props, children });
|
|
31
32
|
}
|
|
32
33
|
);
|
|
33
34
|
Link2.displayName = "Link";
|
package/dist/content/toc.d.ts
CHANGED
package/dist/dynamic-link.js
CHANGED
package/dist/i18n/middleware.js
CHANGED
|
@@ -12,7 +12,7 @@ function getLocale(request, locales, defaultLanguage) {
|
|
|
12
12
|
return matchLocale(languages, locales, defaultLanguage);
|
|
13
13
|
}
|
|
14
14
|
var defaultFormat = (locale, path) => {
|
|
15
|
-
return `/${locale}
|
|
15
|
+
return `/${locale}${path}`;
|
|
16
16
|
};
|
|
17
17
|
function createI18nMiddleware({
|
|
18
18
|
languages,
|
package/dist/link.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defaultThemes,
|
|
3
|
-
getHighlighter
|
|
4
|
-
} from "../chunk-XN2LKXFZ.js";
|
|
5
1
|
import {
|
|
6
2
|
flattenNode,
|
|
7
3
|
remarkHeading
|
|
8
4
|
} from "../chunk-QMATWJ5F.js";
|
|
5
|
+
import {
|
|
6
|
+
defaultThemes,
|
|
7
|
+
getHighlighter
|
|
8
|
+
} from "../chunk-XN2LKXFZ.js";
|
|
9
9
|
import "../chunk-U67V476Y.js";
|
|
10
10
|
|
|
11
11
|
// src/mdx-plugins/index.ts
|
package/dist/toc.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import { ReactNode, RefObject, AnchorHTMLAttributes } from 'react';
|
|
3
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, RefObject, ComponentProps } from 'react';
|
|
4
3
|
|
|
5
4
|
interface TOCItemType {
|
|
6
5
|
title: ReactNode;
|
|
@@ -35,10 +34,10 @@ interface ScrollProviderProps {
|
|
|
35
34
|
}
|
|
36
35
|
declare function ScrollProvider({ containerRef, children, }: ScrollProviderProps): react_jsx_runtime.JSX.Element;
|
|
37
36
|
declare function AnchorProvider({ toc, single, children, }: AnchorProviderProps): react_jsx_runtime.JSX.Element;
|
|
38
|
-
interface TOCItemProps extends Omit<
|
|
37
|
+
interface TOCItemProps extends Omit<ComponentProps<'a'>, 'href'> {
|
|
39
38
|
href: string;
|
|
40
39
|
onActiveChange?: (v: boolean) => void;
|
|
41
40
|
}
|
|
42
|
-
declare
|
|
41
|
+
declare function TOCItem({ ref, onActiveChange, ...props }: TOCItemProps): react_jsx_runtime.JSX.Element;
|
|
43
42
|
|
|
44
43
|
export { AnchorProvider, type AnchorProviderProps, ScrollProvider, type ScrollProviderProps, TOCItem, type TOCItemProps, type TOCItemType, type TableOfContents, useActiveAnchor, useActiveAnchors };
|
package/dist/toc.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
useOnChange
|
|
4
|
-
} from "./chunk-EMWGTXSW.js";
|
|
5
2
|
import "./chunk-U67V476Y.js";
|
|
6
3
|
|
|
7
4
|
// src/toc.tsx
|
|
8
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
createContext,
|
|
7
|
+
useContext,
|
|
8
|
+
useEffect,
|
|
9
|
+
useEffectEvent,
|
|
10
|
+
useLayoutEffect,
|
|
11
|
+
useMemo,
|
|
12
|
+
useRef,
|
|
13
|
+
useState
|
|
14
|
+
} from "react";
|
|
9
15
|
import scrollIntoView from "scroll-into-view-if-needed";
|
|
10
16
|
|
|
11
17
|
// src/utils/merge-refs.ts
|
|
@@ -14,60 +20,13 @@ function mergeRefs(...refs) {
|
|
|
14
20
|
refs.forEach((ref) => {
|
|
15
21
|
if (typeof ref === "function") {
|
|
16
22
|
ref(value);
|
|
17
|
-
} else if (ref
|
|
23
|
+
} else if (ref != null) {
|
|
18
24
|
ref.current = value;
|
|
19
25
|
}
|
|
20
26
|
});
|
|
21
27
|
};
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
// src/utils/use-anchor-observer.ts
|
|
25
|
-
import { useEffect, useState } from "react";
|
|
26
|
-
function useAnchorObserver(watch, single) {
|
|
27
|
-
const [activeAnchor, setActiveAnchor] = useState([]);
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
let visible = [];
|
|
30
|
-
const observer = new IntersectionObserver(
|
|
31
|
-
(entries) => {
|
|
32
|
-
for (const entry of entries) {
|
|
33
|
-
if (entry.isIntersecting && !visible.includes(entry.target.id)) {
|
|
34
|
-
visible = [...visible, entry.target.id];
|
|
35
|
-
} else if (!entry.isIntersecting && visible.includes(entry.target.id)) {
|
|
36
|
-
visible = visible.filter((v) => v !== entry.target.id);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (visible.length > 0) setActiveAnchor(visible);
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
rootMargin: single ? "-80px 0% -70% 0%" : `-20px 0% -40% 0%`,
|
|
43
|
-
threshold: 1
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
function onScroll() {
|
|
47
|
-
const element = document.scrollingElement;
|
|
48
|
-
if (!element) return;
|
|
49
|
-
const top = element.scrollTop;
|
|
50
|
-
if (top <= 0 && single) setActiveAnchor(watch.slice(0, 1));
|
|
51
|
-
else if (top + element.clientHeight >= element.scrollHeight - 6) {
|
|
52
|
-
setActiveAnchor((active) => {
|
|
53
|
-
return active.length > 0 && !single ? watch.slice(watch.indexOf(active[0])) : watch.slice(-1);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
for (const heading of watch) {
|
|
58
|
-
const element = document.getElementById(heading);
|
|
59
|
-
if (element) observer.observe(element);
|
|
60
|
-
}
|
|
61
|
-
onScroll();
|
|
62
|
-
window.addEventListener("scroll", onScroll);
|
|
63
|
-
return () => {
|
|
64
|
-
window.removeEventListener("scroll", onScroll);
|
|
65
|
-
observer.disconnect();
|
|
66
|
-
};
|
|
67
|
-
}, [single, watch]);
|
|
68
|
-
return single ? activeAnchor.slice(0, 1) : activeAnchor;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
30
|
// src/toc.tsx
|
|
72
31
|
import { jsx } from "react/jsx-runtime";
|
|
73
32
|
var ActiveAnchorContext = createContext([]);
|
|
@@ -75,7 +34,7 @@ var ScrollContext = createContext({
|
|
|
75
34
|
current: null
|
|
76
35
|
});
|
|
77
36
|
function useActiveAnchor() {
|
|
78
|
-
return useContext(ActiveAnchorContext)
|
|
37
|
+
return useContext(ActiveAnchorContext)[0];
|
|
79
38
|
}
|
|
80
39
|
function useActiveAnchors() {
|
|
81
40
|
return useContext(ActiveAnchorContext);
|
|
@@ -96,31 +55,93 @@ function AnchorProvider({
|
|
|
96
55
|
}, [toc]);
|
|
97
56
|
return /* @__PURE__ */ jsx(ActiveAnchorContext.Provider, { value: useAnchorObserver(headings, single), children });
|
|
98
57
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
58
|
+
function TOCItem({
|
|
59
|
+
ref,
|
|
60
|
+
onActiveChange = () => null,
|
|
61
|
+
...props
|
|
62
|
+
}) {
|
|
63
|
+
const containerRef = useContext(ScrollContext);
|
|
64
|
+
const anchorRef = useRef(null);
|
|
65
|
+
const activeOrder = useActiveAnchors().indexOf(props.href.slice(1));
|
|
66
|
+
const isActive = activeOrder !== -1;
|
|
67
|
+
const shouldScroll = activeOrder === 0;
|
|
68
|
+
const onActiveChangeEvent = useEffectEvent(onActiveChange);
|
|
69
|
+
useLayoutEffect(() => {
|
|
70
|
+
const anchor = anchorRef.current;
|
|
71
|
+
const container = containerRef.current;
|
|
72
|
+
if (container && anchor && shouldScroll)
|
|
73
|
+
scrollIntoView(anchor, {
|
|
74
|
+
behavior: "smooth",
|
|
75
|
+
block: "center",
|
|
76
|
+
inline: "center",
|
|
77
|
+
scrollMode: "always",
|
|
78
|
+
boundary: container
|
|
79
|
+
});
|
|
80
|
+
}, [containerRef, shouldScroll]);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
return () => onActiveChangeEvent(isActive);
|
|
83
|
+
}, [isActive]);
|
|
84
|
+
return /* @__PURE__ */ jsx("a", { ref: mergeRefs(anchorRef, ref), "data-active": isActive, ...props, children: props.children });
|
|
85
|
+
}
|
|
86
|
+
function useAnchorObserver(watch, single) {
|
|
87
|
+
const observerRef = useRef(null);
|
|
88
|
+
const [activeAnchor, setActiveAnchor] = useState(() => []);
|
|
89
|
+
const stateRef = useRef(null);
|
|
90
|
+
const onChange = useEffectEvent((entries) => {
|
|
91
|
+
stateRef.current ??= {
|
|
92
|
+
visible: /* @__PURE__ */ new Set()
|
|
93
|
+
};
|
|
94
|
+
const state = stateRef.current;
|
|
95
|
+
for (const entry of entries) {
|
|
96
|
+
if (entry.isIntersecting) {
|
|
97
|
+
state.visible.add(entry.target.id);
|
|
98
|
+
} else {
|
|
99
|
+
state.visible.delete(entry.target.id);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (state.visible.size === 0) {
|
|
103
|
+
const viewTop = entries[0].rootBounds.top;
|
|
104
|
+
let fallback;
|
|
105
|
+
let min = -1;
|
|
106
|
+
for (const id of watch) {
|
|
107
|
+
const element = document.getElementById(id);
|
|
108
|
+
if (!element) continue;
|
|
109
|
+
const d = Math.abs(viewTop - element.getBoundingClientRect().top);
|
|
110
|
+
if (min === -1 || d < min) {
|
|
111
|
+
fallback = element;
|
|
112
|
+
min = d;
|
|
113
|
+
}
|
|
117
114
|
}
|
|
118
|
-
|
|
115
|
+
setActiveAnchor(fallback ? [fallback.id] : []);
|
|
116
|
+
} else {
|
|
117
|
+
const items = watch.filter((item) => state.visible.has(item));
|
|
118
|
+
setActiveAnchor(single ? items.slice(0, 1) : items);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (observerRef.current) return;
|
|
123
|
+
observerRef.current = new IntersectionObserver(onChange, {
|
|
124
|
+
rootMargin: "0px",
|
|
125
|
+
threshold: 0.98
|
|
119
126
|
});
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
return () => {
|
|
128
|
+
observerRef.current?.disconnect();
|
|
129
|
+
observerRef.current = null;
|
|
130
|
+
};
|
|
131
|
+
}, []);
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
const observer = observerRef.current;
|
|
134
|
+
if (!observer) return;
|
|
135
|
+
const elements = watch.flatMap(
|
|
136
|
+
(heading) => document.getElementById(heading) ?? []
|
|
137
|
+
);
|
|
138
|
+
for (const element of elements) observer.observe(element);
|
|
139
|
+
return () => {
|
|
140
|
+
for (const element of elements) observer.unobserve(element);
|
|
141
|
+
};
|
|
142
|
+
}, [watch]);
|
|
143
|
+
return activeAnchor;
|
|
144
|
+
}
|
|
124
145
|
export {
|
|
125
146
|
AnchorProvider,
|
|
126
147
|
ScrollProvider,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-core",
|
|
3
|
-
"version": "16.0.
|
|
3
|
+
"version": "16.0.6",
|
|
4
4
|
"description": "The library for building a documentation website in any React.js framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fumadocs",
|
|
@@ -103,8 +103,8 @@
|
|
|
103
103
|
"dependencies": {
|
|
104
104
|
"@formatjs/intl-localematcher": "^0.6.2",
|
|
105
105
|
"@orama/orama": "^3.1.16",
|
|
106
|
-
"@shikijs/rehype": "^3.
|
|
107
|
-
"@shikijs/transformers": "^3.
|
|
106
|
+
"@shikijs/rehype": "^3.14.0",
|
|
107
|
+
"@shikijs/transformers": "^3.14.0",
|
|
108
108
|
"github-slugger": "^2.0.0",
|
|
109
109
|
"hast-util-to-estree": "^3.1.3",
|
|
110
110
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
@@ -116,33 +116,33 @@
|
|
|
116
116
|
"remark-gfm": "^4.0.1",
|
|
117
117
|
"remark-rehype": "^11.1.2",
|
|
118
118
|
"scroll-into-view-if-needed": "^3.1.0",
|
|
119
|
-
"shiki": "^3.
|
|
119
|
+
"shiki": "^3.14.0",
|
|
120
120
|
"unist-util-visit": "^5.0.0"
|
|
121
121
|
},
|
|
122
122
|
"devDependencies": {
|
|
123
123
|
"@mdx-js/mdx": "^3.1.1",
|
|
124
124
|
"@mixedbread/sdk": "^0.35.1",
|
|
125
125
|
"@orama/core": "^1.2.13",
|
|
126
|
-
"@tanstack/react-router": "^1.133.
|
|
126
|
+
"@tanstack/react-router": "^1.133.36",
|
|
127
127
|
"@types/estree-jsx": "^1.0.5",
|
|
128
128
|
"@types/hast": "^3.0.4",
|
|
129
129
|
"@types/mdast": "^4.0.4",
|
|
130
130
|
"@types/negotiator": "^0.6.4",
|
|
131
|
-
"@types/node": "24.9.
|
|
131
|
+
"@types/node": "24.9.2",
|
|
132
132
|
"@types/react": "^19.2.2",
|
|
133
133
|
"@types/react-dom": "^19.2.2",
|
|
134
|
-
"algoliasearch": "5.
|
|
135
|
-
"lucide-react": "^0.
|
|
134
|
+
"algoliasearch": "5.41.0",
|
|
135
|
+
"lucide-react": "^0.548.0",
|
|
136
136
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
137
137
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
138
|
-
"next": "16.0.
|
|
138
|
+
"next": "16.0.1",
|
|
139
139
|
"react-router": "^7.9.4",
|
|
140
140
|
"remark-mdx": "^3.1.1",
|
|
141
141
|
"remove-markdown": "^0.6.2",
|
|
142
142
|
"typescript": "^5.9.3",
|
|
143
143
|
"unified": "^11.0.5",
|
|
144
144
|
"vfile": "^6.0.3",
|
|
145
|
-
"waku": "^0.
|
|
145
|
+
"waku": "^0.27.0",
|
|
146
146
|
"eslint-config-custom": "0.0.0",
|
|
147
147
|
"tsconfig": "0.0.0"
|
|
148
148
|
},
|