react-dropzone 11.2.3 → 11.3.2

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 CHANGED
@@ -3,11 +3,11 @@
3
3
  # react-dropzone
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/react-dropzone.svg?style=flat-square)](https://www.npmjs.com/package/react-dropzone)
6
- ![Build Status](https://github.com/react-dropzone/react-dropzone/workflows/Test/badge.svg)
6
+ [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/react-dropzone/react-dropzone/Test?label=tests&style=flat-square)](https://github.com/react-dropzone/react-dropzone/actions?query=workflow%3ATest)
7
7
  [![codecov](https://img.shields.io/codecov/c/gh/react-dropzone/react-dropzone/master.svg?style=flat-square)](https://codecov.io/gh/react-dropzone/react-dropzone)
8
8
  [![Open Collective](https://img.shields.io/opencollective/backers/react-dropzone.svg?style=flat-square)](#backers)
9
9
  [![Open Collective](https://img.shields.io/opencollective/sponsors/react-dropzone.svg?style=flat-square)](#sponsors)
10
- [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/react-dropzone/react-dropzone)
10
+ [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod&style=flat-square)](https://gitpod.io/#https://github.com/react-dropzone/react-dropzone)
11
11
 
12
12
  Simple React hook to create a HTML5-compliant drag'n'drop zone for files.
13
13
 
@@ -292,6 +292,15 @@ function mockData(files) {
292
292
 
293
293
  More examples for this can be found in `react-dropzone`s own [test suites](https://github.com/react-dropzone/react-dropzone/blob/master/src/index.spec.js).
294
294
 
295
+ ## Need image editing?
296
+
297
+ React Dropzone integrates perfectly with [Doka Image Editor](https://pqina.nl/doka/?ref=react-dropzone), creating a modern image editing experience. Doka supports crop aspect ratios, resizing, rotating, cropping, annotating, filtering, and much more.
298
+
299
+ Checkout the [integration example](https://react-dropzone.js.org/#!/Doka).
300
+
301
+ ## Supported Browsers
302
+
303
+ We use [browserslist](https://github.com/browserslist/browserslist) config to state the browser support for this lib, so check it out on [browserslist.dev](https://browserslist.dev/?q=ZGVmYXVsdHM%3D).
295
304
 
296
305
  ## Support
297
306
 
package/dist/es/index.js CHANGED
@@ -79,7 +79,8 @@ var defaultProps = {
79
79
  noClick: false,
80
80
  noKeyboard: false,
81
81
  noDrag: false,
82
- noDragEventsBubbling: false
82
+ noDragEventsBubbling: false,
83
+ validator: null
83
84
  };
84
85
  Dropzone.defaultProps = defaultProps;
85
86
  Dropzone.propTypes = {
@@ -244,7 +245,14 @@ Dropzone.propTypes = {
244
245
  * @param {FileRejection[]} fileRejections
245
246
  * @param {(DragEvent|Event)} event
246
247
  */
247
- onDropRejected: PropTypes.func
248
+ onDropRejected: PropTypes.func,
249
+
250
+ /**
251
+ * Custom validation function
252
+ * @param {File} file
253
+ * @returns {FileError|FileError[]}
254
+ */
255
+ validator: PropTypes.func
248
256
  };
249
257
  export default Dropzone;
250
258
  /**
@@ -416,7 +424,8 @@ export function useDropzone() {
416
424
  noClick = _defaultProps$options.noClick,
417
425
  noKeyboard = _defaultProps$options.noKeyboard,
418
426
  noDrag = _defaultProps$options.noDrag,
419
- noDragEventsBubbling = _defaultProps$options.noDragEventsBubbling;
427
+ noDragEventsBubbling = _defaultProps$options.noDragEventsBubbling,
428
+ validator = _defaultProps$options.validator;
420
429
 
421
430
  var rootRef = useRef(null);
422
431
  var inputRef = useRef(null);
@@ -559,8 +568,9 @@ export function useDropzone() {
559
568
  event.preventDefault();
560
569
  event.persist();
561
570
  stopPropagation(event);
571
+ var hasFiles = isEvtWithFiles(event);
562
572
 
563
- if (event.dataTransfer) {
573
+ if (hasFiles && event.dataTransfer) {
564
574
  try {
565
575
  event.dataTransfer.dropEffect = 'copy';
566
576
  } catch (_unused) {}
@@ -568,7 +578,7 @@ export function useDropzone() {
568
578
 
569
579
  }
570
580
 
571
- if (isEvtWithFiles(event) && onDragOver) {
581
+ if (hasFiles && onDragOver) {
572
582
  onDragOver(event);
573
583
  }
574
584
 
@@ -632,15 +642,22 @@ export function useDropzone() {
632
642
  sizeMatch = _fileMatchSize2[0],
633
643
  sizeError = _fileMatchSize2[1];
634
644
 
635
- if (accepted && sizeMatch) {
645
+ var customErrors = validator ? validator(file) : null;
646
+
647
+ if (accepted && sizeMatch && !customErrors) {
636
648
  acceptedFiles.push(file);
637
649
  } else {
638
- var errors = [acceptError, sizeError].filter(function (e) {
639
- return e;
640
- });
650
+ var errors = [acceptError, sizeError];
651
+
652
+ if (customErrors) {
653
+ errors = errors.concat(customErrors);
654
+ }
655
+
641
656
  fileRejections.push({
642
657
  file: file,
643
- errors: errors
658
+ errors: errors.filter(function (e) {
659
+ return e;
660
+ })
644
661
  });
645
662
  }
646
663
  });