UNPKG

@hashbrownai/core

Version:

Runtime helpers for Hashbrown AI

61 lines 1.76 kB
import { s } from '../schema'; import { Prettify } from '../utils'; /** * @public */ export type Component<T = any> = { new (...args: any[]): T; } | ((props: T) => any); /** * @public */ export type AngularSignalLike<T> = () => T; /** * @public */ export type ComponentPropSchema<T> = Prettify<T extends Component<infer P> ? { [K in keyof P]?: P[K] extends AngularSignalLike<infer U> ? s.Schema<U> : never; } : T extends Component<infer P> ? { [K in keyof P]?: s.Schema<P[K]>; } : never>; /** * @public */ export interface ExposedComponent<T extends Component<unknown>> { component: T; name: string; description: string; children?: 'any' | 'text' | ExposedComponent<any>[] | false; props?: ComponentPropSchema<T>; } /** * @public */ export type ComponentTree = { $tag: string; $children: ComponentTree[]; $props: Record<string, any>; }; /** * @public */ export type ComponentTreeSchema = { [k in keyof ComponentTree]: s.Schema<ComponentTree[k]>; }; /** * Flattens a component hierarchy into a map of component names to their definitions. * This includes nested components defined in the children property. * * @public */ export declare function flattenComponents(components: ExposedComponent<any>[]): Map<string, ExposedComponent<any>>; /** * Creates a schema for a list of exposed components, allowing for the definition * of component structures and their relationships. * * @public * @param components - An array of components to create schemas for. * @returns A schema representing the structure of the components. */ export declare function createComponentSchema(components: ExposedComponent<any>[]): s.ObjectType<ComponentTreeSchema>; //# sourceMappingURL=expose-component.d.ts.map