This commit is contained in:
barsdeveloper
2022-04-02 11:13:34 +02:00
parent 9ab8801eee
commit e901932953
26 changed files with 392 additions and 279 deletions

View File

@@ -14,38 +14,33 @@ export default class IContext {
/** @type {Object} */
options
#hasFocus = false
get hasFocus() {
return this.#hasFocus
}
set hasFocus(_) {
}
constructor(target, blueprint, options) {
this.target = target
this.blueprint = blueprint
this.options = options
let self = this
this.blueprintFocusHandler = _ => {
this.#hasFocus = true
this.listenHandler = _ => {
self.listenEvents()
}
this.blueprintUnfocusHandler = _ => {
this.unlistenHandler = _ => {
self.unlistenEvents()
this.#hasFocus = false
}
if (options?.wantsFocusCallback ?? false) {
this.blueprint.addEventListener("blueprint-focus", this.blueprintFocusHandler)
this.blueprint.addEventListener("blueprint-unfocus", this.blueprintUnfocusHandler)
if (options?.listenOnFocus ?? false) {
this.blueprint.addEventListener("blueprint-focus", this.listenHandler)
this.blueprint.addEventListener("blueprint-unfocus", this.unlistenHandler)
}
if (options?.unlistenOnEditText ?? false) {
this.blueprint.addEventListener(this.blueprint.settings.editTextEventName.begin, this.unlistenHandler)
this.blueprint.addEventListener(this.blueprint.settings.editTextEventName.end, this.listenHandler)
}
}
unlistenDOMElement() {
this.unlistenEvents()
this.blueprint.removeEventListener("blueprint-focus", this.blueprintFocusHandler)
this.blueprint.removeEventListener("blueprint-unfocus", this.blueprintUnfocusHandler)
this.blueprint.removeEventListener("blueprint-focus", this.listenHandler)
this.blueprint.removeEventListener("blueprint-unfocus", this.unlistenHandler)
this.blueprint.removeEventListener(this.blueprint.settings.editTextEventName.begin, this.unlistenHandler)
this.blueprint.removeEventListener(this.blueprint.settings.editTextEventName.end, this.listenHandler)
}
/* Subclasses will probabily override the following methods */

View File

@@ -8,7 +8,7 @@ export default class Copy extends IContext {
#copyHandler
constructor(target, blueprint, options = {}) {
options.wantsFocusCallback = true
options.listenOnFocus = true
super(target, blueprint, options)
this.serializer = new ObjectSerializer()
let self = this

View File

@@ -9,7 +9,7 @@ export default class Paste extends IContext {
#pasteHandle
constructor(target, blueprint, options = {}) {
options.wantsFocusCallback = true
options.listenOnFocus = true
super(target, blueprint, options)
this.serializer = new ObjectSerializer()
let self = this

View File

@@ -10,7 +10,7 @@ export default class IKeyboardShortcut extends IContext {
#activationKeys
constructor(target, blueprint, options = {}) {
options.wantsFocusCallback = true
options.listenOnFocus = true
options.activationKeys ??= []
if (!(options.activationKeys instanceof Array)) {
options.activationKeys = [options.activationKeys]
@@ -47,6 +47,9 @@ export default class IKeyboardShortcut extends IContext {
&& wantsAlt(keyEntry) == e.altKey
&& this.blueprint.settings.Keys[keyEntry.Key] == e.code
)) {
if (options.consumeEvent) {
e.stopImmediatePropagation()
}
self.fire()
document.removeEventListener("keydown", self.keyDownHandler)
document.addEventListener("keyup", self.keyUpHandler)
@@ -60,9 +63,12 @@ export default class IKeyboardShortcut extends IContext {
keyEntry.bShift && e.key == "Shift"
|| keyEntry.bCtrl && e.key == "Control"
|| keyEntry.bAlt && e.key == "Alt"
|| keyEntry.bCmd && e.key == "Meta" // Unsure about this, what key is that?
|| keyEntry.bCmd && e.key == "Meta"
|| this.blueprint.settings.Keys[keyEntry.Key] == e.code
)) {
if (options.consumeEvent) {
e.stopImmediatePropagation()
}
self.unfire()
document.removeEventListener("keyup", this.keyUpHandler)
document.addEventListener("keydown", this.keyDownHandler)

View File

@@ -5,7 +5,7 @@ import Zoom from "../mouse/Zoom"
export default class KeyboardEnableZoom extends IKeyboardShortcut {
/** @type {} */
/** @type {Zoom} */
#zoomInputObject
/**

View File

@@ -0,0 +1,26 @@
// @ts-check
import KeyboardSelectAll from "./KeyboardSelectAll"
export default class KeyboardIgnoreSelectAll extends KeyboardSelectAll {
/**
* @param {HTMLElement} target
* @param {any} blueprint
* @param {Object} options
*/
constructor(target, blueprint, options = {}) {
options = {
...options,
activationKeys: blueprint.settings.selectAllKeyboardKey
}
super(target, blueprint, options)
}
fire() {
}
unfire() {
}
}

View File

@@ -2,11 +2,14 @@
import IKeyboardShortcut from "./IKeyboardShortcut"
/**
* @typedef {import("../../Blueprint").default} Blueprint
*/
export default class KeyboardSelectAll extends IKeyboardShortcut {
/**
* @param {HTMLElement} target
* @param {import("../../Blueprint").default} blueprint
* @param {Blueprint} blueprint
* @param {Object} options
*/
constructor(target, blueprint, options = {}) {

View File

@@ -29,7 +29,7 @@ export default class IMouseClickDrag extends IPointing {
this.exitAnyButton = options?.exitAnyButton ?? true
this.moveEverywhere = options?.moveEverywhere ?? false
this.looseTarget = options?.looseTarget ?? false
this.consumeClickEvent = options?.consumeClickEvent ?? true
this.consumeEvent = options?.consumeEvent ?? true
this.clickedPosition = [0, 0]
const movementListenedElement = this.moveEverywhere ? document.documentElement : this.movementSpace
@@ -41,7 +41,7 @@ export default class IMouseClickDrag extends IPointing {
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) {
if (this.consumeClickEvent) {
if (this.consumeEvent) {
e.stopImmediatePropagation() // Captured, don't call anyone else
}
// Attach the listeners
@@ -60,7 +60,7 @@ export default class IMouseClickDrag extends IPointing {
}
this.#mouseStartedMovingHandler = e => {
if (this.consumeClickEvent) {
if (this.consumeEvent) {
e.stopImmediatePropagation() // Captured, don't call anyone else
}
// Delegate from now on to self.#mouseMoveHandler
@@ -75,7 +75,7 @@ export default class IMouseClickDrag extends IPointing {
}
this.#mouseMoveHandler = e => {
if (this.consumeClickEvent) {
if (this.consumeEvent) {
e.stopImmediatePropagation() // Captured, don't call anyone else
}
const location = self.locationFromEvent(e)
@@ -88,7 +88,7 @@ export default class IMouseClickDrag extends IPointing {
this.#mouseUpHandler = e => {
if (!self.exitAnyButton || e.button == self.clickButton) {
if (this.consumeClickEvent) {
if (this.consumeEvent) {
e.stopImmediatePropagation() // Captured, don't call anyone else
}
// Remove the handlers of "mousemove" and "mouseup"

View File

@@ -16,7 +16,7 @@ export default class IMouseWheel extends IPointing {
* @param {Object} options
*/
constructor(target, blueprint, options) {
options.wantsFocusCallback = true
options.listenOnFocus = true
super(target, blueprint, options)
this.looseTarget = options?.looseTarget ?? true
let self = this

View File

@@ -17,7 +17,7 @@ export default class MouseTracking extends IPointing {
#trackingMouseGaveBackHandler
constructor(target, blueprint, options = {}) {
options.wantsFocusCallback = true
options.listenOnFocus = true
super(target, blueprint, options)
let self = this

View File

@@ -4,22 +4,22 @@ import IContext from "../IContext"
export default class Unfocus extends IContext {
/** @type {(e: WheelEvent) => void} */
/** @type {(e: MouseEvent) => void} */
#clickHandler
constructor(target, blueprint, options = {}) {
options.wantsFocusCallback = true
options.listenOnFocus = true
super(target, blueprint, options)
let self = this
this.#clickHandler = e => self.clickedSomewhere(e.target)
if (this.blueprint.focuse) {
this.#clickHandler = e => self.clickedSomewhere(/** @type {HTMLElement} */(e.target))
if (this.blueprint.focus) {
document.addEventListener("click", this.#clickHandler)
}
}
/**
* @param {HTMLElement} e
* @param {HTMLElement} target
*/
clickedSomewhere(target) {
// If target is outside the blueprint grid