Icard/angular-clarity-master(work.../node_modules/angular-gridster2/esm2022/lib/gridsterSwap.service.mjs

87 lines
13 KiB
JavaScript
Raw Permalink Normal View History

2024-07-16 14:55:36 +00:00
export class GridsterSwap {
constructor(gridsterItem) {
this.gridsterItem = gridsterItem;
this.gridster = gridsterItem.gridster;
}
destroy() {
this.gridster = this.gridsterItem = this.swapedItem = null;
}
swapItems() {
if (this.gridster.$options.swap) {
this.checkSwapBack();
this.checkSwap(this.gridsterItem);
}
}
checkSwapBack() {
if (this.swapedItem) {
const x = this.swapedItem.$item.x;
const y = this.swapedItem.$item.y;
this.swapedItem.$item.x = this.swapedItem.item.x || 0;
this.swapedItem.$item.y = this.swapedItem.item.y || 0;
if (this.gridster.checkCollision(this.swapedItem.$item)) {
this.swapedItem.$item.x = x;
this.swapedItem.$item.y = y;
}
else {
this.swapedItem.setSize();
this.gridsterItem.$item.x = this.gridsterItem.item.x || 0;
this.gridsterItem.$item.y = this.gridsterItem.item.y || 0;
this.swapedItem = undefined;
}
}
}
restoreSwapItem() {
if (this.swapedItem) {
this.swapedItem.$item.x = this.swapedItem.item.x || 0;
this.swapedItem.$item.y = this.swapedItem.item.y || 0;
this.swapedItem.setSize();
this.swapedItem = undefined;
}
}
setSwapItem() {
if (this.swapedItem) {
this.swapedItem.checkItemChanges(this.swapedItem.$item, this.swapedItem.item);
this.swapedItem = undefined;
}
}
checkSwap(pushedBy) {
let gridsterItemCollision;
if (this.gridster.$options.swapWhileDragging) {
gridsterItemCollision = this.gridster.checkCollisionForSwaping(pushedBy.$item);
}
else {
gridsterItemCollision = this.gridster.checkCollision(pushedBy.$item);
}
if (gridsterItemCollision &&
gridsterItemCollision !== true &&
gridsterItemCollision.canBeDragged()) {
const gridsterItemCollide = gridsterItemCollision;
const copyCollisionX = gridsterItemCollide.$item.x;
const copyCollisionY = gridsterItemCollide.$item.y;
const copyX = pushedBy.$item.x;
const copyY = pushedBy.$item.y;
const diffX = copyX - copyCollisionX;
const diffY = copyY - copyCollisionY;
gridsterItemCollide.$item.x = pushedBy.item.x - diffX;
gridsterItemCollide.$item.y = pushedBy.item.y - diffY;
pushedBy.$item.x = gridsterItemCollide.item.x + diffX;
pushedBy.$item.y = gridsterItemCollide.item.y + diffY;
if (this.gridster.checkCollision(gridsterItemCollide.$item) ||
this.gridster.checkCollision(pushedBy.$item)) {
pushedBy.$item.x = copyX;
pushedBy.$item.y = copyY;
gridsterItemCollide.$item.x = copyCollisionX;
gridsterItemCollide.$item.y = copyCollisionY;
}
else {
gridsterItemCollide.setSize();
this.swapedItem = gridsterItemCollide;
if (this.gridster.$options.swapWhileDragging) {
this.gridsterItem.checkItemChanges(this.gridsterItem.$item, this.gridsterItem.item);
this.setSwapItem();
}
}
}
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JpZHN0ZXJTd2FwLnNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9hbmd1bGFyLWdyaWRzdGVyMi9zcmMvbGliL2dyaWRzdGVyU3dhcC5zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUdBLE1BQU0sT0FBTyxZQUFZO0lBS3ZCLFlBQVksWUFBNEM7UUFDdEQsSUFBSSxDQUFDLFlBQVksR0FBRyxZQUFZLENBQUM7UUFDakMsSUFBSSxDQUFDLFFBQVEsR0FBRyxZQUFZLENBQUMsUUFBUSxDQUFDO0lBQ3hDLENBQUM7SUFFRCxPQUFPO1FBQ0wsSUFBSSxDQUFDLFFBQVEsR0FBRyxJQUFJLENBQUMsWUFBWSxHQUFHLElBQUksQ0FBQyxVQUFVLEdBQUcsSUFBSyxDQUFDO0lBQzlELENBQUM7SUFFRCxTQUFTO1FBQ1AsSUFBSSxJQUFJLENBQUMsUUFBUSxDQUFDLFFBQVEsQ0FBQyxJQUFJLEVBQUU7WUFDL0IsSUFBSSxDQUFDLGFBQWEs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