@conform-to/react
Version:
Conform view adapter for react
58 lines • 3.49 kB
TypeScript
import { type ValidationAttributes, type Serialize } from '@conform-to/dom/future';
import type { DefaultMetadata, FieldMetadata, FieldName, Fieldset, FormContext, FormMetadata, FormState, FormAction, UnknownIntent, ActionHandler } from './types';
export declare function initializeState<ErrorShape>(resetKey?: string): FormState<ErrorShape>;
/**
* Updates form state based on action type:
* - Client actions: update intended value and client errors
* - Server actions: update server errors and clear client errors
* - Initialize: set initial intended value
*/
export declare function updateState<ErrorShape>(state: FormState<ErrorShape>, action: FormAction<ErrorShape, UnknownIntent | null, {
handlers: Record<string, ActionHandler>;
reset: () => FormState<ErrorShape>;
}>): FormState<ErrorShape>;
export declare function getDefaultValue(context: FormContext<any>, name: string, serialize?: Serialize): string | undefined;
export declare function getDefaultOptions(context: FormContext<any>, name: string, serialize?: Serialize): string[] | undefined;
export declare function isDefaultChecked(context: FormContext<any>, name: string, serialize?: Serialize): boolean;
/**
* Determine if the field is touched
*
* This checks if the field is in the list of touched fields,
* or if there is any child field that is touched, i.e. form / fieldset
*/
export declare function isTouched(state: FormState<any>, name?: string): boolean;
export declare function getDefaultListKey(prefix: string, initialValue: Record<string, unknown> | null, name: string): string[];
export declare function getListKey(context: FormContext<any>, name: string): string[];
export declare function getErrors<ErrorShape>(state: FormState<ErrorShape>, name?: string): ErrorShape[] | undefined;
export declare function getFieldErrors<ErrorShape>(state: FormState<ErrorShape>, name?: string): Record<string, ErrorShape[]>;
export declare function isValid(state: FormState<any>, name?: string): boolean;
/**
* Gets validation constraint for a field, with fallback to parent array patterns.
* e.g. "array[0].key" falls back to "array[].key" if specific constraint not found.
*/
export declare function getConstraint(context: FormContext<any>, name: string): ValidationAttributes | undefined;
export declare function getFormMetadata<ErrorShape>(context: FormContext<ErrorShape>, options: {
serialize: Serialize;
}): FormMetadata<ErrorShape, DefaultMetadata<ErrorShape>>;
export declare function getField<FieldShape, ErrorShape = string>(context: FormContext<ErrorShape>, options: {
name: FieldName<FieldShape>;
serialize: Serialize;
key?: string;
}): FieldMetadata<FieldShape, DefaultMetadata<ErrorShape>>;
/**
* Creates a proxy that dynamically generates field objects when properties are accessed.
*/
export declare function getFieldset<FieldShape = Record<string, any>, ErrorShape = string>(context: FormContext<ErrorShape>, options: {
name?: FieldName<FieldShape>;
serialize: Serialize;
}): Fieldset<FieldShape, DefaultMetadata<ErrorShape>>;
/**
* Creates an array of field objects for list/array inputs
*/
export declare function getFieldList<FieldShape = Array<any>, ErrorShape = string>(context: FormContext<ErrorShape>, options: {
name: FieldName<FieldShape>;
serialize: Serialize;
}): FieldMetadata<[
FieldShape
] extends [Array<infer ItemShape> | null | undefined] ? ItemShape : unknown, DefaultMetadata<ErrorShape>>[];
//# sourceMappingURL=state.d.ts.map