fumadocs-core 15.2.13 → 15.2.15

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.
@@ -2,19 +2,6 @@
2
2
  import { toJsxRuntime } from "hast-util-to-jsx-runtime";
3
3
  import { Fragment } from "react";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
- function createStyleTransformer() {
6
- return {
7
- name: "rehype-code:styles",
8
- line(hast) {
9
- if (hast.children.length === 0) {
10
- hast.children.push({
11
- type: "text",
12
- value: " "
13
- });
14
- }
15
- }
16
- };
17
- }
18
5
  var defaultThemes = {
19
6
  light: "github-light",
20
7
  dark: "github-dark"
@@ -37,7 +24,6 @@ async function _highlight(code, options) {
37
24
  lang,
38
25
  ...rest,
39
26
  ...themes,
40
- transformers: [createStyleTransformer(), ...rest.transformers ?? []],
41
27
  defaultColor: "themes" in themes ? false : void 0
42
28
  });
43
29
  }
@@ -88,7 +74,6 @@ async function highlight(code, options) {
88
74
  }
89
75
 
90
76
  export {
91
- createStyleTransformer,
92
77
  defaultThemes,
93
78
  _highlight,
94
79
  _renderHighlight,
@@ -21,6 +21,12 @@ interface I18nConfig {
21
21
  * @defaultValue 'never'
22
22
  */
23
23
  hideLocale?: 'always' | 'default-locale' | 'never';
24
+ /**
25
+ * Used by `loader()`, specify the way to parse i18n file structure.
26
+ *
27
+ * @defaultValue 'dot'
28
+ */
29
+ parser?: 'dot' | 'dir';
24
30
  }
25
31
 
26
32
  export type { I18nConfig as I };
@@ -3,7 +3,7 @@ import {
3
3
  _highlight,
4
4
  _renderHighlight,
5
5
  highlight
6
- } from "../chunk-SRVMHXJD.js";
6
+ } from "../chunk-KNWSJ4IF.js";
7
7
  import "../chunk-MLKGABMK.js";
8
8
 
9
9
  // src/highlight/client.tsx
@@ -1,9 +1,8 @@
1
- import { CodeToHastOptionsCommon, BundledLanguage, CodeOptionsMeta, Awaitable, RegexEngine, CodeOptionsThemes, ShikiTransformer, BundledHighlighterOptions, Highlighter } from 'shiki';
1
+ import { CodeToHastOptionsCommon, BundledLanguage, CodeOptionsMeta, Awaitable, RegexEngine, CodeOptionsThemes, BundledHighlighterOptions, Highlighter } from 'shiki';
2
2
  import { BundledTheme } from 'shiki/themes';
3
3
  import { Components } from 'hast-util-to-jsx-runtime';
4
4
  import { ReactNode } from 'react';
5
5
 
