fumadocs-mdx 11.7.0 → 11.7.3
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/{chunk-2KBRPMAM.js → chunk-4CGSOZUZ.js} +3 -29
- package/dist/chunk-JFNBRKRV.js +47 -0
- package/dist/{chunk-JPPCALFT.js → chunk-OWZSTKKX.js} +25 -1
- package/dist/chunk-VUEZTR2H.js +26 -0
- package/dist/config/index.cjs +0 -2
- package/dist/config/index.d.cts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +0 -2
- package/dist/{define-CCrinVBZ.d.ts → define-E6TRBwBQ.d.cts} +1 -1
- package/dist/{define-CCrinVBZ.d.cts → define-E6TRBwBQ.d.ts} +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/loader-mdx.cjs +19 -25
- package/dist/loader-mdx.js +5 -3
- package/dist/next/index.cjs +86 -68
- package/dist/next/index.js +49 -39
- package/dist/runtime/async.cjs +18 -22
- package/dist/runtime/async.d.cts +3 -3
- package/dist/runtime/async.d.ts +3 -3
- package/dist/runtime/async.js +3 -3
- package/dist/runtime/vite.cjs +42 -7
- package/dist/runtime/vite.d.cts +37 -11
- package/dist/runtime/vite.d.ts +37 -11
- package/dist/runtime/vite.js +42 -8
- package/dist/{types-C0bKwtAx.d.ts → types-DiL328cG.d.ts} +2 -2
- package/dist/{types-CnslxmoO.d.cts → types-Lh_-Uuix.d.cts} +2 -2
- package/dist/vite/index.cjs +217 -184
- package/dist/vite/index.js +168 -164
- package/package.json +9 -8
- package/dist/chunk-GWR7KMRU.js +0 -51
package/dist/next/index.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
findConfigFile,
|
|
3
3
|
getConfigHash,
|
|
4
|
-
getGitTimestamp,
|
|
5
4
|
loadConfig
|
|
6
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-4CGSOZUZ.js";
|
|
7
6
|
import {
|
|
7
|
+
getGlobPatterns,
|
|
8
8
|
getImportCode,
|
|
9
|
+
isFileSupported,
|
|
9
10
|
toImportPath
|
|
10
|
-
} from "../chunk-
|
|
11
|
-
import
|
|
11
|
+
} from "../chunk-OWZSTKKX.js";
|
|
12
|
+
import {
|
|
13
|
+
getGitTimestamp
|
|
14
|
+
} from "../chunk-VUEZTR2H.js";
|
|
12
15
|
import {
|
|
13
16
|
ValidationError,
|
|
14
17
|
validate
|
|
15
18
|
} from "../chunk-ZOWJF3OH.js";
|
|
19
|
+
import "../chunk-JFNBRKRV.js";
|
|
16
20
|
import {
|
|
17
21
|
fumaMatter
|
|
18
22
|
} from "../chunk-KVWX6THC.js";
|
|
@@ -26,16 +30,6 @@ import * as path from "path";
|
|
|
26
30
|
import * as fs from "fs/promises";
|
|
27
31
|
import { glob } from "tinyglobby";
|
|
28
32
|
|
|
29
|
-
// src/utils/get-type-from-path.ts
|
|
30
|
-
import { extname } from "path";
|
|
31
|
-
var docTypes = [".mdx", ".md"];
|
|
32
|
-
var metaTypes = [".json", ".yaml"];
|
|
33
|
-
function getTypeFromPath(path4) {
|
|
34
|
-
const ext = extname(path4);
|
|
35
|
-
if (docTypes.includes(ext)) return "doc";
|
|
36
|
-
if (metaTypes.includes(ext)) return "meta";
|
|
37
|
-
}
|
|
38
|
-
|
|
39
33
|
// src/map/file-cache.ts
|
|
40
34
|
import { LRUCache } from "lru-cache";
|
|
41
35
|
var map = new LRUCache({
|
|
@@ -126,8 +120,7 @@ async function generateJS(configPath, config, importPath, configHash = false) {
|
|
|
126
120
|
specifier: "fumadocs-mdx/runtime/async",
|
|
127
121
|
names: ["_runtimeAsync", "buildConfig"]
|
|
128
122
|
}),
|
|
129
|
-
"const
|
|
130
|
-
"if (!_sourceConfig) throw new Error(err)"
|
|
123
|
+
"const _sourceConfig = buildConfig(_source)"
|
|
131
124
|
);
|
|
132
125
|
asyncInit = true;
|
|
133
126
|
}
|
|
@@ -189,14 +182,15 @@ async function generateJS(configPath, config, importPath, configHash = false) {
|
|
|
189
182
|
async function getCollectionFiles(collection) {
|
|
190
183
|
const files = /* @__PURE__ */ new Map();
|
|
191
184
|
const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
|
|
185
|
+
const patterns = getGlobPatterns(collection);
|
|
192
186
|
await Promise.all(
|
|
193
187
|
dirs.map(async (dir) => {
|
|
194
|
-
const result = await glob(
|
|
188
|
+
const result = await glob(patterns, {
|
|
195
189
|
cwd: path.resolve(dir),
|
|
196
190
|
absolute: true
|
|
197
191
|
});
|
|
198
192
|
for (const item of result) {
|
|
199
|
-
if (
|
|
193
|
+
if (!isFileSupported(item, collection)) continue;
|
|
200
194
|
files.set(item, {
|
|
201
195
|
path: path.relative(dir, item),
|
|
202
196
|
absolutePath: item
|
|
@@ -207,16 +201,16 @@ async function getCollectionFiles(collection) {
|
|
|
207
201
|
return Array.from(files.values());
|
|
208
202
|
}
|
|
209
203
|
function parseMetaEntry(file, content) {
|
|
210
|
-
const
|
|
204
|
+
const extname2 = path.extname(file);
|
|
211
205
|
try {
|
|
212
|
-
if (
|
|
213
|
-
if (
|
|
206
|
+
if (extname2 === ".json") return JSON.parse(content);
|
|
207
|
+
if (extname2 === ".yaml") return load(content);
|
|
214
208
|
} catch (e) {
|
|
215
209
|
throw new Error(`Failed to parse meta file: ${file}.`, {
|
|
216
210
|
cause: e
|
|
217
211
|
});
|
|
218
212
|
}
|
|
219
|
-
throw new Error(`Unknown meta file format: ${
|
|
213
|
+
throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
|
|
220
214
|
}
|
|
221
215
|
|
|
222
216
|
// src/map/index.ts
|
|
@@ -274,7 +268,16 @@ async function start(dev, configPath, outDir) {
|
|
|
274
268
|
}
|
|
275
269
|
|
|
276
270
|
// src/next/create.ts
|
|
271
|
+
import { readFileSync } from "fs";
|
|
277
272
|
var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
|
|
273
|
+
var isTurboExperimental;
|
|
274
|
+
try {
|
|
275
|
+
const content = readFileSync("./node_modules/next/package.json").toString();
|
|
276
|
+
const version = JSON.parse(content).version;
|
|
277
|
+
isTurboExperimental = version.startsWith("15.0.") || version.startsWith("15.1.") || version.startsWith("15.2.");
|
|
278
|
+
} catch {
|
|
279
|
+
isTurboExperimental = false;
|
|
280
|
+
}
|
|
278
281
|
function createMDX({
|
|
279
282
|
configPath = findConfigFile(),
|
|
280
283
|
outDir = ".source"
|
|
@@ -290,24 +293,25 @@ function createMDX({
|
|
|
290
293
|
configPath,
|
|
291
294
|
outDir
|
|
292
295
|
};
|
|
293
|
-
|
|
294
|
-
...nextConfig,
|
|
295
|
-
turbopack
|
|
296
|
-
|
|
297
|
-
rules
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
as: "*.js"
|
|
308
|
-
}
|
|
296
|
+
const turbo = {
|
|
297
|
+
...nextConfig.experimental?.turbo,
|
|
298
|
+
...nextConfig.turbopack,
|
|
299
|
+
rules: {
|
|
300
|
+
...nextConfig.experimental?.turbo?.rules,
|
|
301
|
+
...nextConfig.turbopack?.rules,
|
|
302
|
+
"*.{md,mdx}": {
|
|
303
|
+
loaders: [
|
|
304
|
+
{
|
|
305
|
+
loader: "fumadocs-mdx/loader-mdx",
|
|
306
|
+
options: mdxLoaderOptions
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
as: "*.js"
|
|
309
310
|
}
|
|
310
|
-
}
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const updated = {
|
|
314
|
+
...nextConfig,
|
|
311
315
|
pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
|
|
312
316
|
webpack: (config, options) => {
|
|
313
317
|
config.resolve ||= {};
|
|
@@ -327,6 +331,12 @@ function createMDX({
|
|
|
327
331
|
return nextConfig.webpack?.(config, options) ?? config;
|
|
328
332
|
}
|
|
329
333
|
};
|
|
334
|
+
if (isTurboExperimental) {
|
|
335
|
+
updated.experimental = { ...updated.experimental, turbo };
|
|
336
|
+
} else {
|
|
337
|
+
updated.turbopack = turbo;
|
|
338
|
+
}
|
|
339
|
+
return updated;
|
|
330
340
|
};
|
|
331
341
|
}
|
|
332
342
|
|
package/dist/runtime/async.cjs
CHANGED
|
@@ -338,7 +338,7 @@ function resolveFiles({ docs, meta }) {
|
|
|
338
338
|
// src/config/build.ts
|
|
339
339
|
function buildConfig(config) {
|
|
340
340
|
const collections = /* @__PURE__ */ new Map();
|
|
341
|
-
let globalConfig;
|
|
341
|
+
let globalConfig = {};
|
|
342
342
|
for (const [k, v] of Object.entries(config)) {
|
|
343
343
|
if (!v) {
|
|
344
344
|
continue;
|
|
@@ -353,34 +353,30 @@ function buildConfig(config) {
|
|
|
353
353
|
continue;
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
|
-
if (k === "default") {
|
|
356
|
+
if (k === "default" && v) {
|
|
357
357
|
globalConfig = v;
|
|
358
358
|
continue;
|
|
359
359
|
}
|
|
360
|
-
|
|
361
|
-
`Unknown export "${k}", you can only export collections from source configuration file
|
|
362
|
-
|
|
363
|
-
];
|
|
360
|
+
throw new Error(
|
|
361
|
+
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
362
|
+
);
|
|
364
363
|
}
|
|
365
364
|
let cachedMdxOptions;
|
|
366
|
-
return
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
if (options?.preset === "minimal") return options;
|
|
378
|
-
return getDefaultMDXOptions2(options ?? {});
|
|
379
|
-
}
|
|
380
|
-
return cachedMdxOptions = uncached();
|
|
365
|
+
return {
|
|
366
|
+
global: globalConfig,
|
|
367
|
+
collections,
|
|
368
|
+
async getDefaultMDXOptions() {
|
|
369
|
+
if (cachedMdxOptions) return cachedMdxOptions;
|
|
370
|
+
const input = this.global.mdxOptions;
|
|
371
|
+
async function uncached() {
|
|
372
|
+
const options = typeof input === "function" ? await input() : input;
|
|
373
|
+
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
|
|
374
|
+
if (options?.preset === "minimal") return options;
|
|
375
|
+
return getDefaultMDXOptions2(options ?? {});
|
|
381
376
|
}
|
|
377
|
+
return cachedMdxOptions = uncached();
|
|
382
378
|
}
|
|
383
|
-
|
|
379
|
+
};
|
|
384
380
|
}
|
|
385
381
|
|
|
386
382
|
// src/runtime/async.ts
|
package/dist/runtime/async.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LoadedConfig, a as RuntimeAsync } from '../types-
|
|
1
|
+
import { L as LoadedConfig, a as RuntimeAsync } from '../types-Lh_-Uuix.cjs';
|
|
2
2
|
import '@standard-schema/spec';
|
|
3
3
|
import 'fumadocs-core/source';
|
|
4
|
-
import '../define-
|
|
4
|
+
import '../define-E6TRBwBQ.cjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'fumadocs-core/mdx-plugins';
|
|
7
7
|
import '@mdx-js/mdx';
|
|
@@ -10,7 +10,7 @@ import 'react';
|
|
|
10
10
|
import 'mdx/types';
|
|
11
11
|
import 'fumadocs-core/server';
|
|
12
12
|
|
|
13
|
-
declare function buildConfig(config: Record<string, unknown>):
|
|
13
|
+
declare function buildConfig(config: Record<string, unknown>): LoadedConfig;
|
|
14
14
|
|
|
15
15
|
declare const _runtimeAsync: RuntimeAsync;
|
|
16
16
|
|
package/dist/runtime/async.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LoadedConfig, a as RuntimeAsync } from '../types-
|
|
1
|
+
import { L as LoadedConfig, a as RuntimeAsync } from '../types-DiL328cG.js';
|
|
2
2
|
import '@standard-schema/spec';
|
|
3
3
|
import 'fumadocs-core/source';
|
|
4
|
-
import '../define-
|
|
4
|
+
import '../define-E6TRBwBQ.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'fumadocs-core/mdx-plugins';
|
|
7
7
|
import '@mdx-js/mdx';
|
|
@@ -10,7 +10,7 @@ import 'react';
|
|
|
10
10
|
import 'mdx/types';
|
|
11
11
|
import 'fumadocs-core/server';
|
|
12
12
|
|
|
13
|
-
declare function buildConfig(config: Record<string, unknown>):
|
|
13
|
+
declare function buildConfig(config: Record<string, unknown>): LoadedConfig;
|
|
14
14
|
|
|
15
15
|
declare const _runtimeAsync: RuntimeAsync;
|
|
16
16
|
|
package/dist/runtime/async.js
CHANGED
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
_runtime,
|
|
3
3
|
createMDXSource
|
|
4
4
|
} from "../chunk-NUDEC6C5.js";
|
|
5
|
-
import {
|
|
6
|
-
buildConfig
|
|
7
|
-
} from "../chunk-GWR7KMRU.js";
|
|
8
5
|
import {
|
|
9
6
|
remarkInclude
|
|
10
7
|
} from "../chunk-AVMO2SRO.js";
|
|
8
|
+
import {
|
|
9
|
+
buildConfig
|
|
10
|
+
} from "../chunk-JFNBRKRV.js";
|
|
11
11
|
import "../chunk-KVWX6THC.js";
|
|
12
12
|
|
|
13
13
|
// src/runtime/async.ts
|
package/dist/runtime/vite.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/runtime/vite.ts
|
|
21
21
|
var vite_exports = {};
|
|
22
22
|
__export(vite_exports, {
|
|
23
|
+
createClientLoader: () => createClientLoader,
|
|
23
24
|
fromConfig: () => fromConfig,
|
|
24
25
|
toClientRenderer: () => toClientRenderer
|
|
25
26
|
});
|
|
@@ -35,12 +36,13 @@ function fromConfig() {
|
|
|
35
36
|
return out;
|
|
36
37
|
}
|
|
37
38
|
function mapPageData(entry) {
|
|
38
|
-
const { toc, structuredData } = entry;
|
|
39
|
+
const { toc, structuredData, lastModified, frontmatter } = entry;
|
|
39
40
|
return {
|
|
40
|
-
...
|
|
41
|
+
...frontmatter,
|
|
41
42
|
default: entry.default,
|
|
42
43
|
toc,
|
|
43
44
|
structuredData,
|
|
45
|
+
lastModified,
|
|
44
46
|
_exports: entry
|
|
45
47
|
};
|
|
46
48
|
}
|
|
@@ -99,18 +101,51 @@ function fromConfig() {
|
|
|
99
101
|
}
|
|
100
102
|
};
|
|
101
103
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
+
var loaderStore = /* @__PURE__ */ new Map();
|
|
105
|
+
function createClientLoader(files, options) {
|
|
106
|
+
const { id = "", component } = options;
|
|
107
|
+
const store = loaderStore.get(id) ?? {
|
|
108
|
+
preloaded: /* @__PURE__ */ new Map()
|
|
109
|
+
};
|
|
110
|
+
loaderStore.set(id, store);
|
|
111
|
+
let renderer;
|
|
112
|
+
return {
|
|
113
|
+
async preload(path) {
|
|
114
|
+
const loaded = await files[path]();
|
|
115
|
+
store.preloaded.set(path, loaded);
|
|
116
|
+
return loaded;
|
|
117
|
+
},
|
|
118
|
+
getComponent(path) {
|
|
119
|
+
renderer ??= toClientRenderer(files, component, {
|
|
120
|
+
cache: store.preloaded
|
|
121
|
+
});
|
|
122
|
+
return renderer[path];
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function toClientRenderer(files, component, options = {}) {
|
|
127
|
+
const { cache } = options;
|
|
128
|
+
const renderer = {};
|
|
104
129
|
for (const k in files) {
|
|
105
|
-
|
|
130
|
+
const OnDemand = (0, import_react.lazy)(async () => {
|
|
106
131
|
const loaded = await files[k]();
|
|
107
|
-
return { default: (props) =>
|
|
132
|
+
return { default: (props) => component(loaded, props) };
|
|
108
133
|
});
|
|
134
|
+
if (cache) {
|
|
135
|
+
renderer[k] = (props) => {
|
|
136
|
+
const cached = cache.get(k);
|
|
137
|
+
if (!cached) return (0, import_react.createElement)(OnDemand, props);
|
|
138
|
+
return component(cached, props);
|
|
139
|
+
};
|
|
140
|
+
} else {
|
|
141
|
+
renderer[k] = OnDemand;
|
|
142
|
+
}
|
|
109
143
|
}
|
|
110
|
-
return
|
|
144
|
+
return renderer;
|
|
111
145
|
}
|
|
112
146
|
// Annotate the CommonJS export names for ESM import in node:
|
|
113
147
|
0 && (module.exports = {
|
|
148
|
+
createClientLoader,
|
|
114
149
|
fromConfig,
|
|
115
150
|
toClientRenderer
|
|
116
151
|
});
|
package/dist/runtime/vite.d.cts
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { TableOfContents } from 'fumadocs-core/server';
|
|
2
|
-
import { FC, ReactNode
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
3
|
import { MDXProps } from 'mdx/types';
|
|
4
4
|
import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
5
|
-
import {
|
|
5
|
+
import { a as DocCollection, M as MetaCollection, b as DocsCollection } from '../define-E6TRBwBQ.cjs';
|
|
6
6
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
7
7
|
import { PageData, MetaData, Source } from 'fumadocs-core/source';
|
|
8
8
|
import 'zod';
|
|
9
9
|
import '@mdx-js/mdx';
|
|
10
10
|
import 'unified';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
interface CompiledMDXProperties<Frontmatter> {
|
|
13
13
|
frontmatter: Frontmatter;
|
|
14
|
-
toc: TableOfContents;
|
|
15
|
-
default: FC<MDXProps>;
|
|
16
14
|
structuredData: StructuredData;
|
|
17
|
-
} & Record<string, unknown>;
|
|
18
|
-
type MDXFileToPageData<Frontmatter> = Frontmatter & {
|
|
19
15
|
toc: TableOfContents;
|
|
20
16
|
default: FC<MDXProps>;
|
|
21
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Only available when `lastModifiedTime` is enabled on MDX loader
|
|
19
|
+
*/
|
|
20
|
+
lastModified?: Date;
|
|
21
|
+
}
|
|
22
|
+
type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
|
|
23
|
+
type MDXFileToPageData<Frontmatter> = Frontmatter & Omit<CompiledMDXProperties<Frontmatter>, 'frontmatter'> & {
|
|
22
24
|
_exports: Record<string, unknown>;
|
|
23
25
|
};
|
|
24
26
|
type AttachGlobValue<GlobValue, Attach> = GlobValue extends () => Promise<unknown> ? () => Promise<Attach> : Attach;
|
|
@@ -41,7 +43,31 @@ declare function fromConfig<Config>(): {
|
|
|
41
43
|
metaData: MetaOut;
|
|
42
44
|
}>>;
|
|
43
45
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
interface ClientLoaderOptions<Frontmatter, Props> {
|
|
47
|
+
/**
|
|
48
|
+
* Loader ID (usually your collection name)
|
|
49
|
+
*
|
|
50
|
+
* The code splitting strategy of frameworks like Tanstack Start may duplicate `createClientLoader()` into different chunks.
|
|
51
|
+
*
|
|
52
|
+
* We use loader ID to share cache between multiple instances of client loader.
|
|
53
|
+
*
|
|
54
|
+
* @defaultValue ''
|
|
55
|
+
*/
|
|
56
|
+
id?: string;
|
|
57
|
+
component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode;
|
|
58
|
+
}
|
|
59
|
+
interface ClientLoader<Frontmatter, Props> {
|
|
60
|
+
preload: (path: string) => Promise<CompiledMDXFile<Frontmatter>>;
|
|
61
|
+
/**
|
|
62
|
+
* Get a component that renders content with `React.lazy`
|
|
63
|
+
*/
|
|
64
|
+
getComponent: (path: string) => FC<Props>;
|
|
65
|
+
}
|
|
66
|
+
declare function createClientLoader<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, options: ClientLoaderOptions<Frontmatter, Props>): ClientLoader<Frontmatter, Props>;
|
|
67
|
+
interface ClientRendererOptions<Frontmatter> {
|
|
68
|
+
cache?: Map<string, CompiledMDXFile<Frontmatter>>;
|
|
69
|
+
}
|
|
70
|
+
type ClientRenderer<Props> = Record<string, FC<Props>>;
|
|
71
|
+
declare function toClientRenderer<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode, options?: ClientRendererOptions<Frontmatter>): ClientRenderer<Props>;
|
|
46
72
|
|
|
47
|
-
export { type CompiledMDXFile, fromConfig, toClientRenderer };
|
|
73
|
+
export { type ClientLoader, type ClientLoaderOptions, type ClientRendererOptions, type CompiledMDXFile, createClientLoader, fromConfig, toClientRenderer };
|
package/dist/runtime/vite.d.ts
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { TableOfContents } from 'fumadocs-core/server';
|
|
2
|
-
import { FC, ReactNode
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
3
|
import { MDXProps } from 'mdx/types';
|
|
4
4
|
import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
5
|
-
import {
|
|
5
|
+
import { a as DocCollection, M as MetaCollection, b as DocsCollection } from '../define-E6TRBwBQ.js';
|
|
6
6
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
7
7
|
import { PageData, MetaData, Source } from 'fumadocs-core/source';
|
|
8
8
|
import 'zod';
|
|
9
9
|
import '@mdx-js/mdx';
|
|
10
10
|
import 'unified';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
interface CompiledMDXProperties<Frontmatter> {
|
|
13
13
|
frontmatter: Frontmatter;
|
|
14
|
-
toc: TableOfContents;
|
|
15
|
-
default: FC<MDXProps>;
|
|
16
14
|
structuredData: StructuredData;
|
|
17
|
-
} & Record<string, unknown>;
|
|
18
|
-
type MDXFileToPageData<Frontmatter> = Frontmatter & {
|
|
19
15
|
toc: TableOfContents;
|
|
20
16
|
default: FC<MDXProps>;
|
|
21
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Only available when `lastModifiedTime` is enabled on MDX loader
|
|
19
|
+
*/
|
|
20
|
+
lastModified?: Date;
|
|
21
|
+
}
|
|
22
|
+
type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
|
|
23
|
+
type MDXFileToPageData<Frontmatter> = Frontmatter & Omit<CompiledMDXProperties<Frontmatter>, 'frontmatter'> & {
|
|
22
24
|
_exports: Record<string, unknown>;
|
|
23
25
|
};
|
|
24
26
|
type AttachGlobValue<GlobValue, Attach> = GlobValue extends () => Promise<unknown> ? () => Promise<Attach> : Attach;
|
|
@@ -41,7 +43,31 @@ declare function fromConfig<Config>(): {
|
|
|
41
43
|
metaData: MetaOut;
|
|
42
44
|
}>>;
|
|
43
45
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
interface ClientLoaderOptions<Frontmatter, Props> {
|
|
47
|
+
/**
|
|
48
|
+
* Loader ID (usually your collection name)
|
|
49
|
+
*
|
|
50
|
+
* The code splitting strategy of frameworks like Tanstack Start may duplicate `createClientLoader()` into different chunks.
|
|
51
|
+
*
|
|
52
|
+
* We use loader ID to share cache between multiple instances of client loader.
|
|
53
|
+
*
|
|
54
|
+
* @defaultValue ''
|
|
55
|
+
*/
|
|
56
|
+
id?: string;
|
|
57
|
+
component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode;
|
|
58
|
+
}
|
|
59
|
+
interface ClientLoader<Frontmatter, Props> {
|
|
60
|
+
preload: (path: string) => Promise<CompiledMDXFile<Frontmatter>>;
|
|
61
|
+
/**
|
|
62
|
+
* Get a component that renders content with `React.lazy`
|
|
63
|
+
*/
|
|
64
|
+
getComponent: (path: string) => FC<Props>;
|
|
65
|
+
}
|
|
66
|
+
declare function createClientLoader<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, options: ClientLoaderOptions<Frontmatter, Props>): ClientLoader<Frontmatter, Props>;
|
|
67
|
+
interface ClientRendererOptions<Frontmatter> {
|
|
68
|
+
cache?: Map<string, CompiledMDXFile<Frontmatter>>;
|
|
69
|
+
}
|
|
70
|
+
type ClientRenderer<Props> = Record<string, FC<Props>>;
|
|
71
|
+
declare function toClientRenderer<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode, options?: ClientRendererOptions<Frontmatter>): ClientRenderer<Props>;
|
|
46
72
|
|
|
47
|
-
export { type CompiledMDXFile, fromConfig, toClientRenderer };
|
|
73
|
+
export { type ClientLoader, type ClientLoaderOptions, type ClientRendererOptions, type CompiledMDXFile, createClientLoader, fromConfig, toClientRenderer };
|
package/dist/runtime/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/runtime/vite.ts
|
|
2
|
-
import { lazy } from "react";
|
|
2
|
+
import { createElement, lazy } from "react";
|
|
3
3
|
function fromConfig() {
|
|
4
4
|
function normalize(entries) {
|
|
5
5
|
const out = {};
|
|
@@ -10,12 +10,13 @@ function fromConfig() {
|
|
|
10
10
|
return out;
|
|
11
11
|
}
|
|
12
12
|
function mapPageData(entry) {
|
|
13
|
-
const { toc, structuredData } = entry;
|
|
13
|
+
const { toc, structuredData, lastModified, frontmatter } = entry;
|
|
14
14
|
return {
|
|
15
|
-
...
|
|
15
|
+
...frontmatter,
|
|
16
16
|
default: entry.default,
|
|
17
17
|
toc,
|
|
18
18
|
structuredData,
|
|
19
|
+
lastModified,
|
|
19
20
|
_exports: entry
|
|
20
21
|
};
|
|
21
22
|
}
|
|
@@ -74,17 +75,50 @@ function fromConfig() {
|
|
|
74
75
|
}
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
var loaderStore = /* @__PURE__ */ new Map();
|
|
79
|
+
function createClientLoader(files, options) {
|
|
80
|
+
const { id = "", component } = options;
|
|
81
|
+
const store = loaderStore.get(id) ?? {
|
|
82
|
+
preloaded: /* @__PURE__ */ new Map()
|
|
83
|
+
};
|
|
84
|
+
loaderStore.set(id, store);
|
|
85
|
+
let renderer;
|
|
86
|
+
return {
|
|
87
|
+
async preload(path) {
|
|
88
|
+
const loaded = await files[path]();
|
|
89
|
+
store.preloaded.set(path, loaded);
|
|
90
|
+
return loaded;
|
|
91
|
+
},
|
|
92
|
+
getComponent(path) {
|
|
93
|
+
renderer ??= toClientRenderer(files, component, {
|
|
94
|
+
cache: store.preloaded
|
|
95
|
+
});
|
|
96
|
+
return renderer[path];
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function toClientRenderer(files, component, options = {}) {
|
|
101
|
+
const { cache } = options;
|
|
102
|
+
const renderer = {};
|
|
79
103
|
for (const k in files) {
|
|
80
|
-
|
|
104
|
+
const OnDemand = lazy(async () => {
|
|
81
105
|
const loaded = await files[k]();
|
|
82
|
-
return { default: (props) =>
|
|
106
|
+
return { default: (props) => component(loaded, props) };
|
|
83
107
|
});
|
|
108
|
+
if (cache) {
|
|
109
|
+
renderer[k] = (props) => {
|
|
110
|
+
const cached = cache.get(k);
|
|
111
|
+
if (!cached) return createElement(OnDemand, props);
|
|
112
|
+
return component(cached, props);
|
|
113
|
+
};
|
|
114
|
+
} else {
|
|
115
|
+
renderer[k] = OnDemand;
|
|
116
|
+
}
|
|
84
117
|
}
|
|
85
|
-
return
|
|
118
|
+
return renderer;
|
|
86
119
|
}
|
|
87
120
|
export {
|
|
121
|
+
createClientLoader,
|
|
88
122
|
fromConfig,
|
|
89
123
|
toClientRenderer
|
|
90
124
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import { Source, PageData, MetaData } from 'fumadocs-core/source';
|
|
3
|
-
import {
|
|
3
|
+
import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define-E6TRBwBQ.js';
|
|
4
4
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
5
5
|
import { FC } from 'react';
|
|
6
6
|
import { MDXProps } from 'mdx/types';
|
|
@@ -9,7 +9,7 @@ import { TableOfContents } from 'fumadocs-core/server';
|
|
|
9
9
|
|
|
10
10
|
interface LoadedConfig {
|
|
11
11
|
collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
|
|
12
|
-
global
|
|
12
|
+
global: GlobalConfig;
|
|
13
13
|
getDefaultMDXOptions(): Promise<ProcessorOptions>;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import { Source, PageData, MetaData } from 'fumadocs-core/source';
|
|
3
|
-
import {
|
|
3
|
+
import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define-E6TRBwBQ.cjs';
|
|
4
4
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
5
5
|
import { FC } from 'react';
|
|
6
6
|
import { MDXProps } from 'mdx/types';
|
|
@@ -9,7 +9,7 @@ import { TableOfContents } from 'fumadocs-core/server';
|
|
|
9
9
|
|
|
10
10
|
interface LoadedConfig {
|
|
11
11
|
collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
|
|
12
|
-
global
|
|
12
|
+
global: GlobalConfig;
|
|
13
13
|
getDefaultMDXOptions(): Promise<ProcessorOptions>;
|
|
14
14
|
}
|
|
15
15
|
|