@shellui/core 0.5.3 → 0.6.0-beta.1

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.
Files changed (113) hide show
  1. package/README.md +2 -0
  2. package/package.json +6 -4
  3. package/schemas/shellui.config.schema.json +104 -64
  4. package/src/app.tsx +5 -3
  5. package/src/components/ContentView.tsx +14 -23
  6. package/src/components/LoadingOverlay.tsx +1 -1
  7. package/src/components/ui/sonner.spec.tsx +138 -0
  8. package/src/components/ui/sonner.tsx +5 -5
  9. package/src/components/ui/switch.tsx +1 -1
  10. package/src/features/admin/AdminView.tsx +14 -3
  11. package/src/features/ai/AiBridge.tsx +106 -0
  12. package/src/features/ai/AiUnavailableResponder.tsx +39 -0
  13. package/src/features/ai/README.md +52 -0
  14. package/src/features/ai/ShellAiHost.tsx +24 -0
  15. package/src/features/ai/adapters/ollama.ts +170 -0
  16. package/src/features/ai/adapters/promptApi.spec.ts +135 -0
  17. package/src/features/ai/adapters/promptApi.ts +222 -0
  18. package/src/features/ai/adapters/webllm.experimental.spec.ts +69 -0
  19. package/src/features/ai/adapters/webllm.spec.ts +527 -0
  20. package/src/features/ai/adapters/webllm.ts +142 -0
  21. package/src/features/ai/aiDisabledResponses.spec.ts +29 -0
  22. package/src/features/ai/aiDisabledResponses.ts +32 -0
  23. package/src/features/ai/browserInstallStore.spec.ts +58 -0
  24. package/src/features/ai/browserInstallStore.ts +76 -0
  25. package/src/features/ai/catalog.ts +31 -0
  26. package/src/features/ai/createRegistry.ts +83 -0
  27. package/src/features/ai/developHarness.spec.ts +108 -0
  28. package/src/features/ai/developHarness.ts +161 -0
  29. package/src/features/ai/engine/formatAiError.spec.ts +85 -0
  30. package/src/features/ai/engine/formatAiError.ts +132 -0
  31. package/src/features/ai/engine/mapInitProgress.ts +9 -0
  32. package/src/features/ai/engine/normalizeWebLlmModule.spec.ts +47 -0
  33. package/src/features/ai/engine/vite-worker.d.ts +6 -0
  34. package/src/features/ai/engine/webllm.worker.ts +51 -0
  35. package/src/features/ai/engine/webllmEngine.ts +1011 -0
  36. package/src/features/ai/handleRequest.spec.ts +288 -0
  37. package/src/features/ai/handleRequest.ts +325 -0
  38. package/src/features/ai/isAiFeatureEnabled.spec.ts +15 -0
  39. package/src/features/ai/isAiFeatureEnabled.ts +9 -0
  40. package/src/features/ai/promptApiSupport.spec.ts +64 -0
  41. package/src/features/ai/promptApiSupport.ts +117 -0
  42. package/src/features/ai/registry.spec.ts +100 -0
  43. package/src/features/ai/registry.ts +131 -0
  44. package/src/features/ai/status.spec.ts +92 -0
  45. package/src/features/ai/status.ts +85 -0
  46. package/src/features/ai/types.ts +100 -0
  47. package/src/features/ai/webLlmBrowserSupport.spec.ts +86 -0
  48. package/src/features/ai/webLlmBrowserSupport.ts +92 -0
  49. package/src/features/alertDialog/DialogContext.tsx +3 -1
  50. package/src/features/auth/AuthProvider.tsx +254 -39
  51. package/src/features/auth/backends/index.ts +8 -0
  52. package/src/features/auth/backends/shellui.spec.ts +201 -0
  53. package/src/features/auth/backends/shellui.ts +93 -16
  54. package/src/features/auth/backends/supabase.ts +8 -0
  55. package/src/features/auth/backends/types.ts +16 -1
  56. package/src/features/auth/components/LoginButton.tsx +26 -2
  57. package/src/features/auth/components/LoginView.tsx +114 -133
  58. package/src/features/auth/components/SessionLoadingView.tsx +21 -0
  59. package/src/features/auth/hooks/useAuth.tsx +12 -0
  60. package/src/features/auth/shellAccountRequests.ts +76 -0
  61. package/src/features/auth/utils/authRequestError.ts +4 -1
  62. package/src/features/auth/utils/authSessionPersistence.spec.ts +11 -0
  63. package/src/features/auth/utils/authSessionPersistence.ts +12 -0
  64. package/src/features/auth/utils/index.ts +4 -0
  65. package/src/features/auth/utils/resolveLoginSettings.spec.ts +33 -0
  66. package/src/features/auth/utils/resolveLoginSettings.ts +33 -0
  67. package/src/features/auth/utils/shareInFlight.spec.ts +41 -0
  68. package/src/features/auth/utils/shareInFlight.ts +14 -0
  69. package/src/features/config/ConfigProvider.ts +9 -1
  70. package/src/features/config/types.ts +43 -0
  71. package/src/features/layouts/appbar/AppBarLayout.tsx +8 -3
  72. package/src/features/layouts/filterNavigationForAuthState.spec.ts +41 -0
  73. package/src/features/layouts/floating/FloatingLayout.tsx +9 -4
  74. package/src/features/layouts/floating/layoutChromeStore.ts +3 -1
  75. package/src/features/layouts/sidebar/SidebarLayout.tsx +9 -4
  76. package/src/features/layouts/utils.ts +6 -2
  77. package/src/features/layouts/windows/WindowsLayout.tsx +8 -3
  78. package/src/features/messaging/MessagingSecurityBootstrap.tsx +6 -6
  79. package/src/features/security/trustedFrames.spec.ts +65 -0
  80. package/src/features/security/trustedFrames.ts +52 -0
  81. package/src/features/settings/SettingsIcons.tsx +17 -0
  82. package/src/features/settings/SettingsProvider.tsx +29 -4
  83. package/src/features/settings/SettingsRoutes.tsx +8 -0
  84. package/src/features/settings/SettingsView.tsx +21 -4
  85. package/src/features/settings/components/Ai.tsx +830 -0
  86. package/src/features/settings/components/Develop.tsx +4 -0
  87. package/src/features/settings/components/Storage.tsx +197 -32
  88. package/src/features/settings/components/UserSettingsPanel.tsx +160 -12
  89. package/src/features/settings/components/createUserSettingsRoute.tsx +4 -0
  90. package/src/features/settings/components/develop/AiTestTools.tsx +231 -0
  91. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +54 -1
  92. package/src/features/settings/utils/buildSettingsForPropagation.ts +15 -1
  93. package/src/features/settings/utils/mergePreferencesIntoSettings.spec.ts +6 -0
  94. package/src/features/settings/utils/shouldShowStorageSettings.spec.ts +49 -0
  95. package/src/features/settings/utils/shouldShowStorageSettings.ts +19 -0
  96. package/src/features/storage/uploads/UploadToastCard.tsx +2 -442
  97. package/src/features/storage/uploads/UploadToaster.tsx +2 -44
  98. package/src/features/storage/uploads/uploadQueue.ts +128 -308
  99. package/src/features/storage/uploads/useUploadQueue.ts +7 -3
  100. package/src/features/transfers/TransferToastCard.tsx +467 -0
  101. package/src/features/transfers/TransferToaster.tsx +50 -0
  102. package/src/features/transfers/index.ts +33 -0
  103. package/src/features/transfers/transferQueue.spec.ts +97 -0
  104. package/src/features/transfers/transferQueue.ts +442 -0
  105. package/src/features/transfers/types.ts +38 -0
  106. package/src/features/transfers/useTransferQueue.ts +30 -0
  107. package/src/i18n/translations/en/common.json +46 -2
  108. package/src/i18n/translations/en/settings.json +151 -2
  109. package/src/i18n/translations/fr/common.json +46 -2
  110. package/src/i18n/translations/fr/settings.json +151 -2
  111. package/src/index.css +57 -4
  112. package/src/index.ts +1 -0
  113. package/src/routes/components/NavigationItemRoute.tsx +2 -1
