@rdlabo/ionic-angular-kit 22.0.0-1 → 22.0.0-3

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 CHANGED
@@ -25,6 +25,7 @@ Install `@ionic/storage-angular` when using storage. Other peers are feature-sco
25
25
  | `@rdlabo/ionic-angular-kit` | Storage, overlays, guards, HTTP, realtime, directives, keyboard, and utilities |
26
26
  | `@rdlabo/ionic-angular-kit/offline` | Scoped local replica, outbox, pull, replay, and request policies |
27
27
  | `@rdlabo/ionic-angular-kit/theme` | Persisted light/dark theme and native status bar sync |
28
+ | `@rdlabo/ionic-angular-kit/forms` | Ionic error text and state classes for Angular Signal Forms |
28
29
  | `@rdlabo/ionic-angular-kit/review` | Throttled native in-app review requests |
29
30
  | `@rdlabo/ionic-angular-kit/printer` | DOM-to-PNG, Brother label, and PDF helpers |
30
31
  | `@rdlabo/ionic-angular-kit/auth-firebase` | Firebase dependency wiring and authentication flows |
@@ -42,6 +43,7 @@ Most features expose a provider whose callbacks keep routes, copy, credentials,
42
43
  - [Authentication and HTTP](./docs/auth-http.md)
43
44
  - [Offline and Realtime](./docs/offline-realtime.md)
44
45
  - [Optional Features](./docs/optional-features.md)
46
+ - [Ionic Signal Forms](./docs/forms.md)
45
47
 
46
48
  <!-- rdlabo-docs-omit -->
