@@ -349,6 +349,12 @@ export class GridStackEngine {
349
349
if ( node . minH ) { node . h = Math . max ( node . h , node . minH ) ; }
350
350
351
351
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
+ }
352
358
node . w = this . column ;
353
359
} else if ( node . w < 1 ) {
354
360
node . w = 1 ;
@@ -691,8 +697,9 @@ export class GridStackEngine {
691
697
// we save the original x,y,w (h isn't cached) to see what actually changed to propagate better.
692
698
// Note: we don't need to check against out of bound scaling/moving as that will be done when using those cache values.
693
699
nodes . forEach ( node => {
700
+ if ( ! node . _orig ) return ; // didn't change (newly added ?)
694
701
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.
696
703
let ratio = column / this . column ;
697
704
// Y changed, push down same amount
698
705
// TODO: detect doing item 'swaps' will help instead of move (especially in 1 column mode)
@@ -828,6 +835,21 @@ export class GridStackEngine {
828
835
return this ;
829
836
}
830
837
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
+
831
853
832
854
/** called to remove all internal values but the _id */
833
855
public cleanupNode ( node : GridStackNode ) : GridStackEngine {
0 commit comments