mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:28:17 +08:00
Various fixes and refactoring
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../Configuration"
|
||||
|
||||
/**
|
||||
* @typedef {import("../Blueprint").default} Blueprint
|
||||
*/
|
||||
@@ -39,21 +41,21 @@ export default class IContext {
|
||||
this.listenHandler = _ => self.listenEvents()
|
||||
this.unlistenHandler = _ => self.unlistenEvents()
|
||||
if (this.options.listenOnFocus) {
|
||||
this.blueprint.addEventListener(this.blueprint.settings.focusEventName.begin, this.listenHandler)
|
||||
this.blueprint.addEventListener(this.blueprint.settings.focusEventName.end, this.unlistenHandler)
|
||||
this.blueprint.addEventListener(Configuration.focusEventName.begin, this.listenHandler)
|
||||
this.blueprint.addEventListener(Configuration.focusEventName.end, this.unlistenHandler)
|
||||
}
|
||||
if (options?.unlistenOnTextEdit ?? false) {
|
||||
this.blueprint.addEventListener(this.blueprint.settings.editTextEventName.begin, this.unlistenHandler)
|
||||
this.blueprint.addEventListener(this.blueprint.settings.editTextEventName.end, this.listenHandler)
|
||||
this.blueprint.addEventListener(Configuration.editTextEventName.begin, this.unlistenHandler)
|
||||
this.blueprint.addEventListener(Configuration.editTextEventName.end, this.listenHandler)
|
||||
}
|
||||
}
|
||||
|
||||
unlistenDOMElement() {
|
||||
this.unlistenEvents()
|
||||
this.blueprint.removeEventListener(this.blueprint.settings.focusEventName.begin, this.listenHandler)
|
||||
this.blueprint.removeEventListener(this.blueprint.settings.focusEventName.end, this.unlistenHandler)
|
||||
this.blueprint.removeEventListener(this.blueprint.settings.editTextEventName.begin, this.unlistenHandler)
|
||||
this.blueprint.removeEventListener(this.blueprint.settings.editTextEventName.end, this.listenHandler)
|
||||
this.blueprint.removeEventListener(Configuration.focusEventName.begin, this.listenHandler)
|
||||
this.blueprint.removeEventListener(Configuration.focusEventName.end, this.unlistenHandler)
|
||||
this.blueprint.removeEventListener(Configuration.editTextEventName.begin, this.unlistenHandler)
|
||||
this.blueprint.removeEventListener(Configuration.editTextEventName.end, this.listenHandler)
|
||||
}
|
||||
|
||||
/* Subclasses will probabily override the following methods */
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IContext from "../IContext"
|
||||
import ISerializer from "../../serialization/ISerializer"
|
||||
import KeyBindingEntity from "../../entity/KeyBindingEntity"
|
||||
@@ -45,7 +46,7 @@ export default class IKeyboardShortcut extends IContext {
|
||||
wantsShift(keyEntry) == e.shiftKey
|
||||
&& wantsCtrl(keyEntry) == e.ctrlKey
|
||||
&& wantsAlt(keyEntry) == e.altKey
|
||||
&& this.blueprint.settings.Keys[keyEntry.Key] == e.code
|
||||
&& Configuration.Keys[keyEntry.Key] == e.code
|
||||
)) {
|
||||
if (options.consumeEvent) {
|
||||
e.stopImmediatePropagation()
|
||||
@@ -64,7 +65,7 @@ export default class IKeyboardShortcut extends IContext {
|
||||
|| keyEntry.bCtrl && e.key == "Control"
|
||||
|| keyEntry.bAlt && e.key == "Alt"
|
||||
|| keyEntry.bCmd && e.key == "Meta"
|
||||
|| this.blueprint.settings.Keys[keyEntry.Key] == e.code
|
||||
|| Configuration.Keys[keyEntry.Key] == e.code
|
||||
)) {
|
||||
if (options.consumeEvent) {
|
||||
e.stopImmediatePropagation()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
|
||||
export default class KeyboardCanc extends IKeyboardShortcut {
|
||||
@@ -12,7 +13,7 @@ export default class KeyboardCanc extends IKeyboardShortcut {
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = {
|
||||
...options,
|
||||
activationKeys: blueprint.settings.deleteNodesKeyboardKey
|
||||
activationKeys: Configuration.deleteNodesKeyboardKey
|
||||
}
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
import Zoom from "../mouse/Zoom"
|
||||
|
||||
@@ -16,7 +17,7 @@ export default class KeyboardEnableZoom extends IKeyboardShortcut {
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = {
|
||||
...options,
|
||||
activationKeys: blueprint.settings.enableZoomIn
|
||||
activationKeys: Configuration.enableZoomIn
|
||||
}
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
|
||||
/**
|
||||
@@ -15,7 +16,7 @@ export default class KeyboardSelectAll extends IKeyboardShortcut {
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = {
|
||||
...options,
|
||||
activationKeys: blueprint.settings.selectAllKeyboardKey
|
||||
activationKeys: Configuration.selectAllKeyboardKey
|
||||
}
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
/**
|
||||
@@ -74,7 +75,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(this.blueprint.settings.trackingMouseEventName.begin)
|
||||
const dragEvent = self.getEvent(Configuration.trackingMouseEventName.begin)
|
||||
self.#trackingMouse = this.target.dispatchEvent(dragEvent) == false
|
||||
// Do actual actions
|
||||
self.startDrag()
|
||||
@@ -107,7 +108,7 @@ export default class IMouseClickDrag extends IPointing {
|
||||
}
|
||||
self.unclicked()
|
||||
if (self.#trackingMouse) {
|
||||
const dragEvent = self.getEvent(this.blueprint.settings.trackingMouseEventName.end)
|
||||
const dragEvent = self.getEvent(Configuration.trackingMouseEventName.end)
|
||||
this.target.dispatchEvent(dragEvent)
|
||||
self.#trackingMouse = false
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
})
|
||||
if (this.enteredPin) {
|
||||
this.blueprint.addGraphElement(this.link)
|
||||
this.link.setDestinationPin(this.enteredPin)
|
||||
this.link.destinationPin = this.enteredPin
|
||||
this.link.setLinkMessage(null)
|
||||
this.link.finishDragging()
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @ts-check
|
||||
|
||||
import Configuration from "../../Configuration"
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
export default class MouseTracking extends IPointing {
|
||||
@@ -55,20 +56,20 @@ export default class MouseTracking extends IPointing {
|
||||
listenEvents() {
|
||||
this.listenMouseMove()
|
||||
this.blueprint.addEventListener(
|
||||
this.blueprint.settings.trackingMouseEventName.begin,
|
||||
Configuration.trackingMouseEventName.begin,
|
||||
/** @type {(e: Event) => any} */(this.#trackingMouseStolenHandler))
|
||||
this.blueprint.addEventListener(
|
||||
this.blueprint.settings.trackingMouseEventName.end,
|
||||
Configuration.trackingMouseEventName.end,
|
||||
/** @type {(e: Event) => any} */(this.#trackingMouseGaveBackHandler))
|
||||
}
|
||||
|
||||
unlistenEvents() {
|
||||
this.unlistenMouseMove()
|
||||
this.blueprint.removeEventListener(
|
||||
this.blueprint.settings.trackingMouseEventName.begin,
|
||||
Configuration.trackingMouseEventName.begin,
|
||||
/** @type {(e: Event) => any} */(this.#trackingMouseStolenHandler))
|
||||
this.blueprint.removeEventListener(
|
||||
this.blueprint.settings.trackingMouseEventName.end,
|
||||
Configuration.trackingMouseEventName.end,
|
||||
/** @type {(e: Event) => any} */(this.#trackingMouseGaveBackHandler)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user