react-dropzone 13.0.0 → 14.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/package.json CHANGED
@@ -95,7 +95,7 @@
95
95
  ],
96
96
  "license": "MIT",
97
97
  "peerDependencies": {
98
- "react": ">= 16.8"
98
+ "react": ">= 16.8 || 18.0.0"
99
99
  },
100
100
  "dependencies": {
101
101
  "attr-accept": "^2.2.2",
@@ -129,8 +129,8 @@
129
129
  "@size-limit/webpack-why": "^7.0.5",
130
130
  "@testing-library/dom": "^8.11.3",
131
131
  "@testing-library/jest-dom": "^5.16.1",
132
- "@testing-library/react": "^12.1.2",
133
- "@testing-library/react-hooks": "^7.0.2",
132
+ "@testing-library/react": "^13.1.1",
133
+ "@testing-library/react-hooks": "^8.0.0",
134
134
  "@types/react": "^17.0.0",
135
135
  "@types/react-dom": "^17.0.0",
136
136
  "@typescript-eslint/eslint-plugin": "^5.10.1",
@@ -156,10 +156,10 @@
156
156
  "markdownlint-cli": "^0.30.0",
157
157
  "pinst": "^2.1.6",
158
158
  "prettier": "^2.5.1",
159
- "react": "^17.0.0",
160
- "react-dom": "^17.0.0",
159
+ "react": "^18.1.0",
160
+ "react-dom": "^18.1.0",
161
161
  "react-styleguidist": "^11.2.0",
162
- "react-test-renderer": "^17.0.0",
162
+ "react-test-renderer": "^18.1.0",
163
163
  "rimraf": "^3.0.2",
164
164
  "rollup": "^2.66.1",
165
165
  "rollup-plugin-terser": "^7.0.2",
@@ -171,7 +171,7 @@
171
171
  "webpack-blocks": "^2.1.0"
172
172
  },
173
173
  "typings": "typings/react-dropzone.d.ts",
174
- "version": "13.0.0",
174
+ "version": "14.0.0",
175
175
  "engines": {
176
176
  "node": ">= 10.13"
177
177
  },
