fumadocs-typescript 5.4.0 → 5.5.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.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { a as GeneratedDoc, c as RawTag, d as TypescriptConfig, f as createProject, g as GenerateTypeTableOptions, h as BaseTypeTableProps, i as GenerateOptions, l as createGenerator, m as generateHash, n as ShikiOptions, o as Generator, p as Cache, r as DocEntry, s as GeneratorOptions, t as MarkdownRenderer, u as Project } from "./markdown-CcCPhMmC.js";
2
2
  import { Root } from "mdast";
3
3
  import { Transformer } from "unified";
4
+ import { StructuredData } from "fumadocs-core/mdx-plugins/remark-structure";
4
5
  //#region src/lib/remark-auto-type-table.d.ts
5
- interface RemarkAutoTypeTableOptions {
6
+ export interface RemarkAutoTypeTableOptions {
6
7
  /**
7
8
  * @defaultValue 'auto-type-table'
8
9
  */
@@ -27,7 +28,11 @@ interface RemarkAutoTypeTableOptions {
27
28
  remarkStringify?: boolean;
28
29
  generator?: Generator;
29
30
  }
30
- interface TypeTableProps extends BaseTypeTableProps {
31
+ /** the structured data of a type table, a table row without header for each prop, linked to the prop */
32
+ export declare function typeTableToStructuredData(id: string, entries: DocEntry[]): StructuredData['contents'];
33
+ /** a type table as Markdown: a heading, its description, and a table of its props */
34
+ export declare function typeTableToMarkdown(doc: GeneratedDoc): string;
35
+ export interface TypeTableProps extends BaseTypeTableProps {
31
36
  cwd?: true;
32
37
  }
33
38
  /**
@@ -35,9 +40,9 @@ interface TypeTableProps extends BaseTypeTableProps {
35
40
  *
36
41
  * MDX is required to use this plugin.
37
42
  */
38
- declare function remarkAutoTypeTable(config?: RemarkAutoTypeTableOptions): Transformer<Root, Root>;
43
+ export declare function remarkAutoTypeTable(config?: RemarkAutoTypeTableOptions): Transformer<Root, Root>;
39
44
  //#endregion
40
45
  //#region src/cache/fs-cache.d.ts
41
- declare function createFileSystemGeneratorCache(dir: string): Cache;
46
+ export declare function createFileSystemGeneratorCache(dir: string): Cache;
42
47
  //#endregion
43
- export { Cache, DocEntry, GenerateOptions, GeneratedDoc, Generator, GeneratorOptions, type MarkdownRenderer, type Project, RawTag, RemarkAutoTypeTableOptions, TypeTableProps, type TypescriptConfig, createFileSystemGeneratorCache, createGenerator, createProject, generateHash, remarkAutoTypeTable };
48
+ export { Cache, DocEntry, GenerateOptions, GeneratedDoc, Generator, GeneratorOptions, type MarkdownRenderer, type Project, RawTag, type TypescriptConfig, createGenerator, createProject, generateHash };
package/dist/index.js CHANGED
@@ -5,8 +5,9 @@ import path from "node:path";
5
5
  import { createHash } from "node:crypto";
6
6
  import fs$1 from "node:fs";
7
7
  import { valueToEstree } from "estree-util-value-to-estree";
8
- import { visit } from "unist-util-visit";
9
8
  import { toEstree } from "hast-util-to-estree";
9
+ import { tableRowToStructuredData } from "fumadocs-core/search";
10
+ import { replaceSource } from "fumadocs-core/mdx-plugins/stringifier";
10
11
  //#region src/lib/type-table.ts
11
12
  async function getTypeTableOutput(gen, { name, type, ...props }, options) {
12
13
  const file = props.path && options?.basePath ? path.join(options.basePath, props.path) : props.path;
@@ -32,7 +33,7 @@ function generateHash(str) {
32
33
  }
33
34
  //#endregion
34
35
  //#region package.json
35
- var version = "5.4.0";
36
+ var version = "5.5.0";
36
37
  //#endregion
37
38
  //#region src/lib/get-simple-form.ts
38
39
  function getSimpleForm(type, checker, location, options = {}) {
@@ -357,6 +358,38 @@ async function buildTypeProp(entries, renderer) {
357
358
  for (const node of output) prop.addExpressionNode(node.name, node.node);
358
359
  return prop.build();
359
360
  }
361
+ /** the structured data of a type table, a table row without header for each prop, linked to the prop */
362
+ function typeTableToStructuredData(id, entries) {
363
+ const contents = [];
364
+ for (const entry of entries) contents.push(tableRowToStructuredData({
365
+ table: id,
366
+ heading: `${id}-${entry.name}`,
367
+ row: typeTableRow(entry)
368
+ }));
369
+ return contents;
370
+ }
371
+ /** a type table as Markdown: a heading, its description, and a table of its props */
372
+ function typeTableToMarkdown(doc) {
373
+ let out = `### ${doc.name}\n\n`;
374
+ if (doc.description) out += `${doc.description.trim()}\n\n`;
375
+ out += "| Prop | Type | Description |\n| --- | --- | --- |";
376
+ for (const entry of doc.entries) {
377
+ out += "\n|";
378
+ for (const cell of typeTableRow(entry)) out += ` ${cell.replace(/\s*\n\s*/g, " ").replaceAll("|", "\\|")} |`;
379
+ }
380
+ return out;
381
+ }
382
+ function typeTableRow(entry) {
383
+ const tags = parseTags(entry.tags);
384
+ let description = entry.description.replace(/{@link (?<link>[^}]*)}/g, "$1").trim();
385
+ if (tags.default) description += `${description ? " " : ""}Default: \`${tags.default}\``;
386
+ if (entry.deprecated) description = `**Deprecated.** ${description}`;
387
+ return [
388
+ `\`${entry.name}${entry.required ? "" : "?"}\``,
389
+ `\`${entry.simplifiedType}\``,
390
+ description
391
+ ];
392
+ }
360
393
  /**
361
394
  * Compile `auto-type-table` into Fumadocs UI compatible TypeTable
362
395
  *
@@ -409,14 +442,18 @@ function remarkAutoTypeTable(config = {}) {
409
442
  },
410
443
  ...attributes
411
444
  ],
412
- children: []
445
+ children: [],
446
+ data: { structuredData: { contents: typeTableToStructuredData(`type-table-${doc.id}`, doc.entries) } }
413
447
  });
414
- return rendered;
448
+ return {
449
+ output,
450
+ rendered
451
+ };
415
452
  }
416
453
  return async (tree, file) => {
417
454
  const queue = [];
418
- visit(tree, "mdxJsxFlowElement", (node) => {
419
- if (node.name !== name) return;
455
+ walk(tree, (node) => {
456
+ if (node.type !== "mdxJsxFlowElement" || node.name !== name) return;
420
457
  const props = {};
421
458
  const attributes = [];
422
459
  const onError = (message, cause) => {
@@ -441,10 +478,13 @@ function remarkAutoTypeTable(config = {}) {
441
478
  default: attributes.push(attr);
442
479
  }
443
480
  }
444
- queue.push(generate(file, props, attributes).then((children) => {
481
+ queue.push(generate(file, props, attributes).then(({ output, rendered }) => {
482
+ let markdown = "";
483
+ for (const doc of output) markdown += `${markdown ? "\n\n" : ""}${typeTableToMarkdown(doc)}`;
484
+ replaceSource(file, node, markdown);
445
485
  Object.assign(node, {
446
486
  type: "root",
447
- children
487
+ children: rendered
448
488
  });
449
489
  }).catch((err) => {
450
490
  onError("failed to generate type table", err);
@@ -454,6 +494,11 @@ function remarkAutoTypeTable(config = {}) {
454
494
  await Promise.all(queue);
455
495
  };
456
496
  }
497
+ /** visit a tree in document order, returning `skip` skips the children of a node */
498
+ function walk(node, visitor) {
499
+ if (visitor(node) === "skip" || !("children" in node)) return;
500
+ for (const child of node.children) walk(child, visitor);
501
+ }
457
502
  //#endregion
458
503
  //#region src/cache/fs-cache.ts
459
504
  function createFileSystemGeneratorCache(dir) {
@@ -474,4 +519,4 @@ function createFileSystemGeneratorCache(dir) {
474
519
  };
475
520
  }
476
521
  //#endregion
477
- export { createFileSystemGeneratorCache, createGenerator, createProject, generateHash, remarkAutoTypeTable };
522
+ export { createFileSystemGeneratorCache, createGenerator, createProject, generateHash, remarkAutoTypeTable, typeTableToMarkdown, typeTableToStructuredData };
@@ -2,7 +2,7 @@ import { g as GenerateTypeTableOptions, h as BaseTypeTableProps, n as ShikiOptio
2
2
  import * as JsxRuntime from "react/jsx-runtime";
3
3
  import { ComponentProps, ReactNode } from "react";
4
4
  //#region src/ui/auto-type-table.d.ts
5
- interface AutoTypeTableProps extends BaseTypeTableProps, ComponentProps<'div'> {
5
+ export interface AutoTypeTableProps extends BaseTypeTableProps, ComponentProps<'div'> {
6
6
  generator: Generator;
7
7
  /** Shiki configuration when using default `renderMarkdown` & `renderType` */
8
8
  shiki?: ShikiOptions;
@@ -10,6 +10,5 @@ interface AutoTypeTableProps extends BaseTypeTableProps, ComponentProps<'div'> {
10
10
  renderMarkdown?: (md: string) => Promise<ReactNode>;
11
11
  renderType?: (type: string) => Promise<ReactNode>;
12
12
  }
13
- declare function AutoTypeTable({ generator, options, renderType, renderMarkdown, shiki, name, path, type, ...props }: AutoTypeTableProps): Promise<Promise<JsxRuntime.JSX.Element>[]>;
14
- //#endregion
15
- export { AutoTypeTable, AutoTypeTableProps };
13
+ export declare function AutoTypeTable({ generator, options, renderType, renderMarkdown, shiki, name, path, type, ...props }: AutoTypeTableProps): Promise<Promise<JsxRuntime.JSX.Element>[]>;
14
+ //#endregion
package/dist/ui/index.js CHANGED
@@ -47,7 +47,7 @@ function toJsx(hast) {
47
47
  ...JsxRuntime,
48
48
  components: {
49
49
  ...defaultMdxComponents,
50
- img: void 0
50
+ img: "img"
51
51
  }
52
52
  });
53
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-typescript",
3
- "version": "5.4.0",
3
+ "version": "5.5.0",
4
4
  "description": "Typescript Integration for Fumadocs",
5
5
  "keywords": [
6
6
  "Docs",
@@ -17,6 +17,7 @@
17
17
  "dist"
18
18
  ],
19
19
  "type": "module",
20
+ "sideEffects": false,
20
21
  "main": "./dist/index.js",
21
22
  "types": "./dist/index.d.ts",
22
23
  "exports": {
@@ -38,32 +39,31 @@
38
39
  "hast-util-to-jsx-runtime": "^2.3.6",
39
40
  "remark": "^15.0.1",
40
41
  "remark-rehype": "^11.1.2",
41
- "shiki": "^4.4.3",
42
+ "shiki": "^4.5.0",
42
43
  "typescript": "~7.0.2",
43
- "unified": "^11.0.5",
44
- "unist-util-visit": "^5.1.0"
44
+ "unified": "^11.0.5"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@mdx-js/mdx": "^3.1.1",
48
48
  "@types/estree": "^1.0.9",
49
49
  "@types/hast": "^3.0.5",
50
50
  "@types/mdast": "^4.0.4",
51
- "@types/node": "26.4.1",
52
- "@types/react": "^19.2.18",
53
- "@types/react-dom": "^19.2.5",
51
+ "@types/node": "26.6.4",
52
+ "@types/react": "^19.3.0",
53
+ "@types/react-dom": "^19.3.0",
54
+ "fumadocs-core": "16.17.0",
55
+ "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.0",
54
56
  "mdast-util-mdx": "^3.0.0",
55
- "tsdown": "0.22.14",
56
- "vfile": "^6.0.3",
57
- "fumadocs-core": "16.15.6",
58
- "fumadocs-ui": "npm:@fumadocs/base-ui@16.15.6",
59
- "tsconfig": "0.0.0"
57
+ "tsconfig": "0.0.0",
58
+ "tsdown": "0.23.0",
59
+ "vfile": "^6.0.3"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@types/estree": "*",
63
63
  "@types/hast": "*",
64
64
  "@types/mdast": "*",
65
65
  "@types/react": "*",
66
- "fumadocs-core": "^16.7.0",
66
+ "fumadocs-core": "^16.17.0",
67
67
  "fumadocs-ui": "^16.7.0",
68
68
  "react": "^19.2.0",
69
69
  "react-dom": "^19.2.0"