Refactoring

This commit is contained in:
barsdeveloper
2022-01-05 21:48:45 +01:00
parent 303cc5b71e
commit 7704850cf6
49 changed files with 1481 additions and 1469 deletions

52
js/input/Copy.js Normal file → Executable file
View File

@@ -1,26 +1,26 @@
import Context from "./Context"
import ObjectSerializer from "../serialization/ObjectSerializer"
export default class Copy extends Context {
constructor(target, blueprint, options = {}) {
options.wantsFocusCallback = true
super(target, blueprint, options)
this.serializer = new ObjectSerializer()
let self = this
this.copyHandle = _ => self.copied()
}
blueprintFocused() {
document.body.addEventListener("copy", this.copyHandle)
}
blueprintUnfocused() {
document.body.removeEventListener("copy", this.copyHandle)
}
copied() {
const value = this.blueprint.getNodes(true).map(node => this.serializer.write(node.entity)).join("\n")
navigator.clipboard.writeText(value)
}
}
import Context from "./Context"
import ObjectSerializer from "../serialization/ObjectSerializer"
export default class Copy extends Context {
constructor(target, blueprint, options = {}) {
options.wantsFocusCallback = true
super(target, blueprint, options)
this.serializer = new ObjectSerializer()
let self = this
this.copyHandler = _ => self.copied()
}
blueprintFocused() {
document.body.addEventListener("copy", this.copyHandler)
}
blueprintUnfocused() {
document.body.removeEventListener("copy", this.copyHandler)
}
copied() {
const value = this.blueprint.getNodes(true).map(node => this.serializer.write(node.entity)).join("\n")
navigator.clipboard.writeText(value)
}
}