mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:28:17 +08:00
Configuration dependant on blueprint, refactoring
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IContext from "../IContext"
|
||||
import ISerializer from "../../serialization/ISerializer"
|
||||
import KeyBindingEntity from "../../entity/KeyBindingEntity"
|
||||
|
||||
export default class IKeyboardShortcut extends IContext {
|
||||
|
||||
/** @type {KeyBindingEntity} */
|
||||
/** @type {KeyBindingEntity[]} */
|
||||
#activationKeys
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
@@ -21,6 +20,7 @@ export default class IKeyboardShortcut extends IContext {
|
||||
return v
|
||||
}
|
||||
if (v.constructor === String) {
|
||||
// @ts-expect-error
|
||||
const parsed = ISerializer.grammar.KeyBinding.parse(v)
|
||||
if (parsed.status) {
|
||||
return parsed.value
|
||||
@@ -45,7 +45,7 @@ export default class IKeyboardShortcut extends IContext {
|
||||
wantsShift(keyEntry) == e.shiftKey
|
||||
&& wantsCtrl(keyEntry) == e.ctrlKey
|
||||
&& wantsAlt(keyEntry) == e.altKey
|
||||
&& Configuration.Keys[keyEntry.Key] == e.code
|
||||
&& this.blueprint.settings.Keys[keyEntry.Key] == e.code
|
||||
)) {
|
||||
self.fire()
|
||||
document.removeEventListener("keydown", self.keyDownHandler)
|
||||
@@ -61,7 +61,7 @@ export default class IKeyboardShortcut extends IContext {
|
||||
|| keyEntry.bCtrl && e.key == "Control"
|
||||
|| keyEntry.bAlt && e.key == "Alt"
|
||||
|| keyEntry.bCmd && e.key == "Meta" // Unsure about this, what key is that?
|
||||
|| Configuration.Keys[keyEntry.Key] == e.code
|
||||
|| this.blueprint.settings.Keys[keyEntry.Key] == e.code
|
||||
)) {
|
||||
self.unfire()
|
||||
document.removeEventListener("keyup", this.keyUpHandler)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
|
||||
export default class KeyboardCanc extends IKeyboardShortcut {
|
||||
@@ -8,12 +7,12 @@ export default class KeyboardCanc extends IKeyboardShortcut {
|
||||
/**
|
||||
* @param {HTMLElement} target
|
||||
* @param {import("../../Blueprint").default} blueprint
|
||||
* @param {OBject} options
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = {
|
||||
...options,
|
||||
activationKeys: Configuration.deleteNodesKeyboardKey
|
||||
activationKeys: blueprint.settings.deleteNodesKeyboardKey
|
||||
}
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
import Zoom from "../mouse/Zoom"
|
||||
|
||||
@@ -12,12 +11,12 @@ export default class KeyboardEnableZoom extends IKeyboardShortcut {
|
||||
/**
|
||||
* @param {HTMLElement} target
|
||||
* @param {import("../../Blueprint").default} blueprint
|
||||
* @param {OBject} options
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = {
|
||||
...options,
|
||||
activationKeys: Configuration.enableZoomIn
|
||||
activationKeys: blueprint.settings.enableZoomIn
|
||||
}
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
|
||||
export default class KeyboardSelectAll extends IKeyboardShortcut {
|
||||
@@ -13,7 +12,7 @@ export default class KeyboardSelectAll extends IKeyboardShortcut {
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = {
|
||||
...options,
|
||||
activationKeys: Configuration.selectAllKeyboardKey
|
||||
activationKeys: blueprint.settings.selectAllKeyboardKey
|
||||
}
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
/**
|
||||
@@ -68,7 +67,7 @@ export default class IMouseClickDrag extends IPointing {
|
||||
movementListenedElement.removeEventListener("mousemove", self.#mouseStartedMovingHandler)
|
||||
movementListenedElement.addEventListener("mousemove", self.#mouseMoveHandler)
|
||||
// Handler calls e.preventDefault() when it receives the event, this means dispatchEvent returns false
|
||||
const dragEvent = self.getEvent(Configuration.trackingMouseEventName.begin)
|
||||
const dragEvent = self.getEvent(this.blueprint.settings.trackingMouseEventName.begin)
|
||||
self.#trackingMouse = this.target.dispatchEvent(dragEvent) == false
|
||||
// Do actual actions
|
||||
self.startDrag()
|
||||
@@ -101,7 +100,7 @@ export default class IMouseClickDrag extends IPointing {
|
||||
}
|
||||
self.unclicked()
|
||||
if (self.#trackingMouse) {
|
||||
const dragEvent = self.getEvent(Configuration.trackingMouseEventName.end)
|
||||
const dragEvent = self.getEvent(this.blueprint.settings.trackingMouseEventName.end)
|
||||
this.target.dispatchEvent(dragEvent)
|
||||
self.#trackingMouse = false
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
export default class MouseTracking extends IPointing {
|
||||
@@ -56,20 +55,20 @@ export default class MouseTracking extends IPointing {
|
||||
listenEvents() {
|
||||
this.listenMouseMove()
|
||||
this.blueprint.addEventListener(
|
||||
Configuration.trackingMouseEventName.begin,
|
||||
this.blueprint.settings.trackingMouseEventName.begin,
|
||||
/** @type {(e: Event) => any} */(this.#trackingMouseStolenHandler))
|
||||
this.blueprint.addEventListener(
|
||||
Configuration.trackingMouseEventName.end,
|
||||
this.blueprint.settings.trackingMouseEventName.end,
|
||||
/** @type {(e: Event) => any} */(this.#trackingMouseGaveBackHandler))
|
||||
}
|
||||
|
||||
unlistenEvents() {
|
||||
this.unlistenMouseMove()
|
||||
this.blueprint.removeEventListener(
|
||||
Configuration.trackingMouseEventName.begin,
|
||||
this.blueprint.settings.trackingMouseEventName.begin,
|
||||
/** @type {(e: Event) => any} */(this.#trackingMouseStolenHandler))
|
||||
this.blueprint.removeEventListener(
|
||||
Configuration.trackingMouseEventName.end,
|
||||
this.blueprint.settings.trackingMouseEventName.end,
|
||||
/** @type {(e: Event) => any} */(this.#trackingMouseGaveBackHandler)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user