Skip to content

Commit f16260f

Browse files
committed
fix #1890 exception when draggin fast
* also fixed some doc and added test case for another bug
1 parent 2d4d2c8 commit f16260f

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

doc/CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ Change log
6565
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
6666

6767
## 4.3.1-dev TBD
68-
* fix [#1785](https://github.com/gridstack/gridstack.js/issue/1785) overlapping items when switching column() and making edits. Thank you [@radovanobal](https://github.com/radovanobal) for sponsoring it.
6968
* add [#1887](https://github.com/gridstack/gridstack.js/pull/1887) support for IE (new es5 folder) by [@SmileLifeIven](https://github.com/SmileLifeIven)
69+
* fix [#1785](https://github.com/gridstack/gridstack.js/issue/1785) overlapping items when switching column() and making edits. Thank you [@radovanobal](https://github.com/radovanobal) for sponsoring it.
70+
* fix [#1890](https://github.com/gridstack/gridstack.js/issue/1890) unhandled exception when dragging fast between grids.
7071

7172
## 4.3.1 (2021-10-18)
7273
* fix [#1868](https://github.com/gridstack/gridstack.js/issues/1868) prevent swap during resize
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>1858</title>
8+
9+
<link rel="stylesheet" href="../../../demo/demo.css"/>
10+
<script src="../../../dist/gridstack-h5.js"></script>
11+
12+
</head>
13+
<body>
14+
<div class="container-fluid">
15+
<h1>Full grid, drag 0 out and back in - see 1858</h1>
16+
<div class="grid-stack"></div>
17+
</div>
18+
<script type="text/javascript">
19+
options = {
20+
disableOneColumnMode: true,
21+
row: 15,
22+
margin: 2,
23+
cellHeight: 20,
24+
acceptWidgets: true,
25+
float: false,
26+
};
27+
28+
GridStack.init(options).load([
29+
{ x: 0, y: 0, w: 4, h: 6, content:'0' },
30+
{ x: 0, y: 6, w: 4, h: 2, content:'1' },
31+
{ x: 0, y: 8, w: 4, h: 2, content:'2' },
32+
{ x: 0, y: 10, w: 4, h: 2, content:'3' },
33+
{ x: 0, y: 12, w: 12, h: 3, content:'4' },
34+
{ x: 4, y: 0, w: 8, h: 12, content:'5' },
35+
])
36+
</script>
37+
</body>
38+
</html>

src/gridstack-dd.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ GridStack.prototype._setupAcceptWidget = function(this: GridStack): GridStack {
128128
accept: (el: GridItemHTMLElement) => {
129129
let node: GridStackNode = el.gridstackNode;
130130
// set accept drop to true on ourself (which we ignore) so we don't get "can't drop" icon in HTML5 mode while moving
131-
if (node && node.grid === this) return true;
131+
if (node?.grid === this) return true;
132132
if (!this.opts.acceptWidgets) return false;
133133
// check for accept method or class matching
134134
let canAccept = true;
@@ -152,13 +152,13 @@ GridStack.prototype._setupAcceptWidget = function(this: GridStack): GridStack {
152152
.on(this.el, 'dropover', (event: Event, el: GridItemHTMLElement, helper: GridItemHTMLElement) => {
153153
let node = el.gridstackNode;
154154
// ignore drop enter on ourself (unless we temporarily removed) which happens on a simple drag of our item
155-
if (node && node.grid === this && !node._temporaryRemoved) {
155+
if (node?.grid === this && !node._temporaryRemoved) {
156156
// delete node._added; // reset this to track placeholder again in case we were over other grid #1484 (dropout doesn't always clear)
157157
return false; // prevent parent from receiving msg (which may be a grid as well)
158158
}
159159

160160
// fix #1578 when dragging fast, we may not get a leave on the previous grid so force one now
161-
if (node && node.grid && node.grid !== this && !node._temporaryRemoved) {
161+
if (node?.grid && node.grid !== this && !node._temporaryRemoved) {
162162
// TEST console.log('dropover without leave');
163163
let otherGrid = node.grid;
164164
otherGrid._leave(el, helper);
@@ -214,6 +214,7 @@ GridStack.prototype._setupAcceptWidget = function(this: GridStack): GridStack {
214214
*/
215215
.on(this.el, 'dropout', (event, el: GridItemHTMLElement, helper: GridItemHTMLElement) => {
216216
let node = el.gridstackNode;
217+
if (!node) return false;
217218
// fix #1578 when dragging fast, we might get leave after other grid gets enter (which calls us to clean)
218219
// so skip this one if we're not the active grid really..
219220
if (!node.grid || node.grid === this) {
@@ -227,7 +228,7 @@ GridStack.prototype._setupAcceptWidget = function(this: GridStack): GridStack {
227228
.on(this.el, 'drop', (event, el: GridItemHTMLElement, helper: GridItemHTMLElement) => {
228229
let node = el.gridstackNode;
229230
// ignore drop on ourself from ourself that didn't come from the outside - dragend will handle the simple move instead
230-
if (node && node.grid === this && !node._isExternal) return false;
231+
if (node?.grid === this && !node._isExternal) return false;
231232

232233
let wasAdded = !!this.placeholder.parentElement; // skip items not actually added to us because of constrains, but do cleanup #1419
233234
this.placeholder.remove();

src/gridstack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ export class GridStack {
322322
this.engine.nodes.forEach(n => { maxH = Math.max(maxH, n.y + n.h) });
323323
cbNodes.forEach(n => {
324324
let el = n.el;
325+
if (!el) return;
325326
if (n._removeDOM) {
326327
if (el) el.remove();
327328
delete n._removeDOM;

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export interface GridStackWidget extends GridStackPosition {
243243
noResize?: boolean;
244244
/** prevents moving (default?: undefined = un-constrained) */
245245
noMove?: boolean;
246-
/** prevents moving and resizing (default?: undefined = un-constrained) */
246+
/** prevents being moved by others during their (default?: undefined = un-constrained) */
247247
locked?: boolean;
248248
/** widgets can have their own custom resize handles. For example 'e,w' will make that particular widget only resize east and west. See `resizable: {handles: string}` option */
249249
resizeHandles?: string;

0 commit comments

Comments
 (0)