Paste event handling WIP

This commit is contained in:
barsdeveloper
2021-10-31 17:01:56 +01:00
parent 199005ec20
commit ceb07688f2
11 changed files with 352 additions and 221 deletions

View File

@@ -15,7 +15,7 @@ export default class MouseClickDrag extends Pointing {
const movementListenedElement = this.moveEverywhere ? document.documentElement : this.movementSpace
let self = this
this.mouseDownHandler = function (e) {
this.mouseDownHandler = e => {
switch (e.button) {
case self.clickButton:
// Either doesn't matter or consider the click only when clicking on the parent, not descandants
@@ -37,7 +37,7 @@ export default class MouseClickDrag extends Pointing {
}
}
this.mouseStartedMovingHandler = function (e) {
this.mouseStartedMovingHandler = e => {
e.preventDefault()
e.stopPropagation()
@@ -50,7 +50,7 @@ export default class MouseClickDrag extends Pointing {
self.started = true
}
this.mouseMoveHandler = function (e) {
this.mouseMoveHandler = e => {
e.preventDefault()
e.stopPropagation()
const location = self.getLocation(e)
@@ -58,7 +58,7 @@ export default class MouseClickDrag extends Pointing {
self.dragTo(location, movement)
}
this.mouseUpHandler = function (e) {
this.mouseUpHandler = e => {
if (!self.exitAnyButton || e.button == self.clickButton) {
// Remove the handlers of "mousemove" and "mouseup"
movementListenedElement.removeEventListener('mousemove', self.mouseStartedMovingHandler)

View File

@@ -13,7 +13,7 @@ export default class MouseWheel extends Pointing {
this.looseTarget = options?.looseTarget ?? true
let self = this
this.mouseWheelHandler = function (e) {
this.mouseWheelHandler = e => {
e.preventDefault()
const location = self.getLocation(e)
self.wheel(Math.sign(e.deltaY), location)

29
js/input/Paste.js Normal file
View File

@@ -0,0 +1,29 @@
import GraphNode from "../graph/GraphNode"
import ObjectSerializer from "../serialization/ObjectSerializer"
export default class Paste {
constructor(target, blueprint, options) {
/** @type {HTMLElement} */
this.target = target
/** @type {import("../Blueprint").default}" */
this.blueprint = blueprint
this.serializer = new ObjectSerializer()
let self = this
this.pasteHandler = e => {
self.pasted(e.clipboardData.getData("text"))
}
this.target.addEventListener("paste", this.pasteHandler)
}
pasted(value) {
let nodes = this.serializer.readMultiple(value).map(entity => new GraphNode(entity))
this.blueprint.addNode(...nodes)
}
unlistenDOMElement() {
this.target.removeEventListener("paste", this.pasteHandler)
}
}