@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.
- package/README.md +2 -0
- package/package.json +6 -4
- package/schemas/shellui.config.schema.json +104 -64
- package/src/app.tsx +5 -3
- package/src/components/ContentView.tsx +14 -23
- package/src/components/LoadingOverlay.tsx +1 -1
- package/src/components/ui/sonner.spec.tsx +138 -0
- package/src/components/ui/sonner.tsx +5 -5
- package/src/components/ui/switch.tsx +1 -1
- package/src/features/admin/AdminView.tsx +14 -3
- package/src/features/ai/AiBridge.tsx +106 -0
- package/src/features/ai/AiUnavailableResponder.tsx +39 -0
- package/src/features/ai/README.md +52 -0
- package/src/features/ai/ShellAiHost.tsx +24 -0
- package/src/features/ai/adapters/ollama.ts +170 -0
- package/src/features/ai/adapters/promptApi.spec.ts +135 -0
- package/src/features/ai/adapters/promptApi.ts +222 -0
- package/src/features/ai/adapters/webllm.experimental.spec.ts +69 -0
- package/src/features/ai/adapters/webllm.spec.ts +527 -0
- package/src/features/ai/adapters/webllm.ts +142 -0
- package/src/features/ai/aiDisabledResponses.spec.ts +29 -0
- package/src/features/ai/aiDisabledResponses.ts +32 -0
- package/src/features/ai/browserInstallStore.spec.ts +58 -0
- package/src/features/ai/browserInstallStore.ts +76 -0
- package/src/features/ai/catalog.ts +31 -0
- package/src/features/ai/createRegistry.ts +83 -0
- package/src/features/ai/developHarness.spec.ts +108 -0
- package/src/features/ai/developHarness.ts +161 -0
- package/src/features/ai/engine/formatAiError.spec.ts +85 -0
- package/src/features/ai/engine/formatAiError.ts +132 -0
- package/src/features/ai/engine/mapInitProgress.ts +9 -0
- package/src/features/ai/engine/normalizeWebLlmModule.spec.ts +47 -0
- package/src/features/ai/engine/vite-worker.d.ts +6 -0
- package/src/features/ai/engine/webllm.worker.ts +51 -0
- package/src/features/ai/engine/webllmEngine.ts +1011 -0
- package/src/features/ai/handleRequest.spec.ts +288 -0
- package/src/features/ai/handleRequest.ts +325 -0
- package/src/features/ai/isAiFeatureEnabled.spec.ts +15 -0
- package/src/features/ai/isAiFeatureEnabled.ts +9 -0
- package/src/features/ai/promptApiSupport.spec.ts +64 -0
- package/src/features/ai/promptApiSupport.ts +117 -0
- package/src/features/ai/registry.spec.ts +100 -0
- package/src/features/ai/registry.ts +131 -0
- package/src/features/ai/status.spec.ts +92 -0
- package/src/features/ai/status.ts +85 -0
- package/src/features/ai/types.ts +100 -0
- package/src/features/ai/webLlmBrowserSupport.spec.ts +86 -0
- package/src/features/ai/webLlmBrowserSupport.ts +92 -0
- package/src/features/alertDialog/DialogContext.tsx +3 -1
- package/src/features/auth/AuthProvider.tsx +254 -39
- package/src/features/auth/backends/index.ts +8 -0
- package/src/features/auth/backends/shellui.spec.ts +201 -0
- package/src/features/auth/backends/shellui.ts +93 -16
- package/src/features/auth/backends/supabase.ts +8 -0
- package/src/features/auth/backends/types.ts +16 -1
- package/src/features/auth/components/LoginButton.tsx +26 -2
- package/src/features/auth/components/LoginView.tsx +114 -133
- package/src/features/auth/components/SessionLoadingView.tsx +21 -0
- package/src/features/auth/hooks/useAuth.tsx +12 -0
- package/src/features/auth/shellAccountRequests.ts +76 -0
- package/src/features/auth/utils/authRequestError.ts +4 -1
- package/src/features/auth/utils/authSessionPersistence.spec.ts +11 -0
- package/src/features/auth/utils/authSessionPersistence.ts +12 -0
- package/src/features/auth/utils/index.ts +4 -0
- package/src/features/auth/utils/resolveLoginSettings.spec.ts +33 -0
- package/src/features/auth/utils/resolveLoginSettings.ts +33 -0
- package/src/features/auth/utils/shareInFlight.spec.ts +41 -0
- package/src/features/auth/utils/shareInFlight.ts +14 -0
- package/src/features/config/ConfigProvider.ts +9 -1
- package/src/features/config/types.ts +43 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +8 -3
- package/src/features/layouts/filterNavigationForAuthState.spec.ts +41 -0
- package/src/features/layouts/floating/FloatingLayout.tsx +9 -4
- package/src/features/layouts/floating/layoutChromeStore.ts +3 -1
- package/src/features/layouts/sidebar/SidebarLayout.tsx +9 -4
- package/src/features/layouts/utils.ts +6 -2
- package/src/features/layouts/windows/WindowsLayout.tsx +8 -3
- package/src/features/messaging/MessagingSecurityBootstrap.tsx +6 -6
- package/src/features/security/trustedFrames.spec.ts +65 -0
- package/src/features/security/trustedFrames.ts +52 -0
- package/src/features/settings/SettingsIcons.tsx +17 -0
- package/src/features/settings/SettingsProvider.tsx +29 -4
- package/src/features/settings/SettingsRoutes.tsx +8 -0
- package/src/features/settings/SettingsView.tsx +21 -4
- package/src/features/settings/components/Ai.tsx +830 -0
- package/src/features/settings/components/Develop.tsx +4 -0
- package/src/features/settings/components/Storage.tsx +197 -32
- package/src/features/settings/components/UserSettingsPanel.tsx +160 -12
- package/src/features/settings/components/createUserSettingsRoute.tsx +4 -0
- package/src/features/settings/components/develop/AiTestTools.tsx +231 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +54 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +15 -1
- package/src/features/settings/utils/mergePreferencesIntoSettings.spec.ts +6 -0
- package/src/features/settings/utils/shouldShowStorageSettings.spec.ts +49 -0
- package/src/features/settings/utils/shouldShowStorageSettings.ts +19 -0
- package/src/features/storage/uploads/UploadToastCard.tsx +2 -442
- package/src/features/storage/uploads/UploadToaster.tsx +2 -44
- package/src/features/storage/uploads/uploadQueue.ts +128 -308
- package/src/features/storage/uploads/useUploadQueue.ts +7 -3
- package/src/features/transfers/TransferToastCard.tsx +467 -0
- package/src/features/transfers/TransferToaster.tsx +50 -0
- package/src/features/transfers/index.ts +33 -0
- package/src/features/transfers/transferQueue.spec.ts +97 -0
- package/src/features/transfers/transferQueue.ts +442 -0
- package/src/features/transfers/types.ts +38 -0
- package/src/features/transfers/useTransferQueue.ts +30 -0
- package/src/i18n/translations/en/common.json +46 -2
- package/src/i18n/translations/en/settings.json +151 -2
- package/src/i18n/translations/fr/common.json +46 -2
- package/src/i18n/translations/fr/settings.json +151 -2
- package/src/index.css +57 -4
- package/src/index.ts +1 -0
- package/src/routes/components/NavigationItemRoute.tsx +2 -1
|
@@ -1,12 +1,38 @@
|
|
|
1
|
-
|
|
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 =
|
|
5
|
-
export const UPLOAD_TOAST_DEMO_MESSAGE =
|
|
6
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
79
|
-
|
|
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
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
};
|
|
81
|
+
export function getUploadQueue(): UploadItem[] {
|
|
82
|
+
return getTransferQueue()
|
|
83
|
+
.filter((item) => item.kind === 'upload')
|
|
84
|
+
.map(toUploadItem);
|
|
91
85
|
}
|
|
92
86
|
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
93
|
+
return isTransferToastExpanded();
|
|
99
94
|
}
|
|
100
95
|
|
|
101
96
|
export function setUploadToastExpanded(value: boolean): void {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
161
|
-
bucket: input.bucket,
|
|
162
|
-
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
187
|
+
closeTransferToaster();
|
|
269
188
|
}
|
|
270
189
|
|
|
271
190
|
export function resetUploadQueue(): void {
|
|
272
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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[]>(
|
|
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(
|
|
24
|
+
setItems(getUploadQueueIncludingDownloads());
|
|
21
25
|
setExpanded(isUploadToastExpanded());
|
|
22
26
|
});
|
|
23
27
|
}, []);
|