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/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint prefer-template: 0 */
|
|
2
2
|
|
|
3
3
|
import React from 'react'
|
|
4
|
+
import { fromEvent } from 'file-selector'
|
|
4
5
|
import PropTypes from 'prop-types'
|
|
5
6
|
import {
|
|
6
7
|
isDragDataWithFiles,
|
|
@@ -9,9 +10,10 @@ import {
|
|
|
9
10
|
allFilesAccepted,
|
|
10
11
|
fileMatchSize,
|
|
11
12
|
onDocumentDragOver,
|
|
12
|
-
getDataTransferItems as defaultGetDataTransferItem,
|
|
13
13
|
isIeOrEdge,
|
|
14
|
-
composeEventHandlers
|
|
14
|
+
composeEventHandlers,
|
|
15
|
+
isPropagationStopped,
|
|
16
|
+
isDefaultPrevented
|
|
15
17
|
} from './utils'
|
|
16
18
|
|
|
17
19
|
class Dropzone extends React.Component {
|
|
@@ -73,7 +75,7 @@ class Dropzone extends React.Component {
|
|
|
73
75
|
|
|
74
76
|
if (isDragDataWithFiles(evt)) {
|
|
75
77
|
Promise.resolve(this.props.getDataTransferItems(evt)).then(draggedFiles => {
|
|
76
|
-
if (
|
|
78
|
+
if (isPropagationStopped(evt)) {
|
|
77
79
|
return
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -95,6 +97,10 @@ class Dropzone extends React.Component {
|
|
|
95
97
|
evt.preventDefault()
|
|
96
98
|
evt.persist()
|
|
97
99
|
|
|
100
|
+
if (evt.dataTransfer) {
|
|
101
|
+
evt.dataTransfer.dropEffect = 'copy'
|
|
102
|
+
}
|
|
103
|
+
|
|
98
104
|
if (this.props.onDragOver && isDragDataWithFiles(evt)) {
|
|
99
105
|
this.props.onDragOver.call(this, evt)
|
|
100
106
|
}
|
|
@@ -157,7 +163,7 @@ class Dropzone extends React.Component {
|
|
|
157
163
|
const acceptedFiles = []
|
|
158
164
|
const rejectedFiles = []
|
|
159
165
|
|
|
160
|
-
if (
|
|
166
|
+
if (isPropagationStopped(evt)) {
|
|
161
167
|
return
|
|
162
168
|
}
|
|
163
169
|
|
|
@@ -199,16 +205,16 @@ class Dropzone extends React.Component {
|
|
|
199
205
|
}
|
|
200
206
|
|
|
201
207
|
onClick = evt => {
|
|
202
|
-
const { onClick
|
|
208
|
+
const { onClick } = this.props
|
|
203
209
|
|
|
204
210
|
// if onClick prop is given, run it first
|
|
205
211
|
if (onClick) {
|
|
206
212
|
onClick.call(this, evt)
|
|
207
213
|
}
|
|
208
214
|
|
|
209
|
-
//
|
|
215
|
+
// If the event hasn't been default prevented from within
|
|
210
216
|
// the onClick listener, open the file dialog
|
|
211
|
-
if (!
|
|
217
|
+
if (!isDefaultPrevented(evt)) {
|
|
212
218
|
evt.stopPropagation()
|
|
213
219
|
|
|
214
220
|
// in IE11/Edge the file-browser dialog is blocking, ensure this is behind setTimeout
|
|
@@ -253,7 +259,7 @@ class Dropzone extends React.Component {
|
|
|
253
259
|
if (onFocus) {
|
|
254
260
|
onFocus.call(this, evt)
|
|
255
261
|
}
|
|
256
|
-
if (!
|
|
262
|
+
if (!isDefaultPrevented(evt)) {
|
|
257
263
|
this.setState({ isFocused: true })
|
|
258
264
|
}
|
|
259
265
|
}
|
|
@@ -263,7 +269,7 @@ class Dropzone extends React.Component {
|
|
|
263
269
|
if (onBlur) {
|
|
264
270
|
onBlur.call(this, evt)
|
|
265
271
|
}
|
|
266
|
-
if (!
|
|
272
|
+
if (!isDefaultPrevented(evt)) {
|
|
267
273
|
this.setState({ isFocused: false })
|
|
268
274
|
}
|
|
269
275
|
}
|
|
@@ -278,7 +284,7 @@ class Dropzone extends React.Component {
|
|
|
278
284
|
onKeyDown.call(this, evt)
|
|
279
285
|
}
|
|
280
286
|
|
|
281
|
-
if (!
|
|
287
|
+
if (!isDefaultPrevented(evt) && (evt.keyCode === 32 || evt.keyCode === 13)) {
|
|
282
288
|
evt.preventDefault()
|
|
283
289
|
this.open()
|
|
284
290
|
}
|
|
@@ -428,11 +434,6 @@ Dropzone.propTypes = {
|
|
|
428
434
|
*/
|
|
429
435
|
children: PropTypes.func,
|
|
430
436
|
|
|
431
|
-
/**
|
|
432
|
-
* Disallow clicking on the dropzone container to open file dialog
|
|
433
|
-
*/
|
|
434
|
-
disableClick: PropTypes.bool,
|
|
435
|
-
|
|
436
437
|
/**
|
|
437
438
|
* Enable/disable the dropzone entirely
|
|
438
439
|
*/
|
|
@@ -561,9 +562,8 @@ Dropzone.propTypes = {
|
|
|
561
562
|
Dropzone.defaultProps = {
|
|
562
563
|
preventDropOnDocument: true,
|
|
563
564
|
disabled: false,
|
|
564
|
-
disableClick: false,
|
|
565
565
|
multiple: true,
|
|
566
566
|
maxSize: Infinity,
|
|
567
567
|
minSize: 0,
|
|
568
|
-
getDataTransferItems:
|
|
568
|
+
getDataTransferItems: fromEvent
|
|
569
569
|
}
|
package/src/index.spec.js
CHANGED
|
@@ -30,6 +30,11 @@ const createDtWithFiles = (files = []) => {
|
|
|
30
30
|
return {
|
|
31
31
|
dataTransfer: {
|
|
32
32
|
files,
|
|
33
|
+
items: files.map(file => ({
|
|
34
|
+
kind: 'file',
|
|
35
|
+
type: file.type,
|
|
36
|
+
getAsFile: () => file
|
|
37
|
+
})),
|
|
33
38
|
types: ['Files']
|
|
34
39
|
}
|
|
35
40
|
}
|
|
@@ -307,21 +312,6 @@ describe('Dropzone', () => {
|
|
|
307
312
|
expect(open).toHaveBeenCalled()
|
|
308
313
|
})
|
|
309
314
|
|
|
310
|
-
it('should not call `open` if disableClick prop is true', () => {
|
|
311
|
-
const dropzone = mount(
|
|
312
|
-
<Dropzone disableClick>
|
|
313
|
-
{({ getRootProps, getInputProps }) => (
|
|
314
|
-
<div {...getRootProps()}>
|
|
315
|
-
<input {...getInputProps()} />
|
|
316
|
-
</div>
|
|
317
|
-
)}
|
|
318
|
-
</Dropzone>
|
|
319
|
-
)
|
|
320
|
-
const open = jest.spyOn(dropzone.instance(), 'open')
|
|
321
|
-
dropzone.simulate('click')
|
|
322
|
-
expect(open).not.toHaveBeenCalled()
|
|
323
|
-
})
|
|
324
|
-
|
|
325
315
|
it('should call `onClick` callback if provided', () => {
|
|
326
316
|
const onClick = jest.fn()
|
|
327
317
|
const dropzone = mount(
|
|
@@ -339,23 +329,6 @@ describe('Dropzone', () => {
|
|
|
339
329
|
expect(onClick).toHaveBeenCalled()
|
|
340
330
|
})
|
|
341
331
|
|
|
342
|
-
it('should call `onClick` if provided even if `disableClick` is set', () => {
|
|
343
|
-
const onClick = jest.fn()
|
|
344
|
-
const dropzone = mount(
|
|
345
|
-
<Dropzone onClick={onClick} disableClick>
|
|
346
|
-
{({ getRootProps, getInputProps }) => (
|
|
347
|
-
<div {...getRootProps()}>
|
|
348
|
-
<input {...getInputProps()} />
|
|
349
|
-
</div>
|
|
350
|
-
)}
|
|
351
|
-
</Dropzone>
|
|
352
|
-
)
|
|
353
|
-
const open = jest.spyOn(dropzone.instance(), 'open')
|
|
354
|
-
dropzone.simulate('click')
|
|
355
|
-
expect(open).toHaveBeenCalledTimes(0)
|
|
356
|
-
expect(onClick).toHaveBeenCalled()
|
|
357
|
-
})
|
|
358
|
-
|
|
359
332
|
it('should not call `open` if event was prevented in `onClick`', () => {
|
|
360
333
|
const onClick = jest.fn(event => event.preventDefault())
|
|
361
334
|
const dropzone = mount(
|
|
@@ -447,24 +420,6 @@ describe('Dropzone', () => {
|
|
|
447
420
|
expect(onClickInner).toHaveBeenCalled()
|
|
448
421
|
})
|
|
449
422
|
|
|
450
|
-
it('should invoke onClick on the wrapper if disableClick is set', () => {
|
|
451
|
-
const onClick = jest.fn()
|
|
452
|
-
const component = mount(
|
|
453
|
-
<div onClick={onClick}>
|
|
454
|
-
<Dropzone disableClick>
|
|
455
|
-
{({ getRootProps, getInputProps }) => (
|
|
456
|
-
<div {...getRootProps()}>
|
|
457
|
-
<input {...getInputProps()} />
|
|
458
|
-
</div>
|
|
459
|
-
)}
|
|
460
|
-
</Dropzone>
|
|
461
|
-
</div>
|
|
462
|
-
)
|
|
463
|
-
|
|
464
|
-
component.find(Dropzone).simulate('click')
|
|
465
|
-
expect(onClick).toHaveBeenCalled()
|
|
466
|
-
})
|
|
467
|
-
|
|
468
423
|
it('should invoke inputProps onClick if provided', () => {
|
|
469
424
|
const onClick = jest.fn()
|
|
470
425
|
const component = mount(
|
|
@@ -516,7 +471,7 @@ describe('Dropzone', () => {
|
|
|
516
471
|
)}
|
|
517
472
|
</Dropzone>
|
|
518
473
|
)
|
|
519
|
-
dropzone.simulate('focus', {
|
|
474
|
+
dropzone.simulate('focus', { defaultPrevented: false })
|
|
520
475
|
expect(dropzone.find('.dropzone-focused')).toHaveLength(1)
|
|
521
476
|
})
|
|
522
477
|
|
|
@@ -531,7 +486,7 @@ describe('Dropzone', () => {
|
|
|
531
486
|
)}
|
|
532
487
|
</Dropzone>
|
|
533
488
|
)
|
|
534
|
-
dropzone.simulate('focus', {
|
|
489
|
+
dropzone.simulate('focus', { defaultPrevented: false })
|
|
535
490
|
expect(dropzone.state('isFocused')).toBe(true)
|
|
536
491
|
expect(onFocus).toHaveBeenCalled()
|
|
537
492
|
})
|
|
@@ -539,7 +494,7 @@ describe('Dropzone', () => {
|
|
|
539
494
|
it('does not set focus state if user supplied onFocus prevented default', async () => {
|
|
540
495
|
const onFocus = jest.fn().mockImplementationOnce(evt => {
|
|
541
496
|
Object.assign(evt, {
|
|
542
|
-
|
|
497
|
+
defaultPrevented: true
|
|
543
498
|
})
|
|
544
499
|
})
|
|
545
500
|
const dropzone = mount(
|
|
@@ -568,9 +523,9 @@ describe('Dropzone', () => {
|
|
|
568
523
|
)}
|
|
569
524
|
</Dropzone>
|
|
570
525
|
)
|
|
571
|
-
dropzone.simulate('focus', {
|
|
526
|
+
dropzone.simulate('focus', { defaultPrevented: false })
|
|
572
527
|
expect(dropzone.find('.dropzone-focused')).toHaveLength(1)
|
|
573
|
-
dropzone.simulate('blur', {
|
|
528
|
+
dropzone.simulate('blur', { defaultPrevented: false })
|
|
574
529
|
expect(dropzone.find('.dropzone-focused')).toHaveLength(0)
|
|
575
530
|
})
|
|
576
531
|
|
|
@@ -585,14 +540,14 @@ describe('Dropzone', () => {
|
|
|
585
540
|
)}
|
|
586
541
|
</Dropzone>
|
|
587
542
|
)
|
|
588
|
-
dropzone.simulate('blur', {
|
|
543
|
+
dropzone.simulate('blur', { defaultPrevented: false })
|
|
589
544
|
expect(onBlur).toHaveBeenCalled()
|
|
590
545
|
})
|
|
591
546
|
|
|
592
547
|
it('does not unset focus state if user supplied onBlur prevented default', async () => {
|
|
593
548
|
const onBlur = jest.fn().mockImplementationOnce(evt => {
|
|
594
549
|
Object.assign(evt, {
|
|
595
|
-
|
|
550
|
+
defaultPrevented: true
|
|
596
551
|
})
|
|
597
552
|
})
|
|
598
553
|
const dropzone = mount(
|
|
@@ -604,7 +559,7 @@ describe('Dropzone', () => {
|
|
|
604
559
|
)}
|
|
605
560
|
</Dropzone>
|
|
606
561
|
)
|
|
607
|
-
dropzone.simulate('focus', {
|
|
562
|
+
dropzone.simulate('focus', { defaultPrevented: false })
|
|
608
563
|
dropzone.simulate('blur', {})
|
|
609
564
|
expect(onBlur).toHaveBeenCalled()
|
|
610
565
|
})
|
|
@@ -625,13 +580,13 @@ describe('Dropzone', () => {
|
|
|
625
580
|
|
|
626
581
|
dropzone.simulate('keydown', {
|
|
627
582
|
keyCode: 32,
|
|
628
|
-
|
|
583
|
+
defaultPrevented: false,
|
|
629
584
|
preventDefault() {}
|
|
630
585
|
})
|
|
631
586
|
|
|
632
587
|
dropzone.simulate('keydown', {
|
|
633
588
|
keyCode: 13,
|
|
634
|
-
|
|
589
|
+
defaultPrevented: false,
|
|
635
590
|
preventDefault() {}
|
|
636
591
|
})
|
|
637
592
|
|
|
@@ -651,7 +606,7 @@ describe('Dropzone', () => {
|
|
|
651
606
|
const open = jest.spyOn(dropzone.instance(), 'open')
|
|
652
607
|
dropzone.simulate('keydown', {
|
|
653
608
|
keyCode: 32,
|
|
654
|
-
|
|
609
|
+
defaultPrevented: false,
|
|
655
610
|
preventDefault() {}
|
|
656
611
|
})
|
|
657
612
|
expect(open).not.toHaveBeenCalled()
|
|
@@ -670,7 +625,7 @@ describe('Dropzone', () => {
|
|
|
670
625
|
const open = jest.spyOn(dropzone.instance(), 'open')
|
|
671
626
|
dropzone.find('input').simulate('keydown', {
|
|
672
627
|
keyCode: 32,
|
|
673
|
-
|
|
628
|
+
defaultPrevented: false,
|
|
674
629
|
preventDefault() {}
|
|
675
630
|
})
|
|
676
631
|
expect(open).not.toHaveBeenCalled()
|
|
@@ -705,7 +660,7 @@ describe('Dropzone', () => {
|
|
|
705
660
|
const open = jest.spyOn(dropzone.instance(), 'open')
|
|
706
661
|
dropzone.simulate('keydown', {
|
|
707
662
|
keyCode: 32,
|
|
708
|
-
|
|
663
|
+
defaultPrevented: false,
|
|
709
664
|
preventDefault() {}
|
|
710
665
|
})
|
|
711
666
|
expect(onKeyDown).toHaveBeenCalled()
|
|
@@ -725,7 +680,7 @@ describe('Dropzone', () => {
|
|
|
725
680
|
)
|
|
726
681
|
dropzone.find('input').simulate('keydown', {
|
|
727
682
|
keyCode: 32,
|
|
728
|
-
|
|
683
|
+
defaultPrevented: false,
|
|
729
684
|
preventDefault() {}
|
|
730
685
|
})
|
|
731
686
|
expect(onKeyDown).not.toHaveBeenCalled()
|
|
@@ -734,7 +689,7 @@ describe('Dropzone', () => {
|
|
|
734
689
|
it('does not react to keydown if user-supplied onKeyDown prevents default', async () => {
|
|
735
690
|
const onKeyDown = jest.fn().mockImplementationOnce(evt => {
|
|
736
691
|
Object.assign(evt, {
|
|
737
|
-
|
|
692
|
+
defaultPrevented: true
|
|
738
693
|
})
|
|
739
694
|
})
|
|
740
695
|
const dropzone = mount(
|
|
@@ -765,7 +720,7 @@ describe('Dropzone', () => {
|
|
|
765
720
|
const open = jest.spyOn(dropzone.instance(), 'open')
|
|
766
721
|
dropzone.simulate('keydown', {
|
|
767
722
|
keyCode: 100,
|
|
768
|
-
|
|
723
|
+
defaultPrevented: false,
|
|
769
724
|
preventDefault() {}
|
|
770
725
|
})
|
|
771
726
|
expect(open).not.toHaveBeenCalled()
|
|
@@ -1073,7 +1028,7 @@ describe('Dropzone', () => {
|
|
|
1073
1028
|
describe('open() fn', () => {
|
|
1074
1029
|
it('should be exposed to children', () => {
|
|
1075
1030
|
const subject = mount(
|
|
1076
|
-
<Dropzone
|
|
1031
|
+
<Dropzone>
|
|
1077
1032
|
{({ getRootProps, getInputProps, open }) => (
|
|
1078
1033
|
<div {...getRootProps()}>
|
|
1079
1034
|
<input {...getInputProps()} />
|
|
@@ -1127,8 +1082,9 @@ describe('Dropzone', () => {
|
|
|
1127
1082
|
)
|
|
1128
1083
|
|
|
1129
1084
|
const input = component.find('input')
|
|
1085
|
+
Object.defineProperty(input, 'files', { value: files })
|
|
1130
1086
|
const evt = {
|
|
1131
|
-
target:
|
|
1087
|
+
target: input,
|
|
1132
1088
|
preventDefault() {},
|
|
1133
1089
|
isPropagationStopped: () => false,
|
|
1134
1090
|
persist() {}
|
|
@@ -1202,6 +1158,7 @@ describe('Dropzone', () => {
|
|
|
1202
1158
|
</Dropzone>
|
|
1203
1159
|
)
|
|
1204
1160
|
await dropzone.simulate('drop', createDtWithFiles(files))
|
|
1161
|
+
await flushPromises(dropzone)
|
|
1205
1162
|
expect(onDrop).toHaveBeenCalledWith([], files, expectedEvent)
|
|
1206
1163
|
})
|
|
1207
1164
|
|
|
@@ -1217,6 +1174,7 @@ describe('Dropzone', () => {
|
|
|
1217
1174
|
)
|
|
1218
1175
|
|
|
1219
1176
|
await dropzone.simulate('drop', createDtWithFiles([images[0]]))
|
|
1177
|
+
await flushPromises(dropzone)
|
|
1220
1178
|
expect(onDrop).toHaveBeenCalledWith([images[0]], [], expectedEvent)
|
|
1221
1179
|
})
|
|
1222
1180
|
|
|
@@ -1232,6 +1190,7 @@ describe('Dropzone', () => {
|
|
|
1232
1190
|
)
|
|
1233
1191
|
|
|
1234
1192
|
await dropzone.simulate('drop', createDtWithFiles(images))
|
|
1193
|
+
await flushPromises(dropzone)
|
|
1235
1194
|
expect(onDrop).toHaveBeenCalledWith([], images, expectedEvent)
|
|
1236
1195
|
})
|
|
1237
1196
|
|
|
@@ -1246,6 +1205,7 @@ describe('Dropzone', () => {
|
|
|
1246
1205
|
</Dropzone>
|
|
1247
1206
|
)
|
|
1248
1207
|
await dropzone.simulate('drop', createDtWithFiles(images))
|
|
1208
|
+
await flushPromises(dropzone)
|
|
1249
1209
|
expect(onDrop).toHaveBeenCalledWith(images, [], expectedEvent)
|
|
1250
1210
|
})
|
|
1251
1211
|
|
|
@@ -1276,14 +1236,17 @@ describe('Dropzone', () => {
|
|
|
1276
1236
|
)
|
|
1277
1237
|
|
|
1278
1238
|
await dropzone.simulate('drop', createDtWithFiles(files))
|
|
1239
|
+
await flushPromises(dropzone)
|
|
1279
1240
|
expect(onDrop).toHaveBeenCalledWith([], files, expectedEvent)
|
|
1280
1241
|
onDrop.mockClear()
|
|
1281
1242
|
|
|
1282
1243
|
await dropzone.simulate('drop', createDtWithFiles(images))
|
|
1244
|
+
await flushPromises(dropzone)
|
|
1283
1245
|
expect(onDrop).toHaveBeenCalledWith(images, [], expectedEvent)
|
|
1284
1246
|
onDrop.mockClear()
|
|
1285
1247
|
|
|
1286
1248
|
await dropzone.simulate('drop', createDtWithFiles(files.concat(images)))
|
|
1249
|
+
await flushPromises(dropzone)
|
|
1287
1250
|
expect(onDrop).toHaveBeenCalledWith(images, files, expectedEvent)
|
|
1288
1251
|
})
|
|
1289
1252
|
|
|
@@ -1299,14 +1262,17 @@ describe('Dropzone', () => {
|
|
|
1299
1262
|
)
|
|
1300
1263
|
|
|
1301
1264
|
await dropzone.simulate('drop', createDtWithFiles(files))
|
|
1265
|
+
await flushPromises(dropzone)
|
|
1302
1266
|
expect(onDropAccepted).not.toHaveBeenCalled()
|
|
1303
1267
|
onDropAccepted.mockClear()
|
|
1304
1268
|
|
|
1305
1269
|
await dropzone.simulate('drop', createDtWithFiles(images))
|
|
1270
|
+
await flushPromises(dropzone)
|
|
1306
1271
|
expect(onDropAccepted).toHaveBeenCalledWith(images, expectedEvent)
|
|
1307
1272
|
onDropAccepted.mockClear()
|
|
1308
1273
|
|
|
1309
1274
|
await dropzone.simulate('drop', createDtWithFiles(files.concat(images)))
|
|
1275
|
+
await flushPromises(dropzone)
|
|
1310
1276
|
expect(onDropAccepted).toHaveBeenCalledWith(images, expectedEvent)
|
|
1311
1277
|
})
|
|
1312
1278
|
|
|
@@ -1322,14 +1288,17 @@ describe('Dropzone', () => {
|
|
|
1322
1288
|
)
|
|
1323
1289
|
|
|
1324
1290
|
await dropzone.simulate('drop', createDtWithFiles(images))
|
|
1291
|
+
await flushPromises(dropzone)
|
|
1325
1292
|
expect(onDropRejected).not.toHaveBeenCalled()
|
|
1326
1293
|
onDropRejected.mockClear()
|
|
1327
1294
|
|
|
1328
1295
|
await dropzone.simulate('drop', createDtWithFiles(files))
|
|
1296
|
+
await flushPromises(dropzone)
|
|
1329
1297
|
expect(onDropRejected).toHaveBeenCalledWith(files, expectedEvent)
|
|
1330
1298
|
onDropRejected.mockClear()
|
|
1331
1299
|
|
|
1332
1300
|
await dropzone.simulate('drop', createDtWithFiles(files.concat(images)))
|
|
1301
|
+
await flushPromises(dropzone)
|
|
1333
1302
|
expect(onDropRejected).toHaveBeenCalledWith(files, expectedEvent)
|
|
1334
1303
|
})
|
|
1335
1304
|
|
|
@@ -1349,6 +1318,7 @@ describe('Dropzone', () => {
|
|
|
1349
1318
|
</Dropzone>
|
|
1350
1319
|
)
|
|
1351
1320
|
await dropzone.simulate('drop', createDtWithFiles(files))
|
|
1321
|
+
await flushPromises(dropzone)
|
|
1352
1322
|
expect(onDrop).toHaveBeenCalledWith([], files, expectedEvent)
|
|
1353
1323
|
expect(onDropAccepted).not.toHaveBeenCalled()
|
|
1354
1324
|
expect(onDropRejected).toHaveBeenCalledWith(files, expectedEvent)
|
|
@@ -1371,6 +1341,7 @@ describe('Dropzone', () => {
|
|
|
1371
1341
|
)
|
|
1372
1342
|
|
|
1373
1343
|
await dropzone.simulate('drop', createDtWithFiles(images))
|
|
1344
|
+
await flushPromises(dropzone)
|
|
1374
1345
|
expect(onDrop).toHaveBeenCalledWith(images, [], expectedEvent)
|
|
1375
1346
|
expect(onDropAccepted).toHaveBeenCalledWith(images, expectedEvent)
|
|
1376
1347
|
expect(onDropRejected).not.toHaveBeenCalled()
|
|
@@ -1394,6 +1365,7 @@ describe('Dropzone', () => {
|
|
|
1394
1365
|
const bogusImages = [createFile('bogus.gif', 1234, 'application/x-moz-file')]
|
|
1395
1366
|
|
|
1396
1367
|
await dropzone.simulate('drop', createDtWithFiles(bogusImages))
|
|
1368
|
+
await flushPromises(dropzone)
|
|
1397
1369
|
expect(onDrop).toHaveBeenCalledWith(bogusImages, [], expectedEvent)
|
|
1398
1370
|
expect(onDropAccepted).toHaveBeenCalledWith(bogusImages, expectedEvent)
|
|
1399
1371
|
expect(onDropRejected).not.toHaveBeenCalled()
|
|
@@ -1410,6 +1382,7 @@ describe('Dropzone', () => {
|
|
|
1410
1382
|
</Dropzone>
|
|
1411
1383
|
)
|
|
1412
1384
|
await dropzone.simulate('drop', createDtWithFiles(files.concat(images)))
|
|
1385
|
+
await flushPromises(dropzone)
|
|
1413
1386
|
expect(onDrop).toHaveBeenCalledWith(files.concat(images), [], expectedEvent)
|
|
1414
1387
|
expect(onDropAccepted).toHaveBeenCalledWith(files.concat(images), expectedEvent)
|
|
1415
1388
|
expect(onDropRejected).not.toHaveBeenCalled()
|
|
@@ -1432,6 +1405,7 @@ describe('Dropzone', () => {
|
|
|
1432
1405
|
)
|
|
1433
1406
|
|
|
1434
1407
|
await dropzone.simulate('drop', createDtWithFiles(files))
|
|
1408
|
+
await flushPromises(dropzone)
|
|
1435
1409
|
expect(onDrop).toHaveBeenCalledWith(files, [], expectedEvent)
|
|
1436
1410
|
expect(onDropAccepted).toHaveBeenCalledWith(files, expectedEvent)
|
|
1437
1411
|
expect(onDropRejected).not.toHaveBeenCalled()
|
|
@@ -1453,6 +1427,7 @@ describe('Dropzone', () => {
|
|
|
1453
1427
|
</Dropzone>
|
|
1454
1428
|
)
|
|
1455
1429
|
await dropzone.simulate('drop', createDtWithFiles(images))
|
|
1430
|
+
await flushPromises(dropzone)
|
|
1456
1431
|
expect(onDrop).toHaveBeenCalledWith([], images, expectedEvent)
|
|
1457
1432
|
expect(onDropAccepted).not.toHaveBeenCalled()
|
|
1458
1433
|
expect(onDropRejected).toHaveBeenCalledWith(images, expectedEvent)
|
|
@@ -1474,6 +1449,7 @@ describe('Dropzone', () => {
|
|
|
1474
1449
|
</Dropzone>
|
|
1475
1450
|
)
|
|
1476
1451
|
await dropzone.simulate('drop', createDtWithFiles(files))
|
|
1452
|
+
await flushPromises(dropzone)
|
|
1477
1453
|
expect(onDrop).toHaveBeenCalledWith([], files, expectedEvent)
|
|
1478
1454
|
expect(onDropAccepted).not.toHaveBeenCalled()
|
|
1479
1455
|
expect(onDropRejected).toHaveBeenCalledWith(files, expectedEvent)
|
|
@@ -1495,6 +1471,7 @@ describe('Dropzone', () => {
|
|
|
1495
1471
|
</Dropzone>
|
|
1496
1472
|
)
|
|
1497
1473
|
await dropzone.simulate('drop', createDtWithFiles(images))
|
|
1474
|
+
await flushPromises(dropzone)
|
|
1498
1475
|
expect(onDrop).toHaveBeenCalledWith(images, [], expectedEvent)
|
|
1499
1476
|
expect(onDropAccepted).toHaveBeenCalledWith(images, expectedEvent)
|
|
1500
1477
|
expect(onDropRejected).not.toHaveBeenCalled()
|
|
@@ -1511,6 +1488,7 @@ describe('Dropzone', () => {
|
|
|
1511
1488
|
</Dropzone>
|
|
1512
1489
|
)
|
|
1513
1490
|
await dropzone.simulate('drop', createDtWithFiles(files.concat(images)))
|
|
1491
|
+
await flushPromises(dropzone)
|
|
1514
1492
|
expect(onDrop).toHaveBeenCalledWith(files.concat(images), [], expectedEvent)
|
|
1515
1493
|
expect(onDropAccepted).toHaveBeenCalledWith(files.concat(images), expectedEvent)
|
|
1516
1494
|
expect(onDropRejected).not.toHaveBeenCalled()
|
package/src/utils/index.js
CHANGED
|
@@ -5,28 +5,6 @@ export const supportMultiple =
|
|
|
5
5
|
? 'multiple' in document.createElement('input')
|
|
6
6
|
: true
|
|
7
7
|
|
|
8
|
-
export function getDataTransferItems(event) {
|
|
9
|
-
let dataTransferItemsList = []
|
|
10
|
-
if (event.dataTransfer) {
|
|
11
|
-
const dt = event.dataTransfer
|
|
12
|
-
|
|
13
|
-
// NOTE: Only the 'drop' event has access to DataTransfer.files,
|
|
14
|
-
// otherwise it will always be empty
|
|
15
|
-
if (dt.files && dt.files.length) {
|
|
16
|
-
dataTransferItemsList = dt.files
|
|
17
|
-
} else if (dt.items && dt.items.length) {
|
|
18
|
-
// During the drag even the dataTransfer.files is null
|
|
19
|
-
// but Chrome implements some drag store, which is accesible via dataTransfer.items
|
|
20
|
-
dataTransferItemsList = dt.items
|
|
21
|
-
}
|
|
22
|
-
} else if (event.target && event.target.files) {
|
|
23
|
-
dataTransferItemsList = event.target.files
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Convert from DataTransferItemsList to the native Array
|
|
27
|
-
return Array.prototype.slice.call(dataTransferItemsList)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
8
|
// Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
|
|
31
9
|
// that MIME type will always be accepted
|
|
32
10
|
export function fileAccepted(file, accept) {
|
|
@@ -41,6 +19,30 @@ export function allFilesAccepted(files, accept) {
|
|
|
41
19
|
return files.every(file => fileAccepted(file, accept))
|
|
42
20
|
}
|
|
43
21
|
|
|
22
|
+
// React's synthetic events has evt.isPropagationStopped,
|
|
23
|
+
// but to remain compatibility with other libs (Preact) fall back
|
|
24
|
+
// to check evt.cancelBubble
|
|
25
|
+
export function isPropagationStopped(evt) {
|
|
26
|
+
if (typeof evt.isPropagationStopped === 'function') {
|
|
27
|
+
return evt.isPropagationStopped()
|
|
28
|
+
} else if (typeof evt.cancelBubble !== 'undefined') {
|
|
29
|
+
return evt.cancelBubble
|
|
30
|
+
}
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// React's synthetic events has evt.isDefaultPrevented,
|
|
35
|
+
// but to remain compatibility with other libs (Preact) first
|
|
36
|
+
// check evt.defaultPrevented
|
|
37
|
+
export function isDefaultPrevented(evt) {
|
|
38
|
+
if (typeof evt.defaultPrevented !== 'undefined') {
|
|
39
|
+
return evt.defaultPrevented
|
|
40
|
+
} else if (typeof evt.isDefaultPrevented === 'function') {
|
|
41
|
+
return evt.isDefaultPrevented()
|
|
42
|
+
}
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
|
|
44
46
|
export function isDragDataWithFiles(evt) {
|
|
45
47
|
if (!evt.dataTransfer) {
|
|
46
48
|
return true
|