mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:41:34 +08:00
Fix other interface classes naming convention
This commit is contained in:
60
js/input/Context.js → js/input/IContext.js
Executable file → Normal file
60
js/input/Context.js → js/input/IContext.js
Executable file → Normal file
@@ -1,30 +1,30 @@
|
||||
export default class Context {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
/** @type {HTMLElement} */
|
||||
this.target = target
|
||||
/** @type {import("../Blueprint").default}" */
|
||||
this.blueprint = blueprint
|
||||
this.options = options
|
||||
let self = this
|
||||
this.blueprintFocusHandler = _ => self.listenEvents()
|
||||
this.blueprintUnfocusHandler = _ => self.unlistenEvents()
|
||||
if (options?.wantsFocusCallback ?? false) {
|
||||
this.blueprint.addEventListener("blueprint-focus", this.blueprintFocusHandler)
|
||||
this.blueprint.addEventListener("blueprint-unfocus", this.blueprintUnfocusHandler)
|
||||
}
|
||||
}
|
||||
|
||||
unlistenDOMElement() {
|
||||
this.unlistenEvents()
|
||||
this.blueprint.removeEventListener("blueprint-focus", this.blueprintFocusHandler)
|
||||
this.blueprint.removeEventListener("blueprint-unfocus", this.blueprintUnfocusHandler)
|
||||
}
|
||||
|
||||
/* Subclasses will probabily override the following methods */
|
||||
listenEvents() {
|
||||
}
|
||||
|
||||
unlistenEvents() {
|
||||
}
|
||||
}
|
||||
export default class IContext {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
/** @type {HTMLElement} */
|
||||
this.target = target
|
||||
/** @type {import("../Blueprint").default}" */
|
||||
this.blueprint = blueprint
|
||||
this.options = options
|
||||
let self = this
|
||||
this.blueprintFocusHandler = _ => self.listenEvents()
|
||||
this.blueprintUnfocusHandler = _ => self.unlistenEvents()
|
||||
if (options?.wantsFocusCallback ?? false) {
|
||||
this.blueprint.addEventListener("blueprint-focus", this.blueprintFocusHandler)
|
||||
this.blueprint.addEventListener("blueprint-unfocus", this.blueprintUnfocusHandler)
|
||||
}
|
||||
}
|
||||
|
||||
unlistenDOMElement() {
|
||||
this.unlistenEvents()
|
||||
this.blueprint.removeEventListener("blueprint-focus", this.blueprintFocusHandler)
|
||||
this.blueprint.removeEventListener("blueprint-unfocus", this.blueprintUnfocusHandler)
|
||||
}
|
||||
|
||||
/* Subclasses will probabily override the following methods */
|
||||
listenEvents() {
|
||||
}
|
||||
|
||||
unlistenEvents() {
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import Context from "../Context"
|
||||
import IContext from "../IContext"
|
||||
import ObjectSerializer from "../../serialization/ObjectSerializer"
|
||||
|
||||
export default class Copy extends Context {
|
||||
export default class Copy extends IContext {
|
||||
|
||||
#copyHandler
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import NodeElement from "../../element/NodeElement"
|
||||
import ObjectSerializer from "../../serialization/ObjectSerializer"
|
||||
import Context from "../Context"
|
||||
import IContext from "../IContext"
|
||||
|
||||
export default class Paste extends Context {
|
||||
export default class Paste extends IContext {
|
||||
|
||||
#pasteHandle
|
||||
|
||||
|
||||
174
js/input/keybaord/KeyboardShortcut.js → js/input/keybaord/IKeyboardShortcut.js
Executable file → Normal file
174
js/input/keybaord/KeyboardShortcut.js → js/input/keybaord/IKeyboardShortcut.js
Executable file → Normal file
@@ -1,87 +1,87 @@
|
||||
import Configuration from "../../Configuration"
|
||||
import Context from "../Context"
|
||||
import Parsimmon from "parsimmon"
|
||||
|
||||
let P = Parsimmon
|
||||
|
||||
class KeyGrammar {
|
||||
|
||||
// Creates a grammar where each alternative is the string from ModifierKey mapped to a number for bit or use
|
||||
ModifierKey = r => P.alt(...Configuration.ModifierKeys.map((v, i) => P.string(v).map(_ => 1 << i)))
|
||||
Key = r => P.alt(...Object.keys(Configuration.Keys).map(v => P.string(v))).map(v => Configuration.Keys[v])
|
||||
KeyboardShortcut = r => P.alt(
|
||||
P.seqMap(
|
||||
P.seqMap(r.ModifierKey, P.optWhitespace, P.string(Configuration.keysSeparator), (v, _, __) => v)
|
||||
.atLeast(1)
|
||||
.map(v => v.reduce((acc, cur) => acc | cur)),
|
||||
P.optWhitespace,
|
||||
r.Key,
|
||||
(modifierKeysFlag, _, key) => ({
|
||||
key: key,
|
||||
ctrlKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Ctrl"))),
|
||||
shiftKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Shift"))),
|
||||
altKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Alt"))),
|
||||
metaKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Meta")))
|
||||
})
|
||||
),
|
||||
r.Key.map(v => ({ key: v }))
|
||||
)
|
||||
.trim(P.optWhitespace)
|
||||
}
|
||||
|
||||
export default class KeyboardShortcut extends Context {
|
||||
|
||||
static keyGrammar = P.createLanguage(new KeyGrammar())
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.wantsFocusCallback = true
|
||||
super(target, blueprint, options)
|
||||
|
||||
/** @type {String[]} */
|
||||
this.key = this.options.key
|
||||
this.ctrlKey = options.ctrlKey ?? false
|
||||
this.shiftKey = options.shiftKey ?? false
|
||||
this.altKey = options.altKey ?? false
|
||||
this.metaKey = options.metaKey ?? false
|
||||
|
||||
let self = this
|
||||
this.keyDownHandler = e => {
|
||||
if (
|
||||
e.code == self.key
|
||||
&& e.ctrlKey === self.ctrlKey
|
||||
&& e.shiftKey === self.shiftKey
|
||||
&& e.altKey === self.altKey
|
||||
&& e.metaKey === self.metaKey
|
||||
) {
|
||||
self.fire()
|
||||
e.preventDefault()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} keyString
|
||||
* @returns {Object}
|
||||
*/
|
||||
static keyOptionsParse(options, keyString) {
|
||||
options = {
|
||||
...options,
|
||||
...KeyboardShortcut.keyGrammar.KeyboardShortcut.parse(keyString).value
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
listenEvents() {
|
||||
document.addEventListener("keydown", this.keyDownHandler)
|
||||
}
|
||||
|
||||
unlistenEvents() {
|
||||
document.removeEventListener("keydown", this.keyDownHandler)
|
||||
}
|
||||
|
||||
fire() {
|
||||
}
|
||||
}
|
||||
import Configuration from "../../Configuration"
|
||||
import IContext from "../IContext"
|
||||
import Parsimmon from "parsimmon"
|
||||
|
||||
let P = Parsimmon
|
||||
|
||||
class KeyGrammar {
|
||||
|
||||
// Creates a grammar where each alternative is the string from ModifierKey mapped to a number for bit or use
|
||||
ModifierKey = r => P.alt(...Configuration.ModifierKeys.map((v, i) => P.string(v).map(_ => 1 << i)))
|
||||
Key = r => P.alt(...Object.keys(Configuration.Keys).map(v => P.string(v))).map(v => Configuration.Keys[v])
|
||||
KeyboardShortcut = r => P.alt(
|
||||
P.seqMap(
|
||||
P.seqMap(r.ModifierKey, P.optWhitespace, P.string(Configuration.keysSeparator), (v, _, __) => v)
|
||||
.atLeast(1)
|
||||
.map(v => v.reduce((acc, cur) => acc | cur)),
|
||||
P.optWhitespace,
|
||||
r.Key,
|
||||
(modifierKeysFlag, _, key) => ({
|
||||
key: key,
|
||||
ctrlKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Ctrl"))),
|
||||
shiftKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Shift"))),
|
||||
altKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Alt"))),
|
||||
metaKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Meta")))
|
||||
})
|
||||
),
|
||||
r.Key.map(v => ({ key: v }))
|
||||
)
|
||||
.trim(P.optWhitespace)
|
||||
}
|
||||
|
||||
export default class IKeyboardShortcut extends IContext {
|
||||
|
||||
static keyGrammar = P.createLanguage(new KeyGrammar())
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.wantsFocusCallback = true
|
||||
super(target, blueprint, options)
|
||||
|
||||
/** @type {String[]} */
|
||||
this.key = this.options.key
|
||||
this.ctrlKey = options.ctrlKey ?? false
|
||||
this.shiftKey = options.shiftKey ?? false
|
||||
this.altKey = options.altKey ?? false
|
||||
this.metaKey = options.metaKey ?? false
|
||||
|
||||
let self = this
|
||||
this.keyDownHandler = e => {
|
||||
if (
|
||||
e.code == self.key
|
||||
&& e.ctrlKey === self.ctrlKey
|
||||
&& e.shiftKey === self.shiftKey
|
||||
&& e.altKey === self.altKey
|
||||
&& e.metaKey === self.metaKey
|
||||
) {
|
||||
self.fire()
|
||||
e.preventDefault()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} keyString
|
||||
* @returns {Object}
|
||||
*/
|
||||
static keyOptionsParse(options, keyString) {
|
||||
options = {
|
||||
...options,
|
||||
...IKeyboardShortcut.keyGrammar.KeyboardShortcut.parse(keyString).value
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
listenEvents() {
|
||||
document.addEventListener("keydown", this.keyDownHandler)
|
||||
}
|
||||
|
||||
unlistenEvents() {
|
||||
document.removeEventListener("keydown", this.keyDownHandler)
|
||||
}
|
||||
|
||||
fire() {
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import KeyboardShortcut from "./KeyboardShortcut"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
import Configuration from "../../Configuration"
|
||||
|
||||
export default class KeyvoardCanc extends KeyboardShortcut {
|
||||
export default class KeyvoardCanc extends IKeyboardShortcut {
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -10,7 +10,7 @@ export default class KeyvoardCanc extends KeyboardShortcut {
|
||||
* @param {OBject} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = KeyboardShortcut.keyOptionsParse(options, Configuration.deleteNodesKeyboardKey)
|
||||
options = IKeyboardShortcut.keyOptionsParse(options, Configuration.deleteNodesKeyboardKey)
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import KeyboardShortcut from "./KeyboardShortcut"
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
import Configuration from "../../Configuration"
|
||||
|
||||
export default class KeyboardSelectAll extends KeyboardShortcut {
|
||||
export default class KeyboardSelectAll extends IKeyboardShortcut {
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -10,7 +10,7 @@ export default class KeyboardSelectAll extends KeyboardShortcut {
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options = KeyboardShortcut.keyOptionsParse(options, Configuration.selectAllKeyboardKey)
|
||||
options = IKeyboardShortcut.keyOptionsParse(options, Configuration.selectAllKeyboardKey)
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
|
||||
278
js/input/mouse/MouseClickDrag.js → js/input/mouse/IMouseClickDrag.js
Executable file → Normal file
278
js/input/mouse/MouseClickDrag.js → js/input/mouse/IMouseClickDrag.js
Executable file → Normal file
@@ -1,139 +1,139 @@
|
||||
import Configuration from "../../Configuration"
|
||||
import Pointing from "./Pointing"
|
||||
|
||||
/**
|
||||
* This class manages the ui gesture of mouse click and drag. Tha actual operations are implemented by the subclasses.
|
||||
*/
|
||||
export default class MouseClickDrag extends Pointing {
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseDownHandler
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseStartedMovingHandler
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseMoveHandler
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseUpHandler
|
||||
|
||||
/** @type {Boolean} */
|
||||
#trackingMouse = false
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
this.clickButton = options?.clickButton ?? 0
|
||||
this.exitAnyButton = options?.exitAnyButton ?? true
|
||||
this.moveEverywhere = options?.moveEverywhere ?? false
|
||||
this.looseTarget = options?.looseTarget ?? false
|
||||
this.consumeClickEvent = options?.consumeClickEvent ?? true
|
||||
this.started = false
|
||||
this.clickedPosition = [0, 0]
|
||||
|
||||
const movementListenedElement = this.moveEverywhere ? document.documentElement : this.movementSpace
|
||||
let self = this
|
||||
|
||||
this.#mouseDownHandler = e => {
|
||||
this.blueprint.setFocused(true)
|
||||
switch (e.button) {
|
||||
case self.clickButton:
|
||||
// Either doesn't matter or consider the click only when clicking on the parent, not descandants
|
||||
if (self.looseTarget || e.target == e.currentTarget) {
|
||||
e.preventDefault()
|
||||
if (this.consumeClickEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
self.started = false
|
||||
// Attach the listeners
|
||||
movementListenedElement.addEventListener("mousemove", self.#mouseStartedMovingHandler)
|
||||
document.addEventListener("mouseup", self.#mouseUpHandler)
|
||||
self.clickedPosition = self.locationFromEvent(e)
|
||||
self.clicked(self.clickedPosition)
|
||||
}
|
||||
break
|
||||
default:
|
||||
if (!self.exitAnyButton) {
|
||||
self.#mouseUpHandler(e)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
this.#mouseStartedMovingHandler = e => {
|
||||
e.preventDefault()
|
||||
// Delegate from now on to self.#mouseMoveHandler
|
||||
movementListenedElement.removeEventListener("mousemove", self.#mouseStartedMovingHandler)
|
||||
movementListenedElement.addEventListener("mousemove", self.#mouseMoveHandler)
|
||||
|
||||
// Do actual actions
|
||||
self.startDrag()
|
||||
self.started = true
|
||||
const dragEvent = self.getEvent(Configuration.trackingMouseEventName.begin)
|
||||
// Handler calls e.preventDefault() when it receives the event, this means dispatchEvent returns false
|
||||
self.#trackingMouse = this.target.dispatchEvent(dragEvent) == false
|
||||
}
|
||||
|
||||
this.#mouseMoveHandler = e => {
|
||||
e.preventDefault()
|
||||
const location = self.locationFromEvent(e)
|
||||
const movement = [e.movementX, e.movementY]
|
||||
self.dragTo(location, movement)
|
||||
if (self.#trackingMouse) {
|
||||
self.blueprint.entity.mousePosition = self.locationFromEvent(e)
|
||||
}
|
||||
}
|
||||
|
||||
this.#mouseUpHandler = e => {
|
||||
if (!self.exitAnyButton || e.button == self.clickButton) {
|
||||
e.preventDefault()
|
||||
// Remove the handlers of "mousemove" and "mouseup"
|
||||
movementListenedElement.removeEventListener("mousemove", self.#mouseStartedMovingHandler)
|
||||
movementListenedElement.removeEventListener("mousemove", self.#mouseMoveHandler)
|
||||
document.removeEventListener("mouseup", self.#mouseUpHandler)
|
||||
self.endDrag()
|
||||
if (self.#trackingMouse) {
|
||||
const dragEvent = self.getEvent(Configuration.trackingMouseEventName.end)
|
||||
this.target.dispatchEvent(dragEvent)
|
||||
self.#trackingMouse = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.target.addEventListener("mousedown", this.#mouseDownHandler)
|
||||
if (this.clickButton == 2) {
|
||||
this.target.addEventListener("contextmenu", e => e.preventDefault())
|
||||
}
|
||||
}
|
||||
|
||||
getEvent(eventName) {
|
||||
return new CustomEvent(eventName, {
|
||||
detail: {
|
||||
tracker: this
|
||||
},
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
})
|
||||
}
|
||||
|
||||
unlistenDOMElement() {
|
||||
super.unlistenDOMElement()
|
||||
this.target.removeEventListener("mousedown", this.#mouseDownHandler)
|
||||
if (this.clickButton == 2) {
|
||||
this.target.removeEventListener("contextmenu", e => e.preventDefault())
|
||||
}
|
||||
}
|
||||
|
||||
/* Subclasses will override the following methods */
|
||||
clicked(location) {
|
||||
}
|
||||
|
||||
startDrag() {
|
||||
}
|
||||
|
||||
dragTo(location, movement) {
|
||||
}
|
||||
|
||||
endDrag() {
|
||||
}
|
||||
}
|
||||
import Configuration from "../../Configuration"
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
/**
|
||||
* This class manages the ui gesture of mouse click and drag. Tha actual operations are implemented by the subclasses.
|
||||
*/
|
||||
export default class IMouseClickDrag extends IPointing {
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseDownHandler
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseStartedMovingHandler
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseMoveHandler
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
#mouseUpHandler
|
||||
|
||||
/** @type {Boolean} */
|
||||
#trackingMouse = false
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
this.clickButton = options?.clickButton ?? 0
|
||||
this.exitAnyButton = options?.exitAnyButton ?? true
|
||||
this.moveEverywhere = options?.moveEverywhere ?? false
|
||||
this.looseTarget = options?.looseTarget ?? false
|
||||
this.consumeClickEvent = options?.consumeClickEvent ?? true
|
||||
this.started = false
|
||||
this.clickedPosition = [0, 0]
|
||||
|
||||
const movementListenedElement = this.moveEverywhere ? document.documentElement : this.movementSpace
|
||||
let self = this
|
||||
|
||||
this.#mouseDownHandler = e => {
|
||||
this.blueprint.setFocused(true)
|
||||
switch (e.button) {
|
||||
case self.clickButton:
|
||||
// Either doesn't matter or consider the click only when clicking on the parent, not descandants
|
||||
if (self.looseTarget || e.target == e.currentTarget) {
|
||||
e.preventDefault()
|
||||
if (this.consumeClickEvent) {
|
||||
e.stopImmediatePropagation() // Captured, don't call anyone else
|
||||
}
|
||||
self.started = false
|
||||
// Attach the listeners
|
||||
movementListenedElement.addEventListener("mousemove", self.#mouseStartedMovingHandler)
|
||||
document.addEventListener("mouseup", self.#mouseUpHandler)
|
||||
self.clickedPosition = self.locationFromEvent(e)
|
||||
self.clicked(self.clickedPosition)
|
||||
}
|
||||
break
|
||||
default:
|
||||
if (!self.exitAnyButton) {
|
||||
self.#mouseUpHandler(e)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
this.#mouseStartedMovingHandler = e => {
|
||||
e.preventDefault()
|
||||
// Delegate from now on to self.#mouseMoveHandler
|
||||
movementListenedElement.removeEventListener("mousemove", self.#mouseStartedMovingHandler)
|
||||
movementListenedElement.addEventListener("mousemove", self.#mouseMoveHandler)
|
||||
|
||||
// Do actual actions
|
||||
self.startDrag()
|
||||
self.started = true
|
||||
const dragEvent = self.getEvent(Configuration.trackingMouseEventName.begin)
|
||||
// Handler calls e.preventDefault() when it receives the event, this means dispatchEvent returns false
|
||||
self.#trackingMouse = this.target.dispatchEvent(dragEvent) == false
|
||||
}
|
||||
|
||||
this.#mouseMoveHandler = e => {
|
||||
e.preventDefault()
|
||||
const location = self.locationFromEvent(e)
|
||||
const movement = [e.movementX, e.movementY]
|
||||
self.dragTo(location, movement)
|
||||
if (self.#trackingMouse) {
|
||||
self.blueprint.entity.mousePosition = self.locationFromEvent(e)
|
||||
}
|
||||
}
|
||||
|
||||
this.#mouseUpHandler = e => {
|
||||
if (!self.exitAnyButton || e.button == self.clickButton) {
|
||||
e.preventDefault()
|
||||
// Remove the handlers of "mousemove" and "mouseup"
|
||||
movementListenedElement.removeEventListener("mousemove", self.#mouseStartedMovingHandler)
|
||||
movementListenedElement.removeEventListener("mousemove", self.#mouseMoveHandler)
|
||||
document.removeEventListener("mouseup", self.#mouseUpHandler)
|
||||
self.endDrag()
|
||||
if (self.#trackingMouse) {
|
||||
const dragEvent = self.getEvent(Configuration.trackingMouseEventName.end)
|
||||
this.target.dispatchEvent(dragEvent)
|
||||
self.#trackingMouse = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.target.addEventListener("mousedown", this.#mouseDownHandler)
|
||||
if (this.clickButton == 2) {
|
||||
this.target.addEventListener("contextmenu", e => e.preventDefault())
|
||||
}
|
||||
}
|
||||
|
||||
getEvent(eventName) {
|
||||
return new CustomEvent(eventName, {
|
||||
detail: {
|
||||
tracker: this
|
||||
},
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
})
|
||||
}
|
||||
|
||||
unlistenDOMElement() {
|
||||
super.unlistenDOMElement()
|
||||
this.target.removeEventListener("mousedown", this.#mouseDownHandler)
|
||||
if (this.clickButton == 2) {
|
||||
this.target.removeEventListener("contextmenu", e => e.preventDefault())
|
||||
}
|
||||
}
|
||||
|
||||
/* Subclasses will override the following methods */
|
||||
clicked(location) {
|
||||
}
|
||||
|
||||
startDrag() {
|
||||
}
|
||||
|
||||
dragTo(location, movement) {
|
||||
}
|
||||
|
||||
endDrag() {
|
||||
}
|
||||
}
|
||||
96
js/input/mouse/MouseWheel.js → js/input/mouse/IMouseWheel.js
Executable file → Normal file
96
js/input/mouse/MouseWheel.js → js/input/mouse/IMouseWheel.js
Executable file → Normal file
@@ -1,48 +1,48 @@
|
||||
import Pointing from "./Pointing"
|
||||
|
||||
export default class MouseWheel extends Pointing {
|
||||
|
||||
/** @type {(e: WheelEvent) => void} */
|
||||
#mouseWheelHandler
|
||||
|
||||
/** @type {(e: WheelEvent) => void} */
|
||||
#mouseParentWheelHandler
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {HTMLElement} target
|
||||
* @param {import("../../Blueprint").default} blueprint
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options) {
|
||||
options.wantsFocusCallback = true
|
||||
super(target, blueprint, options)
|
||||
this.looseTarget = options?.looseTarget ?? true
|
||||
let self = this
|
||||
|
||||
this.#mouseWheelHandler = e => {
|
||||
e.preventDefault()
|
||||
const location = self.locationFromEvent(e)
|
||||
self.wheel(Math.sign(e.deltaY), location)
|
||||
}
|
||||
this.#mouseParentWheelHandler = e => e.preventDefault()
|
||||
|
||||
if (this.blueprint.focused) {
|
||||
this.movementSpace.addEventListener("wheel", this.#mouseWheelHandler, false)
|
||||
}
|
||||
}
|
||||
|
||||
listenEvents() {
|
||||
this.movementSpace.addEventListener("wheel", this.#mouseWheelHandler, false)
|
||||
this.movementSpace.parentElement?.addEventListener("wheel", this.#mouseParentWheelHandler)
|
||||
}
|
||||
|
||||
unlistenEvents() {
|
||||
this.movementSpace.removeEventListener("wheel", this.#mouseWheelHandler, false)
|
||||
this.movementSpace.parentElement?.removeEventListener("wheel", this.#mouseParentWheelHandler)
|
||||
}
|
||||
|
||||
/* Subclasses will override the following method */
|
||||
wheel(variation, location) {
|
||||
}
|
||||
}
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
export default class IMouseWheel extends IPointing {
|
||||
|
||||
/** @type {(e: WheelEvent) => void} */
|
||||
#mouseWheelHandler
|
||||
|
||||
/** @type {(e: WheelEvent) => void} */
|
||||
#mouseParentWheelHandler
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {HTMLElement} target
|
||||
* @param {import("../../Blueprint").default} blueprint
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options) {
|
||||
options.wantsFocusCallback = true
|
||||
super(target, blueprint, options)
|
||||
this.looseTarget = options?.looseTarget ?? true
|
||||
let self = this
|
||||
|
||||
this.#mouseWheelHandler = e => {
|
||||
e.preventDefault()
|
||||
const location = self.locationFromEvent(e)
|
||||
self.wheel(Math.sign(e.deltaY), location)
|
||||
}
|
||||
this.#mouseParentWheelHandler = e => e.preventDefault()
|
||||
|
||||
if (this.blueprint.focused) {
|
||||
this.movementSpace.addEventListener("wheel", this.#mouseWheelHandler, false)
|
||||
}
|
||||
}
|
||||
|
||||
listenEvents() {
|
||||
this.movementSpace.addEventListener("wheel", this.#mouseWheelHandler, false)
|
||||
this.movementSpace.parentElement?.addEventListener("wheel", this.#mouseParentWheelHandler)
|
||||
}
|
||||
|
||||
unlistenEvents() {
|
||||
this.movementSpace.removeEventListener("wheel", this.#mouseWheelHandler, false)
|
||||
this.movementSpace.parentElement?.removeEventListener("wheel", this.#mouseParentWheelHandler)
|
||||
}
|
||||
|
||||
/* Subclasses will override the following method */
|
||||
wheel(variation, location) {
|
||||
}
|
||||
}
|
||||
44
js/input/mouse/Pointing.js → js/input/mouse/IPointing.js
Executable file → Normal file
44
js/input/mouse/Pointing.js → js/input/mouse/IPointing.js
Executable file → Normal file
@@ -1,22 +1,22 @@
|
||||
import Context from "../Context"
|
||||
import Utility from "../../Utility"
|
||||
|
||||
export default class Pointing extends Context {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
this.movementSpace = this.blueprint?.getGridDOMElement() ?? document.documentElement
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {MouseEvent} mouseEvent
|
||||
* @returns
|
||||
*/
|
||||
locationFromEvent(mouseEvent) {
|
||||
return this.blueprint.compensateTranslation(
|
||||
Utility.convertLocation(
|
||||
[mouseEvent.clientX, mouseEvent.clientY],
|
||||
this.movementSpace))
|
||||
}
|
||||
}
|
||||
import IContext from "../IContext"
|
||||
import Utility from "../../Utility"
|
||||
|
||||
export default class IPointing extends IContext {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
this.movementSpace = this.blueprint?.getGridDOMElement() ?? document.documentElement
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {MouseEvent} mouseEvent
|
||||
* @returns
|
||||
*/
|
||||
locationFromEvent(mouseEvent) {
|
||||
return this.blueprint.compensateTranslation(
|
||||
Utility.convertLocation(
|
||||
[mouseEvent.clientX, mouseEvent.clientY],
|
||||
this.movementSpace))
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import LinkElement from "../../element/LinkElement"
|
||||
import LinkMessageElement from "../../element/LinkMessageElement"
|
||||
import MouseClickDrag from "./MouseClickDrag"
|
||||
import IMouseClickDrag from "./IMouseClickDrag"
|
||||
|
||||
/** @typedef {import("../../element/PinElement").default} PinElement */
|
||||
export default class MouseCreateLink extends MouseClickDrag {
|
||||
export default class MouseCreateLink extends IMouseClickDrag {
|
||||
|
||||
/** @type {NodeListOf<PinElement>} */
|
||||
#listenedPins
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import MouseClickDrag from "./MouseClickDrag"
|
||||
import IMouseClickDrag from "./IMouseClickDrag"
|
||||
import Utility from "../../Utility"
|
||||
|
||||
/**
|
||||
* @typedef {import("../../element/ISelectableDraggableElement").ISelectableDraggableElement} ISelectableDraggableElement
|
||||
* @typedef {import("../../element/ISelectableDraggableElement").default} ISelectableDraggableElement
|
||||
*/
|
||||
export default class MouseMoveNodes extends MouseClickDrag {
|
||||
export default class MouseMoveNodes extends IMouseClickDrag {
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import MouseClickDrag from "./MouseClickDrag"
|
||||
import IMouseClickDrag from "./IMouseClickDrag"
|
||||
|
||||
export default class MouseScrollGraph extends MouseClickDrag {
|
||||
export default class MouseScrollGraph extends IMouseClickDrag {
|
||||
|
||||
startDrag() {
|
||||
this.blueprint.template.applyStartDragScrolling(this.blueprint)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import Configuration from "../../Configuration"
|
||||
import Pointing from "./Pointing"
|
||||
import IPointing from "./IPointing"
|
||||
|
||||
export default class MouseTracking extends Pointing {
|
||||
export default class MouseTracking extends IPointing {
|
||||
|
||||
/** @type {Pointing} */
|
||||
/** @type {IPointing} */
|
||||
#mouseTracker = null
|
||||
|
||||
/** @type {(e: MouseEvent) => void} */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import MouseClickDrag from "./MouseClickDrag"
|
||||
import IMouseClickDrag from "./IMouseClickDrag"
|
||||
|
||||
export default class Select extends MouseClickDrag {
|
||||
export default class Select extends IMouseClickDrag {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Context from "../Context"
|
||||
import IContext from "../IContext"
|
||||
|
||||
export default class Unfocus extends Context {
|
||||
export default class Unfocus extends IContext {
|
||||
|
||||
/** @type {(e: WheelEvent) => void} */
|
||||
#clickHandler
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import MouseWheel from "./MouseWheel"
|
||||
import IMouseWheel from "./IMouseWheel"
|
||||
|
||||
export default class Zoom extends MouseWheel {
|
||||
export default class Zoom extends IMouseWheel {
|
||||
|
||||
wheel(variation, location) {
|
||||
let zoomLevel = this.blueprint.getZoom()
|
||||
|
||||
Reference in New Issue
Block a user