@@ -349,6 +349,12 @@ export class GridStackEngine {
349349 if ( node . minH ) { node . h = Math . max ( node . h , node . minH ) ; }
350350
351351 if ( node . w > this . column ) {
352+ // if user loaded a larger than allowed widget for current # of columns,
353+ // remember it's full width so we can restore back (1 -> 12 column) #1655
354+ if ( this . column < 12 ) {
355+ node . w = Math . min ( 12 , node . w ) ;
356+ this . cacheOneLayout ( node , 12 ) ;
357+ }
352358 node . w = this . column ;
353359 } else if ( node . w < 1 ) {
354360 node . w = 1 ;
@@ -484,7 +490,7 @@ export class GridStackEngine {
484490 // don't use 'faster' .splice(findIndex(),1) in case node isn't in our list, or in multiple times.
485491 this . nodes = this . nodes . filter ( n => n !== node ) ;
486492 return this . _packNodes ( )
487- . _notify ( node , removeDOM ) ;
493+ . _notify ( node ) ;
488494 }
489495
490496 public removeAll ( removeDOM = true ) : GridStackEngine {
@@ -493,7 +499,7 @@ export class GridStackEngine {
493499 removeDOM && this . nodes . forEach ( n => n . _removeDOM = true ) ; // let CB remove actual HTML (used to set _id to null, but then we loose layout info)
494500 this . removedNodes = this . nodes ;
495501 this . nodes = [ ] ;
496- return this . _notify ( this . removedNodes , removeDOM ) ;
502+ return this . _notify ( this . removedNodes ) ;
497503 }
498504
499505 /** checks if item can be moved (layout constrain) vs moveNode(), returning true if was able to move.
@@ -691,8 +697,9 @@ export class GridStackEngine {
691697 // we save the original x,y,w (h isn't cached) to see what actually changed to propagate better.
692698 // Note: we don't need to check against out of bound scaling/moving as that will be done when using those cache values.
693699 nodes . forEach ( node => {
700+ if ( ! node . _orig ) return ; // didn't change (newly added ?)
694701 let n = layout . find ( l => l . _id === node . _id ) ;
695- if ( ! n ) return this ; // no cache for new nodes. Will use those values.
702+ if ( ! n ) return ; // no cache for new nodes. Will use those values.
696703 let ratio = column / this . column ;
697704 // Y changed, push down same amount
698705 // TODO: detect doing item 'swaps' will help instead of move (especially in 1 column mode)
@@ -828,6 +835,21 @@ export class GridStackEngine {
828835 return this ;
829836 }
830837
838+ /**
839+ * call to cache the given node layout internally to the given location so we can restore back when column changes size
840+ * @param node single node to cache
841+ * @param column corresponding column index to save it under
842+ */
843+ public cacheOneLayout ( n : GridStackNode , column : number ) : GridStackEngine {
844+ n . _id = n . _id || GridStackEngine . _idSeq ++ ;
845+ let layout : Layout = { x : n . x , y : n . y , w : n . w , _id : n . _id }
846+ this . _layouts = this . _layouts || [ ] ;
847+ this . _layouts [ column ] = this . _layouts [ column ] || [ ] ;
848+ let index = this . _layouts [ column ] . findIndex ( l => l . _id === n . _id ) ;
849+ index === - 1 ? this . _layouts [ column ] . push ( layout ) : this . _layouts [ column ] [ index ] = layout ;
850+ return this ;
851+ }
852+
831853
832854 /** called to remove all internal values but the _id */
833855 public cleanupNode ( node : GridStackNode ) : GridStackEngine {
0 commit comments