@osmandvc/react-upload-control 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +421 -0
- package/dist/FileUploadContainer.d.ts +9 -0
- package/dist/FileUploadControl.d.ts +5 -0
- package/dist/actions/FileDeleteAllButton.d.ts +1 -0
- package/dist/actions/FileItemActions.d.ts +7 -0
- package/dist/actions/FileUploadAllButton.d.ts +1 -0
- package/dist/actions/index.d.ts +3 -0
- package/dist/components/camera/custom-react-webcam.d.ts +58 -0
- package/dist/components/camera/frames/WebcamFrameA4.d.ts +20 -0
- package/dist/components/camera/frames/index.d.ts +1 -0
- package/dist/components/camera/index.d.ts +1 -0
- package/dist/components/camera/use-webcam.d.ts +34 -0
- package/dist/components/file-drop/FileDropArea.d.ts +2 -0
- package/dist/components/file-drop/FileDropLarge.d.ts +6 -0
- package/dist/components/file-drop/FileDropSmall.d.ts +6 -0
- package/dist/components/file-list/FileList.d.ts +2 -0
- package/dist/components/file-list/FileListActions.d.ts +1 -0
- package/dist/components/file-list/FileListContainer.d.ts +6 -0
- package/dist/components/file-list/FileListItem.d.ts +3 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/use-mobile-detect.d.ts +9 -0
- package/dist/hooks/use-state-machine.d.ts +21 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +33 -0
- package/dist/loaders/FileLoaderActions.d.ts +2 -0
- package/dist/loaders/FileLoaderCamera.d.ts +2 -0
- package/dist/loaders/FileLoaderFileSystem.d.ts +2 -0
- package/dist/loaders/index.d.ts +3 -0
- package/dist/providers/UploadedFilesManager.d.ts +26 -0
- package/dist/providers/UploadedFilesProvider.d.ts +3 -0
- package/dist/providers/index.d.ts +2 -0
- package/dist/stories/FileUploadControlSimple.d.ts +3 -0
- package/dist/stories/FileUploadControlSmall.d.ts +3 -0
- package/dist/stories/FileUploadControlWithProgress.d.ts +3 -0
- package/dist/types.d.ts +162 -0
- package/dist/ui/button/Button.d.ts +18 -0
- package/dist/ui/button/index.d.ts +1 -0
- package/dist/ui/card/Card.d.ts +8 -0
- package/dist/ui/card/index.d.ts +1 -0
- package/dist/ui/dialog/Dialog.d.ts +19 -0
- package/dist/ui/dialog/index.d.ts +1 -0
- package/dist/ui/icons/index.d.ts +1 -0
- package/dist/ui/image-zoom/index.d.ts +3 -0
- package/dist/ui/progress/Progress.d.ts +4 -0
- package/dist/ui/progress/index.d.ts +1 -0
- package/dist/ui/select/Select.d.ts +13 -0
- package/dist/ui/select/index.d.ts +1 -0
- package/dist/ui/seperator/Seperator.d.ts +4 -0
- package/dist/ui/seperator/index.d.ts +1 -0
- package/dist/ui/tooltip/Tooltip.d.ts +7 -0
- package/dist/ui/tooltip/index.d.ts +1 -0
- package/dist/utils/api-mocker.d.ts +2 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/utils/date/index.d.ts +1 -0
- package/dist/utils/error-handling.d.ts +3 -0
- package/dist/utils/file-types.d.ts +36 -0
- package/dist/utils/image-processing/blob-to-base64.d.ts +1 -0
- package/dist/utils/image-processing/canvas-utils.d.ts +7 -0
- package/dist/utils/image-processing/index.d.ts +3 -0
- package/dist/utils/image-processing/load-image.d.ts +3 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/is-filedrop-error.d.ts +2 -0
- package/package.json +107 -0
package/README.md
ADDED
@@ -0,0 +1,421 @@
|
|
1
|
+
# React Upload Control
|
2
|
+
|
3
|
+
A modern, flexible file upload control for React applications.
|
4
|
+
|
5
|
+
> ⚠️ **Early Release Notice:** This library is in active development! While it's already battle-tested and production-ready, we're working on comprehensive documentation and additional features. The current docs provide basic usage - stay tuned for in-depth guides, examples, and advanced customization options coming soon!
|
6
|
+
|
7
|
+
React Upload Control is a free, lightweight and open-source file uploader library designed for modern React applications. This library is crafted to provide a high-quality developer experience (DX), making it easy to use for simple file uploads while offering extensive customization options for advanced use cases.
|
8
|
+
|
9
|
+
- 🚀 **Modern Stack:** Built with React 18+ and TypeScript for type-safe development
|
10
|
+
- 📁 **Drag & Drop:** Intuitive file uploading with visual feedback and validation
|
11
|
+
- 📋 **File Management:** Drag-to-reorder capability for organizing user uploads
|
12
|
+
- 📷 **Camera Integration:** Camera integration for capturing photos directly
|
13
|
+
- 💻 **Developer Experience:** Simple API with comprehensive TypeScript support and documentation
|
14
|
+
- 🌐 **Internationalization:** Built-in i18n support for multiple languages (currently English and German)
|
15
|
+
- 🎨 **Beautiful UI:** Modern, responsive design powered by Tailwind CSS
|
16
|
+
- 📱 **Mobile Ready:** Optimized experience across all device sizes
|
17
|
+
- ⚡ **Async Processing:** Handle file uploads asynchronously with progress updates
|
18
|
+
- 🔍 **File Preview:** Built-in preview support for images
|
19
|
+
- ⚙️ **Unopinionated:** You decide how and where files are uploaded, no vendor lock-in
|
20
|
+
- 🔓 **Open Source:** Free to use and modify under the MIT license
|
21
|
+
|
22
|
+
## Demo
|
23
|
+
|
24
|
+
Check out our interactive demo cases here:
|
25
|
+
[React Upload Control Demo](https://675c9582166050575d7b72e2-kpevajcgoj.chromatic.com/)
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
To install React Upload Control, use npm or yarn:
|
30
|
+
|
31
|
+
```bash
|
32
|
+
npm install @osmandvc/react-upload-control
|
33
|
+
```
|
34
|
+
|
35
|
+
or
|
36
|
+
|
37
|
+
```bash
|
38
|
+
yarn add @osmandvc/react-upload-control
|
39
|
+
```
|
40
|
+
|
41
|
+
## Getting Started
|
42
|
+
|
43
|
+
This section will guide you through the process of setting up everything you need to get started. The library is built around the concept of providers and the React Context API, which means you need to wrap your application in a `UploadedFilesProvider` provider. If you want to use the default use case of a list of files and a drop area, you can do this by wrapping your `FileUploadControl` component in the provider. An minimal example of this can be seen below:
|
44
|
+
|
45
|
+
```tsx
|
46
|
+
import React, { PropsWithChildren } from "react";
|
47
|
+
import {
|
48
|
+
FileUploadControl,
|
49
|
+
UploadedFilesProvider,
|
50
|
+
UploadedFile,
|
51
|
+
UploadFileResult,
|
52
|
+
} from "react-upload-control";
|
53
|
+
|
54
|
+
function MyFileUploadParent(props: PropsWithChildren) {
|
55
|
+
// Your custom delete and upload handlers (more about them later)...
|
56
|
+
// function handleDelete(files: UploadedFile[]) {...}
|
57
|
+
// function handleUpload(files: UploadedFile[], onProgressChange: (...) => void) {...}
|
58
|
+
|
59
|
+
function handleFinish(files: UploadedFile[]) {
|
60
|
+
console.log(files);
|
61
|
+
}
|
62
|
+
|
63
|
+
return (
|
64
|
+
<UploadedFilesProvider
|
65
|
+
handlers={{ onUpload: handleUpload, onFinish: handleFinish }}
|
66
|
+
config={{
|
67
|
+
mimeTypes: ["image/png", "image/jpeg"],
|
68
|
+
disableSorting: false, // Disable drag-to-reorder functionality
|
69
|
+
}}
|
70
|
+
>
|
71
|
+
<FileUploadControl />
|
72
|
+
</UploadedFilesProvider>
|
73
|
+
);
|
74
|
+
}
|
75
|
+
```
|
76
|
+
|
77
|
+
## Upload Handler Guide
|
78
|
+
|
79
|
+
The upload handler is a crucial part of the library that gives you complete control over how files are processed and uploaded.
|
80
|
+
|
81
|
+
The upload handler receives two parameters:
|
82
|
+
|
83
|
+
1. `files`: An array of `UploadedFile` objects to be uploaded
|
84
|
+
2. `onProgressChange`: A callback function to update the upload progress
|
85
|
+
|
86
|
+
The upload handler should return an array of `UploadFileResult` objects, which specify the success, error, and metadata for each file upload. The library will handle the UI updates based on the progress updates and final results you provide.
|
87
|
+
|
88
|
+
Here are two examples of implementing an upload handler:
|
89
|
+
|
90
|
+
### Example 1: Simple Batch Upload
|
91
|
+
|
92
|
+
```tsx
|
93
|
+
async function handleUpload(
|
94
|
+
files: UploadedFile[],
|
95
|
+
onProgressChange: (
|
96
|
+
fileId: string,
|
97
|
+
progress: number,
|
98
|
+
error?: { text: string; code: string }
|
99
|
+
) => void
|
100
|
+
): Promise<UploadFileResult[]> {
|
101
|
+
try {
|
102
|
+
// Set initial progress for all files
|
103
|
+
files.forEach((file) => {
|
104
|
+
onProgressChange(file.id, 0);
|
105
|
+
});
|
106
|
+
|
107
|
+
// Create form data with all files
|
108
|
+
const formData = new FormData();
|
109
|
+
files.forEach((file, index) => {
|
110
|
+
if (file.file) {
|
111
|
+
formData.append(`files`, file.file);
|
112
|
+
}
|
113
|
+
});
|
114
|
+
|
115
|
+
// Make API call with all files
|
116
|
+
const response = await fetch("https://api.example.com/upload", {
|
117
|
+
method: "POST",
|
118
|
+
body: formData,
|
119
|
+
});
|
120
|
+
|
121
|
+
if (!response.ok) {
|
122
|
+
throw new Error("Upload failed");
|
123
|
+
}
|
124
|
+
|
125
|
+
// Example API response with processed file data
|
126
|
+
const result = await response.json();
|
127
|
+
// { success: true, files: [{ id: "...", url: "..." }] }
|
128
|
+
|
129
|
+
// Set progress to 100% for all files after successful upload
|
130
|
+
files.forEach((file) => {
|
131
|
+
onProgressChange(file.id, 100);
|
132
|
+
});
|
133
|
+
|
134
|
+
// Return success results with metadata from API
|
135
|
+
return files.map((file, index) => ({
|
136
|
+
fileId: file.id,
|
137
|
+
success: true,
|
138
|
+
metadata: {
|
139
|
+
url: result.files[index].url,
|
140
|
+
uploadedAt: new Date().toISOString(),
|
141
|
+
},
|
142
|
+
}));
|
143
|
+
} catch (error) {
|
144
|
+
// Set error state for all files
|
145
|
+
const errorResult = {
|
146
|
+
text: error.message || "Upload failed",
|
147
|
+
code: "BATCH_UPLOAD_ERROR",
|
148
|
+
};
|
149
|
+
|
150
|
+
// Return error results for all files
|
151
|
+
return files.map((file) => ({
|
152
|
+
fileId: file.id,
|
153
|
+
success: false,
|
154
|
+
error: errorResult,
|
155
|
+
}));
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
// Usage with the UploadedFilesProvider
|
160
|
+
function MyFileUpload() {
|
161
|
+
return (
|
162
|
+
<UploadedFilesProvider
|
163
|
+
handlers={{
|
164
|
+
onUpload: handleUpload,
|
165
|
+
onFinish: (files) => {
|
166
|
+
// All files are uploaded successfully at this point
|
167
|
+
const urls = files.map((f) => f.metadata.url);
|
168
|
+
console.log("Uploaded file URLs:", urls);
|
169
|
+
},
|
170
|
+
}}
|
171
|
+
config={{
|
172
|
+
mimeTypes: ["image/jpeg", "image/png", "application/pdf"],
|
173
|
+
maxFileSizeMb: 10,
|
174
|
+
}}
|
175
|
+
>
|
176
|
+
<FileUploadControl />
|
177
|
+
</UploadedFilesProvider>
|
178
|
+
);
|
179
|
+
}
|
180
|
+
```
|
181
|
+
|
182
|
+
### Example 2: Real-World AWS S3 Example
|
183
|
+
|
184
|
+
```tsx
|
185
|
+
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
|
186
|
+
import { Upload } from "@aws-sdk/lib-storage";
|
187
|
+
|
188
|
+
async function handleS3Upload(
|
189
|
+
files: UploadedFile[],
|
190
|
+
onProgressChange: (
|
191
|
+
fileId: string,
|
192
|
+
progress: number,
|
193
|
+
error?: { text: string; code: string }
|
194
|
+
) => void
|
195
|
+
): Promise<UploadFileResult[]> {
|
196
|
+
// Initialize the S3 client
|
197
|
+
const s3Client = new S3Client({
|
198
|
+
region: "your-region",
|
199
|
+
credentials: {
|
200
|
+
accessKeyId: "your-access-key",
|
201
|
+
secretAccessKey: "your-secret-key",
|
202
|
+
},
|
203
|
+
});
|
204
|
+
|
205
|
+
return Promise.all(
|
206
|
+
files.map(async (file) => {
|
207
|
+
try {
|
208
|
+
if (!file.file) throw new Error("No file provided");
|
209
|
+
|
210
|
+
// Generate a unique key for the file
|
211
|
+
const key = `uploads/${Date.now()}-${file.name}`;
|
212
|
+
|
213
|
+
// Create the upload
|
214
|
+
const upload = new Upload({
|
215
|
+
client: s3Client,
|
216
|
+
params: {
|
217
|
+
Bucket: "your-bucket-name",
|
218
|
+
Key: key,
|
219
|
+
Body: file.file,
|
220
|
+
ContentType: file.file.type,
|
221
|
+
// Optional: Set additional parameters
|
222
|
+
// ACL: 'public-read',
|
223
|
+
// Metadata: { /* your metadata */ }
|
224
|
+
},
|
225
|
+
});
|
226
|
+
|
227
|
+
// Handle upload progress
|
228
|
+
upload.on("httpUploadProgress", (progress) => {
|
229
|
+
const percentage = Math.round(
|
230
|
+
((progress.loaded || 0) * 100) / (progress.total || 100)
|
231
|
+
);
|
232
|
+
onProgressChange(file.id, percentage);
|
233
|
+
});
|
234
|
+
|
235
|
+
// Perform the upload
|
236
|
+
await upload.done();
|
237
|
+
|
238
|
+
// Return success result with the S3 URL
|
239
|
+
return {
|
240
|
+
fileId: file.id,
|
241
|
+
success: true,
|
242
|
+
metadata: {
|
243
|
+
url: `https://your-bucket-name.s3.your-region.amazonaws.com/${key}`,
|
244
|
+
},
|
245
|
+
};
|
246
|
+
} catch (error) {
|
247
|
+
console.error("S3 upload error:", error);
|
248
|
+
return {
|
249
|
+
fileId: file.id,
|
250
|
+
success: false,
|
251
|
+
error: {
|
252
|
+
text: error.message || "S3 upload failed",
|
253
|
+
code: "S3_UPLOAD_ERROR",
|
254
|
+
},
|
255
|
+
};
|
256
|
+
}
|
257
|
+
})
|
258
|
+
);
|
259
|
+
}
|
260
|
+
|
261
|
+
// Usage with the UploadedFilesProvider
|
262
|
+
function MyFileUpload() {
|
263
|
+
return (
|
264
|
+
<UploadedFilesProvider
|
265
|
+
handlers={{
|
266
|
+
onUpload: handleS3Upload,
|
267
|
+
onFinish: (files) => {
|
268
|
+
// All files are successfully uploaded at this point
|
269
|
+
const urls = files.map((f) => f.metadata.url);
|
270
|
+
console.log("Uploaded file URLs:", urls);
|
271
|
+
},
|
272
|
+
}}
|
273
|
+
config={{
|
274
|
+
mimeTypes: ["image/jpeg", "image/png", "application/pdf"],
|
275
|
+
maxFileSizeMb: 10,
|
276
|
+
}}
|
277
|
+
>
|
278
|
+
<FileUploadControl />
|
279
|
+
</UploadedFilesProvider>
|
280
|
+
);
|
281
|
+
}
|
282
|
+
```
|
283
|
+
|
284
|
+
## onDelete Handler
|
285
|
+
|
286
|
+
The `onDelete` handler is designed to be non-blocking and does not include progress tracking. This is intentional for better UX - since it's primarily used for cleanup when resetting a control with already finished uploads. Users should be able to reset the control immediately without waiting for deletion to complete or being blocked by deletion errors.
|
287
|
+
|
288
|
+
```typescript
|
289
|
+
interface Props {
|
290
|
+
onDelete?: (files: UploadedFile[]) => void | Promise<void>;
|
291
|
+
}
|
292
|
+
```
|
293
|
+
|
294
|
+
> Note: Unlike `onUpload`, the `onDelete` handler won't show progress or block the UI. This ensures users can quickly reset or clear their upload state without delays.
|
295
|
+
|
296
|
+
## Core Components
|
297
|
+
|
298
|
+
### FileUploadControl
|
299
|
+
|
300
|
+
The default component that provides the file upload interface with a FileList and FileDropArea.
|
301
|
+
|
302
|
+
```tsx
|
303
|
+
<FileUploadControl
|
304
|
+
size="auto" // 'auto' | 'sm' | 'lg'
|
305
|
+
disableCamera={false} // Disable camera integration
|
306
|
+
disableFileSystem={false} // Disable file system uploads
|
307
|
+
/>
|
308
|
+
```
|
309
|
+
|
310
|
+
### UploadedFilesProvider
|
311
|
+
|
312
|
+
The provider component that manages the upload state and configuration.
|
313
|
+
|
314
|
+
```tsx
|
315
|
+
<UploadedFilesProvider
|
316
|
+
config={{
|
317
|
+
mimeTypes: ["image/jpeg", "image/png"], // Allowed file types
|
318
|
+
maxFileSizeMb: 10, // Maximum file size in MB
|
319
|
+
multiple: true, // Allow multiple file uploads
|
320
|
+
maxFiles: 5, // Maximum number of files
|
321
|
+
locale: "en", // Locale for i18n
|
322
|
+
resetOnFinish: false, // Reset state after finish
|
323
|
+
disableSorting: false, // Disable drag-to-reorder functionality
|
324
|
+
}}
|
325
|
+
handlers={{
|
326
|
+
onUpload: handleUpload, // Upload handler function
|
327
|
+
onDelete: handleDelete, // Delete handler function
|
328
|
+
onFinish: handleFinish, // Finish handler function
|
329
|
+
}}
|
330
|
+
/>
|
331
|
+
```
|
332
|
+
|
333
|
+
## API Reference
|
334
|
+
|
335
|
+
### UploadedFilesProvider Props
|
336
|
+
|
337
|
+
| Prop | Type | Default | Description |
|
338
|
+
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------------------------------------------- |
|
339
|
+
| config | { mimeTypes: string[], maxFileSizeMb: number, multiple: boolean, maxFiles: number, locale: string, resetOnFinish: boolean, disableSorting: boolean } | required | Configuration object |
|
340
|
+
| handlers | { onUpload: (files: UploadedFile[]) => Promise<UploadFileResult[]>, onDelete: (files: UploadedFile[]) => Promise<UploadFileResult[]>, onFinish: (files: UploadedFile[]) => void } | required | Handlers object |
|
341
|
+
| children | React.ReactNode | required | Child components to render |
|
342
|
+
| initFiles | UploadedFile[] | undefined | Initial files to populate the uploader with |
|
343
|
+
| locale | string | 'en' | Locale for internationalization |
|
344
|
+
|
345
|
+
### FileUploadControl Props
|
346
|
+
|
347
|
+
| Prop | Type | Default | Description |
|
348
|
+
| ----------------- | ---------------------- | --------- | --------------------------- |
|
349
|
+
| size | 'auto' \| 'sm' \| 'lg' | 'auto' | Component size variant |
|
350
|
+
| disableCamera | boolean | false | Disable camera integration |
|
351
|
+
| disableFileSystem | boolean | false | Disable file system uploads |
|
352
|
+
| className | string | undefined | Additional CSS classes |
|
353
|
+
|
354
|
+
## Understanding the UploadedFile Type
|
355
|
+
|
356
|
+
When implementing your upload handlers, you'll work with the `UploadedFile` type, which provides access to various file properties:
|
357
|
+
|
358
|
+
```typescript
|
359
|
+
interface UploadedFile {
|
360
|
+
id: string; // Unique identifier for the file
|
361
|
+
file?: File; // The actual File object
|
362
|
+
name: string; // File name
|
363
|
+
size?: number; // File size in bytes
|
364
|
+
type: string; // MIME type
|
365
|
+
base64Uri?: string; // Base64 encoded file content
|
366
|
+
previewImg?: {
|
367
|
+
// Preview image data (for images)
|
368
|
+
imgBase64Uri: string;
|
369
|
+
width?: number;
|
370
|
+
height?: number;
|
371
|
+
};
|
372
|
+
uploadStatus: {
|
373
|
+
// Current upload status
|
374
|
+
stage?: "IDLE" | "FINISHED" | "FAILED" | "UPLOADING" | "REMOVING";
|
375
|
+
progress?: number; // Upload progress (0-100)
|
376
|
+
error?: {
|
377
|
+
text: string; // Error message
|
378
|
+
code: string; // Error code
|
379
|
+
};
|
380
|
+
};
|
381
|
+
order?: number; // File order in the list
|
382
|
+
metadata?: {
|
383
|
+
// Custom metadata
|
384
|
+
[key: string]: any;
|
385
|
+
};
|
386
|
+
}
|
387
|
+
```
|
388
|
+
|
389
|
+
## Creating Custom Upload Sources and Destinations
|
390
|
+
|
391
|
+
The `useUploadFilesProvider` hook allows you to create your own file sources (like drop areas) and file destinations (like file lists) with ease. The provider handles all the complex validation and state management for you.
|
392
|
+
|
393
|
+
The provider abstracts away:
|
394
|
+
|
395
|
+
- File validation (size, type, count)
|
396
|
+
- Progress tracking
|
397
|
+
- File state management
|
398
|
+
- Error handling
|
399
|
+
- Upload coordination
|
400
|
+
|
401
|
+
> 🔍 **Coming Soon**: Detailed documentation on creating custom upload components, handling file preprocessing, and implementing advanced validation logic.
|
402
|
+
|
403
|
+
## Customization
|
404
|
+
|
405
|
+
React Upload Control is highly customizable. You can tailor it to meet your specific needs by adjusting its configuration and using its extensive API. <i> Detailed documentation coming soon. </i>
|
406
|
+
|
407
|
+
## Contributing
|
408
|
+
|
409
|
+
We welcome contributions from the community. Feel free to open issues or submit pull requests on our [GitHub repository](https://github.com/osmandvc/react-upload-control).
|
410
|
+
|
411
|
+
Please note that while React Upload Control is in an early state and has been battle-tested, bugs may still appear. We would appreciate it if you report any issues you encounter so they can be fixed as soon as possible. Contributions to improve the library are **very welcome**.
|
412
|
+
|
413
|
+
Because the library is in its early stages, **we are open to suggestions and feedback. If you have any ideas for new features or enhancements, please don't hesitate to share them with us.**
|
414
|
+
|
415
|
+
## License
|
416
|
+
|
417
|
+
This project is licensed under the MIT License.
|
418
|
+
|
419
|
+
---
|
420
|
+
|
421
|
+
MIT © Osman Deveci
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { PropsWithChildren } from "react";
|
2
|
+
/**
|
3
|
+
* The Default Container for the File Upload Control
|
4
|
+
*/
|
5
|
+
interface ContainerProps extends PropsWithChildren {
|
6
|
+
className?: string;
|
7
|
+
}
|
8
|
+
export declare const FileUploadContainer: ({ className, children, }: ContainerProps) => import("react/jsx-runtime").JSX.Element;
|
9
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { FileUploadControlProps } from "./types";
|
2
|
+
/**
|
3
|
+
* The Default File-Upload-Control Component with a Drop-Area and a List which displays the Files.
|
4
|
+
*/
|
5
|
+
export declare const FileUploadControl: ({ className, children, disableCamera, disableFileSystem, size, }: FileUploadControlProps) => import("react/jsx-runtime").JSX.Element;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const FileDeleteAllButton: () => import("react/jsx-runtime").JSX.Element;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const FileUploadAllButton: () => import("react/jsx-runtime").JSX.Element;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import React from "react";
|
2
|
+
interface ScreenshotDimensions {
|
3
|
+
width: number;
|
4
|
+
height: number;
|
5
|
+
}
|
6
|
+
interface ChildrenProps {
|
7
|
+
getScreenshot: (screenshotDimensions?: ScreenshotDimensions) => string | null;
|
8
|
+
}
|
9
|
+
export type WebcamProps = Omit<React.HTMLProps<HTMLVideoElement>, "ref"> & {
|
10
|
+
audio: boolean;
|
11
|
+
audioConstraints?: MediaStreamConstraints["audio"];
|
12
|
+
forceScreenshotSourceSize: boolean;
|
13
|
+
imageSmoothing: boolean;
|
14
|
+
mirrored: boolean;
|
15
|
+
minScreenshotHeight?: number;
|
16
|
+
minScreenshotWidth?: number;
|
17
|
+
onUserMedia: (stream: MediaStream) => void;
|
18
|
+
onUserMediaError: (error: string | DOMException) => void;
|
19
|
+
screenshotFormat: "image/webp" | "image/png" | "image/jpeg";
|
20
|
+
screenshotQuality: number;
|
21
|
+
videoConstraints?: MediaStreamConstraints["video"];
|
22
|
+
children?: (childrenProps: ChildrenProps) => JSX.Element;
|
23
|
+
};
|
24
|
+
interface WebcamState {
|
25
|
+
hasUserMedia: boolean;
|
26
|
+
src?: string;
|
27
|
+
}
|
28
|
+
export default class Webcam extends React.Component<WebcamProps, WebcamState> {
|
29
|
+
static defaultProps: {
|
30
|
+
audio: boolean;
|
31
|
+
forceScreenshotSourceSize: boolean;
|
32
|
+
imageSmoothing: boolean;
|
33
|
+
mirrored: boolean;
|
34
|
+
onUserMedia: () => undefined;
|
35
|
+
onUserMediaError: () => undefined;
|
36
|
+
screenshotFormat: string;
|
37
|
+
screenshotQuality: number;
|
38
|
+
};
|
39
|
+
private canvas;
|
40
|
+
private ctx;
|
41
|
+
private requestUserMediaId;
|
42
|
+
private unmounted;
|
43
|
+
private requestedUserMedia;
|
44
|
+
stream: MediaStream | null;
|
45
|
+
video: HTMLVideoElement | null;
|
46
|
+
constructor(props: WebcamProps);
|
47
|
+
componentDidMount(): void;
|
48
|
+
componentDidUpdate(nextProps: WebcamProps): void;
|
49
|
+
componentWillUnmount(): void;
|
50
|
+
private static stopMediaStream;
|
51
|
+
private stopAndCleanup;
|
52
|
+
getScreenshot(screenshotDimensions?: ScreenshotDimensions): string | null;
|
53
|
+
getCanvas(screenshotDimensions?: ScreenshotDimensions): HTMLCanvasElement | null;
|
54
|
+
private requestUserMedia;
|
55
|
+
private handleUserMedia;
|
56
|
+
render(): import("react/jsx-runtime").JSX.Element;
|
57
|
+
}
|
58
|
+
export {};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
interface WebcamFrameProps {
|
2
|
+
width: number;
|
3
|
+
height: number;
|
4
|
+
offset?: {
|
5
|
+
top: number;
|
6
|
+
right: number;
|
7
|
+
bottom: number;
|
8
|
+
left: number;
|
9
|
+
};
|
10
|
+
proportion?: number;
|
11
|
+
}
|
12
|
+
export declare function getFrame(props: WebcamFrameProps): {
|
13
|
+
x: number;
|
14
|
+
y: number;
|
15
|
+
width: number;
|
16
|
+
height: number;
|
17
|
+
orientation: string;
|
18
|
+
};
|
19
|
+
export declare function WebcamFrameA4(props: WebcamFrameProps): import("react/jsx-runtime").JSX.Element;
|
20
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./WebcamFrameA4";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./use-webcam";
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import React from "react";
|
2
|
+
export type WebcamOutputProps = {
|
3
|
+
imageUriBase64: string | undefined;
|
4
|
+
imageData: ImageData | undefined;
|
5
|
+
};
|
6
|
+
type WebcamProps = {
|
7
|
+
outputImageUriBase64: boolean;
|
8
|
+
outputImageData: boolean;
|
9
|
+
targetWidth: number;
|
10
|
+
targetHeight: number;
|
11
|
+
screenshotFormat: "image/jpeg" | "image/webp" | "image/png" | undefined;
|
12
|
+
screenshotQuality: number;
|
13
|
+
imageSmoothing: boolean;
|
14
|
+
mirrored: boolean;
|
15
|
+
videoConstraints: any;
|
16
|
+
onCapture(img: WebcamOutputProps): void;
|
17
|
+
onUserMediaError(error: string | DOMException): void;
|
18
|
+
onToggleDevice(): void;
|
19
|
+
};
|
20
|
+
export declare function useWebcam(props: Partial<WebcamProps>): {
|
21
|
+
WebcamComponent: () => import("react/jsx-runtime").JSX.Element;
|
22
|
+
userMediaStatus: string;
|
23
|
+
userMediaError: string | Error | undefined;
|
24
|
+
userMediaErrorString: string;
|
25
|
+
getDevices: () => Promise<MediaDeviceInfo[] | undefined>;
|
26
|
+
deviceCount: number | undefined;
|
27
|
+
selectedDeviceId: string | null;
|
28
|
+
setSelectedDeviceId: React.Dispatch<React.SetStateAction<string | null>>;
|
29
|
+
doCaptureImage: () => void;
|
30
|
+
doRotateDevice: () => void;
|
31
|
+
doMirrorDevice: () => void;
|
32
|
+
doNextDevice: () => Promise<void>;
|
33
|
+
};
|
34
|
+
export {};
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { FileLoaderActionsProps } from "../../types";
|
3
|
+
export declare const FileDropLarge: ({ children, disableCamera, disableFileSystem, className, disabled, }: FileLoaderActionsProps & {
|
4
|
+
children?: React.ReactNode;
|
5
|
+
className?: string;
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { FileLoaderActionsProps } from "../../types";
|
3
|
+
export declare const FileDropSmall: ({ children, disableCamera, disableFileSystem, className, }: FileLoaderActionsProps & {
|
4
|
+
children?: React.ReactNode;
|
5
|
+
className?: string;
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const FileListActions: () => import("react/jsx-runtime").JSX.Element;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { FileListItemProps } from "../../types";
|
3
|
+
export declare const FileListItem: React.MemoExoticComponent<({ size, name, previewImgSrc, id, uploadStatus, order, count, disabled, disableSorting, }: FileListItemProps) => import("react/jsx-runtime").JSX.Element>;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
export declare enum STATUS {
|
2
|
+
IDLE = "IDLE",
|
3
|
+
LOADING = "LOADING",
|
4
|
+
PROCESSING = "PROCESSING",
|
5
|
+
ERROR = "ERROR",
|
6
|
+
READY = "READY",
|
7
|
+
PENDING = "PENDING"
|
8
|
+
}
|
9
|
+
export declare function useStateMachine(initialStatus?: string, initialValue?: any): {
|
10
|
+
smStatus: string;
|
11
|
+
smStatusIs: (...args: string[]) => boolean;
|
12
|
+
smStatusIsnt: (...args: string[]) => boolean;
|
13
|
+
smIsError: boolean;
|
14
|
+
smError: string | Error | undefined;
|
15
|
+
smErrorString: string;
|
16
|
+
smValue: any;
|
17
|
+
smGetStatus: () => string;
|
18
|
+
smSetStatus: (newStatus: string, error?: string | Error | undefined, value?: any) => void;
|
19
|
+
smResetStatus: (newStatus: string) => void;
|
20
|
+
status: typeof STATUS;
|
21
|
+
};
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
import "@/src/styles/tailwind.css";
|
2
|
+
export { FileUploadContainer } from "./FileUploadContainer";
|
3
|
+
export { FileUploadControl } from "./FileUploadControl";
|
4
|
+
export { UploadedFilesProvider } from "./providers";
|
5
|
+
export { isFileDropError } from "./utils";
|
6
|
+
export * from "./types";
|