@conform-to/react
Version:
Conform view adapter for react
70 lines • 4.16 kB
TypeScript
import { type FieldName, type ValidationAttributes, type Serialize } from '@conform-to/dom/future';
import type { FieldMetadata, Fieldset, FormContext, FormMetadata, FormState, FormAction, UnknownIntent, ActionHandler, CustomMetadataDefinition } from './types';
export declare function initializeState<ErrorShape>(options?: {
defaultValue?: Record<string, unknown> | null | undefined;
resetKey?: string | undefined;
}): FormState<ErrorShape>;
/**
* Updates form state based on action type:
* - Client actions: update target value and client errors
* - Server actions: update server errors and clear client errors, with optional target value
* - Initialize: set initial server value
*/
export declare function updateState<ErrorShape>(state: FormState<ErrorShape>, action: FormAction<ErrorShape, UnknownIntent | null, {
handlers: Record<string, ActionHandler>;
reset: (defaultValue?: Record<string, unknown> | null | undefined) => FormState<ErrorShape>;
}>): FormState<ErrorShape>;
/**
* Removes list keys where array length has changed to force regeneration.
* Minimizes UI state loss by only invalidating keys when necessary.
*/
export declare function pruneListKeys(listKeys: Record<string, string[]>, targetValue: Record<string, unknown>): Record<string, string[]>;
export declare function getDefaultValue(context: FormContext<any>, name: string, serialize?: Serialize): string;
export declare function getDefaultOptions(context: FormContext<any>, name: string, serialize?: Serialize): string[];
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 | undefined;
customize?: CustomMetadataDefinition | undefined;
}): FormMetadata<ErrorShape>;
export declare function getField<FieldShape, ErrorShape = string>(context: FormContext<ErrorShape>, options: {
name: FieldName<FieldShape>;
serialize?: Serialize | undefined;
customize?: CustomMetadataDefinition | undefined;
key?: string | undefined;
}): FieldMetadata<FieldShape, 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> | undefined;
serialize?: Serialize | undefined;
customize?: CustomMetadataDefinition | undefined;
}): Fieldset<FieldShape, 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 | undefined;
customize?: CustomMetadataDefinition | undefined;
}): FieldMetadata<[
FieldShape
] extends [Array<infer ItemShape> | null | undefined] ? ItemShape : unknown, ErrorShape>[];
//# sourceMappingURL=state.d.ts.map