@spider-baby/utils-forms 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spider-baby/utils-forms",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "A comprehensive Angular forms utility library for streamlined validation, error handling, and accessible error display.",
5
5
  "keywords": [
6
6
  "angular",
@@ -21,28 +21,15 @@
21
21
  "license": "MIT",
22
22
  "main": "./bundles/utils-forms.umd.js",
23
23
  "module": "fesm2022/spider-baby-utils-forms.mjs",
24
- "es2020": "./fesm2020/utils-forms.mjs",
25
- "esm2020": "./esm2020/utils-forms.mjs",
26
- "types": "./index.d.ts",
27
- "exports": {
28
- ".": {
29
- "types": "./types/spider-baby-utils-forms.d.ts",
30
- "default": "./fesm2022/spider-baby-utils-forms.mjs"
31
- },
32
- "./package.json": {
33
- "default": "./package.json"
34
- },
35
- "./validators": {
36
- "types": "./types/spider-baby-utils-forms-validators.d.ts",
37
- "default": "./fesm2022/spider-baby-utils-forms-validators.mjs"
38
- }
39
- },
24
+ "es2020": "./fesm2020/spider-baby-utils-forms.mjs",
25
+ "esm2020": "./esm2020/spider-baby-utils-forms.mjs",
26
+ "types": "./types/spider-baby-utils-forms.d.ts",
40
27
  "files": [
41
28
  "bundles/",
42
29
  "fesm2022/",
43
30
  "fesm2020/",
44
31
  "esm2020/",
45
- "index.d.ts",
32
+ "types/",
46
33
  "package.json",
47
34
  "README.md"
48
35
  ],
@@ -57,6 +44,19 @@
57
44
  },
58
45
  "sideEffects": false,
59
46
  "typings": "types/spider-baby-utils-forms.d.ts",
47
+ "exports": {
48
+ "./package.json": {
49
+ "default": "./package.json"
50
+ },
51
+ ".": {
52
+ "types": "./types/spider-baby-utils-forms.d.ts",
53
+ "default": "./fesm2022/spider-baby-utils-forms.mjs"
54
+ },
55
+ "./validators": {
56
+ "types": "./types/spider-baby-utils-forms-validators.d.ts",
57
+ "default": "./fesm2022/spider-baby-utils-forms-validators.mjs"
58
+ }
59
+ },
60
60
  "dependencies": {
61
61
  "tslib": "^2.3.0"
62
62
  }
