@internal called to top gravity pack the items back OR revert back to original Y positions when floating
()
| 455 | |
| 456 | /** @internal called to top gravity pack the items back OR revert back to original Y positions when floating */ |
| 457 | protected _packNodes(): GridStackEngine { |
| 458 | if (this.batchMode) { return this; } |
| 459 | this.sortNodes(); // first to last |
| 460 | |
| 461 | if (this.float) { |
| 462 | // restore original Y pos |
| 463 | this.nodes.forEach(n => { |
| 464 | if (n._updating || n._orig === undefined || n.y === n._orig.y) return; |
| 465 | let newY = n.y; |
| 466 | while (newY > n._orig.y) { |
| 467 | --newY; |
| 468 | const collide = this.collide(n, {x: n.x, y: newY, w: n.w, h: n.h}); |
| 469 | if (!collide) { |
| 470 | n._dirty = true; |
| 471 | n.y = newY; |
| 472 | } |
| 473 | } |
| 474 | }); |
| 475 | } else { |
| 476 | // top gravity pack |
| 477 | this.nodes.forEach((n, i) => { |
| 478 | if (n.locked) return; |
| 479 | while (n.y > 0) { |
| 480 | const newY = i === 0 ? 0 : n.y - 1; |
| 481 | const canBeMoved = i === 0 || !this.collide(n, {x: n.x, y: newY, w: n.w, h: n.h}); |
| 482 | if (!canBeMoved) break; |
| 483 | // Note: must be dirty (from last position) for GridStack::OnChange CB to update positions |
| 484 | // and move items back. The user 'change' CB should detect changes from the original |
| 485 | // starting position instead. |
| 486 | n._dirty = (n.y !== newY); |
| 487 | n.y = newY; |
| 488 | } |
| 489 | }); |
| 490 | } |
| 491 | return this; |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Prepare and validate a node's coordinates and values for the current grid. |
no test coverage detected