fumadocs-mdx 13.0.7 → 14.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.
Files changed (104) hide show
  1. package/dist/bin.cjs +927 -904
  2. package/dist/bin.js +3 -3
  3. package/dist/build-mdx-6UAK5FF5.js +8 -0
  4. package/dist/bun/index.cjs +592 -481
  5. package/dist/bun/index.d.cts +3 -2
  6. package/dist/bun/index.d.ts +3 -2
  7. package/dist/bun/index.js +12 -12
  8. package/dist/chunk-4JSFLXXT.js +8 -0
  9. package/dist/chunk-5UMZCWKV.js +17 -0
  10. package/dist/chunk-5YXP7JLN.js +138 -0
  11. package/dist/{chunk-2E2JCOSO.js → chunk-6NISOLQ6.js} +16 -44
  12. package/dist/chunk-7L2KNF6B.js +180 -0
  13. package/dist/chunk-E5DJTSIM.js +86 -0
  14. package/dist/{chunk-K5ZLPEIQ.js → chunk-FBLMK4RS.js} +9 -6
  15. package/dist/{chunk-QXHN25N3.js → chunk-OXSRIWQW.js} +7 -8
  16. package/dist/chunk-PKI7ZDA5.js +29 -0
  17. package/dist/{chunk-3J3WL7WN.js → chunk-SLY7WXTX.js} +71 -58
  18. package/dist/{chunk-ETIN2W7C.js → chunk-SRSRFOVI.js} +22 -19
  19. package/dist/chunk-TYJDYTKH.js +85 -0
  20. package/dist/chunk-XHJCLBZ4.js +406 -0
  21. package/dist/{chunk-2HXTGJBI.js → chunk-ZY6UZ7NH.js} +22 -19
  22. package/dist/config/index.cjs +79 -71
  23. package/dist/config/index.d.cts +2 -1
  24. package/dist/config/index.d.ts +2 -1
  25. package/dist/config/index.js +5 -5
  26. package/dist/index-BlVBvy-z.d.ts +8 -0
  27. package/dist/{core-HkAVGq_a.d.cts → index-D7JdSMpp.d.cts} +99 -61
  28. package/dist/{core-HkAVGq_a.d.ts → index-D7JdSMpp.d.ts} +99 -61
  29. package/dist/index-P2NNUkHn.d.cts +8 -0
  30. package/dist/index.d.cts +3 -74
  31. package/dist/index.d.ts +3 -74
  32. package/dist/load-from-file-I3ALLIVB.js +8 -0
  33. package/dist/next/index.cjs +698 -476
  34. package/dist/next/index.d.cts +11 -1
  35. package/dist/next/index.d.ts +11 -1
  36. package/dist/next/index.js +78 -281
  37. package/dist/node/loader.cjs +705 -603
  38. package/dist/node/loader.js +10 -11
  39. package/dist/plugins/index-file.cjs +471 -0
  40. package/dist/plugins/index-file.d.cts +29 -0
  41. package/dist/plugins/index-file.d.ts +29 -0
  42. package/dist/plugins/index-file.js +8 -0
  43. package/dist/plugins/json-schema.d.cts +3 -2
  44. package/dist/plugins/json-schema.d.ts +3 -2
  45. package/dist/plugins/last-modified.cjs +75 -0
  46. package/dist/plugins/last-modified.d.cts +27 -0
  47. package/dist/plugins/last-modified.d.ts +27 -0
  48. package/dist/plugins/last-modified.js +44 -0
  49. package/dist/runtime/{vite/browser.cjs → browser.cjs} +40 -53
  50. package/dist/runtime/browser.d.cts +50 -0
  51. package/dist/runtime/browser.d.ts +50 -0
  52. package/dist/runtime/browser.js +68 -0
  53. package/dist/runtime/dynamic.cjs +985 -0
  54. package/dist/runtime/dynamic.d.cts +27 -0
  55. package/dist/runtime/dynamic.d.ts +27 -0
  56. package/dist/runtime/dynamic.js +78 -0
  57. package/dist/runtime/server.cjs +173 -0
  58. package/dist/runtime/server.d.cts +161 -0
  59. package/dist/runtime/server.d.ts +161 -0
  60. package/dist/runtime/server.js +8 -0
  61. package/dist/vite/index.cjs +935 -639
  62. package/dist/vite/index.d.cts +12 -22
  63. package/dist/vite/index.d.ts +12 -22
  64. package/dist/vite/index.js +30 -221
  65. package/dist/webpack/mdx.cjs +614 -515
  66. package/dist/webpack/mdx.d.cts +9 -1
  67. package/dist/webpack/mdx.d.ts +9 -1
  68. package/dist/webpack/mdx.js +12 -17
  69. package/dist/webpack/meta.cjs +328 -234
  70. package/dist/webpack/meta.d.cts +9 -1
  71. package/dist/webpack/meta.d.ts +9 -1
  72. package/dist/webpack/meta.js +13 -15
  73. package/package.json +15 -32
  74. package/dist/build-mdx-BnJhW5O1.d.cts +0 -53
  75. package/dist/build-mdx-DNzfRRlY.d.ts +0 -53
  76. package/dist/chunk-2AQRQXSO.js +0 -119
  77. package/dist/chunk-4757L6ST.js +0 -77
  78. package/dist/chunk-CXA4JO4Z.js +0 -45
  79. package/dist/chunk-FSZMKRVH.js +0 -80
  80. package/dist/chunk-II3H5ZVZ.js +0 -77
  81. package/dist/chunk-KILFIBVW.js +0 -75
  82. package/dist/chunk-NVRDCY6Z.js +0 -30
  83. package/dist/chunk-VUEZTR2H.js +0 -26
  84. package/dist/index-D7s7kCc2.d.cts +0 -7
  85. package/dist/index-D7s7kCc2.d.ts +0 -7
  86. package/dist/load-from-file-AVYOFOI7.js +0 -7
  87. package/dist/preset-ZMP6U62C.js +0 -6
  88. package/dist/runtime/next/async.cjs +0 -760
  89. package/dist/runtime/next/async.d.cts +0 -19
  90. package/dist/runtime/next/async.d.ts +0 -19
  91. package/dist/runtime/next/async.js +0 -86
  92. package/dist/runtime/next/index.cjs +0 -136
  93. package/dist/runtime/next/index.d.cts +0 -33
  94. package/dist/runtime/next/index.d.ts +0 -33
  95. package/dist/runtime/next/index.js +0 -11
  96. package/dist/runtime/vite/browser.d.cts +0 -59
  97. package/dist/runtime/vite/browser.d.ts +0 -59
  98. package/dist/runtime/vite/browser.js +0 -11
  99. package/dist/runtime/vite/server.cjs +0 -243
  100. package/dist/runtime/vite/server.d.cts +0 -30
  101. package/dist/runtime/vite/server.d.ts +0 -30
  102. package/dist/runtime/vite/server.js +0 -111
  103. package/dist/types-By6wKOnT.d.cts +0 -45
  104. package/dist/types-DgD5Omj2.d.ts +0 -45
