fumadocs-core 15.2.8 → 16.0.3

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 (92) hide show
  1. package/README.md +1 -1
  2. package/dist/algolia-IZEDLPHE.js +58 -0
  3. package/dist/breadcrumb.d.ts +7 -5
  4. package/dist/breadcrumb.js +46 -52
  5. package/dist/builder-feW_xVjc.d.ts +296 -0
  6. package/dist/{chunk-FVY6EZ3N.js → chunk-BBP7MIO4.js} +12 -14
  7. package/dist/{chunk-ORHEEQVY.js → chunk-EMWGTXSW.js} +0 -7
  8. package/dist/chunk-FAEPKD7U.js +20 -0
  9. package/dist/{chunk-NNKVN7WA.js → chunk-H2GMUTQG.js} +4 -2
  10. package/dist/chunk-IZPLHEX4.js +113 -0
  11. package/dist/chunk-OTD7MV33.js +53 -0
  12. package/dist/chunk-PFNP6PEB.js +11 -0
  13. package/dist/{chunk-Y2774T3B.js → chunk-QMATWJ5F.js} +6 -7
  14. package/dist/chunk-U67V476Y.js +35 -0
  15. package/dist/{chunk-BUCUQ3WX.js → chunk-XN2LKXFZ.js} +39 -34
  16. package/dist/{chunk-WFUH5VBX.js → chunk-XOFXGHS4.js} +26 -10
  17. package/dist/chunk-XZSI7AHE.js +67 -0
  18. package/dist/chunk-YVVDKJ2H.js +34 -0
  19. package/dist/chunk-ZMWYLUDP.js +21 -0
  20. package/dist/content/github.d.ts +34 -0
  21. package/dist/content/github.js +43 -0
  22. package/dist/content/index.d.ts +16 -0
  23. package/dist/content/index.js +30 -0
  24. package/dist/{get-toc-Cr2URuiP.d.ts → content/toc.d.ts} +6 -10
  25. package/dist/content/toc.js +21 -0
  26. package/dist/{page-tree-BG3wP0gU.d.ts → definitions-BRsJlZ6m.d.ts} +10 -15
  27. package/dist/dynamic-link.js +3 -3
  28. package/dist/fetch-2XFMBLBA.js +22 -0
  29. package/dist/framework/index.d.ts +1 -1
  30. package/dist/framework/index.js +2 -2
  31. package/dist/framework/next.js +2 -2
  32. package/dist/framework/react-router.js +2 -2
  33. package/dist/framework/tanstack.js +2 -2
  34. package/dist/framework/waku.d.ts +8 -0
  35. package/dist/framework/waku.js +51 -0
  36. package/dist/hide-if-empty.d.ts +18 -0
  37. package/dist/hide-if-empty.js +83 -0
  38. package/dist/highlight/client.d.ts +8 -5
  39. package/dist/highlight/client.js +9 -93
  40. package/dist/highlight/index.d.ts +20 -5
  41. package/dist/highlight/index.js +10 -6
  42. package/dist/i18n/index.d.ts +35 -8
  43. package/dist/i18n/index.js +5 -69
  44. package/dist/i18n/middleware.d.ts +12 -0
  45. package/dist/i18n/middleware.js +63 -0
  46. package/dist/link.js +3 -3
  47. package/dist/mdx-plugins/index.d.ts +124 -18
  48. package/dist/mdx-plugins/index.js +605 -203
  49. package/dist/mixedbread-RAHDVXGJ.js +118 -0
  50. package/dist/negotiation/index.d.ts +19 -0
  51. package/dist/negotiation/index.js +11 -0
  52. package/dist/{orama-cloud-USLSOSXS.js → orama-cloud-WEGQE5A6.js} +37 -27
  53. package/dist/page-tree/index.d.ts +32 -0
  54. package/dist/page-tree/index.js +15 -0
  55. package/dist/remark-code-tab-DmyIyi6m.d.ts +57 -0
  56. package/dist/{remark-structure-FIjTA11P.d.ts → remark-structure-DkCXCzpD.d.ts} +13 -2
  57. package/dist/search/algolia.d.ts +9 -7
  58. package/dist/search/algolia.js +31 -17
  59. package/dist/search/client.d.ts +88 -17
  60. package/dist/search/client.js +71 -50
  61. package/dist/search/index.d.ts +26 -0
  62. package/dist/search/index.js +7 -0
  63. package/dist/search/orama-cloud.d.ts +7 -5
  64. package/dist/search/orama-cloud.js +18 -10
  65. package/dist/search/server.d.ts +33 -25
  66. package/dist/search/server.js +109 -47
  67. package/dist/source/index.d.ts +33 -254
  68. package/dist/source/index.js +532 -353
  69. package/dist/source/plugins/lucide-icons.d.ts +14 -0
  70. package/dist/source/plugins/lucide-icons.js +23 -0
  71. package/dist/static-A2YJ5TXV.js +62 -0
  72. package/dist/toc.d.ts +11 -7
  73. package/dist/toc.js +6 -5
  74. package/dist/utils/use-effect-event.d.ts +4 -3
  75. package/dist/utils/use-effect-event.js +9 -6
  76. package/dist/utils/use-media-query.d.ts +3 -0
  77. package/dist/utils/use-media-query.js +23 -0
  78. package/dist/utils/use-on-change.js +2 -2
  79. package/package.json +92 -40
  80. package/dist/algolia-NTWLS6J3.js +0 -49
  81. package/dist/chunk-KAOEMCTI.js +0 -17
  82. package/dist/chunk-MLKGABMK.js +0 -9
  83. package/dist/chunk-XMCPKVJQ.js +0 -34
  84. package/dist/config-inq6kP6y.d.ts +0 -26
  85. package/dist/fetch-W5EHIBOE.js +0 -21
  86. package/dist/remark-heading-BPCoYwjn.d.ts +0 -31
  87. package/dist/server/index.d.ts +0 -117
  88. package/dist/server/index.js +0 -202
  89. package/dist/sidebar.d.ts +0 -33
  90. package/dist/sidebar.js +0 -89
  91. package/dist/static-VESU2S64.js +0 -61
  92. package/dist/types-Ch8gnVgO.d.ts +0 -8
