react-dropzone 7.0.1 → 8.0.3
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 +71 -20
- package/dist/es/index.js +273 -370
- package/dist/es/utils/index.js +25 -1
- package/dist/index.js +2 -2
- package/examples/Accept/Readme.md +33 -30
- package/examples/Basic/Readme.md +59 -31
- package/examples/FileDialog/Readme.md +42 -25
- package/examples/Folders/Readme.md +21 -17
- package/examples/Fullscreen/Readme.md +38 -51
- package/examples/Nesting/Readme.md +16 -9
- package/examples/PluginArchitecture/Readme.md +19 -13
- package/examples/Previews/Readme.md +14 -14
- package/examples/Styling/Readme.md +81 -17
- package/package.json +2 -1
- package/src/__snapshots__/index.spec.js.snap +3 -3
- package/src/index.js +202 -277
- package/src/index.spec.js +948 -331
- package/src/utils/index.js +16 -1
- package/src/utils/index.spec.js +43 -4
- package/styleguide.config.js +4 -0
- package/typings/react-dropzone.d.ts +49 -35
- package/typings/tests/accept.tsx +25 -25
- package/typings/tests/all.tsx +6 -19
- package/typings/tests/basic.tsx +20 -53
- package/typings/tests/events.tsx +9 -4
- package/typings/tests/file-dialog.tsx +12 -23
- package/typings/tests/plugin.tsx +15 -5
- package/typings/tests/fullscreen.tsx +0 -88
- package/typings/tests/ref-object.tsx +0 -27
- package/typings/tests/styling.tsx +0 -18
package/dist/es/index.js
CHANGED
|
@@ -2,6 +2,8 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
|
|
|
2
2
|
|
|
3
3
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
4
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
|
+
|
|
5
7
|
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; }
|
|
6
8
|
|
|
7
9
|
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); } }
|
|
@@ -16,203 +18,104 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
16
18
|
|
|
17
19
|
import React from 'react';
|
|
18
20
|
import PropTypes from 'prop-types';
|
|
19
|
-
import { isDragDataWithFiles, supportMultiple, fileAccepted, allFilesAccepted, fileMatchSize, onDocumentDragOver, getDataTransferItems as defaultGetDataTransferItem, isIeOrEdge } from './utils';
|
|
20
|
-
import styles from './utils/styles';
|
|
21
|
+
import { isDragDataWithFiles, supportMultiple, fileAccepted, allFilesAccepted, fileMatchSize, onDocumentDragOver, getDataTransferItems as defaultGetDataTransferItem, isIeOrEdge, composeEventHandlers } from './utils';
|
|
21
22
|
|
|
22
23
|
var Dropzone = function (_React$Component) {
|
|
23
24
|
_inherits(Dropzone, _React$Component);
|
|
24
25
|
|
|
25
|
-
function Dropzone(
|
|
26
|
+
function Dropzone() {
|
|
27
|
+
var _ref;
|
|
28
|
+
|
|
29
|
+
var _temp, _this, _ret;
|
|
30
|
+
|
|
26
31
|
_classCallCheck(this, Dropzone);
|
|
27
32
|
|
|
28
|
-
var
|
|
33
|
+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
34
|
+
args[_key] = arguments[_key];
|
|
35
|
+
}
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
if (typeof children === 'function') {
|
|
32
|
-
return children(_extends({}, _this.state, {
|
|
33
|
-
isDragActive: isDragActive,
|
|
34
|
-
isDragAccept: isDragAccept,
|
|
35
|
-
isDragReject: isDragReject,
|
|
36
|
-
open: _this.open
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
return children;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
_this.composeHandlers = _this.composeHandlers.bind(_this);
|
|
43
|
-
_this.onClick = _this.onClick.bind(_this);
|
|
44
|
-
_this.onDocumentDrop = _this.onDocumentDrop.bind(_this);
|
|
45
|
-
_this.onDragEnter = _this.onDragEnter.bind(_this);
|
|
46
|
-
_this.onDragLeave = _this.onDragLeave.bind(_this);
|
|
47
|
-
_this.onDragOver = _this.onDragOver.bind(_this);
|
|
48
|
-
_this.onDragStart = _this.onDragStart.bind(_this);
|
|
49
|
-
_this.onDrop = _this.onDrop.bind(_this);
|
|
50
|
-
_this.onFileDialogCancel = _this.onFileDialogCancel.bind(_this);
|
|
51
|
-
_this.onInputElementClick = _this.onInputElementClick.bind(_this);
|
|
52
|
-
_this.open = _this.open.bind(_this);
|
|
53
|
-
|
|
54
|
-
_this.setRef = _this.setRef.bind(_this);
|
|
55
|
-
_this.setRefs = _this.setRefs.bind(_this);
|
|
56
|
-
|
|
57
|
-
_this.isFileDialogActive = false;
|
|
58
|
-
|
|
59
|
-
_this.state = {
|
|
37
|
+
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Dropzone.__proto__ || Object.getPrototypeOf(Dropzone)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
|
|
60
38
|
draggedFiles: [],
|
|
61
39
|
acceptedFiles: [],
|
|
62
40
|
rejectedFiles: []
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
_createClass(Dropzone, [{
|
|
68
|
-
key: 'componentDidMount',
|
|
69
|
-
value: function componentDidMount() {
|
|
70
|
-
var preventDropOnDocument = this.props.preventDropOnDocument;
|
|
71
|
-
|
|
72
|
-
this.dragTargets = [];
|
|
73
|
-
|
|
74
|
-
if (preventDropOnDocument) {
|
|
75
|
-
document.addEventListener('dragover', onDocumentDragOver, false);
|
|
76
|
-
document.addEventListener('drop', this.onDocumentDrop, false);
|
|
77
|
-
}
|
|
78
|
-
if (this.fileInputEl != null) {
|
|
79
|
-
this.fileInputEl.addEventListener('click', this.onInputElementClick, false);
|
|
80
|
-
}
|
|
81
|
-
window.addEventListener('focus', this.onFileDialogCancel, false);
|
|
82
|
-
}
|
|
83
|
-
}, {
|
|
84
|
-
key: 'componentWillUnmount',
|
|
85
|
-
value: function componentWillUnmount() {
|
|
86
|
-
var preventDropOnDocument = this.props.preventDropOnDocument;
|
|
87
|
-
|
|
88
|
-
if (preventDropOnDocument) {
|
|
89
|
-
document.removeEventListener('dragover', onDocumentDragOver);
|
|
90
|
-
document.removeEventListener('drop', this.onDocumentDrop);
|
|
91
|
-
}
|
|
92
|
-
if (this.fileInputEl != null) {
|
|
93
|
-
this.fileInputEl.removeEventListener('click', this.onInputElementClick, false);
|
|
94
|
-
}
|
|
95
|
-
window.removeEventListener('focus', this.onFileDialogCancel, false);
|
|
96
|
-
}
|
|
97
|
-
}, {
|
|
98
|
-
key: 'composeHandlers',
|
|
99
|
-
value: function composeHandlers(handler) {
|
|
100
|
-
if (this.props.disabled) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return handler;
|
|
105
|
-
}
|
|
106
|
-
}, {
|
|
107
|
-
key: 'onDocumentDrop',
|
|
108
|
-
value: function onDocumentDrop(evt) {
|
|
109
|
-
if (this.node && this.node.contains(evt.target)) {
|
|
41
|
+
}, _this.isFileDialogActive = false, _this.onDocumentDrop = function (evt) {
|
|
42
|
+
if (_this.node && _this.node.contains(evt.target)) {
|
|
110
43
|
// if we intercepted an event for our instance, let it propagate down to the instance's onDrop handler
|
|
111
44
|
return;
|
|
112
45
|
}
|
|
113
46
|
evt.preventDefault();
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
}, {
|
|
117
|
-
key: 'onDragStart',
|
|
118
|
-
value: function onDragStart(evt) {
|
|
47
|
+
_this.dragTargets = [];
|
|
48
|
+
}, _this.onDragStart = function (evt) {
|
|
119
49
|
evt.persist();
|
|
120
|
-
if (
|
|
121
|
-
|
|
50
|
+
if (_this.props.onDragStart && isDragDataWithFiles(evt)) {
|
|
51
|
+
_this.props.onDragStart.call(_this, evt);
|
|
122
52
|
}
|
|
123
|
-
}
|
|
124
|
-
}, {
|
|
125
|
-
key: 'onDragEnter',
|
|
126
|
-
value: function onDragEnter(evt) {
|
|
127
|
-
var _this2 = this;
|
|
128
|
-
|
|
53
|
+
}, _this.onDragEnter = function (evt) {
|
|
129
54
|
evt.preventDefault();
|
|
130
55
|
|
|
131
56
|
// Count the dropzone and any children that are entered.
|
|
132
|
-
if (
|
|
133
|
-
|
|
57
|
+
if (_this.dragTargets.indexOf(evt.target) === -1) {
|
|
58
|
+
_this.dragTargets.push(evt.target);
|
|
134
59
|
}
|
|
135
60
|
|
|
136
61
|
evt.persist();
|
|
137
62
|
|
|
138
63
|
if (isDragDataWithFiles(evt)) {
|
|
139
|
-
Promise.resolve(
|
|
64
|
+
Promise.resolve(_this.props.getDataTransferItems(evt)).then(function (draggedFiles) {
|
|
140
65
|
if (evt.isPropagationStopped()) {
|
|
141
66
|
return;
|
|
142
67
|
}
|
|
143
68
|
|
|
144
|
-
|
|
69
|
+
_this.setState({
|
|
145
70
|
draggedFiles: draggedFiles,
|
|
146
71
|
// Do not rely on files for the drag state. It doesn't work in Safari.
|
|
147
72
|
isDragActive: true
|
|
148
73
|
});
|
|
149
74
|
});
|
|
150
75
|
|
|
151
|
-
if (
|
|
152
|
-
|
|
76
|
+
if (_this.props.onDragEnter) {
|
|
77
|
+
_this.props.onDragEnter.call(_this, evt);
|
|
153
78
|
}
|
|
154
79
|
}
|
|
155
|
-
}
|
|
156
|
-
}, {
|
|
157
|
-
key: 'onDragOver',
|
|
158
|
-
value: function onDragOver(evt) {
|
|
80
|
+
}, _this.onDragOver = function (evt) {
|
|
159
81
|
// eslint-disable-line class-methods-use-this
|
|
160
82
|
evt.preventDefault();
|
|
161
83
|
evt.persist();
|
|
162
84
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
// the dropzone, causing the browser the crash when the file dialog is closed.
|
|
166
|
-
// A drop effect of 'none' prevents the file from being dropped
|
|
167
|
-
evt.dataTransfer.dropEffect = this.isFileDialogActive ? 'none' : 'copy'; // eslint-disable-line no-param-reassign
|
|
168
|
-
} catch (err) {
|
|
169
|
-
// continue regardless of error
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (this.props.onDragOver && isDragDataWithFiles(evt)) {
|
|
173
|
-
this.props.onDragOver.call(this, evt);
|
|
85
|
+
if (_this.props.onDragOver && isDragDataWithFiles(evt)) {
|
|
86
|
+
_this.props.onDragOver.call(_this, evt);
|
|
174
87
|
}
|
|
175
88
|
|
|
176
89
|
return false;
|
|
177
|
-
}
|
|
178
|
-
}, {
|
|
179
|
-
key: 'onDragLeave',
|
|
180
|
-
value: function onDragLeave(evt) {
|
|
181
|
-
var _this3 = this;
|
|
182
|
-
|
|
90
|
+
}, _this.onDragLeave = function (evt) {
|
|
183
91
|
evt.preventDefault();
|
|
184
92
|
evt.persist();
|
|
185
93
|
|
|
186
94
|
// Only deactivate once the dropzone and all children have been left.
|
|
187
|
-
|
|
188
|
-
return el !== evt.target &&
|
|
95
|
+
_this.dragTargets = _this.dragTargets.filter(function (el) {
|
|
96
|
+
return el !== evt.target && _this.node.contains(el);
|
|
189
97
|
});
|
|
190
|
-
if (
|
|
98
|
+
if (_this.dragTargets.length > 0) {
|
|
191
99
|
return;
|
|
192
100
|
}
|
|
193
101
|
|
|
194
102
|
// Clear dragging files state
|
|
195
|
-
|
|
103
|
+
_this.setState({
|
|
196
104
|
isDragActive: false,
|
|
197
105
|
draggedFiles: []
|
|
198
106
|
});
|
|
199
107
|
|
|
200
|
-
if (
|
|
201
|
-
|
|
108
|
+
if (_this.props.onDragLeave && isDragDataWithFiles(evt)) {
|
|
109
|
+
_this.props.onDragLeave.call(_this, evt);
|
|
202
110
|
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
onDropAccepted = _props.onDropAccepted,
|
|
212
|
-
onDropRejected = _props.onDropRejected,
|
|
213
|
-
multiple = _props.multiple,
|
|
214
|
-
accept = _props.accept,
|
|
215
|
-
getDataTransferItems = _props.getDataTransferItems;
|
|
111
|
+
}, _this.onDrop = function (evt) {
|
|
112
|
+
var _this$props = _this.props,
|
|
113
|
+
onDrop = _this$props.onDrop,
|
|
114
|
+
onDropAccepted = _this$props.onDropAccepted,
|
|
115
|
+
onDropRejected = _this$props.onDropRejected,
|
|
116
|
+
multiple = _this$props.multiple,
|
|
117
|
+
accept = _this$props.accept,
|
|
118
|
+
getDataTransferItems = _this$props.getDataTransferItems;
|
|
216
119
|
|
|
217
120
|
// Stop default browser behavior
|
|
218
121
|
|
|
@@ -222,14 +125,14 @@ var Dropzone = function (_React$Component) {
|
|
|
222
125
|
evt.persist();
|
|
223
126
|
|
|
224
127
|
// Reset the counter along with the drag on a drop.
|
|
225
|
-
|
|
226
|
-
|
|
128
|
+
_this.dragTargets = [];
|
|
129
|
+
_this.isFileDialogActive = false;
|
|
227
130
|
|
|
228
131
|
// Clear files value
|
|
229
|
-
|
|
132
|
+
_this.draggedFiles = null;
|
|
230
133
|
|
|
231
134
|
// Reset drag state
|
|
232
|
-
|
|
135
|
+
_this.setState({
|
|
233
136
|
isDragActive: false,
|
|
234
137
|
draggedFiles: []
|
|
235
138
|
});
|
|
@@ -244,7 +147,7 @@ var Dropzone = function (_React$Component) {
|
|
|
244
147
|
}
|
|
245
148
|
|
|
246
149
|
fileList.forEach(function (file) {
|
|
247
|
-
if (fileAccepted(file, accept) && fileMatchSize(file,
|
|
150
|
+
if (fileAccepted(file, accept) && fileMatchSize(file, _this.props.maxSize, _this.props.minSize)) {
|
|
248
151
|
acceptedFiles.push(file);
|
|
249
152
|
} else {
|
|
250
153
|
rejectedFiles.push(file);
|
|
@@ -260,33 +163,30 @@ var Dropzone = function (_React$Component) {
|
|
|
260
163
|
// Update `acceptedFiles` and `rejectedFiles` state
|
|
261
164
|
// This will make children render functions receive the appropriate
|
|
262
165
|
// values
|
|
263
|
-
|
|
166
|
+
_this.setState({ acceptedFiles: acceptedFiles, rejectedFiles: rejectedFiles }, function () {
|
|
264
167
|
if (onDrop) {
|
|
265
|
-
onDrop.call(
|
|
168
|
+
onDrop.call(_this, acceptedFiles, rejectedFiles, evt);
|
|
266
169
|
}
|
|
267
170
|
|
|
268
171
|
if (rejectedFiles.length > 0 && onDropRejected) {
|
|
269
|
-
onDropRejected.call(
|
|
172
|
+
onDropRejected.call(_this, rejectedFiles, evt);
|
|
270
173
|
}
|
|
271
174
|
|
|
272
175
|
if (acceptedFiles.length > 0 && onDropAccepted) {
|
|
273
|
-
onDropAccepted.call(
|
|
176
|
+
onDropAccepted.call(_this, acceptedFiles, evt);
|
|
274
177
|
}
|
|
275
178
|
});
|
|
276
179
|
});
|
|
277
180
|
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
var _props2 = this.props,
|
|
283
|
-
onClick = _props2.onClick,
|
|
284
|
-
disableClick = _props2.disableClick;
|
|
181
|
+
}, _this.onClick = function (evt) {
|
|
182
|
+
var _this$props2 = _this.props,
|
|
183
|
+
onClick = _this$props2.onClick,
|
|
184
|
+
disableClick = _this$props2.disableClick;
|
|
285
185
|
|
|
286
186
|
// if onClick prop is given, run it first
|
|
287
187
|
|
|
288
188
|
if (onClick) {
|
|
289
|
-
onClick.call(
|
|
189
|
+
onClick.call(_this, evt);
|
|
290
190
|
}
|
|
291
191
|
|
|
292
192
|
// if disableClick is not set and the event hasn't been default prefented within
|
|
@@ -298,38 +198,27 @@ var Dropzone = function (_React$Component) {
|
|
|
298
198
|
// this is so react can handle state changes in the onClick prop above above
|
|
299
199
|
// see: https://github.com/react-dropzone/react-dropzone/issues/450
|
|
300
200
|
if (isIeOrEdge()) {
|
|
301
|
-
setTimeout(
|
|
201
|
+
setTimeout(_this.open, 0);
|
|
302
202
|
} else {
|
|
303
|
-
|
|
203
|
+
_this.open();
|
|
304
204
|
}
|
|
305
205
|
}
|
|
306
|
-
}
|
|
307
|
-
}, {
|
|
308
|
-
key: 'onInputElementClick',
|
|
309
|
-
value: function onInputElementClick(evt) {
|
|
206
|
+
}, _this.onInputElementClick = function (evt) {
|
|
310
207
|
evt.stopPropagation();
|
|
311
|
-
|
|
312
|
-
this.props.inputProps.onClick(evt);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}, {
|
|
316
|
-
key: 'onFileDialogCancel',
|
|
317
|
-
value: function onFileDialogCancel() {
|
|
318
|
-
var _this5 = this;
|
|
319
|
-
|
|
208
|
+
}, _this.onFileDialogCancel = function () {
|
|
320
209
|
// timeout will not recognize context of this method
|
|
321
|
-
var onFileDialogCancel =
|
|
210
|
+
var onFileDialogCancel = _this.props.onFileDialogCancel;
|
|
322
211
|
// execute the timeout only if the FileDialog is opened in the browser
|
|
323
212
|
|
|
324
|
-
if (
|
|
213
|
+
if (_this.isFileDialogActive) {
|
|
325
214
|
setTimeout(function () {
|
|
326
|
-
if (
|
|
215
|
+
if (_this.input != null) {
|
|
327
216
|
// Returns an object as FileList
|
|
328
|
-
var files =
|
|
217
|
+
var files = _this.input.files;
|
|
329
218
|
|
|
330
219
|
|
|
331
220
|
if (!files.length) {
|
|
332
|
-
|
|
221
|
+
_this.isFileDialogActive = false;
|
|
333
222
|
|
|
334
223
|
if (typeof onFileDialogCancel === 'function') {
|
|
335
224
|
onFileDialogCancel();
|
|
@@ -338,162 +227,179 @@ var Dropzone = function (_React$Component) {
|
|
|
338
227
|
}
|
|
339
228
|
}, 300);
|
|
340
229
|
}
|
|
230
|
+
}, _this.onFocus = function (evt) {
|
|
231
|
+
var onFocus = _this.props.onFocus;
|
|
232
|
+
|
|
233
|
+
if (onFocus) {
|
|
234
|
+
onFocus.call(_this, evt);
|
|
235
|
+
}
|
|
236
|
+
if (!evt.isDefaultPrevented()) {
|
|
237
|
+
_this.setState({ isFocused: true });
|
|
238
|
+
}
|
|
239
|
+
}, _this.onBlur = function (evt) {
|
|
240
|
+
var onBlur = _this.props.onBlur;
|
|
241
|
+
|
|
242
|
+
if (onBlur) {
|
|
243
|
+
onBlur.call(_this, evt);
|
|
244
|
+
}
|
|
245
|
+
if (!evt.isDefaultPrevented()) {
|
|
246
|
+
_this.setState({ isFocused: false });
|
|
247
|
+
}
|
|
248
|
+
}, _this.onKeyDown = function (evt) {
|
|
249
|
+
var onKeyDown = _this.props.onKeyDown;
|
|
250
|
+
|
|
251
|
+
if (!_this.node.isEqualNode(evt.target)) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (onKeyDown) {
|
|
256
|
+
onKeyDown.call(_this, evt);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (!evt.isDefaultPrevented() && (evt.keyCode === 32 || evt.keyCode === 13)) {
|
|
260
|
+
evt.preventDefault();
|
|
261
|
+
_this.open();
|
|
262
|
+
}
|
|
263
|
+
}, _this.composeHandler = function (handler) {
|
|
264
|
+
if (_this.props.disabled) {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
return handler;
|
|
268
|
+
}, _this.getRootProps = function () {
|
|
269
|
+
var _extends2;
|
|
270
|
+
|
|
271
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
272
|
+
|
|
273
|
+
var _ref2$refKey = _ref2.refKey,
|
|
274
|
+
refKey = _ref2$refKey === undefined ? 'ref' : _ref2$refKey,
|
|
275
|
+
onKeyDown = _ref2.onKeyDown,
|
|
276
|
+
onFocus = _ref2.onFocus,
|
|
277
|
+
onBlur = _ref2.onBlur,
|
|
278
|
+
onClick = _ref2.onClick,
|
|
279
|
+
onDragStart = _ref2.onDragStart,
|
|
280
|
+
onDragEnter = _ref2.onDragEnter,
|
|
281
|
+
onDragOver = _ref2.onDragOver,
|
|
282
|
+
onDragLeave = _ref2.onDragLeave,
|
|
283
|
+
onDrop = _ref2.onDrop,
|
|
284
|
+
rest = _objectWithoutProperties(_ref2, ['refKey', 'onKeyDown', 'onFocus', 'onBlur', 'onClick', 'onDragStart', 'onDragEnter', 'onDragOver', 'onDragLeave', 'onDrop']);
|
|
285
|
+
|
|
286
|
+
return _extends((_extends2 = {
|
|
287
|
+
onKeyDown: _this.composeHandler(onKeyDown ? composeEventHandlers(onKeyDown, _this.onKeyDown) : _this.onKeyDown),
|
|
288
|
+
onFocus: _this.composeHandler(onFocus ? composeEventHandlers(onFocus, _this.onFocus) : _this.onFocus),
|
|
289
|
+
onBlur: _this.composeHandler(onBlur ? composeEventHandlers(onBlur, _this.onBlur) : _this.onBlur),
|
|
290
|
+
onClick: _this.composeHandler(onClick ? composeEventHandlers(onClick, _this.onClick) : _this.onClick),
|
|
291
|
+
onDragStart: _this.composeHandler(onDragStart ? composeEventHandlers(onDragStart, _this.onDragStart) : _this.onDragStart),
|
|
292
|
+
onDragEnter: _this.composeHandler(onDragEnter ? composeEventHandlers(onDragEnter, _this.onDragEnter) : _this.onDragEnter),
|
|
293
|
+
onDragOver: _this.composeHandler(onDragOver ? composeEventHandlers(onDragOver, _this.onDragOver) : _this.onDragOver),
|
|
294
|
+
onDragLeave: _this.composeHandler(onDragLeave ? composeEventHandlers(onDragLeave, _this.onDragLeave) : _this.onDragLeave),
|
|
295
|
+
onDrop: _this.composeHandler(onDrop ? composeEventHandlers(onDrop, _this.onDrop) : _this.onDrop)
|
|
296
|
+
}, _defineProperty(_extends2, refKey, _this.setNodeRef), _defineProperty(_extends2, 'tabIndex', _this.props.disabled ? -1 : 0), _extends2), rest);
|
|
297
|
+
}, _this.getInputProps = function () {
|
|
298
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
299
|
+
|
|
300
|
+
var _ref3$refKey = _ref3.refKey,
|
|
301
|
+
refKey = _ref3$refKey === undefined ? 'ref' : _ref3$refKey,
|
|
302
|
+
onChange = _ref3.onChange,
|
|
303
|
+
onClick = _ref3.onClick,
|
|
304
|
+
rest = _objectWithoutProperties(_ref3, ['refKey', 'onChange', 'onClick']);
|
|
305
|
+
|
|
306
|
+
var _this$props3 = _this.props,
|
|
307
|
+
accept = _this$props3.accept,
|
|
308
|
+
multiple = _this$props3.multiple,
|
|
309
|
+
name = _this$props3.name;
|
|
310
|
+
|
|
311
|
+
var inputProps = _defineProperty({
|
|
312
|
+
accept: accept,
|
|
313
|
+
type: 'file',
|
|
314
|
+
style: { display: 'none' },
|
|
315
|
+
multiple: supportMultiple && multiple,
|
|
316
|
+
onChange: composeEventHandlers(onChange, _this.onDrop),
|
|
317
|
+
onClick: composeEventHandlers(onClick, _this.onInputElementClick),
|
|
318
|
+
autoComplete: 'off',
|
|
319
|
+
tabIndex: -1
|
|
320
|
+
}, refKey, _this.setInputRef);
|
|
321
|
+
if (name && name.length) {
|
|
322
|
+
inputProps.name = name;
|
|
323
|
+
}
|
|
324
|
+
return _extends({}, inputProps, rest);
|
|
325
|
+
}, _this.setNodeRef = function (node) {
|
|
326
|
+
_this.node = node;
|
|
327
|
+
}, _this.setInputRef = function (input) {
|
|
328
|
+
_this.input = input;
|
|
329
|
+
}, _this.open = function () {
|
|
330
|
+
_this.isFileDialogActive = true;
|
|
331
|
+
if (_this.input) {
|
|
332
|
+
_this.input.value = null;
|
|
333
|
+
_this.input.click();
|
|
334
|
+
}
|
|
335
|
+
}, _temp), _possibleConstructorReturn(_this, _ret);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
_createClass(Dropzone, [{
|
|
339
|
+
key: 'componentDidMount',
|
|
340
|
+
value: function componentDidMount() {
|
|
341
|
+
var preventDropOnDocument = this.props.preventDropOnDocument;
|
|
342
|
+
|
|
343
|
+
this.dragTargets = [];
|
|
344
|
+
|
|
345
|
+
if (preventDropOnDocument) {
|
|
346
|
+
document.addEventListener('dragover', onDocumentDragOver, false);
|
|
347
|
+
document.addEventListener('drop', this.onDocumentDrop, false);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
window.addEventListener('focus', this.onFileDialogCancel, false);
|
|
341
351
|
}
|
|
342
352
|
}, {
|
|
343
|
-
key: '
|
|
344
|
-
value: function
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
353
|
+
key: 'componentWillUnmount',
|
|
354
|
+
value: function componentWillUnmount() {
|
|
355
|
+
var preventDropOnDocument = this.props.preventDropOnDocument;
|
|
356
|
+
|
|
357
|
+
if (preventDropOnDocument) {
|
|
358
|
+
document.removeEventListener('dragover', onDocumentDragOver);
|
|
359
|
+
document.removeEventListener('drop', this.onDocumentDrop);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
window.removeEventListener('focus', this.onFileDialogCancel, false);
|
|
351
363
|
}
|
|
364
|
+
|
|
352
365
|
/**
|
|
353
366
|
* Open system file upload dialog.
|
|
354
367
|
*
|
|
355
368
|
* @public
|
|
356
369
|
*/
|
|
357
370
|
|
|
358
|
-
}, {
|
|
359
|
-
key: 'open',
|
|
360
|
-
value: function open() {
|
|
361
|
-
this.isFileDialogActive = true;
|
|
362
|
-
this.fileInputEl.value = null;
|
|
363
|
-
this.fileInputEl.click();
|
|
364
|
-
}
|
|
365
371
|
}, {
|
|
366
372
|
key: 'render',
|
|
367
373
|
value: function render() {
|
|
368
|
-
var
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
children = _props3.children,
|
|
373
|
-
disabled = _props3.disabled,
|
|
374
|
-
disabledClassName = _props3.disabledClassName,
|
|
375
|
-
inputProps = _props3.inputProps,
|
|
376
|
-
multiple = _props3.multiple,
|
|
377
|
-
name = _props3.name,
|
|
378
|
-
rejectClassName = _props3.rejectClassName,
|
|
379
|
-
rest = _objectWithoutProperties(_props3, ['accept', 'acceptClassName', 'activeClassName', 'children', 'disabled', 'disabledClassName', 'inputProps', 'multiple', 'name', 'rejectClassName']);
|
|
380
|
-
|
|
381
|
-
var acceptStyle = rest.acceptStyle,
|
|
382
|
-
activeStyle = rest.activeStyle,
|
|
383
|
-
_rest$className = rest.className,
|
|
384
|
-
className = _rest$className === undefined ? '' : _rest$className,
|
|
385
|
-
disabledStyle = rest.disabledStyle,
|
|
386
|
-
rejectStyle = rest.rejectStyle,
|
|
387
|
-
style = rest.style,
|
|
388
|
-
props = _objectWithoutProperties(rest, ['acceptStyle', 'activeStyle', 'className', 'disabledStyle', 'rejectStyle', 'style']);
|
|
389
|
-
|
|
374
|
+
var _props = this.props,
|
|
375
|
+
children = _props.children,
|
|
376
|
+
multiple = _props.multiple,
|
|
377
|
+
disabled = _props.disabled;
|
|
390
378
|
var _state = this.state,
|
|
391
379
|
isDragActive = _state.isDragActive,
|
|
392
|
-
|
|
380
|
+
isFocused = _state.isFocused,
|
|
381
|
+
draggedFiles = _state.draggedFiles,
|
|
382
|
+
acceptedFiles = _state.acceptedFiles,
|
|
383
|
+
rejectedFiles = _state.rejectedFiles;
|
|
384
|
+
|
|
393
385
|
|
|
394
386
|
var filesCount = draggedFiles.length;
|
|
395
387
|
var isMultipleAllowed = multiple || filesCount <= 1;
|
|
396
388
|
var isDragAccept = filesCount > 0 && allFilesAccepted(draggedFiles, this.props.accept);
|
|
397
389
|
var isDragReject = filesCount > 0 && (!isDragAccept || !isMultipleAllowed);
|
|
398
|
-
var noStyles = !className && !style && !activeStyle && !acceptStyle && !rejectStyle && !disabledStyle;
|
|
399
|
-
|
|
400
|
-
if (isDragActive && activeClassName) {
|
|
401
|
-
className += ' ' + activeClassName;
|
|
402
|
-
}
|
|
403
|
-
if (isDragAccept && acceptClassName) {
|
|
404
|
-
className += ' ' + acceptClassName;
|
|
405
|
-
}
|
|
406
|
-
if (isDragReject && rejectClassName) {
|
|
407
|
-
className += ' ' + rejectClassName;
|
|
408
|
-
}
|
|
409
|
-
if (disabled && disabledClassName) {
|
|
410
|
-
className += ' ' + disabledClassName;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (noStyles) {
|
|
414
|
-
style = styles.default;
|
|
415
|
-
activeStyle = styles.active;
|
|
416
|
-
acceptStyle = styles.accepted;
|
|
417
|
-
rejectStyle = styles.rejected;
|
|
418
|
-
disabledStyle = styles.disabled;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
var appliedStyle = _extends({ position: 'relative' }, style);
|
|
422
|
-
if (activeStyle && isDragActive) {
|
|
423
|
-
appliedStyle = _extends({}, appliedStyle, activeStyle);
|
|
424
|
-
}
|
|
425
|
-
if (acceptStyle && isDragAccept) {
|
|
426
|
-
appliedStyle = _extends({}, appliedStyle, acceptStyle);
|
|
427
|
-
}
|
|
428
|
-
if (rejectStyle && isDragReject) {
|
|
429
|
-
appliedStyle = _extends({}, appliedStyle, rejectStyle);
|
|
430
|
-
}
|
|
431
|
-
if (disabledStyle && disabled) {
|
|
432
|
-
appliedStyle = _extends({}, appliedStyle, disabledStyle);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
var inputAttributes = {
|
|
436
|
-
accept: accept,
|
|
437
|
-
disabled: disabled,
|
|
438
|
-
type: 'file',
|
|
439
|
-
style: _extends({
|
|
440
|
-
position: 'absolute',
|
|
441
|
-
top: 0,
|
|
442
|
-
right: 0,
|
|
443
|
-
bottom: 0,
|
|
444
|
-
left: 0,
|
|
445
|
-
opacity: 0.00001,
|
|
446
|
-
pointerEvents: 'none'
|
|
447
|
-
}, inputProps.style),
|
|
448
|
-
multiple: supportMultiple && multiple,
|
|
449
|
-
ref: this.setRefs,
|
|
450
|
-
onChange: this.onDrop,
|
|
451
|
-
autoComplete: 'off'
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
if (name && name.length) {
|
|
455
|
-
inputAttributes.name = name;
|
|
456
|
-
}
|
|
457
390
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
divProps = _objectWithoutProperties(props, ['acceptedFiles', 'preventDropOnDocument', 'disableClick', 'onDropAccepted', 'onDropRejected', 'onFileDialogCancel', 'maxSize', 'minSize', 'getDataTransferItems']);
|
|
471
|
-
/* eslint-enable no-unused-vars */
|
|
472
|
-
|
|
473
|
-
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
474
|
-
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
return React.createElement(
|
|
478
|
-
'div',
|
|
479
|
-
_extends({
|
|
480
|
-
className: className,
|
|
481
|
-
style: appliedStyle
|
|
482
|
-
}, divProps /* expand user provided props first so event handlers are never overridden */
|
|
483
|
-
, {
|
|
484
|
-
onClick: this.composeHandlers(this.onClick),
|
|
485
|
-
onDragStart: this.composeHandlers(this.onDragStart),
|
|
486
|
-
onDragEnter: this.composeHandlers(this.onDragEnter),
|
|
487
|
-
onDragOver: this.composeHandlers(this.onDragOver),
|
|
488
|
-
onDragLeave: this.composeHandlers(this.onDragLeave),
|
|
489
|
-
onDrop: this.composeHandlers(this.onDrop),
|
|
490
|
-
ref: this.setRef,
|
|
491
|
-
'aria-disabled': disabled
|
|
492
|
-
}),
|
|
493
|
-
this.renderChildren(children, isDragActive, isDragAccept, isDragReject),
|
|
494
|
-
React.createElement('input', _extends({}, inputProps /* expand user provided inputProps first so inputAttributes override them */
|
|
495
|
-
, inputAttributes))
|
|
496
|
-
);
|
|
391
|
+
return children({
|
|
392
|
+
isDragActive: isDragActive,
|
|
393
|
+
isDragAccept: isDragAccept,
|
|
394
|
+
isDragReject: isDragReject,
|
|
395
|
+
draggedFiles: draggedFiles,
|
|
396
|
+
acceptedFiles: acceptedFiles,
|
|
397
|
+
rejectedFiles: rejectedFiles,
|
|
398
|
+
isFocused: isFocused && !disabled,
|
|
399
|
+
getRootProps: this.getRootProps,
|
|
400
|
+
getInputProps: this.getInputProps,
|
|
401
|
+
open: this.open
|
|
402
|
+
});
|
|
497
403
|
}
|
|
498
404
|
}]);
|
|
499
405
|
|
|
@@ -513,9 +419,21 @@ Dropzone.propTypes = {
|
|
|
513
419
|
accept: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
514
420
|
|
|
515
421
|
/**
|
|
516
|
-
*
|
|
422
|
+
* Render function that renders the actual component
|
|
423
|
+
*
|
|
424
|
+
* @param {Object} props
|
|
425
|
+
* @param {Function} props.getRootProps Returns the props you should apply to the root drop container you render
|
|
426
|
+
* @param {Function} props.getInputProps Returns the props you should apply to hidden file input you render
|
|
427
|
+
* @param {Function} props.open Open the native file selection dialog
|
|
428
|
+
* @param {Boolean} props.isFocused Dropzone area is in focus
|
|
429
|
+
* @param {Boolean} props.isDragActive Active drag is in progress
|
|
430
|
+
* @param {Boolean} props.isDragAccept Dragged files are accepted
|
|
431
|
+
* @param {Boolean} props.isDragReject Some dragged files are rejected
|
|
432
|
+
* @param {Array} props.draggedFiles Files in active drag
|
|
433
|
+
* @param {Array} props.acceptedFiles Accepted files
|
|
434
|
+
* @param {Array} props.rejectedFiles Rejected files
|
|
517
435
|
*/
|
|
518
|
-
children: PropTypes.
|
|
436
|
+
children: PropTypes.func,
|
|
519
437
|
|
|
520
438
|
/**
|
|
521
439
|
* Disallow clicking on the dropzone container to open file dialog
|
|
@@ -532,11 +450,6 @@ Dropzone.propTypes = {
|
|
|
532
450
|
*/
|
|
533
451
|
preventDropOnDocument: PropTypes.bool,
|
|
534
452
|
|
|
535
|
-
/**
|
|
536
|
-
* Pass additional attributes to the `<input type="file"/>` tag
|
|
537
|
-
*/
|
|
538
|
-
inputProps: PropTypes.object,
|
|
539
|
-
|
|
540
453
|
/**
|
|
541
454
|
* Allow dropping multiple files
|
|
542
455
|
*/
|
|
@@ -558,70 +471,61 @@ Dropzone.propTypes = {
|
|
|
558
471
|
minSize: PropTypes.number,
|
|
559
472
|
|
|
560
473
|
/**
|
|
561
|
-
*
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* className to apply when drag is active
|
|
567
|
-
*/
|
|
568
|
-
activeClassName: PropTypes.string,
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* className to apply when drop will be accepted
|
|
572
|
-
*/
|
|
573
|
-
acceptClassName: PropTypes.string,
|
|
574
|
-
|
|
575
|
-
/**
|
|
576
|
-
* className to apply when drop will be rejected
|
|
577
|
-
*/
|
|
578
|
-
rejectClassName: PropTypes.string,
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* className to apply when dropzone is disabled
|
|
582
|
-
*/
|
|
583
|
-
disabledClassName: PropTypes.string,
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
* CSS styles to apply
|
|
587
|
-
*/
|
|
588
|
-
style: PropTypes.object,
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* CSS styles to apply when drag is active
|
|
592
|
-
*/
|
|
593
|
-
activeStyle: PropTypes.object,
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* CSS styles to apply when drop will be accepted
|
|
474
|
+
* getDataTransferItems handler
|
|
475
|
+
* @param {Event} event
|
|
476
|
+
* @returns {Array} array of File objects
|
|
597
477
|
*/
|
|
598
|
-
|
|
478
|
+
getDataTransferItems: PropTypes.func,
|
|
599
479
|
|
|
600
480
|
/**
|
|
601
|
-
*
|
|
481
|
+
* onClick callback
|
|
482
|
+
* @param {Event} event
|
|
602
483
|
*/
|
|
603
|
-
|
|
484
|
+
onClick: PropTypes.func,
|
|
604
485
|
|
|
605
486
|
/**
|
|
606
|
-
*
|
|
487
|
+
* onFocus callback
|
|
607
488
|
*/
|
|
608
|
-
|
|
489
|
+
onFocus: PropTypes.func,
|
|
609
490
|
|
|
610
491
|
/**
|
|
611
|
-
*
|
|
612
|
-
* @param {Event} event
|
|
613
|
-
* @returns {Array} array of File objects
|
|
492
|
+
* onBlur callback
|
|
614
493
|
*/
|
|
615
|
-
|
|
494
|
+
onBlur: PropTypes.func,
|
|
616
495
|
|
|
617
496
|
/**
|
|
618
|
-
*
|
|
619
|
-
* @param {Event} event
|
|
497
|
+
* onKeyDown callback
|
|
620
498
|
*/
|
|
621
|
-
|
|
499
|
+
onKeyDown: PropTypes.func,
|
|
622
500
|
|
|
623
501
|
/**
|
|
624
|
-
* onDrop
|
|
502
|
+
* The `onDrop` method that accepts two arguments.
|
|
503
|
+
* The first argument represents the accepted files and the second argument the rejected files.
|
|
504
|
+
*
|
|
505
|
+
* ```javascript
|
|
506
|
+
* function onDrop(acceptedFiles, rejectedFiles) {
|
|
507
|
+
* // do stuff with files...
|
|
508
|
+
* }
|
|
509
|
+
* ```
|
|
510
|
+
*
|
|
511
|
+
* Files are accepted or rejected based on the `accept` prop.
|
|
512
|
+
* This must be a valid [MIME type](http://www.iana.org/assignments/media-types/media-types.xhtml) according to [input element specification](https://www.w3.org/wiki/HTML/Elements/input/file) or a valid file extension.
|
|
513
|
+
*
|
|
514
|
+
* Note that the `onDrop` callback will always be called regardless if the dropped files were accepted or rejected.
|
|
515
|
+
* You can use the `onDropAccepted`/`onDropRejected` props if you'd like to react to a specific event instead of the `onDrop` prop.
|
|
516
|
+
*
|
|
517
|
+
* The `onDrop` callback will provide you with an array of [Files](https://developer.mozilla.org/en-US/docs/Web/API/File) which you can then process and send to a server.
|
|
518
|
+
* For example, with [SuperAgent](https://github.com/visionmedia/superagent) as a http/ajax library:
|
|
519
|
+
*
|
|
520
|
+
* ```javascript
|
|
521
|
+
* function onDrop(acceptedFiles) {
|
|
522
|
+
* const req = request.post('/upload')
|
|
523
|
+
* acceptedFiles.forEach(file => {
|
|
524
|
+
* req.attach(file.name, file)
|
|
525
|
+
* })
|
|
526
|
+
* req.end(callback)
|
|
527
|
+
* }
|
|
528
|
+
* ```
|
|
625
529
|
*/
|
|
626
530
|
onDrop: PropTypes.func,
|
|
627
531
|
|
|
@@ -665,7 +569,6 @@ Dropzone.defaultProps = {
|
|
|
665
569
|
preventDropOnDocument: true,
|
|
666
570
|
disabled: false,
|
|
667
571
|
disableClick: false,
|
|
668
|
-
inputProps: {},
|
|
669
572
|
multiple: true,
|
|
670
573
|
maxSize: Infinity,
|
|
671
574
|
minSize: 0,
|