react-dropzone 19.1.0 → 19.2.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 +22 -0
- package/dist/index.cjs +43 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +43 -4
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/index.tsx +89 -1
- package/src/utils/index.ts +6 -3
package/README.md
CHANGED
|
@@ -297,6 +297,28 @@ For more inf check [this SO question](https://stackoverflow.com/a/23005925/22758
|
|
|
297
297
|
|
|
298
298
|
This lib is not a file uploader; as such, it does not process files or provide any way to make HTTP requests to some server; if you're looking for that, checkout [filepond](https://pqina.nl/filepond) or [uppy.io](https://uppy.io/).
|
|
299
299
|
|
|
300
|
+
### Paste to Upload
|
|
301
|
+
|
|
302
|
+
Pasting files into the dropzone is supported out of the box: when the dropzone (or a focused child, e.g. a `<textarea>`) has focus and the user pastes files with <kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>V</kbd> - for instance a screenshot copied to the clipboard - those files run through the same `accept`, size and `validator` checks and the same `onDrop`/`onDropAccepted`/`onDropRejected` callbacks as a drop. Pastes that carry no files (plain text and the like) are ignored and left untouched, so pasting into inputs keeps working.
|
|
303
|
+
|
|
304
|
+
The paste is only received when the dropzone has focus, so pair it with [`autoFocus`](https://react-dropzone.js.org) or let the user click/tab into it first. To disable paste handling, set `noPaste`:
|
|
305
|
+
|
|
306
|
+
```jsx static
|
|
307
|
+
import React from "react";
|
|
308
|
+
import {useDropzone} from "react-dropzone";
|
|
309
|
+
|
|
310
|
+
function MyDropzone() {
|
|
311
|
+
const {getRootProps, getInputProps} = useDropzone({noPaste: true});
|
|
312
|
+
|
|
313
|
+
return (
|
|
314
|
+
<div {...getRootProps()}>
|
|
315
|
+
<input {...getInputProps()} />
|
|
316
|
+
<p>Drag 'n' drop or click - pasting is disabled</p>
|
|
317
|
+
</div>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
300
322
|
### Using \<label\> as Root
|
|
301
323
|
|
|
302
324
|
If you use [\<label\>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label) as the root element, the file dialog will be opened twice; see [#1107](https://github.com/react-dropzone/react-dropzone/issues/1107) and [#1432](https://github.com/react-dropzone/react-dropzone/issues/1432) why. A `<label>` natively forwards clicks to the `<input>` it wraps, so the dialog opens once from that and once from our own click handler. To avoid this, use `noClick`:
|
package/dist/index.cjs
CHANGED
|
@@ -162,8 +162,9 @@ function isPropagationStopped(event) {
|
|
|
162
162
|
return false;
|
|
163
163
|
}
|
|
164
164
|
function isEvtWithFiles(event) {
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
const dataTransfer = event.dataTransfer ?? event.clipboardData;
|
|
166
|
+
if (!dataTransfer) return !!event.target && !!event.target.files;
|
|
167
|
+
return Array.prototype.some.call(dataTransfer.types, (type) => type === "Files" || type === "application/x-moz-file") || Array.prototype.some.call(dataTransfer.items ?? [], isKindFile);
|
|
167
168
|
}
|
|
168
169
|
function isKindFile(item) {
|
|
169
170
|
return typeof item === "object" && item !== null && item.kind === "file";
|
|
@@ -339,7 +340,7 @@ const initialState = {
|
|
|
339
340
|
* ```
|
|
340
341
|
*/
|
|
341
342
|
function useDropzone(props = {}) {
|
|
342
|
-
const { accept, disabled = false, getFilesFromEvent = file_selector.fromEvent, maxSize = Number.POSITIVE_INFINITY, minSize = 0, multiple = true, maxFiles = 0, onDragEnter, onDragLeave, onDragOver, onDrop, onDropAccepted, onDropRejected, onFileDialogCancel, onFileDialogOpen, useFsAccessApi = false, autoFocus = false, preventDropOnDocument = true, noClick = false, noKeyboard = false, noDrag = false, noDragEventsBubbling = false, onError, validator, getErrorMessage } = props;
|
|
343
|
+
const { accept, disabled = false, getFilesFromEvent = file_selector.fromEvent, maxSize = Number.POSITIVE_INFINITY, minSize = 0, multiple = true, maxFiles = 0, onDragEnter, onDragLeave, onDragOver, onDrop, onDropAccepted, onDropRejected, onFileDialogCancel, onFileDialogOpen, useFsAccessApi = false, autoFocus = false, preventDropOnDocument = true, noClick = false, noKeyboard = false, noDrag = false, noDragEventsBubbling = false, noPaste = false, onError, validator, getErrorMessage } = props;
|
|
343
344
|
const acceptAttr = (0, react.useMemo)(() => acceptPropAsAcceptAttr(accept), [accept]);
|
|
344
345
|
const inputAcceptAttr = (0, react.useMemo)(() => acceptPropAsAcceptAttr(accept, { omitWildcardMimeTypesWithExtensions: true }), [accept]);
|
|
345
346
|
const pickerTypes = (0, react.useMemo)(() => pickerOptionsFromAccept(accept), [accept]);
|
|
@@ -349,6 +350,8 @@ function useDropzone(props = {}) {
|
|
|
349
350
|
const inputRef = (0, react.useRef)(null);
|
|
350
351
|
const [state, dispatch] = (0, react.useReducer)(reducer, initialState);
|
|
351
352
|
const { isFocused, isFileDialogActive } = state;
|
|
353
|
+
const isFileDialogActiveRef = (0, react.useRef)(isFileDialogActive);
|
|
354
|
+
isFileDialogActiveRef.current = isFileDialogActive;
|
|
352
355
|
const processingAbortRef = (0, react.useRef)(null);
|
|
353
356
|
const beginProcessing = (0, react.useCallback)(() => {
|
|
354
357
|
processingAbortRef.current?.abort();
|
|
@@ -465,6 +468,7 @@ function useDropzone(props = {}) {
|
|
|
465
468
|
event.preventDefault();
|
|
466
469
|
event.persist?.();
|
|
467
470
|
stopPropagation(event);
|
|
471
|
+
if (isFileDialogActiveRef.current) return;
|
|
468
472
|
dragTargetsRef.current = [...dragTargetsRef.current, event.target];
|
|
469
473
|
if (isEvtWithFiles(event)) Promise.resolve(getFilesFromEvent(event)).then((files) => {
|
|
470
474
|
if (isPropagationStopped(event) && !noDragEventsBubbling) return;
|
|
@@ -502,6 +506,7 @@ function useDropzone(props = {}) {
|
|
|
502
506
|
event.preventDefault();
|
|
503
507
|
event.persist?.();
|
|
504
508
|
stopPropagation(event);
|
|
509
|
+
if (isFileDialogActiveRef.current) return false;
|
|
505
510
|
const hasFiles = isEvtWithFiles(event);
|
|
506
511
|
if (hasFiles && event.dataTransfer) try {
|
|
507
512
|
event.dataTransfer.dropEffect = "copy";
|
|
@@ -617,6 +622,7 @@ function useDropzone(props = {}) {
|
|
|
617
622
|
event.persist?.();
|
|
618
623
|
stopPropagation(event);
|
|
619
624
|
dragTargetsRef.current = [];
|
|
625
|
+
if (isFileDialogActiveRef.current && event.dataTransfer) return;
|
|
620
626
|
dispatch({ type: "reset" });
|
|
621
627
|
if (isEvtWithFiles(event)) {
|
|
622
628
|
const signal = beginProcessing();
|
|
@@ -642,6 +648,33 @@ function useDropzone(props = {}) {
|
|
|
642
648
|
beginProcessing,
|
|
643
649
|
endProcessing
|
|
644
650
|
]);
|
|
651
|
+
const onPasteCb = (0, react.useCallback)((event) => {
|
|
652
|
+
if (!isEvtWithFiles(event)) return;
|
|
653
|
+
event.preventDefault();
|
|
654
|
+
event.persist?.();
|
|
655
|
+
stopPropagation(event);
|
|
656
|
+
const signal = beginProcessing();
|
|
657
|
+
Promise.resolve(getFilesFromEvent(event)).then((files) => {
|
|
658
|
+
if (signal.aborted) return;
|
|
659
|
+
if (isPropagationStopped(event) && !noDragEventsBubbling) {
|
|
660
|
+
endProcessing(signal);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
return setFiles(files, event, signal);
|
|
664
|
+
}).catch((e) => {
|
|
665
|
+
if (!signal.aborted) {
|
|
666
|
+
endProcessing(signal);
|
|
667
|
+
onErrCb(e);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
}, [
|
|
671
|
+
getFilesFromEvent,
|
|
672
|
+
setFiles,
|
|
673
|
+
onErrCb,
|
|
674
|
+
noDragEventsBubbling,
|
|
675
|
+
beginProcessing,
|
|
676
|
+
endProcessing
|
|
677
|
+
]);
|
|
645
678
|
const openFileDialog = (0, react.useCallback)(() => {
|
|
646
679
|
if (fsAccessApiWorksRef.current) {
|
|
647
680
|
dispatch({ type: "openDialog" });
|
|
@@ -718,10 +751,13 @@ function useDropzone(props = {}) {
|
|
|
718
751
|
const composeDragHandler = (fn) => {
|
|
719
752
|
return noDrag ? null : composeHandler(fn);
|
|
720
753
|
};
|
|
754
|
+
const composePasteHandler = (fn) => {
|
|
755
|
+
return noPaste ? null : composeHandler(fn);
|
|
756
|
+
};
|
|
721
757
|
const stopPropagation = (event) => {
|
|
722
758
|
if (noDragEventsBubbling) event.stopPropagation();
|
|
723
759
|
};
|
|
724
|
-
const getRootProps = (0, react.useMemo)(() => ({ refKey = "ref", role, onKeyDown, onFocus, onBlur, onClick, onDragEnter, onDragOver, onDragLeave, onDrop, ...rest } = {}) => ({
|
|
760
|
+
const getRootProps = (0, react.useMemo)(() => ({ refKey = "ref", role, onKeyDown, onFocus, onBlur, onClick, onDragEnter, onDragOver, onDragLeave, onDrop, onPaste, ...rest } = {}) => ({
|
|
725
761
|
onKeyDown: composeKeyboardHandler(composeEventHandlers(onKeyDown, onKeyDownCb)),
|
|
726
762
|
onFocus: composeKeyboardHandler(composeEventHandlers(onFocus, onFocusCb)),
|
|
727
763
|
onBlur: composeKeyboardHandler(composeEventHandlers(onBlur, onBlurCb)),
|
|
@@ -730,6 +766,7 @@ function useDropzone(props = {}) {
|
|
|
730
766
|
onDragOver: composeDragHandler(composeEventHandlers(onDragOver, onDragOverCb)),
|
|
731
767
|
onDragLeave: composeDragHandler(composeEventHandlers(onDragLeave, onDragLeaveCb)),
|
|
732
768
|
onDrop: composeDragHandler(composeEventHandlers(onDrop, onDropCb)),
|
|
769
|
+
onPaste: composePasteHandler(composeEventHandlers(onPaste, onPasteCb)),
|
|
733
770
|
role: typeof role === "string" && role !== "" ? role : "presentation",
|
|
734
771
|
[refKey]: rootRef,
|
|
735
772
|
...!disabled && !noKeyboard ? { tabIndex: 0 } : {},
|
|
@@ -745,8 +782,10 @@ function useDropzone(props = {}) {
|
|
|
745
782
|
onDragOverCb,
|
|
746
783
|
onDragLeaveCb,
|
|
747
784
|
onDropCb,
|
|
785
|
+
onPasteCb,
|
|
748
786
|
noKeyboard,
|
|
749
787
|
noDrag,
|
|
788
|
+
noPaste,
|
|
750
789
|
disabled
|
|
751
790
|
]);
|
|
752
791
|
const onInputElementClick = (0, react.useCallback)((event) => {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["attrAccept","fromEvent"],"sources":["../src/utils/index.ts","../src/index.tsx"],"sourcesContent":["import attrAccept from \"attr-accept\";\n\n// attr-accept ships as a CommonJS module (`module.exports = { __esModule: true, default: fn }`).\n// Bundler interop surfaces its default export inconsistently — as the function under Node/Vitest,\n// but as `{ default: fn }` in some browser bundles. Normalize to the function.\nconst accepts =\n typeof attrAccept === \"function\" ? attrAccept : (attrAccept as unknown as {default: typeof attrAccept}).default;\n\n/**\n * A map of accepted MIME types to file extensions, as passed to the `accept` prop.\n */\nexport interface Accept {\n [key: string]: readonly string[];\n}\n\n/**\n * A file rejection error.\n */\nexport interface FileError {\n message: string;\n code: ErrorCode | string;\n}\n\n/**\n * What a custom `validator` returns: a single error, a list of errors, or `null` when the file\n * passes. A validator may return the result directly (synchronous) or wrapped in a `Promise`\n * (asynchronous, e.g. reading image dimensions or calling an external service).\n */\nexport type ValidatorResult = FileError | readonly FileError[] | null;\n\n// Error codes\nexport const FILE_INVALID_TYPE = \"file-invalid-type\";\nexport const FILE_TOO_LARGE = \"file-too-large\";\nexport const FILE_TOO_SMALL = \"file-too-small\";\nexport const TOO_MANY_FILES = \"too-many-files\";\n\nexport enum ErrorCode {\n FileInvalidType = \"file-invalid-type\",\n FileTooLarge = \"file-too-large\",\n FileTooSmall = \"file-too-small\",\n TooManyFiles = \"too-many-files\"\n}\n\nexport function getInvalidTypeRejectionErr(accept: string = \"\"): FileError {\n const acceptArr = accept.split(\",\");\n const msg = acceptArr.length > 1 ? `one of ${acceptArr.join(\", \")}` : acceptArr[0];\n\n return {\n code: FILE_INVALID_TYPE,\n message: `File type must be ${msg}`\n };\n}\n\nconst FILE_SIZE_UNITS = [\"KB\", \"MB\", \"GB\", \"TB\", \"PB\"];\n\n/**\n * Format a byte count into a human-readable string, e.g. `1111` -> `1.08 KB`.\n * Values below 1 KB are kept in bytes to preserve the singular/plural wording.\n */\nfunction formatBytes(bytes: number): string {\n if (bytes < 1024) {\n return `${bytes} ${bytes === 1 ? \"byte\" : \"bytes\"}`;\n }\n\n let size = bytes / 1024;\n let unitIndex = 0;\n while (size >= 1024 && unitIndex < FILE_SIZE_UNITS.length - 1) {\n size /= 1024;\n unitIndex++;\n }\n\n // Round to 2 decimals, then drop trailing zeros (1.00 -> 1, 1.50 -> 1.5).\n return `${Number(size.toFixed(2))} ${FILE_SIZE_UNITS[unitIndex]}`;\n}\n\nexport function getTooLargeRejectionErr(maxSize: number): FileError {\n return {\n code: FILE_TOO_LARGE,\n message: `File is larger than ${formatBytes(maxSize)}`\n };\n}\n\nexport function getTooSmallRejectionErr(minSize: number): FileError {\n return {\n code: FILE_TOO_SMALL,\n message: `File is smaller than ${formatBytes(minSize)}`\n };\n}\n\nexport const TOO_MANY_FILES_REJECTION: FileError = {\n code: TOO_MANY_FILES,\n message: \"Too many files\"\n};\n\n/**\n * Check if the given file is a DataTransferItem with an empty type.\n *\n * During drag events, browsers may return DataTransferItem objects instead of File objects.\n * Some browsers (e.g., Chrome) return an empty MIME type for certain file types (like .md files)\n * on DataTransferItem during drag events, even though the type is correctly set during drop.\n */\nexport function isDataTransferItemWithEmptyType(file: File | DataTransferItem): boolean {\n return file.type === \"\" && typeof (file as DataTransferItem).getAsFile === \"function\";\n}\n\n/**\n * Check if file is accepted.\n *\n * Firefox versions prior to 53 return a bogus MIME type for every file drag,\n * so dragovers with that MIME type will always be accepted.\n *\n * Chrome/other browsers may return an empty MIME type for files during drag events,\n * so we accept those as well (we'll validate properly on drop).\n */\nexport function fileAccepted(file: File, accept?: string): [boolean, FileError | null] {\n const isAcceptable =\n file.type === \"application/x-moz-file\" || accepts(file, accept ?? \"\") || isDataTransferItemWithEmptyType(file);\n return [isAcceptable, isAcceptable ? null : getInvalidTypeRejectionErr(accept)];\n}\n\nexport function fileMatchSize(\n file: {size?: number | null},\n minSize?: number,\n maxSize?: number\n): [boolean, FileError | null] {\n if (isDefined(file.size)) {\n if (isDefined(minSize) && isDefined(maxSize)) {\n if (file.size > maxSize) return [false, getTooLargeRejectionErr(maxSize)];\n if (file.size < minSize) return [false, getTooSmallRejectionErr(minSize)];\n } else if (isDefined(minSize) && file.size < minSize) {\n return [false, getTooSmallRejectionErr(minSize)];\n } else if (isDefined(maxSize) && file.size > maxSize) {\n return [false, getTooLargeRejectionErr(maxSize)];\n }\n }\n return [true, null];\n}\n\nfunction isDefined<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n}\n\n/**\n * Check if a value is thenable (Promise-like), used to tell a synchronous validator result from an\n * asynchronous one.\n */\nexport function isThenable(value: unknown): value is PromiseLike<unknown> {\n return value != null && typeof (value as {then?: unknown}).then === \"function\";\n}\n\nexport function allFilesAccepted({\n files,\n accept,\n minSize,\n maxSize,\n multiple,\n maxFiles = 0,\n validator\n}: {\n files: File[];\n accept?: string;\n minSize?: number;\n maxSize?: number;\n multiple?: boolean;\n maxFiles?: number;\n validator?: (file: File) => FileError | readonly FileError[] | null;\n}): boolean {\n if ((!multiple && files.length > 1) || (multiple && maxFiles >= 1 && files.length > maxFiles)) {\n return false;\n }\n\n return files.every(file => {\n const [accepted] = fileAccepted(file, accept);\n const [sizeMatch] = fileMatchSize(file, minSize, maxSize);\n const customErrors = validator ? validator(file) : null;\n return accepted && sizeMatch && !customErrors;\n });\n}\n\n/**\n * The outcome of the drag-time acceptance check.\n *\n * - `accept` - every file passes the checks we can evaluate during a drag.\n * - `reject` - at least one file confidently fails a check we can fully evaluate during a\n * drag (the file count, or a non-empty MIME type that doesn't match `accept`).\n * - `unknown` - nothing confidently fails, but the outcome can't be confirmed until drop,\n * because a custom `validator` is configured and can't be evaluated yet.\n */\nexport type DragVerdict = \"accept\" | \"reject\" | \"unknown\";\n\n/**\n * Classify a set of dragged files for the `isDragAccept`/`isDragReject`/`isDragUnknown` states.\n *\n * During `dragenter`/`dragover` the browser only exposes `DataTransferItem`s, which carry a MIME\n * `type` but no file name, extension or size (see https://html.spec.whatwg.org/multipage/dnd.html#dndevents).\n * So the drag-time check is deliberately optimistic about anything it can't see:\n *\n * - The custom `validator` is **never** run here. It is typed `(file: File) => ...` and users\n * routinely read `file.name`/`file.size`, which are `undefined` on a `DataTransferItem` - running\n * it would throw and abort the whole drag handler (leaving `isDragActive` stuck at `false`).\n * See https://github.com/react-dropzone/react-dropzone/issues/1408\n * - When a `validator` is configured we therefore can't promise the files are acceptable, so the\n * verdict is `unknown` rather than a misleading `reject` (or a premature `accept`).\n * See https://github.com/react-dropzone/react-dropzone/issues/1244\n *\n * The full check (including the `validator`) still runs on drop in {@link fileAccepted}/`setFiles`.\n */\nexport function getDragVerdict({\n files,\n accept,\n minSize,\n maxSize,\n multiple,\n maxFiles = 0,\n validator\n}: {\n files: Array<File | DataTransferItem>;\n accept?: string;\n minSize?: number;\n maxSize?: number;\n multiple?: boolean;\n maxFiles?: number;\n // The validator is never invoked here (see the note above), so its async variant is accepted\n // purely so the same `validator` prop is assignable during a drag.\n validator?: (file: File) => ValidatorResult | Promise<ValidatorResult>;\n}): DragVerdict {\n // The file count is knowable during a drag, so an over-the-limit selection is a confident reject.\n if ((!multiple && files.length > 1) || (multiple && maxFiles >= 1 && files.length > maxFiles)) {\n return \"reject\";\n }\n\n const confidentlyRejected = files.some(file => {\n const [accepted] = fileAccepted(file as File, accept);\n const [sizeMatch] = fileMatchSize(file as File, minSize, maxSize);\n return !accepted || !sizeMatch;\n });\n if (confidentlyRejected) {\n return \"reject\";\n }\n\n // Built-in checks pass. A custom validator can only ever add rejections on drop, never rescue\n // one - so with a validator present the drag outcome is unknown until we have real Files.\n return validator ? \"unknown\" : \"accept\";\n}\n\n// React's synthetic events has event.isPropagationStopped,\n// but to remain compatibility with other libs (Preact) fall back\n// to check event.cancelBubble\nexport function isPropagationStopped(event: any): boolean {\n if (typeof event.isPropagationStopped === \"function\") {\n return event.isPropagationStopped();\n } else if (typeof event.cancelBubble !== \"undefined\") {\n return event.cancelBubble;\n }\n return false;\n}\n\nexport function isEvtWithFiles(event: any): boolean {\n if (!event.dataTransfer) {\n return !!event.target && !!event.target.files;\n }\n // https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types\n // https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types#file\n // Some Chromium drags omit \"Files\" from types (e.g. reporting only [\"text/plain\"])\n // while still exposing a kind: \"file\" entry in items - the same signal file-selector\n // uses to extract the files. Accept either so detection stays consistent. See #1409.\n return (\n Array.prototype.some.call(\n event.dataTransfer.types,\n (type: string) => type === \"Files\" || type === \"application/x-moz-file\"\n ) || Array.prototype.some.call(event.dataTransfer.items ?? [], isKindFile)\n );\n}\n\nexport function isKindFile(item: any): boolean {\n return typeof item === \"object\" && item !== null && item.kind === \"file\";\n}\n\n// allow the entire document to be a drag target\nexport function onDocumentDragOver(event: Event): void {\n event.preventDefault();\n}\n\nfunction isIe(userAgent: string): boolean {\n return userAgent.indexOf(\"MSIE\") !== -1 || userAgent.indexOf(\"Trident/\") !== -1;\n}\n\nfunction isEdge(userAgent: string): boolean {\n return userAgent.indexOf(\"Edge/\") !== -1;\n}\n\nexport function isIeOrEdge(userAgent: string = window.navigator.userAgent): boolean {\n return isIe(userAgent) || isEdge(userAgent);\n}\n\n/**\n * This is intended to be used to compose event handlers.\n * They are executed in order until one of them calls `event.isPropagationStopped()`.\n * Note that the check is done on the first invoke too,\n * meaning that if propagation was stopped before invoking the fns,\n * no handlers will be executed.\n */\nexport function composeEventHandlers(\n ...fns: Array<((event: any, ...args: any[]) => void) | null | undefined>\n): (event: any, ...args: any[]) => boolean {\n return (event: any, ...args: any[]) =>\n fns.some(fn => {\n if (!isPropagationStopped(event) && fn) {\n fn(event, ...args);\n }\n return isPropagationStopped(event);\n });\n}\n\n/**\n * canUseFileSystemAccessAPI checks if the File System Access API is supported by the browser.\n */\nexport function canUseFileSystemAccessAPI(): boolean {\n return \"showOpenFilePicker\" in window;\n}\n\n/**\n * Convert the `{accept}` dropzone prop to the `{types}` option for showOpenFilePicker.\n */\nexport function pickerOptionsFromAccept(accept?: Accept): Array<{description: string; accept: Accept}> | undefined {\n if (isDefined(accept)) {\n const acceptForPicker = Object.entries(accept)\n .filter(([mimeType, ext]) => {\n let ok = true;\n\n if (!isMIMEType(mimeType)) {\n console.warn(\n `Skipped \"${mimeType}\" because it is not a valid MIME type. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for a list of valid MIME types.`\n );\n ok = false;\n }\n\n if (!Array.isArray(ext) || !ext.every(isExt)) {\n console.warn(`Skipped \"${mimeType}\" because an invalid file extension was provided.`);\n ok = false;\n }\n\n return ok;\n })\n .reduce<Accept>((agg, [mimeType, ext]) => {\n agg[mimeType] = ext;\n return agg;\n }, {});\n return [\n {\n // description is required due to https://crbug.com/1264708\n description: \"Files\",\n accept: acceptForPicker\n }\n ];\n }\n return undefined;\n}\n\n/**\n * Convert the `{accept}` dropzone prop to a comma-separated accept attribute string.\n *\n * When `omitWildcardMimeTypesWithExtensions` is set, a wildcard MIME type (e.g. `image/*`)\n * that is paired with explicit extensions is dropped in favour of those extensions. The\n * accept attribute is an OR list, so leaving `image/*` in would make both the native file\n * picker and the drop-time validator accept ANY file of that type, ignoring the extension\n * restriction. The drag-time `isDragAccept` check keeps the wildcard because file names\n * (and therefore extensions) aren't readable during a drag.\n *\n * See https://github.com/react-dropzone/react-dropzone/issues/1220\n */\nexport function acceptPropAsAcceptAttr(\n accept?: Accept,\n {omitWildcardMimeTypesWithExtensions = false}: {omitWildcardMimeTypesWithExtensions?: boolean} = {}\n): string | undefined {\n if (isDefined(accept)) {\n return (\n Object.entries(accept)\n .reduce<string[]>((a, [mimeType, ext]) => {\n if (omitWildcardMimeTypesWithExtensions && isMIMETypeWildcard(mimeType) && ext.some(isExt)) {\n a.push(...ext);\n } else {\n a.push(mimeType, ...ext);\n }\n return a;\n }, [])\n // Silently discard invalid entries as pickerOptionsFromAccept warns about these\n .filter(v => isMIMEType(v) || isExt(v))\n .join(\",\")\n );\n }\n\n return undefined;\n}\n\n/**\n * Check if v is an exception caused by aborting a request (e.g window.showOpenFilePicker()).\n */\nexport function isAbort(v: any): boolean {\n return v instanceof DOMException && (v.name === \"AbortError\" || v.code === v.ABORT_ERR);\n}\n\n/**\n * Check if v is a security error.\n */\nexport function isSecurityError(v: any): boolean {\n return v instanceof DOMException && (v.name === \"SecurityError\" || v.code === v.SECURITY_ERR);\n}\n\n/**\n * Check if v is a \"not allowed\" error.\n *\n * Some browsers/configurations block `window.showOpenFilePicker()` outright and reject with a\n * `NotAllowedError` instead of showing the picker (e.g. Microsoft Edge for Business, or other\n * restrictive enterprise/security policies). We treat this like a security error and fall back\n * to the native `<input>`. See https://github.com/react-dropzone/react-dropzone/issues/1429\n */\nexport function isNotAllowedError(v: any): boolean {\n return v instanceof DOMException && v.name === \"NotAllowedError\";\n}\n\n/**\n * Check if v is a MIME type string.\n */\nexport function isMIMEType(v: string): boolean {\n return (\n v === \"audio/*\" ||\n v === \"video/*\" ||\n v === \"image/*\" ||\n v === \"text/*\" ||\n v === \"application/*\" ||\n /\\w+\\/[-+.\\w]+/g.test(v)\n );\n}\n\n/**\n * Check if v is a wildcard MIME type (e.g. `image/*`).\n */\nexport function isMIMETypeWildcard(v: string): boolean {\n return v.endsWith(\"/*\");\n}\n\n/**\n * Check if v is a file extension.\n */\nexport function isExt(v: string): boolean {\n return /^.*\\.[\\w]+$/.test(v);\n}\n","import {fromEvent} from \"file-selector\";\nimport type {FileWithPath} from \"file-selector\";\nimport type * as React from \"react\";\nimport {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef} from \"react\";\nimport {\n acceptPropAsAcceptAttr,\n canUseFileSystemAccessAPI,\n composeEventHandlers,\n ErrorCode,\n fileAccepted,\n fileMatchSize,\n getDragVerdict,\n isAbort,\n isEvtWithFiles,\n isIeOrEdge,\n isNotAllowedError,\n isThenable,\n isPropagationStopped,\n isSecurityError,\n onDocumentDragOver,\n pickerOptionsFromAccept,\n TOO_MANY_FILES_REJECTION\n} from \"./utils\";\nimport type {Accept, FileError, ValidatorResult} from \"./utils\";\n\nexport type {Accept, FileError, FileWithPath, ValidatorResult};\nexport {ErrorCode};\n\nexport interface DropzoneProps extends DropzoneOptions {\n children?: (state: DropzoneState) => React.ReactElement;\n}\n\nexport interface FileRejection {\n file: FileWithPath;\n errors: readonly FileError[];\n}\n\ntype SharedProps = \"multiple\" | \"onDragEnter\" | \"onDragOver\" | \"onDragLeave\";\n\nexport type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, SharedProps> & {\n accept?: Accept;\n minSize?: number;\n maxSize?: number;\n maxFiles?: number;\n preventDropOnDocument?: boolean;\n noClick?: boolean;\n noKeyboard?: boolean;\n noDrag?: boolean;\n noDragEventsBubbling?: boolean;\n disabled?: boolean;\n onDrop?: <T extends File>(acceptedFiles: T[], fileRejections: FileRejection[], event: DropEvent) => void;\n onDropAccepted?: <T extends File>(files: T[], event: DropEvent) => void;\n onDropRejected?: (fileRejections: FileRejection[], event: DropEvent) => void;\n getFilesFromEvent?: (event: DropEvent | Array<FileSystemFileHandle>) => Promise<Array<File | DataTransferItem>>;\n onFileDialogCancel?: () => void;\n onFileDialogOpen?: () => void;\n onError?: (err: Error) => void;\n /**\n * Custom validation, run once per file on drop/selection. Return `null` to accept the file, or a\n * {@link FileError} (or array of them) to reject it. May be `async` (return a `Promise`) to support\n * checks that can't run synchronously - e.g. reading image dimensions, inspecting file contents,\n * or calling an external service. While an async validator is pending, {@link DropzoneState.isProcessing}\n * is `true`, and `onDrop`/`onDropAccepted`/`onDropRejected` fire only once it settles. If the\n * validator throws or rejects, `onError` is called and the drop is discarded.\n *\n * Note: the validator never runs during a drag (a `DataTransferItem` has no name/size), so a\n * validator-configured dropzone is `isDragUnknown` until drop.\n */\n validator?: <T extends File>(file: T) => ValidatorResult | Promise<ValidatorResult>;\n /**\n * Override the message of any rejection error (built-in or custom). Called once per error;\n * receives the error and the file it belongs to and returns the message to use. Return\n * `error.message` for codes you don't want to change. Useful for localizing error messages.\n */\n getErrorMessage?: (error: FileError, file: File) => string;\n useFsAccessApi?: boolean;\n autoFocus?: boolean;\n};\n\nexport type DropEvent = React.DragEvent<HTMLElement> | React.ChangeEvent<HTMLInputElement> | DragEvent | Event;\n\nexport interface DropzoneRef {\n open: () => void;\n}\n\nexport type DropzoneState = DropzoneRef & {\n isFocused: boolean;\n isDragActive: boolean;\n isDragAccept: boolean;\n isDragReject: boolean;\n isDragUnknown: boolean;\n isDragGlobal: boolean;\n isFileDialogActive: boolean;\n /**\n * `true` while a drop/selection is being processed asynchronously - i.e. while `getFilesFromEvent`\n * reads the files and/or an async {@link DropzoneOptions.validator} runs. Spans the whole pipeline,\n * from when files start being read until validation settles. When both are synchronous (the default\n * `getFilesFromEvent` with no/async-free validator) the work resolves within a microtask, so it's\n * only observable for genuinely async work. Use it to show a spinner or disable UI while processing.\n */\n isProcessing: boolean;\n acceptedFiles: readonly FileWithPath[];\n fileRejections: readonly FileRejection[];\n rootRef: React.RefObject<HTMLElement>;\n inputRef: React.RefObject<HTMLInputElement>;\n getRootProps: <T extends DropzoneRootProps>(props?: T) => T;\n getInputProps: <T extends DropzoneInputProps>(props?: T) => T;\n};\n\nexport interface DropzoneRootProps extends React.HTMLAttributes<HTMLElement> {\n refKey?: string;\n [key: string]: any;\n}\n\nexport interface DropzoneInputProps extends React.InputHTMLAttributes<HTMLInputElement> {\n refKey?: string;\n}\n\n/**\n * Convenience wrapper component for the `useDropzone` hook\n *\n * ```jsx\n * <Dropzone>\n * {({getRootProps, getInputProps}) => (\n * <div {...getRootProps()}>\n * <input {...getInputProps()} />\n * <p>Drag 'n' drop some files here, or click to select files</p>\n * </div>\n * )}\n * </Dropzone>\n * ```\n */\nconst Dropzone: React.ForwardRefExoticComponent<DropzoneProps & React.RefAttributes<DropzoneRef>> = forwardRef<\n DropzoneRef,\n DropzoneProps\n>(({children, ...params}, ref) => {\n const {open, ...props} = useDropzone(params);\n\n useImperativeHandle(ref, () => ({open}), [open]);\n\n return <>{children?.({...props, open})}</>;\n});\n\nDropzone.displayName = \"Dropzone\";\n\nexport default Dropzone;\n\ninterface DropzoneInternalState {\n isFocused: boolean;\n isFileDialogActive: boolean;\n isDragActive: boolean;\n isDragAccept: boolean;\n isDragReject: boolean;\n isDragUnknown: boolean;\n isDragGlobal: boolean;\n isProcessing: boolean;\n acceptedFiles: FileWithPath[];\n fileRejections: FileRejection[];\n}\n\n/**\n * The per-file outcome of the built-in checks plus the (resolved) custom validator, assembled in\n * setFiles before the accepted/rejected split.\n */\ninterface PerFileResult {\n file: FileWithPath;\n accepted: boolean;\n acceptError: FileError | null;\n sizeMatch: boolean;\n sizeError: FileError | null;\n customErrors: ValidatorResult;\n}\n\nconst initialState: DropzoneInternalState = {\n isFocused: false,\n isFileDialogActive: false,\n isDragActive: false,\n isDragAccept: false,\n isDragReject: false,\n isDragUnknown: false,\n isDragGlobal: false,\n isProcessing: false,\n acceptedFiles: [],\n fileRejections: []\n};\n\n/**\n * A React hook that creates a drag 'n' drop area.\n *\n * ```jsx\n * function MyDropzone(props) {\n * const {getRootProps, getInputProps} = useDropzone({\n * onDrop: acceptedFiles => {\n * // do something with the File objects, e.g. upload to some server\n * }\n * });\n * return (\n * <div {...getRootProps()}>\n * <input {...getInputProps()} />\n * <p>Drag and drop some files here, or click to select files</p>\n * </div>\n * )\n * }\n * ```\n */\nexport function useDropzone(props: DropzoneOptions = {}): DropzoneState {\n const {\n accept,\n disabled = false,\n getFilesFromEvent = fromEvent,\n maxSize = Number.POSITIVE_INFINITY,\n minSize = 0,\n multiple = true,\n maxFiles = 0,\n onDragEnter,\n onDragLeave,\n onDragOver,\n onDrop,\n onDropAccepted,\n onDropRejected,\n onFileDialogCancel,\n onFileDialogOpen,\n useFsAccessApi = false,\n autoFocus = false,\n preventDropOnDocument = true,\n noClick = false,\n noKeyboard = false,\n noDrag = false,\n noDragEventsBubbling = false,\n onError,\n validator,\n getErrorMessage\n } = props;\n\n // `acceptAttr` keeps wildcard MIME types (e.g. `image/*`) so the drag-time\n // `isDragAccept`/`isDragReject` check can react to a file's MIME type - file names\n // (hence extensions) aren't readable during a drag.\n const acceptAttr = useMemo(() => acceptPropAsAcceptAttr(accept), [accept]);\n // `inputAcceptAttr` drops a wildcard MIME type when it is paired with extensions, so the\n // native picker and drop-time validation enforce the extensions instead of accepting any\n // file of that type. See https://github.com/react-dropzone/react-dropzone/issues/1220\n const inputAcceptAttr = useMemo(\n () =>\n acceptPropAsAcceptAttr(accept, {\n omitWildcardMimeTypesWithExtensions: true\n }),\n [accept]\n );\n const pickerTypes = useMemo(() => pickerOptionsFromAccept(accept), [accept]);\n\n const onFileDialogOpenCb = useMemo<(...args: any[]) => void>(\n () => (typeof onFileDialogOpen === \"function\" ? onFileDialogOpen : noop),\n [onFileDialogOpen]\n );\n const onFileDialogCancelCb = useMemo<(...args: any[]) => void>(\n () => (typeof onFileDialogCancel === \"function\" ? onFileDialogCancel : noop),\n [onFileDialogCancel]\n );\n\n const rootRef = useRef<HTMLElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n\n const [state, dispatch] = useReducer(reducer, initialState);\n const {isFocused, isFileDialogActive} = state;\n\n // Tracks the in-flight processing run - reading files (getFilesFromEvent) plus running an async\n // validator. A newer drop/selection aborts the previous run so slow async work can't resolve late\n // and clobber the state with stale results.\n const processingAbortRef = useRef<AbortController | null>(null);\n\n // Begin a processing run: supersede any run still in flight and flip {isProcessing} on. Returns\n // the run's AbortSignal, which downstream async steps check to bail if a newer run took over.\n const beginProcessing = useCallback(() => {\n processingAbortRef.current?.abort();\n const controller = new AbortController();\n processingAbortRef.current = controller;\n dispatch({type: \"setProcessing\", isProcessing: true});\n return controller.signal;\n }, []);\n\n // End a processing run by clearing {isProcessing} - but only if this run is still the active one.\n // A superseded run (signal aborted) leaves the flag to the run that replaced it.\n const endProcessing = useCallback((signal: AbortSignal) => {\n if (!signal.aborted) {\n dispatch({type: \"setProcessing\", isProcessing: false});\n }\n }, []);\n\n const fsAccessApiWorksRef = useRef(\n typeof window !== \"undefined\" && window.isSecureContext && useFsAccessApi && canUseFileSystemAccessAPI()\n );\n\n // Update file dialog active state when the window is focused on\n const onWindowFocus = () => {\n // Execute the timeout only if the file dialog is opened in the browser\n if (!fsAccessApiWorksRef.current && isFileDialogActive) {\n setTimeout(() => {\n if (inputRef.current) {\n const {files} = inputRef.current;\n\n if (!files?.length) {\n dispatch({type: \"closeDialog\"});\n onFileDialogCancelCb();\n }\n }\n }, 300);\n }\n };\n useEffect(() => {\n window.addEventListener(\"focus\", onWindowFocus, false);\n return () => {\n window.removeEventListener(\"focus\", onWindowFocus, false);\n };\n }, [inputRef, isFileDialogActive, onFileDialogCancelCb, fsAccessApiWorksRef]);\n\n const dragTargetsRef = useRef<EventTarget[]>([]);\n const globalDragTargetsRef = useRef<EventTarget[]>([]);\n const onDocumentDrop = (event: DragEvent) => {\n // This is a document-level, bubble-phase listener, so it runs *after* the event has already\n // bubbled through the dropzone root. If the drop landed inside the root and the instance's own\n // onDrop handler already prevented the default, there's nothing left to do.\n //\n // We must NOT bail out on `contains()` alone: when the dropzone is `disabled` or has `noDrag`,\n // the root has no onDrop handler, so nothing prevents the browser's default action and the file\n // is opened in the tab. Falling through to `preventDefault()` here keeps that from happening.\n // See https://github.com/react-dropzone/react-dropzone/issues/1362\n if (rootRef.current && event.target && rootRef.current.contains(event.target as Node) && event.defaultPrevented) {\n return;\n }\n event.preventDefault();\n dragTargetsRef.current = [];\n };\n\n useEffect(() => {\n if (preventDropOnDocument) {\n document.addEventListener(\"dragover\", onDocumentDragOver, false);\n document.addEventListener(\"drop\", onDocumentDrop, false);\n }\n\n return () => {\n if (preventDropOnDocument) {\n document.removeEventListener(\"dragover\", onDocumentDragOver);\n document.removeEventListener(\"drop\", onDocumentDrop);\n }\n };\n }, [rootRef, preventDropOnDocument]);\n\n // Track global drag state for document-level drag events\n useEffect(() => {\n const onDocumentDragEnter = (event: DragEvent) => {\n if (event.target) {\n globalDragTargetsRef.current = [...globalDragTargetsRef.current, event.target];\n }\n\n if (isEvtWithFiles(event)) {\n dispatch({isDragGlobal: true, type: \"setDragGlobal\"});\n }\n };\n\n const onDocumentDragLeave = (event: DragEvent) => {\n // Only deactivate once we've left all children\n globalDragTargetsRef.current = globalDragTargetsRef.current.filter(el => el !== event.target && el !== null);\n\n if (globalDragTargetsRef.current.length > 0) {\n return;\n }\n\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n const onDocumentDragEnd = () => {\n globalDragTargetsRef.current = [];\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n const onDocumentDropGlobal = () => {\n globalDragTargetsRef.current = [];\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n document.addEventListener(\"dragenter\", onDocumentDragEnter, false);\n document.addEventListener(\"dragleave\", onDocumentDragLeave, false);\n document.addEventListener(\"dragend\", onDocumentDragEnd, false);\n document.addEventListener(\"drop\", onDocumentDropGlobal, false);\n\n return () => {\n document.removeEventListener(\"dragenter\", onDocumentDragEnter);\n document.removeEventListener(\"dragleave\", onDocumentDragLeave);\n document.removeEventListener(\"dragend\", onDocumentDragEnd);\n document.removeEventListener(\"drop\", onDocumentDropGlobal);\n };\n }, [rootRef]);\n\n // Auto focus the root when autoFocus is true\n useEffect(() => {\n if (!disabled && autoFocus && rootRef.current) {\n rootRef.current.focus();\n }\n return () => {};\n }, [rootRef, autoFocus, disabled]);\n\n const onErrCb = useCallback(\n (e: Error) => {\n if (onError) {\n onError(e);\n } else {\n // Let the user know something's gone wrong if they haven't provided the onError cb.\n console.error(e);\n }\n },\n [onError]\n );\n\n const onDragEnterCb = useCallback(\n (event: any) => {\n event.preventDefault();\n // Persist here because we need the event later after getFilesFromEvent() is done\n event.persist?.();\n stopPropagation(event);\n\n dragTargetsRef.current = [...dragTargetsRef.current, event.target];\n\n if (isEvtWithFiles(event)) {\n Promise.resolve(getFilesFromEvent(event))\n .then(files => {\n if (isPropagationStopped(event) && !noDragEventsBubbling) {\n return;\n }\n\n const fileCount = files.length;\n // During a drag we only have DataTransferItems (MIME type, no name/size), so the\n // custom validator can't run yet - a validator-configured dropzone is \"unknown\" until\n // drop rather than a misleading accept/reject. See getDragVerdict for the details.\n const verdict =\n fileCount > 0\n ? getDragVerdict({\n files: files as Array<File | DataTransferItem>,\n accept: acceptAttr,\n minSize,\n maxSize,\n multiple,\n maxFiles,\n validator\n })\n : null;\n\n dispatch({\n isDragAccept: verdict === \"accept\",\n isDragReject: verdict === \"reject\",\n isDragUnknown: verdict === \"unknown\",\n isDragActive: true,\n type: \"setDraggedFiles\"\n });\n\n if (onDragEnter) {\n onDragEnter(event);\n }\n })\n .catch(e => onErrCb(e));\n }\n },\n [\n getFilesFromEvent,\n onDragEnter,\n onErrCb,\n noDragEventsBubbling,\n acceptAttr,\n minSize,\n maxSize,\n multiple,\n maxFiles,\n validator\n ]\n );\n\n const onDragOverCb = useCallback(\n (event: any) => {\n event.preventDefault();\n event.persist?.();\n stopPropagation(event);\n\n const hasFiles = isEvtWithFiles(event);\n if (hasFiles && event.dataTransfer) {\n try {\n event.dataTransfer.dropEffect = \"copy\";\n } catch {\n /* no-op */\n }\n }\n\n if (hasFiles && onDragOver) {\n onDragOver(event);\n }\n\n return false;\n },\n [onDragOver, noDragEventsBubbling]\n );\n\n const onDragLeaveCb = useCallback(\n (event: any) => {\n event.preventDefault();\n event.persist?.();\n stopPropagation(event);\n\n // Only deactivate once the dropzone and all children have been left\n const targets = dragTargetsRef.current.filter(target => rootRef.current?.contains(target as Node));\n // Make sure to remove a target present multiple times only once\n // (Firefox may fire dragenter/dragleave multiple times on the same element)\n const targetIdx = targets.indexOf(event.target);\n if (targetIdx !== -1) {\n targets.splice(targetIdx, 1);\n }\n dragTargetsRef.current = targets;\n if (targets.length > 0) {\n return;\n }\n\n dispatch({\n type: \"setDraggedFiles\",\n isDragActive: false,\n isDragAccept: false,\n isDragReject: false,\n isDragUnknown: false\n });\n\n if (isEvtWithFiles(event) && onDragLeave) {\n onDragLeave(event);\n }\n },\n [rootRef, onDragLeave, noDragEventsBubbling]\n );\n\n const setFiles = useCallback(\n async (files: FileWithPath[], event: any, signal: AbortSignal) => {\n const localizeError = (error: FileError, file: File): FileError =>\n getErrorMessage ? {...error, message: getErrorMessage(error, file)} : error;\n\n // Commit the per-file verdicts: split accepted/rejected, cap the surplus, update state and\n // fire the onDrop callbacks. Runs synchronously so nested-dropzone ordering is preserved on\n // the fast path (an onDrop handler calling stopPropagation must do so before a parent's onDrop\n // check - see the noDragEventsBubbling tests).\n const commit = (results: Array<PerFileResult>) => {\n const acceptedFiles: FileWithPath[] = [];\n const fileRejections: FileRejection[] = [];\n\n results.forEach(({file, accepted, acceptError, sizeMatch, sizeError, customErrors}) => {\n if (accepted && sizeMatch && !customErrors) {\n acceptedFiles.push(file);\n } else {\n let errors: Array<FileError | null> = [acceptError, sizeError];\n\n if (customErrors) {\n errors = errors.concat(customErrors);\n }\n\n fileRejections.push({\n file,\n errors: errors.filter((e): e is FileError => e != null).map(error => localizeError(error, file))\n });\n }\n });\n\n // Cap the accepted files at the configured limit and reject only the surplus (the files past\n // the limit) with a too-many-files error, instead of rejecting the whole batch. The limit is 1\n // when {multiple} is false, and {maxFiles} when {multiple} is true (0 means no limit). Files\n // that already failed the per-file checks above are in {fileRejections} and don't count here.\n // See https://github.com/react-dropzone/react-dropzone/issues/1355\n // and https://github.com/react-dropzone/react-dropzone/issues/1358\n const acceptedFilesLimit = multiple ? (maxFiles >= 1 ? maxFiles : Number.POSITIVE_INFINITY) : 1;\n if (acceptedFiles.length > acceptedFilesLimit) {\n const surplusFiles = acceptedFiles.splice(acceptedFilesLimit);\n surplusFiles.forEach(file => {\n fileRejections.push({file, errors: [localizeError(TOO_MANY_FILES_REJECTION, file)]});\n });\n }\n\n // Clears isProcessing back to false (see the reducer) in the same update that sets the files.\n dispatch({\n acceptedFiles,\n fileRejections,\n type: \"setFiles\"\n });\n\n if (onDrop) {\n onDrop(acceptedFiles, fileRejections, event);\n }\n\n if (fileRejections.length > 0 && onDropRejected) {\n onDropRejected(fileRejections, event);\n }\n\n if (acceptedFiles.length > 0 && onDropAccepted) {\n onDropAccepted(acceptedFiles, event);\n }\n };\n\n // Run the built-in checks synchronously and invoke the validator (which may return a value or\n // a Promise). customErrors is left as-is here so we can tell sync from async below.\n const pending = files.map(file => {\n const [accepted, acceptError] = fileAccepted(file, inputAcceptAttr);\n const [sizeMatch, sizeError] = fileMatchSize(file, minSize, maxSize);\n const customErrors = validator ? validator(file) : null;\n return {file, accepted, acceptError, sizeMatch, sizeError, customErrors};\n });\n\n // Callers check signal.aborted right before invoking setFiles (synchronously, no await in\n // between), so this run is guaranteed live here - the supersession guards below only matter\n // after we await the validator.\n\n // Fast path: no validator, or a synchronous one. Commit synchronously - no extra microtask\n // hop, so nested-dropzone ordering is preserved (an onDrop handler calling stopPropagation\n // must run before a parent's onDrop check - see the noDragEventsBubbling tests). commit's\n // dispatch also clears isProcessing.\n if (!pending.some(({customErrors}) => isThenable(customErrors))) {\n commit(pending as Array<PerFileResult>);\n return;\n }\n\n // Async path: at least one validator returned a Promise. isProcessing is already on (set when\n // the run began, before getFilesFromEvent); keep guarding against supersession while we await.\n let results: Array<PerFileResult>;\n try {\n results = await Promise.all(\n pending.map(async ({customErrors, ...rest}) => ({...rest, customErrors: await customErrors}))\n );\n } catch (e) {\n // A validator threw/rejected. If a newer run already superseded this one, let it own the\n // state; otherwise clear the processing flag and report the error via onError.\n if (!signal.aborted) {\n endProcessing(signal);\n onErrCb(e as Error);\n }\n return;\n }\n\n // A newer drop landed while we were validating - discard these stale results.\n if (signal.aborted) {\n return;\n }\n\n commit(results);\n },\n [\n dispatch,\n multiple,\n inputAcceptAttr,\n minSize,\n maxSize,\n maxFiles,\n onDrop,\n onDropAccepted,\n onDropRejected,\n validator,\n getErrorMessage,\n onErrCb,\n endProcessing\n ]\n );\n\n const onDropCb = useCallback(\n (event: any) => {\n event.preventDefault();\n // Persist here because we need the event later after getFilesFromEvent() is done\n event.persist?.();\n stopPropagation(event);\n\n dragTargetsRef.current = [];\n\n // Clear drag state before we begin processing so beginProcessing's isProcessing isn't reset.\n dispatch({type: \"reset\"});\n\n if (isEvtWithFiles(event)) {\n // Processing spans reading the files (getFilesFromEvent) and running the validator.\n const signal = beginProcessing();\n Promise.resolve(getFilesFromEvent(event))\n .then(files => {\n // A newer drop superseded this one while reading files - it owns isProcessing now.\n if (signal.aborted) {\n return;\n }\n if (isPropagationStopped(event) && !noDragEventsBubbling) {\n endProcessing(signal);\n return;\n }\n // setFiles handles validator errors internally (routing them to onError); the outer\n // catch here only fires for a getFilesFromEvent failure.\n return setFiles(files as FileWithPath[], event, signal);\n })\n .catch(e => {\n if (!signal.aborted) {\n endProcessing(signal);\n onErrCb(e);\n }\n });\n }\n },\n [getFilesFromEvent, setFiles, onErrCb, noDragEventsBubbling, beginProcessing, endProcessing]\n );\n\n // Fn for opening the file dialog programmatically\n const openFileDialog = useCallback(() => {\n // No point to use FS access APIs if context is not secure\n // https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts#feature_detection\n if (fsAccessApiWorksRef.current) {\n dispatch({type: \"openDialog\"});\n onFileDialogOpenCb();\n // https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker\n const opts = {\n multiple,\n types: pickerTypes\n };\n // Set once the user has picked file(s); processing then spans reading them (getFilesFromEvent)\n // and running the validator. Picker rejections (cancel, security) happen before this, so it\n // stays undefined there and no processing state is touched.\n let signal: AbortSignal | undefined;\n (window as any)\n .showOpenFilePicker(opts)\n .then((handles: any) => {\n signal = beginProcessing();\n return getFilesFromEvent(handles);\n })\n .then((files: Array<File | DataTransferItem>) => {\n // Close the dialog as soon as we have the selection; validation runs afterwards and is\n // reflected by isProcessing rather than by keeping the dialog \"active\".\n dispatch({type: \"closeDialog\"});\n // A drop elsewhere superseded this selection while reading files - it owns isProcessing.\n if (signal!.aborted) {\n return;\n }\n return setFiles(files as FileWithPath[], null, signal!);\n })\n .catch((e: any) => {\n // Clear any processing this run started (e.g. a getFilesFromEvent failure).\n if (signal) {\n endProcessing(signal);\n }\n // AbortError means the user canceled\n if (isAbort(e)) {\n onFileDialogCancelCb(e);\n dispatch({type: \"closeDialog\"});\n } else if (isSecurityError(e) || isNotAllowedError(e)) {\n // The FS access API is unusable here: either the context forbids it (SecurityError,\n // e.g. CORS) or the browser/platform blocked the picker (NotAllowedError, e.g. Edge\n // for Business - see https://github.com/react-dropzone/react-dropzone/issues/1429).\n // Stop using it and fall back to the native <input>.\n fsAccessApiWorksRef.current = false;\n if (inputRef.current) {\n inputRef.current.value = \"\";\n inputRef.current.click();\n } else {\n onErrCb(\n new Error(\n \"Cannot open the file picker because the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API is not supported and no <input> was provided.\"\n )\n );\n }\n } else {\n onErrCb(e);\n }\n });\n return;\n }\n\n if (inputRef.current) {\n dispatch({type: \"openDialog\"});\n onFileDialogOpenCb();\n inputRef.current.value = \"\";\n inputRef.current.click();\n }\n }, [\n dispatch,\n onFileDialogOpenCb,\n onFileDialogCancelCb,\n useFsAccessApi,\n setFiles,\n onErrCb,\n pickerTypes,\n multiple,\n beginProcessing,\n endProcessing\n ]);\n\n // Cb to open the file dialog when SPACE/ENTER occurs on the dropzone\n const onKeyDownCb = useCallback(\n (event: any) => {\n // Ignore keyboard events bubbling up the DOM tree\n if (!rootRef.current?.isEqualNode(event.target)) {\n return;\n }\n\n if (event.key === \" \" || event.key === \"Enter\" || event.keyCode === 32 || event.keyCode === 13) {\n event.preventDefault();\n openFileDialog();\n }\n },\n [rootRef, openFileDialog]\n );\n\n // Update focus state for the dropzone\n const onFocusCb = useCallback(() => {\n dispatch({type: \"focus\"});\n }, []);\n const onBlurCb = useCallback(() => {\n dispatch({type: \"blur\"});\n }, []);\n\n // Cb to open the file dialog when click occurs on the dropzone\n const onClickCb = useCallback(() => {\n if (noClick) {\n return;\n }\n\n // In IE11/Edge the file-browser dialog is blocking, therefore, use setTimeout()\n // to ensure React can handle state changes\n // See: https://github.com/react-dropzone/react-dropzone/issues/450\n if (isIeOrEdge()) {\n setTimeout(openFileDialog, 0);\n } else {\n openFileDialog();\n }\n }, [noClick, openFileDialog]);\n\n const composeHandler = (fn: any) => {\n return disabled ? null : fn;\n };\n\n const composeKeyboardHandler = (fn: any) => {\n return noKeyboard ? null : composeHandler(fn);\n };\n\n const composeDragHandler = (fn: any) => {\n return noDrag ? null : composeHandler(fn);\n };\n\n const stopPropagation = (event: any) => {\n if (noDragEventsBubbling) {\n event.stopPropagation();\n }\n };\n\n const getRootProps = useMemo(\n () =>\n ({\n refKey = \"ref\",\n role,\n onKeyDown,\n onFocus,\n onBlur,\n onClick,\n onDragEnter,\n onDragOver,\n onDragLeave,\n onDrop,\n ...rest\n }: DropzoneRootProps = {}) => ({\n onKeyDown: composeKeyboardHandler(composeEventHandlers(onKeyDown, onKeyDownCb)),\n onFocus: composeKeyboardHandler(composeEventHandlers(onFocus, onFocusCb)),\n onBlur: composeKeyboardHandler(composeEventHandlers(onBlur, onBlurCb)),\n onClick: composeHandler(composeEventHandlers(onClick, onClickCb)),\n onDragEnter: composeDragHandler(composeEventHandlers(onDragEnter, onDragEnterCb)),\n onDragOver: composeDragHandler(composeEventHandlers(onDragOver, onDragOverCb)),\n onDragLeave: composeDragHandler(composeEventHandlers(onDragLeave, onDragLeaveCb)),\n onDrop: composeDragHandler(composeEventHandlers(onDrop, onDropCb)),\n role: typeof role === \"string\" && role !== \"\" ? role : \"presentation\",\n [refKey]: rootRef,\n ...(!disabled && !noKeyboard ? {tabIndex: 0} : {}),\n ...(disabled ? {\"aria-disabled\": true} : {}),\n ...rest\n }),\n [\n rootRef,\n onKeyDownCb,\n onFocusCb,\n onBlurCb,\n onClickCb,\n onDragEnterCb,\n onDragOverCb,\n onDragLeaveCb,\n onDropCb,\n noKeyboard,\n noDrag,\n disabled\n ]\n );\n\n const onInputElementClick = useCallback((event: any) => {\n event.stopPropagation();\n }, []);\n\n const getInputProps = useMemo(\n () =>\n ({refKey = \"ref\", onChange, onClick, ...rest}: DropzoneInputProps = {}) => {\n const inputProps = {\n accept: inputAcceptAttr,\n multiple,\n type: \"file\",\n \"aria-label\": \"file upload\",\n // Hide the input without taking it out of flow. A visually-hidden input with\n // {position: absolute} makes the browser scroll the page to it whenever it gets\n // focus (e.g. inside a collapsed accordion), see #1413. Keeping it in flow as a\n // zero-size, transparent block avoids that while staying focusable so a {required}\n // input still triggers form validation, see #1268. Don't use {display: none} or\n // {visibility: hidden}: those make the input unfocusable and reintroduce #1268.\n style: {\n border: 0,\n display: \"block\",\n height: 0,\n margin: 0,\n opacity: 0,\n overflow: \"hidden\",\n padding: 0,\n width: 0\n },\n onChange: composeHandler(composeEventHandlers(onChange, onDropCb)),\n onClick: composeHandler(composeEventHandlers(onClick, onInputElementClick)),\n tabIndex: -1,\n [refKey]: inputRef\n };\n\n return {\n ...inputProps,\n ...rest\n };\n },\n [inputRef, accept, multiple, onDropCb, disabled]\n );\n\n return {\n ...state,\n isFocused: isFocused && !disabled,\n getRootProps,\n getInputProps,\n rootRef,\n inputRef,\n open: composeHandler(openFileDialog)\n } as unknown as DropzoneState;\n}\n\nfunction reducer(state: DropzoneInternalState, action: any): DropzoneInternalState {\n switch (action.type) {\n case \"focus\":\n return {\n ...state,\n isFocused: true\n };\n case \"blur\":\n return {\n ...state,\n isFocused: false\n };\n case \"openDialog\":\n return {\n ...initialState,\n isFileDialogActive: true\n };\n case \"closeDialog\":\n return {\n ...state,\n isFileDialogActive: false\n };\n case \"setDraggedFiles\":\n return {\n ...state,\n isDragActive: action.isDragActive,\n isDragAccept: action.isDragAccept,\n isDragReject: action.isDragReject,\n isDragUnknown: action.isDragUnknown\n };\n case \"setProcessing\":\n return {\n ...state,\n isProcessing: action.isProcessing\n };\n case \"setFiles\":\n return {\n ...state,\n acceptedFiles: action.acceptedFiles,\n fileRejections: action.fileRejections,\n isProcessing: false,\n isDragReject: false,\n isDragUnknown: false\n };\n case \"setDragGlobal\":\n return {\n ...state,\n isDragGlobal: action.isDragGlobal\n };\n case \"reset\":\n return {\n ...initialState\n };\n default:\n return state;\n }\n}\n\nfunction noop() {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,UACJ,OAAOA,YAAAA,YAAe,aAAaA,YAAAA,UAAcA,YAAAA,QAAuD;AAyB1G,MAAa,oBAAoB;AACjC,MAAa,iBAAiB;AAC9B,MAAa,iBAAiB;AAC9B,MAAa,iBAAiB;AAE9B,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,qBAAA;CACA,UAAA,kBAAA;CACA,UAAA,kBAAA;CACA,UAAA,kBAAA;;AACF,EAAA,CAAA,CAAA;AAEA,SAAgB,2BAA2B,SAAiB,IAAe;CACzE,MAAM,YAAY,OAAO,MAAM,GAAG;CAClC,MAAM,MAAM,UAAU,SAAS,IAAI,UAAU,UAAU,KAAK,IAAI,MAAM,UAAU;CAEhF,OAAO;EACL,MAAM;EACN,SAAS,qBAAqB;CAChC;AACF;AAEA,MAAM,kBAAkB;CAAC;CAAM;CAAM;CAAM;CAAM;AAAI;;;;;AAMrD,SAAS,YAAY,OAAuB;CAC1C,IAAI,QAAQ,MACV,OAAO,GAAG,MAAM,GAAG,UAAU,IAAI,SAAS;CAG5C,IAAI,OAAO,QAAQ;CACnB,IAAI,YAAY;CAChB,OAAO,QAAQ,QAAQ,YAAY,gBAAgB,SAAS,GAAG;EAC7D,QAAQ;EACR;CACF;CAGA,OAAO,GAAG,OAAO,KAAK,QAAQ,CAAC,CAAC,EAAE,GAAG,gBAAgB;AACvD;AAEA,SAAgB,wBAAwB,SAA4B;CAClE,OAAO;EACL,MAAM;EACN,SAAS,uBAAuB,YAAY,OAAO;CACrD;A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ACL,GAAG;GACH,cAAc,OAAO;EACvB;EACF,KAAK,SACH,OAAO,EACL,GAAG,aACL;EACF,SACE,OAAO;CACX;AACF;AAEA,SAAS,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["attrAccept","fromEvent"],"sources":["../src/utils/index.ts","../src/index.tsx"],"sourcesContent":["import attrAccept from \"attr-accept\";\n\n// attr-accept ships as a CommonJS module (`module.exports = { __esModule: true, default: fn }`).\n// Bundler interop surfaces its default export inconsistently — as the function under Node/Vitest,\n// but as `{ default: fn }` in some browser bundles. Normalize to the function.\nconst accepts =\n typeof attrAccept === \"function\" ? attrAccept : (attrAccept as unknown as {default: typeof attrAccept}).default;\n\n/**\n * A map of accepted MIME types to file extensions, as passed to the `accept` prop.\n */\nexport interface Accept {\n [key: string]: readonly string[];\n}\n\n/**\n * A file rejection error.\n */\nexport interface FileError {\n message: string;\n code: ErrorCode | string;\n}\n\n/**\n * What a custom `validator` returns: a single error, a list of errors, or `null` when the file\n * passes. A validator may return the result directly (synchronous) or wrapped in a `Promise`\n * (asynchronous, e.g. reading image dimensions or calling an external service).\n */\nexport type ValidatorResult = FileError | readonly FileError[] | null;\n\n// Error codes\nexport const FILE_INVALID_TYPE = \"file-invalid-type\";\nexport const FILE_TOO_LARGE = \"file-too-large\";\nexport const FILE_TOO_SMALL = \"file-too-small\";\nexport const TOO_MANY_FILES = \"too-many-files\";\n\nexport enum ErrorCode {\n FileInvalidType = \"file-invalid-type\",\n FileTooLarge = \"file-too-large\",\n FileTooSmall = \"file-too-small\",\n TooManyFiles = \"too-many-files\"\n}\n\nexport function getInvalidTypeRejectionErr(accept: string = \"\"): FileError {\n const acceptArr = accept.split(\",\");\n const msg = acceptArr.length > 1 ? `one of ${acceptArr.join(\", \")}` : acceptArr[0];\n\n return {\n code: FILE_INVALID_TYPE,\n message: `File type must be ${msg}`\n };\n}\n\nconst FILE_SIZE_UNITS = [\"KB\", \"MB\", \"GB\", \"TB\", \"PB\"];\n\n/**\n * Format a byte count into a human-readable string, e.g. `1111` -> `1.08 KB`.\n * Values below 1 KB are kept in bytes to preserve the singular/plural wording.\n */\nfunction formatBytes(bytes: number): string {\n if (bytes < 1024) {\n return `${bytes} ${bytes === 1 ? \"byte\" : \"bytes\"}`;\n }\n\n let size = bytes / 1024;\n let unitIndex = 0;\n while (size >= 1024 && unitIndex < FILE_SIZE_UNITS.length - 1) {\n size /= 1024;\n unitIndex++;\n }\n\n // Round to 2 decimals, then drop trailing zeros (1.00 -> 1, 1.50 -> 1.5).\n return `${Number(size.toFixed(2))} ${FILE_SIZE_UNITS[unitIndex]}`;\n}\n\nexport function getTooLargeRejectionErr(maxSize: number): FileError {\n return {\n code: FILE_TOO_LARGE,\n message: `File is larger than ${formatBytes(maxSize)}`\n };\n}\n\nexport function getTooSmallRejectionErr(minSize: number): FileError {\n return {\n code: FILE_TOO_SMALL,\n message: `File is smaller than ${formatBytes(minSize)}`\n };\n}\n\nexport const TOO_MANY_FILES_REJECTION: FileError = {\n code: TOO_MANY_FILES,\n message: \"Too many files\"\n};\n\n/**\n * Check if the given file is a DataTransferItem with an empty type.\n *\n * During drag events, browsers may return DataTransferItem objects instead of File objects.\n * Some browsers (e.g., Chrome) return an empty MIME type for certain file types (like .md files)\n * on DataTransferItem during drag events, even though the type is correctly set during drop.\n */\nexport function isDataTransferItemWithEmptyType(file: File | DataTransferItem): boolean {\n return file.type === \"\" && typeof (file as DataTransferItem).getAsFile === \"function\";\n}\n\n/**\n * Check if file is accepted.\n *\n * Firefox versions prior to 53 return a bogus MIME type for every file drag,\n * so dragovers with that MIME type will always be accepted.\n *\n * Chrome/other browsers may return an empty MIME type for files during drag events,\n * so we accept those as well (we'll validate properly on drop).\n */\nexport function fileAccepted(file: File, accept?: string): [boolean, FileError | null] {\n const isAcceptable =\n file.type === \"application/x-moz-file\" || accepts(file, accept ?? \"\") || isDataTransferItemWithEmptyType(file);\n return [isAcceptable, isAcceptable ? null : getInvalidTypeRejectionErr(accept)];\n}\n\nexport function fileMatchSize(\n file: {size?: number | null},\n minSize?: number,\n maxSize?: number\n): [boolean, FileError | null] {\n if (isDefined(file.size)) {\n if (isDefined(minSize) && isDefined(maxSize)) {\n if (file.size > maxSize) return [false, getTooLargeRejectionErr(maxSize)];\n if (file.size < minSize) return [false, getTooSmallRejectionErr(minSize)];\n } else if (isDefined(minSize) && file.size < minSize) {\n return [false, getTooSmallRejectionErr(minSize)];\n } else if (isDefined(maxSize) && file.size > maxSize) {\n return [false, getTooLargeRejectionErr(maxSize)];\n }\n }\n return [true, null];\n}\n\nfunction isDefined<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n}\n\n/**\n * Check if a value is thenable (Promise-like), used to tell a synchronous validator result from an\n * asynchronous one.\n */\nexport function isThenable(value: unknown): value is PromiseLike<unknown> {\n return value != null && typeof (value as {then?: unknown}).then === \"function\";\n}\n\nexport function allFilesAccepted({\n files,\n accept,\n minSize,\n maxSize,\n multiple,\n maxFiles = 0,\n validator\n}: {\n files: File[];\n accept?: string;\n minSize?: number;\n maxSize?: number;\n multiple?: boolean;\n maxFiles?: number;\n validator?: (file: File) => FileError | readonly FileError[] | null;\n}): boolean {\n if ((!multiple && files.length > 1) || (multiple && maxFiles >= 1 && files.length > maxFiles)) {\n return false;\n }\n\n return files.every(file => {\n const [accepted] = fileAccepted(file, accept);\n const [sizeMatch] = fileMatchSize(file, minSize, maxSize);\n const customErrors = validator ? validator(file) : null;\n return accepted && sizeMatch && !customErrors;\n });\n}\n\n/**\n * The outcome of the drag-time acceptance check.\n *\n * - `accept` - every file passes the checks we can evaluate during a drag.\n * - `reject` - at least one file confidently fails a check we can fully evaluate during a\n * drag (the file count, or a non-empty MIME type that doesn't match `accept`).\n * - `unknown` - nothing confidently fails, but the outcome can't be confirmed until drop,\n * because a custom `validator` is configured and can't be evaluated yet.\n */\nexport type DragVerdict = \"accept\" | \"reject\" | \"unknown\";\n\n/**\n * Classify a set of dragged files for the `isDragAccept`/`isDragReject`/`isDragUnknown` states.\n *\n * During `dragenter`/`dragover` the browser only exposes `DataTransferItem`s, which carry a MIME\n * `type` but no file name, extension or size (see https://html.spec.whatwg.org/multipage/dnd.html#dndevents).\n * So the drag-time check is deliberately optimistic about anything it can't see:\n *\n * - The custom `validator` is **never** run here. It is typed `(file: File) => ...` and users\n * routinely read `file.name`/`file.size`, which are `undefined` on a `DataTransferItem` - running\n * it would throw and abort the whole drag handler (leaving `isDragActive` stuck at `false`).\n * See https://github.com/react-dropzone/react-dropzone/issues/1408\n * - When a `validator` is configured we therefore can't promise the files are acceptable, so the\n * verdict is `unknown` rather than a misleading `reject` (or a premature `accept`).\n * See https://github.com/react-dropzone/react-dropzone/issues/1244\n *\n * The full check (including the `validator`) still runs on drop in {@link fileAccepted}/`setFiles`.\n */\nexport function getDragVerdict({\n files,\n accept,\n minSize,\n maxSize,\n multiple,\n maxFiles = 0,\n validator\n}: {\n files: Array<File | DataTransferItem>;\n accept?: string;\n minSize?: number;\n maxSize?: number;\n multiple?: boolean;\n maxFiles?: number;\n // The validator is never invoked here (see the note above), so its async variant is accepted\n // purely so the same `validator` prop is assignable during a drag.\n validator?: (file: File) => ValidatorResult | Promise<ValidatorResult>;\n}): DragVerdict {\n // The file count is knowable during a drag, so an over-the-limit selection is a confident reject.\n if ((!multiple && files.length > 1) || (multiple && maxFiles >= 1 && files.length > maxFiles)) {\n return \"reject\";\n }\n\n const confidentlyRejected = files.some(file => {\n const [accepted] = fileAccepted(file as File, accept);\n const [sizeMatch] = fileMatchSize(file as File, minSize, maxSize);\n return !accepted || !sizeMatch;\n });\n if (confidentlyRejected) {\n return \"reject\";\n }\n\n // Built-in checks pass. A custom validator can only ever add rejections on drop, never rescue\n // one - so with a validator present the drag outcome is unknown until we have real Files.\n return validator ? \"unknown\" : \"accept\";\n}\n\n// React's synthetic events has event.isPropagationStopped,\n// but to remain compatibility with other libs (Preact) fall back\n// to check event.cancelBubble\nexport function isPropagationStopped(event: any): boolean {\n if (typeof event.isPropagationStopped === \"function\") {\n return event.isPropagationStopped();\n } else if (typeof event.cancelBubble !== \"undefined\") {\n return event.cancelBubble;\n }\n return false;\n}\n\nexport function isEvtWithFiles(event: any): boolean {\n // A paste (ClipboardEvent) carries its DataTransfer under {clipboardData} rather than\n // {dataTransfer}, so a pasted screenshot is detected the same way as a drop.\n const dataTransfer = event.dataTransfer ?? event.clipboardData;\n if (!dataTransfer) {\n return !!event.target && !!event.target.files;\n }\n // https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types\n // https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types#file\n // Some Chromium drags omit \"Files\" from types (e.g. reporting only [\"text/plain\"])\n // while still exposing a kind: \"file\" entry in items - the same signal file-selector\n // uses to extract the files. Accept either so detection stays consistent. See #1409.\n return (\n Array.prototype.some.call(\n dataTransfer.types,\n (type: string) => type === \"Files\" || type === \"application/x-moz-file\"\n ) || Array.prototype.some.call(dataTransfer.items ?? [], isKindFile)\n );\n}\n\nexport function isKindFile(item: any): boolean {\n return typeof item === \"object\" && item !== null && item.kind === \"file\";\n}\n\n// allow the entire document to be a drag target\nexport function onDocumentDragOver(event: Event): void {\n event.preventDefault();\n}\n\nfunction isIe(userAgent: string): boolean {\n return userAgent.indexOf(\"MSIE\") !== -1 || userAgent.indexOf(\"Trident/\") !== -1;\n}\n\nfunction isEdge(userAgent: string): boolean {\n return userAgent.indexOf(\"Edge/\") !== -1;\n}\n\nexport function isIeOrEdge(userAgent: string = window.navigator.userAgent): boolean {\n return isIe(userAgent) || isEdge(userAgent);\n}\n\n/**\n * This is intended to be used to compose event handlers.\n * They are executed in order until one of them calls `event.isPropagationStopped()`.\n * Note that the check is done on the first invoke too,\n * meaning that if propagation was stopped before invoking the fns,\n * no handlers will be executed.\n */\nexport function composeEventHandlers(\n ...fns: Array<((event: any, ...args: any[]) => void) | null | undefined>\n): (event: any, ...args: any[]) => boolean {\n return (event: any, ...args: any[]) =>\n fns.some(fn => {\n if (!isPropagationStopped(event) && fn) {\n fn(event, ...args);\n }\n return isPropagationStopped(event);\n });\n}\n\n/**\n * canUseFileSystemAccessAPI checks if the File System Access API is supported by the browser.\n */\nexport function canUseFileSystemAccessAPI(): boolean {\n return \"showOpenFilePicker\" in window;\n}\n\n/**\n * Convert the `{accept}` dropzone prop to the `{types}` option for showOpenFilePicker.\n */\nexport function pickerOptionsFromAccept(accept?: Accept): Array<{description: string; accept: Accept}> | undefined {\n if (isDefined(accept)) {\n const acceptForPicker = Object.entries(accept)\n .filter(([mimeType, ext]) => {\n let ok = true;\n\n if (!isMIMEType(mimeType)) {\n console.warn(\n `Skipped \"${mimeType}\" because it is not a valid MIME type. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for a list of valid MIME types.`\n );\n ok = false;\n }\n\n if (!Array.isArray(ext) || !ext.every(isExt)) {\n console.warn(`Skipped \"${mimeType}\" because an invalid file extension was provided.`);\n ok = false;\n }\n\n return ok;\n })\n .reduce<Accept>((agg, [mimeType, ext]) => {\n agg[mimeType] = ext;\n return agg;\n }, {});\n return [\n {\n // description is required due to https://crbug.com/1264708\n description: \"Files\",\n accept: acceptForPicker\n }\n ];\n }\n return undefined;\n}\n\n/**\n * Convert the `{accept}` dropzone prop to a comma-separated accept attribute string.\n *\n * When `omitWildcardMimeTypesWithExtensions` is set, a wildcard MIME type (e.g. `image/*`)\n * that is paired with explicit extensions is dropped in favour of those extensions. The\n * accept attribute is an OR list, so leaving `image/*` in would make both the native file\n * picker and the drop-time validator accept ANY file of that type, ignoring the extension\n * restriction. The drag-time `isDragAccept` check keeps the wildcard because file names\n * (and therefore extensions) aren't readable during a drag.\n *\n * See https://github.com/react-dropzone/react-dropzone/issues/1220\n */\nexport function acceptPropAsAcceptAttr(\n accept?: Accept,\n {omitWildcardMimeTypesWithExtensions = false}: {omitWildcardMimeTypesWithExtensions?: boolean} = {}\n): string | undefined {\n if (isDefined(accept)) {\n return (\n Object.entries(accept)\n .reduce<string[]>((a, [mimeType, ext]) => {\n if (omitWildcardMimeTypesWithExtensions && isMIMETypeWildcard(mimeType) && ext.some(isExt)) {\n a.push(...ext);\n } else {\n a.push(mimeType, ...ext);\n }\n return a;\n }, [])\n // Silently discard invalid entries as pickerOptionsFromAccept warns about these\n .filter(v => isMIMEType(v) || isExt(v))\n .join(\",\")\n );\n }\n\n return undefined;\n}\n\n/**\n * Check if v is an exception caused by aborting a request (e.g window.showOpenFilePicker()).\n */\nexport function isAbort(v: any): boolean {\n return v instanceof DOMException && (v.name === \"AbortError\" || v.code === v.ABORT_ERR);\n}\n\n/**\n * Check if v is a security error.\n */\nexport function isSecurityError(v: any): boolean {\n return v instanceof DOMException && (v.name === \"SecurityError\" || v.code === v.SECURITY_ERR);\n}\n\n/**\n * Check if v is a \"not allowed\" error.\n *\n * Some browsers/configurations block `window.showOpenFilePicker()` outright and reject with a\n * `NotAllowedError` instead of showing the picker (e.g. Microsoft Edge for Business, or other\n * restrictive enterprise/security policies). We treat this like a security error and fall back\n * to the native `<input>`. See https://github.com/react-dropzone/react-dropzone/issues/1429\n */\nexport function isNotAllowedError(v: any): boolean {\n return v instanceof DOMException && v.name === \"NotAllowedError\";\n}\n\n/**\n * Check if v is a MIME type string.\n */\nexport function isMIMEType(v: string): boolean {\n return (\n v === \"audio/*\" ||\n v === \"video/*\" ||\n v === \"image/*\" ||\n v === \"text/*\" ||\n v === \"application/*\" ||\n /\\w+\\/[-+.\\w]+/g.test(v)\n );\n}\n\n/**\n * Check if v is a wildcard MIME type (e.g. `image/*`).\n */\nexport function isMIMETypeWildcard(v: string): boolean {\n return v.endsWith(\"/*\");\n}\n\n/**\n * Check if v is a file extension.\n */\nexport function isExt(v: string): boolean {\n return /^.*\\.[\\w]+$/.test(v);\n}\n","import {fromEvent} from \"file-selector\";\nimport type {FileWithPath} from \"file-selector\";\nimport type * as React from \"react\";\nimport {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef} from \"react\";\nimport {\n acceptPropAsAcceptAttr,\n canUseFileSystemAccessAPI,\n composeEventHandlers,\n ErrorCode,\n fileAccepted,\n fileMatchSize,\n getDragVerdict,\n isAbort,\n isEvtWithFiles,\n isIeOrEdge,\n isNotAllowedError,\n isThenable,\n isPropagationStopped,\n isSecurityError,\n onDocumentDragOver,\n pickerOptionsFromAccept,\n TOO_MANY_FILES_REJECTION\n} from \"./utils\";\nimport type {Accept, FileError, ValidatorResult} from \"./utils\";\n\nexport type {Accept, FileError, FileWithPath, ValidatorResult};\nexport {ErrorCode};\n\nexport interface DropzoneProps extends DropzoneOptions {\n children?: (state: DropzoneState) => React.ReactElement;\n}\n\nexport interface FileRejection {\n file: FileWithPath;\n errors: readonly FileError[];\n}\n\ntype SharedProps = \"multiple\" | \"onDragEnter\" | \"onDragOver\" | \"onDragLeave\";\n\nexport type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, SharedProps> & {\n accept?: Accept;\n minSize?: number;\n maxSize?: number;\n maxFiles?: number;\n preventDropOnDocument?: boolean;\n noClick?: boolean;\n noKeyboard?: boolean;\n noDrag?: boolean;\n noDragEventsBubbling?: boolean;\n /**\n * If true, disables paste-to-upload. By default, when the dropzone (or a focused child) receives a\n * paste that carries files - e.g. a screenshot pasted with Ctrl/Cmd+V - those files go through the\n * same `accept`/size/`validator` checks and `onDrop` callbacks as a drop. Pastes with no files\n * (plain text, etc.) are ignored and left untouched. See\n * https://github.com/react-dropzone/react-dropzone/issues/1210\n */\n noPaste?: boolean;\n disabled?: boolean;\n onDrop?: <T extends File>(acceptedFiles: T[], fileRejections: FileRejection[], event: DropEvent) => void;\n onDropAccepted?: <T extends File>(files: T[], event: DropEvent) => void;\n onDropRejected?: (fileRejections: FileRejection[], event: DropEvent) => void;\n getFilesFromEvent?: (event: DropEvent | Array<FileSystemFileHandle>) => Promise<Array<File | DataTransferItem>>;\n onFileDialogCancel?: () => void;\n onFileDialogOpen?: () => void;\n onError?: (err: Error) => void;\n /**\n * Custom validation, run once per file on drop/selection. Return `null` to accept the file, or a\n * {@link FileError} (or array of them) to reject it. May be `async` (return a `Promise`) to support\n * checks that can't run synchronously - e.g. reading image dimensions, inspecting file contents,\n * or calling an external service. While an async validator is pending, {@link DropzoneState.isProcessing}\n * is `true`, and `onDrop`/`onDropAccepted`/`onDropRejected` fire only once it settles. If the\n * validator throws or rejects, `onError` is called and the drop is discarded.\n *\n * Note: the validator never runs during a drag (a `DataTransferItem` has no name/size), so a\n * validator-configured dropzone is `isDragUnknown` until drop.\n */\n validator?: <T extends File>(file: T) => ValidatorResult | Promise<ValidatorResult>;\n /**\n * Override the message of any rejection error (built-in or custom). Called once per error;\n * receives the error and the file it belongs to and returns the message to use. Return\n * `error.message` for codes you don't want to change. Useful for localizing error messages.\n */\n getErrorMessage?: (error: FileError, file: File) => string;\n useFsAccessApi?: boolean;\n autoFocus?: boolean;\n};\n\nexport type DropEvent =\n | React.DragEvent<HTMLElement>\n | React.ChangeEvent<HTMLInputElement>\n | React.ClipboardEvent<HTMLElement>\n | DragEvent\n | ClipboardEvent\n | Event;\n\nexport interface DropzoneRef {\n open: () => void;\n}\n\nexport type DropzoneState = DropzoneRef & {\n isFocused: boolean;\n isDragActive: boolean;\n isDragAccept: boolean;\n isDragReject: boolean;\n isDragUnknown: boolean;\n isDragGlobal: boolean;\n isFileDialogActive: boolean;\n /**\n * `true` while a drop/selection is being processed asynchronously - i.e. while `getFilesFromEvent`\n * reads the files and/or an async {@link DropzoneOptions.validator} runs. Spans the whole pipeline,\n * from when files start being read until validation settles. When both are synchronous (the default\n * `getFilesFromEvent` with no/async-free validator) the work resolves within a microtask, so it's\n * only observable for genuinely async work. Use it to show a spinner or disable UI while processing.\n */\n isProcessing: boolean;\n acceptedFiles: readonly FileWithPath[];\n fileRejections: readonly FileRejection[];\n rootRef: React.RefObject<HTMLElement>;\n inputRef: React.RefObject<HTMLInputElement>;\n getRootProps: <T extends DropzoneRootProps>(props?: T) => T;\n getInputProps: <T extends DropzoneInputProps>(props?: T) => T;\n};\n\nexport interface DropzoneRootProps extends React.HTMLAttributes<HTMLElement> {\n refKey?: string;\n [key: string]: any;\n}\n\nexport interface DropzoneInputProps extends React.InputHTMLAttributes<HTMLInputElement> {\n refKey?: string;\n}\n\n/**\n * Convenience wrapper component for the `useDropzone` hook\n *\n * ```jsx\n * <Dropzone>\n * {({getRootProps, getInputProps}) => (\n * <div {...getRootProps()}>\n * <input {...getInputProps()} />\n * <p>Drag 'n' drop some files here, or click to select files</p>\n * </div>\n * )}\n * </Dropzone>\n * ```\n */\nconst Dropzone: React.ForwardRefExoticComponent<DropzoneProps & React.RefAttributes<DropzoneRef>> = forwardRef<\n DropzoneRef,\n DropzoneProps\n>(({children, ...params}, ref) => {\n const {open, ...props} = useDropzone(params);\n\n useImperativeHandle(ref, () => ({open}), [open]);\n\n return <>{children?.({...props, open})}</>;\n});\n\nDropzone.displayName = \"Dropzone\";\n\nexport default Dropzone;\n\ninterface DropzoneInternalState {\n isFocused: boolean;\n isFileDialogActive: boolean;\n isDragActive: boolean;\n isDragAccept: boolean;\n isDragReject: boolean;\n isDragUnknown: boolean;\n isDragGlobal: boolean;\n isProcessing: boolean;\n acceptedFiles: FileWithPath[];\n fileRejections: FileRejection[];\n}\n\n/**\n * The per-file outcome of the built-in checks plus the (resolved) custom validator, assembled in\n * setFiles before the accepted/rejected split.\n */\ninterface PerFileResult {\n file: FileWithPath;\n accepted: boolean;\n acceptError: FileError | null;\n sizeMatch: boolean;\n sizeError: FileError | null;\n customErrors: ValidatorResult;\n}\n\nconst initialState: DropzoneInternalState = {\n isFocused: false,\n isFileDialogActive: false,\n isDragActive: false,\n isDragAccept: false,\n isDragReject: false,\n isDragUnknown: false,\n isDragGlobal: false,\n isProcessing: false,\n acceptedFiles: [],\n fileRejections: []\n};\n\n/**\n * A React hook that creates a drag 'n' drop area.\n *\n * ```jsx\n * function MyDropzone(props) {\n * const {getRootProps, getInputProps} = useDropzone({\n * onDrop: acceptedFiles => {\n * // do something with the File objects, e.g. upload to some server\n * }\n * });\n * return (\n * <div {...getRootProps()}>\n * <input {...getInputProps()} />\n * <p>Drag and drop some files here, or click to select files</p>\n * </div>\n * )\n * }\n * ```\n */\nexport function useDropzone(props: DropzoneOptions = {}): DropzoneState {\n const {\n accept,\n disabled = false,\n getFilesFromEvent = fromEvent,\n maxSize = Number.POSITIVE_INFINITY,\n minSize = 0,\n multiple = true,\n maxFiles = 0,\n onDragEnter,\n onDragLeave,\n onDragOver,\n onDrop,\n onDropAccepted,\n onDropRejected,\n onFileDialogCancel,\n onFileDialogOpen,\n useFsAccessApi = false,\n autoFocus = false,\n preventDropOnDocument = true,\n noClick = false,\n noKeyboard = false,\n noDrag = false,\n noDragEventsBubbling = false,\n noPaste = false,\n onError,\n validator,\n getErrorMessage\n } = props;\n\n // `acceptAttr` keeps wildcard MIME types (e.g. `image/*`) so the drag-time\n // `isDragAccept`/`isDragReject` check can react to a file's MIME type - file names\n // (hence extensions) aren't readable during a drag.\n const acceptAttr = useMemo(() => acceptPropAsAcceptAttr(accept), [accept]);\n // `inputAcceptAttr` drops a wildcard MIME type when it is paired with extensions, so the\n // native picker and drop-time validation enforce the extensions instead of accepting any\n // file of that type. See https://github.com/react-dropzone/react-dropzone/issues/1220\n const inputAcceptAttr = useMemo(\n () =>\n acceptPropAsAcceptAttr(accept, {\n omitWildcardMimeTypesWithExtensions: true\n }),\n [accept]\n );\n const pickerTypes = useMemo(() => pickerOptionsFromAccept(accept), [accept]);\n\n const onFileDialogOpenCb = useMemo<(...args: any[]) => void>(\n () => (typeof onFileDialogOpen === \"function\" ? onFileDialogOpen : noop),\n [onFileDialogOpen]\n );\n const onFileDialogCancelCb = useMemo<(...args: any[]) => void>(\n () => (typeof onFileDialogCancel === \"function\" ? onFileDialogCancel : noop),\n [onFileDialogCancel]\n );\n\n const rootRef = useRef<HTMLElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n\n const [state, dispatch] = useReducer(reducer, initialState);\n const {isFocused, isFileDialogActive} = state;\n\n // Mirror {isFileDialogActive} into a ref so the memoized drag handlers can read the current value\n // without being recreated (and churning getRootProps/getInputProps) every time the dialog toggles.\n const isFileDialogActiveRef = useRef(isFileDialogActive);\n isFileDialogActiveRef.current = isFileDialogActive;\n\n // Tracks the in-flight processing run - reading files (getFilesFromEvent) plus running an async\n // validator. A newer drop/selection aborts the previous run so slow async work can't resolve late\n // and clobber the state with stale results.\n const processingAbortRef = useRef<AbortController | null>(null);\n\n // Begin a processing run: supersede any run still in flight and flip {isProcessing} on. Returns\n // the run's AbortSignal, which downstream async steps check to bail if a newer run took over.\n const beginProcessing = useCallback(() => {\n processingAbortRef.current?.abort();\n const controller = new AbortController();\n processingAbortRef.current = controller;\n dispatch({type: \"setProcessing\", isProcessing: true});\n return controller.signal;\n }, []);\n\n // End a processing run by clearing {isProcessing} - but only if this run is still the active one.\n // A superseded run (signal aborted) leaves the flag to the run that replaced it.\n const endProcessing = useCallback((signal: AbortSignal) => {\n if (!signal.aborted) {\n dispatch({type: \"setProcessing\", isProcessing: false});\n }\n }, []);\n\n const fsAccessApiWorksRef = useRef(\n typeof window !== \"undefined\" && window.isSecureContext && useFsAccessApi && canUseFileSystemAccessAPI()\n );\n\n // Update file dialog active state when the window is focused on\n const onWindowFocus = () => {\n // Execute the timeout only if the file dialog is opened in the browser\n if (!fsAccessApiWorksRef.current && isFileDialogActive) {\n setTimeout(() => {\n if (inputRef.current) {\n const {files} = inputRef.current;\n\n if (!files?.length) {\n dispatch({type: \"closeDialog\"});\n onFileDialogCancelCb();\n }\n }\n }, 300);\n }\n };\n useEffect(() => {\n window.addEventListener(\"focus\", onWindowFocus, false);\n return () => {\n window.removeEventListener(\"focus\", onWindowFocus, false);\n };\n }, [inputRef, isFileDialogActive, onFileDialogCancelCb, fsAccessApiWorksRef]);\n\n const dragTargetsRef = useRef<EventTarget[]>([]);\n const globalDragTargetsRef = useRef<EventTarget[]>([]);\n const onDocumentDrop = (event: DragEvent) => {\n // This is a document-level, bubble-phase listener, so it runs *after* the event has already\n // bubbled through the dropzone root. If the drop landed inside the root and the instance's own\n // onDrop handler already prevented the default, there's nothing left to do.\n //\n // We must NOT bail out on `contains()` alone: when the dropzone is `disabled` or has `noDrag`,\n // the root has no onDrop handler, so nothing prevents the browser's default action and the file\n // is opened in the tab. Falling through to `preventDefault()` here keeps that from happening.\n // See https://github.com/react-dropzone/react-dropzone/issues/1362\n if (rootRef.current && event.target && rootRef.current.contains(event.target as Node) && event.defaultPrevented) {\n return;\n }\n event.preventDefault();\n dragTargetsRef.current = [];\n };\n\n useEffect(() => {\n if (preventDropOnDocument) {\n document.addEventListener(\"dragover\", onDocumentDragOver, false);\n document.addEventListener(\"drop\", onDocumentDrop, false);\n }\n\n return () => {\n if (preventDropOnDocument) {\n document.removeEventListener(\"dragover\", onDocumentDragOver);\n document.removeEventListener(\"drop\", onDocumentDrop);\n }\n };\n }, [rootRef, preventDropOnDocument]);\n\n // Track global drag state for document-level drag events\n useEffect(() => {\n const onDocumentDragEnter = (event: DragEvent) => {\n if (event.target) {\n globalDragTargetsRef.current = [...globalDragTargetsRef.current, event.target];\n }\n\n if (isEvtWithFiles(event)) {\n dispatch({isDragGlobal: true, type: \"setDragGlobal\"});\n }\n };\n\n const onDocumentDragLeave = (event: DragEvent) => {\n // Only deactivate once we've left all children\n globalDragTargetsRef.current = globalDragTargetsRef.current.filter(el => el !== event.target && el !== null);\n\n if (globalDragTargetsRef.current.length > 0) {\n return;\n }\n\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n const onDocumentDragEnd = () => {\n globalDragTargetsRef.current = [];\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n const onDocumentDropGlobal = () => {\n globalDragTargetsRef.current = [];\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n document.addEventListener(\"dragenter\", onDocumentDragEnter, false);\n document.addEventListener(\"dragleave\", onDocumentDragLeave, false);\n document.addEventListener(\"dragend\", onDocumentDragEnd, false);\n document.addEventListener(\"drop\", onDocumentDropGlobal, false);\n\n return () => {\n document.removeEventListener(\"dragenter\", onDocumentDragEnter);\n document.removeEventListener(\"dragleave\", onDocumentDragLeave);\n document.removeEventListener(\"dragend\", onDocumentDragEnd);\n document.removeEventListener(\"drop\", onDocumentDropGlobal);\n };\n }, [rootRef]);\n\n // Auto focus the root when autoFocus is true\n useEffect(() => {\n if (!disabled && autoFocus && rootRef.current) {\n rootRef.current.focus();\n }\n return () => {};\n }, [rootRef, autoFocus, disabled]);\n\n const onErrCb = useCallback(\n (e: Error) => {\n if (onError) {\n onError(e);\n } else {\n // Let the user know something's gone wrong if they haven't provided the onError cb.\n console.error(e);\n }\n },\n [onError]\n );\n\n const onDragEnterCb = useCallback(\n (event: any) => {\n event.preventDefault();\n // Persist here because we need the event later after getFilesFromEvent() is done\n event.persist?.();\n stopPropagation(event);\n\n // Ignore drags onto the dropzone while the file picker dialog is open: the page underneath a\n // live picker shouldn't react to (or accept) dropped files. See #1455. preventDefault() above\n // still runs so the browser doesn't try to open/navigate to a dropped file.\n if (isFileDialogActiveRef.current) {\n return;\n }\n\n dragTargetsRef.current = [...dragTargetsRef.current, event.target];\n\n if (isEvtWithFiles(event)) {\n Promise.resolve(getFilesFromEvent(event))\n .then(files => {\n if (isPropagationStopped(event) && !noDragEventsBubbling) {\n return;\n }\n\n const fileCount = files.length;\n // During a drag we only have DataTransferItems (MIME type, no name/size), so the\n // custom validator can't run yet - a validator-configured dropzone is \"unknown\" until\n // drop rather than a misleading accept/reject. See getDragVerdict for the details.\n const verdict =\n fileCount > 0\n ? getDragVerdict({\n files: files as Array<File | DataTransferItem>,\n accept: acceptAttr,\n minSize,\n maxSize,\n multiple,\n maxFiles,\n validator\n })\n : null;\n\n dispatch({\n isDragAccept: verdict === \"accept\",\n isDragReject: verdict === \"reject\",\n isDragUnknown: verdict === \"unknown\",\n isDragActive: true,\n type: \"setDraggedFiles\"\n });\n\n if (onDragEnter) {\n onDragEnter(event);\n }\n })\n .catch(e => onErrCb(e));\n }\n },\n [\n getFilesFromEvent,\n onDragEnter,\n onErrCb,\n noDragEventsBubbling,\n acceptAttr,\n minSize,\n maxSize,\n multiple,\n maxFiles,\n validator\n ]\n );\n\n const onDragOverCb = useCallback(\n (event: any) => {\n event.preventDefault();\n event.persist?.();\n stopPropagation(event);\n\n // Ignore drags over the dropzone while the file picker dialog is open. See #1455.\n if (isFileDialogActiveRef.current) {\n return false;\n }\n\n const hasFiles = isEvtWithFiles(event);\n if (hasFiles && event.dataTransfer) {\n try {\n event.dataTransfer.dropEffect = \"copy\";\n } catch {\n /* no-op */\n }\n }\n\n if (hasFiles && onDragOver) {\n onDragOver(event);\n }\n\n return false;\n },\n [onDragOver, noDragEventsBubbling]\n );\n\n const onDragLeaveCb = useCallback(\n (event: any) => {\n event.preventDefault();\n event.persist?.();\n stopPropagation(event);\n\n // Only deactivate once the dropzone and all children have been left\n const targets = dragTargetsRef.current.filter(target => rootRef.current?.contains(target as Node));\n // Make sure to remove a target present multiple times only once\n // (Firefox may fire dragenter/dragleave multiple times on the same element)\n const targetIdx = targets.indexOf(event.target);\n if (targetIdx !== -1) {\n targets.splice(targetIdx, 1);\n }\n dragTargetsRef.current = targets;\n if (targets.length > 0) {\n return;\n }\n\n dispatch({\n type: \"setDraggedFiles\",\n isDragActive: false,\n isDragAccept: false,\n isDragReject: false,\n isDragUnknown: false\n });\n\n if (isEvtWithFiles(event) && onDragLeave) {\n onDragLeave(event);\n }\n },\n [rootRef, onDragLeave, noDragEventsBubbling]\n );\n\n const setFiles = useCallback(\n async (files: FileWithPath[], event: any, signal: AbortSignal) => {\n const localizeError = (error: FileError, file: File): FileError =>\n getErrorMessage ? {...error, message: getErrorMessage(error, file)} : error;\n\n // Commit the per-file verdicts: split accepted/rejected, cap the surplus, update state and\n // fire the onDrop callbacks. Runs synchronously so nested-dropzone ordering is preserved on\n // the fast path (an onDrop handler calling stopPropagation must do so before a parent's onDrop\n // check - see the noDragEventsBubbling tests).\n const commit = (results: Array<PerFileResult>) => {\n const acceptedFiles: FileWithPath[] = [];\n const fileRejections: FileRejection[] = [];\n\n results.forEach(({file, accepted, acceptError, sizeMatch, sizeError, customErrors}) => {\n if (accepted && sizeMatch && !customErrors) {\n acceptedFiles.push(file);\n } else {\n let errors: Array<FileError | null> = [acceptError, sizeError];\n\n if (customErrors) {\n errors = errors.concat(customErrors);\n }\n\n fileRejections.push({\n file,\n errors: errors.filter((e): e is FileError => e != null).map(error => localizeError(error, file))\n });\n }\n });\n\n // Cap the accepted files at the configured limit and reject only the surplus (the files past\n // the limit) with a too-many-files error, instead of rejecting the whole batch. The limit is 1\n // when {multiple} is false, and {maxFiles} when {multiple} is true (0 means no limit). Files\n // that already failed the per-file checks above are in {fileRejections} and don't count here.\n // See https://github.com/react-dropzone/react-dropzone/issues/1355\n // and https://github.com/react-dropzone/react-dropzone/issues/1358\n const acceptedFilesLimit = multiple ? (maxFiles >= 1 ? maxFiles : Number.POSITIVE_INFINITY) : 1;\n if (acceptedFiles.length > acceptedFilesLimit) {\n const surplusFiles = acceptedFiles.splice(acceptedFilesLimit);\n surplusFiles.forEach(file => {\n fileRejections.push({file, errors: [localizeError(TOO_MANY_FILES_REJECTION, file)]});\n });\n }\n\n // Clears isProcessing back to false (see the reducer) in the same update that sets the files.\n dispatch({\n acceptedFiles,\n fileRejections,\n type: \"setFiles\"\n });\n\n if (onDrop) {\n onDrop(acceptedFiles, fileRejections, event);\n }\n\n if (fileRejections.length > 0 && onDropRejected) {\n onDropRejected(fileRejections, event);\n }\n\n if (acceptedFiles.length > 0 && onDropAccepted) {\n onDropAccepted(acceptedFiles, event);\n }\n };\n\n // Run the built-in checks synchronously and invoke the validator (which may return a value or\n // a Promise). customErrors is left as-is here so we can tell sync from async below.\n const pending = files.map(file => {\n const [accepted, acceptError] = fileAccepted(file, inputAcceptAttr);\n const [sizeMatch, sizeError] = fileMatchSize(file, minSize, maxSize);\n const customErrors = validator ? validator(file) : null;\n return {file, accepted, acceptError, sizeMatch, sizeError, customErrors};\n });\n\n // Callers check signal.aborted right before invoking setFiles (synchronously, no await in\n // between), so this run is guaranteed live here - the supersession guards below only matter\n // after we await the validator.\n\n // Fast path: no validator, or a synchronous one. Commit synchronously - no extra microtask\n // hop, so nested-dropzone ordering is preserved (an onDrop handler calling stopPropagation\n // must run before a parent's onDrop check - see the noDragEventsBubbling tests). commit's\n // dispatch also clears isProcessing.\n if (!pending.some(({customErrors}) => isThenable(customErrors))) {\n commit(pending as Array<PerFileResult>);\n return;\n }\n\n // Async path: at least one validator returned a Promise. isProcessing is already on (set when\n // the run began, before getFilesFromEvent); keep guarding against supersession while we await.\n let results: Array<PerFileResult>;\n try {\n results = await Promise.all(\n pending.map(async ({customErrors, ...rest}) => ({...rest, customErrors: await customErrors}))\n );\n } catch (e) {\n // A validator threw/rejected. If a newer run already superseded this one, let it own the\n // state; otherwise clear the processing flag and report the error via onError.\n if (!signal.aborted) {\n endProcessing(signal);\n onErrCb(e as Error);\n }\n return;\n }\n\n // A newer drop landed while we were validating - discard these stale results.\n if (signal.aborted) {\n return;\n }\n\n commit(results);\n },\n [\n dispatch,\n multiple,\n inputAcceptAttr,\n minSize,\n maxSize,\n maxFiles,\n onDrop,\n onDropAccepted,\n onDropRejected,\n validator,\n getErrorMessage,\n onErrCb,\n endProcessing\n ]\n );\n\n const onDropCb = useCallback(\n (event: any) => {\n event.preventDefault();\n // Persist here because we need the event later after getFilesFromEvent() is done\n event.persist?.();\n stopPropagation(event);\n\n dragTargetsRef.current = [];\n\n // Ignore a drop landing on the dropzone while the file picker dialog is open (see #1455).\n // Guard on {event.dataTransfer} so only real drag-drops are suppressed: the input's change\n // event (a file picked from the dialog) also runs through here while the dialog is still\n // flagged active, and that path must keep working. Returning before the reset below leaves\n // the dialog flag intact.\n if (isFileDialogActiveRef.current && event.dataTransfer) {\n return;\n }\n\n // Clear drag state before we begin processing so beginProcessing's isProcessing isn't reset.\n dispatch({type: \"reset\"});\n\n if (isEvtWithFiles(event)) {\n // Processing spans reading the files (getFilesFromEvent) and running the validator.\n const signal = beginProcessing();\n Promise.resolve(getFilesFromEvent(event))\n .then(files => {\n // A newer drop superseded this one while reading files - it owns isProcessing now.\n if (signal.aborted) {\n return;\n }\n if (isPropagationStopped(event) && !noDragEventsBubbling) {\n endProcessing(signal);\n return;\n }\n // setFiles handles validator errors internally (routing them to onError); the outer\n // catch here only fires for a getFilesFromEvent failure.\n return setFiles(files as FileWithPath[], event, signal);\n })\n .catch(e => {\n if (!signal.aborted) {\n endProcessing(signal);\n onErrCb(e);\n }\n });\n }\n },\n [getFilesFromEvent, setFiles, onErrCb, noDragEventsBubbling, beginProcessing, endProcessing]\n );\n\n // Cb to add files pasted into the dropzone (e.g. a screenshot pasted with Ctrl/Cmd+V). Fires when\n // the root - or a focused descendant, so a child <textarea> works too - receives a paste. Reuses\n // the same read/validate/onDrop pipeline as a drop.\n const onPasteCb = useCallback(\n (event: any) => {\n // Only act on a paste that carries files. Bail before preventDefault() for text/other pastes\n // so pasting into a child input keeps working normally.\n if (!isEvtWithFiles(event)) {\n return;\n }\n event.preventDefault();\n // Persist here because we need the event later after getFilesFromEvent() is done\n event.persist?.();\n stopPropagation(event);\n\n // Processing spans reading the files (getFilesFromEvent) and running the validator.\n const signal = beginProcessing();\n Promise.resolve(getFilesFromEvent(event))\n .then(files => {\n // A newer drop/paste superseded this one while reading files - it owns isProcessing now.\n if (signal.aborted) {\n return;\n }\n if (isPropagationStopped(event) && !noDragEventsBubbling) {\n endProcessing(signal);\n return;\n }\n return setFiles(files as FileWithPath[], event, signal);\n })\n .catch(e => {\n if (!signal.aborted) {\n endProcessing(signal);\n onErrCb(e);\n }\n });\n },\n [getFilesFromEvent, setFiles, onErrCb, noDragEventsBubbling, beginProcessing, endProcessing]\n );\n\n // Fn for opening the file dialog programmatically\n const openFileDialog = useCallback(() => {\n // No point to use FS access APIs if context is not secure\n // https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts#feature_detection\n if (fsAccessApiWorksRef.current) {\n dispatch({type: \"openDialog\"});\n onFileDialogOpenCb();\n // https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker\n const opts = {\n multiple,\n types: pickerTypes\n };\n // Set once the user has picked file(s); processing then spans reading them (getFilesFromEvent)\n // and running the validator. Picker rejections (cancel, security) happen before this, so it\n // stays undefined there and no processing state is touched.\n let signal: AbortSignal | undefined;\n (window as any)\n .showOpenFilePicker(opts)\n .then((handles: any) => {\n signal = beginProcessing();\n return getFilesFromEvent(handles);\n })\n .then((files: Array<File | DataTransferItem>) => {\n // Close the dialog as soon as we have the selection; validation runs afterwards and is\n // reflected by isProcessing rather than by keeping the dialog \"active\".\n dispatch({type: \"closeDialog\"});\n // A drop elsewhere superseded this selection while reading files - it owns isProcessing.\n if (signal!.aborted) {\n return;\n }\n return setFiles(files as FileWithPath[], null, signal!);\n })\n .catch((e: any) => {\n // Clear any processing this run started (e.g. a getFilesFromEvent failure).\n if (signal) {\n endProcessing(signal);\n }\n // AbortError means the user canceled\n if (isAbort(e)) {\n onFileDialogCancelCb(e);\n dispatch({type: \"closeDialog\"});\n } else if (isSecurityError(e) || isNotAllowedError(e)) {\n // The FS access API is unusable here: either the context forbids it (SecurityError,\n // e.g. CORS) or the browser/platform blocked the picker (NotAllowedError, e.g. Edge\n // for Business - see https://github.com/react-dropzone/react-dropzone/issues/1429).\n // Stop using it and fall back to the native <input>.\n fsAccessApiWorksRef.current = false;\n if (inputRef.current) {\n inputRef.current.value = \"\";\n inputRef.current.click();\n } else {\n onErrCb(\n new Error(\n \"Cannot open the file picker because the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API is not supported and no <input> was provided.\"\n )\n );\n }\n } else {\n onErrCb(e);\n }\n });\n return;\n }\n\n if (inputRef.current) {\n dispatch({type: \"openDialog\"});\n onFileDialogOpenCb();\n inputRef.current.value = \"\";\n inputRef.current.click();\n }\n }, [\n dispatch,\n onFileDialogOpenCb,\n onFileDialogCancelCb,\n useFsAccessApi,\n setFiles,\n onErrCb,\n pickerTypes,\n multiple,\n beginProcessing,\n endProcessing\n ]);\n\n // Cb to open the file dialog when SPACE/ENTER occurs on the dropzone\n const onKeyDownCb = useCallback(\n (event: any) => {\n // Ignore keyboard events bubbling up the DOM tree\n if (!rootRef.current?.isEqualNode(event.target)) {\n return;\n }\n\n if (event.key === \" \" || event.key === \"Enter\" || event.keyCode === 32 || event.keyCode === 13) {\n event.preventDefault();\n openFileDialog();\n }\n },\n [rootRef, openFileDialog]\n );\n\n // Update focus state for the dropzone\n const onFocusCb = useCallback(() => {\n dispatch({type: \"focus\"});\n }, []);\n const onBlurCb = useCallback(() => {\n dispatch({type: \"blur\"});\n }, []);\n\n // Cb to open the file dialog when click occurs on the dropzone\n const onClickCb = useCallback(() => {\n if (noClick) {\n return;\n }\n\n // In IE11/Edge the file-browser dialog is blocking, therefore, use setTimeout()\n // to ensure React can handle state changes\n // See: https://github.com/react-dropzone/react-dropzone/issues/450\n if (isIeOrEdge()) {\n setTimeout(openFileDialog, 0);\n } else {\n openFileDialog();\n }\n }, [noClick, openFileDialog]);\n\n const composeHandler = (fn: any) => {\n return disabled ? null : fn;\n };\n\n const composeKeyboardHandler = (fn: any) => {\n return noKeyboard ? null : composeHandler(fn);\n };\n\n const composeDragHandler = (fn: any) => {\n return noDrag ? null : composeHandler(fn);\n };\n\n const composePasteHandler = (fn: any) => {\n return noPaste ? null : composeHandler(fn);\n };\n\n const stopPropagation = (event: any) => {\n if (noDragEventsBubbling) {\n event.stopPropagation();\n }\n };\n\n const getRootProps = useMemo(\n () =>\n ({\n refKey = \"ref\",\n role,\n onKeyDown,\n onFocus,\n onBlur,\n onClick,\n onDragEnter,\n onDragOver,\n onDragLeave,\n onDrop,\n onPaste,\n ...rest\n }: DropzoneRootProps = {}) => ({\n onKeyDown: composeKeyboardHandler(composeEventHandlers(onKeyDown, onKeyDownCb)),\n onFocus: composeKeyboardHandler(composeEventHandlers(onFocus, onFocusCb)),\n onBlur: composeKeyboardHandler(composeEventHandlers(onBlur, onBlurCb)),\n onClick: composeHandler(composeEventHandlers(onClick, onClickCb)),\n onDragEnter: composeDragHandler(composeEventHandlers(onDragEnter, onDragEnterCb)),\n onDragOver: composeDragHandler(composeEventHandlers(onDragOver, onDragOverCb)),\n onDragLeave: composeDragHandler(composeEventHandlers(onDragLeave, onDragLeaveCb)),\n onDrop: composeDragHandler(composeEventHandlers(onDrop, onDropCb)),\n onPaste: composePasteHandler(composeEventHandlers(onPaste, onPasteCb)),\n role: typeof role === \"string\" && role !== \"\" ? role : \"presentation\",\n [refKey]: rootRef,\n ...(!disabled && !noKeyboard ? {tabIndex: 0} : {}),\n ...(disabled ? {\"aria-disabled\": true} : {}),\n ...rest\n }),\n [\n rootRef,\n onKeyDownCb,\n onFocusCb,\n onBlurCb,\n onClickCb,\n onDragEnterCb,\n onDragOverCb,\n onDragLeaveCb,\n onDropCb,\n onPasteCb,\n noKeyboard,\n noDrag,\n noPaste,\n disabled\n ]\n );\n\n const onInputElementClick = useCallback((event: any) => {\n event.stopPropagation();\n }, []);\n\n const getInputProps = useMemo(\n () =>\n ({refKey = \"ref\", onChange, onClick, ...rest}: DropzoneInputProps = {}) => {\n const inputProps = {\n accept: inputAcceptAttr,\n multiple,\n type: \"file\",\n \"aria-label\": \"file upload\",\n // Hide the input without taking it out of flow. A visually-hidden input with\n // {position: absolute} makes the browser scroll the page to it whenever it gets\n // focus (e.g. inside a collapsed accordion), see #1413. Keeping it in flow as a\n // zero-size, transparent block avoids that while staying focusable so a {required}\n // input still triggers form validation, see #1268. Don't use {display: none} or\n // {visibility: hidden}: those make the input unfocusable and reintroduce #1268.\n style: {\n border: 0,\n display: \"block\",\n height: 0,\n margin: 0,\n opacity: 0,\n overflow: \"hidden\",\n padding: 0,\n width: 0\n },\n onChange: composeHandler(composeEventHandlers(onChange, onDropCb)),\n onClick: composeHandler(composeEventHandlers(onClick, onInputElementClick)),\n tabIndex: -1,\n [refKey]: inputRef\n };\n\n return {\n ...inputProps,\n ...rest\n };\n },\n [inputRef, accept, multiple, onDropCb, disabled]\n );\n\n return {\n ...state,\n isFocused: isFocused && !disabled,\n getRootProps,\n getInputProps,\n rootRef,\n inputRef,\n open: composeHandler(openFileDialog)\n } as unknown as DropzoneState;\n}\n\nfunction reducer(state: DropzoneInternalState, action: any): DropzoneInternalState {\n switch (action.type) {\n case \"focus\":\n return {\n ...state,\n isFocused: true\n };\n case \"blur\":\n return {\n ...state,\n isFocused: false\n };\n case \"openDialog\":\n return {\n ...initialState,\n isFileDialogActive: true\n };\n case \"closeDialog\":\n return {\n ...state,\n isFileDialogActive: false\n };\n case \"setDraggedFiles\":\n return {\n ...state,\n isDragActive: action.isDragActive,\n isDragAccept: action.isDragAccept,\n isDragReject: action.isDragReject,\n isDragUnknown: action.isDragUnknown\n };\n case \"setProcessing\":\n return {\n ...state,\n isProcessing: action.isProcessing\n };\n case \"setFiles\":\n return {\n ...state,\n acceptedFiles: action.acceptedFiles,\n fileRejections: action.fileRejections,\n isProcessing: false,\n isDragReject: false,\n isDragUnknown: false\n };\n case \"setDragGlobal\":\n return {\n ...state,\n isDragGlobal: action.isDragGlobal\n };\n case \"reset\":\n return {\n ...initialState\n };\n default:\n return state;\n }\n}\n\nfunction noop() {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,UACJ,OAAOA,YAAAA,YAAe,aAAaA,YAAAA,UAAcA,YAAAA,QAAuD;AAyB1G,MAAa,oBAAoB;AACjC,MAAa,iBAAiB;AAC9B,MAAa,iBAAiB;AAC9B,MAAa,iBAAiB;AAE9B,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,qBAAA;CACA,UAAA,kBAAA;CACA,UAAA,kBAAA;CACA,UAAA,kBAAA;;AACF,EAAA,CAAA,CAAA;AAEA,SAAgB,2BAA2B,SAAiB,IAAe;CACzE,MAAM,YAAY,OAAO,MAAM,GAAG;CAClC,MAAM,MAAM,UAAU,SAAS,IAAI,UAAU,UAAU,KAAK,IAAI,MAAM,UAAU;CAEhF,OAAO;EAC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EACvB;EACF,KAAK,YACH,OAAO;GACL,GAAG;GACH,eAAe,OAAO;GACtB,gBAAgB,OAAO;GACvB,cAAc;GACd,cAAc;GACd,eAAe;EACjB;EACF,KAAK,iBACH,OAAO;GACL,GAAG;GACH,cAAc,OAAO;EACvB;EACF,KAAK,SACH,OAAO,EACL,GAAG,aACL;EACF,SACE,OAAO;CACX;AACF;AAEA,SAAS,OAAO,CAAC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -46,6 +46,14 @@ type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, SharedProps> & {
|
|
|
46
46
|
noKeyboard?: boolean;
|
|
47
47
|
noDrag?: boolean;
|
|
48
48
|
noDragEventsBubbling?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* If true, disables paste-to-upload. By default, when the dropzone (or a focused child) receives a
|
|
51
|
+
* paste that carries files - e.g. a screenshot pasted with Ctrl/Cmd+V - those files go through the
|
|
52
|
+
* same `accept`/size/`validator` checks and `onDrop` callbacks as a drop. Pastes with no files
|
|
53
|
+
* (plain text, etc.) are ignored and left untouched. See
|
|
54
|
+
* https://github.com/react-dropzone/react-dropzone/issues/1210
|
|
55
|
+
*/
|
|
56
|
+
noPaste?: boolean;
|
|
49
57
|
disabled?: boolean;
|
|
50
58
|
onDrop?: <T extends File>(acceptedFiles: T[], fileRejections: FileRejection[], event: DropEvent) => void;
|
|
51
59
|
onDropAccepted?: <T extends File>(files: T[], event: DropEvent) => void;
|
|
@@ -75,7 +83,7 @@ type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, SharedProps> & {
|
|
|
75
83
|
useFsAccessApi?: boolean;
|
|
76
84
|
autoFocus?: boolean;
|
|
77
85
|
};
|
|
78
|
-
type DropEvent = React.DragEvent<HTMLElement> | React.ChangeEvent<HTMLInputElement> | DragEvent | Event;
|
|
86
|
+
type DropEvent = React.DragEvent<HTMLElement> | React.ChangeEvent<HTMLInputElement> | React.ClipboardEvent<HTMLElement> | DragEvent | ClipboardEvent | Event;
|
|
79
87
|
interface DropzoneRef {
|
|
80
88
|
open: () => void;
|
|
81
89
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,14 @@ type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, SharedProps> & {
|
|
|
46
46
|
noKeyboard?: boolean;
|
|
47
47
|
noDrag?: boolean;
|
|
48
48
|
noDragEventsBubbling?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* If true, disables paste-to-upload. By default, when the dropzone (or a focused child) receives a
|
|
51
|
+
* paste that carries files - e.g. a screenshot pasted with Ctrl/Cmd+V - those files go through the
|
|
52
|
+
* same `accept`/size/`validator` checks and `onDrop` callbacks as a drop. Pastes with no files
|
|
53
|
+
* (plain text, etc.) are ignored and left untouched. See
|
|
54
|
+
* https://github.com/react-dropzone/react-dropzone/issues/1210
|
|
55
|
+
*/
|
|
56
|
+
noPaste?: boolean;
|
|
49
57
|
disabled?: boolean;
|
|
50
58
|
onDrop?: <T extends File>(acceptedFiles: T[], fileRejections: FileRejection[], event: DropEvent) => void;
|
|
51
59
|
onDropAccepted?: <T extends File>(files: T[], event: DropEvent) => void;
|
|
@@ -75,7 +83,7 @@ type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, SharedProps> & {
|
|
|
75
83
|
useFsAccessApi?: boolean;
|
|
76
84
|
autoFocus?: boolean;
|
|
77
85
|
};
|
|
78
|
-
type DropEvent = React.DragEvent<HTMLElement> | React.ChangeEvent<HTMLInputElement> | DragEvent | Event;
|
|
86
|
+
type DropEvent = React.DragEvent<HTMLElement> | React.ChangeEvent<HTMLInputElement> | React.ClipboardEvent<HTMLElement> | DragEvent | ClipboardEvent | Event;
|
|
79
87
|
interface DropzoneRef {
|
|
80
88
|
open: () => void;
|
|
81
89
|
}
|
package/dist/index.js
CHANGED
|
@@ -135,8 +135,9 @@ function isPropagationStopped(event) {
|
|
|
135
135
|
return false;
|
|
136
136
|
}
|
|
137
137
|
function isEvtWithFiles(event) {
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
const dataTransfer = event.dataTransfer ?? event.clipboardData;
|
|
139
|
+
if (!dataTransfer) return !!event.target && !!event.target.files;
|
|
140
|
+
return Array.prototype.some.call(dataTransfer.types, (type) => type === "Files" || type === "application/x-moz-file") || Array.prototype.some.call(dataTransfer.items ?? [], isKindFile);
|
|
140
141
|
}
|
|
141
142
|
function isKindFile(item) {
|
|
142
143
|
return typeof item === "object" && item !== null && item.kind === "file";
|
|
@@ -312,7 +313,7 @@ const initialState = {
|
|
|
312
313
|
* ```
|
|
313
314
|
*/
|
|
314
315
|
function useDropzone(props = {}) {
|
|
315
|
-
const { accept, disabled = false, getFilesFromEvent = fromEvent, maxSize = Number.POSITIVE_INFINITY, minSize = 0, multiple = true, maxFiles = 0, onDragEnter, onDragLeave, onDragOver, onDrop, onDropAccepted, onDropRejected, onFileDialogCancel, onFileDialogOpen, useFsAccessApi = false, autoFocus = false, preventDropOnDocument = true, noClick = false, noKeyboard = false, noDrag = false, noDragEventsBubbling = false, onError, validator, getErrorMessage } = props;
|
|
316
|
+
const { accept, disabled = false, getFilesFromEvent = fromEvent, maxSize = Number.POSITIVE_INFINITY, minSize = 0, multiple = true, maxFiles = 0, onDragEnter, onDragLeave, onDragOver, onDrop, onDropAccepted, onDropRejected, onFileDialogCancel, onFileDialogOpen, useFsAccessApi = false, autoFocus = false, preventDropOnDocument = true, noClick = false, noKeyboard = false, noDrag = false, noDragEventsBubbling = false, noPaste = false, onError, validator, getErrorMessage } = props;
|
|
316
317
|
const acceptAttr = useMemo(() => acceptPropAsAcceptAttr(accept), [accept]);
|
|
317
318
|
const inputAcceptAttr = useMemo(() => acceptPropAsAcceptAttr(accept, { omitWildcardMimeTypesWithExtensions: true }), [accept]);
|
|
318
319
|
const pickerTypes = useMemo(() => pickerOptionsFromAccept(accept), [accept]);
|
|
@@ -322,6 +323,8 @@ function useDropzone(props = {}) {
|
|
|
322
323
|
const inputRef = useRef(null);
|
|
323
324
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
324
325
|
const { isFocused, isFileDialogActive } = state;
|
|
326
|
+
const isFileDialogActiveRef = useRef(isFileDialogActive);
|
|
327
|
+
isFileDialogActiveRef.current = isFileDialogActive;
|
|
325
328
|
const processingAbortRef = useRef(null);
|
|
326
329
|
const beginProcessing = useCallback(() => {
|
|
327
330
|
processingAbortRef.current?.abort();
|
|
@@ -438,6 +441,7 @@ function useDropzone(props = {}) {
|
|
|
438
441
|
event.preventDefault();
|
|
439
442
|
event.persist?.();
|
|
440
443
|
stopPropagation(event);
|
|
444
|
+
if (isFileDialogActiveRef.current) return;
|
|
441
445
|
dragTargetsRef.current = [...dragTargetsRef.current, event.target];
|
|
442
446
|
if (isEvtWithFiles(event)) Promise.resolve(getFilesFromEvent(event)).then((files) => {
|
|
443
447
|
if (isPropagationStopped(event) && !noDragEventsBubbling) return;
|
|
@@ -475,6 +479,7 @@ function useDropzone(props = {}) {
|
|
|
475
479
|
event.preventDefault();
|
|
476
480
|
event.persist?.();
|
|
477
481
|
stopPropagation(event);
|
|
482
|
+
if (isFileDialogActiveRef.current) return false;
|
|
478
483
|
const hasFiles = isEvtWithFiles(event);
|
|
479
484
|
if (hasFiles && event.dataTransfer) try {
|
|
480
485
|
event.dataTransfer.dropEffect = "copy";
|
|
@@ -590,6 +595,7 @@ function useDropzone(props = {}) {
|
|
|
590
595
|
event.persist?.();
|
|
591
596
|
stopPropagation(event);
|
|
592
597
|
dragTargetsRef.current = [];
|
|
598
|
+
if (isFileDialogActiveRef.current && event.dataTransfer) return;
|
|
593
599
|
dispatch({ type: "reset" });
|
|
594
600
|
if (isEvtWithFiles(event)) {
|
|
595
601
|
const signal = beginProcessing();
|
|
@@ -615,6 +621,33 @@ function useDropzone(props = {}) {
|
|
|
615
621
|
beginProcessing,
|
|
616
622
|
endProcessing
|
|
617
623
|
]);
|
|
624
|
+
const onPasteCb = useCallback((event) => {
|
|
625
|
+
if (!isEvtWithFiles(event)) return;
|
|
626
|
+
event.preventDefault();
|
|
627
|
+
event.persist?.();
|
|
628
|
+
stopPropagation(event);
|
|
629
|
+
const signal = beginProcessing();
|
|
630
|
+
Promise.resolve(getFilesFromEvent(event)).then((files) => {
|
|
631
|
+
if (signal.aborted) return;
|
|
632
|
+
if (isPropagationStopped(event) && !noDragEventsBubbling) {
|
|
633
|
+
endProcessing(signal);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
return setFiles(files, event, signal);
|
|
637
|
+
}).catch((e) => {
|
|
638
|
+
if (!signal.aborted) {
|
|
639
|
+
endProcessing(signal);
|
|
640
|
+
onErrCb(e);
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
}, [
|
|
644
|
+
getFilesFromEvent,
|
|
645
|
+
setFiles,
|
|
646
|
+
onErrCb,
|
|
647
|
+
noDragEventsBubbling,
|
|
648
|
+
beginProcessing,
|
|
649
|
+
endProcessing
|
|
650
|
+
]);
|
|
618
651
|
const openFileDialog = useCallback(() => {
|
|
619
652
|
if (fsAccessApiWorksRef.current) {
|
|
620
653
|
dispatch({ type: "openDialog" });
|
|
@@ -691,10 +724,13 @@ function useDropzone(props = {}) {
|
|
|
691
724
|
const composeDragHandler = (fn) => {
|
|
692
725
|
return noDrag ? null : composeHandler(fn);
|
|
693
726
|
};
|
|
727
|
+
const composePasteHandler = (fn) => {
|
|
728
|
+
return noPaste ? null : composeHandler(fn);
|
|
729
|
+
};
|
|
694
730
|
const stopPropagation = (event) => {
|
|
695
731
|
if (noDragEventsBubbling) event.stopPropagation();
|
|
696
732
|
};
|
|
697
|
-
const getRootProps = useMemo(() => ({ refKey = "ref", role, onKeyDown, onFocus, onBlur, onClick, onDragEnter, onDragOver, onDragLeave, onDrop, ...rest } = {}) => ({
|
|
733
|
+
const getRootProps = useMemo(() => ({ refKey = "ref", role, onKeyDown, onFocus, onBlur, onClick, onDragEnter, onDragOver, onDragLeave, onDrop, onPaste, ...rest } = {}) => ({
|
|
698
734
|
onKeyDown: composeKeyboardHandler(composeEventHandlers(onKeyDown, onKeyDownCb)),
|
|
699
735
|
onFocus: composeKeyboardHandler(composeEventHandlers(onFocus, onFocusCb)),
|
|
700
736
|
onBlur: composeKeyboardHandler(composeEventHandlers(onBlur, onBlurCb)),
|
|
@@ -703,6 +739,7 @@ function useDropzone(props = {}) {
|
|
|
703
739
|
onDragOver: composeDragHandler(composeEventHandlers(onDragOver, onDragOverCb)),
|
|
704
740
|
onDragLeave: composeDragHandler(composeEventHandlers(onDragLeave, onDragLeaveCb)),
|
|
705
741
|
onDrop: composeDragHandler(composeEventHandlers(onDrop, onDropCb)),
|
|
742
|
+
onPaste: composePasteHandler(composeEventHandlers(onPaste, onPasteCb)),
|
|
706
743
|
role: typeof role === "string" && role !== "" ? role : "presentation",
|
|
707
744
|
[refKey]: rootRef,
|
|
708
745
|
...!disabled && !noKeyboard ? { tabIndex: 0 } : {},
|
|
@@ -718,8 +755,10 @@ function useDropzone(props = {}) {
|
|
|
718
755
|
onDragOverCb,
|
|
719
756
|
onDragLeaveCb,
|
|
720
757
|
onDropCb,
|
|
758
|
+
onPasteCb,
|
|
721
759
|
noKeyboard,
|
|
722
760
|
noDrag,
|
|
761
|
+
noPaste,
|
|
723
762
|
disabled
|
|
724
763
|
]);
|
|
725
764
|
const onInputElementClick = useCallback((event) => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/utils/index.ts","../src/index.tsx"],"sourcesContent":["import attrAccept from \"attr-accept\";\n\n// attr-accept ships as a CommonJS module (`module.exports = { __esModule: true, default: fn }`).\n// Bundler interop surfaces its default export inconsistently — as the function under Node/Vitest,\n// but as `{ default: fn }` in some browser bundles. Normalize to the function.\nconst accepts =\n typeof attrAccept === \"function\" ? attrAccept : (attrAccept as unknown as {default: typeof attrAccept}).default;\n\n/**\n * A map of accepted MIME types to file extensions, as passed to the `accept` prop.\n */\nexport interface Accept {\n [key: string]: readonly string[];\n}\n\n/**\n * A file rejection error.\n */\nexport interface FileError {\n message: string;\n code: ErrorCode | string;\n}\n\n/**\n * What a custom `validator` returns: a single error, a list of errors, or `null` when the file\n * passes. A validator may return the result directly (synchronous) or wrapped in a `Promise`\n * (asynchronous, e.g. reading image dimensions or calling an external service).\n */\nexport type ValidatorResult = FileError | readonly FileError[] | null;\n\n// Error codes\nexport const FILE_INVALID_TYPE = \"file-invalid-type\";\nexport const FILE_TOO_LARGE = \"file-too-large\";\nexport const FILE_TOO_SMALL = \"file-too-small\";\nexport const TOO_MANY_FILES = \"too-many-files\";\n\nexport enum ErrorCode {\n FileInvalidType = \"file-invalid-type\",\n FileTooLarge = \"file-too-large\",\n FileTooSmall = \"file-too-small\",\n TooManyFiles = \"too-many-files\"\n}\n\nexport function getInvalidTypeRejectionErr(accept: string = \"\"): FileError {\n const acceptArr = accept.split(\",\");\n const msg = acceptArr.length > 1 ? `one of ${acceptArr.join(\", \")}` : acceptArr[0];\n\n return {\n code: FILE_INVALID_TYPE,\n message: `File type must be ${msg}`\n };\n}\n\nconst FILE_SIZE_UNITS = [\"KB\", \"MB\", \"GB\", \"TB\", \"PB\"];\n\n/**\n * Format a byte count into a human-readable string, e.g. `1111` -> `1.08 KB`.\n * Values below 1 KB are kept in bytes to preserve the singular/plural wording.\n */\nfunction formatBytes(bytes: number): string {\n if (bytes < 1024) {\n return `${bytes} ${bytes === 1 ? \"byte\" : \"bytes\"}`;\n }\n\n let size = bytes / 1024;\n let unitIndex = 0;\n while (size >= 1024 && unitIndex < FILE_SIZE_UNITS.length - 1) {\n size /= 1024;\n unitIndex++;\n }\n\n // Round to 2 decimals, then drop trailing zeros (1.00 -> 1, 1.50 -> 1.5).\n return `${Number(size.toFixed(2))} ${FILE_SIZE_UNITS[unitIndex]}`;\n}\n\nexport function getTooLargeRejectionErr(maxSize: number): FileError {\n return {\n code: FILE_TOO_LARGE,\n message: `File is larger than ${formatBytes(maxSize)}`\n };\n}\n\nexport function getTooSmallRejectionErr(minSize: number): FileError {\n return {\n code: FILE_TOO_SMALL,\n message: `File is smaller than ${formatBytes(minSize)}`\n };\n}\n\nexport const TOO_MANY_FILES_REJECTION: FileError = {\n code: TOO_MANY_FILES,\n message: \"Too many files\"\n};\n\n/**\n * Check if the given file is a DataTransferItem with an empty type.\n *\n * During drag events, browsers may return DataTransferItem objects instead of File objects.\n * Some browsers (e.g., Chrome) return an empty MIME type for certain file types (like .md files)\n * on DataTransferItem during drag events, even though the type is correctly set during drop.\n */\nexport function isDataTransferItemWithEmptyType(file: File | DataTransferItem): boolean {\n return file.type === \"\" && typeof (file as DataTransferItem).getAsFile === \"function\";\n}\n\n/**\n * Check if file is accepted.\n *\n * Firefox versions prior to 53 return a bogus MIME type for every file drag,\n * so dragovers with that MIME type will always be accepted.\n *\n * Chrome/other browsers may return an empty MIME type for files during drag events,\n * so we accept those as well (we'll validate properly on drop).\n */\nexport function fileAccepted(file: File, accept?: string): [boolean, FileError | null] {\n const isAcceptable =\n file.type === \"application/x-moz-file\" || accepts(file, accept ?? \"\") || isDataTransferItemWithEmptyType(file);\n return [isAcceptable, isAcceptable ? null : getInvalidTypeRejectionErr(accept)];\n}\n\nexport function fileMatchSize(\n file: {size?: number | null},\n minSize?: number,\n maxSize?: number\n): [boolean, FileError | null] {\n if (isDefined(file.size)) {\n if (isDefined(minSize) && isDefined(maxSize)) {\n if (file.size > maxSize) return [false, getTooLargeRejectionErr(maxSize)];\n if (file.size < minSize) return [false, getTooSmallRejectionErr(minSize)];\n } else if (isDefined(minSize) && file.size < minSize) {\n return [false, getTooSmallRejectionErr(minSize)];\n } else if (isDefined(maxSize) && file.size > maxSize) {\n return [false, getTooLargeRejectionErr(maxSize)];\n }\n }\n return [true, null];\n}\n\nfunction isDefined<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n}\n\n/**\n * Check if a value is thenable (Promise-like), used to tell a synchronous validator result from an\n * asynchronous one.\n */\nexport function isThenable(value: unknown): value is PromiseLike<unknown> {\n return value != null && typeof (value as {then?: unknown}).then === \"function\";\n}\n\nexport function allFilesAccepted({\n files,\n accept,\n minSize,\n maxSize,\n multiple,\n maxFiles = 0,\n validator\n}: {\n files: File[];\n accept?: string;\n minSize?: number;\n maxSize?: number;\n multiple?: boolean;\n maxFiles?: number;\n validator?: (file: File) => FileError | readonly FileError[] | null;\n}): boolean {\n if ((!multiple && files.length > 1) || (multiple && maxFiles >= 1 && files.length > maxFiles)) {\n return false;\n }\n\n return files.every(file => {\n const [accepted] = fileAccepted(file, accept);\n const [sizeMatch] = fileMatchSize(file, minSize, maxSize);\n const customErrors = validator ? validator(file) : null;\n return accepted && sizeMatch && !customErrors;\n });\n}\n\n/**\n * The outcome of the drag-time acceptance check.\n *\n * - `accept` - every file passes the checks we can evaluate during a drag.\n * - `reject` - at least one file confidently fails a check we can fully evaluate during a\n * drag (the file count, or a non-empty MIME type that doesn't match `accept`).\n * - `unknown` - nothing confidently fails, but the outcome can't be confirmed until drop,\n * because a custom `validator` is configured and can't be evaluated yet.\n */\nexport type DragVerdict = \"accept\" | \"reject\" | \"unknown\";\n\n/**\n * Classify a set of dragged files for the `isDragAccept`/`isDragReject`/`isDragUnknown` states.\n *\n * During `dragenter`/`dragover` the browser only exposes `DataTransferItem`s, which carry a MIME\n * `type` but no file name, extension or size (see https://html.spec.whatwg.org/multipage/dnd.html#dndevents).\n * So the drag-time check is deliberately optimistic about anything it can't see:\n *\n * - The custom `validator` is **never** run here. It is typed `(file: File) => ...` and users\n * routinely read `file.name`/`file.size`, which are `undefined` on a `DataTransferItem` - running\n * it would throw and abort the whole drag handler (leaving `isDragActive` stuck at `false`).\n * See https://github.com/react-dropzone/react-dropzone/issues/1408\n * - When a `validator` is configured we therefore can't promise the files are acceptable, so the\n * verdict is `unknown` rather than a misleading `reject` (or a premature `accept`).\n * See https://github.com/react-dropzone/react-dropzone/issues/1244\n *\n * The full check (including the `validator`) still runs on drop in {@link fileAccepted}/`setFiles`.\n */\nexport function getDragVerdict({\n files,\n accept,\n minSize,\n maxSize,\n multiple,\n maxFiles = 0,\n validator\n}: {\n files: Array<File | DataTransferItem>;\n accept?: string;\n minSize?: number;\n maxSize?: number;\n multiple?: boolean;\n maxFiles?: number;\n // The validator is never invoked here (see the note above), so its async variant is accepted\n // purely so the same `validator` prop is assignable during a drag.\n validator?: (file: File) => ValidatorResult | Promise<ValidatorResult>;\n}): DragVerdict {\n // The file count is knowable during a drag, so an over-the-limit selection is a confident reject.\n if ((!multiple && files.length > 1) || (multiple && maxFiles >= 1 && files.length > maxFiles)) {\n return \"reject\";\n }\n\n const confidentlyRejected = files.some(file => {\n const [accepted] = fileAccepted(file as File, accept);\n const [sizeMatch] = fileMatchSize(file as File, minSize, maxSize);\n return !accepted || !sizeMatch;\n });\n if (confidentlyRejected) {\n return \"reject\";\n }\n\n // Built-in checks pass. A custom validator can only ever add rejections on drop, never rescue\n // one - so with a validator present the drag outcome is unknown until we have real Files.\n return validator ? \"unknown\" : \"accept\";\n}\n\n// React's synthetic events has event.isPropagationStopped,\n// but to remain compatibility with other libs (Preact) fall back\n// to check event.cancelBubble\nexport function isPropagationStopped(event: any): boolean {\n if (typeof event.isPropagationStopped === \"function\") {\n return event.isPropagationStopped();\n } else if (typeof event.cancelBubble !== \"undefined\") {\n return event.cancelBubble;\n }\n return false;\n}\n\nexport function isEvtWithFiles(event: any): boolean {\n if (!event.dataTransfer) {\n return !!event.target && !!event.target.files;\n }\n // https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types\n // https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types#file\n // Some Chromium drags omit \"Files\" from types (e.g. reporting only [\"text/plain\"])\n // while still exposing a kind: \"file\" entry in items - the same signal file-selector\n // uses to extract the files. Accept either so detection stays consistent. See #1409.\n return (\n Array.prototype.some.call(\n event.dataTransfer.types,\n (type: string) => type === \"Files\" || type === \"application/x-moz-file\"\n ) || Array.prototype.some.call(event.dataTransfer.items ?? [], isKindFile)\n );\n}\n\nexport function isKindFile(item: any): boolean {\n return typeof item === \"object\" && item !== null && item.kind === \"file\";\n}\n\n// allow the entire document to be a drag target\nexport function onDocumentDragOver(event: Event): void {\n event.preventDefault();\n}\n\nfunction isIe(userAgent: string): boolean {\n return userAgent.indexOf(\"MSIE\") !== -1 || userAgent.indexOf(\"Trident/\") !== -1;\n}\n\nfunction isEdge(userAgent: string): boolean {\n return userAgent.indexOf(\"Edge/\") !== -1;\n}\n\nexport function isIeOrEdge(userAgent: string = window.navigator.userAgent): boolean {\n return isIe(userAgent) || isEdge(userAgent);\n}\n\n/**\n * This is intended to be used to compose event handlers.\n * They are executed in order until one of them calls `event.isPropagationStopped()`.\n * Note that the check is done on the first invoke too,\n * meaning that if propagation was stopped before invoking the fns,\n * no handlers will be executed.\n */\nexport function composeEventHandlers(\n ...fns: Array<((event: any, ...args: any[]) => void) | null | undefined>\n): (event: any, ...args: any[]) => boolean {\n return (event: any, ...args: any[]) =>\n fns.some(fn => {\n if (!isPropagationStopped(event) && fn) {\n fn(event, ...args);\n }\n return isPropagationStopped(event);\n });\n}\n\n/**\n * canUseFileSystemAccessAPI checks if the File System Access API is supported by the browser.\n */\nexport function canUseFileSystemAccessAPI(): boolean {\n return \"showOpenFilePicker\" in window;\n}\n\n/**\n * Convert the `{accept}` dropzone prop to the `{types}` option for showOpenFilePicker.\n */\nexport function pickerOptionsFromAccept(accept?: Accept): Array<{description: string; accept: Accept}> | undefined {\n if (isDefined(accept)) {\n const acceptForPicker = Object.entries(accept)\n .filter(([mimeType, ext]) => {\n let ok = true;\n\n if (!isMIMEType(mimeType)) {\n console.warn(\n `Skipped \"${mimeType}\" because it is not a valid MIME type. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for a list of valid MIME types.`\n );\n ok = false;\n }\n\n if (!Array.isArray(ext) || !ext.every(isExt)) {\n console.warn(`Skipped \"${mimeType}\" because an invalid file extension was provided.`);\n ok = false;\n }\n\n return ok;\n })\n .reduce<Accept>((agg, [mimeType, ext]) => {\n agg[mimeType] = ext;\n return agg;\n }, {});\n return [\n {\n // description is required due to https://crbug.com/1264708\n description: \"Files\",\n accept: acceptForPicker\n }\n ];\n }\n return undefined;\n}\n\n/**\n * Convert the `{accept}` dropzone prop to a comma-separated accept attribute string.\n *\n * When `omitWildcardMimeTypesWithExtensions` is set, a wildcard MIME type (e.g. `image/*`)\n * that is paired with explicit extensions is dropped in favour of those extensions. The\n * accept attribute is an OR list, so leaving `image/*` in would make both the native file\n * picker and the drop-time validator accept ANY file of that type, ignoring the extension\n * restriction. The drag-time `isDragAccept` check keeps the wildcard because file names\n * (and therefore extensions) aren't readable during a drag.\n *\n * See https://github.com/react-dropzone/react-dropzone/issues/1220\n */\nexport function acceptPropAsAcceptAttr(\n accept?: Accept,\n {omitWildcardMimeTypesWithExtensions = false}: {omitWildcardMimeTypesWithExtensions?: boolean} = {}\n): string | undefined {\n if (isDefined(accept)) {\n return (\n Object.entries(accept)\n .reduce<string[]>((a, [mimeType, ext]) => {\n if (omitWildcardMimeTypesWithExtensions && isMIMETypeWildcard(mimeType) && ext.some(isExt)) {\n a.push(...ext);\n } else {\n a.push(mimeType, ...ext);\n }\n return a;\n }, [])\n // Silently discard invalid entries as pickerOptionsFromAccept warns about these\n .filter(v => isMIMEType(v) || isExt(v))\n .join(\",\")\n );\n }\n\n return undefined;\n}\n\n/**\n * Check if v is an exception caused by aborting a request (e.g window.showOpenFilePicker()).\n */\nexport function isAbort(v: any): boolean {\n return v instanceof DOMException && (v.name === \"AbortError\" || v.code === v.ABORT_ERR);\n}\n\n/**\n * Check if v is a security error.\n */\nexport function isSecurityError(v: any): boolean {\n return v instanceof DOMException && (v.name === \"SecurityError\" || v.code === v.SECURITY_ERR);\n}\n\n/**\n * Check if v is a \"not allowed\" error.\n *\n * Some browsers/configurations block `window.showOpenFilePicker()` outright and reject with a\n * `NotAllowedError` instead of showing the picker (e.g. Microsoft Edge for Business, or other\n * restrictive enterprise/security policies). We treat this like a security error and fall back\n * to the native `<input>`. See https://github.com/react-dropzone/react-dropzone/issues/1429\n */\nexport function isNotAllowedError(v: any): boolean {\n return v instanceof DOMException && v.name === \"NotAllowedError\";\n}\n\n/**\n * Check if v is a MIME type string.\n */\nexport function isMIMEType(v: string): boolean {\n return (\n v === \"audio/*\" ||\n v === \"video/*\" ||\n v === \"image/*\" ||\n v === \"text/*\" ||\n v === \"application/*\" ||\n /\\w+\\/[-+.\\w]+/g.test(v)\n );\n}\n\n/**\n * Check if v is a wildcard MIME type (e.g. `image/*`).\n */\nexport function isMIMETypeWildcard(v: string): boolean {\n return v.endsWith(\"/*\");\n}\n\n/**\n * Check if v is a file extension.\n */\nexport function isExt(v: string): boolean {\n return /^.*\\.[\\w]+$/.test(v);\n}\n","import {fromEvent} from \"file-selector\";\nimport type {FileWithPath} from \"file-selector\";\nimport type * as React from \"react\";\nimport {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef} from \"react\";\nimport {\n acceptPropAsAcceptAttr,\n canUseFileSystemAccessAPI,\n composeEventHandlers,\n ErrorCode,\n fileAccepted,\n fileMatchSize,\n getDragVerdict,\n isAbort,\n isEvtWithFiles,\n isIeOrEdge,\n isNotAllowedError,\n isThenable,\n isPropagationStopped,\n isSecurityError,\n onDocumentDragOver,\n pickerOptionsFromAccept,\n TOO_MANY_FILES_REJECTION\n} from \"./utils\";\nimport type {Accept, FileError, ValidatorResult} from \"./utils\";\n\nexport type {Accept, FileError, FileWithPath, ValidatorResult};\nexport {ErrorCode};\n\nexport interface DropzoneProps extends DropzoneOptions {\n children?: (state: DropzoneState) => React.ReactElement;\n}\n\nexport interface FileRejection {\n file: FileWithPath;\n errors: readonly FileError[];\n}\n\ntype SharedProps = \"multiple\" | \"onDragEnter\" | \"onDragOver\" | \"onDragLeave\";\n\nexport type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, SharedProps> & {\n accept?: Accept;\n minSize?: number;\n maxSize?: number;\n maxFiles?: number;\n preventDropOnDocument?: boolean;\n noClick?: boolean;\n noKeyboard?: boolean;\n noDrag?: boolean;\n noDragEventsBubbling?: boolean;\n disabled?: boolean;\n onDrop?: <T extends File>(acceptedFiles: T[], fileRejections: FileRejection[], event: DropEvent) => void;\n onDropAccepted?: <T extends File>(files: T[], event: DropEvent) => void;\n onDropRejected?: (fileRejections: FileRejection[], event: DropEvent) => void;\n getFilesFromEvent?: (event: DropEvent | Array<FileSystemFileHandle>) => Promise<Array<File | DataTransferItem>>;\n onFileDialogCancel?: () => void;\n onFileDialogOpen?: () => void;\n onError?: (err: Error) => void;\n /**\n * Custom validation, run once per file on drop/selection. Return `null` to accept the file, or a\n * {@link FileError} (or array of them) to reject it. May be `async` (return a `Promise`) to support\n * checks that can't run synchronously - e.g. reading image dimensions, inspecting file contents,\n * or calling an external service. While an async validator is pending, {@link DropzoneState.isProcessing}\n * is `true`, and `onDrop`/`onDropAccepted`/`onDropRejected` fire only once it settles. If the\n * validator throws or rejects, `onError` is called and the drop is discarded.\n *\n * Note: the validator never runs during a drag (a `DataTransferItem` has no name/size), so a\n * validator-configured dropzone is `isDragUnknown` until drop.\n */\n validator?: <T extends File>(file: T) => ValidatorResult | Promise<ValidatorResult>;\n /**\n * Override the message of any rejection error (built-in or custom). Called once per error;\n * receives the error and the file it belongs to and returns the message to use. Return\n * `error.message` for codes you don't want to change. Useful for localizing error messages.\n */\n getErrorMessage?: (error: FileError, file: File) => string;\n useFsAccessApi?: boolean;\n autoFocus?: boolean;\n};\n\nexport type DropEvent = React.DragEvent<HTMLElement> | React.ChangeEvent<HTMLInputElement> | DragEvent | Event;\n\nexport interface DropzoneRef {\n open: () => void;\n}\n\nexport type DropzoneState = DropzoneRef & {\n isFocused: boolean;\n isDragActive: boolean;\n isDragAccept: boolean;\n isDragReject: boolean;\n isDragUnknown: boolean;\n isDragGlobal: boolean;\n isFileDialogActive: boolean;\n /**\n * `true` while a drop/selection is being processed asynchronously - i.e. while `getFilesFromEvent`\n * reads the files and/or an async {@link DropzoneOptions.validator} runs. Spans the whole pipeline,\n * from when files start being read until validation settles. When both are synchronous (the default\n * `getFilesFromEvent` with no/async-free validator) the work resolves within a microtask, so it's\n * only observable for genuinely async work. Use it to show a spinner or disable UI while processing.\n */\n isProcessing: boolean;\n acceptedFiles: readonly FileWithPath[];\n fileRejections: readonly FileRejection[];\n rootRef: React.RefObject<HTMLElement>;\n inputRef: React.RefObject<HTMLInputElement>;\n getRootProps: <T extends DropzoneRootProps>(props?: T) => T;\n getInputProps: <T extends DropzoneInputProps>(props?: T) => T;\n};\n\nexport interface DropzoneRootProps extends React.HTMLAttributes<HTMLElement> {\n refKey?: string;\n [key: string]: any;\n}\n\nexport interface DropzoneInputProps extends React.InputHTMLAttributes<HTMLInputElement> {\n refKey?: string;\n}\n\n/**\n * Convenience wrapper component for the `useDropzone` hook\n *\n * ```jsx\n * <Dropzone>\n * {({getRootProps, getInputProps}) => (\n * <div {...getRootProps()}>\n * <input {...getInputProps()} />\n * <p>Drag 'n' drop some files here, or click to select files</p>\n * </div>\n * )}\n * </Dropzone>\n * ```\n */\nconst Dropzone: React.ForwardRefExoticComponent<DropzoneProps & React.RefAttributes<DropzoneRef>> = forwardRef<\n DropzoneRef,\n DropzoneProps\n>(({children, ...params}, ref) => {\n const {open, ...props} = useDropzone(params);\n\n useImperativeHandle(ref, () => ({open}), [open]);\n\n return <>{children?.({...props, open})}</>;\n});\n\nDropzone.displayName = \"Dropzone\";\n\nexport default Dropzone;\n\ninterface DropzoneInternalState {\n isFocused: boolean;\n isFileDialogActive: boolean;\n isDragActive: boolean;\n isDragAccept: boolean;\n isDragReject: boolean;\n isDragUnknown: boolean;\n isDragGlobal: boolean;\n isProcessing: boolean;\n acceptedFiles: FileWithPath[];\n fileRejections: FileRejection[];\n}\n\n/**\n * The per-file outcome of the built-in checks plus the (resolved) custom validator, assembled in\n * setFiles before the accepted/rejected split.\n */\ninterface PerFileResult {\n file: FileWithPath;\n accepted: boolean;\n acceptError: FileError | null;\n sizeMatch: boolean;\n sizeError: FileError | null;\n customErrors: ValidatorResult;\n}\n\nconst initialState: DropzoneInternalState = {\n isFocused: false,\n isFileDialogActive: false,\n isDragActive: false,\n isDragAccept: false,\n isDragReject: false,\n isDragUnknown: false,\n isDragGlobal: false,\n isProcessing: false,\n acceptedFiles: [],\n fileRejections: []\n};\n\n/**\n * A React hook that creates a drag 'n' drop area.\n *\n * ```jsx\n * function MyDropzone(props) {\n * const {getRootProps, getInputProps} = useDropzone({\n * onDrop: acceptedFiles => {\n * // do something with the File objects, e.g. upload to some server\n * }\n * });\n * return (\n * <div {...getRootProps()}>\n * <input {...getInputProps()} />\n * <p>Drag and drop some files here, or click to select files</p>\n * </div>\n * )\n * }\n * ```\n */\nexport function useDropzone(props: DropzoneOptions = {}): DropzoneState {\n const {\n accept,\n disabled = false,\n getFilesFromEvent = fromEvent,\n maxSize = Number.POSITIVE_INFINITY,\n minSize = 0,\n multiple = true,\n maxFiles = 0,\n onDragEnter,\n onDragLeave,\n onDragOver,\n onDrop,\n onDropAccepted,\n onDropRejected,\n onFileDialogCancel,\n onFileDialogOpen,\n useFsAccessApi = false,\n autoFocus = false,\n preventDropOnDocument = true,\n noClick = false,\n noKeyboard = false,\n noDrag = false,\n noDragEventsBubbling = false,\n onError,\n validator,\n getErrorMessage\n } = props;\n\n // `acceptAttr` keeps wildcard MIME types (e.g. `image/*`) so the drag-time\n // `isDragAccept`/`isDragReject` check can react to a file's MIME type - file names\n // (hence extensions) aren't readable during a drag.\n const acceptAttr = useMemo(() => acceptPropAsAcceptAttr(accept), [accept]);\n // `inputAcceptAttr` drops a wildcard MIME type when it is paired with extensions, so the\n // native picker and drop-time validation enforce the extensions instead of accepting any\n // file of that type. See https://github.com/react-dropzone/react-dropzone/issues/1220\n const inputAcceptAttr = useMemo(\n () =>\n acceptPropAsAcceptAttr(accept, {\n omitWildcardMimeTypesWithExtensions: true\n }),\n [accept]\n );\n const pickerTypes = useMemo(() => pickerOptionsFromAccept(accept), [accept]);\n\n const onFileDialogOpenCb = useMemo<(...args: any[]) => void>(\n () => (typeof onFileDialogOpen === \"function\" ? onFileDialogOpen : noop),\n [onFileDialogOpen]\n );\n const onFileDialogCancelCb = useMemo<(...args: any[]) => void>(\n () => (typeof onFileDialogCancel === \"function\" ? onFileDialogCancel : noop),\n [onFileDialogCancel]\n );\n\n const rootRef = useRef<HTMLElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n\n const [state, dispatch] = useReducer(reducer, initialState);\n const {isFocused, isFileDialogActive} = state;\n\n // Tracks the in-flight processing run - reading files (getFilesFromEvent) plus running an async\n // validator. A newer drop/selection aborts the previous run so slow async work can't resolve late\n // and clobber the state with stale results.\n const processingAbortRef = useRef<AbortController | null>(null);\n\n // Begin a processing run: supersede any run still in flight and flip {isProcessing} on. Returns\n // the run's AbortSignal, which downstream async steps check to bail if a newer run took over.\n const beginProcessing = useCallback(() => {\n processingAbortRef.current?.abort();\n const controller = new AbortController();\n processingAbortRef.current = controller;\n dispatch({type: \"setProcessing\", isProcessing: true});\n return controller.signal;\n }, []);\n\n // End a processing run by clearing {isProcessing} - but only if this run is still the active one.\n // A superseded run (signal aborted) leaves the flag to the run that replaced it.\n const endProcessing = useCallback((signal: AbortSignal) => {\n if (!signal.aborted) {\n dispatch({type: \"setProcessing\", isProcessing: false});\n }\n }, []);\n\n const fsAccessApiWorksRef = useRef(\n typeof window !== \"undefined\" && window.isSecureContext && useFsAccessApi && canUseFileSystemAccessAPI()\n );\n\n // Update file dialog active state when the window is focused on\n const onWindowFocus = () => {\n // Execute the timeout only if the file dialog is opened in the browser\n if (!fsAccessApiWorksRef.current && isFileDialogActive) {\n setTimeout(() => {\n if (inputRef.current) {\n const {files} = inputRef.current;\n\n if (!files?.length) {\n dispatch({type: \"closeDialog\"});\n onFileDialogCancelCb();\n }\n }\n }, 300);\n }\n };\n useEffect(() => {\n window.addEventListener(\"focus\", onWindowFocus, false);\n return () => {\n window.removeEventListener(\"focus\", onWindowFocus, false);\n };\n }, [inputRef, isFileDialogActive, onFileDialogCancelCb, fsAccessApiWorksRef]);\n\n const dragTargetsRef = useRef<EventTarget[]>([]);\n const globalDragTargetsRef = useRef<EventTarget[]>([]);\n const onDocumentDrop = (event: DragEvent) => {\n // This is a document-level, bubble-phase listener, so it runs *after* the event has already\n // bubbled through the dropzone root. If the drop landed inside the root and the instance's own\n // onDrop handler already prevented the default, there's nothing left to do.\n //\n // We must NOT bail out on `contains()` alone: when the dropzone is `disabled` or has `noDrag`,\n // the root has no onDrop handler, so nothing prevents the browser's default action and the file\n // is opened in the tab. Falling through to `preventDefault()` here keeps that from happening.\n // See https://github.com/react-dropzone/react-dropzone/issues/1362\n if (rootRef.current && event.target && rootRef.current.contains(event.target as Node) && event.defaultPrevented) {\n return;\n }\n event.preventDefault();\n dragTargetsRef.current = [];\n };\n\n useEffect(() => {\n if (preventDropOnDocument) {\n document.addEventListener(\"dragover\", onDocumentDragOver, false);\n document.addEventListener(\"drop\", onDocumentDrop, false);\n }\n\n return () => {\n if (preventDropOnDocument) {\n document.removeEventListener(\"dragover\", onDocumentDragOver);\n document.removeEventListener(\"drop\", onDocumentDrop);\n }\n };\n }, [rootRef, preventDropOnDocument]);\n\n // Track global drag state for document-level drag events\n useEffect(() => {\n const onDocumentDragEnter = (event: DragEvent) => {\n if (event.target) {\n globalDragTargetsRef.current = [...globalDragTargetsRef.current, event.target];\n }\n\n if (isEvtWithFiles(event)) {\n dispatch({isDragGlobal: true, type: \"setDragGlobal\"});\n }\n };\n\n const onDocumentDragLeave = (event: DragEvent) => {\n // Only deactivate once we've left all children\n globalDragTargetsRef.current = globalDragTargetsRef.current.filter(el => el !== event.target && el !== null);\n\n if (globalDragTargetsRef.current.length > 0) {\n return;\n }\n\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n const onDocumentDragEnd = () => {\n globalDragTargetsRef.current = [];\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n const onDocumentDropGlobal = () => {\n globalDragTargetsRef.current = [];\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n document.addEventListener(\"dragenter\", onDocumentDragEnter, false);\n document.addEventListener(\"dragleave\", onDocumentDragLeave, false);\n document.addEventListener(\"dragend\", onDocumentDragEnd, false);\n document.addEventListener(\"drop\", onDocumentDropGlobal, false);\n\n return () => {\n document.removeEventListener(\"dragenter\", onDocumentDragEnter);\n document.removeEventListener(\"dragleave\", onDocumentDragLeave);\n document.removeEventListener(\"dragend\", onDocumentDragEnd);\n document.removeEventListener(\"drop\", onDocumentDropGlobal);\n };\n }, [rootRef]);\n\n // Auto focus the root when autoFocus is true\n useEffect(() => {\n if (!disabled && autoFocus && rootRef.current) {\n rootRef.current.focus();\n }\n return () => {};\n }, [rootRef, autoFocus, disabled]);\n\n const onErrCb = useCallback(\n (e: Error) => {\n if (onError) {\n onError(e);\n } else {\n // Let the user know something's gone wrong if they haven't provided the onError cb.\n console.error(e);\n }\n },\n [onError]\n );\n\n const onDragEnterCb = useCallback(\n (event: any) => {\n event.preventDefault();\n // Persist here because we need the event later after getFilesFromEvent() is done\n event.persist?.();\n stopPropagation(event);\n\n dragTargetsRef.current = [...dragTargetsRef.current, event.target];\n\n if (isEvtWithFiles(event)) {\n Promise.resolve(getFilesFromEvent(event))\n .then(files => {\n if (isPropagationStopped(event) && !noDragEventsBubbling) {\n return;\n }\n\n const fileCount = files.length;\n // During a drag we only have DataTransferItems (MIME type, no name/size), so the\n // custom validator can't run yet - a validator-configured dropzone is \"unknown\" until\n // drop rather than a misleading accept/reject. See getDragVerdict for the details.\n const verdict =\n fileCount > 0\n ? getDragVerdict({\n files: files as Array<File | DataTransferItem>,\n accept: acceptAttr,\n minSize,\n maxSize,\n multiple,\n maxFiles,\n validator\n })\n : null;\n\n dispatch({\n isDragAccept: verdict === \"accept\",\n isDragReject: verdict === \"reject\",\n isDragUnknown: verdict === \"unknown\",\n isDragActive: true,\n type: \"setDraggedFiles\"\n });\n\n if (onDragEnter) {\n onDragEnter(event);\n }\n })\n .catch(e => onErrCb(e));\n }\n },\n [\n getFilesFromEvent,\n onDragEnter,\n onErrCb,\n noDragEventsBubbling,\n acceptAttr,\n minSize,\n maxSize,\n multiple,\n maxFiles,\n validator\n ]\n );\n\n const onDragOverCb = useCallback(\n (event: any) => {\n event.preventDefault();\n event.persist?.();\n stopPropagation(event);\n\n const hasFiles = isEvtWithFiles(event);\n if (hasFiles && event.dataTransfer) {\n try {\n event.dataTransfer.dropEffect = \"copy\";\n } catch {\n /* no-op */\n }\n }\n\n if (hasFiles && onDragOver) {\n onDragOver(event);\n }\n\n return false;\n },\n [onDragOver, noDragEventsBubbling]\n );\n\n const onDragLeaveCb = useCallback(\n (event: any) => {\n event.preventDefault();\n event.persist?.();\n stopPropagation(event);\n\n // Only deactivate once the dropzone and all children have been left\n const targets = dragTargetsRef.current.filter(target => rootRef.current?.contains(target as Node));\n // Make sure to remove a target present multiple times only once\n // (Firefox may fire dragenter/dragleave multiple times on the same element)\n const targetIdx = targets.indexOf(event.target);\n if (targetIdx !== -1) {\n targets.splice(targetIdx, 1);\n }\n dragTargetsRef.current = targets;\n if (targets.length > 0) {\n return;\n }\n\n dispatch({\n type: \"setDraggedFiles\",\n isDragActive: false,\n isDragAccept: false,\n isDragReject: false,\n isDragUnknown: false\n });\n\n if (isEvtWithFiles(event) && onDragLeave) {\n onDragLeave(event);\n }\n },\n [rootRef, onDragLeave, noDragEventsBubbling]\n );\n\n const setFiles = useCallback(\n async (files: FileWithPath[], event: any, signal: AbortSignal) => {\n const localizeError = (error: FileError, file: File): FileError =>\n getErrorMessage ? {...error, message: getErrorMessage(error, file)} : error;\n\n // Commit the per-file verdicts: split accepted/rejected, cap the surplus, update state and\n // fire the onDrop callbacks. Runs synchronously so nested-dropzone ordering is preserved on\n // the fast path (an onDrop handler calling stopPropagation must do so before a parent's onDrop\n // check - see the noDragEventsBubbling tests).\n const commit = (results: Array<PerFileResult>) => {\n const acceptedFiles: FileWithPath[] = [];\n const fileRejections: FileRejection[] = [];\n\n results.forEach(({file, accepted, acceptError, sizeMatch, sizeError, customErrors}) => {\n if (accepted && sizeMatch && !customErrors) {\n acceptedFiles.push(file);\n } else {\n let errors: Array<FileError | null> = [acceptError, sizeError];\n\n if (customErrors) {\n errors = errors.concat(customErrors);\n }\n\n fileRejections.push({\n file,\n errors: errors.filter((e): e is FileError => e != null).map(error => localizeError(error, file))\n });\n }\n });\n\n // Cap the accepted files at the configured limit and reject only the surplus (the files past\n // the limit) with a too-many-files error, instead of rejecting the whole batch. The limit is 1\n // when {multiple} is false, and {maxFiles} when {multiple} is true (0 means no limit). Files\n // that already failed the per-file checks above are in {fileRejections} and don't count here.\n // See https://github.com/react-dropzone/react-dropzone/issues/1355\n // and https://github.com/react-dropzone/react-dropzone/issues/1358\n const acceptedFilesLimit = multiple ? (maxFiles >= 1 ? maxFiles : Number.POSITIVE_INFINITY) : 1;\n if (acceptedFiles.length > acceptedFilesLimit) {\n const surplusFiles = acceptedFiles.splice(acceptedFilesLimit);\n surplusFiles.forEach(file => {\n fileRejections.push({file, errors: [localizeError(TOO_MANY_FILES_REJECTION, file)]});\n });\n }\n\n // Clears isProcessing back to false (see the reducer) in the same update that sets the files.\n dispatch({\n acceptedFiles,\n fileRejections,\n type: \"setFiles\"\n });\n\n if (onDrop) {\n onDrop(acceptedFiles, fileRejections, event);\n }\n\n if (fileRejections.length > 0 && onDropRejected) {\n onDropRejected(fileRejections, event);\n }\n\n if (acceptedFiles.length > 0 && onDropAccepted) {\n onDropAccepted(acceptedFiles, event);\n }\n };\n\n // Run the built-in checks synchronously and invoke the validator (which may return a value or\n // a Promise). customErrors is left as-is here so we can tell sync from async below.\n const pending = files.map(file => {\n const [accepted, acceptError] = fileAccepted(file, inputAcceptAttr);\n const [sizeMatch, sizeError] = fileMatchSize(file, minSize, maxSize);\n const customErrors = validator ? validator(file) : null;\n return {file, accepted, acceptError, sizeMatch, sizeError, customErrors};\n });\n\n // Callers check signal.aborted right before invoking setFiles (synchronously, no await in\n // between), so this run is guaranteed live here - the supersession guards below only matter\n // after we await the validator.\n\n // Fast path: no validator, or a synchronous one. Commit synchronously - no extra microtask\n // hop, so nested-dropzone ordering is preserved (an onDrop handler calling stopPropagation\n // must run before a parent's onDrop check - see the noDragEventsBubbling tests). commit's\n // dispatch also clears isProcessing.\n if (!pending.some(({customErrors}) => isThenable(customErrors))) {\n commit(pending as Array<PerFileResult>);\n return;\n }\n\n // Async path: at least one validator returned a Promise. isProcessing is already on (set when\n // the run began, before getFilesFromEvent); keep guarding against supersession while we await.\n let results: Array<PerFileResult>;\n try {\n results = await Promise.all(\n pending.map(async ({customErrors, ...rest}) => ({...rest, customErrors: await customErrors}))\n );\n } catch (e) {\n // A validator threw/rejected. If a newer run already superseded this one, let it own the\n // state; otherwise clear the processing flag and report the error via onError.\n if (!signal.aborted) {\n endProcessing(signal);\n onErrCb(e as Error);\n }\n return;\n }\n\n // A newer drop landed while we were validating - discard these stale results.\n if (signal.aborted) {\n return;\n }\n\n commit(results);\n },\n [\n dispatch,\n multiple,\n inputAcceptAttr,\n minSize,\n maxSize,\n maxFiles,\n onDrop,\n onDropAccepted,\n onDropRejected,\n validator,\n getErrorMessage,\n onErrCb,\n endProcessing\n ]\n );\n\n const onDropCb = useCallback(\n (event: any) => {\n event.preventDefault();\n // Persist here because we need the event later after getFilesFromEvent() is done\n event.persist?.();\n stopPropagation(event);\n\n dragTargetsRef.current = [];\n\n // Clear drag state before we begin processing so beginProcessing's isProcessing isn't reset.\n dispatch({type: \"reset\"});\n\n if (isEvtWithFiles(event)) {\n // Processing spans reading the files (getFilesFromEvent) and running the validator.\n const signal = beginProcessing();\n Promise.resolve(getFilesFromEvent(event))\n .then(files => {\n // A newer drop superseded this one while reading files - it owns isProcessing now.\n if (signal.aborted) {\n return;\n }\n if (isPropagationStopped(event) && !noDragEventsBubbling) {\n endProcessing(signal);\n return;\n }\n // setFiles handles validator errors internally (routing them to onError); the outer\n // catch here only fires for a getFilesFromEvent failure.\n return setFiles(files as FileWithPath[], event, signal);\n })\n .catch(e => {\n if (!signal.aborted) {\n endProcessing(signal);\n onErrCb(e);\n }\n });\n }\n },\n [getFilesFromEvent, setFiles, onErrCb, noDragEventsBubbling, beginProcessing, endProcessing]\n );\n\n // Fn for opening the file dialog programmatically\n const openFileDialog = useCallback(() => {\n // No point to use FS access APIs if context is not secure\n // https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts#feature_detection\n if (fsAccessApiWorksRef.current) {\n dispatch({type: \"openDialog\"});\n onFileDialogOpenCb();\n // https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker\n const opts = {\n multiple,\n types: pickerTypes\n };\n // Set once the user has picked file(s); processing then spans reading them (getFilesFromEvent)\n // and running the validator. Picker rejections (cancel, security) happen before this, so it\n // stays undefined there and no processing state is touched.\n let signal: AbortSignal | undefined;\n (window as any)\n .showOpenFilePicker(opts)\n .then((handles: any) => {\n signal = beginProcessing();\n return getFilesFromEvent(handles);\n })\n .then((files: Array<File | DataTransferItem>) => {\n // Close the dialog as soon as we have the selection; validation runs afterwards and is\n // reflected by isProcessing rather than by keeping the dialog \"active\".\n dispatch({type: \"closeDialog\"});\n // A drop elsewhere superseded this selection while reading files - it owns isProcessing.\n if (signal!.aborted) {\n return;\n }\n return setFiles(files as FileWithPath[], null, signal!);\n })\n .catch((e: any) => {\n // Clear any processing this run started (e.g. a getFilesFromEvent failure).\n if (signal) {\n endProcessing(signal);\n }\n // AbortError means the user canceled\n if (isAbort(e)) {\n onFileDialogCancelCb(e);\n dispatch({type: \"closeDialog\"});\n } else if (isSecurityError(e) || isNotAllowedError(e)) {\n // The FS access API is unusable here: either the context forbids it (SecurityError,\n // e.g. CORS) or the browser/platform blocked the picker (NotAllowedError, e.g. Edge\n // for Business - see https://github.com/react-dropzone/react-dropzone/issues/1429).\n // Stop using it and fall back to the native <input>.\n fsAccessApiWorksRef.current = false;\n if (inputRef.current) {\n inputRef.current.value = \"\";\n inputRef.current.click();\n } else {\n onErrCb(\n new Error(\n \"Cannot open the file picker because the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API is not supported and no <input> was provided.\"\n )\n );\n }\n } else {\n onErrCb(e);\n }\n });\n return;\n }\n\n if (inputRef.current) {\n dispatch({type: \"openDialog\"});\n onFileDialogOpenCb();\n inputRef.current.value = \"\";\n inputRef.current.click();\n }\n }, [\n dispatch,\n onFileDialogOpenCb,\n onFileDialogCancelCb,\n useFsAccessApi,\n setFiles,\n onErrCb,\n pickerTypes,\n multiple,\n beginProcessing,\n endProcessing\n ]);\n\n // Cb to open the file dialog when SPACE/ENTER occurs on the dropzone\n const onKeyDownCb = useCallback(\n (event: any) => {\n // Ignore keyboard events bubbling up the DOM tree\n if (!rootRef.current?.isEqualNode(event.target)) {\n return;\n }\n\n if (event.key === \" \" || event.key === \"Enter\" || event.keyCode === 32 || event.keyCode === 13) {\n event.preventDefault();\n openFileDialog();\n }\n },\n [rootRef, openFileDialog]\n );\n\n // Update focus state for the dropzone\n const onFocusCb = useCallback(() => {\n dispatch({type: \"focus\"});\n }, []);\n const onBlurCb = useCallback(() => {\n dispatch({type: \"blur\"});\n }, []);\n\n // Cb to open the file dialog when click occurs on the dropzone\n const onClickCb = useCallback(() => {\n if (noClick) {\n return;\n }\n\n // In IE11/Edge the file-browser dialog is blocking, therefore, use setTimeout()\n // to ensure React can handle state changes\n // See: https://github.com/react-dropzone/react-dropzone/issues/450\n if (isIeOrEdge()) {\n setTimeout(openFileDialog, 0);\n } else {\n openFileDialog();\n }\n }, [noClick, openFileDialog]);\n\n const composeHandler = (fn: any) => {\n return disabled ? null : fn;\n };\n\n const composeKeyboardHandler = (fn: any) => {\n return noKeyboard ? null : composeHandler(fn);\n };\n\n const composeDragHandler = (fn: any) => {\n return noDrag ? null : composeHandler(fn);\n };\n\n const stopPropagation = (event: any) => {\n if (noDragEventsBubbling) {\n event.stopPropagation();\n }\n };\n\n const getRootProps = useMemo(\n () =>\n ({\n refKey = \"ref\",\n role,\n onKeyDown,\n onFocus,\n onBlur,\n onClick,\n onDragEnter,\n onDragOver,\n onDragLeave,\n onDrop,\n ...rest\n }: DropzoneRootProps = {}) => ({\n onKeyDown: composeKeyboardHandler(composeEventHandlers(onKeyDown, onKeyDownCb)),\n onFocus: composeKeyboardHandler(composeEventHandlers(onFocus, onFocusCb)),\n onBlur: composeKeyboardHandler(composeEventHandlers(onBlur, onBlurCb)),\n onClick: composeHandler(composeEventHandlers(onClick, onClickCb)),\n onDragEnter: composeDragHandler(composeEventHandlers(onDragEnter, onDragEnterCb)),\n onDragOver: composeDragHandler(composeEventHandlers(onDragOver, onDragOverCb)),\n onDragLeave: composeDragHandler(composeEventHandlers(onDragLeave, onDragLeaveCb)),\n onDrop: composeDragHandler(composeEventHandlers(onDrop, onDropCb)),\n role: typeof role === \"string\" && role !== \"\" ? role : \"presentation\",\n [refKey]: rootRef,\n ...(!disabled && !noKeyboard ? {tabIndex: 0} : {}),\n ...(disabled ? {\"aria-disabled\": true} : {}),\n ...rest\n }),\n [\n rootRef,\n onKeyDownCb,\n onFocusCb,\n onBlurCb,\n onClickCb,\n onDragEnterCb,\n onDragOverCb,\n onDragLeaveCb,\n onDropCb,\n noKeyboard,\n noDrag,\n disabled\n ]\n );\n\n const onInputElementClick = useCallback((event: any) => {\n event.stopPropagation();\n }, []);\n\n const getInputProps = useMemo(\n () =>\n ({refKey = \"ref\", onChange, onClick, ...rest}: DropzoneInputProps = {}) => {\n const inputProps = {\n accept: inputAcceptAttr,\n multiple,\n type: \"file\",\n \"aria-label\": \"file upload\",\n // Hide the input without taking it out of flow. A visually-hidden input with\n // {position: absolute} makes the browser scroll the page to it whenever it gets\n // focus (e.g. inside a collapsed accordion), see #1413. Keeping it in flow as a\n // zero-size, transparent block avoids that while staying focusable so a {required}\n // input still triggers form validation, see #1268. Don't use {display: none} or\n // {visibility: hidden}: those make the input unfocusable and reintroduce #1268.\n style: {\n border: 0,\n display: \"block\",\n height: 0,\n margin: 0,\n opacity: 0,\n overflow: \"hidden\",\n padding: 0,\n width: 0\n },\n onChange: composeHandler(composeEventHandlers(onChange, onDropCb)),\n onClick: composeHandler(composeEventHandlers(onClick, onInputElementClick)),\n tabIndex: -1,\n [refKey]: inputRef\n };\n\n return {\n ...inputProps,\n ...rest\n };\n },\n [inputRef, accept, multiple, onDropCb, disabled]\n );\n\n return {\n ...state,\n isFocused: isFocused && !disabled,\n getRootProps,\n getInputProps,\n rootRef,\n inputRef,\n open: composeHandler(openFileDialog)\n } as unknown as DropzoneState;\n}\n\nfunction reducer(state: DropzoneInternalState, action: any): DropzoneInternalState {\n switch (action.type) {\n case \"focus\":\n return {\n ...state,\n isFocused: true\n };\n case \"blur\":\n return {\n ...state,\n isFocused: false\n };\n case \"openDialog\":\n return {\n ...initialState,\n isFileDialogActive: true\n };\n case \"closeDialog\":\n return {\n ...state,\n isFileDialogActive: false\n };\n case \"setDraggedFiles\":\n return {\n ...state,\n isDragActive: action.isDragActive,\n isDragAccept: action.isDragAccept,\n isDragReject: action.isDragReject,\n isDragUnknown: action.isDragUnknown\n };\n case \"setProcessing\":\n return {\n ...state,\n isProcessing: action.isProcessing\n };\n case \"setFiles\":\n return {\n ...state,\n acceptedFiles: action.acceptedFiles,\n fileRejections: action.fileRejections,\n isProcessing: false,\n isDragReject: false,\n isDragUnknown: false\n };\n case \"setDragGlobal\":\n return {\n ...state,\n isDragGlobal: action.isDragGlobal\n };\n case \"reset\":\n return {\n ...initialState\n };\n default:\n return state;\n }\n}\n\nfunction noop() {}\n"],"mappings":";;;;;AAKA,MAAM,UACJ,OAAO,eAAe,aAAa,aAAc,WAAuD;AAyB1G,MAAa,oBAAoB;AACjC,MAAa,iBAAiB;AAC9B,MAAa,iBAAiB;AAC9B,MAAa,iBAAiB;AAE9B,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,qBAAA;CACA,UAAA,kBAAA;CACA,UAAA,kBAAA;CACA,UAAA,kBAAA;;AACF,EAAA,CAAA,CAAA;AAEA,SAAgB,2BAA2B,SAAiB,IAAe;CACzE,MAAM,YAAY,OAAO,MAAM,GAA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,OAAO;CACX;AACF;AAEA,SAAS,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/utils/index.ts","../src/index.tsx"],"sourcesContent":["import attrAccept from \"attr-accept\";\n\n// attr-accept ships as a CommonJS module (`module.exports = { __esModule: true, default: fn }`).\n// Bundler interop surfaces its default export inconsistently — as the function under Node/Vitest,\n// but as `{ default: fn }` in some browser bundles. Normalize to the function.\nconst accepts =\n typeof attrAccept === \"function\" ? attrAccept : (attrAccept as unknown as {default: typeof attrAccept}).default;\n\n/**\n * A map of accepted MIME types to file extensions, as passed to the `accept` prop.\n */\nexport interface Accept {\n [key: string]: readonly string[];\n}\n\n/**\n * A file rejection error.\n */\nexport interface FileError {\n message: string;\n code: ErrorCode | string;\n}\n\n/**\n * What a custom `validator` returns: a single error, a list of errors, or `null` when the file\n * passes. A validator may return the result directly (synchronous) or wrapped in a `Promise`\n * (asynchronous, e.g. reading image dimensions or calling an external service).\n */\nexport type ValidatorResult = FileError | readonly FileError[] | null;\n\n// Error codes\nexport const FILE_INVALID_TYPE = \"file-invalid-type\";\nexport const FILE_TOO_LARGE = \"file-too-large\";\nexport const FILE_TOO_SMALL = \"file-too-small\";\nexport const TOO_MANY_FILES = \"too-many-files\";\n\nexport enum ErrorCode {\n FileInvalidType = \"file-invalid-type\",\n FileTooLarge = \"file-too-large\",\n FileTooSmall = \"file-too-small\",\n TooManyFiles = \"too-many-files\"\n}\n\nexport function getInvalidTypeRejectionErr(accept: string = \"\"): FileError {\n const acceptArr = accept.split(\",\");\n const msg = acceptArr.length > 1 ? `one of ${acceptArr.join(\", \")}` : acceptArr[0];\n\n return {\n code: FILE_INVALID_TYPE,\n message: `File type must be ${msg}`\n };\n}\n\nconst FILE_SIZE_UNITS = [\"KB\", \"MB\", \"GB\", \"TB\", \"PB\"];\n\n/**\n * Format a byte count into a human-readable string, e.g. `1111` -> `1.08 KB`.\n * Values below 1 KB are kept in bytes to preserve the singular/plural wording.\n */\nfunction formatBytes(bytes: number): string {\n if (bytes < 1024) {\n return `${bytes} ${bytes === 1 ? \"byte\" : \"bytes\"}`;\n }\n\n let size = bytes / 1024;\n let unitIndex = 0;\n while (size >= 1024 && unitIndex < FILE_SIZE_UNITS.length - 1) {\n size /= 1024;\n unitIndex++;\n }\n\n // Round to 2 decimals, then drop trailing zeros (1.00 -> 1, 1.50 -> 1.5).\n return `${Number(size.toFixed(2))} ${FILE_SIZE_UNITS[unitIndex]}`;\n}\n\nexport function getTooLargeRejectionErr(maxSize: number): FileError {\n return {\n code: FILE_TOO_LARGE,\n message: `File is larger than ${formatBytes(maxSize)}`\n };\n}\n\nexport function getTooSmallRejectionErr(minSize: number): FileError {\n return {\n code: FILE_TOO_SMALL,\n message: `File is smaller than ${formatBytes(minSize)}`\n };\n}\n\nexport const TOO_MANY_FILES_REJECTION: FileError = {\n code: TOO_MANY_FILES,\n message: \"Too many files\"\n};\n\n/**\n * Check if the given file is a DataTransferItem with an empty type.\n *\n * During drag events, browsers may return DataTransferItem objects instead of File objects.\n * Some browsers (e.g., Chrome) return an empty MIME type for certain file types (like .md files)\n * on DataTransferItem during drag events, even though the type is correctly set during drop.\n */\nexport function isDataTransferItemWithEmptyType(file: File | DataTransferItem): boolean {\n return file.type === \"\" && typeof (file as DataTransferItem).getAsFile === \"function\";\n}\n\n/**\n * Check if file is accepted.\n *\n * Firefox versions prior to 53 return a bogus MIME type for every file drag,\n * so dragovers with that MIME type will always be accepted.\n *\n * Chrome/other browsers may return an empty MIME type for files during drag events,\n * so we accept those as well (we'll validate properly on drop).\n */\nexport function fileAccepted(file: File, accept?: string): [boolean, FileError | null] {\n const isAcceptable =\n file.type === \"application/x-moz-file\" || accepts(file, accept ?? \"\") || isDataTransferItemWithEmptyType(file);\n return [isAcceptable, isAcceptable ? null : getInvalidTypeRejectionErr(accept)];\n}\n\nexport function fileMatchSize(\n file: {size?: number | null},\n minSize?: number,\n maxSize?: number\n): [boolean, FileError | null] {\n if (isDefined(file.size)) {\n if (isDefined(minSize) && isDefined(maxSize)) {\n if (file.size > maxSize) return [false, getTooLargeRejectionErr(maxSize)];\n if (file.size < minSize) return [false, getTooSmallRejectionErr(minSize)];\n } else if (isDefined(minSize) && file.size < minSize) {\n return [false, getTooSmallRejectionErr(minSize)];\n } else if (isDefined(maxSize) && file.size > maxSize) {\n return [false, getTooLargeRejectionErr(maxSize)];\n }\n }\n return [true, null];\n}\n\nfunction isDefined<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n}\n\n/**\n * Check if a value is thenable (Promise-like), used to tell a synchronous validator result from an\n * asynchronous one.\n */\nexport function isThenable(value: unknown): value is PromiseLike<unknown> {\n return value != null && typeof (value as {then?: unknown}).then === \"function\";\n}\n\nexport function allFilesAccepted({\n files,\n accept,\n minSize,\n maxSize,\n multiple,\n maxFiles = 0,\n validator\n}: {\n files: File[];\n accept?: string;\n minSize?: number;\n maxSize?: number;\n multiple?: boolean;\n maxFiles?: number;\n validator?: (file: File) => FileError | readonly FileError[] | null;\n}): boolean {\n if ((!multiple && files.length > 1) || (multiple && maxFiles >= 1 && files.length > maxFiles)) {\n return false;\n }\n\n return files.every(file => {\n const [accepted] = fileAccepted(file, accept);\n const [sizeMatch] = fileMatchSize(file, minSize, maxSize);\n const customErrors = validator ? validator(file) : null;\n return accepted && sizeMatch && !customErrors;\n });\n}\n\n/**\n * The outcome of the drag-time acceptance check.\n *\n * - `accept` - every file passes the checks we can evaluate during a drag.\n * - `reject` - at least one file confidently fails a check we can fully evaluate during a\n * drag (the file count, or a non-empty MIME type that doesn't match `accept`).\n * - `unknown` - nothing confidently fails, but the outcome can't be confirmed until drop,\n * because a custom `validator` is configured and can't be evaluated yet.\n */\nexport type DragVerdict = \"accept\" | \"reject\" | \"unknown\";\n\n/**\n * Classify a set of dragged files for the `isDragAccept`/`isDragReject`/`isDragUnknown` states.\n *\n * During `dragenter`/`dragover` the browser only exposes `DataTransferItem`s, which carry a MIME\n * `type` but no file name, extension or size (see https://html.spec.whatwg.org/multipage/dnd.html#dndevents).\n * So the drag-time check is deliberately optimistic about anything it can't see:\n *\n * - The custom `validator` is **never** run here. It is typed `(file: File) => ...` and users\n * routinely read `file.name`/`file.size`, which are `undefined` on a `DataTransferItem` - running\n * it would throw and abort the whole drag handler (leaving `isDragActive` stuck at `false`).\n * See https://github.com/react-dropzone/react-dropzone/issues/1408\n * - When a `validator` is configured we therefore can't promise the files are acceptable, so the\n * verdict is `unknown` rather than a misleading `reject` (or a premature `accept`).\n * See https://github.com/react-dropzone/react-dropzone/issues/1244\n *\n * The full check (including the `validator`) still runs on drop in {@link fileAccepted}/`setFiles`.\n */\nexport function getDragVerdict({\n files,\n accept,\n minSize,\n maxSize,\n multiple,\n maxFiles = 0,\n validator\n}: {\n files: Array<File | DataTransferItem>;\n accept?: string;\n minSize?: number;\n maxSize?: number;\n multiple?: boolean;\n maxFiles?: number;\n // The validator is never invoked here (see the note above), so its async variant is accepted\n // purely so the same `validator` prop is assignable during a drag.\n validator?: (file: File) => ValidatorResult | Promise<ValidatorResult>;\n}): DragVerdict {\n // The file count is knowable during a drag, so an over-the-limit selection is a confident reject.\n if ((!multiple && files.length > 1) || (multiple && maxFiles >= 1 && files.length > maxFiles)) {\n return \"reject\";\n }\n\n const confidentlyRejected = files.some(file => {\n const [accepted] = fileAccepted(file as File, accept);\n const [sizeMatch] = fileMatchSize(file as File, minSize, maxSize);\n return !accepted || !sizeMatch;\n });\n if (confidentlyRejected) {\n return \"reject\";\n }\n\n // Built-in checks pass. A custom validator can only ever add rejections on drop, never rescue\n // one - so with a validator present the drag outcome is unknown until we have real Files.\n return validator ? \"unknown\" : \"accept\";\n}\n\n// React's synthetic events has event.isPropagationStopped,\n// but to remain compatibility with other libs (Preact) fall back\n// to check event.cancelBubble\nexport function isPropagationStopped(event: any): boolean {\n if (typeof event.isPropagationStopped === \"function\") {\n return event.isPropagationStopped();\n } else if (typeof event.cancelBubble !== \"undefined\") {\n return event.cancelBubble;\n }\n return false;\n}\n\nexport function isEvtWithFiles(event: any): boolean {\n // A paste (ClipboardEvent) carries its DataTransfer under {clipboardData} rather than\n // {dataTransfer}, so a pasted screenshot is detected the same way as a drop.\n const dataTransfer = event.dataTransfer ?? event.clipboardData;\n if (!dataTransfer) {\n return !!event.target && !!event.target.files;\n }\n // https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types\n // https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types#file\n // Some Chromium drags omit \"Files\" from types (e.g. reporting only [\"text/plain\"])\n // while still exposing a kind: \"file\" entry in items - the same signal file-selector\n // uses to extract the files. Accept either so detection stays consistent. See #1409.\n return (\n Array.prototype.some.call(\n dataTransfer.types,\n (type: string) => type === \"Files\" || type === \"application/x-moz-file\"\n ) || Array.prototype.some.call(dataTransfer.items ?? [], isKindFile)\n );\n}\n\nexport function isKindFile(item: any): boolean {\n return typeof item === \"object\" && item !== null && item.kind === \"file\";\n}\n\n// allow the entire document to be a drag target\nexport function onDocumentDragOver(event: Event): void {\n event.preventDefault();\n}\n\nfunction isIe(userAgent: string): boolean {\n return userAgent.indexOf(\"MSIE\") !== -1 || userAgent.indexOf(\"Trident/\") !== -1;\n}\n\nfunction isEdge(userAgent: string): boolean {\n return userAgent.indexOf(\"Edge/\") !== -1;\n}\n\nexport function isIeOrEdge(userAgent: string = window.navigator.userAgent): boolean {\n return isIe(userAgent) || isEdge(userAgent);\n}\n\n/**\n * This is intended to be used to compose event handlers.\n * They are executed in order until one of them calls `event.isPropagationStopped()`.\n * Note that the check is done on the first invoke too,\n * meaning that if propagation was stopped before invoking the fns,\n * no handlers will be executed.\n */\nexport function composeEventHandlers(\n ...fns: Array<((event: any, ...args: any[]) => void) | null | undefined>\n): (event: any, ...args: any[]) => boolean {\n return (event: any, ...args: any[]) =>\n fns.some(fn => {\n if (!isPropagationStopped(event) && fn) {\n fn(event, ...args);\n }\n return isPropagationStopped(event);\n });\n}\n\n/**\n * canUseFileSystemAccessAPI checks if the File System Access API is supported by the browser.\n */\nexport function canUseFileSystemAccessAPI(): boolean {\n return \"showOpenFilePicker\" in window;\n}\n\n/**\n * Convert the `{accept}` dropzone prop to the `{types}` option for showOpenFilePicker.\n */\nexport function pickerOptionsFromAccept(accept?: Accept): Array<{description: string; accept: Accept}> | undefined {\n if (isDefined(accept)) {\n const acceptForPicker = Object.entries(accept)\n .filter(([mimeType, ext]) => {\n let ok = true;\n\n if (!isMIMEType(mimeType)) {\n console.warn(\n `Skipped \"${mimeType}\" because it is not a valid MIME type. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for a list of valid MIME types.`\n );\n ok = false;\n }\n\n if (!Array.isArray(ext) || !ext.every(isExt)) {\n console.warn(`Skipped \"${mimeType}\" because an invalid file extension was provided.`);\n ok = false;\n }\n\n return ok;\n })\n .reduce<Accept>((agg, [mimeType, ext]) => {\n agg[mimeType] = ext;\n return agg;\n }, {});\n return [\n {\n // description is required due to https://crbug.com/1264708\n description: \"Files\",\n accept: acceptForPicker\n }\n ];\n }\n return undefined;\n}\n\n/**\n * Convert the `{accept}` dropzone prop to a comma-separated accept attribute string.\n *\n * When `omitWildcardMimeTypesWithExtensions` is set, a wildcard MIME type (e.g. `image/*`)\n * that is paired with explicit extensions is dropped in favour of those extensions. The\n * accept attribute is an OR list, so leaving `image/*` in would make both the native file\n * picker and the drop-time validator accept ANY file of that type, ignoring the extension\n * restriction. The drag-time `isDragAccept` check keeps the wildcard because file names\n * (and therefore extensions) aren't readable during a drag.\n *\n * See https://github.com/react-dropzone/react-dropzone/issues/1220\n */\nexport function acceptPropAsAcceptAttr(\n accept?: Accept,\n {omitWildcardMimeTypesWithExtensions = false}: {omitWildcardMimeTypesWithExtensions?: boolean} = {}\n): string | undefined {\n if (isDefined(accept)) {\n return (\n Object.entries(accept)\n .reduce<string[]>((a, [mimeType, ext]) => {\n if (omitWildcardMimeTypesWithExtensions && isMIMETypeWildcard(mimeType) && ext.some(isExt)) {\n a.push(...ext);\n } else {\n a.push(mimeType, ...ext);\n }\n return a;\n }, [])\n // Silently discard invalid entries as pickerOptionsFromAccept warns about these\n .filter(v => isMIMEType(v) || isExt(v))\n .join(\",\")\n );\n }\n\n return undefined;\n}\n\n/**\n * Check if v is an exception caused by aborting a request (e.g window.showOpenFilePicker()).\n */\nexport function isAbort(v: any): boolean {\n return v instanceof DOMException && (v.name === \"AbortError\" || v.code === v.ABORT_ERR);\n}\n\n/**\n * Check if v is a security error.\n */\nexport function isSecurityError(v: any): boolean {\n return v instanceof DOMException && (v.name === \"SecurityError\" || v.code === v.SECURITY_ERR);\n}\n\n/**\n * Check if v is a \"not allowed\" error.\n *\n * Some browsers/configurations block `window.showOpenFilePicker()` outright and reject with a\n * `NotAllowedError` instead of showing the picker (e.g. Microsoft Edge for Business, or other\n * restrictive enterprise/security policies). We treat this like a security error and fall back\n * to the native `<input>`. See https://github.com/react-dropzone/react-dropzone/issues/1429\n */\nexport function isNotAllowedError(v: any): boolean {\n return v instanceof DOMException && v.name === \"NotAllowedError\";\n}\n\n/**\n * Check if v is a MIME type string.\n */\nexport function isMIMEType(v: string): boolean {\n return (\n v === \"audio/*\" ||\n v === \"video/*\" ||\n v === \"image/*\" ||\n v === \"text/*\" ||\n v === \"application/*\" ||\n /\\w+\\/[-+.\\w]+/g.test(v)\n );\n}\n\n/**\n * Check if v is a wildcard MIME type (e.g. `image/*`).\n */\nexport function isMIMETypeWildcard(v: string): boolean {\n return v.endsWith(\"/*\");\n}\n\n/**\n * Check if v is a file extension.\n */\nexport function isExt(v: string): boolean {\n return /^.*\\.[\\w]+$/.test(v);\n}\n","import {fromEvent} from \"file-selector\";\nimport type {FileWithPath} from \"file-selector\";\nimport type * as React from \"react\";\nimport {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef} from \"react\";\nimport {\n acceptPropAsAcceptAttr,\n canUseFileSystemAccessAPI,\n composeEventHandlers,\n ErrorCode,\n fileAccepted,\n fileMatchSize,\n getDragVerdict,\n isAbort,\n isEvtWithFiles,\n isIeOrEdge,\n isNotAllowedError,\n isThenable,\n isPropagationStopped,\n isSecurityError,\n onDocumentDragOver,\n pickerOptionsFromAccept,\n TOO_MANY_FILES_REJECTION\n} from \"./utils\";\nimport type {Accept, FileError, ValidatorResult} from \"./utils\";\n\nexport type {Accept, FileError, FileWithPath, ValidatorResult};\nexport {ErrorCode};\n\nexport interface DropzoneProps extends DropzoneOptions {\n children?: (state: DropzoneState) => React.ReactElement;\n}\n\nexport interface FileRejection {\n file: FileWithPath;\n errors: readonly FileError[];\n}\n\ntype SharedProps = \"multiple\" | \"onDragEnter\" | \"onDragOver\" | \"onDragLeave\";\n\nexport type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, SharedProps> & {\n accept?: Accept;\n minSize?: number;\n maxSize?: number;\n maxFiles?: number;\n preventDropOnDocument?: boolean;\n noClick?: boolean;\n noKeyboard?: boolean;\n noDrag?: boolean;\n noDragEventsBubbling?: boolean;\n /**\n * If true, disables paste-to-upload. By default, when the dropzone (or a focused child) receives a\n * paste that carries files - e.g. a screenshot pasted with Ctrl/Cmd+V - those files go through the\n * same `accept`/size/`validator` checks and `onDrop` callbacks as a drop. Pastes with no files\n * (plain text, etc.) are ignored and left untouched. See\n * https://github.com/react-dropzone/react-dropzone/issues/1210\n */\n noPaste?: boolean;\n disabled?: boolean;\n onDrop?: <T extends File>(acceptedFiles: T[], fileRejections: FileRejection[], event: DropEvent) => void;\n onDropAccepted?: <T extends File>(files: T[], event: DropEvent) => void;\n onDropRejected?: (fileRejections: FileRejection[], event: DropEvent) => void;\n getFilesFromEvent?: (event: DropEvent | Array<FileSystemFileHandle>) => Promise<Array<File | DataTransferItem>>;\n onFileDialogCancel?: () => void;\n onFileDialogOpen?: () => void;\n onError?: (err: Error) => void;\n /**\n * Custom validation, run once per file on drop/selection. Return `null` to accept the file, or a\n * {@link FileError} (or array of them) to reject it. May be `async` (return a `Promise`) to support\n * checks that can't run synchronously - e.g. reading image dimensions, inspecting file contents,\n * or calling an external service. While an async validator is pending, {@link DropzoneState.isProcessing}\n * is `true`, and `onDrop`/`onDropAccepted`/`onDropRejected` fire only once it settles. If the\n * validator throws or rejects, `onError` is called and the drop is discarded.\n *\n * Note: the validator never runs during a drag (a `DataTransferItem` has no name/size), so a\n * validator-configured dropzone is `isDragUnknown` until drop.\n */\n validator?: <T extends File>(file: T) => ValidatorResult | Promise<ValidatorResult>;\n /**\n * Override the message of any rejection error (built-in or custom). Called once per error;\n * receives the error and the file it belongs to and returns the message to use. Return\n * `error.message` for codes you don't want to change. Useful for localizing error messages.\n */\n getErrorMessage?: (error: FileError, file: File) => string;\n useFsAccessApi?: boolean;\n autoFocus?: boolean;\n};\n\nexport type DropEvent =\n | React.DragEvent<HTMLElement>\n | React.ChangeEvent<HTMLInputElement>\n | React.ClipboardEvent<HTMLElement>\n | DragEvent\n | ClipboardEvent\n | Event;\n\nexport interface DropzoneRef {\n open: () => void;\n}\n\nexport type DropzoneState = DropzoneRef & {\n isFocused: boolean;\n isDragActive: boolean;\n isDragAccept: boolean;\n isDragReject: boolean;\n isDragUnknown: boolean;\n isDragGlobal: boolean;\n isFileDialogActive: boolean;\n /**\n * `true` while a drop/selection is being processed asynchronously - i.e. while `getFilesFromEvent`\n * reads the files and/or an async {@link DropzoneOptions.validator} runs. Spans the whole pipeline,\n * from when files start being read until validation settles. When both are synchronous (the default\n * `getFilesFromEvent` with no/async-free validator) the work resolves within a microtask, so it's\n * only observable for genuinely async work. Use it to show a spinner or disable UI while processing.\n */\n isProcessing: boolean;\n acceptedFiles: readonly FileWithPath[];\n fileRejections: readonly FileRejection[];\n rootRef: React.RefObject<HTMLElement>;\n inputRef: React.RefObject<HTMLInputElement>;\n getRootProps: <T extends DropzoneRootProps>(props?: T) => T;\n getInputProps: <T extends DropzoneInputProps>(props?: T) => T;\n};\n\nexport interface DropzoneRootProps extends React.HTMLAttributes<HTMLElement> {\n refKey?: string;\n [key: string]: any;\n}\n\nexport interface DropzoneInputProps extends React.InputHTMLAttributes<HTMLInputElement> {\n refKey?: string;\n}\n\n/**\n * Convenience wrapper component for the `useDropzone` hook\n *\n * ```jsx\n * <Dropzone>\n * {({getRootProps, getInputProps}) => (\n * <div {...getRootProps()}>\n * <input {...getInputProps()} />\n * <p>Drag 'n' drop some files here, or click to select files</p>\n * </div>\n * )}\n * </Dropzone>\n * ```\n */\nconst Dropzone: React.ForwardRefExoticComponent<DropzoneProps & React.RefAttributes<DropzoneRef>> = forwardRef<\n DropzoneRef,\n DropzoneProps\n>(({children, ...params}, ref) => {\n const {open, ...props} = useDropzone(params);\n\n useImperativeHandle(ref, () => ({open}), [open]);\n\n return <>{children?.({...props, open})}</>;\n});\n\nDropzone.displayName = \"Dropzone\";\n\nexport default Dropzone;\n\ninterface DropzoneInternalState {\n isFocused: boolean;\n isFileDialogActive: boolean;\n isDragActive: boolean;\n isDragAccept: boolean;\n isDragReject: boolean;\n isDragUnknown: boolean;\n isDragGlobal: boolean;\n isProcessing: boolean;\n acceptedFiles: FileWithPath[];\n fileRejections: FileRejection[];\n}\n\n/**\n * The per-file outcome of the built-in checks plus the (resolved) custom validator, assembled in\n * setFiles before the accepted/rejected split.\n */\ninterface PerFileResult {\n file: FileWithPath;\n accepted: boolean;\n acceptError: FileError | null;\n sizeMatch: boolean;\n sizeError: FileError | null;\n customErrors: ValidatorResult;\n}\n\nconst initialState: DropzoneInternalState = {\n isFocused: false,\n isFileDialogActive: false,\n isDragActive: false,\n isDragAccept: false,\n isDragReject: false,\n isDragUnknown: false,\n isDragGlobal: false,\n isProcessing: false,\n acceptedFiles: [],\n fileRejections: []\n};\n\n/**\n * A React hook that creates a drag 'n' drop area.\n *\n * ```jsx\n * function MyDropzone(props) {\n * const {getRootProps, getInputProps} = useDropzone({\n * onDrop: acceptedFiles => {\n * // do something with the File objects, e.g. upload to some server\n * }\n * });\n * return (\n * <div {...getRootProps()}>\n * <input {...getInputProps()} />\n * <p>Drag and drop some files here, or click to select files</p>\n * </div>\n * )\n * }\n * ```\n */\nexport function useDropzone(props: DropzoneOptions = {}): DropzoneState {\n const {\n accept,\n disabled = false,\n getFilesFromEvent = fromEvent,\n maxSize = Number.POSITIVE_INFINITY,\n minSize = 0,\n multiple = true,\n maxFiles = 0,\n onDragEnter,\n onDragLeave,\n onDragOver,\n onDrop,\n onDropAccepted,\n onDropRejected,\n onFileDialogCancel,\n onFileDialogOpen,\n useFsAccessApi = false,\n autoFocus = false,\n preventDropOnDocument = true,\n noClick = false,\n noKeyboard = false,\n noDrag = false,\n noDragEventsBubbling = false,\n noPaste = false,\n onError,\n validator,\n getErrorMessage\n } = props;\n\n // `acceptAttr` keeps wildcard MIME types (e.g. `image/*`) so the drag-time\n // `isDragAccept`/`isDragReject` check can react to a file's MIME type - file names\n // (hence extensions) aren't readable during a drag.\n const acceptAttr = useMemo(() => acceptPropAsAcceptAttr(accept), [accept]);\n // `inputAcceptAttr` drops a wildcard MIME type when it is paired with extensions, so the\n // native picker and drop-time validation enforce the extensions instead of accepting any\n // file of that type. See https://github.com/react-dropzone/react-dropzone/issues/1220\n const inputAcceptAttr = useMemo(\n () =>\n acceptPropAsAcceptAttr(accept, {\n omitWildcardMimeTypesWithExtensions: true\n }),\n [accept]\n );\n const pickerTypes = useMemo(() => pickerOptionsFromAccept(accept), [accept]);\n\n const onFileDialogOpenCb = useMemo<(...args: any[]) => void>(\n () => (typeof onFileDialogOpen === \"function\" ? onFileDialogOpen : noop),\n [onFileDialogOpen]\n );\n const onFileDialogCancelCb = useMemo<(...args: any[]) => void>(\n () => (typeof onFileDialogCancel === \"function\" ? onFileDialogCancel : noop),\n [onFileDialogCancel]\n );\n\n const rootRef = useRef<HTMLElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n\n const [state, dispatch] = useReducer(reducer, initialState);\n const {isFocused, isFileDialogActive} = state;\n\n // Mirror {isFileDialogActive} into a ref so the memoized drag handlers can read the current value\n // without being recreated (and churning getRootProps/getInputProps) every time the dialog toggles.\n const isFileDialogActiveRef = useRef(isFileDialogActive);\n isFileDialogActiveRef.current = isFileDialogActive;\n\n // Tracks the in-flight processing run - reading files (getFilesFromEvent) plus running an async\n // validator. A newer drop/selection aborts the previous run so slow async work can't resolve late\n // and clobber the state with stale results.\n const processingAbortRef = useRef<AbortController | null>(null);\n\n // Begin a processing run: supersede any run still in flight and flip {isProcessing} on. Returns\n // the run's AbortSignal, which downstream async steps check to bail if a newer run took over.\n const beginProcessing = useCallback(() => {\n processingAbortRef.current?.abort();\n const controller = new AbortController();\n processingAbortRef.current = controller;\n dispatch({type: \"setProcessing\", isProcessing: true});\n return controller.signal;\n }, []);\n\n // End a processing run by clearing {isProcessing} - but only if this run is still the active one.\n // A superseded run (signal aborted) leaves the flag to the run that replaced it.\n const endProcessing = useCallback((signal: AbortSignal) => {\n if (!signal.aborted) {\n dispatch({type: \"setProcessing\", isProcessing: false});\n }\n }, []);\n\n const fsAccessApiWorksRef = useRef(\n typeof window !== \"undefined\" && window.isSecureContext && useFsAccessApi && canUseFileSystemAccessAPI()\n );\n\n // Update file dialog active state when the window is focused on\n const onWindowFocus = () => {\n // Execute the timeout only if the file dialog is opened in the browser\n if (!fsAccessApiWorksRef.current && isFileDialogActive) {\n setTimeout(() => {\n if (inputRef.current) {\n const {files} = inputRef.current;\n\n if (!files?.length) {\n dispatch({type: \"closeDialog\"});\n onFileDialogCancelCb();\n }\n }\n }, 300);\n }\n };\n useEffect(() => {\n window.addEventListener(\"focus\", onWindowFocus, false);\n return () => {\n window.removeEventListener(\"focus\", onWindowFocus, false);\n };\n }, [inputRef, isFileDialogActive, onFileDialogCancelCb, fsAccessApiWorksRef]);\n\n const dragTargetsRef = useRef<EventTarget[]>([]);\n const globalDragTargetsRef = useRef<EventTarget[]>([]);\n const onDocumentDrop = (event: DragEvent) => {\n // This is a document-level, bubble-phase listener, so it runs *after* the event has already\n // bubbled through the dropzone root. If the drop landed inside the root and the instance's own\n // onDrop handler already prevented the default, there's nothing left to do.\n //\n // We must NOT bail out on `contains()` alone: when the dropzone is `disabled` or has `noDrag`,\n // the root has no onDrop handler, so nothing prevents the browser's default action and the file\n // is opened in the tab. Falling through to `preventDefault()` here keeps that from happening.\n // See https://github.com/react-dropzone/react-dropzone/issues/1362\n if (rootRef.current && event.target && rootRef.current.contains(event.target as Node) && event.defaultPrevented) {\n return;\n }\n event.preventDefault();\n dragTargetsRef.current = [];\n };\n\n useEffect(() => {\n if (preventDropOnDocument) {\n document.addEventListener(\"dragover\", onDocumentDragOver, false);\n document.addEventListener(\"drop\", onDocumentDrop, false);\n }\n\n return () => {\n if (preventDropOnDocument) {\n document.removeEventListener(\"dragover\", onDocumentDragOver);\n document.removeEventListener(\"drop\", onDocumentDrop);\n }\n };\n }, [rootRef, preventDropOnDocument]);\n\n // Track global drag state for document-level drag events\n useEffect(() => {\n const onDocumentDragEnter = (event: DragEvent) => {\n if (event.target) {\n globalDragTargetsRef.current = [...globalDragTargetsRef.current, event.target];\n }\n\n if (isEvtWithFiles(event)) {\n dispatch({isDragGlobal: true, type: \"setDragGlobal\"});\n }\n };\n\n const onDocumentDragLeave = (event: DragEvent) => {\n // Only deactivate once we've left all children\n globalDragTargetsRef.current = globalDragTargetsRef.current.filter(el => el !== event.target && el !== null);\n\n if (globalDragTargetsRef.current.length > 0) {\n return;\n }\n\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n const onDocumentDragEnd = () => {\n globalDragTargetsRef.current = [];\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n const onDocumentDropGlobal = () => {\n globalDragTargetsRef.current = [];\n dispatch({isDragGlobal: false, type: \"setDragGlobal\"});\n };\n\n document.addEventListener(\"dragenter\", onDocumentDragEnter, false);\n document.addEventListener(\"dragleave\", onDocumentDragLeave, false);\n document.addEventListener(\"dragend\", onDocumentDragEnd, false);\n document.addEventListener(\"drop\", onDocumentDropGlobal, false);\n\n return () => {\n document.removeEventListener(\"dragenter\", onDocumentDragEnter);\n document.removeEventListener(\"dragleave\", onDocumentDragLeave);\n document.removeEventListener(\"dragend\", onDocumentDragEnd);\n document.removeEventListener(\"drop\", onDocumentDropGlobal);\n };\n }, [rootRef]);\n\n // Auto focus the root when autoFocus is true\n useEffect(() => {\n if (!disabled && autoFocus && rootRef.current) {\n rootRef.current.focus();\n }\n return () => {};\n }, [rootRef, autoFocus, disabled]);\n\n const onErrCb = useCallback(\n (e: Error) => {\n if (onError) {\n onError(e);\n } else {\n // Let the user know something's gone wrong if they haven't provided the onError cb.\n console.error(e);\n }\n },\n [onError]\n );\n\n const onDragEnterCb = useCallback(\n (event: any) => {\n event.preventDefault();\n // Persist here because we need the event later after getFilesFromEvent() is done\n event.persist?.();\n stopPropagation(event);\n\n // Ignore drags onto the dropzone while the file picker dialog is open: the page underneath a\n // live picker shouldn't react to (or accept) dropped files. See #1455. preventDefault() above\n // still runs so the browser doesn't try to open/navigate to a dropped file.\n if (isFileDialogActiveRef.current) {\n return;\n }\n\n dragTargetsRef.current = [...dragTargetsRef.current, event.target];\n\n if (isEvtWithFiles(event)) {\n Promise.resolve(getFilesFromEvent(event))\n .then(files => {\n if (isPropagationStopped(event) && !noDragEventsBubbling) {\n return;\n }\n\n const fileCount = files.length;\n // During a drag we only have DataTransferItems (MIME type, no name/size), so the\n // custom validator can't run yet - a validator-configured dropzone is \"unknown\" until\n // drop rather than a misleading accept/reject. See getDragVerdict for the details.\n const verdict =\n fileCount > 0\n ? getDragVerdict({\n files: files as Array<File | DataTransferItem>,\n accept: acceptAttr,\n minSize,\n maxSize,\n multiple,\n maxFiles,\n validator\n })\n : null;\n\n dispatch({\n isDragAccept: verdict === \"accept\",\n isDragReject: verdict === \"reject\",\n isDragUnknown: verdict === \"unknown\",\n isDragActive: true,\n type: \"setDraggedFiles\"\n });\n\n if (onDragEnter) {\n onDragEnter(event);\n }\n })\n .catch(e => onErrCb(e));\n }\n },\n [\n getFilesFromEvent,\n onDragEnter,\n onErrCb,\n noDragEventsBubbling,\n acceptAttr,\n minSize,\n maxSize,\n multiple,\n maxFiles,\n validator\n ]\n );\n\n const onDragOverCb = useCallback(\n (event: any) => {\n event.preventDefault();\n event.persist?.();\n stopPropagation(event);\n\n // Ignore drags over the dropzone while the file picker dialog is open. See #1455.\n if (isFileDialogActiveRef.current) {\n return false;\n }\n\n const hasFiles = isEvtWithFiles(event);\n if (hasFiles && event.dataTransfer) {\n try {\n event.dataTransfer.dropEffect = \"copy\";\n } catch {\n /* no-op */\n }\n }\n\n if (hasFiles && onDragOver) {\n onDragOver(event);\n }\n\n return false;\n },\n [onDragOver, noDragEventsBubbling]\n );\n\n const onDragLeaveCb = useCallback(\n (event: any) => {\n event.preventDefault();\n event.persist?.();\n stopPropagation(event);\n\n // Only deactivate once the dropzone and all children have been left\n const targets = dragTargetsRef.current.filter(target => rootRef.current?.contains(target as Node));\n // Make sure to remove a target present multiple times only once\n // (Firefox may fire dragenter/dragleave multiple times on the same element)\n const targetIdx = targets.indexOf(event.target);\n if (targetIdx !== -1) {\n targets.splice(targetIdx, 1);\n }\n dragTargetsRef.current = targets;\n if (targets.length > 0) {\n return;\n }\n\n dispatch({\n type: \"setDraggedFiles\",\n isDragActive: false,\n isDragAccept: false,\n isDragReject: false,\n isDragUnknown: false\n });\n\n if (isEvtWithFiles(event) && onDragLeave) {\n onDragLeave(event);\n }\n },\n [rootRef, onDragLeave, noDragEventsBubbling]\n );\n\n const setFiles = useCallback(\n async (files: FileWithPath[], event: any, signal: AbortSignal) => {\n const localizeError = (error: FileError, file: File): FileError =>\n getErrorMessage ? {...error, message: getErrorMessage(error, file)} : error;\n\n // Commit the per-file verdicts: split accepted/rejected, cap the surplus, update state and\n // fire the onDrop callbacks. Runs synchronously so nested-dropzone ordering is preserved on\n // the fast path (an onDrop handler calling stopPropagation must do so before a parent's onDrop\n // check - see the noDragEventsBubbling tests).\n const commit = (results: Array<PerFileResult>) => {\n const acceptedFiles: FileWithPath[] = [];\n const fileRejections: FileRejection[] = [];\n\n results.forEach(({file, accepted, acceptError, sizeMatch, sizeError, customErrors}) => {\n if (accepted && sizeMatch && !customErrors) {\n acceptedFiles.push(file);\n } else {\n let errors: Array<FileError | null> = [acceptError, sizeError];\n\n if (customErrors) {\n errors = errors.concat(customErrors);\n }\n\n fileRejections.push({\n file,\n errors: errors.filter((e): e is FileError => e != null).map(error => localizeError(error, file))\n });\n }\n });\n\n // Cap the accepted files at the configured limit and reject only the surplus (the files past\n // the limit) with a too-many-files error, instead of rejecting the whole batch. The limit is 1\n // when {multiple} is false, and {maxFiles} when {multiple} is true (0 means no limit). Files\n // that already failed the per-file checks above are in {fileRejections} and don't count here.\n // See https://github.com/react-dropzone/react-dropzone/issues/1355\n // and https://github.com/react-dropzone/react-dropzone/issues/1358\n const acceptedFilesLimit = multiple ? (maxFiles >= 1 ? maxFiles : Number.POSITIVE_INFINITY) : 1;\n if (acceptedFiles.length > acceptedFilesLimit) {\n const surplusFiles = acceptedFiles.splice(acceptedFilesLimit);\n surplusFiles.forEach(file => {\n fileRejections.push({file, errors: [localizeError(TOO_MANY_FILES_REJECTION, file)]});\n });\n }\n\n // Clears isProcessing back to false (see the reducer) in the same update that sets the files.\n dispatch({\n acceptedFiles,\n fileRejections,\n type: \"setFiles\"\n });\n\n if (onDrop) {\n onDrop(acceptedFiles, fileRejections, event);\n }\n\n if (fileRejections.length > 0 && onDropRejected) {\n onDropRejected(fileRejections, event);\n }\n\n if (acceptedFiles.length > 0 && onDropAccepted) {\n onDropAccepted(acceptedFiles, event);\n }\n };\n\n // Run the built-in checks synchronously and invoke the validator (which may return a value or\n // a Promise). customErrors is left as-is here so we can tell sync from async below.\n const pending = files.map(file => {\n const [accepted, acceptError] = fileAccepted(file, inputAcceptAttr);\n const [sizeMatch, sizeError] = fileMatchSize(file, minSize, maxSize);\n const customErrors = validator ? validator(file) : null;\n return {file, accepted, acceptError, sizeMatch, sizeError, customErrors};\n });\n\n // Callers check signal.aborted right before invoking setFiles (synchronously, no await in\n // between), so this run is guaranteed live here - the supersession guards below only matter\n // after we await the validator.\n\n // Fast path: no validator, or a synchronous one. Commit synchronously - no extra microtask\n // hop, so nested-dropzone ordering is preserved (an onDrop handler calling stopPropagation\n // must run before a parent's onDrop check - see the noDragEventsBubbling tests). commit's\n // dispatch also clears isProcessing.\n if (!pending.some(({customErrors}) => isThenable(customErrors))) {\n commit(pending as Array<PerFileResult>);\n return;\n }\n\n // Async path: at least one validator returned a Promise. isProcessing is already on (set when\n // the run began, before getFilesFromEvent); keep guarding against supersession while we await.\n let results: Array<PerFileResult>;\n try {\n results = await Promise.all(\n pending.map(async ({customErrors, ...rest}) => ({...rest, customErrors: await customErrors}))\n );\n } catch (e) {\n // A validator threw/rejected. If a newer run already superseded this one, let it own the\n // state; otherwise clear the processing flag and report the error via onError.\n if (!signal.aborted) {\n endProcessing(signal);\n onErrCb(e as Error);\n }\n return;\n }\n\n // A newer drop landed while we were validating - discard these stale results.\n if (signal.aborted) {\n return;\n }\n\n commit(results);\n },\n [\n dispatch,\n multiple,\n inputAcceptAttr,\n minSize,\n maxSize,\n maxFiles,\n onDrop,\n onDropAccepted,\n onDropRejected,\n validator,\n getErrorMessage,\n onErrCb,\n endProcessing\n ]\n );\n\n const onDropCb = useCallback(\n (event: any) => {\n event.preventDefault();\n // Persist here because we need the event later after getFilesFromEvent() is done\n event.persist?.();\n stopPropagation(event);\n\n dragTargetsRef.current = [];\n\n // Ignore a drop landing on the dropzone while the file picker dialog is open (see #1455).\n // Guard on {event.dataTransfer} so only real drag-drops are suppressed: the input's change\n // event (a file picked from the dialog) also runs through here while the dialog is still\n // flagged active, and that path must keep working. Returning before the reset below leaves\n // the dialog flag intact.\n if (isFileDialogActiveRef.current && event.dataTransfer) {\n return;\n }\n\n // Clear drag state before we begin processing so beginProcessing's isProcessing isn't reset.\n dispatch({type: \"reset\"});\n\n if (isEvtWithFiles(event)) {\n // Processing spans reading the files (getFilesFromEvent) and running the validator.\n const signal = beginProcessing();\n Promise.resolve(getFilesFromEvent(event))\n .then(files => {\n // A newer drop superseded this one while reading files - it owns isProcessing now.\n if (signal.aborted) {\n return;\n }\n if (isPropagationStopped(event) && !noDragEventsBubbling) {\n endProcessing(signal);\n return;\n }\n // setFiles handles validator errors internally (routing them to onError); the outer\n // catch here only fires for a getFilesFromEvent failure.\n return setFiles(files as FileWithPath[], event, signal);\n })\n .catch(e => {\n if (!signal.aborted) {\n endProcessing(signal);\n onErrCb(e);\n }\n });\n }\n },\n [getFilesFromEvent, setFiles, onErrCb, noDragEventsBubbling, beginProcessing, endProcessing]\n );\n\n // Cb to add files pasted into the dropzone (e.g. a screenshot pasted with Ctrl/Cmd+V). Fires when\n // the root - or a focused descendant, so a child <textarea> works too - receives a paste. Reuses\n // the same read/validate/onDrop pipeline as a drop.\n const onPasteCb = useCallback(\n (event: any) => {\n // Only act on a paste that carries files. Bail before preventDefault() for text/other pastes\n // so pasting into a child input keeps working normally.\n if (!isEvtWithFiles(event)) {\n return;\n }\n event.preventDefault();\n // Persist here because we need the event later after getFilesFromEvent() is done\n event.persist?.();\n stopPropagation(event);\n\n // Processing spans reading the files (getFilesFromEvent) and running the validator.\n const signal = beginProcessing();\n Promise.resolve(getFilesFromEvent(event))\n .then(files => {\n // A newer drop/paste superseded this one while reading files - it owns isProcessing now.\n if (signal.aborted) {\n return;\n }\n if (isPropagationStopped(event) && !noDragEventsBubbling) {\n endProcessing(signal);\n return;\n }\n return setFiles(files as FileWithPath[], event, signal);\n })\n .catch(e => {\n if (!signal.aborted) {\n endProcessing(signal);\n onErrCb(e);\n }\n });\n },\n [getFilesFromEvent, setFiles, onErrCb, noDragEventsBubbling, beginProcessing, endProcessing]\n );\n\n // Fn for opening the file dialog programmatically\n const openFileDialog = useCallback(() => {\n // No point to use FS access APIs if context is not secure\n // https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts#feature_detection\n if (fsAccessApiWorksRef.current) {\n dispatch({type: \"openDialog\"});\n onFileDialogOpenCb();\n // https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker\n const opts = {\n multiple,\n types: pickerTypes\n };\n // Set once the user has picked file(s); processing then spans reading them (getFilesFromEvent)\n // and running the validator. Picker rejections (cancel, security) happen before this, so it\n // stays undefined there and no processing state is touched.\n let signal: AbortSignal | undefined;\n (window as any)\n .showOpenFilePicker(opts)\n .then((handles: any) => {\n signal = beginProcessing();\n return getFilesFromEvent(handles);\n })\n .then((files: Array<File | DataTransferItem>) => {\n // Close the dialog as soon as we have the selection; validation runs afterwards and is\n // reflected by isProcessing rather than by keeping the dialog \"active\".\n dispatch({type: \"closeDialog\"});\n // A drop elsewhere superseded this selection while reading files - it owns isProcessing.\n if (signal!.aborted) {\n return;\n }\n return setFiles(files as FileWithPath[], null, signal!);\n })\n .catch((e: any) => {\n // Clear any processing this run started (e.g. a getFilesFromEvent failure).\n if (signal) {\n endProcessing(signal);\n }\n // AbortError means the user canceled\n if (isAbort(e)) {\n onFileDialogCancelCb(e);\n dispatch({type: \"closeDialog\"});\n } else if (isSecurityError(e) || isNotAllowedError(e)) {\n // The FS access API is unusable here: either the context forbids it (SecurityError,\n // e.g. CORS) or the browser/platform blocked the picker (NotAllowedError, e.g. Edge\n // for Business - see https://github.com/react-dropzone/react-dropzone/issues/1429).\n // Stop using it and fall back to the native <input>.\n fsAccessApiWorksRef.current = false;\n if (inputRef.current) {\n inputRef.current.value = \"\";\n inputRef.current.click();\n } else {\n onErrCb(\n new Error(\n \"Cannot open the file picker because the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API is not supported and no <input> was provided.\"\n )\n );\n }\n } else {\n onErrCb(e);\n }\n });\n return;\n }\n\n if (inputRef.current) {\n dispatch({type: \"openDialog\"});\n onFileDialogOpenCb();\n inputRef.current.value = \"\";\n inputRef.current.click();\n }\n }, [\n dispatch,\n onFileDialogOpenCb,\n onFileDialogCancelCb,\n useFsAccessApi,\n setFiles,\n onErrCb,\n pickerTypes,\n multiple,\n beginProcessing,\n endProcessing\n ]);\n\n // Cb to open the file dialog when SPACE/ENTER occurs on the dropzone\n const onKeyDownCb = useCallback(\n (event: any) => {\n // Ignore keyboard events bubbling up the DOM tree\n if (!rootRef.current?.isEqualNode(event.target)) {\n return;\n }\n\n if (event.key === \" \" || event.key === \"Enter\" || event.keyCode === 32 || event.keyCode === 13) {\n event.preventDefault();\n openFileDialog();\n }\n },\n [rootRef, openFileDialog]\n );\n\n // Update focus state for the dropzone\n const onFocusCb = useCallback(() => {\n dispatch({type: \"focus\"});\n }, []);\n const onBlurCb = useCallback(() => {\n dispatch({type: \"blur\"});\n }, []);\n\n // Cb to open the file dialog when click occurs on the dropzone\n const onClickCb = useCallback(() => {\n if (noClick) {\n return;\n }\n\n // In IE11/Edge the file-browser dialog is blocking, therefore, use setTimeout()\n // to ensure React can handle state changes\n // See: https://github.com/react-dropzone/react-dropzone/issues/450\n if (isIeOrEdge()) {\n setTimeout(openFileDialog, 0);\n } else {\n openFileDialog();\n }\n }, [noClick, openFileDialog]);\n\n const composeHandler = (fn: any) => {\n return disabled ? null : fn;\n };\n\n const composeKeyboardHandler = (fn: any) => {\n return noKeyboard ? null : composeHandler(fn);\n };\n\n const composeDragHandler = (fn: any) => {\n return noDrag ? null : composeHandler(fn);\n };\n\n const composePasteHandler = (fn: any) => {\n return noPaste ? null : composeHandler(fn);\n };\n\n const stopPropagation = (event: any) => {\n if (noDragEventsBubbling) {\n event.stopPropagation();\n }\n };\n\n const getRootProps = useMemo(\n () =>\n ({\n refKey = \"ref\",\n role,\n onKeyDown,\n onFocus,\n onBlur,\n onClick,\n onDragEnter,\n onDragOver,\n onDragLeave,\n onDrop,\n onPaste,\n ...rest\n }: DropzoneRootProps = {}) => ({\n onKeyDown: composeKeyboardHandler(composeEventHandlers(onKeyDown, onKeyDownCb)),\n onFocus: composeKeyboardHandler(composeEventHandlers(onFocus, onFocusCb)),\n onBlur: composeKeyboardHandler(composeEventHandlers(onBlur, onBlurCb)),\n onClick: composeHandler(composeEventHandlers(onClick, onClickCb)),\n onDragEnter: composeDragHandler(composeEventHandlers(onDragEnter, onDragEnterCb)),\n onDragOver: composeDragHandler(composeEventHandlers(onDragOver, onDragOverCb)),\n onDragLeave: composeDragHandler(composeEventHandlers(onDragLeave, onDragLeaveCb)),\n onDrop: composeDragHandler(composeEventHandlers(onDrop, onDropCb)),\n onPaste: composePasteHandler(composeEventHandlers(onPaste, onPasteCb)),\n role: typeof role === \"string\" && role !== \"\" ? role : \"presentation\",\n [refKey]: rootRef,\n ...(!disabled && !noKeyboard ? {tabIndex: 0} : {}),\n ...(disabled ? {\"aria-disabled\": true} : {}),\n ...rest\n }),\n [\n rootRef,\n onKeyDownCb,\n onFocusCb,\n onBlurCb,\n onClickCb,\n onDragEnterCb,\n onDragOverCb,\n onDragLeaveCb,\n onDropCb,\n onPasteCb,\n noKeyboard,\n noDrag,\n noPaste,\n disabled\n ]\n );\n\n const onInputElementClick = useCallback((event: any) => {\n event.stopPropagation();\n }, []);\n\n const getInputProps = useMemo(\n () =>\n ({refKey = \"ref\", onChange, onClick, ...rest}: DropzoneInputProps = {}) => {\n const inputProps = {\n accept: inputAcceptAttr,\n multiple,\n type: \"file\",\n \"aria-label\": \"file upload\",\n // Hide the input without taking it out of flow. A visually-hidden input with\n // {position: absolute} makes the browser scroll the page to it whenever it gets\n // focus (e.g. inside a collapsed accordion), see #1413. Keeping it in flow as a\n // zero-size, transparent block avoids that while staying focusable so a {required}\n // input still triggers form validation, see #1268. Don't use {display: none} or\n // {visibility: hidden}: those make the input unfocusable and reintroduce #1268.\n style: {\n border: 0,\n display: \"block\",\n height: 0,\n margin: 0,\n opacity: 0,\n overflow: \"hidden\",\n padding: 0,\n width: 0\n },\n onChange: composeHandler(composeEventHandlers(onChange, onDropCb)),\n onClick: composeHandler(composeEventHandlers(onClick, onInputElementClick)),\n tabIndex: -1,\n [refKey]: inputRef\n };\n\n return {\n ...inputProps,\n ...rest\n };\n },\n [inputRef, accept, multiple, onDropCb, disabled]\n );\n\n return {\n ...state,\n isFocused: isFocused && !disabled,\n getRootProps,\n getInputProps,\n rootRef,\n inputRef,\n open: composeHandler(openFileDialog)\n } as unknown as DropzoneState;\n}\n\nfunction reducer(state: DropzoneInternalState, action: any): DropzoneInternalState {\n switch (action.type) {\n case \"focus\":\n return {\n ...state,\n isFocused: true\n };\n case \"blur\":\n return {\n ...state,\n isFocused: false\n };\n case \"openDialog\":\n return {\n ...initialState,\n isFileDialogActive: true\n };\n case \"closeDialog\":\n return {\n ...state,\n isFileDialogActive: false\n };\n case \"setDraggedFiles\":\n return {\n ...state,\n isDragActive: action.isDragActive,\n isDragAccept: action.isDragAccept,\n isDragReject: action.isDragReject,\n isDragUnknown: action.isDragUnknown\n };\n case \"setProcessing\":\n return {\n ...state,\n isProcessing: action.isProcessing\n };\n case \"setFiles\":\n return {\n ...state,\n acceptedFiles: action.acceptedFiles,\n fileRejections: action.fileRejections,\n isProcessing: false,\n isDragReject: false,\n isDragUnknown: false\n };\n case \"setDragGlobal\":\n return {\n ...state,\n isDragGlobal: action.isDragGlobal\n };\n case \"reset\":\n return {\n ...initialState\n };\n default:\n return state;\n }\n}\n\nfunction noop() {}\n"],"mappings":";;;;;AAKA,MAAM,UACJ,OAAO,eAAe,aAAa,aAAc,WAAuD;AAyB1G,MAAa,oBAAoB;AACjC,MAAa,iBAAiB;AAC9B,MAAa,iBAAiB;AAC9B,MAAa,iBAAiB;AAE9B,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,qBAAA;CACA,UAAA,kBAAA;CACA,UAAA,kBAAA;CACA,UAAA,kBAAA;;AACF,EAAA,CAAA,CAAA;AAEA,SAAgB,2BAA2B,SAAiB,IAAe;CACzE,MAAM,YAAY,OAAO,MAAM,GAAG;CAClC,MAAM,MAAM,UAAU,SAAS,IAAI,UAAU,UAAU,KAAK,IAAI,MAAM,UAAU;CAEhF,OAAO;EACL,MAAM;EACN,SAAS,qBAAqB;CAChC;AACF;AAEA,MAAM,kBAAkB;CAAC;CAAM;CAAM;CAAM;CAAM;AAAI;;;;;AAMrD,SAAS,YAAY,OAAuB;CAC1C,IAAI,QAAQ,MACV,O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QAAoC;CACjF,QAAQ,OAAO,MAAf;EACE,KAAK,SACH,OAAO;GACL,GAAG;GACH,WAAW;EACb;EACF,KAAK,QACH,OAAO;GACL,GAAG;GACH,WAAW;EACb;EACF,KAAK,cACH,OAAO;GACL,GAAG;GACH,oBAAoB;EACtB;EACF,KAAK,eACH,OAAO;GACL,GAAG;GACH,oBAAoB;EACtB;EACF,KAAK,mBACH,OAAO;GACL,GAAG;GACH,cAAc,OAAO;GACrB,cAAc,OAAO;GACrB,cAAc,OAAO;GACrB,eAAe,OAAO;EACxB;EACF,KAAK,iBACH,OAAO;GACL,GAAG;GACH,cAAc,OAAO;EACvB;EACF,KAAK,YACH,OAAO;GACL,GAAG;GACH,eAAe,OAAO;GACtB,gBAAgB,OAAO;GACvB,cAAc;GACd,cAAc;GACd,eAAe;EACjB;EACF,KAAK,iBACH,OAAO;GACL,GAAG;GACH,cAAc,OAAO;EACvB;EACF,KAAK,SACH,OAAO,EACL,GAAG,aACL;EACF,SACE,OAAO;CACX;AACF;AAEA,SAAS,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-dropzone",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.2.0",
|
|
4
4
|
"description": "Simple HTML5 drag-drop zone with React.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"drag",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"attr-accept": "^2.2.5",
|
|
74
|
-
"file-selector": "^4.0
|
|
74
|
+
"file-selector": "^4.1.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@semantic-release/changelog": "^6.0.0",
|
|
@@ -87,18 +87,18 @@
|
|
|
87
87
|
"@types/react-dom": "^19.0.0",
|
|
88
88
|
"@vitest/coverage-v8": "^4.1.10",
|
|
89
89
|
"jsdom": "^29.1.1",
|
|
90
|
-
"oxfmt": "^0.
|
|
91
|
-
"oxlint": "^1.
|
|
90
|
+
"oxfmt": "^0.60.0",
|
|
91
|
+
"oxlint": "^1.75.0",
|
|
92
92
|
"oxlint-tsgolint": "^0.24.0",
|
|
93
|
-
"react": "^19.
|
|
94
|
-
"react-dom": "^19.
|
|
95
|
-
"semantic-release": "^25.0.
|
|
96
|
-
"styled-components": "^6.4.
|
|
97
|
-
"tsdown": "^0.22.
|
|
93
|
+
"react": "^19.2.8",
|
|
94
|
+
"react-dom": "^19.2.8",
|
|
95
|
+
"semantic-release": "^25.0.8",
|
|
96
|
+
"styled-components": "^6.4.4",
|
|
97
|
+
"tsdown": "^0.22.14",
|
|
98
98
|
"typescript": "^7.0.2",
|
|
99
99
|
"vitest": "^4.1.10",
|
|
100
|
-
"vocs": "^2.
|
|
101
|
-
"waku": "^1.0.0-beta.
|
|
100
|
+
"vocs": "^2.6.2",
|
|
101
|
+
"waku": "^1.0.0-beta.8"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"@types/react": "*",
|
package/src/index.tsx
CHANGED
|
@@ -47,6 +47,14 @@ export type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, SharedProps> &
|
|
|
47
47
|
noKeyboard?: boolean;
|
|
48
48
|
noDrag?: boolean;
|
|
49
49
|
noDragEventsBubbling?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* If true, disables paste-to-upload. By default, when the dropzone (or a focused child) receives a
|
|
52
|
+
* paste that carries files - e.g. a screenshot pasted with Ctrl/Cmd+V - those files go through the
|
|
53
|
+
* same `accept`/size/`validator` checks and `onDrop` callbacks as a drop. Pastes with no files
|
|
54
|
+
* (plain text, etc.) are ignored and left untouched. See
|
|
55
|
+
* https://github.com/react-dropzone/react-dropzone/issues/1210
|
|
56
|
+
*/
|
|
57
|
+
noPaste?: boolean;
|
|
50
58
|
disabled?: boolean;
|
|
51
59
|
onDrop?: <T extends File>(acceptedFiles: T[], fileRejections: FileRejection[], event: DropEvent) => void;
|
|
52
60
|
onDropAccepted?: <T extends File>(files: T[], event: DropEvent) => void;
|
|
@@ -77,7 +85,13 @@ export type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, SharedProps> &
|
|
|
77
85
|
autoFocus?: boolean;
|
|
78
86
|
};
|
|
79
87
|
|
|
80
|
-
export type DropEvent =
|
|
88
|
+
export type DropEvent =
|
|
89
|
+
| React.DragEvent<HTMLElement>
|
|
90
|
+
| React.ChangeEvent<HTMLInputElement>
|
|
91
|
+
| React.ClipboardEvent<HTMLElement>
|
|
92
|
+
| DragEvent
|
|
93
|
+
| ClipboardEvent
|
|
94
|
+
| Event;
|
|
81
95
|
|
|
82
96
|
export interface DropzoneRef {
|
|
83
97
|
open: () => void;
|
|
@@ -227,6 +241,7 @@ export function useDropzone(props: DropzoneOptions = {}): DropzoneState {
|
|
|
227
241
|
noKeyboard = false,
|
|
228
242
|
noDrag = false,
|
|
229
243
|
noDragEventsBubbling = false,
|
|
244
|
+
noPaste = false,
|
|
230
245
|
onError,
|
|
231
246
|
validator,
|
|
232
247
|
getErrorMessage
|
|
@@ -263,6 +278,11 @@ export function useDropzone(props: DropzoneOptions = {}): DropzoneState {
|
|
|
263
278
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
264
279
|
const {isFocused, isFileDialogActive} = state;
|
|
265
280
|
|
|
281
|
+
// Mirror {isFileDialogActive} into a ref so the memoized drag handlers can read the current value
|
|
282
|
+
// without being recreated (and churning getRootProps/getInputProps) every time the dialog toggles.
|
|
283
|
+
const isFileDialogActiveRef = useRef(isFileDialogActive);
|
|
284
|
+
isFileDialogActiveRef.current = isFileDialogActive;
|
|
285
|
+
|
|
266
286
|
// Tracks the in-flight processing run - reading files (getFilesFromEvent) plus running an async
|
|
267
287
|
// validator. A newer drop/selection aborts the previous run so slow async work can't resolve late
|
|
268
288
|
// and clobber the state with stale results.
|
|
@@ -418,6 +438,13 @@ export function useDropzone(props: DropzoneOptions = {}): DropzoneState {
|
|
|
418
438
|
event.persist?.();
|
|
419
439
|
stopPropagation(event);
|
|
420
440
|
|
|
441
|
+
// Ignore drags onto the dropzone while the file picker dialog is open: the page underneath a
|
|
442
|
+
// live picker shouldn't react to (or accept) dropped files. See #1455. preventDefault() above
|
|
443
|
+
// still runs so the browser doesn't try to open/navigate to a dropped file.
|
|
444
|
+
if (isFileDialogActiveRef.current) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
421
448
|
dragTargetsRef.current = [...dragTargetsRef.current, event.target];
|
|
422
449
|
|
|
423
450
|
if (isEvtWithFiles(event)) {
|
|
@@ -479,6 +506,11 @@ export function useDropzone(props: DropzoneOptions = {}): DropzoneState {
|
|
|
479
506
|
event.persist?.();
|
|
480
507
|
stopPropagation(event);
|
|
481
508
|
|
|
509
|
+
// Ignore drags over the dropzone while the file picker dialog is open. See #1455.
|
|
510
|
+
if (isFileDialogActiveRef.current) {
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
|
|
482
514
|
const hasFiles = isEvtWithFiles(event);
|
|
483
515
|
if (hasFiles && event.dataTransfer) {
|
|
484
516
|
try {
|
|
@@ -667,6 +699,15 @@ export function useDropzone(props: DropzoneOptions = {}): DropzoneState {
|
|
|
667
699
|
|
|
668
700
|
dragTargetsRef.current = [];
|
|
669
701
|
|
|
702
|
+
// Ignore a drop landing on the dropzone while the file picker dialog is open (see #1455).
|
|
703
|
+
// Guard on {event.dataTransfer} so only real drag-drops are suppressed: the input's change
|
|
704
|
+
// event (a file picked from the dialog) also runs through here while the dialog is still
|
|
705
|
+
// flagged active, and that path must keep working. Returning before the reset below leaves
|
|
706
|
+
// the dialog flag intact.
|
|
707
|
+
if (isFileDialogActiveRef.current && event.dataTransfer) {
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
|
|
670
711
|
// Clear drag state before we begin processing so beginProcessing's isProcessing isn't reset.
|
|
671
712
|
dispatch({type: "reset"});
|
|
672
713
|
|
|
@@ -698,6 +739,45 @@ export function useDropzone(props: DropzoneOptions = {}): DropzoneState {
|
|
|
698
739
|
[getFilesFromEvent, setFiles, onErrCb, noDragEventsBubbling, beginProcessing, endProcessing]
|
|
699
740
|
);
|
|
700
741
|
|
|
742
|
+
// Cb to add files pasted into the dropzone (e.g. a screenshot pasted with Ctrl/Cmd+V). Fires when
|
|
743
|
+
// the root - or a focused descendant, so a child <textarea> works too - receives a paste. Reuses
|
|
744
|
+
// the same read/validate/onDrop pipeline as a drop.
|
|
745
|
+
const onPasteCb = useCallback(
|
|
746
|
+
(event: any) => {
|
|
747
|
+
// Only act on a paste that carries files. Bail before preventDefault() for text/other pastes
|
|
748
|
+
// so pasting into a child input keeps working normally.
|
|
749
|
+
if (!isEvtWithFiles(event)) {
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
event.preventDefault();
|
|
753
|
+
// Persist here because we need the event later after getFilesFromEvent() is done
|
|
754
|
+
event.persist?.();
|
|
755
|
+
stopPropagation(event);
|
|
756
|
+
|
|
757
|
+
// Processing spans reading the files (getFilesFromEvent) and running the validator.
|
|
758
|
+
const signal = beginProcessing();
|
|
759
|
+
Promise.resolve(getFilesFromEvent(event))
|
|
760
|
+
.then(files => {
|
|
761
|
+
// A newer drop/paste superseded this one while reading files - it owns isProcessing now.
|
|
762
|
+
if (signal.aborted) {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
if (isPropagationStopped(event) && !noDragEventsBubbling) {
|
|
766
|
+
endProcessing(signal);
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
return setFiles(files as FileWithPath[], event, signal);
|
|
770
|
+
})
|
|
771
|
+
.catch(e => {
|
|
772
|
+
if (!signal.aborted) {
|
|
773
|
+
endProcessing(signal);
|
|
774
|
+
onErrCb(e);
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
},
|
|
778
|
+
[getFilesFromEvent, setFiles, onErrCb, noDragEventsBubbling, beginProcessing, endProcessing]
|
|
779
|
+
);
|
|
780
|
+
|
|
701
781
|
// Fn for opening the file dialog programmatically
|
|
702
782
|
const openFileDialog = useCallback(() => {
|
|
703
783
|
// No point to use FS access APIs if context is not secure
|
|
@@ -833,6 +913,10 @@ export function useDropzone(props: DropzoneOptions = {}): DropzoneState {
|
|
|
833
913
|
return noDrag ? null : composeHandler(fn);
|
|
834
914
|
};
|
|
835
915
|
|
|
916
|
+
const composePasteHandler = (fn: any) => {
|
|
917
|
+
return noPaste ? null : composeHandler(fn);
|
|
918
|
+
};
|
|
919
|
+
|
|
836
920
|
const stopPropagation = (event: any) => {
|
|
837
921
|
if (noDragEventsBubbling) {
|
|
838
922
|
event.stopPropagation();
|
|
@@ -852,6 +936,7 @@ export function useDropzone(props: DropzoneOptions = {}): DropzoneState {
|
|
|
852
936
|
onDragOver,
|
|
853
937
|
onDragLeave,
|
|
854
938
|
onDrop,
|
|
939
|
+
onPaste,
|
|
855
940
|
...rest
|
|
856
941
|
}: DropzoneRootProps = {}) => ({
|
|
857
942
|
onKeyDown: composeKeyboardHandler(composeEventHandlers(onKeyDown, onKeyDownCb)),
|
|
@@ -862,6 +947,7 @@ export function useDropzone(props: DropzoneOptions = {}): DropzoneState {
|
|
|
862
947
|
onDragOver: composeDragHandler(composeEventHandlers(onDragOver, onDragOverCb)),
|
|
863
948
|
onDragLeave: composeDragHandler(composeEventHandlers(onDragLeave, onDragLeaveCb)),
|
|
864
949
|
onDrop: composeDragHandler(composeEventHandlers(onDrop, onDropCb)),
|
|
950
|
+
onPaste: composePasteHandler(composeEventHandlers(onPaste, onPasteCb)),
|
|
865
951
|
role: typeof role === "string" && role !== "" ? role : "presentation",
|
|
866
952
|
[refKey]: rootRef,
|
|
867
953
|
...(!disabled && !noKeyboard ? {tabIndex: 0} : {}),
|
|
@@ -878,8 +964,10 @@ export function useDropzone(props: DropzoneOptions = {}): DropzoneState {
|
|
|
878
964
|
onDragOverCb,
|
|
879
965
|
onDragLeaveCb,
|
|
880
966
|
onDropCb,
|
|
967
|
+
onPasteCb,
|
|
881
968
|
noKeyboard,
|
|
882
969
|
noDrag,
|
|
970
|
+
noPaste,
|
|
883
971
|
disabled
|
|
884
972
|
]
|
|
885
973
|
);
|
package/src/utils/index.ts
CHANGED
|
@@ -256,7 +256,10 @@ export function isPropagationStopped(event: any): boolean {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
export function isEvtWithFiles(event: any): boolean {
|
|
259
|
-
|
|
259
|
+
// A paste (ClipboardEvent) carries its DataTransfer under {clipboardData} rather than
|
|
260
|
+
// {dataTransfer}, so a pasted screenshot is detected the same way as a drop.
|
|
261
|
+
const dataTransfer = event.dataTransfer ?? event.clipboardData;
|
|
262
|
+
if (!dataTransfer) {
|
|
260
263
|
return !!event.target && !!event.target.files;
|
|
261
264
|
}
|
|
262
265
|
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types
|
|
@@ -266,9 +269,9 @@ export function isEvtWithFiles(event: any): boolean {
|
|
|
266
269
|
// uses to extract the files. Accept either so detection stays consistent. See #1409.
|
|
267
270
|
return (
|
|
268
271
|
Array.prototype.some.call(
|
|
269
|
-
|
|
272
|
+
dataTransfer.types,
|
|
270
273
|
(type: string) => type === "Files" || type === "application/x-moz-file"
|
|
271
|
-
) || Array.prototype.some.call(
|
|
274
|
+
) || Array.prototype.some.call(dataTransfer.items ?? [], isKindFile)
|
|
272
275
|
);
|
|
273
276
|
}
|
|
274
277
|
|