@@ -0,0 +1,29 @@
1
+ import { ValidatorFn, ValidationErrors } from '@angular/forms';
2
+ import { CountryCode } from 'libphonenumber-js';
3
+
4
+ declare class NumericValidation {
5
+ static lessThanValidator(minControlName: string, maxControlName: string, strictlyLessThan?: boolean, errorMessage?: string): ValidatorFn;
6
+ }
7
+
8
+ declare class PasswordValidation {
9
+ static validationArray: (minLength?: number) => ValidatorFn[];
10
+ static matchValidator(passwordControlName?: string, confirmPasswordControlName?: string, errorMessage?: string): ValidatorFn;
11
+ static patternValidator(regex: RegExp, error: ValidationErrors): ValidatorFn;
12
+ static hasUppercaseValidator(): ValidatorFn;
13
+ static hasLowercaseValidator(): ValidatorFn;
14
+ static hasNumberValidator(): ValidatorFn;
15
+ static hasNonAlphaNumericValidator(): ValidatorFn;
16
+ }
17
+
18
+ declare const StrongPassword6Regx: RegExp;
19
+ declare const StrongPassword6WithSpecialRegx: RegExp;
20
+ declare const StrongPassword8Regx: RegExp;
21
+ declare const StrongPassword8WithSpecialRegx: RegExp;
22
+ declare const StrongPassword10Regx: RegExp;
23
+ declare const StrongPassword10WithSpecialRegx: RegExp;
24
+
25
+ declare class PhoneValidation {
26
+ static validator(defaultCountry?: CountryCode): ValidatorFn;
27
+ }
28
+
29
+ export { NumericValidation, PasswordValidation, PhoneValidation, StrongPassword10Regx, StrongPassword10WithSpecialRegx, StrongPassword6Regx, StrongPassword6WithSpecialRegx, StrongPassword8Regx, StrongPassword8WithSpecialRegx };
@@ -0,0 +1,93 @@
1
+ import * as i0 from '@angular/core';
2
+ import { TemplateRef, OnDestroy } from '@angular/core';
3
+ import { AbstractControl, FormGroup } from '@angular/forms';
4
+
5
+ declare class FirstErrorComponent {
6
+ control: i0.InputSignal<AbstractControl<any, any, any>>;
7
+ customErrorTemplate: i0.InputSignal<TemplateRef<unknown> | undefined>;
8
+ static ɵfac: i0.ɵɵFactoryDeclaration<FirstErrorComponent, never>;
9
+ static ɵcmp: i0.ɵɵComponentDeclaration<FirstErrorComponent, "sb-first-error", never, { "control": { "alias": "control"; "required": true; "isSignal": true; }; "customErrorTemplate": { "alias": "customErrorTemplate"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
10
+ }
11
+
12
+ declare class FirstErrorMatComponent {
13
+ control: i0.InputSignal<AbstractControl<any, any, any>>;
14
+ customErrorTemplate: i0.InputSignal<TemplateRef<unknown> | undefined>;
15
+ static ɵfac: i0.ɵɵFactoryDeclaration<FirstErrorMatComponent, never>;
16
+ static ɵcmp: i0.ɵɵComponentDeclaration<FirstErrorMatComponent, "sb-first-error-mat", never, { "control": { "alias": "control"; "required": true; "isSignal": true; }; "customErrorTemplate": { "alias": "customErrorTemplate"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
17
+ }
18
+
19
+ type ErrorMessageFunction = (fieldName: string, errorValue: any) => string;
20
+ type CustomErrorMessageMap = Map<string, ErrorMessageFunction>;
21
+ declare class FormErrors {
22
+ static setFirstErrors(form: FormGroup, customErrorMessages?: CustomErrorMessageMap): void;
23
+ static setFirstErrorMessage(name: string, control: AbstractControl, customErrorMessages?: CustomErrorMessageMap): void;
24
+ static getFirstErrorMessage(name: string, control: AbstractControl, customErrorMessages?: CustomErrorMessageMap): string | null;
25
+ private static firstErrorKey;
26
+ private static toTitleCase;
27
+ }
28
+
29
+ /**
30
+ * Directive: sbFormControlFirstError
31
+ *
32
+ * Automatically manages and displays the first validation error for each control in a FormGroup.
33
+ * - Shows errors only after controls are touched (unless showUntouched is true)
34
+ * - Dynamically adds blur/focusout listeners for untouched invalid controls
35
+ * - Supports custom error messages via CustomErrorMessageMap
36
+ * - Cleans up all listeners and subscriptions on destroy
37
+ * - SSR-safe: all DOM access is guarded by isPlatformBrowser
38
+ *
39
+ * Limitations:
40
+ * - Dynamic form changes (adding/removing controls at runtime) are NOT automatically handled in this version.
41
+ * If you add or remove controls after initialization, you must manually re-run error setup logic.
42
+ * (This feature is planned for a future release.)
43
+ */
44
+ declare class FirstErrorDirective implements OnDestroy {
45
+ private _platformId;
46
+ private _renderer;
47
+ private _host;
48
+ set sbFormControlFirstError(form: FormGroup);
49
+ /**
50
+ * Custom error messages map to override default error messages.
51
+ * If map returns undefined for a specific error, the default message map will be used.
52
+ */
53
+ customErrorMessages?: CustomErrorMessageMap;
54
+ /**
55
+ * If true, errors will be shown immediately for untouched controls.
56
+ * If false, errors will only be shown after the control is touched.
57
+ * Default is false.
58
+ */
59
+ showUntouched: boolean;
60
+ private _form?;
61
+ private _vcSub?;
62
+ private blurListeners;
63
+ ngOnDestroy(): void;
64
+ private addBlurListener;
65
+ private removeAllBlurListeners;
66
+ private observeValueChanges;
67
+ static ɵfac: i0.ɵɵFactoryDeclaration<FirstErrorDirective, never>;
68
+ static ɵdir: i0.ɵɵDirectiveDeclaration<FirstErrorDirective, "[sbFormControlFirstError]", never, { "sbFormControlFirstError": { "alias": "sbFormControlFirstError"; "required": true; }; "customErrorMessages": { "alias": "customErrorMessages"; "required": false; }; "showUntouched": { "alias": "showUntouched"; "required": false; }; }, {}, never, never, true, never>;
69
+ }
70
+
71
+ interface ControlData {
72
+ name: string;
73
+ control: AbstractControl;
74
+ }
75
+ declare class FormUtility {
76
+ static findInvalidControlNames(form: FormGroup): Set<string>;
77
+ static findInvalidControlInfo(form: FormGroup): Set<string>;
78
+ static findInvalidControls(form: FormGroup): AbstractControl[];
79
+ static findInvalidControlsData(form: FormGroup): ControlData[];
80
+ static replaceNullWithUndefined(obj: Record<string, any>): Record<string, any>;
81
+ static getFirstFormError(form: FormGroup): Record<string, any> | null;
82
+ static firstErrorKey: (control: AbstractControl) => string | null;
83
+ }
84
+
85
+ declare class RemoveNullsService<T> {
86
+ remove: (obj: T) => T;
87
+ static ɵfac: i0.ɵɵFactoryDeclaration<RemoveNullsService<any>, never>;
88
+ static ɵprov: i0.ɵɵInjectableDeclaration<RemoveNullsService<any>>;
89
+ }
90
+ declare function RemoveNulls<T>(obj: T, iterate?: boolean): T;
91
+
92
+ export { FirstErrorComponent, FirstErrorDirective, FirstErrorMatComponent, FormErrors, FormUtility, RemoveNulls, RemoveNullsService };
93
+ export type { ControlData, CustomErrorMessageMap, ErrorMessageFunction };