@dloizides/ui-feedback 1.5.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,93 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.0
4
+
5
+ Closes the API gap that kept `kefi-web`, `erevna-web` and `katalogos-web` on their
6
+ local `ErrorBoundary` copies. Those three vary the boundary **by error class** — a
7
+ stale-chunk failure after a deploy needs different wording, no retry button, and no
8
+ stack dump — which 1.6.0's static `labels` / boolean `showDetails` could not express.
9
+ Every addition is opt-in; the pre-1.7.0 test suite passes unmodified.
10
+
11
+ **The kit still does not know what a "chunk" is.** Apps inject the classification;
12
+ the boundary only learns *whether retry is meaningful* and *what to say*.
13
+
14
+ - **Add `retryable?: (error) => boolean`.** When it returns `false` the retry action is
15
+ not rendered at all. Offering a button that re-renders straight back into the same
16
+ missing chunk is worse than offering nothing. Default: every error is retryable
17
+ (1.6.0 behaviour).
18
+ - **Add `labelsFor?: (error) => Partial<ErrorBoundaryLabels>`,** merged OVER the static
19
+ `labels`. Lets an app say "Update available" for a stale chunk without the kit knowing
20
+ why — it sees only the resulting strings.
21
+ - **Widen `showDetails` to `boolean | ((error) => boolean)`.** A predicate can suppress
22
+ the dev-only block per error class (a hashed filename is noise, not signal). **A plain
23
+ boolean behaves exactly as before.**
24
+ - **Add `onMount?: () => void`,** called from `componentDidMount` ONLY when the mount was
25
+ clean. The three apps release their one-shot reload guard here: a clean mount proves the
26
+ current chunks loaded, so a FUTURE deploy may auto-recover again. Deliberately not called
27
+ on an errored mount — that would re-arm the guard during the very failure it bounds.
28
+ - **Add `reloadIsPrimary?: boolean`** (default `false`). Gives Reload the filled emphasis
29
+ and the first position instead of Try Again.
30
+
31
+ **Why a flag rather than an unconditional swap:** `agora-web` and `zygos-web` both pass
32
+ `onReload`, so simply inverting the priority would have silently restyled and reordered
33
+ their error screens too. They have no chunk-recovery path, so retry is still the right
34
+ primary there. The default preserves their rendering exactly; the three chunk-aware apps
35
+ opt in.
36
+
37
+ **Notably, `DEFAULT_ERROR_BOUNDARY_LABELS` gains no `updateTitle`/`updateMessage`.** Those
38
+ are domain vocabulary — "an update is available" is a fact about the app's deploy model, not
39
+ about error boundaries. `labelsFor` supplies them as ordinary `title`/`message` overrides,
40
+ which keeps the kit's label bag domain-free.
41
+
42
+ ### Fixed
43
+
44
+ - **`AppErrorBoundary.test.tsx` had never actually run.** `jest.setup.ts` imports
45
+ `@testing-library/jest-dom`, which registers matchers at runtime, but `tsconfig.test.json`
46
+ listed no `types`, so ts-jest failed every `toBeInTheDocument()` with TS2339 and aborted the
47
+ whole suite at compile time. It was the only suite using those matchers, so `npm test`
48
+ reported a red SUITE while the other five stayed green and the true test count read 34.
49
+ Adding `"types": ["jest", "node", "@testing-library/jest-dom"]` brings its 14 assertions
50
+ online for the first time — unmodified, and passing against the 1.7.0 source.
51
+
52
+ ## 1.6.0
53
+
54
+ Two fleet-wide duplicates extracted (W1.2 + W1.3). Both are purely additive — every
55
+ existing export is unchanged.
56
+
57
+ - **Add `createToastBus()` — the shared toast EMIT half (W1.2).** Promoted from the three
58
+ hand-rolled ~25-line twins in `aml-v2` (`components/toast.ts` — `emitToast`/`subscribeToasts`),
59
+ `agora-web` and `zygos-web` (`lib/toastBus.ts` — `toastSuccess`/`toastError`). The returned
60
+ bus is a superset: `subscribe` (the `<ToastHost>` port), `emit(text, type?)`, and the
61
+ `success`/`error`/`info` shorthands.
62
+
63
+ **Deliberately framework-agnostic — no React import, no hook, no provider.** Call sites are
64
+ React Query mutation `onSuccess`/`onError` callbacks with no component context in scope, so a
65
+ hook-based API would break every one of them. It carries no styling: `<ToastHost>` themes each
66
+ toast from `UiProvider`. Text passed in is already localized by the caller.
67
+
68
+ New exports: `createToastBus`, `ToastBus`, `ToastPush`.
69
+
70
+ - **Add `<AppErrorBoundary>` — the shared top-level error boundary (W1.3).** Promoted from the
71
+ SIX app-local copies (`agora-web` + `zygos-web` byte-identical, `kefi-web`, `erevna-web`,
72
+ `katalogos-web`, `ichnos-web`); `aml-v2` had none at all. The axes that actually varied are now
73
+ injected rather than baked in: `onError` (Sentry/logger), `recover` (the apps' chunk-load
74
+ retry), `showDetails` (dev-only error text), `labels` (pre-localized bag), `testIDPrefix`,
75
+ and `fallback` (escape hatch). An optional `onReload` renders the manual **Reload** action
76
+ that kefi/erevna/katalogos shipped alongside **Try Again**.
77
+
78
+ Two behaviour fixes come with the extraction:
79
+ - **Themed.** The fallback renders through the shared `<ErrorState>`, so it reads
80
+ `UiProvider` colours — this removes the 40+ hardcoded Bootstrap-4 hex literals
81
+ (`#f8f9fa`, `#212529`, `#6c757d`, `#fff3cd`, `#856404`, `#007bff`, …) three copies carried.
82
+ - **Announced.** The fallback ships `role="alert"` + `accessibilityLiveRegion="assertive"`;
83
+ none of the six announced anything to a screen reader, and agora/zygos rendered only the
84
+ app *name* with no message and no retry.
85
+
86
+ New exports: `AppErrorBoundary`, `AppErrorBoundaryProps`, `ErrorFallbackState`,
87
+ `ErrorBoundaryLabels`, `DEFAULT_ERROR_BOUNDARY_LABELS`, plus the `errorBoundary` id in
88
+ `FEEDBACK_TEST_IDS` (default prefix `error-boundary`, preserving the existing
89
+ `error-boundary-retry-button` / `-reload-button` / `-updating` Playwright selectors).
90
+
3
91
  ## 1.5.0
