@hashbrownai/core
Version:
Runtime helpers for Hashbrown AI
41 lines • 1.65 kB
TypeScript
import { s } from '../schema';
import { Prettify } from './types';
type Component<T = any> = {
new (...args: any[]): T;
} | ((props: T) => any);
type AngularSignalLike<T> = () => T;
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>;
interface ExposedComponent<T extends Component<unknown>> {
component: T;
name: string;
description: string;
children?: 'any' | ExposedComponent<any>[] | false;
props?: ComponentPropSchema<T>;
}
type ComponentTree = {
$tagName: string;
$children: ComponentTree[];
$props: Record<string, any>;
};
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.
*/
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.
*
* @param {ExposedComponent<any>[]} components - An array of components to create schemas for.
* @returns {s.ObjectType<ComponentTree>} - A schema representing the structure of the components.
*/
export declare function createComponentSchema(components: ExposedComponent<any>[]): s.ObjectType<ComponentTreeSchema>;
export {};
//# sourceMappingURL=expose-component.d.ts.map