@jobber/components 9.16.7-update-inp-2e263d0.2 → 9.16.7
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/Countdown/index.cjs +2 -0
- package/dist/Countdown/index.mjs +2 -0
- package/dist/Countdown-cjs.js +23 -1204
- package/dist/Countdown-es.js +1 -1182
- package/dist/InputAvatar/index.cjs +2 -1
- package/dist/InputAvatar/index.mjs +2 -1
- package/dist/InputFile/index.cjs +2 -1
- package/dist/InputFile/index.mjs +2 -1
- package/dist/InputFile-cjs.js +1370 -1157
- package/dist/InputFile-es.js +1372 -1159
- package/dist/docs/Elevations/Elevations.md +7 -0
- package/dist/docs/InputFile/InputFile.md +1 -3
- package/dist/index-cjs.js +1189 -0
- package/dist/index-es.js +1186 -0
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +1 -0
- package/dist/tslib.es6-cjs.js +54 -0
- package/dist/tslib.es6-es.js +53 -1
- package/package.json +4 -4
package/dist/InputFile-cjs.js
CHANGED
|
@@ -3,1220 +3,1441 @@
|
|
|
3
3
|
var tslib_es6 = require('./tslib.es6-cjs.js');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var classnames = require('classnames');
|
|
6
|
-
var
|
|
6
|
+
var index = require('./index-cjs.js');
|
|
7
7
|
var axios = require('axios');
|
|
8
8
|
var Text = require('./Text-cjs.js');
|
|
9
9
|
var Button = require('./Button-cjs.js');
|
|
10
10
|
var InputValidation = require('./InputValidation-cjs.js');
|
|
11
11
|
var Content = require('./Content-cjs.js');
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
13
|
+
var COMMON_MIME_TYPES = new Map([
|
|
14
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
|
15
|
+
['aac', 'audio/aac'],
|
|
16
|
+
['abw', 'application/x-abiword'],
|
|
17
|
+
['arc', 'application/x-freearc'],
|
|
18
|
+
['avif', 'image/avif'],
|
|
19
|
+
['avi', 'video/x-msvideo'],
|
|
20
|
+
['azw', 'application/vnd.amazon.ebook'],
|
|
21
|
+
['bin', 'application/octet-stream'],
|
|
22
|
+
['bmp', 'image/bmp'],
|
|
23
|
+
['bz', 'application/x-bzip'],
|
|
24
|
+
['bz2', 'application/x-bzip2'],
|
|
25
|
+
['cda', 'application/x-cdf'],
|
|
26
|
+
['csh', 'application/x-csh'],
|
|
27
|
+
['css', 'text/css'],
|
|
28
|
+
['csv', 'text/csv'],
|
|
29
|
+
['doc', 'application/msword'],
|
|
30
|
+
['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
31
|
+
['eot', 'application/vnd.ms-fontobject'],
|
|
32
|
+
['epub', 'application/epub+zip'],
|
|
33
|
+
['gz', 'application/gzip'],
|
|
34
|
+
['gif', 'image/gif'],
|
|
35
|
+
['htm', 'text/html'],
|
|
36
|
+
['html', 'text/html'],
|
|
37
|
+
['ico', 'image/vnd.microsoft.icon'],
|
|
38
|
+
['ics', 'text/calendar'],
|
|
39
|
+
['jar', 'application/java-archive'],
|
|
40
|
+
['jpeg', 'image/jpeg'],
|
|
41
|
+
['jpg', 'image/jpeg'],
|
|
42
|
+
['js', 'text/javascript'],
|
|
43
|
+
['json', 'application/json'],
|
|
44
|
+
['jsonld', 'application/ld+json'],
|
|
45
|
+
['mid', 'audio/midi'],
|
|
46
|
+
['midi', 'audio/midi'],
|
|
47
|
+
['mjs', 'text/javascript'],
|
|
48
|
+
['mp3', 'audio/mpeg'],
|
|
49
|
+
['mp4', 'video/mp4'],
|
|
50
|
+
['mpeg', 'video/mpeg'],
|
|
51
|
+
['mpkg', 'application/vnd.apple.installer+xml'],
|
|
52
|
+
['odp', 'application/vnd.oasis.opendocument.presentation'],
|
|
53
|
+
['ods', 'application/vnd.oasis.opendocument.spreadsheet'],
|
|
54
|
+
['odt', 'application/vnd.oasis.opendocument.text'],
|
|
55
|
+
['oga', 'audio/ogg'],
|
|
56
|
+
['ogv', 'video/ogg'],
|
|
57
|
+
['ogx', 'application/ogg'],
|
|
58
|
+
['opus', 'audio/opus'],
|
|
59
|
+
['otf', 'font/otf'],
|
|
60
|
+
['png', 'image/png'],
|
|
61
|
+
['pdf', 'application/pdf'],
|
|
62
|
+
['php', 'application/x-httpd-php'],
|
|
63
|
+
['ppt', 'application/vnd.ms-powerpoint'],
|
|
64
|
+
['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
|
|
65
|
+
['rar', 'application/vnd.rar'],
|
|
66
|
+
['rtf', 'application/rtf'],
|
|
67
|
+
['sh', 'application/x-sh'],
|
|
68
|
+
['svg', 'image/svg+xml'],
|
|
69
|
+
['swf', 'application/x-shockwave-flash'],
|
|
70
|
+
['tar', 'application/x-tar'],
|
|
71
|
+
['tif', 'image/tiff'],
|
|
72
|
+
['tiff', 'image/tiff'],
|
|
73
|
+
['ts', 'video/mp2t'],
|
|
74
|
+
['ttf', 'font/ttf'],
|
|
75
|
+
['txt', 'text/plain'],
|
|
76
|
+
['vsd', 'application/vnd.visio'],
|
|
77
|
+
['wav', 'audio/wav'],
|
|
78
|
+
['weba', 'audio/webm'],
|
|
79
|
+
['webm', 'video/webm'],
|
|
80
|
+
['webp', 'image/webp'],
|
|
81
|
+
['woff', 'font/woff'],
|
|
82
|
+
['woff2', 'font/woff2'],
|
|
83
|
+
['xhtml', 'application/xhtml+xml'],
|
|
84
|
+
['xls', 'application/vnd.ms-excel'],
|
|
85
|
+
['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
86
|
+
['xml', 'application/xml'],
|
|
87
|
+
['xul', 'application/vnd.mozilla.xul+xml'],
|
|
88
|
+
['zip', 'application/zip'],
|
|
89
|
+
['7z', 'application/x-7z-compressed'],
|
|
90
|
+
// Others
|
|
91
|
+
['mkv', 'video/x-matroska'],
|
|
92
|
+
['mov', 'video/quicktime'],
|
|
93
|
+
['msg', 'application/vnd.ms-outlook']
|
|
62
94
|
]);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
configurable: false,
|
|
101
|
-
enumerable: true
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return file;
|
|
105
|
-
}
|
|
106
|
-
function setObjProp(f, key, value) {
|
|
107
|
-
Object.defineProperty(f, key, {
|
|
108
|
-
value,
|
|
109
|
-
writable: false,
|
|
110
|
-
configurable: false,
|
|
111
|
-
enumerable: true
|
|
112
|
-
});
|
|
95
|
+
function toFileWithPath(file, path) {
|
|
96
|
+
var f = withMimeType(file);
|
|
97
|
+
if (typeof f.path !== 'string') { // on electron, path is already set to the absolute path
|
|
98
|
+
var webkitRelativePath = file.webkitRelativePath;
|
|
99
|
+
Object.defineProperty(f, 'path', {
|
|
100
|
+
value: typeof path === 'string'
|
|
101
|
+
? path
|
|
102
|
+
// If <input webkitdirectory> is set,
|
|
103
|
+
// the File will have a {webkitRelativePath} property
|
|
104
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory
|
|
105
|
+
: typeof webkitRelativePath === 'string' && webkitRelativePath.length > 0
|
|
106
|
+
? webkitRelativePath
|
|
107
|
+
: file.name,
|
|
108
|
+
writable: false,
|
|
109
|
+
configurable: false,
|
|
110
|
+
enumerable: true
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return f;
|
|
114
|
+
}
|
|
115
|
+
function withMimeType(file) {
|
|
116
|
+
var name = file.name;
|
|
117
|
+
var hasExtension = name && name.lastIndexOf('.') !== -1;
|
|
118
|
+
if (hasExtension && !file.type) {
|
|
119
|
+
var ext = name.split('.')
|
|
120
|
+
.pop().toLowerCase();
|
|
121
|
+
var type = COMMON_MIME_TYPES.get(ext);
|
|
122
|
+
if (type) {
|
|
123
|
+
Object.defineProperty(file, 'type', {
|
|
124
|
+
value: type,
|
|
125
|
+
writable: false,
|
|
126
|
+
configurable: false,
|
|
127
|
+
enumerable: true
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return file;
|
|
113
132
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
133
|
+
|
|
134
|
+
var FILES_TO_IGNORE = [
|
|
135
|
+
// Thumbnail cache files for macOS and Windows
|
|
136
|
+
'.DS_Store',
|
|
137
|
+
'Thumbs.db' // Windows
|
|
138
|
+
];
|
|
117
139
|
/**
|
|
118
|
-
* Convert a DragEvent's DataTrasfer object to a list of File objects
|
|
119
|
-
* NOTE: If some of the items are folders,
|
|
120
|
-
* everything will be flattened and placed in the same list but the paths will be kept as a {path} property.
|
|
121
|
-
*
|
|
122
|
-
* A https://developer.mozilla.org/en-US/docs/Web/API/
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
* Convert a DragEvent's DataTrasfer object to a list of File objects
|
|
141
|
+
* NOTE: If some of the items are folders,
|
|
142
|
+
* everything will be flattened and placed in the same list but the paths will be kept as a {path} property.
|
|
143
|
+
*
|
|
144
|
+
* EXPERIMENTAL: A list of https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle objects can also be passed as an arg
|
|
145
|
+
* and a list of File objects will be returned.
|
|
146
|
+
*
|
|
147
|
+
* @param evt
|
|
148
|
+
*/
|
|
149
|
+
function fromEvent(evt) {
|
|
150
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function () {
|
|
151
|
+
return tslib_es6.__generator(this, function (_a) {
|
|
152
|
+
if (isObject(evt) && isDataTransfer(evt)) {
|
|
153
|
+
return [2 /*return*/, getDataTransferFiles(evt.dataTransfer, evt.type)];
|
|
154
|
+
}
|
|
155
|
+
else if (isChangeEvt(evt)) {
|
|
156
|
+
return [2 /*return*/, getInputFiles(evt)];
|
|
157
|
+
}
|
|
158
|
+
else if (Array.isArray(evt) && evt.every(function (item) { return 'getFile' in item && typeof item.getFile === 'function'; })) {
|
|
159
|
+
return [2 /*return*/, getFsHandleFiles(evt)];
|
|
160
|
+
}
|
|
161
|
+
return [2 /*return*/, []];
|
|
162
|
+
});
|
|
163
|
+
});
|
|
140
164
|
}
|
|
141
165
|
function isDataTransfer(value) {
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
function isClipboardEvt(value) {
|
|
145
|
-
return isObject(value) && isDataTransfer(value.clipboardData);
|
|
166
|
+
return isObject(value.dataTransfer);
|
|
146
167
|
}
|
|
147
168
|
function isChangeEvt(value) {
|
|
148
|
-
|
|
169
|
+
return isObject(value) && isObject(value.target);
|
|
149
170
|
}
|
|
150
171
|
function isObject(v) {
|
|
151
|
-
|
|
172
|
+
return typeof v === 'object' && v !== null;
|
|
152
173
|
}
|
|
153
174
|
function getInputFiles(evt) {
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
175
|
+
return fromList(evt.target.files).map(function (file) { return toFileWithPath(file); });
|
|
176
|
+
}
|
|
177
|
+
// Ee expect each handle to be https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle
|
|
178
|
+
function getFsHandleFiles(handles) {
|
|
179
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function () {
|
|
180
|
+
var files;
|
|
181
|
+
return tslib_es6.__generator(this, function (_a) {
|
|
182
|
+
switch (_a.label) {
|
|
183
|
+
case 0: return [4 /*yield*/, Promise.all(handles.map(function (h) { return h.getFile(); }))];
|
|
184
|
+
case 1:
|
|
185
|
+
files = _a.sent();
|
|
186
|
+
return [2 /*return*/, files.map(function (file) { return toFileWithPath(file); })];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
163
190
|
}
|
|
164
|
-
function
|
|
165
|
-
|
|
166
|
-
|
|
191
|
+
function getDataTransferFiles(dt, type) {
|
|
192
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function () {
|
|
193
|
+
var items, files;
|
|
194
|
+
return tslib_es6.__generator(this, function (_a) {
|
|
195
|
+
switch (_a.label) {
|
|
196
|
+
case 0:
|
|
197
|
+
if (dt === null) {
|
|
198
|
+
return [2 /*return*/, []];
|
|
199
|
+
}
|
|
200
|
+
if (!dt.items) return [3 /*break*/, 2];
|
|
201
|
+
items = fromList(dt.items)
|
|
202
|
+
.filter(function (item) { return item.kind === 'file'; });
|
|
203
|
+
// According to https://html.spec.whatwg.org/multipage/dnd.html#dndevents,
|
|
204
|
+
// only 'dragstart' and 'drop' has access to the data (source node)
|
|
205
|
+
if (type !== 'drop') {
|
|
206
|
+
return [2 /*return*/, items];
|
|
207
|
+
}
|
|
208
|
+
return [4 /*yield*/, Promise.all(items.map(toFilePromises))];
|
|
209
|
+
case 1:
|
|
210
|
+
files = _a.sent();
|
|
211
|
+
return [2 /*return*/, noIgnoredFiles(flatten(files))];
|
|
212
|
+
case 2: return [2 /*return*/, noIgnoredFiles(fromList(dt.files)
|
|
213
|
+
.map(function (file) { return toFileWithPath(file); }))];
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
});
|
|
167
217
|
}
|
|
168
218
|
function noIgnoredFiles(files) {
|
|
169
|
-
|
|
219
|
+
return files.filter(function (file) { return FILES_TO_IGNORE.indexOf(file.name) === -1; });
|
|
170
220
|
}
|
|
221
|
+
// IE11 does not support Array.from()
|
|
222
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Browser_compatibility
|
|
223
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/FileList
|
|
224
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItemList
|
|
171
225
|
function fromList(items) {
|
|
172
|
-
|
|
173
|
-
|
|
226
|
+
if (items === null) {
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
var files = [];
|
|
230
|
+
// tslint:disable: prefer-for-of
|
|
231
|
+
for (var i = 0; i < items.length; i++) {
|
|
232
|
+
var file = items[i];
|
|
233
|
+
files.push(file);
|
|
234
|
+
}
|
|
235
|
+
return files;
|
|
174
236
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
237
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem
|
|
238
|
+
function toFilePromises(item) {
|
|
239
|
+
if (typeof item.webkitGetAsEntry !== 'function') {
|
|
240
|
+
return fromDataTransferItem(item);
|
|
241
|
+
}
|
|
242
|
+
var entry = item.webkitGetAsEntry();
|
|
243
|
+
// Safari supports dropping an image node from a different window and can be retrieved using
|
|
244
|
+
// the DataTransferItem.getAsFile() API
|
|
245
|
+
// NOTE: FileSystemEntry.file() throws if trying to get the file
|
|
246
|
+
if (entry && entry.isDirectory) {
|
|
247
|
+
return fromDirEntry(entry);
|
|
248
|
+
}
|
|
249
|
+
return fromDataTransferItem(item);
|
|
184
250
|
}
|
|
185
251
|
function flatten(items) {
|
|
186
|
-
|
|
187
|
-
for (const item of items) if (Array.isArray(item)) result.push(...flatten(item));
|
|
188
|
-
else result.push(item);
|
|
189
|
-
return result;
|
|
252
|
+
return items.reduce(function (acc, files) { return tslib_es6.__spread(acc, (Array.isArray(files) ? flatten(files) : [files])); }, []);
|
|
190
253
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const files = [];
|
|
207
|
-
for await (const child of handle.values()) {
|
|
208
|
-
const childPath = `${path}/${child.name}`;
|
|
209
|
-
if (child.kind === "directory") files.push(...await fromDirHandle(child, childPath));
|
|
210
|
-
else {
|
|
211
|
-
const file = await child.getFile();
|
|
212
|
-
files.push(toFileWithPath(file, childPath, child));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return files;
|
|
216
|
-
}
|
|
217
|
-
async function fromEntry(entry) {
|
|
218
|
-
return entry.isDirectory ? fromDirEntry(entry) : fromFileEntry(entry);
|
|
254
|
+
function fromDataTransferItem(item) {
|
|
255
|
+
var file = item.getAsFile();
|
|
256
|
+
if (!file) {
|
|
257
|
+
return Promise.reject(item + " is not a File");
|
|
258
|
+
}
|
|
259
|
+
var fwp = toFileWithPath(file);
|
|
260
|
+
return Promise.resolve(fwp);
|
|
261
|
+
}
|
|
262
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry
|
|
263
|
+
function fromEntry(entry) {
|
|
264
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function () {
|
|
265
|
+
return tslib_es6.__generator(this, function (_a) {
|
|
266
|
+
return [2 /*return*/, entry.isDirectory ? fromDirEntry(entry) : fromFileEntry(entry)];
|
|
267
|
+
});
|
|
268
|
+
});
|
|
219
269
|
}
|
|
270
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry
|
|
220
271
|
function fromDirEntry(entry) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
272
|
+
var reader = entry.createReader();
|
|
273
|
+
return new Promise(function (resolve, reject) {
|
|
274
|
+
var entries = [];
|
|
275
|
+
function readEntries() {
|
|
276
|
+
var _this = this;
|
|
277
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry/createReader
|
|
278
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader/readEntries
|
|
279
|
+
reader.readEntries(function (batch) { return tslib_es6.__awaiter(_this, void 0, void 0, function () {
|
|
280
|
+
var files, err_1, items;
|
|
281
|
+
return tslib_es6.__generator(this, function (_a) {
|
|
282
|
+
switch (_a.label) {
|
|
283
|
+
case 0:
|
|
284
|
+
if (!!batch.length) return [3 /*break*/, 5];
|
|
285
|
+
_a.label = 1;
|
|
286
|
+
case 1:
|
|
287
|
+
_a.trys.push([1, 3, , 4]);
|
|
288
|
+
return [4 /*yield*/, Promise.all(entries)];
|
|
289
|
+
case 2:
|
|
290
|
+
files = _a.sent();
|
|
291
|
+
resolve(files);
|
|
292
|
+
return [3 /*break*/, 4];
|
|
293
|
+
case 3:
|
|
294
|
+
err_1 = _a.sent();
|
|
295
|
+
reject(err_1);
|
|
296
|
+
return [3 /*break*/, 4];
|
|
297
|
+
case 4: return [3 /*break*/, 6];
|
|
298
|
+
case 5:
|
|
299
|
+
items = Promise.all(batch.map(fromEntry));
|
|
300
|
+
entries.push(items);
|
|
301
|
+
// Continue reading
|
|
302
|
+
readEntries();
|
|
303
|
+
_a.label = 6;
|
|
304
|
+
case 6: return [2 /*return*/];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}); }, function (err) {
|
|
308
|
+
reject(err);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
readEntries();
|
|
312
|
+
});
|
|
242
313
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
314
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry
|
|
315
|
+
function fromFileEntry(entry) {
|
|
316
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function () {
|
|
317
|
+
return tslib_es6.__generator(this, function (_a) {
|
|
318
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
319
|
+
entry.file(function (file) {
|
|
320
|
+
var fwp = toFileWithPath(file, entry.fullPath);
|
|
321
|
+
resolve(fwp);
|
|
322
|
+
}, function (err) {
|
|
323
|
+
reject(err);
|
|
324
|
+
});
|
|
325
|
+
})];
|
|
326
|
+
});
|
|
327
|
+
});
|
|
251
328
|
}
|
|
252
329
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
*
|
|
262
|
-
* @param file The file to check. When omitted or `null`, the file is accepted.
|
|
263
|
-
* @param acceptedFiles One or more MIME types and/or file extensions, either as
|
|
264
|
-
* a comma-delimited string or an array. When omitted or empty, any file is accepted.
|
|
265
|
-
* @returns `true` if the file matches (or when there is nothing to match against).
|
|
266
|
-
*/
|
|
267
|
-
function accept(file, acceptedFiles) {
|
|
268
|
-
if (file && acceptedFiles) {
|
|
269
|
-
const acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(",");
|
|
270
|
-
if (acceptedFilesArray.length === 0) return true;
|
|
271
|
-
const fileName = file.name || "";
|
|
272
|
-
const mimeType = (file.type || "").toLowerCase();
|
|
273
|
-
const baseMimeType = mimeType.replace(/\/.*$/, "");
|
|
274
|
-
return acceptedFilesArray.some((type) => {
|
|
275
|
-
const validType = type.trim().toLowerCase();
|
|
276
|
-
if (validType.charAt(0) === ".") return fileName.toLowerCase().endsWith(validType);
|
|
277
|
-
else if (validType.endsWith("/*")) return baseMimeType === validType.replace(/\/.*$/, "");
|
|
278
|
-
return mimeType === validType;
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
return true;
|
|
282
|
-
}
|
|
330
|
+
var _default = function (file, acceptedFiles) {
|
|
331
|
+
if (file && acceptedFiles) {
|
|
332
|
+
var acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(',');
|
|
333
|
+
var fileName = file.name || '';
|
|
334
|
+
var mimeType = (file.type || '').toLowerCase();
|
|
335
|
+
var baseMimeType = mimeType.replace(/\/.*$/, '');
|
|
336
|
+
return acceptedFilesArray.some(function (type) {
|
|
337
|
+
var validType = type.trim().toLowerCase();
|
|
283
338
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
const FILE_SIZE_UNITS = [
|
|
299
|
-
"KB",
|
|
300
|
-
"MB",
|
|
301
|
-
"GB",
|
|
302
|
-
"TB",
|
|
303
|
-
"PB"
|
|
304
|
-
];
|
|
305
|
-
/**
|
|
306
|
-
* Format a byte count into a human-readable string, e.g. `1111` -> `1.08 KB`.
|
|
307
|
-
* Values below 1 KB are kept in bytes to preserve the singular/plural wording.
|
|
308
|
-
*/
|
|
309
|
-
function formatBytes(bytes) {
|
|
310
|
-
if (bytes < 1024) return `${bytes} ${bytes === 1 ? "byte" : "bytes"}`;
|
|
311
|
-
let size = bytes / 1024;
|
|
312
|
-
let unitIndex = 0;
|
|
313
|
-
while (size >= 1024 && unitIndex < FILE_SIZE_UNITS.length - 1) {
|
|
314
|
-
size /= 1024;
|
|
315
|
-
unitIndex++;
|
|
316
|
-
}
|
|
317
|
-
return `${Number(size.toFixed(2))} ${FILE_SIZE_UNITS[unitIndex]}`;
|
|
318
|
-
}
|
|
319
|
-
function getTooLargeRejectionErr(maxSize) {
|
|
320
|
-
return {
|
|
321
|
-
code: FILE_TOO_LARGE,
|
|
322
|
-
message: `File is larger than ${formatBytes(maxSize)}`
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
function getTooSmallRejectionErr(minSize) {
|
|
326
|
-
return {
|
|
327
|
-
code: FILE_TOO_SMALL,
|
|
328
|
-
message: `File is smaller than ${formatBytes(minSize)}`
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
const TOO_MANY_FILES_REJECTION = {
|
|
332
|
-
code: TOO_MANY_FILES,
|
|
333
|
-
message: "Too many files"
|
|
339
|
+
if (validType.charAt(0) === '.') {
|
|
340
|
+
return fileName.toLowerCase().endsWith(validType);
|
|
341
|
+
} else if (validType.endsWith('/*')) {
|
|
342
|
+
// This is something like a image/* mime type
|
|
343
|
+
return baseMimeType === validType.replace(/\/.*$/, '');
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return mimeType === validType;
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return true;
|
|
334
351
|
};
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
function
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
352
|
+
|
|
353
|
+
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
354
|
+
|
|
355
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
356
|
+
|
|
357
|
+
function _defineProperty$1(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
358
|
+
|
|
359
|
+
function _slicedToArray$1(arr, i) { return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest$1(); }
|
|
360
|
+
|
|
361
|
+
function _nonIterableRest$1() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
362
|
+
|
|
363
|
+
function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
|
|
364
|
+
|
|
365
|
+
function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
366
|
+
|
|
367
|
+
function _iterableToArrayLimit$1(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
368
|
+
|
|
369
|
+
function _arrayWithHoles$1(arr) { if (Array.isArray(arr)) return arr; }
|
|
370
|
+
|
|
371
|
+
var FILE_INVALID_TYPE = 'file-invalid-type';
|
|
372
|
+
var FILE_TOO_LARGE = 'file-too-large';
|
|
373
|
+
var FILE_TOO_SMALL = 'file-too-small';
|
|
374
|
+
var TOO_MANY_FILES = 'too-many-files';
|
|
375
|
+
|
|
376
|
+
var getInvalidTypeRejectionErr = function getInvalidTypeRejectionErr(accept) {
|
|
377
|
+
accept = Array.isArray(accept) && accept.length === 1 ? accept[0] : accept;
|
|
378
|
+
var messageSuffix = Array.isArray(accept) ? "one of ".concat(accept.join(', ')) : accept;
|
|
379
|
+
return {
|
|
380
|
+
code: FILE_INVALID_TYPE,
|
|
381
|
+
message: "File type must be ".concat(messageSuffix)
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
var getTooLargeRejectionErr = function getTooLargeRejectionErr(maxSize) {
|
|
385
|
+
return {
|
|
386
|
+
code: FILE_TOO_LARGE,
|
|
387
|
+
message: "File is larger than ".concat(maxSize, " ").concat(maxSize === 1 ? 'byte' : 'bytes')
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
var getTooSmallRejectionErr = function getTooSmallRejectionErr(minSize) {
|
|
391
|
+
return {
|
|
392
|
+
code: FILE_TOO_SMALL,
|
|
393
|
+
message: "File is smaller than ".concat(minSize, " ").concat(minSize === 1 ? 'byte' : 'bytes')
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
var TOO_MANY_FILES_REJECTION = {
|
|
397
|
+
code: TOO_MANY_FILES,
|
|
398
|
+
message: 'Too many files'
|
|
399
|
+
}; // Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
|
|
400
|
+
// that MIME type will always be accepted
|
|
401
|
+
|
|
354
402
|
function fileAccepted(file, accept) {
|
|
355
|
-
|
|
356
|
-
|
|
403
|
+
var isAcceptable = file.type === 'application/x-moz-file' || _default(file, accept);
|
|
404
|
+
return [isAcceptable, isAcceptable ? null : getInvalidTypeRejectionErr(accept)];
|
|
357
405
|
}
|
|
358
406
|
function fileMatchSize(file, minSize, maxSize) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
407
|
+
if (isDefined(file.size)) {
|
|
408
|
+
if (isDefined(minSize) && isDefined(maxSize)) {
|
|
409
|
+
if (file.size > maxSize) return [false, getTooLargeRejectionErr(maxSize)];
|
|
410
|
+
if (file.size < minSize) return [false, getTooSmallRejectionErr(minSize)];
|
|
411
|
+
} else if (isDefined(minSize) && file.size < minSize) return [false, getTooSmallRejectionErr(minSize)];else if (isDefined(maxSize) && file.size > maxSize) return [false, getTooLargeRejectionErr(maxSize)];
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return [true, null];
|
|
367
415
|
}
|
|
416
|
+
|
|
368
417
|
function isDefined(value) {
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Check if a value is thenable (Promise-like), used to tell a synchronous validator result from an
|
|
373
|
-
* asynchronous one.
|
|
374
|
-
*/
|
|
375
|
-
function isThenable(value) {
|
|
376
|
-
return value != null && typeof value.then === "function";
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Classify a set of dragged files for the `isDragAccept`/`isDragReject`/`isDragUnknown` states.
|
|
380
|
-
*
|
|
381
|
-
* During `dragenter`/`dragover` the browser only exposes `DataTransferItem`s, which carry a MIME
|
|
382
|
-
* `type` but no file name, extension or size (see https://html.spec.whatwg.org/multipage/dnd.html#dndevents).
|
|
383
|
-
* So the drag-time check is deliberately optimistic about anything it can't see:
|
|
384
|
-
*
|
|
385
|
-
* - The custom `validator` is **never** run here. It is typed `(file: File) => ...` and users
|
|
386
|
-
* routinely read `file.name`/`file.size`, which are `undefined` on a `DataTransferItem` - running
|
|
387
|
-
* it would throw and abort the whole drag handler (leaving `isDragActive` stuck at `false`).
|
|
388
|
-
* See https://github.com/react-dropzone/react-dropzone/issues/1408
|
|
389
|
-
* - When a `validator` is configured we therefore can't promise the files are acceptable, so the
|
|
390
|
-
* verdict is `unknown` rather than a misleading `reject` (or a premature `accept`).
|
|
391
|
-
* See https://github.com/react-dropzone/react-dropzone/issues/1244
|
|
392
|
-
*
|
|
393
|
-
* The full check (including the `validator`) still runs on drop in {@link fileAccepted}/`setFiles`.
|
|
394
|
-
*/
|
|
395
|
-
function evaluateDragFiles({ files, accept, minSize, maxSize, multiple, maxFiles = 0, validator, getErrorMessage }) {
|
|
396
|
-
const acceptedFiles = [];
|
|
397
|
-
const rejections = [];
|
|
398
|
-
const localizeError = (error, file) => getErrorMessage && typeof File !== "undefined" && file instanceof File ? {
|
|
399
|
-
...error,
|
|
400
|
-
message: getErrorMessage(error, file)
|
|
401
|
-
} : error;
|
|
402
|
-
files.forEach((file) => {
|
|
403
|
-
const [accepted, acceptError] = fileAccepted(file, accept);
|
|
404
|
-
const [sizeMatch, sizeError] = fileMatchSize(file, minSize, maxSize);
|
|
405
|
-
if (accepted && sizeMatch) acceptedFiles.push(file);
|
|
406
|
-
else rejections.push({
|
|
407
|
-
file,
|
|
408
|
-
errors: [acceptError, sizeError].filter((error) => error != null).map((error) => localizeError(error, file))
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
const acceptedFilesLimit = multiple ? maxFiles >= 1 ? maxFiles : Number.POSITIVE_INFINITY : 1;
|
|
412
|
-
if (acceptedFiles.length > acceptedFilesLimit) acceptedFiles.slice(acceptedFilesLimit).forEach((file) => {
|
|
413
|
-
rejections.push({
|
|
414
|
-
file,
|
|
415
|
-
errors: [localizeError(TOO_MANY_FILES_REJECTION, file)]
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
if (rejections.length > 0) return {
|
|
419
|
-
verdict: "reject",
|
|
420
|
-
rejections
|
|
421
|
-
};
|
|
422
|
-
return {
|
|
423
|
-
verdict: validator ? "unknown" : "accept",
|
|
424
|
-
rejections
|
|
425
|
-
};
|
|
418
|
+
return value !== undefined && value !== null;
|
|
426
419
|
}
|
|
420
|
+
|
|
421
|
+
function allFilesAccepted(_ref) {
|
|
422
|
+
var files = _ref.files,
|
|
423
|
+
accept = _ref.accept,
|
|
424
|
+
minSize = _ref.minSize,
|
|
425
|
+
maxSize = _ref.maxSize,
|
|
426
|
+
multiple = _ref.multiple,
|
|
427
|
+
maxFiles = _ref.maxFiles;
|
|
428
|
+
|
|
429
|
+
if (!multiple && files.length > 1 || multiple && maxFiles >= 1 && files.length > maxFiles) {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return files.every(function (file) {
|
|
434
|
+
var _fileAccepted = fileAccepted(file, accept),
|
|
435
|
+
_fileAccepted2 = _slicedToArray$1(_fileAccepted, 1),
|
|
436
|
+
accepted = _fileAccepted2[0];
|
|
437
|
+
|
|
438
|
+
var _fileMatchSize = fileMatchSize(file, minSize, maxSize),
|
|
439
|
+
_fileMatchSize2 = _slicedToArray$1(_fileMatchSize, 1),
|
|
440
|
+
sizeMatch = _fileMatchSize2[0];
|
|
441
|
+
|
|
442
|
+
return accepted && sizeMatch;
|
|
443
|
+
});
|
|
444
|
+
} // React's synthetic events has event.isPropagationStopped,
|
|
445
|
+
// but to remain compatibility with other libs (Preact) fall back
|
|
446
|
+
// to check event.cancelBubble
|
|
447
|
+
|
|
427
448
|
function isPropagationStopped(event) {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
449
|
+
if (typeof event.isPropagationStopped === 'function') {
|
|
450
|
+
return event.isPropagationStopped();
|
|
451
|
+
} else if (typeof event.cancelBubble !== 'undefined') {
|
|
452
|
+
return event.cancelBubble;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return false;
|
|
431
456
|
}
|
|
432
457
|
function isEvtWithFiles(event) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
458
|
+
if (!event.dataTransfer) {
|
|
459
|
+
return !!event.target && !!event.target.files;
|
|
460
|
+
} // https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types
|
|
461
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types#file
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
return Array.prototype.some.call(event.dataTransfer.types, function (type) {
|
|
465
|
+
return type === 'Files' || type === 'application/x-moz-file';
|
|
466
|
+
});
|
|
439
467
|
}
|
|
468
|
+
|
|
440
469
|
function onDocumentDragOver(event) {
|
|
441
|
-
|
|
470
|
+
event.preventDefault();
|
|
442
471
|
}
|
|
472
|
+
|
|
443
473
|
function isIe(userAgent) {
|
|
444
|
-
|
|
474
|
+
return userAgent.indexOf('MSIE') !== -1 || userAgent.indexOf('Trident/') !== -1;
|
|
445
475
|
}
|
|
476
|
+
|
|
446
477
|
function isEdge(userAgent) {
|
|
447
|
-
|
|
478
|
+
return userAgent.indexOf('Edge/') !== -1;
|
|
448
479
|
}
|
|
449
|
-
|
|
450
|
-
|
|
480
|
+
|
|
481
|
+
function isIeOrEdge() {
|
|
482
|
+
var userAgent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.navigator.userAgent;
|
|
483
|
+
return isIe(userAgent) || isEdge(userAgent);
|
|
451
484
|
}
|
|
452
485
|
/**
|
|
453
|
-
* This is intended to be used to compose event handlers
|
|
454
|
-
* They are executed in order until one of them calls `event.isPropagationStopped()`.
|
|
455
|
-
* Note that the check is done on the first invoke too,
|
|
456
|
-
* meaning that if propagation was stopped before invoking the fns,
|
|
457
|
-
* no handlers will be executed.
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
486
|
+
* This is intended to be used to compose event handlers
|
|
487
|
+
* They are executed in order until one of them calls `event.isPropagationStopped()`.
|
|
488
|
+
* Note that the check is done on the first invoke too,
|
|
489
|
+
* meaning that if propagation was stopped before invoking the fns,
|
|
490
|
+
* no handlers will be executed.
|
|
491
|
+
*
|
|
492
|
+
* @param {Function} fns the event hanlder functions
|
|
493
|
+
* @return {Function} the event handler to add to an element
|
|
494
|
+
*/
|
|
495
|
+
|
|
496
|
+
function composeEventHandlers() {
|
|
497
|
+
for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
498
|
+
fns[_key] = arguments[_key];
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
return function (event) {
|
|
502
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
503
|
+
args[_key2 - 1] = arguments[_key2];
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return fns.some(function (fn) {
|
|
507
|
+
if (!isPropagationStopped(event) && fn) {
|
|
508
|
+
fn.apply(void 0, [event].concat(args));
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return isPropagationStopped(event);
|
|
512
|
+
});
|
|
513
|
+
};
|
|
464
514
|
}
|
|
465
515
|
/**
|
|
466
|
-
* canUseFileSystemAccessAPI checks if the File System Access API
|
|
467
|
-
|
|
516
|
+
* canUseFileSystemAccessAPI checks if the [File System Access API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API)
|
|
517
|
+
* is supported by the browser.
|
|
518
|
+
* @returns {boolean}
|
|
519
|
+
*/
|
|
520
|
+
|
|
468
521
|
function canUseFileSystemAccessAPI() {
|
|
469
|
-
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Coerce an `accept` extension value to an array. `window.showOpenFilePicker` allows a single
|
|
473
|
-
* extension string as well as an array, so we accept both and normalize to an array. Anything
|
|
474
|
-
* else (a malformed value) collapses to an empty list.
|
|
475
|
-
*/
|
|
476
|
-
function toExtensions(ext) {
|
|
477
|
-
if (Array.isArray(ext)) return ext;
|
|
478
|
-
if (typeof ext === "string") return [ext];
|
|
479
|
-
return [];
|
|
522
|
+
return 'showOpenFilePicker' in window;
|
|
480
523
|
}
|
|
481
524
|
/**
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
*/
|
|
502
|
-
function describeAccept(accept) {
|
|
503
|
-
const extensions = [];
|
|
504
|
-
const mimeTypes = Object.keys(accept);
|
|
505
|
-
for (const ext of Object.values(accept)) for (const e of toExtensions(ext)) if (!extensions.includes(e)) extensions.push(e);
|
|
506
|
-
if (extensions.length > 0) return extensions.join(", ");
|
|
507
|
-
if (mimeTypes.length > 0) return mimeTypes.join(", ");
|
|
508
|
-
return "Files";
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* Merge every `accept` group into a single MIME-type -> extensions map. Duplicate MIME keys union
|
|
512
|
-
* their extensions. This flattened map drives the native `<input accept>` attribute and the
|
|
513
|
-
* drag/drop validators, which have no concept of groups or descriptions.
|
|
514
|
-
*/
|
|
515
|
-
function flattenAccept(accept) {
|
|
516
|
-
const groups = normalizeAcceptGroups(accept);
|
|
517
|
-
if (!isDefined(groups)) return;
|
|
518
|
-
const merged = {};
|
|
519
|
-
for (const group of groups) for (const [mimeType, ext] of Object.entries(group.accept)) {
|
|
520
|
-
const existing = merged[mimeType] ?? (merged[mimeType] = []);
|
|
521
|
-
for (const e of toExtensions(ext)) if (!existing.includes(e)) existing.push(e);
|
|
522
|
-
}
|
|
523
|
-
return merged;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Convert the `{accept}` dropzone prop to the `{types}` option for showOpenFilePicker.
|
|
527
|
-
*
|
|
528
|
-
* Each group becomes one filter row in the picker. Invalid MIME types / extensions are dropped
|
|
529
|
-
* with a warning; a group left with no valid entries is omitted entirely (showOpenFilePicker
|
|
530
|
-
* rejects an empty `accept`). Returns `undefined` when nothing valid remains.
|
|
531
|
-
*/
|
|
532
|
-
function pickerOptionsFromAccept(accept) {
|
|
533
|
-
const groups = normalizeAcceptGroups(accept);
|
|
534
|
-
if (!isDefined(groups)) return;
|
|
535
|
-
const options = groups.map((group) => {
|
|
536
|
-
const acceptForPicker = Object.entries(group.accept).filter(([mimeType, ext]) => {
|
|
537
|
-
let ok = true;
|
|
538
|
-
if (!isMIMEType(mimeType)) {
|
|
539
|
-
console.warn(`Skipped "${mimeType}" because it is not a valid MIME type. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for a list of valid MIME types.`);
|
|
540
|
-
ok = false;
|
|
541
|
-
}
|
|
542
|
-
if (!(Array.isArray(ext) || typeof ext === "string") || !toExtensions(ext).every(isExt)) {
|
|
543
|
-
console.warn(`Skipped "${mimeType}" because an invalid file extension was provided.`);
|
|
544
|
-
ok = false;
|
|
545
|
-
}
|
|
546
|
-
return ok;
|
|
547
|
-
}).reduce((agg, [mimeType, ext]) => {
|
|
548
|
-
agg[mimeType] = toExtensions(ext);
|
|
549
|
-
return agg;
|
|
550
|
-
}, {});
|
|
551
|
-
return {
|
|
552
|
-
description: isDefined(group.description) && group.description !== "" ? group.description : describeAccept(acceptForPicker),
|
|
553
|
-
accept: acceptForPicker
|
|
554
|
-
};
|
|
555
|
-
}).filter((option) => Object.keys(option.accept).length > 0);
|
|
556
|
-
return options.length > 0 ? options : void 0;
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* Convert the `{accept}` dropzone prop to a comma-separated accept attribute string.
|
|
560
|
-
*
|
|
561
|
-
* When `omitWildcardMimeTypesWithExtensions` is set, a wildcard MIME type (e.g. `image/*`)
|
|
562
|
-
* that is paired with explicit extensions is dropped in favour of those extensions. The
|
|
563
|
-
* accept attribute is an OR list, so leaving `image/*` in would make both the native file
|
|
564
|
-
* picker and the drop-time validator accept ANY file of that type, ignoring the extension
|
|
565
|
-
* restriction. The drag-time `isDragAccept` check keeps the wildcard because file names
|
|
566
|
-
* (and therefore extensions) aren't readable during a drag.
|
|
567
|
-
*
|
|
568
|
-
* See https://github.com/react-dropzone/react-dropzone/issues/1220
|
|
569
|
-
*/
|
|
570
|
-
function acceptPropAsAcceptAttr(accept, { omitWildcardMimeTypesWithExtensions = false } = {}) {
|
|
571
|
-
if (isDefined(accept)) return Object.entries(accept).reduce((a, [mimeType, extVal]) => {
|
|
572
|
-
const ext = toExtensions(extVal);
|
|
573
|
-
if (omitWildcardMimeTypesWithExtensions && isMIMETypeWildcard(mimeType) && ext.some(isExt)) a.push(...ext);
|
|
574
|
-
else a.push(mimeType, ...ext);
|
|
575
|
-
return a;
|
|
576
|
-
}, []).filter((v) => isMIMEType(v) || isExt(v)).join(",");
|
|
525
|
+
* filePickerOptionsTypes returns the {types} option for https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker
|
|
526
|
+
* based on the accept attr (see https://github.com/react-dropzone/attr-accept)
|
|
527
|
+
* E.g: converts ['image/*', 'text/*'] to {'image/*': [], 'text/*': []}
|
|
528
|
+
* @param {string|string[]} accept
|
|
529
|
+
*/
|
|
530
|
+
|
|
531
|
+
function filePickerOptionsTypes(accept) {
|
|
532
|
+
accept = typeof accept === 'string' ? accept.split(',') : accept;
|
|
533
|
+
return [{
|
|
534
|
+
description: 'everything',
|
|
535
|
+
// TODO: Need to handle filtering more elegantly than this!
|
|
536
|
+
accept: Array.isArray(accept) // Accept just MIME types as per spec
|
|
537
|
+
// NOTE: accept can be https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#unique_file_type_specifiers
|
|
538
|
+
? accept.filter(function (item) {
|
|
539
|
+
return item === 'audio/*' || item === 'video/*' || item === 'image/*' || item === 'text/*' || /\w+\/[-+.\w]+/g.test(item);
|
|
540
|
+
}).reduce(function (a, b) {
|
|
541
|
+
return _objectSpread$1(_objectSpread$1({}, a), {}, _defineProperty$1({}, b, []));
|
|
542
|
+
}, {}) : {}
|
|
543
|
+
}];
|
|
577
544
|
}
|
|
545
|
+
|
|
546
|
+
var _excluded = ["children"],
|
|
547
|
+
_excluded2 = ["open"],
|
|
548
|
+
_excluded3 = ["refKey", "role", "onKeyDown", "onFocus", "onBlur", "onClick", "onDragEnter", "onDragOver", "onDragLeave", "onDrop"],
|
|
549
|
+
_excluded4 = ["refKey", "onChange", "onClick"];
|
|
550
|
+
|
|
551
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
552
|
+
|
|
553
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
554
|
+
|
|
555
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
556
|
+
|
|
557
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
558
|
+
|
|
559
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
560
|
+
|
|
561
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
562
|
+
|
|
563
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
564
|
+
|
|
565
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
566
|
+
|
|
567
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
568
|
+
|
|
569
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
570
|
+
|
|
571
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
572
|
+
|
|
573
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
574
|
+
|
|
575
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
576
|
+
|
|
577
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
578
|
+
|
|
579
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
578
580
|
/**
|
|
579
|
-
*
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
581
|
+
* Convenience wrapper component for the `useDropzone` hook
|
|
582
|
+
*
|
|
583
|
+
* ```jsx
|
|
584
|
+
* <Dropzone>
|
|
585
|
+
* {({getRootProps, getInputProps}) => (
|
|
586
|
+
* <div {...getRootProps()}>
|
|
587
|
+
* <input {...getInputProps()} />
|
|
588
|
+
* <p>Drag 'n' drop some files here, or click to select files</p>
|
|
589
|
+
* </div>
|
|
590
|
+
* )}
|
|
591
|
+
* </Dropzone>
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
|
|
595
|
+
var Dropzone = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
596
|
+
var children = _ref.children,
|
|
597
|
+
params = _objectWithoutProperties(_ref, _excluded);
|
|
598
|
+
|
|
599
|
+
var _useDropzone = useDropzone(params),
|
|
600
|
+
open = _useDropzone.open,
|
|
601
|
+
props = _objectWithoutProperties(_useDropzone, _excluded2);
|
|
602
|
+
|
|
603
|
+
React.useImperativeHandle(ref, function () {
|
|
604
|
+
return {
|
|
605
|
+
open: open
|
|
606
|
+
};
|
|
607
|
+
}, [open]); // TODO: Figure out why react-styleguidist cannot create docs if we don't return a jsx element
|
|
608
|
+
|
|
609
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children(_objectSpread(_objectSpread({}, props), {}, {
|
|
610
|
+
open: open
|
|
611
|
+
})));
|
|
612
|
+
});
|
|
613
|
+
Dropzone.displayName = 'Dropzone'; // Add default props for react-docgen
|
|
614
|
+
|
|
615
|
+
var defaultProps = {
|
|
616
|
+
disabled: false,
|
|
617
|
+
getFilesFromEvent: fromEvent,
|
|
618
|
+
maxSize: Infinity,
|
|
619
|
+
minSize: 0,
|
|
620
|
+
multiple: true,
|
|
621
|
+
maxFiles: 0,
|
|
622
|
+
preventDropOnDocument: true,
|
|
623
|
+
noClick: false,
|
|
624
|
+
noKeyboard: false,
|
|
625
|
+
noDrag: false,
|
|
626
|
+
noDragEventsBubbling: false,
|
|
627
|
+
validator: null,
|
|
628
|
+
useFsAccessApi: false
|
|
629
|
+
};
|
|
630
|
+
Dropzone.defaultProps = defaultProps;
|
|
631
|
+
Dropzone.propTypes = {
|
|
632
|
+
/**
|
|
633
|
+
* Render function that exposes the dropzone state and prop getter fns
|
|
634
|
+
*
|
|
635
|
+
* @param {object} params
|
|
636
|
+
* @param {Function} params.getRootProps Returns the props you should apply to the root drop container you render
|
|
637
|
+
* @param {Function} params.getInputProps Returns the props you should apply to hidden file input you render
|
|
638
|
+
* @param {Function} params.open Open the native file selection dialog
|
|
639
|
+
* @param {boolean} params.isFocused Dropzone area is in focus
|
|
640
|
+
* @param {boolean} params.isFileDialogActive File dialog is opened
|
|
641
|
+
* @param {boolean} params.isDragActive Active drag is in progress
|
|
642
|
+
* @param {boolean} params.isDragAccept Dragged files are accepted
|
|
643
|
+
* @param {boolean} params.isDragReject Some dragged files are rejected
|
|
644
|
+
* @param {File[]} params.draggedFiles Files in active drag
|
|
645
|
+
* @param {File[]} params.acceptedFiles Accepted files
|
|
646
|
+
* @param {FileRejection[]} params.fileRejections Rejected files and why they were rejected
|
|
647
|
+
*/
|
|
648
|
+
children: index.PropTypes.func,
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Set accepted file types.
|
|
652
|
+
* See https://github.com/okonet/attr-accept for more information.
|
|
653
|
+
* Keep in mind that mime type determination is not reliable across platforms. CSV files,
|
|
654
|
+
* for example, are reported as text/plain under macOS but as application/vnd.ms-excel under
|
|
655
|
+
* Windows. In some cases there might not be a mime type set at all.
|
|
656
|
+
* See: https://github.com/react-dropzone/react-dropzone/issues/276
|
|
657
|
+
*/
|
|
658
|
+
accept: index.PropTypes.oneOfType([index.PropTypes.string, index.PropTypes.arrayOf(index.PropTypes.string)]),
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Allow drag 'n' drop (or selection from the file dialog) of multiple files
|
|
662
|
+
*/
|
|
663
|
+
multiple: index.PropTypes.bool,
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* If false, allow dropped items to take over the current browser window
|
|
667
|
+
*/
|
|
668
|
+
preventDropOnDocument: index.PropTypes.bool,
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* If true, disables click to open the native file selection dialog
|
|
672
|
+
*/
|
|
673
|
+
noClick: index.PropTypes.bool,
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* If true, disables SPACE/ENTER to open the native file selection dialog.
|
|
677
|
+
* Note that it also stops tracking the focus state.
|
|
678
|
+
*/
|
|
679
|
+
noKeyboard: index.PropTypes.bool,
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* If true, disables drag 'n' drop
|
|
683
|
+
*/
|
|
684
|
+
noDrag: index.PropTypes.bool,
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* If true, stops drag event propagation to parents
|
|
688
|
+
*/
|
|
689
|
+
noDragEventsBubbling: index.PropTypes.bool,
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Minimum file size (in bytes)
|
|
693
|
+
*/
|
|
694
|
+
minSize: index.PropTypes.number,
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Maximum file size (in bytes)
|
|
698
|
+
*/
|
|
699
|
+
maxSize: index.PropTypes.number,
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Maximum accepted number of files
|
|
703
|
+
* The default value is 0 which means there is no limitation to how many files are accepted.
|
|
704
|
+
*/
|
|
705
|
+
maxFiles: index.PropTypes.number,
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Enable/disable the dropzone
|
|
709
|
+
*/
|
|
710
|
+
disabled: index.PropTypes.bool,
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Use this to provide a custom file aggregator
|
|
714
|
+
*
|
|
715
|
+
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
716
|
+
*/
|
|
717
|
+
getFilesFromEvent: index.PropTypes.func,
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Cb for when closing the file dialog with no selection
|
|
721
|
+
*/
|
|
722
|
+
onFileDialogCancel: index.PropTypes.func,
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Cb for when opening the file dialog
|
|
726
|
+
*/
|
|
727
|
+
onFileDialogOpen: index.PropTypes.func,
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* Set to true to use the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API
|
|
731
|
+
* to open the file picker instead of using an `<input type="file">` click event.
|
|
732
|
+
*/
|
|
733
|
+
useFsAccessApi: index.PropTypes.bool,
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Cb for when the `dragenter` event occurs.
|
|
737
|
+
*
|
|
738
|
+
* @param {DragEvent} event
|
|
739
|
+
*/
|
|
740
|
+
onDragEnter: index.PropTypes.func,
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Cb for when the `dragleave` event occurs
|
|
744
|
+
*
|
|
745
|
+
* @param {DragEvent} event
|
|
746
|
+
*/
|
|
747
|
+
onDragLeave: index.PropTypes.func,
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Cb for when the `dragover` event occurs
|
|
751
|
+
*
|
|
752
|
+
* @param {DragEvent} event
|
|
753
|
+
*/
|
|
754
|
+
onDragOver: index.PropTypes.func,
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* Cb for when the `drop` event occurs.
|
|
758
|
+
* Note that this callback is invoked after the `getFilesFromEvent` callback is done.
|
|
759
|
+
*
|
|
760
|
+
* Files are accepted or rejected based on the `accept`, `multiple`, `minSize` and `maxSize` props.
|
|
761
|
+
* `accept` must be a valid [MIME type](http://www.iana.org/assignments/media-types/media-types.xhtml) according to [input element specification](https://www.w3.org/wiki/HTML/Elements/input/file) or a valid file extension.
|
|
762
|
+
* If `multiple` is set to false and additional files are dropped,
|
|
763
|
+
* all files besides the first will be rejected.
|
|
764
|
+
* Any file which does not have a size in the [`minSize`, `maxSize`] range, will be rejected as well.
|
|
765
|
+
*
|
|
766
|
+
* Note that the `onDrop` callback will always be invoked regardless if the dropped files were accepted or rejected.
|
|
767
|
+
* If you'd like to react to a specific scenario, use the `onDropAccepted`/`onDropRejected` props.
|
|
768
|
+
*
|
|
769
|
+
* `onDrop` will provide you with an array of [File](https://developer.mozilla.org/en-US/docs/Web/API/File) objects which you can then process and send to a server.
|
|
770
|
+
* For example, with [SuperAgent](https://github.com/visionmedia/superagent) as a http/ajax library:
|
|
771
|
+
*
|
|
772
|
+
* ```js
|
|
773
|
+
* function onDrop(acceptedFiles) {
|
|
774
|
+
* const req = request.post('/upload')
|
|
775
|
+
* acceptedFiles.forEach(file => {
|
|
776
|
+
* req.attach(file.name, file)
|
|
777
|
+
* })
|
|
778
|
+
* req.end(callback)
|
|
779
|
+
* }
|
|
780
|
+
* ```
|
|
781
|
+
*
|
|
782
|
+
* @param {File[]} acceptedFiles
|
|
783
|
+
* @param {FileRejection[]} fileRejections
|
|
784
|
+
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
785
|
+
*/
|
|
786
|
+
onDrop: index.PropTypes.func,
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Cb for when the `drop` event occurs.
|
|
790
|
+
* Note that if no files are accepted, this callback is not invoked.
|
|
791
|
+
*
|
|
792
|
+
* @param {File[]} files
|
|
793
|
+
* @param {(DragEvent|Event)} event
|
|
794
|
+
*/
|
|
795
|
+
onDropAccepted: index.PropTypes.func,
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Cb for when the `drop` event occurs.
|
|
799
|
+
* Note that if no files are rejected, this callback is not invoked.
|
|
800
|
+
*
|
|
801
|
+
* @param {FileRejection[]} fileRejections
|
|
802
|
+
* @param {(DragEvent|Event)} event
|
|
803
|
+
*/
|
|
804
|
+
onDropRejected: index.PropTypes.func,
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Custom validation function
|
|
808
|
+
* @param {File} file
|
|
809
|
+
* @returns {FileError|FileError[]}
|
|
810
|
+
*/
|
|
811
|
+
validator: index.PropTypes.func
|
|
812
|
+
};
|
|
584
813
|
/**
|
|
585
|
-
*
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
814
|
+
* A function that is invoked for the `dragenter`,
|
|
815
|
+
* `dragover` and `dragleave` events.
|
|
816
|
+
* It is not invoked if the items are not files (such as link, text, etc.).
|
|
817
|
+
*
|
|
818
|
+
* @callback dragCb
|
|
819
|
+
* @param {DragEvent} event
|
|
820
|
+
*/
|
|
821
|
+
|
|
590
822
|
/**
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
}
|
|
823
|
+
* A function that is invoked for the `drop` or input change event.
|
|
824
|
+
* It is not invoked if the items are not files (such as link, text, etc.).
|
|
825
|
+
*
|
|
826
|
+
* @callback dropCb
|
|
827
|
+
* @param {File[]} acceptedFiles List of accepted files
|
|
828
|
+
* @param {FileRejection[]} fileRejections List of rejected files and why they were rejected
|
|
829
|
+
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
830
|
+
*/
|
|
831
|
+
|
|
601
832
|
/**
|
|
602
|
-
*
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}
|
|
833
|
+
* A function that is invoked for the `drop` or input change event.
|
|
834
|
+
* It is not invoked if the items are files (such as link, text, etc.).
|
|
835
|
+
*
|
|
836
|
+
* @callback dropAcceptedCb
|
|
837
|
+
* @param {File[]} files List of accepted files that meet the given criteria
|
|
838
|
+
* (`accept`, `multiple`, `minSize`, `maxSize`)
|
|
839
|
+
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
840
|
+
*/
|
|
841
|
+
|
|
607
842
|
/**
|
|
608
|
-
*
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
843
|
+
* A function that is invoked for the `drop` or input change event.
|
|
844
|
+
*
|
|
845
|
+
* @callback dropRejectedCb
|
|
846
|
+
* @param {File[]} files List of rejected files that do not meet the given criteria
|
|
847
|
+
* (`accept`, `multiple`, `minSize`, `maxSize`)
|
|
848
|
+
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
849
|
+
*/
|
|
850
|
+
|
|
613
851
|
/**
|
|
614
|
-
*
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
|
|
852
|
+
* A function that is used aggregate files,
|
|
853
|
+
* in a asynchronous fashion, from drag or input change events.
|
|
854
|
+
*
|
|
855
|
+
* @callback getFilesFromEvent
|
|
856
|
+
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
857
|
+
* @returns {(File[]|Promise<File[]>)}
|
|
858
|
+
*/
|
|
859
|
+
|
|
621
860
|
/**
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
*
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
isDragActive: false,
|
|
648
|
-
isDragAccept: false,
|
|
649
|
-
isDragReject: false,
|
|
650
|
-
isDragUnknown: false,
|
|
651
|
-
isDragGlobal: false,
|
|
652
|
-
isProcessing: false,
|
|
653
|
-
acceptedFiles: [],
|
|
654
|
-
fileRejections: [],
|
|
655
|
-
dragFileRejections: []
|
|
861
|
+
* An object with the current dropzone state and some helper functions.
|
|
862
|
+
*
|
|
863
|
+
* @typedef {object} DropzoneState
|
|
864
|
+
* @property {Function} getRootProps Returns the props you should apply to the root drop container you render
|
|
865
|
+
* @property {Function} getInputProps Returns the props you should apply to hidden file input you render
|
|
866
|
+
* @property {Function} open Open the native file selection dialog
|
|
867
|
+
* @property {boolean} isFocused Dropzone area is in focus
|
|
868
|
+
* @property {boolean} isFileDialogActive File dialog is opened
|
|
869
|
+
* @property {boolean} isDragActive Active drag is in progress
|
|
870
|
+
* @property {boolean} isDragAccept Dragged files are accepted
|
|
871
|
+
* @property {boolean} isDragReject Some dragged files are rejected
|
|
872
|
+
* @property {File[]} draggedFiles Files in active drag
|
|
873
|
+
* @property {File[]} acceptedFiles Accepted files
|
|
874
|
+
* @property {FileRejection[]} fileRejections Rejected files and why they were rejected
|
|
875
|
+
*/
|
|
876
|
+
|
|
877
|
+
var initialState = {
|
|
878
|
+
isFocused: false,
|
|
879
|
+
isFileDialogActive: false,
|
|
880
|
+
isDragActive: false,
|
|
881
|
+
isDragAccept: false,
|
|
882
|
+
isDragReject: false,
|
|
883
|
+
draggedFiles: [],
|
|
884
|
+
acceptedFiles: [],
|
|
885
|
+
fileRejections: []
|
|
656
886
|
};
|
|
657
887
|
/**
|
|
658
|
-
* A React hook that creates a drag 'n' drop area.
|
|
659
|
-
*
|
|
660
|
-
* ```jsx
|
|
661
|
-
* function MyDropzone(props) {
|
|
662
|
-
* const {getRootProps, getInputProps} = useDropzone({
|
|
663
|
-
* onDrop: acceptedFiles => {
|
|
664
|
-
* // do something with the File objects, e.g. upload to some server
|
|
665
|
-
* }
|
|
666
|
-
* });
|
|
667
|
-
* return (
|
|
668
|
-
* <div {...getRootProps()}>
|
|
669
|
-
* <input {...getInputProps()} />
|
|
670
|
-
* <p>Drag and drop some files here, or click to select files</p>
|
|
671
|
-
* </div>
|
|
672
|
-
* )
|
|
673
|
-
* }
|
|
674
|
-
* ```
|
|
675
|
-
|
|
676
|
-
function useDropzone
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
return {
|
|
1164
|
-
...state,
|
|
1165
|
-
isFocused: isFocused && !disabled,
|
|
1166
|
-
getRootProps,
|
|
1167
|
-
getInputProps,
|
|
1168
|
-
rootRef,
|
|
1169
|
-
inputRef,
|
|
1170
|
-
open: composeHandler(openFileDialog)
|
|
1171
|
-
};
|
|
888
|
+
* A React hook that creates a drag 'n' drop area.
|
|
889
|
+
*
|
|
890
|
+
* ```jsx
|
|
891
|
+
* function MyDropzone(props) {
|
|
892
|
+
* const {getRootProps, getInputProps} = useDropzone({
|
|
893
|
+
* onDrop: acceptedFiles => {
|
|
894
|
+
* // do something with the File objects, e.g. upload to some server
|
|
895
|
+
* }
|
|
896
|
+
* });
|
|
897
|
+
* return (
|
|
898
|
+
* <div {...getRootProps()}>
|
|
899
|
+
* <input {...getInputProps()} />
|
|
900
|
+
* <p>Drag and drop some files here, or click to select files</p>
|
|
901
|
+
* </div>
|
|
902
|
+
* )
|
|
903
|
+
* }
|
|
904
|
+
* ```
|
|
905
|
+
*
|
|
906
|
+
* @function useDropzone
|
|
907
|
+
*
|
|
908
|
+
* @param {object} props
|
|
909
|
+
* @param {string|string[]} [props.accept] Set accepted file types.
|
|
910
|
+
* See https://github.com/okonet/attr-accept for more information.
|
|
911
|
+
* Keep in mind that mime type determination is not reliable across platforms. CSV files,
|
|
912
|
+
* for example, are reported as text/plain under macOS but as application/vnd.ms-excel under
|
|
913
|
+
* Windows. In some cases there might not be a mime type set at all.
|
|
914
|
+
* See: https://github.com/react-dropzone/react-dropzone/issues/276
|
|
915
|
+
* @param {boolean} [props.multiple=true] Allow drag 'n' drop (or selection from the file dialog) of multiple files
|
|
916
|
+
* @param {boolean} [props.preventDropOnDocument=true] If false, allow dropped items to take over the current browser window
|
|
917
|
+
* @param {boolean} [props.noClick=false] If true, disables click to open the native file selection dialog
|
|
918
|
+
* @param {boolean} [props.noKeyboard=false] If true, disables SPACE/ENTER to open the native file selection dialog.
|
|
919
|
+
* Note that it also stops tracking the focus state.
|
|
920
|
+
* @param {boolean} [props.noDrag=false] If true, disables drag 'n' drop
|
|
921
|
+
* @param {boolean} [props.noDragEventsBubbling=false] If true, stops drag event propagation to parents
|
|
922
|
+
* @param {number} [props.minSize=0] Minimum file size (in bytes)
|
|
923
|
+
* @param {number} [props.maxSize=Infinity] Maximum file size (in bytes)
|
|
924
|
+
* @param {boolean} [props.disabled=false] Enable/disable the dropzone
|
|
925
|
+
* @param {getFilesFromEvent} [props.getFilesFromEvent] Use this to provide a custom file aggregator
|
|
926
|
+
* @param {Function} [props.onFileDialogCancel] Cb for when closing the file dialog with no selection
|
|
927
|
+
* @param {boolean} [props.useFsAccessApi] Set to true to use the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API
|
|
928
|
+
* to open the file picker instead of using an `<input type="file">` click event.
|
|
929
|
+
* @param {Function} [props.onFileDialogOpen] Cb for when opening the file dialog
|
|
930
|
+
* @param {dragCb} [props.onDragEnter] Cb for when the `dragenter` event occurs.
|
|
931
|
+
* @param {dragCb} [props.onDragLeave] Cb for when the `dragleave` event occurs
|
|
932
|
+
* @param {dragCb} [props.onDragOver] Cb for when the `dragover` event occurs
|
|
933
|
+
* @param {dropCb} [props.onDrop] Cb for when the `drop` event occurs.
|
|
934
|
+
* Note that this callback is invoked after the `getFilesFromEvent` callback is done.
|
|
935
|
+
*
|
|
936
|
+
* Files are accepted or rejected based on the `accept`, `multiple`, `minSize` and `maxSize` props.
|
|
937
|
+
* `accept` must be a valid [MIME type](http://www.iana.org/assignments/media-types/media-types.xhtml) according to [input element specification](https://www.w3.org/wiki/HTML/Elements/input/file) or a valid file extension.
|
|
938
|
+
* If `multiple` is set to false and additional files are dropped,
|
|
939
|
+
* all files besides the first will be rejected.
|
|
940
|
+
* Any file which does not have a size in the [`minSize`, `maxSize`] range, will be rejected as well.
|
|
941
|
+
*
|
|
942
|
+
* Note that the `onDrop` callback will always be invoked regardless if the dropped files were accepted or rejected.
|
|
943
|
+
* If you'd like to react to a specific scenario, use the `onDropAccepted`/`onDropRejected` props.
|
|
944
|
+
*
|
|
945
|
+
* `onDrop` will provide you with an array of [File](https://developer.mozilla.org/en-US/docs/Web/API/File) objects which you can then process and send to a server.
|
|
946
|
+
* For example, with [SuperAgent](https://github.com/visionmedia/superagent) as a http/ajax library:
|
|
947
|
+
*
|
|
948
|
+
* ```js
|
|
949
|
+
* function onDrop(acceptedFiles) {
|
|
950
|
+
* const req = request.post('/upload')
|
|
951
|
+
* acceptedFiles.forEach(file => {
|
|
952
|
+
* req.attach(file.name, file)
|
|
953
|
+
* })
|
|
954
|
+
* req.end(callback)
|
|
955
|
+
* }
|
|
956
|
+
* ```
|
|
957
|
+
* @param {dropAcceptedCb} [props.onDropAccepted]
|
|
958
|
+
* @param {dropRejectedCb} [props.onDropRejected]
|
|
959
|
+
*
|
|
960
|
+
* @returns {DropzoneState}
|
|
961
|
+
*/
|
|
962
|
+
|
|
963
|
+
function useDropzone() {
|
|
964
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
965
|
+
|
|
966
|
+
var _defaultProps$options = _objectSpread(_objectSpread({}, defaultProps), options),
|
|
967
|
+
accept = _defaultProps$options.accept,
|
|
968
|
+
disabled = _defaultProps$options.disabled,
|
|
969
|
+
getFilesFromEvent = _defaultProps$options.getFilesFromEvent,
|
|
970
|
+
maxSize = _defaultProps$options.maxSize,
|
|
971
|
+
minSize = _defaultProps$options.minSize,
|
|
972
|
+
multiple = _defaultProps$options.multiple,
|
|
973
|
+
maxFiles = _defaultProps$options.maxFiles,
|
|
974
|
+
onDragEnter = _defaultProps$options.onDragEnter,
|
|
975
|
+
onDragLeave = _defaultProps$options.onDragLeave,
|
|
976
|
+
onDragOver = _defaultProps$options.onDragOver,
|
|
977
|
+
onDrop = _defaultProps$options.onDrop,
|
|
978
|
+
onDropAccepted = _defaultProps$options.onDropAccepted,
|
|
979
|
+
onDropRejected = _defaultProps$options.onDropRejected,
|
|
980
|
+
onFileDialogCancel = _defaultProps$options.onFileDialogCancel,
|
|
981
|
+
onFileDialogOpen = _defaultProps$options.onFileDialogOpen,
|
|
982
|
+
useFsAccessApi = _defaultProps$options.useFsAccessApi,
|
|
983
|
+
preventDropOnDocument = _defaultProps$options.preventDropOnDocument,
|
|
984
|
+
noClick = _defaultProps$options.noClick,
|
|
985
|
+
noKeyboard = _defaultProps$options.noKeyboard,
|
|
986
|
+
noDrag = _defaultProps$options.noDrag,
|
|
987
|
+
noDragEventsBubbling = _defaultProps$options.noDragEventsBubbling,
|
|
988
|
+
validator = _defaultProps$options.validator;
|
|
989
|
+
|
|
990
|
+
var onFileDialogOpenCb = React.useMemo(function () {
|
|
991
|
+
return typeof onFileDialogOpen === 'function' ? onFileDialogOpen : noop;
|
|
992
|
+
}, [onFileDialogOpen]);
|
|
993
|
+
var onFileDialogCancelCb = React.useMemo(function () {
|
|
994
|
+
return typeof onFileDialogCancel === 'function' ? onFileDialogCancel : noop;
|
|
995
|
+
}, [onFileDialogCancel]);
|
|
996
|
+
var rootRef = React.useRef(null);
|
|
997
|
+
var inputRef = React.useRef(null);
|
|
998
|
+
|
|
999
|
+
var _useReducer = React.useReducer(reducer, initialState),
|
|
1000
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
1001
|
+
state = _useReducer2[0],
|
|
1002
|
+
dispatch = _useReducer2[1];
|
|
1003
|
+
|
|
1004
|
+
var isFocused = state.isFocused,
|
|
1005
|
+
isFileDialogActive = state.isFileDialogActive,
|
|
1006
|
+
draggedFiles = state.draggedFiles; // Update file dialog active state when the window is focused on
|
|
1007
|
+
|
|
1008
|
+
var onWindowFocus = function onWindowFocus() {
|
|
1009
|
+
// Execute the timeout only if the file dialog is opened in the browser
|
|
1010
|
+
if (isFileDialogActive) {
|
|
1011
|
+
setTimeout(function () {
|
|
1012
|
+
if (inputRef.current) {
|
|
1013
|
+
var files = inputRef.current.files;
|
|
1014
|
+
|
|
1015
|
+
if (!files.length) {
|
|
1016
|
+
dispatch({
|
|
1017
|
+
type: 'closeDialog'
|
|
1018
|
+
});
|
|
1019
|
+
onFileDialogCancelCb();
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}, 300);
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
React.useEffect(function () {
|
|
1027
|
+
if (useFsAccessApi && canUseFileSystemAccessAPI()) {
|
|
1028
|
+
return function () {};
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
window.addEventListener('focus', onWindowFocus, false);
|
|
1032
|
+
return function () {
|
|
1033
|
+
window.removeEventListener('focus', onWindowFocus, false);
|
|
1034
|
+
};
|
|
1035
|
+
}, [inputRef, isFileDialogActive, onFileDialogCancelCb, useFsAccessApi]);
|
|
1036
|
+
var dragTargetsRef = React.useRef([]);
|
|
1037
|
+
|
|
1038
|
+
var onDocumentDrop = function onDocumentDrop(event) {
|
|
1039
|
+
if (rootRef.current && rootRef.current.contains(event.target)) {
|
|
1040
|
+
// If we intercepted an event for our instance, let it propagate down to the instance's onDrop handler
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
event.preventDefault();
|
|
1045
|
+
dragTargetsRef.current = [];
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
React.useEffect(function () {
|
|
1049
|
+
if (preventDropOnDocument) {
|
|
1050
|
+
document.addEventListener('dragover', onDocumentDragOver, false);
|
|
1051
|
+
document.addEventListener('drop', onDocumentDrop, false);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
return function () {
|
|
1055
|
+
if (preventDropOnDocument) {
|
|
1056
|
+
document.removeEventListener('dragover', onDocumentDragOver);
|
|
1057
|
+
document.removeEventListener('drop', onDocumentDrop);
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
}, [rootRef, preventDropOnDocument]);
|
|
1061
|
+
var onDragEnterCb = React.useCallback(function (event) {
|
|
1062
|
+
event.preventDefault(); // Persist here because we need the event later after getFilesFromEvent() is done
|
|
1063
|
+
|
|
1064
|
+
event.persist();
|
|
1065
|
+
stopPropagation(event);
|
|
1066
|
+
dragTargetsRef.current = [].concat(_toConsumableArray(dragTargetsRef.current), [event.target]);
|
|
1067
|
+
|
|
1068
|
+
if (isEvtWithFiles(event)) {
|
|
1069
|
+
Promise.resolve(getFilesFromEvent(event)).then(function (draggedFiles) {
|
|
1070
|
+
if (isPropagationStopped(event) && !noDragEventsBubbling) {
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
dispatch({
|
|
1075
|
+
draggedFiles: draggedFiles,
|
|
1076
|
+
isDragActive: true,
|
|
1077
|
+
type: 'setDraggedFiles'
|
|
1078
|
+
});
|
|
1079
|
+
|
|
1080
|
+
if (onDragEnter) {
|
|
1081
|
+
onDragEnter(event);
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
}, [getFilesFromEvent, onDragEnter, noDragEventsBubbling]);
|
|
1086
|
+
var onDragOverCb = React.useCallback(function (event) {
|
|
1087
|
+
event.preventDefault();
|
|
1088
|
+
event.persist();
|
|
1089
|
+
stopPropagation(event);
|
|
1090
|
+
var hasFiles = isEvtWithFiles(event);
|
|
1091
|
+
|
|
1092
|
+
if (hasFiles && event.dataTransfer) {
|
|
1093
|
+
try {
|
|
1094
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
1095
|
+
} catch (_unused) {}
|
|
1096
|
+
/* eslint-disable-line no-empty */
|
|
1097
|
+
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
if (hasFiles && onDragOver) {
|
|
1101
|
+
onDragOver(event);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
return false;
|
|
1105
|
+
}, [onDragOver, noDragEventsBubbling]);
|
|
1106
|
+
var onDragLeaveCb = React.useCallback(function (event) {
|
|
1107
|
+
event.preventDefault();
|
|
1108
|
+
event.persist();
|
|
1109
|
+
stopPropagation(event); // Only deactivate once the dropzone and all children have been left
|
|
1110
|
+
|
|
1111
|
+
var targets = dragTargetsRef.current.filter(function (target) {
|
|
1112
|
+
return rootRef.current && rootRef.current.contains(target);
|
|
1113
|
+
}); // Make sure to remove a target present multiple times only once
|
|
1114
|
+
// (Firefox may fire dragenter/dragleave multiple times on the same element)
|
|
1115
|
+
|
|
1116
|
+
var targetIdx = targets.indexOf(event.target);
|
|
1117
|
+
|
|
1118
|
+
if (targetIdx !== -1) {
|
|
1119
|
+
targets.splice(targetIdx, 1);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
dragTargetsRef.current = targets;
|
|
1123
|
+
|
|
1124
|
+
if (targets.length > 0) {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
dispatch({
|
|
1129
|
+
isDragActive: false,
|
|
1130
|
+
type: 'setDraggedFiles',
|
|
1131
|
+
draggedFiles: []
|
|
1132
|
+
});
|
|
1133
|
+
|
|
1134
|
+
if (isEvtWithFiles(event) && onDragLeave) {
|
|
1135
|
+
onDragLeave(event);
|
|
1136
|
+
}
|
|
1137
|
+
}, [rootRef, onDragLeave, noDragEventsBubbling]);
|
|
1138
|
+
var setFiles = React.useCallback(function (files, event) {
|
|
1139
|
+
var acceptedFiles = [];
|
|
1140
|
+
var fileRejections = [];
|
|
1141
|
+
files.forEach(function (file) {
|
|
1142
|
+
var _fileAccepted = fileAccepted(file, accept),
|
|
1143
|
+
_fileAccepted2 = _slicedToArray(_fileAccepted, 2),
|
|
1144
|
+
accepted = _fileAccepted2[0],
|
|
1145
|
+
acceptError = _fileAccepted2[1];
|
|
1146
|
+
|
|
1147
|
+
var _fileMatchSize = fileMatchSize(file, minSize, maxSize),
|
|
1148
|
+
_fileMatchSize2 = _slicedToArray(_fileMatchSize, 2),
|
|
1149
|
+
sizeMatch = _fileMatchSize2[0],
|
|
1150
|
+
sizeError = _fileMatchSize2[1];
|
|
1151
|
+
|
|
1152
|
+
var customErrors = validator ? validator(file) : null;
|
|
1153
|
+
|
|
1154
|
+
if (accepted && sizeMatch && !customErrors) {
|
|
1155
|
+
acceptedFiles.push(file);
|
|
1156
|
+
} else {
|
|
1157
|
+
var errors = [acceptError, sizeError];
|
|
1158
|
+
|
|
1159
|
+
if (customErrors) {
|
|
1160
|
+
errors = errors.concat(customErrors);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
fileRejections.push({
|
|
1164
|
+
file: file,
|
|
1165
|
+
errors: errors.filter(function (e) {
|
|
1166
|
+
return e;
|
|
1167
|
+
})
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
if (!multiple && acceptedFiles.length > 1 || multiple && maxFiles >= 1 && acceptedFiles.length > maxFiles) {
|
|
1173
|
+
// Reject everything and empty accepted files
|
|
1174
|
+
acceptedFiles.forEach(function (file) {
|
|
1175
|
+
fileRejections.push({
|
|
1176
|
+
file: file,
|
|
1177
|
+
errors: [TOO_MANY_FILES_REJECTION]
|
|
1178
|
+
});
|
|
1179
|
+
});
|
|
1180
|
+
acceptedFiles.splice(0);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
dispatch({
|
|
1184
|
+
acceptedFiles: acceptedFiles,
|
|
1185
|
+
fileRejections: fileRejections,
|
|
1186
|
+
type: 'setFiles'
|
|
1187
|
+
});
|
|
1188
|
+
|
|
1189
|
+
if (onDrop) {
|
|
1190
|
+
onDrop(acceptedFiles, fileRejections, event);
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
if (fileRejections.length > 0 && onDropRejected) {
|
|
1194
|
+
onDropRejected(fileRejections, event);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
if (acceptedFiles.length > 0 && onDropAccepted) {
|
|
1198
|
+
onDropAccepted(acceptedFiles, event);
|
|
1199
|
+
}
|
|
1200
|
+
}, [dispatch, multiple, accept, minSize, maxSize, maxFiles, onDrop, onDropAccepted, onDropRejected, validator]);
|
|
1201
|
+
var onDropCb = React.useCallback(function (event) {
|
|
1202
|
+
event.preventDefault(); // Persist here because we need the event later after getFilesFromEvent() is done
|
|
1203
|
+
|
|
1204
|
+
event.persist();
|
|
1205
|
+
stopPropagation(event);
|
|
1206
|
+
dragTargetsRef.current = [];
|
|
1207
|
+
|
|
1208
|
+
if (isEvtWithFiles(event)) {
|
|
1209
|
+
Promise.resolve(getFilesFromEvent(event)).then(function (files) {
|
|
1210
|
+
if (isPropagationStopped(event) && !noDragEventsBubbling) {
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
setFiles(files, event);
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
dispatch({
|
|
1219
|
+
type: 'reset'
|
|
1220
|
+
});
|
|
1221
|
+
}, [getFilesFromEvent, setFiles, noDragEventsBubbling]); // Fn for opening the file dialog programmatically
|
|
1222
|
+
|
|
1223
|
+
var openFileDialog = React.useCallback(function () {
|
|
1224
|
+
if (useFsAccessApi && canUseFileSystemAccessAPI()) {
|
|
1225
|
+
dispatch({
|
|
1226
|
+
type: 'openDialog'
|
|
1227
|
+
});
|
|
1228
|
+
onFileDialogOpenCb(); // https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker
|
|
1229
|
+
|
|
1230
|
+
var opts = {
|
|
1231
|
+
multiple: multiple,
|
|
1232
|
+
types: filePickerOptionsTypes(accept)
|
|
1233
|
+
};
|
|
1234
|
+
window.showOpenFilePicker(opts).then(function (handles) {
|
|
1235
|
+
return getFilesFromEvent(handles);
|
|
1236
|
+
}).then(function (files) {
|
|
1237
|
+
return setFiles(files, null);
|
|
1238
|
+
}).catch(function (e) {
|
|
1239
|
+
return onFileDialogCancelCb(e);
|
|
1240
|
+
}).finally(function () {
|
|
1241
|
+
return dispatch({
|
|
1242
|
+
type: 'closeDialog'
|
|
1243
|
+
});
|
|
1244
|
+
});
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
if (inputRef.current) {
|
|
1249
|
+
dispatch({
|
|
1250
|
+
type: 'openDialog'
|
|
1251
|
+
});
|
|
1252
|
+
onFileDialogOpenCb();
|
|
1253
|
+
inputRef.current.value = null;
|
|
1254
|
+
inputRef.current.click();
|
|
1255
|
+
}
|
|
1256
|
+
}, [dispatch, onFileDialogOpenCb, onFileDialogCancelCb, useFsAccessApi, setFiles, accept, multiple]); // Cb to open the file dialog when SPACE/ENTER occurs on the dropzone
|
|
1257
|
+
|
|
1258
|
+
var onKeyDownCb = React.useCallback(function (event) {
|
|
1259
|
+
// Ignore keyboard events bubbling up the DOM tree
|
|
1260
|
+
if (!rootRef.current || !rootRef.current.isEqualNode(event.target)) {
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
if (event.keyCode === 32 || event.keyCode === 13) {
|
|
1265
|
+
event.preventDefault();
|
|
1266
|
+
openFileDialog();
|
|
1267
|
+
}
|
|
1268
|
+
}, [rootRef, inputRef, openFileDialog]); // Update focus state for the dropzone
|
|
1269
|
+
|
|
1270
|
+
var onFocusCb = React.useCallback(function () {
|
|
1271
|
+
dispatch({
|
|
1272
|
+
type: 'focus'
|
|
1273
|
+
});
|
|
1274
|
+
}, []);
|
|
1275
|
+
var onBlurCb = React.useCallback(function () {
|
|
1276
|
+
dispatch({
|
|
1277
|
+
type: 'blur'
|
|
1278
|
+
});
|
|
1279
|
+
}, []); // Cb to open the file dialog when click occurs on the dropzone
|
|
1280
|
+
|
|
1281
|
+
var onClickCb = React.useCallback(function () {
|
|
1282
|
+
if (noClick) {
|
|
1283
|
+
return;
|
|
1284
|
+
} // In IE11/Edge the file-browser dialog is blocking, therefore, use setTimeout()
|
|
1285
|
+
// to ensure React can handle state changes
|
|
1286
|
+
// See: https://github.com/react-dropzone/react-dropzone/issues/450
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
if (isIeOrEdge()) {
|
|
1290
|
+
setTimeout(openFileDialog, 0);
|
|
1291
|
+
} else {
|
|
1292
|
+
openFileDialog();
|
|
1293
|
+
}
|
|
1294
|
+
}, [inputRef, noClick, openFileDialog]);
|
|
1295
|
+
|
|
1296
|
+
var composeHandler = function composeHandler(fn) {
|
|
1297
|
+
return disabled ? null : fn;
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
var composeKeyboardHandler = function composeKeyboardHandler(fn) {
|
|
1301
|
+
return noKeyboard ? null : composeHandler(fn);
|
|
1302
|
+
};
|
|
1303
|
+
|
|
1304
|
+
var composeDragHandler = function composeDragHandler(fn) {
|
|
1305
|
+
return noDrag ? null : composeHandler(fn);
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
var stopPropagation = function stopPropagation(event) {
|
|
1309
|
+
if (noDragEventsBubbling) {
|
|
1310
|
+
event.stopPropagation();
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
|
|
1314
|
+
var getRootProps = React.useMemo(function () {
|
|
1315
|
+
return function () {
|
|
1316
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1317
|
+
_ref2$refKey = _ref2.refKey,
|
|
1318
|
+
refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
|
|
1319
|
+
role = _ref2.role,
|
|
1320
|
+
onKeyDown = _ref2.onKeyDown,
|
|
1321
|
+
onFocus = _ref2.onFocus,
|
|
1322
|
+
onBlur = _ref2.onBlur,
|
|
1323
|
+
onClick = _ref2.onClick,
|
|
1324
|
+
onDragEnter = _ref2.onDragEnter,
|
|
1325
|
+
onDragOver = _ref2.onDragOver,
|
|
1326
|
+
onDragLeave = _ref2.onDragLeave,
|
|
1327
|
+
onDrop = _ref2.onDrop,
|
|
1328
|
+
rest = _objectWithoutProperties(_ref2, _excluded3);
|
|
1329
|
+
|
|
1330
|
+
return _objectSpread(_objectSpread(_defineProperty({
|
|
1331
|
+
onKeyDown: composeKeyboardHandler(composeEventHandlers(onKeyDown, onKeyDownCb)),
|
|
1332
|
+
onFocus: composeKeyboardHandler(composeEventHandlers(onFocus, onFocusCb)),
|
|
1333
|
+
onBlur: composeKeyboardHandler(composeEventHandlers(onBlur, onBlurCb)),
|
|
1334
|
+
onClick: composeHandler(composeEventHandlers(onClick, onClickCb)),
|
|
1335
|
+
onDragEnter: composeDragHandler(composeEventHandlers(onDragEnter, onDragEnterCb)),
|
|
1336
|
+
onDragOver: composeDragHandler(composeEventHandlers(onDragOver, onDragOverCb)),
|
|
1337
|
+
onDragLeave: composeDragHandler(composeEventHandlers(onDragLeave, onDragLeaveCb)),
|
|
1338
|
+
onDrop: composeDragHandler(composeEventHandlers(onDrop, onDropCb)),
|
|
1339
|
+
role: typeof role === 'string' && role !== '' ? role : 'button'
|
|
1340
|
+
}, refKey, rootRef), !disabled && !noKeyboard ? {
|
|
1341
|
+
tabIndex: 0
|
|
1342
|
+
} : {}), rest);
|
|
1343
|
+
};
|
|
1344
|
+
}, [rootRef, onKeyDownCb, onFocusCb, onBlurCb, onClickCb, onDragEnterCb, onDragOverCb, onDragLeaveCb, onDropCb, noKeyboard, noDrag, disabled]);
|
|
1345
|
+
var onInputElementClick = React.useCallback(function (event) {
|
|
1346
|
+
event.stopPropagation();
|
|
1347
|
+
}, []);
|
|
1348
|
+
var getInputProps = React.useMemo(function () {
|
|
1349
|
+
return function () {
|
|
1350
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1351
|
+
_ref3$refKey = _ref3.refKey,
|
|
1352
|
+
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
1353
|
+
onChange = _ref3.onChange,
|
|
1354
|
+
onClick = _ref3.onClick,
|
|
1355
|
+
rest = _objectWithoutProperties(_ref3, _excluded4);
|
|
1356
|
+
|
|
1357
|
+
var inputProps = _defineProperty({
|
|
1358
|
+
accept: accept,
|
|
1359
|
+
multiple: multiple,
|
|
1360
|
+
type: 'file',
|
|
1361
|
+
style: {
|
|
1362
|
+
display: 'none'
|
|
1363
|
+
},
|
|
1364
|
+
onChange: composeHandler(composeEventHandlers(onChange, onDropCb)),
|
|
1365
|
+
onClick: composeHandler(composeEventHandlers(onClick, onInputElementClick)),
|
|
1366
|
+
autoComplete: 'off',
|
|
1367
|
+
tabIndex: -1
|
|
1368
|
+
}, refKey, inputRef);
|
|
1369
|
+
|
|
1370
|
+
return _objectSpread(_objectSpread({}, inputProps), rest);
|
|
1371
|
+
};
|
|
1372
|
+
}, [inputRef, accept, multiple, onDropCb, disabled]);
|
|
1373
|
+
var fileCount = draggedFiles.length;
|
|
1374
|
+
var isDragAccept = fileCount > 0 && allFilesAccepted({
|
|
1375
|
+
files: draggedFiles,
|
|
1376
|
+
accept: accept,
|
|
1377
|
+
minSize: minSize,
|
|
1378
|
+
maxSize: maxSize,
|
|
1379
|
+
multiple: multiple,
|
|
1380
|
+
maxFiles: maxFiles
|
|
1381
|
+
});
|
|
1382
|
+
var isDragReject = fileCount > 0 && !isDragAccept;
|
|
1383
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
1384
|
+
isDragAccept: isDragAccept,
|
|
1385
|
+
isDragReject: isDragReject,
|
|
1386
|
+
isFocused: isFocused && !disabled,
|
|
1387
|
+
getRootProps: getRootProps,
|
|
1388
|
+
getInputProps: getInputProps,
|
|
1389
|
+
rootRef: rootRef,
|
|
1390
|
+
inputRef: inputRef,
|
|
1391
|
+
open: composeHandler(openFileDialog)
|
|
1392
|
+
});
|
|
1172
1393
|
}
|
|
1394
|
+
|
|
1173
1395
|
function reducer(state, action) {
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
default: return state;
|
|
1218
|
-
}
|
|
1396
|
+
/* istanbul ignore next */
|
|
1397
|
+
switch (action.type) {
|
|
1398
|
+
case 'focus':
|
|
1399
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
1400
|
+
isFocused: true
|
|
1401
|
+
});
|
|
1402
|
+
|
|
1403
|
+
case 'blur':
|
|
1404
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
1405
|
+
isFocused: false
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
case 'openDialog':
|
|
1409
|
+
return _objectSpread(_objectSpread({}, initialState), {}, {
|
|
1410
|
+
isFileDialogActive: true
|
|
1411
|
+
});
|
|
1412
|
+
|
|
1413
|
+
case 'closeDialog':
|
|
1414
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
1415
|
+
isFileDialogActive: false
|
|
1416
|
+
});
|
|
1417
|
+
|
|
1418
|
+
case 'setDraggedFiles':
|
|
1419
|
+
/* eslint no-case-declarations: 0 */
|
|
1420
|
+
var isDragActive = action.isDragActive,
|
|
1421
|
+
draggedFiles = action.draggedFiles;
|
|
1422
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
1423
|
+
draggedFiles: draggedFiles,
|
|
1424
|
+
isDragActive: isDragActive
|
|
1425
|
+
});
|
|
1426
|
+
|
|
1427
|
+
case 'setFiles':
|
|
1428
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
1429
|
+
acceptedFiles: action.acceptedFiles,
|
|
1430
|
+
fileRejections: action.fileRejections
|
|
1431
|
+
});
|
|
1432
|
+
|
|
1433
|
+
case 'reset':
|
|
1434
|
+
return _objectSpread({}, initialState);
|
|
1435
|
+
|
|
1436
|
+
default:
|
|
1437
|
+
return state;
|
|
1438
|
+
}
|
|
1219
1439
|
}
|
|
1440
|
+
|
|
1220
1441
|
function noop() {}
|
|
1221
1442
|
|
|
1222
1443
|
var styles = {"dropZoneBase":"fSDkYM-382I-","dropZone":"yT6m1v71VK8-","active":"fCb0O1wAjR0-","error":"Cm5wIem0XQI-","validationErrors":"wyjYhAlF1qA-","dropzoneContent":"sAxF04DcAi4-"};
|
|
@@ -1338,13 +1559,13 @@ function InputFile({ variation = "dropzone", size = "base", name, buttonLabel: p
|
|
|
1338
1559
|
validator: handleValidation,
|
|
1339
1560
|
};
|
|
1340
1561
|
if (allowedTypes === "images") {
|
|
1341
|
-
options.accept =
|
|
1562
|
+
options.accept = "image/*";
|
|
1342
1563
|
}
|
|
1343
1564
|
else if (allowedTypes === "basicImages") {
|
|
1344
|
-
options.accept =
|
|
1565
|
+
options.accept = convertToMimeTypes(BASIC_IMAGE_TYPES).join(",");
|
|
1345
1566
|
}
|
|
1346
1567
|
else if (Array.isArray(allowedTypes)) {
|
|
1347
|
-
options.accept =
|
|
1568
|
+
options.accept = convertToMimeTypes(allowedTypes).join(",");
|
|
1348
1569
|
}
|
|
1349
1570
|
const { getRootProps, getInputProps, isDragActive, fileRejections } = useDropzone(options);
|
|
1350
1571
|
const allowedTypesString = Array.isArray(allowedTypes)
|
|
@@ -1417,9 +1638,7 @@ function InputFile({ variation = "dropzone", size = "base", name, buttonLabel: p
|
|
|
1417
1638
|
React.createElement("input", Object.assign({}, getInputProps(), { "data-testid": "input-file-input", name: name })),
|
|
1418
1639
|
React.createElement(InputFileContentContext.Provider, { value: contentContext }, children || defaultContent)),
|
|
1419
1640
|
React.createElement(InputFileValidationErrors, { validationErrors: validationErrors })));
|
|
1420
|
-
function handleDrop(acceptedFiles
|
|
1421
|
-
if (rejectedFiles.some(hasTooManyFilesError))
|
|
1422
|
-
return;
|
|
1641
|
+
function handleDrop(acceptedFiles) {
|
|
1423
1642
|
acceptedFiles.forEach(file => {
|
|
1424
1643
|
uploadFile(file);
|
|
1425
1644
|
});
|
|
@@ -1464,12 +1683,6 @@ function InputFile({ variation = "dropzone", size = "base", name, buttonLabel: p
|
|
|
1464
1683
|
});
|
|
1465
1684
|
}
|
|
1466
1685
|
}
|
|
1467
|
-
function mimeTypesToAccept(mimeTypes) {
|
|
1468
|
-
return Object.fromEntries(mimeTypes.map(mimeType => [mimeType, []]));
|
|
1469
|
-
}
|
|
1470
|
-
function hasTooManyFilesError({ errors }) {
|
|
1471
|
-
return errors.some(error => error.code === "too-many-files");
|
|
1472
|
-
}
|
|
1473
1686
|
function createAxiosConfig({ url, httpMethod = "POST", fields = {}, file, handleUploadProgress, }) {
|
|
1474
1687
|
let data;
|
|
1475
1688
|
let headers;
|