mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-12 11:07:40 +08:00
Paste event handling WIP
This commit is contained in:
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