gridstack 10.3.1 → 11.0.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 +37 -3
- package/dist/angular/README.md +47 -25
- package/dist/angular/{esm2020 → esm2022}/gridstack-angular.mjs +5 -5
- package/dist/angular/esm2022/index.mjs +8 -0
- package/dist/angular/esm2022/lib/base-widget.mjs +34 -0
- package/dist/angular/esm2022/lib/gridstack-item.component.mjs +72 -0
- package/dist/angular/esm2022/lib/gridstack.component.mjs +300 -0
- package/dist/angular/esm2022/lib/gridstack.module.mjs +39 -0
- package/dist/angular/{fesm2020 → fesm2022}/gridstack-angular.mjs +400 -369
- package/dist/angular/fesm2022/gridstack-angular.mjs.map +1 -0
- package/dist/angular/index.d.ts +4 -5
- package/dist/angular/lib/base-widget.d.ts +18 -16
- package/dist/angular/lib/gridstack-item.component.d.ts +37 -37
- package/dist/angular/lib/gridstack.component.d.ts +135 -129
- package/dist/angular/lib/gridstack.module.d.ts +10 -10
- package/dist/angular/src/base-widget.ts +10 -2
- package/dist/angular/src/gridstack-item.component.ts +11 -7
- package/dist/angular/src/gridstack.component.ts +67 -44
- package/dist/angular/src/gridstack.module.ts +2 -2
- package/dist/dd-base-impl.d.ts +2 -2
- package/dist/dd-base-impl.js +2 -2
- package/dist/dd-base-impl.js.map +1 -1
- package/dist/dd-draggable.d.ts +7 -16
- package/dist/dd-draggable.js +22 -34
- package/dist/dd-draggable.js.map +1 -1
- package/dist/dd-droppable.d.ts +2 -2
- package/dist/dd-droppable.js +2 -2
- package/dist/dd-droppable.js.map +1 -1
- package/dist/dd-element.d.ts +5 -5
- package/dist/dd-element.js +2 -2
- package/dist/dd-element.js.map +1 -1
- package/dist/dd-gridstack.d.ts +4 -4
- package/dist/dd-gridstack.js +8 -8
- package/dist/dd-gridstack.js.map +1 -1
- package/dist/dd-manager.d.ts +2 -2
- package/dist/dd-manager.js +2 -2
- package/dist/dd-manager.js.map +1 -1
- package/dist/dd-resizable-handle.d.ts +2 -2
- package/dist/dd-resizable-handle.js +3 -3
- package/dist/dd-resizable-handle.js.map +1 -1
- package/dist/dd-resizable.d.ts +2 -2
- package/dist/dd-resizable.js +4 -4
- package/dist/dd-resizable.js.map +1 -1
- package/dist/dd-touch.d.ts +2 -2
- package/dist/dd-touch.js +2 -2
- package/dist/dd-touch.js.map +1 -1
- package/dist/es5/dd-base-impl.d.ts +2 -2
- package/dist/es5/dd-base-impl.js +2 -2
- package/dist/es5/dd-base-impl.js.map +1 -1
- package/dist/es5/dd-draggable.d.ts +7 -16
- package/dist/es5/dd-draggable.js +19 -29
- package/dist/es5/dd-draggable.js.map +1 -1
- package/dist/es5/dd-droppable.d.ts +2 -2
- package/dist/es5/dd-droppable.js +2 -2
- package/dist/es5/dd-droppable.js.map +1 -1
- package/dist/es5/dd-element.d.ts +5 -5
- package/dist/es5/dd-element.js +2 -2
- package/dist/es5/dd-element.js.map +1 -1
- package/dist/es5/dd-gridstack.d.ts +4 -4
- package/dist/es5/dd-gridstack.js +9 -6
- package/dist/es5/dd-gridstack.js.map +1 -1
- package/dist/es5/dd-manager.d.ts +2 -2
- package/dist/es5/dd-manager.js +2 -2
- package/dist/es5/dd-manager.js.map +1 -1
- package/dist/es5/dd-resizable-handle.d.ts +2 -2
- package/dist/es5/dd-resizable-handle.js +2 -2
- package/dist/es5/dd-resizable-handle.js.map +1 -1
- package/dist/es5/dd-resizable.d.ts +2 -2
- package/dist/es5/dd-resizable.js +2 -2
- package/dist/es5/dd-resizable.js.map +1 -1
- package/dist/es5/dd-touch.d.ts +2 -2
- package/dist/es5/dd-touch.js +2 -2
- 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 +2 -2
- package/dist/es5/gridstack-all.js.map +1 -1
- package/dist/es5/gridstack-engine.d.ts +2 -2
- package/dist/es5/gridstack-engine.js +5 -5
- package/dist/es5/gridstack-engine.js.map +1 -1
- package/dist/es5/gridstack-poly.js +2 -2
- package/dist/es5/gridstack.d.ts +22 -17
- package/dist/es5/gridstack.js +158 -141
- package/dist/es5/gridstack.js.map +1 -1
- package/dist/es5/types.d.ts +16 -8
- package/dist/es5/types.js +3 -10
- package/dist/es5/types.js.map +1 -1
- package/dist/es5/utils.d.ts +6 -2
- package/dist/es5/utils.js +36 -3
- package/dist/es5/utils.js.map +1 -1
- package/dist/gridstack-all.js +1 -1
- package/dist/gridstack-all.js.LICENSE.txt +2 -2
- package/dist/gridstack-all.js.map +1 -1
- package/dist/gridstack-engine.d.ts +2 -2
- package/dist/gridstack-engine.js +61 -61
- package/dist/gridstack-engine.js.map +1 -1
- package/dist/gridstack-extra.css +1 -1
- package/dist/gridstack.css +2 -2
- package/dist/gridstack.d.ts +22 -17
- package/dist/gridstack.js +244 -226
- package/dist/gridstack.js.map +1 -1
- package/dist/src/gridstack-extra.scss +1 -1
- package/dist/src/gridstack.scss +2 -2
- package/dist/types.d.ts +16 -8
- package/dist/types.js +2 -9
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +6 -2
- package/dist/utils.js +50 -20
- package/dist/utils.js.map +1 -1
- package/doc/CHANGES.md +8 -0
- package/doc/README.md +18 -23
- package/package.json +1 -1
- package/dist/angular/esm2020/lib/base-widget.mjs +0 -30
- package/dist/angular/esm2020/lib/gridstack-item.component.mjs +0 -68
- package/dist/angular/esm2020/lib/gridstack.component.mjs +0 -280
- package/dist/angular/esm2020/lib/gridstack.module.mjs +0 -39
- package/dist/angular/esm2020/public-api.mjs +0 -8
- package/dist/angular/fesm2015/gridstack-angular.mjs +0 -420
- package/dist/angular/fesm2015/gridstack-angular.mjs.map +0 -1
- package/dist/angular/fesm2020/gridstack-angular.mjs.map +0 -1
- package/dist/angular/package.json +0 -31
- package/dist/angular/public-api.d.ts +0 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* gridstack-engine.ts
|
|
3
|
-
* Copyright (c) 2021-
|
|
2
|
+
* gridstack-engine.ts 11.0.0
|
|
3
|
+
* Copyright (c) 2021-2024 Alain Dumesny - see GridStack root license
|
|
4
4
|
*/
|
|
5
5
|
import { GridStackNode, GridStackPosition, GridStackMoveOpts, SaveFcn, CompactOptions } from './types';
|
|
6
6
|
/** callback to update the DOM attributes since this class is generic (no HTML or other info) for items that changed - see _notify() */
|
package/dist/gridstack-engine.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* gridstack-engine.ts
|
|
3
|
-
* Copyright (c) 2021-
|
|
2
|
+
* gridstack-engine.ts 11.0.0
|
|
3
|
+
* Copyright (c) 2021-2024 Alain Dumesny - see GridStack root license
|
|
4
4
|
*/
|
|
5
5
|
import { Utils } from './utils';
|
|
6
6
|
/**
|
|
@@ -61,7 +61,7 @@ class GridStackEngine {
|
|
|
61
61
|
collide = this.collide(node, area, opt.skip); // force new hit
|
|
62
62
|
}
|
|
63
63
|
let didMove = false;
|
|
64
|
-
|
|
64
|
+
const newOpt = { nested: true, pack: false };
|
|
65
65
|
while (collide = collide || this.collide(node, area, opt.skip)) { // could collide with more than 1 item... so repeat for each
|
|
66
66
|
let moved;
|
|
67
67
|
// 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,
|
|
@@ -108,8 +108,8 @@ class GridStackEngine {
|
|
|
108
108
|
directionCollideCoverage(node, o, collides) {
|
|
109
109
|
if (!o.rect || !node._rect)
|
|
110
110
|
return;
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
const r0 = node._rect; // where started
|
|
112
|
+
const r = { ...o.rect }; // where we are
|
|
113
113
|
// update dragged rect to show where it's coming from (above or below, etc...)
|
|
114
114
|
if (r.y > r0.y) {
|
|
115
115
|
r.h += r.y - r0.y;
|
|
@@ -131,7 +131,7 @@ class GridStackEngine {
|
|
|
131
131
|
if (n.locked || !n._rect) {
|
|
132
132
|
break;
|
|
133
133
|
}
|
|
134
|
-
|
|
134
|
+
const r2 = n._rect; // overlapping target
|
|
135
135
|
let yOver = Number.MAX_VALUE, xOver = Number.MAX_VALUE;
|
|
136
136
|
// depending on which side we started from, compute the overlap % of coverage
|
|
137
137
|
// (ex: from above/below we only compute the max horizontal line coverage)
|
|
@@ -147,7 +147,7 @@ class GridStackEngine {
|
|
|
147
147
|
else if (r0.x + r0.w > r2.x + r2.w) { // from the right
|
|
148
148
|
xOver = ((r2.x + r2.w) - r.x) / r2.w;
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
const over = Math.min(xOver, yOver);
|
|
151
151
|
if (over > overMax) {
|
|
152
152
|
overMax = over;
|
|
153
153
|
collide = n;
|
|
@@ -159,11 +159,11 @@ class GridStackEngine {
|
|
|
159
159
|
/** does a pixel coverage returning the node that has the most coverage by area */
|
|
160
160
|
/*
|
|
161
161
|
protected collideCoverage(r: GridStackPosition, collides: GridStackNode[]): {collide: GridStackNode, over: number} {
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
const collide: GridStackNode;
|
|
163
|
+
const overMax = 0;
|
|
164
164
|
collides.forEach(n => {
|
|
165
165
|
if (n.locked || !n._rect) return;
|
|
166
|
-
|
|
166
|
+
const over = Utils.areaIntercept(r, n._rect);
|
|
167
167
|
if (over > overMax) {
|
|
168
168
|
overMax = over;
|
|
169
169
|
collide = n;
|
|
@@ -187,7 +187,7 @@ class GridStackEngine {
|
|
|
187
187
|
if (!b || b.locked || !a || a.locked)
|
|
188
188
|
return false;
|
|
189
189
|
function _doSwap() {
|
|
190
|
-
|
|
190
|
+
const x = b.x, y = b.y;
|
|
191
191
|
b.x = a.x;
|
|
192
192
|
b.y = a.y; // b -> a position
|
|
193
193
|
if (a.h != b.h) {
|
|
@@ -214,7 +214,7 @@ class GridStackEngine {
|
|
|
214
214
|
// check for taking same columns (but different height) and touching
|
|
215
215
|
if (a.w === b.w && a.x === b.x && (touching || (touching = Utils.isTouching(a, b)))) {
|
|
216
216
|
if (b.y < a.y) {
|
|
217
|
-
|
|
217
|
+
const t = a;
|
|
218
218
|
a = b;
|
|
219
219
|
b = t;
|
|
220
220
|
} // swap a <-> b vars so a is first
|
|
@@ -225,7 +225,7 @@ class GridStackEngine {
|
|
|
225
225
|
// check if taking same row (but different width) and touching
|
|
226
226
|
if (a.h === b.h && a.y === b.y && (touching || (touching = Utils.isTouching(a, b)))) {
|
|
227
227
|
if (b.x < a.x) {
|
|
228
|
-
|
|
228
|
+
const t = a;
|
|
229
229
|
a = b;
|
|
230
230
|
b = t;
|
|
231
231
|
} // swap a <-> b vars so a is first
|
|
@@ -234,7 +234,7 @@ class GridStackEngine {
|
|
|
234
234
|
return false;
|
|
235
235
|
}
|
|
236
236
|
isAreaEmpty(x, y, w, h) {
|
|
237
|
-
|
|
237
|
+
const nn = { x: x || 0, y: y || 0, w: w || 1, h: h || 1 };
|
|
238
238
|
return !this.collide(nn);
|
|
239
239
|
}
|
|
240
240
|
/** 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 */
|
|
@@ -249,7 +249,7 @@ class GridStackEngine {
|
|
|
249
249
|
const wasColumnResize = this._inColumnResize;
|
|
250
250
|
if (!wasColumnResize)
|
|
251
251
|
this._inColumnResize = true; // faster addNode()
|
|
252
|
-
|
|
252
|
+
const copyNodes = this.nodes;
|
|
253
253
|
this.nodes = []; // pretend we have no nodes to conflict layout to start with...
|
|
254
254
|
copyNodes.forEach((n, index, list) => {
|
|
255
255
|
let after;
|
|
@@ -296,7 +296,7 @@ class GridStackEngine {
|
|
|
296
296
|
let newY = n.y;
|
|
297
297
|
while (newY > n._orig.y) {
|
|
298
298
|
--newY;
|
|
299
|
-
|
|
299
|
+
const collide = this.collide(n, { x: n.x, y: newY, w: n.w, h: n.h });
|
|
300
300
|
if (!collide) {
|
|
301
301
|
n._dirty = true;
|
|
302
302
|
n.y = newY;
|
|
@@ -310,8 +310,8 @@ class GridStackEngine {
|
|
|
310
310
|
if (n.locked)
|
|
311
311
|
return;
|
|
312
312
|
while (n.y > 0) {
|
|
313
|
-
|
|
314
|
-
|
|
313
|
+
const newY = i === 0 ? 0 : n.y - 1;
|
|
314
|
+
const canBeMoved = i === 0 || !this.collide(n, { x: n.x, y: newY, w: n.w, h: n.h });
|
|
315
315
|
if (!canBeMoved)
|
|
316
316
|
break;
|
|
317
317
|
// Note: must be dirty (from last position) for GridStack::OnChange CB to update positions
|
|
@@ -336,7 +336,7 @@ class GridStackEngine {
|
|
|
336
336
|
node.autoPosition = true;
|
|
337
337
|
}
|
|
338
338
|
// assign defaults for missing required fields
|
|
339
|
-
|
|
339
|
+
const defaults = { x: 0, y: 0, w: 1, h: 1 };
|
|
340
340
|
Utils.defaults(node, defaults);
|
|
341
341
|
if (!node.autoPosition) {
|
|
342
342
|
delete node.autoPosition;
|
|
@@ -380,7 +380,7 @@ class GridStackEngine {
|
|
|
380
380
|
}
|
|
381
381
|
/** part2 of preparing a node to fit inside our grid - checks for x,y,w from grid dimensions */
|
|
382
382
|
nodeBoundFix(node, resizing) {
|
|
383
|
-
|
|
383
|
+
const before = node._orig || Utils.copyPos({}, node);
|
|
384
384
|
if (node.maxW) {
|
|
385
385
|
node.w = Math.min(node.w, node.maxW);
|
|
386
386
|
}
|
|
@@ -398,7 +398,7 @@ class GridStackEngine {
|
|
|
398
398
|
// IFF we're not in the middle of column resizing!
|
|
399
399
|
const saveOrig = (node.x || 0) + (node.w || 1) > this.column;
|
|
400
400
|
if (saveOrig && this.column < 12 && !this._inColumnResize && node._id && this.findCacheLayout(node, 12) === -1) {
|
|
401
|
-
|
|
401
|
+
const copy = { ...node }; // need _id + positions
|
|
402
402
|
if (copy.autoPosition || copy.x === undefined) {
|
|
403
403
|
delete copy.x;
|
|
404
404
|
delete copy.y;
|
|
@@ -459,7 +459,7 @@ class GridStackEngine {
|
|
|
459
459
|
_notify(removedNodes) {
|
|
460
460
|
if (this.batchMode || !this.onChange)
|
|
461
461
|
return this;
|
|
462
|
-
|
|
462
|
+
const dirtyNodes = (removedNodes || []).concat(this.getDirtyNodes());
|
|
463
463
|
this.onChange(dirtyNodes);
|
|
464
464
|
return this;
|
|
465
465
|
}
|
|
@@ -500,15 +500,15 @@ class GridStackEngine {
|
|
|
500
500
|
* Optionally pass a widget to start search AFTER, meaning the order will remain the same but possibly have empty slots we skipped
|
|
501
501
|
*/
|
|
502
502
|
findEmptyPosition(node, nodeList = this.nodes, column = this.column, after) {
|
|
503
|
-
|
|
503
|
+
const start = after ? after.y * column + (after.x + after.w) : 0;
|
|
504
504
|
let found = false;
|
|
505
505
|
for (let i = start; !found; ++i) {
|
|
506
|
-
|
|
507
|
-
|
|
506
|
+
const x = i % column;
|
|
507
|
+
const y = Math.floor(i / column);
|
|
508
508
|
if (x + node.w > column) {
|
|
509
509
|
continue;
|
|
510
510
|
}
|
|
511
|
-
|
|
511
|
+
const box = { x, y, w: node.w, h: node.h };
|
|
512
512
|
if (!nodeList.find(n => Utils.isIntercepted(box, n))) {
|
|
513
513
|
if (node.x !== x || node.y !== y)
|
|
514
514
|
node._dirty = true;
|
|
@@ -522,7 +522,7 @@ class GridStackEngine {
|
|
|
522
522
|
}
|
|
523
523
|
/** call to add the given node to our list, fixing collision and re-packing */
|
|
524
524
|
addNode(node, triggerAddEvent = false, after) {
|
|
525
|
-
|
|
525
|
+
const dup = this.nodes.find(n => n._id === node._id);
|
|
526
526
|
if (dup)
|
|
527
527
|
return dup; // prevent inserting twice! return it instead.
|
|
528
528
|
// skip prepareNode if we're in middle of column resize (not new) but do check for bounds!
|
|
@@ -586,7 +586,7 @@ class GridStackEngine {
|
|
|
586
586
|
}
|
|
587
587
|
// complex case: create a clone with NO maxRow (will check for out of bounds at the end)
|
|
588
588
|
let clonedNode;
|
|
589
|
-
|
|
589
|
+
const clone = new GridStackEngine({
|
|
590
590
|
column: this.column,
|
|
591
591
|
float: this.float,
|
|
592
592
|
nodes: this.nodes.map(n => {
|
|
@@ -601,10 +601,10 @@ class GridStackEngine {
|
|
|
601
601
|
return false;
|
|
602
602
|
// check if we're covering 50% collision and could move, while still being under maxRow or at least not making it worse
|
|
603
603
|
// (case where widget was somehow added past our max #2449)
|
|
604
|
-
|
|
604
|
+
const canMove = clone.moveNode(clonedNode, o) && clone.getRow() <= Math.max(this.getRow(), this.maxRow);
|
|
605
605
|
// else check if we can force a swap (float=true, or different shapes) on non-resize
|
|
606
606
|
if (!canMove && !o.resizing && o.collide) {
|
|
607
|
-
|
|
607
|
+
const collide = o.collide.el.gridstackNode; // find the source node the clone collided with at 50%
|
|
608
608
|
if (this.swap(node, collide)) { // swaps and mark dirty
|
|
609
609
|
this._notify();
|
|
610
610
|
return true;
|
|
@@ -615,7 +615,7 @@ class GridStackEngine {
|
|
|
615
615
|
// if clone was able to move, copy those mods over to us now instead of caller trying to do this all over!
|
|
616
616
|
// Note: we can't use the list directly as elements and other parts point to actual node, so copy content
|
|
617
617
|
clone.nodes.filter(n => n._dirty).forEach(c => {
|
|
618
|
-
|
|
618
|
+
const n = this.nodes.find(a => a._id === c._id);
|
|
619
619
|
if (!n)
|
|
620
620
|
return;
|
|
621
621
|
Utils.copyPos(n, c);
|
|
@@ -630,12 +630,12 @@ class GridStackEngine {
|
|
|
630
630
|
if (!this.maxRow)
|
|
631
631
|
return true;
|
|
632
632
|
// create a clone with NO maxRow and check if still within size
|
|
633
|
-
|
|
633
|
+
const clone = new GridStackEngine({
|
|
634
634
|
column: this.column,
|
|
635
635
|
float: this.float,
|
|
636
636
|
nodes: this.nodes.map(n => { return { ...n }; })
|
|
637
637
|
});
|
|
638
|
-
|
|
638
|
+
const n = { ...node }; // clone node so we don't mod any settings on it but have full autoPosition and min/max as well! #1687
|
|
639
639
|
this.cleanupNode(n);
|
|
640
640
|
delete n.el;
|
|
641
641
|
delete n._id;
|
|
@@ -691,27 +691,27 @@ class GridStackEngine {
|
|
|
691
691
|
if (typeof o.h !== 'number') {
|
|
692
692
|
o.h = node.h;
|
|
693
693
|
}
|
|
694
|
-
|
|
695
|
-
|
|
694
|
+
const resizing = (node.w !== o.w || node.h !== o.h);
|
|
695
|
+
const nn = Utils.copyPos({}, node, true); // get min/max out first, then opt positions next
|
|
696
696
|
Utils.copyPos(nn, o);
|
|
697
697
|
this.nodeBoundFix(nn, resizing);
|
|
698
698
|
Utils.copyPos(o, nn);
|
|
699
699
|
if (!o.forceCollide && Utils.samePos(node, o))
|
|
700
700
|
return false;
|
|
701
|
-
|
|
701
|
+
const prevPos = Utils.copyPos({}, node);
|
|
702
702
|
// check if we will need to fix collision at our new location
|
|
703
|
-
|
|
703
|
+
const collides = this.collideAll(node, nn, o.skip);
|
|
704
704
|
let needToMove = true;
|
|
705
705
|
if (collides.length) {
|
|
706
|
-
|
|
706
|
+
const activeDrag = node._moving && !o.nested;
|
|
707
707
|
// check to make sure we actually collided over 50% surface area while dragging
|
|
708
708
|
let collide = activeDrag ? this.directionCollideCoverage(node, o, collides) : collides[0];
|
|
709
709
|
// 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
|
|
710
710
|
if (activeDrag && collide && node.grid?.opts?.subGridDynamic && !node.grid._isTemp) {
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
711
|
+
const over = Utils.areaIntercept(o.rect, collide._rect);
|
|
712
|
+
const a1 = Utils.area(o.rect);
|
|
713
|
+
const a2 = Utils.area(collide._rect);
|
|
714
|
+
const perc = over / (a1 < a2 ? a1 : a2);
|
|
715
715
|
if (perc > .8) {
|
|
716
716
|
collide.grid.makeSubGrid(collide.el, undefined, node);
|
|
717
717
|
collide = undefined;
|
|
@@ -750,7 +750,7 @@ class GridStackEngine {
|
|
|
750
750
|
return this;
|
|
751
751
|
}
|
|
752
752
|
endUpdate() {
|
|
753
|
-
|
|
753
|
+
const n = this.nodes.find(n => n._updating);
|
|
754
754
|
if (n) {
|
|
755
755
|
delete n._updating;
|
|
756
756
|
delete n._skipDown;
|
|
@@ -761,14 +761,14 @@ class GridStackEngine {
|
|
|
761
761
|
* returning a list of widgets for serialization */
|
|
762
762
|
save(saveElement = true, saveCB) {
|
|
763
763
|
// use the highest layout for any saved info so we can have full detail on reload #1849
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
764
|
+
const len = this._layouts?.length;
|
|
765
|
+
const layout = len && this.column !== (len - 1) ? this._layouts[len - 1] : null;
|
|
766
|
+
const list = [];
|
|
767
767
|
this.sortNodes();
|
|
768
768
|
this.nodes.forEach(n => {
|
|
769
|
-
|
|
769
|
+
const wl = layout?.find(l => l._id === n._id);
|
|
770
770
|
// use layout info fields instead if set
|
|
771
|
-
|
|
771
|
+
const w = { ...n, ...(wl || {}) };
|
|
772
772
|
Utils.removeInternalForSave(w, !saveElement);
|
|
773
773
|
if (saveCB)
|
|
774
774
|
saveCB(n, w);
|
|
@@ -790,11 +790,11 @@ class GridStackEngine {
|
|
|
790
790
|
else {
|
|
791
791
|
// we save the original x,y,w (h isn't cached) to see what actually changed to propagate better.
|
|
792
792
|
// NOTE: we don't need to check against out of bound scaling/moving as that will be done when using those cache values. #1785
|
|
793
|
-
|
|
793
|
+
const ratio = column / this.column;
|
|
794
794
|
nodes.forEach(node => {
|
|
795
795
|
if (!node._orig)
|
|
796
796
|
return; // didn't change (newly added ?)
|
|
797
|
-
|
|
797
|
+
const n = layout.find(l => l._id === node._id);
|
|
798
798
|
if (!n)
|
|
799
799
|
return; // no cache for new nodes. Will use those values.
|
|
800
800
|
// Y changed, push down same amount
|
|
@@ -849,11 +849,11 @@ class GridStackEngine {
|
|
|
849
849
|
const cacheNodes = this._layouts[column] || [];
|
|
850
850
|
// ...if not, start with the largest layout (if not already there) as down-scaling is more accurate
|
|
851
851
|
// by pretending we came from that larger column by assigning those values as starting point
|
|
852
|
-
|
|
852
|
+
const lastIndex = this._layouts.length - 1;
|
|
853
853
|
if (!cacheNodes.length && prevColumn !== lastIndex && this._layouts[lastIndex]?.length) {
|
|
854
854
|
prevColumn = lastIndex;
|
|
855
855
|
this._layouts[lastIndex].forEach(cacheNode => {
|
|
856
|
-
|
|
856
|
+
const n = nodes.find(n => n._id === cacheNode._id);
|
|
857
857
|
if (n) {
|
|
858
858
|
// still current, use cache info positions
|
|
859
859
|
if (!doCompact && !cacheNode.autoPosition) {
|
|
@@ -868,7 +868,7 @@ class GridStackEngine {
|
|
|
868
868
|
}
|
|
869
869
|
// if we found cache re-use those nodes that are still current
|
|
870
870
|
cacheNodes.forEach(cacheNode => {
|
|
871
|
-
|
|
871
|
+
const j = nodes.findIndex(n => n._id === cacheNode._id);
|
|
872
872
|
if (j !== -1) {
|
|
873
873
|
const n = nodes[j];
|
|
874
874
|
// still current, use cache info positions
|
|
@@ -900,9 +900,9 @@ class GridStackEngine {
|
|
|
900
900
|
layout(column, prevColumn, newNodes, nodes);
|
|
901
901
|
}
|
|
902
902
|
else {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
903
|
+
const ratio = doCompact ? 1 : column / prevColumn;
|
|
904
|
+
const move = (layout === 'move' || layout === 'moveScale');
|
|
905
|
+
const scale = (layout === 'scale' || layout === 'moveScale');
|
|
906
906
|
nodes.forEach(node => {
|
|
907
907
|
// NOTE: x + w could be outside of the grid, but addNode() below will handle that
|
|
908
908
|
node.x = (column === 1 ? 0 : (move ? Math.round(node.x * ratio) : Math.min(node.x, column - 1)));
|
|
@@ -933,7 +933,7 @@ class GridStackEngine {
|
|
|
933
933
|
* @param clear if true, will force other caches to be removed (default false)
|
|
934
934
|
*/
|
|
935
935
|
cacheLayout(nodes, column, clear = false) {
|
|
936
|
-
|
|
936
|
+
const copy = [];
|
|
937
937
|
nodes.forEach((n, i) => {
|
|
938
938
|
// make sure we have an id in case this is new layout, else re-use id already set
|
|
939
939
|
if (n._id === undefined) {
|
|
@@ -953,7 +953,7 @@ class GridStackEngine {
|
|
|
953
953
|
*/
|
|
954
954
|
cacheOneLayout(n, column) {
|
|
955
955
|
n._id = n._id ?? GridStackEngine._idSeq++;
|
|
956
|
-
|
|
956
|
+
const l = { x: n.x, y: n.y, w: n.w, _id: n._id };
|
|
957
957
|
if (n.autoPosition || n.x === undefined) {
|
|
958
958
|
delete l.x;
|
|
959
959
|
delete l.y;
|
|
@@ -962,7 +962,7 @@ class GridStackEngine {
|
|
|
962
962
|
}
|
|
963
963
|
this._layouts = this._layouts || [];
|
|
964
964
|
this._layouts[column] = this._layouts[column] || [];
|
|
965
|
-
|
|
965
|
+
const index = this.findCacheLayout(n, column);
|
|
966
966
|
if (index === -1)
|
|
967
967
|
this._layouts[column].push(l);
|
|
968
968
|
else
|
|
@@ -977,7 +977,7 @@ class GridStackEngine {
|
|
|
977
977
|
return;
|
|
978
978
|
}
|
|
979
979
|
for (let i = 0; i < this._layouts.length; i++) {
|
|
980
|
-
|
|
980
|
+
const index = this.findCacheLayout(n, i);
|
|
981
981
|
if (index !== -1) {
|
|
982
982
|
this._layouts[i].splice(index, 1);
|
|
983
983
|
}
|
|
@@ -985,7 +985,7 @@ class GridStackEngine {
|
|
|
985
985
|
}
|
|
986
986
|
/** called to remove all internal values but the _id */
|
|
987
987
|
cleanupNode(node) {
|
|
988
|
-
for (
|
|
988
|
+
for (const prop in node) {
|
|
989
989
|
if (prop[0] === '_' && prop !== '_id')
|
|
990
990
|
delete node[prop];
|
|
991
991
|
}
|