react-dropzone 3.13.0 → 3.13.4
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 +3 -54
- package/.travis.yml +2 -7
- package/README.md +12 -78
- package/commitlint.config.js +1 -0
- package/dist/index.js +94 -71
- package/dist/index.js.map +1 -1
- package/examples/.eslintrc +3 -0
- package/examples/Accept/Readme.md +63 -11
- package/examples/Basic/Readme.md +9 -12
- package/examples/File Dialog/Readme.md +16 -0
- package/examples/Fullscreen/Readme.md +19 -20
- package/examples/Styling/Readme.md +23 -0
- package/package.json +28 -30
- package/src/__snapshots__/index.spec.js.snap +5 -3
- package/src/getDataTransferItems.js +7 -12
- package/src/getDataTransferItems.spec.js +48 -61
- package/src/index.js +164 -142
- package/src/index.spec.js +604 -592
- package/styleguide.config.js +28 -5
- package/testSetup.js +3 -2
- package/wallaby.config.js +3 -9
- package/webpack.config.js +3 -6
- package/yarn.lock +1549 -1029
- package/examples/Accept/index.js +0 -38
- package/examples/Basic/index.js +0 -26
- package/examples/Fullscreen/index.js +0 -78
- package/examples/Readme.md +0 -1
package/.eslintrc
CHANGED
|
@@ -1,60 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"parser": "babel-eslint",
|
|
3
2
|
"extends": [
|
|
4
|
-
"
|
|
3
|
+
"okonet"
|
|
5
4
|
],
|
|
6
|
-
"env": {
|
|
7
|
-
// We write for browser
|
|
8
|
-
"browser": true,
|
|
9
|
-
// using CommonJS imports
|
|
10
|
-
"node": true,
|
|
11
|
-
// We use Jest for tests
|
|
12
|
-
"jest": true,
|
|
13
|
-
// And we use ES6 features
|
|
14
|
-
"es6": true
|
|
15
|
-
},
|
|
16
|
-
"ecmaFeatures": {
|
|
17
|
-
"jsx": true
|
|
18
|
-
},
|
|
19
5
|
"rules": {
|
|
20
|
-
"indent": [
|
|
21
|
-
2,
|
|
22
|
-
2,
|
|
23
|
-
{
|
|
24
|
-
"SwitchCase": 1
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
"comma-dangle": [
|
|
28
|
-
2,
|
|
29
|
-
"never"
|
|
30
|
-
],
|
|
31
|
-
"jsx-quotes": [
|
|
32
|
-
2,
|
|
33
|
-
"prefer-double"
|
|
34
|
-
],
|
|
35
|
-
"padded-blocks": [
|
|
36
|
-
0,
|
|
37
|
-
"never"
|
|
38
|
-
],
|
|
39
|
-
"no-console": 2,
|
|
40
|
-
"no-debugger": 2,
|
|
41
|
-
"no-plusplus": 0,
|
|
42
|
-
"no-prototype-builtins": 0,
|
|
43
|
-
"guard-for-in": 0,
|
|
44
|
-
"object-curly-spacing": [
|
|
45
|
-
2,
|
|
46
|
-
"always"
|
|
47
|
-
],
|
|
48
|
-
"max-len": [
|
|
49
|
-
2,
|
|
50
|
-
{
|
|
51
|
-
"code": 120,
|
|
52
|
-
"ignoreComments": true
|
|
53
|
-
}
|
|
54
|
-
],
|
|
55
|
-
|
|
56
6
|
// React
|
|
57
|
-
"react/jsx-filename-extension": 0,
|
|
58
7
|
"react/forbid-prop-types": [
|
|
59
8
|
2,
|
|
60
9
|
{
|
|
@@ -73,9 +22,9 @@
|
|
|
73
22
|
2,
|
|
74
23
|
{
|
|
75
24
|
"devDependencies": [
|
|
76
|
-
"
|
|
25
|
+
"webpack*.js",
|
|
77
26
|
"**/*.spec.js",
|
|
78
|
-
"
|
|
27
|
+
"**/testSetup.js"
|
|
79
28
|
]
|
|
80
29
|
}
|
|
81
30
|
]
|
package/.travis.yml
CHANGED
package/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
# react-dropzone
|
|
4
4
|
|
|
5
|
-
[](https://travis-ci.org/okonet/
|
|
5
|
+
[](https://travis-ci.org/okonet/react-dropzone) [](https://badge.fury.io/js/react-dropzone) [](https://codecov.io/gh/okonet/react-dropzone) [](#backers)
|
|
6
6
|
[](#sponsors)
|
|
7
7
|
|
|
8
8
|
Simple HTML5-compliant drag'n'drop zone for files built with React.js.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Documentation and examples: https://react-dropzone.js.org
|
|
11
|
+
Source code: https://github.com/okonet/react-dropzone/
|
|
11
12
|
|
|
12
13
|
---
|
|
13
14
|
|
|
@@ -39,81 +40,6 @@ Files accepted or rejected based on `accept` prop. This must be a valid [MIME ty
|
|
|
39
40
|
|
|
40
41
|
Please note that `onDrop` method will always be called regardless if dropped file was accepted or rejected. The `onDropAccepted` method will be called if all dropped files were accepted and the `onDropRejected` method will be called if any of the dropped files was rejected.
|
|
41
42
|
|
|
42
|
-
## Styling Dropzone
|
|
43
|
-
|
|
44
|
-
By default, the component picks up some default styling to get you started. You can customize `<Dropzone>` by specifying a `style`, `activeStyle` or `rejectStyle` which is applied when a file is dragged over the zone. You can also specify `className`, `activeClassName` or `rejectClassName` if you would rather style using CSS.
|
|
45
|
-
|
|
46
|
-
## Updating styles and contents based on user input
|
|
47
|
-
|
|
48
|
-
By providing a function that returns the component's children you can not only style Dropzone appropriately but also render appropriate content.
|
|
49
|
-
|
|
50
|
-
```javascript
|
|
51
|
-
<Dropzone>
|
|
52
|
-
{({ isDragActive, isDragReject, acceptedFiles, rejectedFiles }) => {
|
|
53
|
-
if (isDragActive) {
|
|
54
|
-
return "This file is authorized";
|
|
55
|
-
}
|
|
56
|
-
if (isDragReject) {
|
|
57
|
-
return "This file is not authorized";
|
|
58
|
-
}
|
|
59
|
-
return acceptedFiles.length || rejectedFiles.length
|
|
60
|
-
? `Accepted ${acceptedFiles.length}, rejected ${rejectedFiles.length} files`
|
|
61
|
-
: "Try dropping some files";
|
|
62
|
-
}}
|
|
63
|
-
</Dropzone>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Programmatically open the file dialog
|
|
67
|
-
* To trigger the dropzone manually (open the file prompt), call the component's `open` function.
|
|
68
|
-
* The completion handler for the `open` function is also the `onDrop` function.
|
|
69
|
-
|
|
70
|
-
```jsx
|
|
71
|
-
/** @jsx React.DOM */
|
|
72
|
-
var React = require('react');
|
|
73
|
-
var Dropzone = require('react-dropzone');
|
|
74
|
-
|
|
75
|
-
var DropzoneDemo = React.createClass({
|
|
76
|
-
getInitialState: function () {
|
|
77
|
-
return {
|
|
78
|
-
files: []
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
onDrop: function (acceptedFiles) {
|
|
83
|
-
this.setState({
|
|
84
|
-
files: acceptedFiles
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
onOpenClick: function () {
|
|
89
|
-
this.dropzone.open();
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
render: function () {
|
|
93
|
-
return (
|
|
94
|
-
<div>
|
|
95
|
-
<Dropzone ref={(node) => { this.dropzone = node; }} onDrop={this.onDrop}>
|
|
96
|
-
<div>Try dropping some files here, or click to select files to upload.</div>
|
|
97
|
-
</Dropzone>
|
|
98
|
-
<button type="button" onClick={this.onOpenClick}>
|
|
99
|
-
Open Dropzone
|
|
100
|
-
</button>
|
|
101
|
-
{this.state.files.length > 0 ? <div>
|
|
102
|
-
<h2>Uploading {this.state.files.length} files...</h2>
|
|
103
|
-
<div>{this.state.files.map((file) => <img src={file.preview} /> )}</div>
|
|
104
|
-
</div> : null}
|
|
105
|
-
</div>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
React.render(<DropzoneDemo />, document.body);
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
*Important*: `react-dropzone` doesn't manage dropped files by itself. You need to destroy the object URL yourself whenever you don't need the `preview` by calling `window.URL.revokeObjectURL(file.preview);` to avoid memory leaks.
|
|
114
|
-
|
|
115
|
-
## Uploads
|
|
116
|
-
|
|
117
43
|
Using `react-dropzone` is similar to using a file form field, but instead of getting the `files` property from the field, you listen to the `onDrop` callback to handle the files. Simple explanation here: http://abandon.ie/notebook/simple-file-uploads-using-jquery-ajax
|
|
118
44
|
|
|
119
45
|
Specifying the `onDrop` method, provides you with an array of [Files](https://developer.mozilla.org/en-US/docs/Web/API/File) which you can then send to a server. For example, with [SuperAgent](https://github.com/visionmedia/superagent) as a http/ajax library:
|
|
@@ -128,6 +54,14 @@ Specifying the `onDrop` method, provides you with an array of [Files](https://de
|
|
|
128
54
|
}
|
|
129
55
|
```
|
|
130
56
|
|
|
57
|
+
## PropTypes
|
|
58
|
+
|
|
59
|
+
See https://react-dropzone.netlify.com/#proptypes
|
|
60
|
+
|
|
61
|
+
### Word of caution when working with previews
|
|
62
|
+
|
|
63
|
+
*Important*: `react-dropzone` doesn't manage dropped files. You need to destroy the object URL yourself whenever you don't need the `preview` by calling `window.URL.revokeObjectURL(file.preview);` to avoid memory leaks.
|
|
64
|
+
|
|
131
65
|
## Support
|
|
132
66
|
|
|
133
67
|
### Backers
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = { extends: ['@commitlint/config-angular'] }
|
package/dist/index.js
CHANGED
|
@@ -84,6 +84,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
84
84
|
|
|
85
85
|
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
|
86
86
|
|
|
87
|
+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
88
|
+
|
|
87
89
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
88
90
|
|
|
89
91
|
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
@@ -92,14 +94,20 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
92
94
|
|
|
93
95
|
var supportMultiple = typeof document !== 'undefined' && document && document.createElement ? 'multiple' in document.createElement('input') : true;
|
|
94
96
|
|
|
97
|
+
function fileAccepted(file, accept) {
|
|
98
|
+
// Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
|
|
99
|
+
// that MIME type will always be accepted
|
|
100
|
+
return file.type === 'application/x-moz-file' || (0, _attrAccept2.default)(file, accept);
|
|
101
|
+
}
|
|
102
|
+
|
|
95
103
|
var Dropzone = function (_React$Component) {
|
|
96
104
|
_inherits(Dropzone, _React$Component);
|
|
97
105
|
|
|
98
106
|
_createClass(Dropzone, null, [{
|
|
99
107
|
key: 'onDocumentDragOver',
|
|
100
|
-
value: function onDocumentDragOver(
|
|
108
|
+
value: function onDocumentDragOver(evt) {
|
|
101
109
|
// allow the entire document to be a drag target
|
|
102
|
-
|
|
110
|
+
evt.preventDefault();
|
|
103
111
|
}
|
|
104
112
|
}]);
|
|
105
113
|
|
|
@@ -108,9 +116,9 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
108
116
|
|
|
109
117
|
var _this = _possibleConstructorReturn(this, (Dropzone.__proto__ || Object.getPrototypeOf(Dropzone)).call(this, props, context));
|
|
110
118
|
|
|
111
|
-
_this.renderChildren = function (children) {
|
|
119
|
+
_this.renderChildren = function (children, isDragActive, isDragReject) {
|
|
112
120
|
if (typeof children === 'function') {
|
|
113
|
-
return children(_this.state);
|
|
121
|
+
return children(_extends({}, _this.state, { isDragActive: isDragActive, isDragReject: isDragReject }));
|
|
114
122
|
}
|
|
115
123
|
return children;
|
|
116
124
|
};
|
|
@@ -123,11 +131,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
123
131
|
_this.onDragOver = _this.onDragOver.bind(_this);
|
|
124
132
|
_this.onDrop = _this.onDrop.bind(_this);
|
|
125
133
|
_this.onFileDialogCancel = _this.onFileDialogCancel.bind(_this);
|
|
126
|
-
_this.fileAccepted = _this.fileAccepted.bind(_this);
|
|
127
134
|
_this.setRef = _this.setRef.bind(_this);
|
|
135
|
+
_this.setRefs = _this.setRefs.bind(_this);
|
|
136
|
+
_this.onInputElementClick = _this.onInputElementClick.bind(_this);
|
|
128
137
|
_this.isFileDialogActive = false;
|
|
129
138
|
_this.state = {
|
|
130
|
-
|
|
139
|
+
draggedFiles: [],
|
|
131
140
|
acceptedFiles: [],
|
|
132
141
|
rejectedFiles: []
|
|
133
142
|
};
|
|
@@ -145,6 +154,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
145
154
|
document.addEventListener('dragover', Dropzone.onDocumentDragOver, false);
|
|
146
155
|
document.addEventListener('drop', this.onDocumentDrop, false);
|
|
147
156
|
}
|
|
157
|
+
this.fileInputEl.addEventListener('click', this.onInputElementClick, false);
|
|
148
158
|
// Tried implementing addEventListener, but didn't work out
|
|
149
159
|
document.body.onfocus = this.onFileDialogCancel;
|
|
150
160
|
}
|
|
@@ -157,91 +167,85 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
157
167
|
document.removeEventListener('dragover', Dropzone.onDocumentDragOver);
|
|
158
168
|
document.removeEventListener('drop', this.onDocumentDrop);
|
|
159
169
|
}
|
|
170
|
+
this.fileInputEl.removeEventListener('click', this.onInputElementClick, false);
|
|
160
171
|
// Can be replaced with removeEventListener, if addEventListener works
|
|
161
172
|
document.body.onfocus = null;
|
|
162
173
|
}
|
|
163
174
|
}, {
|
|
164
175
|
key: 'onDocumentDrop',
|
|
165
|
-
value: function onDocumentDrop(
|
|
166
|
-
if (this.node.contains(
|
|
176
|
+
value: function onDocumentDrop(evt) {
|
|
177
|
+
if (this.node.contains(evt.target)) {
|
|
167
178
|
// if we intercepted an event for our instance, let it propagate down to the instance's onDrop handler
|
|
168
179
|
return;
|
|
169
180
|
}
|
|
170
|
-
|
|
181
|
+
evt.preventDefault();
|
|
171
182
|
this.dragTargets = [];
|
|
172
183
|
}
|
|
173
184
|
}, {
|
|
174
185
|
key: 'onDragStart',
|
|
175
|
-
value: function onDragStart(
|
|
186
|
+
value: function onDragStart(evt) {
|
|
176
187
|
if (this.props.onDragStart) {
|
|
177
|
-
this.props.onDragStart.call(this,
|
|
188
|
+
this.props.onDragStart.call(this, evt);
|
|
178
189
|
}
|
|
179
190
|
}
|
|
180
191
|
}, {
|
|
181
192
|
key: 'onDragEnter',
|
|
182
|
-
value: function onDragEnter(
|
|
183
|
-
|
|
193
|
+
value: function onDragEnter(evt) {
|
|
194
|
+
evt.preventDefault();
|
|
184
195
|
|
|
185
196
|
// Count the dropzone and any children that are entered.
|
|
186
|
-
if (this.dragTargets.indexOf(
|
|
187
|
-
this.dragTargets.push(
|
|
197
|
+
if (this.dragTargets.indexOf(evt.target) === -1) {
|
|
198
|
+
this.dragTargets.push(evt.target);
|
|
188
199
|
}
|
|
189
200
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this.setState({
|
|
193
|
-
isDragActive: allFilesAccepted,
|
|
194
|
-
isDragReject: !allFilesAccepted
|
|
195
|
-
});
|
|
201
|
+
this.setState({ draggedFiles: (0, _getDataTransferItems2.default)(evt) });
|
|
196
202
|
|
|
197
203
|
if (this.props.onDragEnter) {
|
|
198
|
-
this.props.onDragEnter.call(this,
|
|
204
|
+
this.props.onDragEnter.call(this, evt);
|
|
199
205
|
}
|
|
200
206
|
}
|
|
201
207
|
}, {
|
|
202
208
|
key: 'onDragOver',
|
|
203
|
-
value: function onDragOver(
|
|
209
|
+
value: function onDragOver(evt) {
|
|
204
210
|
// eslint-disable-line class-methods-use-this
|
|
205
|
-
|
|
206
|
-
|
|
211
|
+
evt.preventDefault();
|
|
212
|
+
evt.stopPropagation();
|
|
207
213
|
try {
|
|
208
|
-
|
|
214
|
+
evt.dataTransfer.dropEffect = 'copy'; // eslint-disable-line no-param-reassign
|
|
209
215
|
} catch (err) {
|
|
210
216
|
// continue regardless of error
|
|
211
217
|
}
|
|
212
218
|
|
|
213
219
|
if (this.props.onDragOver) {
|
|
214
|
-
this.props.onDragOver.call(this,
|
|
220
|
+
this.props.onDragOver.call(this, evt);
|
|
215
221
|
}
|
|
216
222
|
return false;
|
|
217
223
|
}
|
|
218
224
|
}, {
|
|
219
225
|
key: 'onDragLeave',
|
|
220
|
-
value: function onDragLeave(
|
|
226
|
+
value: function onDragLeave(evt) {
|
|
221
227
|
var _this2 = this;
|
|
222
228
|
|
|
223
|
-
|
|
229
|
+
evt.preventDefault();
|
|
224
230
|
|
|
225
231
|
// Only deactivate once the dropzone and all children have been left.
|
|
226
232
|
this.dragTargets = this.dragTargets.filter(function (el) {
|
|
227
|
-
return el !==
|
|
233
|
+
return el !== evt.target && _this2.node.contains(el);
|
|
228
234
|
});
|
|
229
235
|
if (this.dragTargets.length > 0) {
|
|
230
236
|
return;
|
|
231
237
|
}
|
|
232
238
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
isDragReject: false
|
|
236
|
-
});
|
|
239
|
+
// Clear dragging files state
|
|
240
|
+
this.setState({ draggedFiles: [] });
|
|
237
241
|
|
|
238
242
|
if (this.props.onDragLeave) {
|
|
239
|
-
this.props.onDragLeave.call(this,
|
|
243
|
+
this.props.onDragLeave.call(this, evt);
|
|
240
244
|
}
|
|
241
245
|
}
|
|
242
246
|
}, {
|
|
243
247
|
key: 'onDrop',
|
|
244
|
-
value: function onDrop(
|
|
248
|
+
value: function onDrop(evt) {
|
|
245
249
|
var _this3 = this;
|
|
246
250
|
|
|
247
251
|
var _props = this.props,
|
|
@@ -249,14 +253,15 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
249
253
|
onDropAccepted = _props.onDropAccepted,
|
|
250
254
|
onDropRejected = _props.onDropRejected,
|
|
251
255
|
multiple = _props.multiple,
|
|
252
|
-
disablePreview = _props.disablePreview
|
|
256
|
+
disablePreview = _props.disablePreview,
|
|
257
|
+
accept = _props.accept;
|
|
253
258
|
|
|
254
|
-
var fileList = (0, _getDataTransferItems2.default)(
|
|
259
|
+
var fileList = (0, _getDataTransferItems2.default)(evt);
|
|
255
260
|
var acceptedFiles = [];
|
|
256
261
|
var rejectedFiles = [];
|
|
257
262
|
|
|
258
263
|
// Stop default browser behavior
|
|
259
|
-
|
|
264
|
+
evt.preventDefault();
|
|
260
265
|
|
|
261
266
|
// Reset the counter along with the drag on a drop.
|
|
262
267
|
this.dragTargets = [];
|
|
@@ -273,46 +278,67 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
273
278
|
}
|
|
274
279
|
}
|
|
275
280
|
|
|
276
|
-
if (
|
|
281
|
+
if (fileAccepted(file, accept) && _this3.fileMatchSize(file)) {
|
|
277
282
|
acceptedFiles.push(file);
|
|
278
283
|
} else {
|
|
279
284
|
rejectedFiles.push(file);
|
|
280
285
|
}
|
|
281
286
|
});
|
|
282
287
|
|
|
288
|
+
if (!multiple) {
|
|
289
|
+
// if not in multi mode add any extra accepted files to rejected.
|
|
290
|
+
// This will allow end users to easily ignore a multi file drop in "single" mode.
|
|
291
|
+
rejectedFiles.push.apply(rejectedFiles, _toConsumableArray(acceptedFiles.splice(1)));
|
|
292
|
+
}
|
|
293
|
+
|
|
283
294
|
if (onDrop) {
|
|
284
|
-
onDrop.call(this, acceptedFiles, rejectedFiles,
|
|
295
|
+
onDrop.call(this, acceptedFiles, rejectedFiles, evt);
|
|
285
296
|
}
|
|
286
297
|
|
|
287
298
|
if (rejectedFiles.length > 0 && onDropRejected) {
|
|
288
|
-
onDropRejected.call(this, rejectedFiles,
|
|
299
|
+
onDropRejected.call(this, rejectedFiles, evt);
|
|
289
300
|
}
|
|
290
301
|
|
|
291
302
|
if (acceptedFiles.length > 0 && onDropAccepted) {
|
|
292
|
-
onDropAccepted.call(this, acceptedFiles,
|
|
303
|
+
onDropAccepted.call(this, acceptedFiles, evt);
|
|
293
304
|
}
|
|
294
305
|
|
|
306
|
+
// Clear files value
|
|
307
|
+
this.draggedFiles = null;
|
|
308
|
+
|
|
295
309
|
// Reset drag state
|
|
296
310
|
this.setState({
|
|
297
|
-
|
|
298
|
-
isDragReject: false,
|
|
311
|
+
draggedFiles: [],
|
|
299
312
|
acceptedFiles: acceptedFiles,
|
|
300
313
|
rejectedFiles: rejectedFiles
|
|
301
314
|
});
|
|
302
315
|
}
|
|
303
316
|
}, {
|
|
304
317
|
key: 'onClick',
|
|
305
|
-
value: function onClick(
|
|
318
|
+
value: function onClick(evt) {
|
|
306
319
|
var _props2 = this.props,
|
|
307
320
|
onClick = _props2.onClick,
|
|
308
321
|
disableClick = _props2.disableClick;
|
|
309
322
|
|
|
310
323
|
if (!disableClick) {
|
|
311
|
-
|
|
312
|
-
|
|
324
|
+
evt.stopPropagation();
|
|
325
|
+
|
|
313
326
|
if (onClick) {
|
|
314
|
-
onClick.call(this,
|
|
327
|
+
onClick.call(this, evt);
|
|
315
328
|
}
|
|
329
|
+
|
|
330
|
+
// in IE11/Edge the file-browser dialog is blocking, ensure this is behind setTimeout
|
|
331
|
+
// this is so react can handle state changes in the onClick prop above above
|
|
332
|
+
// see: https://github.com/okonet/react-dropzone/issues/450
|
|
333
|
+
setTimeout(this.open.bind(this), 0);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}, {
|
|
337
|
+
key: 'onInputElementClick',
|
|
338
|
+
value: function onInputElementClick(evt) {
|
|
339
|
+
evt.stopPropagation();
|
|
340
|
+
if (this.props.inputProps && this.props.inputProps.onClick) {
|
|
341
|
+
this.props.inputProps.onClick();
|
|
316
342
|
}
|
|
317
343
|
}
|
|
318
344
|
}, {
|
|
@@ -342,11 +368,9 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
342
368
|
this.node = ref;
|
|
343
369
|
}
|
|
344
370
|
}, {
|
|
345
|
-
key: '
|
|
346
|
-
value: function
|
|
347
|
-
|
|
348
|
-
// that MIME type will always be accepted
|
|
349
|
-
return file.type === 'application/x-moz-file' || (0, _attrAccept2.default)(file, this.props.accept);
|
|
371
|
+
key: 'setRefs',
|
|
372
|
+
value: function setRefs(ref) {
|
|
373
|
+
this.fileInputEl = ref;
|
|
350
374
|
}
|
|
351
375
|
}, {
|
|
352
376
|
key: 'fileMatchSize',
|
|
@@ -356,7 +380,11 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
356
380
|
}, {
|
|
357
381
|
key: 'allFilesAccepted',
|
|
358
382
|
value: function allFilesAccepted(files) {
|
|
359
|
-
|
|
383
|
+
var _this4 = this;
|
|
384
|
+
|
|
385
|
+
return files.every(function (file) {
|
|
386
|
+
return fileAccepted(file, _this4.props.accept);
|
|
387
|
+
});
|
|
360
388
|
}
|
|
361
389
|
|
|
362
390
|
/**
|
|
@@ -375,8 +403,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
375
403
|
}, {
|
|
376
404
|
key: 'render',
|
|
377
405
|
value: function render() {
|
|
378
|
-
var _this4 = this;
|
|
379
|
-
|
|
380
406
|
var _props3 = this.props,
|
|
381
407
|
accept = _props3.accept,
|
|
382
408
|
activeClassName = _props3.activeClassName,
|
|
@@ -393,10 +419,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
393
419
|
style = rest.style,
|
|
394
420
|
props = _objectWithoutProperties(rest, ['activeStyle', 'className', 'rejectStyle', 'style']);
|
|
395
421
|
|
|
396
|
-
var
|
|
397
|
-
isDragActive = _state.isDragActive,
|
|
398
|
-
isDragReject = _state.isDragReject;
|
|
422
|
+
var draggedFiles = this.state.draggedFiles;
|
|
399
423
|
|
|
424
|
+
var filesCount = draggedFiles.length;
|
|
425
|
+
var isMultipleAllowed = multiple || filesCount <= 1;
|
|
426
|
+
var isDragActive = filesCount > 0 && this.allFilesAccepted(draggedFiles);
|
|
427
|
+
var isDragReject = filesCount > 0 && (!isDragActive || !isMultipleAllowed);
|
|
400
428
|
|
|
401
429
|
className = className || '';
|
|
402
430
|
|
|
@@ -442,9 +470,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
442
470
|
type: 'file',
|
|
443
471
|
style: { display: 'none' },
|
|
444
472
|
multiple: supportMultiple && multiple,
|
|
445
|
-
ref:
|
|
446
|
-
return _this4.fileInputEl = el;
|
|
447
|
-
}, // eslint-disable-line
|
|
473
|
+
ref: this.setRefs,
|
|
448
474
|
onChange: this.onDrop
|
|
449
475
|
};
|
|
450
476
|
|
|
@@ -473,7 +499,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
473
499
|
onDrop: this.onDrop,
|
|
474
500
|
ref: this.setRef
|
|
475
501
|
}),
|
|
476
|
-
this.renderChildren(children),
|
|
502
|
+
this.renderChildren(children, isDragActive, isDragReject),
|
|
477
503
|
_react2.default.createElement('input', _extends({}, inputProps /* expand user provided inputProps first so inputAttributes override them */, inputAttributes))
|
|
478
504
|
);
|
|
479
505
|
}
|
|
@@ -801,6 +827,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
801
827
|
process.removeListener = noop;
|
|
802
828
|
process.removeAllListeners = noop;
|
|
803
829
|
process.emit = noop;
|
|
830
|
+
process.prependListener = noop;
|
|
831
|
+
process.prependOnceListener = noop;
|
|
832
|
+
|
|
833
|
+
process.listeners = function (name) { return [] }
|
|
804
834
|
|
|
805
835
|
process.binding = function (name) {
|
|
806
836
|
throw new Error('process.binding is not supported');
|
|
@@ -842,8 +872,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
842
872
|
});
|
|
843
873
|
exports.default = getDataTransferFiles;
|
|
844
874
|
function getDataTransferFiles(event) {
|
|
845
|
-
var isMultipleAllowed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
846
|
-
|
|
847
875
|
var dataTransferItemsList = [];
|
|
848
876
|
if (event.dataTransfer) {
|
|
849
877
|
var dt = event.dataTransfer;
|
|
@@ -857,11 +885,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
857
885
|
} else if (event.target && event.target.files) {
|
|
858
886
|
dataTransferItemsList = event.target.files;
|
|
859
887
|
}
|
|
860
|
-
|
|
861
|
-
if (dataTransferItemsList.length > 0) {
|
|
862
|
-
dataTransferItemsList = isMultipleAllowed ? dataTransferItemsList : [dataTransferItemsList[0]];
|
|
863
|
-
}
|
|
864
|
-
|
|
865
888
|
// Convert from DataTransferItemsList to the native Array
|
|
866
889
|
return Array.prototype.slice.call(dataTransferItemsList);
|
|
867
890
|
}
|