react-dropzone 4.2.12 → 5.0.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/dist/es/index.js +73 -58
- package/dist/es/utils/index.js +2 -0
- package/dist/index.js +2 -2
- package/package.json +4 -4
- package/src/__snapshots__/index.spec.js.snap +7 -7
- package/src/index.js +72 -52
- package/src/index.spec.js +93 -90
- package/src/utils/index.js +2 -0
package/package.json
CHANGED
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"size-limit": [
|
|
27
27
|
{
|
|
28
28
|
"path": "dist/index.js",
|
|
29
|
-
"limit": "
|
|
29
|
+
"limit": "6 KB"
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
"path": "dist/es/index.js",
|
|
33
|
-
"limit": "
|
|
33
|
+
"limit": "4 KB"
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
36
|
"lint-staged": {
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"react": ">=0.14.0"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"attr-accept": "^1.
|
|
77
|
+
"attr-accept": "^1.1.3",
|
|
78
78
|
"prop-types": "^15.5.7"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"path": "@commitlint/prompt"
|
|
124
124
|
}
|
|
125
125
|
},
|
|
126
|
-
"version": "
|
|
126
|
+
"version": "5.0.1"
|
|
127
127
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Dropzone basics should render children 1`] = `"<div class=\\"\\" aria-disabled=\\"false\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\"><p>some content</p><input type=\\"file\\" multiple=\\"\\" autocomplete=\\"off\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\"></div>"`;
|
|
4
|
-
|
|
5
|
-
exports[`Dropzone document drop protection does not prevent stray drops when preventDropOnDocument is false 1`] = `"<div class=\\"\\" aria-disabled=\\"false\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\"><input type=\\"file\\" multiple=\\"\\" autocomplete=\\"off\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\"></div>"`;
|
|
6
|
-
|
|
7
|
-
exports[`Dropzone document drop protection installs hooks to prevent stray drops from taking over the browser window 1`] = `"<div class=\\"\\" aria-disabled=\\"false\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\"><p>Content</p><input type=\\"file\\" multiple=\\"\\" autocomplete=\\"off\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\"></div>"`;
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Dropzone basics should render children 1`] = `"<div class=\\"\\" aria-disabled=\\"false\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\"><p>some content</p><input type=\\"file\\" multiple=\\"\\" autocomplete=\\"off\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\"></div>"`;
|
|
4
|
+
|
|
5
|
+
exports[`Dropzone document drop protection does not prevent stray drops when preventDropOnDocument is false 1`] = `"<div class=\\"\\" aria-disabled=\\"false\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\"><input type=\\"file\\" multiple=\\"\\" autocomplete=\\"off\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\"></div>"`;
|
|
6
|
+
|
|
7
|
+
exports[`Dropzone document drop protection installs hooks to prevent stray drops from taking over the browser window 1`] = `"<div class=\\"\\" aria-disabled=\\"false\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\"><p>Content</p><input type=\\"file\\" multiple=\\"\\" autocomplete=\\"off\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\"></div>"`;
|
package/src/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
allFilesAccepted,
|
|
9
9
|
fileMatchSize,
|
|
10
10
|
onDocumentDragOver,
|
|
11
|
-
getDataTransferItems,
|
|
11
|
+
getDataTransferItems as defaultGetDataTransferItem,
|
|
12
12
|
isIeOrEdge
|
|
13
13
|
} from './utils'
|
|
14
14
|
import styles from './utils/styles'
|
|
@@ -47,7 +47,9 @@ class Dropzone extends React.Component {
|
|
|
47
47
|
document.addEventListener('dragover', onDocumentDragOver, false)
|
|
48
48
|
document.addEventListener('drop', this.onDocumentDrop, false)
|
|
49
49
|
}
|
|
50
|
-
this.fileInputEl
|
|
50
|
+
if (this.fileInputEl != null) {
|
|
51
|
+
this.fileInputEl.addEventListener('click', this.onInputElementClick, false)
|
|
52
|
+
}
|
|
51
53
|
window.addEventListener('focus', this.onFileDialogCancel, false)
|
|
52
54
|
}
|
|
53
55
|
|
|
@@ -94,11 +96,12 @@ class Dropzone extends React.Component {
|
|
|
94
96
|
this.dragTargets.push(evt.target)
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
this.
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
Promise.resolve(this.props.getDataTransferItems(evt)).then(draggedFiles => {
|
|
100
|
+
this.setState({
|
|
101
|
+
isDragActive: true, // Do not rely on files for the drag state. It doesn't work in Safari.
|
|
102
|
+
draggedFiles
|
|
103
|
+
})
|
|
100
104
|
})
|
|
101
|
-
|
|
102
105
|
if (this.props.onDragEnter) {
|
|
103
106
|
this.props.onDragEnter.call(this, evt)
|
|
104
107
|
}
|
|
@@ -144,10 +147,15 @@ class Dropzone extends React.Component {
|
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
onDrop(evt) {
|
|
147
|
-
const {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
const {
|
|
151
|
+
onDrop,
|
|
152
|
+
onDropAccepted,
|
|
153
|
+
onDropRejected,
|
|
154
|
+
multiple,
|
|
155
|
+
disablePreview,
|
|
156
|
+
accept,
|
|
157
|
+
getDataTransferItems
|
|
158
|
+
} = this.props
|
|
151
159
|
|
|
152
160
|
// Stop default browser behavior
|
|
153
161
|
evt.preventDefault()
|
|
@@ -156,54 +164,57 @@ class Dropzone extends React.Component {
|
|
|
156
164
|
this.dragTargets = []
|
|
157
165
|
this.isFileDialogActive = false
|
|
158
166
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
file.preview = window.URL.createObjectURL(file) // eslint-disable-line no-param-reassign
|
|
163
|
-
} catch (err) {
|
|
164
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
165
|
-
console.error('Failed to generate preview for file', file, err) // eslint-disable-line no-console
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
167
|
+
// Clear files value
|
|
168
|
+
this.draggedFiles = null
|
|
169
169
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
acceptedFiles.push(file)
|
|
175
|
-
} else {
|
|
176
|
-
rejectedFiles.push(file)
|
|
177
|
-
}
|
|
170
|
+
// Reset drag state
|
|
171
|
+
this.setState({
|
|
172
|
+
isDragActive: false,
|
|
173
|
+
draggedFiles: []
|
|
178
174
|
})
|
|
179
175
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
176
|
+
Promise.resolve(getDataTransferItems(evt)).then(fileList => {
|
|
177
|
+
const acceptedFiles = []
|
|
178
|
+
const rejectedFiles = []
|
|
179
|
+
|
|
180
|
+
fileList.forEach(file => {
|
|
181
|
+
if (!disablePreview) {
|
|
182
|
+
try {
|
|
183
|
+
file.preview = window.URL.createObjectURL(file) // eslint-disable-line no-param-reassign
|
|
184
|
+
} catch (err) {
|
|
185
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
186
|
+
console.error('Failed to generate preview for file', file, err) // eslint-disable-line no-console
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
185
190
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
191
|
+
if (
|
|
192
|
+
fileAccepted(file, accept) &&
|
|
193
|
+
fileMatchSize(file, this.props.maxSize, this.props.minSize)
|
|
194
|
+
) {
|
|
195
|
+
acceptedFiles.push(file)
|
|
196
|
+
} else {
|
|
197
|
+
rejectedFiles.push(file)
|
|
198
|
+
}
|
|
199
|
+
})
|
|
189
200
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
if (!multiple && acceptedFiles.length > 1) {
|
|
202
|
+
// if not in multi mode add any extra accepted files to rejected.
|
|
203
|
+
// This will allow end users to easily ignore a multi file drop in "single" mode.
|
|
204
|
+
rejectedFiles.push(...acceptedFiles.splice(0))
|
|
205
|
+
}
|
|
193
206
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
207
|
+
if (onDrop) {
|
|
208
|
+
onDrop.call(this, acceptedFiles, rejectedFiles, evt)
|
|
209
|
+
}
|
|
197
210
|
|
|
198
|
-
|
|
199
|
-
|
|
211
|
+
if (rejectedFiles.length > 0 && onDropRejected) {
|
|
212
|
+
onDropRejected.call(this, rejectedFiles, evt)
|
|
213
|
+
}
|
|
200
214
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
draggedFiles: [],
|
|
205
|
-
acceptedFiles,
|
|
206
|
-
rejectedFiles
|
|
215
|
+
if (acceptedFiles.length > 0 && onDropAccepted) {
|
|
216
|
+
onDropAccepted.call(this, acceptedFiles, evt)
|
|
217
|
+
}
|
|
207
218
|
})
|
|
208
219
|
}
|
|
209
220
|
|
|
@@ -335,7 +346,7 @@ class Dropzone extends React.Component {
|
|
|
335
346
|
if (noStyles) {
|
|
336
347
|
style = styles.default
|
|
337
348
|
activeStyle = styles.active
|
|
338
|
-
acceptStyle =
|
|
349
|
+
acceptStyle = styles.active
|
|
339
350
|
rejectStyle = styles.rejected
|
|
340
351
|
disabledStyle = styles.disabled
|
|
341
352
|
}
|
|
@@ -401,6 +412,7 @@ class Dropzone extends React.Component {
|
|
|
401
412
|
onFileDialogCancel,
|
|
402
413
|
maxSize,
|
|
403
414
|
minSize,
|
|
415
|
+
getDataTransferItems,
|
|
404
416
|
...divProps
|
|
405
417
|
} = props
|
|
406
418
|
|
|
@@ -540,6 +552,13 @@ Dropzone.propTypes = {
|
|
|
540
552
|
*/
|
|
541
553
|
disabledStyle: PropTypes.object,
|
|
542
554
|
|
|
555
|
+
/**
|
|
556
|
+
* getDataTransferItems handler
|
|
557
|
+
* @param {Event} event
|
|
558
|
+
* @returns {Array} array of File objects
|
|
559
|
+
*/
|
|
560
|
+
getDataTransferItems: PropTypes.func,
|
|
561
|
+
|
|
543
562
|
/**
|
|
544
563
|
* onClick callback
|
|
545
564
|
* @param {Event} event
|
|
@@ -595,5 +614,6 @@ Dropzone.defaultProps = {
|
|
|
595
614
|
inputProps: {},
|
|
596
615
|
multiple: true,
|
|
597
616
|
maxSize: Infinity,
|
|
598
|
-
minSize: 0
|
|
617
|
+
minSize: 0,
|
|
618
|
+
getDataTransferItems: defaultGetDataTransferItem
|
|
599
619
|
}
|