react-dropzone 11.2.0 → 11.2.4

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.
@@ -0,0 +1,140 @@
1
+ If you'd like to integrate the dropzone with the [doka](https://pqina.nl/doka/?ref=react-dropzone) image editor, you just need to pass either of the selected images to the `create()` method exported by doka:
2
+
3
+ ```jsx harmony
4
+ import React, {useEffect, useState} from 'react';
5
+ import {useDropzone} from 'react-dropzone';
6
+
7
+ import {create} from 'doka';
8
+
9
+ const thumbsContainer = {
10
+ display: "flex",
11
+ flexDirection: "row",
12
+ flexWrap: "wrap",
13
+ marginTop: 16,
14
+ padding: 20
15
+ };
16
+
17
+ const thumb = {
18
+ position: "relative",
19
+ display: "inline-flex",
20
+ borderRadius: 2,
21
+ border: "1px solid #eaeaea",
22
+ marginBottom: 8,
23
+ marginRight: 8,
24
+ width: 100,
25
+ height: 100,
26
+ padding: 4,
27
+ boxSizing: "border-box"
28
+ };
29
+
30
+ const thumbInner = {
31
+ display: "flex",
32
+ minWidth: 0,
33
+ overflow: "hidden"
34
+ };
35
+
36
+ const img = {
37
+ display: "block",
38
+ width: "auto",
39
+ height: "100%"
40
+ };
41
+
42
+ const thumbButton = {
43
+ position: "absolute",
44
+ right: 10,
45
+ bottom: 10,
46
+ background: "rgba(0,0,0,.8)",
47
+ color: "#fff",
48
+ border: 0,
49
+ borderRadius: ".325em",
50
+ cursor: "pointer"
51
+ };
52
+
53
+ const editImage = (image, done) => {
54
+ const imageFile = image.doka ? image.doka.file : image;
55
+ const imageState = image.doka ? image.doka.data : {};
56
+ create({
57
+ // recreate previous state
58
+ ...imageState,
59
+
60
+ // load original image file
61
+ src: imageFile,
62
+ outputData: true,
63
+
64
+ onconfirm: ({ file, data }) => {
65
+ Object.assign(file, {
66
+ doka: { file: imageFile, data }
67
+ });
68
+ done(file);
69
+ }
70
+ });
71
+ };
72
+
73
+ function Doka(props) {
74
+ const [files, setFiles] = useState([]);
75
+ const { getRootProps, getInputProps } = useDropzone({
76
+ accept: "image/*",
77
+ onDrop: (acceptedFiles) => {
78
+ setFiles(
79
+ acceptedFiles.map((file) =>
80
+ Object.assign(file, {
81
+ preview: URL.createObjectURL(file)
82
+ })
83
+ )
84
+ );
85
+ }
86
+ });
87
+
88
+ const thumbs = files.map((file, index) => (
89
+ <div style={thumb} key={file.name}>
90
+ <div style={thumbInner}>
91
+ <img src={file.preview} style={img} alt="" />
92
+ </div>
93
+ <button
94
+ style={thumbButton}
95
+ onClick={() =>
96
+ editImage(file, (output) => {
97
+ const updatedFiles = [...files];
98
+
99
+ // replace original image with new image
100
+ updatedFiles[index] = output;
101
+
102
+ // revoke preview URL for old image
103
+ if (file.preview) URL.revokeObjectURL(file.preview);
104
+
105
+ // set new preview URL
106
+ Object.assign(output, {
107
+ preview: URL.createObjectURL(output)
108
+ });
109
+
110
+ // update view
111
+ setFiles(updatedFiles);
112
+ })
113
+ }
114
+ >
115
+ edit
116
+ </button>
117
+ </div>
118
+ ));
119
+
120
+ useEffect(
121
+ () => () => {
122
+ // Make sure to revoke the data uris to avoid memory leaks
123
+ files.forEach((file) => URL.revokeObjectURL(file.preview));
124
+ },
125
+ [files]
126
+ );
127
+
128
+ return (
129
+ <section className="container">
130
+ <div {...getRootProps({ className: "dropzone" })}>
131
+ <input {...getInputProps()} />
132
+ <p>Drag 'n' drop some files here, or click to select files</p>
133
+ </div>
134
+ <aside style={thumbsContainer}>{thumbs}</aside>
135
+ </section>
136
+ );
137
+ }
138
+
139
+ <Doka />
140
+ ```
package/package.json CHANGED
@@ -90,74 +90,75 @@
90
90
  "react": ">= 16.8"
91
91
  },
92
92
  "dependencies": {
93
- "attr-accept": "^2.0.0",
94
- "file-selector": "^0.1.12",
93
+ "attr-accept": "^2.2.1",
94
+ "file-selector": "^0.2.2",
95
95
  "prop-types": "^15.7.2"
96
96
  },
