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/utils/index.spec.js
CHANGED
|
@@ -1,106 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getDataTransferItems,
|
|
3
2
|
isIeOrEdge,
|
|
4
3
|
isKindFile,
|
|
5
4
|
isDragDataWithFiles,
|
|
6
|
-
composeEventHandlers
|
|
5
|
+
composeEventHandlers,
|
|
6
|
+
isPropagationStopped,
|
|
7
|
+
isDefaultPrevented
|
|
7
8
|
} from './'
|
|
8
9
|
|
|
9
|
-
const files = [
|
|
10
|
-
{
|
|
11
|
-
name: 'file1.pdf',
|
|
12
|
-
size: 1111,
|
|
13
|
-
type: 'application/pdf'
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
name: 'cats.gif',
|
|
17
|
-
size: 1234,
|
|
18
|
-
type: 'image/gif'
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
name: 'dogs.jpg',
|
|
22
|
-
size: 2345,
|
|
23
|
-
type: 'image/jpeg'
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
const fileItems = [
|
|
28
|
-
{
|
|
29
|
-
kind: 'file',
|
|
30
|
-
type: 'application/json'
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
describe('getDataTransferItems', () => {
|
|
35
|
-
it('should return an array', () => {
|
|
36
|
-
const res = getDataTransferItems({})
|
|
37
|
-
expect(res).toBeInstanceOf(Array)
|
|
38
|
-
expect(res).toHaveLength(0)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('should get dataTransfer before using target', () => {
|
|
42
|
-
const event = {
|
|
43
|
-
target: {
|
|
44
|
-
files
|
|
45
|
-
},
|
|
46
|
-
dataTransfer: {
|
|
47
|
-
files
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const res = getDataTransferItems(event)
|
|
51
|
-
expect(res).toBeInstanceOf(Array)
|
|
52
|
-
expect(res).toHaveLength(3)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('should use dataTransfer.items if files is not defined', () => {
|
|
56
|
-
const event = {
|
|
57
|
-
target: {
|
|
58
|
-
files: [{}]
|
|
59
|
-
},
|
|
60
|
-
dataTransfer: {
|
|
61
|
-
items: fileItems
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const res = getDataTransferItems(event)
|
|
65
|
-
expect(res).toBeInstanceOf(Array)
|
|
66
|
-
expect(res).toHaveLength(1)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('should use event.target if dataTransfer is not defined', () => {
|
|
70
|
-
const event = {
|
|
71
|
-
target: {
|
|
72
|
-
files
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const res = getDataTransferItems(event)
|
|
76
|
-
expect(res).toBeInstanceOf(Array)
|
|
77
|
-
expect(res).toHaveLength(3)
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('should prioritize dataTransfer.files over .items', () => {
|
|
81
|
-
const event = {
|
|
82
|
-
dataTransfer: {
|
|
83
|
-
files: [{}, {}],
|
|
84
|
-
items: [{}, {}, {}]
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const res = getDataTransferItems(event)
|
|
88
|
-
expect(res).toBeInstanceOf(Array)
|
|
89
|
-
expect(res).toHaveLength(2)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('should not mutate data', () => {
|
|
93
|
-
const event = {
|
|
94
|
-
dataTransfer: {
|
|
95
|
-
files
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
expect(Object.keys(files[2])).toHaveLength(3)
|
|
99
|
-
getDataTransferItems(event, true)
|
|
100
|
-
expect(Object.keys(files[2])).toHaveLength(3)
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
|
|
104
10
|
describe('isIeOrEdge', () => {
|
|
105
11
|
it('should return true for IE10', () => {
|
|
106
12
|
const userAgent =
|
|
@@ -139,6 +45,38 @@ describe('isKindFile()', () => {
|
|
|
139
45
|
})
|
|
140
46
|
})
|
|
141
47
|
|
|
48
|
+
describe('isPropagationStopped()', () => {
|
|
49
|
+
const trueFn = jest.fn(() => true)
|
|
50
|
+
|
|
51
|
+
it('should return result of isPropagationStopped() if isPropagationStopped exists', () => {
|
|
52
|
+
expect(isPropagationStopped({ isPropagationStopped: trueFn })).toBe(true)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('should return value of cancelBubble if isPropagationStopped doesnt exist and cancelBubble exists', () => {
|
|
56
|
+
expect(isPropagationStopped({ cancelBubble: true })).toBe(true)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('should return false if isPropagationStopped and cancelBubble are missing', () => {
|
|
60
|
+
expect(isPropagationStopped({})).toBe(false)
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
describe('isDefaultPrevented()', () => {
|
|
65
|
+
const trueFn = jest.fn(() => true)
|
|
66
|
+
|
|
67
|
+
it('should return value of defaultPrevented if defaultPrevented exists', () => {
|
|
68
|
+
expect(isDefaultPrevented({ defaultPrevented: true })).toBe(true)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('should return result of isDefaultPrevented() if isDefaultPrevented exists and defaultPrevented is missing', () => {
|
|
72
|
+
expect(isDefaultPrevented({ isDefaultPrevented: trueFn })).toBe(true)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('should return false if isDefaultPrevented and defaultPrevented are missing', () => {
|
|
76
|
+
expect(isDefaultPrevented({})).toBe(false)
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
142
80
|
describe('isDragDataWithFiles()', () => {
|
|
143
81
|
it('should return true if every dragged type is a file', () => {
|
|
144
82
|
expect(isDragDataWithFiles({ dataTransfer: { types: ['Files'] } })).toBe(true)
|
package/styleguide.config.js
CHANGED
|
@@ -33,6 +33,10 @@ module.exports = {
|
|
|
33
33
|
name: 'Basic example',
|
|
34
34
|
content: 'examples/Basic/Readme.md'
|
|
35
35
|
},
|
|
36
|
+
{
|
|
37
|
+
name: 'Events',
|
|
38
|
+
content: 'examples/Events/README.md'
|
|
39
|
+
},
|
|
36
40
|
{
|
|
37
41
|
name: 'Styling Dropzone',
|
|
38
42
|
content: 'examples/Styling/Readme.md'
|
|
@@ -66,10 +70,6 @@ module.exports = {
|
|
|
66
70
|
{
|
|
67
71
|
name: 'Using third-party plugins',
|
|
68
72
|
content: 'examples/PluginArchitecture/Readme.md'
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: 'Dropzone for folders',
|
|
72
|
-
content: 'examples/Folders/Readme.md'
|
|
73
73
|
}
|
|
74
74
|
]
|
|
75
75
|
}
|
package/typings/tests/all.tsx
CHANGED
package/dist/es/utils/styles.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
active: {
|
|
3
|
-
borderStyle: 'solid',
|
|
4
|
-
backgroundColor: '#eee'
|
|
5
|
-
},
|
|
6
|
-
accepted: {
|
|
7
|
-
borderStyle: 'solid',
|
|
8
|
-
borderColor: '#6c6',
|
|
9
|
-
backgroundColor: '#eee'
|
|
10
|
-
},
|
|
11
|
-
rejected: {
|
|
12
|
-
borderStyle: 'solid',
|
|
13
|
-
borderColor: '#c66',
|
|
14
|
-
backgroundColor: '#eee'
|
|
15
|
-
},
|
|
16
|
-
default: {
|
|
17
|
-
width: 200,
|
|
18
|
-
height: 200,
|
|
19
|
-
borderWidth: 2,
|
|
20
|
-
borderColor: '#666',
|
|
21
|
-
borderStyle: 'dashed',
|
|
22
|
-
borderRadius: 5
|
|
23
|
-
},
|
|
24
|
-
disabled: {
|
|
25
|
-
opacity: 0.5
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
Dropzone that accepts folders as drag-and-drop. Supports multiple folders and subfolders.
|
|
2
|
-
|
|
3
|
-
```jsx harmony
|
|
4
|
-
const {fromEvent} = require('file-selector')
|
|
5
|
-
|
|
6
|
-
class Folders extends React.Component {
|
|
7
|
-
constructor() {
|
|
8
|
-
super()
|
|
9
|
-
this.state = {
|
|
10
|
-
files: []
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
onDrop(files) {
|
|
15
|
-
this.setState({files})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
render() {
|
|
19
|
-
const files = this.state.files.map(f => (
|
|
20
|
-
<li key={f.name}>
|
|
21
|
-
{f.path} - {f.size} bytes
|
|
22
|
-
</li>
|
|
23
|
-
))
|
|
24
|
-
return (
|
|
25
|
-
<section>
|
|
26
|
-
<div>
|
|
27
|
-
<Dropzone
|
|
28
|
-
getDataTransferItems={evt => fromEvent(evt)}
|
|
29
|
-
onDrop={this.onDrop.bind(this)}
|
|
30
|
-
>
|
|
31
|
-
{({getRootProps, getInputProps}) => (
|
|
32
|
-
<div {...getRootProps()}>
|
|
33
|
-
<input {...getInputProps()} />
|
|
34
|
-
<p>Drop a folder with files here</p>
|
|
35
|
-
</div>
|
|
36
|
-
)}
|
|
37
|
-
</Dropzone>
|
|
38
|
-
</div>
|
|
39
|
-
<aside>
|
|
40
|
-
<h4>Files</h4>
|
|
41
|
-
<ul>{files}</ul>
|
|
42
|
-
</aside>
|
|
43
|
-
</section>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
<Folders />
|
|
49
|
-
```
|
package/src/utils/styles.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
active: {
|
|
3
|
-
borderStyle: 'solid',
|
|
4
|
-
backgroundColor: '#eee'
|
|
5
|
-
},
|
|
6
|
-
accepted: {
|
|
7
|
-
borderStyle: 'solid',
|
|
8
|
-
borderColor: '#6c6',
|
|
9
|
-
backgroundColor: '#eee'
|
|
10
|
-
},
|
|
11
|
-
rejected: {
|
|
12
|
-
borderStyle: 'solid',
|
|
13
|
-
borderColor: '#c66',
|
|
14
|
-
backgroundColor: '#eee'
|
|
15
|
-
},
|
|
16
|
-
default: {
|
|
17
|
-
width: 200,
|
|
18
|
-
height: 200,
|
|
19
|
-
borderWidth: 2,
|
|
20
|
-
borderColor: '#666',
|
|
21
|
-
borderStyle: 'dashed',
|
|
22
|
-
borderRadius: 5
|
|
23
|
-
},
|
|
24
|
-
disabled: {
|
|
25
|
-
opacity: 0.5
|
|
26
|
-
}
|
|
27
|
-
}
|