import type { FieldNode, RecordField, VariantField, TupleField, OptionalField, VectorField, BlobField, RecursiveField, PrincipalField, NumberField, BooleanField, NullField, TextField, UnknownField, ArgumentsMeta, ArgumentsServiceMeta } from "./types.js"; import { IDL } from "@icp-sdk/core/candid"; import { BaseActor, FunctionName } from "@ic-reactor/core"; import * as z from "zod"; export * from "./types.js"; export * from "./helpers.js"; export { checkTextFormat, checkNumberFormat } from "../constants.js"; /** * FieldVisitor generates metadata for form input fields from Candid IDL types. * * ## Design Principles * * 1. **Works with raw IDL types** - generates metadata at initialization time * 2. **No value dependencies** - metadata is independent of actual values * 3. **Form-framework agnostic** - output can be used with TanStack, React Hook Form, etc. * 4. **Efficient** - single traversal, no runtime type checking * 5. **TanStack Form optimized** - name paths compatible with TanStack Form patterns * * ## Output Structure * * Each field has: * - `type`: The field type (record, variant, text, number, etc.) * - `label`: Raw label from Candid * - `displayLabel`: Human-readable formatted label * - `name`: TanStack Form compatible path (e.g., "[0]", "[0].owner", "tags[1]") * - `component`: Suggested component type for rendering * - `renderHint`: Hints for UI rendering strategy * - `defaultValue`: Initial value for the form * - `schema`: Zod schema for validation * - Type-specific properties (options for variant, fields for record, etc.) * - Helper methods for dynamic forms (getOptionDefault, getItemDefault, etc.) * * ## Usage with TanStack Form * * @example * ```typescript * import { useForm } from '@tanstack/react-form' * import { FieldVisitor } from '@ic-reactor/candid' * * const visitor = new FieldVisitor() * const serviceMeta = service.accept(visitor, null) * const methodMeta = serviceMeta["icrc1_transfer"] * * const form = useForm({ * defaultValues: methodMeta.defaultValue, * validators: { onBlur: methodMeta.schema }, * onSubmit: async ({ value }) => { * await actor.icrc1_transfer(...value) * } * }) * * // Render fields dynamically * methodMeta.fields.map((field, index) => ( * * {(fieldApi) => } * * )) * ``` */ export declare class FieldVisitor extends IDL.Visitor | ArgumentsServiceMeta> { recursiveSchemas: Map; private nameStack; /** * Execute function with a name segment pushed onto the stack. * Automatically manages stack cleanup. */ private withName; /** * Get the current full name path for form binding. * Returns empty string for root level. */ private currentName; visitService(t: IDL.ServiceClass): ArgumentsServiceMeta; visitFunc(t: IDL.FuncClass, functionName: FunctionName): ArgumentsMeta; visitRecord(_t: IDL.RecordClass, fields_: Array<[string, IDL.Type]>, label: string): RecordField; visitVariant(_t: IDL.VariantClass, fields_: Array<[string, IDL.Type]>, label: string): VariantField; visitTuple(_t: IDL.TupleClass, components: IDL.Type[], label: string): TupleField; visitOpt(_t: IDL.OptClass, ty: IDL.Type, label: string): OptionalField; visitVec(_t: IDL.VecClass, ty: IDL.Type, label: string): VectorField | BlobField; visitRec(_t: IDL.RecClass, ty: IDL.ConstructType, label: string): RecursiveField; visitPrincipal(_t: IDL.PrincipalClass, label: string): PrincipalField; visitText(_t: IDL.TextClass, label: string): TextField; /** * Generate format-specific input props for text fields. */ private getTextInputProps; /** * Generate format-specific zod schema for text fields. */ private getTextSchema; visitBool(_t: IDL.BoolClass, label: string): BooleanField; visitNull(_t: IDL.NullClass, label: string): NullField; private visitNumberType; visitInt(_t: IDL.IntClass, label: string): NumberField | TextField; visitNat(_t: IDL.NatClass, label: string): NumberField | TextField; visitFloat(t: IDL.FloatClass, label: string): NumberField; visitFixedInt(t: IDL.FixedIntClass, label: string): NumberField | TextField; visitFixedNat(t: IDL.FixedNatClass, label: string): NumberField | TextField; visitType(_t: IDL.Type, label: string): UnknownField; } //# sourceMappingURL=index.d.ts.map