react-dropzone 5.0.0 → 5.1.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 +3 -0
- package/.eslintrc +4 -19
- package/.travis.yml +1 -2
- package/README.md +31 -0
- package/dist/es/index.js +24 -3
- package/dist/index.js +2 -2
- package/examples/Styling/Readme.md +7 -6
- package/package.json +61 -39
- package/rollup.config.js +29 -0
- package/src/.eslintrc +8 -0
- package/src/__snapshots__/index.spec.js.snap +7 -7
- package/src/index.js +24 -3
- package/src/index.spec.js +429 -441
- package/styleguide.config.js +5 -2
- package/testSetup.js +7 -1
- package/tslint.json +101 -0
- package/typings/react-dropzone.d.ts +60 -0
- package/typings/tests/accept.tsx +76 -0
- package/typings/tests/all.tsx +58 -0
- package/typings/tests/basic.tsx +82 -0
- package/typings/tests/events.tsx +26 -0
- package/typings/tests/file-dialog.tsx +28 -0
- package/typings/tests/fullscreen.tsx +89 -0
- package/typings/tests/styling.tsx +19 -0
- package/wallaby.config.js +0 -17
- package/webpack.config.js +0 -43
package/.eslintignore
ADDED
package/.eslintrc
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": [
|
|
3
|
-
"okonet",
|
|
4
|
-
"prettier"
|
|
5
|
-
],
|
|
6
|
-
"plugins": [
|
|
7
|
-
"prettier"
|
|
8
|
-
],
|
|
2
|
+
"extends": ["okonet/node"],
|
|
9
3
|
"rules": {
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
2,
|
|
13
|
-
{
|
|
14
|
-
"forbid": [
|
|
15
|
-
"any",
|
|
16
|
-
"array"
|
|
17
|
-
]
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
"react/require-default-props": 0,
|
|
21
|
-
|
|
4
|
+
"strict": 0,
|
|
5
|
+
"node/no-unpublished-require": 0,
|
|
22
6
|
// Import
|
|
23
7
|
"import/no-extraneous-dependencies": [
|
|
24
8
|
2,
|
|
@@ -26,6 +10,7 @@
|
|
|
26
10
|
"devDependencies": [
|
|
27
11
|
"webpack*.js",
|
|
28
12
|
"**/*.spec.js",
|
|
13
|
+
"**/*.config.js",
|
|
29
14
|
"**/testSetup.js"
|
|
30
15
|
]
|
|
31
16
|
}
|
package/.travis.yml
CHANGED
|
@@ -6,8 +6,7 @@ node_js:
|
|
|
6
6
|
- '8'
|
|
7
7
|
after_success:
|
|
8
8
|
- 'bash <(curl -s https://codecov.io/bash)'
|
|
9
|
-
-
|
|
10
|
-
- travis-deploy-once "yarn global add semantic-release@13 && semantic-release"
|
|
9
|
+
- npx semantic-release
|
|
11
10
|
branches:
|
|
12
11
|
except:
|
|
13
12
|
- /^v\d+\.\d+\.\d+$/
|
package/README.md
CHANGED
|
@@ -92,6 +92,37 @@ See https://react-dropzone.netlify.com/#proptypes
|
|
|
92
92
|
|
|
93
93
|
*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.
|
|
94
94
|
|
|
95
|
+
### Testing
|
|
96
|
+
|
|
97
|
+
*Important*: `react-dropzone` makes its drag'n'drop callbacks asynchronous to enable promise based getDataTransfer functions. In order to properly test this, you may want to utilize a helper function to run all promises like this:
|
|
98
|
+
```js
|
|
99
|
+
const flushPromises = () => new Promise(resolve => setImmediate(resolve));
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Example with enzyme 3:
|
|
103
|
+
```js
|
|
104
|
+
|
|
105
|
+
it('tests drag state', async () => {
|
|
106
|
+
const flushPromises = () => new Promise(resolve => setImmediate(resolve));
|
|
107
|
+
const DummyChildComponent = () => null
|
|
108
|
+
const dropzone = mount(
|
|
109
|
+
<Dropzone>{props => <DummyChildComponent {...props} />}</Dropzone>
|
|
110
|
+
)
|
|
111
|
+
dropzone.simulate('dragEnter', {
|
|
112
|
+
dataTransfer: { files: files.concat(images) }
|
|
113
|
+
})
|
|
114
|
+
await flushPromises(dropzone)
|
|
115
|
+
dropzone.update()
|
|
116
|
+
|
|
117
|
+
const child = updatedDropzone.find(DummyChildComponent)
|
|
118
|
+
expect(child).toHaveProp('isDragActive', true)
|
|
119
|
+
expect(child).toHaveProp('isDragAccept', false)
|
|
120
|
+
expect(child).toHaveProp('isDragReject', true)
|
|
121
|
+
})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Remember to update your mounted component before asserting any props. A complete example for this can be found in `react-dropzone`s own test suite.
|
|
125
|
+
|
|
95
126
|
## Support
|
|
96
127
|
|
|
97
128
|
### Backers
|
package/dist/es/index.js
CHANGED
|
@@ -12,6 +12,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
12
12
|
|
|
13
13
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
14
14
|
|
|
15
|
+
/* global process */
|
|
15
16
|
/* eslint prefer-template: 0 */
|
|
16
17
|
|
|
17
18
|
import React from 'react';
|
|
@@ -73,7 +74,9 @@ var Dropzone = function (_React$Component) {
|
|
|
73
74
|
document.addEventListener('dragover', onDocumentDragOver, false);
|
|
74
75
|
document.addEventListener('drop', this.onDocumentDrop, false);
|
|
75
76
|
}
|
|
76
|
-
this.fileInputEl
|
|
77
|
+
if (this.fileInputEl != null) {
|
|
78
|
+
this.fileInputEl.addEventListener('click', this.onInputElementClick, false);
|
|
79
|
+
}
|
|
77
80
|
window.addEventListener('focus', this.onFileDialogCancel, false);
|
|
78
81
|
}
|
|
79
82
|
}, {
|
|
@@ -128,6 +131,8 @@ var Dropzone = function (_React$Component) {
|
|
|
128
131
|
this.dragTargets.push(evt.target);
|
|
129
132
|
}
|
|
130
133
|
|
|
134
|
+
evt.persist();
|
|
135
|
+
|
|
131
136
|
Promise.resolve(this.props.getDataTransferItems(evt)).then(function (draggedFiles) {
|
|
132
137
|
_this2.setState({
|
|
133
138
|
isDragActive: true, // Do not rely on files for the drag state. It doesn't work in Safari.
|
|
@@ -201,6 +206,9 @@ var Dropzone = function (_React$Component) {
|
|
|
201
206
|
|
|
202
207
|
evt.preventDefault();
|
|
203
208
|
|
|
209
|
+
// Persist event for later usage
|
|
210
|
+
evt.persist();
|
|
211
|
+
|
|
204
212
|
// Reset the counter along with the drag on a drop.
|
|
205
213
|
this.dragTargets = [];
|
|
206
214
|
this.isFileDialogActive = false;
|
|
@@ -253,6 +261,11 @@ var Dropzone = function (_React$Component) {
|
|
|
253
261
|
if (acceptedFiles.length > 0 && onDropAccepted) {
|
|
254
262
|
onDropAccepted.call(_this4, acceptedFiles, evt);
|
|
255
263
|
}
|
|
264
|
+
|
|
265
|
+
// Update `acceptedFiles` and `rejectedFiles` state
|
|
266
|
+
// This will make children render functions receive the appropriate
|
|
267
|
+
// values
|
|
268
|
+
_this4.setState({ acceptedFiles: acceptedFiles, rejectedFiles: rejectedFiles });
|
|
256
269
|
});
|
|
257
270
|
}
|
|
258
271
|
}, {
|
|
@@ -431,6 +444,7 @@ var Dropzone = function (_React$Component) {
|
|
|
431
444
|
}
|
|
432
445
|
|
|
433
446
|
// Destructure custom props away from props used for the div element
|
|
447
|
+
/* eslint-disable no-unused-vars */
|
|
434
448
|
|
|
435
449
|
var acceptedFiles = props.acceptedFiles,
|
|
436
450
|
preventDropOnDocument = props.preventDropOnDocument,
|
|
@@ -443,13 +457,19 @@ var Dropzone = function (_React$Component) {
|
|
|
443
457
|
minSize = props.minSize,
|
|
444
458
|
getDataTransferItems = props.getDataTransferItems,
|
|
445
459
|
divProps = _objectWithoutProperties(props, ['acceptedFiles', 'preventDropOnDocument', 'disablePreview', 'disableClick', 'onDropAccepted', 'onDropRejected', 'onFileDialogCancel', 'maxSize', 'minSize', 'getDataTransferItems']);
|
|
460
|
+
/* eslint-enable no-unused-vars */
|
|
461
|
+
|
|
462
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
463
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
464
|
+
|
|
446
465
|
|
|
447
466
|
return React.createElement(
|
|
448
467
|
'div',
|
|
449
468
|
_extends({
|
|
450
469
|
className: className,
|
|
451
470
|
style: appliedStyle
|
|
452
|
-
}, divProps /* expand user provided props first so event handlers are never overridden
|
|
471
|
+
}, divProps /* expand user provided props first so event handlers are never overridden */
|
|
472
|
+
, {
|
|
453
473
|
onClick: this.composeHandlers(this.onClick),
|
|
454
474
|
onDragStart: this.composeHandlers(this.onDragStart),
|
|
455
475
|
onDragEnter: this.composeHandlers(this.onDragEnter),
|
|
@@ -460,7 +480,8 @@ var Dropzone = function (_React$Component) {
|
|
|
460
480
|
'aria-disabled': disabled
|
|
461
481
|
}),
|
|
462
482
|
this.renderChildren(children, isDragActive, isDragAccept, isDragReject),
|
|
463
|
-
React.createElement('input', _extends({}, inputProps /* expand user provided inputProps first so inputAttributes override them
|
|
483
|
+
React.createElement('input', _extends({}, inputProps /* expand user provided inputProps first so inputAttributes override them */
|
|
484
|
+
, inputAttributes))
|
|
464
485
|
);
|
|
465
486
|
}
|
|
466
487
|
}]);
|