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

126 lines
20 KiB
JavaScript
Raw Permalink Normal View History

2024-07-16 14:55:36 +00:00
import { CompactType } from './gridsterConfig.interface';
export class GridsterCompact {
constructor(gridster) {
this.gridster = gridster;
}
destroy() {
this.gridster = null;
}
checkCompact() {
if (this.gridster.$options.compactType !== CompactType.None) {
if (this.gridster.$options.compactType === CompactType.CompactUp) {
this.checkCompactMovement('y', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactLeft) {
this.checkCompactMovement('x', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactUpAndLeft) {
this.checkCompactMovement('y', -1);
this.checkCompactMovement('x', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactLeftAndUp) {
this.checkCompactMovement('x', -1);
this.checkCompactMovement('y', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactRight) {
this.checkCompactMovement('x', 1);
}
else if (this.gridster.$options.compactType === CompactType.CompactUpAndRight) {
this.checkCompactMovement('y', -1);
this.checkCompactMovement('x', 1);
}
else if (this.gridster.$options.compactType === CompactType.CompactRightAndUp) {
this.checkCompactMovement('x', 1);
this.checkCompactMovement('y', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactDown) {
this.checkCompactMovement('y', 1);
}
else if (this.gridster.$options.compactType === CompactType.CompactDownAndLeft) {
this.checkCompactMovement('y', 1);
this.checkCompactMovement('x', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactDownAndRight) {
this.checkCompactMovement('y', 1);
this.checkCompactMovement('x', 1);
}
else if (this.gridster.$options.compactType === CompactType.CompactLeftAndDown) {
this.checkCompactMovement('x', -1);
this.checkCompactMovement('y', 1);
}
else if (this.gridster.$options.compactType === CompactType.CompactRightAndDown) {
this.checkCompactMovement('x', 1);
this.checkCompactMovement('y', 1);
}
}
}
checkCompactItem(item) {
if (this.gridster.$options.compactType !== CompactType.None) {
if (this.gridster.$options.compactType === CompactType.CompactUp) {
this.moveTillCollision(item, 'y', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactLeft) {
this.moveTillCollision(item, 'x', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactUpAndLeft) {
this.moveTillCollision(item, 'y', -1);
this.moveTillCollision(item, 'x', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactLeftAndUp) {
this.moveTillCollision(item, 'x', -1);
this.moveTillCollision(item, 'y', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactUpAndRight) {
this.moveTillCollision(item, 'y', -1);
this.moveTillCollision(item, 'x', 1);
}
else if (this.gridster.$options.compactType === CompactType.CompactDown) {
this.moveTillCollision(item, 'y', 1);
}
else if (this.gridster.$options.compactType === CompactType.CompactDownAndLeft) {
this.moveTillCollision(item, 'y', 1);
this.moveTillCollision(item, 'x', -1);
}
else if (this.gridster.$options.compactType === CompactType.CompactLeftAndDown) {
this.moveTillCollision(item, 'x', -1);
this.moveTillCollision(item, 'y', 1);
}
else if (this.gridster.$options.compactType === CompactType.CompactDownAndRight) {
this.moveTillCollision(item, 'y', 1);
this.moveTillCollision(item, 'x', 1);
}
else if (this.gridster.$options.compactType === CompactType.CompactRightAndDown) {
this.moveTillCollision(item, 'x', 1);
this.moveTillCollision(item, 'y', 1);
}
}
}
checkCompactMovement(direction, delta) {
let widgetMoved = false;
this.gridster.grid.forEach((widget) => {
if (widget.$item.compactEnabled !== false) {
const moved = this.moveTillCollision(widget.$item, direction, delta);
if (moved) {
widgetMoved = true;
widget.item[direction] = widget.$item[direction];
widget.itemChanged();
}
}
});
if (widgetMoved) {
this.checkCompact();
}
}
moveTillCollision(item, direction, delta) {
item[direction] += delta;
if (this.gridster.checkCollision(item)) {
item[direction] -= delta;
return false;
}
else {
this.moveTillCollision(item, direction, delta);
return true;
}
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JpZHN0ZXJDb21wYWN0LnNlcnZpY2UuanMiLCJzb3VyY2VSb290Ijoi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