UNPKG

fumadocs-typescript

Version:

Typescript Integration for Fumadocs

56 lines (55 loc) 1.95 kB
import { n as markdownRenderer, t as parseTags } from "../parse-tags-Cikh_NrX.js"; import { TypeTable } from "fumadocs-ui/components/type-table"; import { toJsxRuntime } from "hast-util-to-jsx-runtime"; import * as JsxRuntime from "react/jsx-runtime"; import { jsx } from "react/jsx-runtime"; import defaultMdxComponents from "fumadocs-ui/mdx"; //#region src/ui/auto-type-table.tsx async function AutoTypeTable({ generator, options, renderType, renderMarkdown, shiki, name, path, type, ...props }) { if (!renderType || !renderMarkdown) { const renderer = markdownRenderer(shiki); renderType ??= async (v) => toJsx(await renderer.renderTypeToHast(v)); renderMarkdown ??= async (v) => toJsx(await renderer.renderMarkdownToHast(v)); } return (await generator.generateTypeTable({ name, path, type }, options)).map(async (item) => { const entries = item.entries.map(async (entry) => { const tags = parseTags(entry.tags); const paramNodes = []; for (const param of tags.params ?? []) paramNodes.push({ name: param.name, description: param.description ? await renderMarkdown(param.description) : void 0 }); return [entry.name, { type: await renderType(entry.simplifiedType), typeDescription: await renderType(entry.type), typeDescriptionLink: entry.typeHref, description: await renderMarkdown(entry.description), default: tags.default ? await renderType(tags.default) : void 0, parameters: paramNodes, required: entry.required, deprecated: entry.deprecated, returns: tags.returns ? await renderMarkdown(tags.returns) : void 0 }]; }); return /* @__PURE__ */ jsx(TypeTable, { id: `type-table-${item.id}`, type: Object.fromEntries(await Promise.all(entries)), ...props }, item.name); }); } function toJsx(hast) { return toJsxRuntime(hast, { ...JsxRuntime, components: { ...defaultMdxComponents, img: void 0 } }); } //#endregion export { AutoTypeTable };