@ttt-productions/upload-ui 0.7.16 → 0.7.18
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/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/react/guard/guarded-link.d.ts +11 -0
- package/dist/react/guard/guarded-link.d.ts.map +1 -0
- package/dist/react/guard/guarded-link.js.map +1 -0
- package/dist/react/guard/index.d.ts +3 -3
- package/dist/react/guard/index.d.ts.map +1 -1
- package/dist/react/guard/index.js +3 -3
- package/dist/react/guard/index.js.map +1 -1
- package/dist/react/guard/local-upload-guard-provider.d.ts +31 -0
- package/dist/react/guard/local-upload-guard-provider.d.ts.map +1 -0
- package/dist/react/{local-upload-guard-provider.js → guard/local-upload-guard-provider.js} +3 -60
- package/dist/react/guard/local-upload-guard-provider.js.map +1 -0
- package/dist/react/guard/use-guarded-navigation.d.ts +3 -0
- package/dist/react/guard/use-guarded-navigation.d.ts.map +1 -0
- package/dist/react/guard/use-guarded-navigation.js +12 -0
- package/dist/react/guard/use-guarded-navigation.js.map +1 -0
- package/dist/react/tray/in-flight-uploads-provider.d.ts +141 -0
- package/dist/react/tray/in-flight-uploads-provider.d.ts.map +1 -0
- package/dist/react/{in-flight-uploads-provider.js → tray/in-flight-uploads-provider.js} +16 -136
- package/dist/react/tray/in-flight-uploads-provider.js.map +1 -0
- package/dist/react/tray/index.d.ts +4 -4
- package/dist/react/tray/index.d.ts.map +1 -1
- package/dist/react/tray/index.js +4 -4
- package/dist/react/tray/index.js.map +1 -1
- package/dist/react/tray/use-clear-upload-activity.d.ts +8 -0
- package/dist/react/tray/use-clear-upload-activity.d.ts.map +1 -0
- package/dist/react/tray/use-clear-upload-activity.js +13 -0
- package/dist/react/tray/use-clear-upload-activity.js.map +1 -0
- package/dist/react/{use-mark-upload-activity-seen.d.ts → tray/use-mark-upload-activity-seen.d.ts} +0 -4
- package/dist/react/tray/use-mark-upload-activity-seen.d.ts.map +1 -0
- package/dist/react/{use-mark-upload-activity-seen.js → tray/use-mark-upload-activity-seen.js} +0 -21
- package/dist/react/tray/use-mark-upload-activity-seen.js.map +1 -0
- package/dist/react/{use-upload-processing.d.ts → tray/use-upload-processing.d.ts} +0 -10
- package/dist/react/tray/use-upload-processing.d.ts.map +1 -0
- package/dist/react/{use-upload-processing.js → tray/use-upload-processing.js} +10 -20
- package/dist/react/tray/use-upload-processing.js.map +1 -0
- package/dist/react/upload/deferred-upload-form-shell.d.ts +28 -0
- package/dist/react/upload/deferred-upload-form-shell.d.ts.map +1 -0
- package/dist/react/{deferred-upload-form-shell.js → upload/deferred-upload-form-shell.js} +5 -2
- package/dist/react/upload/deferred-upload-form-shell.js.map +1 -0
- package/dist/react/upload/index.d.ts +2 -2
- package/dist/react/upload/index.d.ts.map +1 -1
- package/dist/react/upload/index.js +2 -2
- package/dist/react/upload/index.js.map +1 -1
- package/dist/react/upload/use-guarded-upload.d.ts +16 -0
- package/dist/react/upload/use-guarded-upload.d.ts.map +1 -0
- package/dist/react/{use-guarded-upload.js → upload/use-guarded-upload.js} +2 -15
- package/dist/react/upload/use-guarded-upload.js.map +1 -0
- package/dist/upload-display.d.ts +0 -14
- package/dist/upload-display.d.ts.map +1 -1
- package/dist/upload-display.js +11 -12
- package/dist/upload-display.js.map +1 -1
- package/package.json +5 -5
- package/dist/react/deferred-upload-form-shell.d.ts +0 -46
- package/dist/react/deferred-upload-form-shell.d.ts.map +0 -1
- package/dist/react/deferred-upload-form-shell.js.map +0 -1
- package/dist/react/guarded-link.d.ts +0 -38
- package/dist/react/guarded-link.d.ts.map +0 -1
- package/dist/react/guarded-link.js.map +0 -1
- package/dist/react/in-flight-uploads-provider.d.ts +0 -266
- package/dist/react/in-flight-uploads-provider.d.ts.map +0 -1
- package/dist/react/in-flight-uploads-provider.js.map +0 -1
- package/dist/react/local-upload-guard-provider.d.ts +0 -112
- package/dist/react/local-upload-guard-provider.d.ts.map +0 -1
- package/dist/react/local-upload-guard-provider.js.map +0 -1
- package/dist/react/use-clear-upload-activity.d.ts +0 -33
- package/dist/react/use-clear-upload-activity.d.ts.map +0 -1
- package/dist/react/use-clear-upload-activity.js +0 -31
- package/dist/react/use-clear-upload-activity.js.map +0 -1
- package/dist/react/use-guarded-navigation.d.ts +0 -10
- package/dist/react/use-guarded-navigation.d.ts.map +0 -1
- package/dist/react/use-guarded-navigation.js +0 -40
- package/dist/react/use-guarded-navigation.js.map +0 -1
- package/dist/react/use-guarded-upload.d.ts +0 -45
- package/dist/react/use-guarded-upload.d.ts.map +0 -1
- package/dist/react/use-guarded-upload.js.map +0 -1
- package/dist/react/use-mark-upload-activity-seen.d.ts.map +0 -1
- package/dist/react/use-mark-upload-activity-seen.js.map +0 -1
- package/dist/react/use-upload-processing.d.ts.map +0 -1
- package/dist/react/use-upload-processing.js.map +0 -1
- /package/dist/react/{guarded-link.js → guard/guarded-link.js} +0 -0
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic in-flight uploads provider.
|
|
3
|
-
*
|
|
4
|
-
* Provides a global Map of in-flight upload state by `pendingMediaId`, derived
|
|
5
|
-
* from a Firestore listener over the consumer-supplied collection. On terminal
|
|
6
|
-
* status transitions observed THIS SESSION, fires consumer-supplied success /
|
|
7
|
-
* failure / rejection callbacks. Records monitoring breadcrumbs and parse
|
|
8
|
-
* errors through the injected monitoring callback.
|
|
9
|
-
*
|
|
10
|
-
* EVERY app-specific value is supplied by the consumer:
|
|
11
|
-
* - userId resolution
|
|
12
|
-
* - Firestore `db` reference
|
|
13
|
-
* - collection path
|
|
14
|
-
* - listener time window (ms)
|
|
15
|
-
* - parser/schema for raw Firestore doc → typed PendingMedia
|
|
16
|
-
* - success copy per origin
|
|
17
|
-
* - notification callback (cache invalidation, etc.)
|
|
18
|
-
* - toast callback
|
|
19
|
-
* - rejection callback (for the media-rejection dialog or equivalent)
|
|
20
|
-
* - monitoring callback (breadcrumbs + captured errors)
|
|
21
|
-
*
|
|
22
|
-
* Read APIs:
|
|
23
|
-
* - `useInFlightUploadsState()` — full Map.
|
|
24
|
-
* - `useInFlightUpload(id)` — single doc, narrowable on status.
|
|
25
|
-
* - `useUploadActivityState()` — tray-visible items, sorted newest-first.
|
|
26
|
-
*
|
|
27
|
-
* The package owns the deduplication, initial-snapshot suppression, and
|
|
28
|
-
* non-terminal → terminal transition tracking. It does NOT own anything about
|
|
29
|
-
* what a file-origin is or what message text appears in toasts.
|
|
30
|
-
*/
|
|
31
|
-
import { type ReactNode } from 'react';
|
|
32
|
-
import { PendingMediaStatusSchema, type PendingMediaNonTerminalStatus, type PendingMediaStatus } from '@ttt-productions/media-schemas';
|
|
33
|
-
/** Generic pending-media status — media-schemas' one declaration. */
|
|
34
|
-
export type InFlightUploadStatus = PendingMediaStatus;
|
|
35
|
-
/**
|
|
36
|
-
* Generic in-flight upload record. The provider keeps a Map<id, InFlightUpload>
|
|
37
|
-
* built from each parsed PendingMedia. Consumers parameterize the `fileOrigin`
|
|
38
|
-
* type via the parser's return type (the provider treats it as opaque).
|
|
39
|
-
*
|
|
40
|
-
* `TFileOrigin` defaults to `string` so unannotated consumers get a permissive
|
|
41
|
-
* shape; consuming apps bind it to their own `FileOrigin` union at the call site.
|
|
42
|
-
*/
|
|
43
|
-
export type InFlightUploadBase<TFileOrigin extends string = string> = {
|
|
44
|
-
id: string;
|
|
45
|
-
fileOrigin: TFileOrigin;
|
|
46
|
-
surface: string;
|
|
47
|
-
createdAt: number;
|
|
48
|
-
targetIds?: string[];
|
|
49
|
-
originalContentType?: string;
|
|
50
|
-
originalSize?: number;
|
|
51
|
-
};
|
|
52
|
-
export type InFlightUploadActive<TFileOrigin extends string = string> = InFlightUploadBase<TFileOrigin> & {
|
|
53
|
-
status: PendingMediaNonTerminalStatus;
|
|
54
|
-
};
|
|
55
|
-
export type InFlightUploadCompleted<TFileOrigin extends string = string> = InFlightUploadBase<TFileOrigin> & {
|
|
56
|
-
status: typeof PendingMediaStatusSchema.enum.completed;
|
|
57
|
-
completedAt: number;
|
|
58
|
-
uploadTrayClearedAt?: number;
|
|
59
|
-
uploadTrayClearedBy?: string;
|
|
60
|
-
uploadTraySeenAt?: number;
|
|
61
|
-
uploadTraySeenBy?: string;
|
|
62
|
-
};
|
|
63
|
-
export type InFlightUploadFailed<TFileOrigin extends string = string> = InFlightUploadBase<TFileOrigin> & {
|
|
64
|
-
status: typeof PendingMediaStatusSchema.enum.failed;
|
|
65
|
-
failedAt: number;
|
|
66
|
-
errorCategory: string;
|
|
67
|
-
errorMessage: string;
|
|
68
|
-
uploadTrayClearedAt?: number;
|
|
69
|
-
uploadTrayClearedBy?: string;
|
|
70
|
-
uploadTraySeenAt?: number;
|
|
71
|
-
uploadTraySeenBy?: string;
|
|
72
|
-
};
|
|
73
|
-
export type InFlightUploadRejected<TFileOrigin extends string = string> = InFlightUploadBase<TFileOrigin> & {
|
|
74
|
-
status: typeof PendingMediaStatusSchema.enum.rejected;
|
|
75
|
-
rejectedAt: number;
|
|
76
|
-
rejectionType: 'text' | 'media';
|
|
77
|
-
errorMessage: string;
|
|
78
|
-
violationId?: string;
|
|
79
|
-
uploadTrayClearedAt?: number;
|
|
80
|
-
uploadTrayClearedBy?: string;
|
|
81
|
-
uploadTraySeenAt?: number;
|
|
82
|
-
uploadTraySeenBy?: string;
|
|
83
|
-
};
|
|
84
|
-
export type InFlightUpload<TFileOrigin extends string = string> = InFlightUploadActive<TFileOrigin> | InFlightUploadCompleted<TFileOrigin> | InFlightUploadFailed<TFileOrigin> | InFlightUploadRejected<TFileOrigin>;
|
|
85
|
-
/**
|
|
86
|
-
* Result of the consumer-supplied parser. The provider keeps the raw parsed
|
|
87
|
-
* record for callbacks (so consumers can read domain events, target IDs, etc.)
|
|
88
|
-
* AND derives the generic InFlightUpload from it for the public Map.
|
|
89
|
-
*
|
|
90
|
-
* The parser MUST throw if validation fails; the provider catches and routes
|
|
91
|
-
* the error to the monitoring callback.
|
|
92
|
-
*/
|
|
93
|
-
export type ParsedPendingMedia<TFileOrigin extends string = string> = {
|
|
94
|
-
id: string;
|
|
95
|
-
userId: string;
|
|
96
|
-
fileOrigin: TFileOrigin;
|
|
97
|
-
status: InFlightUploadStatus;
|
|
98
|
-
createdAt: number;
|
|
99
|
-
surface: string;
|
|
100
|
-
targetIds?: string[];
|
|
101
|
-
originalContentType?: string;
|
|
102
|
-
originalSize?: number;
|
|
103
|
-
completedAt?: number;
|
|
104
|
-
failedAt?: number;
|
|
105
|
-
rejectedAt?: number;
|
|
106
|
-
errorCategory?: string;
|
|
107
|
-
errorMessage?: string;
|
|
108
|
-
rejectionType?: 'text' | 'media';
|
|
109
|
-
violationId?: string;
|
|
110
|
-
uploadTrayClearedAt?: number;
|
|
111
|
-
uploadTrayClearedBy?: string;
|
|
112
|
-
uploadTraySeenAt?: number;
|
|
113
|
-
uploadTraySeenBy?: string;
|
|
114
|
-
/**
|
|
115
|
-
* Opaque consumer-controlled domain-event payload, surfaced to the
|
|
116
|
-
* `onUploadCompleted` and `onUploadRejected` callbacks for cache
|
|
117
|
-
* invalidation. The provider does not interpret it.
|
|
118
|
-
*/
|
|
119
|
-
domainEvents?: unknown;
|
|
120
|
-
};
|
|
121
|
-
export type InFlightUploadsAdapter<TFileOrigin extends string = string> = {
|
|
122
|
-
/** Returns the current user's uid, or null if not signed in. */
|
|
123
|
-
getCurrentUserId: () => string | null;
|
|
124
|
-
/** Firestore database adapter (loose typing — `unknown` keeps zero firebase coupling at the type level). */
|
|
125
|
-
db: unknown;
|
|
126
|
-
/** Collection path holding pending-media docs (e.g. "pendingMedia"). */
|
|
127
|
-
collectionPath: string;
|
|
128
|
-
/** Listener window in milliseconds — only docs with `createdAt >= now - window` are tracked. */
|
|
129
|
-
listenerWindowMs: number;
|
|
130
|
-
/**
|
|
131
|
-
* Parse a raw Firestore doc snapshot's `.data()` into the generic shape the
|
|
132
|
-
* provider tracks. Throws on validation failure; the provider routes thrown
|
|
133
|
-
* errors to `onMonitoringEvent`.
|
|
134
|
-
*/
|
|
135
|
-
parsePendingMedia: (raw: unknown) => ParsedPendingMedia<TFileOrigin>;
|
|
136
|
-
/** Called once per observed non-terminal → terminal completed transition. */
|
|
137
|
-
onUploadCompleted: (parsed: ParsedPendingMedia<TFileOrigin>) => void;
|
|
138
|
-
/** Called once per observed non-terminal → terminal failed transition. */
|
|
139
|
-
onUploadFailed: (parsed: ParsedPendingMedia<TFileOrigin>) => void;
|
|
140
|
-
/** Called once per observed non-terminal → terminal rejected transition. */
|
|
141
|
-
onUploadRejected: (parsed: ParsedPendingMedia<TFileOrigin>) => void;
|
|
142
|
-
/**
|
|
143
|
-
* Monitoring callback. Receives:
|
|
144
|
-
* - `breadcrumb`: informational, fired on every observed terminal transition.
|
|
145
|
-
* - `parse-error`: when `parsePendingMedia` throws.
|
|
146
|
-
* - `listener-error`: when the Firestore listener's error callback fires.
|
|
147
|
-
*
|
|
148
|
-
* Consumers wire this to Sentry, OpenTelemetry, or any other observability
|
|
149
|
-
* provider. The provider does NOT import any monitoring SDK directly.
|
|
150
|
-
*/
|
|
151
|
-
onMonitoringEvent: (event: InFlightUploadsMonitoringEvent<TFileOrigin>) => void;
|
|
152
|
-
};
|
|
153
|
-
export type InFlightUploadsMonitoringEvent<TFileOrigin extends string = string> = {
|
|
154
|
-
type: 'breadcrumb';
|
|
155
|
-
category: 'upload.terminal';
|
|
156
|
-
level: 'info';
|
|
157
|
-
message: string;
|
|
158
|
-
data: {
|
|
159
|
-
id: string;
|
|
160
|
-
fileOrigin: TFileOrigin;
|
|
161
|
-
status: InFlightUploadStatus;
|
|
162
|
-
surface: string;
|
|
163
|
-
};
|
|
164
|
-
} | {
|
|
165
|
-
type: 'parse-error';
|
|
166
|
-
docId: string;
|
|
167
|
-
error: unknown;
|
|
168
|
-
data: unknown;
|
|
169
|
-
} | {
|
|
170
|
-
type: 'listener-error';
|
|
171
|
-
error: unknown;
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Minimal subscription contract used by the provider. The default
|
|
175
|
-
* implementation lives in `firestore-subscribe.ts` and uses the standard
|
|
176
|
-
* `firebase/firestore` `onSnapshot` + `query` + `where` builders.
|
|
177
|
-
*
|
|
178
|
-
* Tests inject a fake to drive the listener without spinning up Firestore.
|
|
179
|
-
*/
|
|
180
|
-
export type FirestoreSubscribeFn = (args: {
|
|
181
|
-
db: unknown;
|
|
182
|
-
collectionPath: string;
|
|
183
|
-
userId: string;
|
|
184
|
-
windowStartMs: number;
|
|
185
|
-
onSnapshot: (snapshot: FirestoreLikeSnapshot) => void;
|
|
186
|
-
onError: (error: unknown) => void;
|
|
187
|
-
}) => () => void;
|
|
188
|
-
export type FirestoreLikeSnapshot = {
|
|
189
|
-
docChanges: () => FirestoreLikeDocChange[];
|
|
190
|
-
/**
|
|
191
|
-
* Snapshot metadata. Present when the subscription is opened with
|
|
192
|
-
* `{ includeMetadataChanges: true }` (the default firebase implementation does).
|
|
193
|
-
* `fromCache === false` means a server-confirmed snapshot. Optional so injected
|
|
194
|
-
* test fakes need not supply it (absent ⇒ treated as server-confirmed).
|
|
195
|
-
*/
|
|
196
|
-
metadata?: {
|
|
197
|
-
fromCache: boolean;
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
/**
|
|
201
|
-
* Metadata-derived liveness of the uploads listener, mirroring query-core's
|
|
202
|
-
* `FirestoreSourceState`. Firestore serves cached snapshots offline WITHOUT
|
|
203
|
-
* firing the error callback, so the Files tray source needs this to show a
|
|
204
|
-
* degraded indicator instead of a false "all caught up":
|
|
205
|
-
* - `connecting` — no server-confirmed snapshot yet.
|
|
206
|
-
* - `live` — at least one server-confirmed snapshot (`fromCache === false`).
|
|
207
|
-
* - `offline` — only cached data after having been live.
|
|
208
|
-
* - `error` — the listener error callback fired.
|
|
209
|
-
*/
|
|
210
|
-
export type UploadsSourceState = 'connecting' | 'live' | 'offline' | 'error';
|
|
211
|
-
export type FirestoreLikeDocChange = {
|
|
212
|
-
type: 'added' | 'modified' | 'removed';
|
|
213
|
-
doc: {
|
|
214
|
-
id: string;
|
|
215
|
-
data: () => unknown;
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
/** Restarting the uploads listener after it failed, and whether that restart is running. */
|
|
219
|
-
export interface UploadsSourceRetry {
|
|
220
|
-
/**
|
|
221
|
-
* Tear the listener down and subscribe again on a fresh retry ladder. While the restart runs the
|
|
222
|
-
* source state stays as it was (an `error` stays `error`), so a failure shown on it stays on
|
|
223
|
-
* screen with its control pending.
|
|
224
|
-
*/
|
|
225
|
-
retry: () => void;
|
|
226
|
-
/** A `retry` is running: true until the restarted listener answers or its ladder fails again. */
|
|
227
|
-
retrying: boolean;
|
|
228
|
-
}
|
|
229
|
-
export interface InFlightUploadsProviderProps<TFileOrigin extends string = string> {
|
|
230
|
-
adapter: InFlightUploadsAdapter<TFileOrigin>;
|
|
231
|
-
/** Firestore subscription function. Defaults to the firebase/firestore implementation. */
|
|
232
|
-
subscribe?: FirestoreSubscribeFn;
|
|
233
|
-
children: ReactNode;
|
|
234
|
-
}
|
|
235
|
-
export declare function InFlightUploadsProvider<TFileOrigin extends string = string>(props: InFlightUploadsProviderProps<TFileOrigin>): import("react").JSX.Element;
|
|
236
|
-
export declare function useInFlightUploadsState<TFileOrigin extends string = string>(): Map<string, InFlightUpload<TFileOrigin>>;
|
|
237
|
-
export declare function useInFlightUpload<TFileOrigin extends string = string>(id: string | null | undefined): InFlightUpload<TFileOrigin> | undefined;
|
|
238
|
-
/**
|
|
239
|
-
* Metadata-derived source state of the uploads listener
|
|
240
|
-
* (`connecting | live | offline | error`). The Files tray uses this to show a
|
|
241
|
-
* degraded indicator and never display "all caught up" while the source is
|
|
242
|
-
* `offline`/`error`/`connecting`.
|
|
243
|
-
*/
|
|
244
|
-
export declare function useUploadsSourceState(): UploadsSourceState;
|
|
245
|
-
/**
|
|
246
|
-
* The uploads listener's restart — the Try again of a failure shown on `useUploadsSourceState` —
|
|
247
|
-
* and whether it is running.
|
|
248
|
-
*/
|
|
249
|
-
export declare function useUploadsSourceRetry(): UploadsSourceRetry;
|
|
250
|
-
/**
|
|
251
|
-
* `true` for `completed` / `failed` / `rejected`. Used by tray UI to decide
|
|
252
|
-
* whether a Clear action is available for an item.
|
|
253
|
-
*/
|
|
254
|
-
export declare function isTerminalUpload<TFileOrigin extends string = string>(item: InFlightUpload<TFileOrigin>): item is Exclude<InFlightUpload<TFileOrigin>, {
|
|
255
|
-
status: PendingMediaNonTerminalStatus;
|
|
256
|
-
}>;
|
|
257
|
-
/**
|
|
258
|
-
* Tray-visible items. Includes every pending/processing upload, plus terminal
|
|
259
|
-
* uploads that have NOT been cleared from the tray. Sorted newest-first by
|
|
260
|
-
* createdAt.
|
|
261
|
-
*
|
|
262
|
-
* The public selector name in upload-ui is `useUploadActivityState`. The
|
|
263
|
-
* mutation hook is `useClearUploadActivity` (in a separate file).
|
|
264
|
-
*/
|
|
265
|
-
export declare function useUploadActivityState<TFileOrigin extends string = string>(): InFlightUpload<TFileOrigin>[];
|
|
266
|
-
//# sourceMappingURL=in-flight-uploads-provider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-flight-uploads-provider.d.ts","sourceRoot":"","sources":["../../src/react/in-flight-uploads-provider.tsx"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAGL,wBAAwB,EACxB,KAAK,6BAA6B,EAClC,KAAK,kBAAkB,EACxB,MAAM,gCAAgC,CAAC;AASxC,qEAAqE;AACrE,MAAM,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,CAAC,WAAW,SAAS,MAAM,GAAG,MAAM,IAAI;IACpE,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,WAAW,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IACh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;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAiC;IAEjC,OAAO,4BAA4B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,OAAO,GAAG,uBAAuB,EAAe,CAAC;IACvD,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;aAChC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACf,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;YACzC,OAAO,IAAI,CAAC,mBAAmB,KAAK,SAAS,CAAC;QAChD,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB,CAAC;AAED,gFAAgF;AAChF,gDAAgD;AAChD,gFAAgF;AAEhF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,yBAAyB,GAAyB,CAAC,IAAI,EAAE,EAAE;IAC/D,MAAM,CAAC,GAAG,KAAK,CAEb,UAAU,CAAC,IAAI,CAAC,EAAS,EAAE,IAAI,CAAC,cAAc,CAAC,EAC/C,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAClC,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAC7C,CAAC;IACF,sFAAsF;IACtF,uFAAuF;IACvF,OAAO,UAAU,CAAC,CAAC,EAAE,EAAE,sBAAsB,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,UAAmB,EAAE,IAAI,CAAC,OAAgB,CAAC,CAAC;AAC1G,CAAC,CAAC","sourcesContent":["'use client';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// SANCTIONED EXCEPTION to the \"packages read/write Firestore only through\n// @ttt-productions/query-core\" rule (see docs/packages/package-architecture.md →\n// \"Firestore access goes through query-core\").\n//\n// WHY this provider reads Firestore directly instead of via a query-core hook:\n// 1. It needs snapshot *transition events* — onSnapshot's `docChanges()` with\n// added / modified / removed — to fire one-shot terminal callbacks and to\n// suppress the initial snapshot. query-core's hooks return \"the current\n// list\", not per-doc transitions, so they cannot express this state machine.\n// 2. The subscription is already abstracted behind an injectable\n// `FirestoreSubscribeFn` (the `subscribe` prop); the direct firebase code\n// path lives ONLY in `defaultFirestoreSubscribe` below and is fully\n// swappable (tests / alternate backends inject their own).\n// 3. The static ESM `firebase/firestore` import is load-bearing for Next.js +\n// Turbopack module identity (see defaultFirestoreSubscribe's comment).\n//\n// Do NOT \"migrate\" this onto query-core without preserving docChanges() semantics.\n// ─────────────────────────────────────────────────────────────────────────────\nimport { collection, onSnapshot, query, where } from 'firebase/firestore';\n\n/**\n * Generic in-flight uploads provider.\n *\n * Provides a global Map of in-flight upload state by `pendingMediaId`, derived\n * from a Firestore listener over the consumer-supplied collection. On terminal\n * status transitions observed THIS SESSION, fires consumer-supplied success /\n * failure / rejection callbacks. Records monitoring breadcrumbs and parse\n * errors through the injected monitoring callback.\n *\n * EVERY app-specific value is supplied by the consumer:\n * - userId resolution\n * - Firestore `db` reference\n * - collection path\n * - listener time window (ms)\n * - parser/schema for raw Firestore doc → typed PendingMedia\n * - success copy per origin\n * - notification callback (cache invalidation, etc.)\n * - toast callback\n * - rejection callback (for the media-rejection dialog or equivalent)\n * - monitoring callback (breadcrumbs + captured errors)\n *\n * Read APIs:\n * - `useInFlightUploadsState()` — full Map.\n * - `useInFlightUpload(id)` — single doc, narrowable on status.\n * - `useUploadActivityState()` — tray-visible items, sorted newest-first.\n *\n * The package owns the deduplication, initial-snapshot suppression, and\n * non-terminal → terminal transition tracking. It does NOT own anything about\n * what a file-origin is or what message text appears in toasts.\n */\n\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\nimport {\n isPendingMediaNonTerminalStatus,\n isPendingMediaTerminalStatus,\n PendingMediaStatusSchema,\n type PendingMediaNonTerminalStatus,\n type PendingMediaStatus,\n} from '@ttt-productions/media-schemas';\n\n// Status values derive from media-schemas' one declaration.\nconst STATUS = PendingMediaStatusSchema.enum;\n\n// =============================================================================\n// Generic shape of the data the provider tracks\n// =============================================================================\n\n/** Generic pending-media status — media-schemas' one declaration. */\nexport type InFlightUploadStatus = PendingMediaStatus;\n\n/**\n * Generic in-flight upload record. The provider keeps a Map<id, InFlightUpload>\n * built from each parsed PendingMedia. Consumers parameterize the `fileOrigin`\n * type via the parser's return type (the provider treats it as opaque).\n *\n * `TFileOrigin` defaults to `string` so unannotated consumers get a permissive\n * shape; consuming apps bind it to their own `FileOrigin` union at the call site.\n */\nexport type InFlightUploadBase<TFileOrigin extends string = string> = {\n id: string;\n fileOrigin: TFileOrigin;\n surface: string;\n createdAt: number;\n targetIds?: string[];\n originalContentType?: string;\n originalSize?: number;\n};\n\nexport type InFlightUploadActive<TFileOrigin extends string = string> =\n InFlightUploadBase<TFileOrigin> & {\n status: PendingMediaNonTerminalStatus;\n };\n\nexport type InFlightUploadCompleted<TFileOrigin extends string = string> =\n InFlightUploadBase<TFileOrigin> & {\n status: typeof PendingMediaStatusSchema.enum.completed;\n completedAt: number;\n uploadTrayClearedAt?: number;\n uploadTrayClearedBy?: string;\n uploadTraySeenAt?: number;\n uploadTraySeenBy?: string;\n };\n\nexport type InFlightUploadFailed<TFileOrigin extends string = string> =\n InFlightUploadBase<TFileOrigin> & {\n status: typeof PendingMediaStatusSchema.enum.failed;\n failedAt: number;\n errorCategory: string;\n errorMessage: string;\n uploadTrayClearedAt?: number;\n uploadTrayClearedBy?: string;\n uploadTraySeenAt?: number;\n uploadTraySeenBy?: string;\n };\n\nexport type InFlightUploadRejected<TFileOrigin extends string = string> =\n InFlightUploadBase<TFileOrigin> & {\n status: typeof PendingMediaStatusSchema.enum.rejected;\n rejectedAt: number;\n rejectionType: 'text' | 'media';\n errorMessage: string;\n violationId?: string;\n uploadTrayClearedAt?: number;\n uploadTrayClearedBy?: string;\n uploadTraySeenAt?: number;\n uploadTraySeenBy?: string;\n };\n\nexport type InFlightUpload<TFileOrigin extends string = string> =\n | InFlightUploadActive<TFileOrigin>\n | InFlightUploadCompleted<TFileOrigin>\n | InFlightUploadFailed<TFileOrigin>\n | InFlightUploadRejected<TFileOrigin>;\n\n// =============================================================================\n// Adapter contract — every app-specific behavior is injected here\n// =============================================================================\n\n/**\n * Result of the consumer-supplied parser. The provider keeps the raw parsed\n * record for callbacks (so consumers can read domain events, target IDs, etc.)\n * AND derives the generic InFlightUpload from it for the public Map.\n *\n * The parser MUST throw if validation fails; the provider catches and routes\n * the error to the monitoring callback.\n */\nexport type ParsedPendingMedia<TFileOrigin extends string = string> = {\n id: string;\n userId: string;\n fileOrigin: TFileOrigin;\n status: InFlightUploadStatus;\n createdAt: number;\n surface: string;\n targetIds?: string[];\n originalContentType?: string;\n originalSize?: number;\n // Terminal-status fields (only meaningful for the matching status)\n completedAt?: number;\n failedAt?: number;\n rejectedAt?: number;\n errorCategory?: string;\n errorMessage?: string;\n rejectionType?: 'text' | 'media';\n violationId?: string;\n uploadTrayClearedAt?: number;\n uploadTrayClearedBy?: string;\n uploadTraySeenAt?: number;\n uploadTraySeenBy?: string;\n /**\n * Opaque consumer-controlled domain-event payload, surfaced to the\n * `onUploadCompleted` and `onUploadRejected` callbacks for cache\n * invalidation. The provider does not interpret it.\n */\n domainEvents?: unknown;\n};\n\nexport type InFlightUploadsAdapter<TFileOrigin extends string = string> = {\n /** Returns the current user's uid, or null if not signed in. */\n getCurrentUserId: () => string | null;\n\n /** Firestore database adapter (loose typing — `unknown` keeps zero firebase coupling at the type level). */\n db: unknown;\n\n /** Collection path holding pending-media docs (e.g. \"pendingMedia\"). */\n collectionPath: string;\n\n /** Listener window in milliseconds — only docs with `createdAt >= now - window` are tracked. */\n listenerWindowMs: number;\n\n /**\n * Parse a raw Firestore doc snapshot's `.data()` into the generic shape the\n * provider tracks. Throws on validation failure; the provider routes thrown\n * errors to `onMonitoringEvent`.\n */\n parsePendingMedia: (raw: unknown) => ParsedPendingMedia<TFileOrigin>;\n\n /** Called once per observed non-terminal → terminal completed transition. */\n onUploadCompleted: (parsed: ParsedPendingMedia<TFileOrigin>) => void;\n\n /** Called once per observed non-terminal → terminal failed transition. */\n onUploadFailed: (parsed: ParsedPendingMedia<TFileOrigin>) => void;\n\n /** Called once per observed non-terminal → terminal rejected transition. */\n onUploadRejected: (parsed: ParsedPendingMedia<TFileOrigin>) => void;\n\n /**\n * Monitoring callback. Receives:\n * - `breadcrumb`: informational, fired on every observed terminal transition.\n * - `parse-error`: when `parsePendingMedia` throws.\n * - `listener-error`: when the Firestore listener's error callback fires.\n *\n * Consumers wire this to Sentry, OpenTelemetry, or any other observability\n * provider. The provider does NOT import any monitoring SDK directly.\n */\n onMonitoringEvent: (event: InFlightUploadsMonitoringEvent<TFileOrigin>) => void;\n};\n\nexport type InFlightUploadsMonitoringEvent<TFileOrigin extends string = string> =\n | {\n type: 'breadcrumb';\n category: 'upload.terminal';\n level: 'info';\n message: string;\n data: {\n id: string;\n fileOrigin: TFileOrigin;\n status: InFlightUploadStatus;\n surface: string;\n };\n }\n | {\n type: 'parse-error';\n docId: string;\n error: unknown;\n data: unknown;\n }\n | {\n type: 'listener-error';\n error: unknown;\n };\n\n// =============================================================================\n// Firestore subscription contract — abstracted to avoid firebase coupling\n// =============================================================================\n\n/**\n * Minimal subscription contract used by the provider. The default\n * implementation lives in `firestore-subscribe.ts` and uses the standard\n * `firebase/firestore` `onSnapshot` + `query` + `where` builders.\n *\n * Tests inject a fake to drive the listener without spinning up Firestore.\n */\nexport type FirestoreSubscribeFn = (args: {\n db: unknown;\n collectionPath: string;\n userId: string;\n windowStartMs: number;\n onSnapshot: (snapshot: FirestoreLikeSnapshot) => void;\n onError: (error: unknown) => void;\n}) => () => void;\n\nexport type FirestoreLikeSnapshot = {\n docChanges: () => FirestoreLikeDocChange[];\n /**\n * Snapshot metadata. Present when the subscription is opened with\n * `{ includeMetadataChanges: true }` (the default firebase implementation does).\n * `fromCache === false` means a server-confirmed snapshot. Optional so injected\n * test fakes need not supply it (absent ⇒ treated as server-confirmed).\n */\n metadata?: { fromCache: boolean };\n};\n\n/**\n * Metadata-derived liveness of the uploads listener, mirroring query-core's\n * `FirestoreSourceState`. Firestore serves cached snapshots offline WITHOUT\n * firing the error callback, so the Files tray source needs this to show a\n * degraded indicator instead of a false \"all caught up\":\n * - `connecting` — no server-confirmed snapshot yet.\n * - `live` — at least one server-confirmed snapshot (`fromCache === false`).\n * - `offline` — only cached data after having been live.\n * - `error` — the listener error callback fired.\n */\nexport type UploadsSourceState = 'connecting' | 'live' | 'offline' | 'error';\n\nexport type FirestoreLikeDocChange = {\n type: 'added' | 'modified' | 'removed';\n doc: {\n id: string;\n data: () => unknown;\n };\n};\n\n// =============================================================================\n// Provider\n// =============================================================================\n\ninterface InFlightUploadsContextValue<TFileOrigin extends string = string> {\n uploads: Map<string, InFlightUpload<TFileOrigin>>;\n sourceState: UploadsSourceState;\n retry: () => void;\n retrying: boolean;\n}\n\n/** Restarting the uploads listener after it failed, and whether that restart is running. */\nexport interface UploadsSourceRetry {\n /**\n * Tear the listener down and subscribe again on a fresh retry ladder. While the restart runs the\n * source state stays as it was (an `error` stays `error`), so a failure shown on it stays on\n * screen with its control pending.\n */\n retry: () => void;\n /** A `retry` is running: true until the restarted listener answers or its ladder fails again. */\n retrying: boolean;\n}\n\nconst InFlightUploadsContext = createContext<InFlightUploadsContextValue | undefined>(undefined);\n\nexport interface InFlightUploadsProviderProps<TFileOrigin extends string = string> {\n adapter: InFlightUploadsAdapter<TFileOrigin>;\n /** Firestore subscription function. Defaults to the firebase/firestore implementation. */\n subscribe?: FirestoreSubscribeFn;\n children: ReactNode;\n}\n\nfunction fromParsed<TFileOrigin extends string>(\n parsed: ParsedPendingMedia<TFileOrigin>,\n): InFlightUpload<TFileOrigin> {\n const base: InFlightUploadBase<TFileOrigin> = {\n id: parsed.id,\n fileOrigin: parsed.fileOrigin,\n surface: parsed.surface,\n createdAt: parsed.createdAt,\n targetIds: parsed.targetIds,\n originalContentType: parsed.originalContentType,\n originalSize: parsed.originalSize,\n };\n if (isPendingMediaNonTerminalStatus(parsed.status)) {\n return { ...base, status: parsed.status };\n }\n if (parsed.status === STATUS.completed) {\n return {\n ...base,\n status: STATUS.completed,\n completedAt: parsed.completedAt ?? parsed.createdAt,\n uploadTrayClearedAt: parsed.uploadTrayClearedAt,\n uploadTrayClearedBy: parsed.uploadTrayClearedBy,\n uploadTraySeenAt: parsed.uploadTraySeenAt,\n uploadTraySeenBy: parsed.uploadTraySeenBy,\n };\n }\n if (parsed.status === STATUS.failed) {\n return {\n ...base,\n status: STATUS.failed,\n failedAt: parsed.failedAt ?? parsed.createdAt,\n errorCategory: parsed.errorCategory ?? 'system',\n errorMessage: parsed.errorMessage ?? '',\n uploadTrayClearedAt: parsed.uploadTrayClearedAt,\n uploadTrayClearedBy: parsed.uploadTrayClearedBy,\n uploadTraySeenAt: parsed.uploadTraySeenAt,\n uploadTraySeenBy: parsed.uploadTraySeenBy,\n };\n }\n // rejected\n return {\n ...base,\n status: STATUS.rejected,\n rejectedAt: parsed.rejectedAt ?? parsed.createdAt,\n rejectionType: parsed.rejectionType ?? 'media',\n errorMessage: parsed.errorMessage ?? '',\n violationId: parsed.violationId,\n uploadTrayClearedAt: parsed.uploadTrayClearedAt,\n uploadTrayClearedBy: parsed.uploadTrayClearedBy,\n // Carry the seen fields through (round-9 finding 9): dropping them on the\n // `rejected` branch — while `completed`/`failed` keep them — made a seen\n // rejected upload relight the Files dot forever, because the tray's\n // unseen-terminal check never saw `uploadTraySeenAt`.\n uploadTraySeenAt: parsed.uploadTraySeenAt,\n uploadTraySeenBy: parsed.uploadTraySeenBy,\n };\n}\n\nexport function InFlightUploadsProvider<TFileOrigin extends string = string>(\n props: InFlightUploadsProviderProps<TFileOrigin>,\n) {\n const { adapter, subscribe = defaultFirestoreSubscribe, children } = props;\n\n const [uploads, setUploads] = useState<Map<string, InFlightUpload<TFileOrigin>>>(new Map());\n const [sourceState, setSourceState] = useState<UploadsSourceState>('connecting');\n const [restarts, setRestarts] = useState(0);\n const [retrying, setRetrying] = useState(false);\n /** Set by `retry` for the subscription the restart opens; that run keeps the source state. */\n const restartRequestedRef = useRef(false);\n const seenTerminalIdsRef = useRef<Set<string>>(new Set());\n const statusByIdRef = useRef<Map<string, InFlightUploadStatus>>(new Map());\n const hasProcessedInitialSnapshotRef = useRef(false);\n /** The identity the dedup/tracking refs belong to — they outlive resubscribes\n * for the SAME user (auth-settling flaps) and reset only on a real identity\n * change. See the reset block in the subscription effect. */\n const trackedUserIdRef = useRef<string | null>(null);\n\n // Stable refs for adapter callbacks — read from latest adapter inside effect.\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n });\n\n const userId = adapter.getCurrentUserId();\n\n useEffect(() => {\n // The uploads map and source state rebuild from every subscription's initial\n // snapshot, so they reset on every effect run. The terminal-dedup and\n // status-tracking refs are IDENTITY-scoped, not subscription-scoped: an\n // auth-settling flap (uid → null → same uid re-subscribes) must neither\n // re-fire terminals the previous subscription already fired (seen set\n // persists) nor lose the observed non-terminal statuses that let the new\n // subscription's initial listing detect a transition that completed during\n // the gap. A real identity change — including UID-A → UID-B with no\n // intermediate null user — starts clean; never rely on an intermediate\n // sign-out to clear refs between two authenticated UIDs.\n // A restart the person asked for keeps the source state it had (a failure stays a failure\n // until the restarted listener answers); every other run starts over as `connecting`.\n // A restart belongs to the identity it was asked for: one that lands with a sign-out or a switch\n // of account is an ordinary new subscription, which starts over.\n let restarting = restartRequestedRef.current && userId !== null && userId === trackedUserIdRef.current;\n restartRequestedRef.current = false;\n setUploads(new Map());\n if (!restarting) {\n setSourceState('connecting');\n setRetrying(false);\n }\n if (userId !== null && userId !== trackedUserIdRef.current) {\n seenTerminalIdsRef.current = new Set();\n statusByIdRef.current = new Map();\n trackedUserIdRef.current = userId;\n }\n hasProcessedInitialSnapshotRef.current = false;\n\n if (!userId) {\n return;\n }\n\n const a = adapterRef.current;\n const windowStartMs = Date.now() - a.listenerWindowMs;\n\n const handleSnapshot = (snapshot: FirestoreLikeSnapshot) => {\n const updates: Array<{ id: string; upload: InFlightUpload<TFileOrigin> | null }> = [];\n const newlyTerminal: Array<ParsedPendingMedia<TFileOrigin>> = [];\n const isInitialSnapshot = !hasProcessedInitialSnapshotRef.current;\n\n for (const change of snapshot.docChanges()) {\n if (change.type === 'removed') {\n updates.push({ id: change.doc.id, upload: null });\n statusByIdRef.current.delete(change.doc.id);\n seenTerminalIdsRef.current.delete(change.doc.id);\n continue;\n }\n\n let parsed: ParsedPendingMedia<TFileOrigin>;\n try {\n parsed = adapterRef.current.parsePendingMedia(change.doc.data());\n } catch (error) {\n adapterRef.current.onMonitoringEvent({\n type: 'parse-error',\n docId: change.doc.id,\n error,\n data: change.doc.data(),\n });\n continue;\n }\n\n const upload = fromParsed(parsed);\n updates.push({ id: parsed.id, upload });\n\n const previousStatus = statusByIdRef.current.get(parsed.id);\n const currentStatus = parsed.status;\n const currentIsTerminal = isPendingMediaTerminalStatus(currentStatus);\n const previousWasNonTerminal = isPendingMediaNonTerminalStatus(previousStatus);\n\n if (isInitialSnapshot) {\n // A subscription's first snapshot is a (re-)listing of current state,\n // not a live event: already-terminal docs stay suppressed so a page\n // refresh never re-toasts. ONE exception — this provider instance\n // tracked the doc as non-terminal before (same-identity resubscribe\n // gap; the tracking refs survive those), so the terminal listing IS\n // the transition, observed across the gap, and must fire.\n if (currentIsTerminal) {\n if (previousWasNonTerminal && !seenTerminalIdsRef.current.has(parsed.id)) {\n newlyTerminal.push(parsed);\n }\n seenTerminalIdsRef.current.add(parsed.id);\n }\n } else if (currentIsTerminal && !seenTerminalIdsRef.current.has(parsed.id)) {\n // Any unseen terminal in a LIVE snapshot fires — including a doc whose\n // FIRST client-visible state is already terminal. A fast backend\n // outcome (moderation rejection in ~2s) can coalesce created→terminal\n // into one delivery, and the uploader is actively waiting on exactly\n // this callback; swallowing it silently loses a rejection dialog.\n seenTerminalIdsRef.current.add(parsed.id);\n newlyTerminal.push(parsed);\n }\n\n statusByIdRef.current.set(parsed.id, currentStatus);\n }\n\n hasProcessedInitialSnapshotRef.current = true;\n\n // Metadata-derived source state: stay `connecting` until a server-confirmed\n // snapshot, `offline` if only cached data arrives after being live.\n const fromCache = snapshot.metadata?.fromCache ?? false;\n // A restart ends on the server's answer: a cached snapshot during it keeps the failure on screen\n // (the server may refuse again). Otherwise a snapshot after a failed listener comes from a new\n // subscription: not yet live, never offline.\n if (!(restarting && fromCache)) {\n setSourceState((prev) =>\n fromCache ? (prev === 'connecting' || prev === 'error' ? 'connecting' : 'offline') : 'live',\n );\n restarting = false;\n setRetrying(false);\n }\n\n if (updates.length > 0) {\n setUploads((prev) => {\n const next = new Map(prev);\n for (const { id, upload } of updates) {\n if (upload === null) next.delete(id);\n else next.set(id, upload);\n }\n return next;\n });\n }\n\n for (const parsed of newlyTerminal) {\n handleTerminal(parsed);\n }\n };\n\n function handleTerminal(parsed: ParsedPendingMedia<TFileOrigin>) {\n adapterRef.current.onMonitoringEvent({\n type: 'breadcrumb',\n category: 'upload.terminal',\n level: 'info',\n message: `${parsed.fileOrigin}:${parsed.status}`,\n data: {\n id: parsed.id,\n fileOrigin: parsed.fileOrigin,\n status: parsed.status,\n surface: parsed.surface,\n },\n });\n\n if (parsed.status === STATUS.completed) {\n adapterRef.current.onUploadCompleted(parsed);\n } else if (parsed.status === STATUS.failed) {\n adapterRef.current.onUploadFailed(parsed);\n } else if (parsed.status === STATUS.rejected) {\n adapterRef.current.onUploadRejected(parsed);\n }\n }\n\n // Bounded RESUBSCRIBE on listener error: a cold-session race (e.g. Firestore\n // App Check enforcement rejecting the first attach before the token is\n // minted) must not kill the listener for the whole session — observed live:\n // one permission-denied at first login → sourceState 'error' forever, every\n // tray file status dead until reload. Retry on a short ladder; a snapshot\n // resets the ladder (healthy again); exhausting it goes terminal 'error'\n // (a real rules denial stays denied — retries are cheap and bounded).\n const RESUBSCRIBE_DELAYS_MS = [1_000, 3_000, 10_000, 30_000];\n let attempt = 0;\n let disposed = false;\n let retryTimer: ReturnType<typeof setTimeout> | undefined;\n let unsubscribe: (() => void) | undefined;\n\n const start = () => {\n unsubscribe = subscribe({\n db: a.db,\n collectionPath: a.collectionPath,\n userId,\n windowStartMs,\n onSnapshot: (snapshot) => {\n attempt = 0; // healthy — future errors get a fresh ladder\n handleSnapshot(snapshot);\n },\n onError: (error) => {\n adapterRef.current.onMonitoringEvent({ type: 'listener-error', error });\n unsubscribe?.();\n unsubscribe = undefined;\n if (disposed || attempt >= RESUBSCRIBE_DELAYS_MS.length) {\n setSourceState('error');\n setRetrying(false);\n return;\n }\n if (!restarting) setSourceState('connecting');\n retryTimer = setTimeout(() => {\n if (disposed) return;\n attempt += 1;\n start();\n }, RESUBSCRIBE_DELAYS_MS[attempt]);\n },\n });\n };\n start();\n\n return () => {\n disposed = true;\n if (retryTimer) clearTimeout(retryTimer);\n unsubscribe?.();\n };\n // adapter is intentionally NOT in the deps array — adapter is read via\n // adapterRef on every snapshot, so identity changes don't re-subscribe.\n\n }, [userId, subscribe, restarts]);\n\n const retry = useCallback(() => {\n restartRequestedRef.current = true;\n setRetrying(true);\n setRestarts((count) => count + 1);\n }, []);\n\n const value = useMemo<InFlightUploadsContextValue<TFileOrigin>>(\n () => ({ uploads, sourceState, retry, retrying }),\n [uploads, sourceState, retry, retrying],\n );\n\n return (\n <InFlightUploadsContext.Provider value={value as InFlightUploadsContextValue}>\n {children}\n </InFlightUploadsContext.Provider>\n );\n}\n\n// =============================================================================\n// Read APIs\n// =============================================================================\n\nexport function useInFlightUploadsState<TFileOrigin extends string = string>(): Map<\n string,\n InFlightUpload<TFileOrigin>\n> {\n const ctx = useContext(InFlightUploadsContext);\n if (ctx === undefined) {\n throw new Error('useInFlightUploadsState must be used within InFlightUploadsProvider');\n }\n return ctx.uploads as Map<string, InFlightUpload<TFileOrigin>>;\n}\n\nexport function useInFlightUpload<TFileOrigin extends string = string>(\n id: string | null | undefined,\n): InFlightUpload<TFileOrigin> | undefined {\n const ctx = useContext(InFlightUploadsContext);\n if (ctx === undefined) {\n throw new Error('useInFlightUpload must be used within InFlightUploadsProvider');\n }\n if (!id) return undefined;\n return ctx.uploads.get(id) as InFlightUpload<TFileOrigin> | undefined;\n}\n\n/**\n * Metadata-derived source state of the uploads listener\n * (`connecting | live | offline | error`). The Files tray uses this to show a\n * degraded indicator and never display \"all caught up\" while the source is\n * `offline`/`error`/`connecting`.\n */\nexport function useUploadsSourceState(): UploadsSourceState {\n const ctx = useContext(InFlightUploadsContext);\n if (ctx === undefined) {\n throw new Error('useUploadsSourceState must be used within InFlightUploadsProvider');\n }\n return ctx.sourceState;\n}\n\n/**\n * The uploads listener's restart — the Try again of a failure shown on `useUploadsSourceState` —\n * and whether it is running.\n */\nexport function useUploadsSourceRetry(): UploadsSourceRetry {\n const ctx = useContext(InFlightUploadsContext);\n if (ctx === undefined) {\n throw new Error('useUploadsSourceRetry must be used within InFlightUploadsProvider');\n }\n return { retry: ctx.retry, retrying: ctx.retrying };\n}\n\n// =============================================================================\n// Tray helpers\n// =============================================================================\n\n/**\n * `true` for `completed` / `failed` / `rejected`. Used by tray UI to decide\n * whether a Clear action is available for an item.\n */\nexport function isTerminalUpload<TFileOrigin extends string = string>(\n item: InFlightUpload<TFileOrigin>,\n): item is Exclude<InFlightUpload<TFileOrigin>, { status: PendingMediaNonTerminalStatus }> {\n return isPendingMediaTerminalStatus(item.status);\n}\n\n/**\n * Tray-visible items. Includes every pending/processing upload, plus terminal\n * uploads that have NOT been cleared from the tray. Sorted newest-first by\n * createdAt.\n *\n * The public selector name in upload-ui is `useUploadActivityState`. The\n * mutation hook is `useClearUploadActivity` (in a separate file).\n */\nexport function useUploadActivityState<TFileOrigin extends string = string>(): InFlightUpload<TFileOrigin>[] {\n const uploads = useInFlightUploadsState<TFileOrigin>();\n return useMemo(() => {\n return Array.from(uploads.values())\n .filter((item) => {\n if (!isTerminalUpload(item)) return true;\n return item.uploadTrayClearedAt === undefined;\n })\n .sort((a, b) => b.createdAt - a.createdAt);\n }, [uploads]);\n}\n\n// =============================================================================\n// Default Firestore subscription implementation\n// =============================================================================\n\n/**\n * Default Firestore subscription using the consumer's `firebase/firestore`\n * module instance (via static ESM import at the top of this file).\n *\n * Using static ESM import — NOT `require()` — is load-bearing. CommonJS\n * `require('firebase/firestore')` and ESM `import 'firebase/firestore'` resolve\n * to different module instances under Next.js + Turbopack. If the consumer\n * constructs `db` via ESM and we receive it here, but we then call\n * `collection()` from a CJS-loaded copy of firebase, the firebase runtime\n * does not recognize the db as a Firestore instance and throws\n * \"Expected first argument to collection() to be a CollectionReference,\n * a DocumentReference or FirebaseFirestore\".\n *\n * Consumers who want to skip the firebase code path entirely (tests, alt\n * backends) supply their own `subscribe` prop to `InFlightUploadsProvider`.\n */\nconst defaultFirestoreSubscribe: FirestoreSubscribeFn = (args) => {\n const q = query(\n\n collection(args.db as any, args.collectionPath),\n where('userId', '==', args.userId),\n where('createdAt', '>=', args.windowStartMs),\n );\n // includeMetadataChanges so the provider can derive a `connecting|live|offline|error`\n // source state from `snapshot.metadata.fromCache` (the Files tray degraded indicator).\n return onSnapshot(q, { includeMetadataChanges: true }, args.onSnapshot as never, args.onError as never);\n};\n"]}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The navigation and leave guard: warns before the user leaves while work that leaving would lose
|
|
3
|
-
* is registered — a LOCAL byte upload in flight, or an editor's unsaved input.
|
|
4
|
-
*
|
|
5
|
-
* Uploads: phases `preparing` and `uploading` only. `finalizing` and backend `pendingMedia`
|
|
6
|
-
* processing are safe to leave (the bytes are already in Storage), so they are not registered.
|
|
7
|
-
* Unsaved work: an editor registers while it holds input its user has not saved, and unregisters
|
|
8
|
-
* when the input is saved, discarded, or the editor unmounts.
|
|
9
|
-
*
|
|
10
|
-
* While anything is registered the provider installs ONE `beforeunload` listener (tab close,
|
|
11
|
-
* reload, full-page navigation), and `confirmNavigation()` asks before an in-app navigation. It is
|
|
12
|
-
* the one leave guard: an editor never installs its own `beforeunload` handler (FRONTEND-207).
|
|
13
|
-
*
|
|
14
|
-
* Consumers register with a stable id per piece of work; registering a registered id, or
|
|
15
|
-
* unregistering an absent one, is a no-op. Uploads and unsaved work are counted separately, so the
|
|
16
|
-
* same id may be both.
|
|
17
|
-
*/
|
|
18
|
-
import { type ReactNode } from 'react';
|
|
19
|
-
export interface ConfirmNavigationOptions {
|
|
20
|
-
/**
|
|
21
|
-
* The caller leaves through a FULL-PAGE navigation (`location.assign` /
|
|
22
|
-
* `location.replace`) once this returns true. The provider then lets that
|
|
23
|
-
* navigation's next `beforeunload` pass without the browser's own
|
|
24
|
-
* "Leave site?" prompt, because the user has just answered this one. Soft
|
|
25
|
-
* (in-app router) navigations never pass it: they fire no `beforeunload`.
|
|
26
|
-
*/
|
|
27
|
-
fullPageNavigation?: boolean;
|
|
28
|
-
}
|
|
29
|
-
interface LocalUploadGuardContextValue {
|
|
30
|
-
/** Registered local uploads. */
|
|
31
|
-
activeUploadCount: number;
|
|
32
|
-
/** Registered pieces of unsaved work. */
|
|
33
|
-
unsavedWorkCount: number;
|
|
34
|
-
/** Everything the guard warns about: uploads plus unsaved work. Zero means leaving asks nothing. */
|
|
35
|
-
guardedWorkCount: number;
|
|
36
|
-
registerUpload: (id: string) => void;
|
|
37
|
-
unregisterUpload: (id: string) => void;
|
|
38
|
-
registerUnsavedWork: (id: string) => void;
|
|
39
|
-
unregisterUnsavedWork: (id: string) => void;
|
|
40
|
-
/** Returns true iff an upload or unsaved work is currently registered. Pure read. */
|
|
41
|
-
shouldConfirmNavigation: () => boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Shows a confirm() dialog with the message for what is registered and returns the user's
|
|
44
|
-
* choice. Safe to call when nothing is registered — returns true without prompting.
|
|
45
|
-
*
|
|
46
|
-
* With `{ fullPageNavigation: true }` and a result of true (confirmed, or nothing registered),
|
|
47
|
-
* arms a ONE-SHOT bypass: the next `beforeunload` is not prevented, so a confirmed full-page
|
|
48
|
-
* navigation does not prompt twice. A declined confirm never arms it; the bypass is cleared when
|
|
49
|
-
* it is consumed, when new work (an upload or unsaved work) registers, and on `pageshow` (a
|
|
50
|
-
* back/forward-cache return).
|
|
51
|
-
*/
|
|
52
|
-
confirmNavigation: (options?: ConfirmNavigationOptions) => boolean;
|
|
53
|
-
}
|
|
54
|
-
export interface LocalUploadGuardProviderProps {
|
|
55
|
-
/**
|
|
56
|
-
* Message the browser is given when the user closes the tab, reloads, or leaves the page while
|
|
57
|
-
* work is registered. Modern browsers show their own generic dialog and ignore it; when omitted,
|
|
58
|
-
* the default for what is registered is used.
|
|
59
|
-
*/
|
|
60
|
-
beforeUnloadMessage?: string;
|
|
61
|
-
/** `confirmNavigation()`'s message while an upload is in progress (and no unsaved work). */
|
|
62
|
-
navigationConfirmMessage?: string;
|
|
63
|
-
/** `confirmNavigation()`'s message while unsaved work is registered (and no upload). */
|
|
64
|
-
unsavedWorkConfirmMessage?: string;
|
|
65
|
-
/** `confirmNavigation()`'s message while both an upload and unsaved work are registered. */
|
|
66
|
-
uploadAndUnsavedWorkConfirmMessage?: string;
|
|
67
|
-
children: ReactNode;
|
|
68
|
-
}
|
|
69
|
-
export declare function LocalUploadGuardProvider(props: LocalUploadGuardProviderProps): import("react").JSX.Element;
|
|
70
|
-
/**
|
|
71
|
-
* Low-level accessor for the guard context. Throws if used outside a
|
|
72
|
-
* `LocalUploadGuardProvider`. Most consumers should use `useLocalUploadGuard`
|
|
73
|
-
* (the public re-export below) instead.
|
|
74
|
-
*/
|
|
75
|
-
export declare function useLocalUploadGuardContext(): LocalUploadGuardContextValue;
|
|
76
|
-
/**
|
|
77
|
-
* Optional accessor: returns the guard context, or `null` when rendered
|
|
78
|
-
* outside a `LocalUploadGuardProvider`. For package components (e.g. the
|
|
79
|
-
* chat composer registering an in-flight send) that must degrade gracefully
|
|
80
|
-
* in consumers that don't mount the provider, instead of throwing.
|
|
81
|
-
*/
|
|
82
|
-
export declare function useOptionalLocalUploadGuard(): LocalUploadGuardContextValue | null;
|
|
83
|
-
/**
|
|
84
|
-
* Public hook for the navigation and leave guard.
|
|
85
|
-
*
|
|
86
|
-
* Typical usage in an upload flow:
|
|
87
|
-
*
|
|
88
|
-
* const { registerUpload, unregisterUpload } = useLocalUploadGuard();
|
|
89
|
-
* useEffect(() => {
|
|
90
|
-
* if (phase === 'preparing' || phase === 'uploading') {
|
|
91
|
-
* registerUpload(uploadId);
|
|
92
|
-
* return () => unregisterUpload(uploadId);
|
|
93
|
-
* }
|
|
94
|
-
* }, [phase, uploadId, registerUpload, unregisterUpload]);
|
|
95
|
-
*
|
|
96
|
-
* An editor holding input uses `useUnsavedWorkGuard(hasUnsavedWork)` instead.
|
|
97
|
-
*/
|
|
98
|
-
export declare function useLocalUploadGuard(): LocalUploadGuardContextValue;
|
|
99
|
-
/**
|
|
100
|
-
* Registers the calling editor's unsaved input with the leave guard while `hasUnsavedWork` is
|
|
101
|
-
* true, and unregisters it when that turns false or the editor unmounts. While registered, closing
|
|
102
|
-
* the tab, reloading, a full-page navigation, and every guarded in-app navigation ask first.
|
|
103
|
-
* Throws outside a `LocalUploadGuardProvider`.
|
|
104
|
-
*
|
|
105
|
-
* Returns `release`, which unregisters at once: an editor that saves and then navigates in the
|
|
106
|
-
* same handler calls it after the save, because its dirty flag clears only on the next render.
|
|
107
|
-
*/
|
|
108
|
-
export declare function useUnsavedWorkGuard(hasUnsavedWork: boolean): {
|
|
109
|
-
release: () => void;
|
|
110
|
-
};
|
|
111
|
-
export {};
|
|
112
|
-
//# sourceMappingURL=local-upload-guard-provider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"local-upload-guard-provider.d.ts","sourceRoot":"","sources":["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I,CAEjF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,IAAI,4BAA4B,CAElE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAUpF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"local-upload-guard-provider.js","sourceRoot":"","sources":["../../src/react/local-upload-guard-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GAET,MAAM,OAAO,CAAC;AAuCf,MAAM,uBAAuB,GAAG,aAAa,CAA2C,SAAS,CAAC,CAAC;AAkBnG,MAAM,kCAAkC,GACtC,oGAAoG,CAAC;AACvG,MAAM,oCAAoC,GACxC,gFAAgF,CAAC;AACnF,MAAM,+CAA+C,GACnD,qJAAqJ,CAAC;AACxJ,MAAM,oCAAoC,GACxC,kFAAkF,CAAC;AACrF,MAAM,0CAA0C,GAC9C,yEAAyE,CAAC;AAE5E,SAAS,WAAW,CAAC,UAAsB;IACzC,MAAM,MAAM,GAAG,MAAM,CAAc,IAAI,GAAG,EAAE,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEtC,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,EAAU,EAAE,EAAE;QACb,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO;QACnC,UAAU,EAAE,CAAC;QACb,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACvB,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAA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C,CAAC;IAC1F,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AACjD,CAAC","sourcesContent":["'use client';\n\n/**\n * The navigation and leave guard: warns before the user leaves while work that leaving would lose\n * is registered — a LOCAL byte upload in flight, or an editor's unsaved input.\n *\n * Uploads: phases `preparing` and `uploading` only. `finalizing` and backend `pendingMedia`\n * processing are safe to leave (the bytes are already in Storage), so they are not registered.\n * Unsaved work: an editor registers while it holds input its user has not saved, and unregisters\n * when the input is saved, discarded, or the editor unmounts.\n *\n * While anything is registered the provider installs ONE `beforeunload` listener (tab close,\n * reload, full-page navigation), and `confirmNavigation()` asks before an in-app navigation. It is\n * the one leave guard: an editor never installs its own `beforeunload` handler (FRONTEND-207).\n *\n * Consumers register with a stable id per piece of work; registering a registered id, or\n * unregistering an absent one, is a no-op. Uploads and unsaved work are counted separately, so the\n * same id may be both.\n */\n\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\n\nexport interface ConfirmNavigationOptions {\n /**\n * The caller leaves through a FULL-PAGE navigation (`location.assign` /\n * `location.replace`) once this returns true. The provider then lets that\n * navigation's next `beforeunload` pass without the browser's own\n * \"Leave site?\" prompt, because the user has just answered this one. Soft\n * (in-app router) navigations never pass it: they fire no `beforeunload`.\n */\n fullPageNavigation?: boolean;\n}\n\ninterface LocalUploadGuardContextValue {\n /** Registered local uploads. */\n activeUploadCount: number;\n /** Registered pieces of unsaved work. */\n unsavedWorkCount: number;\n /** Everything the guard warns about: uploads plus unsaved work. Zero means leaving asks nothing. */\n guardedWorkCount: number;\n registerUpload: (id: string) => void;\n unregisterUpload: (id: string) => void;\n registerUnsavedWork: (id: string) => void;\n unregisterUnsavedWork: (id: string) => void;\n /** Returns true iff an upload or unsaved work is currently registered. Pure read. */\n shouldConfirmNavigation: () => boolean;\n /**\n * Shows a confirm() dialog with the message for what is registered and returns the user's\n * choice. Safe to call when nothing is registered — returns true without prompting.\n *\n * With `{ fullPageNavigation: true }` and a result of true (confirmed, or nothing registered),\n * arms a ONE-SHOT bypass: the next `beforeunload` is not prevented, so a confirmed full-page\n * navigation does not prompt twice. A declined confirm never arms it; the bypass is cleared when\n * it is consumed, when new work (an upload or unsaved work) registers, and on `pageshow` (a\n * back/forward-cache return).\n */\n confirmNavigation: (options?: ConfirmNavigationOptions) => boolean;\n}\n\nconst LocalUploadGuardContext = createContext<LocalUploadGuardContextValue | undefined>(undefined);\n\nexport interface LocalUploadGuardProviderProps {\n /**\n * Message the browser is given when the user closes the tab, reloads, or leaves the page while\n * work is registered. Modern browsers show their own generic dialog and ignore it; when omitted,\n * the default for what is registered is used.\n */\n beforeUnloadMessage?: string;\n /** `confirmNavigation()`'s message while an upload is in progress (and no unsaved work). */\n navigationConfirmMessage?: string;\n /** `confirmNavigation()`'s message while unsaved work is registered (and no upload). */\n unsavedWorkConfirmMessage?: string;\n /** `confirmNavigation()`'s message while both an upload and unsaved work are registered. */\n uploadAndUnsavedWorkConfirmMessage?: string;\n children: ReactNode;\n}\n\nconst DEFAULT_NAVIGATION_CONFIRM_MESSAGE =\n 'An upload is currently in progress. If you leave this page, the upload will be canceled. Continue?';\nconst DEFAULT_UNSAVED_WORK_CONFIRM_MESSAGE =\n 'You have unsaved changes. If you leave this page, they will be lost. Continue?';\nconst DEFAULT_UPLOAD_AND_UNSAVED_WORK_CONFIRM_MESSAGE =\n 'An upload is in progress and you have unsaved changes. If you leave this page, the upload will be canceled and your changes will be lost. Continue?';\nconst DEFAULT_UPLOAD_BEFORE_UNLOAD_MESSAGE =\n 'File upload in progress. Are you sure you want to leave and end the file upload?';\nconst DEFAULT_UNSAVED_WORK_BEFORE_UNLOAD_MESSAGE =\n 'You have unsaved changes. Are you sure you want to leave and lose them?';\n\nfunction useRegistry(onRegister: () => void) {\n const idsRef = useRef<Set<string>>(new Set());\n const [count, setCount] = useState(0);\n\n const register = useCallback(\n (id: string) => {\n if (idsRef.current.has(id)) return;\n onRegister();\n idsRef.current.add(id);\n setCount(idsRef.current.size);\n },\n [onRegister],\n );\n\n const unregister = useCallback((id: string) => {\n if (!idsRef.current.has(id)) return;\n idsRef.current.delete(id);\n setCount(idsRef.current.size);\n }, []);\n\n return { idsRef, count, register, unregister };\n}\n\nexport function LocalUploadGuardProvider(props: LocalUploadGuardProviderProps) {\n const {\n children,\n beforeUnloadMessage,\n navigationConfirmMessage = DEFAULT_NAVIGATION_CONFIRM_MESSAGE,\n unsavedWorkConfirmMessage = DEFAULT_UNSAVED_WORK_CONFIRM_MESSAGE,\n uploadAndUnsavedWorkConfirmMessage = DEFAULT_UPLOAD_AND_UNSAVED_WORK_CONFIRM_MESSAGE,\n } = props;\n // One-shot: the user already confirmed the full-page navigation now unloading.\n const bypassNextUnloadRef = useRef(false);\n // Also run when work registers: work that starts after a confirmation was not covered by it.\n const clearBypass = useCallback(() => {\n bypassNextUnloadRef.current = false;\n }, []);\n\n const uploads = useRegistry(clearBypass);\n const unsavedWork = useRegistry(clearBypass);\n const uploadIdsRef = uploads.idsRef;\n const unsavedWorkIdsRef = unsavedWork.idsRef;\n const guardedWorkCount = uploads.count + unsavedWork.count;\n const hasGuardedWork = guardedWorkCount > 0;\n\n // Read at the moment of asking, so a message always matches what is registered right then.\n const confirmMessage = useCallback((): string => {\n const uploading = uploadIdsRef.current.size > 0;\n const unsaved = unsavedWorkIdsRef.current.size > 0;\n if (uploading && unsaved) return uploadAndUnsavedWorkConfirmMessage;\n return uploading ? navigationConfirmMessage : unsavedWorkConfirmMessage;\n }, [\n uploadIdsRef,\n unsavedWorkIdsRef,\n navigationConfirmMessage,\n unsavedWorkConfirmMessage,\n uploadAndUnsavedWorkConfirmMessage,\n ]);\n\n useEffect(() => {\n if (!hasGuardedWork) return;\n\n const handleBeforeUnload = (event: BeforeUnloadEvent) => {\n if (bypassNextUnloadRef.current) {\n bypassNextUnloadRef.current = false;\n return;\n }\n event.preventDefault();\n // Modern browsers may ignore the custom string and show their own generic confirmation;\n // what matters is that leaving is warned, not the exact text.\n event.returnValue =\n beforeUnloadMessage ??\n (uploadIdsRef.current.size > 0\n ? DEFAULT_UPLOAD_BEFORE_UNLOAD_MESSAGE\n : DEFAULT_UNSAVED_WORK_BEFORE_UNLOAD_MESSAGE);\n return event.returnValue;\n };\n\n window.addEventListener('beforeunload', handleBeforeUnload);\n return () => {\n window.removeEventListener('beforeunload', handleBeforeUnload);\n };\n }, [hasGuardedWork, beforeUnloadMessage, uploadIdsRef]);\n\n // A back/forward-cache return re-shows this page without reloading it: an\n // armed bypass from the navigation that left must never outlive that navigation.\n useEffect(() => {\n window.addEventListener('pageshow', clearBypass);\n return () => {\n window.removeEventListener('pageshow', clearBypass);\n };\n }, [clearBypass]);\n\n const shouldConfirmNavigation = useCallback(\n () => uploadIdsRef.current.size > 0 || unsavedWorkIdsRef.current.size > 0,\n [uploadIdsRef, unsavedWorkIdsRef],\n );\n\n const confirmNavigation = useCallback(\n (options?: ConfirmNavigationOptions): boolean => {\n // SSR / non-browser safety: if `window` isn't available, default to allow.\n if (typeof window === 'undefined') return true;\n const proceed = !shouldConfirmNavigation() || window.confirm(confirmMessage());\n if (proceed && options?.fullPageNavigation) bypassNextUnloadRef.current = true;\n return proceed;\n },\n [shouldConfirmNavigation, confirmMessage],\n );\n\n const value = useMemo<LocalUploadGuardContextValue>(\n () => ({\n activeUploadCount: uploads.count,\n unsavedWorkCount: unsavedWork.count,\n guardedWorkCount,\n registerUpload: uploads.register,\n unregisterUpload: uploads.unregister,\n registerUnsavedWork: unsavedWork.register,\n unregisterUnsavedWork: unsavedWork.unregister,\n shouldConfirmNavigation,\n confirmNavigation,\n }),\n [\n uploads.count,\n uploads.register,\n uploads.unregister,\n unsavedWork.count,\n unsavedWork.register,\n unsavedWork.unregister,\n guardedWorkCount,\n shouldConfirmNavigation,\n confirmNavigation,\n ],\n );\n\n return (\n <LocalUploadGuardContext.Provider value={value}>\n {children}\n </LocalUploadGuardContext.Provider>\n );\n}\n\n/**\n * Low-level accessor for the guard context. Throws if used outside a\n * `LocalUploadGuardProvider`. Most consumers should use `useLocalUploadGuard`\n * (the public re-export below) instead.\n */\nexport function useLocalUploadGuardContext(): LocalUploadGuardContextValue {\n const ctx = useContext(LocalUploadGuardContext);\n if (ctx === undefined) {\n throw new Error(\n 'useLocalUploadGuard must be used within LocalUploadGuardProvider',\n );\n }\n return ctx;\n}\n\n/**\n * Optional accessor: returns the guard context, or `null` when rendered\n * outside a `LocalUploadGuardProvider`. For package components (e.g. the\n * chat composer registering an in-flight send) that must degrade gracefully\n * in consumers that don't mount the provider, instead of throwing.\n */\nexport function useOptionalLocalUploadGuard(): LocalUploadGuardContextValue | null {\n return useContext(LocalUploadGuardContext) ?? null;\n}\n\n/**\n * Public hook for the navigation and leave guard.\n *\n * Typical usage in an upload flow:\n *\n * const { registerUpload, unregisterUpload } = useLocalUploadGuard();\n * useEffect(() => {\n * if (phase === 'preparing' || phase === 'uploading') {\n * registerUpload(uploadId);\n * return () => unregisterUpload(uploadId);\n * }\n * }, [phase, uploadId, registerUpload, unregisterUpload]);\n *\n * An editor holding input uses `useUnsavedWorkGuard(hasUnsavedWork)` instead.\n */\nexport function useLocalUploadGuard(): LocalUploadGuardContextValue {\n return useLocalUploadGuardContext();\n}\n\n/**\n * Registers the calling editor's unsaved input with the leave guard while `hasUnsavedWork` is\n * true, and unregisters it when that turns false or the editor unmounts. While registered, closing\n * the tab, reloading, a full-page navigation, and every guarded in-app navigation ask first.\n * Throws outside a `LocalUploadGuardProvider`.\n *\n * Returns `release`, which unregisters at once: an editor that saves and then navigates in the\n * same handler calls it after the save, because its dirty flag clears only on the next render.\n */\nexport function useUnsavedWorkGuard(hasUnsavedWork: boolean): { release: () => void } {\n const { registerUnsavedWork, unregisterUnsavedWork } = useLocalUploadGuardContext();\n const id = useId();\n useEffect(() => {\n if (!hasUnsavedWork) return;\n registerUnsavedWork(id);\n return () => unregisterUnsavedWork(id);\n }, [hasUnsavedWork, id, registerUnsavedWork, unregisterUnsavedWork]);\n const release = useCallback(() => unregisterUnsavedWork(id), [id, unregisterUnsavedWork]);\n return useMemo(() => ({ release }), [release]);\n}\n"]}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic mutation hook to clear a terminal pendingMedia item from the tray.
|
|
3
|
-
*
|
|
4
|
-
* Pure adapter: the consumer supplies `clearFn` (typically a wrapped Firebase
|
|
5
|
-
* callable in the consuming app, or a fetch call elsewhere). The package owns the
|
|
6
|
-
* useMutation wiring and the optional `onError` toast hook; the consumer owns
|
|
7
|
-
* the network call.
|
|
8
|
-
*
|
|
9
|
-
* The provider's Firestore listener observes the `uploadTrayClearedAt` write
|
|
10
|
-
* and removes the item from the tray selector automatically — no optimistic
|
|
11
|
-
* update is needed in this hook.
|
|
12
|
-
*
|
|
13
|
-
* The returned object is the standard `useMutation` result (`mutate`,
|
|
14
|
-
* `mutateAsync`, `isPending`, …). Pass `mutationKey` to register the clear in
|
|
15
|
-
* React Query's shared `MutationCache` under a stable key, so a consumer can
|
|
16
|
-
* read per-item pending with `useMutationState` (the pendingMediaId is the
|
|
17
|
-
* mutation variables) — pending that survives the clearing row unmounting.
|
|
18
|
-
*/
|
|
19
|
-
import { type MutationKey } from '@tanstack/react-query';
|
|
20
|
-
export interface ClearUploadActivityOptions {
|
|
21
|
-
/** Network call performing the clear. Receives the pendingMediaId. */
|
|
22
|
-
clearFn: (pendingMediaId: string) => Promise<void>;
|
|
23
|
-
/** Optional error callback. Receives the error and the pendingMediaId that failed. */
|
|
24
|
-
onError?: (error: Error, pendingMediaId: string) => void;
|
|
25
|
-
/**
|
|
26
|
-
* Optional stable key for the underlying mutation, registering it in the
|
|
27
|
-
* shared `MutationCache` so pending can be read with `useMutationState`.
|
|
28
|
-
* Omitted ⇒ an unkeyed mutation (the prior behavior).
|
|
29
|
-
*/
|
|
30
|
-
mutationKey?: MutationKey;
|
|
31
|
-
}
|
|
32
|
-
export declare function useClearUploadActivity(options: ClearUploadActivityOptions): import("@tanstack/react-query").UseMutationResult<void, Error, string, unknown>;
|
|
33
|
-
//# sourceMappingURL=use-clear-upload-activity.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-clear-upload-activity.d.ts","sourceRoot":"","sources":["../../src/react/use-clear-upload-activity.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEtE,MAAM,WAAW,0BAA0B;IACzC,sEAAsE;IACtE,OAAO,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,sFAAsF;IACtF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,0BAA0B,mFASzE"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
/**
|
|
3
|
-
* Generic mutation hook to clear a terminal pendingMedia item from the tray.
|
|
4
|
-
*
|
|
5
|
-
* Pure adapter: the consumer supplies `clearFn` (typically a wrapped Firebase
|
|
6
|
-
* callable in the consuming app, or a fetch call elsewhere). The package owns the
|
|
7
|
-
* useMutation wiring and the optional `onError` toast hook; the consumer owns
|
|
8
|
-
* the network call.
|
|
9
|
-
*
|
|
10
|
-
* The provider's Firestore listener observes the `uploadTrayClearedAt` write
|
|
11
|
-
* and removes the item from the tray selector automatically — no optimistic
|
|
12
|
-
* update is needed in this hook.
|
|
13
|
-
*
|
|
14
|
-
* The returned object is the standard `useMutation` result (`mutate`,
|
|
15
|
-
* `mutateAsync`, `isPending`, …). Pass `mutationKey` to register the clear in
|
|
16
|
-
* React Query's shared `MutationCache` under a stable key, so a consumer can
|
|
17
|
-
* read per-item pending with `useMutationState` (the pendingMediaId is the
|
|
18
|
-
* mutation variables) — pending that survives the clearing row unmounting.
|
|
19
|
-
*/
|
|
20
|
-
import { useMutation } from '@tanstack/react-query';
|
|
21
|
-
export function useClearUploadActivity(options) {
|
|
22
|
-
const { clearFn, onError, mutationKey } = options;
|
|
23
|
-
return useMutation({
|
|
24
|
-
mutationKey,
|
|
25
|
-
mutationFn: clearFn,
|
|
26
|
-
onError: (error, pendingMediaId) => {
|
|
27
|
-
onError?.(error, pendingMediaId);
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=use-clear-upload-activity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-clear-upload-activity.js","sourceRoot":"","sources":["../../src/react/use-clear-upload-activity.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,WAAW,EAAoB,MAAM,uBAAuB,CAAC;AAetE,MAAM,UAAU,sBAAsB,CAAC,OAAmC;IACxE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAClD,OAAO,WAAW,CAAsB;QACtC,WAAW;QACX,UAAU,EAAE,OAAO;QACnB,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE;YACjC,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;QACnC,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["'use client';\n\n/**\n * Generic mutation hook to clear a terminal pendingMedia item from the tray.\n *\n * Pure adapter: the consumer supplies `clearFn` (typically a wrapped Firebase\n * callable in the consuming app, or a fetch call elsewhere). The package owns the\n * useMutation wiring and the optional `onError` toast hook; the consumer owns\n * the network call.\n *\n * The provider's Firestore listener observes the `uploadTrayClearedAt` write\n * and removes the item from the tray selector automatically — no optimistic\n * update is needed in this hook.\n *\n * The returned object is the standard `useMutation` result (`mutate`,\n * `mutateAsync`, `isPending`, …). Pass `mutationKey` to register the clear in\n * React Query's shared `MutationCache` under a stable key, so a consumer can\n * read per-item pending with `useMutationState` (the pendingMediaId is the\n * mutation variables) — pending that survives the clearing row unmounting.\n */\n\nimport { useMutation, type MutationKey } from '@tanstack/react-query';\n\nexport interface ClearUploadActivityOptions {\n /** Network call performing the clear. Receives the pendingMediaId. */\n clearFn: (pendingMediaId: string) => Promise<void>;\n /** Optional error callback. Receives the error and the pendingMediaId that failed. */\n onError?: (error: Error, pendingMediaId: string) => void;\n /**\n * Optional stable key for the underlying mutation, registering it in the\n * shared `MutationCache` so pending can be read with `useMutationState`.\n * Omitted ⇒ an unkeyed mutation (the prior behavior).\n */\n mutationKey?: MutationKey;\n}\n\nexport function useClearUploadActivity(options: ClearUploadActivityOptions) {\n const { clearFn, onError, mutationKey } = options;\n return useMutation<void, Error, string>({\n mutationKey,\n mutationFn: clearFn,\n onError: (error, pendingMediaId) => {\n onError?.(error, pendingMediaId);\n },\n });\n}\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type ConfirmNavigationOptions } from './local-upload-guard-provider.js';
|
|
2
|
-
/**
|
|
3
|
-
* Returns a callable that wraps a navigation action. Calling the returned
|
|
4
|
-
* function with `performNavigation` either invokes it immediately (when
|
|
5
|
-
* nothing is registered) or shows a confirmation prompt; if the user confirms,
|
|
6
|
-
* `performNavigation` is invoked. `options` passes through to
|
|
7
|
-
* `confirmNavigation()`.
|
|
8
|
-
*/
|
|
9
|
-
export declare function useGuardedNavigation(): (performNavigation: () => void, options?: ConfirmNavigationOptions) => void;
|
|
10
|
-
//# sourceMappingURL=use-guarded-navigation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-guarded-navigation.d.ts","sourceRoot":"","sources":["../../src/react/use-guarded-navigation.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAuB,KAAK,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAEtG;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,CACtC,iBAAiB,EAAE,MAAM,IAAI,EAC7B,OAAO,CAAC,EAAE,wBAAwB,KAC/B,IAAI,CAUR"}
|