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/README.md +9 -17
- package/dist/es/index.js +37 -32
- package/dist/index.js +3 -3
- package/package.json +7 -7
- package/src/index.js +50 -33
- package/src/index.spec.js +410 -605
- package/typings/react-dropzone.d.ts +0 -1
package/README.md
CHANGED
|
@@ -230,7 +230,7 @@ dropzoneRef.open()
|
|
|
230
230
|
```js static
|
|
231
231
|
import React from 'react'
|
|
232
232
|
import Dropzone from 'react-dropzone'
|
|
233
|
-
import {act, fireEvent, render
|
|
233
|
+
import {act, fireEvent, render} from '@testing-library/react'
|
|
234
234
|
|
|
235
235
|
test('invoke onDragEnter when dragenter event occurs', async () => {
|
|
236
236
|
const file = new File([
|
|
@@ -248,25 +248,17 @@ test('invoke onDragEnter when dragenter event occurs', async () => {
|
|
|
248
248
|
)}
|
|
249
249
|
</Dropzone>
|
|
250
250
|
)
|
|
251
|
-
const { container
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
251
|
+
const { container } = render(ui)
|
|
252
|
+
|
|
253
|
+
await act(
|
|
254
|
+
() => fireEvent.dragEnter(
|
|
255
|
+
container.querySelector('div'),
|
|
256
|
+
data,
|
|
257
|
+
)
|
|
258
|
+
);
|
|
257
259
|
expect(onDragEnter).toHaveBeenCalled()
|
|
258
260
|
})
|
|
259
261
|
|
|
260
|
-
async function flushPromises(rerender, ui) {
|
|
261
|
-
await act(() => waitFor(() => rerender(ui)))
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function dispatchEvt(node, type, data) {
|
|
265
|
-
const event = new Event(type, { bubbles: true })
|
|
266
|
-
Object.assign(event, data)
|
|
267
|
-
fireEvent(node, event)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
262
|
function mockData(files) {
|
|
271
263
|
return {
|
|
272
264
|
dataTransfer: {
|
package/dist/es/index.js
CHANGED
|
@@ -102,7 +102,6 @@ Dropzone.propTypes = {
|
|
|
102
102
|
* @param {boolean} params.isDragActive Active drag is in progress
|
|
103
103
|
* @param {boolean} params.isDragAccept Dragged files are accepted
|
|
104
104
|
* @param {boolean} params.isDragReject Some dragged files are rejected
|
|
105
|
-
* @param {File[]} params.draggedFiles Files in active drag
|
|
106
105
|
* @param {File[]} params.acceptedFiles Accepted files
|
|
107
106
|
* @param {FileRejection[]} params.fileRejections Rejected files and why they were rejected
|
|
108
107
|
*/
|
|
@@ -326,29 +325,33 @@ export default Dropzone;
|
|
|
326
325
|
*/
|
|
327
326
|
|
|
328
327
|
/**
|
|
329
|
-
* An object with the current dropzone state
|
|
328
|
+
* An object with the current dropzone state.
|
|
330
329
|
*
|
|
331
330
|
* @typedef {object} DropzoneState
|
|
332
|
-
* @property {Function} getRootProps Returns the props you should apply to the root drop container you render
|
|
333
|
-
* @property {Function} getInputProps Returns the props you should apply to hidden file input you render
|
|
334
|
-
* @property {Function} open Open the native file selection dialog
|
|
335
331
|
* @property {boolean} isFocused Dropzone area is in focus
|
|
336
332
|
* @property {boolean} isFileDialogActive File dialog is opened
|
|
337
333
|
* @property {boolean} isDragActive Active drag is in progress
|
|
338
334
|
* @property {boolean} isDragAccept Dragged files are accepted
|
|
339
335
|
* @property {boolean} isDragReject Some dragged files are rejected
|
|
340
|
-
* @property {File[]} draggedFiles Files in active drag
|
|
341
336
|
* @property {File[]} acceptedFiles Accepted files
|
|
342
337
|
* @property {FileRejection[]} fileRejections Rejected files and why they were rejected
|
|
343
338
|
*/
|
|
344
339
|
|
|
340
|
+
/**
|
|
341
|
+
* An object with the dropzone methods.
|
|
342
|
+
*
|
|
343
|
+
* @typedef {object} DropzoneMethods
|
|
344
|
+
* @property {Function} getRootProps Returns the props you should apply to the root drop container you render
|
|
345
|
+
* @property {Function} getInputProps Returns the props you should apply to hidden file input you render
|
|
346
|
+
* @property {Function} open Open the native file selection dialog
|
|
347
|
+
*/
|
|
348
|
+
|
|
345
349
|
var initialState = {
|
|
346
350
|
isFocused: false,
|
|
347
351
|
isFileDialogActive: false,
|
|
348
352
|
isDragActive: false,
|
|
349
353
|
isDragAccept: false,
|
|
350
354
|
isDragReject: false,
|
|
351
|
-
draggedFiles: [],
|
|
352
355
|
acceptedFiles: [],
|
|
353
356
|
fileRejections: []
|
|
354
357
|
};
|
|
@@ -425,7 +428,7 @@ var initialState = {
|
|
|
425
428
|
* @param {dropRejectedCb} [props.onDropRejected]
|
|
426
429
|
* @param {(error: Error) => void} [props.onError]
|
|
427
430
|
*
|
|
428
|
-
* @returns {DropzoneState}
|
|
431
|
+
* @returns {DropzoneState & DropzoneMethods}
|
|
429
432
|
*/
|
|
430
433
|
|
|
431
434
|
export function useDropzone() {
|
|
@@ -477,8 +480,7 @@ export function useDropzone() {
|
|
|
477
480
|
dispatch = _useReducer2[1];
|
|
478
481
|
|
|
479
482
|
var isFocused = state.isFocused,
|
|
480
|
-
isFileDialogActive = state.isFileDialogActive
|
|
481
|
-
draggedFiles = state.draggedFiles;
|
|
483
|
+
isFileDialogActive = state.isFileDialogActive;
|
|
482
484
|
var fsAccessApiWorksRef = useRef(typeof window !== "undefined" && window.isSecureContext && useFsAccessApi && canUseFileSystemAccessAPI()); // Update file dialog active state when the window is focused on
|
|
483
485
|
|
|
484
486
|
var onWindowFocus = function onWindowFocus() {
|
|
@@ -546,13 +548,24 @@ export function useDropzone() {
|
|
|
546
548
|
dragTargetsRef.current = [].concat(_toConsumableArray(dragTargetsRef.current), [event.target]);
|
|
547
549
|
|
|
548
550
|
if (isEvtWithFiles(event)) {
|
|
549
|
-
Promise.resolve(getFilesFromEvent(event)).then(function (
|
|
551
|
+
Promise.resolve(getFilesFromEvent(event)).then(function (files) {
|
|
550
552
|
if (isPropagationStopped(event) && !noDragEventsBubbling) {
|
|
551
553
|
return;
|
|
552
554
|
}
|
|
553
555
|
|
|
556
|
+
var fileCount = files.length;
|
|
557
|
+
var isDragAccept = fileCount > 0 && allFilesAccepted({
|
|
558
|
+
files: files,
|
|
559
|
+
accept: acceptAttr,
|
|
560
|
+
minSize: minSize,
|
|
561
|
+
maxSize: maxSize,
|
|
562
|
+
multiple: multiple,
|
|
563
|
+
maxFiles: maxFiles
|
|
564
|
+
});
|
|
565
|
+
var isDragReject = fileCount > 0 && !isDragAccept;
|
|
554
566
|
dispatch({
|
|
555
|
-
|
|
567
|
+
isDragAccept: isDragAccept,
|
|
568
|
+
isDragReject: isDragReject,
|
|
556
569
|
isDragActive: true,
|
|
557
570
|
type: "setDraggedFiles"
|
|
558
571
|
});
|
|
@@ -564,7 +577,7 @@ export function useDropzone() {
|
|
|
564
577
|
return onErrCb(e);
|
|
565
578
|
});
|
|
566
579
|
}
|
|
567
|
-
}, [getFilesFromEvent, onDragEnter, onErrCb, noDragEventsBubbling]);
|
|
580
|
+
}, [getFilesFromEvent, onDragEnter, onErrCb, noDragEventsBubbling, acceptAttr, minSize, maxSize, multiple, maxFiles]);
|
|
568
581
|
var onDragOverCb = useCallback(function (event) {
|
|
569
582
|
event.preventDefault();
|
|
570
583
|
event.persist();
|
|
@@ -608,9 +621,10 @@ export function useDropzone() {
|
|
|
608
621
|
}
|
|
609
622
|
|
|
610
623
|
dispatch({
|
|
611
|
-
isDragActive: false,
|
|
612
624
|
type: "setDraggedFiles",
|
|
613
|
-
|
|
625
|
+
isDragActive: false,
|
|
626
|
+
isDragAccept: false,
|
|
627
|
+
isDragReject: false
|
|
614
628
|
});
|
|
615
629
|
|
|
616
630
|
if (isEvtWithFiles(event) && onDragLeave) {
|
|
@@ -870,19 +884,7 @@ export function useDropzone() {
|
|
|
870
884
|
return _objectSpread(_objectSpread({}, inputProps), rest);
|
|
871
885
|
};
|
|
872
886
|
}, [inputRef, accept, multiple, onDropCb, disabled]);
|
|
873
|
-
var fileCount = draggedFiles.length;
|
|
874
|
-
var isDragAccept = fileCount > 0 && allFilesAccepted({
|
|
875
|
-
files: draggedFiles,
|
|
876
|
-
accept: acceptAttr,
|
|
877
|
-
minSize: minSize,
|
|
878
|
-
maxSize: maxSize,
|
|
879
|
-
multiple: multiple,
|
|
880
|
-
maxFiles: maxFiles
|
|
881
|
-
});
|
|
882
|
-
var isDragReject = fileCount > 0 && !isDragAccept;
|
|
883
887
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
884
|
-
isDragAccept: isDragAccept,
|
|
885
|
-
isDragReject: isDragReject,
|
|
886
888
|
isFocused: isFocused && !disabled,
|
|
887
889
|
getRootProps: getRootProps,
|
|
888
890
|
getInputProps: getInputProps,
|
|
@@ -891,6 +893,11 @@ export function useDropzone() {
|
|
|
891
893
|
open: composeHandler(openFileDialog)
|
|
892
894
|
});
|
|
893
895
|
}
|
|
896
|
+
/**
|
|
897
|
+
* @param {DropzoneState} state
|
|
898
|
+
* @param {{type: string} & DropzoneState} action
|
|
899
|
+
* @returns {DropzoneState}
|
|
900
|
+
*/
|
|
894
901
|
|
|
895
902
|
function reducer(state, action) {
|
|
896
903
|
/* istanbul ignore next */
|
|
@@ -916,12 +923,10 @@ function reducer(state, action) {
|
|
|
916
923
|
});
|
|
917
924
|
|
|
918
925
|
case "setDraggedFiles":
|
|
919
|
-
/* eslint no-case-declarations: 0 */
|
|
920
|
-
var isDragActive = action.isDragActive,
|
|
921
|
-
draggedFiles = action.draggedFiles;
|
|
922
926
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
923
|
-
|
|
924
|
-
|
|
927
|
+
isDragActive: action.isDragActive,
|
|
928
|
+
isDragAccept: action.isDragAccept,
|
|
929
|
+
isDragReject: action.isDragReject
|
|
925
930
|
});
|
|
926
931
|
|
|
927
932
|
case "setFiles":
|