@suntelecoms/ngx-dynamic-form 1.12.1 → 1.14.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 +81 -0
- package/fesm2022/suntelecoms-ngx-dynamic-form.mjs +579 -25
- package/fesm2022/suntelecoms-ngx-dynamic-form.mjs.map +1 -1
- package/lib/components/recherche-field/recherche-field.component.d.ts +60 -0
- package/lib/models/form-field.model.d.ts +97 -1
- package/lib/utils/option-label.d.ts +10 -1
- package/lib/utils/recherche.d.ts +44 -0
- package/package.json +1 -1
- package/public-api.d.ts +5 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { OnDestroy, OnInit } from '@angular/core';
|
|
2
|
+
import { AbstractControl, FormControl, FormGroup } from '@angular/forms';
|
|
3
|
+
import { DynamicFormField, RechercheConfig } from '../../models/form-field.model';
|
|
4
|
+
import { RechercheResultat } from '../../utils/recherche';
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
/**
|
|
7
|
+
* type: 'recherche' — recherche d'une entité via une API puis fiche de la sélection (bouton « Changer »).
|
|
8
|
+
* Avec `{{q}}` dans `recherche.url` : recherche serveur (debounce, ou Entrée / bouton) ; sans : liste chargée une
|
|
9
|
+
* fois puis filtrée dans le navigateur. Valeur du champ : `recherche.valeur` de l'item choisi ; `recherche.champs`
|
|
10
|
+
* sont écrits à plat dans le formulaire. Au retour sur l'étape, la fiche est rechargée via
|
|
11
|
+
* `recherche.chargementUrl` (`{{value}}`), ou retrouvée dans la liste (mode sans `{{q}}`).
|
|
12
|
+
*/
|
|
13
|
+
export declare class RechercheFieldComponent implements OnInit, OnDestroy {
|
|
14
|
+
field: DynamicFormField;
|
|
15
|
+
form: FormGroup;
|
|
16
|
+
private readonly http;
|
|
17
|
+
private readonly dataApiUrl;
|
|
18
|
+
private readonly builder;
|
|
19
|
+
private readonly cdr;
|
|
20
|
+
private readonly manuelle$;
|
|
21
|
+
private subs;
|
|
22
|
+
/** Mode sans {{q}} : items chargés une fois, filtrés dans le navigateur. */
|
|
23
|
+
private liste;
|
|
24
|
+
readonly saisie: FormControl<string>;
|
|
25
|
+
resultats: RechercheResultat[];
|
|
26
|
+
retenu: RechercheResultat | null;
|
|
27
|
+
recherchant: boolean;
|
|
28
|
+
rechercheFaite: boolean;
|
|
29
|
+
echec: string;
|
|
30
|
+
get cfg(): RechercheConfig;
|
|
31
|
+
get control(): AbstractControl;
|
|
32
|
+
get erreur(): string | null;
|
|
33
|
+
/** Saisie d'une nouvelle entité (recherche.ajout) : le champ `ajout.champ` porte `ajout.valeur`. */
|
|
34
|
+
get nouveau(): boolean;
|
|
35
|
+
private get serveur();
|
|
36
|
+
ngOnInit(): void;
|
|
37
|
+
ngOnDestroy(): void;
|
|
38
|
+
lancer(): void;
|
|
39
|
+
choisir(r: RechercheResultat): void;
|
|
40
|
+
changer(): void;
|
|
41
|
+
/** « Ajouter » : sélection effacée, mode de saisie d'une nouvelle entité. */
|
|
42
|
+
ajouter(): void;
|
|
43
|
+
rechercherExistant(): void;
|
|
44
|
+
/** Codes techniques (EN_ATTENTE) rendus lisibles (En attente) ; le reste tel quel. */
|
|
45
|
+
lisible(valeur: string): string;
|
|
46
|
+
private poserMode;
|
|
47
|
+
private chercher;
|
|
48
|
+
private tous;
|
|
49
|
+
private charger;
|
|
50
|
+
private versResultats;
|
|
51
|
+
/** Fiche de la valeur courante : chargementUrl, sinon recherche dans la liste (mode sans {{q}}). */
|
|
52
|
+
private restaurer;
|
|
53
|
+
private appliquer;
|
|
54
|
+
/** Clés plates écrites dans le formulaire (ajoutées si l'étape ne les déclare pas). */
|
|
55
|
+
private ecrireChamps;
|
|
56
|
+
/** {{q}} / {{value}} puis {{champ}} du formulaire ; relative à dataUrl sauf 'http…' ou '/…'. */
|
|
57
|
+
private url;
|
|
58
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RechercheFieldComponent, never>;
|
|
59
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<RechercheFieldComponent, "ngx-recherche-field", never, { "field": { "alias": "field"; "required": true; }; "form": { "alias": "form"; "required": true; }; }, {}, never, never, true, never>;
|
|
60
|
+
}
|
|
@@ -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' | 'questionnaire';
|
|
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' | 'recherche';
|
|
2
2
|
export interface SelectOption {
|
|
3
3
|
label: string;
|
|
4
4
|
value: any;
|
|
@@ -154,6 +154,101 @@ export interface RemoteSearchConfig {
|
|
|
154
154
|
/** Extra static query params sent on every request (e.g. { size: 20 }). */
|
|
155
155
|
params?: Record<string, string | number>;
|
|
156
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* type: 'recherche' — recherche d'une entité via une API, puis fiche de la sélection (bouton « Changer »).
|
|
159
|
+
* Les textes (titre, sousTitre, details[].path en modèle) suivent la syntaxe de displayName :
|
|
160
|
+
* chemin pointé ou modèle '{{a}} · {{b}}' (repli '{{x ?? 0}}').
|
|
161
|
+
*/
|
|
162
|
+
export interface RechercheConfig {
|
|
163
|
+
/**
|
|
164
|
+
* Adresse de la recherche. Avec `{{q}}` (texte saisi) : appelée à chaque saisie (debounce).
|
|
165
|
+
* Sans `{{q}}` : liste chargée une fois puis filtrée dans le navigateur (titre + sous-titre).
|
|
166
|
+
* Accepte aussi `{{cléDeChamp}}` ; relative à dataUrl sauf 'http…' ou '/…'.
|
|
167
|
+
*/
|
|
168
|
+
url: string;
|
|
169
|
+
/** Clé (chemin pointé) de la liste dans la réponse ; '' = la réponse. Défaut : tableau, content, data.content, data. */
|
|
170
|
+
responseDataKey?: string;
|
|
171
|
+
/** Recherche à partir de N caractères. @default 2 */
|
|
172
|
+
minChars?: number;
|
|
173
|
+
/** Délai après la frappe, en ms. @default 350 */
|
|
174
|
+
debounceMs?: number;
|
|
175
|
+
/** Mode sans `{{q}}` : nombre maximum de résultats affichés. @default 10 */
|
|
176
|
+
maxResultats?: number;
|
|
177
|
+
placeholder?: string;
|
|
178
|
+
/** Bouton dans la barre (ex. 'Rechercher') : lance la recherche quel que soit minChars, comme Entrée. ← v1.14.0 */
|
|
179
|
+
bouton?: string;
|
|
180
|
+
/** Message quand rien ne correspond ; `{q}` = texte saisi. @default 'Aucun résultat pour « {q} ».' */
|
|
181
|
+
aucunResultat?: string;
|
|
182
|
+
/** Filtre des items reçus (propriétés brutes de l'item), même forme que optionsFilter. */
|
|
183
|
+
filtre?: FieldCondition | FieldCondition[];
|
|
184
|
+
/** @default 'AND' */
|
|
185
|
+
filtreLogic?: 'AND' | 'OR';
|
|
186
|
+
/** Propriété de l'item gardée comme valeur du champ. @default 'id' */
|
|
187
|
+
valeur?: string;
|
|
188
|
+
/** Titre (liste et fiche). @default '{{label}}' */
|
|
189
|
+
titre?: string;
|
|
190
|
+
/** Sous-titre (liste ; fiche si pas de badge). */
|
|
191
|
+
sousTitre?: string;
|
|
192
|
+
/** Titre de la fiche s'il diffère de celui de la liste (ex. propriétaire d'un véhicule). ← v1.14.0 */
|
|
193
|
+
titreFiche?: string;
|
|
194
|
+
/** Pastille de la fiche : texte fixe ('Partenaire') ou modèle ("{{statut ?? 'Contrat'}}"). */
|
|
195
|
+
badge?: string;
|
|
196
|
+
/** Icône Material de l'avatar de la fiche, à la place de l'initiale du titre (ex. 'description'). ← v1.14.0 */
|
|
197
|
+
avatar?: string;
|
|
198
|
+
/** Plaque affichée à gauche de chaque résultat (ex. '{{immatriculation || numeroChassis}}'). ← v1.14.0 */
|
|
199
|
+
etiquette?: string;
|
|
200
|
+
/** Texte à droite de chaque résultat (ex. '{{proprietaire.nom}}') : texte fixe, ou modèle avec {{…}}. ← v1.14.0 */
|
|
201
|
+
note?: string;
|
|
202
|
+
/** Résultat choisissable seulement si ces conditions (propriétés brutes de l'item) sont vraies ; sinon grisé. ← v1.14.0 */
|
|
203
|
+
selectionnable?: FieldCondition | FieldCondition[];
|
|
204
|
+
/** @default 'AND' */
|
|
205
|
+
selectionnableLogic?: 'AND' | 'OR';
|
|
206
|
+
/** Mention d'un résultat non choisissable (ex. 'Sans propriétaire client'). */
|
|
207
|
+
nonSelectionnable?: string;
|
|
208
|
+
/** Grille de la fiche ; format 'badge' = pastille de statut, 'date' = jj/mm/aaaa. Valeur vide : « Non renseigné ». */
|
|
209
|
+
details?: {
|
|
210
|
+
label: string;
|
|
211
|
+
path: string;
|
|
212
|
+
format?: 'badge' | 'date';
|
|
213
|
+
}[];
|
|
214
|
+
/**
|
|
215
|
+
* Bloc sous la fiche (ex. véhicule) : surtitre, titre et puces (texte fixe, ou modèle avec {{…}}), plaque
|
|
216
|
+
* (`etiquette` : chemin ou modèle). Affiché si la plaque est renseignée (sans plaque : si le titre l'est). ← v1.14.0
|
|
217
|
+
*/
|
|
218
|
+
encart?: {
|
|
219
|
+
icone?: string;
|
|
220
|
+
surtitre?: string;
|
|
221
|
+
titre?: string;
|
|
222
|
+
puces?: string[];
|
|
223
|
+
etiquette?: string;
|
|
224
|
+
etiquetteLabel?: string;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Bouton « Ajouter » sous la barre (saisie d'une nouvelle entité dans les autres champs) : pose `valeur` dans le
|
|
228
|
+
* champ `champ` (ex. modeSouscripteur = 'NOUVEAU') et masque la recherche ; le lien `retourLabel` (et le choix
|
|
229
|
+
* d'un résultat) y remet `retourValeur`. Les autres champs suivent avec showWhen / requiredWhen. ← v1.14.0
|
|
230
|
+
*/
|
|
231
|
+
ajout?: {
|
|
232
|
+
label: string;
|
|
233
|
+
champ: string;
|
|
234
|
+
valeur: any;
|
|
235
|
+
retourValeur?: any;
|
|
236
|
+
retourLabel?: string;
|
|
237
|
+
aide?: string;
|
|
238
|
+
icone?: string;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Valeurs écrites à plat dans le formulaire au choix (remises à null par « Changer ») :
|
|
242
|
+
* { cléDuFormulaire: source }, source = chemin ('id'), modèle ('{{prenom}} {{nom}}') ou constante entre
|
|
243
|
+
* apostrophes ("'PARTENAIRE'").
|
|
244
|
+
*/
|
|
245
|
+
champs?: Record<string, string>;
|
|
246
|
+
/** GET de la fiche d'une valeur déjà posée (retour sur l'étape) ; `{{value}}` = valeur du champ.
|
|
247
|
+
* Sans elle, la fiche est retrouvée dans la liste (mode sans `{{q}}`). */
|
|
248
|
+
chargementUrl?: string;
|
|
249
|
+
/** Libellé du bouton de la fiche. @default 'Changer' */
|
|
250
|
+
changerLabel?: string;
|
|
251
|
+
}
|
|
157
252
|
/** Async guard executed before advancing to the next stepper step */
|
|
158
253
|
export interface StepGuard {
|
|
159
254
|
url: string;
|
|
@@ -259,6 +354,7 @@ export interface DynamicFormField {
|
|
|
259
354
|
/** Nombre minimum / maximum de lignes (minItems > 0 : la liste est obligatoire). */
|
|
260
355
|
minItems?: number;
|
|
261
356
|
maxItems?: number;
|
|
357
|
+
recherche?: RechercheConfig;
|
|
262
358
|
/** Questions statiques ; avec `url`, chargées depuis l'API (interpolation {{champ}} possible). */
|
|
263
359
|
questions?: QuestionItem[];
|
|
264
360
|
/** Propriétés des questions de l'API : code (défaut 'code'), libellé (défaut 'libelle', puis 'label'),
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
/** Lit une valeur via un chemin pointé : getPath(item, 'personnePhysique.nom'). */
|
|
2
2
|
export declare function getPath(obj: any, path: string): any;
|
|
3
|
+
/** Date ISO ('2026-03-15', '2026-03-15T10:00:00') → '15/03/2026' ; autre valeur telle quelle. */
|
|
4
|
+
export declare function formatDate(v: any): string;
|
|
5
|
+
/**
|
|
6
|
+
* Première valeur non vide parmi des chemins séparés par '||' : 'immatriculation || numeroChassis'.
|
|
7
|
+
* Un seul chemin : getPath tel quel.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getFirstPath(obj: any, paths: string, defaults?: Record<string, any>): any;
|
|
3
10
|
/**
|
|
4
11
|
* Libellé d'une option chargée depuis une API. `displayName` accepte :
|
|
5
12
|
* - une clé ou un chemin pointé : 'codeClient', 'personnePhysique.nom'
|
|
13
|
+
* - des alternatives (première non vide) : 'raisonSociale || codeClient'
|
|
6
14
|
* - un modèle de concaténation : '{{codeClient}} - {{telephone}}',
|
|
7
15
|
* '{{personnePhysique.nom}} {{personnePhysique.prenom}}'
|
|
8
|
-
* -
|
|
16
|
+
* - dans un modèle : alternatives '{{immatriculation || numeroChassis}}', date '{{dateEffet | date}}' (jj/mm/aaaa),
|
|
17
|
+
* valeur de repli quand la propriété est vide '{{libelle}} ({{valeur ?? 0}})', "{{unite ?? 'FCFA'}}"
|
|
9
18
|
* Dans un modèle, une valeur absente (null/undefined) est remplacée par '' et les espaces en trop sont
|
|
10
19
|
* réduits — on peut donc enchaîner des alternatives :
|
|
11
20
|
* '{{personnePhysique.nom}} {{personnePhysique.prenom}}{{personneMorale.raisonSociale}}'.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { RechercheConfig } from '../models/form-field.model';
|
|
2
|
+
/** Résultat affiché (liste et fiche), calculé depuis un item brut de l'API. */
|
|
3
|
+
export interface RechercheResultat {
|
|
4
|
+
valeur: any;
|
|
5
|
+
titre: string;
|
|
6
|
+
sousTitre: string;
|
|
7
|
+
/** Titre de la fiche (recherche.titreFiche, sinon titre). */
|
|
8
|
+
titreFiche: string;
|
|
9
|
+
badge: string;
|
|
10
|
+
etiquette: string;
|
|
11
|
+
note: string;
|
|
12
|
+
selectionnable: boolean;
|
|
13
|
+
details: {
|
|
14
|
+
label: string;
|
|
15
|
+
valeur: string;
|
|
16
|
+
format?: 'badge' | 'date';
|
|
17
|
+
}[];
|
|
18
|
+
encart: {
|
|
19
|
+
surtitre: string;
|
|
20
|
+
titre: string;
|
|
21
|
+
puces: string[];
|
|
22
|
+
etiquette: string;
|
|
23
|
+
} | null;
|
|
24
|
+
item: any;
|
|
25
|
+
}
|
|
26
|
+
/** Liste d'items d'une réponse : tableau, `responseDataKey`, sinon content / data.content / data. */
|
|
27
|
+
export declare function rechercheItems(r: any, responseDataKey?: string): any[];
|
|
28
|
+
/** Item d'une réponse de chargement (fiche) : à la racine, ou dans `data` (enveloppe { data: {...} }). */
|
|
29
|
+
export declare function rechercheItem(r: any): any;
|
|
30
|
+
/**
|
|
31
|
+
* Texte d'un modèle pour un item : chemin, alternatives ('a || b') ou modèle ('{{a}} · {{b | date}}').
|
|
32
|
+
* Dans un modèle, les séparateurs orphelins sont retirés quand une partie est vide (« BANQUE · » → « BANQUE »).
|
|
33
|
+
*/
|
|
34
|
+
export declare function rechercheTexte(item: any, modele?: string): string;
|
|
35
|
+
/** Item brut → résultat affiché. */
|
|
36
|
+
export declare function versResultat(cfg: RechercheConfig, item: any): RechercheResultat;
|
|
37
|
+
/**
|
|
38
|
+
* Valeurs écrites à plat dans le formulaire (`champs`) : chemin ou alternatives ('id', 'a.nom || b.raisonSociale')
|
|
39
|
+
* = valeur brute ; modèle ('{{prenom}} {{nom}}') = texte ; entre apostrophes ("'PARTENAIRE'") = constante.
|
|
40
|
+
* `item` null : toutes les clés à null (« Changer »).
|
|
41
|
+
*/
|
|
42
|
+
export declare function rechercheChamps(cfg: RechercheConfig, item: any | null): Record<string, any>;
|
|
43
|
+
/** Mode sans {{q}} : résultats dont le titre, le sous-titre, l'étiquette ou la note contiennent q. */
|
|
44
|
+
export declare function filtrerResultats(liste: RechercheResultat[], q: string, max: number): RechercheResultat[];
|
package/package.json
CHANGED
package/public-api.d.ts
CHANGED
|
@@ -6,7 +6,10 @@ export { MesFormulairesComponent } from './lib/components/mes-formulaires/mes-fo
|
|
|
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
8
|
export { QuestionnaireFieldComponent } from './lib/components/questionnaire-field/questionnaire-field.component';
|
|
9
|
-
export {
|
|
9
|
+
export { RechercheFieldComponent } from './lib/components/recherche-field/recherche-field.component';
|
|
10
|
+
export { optionLabel, getPath, getFirstPath, formatDate } from './lib/utils/option-label';
|
|
11
|
+
export { rechercheItems, rechercheItem, rechercheTexte, versResultat, rechercheChamps, filtrerResultats } from './lib/utils/recherche';
|
|
12
|
+
export type { RechercheResultat } from './lib/utils/recherche';
|
|
10
13
|
export { withoutFields, toFormValues, prepareSubmit, evaluateRules, matchesConditions, includedBy, toggleWithIncludes, withLockedIncludes, toQuestions, answerQuestion, questionErrors, answeredCount, keepAnswers } from './lib/utils/form-logic';
|
|
11
14
|
export { ThousandsInputDirective } from './lib/utils/thousands-input.directive';
|
|
12
15
|
export { DynamicFormBuilderService } from './lib/services/dynamic-form-builder.service';
|
|
@@ -20,7 +23,7 @@ export { provideNgxForms, NGX_DATA_API_URL, NGX_CUSTOM_FIELDS, ngxFormsAuthInter
|
|
|
20
23
|
export type { NgxFormsOptions, NgxFormsLocalOptions, NgxFormsHttpOptions } from './lib/providers';
|
|
21
24
|
export { NgxFormsAuthService, NGX_FORMS_AUTH } from './lib/auth/ngx-forms-auth.service';
|
|
22
25
|
export type { NgxFormsAuthOptions } from './lib/auth/ngx-forms-auth.service';
|
|
23
|
-
export type { DynamicFormField, DynamicFormConfig, StepperFormConfig, FormStep, DynamicFormSubmitEvent, FieldType, FieldValidation, FieldCondition, SelectOption, ValueRule, QuestionItem, FormRulesFn, FormValuesTransform, FileUploadConfig, UploadedFileValue, } from './lib/models/form-field.model';
|
|
26
|
+
export type { DynamicFormField, DynamicFormConfig, StepperFormConfig, FormStep, DynamicFormSubmitEvent, FieldType, FieldValidation, FieldCondition, SelectOption, ValueRule, QuestionItem, FormRulesFn, FormValuesTransform, FileUploadConfig, UploadedFileValue, RechercheConfig, } from './lib/models/form-field.model';
|
|
24
27
|
export type { SavedFormSchema, AnyFormConfig } from './lib/models/saved-form.model';
|
|
25
28
|
export type { PhoneCountry } from './lib/data/phone-countries';
|
|
26
29
|
export { PHONE_COUNTRIES } from './lib/data/phone-countries';
|