47
49
  **Full documentation:** [https://docs.rdlabo.dev/projects/ionic-angular-kit](https://docs.rdlabo.dev/projects/ionic-angular-kit)
package/docs/forms.md ADDED
@@ -0,0 +1,40 @@
1
+ # Ionic Signal Forms
2
+
3
+ This entry point targets Angular 22 Signal Forms.
4
+
5
+ Import Angular's `FormField` together with the kit adapter in each standalone component that binds Signal Forms to Ionic controls.
6
+
7
+ ```ts
8
+ import { FormField } from '@angular/forms/signals';
9
+ import { KitIonicFormField } from '@rdlabo/ionic-angular-kit/forms';
10
+
11
+ @Component({
12
+ imports: [FormField, KitIonicFormField],
13
+ })
14
+ export class ProfilePage {}
15
+ ```
16
+
17
+ The adapter copies the first non-empty string validation message to Ionic's `errorText` property for `ion-input`, `ion-textarea`, `ion-select`, `ion-checkbox`, `ion-radio-group`, and `ion-toggle`. Validation wording and localization remain the application's responsibility. An explicit `errorText` or `[errorText]` binding takes precedence and prevents the adapter from being instantiated.
18
+
19
+ Install the state-class configuration once at application bootstrap:
20
+
21
+ ```ts
22
+ import { provideKitIonicSignalForms } from '@rdlabo/ionic-angular-kit/forms';
23
+
24
+ export const appConfig: ApplicationConfig = {
25
+ providers: [provideKitIonicSignalForms()],
26
+ };
27
+ ```
28
+
29
+ Angular does not merge multiple `provideSignalFormsConfig` class configurations. If the application provides its own configuration, combine all required class mappings in one provider instead of registering both providers and relying on their order.
30
+
31
+ When using `@rdlabo/eslint-plugin-rules`, enable its adapter-aware mode only after every relevant standalone component has imported the adapter:
32
+
33
+ ```js
34
+ {
35
+ files: ['**/*.html'],
36
+ rules: {
37
+ '@rdlabo/rules/require-ion-error-text': ['error', { formFieldProvidesErrorText: true }],
38
+ },
39
+ }
40
+ ```
@@ -0,0 +1,57 @@
1
+ import * as i0 from '@angular/core';
2
+ import { inject, ElementRef, Renderer2, effect, Directive } from '@angular/core';
3
+ import { FORM_FIELD, provideSignalFormsConfig } from '@angular/forms/signals';
4
+
5
+ class KitIonicFormField {
6
+ #field = inject(FORM_FIELD, { self: true });
7
+ #element = inject((ElementRef));
8
+ #renderer = inject(Renderer2);
9
+ constructor() {
10
+ effect(() => {
11
+ const message = this.#field
12
+ .errors()
13
+ .map((error) => error.message)
14
+ .find((candidate) => typeof candidate === 'string' && candidate.trim().length > 0);
15
+ this.#renderer.setProperty(this.#element.nativeElement, 'errorText', message);
16
+ });
17
+ }
18
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: KitIonicFormField, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
19
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.1.3", type: KitIonicFormField, isStandalone: true, selector: "\n ion-input[formField]:not([errorText]),\n ion-textarea[formField]:not([errorText]),\n ion-select[formField]:not([errorText]),\n ion-checkbox[formField]:not([errorText]),\n ion-radio-group[formField]:not([errorText]),\n ion-toggle[formField]:not([errorText])\n ", ngImport: i0 }); }
20
+ }
21
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: KitIonicFormField, decorators: [{
22
+ type: Directive,
23
+ args: [{
24
+ // Angular's FormField owns [formField]. This sibling directive only adapts its validation message to Ionic.
25
+ selector: `
26
+ ion-input[formField]:not([errorText]),
27
+ ion-textarea[formField]:not([errorText]),
28
+ ion-select[formField]:not([errorText]),
29
+ ion-checkbox[formField]:not([errorText]),
30
+ ion-radio-group[formField]:not([errorText]),
31
+ ion-toggle[formField]:not([errorText])
32
+ `,
33
+ }]
34
+ }], ctorParameters: () => [] });
35
+
36
+ /** Adds Angular and Ionic validity state classes to Signal Forms controls. */
37
+ const provideKitIonicSignalForms = () => provideSignalFormsConfig({
38
+ classes: {
39
+ 'ng-dirty': ({ state }) => state().dirty(),
40
+ 'ng-invalid': ({ state }) => state().invalid(),
41
+ 'ng-pending': ({ state }) => state().pending(),
42
+ 'ng-pristine': ({ state }) => !state().dirty(),
43
+ 'ng-touched': ({ state }) => state().touched(),
44
+ 'ng-untouched': ({ state }) => !state().touched(),
45
+ 'ng-valid': ({ state }) => state().valid(),
46
+ 'ion-invalid': ({ state }) => state().invalid(),
47
+ 'ion-touched': ({ state }) => state().touched(),
48
+ 'ion-valid': ({ state }) => state().valid(),
49
+ },
50
+ });
51
+
52
+ /**
53
+ * Generated bundle index. Do not edit.
54
+ */
55
+
56
+ export { KitIonicFormField, provideKitIonicSignalForms };
57
+ //# sourceMappingURL=rdlabo-ionic-angular-kit-forms.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rdlabo-ionic-angular-kit-forms.mjs","sources":["../../../projects/kit/forms/src/kit-ionic-form-field.ts","../../../projects/kit/forms/src/provide-kit-ionic-signal-forms.ts","../../../projects/kit/forms/src/rdlabo-ionic-angular-kit-forms.ts"],"sourcesContent":["import { Directive, effect, ElementRef, inject, Renderer2 } from '@angular/core';\nimport { FORM_FIELD } from '@angular/forms/signals';\n\n@Directive({\n // Angular's FormField owns [formField]. This sibling directive only adapts its validation message to Ionic.\n selector: `\n ion-input[formField]:not([errorText]),\n ion-textarea[formField]:not([errorText]),\n ion-select[formField]:not([errorText]),\n ion-checkbox[formField]:not([errorText]),\n ion-radio-group[formField]:not([errorText]),\n ion-toggle[formField]:not([errorText])\n `,\n})\nexport class KitIonicFormField {\n readonly #field = inject(FORM_FIELD, { self: true });\n readonly #element = inject(ElementRef<HTMLElement>);\n readonly #renderer = inject(Renderer2);\n\n constructor() {\n effect(() => {\n const message = this.#field\n .errors()\n .map((error) => error.message)\n .find((candidate): candidate is string => typeof candidate === 'string' && candidate.trim().length > 0);\n this.#renderer.setProperty(this.#element.nativeElement, 'errorText', message);\n });\n }\n}\n","import { provideSignalFormsConfig } from '@angular/forms/signals';\n\n/** Adds Angular and Ionic validity state classes to Signal Forms controls. */\nexport const provideKitIonicSignalForms = () =>\n provideSignalFormsConfig({\n classes: {\n 'ng-dirty': ({ state }) => state().dirty(),\n 'ng-invalid': ({ state }) => state().invalid(),\n 'ng-pending': ({ state }) => state().pending(),\n 'ng-pristine': ({ state }) => !state().dirty(),\n 'ng-touched': ({ state }) => state().touched(),\n 'ng-untouched': ({ state }) => !state().touched(),\n 'ng-valid': ({ state }) => state().valid(),\n 'ion-invalid': ({ state }) => state().invalid(),\n 'ion-touched': ({ state }) => state().touched(),\n 'ion-valid': ({ state }) => state().valid(),\n },\n });\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAca,iBAAiB,CAAA;IACnB,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC3C,IAAA,Q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AAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE;AAC9C,QAAA,YAAY,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,CAAC,OAAO,EAAE;AAC9C,QAAA,cAAc,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE;AACjD,QAAA,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,CAAC,KAAK,EAAE;AAC1C,QAAA,aAAa,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,CAAC,OAAO,EAAE;AAC/C,QAAA,aAAa,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,CAAC,OAAO,EAAE;AAC/C,QAAA,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,CAAC,KAAK,EAAE;AAC5C,KAAA;AACF,CAAA;;ACjBH;;AAEG;;;;"}
@@ -2583,6 +2583,7 @@ const objectEqual = (a, b) => {
2583
2583
  return JSON.stringify(sortDeep(a)) === JSON.stringify(sortDeep(b));
2584
2584
  };
