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/gridstack.js
CHANGED
|
@@ -12,7 +12,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.GridStack = void 0;
|
|
14
14
|
/*!
|
|
15
|
-
* GridStack 7.
|
|
15
|
+
* GridStack 7.2.0
|
|
16
16
|
* https://gridstackjs.com/
|
|
17
17
|
*
|
|
18
18
|
* Copyright (c) 2021-2022 Alain Dumesny
|
|
@@ -21,10 +21,22 @@ exports.GridStack = void 0;
|
|
|
21
21
|
const gridstack_engine_1 = require("./gridstack-engine");
|
|
22
22
|
const utils_1 = require("./utils");
|
|
23
23
|
const types_1 = require("./types");
|
|
24
|
+
/*
|
|
25
|
+
* and include D&D by default
|
|
26
|
+
* TODO: while we could generate a gridstack-static.js at smaller size - saves about 31k (41k -> 72k)
|
|
27
|
+
* I don't know how to generate the DD only code at the remaining 31k to delay load as code depends on Gridstack.ts
|
|
28
|
+
* also it caused loading issues in prod - see https://github.com/gridstack/gridstack.js/issues/2039
|
|
29
|
+
*/
|
|
30
|
+
const dd_gridstack_1 = require("./dd-gridstack");
|
|
31
|
+
const dd_touch_1 = require("./dd-touch");
|
|
32
|
+
const dd_manager_1 = require("./dd-manager");
|
|
33
|
+
/** global instance */
|
|
34
|
+
const dd = new dd_gridstack_1.DDGridStack;
|
|
24
35
|
// export all dependent file as well to make it easier for users to just import the main file
|
|
25
36
|
__exportStar(require("./types"), exports);
|
|
26
37
|
__exportStar(require("./utils"), exports);
|
|
27
38
|
__exportStar(require("./gridstack-engine"), exports);
|
|
39
|
+
__exportStar(require("./dd-gridstack"), exports);
|
|
28
40
|
/**
|
|
29
41
|
* Main gridstack class - you will need to call `GridStack.init()` first to initialize your grid.
|
|
30
42
|
* Note: your grid elements MUST have the following classes for the CSS layout to work:
|
|
@@ -49,6 +61,9 @@ class GridStack {
|
|
|
49
61
|
this._extraDragRow = 0;
|
|
50
62
|
this.el = el; // exposed HTML element to the user
|
|
51
63
|
opts = opts || {}; // handles null/undefined/0
|
|
64
|
+
if (!el.classList.contains('grid-stack')) {
|
|
65
|
+
this.el.classList.add('grid-stack');
|
|
66
|
+
}
|
|
52
67
|
// if row property exists, replace minRow and maxRow instead
|
|
53
68
|
if (opts.row) {
|
|
54
69
|
opts.minRow = opts.maxRow = opts.row;
|
|
@@ -163,6 +178,13 @@ class GridStack {
|
|
|
163
178
|
elements.sort((a, b) => b.i - a.i).forEach(e => this._prepareElement(e.el)); // revert sort so lowest item wins
|
|
164
179
|
this.batchUpdate(false);
|
|
165
180
|
}
|
|
181
|
+
// load any passed in children as well, which overrides any DOM layout done above
|
|
182
|
+
if (this.opts.children) {
|
|
183
|
+
let children = this.opts.children;
|
|
184
|
+
delete this.opts.children;
|
|
185
|
+
if (children.length)
|
|
186
|
+
this.load(children); // don't load empty
|
|
187
|
+
}
|
|
166
188
|
this.setAnimation(this.opts.animate);
|
|
167
189
|
this._updateStyles();
|
|
168
190
|
if (this.opts.column != 12) {
|
|
@@ -257,11 +279,6 @@ class GridStack {
|
|
|
257
279
|
}
|
|
258
280
|
// create grid class and load any children
|
|
259
281
|
let grid = GridStack.init(opt, el);
|
|
260
|
-
if (grid.opts.children) {
|
|
261
|
-
let children = grid.opts.children;
|
|
262
|
-
delete grid.opts.children;
|
|
263
|
-
grid.load(children);
|
|
264
|
-
}
|
|
265
282
|
return grid;
|
|
266
283
|
}
|
|
267
284
|
/** call this method to register your engine instead of the default one.
|
|
@@ -305,28 +322,39 @@ class GridStack {
|
|
|
305
322
|
return w.x !== undefined || w.y !== undefined || w.w !== undefined || w.h !== undefined || w.content !== undefined ? true : false;
|
|
306
323
|
}
|
|
307
324
|
let el;
|
|
325
|
+
let node;
|
|
308
326
|
if (typeof els === 'string') {
|
|
309
327
|
let doc = document.implementation.createHTMLDocument(''); // IE needs a param
|
|
310
328
|
doc.body.innerHTML = els;
|
|
311
329
|
el = doc.body.children[0];
|
|
312
330
|
}
|
|
313
331
|
else if (arguments.length === 0 || arguments.length === 1 && isGridStackWidget(els)) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
332
|
+
node = options = els;
|
|
333
|
+
if (node === null || node === void 0 ? void 0 : node.el) {
|
|
334
|
+
el = node.el; // re-use element stored in the node
|
|
335
|
+
}
|
|
336
|
+
else if (this.opts.addRemoveCB) {
|
|
337
|
+
el = this.opts.addRemoveCB(this, options, true);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
let content = (options === null || options === void 0 ? void 0 : options.content) || '';
|
|
341
|
+
let doc = document.implementation.createHTMLDocument(''); // IE needs a param
|
|
342
|
+
doc.body.innerHTML = `<div class="grid-stack-item ${this.opts.itemClass || ''}"><div class="grid-stack-item-content">${content}</div></div>`;
|
|
343
|
+
el = doc.body.children[0];
|
|
344
|
+
}
|
|
319
345
|
}
|
|
320
346
|
else {
|
|
321
347
|
el = els;
|
|
322
348
|
}
|
|
349
|
+
if (!el)
|
|
350
|
+
return;
|
|
323
351
|
// Tempting to initialize the passed in opt with default and valid values, but this break knockout demos
|
|
324
|
-
// as the actual value are filled in when _prepareElement() calls el.getAttribute('gs-xyz) before adding the node.
|
|
352
|
+
// as the actual value are filled in when _prepareElement() calls el.getAttribute('gs-xyz') before adding the node.
|
|
325
353
|
// So make sure we load any DOM attributes that are not specified in passed in options (which override)
|
|
326
354
|
let domAttr = this._readAttr(el);
|
|
327
355
|
options = utils_1.Utils.cloneDeep(options) || {}; // make a copy before we modify in case caller re-uses it
|
|
328
356
|
utils_1.Utils.defaults(options, domAttr);
|
|
329
|
-
|
|
357
|
+
node = this.engine.prepareNode(options);
|
|
330
358
|
this._writeAttr(el, options);
|
|
331
359
|
if (this._insertNotAppend) {
|
|
332
360
|
this.el.prepend(el);
|
|
@@ -378,6 +406,7 @@ class GridStack {
|
|
|
378
406
|
ops.disableOneColumnMode = true; // driven by parent
|
|
379
407
|
}
|
|
380
408
|
// if we're converting an existing full item, move over the content to be the first sub item in the new grid
|
|
409
|
+
// TODO: support this.opts.addRemoveCB for frameworks
|
|
381
410
|
let content = node.el.querySelector('.grid-stack-item-content');
|
|
382
411
|
let newItem;
|
|
383
412
|
let newItemOpt;
|
|
@@ -529,7 +558,7 @@ class GridStack {
|
|
|
529
558
|
* @example
|
|
530
559
|
* see http://gridstackjs.com/demo/serialization.html
|
|
531
560
|
**/
|
|
532
|
-
load(layout,
|
|
561
|
+
load(layout, addRemove = this.opts.addRemoveCB || true) {
|
|
533
562
|
let items = GridStack.Utils.sort([...layout], -1, this._prevColumn || this.getColumn()); // make copy before we mod/sort
|
|
534
563
|
this._insertNotAppend = true; // since create in reverse order...
|
|
535
564
|
// 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
|
|
@@ -538,21 +567,22 @@ class GridStack {
|
|
|
538
567
|
this._ignoreLayoutsNodeChange = true; // skip layout update
|
|
539
568
|
this.engine.cacheLayout(items, this._prevColumn, true);
|
|
540
569
|
}
|
|
570
|
+
// if given a different callback, temporally set it as global option to creating will use it
|
|
571
|
+
const prevCB = this.opts.addRemoveCB;
|
|
572
|
+
if (typeof (addRemove) === 'function')
|
|
573
|
+
this.opts.addRemoveCB = addRemove;
|
|
541
574
|
let removed = [];
|
|
542
575
|
this.batchUpdate();
|
|
543
576
|
// see if any items are missing from new layout and need to be removed first
|
|
544
|
-
if (
|
|
577
|
+
if (addRemove) {
|
|
545
578
|
let copyNodes = [...this.engine.nodes]; // don't loop through array you modify
|
|
546
579
|
copyNodes.forEach(n => {
|
|
547
580
|
let item = items.find(w => n.id === w.id);
|
|
548
581
|
if (!item) {
|
|
549
|
-
if (
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
removed.push(n); // batch keep track
|
|
554
|
-
this.removeWidget(n.el, true, false);
|
|
555
|
-
}
|
|
582
|
+
if (this.opts.addRemoveCB)
|
|
583
|
+
this.opts.addRemoveCB(this, n, false);
|
|
584
|
+
removed.push(n); // batch keep track
|
|
585
|
+
this.removeWidget(n.el, true, false);
|
|
556
586
|
}
|
|
557
587
|
});
|
|
558
588
|
}
|
|
@@ -569,13 +599,8 @@ class GridStack {
|
|
|
569
599
|
}
|
|
570
600
|
}
|
|
571
601
|
}
|
|
572
|
-
else if (
|
|
573
|
-
|
|
574
|
-
w = addAndRemove(this, w, true).gridstackNode;
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
w = this.addWidget(w).gridstackNode;
|
|
578
|
-
}
|
|
602
|
+
else if (addRemove) {
|
|
603
|
+
this.addWidget(w);
|
|
579
604
|
}
|
|
580
605
|
});
|
|
581
606
|
this.engine.removedNodes = removed;
|
|
@@ -583,6 +608,7 @@ class GridStack {
|
|
|
583
608
|
// after commit, clear that flag
|
|
584
609
|
delete this._ignoreLayoutsNodeChange;
|
|
585
610
|
delete this._insertNotAppend;
|
|
611
|
+
prevCB ? this.opts.addRemoveCB = prevCB : delete this.opts.addRemoveCB;
|
|
586
612
|
return this;
|
|
587
613
|
}
|
|
588
614
|
/**
|
|
@@ -960,14 +986,20 @@ class GridStack {
|
|
|
960
986
|
* Toggle the grid static state, which permanently removes/add Drag&Drop support, unlike disable()/enable() that just turns it off/on.
|
|
961
987
|
* Also toggle the grid-stack-static class.
|
|
962
988
|
* @param val if true the grid become static.
|
|
989
|
+
* @param updateClass true (default) if css class gets updated
|
|
990
|
+
* @param recurse true (default) if sub-grids also get updated
|
|
963
991
|
*/
|
|
964
|
-
setStatic(val, updateClass = true) {
|
|
992
|
+
setStatic(val, updateClass = true, recurse = true) {
|
|
965
993
|
if (this.opts.staticGrid === val)
|
|
966
994
|
return this;
|
|
967
995
|
this.opts.staticGrid = val;
|
|
968
996
|
this._setupRemoveDrop();
|
|
969
997
|
this._setupAcceptWidget();
|
|
970
|
-
this.engine.nodes.forEach(n =>
|
|
998
|
+
this.engine.nodes.forEach(n => {
|
|
999
|
+
this._prepareDragDropByNode(n); // either delete or init Drag&drop
|
|
1000
|
+
if (n.subGrid && recurse)
|
|
1001
|
+
n.subGrid.setStatic(val, updateClass, recurse);
|
|
1002
|
+
});
|
|
971
1003
|
if (updateClass) {
|
|
972
1004
|
this._setStaticClass();
|
|
973
1005
|
}
|
|
@@ -1226,10 +1258,8 @@ class GridStack {
|
|
|
1226
1258
|
}
|
|
1227
1259
|
/** @internal */
|
|
1228
1260
|
_prepareElement(el, triggerAddEvent = false, node) {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
node = this._readAttr(el);
|
|
1232
|
-
}
|
|
1261
|
+
el.classList.add(this.opts.itemClass);
|
|
1262
|
+
node = node || this._readAttr(el);
|
|
1233
1263
|
el.gridstackNode = node;
|
|
1234
1264
|
node.el = el;
|
|
1235
1265
|
node.grid = this;
|
|
@@ -1273,7 +1303,6 @@ class GridStack {
|
|
|
1273
1303
|
noMove: 'gs-no-move',
|
|
1274
1304
|
locked: 'gs-locked',
|
|
1275
1305
|
id: 'gs-id',
|
|
1276
|
-
resizeHandles: 'gs-resize-handles'
|
|
1277
1306
|
};
|
|
1278
1307
|
for (const key in attrs) {
|
|
1279
1308
|
if (node[key]) { // 0 is valid for x,y only but done above already and not in list anyway
|
|
@@ -1300,7 +1329,6 @@ class GridStack {
|
|
|
1300
1329
|
node.noResize = utils_1.Utils.toBool(el.getAttribute('gs-no-resize'));
|
|
1301
1330
|
node.noMove = utils_1.Utils.toBool(el.getAttribute('gs-no-move'));
|
|
1302
1331
|
node.locked = utils_1.Utils.toBool(el.getAttribute('gs-locked'));
|
|
1303
|
-
node.resizeHandles = el.getAttribute('gs-resize-handles');
|
|
1304
1332
|
node.id = el.getAttribute('gs-id');
|
|
1305
1333
|
// remove any key not found (null or false which is default)
|
|
1306
1334
|
for (const key in node) {
|
|
@@ -1460,14 +1488,15 @@ class GridStack {
|
|
|
1460
1488
|
}
|
|
1461
1489
|
return this;
|
|
1462
1490
|
}
|
|
1463
|
-
/*
|
|
1464
|
-
* drag&drop
|
|
1465
|
-
*
|
|
1466
|
-
*
|
|
1467
|
-
* GridStack.prototype._setupAcceptWidget = function()
|
|
1468
|
-
* maybe there is a better way ????
|
|
1491
|
+
/* ===========================================================================================
|
|
1492
|
+
* drag&drop methods that used to be stubbed out and implemented in dd-gridstack.ts
|
|
1493
|
+
* but caused loading issues in prod - see https://github.com/gridstack/gridstack.js/issues/2039
|
|
1494
|
+
* ===========================================================================================
|
|
1469
1495
|
*/
|
|
1470
|
-
|
|
1496
|
+
/** get the global (but static to this code) DD implementation */
|
|
1497
|
+
static getDD() {
|
|
1498
|
+
return dd;
|
|
1499
|
+
}
|
|
1471
1500
|
/**
|
|
1472
1501
|
* call to setup dragging in from the outside (say toolbar), by specifying the class selection and options.
|
|
1473
1502
|
* Called during GridStack.init() as options, but can also be called directly (last param are used) in case the toolbar
|
|
@@ -1475,20 +1504,59 @@ class GridStack {
|
|
|
1475
1504
|
* @param dragIn string selector (ex: '.sidebar .grid-stack-item')
|
|
1476
1505
|
* @param dragInOptions options - see DDDragInOpt. (default: {handle: '.grid-stack-item-content', appendTo: 'body'}
|
|
1477
1506
|
**/
|
|
1478
|
-
static setupDragIn(dragIn, dragInOptions) {
|
|
1507
|
+
static setupDragIn(dragIn, dragInOptions) {
|
|
1508
|
+
if ((dragInOptions === null || dragInOptions === void 0 ? void 0 : dragInOptions.pause) !== undefined) {
|
|
1509
|
+
dd_manager_1.DDManager.pauseDrag = dragInOptions.pause;
|
|
1510
|
+
}
|
|
1511
|
+
if (typeof dragIn === 'string') {
|
|
1512
|
+
dragInOptions = Object.assign(Object.assign({}, types_1.dragInDefaultOptions), (dragInOptions || {}));
|
|
1513
|
+
utils_1.Utils.getElements(dragIn).forEach(el => {
|
|
1514
|
+
if (!dd.isDraggable(el))
|
|
1515
|
+
dd.dragIn(el, dragInOptions);
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1479
1519
|
/**
|
|
1480
1520
|
* 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.
|
|
1481
1521
|
* IF you are looking to prevent an item from moving (due to being pushed around by another during collision) use locked property instead.
|
|
1482
1522
|
* @param els widget or selector to modify.
|
|
1483
1523
|
* @param val if true widget will be draggable.
|
|
1484
1524
|
*/
|
|
1485
|
-
movable(els, val) {
|
|
1525
|
+
movable(els, val) {
|
|
1526
|
+
if (this.opts.staticGrid)
|
|
1527
|
+
return this; // can't move a static grid!
|
|
1528
|
+
GridStack.getElements(els).forEach(el => {
|
|
1529
|
+
let node = el.gridstackNode;
|
|
1530
|
+
if (!node)
|
|
1531
|
+
return;
|
|
1532
|
+
if (val)
|
|
1533
|
+
delete node.noMove;
|
|
1534
|
+
else
|
|
1535
|
+
node.noMove = true;
|
|
1536
|
+
this._prepareDragDropByNode(node); // init DD if need be, and adjust
|
|
1537
|
+
});
|
|
1538
|
+
return this;
|
|
1539
|
+
}
|
|
1486
1540
|
/**
|
|
1487
1541
|
* 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.
|
|
1488
1542
|
* @param els widget or selector to modify
|
|
1489
1543
|
* @param val if true widget will be resizable.
|
|
1490
1544
|
*/
|
|
1491
|
-
resizable(els, val) {
|
|
1545
|
+
resizable(els, val) {
|
|
1546
|
+
if (this.opts.staticGrid)
|
|
1547
|
+
return this; // can't resize a static grid!
|
|
1548
|
+
GridStack.getElements(els).forEach(el => {
|
|
1549
|
+
let node = el.gridstackNode;
|
|
1550
|
+
if (!node)
|
|
1551
|
+
return;
|
|
1552
|
+
if (val)
|
|
1553
|
+
delete node.noResize;
|
|
1554
|
+
else
|
|
1555
|
+
node.noResize = true;
|
|
1556
|
+
this._prepareDragDropByNode(node); // init DD if need be, and adjust
|
|
1557
|
+
});
|
|
1558
|
+
return this;
|
|
1559
|
+
}
|
|
1492
1560
|
/**
|
|
1493
1561
|
* Temporarily disables widgets moving/resizing.
|
|
1494
1562
|
* If you want a more permanent way (which freezes up resources) use `setStatic(true)` instead.
|
|
@@ -1497,8 +1565,16 @@ class GridStack {
|
|
|
1497
1565
|
* @example
|
|
1498
1566
|
* grid.enableMove(false);
|
|
1499
1567
|
* grid.enableResize(false);
|
|
1568
|
+
* @param recurse true (default) if sub-grids also get updated
|
|
1500
1569
|
*/
|
|
1501
|
-
disable() {
|
|
1570
|
+
disable(recurse = true) {
|
|
1571
|
+
if (this.opts.staticGrid)
|
|
1572
|
+
return;
|
|
1573
|
+
this.enableMove(false, recurse);
|
|
1574
|
+
this.enableResize(false, recurse); // @ts-ignore
|
|
1575
|
+
this._triggerEvent('disable');
|
|
1576
|
+
return this;
|
|
1577
|
+
}
|
|
1502
1578
|
/**
|
|
1503
1579
|
* Re-enables widgets moving/resizing - see disable().
|
|
1504
1580
|
* Note: no-op for static grid.
|
|
@@ -1506,30 +1582,552 @@ class GridStack {
|
|
|
1506
1582
|
* @example
|
|
1507
1583
|
* grid.enableMove(true);
|
|
1508
1584
|
* grid.enableResize(true);
|
|
1585
|
+
* @param recurse true (default) if sub-grids also get updated
|
|
1509
1586
|
*/
|
|
1510
|
-
enable() {
|
|
1587
|
+
enable(recurse = true) {
|
|
1588
|
+
if (this.opts.staticGrid)
|
|
1589
|
+
return;
|
|
1590
|
+
this.enableMove(true, recurse);
|
|
1591
|
+
this.enableResize(true, recurse); // @ts-ignore
|
|
1592
|
+
this._triggerEvent('enable');
|
|
1593
|
+
return this;
|
|
1594
|
+
}
|
|
1511
1595
|
/**
|
|
1512
1596
|
* Enables/disables widget moving. No-op for static grids.
|
|
1597
|
+
* @param recurse true (default) if sub-grids also get updated
|
|
1513
1598
|
*/
|
|
1514
|
-
enableMove(doEnable
|
|
1599
|
+
enableMove(doEnable, recurse = true) {
|
|
1600
|
+
if (this.opts.staticGrid)
|
|
1601
|
+
return this; // can't move a static grid!
|
|
1602
|
+
this.opts.disableDrag = !doEnable; // FIRST before we update children as grid overrides #1658
|
|
1603
|
+
this.engine.nodes.forEach(n => {
|
|
1604
|
+
this.movable(n.el, doEnable);
|
|
1605
|
+
if (n.subGrid && recurse)
|
|
1606
|
+
n.subGrid.enableMove(doEnable, recurse);
|
|
1607
|
+
});
|
|
1608
|
+
return this;
|
|
1609
|
+
}
|
|
1515
1610
|
/**
|
|
1516
1611
|
* Enables/disables widget resizing. No-op for static grids.
|
|
1612
|
+
* @param recurse true (default) if sub-grids also get updated
|
|
1517
1613
|
*/
|
|
1518
|
-
enableResize(doEnable
|
|
1614
|
+
enableResize(doEnable, recurse = true) {
|
|
1615
|
+
if (this.opts.staticGrid)
|
|
1616
|
+
return this; // can't size a static grid!
|
|
1617
|
+
this.opts.disableResize = !doEnable; // FIRST before we update children as grid overrides #1658
|
|
1618
|
+
this.engine.nodes.forEach(n => {
|
|
1619
|
+
this.resizable(n.el, doEnable);
|
|
1620
|
+
if (n.subGrid && recurse)
|
|
1621
|
+
n.subGrid.enableResize(doEnable, recurse);
|
|
1622
|
+
});
|
|
1623
|
+
return this;
|
|
1624
|
+
}
|
|
1519
1625
|
/** @internal removes any drag&drop present (called during destroy) */
|
|
1520
|
-
_removeDD(el) {
|
|
1521
|
-
|
|
1522
|
-
|
|
1626
|
+
_removeDD(el) {
|
|
1627
|
+
dd.draggable(el, 'destroy').resizable(el, 'destroy');
|
|
1628
|
+
if (el.gridstackNode) {
|
|
1629
|
+
delete el.gridstackNode._initDD; // reset our DD init flag
|
|
1630
|
+
}
|
|
1631
|
+
delete el.ddElement;
|
|
1632
|
+
return this;
|
|
1633
|
+
}
|
|
1634
|
+
/** @internal called to add drag over to support widgets being added externally */
|
|
1635
|
+
_setupAcceptWidget() {
|
|
1636
|
+
// check if we need to disable things
|
|
1637
|
+
if (this.opts.staticGrid || (!this.opts.acceptWidgets && !this.opts.removable)) {
|
|
1638
|
+
dd.droppable(this.el, 'destroy');
|
|
1639
|
+
return this;
|
|
1640
|
+
}
|
|
1641
|
+
// vars shared across all methods
|
|
1642
|
+
let cellHeight, cellWidth;
|
|
1643
|
+
let onDrag = (event, el, helper) => {
|
|
1644
|
+
let node = el.gridstackNode;
|
|
1645
|
+
if (!node)
|
|
1646
|
+
return;
|
|
1647
|
+
helper = helper || el;
|
|
1648
|
+
let parent = this.el.getBoundingClientRect();
|
|
1649
|
+
let { top, left } = helper.getBoundingClientRect();
|
|
1650
|
+
left -= parent.left;
|
|
1651
|
+
top -= parent.top;
|
|
1652
|
+
let ui = { position: { top, left } };
|
|
1653
|
+
if (node._temporaryRemoved) {
|
|
1654
|
+
node.x = Math.max(0, Math.round(left / cellWidth));
|
|
1655
|
+
node.y = Math.max(0, Math.round(top / cellHeight));
|
|
1656
|
+
delete node.autoPosition;
|
|
1657
|
+
this.engine.nodeBoundFix(node);
|
|
1658
|
+
// 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
|
|
1659
|
+
if (!this.engine.willItFit(node)) {
|
|
1660
|
+
node.autoPosition = true; // ignore x,y and try for any slot...
|
|
1661
|
+
if (!this.engine.willItFit(node)) {
|
|
1662
|
+
dd.off(el, 'drag'); // stop calling us
|
|
1663
|
+
return; // full grid or can't grow
|
|
1664
|
+
}
|
|
1665
|
+
if (node._willFitPos) {
|
|
1666
|
+
// use the auto position instead #1687
|
|
1667
|
+
utils_1.Utils.copyPos(node, node._willFitPos);
|
|
1668
|
+
delete node._willFitPos;
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
// re-use the existing node dragging method
|
|
1672
|
+
this._onStartMoving(helper, event, ui, node, cellWidth, cellHeight);
|
|
1673
|
+
}
|
|
1674
|
+
else {
|
|
1675
|
+
// re-use the existing node dragging that does so much of the collision detection
|
|
1676
|
+
this._dragOrResize(helper, event, ui, node, cellWidth, cellHeight);
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
dd.droppable(this.el, {
|
|
1680
|
+
accept: (el) => {
|
|
1681
|
+
let node = el.gridstackNode;
|
|
1682
|
+
// set accept drop to true on ourself (which we ignore) so we don't get "can't drop" icon in HTML5 mode while moving
|
|
1683
|
+
if ((node === null || node === void 0 ? void 0 : node.grid) === this)
|
|
1684
|
+
return true;
|
|
1685
|
+
if (!this.opts.acceptWidgets)
|
|
1686
|
+
return false;
|
|
1687
|
+
// check for accept method or class matching
|
|
1688
|
+
let canAccept = true;
|
|
1689
|
+
if (typeof this.opts.acceptWidgets === 'function') {
|
|
1690
|
+
canAccept = this.opts.acceptWidgets(el);
|
|
1691
|
+
}
|
|
1692
|
+
else {
|
|
1693
|
+
let selector = (this.opts.acceptWidgets === true ? '.grid-stack-item' : this.opts.acceptWidgets);
|
|
1694
|
+
canAccept = el.matches(selector);
|
|
1695
|
+
}
|
|
1696
|
+
// finally check to make sure we actually have space left #1571
|
|
1697
|
+
if (canAccept && node && this.opts.maxRow) {
|
|
1698
|
+
let n = { w: node.w, h: node.h, minW: node.minW, minH: node.minH }; // only width/height matters and autoPosition
|
|
1699
|
+
canAccept = this.engine.willItFit(n);
|
|
1700
|
+
}
|
|
1701
|
+
return canAccept;
|
|
1702
|
+
}
|
|
1703
|
+
})
|
|
1704
|
+
/**
|
|
1705
|
+
* entering our grid area
|
|
1706
|
+
*/
|
|
1707
|
+
.on(this.el, 'dropover', (event, el, helper) => {
|
|
1708
|
+
// console.log(`over ${this.el.gridstack.opts.id} ${count++}`); // TEST
|
|
1709
|
+
let node = el.gridstackNode;
|
|
1710
|
+
// ignore drop enter on ourself (unless we temporarily removed) which happens on a simple drag of our item
|
|
1711
|
+
if ((node === null || node === void 0 ? void 0 : node.grid) === this && !node._temporaryRemoved) {
|
|
1712
|
+
// delete node._added; // reset this to track placeholder again in case we were over other grid #1484 (dropout doesn't always clear)
|
|
1713
|
+
return false; // prevent parent from receiving msg (which may be a grid as well)
|
|
1714
|
+
}
|
|
1715
|
+
// fix #1578 when dragging fast, we may not get a leave on the previous grid so force one now
|
|
1716
|
+
if ((node === null || node === void 0 ? void 0 : node.grid) && node.grid !== this && !node._temporaryRemoved) {
|
|
1717
|
+
// console.log('dropover without leave'); // TEST
|
|
1718
|
+
let otherGrid = node.grid;
|
|
1719
|
+
otherGrid._leave(el, helper);
|
|
1720
|
+
}
|
|
1721
|
+
// cache cell dimensions (which don't change), position can animate if we removed an item in otherGrid that affects us...
|
|
1722
|
+
cellWidth = this.cellWidth();
|
|
1723
|
+
cellHeight = this.getCellHeight(true);
|
|
1724
|
+
// load any element attributes if we don't have a node
|
|
1725
|
+
if (!node) { // @ts-ignore private read only on ourself
|
|
1726
|
+
node = this._readAttr(el);
|
|
1727
|
+
}
|
|
1728
|
+
if (!node.grid) {
|
|
1729
|
+
node._isExternal = true;
|
|
1730
|
+
el.gridstackNode = node;
|
|
1731
|
+
}
|
|
1732
|
+
// calculate the grid size based on element outer size
|
|
1733
|
+
helper = helper || el;
|
|
1734
|
+
let w = node.w || Math.round(helper.offsetWidth / cellWidth) || 1;
|
|
1735
|
+
let h = node.h || Math.round(helper.offsetHeight / cellHeight) || 1;
|
|
1736
|
+
// if the item came from another grid, make a copy and save the original info in case we go back there
|
|
1737
|
+
if (node.grid && node.grid !== this) {
|
|
1738
|
+
// copy the node original values (min/max/id/etc...) but override width/height/other flags which are this grid specific
|
|
1739
|
+
// console.log('dropover cloning node'); // TEST
|
|
1740
|
+
if (!el._gridstackNodeOrig)
|
|
1741
|
+
el._gridstackNodeOrig = node; // shouldn't have multiple nested!
|
|
1742
|
+
el.gridstackNode = node = Object.assign(Object.assign({}, node), { w, h, grid: this });
|
|
1743
|
+
this.engine.cleanupNode(node)
|
|
1744
|
+
.nodeBoundFix(node);
|
|
1745
|
+
// restore some internal fields we need after clearing them all
|
|
1746
|
+
node._initDD =
|
|
1747
|
+
node._isExternal = // DOM needs to be re-parented on a drop
|
|
1748
|
+
node._temporaryRemoved = true; // so it can be inserted onDrag below
|
|
1749
|
+
}
|
|
1750
|
+
else {
|
|
1751
|
+
node.w = w;
|
|
1752
|
+
node.h = h;
|
|
1753
|
+
node._temporaryRemoved = true; // so we can insert it
|
|
1754
|
+
}
|
|
1755
|
+
// clear any marked for complete removal (Note: don't check _isAboutToRemove as that is cleared above - just do it)
|
|
1756
|
+
this._itemRemoving(node.el, false);
|
|
1757
|
+
dd.on(el, 'drag', onDrag);
|
|
1758
|
+
// make sure this is called at least once when going fast #1578
|
|
1759
|
+
onDrag(event, el, helper);
|
|
1760
|
+
return false; // prevent parent from receiving msg (which may be a grid as well)
|
|
1761
|
+
})
|
|
1762
|
+
/**
|
|
1763
|
+
* Leaving our grid area...
|
|
1764
|
+
*/
|
|
1765
|
+
.on(this.el, 'dropout', (event, el, helper) => {
|
|
1766
|
+
// console.log(`out ${this.el.gridstack.opts.id} ${count++}`); // TEST
|
|
1767
|
+
let node = el.gridstackNode;
|
|
1768
|
+
if (!node)
|
|
1769
|
+
return false;
|
|
1770
|
+
// fix #1578 when dragging fast, we might get leave after other grid gets enter (which calls us to clean)
|
|
1771
|
+
// so skip this one if we're not the active grid really..
|
|
1772
|
+
if (!node.grid || node.grid === this) {
|
|
1773
|
+
this._leave(el, helper);
|
|
1774
|
+
// if we were created as temporary nested grid, go back to before state
|
|
1775
|
+
if (this._isTemp) {
|
|
1776
|
+
this.removeAsSubGrid(node);
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
return false; // prevent parent from receiving msg (which may be grid as well)
|
|
1780
|
+
})
|
|
1781
|
+
/**
|
|
1782
|
+
* end - releasing the mouse
|
|
1783
|
+
*/
|
|
1784
|
+
.on(this.el, 'drop', (event, el, helper) => {
|
|
1785
|
+
var _a, _b;
|
|
1786
|
+
let node = el.gridstackNode;
|
|
1787
|
+
// ignore drop on ourself from ourself that didn't come from the outside - dragend will handle the simple move instead
|
|
1788
|
+
if ((node === null || node === void 0 ? void 0 : node.grid) === this && !node._isExternal)
|
|
1789
|
+
return false;
|
|
1790
|
+
let wasAdded = !!this.placeholder.parentElement; // skip items not actually added to us because of constrains, but do cleanup #1419
|
|
1791
|
+
this.placeholder.remove();
|
|
1792
|
+
// notify previous grid of removal
|
|
1793
|
+
// console.log('drop delete _gridstackNodeOrig') // TEST
|
|
1794
|
+
let origNode = el._gridstackNodeOrig;
|
|
1795
|
+
delete el._gridstackNodeOrig;
|
|
1796
|
+
if (wasAdded && (origNode === null || origNode === void 0 ? void 0 : origNode.grid) && origNode.grid !== this) {
|
|
1797
|
+
let oGrid = origNode.grid;
|
|
1798
|
+
oGrid.engine.removedNodes.push(origNode);
|
|
1799
|
+
oGrid._triggerRemoveEvent();
|
|
1800
|
+
// if it's an empty sub-grid, to get auto-created, nuke it
|
|
1801
|
+
if (oGrid.parentGridItem && !oGrid.engine.nodes.length && oGrid.opts.subGridDynamic) {
|
|
1802
|
+
oGrid.removeAsSubGrid();
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
if (!node)
|
|
1806
|
+
return false;
|
|
1807
|
+
// use existing placeholder node as it's already in our list with drop location
|
|
1808
|
+
if (wasAdded) {
|
|
1809
|
+
this.engine.cleanupNode(node); // removes all internal _xyz values
|
|
1810
|
+
node.grid = this;
|
|
1811
|
+
}
|
|
1812
|
+
dd.off(el, 'drag');
|
|
1813
|
+
// if we made a copy ('helper' which is temp) of the original node then insert a copy, else we move the original node (#1102)
|
|
1814
|
+
// as the helper will be nuked by jquery-ui otherwise
|
|
1815
|
+
if (helper !== el) {
|
|
1816
|
+
helper.remove();
|
|
1817
|
+
el.gridstackNode = origNode; // original item (left behind) is re-stored to pre dragging as the node now has drop info
|
|
1818
|
+
if (wasAdded) {
|
|
1819
|
+
el = el.cloneNode(true);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
else {
|
|
1823
|
+
el.remove(); // reduce flicker as we change depth here, and size further down
|
|
1824
|
+
this._removeDD(el);
|
|
1825
|
+
}
|
|
1826
|
+
if (!wasAdded)
|
|
1827
|
+
return false;
|
|
1828
|
+
el.gridstackNode = node;
|
|
1829
|
+
node.el = el;
|
|
1830
|
+
let 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
|
|
1831
|
+
// @ts-ignore
|
|
1832
|
+
utils_1.Utils.copyPos(node, this._readAttr(this.placeholder)); // placeholder values as moving VERY fast can throw things off #1578
|
|
1833
|
+
utils_1.Utils.removePositioningStyles(el); // @ts-ignore
|
|
1834
|
+
this._writeAttr(el, node);
|
|
1835
|
+
this.el.appendChild(el); // @ts-ignore // TODO: now would be ideal time to _removeHelperStyle() overriding floating styles (native only)
|
|
1836
|
+
if (subGrid) {
|
|
1837
|
+
subGrid.parentGridItem = node;
|
|
1838
|
+
if (!subGrid.opts.styleInHead)
|
|
1839
|
+
subGrid._updateStyles(true); // re-create sub-grid styles now that we've moved
|
|
1840
|
+
}
|
|
1841
|
+
this._updateContainerHeight();
|
|
1842
|
+
this.engine.addedNodes.push(node); // @ts-ignore
|
|
1843
|
+
this._triggerAddEvent(); // @ts-ignore
|
|
1844
|
+
this._triggerChangeEvent();
|
|
1845
|
+
this.engine.endUpdate();
|
|
1846
|
+
if (this._gsEventHandler['dropped']) {
|
|
1847
|
+
this._gsEventHandler['dropped'](Object.assign(Object.assign({}, event), { type: 'dropped' }), origNode && origNode.grid ? origNode : undefined, node);
|
|
1848
|
+
}
|
|
1849
|
+
// wait till we return out of the drag callback to set the new drag&resize handler or they may get messed up
|
|
1850
|
+
window.setTimeout(() => {
|
|
1851
|
+
// IFF we are still there (some application will use as placeholder and insert their real widget instead and better call makeWidget())
|
|
1852
|
+
if (node.el && node.el.parentElement) {
|
|
1853
|
+
this._prepareDragDropByNode(node);
|
|
1854
|
+
}
|
|
1855
|
+
else {
|
|
1856
|
+
this.engine.removeNode(node);
|
|
1857
|
+
}
|
|
1858
|
+
delete node.grid._isTemp;
|
|
1859
|
+
});
|
|
1860
|
+
return false; // prevent parent from receiving msg (which may be grid as well)
|
|
1861
|
+
});
|
|
1862
|
+
return this;
|
|
1863
|
+
}
|
|
1864
|
+
/** @internal mark item for removal */
|
|
1865
|
+
_itemRemoving(el, remove) {
|
|
1866
|
+
let node = el ? el.gridstackNode : undefined;
|
|
1867
|
+
if (!node || !node.grid)
|
|
1868
|
+
return;
|
|
1869
|
+
remove ? node._isAboutToRemove = true : delete node._isAboutToRemove;
|
|
1870
|
+
remove ? el.classList.add('grid-stack-item-removing') : el.classList.remove('grid-stack-item-removing');
|
|
1871
|
+
}
|
|
1523
1872
|
/** @internal called to setup a trash drop zone if the user specifies it */
|
|
1524
|
-
_setupRemoveDrop() {
|
|
1873
|
+
_setupRemoveDrop() {
|
|
1874
|
+
if (!this.opts.staticGrid && typeof this.opts.removable === 'string') {
|
|
1875
|
+
let trashEl = document.querySelector(this.opts.removable);
|
|
1876
|
+
if (!trashEl)
|
|
1877
|
+
return this;
|
|
1878
|
+
// only register ONE drop-over/dropout callback for the 'trash', and it will
|
|
1879
|
+
// update the passed in item and parent grid because the 'trash' is a shared resource anyway,
|
|
1880
|
+
// and Native DD only has 1 event CB (having a list and technically a per grid removableOptions complicates things greatly)
|
|
1881
|
+
if (!dd.isDroppable(trashEl)) {
|
|
1882
|
+
dd.droppable(trashEl, this.opts.removableOptions)
|
|
1883
|
+
.on(trashEl, 'dropover', (event, el) => this._itemRemoving(el, true))
|
|
1884
|
+
.on(trashEl, 'dropout', (event, el) => this._itemRemoving(el, false));
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
return this;
|
|
1888
|
+
}
|
|
1525
1889
|
/** @internal prepares the element for drag&drop **/
|
|
1526
|
-
_prepareDragDropByNode(node) {
|
|
1890
|
+
_prepareDragDropByNode(node) {
|
|
1891
|
+
let el = node.el;
|
|
1892
|
+
const noMove = node.noMove || this.opts.disableDrag;
|
|
1893
|
+
const noResize = node.noResize || this.opts.disableResize;
|
|
1894
|
+
// check for disabled grid first
|
|
1895
|
+
if (this.opts.staticGrid || (noMove && noResize)) {
|
|
1896
|
+
if (node._initDD) {
|
|
1897
|
+
this._removeDD(el); // nukes everything instead of just disable, will add some styles back next
|
|
1898
|
+
delete node._initDD;
|
|
1899
|
+
}
|
|
1900
|
+
el.classList.add('ui-draggable-disabled', 'ui-resizable-disabled'); // add styles one might depend on #1435
|
|
1901
|
+
return this;
|
|
1902
|
+
}
|
|
1903
|
+
if (!node._initDD) {
|
|
1904
|
+
// variables used/cashed between the 3 start/move/end methods, in addition to node passed above
|
|
1905
|
+
let cellWidth;
|
|
1906
|
+
let cellHeight;
|
|
1907
|
+
/** called when item starts moving/resizing */
|
|
1908
|
+
let onStartMoving = (event, ui) => {
|
|
1909
|
+
// trigger any 'dragstart' / 'resizestart' manually
|
|
1910
|
+
if (this._gsEventHandler[event.type]) {
|
|
1911
|
+
this._gsEventHandler[event.type](event, event.target);
|
|
1912
|
+
}
|
|
1913
|
+
cellWidth = this.cellWidth();
|
|
1914
|
+
cellHeight = this.getCellHeight(true); // force pixels for calculations
|
|
1915
|
+
this._onStartMoving(el, event, ui, node, cellWidth, cellHeight);
|
|
1916
|
+
};
|
|
1917
|
+
/** called when item is being dragged/resized */
|
|
1918
|
+
let dragOrResize = (event, ui) => {
|
|
1919
|
+
this._dragOrResize(el, event, ui, node, cellWidth, cellHeight);
|
|
1920
|
+
};
|
|
1921
|
+
/** called when the item stops moving/resizing */
|
|
1922
|
+
let onEndMoving = (event) => {
|
|
1923
|
+
this.placeholder.remove();
|
|
1924
|
+
delete node._moving;
|
|
1925
|
+
delete node._event;
|
|
1926
|
+
delete node._lastTried;
|
|
1927
|
+
// if the item has moved to another grid, we're done here
|
|
1928
|
+
let target = event.target;
|
|
1929
|
+
if (!target.gridstackNode || target.gridstackNode.grid !== this)
|
|
1930
|
+
return;
|
|
1931
|
+
node.el = target;
|
|
1932
|
+
if (node._isAboutToRemove) {
|
|
1933
|
+
let gridToNotify = el.gridstackNode.grid;
|
|
1934
|
+
if (gridToNotify._gsEventHandler[event.type]) {
|
|
1935
|
+
gridToNotify._gsEventHandler[event.type](event, target);
|
|
1936
|
+
}
|
|
1937
|
+
this._removeDD(el);
|
|
1938
|
+
gridToNotify.engine.removedNodes.push(node);
|
|
1939
|
+
gridToNotify._triggerRemoveEvent();
|
|
1940
|
+
// break circular links and remove DOM
|
|
1941
|
+
delete el.gridstackNode;
|
|
1942
|
+
delete node.el;
|
|
1943
|
+
el.remove();
|
|
1944
|
+
}
|
|
1945
|
+
else {
|
|
1946
|
+
utils_1.Utils.removePositioningStyles(target);
|
|
1947
|
+
if (node._temporaryRemoved) {
|
|
1948
|
+
// got removed - restore item back to before dragging position
|
|
1949
|
+
utils_1.Utils.copyPos(node, node._orig); // @ts-ignore
|
|
1950
|
+
this._writePosAttr(target, node);
|
|
1951
|
+
this.engine.addNode(node);
|
|
1952
|
+
}
|
|
1953
|
+
else {
|
|
1954
|
+
// move to new placeholder location
|
|
1955
|
+
this._writePosAttr(target, node);
|
|
1956
|
+
}
|
|
1957
|
+
if (this._gsEventHandler[event.type]) {
|
|
1958
|
+
this._gsEventHandler[event.type](event, target);
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
// @ts-ignore
|
|
1962
|
+
this._extraDragRow = 0; // @ts-ignore
|
|
1963
|
+
this._updateContainerHeight(); // @ts-ignore
|
|
1964
|
+
this._triggerChangeEvent();
|
|
1965
|
+
this.engine.endUpdate();
|
|
1966
|
+
};
|
|
1967
|
+
dd.draggable(el, {
|
|
1968
|
+
start: onStartMoving,
|
|
1969
|
+
stop: onEndMoving,
|
|
1970
|
+
drag: dragOrResize
|
|
1971
|
+
}).resizable(el, {
|
|
1972
|
+
start: onStartMoving,
|
|
1973
|
+
stop: onEndMoving,
|
|
1974
|
+
resize: dragOrResize
|
|
1975
|
+
});
|
|
1976
|
+
node._initDD = true; // we've set DD support now
|
|
1977
|
+
}
|
|
1978
|
+
// finally fine tune move vs resize by disabling any part...
|
|
1979
|
+
dd.draggable(el, noMove ? 'disable' : 'enable')
|
|
1980
|
+
.resizable(el, noResize ? 'disable' : 'enable');
|
|
1981
|
+
return this;
|
|
1982
|
+
}
|
|
1527
1983
|
/** @internal handles actual drag/resize start **/
|
|
1528
|
-
_onStartMoving(el, event, ui, node, cellWidth, cellHeight) {
|
|
1984
|
+
_onStartMoving(el, event, ui, node, cellWidth, cellHeight) {
|
|
1985
|
+
this.engine.cleanNodes()
|
|
1986
|
+
.beginUpdate(node);
|
|
1987
|
+
// @ts-ignore
|
|
1988
|
+
this._writePosAttr(this.placeholder, node);
|
|
1989
|
+
this.el.appendChild(this.placeholder);
|
|
1990
|
+
// console.log('_onStartMoving placeholder') // TEST
|
|
1991
|
+
node.el = this.placeholder;
|
|
1992
|
+
node._lastUiPosition = ui.position;
|
|
1993
|
+
node._prevYPix = ui.position.top;
|
|
1994
|
+
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)
|
|
1995
|
+
delete node._lastTried;
|
|
1996
|
+
if (event.type === 'dropover' && node._temporaryRemoved) {
|
|
1997
|
+
// console.log('engine.addNode x=' + node.x); // TEST
|
|
1998
|
+
this.engine.addNode(node); // will add, fix collisions, update attr and clear _temporaryRemoved
|
|
1999
|
+
node._moving = true; // AFTER, mark as moving object (wanted fix location before)
|
|
2000
|
+
}
|
|
2001
|
+
// set the min/max resize info
|
|
2002
|
+
this.engine.cacheRects(cellWidth, cellHeight, this.opts.marginTop, this.opts.marginRight, this.opts.marginBottom, this.opts.marginLeft);
|
|
2003
|
+
if (event.type === 'resizestart') {
|
|
2004
|
+
dd.resizable(el, 'option', 'minWidth', cellWidth * (node.minW || 1))
|
|
2005
|
+
.resizable(el, 'option', 'minHeight', cellHeight * (node.minH || 1));
|
|
2006
|
+
if (node.maxW) {
|
|
2007
|
+
dd.resizable(el, 'option', 'maxWidth', cellWidth * node.maxW);
|
|
2008
|
+
}
|
|
2009
|
+
if (node.maxH) {
|
|
2010
|
+
dd.resizable(el, 'option', 'maxHeight', cellHeight * node.maxH);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
1529
2014
|
/** @internal handles actual drag/resize **/
|
|
1530
|
-
_dragOrResize(el, event, ui, node, cellWidth, cellHeight) {
|
|
1531
|
-
|
|
1532
|
-
|
|
2015
|
+
_dragOrResize(el, event, ui, node, cellWidth, cellHeight) {
|
|
2016
|
+
let p = Object.assign({}, node._orig); // could be undefined (_isExternal) which is ok (drag only set x,y and w,h will default to node value)
|
|
2017
|
+
let resizing;
|
|
2018
|
+
let mLeft = this.opts.marginLeft, mRight = this.opts.marginRight, mTop = this.opts.marginTop, mBottom = this.opts.marginBottom;
|
|
2019
|
+
// if margins (which are used to pass mid point by) are large relative to cell height/width, reduce them down #1855
|
|
2020
|
+
let mHeight = Math.round(cellHeight * 0.1), mWidth = Math.round(cellWidth * 0.1);
|
|
2021
|
+
mLeft = Math.min(mLeft, mWidth);
|
|
2022
|
+
mRight = Math.min(mRight, mWidth);
|
|
2023
|
+
mTop = Math.min(mTop, mHeight);
|
|
2024
|
+
mBottom = Math.min(mBottom, mHeight);
|
|
2025
|
+
if (event.type === 'drag') {
|
|
2026
|
+
if (node._temporaryRemoved)
|
|
2027
|
+
return; // handled by dropover
|
|
2028
|
+
let distance = ui.position.top - node._prevYPix;
|
|
2029
|
+
node._prevYPix = ui.position.top;
|
|
2030
|
+
utils_1.Utils.updateScrollPosition(el, ui.position, distance);
|
|
2031
|
+
// get new position taking into account the margin in the direction we are moving! (need to pass mid point by margin)
|
|
2032
|
+
let left = ui.position.left + (ui.position.left > node._lastUiPosition.left ? -mRight : mLeft);
|
|
2033
|
+
let top = ui.position.top + (ui.position.top > node._lastUiPosition.top ? -mBottom : mTop);
|
|
2034
|
+
p.x = Math.round(left / cellWidth);
|
|
2035
|
+
p.y = Math.round(top / cellHeight);
|
|
2036
|
+
// @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
|
|
2037
|
+
let prev = this._extraDragRow;
|
|
2038
|
+
if (this.engine.collide(node, p)) {
|
|
2039
|
+
let row = this.getRow();
|
|
2040
|
+
let extra = Math.max(0, (p.y + node.h) - row);
|
|
2041
|
+
if (this.opts.maxRow && row + extra > this.opts.maxRow) {
|
|
2042
|
+
extra = Math.max(0, this.opts.maxRow - row);
|
|
2043
|
+
} // @ts-ignore
|
|
2044
|
+
this._extraDragRow = extra; // @ts-ignore
|
|
2045
|
+
}
|
|
2046
|
+
else
|
|
2047
|
+
this._extraDragRow = 0; // @ts-ignore
|
|
2048
|
+
if (this._extraDragRow !== prev)
|
|
2049
|
+
this._updateContainerHeight();
|
|
2050
|
+
if (node.x === p.x && node.y === p.y)
|
|
2051
|
+
return; // skip same
|
|
2052
|
+
// DON'T skip one we tried as we might have failed because of coverage <50% before
|
|
2053
|
+
// if (node._lastTried && node._lastTried.x === x && node._lastTried.y === y) return;
|
|
2054
|
+
}
|
|
2055
|
+
else if (event.type === 'resize') {
|
|
2056
|
+
if (p.x < 0)
|
|
2057
|
+
return;
|
|
2058
|
+
// Scrolling page if needed
|
|
2059
|
+
utils_1.Utils.updateScrollResize(event, el, cellHeight);
|
|
2060
|
+
// get new size
|
|
2061
|
+
p.w = Math.round((ui.size.width - mLeft) / cellWidth);
|
|
2062
|
+
p.h = Math.round((ui.size.height - mTop) / cellHeight);
|
|
2063
|
+
if (node.w === p.w && node.h === p.h)
|
|
2064
|
+
return;
|
|
2065
|
+
if (node._lastTried && node._lastTried.w === p.w && node._lastTried.h === p.h)
|
|
2066
|
+
return; // skip one we tried (but failed)
|
|
2067
|
+
// if we size on left/top side this might move us, so get possible new position as well
|
|
2068
|
+
let left = ui.position.left + mLeft;
|
|
2069
|
+
let top = ui.position.top + mTop;
|
|
2070
|
+
p.x = Math.round(left / cellWidth);
|
|
2071
|
+
p.y = Math.round(top / cellHeight);
|
|
2072
|
+
resizing = true;
|
|
2073
|
+
}
|
|
2074
|
+
node._event = event;
|
|
2075
|
+
node._lastTried = p; // set as last tried (will nuke if we go there)
|
|
2076
|
+
let rect = {
|
|
2077
|
+
x: ui.position.left + mLeft,
|
|
2078
|
+
y: ui.position.top + mTop,
|
|
2079
|
+
w: (ui.size ? ui.size.width : node.w * cellWidth) - mLeft - mRight,
|
|
2080
|
+
h: (ui.size ? ui.size.height : node.h * cellHeight) - mTop - mBottom
|
|
2081
|
+
};
|
|
2082
|
+
if (this.engine.moveNodeCheck(node, Object.assign(Object.assign({}, p), { cellWidth, cellHeight, rect, resizing }))) {
|
|
2083
|
+
node._lastUiPosition = ui.position;
|
|
2084
|
+
this.engine.cacheRects(cellWidth, cellHeight, mTop, mRight, mBottom, mLeft);
|
|
2085
|
+
delete node._skipDown;
|
|
2086
|
+
if (resizing && node.subGrid) {
|
|
2087
|
+
node.subGrid.onParentResize();
|
|
2088
|
+
} // @ts-ignore
|
|
2089
|
+
this._extraDragRow = 0; // @ts-ignore
|
|
2090
|
+
this._updateContainerHeight();
|
|
2091
|
+
let target = event.target; // @ts-ignore
|
|
2092
|
+
this._writePosAttr(target, node);
|
|
2093
|
+
if (this._gsEventHandler[event.type]) {
|
|
2094
|
+
this._gsEventHandler[event.type](event, target);
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
/** @internal called when item leaving our area by either cursor dropout event
|
|
2099
|
+
* or shape is outside our boundaries. remove it from us, and mark temporary if this was
|
|
2100
|
+
* our item to start with else restore prev node values from prev grid it came from.
|
|
2101
|
+
**/
|
|
2102
|
+
_leave(el, helper) {
|
|
2103
|
+
let node = el.gridstackNode;
|
|
2104
|
+
if (!node)
|
|
2105
|
+
return;
|
|
2106
|
+
dd.off(el, 'drag'); // no need to track while being outside
|
|
2107
|
+
// this gets called when cursor leaves and shape is outside, so only do this once
|
|
2108
|
+
if (node._temporaryRemoved)
|
|
2109
|
+
return;
|
|
2110
|
+
node._temporaryRemoved = true;
|
|
2111
|
+
this.engine.removeNode(node); // remove placeholder as well, otherwise it's a sign node is not in our list, which is a bigger issue
|
|
2112
|
+
node.el = node._isExternal && helper ? helper : el; // point back to real item being dragged
|
|
2113
|
+
if (this.opts.removable === true) { // boolean vs a class string
|
|
2114
|
+
// item leaving us and we are supposed to remove on leave (no need to drag onto trash) mark it so
|
|
2115
|
+
this._itemRemoving(el, true);
|
|
2116
|
+
}
|
|
2117
|
+
// finally if item originally came from another grid, but left us, restore things back to prev info
|
|
2118
|
+
if (el._gridstackNodeOrig) {
|
|
2119
|
+
// console.log('leave delete _gridstackNodeOrig') // TEST
|
|
2120
|
+
el.gridstackNode = el._gridstackNodeOrig;
|
|
2121
|
+
delete el._gridstackNodeOrig;
|
|
2122
|
+
}
|
|
2123
|
+
else if (node._isExternal) {
|
|
2124
|
+
// item came from outside (like a toolbar) so nuke any node info
|
|
2125
|
+
delete node.el;
|
|
2126
|
+
delete el.gridstackNode;
|
|
2127
|
+
// and restore all nodes back to original
|
|
2128
|
+
this.engine.restoreInitial();
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
1533
2131
|
// legacy method removed
|
|
1534
2132
|
commit() { utils_1.obsolete(this, this.batchUpdate(false), 'commit', 'batchUpdate', '5.2'); return this; }
|
|
1535
2133
|
}
|
|
@@ -1538,8 +2136,5 @@ exports.GridStack = GridStack;
|
|
|
1538
2136
|
GridStack.Utils = utils_1.Utils;
|
|
1539
2137
|
/** scoping so users can call new GridStack.Engine(12) for example */
|
|
1540
2138
|
GridStack.Engine = gridstack_engine_1.GridStackEngine;
|
|
1541
|
-
GridStack.GDRev = '7.
|
|
1542
|
-
const dd_touch_1 = require("./dd-touch");
|
|
1543
|
-
const dd_manager_1 = require("./dd-manager");
|
|
1544
|
-
__exportStar(require("./dd-gridstack"), exports);
|
|
2139
|
+
GridStack.GDRev = '7.2.0';
|
|
1545
2140
|
//# sourceMappingURL=gridstack.js.map
|