4
92
 
5
93
  - **Accessibility (WCAG 2.1 AA) — `ToastHost` announcements.** Each toast is now a live region so
package/README.md CHANGED
@@ -14,6 +14,15 @@ package depending on any app's internals.
14
14
  | `LoadingFallback` | Lightweight spinner for `React.lazy` / `Suspense` boundaries. |
15
15
  | `PageSkeleton` | Shimmer skeleton for full-page loads (list or card variant). |
16
16
  | `ConfirmDialog` | Modal confirm/cancel dialog with destructive + loading states. |
17
+ | `ToastHost` | Transient-toast overlay; pair it with `createToastBus()`. |
18
+ | `WarmingOverlay` | Branded cold-start "warming up…" overlay. |
19
+ | `AppErrorBoundary` | Top-level error boundary with a themed, announced fallback. |
20
+
21
+ ## Helpers
22
+
23
+ | Helper | Purpose |
24
+ |--------|---------|
25
+ | `createToastBus()` | Framework-agnostic toast emit bus — the `ToastHost` `subscribe` port. |
17
26
 
18
27
  ## Install
19
28
 
@@ -66,6 +75,64 @@ import { ErrorState, ConfirmDialog, LoadingFallback } from '@dloizides/ui-feedba
66
75
  />
67
76
  ```
68
77
 
78
+ ## Toasts — `createToastBus()`
79
+
80
+ The toast pipeline is two halves: `createToastBus()` **emits**, `<ToastHost>` **renders**.
81
+ A bus's `subscribe` *is* the host's `subscribe` port.
82
+
83
+ The bus is **framework-agnostic on purpose** — no React import, no hook, no provider — so a
84
+ React Query mutation callback can raise a toast with no component context in scope. It carries
85
+ no styling (`ToastHost` themes every toast from the provider), and the text you pass is already
86
+ localized by you; the bus never sees a translation key.
87
+
88
+ ```ts
89
+ // src/lib/toastBus.ts — one module-level instance per app
90
+ import { createToastBus } from '@dloizides/ui-feedback';
91
+ export const toastBus = createToastBus();
92
+ ```
93
+
94
+ ```tsx
95
+ // once, in the shell:
96
+ <ToastHost subscribe={toastBus.subscribe} />
97
+
98
+ // anywhere — no provider needed:
99
+ useMutation({ onSuccess: () => toastBus.success(FM('menu.saved')) });
100
+ toastBus.error(FM('menu.saveFailed'));
101
+ toastBus.emit(FM('menu.queued'), 'info'); // explicit type; defaults to 'info'
102
+ ```
103
+
104
+ Emitting with no host mounted is a silent no-op. Every subscriber receives every emit, and
105
+ `subscribe` returns an unsubscribe.
106
+
107
+ ## Error boundary — `<AppErrorBoundary>`
108
+
109
+ Wrap your app once. The fallback renders through `ErrorState`, so it themes from the provider,
110
+ and it announces itself (`role="alert"` + `accessibilityLiveRegion="assertive"`).
111
+
112
+ ```tsx
113
+ <AppErrorBoundary
114
+ labels={{ title: FM('errorBoundary.title'), message: FM('errorBoundary.message') }}
115
+ showDetails={__DEV__}
116
+ onError={(error, info) => captureException(error, { extra: { componentStack: info.componentStack } })}
117
+ recover={(error) => isChunkLoadError(error) && attemptChunkRecovery()}
118
+ onReload={reloadPage}
119
+ >
120
+ <App />
121
+ </AppErrorBoundary>
122
+ ```
123
+
124
+ | Prop | Purpose |
125
+ |------|---------|
126
+ | `onError(error, info)` | Reporting sink (Sentry / logger). Called for **every** caught error, before `recover`. |
127
+ | `recover(error)` | Return `true` if handled (e.g. a guarded reload is under way) → shows the `updating` screen instead of the error screen. |
128
+ | `showDetails` | Render the error message in the fallback (dev-only). Default `false`. |
129
+ | `labels` | Partial, **pre-localized** `ErrorBoundaryLabels`; anything omitted uses the English defaults in `DEFAULT_ERROR_BOUNDARY_LABELS`. |
130
+ | `testIDPrefix` | Prefix for every testID. Default `error-boundary`. |
131
+ | `fallback(state)` | Escape hatch — replaces the built-in fallback entirely. Receives `{ error, recovering, retry }`. |
132
+ | `onReload` | Optional secondary **Reload** action. The kit never touches `window`, so you inject the reload. |
133
+
134
+ The package imports no i18n runtime — localize at the call site and pass strings.
135
+
69
136
  ## i18n keys
70
137
 
71
138
  The components call the injected `t(key)` with these keys (provide them in each app's
@@ -78,7 +145,12 @@ locale files): `common.retry`, `common.retryHint`, `common.confirm`, `common.can
78
145
  Default testIDs (`FEEDBACK_TEST_IDS`) match the strings the consuming apps already used,