2585
2585
 
2586
+ const disableStates = new WeakMap();
2586
2587
  const isDisableable = (element) => element instanceof HTMLElement && 'disabled' in element;
2587
2588
  const getIonicSubmitButtons = (form) => Array.from(document.querySelectorAll('ion-button[type="submit"]')).filter((button) => {
2588
2589
  if (!isDisableable(button))
@@ -2612,37 +2613,35 @@ const getDisableTargets = (event) => {
2612
2613
  targets.push(event.target);
2613
2614
  return [...new Set(targets)];
2614
2615
  };
2615
- /**
2616
- * Disable the controls that triggered an event while an async operation runs.
2617
- *
2618
- * @remarks
2619
- * For a click event, the clicked control is disabled. For a submit event, the submitter is
2620
- * disabled and the browser's default form navigation is prevented. Ionic's external
2621
- * `ion-button[form]` uses a hidden native submitter, so buttons associated with the submitted form
2622
- * are resolved through their `form` property and disabled instead. Rejections are swallowed so
2623
- * controls always recover; handle errors inside `work` when the caller needs to react.
2624
- *
2625
- * @param event - The click or submit event that triggered the operation.
2626
- * @param work - The async operation to run while the controls are disabled.
2627
- * @returns A Promise that resolves once the work has settled and the controls have been restored.
2628
- * @example
2629
- * ```html
2630
- * <form #formRef (submit)="helper.disableHandler($event, save())"></form>
2631
- * <ion-button type="submit" [form]="formRef">Save</ion-button>
2632
- * ```
2633
- */
2634
- const disableHandler = (event, work) => {
2616
+ const acquireDisableTarget = (target) => {
2617
+ const state = disableStates.get(target);
2618
+ if (state) {
2619
+ state.count += 1;
2620
+ return;
2621
+ }
2622
+ disableStates.set(target, { count: 1, original: target.disabled });
2623
+ target.disabled = true;
2624
+ };
2625
+ const releaseDisableTarget = (target) => {
2626
+ const state = disableStates.get(target);
2627
+ if (!state)
2628
+ return;
2629
+ state.count -= 1;
2630
+ if (state.count > 0)
2631
+ return;
2632
+ target.disabled = state.original;
2633
+ disableStates.delete(target);
2634
+ };
2635
+ function disableHandler(event, work) {
2635
2636
  if (event.type === 'submit')
2636
2637
  event.preventDefault();
2638
+ if (work === undefined)
2639
+ return;
2637
2640
  const targets = getDisableTargets(event);
2638
- const disabledStates = targets.map((target) => target.disabled);
2639
- targets.forEach((target) => (target.disabled = true));
2640
- return work
2641
- .then(() => undefined, () => undefined)
2642
- .finally(() => {
2643
- targets.forEach((target, index) => (target.disabled = disabledStates[index]));
2644
- });
2645
- };
2641
+ targets.forEach(acquireDisableTarget);
2642
+ const restore = () => targets.forEach(releaseDisableTarget);
2643
+ return new Promise((resolve) => resolve(work)).then(restore, restore);
2644
+ }
2646
2645
 
2647
2646
  /**
2648
2647
  * Toggle the `disabled` flag of a signal-held `ion-infinite-scroll` / `ion-refresher` element.