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

Method removeAsSubGrid

src/gridstack.ts:599–619  ·  view source on GitHub ↗

* called when an item was converted into a nested grid to accommodate a dragged over item, but then item leaves - return back * to the original grid-item. Also called to remove empty sub-grids when last item is dragged out (since re-creating is simple)

(nodeThatRemoved?: GridStackNode)

Source from the content-addressed store, hash-verified

597 * to the original grid-item. Also called to remove empty sub-grids when last item is dragged out (since re-creating is simple)
598 */
599 public removeAsSubGrid(nodeThatRemoved?: GridStackNode): void {
600 const pGrid = this.parentGridNode?.grid;
601 if (!pGrid) return;
602
603 pGrid.batchUpdate();
604 pGrid.removeWidget(this.parentGridNode.el, true, true);
605 this.engine.nodes.forEach(n => {
606 // migrate any children over and offsetting by our location
607 n.x += this.parentGridNode.x;
608 n.y += this.parentGridNode.y;
609 pGrid.makeWidget(n.el, n);
610 });
611 pGrid.batchUpdate(false);
612 if (this.parentGridNode) delete this.parentGridNode.subGrid;
613 delete this.parentGridNode;
614
615 // create an artificial event for the original grid now that this one is gone (got a leave, but won't get enter)
616 if (nodeThatRemoved) {
617 window.setTimeout(() => Utils.simulateMouseEvent(nodeThatRemoved._event, 'mouseenter', pGrid.el), 0);
618 }
619 }
620
621 /**
622 * saves the current layout returning a list of widgets for serialization which might include any nested grids.

Callers 1

_setupAcceptWidgetMethod · 0.95

Calls 4

removeWidgetMethod · 0.80
makeWidgetMethod · 0.80
simulateMouseEventMethod · 0.80
batchUpdateMethod · 0.45

Tested by

no test coverage detected