MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / addNode

Method addNode

src/gridstack-engine.ts:756–777  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 7

compactMethod · 0.95
willItFitMethod · 0.95
columnChangedMethod · 0.95
_prepareElementMethod · 0.80
onEndMovingMethod · 0.80
_onStartMovingMethod · 0.80

Calls 7

nodeBoundFixMethod · 0.95
prepareNodeMethod · 0.95
findEmptyPositionMethod · 0.95
_fixCollisionsMethod · 0.95
_packNodesMethod · 0.95
findMethod · 0.80
_notifyMethod · 0.80

Tested by

no test coverage detected