Closeable color picker window

This commit is contained in:
barsdeveloper
2022-11-06 17:44:50 +01:00
parent 5183aae21b
commit b86d952e3a
19 changed files with 272 additions and 203 deletions

View File

@@ -25,12 +25,12 @@ export default class IInput {
* @param {Blueprint} blueprint
* @param {Object} options
*/
constructor(target, blueprint, options) {
this.#target = target
this.#blueprint = blueprint
constructor(target, blueprint, options = {}) {
options.consumeEvent ??= false
options.listenOnFocus ??= false
options.unlistenOnTextEdit ??= false
this.#target = target
this.#blueprint = blueprint
this.options = options
let self = this
this.listenHandler = _ => self.listenEvents()

View File

@@ -3,14 +3,15 @@ import ObjectSerializer from "../../serialization/ObjectSerializer"
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)
options.listenOnFocus ??= true
options.unlistenOnTextEdit ??= true // No nodes copy if inside a text field, just text (default behavior)
super(target, blueprint, options)
this.serializer = new ObjectSerializer()
let self = this
this.#copyHandler = _ => self.copied()
}
@@ -24,7 +25,10 @@ export default class Copy extends IInput {
}
copied() {
const value = this.blueprint.getNodes(true).map(node => this.serializer.serialize(node.entity, false)).join("\n\n")
const value = this.blueprint
.getNodes(true)
.map(node => Copy.#serializer.serialize(node.entity, false))
.join("\n\n")
navigator.clipboard.writeText(value)
}
}

View File

@@ -4,14 +4,15 @@ import ObjectSerializer from "../../serialization/ObjectSerializer"
export default class Paste extends IInput {
static #serializer = new ObjectSerializer()
/** @type {(e: ClipboardEvent) => void} */
#pasteHandle
constructor(target, blueprint, options = {}) {
options.listenOnFocus = true
options.unlistenOnTextEdit = true // No nodes paste if inside a text field, just text (default behavior)
options.listenOnFocus ??= true
options.unlistenOnTextEdit ??= true // No nodes paste if inside a text field, just text (default behavior)
super(target, blueprint, options)
this.serializer = new ObjectSerializer()
let self = this
this.#pasteHandle = e => self.pasted(e.clipboardData.getData("Text"))
}
@@ -28,7 +29,7 @@ export default class Paste extends IInput {
let top = 0
let left = 0
let count = 0
let nodes = this.serializer.readMultiple(value).map(entity => {
let nodes = Paste.#serializer.readMultiple(value).map(entity => {
let node = new NodeElement(entity)
top += node.locationY
left += node.locationX

View File

@@ -9,9 +9,9 @@ import Utility from "../../Utility"
*/
export default class IPointing extends IInput {
constructor(target, blueprint, options) {
constructor(target, blueprint, options = {}) {
options.ignoreTranslateCompensate ??= false
options.movementSpace ??= blueprint?.getGridDOMElement() ?? document.documentElement
options.movementSpace ??= blueprint.getGridDOMElement() ?? document.documentElement
super(target, blueprint, options)
this.movementSpace = options.movementSpace
}

View File

@@ -0,0 +1,28 @@
import IMouseClick from "./IMouseClick"
export default class MouseClickAction extends IMouseClick {
static #ignoreEvent =
/** @param {MouseClickAction} self */
self => { }
constructor(
target,
blueprint,
options,
onMouseDown = MouseClickAction.#ignoreEvent,
onMouseUp = MouseClickAction.#ignoreEvent
) {
super(target, blueprint, options)
this.onMouseDown = onMouseDown
this.onMouseUp = onMouseUp
}
clicked() {
this.onMouseDown(this)
}
unclicked() {
this.onMouseUp(this)
}
}

View File

@@ -1,22 +0,0 @@
import IMouseClick from "./IMouseClick"
import WindowElement from "../../element/WindowElement"
/**
* @template {HTMLElement} T
* @extends {IMouseClick<T>}
*/
export default class MouseOpenWindow extends IMouseClick {
#window
clicked(location) {
}
unclicked(location) {
this.#window = new WindowElement({
type: this.options.windowType,
windowOptions: this.options.windowOptions,
})
this.blueprint.append(this.#window)
}
}