mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-03 23:55:04 +08:00
JSDoc complete type check
This commit is contained in:
@@ -21,6 +21,7 @@ export default class IKeyboardShortcut extends IInput {
|
||||
return v
|
||||
}
|
||||
if (v.constructor === String) {
|
||||
// @ts-expect-error
|
||||
const parsed = ISerializer.grammar.KeyBinding.parse(v)
|
||||
if (parsed.status) {
|
||||
return parsed.value
|
||||
|
||||
@@ -31,13 +31,21 @@ export default class IMouseClickDrag extends IPointing {
|
||||
clickedPosition = [0, 0]
|
||||
mouseLocation = [0, 0]
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {T} target
|
||||
* @param {Blueprint} blueprint
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.clickButton ??= 0
|
||||
options.consumeEvent ??= true
|
||||
options.exitAnyButton ??= true
|
||||
options.draggableElement ??= target
|
||||
options.exitAnyButton ??= true
|
||||
options.looseTarget ??= false
|
||||
options.moveEverywhere ??= false
|
||||
options.movementSpace ??= blueprint?.getGridDOMElement()
|
||||
options.repositionClickOffset ??= false
|
||||
super(target, blueprint, options)
|
||||
this.stepSize = parseInt(options?.stepSize ?? Configuration.gridSize)
|
||||
|
||||
@@ -151,7 +159,7 @@ export default class IMouseClickDrag extends IPointing {
|
||||
startDrag(location) {
|
||||
}
|
||||
|
||||
dragTo(location, movement) {
|
||||
dragTo(location, offset) {
|
||||
}
|
||||
|
||||
endDrag() {
|
||||
|
||||
@@ -10,6 +10,7 @@ import Utility from "../../Utility"
|
||||
export default class IPointing extends IInput {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
options.ignoreTranslateCompensate ??= false
|
||||
options.movementSpace ??= blueprint?.getGridDOMElement() ?? document.documentElement
|
||||
super(target, blueprint, options)
|
||||
this.movementSpace = options.movementSpace
|
||||
@@ -21,6 +22,8 @@ export default class IPointing extends IInput {
|
||||
[mouseEvent.clientX, mouseEvent.clientY],
|
||||
this.movementSpace
|
||||
)
|
||||
return this.blueprint.compensateTranslation(location)
|
||||
return this.options.ignoreTranslateCompensate
|
||||
? location
|
||||
: this.blueprint.compensateTranslation(location)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,29 +3,45 @@ import Utility from "../../Utility"
|
||||
|
||||
/**
|
||||
* @typedef {import("../../Blueprint").default} Blueprint
|
||||
* @typedef {import("../../element/ISelectableDraggableElement").default} ISelectableDraggableElement
|
||||
* @typedef {import("../../element/IDraggableElement").default} IDraggableElement
|
||||
*/
|
||||
|
||||
/** @extends {IMouseClickDrag<ISelectableDraggableElement>} */
|
||||
/**
|
||||
* @template {IDraggableElement} T
|
||||
* @extends {IMouseClickDrag<T>}
|
||||
*/
|
||||
export default class MouseMoveDraggable extends IMouseClickDrag {
|
||||
|
||||
dragTo(location, movement) {
|
||||
const initialTargetLocation = [this.target.locationX, this.target.locationY]
|
||||
const [mouseLocation, targetLocation] = this.stepSize > 1
|
||||
? [Utility.snapToGrid(location, this.stepSize), Utility.snapToGrid(initialTargetLocation, this.stepSize)]
|
||||
: [location, initialTargetLocation]
|
||||
const d = [
|
||||
mouseLocation[0] - this.mouseLocation[0],
|
||||
mouseLocation[1] - this.mouseLocation[1]
|
||||
clicked(location) {
|
||||
if (this.options.repositionClickOffset) {
|
||||
this.target.setLocation(this.stepSize > 1
|
||||
? Utility.snapToGrid(location, this.stepSize)
|
||||
: location
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
dragTo(location, offset) {
|
||||
const targetLocation = [this.target.locationX, this.target.locationY]
|
||||
const [adjustedLocation, adjustedTargetLocation] = this.stepSize > 1
|
||||
? [Utility.snapToGrid(location, this.stepSize), Utility.snapToGrid(targetLocation, this.stepSize)]
|
||||
: [location, targetLocation]
|
||||
offset = [
|
||||
adjustedLocation[0] - this.mouseLocation[0],
|
||||
adjustedLocation[1] - this.mouseLocation[1]
|
||||
]
|
||||
if (d[0] == 0 && d[1] == 0) {
|
||||
if (offset[0] == 0 && offset[1] == 0) {
|
||||
return
|
||||
}
|
||||
// Make sure it snaps on the grid
|
||||
d[0] += targetLocation[0] - this.target.locationX
|
||||
d[1] += targetLocation[1] - this.target.locationY
|
||||
this.target.addLocation(d)
|
||||
offset[0] += adjustedTargetLocation[0] - this.target.locationX
|
||||
offset[1] += adjustedTargetLocation[1] - this.target.locationY
|
||||
this.dragAction(adjustedLocation, offset)
|
||||
// Reassign the position of mouse
|
||||
this.mouseLocation = mouseLocation
|
||||
this.mouseLocation = adjustedLocation
|
||||
}
|
||||
|
||||
dragAction(location, offset) {
|
||||
this.target.addLocation(offset)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import IMouseClickDrag from "./IMouseClickDrag"
|
||||
import MouseMoveDraggable from "./MouseMoveDraggable"
|
||||
import Utility from "../../Utility"
|
||||
|
||||
/**
|
||||
* @typedef {import("../../Blueprint").default} Blueprint
|
||||
* @typedef {import("../../element/ISelectableDraggableElement").default} ISelectableDraggableElement
|
||||
*/
|
||||
|
||||
/** @extends {IMouseClickDrag<ISelectableDraggableElement>} */
|
||||
/** @extends {MouseMoveDraggable<ISelectableDraggableElement>} */
|
||||
export default class MouseMoveNodes extends MouseMoveDraggable {
|
||||
|
||||
startDrag() {
|
||||
@@ -17,24 +15,8 @@ export default class MouseMoveNodes extends MouseMoveDraggable {
|
||||
}
|
||||
}
|
||||
|
||||
dragTo(location, movement) {
|
||||
const initialTargetLocation = [this.target.locationX, this.target.locationY]
|
||||
const [mouseLocation, targetLocation] = this.stepSize > 1
|
||||
? [Utility.snapToGrid(location, this.stepSize), Utility.snapToGrid(initialTargetLocation, this.stepSize)]
|
||||
: [location, initialTargetLocation]
|
||||
const d = [
|
||||
mouseLocation[0] - this.mouseLocation[0],
|
||||
mouseLocation[1] - this.mouseLocation[1]
|
||||
]
|
||||
if (d[0] == 0 && d[1] == 0) {
|
||||
return
|
||||
}
|
||||
// Make sure it snaps on the grid
|
||||
d[0] += targetLocation[0] - this.target.locationX
|
||||
d[1] += targetLocation[1] - this.target.locationY
|
||||
this.target.dispatchDragEvent(d)
|
||||
// Reassign the position of mouse
|
||||
this.mouseLocation = mouseLocation
|
||||
dragAction(location, offset) {
|
||||
this.target.dispatchDragEvent(offset)
|
||||
}
|
||||
|
||||
unclicked() {
|
||||
|
||||
@@ -9,17 +9,13 @@ export default class MouseOpenWindow extends IMouseClick {
|
||||
|
||||
#window
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.windowType ??= "window"
|
||||
super(target, blueprint, options)
|
||||
}
|
||||
|
||||
clicked(location) {
|
||||
}
|
||||
|
||||
unclicked(location) {
|
||||
this.#window = new WindowElement({
|
||||
type: this.options.windowType
|
||||
type: this.options.windowType,
|
||||
windowOptions: this.options.windowOptions,
|
||||
})
|
||||
this.blueprint.append(this.#window)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user