@uppy/drop-target
Advanced tools
Comparing version 3.0.0-beta to 3.0.0-beta.1
# @uppy/drop-target | ||
## 3.0.0-beta.1 | ||
Released: 2024-03-28 | ||
Included in: Uppy v4.0.0-beta.1 | ||
- @uppy/audio,@uppy/dashboard,@uppy/drop-target,@uppy/webcam: add missing exports (Antoine du Hamel / #5014) | ||
## 2.0.5 | ||
Released: 2024-03-27 | ||
Included in: Uppy v3.24.0 | ||
- @uppy/audio,@uppy/dashboard,@uppy/drop-target,@uppy/webcam: add missing exports (Antoine du Hamel / #5014) | ||
## 2.0.3 | ||
Released: 2024-02-19 | ||
Included in: Uppy v3.22.0 | ||
- @uppy/drop-target: refactor to typescript (artur paikin / #4863) | ||
## 2.0.1 | ||
Released: 2022-09-25 | ||
Included in: Uppy v3.1.0 | ||
- @uppy/audio,@uppy/aws-s3-multipart,@uppy/aws-s3,@uppy/box,@uppy/companion-client,@uppy/companion,@uppy/compressor,@uppy/core,@uppy/dashboard,@uppy/drag-drop,@uppy/drop-target,@uppy/dropbox,@uppy/facebook,@uppy/file-input,@uppy/form,@uppy/golden-retriever,@uppy/google-drive,@uppy/image-editor,@uppy/informer,@uppy/instagram,@uppy/locales,@uppy/onedrive,@uppy/progress-bar,@uppy/provider-views,@uppy/react,@uppy/redux-dev-tools,@uppy/remote-sources,@uppy/screen-capture,@uppy/status-bar,@uppy/store-default,@uppy/store-redux,@uppy/svelte,@uppy/thumbnail-generator,@uppy/transloadit,@uppy/tus,@uppy/unsplash,@uppy/url,@uppy/utils,@uppy/vue,@uppy/webcam,@uppy/xhr-upload,@uppy/zoom: add missing entries to changelog for individual packages (Antoine du Hamel / #4092) | ||
## 2.0.0 | ||
Released: 2022-08-22 | ||
Included in: Uppy v3.0.0 | ||
- Switch to ESM | ||
## 2.0.0-beta.2 | ||
Released: 2022-08-03 | ||
Included in: Uppy v3.0.0-beta.4 | ||
- @uppy/drop-target: remove `isFileTransfer` from the public API (Antoine du Hamel / #3932) | ||
## 1.1.3 | ||
@@ -4,0 +46,0 @@ |
109
lib/index.js
@@ -1,13 +0,18 @@ | ||
import BasePlugin from '@uppy/core/lib/BasePlugin'; | ||
import BasePlugin from '@uppy/core/lib/BasePlugin.js'; | ||
import getDroppedFiles from '@uppy/utils/lib/getDroppedFiles'; | ||
import toArray from '@uppy/utils/lib/toArray'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore We don't want TS to generate types for the package.json | ||
const packageJson = { | ||
"version": "3.0.0-beta" | ||
"version": "3.0.0-beta.1" | ||
}; | ||
// Default options | ||
const defaultOpts = { | ||
target: null | ||
}; | ||
function isFileTransfer(event) { | ||
var _event$dataTransfer$t, _event$dataTransfer$t2; | ||
var _event$dataTransfer$t, _event$dataTransfer; | ||
return (_event$dataTransfer$t = (_event$dataTransfer = event.dataTransfer) == null || (_event$dataTransfer = _event$dataTransfer.types) == null ? void 0 : _event$dataTransfer.some(type => type === 'Files')) != null ? _event$dataTransfer$t : false; | ||
} | ||
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; | ||
} | ||
/** | ||
@@ -17,8 +22,8 @@ * Drop Target plugin | ||
*/ | ||
export default class DropTarget extends BasePlugin { | ||
constructor(uppy, opts) { | ||
super(uppy, opts); | ||
super(uppy, { | ||
...defaultOpts, | ||
...opts | ||
}); | ||
this.addFiles = files => { | ||
@@ -36,3 +41,2 @@ const descriptors = files.map(file => ({ | ||
})); | ||
try { | ||
@@ -44,34 +48,33 @@ this.uppy.addFiles(descriptors); | ||
}; | ||
this.isFileTransfer = isFileTransfer; | ||
this.handleDrop = async event => { | ||
var _this$opts$onDrop, _this$opts; | ||
if (!this.isFileTransfer(event)) { | ||
var _event$currentTarget, _this$opts$onDrop, _this$opts; | ||
if (!isFileTransfer(event)) { | ||
return; | ||
} | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
clearTimeout(this.removeDragOverClassTimeout); // Remove dragover class | ||
clearTimeout(this.removeDragOverClassTimeout) | ||
event.currentTarget.classList.remove('uppy-is-drag-over'); | ||
// Remove dragover class | ||
; | ||
(_event$currentTarget = event.currentTarget) == null || _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 => { | ||
if (plugin.type === 'acquirer') { | ||
// Every Plugin with .type acquirer can define handleRootDrop(event) | ||
plugin.handleRootDrop == null ? void 0 : plugin.handleRootDrop(event); | ||
// @ts-expect-error Every Plugin with .type acquirer can define handleRootDrop(event) | ||
plugin.handleRootDrop == null || plugin.handleRootDrop(event); | ||
} | ||
}); // 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 +85,5 @@ this.uppy.info(error.message, 'error'); | ||
}; | ||
const files = await getDroppedFiles(event.dataTransfer, { | ||
logDropError | ||
}); | ||
if (files.length > 0) { | ||
@@ -92,18 +93,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$opts$onDrop = (_this$opts = this.opts).onDrop) == null || _this$opts$onDrop.call(_this$opts, event); | ||
}; | ||
this.handleDragOver = event => { | ||
var _this$opts$onDragOver, _this$opts2; | ||
if (!this.isFileTransfer(event)) { | ||
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 | ||
@@ -116,12 +114,9 @@ | ||
}); | ||
(_this$opts$onDragOver = (_this$opts2 = this.opts).onDragOver) == null ? void 0 : _this$opts$onDragOver.call(_this$opts2, event); | ||
(_this$opts$onDragOver = (_this$opts2 = this.opts).onDragOver) == null || _this$opts$onDragOver.call(_this$opts2, event); | ||
}; | ||
this.handleDragLeave = event => { | ||
var _this$opts$onDragLeav, _this$opts3; | ||
if (!this.isFileTransfer(event)) { | ||
if (!isFileTransfer(event)) { | ||
return; | ||
} | ||
event.preventDefault(); | ||
@@ -132,6 +127,7 @@ 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(() => { | ||
; | ||
currentTarget.classList.remove('uppy-is-drag-over'); | ||
@@ -142,5 +138,4 @@ this.setPluginState({ | ||
}, 50); | ||
(_this$opts$onDragLeav = (_this$opts3 = this.opts).onDragLeave) == null ? void 0 : _this$opts$onDragLeav.call(_this$opts3, event); | ||
(_this$opts$onDragLeav = (_this$opts3 = this.opts).onDragLeave) == null || _this$opts$onDragLeav.call(_this$opts3, event); | ||
}; | ||
this.addListeners = () => { | ||
@@ -150,3 +145,2 @@ const { | ||
} = this.opts; | ||
if (target instanceof Element) { | ||
@@ -157,7 +151,5 @@ this.nodes = [target]; | ||
} | ||
if (!this.nodes && !this.nodes.length > 0) { | ||
if (!this.nodes || this.nodes.length === 0) { | ||
throw new Error(`"${target}" does not match any HTML elements`); | ||
} | ||
this.nodes.forEach(node => { | ||
@@ -169,3 +161,2 @@ node.addEventListener('dragover', this.handleDragOver, false); | ||
}; | ||
this.removeListeners = () => { | ||
@@ -180,17 +171,7 @@ if (this.nodes) { | ||
}; | ||
this.type = 'acquirer'; | ||
this.id = this.opts.id || 'DropTarget'; | ||
this.title = 'Drop Target'; // Default options | ||
const defaultOpts = { | ||
target: null | ||
}; // Merge default options with the ones set by user | ||
this.opts = { ...defaultOpts, | ||
...opts | ||
}; | ||
this.removeDragOverClassTimeout = null; | ||
// @ts-expect-error TODO: remove in major | ||
this.title = 'Drop Target'; | ||
} | ||
install() { | ||
@@ -202,8 +183,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": "3.0.0-beta", | ||
"version": "3.0.0-beta.1", | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"types": "types/index.d.ts", | ||
"keywords": [ | ||
@@ -28,6 +27,6 @@ "file uploader", | ||
"dependencies": { | ||
"@uppy/utils": "^5.0.0-beta" | ||
"@uppy/utils": "^6.0.0-beta.1" | ||
}, | ||
"peerDependencies": { | ||
"@uppy/core": "^3.0.0-beta" | ||
"@uppy/core": "^4.0.0-beta.1" | ||
}, | ||
@@ -37,3 +36,3 @@ "publishConfig": { | ||
}, | ||
"stableVersion": "1.1.3" | ||
"stableVersion": "2.0.5" | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
29755
373
1
+ Added@uppy/core@4.4.2(transitive)
+ Added@uppy/store-default@4.2.0(transitive)
+ Added@uppy/utils@6.1.2(transitive)
+ Addednanoid@5.1.2(transitive)
- Removed@uppy/core@3.13.1(transitive)
- Removed@uppy/store-default@3.2.2(transitive)
- Removed@uppy/utils@5.9.0(transitive)
- Removednanoid@4.0.2(transitive)
Updated@uppy/utils@^6.0.0-beta.1