react-dropzone 14.3.4 → 14.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/es/utils/index.js +22 -8
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/src/utils/index.js +21 -10
- package/src/utils/index.spec.js +46 -8
- package/typings/react-dropzone.d.ts +2 -2
package/package.json
CHANGED
package/src/utils/index.js
CHANGED
|
@@ -15,15 +15,18 @@ export const ErrorCode = {
|
|
|
15
15
|
TooManyFiles: TOO_MANY_FILES,
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {string} accept
|
|
21
|
+
*/
|
|
22
|
+
export const getInvalidTypeRejectionErr = (accept = "") => {
|
|
23
|
+
const acceptArr = accept.split(",");
|
|
24
|
+
const msg =
|
|
25
|
+
acceptArr.length > 1 ? `one of ${acceptArr.join(", ")}` : acceptArr[0];
|
|
26
|
+
|
|
24
27
|
return {
|
|
25
28
|
code: FILE_INVALID_TYPE,
|
|
26
|
-
message: `File type must be ${
|
|
29
|
+
message: `File type must be ${msg}`,
|
|
27
30
|
};
|
|
28
31
|
};
|
|
29
32
|
|
|
@@ -50,8 +53,16 @@ export const TOO_MANY_FILES_REJECTION = {
|
|
|
50
53
|
message: "Too many files",
|
|
51
54
|
};
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Check if file is accepted.
|
|
58
|
+
*
|
|
59
|
+
* Firefox versions prior to 53 return a bogus MIME type for every file drag,
|
|
60
|
+
* so dragovers with that MIME type will always be accepted.
|
|
61
|
+
*
|
|
62
|
+
* @param {File} file
|
|
63
|
+
* @param {string} accept
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
55
66
|
export function fileAccepted(file, accept) {
|
|
56
67
|
const isAcceptable =
|
|
57
68
|
file.type === "application/x-moz-file" || accepts(file, accept);
|
|
@@ -82,7 +93,7 @@ function isDefined(value) {
|
|
|
82
93
|
*
|
|
83
94
|
* @param {object} options
|
|
84
95
|
* @param {File[]} options.files
|
|
85
|
-
* @param {string
|
|
96
|
+
* @param {string} [options.accept]
|
|
86
97
|
* @param {number} [options.minSize]
|
|
87
98
|
* @param {number} [options.maxSize]
|
|
88
99
|
* @param {boolean} [options.multiple]
|
package/src/utils/index.spec.js
CHANGED
|
@@ -269,7 +269,7 @@ describe("fileAccepted()", () => {
|
|
|
269
269
|
|
|
270
270
|
it("accepts file when multiple accept criteria", () => {
|
|
271
271
|
const file = createFile("hamster.pdf", 100, "application/pdf");
|
|
272
|
-
expect(utils.fileAccepted(file,
|
|
272
|
+
expect(utils.fileAccepted(file, ".pdf,.png")).toEqual([true, null]);
|
|
273
273
|
});
|
|
274
274
|
|
|
275
275
|
it("rejects file when single accept criteria", () => {
|
|
@@ -282,7 +282,7 @@ describe("fileAccepted()", () => {
|
|
|
282
282
|
|
|
283
283
|
it("rejects file when multiple accept criteria", () => {
|
|
284
284
|
const file = createFile("hamster.pdf", 100, "application/pdf");
|
|
285
|
-
expect(utils.fileAccepted(file,
|
|
285
|
+
expect(utils.fileAccepted(file, ".gif,.png")).toEqual([
|
|
286
286
|
false,
|
|
287
287
|
{
|
|
288
288
|
code: "file-invalid-type",
|
|
@@ -290,13 +290,51 @@ describe("fileAccepted()", () => {
|
|
|
290
290
|
},
|
|
291
291
|
]);
|
|
292
292
|
});
|
|
293
|
+
});
|
|
293
294
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
295
|
+
describe("getTooLargeRejectionErr()", () => {
|
|
296
|
+
/**
|
|
297
|
+
* @constant
|
|
298
|
+
* @type {import('./index')}
|
|
299
|
+
*/
|
|
300
|
+
let utils;
|
|
301
|
+
beforeEach(async () => {
|
|
302
|
+
utils = await import("./index");
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("prints byte when maxSize is 1", () => {
|
|
306
|
+
expect(utils.getTooLargeRejectionErr(1).message).toEqual(
|
|
307
|
+
"File is larger than 1 byte"
|
|
308
|
+
);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("prints bytes when maxSize > 1", () => {
|
|
312
|
+
expect(utils.getTooLargeRejectionErr(100).message).toEqual(
|
|
313
|
+
"File is larger than 100 bytes"
|
|
314
|
+
);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
describe("getTooSmallRejectionErr()", () => {
|
|
319
|
+
/**
|
|
320
|
+
* @constant
|
|
321
|
+
* @type {import('./index')}
|
|
322
|
+
*/
|
|
323
|
+
let utils;
|
|
324
|
+
beforeEach(async () => {
|
|
325
|
+
utils = await import("./index");
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("prints byte when minSize is 1", () => {
|
|
329
|
+
expect(utils.getTooSmallRejectionErr(1).message).toEqual(
|
|
330
|
+
"File is smaller than 1 byte"
|
|
331
|
+
);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("prints bytes when minSize > 1", () => {
|
|
335
|
+
expect(utils.getTooSmallRejectionErr(100).message).toEqual(
|
|
336
|
+
"File is smaller than 100 bytes"
|
|
337
|
+
);
|
|
300
338
|
});
|
|
301
339
|
});
|
|
302
340
|
|
|
@@ -4,11 +4,11 @@ import { FileWithPath } from "file-selector";
|
|
|
4
4
|
export { FileWithPath };
|
|
5
5
|
export default function Dropzone(
|
|
6
6
|
props: DropzoneProps & React.RefAttributes<DropzoneRef>
|
|
7
|
-
):
|
|
7
|
+
): React.ReactElement;
|
|
8
8
|
export function useDropzone(options?: DropzoneOptions): DropzoneState;
|
|
9
9
|
|
|
10
10
|
export interface DropzoneProps extends DropzoneOptions {
|
|
11
|
-
children?(state: DropzoneState):
|
|
11
|
+
children?(state: DropzoneState): React.ReactElement;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export enum ErrorCode {
|