index.js 946 B

12345678910111213141516171819
  1. const webkitGetAsEntryApi = require('./utils/webkitGetAsEntryApi')
  2. const fallbackApi = require('./utils/fallbackApi')
  3. /**
  4. * Returns a promise that resolves to the array of dropped files (if a folder is dropped, and browser supports folder parsing - promise resolves to the flat array of all files in all directories).
  5. * Each file has .relativePath prop appended to it (e.g. "/docs/Prague/ticket_from_prague_to_ufa.pdf") if browser supports it. Otherwise it's undefined.
  6. *
  7. * @param {DataTransfer} dataTransfer
  8. * @returns {Promise} - Array<File>
  9. */
  10. module.exports = function getDroppedFiles (dataTransfer) {
  11. // Get all files from all subdirs. Works (at least) in Chrome, Mozilla, and Safari
  12. if (dataTransfer.items && dataTransfer.items[0] && 'webkitGetAsEntry' in dataTransfer.items[0]) {
  13. return webkitGetAsEntryApi(dataTransfer)
  14. // Otherwise just return all first-order files
  15. } else {
  16. return fallbackApi(dataTransfer)
  17. }
  18. }