@12-apps/notifications 4.10.3 → 4.11.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/ADOPTING.md +31 -2
- package/dist/{chunk-BW723CX2.js → chunk-2IAHFIXS.js} +51 -38
- package/dist/chunk-2IAHFIXS.js.map +1 -0
- package/dist/{chunk-H55A4LHG.js → chunk-2TJ4D2KE.js} +38 -27
- package/dist/chunk-2TJ4D2KE.js.map +1 -0
- package/dist/{create-web-notifications-DV3Y8k7e.d.ts → create-web-notifications-CnaXx6km.d.ts} +59 -12
- package/dist/manifest/web.d.ts +1 -1
- package/dist/manifest/web.js +2 -2
- package/dist/{panel-V2ULFC4Y.js → panel-MKI4PTNZ.js} +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +2 -2
- package/package.json +2 -2
- package/src/react/bell-badge.ts +147 -0
- package/src/react/bell-button.tsx +19 -31
- package/src/react/create-web-notifications.tsx +55 -6
- package/src/react/hooks.ts +61 -13
- package/src/react/index.ts +13 -0
- package/dist/chunk-BW723CX2.js.map +0 -1
- package/dist/chunk-H55A4LHG.js.map +0 -1
- /package/dist/{panel-V2ULFC4Y.js.map → panel-MKI4PTNZ.js.map} +0 -0
package/dist/react/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
createNotificationsApiClient,
|
|
4
4
|
createWebNotifications,
|
|
5
5
|
httpNotificationsTransport
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-2TJ4D2KE.js";
|
|
7
7
|
import {
|
|
8
8
|
LiveSection,
|
|
9
9
|
relativeTime
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
useInboxList,
|
|
18
18
|
useInboxState,
|
|
19
19
|
useUnreadCount
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-2IAHFIXS.js";
|
|
21
21
|
import {
|
|
22
22
|
disableWebPush,
|
|
23
23
|
enableWebPush,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@12-apps/notifications",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Plug-and-play notification system (12-15): an always-on in-app inbox, per-user × per-category channel preferences, and email / SMS / WhatsApp / web-push transports behind vendor DRIVERS so a second provider is a config entry. Framework-free core (.), host-mounted backend surface (./server: inbox / preferences / push-subscription endpoints, the channel router with delivery records + retry sweep, the permission fan-out, duck-typed Prisma seam), Hono adapter (./hono), React surface (./react: bell + badge, inbox drawer, preferences screen), VAPID sender (./web-push) and the package-owned Prisma partial + migrations. Standardized adoption contract in ADOPTING.md.",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"prisma:sync:check": "node scripts/sync-notifications-schema.mjs --check"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@12-apps/ui": "^6.
|
|
74
|
+
"@12-apps/ui": "^6.22.0"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@12-apps/wiring": ">=1.3.0",
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the bell shows: ONE number, and whether any of it is news.
|
|
3
|
+
*
|
|
4
|
+
* The badge answers two different questions with one glyph, and keeping them
|
|
5
|
+
* apart is the whole design:
|
|
6
|
+
*
|
|
7
|
+
* - the COUNT is how many things the centre is holding for the reader;
|
|
8
|
+
* - the TONE is whether any of them has happened since they last looked.
|
|
9
|
+
*
|
|
10
|
+
* An inbox row makes those the same question — an unread row is by definition
|
|
11
|
+
* both present and unseen — which is why the distinction did not exist before
|
|
12
|
+
* live activities did. A live activity separates them: a pedido that has been
|
|
13
|
+
* `Preparo` for ten minutes is still worth a `1`, and shouting about it every
|
|
14
|
+
* render is how a badge teaches people to stop reading it.
|
|
15
|
+
*
|
|
16
|
+
* ## This is here so a host can DRAW it
|
|
17
|
+
*
|
|
18
|
+
* The numbers were already correct inside this package's own `BellButton`, and
|
|
19
|
+
* unreachable from a host that cannot take that component — a header whose cart
|
|
20
|
+
* and search buttons are one styled icon-button is importing a second trigger
|
|
21
|
+
* style the moment it does. Such a host had `useUnreadCount` and nothing else,
|
|
22
|
+
* so its bell showed NOTHING while a pinned pedido sat inside the panel it
|
|
23
|
+
* opens. Both bells now read these hooks, so a host cannot drift from what this
|
|
24
|
+
* package renders.
|
|
25
|
+
*
|
|
26
|
+
* ## What it does NOT yet do
|
|
27
|
+
*
|
|
28
|
+
* A live subject usually also writes inbox rows as it moves, and this counts
|
|
29
|
+
* both: a pedido with one unread row about it reads `2`. Subtracting the double
|
|
30
|
+
* needs the server to say which unread rows name which subject, and that was
|
|
31
|
+
* built, reviewed and pulled — for reasons about the CONTRACT rather than the
|
|
32
|
+
* arithmetic, and worth recording so the next attempt starts past them:
|
|
33
|
+
*
|
|
34
|
+
* - it added a field to `GET /notifications/unread-count`, and at least one
|
|
35
|
+
* adopter publishes that response as a closed schema to LLM clients. An
|
|
36
|
+
* additive field is a breaking change against `additionalProperties: false`.
|
|
37
|
+
* - the scan is per READER, so every host paid it — including the two SPAs in
|
|
38
|
+
* that adopter that share one factory and configure no live activities at
|
|
39
|
+
* all, and read the count through `useUnreadCount`, which never sees the
|
|
40
|
+
* breakdown.
|
|
41
|
+
* - it narrowed `NotificationsApiClient.unreadCount()` from `Promise<number>`,
|
|
42
|
+
* which is a breaking change on a commit the release rules cut as a minor.
|
|
43
|
+
*
|
|
44
|
+
* The way through is an opt-in the surface asks for — a host with no live
|
|
45
|
+
* activities then sends nothing different and receives nothing different.
|
|
46
|
+
*
|
|
47
|
+
* (An earlier revision of this docblock blamed a missing index instead. That
|
|
48
|
+
* was wrong: `[userId, deletedAt, readAt]` is a full equality prefix over the
|
|
49
|
+
* filter, and the `ORDER BY` the scan carried was not load-bearing, since a
|
|
50
|
+
* tally does not care what order it counts in.)
|
|
51
|
+
*/
|
|
52
|
+
import { useMemo, useSyncExternalStore } from 'react';
|
|
53
|
+
|
|
54
|
+
import { useBadgeState, type BadgeSyncOptions } from './hooks';
|
|
55
|
+
import type { InboxStore } from './inbox-state';
|
|
56
|
+
import type { LiveActivitiesConfig } from './live-config';
|
|
57
|
+
import { hasUnseenActivity, type LiveSeenStore } from './live-seen';
|
|
58
|
+
|
|
59
|
+
/** The bell's whole state — see the file docblock for what each half means. */
|
|
60
|
+
export interface BellBadge {
|
|
61
|
+
/** What the badge shows. `0` renders no badge at all. */
|
|
62
|
+
count: number;
|
|
63
|
+
/**
|
|
64
|
+
* Whether any of it has arrived or moved since the reader last looked.
|
|
65
|
+
*
|
|
66
|
+
* The trigger paints this as its accent colour; a host with its own chrome
|
|
67
|
+
* decides how to say it, but it should be a difference somebody notices.
|
|
68
|
+
*/
|
|
69
|
+
hasNew: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The badge for a host with no live activities: unread rows, and that is all.
|
|
74
|
+
*
|
|
75
|
+
* `hasNew` is `count > 0` here, and not as a simplification — an UNREAD row is
|
|
76
|
+
* one the reader has not seen, so for this host presence and novelty really are
|
|
77
|
+
* the same fact.
|
|
78
|
+
*/
|
|
79
|
+
export function useInboxBellBadge(store: InboxStore, options: BadgeSyncOptions = {}): BellBadge {
|
|
80
|
+
// `useBadgeState` already blanks itself when disabled — the gate lives there,
|
|
81
|
+
// once, rather than at each of the three hooks that layer on it.
|
|
82
|
+
const { unread } = useBadgeState(store, options);
|
|
83
|
+
// MEMOISED, unlike the number `useUnreadCount` returns. `useSyncExternalStore`
|
|
84
|
+
// re-renders on every `patch` and `patch` always allocates, so a poll that
|
|
85
|
+
// comes back with an unchanged count would otherwise hand a host a new object
|
|
86
|
+
// every 60 s — enough to re-fire a `useEffect` keyed on it, or defeat a
|
|
87
|
+
// `React.memo` on the trigger, forever.
|
|
88
|
+
return useMemo(() => ({ count: unread, hasNew: unread > 0 }), [unread]);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The badge for a host that configured live activities.
|
|
93
|
+
*
|
|
94
|
+
* A SECOND hook rather than a flag on the one above, for the reason the bell
|
|
95
|
+
* itself is two components: `live.useActivities` is a hook, so a single hook
|
|
96
|
+
* reading an optional config would be calling one conditionally — which React
|
|
97
|
+
* reports as a crash somewhere else entirely. The factory knows statically
|
|
98
|
+
* which host it is building for and binds one.
|
|
99
|
+
*
|
|
100
|
+
* ## `enabled` is enforced HERE, not taken on trust
|
|
101
|
+
*
|
|
102
|
+
* A host is explicitly allowed to ignore the `active` hint and always answer —
|
|
103
|
+
* `./live-config` calls that "behaving correctly and merely paying for it" — so
|
|
104
|
+
* a signed-out header, which still MOUNTS the bell, can be handed a list of
|
|
105
|
+
* somebody's pedidos. The guard below is the only thing between that and a
|
|
106
|
+
* badge counting them.
|
|
107
|
+
*
|
|
108
|
+
* Defensive against the CONTRACT, not against an observed adopter: today's one
|
|
109
|
+
* honours the hint on every lever it has. That is exactly why the guard needs
|
|
110
|
+
* saying — nothing about the current tree would fail if it went, and the case
|
|
111
|
+
* that covers it has to build the ignoring host itself.
|
|
112
|
+
*
|
|
113
|
+
* ## What it costs the host, stated plainly
|
|
114
|
+
*
|
|
115
|
+
* The bell is mounted for as long as the app is, so unlike the panel's copy of
|
|
116
|
+
* this hook there is no "nobody is looking" state to stand down in — `active`
|
|
117
|
+
* is simply `enabled`. A host that answers by polling therefore polls for every
|
|
118
|
+
* signed-in reader whether or not they ever open the centre. That is the price
|
|
119
|
+
* of a badge that knows about live activities at all, and the reason to answer
|
|
120
|
+
* this hook from a pushed cache rather than from an interval.
|
|
121
|
+
*/
|
|
122
|
+
export function useLiveBellBadge(
|
|
123
|
+
store: InboxStore,
|
|
124
|
+
live: LiveActivitiesConfig,
|
|
125
|
+
seen: LiveSeenStore,
|
|
126
|
+
options: BadgeSyncOptions = {},
|
|
127
|
+
): BellBadge {
|
|
128
|
+
const enabled = options.enabled ?? true;
|
|
129
|
+
const { unread } = useBadgeState(store, options);
|
|
130
|
+
const activities = live.useActivities({ active: enabled });
|
|
131
|
+
const seenAt = useSyncExternalStore(seen.subscribe, seen.read, seen.read);
|
|
132
|
+
// The store's own half is already blanked by `useBadgeState`; the `enabled`
|
|
133
|
+
// guard here is for the ACTIVITIES half, which comes from a host hook that
|
|
134
|
+
// may have ignored the hint.
|
|
135
|
+
//
|
|
136
|
+
// A live entry COUNTS. It is a notification — it is the one the reader most
|
|
137
|
+
// wants to know about — and the panel it opens lists it.
|
|
138
|
+
const count = enabled ? unread + activities.length : 0;
|
|
139
|
+
const hasNew = enabled && (unread > 0 || hasUnseenActivity(activities, seenAt));
|
|
140
|
+
// Memoised on the two RESULTS, not on `activities`. A host's hook returns a
|
|
141
|
+
// fresh array every render — the storefront's maps its query's rows, so
|
|
142
|
+
// structural sharing keeps the DATA identical and the array new — so an
|
|
143
|
+
// `activities` dependency would invalidate on every render and the memo would
|
|
144
|
+
// buy nothing at all. `hasUnseenActivity` runs unmemoised in front of it,
|
|
145
|
+
// which is a `.some()` over the handful of things happening at once.
|
|
146
|
+
return useMemo(() => ({ count, hasNew }), [count, hasNew]);
|
|
147
|
+
}
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bare bell trigger with the live unread badge — for hosts that do not already
|
|
3
|
-
* have a styled icon-button slot.
|
|
4
|
-
*
|
|
3
|
+
* have a styled icon-button slot.
|
|
4
|
+
*
|
|
5
|
+
* A host with its own trigger chrome uses `useBellBadge` + `Panel` directly,
|
|
6
|
+
* and NOT `useUnreadCount`, which is what this sentence used to say. That
|
|
7
|
+
* advice was taken, verbatim and by name, by a storefront whose header needed
|
|
8
|
+
* its own trigger — and it gave that storefront a bell showing nothing at all
|
|
9
|
+
* while a live pedido sat in the panel it opens, because `useUnreadCount`
|
|
10
|
+
* counts inbox rows and knows nothing about what is happening right now.
|
|
5
11
|
*/
|
|
6
|
-
import {
|
|
12
|
+
import type { JSX } from 'react';
|
|
7
13
|
|
|
8
14
|
import { Badge } from '@12-apps/ui/data-display/Badge';
|
|
9
15
|
import { Box } from '@12-apps/ui/mui/Box';
|
|
10
16
|
|
|
11
17
|
import type { NotificationMessages } from '../messages';
|
|
12
18
|
|
|
19
|
+
import { useInboxBellBadge, useLiveBellBadge } from './bell-badge';
|
|
13
20
|
import { BellIcon } from './bell-icon';
|
|
14
|
-
import {
|
|
21
|
+
import type { NotificationsSignalHook, NotificationsSubscribe } from './hooks';
|
|
15
22
|
import type { LiveActivitiesConfig } from './live-config';
|
|
16
|
-
import {
|
|
23
|
+
import type { LiveSeenStore } from './live-seen';
|
|
17
24
|
import type { InboxStore } from './inbox-state';
|
|
18
25
|
|
|
19
26
|
const triggerSx = {
|
|
@@ -111,14 +118,12 @@ export function BellButton({
|
|
|
111
118
|
subscribe?: NotificationsSubscribe;
|
|
112
119
|
useSignal?: NotificationsSignalHook;
|
|
113
120
|
}): JSX.Element {
|
|
114
|
-
const
|
|
121
|
+
const badge = useInboxBellBadge(store, {
|
|
115
122
|
enabled,
|
|
116
123
|
...(subscribe ? { subscribe } : {}),
|
|
117
124
|
...(useSignal ? { useSignal } : {}),
|
|
118
125
|
});
|
|
119
|
-
|
|
120
|
-
// is by definition something the reader has not seen.
|
|
121
|
-
return <BellTrigger onClick={onClick} count={count} hasNew={count > 0} messages={messages} />;
|
|
126
|
+
return <BellTrigger onClick={onClick} {...badge} messages={messages} />;
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
/**
|
|
@@ -130,14 +135,9 @@ export function BellButton({
|
|
|
130
135
|
* unrelated component rather than here. The factory knows statically which host
|
|
131
136
|
* it is building for and picks one.
|
|
132
137
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* this hook there is no "nobody is looking" state to stand down in — `active`
|
|
137
|
-
* is simply `enabled`. A host that answers by polling therefore polls for every
|
|
138
|
-
* signed-in reader whether or not they ever open the centre. That is the price
|
|
139
|
-
* of a badge that knows about live activities at all, and the reason to answer
|
|
140
|
-
* this hook from a pushed cache rather than from an interval.
|
|
138
|
+
* What the number MEANS, and what it costs the host, is `bell-badge.ts` — the
|
|
139
|
+
* same hook a host with its own trigger chrome reaches through the factory's
|
|
140
|
+
* `useBellBadge`, so the two bells can never disagree about the count.
|
|
141
141
|
*/
|
|
142
142
|
export function LiveBellButton({
|
|
143
143
|
onClick,
|
|
@@ -156,22 +156,10 @@ export function LiveBellButton({
|
|
|
156
156
|
live: LiveActivitiesConfig;
|
|
157
157
|
seen: LiveSeenStore;
|
|
158
158
|
}): JSX.Element {
|
|
159
|
-
const
|
|
159
|
+
const badge = useLiveBellBadge(store, live, seen, {
|
|
160
160
|
enabled,
|
|
161
161
|
...(subscribe ? { subscribe } : {}),
|
|
162
162
|
...(useSignal ? { useSignal } : {}),
|
|
163
163
|
});
|
|
164
|
-
|
|
165
|
-
const seenIso = useSyncExternalStore(seen.subscribe, seen.read, seen.read);
|
|
166
|
-
const liveCount = enabled ? activities.length : 0;
|
|
167
|
-
return (
|
|
168
|
-
<BellTrigger
|
|
169
|
-
onClick={onClick}
|
|
170
|
-
// A live entry counts. It is a notification — it is the one the reader
|
|
171
|
-
// most wants to know about — and the panel it opens lists it.
|
|
172
|
-
count={unread + liveCount}
|
|
173
|
-
hasNew={unread > 0 || (enabled && hasUnseenActivity(activities, seenIso))}
|
|
174
|
-
messages={messages}
|
|
175
|
-
/>
|
|
176
|
-
);
|
|
164
|
+
return <BellTrigger onClick={onClick} {...badge} messages={messages} />;
|
|
177
165
|
}
|
|
@@ -3,6 +3,7 @@ import { useState, type ComponentType, type JSX } from 'react';
|
|
|
3
3
|
import { messagesOf, type NotificationMessages } from '../messages';
|
|
4
4
|
|
|
5
5
|
import { createNotificationsApiClient, type NotificationsApiClient } from './api';
|
|
6
|
+
import { useInboxBellBadge, useLiveBellBadge, type BellBadge } from './bell-badge';
|
|
6
7
|
import { BellButton, LiveBellButton, type BellButtonProps } from './bell-button';
|
|
7
8
|
import {
|
|
8
9
|
useUnreadCount,
|
|
@@ -11,7 +12,7 @@ import {
|
|
|
11
12
|
} from './hooks';
|
|
12
13
|
import { createInboxStore, type InboxStore } from './inbox-state';
|
|
13
14
|
import type { LiveActivitiesConfig } from './live-config';
|
|
14
|
-
import { createLiveSeenStore } from './live-seen';
|
|
15
|
+
import { createLiveSeenStore, type LiveSeenStore } from './live-seen';
|
|
15
16
|
import { lazyNotificationsPanel } from './panel-lazy';
|
|
16
17
|
import type { NotificationsPanelProps } from './panel';
|
|
17
18
|
import { lazyPreferencesPage } from './page-lazy';
|
|
@@ -94,8 +95,31 @@ export interface WebNotifications {
|
|
|
94
95
|
enabled?: boolean;
|
|
95
96
|
onNavigate?: (link: string) => void;
|
|
96
97
|
}>;
|
|
97
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* The unread INBOX count.
|
|
100
|
+
*
|
|
101
|
+
* For a host with its own trigger chrome only when that host configured no
|
|
102
|
+
* live activities — otherwise it is a bell that ignores everything happening
|
|
103
|
+
* right now, and `useBellBadge` below is the door. Still the right hook for
|
|
104
|
+
* anything that genuinely wants "how many unread rows".
|
|
105
|
+
*/
|
|
98
106
|
useUnreadCount: (options?: { enabled?: boolean }) => number;
|
|
107
|
+
/**
|
|
108
|
+
* The badge's NUMBER AND TONE, for a host with its own trigger chrome.
|
|
109
|
+
*
|
|
110
|
+
* What `useUnreadCount` should have been for a host that also configured live
|
|
111
|
+
* activities, and the reason it is a second door rather than a change to that
|
|
112
|
+
* one: a count alone cannot express a bell, because a live entry is present
|
|
113
|
+
* without being news (see `./bell-badge`). A host that renders
|
|
114
|
+
* `useUnreadCount` in its own chrome gets a badge that ignores everything
|
|
115
|
+
* happening right now — which is not a subtle wrongness, it is the pinned
|
|
116
|
+
* pedido on screen going uncounted.
|
|
117
|
+
*
|
|
118
|
+
* Identical to what this package's own `BellButton` draws, because it is the
|
|
119
|
+
* hook that bell uses. Without live activities configured it is
|
|
120
|
+
* `useUnreadCount` plus `hasNew: count > 0`.
|
|
121
|
+
*/
|
|
122
|
+
useBellBadge: (options?: { enabled?: boolean }) => BellBadge;
|
|
99
123
|
/** The shared client state, for host glue. */
|
|
100
124
|
store: InboxStore;
|
|
101
125
|
/** The bound wire client. */
|
|
@@ -104,6 +128,33 @@ export interface WebNotifications {
|
|
|
104
128
|
messages: NotificationMessages;
|
|
105
129
|
}
|
|
106
130
|
|
|
131
|
+
/** What the factory passes both badge hooks: whatever realtime wiring it has. */
|
|
132
|
+
type SubscribeOption = {
|
|
133
|
+
subscribe?: NotificationsSubscribe;
|
|
134
|
+
useSignal?: NotificationsSignalHook;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The two badge hooks, bound to this factory's store.
|
|
139
|
+
*
|
|
140
|
+
* `useBellBadge` is chosen ONCE here, the same way `Bell` is below and for the
|
|
141
|
+
* same reason: `live.useActivities` is a hook, so which implementation runs
|
|
142
|
+
* must not be a per-render decision.
|
|
143
|
+
*/
|
|
144
|
+
function bindBadgeHooks(
|
|
145
|
+
store: InboxStore,
|
|
146
|
+
subscribeOption: SubscribeOption,
|
|
147
|
+
liveSeen: LiveSeenStore,
|
|
148
|
+
live: LiveActivitiesConfig | undefined,
|
|
149
|
+
): Pick<WebNotifications, 'useUnreadCount' | 'useBellBadge'> {
|
|
150
|
+
return {
|
|
151
|
+
useUnreadCount: (options = {}) => useUnreadCount(store, { ...options, ...subscribeOption }),
|
|
152
|
+
useBellBadge: live
|
|
153
|
+
? (options = {}) => useLiveBellBadge(store, live, liveSeen, { ...options, ...subscribeOption })
|
|
154
|
+
: (options = {}) => useInboxBellBadge(store, { ...options, ...subscribeOption }),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
107
158
|
export function createWebNotifications(config: NotificationsWebConfig): WebNotifications {
|
|
108
159
|
const messages = messagesOf(config);
|
|
109
160
|
const api = createNotificationsApiClient(
|
|
@@ -147,9 +198,7 @@ export function createWebNotifications(config: NotificationsWebConfig): WebNotif
|
|
|
147
198
|
...(live ? { live, liveSeen } : {}),
|
|
148
199
|
});
|
|
149
200
|
|
|
150
|
-
|
|
151
|
-
return useUnreadCount(store, { ...options, ...subscribeOption });
|
|
152
|
-
}
|
|
201
|
+
const badgeHooks = bindBadgeHooks(store, subscribeOption, liveSeen, live);
|
|
153
202
|
|
|
154
203
|
function BellWithPanel({
|
|
155
204
|
enabled = true,
|
|
@@ -176,7 +225,7 @@ export function createWebNotifications(config: NotificationsWebConfig): WebNotif
|
|
|
176
225
|
BellButton: Bell,
|
|
177
226
|
Panel,
|
|
178
227
|
BellWithPanel,
|
|
179
|
-
|
|
228
|
+
...badgeHooks,
|
|
180
229
|
store,
|
|
181
230
|
api,
|
|
182
231
|
messages,
|
package/src/react/hooks.ts
CHANGED
|
@@ -48,23 +48,60 @@ export function useInboxState(store: InboxStore): InboxState {
|
|
|
48
48
|
return useSyncExternalStore(store.subscribe, store.getState, store.getState);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/** What both badge hooks below take, and what the bell passes them. */
|
|
52
|
+
export interface BadgeSyncOptions {
|
|
53
|
+
enabled?: boolean;
|
|
54
|
+
subscribe?: NotificationsSubscribe;
|
|
55
|
+
useSignal?: NotificationsSignalHook;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* What a disabled badge reads, instead of whatever the store happens to hold.
|
|
60
|
+
*
|
|
61
|
+
* A CONSTANT, so `useSyncExternalStore`'s identity comparison sees no change
|
|
62
|
+
* across the renders of a signed-out session.
|
|
63
|
+
*/
|
|
64
|
+
const NOTHING_TO_SHOW: InboxState = {
|
|
65
|
+
unread: 0,
|
|
66
|
+
items: [],
|
|
67
|
+
status: 'idle',
|
|
68
|
+
nextCursor: null,
|
|
69
|
+
loadingMore: false,
|
|
70
|
+
};
|
|
71
|
+
|
|
51
72
|
/**
|
|
52
|
-
* The
|
|
73
|
+
* The badge's server state, kept fresh: pushed while a subscription is live,
|
|
74
|
+
* polled otherwise.
|
|
75
|
+
*
|
|
76
|
+
* The whole state rather than the count, because every badge hook that layers
|
|
77
|
+
* on top of it needs the poll and the subscription mounted exactly ONCE per
|
|
78
|
+
* bell — read through two hooks, a bell that showed both a number and a tone
|
|
79
|
+
* would open two of everything.
|
|
80
|
+
*
|
|
81
|
+
* ## `enabled` gates the ANSWER, not only the fetching
|
|
53
82
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
83
|
+
* It gates the poll and the subscription, which is the obvious half. It also
|
|
84
|
+
* blanks the returned state, which is the half that was missing and matters
|
|
85
|
+
* more: the store is per FACTORY and a host builds one at module scope for the
|
|
86
|
+
* whole app, so signing out does not empty it — `refreshBadge` swallows the 401
|
|
87
|
+
* and leaves the last number in place. Without this, a hook told there is
|
|
88
|
+
* nobody signed in hands back the PREVIOUS reader's unread count and their
|
|
89
|
+
* inbox rows.
|
|
90
|
+
*
|
|
91
|
+
* Deliberately here rather than at each caller. It was at each caller, three
|
|
92
|
+
* times, in three shapes, and two of them were dead weight no test could reach
|
|
93
|
+
* — which is what an invariant looks like just before one copy of it goes
|
|
94
|
+
* missing.
|
|
95
|
+
*
|
|
96
|
+
* INTERNAL. Not exported from `./index`: it hands back rows as well as a count,
|
|
97
|
+
* and a host wanting a number has `useUnreadCount` or the factory's
|
|
98
|
+
* `useBellBadge`.
|
|
56
99
|
*/
|
|
57
|
-
export function
|
|
58
|
-
store: InboxStore,
|
|
59
|
-
options: {
|
|
60
|
-
enabled?: boolean;
|
|
61
|
-
subscribe?: NotificationsSubscribe;
|
|
62
|
-
useSignal?: NotificationsSignalHook;
|
|
63
|
-
} = {},
|
|
64
|
-
): number {
|
|
100
|
+
export function useBadgeState(store: InboxStore, options: BadgeSyncOptions = {}): InboxState {
|
|
65
101
|
const enabled = options.enabled ?? true;
|
|
66
102
|
const subscribe = options.subscribe;
|
|
67
|
-
const
|
|
103
|
+
const live = useInboxState(store);
|
|
104
|
+
const state = enabled ? live : NOTHING_TO_SHOW;
|
|
68
105
|
|
|
69
106
|
// Called unconditionally — it is a hook, so it cannot sit behind `enabled`.
|
|
70
107
|
// The host's own hook decides what to do when there is nothing to hear.
|
|
@@ -91,7 +128,18 @@ export function useUnreadCount(
|
|
|
91
128
|
};
|
|
92
129
|
}, [store, enabled, subscribe]);
|
|
93
130
|
|
|
94
|
-
return
|
|
131
|
+
return state;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The bell badge number, for a host with its own trigger chrome.
|
|
136
|
+
*
|
|
137
|
+
* A host that also publishes live activities wants `useBellBadge` from the
|
|
138
|
+
* factory instead — this one counts inbox rows and knows nothing about what is
|
|
139
|
+
* happening right now.
|
|
140
|
+
*/
|
|
141
|
+
export function useUnreadCount(store: InboxStore, options: BadgeSyncOptions = {}): number {
|
|
142
|
+
return useBadgeState(store, options).unread;
|
|
95
143
|
}
|
|
96
144
|
|
|
97
145
|
/** The panel's list — only fetches while the panel is open. */
|
package/src/react/index.ts
CHANGED
|
@@ -26,6 +26,15 @@ export {
|
|
|
26
26
|
type PushRegistrationPayload,
|
|
27
27
|
} from './api';
|
|
28
28
|
|
|
29
|
+
// `useInboxBellBadge` and `useLiveBellBadge` are deliberately NOT exported, and
|
|
30
|
+
// the live one is why: it takes a `LiveSeenStore`, and the only store that
|
|
31
|
+
// works is the factory's own — the panel writes "seen" into THAT one. A host
|
|
32
|
+
// handed the hook and no way to build the store would either hand-roll a
|
|
33
|
+
// `{read, mark, subscribe}` nothing ever writes to, and get a badge that is
|
|
34
|
+
// permanently `new`, or reach for `createLiveSeenStore` and find it unexported
|
|
35
|
+
// too. `useBellBadge` off the factory is the door, already bound to both.
|
|
36
|
+
export type { BellBadge } from './bell-badge';
|
|
37
|
+
|
|
29
38
|
export {
|
|
30
39
|
BADGE_POLL_MS,
|
|
31
40
|
BADGE_RECONCILE_MS,
|
|
@@ -36,10 +45,14 @@ export {
|
|
|
36
45
|
type InboxStore,
|
|
37
46
|
} from './inbox-state';
|
|
38
47
|
|
|
48
|
+
// `useBadgeState` is NOT here, for the reason the raw badge hooks above are
|
|
49
|
+
// not: it hands back the inbox ROWS as well as the count, and a host wanting a
|
|
50
|
+
// number already has `useUnreadCount` and the factory's `useBellBadge`.
|
|
39
51
|
export {
|
|
40
52
|
useInboxList,
|
|
41
53
|
useInboxState,
|
|
42
54
|
useUnreadCount,
|
|
55
|
+
type BadgeSyncOptions,
|
|
43
56
|
type NotificationsSignalHook,
|
|
44
57
|
type NotificationsSubscribe,
|
|
45
58
|
} from './hooks';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react/bell-icon.tsx","../src/react/inbox-state.ts","../src/react/hooks.ts"],"sourcesContent":["/** Inline SVG bell (no icon-library dependency in this package). */\nimport type { JSX } from 'react';\n\nimport { Box } from '@12-apps/ui/mui/Box';\n\nexport function BellIcon({\n size = 28,\n dim = false,\n}: {\n size?: number;\n dim?: boolean;\n}): JSX.Element {\n return (\n <Box\n component=\"svg\"\n viewBox=\"0 0 24 24\"\n aria-hidden\n sx={{\n width: size,\n height: size,\n fill: 'none',\n stroke: 'currentColor',\n opacity: dim ? 0.4 : 1,\n }}\n strokeWidth={1.8}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M6 9a6 6 0 0 1 12 0c0 5 2 6 2 6H4s2-1 2-6\" />\n <path d=\"M10 20a2 2 0 0 0 4 0\" />\n </Box>\n );\n}\n","import type { InboxNotification } from '../wire';\n\nimport type { NotificationsApiClient } from './api';\n\n/**\n * The inbox's client state, as ONE store shared by the bell and the panel.\n *\n * They have to share it: marking a row read in the panel must move the badge in\n * the same tick, and an arrival must add a row to the list AND to the count.\n * the origin got that for free from a react-query cache the host had already\n * mounted; a published package cannot assume one — a query client is a host\n * decision, and requiring a particular one (or a particular version of one) is\n * the kind of dependency that keeps a package out of a host that made the other\n * choice. So the sharing is explicit and dependency-free: one subscribable\n * store, read through `useSyncExternalStore`.\n *\n * Optimistic on every write, with invalidate-on-error: the badge and the list\n * update instantly, and a failed write refetches the server truth rather than\n * leaving the screen asserting something the database does not say.\n */\n\nexport const PAGE_SIZE = 20;\n\n/** The badge's poll while nothing is pushing to us. */\nexport const BADGE_POLL_MS = 60_000;\n\n/**\n * The badge's interval while a realtime connection is live.\n *\n * Five minutes, not \"never\": this is the reconcile that catches an event the bus\n * dropped, and it costs one COUNT per open tab per five minutes. Deliberately\n * far slower than an operational screen's — a bell badge is ambient, and the\n * arrival that matters is pushed within milliseconds anyway. The poll does NOT\n * stop, which is the standing contract: a dropped event must cost latency and\n * never correctness.\n */\nexport const BADGE_RECONCILE_MS = 300_000;\n\nexport type InboxListStatus = 'idle' | 'pending' | 'ready' | 'error';\n\nexport interface InboxState {\n unread: number;\n items: InboxNotification[];\n status: InboxListStatus;\n /** A cursor means there is another page. */\n nextCursor: string | null;\n loadingMore: boolean;\n}\n\nexport interface InboxStore {\n getState(): InboxState;\n subscribe(listener: () => void): () => void;\n /** Load the first page (idempotent while one is in flight). */\n open(): void;\n /** Refetch the badge count. */\n refreshBadge(): void;\n /** Refetch both — what a realtime hint or a failed write triggers. */\n invalidate(): void;\n loadMore(): void;\n markRead(ids: readonly string[]): void;\n markAllRead(): void;\n remove(id: string): void;\n}\n\nconst EMPTY: InboxState = {\n unread: 0,\n items: [],\n status: 'idle',\n nextCursor: null,\n loadingMore: false,\n};\n\n/** The mutable cell the functions below share, so each one stays small. */\ninterface Cell {\n state: InboxState;\n listeners: Set<() => void>;\n /** Fences a stale reload: a newer one must always win. */\n request: number;\n}\n\nfunction patch(cell: Cell, next: Partial<InboxState>): void {\n cell.state = { ...cell.state, ...next };\n for (const listener of cell.listeners) listener();\n}\n\n/** Refetch the badge count. The number is always one the server just gave us. */\nfunction refreshBadge(cell: Cell, api: NotificationsApiClient): void {\n void api\n .unreadCount()\n .then((unread) => patch(cell, { unread }))\n .catch(() => undefined);\n}\n\n/**\n * Reload page one, discarding whatever the optimistic path had produced.\n * `request` fences it: a reload that started before a newer one must not land\n * after it and reinstate stale rows.\n */\nfunction reloadList(cell: Cell, api: NotificationsApiClient): void {\n const token = (cell.request += 1);\n patch(cell, { status: cell.state.items.length > 0 ? cell.state.status : 'pending' });\n void api\n .listNotifications({ limit: PAGE_SIZE })\n .then((page) => {\n if (token !== cell.request) return;\n patch(cell, { items: page.items, nextCursor: page.nextCursor, status: 'ready' });\n })\n .catch(() => {\n if (token !== cell.request) return;\n patch(cell, { status: 'error' });\n });\n}\n\nfunction invalidate(cell: Cell, api: NotificationsApiClient): void {\n refreshBadge(cell, api);\n if (cell.state.status !== 'idle') reloadList(cell, api);\n}\n\n/** Apply an optimistic edit; on failure, take the server's word instead. */\nfunction write(\n cell: Cell,\n api: NotificationsApiClient,\n apply: () => void,\n send: () => Promise<{ ok: boolean }>,\n): void {\n apply();\n void send()\n .then((result) => {\n if (!result.ok) invalidate(cell, api);\n })\n .catch(() => invalidate(cell, api));\n}\n\nfunction bumpUnread(cell: Cell, delta: number): void {\n patch(cell, { unread: Math.max(0, cell.state.unread + delta) });\n}\n\nfunction loadMore(cell: Cell, api: NotificationsApiClient): void {\n const cursor = cell.state.nextCursor;\n if (!cursor || cell.state.loadingMore) return;\n patch(cell, { loadingMore: true });\n void api\n .listNotifications({ cursor, limit: PAGE_SIZE })\n .then((page) => {\n patch(cell, {\n items: [...cell.state.items, ...page.items],\n nextCursor: page.nextCursor,\n loadingMore: false,\n });\n })\n .catch(() => patch(cell, { loadingMore: false }));\n}\n\nfunction markRead(cell: Cell, api: NotificationsApiClient, ids: readonly string[]): void {\n const readAt = new Date().toISOString();\n let flipped = 0;\n const items = cell.state.items.map((item) => {\n if (!ids.includes(item.id) || item.readAt !== null) return item;\n flipped += 1;\n return { ...item, readAt };\n });\n if (flipped === 0) return;\n write(\n cell,\n api,\n () => {\n patch(cell, { items });\n bumpUnread(cell, -flipped);\n },\n () => api.markRead(ids),\n );\n}\n\nfunction remove(cell: Cell, api: NotificationsApiClient, id: string): void {\n const target = cell.state.items.find((item) => item.id === id);\n if (!target) return;\n const items = cell.state.items.filter((item) => item.id !== id);\n write(\n cell,\n api,\n () => {\n patch(cell, { items });\n if (target.readAt === null) bumpUnread(cell, -1);\n },\n () => api.remove([id]),\n );\n}\n\nexport function createInboxStore(api: NotificationsApiClient): InboxStore {\n const cell: Cell = { state: EMPTY, listeners: new Set(), request: 0 };\n return {\n getState: () => cell.state,\n subscribe(listener) {\n cell.listeners.add(listener);\n return () => cell.listeners.delete(listener);\n },\n open() {\n if (cell.state.status === 'idle') reloadList(cell, api);\n },\n refreshBadge: () => refreshBadge(cell, api),\n invalidate: () => invalidate(cell, api),\n loadMore: () => loadMore(cell, api),\n markRead: (ids) => markRead(cell, api, ids),\n markAllRead() {\n const readAt = new Date().toISOString();\n const items = cell.state.items.map((item) => ({ ...item, readAt: item.readAt ?? readAt }));\n write(\n cell,\n api,\n () => patch(cell, { items, unread: 0 }),\n () => api.markAllRead(),\n );\n },\n remove: (id) => remove(cell, api, id),\n };\n}\n","import { useEffect, useSyncExternalStore } from 'react';\n\nimport {\n BADGE_POLL_MS,\n BADGE_RECONCILE_MS,\n type InboxState,\n type InboxStore,\n} from './inbox-state';\n\n/**\n * The two hooks the bell and the panel use, and the realtime seam between them.\n *\n * A host that has a message bus passes `subscribe`; one that has not passes\n * nothing and keeps the 60 s poll. The bell ships in this package and mounts in\n * whatever embeds it, so it must not require the host to have adopted anything.\n */\n\n/**\n * How the surface learns an inbox changed without asking.\n *\n * Called once per mounted bell with a callback that means only \"ask again\" — no\n * payload, so the number on screen is always one the server just gave us.\n * Returns its own teardown. A host wires this to whatever it already has.\n */\nexport type NotificationsSubscribe = (onHint: () => void) => () => void;\n\n/**\n * The same wiring, as a HOOK — for a host whose realtime connection lives in\n * React context rather than in a module.\n *\n * `subscribe` above is supplied at FACTORY time, which is module scope, and a\n * context-bound connection cannot be reached from there: the provider holding\n * it is inside the tree. A host in that shape (a `<UserRealtimeProvider>` and a\n * `useUserTopics` hook, which is the common one) had no way to pass anything at\n * all, and the badge simply never heard an event.\n *\n * So this is the second door, and it is the one `@12-apps/app-shell` already\n * uses for the same problem — its consent dialog takes a `useSignal` hook for\n * exactly this reason. Two packages solving one problem two ways is how an\n * adopter ends up believing the feature is unavailable to it.\n *\n * Called during render, so it may use context and hooks freely. Pass one or\n * the other; passing both runs both, which is a host's business.\n */\nexport type NotificationsSignalHook = (onHint: () => void) => void;\n\nexport function useInboxState(store: InboxStore): InboxState {\n return useSyncExternalStore(store.subscribe, store.getState, store.getState);\n}\n\n/**\n * The bell badge number: pushed while a subscription is live, polled otherwise.\n *\n * `enabled` gates the poll AND the subscription. A signed-out header still\n * mounts the bell, and there is nothing for it to hear.\n */\nexport function useUnreadCount(\n store: InboxStore,\n options: {\n enabled?: boolean;\n subscribe?: NotificationsSubscribe;\n useSignal?: NotificationsSignalHook;\n } = {},\n): number {\n const enabled = options.enabled ?? true;\n const subscribe = options.subscribe;\n const { unread } = useInboxState(store);\n\n // Called unconditionally — it is a hook, so it cannot sit behind `enabled`.\n // The host's own hook decides what to do when there is nothing to hear.\n options.useSignal?.(() => {\n if (enabled) store.invalidate();\n });\n\n useEffect(() => {\n if (!enabled) return;\n store.refreshBadge();\n const unsubscribe = subscribe?.(() => store.invalidate());\n // A live subscription relaxes the poll to the reconcile interval; without\n // one it stays the 60 s poll.\n const interval = setInterval(\n () => store.refreshBadge(),\n subscribe ? BADGE_RECONCILE_MS : BADGE_POLL_MS,\n );\n const onFocus = (): void => store.refreshBadge();\n globalThis.addEventListener?.('focus', onFocus);\n return () => {\n clearInterval(interval);\n globalThis.removeEventListener?.('focus', onFocus);\n unsubscribe?.();\n };\n }, [store, enabled, subscribe]);\n\n return enabled ? unread : 0;\n}\n\n/** The panel's list — only fetches while the panel is open. */\nexport function useInboxList(store: InboxStore, open: boolean): InboxState {\n const state = useInboxState(store);\n useEffect(() => {\n if (open) store.open();\n }, [store, open]);\n return state;\n}\n"],"mappings":";;;;;AAGA,SAAS,WAAW;AAUhB,SAeE,KAfF;AARG,SA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AAC;AAE9B,SAAO,UAAU,SAAS;AAC5B;AAtCgB;AAyCT,SAAS,aAAa,OAAmB,MAA2B;AACzE,QAAM,QAAQ,cAAc,KAAK;AACjC,YAAU,MAAM;AACd,QAAI,KAAM,OAAM,KAAK;AAAA,EACvB,GAAG,CAAC,OAAO,IAAI,CAAC;AAChB,SAAO;AACT;AANgB;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react/api.ts","../src/react/transport.ts","../src/react/create-web-notifications.tsx","../src/react/bell-button.tsx","../src/react/live-seen.ts","../src/react/panel-lazy.tsx","../src/react/page-lazy.tsx"],"sourcesContent":["import type { ChannelRow } from '../preferences-core';\nimport type { NotificationChannel } from '../types';\nimport type { ListNotificationsResult } from '../wire';\n\nimport type { NotificationsResult, NotificationsTransport } from './transport';\n\n/**\n * The wire client, bound to one mount (12-15).\n *\n * Every path this package's screens can call, in one place — which is what\n * makes the api half's route table and the web half's URLs one contract instead\n * of two lists that drift.\n */\n\n/** `GET <mount>/notification-preferences` and the PUT's answer. */\nexport interface PreferencesPayload {\n preferences: Record<string, ChannelRow>;\n availability: Record<NotificationChannel, boolean>;\n /** The host's taxonomy, so the screen renders it without being told twice. */\n categories: string[];\n}\n\n/** `GET <mount>/push-subscriptions`. */\nexport interface PushRegistrationPayload {\n /** null = web push is not configured on this deployment. */\n vapidPublicKey: string | null;\n count: number;\n /**\n * Whether the endpoint asked about is still registered to the caller. Present\n * only when one was passed — see {@link NotificationsApiClient.getPushRegistration}.\n */\n registered?: boolean;\n}\n\nexport interface NotificationsApiClient {\n listNotifications(input: {\n cursor?: string | null;\n limit?: number;\n filter?: 'all' | 'unread';\n }): Promise<ListNotificationsResult>;\n unreadCount(): Promise<number>;\n markRead(ids: readonly string[]): Promise<NotificationsResult<{ updated: number }>>;\n markAllRead(): Promise<NotificationsResult<{ updated: number }>>;\n remove(ids: readonly string[]): Promise<NotificationsResult<{ deleted: number }>>;\n getPreferences(): Promise<PreferencesPayload>;\n savePreference(\n category: string,\n channel: NotificationChannel,\n enabled: boolean,\n ): Promise<NotificationsResult<PreferencesPayload>>;\n /**\n * The deployment's VAPID key and the caller's device count — and, when an\n * `endpoint` is passed, whether the SERVER still has that exact subscription\n * under the caller's id. The browser holding a subscription object is not\n * evidence of that: a re-own or a 404/410 prune drops the row and leaves the\n * browser's object in place.\n */\n getPushRegistration(input?: { endpoint?: string }): Promise<PushRegistrationPayload>;\n savePushSubscription(input: {\n endpoint: string;\n keys: { p256dh: string; auth: string };\n }): Promise<NotificationsResult<{ count: number }>>;\n removePushSubscription(endpoint: string): Promise<NotificationsResult<{ count: number }>>;\n}\n\nexport function createNotificationsApiClient(\n apiBase: string,\n transport: NotificationsTransport,\n): NotificationsApiClient {\n const base = apiBase.replace(/\\/$/, '');\n const url = (path: string): string => `${base}${path}`;\n\n return {\n listNotifications({ cursor, limit, filter }) {\n const params = new URLSearchParams();\n if (limit !== undefined) params.set('limit', String(limit));\n if (cursor) params.set('cursor', cursor);\n if (filter) params.set('filter', filter);\n const query = params.toString();\n return transport.get<ListNotificationsResult>(\n url(`/notifications${query ? `?${query}` : ''}`),\n );\n },\n async unreadCount() {\n const { count } = await transport.get<{ count: number }>(\n url('/notifications/unread-count'),\n );\n return count;\n },\n markRead: (ids) =>\n transport.send(url('/notifications/mark-read'), 'POST', { ids: [...ids] }),\n markAllRead: () => transport.send(url('/notifications/mark-read'), 'POST', { all: true }),\n remove: (ids) => transport.send(url('/notifications/delete'), 'POST', { ids: [...ids] }),\n getPreferences: () => transport.get<PreferencesPayload>(url('/notification-preferences')),\n savePreference: (category, channel, enabled) =>\n transport.send(url('/notification-preferences'), 'PUT', {\n [category]: { [channel]: enabled },\n }),\n getPushRegistration: ({ endpoint } = {}) =>\n transport.get<PushRegistrationPayload>(\n url(\n endpoint\n ? `/push-subscriptions?endpoint=${encodeURIComponent(endpoint)}`\n : '/push-subscriptions',\n ),\n ),\n savePushSubscription: (input) => transport.send(url('/push-subscriptions'), 'POST', input),\n removePushSubscription: (endpoint) =>\n transport.send(url('/push-subscriptions'), 'DELETE', { endpoint }),\n };\n}\n","/**\n * How the notification screens reach their data (12-15) — the report-builder\n * transport doctrine: this is the ONLY way the surface performs I/O, so a\n * caller supplying one has substituted the entire backend without stubbing a\n * global. The default is same-origin `fetch` riding the browser's cookies.\n */\n\n/** A write outcome the screens branch on — never a thrown mutation. */\nexport type NotificationsResult<T> = { ok: true; data: T } | { ok: false; error: string };\n\n/** A failed read, carrying the status the screens branch on (401 = signed out). */\nexport class NotificationsHttpError extends Error {\n readonly status: number;\n constructor(status: number, message: string) {\n super(message);\n this.name = 'NotificationsHttpError';\n this.status = status;\n Object.setPrototypeOf(this, NotificationsHttpError.prototype);\n }\n}\n\nexport interface NotificationsTransport {\n /** A read. Returns the payload INSIDE the `{ data }` envelope. */\n get<T>(path: string): Promise<T>;\n /** A write. Returns a {@link NotificationsResult} rather than rejecting. */\n send<T>(path: string, method: string, body?: unknown): Promise<NotificationsResult<T>>;\n}\n\n/**\n * @param fallbackError What a failed write says when the server sent no\n * sentence of its own — REQUIRED, the host's words. `createWebNotifications`\n * already passes its (equally required) `messages.operationFailed`; only a\n * host constructing the transport directly writes it here. The old default\n * was one application's Portuguese, and the only string in this package the\n * required-messages port did not cover.\n */\nexport function httpNotificationsTransport(fallbackError: string): NotificationsTransport {\n return {\n async get<T>(path: string): Promise<T> {\n const response = await fetch(path, {\n credentials: 'same-origin',\n headers: { Accept: 'application/json' },\n });\n const payload = (await response.json().catch(() => null)) as\n | { data?: T; error?: string }\n | null;\n if (!response.ok) {\n throw new NotificationsHttpError(\n response.status,\n payload?.error ?? `HTTP ${response.status} for ${path}`,\n );\n }\n return (payload?.data ?? payload) as T;\n },\n\n async send<T>(path: string, method: string, body?: unknown): Promise<NotificationsResult<T>> {\n try {\n const response = await fetch(path, {\n method,\n credentials: 'same-origin',\n headers: {\n Accept: 'application/json',\n ...(body === undefined ? {} : { 'Content-Type': 'application/json' }),\n },\n ...(body === undefined ? {} : { body: JSON.stringify(body) }),\n });\n if (response.status === 204) return { ok: true, data: undefined as T };\n const payload = (await response.json().catch(() => null)) as\n | { data?: T; error?: string }\n | null;\n if (!response.ok) return { ok: false, error: payload?.error ?? fallbackError };\n return { ok: true, data: (payload?.data ?? payload) as T };\n } catch {\n return { ok: false, error: fallbackError };\n }\n },\n };\n}\n","import { useState, type ComponentType, type JSX } from 'react';\n\nimport { messagesOf, type NotificationMessages } from '../messages';\n\nimport { createNotificationsApiClient, type NotificationsApiClient } from './api';\nimport { BellButton, LiveBellButton, type BellButtonProps } from './bell-button';\nimport {\n useUnreadCount,\n type NotificationsSignalHook,\n type NotificationsSubscribe,\n} from './hooks';\nimport { createInboxStore, type InboxStore } from './inbox-state';\nimport type { LiveActivitiesConfig } from './live-config';\nimport { createLiveSeenStore } from './live-seen';\nimport { lazyNotificationsPanel } from './panel-lazy';\nimport type { NotificationsPanelProps } from './panel';\nimport { lazyPreferencesPage } from './page-lazy';\nimport type { PreferencesScreenProps } from './preferences-screen';\nimport { httpNotificationsTransport, type NotificationsTransport } from './transport';\nimport type { WebPushSetupConfig } from './web-push-setup';\n\n/**\n * The one thing this package exposes to a FRONTEND host (12-15).\n *\n * Everything the notification centre IS — the bell with its live badge, the\n * slide-over inbox with its optimistic mark-read / delete / mark-all and its\n * cursor pager, the preferences matrix with its availability hints and the\n * per-browser push enable step, and every wire call between them — lives inside\n * this package. The host names where the API is mounted, and that is the whole\n * wiring.\n *\n * `page` is the standalone surface (the preferences screen), which is the one\n * thing a host routes to. The bell and the panel are a PAIR a host drops into\n * its own chrome, and they share one store, so a read in the panel moves the\n * badge in the same tick.\n */\n\nexport interface NotificationsWebConfig {\n /** The account mount the routes live under, e.g. `/api/account`. */\n apiBase: string;\n /** How the surface reaches its data. Default: same-origin fetch. */\n transport?: NotificationsTransport;\n /** User-facing copy overrides (pt-BR product copy by default). */\n messages: NotificationMessages;\n /**\n * How the surface learns an inbox changed without asking — the host's message\n * bus. Without it the badge keeps its 60 s poll, which is the standing\n * contract rather than a fallback: a dropped event must cost latency, never\n * correctness.\n */\n subscribe?: NotificationsSubscribe;\n /**\n * The same wiring as a HOOK, for a host whose realtime connection lives in\n * React context — see `NotificationsSignalHook`. `subscribe` is read at\n * factory time, which such a host cannot reach.\n */\n useSignal?: NotificationsSignalHook;\n /** The browser push enable step's host seams (SW path, platform hint). */\n webPush?: WebPushSetupConfig;\n /**\n * LIVE ACTIVITIES — the ongoing-state entries pinned above the inbox list.\n *\n * Opt-in, and absent means absent: a host that passes nothing gets the panel\n * it had, with no section, no heading and no reserved space. See\n * `./live-config` for the two things a host has to supply (where they come\n * from, and what the section says) and `../live` for what one IS.\n */\n liveActivities?: LiveActivitiesConfig;\n}\n\nexport interface WebNotifications {\n /**\n * The routed surface: the preferences screen.\n *\n * Loaded on demand — see `page-lazy.tsx`. A host that mounts only the bell and\n * the panel never downloads it, and a host that routes to it fetches it while\n * entering that route.\n */\n page: ComponentType<PreferencesScreenProps>;\n /** The bell, already bound to the shared store. */\n BellButton: ComponentType<BellButtonProps>;\n /**\n * The inbox slide-over, sharing that store.\n *\n * Loaded the first time it is opened — see `panel-lazy.tsx`. Until then a\n * host's chrome carries the bell and nothing else.\n */\n Panel: ComponentType<NotificationsPanelProps>;\n /**\n * Bell + panel as ONE element, for a host that just wants the feature in its\n * header and does not want to own the open/closed state.\n */\n BellWithPanel: ComponentType<{\n enabled?: boolean;\n onNavigate?: (link: string) => void;\n }>;\n /** The badge number, for a host with its own trigger chrome. */\n useUnreadCount: (options?: { enabled?: boolean }) => number;\n /** The shared client state, for host glue. */\n store: InboxStore;\n /** The bound wire client. */\n api: NotificationsApiClient;\n /** The copy in force, so a host's own chrome can reuse a sentence. */\n messages: NotificationMessages;\n}\n\nexport function createWebNotifications(config: NotificationsWebConfig): WebNotifications {\n const messages = messagesOf(config);\n const api = createNotificationsApiClient(\n config.apiBase,\n config.transport ?? httpNotificationsTransport(messages.operationFailed),\n );\n const store = createInboxStore(api);\n const webPush = config.webPush ?? {};\n const subscribe = config.subscribe;\n const subscribeOption = {\n ...(subscribe ? { subscribe } : {}),\n ...(config.useSignal ? { useSignal: config.useSignal } : {}),\n };\n\n // One store per factory, shared by the bell that READS it and the panel that\n // WRITES it — the same arrangement as the inbox store above, and for the same\n // reason: two independent copies would disagree about what the reader saw.\n const liveSeen = createLiveSeenStore();\n\n // Chosen ONCE, here, because `useActivities` is a hook and the choice must\n // not be made per render: a bell that read an optional config inside itself\n // would be calling a hook conditionally.\n const live = config.liveActivities;\n const Bell: ComponentType<BellButtonProps> = live\n ? (props) => (\n <LiveBellButton\n {...props}\n store={store}\n messages={messages}\n live={live}\n seen={liveSeen}\n {...subscribeOption}\n />\n )\n : (props) => (\n <BellButton {...props} store={store} messages={messages} {...subscribeOption} />\n );\n const Panel = lazyNotificationsPanel({\n store,\n messages,\n ...(live ? { live, liveSeen } : {}),\n });\n\n function useBoundUnreadCount(options: { enabled?: boolean } = {}): number {\n return useUnreadCount(store, { ...options, ...subscribeOption });\n }\n\n function BellWithPanel({\n enabled = true,\n onNavigate,\n }: {\n enabled?: boolean;\n onNavigate?: (link: string) => void;\n }): JSX.Element {\n const [open, setOpen] = useState(false);\n return (\n <>\n <Bell enabled={enabled} onClick={() => setOpen(true)} />\n <Panel\n open={open}\n onClose={() => setOpen(false)}\n {...(onNavigate ? { onNavigate } : {})}\n />\n </>\n );\n }\n\n return {\n page: lazyPreferencesPage({ api, messages, webPush }),\n BellButton: Bell,\n Panel,\n BellWithPanel,\n useUnreadCount: useBoundUnreadCount,\n store,\n api,\n messages,\n };\n}\n","/**\n * Bare bell trigger with the live unread badge — for hosts that do not already\n * have a styled icon-button slot. A host with its own trigger chrome uses\n * `useUnreadCount` + `Panel` directly.\n */\nimport { useSyncExternalStore, type JSX } from 'react';\n\nimport { Badge } from '@12-apps/ui/data-display/Badge';\nimport { Box } from '@12-apps/ui/mui/Box';\n\nimport type { NotificationMessages } from '../messages';\n\nimport { BellIcon } from './bell-icon';\nimport { useUnreadCount, type NotificationsSignalHook, type NotificationsSubscribe } from './hooks';\nimport type { LiveActivitiesConfig } from './live-config';\nimport { hasUnseenActivity, type LiveSeenStore } from './live-seen';\nimport type { InboxStore } from './inbox-state';\n\nconst triggerSx = {\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n p: 0.5,\n border: 'none',\n background: 'none',\n cursor: 'pointer',\n color: 'text.primary',\n lineHeight: 0,\n '& *': { cursor: 'pointer' },\n '&:hover': { color: 'primary.main' },\n '&:focus-visible': {\n outline: '2px solid',\n outlineColor: 'primary.main',\n outlineOffset: '2px',\n borderRadius: '50%',\n },\n} as const;\n\nexport interface BellButtonProps {\n onClick: () => void;\n /** Signed-out hosts still mount the bell; `false` silences it. */\n enabled?: boolean;\n}\n\n/**\n * The trigger itself, given a count and whether any of it is NEW.\n *\n * Presentational, and shared by both bells below, so the two can never drift on\n * what the badge looks like — only on where the number comes from.\n *\n * ## The two tones\n *\n * `primary` says *something happened*; `neutral` says *something is present*. A\n * live activity is the reason that distinction has to exist: it stays on the\n * panel for as long as the thing is happening, so a bell that painted every\n * live entry as new would be permanently red for a pedido the reader already\n * looked at, and a bell that ignored them would say nothing at all while one\n * was running. Grey keeps the count honest without spending attention twice.\n */\nfunction BellTrigger({\n onClick,\n count,\n hasNew,\n messages,\n}: {\n onClick: () => void;\n count: number;\n hasNew: boolean;\n messages: NotificationMessages;\n}): JSX.Element {\n return (\n <Box\n component=\"button\"\n type=\"button\"\n onClick={onClick}\n // `openBellWithUnread` rather than a new message, and not for want of\n // precision: `NotificationMessages` is REQUIRED of every host, so adding\n // a field is a breaking change to a package several apps already mount.\n // The sentence a host wrote for \"you have N\" is the sentence this wants.\n aria-label={count > 0 ? messages.openBellWithUnread(count) : messages.openBell}\n data-testid=\"notifications-bell\"\n sx={triggerSx}\n >\n <Badge\n content={count > 0 ? count : undefined}\n color={hasNew ? 'primary' : 'neutral'}\n variant=\"count\"\n max={99}\n data-testid=\"notifications-badge\"\n // The tone is carried by a colour, and a colour is not something a\n // test can read — nor, on its own, a signal every reader can. This is\n // what the tests assert on.\n data-tone={hasNew ? 'new' : 'seen'}\n >\n <BellIcon size={28} />\n </Badge>\n </Box>\n );\n}\n\nexport function BellButton({\n onClick,\n enabled = true,\n store,\n messages,\n subscribe,\n useSignal,\n}: BellButtonProps & {\n store: InboxStore;\n messages: NotificationMessages;\n subscribe?: NotificationsSubscribe;\n useSignal?: NotificationsSignalHook;\n}): JSX.Element {\n const count = useUnreadCount(store, {\n enabled,\n ...(subscribe ? { subscribe } : {}),\n ...(useSignal ? { useSignal } : {}),\n });\n // No live config on this host: unread IS the whole count, and an unread row\n // is by definition something the reader has not seen.\n return <BellTrigger onClick={onClick} count={count} hasNew={count > 0} messages={messages} />;\n}\n\n/**\n * The bell for a host that configured live activities.\n *\n * A SECOND component rather than a flag on the one above, because the host's\n * `useActivities` is a hook: reading an optional config inside one component\n * would mean calling it conditionally, which React reports as a crash in some\n * unrelated component rather than here. The factory knows statically which host\n * it is building for and picks one.\n *\n * ## What it costs the host, stated plainly\n *\n * The bell is mounted for as long as the app is, so unlike the panel's copy of\n * this hook there is no \"nobody is looking\" state to stand down in — `active`\n * is simply `enabled`. A host that answers by polling therefore polls for every\n * signed-in reader whether or not they ever open the centre. That is the price\n * of a badge that knows about live activities at all, and the reason to answer\n * this hook from a pushed cache rather than from an interval.\n */\nexport function LiveBellButton({\n onClick,\n enabled = true,\n store,\n messages,\n subscribe,\n useSignal,\n live,\n seen,\n}: BellButtonProps & {\n store: InboxStore;\n messages: NotificationMessages;\n subscribe?: NotificationsSubscribe;\n useSignal?: NotificationsSignalHook;\n live: LiveActivitiesConfig;\n seen: LiveSeenStore;\n}): JSX.Element {\n const unread = useUnreadCount(store, {\n enabled,\n ...(subscribe ? { subscribe } : {}),\n ...(useSignal ? { useSignal } : {}),\n });\n const activities = live.useActivities({ active: enabled });\n const seenIso = useSyncExternalStore(seen.subscribe, seen.read, seen.read);\n const liveCount = enabled ? activities.length : 0;\n return (\n <BellTrigger\n onClick={onClick}\n // A live entry counts. It is a notification — it is the one the reader\n // most wants to know about — and the panel it opens lists it.\n count={unread + liveCount}\n hasNew={unread > 0 || (enabled && hasUnseenActivity(activities, seenIso))}\n messages={messages}\n />\n );\n}\n","/**\n * What the reader has already been shown, so the bell can say NEW rather than\n * merely PRESENT.\n *\n * A live activity is unlike an inbox row in the one way that matters here: it\n * stays on the panel for as long as the thing is happening, so its presence\n * cannot mean \"you have not seen this\". A pedido that has been `Preparo` for\n * ten minutes is still live and still worth counting, but nothing has happened\n * — and a badge that shouts for a subject the reader has already looked at is a\n * badge people stop reading.\n *\n * So presence and novelty are answered separately: the COUNT comes from how\n * many are live, and the TONE comes from this. The panel writes it — being on\n * screen is what seen means — and the bell reads it.\n *\n * ## Per subject, not one watermark\n *\n * A single \"newest instant already seen\" is smaller and was the first cut, and\n * it is wrong in a way that shows up in normal use: a pedido placed ten minutes\n * ago but only now reaching the client arrives with an `updatedAt` BEHIND the\n * watermark, and would be silently marked as already seen. The reader has never\n * laid eyes on it. Keyed by subject, an id that has not been recorded is new\n * whatever its clock says.\n *\n * Bounded by pruning rather than by expiry: every write keeps only the subjects\n * that are live at that moment, so the record can never outgrow the number of\n * things happening at once. A subject that finishes and later comes back is\n * news again, which is correct — it is a different occurrence.\n */\nimport type { LiveActivity } from '../live';\n\nconst STORAGE_KEY = '12a.notifications.live-seen';\n\n/** id -> the `updatedAt` that was on screen. */\ntype SeenMap = Readonly<Record<string, string>>;\n\nconst EMPTY: SeenMap = {};\n\n/** ms since epoch, or `null` for an absent or unparseable stamp. */\nfunction instant(iso: string | undefined): number | null {\n if (iso === undefined) return null;\n const ms = Date.parse(iso);\n return Number.isNaN(ms) ? null : ms;\n}\n\n/**\n * Read/write through `try`, every time.\n *\n * `localStorage` is not merely absent in SSR and in a worker — the ACCESSOR\n * itself throws in a browser set to block site data. A notification bell that\n * cannot render because storage is blocked is a worse failure than one that\n * forgets what was seen, and forgetting degrades in the safe direction: towards\n * saying something is happening.\n */\nfunction readStored(): SeenMap {\n try {\n const raw = globalThis.localStorage?.getItem(STORAGE_KEY);\n if (!raw) return EMPTY;\n const parsed: unknown = JSON.parse(raw);\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return EMPTY;\n // Anything can be in storage — another version of this package, or a person\n // with the devtools open. Keep only what has the shape this reads.\n const clean: Record<string, string> = {};\n for (const [id, value] of Object.entries(parsed)) {\n if (typeof value === 'string') clean[id] = value;\n }\n return clean;\n } catch {\n return EMPTY;\n }\n}\n\nfunction writeStored(value: SeenMap): void {\n try {\n globalThis.localStorage?.setItem(STORAGE_KEY, JSON.stringify(value));\n } catch {\n // Blocked or full. The badge stays new a while longer; nothing else breaks.\n }\n}\n\nexport interface LiveSeenStore {\n /** What has been shown, keyed by subject id. */\n read: () => SeenMap;\n /** Record that exactly these are on screen now, forgetting subjects that are not. */\n mark: (activities: readonly LiveActivity[]) => void;\n subscribe: (listener: () => void) => () => void;\n}\n\nexport function createLiveSeenStore(): LiveSeenStore {\n // Mirrored in memory as well as in storage: `useSyncExternalStore` compares\n // snapshots by IDENTITY and calls `read` on every render, so parsing storage\n // there would hand it a fresh object each time and re-render for ever.\n let current = readStored();\n const listeners = new Set<() => void>();\n\n return {\n read: () => current,\n mark: (activities) => {\n const next: Record<string, string> = {};\n for (const activity of activities) next[activity.id] = activity.updatedAt;\n // Identity is the snapshot, so an unchanged map must not become a new\n // object — see `read` above.\n const ids = Object.keys(next);\n const same =\n ids.length === Object.keys(current).length &&\n ids.every((id) => current[id] === next[id]);\n if (same) return;\n current = next;\n writeStored(next);\n for (const listener of listeners) listener();\n },\n subscribe: (listener) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n\n/**\n * Whether any of these has moved, or arrived, since the reader last looked.\n *\n * An id with nothing recorded is new — that is the case the per-subject record\n * exists for. An unparseable stamp is treated as new too: the alternative is\n * silently never alerting for a host whose clock format this does not read.\n */\nexport function hasUnseenActivity(\n activities: readonly LiveActivity[],\n seen: SeenMap,\n): boolean {\n return activities.some((activity) => {\n const shown = instant(seen[activity.id]);\n if (shown === null) return true;\n const now = instant(activity.updatedAt);\n return now === null || now > shown;\n });\n}\n","/**\n * The inbox slide-over, fetched the first time somebody opens it.\n *\n * The bell and the panel are a PAIR a host drops into its chrome, and that is\n * still true — but only the BELL is on screen when a page paints. The panel is\n * behind a tap, and a static import made every host pay for it up front: the\n * design-system `Drawer` and, through it, MUI's `SwipeableDrawer`, `Modal`,\n * `Slide` and the focus trap, plus the row, the empty state and the pager. On a\n * storefront that is a slide-over most visits never open, parsed before the\n * first screen can render.\n *\n * ## Why the gate is \"ever opened\" rather than `open`\n *\n * `lazy` fetches when a component first RENDERS, so a boundary that still\n * rendered the panel while closed would fetch immediately and buy nothing. This\n * renders `null` until the panel has been open once, which is what actually\n * defers the download to the tap.\n *\n * And once opened it STAYS mounted. Unmounting on close would throw away the\n * drawer's transition state, so the panel would vanish instead of sliding out,\n * and the entrance animation would re-run on every reopen — which someone\n * working through an inbox does repeatedly. The fetch happens once.\n *\n * The initial state reads `open` rather than starting at `false`, so a host that\n * mounts the panel already open renders it in the same commit instead of a frame\n * later.\n *\n * ## Why `null` for the fallback\n *\n * The only frame this can show anything is the one right after the tap, where a\n * spinner reads as a stall rather than as progress. The chunk is small and\n * same-origin.\n */\nimport { Suspense, lazy, useEffect, useState, type ComponentType, type JSX } from 'react';\n\nimport type { NotificationMessages } from '../messages';\n\nimport type { InboxStore } from './inbox-state';\nimport type { LiveActivitiesConfig } from './live-config';\nimport type { LiveSeenStore } from './live-seen';\nimport type { NotificationsPanelProps } from './panel';\n\n/** What the factory binds into the panel, and the host never passes. */\ninterface PanelParts {\n store: InboxStore;\n messages: NotificationMessages;\n /** Absent unless the host turned live activities on — see `./live-config`. */\n live?: LiveActivitiesConfig;\n /** Travels with `live`: where the panel records what the reader has seen. */\n liveSeen?: LiveSeenStore;\n}\n\nexport function lazyNotificationsPanel(\n parts: PanelParts,\n): ComponentType<NotificationsPanelProps> {\n const Bound = lazy(async () => {\n const { NotificationsPanel } = await import('./panel');\n return {\n default: (props: NotificationsPanelProps): JSX.Element => (\n <NotificationsPanel {...props} {...parts} />\n ),\n };\n });\n\n return function NotificationsPanelSlot(props: NotificationsPanelProps): JSX.Element | null {\n const [everOpened, setEverOpened] = useState(props.open);\n\n useEffect(() => {\n if (props.open) setEverOpened(true);\n }, [props.open]);\n\n if (!everOpened) return null;\n\n return (\n <Suspense fallback={null}>\n <Bound {...props} />\n </Suspense>\n );\n };\n}\n","/**\n * The routed preferences screen, fetched when a host actually routes to it.\n *\n * `createWebNotifications` returns two different KINDS of thing, and its own\n * docstring says so: `page` is \"the standalone surface … the one thing a host\n * routes to\", while the bell and the panel \"are a PAIR a host drops into its own\n * chrome\". Chrome is on screen from the first paint; a routed surface is not.\n *\n * A static import made that distinction invisible to a bundler. Every host that\n * put the bell in its header also shipped the preferences matrix — its channel\n * toggles, the per-browser push enable step, and the design-system `Switch`\n * behind them — in the same chunk as the header. A storefront paid for a\n * settings screen a shopper never opens, before its first screen could render;\n * a host that renders its OWN preferences page paid for this one twice.\n *\n * So `page` now loads on demand. Nothing else moves: the bell, the panel and\n * `BellWithPanel` stay exactly as eager as the chrome they belong to, because\n * that is what they are.\n *\n * NO PREFETCH, deliberately, and this is the opposite call from a surface a\n * host opens from chrome it already has. A routed surface is reached by\n * NAVIGATION, and every host here already code-splits its routes — so the\n * fetch happens while the route is being entered, which is the moment a\n * prefetch would have been trying to anticipate. Warming it at factory time\n * would put the screen back on the boot path of every app, which is the whole\n * cost this removes.\n */\nimport { Suspense, lazy, type ComponentType, type JSX } from 'react';\n\nimport type { NotificationMessages } from '../messages';\n\nimport type { NotificationsApiClient } from './api';\nimport type { PreferencesScreenProps } from './preferences-screen';\nimport type { WebPushSetupConfig } from './web-push-setup';\n\n/** What the factory binds into the screen, and the host never passes. */\ninterface PreferencesPageParts {\n api: NotificationsApiClient;\n messages: NotificationMessages;\n webPush: WebPushSetupConfig;\n}\n\n/**\n * The routed screen, bound and loaded on first render.\n *\n * `lazy` memoises its factory, so the binding below happens once however many\n * times a host mounts the page — the same guarantee the direct call gave.\n *\n * The fallback is `null` because a host routes to this: whatever it renders\n * around the route is already on screen, and a second spinner inside it would\n * be one more thing appearing and disappearing during a navigation the host is\n * already indicating.\n */\nexport function lazyPreferencesPage(\n parts: PreferencesPageParts,\n): ComponentType<PreferencesScreenProps> {\n const Bound = lazy(async () => {\n const { PreferencesScreen } = await import('./preferences-screen');\n return {\n default: (props: PreferencesScreenProps): JSX.Element => (\n <PreferencesScreen {...props} {...parts} />\n ),\n };\n });\n\n return function NotificationsPreferencesPage(props: PreferencesScreenProps): JSX.Element {\n return (\n <Suspense fallback={null}>\n <Bound {...props} />\n </Suspense>\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAiEO,SAAS,6BACd,SACA,WACwB;AACxB,QAAM,OAAO,QAAQ,QAAQ,OAAO,EAAE;AACtC,QAAM,MAAM,wBAAC,SAAyB,GAAG,IAAI,GAAG,IAAI,IAAxC;AAEZ,SAAO;AAAA,IACL,kBAAkB,EAAE,QAAQ,OAAO,OAAO,GAAG;AAC3C,YAAM,SAAS,IAAI,gBAAgB;AACnC,UAAI,UAAU,OAAW,QAAO,IAAI,SAAS,OAAO,KAAK,CAAC;AAC1D,UAAI,OAAQ,QAAO,IAAI,UAAU,MAAM;AACvC,UAAI,OAAQ,QAAO,IAAI,UAAU,MAAM;AACvC,YAAM,QAAQ,OAAO,SAAS;AAC9B,aAAO,UAAU;AAAA,QACf,IAAI,iBAAiB,QAAQ,IAAI,KAAK,KAAK,EAAE,EAAE;AAAA,MACjD;AAAA,IACF;AAAA,IACA,MAAM,cAAc;AAClB,YAAM,EAAE,MAAM,IAAI,MAAM,UAAU;AAAA,QAChC,IAAI,6BAA6B;AAAA,MACnC;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,wBAAC,QACT,UAAU,KAAK,IAAI,0BAA0B,GAAG,QAAQ,EA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