@forgeroute/ui 0.4.83 → 0.4.85
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/fesm2022/forgeroute-ui-offline.mjs +179 -22
- package/fesm2022/forgeroute-ui-offline.mjs.map +1 -1
- package/fesm2022/{forgeroute-ui-ui-labels.es-DPY2FHcg.mjs → forgeroute-ui-ui-labels.es-CioAOUhm.mjs} +15 -1
- package/fesm2022/{forgeroute-ui-ui-labels.es-DPY2FHcg.mjs.map → forgeroute-ui-ui-labels.es-CioAOUhm.mjs.map} +1 -1
- package/fesm2022/forgeroute-ui.mjs +570 -136
- package/fesm2022/forgeroute-ui.mjs.map +1 -1
- package/package.json +1 -1
- package/types/forgeroute-ui-offline.d.ts +25 -3
- package/types/forgeroute-ui.d.ts +251 -2
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import * as i0 from "@angular/core";
|
|
|
2
2
|
import { EnvironmentProviders, InjectionToken } from "@angular/core";
|
|
3
3
|
import { Subject } from "rxjs";
|
|
4
4
|
import { HttpContextToken, HttpInterceptorFn } from "@angular/common/http";
|
|
5
|
-
import { UiLabelsService } from "@forgeroute/ui";
|
|
5
|
+
import { QueuedNote, UiLabelsService, UiNotesQueue } from "@forgeroute/ui";
|
|
6
6
|
export type MutationStatus = 'pending' | 'syncing' | 'failed' | 'conflict';
|
|
7
7
|
export type MutationErrorKind = 'conflict' | 'rejected' | 'auth' | 'server' | 'network' | 'timeout' | 'dependency';
|
|
8
8
|
export interface MutationError {
|
|
@@ -541,8 +541,8 @@ export declare class OfflineReplayer {
|
|
|
541
541
|
keepMineOne(id: string): Promise<KeepMineRun>;
|
|
542
542
|
/** sent = delivered; shortly = it is still queued (no run could start because another tab holds the lock, still pending / being sent, or waiting out a retry); failed = refused again or a new conflict. */
|
|
543
543
|
private keepMineOutcome;
|
|
544
|
-
/** Deletes one row of the signed-in user (the user chose to discard it). When that row was a stuck (failed / conflict) one with later pending changes of the same record behind it, one normal drain follows so they go out. */
|
|
545
|
-
discard(id: string): Promise<
|
|
544
|
+
/** Deletes one row of the signed-in user (the user chose to discard it). Resolves `true` when this call found and deleted the row, `false` when it was already gone (e.g. delivered meanwhile) or is not the user's. When that row was a stuck (failed / conflict) one with later pending changes of the same record behind it, one normal drain follows so they go out. */
|
|
545
|
+
discard(id: string): Promise<boolean>;
|
|
546
546
|
private readonly discardDrains;
|
|
547
547
|
/** Resolves when EVERY drain started by a `discard` (also overlapping ones) has finished; immediately when none is running. Never rejects. */
|
|
548
548
|
drainSettled(): Promise<void>;
|
|
@@ -736,6 +736,13 @@ export declare class OfflineSupportService {
|
|
|
736
736
|
* Throws `KeepMineError` when the feature is off, the row does not exist, it is not in status `conflict`, or its body has no stamp field (`noStamp`; same rule as `canKeepMine`).
|
|
737
737
|
*/
|
|
738
738
|
keepMine(id: string): Promise<KeepMineOutcome>;
|
|
739
|
+
/** Rows the USER discarded (id -> when), set before the row is deleted so a reader that sees the row leave can tell a discard from a delivery. */
|
|
740
|
+
private readonly discardedIds;
|
|
741
|
+
/** A discard mark only matters while its row leaves the list; it expires after this many ms (and the map is emptied when it grows past 500). */
|
|
742
|
+
private static readonly DISCARD_MARK_MS;
|
|
743
|
+
/** True when the row with this id left the list because the user discarded it (not because it was delivered). */
|
|
744
|
+
wasDiscarded(id: string): boolean;
|
|
745
|
+
private markDiscarded;
|
|
739
746
|
discard(id: string): Promise<void>;
|
|
740
747
|
discardAll(): Promise<void>;
|
|
741
748
|
/**
|
|
@@ -780,6 +787,21 @@ export declare class OfflineSupportService {
|
|
|
780
787
|
* `provideHttpClient(withInterceptors([..., ...offlineHttpInterceptors]))`.
|
|
781
788
|
*/
|
|
782
789
|
export declare function provideOfflineSupport(config: OfflineSupportConfig): EnvironmentProviders;
|
|
790
|
+
/**
|
|
791
|
+
* Lets `ui-notes` show the note changes the offline layer has saved on the device. It reads `OfflineSupportService.rows` (the offline layer's own
|
|
792
|
+
* list - nothing is copied or cached here) and keeps the rows whose URL belongs to the notes list asked for. Provided as `UI_NOTES_QUEUE` by
|
|
793
|
+
* `provideOfflineSupport`; the app still decides whether notes may be queued at all (its `allowQueue` rules / `blockOffline`).
|
|
794
|
+
*/
|
|
795
|
+
export declare class OfflineNotesQueue implements UiNotesQueue {
|
|
796
|
+
private readonly support;
|
|
797
|
+
private readonly connection;
|
|
798
|
+
readonly offline: import("@angular/core").Signal<boolean>;
|
|
799
|
+
wasDiscarded(rowId: string): boolean;
|
|
800
|
+
queuedFor(listPath: string, itemPrefix: string): readonly QueuedNote[];
|
|
801
|
+
private toQueued;
|
|
802
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<OfflineNotesQueue, never>;
|
|
803
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
804
|
+
}
|
|
783
805
|
/** How long the green "All changes synced" bar stays after a sync. */
|
|
784
806
|
export declare const SYNCED_FLASH_MS = 3000;
|
|
785
807
|
export type ConnectionBannerKind = 'auth' | 'offline' | 'unreachable' | 'syncing' | 'attention' | 'slow' | 'synced';
|
package/types/forgeroute-ui.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { AfterContentChecked, EnvironmentProviders, InjectionToken, OnDestroy, OnInit, Signal, TemplateRef, WritableSignal } from "@angular/core";
|
|
2
|
+
import { AfterContentChecked, EnvironmentProviders, InjectionToken, OnDestroy, OnInit, Provider, Signal, TemplateRef, WritableSignal } from "@angular/core";
|
|
3
3
|
import { UrlTree } from "@angular/router";
|
|
4
4
|
import { Observable, Subject } from "rxjs";
|
|
5
5
|
import { AbstractControl, ControlValueAccessor, FormControl, ValidationErrors, Validator, ValidatorFn } from "@angular/forms";
|
|
@@ -1759,6 +1759,10 @@ export declare const UI_DEFAULT_LABELS: {
|
|
|
1759
1759
|
readonly 'paymentSidePanel.sending': "Sending...";
|
|
1760
1760
|
readonly 'starRating.rating': "Rating";
|
|
1761
1761
|
readonly 'timeline.ariaLabel': "Timeline";
|
|
1762
|
+
/** Second line of a timeline item built by `timelineItemsFromEvents`: "Amount: $10.00". */
|
|
1763
|
+
readonly 'timeline.eventAmount': "Amount";
|
|
1764
|
+
/** Title of a locked record built by `timelineItemsFromEvents`. */
|
|
1765
|
+
readonly 'timeline.eventLocked': "{{ title }} (locked record)";
|
|
1762
1766
|
readonly 'common.change': "Change";
|
|
1763
1767
|
readonly 'common.delete': "Delete";
|
|
1764
1768
|
readonly 'common.hide': "Hide";
|
|
@@ -1792,6 +1796,18 @@ export declare const UI_DEFAULT_LABELS: {
|
|
|
1792
1796
|
readonly 'messagingSendMessagePanel.enterValue': "Enter {{ name }}...";
|
|
1793
1797
|
readonly 'messagingTemplatePicker.custom': "Custom";
|
|
1794
1798
|
readonly 'messagingTemplatePicker.system': "System";
|
|
1799
|
+
readonly 'notes.queued.waiting': "Waiting to send";
|
|
1800
|
+
readonly 'notes.queued.sending': "Sending…";
|
|
1801
|
+
readonly 'notes.queued.deleteWaiting': "Waiting to delete";
|
|
1802
|
+
readonly 'notes.queued.deleteSending': "Deleting…";
|
|
1803
|
+
readonly 'notes.queued.failed': "Not sent. This change needs your attention.";
|
|
1804
|
+
readonly 'notes.queued.conflict': "Not sent. Someone else changed this note.";
|
|
1805
|
+
readonly 'notes.queued.addedAnnounce': "Note saved on this device. Waiting to send.";
|
|
1806
|
+
readonly 'notes.queued.editedAnnounce': "Note change saved on this device. Waiting to send.";
|
|
1807
|
+
readonly 'notes.queued.deletedAnnounce': "Note deletion saved on this device. Waiting to send.";
|
|
1808
|
+
readonly 'notes.queued.problemAnnounce': "A note change could not be sent.";
|
|
1809
|
+
readonly 'notes.queued.offlineSome': "You're offline, so only the notes saved on this device are shown here.";
|
|
1810
|
+
readonly 'notes.queued.offlineNone': "You're offline, so the notes can't be loaded right now. A note you add is saved on this device and sent when you're back online.";
|
|
1795
1811
|
readonly 'notes.you': "You";
|
|
1796
1812
|
readonly 'passwordRequirements.met': "met";
|
|
1797
1813
|
readonly 'passwordRequirements.notMet': "not met";
|
|
@@ -10296,6 +10312,44 @@ export declare class CardListItemComponent {
|
|
|
10296
10312
|
"action": "action";
|
|
10297
10313
|
}, never, ["[card-list-inline]", "[card-list-action]", "*", "[card-stats]", "[card-detail]"], true, never>;
|
|
10298
10314
|
}
|
|
10315
|
+
/** Where a note change saved on the device is in the offline layer. */
|
|
10316
|
+
export type QueuedNoteState = 'waiting' | 'sending' | 'failed' | 'conflict';
|
|
10317
|
+
/** One note change that was saved while offline and has not been delivered yet. */
|
|
10318
|
+
export interface QueuedNote {
|
|
10319
|
+
/** The id of the saved change (the offline layer's row), unique per change. */
|
|
10320
|
+
rowId: string;
|
|
10321
|
+
/** `add` = a new note, `edit` = new text for the note `noteId`, `delete` = the note `noteId` is to be deleted. */
|
|
10322
|
+
kind: 'add' | 'edit' | 'delete';
|
|
10323
|
+
/** The note an `edit` / `delete` is about; empty for an `add`. */
|
|
10324
|
+
noteId: string;
|
|
10325
|
+
/** The text of an `add` / `edit` (already trimmed, as it will be sent); empty for a `delete`. */
|
|
10326
|
+
text: string;
|
|
10327
|
+
/** When the change was saved on the device (ms since the epoch). */
|
|
10328
|
+
createdAt: number;
|
|
10329
|
+
state: QueuedNoteState;
|
|
10330
|
+
}
|
|
10331
|
+
/**
|
|
10332
|
+
* The small contract between `ui-notes` and an offline layer (the `@forgeroute/ui/offline` entry point provides it). It is optional: when nothing
|
|
10333
|
+
* provides `UI_NOTES_QUEUE`, `ui-notes` behaves exactly as it always did. It holds no data of its own: `queuedFor` reads the offline layer's own
|
|
10334
|
+
* saved-change list (a signal), so calling it inside a `computed` / template stays reactive.
|
|
10335
|
+
*/
|
|
10336
|
+
export interface UiNotesQueue {
|
|
10337
|
+
/**
|
|
10338
|
+
* The saved changes that belong to one notes list, oldest first. `listPath` is the list URL (`<base>/notes/contact/5` or `<base><basePath>`;
|
|
10339
|
+
* an `add` is a POST to exactly this path) and `itemPrefix` the URL of a single note up to its id (`<base>/notes/` or `<base><basePath>/`; an
|
|
10340
|
+
* `edit` is a PUT and a `delete` a DELETE to `<itemPrefix><noteId>`). Origin and query are ignored when comparing.
|
|
10341
|
+
*/
|
|
10342
|
+
queuedFor(listPath: string, itemPrefix: string): readonly QueuedNote[];
|
|
10343
|
+
/** True while the browser is offline or the server cannot be reached: a failed load is then expected and shows no error toast. */
|
|
10344
|
+
readonly offline: () => boolean;
|
|
10345
|
+
/**
|
|
10346
|
+
* True when the saved change left the list because the USER discarded it. Any other departure (the change was delivered, or the session ended) makes
|
|
10347
|
+
* `ui-notes` reload the list and keep showing that change until the answer arrives, so a delivered note never flashes away or shows stale text.
|
|
10348
|
+
*/
|
|
10349
|
+
wasDiscarded(rowId: string): boolean;
|
|
10350
|
+
}
|
|
10351
|
+
/** Optional provider of queued notes. Provided automatically by `provideOfflineSupport` from `@forgeroute/ui/offline`; absent = `ui-notes` is unchanged. */
|
|
10352
|
+
export declare const UI_NOTES_QUEUE: InjectionToken<UiNotesQueue>;
|
|
10299
10353
|
/** A note as the notes API returns it. */
|
|
10300
10354
|
export interface NoteItem {
|
|
10301
10355
|
id: string;
|
|
@@ -10304,6 +10358,13 @@ export interface NoteItem {
|
|
|
10304
10358
|
createdAt: string;
|
|
10305
10359
|
updatedAt: string;
|
|
10306
10360
|
}
|
|
10361
|
+
/** A note as listed: a server note, or one saved on the device (`queued`) that the server does not have yet / has a pending change for. */
|
|
10362
|
+
interface NoteView extends NoteItem {
|
|
10363
|
+
queued?: {
|
|
10364
|
+
kind: QueuedNote['kind'];
|
|
10365
|
+
state: QueuedNote['state'];
|
|
10366
|
+
};
|
|
10367
|
+
}
|
|
10307
10368
|
/**
|
|
10308
10369
|
* Longest note body, in characters, counted AFTER trimming. Matches the backend `NoteController` cap (10000 after trim; the server trims first,
|
|
10309
10370
|
* so leading / trailing spaces never count). The add box and the edit box block Add Note / Save above it and show "Too long (max 10000 characters).".
|
|
@@ -10326,6 +10387,11 @@ export declare const NOTES_MAX_LENGTH = 10000;
|
|
|
10326
10387
|
* A note may hold at most `NOTES_MAX_LENGTH` (10000) characters after trimming; longer text (typed or pasted) shows the field's
|
|
10327
10388
|
* "Too long" message at once and Add Note / Save stay disabled, so no request is sent.
|
|
10328
10389
|
* Pagination is the library `ui-pagination` (shown only above one page). Cmd/Ctrl+Enter in the add box adds the note.
|
|
10390
|
+
*
|
|
10391
|
+
* Offline (optional): when an offline layer provides `UI_NOTES_QUEUE` (`provideOfflineSupport` from `@forgeroute/ui/offline` does), a note added, edited
|
|
10392
|
+
* or deleted while offline is shown at once with "Waiting to send" (text in the card, announced in a live region), replaced by the real note after the
|
|
10393
|
+
* layer delivered it, and marked "Not sent" when the change failed or conflicted (it disappears if the user discards it). A note that is waiting has no
|
|
10394
|
+
* edit / delete icons. Without a provider nothing of this exists. See `docs/notes-offline.md`.
|
|
10329
10395
|
*/
|
|
10330
10396
|
export declare class NotesComponent {
|
|
10331
10397
|
protected readonly labels: UiLabelsService;
|
|
@@ -10363,6 +10429,22 @@ export declare class NotesComponent {
|
|
|
10363
10429
|
readonly totalElements: import("@angular/core").WritableSignal<number>;
|
|
10364
10430
|
readonly editingId: import("@angular/core").WritableSignal<string | null>;
|
|
10365
10431
|
readonly deletingId: import("@angular/core").WritableSignal<string | null>;
|
|
10432
|
+
/** Optional offline layer (see `UI_NOTES_QUEUE`). Absent = every queue-related behaviour below is off. */
|
|
10433
|
+
protected readonly queue: import("@forgeroute/ui").UiNotesQueue | null;
|
|
10434
|
+
protected readonly announcement: import("@angular/core").WritableSignal<string>;
|
|
10435
|
+
/** Saved changes that just left the queue (delivered) and are still shown until the reload that fetches the real data has answered. Each knows its list. */
|
|
10436
|
+
private readonly settling;
|
|
10437
|
+
/** Overlay clean-ups waiting for the NEWEST load to answer (an older, superseded load never runs them). */
|
|
10438
|
+
private afters;
|
|
10439
|
+
/** Number of the newest load; an answer from an older load is ignored. */
|
|
10440
|
+
private loadSeq;
|
|
10441
|
+
/** True when the last load failed while the offline layer says we are offline (the list then shows only what is saved on this device). */
|
|
10442
|
+
readonly offlineLoadFailed: import("@angular/core").WritableSignal<boolean>;
|
|
10443
|
+
/**
|
|
10444
|
+
* What the list shows: with an offline layer, notes saved on this device are shown right away - new notes first on page 1 (newest first, like the
|
|
10445
|
+
* server's order), and a note with a saved edit / delete keeps its place, marked as waiting. Without one it is exactly `notes()`.
|
|
10446
|
+
*/
|
|
10447
|
+
readonly shown: import("@angular/core").Signal<NoteView[]>;
|
|
10366
10448
|
newBody: string;
|
|
10367
10449
|
editBody: string;
|
|
10368
10450
|
/** Up to two initials of the author's name for the avatar ("Ana Lopez" -> "AL"); "Y" for the current user's own unnamed notes. */
|
|
@@ -10373,13 +10455,29 @@ export declare class NotesComponent {
|
|
|
10373
10455
|
protected validBody(text: string): boolean;
|
|
10374
10456
|
private get listUrl();
|
|
10375
10457
|
private noteUrl;
|
|
10458
|
+
/** The URL of one note up to its id (`.../notes/` or `<basePath>/`). */
|
|
10459
|
+
private get itemPrefix();
|
|
10376
10460
|
private get ready();
|
|
10377
10461
|
/** Request body for create / update: `{ content }` for a `basePath` API, `{ body }` for the generic one. */
|
|
10378
10462
|
private payload;
|
|
10379
10463
|
/** Accepts `body` or `content` as the text and a missing `updatedAt`. */
|
|
10380
10464
|
private normalize;
|
|
10381
10465
|
constructor();
|
|
10382
|
-
|
|
10466
|
+
/** The label under a queued note: what is waiting and why it may be stuck (text, not colour alone). */
|
|
10467
|
+
protected queuedText(q: {
|
|
10468
|
+
kind: QueuedNote['kind'];
|
|
10469
|
+
state: QueuedNote['state'];
|
|
10470
|
+
}): string;
|
|
10471
|
+
/** Says it in the live region; clears first so the same words twice in a row are read twice. */
|
|
10472
|
+
private announce;
|
|
10473
|
+
/** True when the answer is the offline layer's "saved on this device" reply (and an offline layer is present). */
|
|
10474
|
+
private savedOffline;
|
|
10475
|
+
/**
|
|
10476
|
+
* Loads one page. Only the NEWEST load's answer is applied (an older answer arriving late is ignored, so stale data never overwrites newer data and
|
|
10477
|
+
* `loading` stays true until the latest answer). `after` (overlay clean-up of delivered changes) runs when the newest load has answered - also when
|
|
10478
|
+
* a later load superseded the one it was given to, so the overlay drops in the same render the replacing data arrives.
|
|
10479
|
+
*/
|
|
10480
|
+
loadPage(p: number, after?: () => void): void;
|
|
10383
10481
|
addNote(): void;
|
|
10384
10482
|
startEdit(note: NoteItem): void;
|
|
10385
10483
|
cancelEdit(): void;
|
|
@@ -11706,6 +11804,56 @@ export declare class TimelineComponent {
|
|
|
11706
11804
|
"itemAction": "itemAction";
|
|
11707
11805
|
}, never, never, true, never>;
|
|
11708
11806
|
}
|
|
11807
|
+
/** A badge on an event: its text and colour. */
|
|
11808
|
+
export interface TimelineEventBadge {
|
|
11809
|
+
label: string;
|
|
11810
|
+
/** Library badge colour. Default `gray`. */
|
|
11811
|
+
variant?: BadgeVariant;
|
|
11812
|
+
}
|
|
11813
|
+
/**
|
|
11814
|
+
* One activity event of a host page (a note, a payment, a status change...). Hosts map their own records to this shape once and let
|
|
11815
|
+
* {@link timelineItemsFromEvents} build the `ui-timeline` items, so the title / second line / time text / badges / dot colour are the same on every page.
|
|
11816
|
+
*/
|
|
11817
|
+
export interface TimelineEvent {
|
|
11818
|
+
id?: string;
|
|
11819
|
+
/** ISO date or date-time. Drives the time text, the machine-readable `datetime` and, for `groupByDay`, the day heading. */
|
|
11820
|
+
date: string;
|
|
11821
|
+
title: string;
|
|
11822
|
+
/** What happened, in a sentence. */
|
|
11823
|
+
description?: string | null;
|
|
11824
|
+
/** Who did it. */
|
|
11825
|
+
actor?: string | null;
|
|
11826
|
+
/** Money involved (US dollars). 0 and null show nothing. */
|
|
11827
|
+
amount?: number | null;
|
|
11828
|
+
/** A legally immutable record: the title gets the `lockedSuffix`. */
|
|
11829
|
+
locked?: boolean;
|
|
11830
|
+
/** First badge; its colour also colours the dot. */
|
|
11831
|
+
category?: TimelineEventBadge | null;
|
|
11832
|
+
/** Second badge. */
|
|
11833
|
+
status?: TimelineEventBadge | null;
|
|
11834
|
+
}
|
|
11835
|
+
export interface TimelineEventOptions {
|
|
11836
|
+
/** Angular `formatDate` pattern of the visible time. Default `M/d/yyyy h:mm a` (11/8/2026 3:15 PM). */
|
|
11837
|
+
timeFormat?: string;
|
|
11838
|
+
/** Locale of the time text and the amount. Default: the app's active locale (`en-US` without a language service). */
|
|
11839
|
+
locale?: string;
|
|
11840
|
+
/** Words before the amount in the second line. Default: the library text "Amount" in the active language. */
|
|
11841
|
+
amountLabel?: string;
|
|
11842
|
+
/** Appended to the title of a locked record. Default: the library text "<title> (locked record)" in the active language. */
|
|
11843
|
+
lockedSuffix?: string;
|
|
11844
|
+
/** Joins the parts of the second line. Default ` · `. */
|
|
11845
|
+
separator?: string;
|
|
11846
|
+
}
|
|
11847
|
+
/**
|
|
11848
|
+
* Builds `<ui-timeline>` items from activity events.
|
|
11849
|
+
*
|
|
11850
|
+
* - title: the event title (plus `lockedSuffix` for a locked record)
|
|
11851
|
+
* - description: the non-empty ones of `description`, `actor` and `Amount: $1,234.50`, joined with `separator` (absent when there are none)
|
|
11852
|
+
* - time / dateTime: the formatted date and the raw `date`; an unparsable date gives no time text (never "Invalid Date")
|
|
11853
|
+
* - badges: the category and the status badge, in that order, when they have a label
|
|
11854
|
+
* - dotVariant: the colour of the category badge (`gray` when there is none)
|
|
11855
|
+
*/
|
|
11856
|
+
export declare function timelineItemsFromEvents(events: readonly TimelineEvent[], options?: TimelineEventOptions): TimelineItem[];
|
|
11709
11857
|
/**
|
|
11710
11858
|
* Small muted helper text shown under a form or panel section.
|
|
11711
11859
|
*
|
|
@@ -19396,6 +19544,107 @@ export declare class UiLanguageService implements OnDestroy {
|
|
|
19396
19544
|
static ɵfac: i0.ɵɵFactoryDeclaration<UiLanguageService, never>;
|
|
19397
19545
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
19398
19546
|
}
|
|
19547
|
+
/**
|
|
19548
|
+
* Module labels: English + Spanish texts for a module package (@forgeroute/communications, accounting, marketing ...) that follow the app's language with
|
|
19549
|
+
* the SAME mechanism the library uses: the language comes from `UiLanguageService` (switcher, `?lang=`, postMessage ...), English is built in, the Spanish
|
|
19550
|
+
* dictionary is a lazy chunk downloaded the first time Spanish is active, `{{ name }}` placeholders, `_one` / `_other` plurals, and the library locale
|
|
19551
|
+
* for numbers and dates. See docs/module-labels.md.
|
|
19552
|
+
*/
|
|
19553
|
+
export type ModuleLabelParams = Readonly<Record<string, string | number>>;
|
|
19554
|
+
/** The plural base names of a dictionary: every key written `<base>_one` (its `<base>_other` pair is required by `assertModuleLabelParity`). */
|
|
19555
|
+
export type ModuleLabelPluralBase<K extends string> = K extends `${infer B}_one` ? B : never;
|
|
19556
|
+
export interface ModuleLabelsOptions<K extends string> {
|
|
19557
|
+
/** Unique name of the module ('communications'); overrides and the test helper address the module by it. */
|
|
19558
|
+
namespace: string;
|
|
19559
|
+
/** The English texts: the key set of the module, always available, no download. */
|
|
19560
|
+
en: Readonly<Record<K, string>>;
|
|
19561
|
+
/** Loads the Spanish texts, written as a dynamic import so a bundler puts them in a lazy chunk: `() => import('./labels.es').then(m => m.ES)`. */
|
|
19562
|
+
es?: () => Promise<Readonly<Record<K, string>>>;
|
|
19563
|
+
}
|
|
19564
|
+
/** What `createModuleLabels` returns: plain data, safe to create at module level (no injection context needed). Hand it to `injectModuleLabels`. */
|
|
19565
|
+
export interface ModuleLabelsHandle<K extends string> {
|
|
19566
|
+
readonly namespace: string;
|
|
19567
|
+
readonly en: Readonly<Record<K, string>>;
|
|
19568
|
+
readonly es?: () => Promise<Readonly<Record<K, string>>>;
|
|
19569
|
+
}
|
|
19570
|
+
export declare function createModuleLabels<K extends string>(options: ModuleLabelsOptions<K>): ModuleLabelsHandle<K>;
|
|
19571
|
+
/** The labels of one module in the current injection context. Every member reads signals, so a template or `computed` that calls it follows a language change. */
|
|
19572
|
+
export interface ModuleLabels<K extends string> {
|
|
19573
|
+
/** The text of `key` in the active language (English for a key the language lacks or while its chunk loads), `{{ name }}` filled from `params`. */
|
|
19574
|
+
t(key: K, params?: ModuleLabelParams): string;
|
|
19575
|
+
/** A plural text: `<base>_one` when `count === 1`, else `<base>_other`; `count` is available as `{{ count }}` (an own `count` param wins). */
|
|
19576
|
+
tn(base: ModuleLabelPluralBase<K>, count: number, params?: ModuleLabelParams): string;
|
|
19577
|
+
/** `true` when the active language needs no chunk (English, a language the module has no texts for) or its chunk finished loading (or failed: English is shown). */
|
|
19578
|
+
readonly ready: Signal<boolean>;
|
|
19579
|
+
/** The active language code of the app (base language: 'es-MX' reads 'es'). */
|
|
19580
|
+
readonly language: Signal<string>;
|
|
19581
|
+
/** The library locale (dates / numbers) that goes with the language. */
|
|
19582
|
+
readonly locale: Signal<string>;
|
|
19583
|
+
formatDate(value: Date | string | number | null | undefined, format?: string, timeZone?: string): string;
|
|
19584
|
+
formatNumber(value: number | null | undefined, options?: Intl.NumberFormatOptions): string;
|
|
19585
|
+
formatCurrency(value: number | null | undefined, currency?: string, options?: Intl.NumberFormatOptions): string;
|
|
19586
|
+
}
|
|
19587
|
+
export interface ModuleLabelOverrides<K extends string = string> {
|
|
19588
|
+
en?: Partial<Readonly<Record<K, string>>>;
|
|
19589
|
+
es?: Partial<Readonly<Record<K, string>>>;
|
|
19590
|
+
}
|
|
19591
|
+
/**
|
|
19592
|
+
* Lets the host app change single texts of a module, with the semantics of `UiLabelsService.setLabels`: a key the module does not have is ignored, a blank text
|
|
19593
|
+
* is ignored (the module's own text stays) and the placeholders must be exactly those of the module's English text of that key (otherwise ignored).
|
|
19594
|
+
* Several calls for one namespace merge; the later one wins.
|
|
19595
|
+
*/
|
|
19596
|
+
export declare function provideModuleLabelOverrides<K extends string = string>(namespace: string | Pick<ModuleLabelsHandle<K>, 'namespace'>, overrides: ModuleLabelOverrides<K>): EnvironmentProviders;
|
|
19597
|
+
type Status = 'idle' | 'loading' | 'done' | 'failed';
|
|
19598
|
+
interface ModuleState {
|
|
19599
|
+
readonly handle: ModuleLabelsHandle<string>;
|
|
19600
|
+
readonly status: WritableSignal<Status>;
|
|
19601
|
+
readonly spanish: WritableSignal<Readonly<Record<string, string>> | null>;
|
|
19602
|
+
readonly overrides: {
|
|
19603
|
+
en: Record<string, string>;
|
|
19604
|
+
es: Record<string, string>;
|
|
19605
|
+
};
|
|
19606
|
+
}
|
|
19607
|
+
/** Root-level store of the module labels of one application: language, lazily loaded Spanish dictionaries (once per module), host overrides. */
|
|
19608
|
+
export declare class ModuleLabelsRegistry implements OnDestroy {
|
|
19609
|
+
private readonly injector;
|
|
19610
|
+
private readonly labels;
|
|
19611
|
+
private readonly loaders;
|
|
19612
|
+
private readonly entries;
|
|
19613
|
+
private readonly states;
|
|
19614
|
+
private destroyed;
|
|
19615
|
+
/** The app's language (base code). */
|
|
19616
|
+
readonly language: Signal<string>;
|
|
19617
|
+
ngOnDestroy(): void;
|
|
19618
|
+
stateFor(handle: ModuleLabelsHandle<string>): ModuleState;
|
|
19619
|
+
/** Downloads the Spanish texts once per module (a failed download is tried again the next time Spanish becomes active). */
|
|
19620
|
+
private load;
|
|
19621
|
+
create<K extends string>(handle: ModuleLabelsHandle<K>): ModuleLabels<K>;
|
|
19622
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ModuleLabelsRegistry, never>;
|
|
19623
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
19624
|
+
}
|
|
19625
|
+
/** The labels of a module for the current injection context (a component, directive or service field). Call it once, as a field initializer. */
|
|
19626
|
+
export declare function injectModuleLabels<K extends string>(handle: ModuleLabelsHandle<K>): ModuleLabels<K>;
|
|
19627
|
+
/**
|
|
19628
|
+
* For a module package's specs: throws one Error listing every problem when the Spanish dictionary does not match the English one - a key missing or extra,
|
|
19629
|
+
* a blank text, different `{{ placeholders }}`, a plural pair (`x_one` / `x_other`) incomplete in either language.
|
|
19630
|
+
*/
|
|
19631
|
+
export declare function assertModuleLabelParity(en: Readonly<Record<string, string>>, es: Readonly<Record<string, string>>): void;
|
|
19632
|
+
export interface ModuleLabelsTestingOptions {
|
|
19633
|
+
/** Starting language (default 'en'). */
|
|
19634
|
+
language?: string;
|
|
19635
|
+
/** In-memory Spanish texts by namespace; replaces the module's own lazy loader so no chunk is requested. A function may return a rejected promise to simulate a failed download. */
|
|
19636
|
+
es?: Readonly<Record<string, Readonly<Record<string, string>> | (() => Promise<Readonly<Record<string, string>>>)>>;
|
|
19637
|
+
}
|
|
19638
|
+
export interface ModuleLabelsTesting {
|
|
19639
|
+
/** Add to `TestBed.configureTestingModule({ providers })`. */
|
|
19640
|
+
readonly providers: Provider[];
|
|
19641
|
+
/** Change it in a spec to switch the language (then `TestBed.tick()` to let the lazy load start). */
|
|
19642
|
+
readonly language: WritableSignal<string>;
|
|
19643
|
+
/** How many times the Spanish loader of a namespace was called. */
|
|
19644
|
+
loadCount(namespace: string): number;
|
|
19645
|
+
}
|
|
19646
|
+
/** Test helper for module specs, like `provideTestI18n` in apps: a writable language and in-memory Spanish loaders (no `provideUiLanguage` needed). */
|
|
19647
|
+
export declare function moduleLabelsTesting(options?: ModuleLabelsTestingOptions): ModuleLabelsTesting;
|
|
19399
19648
|
/**
|
|
19400
19649
|
* Language picker for the whole app: `<ui-language-switcher />` (needs `provideUiLanguage()`). A native select, so keyboard, screen readers and phones work
|
|
19401
19650
|
* with no extra code. The first option, "Automatic (<language in use>)", follows the visitor's browser / the embedding page; picking a language is a manual
|