react-dropzone 14.2.9 → 14.3.8
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 +16 -0
- package/dist/es/index.js +17 -6
- package/dist/es/package.json +1 -0
- package/dist/es/utils/index.js +23 -9
- package/dist/index.js +2 -2
- package/package.json +16 -10
- package/src/__snapshots__/index.spec.js.snap +1 -1
- package/src/index.js +18 -5
- package/src/index.spec.js +11 -2
- package/src/utils/index.js +22 -10
- package/src/utils/index.spec.js +47 -8
- package/typings/react-dropzone.d.ts +4 -3
- package/CONTRIBUTING.md +0 -135
package/README.md
CHANGED
|
@@ -339,6 +339,19 @@ Also keep in mind that the FS access API can only be used in [secure contexts](h
|
|
|
339
339
|
|
|
340
340
|
**NOTE** You can enable using the FS access API with the `useFsAccessApi` property: `useDropzone({useFsAccessApi: true})`.
|
|
341
341
|
|
|
342
|
+
### File System Access API
|
|
343
|
+
|
|
344
|
+
When setting `useFsAccessApi` to `true`, you're switching to the [File System API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API) (see the [file system access](https://wicg.github.io/file-system-access/) RFC).
|
|
345
|
+
|
|
346
|
+
What this essentially does is that it will use the [showOpenFilePicker](https://developer.mozilla.org/en-US/docs/Web/API/Window/showOpenFilePicker) method to open the file picker window so that the user can select files.
|
|
347
|
+
|
|
348
|
+
In contrast, the traditional way (when the `useFsAccessApi` is not set to `true` or not specified) uses an `<input type="file">` (see [docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file)) on which a click event is triggered.
|
|
349
|
+
|
|
350
|
+
With the use of the file system access API enabled, there's a couple of caveats to keep in mind:
|
|
351
|
+
1. The users will not be able to select directories
|
|
352
|
+
2. It requires the app to run in a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts)
|
|
353
|
+
3. In [Electron](https://www.electronjs.org/), the path may not be set (see [#1249](https://github.com/react-dropzone/react-dropzone/issues/1249))
|
|
354
|
+
|
|
342
355
|
## Supported Browsers
|
|
343
356
|
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).
|
|
344
357
|
|
|
@@ -424,5 +437,8 @@ Become a sponsor and get your logo on our README on Github with a link to your s
|
|
|
424
437
|
### Hosting
|
|
425
438
|
[react-dropzone.js.org](https://react-dropzone.js.org/) hosting provided by [netlify](https://www.netlify.com/).
|
|
426
439
|
|
|
440
|
+
## Contribute
|
|
441
|
+
Checkout the organization [CONTRIBUTING.md](https://github.com/react-dropzone/.github/blob/main/CONTRIBUTING.md).
|
|
442
|
+
|
|
427
443
|
## License
|
|
428
444
|
MIT
|
package/dist/es/index.js
CHANGED
|
@@ -37,7 +37,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
37
37
|
import React, { forwardRef, Fragment, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef } from "react";
|
|
38
38
|
import PropTypes from "prop-types";
|
|
39
39
|
import { fromEvent } from "file-selector";
|
|
40
|
-
import { acceptPropAsAcceptAttr, allFilesAccepted, composeEventHandlers, fileAccepted, fileMatchSize, canUseFileSystemAccessAPI, isAbort, isEvtWithFiles, isIeOrEdge, isPropagationStopped, isSecurityError, onDocumentDragOver, pickerOptionsFromAccept, TOO_MANY_FILES_REJECTION } from "./utils/index";
|
|
40
|
+
import { acceptPropAsAcceptAttr, allFilesAccepted, composeEventHandlers, fileAccepted, fileMatchSize, canUseFileSystemAccessAPI, isAbort, isEvtWithFiles, isIeOrEdge, isPropagationStopped, isSecurityError, onDocumentDragOver, pickerOptionsFromAccept, TOO_MANY_FILES_REJECTION } from "./utils/index.js";
|
|
41
41
|
/**
|
|
42
42
|
* Convenience wrapper component for the `useDropzone` hook
|
|
43
43
|
*
|
|
@@ -172,7 +172,7 @@ Dropzone.propTypes = {
|
|
|
172
172
|
/**
|
|
173
173
|
* Use this to provide a custom file aggregator
|
|
174
174
|
*
|
|
175
|
-
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
175
|
+
* @param {(DragEvent|Event|Array<FileSystemFileHandle>)} event A drag event or input change event (if files were selected via the file dialog)
|
|
176
176
|
*/
|
|
177
177
|
getFilesFromEvent: PropTypes.func,
|
|
178
178
|
|
|
@@ -326,7 +326,7 @@ export default Dropzone;
|
|
|
326
326
|
* in a asynchronous fashion, from drag or input change events.
|
|
327
327
|
*
|
|
328
328
|
* @callback getFilesFromEvent
|
|
329
|
-
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
329
|
+
* @param {(DragEvent|Event|Array<FileSystemFileHandle>)} event A drag event or input change event (if files were selected via the file dialog)
|
|
330
330
|
* @returns {(File[]|Promise<File[]>)}
|
|
331
331
|
*/
|
|
332
332
|
|
|
@@ -701,6 +701,7 @@ export function useDropzone() {
|
|
|
701
701
|
dispatch({
|
|
702
702
|
acceptedFiles: acceptedFiles,
|
|
703
703
|
fileRejections: fileRejections,
|
|
704
|
+
isDragReject: fileRejections.length > 0,
|
|
704
705
|
type: "setFiles"
|
|
705
706
|
});
|
|
706
707
|
|
|
@@ -898,7 +899,16 @@ export function useDropzone() {
|
|
|
898
899
|
multiple: multiple,
|
|
899
900
|
type: "file",
|
|
900
901
|
style: {
|
|
901
|
-
|
|
902
|
+
border: 0,
|
|
903
|
+
clip: "rect(0, 0, 0, 0)",
|
|
904
|
+
clipPath: "inset(50%)",
|
|
905
|
+
height: "1px",
|
|
906
|
+
margin: "0 -1px -1px 0",
|
|
907
|
+
overflow: "hidden",
|
|
908
|
+
padding: 0,
|
|
909
|
+
position: "absolute",
|
|
910
|
+
width: "1px",
|
|
911
|
+
whiteSpace: "nowrap"
|
|
902
912
|
},
|
|
903
913
|
onChange: composeHandler(composeEventHandlers(onChange, onDropCb)),
|
|
904
914
|
onClick: composeHandler(composeEventHandlers(onClick, onInputElementClick)),
|
|
@@ -956,7 +966,8 @@ function reducer(state, action) {
|
|
|
956
966
|
case "setFiles":
|
|
957
967
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
958
968
|
acceptedFiles: action.acceptedFiles,
|
|
959
|
-
fileRejections: action.fileRejections
|
|
969
|
+
fileRejections: action.fileRejections,
|
|
970
|
+
isDragReject: action.isDragReject
|
|
960
971
|
});
|
|
961
972
|
|
|
962
973
|
case "reset":
|
|
@@ -969,4 +980,4 @@ function reducer(state, action) {
|
|
|
969
980
|
|
|
970
981
|
function noop() {}
|
|
971
982
|
|
|
972
|
-
export { ErrorCode } from "./utils";
|
|
983
|
+
export { ErrorCode } from "./utils/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/dist/es/utils/index.js
CHANGED
|
@@ -38,14 +38,19 @@ export var ErrorCode = {
|
|
|
38
38
|
FileTooLarge: FILE_TOO_LARGE,
|
|
39
39
|
FileTooSmall: FILE_TOO_SMALL,
|
|
40
40
|
TooManyFiles: TOO_MANY_FILES
|
|
41
|
-
};
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param {string} accept
|
|
45
|
+
*/
|
|
42
46
|
|
|
43
|
-
export var getInvalidTypeRejectionErr = function getInvalidTypeRejectionErr(
|
|
44
|
-
accept =
|
|
45
|
-
var
|
|
47
|
+
export var getInvalidTypeRejectionErr = function getInvalidTypeRejectionErr() {
|
|
48
|
+
var accept = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
49
|
+
var acceptArr = accept.split(",");
|
|
50
|
+
var msg = acceptArr.length > 1 ? "one of ".concat(acceptArr.join(", ")) : acceptArr[0];
|
|
46
51
|
return {
|
|
47
52
|
code: FILE_INVALID_TYPE,
|
|
48
|
-
message: "File type must be ".concat(
|
|
53
|
+
message: "File type must be ".concat(msg)
|
|
49
54
|
};
|
|
50
55
|
};
|
|
51
56
|
export var getTooLargeRejectionErr = function getTooLargeRejectionErr(maxSize) {
|
|
@@ -63,8 +68,17 @@ export var getTooSmallRejectionErr = function getTooSmallRejectionErr(minSize) {
|
|
|
63
68
|
export var TOO_MANY_FILES_REJECTION = {
|
|
64
69
|
code: TOO_MANY_FILES,
|
|
65
70
|
message: "Too many files"
|
|
66
|
-
};
|
|
67
|
-
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Check if file is accepted.
|
|
74
|
+
*
|
|
75
|
+
* Firefox versions prior to 53 return a bogus MIME type for every file drag,
|
|
76
|
+
* so dragovers with that MIME type will always be accepted.
|
|
77
|
+
*
|
|
78
|
+
* @param {File} file
|
|
79
|
+
* @param {string} accept
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
68
82
|
|
|
69
83
|
export function fileAccepted(file, accept) {
|
|
70
84
|
var isAcceptable = file.type === "application/x-moz-file" || accepts(file, accept);
|
|
@@ -88,7 +102,7 @@ function isDefined(value) {
|
|
|
88
102
|
*
|
|
89
103
|
* @param {object} options
|
|
90
104
|
* @param {File[]} options.files
|
|
91
|
-
* @param {string
|
|
105
|
+
* @param {string} [options.accept]
|
|
92
106
|
* @param {number} [options.minSize]
|
|
93
107
|
* @param {number} [options.maxSize]
|
|
94
108
|
* @param {boolean} [options.multiple]
|
|
@@ -303,7 +317,7 @@ export function isSecurityError(v) {
|
|
|
303
317
|
*/
|
|
304
318
|
|
|
305
319
|
export function isMIMEType(v) {
|
|
306
|
-
return v === "audio/*" || v === "video/*" || v === "image/*" || v === "text/*" || /\w+\/[-+.\w]+/g.test(v);
|
|
320
|
+
return v === "audio/*" || v === "video/*" || v === "image/*" || v === "text/*" || v === "application/*" || /\w+\/[-+.\w]+/g.test(v);
|
|
307
321
|
}
|
|
308
322
|
/**
|
|
309
323
|
* Check if v is a file extension.
|