* Part 2 of preparing a node to fit inside the grid - validates and fixes coordinates and dimensions. * This ensures the node fits within grid boundaries and respects min/max constraints. * * @param node the node to validate and fix * @param resizing if true, resize the node to fit; if f
(node: GridStackNode, resizing?: boolean)
| 558 | * engine.nodeBoundFix(node, false); // Move to fit |
| 559 | */ |
| 560 | public nodeBoundFix(node: GridStackNode, resizing?: boolean): GridStackEngine { |
| 561 | |
| 562 | const before = node._orig || Utils.copyPos({}, node); |
| 563 | |
| 564 | if (node.maxW) { node.w = Math.min(node.w || 1, node.maxW); } |
| 565 | if (node.maxH) { node.h = Math.min(node.h || 1, node.maxH); } |
| 566 | if (node.minW) { node.w = Math.max(node.w || 1, node.minW); } |
| 567 | if (node.minH) { node.h = Math.max(node.h || 1, node.minH); } |
| 568 | |
| 569 | // if user loaded a larger than allowed widget for current # of columns, |
| 570 | // remember it's position & width so we can restore back (1 -> 12 column) #1655 #1985 |
| 571 | // IFF we're not in the middle of column resizing! |
| 572 | const saveOrig = (node.x || 0) + (node.w || 1) > this.column; |
| 573 | if (saveOrig && this.column < this.defaultColumn && !this._inColumnResize && !this.skipCacheUpdate && node._id != null && this.findCacheLayout(node, this.defaultColumn) === -1) { |
| 574 | const copy = {...node}; // need _id + positions |
| 575 | if (copy.autoPosition || copy.x === undefined) { delete copy.x; delete copy.y; } |
| 576 | else copy.x = Math.min(this.defaultColumn - 1, copy.x); |
| 577 | copy.w = Math.min(this.defaultColumn, copy.w || 1); |
| 578 | this.cacheOneLayout(copy, this.defaultColumn); |
| 579 | } |
| 580 | |
| 581 | if (node.w > this.column) { |
| 582 | node.w = this.column; |
| 583 | } else if (node.w < 1) { |
| 584 | node.w = 1; |
| 585 | } |
| 586 | |
| 587 | if (this.maxRow && node.h > this.maxRow) { |
| 588 | node.h = this.maxRow; |
| 589 | } else if (node.h < 1) { |
| 590 | node.h = 1; |
| 591 | } |
| 592 | |
| 593 | if (node.x < 0) { |
| 594 | node.x = 0; |
| 595 | } |
| 596 | if (node.y < 0) { |
| 597 | node.y = 0; |
| 598 | } |
| 599 | |
| 600 | if (node.x + node.w > this.column) { |
| 601 | if (resizing) { |
| 602 | node.w = this.column - node.x; |
| 603 | } else { |
| 604 | node.x = this.column - node.w; |
| 605 | } |
| 606 | } |
| 607 | if (this.maxRow && node.y + node.h > this.maxRow) { |
| 608 | if (resizing) { |
| 609 | node.h = this.maxRow - node.y; |
| 610 | } else { |
| 611 | node.y = this.maxRow - node.h; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | if (!Utils.samePos(node, before)) { |
| 616 | node._dirty = true; |
| 617 | } |
no test coverage detected