This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/utils/getDataTransferFiles.js

23 lines
769 B
JavaScript
Raw Normal View History

// @flow
export default function getDataTransferFiles(event: SyntheticEvent<>): File[] {
let dataTransferItemsList = [];
2018-05-05 23:16:08 +00:00
// $FlowFixMe
if (event.dataTransfer) {
const dt = event.dataTransfer;
if (dt.files && dt.files.length) {
dataTransferItemsList = dt.files;
} else if (dt.items && dt.items.length) {
// During the drag even the dataTransfer.files is null
// but Chrome implements some drag store, which is accesible via dataTransfer.items
dataTransferItemsList = dt.items;
}
2018-05-05 23:16:08 +00:00
// $FlowFixMe
} else if (event.target && event.target.files) {
dataTransferItemsList = event.target.files;
}
// Convert from DataTransferItemsList to the native Array
return Array.prototype.slice.call(dataTransferItemsList);
}