Allow unlisten events in case of text edit

This commit is contained in:
barsdeveloper
2022-04-02 13:47:16 +02:00
parent e901932953
commit 6ffdcbccab
11 changed files with 1380 additions and 1403 deletions

View File

@@ -4,10 +4,14 @@ export default class Configuration {
deleteNodesKeyboardKey = "Delete"
editTextEventName = {
begin: "ueb-edit-text-begin",
end: "ueb-edit-text-end"
end: "ueb-edit-text-end",
}
enableZoomIn = ["LeftControl", "RightControl"] // Button to enable more than 0 (1:1) zoom
expandGridSize = 400
focusEventName = {
begin: "blueprint-focus",
end: "blueprint-unfocus",
}
fontSize = "12px"
gridAxisLineColor = "black"
gridExpandThreshold = 0.25 // remaining size factor threshold to cause an expansion event
@@ -39,13 +43,13 @@ export default class Configuration {
selectAllKeyboardKey = "(bCtrl=True,Key=A)"
trackingMouseEventName = {
begin: "ueb-tracking-mouse-begin",
end: "ueb-tracking-mouse-end"
end: "ueb-tracking-mouse-end",
}
ModifierKeys = [
"Ctrl",
"Shift",
"Alt",
"Meta"
"Meta",
]
Keys = {
/* UE name: JS name */

View File

@@ -5,7 +5,6 @@ import MouseCreateLink from "../input/mouse/MouseCreateLink"
import PinTemplate from "../template/PinTemplate"
import ExecPinTemplate from "../template/ExecPinTemplate"
import StringPinTemplate from "../template/StringPinTemplate"
import KeyboardIgnoreSelectAll from "../input/keybaord/KeyboardIgnoreSelectAll"
/**
* @typedef {import("../entity/GuidEntity").default} GuidEntity
@@ -53,9 +52,6 @@ export default class PinElement extends IElement {
new MouseCreateLink(this.clickableElement, this.blueprint, {
moveEverywhere: true,
looseTarget: true
}),
new KeyboardIgnoreSelectAll(this, this.blueprint, {
consumeEvent: true
})
]
}

View File

@@ -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)
}

View File

@@ -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

View File

@@ -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

View File

@@ -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() {
}
}

View File

@@ -20,8 +20,8 @@ export default class StringPinTemplate extends PinTemplate {
return html`
<span class="ueb-pin-input">
<span class="ueb-pin-input-content" role="textbox" contenteditable="true"
onfocus="_ => this.closest('ueb-blueprint').editText = true"
onfocusout="_ => this.closest('ueb-blueprint').editText = false"
onfocus="this.closest('ueb-blueprint')?.dispatchEditTextEvent(true)"
onfocusout="this.closest('ueb-blueprint')?.dispatchEditTextEvent(false)"
></span>
</span>
`