react-dropzone 11.5.3 → 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.
@@ -1,4 +1,10 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
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
 
@@ -12,12 +18,12 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
12
18
 
13
19
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
20
 
15
- import accepts from 'attr-accept'; // Error codes
21
+ import accepts from "attr-accept"; // Error codes
16
22
 
17
- export var FILE_INVALID_TYPE = 'file-invalid-type';
18
- export var FILE_TOO_LARGE = 'file-too-large';
19
- export var FILE_TOO_SMALL = 'file-too-small';
20
- export var TOO_MANY_FILES = '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";
21
27
  export var ErrorCode = {
22
28
  FileInvalidType: FILE_INVALID_TYPE,
23
29
  FileTooLarge: FILE_TOO_LARGE,
@@ -27,7 +33,7 @@ export var ErrorCode = {
27
33
 
28
34
  export var getInvalidTypeRejectionErr = function getInvalidTypeRejectionErr(accept) {
29
35
  accept = Array.isArray(accept) && accept.length === 1 ? accept[0] : accept;
30
- var messageSuffix = Array.isArray(accept) ? "one of ".concat(accept.join(', ')) : accept;
36
+ var messageSuffix = Array.isArray(accept) ? "one of ".concat(accept.join(", ")) : accept;
31
37
  return {
32
38
  code: FILE_INVALID_TYPE,
33
39
  message: "File type must be ".concat(messageSuffix)
@@ -36,23 +42,23 @@ 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, " ").concat(maxSize === 1 ? 'byte' : 'bytes')
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, " ").concat(minSize === 1 ? 'byte' : 'bytes')
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 = {
49
55
  code: TOO_MANY_FILES,
50
- message: 'Too many files'
56
+ message: "Too many files"
51
57
  }; // Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
52
58
  // that MIME type will always be accepted
53
59
 
54
60
  export function fileAccepted(file, accept) {
55
- var isAcceptable = file.type === 'application/x-moz-file' || accepts(file, accept);
61
+ var isAcceptable = file.type === "application/x-moz-file" || accepts(file, accept);
56
62
  return [isAcceptable, isAcceptable ? null : getInvalidTypeRejectionErr(accept)];
57
63
  }
58
64
  export function fileMatchSize(file, minSize, maxSize) {
@@ -98,9 +104,9 @@ export function allFilesAccepted(_ref) {
98
104
  // to check event.cancelBubble
99
105
 
100
106
  export function isPropagationStopped(event) {
101
- if (typeof event.isPropagationStopped === 'function') {
107
+ if (typeof event.isPropagationStopped === "function") {
102
108
  return event.isPropagationStopped();
103
- } else if (typeof event.cancelBubble !== 'undefined') {
109
+ } else if (typeof event.cancelBubble !== "undefined") {
104
110
  return event.cancelBubble;
105
111
  }
106
112
 
@@ -114,11 +120,11 @@ export function isEvtWithFiles(event) {
114
120
 
115
121
 
116
122
  return Array.prototype.some.call(event.dataTransfer.types, function (type) {
117
- return type === 'Files' || type === 'application/x-moz-file';
123
+ return type === "Files" || type === "application/x-moz-file";
118
124
  });
119
125
  }
120
126
  export function isKindFile(item) {
121
- return _typeof(item) === 'object' && item !== null && item.kind === 'file';
127
+ return _typeof(item) === "object" && item !== null && item.kind === "file";
122
128
  } // allow the entire document to be a drag target
123
129
 
124
130
  export function onDocumentDragOver(event) {
@@ -126,11 +132,11 @@ export function onDocumentDragOver(event) {
126
132
  }
127
133
 
128
134
  function isIe(userAgent) {
129
- return userAgent.indexOf('MSIE') !== -1 || userAgent.indexOf('Trident/') !== -1;
135
+ return userAgent.indexOf("MSIE") !== -1 || userAgent.indexOf("Trident/") !== -1;
130
136
  }
131
137
 
132
138
  function isEdge(userAgent) {
133
- return userAgent.indexOf('Edge/') !== -1;
139
+ return userAgent.indexOf("Edge/") !== -1;
134
140
  }
135
141
 
136
142
  export function isIeOrEdge() {
@@ -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
  }