@suntelecoms/ngx-dynamic-form 1.9.0 → 1.11.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 +111 -0
- package/fesm2022/suntelecoms-ngx-dynamic-form.mjs +1269 -194
- package/fesm2022/suntelecoms-ngx-dynamic-form.mjs.map +1 -1
- package/lib/components/dynamic-field/dynamic-field.component.d.ts +14 -2
- package/lib/components/dynamic-form/dynamic-form.component.d.ts +29 -8
- package/lib/components/form-builder/form-builder.component.d.ts +40 -1
- package/lib/components/questionnaire-field/questionnaire-field.component.d.ts +37 -0
- package/lib/components/repeater-field/repeater-field.component.d.ts +30 -0
- package/lib/components/stepper-form/stepper-form.component.d.ts +29 -3
- package/lib/models/form-field.model.d.ts +88 -1
- package/lib/services/dynamic-form-builder.service.d.ts +9 -1
- package/lib/utils/form-logic.d.ts +90 -0
- package/lib/utils/option-label.d.ts +7 -3
- package/package.json +1 -1
- package/public-api.d.ts +5 -1
|
@@ -6,6 +6,10 @@ import { PhoneCountry } from '../../data/phone-countries';
|
|
|
6
6
|
import * as i0 from "@angular/core";
|
|
7
7
|
export declare class DynamicFieldComponent implements OnInit {
|
|
8
8
|
field: DynamicFormField;
|
|
9
|
+
/** Préfixe des id (et des for) : unique par ligne dans une liste répétable (ex. 'capitaux-1'). */
|
|
10
|
+
idPrefix?: string;
|
|
11
|
+
/** Id de l'élément de saisie : la clé du champ, préfixée si besoin. */
|
|
12
|
+
get fieldId(): string;
|
|
9
13
|
form: FormGroup;
|
|
10
14
|
/** Apparence héritée du formulaire parent — surchargeable par field.appearance */
|
|
11
15
|
formAppearance: 'outline' | 'fill' | 'simple';
|
|
@@ -122,8 +126,16 @@ export declare class DynamicFieldComponent implements OnInit {
|
|
|
122
126
|
private get cardValues();
|
|
123
127
|
get selectedCount(): number;
|
|
124
128
|
isOptionChecked(opt: SelectOption): boolean;
|
|
129
|
+
/** Valeurs cochées automatiquement par une inclusion (retirées quand l'option qui les incluait est décochée). */
|
|
130
|
+
private autoIncluded;
|
|
131
|
+
/** Options vues par la logique des inclusions (includesLocked par défaut : field.lockIncludedOptions). */
|
|
132
|
+
private get includeOptions();
|
|
133
|
+
/** Option cochée par une inclusion grisée : non décochable tant que l'option qui l'inclut est cochée. */
|
|
134
|
+
includedLock(opt: SelectOption): boolean;
|
|
135
|
+
/** Libellés des options qui incluent `opt` (infobulle « Incluse avec … »). */
|
|
136
|
+
includedSources(opt: SelectOption): string;
|
|
125
137
|
toggleOption(opt: SelectOption, checked: boolean): void;
|
|
126
|
-
/** Locked options are part of the value
|
|
138
|
+
/** Locked options (and options included greyed by a selected one) are part of the value, not only displayed as checked. */
|
|
127
139
|
private ensureLockedOptions;
|
|
128
140
|
get isInputField(): boolean;
|
|
129
141
|
/** type: 'custom' — composant déclaré par l'application (provideNgxForms({ customFields })). */
|
|
@@ -156,5 +168,5 @@ export declare class DynamicFieldComponent implements OnInit {
|
|
|
156
168
|
private updateRequiredFromConditions;
|
|
157
169
|
onLookupBlur(): void;
|
|
158
170
|
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFieldComponent, never>;
|
|
159
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFieldComponent, "ngx-dynamic-field", never, { "field": { "alias": "field"; "required": true; }; "form": { "alias": "form"; "required": true; }; "formAppearance": { "alias": "formAppearance"; "required": false; }; "formFloatLabel": { "alias": "formFloatLabel"; "required": false; }; }, { "fieldChange": "fieldChange"; }, never, never, true, never>;
|
|
171
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFieldComponent, "ngx-dynamic-field", never, { "field": { "alias": "field"; "required": true; }; "idPrefix": { "alias": "idPrefix"; "required": false; }; "form": { "alias": "form"; "required": true; }; "formAppearance": { "alias": "formAppearance"; "required": false; }; "formFloatLabel": { "alias": "formFloatLabel"; "required": false; }; }, { "fieldChange": "fieldChange"; }, never, never, true, never>;
|
|
160
172
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter, OnInit, OnChanges, SimpleChanges, ChangeDetectorRef } from '@angular/core';
|
|
2
2
|
import { FormGroup } from '@angular/forms';
|
|
3
|
-
import { DynamicFormConfig, DynamicFormField, DynamicFormSubmitEvent } from '../../models/form-field.model';
|
|
3
|
+
import { DynamicFormConfig, DynamicFormField, DynamicFormSubmitEvent, FormRulesFn, FormValuesTransform } from '../../models/form-field.model';
|
|
4
4
|
import { DynamicFormBuilderService } from '../../services/dynamic-form-builder.service';
|
|
5
5
|
import { ConditionEvaluatorService } from '../../services/condition-evaluator.service';
|
|
6
6
|
import * as i0 from "@angular/core";
|
|
@@ -11,6 +11,17 @@ export declare class DynamicFormComponent implements OnInit, OnChanges {
|
|
|
11
11
|
config: DynamicFormConfig;
|
|
12
12
|
/** Pre-fill the form with values (e.g. in edit mode) */
|
|
13
13
|
initialValues?: Record<string, any>;
|
|
14
|
+
/** Champs retirés pour cet écran (ni affichés ni construits) ; le formulaire enregistré n'est pas modifié. */
|
|
15
|
+
hiddenFields?: string[];
|
|
16
|
+
/** Champs affichés mais absents des valeurs envoyées, pour cet écran (en plus de field.excludeFromSubmit). */
|
|
17
|
+
excludeFromSubmit?: string[];
|
|
18
|
+
/** Règles de saisie calculées par l'application à chaque changement : valeurs imposées, champs verrouillés
|
|
19
|
+
* (en plus de field.valueWhen / field.disabledWhen). */
|
|
20
|
+
rules?: FormRulesFn;
|
|
21
|
+
/** Conversion des valeurs initiales avant remplissage (ex. relation → champs du formulaire). */
|
|
22
|
+
transformIn?: FormValuesTransform;
|
|
23
|
+
/** Conversion des valeurs envoyées (après exclusions et submitAs), appliquée à value et rawValue. */
|
|
24
|
+
transformOut?: FormValuesTransform;
|
|
14
25
|
/** Emitted on valid form submit */
|
|
15
26
|
formSubmit: EventEmitter<DynamicFormSubmitEvent>;
|
|
16
27
|
/** Emitted on every value change */
|
|
@@ -23,10 +34,24 @@ export declare class DynamicFormComponent implements OnInit, OnChanges {
|
|
|
23
34
|
/** Emitted when form is reset */
|
|
24
35
|
formReset: EventEmitter<void>;
|
|
25
36
|
form: FormGroup;
|
|
37
|
+
/** Champs affichés : ceux de la configuration sans hiddenFields. */
|
|
38
|
+
fields: DynamicFormField[];
|
|
39
|
+
/** Champs verrouillés par une règle (rendus à nouveau saisissables quand la règle ne s'applique plus). */
|
|
40
|
+
private locked;
|
|
41
|
+
private applyingRules;
|
|
26
42
|
constructor(builder: DynamicFormBuilderService, conditionEvaluator: ConditionEvaluatorService, cdr: ChangeDetectorRef);
|
|
27
43
|
ngOnInit(): void;
|
|
28
44
|
ngOnChanges(changes: SimpleChanges): void;
|
|
29
45
|
private buildForm;
|
|
46
|
+
/** Valeurs initiales : transformIn, objets → valeurs, initialFrom, lignes des listes répétables. */
|
|
47
|
+
private applyValues;
|
|
48
|
+
/**
|
|
49
|
+
* Règles de saisie (valueWhen / disabledWhen / entrée rules) : valeurs imposées (seulement si elles
|
|
50
|
+
* diffèrent : pas de boucle), verrouillage ; listes répétables masquées désactivées (non validées).
|
|
51
|
+
*/
|
|
52
|
+
private applyRules;
|
|
53
|
+
/** Valeurs envoyées : verrouillés par règle gardés, exclus retirés, submitAs, listes masquées vides, transformOut. */
|
|
54
|
+
private submitValues;
|
|
30
55
|
isVisible(field: DynamicFormField): boolean;
|
|
31
56
|
onSubmit(): void;
|
|
32
57
|
onReset(): void;
|
|
@@ -34,12 +59,8 @@ export declare class DynamicFormComponent implements OnInit, OnChanges {
|
|
|
34
59
|
getForm(): FormGroup;
|
|
35
60
|
/** Public API: patch values from outside */
|
|
36
61
|
patchValues(values: Record<string, any>): void;
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
* (e.g. ville: { id: 9, nom: "Dakar" }) instead of a primitive value (9).
|
|
40
|
-
* Extract the displayValue key so the select control matches the correct option.
|
|
41
|
-
*/
|
|
42
|
-
private normalizeValues;
|
|
62
|
+
/** Public API: valeurs telles qu'elles seraient envoyées (exclusions, submitAs, transformOut). */
|
|
63
|
+
getSubmitValue(): Record<string, any>;
|
|
43
64
|
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormComponent, never>;
|
|
44
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFormComponent, "ngx-dynamic-form", never, { "config": { "alias": "config"; "required": true; }; "initialValues": { "alias": "initialValues"; "required": false; }; }, { "formSubmit": "formSubmit"; "formChange": "formChange"; "fieldChange": "fieldChange"; "formReset": "formReset"; }, never, never, true, never>;
|
|
65
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFormComponent, "ngx-dynamic-form", never, { "config": { "alias": "config"; "required": true; }; "initialValues": { "alias": "initialValues"; "required": false; }; "hiddenFields": { "alias": "hiddenFields"; "required": false; }; "excludeFromSubmit": { "alias": "excludeFromSubmit"; "required": false; }; "rules": { "alias": "rules"; "required": false; }; "transformIn": { "alias": "transformIn"; "required": false; }; "transformOut": { "alias": "transformOut"; "required": false; }; }, { "formSubmit": "formSubmit"; "formChange": "formChange"; "fieldChange": "fieldChange"; "formReset": "formReset"; }, never, never, true, never>;
|
|
45
66
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DynamicFormConfig, DynamicFormField, FieldCondition, FieldType, FieldValidation, RemoteSearchConfig, SelectOption, StepGuard, StepperFormConfig } from '../../models/form-field.model';
|
|
1
|
+
import type { DynamicFormConfig, DynamicFormField, FieldCondition, FieldType, FieldValidation, RemoteSearchConfig, SelectOption, StepGuard, StepperFormConfig, ValueRule, QuestionItem } from '../../models/form-field.model';
|
|
2
2
|
import type { SavedFormSchema } from '../../models/saved-form.model';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
interface FieldTypeDef {
|
|
@@ -89,6 +89,11 @@ export declare class FormBuilderComponent {
|
|
|
89
89
|
getOptions(): SelectOption[];
|
|
90
90
|
addOption(): void;
|
|
91
91
|
updateOption(idx: number, prop: 'label' | 'value' | 'dependsOnValue' | 'locked', value: string | boolean): void;
|
|
92
|
+
/** Options cochées en même temps que l'option idx (includes) ; « griser » : includesLocked. */
|
|
93
|
+
updateOptionIncludes(idx: number, values: any[]): void;
|
|
94
|
+
updateOptionIncludesLocked(idx: number, locked: boolean): void;
|
|
95
|
+
/** Autres options du champ (choix de « Coche aussi »). */
|
|
96
|
+
otherOptions(idx: number): SelectOption[];
|
|
92
97
|
/** Options statiques du champ dont dépend le champ sélectionné (vide si liste API ou autre type). */
|
|
93
98
|
parentStaticOptions(): SelectOption[];
|
|
94
99
|
removeOption(idx: number): void;
|
|
@@ -96,6 +101,40 @@ export declare class FormBuilderComponent {
|
|
|
96
101
|
private deleteProp;
|
|
97
102
|
setPattern(regex: string): void;
|
|
98
103
|
updateValidationMessage(key: keyof NonNullable<FieldValidation['messages']>, value: string): void;
|
|
104
|
+
/** Types proposés pour une colonne de liste répétable. */
|
|
105
|
+
readonly columnTypes: {
|
|
106
|
+
type: FieldType;
|
|
107
|
+
label: string;
|
|
108
|
+
}[];
|
|
109
|
+
getColumns(): DynamicFormField[];
|
|
110
|
+
addColumn(): void;
|
|
111
|
+
removeColumn(index: number): void;
|
|
112
|
+
updateColumn(index: number, prop: keyof DynamicFormField, value: any): void;
|
|
113
|
+
updateColumnRequired(index: number, required: boolean): void;
|
|
114
|
+
/** Nombre saisi (vide : undefined). */
|
|
115
|
+
numberOrUndefined(v: any): number | undefined;
|
|
116
|
+
getQuestions(): QuestionItem[];
|
|
117
|
+
addQuestion(): void;
|
|
118
|
+
removeQuestion(index: number): void;
|
|
119
|
+
updateQuestion(index: number, prop: keyof QuestionItem, value: any): void;
|
|
120
|
+
/** Source des questions : saisies ici ('static') ou chargées depuis une API ('api'). */
|
|
121
|
+
questionSource(): 'static' | 'api';
|
|
122
|
+
setQuestionSource(source: 'static' | 'api'): void;
|
|
123
|
+
/** Valeur saisie dans le constructeur : 'true' / 'false' deviennent des booléens (cases à cocher). */
|
|
124
|
+
private valeurSaisie;
|
|
125
|
+
getValueRules(): ValueRule[];
|
|
126
|
+
/** Première condition d'une règle (le constructeur en édite une ; les autres, venues du JSON, sont gardées). */
|
|
127
|
+
ruleCondition(rule: ValueRule): FieldCondition;
|
|
128
|
+
addValueRule(): void;
|
|
129
|
+
removeValueRule(index: number): void;
|
|
130
|
+
updateValueRule(index: number, prop: 'value' | 'lock', value: any): void;
|
|
131
|
+
updateValueRuleCondition(index: number, key: keyof FieldCondition, value: any): void;
|
|
132
|
+
getDisabledConditions(): FieldCondition[];
|
|
133
|
+
addDisabledCondition(): void;
|
|
134
|
+
removeDisabledCondition(index: number): void;
|
|
135
|
+
updateDisabledCondition(index: number, key: keyof FieldCondition, value: any): void;
|
|
136
|
+
optionDefaultsText(): string;
|
|
137
|
+
updateOptionDefaults(text: string): void;
|
|
99
138
|
getConditions(): FieldCondition[];
|
|
100
139
|
allFieldKeysExcludingCurrent(): string[];
|
|
101
140
|
setConditionLogic(logic: 'AND' | 'OR'): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { OnDestroy, OnInit } from '@angular/core';
|
|
2
|
+
import { AbstractControl, FormGroup } from '@angular/forms';
|
|
3
|
+
import { DynamicFormField } from '../../models/form-field.model';
|
|
4
|
+
import { Question } from '../../utils/form-logic';
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
/**
|
|
7
|
+
* type: 'questionnaire' — questions Oui / Non (santé, activité…), statiques (`questions`) ou chargées depuis
|
|
8
|
+
* `url` (interpolation {{champ}} : rechargées quand le champ change). Précision demandée sous la question quand
|
|
9
|
+
* la réponse est Oui (`details`). Valeur : { q1: 'OUI', q1Precision: '…', q2: 'NON' }.
|
|
10
|
+
*/
|
|
11
|
+
export declare class QuestionnaireFieldComponent implements OnInit, OnDestroy {
|
|
12
|
+
field: DynamicFormField;
|
|
13
|
+
form: FormGroup;
|
|
14
|
+
private readonly http;
|
|
15
|
+
private readonly dataApiUrl;
|
|
16
|
+
private readonly cdr;
|
|
17
|
+
private subs;
|
|
18
|
+
questions: Question[];
|
|
19
|
+
chargement: boolean;
|
|
20
|
+
get control(): AbstractControl;
|
|
21
|
+
get valeur(): Record<string, any>;
|
|
22
|
+
get oui(): any;
|
|
23
|
+
get non(): any;
|
|
24
|
+
get suffixe(): string;
|
|
25
|
+
get repondues(): number;
|
|
26
|
+
ngOnInit(): void;
|
|
27
|
+
ngOnDestroy(): void;
|
|
28
|
+
/** URL des questions, {{champ}} remplacé par sa valeur ; null tant qu'un champ utilisé est vide. */
|
|
29
|
+
private urlResolue;
|
|
30
|
+
private definir;
|
|
31
|
+
/** Message d'erreur d'une question, affiché une fois le champ touché (ou l'envoi tenté). */
|
|
32
|
+
erreur(code: string): string | null;
|
|
33
|
+
repondre(code: string, reponse: any): void;
|
|
34
|
+
preciser(code: string, texte: string): void;
|
|
35
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<QuestionnaireFieldComponent, never>;
|
|
36
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<QuestionnaireFieldComponent, "ngx-questionnaire-field", never, { "field": { "alias": "field"; "required": true; }; "form": { "alias": "form"; "required": true; }; }, {}, never, never, true, never>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { OnDestroy, OnInit } from '@angular/core';
|
|
2
|
+
import { FormArray, FormGroup } from '@angular/forms';
|
|
3
|
+
import { DynamicFormField } from '../../models/form-field.model';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
/**
|
|
6
|
+
* type: 'repeater' — liste de lignes à plusieurs colonnes (itemFields), ajoutées ou retirées par
|
|
7
|
+
* l'utilisateur, chaque ligne validée comme un petit formulaire. Valeur du champ : tableau d'objets.
|
|
8
|
+
*/
|
|
9
|
+
export declare class RepeaterFieldComponent implements OnInit, OnDestroy {
|
|
10
|
+
field: DynamicFormField;
|
|
11
|
+
form: FormGroup;
|
|
12
|
+
formAppearance: 'outline' | 'fill' | 'simple';
|
|
13
|
+
formFloatLabel: 'auto' | 'always';
|
|
14
|
+
private readonly builder;
|
|
15
|
+
private readonly conditions;
|
|
16
|
+
private readonly cdr;
|
|
17
|
+
private sub?;
|
|
18
|
+
get lignes(): FormArray<FormGroup>;
|
|
19
|
+
ngOnInit(): void;
|
|
20
|
+
ngOnDestroy(): void;
|
|
21
|
+
visible(f: DynamicFormField, ligne: FormGroup): boolean;
|
|
22
|
+
peutAjouter(): boolean;
|
|
23
|
+
peutRetirer(): boolean;
|
|
24
|
+
ajouter(): void;
|
|
25
|
+
retirer(i: number): void;
|
|
26
|
+
/** Erreur de la liste (nombre de lignes), affichée une fois la liste touchée (ou l'envoi tenté). */
|
|
27
|
+
erreur(): string | null;
|
|
28
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RepeaterFieldComponent, never>;
|
|
29
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<RepeaterFieldComponent, "ngx-repeater-field", never, { "field": { "alias": "field"; "required": true; }; "form": { "alias": "form"; "required": true; }; "formAppearance": { "alias": "formAppearance"; "required": false; }; "formFloatLabel": { "alias": "formFloatLabel"; "required": false; }; }, {}, never, never, true, never>;
|
|
30
|
+
}
|
|
@@ -2,7 +2,7 @@ import { EventEmitter, OnInit, OnChanges, SimpleChanges, ChangeDetectorRef } fro
|
|
|
2
2
|
import { HttpClient } from '@angular/common/http';
|
|
3
3
|
import { FormGroup } from '@angular/forms';
|
|
4
4
|
import { MatStepper } from '@angular/material/stepper';
|
|
5
|
-
import { StepperFormConfig, DynamicFormSubmitEvent, DynamicFormField } from '../../models/form-field.model';
|
|
5
|
+
import { StepperFormConfig, DynamicFormSubmitEvent, DynamicFormField, FormStep, FormRulesFn, FormValuesTransform } from '../../models/form-field.model';
|
|
6
6
|
import { DynamicFormBuilderService } from '../../services/dynamic-form-builder.service';
|
|
7
7
|
import { ConditionEvaluatorService } from '../../services/condition-evaluator.service';
|
|
8
8
|
import * as i0 from "@angular/core";
|
|
@@ -22,6 +22,16 @@ export declare class StepperFormComponent implements OnInit, OnChanges {
|
|
|
22
22
|
private http;
|
|
23
23
|
config: StepperFormConfig;
|
|
24
24
|
initialValues?: Record<string, any>;
|
|
25
|
+
/** Champs retirés pour cet écran (ni affichés ni construits) ; le formulaire enregistré n'est pas modifié. */
|
|
26
|
+
hiddenFields?: string[];
|
|
27
|
+
/** Champs affichés mais absents des valeurs envoyées, pour cet écran (en plus de field.excludeFromSubmit). */
|
|
28
|
+
excludeFromSubmit?: string[];
|
|
29
|
+
/** Règles de saisie de l'application (valeurs imposées, verrous), en plus de valueWhen / disabledWhen. */
|
|
30
|
+
rules?: FormRulesFn;
|
|
31
|
+
/** Conversion des valeurs initiales avant remplissage. */
|
|
32
|
+
transformIn?: FormValuesTransform;
|
|
33
|
+
/** Conversion des valeurs envoyées (après exclusions et submitAs). */
|
|
34
|
+
transformOut?: FormValuesTransform;
|
|
25
35
|
formSubmit: EventEmitter<DynamicFormSubmitEvent>;
|
|
26
36
|
formChange: EventEmitter<Record<string, any>>;
|
|
27
37
|
stepChange: EventEmitter<number>;
|
|
@@ -37,11 +47,27 @@ export declare class StepperFormComponent implements OnInit, OnChanges {
|
|
|
37
47
|
guardError: Record<number, string | null>;
|
|
38
48
|
stepper: MatStepper;
|
|
39
49
|
stepForms: FormGroup[];
|
|
50
|
+
/** Étapes affichées : celles de la configuration sans hiddenFields. */
|
|
51
|
+
steps: FormStep[];
|
|
52
|
+
/** Champs verrouillés par une règle, et l'étape qui les porte. */
|
|
53
|
+
private locked;
|
|
54
|
+
private applyingRules;
|
|
55
|
+
/** Construction en cours : le remplissage initial n'émet pas formChange (comme avant). */
|
|
56
|
+
private building;
|
|
40
57
|
constructor(builder: DynamicFormBuilderService, conditionEvaluator: ConditionEvaluatorService, cdr: ChangeDetectorRef, http: HttpClient);
|
|
41
58
|
ngOnInit(): void;
|
|
42
59
|
ngOnChanges(changes: SimpleChanges): void;
|
|
43
60
|
private buildForms;
|
|
44
|
-
|
|
61
|
+
/** Tous les champs des étapes affichées. */
|
|
62
|
+
private allFields;
|
|
63
|
+
/** Contrôle d'un champ, quelle que soit son étape. */
|
|
64
|
+
private control;
|
|
65
|
+
/** Valeurs initiales : transformIn, objets → valeurs, initialFrom, lignes des listes répétables. */
|
|
66
|
+
private applyValues;
|
|
67
|
+
/** Règles de saisie sur l'ensemble des étapes (une règle peut dépendre d'un champ d'une autre étape). */
|
|
68
|
+
private applyRules;
|
|
69
|
+
/** Valeurs envoyées : verrouillés par règle gardés, exclus retirés, submitAs, listes masquées vides, transformOut. */
|
|
70
|
+
private submitValues;
|
|
45
71
|
isVisible(field: DynamicFormField, form: FormGroup): boolean;
|
|
46
72
|
nextStep(i: number): void;
|
|
47
73
|
goToStep(i: number): void;
|
|
@@ -53,6 +79,6 @@ export declare class StepperFormComponent implements OnInit, OnChanges {
|
|
|
53
79
|
getAllValues(): Record<string, any>;
|
|
54
80
|
private getAllRawValues;
|
|
55
81
|
static ɵfac: i0.ɵɵFactoryDeclaration<StepperFormComponent, never>;
|
|
56
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<StepperFormComponent, "ngx-stepper-form", never, { "config": { "alias": "config"; "required": true; }; "initialValues": { "alias": "initialValues"; "required": false; }; }, { "formSubmit": "formSubmit"; "formChange": "formChange"; "stepChange": "stepChange"; "fieldChange": "fieldChange"; }, never, never, true, never>;
|
|
82
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<StepperFormComponent, "ngx-stepper-form", never, { "config": { "alias": "config"; "required": true; }; "initialValues": { "alias": "initialValues"; "required": false; }; "hiddenFields": { "alias": "hiddenFields"; "required": false; }; "excludeFromSubmit": { "alias": "excludeFromSubmit"; "required": false; }; "rules": { "alias": "rules"; "required": false; }; "transformIn": { "alias": "transformIn"; "required": false; }; "transformOut": { "alias": "transformOut"; "required": false; }; }, { "formSubmit": "formSubmit"; "formChange": "formChange"; "stepChange": "stepChange"; "fieldChange": "fieldChange"; }, never, never, true, never>;
|
|
57
83
|
}
|
|
58
84
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
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' | 'repeater' | 'questionnaire';
|
|
2
2
|
export interface SelectOption {
|
|
3
3
|
label: string;
|
|
4
4
|
value: any;
|
|
@@ -10,12 +10,47 @@ export interface SelectOption {
|
|
|
10
10
|
* (badge « Obligatoire »), e.g. a mandatory guarantee.
|
|
11
11
|
*/
|
|
12
12
|
locked?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* type: 'multiselect' + display: 'cards' — valeurs des options cochées en même temps que celle-ci
|
|
15
|
+
* (ex. cocher « Invalidité totale » coche « Invalidité partielle »). Décochée, elle retire ce qu'elle a ajouté.
|
|
16
|
+
*/
|
|
17
|
+
includes?: any[];
|
|
18
|
+
/** Options incluses grisées : non décochables tant que cette option est cochée (défaut : field.lockIncludedOptions). */
|
|
19
|
+
includesLocked?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Question d'un champ type: 'questionnaire' (réponse Oui / Non, précision demandée si Oui). */
|
|
22
|
+
export interface QuestionItem {
|
|
23
|
+
/** Clé de la réponse dans la valeur du champ (précision : code + detailsSuffix). */
|
|
24
|
+
code: string;
|
|
25
|
+
label: string;
|
|
26
|
+
/** Précision demandée (et obligatoire) quand la réponse est Oui. */
|
|
27
|
+
details?: boolean;
|
|
28
|
+
/** Réponse obligatoire. @default true */
|
|
29
|
+
required?: boolean;
|
|
13
30
|
}
|
|
14
31
|
export interface FieldCondition {
|
|
15
32
|
field: string;
|
|
16
33
|
operator: 'equals' | 'notEquals' | 'contains' | 'greaterThan' | 'lessThan' | 'exists' | 'notExists';
|
|
17
34
|
value?: any;
|
|
18
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Valeur imposée à un champ quand des conditions sur les autres champs sont vraies (première règle vraie
|
|
38
|
+
* retenue). `lock` : le champ est aussi verrouillé (non modifiable) — sa valeur reste envoyée.
|
|
39
|
+
*/
|
|
40
|
+
export interface ValueRule {
|
|
41
|
+
when: FieldCondition | FieldCondition[];
|
|
42
|
+
/** Logique entre les conditions de `when`. @default 'AND' */
|
|
43
|
+
logic?: 'AND' | 'OR';
|
|
44
|
+
value: any;
|
|
45
|
+
lock?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** Règles de saisie calculées par l'application (entrée `rules` des formulaires) : même effet que valueWhen. */
|
|
48
|
+
export type FormRulesFn = (values: Record<string, any>) => {
|
|
49
|
+
values?: Record<string, any>;
|
|
50
|
+
locked?: string[];
|
|
51
|
+
} | void;
|
|
52
|
+
/** Conversion des valeurs à l'ouverture (`transformIn`) ou à l'envoi (`transformOut`) par l'application. */
|
|
53
|
+
export type FormValuesTransform = (values: Record<string, any>) => Record<string, any>;
|
|
19
54
|
export interface FieldValidation {
|
|
20
55
|
required?: boolean;
|
|
21
56
|
minLength?: number;
|
|
@@ -152,6 +187,15 @@ export interface DynamicFormField {
|
|
|
152
187
|
* display: 'cards' shows each group as an exclusive « Une seule option » section.
|
|
153
188
|
*/
|
|
154
189
|
optionGroupKey?: string;
|
|
190
|
+
/**
|
|
191
|
+
* Options from `url`: item property listing the values checked along with this option (array, or text
|
|
192
|
+
* separated by commas) — mapped to SelectOption.includes.
|
|
193
|
+
*/
|
|
194
|
+
optionIncludesKey?: string;
|
|
195
|
+
/** Options from `url`: item property (boolean) mapped to SelectOption.includesLocked. */
|
|
196
|
+
optionIncludesLockedKey?: string;
|
|
197
|
+
/** Default of SelectOption.includesLocked: options checked by an inclusion are greyed (not uncheckable). */
|
|
198
|
+
lockIncludedOptions?: boolean;
|
|
155
199
|
/**
|
|
156
200
|
* type: 'custom' — name of a component registered by the host application
|
|
157
201
|
* (provideNgxForms({ customFields: { name: Component } })). It receives `field` and `form`
|
|
@@ -160,6 +204,49 @@ export interface DynamicFormField {
|
|
|
160
204
|
component?: string;
|
|
161
205
|
/** type: 'custom' — free configuration passed to the component (field.componentConfig). */
|
|
162
206
|
componentConfig?: Record<string, any>;
|
|
207
|
+
/** Champs (colonnes) de chaque ligne, avec leurs validations. Valeur du champ : tableau d'objets. */
|
|
208
|
+
itemFields?: DynamicFormField[];
|
|
209
|
+
/** Libellé du bouton d'ajout (défaut « Ajouter une ligne »). */
|
|
210
|
+
addLabel?: string;
|
|
211
|
+
/** Texte affiché quand la liste n'a aucune ligne. */
|
|
212
|
+
emptyLabel?: string;
|
|
213
|
+
/** Nombre minimum / maximum de lignes (minItems > 0 : la liste est obligatoire). */
|
|
214
|
+
minItems?: number;
|
|
215
|
+
maxItems?: number;
|
|
216
|
+
/** Questions statiques ; avec `url`, chargées depuis l'API (interpolation {{champ}} possible). */
|
|
217
|
+
questions?: QuestionItem[];
|
|
218
|
+
/** Propriétés des questions de l'API : code (défaut 'code'), libellé (défaut 'libelle', puis 'label'),
|
|
219
|
+
* précision si Oui (défaut 'precisionSiOui'), réponse obligatoire (défaut : toujours). */
|
|
220
|
+
questionCodeKey?: string;
|
|
221
|
+
questionLabelKey?: string;
|
|
222
|
+
questionDetailsKey?: string;
|
|
223
|
+
questionRequiredKey?: string;
|
|
224
|
+
/** Libellés et valeurs des réponses. @default 'Oui' / 'Non', 'OUI' / 'NON' */
|
|
225
|
+
yesLabel?: string;
|
|
226
|
+
noLabel?: string;
|
|
227
|
+
yesValue?: any;
|
|
228
|
+
noValue?: any;
|
|
229
|
+
/** Précision : libellé (défaut « Si oui, précisez »), aide, suffixe de sa clé (défaut 'Precision'). */
|
|
230
|
+
detailsLabel?: string;
|
|
231
|
+
detailsPlaceholder?: string;
|
|
232
|
+
detailsSuffix?: string;
|
|
233
|
+
/** Champ affiché (et utilisable dans les conditions, cascades…) mais absent des valeurs envoyées. */
|
|
234
|
+
excludeFromSubmit?: boolean;
|
|
235
|
+
/** Envoi sous forme d'objet : 5 → { id: 5 } (clé : displayValue, défaut 'id'). Tableau : chaque valeur.
|
|
236
|
+
* À l'ouverture, un objet reçu est ramené à sa valeur. */
|
|
237
|
+
submitAs?: 'object';
|
|
238
|
+
/** À l'ouverture, si le champ est vide : valeur lue à ce chemin des valeurs initiales
|
|
239
|
+
* (ex. 'typeGarantie.brancheId'). */
|
|
240
|
+
initialFrom?: string;
|
|
241
|
+
/** Valeurs imposées selon les autres champs (voir ValueRule). */
|
|
242
|
+
valueWhen?: ValueRule[];
|
|
243
|
+
/** Champ verrouillé (non modifiable, valeur conservée et envoyée) quand ces conditions sont vraies. */
|
|
244
|
+
disabledWhen?: FieldCondition | FieldCondition[];
|
|
245
|
+
/** Logique entre les conditions de disabledWhen. @default 'AND' */
|
|
246
|
+
disabledWhenLogic?: 'AND' | 'OR';
|
|
247
|
+
/** Valeurs de repli des propriétés vides de chaque option avant le calcul du libellé
|
|
248
|
+
* (ex. { valeur: 0 }). Dans displayName, un repli se note aussi '{{valeur ?? 0}}'. */
|
|
249
|
+
optionDefaults?: Record<string, any>;
|
|
163
250
|
min?: number;
|
|
164
251
|
max?: number;
|
|
165
252
|
step?: number;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import { AbstractControl, FormGroup, ValidatorFn } from '@angular/forms';
|
|
1
|
+
import { AbstractControl, FormArray, FormGroup, ValidatorFn } from '@angular/forms';
|
|
2
2
|
import { DynamicFormField, FieldValidation } from '../models/form-field.model';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
export declare class DynamicFormBuilderService {
|
|
5
5
|
private uniqueness;
|
|
6
6
|
buildFormGroup(fields: DynamicFormField[]): FormGroup;
|
|
7
|
+
/** FormArray d'une liste répétable (sans ligne : les lignes initiales sont ajoutées par setRows). */
|
|
8
|
+
buildRepeater(field: DynamicFormField): FormArray;
|
|
9
|
+
/** Une ligne d'une liste répétable : FormGroup de ses itemFields (validations comprises). */
|
|
10
|
+
buildRow(field: DynamicFormField, value?: Record<string, any>): FormGroup;
|
|
11
|
+
/** Remplace les lignes d'une liste répétable par `rows` (valeurs initiales, patch). */
|
|
12
|
+
setRows(arr: FormArray, field: DynamicFormField, rows: any): void;
|
|
13
|
+
/** minItems / maxItems d'une liste répétable (erreurs minItems / maxItems). */
|
|
14
|
+
private repeaterValidator;
|
|
7
15
|
/** Build group-level validators for cross-field constraints */
|
|
8
16
|
buildGroupValidators(fields: DynamicFormField[], atLeastOneOf?: string[], atLeastOneOfMessage?: string): ValidatorFn[];
|
|
9
17
|
buildValidators(validation?: FieldValidation): ValidatorFn[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logique des formulaires sans Angular (testée par form-logic.spec.ts) : conditions, champs masqués selon
|
|
3
|
+
* l'écran, conversion des valeurs à l'ouverture et à l'envoi, règles de saisie (valeur imposée / verrou).
|
|
4
|
+
* Aucun import de valeur : le fichier doit rester exécutable seul par node (--experimental-strip-types).
|
|
5
|
+
*/
|
|
6
|
+
import type { DynamicFormField, FieldCondition } from '../models/form-field.model';
|
|
7
|
+
export declare function compareCondition(operator: FieldCondition['operator'], value: any, conditionValue: any): boolean;
|
|
8
|
+
/** Condition(s) évaluées contre `read(champ)`, en ET (défaut) ou en OU. */
|
|
9
|
+
export declare function matchesConditions(conditions: FieldCondition | FieldCondition[], logic: 'AND' | 'OR' | undefined, read: (field: string) => any): boolean;
|
|
10
|
+
/** Configuration sans les champs `keys` (à plat et dans les étapes) ; l'original n'est pas modifié. */
|
|
11
|
+
export declare function withoutFields<T extends {
|
|
12
|
+
fields?: DynamicFormField[];
|
|
13
|
+
steps?: {
|
|
14
|
+
fields: DynamicFormField[];
|
|
15
|
+
}[];
|
|
16
|
+
}>(config: T, keys: readonly string[] | null | undefined): T;
|
|
17
|
+
/**
|
|
18
|
+
* Valeurs initiales prêtes pour le formulaire : objets ramenés à leur valeur pour les listes (url, options,
|
|
19
|
+
* submitAs: 'object'), champs vides remplis depuis `initialFrom`, lignes des listes répétables converties.
|
|
20
|
+
* Les autres clés sont gardées telles quelles.
|
|
21
|
+
*/
|
|
22
|
+
export declare function toFormValues(fields: DynamicFormField[], values: Record<string, any>): Record<string, any>;
|
|
23
|
+
/**
|
|
24
|
+
* Valeurs à envoyer : valeurs des champs verrouillés par règle ajoutées (un champ désactivé n'est pas dans
|
|
25
|
+
* form.value), champs exclus retirés (excludeFromSubmit et liste `excluded` de l'écran), submitAs: 'object'
|
|
26
|
+
* appliqué, lignes des listes répétables traitées de même.
|
|
27
|
+
*/
|
|
28
|
+
export declare function prepareSubmit(fields: DynamicFormField[], values: Record<string, any>, options: {
|
|
29
|
+
excluded?: readonly string[];
|
|
30
|
+
locked?: Record<string, any>;
|
|
31
|
+
}): Record<string, any>;
|
|
32
|
+
/** Valeurs imposées (valueWhen : première règle vraie) et champs verrouillés (lock, disabledWhen). */
|
|
33
|
+
export declare function evaluateRules(fields: DynamicFormField[], read: (field: string) => any): {
|
|
34
|
+
values: Record<string, any>;
|
|
35
|
+
locked: string[];
|
|
36
|
+
};
|
|
37
|
+
/** Option vue par la logique des inclusions (sous-ensemble de SelectOption). */
|
|
38
|
+
export interface IncludeOption {
|
|
39
|
+
value: any;
|
|
40
|
+
includes?: any[];
|
|
41
|
+
includesLocked?: boolean;
|
|
42
|
+
group?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Options incluses par la sélection (inclusion directe) : grisée si l'une des options qui l'incluent a
|
|
46
|
+
* includesLocked, et la liste de ces options.
|
|
47
|
+
*/
|
|
48
|
+
export declare function includedBy(options: IncludeOption[], selected: any[]): Map<string, {
|
|
49
|
+
locked: boolean;
|
|
50
|
+
sources: any[];
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Cocher / décocher une option avec ses inclusions. Cocher : l'option et ce qu'elle inclut (par
|
|
54
|
+
* enchaînement) sont ajoutés — les ajouts sont mémorisés dans `autoAdded` ; une option d'un groupe exclusif
|
|
55
|
+
* retire ses voisines. Décocher : les options ajoutées automatiquement qui ne sont plus incluses par une option
|
|
56
|
+
* choisie sont retirées. Les options choisies par l'utilisateur ne sont jamais retirées par une inclusion.
|
|
57
|
+
*/
|
|
58
|
+
export declare function toggleWithIncludes(options: IncludeOption[], current: any[], value: any, checked: boolean, autoAdded: Set<string>): {
|
|
59
|
+
value: any[];
|
|
60
|
+
autoAdded: Set<string>;
|
|
61
|
+
};
|
|
62
|
+
/** Valeur avec les inclusions grisées des options sélectionnées (ajoutées d'office, comme les obligatoires). */
|
|
63
|
+
export declare function withLockedIncludes(options: IncludeOption[], value: any[]): any[];
|
|
64
|
+
/** Question normalisée (voir QuestionItem du modèle). */
|
|
65
|
+
export interface Question {
|
|
66
|
+
code: string;
|
|
67
|
+
label: string;
|
|
68
|
+
details: boolean;
|
|
69
|
+
required: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface ChampQuestionnaire {
|
|
72
|
+
questionCodeKey?: string;
|
|
73
|
+
questionLabelKey?: string;
|
|
74
|
+
questionDetailsKey?: string;
|
|
75
|
+
questionRequiredKey?: string;
|
|
76
|
+
yesValue?: any;
|
|
77
|
+
noValue?: any;
|
|
78
|
+
detailsSuffix?: string;
|
|
79
|
+
}
|
|
80
|
+
/** Questions reçues d'une API (ou saisies dans le formulaire) → questions normalisées ; sans code : ignorée. */
|
|
81
|
+
export declare function toQuestions(field: ChampQuestionnaire, items: any[]): Question[];
|
|
82
|
+
/** Réponse à une question : la précision n'est gardée que pour la réponse Oui. */
|
|
83
|
+
export declare function answerQuestion(field: ChampQuestionnaire, value: Record<string, any> | null, code: string, answer: any): Record<string, any>;
|
|
84
|
+
/** Erreurs par question : réponse manquante, précision manquante après Oui. */
|
|
85
|
+
export declare function questionErrors(field: ChampQuestionnaire, questions: Question[], value: Record<string, any> | null): Record<string, string>;
|
|
86
|
+
/** Nombre de questions répondues. */
|
|
87
|
+
export declare function answeredCount(questions: Question[], value: Record<string, any> | null): number;
|
|
88
|
+
/** Réponses limitées aux questions affichées (les questions ont changé : autre risque…) ; null reste null. */
|
|
89
|
+
export declare function keepAnswers(field: ChampQuestionnaire, questions: Question[], value: Record<string, any> | null): Record<string, any> | null;
|
|
90
|
+
export {};
|
|
@@ -5,8 +5,12 @@ export declare function getPath(obj: any, path: string): any;
|
|
|
5
5
|
* - une clé ou un chemin pointé : 'codeClient', 'personnePhysique.nom'
|
|
6
6
|
* - un modèle de concaténation : '{{codeClient}} - {{telephone}}',
|
|
7
7
|
* '{{personnePhysique.nom}} {{personnePhysique.prenom}}'
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* - une valeur de repli quand la propriété est vide : '{{libelle}} ({{valeur ?? 0}})', "{{unite ?? 'FCFA'}}"
|
|
9
|
+
* Dans un modèle, une valeur absente (null/undefined) est remplacée par '' et les espaces en trop sont
|
|
10
|
+
* réduits — on peut donc enchaîner des alternatives :
|
|
10
11
|
* '{{personnePhysique.nom}} {{personnePhysique.prenom}}{{personneMorale.raisonSociale}}'.
|
|
12
|
+
* `defaults` : valeurs de repli par chemin (field.optionDefaults), appliquées avant le calcul.
|
|
13
|
+
* Une option qui n'est pas un objet s'affiche telle quelle ; une propriété absente ou non textuelle
|
|
14
|
+
* ne s'affiche jamais « [object Object] ».
|
|
11
15
|
*/
|
|
12
|
-
export declare function optionLabel(item: any, displayName: string): string;
|
|
16
|
+
export declare function optionLabel(item: any, displayName: string, defaults?: Record<string, any>): string;
|
package/package.json
CHANGED
package/public-api.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ export { StepperFormComponent } from './lib/components/stepper-form/stepper-form
|
|
|
4
4
|
export { FormBuilderComponent } from './lib/components/form-builder/form-builder.component';
|
|
5
5
|
export { MesFormulairesComponent } from './lib/components/mes-formulaires/mes-formulaires.component';
|
|
6
6
|
export { FormLoaderComponent } from './lib/components/form-loader/form-loader.component';
|
|
7
|
+
export { RepeaterFieldComponent } from './lib/components/repeater-field/repeater-field.component';
|
|
8
|
+
export { QuestionnaireFieldComponent } from './lib/components/questionnaire-field/questionnaire-field.component';
|
|
9
|
+
export { optionLabel, getPath } from './lib/utils/option-label';
|
|
10
|
+
export { withoutFields, toFormValues, prepareSubmit, evaluateRules, matchesConditions, includedBy, toggleWithIncludes, withLockedIncludes, toQuestions, answerQuestion, questionErrors, answeredCount, keepAnswers } from './lib/utils/form-logic';
|
|
7
11
|
export { ThousandsInputDirective } from './lib/utils/thousands-input.directive';
|
|
8
12
|
export { DynamicFormBuilderService } from './lib/services/dynamic-form-builder.service';
|
|
9
13
|
export { ConditionEvaluatorService } from './lib/services/condition-evaluator.service';
|
|
@@ -16,7 +20,7 @@ export { provideNgxForms, NGX_DATA_API_URL, NGX_CUSTOM_FIELDS, ngxFormsAuthInter
|
|
|
16
20
|
export type { NgxFormsOptions, NgxFormsLocalOptions, NgxFormsHttpOptions } from './lib/providers';
|
|
17
21
|
export { NgxFormsAuthService, NGX_FORMS_AUTH } from './lib/auth/ngx-forms-auth.service';
|
|
18
22
|
export type { NgxFormsAuthOptions } from './lib/auth/ngx-forms-auth.service';
|
|
19
|
-
export type { DynamicFormField, DynamicFormConfig, StepperFormConfig, FormStep, DynamicFormSubmitEvent, FieldType, FieldValidation, FieldCondition, SelectOption, } from './lib/models/form-field.model';
|
|
23
|
+
export type { DynamicFormField, DynamicFormConfig, StepperFormConfig, FormStep, DynamicFormSubmitEvent, FieldType, FieldValidation, FieldCondition, SelectOption, ValueRule, QuestionItem, FormRulesFn, FormValuesTransform, } from './lib/models/form-field.model';
|
|
20
24
|
export type { SavedFormSchema, AnyFormConfig } from './lib/models/saved-form.model';
|
|
21
25
|
export type { PhoneCountry } from './lib/data/phone-countries';
|
|
22
26
|
export { PHONE_COUNTRIES } from './lib/data/phone-countries';
|