import { ReadonlyStore } from '@tanstack/store'; import { Updater } from './utils.js'; import { FormApi, FormAsyncValidateOrFn, FormValidateOrFn } from './FormApi.js'; import { AnyFieldMetaBase, FieldOptions } from './FieldApi.js'; import { DeepKeys, DeepKeysOfType, DeepValue, FieldsMap } from './util-types.js'; import { FieldManipulator, UpdateMetaOptions, ValidationCause } from './types.js'; export type AnyFieldGroupApi = FieldGroupApi; export interface FieldGroupState { /** * The current values of the field group */ values: TFieldGroupData; } /** * An object representing the options for a field group. */ export interface FieldGroupOptions | FieldsMap, in out TOnMount extends undefined | FormValidateOrFn, in out TOnChange extends undefined | FormValidateOrFn, in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn, in out TOnBlur extends undefined | FormValidateOrFn, in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn, in out TOnSubmit extends undefined | FormValidateOrFn, in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, in out TOnDynamic extends undefined | FormValidateOrFn, in out TOnDynamicAsync extends undefined | FormAsyncValidateOrFn, in out TOnServer extends undefined | FormAsyncValidateOrFn, in out TSubmitMeta = never> { form: FormApi | FieldGroupApi; /** * The path to the field group data. */ fields: TFields; /** * The expected subsetValues that the form must provide. */ defaultValues?: TFieldGroupData; /** * onSubmitMeta, the data passed from the handleSubmit handler, to the onSubmit function props */ onSubmitMeta?: TSubmitMeta; } export declare class FieldGroupApi | FieldsMap, in out TOnMount extends undefined | FormValidateOrFn, in out TOnChange extends undefined | FormValidateOrFn, in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn, in out TOnBlur extends undefined | FormValidateOrFn, in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn, in out TOnSubmit extends undefined | FormValidateOrFn, in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, in out TOnDynamic extends undefined | FormValidateOrFn, in out TOnDynamicAsync extends undefined | FormAsyncValidateOrFn, in out TOnServer extends undefined | FormAsyncValidateOrFn, in out TSubmitMeta = never> implements FieldManipulator { /** * The form that called this field group. */ readonly form: FormApi; readonly fieldsMap: TFields; /** * Get the true name of the field. Not required within `Field` or `AppField`. * @private */ getFormFieldName: >(subfield: TField) => DeepKeys; /** * Get the field options with the true form DeepKeys for validators * @private */ getFormFieldOptions: >(props: TOptions) => TOptions; store: ReadonlyStore>; get state(): FieldGroupState; /** * Constructs a new `FieldGroupApi` instance with the given form options. */ constructor(opts: FieldGroupOptions); /** * Mounts the field group instance to listen to value changes. * * TODO: Remove */ mount: () => () => void; /** * Validates the children of a specified array in the form starting from a given index until the end using the correct handlers for a given validation type. */ validateArrayFieldsStartingFrom: >(field: TField, index: number, cause: ValidationCause) => Promise; /** * Validates a specified field in the form using the correct handlers for a given validation type. */ validateField: >(field: TField, cause: ValidationCause) => any[] | Promise; /** * Handles the form submission, performs validation, and calls the appropriate onSubmit or onSubmitInvalid callbacks. */ handleSubmit(): Promise; handleSubmit(submitMeta: TSubmitMeta): Promise; /** * Gets the value of the specified field. */ getFieldValue: >(field: TField) => DeepValue; /** * Gets the metadata of the specified field. */ getFieldMeta: >(field: TField) => import('./FieldApi.js').AnyFieldMeta | undefined; /** * Updates the metadata of the specified field. */ setFieldMeta: >(field: TField, updater: Updater) => void; /** * Sets the value of the specified field and optionally updates the touched state. */ setFieldValue: >(field: TField, updater: Updater>, opts?: UpdateMetaOptions) => void; /** * Delete a field and its subfields. */ deleteField: >(field: TField) => void; /** * Pushes a value into an array field. */ pushFieldValue: >(field: TField, value: DeepValue extends any[] ? DeepValue[number] : never, opts?: UpdateMetaOptions) => void; /** * Insert a value into an array field at the specified index. */ insertFieldValue: >(field: TField, index: number, value: DeepValue extends any[] ? DeepValue[number] : never, opts?: UpdateMetaOptions) => Promise; /** * Replaces a value into an array field at the specified index. */ replaceFieldValue: >(field: TField, index: number, value: DeepValue extends any[] ? DeepValue[number] : never, opts?: UpdateMetaOptions) => Promise; /** * Removes a value from an array field at the specified index. */ removeFieldValue: >(field: TField, index: number, opts?: UpdateMetaOptions) => Promise; /** * Swaps the values at the specified indices within an array field. */ swapFieldValues: >(field: TField, index1: number, index2: number, opts?: UpdateMetaOptions) => void; /** * Moves the value at the first specified index to the second specified index within an array field. */ moveFieldValues: >(field: TField, index1: number, index2: number, opts?: UpdateMetaOptions) => void; clearFieldValues: >(field: TField, opts?: UpdateMetaOptions) => void; /** * Resets the field value and meta to default state */ resetField: >(field: TField) => void; validateAllFields: (cause: ValidationCause) => Promise; }