/** * Check whether a global save or a scoped validation for an element has been attempted. * @param {Element | null} [element] - Field element to check for a scoped attempt. * @returns {boolean} Whether a save has been attempted. */ export function hasAttemptedSave(element?: Element | null): boolean; /** * Check whether an element is rendered and visible. * @param {Element | null | undefined} element - Element to check. * @returns {boolean} Whether the element is visible. */ export function isVisible(element: Element | null | undefined): boolean; /** * Check whether an element is inert or outside the active modal dialog. * @param {Element | null | undefined} element - Element to check. * @returns {boolean} Whether the element is inert. */ export function isInert(element: Element | null | undefined): boolean; /** * Remove a field's validator from the registry. * @param {HTMLElement} element - Field element whose validator should be removed. * @returns {void} */ export function removeValidator(element: HTMLElement): void; /** * Run every registered field validator after a save attempt. * @returns {boolean} Whether every registered field passed validation. */ export function validateAll(): boolean; /** * Validate registered fields within a container without marking other fields as attempted. * @param {Element} root - Container whose registered descendants should be validated. * @returns {boolean} Whether every matching field passed validation. */ export function validateWithin(root: Element): boolean; /** * Disables the save functionality by overriding the window.validate function. * @returns {() => void} A function that restores the original window.validate function. */ export function disableSave(): () => void; /** * Check whether the standard validation state allows validation. * @param {Pick} context - The validation state. * @returns {boolean} Whether validation should run. */ export function shouldValidate({ visible, inert }: Pick): boolean; /** * Register a field validator and provide its live validation state when invoked. * @template {Record} [TArgs=Record] * @param {HTMLElement} element - Field element associated with the validator. * @param {Validator} validator - Field validation callback. * @returns {(args?: TArgs) => boolean} The registered validator. */ export function createValidator = Record>(element: HTMLElement, validator: Validator): (args?: TArgs) => boolean; /** * Validates the context using the provided validators in sequence. * @param {ValidationContext} context * @param {...(context: ValidationContext & Record) => ValidationResult} validators - The validators to apply to the context. * @returns {ValidationResult} The result of the validation. */ export function validateWith(context: ValidationContext, ...validators: ((context: ValidationContext & Record) => ValidationResult)[]): ValidationResult; /** * Default validator function for input fields. * @param {ValidationContext} context - The validation context. * @returns {ValidationResult} Whether validation passed and an optional error message. */ export function defaultValidator(context: ValidationContext): ValidationResult; export type ValidationValue = string | number | boolean | readonly unknown[] | null | undefined; export type ValidationResult = { success: boolean; message?: string; }; /** * - The context object passed to field validators. */ export type ValidationContext = { /** * - The current value of the field. */ value: T; /** * - The DOM element associated with the field. */ element: HTMLElement; /** * - Whether the field is currently visible. */ visible: boolean; /** * - Whether the field is inert or outside the active modal dialog. */ inert: boolean; /** * - Whether the field is required. */ required?: boolean; /** * - Whether the field is disabled. */ disabled?: boolean; /** * - Whether the field is read-only. */ readonly?: boolean; }; export type ValidatorState = Pick; /** * - Field validation callback. */ export type Validator = Record> = (context: TArgs & ValidatorState) => boolean;