file-selector
Version:
Convert DataTransfer object to a list of File objects
42 lines • 1.66 kB
TypeScript
import { DEFAULT_MIME_TYPES } from "./mime-default.js";
//#region src/file.d.ts
interface FileWithPath extends File {
readonly path: string;
readonly relativePath: string;
readonly handle?: FileSystemFileHandle;
}
//#endregion
//#region src/file-selector.d.ts
interface FromEventOptions {
/**
* Extension-to-MIME lookup used to set `type` on files the browser left typeless.
* Defaults to a small built-in set of common types ({@link DEFAULT_MIME_TYPES}).
*
* The full extension-to-MIME table (~1,200 entries) is not bundled into the main entry;
* import it from the `file-selector/mime` subpath when broader coverage is needed:
*
* ```ts
* import {fromEvent} from 'file-selector';
* import {COMMON_MIME_TYPES} from 'file-selector/mime';
* await fromEvent(evt, {mimeTypes: COMMON_MIME_TYPES});
* ```
*
* See https://github.com/react-dropzone/file-selector/issues/127
*/
mimeTypes?: Map<string, string>;
}
/**
* Convert a DragEvent's DataTrasfer object to a list of File objects
* NOTE: If some of the items are folders,
* everything will be flattened and placed in the same list but the paths will be kept as a {path} property.
*
* EXPERIMENTAL: A list of https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle objects can also be passed as an arg
* and a list of File objects will be returned.
*
* @param evt
* @param options
*/
declare function fromEvent(evt: Event | any, { mimeTypes }?: FromEventOptions): Promise<(FileWithPath | DataTransferItem)[]>;
//#endregion
export { DEFAULT_MIME_TYPES, type FileWithPath, type FromEventOptions, fromEvent };
//# sourceMappingURL=index.d.ts.map