import type { OnLoadArgs, OnLoadResult, } from '@umijs/bundler-utils/compiled/esbuild'; import type { IModify } from '@umijs/core'; import type { AssetsPackage, ExampleBlockAsset } from 'dumi-assets-types'; import type { Element } from 'hast'; import type { IApi as IUmiApi, defineConfig as defineUmiConfig } from 'umi'; import type { IDumiDemoProps, ILocalesConfig, IThemeConfig } from './theme-api'; type Subset = { [attr in keyof K]?: K[attr] extends Array ? K[attr] : K[attr] extends (...args: any[]) => any | undefined ? K[attr] : K[attr] extends object ? Subset : K[attr] extends object | null ? Subset | null : K[attr] extends object | null | undefined ? Subset | null | undefined : K[attr]; }; type NoStringIndex = { [K in keyof T as string extends K ? never : K]: T[K]; }; type IUmiConfig = Omit< NoStringIndex[0]>, 'resolve' | 'extraRemarkPlugins' | 'extraRehypePlugins' | 'themeConfig' >; type UnifiedPluginConfig = | string | ((...args: any[]) => any) | [string | ((...args: any[]) => any), object]; export interface IDumiExtendsConfig { resolve: { docDirs: (string | { type?: string; dir: string })[]; atomDirs: { type: string; subType?: string; dir: string }[]; codeBlockMode: 'active' | 'passive'; entryFile?: string; forceKebabCaseRouting: boolean; }; locales: ILocalesConfig; themeConfig: IThemeConfig; autoAlias?: boolean; extraRemarkPlugins?: UnifiedPluginConfig[]; extraRehypePlugins?: UnifiedPluginConfig[]; } export type IDumiConfig = Omit & IDumiExtendsConfig; export type IDumiUserConfig = Subset> & { locales?: | Exclude[] | Omit, 'base'>[]; [key: string]: any; }; export interface IDumiTechStackOnBlockLoadResult { content: string; type: Required['loader']; } export type IDumiTechStackOnBlockLoadArgs = OnLoadArgs & { entryPointCode: string; filename: string; }; export interface IDumiTechStackRuntimeOpts { preflightPath?: string; rendererPath?: string; compilePath?: string; pluginPath?: string; } export abstract class IDumiTechStack { abstract name: string; abstract runtimeOpts?: IDumiTechStackRuntimeOpts; abstract isSupported(node: Element, lang: string): boolean; abstract transformCode( raw: string, opts: { type: 'external' | 'code-block'; fileAbsPath: string }, ): string; abstract generateMetadata?( asset: ExampleBlockAsset, opts: { type: Parameters[1]['type']; mdAbsPath: string; fileAbsPath?: string; entryPointCode?: string; }, ): Promise | ExampleBlockAsset; abstract generatePreviewerProps?( props: IDumiDemoProps['previewerProps'], opts: Parameters>[1], ): | Promise | IDumiDemoProps['previewerProps']; abstract generateSources?( source: Record, opts: Parameters>[1], ): Promise> | Record; abstract onBlockLoad?( args: IDumiTechStackOnBlockLoadArgs, ): IDumiTechStackOnBlockLoadResult | null; } export type IApi = IUmiApi & { config: IDumiConfig & { [key: string]: any }; userConfig: IDumiUserConfig; service: IUmiApi['service'] & { themeData: any; atomParser: any; }; registerTechStack: (fn: () => IDumiTechStack) => void; modifyTheme: IModify; addContentTab: (fn: () => any) => void; modifyAssetsMetadata: IModify; getAssetsMetadata?: () => Promise; };