Skip to content

Commit f280a1c

Browse files
committed
prevent double nesting using gesture
* remaining fix for #992 to prevent a nested grid from going inside another until we can do the right thing down the line. Very broken otherwise * also fixed heuristics to work like regular items (ignore enter/leave for sub grid dragging)
1 parent 98836f6 commit f280a1c

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/gridstack-dd.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ GridStack.prototype._setupAcceptWidget = function(this: GridStack): GridStack {
131131
// set accept drop to true on ourself (which we ignore) so we don't get "can't drop" icon in HTML5 mode while moving
132132
if (node?.grid === this) return true;
133133
if (!this.opts.acceptWidgets) return false;
134+
// prevent deeper nesting until rest of 992 can be fixed
135+
if (node?.subGrid) return false;
134136
// check for accept method or class matching
135137
let canAccept = true;
136138
if (typeof this.opts.acceptWidgets === 'function') {

src/gridstack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ export class GridStack {
293293
if (parentGridItemEl && parentGridItemEl.gridstackNode) {
294294
this.opts._isNested = parentGridItemEl.gridstackNode;
295295
this.opts._isNested.subGrid = this;
296+
parentGridItemEl.classList.add('grid-stack-nested');
296297
this.el.classList.add('grid-stack-nested');
297298
}
298299

src/h5/dd-droppable.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DDManager } from './dd-manager';
88
import { DDBaseImplement, HTMLElementExtendOpt } from './dd-base-impl';
99
import { DDUtils } from './dd-utils';
1010
import { GridHTMLElement, GridStack } from '../gridstack';
11+
import { GridItemHTMLElement } from '../types';
1112

1213
export interface DDDroppableOpt {
1314
accept?: string | ((el: HTMLElement) => boolean);
@@ -121,10 +122,12 @@ export class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt
121122
event.stopPropagation();
122123

123124
// ignore leave events on our children (we get them when starting to drag our items)
124-
// but exclude nested grids since we would still be leaving ourself
125+
// but exclude nested grids since we would still be leaving ourself,
126+
// but don't handle leave if we're dragging a nested grid around
125127
if (!forceLeave) {
126128
let onChild = DDUtils.inside(event, this.el);
127-
if (onChild) {
129+
let drag: GridItemHTMLElement = DDManager.dragElement.el;
130+
if (onChild && !drag.gridstackNode?.subGrid) { // dragging a nested grid ?
128131
let nestedEl = (this.el as GridHTMLElement).gridstack.engine.nodes.filter(n => n.subGrid).map(n => (n.subGrid as GridStack).el);
129132
onChild = !nestedEl.some(el => DDUtils.inside(event, el));
130133
}

0 commit comments

Comments
 (0)