UNPKG

@funidata/ngx-fudis

Version:

Funidata Design System.

167 lines (166 loc) 6.07 kB
import { OnDestroy, WritableSignal } from '@angular/core'; import { FudisErrorSummaryNewError, FudisErrorSummaryRemoveError, FudisFormErrorSummaryUpdateStrategy, FudisErrorSummaryAllErrors, FudisErrorSummaryAllErrorsSignal } from '../../../types/errorSummary'; import { BehaviorSubject } from 'rxjs'; import { FudisTranslationService } from '../../translation/translation.service'; import * as i0 from "@angular/core"; type FudisFormErrorSummarySection = { id: string; formId: string; title: string; }; type FudisFormErrorSummaryFormChild = { [childId: string]: string; }; type FudisFormErrorSummaryStructure = { [formId: string]: { sections: FudisFormErrorSummaryFormChild; fieldsets: FudisFormErrorSummaryFormChild; }; }; /** * Internal Error Summary tools not exposed to public */ export declare class FudisInternalErrorSummaryService implements OnDestroy { private _translationService; constructor(_translationService: FudisTranslationService); /** * Collection of all registered errors categorised by parent Form id. Used as "temporary" storage * and value will be passed to Observable when ReloadErrors is called. */ private _errorsStore; /** * Collection of all registered errors categorised by parent Form id. This Observable is updated * with new value only when ReloadErrors is called. */ private _errorsObservable; private _errorsSignal; /** * Current Form ids with their Error Summary Visibility status */ private _errorSummaryVisibilityStatus; /** * Collection of child Sections, Expandables and Fieldsets of each Form Component */ private _formStructure; /** * Info to Error Summary Component if it should move user focus to updated list or not */ private _focusToFormOnReload; /** * Update strategy of Error Summary */ private _updateStrategy; /** * Used prevent unnecessary frequent Signal updates */ private _reloadGuard; /** * Used in Components to listen to Reload updates */ get errorsObservable(): BehaviorSubject<FudisErrorSummaryAllErrors>; /** * For unit testing purposes */ get errors(): FudisErrorSummaryAllErrors; /** * For unit testing purposes */ get errorsSignal(): FudisErrorSummaryAllErrorsSignal; /** * Observable to store each Form's Error Summary's visibility status. Form component will listen * to these changes if visiblity changes elsewhere than the Input() prop */ get errorSummaryVisibilityStatus(): { [formId: string]: WritableSignal<boolean>; }; get updateStrategy(): FudisFormErrorSummaryUpdateStrategy; set updateStrategy(value: FudisFormErrorSummaryUpdateStrategy); get focusToFormOnReload(): string | null; get formStructure(): FudisFormErrorSummaryStructure; set focusToFormOnReload(value: string | null); /** * Hide or show Error Summary of spesific Form Component * * @param formId Form to target * @param visible Hide or show Error Summary */ setErrorSummaryVisibility(formId: string, visible: boolean): void; /** * Adds a new error to the list of current errors If new error item has a matching id on the list, * new error is tied to that error list object * * @param newError Form error summary item */ addError(newError: FudisErrorSummaryNewError): void; /** * Removes error object from the current errors list if it contains matching error id * * @param error Error object */ removeError(errorToRemove: FudisErrorSummaryRemoveError): void; /** * Updates the visible and dynamic lists of all form and errors with the current error list */ reloadAllErrors(): void; /** * @param formId * @param focus */ reloadFormErrors(formId: string, focus?: boolean): void; /** * @param element HTMLElement to check, if it has Form Component as ancestor * @returns If ancestor found, returns id of that Form and visibility status of Form's Error * Summary */ getFormAncestorId(element: HTMLElement): Promise<null | string>; /** * When new Form Component is initialized, it will register itself for child components and error * messages related to it * * @param formId */ registerNewForm(formId: string, errorSummaryVisible?: boolean): void; /** * When Form Component is destroyed, it will remove itself from the service * * @param formId */ removeForm(formId: string): void; /** * Adds new fieldset to the list of current fieldsets If a fieldset with a matching id exists, * replace the old fieldset with the new one * * @param fieldset Form error summary fieldset */ addFieldset(fieldset: FudisFormErrorSummarySection): void; /** * Removes the fieldset from the current fieldsets * * @param fieldset Form error summary fieldset */ removeFieldset(formId: string, fieldsetId: string): void; /** * Adds new section to the list of current sections If a section with a matching id exists, * replace the old section with the new one * * @param section Form error summary section */ addSection(section: FudisFormErrorSummarySection): void; /** * Removes the section from the current sections * * @param section Form error summary section */ removeSection(formId: string, sectionId: string): void; ngOnDestroy(): void; /** * Returns an error id including a control name if one is given * * @param id Id of the form error summary item * @param controlName Control name of the form error summary item */ defineErrorId(id: string, controlName: string | undefined): string; static ɵfac: i0.ɵɵFactoryDeclaration<FudisInternalErrorSummaryService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<FudisInternalErrorSummaryService>; } export {};