@@ -0,0 +1,27 @@
1
+ import { j as Plugin } from '../index-D7JdSMpp.cjs';
2
+ import '@mdx-js/mdx';
3
+ import '@standard-schema/spec';
4
+ import 'unified';
5
+ import 'fumadocs-core/mdx-plugins';
6
+ import 'zod';
7
+ import 'chokidar';
8
+ import 'vfile';
9
+
10
+ interface LastModifiedPluginOptions {
11
+ /**
12
+ * Version control to obtain the last modified time.
13
+ *
14
+ * - `git`: Requires `git` to be installed.
15
+ *
16
+ * If you are using Vercel, please set `VERCEL_DEEP_CLONE` environment variable to `true`.
17
+ *
18
+ * @defaultValue 'git'
19
+ */
20
+ versionControl?: 'git';
21
+ }
22
+ /**
23
+ * Injects `lastModified` property to page exports.
24
+ */
25
+ declare function lastModified(options?: LastModifiedPluginOptions): Plugin;
26
+
27
+ export { type LastModifiedPluginOptions, lastModified as default };
@@ -0,0 +1,27 @@
1
+ import { j as Plugin } from '../index-D7JdSMpp.js';
2
+ import '@mdx-js/mdx';
3
+ import '@standard-schema/spec';
4
+ import 'unified';
5
+ import 'fumadocs-core/mdx-plugins';
6
+ import 'zod';
7
+ import 'chokidar';
8
+ import 'vfile';
9
+
10
+ interface LastModifiedPluginOptions {
11
+ /**
12
+ * Version control to obtain the last modified time.
13
+ *
14
+ * - `git`: Requires `git` to be installed.
15
+ *
16
+ * If you are using Vercel, please set `VERCEL_DEEP_CLONE` environment variable to `true`.
17
+ *
18
+ * @defaultValue 'git'
19
+ */
20
+ versionControl?: 'git';
21
+ }
22
+ /**
23
+ * Injects `lastModified` property to page exports.
24
+ */
25
+ declare function lastModified(options?: LastModifiedPluginOptions): Plugin;
26
+
27
+ export { type LastModifiedPluginOptions, lastModified as default };
@@ -0,0 +1,44 @@
1
+ // src/plugins/last-modified.ts
2
+ import path from "path";
3
+ import { x } from "tinyexec";
4
+ var cache = /* @__PURE__ */ new Map();
5
+ function lastModified(options = {}) {
6
+ const { versionControl = "git" } = options;
7
+ return {
8
+ name: "last-modified",
9
+ doc: {
10
+ async vfile(file) {
11
+ if (versionControl === "git") {
12
+ const timestamp = await getGitTimestamp(this.filePath).then(
13
+ (v) => v?.getTime()
14
+ );
15
+ if (timestamp === void 0) return;
16
+ file.data["mdx-export"] ??= [];
17
+ file.data["mdx-export"].push({
18
+ name: "lastModified",
19
+ value: timestamp
20
+ });
21
+ }
22
+ }
23
+ }
24
+ };
25
+ }
26
+ async function getGitTimestamp(file) {
27
+ const cached = cache.get(file);
28
+ if (cached) return cached;
29
+ const timePromise = (async () => {
30
+ const out = await x(
31
+ "git",
32
+ ["log", "-1", '--pretty="%ai"', path.relative(process.cwd(), file)],
33
+ {
34
+ throwOnError: true
35
+ }
36
+ );
37
+ return new Date(out.stdout);
38
+ })();
39
+ cache.set(file, timePromise);
40
+ return timePromise.catch(() => void 0);
41
+ }
42
+ export {
43
+ lastModified as default
44
+ };
@@ -17,77 +17,69 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/runtime/vite/browser.ts
20
+ // src/runtime/browser.ts
21
21
  var browser_exports = {};