79
146
  so existing Playwright selectors keep working: `error-state`, `error-state-retry`,
80
147
  `empty-list-cta`, `loading-fallback`, `page-skeleton`, `confirm-dialog`, `confirm-button`,
81
- `cancel-confirm-button`.
148
+ `cancel-confirm-button`, `notification-toast`, `warming-overlay`, `error-boundary`.
149
+
150
+ `AppErrorBoundary` derives its ids from `testIDPrefix` (default `error-boundary`), preserving the
151
+ selectors the app-local copies used: `error-boundary`, `error-boundary-message`,
152
+ `error-boundary-details`, `error-boundary-retry-button`, `error-boundary-reload-button`,
153
+ `error-boundary-updating`.
82
154
 
83
155
  ## License
84
156
 
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { Component, ReactNode, ErrorInfo } from 'react';
2
2
 
3
3
  /**
4
4
  * The minimal theme surface the feedback components read. Each consuming app's
@@ -77,6 +77,7 @@ declare const FEEDBACK_TEST_IDS: {
77
77
  readonly cancelConfirmButton: "cancel-confirm-button";
78
78
  readonly notificationToast: "notification-toast";
79
79
  readonly warmingOverlay: "warming-overlay";
80
+ readonly errorBoundary: "error-boundary";
80
81
  };
81
82
 
82
83
  /**
@@ -277,4 +278,185 @@ declare function subscribeWarming(listener: WarmingListener): () => void;
277
278
  /** Current immutable snapshot. Stable identity until the value changes. */
278
279
  declare function getWarmingSnapshot(): WarmingSnapshot;
