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.
@@ -1,4 +1,4 @@
1
- import { R as Root } from './page-tree-mLHMYx2B.js';
1
+ import { R as Root } from './page-tree-_z0bnHIU.js';
2
2
  import 'react';
3
3
 
4
4
  interface BreadcrumbItem {
@@ -1,4 +1,4 @@
1
- import "./chunk-WEAGW6MQ.js";
1
+ import "./chunk-UWTMEZUM.js";
2
2
 
3
3
  // src/breadcrumb.tsx
4
4
  import { useMemo } from "react";
@@ -2,7 +2,7 @@ import {
2
2
  __objRest,
3
3
  __spreadProps,
4
4
  __spreadValues
5
- } from "./chunk-WEAGW6MQ.js";
5
+ } from "./chunk-UWTMEZUM.js";
6
6
 
7
7
  // src/link.tsx
8
8
  import Original from "next/link";
@@ -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
- let id = heading.data.hProperties.id;
21
- if (!id && customId) {
22
- const match = regex.exec(node.value);
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
- node.value = node.value.slice(0, match.index);
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, node.value) : slugger.slug(node.value);
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: node.value,
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
  };
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import {
3
3
  Link
4
- } from "./chunk-AFKH746E.js";
4
+ } from "./chunk-2BP57A6C.js";
5
5
  import {
6
6
  __objRest,
7
7
  __spreadValues
8
- } from "./chunk-WEAGW6MQ.js";
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
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Link
3
- } from "./chunk-AFKH746E.js";
4
- import "./chunk-WEAGW6MQ.js";
3
+ } from "./chunk-2BP57A6C.js";
4
+ import "./chunk-UWTMEZUM.js";
5
5
  export {
6
6
  Link as default
7
7
  };
@@ -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-Os9Vuaua.js';
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-5BST7EWT.js";
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-WEAGW6MQ.js";
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, vfile) => __async(this, null, function* () {
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, vfile, () => {
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 = {});
@@ -1,4 +1,4 @@
1
- import "./chunk-WEAGW6MQ.js";
1
+ import "./chunk-UWTMEZUM.js";
2
2
 
3
3
  // src/middleware.ts
4
4
  import { match as matchLocale } from "@formatjs/intl-localematcher";
@@ -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 };
@@ -1,23 +1,19 @@
1
1
  import {
2
2
  __async
3
- } from "../chunk-WEAGW6MQ.js";
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
- params.set("locale", locale);
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
  }
@@ -1,5 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { S as StructuredData } from '../remark-structure-Os9Vuaua.js';
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';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __spreadProps,
3
3
  __spreadValues
4
- } from "../chunk-WEAGW6MQ.js";
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-Os9Vuaua.js';
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-WEAGW6MQ.js";
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
  {
@@ -1,5 +1,5 @@
1
1
  import { SearchClient, SearchIndex } from 'algoliasearch';
2
- import { S as StructuredData } from '../remark-structure-Os9Vuaua.js';
2
+ import { S as StructuredData } from '../remark-structure-Dj8oa5Ba.js';
3
3
  import 'mdast';
4
4
  import 'unified';
5
5
 
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __async,
3
3
  __spreadValues
4
- } from "../chunk-WEAGW6MQ.js";
4
+ } from "../chunk-UWTMEZUM.js";
5
5
 
6
6
  // src/search-algolia/server.ts
7
7
  import { randomUUID } from "crypto";
