fumadocs-mdx 12.0.3 → 13.0.1
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/bin.cjs +1116 -359
- package/dist/bin.js +4 -4
- package/dist/build-mdx-CCNr86q6.d.ts +53 -0
- package/dist/build-mdx-D-r3_eQL.d.cts +53 -0
- package/dist/bun/index.cjs +196 -52
- package/dist/bun/index.d.cts +8 -3
- package/dist/bun/index.d.ts +8 -3
- package/dist/bun/index.js +19 -10
- package/dist/{chunk-QAUWMR5D.js → chunk-3J3WL7WN.js} +23 -5
- package/dist/{chunk-6Y5JDZHD.js → chunk-CXA4JO4Z.js} +1 -21
- package/dist/chunk-EELYB2XC.js +207 -0
- package/dist/{chunk-46UPKP5R.js → chunk-II3H5ZVZ.js} +5 -5
- package/dist/{chunk-LGYVNESJ.js → chunk-JVZFH6ND.js} +6 -22
- package/dist/{chunk-LMG6UWCL.js → chunk-K5ZLPEIQ.js} +56 -16
- package/dist/{chunk-OMAMTKDE.js → chunk-KILFIBVW.js} +3 -12
- package/dist/chunk-NVRDCY6Z.js +30 -0
- package/dist/{chunk-RMDXSZYE.js → chunk-XQ5O7IPO.js} +31 -24
- package/dist/chunk-XZY2AWJI.js +81 -0
- package/dist/{chunk-VXEBLM4X.js → chunk-YVCR6FUH.js} +1 -1
- package/dist/config/index.cjs +56 -16
- package/dist/config/index.d.cts +2 -1
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +1 -1
- package/dist/{define-DJbJduHy.d.ts → core-B6j6Fxse.d.cts} +89 -2
- package/dist/{define-DJbJduHy.d.cts → core-B6j6Fxse.d.ts} +89 -2
- package/dist/index.cjs +0 -109
- package/dist/index.d.cts +75 -9
- package/dist/index.d.ts +75 -9
- package/dist/index.js +0 -11
- package/dist/{load-UUXLUBHL.js → load-MNG3CLET.js} +1 -3
- package/dist/next/index.cjs +298 -234
- package/dist/next/index.d.cts +2 -11
- package/dist/next/index.d.ts +2 -11
- package/dist/next/index.js +177 -141
- package/dist/node/loader.cjs +228 -85
- package/dist/node/loader.js +19 -9
- package/dist/plugins/json-schema.cjs +162 -0
- package/dist/plugins/json-schema.d.cts +24 -0
- package/dist/plugins/json-schema.d.ts +24 -0
- package/dist/plugins/json-schema.js +78 -0
- package/dist/runtime/next/async.cjs +108 -70
- package/dist/runtime/next/async.d.cts +9 -6
- package/dist/runtime/next/async.d.ts +9 -6
- package/dist/runtime/next/async.js +8 -18
- package/dist/runtime/next/index.cjs +25 -14
- package/dist/runtime/next/index.d.cts +11 -8
- package/dist/runtime/next/index.d.ts +11 -8
- package/dist/runtime/next/index.js +2 -2
- package/dist/runtime/vite/browser.cjs +7 -3
- package/dist/runtime/vite/browser.d.cts +56 -7
- package/dist/runtime/vite/browser.d.ts +56 -7
- package/dist/runtime/vite/browser.js +2 -1
- package/dist/runtime/vite/server.cjs +40 -34
- package/dist/runtime/vite/server.d.cts +13 -10
- package/dist/runtime/vite/server.d.ts +13 -10
- package/dist/runtime/vite/server.js +8 -23
- package/dist/{types-TeHjsmja.d.ts → types-AGzTfBmf.d.ts} +3 -10
- package/dist/{types-BRx1QsIJ.d.cts → types-DKGMoay5.d.cts} +3 -10
- package/dist/vite/index.cjs +443 -249
- package/dist/vite/index.d.cts +23 -10
- package/dist/vite/index.d.ts +23 -10
- package/dist/vite/index.js +213 -36
- package/dist/{loader-mdx.cjs → webpack/index.cjs} +268 -82
- package/dist/{loader-mdx.d.ts → webpack/index.d.cts} +1 -0
- package/dist/{loader-mdx.d.cts → webpack/index.d.ts} +1 -0
- package/dist/webpack/index.js +44 -0
- package/loader-mdx.cjs +1 -1
- package/package.json +30 -16
- package/dist/browser-BupUnhpC.d.ts +0 -98
- package/dist/browser-R0x9IPaQ.d.cts +0 -98
- package/dist/chunk-ADR6R7HM.js +0 -29
- package/dist/chunk-IQAEAI4P.js +0 -66
- package/dist/chunk-XMFLD5J6.js +0 -30
- package/dist/chunk-ZLCSVXCD.js +0 -10
- package/dist/chunk-ZX7TM4AR.js +0 -127
- package/dist/loader-mdx.js +0 -25
- package/dist/postinstall-SCSXM4IM.js +0 -10
- package/dist/shared-CfiiRctw.d.ts +0 -70
- package/dist/shared-fFqiuWJC.d.cts +0 -70
- package/dist/watcher-HGOH3APP.js +0 -22
package/dist/config/index.cjs
CHANGED
|
@@ -165,7 +165,7 @@ function getDefaultMDXOptions({
|
|
|
165
165
|
|
|
166
166
|
// src/loaders/mdx/remark-include.ts
|
|
167
167
|
var import_unified = require("unified");
|
|
168
|
-
var
|
|
168
|
+
var import_unist_util_visit2 = require("unist-util-visit");
|
|
169
169
|
var path = __toESM(require("path"), 1);
|
|
170
170
|
var fs = __toESM(require("fs/promises"), 1);
|
|
171
171
|
|
|
@@ -186,9 +186,53 @@ function fumaMatter(input) {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
// src/loaders/mdx/remark-include.ts
|
|
189
|
-
var import_remark_parse = __toESM(require("remark-parse"), 1);
|
|
190
|
-
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
191
189
|
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
190
|
+
|
|
191
|
+
// src/loaders/mdx/remark-unravel.ts
|
|
192
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
193
|
+
function remarkMarkAndUnravel() {
|
|
194
|
+
return (tree) => {
|
|
195
|
+
(0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
|
|
196
|
+
let offset = -1;
|
|
197
|
+
let all = true;
|
|
198
|
+
let oneOrMore = false;
|
|
199
|
+
if (parent && typeof index === "number" && node.type === "paragraph") {
|
|
200
|
+
const children = node.children;
|
|
201
|
+
while (++offset < children.length) {
|
|
202
|
+
const child = children[offset];
|
|
203
|
+
if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
|
|
204
|
+
oneOrMore = true;
|
|
205
|
+
} else if (child.type === "text" && child.value.trim().length === 0) {
|
|
206
|
+
} else {
|
|
207
|
+
all = false;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (all && oneOrMore) {
|
|
212
|
+
offset = -1;
|
|
213
|
+
const newChildren = [];
|
|
214
|
+
while (++offset < children.length) {
|
|
215
|
+
const child = children[offset];
|
|
216
|
+
if (child.type === "mdxJsxTextElement") {
|
|
217
|
+
child.type = "mdxJsxFlowElement";
|
|
218
|
+
}
|
|
219
|
+
if (child.type === "mdxTextExpression") {
|
|
220
|
+
child.type = "mdxFlowExpression";
|
|
221
|
+
}
|
|
222
|
+
if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
|
|
223
|
+
} else {
|
|
224
|
+
newChildren.push(child);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
parent.children.splice(index, 1, ...newChildren);
|
|
228
|
+
return index;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/loaders/mdx/remark-include.ts
|
|
192
236
|
var ElementLikeTypes = [
|
|
193
237
|
"mdxJsxFlowElement",
|
|
194
238
|
"mdxJsxTextElement",
|
|
@@ -228,7 +272,7 @@ function parseSpecifier(specifier) {
|
|
|
228
272
|
function extractSection(root, section) {
|
|
229
273
|
let nodes;
|
|
230
274
|
let capturingHeadingContent = false;
|
|
231
|
-
(0,
|
|
275
|
+
(0, import_unist_util_visit2.visit)(root, (node) => {
|
|
232
276
|
if (node.type === "heading") {
|
|
233
277
|
if (capturingHeadingContent) {
|
|
234
278
|
return false;
|
|
@@ -260,7 +304,7 @@ function extractSection(root, section) {
|
|
|
260
304
|
}
|
|
261
305
|
function remarkInclude() {
|
|
262
306
|
const TagName = "include";
|
|
263
|
-
async
|
|
307
|
+
const embedContent = async (file, heading, params, data) => {
|
|
264
308
|
let content;
|
|
265
309
|
try {
|
|
266
310
|
content = (await fs.readFile(file)).toString();
|
|
@@ -283,18 +327,17 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
283
327
|
data: {}
|
|
284
328
|
};
|
|
285
329
|
}
|
|
286
|
-
const parser =
|
|
287
|
-
ext === ".mdx" ? "mdx" : "md"
|
|
288
|
-
);
|
|
330
|
+
const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
|
|
289
331
|
const parsed = fumaMatter(content);
|
|
290
332
|
let mdast = parser.parse({
|
|
291
333
|
path: file,
|
|
292
334
|
value: parsed.content,
|
|
293
335
|
data: { frontmatter: parsed.data }
|
|
294
336
|
});
|
|
337
|
+
const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
|
|
295
338
|
if (heading) {
|
|
296
339
|
const extracted = extractSection(
|
|
297
|
-
await
|
|
340
|
+
await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
|
|
298
341
|
heading
|
|
299
342
|
);
|
|
300
343
|
if (!extracted)
|
|
@@ -302,13 +345,15 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
302
345
|
`Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
|
|
303
346
|
);
|
|
304
347
|
mdast = extracted;
|
|
348
|
+
} else {
|
|
349
|
+
mdast = await baseProcessor.run(mdast);
|
|
305
350
|
}
|
|
306
351
|
await update(mdast, path.dirname(file), data);
|
|
307
352
|
return mdast;
|
|
308
|
-
}
|
|
353
|
+
};
|
|
309
354
|
async function update(tree, directory, data) {
|
|
310
355
|
const queue = [];
|
|
311
|
-
(0,
|
|
356
|
+
(0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
312
357
|
const node = _node;
|
|
313
358
|
if (node.name !== TagName) return;
|
|
314
359
|
const specifier = flattenNode(node);
|
|
@@ -335,11 +380,6 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
335
380
|
await update(tree, path.dirname(file.path), file.data);
|
|
336
381
|
};
|
|
337
382
|
}
|
|
338
|
-
function getDefaultProcessor(format) {
|
|
339
|
-
const mdProcessor = (0, import_unified.unified)().use(import_remark_parse.default);
|
|
340
|
-
if (format === "md") return mdProcessor;
|
|
341
|
-
return mdProcessor.use(import_remark_mdx.default);
|
|
342
|
-
}
|
|
343
383
|
// Annotate the CommonJS export names for ESM import in node:
|
|
344
384
|
0 && (module.exports = {
|
|
345
385
|
defineCollections,
|
package/dist/config/index.d.cts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export { A as AnyCollection, B as BaseCollection,
|
|
1
|
+
export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, D as DefaultMDXOptions, b as DocCollection, c as DocsCollection, G as GlobalConfig, M as MetaCollection, P as PostprocessOptions, d as defineCollections, f as defineConfig, e as defineDocs, h as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../core-B6j6Fxse.cjs';
|
|
2
2
|
import { Processor, Transformer } from 'unified';
|
|
3
3
|
import { Root } from 'mdast';
|
|
4
4
|
import '@standard-schema/spec';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
|
6
6
|
import '@mdx-js/mdx';
|
|
7
7
|
import 'zod';
|
|
8
|
+
import 'chokidar';
|
|
8
9
|
|
|
9
10
|
declare function remarkInclude(this: Processor): Transformer<Root, Root>;
|
|
10
11
|
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export { A as AnyCollection, B as BaseCollection,
|
|
1
|
+
export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, D as DefaultMDXOptions, b as DocCollection, c as DocsCollection, G as GlobalConfig, M as MetaCollection, P as PostprocessOptions, d as defineCollections, f as defineConfig, e as defineDocs, h as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../core-B6j6Fxse.js';
|
|
2
2
|
import { Processor, Transformer } from 'unified';
|
|
3
3
|
import { Root } from 'mdast';
|
|
4
4
|
import '@standard-schema/spec';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
|
6
6
|
import '@mdx-js/mdx';
|
|
7
7
|
import 'zod';
|
|
8
|
+
import 'chokidar';
|
|
8
9
|
|
|
9
10
|
declare function remarkInclude(this: Processor): Transformer<Root, Root>;
|
|
10
11
|
|
package/dist/config/index.js
CHANGED
|
@@ -3,11 +3,13 @@ import * as plugins from 'fumadocs-core/mdx-plugins';
|
|
|
3
3
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
4
4
|
import { Pluggable } from 'unified';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
+
import { FSWatcher } from 'chokidar';
|
|
6
7
|
|
|
7
8
|
interface ExtractedReference {
|
|
8
9
|
href: string;
|
|
9
10
|
}
|
|
10
11
|
interface PostprocessOptions {
|
|
12
|
+
_format: 'md' | 'mdx';
|
|
11
13
|
/**
|
|
12
14
|
* Properties to export from `vfile.data`
|
|
13
15
|
*/
|
|
@@ -16,6 +18,12 @@ interface PostprocessOptions {
|
|
|
16
18
|
* stringify MDAST and export via `_markdown`.
|
|
17
19
|
*/
|
|
18
20
|
includeProcessedMarkdown?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* store MDAST and export via `_mdast`.
|
|
23
|
+
*/
|
|
24
|
+
includeMDAST?: boolean | {
|
|
25
|
+
removePosition?: boolean;
|
|
26
|
+
};
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
|
|
@@ -36,6 +44,9 @@ type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | '
|
|
|
36
44
|
};
|
|
37
45
|
declare function getDefaultMDXOptions({ valueToExport, rehypeCodeOptions, remarkImageOptions, remarkHeadingOptions, remarkStructureOptions, remarkCodeTabOptions, remarkNpmOptions, _withoutBundler, ...mdxOptions }: DefaultMDXOptions): ProcessorOptions;
|
|
38
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Zod 4 schema
|
|
49
|
+
*/
|
|
39
50
|
declare const metaSchema: z.ZodObject<{
|
|
40
51
|
title: z.ZodOptional<z.ZodString>;
|
|
41
52
|
pages: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -44,6 +55,9 @@ declare const metaSchema: z.ZodObject<{
|
|
|
44
55
|
defaultOpen: z.ZodOptional<z.ZodBoolean>;
|
|
45
56
|
icon: z.ZodOptional<z.ZodString>;
|
|
46
57
|
}, z.core.$strip>;
|
|
58
|
+
/**
|
|
59
|
+
* Zod 4 schema
|
|
60
|
+
*/
|
|
47
61
|
declare const frontmatterSchema: z.ZodObject<{
|
|
48
62
|
title: z.ZodString;
|
|
49
63
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -75,7 +89,7 @@ interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> ext
|
|
|
75
89
|
}
|
|
76
90
|
interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection {
|
|
77
91
|
type: 'doc';
|
|
78
|
-
postprocess?: PostprocessOptions
|
|
92
|
+
postprocess?: Partial<PostprocessOptions>;
|
|
79
93
|
mdxOptions?: ProcessorOptions;
|
|
80
94
|
/**
|
|
81
95
|
* Load files with async
|
|
@@ -98,6 +112,7 @@ type GlobalConfigMDXOptions = ({
|
|
|
98
112
|
preset: 'minimal';
|
|
99
113
|
} & ProcessorOptions);
|
|
100
114
|
interface GlobalConfig {
|
|
115
|
+
plugins?: PluginOption[];
|
|
101
116
|
/**
|
|
102
117
|
* Configure global MDX options
|
|
103
118
|
*/
|
|
@@ -128,4 +143,76 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
|
|
|
128
143
|
}): DocsCollection<DocSchema, MetaSchema, Async>;
|
|
129
144
|
declare function defineConfig(config?: GlobalConfig): GlobalConfig;
|
|
130
145
|
|
|
131
|
-
|
|
146
|
+
interface ConfigLoader {
|
|
147
|
+
getConfig: () => LoadedConfig | Promise<LoadedConfig>;
|
|
148
|
+
}
|
|
149
|
+
interface LoadedConfig {
|
|
150
|
+
collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
|
|
151
|
+
global: GlobalConfig;
|
|
152
|
+
getDefaultMDXOptions(mode?: 'default' | 'remote'): Promise<ProcessorOptions>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type Awaitable<T> = T | Promise<T>;
|
|
156
|
+
interface EmitEntry {
|
|
157
|
+
/**
|
|
158
|
+
* path relative to output directory
|
|
159
|
+
*/
|
|
160
|
+
path: string;
|
|
161
|
+
content: string;
|
|
162
|
+
}
|
|
163
|
+
interface PluginContext extends CoreOptions {
|
|
164
|
+
core: Core;
|
|
165
|
+
}
|
|
166
|
+
interface Plugin {
|
|
167
|
+
name?: string;
|
|
168
|
+
/**
|
|
169
|
+
* on config loaded/updated
|
|
170
|
+
*/
|
|
171
|
+
config?: (this: PluginContext, config: LoadedConfig) => Awaitable<void | LoadedConfig>;
|
|
172
|
+
/**
|
|
173
|
+
* Generate files (e.g. types, index file, or JSON schemas)
|
|
174
|
+
*/
|
|
175
|
+
emit?: (this: PluginContext) => Awaitable<EmitEntry[]>;
|
|
176
|
+
/**
|
|
177
|
+
* Configure Fumadocs dev server
|
|
178
|
+
*/
|
|
179
|
+
configureServer?: (this: PluginContext, server: ServerContext) => Awaitable<void>;
|
|
180
|
+
}
|
|
181
|
+
type PluginOption = Awaitable<Plugin | Plugin[] | false>;
|
|
182
|
+
interface ServerContext {
|
|
183
|
+
/**
|
|
184
|
+
* the file watcher, by default all content files are watched, along with other files.
|
|
185
|
+
*
|
|
186
|
+
* make sure to filter when listening to events
|
|
187
|
+
*/
|
|
188
|
+
watcher?: FSWatcher;
|
|
189
|
+
}
|
|
190
|
+
interface CoreOptions {
|
|
191
|
+
environment: string;
|
|
192
|
+
configPath: string;
|
|
193
|
+
outDir: string;
|
|
194
|
+
}
|
|
195
|
+
interface EmitOptions {
|
|
196
|
+
/**
|
|
197
|
+
* filter the plugins to run emit
|
|
198
|
+
*/
|
|
199
|
+
filterPlugin?: (plugin: Plugin) => boolean;
|
|
200
|
+
}
|
|
201
|
+
declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[]): {
|
|
202
|
+
_options: CoreOptions;
|
|
203
|
+
getPluginContext(): PluginContext;
|
|
204
|
+
/**
|
|
205
|
+
* Convenient cache store, reset when config changes
|
|
206
|
+
*/
|
|
207
|
+
cache: Map<string, unknown>;
|
|
208
|
+
init({ config: newConfig }: {
|
|
209
|
+
config: Awaitable<LoadedConfig>;
|
|
210
|
+
}): Promise</*elided*/ any>;
|
|
211
|
+
getConfig(): LoadedConfig;
|
|
212
|
+
creatConfigLoader(): ConfigLoader;
|
|
213
|
+
initServer(server: ServerContext): Promise<void>;
|
|
214
|
+
emitAndWrite({ filterPlugin, }?: EmitOptions): Promise<void>;
|
|
215
|
+
};
|
|
216
|
+
type Core = ReturnType<typeof createCore>;
|
|
217
|
+
|
|
218
|
+
export { type AnyCollection as A, type BaseCollection as B, type CoreOptions as C, type DefaultMDXOptions as D, type ExtractedReference as E, type GlobalConfig as G, type LoadedConfig as L, type MetaCollection as M, type PostprocessOptions as P, type ServerContext as S, type CollectionSchema as a, type DocCollection as b, type DocsCollection as c, defineCollections as d, defineDocs as e, defineConfig as f, getDefaultMDXOptions as g, frontmatterSchema as h, type Plugin as i, type EmitEntry as j, type PluginContext as k, type PluginOption as l, metaSchema as m, type EmitOptions as n, createCore as o, type Core as p };
|
|
@@ -3,11 +3,13 @@ import * as plugins from 'fumadocs-core/mdx-plugins';
|
|
|
3
3
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
4
4
|
import { Pluggable } from 'unified';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
+
import { FSWatcher } from 'chokidar';
|
|
6
7
|
|
|
7
8
|
interface ExtractedReference {
|
|
8
9
|
href: string;
|
|
9
10
|
}
|
|
10
11
|
interface PostprocessOptions {
|
|
12
|
+
_format: 'md' | 'mdx';
|
|
11
13
|
/**
|
|
12
14
|
* Properties to export from `vfile.data`
|
|
13
15
|
*/
|
|
@@ -16,6 +18,12 @@ interface PostprocessOptions {
|
|
|
16
18
|
* stringify MDAST and export via `_markdown`.
|
|
17
19
|
*/
|
|
18
20
|
includeProcessedMarkdown?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* store MDAST and export via `_mdast`.
|
|
23
|
+
*/
|
|
24
|
+
includeMDAST?: boolean | {
|
|
25
|
+
removePosition?: boolean;
|
|
26
|
+
};
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
|
|
@@ -36,6 +44,9 @@ type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | '
|
|
|
36
44
|
};
|
|
37
45
|
declare function getDefaultMDXOptions({ valueToExport, rehypeCodeOptions, remarkImageOptions, remarkHeadingOptions, remarkStructureOptions, remarkCodeTabOptions, remarkNpmOptions, _withoutBundler, ...mdxOptions }: DefaultMDXOptions): ProcessorOptions;
|
|
38
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Zod 4 schema
|
|
49
|
+
*/
|
|
39
50
|
declare const metaSchema: z.ZodObject<{
|
|
40
51
|
title: z.ZodOptional<z.ZodString>;
|
|
41
52
|
pages: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -44,6 +55,9 @@ declare const metaSchema: z.ZodObject<{
|
|
|
44
55
|
defaultOpen: z.ZodOptional<z.ZodBoolean>;
|
|
45
56
|
icon: z.ZodOptional<z.ZodString>;
|
|
46
57
|
}, z.core.$strip>;
|
|
58
|
+
/**
|
|
59
|
+
* Zod 4 schema
|
|
60
|
+
*/
|
|
47
61
|
declare const frontmatterSchema: z.ZodObject<{
|
|
48
62
|
title: z.ZodString;
|
|
49
63
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -75,7 +89,7 @@ interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> ext
|
|
|
75
89
|
}
|
|
76
90
|
interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection {
|
|
77
91
|
type: 'doc';
|
|
78
|
-
postprocess?: PostprocessOptions
|
|
92
|
+
postprocess?: Partial<PostprocessOptions>;
|
|
79
93
|
mdxOptions?: ProcessorOptions;
|
|
80
94
|
/**
|
|
81
95
|
* Load files with async
|
|
@@ -98,6 +112,7 @@ type GlobalConfigMDXOptions = ({
|
|
|
98
112
|
preset: 'minimal';
|
|
99
113
|
} & ProcessorOptions);
|
|
100
114
|
interface GlobalConfig {
|
|
115
|
+
plugins?: PluginOption[];
|
|
101
116
|
/**
|
|
102
117
|
* Configure global MDX options
|
|
103
118
|
*/
|
|
@@ -128,4 +143,76 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
|
|
|
128
143
|
}): DocsCollection<DocSchema, MetaSchema, Async>;
|
|
129
144
|
declare function defineConfig(config?: GlobalConfig): GlobalConfig;
|
|
130
145
|
|
|
131
|
-
|
|
146
|
+
interface ConfigLoader {
|
|
147
|
+
getConfig: () => LoadedConfig | Promise<LoadedConfig>;
|
|
148
|
+
}
|
|
149
|
+
interface LoadedConfig {
|
|
150
|
+
collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
|
|
151
|
+
global: GlobalConfig;
|
|
152
|
+
getDefaultMDXOptions(mode?: 'default' | 'remote'): Promise<ProcessorOptions>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type Awaitable<T> = T | Promise<T>;
|
|
156
|
+
interface EmitEntry {
|
|
157
|
+
/**
|
|
158
|
+
* path relative to output directory
|
|
159
|
+
*/
|
|
160
|
+
path: string;
|
|
161
|
+
content: string;
|
|
162
|
+
}
|
|
163
|
+
interface PluginContext extends CoreOptions {
|
|
164
|
+
core: Core;
|
|
165
|
+
}
|
|
166
|
+
interface Plugin {
|
|
167
|
+
name?: string;
|
|
168
|
+
/**
|
|
169
|
+
* on config loaded/updated
|
|
170
|
+
*/
|
|
171
|
+
config?: (this: PluginContext, config: LoadedConfig) => Awaitable<void | LoadedConfig>;
|
|
172
|
+
/**
|
|
173
|
+
* Generate files (e.g. types, index file, or JSON schemas)
|
|
174
|
+
*/
|
|
175
|
+
emit?: (this: PluginContext) => Awaitable<EmitEntry[]>;
|
|
176
|
+
/**
|
|
177
|
+
* Configure Fumadocs dev server
|
|
178
|
+
*/
|
|
179
|
+
configureServer?: (this: PluginContext, server: ServerContext) => Awaitable<void>;
|
|
180
|
+
}
|
|
181
|
+
type PluginOption = Awaitable<Plugin | Plugin[] | false>;
|
|
182
|
+
interface ServerContext {
|
|
183
|
+
/**
|
|
184
|
+
* the file watcher, by default all content files are watched, along with other files.
|
|
185
|
+
*
|
|
186
|
+
* make sure to filter when listening to events
|
|
187
|
+
*/
|
|
188
|
+
watcher?: FSWatcher;
|
|
189
|
+
}
|
|
190
|
+
interface CoreOptions {
|
|
191
|
+
environment: string;
|
|
192
|
+
configPath: string;
|
|
193
|
+
outDir: string;
|
|
194
|
+
}
|
|
195
|
+
interface EmitOptions {
|
|
196
|
+
/**
|
|
197
|
+
* filter the plugins to run emit
|
|
198
|
+
*/
|
|
199
|
+
filterPlugin?: (plugin: Plugin) => boolean;
|
|
200
|
+
}
|
|
201
|
+
declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[]): {
|
|
202
|
+
_options: CoreOptions;
|
|
203
|
+
getPluginContext(): PluginContext;
|
|
204
|
+
/**
|
|
205
|
+
* Convenient cache store, reset when config changes
|
|
206
|
+
*/
|
|
207
|
+
cache: Map<string, unknown>;
|
|
208
|
+
init({ config: newConfig }: {
|
|
209
|
+
config: Awaitable<LoadedConfig>;
|
|
210
|
+
}): Promise</*elided*/ any>;
|
|
211
|
+
getConfig(): LoadedConfig;
|
|
212
|
+
creatConfigLoader(): ConfigLoader;
|
|
213
|
+
initServer(server: ServerContext): Promise<void>;
|
|
214
|
+
emitAndWrite({ filterPlugin, }?: EmitOptions): Promise<void>;
|
|
215
|
+
};
|
|
216
|
+
type Core = ReturnType<typeof createCore>;
|
|
217
|
+
|
|
218
|
+
export { type AnyCollection as A, type BaseCollection as B, type CoreOptions as C, type DefaultMDXOptions as D, type ExtractedReference as E, type GlobalConfig as G, type LoadedConfig as L, type MetaCollection as M, type PostprocessOptions as P, type ServerContext as S, type CollectionSchema as a, type DocCollection as b, type DocsCollection as c, defineCollections as d, defineDocs as e, defineConfig as f, getDefaultMDXOptions as g, frontmatterSchema as h, type Plugin as i, type EmitEntry as j, type PluginContext as k, type PluginOption as l, metaSchema as m, type EmitOptions as n, createCore as o, type Core as p };
|
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
6
|
var __copyProps = (to, from, except, desc) => {
|
|
13
7
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
8
|
for (let key of __getOwnPropNames(from))
|
|
@@ -17,111 +11,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
11
|
}
|
|
18
12
|
return to;
|
|
19
13
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
15
|
|
|
30
16
|
// src/index.ts
|
|
31
17
|
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
_runtime: () => _runtime,
|
|
34
|
-
createMDXSource: () => createMDXSource,
|
|
35
|
-
resolveFiles: () => resolveFiles
|
|
36
|
-
});
|
|
37
18
|
module.exports = __toCommonJS(index_exports);
|
|
38
|
-
|
|
39
|
-
// src/runtime/next/index.ts
|
|
40
|
-
var fs = __toESM(require("fs/promises"), 1);
|
|
41
|
-
|
|
42
|
-
// src/runtime/shared.ts
|
|
43
|
-
function missingProcessedMarkdown() {
|
|
44
|
-
throw new Error(
|
|
45
|
-
"getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// src/runtime/next/index.ts
|
|
50
|
-
var _runtime = {
|
|
51
|
-
doc(files) {
|
|
52
|
-
return files.map((file) => {
|
|
53
|
-
const data = file.data;
|
|
54
|
-
const filePath = file.info.fullPath;
|
|
55
|
-
return {
|
|
56
|
-
info: file.info,
|
|
57
|
-
_exports: data,
|
|
58
|
-
body: data.default,
|
|
59
|
-
lastModified: data.lastModified,
|
|
60
|
-
toc: data.toc,
|
|
61
|
-
structuredData: data.structuredData,
|
|
62
|
-
extractedReferences: data.extractedReferences,
|
|
63
|
-
...data.frontmatter,
|
|
64
|
-
async getText(type) {
|
|
65
|
-
if (type === "raw") {
|
|
66
|
-
return (await fs.readFile(filePath)).toString();
|
|
67
|
-
}
|
|
68
|
-
if (typeof data._markdown !== "string") missingProcessedMarkdown();
|
|
69
|
-
return data._markdown;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
meta(files) {
|
|
75
|
-
return files.map((file) => {
|
|
76
|
-
return {
|
|
77
|
-
info: file.info,
|
|
78
|
-
...file.data
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
},
|
|
82
|
-
docs(docs, metas) {
|
|
83
|
-
const parsedDocs = this.doc(docs);
|
|
84
|
-
const parsedMetas = this.meta(metas);
|
|
85
|
-
return {
|
|
86
|
-
docs: parsedDocs,
|
|
87
|
-
meta: parsedMetas,
|
|
88
|
-
toFumadocsSource() {
|
|
89
|
-
return createMDXSource(parsedDocs, parsedMetas);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
function createMDXSource(docs, meta = []) {
|
|
95
|
-
return {
|
|
96
|
-
files: resolveFiles({
|
|
97
|
-
docs,
|
|
98
|
-
meta
|
|
99
|
-
})
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function resolveFiles({ docs, meta }) {
|
|
103
|
-
const outputs = [];
|
|
104
|
-
for (const entry of docs) {
|
|
105
|
-
outputs.push({
|
|
106
|
-
type: "page",
|
|
107
|
-
absolutePath: entry.info.fullPath,
|
|
108
|
-
path: entry.info.path,
|
|
109
|
-
data: entry
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
for (const entry of meta) {
|
|
113
|
-
outputs.push({
|
|
114
|
-
type: "meta",
|
|
115
|
-
absolutePath: entry.info.fullPath,
|
|
116
|
-
path: entry.info.path,
|
|
117
|
-
data: entry
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
return outputs;
|
|
121
|
-
}
|
|
122
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
-
0 && (module.exports = {
|
|
124
|
-
_runtime,
|
|
125
|
-
createMDXSource,
|
|
126
|
-
resolveFiles
|
|
127
|
-
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import '
|
|
7
|
-
import '
|
|
8
|
-
import 'mdx/types';
|
|
9
|
-
import 'fumadocs-core/source';
|
|
1
|
+
import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
2
|
+
import { TOCItemType } from 'fumadocs-core/toc';
|
|
3
|
+
import { MDXContent } from 'mdx/types';
|
|
4
|
+
import { E as ExtractedReference } from './core-B6j6Fxse.cjs';
|
|
5
|
+
export { p as Core, C as CoreOptions, j as EmitEntry, n as EmitOptions, i as Plugin, k as PluginContext, l as PluginOption, S as ServerContext, o as createCore } from './core-B6j6Fxse.cjs';
|
|
6
|
+
import { Root } from 'mdast';
|
|
7
|
+
import { C as CompiledMDXProperties } from './build-mdx-D-r3_eQL.cjs';
|
|
10
8
|
import '@standard-schema/spec';
|
|
11
9
|
import '@mdx-js/mdx';
|
|
12
10
|
import 'unified';
|
|
13
11
|
import 'zod';
|
|
12
|
+
import 'chokidar';
|
|
13
|
+
import 'react';
|
|
14
|
+
|
|
15
|
+
interface FileInfo {
|
|
16
|
+
/**
|
|
17
|
+
* virtualized path for Source API
|
|
18
|
+
*/
|
|
19
|
+
path: string;
|
|
20
|
+
/**
|
|
21
|
+
* the file path in file system
|
|
22
|
+
*/
|
|
23
|
+
fullPath: string;
|
|
24
|
+
}
|
|
25
|
+
interface DocData {
|
|
26
|
+
/**
|
|
27
|
+
* Compiled MDX content (as component)
|
|
28
|
+
*/
|
|
29
|
+
body: MDXContent;
|
|
30
|
+
/**
|
|
31
|
+
* table of contents generated from content.
|
|
32
|
+
*/
|
|
33
|
+
toc: TOCItemType[];
|
|
34
|
+
/**
|
|
35
|
+
* structured data for document search indexing.
|
|
36
|
+
*/
|
|
37
|
+
structuredData: StructuredData;
|
|
38
|
+
/**
|
|
39
|
+
* Raw exports from the compiled MDX file.
|
|
40
|
+
*/
|
|
41
|
+
_exports: Record<string, unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Last modified date of document file, obtained from version control.
|
|
44
|
+
*
|
|
45
|
+
* Only available when `lastModifiedTime` is enabled on global config.
|
|
46
|
+
*/
|
|
47
|
+
lastModified?: Date;
|
|
48
|
+
/**
|
|
49
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
50
|
+
*/
|
|
51
|
+
extractedReferences?: ExtractedReference[];
|
|
52
|
+
}
|
|
53
|
+
interface DocMethods {
|
|
54
|
+
/**
|
|
55
|
+
* file info
|
|
56
|
+
*/
|
|
57
|
+
info: FileInfo;
|
|
58
|
+
/**
|
|
59
|
+
* get document as text.
|
|
60
|
+
*
|
|
61
|
+
* - `type: raw` - read the original content from file system.
|
|
62
|
+
* - `type: processed` - get the processed Markdown content, only available when `includeProcessedMarkdown` is enabled on collection config.
|
|
63
|
+
*/
|
|
64
|
+
getText: (type: 'raw' | 'processed') => Promise<string>;
|
|
65
|
+
getMDAST: () => Promise<Root>;
|
|
66
|
+
}
|
|
67
|
+
type MetaCollectionEntry<Data> = Data & {
|
|
68
|
+
/**
|
|
69
|
+
* file info
|
|
70
|
+
*/
|
|
71
|
+
info: FileInfo;
|
|
72
|
+
};
|
|
73
|
+
type DocCollectionEntry<Frontmatter> = DocData & DocMethods & Frontmatter;
|
|
74
|
+
type AsyncDocCollectionEntry<Frontmatter> = DocMethods & {
|
|
75
|
+
load: () => Promise<DocData>;
|
|
76
|
+
} & Frontmatter;
|
|
77
|
+
declare function createDocMethods(info: FileInfo, load: () => Promise<CompiledMDXProperties<any>>): DocMethods;
|
|
78
|
+
|
|
79
|
+
export { type AsyncDocCollectionEntry, type DocCollectionEntry, type DocData, type DocMethods, ExtractedReference, type FileInfo, type MetaCollectionEntry, createDocMethods };
|