UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

264 lines 10.6 kB
import * as React from 'react'; import type { PluggableList } from 'unified'; import type { HighlightedTypesMeta } from '@mui/internal-docs-infra/pipeline/loadServerTypes'; import type { ModuleLinkMapEntry } from "../pipeline/enhanceCodeTypes/scanState.mjs"; import { type TypesJsxOptions } from "./typesToJsx.mjs"; import type { TypesTableProps } from "../useTypes/useTypes.mjs"; /** * Export data structure containing a main type and its related additional types. * Used in the precompute field for structured type data. */ export interface ExportData { /** The main component/hook/function type for this export */ type: HighlightedTypesMeta; /** Related types like .Props, .State, .ChangeEventDetails for this export */ additionalTypes: HighlightedTypesMeta[]; } export type TypesTableMeta = { precompute?: { /** * Structured export data where each export has a main type and related additional types. * Keys are export names like "Root", "Trigger", etc. */ exports: Record<string, ExportData>; /** * Top-level types that are not namespaced under any component part * and not claimed by any variant-only group. */ additionalTypes: HighlightedTypesMeta[]; /** * Types belonging to variant-only groups (variants with no main export). * Keyed by variant name, containing the types from that variant. * Separated from `additionalTypes` to avoid duplication. */ variantOnlyAdditionalTypes?: Record<string, HighlightedTypesMeta[]>; /** * Maps variant names to the type names that originated from that variant. * Used for namespace imports (e.g., `* as Types`) to filter additionalTypes * to only show types from that specific module. */ variantTypeNames?: Record<string, string[]>; singleComponentName?: string; /** * Platform-scoped anchor maps for linking type references in code. * Used by enhanceCodeTypes to create links to type documentation. */ anchorMap?: { js?: Record<string, string>; css?: Record<string, string>; }; }; name?: string; displayName?: string; disableOptimization?: boolean; watchSourceDirectly?: boolean; /** * When true, excludes this component from the parent index page. * The component types will still be processed, but won't be added to the index. */ excludeFromIndex?: boolean; components?: TypesJsxOptions['components']; /** * Override pre component for type code blocks. * When set, overrides the factory-level TypePre. */ TypePre?: TypesJsxOptions['TypePre']; /** * Override pre component for detailed type blocks. * When set, overrides the factory-level DetailedTypePre. */ DetailedTypePre?: TypesJsxOptions['DetailedTypePre']; /** * Override code component for shortType fields. * When set, overrides the factory-level ShortTypeCode. */ ShortTypeCode?: TypesJsxOptions['ShortTypeCode']; /** * Override code component for default value fields. * When set, overrides the factory-level DefaultCode. */ DefaultCode?: TypesJsxOptions['DefaultCode']; /** * Override pre component for raw type formatted code blocks. * When set, overrides the factory-level RawTypePre. */ RawTypePre?: TypesJsxOptions['RawTypePre']; /** * Rehype plugins to run on HAST before converting to JSX. * If set, completely overrides enhancers from AbstractCreateTypesOptions. * Defaults to `[enhanceCodeInline]` when undefined. * Pass an empty array to disable all enhancers. */ enhancers?: PluggableList; /** * Rehype plugins to run on inline HAST fields (shortType and default). * If set, completely overrides enhancersInline from AbstractCreateTypesOptions. * Defaults to `[enhanceCodeInline]` when undefined. * Pass an empty array to disable all inline enhancers. */ enhancersInline?: PluggableList; /** * Controls when expensive detailedType and formattedCode HAST fields are * converted to fully-highlighted JSX. * When set, overrides the factory-level highlightAt. */ highlightAt?: TypesJsxOptions['highlightAt']; /** * Custom component tag name to use instead of `<a>` for type reference links. * When set, enhanceCodeTypes emits elements with this tag name, * adding a `name` property (the matched identifier) alongside `href`. * This enables interactive type popovers via a `TypeRef` component. */ typeRefComponent?: string; /** * Custom component tag name to use instead of a plain HTML element * for property references within type definitions, object literals, function calls, and JSX. * For definitions the element receives `id`, for references it receives `href`. * Both also receive `name` (owner) and `prop` (kebab-case property path). */ typePropRefComponent?: string; /** * Custom component tag name to use instead of a plain HTML element * for function parameter references. * For definitions the element receives `id`, for references it receives `href`. * Both also receive `name` (owner) and `param` (parameter name). */ typeParamRefComponent?: string; /** * Opt-in property linking mode for enhanceCodeTypes. * - `'shallow'`: Link only top-level properties of known owners. * - `'deep'`: Link nested properties with dotted paths (e.g., `address.street-name`). * - `undefined` (default): No property linking. */ linkProps?: 'shallow' | 'deep'; /** * Opt-in function parameter linking for enhanceCodeTypes. * When `true`, links function parameter names to documentation anchors. */ linkParams?: boolean; /** * Opt-in scope-based variable linking for enhanceCodeTypes. * When `true`, links variable references to the type from their declaration * using single-pass scope tracking. */ linkScope?: boolean; /** * Module import linking map for enhanceCodeTypes. * Maps module specifiers to their documentation page and exports. */ moduleLinkMap?: { js?: Record<string, ModuleLinkMapEntry>; css?: Record<string, ModuleLinkMapEntry>; }; /** * Default anchor slug for default/namespace imports when the module entry * in `moduleLinkMap` does not specify a `defaultSlug`. */ defaultImportSlug?: string; }; export type AbstractCreateTypesOptions<T extends {} = {}> = { TypesTable: React.ComponentType<TypesTableProps<T>>; components?: TypesJsxOptions['components']; /** * Required pre component for type code blocks. * Type signatures are not precomputed, so this has a different * contract from `components.pre`. * Can be overridden by TypesTableMeta.TypePre. */ TypePre: TypesJsxOptions['TypePre']; /** * Optional pre component for detailed type blocks. * Falls back to `TypePre` when not provided. * Can be overridden by TypesTableMeta.DetailedTypePre. */ DetailedTypePre?: TypesJsxOptions['DetailedTypePre']; /** * Optional code component for shortType fields. * Falls back to `components.code` when not provided. * Can be overridden by TypesTableMeta.ShortTypeCode. */ ShortTypeCode?: TypesJsxOptions['ShortTypeCode']; /** * Optional code component for default value fields. * Falls back to `components.code` when not provided. * Can be overridden by TypesTableMeta.DefaultCode. */ DefaultCode?: TypesJsxOptions['DefaultCode']; /** * Optional pre component for raw type formatted code blocks. * Falls back to `DetailedTypePre`, then `TypePre` when not provided. * Can be overridden by TypesTableMeta.RawTypePre. */ RawTypePre?: TypesJsxOptions['RawTypePre']; /** * Rehype plugins to run on HAST before converting to JSX. * Can be overridden by TypesTableMeta.enhancers. * Defaults to `[enhanceCodeInline]` when undefined. * Pass an empty array to disable all enhancers. */ enhancers?: PluggableList; /** * Rehype plugins to run on inline HAST fields (shortType and default). * Can be overridden by TypesTableMeta.enhancersInline. * Defaults to `[enhanceCodeInline]` when undefined. * Pass an empty array to disable all inline enhancers. */ enhancersInline?: PluggableList; /** * Custom component tag name to use instead of `<a>` for type reference links. * When set, enhanceCodeTypes emits elements with this tag name, * adding a `name` property (the matched identifier) alongside `href`. * Can be overridden by TypesTableMeta.typeRefComponent. */ typeRefComponent?: string; /** * Custom component tag name for property reference elements. * Can be overridden by TypesTableMeta.typePropRefComponent. */ typePropRefComponent?: string; /** * Custom component tag name for function parameter reference elements. * Can be overridden by TypesTableMeta.typeParamRefComponent. */ typeParamRefComponent?: string; /** * Opt-in property linking mode for enhanceCodeTypes. * Can be overridden by TypesTableMeta.linkProps. */ linkProps?: 'shallow' | 'deep'; /** * Opt-in function parameter linking for enhanceCodeTypes. * Can be overridden by TypesTableMeta.linkParams. */ linkParams?: boolean; /** * Opt-in scope-based variable linking for enhanceCodeTypes. * Can be overridden by TypesTableMeta.linkScope. */ linkScope?: boolean; /** * Module import linking map for enhanceCodeTypes. * Can be overridden by TypesTableMeta.moduleLinkMap. */ moduleLinkMap?: { js?: Record<string, ModuleLinkMapEntry>; css?: Record<string, ModuleLinkMapEntry>; }; /** * Default anchor slug for default/namespace imports. * Can be overridden by TypesTableMeta.defaultImportSlug. */ defaultImportSlug?: string; /** * Controls when expensive detailedType and formattedCode HAST fields are * converted to fully-highlighted JSX. * Can be overridden by TypesTableMeta.highlightAt. */ highlightAt?: TypesJsxOptions['highlightAt']; }; export declare function abstractCreateTypes<T extends {}>(options: AbstractCreateTypesOptions<T>, url: string, meta: TypesTableMeta | undefined, exportName?: string): React.ComponentType<T>; export declare function createTypesFactory<T extends {}>(options: AbstractCreateTypesOptions<T>): (url: string, typeDef: object, meta?: TypesTableMeta | undefined) => React.ComponentType<T>; export declare function createMultipleTypesFactory<T extends {}>(options: AbstractCreateTypesOptions<T>): <K extends Record<string, any>>(url: string, typeDef: K, meta?: TypesTableMeta | undefined) => { types: Record<keyof K, React.ComponentType<T>>; AdditionalTypes: React.ComponentType<T>; };