97
97
  "devDependencies": {
98
- "@babel/cli": "^7.6.4",
99
- "@babel/core": "^7.6.4",
100
- "@babel/plugin-external-helpers": "^7.2.0",
101
- "@babel/plugin-proposal-export-default-from": "^7.5.2",
102
- "@babel/plugin-proposal-logical-assignment-operators": "^7.2.0",
103
- "@babel/plugin-proposal-optional-chaining": "^7.6.0",
104
- "@babel/plugin-proposal-pipeline-operator": "^7.5.0",
105
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
106
- "@babel/plugin-proposal-do-expressions": "^7.6.0",
107
- "@babel/plugin-transform-runtime": "^7.6.2",
108
- "@babel/preset-env": "^7.6.3",
109
- "@babel/preset-react": "^7.6.3",
110
- "@babel/register": "^7.6.2",
111
- "@commitlint/cli": "^8.2.0",
112
- "@commitlint/config-angular": "^8.2.0",
113
- "@commitlint/prompt": "^8.2.0",
114
- "@commitlint/prompt-cli": "^8.2.0",
115
- "@size-limit/preset-small-lib": "^2.1.6",
116
- "@testing-library/dom": "^6.5.0",
117
- "@testing-library/jest-dom": "^4.1.0",
118
- "@testing-library/react": "^9.3.0",
119
- "@testing-library/react-hooks": "^2.0.3",
120
- "@types/react": "^16.9.0",
121
- "@types/react-dom": "^16.9.0",
98
+ "@babel/cli": "^7.11.6",
99
+ "@babel/core": "^7.11.6",
100
+ "@babel/plugin-external-helpers": "^7.10.4",
101
+ "@babel/plugin-proposal-do-expressions": "^7.10.4",
102
+ "@babel/plugin-proposal-export-default-from": "^7.10.4",
103
+ "@babel/plugin-proposal-logical-assignment-operators": "^7.11.0",
104
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.4",
105
+ "@babel/plugin-proposal-optional-chaining": "^7.11.0",
106
+ "@babel/plugin-proposal-pipeline-operator": "^7.10.5",
107
+ "@babel/plugin-transform-runtime": "^7.11.5",
108
+ "@babel/preset-env": "^7.11.5",
109
+ "@babel/preset-react": "^7.10.4",
110
+ "@babel/register": "^7.11.5",
111
+ "@commitlint/cli": "^9.1.2",
112
+ "@commitlint/config-angular": "^9.1.2",
113
+ "@commitlint/prompt": "^9.1.2",
114
+ "@commitlint/prompt-cli": "^9.1.2",
115
+ "@size-limit/preset-small-lib": "^4.5.7",
116
+ "@testing-library/dom": "^7.24.1",
117
+ "@testing-library/jest-dom": "^5.11.4",
118
+ "@testing-library/react": "^11.0.2",
119
+ "@testing-library/react-hooks": "^3.4.1",
120
+ "@types/react": "^16.9.49",
121
+ "@types/react-dom": "^16.9.8",
122
122
  "babel-eslint": "10.x",
123
- "babel-jest": "^24.9.0",
123
+ "babel-jest": "^26.3.0",
124
124
  "babel-plugin-add-module-exports": "^1.0.2",
125
- "babel-plugin-dynamic-import-node": "^2.3.0",
126
- "commitizen": "^3.1.2",
127
- "cross-env": "^6.0.3",
128
- "eslint": "6.x",
125
+ "babel-plugin-dynamic-import-node": "^2.3.3",
126
+ "commitizen": "^4.2.1",
127
+ "cross-env": "^7.0.2",
128
+ "eslint": "7.x",
129
129
  "eslint-config-okonet": "^7.0.2",
130
130
  "eslint-config-prettier": "6.x",
131
131
  "eslint-plugin-import": "2.x",
132
132
  "eslint-plugin-jsx-a11y": "6.x",
133
- "eslint-plugin-node": "10.x",
133
+ "eslint-plugin-node": "11.x",
134
134
  "eslint-plugin-prettier": "3.x",
135
135
  "eslint-plugin-react": "7.x",
136
- "eslint-plugin-react-hooks": "2.x",
137
- "husky": "^3.0.8",
138
- "imagemin-cli": "^5.0.0",
139
- "imagemin-pngquant": "^8.0.0",
140
- "jest": "^24.9.0",
141
- "lint-staged": "^9.4.2",
142
- "markdownlint-cli": "^0.18.0",
136
+ "eslint-plugin-react-hooks": "4.x",
137
+ "husky": "^4.2.5",
138
+ "imagemin-cli": "^6.0.0",
139
+ "imagemin-pngquant": "^9.0.0",
140
+ "jest": "^26.4.2",
141
+ "lint-staged": "^10.3.0",
142
+ "markdownlint-cli": "^0.23.2",
143
143
  "prettier": "*",
144
- "react": "^16.9.0",
145
- "react-dom": "^16.9.0",
146
- "react-styleguidist": "^9.1.16",
147
- "react-test-renderer": "^16.9.0",
148
- "rimraf": "^3.0.0",
149
- "rollup": "^1.23.1",
150
- "rollup-plugin-babel": "^4.3.3",
144
+ "react": "^16.13.1",
145
+ "react-dom": "^16.13.1",
146
+ "react-styleguidist": "^11.0.10",
147
+ "react-test-renderer": "^16.13.1",
148
+ "rimraf": "^3.0.2",
149
+ "rollup": "^2.26.10",
150
+ "rollup-plugin-babel": "^4.4.0",
151
151
  "rollup-plugin-commonjs": "^10.1.0",
152
152
  "rollup-plugin-node-resolve": "^5.2.0",
153
- "rollup-plugin-uglify": "^6.0.3",
154
- "styled-components": "^4.4.0",
155
- "webpack-blocks": "^2.0.1",
156
- "sinon": "^3.2.1",
157
- "style-loader": "^1.0.0",
158
- "tslint": "^5.20.0",
159
- "typescript": "^3.2.4",
160
- "webpack": "^4.41.1"
153
+ "rollup-plugin-uglify": "^6.0.4",
154
+ "sinon": "^9.0.3",
155
+ "size-limit": "^4.5.7",
156
+ "style-loader": "^1.2.1",
157
+ "styled-components": "^5.2.0",
158
+ "tslint": "^6.1.3",
159
+ "typescript": "^4.0.2",
160
+ "webpack": "^4.44.1",
161
+ "webpack-blocks": "^2.1.0"
161
162
  },
