mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
Various improvements
This commit is contained in:
13
js/input/common/FocusTextEdit.js
Normal file
13
js/input/common/FocusTextEdit.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import IFocus from "./IFocus"
|
||||
|
||||
export default class FocusTextEdit extends IFocus {
|
||||
|
||||
focused() {
|
||||
this.blueprint.dispatchEditTextEvent(true)
|
||||
}
|
||||
|
||||
unfocused() {
|
||||
document.getSelection()?.removeAllRanges() // Deselect eventually selected text inside the input
|
||||
this.blueprint.dispatchEditTextEvent(false)
|
||||
}
|
||||
}
|
||||
40
js/input/common/IFocus.js
Normal file
40
js/input/common/IFocus.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import IInput from "../IInput"
|
||||
|
||||
export default class IFocus extends IInput {
|
||||
|
||||
/** @type {(e: FocusEvent) => void} */
|
||||
#focusHandler
|
||||
|
||||
/** @type {(e: FocusEvent) => void} */
|
||||
#focusoutHandler
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.listenOnFocus ??= true
|
||||
super(target, blueprint, options)
|
||||
const self = this
|
||||
this.#focusHandler = e => {
|
||||
e.preventDefault()
|
||||
this.focused()
|
||||
}
|
||||
this.#focusoutHandler = e => {
|
||||
e.preventDefault()
|
||||
this.unfocused()
|
||||
}
|
||||
}
|
||||
|
||||
listenEvents() {
|
||||
this.target.addEventListener("focus", this.#focusHandler)
|
||||
this.target.addEventListener("focusout", this.#focusoutHandler)
|
||||
}
|
||||
|
||||
unlistenEvents() {
|
||||
this.target.removeEventListener("focus", this.#focusHandler)
|
||||
this.target.removeEventListener("focusout", this.#focusoutHandler)
|
||||
}
|
||||
|
||||
focused() {
|
||||
}
|
||||
|
||||
unfocused() {
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,22 @@ import IInput from "../IInput"
|
||||
import ISerializer from "../../serialization/ISerializer"
|
||||
import KeyBindingEntity from "../../entity/KeyBindingEntity"
|
||||
|
||||
/** @typedef {import("../../Blueprint").default} Blueprint */
|
||||
|
||||
/**
|
||||
* @template {HTMLElement} T
|
||||
* @extends IInput<T>
|
||||
*/
|
||||
export default class IKeyboardShortcut extends IInput {
|
||||
|
||||
/** @type {KeyBindingEntity[]} */
|
||||
#activationKeys
|
||||
|
||||
/**
|
||||
* @param {T} target
|
||||
* @param {Blueprint} blueprint
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.activateAnyKey ??= false
|
||||
options.activationKeys ??= []
|
||||
|
||||
41
js/input/keybaord/KeyboardShortcutAction.js
Normal file
41
js/input/keybaord/KeyboardShortcutAction.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import IKeyboardShortcut from "./IKeyboardShortcut"
|
||||
|
||||
/** @typedef {import("../../Blueprint").default} Blueprint */
|
||||
|
||||
/**
|
||||
* @template {HTMLElement} T
|
||||
* @extends IKeyboardShortcut<T>
|
||||
*/
|
||||
export default class KeyboardShortcutAction extends IKeyboardShortcut {
|
||||
|
||||
static #ignoreEvent =
|
||||
/** @param {KeyboardShortcutAction} self */
|
||||
self => { }
|
||||
|
||||
/**
|
||||
* @param {T} target
|
||||
* @param {Blueprint} blueprint
|
||||
* @param {Object} options
|
||||
* @param {(self: KeyboardShortcutAction<T>) => void} onKeyDown
|
||||
* @param {(self: KeyboardShortcutAction<T>) => void} onKeyUp
|
||||
*/
|
||||
constructor(
|
||||
target,
|
||||
blueprint,
|
||||
options,
|
||||
onKeyDown = KeyboardShortcutAction.#ignoreEvent,
|
||||
onKeyUp = KeyboardShortcutAction.#ignoreEvent
|
||||
) {
|
||||
super(target, blueprint, options)
|
||||
this.onKeyDown = onKeyDown
|
||||
this.onKeyUp = onKeyUp
|
||||
}
|
||||
|
||||
fire() {
|
||||
this.onKeyDown(this)
|
||||
}
|
||||
|
||||
unfire() {
|
||||
this.onKeyUp(this)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user