react-dropzone 11.5.2 → 11.7.1
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/.eslintignore +1 -3
- package/.eslintrc +1 -1
- package/.husky/commit-msg +5 -0
- package/.husky/pre-commit +5 -0
- package/.nvmrc +1 -1
- package/README.md +77 -29
- package/dist/es/index.js +168 -124
- package/dist/es/utils/index.js +39 -3
- package/dist/index.js +16 -2
- package/examples/events/README.md +3 -1
- package/examples/no-jsx/README.md +32 -0
- package/package.json +78 -75
- package/rollup.config.js +9 -6
- package/src/.eslintrc +7 -3
- package/src/__snapshots__/index.spec.js.snap +1 -1
- package/src/index.js +186 -134
- package/src/index.spec.js +306 -0
- package/src/utils/index.js +38 -4
- package/src/utils/index.spec.js +92 -29
- package/styleguide.config.js +4 -0
- package/typings/.eslintrc +28 -0
- package/tslint.json +0 -101
package/dist/es/utils/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
function
|
|
1
|
+
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; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
8
|
|
|
3
9
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
10
|
|
|
@@ -36,13 +42,13 @@ export var getInvalidTypeRejectionErr = function getInvalidTypeRejectionErr(acce
|
|
|
36
42
|
export var getTooLargeRejectionErr = function getTooLargeRejectionErr(maxSize) {
|
|
37
43
|
return {
|
|
38
44
|
code: FILE_TOO_LARGE,
|
|
39
|
-
message: "File is larger than ".concat(maxSize, "
|
|
45
|
+
message: "File is larger than ".concat(maxSize, " ").concat(maxSize === 1 ? 'byte' : 'bytes')
|
|
40
46
|
};
|
|
41
47
|
};
|
|
42
48
|
export var getTooSmallRejectionErr = function getTooSmallRejectionErr(minSize) {
|
|
43
49
|
return {
|
|
44
50
|
code: FILE_TOO_SMALL,
|
|
45
|
-
message: "File is smaller than ".concat(minSize, "
|
|
51
|
+
message: "File is smaller than ".concat(minSize, " ").concat(minSize === 1 ? 'byte' : 'bytes')
|
|
46
52
|
};
|
|
47
53
|
};
|
|
48
54
|
export var TOO_MANY_FILES_REJECTION = {
|
|
@@ -166,4 +172,34 @@ export function composeEventHandlers() {
|
|
|
166
172
|
return isPropagationStopped(event);
|
|
167
173
|
});
|
|
168
174
|
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* canUseFileSystemAccessAPI checks if the [File System Access API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API)
|
|
178
|
+
* is supported by the browser.
|
|
179
|
+
* @returns {boolean}
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
export function canUseFileSystemAccessAPI() {
|
|
183
|
+
return 'showOpenFilePicker' in window;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* filePickerOptionsTypes returns the {types} option for https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker
|
|
187
|
+
* based on the accept attr (see https://github.com/react-dropzone/attr-accept)
|
|
188
|
+
* E.g: converts ['image/*', 'text/*'] to {'image/*': [], 'text/*': []}
|
|
189
|
+
* @param {string|string[]} accept
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
export function filePickerOptionsTypes(accept) {
|
|
193
|
+
accept = typeof accept === 'string' ? accept.split(',') : accept;
|
|
194
|
+
return [{
|
|
195
|
+
description: 'everything',
|
|
196
|
+
// TODO: Need to handle filtering more elegantly than this!
|
|
197
|
+
accept: Array.isArray(accept) // Accept just MIME types as per spec
|
|
198
|
+
// NOTE: accept can be https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#unique_file_type_specifiers
|
|
199
|
+
? accept.filter(function (item) {
|
|
200
|
+
return item === 'audio/*' || item === 'video/*' || item === 'image/*' || item === 'text/*' || /\w+\/[-+.\w]+/g.test(item);
|
|
201
|
+
}).reduce(function (a, b) {
|
|
202
|
+
return _objectSpread(_objectSpread({}, a), {}, _defineProperty({}, b, []));
|
|
203
|
+
}, {}) : {}
|
|
204
|
+
}];
|
|
169
205
|
}
|