6
- declare function createStyleTransformer(): ShikiTransformer;
7
6
  type HighlightOptionsCommon = CodeToHastOptionsCommon<BundledLanguage> & CodeOptionsMeta & {
8
7
  engine?: Awaitable<RegexEngine>;
9
8
  components?: Partial<Components>;
@@ -19,4 +18,4 @@ type HighlightOptions = HighlightOptionsCommon & (HighlightOptionsThemes | Recor
19
18
  declare function getHighlighter(engineType: 'js' | 'oniguruma' | 'custom', options: BundledHighlighterOptions<BundledLanguage, BundledTheme>): Promise<Highlighter>;
20
19
  declare function highlight(code: string, options: HighlightOptions): Promise<ReactNode>;
21
20
 
22
- export { type HighlightOptions, type HighlightOptionsCommon, type HighlightOptionsThemes, createStyleTransformer, getHighlighter, highlight };
21
+ export { type HighlightOptions, type HighlightOptionsCommon, type HighlightOptionsThemes, getHighlighter, highlight };
@@ -1,11 +1,9 @@
1
1
  import {
2
- createStyleTransformer,
3
2
  getHighlighter,
4
3
  highlight
5
- } from "../chunk-SRVMHXJD.js";
4
+ } from "../chunk-KNWSJ4IF.js";
6
5
  import "../chunk-MLKGABMK.js";
7
6
  export {
8
- createStyleTransformer,
9
7
  getHighlighter,
10
8
  highlight
11
9
  };
@@ -1,4 +1,4 @@
1
- import { I as I18nConfig } from '../config-inq6kP6y.js';
1
+ import { I as I18nConfig } from '../config-Cm58P4fz.js';
2
2
  import { NextMiddleware } from 'next/dist/server/web/types';
3
3
 
4
4
  interface MiddlewareOptions extends I18nConfig {
@@ -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 } from 'mdast';
7
- export { a as StructureOptions, S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-FIjTA11P.js';
7
+ export { a as StructureOptions, S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-DVje0Sib.js';
8
8
  export { R as RemarkHeadingOptions, r as remarkHeading } from '../remark-heading-BPCoYwjn.js';
9
9
  import 'mdast-util-mdx-jsx';
10
10
 
@@ -7,10 +7,9 @@ import {
7
7
  slash
8
8
  } from "../chunk-XMCPKVJQ.js";
9
9
  import {
10
- createStyleTransformer,
11
10
  defaultThemes,
12
11
  getHighlighter
13
- } from "../chunk-SRVMHXJD.js";
12
+ } from "../chunk-KNWSJ4IF.js";
14
13
  import "../chunk-MLKGABMK.js";
15
14
 
16
15
  // src/mdx-plugins/index.ts
@@ -194,7 +193,6 @@ var rehypeCodeDefaultOptions = {
194
193
  defaultLanguage: "plaintext",
195
194
  experimentalJSEngine: false,
196
195
  transformers: [
197
- createStyleTransformer(),
198
196
  transformerNotationHighlight({
199
197
  matchAlgorithm: "v3"
200
198
  }),
@@ -247,7 +245,7 @@ function rehypeCode(_options = {}) {
247
245
  options.experimentalJSEngine ? "js" : "oniguruma",
248
246
  {
249
247
  themes: "themes" in options ? Object.values(options.themes).filter(Boolean) : [options.theme],
250
- langs: options.langs ?? (options.lazy ? [] : Object.keys(bundledLanguages))
248
+ langs: options.langs ?? (options.lazy ? ["ts", "tsx"] : Object.keys(bundledLanguages))
251
249
  }
252
250
  );
253
251
  const transformer = highlighter.then(
@@ -450,7 +448,10 @@ function remarkStructure({
450
448
  "tableCell",
451
449
  "mdxJsxFlowElement"
452
450
  ],
453
- allowedMdxAttributes = () => true
451
+ allowedMdxAttributes = (node) => {
452
+ if (!node.name) return false;
453
+ return ["TypeTable", "Callout"].includes(node.name);
454
+ }
454
455
  } = {}) {
455
456
  if (Array.isArray(allowedMdxAttributes)) {
456
457
  const arr = allowedMdxAttributes;
@@ -503,13 +504,13 @@ function remarkStructure({
503
504
  content: element.name
504
505
  },
505
506
  ...element.attributes.flatMap((attribute) => {
506
- const valueStr = typeof attribute.value === "string" ? attribute.value : attribute.value?.value;
507
- if (!valueStr) return [];
507
+ const value = typeof attribute.value === "string" ? attribute.value : attribute.value?.value;
508
+ if (!value || value.length === 0) return [];
508
509
  if (allowedMdxAttributes && !allowedMdxAttributes(element, attribute))
509
510
  return [];
510
511
  return {
511
512
  heading: lastHeading,
512
- content: attribute.type === "mdxJsxAttribute" ? `${attribute.name}: ${valueStr}` : valueStr
513
+ content: attribute.type === "mdxJsxAttribute" ? `${attribute.name}: ${value}` : value
513
514
  };
514
515
  })
515
516
  );
@@ -1,6 +1,6 @@
1
1
  import { Nodes, Root } from 'mdast';
2
2
  import { Transformer, PluggableList } from 'unified';
3
- import { MdxJsxAttribute, MdxJsxExpressionAttribute } from 'mdast-util-mdx-jsx';
3
+ import { MdxJsxFlowElement, MdxJsxAttribute, MdxJsxExpressionAttribute } from 'mdast-util-mdx-jsx';
4
4
 
5
5
  interface Heading {
6
6
  id: string;
@@ -24,7 +24,13 @@ interface StructureOptions {
24
24
  * @defaultValue ['heading', 'paragraph', 'blockquote', 'tableCell', 'mdxJsxFlowElement']
25
25
  */
26
26
  types?: string[] | ((node: Nodes) => boolean);
27
- allowedMdxAttributes?: string[] | ((node: Nodes, attribute: MdxJsxAttribute | MdxJsxExpressionAttribute) => boolean);
27
+ /**
28
+ * A list of indexable MDX attributes, either:
29
+ *
30
+ * - an array of attribute names.
31
+ * - a function that determines if attribute should be indexed.
32
+ */
33
+ allowedMdxAttributes?: string[] | ((node: MdxJsxFlowElement, attribute: MdxJsxAttribute | MdxJsxExpressionAttribute) => boolean);
28
34
  }
29
35
  declare module 'mdast' {
30
36
  interface Data {
@@ -1,5 +1,5 @@
1
1
  import { SearchClient, SearchIndex } from 'algoliasearch';
2
- import { S as StructuredData } from '../remark-structure-FIjTA11P.js';
2
+ import { S as StructuredData } from '../remark-structure-DVje0Sib.js';
3
3
  import 'mdast';
4
4
  import 'unified';
5
5
  import 'mdast-util-mdx-jsx';
@@ -2,7 +2,7 @@ import { S as SortedResult } from '../types-Ch8gnVgO.js';
2
2
  import { AnyOrama } from '@orama/orama';
3
3
  import { SearchOptions } from '@algolia/client-search';
4
4
  import { SearchIndex } from 'algoliasearch/lite';
5
- import '../remark-structure-FIjTA11P.js';
5
+ import '../remark-structure-DVje0Sib.js';
6
6
  import { OramaClient, ClientSearchParams } from '@oramacloud/client';
7
7
  import 'mdast';
8
8
  import 'unified';
@@ -1,5 +1,5 @@
1
1
  import { CloudManager } from '@oramacloud/client';
2
- import { S as StructuredData } from '../remark-structure-FIjTA11P.js';
2
+ import { S as StructuredData } from '../remark-structure-DVje0Sib.js';
3
3
  import '../remark-heading-BPCoYwjn.js';
4
4
  import 'mdast';
5
5
  import 'unified';
@@ -1,7 +1,7 @@
1
1
  import { TypedDocument, Orama, Language, RawData, create, SearchParams } from '@orama/orama';
2
- import { S as StructuredData } from '../remark-structure-FIjTA11P.js';
2
+ import { S as StructuredData } from '../remark-structure-DVje0Sib.js';
3
3
  import { S as SortedResult } from '../types-Ch8gnVgO.js';
4
- import { I as I18nConfig } from '../config-inq6kP6y.js';
4
+ import { I as I18nConfig } from '../config-Cm58P4fz.js';
5
5
  import { LoaderOutput, LoaderConfig, InferPageType } from '../source/index.js';
6
6
  import 'mdast';
7
7
  import 'unified';
@@ -8,7 +8,7 @@ import { LoaderOutput, LoaderConfig, InferPageType } from '../source/index.js';
8
8
  import 'react';
9
9
  import 'unified';
10
10
  import 'vfile';
11
- import '../config-inq6kP6y.js';
11
+ import '../config-Cm58P4fz.js';
12
12
 
13
13
  /**
14
14
  * Flatten tree to an array of page nodes
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { I as I18nConfig } from '../config-inq6kP6y.js';
2
+ import { I as I18nConfig } from '../config-Cm58P4fz.js';
3
3
  import { R as Root, I as Item, F as Folder$1, S as Separator } from '../page-tree-bSt6K__E.js';
4
4
 
5
5
  interface FileInfo {
@@ -43,13 +43,6 @@ interface LoadOptions {
43
43
  transformers?: Transformer[];
44
44
  getSlugs: (info: FileInfo) => string[];
45
45
  }
46
- interface I18nLoadOptions extends LoadOptions {
47
- i18n: {
48
- parser: 'dot' | 'dir';
49
- languages: string[];
50
- defaultLanguage: string;
51
- };
52
- }
53
46
  interface VirtualFile {
54
47
  /**
55
48
  * Relative path
@@ -78,23 +71,21 @@ interface SourceConfig {
78
71
  pageData: PageData;
79
72
  metaData: MetaData;
80
73
  }
81
- interface LoaderOptions {
74
+ interface LoaderOptions<T extends SourceConfig = SourceConfig, I18n extends I18nConfig | undefined = I18nConfig | undefined> {
82
75
  baseUrl: string;
83
- icon?: NonNullable<BuildPageTreeOptions['resolveIcon']>;
76
+ icon?: NonNullable<BaseOptions['resolveIcon']>;
84
77
  slugs?: LoadOptions['getSlugs'];
85
78
  url?: UrlFn;
86
- source: Source<any>;
79
+ source: Source<T>;
87
80
  transformers?: Transformer[];
88
81
  /**
89
82
  * Additional options for page tree builder
90
83
  */
91
- pageTree?: Partial<Omit<BuildPageTreeOptions, 'storage' | 'getUrl'>>;
84
+ pageTree?: Partial<BaseOptions<T['pageData'], T['metaData']>>;
92
85
  /**
93
86
  * Configure i18n
94
87
  */
95
- i18n?: I18nConfig & {
96
- parser?: I18nLoadOptions['i18n']['parser'];
97
- };
88
+ i18n?: I18n;
98
89
  }
99
90
  interface Source<Config extends SourceConfig> {
100
91
  /**
@@ -162,10 +153,9 @@ interface LoaderOutput<Config extends LoaderConfig> {
162
153
  }
163
154
  declare function createGetUrl(baseUrl: string, i18n?: I18nConfig): UrlFn;
164
155
  declare function getSlugs(info: FileInfo): string[];
165
- type InferSourceConfig<T> = T extends Source<infer Config> ? Config : never;
166
- declare function loader<Options extends LoaderOptions>(options: Options): LoaderOutput<{
167
- source: InferSourceConfig<Options['source']>;
168
- i18n: Options['i18n'] extends I18nConfig ? true : false;
156
+ declare function loader<Config extends SourceConfig, I18n extends I18nConfig | undefined = undefined>(options: LoaderOptions<Config, I18n>): LoaderOutput<{
157
+ source: Config;
158
+ i18n: I18n extends I18nConfig ? true : false;
169
159
  }>;
170
160
 
171
161
  interface MetaData {
@@ -188,23 +178,23 @@ type InferMetaType<Utils extends LoaderOutput<any>> = Utils extends LoaderOutput
188
178
  */
189
179
  type UrlFn = (slugs: string[], locale?: string) => string;
190
180
 
191
- interface MetaFile {
181
+ interface MetaFile<Data extends MetaData = MetaData> {
192
182
  file: FileInfo;
193
183
  format: 'meta';
194
- data: MetaData;
184
+ data: Data;
195
185
  }
196
- interface PageFile {
186
+ interface PageFile<Data extends PageData = PageData> {
197
187
  file: FileInfo;
198
188
  format: 'page';
199
189
  data: {
200
190
  slugs: string[];
201
- data: PageData;
191
+ data: Data;
202
192
  };
203
193
  }
204
194
  type File = MetaFile | PageFile;
205
- interface Folder {
195
+ interface Folder<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
206
196
  file: FolderInfo;
207
- children: (File | Folder)[];
197
+ children: (MetaFile<Meta> | PageFile<Page> | Folder<Page, Meta>)[];
208
198
  }
209
199
  /**
210
200
  * A virtual file system that solves inconsistent behaviours
@@ -213,7 +203,7 @@ interface Folder {
213
203
  */
214
204
  declare class Storage {
215
205
  files: Map<string, File>;
216
- folders: Map<string, Folder>;
206
+ folders: Map<string, Folder<PageData, MetaData>>;
217
207
  private rootFolder;
218
208
  constructor();
219
209
  /**
@@ -232,33 +222,31 @@ declare class Storage {
232
222
  makeDir(path: string): void;
233
223
  }
234
224
 
235
- type fileSystem_File = File;
236
- type fileSystem_Folder = Folder;
237
- type fileSystem_MetaFile = MetaFile;
238
- type fileSystem_PageFile = PageFile;
225
+ type fileSystem_Folder<Page extends PageData = PageData, Meta extends MetaData = MetaData> = Folder<Page, Meta>;
226
+ type fileSystem_MetaFile<Data extends MetaData = MetaData> = MetaFile<Data>;
227
+ type fileSystem_PageFile<Data extends PageData = PageData> = PageFile<Data>;
239
228
  type fileSystem_Storage = Storage;
240
229
  declare const fileSystem_Storage: typeof Storage;
241
230
  declare namespace fileSystem {
242
- export { type fileSystem_File as File, type fileSystem_Folder as Folder, type fileSystem_MetaFile as MetaFile, type fileSystem_PageFile as PageFile, fileSystem_Storage as Storage };
231
+ export { type fileSystem_Folder as Folder, type fileSystem_MetaFile as MetaFile, type fileSystem_PageFile as PageFile, fileSystem_Storage as Storage };
243
232
  }
244
233
 
245
- interface Options {
234
+ interface BaseOptions<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
246
235
  /**
247
236
  * Remove references to the file path of original nodes (`$ref`)
248
237
  *
249
238
  * @defaultValue false
250
239
  */
251
240
  noRef?: boolean;
252
- attachFile?: (node: Item, file?: PageFile) => Item;
253
- attachFolder?: (node: Folder$1, folder: Folder, meta?: MetaFile) => Folder$1;
241
+ attachFile?: (node: Item, file?: PageFile<Page>) => Item;
242
+ attachFolder?: (node: Folder$1, folder: Folder<Page, Meta>, meta?: MetaFile<Meta>) => Folder$1;
254
243
  attachSeparator?: (node: Separator) => Separator;
255
- getUrl: UrlFn;
256
244
  resolveIcon?: (icon: string | undefined) => ReactElement | undefined;
257
245
  }
258
- interface BuildPageTreeOptions extends Options {
246
+ interface BuildPageTreeOptions extends BaseOptions {
259
247
  storage: Storage;
260
248
  }
261
- interface BuildPageTreeOptionsWithI18n extends Options {
249
+ interface BuildPageTreeOptionsWithI18n extends BaseOptions {
262
250
  storages: Record<string, Storage>;
263
251
  i18n: I18nConfig;
264
252
  }
@@ -269,6 +257,6 @@ interface PageTreeBuilder {
269
257
  */
270
258
  buildI18n: (options: BuildPageTreeOptionsWithI18n) => Record<string, Root>;
271
259
  }
272
- declare function createPageTreeBuilder(): PageTreeBuilder;
260
+ declare function createPageTreeBuilder(getUrl: UrlFn): PageTreeBuilder;
273
261
 
274
- export { type BuildPageTreeOptions, type BuildPageTreeOptionsWithI18n, type FileInfo, fileSystem as FileSystem, type FolderInfo, 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, loadFiles, loader, parseFilePath, parseFolderPath };
262
+ export { type BaseOptions, type BuildPageTreeOptions, type BuildPageTreeOptionsWithI18n, type FileInfo, fileSystem as FileSystem, type FolderInfo, 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, loadFiles, loader, parseFilePath, parseFolderPath };
@@ -140,7 +140,7 @@ function buildFileNode(file, ctx) {
140
140
  name: file.data.data.title ?? pathToName(file.file.name),
141
141
  description: file.data.data.description,
142
142
  icon: ctx.options.resolveIcon?.(file.data.data.icon),
143
- url: ctx.options.getUrl(file.data.slugs, ctx.locale),
143
+ url: ctx.getUrl(file.data.slugs, ctx.locale),
144
144
  $ref: !ctx.options.noRef ? {
145
145
  file: file.file.path
146
146
  } : void 0
@@ -156,19 +156,21 @@ function build(ctx) {
156
156
  children: folder.children
157
157
  };
158
158
  }
159
- function createPageTreeBuilder() {
159
+ function createPageTreeBuilder(getUrl) {
160
160
  return {
161
161
  build(options) {
162
162
  return build({
163
163
  options,
164
164
  builder: this,
165
- storage: options.storage
165
+ storage: options.storage,
166
+ getUrl
166
167
  });
167
168
  },
168
169
  buildI18n({ i18n, ...options }) {
169
170
  const entries = i18n.languages.map((lang) => {
170
171
  const tree = build({
171
172
  options,
173
+ getUrl,
172
174
  builder: this,
173
175
  locale: lang,
174
176
  storage: options.storages[i18n.defaultLanguage],
@@ -429,7 +431,7 @@ function createOutput(options) {
429
431
  })
430
432
  };
431
433
  const walker = indexPages(storages, getUrl, options.i18n);
432
- const builder = createPageTreeBuilder();
434
+ const builder = createPageTreeBuilder(getUrl);
433
435
  let pageTree;
434
436
  return {
435
437
  _i18n: options.i18n,
@@ -438,7 +440,6 @@ function createOutput(options) {
438
440
  pageTree ??= builder.buildI18n({
439
441
  storages,
440
442
  resolveIcon: options.icon,
441
- getUrl,
442
443
  i18n: options.i18n,
443
444
  ...options.pageTree
444
445
  });
@@ -446,7 +447,6 @@ function createOutput(options) {
446
447
  pageTree ??= builder.build({
447
448
  storage: storages[""],
448
449
  resolveIcon: options.icon,
449
- getUrl,
450
450
  ...options.pageTree
451
451
  });
452
452
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "15.2.13",
3
+ "version": "15.2.15",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -115,8 +115,8 @@
115
115
  "typescript": "^5.8.3",
116
116
  "unified": "^11.0.5",
117
117
  "vfile": "^6.0.3",
118
- "eslint-config-custom": "0.0.0",
119
- "tsconfig": "0.0.0"
118
+ "tsconfig": "0.0.0",
119
+ "eslint-config-custom": "0.0.0"
120
120
  },
121
121
  "peerDependencies": {
122
122
  "@oramacloud/client": "1.x.x || 2.x.x",