* Add the given node to the grid, handling collision detection and re-packing. * This is the main method for adding new widgets to the engine. * * @param node the node to add to the grid * @param triggerAddEvent if true, adds node to addedNodes list for event triggering * @param after
(node: GridStackNode, triggerAddEvent = false, after?: GridStackNode)
| 754 | * const added = engine.addNode(node, true); |
| 755 | */ |
| 756 | public addNode(node: GridStackNode, triggerAddEvent = false, after?: GridStackNode): GridStackNode { |
| 757 | const dup = this.nodes.find(n => n._id === node._id); |
| 758 | if (dup) return dup; // prevent inserting twice! return it instead. |
| 759 | |
| 760 | // skip prepareNode if we're in middle of column resize (not new) but do check for bounds! |
| 761 | this._inColumnResize ? this.nodeBoundFix(node) : this.prepareNode(node); |
| 762 | delete node._temporaryRemoved; |
| 763 | delete node._removeDOM; |
| 764 | |
| 765 | let skipCollision: boolean; |
| 766 | if (node.autoPosition && this.findEmptyPosition(node, this.nodes, this.column, after)) { |
| 767 | delete node.autoPosition; // found our slot |
| 768 | skipCollision = true; |
| 769 | } |
| 770 | |
| 771 | this.nodes.push(node); |
| 772 | if (triggerAddEvent) { this.addedNodes.push(node); } |
| 773 | |
| 774 | if (!skipCollision) this._fixCollisions(node); |
| 775 | if (!this.batchMode) { this._packNodes()._notify(); } |
| 776 | return node; |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * Remove the given node from the grid. |
no test coverage detected