Skip to content

Commit 0d831f6

Browse files
authored
Merge pull request #1652 from adumesny/develop
drag in/out re-write
2 parents c2ddeec + cd396fa commit 0d831f6

File tree

13 files changed

+203
-219
lines changed

13 files changed

+203
-219
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Join us on Slack: https://gridstackjs.troolee.com
4343
- [Migrating to v1](#migrating-to-v1)
4444
- [Migrating to v2](#migrating-to-v2)
4545
- [Migrating to v3](#migrating-to-v3)
46+
- [Migrating to v4](#migrating-to-v4)
4647
- [jQuery Application](#jquery-application)
4748
- [Changes](#changes)
4849
- [The Team](#the-team)
@@ -390,6 +391,30 @@ Breaking changes:
390391
391392
5. `GridStackWidget` used in most API `width|height|minWidth|minHeight|maxWidth|maxHeight` are now shorter `w|h|minW|minH|maxW|maxH` as well
392393
394+
## Migrating to v4
395+
396+
make sure to read v3 migration first!
397+
398+
v4 is a complete re-write of the collision and drag in/out heuristics to fix some very long standing request & bugs. It also greatly improved usability. Read the release notes for more detail.
399+
400+
**Unlikely** Breaking Changes (internal usage):
401+
402+
1. `removeTimeout` was removed (feedback over trash will be immediate - actual removal still on mouse up)
403+
404+
2. the following `GridStackEngine` methods changed (used internally, doesn't affect `GridStack` public API)
405+
406+
```js
407+
// moved to 3 methods with new option params to support new code and pixel coverage check
408+
`collision()` -> `collide(), collideAll(), collideCoverage()`
409+
`moveNodeCheck(node, x, y, w, h)` -> `moveNodeCheck(node, opt: GridStackMoveOpts)`
410+
`isNodeChangedPosition(node, x, y, w, h)` -> `changedPosConstrain(node, opt: GridStackMoveOpts)`
411+
`moveNode(node, x, y, w, h, noPack)` -> `moveNode(node, opt: GridStackMoveOpts)`
412+
```
413+
414+
3. removed old obsolete (v0.6-v1 methods/attrs) `getGridHeight()`, `verticalMargin`, `data-gs-current-height`,
415+
`locked()`, `maxWidth()`, `minWidth()`, `maxHeight()`, `minHeight()`, `move()`, `resize()`
416+
417+
393418
# jQuery Application
394419
395420
We now have a native HTML5 drag'n'drop through the plugin system (default), but the jquery-ui version can be used instead. It will bundle `jquery` (3.5.1) + `jquery-ui` (1.12.1 minimal drag|drop|resize) + `jquery-ui-touch-punch` (1.0.8 for mobile support) in `gridstack-jq.js`. IFF you want to use gridstack-jq instead and your app needs to bring your own JQ version (only possible in 1.x), you should **instead** use v1.x and include `gridstack-poly.min.js` (optional IE support) + `gridstack.min.js` + `gridstack.jQueryUI.min.js` after you import your JQ libs. But note that there are issue with jQuery and ES6 import (see [1306](https://github.com/gridstack/gridstack.js/issues/1306)).

demo/two-jq.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ <h1>Two grids demo (Jquery version)</h1>
9292
dragIn: '.sidebar .grid-stack-item', // add draggable to class
9393
dragInOptions: { revert: 'invalid', scroll: false, appendTo: 'body', helper: 'clone' }, // clone
9494
removable: '.trash', // drag-out delete class
95-
removeTimeout: 100,
9695
acceptWidgets: function(el) { return true; } // function example, else can be simple: true | false | '.someClass' value
9796
};
9897
grids = GridStack.initAll(options);

demo/two.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ <h1>Two grids demo</h1>
9090
// dragIn: '.sidebar .grid-stack-item', // add draggable to class
9191
// dragInOptions: { revert: 'invalid', scroll: false, appendTo: 'body', helper: 'clone' }, // clone
9292
removable: '.trash', // drag-out delete class
93-
removeTimeout: 100,
9493
acceptWidgets: function(el) { return true; } // function example, else can be simple: true | false | '.someClass' value
9594
};
9695
let grids = GridStack.initAll(options);

demo/web2.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ <h1>Advanced Demo</h1>
6262
dragIn: '.newWidget', // class that can be dragged from outside
6363
dragInOptions: { revert: 'invalid', scroll: false, appendTo: 'body', helper: 'clone' },
6464
removable: '#trash', // drag-out delete class
65-
removeTimeout: 100,
6665
});
6766

6867
let items = [

doc/CHANGES.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,19 @@ Change log
5050
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
5151
## 3.3.0-dev
5252

53-
- fix [#149](https://github.com/gridstack/gridstack.js/issues/149) [#1094](https://github.com/gridstack/gridstack.js/issues/1094) [#1605](https://github.com/gridstack/gridstack.js/issues/1605) re-write of the **collision code**! you can now swap items of the same size (vertical/horizontal) when grid is full, and is the default in `float:false` (top gravity) as it feels more natural. Could add Alt key for swap vs push behavior later.
54-
- Dragging up and down now behave the same (used to require push WAY down past to swap/append). Also much more efficient collision code.
55-
- handle mid point of dragged over items (>50%) rather than a new row/column and check for the most covered when multiple items collide.
53+
- fix [#149](https://github.com/gridstack/gridstack.js/issues/149) [#1094](https://github.com/gridstack/gridstack.js/issues/1094) [#1605](https://github.com/gridstack/gridstack.js/issues/1605) re-write of the **collision code - fixing 6 years old most requested request**
54+
1. you can now swap items of the same size (vertical/horizontal) when grid is full, and is the default in `float:false` (top gravity) as it feels more natural. Could add Alt key for swap vs push behavior later.
55+
2. Dragging up and down now behave the same (used to require push WAY down past to swap/append). Also much more efficient collision code.
56+
3. handle mid point of dragged over items (>50%) rather than just a new row/column and check for the most covered item when multiple collide.
57+
58+
- fix [#393](https://github.com/gridstack/gridstack.js/issues/393) [#1612](https://github.com/gridstack/gridstack.js/issues/1612) [#1578](https://github.com/gridstack/gridstack.js/issues/1578) re-write of the **drag in/out code - fixing 5 years old bug**
59+
1. we now remove item when cursor leaves (`acceptWidgets` case using `dropout` event) or shape is outside (re-using same method) and re-insert on cursor enter (since we only get `dropover` event). Should **not be possible to have 2 placeholders** which confuses the grids.
60+
2. major re-write and cleanup of the drag in/out. Vars have been renamed and fully documented as I couldn't understand the legacy buggy code.
61+
3. removed any over trash delay feedback as I don't see the point and could introduce race conditions.
5662
- fix [1617](https://github.com/gridstack/gridstack.js/issues/1617) FireFox DOM order issue. Thanks [@marcel-necker](https://github.com/marcel-necker)
5763
- fix changing column # `column(n)` now resizes `cellHeight:'auto'` to keep square
58-
- add `drag | resize` events while dragging [1616](https://github.com/gridstack/gridstack.js/pull/1616). Thanks [@MrCorba](https://github.com/MrCorba)
59-
- add `GridStack.setupDragIn()` so user can update external draggable after the grid has been created [1637](https://github.com/gridstack/gridstack.js/issues/1637)
64+
- add [1616](https://github.com/gridstack/gridstack.js/pull/1616) `drag | resize` events while dragging. Thanks [@MrCorba](https://github.com/MrCorba)
65+
- add [1637](https://github.com/gridstack/gridstack.js/issues/1637) `GridStack.setupDragIn()` so user can update external draggable after the grid has been created
6066

6167
## 3.3.0 (2021-2-2)
6268

spec/e2e/html/1570_drag_bottom_max_row.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
maxRow: 3, // change this to show issue
9292
acceptWidgets: true,
9393
removable: true,
94-
removeTimeout: 0,
9594
float: true
9695
}
9796

spec/e2e/html/1571_drop_onto_full.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ <h1>drop onto full</h1>
8989
dragIn: '.sidebar .grid-stack-item', // class that can be dragged from outside
9090
dragInOptions: { revert: 'invalid', scroll: false, appendTo: 'body', helper: 'clone' }, // clone
9191
removable: '.trash', // drag-out delete class
92-
removeTimeout: 100,
9392
acceptWidgets: function(el) { return true; } // function example, else can be simple: true | false | '.someClass' value
9493
};
9594
let grids = GridStack.initAll(options);

spec/gridstack-spec.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ describe('gridstack', function() {
359359
// back to 1 column, move item2 to beginning to [3][1][2] vertically
360360
grid.column(1);
361361
expect(grid.getColumn()).toBe(1);
362-
grid.move(el3, 0, 0);
362+
grid.update(el3, {x:0, y:0});
363363
expect(parseInt(el3.getAttribute('gs-x'))).toBe(0);
364364
expect(parseInt(el3.getAttribute('gs-y'))).toBe(0);
365365
expect(parseInt(el3.getAttribute('gs-w'))).toBe(1);
@@ -619,11 +619,7 @@ describe('gridstack', function() {
619619
let grid = GridStack.init();
620620
let items = Utils.getElements('.grid-stack-item');
621621
for (let i = 0; i < items.length; i++) {
622-
grid
623-
.minWidth(items[i], 2)
624-
.maxWidth(items[i], 3)
625-
.minHeight(items[i], 4)
626-
.maxHeight(items[i], 5);
622+
grid.update(items[i], {minW: 2, maxW: 3, minH: 4, maxH: 5});
627623
}
628624
for (let j = 0; j < items.length; j++) {
629625
expect(parseInt(items[j].getAttribute('gs-min-w'), 10)).toBe(2);
@@ -632,11 +628,7 @@ describe('gridstack', function() {
632628
expect(parseInt(items[j].getAttribute('gs-max-h'), 10)).toBe(5);
633629
}
634630
// remove all constrain
635-
grid
636-
.minWidth('grid-stack-item', 0)
637-
.maxWidth('.grid-stack-item', null)
638-
.minHeight('grid-stack-item', undefined)
639-
.maxHeight(undefined, 0);
631+
grid.update('grid-stack-item', {minW: 0, maxW: null, minH: undefined, maxH: 0});
640632
for (let j = 0; j < items.length; j++) {
641633
expect(items[j].getAttribute('gs-min-w')).toBe(null);
642634
expect(items[j].getAttribute('gs-max-w')).toBe(null);
@@ -1093,7 +1085,7 @@ describe('gridstack', function() {
10931085
};
10941086
let grid = GridStack.init(options);
10951087
let items = Utils.getElements('.grid-stack-item');
1096-
grid.resize(items[0], 5, 5);
1088+
grid.update(items[0], {w:5, h:5});
10971089
expect(parseInt(items[0].getAttribute('gs-w'), 10)).toBe(5);
10981090
expect(parseInt(items[0].getAttribute('gs-h'), 10)).toBe(5);
10991091
});
@@ -1114,7 +1106,7 @@ describe('gridstack', function() {
11141106
};
11151107
let grid = GridStack.init(options);
11161108
let items = Utils.getElements('.grid-stack-item');
1117-
grid.move(items[0], 5, 5);
1109+
grid.update(items[0], {x:5, y:5});
11181110
expect(parseInt(items[0].getAttribute('gs-x'), 10)).toBe(5);
11191111
expect(parseInt(items[0].getAttribute('gs-y'), 10)).toBe(5);
11201112
});
@@ -1549,7 +1541,7 @@ describe('gridstack', function() {
15491541
margin: 5
15501542
};
15511543
let grid = GridStack.init(options);
1552-
grid.locked('.grid-stack-item', true);
1544+
grid.update('.grid-stack-item', {locked: true});
15531545
Utils.getElements('.grid-stack-item').forEach(item => {
15541546
expect(item.getAttribute('gs-locked')).toBe('true');
15551547
})
@@ -1560,7 +1552,7 @@ describe('gridstack', function() {
15601552
margin: 5
15611553
};
15621554
let grid = GridStack.init(options);
1563-
grid.locked('.grid-stack-item', false);
1555+
grid.update('.grid-stack-item', {locked: false});
15641556
Utils.getElements('.grid-stack-item').forEach(item => {
15651557
expect(item.getAttribute('gs-locked')).toBe(null);
15661558
})

0 commit comments

Comments
 (0)