fumadocs-core 11.3.2 → 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-_omg_2NB.js';
1
+ import { R as Root } from './page-tree-_z0bnHIU.js';
2
2
  import 'react';
3
3
 
4
4
  interface BreadcrumbItem {
@@ -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,24 +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") return;
17
25
  heading.data || (heading.data = {});
18
26
  (_a = heading.data).hProperties || (_a.hProperties = {});
19
- let id = heading.data.hProperties.id;
20
- if (!id && customId) {
21
- 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);
22
30
  if (match == null ? void 0 : match[1]) {
23
- id = match[1];
24
- node.value = node.value.slice(0, match.index);
31
+ heading.data.hProperties.id = match[1];
32
+ lastNode.value = lastNode.value.slice(0, match.index);
25
33
  }
26
34
  }
35
+ const value = flattenNode(heading);
36
+ let id = heading.data.hProperties.id;
27
37
  if (!id) {
28
- id = defaultSlug ? defaultSlug(root, heading, node.value) : slugger.slug(node.value);
38
+ id = defaultSlug ? defaultSlug(root, heading, value) : slugger.slug(value);
29
39
  }
30
40
  heading.data.hProperties.id = id;
31
41
  toc.push({
32
- title: node.value,
42
+ title: value,
33
43
  url: `#${id}`,
34
44
  depth: heading.depth
35
45
  });
@@ -40,5 +50,6 @@ function remarkHeading({
40
50
  }
41
51
 
42
52
  export {
53
+ flattenNode,
43
54
  remarkHeading
44
55
  };
@@ -1,6 +1,7 @@
1
1
  import {
2
+ flattenNode,
2
3
  remarkHeading
3
- } from "../chunk-EWRPHFJQ.js";
4
+ } from "../chunk-QRNTLL6S.js";
4
5
  import {
5
6
  slash
6
7
  } from "../chunk-UWEEHUJV.js";
