Improove naming input options

This commit is contained in:
barsdeveloper
2022-10-14 19:52:00 +02:00
parent da73cf98b5
commit 0b19d89416
17 changed files with 64 additions and 60 deletions

View File

@@ -18,7 +18,7 @@ export default class IMouseClick extends IPointing {
options.clickButton ??= 0
options.consumeEvent ??= true
options.exitAnyButton ??= true
options.looseTarget ??= false
options.strictTarget ??= false
super(target, blueprint, options)
this.clickedPosition = [0, 0]
let self = this
@@ -28,7 +28,7 @@ export default class IMouseClick extends IPointing {
switch (e.button) {
case self.options.clickButton:
// Either doesn't matter or consider the click only when clicking on the target, not descandants
if (self.options.looseTarget || e.target == e.currentTarget) {
if (!self.options.strictTarget || e.target == e.currentTarget) {
if (self.options.consumeEvent) {
e.stopImmediatePropagation() // Captured, don't call anyone else
}

View File

@@ -46,10 +46,10 @@ export default class IMouseClickDrag extends IPointing {
options.consumeEvent ??= true
options.draggableElement ??= target
options.exitAnyButton ??= true
options.looseTarget ??= false
options.moveEverywhere ??= false
options.movementSpace ??= blueprint?.getGridDOMElement()
options.repositionClickOffset ??= false
options.repositionOnClick ??= false
options.strictTarget ??= false
super(target, blueprint, options)
this.stepSize = parseInt(options?.stepSize ?? Configuration.gridSize)
@@ -62,7 +62,7 @@ export default class IMouseClickDrag extends IPointing {
switch (e.button) {
case self.options.clickButton:
// Either doesn't matter or consider the click only when clicking on the parent, not descandants
if (self.options.looseTarget || e.target == e.currentTarget) {
if (!self.options.strictTarget || e.target == e.currentTarget) {
if (self.options.consumeEvent) {
e.stopImmediatePropagation() // Captured, don't call anyone else
}

View File

@@ -14,12 +14,13 @@ export default class IMouseWheel extends IPointing {
* @param {import("../../Blueprint").default} blueprint
* @param {Object} options
*/
constructor(target, blueprint, options) {
constructor(target, blueprint, options = {}) {
options.listenOnFocus = true
options.strictTarget ??= false
super(target, blueprint, options)
this.looseTarget = options?.looseTarget ?? true
let self = this
this.strictTarget = options.strictTarget
const self = this
this.#mouseWheelHandler = e => {
e.preventDefault()
const location = self.locationFromEvent(e)

View File

@@ -1,8 +1,13 @@
import IMouseClickDrag from "./IMouseClickDrag"
/** @typedef {import("../../element/PinElement").default} PinElement */
/**
* @typedef {import("../../element/IDraggableElement").default} IDraggableElement
*/
/** @extends IMouseClickDrag<PinElement> */
/**
* @template {IDraggableElement} T
* @extends {IMouseClickDrag<T>}
*/
export default class MouseIgnore extends IMouseClickDrag {
constructor(target, blueprint, options = {}) {

View File

@@ -13,7 +13,7 @@ import Utility from "../../Utility"
export default class MouseMoveDraggable extends IMouseClickDrag {
clicked(location) {
if (this.options.repositionClickOffset) {
if (this.options.repositionOnClick) {
this.target.setLocation(this.stepSize > 1
? Utility.snapToGrid(location, this.stepSize)
: location

View File

@@ -56,19 +56,15 @@ export default class BlueprintTemplate extends ITemplate {
new Paste(this.element.getGridDOMElement(), this.element),
new KeyboardCanc(this.element.getGridDOMElement(), this.element),
new KeyboardSelectAll(this.element.getGridDOMElement(), this.element),
new Zoom(this.element.getGridDOMElement(), this.element, {
looseTarget: true,
}),
new Zoom(this.element.getGridDOMElement(), this.element),
new Select(this.element.getGridDOMElement(), this.element, {
clickButton: 0,
exitAnyButton: true,
looseTarget: true,
moveEverywhere: true,
}),
new MouseScrollGraph(this.element.getGridDOMElement(), this.element, {
clickButton: 2,
exitAnyButton: false,
looseTarget: true,
moveEverywhere: true,
}),
new Unfocus(this.element.getGridDOMElement(), this.element),

View File

@@ -1,4 +1,5 @@
import { html, nothing } from "lit"
import MouseIgnore from "../input/mouse/MouseIgnore"
import PinTemplate from "./PinTemplate"
/**
@@ -23,6 +24,13 @@ export default class BoolPinTemplate extends PinTemplate {
this.#input.removeEventListener("change", this.onChangeHandler)
}
createInputObjects() {
return [
...super.createInputObjects(),
new MouseIgnore(this.#input, this.element.blueprint),
]
}
getInputs() {
return [this.#input.checked ? "true" : "false"]
}

View File

@@ -21,10 +21,9 @@ export default class ColorHandlerTemplate extends IDraggableTemplate {
return new MouseMoveDraggable(this.element, this.element.blueprint, {
draggableElement: this.element.parentElement,
ignoreTranslateCompensate: true,
looseTarget: true,
moveEverywhere: true,
movementSpace: this.element.parentElement,
repositionClickOffset: true,
repositionOnClick: true,
stepSize: 1,
})
}

View File

@@ -19,7 +19,6 @@ export default class IDraggableTemplate extends ITemplate {
createDraggableObject() {
return new MouseMoveDraggable(this.element, this.element.blueprint, {
draggableElement: this.getDraggableElement(),
looseTarget: true,
})
}

View File

@@ -65,7 +65,7 @@ export default class IInputPinTemplate extends PinTemplate {
createInputObjects() {
return [
...super.createInputObjects(),
...this.#inputContentElements.map(elem => new MouseIgnore(elem, this.element.blueprint))
...this.#inputContentElements.map(elem => new MouseIgnore(elem, this.element.blueprint)),
]
}

View File

@@ -19,7 +19,6 @@ export default class ISelectableDraggableTemplate extends IDraggableTemplate {
createDraggableObject() {
return /** @type {MouseMoveDraggable} */ (new MouseMoveNodes(this.element, this.element.blueprint, {
draggableElement: this.getDraggableElement(),
looseTarget: true,
}))
}

View File

@@ -24,7 +24,6 @@ export default class LinearColorPinTemplate extends IInputPinTemplate {
...super.createInputObjects(),
new MouseOpenWindow(this.#input, this.element.blueprint, {
moveEverywhere: true,
looseTarget: true,
windowType: ColorPickerWindowTemplate,
windowOptions: {
// The created window will use the following functions to get and set the color

View File

@@ -27,7 +27,6 @@ export default class PinTemplate extends ITemplate {
return [
new MouseCreateLink(this.element.clickableElement, this.element.blueprint, {
moveEverywhere: true,
looseTarget: true,
})
]
}

View File

@@ -4,5 +4,4 @@ import IFromToPositionedTemplate from "./IFromToPositionedTemplate"
/** @extends IFromToPositionedTemplate<SelectorElement> */
export default class SelectorTemplate extends IFromToPositionedTemplate {
}

View File

@@ -19,7 +19,6 @@ export default class WindowTemplate extends IDraggableTemplate {
return new MouseMoveDraggable(this.element, this.element.blueprint, {
draggableElement: this.getDraggableElement(),
ignoreTranslateCompensate: true,
looseTarget: true,
movementSpace: this.element.blueprint,
stepSize: 1,
})