@@ -1,117 +0,0 @@
1
- export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-Cr2URuiP.js';
2
- import { N as Node, I as Item, R as Root, F as Folder } from '../page-tree-BG3wP0gU.js';
3
- export { p as PageTree } from '../page-tree-BG3wP0gU.js';
4
- export { S as SortedResult } from '../types-Ch8gnVgO.js';
5
- import { Metadata } from 'next';
6
- import { NextRequest } from 'next/server';
7
- import { LoaderOutput, LoaderConfig, InferPageType } from '../source/index.js';
8
- import 'react';
9
- import 'unified';
10
- import 'vfile';
11
- import '../config-inq6kP6y.js';
12
-
13
- /**
14
- * Flatten tree to an array of page nodes
15
- */
16
- declare function flattenTree(tree: Node[]): Item[];
17
- /**
18
- * Get neighbours of a page, useful for implementing "previous & next" buttons
19
- */
20
- declare function findNeighbour(tree: Root, url: string, options?: {
21
- separateRoot?: boolean;
22
- }): {
23
- previous?: Item;
24
- next?: Item;
25
- };
26
- declare function getPageTreeRoots(pageTree: Root | Folder): (Root | Folder)[];
27
- /**
28
- * Separate the folder nodes of a root into multiple roots
29
- */
30
- declare function separatePageTree(pageTree: Root): Root[];
31
- /**
32
- * Get other page tree nodes that lives under the same parent
33
- */
34
- declare function getPageTreePeers(tree: Root, url: string): Item[];
35
-
36
- interface GetGithubLastCommitOptions {
37
- /**
38
- * Repository name, like "fumadocs"
39
- */
40
- repo: string;
41
- /** Owner of repository */
42
- owner: string;
43
- /**
44
- * Path to file
45
- */
46
- path: string;
47
- /**
48
- * GitHub access token
49
- */
50
- token?: string;
51
- /**
52
- * SHA or ref (branch or tag) name.
53
- */
54
- sha?: string;
55
- /**
56
- * Custom query parameters
57
- */
58
- params?: Record<string, string>;
59
- options?: RequestInit;
60
- }
61
- /**
62
- * Get the last edit time of a file using GitHub API
63
- *
64
- * By default, this will cache the result forever.
65
- * Set `options.next.revalidate` to customise this.
66
- */
67
- declare function getGithubLastEdit({ repo, token, owner, path, sha, options, params: customParams, }: GetGithubLastCommitOptions): Promise<Date | null>;
68
-
69
- interface ImageMeta {
70
- alt: string;
71
- url: string;
72
- width: number;
73
- height: number;
74
- }
75
- declare function createMetadataImage<S extends LoaderOutput<LoaderConfig>>(options: {
76
- source: S;
77
- /**
78
- * the route of your OG image generator.
79
- *
80
- * @example '/docs-og'
81
- * @defaultValue '/docs-og'
82
- */
83
- imageRoute?: string;
84
- /**
85
- * The filename of generated OG Image
86
- *
87
- * @defaultValue 'image.png'
88
- */
89
- filename?: string;
90
- }): {
91
- getImageMeta: (slugs: string[]) => ImageMeta;
92
- /**
93
- * Add image meta tags to metadata
94
- */
95
- withImage: (slugs: string[], metadata?: Metadata) => Metadata;
96
- /**
97
- * Generate static params for OG Image Generator
98
- */
99
- generateParams: () => {
100
- slug: string[];
101
- lang?: string;
102
- }[];
103
- /**
104
- * create route handler for OG Image Generator
105
- */
106
- createAPI: (handler: (page: InferPageType<S>, request: NextRequest, options: {
107
- params: {
108
- slug: string[];
109
- lang?: string;
110
- } | Promise<{
111
- slug: string[];
112
- lang?: string;
113
- }>;
114
- }) => Response | Promise<Response>) => (request: NextRequest, options: any) => Response | Promise<Response>;
115
- };
116
-
117
- export { type GetGithubLastCommitOptions, createMetadataImage, findNeighbour, flattenTree, getGithubLastEdit, getPageTreePeers, getPageTreeRoots, separatePageTree };
@@ -1,202 +0,0 @@
1
- import {
2
- remarkHeading
3
- } from "../chunk-Y2774T3B.js";
4
- import "../chunk-MLKGABMK.js";
5
-
6
- // src/server/get-toc.ts
7
- import { remark } from "remark";
8
- function getTableOfContents(content, remarkPlugins) {
9
- if (remarkPlugins) {
10
- return remark().use(remarkPlugins).use(remarkHeading).process(content).then((result2) => {
11
- if ("toc" in result2.data) return result2.data.toc;
12
- return [];
13
- });
14
- }
15
- const result = remark().use(remarkHeading).processSync(content);
16
- if ("toc" in result.data) return result.data.toc;
17
- return [];
18
- }
19
-
20
- // src/utils/page-tree.tsx
21
- function flattenTree(tree) {
22
- return tree.flatMap((node) => {
23
- if (node.type === "separator") return [];
24
- if (node.type === "folder") {
25
- const child = flattenTree(node.children);
26
- if (node.index) return [node.index, ...child];
27
- return child;
28
- }
29
- return [node];
30
- });
31
- }
32
- function findNeighbour(tree, url, options) {
33
- const { separateRoot = true } = options ?? {};
34
- const roots = separateRoot ? getPageTreeRoots(tree) : [tree];
35
- const lists = roots.map((node) => flattenTree(node.children));
36
- for (const list of lists) {
37
- for (let i = 0; i < list.length; i++) {
38
- if (list[i].url === url) {
39
- return {
40
- next: list[i + 1],
41
- previous: list[i - 1]
42
- };
43
- }
44
- }
45
- }
46
- return {};
47
- }
48
- function getPageTreeRoots(pageTree) {
49
- const result = pageTree.children.flatMap((child) => {
50
- if (child.type !== "folder") return [];
51
- const roots = getPageTreeRoots(child);
52
- if (child.root) {
53
- roots.push(child);
54
- }
55
- return roots;
56
- });
57
- if (!("type" in pageTree)) result.push(pageTree);
58
- return result;
59
- }
60
- function separatePageTree(pageTree) {
61
- return pageTree.children.flatMap((child) => {
62
- if (child.type !== "folder") return [];
63
- return {
64
- name: child.name,
65
- url: child.index?.url,
66
- children: child.children
67
- };
68
- });
69
- }
70
- function getPageTreePeers(tree, url) {
71
- const parent = findParentFromTree(tree, url);
72
- if (!parent) return [];
73
- return parent.children.filter(
74
- (item) => item.type === "page" && item.url !== url
75
- );
76
- }
77
- function findParentFromTree(node, url) {
78
- if ("index" in node && node.index?.url === url) {
79
- return node;
80
- }
81
- for (const child of node.children) {
82
- if (child.type === "folder") {
83
- const parent = findParentFromTree(child, url);
84
- if (parent) return parent;
85
- }
86
- if (child.type === "page" && child.url === url) {
87
- return node;
88
- }
89
- }
90
- }
91
-
92
- // src/server/page-tree.ts
93
- var page_tree_exports = {};
94
-
95
- // src/server/git-api.ts
96
- async function getGithubLastEdit({
97
- repo,
98
- token,
99
- owner,
100
- path,
101
- sha,
102
- options = {},
103
- params: customParams = {}
104
- }) {
105
- const headers = new Headers(options.headers);
106
- const params = new URLSearchParams();
107
- params.set("path", path);
108
- params.set("page", "1");
109
- params.set("per_page", "1");
110
- if (sha) params.set("sha", sha);
111
- for (const [key, value] of Object.entries(customParams)) {
112
- params.set(key, value);
113
- }
114
- if (token) {
115
- headers.append("authorization", token);
116
- }
117
- const res = await fetch(
118
- `https://api.github.com/repos/${owner}/${repo}/commits?${params.toString()}`,
119
- {
120
- cache: "force-cache",
121
- ...options,
122
- headers
123
- }
124
- );
125
- if (!res.ok)
126
- throw new Error(
127
- `Failed to fetch last edit time from Git ${await res.text()}`
128
- );
129
- const data = await res.json();
130
- if (data.length === 0) return null;
131
- return new Date(data[0].commit.committer.date);
132
- }
133
-
134
- // src/server/metadata.ts
135
- function createMetadataImage(options) {
136
- const { filename = "image.png", imageRoute = "/docs-og" } = options;
137
- function getImageMeta(slugs) {
138
- return {
139
- alt: "Banner",
140
- url: `/${[...imageRoute.split("/"), ...slugs, filename].filter((v) => v.length > 0).join("/")}`,
141
- width: 1200,
142
- height: 630
143
- };
144
- }
145
- return {
146
- getImageMeta,
147
- withImage(slugs, data) {
148
- const imageData = getImageMeta(slugs);
149
- return {
150
- ...data,
151
- openGraph: {
152
- images: imageData,
153
- ...data?.openGraph
154
- },
155
- twitter: {
156
- images: imageData,
157
- card: "summary_large_image",
158
- ...data?.twitter
159
- }
160
- };
161
- },
162
- generateParams() {
163
- return options.source.generateParams().map((params) => ({
164
- ...params,
165
- slug: [...params.slug, filename]
166
- }));
167
- },
168
- createAPI(handler) {
169
- return async (req, args) => {
170
- const params = await args.params;
171
- if (!params || !("slug" in params) || params.slug === void 0)
172
- throw new Error(`Invalid params: ${JSON.stringify(params)}`);
173
- const lang = "lang" in params && typeof params.lang === "string" ? params.lang : void 0;
174
- const input = {
175
- slug: Array.isArray(params.slug) ? params.slug : [params.slug],
176
- lang
177
- };
178
- const page = options.source.getPage(
179
- input.slug.slice(0, -1),
180
- //remove filename
181
- lang
182
- );
183
- if (!page)
184
- return new Response(null, {
185
- status: 404
186
- });
187
- return handler(page, req, { params: input });
188
- };
189
- }
190
- };
191
- }
192
- export {
193
- page_tree_exports as PageTree,
194
- createMetadataImage,
195
- findNeighbour,
196
- flattenTree,
197
- getGithubLastEdit,
198
- getPageTreePeers,
199
- getPageTreeRoots,
200
- getTableOfContents,
201
- separatePageTree
202
- };
package/dist/sidebar.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode, ElementType, ComponentPropsWithoutRef, ReactElement } from 'react';
3
-
4
- interface SidebarProviderProps {
5
- open?: boolean;
6
- onOpenChange?: (v: boolean) => void;
7
- children: ReactNode;
8
- }
9
- declare function SidebarProvider(props: SidebarProviderProps): react_jsx_runtime.JSX.Element;
10
- type AsProps<T extends ElementType> = Omit<ComponentPropsWithoutRef<T>, 'as'> & {
11
- as?: T;
12
- };
13
- type SidebarTriggerProps<T extends ElementType> = AsProps<T>;
14
- declare function SidebarTrigger<T extends ElementType = 'button'>({ as, ...props }: SidebarTriggerProps<T>): ReactElement;
15
- type SidebarContentProps<T extends ElementType> = AsProps<T> & {
16
- /**
17
- * Disable scroll blocking when the viewport width is larger than a certain number (in pixels)
18
- *
19
- * @deprecated use `removeScrollOn`
20
- */
21
- blockScrollingWidth?: number;
22
- /**
23
- * A media query.
24
- *
25
- * When the sidebar is opening and media query is matched, scrolling outside the sidebar will be blocked.
26
- *
27
- * @example (max-width: 1000px)
28
- */
29
- removeScrollOn?: string;
30
- };
31
- declare function SidebarList<T extends ElementType = 'aside'>({ as, blockScrollingWidth, removeScrollOn, ...props }: SidebarContentProps<T>): ReactElement;
32
-
33
- export { type SidebarContentProps, SidebarList, SidebarProvider, type SidebarProviderProps, SidebarTrigger, type SidebarTriggerProps };
package/dist/sidebar.js DELETED
@@ -1,89 +0,0 @@
1
- "use client";
2
- import "./chunk-MLKGABMK.js";
3
-
4
- // src/sidebar.tsx
5
- import {
6
- createContext,
7
- useContext,
8
- useEffect,
9
- useState,
10
- useMemo
11
- } from "react";
12
- import { RemoveScroll } from "react-remove-scroll";
13
- import { jsx } from "react/jsx-runtime";
14
- var SidebarContext = createContext(null);
15
- function useSidebarContext() {
16
- const ctx = useContext(SidebarContext);
17
- if (!ctx) throw new Error("Missing sidebar provider");
18
- return ctx;
19
- }
20
- function SidebarProvider(props) {
21
- const [open, setOpen] = props.open === void 0 ? (
22
- // eslint-disable-next-line react-hooks/rules-of-hooks
23
- useState(false)
24
- ) : [props.open, props.onOpenChange];
25
- return /* @__PURE__ */ jsx(
26
- SidebarContext.Provider,
27
- {
28
- value: useMemo(
29
- () => ({ open, setOpen: setOpen ?? (() => void 0) }),
30
- [open, setOpen]
31
- ),
32
- children: props.children
33
- }
34
- );
35
- }
36
- function SidebarTrigger({
37
- as,
38
- ...props
39
- }) {
40
- const { open, setOpen } = useSidebarContext();
41
- const As = as ?? "button";
42
- return /* @__PURE__ */ jsx(
43
- As,
44
- {
45
- "aria-label": "Toggle Sidebar",
46
- "data-open": open,
47
- onClick: () => {
48
- setOpen(!open);
49
- },
50
- ...props
51
- }
52
- );
53
- }
54
- function SidebarList({
55
- as,
56
- blockScrollingWidth,
57
- removeScrollOn = blockScrollingWidth ? `(width < ${blockScrollingWidth}px)` : void 0,
58
- ...props
59
- }) {
60
- const { open } = useSidebarContext();
61
- const [isBlocking, setIsBlocking] = useState(false);
62
- useEffect(() => {
63
- if (!removeScrollOn) return;
64
- const mediaQueryList = window.matchMedia(removeScrollOn);
65
- const handleChange = () => {
66
- setIsBlocking(mediaQueryList.matches);
67
- };
68
- handleChange();
69
- mediaQueryList.addEventListener("change", handleChange);
70
- return () => {
71
- mediaQueryList.removeEventListener("change", handleChange);
72
- };
73
- }, [removeScrollOn]);
74
- return /* @__PURE__ */ jsx(
75
- RemoveScroll,
76
- {
77
- as: as ?? "aside",
78
- "data-open": open,
79
- enabled: Boolean(isBlocking && open),
80
- ...props,
81
- children: props.children
82
- }
83
- );
84
- }
85
- export {
86
- SidebarList,
87
- SidebarProvider,
88
- SidebarTrigger
89
- };
@@ -1,61 +0,0 @@
1
- import {
2
- searchAdvanced,
3
- searchSimple
4
- } from "./chunk-WFUH5VBX.js";
5
- import "./chunk-KAOEMCTI.js";
6
- import "./chunk-MLKGABMK.js";
7
-
8
- // src/search/client/static.ts
9
- import { create, load } from "@orama/orama";
10
- function createStaticClient({
11
- from = "/api/search",
12
- initOrama = (locale) => create({ schema: { _: "string" }, language: locale })
13
- }) {
14
- const dbs = /* @__PURE__ */ new Map();
15
- async function init() {
16
- const res = await fetch(from);
17
- if (!res.ok)
18
- throw new Error(
19
- `failed to fetch exported search indexes from ${from}, make sure the search database is exported and available for client.`
20
- );
21
- const data = await res.json();
22
- if (data.type === "i18n") {
23
- for (const [k, v] of Object.entries(data.data)) {
24
- const db = await initOrama(k);
25
- load(db, v);
26
- dbs.set(k, {
27
- type: v.type,
28
- db
29
- });
30
- }
31
- } else {
32
- const db = await initOrama();
33
- load(db, data);
34
- dbs.set("", {
35
- type: data.type,
36
- db
37
- });
38
- }
39
- }
40
- const get = init();
41
- return {
42
- async search(query, locale, tag) {
43
- await get;
44
- const cached = dbs.get(locale ?? "");
45
- if (!cached) return [];
46
- if (cached.type === "simple")
47
- return searchSimple(
48
- cached,
49
- query
50
- );
51
- return searchAdvanced(
52
- cached.db,
53
- query,
54
- tag
55
- );
56
- }
57
- };
58
- }
59
- export {
60
- createStaticClient
61
- };
@@ -1,8 +0,0 @@
1
- interface SortedResult {
2
- id: string;
3
- url: string;
4
- type: 'page' | 'heading' | 'text';
5
- content: string;
6
- }
7
-
8
- export type { SortedResult as S };