@@ -1152,7 +1152,7 @@ export class GridStack {
1152
1152
// check for css min height
1153
1153
let cssMinHeight = parseInt ( getComputedStyle ( this . el ) [ 'min-height' ] ) ;
1154
1154
if ( cssMinHeight > 0 ) {
1155
- let minRow = Math . round ( cssMinHeight / this . getCellHeight ( ) ) ;
1155
+ let minRow = Math . round ( cssMinHeight / this . getCellHeight ( true ) ) ;
1156
1156
if ( row < minRow ) {
1157
1157
row = minRow ;
1158
1158
}
@@ -1610,24 +1610,22 @@ export class GridStack {
1610
1610
}
1611
1611
} )
1612
1612
. on ( this . el , 'dropover' , ( event , el : GridItemHTMLElement ) => {
1613
- let width , height ;
1614
1613
1615
1614
// see if we already have a node with widget/height and check for attributes
1616
- let node = el . gridstackNode ;
1617
- if ( ! node || ! node . width || ! node . height ) {
1615
+ let node = el . gridstackNode || { } ;
1616
+ if ( ! node . width || ! node . height ) {
1618
1617
let w = parseInt ( el . getAttribute ( 'data-gs-width' ) ) ;
1619
- if ( w > 0 ) { node = node || { } ; node . width = w ; }
1618
+ if ( w > 0 ) { node . width = w ; }
1620
1619
let h = parseInt ( el . getAttribute ( 'data-gs-height' ) ) ;
1621
- if ( h > 0 ) { node = node || { } ; node . height = h ; }
1620
+ if ( h > 0 ) { node . height = h ; }
1622
1621
}
1623
1622
1624
1623
// if not calculate the grid size based on element outer size
1625
- let cellWidth = this . cellWidth ( ) ;
1626
- let cellHeight = this . getCellHeight ( ) ;
1627
- width = node && node . width ? node . width : Math . round ( el . offsetWidth / cellWidth ) || 1 ;
1628
- height = node && node . height ? node . height : Math . round ( el . offsetHeight / cellHeight ) || 1 ;
1624
+ let width = node . width || Math . round ( el . offsetWidth / this . cellWidth ( ) ) || 1 ;
1625
+ let height = node . height || Math . round ( el . offsetHeight / this . getCellHeight ( true ) ) || 1 ;
1629
1626
1630
- let newNode = this . engine . prepareNode ( { width, height, _added : false , _temporary : true } ) ;
1627
+ // copy the node original values (min/max/id/etc...) but override width/height/other flags which are this grid specific
1628
+ let newNode = this . engine . prepareNode ( { ...node , ...{ width, height, _added : false , _temporary : true } } ) ;
1631
1629
newNode . _isOutOfGrid = true ;
1632
1630
el . gridstackNode = newNode ;
1633
1631
el . _gridstackNodeOrig = node ;
@@ -1655,7 +1653,7 @@ export class GridStack {
1655
1653
. on ( this . el , 'drop' , ( event , el : GridItemHTMLElement , helper : GridItemHTMLElement ) => {
1656
1654
this . placeholder . remove ( ) ;
1657
1655
1658
- // notify of removal from prev grid...
1656
+ // notify previous grid of removal
1659
1657
let origNode = el . _gridstackNodeOrig ;
1660
1658
delete el . _gridstackNodeOrig ;
1661
1659
if ( origNode && origNode . grid && origNode . grid !== this ) {
@@ -1666,12 +1664,14 @@ export class GridStack {
1666
1664
oGrid . _triggerRemoveEvent ( ) ;
1667
1665
}
1668
1666
1669
- let node : GridStackNode = el . gridstackNode ; // use existing placeholder node as it's already in our list with drop location
1670
- this . engine . cleanupNode ( node ) ; // remove all internal _xyz values
1667
+ let node = el . gridstackNode ; // use existing placeholder node as it's already in our list with drop location
1668
+ const _id = node . _id ;
1669
+ this . engine . cleanupNode ( node ) ; // removes all internal _xyz values (including the _id so add that back)
1670
+ node . _id = _id ;
1671
1671
node . grid = this ;
1672
1672
this . dd . off ( el , 'drag' ) ;
1673
1673
// if we made a copy ('helper' which is temp) of the original node then insert a copy, else we move the original node (#1102)
1674
- // as the helper will be nuked by default (by jqueryui and here to make it the same)
1674
+ // as the helper will be nuked by jqueryui otherwise
1675
1675
if ( helper !== el ) {
1676
1676
helper . remove ( ) ;
1677
1677
el . gridstackNode = origNode ; // original item (left behind) is re-stored to pre dragging as the node now has drop info
@@ -1699,7 +1699,7 @@ export class GridStack {
1699
1699
}
1700
1700
1701
1701
// wait till we return out of the drag callback to set the new drag&resize handler or they may get messed up
1702
- // IFF we are still there (soe application will use as placeholder and insert their real widget instead)
1702
+ // IFF we are still there (some application will use as placeholder and insert their real widget instead)
1703
1703
window . setTimeout ( ( ) => {
1704
1704
if ( node . el && node . el . parentElement ) this . _prepareDragDropByNode ( node ) ;
1705
1705
} ) ;
0 commit comments