gridstack 7.1.1 → 7.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/angular/README.md +57 -0
- package/dist/angular/gridstack-item.component.ts +61 -0
- package/dist/angular/gridstack.component.ts +165 -0
- package/dist/dd-base-impl.d.ts +1 -1
- package/dist/dd-base-impl.js +1 -1
- package/dist/dd-base-impl.js.map +1 -1
- package/dist/dd-draggable.d.ts +1 -1
- package/dist/dd-draggable.js +1 -1
- package/dist/dd-draggable.js.map +1 -1
- package/dist/dd-droppable.d.ts +1 -1
- package/dist/dd-droppable.js +1 -1
- package/dist/dd-droppable.js.map +1 -1
- package/dist/dd-element.d.ts +1 -1
- package/dist/dd-element.js +1 -1
- package/dist/dd-element.js.map +1 -1
- package/dist/dd-gridstack.d.ts +1 -3
- package/dist/dd-gridstack.js +1 -628
- package/dist/dd-gridstack.js.map +1 -1
- package/dist/dd-manager.d.ts +1 -1
- package/dist/dd-manager.js +1 -1
- package/dist/dd-manager.js.map +1 -1
- package/dist/dd-resizable-handle.d.ts +1 -1
- package/dist/dd-resizable-handle.js +1 -1
- package/dist/dd-resizable-handle.js.map +1 -1
- package/dist/dd-resizable.d.ts +1 -1
- package/dist/dd-resizable.js +1 -1
- package/dist/dd-resizable.js.map +1 -1
- package/dist/dd-touch.d.ts +1 -1
- package/dist/dd-touch.js +1 -1
- package/dist/dd-touch.js.map +1 -1
- package/dist/es5/dd-base-impl.d.ts +1 -1
- package/dist/es5/dd-base-impl.js +1 -1
- package/dist/es5/dd-base-impl.js.map +1 -1
- package/dist/es5/dd-draggable.d.ts +1 -1
- package/dist/es5/dd-draggable.js +1 -1
- package/dist/es5/dd-draggable.js.map +1 -1
- package/dist/es5/dd-droppable.d.ts +1 -1
- package/dist/es5/dd-droppable.js +1 -1
- package/dist/es5/dd-droppable.js.map +1 -1
- package/dist/es5/dd-element.d.ts +1 -1
- package/dist/es5/dd-element.js +1 -1
- package/dist/es5/dd-element.js.map +1 -1
- package/dist/es5/dd-gridstack.d.ts +1 -3
- package/dist/es5/dd-gridstack.js +1 -634
- package/dist/es5/dd-gridstack.js.map +1 -1
- package/dist/es5/dd-manager.d.ts +1 -1
- package/dist/es5/dd-manager.js +1 -1
- package/dist/es5/dd-manager.js.map +1 -1
- package/dist/es5/dd-resizable-handle.d.ts +1 -1
- package/dist/es5/dd-resizable-handle.js +1 -1
- package/dist/es5/dd-resizable-handle.js.map +1 -1
- package/dist/es5/dd-resizable.d.ts +1 -1
- package/dist/es5/dd-resizable.js +1 -1
- package/dist/es5/dd-resizable.js.map +1 -1
- package/dist/es5/dd-touch.d.ts +1 -1
- package/dist/es5/dd-touch.js +1 -1
- package/dist/es5/dd-touch.js.map +1 -1
- package/dist/es5/gridstack-all.js +1 -1
- package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
- package/dist/es5/gridstack-all.js.map +1 -1
- package/dist/es5/gridstack-engine.d.ts +1 -1
- package/dist/es5/gridstack-engine.js +1 -1
- package/dist/es5/gridstack-engine.js.map +1 -1
- package/dist/es5/gridstack-poly.js +1 -1
- package/dist/es5/gridstack.d.ts +16 -7
- package/dist/es5/gridstack.js +646 -42
- package/dist/es5/gridstack.js.map +1 -1
- package/dist/es5/types.d.ts +7 -4
- package/dist/es5/types.js +1 -1
- package/dist/es5/types.js.map +1 -1
- package/dist/es5/utils.d.ts +1 -1
- package/dist/es5/utils.js +1 -1
- package/dist/es5/utils.js.map +1 -1
- package/dist/gridstack-all.js +1 -1
- package/dist/gridstack-all.js.LICENSE.txt +1 -1
- package/dist/gridstack-all.js.map +1 -1
- package/dist/gridstack-engine.d.ts +1 -1
- package/dist/gridstack-engine.js +1 -1
- package/dist/gridstack-engine.js.map +1 -1
- package/dist/gridstack.css +1 -1
- package/dist/gridstack.d.ts +16 -7
- package/dist/gridstack.js +634 -42
- package/dist/gridstack.js.map +1 -1
- package/dist/src/gridstack.scss +1 -1
- package/dist/types.d.ts +7 -4
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/doc/CHANGES.md +12 -5
- package/doc/README.md +0 -2
- package/package.json +2 -2
package/dist/es5/gridstack.js
CHANGED
|
@@ -30,7 +30,7 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
31
|
exports.GridStack = void 0;
|
|
32
32
|
/*!
|
|
33
|
-
* GridStack 7.1.
|
|
33
|
+
* GridStack 7.1.2
|
|
34
34
|
* https://gridstackjs.com/
|
|
35
35
|
*
|
|
36
36
|
* Copyright (c) 2021-2022 Alain Dumesny
|
|
@@ -39,10 +39,22 @@ exports.GridStack = void 0;
|
|
|
39
39
|
var gridstack_engine_1 = require("./gridstack-engine");
|
|
40
40
|
var utils_1 = require("./utils");
|
|
41
41
|
var types_1 = require("./types");
|
|
42
|
+
/*
|
|
43
|
+
* and include D&D by default
|
|
44
|
+
* TODO: while we could generate a gridstack-static.js at smaller size - saves about 31k (41k -> 72k)
|
|
45
|
+
* I don't know how to generate the DD only code at the remaining 31k to delay load as code depends on Gridstack.ts
|
|
46
|
+
* also it caused loading issues in prod - see https://github.com/gridstack/gridstack.js/issues/2039
|
|
47
|
+
*/
|
|
48
|
+
var dd_gridstack_1 = require("./dd-gridstack");
|
|
49
|
+
var dd_touch_1 = require("./dd-touch");
|
|
50
|
+
var dd_manager_1 = require("./dd-manager");
|
|
51
|
+
/** global instance */
|
|
52
|
+
var dd = new dd_gridstack_1.DDGridStack;
|
|
42
53
|
// export all dependent file as well to make it easier for users to just import the main file
|
|
43
54
|
__exportStar(require("./types"), exports);
|
|
44
55
|
__exportStar(require("./utils"), exports);
|
|
45
56
|
__exportStar(require("./gridstack-engine"), exports);
|
|
57
|
+
__exportStar(require("./dd-gridstack"), exports);
|
|
46
58
|
/**
|
|
47
59
|
* Main gridstack class - you will need to call `GridStack.init()` first to initialize your grid.
|
|
48
60
|
* Note: your grid elements MUST have the following classes for the CSS layout to work:
|
|
@@ -69,6 +81,9 @@ var GridStack = /** @class */ (function () {
|
|
|
69
81
|
this._extraDragRow = 0;
|
|
70
82
|
this.el = el; // exposed HTML element to the user
|
|
71
83
|
opts = opts || {}; // handles null/undefined/0
|
|
84
|
+
if (!el.classList.contains('grid-stack')) {
|
|
85
|
+
this.el.classList.add('grid-stack');
|
|
86
|
+
}
|
|
72
87
|
// if row property exists, replace minRow and maxRow instead
|
|
73
88
|
if (opts.row) {
|
|
74
89
|
opts.minRow = opts.maxRow = opts.row;
|
|
@@ -334,28 +349,34 @@ var GridStack = /** @class */ (function () {
|
|
|
334
349
|
return w.x !== undefined || w.y !== undefined || w.w !== undefined || w.h !== undefined || w.content !== undefined ? true : false;
|
|
335
350
|
}
|
|
336
351
|
var el;
|
|
352
|
+
var node;
|
|
337
353
|
if (typeof els === 'string') {
|
|
338
354
|
var doc = document.implementation.createHTMLDocument(''); // IE needs a param
|
|
339
355
|
doc.body.innerHTML = els;
|
|
340
356
|
el = doc.body.children[0];
|
|
341
357
|
}
|
|
342
358
|
else if (arguments.length === 0 || arguments.length === 1 && isGridStackWidget(els)) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
359
|
+
node = options = els;
|
|
360
|
+
if (node === null || node === void 0 ? void 0 : node.el) {
|
|
361
|
+
el = node.el; // re-use element stored in the node
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
var content = (options === null || options === void 0 ? void 0 : options.content) || '';
|
|
365
|
+
var doc = document.implementation.createHTMLDocument(''); // IE needs a param
|
|
366
|
+
doc.body.innerHTML = "<div class=\"grid-stack-item " + (this.opts.itemClass || '') + "\"><div class=\"grid-stack-item-content\">" + content + "</div></div>";
|
|
367
|
+
el = doc.body.children[0];
|
|
368
|
+
}
|
|
348
369
|
}
|
|
349
370
|
else {
|
|
350
371
|
el = els;
|
|
351
372
|
}
|
|
352
373
|
// Tempting to initialize the passed in opt with default and valid values, but this break knockout demos
|
|
353
|
-
// as the actual value are filled in when _prepareElement() calls el.getAttribute('gs-xyz) before adding the node.
|
|
374
|
+
// as the actual value are filled in when _prepareElement() calls el.getAttribute('gs-xyz') before adding the node.
|
|
354
375
|
// So make sure we load any DOM attributes that are not specified in passed in options (which override)
|
|
355
376
|
var domAttr = this._readAttr(el);
|
|
356
377
|
options = utils_1.Utils.cloneDeep(options) || {}; // make a copy before we modify in case caller re-uses it
|
|
357
378
|
utils_1.Utils.defaults(options, domAttr);
|
|
358
|
-
|
|
379
|
+
node = this.engine.prepareNode(options);
|
|
359
380
|
this._writeAttr(el, options);
|
|
360
381
|
if (this._insertNotAppend) {
|
|
361
382
|
this.el.prepend(el);
|
|
@@ -609,7 +630,7 @@ var GridStack = /** @class */ (function () {
|
|
|
609
630
|
w = addAndRemove(_this, w, true).gridstackNode;
|
|
610
631
|
}
|
|
611
632
|
else {
|
|
612
|
-
w = _this.addWidget(w).gridstackNode;
|
|
633
|
+
w = (w.el ? _this.addWidget(w.el, w) : _this.addWidget(w)).gridstackNode;
|
|
613
634
|
}
|
|
614
635
|
}
|
|
615
636
|
});
|
|
@@ -1009,16 +1030,23 @@ var GridStack = /** @class */ (function () {
|
|
|
1009
1030
|
* Toggle the grid static state, which permanently removes/add Drag&Drop support, unlike disable()/enable() that just turns it off/on.
|
|
1010
1031
|
* Also toggle the grid-stack-static class.
|
|
1011
1032
|
* @param val if true the grid become static.
|
|
1033
|
+
* @param updateClass true (default) if css class gets updated
|
|
1034
|
+
* @param recurse true (default) if sub-grids also get updated
|
|
1012
1035
|
*/
|
|
1013
|
-
GridStack.prototype.setStatic = function (val, updateClass) {
|
|
1036
|
+
GridStack.prototype.setStatic = function (val, updateClass, recurse) {
|
|
1014
1037
|
var _this = this;
|
|
1015
1038
|
if (updateClass === void 0) { updateClass = true; }
|
|
1039
|
+
if (recurse === void 0) { recurse = true; }
|
|
1016
1040
|
if (this.opts.staticGrid === val)
|
|
1017
1041
|
return this;
|
|
1018
1042
|
this.opts.staticGrid = val;
|
|
1019
1043
|
this._setupRemoveDrop();
|
|
1020
1044
|
this._setupAcceptWidget();
|
|
1021
|
-
this.engine.nodes.forEach(function (n) {
|
|
1045
|
+
this.engine.nodes.forEach(function (n) {
|
|
1046
|
+
_this._prepareDragDropByNode(n); // either delete or init Drag&drop
|
|
1047
|
+
if (n.subGrid && recurse)
|
|
1048
|
+
n.subGrid.setStatic(val, updateClass, recurse);
|
|
1049
|
+
});
|
|
1022
1050
|
if (updateClass) {
|
|
1023
1051
|
this._setStaticClass();
|
|
1024
1052
|
}
|
|
@@ -1280,10 +1308,8 @@ var GridStack = /** @class */ (function () {
|
|
|
1280
1308
|
/** @internal */
|
|
1281
1309
|
GridStack.prototype._prepareElement = function (el, triggerAddEvent, node) {
|
|
1282
1310
|
if (triggerAddEvent === void 0) { triggerAddEvent = false; }
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
node = this._readAttr(el);
|
|
1286
|
-
}
|
|
1311
|
+
el.classList.add(this.opts.itemClass);
|
|
1312
|
+
node = node || this._readAttr(el);
|
|
1287
1313
|
el.gridstackNode = node;
|
|
1288
1314
|
node.el = el;
|
|
1289
1315
|
node.grid = this;
|
|
@@ -1523,14 +1549,15 @@ var GridStack = /** @class */ (function () {
|
|
|
1523
1549
|
}
|
|
1524
1550
|
return this;
|
|
1525
1551
|
};
|
|
1526
|
-
/*
|
|
1527
|
-
* drag&drop
|
|
1528
|
-
*
|
|
1529
|
-
*
|
|
1530
|
-
* GridStack.prototype._setupAcceptWidget = function()
|
|
1531
|
-
* maybe there is a better way ????
|
|
1552
|
+
/* ===========================================================================================
|
|
1553
|
+
* drag&drop methods that used to be stubbed out and implemented in dd-gridstack.ts
|
|
1554
|
+
* but caused loading issues in prod - see https://github.com/gridstack/gridstack.js/issues/2039
|
|
1555
|
+
* ===========================================================================================
|
|
1532
1556
|
*/
|
|
1533
|
-
|
|
1557
|
+
/** get the global (but static to this code) DD implementation */
|
|
1558
|
+
GridStack.getDD = function () {
|
|
1559
|
+
return dd;
|
|
1560
|
+
};
|
|
1534
1561
|
/**
|
|
1535
1562
|
* call to setup dragging in from the outside (say toolbar), by specifying the class selection and options.
|
|
1536
1563
|
* Called during GridStack.init() as options, but can also be called directly (last param are used) in case the toolbar
|
|
@@ -1538,20 +1565,61 @@ var GridStack = /** @class */ (function () {
|
|
|
1538
1565
|
* @param dragIn string selector (ex: '.sidebar .grid-stack-item')
|
|
1539
1566
|
* @param dragInOptions options - see DDDragInOpt. (default: {handle: '.grid-stack-item-content', appendTo: 'body'}
|
|
1540
1567
|
**/
|
|
1541
|
-
GridStack.setupDragIn = function (dragIn, dragInOptions) {
|
|
1568
|
+
GridStack.setupDragIn = function (dragIn, dragInOptions) {
|
|
1569
|
+
if ((dragInOptions === null || dragInOptions === void 0 ? void 0 : dragInOptions.pause) !== undefined) {
|
|
1570
|
+
dd_manager_1.DDManager.pauseDrag = dragInOptions.pause;
|
|
1571
|
+
}
|
|
1572
|
+
if (typeof dragIn === 'string') {
|
|
1573
|
+
dragInOptions = __assign(__assign({}, types_1.dragInDefaultOptions), (dragInOptions || {}));
|
|
1574
|
+
utils_1.Utils.getElements(dragIn).forEach(function (el) {
|
|
1575
|
+
if (!dd.isDraggable(el))
|
|
1576
|
+
dd.dragIn(el, dragInOptions);
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1542
1580
|
/**
|
|
1543
1581
|
* Enables/Disables dragging by the user of specific grid element. If you want all items, and have it affect future items, use enableMove() instead. No-op for static grids.
|
|
1544
1582
|
* IF you are looking to prevent an item from moving (due to being pushed around by another during collision) use locked property instead.
|
|
1545
1583
|
* @param els widget or selector to modify.
|
|
1546
1584
|
* @param val if true widget will be draggable.
|
|
1547
1585
|
*/
|
|
1548
|
-
GridStack.prototype.movable = function (els, val) {
|
|
1586
|
+
GridStack.prototype.movable = function (els, val) {
|
|
1587
|
+
var _this = this;
|
|
1588
|
+
if (this.opts.staticGrid)
|
|
1589
|
+
return this; // can't move a static grid!
|
|
1590
|
+
GridStack.getElements(els).forEach(function (el) {
|
|
1591
|
+
var node = el.gridstackNode;
|
|
1592
|
+
if (!node)
|
|
1593
|
+
return;
|
|
1594
|
+
if (val)
|
|
1595
|
+
delete node.noMove;
|
|
1596
|
+
else
|
|
1597
|
+
node.noMove = true;
|
|
1598
|
+
_this._prepareDragDropByNode(node); // init DD if need be, and adjust
|
|
1599
|
+
});
|
|
1600
|
+
return this;
|
|
1601
|
+
};
|
|
1549
1602
|
/**
|
|
1550
1603
|
* Enables/Disables user resizing of specific grid element. If you want all items, and have it affect future items, use enableResize() instead. No-op for static grids.
|
|
1551
1604
|
* @param els widget or selector to modify
|
|
1552
1605
|
* @param val if true widget will be resizable.
|
|
1553
1606
|
*/
|
|
1554
|
-
GridStack.prototype.resizable = function (els, val) {
|
|
1607
|
+
GridStack.prototype.resizable = function (els, val) {
|
|
1608
|
+
var _this = this;
|
|
1609
|
+
if (this.opts.staticGrid)
|
|
1610
|
+
return this; // can't resize a static grid!
|
|
1611
|
+
GridStack.getElements(els).forEach(function (el) {
|
|
1612
|
+
var node = el.gridstackNode;
|
|
1613
|
+
if (!node)
|
|
1614
|
+
return;
|
|
1615
|
+
if (val)
|
|
1616
|
+
delete node.noResize;
|
|
1617
|
+
else
|
|
1618
|
+
node.noResize = true;
|
|
1619
|
+
_this._prepareDragDropByNode(node); // init DD if need be, and adjust
|
|
1620
|
+
});
|
|
1621
|
+
return this;
|
|
1622
|
+
};
|
|
1555
1623
|
/**
|
|
1556
1624
|
* Temporarily disables widgets moving/resizing.
|
|
1557
1625
|
* If you want a more permanent way (which freezes up resources) use `setStatic(true)` instead.
|
|
@@ -1560,8 +1628,17 @@ var GridStack = /** @class */ (function () {
|
|
|
1560
1628
|
* @example
|
|
1561
1629
|
* grid.enableMove(false);
|
|
1562
1630
|
* grid.enableResize(false);
|
|
1631
|
+
* @param recurse true (default) if sub-grids also get updated
|
|
1563
1632
|
*/
|
|
1564
|
-
GridStack.prototype.disable = function () {
|
|
1633
|
+
GridStack.prototype.disable = function (recurse) {
|
|
1634
|
+
if (recurse === void 0) { recurse = true; }
|
|
1635
|
+
if (this.opts.staticGrid)
|
|
1636
|
+
return;
|
|
1637
|
+
this.enableMove(false, recurse);
|
|
1638
|
+
this.enableResize(false, recurse); // @ts-ignore
|
|
1639
|
+
this._triggerEvent('disable');
|
|
1640
|
+
return this;
|
|
1641
|
+
};
|
|
1565
1642
|
/**
|
|
1566
1643
|
* Re-enables widgets moving/resizing - see disable().
|
|
1567
1644
|
* Note: no-op for static grid.
|
|
@@ -1569,41 +1646,568 @@ var GridStack = /** @class */ (function () {
|
|
|
1569
1646
|
* @example
|
|
1570
1647
|
* grid.enableMove(true);
|
|
1571
1648
|
* grid.enableResize(true);
|
|
1649
|
+
* @param recurse true (default) if sub-grids also get updated
|
|
1572
1650
|
*/
|
|
1573
|
-
GridStack.prototype.enable = function () {
|
|
1651
|
+
GridStack.prototype.enable = function (recurse) {
|
|
1652
|
+
if (recurse === void 0) { recurse = true; }
|
|
1653
|
+
if (this.opts.staticGrid)
|
|
1654
|
+
return;
|
|
1655
|
+
this.enableMove(true, recurse);
|
|
1656
|
+
this.enableResize(true, recurse); // @ts-ignore
|
|
1657
|
+
this._triggerEvent('enable');
|
|
1658
|
+
return this;
|
|
1659
|
+
};
|
|
1574
1660
|
/**
|
|
1575
1661
|
* Enables/disables widget moving. No-op for static grids.
|
|
1662
|
+
* @param recurse true (default) if sub-grids also get updated
|
|
1576
1663
|
*/
|
|
1577
|
-
GridStack.prototype.enableMove = function (doEnable) {
|
|
1664
|
+
GridStack.prototype.enableMove = function (doEnable, recurse) {
|
|
1665
|
+
var _this = this;
|
|
1666
|
+
if (recurse === void 0) { recurse = true; }
|
|
1667
|
+
if (this.opts.staticGrid)
|
|
1668
|
+
return this; // can't move a static grid!
|
|
1669
|
+
this.opts.disableDrag = !doEnable; // FIRST before we update children as grid overrides #1658
|
|
1670
|
+
this.engine.nodes.forEach(function (n) {
|
|
1671
|
+
_this.movable(n.el, doEnable);
|
|
1672
|
+
if (n.subGrid && recurse)
|
|
1673
|
+
n.subGrid.enableMove(doEnable, recurse);
|
|
1674
|
+
});
|
|
1675
|
+
return this;
|
|
1676
|
+
};
|
|
1578
1677
|
/**
|
|
1579
1678
|
* Enables/disables widget resizing. No-op for static grids.
|
|
1679
|
+
* @param recurse true (default) if sub-grids also get updated
|
|
1580
1680
|
*/
|
|
1581
|
-
GridStack.prototype.enableResize = function (doEnable) {
|
|
1681
|
+
GridStack.prototype.enableResize = function (doEnable, recurse) {
|
|
1682
|
+
var _this = this;
|
|
1683
|
+
if (recurse === void 0) { recurse = true; }
|
|
1684
|
+
if (this.opts.staticGrid)
|
|
1685
|
+
return this; // can't size a static grid!
|
|
1686
|
+
this.opts.disableResize = !doEnable; // FIRST before we update children as grid overrides #1658
|
|
1687
|
+
this.engine.nodes.forEach(function (n) {
|
|
1688
|
+
_this.resizable(n.el, doEnable);
|
|
1689
|
+
if (n.subGrid && recurse)
|
|
1690
|
+
n.subGrid.enableResize(doEnable, recurse);
|
|
1691
|
+
});
|
|
1692
|
+
return this;
|
|
1693
|
+
};
|
|
1582
1694
|
/** @internal removes any drag&drop present (called during destroy) */
|
|
1583
|
-
GridStack.prototype._removeDD = function (el) {
|
|
1584
|
-
|
|
1585
|
-
|
|
1695
|
+
GridStack.prototype._removeDD = function (el) {
|
|
1696
|
+
dd.draggable(el, 'destroy').resizable(el, 'destroy');
|
|
1697
|
+
if (el.gridstackNode) {
|
|
1698
|
+
delete el.gridstackNode._initDD; // reset our DD init flag
|
|
1699
|
+
}
|
|
1700
|
+
delete el.ddElement;
|
|
1701
|
+
return this;
|
|
1702
|
+
};
|
|
1703
|
+
/** @internal called to add drag over to support widgets being added externally */
|
|
1704
|
+
GridStack.prototype._setupAcceptWidget = function () {
|
|
1705
|
+
var _this = this;
|
|
1706
|
+
// check if we need to disable things
|
|
1707
|
+
if (this.opts.staticGrid || (!this.opts.acceptWidgets && !this.opts.removable)) {
|
|
1708
|
+
dd.droppable(this.el, 'destroy');
|
|
1709
|
+
return this;
|
|
1710
|
+
}
|
|
1711
|
+
// vars shared across all methods
|
|
1712
|
+
var cellHeight, cellWidth;
|
|
1713
|
+
var onDrag = function (event, el, helper) {
|
|
1714
|
+
var node = el.gridstackNode;
|
|
1715
|
+
if (!node)
|
|
1716
|
+
return;
|
|
1717
|
+
helper = helper || el;
|
|
1718
|
+
var parent = _this.el.getBoundingClientRect();
|
|
1719
|
+
var _a = helper.getBoundingClientRect(), top = _a.top, left = _a.left;
|
|
1720
|
+
left -= parent.left;
|
|
1721
|
+
top -= parent.top;
|
|
1722
|
+
var ui = { position: { top: top, left: left } };
|
|
1723
|
+
if (node._temporaryRemoved) {
|
|
1724
|
+
node.x = Math.max(0, Math.round(left / cellWidth));
|
|
1725
|
+
node.y = Math.max(0, Math.round(top / cellHeight));
|
|
1726
|
+
delete node.autoPosition;
|
|
1727
|
+
_this.engine.nodeBoundFix(node);
|
|
1728
|
+
// don't accept *initial* location if doesn't fit #1419 (locked drop region, or can't grow), but maybe try if it will go somewhere
|
|
1729
|
+
if (!_this.engine.willItFit(node)) {
|
|
1730
|
+
node.autoPosition = true; // ignore x,y and try for any slot...
|
|
1731
|
+
if (!_this.engine.willItFit(node)) {
|
|
1732
|
+
dd.off(el, 'drag'); // stop calling us
|
|
1733
|
+
return; // full grid or can't grow
|
|
1734
|
+
}
|
|
1735
|
+
if (node._willFitPos) {
|
|
1736
|
+
// use the auto position instead #1687
|
|
1737
|
+
utils_1.Utils.copyPos(node, node._willFitPos);
|
|
1738
|
+
delete node._willFitPos;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
// re-use the existing node dragging method
|
|
1742
|
+
_this._onStartMoving(helper, event, ui, node, cellWidth, cellHeight);
|
|
1743
|
+
}
|
|
1744
|
+
else {
|
|
1745
|
+
// re-use the existing node dragging that does so much of the collision detection
|
|
1746
|
+
_this._dragOrResize(helper, event, ui, node, cellWidth, cellHeight);
|
|
1747
|
+
}
|
|
1748
|
+
};
|
|
1749
|
+
dd.droppable(this.el, {
|
|
1750
|
+
accept: function (el) {
|
|
1751
|
+
var node = el.gridstackNode;
|
|
1752
|
+
// set accept drop to true on ourself (which we ignore) so we don't get "can't drop" icon in HTML5 mode while moving
|
|
1753
|
+
if ((node === null || node === void 0 ? void 0 : node.grid) === _this)
|
|
1754
|
+
return true;
|
|
1755
|
+
if (!_this.opts.acceptWidgets)
|
|
1756
|
+
return false;
|
|
1757
|
+
// check for accept method or class matching
|
|
1758
|
+
var canAccept = true;
|
|
1759
|
+
if (typeof _this.opts.acceptWidgets === 'function') {
|
|
1760
|
+
canAccept = _this.opts.acceptWidgets(el);
|
|
1761
|
+
}
|
|
1762
|
+
else {
|
|
1763
|
+
var selector = (_this.opts.acceptWidgets === true ? '.grid-stack-item' : _this.opts.acceptWidgets);
|
|
1764
|
+
canAccept = el.matches(selector);
|
|
1765
|
+
}
|
|
1766
|
+
// finally check to make sure we actually have space left #1571
|
|
1767
|
+
if (canAccept && node && _this.opts.maxRow) {
|
|
1768
|
+
var n = { w: node.w, h: node.h, minW: node.minW, minH: node.minH }; // only width/height matters and autoPosition
|
|
1769
|
+
canAccept = _this.engine.willItFit(n);
|
|
1770
|
+
}
|
|
1771
|
+
return canAccept;
|
|
1772
|
+
}
|
|
1773
|
+
})
|
|
1774
|
+
/**
|
|
1775
|
+
* entering our grid area
|
|
1776
|
+
*/
|
|
1777
|
+
.on(this.el, 'dropover', function (event, el, helper) {
|
|
1778
|
+
// console.log(`over ${this.el.gridstack.opts.id} ${count++}`); // TEST
|
|
1779
|
+
var node = el.gridstackNode;
|
|
1780
|
+
// ignore drop enter on ourself (unless we temporarily removed) which happens on a simple drag of our item
|
|
1781
|
+
if ((node === null || node === void 0 ? void 0 : node.grid) === _this && !node._temporaryRemoved) {
|
|
1782
|
+
// delete node._added; // reset this to track placeholder again in case we were over other grid #1484 (dropout doesn't always clear)
|
|
1783
|
+
return false; // prevent parent from receiving msg (which may be a grid as well)
|
|
1784
|
+
}
|
|
1785
|
+
// fix #1578 when dragging fast, we may not get a leave on the previous grid so force one now
|
|
1786
|
+
if ((node === null || node === void 0 ? void 0 : node.grid) && node.grid !== _this && !node._temporaryRemoved) {
|
|
1787
|
+
// console.log('dropover without leave'); // TEST
|
|
1788
|
+
var otherGrid = node.grid;
|
|
1789
|
+
otherGrid._leave(el, helper);
|
|
1790
|
+
}
|
|
1791
|
+
// cache cell dimensions (which don't change), position can animate if we removed an item in otherGrid that affects us...
|
|
1792
|
+
cellWidth = _this.cellWidth();
|
|
1793
|
+
cellHeight = _this.getCellHeight(true);
|
|
1794
|
+
// load any element attributes if we don't have a node
|
|
1795
|
+
if (!node) { // @ts-ignore private read only on ourself
|
|
1796
|
+
node = _this._readAttr(el);
|
|
1797
|
+
}
|
|
1798
|
+
if (!node.grid) {
|
|
1799
|
+
node._isExternal = true;
|
|
1800
|
+
el.gridstackNode = node;
|
|
1801
|
+
}
|
|
1802
|
+
// calculate the grid size based on element outer size
|
|
1803
|
+
helper = helper || el;
|
|
1804
|
+
var w = node.w || Math.round(helper.offsetWidth / cellWidth) || 1;
|
|
1805
|
+
var h = node.h || Math.round(helper.offsetHeight / cellHeight) || 1;
|
|
1806
|
+
// if the item came from another grid, make a copy and save the original info in case we go back there
|
|
1807
|
+
if (node.grid && node.grid !== _this) {
|
|
1808
|
+
// copy the node original values (min/max/id/etc...) but override width/height/other flags which are this grid specific
|
|
1809
|
+
// console.log('dropover cloning node'); // TEST
|
|
1810
|
+
if (!el._gridstackNodeOrig)
|
|
1811
|
+
el._gridstackNodeOrig = node; // shouldn't have multiple nested!
|
|
1812
|
+
el.gridstackNode = node = __assign(__assign({}, node), { w: w, h: h, grid: _this });
|
|
1813
|
+
_this.engine.cleanupNode(node)
|
|
1814
|
+
.nodeBoundFix(node);
|
|
1815
|
+
// restore some internal fields we need after clearing them all
|
|
1816
|
+
node._initDD =
|
|
1817
|
+
node._isExternal = // DOM needs to be re-parented on a drop
|
|
1818
|
+
node._temporaryRemoved = true; // so it can be inserted onDrag below
|
|
1819
|
+
}
|
|
1820
|
+
else {
|
|
1821
|
+
node.w = w;
|
|
1822
|
+
node.h = h;
|
|
1823
|
+
node._temporaryRemoved = true; // so we can insert it
|
|
1824
|
+
}
|
|
1825
|
+
// clear any marked for complete removal (Note: don't check _isAboutToRemove as that is cleared above - just do it)
|
|
1826
|
+
_this._itemRemoving(node.el, false);
|
|
1827
|
+
dd.on(el, 'drag', onDrag);
|
|
1828
|
+
// make sure this is called at least once when going fast #1578
|
|
1829
|
+
onDrag(event, el, helper);
|
|
1830
|
+
return false; // prevent parent from receiving msg (which may be a grid as well)
|
|
1831
|
+
})
|
|
1832
|
+
/**
|
|
1833
|
+
* Leaving our grid area...
|
|
1834
|
+
*/
|
|
1835
|
+
.on(this.el, 'dropout', function (event, el, helper) {
|
|
1836
|
+
// console.log(`out ${this.el.gridstack.opts.id} ${count++}`); // TEST
|
|
1837
|
+
var node = el.gridstackNode;
|
|
1838
|
+
if (!node)
|
|
1839
|
+
return false;
|
|
1840
|
+
// fix #1578 when dragging fast, we might get leave after other grid gets enter (which calls us to clean)
|
|
1841
|
+
// so skip this one if we're not the active grid really..
|
|
1842
|
+
if (!node.grid || node.grid === _this) {
|
|
1843
|
+
_this._leave(el, helper);
|
|
1844
|
+
// if we were created as temporary nested grid, go back to before state
|
|
1845
|
+
if (_this._isTemp) {
|
|
1846
|
+
_this.removeAsSubGrid(node);
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
return false; // prevent parent from receiving msg (which may be grid as well)
|
|
1850
|
+
})
|
|
1851
|
+
/**
|
|
1852
|
+
* end - releasing the mouse
|
|
1853
|
+
*/
|
|
1854
|
+
.on(this.el, 'drop', function (event, el, helper) {
|
|
1855
|
+
var _a, _b;
|
|
1856
|
+
var node = el.gridstackNode;
|
|
1857
|
+
// ignore drop on ourself from ourself that didn't come from the outside - dragend will handle the simple move instead
|
|
1858
|
+
if ((node === null || node === void 0 ? void 0 : node.grid) === _this && !node._isExternal)
|
|
1859
|
+
return false;
|
|
1860
|
+
var wasAdded = !!_this.placeholder.parentElement; // skip items not actually added to us because of constrains, but do cleanup #1419
|
|
1861
|
+
_this.placeholder.remove();
|
|
1862
|
+
// notify previous grid of removal
|
|
1863
|
+
// console.log('drop delete _gridstackNodeOrig') // TEST
|
|
1864
|
+
var origNode = el._gridstackNodeOrig;
|
|
1865
|
+
delete el._gridstackNodeOrig;
|
|
1866
|
+
if (wasAdded && (origNode === null || origNode === void 0 ? void 0 : origNode.grid) && origNode.grid !== _this) {
|
|
1867
|
+
var oGrid = origNode.grid;
|
|
1868
|
+
oGrid.engine.removedNodes.push(origNode);
|
|
1869
|
+
oGrid._triggerRemoveEvent();
|
|
1870
|
+
// if it's an empty sub-grid, to get auto-created, nuke it
|
|
1871
|
+
if (oGrid.parentGridItem && !oGrid.engine.nodes.length && oGrid.opts.subGridDynamic) {
|
|
1872
|
+
oGrid.removeAsSubGrid();
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
if (!node)
|
|
1876
|
+
return false;
|
|
1877
|
+
// use existing placeholder node as it's already in our list with drop location
|
|
1878
|
+
if (wasAdded) {
|
|
1879
|
+
_this.engine.cleanupNode(node); // removes all internal _xyz values
|
|
1880
|
+
node.grid = _this;
|
|
1881
|
+
}
|
|
1882
|
+
dd.off(el, 'drag');
|
|
1883
|
+
// if we made a copy ('helper' which is temp) of the original node then insert a copy, else we move the original node (#1102)
|
|
1884
|
+
// as the helper will be nuked by jquery-ui otherwise
|
|
1885
|
+
if (helper !== el) {
|
|
1886
|
+
helper.remove();
|
|
1887
|
+
el.gridstackNode = origNode; // original item (left behind) is re-stored to pre dragging as the node now has drop info
|
|
1888
|
+
if (wasAdded) {
|
|
1889
|
+
el = el.cloneNode(true);
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
else {
|
|
1893
|
+
el.remove(); // reduce flicker as we change depth here, and size further down
|
|
1894
|
+
_this._removeDD(el);
|
|
1895
|
+
}
|
|
1896
|
+
if (!wasAdded)
|
|
1897
|
+
return false;
|
|
1898
|
+
el.gridstackNode = node;
|
|
1899
|
+
node.el = el;
|
|
1900
|
+
var subGrid = (_b = (_a = node.subGrid) === null || _a === void 0 ? void 0 : _a.el) === null || _b === void 0 ? void 0 : _b.gridstack; // set when actual sub-grid present
|
|
1901
|
+
// @ts-ignore
|
|
1902
|
+
utils_1.Utils.copyPos(node, _this._readAttr(_this.placeholder)); // placeholder values as moving VERY fast can throw things off #1578
|
|
1903
|
+
utils_1.Utils.removePositioningStyles(el); // @ts-ignore
|
|
1904
|
+
_this._writeAttr(el, node);
|
|
1905
|
+
_this.el.appendChild(el); // @ts-ignore // TODO: now would be ideal time to _removeHelperStyle() overriding floating styles (native only)
|
|
1906
|
+
if (subGrid) {
|
|
1907
|
+
subGrid.parentGridItem = node;
|
|
1908
|
+
if (!subGrid.opts.styleInHead)
|
|
1909
|
+
subGrid._updateStyles(true); // re-create sub-grid styles now that we've moved
|
|
1910
|
+
}
|
|
1911
|
+
_this._updateContainerHeight();
|
|
1912
|
+
_this.engine.addedNodes.push(node); // @ts-ignore
|
|
1913
|
+
_this._triggerAddEvent(); // @ts-ignore
|
|
1914
|
+
_this._triggerChangeEvent();
|
|
1915
|
+
_this.engine.endUpdate();
|
|
1916
|
+
if (_this._gsEventHandler['dropped']) {
|
|
1917
|
+
_this._gsEventHandler['dropped'](__assign(__assign({}, event), { type: 'dropped' }), origNode && origNode.grid ? origNode : undefined, node);
|
|
1918
|
+
}
|
|
1919
|
+
// wait till we return out of the drag callback to set the new drag&resize handler or they may get messed up
|
|
1920
|
+
window.setTimeout(function () {
|
|
1921
|
+
// IFF we are still there (some application will use as placeholder and insert their real widget instead and better call makeWidget())
|
|
1922
|
+
if (node.el && node.el.parentElement) {
|
|
1923
|
+
_this._prepareDragDropByNode(node);
|
|
1924
|
+
}
|
|
1925
|
+
else {
|
|
1926
|
+
_this.engine.removeNode(node);
|
|
1927
|
+
}
|
|
1928
|
+
delete node.grid._isTemp;
|
|
1929
|
+
});
|
|
1930
|
+
return false; // prevent parent from receiving msg (which may be grid as well)
|
|
1931
|
+
});
|
|
1932
|
+
return this;
|
|
1933
|
+
};
|
|
1934
|
+
/** @internal mark item for removal */
|
|
1935
|
+
GridStack.prototype._itemRemoving = function (el, remove) {
|
|
1936
|
+
var node = el ? el.gridstackNode : undefined;
|
|
1937
|
+
if (!node || !node.grid)
|
|
1938
|
+
return;
|
|
1939
|
+
remove ? node._isAboutToRemove = true : delete node._isAboutToRemove;
|
|
1940
|
+
remove ? el.classList.add('grid-stack-item-removing') : el.classList.remove('grid-stack-item-removing');
|
|
1941
|
+
};
|
|
1586
1942
|
/** @internal called to setup a trash drop zone if the user specifies it */
|
|
1587
|
-
GridStack.prototype._setupRemoveDrop = function () {
|
|
1943
|
+
GridStack.prototype._setupRemoveDrop = function () {
|
|
1944
|
+
var _this = this;
|
|
1945
|
+
if (!this.opts.staticGrid && typeof this.opts.removable === 'string') {
|
|
1946
|
+
var trashEl = document.querySelector(this.opts.removable);
|
|
1947
|
+
if (!trashEl)
|
|
1948
|
+
return this;
|
|
1949
|
+
// only register ONE drop-over/dropout callback for the 'trash', and it will
|
|
1950
|
+
// update the passed in item and parent grid because the 'trash' is a shared resource anyway,
|
|
1951
|
+
// and Native DD only has 1 event CB (having a list and technically a per grid removableOptions complicates things greatly)
|
|
1952
|
+
if (!dd.isDroppable(trashEl)) {
|
|
1953
|
+
dd.droppable(trashEl, this.opts.removableOptions)
|
|
1954
|
+
.on(trashEl, 'dropover', function (event, el) { return _this._itemRemoving(el, true); })
|
|
1955
|
+
.on(trashEl, 'dropout', function (event, el) { return _this._itemRemoving(el, false); });
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
return this;
|
|
1959
|
+
};
|
|
1588
1960
|
/** @internal prepares the element for drag&drop **/
|
|
1589
|
-
GridStack.prototype._prepareDragDropByNode = function (node) {
|
|
1961
|
+
GridStack.prototype._prepareDragDropByNode = function (node) {
|
|
1962
|
+
var _this = this;
|
|
1963
|
+
var el = node.el;
|
|
1964
|
+
var noMove = node.noMove || this.opts.disableDrag;
|
|
1965
|
+
var noResize = node.noResize || this.opts.disableResize;
|
|
1966
|
+
// check for disabled grid first
|
|
1967
|
+
if (this.opts.staticGrid || (noMove && noResize)) {
|
|
1968
|
+
if (node._initDD) {
|
|
1969
|
+
this._removeDD(el); // nukes everything instead of just disable, will add some styles back next
|
|
1970
|
+
delete node._initDD;
|
|
1971
|
+
}
|
|
1972
|
+
el.classList.add('ui-draggable-disabled', 'ui-resizable-disabled'); // add styles one might depend on #1435
|
|
1973
|
+
return this;
|
|
1974
|
+
}
|
|
1975
|
+
if (!node._initDD) {
|
|
1976
|
+
// variables used/cashed between the 3 start/move/end methods, in addition to node passed above
|
|
1977
|
+
var cellWidth_1;
|
|
1978
|
+
var cellHeight_1;
|
|
1979
|
+
/** called when item starts moving/resizing */
|
|
1980
|
+
var onStartMoving = function (event, ui) {
|
|
1981
|
+
// trigger any 'dragstart' / 'resizestart' manually
|
|
1982
|
+
if (_this._gsEventHandler[event.type]) {
|
|
1983
|
+
_this._gsEventHandler[event.type](event, event.target);
|
|
1984
|
+
}
|
|
1985
|
+
cellWidth_1 = _this.cellWidth();
|
|
1986
|
+
cellHeight_1 = _this.getCellHeight(true); // force pixels for calculations
|
|
1987
|
+
_this._onStartMoving(el, event, ui, node, cellWidth_1, cellHeight_1);
|
|
1988
|
+
};
|
|
1989
|
+
/** called when item is being dragged/resized */
|
|
1990
|
+
var dragOrResize = function (event, ui) {
|
|
1991
|
+
_this._dragOrResize(el, event, ui, node, cellWidth_1, cellHeight_1);
|
|
1992
|
+
};
|
|
1993
|
+
/** called when the item stops moving/resizing */
|
|
1994
|
+
var onEndMoving = function (event) {
|
|
1995
|
+
_this.placeholder.remove();
|
|
1996
|
+
delete node._moving;
|
|
1997
|
+
delete node._event;
|
|
1998
|
+
delete node._lastTried;
|
|
1999
|
+
// if the item has moved to another grid, we're done here
|
|
2000
|
+
var target = event.target;
|
|
2001
|
+
if (!target.gridstackNode || target.gridstackNode.grid !== _this)
|
|
2002
|
+
return;
|
|
2003
|
+
node.el = target;
|
|
2004
|
+
if (node._isAboutToRemove) {
|
|
2005
|
+
var gridToNotify = el.gridstackNode.grid;
|
|
2006
|
+
if (gridToNotify._gsEventHandler[event.type]) {
|
|
2007
|
+
gridToNotify._gsEventHandler[event.type](event, target);
|
|
2008
|
+
}
|
|
2009
|
+
_this._removeDD(el);
|
|
2010
|
+
gridToNotify.engine.removedNodes.push(node);
|
|
2011
|
+
gridToNotify._triggerRemoveEvent();
|
|
2012
|
+
// break circular links and remove DOM
|
|
2013
|
+
delete el.gridstackNode;
|
|
2014
|
+
delete node.el;
|
|
2015
|
+
el.remove();
|
|
2016
|
+
}
|
|
2017
|
+
else {
|
|
2018
|
+
utils_1.Utils.removePositioningStyles(target);
|
|
2019
|
+
if (node._temporaryRemoved) {
|
|
2020
|
+
// got removed - restore item back to before dragging position
|
|
2021
|
+
utils_1.Utils.copyPos(node, node._orig); // @ts-ignore
|
|
2022
|
+
_this._writePosAttr(target, node);
|
|
2023
|
+
_this.engine.addNode(node);
|
|
2024
|
+
}
|
|
2025
|
+
else {
|
|
2026
|
+
// move to new placeholder location
|
|
2027
|
+
_this._writePosAttr(target, node);
|
|
2028
|
+
}
|
|
2029
|
+
if (_this._gsEventHandler[event.type]) {
|
|
2030
|
+
_this._gsEventHandler[event.type](event, target);
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
// @ts-ignore
|
|
2034
|
+
_this._extraDragRow = 0; // @ts-ignore
|
|
2035
|
+
_this._updateContainerHeight(); // @ts-ignore
|
|
2036
|
+
_this._triggerChangeEvent();
|
|
2037
|
+
_this.engine.endUpdate();
|
|
2038
|
+
};
|
|
2039
|
+
dd.draggable(el, {
|
|
2040
|
+
start: onStartMoving,
|
|
2041
|
+
stop: onEndMoving,
|
|
2042
|
+
drag: dragOrResize
|
|
2043
|
+
}).resizable(el, {
|
|
2044
|
+
start: onStartMoving,
|
|
2045
|
+
stop: onEndMoving,
|
|
2046
|
+
resize: dragOrResize
|
|
2047
|
+
});
|
|
2048
|
+
node._initDD = true; // we've set DD support now
|
|
2049
|
+
}
|
|
2050
|
+
// finally fine tune move vs resize by disabling any part...
|
|
2051
|
+
dd.draggable(el, noMove ? 'disable' : 'enable')
|
|
2052
|
+
.resizable(el, noResize ? 'disable' : 'enable');
|
|
2053
|
+
return this;
|
|
2054
|
+
};
|
|
1590
2055
|
/** @internal handles actual drag/resize start **/
|
|
1591
|
-
GridStack.prototype._onStartMoving = function (el, event, ui, node, cellWidth, cellHeight) {
|
|
2056
|
+
GridStack.prototype._onStartMoving = function (el, event, ui, node, cellWidth, cellHeight) {
|
|
2057
|
+
this.engine.cleanNodes()
|
|
2058
|
+
.beginUpdate(node);
|
|
2059
|
+
// @ts-ignore
|
|
2060
|
+
this._writePosAttr(this.placeholder, node);
|
|
2061
|
+
this.el.appendChild(this.placeholder);
|
|
2062
|
+
// console.log('_onStartMoving placeholder') // TEST
|
|
2063
|
+
node.el = this.placeholder;
|
|
2064
|
+
node._lastUiPosition = ui.position;
|
|
2065
|
+
node._prevYPix = ui.position.top;
|
|
2066
|
+
node._moving = (event.type === 'dragstart'); // 'dropover' are not initially moving so they can go exactly where they enter (will push stuff out of the way)
|
|
2067
|
+
delete node._lastTried;
|
|
2068
|
+
if (event.type === 'dropover' && node._temporaryRemoved) {
|
|
2069
|
+
// console.log('engine.addNode x=' + node.x); // TEST
|
|
2070
|
+
this.engine.addNode(node); // will add, fix collisions, update attr and clear _temporaryRemoved
|
|
2071
|
+
node._moving = true; // AFTER, mark as moving object (wanted fix location before)
|
|
2072
|
+
}
|
|
2073
|
+
// set the min/max resize info
|
|
2074
|
+
this.engine.cacheRects(cellWidth, cellHeight, this.opts.marginTop, this.opts.marginRight, this.opts.marginBottom, this.opts.marginLeft);
|
|
2075
|
+
if (event.type === 'resizestart') {
|
|
2076
|
+
dd.resizable(el, 'option', 'minWidth', cellWidth * (node.minW || 1))
|
|
2077
|
+
.resizable(el, 'option', 'minHeight', cellHeight * (node.minH || 1));
|
|
2078
|
+
if (node.maxW) {
|
|
2079
|
+
dd.resizable(el, 'option', 'maxWidth', cellWidth * node.maxW);
|
|
2080
|
+
}
|
|
2081
|
+
if (node.maxH) {
|
|
2082
|
+
dd.resizable(el, 'option', 'maxHeight', cellHeight * node.maxH);
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
};
|
|
1592
2086
|
/** @internal handles actual drag/resize **/
|
|
1593
|
-
GridStack.prototype._dragOrResize = function (el, event, ui, node, cellWidth, cellHeight) {
|
|
1594
|
-
|
|
1595
|
-
|
|
2087
|
+
GridStack.prototype._dragOrResize = function (el, event, ui, node, cellWidth, cellHeight) {
|
|
2088
|
+
var p = __assign({}, node._orig); // could be undefined (_isExternal) which is ok (drag only set x,y and w,h will default to node value)
|
|
2089
|
+
var resizing;
|
|
2090
|
+
var mLeft = this.opts.marginLeft, mRight = this.opts.marginRight, mTop = this.opts.marginTop, mBottom = this.opts.marginBottom;
|
|
2091
|
+
// if margins (which are used to pass mid point by) are large relative to cell height/width, reduce them down #1855
|
|
2092
|
+
var mHeight = Math.round(cellHeight * 0.1), mWidth = Math.round(cellWidth * 0.1);
|
|
2093
|
+
mLeft = Math.min(mLeft, mWidth);
|
|
2094
|
+
mRight = Math.min(mRight, mWidth);
|
|
2095
|
+
mTop = Math.min(mTop, mHeight);
|
|
2096
|
+
mBottom = Math.min(mBottom, mHeight);
|
|
2097
|
+
if (event.type === 'drag') {
|
|
2098
|
+
if (node._temporaryRemoved)
|
|
2099
|
+
return; // handled by dropover
|
|
2100
|
+
var distance = ui.position.top - node._prevYPix;
|
|
2101
|
+
node._prevYPix = ui.position.top;
|
|
2102
|
+
utils_1.Utils.updateScrollPosition(el, ui.position, distance);
|
|
2103
|
+
// get new position taking into account the margin in the direction we are moving! (need to pass mid point by margin)
|
|
2104
|
+
var left = ui.position.left + (ui.position.left > node._lastUiPosition.left ? -mRight : mLeft);
|
|
2105
|
+
var top_2 = ui.position.top + (ui.position.top > node._lastUiPosition.top ? -mBottom : mTop);
|
|
2106
|
+
p.x = Math.round(left / cellWidth);
|
|
2107
|
+
p.y = Math.round(top_2 / cellHeight);
|
|
2108
|
+
// @ts-ignore// if we're at the bottom hitting something else, grow the grid so cursor doesn't leave when trying to place below others
|
|
2109
|
+
var prev = this._extraDragRow;
|
|
2110
|
+
if (this.engine.collide(node, p)) {
|
|
2111
|
+
var row = this.getRow();
|
|
2112
|
+
var extra = Math.max(0, (p.y + node.h) - row);
|
|
2113
|
+
if (this.opts.maxRow && row + extra > this.opts.maxRow) {
|
|
2114
|
+
extra = Math.max(0, this.opts.maxRow - row);
|
|
2115
|
+
} // @ts-ignore
|
|
2116
|
+
this._extraDragRow = extra; // @ts-ignore
|
|
2117
|
+
}
|
|
2118
|
+
else
|
|
2119
|
+
this._extraDragRow = 0; // @ts-ignore
|
|
2120
|
+
if (this._extraDragRow !== prev)
|
|
2121
|
+
this._updateContainerHeight();
|
|
2122
|
+
if (node.x === p.x && node.y === p.y)
|
|
2123
|
+
return; // skip same
|
|
2124
|
+
// DON'T skip one we tried as we might have failed because of coverage <50% before
|
|
2125
|
+
// if (node._lastTried && node._lastTried.x === x && node._lastTried.y === y) return;
|
|
2126
|
+
}
|
|
2127
|
+
else if (event.type === 'resize') {
|
|
2128
|
+
if (p.x < 0)
|
|
2129
|
+
return;
|
|
2130
|
+
// Scrolling page if needed
|
|
2131
|
+
utils_1.Utils.updateScrollResize(event, el, cellHeight);
|
|
2132
|
+
// get new size
|
|
2133
|
+
p.w = Math.round((ui.size.width - mLeft) / cellWidth);
|
|
2134
|
+
p.h = Math.round((ui.size.height - mTop) / cellHeight);
|
|
2135
|
+
if (node.w === p.w && node.h === p.h)
|
|
2136
|
+
return;
|
|
2137
|
+
if (node._lastTried && node._lastTried.w === p.w && node._lastTried.h === p.h)
|
|
2138
|
+
return; // skip one we tried (but failed)
|
|
2139
|
+
// if we size on left/top side this might move us, so get possible new position as well
|
|
2140
|
+
var left = ui.position.left + mLeft;
|
|
2141
|
+
var top_3 = ui.position.top + mTop;
|
|
2142
|
+
p.x = Math.round(left / cellWidth);
|
|
2143
|
+
p.y = Math.round(top_3 / cellHeight);
|
|
2144
|
+
resizing = true;
|
|
2145
|
+
}
|
|
2146
|
+
node._event = event;
|
|
2147
|
+
node._lastTried = p; // set as last tried (will nuke if we go there)
|
|
2148
|
+
var rect = {
|
|
2149
|
+
x: ui.position.left + mLeft,
|
|
2150
|
+
y: ui.position.top + mTop,
|
|
2151
|
+
w: (ui.size ? ui.size.width : node.w * cellWidth) - mLeft - mRight,
|
|
2152
|
+
h: (ui.size ? ui.size.height : node.h * cellHeight) - mTop - mBottom
|
|
2153
|
+
};
|
|
2154
|
+
if (this.engine.moveNodeCheck(node, __assign(__assign({}, p), { cellWidth: cellWidth, cellHeight: cellHeight, rect: rect, resizing: resizing }))) {
|
|
2155
|
+
node._lastUiPosition = ui.position;
|
|
2156
|
+
this.engine.cacheRects(cellWidth, cellHeight, mTop, mRight, mBottom, mLeft);
|
|
2157
|
+
delete node._skipDown;
|
|
2158
|
+
if (resizing && node.subGrid) {
|
|
2159
|
+
node.subGrid.onParentResize();
|
|
2160
|
+
} // @ts-ignore
|
|
2161
|
+
this._extraDragRow = 0; // @ts-ignore
|
|
2162
|
+
this._updateContainerHeight();
|
|
2163
|
+
var target = event.target; // @ts-ignore
|
|
2164
|
+
this._writePosAttr(target, node);
|
|
2165
|
+
if (this._gsEventHandler[event.type]) {
|
|
2166
|
+
this._gsEventHandler[event.type](event, target);
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2170
|
+
/** @internal called when item leaving our area by either cursor dropout event
|
|
2171
|
+
* or shape is outside our boundaries. remove it from us, and mark temporary if this was
|
|
2172
|
+
* our item to start with else restore prev node values from prev grid it came from.
|
|
2173
|
+
**/
|
|
2174
|
+
GridStack.prototype._leave = function (el, helper) {
|
|
2175
|
+
var node = el.gridstackNode;
|
|
2176
|
+
if (!node)
|
|
2177
|
+
return;
|
|
2178
|
+
dd.off(el, 'drag'); // no need to track while being outside
|
|
2179
|
+
// this gets called when cursor leaves and shape is outside, so only do this once
|
|
2180
|
+
if (node._temporaryRemoved)
|
|
2181
|
+
return;
|
|
2182
|
+
node._temporaryRemoved = true;
|
|
2183
|
+
this.engine.removeNode(node); // remove placeholder as well, otherwise it's a sign node is not in our list, which is a bigger issue
|
|
2184
|
+
node.el = node._isExternal && helper ? helper : el; // point back to real item being dragged
|
|
2185
|
+
if (this.opts.removable === true) { // boolean vs a class string
|
|
2186
|
+
// item leaving us and we are supposed to remove on leave (no need to drag onto trash) mark it so
|
|
2187
|
+
this._itemRemoving(el, true);
|
|
2188
|
+
}
|
|
2189
|
+
// finally if item originally came from another grid, but left us, restore things back to prev info
|
|
2190
|
+
if (el._gridstackNodeOrig) {
|
|
2191
|
+
// console.log('leave delete _gridstackNodeOrig') // TEST
|
|
2192
|
+
el.gridstackNode = el._gridstackNodeOrig;
|
|
2193
|
+
delete el._gridstackNodeOrig;
|
|
2194
|
+
}
|
|
2195
|
+
else if (node._isExternal) {
|
|
2196
|
+
// item came from outside (like a toolbar) so nuke any node info
|
|
2197
|
+
delete node.el;
|
|
2198
|
+
delete el.gridstackNode;
|
|
2199
|
+
// and restore all nodes back to original
|
|
2200
|
+
this.engine.restoreInitial();
|
|
2201
|
+
}
|
|
2202
|
+
};
|
|
1596
2203
|
// legacy method removed
|
|
1597
2204
|
GridStack.prototype.commit = function () { utils_1.obsolete(this, this.batchUpdate(false), 'commit', 'batchUpdate', '5.2'); return this; };
|
|
1598
2205
|
/** scoping so users can call GridStack.Utils.sort() for example */
|
|
1599
2206
|
GridStack.Utils = utils_1.Utils;
|
|
1600
2207
|
/** scoping so users can call new GridStack.Engine(12) for example */
|
|
1601
2208
|
GridStack.Engine = gridstack_engine_1.GridStackEngine;
|
|
1602
|
-
GridStack.GDRev = '7.1.
|
|
2209
|
+
GridStack.GDRev = '7.1.2';
|
|
1603
2210
|
return GridStack;
|
|
1604
2211
|
}());
|
|
1605
2212
|
exports.GridStack = GridStack;
|
|
1606
|
-
var dd_touch_1 = require("./dd-touch");
|
|
1607
|
-
var dd_manager_1 = require("./dd-manager");
|
|
1608
|
-
__exportStar(require("./dd-gridstack"), exports);
|
|
1609
2213
|
//# sourceMappingURL=gridstack.js.map
|