8000 Merge pull request #2988 from James-Linskell/master · gridstack/gridstack.js@73dd55a · GitHub
[go: up one dir, main page]

Skip to content

Commit 73dd55a

Browse files
authored
Merge pull request #2988 from James-Linskell/master
#2667 Fixed sidebar items not honouring gs-w
2 parents 585f646 + 5cd7f2b commit 73dd55a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/gridstack.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,12 @@ export class GridStack {
22152215
return false; // prevent parent from receiving msg (which may be a grid as well)
22162216
}
22172217

2218+
// If sidebar item, restore the sidebar node size to ensure consistent behavior when dragging between grids
2219+
if (node?._sidebarOrig) {
2220+
node.w = node._sidebarOrig.w;
2221+
node.h = node._sidebarOrig.h;
2222+
}
2223+
22182224
// fix #1578 when dragging fast, we may not get a leave on the previous grid so force one now
22192225
if (node?.grid && node.grid !== this && !node._temporaryRemoved) {
22202226
// console.log('dropover without leave'); // TEST
@@ -2227,7 +2233,7 @@ export class GridStack {
22272233
cellWidth = this.cellWidth();
22282234
cellHeight = this.getCellHeight(true);
22292235

2230-
// sidebar items: load any element attributes if we don't have a node
2236+
// sidebar items: load any element attributes if we don't have a node on first enter from the sidebar
22312237
if (!node) {
22322238
const attr = helper.getAttribute('data-gs-widget') || helper.getAttribute('gridstacknode'); // TBD: temp support for old V11.0.0 attribute
22332239
if (attr) {
@@ -2240,6 +2246,8 @@ export class GridStack {
22402246
helper.removeAttribute('gridstacknode');
22412247
}
22422248
if (!node) node = this._readAttr(helper); // used to pass false for #2354, but now we clone top level node
2249+
// On first grid enter from sidebar, set the initial sidebar item size properties for the node
2250+
node._sidebarOrig = { w: node.w, h: node.h }
22432251
}
22442252
if (!node.grid) { // sidebar item
22452253
if (!node.el) node = {...node}; // clone first time we're coming from sidebar (since 'clone' doesn't copy vars)
@@ -2661,7 +2669,10 @@ export class GridStack {
26612669
this._updateContainerHeight();
26622670

26632671
const target = event.target as GridItemHTMLElement;// @ts-ignore
2664-
this._writePosAttr(target, node);
2672+
// Do not write sidebar item attributes back to the original sidebar el
2673+
if (!node._sidebarOrig) {
2674+
this._writePosAttr(target, node);
2675+
}
26652676
if (this._gsEventHandler[event.type]) {
26662677
this._gsEventHandler[event.type](event, target);
26672678
}
@@ -2687,7 +2698,10 @@ export class GridStack {
26872698

26882699
this.engine.removeNode(node); // remove placeholder as well, otherwise it's a sign node is not in our list, which is a bigger issue
26892700
node.el = node._isExternal && helper ? helper : el; // point back to real item being dragged
2701+
const sidebarOrig = node._sidebarOrig;
26902702
if (node._isExternal) this.engine.cleanupNode(node);
2703+
// Restore sidebar item initial size info to stay consistent when dragging between multiple grids
2704+
node._sidebarOrig = sidebarOrig;
26912705

26922706
if (this.opts.removable === true) { // boolean vs a class string
26932707
// item leaving us and we are supposed to remove on leave (no need to drag onto trash) mark it so

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ export interface GridStackNode extends GridStackWidget {
456456
_temporaryRemoved?: boolean;
457457
/** @internal true if we should remove DOM element on _notify() rather than clearing _id (old way) */
458458
_removeDOM?: boolean;
459+
/** @internal original position/size of item if dragged from sidebar */
460+
_sidebarOrig?: GridStackPosition;
459461
/** @internal had drag&drop been initialized */
460462
_initDD?: boolean;
461463
}

0 commit comments

Comments
 (0)
0