mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-03 23:55:04 +08:00
* WIP * WIP * wip * WIP * Several fixes * Tests wip port to playwright * WIP * Fix more tests * Serialization tests fixed * Several fixes for tests * Input options types * Type adjustments * Fix object reference parser * Tests fixes * More tests fixes
49 lines
1.9 KiB
JavaScript
Executable File
49 lines
1.9 KiB
JavaScript
Executable File
/**
|
|
* @typedef {typeof import("../Blueprint.js").default.nodeBoundariesSupplier} BoundariesFunction
|
|
* @typedef {typeof import("../Blueprint.js").default.nodeSelectToggleFunction} SelectionFunction
|
|
* @typedef {{
|
|
* primaryBoundary: Number,
|
|
* secondaryBoundary: Number,
|
|
* insertionPosition?: Number,
|
|
* rectangle: Number
|
|
* onSecondaryAxis: Boolean
|
|
* }} Metadata
|
|
*/
|
|
|
|
export default class SimpleSelectionModel {
|
|
|
|
/**
|
|
* @param {Coordinates} initialPosition
|
|
* @param {NodeElement[]} rectangles
|
|
* @param {BoundariesFunction} boundariesFunc
|
|
* @param {SelectionFunction} selectToggleFunction
|
|
*/
|
|
constructor(initialPosition, rectangles, boundariesFunc, selectToggleFunction) {
|
|
this.initialPosition = initialPosition
|
|
this.finalPosition = initialPosition
|
|
this.boundariesFunc = boundariesFunc
|
|
this.selectToggleFunction = selectToggleFunction
|
|
this.rectangles = rectangles
|
|
}
|
|
|
|
selectTo(finalPosition) {
|
|
let primaryInf = Math.min(finalPosition[0], this.initialPosition[0])
|
|
let primarySup = Math.max(finalPosition[0], this.initialPosition[0])
|
|
let secondaryInf = Math.min(finalPosition[1], this.initialPosition[1])
|
|
let secondarySup = Math.max(finalPosition[1], this.initialPosition[1])
|
|
this.finalPosition = finalPosition
|
|
this.rectangles.forEach(rect => {
|
|
let boundaries = this.boundariesFunc(rect)
|
|
if (
|
|
Math.max(boundaries.primaryInf, primaryInf) < Math.min(boundaries.primarySup, primarySup)
|
|
&& Math.max(boundaries.secondaryInf, secondaryInf) < Math.min(boundaries.secondarySup, secondarySup)
|
|
) {
|
|
this.selectToggleFunction(rect, true)
|
|
} else {
|
|
|
|
this.selectToggleFunction(rect, false)
|
|
}
|
|
})
|
|
}
|
|
}
|