Blueprint focusable

This commit is contained in:
barsdeveloper
2021-11-06 20:59:00 +01:00
parent ceb07688f2
commit afa27bf42c
13 changed files with 318 additions and 79 deletions

View File

@@ -1,29 +1,18 @@
import GraphNode from "../graph/GraphNode"
import ObjectSerializer from "../serialization/ObjectSerializer"
import KeyboardShortcut from "./KeyboardShortcut"
export default class Paste {
export default class Paste extends KeyboardShortcut {
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)
constructor(target, blueprint) {
super(target, blueprint, {
keys: ["Control", "C"]
})
}
pasted(value) {
fire() {
let value = navigator.clipboard.readText()
let nodes = this.serializer.readMultiple(value).map(entity => new GraphNode(entity))
this.blueprint.addNode(...nodes)
}
unlistenDOMElement() {
this.target.removeEventListener("paste", this.pasteHandler)
}
}
}