279
280
 
280
- export { ConfirmDialog, type ConfirmDialogProps, DISABLED_OPACITY, EmptyListState, type EmptyListStateProps, ErrorState, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ToastHost, type ToastHostProps, type ToastInput, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, getWarmingSnapshot, notifyWarming, settleWarming, subscribeWarming, useFeedbackUi, useFeedbackUi as useUi };
281
+ /**
282
+ * createToastBus — the shared EMIT half of the toast pipeline, promoted from the
283
+ * hand-rolled twins in aml-v2 (`components/toast.ts`), agora-web and zygos-web
284
+ * (`lib/toastBus.ts`). The RENDERING half is `<ToastHost>`; a bus instance's
285
+ * {@link ToastBus.subscribe} IS the `ToastHost` `subscribe` port.
286
+ *
287
+ * Deliberately FRAMEWORK-AGNOSTIC — no React import, no hook, no provider. Call
288
+ * sites are React Query mutation `onSuccess`/`onError` callbacks that have no
289
+ * component context in scope, so a hook-based API would break every one of them.
290
+ *
291
+ * It carries no styling: `<ToastHost>` themes every toast from `UiProvider`.
292
+ * Text arriving here is ALREADY localized by the caller (`FM()`); this bus never
293
+ * sees a translation key.
294
+ *
295
+ * Usage — one module-level instance per app:
296
+ * ```ts
297
+ * // src/lib/toastBus.ts
298
+ * import { createToastBus } from '@dloizides/ui-feedback';
299
+ * export const toastBus = createToastBus();
300
+ *
301
+ * // anywhere, no provider needed:
302
+ * toastBus.success(FM('menu.saved'));
303
+ *
304
+ * // once, in the shell:
305
+ * <ToastHost subscribe={toastBus.subscribe} />
306
+ * ```
307
+ */
308
+
309
+ /** A registered push callback — what `<ToastHost>` hands to {@link ToastBus.subscribe}. */
310
+ type ToastPush = (toast: ToastInput) => void;
311
+ interface ToastBus {
312
+ /** Register a push callback; returns an unsubscribe. The `<ToastHost>` `subscribe` port. */
313
+ subscribe(push: ToastPush): () => void;
314
+ /** Emit a toast of an explicit type. Defaults to `info`. */
315
+ emit(text: string, type?: ToastType): void;
316
+ /** Emit a success toast. */
317
+ success(text: string): void;
318
+ /** Emit an error toast. */
319
+ error(text: string): void;
320
+ /** Emit an informational toast. */
321
+ info(text: string): void;
322
+ }
323
+ /**
324
+ * Create an independent toast bus. Emitting with no subscriber is a silent no-op
325
+ * (the host simply isn't mounted yet), and every subscriber receives every emit.
326
+ */
327
+ declare function createToastBus(): ToastBus;
328
+
329
+ /**
330
+ * The i18n-agnostic label bag for `<AppErrorBoundary>`.
331
+ *
332
+ * The kit imports no `FM`/i18n runtime — callers localize at the call site and
333
+ * pass PRE-LOCALIZED strings (`labels={{ title: FM('errorBoundary.title') }}`).
334
+ * The defaults below are plain English so the boundary is never blank when a
335
+ * caller omits the bag.
336
+ */
337
+ interface ErrorBoundaryLabels {
338
+ /** Heading of the error screen. */
339
+ title: string;
340
+ /** Body copy under the heading. */
341
+ message: string;
342
+ /** Primary action: reset the boundary and re-render the children. */
343
+ tryAgain: string;
344
+ /** Accessibility hint for the try-again action. */
345
+ tryAgainHint: string;
346
+ /** Secondary action: full page reload (rendered only when `onReload` is given). */
347
+ reload: string;
348
+ /** Accessibility hint for the reload action. */
349
+ reloadHint: string;
350
+ /** Shown while `recover` is handling the error (e.g. a guarded chunk reload). */
351
+ updating: string;
352
+ /** Heading of the dev-only error-details block. */
353
+ errorDetails: string;
354
+ }
355
+ declare const DEFAULT_ERROR_BOUNDARY_LABELS: ErrorBoundaryLabels;
356
+
357
+ /**
358
+ * AppErrorBoundary — the shared top-level React error boundary, promoted from the
359
+ * SIX app-local copies (agora-web + zygos-web byte-identical, kefi-web, erevna-web,
360
+ * katalogos-web, ichnos-web). aml-v2 had none at all.
361
+ *
362
+ * What varied between the copies — and is therefore injected, not baked in:
363
+ * - **reporting** → `onError` (Sentry `captureException` / `loggingService.fatal`)
364
+ * - **recovery** → `recover` (the apps' `isChunkLoadError() && attemptChunkRecovery()`)
365
+ * - **test ids** → `testIDPrefix` (defaults to the value all six already used)
366
+ * - **error text** → `showDetails` (the dev-only stack block)
367
+ * - **wording** → `labels` (pre-localized by the caller; the kit imports no i18n)
368
+ * - **everything else** → `fallback`, the escape hatch
369
+ *
370
+ * What is now uniform: the fallback renders through the shared `<ErrorState>`, so
371
+ * it themes from `UiProvider` instead of the Bootstrap-4 hex literals three copies
372
+ * hardcoded; and it announces via `role="alert"` + `accessibilityLiveRegion`,
373
+ * which none of the six did.
374
+ */
375
+
376
+ /** What the `fallback` render-prop receives. */
377
+ interface ErrorFallbackState {
378
+ /** The caught error, or `null` before anything has been caught. */
379
+ error: Error | null;
380
+ /** True while the caller's `recover` is handling the error. */
381
+ recovering: boolean;
382
+ /** Resets the boundary and re-renders `children`. */
383
+ retry: () => void;
384
+ }
385
+ interface AppErrorBoundaryProps {
386
+ children: ReactNode;
387
+ /** Reporting sink — Sentry / logger. Called for EVERY caught error, before `recover`. */
388
+ onError?: (error: Error, info: ErrorInfo) => void;
389
+ /**
390
+ * Recovery attempt. Return `true` if the error is handled (e.g. a guarded page
391
+ * reload is under way) — the boundary then shows the `updating` screen instead
392
+ * of the error screen. Return `false`/omit to fall through to the fallback.
393
+ */
394
+ recover?: (error: Error) => boolean;
395
+ /**
396
+ * Render the error message in the fallback (dev-only stack). Default `false`.
397
+ *
398
+ * A predicate is asked per caught error, so an app can suppress the block for
399
+ * error classes where the stack is noise rather than signal (the three chunk-aware
400
+ * apps hide it for a stale-chunk failure: the message names a hashed filename the
401
+ * user can do nothing with). A plain boolean behaves exactly as it always has.
402
+ */
403
+ showDetails?: boolean | ((error: Error) => boolean);
404
+ /** Pre-localized wording. Anything omitted falls back to the English defaults. */
405
+ labels?: Partial<ErrorBoundaryLabels>;
406
+ /**
407
+ * Per-error wording, merged OVER `labels`. Lets a caller say something specific
408
+ * about a specific failure ("Update available" for a stale chunk) without the kit
409
+ * knowing why — it never sees the classification, only the resulting strings.
410
+ */
411
+ labelsFor?: (error: Error) => Partial<ErrorBoundaryLabels>;
412
+ /**
413
+ * Whether retrying could plausibly help. When this returns `false` the retry
414
+ * action is NOT rendered at all — offering a button that re-renders straight back
415
+ * into the same failure is worse than offering nothing. Default: every error is
416
+ * retryable, which is the behaviour before this prop existed.
417
+ */
418
+ retryable?: (error: Error) => boolean;
419
+ /**
420
+ * Called from `componentDidMount` ONLY when the mount was clean (nothing caught).
421
+ * The chunk-aware apps use it to release their one-shot reload guard: a clean mount
422
+ * proves the current chunks loaded, so a FUTURE deploy is allowed to auto-recover
423
+ * again. Deliberately NOT called on an errored mount — that would re-arm the guard
424
+ * during the very failure it is meant to bound, and reintroduce the reload loop.
425
+ */
426
+ onMount?: () => void;
427
+ /**
428
+ * Give the primary (filled) emphasis — and the first position — to **Reload**
429
+ * instead of **Try Again**. Default `false`, which preserves the emphasis every
430
+ * existing caller renders today.
431
+ *
432
+ * Apps with a stale-chunk failure mode set this: when the running bundle references
433
+ * a chunk that no longer exists, reloading is the action that actually works and
434
+ * re-rendering is the one that cannot.
435
+ */
436
+ reloadIsPrimary?: boolean;
437
+ /** Prefix for every testID the boundary renders. Default `error-boundary`. */
438
+ testIDPrefix?: string;
439
+ /** Full escape hatch — replaces the built-in fallback entirely. */
440
+ fallback?: (state: ErrorFallbackState) => ReactNode;
441
+ /**
442
+ * Optional secondary action: a full page reload. Rendered only when provided.
443
+ * (kefi/erevna/katalogos shipped a manual **Reload** alongside **Try Again**;
444
+ * the kit does not touch `window`, so the caller injects the reload itself.)
445
+ */
446
+ onReload?: () => void;
447
+ }
448
+ interface AppErrorBoundaryState {
449
+ hasError: boolean;
450
+ error: Error | null;
451
+ recovering: boolean;
452
+ }
453
+ declare class AppErrorBoundary extends Component<AppErrorBoundaryProps, AppErrorBoundaryState> {
454
+ constructor(props: AppErrorBoundaryProps);
455
+ static getDerivedStateFromError(error: Error): Partial<AppErrorBoundaryState>;
456
+ componentDidMount(): void;
457
+ componentDidCatch(error: Error, info: ErrorInfo): void;
458
+ private readonly handleRetry;
459
+ render(): ReactNode;
460
+ }
461
+
462
+ export { AppErrorBoundary, type AppErrorBoundaryProps, ConfirmDialog, type ConfirmDialogProps, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, EmptyListState, type EmptyListStateProps, type ErrorBoundaryLabels, type ErrorFallbackState, ErrorState, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, type ToastBus, ToastHost, type ToastHostProps, type ToastInput, type ToastPush, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, createToastBus, getWarmingSnapshot, notifyWarming, settleWarming, subscribeWarming, useFeedbackUi, useFeedbackUi as useUi };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { Component, ReactNode, ErrorInfo } from 'react';
2
2
 
