Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
proposal-move-events
Advanced tools
Readme
Okay. Implementing drag'n'drop interfaces is tedious. There are too many problems with how it is normally done for me to list them here. So I'll fix them instead.
import { polyfill } from 'proposal-move-events'
polyfill()
element.moveHandler = class Move {
onStart(event) {
if (event.cancelable) {
event.preventDefault()
}
this.snapshot = document.createSnapshot(this.element)
this.element.style.opacity = 0
this.initialX = event.snapshotX
this.initialY = event.snapshotY
this.snapshot.place({
x: event.snapshotX,
y: event.snapshotY
})
}
onMove(event) {
this.snapshot.move({
x: event.snapshotX,
y: event.snapshotY,
})
}
onEnd(event) {
this.snapshot.move({
x: this.initialX,
y: this.initialY,
transition: 300,
})
setTimeout(() => {
this.element.style.opacity = 1
this.snapshot.remove()
}, 300)
}
}
Live example: https://adrianhelvik.github.io/proposal-move-events
Use this in production, not the polyfill. The polyfill is only intended as a demo of how this could be used if the proposal is standardized.
import { setMoveHandler, createSnapshot } from 'proposal-move-events'
setMoveHandler(element, class Move {
onStart(event) {
if (event.cancelable) {
event.preventDefault()
}
this.snapshot = createSnapshot(this.element)
this.element.style.opacity = 0
this.initialX = event.snapshotX
this.initialY = event.snapshotY
this.snapshot.place({
x: event.snapshotX,
y: event.snapshotY
})
}
onMove(event) {
this.snapshot.move({
x: event.snapshotX,
y: event.snapshotY,
})
}
onEnd(event) {
this.snapshot.move({
x: this.initialX,
y: this.initialY,
transition: 300
})
setTimeout(() => {
this.element.style.opacity = 1
this.snapshot.remove()
}, 300)
}
})
HTML5 drag'n'drop events are not a pleasure to use, so we tend to implement things using mose and touch events. When doing this it is way too common to duplicate logic.
So I propose a new way to handle this...
An important rationale behind moves is that a move has a start, a duration and an end. For mouse events, mousemove, mousedown and mouseup works okay.
There is only one mouse, so you can easily add an event for mousedown, mousemove and mouseup (using the APIs however...).
For touch events however, we have to handle multiple touches. From what I've seen online the majority of usage is subtly incorrect. Often relying on event.touches[0].
Lets create an abstraction around a move. A move has a start, a beginning and an end and shares data between these three states. What a perfect use case for classes.
class Move {
onStart(event) {}
onMove(event) {}
onEnd(event) {}
}
Perfect! We now need a way to attach a move to an element. What should the API be for this? I am not 100% happy with it. Naming things is hard! But here it goes.
element.moveHandler = Move
This polyfill does not clone ::before
and ::after
pseudo
elements. To make it usable for me, I've whitelisted class names
from Font Awesome.
FAQs
Okay. Implementing drag'n'drop interfaces is tedious. There are too many problems with how it is normally done for me to list them here. So I'll fix them instead.
The npm package proposal-move-events receives a total of 16 weekly downloads. As such, proposal-move-events popularity was classified as not popular.
We found that proposal-move-events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.