fumadocs-core 8.0.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/breadcrumb.d.ts +11 -0
- package/dist/breadcrumb.js +47 -0
- package/dist/chunk-2ZGUSAWB.js +12 -0
- package/dist/chunk-AFKH746E.js +40 -0
- package/dist/chunk-GT3Y35O6.js +46 -0
- package/dist/chunk-WEAGW6MQ.js +63 -0
- package/dist/dynamic-link.d.ts +14 -0
- package/dist/dynamic-link.js +33 -0
- package/dist/get-toc-YF_TdazL.d.ts +14 -0
- package/dist/link.d.ts +24 -0
- package/dist/link.js +7 -0
- package/dist/mdx-plugins/index.d.ts +89 -0
- package/dist/mdx-plugins/index.js +353 -0
- package/dist/middleware.d.ts +10 -0
- package/dist/middleware.js +43 -0
- package/dist/page-tree-izSPERQk.d.ts +37 -0
- package/dist/remark-structure-RwYPDA6M.d.ts +34 -0
- package/dist/search/client.d.ts +13 -0
- package/dist/search/client.js +52 -0
- package/dist/search/server.d.ts +51 -0
- package/dist/search/server.js +209 -0
- package/dist/search/shared.d.ts +8 -0
- package/dist/search/shared.js +0 -0
- package/dist/search-algolia/client.d.ts +28 -0
- package/dist/search-algolia/client.js +68 -0
- package/dist/search-algolia/server.d.ts +45 -0
- package/dist/search-algolia/server.js +68 -0
- package/dist/server/index.d.ts +57 -0
- package/dist/server/index.js +148 -0
- package/dist/sidebar.d.ts +19 -0
- package/dist/sidebar.js +88 -0
- package/dist/source/index.d.ts +171 -0
- package/dist/source/index.js +389 -0
- package/dist/toc.d.ts +20 -0
- package/dist/toc.js +113 -0
- package/package.json +158 -0
package/dist/toc.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__objRest,
|
|
3
|
+
__spreadProps,
|
|
4
|
+
__spreadValues
|
|
5
|
+
} from "./chunk-WEAGW6MQ.js";
|
|
6
|
+
|
|
7
|
+
// src/toc.tsx
|
|
8
|
+
import {
|
|
9
|
+
createContext,
|
|
10
|
+
forwardRef,
|
|
11
|
+
useContext,
|
|
12
|
+
useEffect as useEffect2,
|
|
13
|
+
useMemo,
|
|
14
|
+
useRef
|
|
15
|
+
} from "react";
|
|
16
|
+
import scrollIntoView from "scroll-into-view-if-needed";
|
|
17
|
+
|
|
18
|
+
// src/utils/merge-refs.ts
|
|
19
|
+
function mergeRefs(...refs) {
|
|
20
|
+
return (value) => {
|
|
21
|
+
refs.forEach((ref) => {
|
|
22
|
+
if (typeof ref === "function") {
|
|
23
|
+
ref(value);
|
|
24
|
+
} else if (ref !== null) {
|
|
25
|
+
ref.current = value;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/utils/use-anchor-observer.ts
|
|
32
|
+
import { useEffect, useState } from "react";
|
|
33
|
+
function useAnchorObserver(watch) {
|
|
34
|
+
const [activeAnchor, setActiveAnchor] = useState();
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const observer = new IntersectionObserver(
|
|
37
|
+
(entries) => {
|
|
38
|
+
setActiveAnchor((f) => {
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
const aboveHalf = window.innerHeight / 2 > entry.boundingClientRect.y;
|
|
41
|
+
const active = aboveHalf && entry.isIntersecting;
|
|
42
|
+
if (active) {
|
|
43
|
+
return entry.target.id;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return f != null ? f : watch[0];
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
{ rootMargin: `0% 0% -80% 0%` }
|
|
50
|
+
);
|
|
51
|
+
for (const heading of watch) {
|
|
52
|
+
const element = document.getElementById(heading);
|
|
53
|
+
if (element !== null) {
|
|
54
|
+
observer.observe(element);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return () => {
|
|
58
|
+
observer.disconnect();
|
|
59
|
+
};
|
|
60
|
+
}, [watch]);
|
|
61
|
+
return activeAnchor;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/toc.tsx
|
|
65
|
+
import { jsx } from "react/jsx-runtime";
|
|
66
|
+
var ActiveAnchorContext = createContext({
|
|
67
|
+
activeAnchor: void 0,
|
|
68
|
+
containerRef: { current: null }
|
|
69
|
+
});
|
|
70
|
+
var useActiveAnchor = (url) => {
|
|
71
|
+
const { activeAnchor } = useContext(ActiveAnchorContext);
|
|
72
|
+
return activeAnchor === url.split("#")[1];
|
|
73
|
+
};
|
|
74
|
+
var TOCProvider = forwardRef(
|
|
75
|
+
(_a, ref) => {
|
|
76
|
+
var _b = _a, { toc } = _b, props = __objRest(_b, ["toc"]);
|
|
77
|
+
const headings = useMemo(() => {
|
|
78
|
+
return toc.map((item) => item.url.split("#")[1]);
|
|
79
|
+
}, [toc]);
|
|
80
|
+
const containerRef = useRef(null);
|
|
81
|
+
const mergedRef = mergeRefs(containerRef, ref);
|
|
82
|
+
const activeAnchor = useAnchorObserver(headings);
|
|
83
|
+
return /* @__PURE__ */ jsx("div", __spreadProps(__spreadValues({ ref: mergedRef }, props), { children: /* @__PURE__ */ jsx(ActiveAnchorContext.Provider, { value: { containerRef, activeAnchor }, children: props.children }) }));
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
TOCProvider.displayName = "TOCProvider";
|
|
87
|
+
var TOCItem = forwardRef(
|
|
88
|
+
(props, ref) => {
|
|
89
|
+
const { containerRef } = useContext(ActiveAnchorContext);
|
|
90
|
+
const active = useActiveAnchor(props.href);
|
|
91
|
+
const anchorRef = useRef(null);
|
|
92
|
+
const mergedRef = mergeRefs(anchorRef, ref);
|
|
93
|
+
useEffect2(() => {
|
|
94
|
+
const element = anchorRef.current;
|
|
95
|
+
if (active && element) {
|
|
96
|
+
scrollIntoView(element, {
|
|
97
|
+
behavior: "smooth",
|
|
98
|
+
block: "center",
|
|
99
|
+
inline: "center",
|
|
100
|
+
scrollMode: "always",
|
|
101
|
+
boundary: containerRef.current
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}, [active, containerRef]);
|
|
105
|
+
return /* @__PURE__ */ jsx("a", __spreadProps(__spreadValues({ ref: mergedRef, "data-active": active }, props), { children: props.children }));
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
TOCItem.displayName = "TOCItem";
|
|
109
|
+
export {
|
|
110
|
+
TOCItem,
|
|
111
|
+
TOCProvider,
|
|
112
|
+
useActiveAnchor
|
|
113
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fumadocs-core",
|
|
3
|
+
"version": "8.0.0",
|
|
4
|
+
"description": "The library for building a documentation website in Next.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"NextJs",
|
|
7
|
+
"Docs"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://fumadocs.vercel.app",
|
|
10
|
+
"repository": "github:fuma-nama/next-docs",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Fuma Nama",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./sidebar": {
|
|
16
|
+
"import": "./dist/sidebar.js",
|
|
17
|
+
"types": "./dist/sidebar.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./breadcrumb": {
|
|
20
|
+
"import": "./dist/breadcrumb.js",
|
|
21
|
+
"types": "./dist/breadcrumb.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./toc": {
|
|
24
|
+
"import": "./dist/toc.js",
|
|
25
|
+
"types": "./dist/toc.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./search/client": {
|
|
28
|
+
"import": "./dist/search/client.js",
|
|
29
|
+
"types": "./dist/search/client.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"./search/server": {
|
|
32
|
+
"import": "./dist/search/server.js",
|
|
33
|
+
"types": "./dist/search/server.d.ts"
|
|
34
|
+
},
|
|
35
|
+
"./server": {
|
|
36
|
+
"import": "./dist/server/index.js",
|
|
37
|
+
"types": "./dist/server/index.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"./source": {
|
|
40
|
+
"import": "./dist/source/index.js",
|
|
41
|
+
"types": "./dist/source/index.d.ts"
|
|
42
|
+
},
|
|
43
|
+
"./link": {
|
|
44
|
+
"import": "./dist/link.js",
|
|
45
|
+
"types": "./dist/link.d.ts"
|
|
46
|
+
},
|
|
47
|
+
"./middleware": {
|
|
48
|
+
"import": "./dist/middleware.js",
|
|
49
|
+
"types": "./dist/middleware.d.ts"
|
|
50
|
+
},
|
|
51
|
+
"./mdx-plugins": {
|
|
52
|
+
"import": "./dist/mdx-plugins/index.js",
|
|
53
|
+
"types": "./dist/mdx-plugins/index.d.ts"
|
|
54
|
+
},
|
|
55
|
+
"./search-algolia/client": {
|
|
56
|
+
"import": "./dist/search-algolia/client.js",
|
|
57
|
+
"types": "./dist/search-algolia/client.d.ts"
|
|
58
|
+
},
|
|
59
|
+
"./search-algolia/server": {
|
|
60
|
+
"import": "./dist/search-algolia/server.js",
|
|
61
|
+
"types": "./dist/search-algolia/server.d.ts"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"typesVersions": {
|
|
65
|
+
"*": {
|
|
66
|
+
"sidebar": [
|
|
67
|
+
"./dist/sidebar.d.ts"
|
|
68
|
+
],
|
|
69
|
+
"breadcrumb": [
|
|
70
|
+
"./dist/breadcrumb.d.ts"
|
|
71
|
+
],
|
|
72
|
+
"toc": [
|
|
73
|
+
"./dist/toc.d.ts"
|
|
74
|
+
],
|
|
75
|
+
"search/client": [
|
|
76
|
+
"./dist/search/client.d.ts"
|
|
77
|
+
],
|
|
78
|
+
"search/shared": [
|
|
79
|
+
"./dist/search/shared.d.ts"
|
|
80
|
+
],
|
|
81
|
+
"search/server": [
|
|
82
|
+
"./dist/search/server.d.ts"
|
|
83
|
+
],
|
|
84
|
+
"server": [
|
|
85
|
+
"./dist/server/index.d.ts"
|
|
86
|
+
],
|
|
87
|
+
"source": [
|
|
88
|
+
"./dist/source/index.d.ts"
|
|
89
|
+
],
|
|
90
|
+
"link": [
|
|
91
|
+
"./dist/link.d.ts"
|
|
92
|
+
],
|
|
93
|
+
"middleware": [
|
|
94
|
+
"./dist/middleware.d.ts"
|
|
95
|
+
],
|
|
96
|
+
"mdx-plugins": [
|
|
97
|
+
"./dist/mdx-plugins/index.d.ts"
|
|
98
|
+
],
|
|
99
|
+
"search-algolia/client": [
|
|
100
|
+
"./dist/search-algolia/client.d.ts"
|
|
101
|
+
],
|
|
102
|
+
"search-algolia/server": [
|
|
103
|
+
"./dist/search-algolia/server.d.ts"
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"files": [
|
|
108
|
+
"dist/*"
|
|
109
|
+
],
|
|
110
|
+
"dependencies": {
|
|
111
|
+
"@formatjs/intl-localematcher": "^0.5.0",
|
|
112
|
+
"flexsearch": "0.7.21",
|
|
113
|
+
"github-slugger": "^2.0.0",
|
|
114
|
+
"negotiator": "^0.6.3",
|
|
115
|
+
"react-remove-scroll": "^2.5.6",
|
|
116
|
+
"rehype-shikiji": "^0.10.0",
|
|
117
|
+
"remark": "^15.0.0",
|
|
118
|
+
"remark-gfm": "^4.0.0",
|
|
119
|
+
"remark-mdx": "^3.0.0",
|
|
120
|
+
"scroll-into-view-if-needed": "^3.1.0",
|
|
121
|
+
"shikiji": "^0.10.0",
|
|
122
|
+
"shikiji-transformers": "^0.10.0",
|
|
123
|
+
"swr": "^2.2.2",
|
|
124
|
+
"unist-util-visit": "^5.0.0"
|
|
125
|
+
},
|
|
126
|
+
"devDependencies": {
|
|
127
|
+
"@algolia/client-search": "^4.20.0",
|
|
128
|
+
"@next/eslint-plugin-next": "^14.0.0",
|
|
129
|
+
"@types/flexsearch": "0.7.6",
|
|
130
|
+
"@types/hast": "^3.0.3",
|
|
131
|
+
"@types/mdast": "^4.0.3",
|
|
132
|
+
"@types/negotiator": "^0.6.1",
|
|
133
|
+
"@types/node": "18.17.5",
|
|
134
|
+
"@types/react": "18.2.0",
|
|
135
|
+
"@types/react-dom": "18.2.1",
|
|
136
|
+
"algoliasearch": "^4.20.0",
|
|
137
|
+
"next": "14.1.0",
|
|
138
|
+
"unified": "^11.0.4",
|
|
139
|
+
"eslint-config-custom": "0.0.0",
|
|
140
|
+
"tsconfig": "0.0.0"
|
|
141
|
+
},
|
|
142
|
+
"peerDependencies": {
|
|
143
|
+
"next": ">= 13.4",
|
|
144
|
+
"react": ">= 18",
|
|
145
|
+
"react-dom": ">= 18"
|
|
146
|
+
},
|
|
147
|
+
"publishConfig": {
|
|
148
|
+
"access": "public"
|
|
149
|
+
},
|
|
150
|
+
"scripts": {
|
|
151
|
+
"build": "tsup",
|
|
152
|
+
"clean": "rimraf dist",
|
|
153
|
+
"dev": "tsup --watch",
|
|
154
|
+
"lint": "eslint .",
|
|
155
|
+
"test": "vitest",
|
|
156
|
+
"types:check": "tsc --noEmit"
|
|
157
|
+
}
|
|
158
|
+
}
|