3
3
  /**
4
4
  * The minimal theme surface the feedback components read. Each consuming app's
@@ -77,6 +77,7 @@ declare const FEEDBACK_TEST_IDS: {
77
77
  readonly cancelConfirmButton: "cancel-confirm-button";
78
78
  readonly notificationToast: "notification-toast";
79
79
  readonly warmingOverlay: "warming-overlay";
80
+ readonly errorBoundary: "error-boundary";
80
81
  };
81
82
 
82
83
  /**
@@ -277,4 +278,185 @@ declare function subscribeWarming(listener: WarmingListener): () => void;
277
278
  /** Current immutable snapshot. Stable identity until the value changes. */
278
279
  declare function getWarmingSnapshot(): WarmingSnapshot;
279
280
 
280
- export { ConfirmDialog, type ConfirmDialogProps, DISABLED_OPACITY, EmptyListState, type EmptyListStateProps, ErrorState, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ToastHost, type ToastHostProps, type ToastInput, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, getWarmingSnapshot, notifyWarming, settleWarming, subscribeWarming, useFeedbackUi, useFeedbackUi as useUi };
281
+ /**
282
+ * createToastBus — the shared EMIT half of the toast pipeline, promoted from the
283
+ * hand-rolled twins in aml-v2 (`components/toast.ts`), agora-web and zygos-web
284
+ * (`lib/toastBus.ts`). The RENDERING half is `<ToastHost>`; a bus instance's
285
+ * {@link ToastBus.subscribe} IS the `ToastHost` `subscribe` port.
286
+ *
287
+ * Deliberately FRAMEWORK-AGNOSTIC — no React import, no hook, no provider. Call
288
+ * sites are React Query mutation `onSuccess`/`onError` callbacks that have no
289
+ * component context in scope, so a hook-based API would break every one of them.
290
+ *
291
+ * It carries no styling: `<ToastHost>` themes every toast from `UiProvider`.
292
+ * Text arriving here is ALREADY localized by the caller (`FM()`); this bus never
293
+ * sees a translation key.
294
+ *
295
+ * Usage — one module-level instance per app:
296
+ * ```ts
297
+ * // src/lib/toastBus.ts
298
+ * import { createToastBus } from '@dloizides/ui-feedback';
299
+ * export const toastBus = createToastBus();
300
+ *
301
+ * // anywhere, no provider needed:
302
+ * toastBus.success(FM('menu.saved'));
303
+ *
304
+ * // once, in the shell:
305
+ * <ToastHost subscribe={toastBus.subscribe} />
306
+ * ```
307
+ */
308
+
309
+ /** A registered push callback — what `<ToastHost>` hands to {@link ToastBus.subscribe}. */
310
+ type ToastPush = (toast: ToastInput) => void;
311
+ interface ToastBus {
312
+ /** Register a push callback; returns an unsubscribe. The `<ToastHost>` `subscribe` port. */
313
+ subscribe(push: ToastPush): () => void;
314
+ /** Emit a toast of an explicit type. Defaults to `info`. */
315
+ emit(text: string, type?: ToastType): void;
316
+ /** Emit a success toast. */
317
+ success(text: string): void;
318
+ /** Emit an error toast. */
319
+ error(text: string): void;
320
+ /** Emit an informational toast. */
321
+ info(text: string): void;
322
+ }
323
+ /**
324
+ * Create an independent toast bus. Emitting with no subscriber is a silent no-op
325
+ * (the host simply isn't mounted yet), and every subscriber receives every emit.
326
+ */
327
+ declare function createToastBus(): ToastBus;
328
+
329
+ /**
330
+ * The i18n-agnostic label bag for `<AppErrorBoundary>`.
331
+ *
332
+ * The kit imports no `FM`/i18n runtime — callers localize at the call site and
333
+ * pass PRE-LOCALIZED strings (`labels={{ title: FM('errorBoundary.title') }}`).
334
+ * The defaults below are plain English so the boundary is never blank when a
335
+ * caller omits the bag.
336
+ */
337
+ interface ErrorBoundaryLabels {
338
+ /** Heading of the error screen. */
339
+ title: string;
340
+ /** Body copy under the heading. */
341
+ message: string;
342
+ /** Primary action: reset the boundary and re-render the children. */
343
+ tryAgain: string;
344
+ /** Accessibility hint for the try-again action. */
345
+ tryAgainHint: string;
346
+ /** Secondary action: full page reload (rendered only when `onReload` is given). */
347
+ reload: string;
348
+ /** Accessibility hint for the reload action. */
349
+ reloadHint: string;
350
+ /** Shown while `recover` is handling the error (e.g. a guarded chunk reload). */
351
+ updating: string;
352
+ /** Heading of the dev-only error-details block. */
353
+ errorDetails: string;
354
+ }
355
+ declare const DEFAULT_ERROR_BOUNDARY_LABELS: ErrorBoundaryLabels;
356
+
357
+ /**
358
+ * AppErrorBoundary — the shared top-level React error boundary, promoted from the
359
+ * SIX app-local copies (agora-web + zygos-web byte-identical, kefi-web, erevna-web,
360
+ * katalogos-web, ichnos-web). aml-v2 had none at all.
361
+ *
362
+ * What varied between the copies — and is therefore injected, not baked in:
363
+ * - **reporting** → `onError` (Sentry `captureException` / `loggingService.fatal`)
364
+ * - **recovery** → `recover` (the apps' `isChunkLoadError() && attemptChunkRecovery()`)
365
+ * - **test ids** → `testIDPrefix` (defaults to the value all six already used)
366
+ * - **error text** → `showDetails` (the dev-only stack block)
367
+ * - **wording** → `labels` (pre-localized by the caller; the kit imports no i18n)
368
+ * - **everything else** → `fallback`, the escape hatch
369
+ *
370
+ * What is now uniform: the fallback renders through the shared `<ErrorState>`, so
371
+ * it themes from `UiProvider` instead of the Bootstrap-4 hex literals three copies
372
+ * hardcoded; and it announces via `role="alert"` + `accessibilityLiveRegion`,
373
+ * which none of the six did.
374
+ */
375
+
376
+ /** What the `fallback` render-prop receives. */
377
+ interface ErrorFallbackState {
378
+ /** The caught error, or `null` before anything has been caught. */
379
+ error: Error | null;
380
+ /** True while the caller's `recover` is handling the error. */
381
+ recovering: boolean;
382
+ /** Resets the boundary and re-renders `children`. */
383
+ retry: () => void;
384
+ }
385
+ interface AppErrorBoundaryProps {
386
+ children: ReactNode;
387
+ /** Reporting sink — Sentry / logger. Called for EVERY caught error, before `recover`. */
388
+ onError?: (error: Error, info: ErrorInfo) => void;
389
+ /**
390
+ * Recovery attempt. Return `true` if the error is handled (e.g. a guarded page
391
+ * reload is under way) — the boundary then shows the `updating` screen instead
392
+ * of the error screen. Return `false`/omit to fall through to the fallback.
393
+ */
394
+ recover?: (error: Error) => boolean;
395
+ /**
396
+ * Render the error message in the fallback (dev-only stack). Default `false`.
397
+ *
398
+ * A predicate is asked per caught error, so an app can suppress the block for
399
+ * error classes where the stack is noise rather than signal (the three chunk-aware
400
+ * apps hide it for a stale-chunk failure: the message names a hashed filename the
401
+ * user can do nothing with). A plain boolean behaves exactly as it always has.
402
+ */
403
+ showDetails?: boolean | ((error: Error) => boolean);
404
+ /** Pre-localized wording. Anything omitted falls back to the English defaults. */
405
+ labels?: Partial<ErrorBoundaryLabels>;
406
+ /**
407
+ * Per-error wording, merged OVER `labels`. Lets a caller say something specific
408
+ * about a specific failure ("Update available" for a stale chunk) without the kit
409
+ * knowing why — it never sees the classification, only the resulting strings.
410
+ */
411
+ labelsFor?: (error: Error) => Partial<ErrorBoundaryLabels>;
412
+ /**
413
+ * Whether retrying could plausibly help. When this returns `false` the retry
414
+ * action is NOT rendered at all — offering a button that re-renders straight back
415
+ * into the same failure is worse than offering nothing. Default: every error is
416
+ * retryable, which is the behaviour before this prop existed.
417
+ */
418
+ retryable?: (error: Error) => boolean;
419
+ /**
420
+ * Called from `componentDidMount` ONLY when the mount was clean (nothing caught).
421
+ * The chunk-aware apps use it to release their one-shot reload guard: a clean mount
422
+ * proves the current chunks loaded, so a FUTURE deploy is allowed to auto-recover
423
+ * again. Deliberately NOT called on an errored mount — that would re-arm the guard
424
+ * during the very failure it is meant to bound, and reintroduce the reload loop.
425
+ */
426
+ onMount?: () => void;
427
+ /**
428
+ * Give the primary (filled) emphasis — and the first position — to **Reload**
429
+ * instead of **Try Again**. Default `false`, which preserves the emphasis every
430
+ * existing caller renders today.
431
+ *
432
+ * Apps with a stale-chunk failure mode set this: when the running bundle references
433
+ * a chunk that no longer exists, reloading is the action that actually works and
434
+ * re-rendering is the one that cannot.
435
+ */
436
+ reloadIsPrimary?: boolean;
437
+ /** Prefix for every testID the boundary renders. Default `error-boundary`. */
438
+ testIDPrefix?: string;
439
+ /** Full escape hatch — replaces the built-in fallback entirely. */
440
+ fallback?: (state: ErrorFallbackState) => ReactNode;
441
+ /**
442
+ * Optional secondary action: a full page reload. Rendered only when provided.
443
+ * (kefi/erevna/katalogos shipped a manual **Reload** alongside **Try Again**;
444
+ * the kit does not touch `window`, so the caller injects the reload itself.)
445
+ */
446
+ onReload?: () => void;
447
+ }
448
+ interface AppErrorBoundaryState {
449
+ hasError: boolean;
450
+ error: Error | null;
451
+ recovering: boolean;
452
+ }
453
+ declare class AppErrorBoundary extends Component<AppErrorBoundaryProps, AppErrorBoundaryState> {
454
+ constructor(props: AppErrorBoundaryProps);
455
+ static getDerivedStateFromError(error: Error): Partial<AppErrorBoundaryState>;
456
+ componentDidMount(): void;
457
+ componentDidCatch(error: Error, info: ErrorInfo): void;
458
+ private readonly handleRetry;
459
+ render(): ReactNode;
460
+ }
461
+
462
+ export { AppErrorBoundary, type AppErrorBoundaryProps, ConfirmDialog, type ConfirmDialogProps, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, EmptyListState, type EmptyListStateProps, type ErrorBoundaryLabels, type ErrorFallbackState, ErrorState, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, type ToastBus, ToastHost, type ToastHostProps, type ToastInput, type ToastPush, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, createToastBus, getWarmingSnapshot, notifyWarming, settleWarming, subscribeWarming, useFeedbackUi, useFeedbackUi as useUi };