@@ -1,12 +1,38 @@
1
- import { postShellMessage } from '@shellui/sdk';
1
+ /**
2
+ * Upload-shaped façade over the shared transfer queue.
3
+ * Prefer `features/transfers` for new code; these helpers keep storage callers stable.
4
+ */
5
+ import type { TransferItem, TransferQueueSummary } from '../../transfers/types.js';
6
+ import {
7
+ addTransfer,
8
+ closeTransferToaster,
9
+ completeTransfer,
10
+ dismissFinishedTransfers,
11
+ failTransfer,
12
+ getItemPercent as getTransferItemPercent,
13
+ getTransferQueue,
14
+ getTransferSummary,
15
+ interruptAllTransfers,
16
+ interruptTransfer,
17
+ isTransferSignalAborted,
18
+ isTransferToastExpanded,
19
+ markTransferCancelled,
20
+ removeTransfer,
21
+ requestUploadToastDemo as requestDemo,
22
+ resetTransferQueue,
23
+ setTransferProgress,
24
+ setTransferToastExpanded,
25
+ startUploadToastDemo as startDemo,
26
+ subscribeTransferQueue,
27
+ TRANSFER_TOAST_AUTO_DISMISS_MS,
28
+ TRANSFER_TOAST_ID,
29
+ UPLOAD_TOAST_DEMO_MESSAGE as DEMO_MESSAGE,
30
+ } from '../../transfers/transferQueue.js';
2
31
  import type { UploadItem, UploadItemStatus, UploadQueueSummary } from './types';
