ngx-recipe-forms 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +48 -48
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,28 +1,28 @@
1
1
  # ngx-recipe-forms
2
2
 
3
- Moteur de formulaire générique **par recette**, construit sur Angular Signal Forms (`@angular/forms/signals`, Angular 22.2) et Tailwind 4.
4
- Une recette est **un objet typé par le modèle**, déclaré dans le code ; le moteur en déduit le schéma Signal Forms, le rendu, les messages et la mise en page.
3
+ Generic **recipe-based** form engine, built on Angular Signal Forms (`@angular/forms/signals`, Angular 22.2) and Tailwind 4.
4
+ A recipe is **an object typed by the model**, declared in code; the engine derives the Signal Forms schema, the rendering, the messages and the layout from it.
5
5
 
6
- Pour écrire une recette, suivre `../../AGENTS.md` (démarche, catalogue, interdits, liste de contrôle).
6
+ To write a recipe, follow [`AGENTS.md`](https://github.com/SrenoG/ngx-recipe-forms/blob/main/AGENTS.md) (in French: method, catalog, pitfalls, checklist).
7
7
 
8
- ## Ce que fait la bibliothèque
8
+ ## What the library does
9
9
 
10
- - **Types de la recette** : `FormRecipe<TModel>`, nœuds `section`, `row`, `sectionGroup`, `field`, `linked`, `array` ; contrôles et règles contraints par le type de la valeur ; constructeur typé `recipeBuilder<TModel>()`. Les nœuds d'un élément d'`array` se construisent avec `recipeBuilder<ItemModel, RootModel>()` : leurs règles lisent la racine par `ctx.root(key)`.
11
- - **Schéma** : `RecipeSchema.build(recipe)` traduit chaque règle en une fonction native (`required`, `pattern`, `min`…, `validate`, `validateTree`, `validateAsync`, `metadata`), applique `disabled`, `hidden`, `readonly` (par champ, par section ou pour toute la recette), les règles des éléments d'`array` (`applyEach`), les règles de la liste entière (`minItems`, `maxItems`, `unique`, `validate`), les avertissements non bloquants (`warn`), les contrôles liés et `extraRules`. Une panne d'un validateur serveur pose l'avertissement « validation indisponible » sans bloquer : le serveur reste juge à l'enregistrement.
12
- - **Messages** : priorités champ → recette → défaut → message brut ; erreurs serveur affichées par leur `message`, que l’appelant a traduit, sinon par la clé `errors.<code>` ; une erreur de champ posée par l'application hôte sous la forme `{ kind: 'server', error: { code, constraint?, message } }` est lue telle quelle.
13
- - **Erreurs serveur par chemin** : `RecipeServerPaths` mémorise la correspondance position → clé des `array` à l'envoi ; `rooms[2].code` est posé sur l'élément qui occupait la position 2, l'erreur s'efface dès que la valeur change, ce qui ne se place pas sort par `unplacedServerErrors`.
14
- - **Sections** : `RecipeSections` (index des champs, compteur d'erreurs, premier champ en erreur).
15
- - **Mise en page Tailwind**, **mesure des temps de réponse** des validateurs serveur.
16
- - **Rendu** : `<app-recipe-form>`, `<app-recipe-node>`, `<app-recipe-section-group>` (formats `plain`, `panel` et `tabs`, compteurs d'erreurs par volet ou par onglet, ouverture du volet ou activation de l'onglet du premier champ en erreur ; aucun format ne détruit une section), `<app-recipe-field>`, `array` en liste ou en table avec slot et API (`addItem`, `removeItem`, `has`, `items`, tri déclaré). Wrappers par défaut `app-input-text`, `app-input-number` (décimales bornées par `minFractionDigits` et `maxFractionDigits`), `app-select`, `app-date-picker`, `app-date-picker-multiple`, `app-checkbox`, `app-button`, `app-panel`, `app-tabs` (avec `TabPanelDirective`), et `app-message` pour les messages de champ, de groupe et de liste. Sous un champ : l'aide (`hintKey`, conditionnable par `{ key, when?, showWhenReadonly? }`, masquée en lecture seule comme l'astérisque d'obligation), puis la raison traduite d'une règle `disabled` active (`reasonKey`), au même style, retirée à la réactivation. Les options `labelKey` d'un `select` sont traduites par le moteur avant d'atteindre le wrapper. Un `array` en table défile dans son propre conteneur (`overflow-x-auto`) ; un message de cellule passe à la ligne au lieu d'élargir sa colonne.
10
+ - **Recipe types**: `FormRecipe<TModel>`, nodes `section`, `row`, `sectionGroup`, `field`, `linked`, `array`; controls and rules constrained by the type of the value; typed builder `recipeBuilder<TModel>()`. The nodes of an `array` item are built with `recipeBuilder<ItemModel, RootModel>()`: their rules read the root through `ctx.root(key)`.
11
+ - **Schema**: `RecipeSchema.build(recipe)` turns each rule into a native function (`required`, `pattern`, `min`…, `validate`, `validateTree`, `validateAsync`, `metadata`), and applies `disabled`, `hidden`, `readonly` (per field, per section or for the whole recipe), the rules of `array` items (`applyEach`), the rules of the whole list (`minItems`, `maxItems`, `unique`, `validate`), non-blocking warnings (`warn`), linked controls and `extraRules`. When a server validator fails, the engine sets the "validation unavailable" warning without blocking: the server still decides on save.
12
+ - **Messages**: priority field → recipe → default → raw message; server errors are shown by their `message`, translated by the caller, otherwise by the key `errors.<code>`; a field error set by the host application as `{ kind: 'server', error: { code, constraint?, message } }` is read as is.
13
+ - **Server errors by path**: `RecipeServerPaths` records the position → key mapping of each `array` when the request is sent; `rooms[2].code` is set on the item that was at position 2, the error clears as soon as the value changes, and whatever cannot be placed comes out through `unplacedServerErrors`.
14
+ - **Sections**: `RecipeSections` (field index, error count, first field in error).
15
+ - **Tailwind layout**, **response time measurement** of server validators.
16
+ - **Rendering**: `<app-recipe-form>`, `<app-recipe-node>`, `<app-recipe-section-group>` (`plain`, `panel` and `tabs` formats, error counts per panel or per tab, opening the panel or activating the tab of the first field in error; no format destroys a section), `<app-recipe-field>`, `array` as a list or a table with a slot and an API (`addItem`, `removeItem`, `has`, `items`, declared sort). Default wrappers `app-input-text`, `app-input-number` (decimals bounded by `minFractionDigits` and `maxFractionDigits`), `app-select`, `app-date-picker`, `app-date-picker-multiple`, `app-checkbox`, `app-button`, `app-panel`, `app-tabs` (with `TabPanelDirective`), and `app-message` for field, group and list messages. Under a field: the hint (`hintKey`, conditional through `{ key, when?, showWhenReadonly? }`, hidden in read-only mode like the required asterisk), then the translated reason of an active `disabled` rule (`reasonKey`), in the same style, removed when the field is enabled again. The `labelKey` options of a `select` are translated by the engine before they reach the wrapper. A table `array` scrolls in its own container (`overflow-x-auto`); a cell message wraps instead of widening its column.
17
17
 
18
- ## Utilisation
18
+ ## Usage
19
19
 
20
20
  ```ts
21
- // 1. Le modèle du formulaire, en texte brut (la conversion vers le DTO reste dans le mapper).
21
+ // 1. The form model, in plain values (the conversion to the DTO stays in the mapper).
22
22
  interface CourseFormData { deliveryMode: string | null; sessions: readonly CourseSession[]; totalHours: number | null; }
23
23
  interface CourseSession extends ArrayItem { date: Date | null; hours: number | null; }
24
24
 
25
- // 2. La recette, construite avec son contexte (signaux de droits, d'options, validateurs).
25
+ // 2. The recipe, built from its context (permission signals, options, validators).
26
26
  const b = recipeBuilder<CourseFormData>();
27
27
  const item = recipeBuilder<Omit<CourseSession, 'key'>, CourseFormData>();
28
28
  export const courseRecipe = (ctx: Ctx) => b.recipe('course', {
@@ -48,7 +48,7 @@ export const courseRecipe = (ctx: Ctx) => b.recipe('course', {
48
48
  ],
49
49
  });
50
50
 
51
- // 3. L'appelant crée le FieldTree et reçoit la valeur soumise.
51
+ // 3. The caller creates the FieldTree and receives the submitted value.
52
52
  readonly model = signal<CourseFormData>(initial);
53
53
  readonly form = form(this.model, RecipeSchema.build(this.recipe, { timing: inject(FORM_VALIDATION_TIMING) }));
54
54
  ```
@@ -69,11 +69,11 @@ readonly form = form(this.model, RecipeSchema.build(this.recipe, { timing: injec
69
69
  (dateRemoved)="api.removeItem(keyOf($event))"
70
70
  />
71
71
  </ng-template>
72
- <button appRecipeActions type="submit">Enregistrer</button>
72
+ <button appRecipeActions type="submit">Save</button>
73
73
  </app-recipe-form>
74
74
  ```
75
75
 
76
- Fournisseurs : `provideRecipeForms({ production, translator, translationChanges, keyGenerator })`. `translator` et `translationChanges` sont des fabriques exécutées dans le contexte d'injection (`useFactory`). Par exemple avec Transloco :
76
+ Providers: `provideRecipeForms({ production, translator, translationChanges, keyGenerator })`. `translator` and `translationChanges` are factories run in the injection context (`useFactory`). For example with Transloco:
77
77
 
78
78
  ```ts
79
79
  provideRecipeForms({
@@ -82,50 +82,50 @@ provideRecipeForms({
82
82
  const transloco = inject(TranslocoService);
83
83
  return (key, params) => transloco.translate(key, params);
84
84
  },
85
- // Un objet nouveau à chaque événement : scope chargé en différé, langue changée.
85
+ // A new object on each event: lazily loaded scope, language change.
86
86
  translationChanges: () => toSignal(inject(TranslocoService).events$),
87
87
  });
88
88
  ```
89
89
 
90
- `translationChanges` (jeton `RECIPE_FORM_TRANSLATION_CHANGES`, par défaut un signal constant) renvoie un signal dont la valeur change à chaque chargement ou changement de traductions. Le moteur le lit avant d'appeler le traducteur dans les titres d'onglets, les textes des compteurs d'erreurs, les options `labelKey` d'un `select` et le pipe `recipeTranslate` : un scope chargé après le premier rendu remplace les clés brutes affichées. Une valeur égale à la précédente (`Object.is`) ne déclenche rien : avec Transloco, `langChanges$` seul ne suffit pas, il ne change pas au chargement d'un scope.
90
+ `translationChanges` (token `RECIPE_FORM_TRANSLATION_CHANGES`, a constant signal by default) returns a signal whose value changes each time translations are loaded or changed. The engine reads it before calling the translator for tab titles, error count texts, the `labelKey` options of a `select` and the `recipeTranslate` pipe: a scope loaded after the first render replaces the raw keys on screen. A value equal to the previous one (`Object.is`) triggers nothing: with Transloco, `langChanges$` alone is not enough, since it does not change when a scope loads.
91
91
 
92
- ## Brancher son design system
92
+ ## Plugging in your design system
93
93
 
94
- - Les sélecteurs sont `app-*` et les classes suffixées `Component`.
95
- - **Contrôles** : le moteur rend chaque contrôle (`text`, `number`, `select`, `date`, `dateMultiple`, `checkbox`) par un gabarit du registre `RecipeUi`. L'hôte passe à `provideRecipeForms({ ui })` un composant qui déclare un `<ng-template appRecipeTextControl let-field let-inputId="inputId" …>` (`appRecipeNumberControl`, `appRecipeSelectControl`, `appRecipeDateControl`, `appRecipeDateMultipleControl`, `appRecipeCheckboxControl`) par contrôle à rendre avec son design system, et y lie son wrapper par `[formField]="field"`. Un contrôle qu'il ne déclare pas garde le gabarit par défaut. `RecipeDefaultUiComponent` (`ui/recipe-default-ui.ts`) déclare les six gabarits avec les wrappers de `ui/` et sert de modèle ; le contexte de chaque gabarit est typé (`RecipeTextControlContext`…). Le registre crée ces composants une fois, hors de l'arbre de l'application ; la vue d'un gabarit est rafraîchie avec le champ qui l'insère, et mise à jour en place quand son contexte change (le contrôle garde son focus). Tests d'apprentissage : `specs/ui-seam.learning.spec.ts`.
96
- - **Messages, boutons, volets et onglets** : le moteur les rend par `app-recipe-message`, `app-recipe-button`, `app-recipe-panel` et `app-recipe-tabs`, qui gardent l'identifiant visé par `aria-describedby`, les classes de placement et l'état (volet replié, onglet actif), et rendent à l'intérieur le gabarit du registre : `appRecipeMessage` (texte traduit, `severity`, `inline`), `appRecipeButton` (libellé, `variant`, `severity`, `click`), `appRecipePanel` (`let-content` à rendre par `ngTemplateOutlet`, textes, `collapsed` et `toggle`), `appRecipeTabs` (`let-panels`, un `{ value, template }` par section à rendre sans jamais le détruire, `options`, `value`, `select`, `fill`). Le gabarit des onglets suit les panneaux par `value` : la liste est recréée à chaque calcul du contexte.
97
- - Pour un champ isolé, un contrôle `SLOT` rend le gabarit fourni par l'appelant. Les wrappers de `ui/` restent ceux des gabarits par défaut. Contrats attendus des wrappers :
98
- - chaque contrôle : contrat Signal Forms (`value` ou `checked`, `disabled`, `invalid`, `touched`, sortie `touch`), entrées `inputId` et `describedBy` (`aria-describedby` posé sur l'élément qui reçoit le focus), méthode `focus(options?: FocusOptions)` qui transmet `options` au focus natif (focus du premier champ en erreur, appelé avec `preventScroll: true` : le moteur fait ensuite défiler `app-recipe-field` au centre par `scrollIntoView({ block: 'center' })`) ;
99
- - `app-input-text` : `placeholder` (`''` par défaut), `inputmode` (`'text'` par défaut), `maxLength` (entrée de `FormValueControl`, liée par `[formField]` à la règle `MAX_LENGTH`), `icon` (icône de fin de champ, absente par défaut ; le moteur passe `TextControlDef.icon` tel quel, un nom d'icône du wrapper de l'hôte, `string` par défaut et restreint aux noms de l'hôte s'il étend `RecipeIconTypes` (`declare module 'ngx-recipe-forms' { interface RecipeIconTypes { icon: IconEnum } }`) ; le wrapper par défaut l'accepte sans la dessiner) ;
100
- - `app-input-number` : `step`, `minFractionDigits` (décimales toujours affichées), `maxFractionDigits` (décimales admises à la saisie, 3 par défaut) ;
101
- - `app-select` : `options: SelectOption<T>[]` (`[]` par défaut ; le champ en passe une copie, `label` déjà traduit pour une option de recette en `labelKey`), `showClear`, `filter` (recherche dans la liste, `false` par défaut ; le moteur passe `filter ?? false` ; le `<select>` natif du wrapper par défaut l'ignore et garde la recherche du navigateur par premières lettres), `ariaLabelledBy` (identifiant du libellé : la liste d'un design system n'est souvent pas un champ natif), `placeholder` (texte affiché quand la valeur est `null`, traduction de `SelectControlDef.placeholderKey`, `''` sans clé). En `readonly`, la liste reste focalisable (jamais `disabled` pour la lecture seule), ne s'ouvre pas, ne change pas de valeur au clavier, n'a ni chevron ni curseur main et porte `aria-readonly="true"` ; le contexte `RecipeSelectControlContext` transmet `placeholder` et `readonly` au gabarit. Spec de contrat du gabarit par défaut : `specs/recipe-select-readonly.spec.ts` ;
102
- - `app-date-picker-multiple` : `FormValueControl<readonly Date[]>`, `maxDate`, `numberOfMonths` (mois affichés côte à côte, 3 par défaut ; le moteur passe `months ?? 3` ; le champ natif du wrapper par défaut l'ignore), `ariaLabel` (nom du groupe, le libellé traduit), sorties `dateAdded` et `dateRemoved` à chaque jour coché ou décoché ;
103
- - `app-panel` : `header`, `collapsible`, `collapsed` (modèle), `badge` (nombre, absent à zéro), `badgeLabel`, `collapseLabel` et `expandLabel` (nom du bouton de repli, avec `aria-expanded`) ;
104
- - `app-tabs` : `value` (modèle, `string`), `options: TabOption[]` (`label`, `value`, `disabled`, `badge` absent à zéro, `badgeLabel` ; même forme que `SelectOption<string>`), `fill` (`false` par défaut ; vrai : sous 768 px, les onglets se partagent toute la largeur, `flex-1` sur une base nulle, et leur titre passe à la ligne entre les mots seulement, sans couper un mot, aucun onglet hors de vue ; marges et texte réduits (`px-2`, `text-xs`) ; pastille au coin haut droit de l'onglet (`absolute`, onglet `relative`), dans un espace haut réservé même sans compteur (`pt-6`) : le titre a toute la largeur et l'onglet la même hauteur avec ou sans compteur ; rien ne change au-dessus ; le groupe de sections le passe à vrai) ; un panneau par `<ng-template [appTabPanel]="valeur">` projeté (`TabPanelDirective`, dans l'ordre des gabarits), masqué (`hidden`) quand son onglet est inactif et jamais détruit ; la barre seule sans gabarit ; motif ARIA des onglets (`aria-controls`, `aria-labelledby`, focus mobile, flèches, Début, Fin) ; barre collante en haut du conteneur qui défile (`sticky z-10`, fond blanc opaque), panneaux dans le même bloc, à `top: var(--app-sticky-top, 0px)` (classe `top-[var(--app-sticky-top,0px)]`) : un conteneur qui défile avec une marge haute pose `--app-sticky-top` au négatif de cette marge (`-20px` pour 20 px), sinon le contenu reste visible dans la bande au-dessus de la barre collée ; changement d'onglet par l'utilisateur (clic ou clavier) quand la barre est collée (haut de l'hôte au-dessus du haut de la barre) : l'hôte défile au début de la zone (`scrollIntoView({ block: 'start' })`, après le rendu), rien sans défilement préalable, rien quand `value` change par le parent (onglet du premier champ en erreur : le focus du champ pilote) ; nom de l'onglet (et du panneau) = titre seul, `badgeLabel` dans un élément `hidden` visé par `aria-describedby` de l'onglet, pastille en `aria-hidden` ; même hauteur d'onglet avec ou sans pastille (`leading-none` dans un conteneur `h-5`, la ligne du titre) ;
105
- - `app-checkbox` (et tout gabarit `appRecipeCheckboxControl`) : `FormCheckboxControl` ; en `readonly`, la case ne change jamais d'état, ni à l'écran ni pour les technologies d'assistance (clic, clic sur le libellé et Espace annulés, la case native ne se coche pas), reste focalisable (jamais `disabled` pour la lecture seule), porte `aria-readonly="true"` sur l'élément focalisable, et garde le curseur par défaut sur la case et son libellé. Le contexte `RecipeCheckboxControlContext` transmet `readonly` au gabarit. Spec de contrat du gabarit par défaut : `specs/recipe-readonly-field.spec.ts` ;
106
- - `app-message` : `severity` (`SeverityEnum`, dont la clé `WARNING`), `inline`, contenu projeté ; `[id]` posé sur l'élément hôte.
107
- - Traducteur : `RECIPE_FORM_TRANSLATOR` et `RECIPE_FORM_TRANSLATION_CHANGES` sont fournis par `useFactory` : la fabrique peut injecter le service i18n de l'application (voir « Fournisseurs » ci-dessus). Sans traducteur, la clé est affichée telle quelle. Le pipe `recipeTranslate` est impur (scopes chargés en différé).
108
- - `translationChanges` : les options `labelKey` d'un `select`, les titres d'onglets et les textes des compteurs sont traduits par le traducteur dans un `computed`, pas par le pipe impur : ils se recalculent à chaque changement de leurs données et, avec `translationChanges`, à chaque chargement de traductions ; sans cette option, le scope qui porte leurs clés doit être chargé avant le rendu du formulaire.
109
- - Clés par défaut : elles sont listées par la constante `RECIPE_FORM_DEFAULT_KEYS` (`constants/recipe-form-default-keys.constants.ts`) ; une spec de l'hôte vérifie que son dictionnaire, mis à plat (`forms.array.add`), contient chacune (modèle : `projects/playground/src/app/i18n/fr.spec.ts`) : `forms.errors.*` (dont `minItems`, `maxItems`, `unique`), `forms.warnings.validationUnavailable`, `forms.pending`, `forms.array.*`, `forms.display.errorCountOne` et `forms.display.errorCount` (« {{ count }} erreur », « {{ count }} erreurs » : le moteur prend la première pour `count` égal à 1, la seconde sinon, le traducteur n'ayant pas de pluriel), `forms.display.collapsePanel` et `forms.display.expandPanel` (« Replier le volet {{ title }} », « Déplier le volet {{ title }} »), et, hors de la constante, `errors.<code>` (ou `<scope>.errors.<code>`) pour les codes serveur.
94
+ - Selectors are `app-*` and classes end with `Component`.
95
+ - **Controls**: the engine renders each control (`text`, `number`, `select`, `date`, `dateMultiple`, `checkbox`) with a template from the `RecipeUi` registry. The host passes to `provideRecipeForms({ ui })` a component that declares one `<ng-template appRecipeTextControl let-field let-inputId="inputId" …>` (`appRecipeNumberControl`, `appRecipeSelectControl`, `appRecipeDateControl`, `appRecipeDateMultipleControl`, `appRecipeCheckboxControl`) per control to render with its design system, and binds its wrapper to it with `[formField]="field"`. A control it does not declare keeps the default template. `RecipeDefaultUiComponent` (`ui/recipe-default-ui.ts`) declares the six templates with the wrappers from `ui/` and serves as a model; the context of each template is typed (`RecipeTextControlContext`…). The registry creates these components once, outside the application tree; a template's view is refreshed with the field that inserts it, and updated in place when its context changes (the control keeps its focus). Learning tests: `specs/ui-seam.learning.spec.ts`.
96
+ - **Messages, buttons, panels and tabs**: the engine renders them through `app-recipe-message`, `app-recipe-button`, `app-recipe-panel` and `app-recipe-tabs`, which keep the id targeted by `aria-describedby`, the placement classes and the state (collapsed panel, active tab), and render the registry template inside: `appRecipeMessage` (translated text, `severity`, `inline`), `appRecipeButton` (label, `variant`, `severity`, `click`), `appRecipePanel` (`let-content` to render with `ngTemplateOutlet`, texts, `collapsed` and `toggle`), `appRecipeTabs` (`let-panels`, one `{ value, template }` per section, to render without ever destroying it, `options`, `value`, `select`, `fill`). The tabs template tracks panels by `value`: the list is recreated on each computation of the context.
97
+ - For a single field, a `SLOT` control renders the template provided by the caller. The wrappers in `ui/` remain those of the default templates. Contracts expected from the wrappers:
98
+ - every control: Signal Forms contract (`value` or `checked`, `disabled`, `invalid`, `touched`, `touch` output), `inputId` and `describedBy` inputs (`aria-describedby` set on the element that receives focus), a `focus(options?: FocusOptions)` method that passes `options` to the native focus (focus of the first field in error, called with `preventScroll: true`: the engine then scrolls `app-recipe-field` to the center with `scrollIntoView({ block: 'center' })`);
99
+ - `app-input-text`: `placeholder` (`''` by default), `inputmode` (`'text'` by default), `maxLength` (a `FormValueControl` input, bound by `[formField]` to the `MAX_LENGTH` rule), `icon` (trailing icon, none by default; the engine passes `TextControlDef.icon` as is, an icon name of the host's wrapper, `string` by default and restricted to the host's names if it extends `RecipeIconTypes` (`declare module 'ngx-recipe-forms' { interface RecipeIconTypes { icon: IconEnum } }`); the default wrapper accepts it without drawing it);
100
+ - `app-input-number`: `step`, `minFractionDigits` (decimals always shown), `maxFractionDigits` (decimals allowed when typing, 3 by default);
101
+ - `app-select`: `options: SelectOption<T>[]` (`[]` by default; the field passes a copy, with `label` already translated for a recipe option using `labelKey`), `showClear`, `filter` (search in the list, `false` by default; the engine passes `filter ?? false`; the native `<select>` of the default wrapper ignores it and keeps the browser's first-letter search), `ariaLabelledBy` (id of the label: a design system's dropdown is often not a native field), `placeholder` (text shown when the value is `null`, translation of `SelectControlDef.placeholderKey`, `''` without a key). In `readonly` mode, the list stays focusable (never `disabled` for read-only), does not open, does not change value from the keyboard, has neither chevron nor pointer cursor and carries `aria-readonly="true"`; the `RecipeSelectControlContext` context passes `placeholder` and `readonly` to the template. Contract spec of the default template: `specs/recipe-select-readonly.spec.ts`;
102
+ - `app-date-picker-multiple`: `FormValueControl<readonly Date[]>`, `maxDate`, `numberOfMonths` (months shown side by side, 3 by default; the engine passes `months ?? 3`; the native field of the default wrapper ignores it), `ariaLabel` (name of the group, the translated label), `dateAdded` and `dateRemoved` outputs for each day checked or unchecked;
103
+ - `app-panel`: `header`, `collapsible`, `collapsed` (model), `badge` (number, absent at zero), `badgeLabel`, `collapseLabel` and `expandLabel` (name of the collapse button, with `aria-expanded`);
104
+ - `app-tabs`: `value` (model, `string`), `options: TabOption[]` (`label`, `value`, `disabled`, `badge` absent at zero, `badgeLabel`; same shape as `SelectOption<string>`), `fill` (`false` by default; when true: below 768 px, the tabs share the full width, `flex-1` on a zero basis, and their title wraps between words only, never inside a word, so no tab is out of view; smaller padding and text (`px-2`, `text-xs`); badge in the top right corner of the tab (`absolute`, tab `relative`), in a top space reserved even without a count (`pt-6`): the title gets the full width and the tab keeps the same height with or without a count; nothing changes above that width; the section group sets it to true); one panel per projected `<ng-template [appTabPanel]="value">` (`TabPanelDirective`, in template order), hidden (`hidden`) when its tab is inactive and never destroyed; the bar alone without a template; ARIA tabs pattern (`aria-controls`, `aria-labelledby`, roving focus, arrows, Home, End); sticky bar at the top of the scrolling container (`sticky z-10`, opaque white background), panels in the same block, at `top: var(--app-sticky-top, 0px)` (class `top-[var(--app-sticky-top,0px)]`): a scrolling container with a top padding sets `--app-sticky-top` to the negative of that padding (`-20px` for 20 px), otherwise content stays visible in the strip above the stuck bar; when the user changes tab (click or keyboard) while the bar is stuck (top of the host above the top of the bar), the host scrolls to the start of the area (`scrollIntoView({ block: 'start' })`, after rendering), nothing without prior scrolling, nothing when `value` is changed by the parent (tab of the first field in error: the field's focus takes over); name of the tab (and of the panel) = title only, `badgeLabel` in a `hidden` element targeted by the tab's `aria-describedby`, badge `aria-hidden`; same tab height with or without a badge (`leading-none` in an `h-5` container, the title's line);
105
+ - `app-checkbox` (and any `appRecipeCheckboxControl` template): `FormCheckboxControl`; in `readonly` mode, the box never changes state, neither on screen nor for assistive technologies (click, click on the label and Space are cancelled, the native box does not get checked), stays focusable (never `disabled` for read-only), carries `aria-readonly="true"` on the focusable element, and keeps the default cursor on the box and its label. The `RecipeCheckboxControlContext` context passes `readonly` to the template. Contract spec of the default template: `specs/recipe-readonly-field.spec.ts`;
106
+ - `app-message`: `severity` (`SeverityEnum`, including the `WARNING` key), `inline`, projected content; `[id]` set on the host element.
107
+ - Translator: `RECIPE_FORM_TRANSLATOR` and `RECIPE_FORM_TRANSLATION_CHANGES` are provided with `useFactory`: the factory can inject the application's i18n service (see "Providers" above). Without a translator, the key is shown as is. The `recipeTranslate` pipe is impure (lazily loaded scopes).
108
+ - `translationChanges`: the `labelKey` options of a `select`, tab titles and count texts are translated by the translator in a `computed`, not by the impure pipe: they are recomputed whenever their data changes and, with `translationChanges`, whenever translations load; without this option, the scope that holds their keys must be loaded before the form renders.
109
+ - Default keys: they are listed by the `RECIPE_FORM_DEFAULT_KEYS` constant (`constants/recipe-form-default-keys.constants.ts`); a host spec checks that its flattened dictionary (`forms.array.add`) contains each of them (model: `projects/playground/src/app/i18n/fr.spec.ts`): `forms.errors.*` (including `minItems`, `maxItems`, `unique`), `forms.warnings.validationUnavailable`, `forms.pending`, `forms.array.*`, `forms.display.errorCountOne` and `forms.display.errorCount` ("{{ count }} error", "{{ count }} errors": the engine uses the first one when `count` is 1 and the second otherwise, since the translator has no plural), `forms.display.collapsePanel` and `forms.display.expandPanel` ("Collapse panel {{ title }}", "Expand panel {{ title }}"), and, outside the constant, `errors.<code>` (or `<scope>.errors.<code>`) for server codes.
110
110
 
111
- ## Dans l'application hôte
111
+ ## In the host application
112
112
 
113
- - Tailwind 4 : les classes de la bibliothèque sont littérales. Si le paquet est consommé depuis `node_modules`, ajouter `@source "../node_modules/ngx-recipe-forms";` dans la feuille de style de l'hôte.
114
- - Les validateurs serveur (`ServerValidator<T>`) renvoient un `Observable<ServerValidationResult>` ; l'adaptateur vers les services HTTP de l'application s'écrit chez l'appelant. Un validateur qui a besoin d'autres clés du modèle (par exemple la date de début et le format d'une formation) se déclare `ServerValidator<T, RootModel>`, reçoit `(value, ctx)` et lit par `ctx.root(key)` les clés que sa règle déclare dans `dependsOn`. Les erreurs d'une écriture (`RecipeServerError[]` : `fields`, `code`, `message?`) se passent telles quelles à `serverErrors`.
115
- - Les règles `server` appellent leur validateur par la ressource de `RECIPE_FORM_RX_RESOURCE` (`rxResource` par défaut) : une application qui impose son propre wrapper de ressources le passe à `provideRecipeForms({ rxResource })`, avec la signature de `rxResource`. Le collecteur de temps est un `@Service({ autoProvided: false })`.
116
- - `npm run check:loose` compile la bibliothèque et ses specs sous des options moins strictes, comme une application qui ne fixe ni `strict` ni `strictTemplates` : les `@ts-expect-error` de `recipe-types.spec.ts` doivent tenir. Les specs n'utilisent aucune API propre à Vitest 5. Celles qui soumettent un formulaire invalide remplacent `Element.prototype.scrollIntoView`, que jsdom n'implémente pas, par un espion `vi.fn` le temps de chaque test ; une spec de l'hôte qui soumet un formulaire de recette invalide fait de même.
113
+ - Tailwind 4: the library's classes are literal. If the package is consumed from `node_modules`, add `@source "../node_modules/ngx-recipe-forms";` to the host's stylesheet.
114
+ - Server validators (`ServerValidator<T>`) return an `Observable<ServerValidationResult>`; the adapter to the application's HTTP services is written by the caller. A validator that needs other keys of the model (for example the start date and the format of a training course) is declared `ServerValidator<T, RootModel>`, receives `(value, ctx)` and reads through `ctx.root(key)` the keys its rule declares in `dependsOn`. The errors of a write (`RecipeServerError[]`: `fields`, `code`, `message?`) are passed as is to `serverErrors`.
115
+ - `server` rules call their validator through the resource of `RECIPE_FORM_RX_RESOURCE` (`rxResource` by default): an application that enforces its own resource wrapper passes it to `provideRecipeForms({ rxResource })`, with the signature of `rxResource`. The timing collector is a `@Service({ autoProvided: false })`.
116
+ - `npm run check:loose` compiles the library and its specs under less strict options, like an application that sets neither `strict` nor `strictTemplates`: the `@ts-expect-error` of `recipe-types.spec.ts` must hold. The specs use no API specific to Vitest 5. Those that submit an invalid form replace `Element.prototype.scrollIntoView`, which jsdom does not implement, with a `vi.fn` spy for each test; a host spec that submits an invalid recipe form must do the same.
117
117
 
118
- ## Commandes
118
+ ## Commands
119
119
 
120
120
  ```bash
121
121
  npm run build:lib # ng build recipe-forms
122
- npm run pack:lib # construit puis emballe le paquet (dist/ngx-recipe-forms-<version>.tgz)
123
- npm run publish:lib # construit puis publie dist/recipe-forms sur npm
122
+ npm run pack:lib # builds then packs the package (dist/ngx-recipe-forms-<version>.tgz)
123
+ npm run publish:lib # builds then publishes dist/recipe-forms to npm
124
124
  npm run test:lib # ng test recipe-forms --watch=false
125
- npm run check:loose # tsc avec des options moins strictes
125
+ npm run check:loose # tsc with less strict options
126
126
  npm start # ng serve playground
127
- npm run install:host -- <dossier de l'hôte> # installe le paquet construit dans un hôte (file:…tgz)
128
- npm run export:host -- <dossier> # copie les sources dans un hôte, avec le manifeste d'empreintes
127
+ npm run install:host -- <host folder> # installs the built package in a host (file:…tgz)
128
+ npm run export:host -- <folder> # copies the sources into a host, with the hash manifest
129
129
  ```
130
130
 
131
- Les deux scripts sont décrits dans le `README.md` à la racine du dépôt (« Trying it in an application before publication », « Copying it into an application »).
131
+ Both scripts are described in the [repository README](https://github.com/SrenoG/ngx-recipe-forms#readme) ("Trying it in an application before publication", "Copying it into an application").
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "ngx-recipe-forms",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "Apache-2.0",
5
- "description": "Moteur de formulaire générique par recette (Angular Signal Forms, Tailwind)",
5
+ "description": "Generic recipe-based form engine for Angular Signal Forms, styled with Tailwind",
6
6
  "keywords": [
7
7
  "angular",
8
8
  "signal-forms",