@suntelecoms/ngx-dynamic-form 1.7.22 → 1.9.0
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/README.md +26 -1
- package/fesm2022/suntelecoms-ngx-dynamic-form.mjs +319 -15
- package/fesm2022/suntelecoms-ngx-dynamic-form.mjs.map +1 -1
- package/lib/components/dynamic-field/dynamic-field.component.d.ts +23 -1
- package/lib/components/form-builder/form-builder.component.d.ts +6 -1
- package/lib/models/form-field.model.d.ts +43 -1
- package/lib/providers.d.ts +10 -1
- package/lib/services/dynamic-form-builder.service.d.ts +8 -0
- package/package.json +1 -1
- package/public-api.d.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventEmitter, OnInit } from '@angular/core';
|
|
1
|
+
import { EventEmitter, OnInit, Type } from '@angular/core';
|
|
2
2
|
import { FormControl, FormGroup } from '@angular/forms';
|
|
3
3
|
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
|
4
4
|
import { DynamicFormField, SelectOption } from '../../models/form-field.model';
|
|
@@ -20,6 +20,7 @@ export declare class DynamicFieldComponent implements OnInit {
|
|
|
20
20
|
private evaluator;
|
|
21
21
|
private http;
|
|
22
22
|
private dataApiUrl;
|
|
23
|
+
private customFields;
|
|
23
24
|
private globalDateLocale;
|
|
24
25
|
private dateAdapter;
|
|
25
26
|
private cdr;
|
|
@@ -111,7 +112,22 @@ export declare class DynamicFieldComponent implements OnInit {
|
|
|
111
112
|
* Ex : '## ## ## ## ##' → téléphone, '##/##/####' → date.
|
|
112
113
|
*/
|
|
113
114
|
applyMask(event: Event): void;
|
|
115
|
+
/** Item d'API -> option (label, value, et locked / group si optionLockedKey / optionGroupKey). */
|
|
116
|
+
private toOption;
|
|
117
|
+
/** Options sans groupe (cases à cocher), puis groupes exclusifs « Une seule option ». */
|
|
118
|
+
get cardSections(): {
|
|
119
|
+
group: string | null;
|
|
120
|
+
options: SelectOption[];
|
|
121
|
+
}[];
|
|
122
|
+
private get cardValues();
|
|
123
|
+
get selectedCount(): number;
|
|
124
|
+
isOptionChecked(opt: SelectOption): boolean;
|
|
125
|
+
toggleOption(opt: SelectOption, checked: boolean): void;
|
|
126
|
+
/** Locked options are part of the value (sent with the form), not only displayed as checked. */
|
|
127
|
+
private ensureLockedOptions;
|
|
114
128
|
get isInputField(): boolean;
|
|
129
|
+
/** type: 'custom' — composant déclaré par l'application (provideNgxForms({ customFields })). */
|
|
130
|
+
get customComponent(): Type<unknown> | null;
|
|
115
131
|
get hasOptions(): boolean;
|
|
116
132
|
get hasError(): boolean;
|
|
117
133
|
get errorMessage(): string | null;
|
|
@@ -120,6 +136,12 @@ export declare class DynamicFieldComponent implements OnInit {
|
|
|
120
136
|
* — une période début/fin grise ainsi les dates invalides dans le calendrier. */
|
|
121
137
|
get minDate(): Date | undefined;
|
|
122
138
|
get maxDate(): Date | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* Date of birth bounded by validation.minAge / maxAge, when the age is computed at today's date
|
|
141
|
+
* (with ageReferenceField the reference can change: only the validator applies).
|
|
142
|
+
* max = today − minAge years ; min = today − (maxAge + 1) years + 1 day.
|
|
143
|
+
*/
|
|
144
|
+
private ageBound;
|
|
123
145
|
/** Same bound, as 'YYYY-MM-DD' for the native <input type="date"> min/max attributes (simple appearance). */
|
|
124
146
|
get minDateAttr(): string | undefined;
|
|
125
147
|
get maxDateAttr(): string | undefined;
|
|
@@ -22,6 +22,11 @@ export declare const ICON_OPTIONS: {
|
|
|
22
22
|
export declare class FormBuilderComponent {
|
|
23
23
|
backRoute: string;
|
|
24
24
|
private formService;
|
|
25
|
+
/** Noms des composants déclarés pour les champs « Composant personnalisé » (provideNgxForms customFields). */
|
|
26
|
+
readonly customFieldNames: string[];
|
|
27
|
+
/** componentConfig édité en JSON ; texte invalide conservé tant qu'il n'est pas corrigé. */
|
|
28
|
+
componentConfigText(): string;
|
|
29
|
+
updateComponentConfig(text: string): void;
|
|
25
30
|
private snack;
|
|
26
31
|
private route;
|
|
27
32
|
constructor();
|
|
@@ -83,7 +88,7 @@ export declare class FormBuilderComponent {
|
|
|
83
88
|
updateValidation(prop: keyof FieldValidation, value: any): void;
|
|
84
89
|
getOptions(): SelectOption[];
|
|
85
90
|
addOption(): void;
|
|
86
|
-
updateOption(idx: number, prop: 'label' | 'value' | 'dependsOnValue', value: string): void;
|
|
91
|
+
updateOption(idx: number, prop: 'label' | 'value' | 'dependsOnValue' | 'locked', value: string | boolean): void;
|
|
87
92
|
/** Options statiques du champ dont dépend le champ sélectionné (vide si liste API ou autre type). */
|
|
88
93
|
parentStaticOptions(): SelectOption[];
|
|
89
94
|
removeOption(idx: number): void;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
export type FieldType = 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | 'textarea' | 'select' | 'multiselect' | 'checkbox' | 'radio' | 'switch' | 'date' | 'datetime-local' | 'time' | 'month' | 'week' | 'range' | 'color' | 'location' | 'file' | 'hidden' | 'phone' | 'iso-country' | 'country-dial-code' | 'divider' | 'heading';
|
|
1
|
+
export type FieldType = 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | 'textarea' | 'select' | 'multiselect' | 'checkbox' | 'radio' | 'switch' | 'date' | 'datetime-local' | 'time' | 'month' | 'week' | 'range' | 'color' | 'location' | 'file' | 'hidden' | 'phone' | 'iso-country' | 'country-dial-code' | 'divider' | 'heading' | 'custom';
|
|
2
2
|
export interface SelectOption {
|
|
3
3
|
label: string;
|
|
4
4
|
value: any;
|
|
5
5
|
disabled?: boolean;
|
|
6
6
|
group?: string;
|
|
7
7
|
dependsOnValue?: any;
|
|
8
|
+
/**
|
|
9
|
+
* type: 'multiselect' + display: 'cards' — option always selected and not deselectable
|
|
10
|
+
* (badge « Obligatoire »), e.g. a mandatory guarantee.
|
|
11
|
+
*/
|
|
12
|
+
locked?: boolean;
|
|
8
13
|
}
|
|
9
14
|
export interface FieldCondition {
|
|
10
15
|
field: string;
|
|
@@ -26,6 +31,15 @@ export interface FieldValidation {
|
|
|
26
31
|
maxField?: string;
|
|
27
32
|
/** This field's numeric value must be >= the value of the named sibling field */
|
|
28
33
|
minField?: string;
|
|
34
|
+
/**
|
|
35
|
+
* type: 'date' (date of birth) — minimum age in completed years, computed at `ageReferenceField`
|
|
36
|
+
* (another date field of the form, e.g. the effective date) or today when not set.
|
|
37
|
+
*/
|
|
38
|
+
minAge?: number;
|
|
39
|
+
/** type: 'date' (date of birth) — maximum age in completed years (same reference as minAge). */
|
|
40
|
+
maxAge?: number;
|
|
41
|
+
/** Date field used as the reference date for minAge / maxAge (default: today). */
|
|
42
|
+
ageReferenceField?: string;
|
|
29
43
|
messages?: {
|
|
30
44
|
required?: string;
|
|
31
45
|
minLength?: string;
|
|
@@ -39,6 +53,9 @@ export interface FieldValidation {
|
|
|
39
53
|
/** type: 'date' — shown when the value is before field.minDate / after field.maxDate */
|
|
40
54
|
minDate?: string;
|
|
41
55
|
maxDate?: string;
|
|
56
|
+
/** type: 'date' — age below minAge / above maxAge */
|
|
57
|
+
minAge?: string;
|
|
58
|
+
maxAge?: string;
|
|
42
59
|
};
|
|
43
60
|
}
|
|
44
61
|
/** Auto-populate sibling fields from an API call when this field loses focus */
|
|
@@ -118,6 +135,31 @@ export interface DynamicFormField {
|
|
|
118
135
|
minDate?: string;
|
|
119
136
|
maxDate?: string;
|
|
120
137
|
dateLocale?: string;
|
|
138
|
+
/**
|
|
139
|
+
* type: 'multiselect' — 'select' (default): drop-down list; 'cards': grid of checkbox cards with a
|
|
140
|
+
* « n / total » counter, hint shown under the label, `locked` options always selected.
|
|
141
|
+
*/
|
|
142
|
+
display?: 'select' | 'cards';
|
|
143
|
+
/** display: 'cards' — word after the counter, e.g. 'retenue(s)' (default 'sélectionnée(s)'). */
|
|
144
|
+
counterLabel?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Options from `url`: item property mapped to SelectOption.locked (e.g. 'obligatoire') —
|
|
147
|
+
* display: 'cards' shows it as an always-selected « Obligatoire » card.
|
|
148
|
+
*/
|
|
149
|
+
optionLockedKey?: string;
|
|
150
|
+
/**
|
|
151
|
+
* Options from `url`: item property mapped to SelectOption.group (e.g. 'groupe') —
|
|
152
|
+
* display: 'cards' shows each group as an exclusive « Une seule option » section.
|
|
153
|
+
*/
|
|
154
|
+
optionGroupKey?: string;
|
|
155
|
+
/**
|
|
156
|
+
* type: 'custom' — name of a component registered by the host application
|
|
157
|
+
* (provideNgxForms({ customFields: { name: Component } })). It receives `field` and `form`
|
|
158
|
+
* inputs and may write its own FormControl (form.get(field.key)).
|
|
159
|
+
*/
|
|
160
|
+
component?: string;
|
|
161
|
+
/** type: 'custom' — free configuration passed to the component (field.componentConfig). */
|
|
162
|
+
componentConfig?: Record<string, any>;
|
|
121
163
|
min?: number;
|
|
122
164
|
max?: number;
|
|
123
165
|
step?: number;
|
package/lib/providers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnvironmentProviders, InjectionToken } from '@angular/core';
|
|
1
|
+
import { EnvironmentProviders, InjectionToken, Type } from '@angular/core';
|
|
2
2
|
import { HttpInterceptorFn } from '@angular/common/http';
|
|
3
3
|
import { NGX_FORMS_LIST_PAGE_SIZE } from './storage/http-storage.adapter';
|
|
4
4
|
import { NgxFormsAuthService, NgxFormsAuthOptions, NGX_FORMS_AUTH } from './auth/ngx-forms-auth.service';
|
|
@@ -15,6 +15,11 @@ export declare const NGX_DATA_API_URL: InjectionToken<string>;
|
|
|
15
15
|
* pas de nouveau parseur de format à maintenir. Surchargeable par champ via
|
|
16
16
|
* `DynamicFormField.dateLocale`.
|
|
17
17
|
*/
|
|
18
|
+
/**
|
|
19
|
+
* Composants des champs `type: 'custom'`, par nom (provideNgxForms({ customFields })).
|
|
20
|
+
* Chaque composant reçoit les inputs `field` (DynamicFormField) et `form` (FormGroup).
|
|
21
|
+
*/
|
|
22
|
+
export declare const NGX_CUSTOM_FIELDS: InjectionToken<Record<string, Type<unknown>>>;
|
|
18
23
|
export declare const NGX_DATE_LOCALE: InjectionToken<string>;
|
|
19
24
|
export { NGX_FORMS_LIST_PAGE_SIZE };
|
|
20
25
|
/**
|
|
@@ -33,6 +38,8 @@ export interface NgxFormsLocalOptions {
|
|
|
33
38
|
auth?: NgxFormsAuthOptions;
|
|
34
39
|
/** Locale par défaut des champs `type: 'date'` (ex: 'fr-FR', 'en-US'). @default 'fr-FR' */
|
|
35
40
|
dateLocale?: string;
|
|
41
|
+
/** Composants des champs `type: 'custom'`, par nom. */
|
|
42
|
+
customFields?: Record<string, Type<unknown>>;
|
|
36
43
|
}
|
|
37
44
|
export interface NgxFormsHttpOptions {
|
|
38
45
|
storage: 'http';
|
|
@@ -49,6 +56,8 @@ export interface NgxFormsHttpOptions {
|
|
|
49
56
|
* (`GET {apiUrl}?page=0&size=...`). @default 1000
|
|
50
57
|
*/
|
|
51
58
|
listPageSize?: number;
|
|
59
|
+
/** Composants des champs `type: 'custom'`, par nom. */
|
|
60
|
+
customFields?: Record<string, Type<unknown>>;
|
|
52
61
|
}
|
|
53
62
|
export type NgxFormsOptions = NgxFormsLocalOptions | NgxFormsHttpOptions;
|
|
54
63
|
export declare function provideNgxForms(options: NgxFormsOptions): EnvironmentProviders;
|
|
@@ -19,8 +19,16 @@ export declare class DynamicFormBuilderService {
|
|
|
19
19
|
* error display in DynamicFieldComponent picks it up automatically.
|
|
20
20
|
*/
|
|
21
21
|
private crossFieldBoundValidator;
|
|
22
|
+
/**
|
|
23
|
+
* Group-level validator for a date of birth: age in completed years at the reference date
|
|
24
|
+
* (`referenceKey` field, or today) must be within [minAge, maxAge]. Sets `minAge` / `maxAge`
|
|
25
|
+
* errors (message string) on the field control, like crossFieldBoundValidator.
|
|
26
|
+
*/
|
|
27
|
+
private ageValidator;
|
|
22
28
|
/** Group-level validator: at least one of the listed field keys must have a non-empty value */
|
|
23
29
|
atLeastOneOfValidator(keys: string[], msg?: string): ValidatorFn;
|
|
24
30
|
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormBuilderService, never>;
|
|
25
31
|
static ɵprov: i0.ɵɵInjectableDeclaration<DynamicFormBuilderService>;
|
|
26
32
|
}
|
|
33
|
+
/** Completed years between two dates (birthday not reached yet = one year less). */
|
|
34
|
+
export declare function completedYears(birth: Date, at: Date): number;
|
package/package.json
CHANGED
package/public-api.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { UniquenessValidatorService } from './lib/services/uniqueness-validator.
|
|
|
12
12
|
export { FormStorageAdapter } from './lib/storage/form-storage.adapter';
|
|
13
13
|
export { LocalStorageAdapter } from './lib/storage/local-storage.adapter';
|
|
14
14
|
export { HttpStorageAdapter, FORM_API_URL, NGX_FORMS_LIST_PAGE_SIZE } from './lib/storage/http-storage.adapter';
|
|
15
|
-
export { provideNgxForms, NGX_DATA_API_URL, ngxFormsAuthInterceptor } from './lib/providers';
|
|
15
|
+
export { provideNgxForms, NGX_DATA_API_URL, NGX_CUSTOM_FIELDS, ngxFormsAuthInterceptor } from './lib/providers';
|
|
16
16
|
export type { NgxFormsOptions, NgxFormsLocalOptions, NgxFormsHttpOptions } from './lib/providers';
|
|
17
17
|
export { NgxFormsAuthService, NGX_FORMS_AUTH } from './lib/auth/ngx-forms-auth.service';
|
|
18
18
|
export type { NgxFormsAuthOptions } from './lib/auth/ngx-forms-auth.service';
|