@suntelecoms/ngx-dynamic-form 1.10.0 → 1.11.1
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 +46 -0
- package/fesm2022/suntelecoms-ngx-dynamic-form.mjs +482 -23
- package/fesm2022/suntelecoms-ngx-dynamic-form.mjs.map +1 -1
- package/lib/components/dynamic-field/dynamic-field.component.d.ts +9 -1
- package/lib/components/form-builder/form-builder.component.d.ts +16 -1
- package/lib/components/questionnaire-field/questionnaire-field.component.d.ts +37 -0
- package/lib/models/form-field.model.d.ts +44 -1
- package/lib/utils/form-logic.d.ts +54 -0
- package/package.json +1 -1
- package/public-api.d.ts +3 -2
|
@@ -126,8 +126,16 @@ export declare class DynamicFieldComponent implements OnInit {
|
|
|
126
126
|
private get cardValues();
|
|
127
127
|
get selectedCount(): number;
|
|
128
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;
|
|
129
137
|
toggleOption(opt: SelectOption, checked: boolean): void;
|
|
130
|
-
/** 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. */
|
|
131
139
|
private ensureLockedOptions;
|
|
132
140
|
get isInputField(): boolean;
|
|
133
141
|
/** type: 'custom' — composant déclaré par l'application (provideNgxForms({ customFields })). */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DynamicFormConfig, DynamicFormField, FieldCondition, FieldType, FieldValidation, RemoteSearchConfig, SelectOption, StepGuard, StepperFormConfig, ValueRule } 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,14 @@ 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
|
+
isIncluded(opt: SelectOption, value: any): boolean;
|
|
96
|
+
/** Ajoute / retire une option de « Coche aussi » (ordre des options du champ conservé). */
|
|
97
|
+
toggleOptionInclude(idx: number, value: any, checked: boolean): void;
|
|
98
|
+
/** Autres options du champ (choix de « Coche aussi »). */
|
|
99
|
+
otherOptions(idx: number): SelectOption[];
|
|
92
100
|
/** Options statiques du champ dont dépend le champ sélectionné (vide si liste API ou autre type). */
|
|
93
101
|
parentStaticOptions(): SelectOption[];
|
|
94
102
|
removeOption(idx: number): void;
|
|
@@ -108,6 +116,13 @@ export declare class FormBuilderComponent {
|
|
|
108
116
|
updateColumnRequired(index: number, required: boolean): void;
|
|
109
117
|
/** Nombre saisi (vide : undefined). */
|
|
110
118
|
numberOrUndefined(v: any): number | undefined;
|
|
119
|
+
getQuestions(): QuestionItem[];
|
|
120
|
+
addQuestion(): void;
|
|
121
|
+
removeQuestion(index: number): void;
|
|
122
|
+
updateQuestion(index: number, prop: keyof QuestionItem, value: any): void;
|
|
123
|
+
/** Source des questions : saisies ici ('static') ou chargées depuis une API ('api'). */
|
|
124
|
+
questionSource(): 'static' | 'api';
|
|
125
|
+
setQuestionSource(source: 'static' | 'api'): void;
|
|
111
126
|
/** Valeur saisie dans le constructeur : 'true' / 'false' deviennent des booléens (cases à cocher). */
|
|
112
127
|
private valeurSaisie;
|
|
113
128
|
getValueRules(): ValueRule[];
|
|
@@ -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
|
+
}
|
|
@@ -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' | 'repeater';
|
|
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,6 +10,23 @@ 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;
|
|
@@ -170,6 +187,15 @@ export interface DynamicFormField {
|
|
|
170
187
|
* display: 'cards' shows each group as an exclusive « Une seule option » section.
|
|
171
188
|
*/
|
|
172
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;
|
|
173
199
|
/**
|
|
174
200
|
* type: 'custom' — name of a component registered by the host application
|
|
175
201
|
* (provideNgxForms({ customFields: { name: Component } })). It receives `field` and `form`
|
|
@@ -187,6 +213,23 @@ export interface DynamicFormField {
|
|
|
187
213
|
/** Nombre minimum / maximum de lignes (minItems > 0 : la liste est obligatoire). */
|
|
188
214
|
minItems?: number;
|
|
189
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;
|
|
190
233
|
/** Champ affiché (et utilisable dans les conditions, cascades…) mais absent des valeurs envoyées. */
|
|
191
234
|
excludeFromSubmit?: boolean;
|
|
192
235
|
/** Envoi sous forme d'objet : 5 → { id: 5 } (clé : displayValue, défaut 'id'). Tableau : chaque valeur.
|
|
@@ -34,3 +34,57 @@ export declare function evaluateRules(fields: DynamicFormField[], read: (field:
|
|
|
34
34
|
values: Record<string, any>;
|
|
35
35
|
locked: string[];
|
|
36
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 {};
|
package/package.json
CHANGED
package/public-api.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ export { FormBuilderComponent } from './lib/components/form-builder/form-builder
|
|
|
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
7
|
export { RepeaterFieldComponent } from './lib/components/repeater-field/repeater-field.component';
|
|
8
|
+
export { QuestionnaireFieldComponent } from './lib/components/questionnaire-field/questionnaire-field.component';
|
|
8
9
|
export { optionLabel, getPath } from './lib/utils/option-label';
|
|
9
|
-
export { withoutFields, toFormValues, prepareSubmit, evaluateRules, matchesConditions } from './lib/utils/form-logic';
|
|
10
|
+
export { withoutFields, toFormValues, prepareSubmit, evaluateRules, matchesConditions, includedBy, toggleWithIncludes, withLockedIncludes, toQuestions, answerQuestion, questionErrors, answeredCount, keepAnswers } from './lib/utils/form-logic';
|
|
10
11
|
export { ThousandsInputDirective } from './lib/utils/thousands-input.directive';
|
|
11
12
|
export { DynamicFormBuilderService } from './lib/services/dynamic-form-builder.service';
|
|
12
13
|
export { ConditionEvaluatorService } from './lib/services/condition-evaluator.service';
|
|
@@ -19,7 +20,7 @@ export { provideNgxForms, NGX_DATA_API_URL, NGX_CUSTOM_FIELDS, ngxFormsAuthInter
|
|
|
19
20
|
export type { NgxFormsOptions, NgxFormsLocalOptions, NgxFormsHttpOptions } from './lib/providers';
|
|
20
21
|
export { NgxFormsAuthService, NGX_FORMS_AUTH } from './lib/auth/ngx-forms-auth.service';
|
|
21
22
|
export type { NgxFormsAuthOptions } from './lib/auth/ngx-forms-auth.service';
|
|
22
|
-
export type { DynamicFormField, DynamicFormConfig, StepperFormConfig, FormStep, DynamicFormSubmitEvent, FieldType, FieldValidation, FieldCondition, SelectOption, ValueRule, FormRulesFn, FormValuesTransform, } 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';
|
|
23
24
|
export type { SavedFormSchema, AnyFormConfig } from './lib/models/saved-form.model';
|
|
24
25
|
export type { PhoneCountry } from './lib/data/phone-countries';
|
|
25
26
|
export { PHONE_COUNTRIES } from './lib/data/phone-countries';
|