@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
311 lines • 14.6 kB
text/typescript
import * as React from 'react';
import type { PluggableList } from 'unified';
import type { HighlightedComponentTypeMeta, HighlightedHookTypeMeta, HighlightedFunctionTypeMeta, HighlightedClassTypeMeta, HighlightedRawTypeMeta, HighlightedEnumMemberMeta, HighlightedTypesMeta, HighlightedProperty, HighlightedParameter, HighlightedMethod, HighlightedClassProperty } from "../pipeline/loadServerTypes/index.mjs";
import type { FormattedEnumMember } from "../pipeline/loadServerTypesMeta/index.mjs";
type ComponentMap = Record<string, any>;
export type TypesJsxOptions = {
components?: ComponentMap & {
pre?: React.ComponentType<{
'data-precompute'?: string;
}>;
};
/**
* Required pre component for type code blocks.
* Type signatures are not precomputed, so this has a different
* contract from `components.pre`.
*/
TypePre: React.ComponentType<{
children: React.ReactNode;
}>;
/**
* Optional pre component for detailed type blocks.
* Falls back to `TypePre` when not provided.
*/
DetailedTypePre?: React.ComponentType<{
children: React.ReactNode;
}>;
/**
* Optional code component for shortType fields.
* Falls back to `components.code` when not provided.
*/
ShortTypeCode?: React.ComponentType<{
children?: React.ReactNode;
className?: string;
}>;
/**
* Optional code component for default value fields.
* Falls back to `components.code` when not provided.
*/
DefaultCode?: React.ComponentType<{
children?: React.ReactNode;
className?: string;
}>;
/**
* Optional pre component for raw type formatted code blocks.
* Falls back to `DetailedTypePre`, then `TypePre` when not provided.
*/
RawTypePre?: React.ComponentType<{
children: React.ReactNode;
}>;
/**
* Rehype plugins to run on HAST before converting to JSX.
* These are applied to each HAST node during processing.
*/
enhancers?: PluggableList;
/**
* Rehype plugins to run on inline HAST fields (shortType and default).
* Applied instead of the full enhancers for these compact fields.
*/
enhancersInline?: PluggableList;
/**
* Controls when expensive detailedType and formattedCode HAST fields are
* converted to fully-highlighted JSX.
* - `'init'`: convert immediately during SSG
* - `'hydration'`: server-render a links-only fallback, highlight on client mount
* - `'idle'`: server-render a links-only fallback, highlight when browser is idle
* - `'visible'`: server-render a links-only fallback, highlight when scrolled into view (default)
*/
highlightAt?: 'init' | 'hydration' | 'idle' | 'visible';
};
/**
* An enhanced property with HAST fields converted to React nodes.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedProperty = Omit<HighlightedProperty, 'type' | 'shortType' | 'description' | 'example' | 'detailedType' | 'default' | 'see'> & {
/** Full type signature. Rendered by the `TypePre` component configured in `createTypes()`. */
type: React.ReactNode;
/** Compact type summary. Rendered by the `ShortTypeCode` component configured in `createTypes()`. */
shortType?: React.ReactNode;
/** Default value. Rendered by the `DefaultCode` component configured in `createTypes()`. */
default?: React.ReactNode;
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
/** Markdown example. Rendered using the `components` MDX map configured in `createTypes()`. */
example?: React.ReactNode;
/** Expanded type detail. Rendered by the `DetailedTypePre` component configured in `createTypes()`. */
detailedType?: React.ReactNode;
/** See-also links. Rendered using the `components` MDX map configured in `createTypes()`. */
see?: React.ReactNode;
};
/**
* An enhanced class property with HAST fields converted to React nodes.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedClassProperty = Omit<HighlightedClassProperty, 'type' | 'shortType' | 'description' | 'example' | 'detailedType' | 'default' | 'see'> & {
/** Full type signature. Rendered by the `TypePre` component configured in `createTypes()`. */
type: React.ReactNode;
/** Compact type summary. Rendered by the `ShortTypeCode` component configured in `createTypes()`. */
shortType?: React.ReactNode;
/** Default value. Rendered by the `DefaultCode` component configured in `createTypes()`. */
default?: React.ReactNode;
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
/** Markdown example. Rendered using the `components` MDX map configured in `createTypes()`. */
example?: React.ReactNode;
/** Expanded type detail. Rendered by the `DetailedTypePre` component configured in `createTypes()`. */
detailedType?: React.ReactNode;
/** See-also links. Rendered using the `components` MDX map configured in `createTypes()`. */
see?: React.ReactNode;
};
/**
* An enhanced enum member (data attribute or CSS variable) with HAST fields converted to React nodes.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedEnumMember = Omit<FormattedEnumMember, 'type' | 'description'> & {
/** Full type signature. Rendered by the `TypePre` component configured in `createTypes()`. */
type?: React.ReactNode;
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
/** Default value. Rendered by the `DefaultCode` component configured in `createTypes()`. */
default?: React.ReactNode;
};
/**
* An enhanced function/hook parameter with HAST fields converted to React nodes.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedParameter = Omit<HighlightedParameter, 'type' | 'shortType' | 'description' | 'example' | 'default' | 'detailedType' | 'see'> & {
/** Full type signature. Rendered by the `TypePre` component configured in `createTypes()`. */
type: React.ReactNode;
/** Compact type summary. Rendered by the `ShortTypeCode` component configured in `createTypes()`. */
shortType?: React.ReactNode;
/** Default value. Rendered by the `DefaultCode` component configured in `createTypes()`. */
default?: React.ReactNode;
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
/** Markdown example. Rendered using the `components` MDX map configured in `createTypes()`. */
example?: React.ReactNode;
/** Expanded type detail. Rendered by the `DetailedTypePre` component configured in `createTypes()`. */
detailedType?: React.ReactNode;
/** See-also links. Rendered using the `components` MDX map configured in `createTypes()`. */
see?: React.ReactNode;
};
/**
* Enhanced component type metadata with React nodes instead of HAST.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedComponentTypeMeta = Omit<HighlightedComponentTypeMeta, 'description' | 'props' | 'dataAttributes' | 'cssVariables'> & {
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
props: Record<string, EnhancedProperty>;
dataAttributes: Record<string, EnhancedEnumMember>;
cssVariables: Record<string, EnhancedEnumMember>;
};
export type EnhancedHookParameter = EnhancedParameter | EnhancedProperty;
/** Discriminated union for hook return values. */
export type EnhancedHookReturnValue = {
kind: 'simple';
/** Full type signature. Rendered by the `TypePre` component configured in `createTypes()`. */
type: React.ReactNode;
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
/** Expanded type detail. Rendered by the `DetailedTypePre` component configured in `createTypes()`. */
detailedType?: React.ReactNode;
} | {
kind: 'object';
typeName?: string;
properties: Record<string, EnhancedProperty>;
};
/**
* Enhanced hook type metadata with React nodes instead of HAST.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedHookTypeMeta = Omit<HighlightedHookTypeMeta, 'description' | 'parameters' | 'expandedProperties' | 'returnValue' | 'returnValueDescription' | 'returnValueDetailedType'> & {
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
parameters?: EnhancedParameter[];
expandedProperties?: Record<string, EnhancedProperty>;
returnValue?: EnhancedHookReturnValue;
/** Markdown return value description. Rendered using the `components` MDX map configured in `createTypes()`. */
returnValueDescription?: React.ReactNode;
};
/** Discriminated union for function return values. */
export type EnhancedFunctionReturnValue = {
kind: 'simple';
/** Full type signature. Rendered by the `TypePre` component configured in `createTypes()`. */
type: React.ReactNode;
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
/** Expanded type detail. Rendered by the `DetailedTypePre` component configured in `createTypes()`. */
detailedType?: React.ReactNode;
} | {
kind: 'object';
typeName?: string;
properties: Record<string, EnhancedProperty>;
};
/**
* Enhanced function type metadata with React nodes instead of HAST.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedFunctionTypeMeta = Omit<HighlightedFunctionTypeMeta, 'description' | 'parameters' | 'expandedProperties' | 'returnValue' | 'returnValueDescription' | 'returnValueDetailedType'> & {
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
parameters?: EnhancedParameter[];
expandedProperties?: Record<string, EnhancedProperty>;
returnValue?: EnhancedFunctionReturnValue;
};
/**
* An enhanced class method with HAST fields converted to React nodes.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedMethod = Omit<HighlightedMethod, 'description' | 'parameters' | 'returnValue' | 'returnValueDescription'> & {
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
parameters: EnhancedParameter[];
/** Return type signature. Rendered by the `TypePre` component configured in `createTypes()`. */
returnValue?: React.ReactNode;
/** Markdown return value description. Rendered using the `components` MDX map configured in `createTypes()`. */
returnValueDescription?: React.ReactNode;
};
/**
* Enhanced class type metadata with React nodes instead of HAST.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedClassTypeMeta = Omit<HighlightedClassTypeMeta, 'description' | 'constructorParameters' | 'properties' | 'methods'> & {
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
constructorParameters: EnhancedParameter[];
properties: Record<string, EnhancedClassProperty>;
methods: Record<string, EnhancedMethod>;
};
/** An enhanced raw type enum member. */
export type EnhancedRawEnumMember = Omit<HighlightedEnumMemberMeta, 'description'> & {
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
};
/**
* Enhanced raw/alias type metadata with React nodes instead of HAST.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedRawTypeMeta = Omit<HighlightedRawTypeMeta, 'description' | 'formattedCode' | 'enumMembers' | 'properties'> & {
/** Markdown description. Rendered using the `components` MDX map configured in `createTypes()`. */
description?: React.ReactNode;
/** Formatted code block. Rendered by the `RawTypePre` component configured in `createTypes()`. */
formattedCode: React.ReactNode;
enumMembers?: EnhancedRawEnumMember[];
properties?: Record<string, EnhancedProperty>;
};
/**
* Discriminated union of all enhanced type kinds.
* The components rendering each field are configured in `createTypes()`.
*/
export type EnhancedTypesMeta = {
type: 'component';
name: string;
slug?: string;
aliases?: string[];
data: EnhancedComponentTypeMeta;
} | {
type: 'hook';
name: string;
slug?: string;
aliases?: string[];
data: EnhancedHookTypeMeta;
} | {
type: 'function';
name: string;
slug?: string;
aliases?: string[];
data: EnhancedFunctionTypeMeta;
} | {
type: 'class';
name: string;
slug?: string;
aliases?: string[];
data: EnhancedClassTypeMeta;
} | {
type: 'raw';
name: string;
slug?: string;
aliases?: string[];
data: EnhancedRawTypeMeta;
};
/**
* Enhanced export data with JSX nodes instead of HAST.
*/
export interface EnhancedExportData {
/** The main component/hook/function type for this export */
type: EnhancedTypesMeta;
/** Related types like .Props, .State, .ChangeEventDetails for this export */
additionalTypes: EnhancedTypesMeta[];
}
/**
* Process a single export's type data to JSX.
* More efficient when you only need one export.
* @param exportData The export's type and namespaced additional types (undefined when only type exports exist)
* @param globalAdditionalTypes Top-level non-namespaced types (only included for single component mode)
* @param options JSX component options
* @param includeGlobalAdditionalTypes Whether to include global additional types (default: true for createTypes, false for createMultipleTypes)
*/
export declare function typeToJsx(exportData: {
type: HighlightedTypesMeta;
additionalTypes: HighlightedTypesMeta[];
} | undefined, globalAdditionalTypes: HighlightedTypesMeta[] | undefined, options: TypesJsxOptions, includeGlobalAdditionalTypes?: boolean): {
type: EnhancedTypesMeta | undefined;
additionalTypes: EnhancedTypesMeta[];
};
/**
* Process only additional types to JSX.
* Used for the AdditionalTypes component that only renders top-level non-namespaced types.
*/
export declare function additionalTypesToJsx(additionalTypes: HighlightedTypesMeta[] | undefined, options: TypesJsxOptions): EnhancedTypesMeta[];
export {};