@@ -1,6 +1,6 @@
1
- export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-YF_TdazL.js';
2
- import { N as Node, I as Item, R as Root } from '../page-tree-mLHMYx2B.js';
3
- export { p as PageTree } from '../page-tree-mLHMYx2B.js';
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
  /**
@@ -1,17 +1,16 @@
1
1
  import {
2
2
  remarkHeading
3
- } from "../chunk-5BST7EWT.js";
3
+ } from "../chunk-QRNTLL6S.js";
4
4
  import {
5
5
  __async
6
- } from "../chunk-WEAGW6MQ.js";
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, minWidth, blockScrollingWidth, ...props }: SidebarContentProps<T>): ReactElement;
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-WEAGW6MQ.js";
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
- minWidth,
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
  );
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { R as Root } from '../page-tree-mLHMYx2B.js';
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<CreatePageTreeBuilderOptions['resolveIcon']>;
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 BuildPageTreeOptionsWithI18n {
181
- languages: string[];
182
- }
183
- interface PageTreeBuilder {
184
- build: () => Root;
184
+ interface BuildPageTreeOptions {
185
185
  /**
186
- * Build page tree and fallback to the default language if the localized page doesn't exist
186
+ * Attach the `folder.id` property
187
+ *
188
+ * @defaultValue false
187
189
  */
188
- buildI18n: (options?: Partial<BuildPageTreeOptionsWithI18n>) => Record<string, Root>;
189
- }
190
- interface CreatePageTreeBuilderOptions {
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
- declare function createPageTreeBuilder(options: CreatePageTreeBuilderOptions): PageTreeBuilder;
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 BuildPageTreeOptionsWithI18n, type CreatePageTreeBuilderOptions, 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 };
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 };
@@ -3,9 +3,9 @@ import {
3
3
  } from "../chunk-UWEEHUJV.js";
4
4
  import {
5
5
  __export,
6
- __spreadProps,
6
+ __objRest,
7
7
  __spreadValues
8
- } from "../chunk-WEAGW6MQ.js";
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
- return [
95
- {
96
- type: "separator",
97
- name: separateResult.groups.name
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
- return [
106
- {
107
- type: "page",
108
- name: text,
109
- url,
110
- external: !isRelative
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
- (_b = (_a = extractResult == null ? void 0 : extractResult.groups) == null ? void 0 : _a.name) != null ? _b : item
113
+ (_h = (_g = extractResult == null ? void 0 : extractResult.groups) == null ? void 0 : _g.name) != null ? _h : item
118
114
  );
119
- const itemNode = (_c = ctx.storage.readDir(path)) != null ? _c : ctx.storage.read(path, "page");
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((node) => !addedNodePaths.has(node.file.path)),
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
- return removeUndefined({
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 : _f.call(ctx, metadata == null ? void 0 : metadata.icon),
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
- return removeUndefined({
177
+ const item = {
177
178
  type: "page",
178
179
  name: data.data.title,
179
- icon: (_b = ctx.resolveIcon) == null ? void 0 : _b.call(ctx, data.data.icon),
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(options) {
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(getContext(this));
195
+ build(options) {
196
+ return build({
197
+ options,
198
+ builder: this,
199
+ storage: options.storage
200
+ });
201
201
  },
202
- buildI18n({ languages = [] } = {}) {
202
+ buildI18n(_a) {
203
+ var _b = _a, { languages = [] } = _b, options = __objRest(_b, ["languages"]);
203
204
  const entries = languages.map((lang) => {
204
- const tree = build(getContext(this, lang));
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: icon,
382
+ resolveIcon,
380
383
  getUrl
381
- });
382
- const pageTree = languages === void 0 ? builder.build() : builder.buildI18n({ languages });
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-YF_TdazL.js';
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
@@ -2,7 +2,7 @@ import {
2
2
  __objRest,
3
3
  __spreadProps,
4
4
  __spreadValues
5
- } from "./chunk-WEAGW6MQ.js";
5
+ } from "./chunk-UWTMEZUM.js";
6
6
 
7
7
  // src/toc.tsx
8
8
  import {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "11.3.1",
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.1",
117
- "@shikijs/transformers": "^1.6.1",
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.1",
128
+ "shiki": "^1.6.3",
129
129
  "swr": "^2.2.5",
130
130
  "unist-util-visit": "^5.0.0"
131
131
  },
File without changes