gridstack 12.0.0 → 12.1.1
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 +5 -3
- package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
- package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
- package/dist/angular/esm2020/lib/gridstack.component.mjs +18 -4
- package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
- package/dist/angular/esm2020/lib/types.mjs +2 -2
- package/dist/angular/fesm2015/gridstack-angular.mjs +22 -6
- package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
- package/dist/angular/fesm2020/gridstack-angular.mjs +21 -7
- package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
- package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
- package/dist/angular/lib/gridstack.component.d.ts +1 -1
- package/dist/angular/lib/types.d.ts +1 -1
- package/dist/angular/src/base-widget.ts +1 -1
- package/dist/angular/src/gridstack-item.component.ts +1 -1
- package/dist/angular/src/gridstack.component.ts +15 -3
- package/dist/angular/src/gridstack.module.ts +1 -1
- package/dist/dd-base-impl.d.ts +1 -1
- package/dist/dd-base-impl.js +1 -1
- package/dist/dd-base-impl.js.map +1 -1
- package/dist/dd-draggable.d.ts +1 -1
- package/dist/dd-draggable.js +1 -1
- package/dist/dd-draggable.js.map +1 -1
- package/dist/dd-droppable.d.ts +1 -1
- package/dist/dd-droppable.js +1 -1
- package/dist/dd-droppable.js.map +1 -1
- package/dist/dd-element.d.ts +1 -1
- package/dist/dd-element.js +1 -1
- package/dist/dd-element.js.map +1 -1
- package/dist/dd-gridstack.d.ts +1 -1
- package/dist/dd-gridstack.js +1 -1
- 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/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 +3 -1
- package/dist/gridstack.js +58 -56
- package/dist/gridstack.js.map +1 -1
- package/dist/src/gridstack.scss +1 -1
- package/dist/types.d.ts +1 -1
- 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 +14 -0
- package/package.json +2 -4
- package/dist/es5/dd-base-impl.d.ts +0 -20
- package/dist/es5/dd-base-impl.js +0 -41
- package/dist/es5/dd-base-impl.js.map +0 -1
- package/dist/es5/dd-draggable.d.ts +0 -20
- package/dist/es5/dd-draggable.js +0 -408
- package/dist/es5/dd-draggable.js.map +0 -1
- package/dist/es5/dd-droppable.d.ts +0 -26
- package/dist/es5/dd-droppable.js +0 -185
- package/dist/es5/dd-droppable.js.map +0 -1
- package/dist/es5/dd-element.d.ts +0 -27
- package/dist/es5/dd-element.js +0 -96
- package/dist/es5/dd-element.js.map +0 -1
- package/dist/es5/dd-gridstack.d.ts +0 -34
- package/dist/es5/dd-gridstack.js +0 -154
- package/dist/es5/dd-gridstack.js.map +0 -1
- package/dist/es5/dd-manager.d.ts +0 -22
- package/dist/es5/dd-manager.js +0 -17
- package/dist/es5/dd-manager.js.map +0 -1
- package/dist/es5/dd-resizable-handle.d.ts +0 -18
- package/dist/es5/dd-resizable-handle.js +0 -117
- package/dist/es5/dd-resizable-handle.js.map +0 -1
- package/dist/es5/dd-resizable.d.ts +0 -30
- package/dist/es5/dd-resizable.js +0 -331
- package/dist/es5/dd-resizable.js.map +0 -1
- package/dist/es5/dd-touch.d.ts +0 -33
- package/dist/es5/dd-touch.js +0 -157
- package/dist/es5/dd-touch.js.map +0 -1
- package/dist/es5/gridstack-all.js +0 -3
- package/dist/es5/gridstack-all.js.LICENSE.txt +0 -7
- package/dist/es5/gridstack-all.js.map +0 -1
- package/dist/es5/gridstack-engine.d.ts +0 -107
- package/dist/es5/gridstack-engine.js +0 -1070
- package/dist/es5/gridstack-engine.js.map +0 -1
- package/dist/es5/gridstack-poly.js +0 -356
- package/dist/es5/gridstack.d.ts +0 -452
- package/dist/es5/gridstack.js +0 -2644
- package/dist/es5/gridstack.js.map +0 -1
- package/dist/es5/types.d.ts +0 -326
- package/dist/es5/types.js +0 -38
- package/dist/es5/types.js.map +0 -1
- package/dist/es5/utils.d.ts +0 -104
- package/dist/es5/utils.js +0 -633
- package/dist/es5/utils.js.map +0 -1
|
@@ -1,1070 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* gridstack-engine.ts 12.0.0
|
|
4
|
-
* Copyright (c) 2021-2024 Alain Dumesny - see GridStack root license
|
|
5
|
-
*/
|
|
6
|
-
var __assign = (this && this.__assign) || function () {
|
|
7
|
-
__assign = Object.assign || function(t) {
|
|
8
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
-
s = arguments[i];
|
|
10
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
-
t[p] = s[p];
|
|
12
|
-
}
|
|
13
|
-
return t;
|
|
14
|
-
};
|
|
15
|
-
return __assign.apply(this, arguments);
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.GridStackEngine = void 0;
|
|
19
|
-
var utils_1 = require("./utils");
|
|
20
|
-
/**
|
|
21
|
-
* Defines the GridStack engine that does most no DOM grid manipulation.
|
|
22
|
-
* See GridStack methods and vars for descriptions.
|
|
23
|
-
*
|
|
24
|
-
* NOTE: values should not be modified directly - call the main GridStack API instead
|
|
25
|
-
*/
|
|
26
|
-
var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
27
|
-
function GridStackEngine(opts) {
|
|
28
|
-
if (opts === void 0) { opts = {}; }
|
|
29
|
-
this.addedNodes = [];
|
|
30
|
-
this.removedNodes = [];
|
|
31
|
-
this.defaultColumn = 12;
|
|
32
|
-
this.column = opts.column || this.defaultColumn;
|
|
33
|
-
if (this.column > this.defaultColumn)
|
|
34
|
-
this.defaultColumn = this.column;
|
|
35
|
-
this.maxRow = opts.maxRow;
|
|
36
|
-
this._float = opts.float;
|
|
37
|
-
this.nodes = opts.nodes || [];
|
|
38
|
-
this.onChange = opts.onChange;
|
|
39
|
-
}
|
|
40
|
-
GridStackEngine.prototype.batchUpdate = function (flag, doPack) {
|
|
41
|
-
if (flag === void 0) { flag = true; }
|
|
42
|
-
if (doPack === void 0) { doPack = true; }
|
|
43
|
-
if (!!this.batchMode === flag)
|
|
44
|
-
return this;
|
|
45
|
-
this.batchMode = flag;
|
|
46
|
-
if (flag) {
|
|
47
|
-
this._prevFloat = this._float;
|
|
48
|
-
this._float = true; // let things go anywhere for now... will restore and possibly reposition later
|
|
49
|
-
this.cleanNodes();
|
|
50
|
-
this.saveInitial(); // since begin update (which is called multiple times) won't do this
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
this._float = this._prevFloat;
|
|
54
|
-
delete this._prevFloat;
|
|
55
|
-
if (doPack)
|
|
56
|
-
this._packNodes();
|
|
57
|
-
this._notify();
|
|
58
|
-
}
|
|
59
|
-
return this;
|
|
60
|
-
};
|
|
61
|
-
// use entire row for hitting area (will use bottom reverse sorted first) if we not actively moving DOWN and didn't already skip
|
|
62
|
-
GridStackEngine.prototype._useEntireRowArea = function (node, nn) {
|
|
63
|
-
return (!this.float || this.batchMode && !this._prevFloat) && !this._hasLocked && (!node._moving || node._skipDown || nn.y <= node.y);
|
|
64
|
-
};
|
|
65
|
-
/** @internal fix collision on given 'node', going to given new location 'nn', with optional 'collide' node already found.
|
|
66
|
-
* return true if we moved. */
|
|
67
|
-
GridStackEngine.prototype._fixCollisions = function (node, nn, collide, opt) {
|
|
68
|
-
if (nn === void 0) { nn = node; }
|
|
69
|
-
if (opt === void 0) { opt = {}; }
|
|
70
|
-
this.sortNodes(-1); // from last to first, so recursive collision move items in the right order
|
|
71
|
-
collide = collide || this.collide(node, nn); // REAL area collide for swap and skip if none...
|
|
72
|
-
if (!collide)
|
|
73
|
-
return false;
|
|
74
|
-
// swap check: if we're actively moving in gravity mode, see if we collide with an object the same size
|
|
75
|
-
if (node._moving && !opt.nested && !this.float) {
|
|
76
|
-
if (this.swap(node, collide))
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
// during while() collisions MAKE SURE to check entire row so larger items don't leap frog small ones (push them all down starting last in grid)
|
|
80
|
-
var area = nn;
|
|
81
|
-
if (!this._loading && this._useEntireRowArea(node, nn)) {
|
|
82
|
-
area = { x: 0, w: this.column, y: nn.y, h: nn.h };
|
|
83
|
-
collide = this.collide(node, area, opt.skip); // force new hit
|
|
84
|
-
}
|
|
85
|
-
var didMove = false;
|
|
86
|
-
var newOpt = { nested: true, pack: false };
|
|
87
|
-
var counter = 0;
|
|
88
|
-
while (collide = collide || this.collide(node, area, opt.skip)) { // could collide with more than 1 item... so repeat for each
|
|
89
|
-
if (counter++ > this.nodes.length * 2) {
|
|
90
|
-
throw new Error("Infinite collide check");
|
|
91
|
-
}
|
|
92
|
-
var moved = void 0;
|
|
93
|
-
// if colliding with a locked item OR loading (move after) OR moving down with top gravity (and collide could move up) -> skip past the collide,
|
|
94
|
-
// but remember that skip down so we only do this once (and push others otherwise).
|
|
95
|
-
if (collide.locked || this._loading || node._moving && !node._skipDown && nn.y > node.y && !this.float &&
|
|
96
|
-
// can take space we had, or before where we're going
|
|
97
|
-
(!this.collide(collide, __assign(__assign({}, collide), { y: node.y }), node) || !this.collide(collide, __assign(__assign({}, collide), { y: nn.y - collide.h }), node))) {
|
|
98
|
-
node._skipDown = (node._skipDown || nn.y > node.y);
|
|
99
|
-
var newNN = __assign(__assign(__assign({}, nn), { y: collide.y + collide.h }), newOpt);
|
|
100
|
-
// pretent we moved to where we are now so we can continue any collision checks #2492
|
|
101
|
-
moved = this._loading && utils_1.Utils.samePos(node, newNN) ? true : this.moveNode(node, newNN);
|
|
102
|
-
if ((collide.locked || this._loading) && moved) {
|
|
103
|
-
utils_1.Utils.copyPos(nn, node); // moving after lock become our new desired location
|
|
104
|
-
}
|
|
105
|
-
else if (!collide.locked && moved && opt.pack) {
|
|
106
|
-
// we moved after and will pack: do it now and keep the original drop location, but past the old collide to see what else we might push way
|
|
107
|
-
this._packNodes();
|
|
108
|
-
nn.y = collide.y + collide.h;
|
|
109
|
-
utils_1.Utils.copyPos(node, nn);
|
|
110
|
-
}
|
|
111
|
-
didMove = didMove || moved;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
// move collide down *after* where we will be, ignoring where we are now (don't collide with us)
|
|
115
|
-
moved = this.moveNode(collide, __assign(__assign(__assign({}, collide), { y: nn.y + nn.h, skip: node }), newOpt));
|
|
116
|
-
}
|
|
117
|
-
if (!moved)
|
|
118
|
-
return didMove; // break inf loop if we couldn't move after all (ex: maxRow, fixed)
|
|
119
|
-
collide = undefined;
|
|
120
|
-
}
|
|
121
|
-
return didMove;
|
|
122
|
-
};
|
|
123
|
-
/** return the nodes that intercept the given node. Optionally a different area can be used, as well as a second node to skip */
|
|
124
|
-
GridStackEngine.prototype.collide = function (skip, area, skip2) {
|
|
125
|
-
if (area === void 0) { area = skip; }
|
|
126
|
-
var skipId = skip._id;
|
|
127
|
-
var skip2Id = skip2 === null || skip2 === void 0 ? void 0 : skip2._id;
|
|
128
|
-
return this.nodes.find(function (n) { return n._id !== skipId && n._id !== skip2Id && utils_1.Utils.isIntercepted(n, area); });
|
|
129
|
-
};
|
|
130
|
-
GridStackEngine.prototype.collideAll = function (skip, area, skip2) {
|
|
131
|
-
if (area === void 0) { area = skip; }
|
|
132
|
-
var skipId = skip._id;
|
|
133
|
-
var skip2Id = skip2 === null || skip2 === void 0 ? void 0 : skip2._id;
|
|
134
|
-
return this.nodes.filter(function (n) { return n._id !== skipId && n._id !== skip2Id && utils_1.Utils.isIntercepted(n, area); });
|
|
135
|
-
};
|
|
136
|
-
/** does a pixel coverage collision based on where we started, returning the node that has the most coverage that is >50% mid line */
|
|
137
|
-
GridStackEngine.prototype.directionCollideCoverage = function (node, o, collides) {
|
|
138
|
-
if (!o.rect || !node._rect)
|
|
139
|
-
return;
|
|
140
|
-
var r0 = node._rect; // where started
|
|
141
|
-
var r = __assign({}, o.rect); // where we are
|
|
142
|
-
// update dragged rect to show where it's coming from (above or below, etc...)
|
|
143
|
-
if (r.y > r0.y) {
|
|
144
|
-
r.h += r.y - r0.y;
|
|
145
|
-
r.y = r0.y;
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
r.h += r0.y - r.y;
|
|
149
|
-
}
|
|
150
|
-
if (r.x > r0.x) {
|
|
151
|
-
r.w += r.x - r0.x;
|
|
152
|
-
r.x = r0.x;
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
r.w += r0.x - r.x;
|
|
156
|
-
}
|
|
157
|
-
var collide;
|
|
158
|
-
var overMax = 0.5; // need >50%
|
|
159
|
-
for (var _i = 0, collides_1 = collides; _i < collides_1.length; _i++) {
|
|
160
|
-
var n = collides_1[_i];
|
|
161
|
-
if (n.locked || !n._rect) {
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
var r2 = n._rect; // overlapping target
|
|
165
|
-
var yOver = Number.MAX_VALUE, xOver = Number.MAX_VALUE;
|
|
166
|
-
// depending on which side we started from, compute the overlap % of coverage
|
|
167
|
-
// (ex: from above/below we only compute the max horizontal line coverage)
|
|
168
|
-
if (r0.y < r2.y) { // from above
|
|
169
|
-
yOver = ((r.y + r.h) - r2.y) / r2.h;
|
|
170
|
-
}
|
|
171
|
-
else if (r0.y + r0.h > r2.y + r2.h) { // from below
|
|
172
|
-
yOver = ((r2.y + r2.h) - r.y) / r2.h;
|
|
173
|
-
}
|
|
174
|
-
if (r0.x < r2.x) { // from the left
|
|
175
|
-
xOver = ((r.x + r.w) - r2.x) / r2.w;
|
|
176
|
-
}
|
|
177
|
-
else if (r0.x + r0.w > r2.x + r2.w) { // from the right
|
|
178
|
-
xOver = ((r2.x + r2.w) - r.x) / r2.w;
|
|
179
|
-
}
|
|
180
|
-
var over = Math.min(xOver, yOver);
|
|
181
|
-
if (over > overMax) {
|
|
182
|
-
overMax = over;
|
|
183
|
-
collide = n;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
o.collide = collide; // save it so we don't have to find it again
|
|
187
|
-
return collide;
|
|
188
|
-
};
|
|
189
|
-
/** does a pixel coverage returning the node that has the most coverage by area */
|
|
190
|
-
/*
|
|
191
|
-
protected collideCoverage(r: GridStackPosition, collides: GridStackNode[]): {collide: GridStackNode, over: number} {
|
|
192
|
-
const collide: GridStackNode;
|
|
193
|
-
const overMax = 0;
|
|
194
|
-
collides.forEach(n => {
|
|
195
|
-
if (n.locked || !n._rect) return;
|
|
196
|
-
const over = Utils.areaIntercept(r, n._rect);
|
|
197
|
-
if (over > overMax) {
|
|
198
|
-
overMax = over;
|
|
199
|
-
collide = n;
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
return {collide, over: overMax};
|
|
203
|
-
}
|
|
204
|
-
*/
|
|
205
|
-
/** called to cache the nodes pixel rectangles used for collision detection during drag */
|
|
206
|
-
GridStackEngine.prototype.cacheRects = function (w, h, top, right, bottom, left) {
|
|
207
|
-
this.nodes.forEach(function (n) {
|
|
208
|
-
return n._rect = {
|
|
209
|
-
y: n.y * h + top,
|
|
210
|
-
x: n.x * w + left,
|
|
211
|
-
w: n.w * w - left - right,
|
|
212
|
-
h: n.h * h - top - bottom
|
|
213
|
-
};
|
|
214
|
-
});
|
|
215
|
-
return this;
|
|
216
|
-
};
|
|
217
|
-
/** called to possibly swap between 2 nodes (same size or column, not locked, touching), returning true if successful */
|
|
218
|
-
GridStackEngine.prototype.swap = function (a, b) {
|
|
219
|
-
if (!b || b.locked || !a || a.locked)
|
|
220
|
-
return false;
|
|
221
|
-
function _doSwap() {
|
|
222
|
-
var x = b.x, y = b.y;
|
|
223
|
-
b.x = a.x;
|
|
224
|
-
b.y = a.y; // b -> a position
|
|
225
|
-
if (a.h != b.h) {
|
|
226
|
-
a.x = x;
|
|
227
|
-
a.y = b.y + b.h; // a -> goes after b
|
|
228
|
-
}
|
|
229
|
-
else if (a.w != b.w) {
|
|
230
|
-
a.x = b.x + b.w;
|
|
231
|
-
a.y = y; // a -> goes after b
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
a.x = x;
|
|
235
|
-
a.y = y; // a -> old b position
|
|
236
|
-
}
|
|
237
|
-
a._dirty = b._dirty = true;
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
var touching; // remember if we called it (vs undefined)
|
|
241
|
-
// same size and same row or column, and touching
|
|
242
|
-
if (a.w === b.w && a.h === b.h && (a.x === b.x || a.y === b.y) && (touching = utils_1.Utils.isTouching(a, b)))
|
|
243
|
-
return _doSwap();
|
|
244
|
-
if (touching === false)
|
|
245
|
-
return; // IFF ran test and fail, bail out
|
|
246
|
-
// check for taking same columns (but different height) and touching
|
|
247
|
-
if (a.w === b.w && a.x === b.x && (touching || (touching = utils_1.Utils.isTouching(a, b)))) {
|
|
248
|
-
if (b.y < a.y) {
|
|
249
|
-
var t = a;
|
|
250
|
-
a = b;
|
|
251
|
-
b = t;
|
|
252
|
-
} // swap a <-> b vars so a is first
|
|
253
|
-
return _doSwap();
|
|
254
|
-
}
|
|
255
|
-
if (touching === false)
|
|
256
|
-
return;
|
|
257
|
-
// check if taking same row (but different width) and touching
|
|
258
|
-
if (a.h === b.h && a.y === b.y && (touching || (touching = utils_1.Utils.isTouching(a, b)))) {
|
|
259
|
-
if (b.x < a.x) {
|
|
260
|
-
var t = a;
|
|
261
|
-
a = b;
|
|
262
|
-
b = t;
|
|
263
|
-
} // swap a <-> b vars so a is first
|
|
264
|
-
return _doSwap();
|
|
265
|
-
}
|
|
266
|
-
return false;
|
|
267
|
-
};
|
|
268
|
-
GridStackEngine.prototype.isAreaEmpty = function (x, y, w, h) {
|
|
269
|
-
var nn = { x: x || 0, y: y || 0, w: w || 1, h: h || 1 };
|
|
270
|
-
return !this.collide(nn);
|
|
271
|
-
};
|
|
272
|
-
/** re-layout grid items to reclaim any empty space - optionally keeping the sort order exactly the same ('list' mode) vs truly finding an empty spaces */
|
|
273
|
-
GridStackEngine.prototype.compact = function (layout, doSort) {
|
|
274
|
-
var _this = this;
|
|
275
|
-
if (layout === void 0) { layout = 'compact'; }
|
|
276
|
-
if (doSort === void 0) { doSort = true; }
|
|
277
|
-
if (this.nodes.length === 0)
|
|
278
|
-
return this;
|
|
279
|
-
if (doSort)
|
|
280
|
-
this.sortNodes();
|
|
281
|
-
var wasBatch = this.batchMode;
|
|
282
|
-
if (!wasBatch)
|
|
283
|
-
this.batchUpdate();
|
|
284
|
-
var wasColumnResize = this._inColumnResize;
|
|
285
|
-
if (!wasColumnResize)
|
|
286
|
-
this._inColumnResize = true; // faster addNode()
|
|
287
|
-
var copyNodes = this.nodes;
|
|
288
|
-
this.nodes = []; // pretend we have no nodes to conflict layout to start with...
|
|
289
|
-
copyNodes.forEach(function (n, index, list) {
|
|
290
|
-
var after;
|
|
291
|
-
if (!n.locked) {
|
|
292
|
-
n.autoPosition = true;
|
|
293
|
-
if (layout === 'list' && index)
|
|
294
|
-
after = list[index - 1];
|
|
295
|
-
}
|
|
296
|
-
_this.addNode(n, false, after); // 'false' for add event trigger
|
|
297
|
-
});
|
|
298
|
-
if (!wasColumnResize)
|
|
299
|
-
delete this._inColumnResize;
|
|
300
|
-
if (!wasBatch)
|
|
301
|
-
this.batchUpdate(false);
|
|
302
|
-
return this;
|
|
303
|
-
};
|
|
304
|
-
Object.defineProperty(GridStackEngine.prototype, "float", {
|
|
305
|
-
/** float getter method */
|
|
306
|
-
get: function () { return this._float || false; },
|
|
307
|
-
/** enable/disable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html) */
|
|
308
|
-
set: function (val) {
|
|
309
|
-
if (this._float === val)
|
|
310
|
-
return;
|
|
311
|
-
this._float = val || false;
|
|
312
|
-
if (!val) {
|
|
313
|
-
this._packNodes()._notify();
|
|
314
|
-
}
|
|
315
|
-
},
|
|
316
|
-
enumerable: false,
|
|
317
|
-
configurable: true
|
|
318
|
-
});
|
|
319
|
-
/** sort the nodes array from first to last, or reverse. Called during collision/placement to force an order */
|
|
320
|
-
GridStackEngine.prototype.sortNodes = function (dir) {
|
|
321
|
-
if (dir === void 0) { dir = 1; }
|
|
322
|
-
this.nodes = utils_1.Utils.sort(this.nodes, dir);
|
|
323
|
-
return this;
|
|
324
|
-
};
|
|
325
|
-
/** @internal called to top gravity pack the items back OR revert back to original Y positions when floating */
|
|
326
|
-
GridStackEngine.prototype._packNodes = function () {
|
|
327
|
-
var _this = this;
|
|
328
|
-
if (this.batchMode) {
|
|
329
|
-
return this;
|
|
330
|
-
}
|
|
331
|
-
this.sortNodes(); // first to last
|
|
332
|
-
if (this.float) {
|
|
333
|
-
// restore original Y pos
|
|
334
|
-
this.nodes.forEach(function (n) {
|
|
335
|
-
if (n._updating || n._orig === undefined || n.y === n._orig.y)
|
|
336
|
-
return;
|
|
337
|
-
var newY = n.y;
|
|
338
|
-
while (newY > n._orig.y) {
|
|
339
|
-
--newY;
|
|
340
|
-
var collide = _this.collide(n, { x: n.x, y: newY, w: n.w, h: n.h });
|
|
341
|
-
if (!collide) {
|
|
342
|
-
n._dirty = true;
|
|
343
|
-
n.y = newY;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
// top gravity pack
|
|
350
|
-
this.nodes.forEach(function (n, i) {
|
|
351
|
-
if (n.locked)
|
|
352
|
-
return;
|
|
353
|
-
while (n.y > 0) {
|
|
354
|
-
var newY = i === 0 ? 0 : n.y - 1;
|
|
355
|
-
var canBeMoved = i === 0 || !_this.collide(n, { x: n.x, y: newY, w: n.w, h: n.h });
|
|
356
|
-
if (!canBeMoved)
|
|
357
|
-
break;
|
|
358
|
-
// Note: must be dirty (from last position) for GridStack::OnChange CB to update positions
|
|
359
|
-
// and move items back. The user 'change' CB should detect changes from the original
|
|
360
|
-
// starting position instead.
|
|
361
|
-
n._dirty = (n.y !== newY);
|
|
362
|
-
n.y = newY;
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
return this;
|
|
367
|
-
};
|
|
368
|
-
/**
|
|
369
|
-
* given a random node, makes sure it's coordinates/values are valid in the current grid
|
|
370
|
-
* @param node to adjust
|
|
371
|
-
* @param resizing if out of bound, resize down or move into the grid to fit ?
|
|
372
|
-
*/
|
|
373
|
-
GridStackEngine.prototype.prepareNode = function (node, resizing) {
|
|
374
|
-
var _a;
|
|
375
|
-
node._id = (_a = node._id) !== null && _a !== void 0 ? _a : GridStackEngine._idSeq++;
|
|
376
|
-
// make sure USER supplied id are unique in our list, else assign a new one as it will create issues during load/update/etc...
|
|
377
|
-
var id = node.id;
|
|
378
|
-
if (id) {
|
|
379
|
-
var count = 1; // append nice _n rather than some random number
|
|
380
|
-
while (this.nodes.find(function (n) { return n.id === node.id && n !== node; })) {
|
|
381
|
-
node.id = id + '_' + (count++);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
// if we're missing position, have the grid position us automatically (before we set them to 0,0)
|
|
385
|
-
if (node.x === undefined || node.y === undefined || node.x === null || node.y === null) {
|
|
386
|
-
node.autoPosition = true;
|
|
387
|
-
}
|
|
388
|
-
// assign defaults for missing required fields
|
|
389
|
-
var defaults = { x: 0, y: 0, w: 1, h: 1 };
|
|
390
|
-
utils_1.Utils.defaults(node, defaults);
|
|
391
|
-
if (!node.autoPosition) {
|
|
392
|
-
delete node.autoPosition;
|
|
393
|
-
}
|
|
394
|
-
if (!node.noResize) {
|
|
395
|
-
delete node.noResize;
|
|
396
|
-
}
|
|
397
|
-
if (!node.noMove) {
|
|
398
|
-
delete node.noMove;
|
|
399
|
-
}
|
|
400
|
-
utils_1.Utils.sanitizeMinMax(node);
|
|
401
|
-
// check for NaN (in case messed up strings were passed. can't do parseInt() || defaults.x above as 0 is valid #)
|
|
402
|
-
if (typeof node.x == 'string') {
|
|
403
|
-
node.x = Number(node.x);
|
|
404
|
-
}
|
|
405
|
-
if (typeof node.y == 'string') {
|
|
406
|
-
node.y = Number(node.y);
|
|
407
|
-
}
|
|
408
|
-
if (typeof node.w == 'string') {
|
|
409
|
-
node.w = Number(node.w);
|
|
410
|
-
}
|
|
411
|
-
if (typeof node.h == 'string') {
|
|
412
|
-
node.h = Number(node.h);
|
|
413
|
-
}
|
|
414
|
-
if (isNaN(node.x)) {
|
|
415
|
-
node.x = defaults.x;
|
|
416
|
-
node.autoPosition = true;
|
|
417
|
-
}
|
|
418
|
-
if (isNaN(node.y)) {
|
|
419
|
-
node.y = defaults.y;
|
|
420
|
-
node.autoPosition = true;
|
|
421
|
-
}
|
|
422
|
-
if (isNaN(node.w)) {
|
|
423
|
-
node.w = defaults.w;
|
|
424
|
-
}
|
|
425
|
-
if (isNaN(node.h)) {
|
|
426
|
-
node.h = defaults.h;
|
|
427
|
-
}
|
|
428
|
-
this.nodeBoundFix(node, resizing);
|
|
429
|
-
return node;
|
|
430
|
-
};
|
|
431
|
-
/** part2 of preparing a node to fit inside our grid - checks for x,y,w from grid dimensions */
|
|
432
|
-
GridStackEngine.prototype.nodeBoundFix = function (node, resizing) {
|
|
433
|
-
var before = node._orig || utils_1.Utils.copyPos({}, node);
|
|
434
|
-
if (node.maxW) {
|
|
435
|
-
node.w = Math.min(node.w || 1, node.maxW);
|
|
436
|
-
}
|
|
437
|
-
if (node.maxH) {
|
|
438
|
-
node.h = Math.min(node.h || 1, node.maxH);
|
|
439
|
-
}
|
|
440
|
-
if (node.minW) {
|
|
441
|
-
node.w = Math.max(node.w || 1, node.minW);
|
|
442
|
-
}
|
|
443
|
-
if (node.minH) {
|
|
444
|
-
node.h = Math.max(node.h || 1, node.minH);
|
|
445
|
-
}
|
|
446
|
-
// if user loaded a larger than allowed widget for current # of columns,
|
|
447
|
-
// remember it's position & width so we can restore back (1 -> 12 column) #1655 #1985
|
|
448
|
-
// IFF we're not in the middle of column resizing!
|
|
449
|
-
var saveOrig = (node.x || 0) + (node.w || 1) > this.column;
|
|
450
|
-
if (saveOrig && this.column < this.defaultColumn && !this._inColumnResize && !this.skipCacheUpdate && node._id && this.findCacheLayout(node, this.defaultColumn) === -1) {
|
|
451
|
-
var copy = __assign({}, node); // need _id + positions
|
|
452
|
-
if (copy.autoPosition || copy.x === undefined) {
|
|
453
|
-
delete copy.x;
|
|
454
|
-
delete copy.y;
|
|
455
|
-
}
|
|
456
|
-
else
|
|
457
|
-
copy.x = Math.min(this.defaultColumn - 1, copy.x);
|
|
458
|
-
copy.w = Math.min(this.defaultColumn, copy.w || 1);
|
|
459
|
-
this.cacheOneLayout(copy, this.defaultColumn);
|
|
460
|
-
}
|
|
461
|
-
if (node.w > this.column) {
|
|
462
|
-
node.w = this.column;
|
|
463
|
-
}
|
|
464
|
-
else if (node.w < 1) {
|
|
465
|
-
node.w = 1;
|
|
466
|
-
}
|
|
467
|
-
if (this.maxRow && node.h > this.maxRow) {
|
|
468
|
-
node.h = this.maxRow;
|
|
469
|
-
}
|
|
470
|
-
else if (node.h < 1) {
|
|
471
|
-
node.h = 1;
|
|
472
|
-
}
|
|
473
|
-
if (node.x < 0) {
|
|
474
|
-
node.x = 0;
|
|
475
|
-
}
|
|
476
|
-
if (node.y < 0) {
|
|
477
|
-
node.y = 0;
|
|
478
|
-
}
|
|
479
|
-
if (node.x + node.w > this.column) {
|
|
480
|
-
if (resizing) {
|
|
481
|
-
node.w = this.column - node.x;
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
node.x = this.column - node.w;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if (this.maxRow && node.y + node.h > this.maxRow) {
|
|
488
|
-
if (resizing) {
|
|
489
|
-
node.h = this.maxRow - node.y;
|
|
490
|
-
}
|
|
491
|
-
else {
|
|
492
|
-
node.y = this.maxRow - node.h;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
if (!utils_1.Utils.samePos(node, before)) {
|
|
496
|
-
node._dirty = true;
|
|
497
|
-
}
|
|
498
|
-
return this;
|
|
499
|
-
};
|
|
500
|
-
/** returns a list of modified nodes from their original values */
|
|
501
|
-
GridStackEngine.prototype.getDirtyNodes = function (verify) {
|
|
502
|
-
// compare original x,y,w,h instead as _dirty can be a temporary state
|
|
503
|
-
if (verify) {
|
|
504
|
-
return this.nodes.filter(function (n) { return n._dirty && !utils_1.Utils.samePos(n, n._orig); });
|
|
505
|
-
}
|
|
506
|
-
return this.nodes.filter(function (n) { return n._dirty; });
|
|
507
|
-
};
|
|
508
|
-
/** @internal call this to call onChange callback with dirty nodes so DOM can be updated */
|
|
509
|
-
GridStackEngine.prototype._notify = function (removedNodes) {
|
|
510
|
-
if (this.batchMode || !this.onChange)
|
|
511
|
-
return this;
|
|
512
|
-
var dirtyNodes = (removedNodes || []).concat(this.getDirtyNodes());
|
|
513
|
-
this.onChange(dirtyNodes);
|
|
514
|
-
return this;
|
|
515
|
-
};
|
|
516
|
-
/** @internal remove dirty and last tried info */
|
|
517
|
-
GridStackEngine.prototype.cleanNodes = function () {
|
|
518
|
-
if (this.batchMode)
|
|
519
|
-
return this;
|
|
520
|
-
this.nodes.forEach(function (n) {
|
|
521
|
-
delete n._dirty;
|
|
522
|
-
delete n._lastTried;
|
|
523
|
-
});
|
|
524
|
-
return this;
|
|
525
|
-
};
|
|
526
|
-
/** @internal called to save initial position/size to track real dirty state.
|
|
527
|
-
* Note: should be called right after we call change event (so next API is can detect changes)
|
|
528
|
-
* as well as right before we start move/resize/enter (so we can restore items to prev values) */
|
|
529
|
-
GridStackEngine.prototype.saveInitial = function () {
|
|
530
|
-
this.nodes.forEach(function (n) {
|
|
531
|
-
n._orig = utils_1.Utils.copyPos({}, n);
|
|
532
|
-
delete n._dirty;
|
|
533
|
-
});
|
|
534
|
-
this._hasLocked = this.nodes.some(function (n) { return n.locked; });
|
|
535
|
-
return this;
|
|
536
|
-
};
|
|
537
|
-
/** @internal restore all the nodes back to initial values (called when we leave) */
|
|
538
|
-
GridStackEngine.prototype.restoreInitial = function () {
|
|
539
|
-
this.nodes.forEach(function (n) {
|
|
540
|
-
if (!n._orig || utils_1.Utils.samePos(n, n._orig))
|
|
541
|
-
return;
|
|
542
|
-
utils_1.Utils.copyPos(n, n._orig);
|
|
543
|
-
n._dirty = true;
|
|
544
|
-
});
|
|
545
|
-
this._notify();
|
|
546
|
-
return this;
|
|
547
|
-
};
|
|
548
|
-
/** find the first available empty spot for the given node width/height, updating the x,y attributes. return true if found.
|
|
549
|
-
* optionally you can pass your own existing node list and column count, otherwise defaults to that engine data.
|
|
550
|
-
* Optionally pass a widget to start search AFTER, meaning the order will remain the same but possibly have empty slots we skipped
|
|
551
|
-
*/
|
|
552
|
-
GridStackEngine.prototype.findEmptyPosition = function (node, nodeList, column, after) {
|
|
553
|
-
if (nodeList === void 0) { nodeList = this.nodes; }
|
|
554
|
-
if (column === void 0) { column = this.column; }
|
|
555
|
-
var start = after ? after.y * column + (after.x + after.w) : 0;
|
|
556
|
-
var found = false;
|
|
557
|
-
var _loop_1 = function (i) {
|
|
558
|
-
var x = i % column;
|
|
559
|
-
var y = Math.floor(i / column);
|
|
560
|
-
if (x + node.w > column) {
|
|
561
|
-
return "continue";
|
|
562
|
-
}
|
|
563
|
-
var box = { x: x, y: y, w: node.w, h: node.h };
|
|
564
|
-
if (!nodeList.find(function (n) { return utils_1.Utils.isIntercepted(box, n); })) {
|
|
565
|
-
if (node.x !== x || node.y !== y)
|
|
566
|
-
node._dirty = true;
|
|
567
|
-
node.x = x;
|
|
568
|
-
node.y = y;
|
|
569
|
-
delete node.autoPosition;
|
|
570
|
-
found = true;
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
for (var i = start; !found; ++i) {
|
|
574
|
-
_loop_1(i);
|
|
575
|
-
}
|
|
576
|
-
return found;
|
|
577
|
-
};
|
|
578
|
-
/** call to add the given node to our list, fixing collision and re-packing */
|
|
579
|
-
GridStackEngine.prototype.addNode = function (node, triggerAddEvent, after) {
|
|
580
|
-
if (triggerAddEvent === void 0) { triggerAddEvent = false; }
|
|
581
|
-
var dup = this.nodes.find(function (n) { return n._id === node._id; });
|
|
582
|
-
if (dup)
|
|
583
|
-
return dup; // prevent inserting twice! return it instead.
|
|
584
|
-
// skip prepareNode if we're in middle of column resize (not new) but do check for bounds!
|
|
585
|
-
this._inColumnResize ? this.nodeBoundFix(node) : this.prepareNode(node);
|
|
586
|
-
delete node._temporaryRemoved;
|
|
587
|
-
delete node._removeDOM;
|
|
588
|
-
var skipCollision;
|
|
589
|
-
if (node.autoPosition && this.findEmptyPosition(node, this.nodes, this.column, after)) {
|
|
590
|
-
delete node.autoPosition; // found our slot
|
|
591
|
-
skipCollision = true;
|
|
592
|
-
}
|
|
593
|
-
this.nodes.push(node);
|
|
594
|
-
if (triggerAddEvent) {
|
|
595
|
-
this.addedNodes.push(node);
|
|
596
|
-
}
|
|
597
|
-
if (!skipCollision)
|
|
598
|
-
this._fixCollisions(node);
|
|
599
|
-
if (!this.batchMode) {
|
|
600
|
-
this._packNodes()._notify();
|
|
601
|
-
}
|
|
602
|
-
return node;
|
|
603
|
-
};
|
|
604
|
-
GridStackEngine.prototype.removeNode = function (node, removeDOM, triggerEvent) {
|
|
605
|
-
if (removeDOM === void 0) { removeDOM = true; }
|
|
606
|
-
if (triggerEvent === void 0) { triggerEvent = false; }
|
|
607
|
-
if (!this.nodes.find(function (n) { return n._id === node._id; })) {
|
|
608
|
-
// TEST console.log(`Error: GridStackEngine.removeNode() node._id=${node._id} not found!`)
|
|
609
|
-
return this;
|
|
610
|
-
}
|
|
611
|
-
if (triggerEvent) { // we wait until final drop to manually track removed items (rather than during drag)
|
|
612
|
-
this.removedNodes.push(node);
|
|
613
|
-
}
|
|
614
|
-
if (removeDOM)
|
|
615
|
-
node._removeDOM = true; // let CB remove actual HTML (used to set _id to null, but then we loose layout info)
|
|
616
|
-
// don't use 'faster' .splice(findIndex(),1) in case node isn't in our list, or in multiple times.
|
|
617
|
-
this.nodes = this.nodes.filter(function (n) { return n._id !== node._id; });
|
|
618
|
-
if (!node._isAboutToRemove)
|
|
619
|
-
this._packNodes(); // if dragged out, no need to relayout as already done...
|
|
620
|
-
this._notify([node]);
|
|
621
|
-
return this;
|
|
622
|
-
};
|
|
623
|
-
GridStackEngine.prototype.removeAll = function (removeDOM, triggerEvent) {
|
|
624
|
-
if (removeDOM === void 0) { removeDOM = true; }
|
|
625
|
-
if (triggerEvent === void 0) { triggerEvent = true; }
|
|
626
|
-
delete this._layouts;
|
|
627
|
-
if (!this.nodes.length)
|
|
628
|
-
return this;
|
|
629
|
-
removeDOM && this.nodes.forEach(function (n) { return n._removeDOM = true; }); // let CB remove actual HTML (used to set _id to null, but then we loose layout info)
|
|
630
|
-
var removedNodes = this.nodes;
|
|
631
|
-
this.removedNodes = triggerEvent ? removedNodes : [];
|
|
632
|
-
this.nodes = [];
|
|
633
|
-
return this._notify(removedNodes);
|
|
634
|
-
};
|
|
635
|
-
/** checks if item can be moved (layout constrain) vs moveNode(), returning true if was able to move.
|
|
636
|
-
* In more complicated cases (maxRow) it will attempt at moving the item and fixing
|
|
637
|
-
* others in a clone first, then apply those changes if still within specs. */
|
|
638
|
-
GridStackEngine.prototype.moveNodeCheck = function (node, o) {
|
|
639
|
-
var _this = this;
|
|
640
|
-
// if (node.locked) return false;
|
|
641
|
-
if (!this.changedPosConstrain(node, o))
|
|
642
|
-
return false;
|
|
643
|
-
o.pack = true;
|
|
644
|
-
// simpler case: move item directly...
|
|
645
|
-
if (!this.maxRow) {
|
|
646
|
-
return this.moveNode(node, o);
|
|
647
|
-
}
|
|
648
|
-
// complex case: create a clone with NO maxRow (will check for out of bounds at the end)
|
|
649
|
-
var clonedNode;
|
|
650
|
-
var clone = new GridStackEngine({
|
|
651
|
-
column: this.column,
|
|
652
|
-
float: this.float,
|
|
653
|
-
nodes: this.nodes.map(function (n) {
|
|
654
|
-
if (n._id === node._id) {
|
|
655
|
-
clonedNode = __assign({}, n);
|
|
656
|
-
return clonedNode;
|
|
657
|
-
}
|
|
658
|
-
return __assign({}, n);
|
|
659
|
-
})
|
|
660
|
-
});
|
|
661
|
-
if (!clonedNode)
|
|
662
|
-
return false;
|
|
663
|
-
// check if we're covering 50% collision and could move, while still being under maxRow or at least not making it worse
|
|
664
|
-
// (case where widget was somehow added past our max #2449)
|
|
665
|
-
var canMove = clone.moveNode(clonedNode, o) && clone.getRow() <= Math.max(this.getRow(), this.maxRow);
|
|
666
|
-
// else check if we can force a swap (float=true, or different shapes) on non-resize
|
|
667
|
-
if (!canMove && !o.resizing && o.collide) {
|
|
668
|
-
var collide = o.collide.el.gridstackNode; // find the source node the clone collided with at 50%
|
|
669
|
-
if (this.swap(node, collide)) { // swaps and mark dirty
|
|
670
|
-
this._notify();
|
|
671
|
-
return true;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
if (!canMove)
|
|
675
|
-
return false;
|
|
676
|
-
// if clone was able to move, copy those mods over to us now instead of caller trying to do this all over!
|
|
677
|
-
// Note: we can't use the list directly as elements and other parts point to actual node, so copy content
|
|
678
|
-
clone.nodes.filter(function (n) { return n._dirty; }).forEach(function (c) {
|
|
679
|
-
var n = _this.nodes.find(function (a) { return a._id === c._id; });
|
|
680
|
-
if (!n)
|
|
681
|
-
return;
|
|
682
|
-
utils_1.Utils.copyPos(n, c);
|
|
683
|
-
n._dirty = true;
|
|
684
|
-
});
|
|
685
|
-
this._notify();
|
|
686
|
-
return true;
|
|
687
|
-
};
|
|
688
|
-
/** return true if can fit in grid height constrain only (always true if no maxRow) */
|
|
689
|
-
GridStackEngine.prototype.willItFit = function (node) {
|
|
690
|
-
delete node._willFitPos;
|
|
691
|
-
if (!this.maxRow)
|
|
692
|
-
return true;
|
|
693
|
-
// create a clone with NO maxRow and check if still within size
|
|
694
|
-
var clone = new GridStackEngine({
|
|
695
|
-
column: this.column,
|
|
696
|
-
float: this.float,
|
|
697
|
-
nodes: this.nodes.map(function (n) { return __assign({}, n); })
|
|
698
|
-
});
|
|
699
|
-
var n = __assign({}, node); // clone node so we don't mod any settings on it but have full autoPosition and min/max as well! #1687
|
|
700
|
-
this.cleanupNode(n);
|
|
701
|
-
delete n.el;
|
|
702
|
-
delete n._id;
|
|
703
|
-
delete n.content;
|
|
704
|
-
delete n.grid;
|
|
705
|
-
clone.addNode(n);
|
|
706
|
-
if (clone.getRow() <= this.maxRow) {
|
|
707
|
-
node._willFitPos = utils_1.Utils.copyPos({}, n);
|
|
708
|
-
return true;
|
|
709
|
-
}
|
|
710
|
-
return false;
|
|
711
|
-
};
|
|
712
|
-
/** true if x,y or w,h are different after clamping to min/max */
|
|
713
|
-
GridStackEngine.prototype.changedPosConstrain = function (node, p) {
|
|
714
|
-
// first make sure w,h are set for caller
|
|
715
|
-
p.w = p.w || node.w;
|
|
716
|
-
p.h = p.h || node.h;
|
|
717
|
-
if (node.x !== p.x || node.y !== p.y)
|
|
718
|
-
return true;
|
|
719
|
-
// check constrained w,h
|
|
720
|
-
if (node.maxW) {
|
|
721
|
-
p.w = Math.min(p.w, node.maxW);
|
|
722
|
-
}
|
|
723
|
-
if (node.maxH) {
|
|
724
|
-
p.h = Math.min(p.h, node.maxH);
|
|
725
|
-
}
|
|
726
|
-
if (node.minW) {
|
|
727
|
-
p.w = Math.max(p.w, node.minW);
|
|
728
|
-
}
|
|
729
|
-
if (node.minH) {
|
|
730
|
-
p.h = Math.max(p.h, node.minH);
|
|
731
|
-
}
|
|
732
|
-
return (node.w !== p.w || node.h !== p.h);
|
|
733
|
-
};
|
|
734
|
-
/** return true if the passed in node was actually moved (checks for no-op and locked) */
|
|
735
|
-
GridStackEngine.prototype.moveNode = function (node, o) {
|
|
736
|
-
var _a, _b;
|
|
737
|
-
if (!node || /*node.locked ||*/ !o)
|
|
738
|
-
return false;
|
|
739
|
-
var wasUndefinedPack;
|
|
740
|
-
if (o.pack === undefined && !this.batchMode) {
|
|
741
|
-
wasUndefinedPack = o.pack = true;
|
|
742
|
-
}
|
|
743
|
-
// constrain the passed in values and check if we're still changing our node
|
|
744
|
-
if (typeof o.x !== 'number') {
|
|
745
|
-
o.x = node.x;
|
|
746
|
-
}
|
|
747
|
-
if (typeof o.y !== 'number') {
|
|
748
|
-
o.y = node.y;
|
|
749
|
-
}
|
|
750
|
-
if (typeof o.w !== 'number') {
|
|
751
|
-
o.w = node.w;
|
|
752
|
-
}
|
|
753
|
-
if (typeof o.h !== 'number') {
|
|
754
|
-
o.h = node.h;
|
|
755
|
-
}
|
|
756
|
-
var resizing = (node.w !== o.w || node.h !== o.h);
|
|
757
|
-
var nn = utils_1.Utils.copyPos({}, node, true); // get min/max out first, then opt positions next
|
|
758
|
-
utils_1.Utils.copyPos(nn, o);
|
|
759
|
-
this.nodeBoundFix(nn, resizing);
|
|
760
|
-
utils_1.Utils.copyPos(o, nn);
|
|
761
|
-
if (!o.forceCollide && utils_1.Utils.samePos(node, o))
|
|
762
|
-
return false;
|
|
763
|
-
var prevPos = utils_1.Utils.copyPos({}, node);
|
|
764
|
-
// check if we will need to fix collision at our new location
|
|
765
|
-
var collides = this.collideAll(node, nn, o.skip);
|
|
766
|
-
var needToMove = true;
|
|
767
|
-
if (collides.length) {
|
|
768
|
-
var activeDrag = node._moving && !o.nested;
|
|
769
|
-
// check to make sure we actually collided over 50% surface area while dragging
|
|
770
|
-
var collide = activeDrag ? this.directionCollideCoverage(node, o, collides) : collides[0];
|
|
771
|
-
// if we're enabling creation of sub-grids on the fly, see if we're covering 80% of either one, if we didn't already do that
|
|
772
|
-
if (activeDrag && collide && ((_b = (_a = node.grid) === null || _a === void 0 ? void 0 : _a.opts) === null || _b === void 0 ? void 0 : _b.subGridDynamic) && !node.grid._isTemp) {
|
|
773
|
-
var over = utils_1.Utils.areaIntercept(o.rect, collide._rect);
|
|
774
|
-
var a1 = utils_1.Utils.area(o.rect);
|
|
775
|
-
var a2 = utils_1.Utils.area(collide._rect);
|
|
776
|
-
var perc = over / (a1 < a2 ? a1 : a2);
|
|
777
|
-
if (perc > .8) {
|
|
778
|
-
collide.grid.makeSubGrid(collide.el, undefined, node);
|
|
779
|
-
collide = undefined;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
if (collide) {
|
|
783
|
-
needToMove = !this._fixCollisions(node, nn, collide, o); // check if already moved...
|
|
784
|
-
}
|
|
785
|
-
else {
|
|
786
|
-
needToMove = false; // we didn't cover >50% for a move, skip...
|
|
787
|
-
if (wasUndefinedPack)
|
|
788
|
-
delete o.pack;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
// now move (to the original ask vs the collision version which might differ) and repack things
|
|
792
|
-
if (needToMove && !utils_1.Utils.samePos(node, nn)) {
|
|
793
|
-
node._dirty = true;
|
|
794
|
-
utils_1.Utils.copyPos(node, nn);
|
|
795
|
-
}
|
|
796
|
-
if (o.pack) {
|
|
797
|
-
this._packNodes()
|
|
798
|
-
._notify();
|
|
799
|
-
}
|
|
800
|
-
return !utils_1.Utils.samePos(node, prevPos); // pack might have moved things back
|
|
801
|
-
};
|
|
802
|
-
GridStackEngine.prototype.getRow = function () {
|
|
803
|
-
return this.nodes.reduce(function (row, n) { return Math.max(row, n.y + n.h); }, 0);
|
|
804
|
-
};
|
|
805
|
-
GridStackEngine.prototype.beginUpdate = function (node) {
|
|
806
|
-
if (!node._updating) {
|
|
807
|
-
node._updating = true;
|
|
808
|
-
delete node._skipDown;
|
|
809
|
-
if (!this.batchMode)
|
|
810
|
-
this.saveInitial();
|
|
811
|
-
}
|
|
812
|
-
return this;
|
|
813
|
-
};
|
|
814
|
-
GridStackEngine.prototype.endUpdate = function () {
|
|
815
|
-
var n = this.nodes.find(function (n) { return n._updating; });
|
|
816
|
-
if (n) {
|
|
817
|
-
delete n._updating;
|
|
818
|
-
delete n._skipDown;
|
|
819
|
-
}
|
|
820
|
-
return this;
|
|
821
|
-
};
|
|
822
|
-
/** saves a copy of the largest column layout (eg 12 even when rendering oneColumnMode) so we don't loose orig layout,
|
|
823
|
-
* returning a list of widgets for serialization */
|
|
824
|
-
GridStackEngine.prototype.save = function (saveElement, saveCB) {
|
|
825
|
-
var _a;
|
|
826
|
-
if (saveElement === void 0) { saveElement = true; }
|
|
827
|
-
// use the highest layout for any saved info so we can have full detail on reload #1849
|
|
828
|
-
var len = (_a = this._layouts) === null || _a === void 0 ? void 0 : _a.length;
|
|
829
|
-
var layout = len && this.column !== (len - 1) ? this._layouts[len - 1] : null;
|
|
830
|
-
var list = [];
|
|
831
|
-
this.sortNodes();
|
|
832
|
-
this.nodes.forEach(function (n) {
|
|
833
|
-
var wl = layout === null || layout === void 0 ? void 0 : layout.find(function (l) { return l._id === n._id; });
|
|
834
|
-
// use layout info fields instead if set
|
|
835
|
-
var w = __assign(__assign({}, n), (wl || {}));
|
|
836
|
-
utils_1.Utils.removeInternalForSave(w, !saveElement);
|
|
837
|
-
if (saveCB)
|
|
838
|
-
saveCB(n, w);
|
|
839
|
-
list.push(w);
|
|
840
|
-
});
|
|
841
|
-
return list;
|
|
842
|
-
};
|
|
843
|
-
/** @internal called whenever a node is added or moved - updates the cached layouts */
|
|
844
|
-
GridStackEngine.prototype.layoutsNodesChange = function (nodes) {
|
|
845
|
-
var _this = this;
|
|
846
|
-
if (!this._layouts || this._inColumnResize)
|
|
847
|
-
return this;
|
|
848
|
-
// remove smaller layouts - we will re-generate those on the fly... larger ones need to update
|
|
849
|
-
this._layouts.forEach(function (layout, column) {
|
|
850
|
-
if (!layout || column === _this.column)
|
|
851
|
-
return _this;
|
|
852
|
-
if (column < _this.column) {
|
|
853
|
-
_this._layouts[column] = undefined;
|
|
854
|
-
}
|
|
855
|
-
else {
|
|
856
|
-
// we save the original x,y,w (h isn't cached) to see what actually changed to propagate better.
|
|
857
|
-
// NOTE: we don't need to check against out of bound scaling/moving as that will be done when using those cache values. #1785
|
|
858
|
-
var ratio_1 = column / _this.column;
|
|
859
|
-
nodes.forEach(function (node) {
|
|
860
|
-
if (!node._orig)
|
|
861
|
-
return; // didn't change (newly added ?)
|
|
862
|
-
var n = layout.find(function (l) { return l._id === node._id; });
|
|
863
|
-
if (!n)
|
|
864
|
-
return; // no cache for new nodes. Will use those values.
|
|
865
|
-
// Y changed, push down same amount
|
|
866
|
-
// TODO: detect doing item 'swaps' will help instead of move (especially in 1 column mode)
|
|
867
|
-
if (n.y >= 0 && node.y !== node._orig.y) {
|
|
868
|
-
n.y += (node.y - node._orig.y);
|
|
869
|
-
}
|
|
870
|
-
// X changed, scale from new position
|
|
871
|
-
if (node.x !== node._orig.x) {
|
|
872
|
-
n.x = Math.round(node.x * ratio_1);
|
|
873
|
-
}
|
|
874
|
-
// width changed, scale from new width
|
|
875
|
-
if (node.w !== node._orig.w) {
|
|
876
|
-
n.w = Math.round(node.w * ratio_1);
|
|
877
|
-
}
|
|
878
|
-
// ...height always carries over from cache
|
|
879
|
-
});
|
|
880
|
-
}
|
|
881
|
-
});
|
|
882
|
-
return this;
|
|
883
|
-
};
|
|
884
|
-
/**
|
|
885
|
-
* @internal Called to scale the widget width & position up/down based on the column change.
|
|
886
|
-
* Note we store previous layouts (especially original ones) to make it possible to go
|
|
887
|
-
* from say 12 -> 1 -> 12 and get back to where we were.
|
|
888
|
-
*
|
|
889
|
-
* @param prevColumn previous number of columns
|
|
890
|
-
* @param column new column number
|
|
891
|
-
* @param layout specify the type of re-layout that will happen (position, size, etc...).
|
|
892
|
-
* Note: items will never be outside of the current column boundaries. default (moveScale). Ignored for 1 column
|
|
893
|
-
*/
|
|
894
|
-
GridStackEngine.prototype.columnChanged = function (prevColumn, column, layout) {
|
|
895
|
-
var _this = this;
|
|
896
|
-
var _a;
|
|
897
|
-
if (layout === void 0) { layout = 'moveScale'; }
|
|
898
|
-
if (!this.nodes.length || !column || prevColumn === column)
|
|
899
|
-
return this;
|
|
900
|
-
// simpler shortcuts layouts
|
|
901
|
-
var doCompact = layout === 'compact' || layout === 'list';
|
|
902
|
-
if (doCompact) {
|
|
903
|
-
this.sortNodes(1); // sort with original layout once and only once (new column will affect order otherwise)
|
|
904
|
-
}
|
|
905
|
-
// cache the current layout in case they want to go back (like 12 -> 1 -> 12) as it requires original data IFF we're sizing down (see below)
|
|
906
|
-
if (column < prevColumn)
|
|
907
|
-
this.cacheLayout(this.nodes, prevColumn);
|
|
908
|
-
this.batchUpdate(); // do this EARLY as it will call saveInitial() so we can detect where we started for _dirty and collision
|
|
909
|
-
var newNodes = [];
|
|
910
|
-
var nodes = doCompact ? this.nodes : utils_1.Utils.sort(this.nodes, -1); // current column reverse sorting so we can insert last to front (limit collision)
|
|
911
|
-
// see if we have cached previous layout IFF we are going up in size (restore) otherwise always
|
|
912
|
-
// generate next size down from where we are (looks more natural as you gradually size down).
|
|
913
|
-
if (column > prevColumn && this._layouts) {
|
|
914
|
-
var cacheNodes = this._layouts[column] || [];
|
|
915
|
-
// ...if not, start with the largest layout (if not already there) as down-scaling is more accurate
|
|
916
|
-
// by pretending we came from that larger column by assigning those values as starting point
|
|
917
|
-
var lastIndex = this._layouts.length - 1;
|
|
918
|
-
if (!cacheNodes.length && prevColumn !== lastIndex && ((_a = this._layouts[lastIndex]) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
919
|
-
prevColumn = lastIndex;
|
|
920
|
-
this._layouts[lastIndex].forEach(function (cacheNode) {
|
|
921
|
-
var _a, _b, _c;
|
|
922
|
-
var n = nodes.find(function (n) { return n._id === cacheNode._id; });
|
|
923
|
-
if (n) {
|
|
924
|
-
// still current, use cache info positions
|
|
925
|
-
if (!doCompact && !cacheNode.autoPosition) {
|
|
926
|
-
n.x = (_a = cacheNode.x) !== null && _a !== void 0 ? _a : n.x;
|
|
927
|
-
n.y = (_b = cacheNode.y) !== null && _b !== void 0 ? _b : n.y;
|
|
928
|
-
}
|
|
929
|
-
n.w = (_c = cacheNode.w) !== null && _c !== void 0 ? _c : n.w;
|
|
930
|
-
if (cacheNode.x == undefined || cacheNode.y === undefined)
|
|
931
|
-
n.autoPosition = true;
|
|
932
|
-
}
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
// if we found cache re-use those nodes that are still current
|
|
936
|
-
cacheNodes.forEach(function (cacheNode) {
|
|
937
|
-
var _a, _b, _c;
|
|
938
|
-
var j = nodes.findIndex(function (n) { return n._id === cacheNode._id; });
|
|
939
|
-
if (j !== -1) {
|
|
940
|
-
var n = nodes[j];
|
|
941
|
-
// still current, use cache info positions
|
|
942
|
-
if (doCompact) {
|
|
943
|
-
n.w = cacheNode.w; // only w is used, and don't trim the list
|
|
944
|
-
return;
|
|
945
|
-
}
|
|
946
|
-
if (cacheNode.autoPosition || isNaN(cacheNode.x) || isNaN(cacheNode.y)) {
|
|
947
|
-
_this.findEmptyPosition(cacheNode, newNodes);
|
|
948
|
-
}
|
|
949
|
-
if (!cacheNode.autoPosition) {
|
|
950
|
-
n.x = (_a = cacheNode.x) !== null && _a !== void 0 ? _a : n.x;
|
|
951
|
-
n.y = (_b = cacheNode.y) !== null && _b !== void 0 ? _b : n.y;
|
|
952
|
-
n.w = (_c = cacheNode.w) !== null && _c !== void 0 ? _c : n.w;
|
|
953
|
-
newNodes.push(n);
|
|
954
|
-
}
|
|
955
|
-
nodes.splice(j, 1);
|
|
956
|
-
}
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
// much simpler layout that just compacts
|
|
960
|
-
if (doCompact) {
|
|
961
|
-
this.compact(layout, false);
|
|
962
|
-
}
|
|
963
|
-
else {
|
|
964
|
-
// ...and add any extra non-cached ones
|
|
965
|
-
if (nodes.length) {
|
|
966
|
-
if (typeof layout === 'function') {
|
|
967
|
-
layout(column, prevColumn, newNodes, nodes);
|
|
968
|
-
}
|
|
969
|
-
else {
|
|
970
|
-
var ratio_2 = (doCompact || layout === 'none') ? 1 : column / prevColumn;
|
|
971
|
-
var move_1 = (layout === 'move' || layout === 'moveScale');
|
|
972
|
-
var scale_1 = (layout === 'scale' || layout === 'moveScale');
|
|
973
|
-
nodes.forEach(function (node) {
|
|
974
|
-
// NOTE: x + w could be outside of the grid, but addNode() below will handle that
|
|
975
|
-
node.x = (column === 1 ? 0 : (move_1 ? Math.round(node.x * ratio_2) : Math.min(node.x, column - 1)));
|
|
976
|
-
node.w = ((column === 1 || prevColumn === 1) ? 1 : scale_1 ? (Math.round(node.w * ratio_2) || 1) : (Math.min(node.w, column)));
|
|
977
|
-
newNodes.push(node);
|
|
978
|
-
});
|
|
979
|
-
nodes = [];
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
// finally re-layout them in reverse order (to get correct placement)
|
|
983
|
-
newNodes = utils_1.Utils.sort(newNodes, -1);
|
|
984
|
-
this._inColumnResize = true; // prevent cache update
|
|
985
|
-
this.nodes = []; // pretend we have no nodes to start with (add() will use same structures) to simplify layout
|
|
986
|
-
newNodes.forEach(function (node) {
|
|
987
|
-
_this.addNode(node, false); // 'false' for add event trigger
|
|
988
|
-
delete node._orig; // make sure the commit doesn't try to restore things back to original
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
this.nodes.forEach(function (n) { return delete n._orig; }); // clear _orig before batch=false so it doesn't handle float=true restore
|
|
992
|
-
this.batchUpdate(false, !doCompact);
|
|
993
|
-
delete this._inColumnResize;
|
|
994
|
-
return this;
|
|
995
|
-
};
|
|
996
|
-
/**
|
|
997
|
-
* call to cache the given layout internally to the given location so we can restore back when column changes size
|
|
998
|
-
* @param nodes list of nodes
|
|
999
|
-
* @param column corresponding column index to save it under
|
|
1000
|
-
* @param clear if true, will force other caches to be removed (default false)
|
|
1001
|
-
*/
|
|
1002
|
-
GridStackEngine.prototype.cacheLayout = function (nodes, column, clear) {
|
|
1003
|
-
var _this = this;
|
|
1004
|
-
if (clear === void 0) { clear = false; }
|
|
1005
|
-
var copy = [];
|
|
1006
|
-
nodes.forEach(function (n, i) {
|
|
1007
|
-
var _a;
|
|
1008
|
-
// make sure we have an id in case this is new layout, else re-use id already set
|
|
1009
|
-
if (n._id === undefined) {
|
|
1010
|
-
var existing = n.id ? _this.nodes.find(function (n2) { return n2.id === n.id; }) : undefined; // find existing node using users id
|
|
1011
|
-
n._id = (_a = existing === null || existing === void 0 ? void 0 : existing._id) !== null && _a !== void 0 ? _a : GridStackEngine._idSeq++;
|
|
1012
|
-
}
|
|
1013
|
-
copy[i] = { x: n.x, y: n.y, w: n.w, _id: n._id }; // only thing we change is x,y,w and id to find it back
|
|
1014
|
-
});
|
|
1015
|
-
this._layouts = clear ? [] : this._layouts || []; // use array to find larger quick
|
|
1016
|
-
this._layouts[column] = copy;
|
|
1017
|
-
return this;
|
|
1018
|
-
};
|
|
1019
|
-
/**
|
|
1020
|
-
* call to cache the given node layout internally to the given location so we can restore back when column changes size
|
|
1021
|
-
* @param node single node to cache
|
|
1022
|
-
* @param column corresponding column index to save it under
|
|
1023
|
-
*/
|
|
1024
|
-
GridStackEngine.prototype.cacheOneLayout = function (n, column) {
|
|
1025
|
-
var _a;
|
|
1026
|
-
n._id = (_a = n._id) !== null && _a !== void 0 ? _a : GridStackEngine._idSeq++;
|
|
1027
|
-
var l = { x: n.x, y: n.y, w: n.w, _id: n._id };
|
|
1028
|
-
if (n.autoPosition || n.x === undefined) {
|
|
1029
|
-
delete l.x;
|
|
1030
|
-
delete l.y;
|
|
1031
|
-
if (n.autoPosition)
|
|
1032
|
-
l.autoPosition = true;
|
|
1033
|
-
}
|
|
1034
|
-
this._layouts = this._layouts || [];
|
|
1035
|
-
this._layouts[column] = this._layouts[column] || [];
|
|
1036
|
-
var index = this.findCacheLayout(n, column);
|
|
1037
|
-
if (index === -1)
|
|
1038
|
-
this._layouts[column].push(l);
|
|
1039
|
-
else
|
|
1040
|
-
this._layouts[column][index] = l;
|
|
1041
|
-
return this;
|
|
1042
|
-
};
|
|
1043
|
-
GridStackEngine.prototype.findCacheLayout = function (n, column) {
|
|
1044
|
-
var _a, _b, _c;
|
|
1045
|
-
return (_c = (_b = (_a = this._layouts) === null || _a === void 0 ? void 0 : _a[column]) === null || _b === void 0 ? void 0 : _b.findIndex(function (l) { return l._id === n._id; })) !== null && _c !== void 0 ? _c : -1;
|
|
1046
|
-
};
|
|
1047
|
-
GridStackEngine.prototype.removeNodeFromLayoutCache = function (n) {
|
|
1048
|
-
if (!this._layouts) {
|
|
1049
|
-
return;
|
|
1050
|
-
}
|
|
1051
|
-
for (var i = 0; i < this._layouts.length; i++) {
|
|
1052
|
-
var index = this.findCacheLayout(n, i);
|
|
1053
|
-
if (index !== -1) {
|
|
1054
|
-
this._layouts[i].splice(index, 1);
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
};
|
|
1058
|
-
/** called to remove all internal values but the _id */
|
|
1059
|
-
GridStackEngine.prototype.cleanupNode = function (node) {
|
|
1060
|
-
for (var prop in node) {
|
|
1061
|
-
if (prop[0] === '_' && prop !== '_id')
|
|
1062
|
-
delete node[prop];
|
|
1063
|
-
}
|
|
1064
|
-
return this;
|
|
1065
|
-
};
|
|
1066
|
-
/** @internal unique global internal _id counter */
|
|
1067
|
-
GridStackEngine._idSeq = 0;
|
|
1068
|
-
return GridStackEngine;
|
|
1069
|
-
}());
|
|
1070
|
-
//# sourceMappingURL=gridstack-engine.js.map
|