Files
ueblueprint/js/input/common/Copy.js
barsdeveloper 7469d55518 Replace parsing and test libraries
* WIP

* WIP

* wip

* WIP

* Several fixes

* Tests wip port to playwright

* WIP

* Fix more tests

* Serialization tests fixed

* Several fixes for tests

* Input options types

* Type adjustments

* Fix object reference parser

* Tests fixes

* More tests fixes
2024-02-14 00:40:42 +01:00

47 lines
1.2 KiB
JavaScript
Executable File

import IInput from "../IInput.js"
import ObjectSerializer from "../../serialization/ObjectSerializer.js"
/**
* @typedef {import("../IInput.js").Options & {
* listenOnFocus?: Boolean,
* unlistenOnTextEdit?: Boolean,
* }} Options
*/
export default class Copy extends IInput {
static #serializer = new ObjectSerializer()
/** @type {(e: ClipboardEvent) => void} */
#copyHandler
constructor(target, blueprint, options = {}) {
options.listenOnFocus ??= true
options.unlistenOnTextEdit ??= true // No nodes copy if inside a text field, just text (default behavior)
super(target, blueprint, options)
let self = this
this.#copyHandler = () => self.copied()
}
listenEvents() {
window.addEventListener("copy", this.#copyHandler)
}
unlistenEvents() {
window.removeEventListener("copy", this.#copyHandler)
}
getSerializedText() {
return this.blueprint
.getNodes(true)
.map(node => Copy.#serializer.write(node.entity, false))
.join("")
}
copied() {
const value = this.getSerializedText()
navigator.clipboard.writeText(value)
return value
}
}