@@ -657,10 +657,10 @@ export class GridStack {
657
657
* @example
658
658
* see http://gridstackjs.com/demo/serialization.html
659
659
*/
660
- public load ( layout : GridStackWidget [ ] , addRemove : boolean | AddRemoveFcn = GridStack . addRemoveCB || true ) : GridStack {
660
+ public load ( items : GridStackWidget [ ] , addRemove : boolean | AddRemoveFcn = GridStack . addRemoveCB || true ) : GridStack {
661
661
// if passed list has coordinates, use them (insert from end to beginning for conflict resolution) else force widget same order
662
- const haveCoord = layout . some ( w => w . x !== undefined || w . y !== undefined ) ;
663
- let items = haveCoord ? Utils . sort ( layout , - 1 , this . _prevColumn || this . getColumn ( ) ) : layout ;
662
+ const haveCoord = items . some ( w => w . x !== undefined || w . y !== undefined ) ;
663
+ if ( haveCoord ) items = Utils . sort ( items , - 1 , this . _prevColumn || this . getColumn ( ) ) ;
664
664
this . _insertNotAppend = haveCoord ; // if we create in reverse order...
665
665
666
666
// if we're loading a layout into for example 1 column (_prevColumn is set only when going to 1) and items don't fit, make sure to save
@@ -681,7 +681,8 @@ export class GridStack {
681
681
if ( addRemove ) {
682
682
let copyNodes = [ ...this . engine . nodes ] ; // don't loop through array you modify
683
683
copyNodes . forEach ( n => {
684
- let item = items . find ( w => n . id === w . id ) ;
684
+ if ( ! n . id ) return ;
685
+ let item = Utils . find ( items , n . id ) ;
685
686
if ( ! item ) {
686
687
if ( GridStack . addRemoveCB )
687
688
GridStack . addRemoveCB ( this . el , n , false , false ) ;
@@ -691,19 +692,16 @@ export class GridStack {
691
692
} ) ;
692
693
}
693
694
694
- // now add/update the widgets - starting with an empty list to reduce collision and add no-coord ones at next available spot
695
- let copyNodes = this . engine . nodes ;
696
- this . engine . nodes = [ ] ;
695
+ // now add/update the widgets
697
696
items . forEach ( w => {
698
- let item = ( w . id !== undefined ) ? copyNodes . find ( n => n . id === w . id ) : undefined ;
697
+ let item = Utils . find ( this . engine . nodes , w . id ) ;
699
698
if ( item ) {
700
699
// check if missing coord, in which case find next empty slot with new (or old if missing) sizes
701
700
if ( w . autoPosition || w . x === undefined || w . y === undefined ) {
702
701
w . w = w . w || item . w ;
703
702
w . h = w . h || item . h ;
704
703
this . engine . findEmptyPosition ( w ) ;
705
704
}
706
- this . engine . nodes . push ( item ) ; // now back to current list...
707
705
this . update ( item . el , w ) ;
708
706
if ( w . subGridOpts ?. children ) { // update any sub grid as well
709
707
let sub = item . el . querySelector ( '.grid-stack' ) as GridHTMLElement ;
@@ -1202,6 +1200,7 @@ export class GridStack {
1202
1200
if ( ! n ) return ;
1203
1201
let w = Utils . cloneDeep ( opt ) ; // make a copy we can modify in case they re-use it or multiple items
1204
1202
delete w . autoPosition ;
1203
+ delete w . id ;
1205
1204
1206
1205
// move/resize widget if anything changed
1207
1206
let keys = [ 'x' , 'y' , 'w' , 'h' ] ;
@@ -1244,7 +1243,7 @@ export class GridStack {
1244
1243
Utils . sanitizeMinMax ( n ) ;
1245
1244
1246
1245
// finally move the widget
1247
- if ( m ) this . moveNode ( n , m ) ;
1246
+ if ( m !== undefined ) this . moveNode ( n , m ) ;
1248
1247
if ( changed ) { // move will only update x,y,w,h so update the rest too
1249
1248
this . _writeAttr ( el , n ) ;
1250
1249
}
0 commit comments