fumadocs-typescript 4.0.14 → 5.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/base-Dvhn4vZx.d.ts +115 -0
- package/dist/base-Dvhn4vZx.d.ts.map +1 -0
- package/dist/index.d.ts +35 -57
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +350 -497
- package/dist/index.js.map +1 -0
- package/dist/objectSpread2-BbbttTvx.js +203 -0
- package/dist/objectSpread2-BbbttTvx.js.map +1 -0
- package/dist/ui/index.d.ts +19 -11
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +77 -80
- package/dist/ui/index.js.map +1 -0
- package/package.json +22 -20
- package/dist/base-Q18nCvFH.d.ts +0 -117
- package/dist/chunk-REUDVA2G.js +0 -132
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["fs","types: string[]","ts","dedupe","out: T[]","instance: Project | undefined","out: GeneratedDoc[]","options","entryContext: EntryContext","entry: DocEntry","out: ObjectExpression","queue: Promise<void>[]","props: Record<string, string | true>"],"sources":["../src/create-project.ts","../src/lib/type-table.ts","../src/lib/get-simple-form.ts","../src/lib/base.ts","../src/lib/remark-auto-type-table.ts","../src/cache/fs-cache.ts"],"sourcesContent":["import { Project } from 'ts-morph';\n\nexport interface TypescriptConfig {\n files?: string[];\n tsconfigPath?: string;\n /** A root directory to resolve relative path entries in the config file to. e.g. outDir */\n basePath?: string;\n}\n\nexport function createProject(options: TypescriptConfig = {}): Project {\n return new Project({\n tsConfigFilePath: options.tsconfigPath ?? './tsconfig.json',\n skipAddingFilesFromTsConfig: true,\n });\n}\n","import * as fs from 'node:fs/promises';\nimport { type GenerateOptions, type Generator } from '@/lib/base';\nimport { join } from 'node:path';\n\nexport interface BaseTypeTableProps {\n /**\n * The path to source TypeScript file.\n */\n path?: string;\n\n /**\n * Exported type name to generate from.\n */\n name?: string;\n\n /**\n * Set the type to generate from.\n *\n * When used with `name`, it generates the type with `name` as export name.\n *\n * ```ts\n * export const myName = MyType;\n * ```\n *\n * When `type` contains multiple lines, `export const` is not added.\n * You need to export it manually, and specify the type name with `name`.\n *\n * ```tsx\n * <AutoTypeTable\n * path=\"./file.ts\"\n * type={`import { ReactNode } from \"react\"\n * export const MyName = ReactNode`}\n * name=\"MyName\"\n * />\n * ```\n */\n type?: string;\n}\n\nexport interface GenerateTypeTableOptions extends GenerateOptions {\n /**\n * base path to resolve `path` prop\n */\n basePath?: string;\n}\n\nexport async function getTypeTableOutput(\n gen: Generator,\n { name, type, ...props }: BaseTypeTableProps,\n options?: GenerateTypeTableOptions,\n) {\n const file = props.path && options?.basePath ? join(options.basePath, props.path) : props.path;\n let typeName = name;\n let content = '';\n\n if (file) {\n content = (await fs.readFile(file)).toString();\n }\n\n if (type && type.split('\\n').length > 1) {\n content += `\\n${type}`;\n } else if (type) {\n typeName ??= '$Fumadocs';\n content += `\\nexport type ${typeName} = ${type}`;\n }\n\n const output = await gen.generateDocumentation(\n { path: file ?? 'temp.ts', content },\n typeName,\n options,\n );\n\n if (name && output.length === 0)\n throw new Error(`${name} in ${file ?? 'empty file'} doesn't exist`);\n\n return output;\n}\n","import * as ts from 'ts-morph';\n\nexport function getSimpleForm(\n type: ts.Type,\n checker: ts.TypeChecker,\n noUndefined = false,\n location?: ts.Node,\n): string {\n if (type.isUndefined() && noUndefined) return '';\n\n const alias = type.getAliasSymbol();\n if (alias) {\n const args = type.getAliasTypeArguments();\n if (args.length === 0) return alias.getName();\n\n return `${alias.getName()}<${args.map((arg) => getSimpleForm(arg, checker)).join(', ')}>`;\n }\n\n if (type.isUnion()) {\n const types: string[] = [];\n for (const t of type.getUnionTypes()) {\n const str = getSimpleForm(t, checker, noUndefined);\n if (str.length > 0 && str !== 'never') types.unshift(str);\n }\n\n return types.length > 0\n ? // boolean | null will become true | false | null, need to ensure it's still returned as boolean\n dedupe(types).join(' | ').replace('true | false', 'boolean')\n : 'never';\n }\n\n if (type.isIntersection()) {\n const types: string[] = [];\n for (const t of type.getIntersectionTypes()) {\n const str = getSimpleForm(t, checker, noUndefined);\n if (str.length > 0 && str !== 'never') types.unshift(str);\n }\n\n return dedupe(types).join(' & ');\n }\n\n if (type.isTuple()) {\n const elements = type\n .getTupleElements()\n .map((t) => getSimpleForm(t, checker))\n .join(', ');\n\n return `[${elements}]`;\n }\n\n if (type.isArray() || type.isReadonlyArray()) {\n return 'array';\n }\n\n if (type.getCallSignatures().length > 0) {\n return 'function';\n }\n\n if (type.isClassOrInterface() || type.isObject()) {\n return 'object';\n }\n\n return type.getText(location, ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);\n}\n\nfunction dedupe<T>(arr: T[]): T[] {\n const dedupe = new Set<T>();\n const out: T[] = [];\n\n for (const item of arr) {\n if (!dedupe.has(item)) {\n out.push(item);\n dedupe.add(item);\n }\n }\n\n return out;\n}\n","import {\n type ExportedDeclarations,\n Project,\n type Symbol as TsSymbol,\n ts,\n type Type,\n} from 'ts-morph';\nimport { createProject, type TypescriptConfig } from '@/create-project';\nimport fs from 'node:fs/promises';\nimport {\n type BaseTypeTableProps,\n type GenerateTypeTableOptions,\n getTypeTableOutput,\n} from '@/lib/type-table';\nimport path from 'node:path';\nimport { getSimpleForm } from '@/lib/get-simple-form';\nimport type { Cache } from '@/cache';\n\nexport interface GeneratedDoc {\n name: string;\n description: string;\n entries: DocEntry[];\n}\n\nexport interface DocEntry {\n name: string;\n description: string;\n type: string;\n simplifiedType: string;\n\n tags: RawTag[];\n required: boolean;\n deprecated: boolean;\n}\n\nexport interface RawTag {\n name: string;\n text: string;\n}\n\ninterface EntryContext {\n program: Project;\n transform?: Transformer;\n type: Type;\n declaration: ExportedDeclarations;\n}\n\ntype Transformer = (\n this: EntryContext,\n entry: DocEntry,\n propertyType: Type,\n propertySymbol: TsSymbol,\n) => void;\n\nexport interface GenerateOptions {\n /**\n * Allow fields with `@internal` tag\n *\n * @defaultValue false\n */\n allowInternal?: boolean;\n\n /**\n * Modify output property entry\n */\n transform?: Transformer;\n}\n\nexport type Generator = ReturnType<typeof createGenerator>;\n\nexport interface GeneratorOptions extends TypescriptConfig {\n /**\n * cache results, note that some options are not marked as dependency.\n *\n * @defaultValue false\n */\n cache?: Cache | false;\n\n project?: Project;\n}\n\nexport function createGenerator(config?: GeneratorOptions | Project) {\n const options =\n config instanceof Project\n ? {\n project: config,\n }\n : config;\n const cache = options?.cache ? options.cache : null;\n let instance: Project | undefined;\n\n function getProject() {\n instance ??= options?.project ?? createProject(options);\n return instance;\n }\n\n return {\n async generateDocumentation(\n file: {\n path: string;\n content?: string;\n },\n name: string | undefined,\n options?: GenerateOptions,\n ) {\n const content = file.content ?? (await fs.readFile(path.resolve(file.path))).toString();\n const cacheKey = `${file.path}:${name}:${content}`;\n if (cache) {\n const cached = (await cache.read(cacheKey)) as GeneratedDoc[] | undefined;\n if (cached) return cached;\n }\n const sourceFile = getProject().createSourceFile(file.path, content, {\n overwrite: true,\n });\n const out: GeneratedDoc[] = [];\n\n for (const [k, d] of sourceFile.getExportedDeclarations()) {\n if (name && name !== k) continue;\n\n if (d.length > 1)\n console.warn(`export ${k} should not have more than one type declaration.`);\n\n out.push(generate(getProject(), k, d[0], options));\n }\n\n void cache?.write(cacheKey, out);\n return out;\n },\n generateTypeTable(props: BaseTypeTableProps, options?: GenerateTypeTableOptions) {\n return getTypeTableOutput(this, props, options);\n },\n };\n}\n\nfunction generate(\n program: Project,\n name: string,\n declaration: ExportedDeclarations,\n { allowInternal = false, transform }: GenerateOptions = {},\n): GeneratedDoc {\n const entryContext: EntryContext = {\n transform,\n program,\n type: declaration.getType(),\n declaration,\n };\n\n const comment = declaration\n .getSymbol()\n ?.compilerSymbol.getDocumentationComment(program.getTypeChecker().compilerObject);\n\n return {\n name,\n description: comment ? ts.displayPartsToString(comment) : '',\n entries: declaration\n .getType()\n .getProperties()\n .map((prop) => getDocEntry(prop, entryContext))\n .filter((entry) => entry && (allowInternal || !('internal' in entry.tags))) as DocEntry[],\n };\n}\n\nfunction getDocEntry(prop: TsSymbol, context: EntryContext): DocEntry | undefined {\n const { transform, program } = context;\n if (context.type.isClass() && prop.getName().startsWith('#')) {\n return;\n }\n\n const subType = prop.getTypeAtLocation(context.declaration);\n const isOptional = prop.isOptional();\n const tags = prop.getJsDocTags().map(\n (tag) =>\n ({\n name: tag.getName(),\n text: ts.displayPartsToString(tag.getText()),\n }) satisfies RawTag,\n );\n\n let type = subType.getText(\n context.declaration,\n ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | ts.TypeFormatFlags.NoTruncation,\n );\n let simplifiedType = getSimpleForm(\n subType,\n program.getTypeChecker(),\n isOptional,\n context.declaration,\n );\n\n for (const tag of tags) {\n // replace full type with @fumadocsType\n if (tag.name === 'fumadocsType') {\n const match = /`(?<name>.+)`$/.exec(tag.text)?.[1];\n if (match) type = match;\n continue;\n }\n\n // replace simplified type with @remarks\n if (tag.name === 'remarks') {\n const match = /^`(?<name>.+)`/.exec(tag.text)?.[1];\n if (match) simplifiedType = match;\n }\n }\n\n const entry: DocEntry = {\n name: prop.getName(),\n description: ts.displayPartsToString(\n prop.compilerSymbol.getDocumentationComment(program.getTypeChecker().compilerObject),\n ),\n tags,\n type,\n simplifiedType,\n required: !isOptional,\n deprecated: tags.some((tag) => tag.name === 'deprecated'),\n };\n\n transform?.call(context, entry, subType, prop);\n\n return entry;\n}\n","import type { Root } from 'mdast';\nimport type { Nodes } from 'hast';\nimport type { Transformer } from 'unified';\nimport type { Expression, ExpressionStatement, ObjectExpression, Program } from 'estree';\nimport { createGenerator, type DocEntry, type Generator } from '@/lib/base';\nimport { renderMarkdownToHast, renderTypeToHast } from '@/markdown';\nimport { valueToEstree } from 'estree-util-value-to-estree';\nimport { visit } from 'unist-util-visit';\nimport { type BaseTypeTableProps, type GenerateTypeTableOptions } from '@/lib/type-table';\nimport { toEstree } from 'hast-util-to-estree';\nimport { type ParameterTag, parseTags } from '@/lib/parse-tags';\n\nfunction objectBuilder() {\n const out: ObjectExpression = {\n type: 'ObjectExpression',\n properties: [],\n };\n\n return {\n addExpressionNode(key: string, expression: Expression) {\n out.properties.push({\n type: 'Property',\n method: false,\n shorthand: false,\n computed: false,\n key: {\n type: 'Identifier',\n name: key,\n },\n kind: 'init',\n value: expression,\n });\n },\n addJsxProperty(key: string, hast: Nodes) {\n const estree = toEstree(hast, {\n elementAttributeNameCase: 'react',\n }).body[0] as ExpressionStatement;\n\n this.addExpressionNode(key, estree.expression);\n },\n build() {\n return out;\n },\n };\n}\n\nasync function buildTypeProp(\n entries: DocEntry[],\n {\n renderMarkdown = renderMarkdownToHast,\n renderType = renderTypeToHast,\n }: RemarkAutoTypeTableOptions,\n): Promise<ObjectExpression> {\n async function onItem(entry: DocEntry) {\n const node = objectBuilder();\n const tags = parseTags(entry.tags);\n node.addJsxProperty('type', await renderType(entry.simplifiedType));\n node.addJsxProperty('typeDescription', await renderType(entry.type));\n node.addExpressionNode('required', valueToEstree(entry.required));\n\n if (tags.default) node.addJsxProperty('default', await renderType(tags.default));\n\n if (tags.returns) node.addJsxProperty('returns', await renderMarkdown(tags.returns));\n\n if (tags.params) {\n node.addExpressionNode('parameters', {\n type: 'ArrayExpression',\n elements: await Promise.all(tags.params.map(onParam)),\n });\n }\n\n if (entry.description) {\n node.addJsxProperty('description', await renderMarkdown(entry.description));\n }\n\n return node.build();\n }\n\n async function onParam(param: ParameterTag) {\n const node = objectBuilder();\n node.addExpressionNode('name', valueToEstree(param.name));\n if (param.description)\n node.addJsxProperty('description', await renderMarkdown(param.description));\n\n return node.build();\n }\n\n const prop = objectBuilder();\n const output = await Promise.all(\n entries.map(async (entry) => ({\n name: entry.name,\n node: await onItem(entry),\n })),\n );\n\n for (const node of output) {\n prop.addExpressionNode(node.name, node.node);\n }\n\n return prop.build();\n}\n\nexport interface RemarkAutoTypeTableOptions {\n /**\n * @defaultValue 'auto-type-table'\n */\n name?: string;\n\n /**\n * @defaultValue 'TypeTable'\n */\n outputName?: string;\n\n renderMarkdown?: typeof renderMarkdownToHast;\n renderType?: typeof renderTypeToHast;\n\n /**\n * Customise type table generation\n */\n options?: GenerateTypeTableOptions;\n\n /**\n * generate required `value` property for `remark-stringify`\n */\n remarkStringify?: boolean;\n\n generator?: Generator;\n}\n\nexport interface TypeTableProps extends BaseTypeTableProps {\n cwd?: true;\n}\n\n/**\n * Compile `auto-type-table` into Fumadocs UI compatible TypeTable\n *\n * MDX is required to use this plugin.\n */\nexport function remarkAutoTypeTable(\n config: RemarkAutoTypeTableOptions = {},\n): Transformer<Root, Root> {\n const {\n name = 'auto-type-table',\n outputName = 'TypeTable',\n options: generateOptions = {},\n remarkStringify = true,\n generator = createGenerator(),\n } = config;\n\n return async (tree, file) => {\n const queue: Promise<void>[] = [];\n async function run(node: object, props: TypeTableProps) {\n let basePath = props.cwd ? file.cwd : generateOptions.basePath;\n if (file.dirname) {\n basePath ??= file.dirname;\n }\n\n const output = await generator.generateTypeTable(props, {\n ...generateOptions,\n basePath,\n });\n\n const rendered = output.map(async (doc) => {\n return {\n type: 'mdxJsxFlowElement',\n name: outputName,\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'type',\n value: {\n type: 'mdxJsxAttributeValueExpression',\n value: remarkStringify ? JSON.stringify(doc, null, 2) : '',\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ExpressionStatement',\n expression: await buildTypeProp(doc.entries, config),\n },\n ],\n } satisfies Program,\n },\n },\n },\n ],\n children: [],\n };\n });\n\n Object.assign(node, {\n type: 'root',\n attributes: [],\n children: await Promise.all(rendered),\n } as Root);\n }\n\n visit(tree, 'mdxJsxFlowElement', (node) => {\n if (node.name !== name) return;\n const props: Record<string, string | true> = {};\n const onError = (message: string, cause?: Error) => {\n const location = node.position\n ? `${file.path}:${node.position.start.line}:${node.position.start.column}`\n : file.path;\n throw new Error(`${location} from <auto-type-table>: ${message}`, {\n cause,\n });\n };\n\n for (const attr of node.attributes) {\n if (attr.type !== 'mdxJsxAttribute') {\n onError('only named attributes are allowed.');\n } else if (typeof attr.value === 'string') {\n props[attr.name] = attr.value;\n } else if (attr.value === null) {\n props[attr.name] = true;\n } else {\n onError('only string & boolean attributes are allowed.');\n }\n }\n\n queue.push(\n run(node, props).catch((err) => {\n onError('failed to generate type table', err);\n }),\n );\n return 'skip';\n });\n\n await Promise.all(queue);\n };\n}\n","import fs from 'node:fs/promises';\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport type { Cache } from '@/cache/index';\n\nexport function createFileSystemGeneratorCache(dir: string): Cache {\n // call `path.resolve` so Vercel NFT will include the cache directory in production.\n dir = path.resolve(dir);\n const initDirPromise = fs.mkdir(dir, { recursive: true }).catch(() => {\n // it fails on Vercel as of 2025 12 May, we can skip it\n });\n\n return {\n async write(input, data) {\n const hash = createHash('SHA256').update(input).digest('hex').slice(0, 12);\n\n await initDirPromise;\n await fs.writeFile(path.join(dir, `${hash}.json`), JSON.stringify(data));\n },\n async read(input) {\n const hash = createHash('SHA256').update(input).digest('hex').slice(0, 12);\n\n try {\n return JSON.parse((await fs.readFile(path.join(dir, `${hash}.json`))).toString());\n } catch {\n return;\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;AASA,SAAgB,cAAc,UAA4B,EAAE,EAAW;;AACrE,QAAO,IAAI,QAAQ;EACjB,2CAAkB,QAAQ,qFAAgB;EAC1C,6BAA6B;EAC9B,CAAC;;;;;mBCmCA,QAAM;AAFV,SAAsB,mBACpB,IACA,KACA;;;;oDAFA,KACA,MACA,SACA;MAFA,EAAE,MAAM,eAAS;EAGjB,MAAM,OAAO,MAAM,2DAAQ,QAAS,YAAW,KAAK,QAAQ,UAAU,MAAM,KAAK,GAAG,MAAM;EAC1F,IAAI,WAAW;EACf,IAAI,UAAU;AAEd,MAAI,KACF,kBAAiBA,KAAG,SAAS,KAAK,EAAE,UAAU;AAGhD,MAAI,QAAQ,KAAK,MAAM,KAAK,CAAC,SAAS,EACpC,YAAW,KAAK;WACP,MAAM;;AACf,0E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O;yCAAM;IACvB,MAAM,OAAO,WAAW,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM,CAAC,MAAM,GAAG,GAAG;AAE1E,UAAM;AACN,UAAM,GAAG,UAAU,KAAK,KAAK,KAAK,GAAG,KAAK,OAAO,EAAE,KAAK,UAAU,KAAK,CAAC;;;EAE1E,AAAM,KAAK;yCAAO;IAChB,MAAM,OAAO,WAAW,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM,CAAC,MAAM,GAAG,GAAG;AAE1E,QAAI;AACF,YAAO,KAAK,aAAa,GAAG,SAAS,KAAK,KAAK,KAAK,GAAG,KAAK,OAAO,CAAC,EAAE,UAAU,CAAC;sBAC3E;AACN;;;;EAGL"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { remark } from "remark";
|
|
2
|
+
import { remarkGfm } from "fumadocs-core/mdx-plugins/remark-gfm";
|
|
3
|
+
import { rehypeCode } from "fumadocs-core/mdx-plugins/rehype-code";
|
|
4
|
+
import remarkRehype from "remark-rehype";
|
|
5
|
+
import { getHighlighter } from "fumadocs-core/highlight";
|
|
6
|
+
|
|
7
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/objectWithoutPropertiesLoose.js
|
|
8
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
9
|
+
if (null == r) return {};
|
|
10
|
+
var t = {};
|
|
11
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
12
|
+
if (e.includes(n)) continue;
|
|
13
|
+
t[n] = r[n];
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/objectWithoutProperties.js
|
|
20
|
+
function _objectWithoutProperties(e, t) {
|
|
21
|
+
if (null == e) return {};
|
|
22
|
+
var o, r, i = _objectWithoutPropertiesLoose(e, t);
|
|
23
|
+
if (Object.getOwnPropertySymbols) {
|
|
24
|
+
var s = Object.getOwnPropertySymbols(e);
|
|
25
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
26
|
+
}
|
|
27
|
+
return i;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/asyncToGenerator.js
|
|
32
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
33
|
+
try {
|
|
34
|
+
var i = n[a](c), u = i.value;
|
|
35
|
+
} catch (n$1) {
|
|
36
|
+
e(n$1);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
40
|
+
}
|
|
41
|
+
function _asyncToGenerator(n) {
|
|
42
|
+
return function() {
|
|
43
|
+
var t = this, e = arguments;
|
|
44
|
+
return new Promise(function(r, o) {
|
|
45
|
+
var a = n.apply(t, e);
|
|
46
|
+
function _next(n$1) {
|
|
47
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n$1);
|
|
48
|
+
}
|
|
49
|
+
function _throw(n$1) {
|
|
50
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n$1);
|
|
51
|
+
}
|
|
52
|
+
_next(void 0);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/markdown.ts
|
|
59
|
+
const shikiOptions = {
|
|
60
|
+
lazy: true,
|
|
61
|
+
langs: ["ts", "tsx"],
|
|
62
|
+
transformers: [],
|
|
63
|
+
parseMetaString: void 0,
|
|
64
|
+
themes: {
|
|
65
|
+
light: "github-light",
|
|
66
|
+
dark: "github-dark"
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const processor = remark().use(remarkGfm).use(remarkRehype).use(rehypeCode, shikiOptions);
|
|
70
|
+
function renderTypeToHast(_x) {
|
|
71
|
+
return _renderTypeToHast.apply(this, arguments);
|
|
72
|
+
}
|
|
73
|
+
function _renderTypeToHast() {
|
|
74
|
+
_renderTypeToHast = _asyncToGenerator(function* (type) {
|
|
75
|
+
return {
|
|
76
|
+
type: "element",
|
|
77
|
+
tagName: "span",
|
|
78
|
+
properties: { class: "shiki" },
|
|
79
|
+
children: [{
|
|
80
|
+
type: "element",
|
|
81
|
+
tagName: "code",
|
|
82
|
+
properties: {},
|
|
83
|
+
children: (yield getHighlighter("js", {
|
|
84
|
+
langs: ["ts"],
|
|
85
|
+
themes: Object.values(shikiOptions.themes)
|
|
86
|
+
})).codeToHast(type, {
|
|
87
|
+
lang: "ts",
|
|
88
|
+
structure: "inline",
|
|
89
|
+
themes: shikiOptions.themes,
|
|
90
|
+
defaultColor: false
|
|
91
|
+
}).children
|
|
92
|
+
}]
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
return _renderTypeToHast.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
function renderMarkdownToHast(_x2) {
|
|
98
|
+
return _renderMarkdownToHast.apply(this, arguments);
|
|
99
|
+
}
|
|
100
|
+
function _renderMarkdownToHast() {
|
|
101
|
+
_renderMarkdownToHast = _asyncToGenerator(function* (md) {
|
|
102
|
+
md = md.replace(new RegExp("{@link (?<link>[^}]*)}", "g"), "$1");
|
|
103
|
+
return processor.run(processor.parse(md));
|
|
104
|
+
});
|
|
105
|
+
return _renderMarkdownToHast.apply(this, arguments);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/lib/parse-tags.ts
|
|
110
|
+
/**
|
|
111
|
+
* Parse tags, only returns recognized fields.
|
|
112
|
+
*/
|
|
113
|
+
function parseTags(tags) {
|
|
114
|
+
const typed = {};
|
|
115
|
+
for (const { name: key, text } of tags) {
|
|
116
|
+
if (key === "default" || key === "defaultValue") {
|
|
117
|
+
typed.default = text;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (key === "param") {
|
|
121
|
+
var _typed$params;
|
|
122
|
+
const [param, description] = text.split("-", 2);
|
|
123
|
+
(_typed$params = typed.params) !== null && _typed$params !== void 0 || (typed.params = []);
|
|
124
|
+
typed.params.push({
|
|
125
|
+
name: param.trim(),
|
|
126
|
+
description: description.trim()
|
|
127
|
+
});
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (key === "returns") typed.returns = text;
|
|
131
|
+
}
|
|
132
|
+
return typed;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
|
|
137
|
+
function _typeof(o) {
|
|
138
|
+
"@babel/helpers - typeof";
|
|
139
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
140
|
+
return typeof o$1;
|
|
141
|
+
} : function(o$1) {
|
|
142
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
143
|
+
}, _typeof(o);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
|
|
148
|
+
function toPrimitive(t, r) {
|
|
149
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
150
|
+
var e = t[Symbol.toPrimitive];
|
|
151
|
+
if (void 0 !== e) {
|
|
152
|
+
var i = e.call(t, r || "default");
|
|
153
|
+
if ("object" != _typeof(i)) return i;
|
|
154
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
155
|
+
}
|
|
156
|
+
return ("string" === r ? String : Number)(t);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
|
|
161
|
+
function toPropertyKey(t) {
|
|
162
|
+
var i = toPrimitive(t, "string");
|
|
163
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
|
|
168
|
+
function _defineProperty(e, r, t) {
|
|
169
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
170
|
+
value: t,
|
|
171
|
+
enumerable: !0,
|
|
172
|
+
configurable: !0,
|
|
173
|
+
writable: !0
|
|
174
|
+
}) : e[r] = t, e;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
|
|
179
|
+
function ownKeys(e, r) {
|
|
180
|
+
var t = Object.keys(e);
|
|
181
|
+
if (Object.getOwnPropertySymbols) {
|
|
182
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
183
|
+
r && (o = o.filter(function(r$1) {
|
|
184
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
185
|
+
})), t.push.apply(t, o);
|
|
186
|
+
}
|
|
187
|
+
return t;
|
|
188
|
+
}
|
|
189
|
+
function _objectSpread2(e) {
|
|
190
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
191
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
192
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
193
|
+
_defineProperty(e, r$1, t[r$1]);
|
|
194
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
195
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return e;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
//#endregion
|
|
202
|
+
export { _asyncToGenerator as a, renderTypeToHast as i, parseTags as n, _objectWithoutProperties as o, renderMarkdownToHast as r, _objectSpread2 as t };
|
|
203
|
+
//# sourceMappingURL=objectSpread2-BbbttTvx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectSpread2-BbbttTvx.js","names":["typed: TypedTags"],"sources":["../src/markdown.ts","../src/lib/parse-tags.ts"],"sourcesContent":["import type { ElementContent, Nodes } from 'hast';\nimport { remark } from 'remark';\nimport { remarkGfm } from 'fumadocs-core/mdx-plugins/remark-gfm';\nimport { rehypeCode, type RehypeCodeOptions } from 'fumadocs-core/mdx-plugins/rehype-code';\nimport remarkRehype from 'remark-rehype';\nimport { getHighlighter } from 'fumadocs-core/highlight';\n\nconst shikiOptions = {\n lazy: true,\n langs: ['ts', 'tsx'],\n\n // disable default transformers & meta parser\n transformers: [],\n parseMetaString: undefined,\n\n themes: {\n light: 'github-light',\n dark: 'github-dark',\n },\n} satisfies RehypeCodeOptions;\n\nconst processor = remark().use(remarkGfm).use(remarkRehype).use(rehypeCode, shikiOptions);\n\nexport async function renderTypeToHast(type: string): Promise<Nodes> {\n const highlighter = await getHighlighter('js', {\n langs: ['ts'],\n themes: Object.values(shikiOptions.themes),\n });\n\n const nodes = highlighter.codeToHast(type, {\n lang: 'ts',\n structure: 'inline',\n themes: shikiOptions.themes,\n defaultColor: false,\n });\n\n return {\n type: 'element',\n tagName: 'span',\n properties: {\n class: 'shiki',\n },\n children: [\n {\n type: 'element',\n tagName: 'code',\n properties: {},\n children: nodes.children as ElementContent[],\n },\n ],\n };\n}\n\nexport async function renderMarkdownToHast(md: string): Promise<Nodes> {\n md = md.replace(/{@link (?<link>[^}]*)}/g, '$1'); // replace jsdoc links\n\n return processor.run(processor.parse(md));\n}\n","import { RawTag } from '@/lib/base';\n\nexport interface ParameterTag {\n name: string;\n description?: string;\n}\n\nexport interface TypedTags {\n default?: string;\n params?: ParameterTag[];\n returns?: string;\n}\n\n/**\n * Parse tags, only returns recognized fields.\n */\nexport function parseTags(tags: RawTag[]): TypedTags {\n const typed: TypedTags = {};\n\n for (const { name: key, text } of tags) {\n if (key === 'default' || key === 'defaultValue') {\n typed.default = text;\n continue;\n }\n\n if (key === 'param') {\n const [param, description] = text.split('-', 2);\n\n typed.params ??= [];\n typed.params.push({\n name: param.trim(),\n description: description.trim(),\n });\n continue;\n }\n\n if (key === 'returns') {\n typed.returns = text;\n }\n }\n\n return typed;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAM,eAAe;CACnB,MAAM;CACN,OAAO,CAAC,MAAM,MAAM;CAGpB,cAAc,EAAE;CAChB,iBAAiB;CAEjB,QAAQ;EACN,OAAO;EACP,MAAM;EACP;CACF;AAED,MAAM,YAAY,QAAQ,CAAC,IAAI,UAAU,CAAC,IAAI,aAAa,CAAC,IAAI,YAAY,aAAa;AAEzF,SAAsB,iBAAiB;;;;wDAA8B;AAanE,SAAO;GACL,MAAM;GACN,SAAS;GACT,YAAY,EACV,OAAO,SACR;GACD,UAAU,CACR;IACE,MAAM;IACN,SAAS;IACT,YAAY,EAAE;IACd,iBAvBoB,eAAe,MAAM;KAC7C,OAAO,CAAC,KAAK;KACb,QAAQ,OAAO,OAAO,aAAa,OAAO;KAC3C,CAAC,EAEwB,WAAW,MAAM;KACzC,MAAM;KACN,WAAW;KACX,QAAQ,aAAa;KACrB,cAAc;KACf,CAAC,CAaoB;IACjB,CACF;GACF;;;;AAGH,SAAsB,qBAAqB;;;;0DAA4B;AACrE,OAAK,GAAG,QAAQ,yCAAyB,EAAE,KAAK;AAEhD,SAAO,UAAU,IAAI,UAAU,MAAM,GAAG,CAAC;;;;;;;;;;ACxC3C,SAAgB,UAAU,MAA2B;CACnD,MAAMA,QAAmB,EAAE;AAE3B,MAAK,MAAM,EAAE,MAAM,KAAK,UAAU,MAAM;AACtC,MAAI,QAAQ,aAAa,QAAQ,gBAAgB;AAC/C,SAAM,UAAU;AAChB;;AAGF,MAAI,QAAQ,SAAS;;GACnB,MAAM,CAAC,OAAO,eAAe,KAAK,MAAM,KAAK,EAAE;AAE/C,0BAAM,iDAAN,MAAM,SAAW,EAAE;AACnB,SAAM,OAAO,KAAK;IAChB,MAAM,MAAM,MAAM;IAClB,aAAa,YAAY,MAAM;IAChC,CAAC;AACF;;AAGF,MAAI,QAAQ,UACV,OAAM,UAAU;;AAIpB,QAAO"}
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { i as Generator, l as BaseTypeTableProps, u as GenerateTypeTableOptions } from "../base-Dvhn4vZx.js";
|
|
2
|
+
import * as runtime from "react/jsx-runtime";
|
|
3
|
+
import "server-only";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
5
|
|
|
6
|
+
//#region src/ui/auto-type-table.d.ts
|
|
6
7
|
type AutoTypeTableProps = BaseTypeTableProps;
|
|
7
|
-
declare function AutoTypeTable({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
declare function AutoTypeTable({
|
|
9
|
+
generator,
|
|
10
|
+
options,
|
|
11
|
+
renderType,
|
|
12
|
+
renderMarkdown,
|
|
13
|
+
...props
|
|
14
|
+
}: AutoTypeTableProps & {
|
|
15
|
+
generator: Generator;
|
|
16
|
+
renderMarkdown?: typeof renderMarkdownDefault;
|
|
17
|
+
renderType?: typeof renderTypeDefault;
|
|
18
|
+
options?: GenerateTypeTableOptions;
|
|
12
19
|
}): Promise<Promise<runtime.JSX.Element>[]>;
|
|
13
20
|
declare function renderTypeDefault(type: string): Promise<ReactNode>;
|
|
14
21
|
declare function renderMarkdownDefault(md: string): Promise<ReactNode>;
|
|
15
|
-
|
|
16
|
-
export { AutoTypeTable,
|
|
22
|
+
//#endregion
|
|
23
|
+
export { AutoTypeTable, AutoTypeTableProps };
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/ui/auto-type-table.tsx"],"sourcesContent":[],"mappings":";;;;;;KAYY,kBAAA,GAAqB;AAArB,iBAEU,aAAA,CAFW;EAAA,SAAA;EAAA,OAAkB;EAAA,UAAA;EAAA,cAAA;EAAA,GAAA;CAAA,EAQhD,kBARgD,GAAA;EAE7B,SAAA,EAOT,SAPsB;EACjC,cAAA,CAAA,EAAA,OAQwB,qBARxB;EACA,UAAA,CAAA,EAAA,OAQoB,iBARpB;EACA,OAAA,CAAA,EAQU,wBARV;CACA,CAAA,EAQD,OARC,CAQD,OARC,CAQD,OAAA,CAAA,GAAA,CAAA,OARC,CAAA,EAAA,CAAA;iBAmDa,iBAAA,CAjDZ,IAAA,EAAA,MAAA,CAAA,EAiD6C,OAjD7C,CAiDqD,SAjDrD,CAAA;iBAqDY,qBAAA,CApDF,EAAA,EAAA,MAAA,CAAA,EAoDqC,OApDrC,CAoD6C,SApD7C,CAAA"}
|
package/dist/ui/index.js
CHANGED
|
@@ -1,89 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
__objRest,
|
|
4
|
-
__spreadProps,
|
|
5
|
-
__spreadValues,
|
|
6
|
-
parseTags,
|
|
7
|
-
renderMarkdownToHast,
|
|
8
|
-
renderTypeToHast
|
|
9
|
-
} from "../chunk-REUDVA2G.js";
|
|
10
|
-
|
|
11
|
-
// src/ui/auto-type-table.tsx
|
|
12
|
-
import {
|
|
13
|
-
TypeTable
|
|
14
|
-
} from "fumadocs-ui/components/type-table";
|
|
1
|
+
import { a as _asyncToGenerator, i as renderTypeToHast, n as parseTags, o as _objectWithoutProperties, r as renderMarkdownToHast, t as _objectSpread2 } from "../objectSpread2-BbbttTvx.js";
|
|
2
|
+
import { TypeTable } from "fumadocs-ui/components/type-table";
|
|
15
3
|
import { toJsxRuntime } from "hast-util-to-jsx-runtime";
|
|
16
4
|
import * as runtime from "react/jsx-runtime";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
17
6
|
import defaultMdxComponents from "fumadocs-ui/mdx";
|
|
18
7
|
import "server-only";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
8
|
+
|
|
9
|
+
//#region src/ui/auto-type-table.tsx
|
|
10
|
+
const _excluded = [
|
|
11
|
+
"generator",
|
|
12
|
+
"options",
|
|
13
|
+
"renderType",
|
|
14
|
+
"renderMarkdown"
|
|
15
|
+
];
|
|
16
|
+
function AutoTypeTable(_x3) {
|
|
17
|
+
return _AutoTypeTable.apply(this, arguments);
|
|
18
|
+
}
|
|
19
|
+
function _AutoTypeTable() {
|
|
20
|
+
_AutoTypeTable = _asyncToGenerator(function* (_ref) {
|
|
21
|
+
let { generator, options = {}, renderType = renderTypeDefault, renderMarkdown = renderMarkdownDefault } = _ref, props = _objectWithoutProperties(_ref, _excluded);
|
|
22
|
+
return (yield generator.generateTypeTable(props, options)).map(function() {
|
|
23
|
+
var _ref3 = _asyncToGenerator(function* (item) {
|
|
24
|
+
const entries = item.entries.map(function() {
|
|
25
|
+
var _ref2 = _asyncToGenerator(function* (entry) {
|
|
26
|
+
var _tags$params;
|
|
27
|
+
const tags = parseTags(entry.tags);
|
|
28
|
+
const paramNodes = [];
|
|
29
|
+
for (const param of (_tags$params = tags.params) !== null && _tags$params !== void 0 ? _tags$params : []) paramNodes.push({
|
|
30
|
+
name: param.name,
|
|
31
|
+
description: param.description ? yield renderMarkdown(param.description) : void 0
|
|
32
|
+
});
|
|
33
|
+
return [entry.name, {
|
|
34
|
+
type: yield renderType(entry.simplifiedType),
|
|
35
|
+
typeDescription: yield renderType(entry.type),
|
|
36
|
+
description: yield renderMarkdown(entry.description),
|
|
37
|
+
default: tags.default ? yield renderType(tags.default) : void 0,
|
|
38
|
+
parameters: paramNodes,
|
|
39
|
+
required: entry.required,
|
|
40
|
+
deprecated: entry.deprecated,
|
|
41
|
+
returns: tags.returns ? yield renderMarkdown(tags.returns) : void 0
|
|
42
|
+
}];
|
|
43
|
+
});
|
|
44
|
+
return function(_x) {
|
|
45
|
+
return _ref2.apply(this, arguments);
|
|
46
|
+
};
|
|
47
|
+
}());
|
|
48
|
+
return /* @__PURE__ */ jsx(TypeTable, { type: Object.fromEntries(yield Promise.all(entries)) }, item.name);
|
|
49
|
+
});
|
|
50
|
+
return function(_x2) {
|
|
51
|
+
return _ref3.apply(this, arguments);
|
|
52
|
+
};
|
|
53
|
+
}());
|
|
54
|
+
});
|
|
55
|
+
return _AutoTypeTable.apply(this, arguments);
|
|
68
56
|
}
|
|
69
57
|
function toJsx(hast) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
return toJsxRuntime(hast, {
|
|
59
|
+
Fragment: runtime.Fragment,
|
|
60
|
+
jsx: runtime.jsx,
|
|
61
|
+
jsxs: runtime.jsxs,
|
|
62
|
+
components: _objectSpread2(_objectSpread2({}, defaultMdxComponents), {}, { img: void 0 })
|
|
63
|
+
});
|
|
76
64
|
}
|
|
77
|
-
function renderTypeDefault(
|
|
78
|
-
|
|
79
|
-
return toJsx(yield renderTypeToHast(type));
|
|
80
|
-
});
|
|
65
|
+
function renderTypeDefault(_x4) {
|
|
66
|
+
return _renderTypeDefault.apply(this, arguments);
|
|
81
67
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
68
|
+
function _renderTypeDefault() {
|
|
69
|
+
_renderTypeDefault = _asyncToGenerator(function* (type) {
|
|
70
|
+
return toJsx(yield renderTypeToHast(type));
|
|
71
|
+
});
|
|
72
|
+
return _renderTypeDefault.apply(this, arguments);
|
|
86
73
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
74
|
+
function renderMarkdownDefault(_x5) {
|
|
75
|
+
return _renderMarkdownDefault.apply(this, arguments);
|
|
76
|
+
}
|
|
77
|
+
function _renderMarkdownDefault() {
|
|
78
|
+
_renderMarkdownDefault = _asyncToGenerator(function* (md) {
|
|
79
|
+
return toJsx(yield renderMarkdownToHast(md));
|
|
80
|
+
});
|
|
81
|
+
return _renderMarkdownDefault.apply(this, arguments);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
export { AutoTypeTable };
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["paramNodes: ParameterNode[]"],"sources":["../../src/ui/auto-type-table.tsx"],"sourcesContent":["import { type ParameterNode, type TypeNode, TypeTable } from 'fumadocs-ui/components/type-table';\nimport { type Jsx, toJsxRuntime } from 'hast-util-to-jsx-runtime';\nimport * as runtime from 'react/jsx-runtime';\nimport defaultMdxComponents from 'fumadocs-ui/mdx';\nimport { renderMarkdownToHast, renderTypeToHast } from '@/markdown';\nimport 'server-only';\nimport type { ReactNode } from 'react';\nimport { type BaseTypeTableProps, type GenerateTypeTableOptions } from '@/lib/type-table';\nimport { type Generator } from '@/lib/base';\nimport type { Nodes } from 'hast';\nimport { parseTags } from '@/lib/parse-tags';\n\nexport type AutoTypeTableProps = BaseTypeTableProps;\n\nexport async function AutoTypeTable({\n generator,\n options = {},\n renderType = renderTypeDefault,\n renderMarkdown = renderMarkdownDefault,\n ...props\n}: AutoTypeTableProps & {\n generator: Generator;\n\n renderMarkdown?: typeof renderMarkdownDefault;\n renderType?: typeof renderTypeDefault;\n options?: GenerateTypeTableOptions;\n}) {\n const output = await generator.generateTypeTable(props, options);\n\n return output.map(async (item) => {\n const entries = item.entries.map(async (entry) => {\n const tags = parseTags(entry.tags);\n const paramNodes: ParameterNode[] = [];\n\n for (const param of tags.params ?? []) {\n paramNodes.push({\n name: param.name,\n description: param.description ? await renderMarkdown(param.description) : undefined,\n });\n }\n\n return [\n entry.name,\n {\n type: await renderType(entry.simplifiedType),\n typeDescription: await renderType(entry.type),\n description: await renderMarkdown(entry.description),\n default: tags.default ? await renderType(tags.default) : undefined,\n parameters: paramNodes,\n required: entry.required,\n deprecated: entry.deprecated,\n returns: tags.returns ? await renderMarkdown(tags.returns) : undefined,\n } as TypeNode,\n ];\n });\n\n return <TypeTable key={item.name} type={Object.fromEntries(await Promise.all(entries))} />;\n });\n}\n\nfunction toJsx(hast: Nodes) {\n return toJsxRuntime(hast, {\n Fragment: runtime.Fragment,\n jsx: runtime.jsx as Jsx,\n jsxs: runtime.jsxs as Jsx,\n components: { ...defaultMdxComponents, img: undefined },\n });\n}\n\nasync function renderTypeDefault(type: string): Promise<ReactNode> {\n return toJsx(await renderTypeToHast(type));\n}\n\nasync function renderMarkdownDefault(md: string): Promise<ReactNode> {\n return toJsx(await renderMarkdownToHast(md));\n}\n"],"mappings":";;;;;;;;;;CAeE;CACA;CACA;CACA;;AAJF,SAAsB,cAAc;;;;qDAYjC;MAZiC,EAClC,WACA,UAAU,EAAE,EACZ,aAAa,mBACb,iBAAiB,gCACd;AAUH,gBAFqB,UAAU,kBAAkB,OAAO,QAAQ,EAElD;4CAAW,MAAS;IAChC,MAAM,UAAU,KAAK,QAAQ;8CAAW,OAAU;;MAChD,MAAM,OAAO,UAAU,MAAM,KAAK;MAClC,MAAMA,aAA8B,EAAE;AAEtC,WAAK,MAAM,yBAAS,KAAK,6DAAU,EAAE,CACnC,YAAW,KAAK;OACd,MAAM,MAAM;OACZ,aAAa,MAAM,oBAAoB,eAAe,MAAM,YAAY,GAAG;OAC5E,CAAC;AAGJ,aAAO,CACL,MAAM,MACN;OACE,YAAY,WAAW,MAAM,eAAe;OAC5C,uBAAuB,WAAW,MAAM,KAAK;OAC7C,mBAAmB,eAAe,MAAM,YAAY;OACpD,SAAS,KAAK,gBAAgB,WAAW,KAAK,QAAQ,GAAG;OACzD,YAAY;OACZ,UAAU,MAAM;OAChB,YAAY,MAAM;OAClB,SAAS,KAAK,gBAAgB,eAAe,KAAK,QAAQ,GAAG;OAC9D,CACF;;qBAvBqC;;;QAwBtC;AAEF,WAAO,oBAAC,aAA0B,MAAM,OAAO,kBAAkB,QAAQ,IAAI,QAAQ,CAAC,IAA/D,KAAK,KAA8D;;mBA3BnE;;;MA4BvB;;;;AAGJ,SAAS,MAAM,MAAa;AAC1B,QAAO,aAAa,MAAM;EACxB,UAAU,QAAQ;EAClB,KAAK,QAAQ;EACb,MAAM,QAAQ;EACd,8CAAiB,6BAAsB,KAAK;EAC7C,CAAC;;AAGJ,SAAe,kBAAkB;;;;yDAAkC;AACjE,SAAO,YAAY,iBAAiB,KAAK,CAAC;;;;AAG5C,SAAe,sBAAsB;;;;2DAAgC;AACnE,SAAO,YAAY,qBAAqB,GAAG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-typescript",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Typescript Integration for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"Docs",
|
|
6
7
|
"NextJs",
|
|
7
|
-
"fumadocs"
|
|
8
|
-
"Docs"
|
|
8
|
+
"fumadocs"
|
|
9
9
|
],
|
|
10
10
|
"homepage": "https://fumadocs.dev",
|
|
11
|
-
"repository": "github:fuma-nama/fumadocs",
|
|
12
11
|
"license": "MIT",
|
|
13
12
|
"author": "Fuma Nama",
|
|
13
|
+
"repository": "github:fuma-nama/fumadocs",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/*"
|
|
16
|
+
],
|
|
14
17
|
"type": "module",
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
15
20
|
"exports": {
|
|
16
21
|
".": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
19
24
|
},
|
|
20
25
|
"./ui": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
26
|
+
"types": "./dist/ui/index.d.ts",
|
|
27
|
+
"import": "./dist/ui/index.js"
|
|
23
28
|
}
|
|
24
29
|
},
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"dist/*"
|
|
29
|
-
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
30
33
|
"dependencies": {
|
|
31
34
|
"estree-util-value-to-estree": "^3.5.0",
|
|
32
35
|
"hast-util-to-estree": "^3.1.3",
|
|
@@ -45,17 +48,19 @@
|
|
|
45
48
|
"@types/node": "24.10.2",
|
|
46
49
|
"@types/react": "^19.2.7",
|
|
47
50
|
"@types/react-dom": "^19.2.3",
|
|
51
|
+
"tsdown": "^0.18.3",
|
|
48
52
|
"typescript": "^5.9.3",
|
|
49
53
|
"unified": "^11.0.5",
|
|
50
54
|
"eslint-config-custom": "0.0.0",
|
|
51
|
-
"fumadocs-core": "16.2
|
|
52
|
-
"fumadocs-ui": "16.2
|
|
55
|
+
"fumadocs-core": "16.4.2",
|
|
56
|
+
"fumadocs-ui": "16.4.2",
|
|
53
57
|
"tsconfig": "0.0.0"
|
|
54
58
|
},
|
|
55
59
|
"peerDependencies": {
|
|
56
60
|
"@types/react": "*",
|
|
57
61
|
"fumadocs-core": "^15.7.0 || ^16.0.0",
|
|
58
62
|
"fumadocs-ui": "^15.7.0 || ^16.0.0",
|
|
63
|
+
"react": "*",
|
|
59
64
|
"typescript": "*"
|
|
60
65
|
},
|
|
61
66
|
"peerDependenciesMeta": {
|
|
@@ -66,13 +71,10 @@
|
|
|
66
71
|
"optional": true
|
|
67
72
|
}
|
|
68
73
|
},
|
|
69
|
-
"publishConfig": {
|
|
70
|
-
"access": "public"
|
|
71
|
-
},
|
|
72
74
|
"scripts": {
|
|
73
|
-
"build": "
|
|
75
|
+
"build": "tsdown",
|
|
74
76
|
"clean": "rimraf dist",
|
|
75
|
-
"dev": "
|
|
77
|
+
"dev": "tsdown --watch",
|
|
76
78
|
"lint": "eslint .",
|
|
77
79
|
"types:check": "tsc --noEmit"
|
|
78
80
|
}
|