package/src/index.js CHANGED
@@ -85,7 +85,6 @@ Dropzone.propTypes = {
85
85
  * @param {boolean} params.isDragActive Active drag is in progress
86
86
  * @param {boolean} params.isDragAccept Dragged files are accepted
87
87
  * @param {boolean} params.isDragReject Some dragged files are rejected
88
- * @param {File[]} params.draggedFiles Files in active drag
89
88
  * @param {File[]} params.acceptedFiles Accepted files
90
89
  * @param {FileRejection[]} params.fileRejections Rejected files and why they were rejected
91
90
  */
@@ -310,29 +309,33 @@ export default Dropzone;
310
309
  */
311
310
 
312
311
  /**
313
- * An object with the current dropzone state and some helper functions.
312
+ * An object with the current dropzone state.
314
313
  *
315
314
  * @typedef {object} DropzoneState
316
- * @property {Function} getRootProps Returns the props you should apply to the root drop container you render
317
- * @property {Function} getInputProps Returns the props you should apply to hidden file input you render
318
- * @property {Function} open Open the native file selection dialog
319
315
  * @property {boolean} isFocused Dropzone area is in focus
320
316
  * @property {boolean} isFileDialogActive File dialog is opened
321
317
  * @property {boolean} isDragActive Active drag is in progress
322
318
  * @property {boolean} isDragAccept Dragged files are accepted
323
319
  * @property {boolean} isDragReject Some dragged files are rejected
324
- * @property {File[]} draggedFiles Files in active drag
325
320
  * @property {File[]} acceptedFiles Accepted files
326
321
  * @property {FileRejection[]} fileRejections Rejected files and why they were rejected
327
322
  */
328
323
 
324
+ /**
325
+ * An object with the dropzone methods.
326
+ *
327
+ * @typedef {object} DropzoneMethods
328
+ * @property {Function} getRootProps Returns the props you should apply to the root drop container you render
329
+ * @property {Function} getInputProps Returns the props you should apply to hidden file input you render
330
+ * @property {Function} open Open the native file selection dialog
331
+ */
332
+
329
333
  const initialState = {
330
334
  isFocused: false,
331
335
  isFileDialogActive: false,
332
336
  isDragActive: false,
333
337
  isDragAccept: false,
334
338
  isDragReject: false,
335
- draggedFiles: [],
336
339
  acceptedFiles: [],
337
340
  fileRejections: [],
338
341
  };
@@ -410,7 +413,7 @@ const initialState = {
410
413
  * @param {dropRejectedCb} [props.onDropRejected]
411
414
  * @param {(error: Error) => void} [props.onError]
412
415
  *
413
- * @returns {DropzoneState}
416
+ * @returns {DropzoneState & DropzoneMethods}
414
417
  */
415
418
  export function useDropzone(props = {}) {
416
419
  const {
@@ -459,7 +462,7 @@ export function useDropzone(props = {}) {
459
462
  const inputRef = useRef(null);
460
463
 
461
464
  const [state, dispatch] = useReducer(reducer, initialState);
462
- const { isFocused, isFileDialogActive, draggedFiles } = state;
465
+ const { isFocused, isFileDialogActive } = state;
463
466
 
464
467
  const fsAccessApiWorksRef = useRef(
465
468
  typeof window !== "undefined" &&
@@ -538,13 +541,27 @@ export function useDropzone(props = {}) {
538
541
 
539
542
  if (isEvtWithFiles(event)) {
540
543
  Promise.resolve(getFilesFromEvent(event))
541
- .then((draggedFiles) => {
544
+ .then((files) => {
542
545
  if (isPropagationStopped(event) && !noDragEventsBubbling) {
543
546
  return;
544
547
  }
545
548
 
549
+ const fileCount = files.length;
550
+ const isDragAccept =
551
+ fileCount > 0 &&
552
+ allFilesAccepted({
553
+ files,
554
+ accept: acceptAttr,
555
+ minSize,
556
+ maxSize,
557
+ multiple,
558
+ maxFiles,
559
+ });
560
+ const isDragReject = fileCount > 0 && !isDragAccept;
561
+
546
562
  dispatch({
547
- draggedFiles,
563
+ isDragAccept,
564
+ isDragReject,
548
565
  isDragActive: true,
549
566
  type: "setDraggedFiles",
550
567
  });
@@ -556,7 +573,17 @@ export function useDropzone(props = {}) {
556
573
  .catch((e) => onErrCb(e));
557
574
  }
558
575
  },
559
- [getFilesFromEvent, onDragEnter, onErrCb, noDragEventsBubbling]
576
+ [
577
+ getFilesFromEvent,
578
+ onDragEnter,
579
+ onErrCb,
580
+ noDragEventsBubbling,
581
+ acceptAttr,
582
+ minSize,
583
+ maxSize,
584
+ multiple,
585
+ maxFiles,
586
+ ]
560
587
  );
561
588
 
562
589
  const onDragOverCb = useCallback(
@@ -603,9 +630,10 @@ export function useDropzone(props = {}) {
603
630
  }
604
631
 
605
632
  dispatch({
606
- isDragActive: false,
607
633
  type: "setDraggedFiles",
608
- draggedFiles: [],
634
+ isDragActive: false,
635
+ isDragAccept: false,
636
+ isDragReject: false,
609
637
  });
610
638
 
611
639
  if (isEvtWithFiles(event) && onDragLeave) {
@@ -906,23 +934,8 @@ export function useDropzone(props = {}) {
906
934
  [inputRef, accept, multiple, onDropCb, disabled]
907
935
  );
908
936
 
909
- const fileCount = draggedFiles.length;
910
- const isDragAccept =
911
- fileCount > 0 &&
912
- allFilesAccepted({
913
- files: draggedFiles,
914
- accept: acceptAttr,
915
- minSize,
916
- maxSize,
917
- multiple,
918
- maxFiles,
919
- });
920
- const isDragReject = fileCount > 0 && !isDragAccept;
921
-
922
937
  return {
923
938
  ...state,
924
- isDragAccept,
925
- isDragReject,
926
939
  isFocused: isFocused && !disabled,
927
940
  getRootProps,
928
941
  getInputProps,
@@ -932,6 +945,11 @@ export function useDropzone(props = {}) {
932
945
  };
933
946
  }
934
947
 
948
+ /**
949
+ * @param {DropzoneState} state
950
+ * @param {{type: string} & DropzoneState} action
951
+ * @returns {DropzoneState}
952
+ */
935
953
  function reducer(state, action) {
936
954
  /* istanbul ignore next */
937
955
  switch (action.type) {
@@ -956,12 +974,11 @@ function reducer(state, action) {
956
974
  isFileDialogActive: false,
957
975
  };
958
976
  case "setDraggedFiles":
959
- /* eslint no-case-declarations: 0 */
960
- const { isDragActive, draggedFiles } = action;
961
977
  return {
962
978
  ...state,
963
- draggedFiles,
964
- isDragActive,
979
+ isDragActive: action.isDragActive,
980
+ isDragAccept: action.isDragAccept,
981
+ isDragReject: action.isDragReject,
965
982
  };
966
983
  case "setFiles":
967
984
  return {