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