@xraph/smartform-react
Version:
React library for rendering and validating SmartForms with shadcn components
42 lines (41 loc) • 1.19 kB
TypeScript
export type TemplateContext = Record<string, any>;
export type TemplateFunction = (args: any[]) => any | Promise<any>;
export interface VariableSuggestion {
expr: string;
type: string;
description: string;
value?: any;
children?: string[];
isNested?: boolean;
arrayInfo?: ArrayInfo;
isFunction?: boolean;
signature?: string;
}
export interface ArrayInfo {
itemType: string;
sampleAccess: string;
}
export interface TemplatePart {
evaluate(registry: VariableRegistry, context: TemplateContext): any | Promise<any>;
}
export interface TemplateExpression {
raw: string;
parts: TemplatePart[];
}
export declare class VariableRegistry {
variables: Map<string, any>;
functions: Map<string, TemplateFunction>;
constructor();
registerVariable(name: string, value: any): void;
getVariable(path: string): {
value: any;
found: boolean;
};
registerFunction(name: string, fn: TemplateFunction): void;
getFunction(name: string): {
func: TemplateFunction | undefined;
found: boolean;
};
registerStandardFunctions(): void;
generateVariableSuggestions(): VariableSuggestion[];
}