22
22
  __export(browser_exports, {
23
23
  createClientLoader: () => createClientLoader,
24
- fromConfig: () => fromConfigBase,
25
- fromConfigBase: () => fromConfigBase,
26
- toClientRenderer: () => toClientRenderer
24
+ fromConfig: () => fromConfig
27
25
  });
28
26
  module.exports = __toCommonJS(browser_exports);
29
-
30
- // src/runtime/vite/base.ts
31
27
  var import_react = require("react");
32
- function fromConfigBase() {
33
- function normalize(entries, base) {
34
- const out = {};
35
- for (const k in entries) {
36
- const mappedK = k.startsWith("./") ? k.slice(2) : k;
37
- if (base) Object.assign(entries[k], { base });
38
- out[mappedK] = entries[k];
39
- }
40
- return out;
41
- }
28
+ function fromConfig() {
42
29
  return {
43
- doc(_, base, glob) {
44
- return normalize(glob, base);
45
- },
46
- meta(_, base, glob) {
47
- return normalize(glob, base);
48
- },
49
- docLazy(_, base, head, body) {
50
- return {
51
- base,
52
- head: normalize(head),
53
- body: normalize(body)
30
+ doc(_name, glob) {
31
+ const raw = glob;
32
+ const out = {
33
+ raw,
34
+ createClientLoader({ id = _name, ...options }) {
35
+ return createClientLoader(raw, { id, ...options });
36
+ }
54
37
  };
38
+ return out;
55
39
  }
56
40
  };
57
41
  }
58
42
  var loaderStore = /* @__PURE__ */ new Map();
59
- function createClientLoader(files, options) {
43
+ function createClientLoader(globEntries, options) {
60
44
  const { id = "", component } = options;
61
- let renderer;
45
+ const renderers = {};
46
+ const loaders = /* @__PURE__ */ new Map();
62
47
  const store = loaderStore.get(id) ?? {
63
48
  preloaded: /* @__PURE__ */ new Map()
64
49
  };
65
50
  loaderStore.set(id, store);
66
- function getRenderer() {
67
- if (renderer) return renderer;
68
- renderer = {};
69
- for (const k in files) {
70
- const OnDemand = (0, import_react.lazy)(async () => {
71
- const loaded = await files[k]();
72
- return { default: (props) => component(loaded, props) };
73
- });
74
- renderer[k] = (props) => {
75
- const cached = store.preloaded.get(k);
76
- if (!cached) return (0, import_react.createElement)(OnDemand, props);
77
- return component(cached, props);
78
- };
79
- }
80
- return renderer;
51
+ for (const k in globEntries) {
52
+ loaders.set(k.startsWith("./") ? k.slice(2) : k, globEntries[k]);
53
+ }
54
+ function getLoader(path) {
55
+ const loader = loaders.get(path);
56
+ if (!loader)
57
+ throw new Error(
58
+ `[createClientLoader] ${path} does not exist in available entries`
59
+ );
60
+ return loader;
61
+ }
62
+ function getRenderer(path) {
63
+ if (path in renderers) return renderers[path];
64
+ const OnDemand = (0, import_react.lazy)(async () => {
65
+ const loaded = await getLoader(path)();
66
+ return { default: (props) => component(loaded, props) };
67
+ });
68
+ renderers[path] = (props) => {
69
+ const cached = store.preloaded.get(path);
70
+ if (!cached) return (0, import_react.createElement)(OnDemand, props);
71
+ return component(cached, props);
72
+ };
73
+ return renderers[path];
81
74
  }
82
75
  return {
83
76
  async preload(path) {
84
- const loaded = await files[path]();
77
+ const loaded = await getLoader(path)();
85
78
  store.preloaded.set(path, loaded);
86
79
  return loaded;
87
80
  },
88
- getRenderer,
89
81
  getComponent(path) {
90
- return getRenderer()[path];
82
+ return getRenderer(path);
91
83
  },
92
84
  useContent(path, props) {
93
85
  const Comp = this.getComponent(path);
@@ -95,13 +87,8 @@ function createClientLoader(files, options) {
95
87
  }
96
88
  };
97
89
  }
98
- function toClientRenderer(files, component) {
99
- return createClientLoader(files, { component }).getRenderer();
100
- }
101
90
  // Annotate the CommonJS export names for ESM import in node:
102
91
  0 && (module.exports = {
103
92
  createClientLoader,
104
- fromConfig,
105
- fromConfigBase,
106
- toClientRenderer
93
+ fromConfig
107
94
  });
@@ -0,0 +1,50 @@
1
+ import { ReactNode, FC } from 'react';
2
+ import { CompiledMDXFile } from './server.cjs';
3
+ import { StandardSchemaV1 } from '@standard-schema/spec';
4
+ import { D as DocCollection, b as DocsCollection } from '../index-D7JdSMpp.cjs';
5
+ import 'fumadocs-core/source';
6
+ import 'fumadocs-core/mdx-plugins';
7
+ import 'fumadocs-core/toc';
8
+ import 'mdx/types';
9
+ import 'mdast';
10
+ import '@mdx-js/mdx';
11
+ import 'unified';
12
+ import 'zod';
13
+ import 'chokidar';
14
+ import 'vfile';
15
+
16
+ interface ClientLoaderOptions<Frontmatter, Props> {
17
+ /**
18
+ * Loader ID (usually your collection name)
19
+ *
20
+ * The code splitting strategy of frameworks like Tanstack Start may duplicate `createClientLoader()` into different chunks.
21
+ *
22
+ * We use loader ID to share cache between multiple instances of client loader.
23
+ *
24
+ * @defaultValue ''
25
+ */
26
+ id?: string;
27
+ component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode;
28
+ }
29
+ interface ClientLoader<Frontmatter, Props> {
30
+ preload: (path: string) => Promise<CompiledMDXFile<Frontmatter>>;
31
+ /**
32
+ * Get a component that renders content with `React.lazy`.
33
+ */
34
+ getComponent: (path: string) => FC<Props>;
35
+ /**
36
+ * Get react nodes that renders content with `React.lazy`.
37
+ */
38
+ useContent: (path: string, props: Props) => ReactNode;
39
+ }
40
+ type BrowserCreate<Config> = ReturnType<typeof fromConfig<Config>>;
41
+ interface DocCollectionEntry<Frontmatter> {
42
+ raw: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>;
43
+ createClientLoader: <Props extends object>(options: ClientLoaderOptions<Frontmatter, Props>) => ClientLoader<Frontmatter, Props>;
44
+ }
45
+ declare function fromConfig<Config>(): {
46
+ doc<Name extends keyof Config>(_name: Name, glob: Record<string, () => Promise<unknown>>): Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? DocCollectionEntry<StandardSchemaV1.InferOutput<Schema>> : never;
47
+ };
48
+ declare function createClientLoader<Frontmatter, Props extends object = object>(globEntries: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, options: ClientLoaderOptions<Frontmatter, Props>): ClientLoader<Frontmatter, Props>;
49
+
50
+ export { type BrowserCreate, type ClientLoader, type ClientLoaderOptions, type DocCollectionEntry, createClientLoader, fromConfig };
@@ -0,0 +1,50 @@
1
+ import { ReactNode, FC } from 'react';
2
+ import { CompiledMDXFile } from './server.js';
3
+ import { StandardSchemaV1 } from '@standard-schema/spec';
4
+ import { D as DocCollection, b as DocsCollection } from '../index-D7JdSMpp.js';
5
+ import 'fumadocs-core/source';
6
+ import 'fumadocs-core/mdx-plugins';
7
+ import 'fumadocs-core/toc';
8
+ import 'mdx/types';
9
+ import 'mdast';
10
+ import '@mdx-js/mdx';
11
+ import 'unified';
12
+ import 'zod';
13
+ import 'chokidar';
14
+ import 'vfile';
15
+
16
+ interface ClientLoaderOptions<Frontmatter, Props> {
17
+ /**
18
+ * Loader ID (usually your collection name)
19
+ *
20
+ * The code splitting strategy of frameworks like Tanstack Start may duplicate `createClientLoader()` into different chunks.
21
+ *
22
+ * We use loader ID to share cache between multiple instances of client loader.
23
+ *
24
+ * @defaultValue ''
25
+ */
26
+ id?: string;
27
+ component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode;
28
+ }
29
+ interface ClientLoader<Frontmatter, Props> {
30
+ preload: (path: string) => Promise<CompiledMDXFile<Frontmatter>>;
31
+ /**
32
+ * Get a component that renders content with `React.lazy`.
33
+ */
34
+ getComponent: (path: string) => FC<Props>;
35
+ /**
36
+ * Get react nodes that renders content with `React.lazy`.
37
+ */
38
+ useContent: (path: string, props: Props) => ReactNode;
39
+ }
40
+ type BrowserCreate<Config> = ReturnType<typeof fromConfig<Config>>;
41
+ interface DocCollectionEntry<Frontmatter> {
42
+ raw: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>;
43
+ createClientLoader: <Props extends object>(options: ClientLoaderOptions<Frontmatter, Props>) => ClientLoader<Frontmatter, Props>;
44
+ }
45
+ declare function fromConfig<Config>(): {
46
+ doc<Name extends keyof Config>(_name: Name, glob: Record<string, () => Promise<unknown>>): Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? DocCollectionEntry<StandardSchemaV1.InferOutput<Schema>> : never;
47
+ };
48
+ declare function createClientLoader<Frontmatter, Props extends object = object>(globEntries: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, options: ClientLoaderOptions<Frontmatter, Props>): ClientLoader<Frontmatter, Props>;
49
+
50
+ export { type BrowserCreate, type ClientLoader, type ClientLoaderOptions, type DocCollectionEntry, createClientLoader, fromConfig };
@@ -0,0 +1,68 @@
1
+ // src/runtime/browser.ts
2
+ import { lazy, createElement } from "react";
3
+ function fromConfig() {
4
+ return {
5
+ doc(_name, glob) {
6
+ const raw = glob;
7
+ const out = {
8
+ raw,
9
+ createClientLoader({ id = _name, ...options }) {
10
+ return createClientLoader(raw, { id, ...options });
11
+ }
12
+ };
13
+ return out;
14
+ }
15
+ };
16
+ }
17
+ var loaderStore = /* @__PURE__ */ new Map();
18
+ function createClientLoader(globEntries, options) {
19
+ const { id = "", component } = options;
20
+ const renderers = {};
21
+ const loaders = /* @__PURE__ */ new Map();
22
+ const store = loaderStore.get(id) ?? {
23
+ preloaded: /* @__PURE__ */ new Map()
24
+ };
25
+ loaderStore.set(id, store);
26
+ for (const k in globEntries) {
27
+ loaders.set(k.startsWith("./") ? k.slice(2) : k, globEntries[k]);
28
+ }
29
+ function getLoader(path) {
30
+ const loader = loaders.get(path);
31
+ if (!loader)
32
+ throw new Error(
33
+ `[createClientLoader] ${path} does not exist in available entries`
34
+ );
35
+ return loader;
36
+ }
37
+ function getRenderer(path) {
38
+ if (path in renderers) return renderers[path];
39
+ const OnDemand = lazy(async () => {
40
+ const loaded = await getLoader(path)();
41
+ return { default: (props) => component(loaded, props) };
42
+ });
43
+ renderers[path] = (props) => {
44
+ const cached = store.preloaded.get(path);
45
+ if (!cached) return createElement(OnDemand, props);
46
+ return component(cached, props);
47
+ };
48
+ return renderers[path];
49
+ }
50
+ return {
51
+ async preload(path) {
52
+ const loaded = await getLoader(path)();
53
+ store.preloaded.set(path, loaded);
54
+ return loaded;
55
+ },
56
+ getComponent(path) {
57
+ return getRenderer(path);
58
+ },
59
+ useContent(path, props) {
60
+ const Comp = this.getComponent(path);
61
+ return createElement(Comp, props);
62
+ }
63
+ };
64
+ }
65
+ export {
66
+ createClientLoader,
67
+ fromConfig
68
+ };