fumadocs-core 11.3.1 → 12.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/dist/breadcrumb.d.ts +1 -1
- package/dist/breadcrumb.js +1 -1
- package/dist/{chunk-AFKH746E.js → chunk-2BP57A6C.js} +1 -1
- package/dist/{chunk-5BST7EWT.js → chunk-QRNTLL6S.js} +20 -10
- package/dist/dynamic-link.js +2 -2
- package/dist/link.js +2 -2
- package/dist/mdx-plugins/index.d.ts +1 -1
- package/dist/mdx-plugins/index.js +17 -23
- package/dist/middleware.js +1 -1
- package/dist/{page-tree-mLHMYx2B.d.ts → page-tree-_z0bnHIU.d.ts} +5 -1
- package/dist/search/client.js +5 -9
- package/dist/search/server.d.ts +1 -1
- package/dist/search/server.js +5 -9
- package/dist/search-algolia/client.d.ts +1 -1
- package/dist/search-algolia/client.js +2 -3
- package/dist/search-algolia/server.d.ts +1 -1
- package/dist/search-algolia/server.js +1 -1
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +7 -12
- package/dist/sidebar.d.ts +1 -5
- package/dist/sidebar.js +4 -13
- package/dist/source/index.d.ts +26 -13
- package/dist/source/index.js +69 -62
- package/dist/toc.d.ts +1 -1
- package/dist/toc.js +1 -1
- package/package.json +4 -4
- /package/dist/{chunk-WEAGW6MQ.js → chunk-UWTMEZUM.js} +0 -0
- /package/dist/{get-toc-YF_TdazL.d.ts → get-toc-B-AMfFKT.d.ts} +0 -0
- /package/dist/{remark-structure-Os9Vuaua.d.ts → remark-structure-Dj8oa5Ba.d.ts} +0 -0
package/dist/breadcrumb.d.ts
CHANGED
package/dist/breadcrumb.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// src/mdx-plugins/remark-heading.ts
|
|
2
2
|
import Slugger from "github-slugger";
|
|
3
3
|
import { visit } from "unist-util-visit";
|
|
4
|
+
|
|
5
|
+
// src/mdx-plugins/remark-utils.ts
|
|
6
|
+
function flattenNode(node) {
|
|
7
|
+
if ("children" in node)
|
|
8
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
9
|
+
if ("value" in node) return node.value;
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/mdx-plugins/remark-heading.ts
|
|
4
14
|
var slugger = new Slugger();
|
|
5
15
|
var regex = new RegExp("\\s*\\[#(?<slug>[^]+?)]\\s*$");
|
|
6
16
|
function remarkHeading({
|
|
@@ -12,25 +22,24 @@ function remarkHeading({
|
|
|
12
22
|
slugger.reset();
|
|
13
23
|
visit(root, "heading", (heading) => {
|
|
14
24
|
var _a;
|
|
15
|
-
const node = heading.children.at(-1);
|
|
16
|
-
if (!node || node.type !== "text")
|
|
17
|
-
return;
|
|
18
25
|
heading.data || (heading.data = {});
|
|
19
26
|
(_a = heading.data).hProperties || (_a.hProperties = {});
|
|
20
|
-
|
|
21
|
-
if (!id && customId) {
|
|
22
|
-
const match = regex.exec(
|
|
27
|
+
const lastNode = heading.children.at(-1);
|
|
28
|
+
if (!heading.data.hProperties.id && (lastNode == null ? void 0 : lastNode.type) === "text" && customId) {
|
|
29
|
+
const match = regex.exec(lastNode.value);
|
|
23
30
|
if (match == null ? void 0 : match[1]) {
|
|
24
|
-
id = match[1];
|
|
25
|
-
|
|
31
|
+
heading.data.hProperties.id = match[1];
|
|
32
|
+
lastNode.value = lastNode.value.slice(0, match.index);
|
|
26
33
|
}
|
|
27
34
|
}
|
|
35
|
+
const value = flattenNode(heading);
|
|
36
|
+
let id = heading.data.hProperties.id;
|
|
28
37
|
if (!id) {
|
|
29
|
-
id = defaultSlug ? defaultSlug(root, heading,
|
|
38
|
+
id = defaultSlug ? defaultSlug(root, heading, value) : slugger.slug(value);
|
|
30
39
|
}
|
|
31
40
|
heading.data.hProperties.id = id;
|
|
32
41
|
toc.push({
|
|
33
|
-
title:
|
|
42
|
+
title: value,
|
|
34
43
|
url: `#${id}`,
|
|
35
44
|
depth: heading.depth
|
|
36
45
|
});
|
|
@@ -41,5 +50,6 @@ function remarkHeading({
|
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
export {
|
|
53
|
+
flattenNode,
|
|
44
54
|
remarkHeading
|
|
45
55
|
};
|
package/dist/dynamic-link.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
Link
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2BP57A6C.js";
|
|
5
5
|
import {
|
|
6
6
|
__objRest,
|
|
7
7
|
__spreadValues
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-UWTMEZUM.js";
|
|
9
9
|
|
|
10
10
|
// src/dynamic-link.tsx
|
|
11
11
|
import { useParams } from "next/navigation";
|
package/dist/link.js
CHANGED
|
@@ -4,7 +4,7 @@ import { RehypeShikiOptions } from '@shikijs/rehype';
|
|
|
4
4
|
import { Processor, Transformer } from 'unified';
|
|
5
5
|
import { ShikiTransformer } from 'shiki';
|
|
6
6
|
import { Root as Root$1, Heading } from 'mdast';
|
|
7
|
-
export { a as StructureOptions, S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-
|
|
7
|
+
export { a as StructureOptions, S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-Dj8oa5Ba.js';
|
|
8
8
|
|
|
9
9
|
interface CodeBlockIcon {
|
|
10
10
|
viewBox: string;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
flattenNode,
|
|
2
3
|
remarkHeading
|
|
3
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-QRNTLL6S.js";
|
|
4
5
|
import {
|
|
5
6
|
slash
|
|
6
7
|
} from "../chunk-UWEEHUJV.js";
|
|
7
8
|
import {
|
|
8
9
|
__async,
|
|
9
10
|
__spreadValues
|
|
10
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-UWTMEZUM.js";
|
|
11
12
|
|
|
12
13
|
// src/mdx-plugins/index.ts
|
|
13
14
|
import {
|
|
@@ -161,11 +162,9 @@ function transformerIcon(options = {}) {
|
|
|
161
162
|
name: "rehype-code:icon",
|
|
162
163
|
root(root) {
|
|
163
164
|
const lang = this.options.lang;
|
|
164
|
-
if (!lang)
|
|
165
|
-
return;
|
|
165
|
+
if (!lang) return;
|
|
166
166
|
const pre = root.children[0];
|
|
167
|
-
if (pre.type !== "element")
|
|
168
|
-
return;
|
|
167
|
+
if (pre.type !== "element" || pre.tagName !== "pre") return;
|
|
169
168
|
const iconName = lang in shortcuts ? shortcuts[lang] : lang;
|
|
170
169
|
const icon = iconName in icons ? icons[iconName] : icons.default;
|
|
171
170
|
const tree = toEstree(pre, {
|
|
@@ -324,6 +323,14 @@ function rehypeCode(options = {}) {
|
|
|
324
323
|
meta.__raw = codeOptions.filterMetaString((_a = meta.__raw) != null ? _a : "");
|
|
325
324
|
}
|
|
326
325
|
return code.replace(/\n$/, "");
|
|
326
|
+
},
|
|
327
|
+
line(hast) {
|
|
328
|
+
if (hast.children.length === 0) {
|
|
329
|
+
hast.children.push({
|
|
330
|
+
type: "text",
|
|
331
|
+
value: " "
|
|
332
|
+
});
|
|
333
|
+
}
|
|
327
334
|
}
|
|
328
335
|
},
|
|
329
336
|
...codeOptions.transformers
|
|
@@ -336,7 +343,7 @@ function rehypeCode(options = {}) {
|
|
|
336
343
|
}
|
|
337
344
|
const prefix = "language-";
|
|
338
345
|
const transformer = rehypeShiki.call(this, codeOptions);
|
|
339
|
-
return (root,
|
|
346
|
+
return (root, file) => __async(this, null, function* () {
|
|
340
347
|
visit(root, ["pre"], (element) => {
|
|
341
348
|
var _a;
|
|
342
349
|
const head = element.children[0];
|
|
@@ -344,8 +351,7 @@ function rehypeCode(options = {}) {
|
|
|
344
351
|
return;
|
|
345
352
|
(_a = head.properties).className || (_a.className = []);
|
|
346
353
|
const classes = head.properties.className;
|
|
347
|
-
if (!Array.isArray(classes))
|
|
348
|
-
return;
|
|
354
|
+
if (!Array.isArray(classes)) return;
|
|
349
355
|
const hasLanguage = classes.some(
|
|
350
356
|
(d) => typeof d === "string" && d.startsWith(prefix)
|
|
351
357
|
);
|
|
@@ -353,7 +359,7 @@ function rehypeCode(options = {}) {
|
|
|
353
359
|
classes.push(`${prefix}${codeOptions.defaultLang}`);
|
|
354
360
|
});
|
|
355
361
|
if (transformer)
|
|
356
|
-
yield transformer.call(this, root,
|
|
362
|
+
yield transformer.call(this, root, file, () => {
|
|
357
363
|
});
|
|
358
364
|
});
|
|
359
365
|
}
|
|
@@ -455,17 +461,6 @@ import { remark } from "remark";
|
|
|
455
461
|
import remarkGfm from "remark-gfm";
|
|
456
462
|
import remarkMdx from "remark-mdx";
|
|
457
463
|
import { visit as visit3 } from "unist-util-visit";
|
|
458
|
-
|
|
459
|
-
// src/mdx-plugins/remark-utils.ts
|
|
460
|
-
function flattenNode(node) {
|
|
461
|
-
if ("children" in node)
|
|
462
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
463
|
-
if ("value" in node)
|
|
464
|
-
return node.value;
|
|
465
|
-
return "";
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// src/mdx-plugins/remark-structure.ts
|
|
469
464
|
var slugger = new Slugger();
|
|
470
465
|
function remarkStructure({
|
|
471
466
|
types = ["paragraph", "blockquote", "heading"]
|
|
@@ -476,8 +471,7 @@ function remarkStructure({
|
|
|
476
471
|
let lastHeading = "";
|
|
477
472
|
visit3(node, types, (element) => {
|
|
478
473
|
var _a, _b;
|
|
479
|
-
if (element.type === "root")
|
|
480
|
-
return;
|
|
474
|
+
if (element.type === "root") return;
|
|
481
475
|
const content = flattenNode(element).trim();
|
|
482
476
|
if (element.type === "heading") {
|
|
483
477
|
element.data || (element.data = {});
|
package/dist/middleware.js
CHANGED
|
@@ -17,6 +17,10 @@ interface Separator {
|
|
|
17
17
|
name: string;
|
|
18
18
|
}
|
|
19
19
|
interface Folder {
|
|
20
|
+
/**
|
|
21
|
+
* Optional id to be attached to folders
|
|
22
|
+
*/
|
|
23
|
+
id?: string;
|
|
20
24
|
type: 'folder';
|
|
21
25
|
name: string;
|
|
22
26
|
root?: boolean;
|
|
@@ -35,4 +39,4 @@ declare namespace pageTree {
|
|
|
35
39
|
export type { pageTree_Folder as Folder, pageTree_Item as Item, pageTree_Node as Node, pageTree_Root as Root, pageTree_Separator as Separator };
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
export { type Item as I, type Node as N, type Root as R, pageTree as p };
|
|
42
|
+
export { type Folder as F, type Item as I, type Node as N, type Root as R, type Separator as S, pageTree as p };
|
package/dist/search/client.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__async
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-UWTMEZUM.js";
|
|
4
4
|
|
|
5
5
|
// src/search/client.ts
|
|
6
6
|
import { useEffect, useState } from "react";
|
|
7
7
|
import useSWR from "swr";
|
|
8
8
|
function fetchDocs(api, query, locale, tag) {
|
|
9
9
|
return __async(this, null, function* () {
|
|
10
|
-
if (query.length === 0)
|
|
11
|
-
return "empty";
|
|
10
|
+
if (query.length === 0) return "empty";
|
|
12
11
|
const params = new URLSearchParams();
|
|
13
12
|
params.set("query", query);
|
|
14
|
-
if (locale)
|
|
15
|
-
|
|
16
|
-
if (tag)
|
|
17
|
-
params.set("tag", tag);
|
|
13
|
+
if (locale) params.set("locale", locale);
|
|
14
|
+
if (tag) params.set("tag", tag);
|
|
18
15
|
const res = yield fetch(`${api}?${params.toString()}`);
|
|
19
|
-
if (!res.ok)
|
|
20
|
-
throw new Error(yield res.text());
|
|
16
|
+
if (!res.ok) throw new Error(yield res.text());
|
|
21
17
|
return yield res.json();
|
|
22
18
|
});
|
|
23
19
|
}
|
package/dist/search/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { S as StructuredData } from '../remark-structure-
|
|
2
|
+
import { S as StructuredData } from '../remark-structure-Dj8oa5Ba.js';
|
|
3
3
|
import { SortedResult } from './shared.js';
|
|
4
4
|
import 'mdast';
|
|
5
5
|
import 'unified';
|
package/dist/search/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__spreadProps,
|
|
3
3
|
__spreadValues
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-UWTMEZUM.js";
|
|
5
5
|
|
|
6
6
|
// src/search/server.ts
|
|
7
7
|
import { Document } from "flexsearch";
|
|
@@ -12,8 +12,7 @@ function create(search) {
|
|
|
12
12
|
GET(request) {
|
|
13
13
|
var _a, _b;
|
|
14
14
|
const query = request.nextUrl.searchParams.get("query");
|
|
15
|
-
if (!query)
|
|
16
|
-
return NextResponse.json([]);
|
|
15
|
+
if (!query) return NextResponse.json([]);
|
|
17
16
|
return NextResponse.json(
|
|
18
17
|
search(query, {
|
|
19
18
|
tag: (_a = request.nextUrl.searchParams.get("tag")) != null ? _a : void 0,
|
|
@@ -45,8 +44,7 @@ function createI18nSearchAPI(type, options) {
|
|
|
45
44
|
return create((query, searchOptions) => {
|
|
46
45
|
if (searchOptions == null ? void 0 : searchOptions.locale) {
|
|
47
46
|
const handler = map.get(searchOptions.locale);
|
|
48
|
-
if (handler)
|
|
49
|
-
return handler.search(query, searchOptions);
|
|
47
|
+
if (handler) return handler.search(query, searchOptions);
|
|
50
48
|
}
|
|
51
49
|
return [];
|
|
52
50
|
});
|
|
@@ -95,8 +93,7 @@ function initSearchAPI({ indexes, language }) {
|
|
|
95
93
|
enrich: true,
|
|
96
94
|
suggest: true
|
|
97
95
|
});
|
|
98
|
-
if (results.length === 0)
|
|
99
|
-
return [];
|
|
96
|
+
if (results.length === 0) return [];
|
|
100
97
|
return results[0].result.map((page) => ({
|
|
101
98
|
type: "page",
|
|
102
99
|
content: page.doc.title,
|
|
@@ -190,8 +187,7 @@ function initSearchAPIAdvanced({
|
|
|
190
187
|
}
|
|
191
188
|
for (const [id, items] of map.entries()) {
|
|
192
189
|
const page = index.get(id);
|
|
193
|
-
if (!page)
|
|
194
|
-
continue;
|
|
190
|
+
if (!page) continue;
|
|
195
191
|
sortedResult.push({
|
|
196
192
|
id: page.id,
|
|
197
193
|
content: page.content,
|
|
@@ -4,7 +4,7 @@ import { SWRResponse } from 'swr';
|
|
|
4
4
|
import { SortedResult } from '../search/shared.js';
|
|
5
5
|
import { BaseIndex } from './server.js';
|
|
6
6
|
import 'algoliasearch';
|
|
7
|
-
import '../remark-structure-
|
|
7
|
+
import '../remark-structure-Dj8oa5Ba.js';
|
|
8
8
|
import 'mdast';
|
|
9
9
|
import 'unified';
|
|
10
10
|
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
__async,
|
|
3
3
|
__objRest,
|
|
4
4
|
__spreadValues
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-UWTMEZUM.js";
|
|
6
6
|
|
|
7
7
|
// src/search-algolia/client.ts
|
|
8
8
|
import { useState } from "react";
|
|
@@ -51,8 +51,7 @@ function useAlgoliaSearch(index, _a = {}) {
|
|
|
51
51
|
const query = useSWR(
|
|
52
52
|
["algolia-search", search, allowEmpty, options],
|
|
53
53
|
() => __async(this, null, function* () {
|
|
54
|
-
if (allowEmpty && search.length === 0)
|
|
55
|
-
return "empty";
|
|
54
|
+
if (allowEmpty && search.length === 0) return "empty";
|
|
56
55
|
return searchDocs(index, search, options);
|
|
57
56
|
}),
|
|
58
57
|
{
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-
|
|
2
|
-
import { N as Node, I as Item, R as Root } from '../page-tree-
|
|
3
|
-
export { p as PageTree } from '../page-tree-
|
|
1
|
+
export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-B-AMfFKT.js';
|
|
2
|
+
import { N as Node, I as Item, R as Root } from '../page-tree-_z0bnHIU.js';
|
|
3
|
+
export { p as PageTree } from '../page-tree-_z0bnHIU.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/server/index.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
remarkHeading
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-QRNTLL6S.js";
|
|
4
4
|
import {
|
|
5
5
|
__async
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-UWTMEZUM.js";
|
|
7
7
|
|
|
8
8
|
// src/server/get-toc.ts
|
|
9
9
|
import { remark } from "remark";
|
|
10
10
|
function getTableOfContents(content) {
|
|
11
11
|
return __async(this, null, function* () {
|
|
12
12
|
const result = yield remark().use(remarkHeading).process(content);
|
|
13
|
-
if ("toc" in result.data)
|
|
14
|
-
return result.data.toc;
|
|
13
|
+
if ("toc" in result.data) return result.data.toc;
|
|
15
14
|
return [];
|
|
16
15
|
});
|
|
17
16
|
}
|
|
@@ -19,12 +18,10 @@ function getTableOfContents(content) {
|
|
|
19
18
|
// src/server/page-tree-utils.ts
|
|
20
19
|
function flattenTree(tree) {
|
|
21
20
|
return tree.flatMap((node) => {
|
|
22
|
-
if (node.type === "separator")
|
|
23
|
-
return [];
|
|
21
|
+
if (node.type === "separator") return [];
|
|
24
22
|
if (node.type === "folder") {
|
|
25
23
|
const child = flattenTree(node.children);
|
|
26
|
-
if (node.index)
|
|
27
|
-
return [node.index, ...child];
|
|
24
|
+
if (node.index) return [node.index, ...child];
|
|
28
25
|
return child;
|
|
29
26
|
}
|
|
30
27
|
return [node];
|
|
@@ -45,8 +42,7 @@ function findNeighbour(tree, url) {
|
|
|
45
42
|
function separatePageTree(pageTree) {
|
|
46
43
|
return pageTree.children.flatMap((child) => {
|
|
47
44
|
var _a;
|
|
48
|
-
if (child.type !== "folder")
|
|
49
|
-
return [];
|
|
45
|
+
if (child.type !== "folder") return [];
|
|
50
46
|
return {
|
|
51
47
|
name: child.name,
|
|
52
48
|
url: (_a = child.index) == null ? void 0 : _a.url,
|
|
@@ -88,8 +84,7 @@ function getGithubLastEdit(_0) {
|
|
|
88
84
|
`Failed to fetch last edit time from Git ${yield res.text()}`
|
|
89
85
|
);
|
|
90
86
|
const data = yield res.json();
|
|
91
|
-
if (data.length === 0)
|
|
92
|
-
return null;
|
|
87
|
+
if (data.length === 0) return null;
|
|
93
88
|
return new Date(data[0].commit.committer.date);
|
|
94
89
|
});
|
|
95
90
|
}
|
package/dist/sidebar.d.ts
CHANGED
|
@@ -12,15 +12,11 @@ type AsProps<T extends ElementType> = Omit<ComponentPropsWithoutRef<T>, 'as'> &
|
|
|
12
12
|
type SidebarTriggerProps<T extends ElementType> = AsProps<T>;
|
|
13
13
|
declare function SidebarTrigger<T extends ElementType = 'button'>({ as, ...props }: SidebarTriggerProps<T>): ReactElement;
|
|
14
14
|
type SidebarContentProps<T extends ElementType> = AsProps<T> & {
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated Use `blockScrollingWidth` instead
|
|
17
|
-
*/
|
|
18
|
-
minWidth?: number;
|
|
19
15
|
/**
|
|
20
16
|
* Disable scroll blocking when the viewport width is larger than a certain number (in pixels)
|
|
21
17
|
*/
|
|
22
18
|
blockScrollingWidth?: number;
|
|
23
19
|
};
|
|
24
|
-
declare function SidebarList<T extends ElementType = 'aside'>({ as,
|
|
20
|
+
declare function SidebarList<T extends ElementType = 'aside'>({ as, blockScrollingWidth, ...props }: SidebarContentProps<T>): ReactElement;
|
|
25
21
|
|
|
26
22
|
export { type SidebarContentProps, SidebarList, SidebarProvider, type SidebarProviderProps, SidebarTrigger, type SidebarTriggerProps };
|
package/dist/sidebar.js
CHANGED
|
@@ -2,10 +2,9 @@ import {
|
|
|
2
2
|
__objRest,
|
|
3
3
|
__spreadProps,
|
|
4
4
|
__spreadValues
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-UWTMEZUM.js";
|
|
6
6
|
|
|
7
7
|
// src/sidebar.tsx
|
|
8
|
-
import { usePathname } from "next/navigation";
|
|
9
8
|
import {
|
|
10
9
|
useCallback,
|
|
11
10
|
createContext,
|
|
@@ -18,8 +17,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
18
17
|
var SidebarContext = createContext(void 0);
|
|
19
18
|
function useSidebarContext() {
|
|
20
19
|
const ctx = useContext(SidebarContext);
|
|
21
|
-
if (!ctx)
|
|
22
|
-
throw new Error("Missing sidebar provider");
|
|
20
|
+
if (!ctx) throw new Error("Missing sidebar provider");
|
|
23
21
|
return ctx;
|
|
24
22
|
}
|
|
25
23
|
function SidebarProvider(props) {
|
|
@@ -29,10 +27,6 @@ function SidebarProvider(props) {
|
|
|
29
27
|
(_a = props.open) != null ? _a : openInner,
|
|
30
28
|
(_b = props.onOpenChange) != null ? _b : setOpenInner
|
|
31
29
|
];
|
|
32
|
-
const pathname = usePathname();
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
setOpen(false);
|
|
35
|
-
}, [pathname, setOpen]);
|
|
36
30
|
return /* @__PURE__ */ jsx(SidebarContext.Provider, { value: [open, setOpen], children: props.children });
|
|
37
31
|
}
|
|
38
32
|
function SidebarTrigger(_a) {
|
|
@@ -57,18 +51,15 @@ function SidebarTrigger(_a) {
|
|
|
57
51
|
function SidebarList(_a) {
|
|
58
52
|
var _b = _a, {
|
|
59
53
|
as,
|
|
60
|
-
|
|
61
|
-
blockScrollingWidth = minWidth
|
|
54
|
+
blockScrollingWidth
|
|
62
55
|
} = _b, props = __objRest(_b, [
|
|
63
56
|
"as",
|
|
64
|
-
"minWidth",
|
|
65
57
|
"blockScrollingWidth"
|
|
66
58
|
]);
|
|
67
59
|
const [open] = useSidebarContext();
|
|
68
60
|
const [isBlocking, setIsBlocking] = useState(false);
|
|
69
61
|
useEffect(() => {
|
|
70
|
-
if (!blockScrollingWidth)
|
|
71
|
-
return;
|
|
62
|
+
if (!blockScrollingWidth) return;
|
|
72
63
|
const mediaQueryList = window.matchMedia(
|
|
73
64
|
`(min-width: ${blockScrollingWidth.toString()}px)`
|
|
74
65
|
);
|
package/dist/source/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { R as Root } from '../page-tree-
|
|
2
|
+
import { R as Root, I as Item, F as Folder$1, S as Separator } from '../page-tree-_z0bnHIU.js';
|
|
3
3
|
|
|
4
4
|
interface FileInfo {
|
|
5
5
|
locale?: string;
|
|
@@ -97,11 +97,15 @@ interface LoaderOptions {
|
|
|
97
97
|
*/
|
|
98
98
|
baseUrl?: string;
|
|
99
99
|
languages?: string[];
|
|
100
|
-
icon?: NonNullable<
|
|
100
|
+
icon?: NonNullable<BuildPageTreeOptions['resolveIcon']>;
|
|
101
101
|
slugs?: LoadOptions['getSlugs'];
|
|
102
102
|
url?: UrlFn;
|
|
103
103
|
source: Source<any>;
|
|
104
104
|
transformers?: Transformer[];
|
|
105
|
+
/**
|
|
106
|
+
* Additional options for page tree builder
|
|
107
|
+
*/
|
|
108
|
+
pageTree?: Partial<Omit<BuildPageTreeOptions, 'storage' | 'getUrl'>>;
|
|
105
109
|
}
|
|
106
110
|
interface Source<Config extends SourceConfig> {
|
|
107
111
|
/**
|
|
@@ -177,21 +181,30 @@ interface FileData {
|
|
|
177
181
|
};
|
|
178
182
|
}
|
|
179
183
|
|
|
180
|
-
interface
|
|
181
|
-
languages: string[];
|
|
182
|
-
}
|
|
183
|
-
interface PageTreeBuilder {
|
|
184
|
-
build: () => Root;
|
|
184
|
+
interface BuildPageTreeOptions {
|
|
185
185
|
/**
|
|
186
|
-
*
|
|
186
|
+
* Attach the `folder.id` property
|
|
187
|
+
*
|
|
188
|
+
* @defaultValue false
|
|
187
189
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
190
|
+
attachFolderIds?: boolean;
|
|
191
|
+
attachFile?: (node: Item, file?: File) => Item;
|
|
192
|
+
attachFolder?: (node: Folder$1, folder: Folder, meta?: File) => Folder$1;
|
|
193
|
+
attachSeparator?: (node: Separator) => Separator;
|
|
191
194
|
storage: Storage;
|
|
192
195
|
getUrl: UrlFn;
|
|
193
196
|
resolveIcon?: (icon: string | undefined) => ReactElement | undefined;
|
|
194
197
|
}
|
|
195
|
-
|
|
198
|
+
interface BuildPageTreeOptionsWithI18n extends BuildPageTreeOptions {
|
|
199
|
+
languages?: string[];
|
|
200
|
+
}
|
|
201
|
+
interface PageTreeBuilder {
|
|
202
|
+
build: (options: BuildPageTreeOptions) => Root;
|
|
203
|
+
/**
|
|
204
|
+
* Build page tree and fallback to the default language if the localized page doesn't exist
|
|
205
|
+
*/
|
|
206
|
+
buildI18n: (options: BuildPageTreeOptionsWithI18n) => Record<string, Root>;
|
|
207
|
+
}
|
|
208
|
+
declare function createPageTreeBuilder(): PageTreeBuilder;
|
|
196
209
|
|
|
197
|
-
export { type
|
|
210
|
+
export { type BuildPageTreeOptions, type BuildPageTreeOptionsWithI18n, type FileData, type FileInfo, fileSystem as FileSystem, type InferMetaType, type InferPageType, type LanguageEntry, type LoadOptions, type LoaderConfig, type LoaderOptions, type LoaderOutput, type Meta, type MetaData, type Page, type PageData, type PageTreeBuilder, type Source, type SourceConfig, type Transformer, type UrlFn, type VirtualFile, createGetUrl, createPageTreeBuilder, getSlugs, loader, parseFilePath, parseFolderPath };
|
package/dist/source/index.js
CHANGED
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
} from "../chunk-UWEEHUJV.js";
|
|
4
4
|
import {
|
|
5
5
|
__export,
|
|
6
|
-
|
|
6
|
+
__objRest,
|
|
7
7
|
__spreadValues
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-UWTMEZUM.js";
|
|
9
9
|
|
|
10
10
|
// src/source/path.ts
|
|
11
11
|
import { parse } from "path";
|
|
@@ -73,8 +73,7 @@ function buildAll(nodes, ctx, skipIndex) {
|
|
|
73
73
|
if ("data" in node && node.format === "page" && !node.file.locale) {
|
|
74
74
|
const treeNode = buildFileNode(node, ctx);
|
|
75
75
|
if (node.file.name === "index") {
|
|
76
|
-
if (!skipIndex)
|
|
77
|
-
output.unshift(treeNode);
|
|
76
|
+
if (!skipIndex) output.unshift(treeNode);
|
|
78
77
|
continue;
|
|
79
78
|
}
|
|
80
79
|
output.push(treeNode);
|
|
@@ -86,39 +85,35 @@ function buildAll(nodes, ctx, skipIndex) {
|
|
|
86
85
|
return output;
|
|
87
86
|
}
|
|
88
87
|
function resolveFolderItem(folder, item, ctx, addedNodePaths) {
|
|
89
|
-
var _a, _b, _c;
|
|
90
|
-
if (item === rest)
|
|
91
|
-
return "...";
|
|
88
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
89
|
+
if (item === rest) return "...";
|
|
92
90
|
const separateResult = separator.exec(item);
|
|
93
91
|
if (separateResult == null ? void 0 : separateResult.groups) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
];
|
|
92
|
+
const node = {
|
|
93
|
+
type: "separator",
|
|
94
|
+
name: separateResult.groups.name
|
|
95
|
+
};
|
|
96
|
+
return [(_c = (_b = (_a = ctx.options).attachSeparator) == null ? void 0 : _b.call(_a, node)) != null ? _c : node];
|
|
100
97
|
}
|
|
101
98
|
const linkResult = link.exec(item);
|
|
102
99
|
if (linkResult == null ? void 0 : linkResult.groups) {
|
|
103
100
|
const { url, text } = linkResult.groups;
|
|
104
101
|
const isRelative = url.startsWith("/") || url.startsWith("#") || url.startsWith(".");
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
];
|
|
102
|
+
const node = {
|
|
103
|
+
type: "page",
|
|
104
|
+
name: text,
|
|
105
|
+
url,
|
|
106
|
+
external: !isRelative
|
|
107
|
+
};
|
|
108
|
+
return [(_f = (_e = (_d = ctx.options).attachFile) == null ? void 0 : _e.call(_d, node)) != null ? _f : node];
|
|
113
109
|
}
|
|
114
110
|
const extractResult = extractor.exec(item);
|
|
115
111
|
const path = resolvePath(
|
|
116
112
|
folder.file.path,
|
|
117
|
-
(
|
|
113
|
+
(_h = (_g = extractResult == null ? void 0 : extractResult.groups) == null ? void 0 : _g.name) != null ? _h : item
|
|
118
114
|
);
|
|
119
|
-
const itemNode = (
|
|
120
|
-
if (!itemNode)
|
|
121
|
-
return [];
|
|
115
|
+
const itemNode = (_i = ctx.storage.readDir(path)) != null ? _i : ctx.storage.read(path, "page");
|
|
116
|
+
if (!itemNode) return [];
|
|
122
117
|
addedNodePaths.add(itemNode.file.path);
|
|
123
118
|
if ("children" in itemNode) {
|
|
124
119
|
const node = buildFolderNode(itemNode, false, ctx);
|
|
@@ -127,7 +122,7 @@ function resolveFolderItem(folder, item, ctx, addedNodePaths) {
|
|
|
127
122
|
return [buildFileNode(itemNode, ctx)];
|
|
128
123
|
}
|
|
129
124
|
function buildFolderNode(folder, defaultIsRoot, ctx) {
|
|
130
|
-
var _a, _b, _c, _d, _e, _f;
|
|
125
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
131
126
|
const metaPath = resolvePath(folder.file.path, "meta");
|
|
132
127
|
let meta = ctx.storage.read(metaPath, "meta");
|
|
133
128
|
meta = (_a = findLocalizedFile(metaPath, "meta", ctx)) != null ? _a : meta;
|
|
@@ -147,7 +142,7 @@ function buildFolderNode(folder, defaultIsRoot, ctx) {
|
|
|
147
142
|
return resolveFolderItem(folder, item, ctx, addedNodePaths);
|
|
148
143
|
});
|
|
149
144
|
const restNodes = buildAll(
|
|
150
|
-
folder.children.filter((
|
|
145
|
+
folder.children.filter((node2) => !addedNodePaths.has(node2.file.path)),
|
|
151
146
|
ctx,
|
|
152
147
|
!isRoot
|
|
153
148
|
);
|
|
@@ -159,26 +154,33 @@ function buildFolderNode(folder, defaultIsRoot, ctx) {
|
|
|
159
154
|
});
|
|
160
155
|
children = nodes != null ? nodes : restNodes;
|
|
161
156
|
}
|
|
162
|
-
|
|
157
|
+
const node = {
|
|
163
158
|
type: "folder",
|
|
164
159
|
name: (_e = (_d = metadata == null ? void 0 : metadata.title) != null ? _d : index == null ? void 0 : index.name) != null ? _e : pathToName(folder.file.name),
|
|
165
|
-
icon: (_f = ctx.resolveIcon) == null ? void 0 :
|
|
160
|
+
icon: (_g = (_f = ctx.options).resolveIcon) == null ? void 0 : _g.call(_f, metadata == null ? void 0 : metadata.icon),
|
|
166
161
|
root: metadata == null ? void 0 : metadata.root,
|
|
167
162
|
defaultOpen: metadata == null ? void 0 : metadata.defaultOpen,
|
|
168
163
|
index,
|
|
169
164
|
children
|
|
170
|
-
}
|
|
165
|
+
};
|
|
166
|
+
if (ctx.options.attachFolderIds) {
|
|
167
|
+
node.id = folder.file.flattenedPath;
|
|
168
|
+
}
|
|
169
|
+
return removeUndefined(
|
|
170
|
+
(_j = (_i = (_h = ctx.options).attachFolder) == null ? void 0 : _i.call(_h, node, folder, meta)) != null ? _j : node
|
|
171
|
+
);
|
|
171
172
|
}
|
|
172
173
|
function buildFileNode(file, ctx) {
|
|
173
|
-
var _a, _b;
|
|
174
|
+
var _a, _b, _c, _d, _e, _f;
|
|
174
175
|
const localized = (_a = findLocalizedFile(file.file.flattenedPath, "page", ctx)) != null ? _a : file;
|
|
175
176
|
const data = localized.data;
|
|
176
|
-
|
|
177
|
+
const item = {
|
|
177
178
|
type: "page",
|
|
178
179
|
name: data.data.title,
|
|
179
|
-
icon: (_b = ctx.resolveIcon) == null ? void 0 :
|
|
180
|
-
url: ctx.getUrl(data.slugs, ctx.lang)
|
|
181
|
-
}
|
|
180
|
+
icon: (_c = (_b = ctx.options).resolveIcon) == null ? void 0 : _c.call(_b, data.data.icon),
|
|
181
|
+
url: ctx.options.getUrl(data.slugs, ctx.lang)
|
|
182
|
+
};
|
|
183
|
+
return removeUndefined((_f = (_e = (_d = ctx.options).attachFile) == null ? void 0 : _e.call(_d, item, file)) != null ? _f : item);
|
|
182
184
|
}
|
|
183
185
|
function build(ctx) {
|
|
184
186
|
const root = ctx.storage.root();
|
|
@@ -188,20 +190,24 @@ function build(ctx) {
|
|
|
188
190
|
children: folder.children
|
|
189
191
|
};
|
|
190
192
|
}
|
|
191
|
-
function createPageTreeBuilder(
|
|
192
|
-
function getContext(builder, locale) {
|
|
193
|
-
return __spreadProps(__spreadValues({}, options), {
|
|
194
|
-
lang: locale,
|
|
195
|
-
builder
|
|
196
|
-
});
|
|
197
|
-
}
|
|
193
|
+
function createPageTreeBuilder() {
|
|
198
194
|
return {
|
|
199
|
-
build() {
|
|
200
|
-
return build(
|
|
195
|
+
build(options) {
|
|
196
|
+
return build({
|
|
197
|
+
options,
|
|
198
|
+
builder: this,
|
|
199
|
+
storage: options.storage
|
|
200
|
+
});
|
|
201
201
|
},
|
|
202
|
-
buildI18n(
|
|
202
|
+
buildI18n(_a) {
|
|
203
|
+
var _b = _a, { languages = [] } = _b, options = __objRest(_b, ["languages"]);
|
|
203
204
|
const entries = languages.map((lang) => {
|
|
204
|
-
const tree = build(
|
|
205
|
+
const tree = build({
|
|
206
|
+
lang,
|
|
207
|
+
options,
|
|
208
|
+
builder: this,
|
|
209
|
+
storage: options.storage
|
|
210
|
+
});
|
|
205
211
|
return [lang, tree];
|
|
206
212
|
});
|
|
207
213
|
return Object.fromEntries(entries);
|
|
@@ -209,8 +215,7 @@ function createPageTreeBuilder(options) {
|
|
|
209
215
|
};
|
|
210
216
|
}
|
|
211
217
|
function findLocalizedFile(path, format, ctx) {
|
|
212
|
-
if (!ctx.lang)
|
|
213
|
-
return;
|
|
218
|
+
if (!ctx.lang) return;
|
|
214
219
|
return ctx.storage.read(`${path}.${ctx.lang}`, format);
|
|
215
220
|
}
|
|
216
221
|
function pathToName(path) {
|
|
@@ -219,8 +224,7 @@ function pathToName(path) {
|
|
|
219
224
|
function removeUndefined(value) {
|
|
220
225
|
const obj = value;
|
|
221
226
|
Object.keys(obj).forEach((key) => {
|
|
222
|
-
if (obj[key] === void 0)
|
|
223
|
-
delete obj[key];
|
|
227
|
+
if (obj[key] === void 0) delete obj[key];
|
|
224
228
|
});
|
|
225
229
|
return value;
|
|
226
230
|
}
|
|
@@ -272,8 +276,7 @@ var Storage = class {
|
|
|
272
276
|
const segments = splitPath(path);
|
|
273
277
|
for (let i = 0; i < segments.length; i++) {
|
|
274
278
|
const segment = segments.slice(0, i + 1).join("/");
|
|
275
|
-
if (this.folders.has(segment))
|
|
276
|
-
continue;
|
|
279
|
+
if (this.folders.has(segment)) continue;
|
|
277
280
|
const folder = {
|
|
278
281
|
file: parseFolderPath(segment),
|
|
279
282
|
children: []
|
|
@@ -292,8 +295,7 @@ function loadFiles(files, options) {
|
|
|
292
295
|
const rootDir = normalizePath((_a = options.rootDir) != null ? _a : "");
|
|
293
296
|
for (const file of files) {
|
|
294
297
|
const normalizedPath = normalizePath(file.path);
|
|
295
|
-
if (!normalizedPath.startsWith(rootDir))
|
|
296
|
-
continue;
|
|
298
|
+
if (!normalizedPath.startsWith(rootDir)) continue;
|
|
297
299
|
const relativePath = normalizedPath.slice(rootDir.length);
|
|
298
300
|
if (file.type === "page") {
|
|
299
301
|
const parsedPath = parseFilePath(relativePath);
|
|
@@ -325,8 +327,7 @@ function buildPageMap(storage, languages, getUrl) {
|
|
|
325
327
|
const defaultMap = /* @__PURE__ */ new Map();
|
|
326
328
|
map.set("", defaultMap);
|
|
327
329
|
for (const file of storage.list()) {
|
|
328
|
-
if (file.format !== "page" || file.file.locale)
|
|
329
|
-
continue;
|
|
330
|
+
if (file.format !== "page" || file.file.locale) continue;
|
|
330
331
|
const page = fileToPage(file, getUrl);
|
|
331
332
|
defaultMap.set(page.slugs.join("/"), page);
|
|
332
333
|
for (const lang of languages) {
|
|
@@ -357,13 +358,14 @@ function loader(options) {
|
|
|
357
358
|
}
|
|
358
359
|
function createOutput({
|
|
359
360
|
source,
|
|
360
|
-
icon,
|
|
361
|
+
icon: resolveIcon,
|
|
361
362
|
languages,
|
|
362
363
|
rootDir = "",
|
|
363
364
|
transformers,
|
|
364
365
|
baseUrl = "/",
|
|
365
366
|
slugs: slugsFn = getSlugs,
|
|
366
|
-
url: getUrl = createGetUrl(baseUrl)
|
|
367
|
+
url: getUrl = createGetUrl(baseUrl),
|
|
368
|
+
pageTree: pageTreeOptions = {}
|
|
367
369
|
}) {
|
|
368
370
|
const storage = loadFiles(
|
|
369
371
|
typeof source.files === "function" ? source.files(rootDir) : source.files,
|
|
@@ -374,12 +376,17 @@ function createOutput({
|
|
|
374
376
|
}
|
|
375
377
|
);
|
|
376
378
|
const i18nMap = buildPageMap(storage, languages != null ? languages : [], getUrl);
|
|
377
|
-
const builder = createPageTreeBuilder(
|
|
379
|
+
const builder = createPageTreeBuilder();
|
|
380
|
+
const pageTree = languages === void 0 ? builder.build(__spreadValues({
|
|
378
381
|
storage,
|
|
379
|
-
resolveIcon
|
|
382
|
+
resolveIcon,
|
|
380
383
|
getUrl
|
|
381
|
-
})
|
|
382
|
-
|
|
384
|
+
}, pageTreeOptions)) : builder.buildI18n(__spreadValues({
|
|
385
|
+
languages,
|
|
386
|
+
storage,
|
|
387
|
+
resolveIcon,
|
|
388
|
+
getUrl
|
|
389
|
+
}, pageTreeOptions));
|
|
383
390
|
return {
|
|
384
391
|
pageTree,
|
|
385
392
|
files: storage.list(),
|
package/dist/toc.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { HTMLAttributes, RefObject, ReactNode, AnchorHTMLAttributes } from 'react';
|
|
3
|
-
import { T as TableOfContents } from './get-toc-
|
|
3
|
+
import { T as TableOfContents } from './get-toc-B-AMfFKT.js';
|
|
4
4
|
|
|
5
5
|
declare const useActiveAnchor: (url: string) => boolean;
|
|
6
6
|
interface TOCProviderProps extends HTMLAttributes<HTMLDivElement> {
|
package/dist/toc.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "The library for building a documentation website in Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -113,8 +113,8 @@
|
|
|
113
113
|
],
|
|
114
114
|
"dependencies": {
|
|
115
115
|
"@formatjs/intl-localematcher": "^0.5.4",
|
|
116
|
-
"@shikijs/rehype": "^1.6.
|
|
117
|
-
"@shikijs/transformers": "^1.6.
|
|
116
|
+
"@shikijs/rehype": "^1.6.3",
|
|
117
|
+
"@shikijs/transformers": "^1.6.3",
|
|
118
118
|
"flexsearch": "0.7.21",
|
|
119
119
|
"github-slugger": "^2.0.0",
|
|
120
120
|
"hast-util-to-estree": "^3.1.0",
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"remark-gfm": "^4.0.0",
|
|
126
126
|
"remark-mdx": "^3.0.1",
|
|
127
127
|
"scroll-into-view-if-needed": "^3.1.0",
|
|
128
|
-
"shiki": "^1.6.
|
|
128
|
+
"shiki": "^1.6.3",
|
|
129
129
|
"swr": "^2.2.5",
|
|
130
130
|
"unist-util-visit": "^5.0.0"
|
|
131
131
|
},
|
|
File without changes
|
|
File without changes
|
|
File without changes
|