import { GroupContext, GroupOptions, GroupTicket, GroupTicketInput } from "../createGroup/index.mjs"; import { RuleInput } from "../useRules/index.mjs"; import { FormValidationRule } from "../createForm/index.mjs"; import { MaybeRefOrGetter, ShallowRef } from "vue"; //#region src/composables/createValidation/index.d.ts /** * Input type for validation tickets. * Each ticket represents a single validation rule. */ interface ValidationTicketInput extends GroupTicketInput {} /** * Output type for validation tickets. * Includes selection methods from GroupTicket for enabling/disabling rules. */ type ValidationTicket = GroupTicket; /** * Context for managing validation rules for a single input. * * @template Z The input ticket type. * @template E The output ticket type. */ interface ValidationContext = ValidationTicket> extends Omit, 'register' | 'onboard' | 'reset'> { register: (rule: RuleInput | Partial) => E; onboard: (rules: (RuleInput | Partial)[]) => E[]; /** Run validation against all active (selected) rules. */ validate: (value?: unknown, silent?: boolean) => Promise; /** Reset errors and validation state. Does not affect rule selection. */ reset: () => void; /** Current validation error messages. */ errors: ShallowRef; /** Tri-state: null (not validated), true (valid), false (invalid). */ isValid: ShallowRef; /** Whether async validation is in progress. */ isValidating: ShallowRef; } interface ValidationOptions extends GroupOptions { /** Initial rules to register. */ rules?: RuleInput[]; /** Value source for validate() when called without arguments. */ value?: MaybeRefOrGetter; /** * Form injection key. Must match the parent Form's `namespace`. * * @default 'v0:form' * * @example * ```ts * createValidation({ formNamespace: 'v0:billing' }) * ``` */ formNamespace?: string; } /** * Creates a per-input validation instance. * * Built on `createGroup` — each registered rule becomes a ticket that can be * enabled/disabled via selection methods (`select`, `unselect`, `toggle`). * Only selected (active) rules run during validation. * * @param options The options for the validation instance. * @returns A new validation context. * * @see https://0.vuetifyjs.com/composables/forms/create-validation * * @example * ```ts * import { createValidation } from '@vuetify/v0' * * const validation = createValidation({ * rules: [ * v => !!v || 'Required', * v => /^.+@\S+\.\S+$/.test(String(v)) || 'Invalid email', * ], * }) * * await validation.validate('') * * console.log(validation.errors.value) // ['Required', 'Invalid email'] * * validation.reset() * ``` */ declare function createValidation(_options?: ValidationOptions): ValidationContext; //#endregion export { ValidationContext, ValidationOptions, ValidationTicket, ValidationTicketInput, createValidation };