@@ -163,7 +164,7 @@ function transformerIcon(options = {}) {
163
164
  const lang = this.options.lang;
164
165
  if (!lang) return;
165
166
  const pre = root.children[0];
166
- if (pre.type !== "element") return;
167
+ if (pre.type !== "element" || pre.tagName !== "pre") return;
167
168
  const iconName = lang in shortcuts ? shortcuts[lang] : lang;
168
169
  const icon = iconName in icons ? icons[iconName] : icons.default;
169
170
  const tree = toEstree(pre, {
@@ -460,16 +461,6 @@ import { remark } from "remark";
460
461
  import remarkGfm from "remark-gfm";
461
462
  import remarkMdx from "remark-mdx";
462
463
  import { visit as visit3 } from "unist-util-visit";
463
-
464
- // src/mdx-plugins/remark-utils.ts
465
- function flattenNode(node) {
466
- if ("children" in node)
467
- return node.children.map((child) => flattenNode(child)).join("");
468
- if ("value" in node) return node.value;
469
- return "";
470
- }
471
-
472
- // src/mdx-plugins/remark-structure.ts
473
464
  var slugger = new Slugger();
474
465
  function remarkStructure({
475
466
  types = ["paragraph", "blockquote", "heading"]
@@ -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,6 +1,6 @@
1
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-_omg_2NB.js';
3
- export { p as PageTree } from '../page-tree-_omg_2NB.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,6 +1,6 @@
1
1
  import {
2
2
  remarkHeading
3
- } from "../chunk-EWRPHFJQ.js";
3
+ } from "../chunk-QRNTLL6S.js";
4
4
  import {
5
5
  __async
6
6
  } from "../chunk-UWTMEZUM.js";
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
@@ -5,7 +5,6 @@ import {
5
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,
@@ -28,10 +27,6 @@ function SidebarProvider(props) {
28
27
  (_a = props.open) != null ? _a : openInner,
29
28
  (_b = props.onOpenChange) != null ? _b : setOpenInner
30
29
  ];
31
- const pathname = usePathname();
32
- useEffect(() => {
33
- setOpen(false);
34
- }, [pathname, setOpen]);
35
30
  return /* @__PURE__ */ jsx(SidebarContext.Provider, { value: [open, setOpen], children: props.children });
36
31
  }
37
32
  function SidebarTrigger(_a) {
@@ -56,11 +51,9 @@ function SidebarTrigger(_a) {
56
51
  function SidebarList(_a) {
57
52
  var _b = _a, {
58
53
  as,
59
- minWidth,
60
- blockScrollingWidth = minWidth
54
+ blockScrollingWidth
61
55
  } = _b, props = __objRest(_b, [
62
56
  "as",
63
- "minWidth",
64
57
  "blockScrollingWidth"
65
58
  ]);
66
59
  const [open] = useSidebarContext();
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { R as Root } from '../page-tree-_omg_2NB.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,7 +3,7 @@ import {
3
3
  } from "../chunk-UWEEHUJV.js";
4
4
  import {
5
5
  __export,
6
- __spreadProps,
6
+ __objRest,
7
7
  __spreadValues
8
8
  } from "../chunk-UWTMEZUM.js";
9
9
 
@@ -85,36 +85,34 @@ function buildAll(nodes, ctx, skipIndex) {
85
85
  return output;
86
86
  }
87
87
  function resolveFolderItem(folder, item, ctx, addedNodePaths) {
88
- var _a, _b, _c;
88
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
89
89
  if (item === rest) return "...";
90
90
  const separateResult = separator.exec(item);
91
91
  if (separateResult == null ? void 0 : separateResult.groups) {
92
- return [
93
- {
94
- type: "separator",
95
- name: separateResult.groups.name
96
- }
97
- ];
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];
98
97
  }
99
98
  const linkResult = link.exec(item);
100
99
  if (linkResult == null ? void 0 : linkResult.groups) {
101
100
  const { url, text } = linkResult.groups;
102
101
  const isRelative = url.startsWith("/") || url.startsWith("#") || url.startsWith(".");
103
- return [
104
- {
105
- type: "page",
106
- name: text,
107
- url,
108
- external: !isRelative
109
- }
110
- ];
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];
111
109
  }
112
110
  const extractResult = extractor.exec(item);
113
111
  const path = resolvePath(
114
112
  folder.file.path,
115
- (_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
116
114
  );
117
- const itemNode = (_c = ctx.storage.readDir(path)) != null ? _c : ctx.storage.read(path, "page");
115
+ const itemNode = (_i = ctx.storage.readDir(path)) != null ? _i : ctx.storage.read(path, "page");
118
116
  if (!itemNode) return [];
119
117
  addedNodePaths.add(itemNode.file.path);
120
118
  if ("children" in itemNode) {
@@ -124,7 +122,7 @@ function resolveFolderItem(folder, item, ctx, addedNodePaths) {
124
122
  return [buildFileNode(itemNode, ctx)];
125
123
  }
126
124
  function buildFolderNode(folder, defaultIsRoot, ctx) {
127
- var _a, _b, _c, _d, _e, _f;
125
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
128
126
  const metaPath = resolvePath(folder.file.path, "meta");
129
127
  let meta = ctx.storage.read(metaPath, "meta");
130
128
  meta = (_a = findLocalizedFile(metaPath, "meta", ctx)) != null ? _a : meta;
@@ -144,7 +142,7 @@ function buildFolderNode(folder, defaultIsRoot, ctx) {
144
142
  return resolveFolderItem(folder, item, ctx, addedNodePaths);
145
143
  });
146
144
  const restNodes = buildAll(
147
- folder.children.filter((node) => !addedNodePaths.has(node.file.path)),
145
+ folder.children.filter((node2) => !addedNodePaths.has(node2.file.path)),
148
146
  ctx,
149
147
  !isRoot
150
148
  );
@@ -156,26 +154,33 @@ function buildFolderNode(folder, defaultIsRoot, ctx) {
156
154
  });
157
155
  children = nodes != null ? nodes : restNodes;
158
156
  }
159
- return removeUndefined({
157
+ const node = {
160
158
  type: "folder",
161
159
  name: (_e = (_d = metadata == null ? void 0 : metadata.title) != null ? _d : index == null ? void 0 : index.name) != null ? _e : pathToName(folder.file.name),
162
- 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),
163
161
  root: metadata == null ? void 0 : metadata.root,
164
162
  defaultOpen: metadata == null ? void 0 : metadata.defaultOpen,
165
163
  index,
166
164
  children
167
- });
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
+ );
168
172
  }
169
173
  function buildFileNode(file, ctx) {
170
- var _a, _b;
174
+ var _a, _b, _c, _d, _e, _f;
171
175
  const localized = (_a = findLocalizedFile(file.file.flattenedPath, "page", ctx)) != null ? _a : file;
172
176
  const data = localized.data;
173
- return removeUndefined({
177
+ const item = {
174
178
  type: "page",
175
179
  name: data.data.title,
176
- icon: (_b = ctx.resolveIcon) == null ? void 0 : _b.call(ctx, data.data.icon),
177
- url: ctx.getUrl(data.slugs, ctx.lang)
178
- });
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);
179
184
  }
180
185
  function build(ctx) {
181
186
  const root = ctx.storage.root();
@@ -185,20 +190,24 @@ function build(ctx) {
185
190
  children: folder.children
186
191
  };
187
192
  }
188
- function createPageTreeBuilder(options) {
189
- function getContext(builder, locale) {
190
- return __spreadProps(__spreadValues({}, options), {
191
- lang: locale,
192
- builder
193
- });
194
- }
193
+ function createPageTreeBuilder() {
195
194
  return {
196
- build() {
197
- return build(getContext(this));
195
+ build(options) {
196
+ return build({
197
+ options,
198
+ builder: this,
199
+ storage: options.storage
200
+ });
198
201
  },
199
- buildI18n({ languages = [] } = {}) {
202
+ buildI18n(_a) {
203
+ var _b = _a, { languages = [] } = _b, options = __objRest(_b, ["languages"]);
200
204
  const entries = languages.map((lang) => {
201
- const tree = build(getContext(this, lang));
205
+ const tree = build({
206
+ lang,
207
+ options,
208
+ builder: this,
209
+ storage: options.storage
210
+ });
202
211
  return [lang, tree];
203
212
  });
204
213
  return Object.fromEntries(entries);
@@ -349,13 +358,14 @@ function loader(options) {
349
358
  }
350
359
  function createOutput({
351
360
  source,
352
- icon,
361
+ icon: resolveIcon,
353
362
  languages,
354
363
  rootDir = "",
355
364
  transformers,
356
365
  baseUrl = "/",
357
366
  slugs: slugsFn = getSlugs,
358
- url: getUrl = createGetUrl(baseUrl)
367
+ url: getUrl = createGetUrl(baseUrl),
368
+ pageTree: pageTreeOptions = {}
359
369
  }) {
360
370
  const storage = loadFiles(
361
371
  typeof source.files === "function" ? source.files(rootDir) : source.files,
@@ -366,12 +376,17 @@ function createOutput({
366
376
  }
367
377
  );
368
378
  const i18nMap = buildPageMap(storage, languages != null ? languages : [], getUrl);
369
- const builder = createPageTreeBuilder({
379
+ const builder = createPageTreeBuilder();
380
+ const pageTree = languages === void 0 ? builder.build(__spreadValues({
370
381
  storage,
371
- resolveIcon: icon,
382
+ resolveIcon,
372
383
  getUrl
373
- });
374
- 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));
375
390
  return {
376
391
  pageTree,
377
392
  files: storage.list(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "11.3.2",
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
  },