@igorvaryvoda/sirv-upload-widget 0.1.0 → 0.1.2
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.mts +574 -0
- package/dist/index.d.ts +574 -0
- package/dist/index.js +1787 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1759 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +806 -0
- package/package.json +1 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface ImageDimensions {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
interface SirvFile {
|
|
8
|
+
id: string;
|
|
9
|
+
file?: File;
|
|
10
|
+
filename: string;
|
|
11
|
+
previewUrl: string;
|
|
12
|
+
sirvUrl?: string;
|
|
13
|
+
sirvPath?: string;
|
|
14
|
+
dimensions?: ImageDimensions;
|
|
15
|
+
size?: number;
|
|
16
|
+
status: UploadStatus;
|
|
17
|
+
progress: number;
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
20
|
+
type UploadStatus = 'pending' | 'uploading' | 'processing' | 'success' | 'error' | 'conflict';
|
|
21
|
+
type ConflictResolution = 'overwrite' | 'rename' | 'skip';
|
|
22
|
+
interface ConflictInfo {
|
|
23
|
+
file: SirvFile;
|
|
24
|
+
existingPath: string;
|
|
25
|
+
suggestedPath: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* For presigned URL mode, user's backend only needs ONE endpoint.
|
|
29
|
+
* The widget uploads directly to Sirv's S3 endpoint.
|
|
30
|
+
*
|
|
31
|
+
* Example backend implementation (Next.js):
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'
|
|
34
|
+
* import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
|
|
35
|
+
*
|
|
36
|
+
* const s3 = new S3Client({
|
|
37
|
+
* endpoint: 'https://s3.sirv.com',
|
|
38
|
+
* region: 'us-east-1',
|
|
39
|
+
* credentials: {
|
|
40
|
+
* accessKeyId: process.env.SIRV_S3_KEY!,
|
|
41
|
+
* secretAccessKey: process.env.SIRV_S3_SECRET!,
|
|
42
|
+
* },
|
|
43
|
+
* forcePathStyle: true,
|
|
44
|
+
* })
|
|
45
|
+
*
|
|
46
|
+
* export async function POST(req: Request) {
|
|
47
|
+
* const { filename, contentType, folder } = await req.json()
|
|
48
|
+
* const key = `${folder}/${filename}`.replace(/^\/+/, '')
|
|
49
|
+
*
|
|
50
|
+
* const uploadUrl = await getSignedUrl(s3, new PutObjectCommand({
|
|
51
|
+
* Bucket: process.env.SIRV_BUCKET!,
|
|
52
|
+
* Key: key,
|
|
53
|
+
* ContentType: contentType,
|
|
54
|
+
* }), { expiresIn: 300 })
|
|
55
|
+
*
|
|
56
|
+
* const publicUrl = `https://${process.env.SIRV_BUCKET}.sirv.com/${key}`
|
|
57
|
+
* return Response.json({ uploadUrl, publicUrl, path: '/' + key })
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
/** POST {presignEndpoint} - Get a presigned upload URL */
|
|
62
|
+
interface PresignRequest {
|
|
63
|
+
/** Target filename */
|
|
64
|
+
filename: string;
|
|
65
|
+
/** Content type of the file */
|
|
66
|
+
contentType: string;
|
|
67
|
+
/** Target folder path (e.g., "/uploads/2024") */
|
|
68
|
+
folder?: string;
|
|
69
|
+
/** File size in bytes (for validation) */
|
|
70
|
+
size?: number;
|
|
71
|
+
}
|
|
72
|
+
interface PresignResponse {
|
|
73
|
+
/** Presigned URL to upload directly to Sirv S3 */
|
|
74
|
+
uploadUrl: string;
|
|
75
|
+
/** Public CDN URL where file will be accessible */
|
|
76
|
+
publicUrl: string;
|
|
77
|
+
/** Path on Sirv (e.g., "/uploads/2024/image.jpg") */
|
|
78
|
+
path: string;
|
|
79
|
+
/** Error message if failed */
|
|
80
|
+
error?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* For proxy mode, user's backend handles all Sirv operations.
|
|
84
|
+
* Use this if you can't use presigned URLs or need more control.
|
|
85
|
+
*/
|
|
86
|
+
/** POST {endpoint}/upload - Upload a file to Sirv */
|
|
87
|
+
interface UploadRequest {
|
|
88
|
+
/** Base64-encoded file data OR a URL to fetch */
|
|
89
|
+
data: string;
|
|
90
|
+
/** Target filename */
|
|
91
|
+
filename: string;
|
|
92
|
+
/** Target folder path (e.g., "/uploads/2024") */
|
|
93
|
+
folder: string;
|
|
94
|
+
/** Content type of the file */
|
|
95
|
+
contentType: string;
|
|
96
|
+
/** Conflict resolution strategy */
|
|
97
|
+
onConflict?: ConflictResolution;
|
|
98
|
+
}
|
|
99
|
+
interface UploadResponse {
|
|
100
|
+
success: boolean;
|
|
101
|
+
/** Full Sirv URL of the uploaded file */
|
|
102
|
+
url?: string;
|
|
103
|
+
/** Path on Sirv (e.g., "/uploads/2024/image.jpg") */
|
|
104
|
+
path?: string;
|
|
105
|
+
/** Error message if failed */
|
|
106
|
+
error?: string;
|
|
107
|
+
/** True if file already exists */
|
|
108
|
+
conflict?: boolean;
|
|
109
|
+
/** Existing file path if conflict */
|
|
110
|
+
existingPath?: string;
|
|
111
|
+
}
|
|
112
|
+
/** GET {endpoint}/browse?path=/folder - List files and folders */
|
|
113
|
+
interface BrowseRequest {
|
|
114
|
+
/** Folder path to browse */
|
|
115
|
+
path: string;
|
|
116
|
+
/** Filter by type */
|
|
117
|
+
type?: 'image' | 'video' | 'all';
|
|
118
|
+
/** Search query */
|
|
119
|
+
search?: string;
|
|
120
|
+
}
|
|
121
|
+
interface BrowseResponse {
|
|
122
|
+
success: boolean;
|
|
123
|
+
/** Current folder path */
|
|
124
|
+
path: string;
|
|
125
|
+
/** List of items in the folder */
|
|
126
|
+
items?: BrowseItem[];
|
|
127
|
+
error?: string;
|
|
128
|
+
}
|
|
129
|
+
interface BrowseItem {
|
|
130
|
+
/** File or folder name */
|
|
131
|
+
name: string;
|
|
132
|
+
/** Full path */
|
|
133
|
+
path: string;
|
|
134
|
+
/** 'file' or 'folder' */
|
|
135
|
+
type: 'file' | 'folder';
|
|
136
|
+
/** File size in bytes (files only) */
|
|
137
|
+
size?: number;
|
|
138
|
+
/** MIME type (files only) */
|
|
139
|
+
contentType?: string;
|
|
140
|
+
/** Last modified date */
|
|
141
|
+
mtime?: string;
|
|
142
|
+
/** Thumbnail URL (images only) */
|
|
143
|
+
thumbnail?: string;
|
|
144
|
+
}
|
|
145
|
+
/** DELETE {endpoint}/delete - Delete a file */
|
|
146
|
+
interface DeleteRequest {
|
|
147
|
+
/** Path of file to delete */
|
|
148
|
+
path: string;
|
|
149
|
+
}
|
|
150
|
+
interface DeleteResponse {
|
|
151
|
+
success: boolean;
|
|
152
|
+
error?: string;
|
|
153
|
+
}
|
|
154
|
+
/** POST {endpoint}/check - Check if file exists (optional) */
|
|
155
|
+
interface CheckRequest {
|
|
156
|
+
/** Path to check */
|
|
157
|
+
path: string;
|
|
158
|
+
}
|
|
159
|
+
interface CheckResponse {
|
|
160
|
+
exists: boolean;
|
|
161
|
+
/** Existing file info if exists */
|
|
162
|
+
file?: BrowseItem;
|
|
163
|
+
}
|
|
164
|
+
interface SirvUploaderProps {
|
|
165
|
+
/**
|
|
166
|
+
* RECOMMENDED: Endpoint to get presigned upload URLs.
|
|
167
|
+
* Widget will POST { filename, contentType, folder } and expect { uploadUrl, publicUrl, path }
|
|
168
|
+
* Then upload directly to Sirv's S3 endpoint.
|
|
169
|
+
*
|
|
170
|
+
* Your backend just needs to call AWS SDK's getSignedUrl with Sirv's S3 endpoint.
|
|
171
|
+
*/
|
|
172
|
+
presignEndpoint?: string;
|
|
173
|
+
/**
|
|
174
|
+
* ALTERNATIVE: Base URL for full proxy endpoint.
|
|
175
|
+
* Use this if you can't use presigned URLs.
|
|
176
|
+
* The widget will call:
|
|
177
|
+
* - POST {endpoint}/upload (with file data)
|
|
178
|
+
* - GET {endpoint}/browse
|
|
179
|
+
* - DELETE {endpoint}/delete
|
|
180
|
+
*/
|
|
181
|
+
proxyEndpoint?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Sirv account/bucket name (e.g., "myaccount" for myaccount.sirv.com)
|
|
184
|
+
* Required for file picker when using presigned URLs.
|
|
185
|
+
*/
|
|
186
|
+
sirvAccount?: string;
|
|
187
|
+
/**
|
|
188
|
+
* Default folder to upload files to.
|
|
189
|
+
* @default "/"
|
|
190
|
+
*/
|
|
191
|
+
folder?: string;
|
|
192
|
+
/**
|
|
193
|
+
* Callback when files are uploaded successfully.
|
|
194
|
+
*/
|
|
195
|
+
onUpload?: (files: SirvFile[]) => void;
|
|
196
|
+
/**
|
|
197
|
+
* Callback when upload fails.
|
|
198
|
+
*/
|
|
199
|
+
onError?: (error: string, file?: SirvFile) => void;
|
|
200
|
+
/**
|
|
201
|
+
* Callback when files are selected (before upload).
|
|
202
|
+
*/
|
|
203
|
+
onSelect?: (files: SirvFile[]) => void;
|
|
204
|
+
/**
|
|
205
|
+
* Callback when a file is removed from the queue.
|
|
206
|
+
*/
|
|
207
|
+
onRemove?: (file: SirvFile) => void;
|
|
208
|
+
/**
|
|
209
|
+
* Feature flags to enable/disable parts of the widget.
|
|
210
|
+
*/
|
|
211
|
+
features?: {
|
|
212
|
+
/** Enable batch/multi-file upload. @default true */
|
|
213
|
+
batch?: boolean;
|
|
214
|
+
/** Enable CSV/Excel import tab. @default true */
|
|
215
|
+
csvImport?: boolean;
|
|
216
|
+
/** Enable Sirv file picker. @default true */
|
|
217
|
+
filePicker?: boolean;
|
|
218
|
+
/** Enable drag and drop. @default true */
|
|
219
|
+
dragDrop?: boolean;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Maximum number of files for batch upload.
|
|
223
|
+
* @default 50
|
|
224
|
+
*/
|
|
225
|
+
maxFiles?: number;
|
|
226
|
+
/**
|
|
227
|
+
* Maximum file size in bytes.
|
|
228
|
+
* @default 10485760 (10MB)
|
|
229
|
+
*/
|
|
230
|
+
maxFileSize?: number;
|
|
231
|
+
/**
|
|
232
|
+
* Accepted file types (MIME types or extensions).
|
|
233
|
+
* @default ["image/*"]
|
|
234
|
+
*/
|
|
235
|
+
accept?: string[];
|
|
236
|
+
/**
|
|
237
|
+
* How to handle filename conflicts.
|
|
238
|
+
* - 'ask': Show modal to let user decide
|
|
239
|
+
* - 'overwrite': Always overwrite
|
|
240
|
+
* - 'rename': Always rename with suffix
|
|
241
|
+
* - 'skip': Skip conflicting files
|
|
242
|
+
* @default 'rename'
|
|
243
|
+
*/
|
|
244
|
+
onConflict?: ConflictResolution | 'ask';
|
|
245
|
+
/**
|
|
246
|
+
* Auto-upload files immediately after selection.
|
|
247
|
+
* @default true
|
|
248
|
+
*/
|
|
249
|
+
autoUpload?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Number of concurrent uploads.
|
|
252
|
+
* @default 3
|
|
253
|
+
*/
|
|
254
|
+
concurrency?: number;
|
|
255
|
+
/**
|
|
256
|
+
* Custom class name for the container.
|
|
257
|
+
*/
|
|
258
|
+
className?: string;
|
|
259
|
+
/**
|
|
260
|
+
* Disable the entire widget.
|
|
261
|
+
*/
|
|
262
|
+
disabled?: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Compact mode for smaller spaces.
|
|
265
|
+
*/
|
|
266
|
+
compact?: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Custom labels for i18n.
|
|
269
|
+
*/
|
|
270
|
+
labels?: Partial<SirvUploaderLabels>;
|
|
271
|
+
/**
|
|
272
|
+
* Children to render inside the dropzone (for custom trigger).
|
|
273
|
+
*/
|
|
274
|
+
children?: React.ReactNode;
|
|
275
|
+
}
|
|
276
|
+
interface SirvUploaderLabels {
|
|
277
|
+
dropzone: string;
|
|
278
|
+
dropzoneHint: string;
|
|
279
|
+
browse: string;
|
|
280
|
+
uploadFiles: string;
|
|
281
|
+
importUrls: string;
|
|
282
|
+
selectFromSirv: string;
|
|
283
|
+
uploading: string;
|
|
284
|
+
processing: string;
|
|
285
|
+
success: string;
|
|
286
|
+
error: string;
|
|
287
|
+
retry: string;
|
|
288
|
+
remove: string;
|
|
289
|
+
cancel: string;
|
|
290
|
+
overwrite: string;
|
|
291
|
+
rename: string;
|
|
292
|
+
skip: string;
|
|
293
|
+
conflictTitle: string;
|
|
294
|
+
conflictMessage: string;
|
|
295
|
+
}
|
|
296
|
+
interface UseSirvUploadOptions$1 {
|
|
297
|
+
endpoint: string;
|
|
298
|
+
folder: string;
|
|
299
|
+
onConflict: ConflictResolution | 'ask';
|
|
300
|
+
concurrency: number;
|
|
301
|
+
autoUpload: boolean;
|
|
302
|
+
maxFileSize: number;
|
|
303
|
+
onUpload?: (files: SirvFile[]) => void;
|
|
304
|
+
onError?: (error: string, file?: SirvFile) => void;
|
|
305
|
+
}
|
|
306
|
+
interface UseSirvUploadReturn$1 {
|
|
307
|
+
/** Current files in the queue */
|
|
308
|
+
files: SirvFile[];
|
|
309
|
+
/** Add files to the queue */
|
|
310
|
+
addFiles: (files: File[]) => void;
|
|
311
|
+
/** Add URLs (from CSV/spreadsheet) */
|
|
312
|
+
addUrls: (urls: string[]) => void;
|
|
313
|
+
/** Remove a file from the queue */
|
|
314
|
+
removeFile: (id: string) => void;
|
|
315
|
+
/** Clear all files */
|
|
316
|
+
clearFiles: () => void;
|
|
317
|
+
/** Start uploading all pending files */
|
|
318
|
+
uploadAll: () => Promise<void>;
|
|
319
|
+
/** Upload a single file */
|
|
320
|
+
uploadFile: (id: string) => Promise<void>;
|
|
321
|
+
/** Retry a failed upload */
|
|
322
|
+
retryFile: (id: string) => Promise<void>;
|
|
323
|
+
/** Cancel an in-progress upload */
|
|
324
|
+
cancelUpload: (id: string) => void;
|
|
325
|
+
/** Resolve a conflict */
|
|
326
|
+
resolveConflict: (id: string, resolution: ConflictResolution) => void;
|
|
327
|
+
/** Current conflict needing resolution (if onConflict='ask') */
|
|
328
|
+
currentConflict: ConflictInfo | null;
|
|
329
|
+
/** Overall upload progress (0-100) */
|
|
330
|
+
progress: number;
|
|
331
|
+
/** True if any uploads are in progress */
|
|
332
|
+
isUploading: boolean;
|
|
333
|
+
/** True if all files have been uploaded */
|
|
334
|
+
isComplete: boolean;
|
|
335
|
+
}
|
|
336
|
+
interface UseFilePickerOptions {
|
|
337
|
+
endpoint: string;
|
|
338
|
+
fileType?: 'image' | 'video' | 'all';
|
|
339
|
+
}
|
|
340
|
+
interface UseFilePickerReturn {
|
|
341
|
+
/** Current folder path */
|
|
342
|
+
currentPath: string;
|
|
343
|
+
/** Items in current folder */
|
|
344
|
+
items: BrowseItem[];
|
|
345
|
+
/** Loading state */
|
|
346
|
+
isLoading: boolean;
|
|
347
|
+
/** Error message */
|
|
348
|
+
error: string | null;
|
|
349
|
+
/** Navigate to a folder */
|
|
350
|
+
navigateTo: (path: string) => void;
|
|
351
|
+
/** Go up one folder */
|
|
352
|
+
goUp: () => void;
|
|
353
|
+
/** Refresh current folder */
|
|
354
|
+
refresh: () => void;
|
|
355
|
+
/** Search within current folder */
|
|
356
|
+
search: (query: string) => void;
|
|
357
|
+
/** Select a file */
|
|
358
|
+
selectFile: (item: BrowseItem) => void;
|
|
359
|
+
/** Selected files */
|
|
360
|
+
selectedFiles: BrowseItem[];
|
|
361
|
+
/** Clear selection */
|
|
362
|
+
clearSelection: () => void;
|
|
363
|
+
}
|
|
364
|
+
interface ParsedUrl {
|
|
365
|
+
url: string;
|
|
366
|
+
path: string;
|
|
367
|
+
valid: boolean;
|
|
368
|
+
error?: string;
|
|
369
|
+
}
|
|
370
|
+
interface CsvParseOptions {
|
|
371
|
+
/** Column name or index containing URLs */
|
|
372
|
+
column?: string | number;
|
|
373
|
+
/** Skip header row */
|
|
374
|
+
hasHeader?: boolean;
|
|
375
|
+
/** Validate URLs */
|
|
376
|
+
validate?: boolean;
|
|
377
|
+
}
|
|
378
|
+
interface CsvParseResult {
|
|
379
|
+
headers: string[];
|
|
380
|
+
urls: ParsedUrl[];
|
|
381
|
+
totalCount: number;
|
|
382
|
+
validCount: number;
|
|
383
|
+
invalidCount: number;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
declare function SirvUploader({ presignEndpoint, proxyEndpoint, sirvAccount, folder, onUpload, onError, onSelect, onRemove, features, maxFiles, maxFileSize, accept, onConflict, autoUpload, concurrency, className, disabled, compact, labels: customLabels, children, }: SirvUploaderProps): react_jsx_runtime.JSX.Element;
|
|
387
|
+
|
|
388
|
+
interface DropZoneProps {
|
|
389
|
+
onFiles: (files: SirvFile[]) => void;
|
|
390
|
+
onSpreadsheet?: (file: File) => void;
|
|
391
|
+
accept?: string[];
|
|
392
|
+
maxFiles?: number;
|
|
393
|
+
maxFileSize?: number;
|
|
394
|
+
disabled?: boolean;
|
|
395
|
+
compact?: boolean;
|
|
396
|
+
className?: string;
|
|
397
|
+
labels?: {
|
|
398
|
+
dropzone?: string;
|
|
399
|
+
dropzoneHint?: string;
|
|
400
|
+
browse?: string;
|
|
401
|
+
};
|
|
402
|
+
children?: React.ReactNode;
|
|
403
|
+
}
|
|
404
|
+
declare function DropZone({ onFiles, onSpreadsheet, accept, maxFiles, maxFileSize, disabled, compact, className, labels, children, }: DropZoneProps): react_jsx_runtime.JSX.Element;
|
|
405
|
+
|
|
406
|
+
interface FileListProps {
|
|
407
|
+
files: SirvFile[];
|
|
408
|
+
onRemove?: (id: string) => void;
|
|
409
|
+
onRetry?: (id: string) => void;
|
|
410
|
+
showThumbnails?: boolean;
|
|
411
|
+
className?: string;
|
|
412
|
+
labels?: {
|
|
413
|
+
retry?: string;
|
|
414
|
+
remove?: string;
|
|
415
|
+
uploading?: string;
|
|
416
|
+
processing?: string;
|
|
417
|
+
success?: string;
|
|
418
|
+
error?: string;
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
declare function FileList({ files, onRemove, onRetry, showThumbnails, className, labels, }: FileListProps): react_jsx_runtime.JSX.Element | null;
|
|
422
|
+
interface FileListSummaryProps {
|
|
423
|
+
files: SirvFile[];
|
|
424
|
+
className?: string;
|
|
425
|
+
}
|
|
426
|
+
declare function FileListSummary({ files, className }: FileListSummaryProps): react_jsx_runtime.JSX.Element | null;
|
|
427
|
+
|
|
428
|
+
interface FilePickerProps {
|
|
429
|
+
endpoint: string;
|
|
430
|
+
isOpen: boolean;
|
|
431
|
+
onClose: () => void;
|
|
432
|
+
onSelect: (items: BrowseItem[]) => void;
|
|
433
|
+
fileType?: 'image' | 'video' | 'all';
|
|
434
|
+
multiple?: boolean;
|
|
435
|
+
initialPath?: string;
|
|
436
|
+
className?: string;
|
|
437
|
+
labels?: {
|
|
438
|
+
title?: string;
|
|
439
|
+
select?: string;
|
|
440
|
+
cancel?: string;
|
|
441
|
+
search?: string;
|
|
442
|
+
empty?: string;
|
|
443
|
+
loading?: string;
|
|
444
|
+
error?: string;
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
declare function FilePicker({ endpoint, isOpen, onClose, onSelect, fileType, multiple, initialPath, className, labels, }: FilePickerProps): react_jsx_runtime.JSX.Element | null;
|
|
448
|
+
|
|
449
|
+
interface SpreadsheetImportProps {
|
|
450
|
+
onUrls: (urls: string[]) => void;
|
|
451
|
+
className?: string;
|
|
452
|
+
labels?: {
|
|
453
|
+
drop?: string;
|
|
454
|
+
hint?: string;
|
|
455
|
+
validUrls?: string;
|
|
456
|
+
invalidUrls?: string;
|
|
457
|
+
import?: string;
|
|
458
|
+
clear?: string;
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
declare function SpreadsheetImport({ onUrls, className, labels, }: SpreadsheetImportProps): react_jsx_runtime.JSX.Element;
|
|
462
|
+
|
|
463
|
+
interface UseSirvUploadOptions {
|
|
464
|
+
/** Endpoint to get presigned URLs (recommended) */
|
|
465
|
+
presignEndpoint?: string;
|
|
466
|
+
/** Full proxy endpoint (alternative) */
|
|
467
|
+
proxyEndpoint?: string;
|
|
468
|
+
/** Default upload folder */
|
|
469
|
+
folder: string;
|
|
470
|
+
/** Conflict resolution strategy */
|
|
471
|
+
onConflict: ConflictResolution | 'ask';
|
|
472
|
+
/** Max concurrent uploads */
|
|
473
|
+
concurrency: number;
|
|
474
|
+
/** Auto-upload on file add */
|
|
475
|
+
autoUpload: boolean;
|
|
476
|
+
/** Max file size */
|
|
477
|
+
maxFileSize: number;
|
|
478
|
+
/** Callback on successful uploads */
|
|
479
|
+
onUpload?: (files: SirvFile[]) => void;
|
|
480
|
+
/** Callback on errors */
|
|
481
|
+
onError?: (error: string, file?: SirvFile) => void;
|
|
482
|
+
}
|
|
483
|
+
interface UseSirvUploadReturn {
|
|
484
|
+
files: SirvFile[];
|
|
485
|
+
addFiles: (newFiles: SirvFile[]) => void;
|
|
486
|
+
addUrls: (urls: string[]) => void;
|
|
487
|
+
removeFile: (id: string) => void;
|
|
488
|
+
clearFiles: () => void;
|
|
489
|
+
uploadAll: () => Promise<void>;
|
|
490
|
+
uploadFile: (id: string) => Promise<void>;
|
|
491
|
+
retryFile: (id: string) => Promise<void>;
|
|
492
|
+
cancelUpload: (id: string) => void;
|
|
493
|
+
progress: number;
|
|
494
|
+
isUploading: boolean;
|
|
495
|
+
isComplete: boolean;
|
|
496
|
+
}
|
|
497
|
+
declare function useSirvUpload(options: UseSirvUploadOptions): UseSirvUploadReturn;
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Image utility functions for the Sirv Upload Widget
|
|
501
|
+
*/
|
|
502
|
+
declare const ACCEPTED_IMAGE_FORMATS = "image/jpeg,image/png,image/gif,image/webp,image/bmp,image/tiff,image/heic,image/heif,image/avif,.jpg,.jpeg,.png,.gif,.webp,.bmp,.tif,.tiff,.heic,.heif,.avif";
|
|
503
|
+
declare const DEFAULT_MAX_FILE_SIZE: number;
|
|
504
|
+
declare function isImageFile(file: File): boolean;
|
|
505
|
+
declare function isHeifFile(file: File): boolean;
|
|
506
|
+
/**
|
|
507
|
+
* Convert HEIC with multiple fallback strategies:
|
|
508
|
+
* 1. Client-side heic2any library
|
|
509
|
+
* 2. Browser native support via canvas (Safari)
|
|
510
|
+
* 3. Optional server-side endpoint
|
|
511
|
+
*/
|
|
512
|
+
declare function convertHeicWithFallback(file: File, serverEndpoint?: string): Promise<File>;
|
|
513
|
+
declare function generateId(): string;
|
|
514
|
+
declare function validateFileSize(file: File, maxSize?: number): {
|
|
515
|
+
valid: boolean;
|
|
516
|
+
error?: string;
|
|
517
|
+
};
|
|
518
|
+
declare function getImageDimensions(file: File): Promise<{
|
|
519
|
+
width: number;
|
|
520
|
+
height: number;
|
|
521
|
+
} | null>;
|
|
522
|
+
declare function formatFileSize(bytes: number): string;
|
|
523
|
+
declare function getMimeType(file: File): string;
|
|
524
|
+
|
|
525
|
+
declare const DELIMITERS: readonly [",", "\t", ";", "|"];
|
|
526
|
+
type CsvDelimiter = (typeof DELIMITERS)[number];
|
|
527
|
+
/**
|
|
528
|
+
* Detect the delimiter used in CSV content by analyzing the first few lines
|
|
529
|
+
*/
|
|
530
|
+
declare function detectDelimiter(csvContent: string): CsvDelimiter;
|
|
531
|
+
interface ParsedUrlItem {
|
|
532
|
+
url: string;
|
|
533
|
+
path: string;
|
|
534
|
+
valid: boolean;
|
|
535
|
+
error?: string;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Validate a URL - customizable validator
|
|
539
|
+
*/
|
|
540
|
+
type UrlValidator = (url: string) => {
|
|
541
|
+
valid: boolean;
|
|
542
|
+
error?: string;
|
|
543
|
+
};
|
|
544
|
+
declare const defaultUrlValidator: UrlValidator;
|
|
545
|
+
declare const sirvUrlValidator: UrlValidator;
|
|
546
|
+
interface ClientParseResult {
|
|
547
|
+
headers: string[];
|
|
548
|
+
sampleRows: string[][];
|
|
549
|
+
rowCount: number;
|
|
550
|
+
estimatedImageCounts: number[];
|
|
551
|
+
urls: ParsedUrlItem[];
|
|
552
|
+
validCount: number;
|
|
553
|
+
invalidCount: number;
|
|
554
|
+
totalCount: number;
|
|
555
|
+
}
|
|
556
|
+
interface ParseOptions {
|
|
557
|
+
column?: string;
|
|
558
|
+
previewOnly?: boolean;
|
|
559
|
+
validator?: UrlValidator;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Parse CSV content client-side with preview and URL extraction
|
|
563
|
+
*/
|
|
564
|
+
declare function parseCsvClient(csvContent: string, options?: ParseOptions): ClientParseResult;
|
|
565
|
+
/**
|
|
566
|
+
* Parse Excel file client-side with preview and URL extraction
|
|
567
|
+
*/
|
|
568
|
+
declare function parseExcelClient(arrayBuffer: ArrayBuffer, options?: ParseOptions): Promise<ClientParseResult>;
|
|
569
|
+
/**
|
|
570
|
+
* Detect if a file is a spreadsheet type
|
|
571
|
+
*/
|
|
572
|
+
declare function isSpreadsheetFile(file: File): boolean;
|
|
573
|
+
|
|
574
|
+
export { ACCEPTED_IMAGE_FORMATS, type BrowseItem, type BrowseRequest, type BrowseResponse, type CheckRequest, type CheckResponse, type ClientParseResult, type ConflictInfo, type ConflictResolution, type CsvParseOptions, type CsvParseResult, DEFAULT_MAX_FILE_SIZE, type DeleteRequest, type DeleteResponse, DropZone, type DropZoneProps, FileList, type FileListProps, FileListSummary, FilePicker, type FilePickerProps, type ImageDimensions, type ParsedUrl, type ParsedUrlItem, type PresignRequest, type PresignResponse, type SirvFile, SirvUploader, type SirvUploaderLabels, type SirvUploaderProps, SpreadsheetImport, type SpreadsheetImportProps, type UploadRequest, type UploadResponse, type UploadStatus, type UrlValidator, type UseFilePickerOptions, type UseFilePickerReturn, type UseSirvUploadOptions$1 as UseSirvUploadOptions, type UseSirvUploadReturn$1 as UseSirvUploadReturn, convertHeicWithFallback, defaultUrlValidator, detectDelimiter, formatFileSize, generateId, getImageDimensions, getMimeType, isHeifFile, isImageFile, isSpreadsheetFile, parseCsvClient, parseExcelClient, sirvUrlValidator, useSirvUpload, validateFileSize };
|