@uploadista/react 0.0.3 → 0.0.6
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/components/index.d.ts +3 -0
- package/dist/components/index.js +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -0
- package/dist/upload-zone-Cqvu-rTY.js +2 -0
- package/dist/upload-zone-Cqvu-rTY.js.map +1 -0
- package/dist/uploadista-provider-D8GQ2GhF.d.ts +1240 -0
- package/dist/uploadista-provider-D8GQ2GhF.d.ts.map +1 -0
- package/dist/use-upload-DpDLlhUA.js +2 -0
- package/dist/use-upload-DpDLlhUA.js.map +1 -0
- package/dist/use-upload-metrics-9Q-8Hij9.d.ts +382 -0
- package/dist/use-upload-metrics-9Q-8Hij9.d.ts.map +1 -0
- package/dist/use-upload-metrics-Dhx_po4K.js +2 -0
- package/dist/use-upload-metrics-Dhx_po4K.js.map +1 -0
- package/dist/use-uploadista-client-CeFo4wuV.d.ts +772 -0
- package/dist/use-uploadista-client-CeFo4wuV.d.ts.map +1 -0
- package/package.json +19 -9
- package/src/components/index.tsx +43 -0
- package/src/hooks/index.ts +49 -0
- package/tsdown.config.ts +14 -0
- package/.turbo/turbo-check.log +0 -89
|
@@ -0,0 +1,772 @@
|
|
|
1
|
+
import { BrowserUploadInput, ChunkMetrics, FlowUploadOptions, PerformanceInsights, UploadSessionMetrics, UploadistaClientOptions, createUploadistaClient } from "@uploadista/client-browser";
|
|
2
|
+
import { UploadFile } from "@uploadista/core/types";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/use-drag-drop.d.ts
|
|
5
|
+
interface DragDropOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Accept specific file types (MIME types or file extensions)
|
|
8
|
+
*/
|
|
9
|
+
accept?: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Maximum number of files allowed
|
|
12
|
+
*/
|
|
13
|
+
maxFiles?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Maximum file size in bytes
|
|
16
|
+
*/
|
|
17
|
+
maxFileSize?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to allow multiple files
|
|
20
|
+
*/
|
|
21
|
+
multiple?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Custom validation function for files
|
|
24
|
+
*/
|
|
25
|
+
validator?: (files: File[]) => string[] | null;
|
|
26
|
+
/**
|
|
27
|
+
* Called when files are dropped or selected
|
|
28
|
+
*/
|
|
29
|
+
onFilesReceived?: (files: File[]) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Called when validation fails
|
|
32
|
+
*/
|
|
33
|
+
onValidationError?: (errors: string[]) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Called when drag state changes
|
|
36
|
+
*/
|
|
37
|
+
onDragStateChange?: (isDragging: boolean) => void;
|
|
38
|
+
}
|
|
39
|
+
interface DragDropState {
|
|
40
|
+
/**
|
|
41
|
+
* Whether files are currently being dragged over the drop zone
|
|
42
|
+
*/
|
|
43
|
+
isDragging: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the drag is currently over the drop zone
|
|
46
|
+
*/
|
|
47
|
+
isOver: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the dragged items are valid files
|
|
50
|
+
*/
|
|
51
|
+
isValid: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Current validation errors
|
|
54
|
+
*/
|
|
55
|
+
errors: string[];
|
|
56
|
+
}
|
|
57
|
+
interface UseDragDropReturn {
|
|
58
|
+
/**
|
|
59
|
+
* Current drag and drop state
|
|
60
|
+
*/
|
|
61
|
+
state: DragDropState;
|
|
62
|
+
/**
|
|
63
|
+
* Event handlers for the drop zone element
|
|
64
|
+
*/
|
|
65
|
+
dragHandlers: {
|
|
66
|
+
onDragEnter: (event: React.DragEvent) => void;
|
|
67
|
+
onDragOver: (event: React.DragEvent) => void;
|
|
68
|
+
onDragLeave: (event: React.DragEvent) => void;
|
|
69
|
+
onDrop: (event: React.DragEvent) => void;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Props for a file input element
|
|
73
|
+
*/
|
|
74
|
+
inputProps: {
|
|
75
|
+
type: "file";
|
|
76
|
+
multiple: boolean;
|
|
77
|
+
accept?: string;
|
|
78
|
+
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
79
|
+
style: {
|
|
80
|
+
display: "none";
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Open file picker dialog
|
|
85
|
+
*/
|
|
86
|
+
openFilePicker: () => void;
|
|
87
|
+
/**
|
|
88
|
+
* Manually process files (useful for programmatic file handling)
|
|
89
|
+
*/
|
|
90
|
+
processFiles: (files: File[]) => void;
|
|
91
|
+
/**
|
|
92
|
+
* Reset drag state
|
|
93
|
+
*/
|
|
94
|
+
reset: () => void;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* React hook for handling drag and drop file uploads with validation.
|
|
98
|
+
* Provides drag state management, file validation, and file picker integration.
|
|
99
|
+
*
|
|
100
|
+
* @param options - Configuration and event handlers
|
|
101
|
+
* @returns Drag and drop state and handlers
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```tsx
|
|
105
|
+
* const dragDrop = useDragDrop({
|
|
106
|
+
* accept: ['image/*', '.pdf'],
|
|
107
|
+
* maxFiles: 5,
|
|
108
|
+
* maxFileSize: 10 * 1024 * 1024, // 10MB
|
|
109
|
+
* multiple: true,
|
|
110
|
+
* onFilesReceived: (files) => {
|
|
111
|
+
* console.log('Received files:', files);
|
|
112
|
+
* // Process files with upload hooks
|
|
113
|
+
* },
|
|
114
|
+
* onValidationError: (errors) => {
|
|
115
|
+
* console.error('Validation errors:', errors);
|
|
116
|
+
* },
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* return (
|
|
120
|
+
* <div>
|
|
121
|
+
* <div
|
|
122
|
+
* {...dragDrop.dragHandlers}
|
|
123
|
+
* style={{
|
|
124
|
+
* border: dragDrop.state.isDragging ? '2px dashed #007bff' : '2px dashed #ccc',
|
|
125
|
+
* backgroundColor: dragDrop.state.isOver ? '#f8f9fa' : 'transparent',
|
|
126
|
+
* padding: '2rem',
|
|
127
|
+
* textAlign: 'center',
|
|
128
|
+
* cursor: 'pointer',
|
|
129
|
+
* }}
|
|
130
|
+
* onClick={dragDrop.openFilePicker}
|
|
131
|
+
* >
|
|
132
|
+
* {dragDrop.state.isDragging ? (
|
|
133
|
+
* <p>Drop files here...</p>
|
|
134
|
+
* ) : (
|
|
135
|
+
* <p>Drag files here or click to select</p>
|
|
136
|
+
* )}
|
|
137
|
+
*
|
|
138
|
+
* {dragDrop.state.errors.length > 0 && (
|
|
139
|
+
* <div style={{ color: 'red', marginTop: '1rem' }}>
|
|
140
|
+
* {dragDrop.state.errors.map((error, index) => (
|
|
141
|
+
* <p key={index}>{error}</p>
|
|
142
|
+
* ))}
|
|
143
|
+
* </div>
|
|
144
|
+
* )}
|
|
145
|
+
* </div>
|
|
146
|
+
*
|
|
147
|
+
* <input {...dragDrop.inputProps} />
|
|
148
|
+
* </div>
|
|
149
|
+
* );
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
declare function useDragDrop(options?: DragDropOptions): UseDragDropReturn;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/hooks/use-flow-upload.d.ts
|
|
155
|
+
/**
|
|
156
|
+
* Possible states for a flow upload lifecycle.
|
|
157
|
+
* Flow uploads progress through: idle → uploading → processing → success/error/aborted
|
|
158
|
+
*/
|
|
159
|
+
type FlowUploadStatus = "idle" | "uploading" | "processing" | "success" | "error" | "aborted";
|
|
160
|
+
/**
|
|
161
|
+
* Complete state information for a flow upload operation.
|
|
162
|
+
* Tracks both the upload phase (file transfer) and processing phase (flow execution).
|
|
163
|
+
*
|
|
164
|
+
* @template TOutput - Type of the final output from the flow (defaults to UploadFile)
|
|
165
|
+
*
|
|
166
|
+
* @property status - Current upload status (idle, uploading, processing, success, error, aborted)
|
|
167
|
+
* @property progress - Upload progress percentage (0-100)
|
|
168
|
+
* @property bytesUploaded - Number of bytes successfully uploaded
|
|
169
|
+
* @property totalBytes - Total file size in bytes (null if unknown)
|
|
170
|
+
* @property error - Error object if upload or processing failed
|
|
171
|
+
* @property result - Final output from the flow (available when status is "success")
|
|
172
|
+
* @property jobId - Unique identifier for the flow execution job
|
|
173
|
+
* @property flowStarted - Whether the flow processing has started
|
|
174
|
+
* @property currentNodeName - Name of the currently executing flow node
|
|
175
|
+
* @property currentNodeType - Type of the currently executing flow node
|
|
176
|
+
* @property flowOutputs - Complete outputs from all output nodes in the flow
|
|
177
|
+
*/
|
|
178
|
+
interface FlowUploadState<TOutput = UploadFile> {
|
|
179
|
+
status: FlowUploadStatus;
|
|
180
|
+
progress: number;
|
|
181
|
+
bytesUploaded: number;
|
|
182
|
+
totalBytes: number | null;
|
|
183
|
+
error: Error | null;
|
|
184
|
+
result: TOutput | null;
|
|
185
|
+
jobId: string | null;
|
|
186
|
+
flowStarted: boolean;
|
|
187
|
+
currentNodeName: string | null;
|
|
188
|
+
currentNodeType: string | null;
|
|
189
|
+
flowOutputs: Record<string, unknown> | null;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Return value from the useFlowUpload hook with upload control methods and state.
|
|
193
|
+
*
|
|
194
|
+
* @template TOutput - Type of the final output from the flow (defaults to UploadFile)
|
|
195
|
+
*
|
|
196
|
+
* @property state - Complete flow upload state with progress and outputs
|
|
197
|
+
* @property upload - Function to initiate file upload through the flow
|
|
198
|
+
* @property abort - Cancel the current upload and flow execution
|
|
199
|
+
* @property reset - Reset state to idle (clears all data)
|
|
200
|
+
* @property isUploading - True when upload or processing is active
|
|
201
|
+
* @property isUploadingFile - True only during file upload phase
|
|
202
|
+
* @property isProcessing - True only during flow processing phase
|
|
203
|
+
*/
|
|
204
|
+
interface UseFlowUploadReturn<TOutput = UploadFile> {
|
|
205
|
+
/**
|
|
206
|
+
* Current upload state
|
|
207
|
+
*/
|
|
208
|
+
state: FlowUploadState<TOutput>;
|
|
209
|
+
/**
|
|
210
|
+
* Upload a file through the flow
|
|
211
|
+
*/
|
|
212
|
+
upload: (file: File | Blob) => Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Abort the current upload
|
|
215
|
+
*/
|
|
216
|
+
abort: () => void;
|
|
217
|
+
/**
|
|
218
|
+
* Reset the upload state
|
|
219
|
+
*/
|
|
220
|
+
reset: () => void;
|
|
221
|
+
/**
|
|
222
|
+
* Whether an upload or flow execution is in progress (uploading OR processing)
|
|
223
|
+
*/
|
|
224
|
+
isUploading: boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Whether the file is currently being uploaded (chunks being sent)
|
|
227
|
+
*/
|
|
228
|
+
isUploadingFile: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Whether the flow is currently processing (after upload completes)
|
|
231
|
+
*/
|
|
232
|
+
isProcessing: boolean;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* React hook for uploading files through a flow with automatic flow execution.
|
|
236
|
+
* Handles both the file upload phase and the flow processing phase, providing
|
|
237
|
+
* real-time progress updates and flow node execution tracking.
|
|
238
|
+
*
|
|
239
|
+
* The flow engine processes the uploaded file through a DAG of nodes, which can
|
|
240
|
+
* perform operations like image optimization, storage saving, webhooks, etc.
|
|
241
|
+
*
|
|
242
|
+
* Must be used within an UploadistaProvider. Flow events (node start/end, flow complete)
|
|
243
|
+
* are automatically subscribed through the provider context.
|
|
244
|
+
*
|
|
245
|
+
* @template TOutput - Type of the final result from the flow (defaults to UploadFile)
|
|
246
|
+
* @param options - Flow upload configuration including flow ID and event handlers
|
|
247
|
+
* @returns Flow upload state and control methods
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```tsx
|
|
251
|
+
* // Basic flow upload with progress tracking
|
|
252
|
+
* function ImageUploader() {
|
|
253
|
+
* const flowUpload = useFlowUpload({
|
|
254
|
+
* flowConfig: {
|
|
255
|
+
* flowId: "image-optimization-flow",
|
|
256
|
+
* storageId: "s3-images",
|
|
257
|
+
* outputNodeId: "optimized-output", // Optional: specify which output to use
|
|
258
|
+
* },
|
|
259
|
+
* onSuccess: (result) => {
|
|
260
|
+
* console.log("Image optimized and saved:", result);
|
|
261
|
+
* },
|
|
262
|
+
* onFlowComplete: (outputs) => {
|
|
263
|
+
* console.log("All flow outputs:", outputs);
|
|
264
|
+
* // outputs might include: { thumbnail: {...}, optimized: {...}, original: {...} }
|
|
265
|
+
* },
|
|
266
|
+
* onError: (error) => {
|
|
267
|
+
* console.error("Upload or processing failed:", error);
|
|
268
|
+
* },
|
|
269
|
+
* });
|
|
270
|
+
*
|
|
271
|
+
* return (
|
|
272
|
+
* <div>
|
|
273
|
+
* <input
|
|
274
|
+
* type="file"
|
|
275
|
+
* accept="image/*"
|
|
276
|
+
* onChange={(e) => {
|
|
277
|
+
* const file = e.target.files?.[0];
|
|
278
|
+
* if (file) flowUpload.upload(file);
|
|
279
|
+
* }}
|
|
280
|
+
* />
|
|
281
|
+
*
|
|
282
|
+
* {flowUpload.isUploadingFile && (
|
|
283
|
+
* <div>Uploading... {flowUpload.state.progress}%</div>
|
|
284
|
+
* )}
|
|
285
|
+
*
|
|
286
|
+
* {flowUpload.isProcessing && (
|
|
287
|
+
* <div>
|
|
288
|
+
* Processing...
|
|
289
|
+
* {flowUpload.state.currentNodeName && (
|
|
290
|
+
* <span>Current step: {flowUpload.state.currentNodeName}</span>
|
|
291
|
+
* )}
|
|
292
|
+
* </div>
|
|
293
|
+
* )}
|
|
294
|
+
*
|
|
295
|
+
* {flowUpload.state.status === "success" && (
|
|
296
|
+
* <div>
|
|
297
|
+
* <p>Upload complete!</p>
|
|
298
|
+
* {flowUpload.state.result && (
|
|
299
|
+
* <img src={flowUpload.state.result.url} alt="Uploaded" />
|
|
300
|
+
* )}
|
|
301
|
+
* </div>
|
|
302
|
+
* )}
|
|
303
|
+
*
|
|
304
|
+
* {flowUpload.state.status === "error" && (
|
|
305
|
+
* <div>
|
|
306
|
+
* <p>Error: {flowUpload.state.error?.message}</p>
|
|
307
|
+
* <button onClick={flowUpload.reset}>Try Again</button>
|
|
308
|
+
* </div>
|
|
309
|
+
* )}
|
|
310
|
+
*
|
|
311
|
+
* {flowUpload.isUploading && (
|
|
312
|
+
* <button onClick={flowUpload.abort}>Cancel</button>
|
|
313
|
+
* )}
|
|
314
|
+
* </div>
|
|
315
|
+
* );
|
|
316
|
+
* }
|
|
317
|
+
* ```
|
|
318
|
+
*
|
|
319
|
+
* @see {@link useMultiFlowUpload} for uploading multiple files through a flow
|
|
320
|
+
* @see {@link useUpload} for simple uploads without flow processing
|
|
321
|
+
*/
|
|
322
|
+
declare function useFlowUpload<TOutput = UploadFile>(options: FlowUploadOptions<TOutput>): UseFlowUploadReturn<TOutput>;
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region src/hooks/use-upload.d.ts
|
|
325
|
+
type UploadStatus = "idle" | "uploading" | "success" | "error" | "aborted";
|
|
326
|
+
interface UploadState {
|
|
327
|
+
status: UploadStatus;
|
|
328
|
+
progress: number;
|
|
329
|
+
bytesUploaded: number;
|
|
330
|
+
totalBytes: number | null;
|
|
331
|
+
error: Error | null;
|
|
332
|
+
result: UploadFile | null;
|
|
333
|
+
}
|
|
334
|
+
interface UseUploadOptions {
|
|
335
|
+
/**
|
|
336
|
+
* Upload metadata to attach to the file
|
|
337
|
+
*/
|
|
338
|
+
metadata?: Record<string, string>;
|
|
339
|
+
/**
|
|
340
|
+
* Whether to defer the upload size calculation
|
|
341
|
+
*/
|
|
342
|
+
uploadLengthDeferred?: boolean;
|
|
343
|
+
/**
|
|
344
|
+
* Manual upload size override
|
|
345
|
+
*/
|
|
346
|
+
uploadSize?: number;
|
|
347
|
+
/**
|
|
348
|
+
* Called when upload progress updates
|
|
349
|
+
*/
|
|
350
|
+
onProgress?: (progress: number, bytesUploaded: number, totalBytes: number | null) => void;
|
|
351
|
+
/**
|
|
352
|
+
* Called when a chunk completes
|
|
353
|
+
*/
|
|
354
|
+
onChunkComplete?: (chunkSize: number, bytesAccepted: number, bytesTotal: number | null) => void;
|
|
355
|
+
/**
|
|
356
|
+
* Called when upload succeeds
|
|
357
|
+
*/
|
|
358
|
+
onSuccess?: (result: UploadFile) => void;
|
|
359
|
+
/**
|
|
360
|
+
* Called when upload fails
|
|
361
|
+
*/
|
|
362
|
+
onError?: (error: Error) => void;
|
|
363
|
+
/**
|
|
364
|
+
* Called when upload is aborted
|
|
365
|
+
*/
|
|
366
|
+
onAbort?: () => void;
|
|
367
|
+
/**
|
|
368
|
+
* Custom retry logic
|
|
369
|
+
*/
|
|
370
|
+
onShouldRetry?: (error: Error, retryAttempt: number) => boolean;
|
|
371
|
+
}
|
|
372
|
+
interface UploadMetrics {
|
|
373
|
+
/**
|
|
374
|
+
* Get performance insights from the upload client
|
|
375
|
+
*/
|
|
376
|
+
getInsights: () => PerformanceInsights;
|
|
377
|
+
/**
|
|
378
|
+
* Export detailed metrics from the upload client
|
|
379
|
+
*/
|
|
380
|
+
exportMetrics: () => {
|
|
381
|
+
session: Partial<UploadSessionMetrics>;
|
|
382
|
+
chunks: ChunkMetrics[];
|
|
383
|
+
insights: PerformanceInsights;
|
|
384
|
+
};
|
|
385
|
+
/**
|
|
386
|
+
* Get current network metrics
|
|
387
|
+
*/
|
|
388
|
+
getNetworkMetrics: () => unknown;
|
|
389
|
+
/**
|
|
390
|
+
* Get current network condition
|
|
391
|
+
*/
|
|
392
|
+
getNetworkCondition: () => unknown;
|
|
393
|
+
/**
|
|
394
|
+
* Reset all metrics
|
|
395
|
+
*/
|
|
396
|
+
resetMetrics: () => void;
|
|
397
|
+
}
|
|
398
|
+
interface UseUploadReturn {
|
|
399
|
+
/**
|
|
400
|
+
* Current upload state
|
|
401
|
+
*/
|
|
402
|
+
state: UploadState;
|
|
403
|
+
/**
|
|
404
|
+
* Start uploading a file
|
|
405
|
+
*/
|
|
406
|
+
upload: (file: BrowserUploadInput) => void;
|
|
407
|
+
/**
|
|
408
|
+
* Abort the current upload
|
|
409
|
+
*/
|
|
410
|
+
abort: () => void;
|
|
411
|
+
/**
|
|
412
|
+
* Reset the upload state to idle
|
|
413
|
+
*/
|
|
414
|
+
reset: () => void;
|
|
415
|
+
/**
|
|
416
|
+
* Retry the last failed upload
|
|
417
|
+
*/
|
|
418
|
+
retry: () => void;
|
|
419
|
+
/**
|
|
420
|
+
* Whether an upload is currently active
|
|
421
|
+
*/
|
|
422
|
+
isUploading: boolean;
|
|
423
|
+
/**
|
|
424
|
+
* Whether the upload can be retried
|
|
425
|
+
*/
|
|
426
|
+
canRetry: boolean;
|
|
427
|
+
/**
|
|
428
|
+
* Upload metrics and performance insights from the client
|
|
429
|
+
*/
|
|
430
|
+
metrics: UploadMetrics;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* React hook for managing individual file uploads with full state management.
|
|
434
|
+
* Provides upload progress tracking, error handling, abort functionality, and retry logic.
|
|
435
|
+
*
|
|
436
|
+
* Must be used within an UploadistaProvider.
|
|
437
|
+
*
|
|
438
|
+
* @param options - Upload configuration and event handlers
|
|
439
|
+
* @returns Upload state and control methods
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```tsx
|
|
443
|
+
* function MyComponent() {
|
|
444
|
+
* const upload = useUpload({
|
|
445
|
+
* onSuccess: (result) => console.log('Upload complete:', result),
|
|
446
|
+
* onError: (error) => console.error('Upload failed:', error),
|
|
447
|
+
* onProgress: (progress) => console.log('Progress:', progress + '%'),
|
|
448
|
+
* });
|
|
449
|
+
*
|
|
450
|
+
* return (
|
|
451
|
+
* <div>
|
|
452
|
+
* <input
|
|
453
|
+
* type="file"
|
|
454
|
+
* onChange={(e) => {
|
|
455
|
+
* const file = e.target.files?.[0];
|
|
456
|
+
* if (file) upload.upload(file);
|
|
457
|
+
* }}
|
|
458
|
+
* />
|
|
459
|
+
* {upload.isUploading && <div>Progress: {upload.state.progress}%</div>}
|
|
460
|
+
* {upload.state.error && <div>Error: {upload.state.error.message}</div>}
|
|
461
|
+
* {upload.canRetry && <button onClick={upload.retry}>Retry</button>}
|
|
462
|
+
* <button onClick={upload.abort} disabled={!upload.isUploading}>Abort</button>
|
|
463
|
+
* </div>
|
|
464
|
+
* );
|
|
465
|
+
* }
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
declare function useUpload(options?: UseUploadOptions): UseUploadReturn;
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/hooks/use-multi-upload.d.ts
|
|
471
|
+
interface UploadItem {
|
|
472
|
+
id: string;
|
|
473
|
+
file: BrowserUploadInput;
|
|
474
|
+
state: UploadState;
|
|
475
|
+
}
|
|
476
|
+
interface MultiUploadOptions extends Omit<UseUploadOptions, "onSuccess" | "onError" | "onProgress"> {
|
|
477
|
+
/**
|
|
478
|
+
* Maximum number of concurrent uploads
|
|
479
|
+
*/
|
|
480
|
+
maxConcurrent?: number;
|
|
481
|
+
/**
|
|
482
|
+
* Called when an individual file upload starts
|
|
483
|
+
*/
|
|
484
|
+
onUploadStart?: (item: UploadItem) => void;
|
|
485
|
+
/**
|
|
486
|
+
* Called when an individual file upload progresses
|
|
487
|
+
*/
|
|
488
|
+
onUploadProgress?: (item: UploadItem, progress: number, bytesUploaded: number, totalBytes: number | null) => void;
|
|
489
|
+
/**
|
|
490
|
+
* Called when an individual file upload succeeds
|
|
491
|
+
*/
|
|
492
|
+
onUploadSuccess?: (item: UploadItem, result: UploadFile) => void;
|
|
493
|
+
/**
|
|
494
|
+
* Called when an individual file upload fails
|
|
495
|
+
*/
|
|
496
|
+
onUploadError?: (item: UploadItem, error: Error) => void;
|
|
497
|
+
/**
|
|
498
|
+
* Called when all uploads complete (successfully or with errors)
|
|
499
|
+
*/
|
|
500
|
+
onComplete?: (results: {
|
|
501
|
+
successful: UploadItem[];
|
|
502
|
+
failed: UploadItem[];
|
|
503
|
+
total: number;
|
|
504
|
+
}) => void;
|
|
505
|
+
}
|
|
506
|
+
interface MultiUploadState {
|
|
507
|
+
/**
|
|
508
|
+
* Total number of uploads
|
|
509
|
+
*/
|
|
510
|
+
total: number;
|
|
511
|
+
/**
|
|
512
|
+
* Number of completed uploads (successful + failed)
|
|
513
|
+
*/
|
|
514
|
+
completed: number;
|
|
515
|
+
/**
|
|
516
|
+
* Number of successful uploads
|
|
517
|
+
*/
|
|
518
|
+
successful: number;
|
|
519
|
+
/**
|
|
520
|
+
* Number of failed uploads
|
|
521
|
+
*/
|
|
522
|
+
failed: number;
|
|
523
|
+
/**
|
|
524
|
+
* Number of currently uploading files
|
|
525
|
+
*/
|
|
526
|
+
uploading: number;
|
|
527
|
+
/**
|
|
528
|
+
* Overall progress as a percentage (0-100)
|
|
529
|
+
*/
|
|
530
|
+
progress: number;
|
|
531
|
+
/**
|
|
532
|
+
* Total bytes uploaded across all files
|
|
533
|
+
*/
|
|
534
|
+
totalBytesUploaded: number;
|
|
535
|
+
/**
|
|
536
|
+
* Total bytes to upload across all files
|
|
537
|
+
*/
|
|
538
|
+
totalBytes: number;
|
|
539
|
+
/**
|
|
540
|
+
* Whether any uploads are currently active
|
|
541
|
+
*/
|
|
542
|
+
isUploading: boolean;
|
|
543
|
+
/**
|
|
544
|
+
* Whether all uploads have completed
|
|
545
|
+
*/
|
|
546
|
+
isComplete: boolean;
|
|
547
|
+
}
|
|
548
|
+
interface UseMultiUploadReturn {
|
|
549
|
+
/**
|
|
550
|
+
* Current multi-upload state
|
|
551
|
+
*/
|
|
552
|
+
state: MultiUploadState;
|
|
553
|
+
/**
|
|
554
|
+
* Array of all upload items
|
|
555
|
+
*/
|
|
556
|
+
items: UploadItem[];
|
|
557
|
+
/**
|
|
558
|
+
* Add files to the upload queue
|
|
559
|
+
*/
|
|
560
|
+
addFiles: (files: BrowserUploadInput[]) => void;
|
|
561
|
+
/**
|
|
562
|
+
* Remove an item from the queue (only if not currently uploading)
|
|
563
|
+
*/
|
|
564
|
+
removeItem: (id: string) => void;
|
|
565
|
+
/**
|
|
566
|
+
* Remove a file from the queue (alias for removeItem)
|
|
567
|
+
*/
|
|
568
|
+
removeFile: (id: string) => void;
|
|
569
|
+
/**
|
|
570
|
+
* Start all pending uploads
|
|
571
|
+
*/
|
|
572
|
+
startAll: () => void;
|
|
573
|
+
/**
|
|
574
|
+
* Abort a specific upload by ID
|
|
575
|
+
*/
|
|
576
|
+
abortUpload: (id: string) => void;
|
|
577
|
+
/**
|
|
578
|
+
* Abort all active uploads
|
|
579
|
+
*/
|
|
580
|
+
abortAll: () => void;
|
|
581
|
+
/**
|
|
582
|
+
* Retry a specific failed upload by ID
|
|
583
|
+
*/
|
|
584
|
+
retryUpload: (id: string) => void;
|
|
585
|
+
/**
|
|
586
|
+
* Retry all failed uploads
|
|
587
|
+
*/
|
|
588
|
+
retryFailed: () => void;
|
|
589
|
+
/**
|
|
590
|
+
* Clear all completed uploads (successful and failed)
|
|
591
|
+
*/
|
|
592
|
+
clearCompleted: () => void;
|
|
593
|
+
/**
|
|
594
|
+
* Clear all items
|
|
595
|
+
*/
|
|
596
|
+
clearAll: () => void;
|
|
597
|
+
/**
|
|
598
|
+
* Get items by status
|
|
599
|
+
*/
|
|
600
|
+
getItemsByStatus: (status: UploadStatus) => UploadItem[];
|
|
601
|
+
/**
|
|
602
|
+
* Aggregated upload metrics and performance insights from the client
|
|
603
|
+
*/
|
|
604
|
+
metrics: UploadMetrics;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* React hook for managing multiple file uploads with queue management,
|
|
608
|
+
* concurrent upload limits, and batch operations.
|
|
609
|
+
*
|
|
610
|
+
* Must be used within an UploadistaProvider.
|
|
611
|
+
*
|
|
612
|
+
* @param options - Multi-upload configuration and event handlers
|
|
613
|
+
* @returns Multi-upload state and control methods
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* ```tsx
|
|
617
|
+
* function MyComponent() {
|
|
618
|
+
* const multiUpload = useMultiUpload({
|
|
619
|
+
* maxConcurrent: 3,
|
|
620
|
+
* onUploadSuccess: (item, result) => {
|
|
621
|
+
* console.log(`${item.file.name} uploaded successfully`);
|
|
622
|
+
* },
|
|
623
|
+
* onComplete: (results) => {
|
|
624
|
+
* console.log(`Upload batch complete: ${results.successful.length}/${results.total} successful`);
|
|
625
|
+
* },
|
|
626
|
+
* });
|
|
627
|
+
*
|
|
628
|
+
* return (
|
|
629
|
+
* <div>
|
|
630
|
+
* <input
|
|
631
|
+
* type="file"
|
|
632
|
+
* multiple
|
|
633
|
+
* onChange={(e) => {
|
|
634
|
+
* if (e.target.files) {
|
|
635
|
+
* multiUpload.addFiles(Array.from(e.target.files));
|
|
636
|
+
* }
|
|
637
|
+
* }}
|
|
638
|
+
* />
|
|
639
|
+
*
|
|
640
|
+
* <div>Progress: {multiUpload.state.progress}%</div>
|
|
641
|
+
* <div>
|
|
642
|
+
* {multiUpload.state.uploading} uploading, {multiUpload.state.successful} successful,
|
|
643
|
+
* {multiUpload.state.failed} failed
|
|
644
|
+
* </div>
|
|
645
|
+
*
|
|
646
|
+
* <button onClick={multiUpload.startAll} disabled={multiUpload.state.isUploading}>
|
|
647
|
+
* Start All
|
|
648
|
+
* </button>
|
|
649
|
+
* <button onClick={multiUpload.abortAll} disabled={!multiUpload.state.isUploading}>
|
|
650
|
+
* Abort All
|
|
651
|
+
* </button>
|
|
652
|
+
* <button onClick={multiUpload.retryFailed} disabled={multiUpload.state.failed === 0}>
|
|
653
|
+
* Retry Failed
|
|
654
|
+
* </button>
|
|
655
|
+
*
|
|
656
|
+
* {multiUpload.items.map((item) => (
|
|
657
|
+
* <div key={item.id}>
|
|
658
|
+
* {item.file.name}: {item.state.status} ({item.state.progress}%)
|
|
659
|
+
* </div>
|
|
660
|
+
* ))}
|
|
661
|
+
* </div>
|
|
662
|
+
* );
|
|
663
|
+
* }
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
declare function useMultiUpload(options?: MultiUploadOptions): UseMultiUploadReturn;
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region src/hooks/use-uploadista-client.d.ts
|
|
669
|
+
/**
|
|
670
|
+
* Configuration options for the uploadista client hook.
|
|
671
|
+
* Extends the base client options with React-specific behavior.
|
|
672
|
+
*
|
|
673
|
+
* @property onEvent - Global event handler for all upload and flow events
|
|
674
|
+
* @property baseUrl - API base URL for uploads
|
|
675
|
+
* @property storageId - Default storage identifier
|
|
676
|
+
* @property chunkSize - Size of upload chunks in bytes
|
|
677
|
+
* @property storeFingerprintForResuming - Enable resumable uploads
|
|
678
|
+
* @property retryDelays - Array of retry delays in milliseconds
|
|
679
|
+
* @property parallelUploads - Maximum number of parallel uploads
|
|
680
|
+
* @property uploadStrategy - Upload strategy (sequential, parallel, adaptive)
|
|
681
|
+
* @property smartChunking - Enable dynamic chunk size adjustment
|
|
682
|
+
* @property networkMonitoring - Enable network condition monitoring
|
|
683
|
+
*/
|
|
684
|
+
interface UseUploadistaClientOptions extends UploadistaClientOptions {
|
|
685
|
+
/**
|
|
686
|
+
* Global event handler for all upload and flow events from this client
|
|
687
|
+
*/
|
|
688
|
+
onEvent?: UploadistaClientOptions["onEvent"];
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Return value from the useUploadistaClient hook.
|
|
692
|
+
*
|
|
693
|
+
* @property client - Configured uploadista client instance (stable across re-renders)
|
|
694
|
+
* @property config - Current client configuration options
|
|
695
|
+
*/
|
|
696
|
+
interface UseUploadistaClientReturn {
|
|
697
|
+
/**
|
|
698
|
+
* The uploadista client instance
|
|
699
|
+
*/
|
|
700
|
+
client: ReturnType<typeof createUploadistaClient>;
|
|
701
|
+
/**
|
|
702
|
+
* Current configuration of the client
|
|
703
|
+
*/
|
|
704
|
+
config: UseUploadistaClientOptions;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* React hook for creating and managing an uploadista client instance.
|
|
708
|
+
* The client instance is memoized and stable across re-renders, only being
|
|
709
|
+
* recreated when configuration options change.
|
|
710
|
+
*
|
|
711
|
+
* This hook is typically used internally by UploadistaProvider, but can be
|
|
712
|
+
* used directly for advanced use cases requiring multiple client instances.
|
|
713
|
+
*
|
|
714
|
+
* @param options - Upload client configuration options
|
|
715
|
+
* @returns Object containing the stable client instance and current configuration
|
|
716
|
+
*
|
|
717
|
+
* @example
|
|
718
|
+
* ```tsx
|
|
719
|
+
* // Basic client setup
|
|
720
|
+
* function MyUploadComponent() {
|
|
721
|
+
* const { client, config } = useUploadistaClient({
|
|
722
|
+
* baseUrl: 'https://api.example.com',
|
|
723
|
+
* storageId: 'default-storage',
|
|
724
|
+
* chunkSize: 1024 * 1024, // 1MB chunks
|
|
725
|
+
* storeFingerprintForResuming: true,
|
|
726
|
+
* onEvent: (event) => {
|
|
727
|
+
* console.log('Upload event:', event);
|
|
728
|
+
* }
|
|
729
|
+
* });
|
|
730
|
+
*
|
|
731
|
+
* // Use client directly
|
|
732
|
+
* const handleUpload = async (file: File) => {
|
|
733
|
+
* await client.upload(file, {
|
|
734
|
+
* onSuccess: (result) => console.log('Uploaded:', result),
|
|
735
|
+
* onError: (error) => console.error('Failed:', error),
|
|
736
|
+
* });
|
|
737
|
+
* };
|
|
738
|
+
*
|
|
739
|
+
* return <FileUploader onUpload={handleUpload} />;
|
|
740
|
+
* }
|
|
741
|
+
*
|
|
742
|
+
* // Advanced: Multiple clients with different configurations
|
|
743
|
+
* function MultiClientComponent() {
|
|
744
|
+
* // Client for image uploads
|
|
745
|
+
* const imageClient = useUploadistaClient({
|
|
746
|
+
* baseUrl: 'https://images.example.com',
|
|
747
|
+
* storageId: 'images',
|
|
748
|
+
* chunkSize: 2 * 1024 * 1024, // 2MB for images
|
|
749
|
+
* });
|
|
750
|
+
*
|
|
751
|
+
* // Client for document uploads
|
|
752
|
+
* const docClient = useUploadistaClient({
|
|
753
|
+
* baseUrl: 'https://docs.example.com',
|
|
754
|
+
* storageId: 'documents',
|
|
755
|
+
* chunkSize: 512 * 1024, // 512KB for documents
|
|
756
|
+
* });
|
|
757
|
+
*
|
|
758
|
+
* return (
|
|
759
|
+
* <div>
|
|
760
|
+
* <ImageUploader client={imageClient.client} />
|
|
761
|
+
* <DocumentUploader client={docClient.client} />
|
|
762
|
+
* </div>
|
|
763
|
+
* );
|
|
764
|
+
* }
|
|
765
|
+
* ```
|
|
766
|
+
*
|
|
767
|
+
* @see {@link UploadistaProvider} for the recommended way to provide client context
|
|
768
|
+
*/
|
|
769
|
+
declare function useUploadistaClient(options: UseUploadistaClientOptions): UseUploadistaClientReturn;
|
|
770
|
+
//#endregion
|
|
771
|
+
export { useFlowUpload as _, MultiUploadState as a, UseDragDropReturn as b, useMultiUpload as c, UseUploadOptions as d, UseUploadReturn as f, UseFlowUploadReturn as g, FlowUploadStatus as h, MultiUploadOptions as i, UploadState as l, FlowUploadState as m, UseUploadistaClientReturn as n, UploadItem as o, useUpload as p, useUploadistaClient as r, UseMultiUploadReturn as s, UseUploadistaClientOptions as t, UploadStatus as u, DragDropOptions as v, useDragDrop as x, DragDropState as y };
|
|
772
|
+
//# sourceMappingURL=use-uploadista-client-CeFo4wuV.d.ts.map
|