export type EventFile = {
file: File;
entry?: FileSystemFileEntry;
};
/**
`getFiles` returns the list of files from a `change` or `drop` Event.
@remarks
`getFiles` supports only the `change` event type on file inputs and the `drop` event type (`DragEvent`).
Calling `getFiles` with other types of events will return an empty list.
For directory drop events, `getFiles` relies on the `webkitGetAsEntry` API;
if this API is unavailable in the browser, `getFiles` will return an empty list.
@param event - The `change` or `drop` `Event` for which files should be retrieved.
@returns A list of `EventFile`s that contain the `File`s retrieved from an `Event`.
@example
```typescript
import { getFiles } from "event-to-files";
// For an ``.
const fileInput = document.getElementById("file-input");
fileInput.addEventListener("change", async (event) => {
event.preventDefault();
const files = await getFiles(event);
for (const { file } of files) {
console.log(file.name);
}
});
// For a drag and drop event.
const dropZone = document.getElementById("drop-zone");
dropZone.addEventListener("dragover", (event) => {
// Cancel the `dragover` event to let the `drop` event fire later.
event.preventDefault();
});
dropZone.addEventListener("drop", async (event) => {
event.preventDefault();
const files = await getFiles(event);
for (const { file, entry } of files) {
console.log(file.name);
// If a directory was dragged and dropped,
// we can get the file's full path in the directory.
if (entry?.fullPath) {
console.log(entry.fullPath);
}
}
});
```
*/
export declare let getFiles: (event: Event) => Promise;