@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
104 lines • 4.59 kB
text/typescript
import type * as tae from 'typescript-api-extractor';
import { type FormattedProperty, type FormatInlineTypeOptions, type DescriptionReplacement } from "./format.mjs";
import { type TypeRewriteContext } from "./rewriteTypes.mjs";
import type { ExternalTypesCollector } from "./externalTypes.mjs";
import type { HastRoot } from "../../CodeHighlighter/types.mjs";
/**
* Information about a re-exported type.
*/
export interface ReExportInfo {
/** Display name of the component (e.g., "Trigger" from "Accordion.Trigger") */
name: string;
/** Anchor slug for linking (e.g., "#trigger") */
slug: string;
/** What kind of type this re-exports */
suffix: 'props' | 'css-variables' | 'data-attributes';
}
/**
* Formatted raw type metadata with the type declaration as a formatted code string.
*
* Used for types that don't fit into component/hook/function categories,
* such as type aliases, interfaces, and enums.
*
* Type highlighting (formattedCode → HAST) is deferred to the loadServerTypes
* stage via highlightTypesMeta() after highlightTypes().
*/
export type RawTypeMeta = {
/** Display name for this type (may include dots like "Component.Root.State") */
name: string;
/** Description parsed from JSDoc as HAST */
description?: HastRoot;
/** Plain text version of description for markdown generation */
descriptionText?: string;
/**
* The formatted type declaration as plain text (e.g., "type ButtonProps = { ... }").
* Will be highlighted to HAST in loadServerTypes.
*/
formattedCode: string;
/**
* For enum types, the individual members with their values and descriptions.
* When present, indicates this type should be rendered as an enum table.
*/
enumMembers?: EnumMemberMeta[];
/**
* For re-exports, information about the component this type re-exports from.
* When set, indicates this should be rendered as a link to the component.
*/
reExportOf?: ReExportInfo;
/**
* For DataAttributes types, the component name this type belongs to.
*/
dataAttributesOf?: string;
/**
* For CssVars types, the component name this type belongs to.
*/
cssVarsOf?: string;
/**
* For object types, the individual properties with their types and descriptions.
* Used by the enhancement stage to convert named return type references into property tables.
*/
properties?: Record<string, FormattedProperty>;
};
/**
* Enum member metadata for raw type enum rendering.
*/
export interface EnumMemberMeta {
name: string;
value?: string | number;
description?: HastRoot;
descriptionText?: string;
}
export interface FormatRawOptions {
/** Options for inline type formatting (e.g., unionPrintWidth) */
formatting?: FormatInlineTypeOptions;
/** Collector for external types discovered during formatting */
externalTypes?: ExternalTypesCollector;
/** Pattern/replacement pairs to apply to descriptions */
descriptionReplacements?: DescriptionReplacement[];
}
/**
* Formats a raw type export into a structured metadata object with formatted code.
*
* @param exportNode - The export node from typescript-api-extractor
* @param displayName - The display name (e.g., "Component.Root.State")
* @param typeNameMap - Map for transforming type names
* @param rewriteContext - Context for type string rewriting
* @param options - Formatting options
* @returns Formatted raw type metadata with the type declaration as formatted code
*/
export declare function formatRawData(exportNode: tae.ExportNode, displayName: string, typeNameMap: Record<string, string>, rewriteContext: TypeRewriteContext, _options?: FormatRawOptions): Promise<RawTypeMeta>;
/**
* Type guard to check if an export node represents a "raw" type that should be
* formatted as a code block (i.e., not a component, hook, or function).
*
* @param exportNode - The export node to check
* @param isComponent - Whether the node has been identified as a component
* @param isHook - Whether the node has been identified as a hook
* @param isFunction - Whether the node has been identified as a function
* @returns true if the export should be formatted as a raw type
*/
export declare function isRawType(exportNode: tae.ExportNode, isComponent: boolean, isHook: boolean, isFunction: boolean): boolean;
/**
* Formats re-export information for a type that re-exports another component's props.
*/
export declare function formatReExportData(exportNode: tae.ExportNode, displayName: string, reExportOf: ReExportInfo, typeNameMap: Record<string, string>, rewriteContext: TypeRewriteContext): Promise<RawTypeMeta>;