Files
ueblueprint/js/input/mouse/MouseClickDrag.js
barsdeveloper 7469d55518 Replace parsing and test libraries
* WIP

* WIP

* wip

* WIP

* Several fixes

* Tests wip port to playwright

* WIP

* Fix more tests

* Serialization tests fixed

* Several fixes for tests

* Input options types

* Type adjustments

* Fix object reference parser

* Tests fixes

* More tests fixes
2024-02-14 00:40:42 +01:00

64 lines
1.5 KiB
JavaScript
Executable File

import MouseMoveDraggable from "./MouseMoveDraggable.js"
/**
* @typedef {import("./MouseMoveDraggable.js").Options & {
* onClicked?: () => void,
* onStartDrag?: () => void,
* onDrag?: (location: Coordinates, movement: Coordinates) => void,
* onEndDrag?: () => void,
* }} Options
*/
export default class MouseClickDrag extends MouseMoveDraggable {
#onClicked
#onStartDrag
#onDrag
#onEndDrag
/**
* @param {HTMLElement} target
* @param {Blueprint} blueprint
* @param {Options} options
*/
constructor(target, blueprint, options = {}) {
super(target, blueprint, options)
if (options.onClicked) {
this.#onClicked = options.onClicked
}
if (options.onStartDrag) {
this.#onStartDrag = options.onStartDrag
}
if (options.onDrag) {
this.#onDrag = options.onDrag
}
if (options.onEndDrag) {
this.#onEndDrag = options.onEndDrag
}
}
/** @param {Coordinates} location */
clicked(location) {
super.clicked(location)
this.#onClicked?.()
}
startDrag() {
super.startDrag()
this.#onStartDrag?.()
}
/**
* @param {Coordinates} location
* @param {Coordinates} movement
*/
dragAction(location, movement) {
this.#onDrag?.(location, movement)
}
endDrag() {
super.endDrag()
this.#onEndDrag?.()
}
}