import { ID } from "../../types/index.mjs"; import { ContextTrinity } from "../createTrinity/index.mjs"; import { RegistryContext, RegistryOptions, RegistryTicket, RegistryTicketInput } from "../createRegistry/index.mjs"; import { ValidationContext } from "../createValidation/index.mjs"; import { ComputedRef, MaybeRefOrGetter } from "vue"; //#region src/composables/createForm/index.d.ts type FormValidationResult = string | boolean | Promise; type FormValidationRule = (value: unknown) => FormValidationResult; type FormValue = ValidationContext; /** * User-facing input shape for form tickets. */ interface FormTicketInput extends RegistryTicketInput {} /** * A registered validation in the form registry. * * @template Z The input ticket type that extends FormTicketInput. */ type FormTicket = RegistryTicket & Z; /** * Context for coordinating validation across multiple fields. * * @template Z The input ticket type. * @template E The output ticket type. */ interface FormContext = FormTicket> extends Omit, 'register' | 'onboard'> { /** Register a validation context with the form. */ register: (registration: Partial & { value: FormValue; }) => E; /** Submit: validate specific fields or all. */ submit: (id?: ID | ID[]) => Promise; /** Reset all registered validations. */ reset: () => void; /** Whether the form is disabled. Components can read this to conditionally disable inputs. */ disabled: MaybeRefOrGetter; /** Whether the form is readonly. Components can read this to conditionally disable inputs. */ readonly: MaybeRefOrGetter; /** Aggregate: true if all validations valid, false if any invalid, null if any unvalidated. */ isValid: ComputedRef; /** Aggregate: true if any validation is in progress. */ isValidating: ComputedRef; } interface FormOptions extends RegistryOptions { /** Whether the form starts disabled. */ disabled?: MaybeRefOrGetter; /** Whether the form starts readonly. */ readonly?: MaybeRefOrGetter; } interface FormContextOptions extends FormOptions { namespace?: string; } /** * Creates a new form instance. * * A form is a pure registry of validation contexts. Validations register * themselves via `useForm()` injection. The form coordinates submit, reset, * and aggregate state across all registered validations. * * @param options The options for the form instance. * @returns A new form context. * * @see https://0.vuetifyjs.com/composables/forms/create-form * * @example * ```ts * import { createForm, createValidation } from '@vuetify/v0' * import { shallowRef } from 'vue' * * const form = createForm() * * // Each validation is one input — form is just the coordinator * const email = shallowRef('') * const validation = createValidation({ * value: email, * rules: ['required', 'email'], * }) * * form.register({ value: validation }) * * await form.submit() * form.reset() * ``` */ declare function createForm(_options?: FormOptions): FormContext; /** * Creates a new form context using the Trinity pattern. * * @param options The options for the form context. * @returns A Trinity tuple: [useFormContext, provideFormContext, formContext] * * @see https://0.vuetifyjs.com/composables/forms/create-form * * @example * ```ts * import { createFormContext } from '@vuetify/v0' * * export const [useMyForm, provideMyForm, myForm] = createFormContext() * ``` */ declare function createFormContext(_options?: FormContextOptions): ContextTrinity; /** * Returns the current form instance. * * @param namespace The namespace for the form context. Defaults to `'v0:form'`. * @returns The current form instance, or undefined if not provided. * * @see https://0.vuetifyjs.com/composables/forms/create-form * * @example * ```vue * * ``` */ declare function useForm = FormTicket, R extends FormContext = FormContext>(namespace?: string): R | undefined; //#endregion export { FormContext, FormContextOptions, FormOptions, FormTicket, FormTicketInput, FormValidationResult, FormValidationRule, FormValue, createForm, createFormContext, useForm };