import type { UmbValidator } from '../interfaces/validator.interface.js'; import type { UmbValidationMessageTranslator } from '../translators/index.js'; import { UmbValidationMessagesManager } from '../context/validation-messages.manager.js'; import type { UmbVariantId } from '../../variant/variant-id.class.js'; import { type UmbClassInterface, UmbControllerBase } from '../../../../libs/class-api/index.js'; import type { UmbControllerHost } from '../../../../libs/controller-api/index.js'; /** * Validation Context is the core of Validation. * It hosts Validators that has to validate for the context to be valid. * It can also be used as a Validator as part of a parent Validation Context. */ export declare class UmbValidationController extends UmbControllerBase implements UmbValidator { #private; readonly messages: UmbValidationMessagesManager; constructor(host: UmbControllerHost); setVariantId(variantId: UmbVariantId): void; getVariantId(): UmbVariantId | undefined; /** * Add a path translator to this validation context. * @param translator */ addTranslator(translator: UmbValidationMessageTranslator): Promise; /** * Remove a path translator from this validation context. * @param {UmbValidationMessageTranslator} translator - The translator to remove. */ removeTranslator(translator: UmbValidationMessageTranslator): Promise; /** * Provide this validation context to a specific controller host. * This can be used to Host a validation context in a Workspace, but provide it on a certain scope, like a specific Workspace View. * @param {UmbClassInterface} controllerHost - The controller host to provide this validation context to. */ provideAt(controllerHost: UmbClassInterface): void; unprovide(): void; /** * Define a specific data path for this validation context. * This will turn this validation context into a sub-context of the parent validation context. * And thereby make this context inherit the messages from the parent validation context. * @see {@link report} Call `report()` to propagate changes to the parent context. * @see {@link autoReport} Call `autoReport()` to continuously synchronize changes to the parent context. * * messages and data will be scoped accordingly to the given data path. * @param {string} dataPath - The data path to bind this validation context to. * @example * ```ts * const validationContext = new UmbValidationContext(this); * validationContext.setDataPath("$.values[?(@.alias == 'my-property')].value"); * ``` * * A message with the path: '$.values[?(@.alias == 'my-property')].value.innerProperty', will for above example become '$.innerProperty' for the local Validation Context. */ setDataPath(dataPath: string): void; /** * Inherit from a parent validation context, notice you should only use this method if you have the validation context at hand. Otherwise use setDataPath which uses Context-API to retrieve the right parent. * @param {UmbValidationController} parent - The parent validation context to inherit from. * @param {string} dataPath - The data path to bind this validation context to. */ inheritFrom(parent: UmbValidationController | undefined, dataPath: string): void; /** * Continuously synchronize the messages from this context to the parent context. */ autoReport(): void; /** * Perform a one time transfer of the messages from this context to the parent context. */ report(): void; hostConnected(): void; hostDisconnected(): void; /** * Get if this context is valid. * Notice this does not verify the validity. * @returns {boolean} */ get isValid(): boolean; /** * Add a validator to this context. * This validator will have to be valid for the context to be valid. * If the context is in validation mode, the validator will be validated immediately. * @param validator { UmbValidator } - The validator to add to this context. */ addValidator(validator: UmbValidator): void; /** * Remove a validator from this context. * @param validator {UmbValidator} - The validator to remove from this context. */ removeValidator(validator: UmbValidator): void; /** * Validate this context, all the validators of this context will be validated. * Notice its a recursive check meaning sub validation contexts also validates their validators. * @returns succeed {Promise} - Returns a promise that resolves to true if the validation succeeded. */ validate(): Promise; /** * Validate this context, by a given set of VariantIDs. * Notice its a recursive check meaning sub validation contexts also validates their validators, but only for validators matching the given variantIds. * @param {Array} variantIds - The variantIds to validate by. * @returns {Promise} - Returns a promise that resolves to true if the validation succeeded. */ validateByVariantIds(variantIds: Array): Promise; /** * Focus the first invalid element that this context can find. */ focusFirstInvalidElement(): void; /** * Reset the validation state of this context. */ reset(): void; destroy(): void; }