mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-17 19:03:27 +08:00
Minor refactoring and fixes
This commit is contained in:
@@ -20,6 +20,10 @@ export default class IInput {
|
||||
/** @type {Object} */
|
||||
options
|
||||
|
||||
|
||||
listenHandler = () => this.listenEvents()
|
||||
unlistenHandler = () => this.unlistenEvents()
|
||||
|
||||
/**
|
||||
* @param {T} target
|
||||
* @param {Blueprint} blueprint
|
||||
@@ -32,9 +36,9 @@ export default class IInput {
|
||||
this.#target = target
|
||||
this.#blueprint = blueprint
|
||||
this.options = options
|
||||
let self = this
|
||||
this.listenHandler = _ => self.listenEvents()
|
||||
this.unlistenHandler = _ => self.unlistenEvents()
|
||||
}
|
||||
|
||||
setup() {
|
||||
if (this.options.listenOnFocus) {
|
||||
this.blueprint.addEventListener(Configuration.focusEventName.begin, this.listenHandler)
|
||||
this.blueprint.addEventListener(Configuration.focusEventName.end, this.unlistenHandler)
|
||||
@@ -43,9 +47,12 @@ export default class IInput {
|
||||
this.blueprint.addEventListener(Configuration.editTextEventName.begin, this.unlistenHandler)
|
||||
this.blueprint.addEventListener(Configuration.editTextEventName.end, this.listenHandler)
|
||||
}
|
||||
if (this.blueprint.focused) {
|
||||
this.listenEvents()
|
||||
}
|
||||
}
|
||||
|
||||
unlistenDOMElement() {
|
||||
cleanup() {
|
||||
this.unlistenEvents()
|
||||
this.blueprint.removeEventListener(Configuration.focusEventName.begin, this.listenHandler)
|
||||
this.blueprint.removeEventListener(Configuration.focusEventName.end, this.unlistenHandler)
|
||||
|
||||
@@ -24,11 +24,15 @@ export default class Copy extends IInput {
|
||||
window.removeEventListener("copy", this.#copyHandler)
|
||||
}
|
||||
|
||||
copied() {
|
||||
const value = this.blueprint
|
||||
getSerializedText() {
|
||||
return this.blueprint
|
||||
.getNodes(true)
|
||||
.map(node => Copy.#serializer.serialize(node.entity, false))
|
||||
.join("")
|
||||
}
|
||||
|
||||
copied() {
|
||||
const value = this.getSerializedText()
|
||||
navigator.clipboard.writeText(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import IInput from "../IInput"
|
||||
import Utility from "../../Utility"
|
||||
|
||||
/** @typedef {import("../../Blueprint").default} Blueprint */
|
||||
|
||||
/**
|
||||
* @template {HTMLElement} T
|
||||
* @extends {IInput<T>}
|
||||
@@ -13,6 +11,7 @@ export default class IPointing extends IInput {
|
||||
options.ignoreTranslateCompensate ??= false
|
||||
options.movementSpace ??= blueprint.getGridDOMElement() ?? document.documentElement
|
||||
super(target, blueprint, options)
|
||||
/** @type {HTMLElement} */
|
||||
this.movementSpace = options.movementSpace
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
e => {
|
||||
if (!this.enteredPin) {
|
||||
this.linkValid = false
|
||||
this.enteredPin = /** @type {PinElement} */ (e.target)
|
||||
this.enteredPin = /** @type {PinElement} */(e.target)
|
||||
const a = this.link.sourcePin ?? this.target // Remember target might have change
|
||||
const b = this.enteredPin
|
||||
if (
|
||||
@@ -74,7 +74,7 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
/** @type {LinkElement} */
|
||||
this.link = /** @type {LinkElementConstructor} */(ElementFactory.getConstructor("ueb-link"))
|
||||
.newObject(this.target, null)
|
||||
this.blueprint.linksContainerElement.prepend(this.link)
|
||||
this.blueprint.template.linksContainerElement.prepend(this.link)
|
||||
this.link.setMessagePlaceNode()
|
||||
this.#listenedPins = this.blueprint.querySelectorAll("ueb-pin")
|
||||
this.#listenedPins.forEach(pin => {
|
||||
|
||||
@@ -4,7 +4,7 @@ export default class Select extends IMouseClickDrag {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
this.selectorElement = this.blueprint.selectorElement
|
||||
this.selectorElement = this.blueprint.template.selectorElement
|
||||
}
|
||||
|
||||
startDrag() {
|
||||
|
||||
Reference in New Issue
Block a user