mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-03 23:55:04 +08:00
Various fixes, smaller refactoring
This commit is contained in:
@@ -3,17 +3,15 @@ import IPointing from "./IPointing"
|
||||
|
||||
export default class IMouseWheel extends IPointing {
|
||||
|
||||
#mouseWheelHandler =
|
||||
/** @param {WheelEvent} e */
|
||||
e => {
|
||||
e.preventDefault()
|
||||
const location = this.locationFromEvent(e)
|
||||
this.wheel(Math.sign(e.deltaY * Configuration.mouseWheelFactor), location)
|
||||
}
|
||||
/** @param {WheelEvent} e */
|
||||
#mouseWheelHandler = e => {
|
||||
e.preventDefault()
|
||||
const location = this.locationFromEvent(e)
|
||||
this.wheel(Math.sign(e.deltaY * Configuration.mouseWheelFactor), location)
|
||||
}
|
||||
|
||||
#mouseParentWheelHandler =
|
||||
/** @param {WheelEvent} e */
|
||||
e => e.preventDefault()
|
||||
/** @param {WheelEvent} e */
|
||||
#mouseParentWheelHandler = e => e.preventDefault()
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} target
|
||||
|
||||
@@ -8,45 +8,43 @@ import IPointing from "./IPointing"
|
||||
*/
|
||||
export default class MouseClick extends IPointing {
|
||||
|
||||
#mouseDownHandler =
|
||||
/** @param {MouseEvent} e */
|
||||
e => {
|
||||
this.blueprint.setFocused(true)
|
||||
switch (e.button) {
|
||||
case this.options.clickButton:
|
||||
// Either doesn't matter or consider the click only when clicking on the target, not descandants
|
||||
if (!this.options.strictTarget || e.target === e.currentTarget) {
|
||||
if (this.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
// Attach the listeners
|
||||
document.addEventListener("mouseup", this.#mouseUpHandler)
|
||||
this.clickedPosition = this.locationFromEvent(e)
|
||||
this.blueprint.mousePosition[0] = this.clickedPosition[0]
|
||||
this.blueprint.mousePosition[1] = this.clickedPosition[1]
|
||||
this.clicked(this.clickedPosition)
|
||||
/** @param {MouseEvent} e */
|
||||
#mouseDownHandler = e => {
|
||||
this.blueprint.setFocused(true)
|
||||
switch (e.button) {
|
||||
case this.options.clickButton:
|
||||
// Either doesn't matter or consider the click only when clicking on the target, not descandants
|
||||
if (!this.options.strictTarget || e.target === e.currentTarget) {
|
||||
if (this.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
break
|
||||
default:
|
||||
if (!this.options.exitAnyButton) {
|
||||
this.#mouseUpHandler(e)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
#mouseUpHandler =
|
||||
/** @param {MouseEvent} e */
|
||||
e => {
|
||||
if (!this.options.exitAnyButton || e.button == this.options.clickButton) {
|
||||
if (this.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
// Attach the listeners
|
||||
document.addEventListener("mouseup", this.#mouseUpHandler)
|
||||
this.clickedPosition = this.locationFromEvent(e)
|
||||
this.blueprint.mousePosition[0] = this.clickedPosition[0]
|
||||
this.blueprint.mousePosition[1] = this.clickedPosition[1]
|
||||
this.clicked(this.clickedPosition)
|
||||
}
|
||||
// Remove the handlers of "mousemove" and "mouseup"
|
||||
document.removeEventListener("mouseup", this.#mouseUpHandler)
|
||||
this.unclicked()
|
||||
}
|
||||
break
|
||||
default:
|
||||
if (!this.options.exitAnyButton) {
|
||||
this.#mouseUpHandler(e)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {MouseEvent} e */
|
||||
#mouseUpHandler = e => {
|
||||
if (!this.options.exitAnyButton || e.button == this.options.clickButton) {
|
||||
if (this.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
// Remove the handlers of "mousemove" and "mouseup"
|
||||
document.removeEventListener("mouseup", this.#mouseUpHandler)
|
||||
this.unclicked()
|
||||
}
|
||||
}
|
||||
|
||||
clickedPosition = [0, 0]
|
||||
|
||||
|
||||
@@ -80,9 +80,8 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
this.#listenedPins = this.blueprint.querySelectorAll("ueb-pin")
|
||||
this.#listenedPins.forEach(pin => {
|
||||
if (pin != this.target) {
|
||||
const clickableElement = pin.template.getClickableElement()
|
||||
clickableElement.addEventListener("mouseenter", this.#mouseenterHandler)
|
||||
clickableElement.addEventListener("mouseleave", this.#mouseleaveHandler)
|
||||
pin.addEventListener("mouseenter", this.#mouseenterHandler)
|
||||
pin.addEventListener("mouseleave", this.#mouseleaveHandler)
|
||||
}
|
||||
})
|
||||
this.link.startDragging()
|
||||
|
||||
@@ -8,23 +8,21 @@ import IPointing from "./IPointing"
|
||||
*/
|
||||
export default class MouseDbClick extends IPointing {
|
||||
|
||||
static ignoreDbClick =
|
||||
/** @param {Number[]} location */
|
||||
location => { }
|
||||
/** @param {Number[]} location */
|
||||
static ignoreDbClick = location => { }
|
||||
|
||||
#mouseDbClickHandler =
|
||||
/** @param {MouseEvent} e */
|
||||
e => {
|
||||
if (!this.options.strictTarget || e.target === e.currentTarget) {
|
||||
if (this.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
this.clickedPosition = this.locationFromEvent(e)
|
||||
this.blueprint.mousePosition[0] = this.clickedPosition[0]
|
||||
this.blueprint.mousePosition[1] = this.clickedPosition[1]
|
||||
this.dbclicked(this.clickedPosition)
|
||||
/** @param {MouseEvent} e */
|
||||
#mouseDbClickHandler = e => {
|
||||
if (!this.options.strictTarget || e.target === e.currentTarget) {
|
||||
if (this.options.consumeEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
this.clickedPosition = this.locationFromEvent(e)
|
||||
this.blueprint.mousePosition[0] = this.clickedPosition[0]
|
||||
this.blueprint.mousePosition[1] = this.clickedPosition[1]
|
||||
this.dbclicked(this.clickedPosition)
|
||||
}
|
||||
}
|
||||
|
||||
#onDbClick
|
||||
get onDbClick() {
|
||||
|
||||
@@ -6,41 +6,33 @@ export default class MouseTracking extends IPointing {
|
||||
/** @type {IPointing} */
|
||||
#mouseTracker = null
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mousemoveHandler
|
||||
/** @param {MouseEvent} e */
|
||||
#mousemoveHandler= e => {
|
||||
e.preventDefault()
|
||||
this.blueprint.mousePosition = this.locationFromEvent(e)
|
||||
}
|
||||
|
||||
/** @type {(e: CustomEvent) => void} */
|
||||
#trackingMouseStolenHandler
|
||||
/** @param {CustomEvent} e */
|
||||
#trackingMouseStolenHandler = e => {
|
||||
if (!this.#mouseTracker) {
|
||||
e.preventDefault()
|
||||
this.#mouseTracker = e.detail.tracker
|
||||
this.unlistenMouseMove()
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {(e: CustomEvent) => void} */
|
||||
#trackingMouseGaveBackHandler
|
||||
/** @param {CustomEvent} e */
|
||||
#trackingMouseGaveBackHandler = e => {
|
||||
if (this.#mouseTracker == e.detail.tracker) {
|
||||
e.preventDefault()
|
||||
this.#mouseTracker = null
|
||||
this.listenMouseMove()
|
||||
}
|
||||
}
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.listenOnFocus = true
|
||||
super(target, blueprint, options)
|
||||
|
||||
let self = this
|
||||
|
||||
this.#mousemoveHandler = e => {
|
||||
e.preventDefault()
|
||||
self.blueprint.mousePosition = self.locationFromEvent(e)
|
||||
}
|
||||
|
||||
this.#trackingMouseStolenHandler = e => {
|
||||
if (!self.#mouseTracker) {
|
||||
e.preventDefault()
|
||||
this.#mouseTracker = e.detail.tracker
|
||||
self.unlistenMouseMove()
|
||||
}
|
||||
}
|
||||
|
||||
this.#trackingMouseGaveBackHandler = e => {
|
||||
if (self.#mouseTracker == e.detail.tracker) {
|
||||
e.preventDefault()
|
||||
self.#mouseTracker = null
|
||||
self.listenMouseMove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
listenMouseMove() {
|
||||
|
||||
@@ -2,15 +2,13 @@ import IInput from "../IInput"
|
||||
|
||||
export default class Unfocus extends IInput {
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#clickHandler
|
||||
/** @param {MouseEvent} e */
|
||||
#clickHandler = e => this.clickedSomewhere(/** @type {HTMLElement} */(e.target))
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.listenOnFocus = true
|
||||
super(target, blueprint, options)
|
||||
|
||||
let self = this
|
||||
this.#clickHandler = e => self.clickedSomewhere(/** @type {HTMLElement} */(e.target))
|
||||
if (this.blueprint.focus) {
|
||||
document.addEventListener("click", this.#clickHandler)
|
||||
}
|
||||
|
||||
@@ -3,12 +3,10 @@ import IMouseWheel from "./IMouseWheel"
|
||||
export default class Zoom extends IMouseWheel {
|
||||
|
||||
#enableZoonIn = false
|
||||
|
||||
get enableZoonIn() {
|
||||
return this.#enableZoonIn
|
||||
}
|
||||
set enableZoonIn(value) {
|
||||
value = Boolean(value)
|
||||
if (value == this.#enableZoonIn) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user