react-dropzone 8.0.3 → 9.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/README.md +0 -6
- package/dist/es/index.js +19 -22
- package/dist/es/utils/index.js +24 -22
- package/dist/index.js +2 -2
- package/examples/Basic/Readme.md +3 -1
- package/examples/Events/README.md +20 -0
- package/examples/FileDialog/Readme.md +2 -4
- package/examples/Fullscreen/Readme.md +2 -3
- package/examples/Styling/Readme.md +6 -5
- package/package.json +6 -5
- package/src/index.js +17 -17
- package/src/index.spec.js +46 -68
- package/src/utils/index.js +24 -22
- package/src/utils/index.spec.js +35 -97
- package/styleguide.config.js +4 -4
- package/typings/react-dropzone.d.ts +0 -1
- package/typings/tests/all.tsx +0 -1
- package/dist/es/utils/styles.js +0 -27
- package/examples/Folders/Readme.md +0 -49
- package/src/utils/styles.js +0 -27
package/README.md
CHANGED
|
@@ -13,12 +13,6 @@ Simple HTML5-compliant drag'n'drop zone for files built with React.js.
|
|
|
13
13
|
Documentation and examples: https://react-dropzone.js.org
|
|
14
14
|
Source code: https://github.com/react-dropzone/react-dropzone/
|
|
15
15
|
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
**Looking for maintainers: https://github.com/react-dropzone/react-dropzone/issues/479**
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
16
|
## Installation
|
|
23
17
|
|
|
24
18
|
Install it from npm and include it in your React build process (using [Webpack](http://webpack.github.io/), [Browserify](http://browserify.org/), etc).
|
package/dist/es/index.js
CHANGED
|
@@ -17,8 +17,9 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
17
17
|
/* eslint prefer-template: 0 */
|
|
18
18
|
|
|
19
19
|
import React from 'react';
|
|
20
|
+
import { fromEvent } from 'file-selector';
|
|
20
21
|
import PropTypes from 'prop-types';
|
|
21
|
-
import { isDragDataWithFiles, supportMultiple, fileAccepted, allFilesAccepted, fileMatchSize, onDocumentDragOver,
|
|
22
|
+
import { isDragDataWithFiles, supportMultiple, fileAccepted, allFilesAccepted, fileMatchSize, onDocumentDragOver, isIeOrEdge, composeEventHandlers, isPropagationStopped, isDefaultPrevented } from './utils';
|
|
22
23
|
|
|
23
24
|
var Dropzone = function (_React$Component) {
|
|
24
25
|
_inherits(Dropzone, _React$Component);
|
|
@@ -62,7 +63,7 @@ var Dropzone = function (_React$Component) {
|
|
|
62
63
|
|
|
63
64
|
if (isDragDataWithFiles(evt)) {
|
|
64
65
|
Promise.resolve(_this.props.getDataTransferItems(evt)).then(function (draggedFiles) {
|
|
65
|
-
if (
|
|
66
|
+
if (isPropagationStopped(evt)) {
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -82,6 +83,10 @@ var Dropzone = function (_React$Component) {
|
|
|
82
83
|
evt.preventDefault();
|
|
83
84
|
evt.persist();
|
|
84
85
|
|
|
86
|
+
if (evt.dataTransfer) {
|
|
87
|
+
evt.dataTransfer.dropEffect = 'copy';
|
|
88
|
+
}
|
|
89
|
+
|
|
85
90
|
if (_this.props.onDragOver && isDragDataWithFiles(evt)) {
|
|
86
91
|
_this.props.onDragOver.call(_this, evt);
|
|
87
92
|
}
|
|
@@ -142,7 +147,7 @@ var Dropzone = function (_React$Component) {
|
|
|
142
147
|
var acceptedFiles = [];
|
|
143
148
|
var rejectedFiles = [];
|
|
144
149
|
|
|
145
|
-
if (
|
|
150
|
+
if (isPropagationStopped(evt)) {
|
|
146
151
|
return;
|
|
147
152
|
}
|
|
148
153
|
|
|
@@ -179,9 +184,7 @@ var Dropzone = function (_React$Component) {
|
|
|
179
184
|
});
|
|
180
185
|
}
|
|
181
186
|
}, _this.onClick = function (evt) {
|
|
182
|
-
var
|
|
183
|
-
onClick = _this$props2.onClick,
|
|
184
|
-
disableClick = _this$props2.disableClick;
|
|
187
|
+
var onClick = _this.props.onClick;
|
|
185
188
|
|
|
186
189
|
// if onClick prop is given, run it first
|
|
187
190
|
|
|
@@ -189,9 +192,9 @@ var Dropzone = function (_React$Component) {
|
|
|
189
192
|
onClick.call(_this, evt);
|
|
190
193
|
}
|
|
191
194
|
|
|
192
|
-
//
|
|
195
|
+
// If the event hasn't been default prevented from within
|
|
193
196
|
// the onClick listener, open the file dialog
|
|
194
|
-
if (!
|
|
197
|
+
if (!isDefaultPrevented(evt)) {
|
|
195
198
|
evt.stopPropagation();
|
|
196
199
|
|
|
197
200
|
// in IE11/Edge the file-browser dialog is blocking, ensure this is behind setTimeout
|
|
@@ -233,7 +236,7 @@ var Dropzone = function (_React$Component) {
|
|
|
233
236
|
if (onFocus) {
|
|
234
237
|
onFocus.call(_this, evt);
|
|
235
238
|
}
|
|
236
|
-
if (!
|
|
239
|
+
if (!isDefaultPrevented(evt)) {
|
|
237
240
|
_this.setState({ isFocused: true });
|
|
238
241
|
}
|
|
239
242
|
}, _this.onBlur = function (evt) {
|
|
@@ -242,7 +245,7 @@ var Dropzone = function (_React$Component) {
|
|
|
242
245
|
if (onBlur) {
|
|
243
246
|
onBlur.call(_this, evt);
|
|
244
247
|
}
|
|
245
|
-
if (!
|
|
248
|
+
if (!isDefaultPrevented(evt)) {
|
|
246
249
|
_this.setState({ isFocused: false });
|
|
247
250
|
}
|
|
248
251
|
}, _this.onKeyDown = function (evt) {
|
|
@@ -256,7 +259,7 @@ var Dropzone = function (_React$Component) {
|
|
|
256
259
|
onKeyDown.call(_this, evt);
|
|
257
260
|
}
|
|
258
261
|
|
|
259
|
-
if (!
|
|
262
|
+
if (!isDefaultPrevented(evt) && (evt.keyCode === 32 || evt.keyCode === 13)) {
|
|
260
263
|
evt.preventDefault();
|
|
261
264
|
_this.open();
|
|
262
265
|
}
|
|
@@ -303,10 +306,10 @@ var Dropzone = function (_React$Component) {
|
|
|
303
306
|
onClick = _ref3.onClick,
|
|
304
307
|
rest = _objectWithoutProperties(_ref3, ['refKey', 'onChange', 'onClick']);
|
|
305
308
|
|
|
306
|
-
var _this$
|
|
307
|
-
accept = _this$
|
|
308
|
-
multiple = _this$
|
|
309
|
-
name = _this$
|
|
309
|
+
var _this$props2 = _this.props,
|
|
310
|
+
accept = _this$props2.accept,
|
|
311
|
+
multiple = _this$props2.multiple,
|
|
312
|
+
name = _this$props2.name;
|
|
310
313
|
|
|
311
314
|
var inputProps = _defineProperty({
|
|
312
315
|
accept: accept,
|
|
@@ -435,11 +438,6 @@ Dropzone.propTypes = {
|
|
|
435
438
|
*/
|
|
436
439
|
children: PropTypes.func,
|
|
437
440
|
|
|
438
|
-
/**
|
|
439
|
-
* Disallow clicking on the dropzone container to open file dialog
|
|
440
|
-
*/
|
|
441
|
-
disableClick: PropTypes.bool,
|
|
442
|
-
|
|
443
441
|
/**
|
|
444
442
|
* Enable/disable the dropzone entirely
|
|
445
443
|
*/
|
|
@@ -568,9 +566,8 @@ Dropzone.propTypes = {
|
|
|
568
566
|
Dropzone.defaultProps = {
|
|
569
567
|
preventDropOnDocument: true,
|
|
570
568
|
disabled: false,
|
|
571
|
-
disableClick: false,
|
|
572
569
|
multiple: true,
|
|
573
570
|
maxSize: Infinity,
|
|
574
571
|
minSize: 0,
|
|
575
|
-
getDataTransferItems:
|
|
572
|
+
getDataTransferItems: fromEvent
|
|
576
573
|
};
|
package/dist/es/utils/index.js
CHANGED
|
@@ -4,28 +4,6 @@ import accepts from 'attr-accept';
|
|
|
4
4
|
|
|
5
5
|
export var supportMultiple = typeof document !== 'undefined' && document && document.createElement ? 'multiple' in document.createElement('input') : true;
|
|
6
6
|
|
|
7
|
-
export function getDataTransferItems(event) {
|
|
8
|
-
var dataTransferItemsList = [];
|
|
9
|
-
if (event.dataTransfer) {
|
|
10
|
-
var dt = event.dataTransfer;
|
|
11
|
-
|
|
12
|
-
// NOTE: Only the 'drop' event has access to DataTransfer.files,
|
|
13
|
-
// otherwise it will always be empty
|
|
14
|
-
if (dt.files && dt.files.length) {
|
|
15
|
-
dataTransferItemsList = dt.files;
|
|
16
|
-
} else if (dt.items && dt.items.length) {
|
|
17
|
-
// During the drag even the dataTransfer.files is null
|
|
18
|
-
// but Chrome implements some drag store, which is accesible via dataTransfer.items
|
|
19
|
-
dataTransferItemsList = dt.items;
|
|
20
|
-
}
|
|
21
|
-
} else if (event.target && event.target.files) {
|
|
22
|
-
dataTransferItemsList = event.target.files;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Convert from DataTransferItemsList to the native Array
|
|
26
|
-
return Array.prototype.slice.call(dataTransferItemsList);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
7
|
// Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
|
|
30
8
|
// that MIME type will always be accepted
|
|
31
9
|
export function fileAccepted(file, accept) {
|
|
@@ -42,6 +20,30 @@ export function allFilesAccepted(files, accept) {
|
|
|
42
20
|
});
|
|
43
21
|
}
|
|
44
22
|
|
|
23
|
+
// React's synthetic events has evt.isPropagationStopped,
|
|
24
|
+
// but to remain compatibility with other libs (Preact) fall back
|
|
25
|
+
// to check evt.cancelBubble
|
|
26
|
+
export function isPropagationStopped(evt) {
|
|
27
|
+
if (typeof evt.isPropagationStopped === 'function') {
|
|
28
|
+
return evt.isPropagationStopped();
|
|
29
|
+
} else if (typeof evt.cancelBubble !== 'undefined') {
|
|
30
|
+
return evt.cancelBubble;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// React's synthetic events has evt.isDefaultPrevented,
|
|
36
|
+
// but to remain compatibility with other libs (Preact) first
|
|
37
|
+
// check evt.defaultPrevented
|
|
38
|
+
export function isDefaultPrevented(evt) {
|
|
39
|
+
if (typeof evt.defaultPrevented !== 'undefined') {
|
|
40
|
+
return evt.defaultPrevented;
|
|
41
|
+
} else if (typeof evt.isDefaultPrevented === 'function') {
|
|
42
|
+
return evt.isDefaultPrevented();
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
45
47
|
export function isDragDataWithFiles(evt) {
|
|
46
48
|
if (!evt.dataTransfer) {
|
|
47
49
|
return true;
|