react-dropzone 11.7.1 → 12.0.0
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/.eslintrc +1 -3
- package/README.md +2 -1
- package/commitlint.config.js +1 -1
- package/dist/es/index.js +39 -39
- package/dist/es/utils/index.js +22 -22
- package/dist/index.js +2 -2
- package/package.json +5 -4
- package/rollup.config.js +20 -20
- package/src/.eslintrc +1 -2
- package/src/index.js +307 -275
- package/src/index.spec.js +1688 -1526
- package/src/utils/index.js +100 -73
- package/src/utils/index.spec.js +386 -289
- package/styleguide.config.js +55 -52
- package/testSetup.js +1 -1
- package/typings/.eslintrc +1 -1
- package/typings/react-dropzone.d.ts +24 -14
- package/typings/tests/accept.tsx +10 -9
- package/typings/tests/all.tsx +6 -5
- package/typings/tests/basic.tsx +8 -7
- package/typings/tests/events.tsx +8 -6
- package/typings/tests/file-dialog.tsx +4 -3
- package/typings/tests/hook.tsx +6 -6
- package/typings/tests/plugin.tsx +11 -22
- package/typings/tests/refs.tsx +4 -4
package/.eslintrc
CHANGED
package/README.md
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
[](https://codecov.io/gh/react-dropzone/react-dropzone)
|
|
7
7
|
[](#backers)
|
|
8
8
|
[](#sponsors)
|
|
9
|
-
[](https://gitpod.io/#https://github.com/react-dropzone/react-dropzone)
|
|
9
|
+
[](https://gitpod.io/#https://github.com/react-dropzone/react-dropzone)
|
|
10
|
+
[](https://github.com/react-dropzone/.github/blob/main/CODE_OF_CONDUCT.md)
|
|
10
11
|
|
|
11
12
|
Simple React hook to create a HTML5-compliant drag'n'drop zone for files.
|
|
12
13
|
|
package/commitlint.config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = { extends: [
|
|
1
|
+
module.exports = { extends: ["@commitlint/config-angular"] };
|
package/dist/es/index.js
CHANGED
|
@@ -34,10 +34,10 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
34
34
|
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; }
|
|
35
35
|
|
|
36
36
|
/* eslint prefer-template: 0 */
|
|
37
|
-
import React, { forwardRef, Fragment, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef } from
|
|
38
|
-
import PropTypes from
|
|
39
|
-
import { fromEvent } from
|
|
40
|
-
import { allFilesAccepted, composeEventHandlers, fileAccepted, fileMatchSize, filePickerOptionsTypes, canUseFileSystemAccessAPI, isEvtWithFiles, isIeOrEdge, isPropagationStopped, onDocumentDragOver, TOO_MANY_FILES_REJECTION } from
|
|
37
|
+
import React, { forwardRef, Fragment, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef } from "react";
|
|
38
|
+
import PropTypes from "prop-types";
|
|
39
|
+
import { fromEvent } from "file-selector";
|
|
40
|
+
import { allFilesAccepted, composeEventHandlers, fileAccepted, fileMatchSize, filePickerOptionsTypes, canUseFileSystemAccessAPI, isEvtWithFiles, isIeOrEdge, isPropagationStopped, onDocumentDragOver, TOO_MANY_FILES_REJECTION } from "./utils/index";
|
|
41
41
|
/**
|
|
42
42
|
* Convenience wrapper component for the `useDropzone` hook
|
|
43
43
|
*
|
|
@@ -71,7 +71,7 @@ var Dropzone = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
71
71
|
open: open
|
|
72
72
|
})));
|
|
73
73
|
});
|
|
74
|
-
Dropzone.displayName =
|
|
74
|
+
Dropzone.displayName = "Dropzone"; // Add default props for react-docgen
|
|
75
75
|
|
|
76
76
|
var defaultProps = {
|
|
77
77
|
disabled: false,
|
|
@@ -86,7 +86,7 @@ var defaultProps = {
|
|
|
86
86
|
noDrag: false,
|
|
87
87
|
noDragEventsBubbling: false,
|
|
88
88
|
validator: null,
|
|
89
|
-
useFsAccessApi:
|
|
89
|
+
useFsAccessApi: true
|
|
90
90
|
};
|
|
91
91
|
Dropzone.defaultProps = defaultProps;
|
|
92
92
|
Dropzone.propTypes = {
|
|
@@ -450,10 +450,10 @@ export function useDropzone() {
|
|
|
450
450
|
validator = _defaultProps$options.validator;
|
|
451
451
|
|
|
452
452
|
var onFileDialogOpenCb = useMemo(function () {
|
|
453
|
-
return typeof onFileDialogOpen ===
|
|
453
|
+
return typeof onFileDialogOpen === "function" ? onFileDialogOpen : noop;
|
|
454
454
|
}, [onFileDialogOpen]);
|
|
455
455
|
var onFileDialogCancelCb = useMemo(function () {
|
|
456
|
-
return typeof onFileDialogCancel ===
|
|
456
|
+
return typeof onFileDialogCancel === "function" ? onFileDialogCancel : noop;
|
|
457
457
|
}, [onFileDialogCancel]);
|
|
458
458
|
var rootRef = useRef(null);
|
|
459
459
|
var inputRef = useRef(null);
|
|
@@ -476,7 +476,7 @@ export function useDropzone() {
|
|
|
476
476
|
|
|
477
477
|
if (!files.length) {
|
|
478
478
|
dispatch({
|
|
479
|
-
type:
|
|
479
|
+
type: "closeDialog"
|
|
480
480
|
});
|
|
481
481
|
onFileDialogCancelCb();
|
|
482
482
|
}
|
|
@@ -490,9 +490,9 @@ export function useDropzone() {
|
|
|
490
490
|
return function () {};
|
|
491
491
|
}
|
|
492
492
|
|
|
493
|
-
window.addEventListener(
|
|
493
|
+
window.addEventListener("focus", onWindowFocus, false);
|
|
494
494
|
return function () {
|
|
495
|
-
window.removeEventListener(
|
|
495
|
+
window.removeEventListener("focus", onWindowFocus, false);
|
|
496
496
|
};
|
|
497
497
|
}, [inputRef, isFileDialogActive, onFileDialogCancelCb, useFsAccessApi]);
|
|
498
498
|
var dragTargetsRef = useRef([]);
|
|
@@ -509,14 +509,14 @@ export function useDropzone() {
|
|
|
509
509
|
|
|
510
510
|
useEffect(function () {
|
|
511
511
|
if (preventDropOnDocument) {
|
|
512
|
-
document.addEventListener(
|
|
513
|
-
document.addEventListener(
|
|
512
|
+
document.addEventListener("dragover", onDocumentDragOver, false);
|
|
513
|
+
document.addEventListener("drop", onDocumentDrop, false);
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
return function () {
|
|
517
517
|
if (preventDropOnDocument) {
|
|
518
|
-
document.removeEventListener(
|
|
519
|
-
document.removeEventListener(
|
|
518
|
+
document.removeEventListener("dragover", onDocumentDragOver);
|
|
519
|
+
document.removeEventListener("drop", onDocumentDrop);
|
|
520
520
|
}
|
|
521
521
|
};
|
|
522
522
|
}, [rootRef, preventDropOnDocument]);
|
|
@@ -536,7 +536,7 @@ export function useDropzone() {
|
|
|
536
536
|
dispatch({
|
|
537
537
|
draggedFiles: draggedFiles,
|
|
538
538
|
isDragActive: true,
|
|
539
|
-
type:
|
|
539
|
+
type: "setDraggedFiles"
|
|
540
540
|
});
|
|
541
541
|
|
|
542
542
|
if (onDragEnter) {
|
|
@@ -553,7 +553,7 @@ export function useDropzone() {
|
|
|
553
553
|
|
|
554
554
|
if (hasFiles && event.dataTransfer) {
|
|
555
555
|
try {
|
|
556
|
-
event.dataTransfer.dropEffect =
|
|
556
|
+
event.dataTransfer.dropEffect = "copy";
|
|
557
557
|
} catch (_unused) {}
|
|
558
558
|
/* eslint-disable-line no-empty */
|
|
559
559
|
|
|
@@ -589,7 +589,7 @@ export function useDropzone() {
|
|
|
589
589
|
|
|
590
590
|
dispatch({
|
|
591
591
|
isDragActive: false,
|
|
592
|
-
type:
|
|
592
|
+
type: "setDraggedFiles",
|
|
593
593
|
draggedFiles: []
|
|
594
594
|
});
|
|
595
595
|
|
|
@@ -645,7 +645,7 @@ export function useDropzone() {
|
|
|
645
645
|
dispatch({
|
|
646
646
|
acceptedFiles: acceptedFiles,
|
|
647
647
|
fileRejections: fileRejections,
|
|
648
|
-
type:
|
|
648
|
+
type: "setFiles"
|
|
649
649
|
});
|
|
650
650
|
|
|
651
651
|
if (onDrop) {
|
|
@@ -678,14 +678,14 @@ export function useDropzone() {
|
|
|
678
678
|
}
|
|
679
679
|
|
|
680
680
|
dispatch({
|
|
681
|
-
type:
|
|
681
|
+
type: "reset"
|
|
682
682
|
});
|
|
683
683
|
}, [getFilesFromEvent, setFiles, noDragEventsBubbling]); // Fn for opening the file dialog programmatically
|
|
684
684
|
|
|
685
685
|
var openFileDialog = useCallback(function () {
|
|
686
686
|
if (useFsAccessApi && canUseFileSystemAccessAPI()) {
|
|
687
687
|
dispatch({
|
|
688
|
-
type:
|
|
688
|
+
type: "openDialog"
|
|
689
689
|
});
|
|
690
690
|
onFileDialogOpenCb(); // https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker
|
|
691
691
|
|
|
@@ -701,7 +701,7 @@ export function useDropzone() {
|
|
|
701
701
|
return onFileDialogCancelCb(e);
|
|
702
702
|
}).finally(function () {
|
|
703
703
|
return dispatch({
|
|
704
|
-
type:
|
|
704
|
+
type: "closeDialog"
|
|
705
705
|
});
|
|
706
706
|
});
|
|
707
707
|
return;
|
|
@@ -709,7 +709,7 @@ export function useDropzone() {
|
|
|
709
709
|
|
|
710
710
|
if (inputRef.current) {
|
|
711
711
|
dispatch({
|
|
712
|
-
type:
|
|
712
|
+
type: "openDialog"
|
|
713
713
|
});
|
|
714
714
|
onFileDialogOpenCb();
|
|
715
715
|
inputRef.current.value = null;
|
|
@@ -731,12 +731,12 @@ export function useDropzone() {
|
|
|
731
731
|
|
|
732
732
|
var onFocusCb = useCallback(function () {
|
|
733
733
|
dispatch({
|
|
734
|
-
type:
|
|
734
|
+
type: "focus"
|
|
735
735
|
});
|
|
736
736
|
}, []);
|
|
737
737
|
var onBlurCb = useCallback(function () {
|
|
738
738
|
dispatch({
|
|
739
|
-
type:
|
|
739
|
+
type: "blur"
|
|
740
740
|
});
|
|
741
741
|
}, []); // Cb to open the file dialog when click occurs on the dropzone
|
|
742
742
|
|
|
@@ -777,7 +777,7 @@ export function useDropzone() {
|
|
|
777
777
|
return function () {
|
|
778
778
|
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
779
779
|
_ref2$refKey = _ref2.refKey,
|
|
780
|
-
refKey = _ref2$refKey === void 0 ?
|
|
780
|
+
refKey = _ref2$refKey === void 0 ? "ref" : _ref2$refKey,
|
|
781
781
|
role = _ref2.role,
|
|
782
782
|
onKeyDown = _ref2.onKeyDown,
|
|
783
783
|
onFocus = _ref2.onFocus,
|
|
@@ -798,7 +798,7 @@ export function useDropzone() {
|
|
|
798
798
|
onDragOver: composeDragHandler(composeEventHandlers(onDragOver, onDragOverCb)),
|
|
799
799
|
onDragLeave: composeDragHandler(composeEventHandlers(onDragLeave, onDragLeaveCb)),
|
|
800
800
|
onDrop: composeDragHandler(composeEventHandlers(onDrop, onDropCb)),
|
|
801
|
-
role: typeof role ===
|
|
801
|
+
role: typeof role === "string" && role !== "" ? role : "button"
|
|
802
802
|
}, refKey, rootRef), !disabled && !noKeyboard ? {
|
|
803
803
|
tabIndex: 0
|
|
804
804
|
} : {}), rest);
|
|
@@ -811,7 +811,7 @@ export function useDropzone() {
|
|
|
811
811
|
return function () {
|
|
812
812
|
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
813
813
|
_ref3$refKey = _ref3.refKey,
|
|
814
|
-
refKey = _ref3$refKey === void 0 ?
|
|
814
|
+
refKey = _ref3$refKey === void 0 ? "ref" : _ref3$refKey,
|
|
815
815
|
onChange = _ref3.onChange,
|
|
816
816
|
onClick = _ref3.onClick,
|
|
817
817
|
rest = _objectWithoutProperties(_ref3, _excluded4);
|
|
@@ -819,13 +819,13 @@ export function useDropzone() {
|
|
|
819
819
|
var inputProps = _defineProperty({
|
|
820
820
|
accept: accept,
|
|
821
821
|
multiple: multiple,
|
|
822
|
-
type:
|
|
822
|
+
type: "file",
|
|
823
823
|
style: {
|
|
824
|
-
display:
|
|
824
|
+
display: "none"
|
|
825
825
|
},
|
|
826
826
|
onChange: composeHandler(composeEventHandlers(onChange, onDropCb)),
|
|
827
827
|
onClick: composeHandler(composeEventHandlers(onClick, onInputElementClick)),
|
|
828
|
-
autoComplete:
|
|
828
|
+
autoComplete: "off",
|
|
829
829
|
tabIndex: -1
|
|
830
830
|
}, refKey, inputRef);
|
|
831
831
|
|
|
@@ -857,27 +857,27 @@ export function useDropzone() {
|
|
|
857
857
|
function reducer(state, action) {
|
|
858
858
|
/* istanbul ignore next */
|
|
859
859
|
switch (action.type) {
|
|
860
|
-
case
|
|
860
|
+
case "focus":
|
|
861
861
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
862
862
|
isFocused: true
|
|
863
863
|
});
|
|
864
864
|
|
|
865
|
-
case
|
|
865
|
+
case "blur":
|
|
866
866
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
867
867
|
isFocused: false
|
|
868
868
|
});
|
|
869
869
|
|
|
870
|
-
case
|
|
870
|
+
case "openDialog":
|
|
871
871
|
return _objectSpread(_objectSpread({}, initialState), {}, {
|
|
872
872
|
isFileDialogActive: true
|
|
873
873
|
});
|
|
874
874
|
|
|
875
|
-
case
|
|
875
|
+
case "closeDialog":
|
|
876
876
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
877
877
|
isFileDialogActive: false
|
|
878
878
|
});
|
|
879
879
|
|
|
880
|
-
case
|
|
880
|
+
case "setDraggedFiles":
|
|
881
881
|
/* eslint no-case-declarations: 0 */
|
|
882
882
|
var isDragActive = action.isDragActive,
|
|
883
883
|
draggedFiles = action.draggedFiles;
|
|
@@ -886,13 +886,13 @@ function reducer(state, action) {
|
|
|
886
886
|
isDragActive: isDragActive
|
|
887
887
|
});
|
|
888
888
|
|
|
889
|
-
case
|
|
889
|
+
case "setFiles":
|
|
890
890
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
891
891
|
acceptedFiles: action.acceptedFiles,
|
|
892
892
|
fileRejections: action.fileRejections
|
|
893
893
|
});
|
|
894
894
|
|
|
895
|
-
case
|
|
895
|
+
case "reset":
|
|
896
896
|
return _objectSpread({}, initialState);
|
|
897
897
|
|
|
898
898
|
default:
|
|
@@ -902,4 +902,4 @@ function reducer(state, action) {
|
|
|
902
902
|
|
|
903
903
|
function noop() {}
|
|
904
904
|
|
|
905
|
-
export { ErrorCode } from
|
|
905
|
+
export { ErrorCode } from "./utils";
|
package/dist/es/utils/index.js
CHANGED
|
@@ -18,12 +18,12 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
18
18
|
|
|
19
19
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
20
|
|
|
21
|
-
import accepts from
|
|
21
|
+
import accepts from "attr-accept"; // Error codes
|
|
22
22
|
|
|
23
|
-
export var FILE_INVALID_TYPE =
|
|
24
|
-
export var FILE_TOO_LARGE =
|
|
25
|
-
export var FILE_TOO_SMALL =
|
|
26
|
-
export var TOO_MANY_FILES =
|
|
23
|
+
export var FILE_INVALID_TYPE = "file-invalid-type";
|
|
24
|
+
export var FILE_TOO_LARGE = "file-too-large";
|
|
25
|
+
export var FILE_TOO_SMALL = "file-too-small";
|
|
26
|
+
export var TOO_MANY_FILES = "too-many-files";
|
|
27
27
|
export var ErrorCode = {
|
|
28
28
|
FileInvalidType: FILE_INVALID_TYPE,
|
|
29
29
|
FileTooLarge: FILE_TOO_LARGE,
|
|
@@ -33,7 +33,7 @@ export var ErrorCode = {
|
|
|
33
33
|
|
|
34
34
|
export var getInvalidTypeRejectionErr = function getInvalidTypeRejectionErr(accept) {
|
|
35
35
|
accept = Array.isArray(accept) && accept.length === 1 ? accept[0] : accept;
|
|
36
|
-
var messageSuffix = Array.isArray(accept) ? "one of ".concat(accept.join(
|
|
36
|
+
var messageSuffix = Array.isArray(accept) ? "one of ".concat(accept.join(", ")) : accept;
|
|
37
37
|
return {
|
|
38
38
|
code: FILE_INVALID_TYPE,
|
|
39
39
|
message: "File type must be ".concat(messageSuffix)
|
|
@@ -42,23 +42,23 @@ export var getInvalidTypeRejectionErr = function getInvalidTypeRejectionErr(acce
|
|
|
42
42
|
export var getTooLargeRejectionErr = function getTooLargeRejectionErr(maxSize) {
|
|
43
43
|
return {
|
|
44
44
|
code: FILE_TOO_LARGE,
|
|
45
|
-
message: "File is larger than ".concat(maxSize, " ").concat(maxSize === 1 ?
|
|
45
|
+
message: "File is larger than ".concat(maxSize, " ").concat(maxSize === 1 ? "byte" : "bytes")
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
48
|
export var getTooSmallRejectionErr = function getTooSmallRejectionErr(minSize) {
|
|
49
49
|
return {
|
|
50
50
|
code: FILE_TOO_SMALL,
|
|
51
|
-
message: "File is smaller than ".concat(minSize, " ").concat(minSize === 1 ?
|
|
51
|
+
message: "File is smaller than ".concat(minSize, " ").concat(minSize === 1 ? "byte" : "bytes")
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
54
|
export var TOO_MANY_FILES_REJECTION = {
|
|
55
55
|
code: TOO_MANY_FILES,
|
|
56
|
-
message:
|
|
56
|
+
message: "Too many files"
|
|
57
57
|
}; // Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
|
|
58
58
|
// that MIME type will always be accepted
|
|
59
59
|
|
|
60
60
|
export function fileAccepted(file, accept) {
|
|
61
|
-
var isAcceptable = file.type ===
|
|
61
|
+
var isAcceptable = file.type === "application/x-moz-file" || accepts(file, accept);
|
|
62
62
|
return [isAcceptable, isAcceptable ? null : getInvalidTypeRejectionErr(accept)];
|
|
63
63
|
}
|
|
64
64
|
export function fileMatchSize(file, minSize, maxSize) {
|
|
@@ -104,9 +104,9 @@ export function allFilesAccepted(_ref) {
|
|
|
104
104
|
// to check event.cancelBubble
|
|
105
105
|
|
|
106
106
|
export function isPropagationStopped(event) {
|
|
107
|
-
if (typeof event.isPropagationStopped ===
|
|
107
|
+
if (typeof event.isPropagationStopped === "function") {
|
|
108
108
|
return event.isPropagationStopped();
|
|
109
|
-
} else if (typeof event.cancelBubble !==
|
|
109
|
+
} else if (typeof event.cancelBubble !== "undefined") {
|
|
110
110
|
return event.cancelBubble;
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -120,11 +120,11 @@ export function isEvtWithFiles(event) {
|
|
|
120
120
|
|
|
121
121
|
|
|
122
122
|
return Array.prototype.some.call(event.dataTransfer.types, function (type) {
|
|
123
|
-
return type ===
|
|
123
|
+
return type === "Files" || type === "application/x-moz-file";
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
export function isKindFile(item) {
|
|
127
|
-
return _typeof(item) ===
|
|
127
|
+
return _typeof(item) === "object" && item !== null && item.kind === "file";
|
|
128
128
|
} // allow the entire document to be a drag target
|
|
129
129
|
|
|
130
130
|
export function onDocumentDragOver(event) {
|
|
@@ -132,11 +132,11 @@ export function onDocumentDragOver(event) {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
function isIe(userAgent) {
|
|
135
|
-
return userAgent.indexOf(
|
|
135
|
+
return userAgent.indexOf("MSIE") !== -1 || userAgent.indexOf("Trident/") !== -1;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
function isEdge(userAgent) {
|
|
139
|
-
return userAgent.indexOf(
|
|
139
|
+
return userAgent.indexOf("Edge/") !== -1;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
export function isIeOrEdge() {
|
|
@@ -180,7 +180,7 @@ export function composeEventHandlers() {
|
|
|
180
180
|
*/
|
|
181
181
|
|
|
182
182
|
export function canUseFileSystemAccessAPI() {
|
|
183
|
-
return
|
|
183
|
+
return "showOpenFilePicker" in window;
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
186
|
* filePickerOptionsTypes returns the {types} option for https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker
|
|
@@ -190,14 +190,14 @@ export function canUseFileSystemAccessAPI() {
|
|
|
190
190
|
*/
|
|
191
191
|
|
|
192
192
|
export function filePickerOptionsTypes(accept) {
|
|
193
|
-
accept = typeof accept ===
|
|
193
|
+
accept = typeof accept === "string" ? accept.split(",") : accept;
|
|
194
194
|
return [{
|
|
195
|
-
description:
|
|
195
|
+
description: "everything",
|
|
196
196
|
// TODO: Need to handle filtering more elegantly than this!
|
|
197
|
-
accept: Array.isArray(accept) // Accept just MIME types as per spec
|
|
197
|
+
accept: Array.isArray(accept) ? // Accept just MIME types as per spec
|
|
198
198
|
// NOTE: accept can be https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#unique_file_type_specifiers
|
|
199
|
-
|
|
200
|
-
return item ===
|
|
199
|
+
accept.filter(function (item) {
|
|
200
|
+
return item === "audio/*" || item === "video/*" || item === "image/*" || item === "text/*" || /\w+\/[-+.\w]+/g.test(item);
|
|
201
201
|
}).reduce(function (a, b) {
|
|
202
202
|
return _objectSpread(_objectSpread({}, a), {}, _defineProperty({}, b, []));
|
|
203
203
|
}, {}) : {}
|