@uppy/drop-target
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -5,10 +5,9 @@ import BasePlugin from '@uppy/core/lib/BasePlugin.js'; | ||
const packageJson = { | ||
"version": "2.0.1" | ||
"version": "2.0.2" | ||
}; | ||
function isFileTransfer(event) { | ||
var _event$dataTransfer$t, _event$dataTransfer$t2; | ||
return (_event$dataTransfer$t = (_event$dataTransfer$t2 = event.dataTransfer.types) == null ? void 0 : _event$dataTransfer$t2.some(type => type === 'Files')) != null ? _event$dataTransfer$t : false; | ||
} | ||
/** | ||
@@ -18,8 +17,5 @@ * Drop Target plugin | ||
*/ | ||
export default class DropTarget extends BasePlugin { | ||
constructor(uppy, opts) { | ||
super(uppy, opts); | ||
this.addFiles = files => { | ||
@@ -37,3 +33,2 @@ const descriptors = files.map(file => ({ | ||
})); | ||
try { | ||
@@ -45,19 +40,18 @@ this.uppy.addFiles(descriptors); | ||
}; | ||
this.handleDrop = async event => { | ||
var _this$opts$onDrop, _this$opts; | ||
if (!isFileTransfer(event)) { | ||
return; | ||
} | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
clearTimeout(this.removeDragOverClassTimeout); // Remove dragover class | ||
clearTimeout(this.removeDragOverClassTimeout); | ||
// Remove dragover class | ||
event.currentTarget.classList.remove('uppy-is-drag-over'); | ||
this.setPluginState({ | ||
isDraggingOver: false | ||
}); // Let any acquirer plugin (Url/Webcam/etc.) handle drops to the root | ||
}); | ||
// Let any acquirer plugin (Url/Webcam/etc.) handle drops to the root | ||
this.uppy.iteratePlugins(plugin => { | ||
@@ -68,10 +62,11 @@ if (plugin.type === 'acquirer') { | ||
} | ||
}); // Add all dropped files, handle errors | ||
}); | ||
// Add all dropped files, handle errors | ||
let executedDropErrorOnce = false; | ||
const logDropError = error => { | ||
this.uppy.log(error, 'error'); | ||
const logDropError = error => { | ||
this.uppy.log(error, 'error'); // In practice all drop errors are most likely the same, | ||
// In practice all drop errors are most likely the same, | ||
// so let's just show one to avoid overwhelming the user | ||
if (!executedDropErrorOnce) { | ||
@@ -82,7 +77,5 @@ this.uppy.info(error.message, 'error'); | ||
}; | ||
const files = await getDroppedFiles(event.dataTransfer, { | ||
logDropError | ||
}); | ||
if (files.length > 0) { | ||
@@ -92,18 +85,15 @@ this.uppy.log('[DropTarget] Files were dropped'); | ||
} | ||
(_this$opts$onDrop = (_this$opts = this.opts).onDrop) == null ? void 0 : _this$opts$onDrop.call(_this$opts, event); | ||
}; | ||
this.handleDragOver = event => { | ||
var _this$opts$onDragOver, _this$opts2; | ||
if (!isFileTransfer(event)) { | ||
return; | ||
} | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
event.stopPropagation(); // Add a small (+) icon on drop | ||
// Add a small (+) icon on drop | ||
// (and prevent browsers from interpreting this as files being _moved_ into the browser, | ||
// https://github.com/transloadit/uppy/issues/1978) | ||
event.dataTransfer.dropEffect = 'copy'; // eslint-disable-line no-param-reassign | ||
@@ -118,10 +108,7 @@ | ||
}; | ||
this.handleDragLeave = event => { | ||
var _this$opts$onDragLeav, _this$opts3; | ||
if (!isFileTransfer(event)) { | ||
return; | ||
} | ||
event.preventDefault(); | ||
@@ -132,5 +119,5 @@ event.stopPropagation(); | ||
} = event; | ||
clearTimeout(this.removeDragOverClassTimeout); // Timeout against flickering, this solution is taken from drag-drop library. | ||
clearTimeout(this.removeDragOverClassTimeout); | ||
// Timeout against flickering, this solution is taken from drag-drop library. | ||
// Solution with 'pointer-events: none' didn't work across browsers. | ||
this.removeDragOverClassTimeout = setTimeout(() => { | ||
@@ -144,3 +131,2 @@ currentTarget.classList.remove('uppy-is-drag-over'); | ||
}; | ||
this.addListeners = () => { | ||
@@ -150,3 +136,2 @@ const { | ||
} = this.opts; | ||
if (target instanceof Element) { | ||
@@ -157,7 +142,5 @@ this.nodes = [target]; | ||
} | ||
if (!this.nodes && !this.nodes.length > 0) { | ||
throw new Error(`"${target}" does not match any HTML elements`); | ||
} | ||
this.nodes.forEach(node => { | ||
@@ -169,3 +152,2 @@ node.addEventListener('dragover', this.handleDragOver, false); | ||
}; | ||
this.removeListeners = () => { | ||
@@ -180,12 +162,14 @@ if (this.nodes) { | ||
}; | ||
this.type = 'acquirer'; | ||
this.id = this.opts.id || 'DropTarget'; | ||
this.title = 'Drop Target'; // Default options | ||
this.title = 'Drop Target'; | ||
// Default options | ||
const defaultOpts = { | ||
target: null | ||
}; // Merge default options with the ones set by user | ||
}; | ||
this.opts = { ...defaultOpts, | ||
// Merge default options with the ones set by user | ||
this.opts = { | ||
...defaultOpts, | ||
...opts | ||
@@ -195,3 +179,2 @@ }; | ||
} | ||
install() { | ||
@@ -203,8 +186,6 @@ this.setPluginState({ | ||
} | ||
uninstall() { | ||
this.removeListeners(); | ||
} | ||
} | ||
DropTarget.VERSION = packageJson.version; |
{ | ||
"name": "@uppy/drop-target", | ||
"description": "Lets your users drag and drop files on a DOM element", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"license": "MIT", | ||
@@ -28,6 +28,6 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/utils": "^5.0.2" | ||
"@uppy/utils": "^5.5.2" | ||
}, | ||
"peerDependencies": { | ||
"@uppy/core": "^3.0.2" | ||
"@uppy/core": "^3.6.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "publishConfig": { |
import type { PluginOptions, BasePlugin } from '@uppy/core' | ||
interface DropTargetOptions extends PluginOptions { | ||
target: string | Element; | ||
onDragOver?: (event: MouseEvent) => void; | ||
onDrop?: (event: MouseEvent) => void; | ||
onDragLeave?: (event: MouseEvent) => void; | ||
target: string | Element | ||
onDragOver?: (event: MouseEvent) => void | ||
onDrop?: (event: MouseEvent) => void | ||
onDragLeave?: (event: MouseEvent) => void | ||
} | ||
@@ -9,0 +9,0 @@ |
Sorry, the diff of this file is not supported yet
25052
338
Updated@uppy/utils@^5.5.2