mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-27 02:34:45 +08:00
Paste event handling WIP
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
29
js/input/Paste.js
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user