mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:28:17 +08:00
Allow unlisten events in case of text edit
This commit is contained in:
@@ -6,30 +6,39 @@
|
||||
export default class IContext {
|
||||
|
||||
/** @type {HTMLElement} */
|
||||
target
|
||||
#target
|
||||
get target() {
|
||||
return this.#target
|
||||
}
|
||||
|
||||
/** @type {Blueprint} */
|
||||
blueprint
|
||||
#blueprint
|
||||
get blueprint() {
|
||||
return this.#blueprint
|
||||
}
|
||||
|
||||
/** @type {Object} */
|
||||
options
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} target
|
||||
* @param {Blueprint} blueprint
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options) {
|
||||
this.target = target
|
||||
this.blueprint = blueprint
|
||||
this.#target = target
|
||||
this.#blueprint = blueprint
|
||||
this.options = options
|
||||
this.options.listenOnFocus = this.options?.listenOnFocus ?? false
|
||||
this.options.unlistenOnTextEdit = this.options?.unlistenOnTextEdit ?? false
|
||||
let self = this
|
||||
this.listenHandler = _ => {
|
||||
self.listenEvents()
|
||||
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.unlistenHandler = _ => {
|
||||
self.unlistenEvents()
|
||||
}
|
||||
if (options?.listenOnFocus ?? false) {
|
||||
this.blueprint.addEventListener("blueprint-focus", this.listenHandler)
|
||||
this.blueprint.addEventListener("blueprint-unfocus", this.unlistenHandler)
|
||||
}
|
||||
if (options?.unlistenOnEditText ?? false) {
|
||||
if (options?.unlistenOnTextEdit ?? false) {
|
||||
this.blueprint.addEventListener(this.blueprint.settings.editTextEventName.begin, this.unlistenHandler)
|
||||
this.blueprint.addEventListener(this.blueprint.settings.editTextEventName.end, this.listenHandler)
|
||||
}
|
||||
@@ -37,8 +46,8 @@ export default class IContext {
|
||||
|
||||
unlistenDOMElement() {
|
||||
this.unlistenEvents()
|
||||
this.blueprint.removeEventListener("blueprint-focus", this.listenHandler)
|
||||
this.blueprint.removeEventListener("blueprint-unfocus", this.unlistenHandler)
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ import ObjectSerializer from "../../serialization/ObjectSerializer"
|
||||
|
||||
export default class Copy extends IContext {
|
||||
|
||||
/** @type {(e: ClipboardEvent) => void} */
|
||||
#copyHandler
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.listenOnFocus = true
|
||||
options.unlistenOnTextEdit = true
|
||||
super(target, blueprint, options)
|
||||
this.serializer = new ObjectSerializer()
|
||||
let self = this
|
||||
|
||||
@@ -6,10 +6,12 @@ import ObjectSerializer from "../../serialization/ObjectSerializer"
|
||||
|
||||
export default class Paste extends IContext {
|
||||
|
||||
/** @type {(e: ClipboardEvent) => void} */
|
||||
#pasteHandle
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.listenOnFocus = true
|
||||
options.unlistenOnTextEdit = true
|
||||
super(target, blueprint, options)
|
||||
this.serializer = new ObjectSerializer()
|
||||
let self = this
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
// @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() {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user