Comparing version 7.0.1 to 7.1.0
63
index.js
/*! drag-drop. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */ | ||
module.exports = dragDrop | ||
module.exports.processItems = processItems | ||
@@ -158,30 +159,7 @@ const parallel = require('run-parallel') | ||
if (listeners.onDrop && event.dataTransfer.items) { | ||
const fileList = event.dataTransfer.files | ||
processItems(event.dataTransfer.items, (files, directories) => { | ||
const fileList = event.dataTransfer.files | ||
// Handle directories in Chrome using the proprietary FileSystem API | ||
const items = Array.from(event.dataTransfer.items).filter(item => { | ||
return item.kind === 'file' | ||
}) | ||
if (items.length === 0) return | ||
parallel(items.map(item => { | ||
return cb => { | ||
processEntry(item.webkitGetAsEntry(), cb) | ||
} | ||
}), (err, results) => { | ||
// This catches permission errors with file:// in Chrome. This should never | ||
// throw in production code, so the user does not need to use try-catch. | ||
if (err) throw err | ||
const entries = results.flat(Infinity) | ||
const files = entries.filter(item => { | ||
return item.isFile | ||
}) | ||
const directories = entries.filter(item => { | ||
return item.isDirectory | ||
}) | ||
// TODO: This callback has too many arguments, and the order is too | ||
// arbitrary. In next major version, it should be cleaned up. | ||
listeners.onDrop(files, pos, fileList, directories) | ||
@@ -203,2 +181,33 @@ }) | ||
function processItems (items, cb) { | ||
// Handle directories in Chrome using the proprietary FileSystem API | ||
items = Array.from(items).filter(item => { | ||
return item.kind === 'file' | ||
}) | ||
if (items.length === 0) return | ||
parallel(items.map(item => { | ||
return cb => { | ||
processEntry(item.webkitGetAsEntry(), cb) | ||
} | ||
}), (err, results) => { | ||
// This catches permission errors with file:// in Chrome. This should never | ||
// throw in production code, so the user does not need to use try-catch. | ||
if (err) throw err | ||
const entries = results.flat(Infinity) | ||
const files = entries.filter(item => { | ||
return item.isFile | ||
}) | ||
const directories = entries.filter(item => { | ||
return item.isDirectory | ||
}) | ||
cb(files, directories) | ||
}) | ||
} | ||
function processEntry (entry, cb) { | ||
@@ -205,0 +214,0 @@ let entries = [] |
{ | ||
"name": "drag-drop", | ||
"description": "HTML5 drag & drop for humans", | ||
"version": "7.0.1", | ||
"version": "7.1.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Feross Aboukhadijeh", |
@@ -185,2 +185,16 @@ # drag-drop [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] | ||
### support pasting files from the clipboard | ||
To support users pasting files from their clipboard, use the provided | ||
`processItems()` function to process the `DataTransferItemList` from the | ||
browser's native `'paste'` event. | ||
```js | ||
document.addEventListener('paste', event => { | ||
dragDrop.processItems(event.clipboardData.items, files => { | ||
// ... | ||
}) | ||
}) | ||
``` | ||
### a note about `file://` urls | ||
@@ -187,0 +201,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16607
231
210