@rdlabo/ionic-angular-kit 0.0.26 → 21.2.0-10

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/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "@rdlabo/ionic-angular-kit",
3
- "version": "0.0.26",
3
+ "version": "21.2.0-10",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/rdlabo-team/ionic-angular-library.git"
7
+ },
4
8
  "peerDependencies": {
5
9
  "@angular/common": "^21.0.0",
6
10
  "@angular/core": "^21.0.0",
@@ -20,6 +24,7 @@
20
24
  "@capacitor-community/apple-sign-in": "*",
21
25
  "@rdlabo/capacitor-brotherprint": ">=6.0.0 <9.0.0",
22
26
  "dom-to-image-more": "^3.0.0",
27
+ "pdf-lib": "^1.17.1",
23
28
  "firebase": ">=11 <13",
24
29
  "rxjs": "^7.8.0"
25
30
  },
@@ -50,6 +55,9 @@
50
55
  },
51
56
  "dom-to-image-more": {
52
57
  "optional": true
58
+ },
59
+ "pdf-lib": {
60
+ "optional": true
53
61
  }
54
62
  },
55
63
  "dependencies": {
@@ -77,5 +77,71 @@ interface KitBrotherPrintSettingsParams {
77
77
  */
78
78
  declare const kitBuildBrotherPrintSettings: (params: KitBrotherPrintSettingsParams) => BRLMPrintOptions;
79
79
 
80
- export { kitBuildBrotherPrintSettings, kitDomToPng, kitRotationImage };
81
- export type { KitBrotherPrintSettingsParams, KitDomToPngOptions };
80
+ /** Physical paper dimensions used to build a PDF page. */
81
+ interface KitPrintPaper {
82
+ /** Human-readable paper name. */
83
+ readonly label: string;
84
+ /** Paper width in millimetres. */
85
+ readonly widthMm: number;
86
+ /** Paper height in millimetres. */
87
+ readonly heightMm: number;
88
+ }
89
+ /** Standard paper presets shared by the printing applications. */
90
+ declare const kitPrintPaperSizes: {
91
+ readonly a4: {
92
+ readonly label: "A4";
93
+ readonly widthMm: 210;
94
+ readonly heightMm: 297;
95
+ };
96
+ readonly b5: {
97
+ readonly label: "B5";
98
+ readonly widthMm: 182;
99
+ readonly heightMm: 257;
100
+ };
101
+ };
102
+ /** A position for one label on a PDF page, expressed in PDF points. */
103
+ interface KitPrintPosition {
104
+ readonly pageIndex: number;
105
+ readonly x: number;
106
+ readonly y: number;
107
+ }
108
+ /** Calculated PDF page and label dimensions. */
109
+ interface KitPrintLayout {
110
+ readonly paperWidth: number;
111
+ readonly paperHeight: number;
112
+ readonly labelWidth: number;
113
+ readonly labelHeight: number;
114
+ readonly positions: readonly KitPrintPosition[];
115
+ }
116
+ /** Optional physical size override for a label. */
117
+ interface KitPrintMeasure {
118
+ readonly type: 'width' | 'height';
119
+ readonly sizeMm: number;
120
+ }
121
+ /** Parameters for {@link kitCalculatePrintLayout}. */
122
+ interface KitCalculatePrintLayoutParams {
123
+ readonly paper: KitPrintPaper;
124
+ readonly labelWidthPx: number;
125
+ readonly labelHeightPx: number;
126
+ readonly copies: number;
127
+ readonly measure?: KitPrintMeasure | null;
128
+ /** Outer page margin in millimetres. Defaults to 5mm. */
129
+ readonly marginMm?: number;
130
+ }
131
+ /**
132
+ * Calculate page dimensions and row-major label positions for a printable PDF.
133
+ *
134
+ * Labels keep their aspect ratio, are never enlarged beyond their requested pixel/physical size,
135
+ * and automatically continue on additional pages when the current page is full.
136
+ */
137
+ declare const kitCalculatePrintLayout: (params: KitCalculatePrintLayoutParams) => KitPrintLayout;
138
+ /** Parameters for {@link kitBuildLabelPdf}. */
139
+ interface KitBuildLabelPdfParams extends KitCalculatePrintLayoutParams {
140
+ /** PNG label artwork as a data URL or base64 string accepted by pdf-lib. */
141
+ readonly imageData: string;
142
+ }
143
+ /** Build a multi-page label PDF and return its bytes without choosing an output destination. */
144
+ declare const kitBuildLabelPdf: (params: KitBuildLabelPdfParams) => Promise<Uint8Array>;
145
+
146
+ export { kitBuildBrotherPrintSettings, kitBuildLabelPdf, kitCalculatePrintLayout, kitDomToPng, kitPrintPaperSizes, kitRotationImage };
147
+ export type { KitBrotherPrintSettingsParams, KitBuildLabelPdfParams, KitCalculatePrintLayoutParams, KitDomToPngOptions, KitPrintLayout, KitPrintMeasure, KitPrintPaper, KitPrintPosition };
@@ -12,6 +12,9 @@ import { BehaviorSubject } from 'rxjs';
12
12
  * palette passes `darkClasses: ['ion-palette-dark'], lightClasses: []`, while an app with an extra
13
13
  * design-system palette adds its own classes (e.g. `darkClasses: ['ion-palette-dark', 'a2ui-dark']`,
14
14
  * `lightClasses: ['a2ui-light']`).
15
+ *
16
+ * Prefer `KIT_THEME_STORAGE_KEY` (from `@rdlabo/ionic-angular-kit`) as `storageKey` so logout
17
+ * clear-preserving lists stay in sync.
15
18
  */
16
19
  interface KitThemeConfig {
17
20
  /** Key under which the chosen theme (`'light'` | `'dark'`) is persisted via `KitStorageService`. */
@@ -35,10 +38,13 @@ declare const KIT_THEME_CONFIG: InjectionToken<KitThemeConfig>;
35
38
  * @returns environment providers to add to the application's provider list
36
39
  * @example
37
40
  * ```ts
41
+ * import { KIT_THEME_STORAGE_KEY } from '@rdlabo/ionic-angular-kit';
42
+ * import { provideKitTheme } from '@rdlabo/ionic-angular-kit/theme';
43
+ *
38
44
  * bootstrapApplication(AppComponent, {
39
45
  * providers: [
40
46
  * provideKitTheme({
41
- * storageKey: StorageKeyEnum.theme,
47
+ * storageKey: KIT_THEME_STORAGE_KEY,
42
48
  * darkClasses: ['ion-palette-dark', 'a2ui-dark'],
43
49
  * lightClasses: ['a2ui-light'],
44
50
  * }),
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, EnvironmentProviders, InputSignalWithTransform, OnInit, ElementRef, WritableSignal } from '@angular/core';
2
+ import { InjectionToken, EnvironmentProviders, InputSignalWithTransform, OnInit, ElementRef, WritableSignal, InputSignal, Signal, OutputEmitterRef } from '@angular/core';
3
3
  import { ModalOptions, PopoverOptions, ToastOptions, LoadingOptions, AlertController, ActionSheetController } from '@ionic/angular/standalone';
4
4
  import { PluginListenerHandle } from '@capacitor/core';
5
5
  import { RouterStateSnapshot, UrlTree, CanActivateFn } from '@angular/router';
@@ -130,6 +130,55 @@ declare const kitRecallEmail: (store: KitEmailStore) => Promise<string | null>;
130
130
  */
131
131
  declare const kitForgetEmail: (store: KitEmailStore) => Promise<void>;
132
132
 
133
+ /**
134
+ * Canonical storage keys persisted via {@link KitStorageService} that fleet apps often need to
135
+ * keep across a sign-out `clear()`.
136
+ *
137
+ * @remarks
138
+ * `KIT_LAST_AUTH_EMAIL_KEY` lives in `kit-auth-email-store` and is exported from the package root.
139
+ * Import both keys from `@rdlabo/ionic-angular-kit` alongside {@link kitClearStoragePreservingKeys}.
140
+ */
141
+ /**
142
+ * Light/dark preference for `provideKitTheme` / `KitThemeController`.
143
+ *
144
+ * @remarks
145
+ * Pass this as `provideKitTheme({ storageKey: KIT_THEME_STORAGE_KEY, … })` and include it in
146
+ * {@link kitClearStoragePreservingKeys} so logout does not reset the user's theme.
147
+ */
148
+ declare const KIT_THEME_STORAGE_KEY = "theme";
149
+
150
+ /**
151
+ * Clear a key/value store while restoring selected keys afterward.
152
+ *
153
+ * @remarks
154
+ * Fleet apps often call `storage.clear()` on sign-out to drop session/token state. Values that
155
+ * should survive logout (for example {@link KIT_LAST_AUTH_EMAIL_KEY}) are passed in `keys`.
156
+ * Missing keys are skipped — only non-null values are written back.
157
+ */
158
+ /** Minimal clearable store — structurally satisfied by {@link KitStorageService}. */
159
+ interface KitClearableStore {
160
+ get<T>(key: string): Promise<T | null>;
161
+ set<T>(key: string, value: T): Promise<void>;
162
+ clear(): Promise<void>;
163
+ }
164
+ /**
165
+ * Wipe the store, then restore the given keys to their pre-clear values (when present).
166
+ *
167
+ * @param store - the app's storage (e.g. `KitStorageService`)
168
+ * @param keys - keys whose values should survive the clear
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * import { KIT_LAST_AUTH_EMAIL_KEY, KIT_THEME_STORAGE_KEY, kitClearStoragePreservingKeys } from '@rdlabo/ionic-angular-kit';
173
+ *
174
+ * await kitSignOut(auth, {
175
+ * success: () =>
176
+ * kitClearStoragePreservingKeys(this.storage, [KIT_LAST_AUTH_EMAIL_KEY, KIT_THEME_STORAGE_KEY]),
177
+ * });
178
+ * ```
179
+ */
180
+ declare const kitClearStoragePreservingKeys: (store: KitClearableStore, keys: readonly string[]) => Promise<void>;
181
+
133
182
  /**
134
183
  * User-visible button labels consumed by `KitOverlayController`.
135
184
  *
@@ -542,6 +591,70 @@ declare class KitReloadAlertController {
542
591
  static ɵprov: i0.ɵɵInjectableDeclaration<KitReloadAlertController>;
543
592
  }
544
593
 
594
+ /**
595
+ * Content for {@link KitMaintenanceController.present}.
596
+ */
597
+ interface KitMaintenanceOptions {
598
+ /** Alert header, e.g. "メンテナンス中です". */
599
+ header: string;
600
+ /** Alert body; keep short — the user cannot dismiss until maintenance ends. */
601
+ message: string;
602
+ /**
603
+ * Absolute URL of the fleet maintenance wait SSE (`GET /public/maintenance/wait`).
604
+ *
605
+ * @remarks
606
+ * Typically `environment.api + 'public/maintenance/wait'`. While the overlay is shown the
607
+ * controller opens an {@link EventSource} on this URL and dismisses on `event: ended`.
608
+ */
609
+ waitUrl: string;
610
+ }
611
+ /**
612
+ * Singleton "maintenance lock" overlay: backdrop-locked, no dismiss buttons, auto-clears via SSE.
613
+ *
614
+ * @remarks
615
+ * Mirrors {@link KitReloadAlertController} as a de-duped stateful controller, but the user cannot
616
+ * cancel or reload out of it — only the server `event: ended` on {@link KitMaintenanceOptions.waitUrl}
617
+ * (or an explicit {@link dismiss}) clears it. Uses Ionic's `AlertController` (not a feature modal)
618
+ * so the kit stays free of page components / i18n; all copy is supplied by the caller.
619
+ *
620
+ * Wire from {@link KitHttpConfig.onMaintenance} when the API returns `503` with
621
+ * `error.error?.code === 'MAINTENANCE'`.
622
+ *
623
+ * @example
624
+ * ```ts
625
+ * provideKitHttp(() => {
626
+ * const maintenance = inject(KitMaintenanceController);
627
+ * return {
628
+ * getAuthHeaders: async () => ({}),
629
+ * onMaintenance: () =>
630
+ * void maintenance.present({
631
+ * header: 'メンテナンス中です',
632
+ * message: 'しばらくお待ちください。終了次第、自動で閉じます。',
633
+ * waitUrl: environment.api + 'public/maintenance/wait',
634
+ * }),
635
+ * };
636
+ * });
637
+ * ```
638
+ */
639
+ declare class KitMaintenanceController {
640
+ #private;
641
+ /**
642
+ * Present the lock overlay and start waiting on the maintenance SSE, unless one is already showing.
643
+ *
644
+ * @param options - overlay copy plus the wait SSE URL
645
+ */
646
+ present(options: KitMaintenanceOptions): Promise<void>;
647
+ /**
648
+ * Dismiss the tracked overlay and tear down the wait SSE.
649
+ *
650
+ * @remarks
651
+ * Normally called when the wait stream emits `ended`. A no-op when nothing is showing.
652
+ */
653
+ dismiss(): Promise<void>;
654
+ static ɵfac: i0.ɵɵFactoryDeclaration<KitMaintenanceController, never>;
655
+ static ɵprov: i0.ɵɵInjectableDeclaration<KitMaintenanceController>;
656
+ }
657
+
545
658
  /**
546
659
  * Content for {@link kitPresentAuthFailedAlert}.
547
660
  */
@@ -920,6 +1033,17 @@ declare const kitRequireConfirmingGuard: CanActivateFn;
920
1033
  */
921
1034
  declare const kitRequireAuthorizedGuard: CanActivateFn;
922
1035
 
1036
+ /**
1037
+ * True when the error is the fleet maintenance short-circuit (`503` + body `code: 'MAINTENANCE'`).
1038
+ *
1039
+ * @remarks
1040
+ * Matches Angular `HttpErrorResponse` as `error.error?.code === 'MAINTENANCE'` (body top-level
1041
+ * `code`). Must not be retried and must not fall through to {@link KitHttpConfig.onServerBusy}.
1042
+ *
1043
+ * @param error - The failed response.
1044
+ * @returns Whether this is a maintenance response.
1045
+ */
1046
+ declare const isMaintenanceError: (error: HttpErrorResponse) => boolean;
923
1047
  /**
924
1048
  * Configuration that customizes the behavior of {@link kitAuthInterceptor}, injected through {@link provideKitHttp}.
925
1049
  *
@@ -1041,12 +1165,22 @@ interface KitHttpConfig {
1041
1165
  * @remarks
1042
1166
  * Optional; defaults to a no-op. Distinct from {@link KitHttpConfig.onNetworkError} — the device's
1043
1167
  * connection is fine, the server is momentarily unavailable — so the app can say "server busy, try
1044
- * again shortly" rather than prompt a reload.
1168
+ * again shortly" rather than prompt a reload. **Not** called for fleet maintenance (`503` with
1169
+ * `error.error?.code === 'MAINTENANCE'`) — that uses {@link KitHttpConfig.onMaintenance}.
1045
1170
  *
1046
1171
  * @param status - `502`, `503`, or `504`.
1047
1172
  * @param retryAfterSeconds - The server's `Retry-After` hint in seconds, when provided.
1048
1173
  */
1049
1174
  onServerBusy?(status: number, retryAfterSeconds?: number): void;
1175
+ /**
1176
+ * UX hook for fleet maintenance: HTTP `503` whose body has `code: 'MAINTENANCE'`.
1177
+ *
1178
+ * @remarks
1179
+ * Optional; defaults to a no-op. Fired **without retries** (maintenance is intentional, not
1180
+ * transient). Wire to {@link KitMaintenanceController.present} with the wait SSE URL so the lock
1181
+ * overlay auto-dismisses when maintenance ends.
1182
+ */
1183
+ onMaintenance?(): void;
1050
1184
  /**
1051
1185
  * UX hook for a `429 Too Many Requests` response, fired after retries are exhausted.
1052
1186
  *
@@ -1131,8 +1265,8 @@ declare const provideKitHttp: (configFactory: () => KitHttpConfig) => Environmen
1131
1265
  * When the device is offline it stops retrying immediately.
1132
1266
  * 5. On the final error, `offlineFallback` is consulted first; otherwise the error is classified by
1133
1267
  * status (see {@link dispatchError}): `401`→`onUnauthorized`, `403`→`onForbidden`, `0`→
1134
- * `onNetworkError` (when connected), `429`→`onRateLimited`, `502`/`503`/`504`→`onServerBusy`, and
1135
- * `400`/`422`/`500` with a body message→`onServerError`.
1268
+ * `onNetworkError` (when connected), `429`→`onRateLimited`, maintenance `503`→`onMaintenance`,
1269
+ * other `502`/`503`/`504`→`onServerBusy`, and `400`/`422`/`500` with a body message→`onServerError`.
1136
1270
  *
1137
1271
  * @param request - The outgoing request.
1138
1272
  * @param next - The next handler in the interceptor chain.
@@ -1256,21 +1390,22 @@ declare const arrayConcatById: <T>(arrayOld: T[], arrayNew: T[], key: keyof T, o
1256
1390
  declare const objectEqual: (a: object, b: object) => boolean;
1257
1391
 
1258
1392
  /**
1259
- * Disable the button that triggered an event while an async operation runs, re-enabling it after.
1393
+ * Disable the controls that triggered an event while an async operation runs.
1260
1394
  *
1261
1395
  * @remarks
1262
- * Prevents the common double-submit / double-tap bug: the `event.target` button is disabled, the
1263
- * work is awaited, and the button is re-enabled — even if the work rejects (the rejection is
1264
- * swallowed here so the button always recovers; handle errors inside `work` if you need to react).
1265
- *
1266
- * @param event - The DOM event whose `target` is the button to disable (e.g. a click event).
1267
- * @param work - The async operation to run while the button is disabled.
1268
- * @returns A Promise that resolves once the work has settled and the button has been re-enabled.
1396
+ * For a click event, the clicked control is disabled. For a submit event, the submitter is
1397
+ * disabled and the browser's default form navigation is prevented. Ionic's external
1398
+ * `ion-button[form]` uses a hidden native submitter, so buttons associated with the submitted form
1399
+ * are resolved through their `form` property and disabled instead. Rejections are swallowed so
1400
+ * controls always recover; handle errors inside `work` when the caller needs to react.
1401
+ *
1402
+ * @param event - The click or submit event that triggered the operation.
1403
+ * @param work - The async operation to run while the controls are disabled.
1404
+ * @returns A Promise that resolves once the work has settled and the controls have been restored.
1269
1405
  * @example
1270
- * ```ts
1271
- * async submit(event: Event): Promise<void> {
1272
- * await disableHandler(event, this.save());
1273
- * }
1406
+ * ```html
1407
+ * <form #formRef (submit)="helper.disableHandler($event, save())"></form>
1408
+ * <ion-button type="submit" [form]="formRef">Save</ion-button>
1274
1409
  * ```
1275
1410
  */
1276
1411
  declare const disableHandler: (event: Event, work: Promise<void | boolean>) => Promise<void>;
@@ -1315,5 +1450,32 @@ declare const kitChangeEventDisabled: (completeEvent: WritableSignal<HTMLIonInfi
1315
1450
  */
1316
1451
  declare const kitCreateDidEnter: (el: ElementRef) => Observable<boolean>;
1317
1452
 
1318
- export { KIT_AUTH_CONFIG, KIT_HTTP_CONFIG, KIT_LAST_AUTH_EMAIL_KEY, KIT_OVERLAY_CONFIG, KitAuthInputDirective, KitLoadingController, KitOverlayController, KitReloadAlertController, KitStorageService, arrayConcatById, disableHandler, kitAuthInterceptor, kitChangeEventDisabled, kitCreateDidEnter, kitForgetEmail, kitImpact, kitIsValidEmail, kitKeyboardInit, kitPresentAuthFailedAlert, kitPresentLanguageActionSheet, kitRecallEmail, kitRememberEmail, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay };
1319
- export type { KitAlertCloseOptions, KitAlertConfirmOptions, KitAuthConfig, KitAuthFailedAlertOptions, KitAuthInputMode, KitAuthRedirects, KitAuthState, KitEmailStore, KitHttpConfig, KitKeyboardAdjust, KitLabels, KitLanguageActionSheetOptions, KitLanguageOption, KitModalPresentOptions, KitOverlayConfig, KitReloadAlertOptions, ModalMetadata };
1453
+ /**
1454
+ * Component のうち Signal(computed / input / viewChild 等)と `output()` だけを
1455
+ * ViewModel から見えるようにする型。`vm` は循環参照になるため除外する。
1456
+ *
1457
+ * 注意: `new ViewModel(this)` の引数型に直接使うと、vm 依存 computed の推論と循環する。
1458
+ * ViewModelStore 側は constructor(host: Component) で受け、`mountViewModel()` により
1459
+ * `ViewModelHost<Component, Keys>` へ絞り込むこと(呼び出し点では mapped type を展開しない)。
1460
+ */
1461
+ type ReactiveHost<T> = Pick<T, {
1462
+ [K in Exclude<keyof T, 'vm'>]-?: T[K] extends Signal<unknown> ? K : T[K] extends OutputEmitterRef<any> ? K : never;
1463
+ }[Exclude<keyof T, 'vm'>]>;
1464
+ /**
1465
+ * ViewModel に公開する Component の Signal と、明示的に許可した非 Signal property。
1466
+ */
1467
+ type ViewModelHost<T, K extends keyof T = never> = ReactiveHost<T> & Pick<T, K>;
1468
+ /**
1469
+ * Component host を ViewModel 用に絞り込み、初回 render 後の mount hook を登録する。
1470
+ */
1471
+ declare function mountViewModel<T, K extends keyof T = never>(host: T, onMount?: () => void): ViewModelHost<T, K>;
1472
+ /**
1473
+ * Modal / page に渡す props オブジェクトを、Angular `input()` の InputSignal 形に写す型。
1474
+ * `implements ComponentPropsType<Props>` で component 側の input 宣言を揃える。
1475
+ */
1476
+ type ComponentPropsType<T> = {
1477
+ [K in keyof T]: InputSignal<T[K]> | InputSignalWithTransform<T[K], any>;
1478
+ };
1479
+
1480
+ export { KIT_AUTH_CONFIG, KIT_HTTP_CONFIG, KIT_LAST_AUTH_EMAIL_KEY, KIT_OVERLAY_CONFIG, KIT_THEME_STORAGE_KEY, KitAuthInputDirective, KitLoadingController, KitMaintenanceController, KitOverlayController, KitReloadAlertController, KitStorageService, arrayConcatById, disableHandler, isMaintenanceError, kitAuthInterceptor, kitChangeEventDisabled, kitClearStoragePreservingKeys, kitCreateDidEnter, kitForgetEmail, kitImpact, kitIsValidEmail, kitKeyboardInit, kitPresentAuthFailedAlert, kitPresentLanguageActionSheet, kitRecallEmail, kitRememberEmail, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, mountViewModel, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay };
1481
+ export type { ComponentPropsType, KitAlertCloseOptions, KitAlertConfirmOptions, KitAuthConfig, KitAuthFailedAlertOptions, KitAuthInputMode, KitAuthRedirects, KitAuthState, KitClearableStore, KitEmailStore, KitHttpConfig, KitKeyboardAdjust, KitLabels, KitLanguageActionSheetOptions, KitLanguageOption, KitMaintenanceOptions, KitModalPresentOptions, KitOverlayConfig, KitReloadAlertOptions, ModalMetadata, ReactiveHost, ViewModelHost };