fumadocs-typescript 5.4.1 → 5.5.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/index.d.ts +5 -0
- package/dist/index.js +55 -9
- package/dist/ui/index.js +1 -1
- package/package.json +11 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
6
|
export interface RemarkAutoTypeTableOptions {
|
|
6
7
|
/**
|
|
@@ -27,6 +28,10 @@ export interface RemarkAutoTypeTableOptions {
|
|
|
27
28
|
remarkStringify?: boolean;
|
|
28
29
|
generator?: Generator;
|
|
29
30
|
}
|
|
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;
|
|
30
35
|
export interface TypeTableProps extends BaseTypeTableProps {
|
|
31
36
|
cwd?: true;
|
|
32
37
|
}
|
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 { markdownTable, 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.
|
|
36
|
+
var version = "5.5.1";
|
|
36
37
|
//#endregion
|
|
37
38
|
//#region src/lib/get-simple-form.ts
|
|
38
39
|
function getSimpleForm(type, checker, location, options = {}) {
|
|
@@ -357,6 +358,39 @@ 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
|
+
const rows = [[
|
|
376
|
+
"Prop",
|
|
377
|
+
"Type",
|
|
378
|
+
"Description"
|
|
379
|
+
]];
|
|
380
|
+
for (const entry of doc.entries) rows.push(typeTableRow(entry));
|
|
381
|
+
return out + markdownTable(rows);
|
|
382
|
+
}
|
|
383
|
+
function typeTableRow(entry) {
|
|
384
|
+
const tags = parseTags(entry.tags);
|
|
385
|
+
let description = entry.description.replace(/{@link (?<link>[^}]*)}/g, "$1").trim();
|
|
386
|
+
if (tags.default) description += `${description ? " " : ""}Default: \`${tags.default}\``;
|
|
387
|
+
if (entry.deprecated) description = `**Deprecated.** ${description}`;
|
|
388
|
+
return [
|
|
389
|
+
`\`${entry.name}${entry.required ? "" : "?"}\``,
|
|
390
|
+
`\`${entry.simplifiedType}\``,
|
|
391
|
+
description
|
|
392
|
+
];
|
|
393
|
+
}
|
|
360
394
|
/**
|
|
361
395
|
* Compile `auto-type-table` into Fumadocs UI compatible TypeTable
|
|
362
396
|
*
|
|
@@ -409,14 +443,18 @@ function remarkAutoTypeTable(config = {}) {
|
|
|
409
443
|
},
|
|
410
444
|
...attributes
|
|
411
445
|
],
|
|
412
|
-
children: []
|
|
446
|
+
children: [],
|
|
447
|
+
data: { structuredData: { contents: typeTableToStructuredData(`type-table-${doc.id}`, doc.entries) } }
|
|
413
448
|
});
|
|
414
|
-
return
|
|
449
|
+
return {
|
|
450
|
+
output,
|
|
451
|
+
rendered
|
|
452
|
+
};
|
|
415
453
|
}
|
|
416
454
|
return async (tree, file) => {
|
|
417
455
|
const queue = [];
|
|
418
|
-
|
|
419
|
-
if (node.name !== name) return;
|
|
456
|
+
walk(tree, (node) => {
|
|
457
|
+
if (node.type !== "mdxJsxFlowElement" || node.name !== name) return;
|
|
420
458
|
const props = {};
|
|
421
459
|
const attributes = [];
|
|
422
460
|
const onError = (message, cause) => {
|
|
@@ -441,10 +479,13 @@ function remarkAutoTypeTable(config = {}) {
|
|
|
441
479
|
default: attributes.push(attr);
|
|
442
480
|
}
|
|
443
481
|
}
|
|
444
|
-
queue.push(generate(file, props, attributes).then((
|
|
482
|
+
queue.push(generate(file, props, attributes).then(({ output, rendered }) => {
|
|
483
|
+
let markdown = "";
|
|
484
|
+
for (const doc of output) markdown += `${markdown ? "\n\n" : ""}${typeTableToMarkdown(doc)}`;
|
|
485
|
+
replaceSource(file, node, markdown);
|
|
445
486
|
Object.assign(node, {
|
|
446
487
|
type: "root",
|
|
447
|
-
children
|
|
488
|
+
children: rendered
|
|
448
489
|
});
|
|
449
490
|
}).catch((err) => {
|
|
450
491
|
onError("failed to generate type table", err);
|
|
@@ -454,6 +495,11 @@ function remarkAutoTypeTable(config = {}) {
|
|
|
454
495
|
await Promise.all(queue);
|
|
455
496
|
};
|
|
456
497
|
}
|
|
498
|
+
/** visit a tree in document order, returning `skip` skips the children of a node */
|
|
499
|
+
function walk(node, visitor) {
|
|
500
|
+
if (visitor(node) === "skip" || !("children" in node)) return;
|
|
501
|
+
for (const child of node.children) walk(child, visitor);
|
|
502
|
+
}
|
|
457
503
|
//#endregion
|
|
458
504
|
//#region src/cache/fs-cache.ts
|
|
459
505
|
function createFileSystemGeneratorCache(dir) {
|
|
@@ -474,4 +520,4 @@ function createFileSystemGeneratorCache(dir) {
|
|
|
474
520
|
};
|
|
475
521
|
}
|
|
476
522
|
//#endregion
|
|
477
|
-
export { createFileSystemGeneratorCache, createGenerator, createProject, generateHash, remarkAutoTypeTable };
|
|
523
|
+
export { createFileSystemGeneratorCache, createGenerator, createProject, generateHash, remarkAutoTypeTable, typeTableToMarkdown, typeTableToStructuredData };
|
package/dist/ui/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-typescript",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.1",
|
|
4
4
|
"description": "Typescript Integration for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -39,32 +39,31 @@
|
|
|
39
39
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
40
40
|
"remark": "^15.0.1",
|
|
41
41
|
"remark-rehype": "^11.1.2",
|
|
42
|
-
"shiki": "^4.
|
|
42
|
+
"shiki": "^4.5.0",
|
|
43
43
|
"typescript": "~7.0.2",
|
|
44
|
-
"unified": "^11.0.5"
|
|
45
|
-
"unist-util-visit": "^5.1.0"
|
|
44
|
+
"unified": "^11.0.5"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"@mdx-js/mdx": "^3.1.1",
|
|
49
48
|
"@types/estree": "^1.0.9",
|
|
50
49
|
"@types/hast": "^3.0.5",
|
|
51
50
|
"@types/mdast": "^4.0.4",
|
|
52
|
-
"@types/node": "26.
|
|
53
|
-
"@types/react": "^19.
|
|
54
|
-
"@types/react-dom": "^19.
|
|
51
|
+
"@types/node": "26.6.4",
|
|
52
|
+
"@types/react": "^19.3.0",
|
|
53
|
+
"@types/react-dom": "^19.3.0",
|
|
54
|
+
"fumadocs-core": "16.17.1",
|
|
55
|
+
"fumadocs-ui": "npm:@fumadocs/base-ui@16.17.1",
|
|
55
56
|
"mdast-util-mdx": "^3.0.0",
|
|
57
|
+
"tsconfig": "0.0.0",
|
|
56
58
|
"tsdown": "0.23.0",
|
|
57
|
-
"vfile": "^6.0.3"
|
|
58
|
-
"fumadocs-core": "16.15.11",
|
|
59
|
-
"fumadocs-ui": "npm:@fumadocs/base-ui@16.15.11",
|
|
60
|
-
"tsconfig": "0.0.0"
|
|
59
|
+
"vfile": "^6.0.3"
|
|
61
60
|
},
|
|
62
61
|
"peerDependencies": {
|
|
63
62
|
"@types/estree": "*",
|
|
64
63
|
"@types/hast": "*",
|
|
65
64
|
"@types/mdast": "*",
|
|
66
65
|
"@types/react": "*",
|
|
67
|
-
"fumadocs-core": "^16.
|
|
66
|
+
"fumadocs-core": "^16.17.1",
|
|
68
67
|
"fumadocs-ui": "^16.7.0",
|
|
69
68
|
"react": "^19.2.0",
|
|
70
69
|
"react-dom": "^19.2.0"
|