162
163
  "typings": "typings/react-dropzone.d.ts",
163
164
  "config": {
@@ -165,8 +166,11 @@
165
166
  "path": "@commitlint/prompt"
166
167
  }
167
168
  },
168
- "version": "11.2.0",
169
+ "version": "11.2.4",
169
170
  "engines": {
170
- "node": ">= 8"
171
- }
171
+ "node": ">= 10"
172
+ },
173
+ "browserslist": [
174
+ "defaults"
175
+ ]
172
176
  }
package/src/index.js CHANGED
@@ -47,6 +47,24 @@ const Dropzone = forwardRef(({ children, ...params }, ref) => {
47
47
  })
48
48
 
49
49
  Dropzone.displayName = 'Dropzone'
50
+
51
+ // Add default props for react-docgen
52
+ const defaultProps = {
53
+ disabled: false,
54
+ getFilesFromEvent: fromEvent,
55
+ maxSize: Infinity,
56
+ minSize: 0,
57
+ multiple: true,
58
+ maxFiles: 0,
59
+ preventDropOnDocument: true,
60
+ noClick: false,
61
+ noKeyboard: false,
62
+ noDrag: false,
63
+ noDragEventsBubbling: false
64
+ }
65
+
66
+ Dropzone.defaultProps = defaultProps
67
+
50
68
  Dropzone.propTypes = {
51
69
  /**
52
70
  * Render function that exposes the dropzone state and prop getter fns
@@ -360,27 +378,32 @@ const initialState = {
360
378
  *
361
379
  * @returns {DropzoneState}
362
380
  */
363
- export function useDropzone({
364
- accept,
365
- disabled = false,
366
- getFilesFromEvent = fromEvent,
367
- maxSize = Infinity,
368
- minSize = 0,
369
- multiple = true,
370
- maxFiles = 0,
371
- onDragEnter,
372
- onDragLeave,
373
- onDragOver,
374
- onDrop,
375
- onDropAccepted,
376
- onDropRejected,
377
- onFileDialogCancel,
378
- preventDropOnDocument = true,
379
- noClick = false,
380
- noKeyboard = false,
381
- noDrag = false,
382
- noDragEventsBubbling = false
383
- } = {}) {
381
+ export function useDropzone(options = {}) {
382
+ const {
383
+ accept,
384
+ disabled,
385
+ getFilesFromEvent,
386
+ maxSize,
387
+ minSize,
388
+ multiple,
389
+ maxFiles,
390
+ onDragEnter,
391
+ onDragLeave,
392
+ onDragOver,
393
+ onDrop,
394
+ onDropAccepted,
395
+ onDropRejected,
396
+ onFileDialogCancel,
397
+ preventDropOnDocument,
398
+ noClick,
399
+ noKeyboard,
400
+ noDrag,
401
+ noDragEventsBubbling
402
+ } = {
403
+ ...defaultProps,
404
+ ...options
405
+ }
406
+
384
407
  const rootRef = useRef(null)
385
408
  const inputRef = useRef(null)
386
409
 
@@ -634,6 +657,7 @@ export function useDropzone({
634
657
  accept,
635
658
  minSize,
636
659
  maxSize,
660
+ maxFiles,
637
661
  getFilesFromEvent,
638
662
  onDrop,
639
663
  onDropAccepted,
@@ -728,7 +752,7 @@ export function useDropzone({
728
752
  )
729
753
 
730
754
  const fileCount = draggedFiles.length
731
- const isDragAccept = fileCount > 0 && allFilesAccepted({ files: draggedFiles, accept, minSize, maxSize, multiple })
755
+ const isDragAccept = fileCount > 0 && allFilesAccepted({ files: draggedFiles, accept, minSize, maxSize, multiple, maxFiles })
732
756
  const isDragReject = fileCount > 0 && !isDragAccept
733
757
 
734
758
  return {