3
32
 
4
- export const UPLOAD_TOAST_ID = 'shellui-upload-progress';
5
- export const UPLOAD_TOAST_DEMO_MESSAGE = 'SHELLUI_UPLOAD_TOAST_DEMO';
6
- /** Brief pause so the success state is visible before the toaster hides. */
7
- export const UPLOAD_TOAST_AUTO_DISMISS_MS = 2500;
8
-
9
- type UploadListener = () => void;
33
+ export const UPLOAD_TOAST_ID = TRANSFER_TOAST_ID;
34
+ export const UPLOAD_TOAST_DEMO_MESSAGE = DEMO_MESSAGE;
35
+ export const UPLOAD_TOAST_AUTO_DISMISS_MS = TRANSFER_TOAST_AUTO_DISMISS_MS;
10
36
 
11
37
  type AddUploadInput = {
12
38
  id?: string;
@@ -17,125 +43,94 @@ type AddUploadInput = {
17
43
  demo?: boolean;
18
44
  };
19
45
 
20
- const listeners = new Set<UploadListener>();
21
- const abortControllers = new Map<string, AbortController>();
22
- const demoTimers = new Map<string, ReturnType<typeof setInterval>>();
23
- const demoStartTimeouts: ReturnType<typeof setTimeout>[] = [];
24
-
25
- let items: UploadItem[] = [];
26
- let expanded = false;
27
- let autoDismissTimeout: ReturnType<typeof setTimeout> | null = null;
28
-
29
- function clearAutoDismissTimeout(): void {
30
- if (autoDismissTimeout === null) return;
31
- clearTimeout(autoDismissTimeout);
32
- autoDismissTimeout = null;
33
- }
34
-
35
- /**
36
- * Hide the toaster a few seconds after every upload finishes successfully.
37
- * Errors and in-progress uploads keep the panel open; cancelled-only queues stay too.
38
- */
39
- function scheduleAutoDismissIfNeeded(): void {
40
- clearAutoDismissTimeout();
41
- const summary = getUploadSummary();
42
- if (summary.uploading > 0 || summary.error > 0 || summary.success === 0) {
43
- return;
44
- }
45
- autoDismissTimeout = setTimeout(() => {
46
- autoDismissTimeout = null;
47
- const current = getUploadSummary();
48
- if (current.uploading > 0 || current.error > 0 || current.success === 0) {
49
- return;
50
- }
51
- resetUploadQueue();
52
- }, UPLOAD_TOAST_AUTO_DISMISS_MS);
53
- }
54
-
55
- function emit(): void {
56
- listeners.forEach((listener) => listener());
57
- }
58
-
59
- function createId(): string {
60
- if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
61
- return crypto.randomUUID();
62
- }
63
- return `upload-${Date.now()}-${Math.random().toString(16).slice(2)}`;
46
+ function toUploadStatus(status: TransferItem['status']): UploadItemStatus {
47
+ return status === 'active' ? 'uploading' : status;
64
48
  }
65
49
 
66
- function patchItem(id: string, patch: Partial<UploadItem>): void {
67
- const index = items.findIndex((item) => item.id === id);
68
- if (index === -1) return;
69
- items = items.map((item) => (item.id === id ? { ...item, ...patch } : item));
70
- emit();
50
+ function toUploadItem(item: TransferItem): UploadItem {
51
+ return {
52
+ id: item.id,
53
+ name: item.name,
54
+ path: item.detail ?? item.meta?.path ?? '',
55
+ bucket: item.meta?.bucket ?? '',
56
+ size: item.size,
57
+ bytesUploaded: item.bytesTransferred,
58
+ status: toUploadStatus(item.status),
59
+ error: item.error,
60
+ demo: item.demo,
61
+ };
71
62
  }
72
63
 
73
- function clearDemoStartTimeouts(): void {
74
- demoStartTimeouts.forEach((timeout) => clearTimeout(timeout));
75
- demoStartTimeouts.length = 0;
64
+ function toUploadSummary(summary: TransferQueueSummary): UploadQueueSummary {
65
+ return {
66
+ total: summary.total,
67
+ uploading: summary.active,
68
+ success: summary.success,
69
+ error: summary.error,
70
+ cancelled: summary.cancelled,
71
+ bytesUploaded: summary.bytesTransferred,
72
+ bytesTotal: summary.bytesTotal,
73
+ percent: summary.percent,
74
+ };
76
75
  }
77
76
 
78
- function clearDemoTimer(id: string): void {
79
- const timer = demoTimers.get(id);
80
- if (timer !== undefined) {
81
- clearInterval(timer);
82
- demoTimers.delete(id);
83
- }
77
+ export function subscribeUploadQueue(listener: () => void): () => void {
78
+ return subscribeTransferQueue(listener);
84
79
  }
85
80
 
86
- export function subscribeUploadQueue(listener: UploadListener): () => void {
87
- listeners.add(listener);
88
- return () => {
89
- listeners.delete(listener);
90
- };
81
+ export function getUploadQueue(): UploadItem[] {
82
+ return getTransferQueue()
83
+ .filter((item) => item.kind === 'upload')
84
+ .map(toUploadItem);
91
85
  }
92
86
 
93
- export function getUploadQueue(): UploadItem[] {
94
- return items;
87
+ /** All transfer items as upload-shaped rows (tests / legacy callers that expect the full queue). */
88
+ export function getUploadQueueIncludingDownloads(): UploadItem[] {
89
+ return getTransferQueue().map(toUploadItem);
95
90
  }
96
91
 
97
92
  export function isUploadToastExpanded(): boolean {
98
- return expanded;
93
+ return isTransferToastExpanded();
99
94
  }
100
95
 
101
96
  export function setUploadToastExpanded(value: boolean): void {
102
- if (expanded === value) return;
103
- expanded = value;
104
- emit();
105
- }
106
-
107
- export function getUploadSummary(list: UploadItem[] = items): UploadQueueSummary {
108
- const uploading = list.filter((item) => item.status === 'uploading').length;
109
- const success = list.filter((item) => item.status === 'success').length;
110
- const error = list.filter((item) => item.status === 'error').length;
111
- const cancelled = list.filter((item) => item.status === 'cancelled').length;
112
- const bytesUploaded = list.reduce((sum, item) => {
113
- if (item.status === 'success') return sum + item.size;
114
- if (item.status === 'uploading') {
115
- return sum + Math.min(item.bytesUploaded, item.size || item.bytesUploaded);
116
- }
117
- return sum;
118
- }, 0);
119
- const bytesTotal = list.reduce((sum, item) => sum + item.size, 0);
120
- const percent =
121
- bytesTotal > 0
122
- ? Math.min(100, Math.max(0, Math.round((bytesUploaded / bytesTotal) * 100)))
123
- : uploading > 0
124
- ? 0
125
- : list.length > 0
126
- ? 100
127
- : 0;
128
-
129
- return {
130
- total: list.length,
131
- uploading,
132
- success,
133
- error,
134
- cancelled,
135
- bytesUploaded,
136
- bytesTotal,
137
- percent,
138
- };
97
+ setTransferToastExpanded(value);
98
+ }
99
+
100
+ export function getUploadSummary(list?: UploadItem[]): UploadQueueSummary {
101
+ if (list) {
102
+ const active = list.filter((item) => item.status === 'uploading').length;
103
+ const success = list.filter((item) => item.status === 'success').length;
104
+ const error = list.filter((item) => item.status === 'error').length;
105
+ const cancelled = list.filter((item) => item.status === 'cancelled').length;
106
+ const bytesUploaded = list.reduce((sum, item) => {
107
+ if (item.status === 'success') return sum + item.size;
108
+ if (item.status === 'uploading') {
109
+ return sum + Math.min(item.bytesUploaded, item.size || item.bytesUploaded);
110
+ }
111
+ return sum;
112
+ }, 0);
113
+ const bytesTotal = list.reduce((sum, item) => sum + item.size, 0);
114
+ const percent =
115
+ bytesTotal > 0
116
+ ? Math.min(100, Math.max(0, Math.round((bytesUploaded / bytesTotal) * 100)))
117
+ : active > 0
118
+ ? 0
119
+ : list.length > 0
120
+ ? 100
121
+ : 0;
122
+ return {
123
+ total: list.length,
124
+ uploading: active,
125
+ success,
126
+ error,
127
+ cancelled,
128
+ bytesUploaded,
129
+ bytesTotal,
130
+ percent,
131
+ };
132
+ }
133
+ return toUploadSummary(getTransferSummary());
139
134
  }
140
135
 
141
136
  export function getItemPercent(item: UploadItem): number {
@@ -145,243 +140,68 @@ export function getItemPercent(item: UploadItem): number {
145
140
  }
146
141
 
147
142
  export function addUpload(input: AddUploadInput): { id: string; signal: AbortSignal } {
148
- clearAutoDismissTimeout();
149
- const id = input.id ?? createId();
150
- const existing = abortControllers.get(id);
151
- existing?.abort();
152
- clearDemoTimer(id);
153
-
154
- const controller = new AbortController();
155
- abortControllers.set(id, controller);
156
-
157
- const next: UploadItem = {
158
- id,
143
+ return addTransfer({
144
+ id: input.id,
145
+ kind: 'upload',
159
146
  name: input.name,
160
- path: input.path,
161
- bucket: input.bucket,
162
- size: Math.max(0, input.size),
163
- bytesUploaded: 0,
164
- status: 'uploading',
147
+ detail: input.path,
148
+ meta: { path: input.path, bucket: input.bucket },
149
+ size: input.size,
165
150
  demo: input.demo,
166
- };
167
-
168
- items = [...items.filter((item) => item.id !== id), next];
169
- emit();
170
- return { id, signal: controller.signal };
151
+ });
171
152
  }
172
153
 
173
154
  export function setUploadProgress(id: string, loaded: number, total?: number): void {
174
- const item = items.find((entry) => entry.id === id);
175
- if (!item || item.status !== 'uploading') return;
176
- const size = total && total > 0 ? total : item.size;
177
- patchItem(id, {
178
- bytesUploaded: Math.max(0, loaded),
179
- size: size > 0 ? size : item.size,
180
- });
155
+ setTransferProgress(id, { loaded, total });
181
156
  }
182
157
 
183
158
  export function completeUpload(id: string): void {
184
- const item = items.find((entry) => entry.id === id);
185
- if (!item || item.status !== 'uploading') return;
186
- abortControllers.delete(id);
187
- clearDemoTimer(id);
188
- patchItem(id, {
189
- status: 'success',
190
- bytesUploaded: item.size || item.bytesUploaded,
191
- error: undefined,
192
- });
193
- scheduleAutoDismissIfNeeded();
159
+ completeTransfer(id);
194
160
  }
195
161
 
196
162
  export function failUpload(id: string, message: string): void {
197
- const item = items.find((entry) => entry.id === id);
198
- if (!item || item.status !== 'uploading') return;
199
- abortControllers.delete(id);
200
- clearDemoTimer(id);
201
- patchItem(id, { status: 'error', error: message });
202
- clearAutoDismissTimeout();
163
+ failTransfer(id, message);
203
164
  }
204
165
 
205
166
  export function markUploadCancelled(id: string): void {
206
- if (!items.some((item) => item.id === id)) return;
207
- abortControllers.delete(id);
208
- clearDemoTimer(id);
209
- patchItem(id, { status: 'cancelled' });
210
- scheduleAutoDismissIfNeeded();
167
+ markTransferCancelled(id);
211
168
  }
212
169
 
213
- /** Abort an in-progress upload and keep it visible as cancelled. */
214
170
  export function interruptUpload(id: string): void {
215
- const item = items.find((entry) => entry.id === id);
216
- if (!item || item.status !== 'uploading') return;
217
- abortControllers.get(id)?.abort();
218
- markUploadCancelled(id);
171
+ interruptTransfer(id);
219
172
  }
220
173
 
221
- /** Remove a finished (or cancelled) item from the toaster. */
222
174
  export function removeUpload(id: string): void {
223
- const item = items.find((entry) => entry.id === id);
224
- if (!item) return;
225
- if (item.status === 'uploading') {
226
- abortControllers.get(id)?.abort();
227
- }
228
- abortControllers.delete(id);
229
- clearDemoTimer(id);
230
- const next = items.filter((entry) => entry.id !== id);
231
- if (next.length === items.length) return;
232
- items = next;
233
- if (items.length === 0) {
234
- expanded = false;
235
- clearAutoDismissTimeout();
236
- }
237
- emit();
238
- if (items.length > 0) {
239
- scheduleAutoDismissIfNeeded();
240
- }
175
+ removeTransfer(id);
241
176
  }
242
177
 
243
178
  export function dismissFinishedUploads(): void {
244
- clearAutoDismissTimeout();
245
- const keep = items.filter((item) => item.status === 'uploading');
246
- items.forEach((item) => {
247
- if (item.status === 'uploading') return;
248
- abortControllers.delete(item.id);
249
- clearDemoTimer(item.id);
250
- });
251
- if (keep.length === items.length) return;
252
- items = keep;
253
- if (items.length === 0) expanded = false;
254
- emit();
179
+ dismissFinishedTransfers();
255
180
  }
256
181
 
257
182
  export function interruptAllUploads(): void {
258
- const uploading = items.filter((item) => item.status === 'uploading');
259
- if (uploading.length === 0) return;
260
- uploading.forEach((item) => {
261
- abortControllers.get(item.id)?.abort();
262
- markUploadCancelled(item.id);
263
- });
183
+ interruptAllTransfers();
264
184
  }
265
185
 
266
- /** Close the toaster: cancel leftover uploads and hide the panel. */
267
186
  export function closeUploadToaster(): void {
268
- resetUploadQueue();
187
+ closeTransferToaster();
269
188
  }
270
189
 
271
190
  export function resetUploadQueue(): void {
272
- clearAutoDismissTimeout();
273
- abortControllers.forEach((controller) => controller.abort());
274
- abortControllers.clear();
275
- demoTimers.forEach((timer) => clearInterval(timer));
276
- demoTimers.clear();
277
- clearDemoStartTimeouts();
278
- items = [];
279
- expanded = false;
280
- emit();
281
- }
282
-
283
- const DEMO_FILES: Array<{
284
- name: string;
285
- path: string;
286
- bucket: string;
287
- size: number;
288
- durationMs: number;
289
- outcome: Extract<UploadItemStatus, 'success' | 'error'>;
290
- error?: string;
291
- }> = [
292
- {
293
- name: 'quarterly-report.pdf',
294
- path: 'docs/quarterly-report.pdf',
295
- bucket: 'company',
296
- size: 2_450_000,
297
- durationMs: 3600,
298
- outcome: 'success',
299
- },
300
- {
301
- name: 'team-offsite.jpg',
302
- path: 'photos/team-offsite.jpg',
303
- bucket: 'company',
304
- size: 6_200_000,
305
- durationMs: 7200,
306
- outcome: 'success',
307
- },
308
- {
309
- name: 'budget.xlsx',
310
- path: 'docs/budget.xlsx',
311
- bucket: 'company',
312
- size: 840_000,
313
- durationMs: 2400,
314
- outcome: 'error',
315
- error: 'Quota exceeded',
316
- },
317
- {
318
- name: 'archive.zip',
319
- path: 'backup/archive.zip',
320
- bucket: 'company',
321
- size: 18_500_000,
322
- durationMs: 9800,
323
- outcome: 'success',
324
- },
325
- ];
326
-
327
- function clearDemoUploads(): void {
328
- clearDemoStartTimeouts();
329
- items
330
- .filter((item) => item.demo)
331
- .forEach((item) => {
332
- abortControllers.get(item.id)?.abort();
333
- abortControllers.delete(item.id);
334
- clearDemoTimer(item.id);
335
- });
336
- items = items.filter((item) => !item.demo);
337
- if (items.length === 0) expanded = false;
338
- emit();
191
+ resetTransferQueue();
339
192
  }
340
193
 
341
- /** Ask the root shell to show the demo toaster (no-op network). Safe to call from iframes. */
342
194
  export function requestUploadToastDemo(): void {
343
- if (typeof window === 'undefined') return;
344
- const message = { type: UPLOAD_TOAST_DEMO_MESSAGE, payload: {} };
345
- postShellMessage(message);
195
+ requestDemo();
346
196
  }
347
197
 
348
- /** Simulated uploads for the Develop panel — no network requests. */
349
198
  export function startUploadToastDemo(): void {
350
- clearDemoUploads();
351
- expanded = false;
352
-
353
- DEMO_FILES.forEach((spec, index) => {
354
- const timeout = setTimeout(() => {
355
- const { id, signal } = addUpload({
356
- name: spec.name,
357
- path: spec.path,
358
- bucket: spec.bucket,
359
- size: spec.size,
360
- demo: true,
361
- });
362
- const startedAt = Date.now();
363
- const timer = setInterval(() => {
364
- if (signal.aborted) {
365
- clearDemoTimer(id);
366
- return;
367
- }
368
- const ratio = Math.min(1, (Date.now() - startedAt) / spec.durationMs);
369
- setUploadProgress(id, Math.round(spec.size * ratio), spec.size);
370
- if (ratio < 1) return;
371
- clearDemoTimer(id);
372
- if (spec.outcome === 'error') {
373
- failUpload(id, spec.error || 'Upload failed');
374
- return;
375
- }
376
- completeUpload(id);
377
- }, 80);
378
- demoTimers.set(id, timer);
379
- }, index * 180);
380
- demoStartTimeouts.push(timeout);
381
- });
199
+ startDemo();
382
200
  }
383
201
 
384
202
  export function isUploadSignalAborted(id: string, signal?: AbortSignal): boolean {
385
- const item = items.find((entry) => entry.id === id);
386
- return Boolean(signal?.aborted) || !item || item.status === 'cancelled';
203
+ return isTransferSignalAborted(id, signal);
387
204
  }
205
+
206
+ /** Re-export for callers that still import percent helpers from this module. */
207
+ export { getTransferItemPercent };
@@ -1,23 +1,27 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import {
3
- getUploadQueue,
3
+ getUploadQueueIncludingDownloads,
4
4
  getUploadSummary,
5
5
  isUploadToastExpanded,
6
6
  subscribeUploadQueue,
7
7
  } from './uploadQueue';
8
8
  import type { UploadItem, UploadQueueSummary } from './types';
9
9
 
10
+ /**
11
+ * Subscribe to the shared transfer queue (uploads + downloads) with upload-shaped items.
12
+ * Prefer `useTransferQueue` for new UI.
13
+ */
10
14
  export function useUploadQueue(): {
11
15
  items: UploadItem[];
12
16
  summary: UploadQueueSummary;
13
17
  expanded: boolean;
14
18
  } {
15
- const [items, setItems] = useState<UploadItem[]>(getUploadQueue);
19
+ const [items, setItems] = useState<UploadItem[]>(getUploadQueueIncludingDownloads);
16
20
  const [expanded, setExpanded] = useState(isUploadToastExpanded);
17
21
 
18
22
  useEffect(() => {
19
23
  return subscribeUploadQueue(() => {
20
- setItems(getUploadQueue());
24
+ setItems(getUploadQueueIncludingDownloads());
21
25
  setExpanded(isUploadToastExpanded());
22
26
  });
23
27
  }, []);