gridstack 8.2.3 → 8.4.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/angular/projects/demo/src/app/app.component.html +32 -0
- package/angular/projects/demo/src/app/app.component.ts +20 -5
- package/angular/projects/demo/src/styles.css +37 -0
- package/angular/projects/lib/package.json +1 -1
- package/angular/projects/lib/src/lib/base-widget.ts +1 -1
- package/angular/projects/lib/src/lib/gridstack-item.component.ts +1 -1
- package/angular/projects/lib/src/lib/gridstack.component.ts +1 -1
- package/angular/projects/lib/src/lib/gridstack.module.ts +1 -1
- 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 +2 -2
- package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
- package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
- package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
- package/dist/angular/fesm2020/gridstack-angular.mjs +4 -4
- 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/package.json +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 +1 -1
- 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 +2 -2
- 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/es5/dd-base-impl.d.ts +1 -1
- package/dist/es5/dd-base-impl.js +1 -1
- package/dist/es5/dd-base-impl.js.map +1 -1
- package/dist/es5/dd-draggable.d.ts +1 -1
- package/dist/es5/dd-draggable.js +1 -1
- package/dist/es5/dd-draggable.js.map +1 -1
- package/dist/es5/dd-droppable.d.ts +1 -1
- package/dist/es5/dd-droppable.js +2 -2
- 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 -1
- package/dist/es5/dd-gridstack.js +1 -1
- 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 +9 -8
- package/dist/es5/gridstack-engine.js +119 -75
- package/dist/es5/gridstack-engine.js.map +1 -1
- package/dist/es5/gridstack-poly.js +1 -1
- package/dist/es5/gridstack.d.ts +11 -5
- package/dist/es5/gridstack.js +54 -32
- package/dist/es5/gridstack.js.map +1 -1
- package/dist/es5/types.d.ts +14 -5
- package/dist/es5/types.js +3 -2
- package/dist/es5/types.js.map +1 -1
- package/dist/es5/utils.d.ts +2 -2
- package/dist/es5/utils.js +4 -3
- 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 +9 -8
- package/dist/gridstack-engine.js +114 -75
- package/dist/gridstack-engine.js.map +1 -1
- package/dist/gridstack.css +1 -1
- package/dist/gridstack.d.ts +11 -5
- package/dist/gridstack.js +49 -30
- package/dist/gridstack.js.map +1 -1
- package/dist/src/gridstack.scss +1 -1
- package/dist/types.d.ts +14 -5
- package/dist/types.js +3 -2
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +4 -4
- package/dist/utils.js.map +1 -1
- package/doc/CHANGES.md +10 -0
- package/doc/README.md +17 -8
- package/package.json +1 -1
- package/angular/projects/demo/src/environments/environment.prod.ts +0 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* gridstack-engine.ts 8.
|
|
2
|
+
* gridstack-engine.ts 8.4.0
|
|
3
3
|
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
|
|
4
4
|
*/
|
|
5
|
-
import { GridStackNode, GridStackPosition, GridStackMoveOpts, SaveFcn } from './types';
|
|
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() */
|
|
7
7
|
type OnChangeCB = (nodes: GridStackNode[]) => void;
|
|
8
8
|
/** options used during creation - similar to GridStackOptions */
|
|
@@ -27,7 +27,7 @@ export declare class GridStackEngine {
|
|
|
27
27
|
removedNodes: GridStackNode[];
|
|
28
28
|
batchMode: boolean;
|
|
29
29
|
constructor(opts?: GridStackEngineOptions);
|
|
30
|
-
batchUpdate(flag?: boolean): GridStackEngine;
|
|
30
|
+
batchUpdate(flag?: boolean, doPack?: boolean): GridStackEngine;
|
|
31
31
|
protected _useEntireRowArea(node: GridStackNode, nn: GridStackPosition): boolean;
|
|
32
32
|
/** return the nodes that intercept the given node. Optionally a different area can be used, as well as a second node to skip */
|
|
33
33
|
collide(skip: GridStackNode, area?: GridStackNode, skip2?: GridStackNode): GridStackNode;
|
|
@@ -40,14 +40,14 @@ export declare class GridStackEngine {
|
|
|
40
40
|
/** called to possibly swap between 2 nodes (same size or column, not locked, touching), returning true if successful */
|
|
41
41
|
swap(a: GridStackNode, b: GridStackNode): boolean;
|
|
42
42
|
isAreaEmpty(x: number, y: number, w: number, h: number): boolean;
|
|
43
|
-
/** re-layout grid items to reclaim any empty space */
|
|
44
|
-
compact(): GridStackEngine;
|
|
43
|
+
/** 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 */
|
|
44
|
+
compact(layout?: CompactOptions, doSort?: boolean): GridStackEngine;
|
|
45
45
|
/** enable/disable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html) */
|
|
46
46
|
set float(val: boolean);
|
|
47
47
|
/** float getter method */
|
|
48
48
|
get float(): boolean;
|
|
49
49
|
/** sort the nodes array from first to last, or reverse. Called during collision/placement to force an order */
|
|
50
|
-
sortNodes(dir?:
|
|
50
|
+
sortNodes(dir?: 1 | -1, column?: number): GridStackEngine;
|
|
51
51
|
/**
|
|
52
52
|
* given a random node, makes sure it's coordinates/values are valid in the current grid
|
|
53
53
|
* @param node to adjust
|
|
@@ -60,10 +60,11 @@ export declare class GridStackEngine {
|
|
|
60
60
|
getDirtyNodes(verify?: boolean): GridStackNode[];
|
|
61
61
|
/** find the first available empty spot for the given node width/height, updating the x,y attributes. return true if found.
|
|
62
62
|
* optionally you can pass your own existing node list and column count, otherwise defaults to that engine data.
|
|
63
|
+
* Optionally pass a widget to start search AFTER, meaning the order will remain the same but possibly have empty slots we skipped
|
|
63
64
|
*/
|
|
64
|
-
findEmptyPosition(node: GridStackNode, nodeList?: GridStackNode[], column?: number): boolean;
|
|
65
|
+
findEmptyPosition(node: GridStackNode, nodeList?: GridStackNode[], column?: number, after?: GridStackNode): boolean;
|
|
65
66
|
/** call to add the given node to our list, fixing collision and re-packing */
|
|
66
|
-
addNode(node: GridStackNode, triggerAddEvent?: boolean): GridStackNode;
|
|
67
|
+
addNode(node: GridStackNode, triggerAddEvent?: boolean, after?: GridStackNode): GridStackNode;
|
|
67
68
|
removeNode(node: GridStackNode, removeDOM?: boolean, triggerEvent?: boolean): GridStackEngine;
|
|
68
69
|
removeAll(removeDOM?: boolean): GridStackEngine;
|
|
69
70
|
/** checks if item can be moved (layout constrain) vs moveNode(), returning true if was able to move.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* gridstack-engine.ts 8.
|
|
3
|
+
* gridstack-engine.ts 8.4.0
|
|
4
4
|
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
|
|
5
5
|
*/
|
|
6
6
|
var __assign = (this && this.__assign) || function () {
|
|
@@ -34,8 +34,9 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
34
34
|
this.nodes = opts.nodes || [];
|
|
35
35
|
this.onChange = opts.onChange;
|
|
36
36
|
}
|
|
37
|
-
GridStackEngine.prototype.batchUpdate = function (flag) {
|
|
37
|
+
GridStackEngine.prototype.batchUpdate = function (flag, doPack) {
|
|
38
38
|
if (flag === void 0) { flag = true; }
|
|
39
|
+
if (doPack === void 0) { doPack = true; }
|
|
39
40
|
if (!!this.batchMode === flag)
|
|
40
41
|
return this;
|
|
41
42
|
this.batchMode = flag;
|
|
@@ -47,7 +48,9 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
47
48
|
else {
|
|
48
49
|
this._float = this._prevFloat;
|
|
49
50
|
delete this._prevFloat;
|
|
50
|
-
|
|
51
|
+
if (doPack)
|
|
52
|
+
this._packNodes();
|
|
53
|
+
this._notify();
|
|
51
54
|
}
|
|
52
55
|
return this;
|
|
53
56
|
};
|
|
@@ -254,23 +257,37 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
254
257
|
var nn = { x: x || 0, y: y || 0, w: w || 1, h: h || 1 };
|
|
255
258
|
return !this.collide(nn);
|
|
256
259
|
};
|
|
257
|
-
/** re-layout grid items to reclaim any empty space */
|
|
258
|
-
GridStackEngine.prototype.compact = function () {
|
|
260
|
+
/** 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 */
|
|
261
|
+
GridStackEngine.prototype.compact = function (layout, doSort) {
|
|
259
262
|
var _this = this;
|
|
263
|
+
if (layout === void 0) { layout = 'compact'; }
|
|
264
|
+
if (doSort === void 0) { doSort = true; }
|
|
260
265
|
if (this.nodes.length === 0)
|
|
261
266
|
return this;
|
|
262
|
-
|
|
263
|
-
.sortNodes();
|
|
267
|
+
if (doSort)
|
|
268
|
+
this.sortNodes();
|
|
269
|
+
var wasBatch = this.batchMode;
|
|
270
|
+
if (!wasBatch)
|
|
271
|
+
this.batchUpdate();
|
|
272
|
+
var wasColumnResize = this._inColumnResize;
|
|
273
|
+
if (!wasColumnResize)
|
|
274
|
+
this._inColumnResize = true; // faster addNode()
|
|
264
275
|
var copyNodes = this.nodes;
|
|
265
276
|
this.nodes = []; // pretend we have no nodes to conflict layout to start with...
|
|
266
|
-
copyNodes.forEach(function (
|
|
267
|
-
|
|
268
|
-
|
|
277
|
+
copyNodes.forEach(function (n, index, list) {
|
|
278
|
+
var after;
|
|
279
|
+
if (!n.locked) {
|
|
280
|
+
n.autoPosition = true;
|
|
281
|
+
if (layout === 'list' && index)
|
|
282
|
+
after = list[index - 1];
|
|
269
283
|
}
|
|
270
|
-
_this.addNode(
|
|
271
|
-
node._dirty = true; // will force attr update
|
|
284
|
+
_this.addNode(n, false, after); // 'false' for add event trigger
|
|
272
285
|
});
|
|
273
|
-
|
|
286
|
+
if (!wasColumnResize)
|
|
287
|
+
delete this._inColumnResize;
|
|
288
|
+
if (!wasBatch)
|
|
289
|
+
this.batchUpdate(false);
|
|
290
|
+
return this;
|
|
274
291
|
};
|
|
275
292
|
Object.defineProperty(GridStackEngine.prototype, "float", {
|
|
276
293
|
/** float getter method */
|
|
@@ -288,8 +305,10 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
288
305
|
configurable: true
|
|
289
306
|
});
|
|
290
307
|
/** sort the nodes array from first to last, or reverse. Called during collision/placement to force an order */
|
|
291
|
-
GridStackEngine.prototype.sortNodes = function (dir) {
|
|
292
|
-
|
|
308
|
+
GridStackEngine.prototype.sortNodes = function (dir, column) {
|
|
309
|
+
if (dir === void 0) { dir = 1; }
|
|
310
|
+
if (column === void 0) { column = this.column; }
|
|
311
|
+
this.nodes = utils_1.Utils.sort(this.nodes, dir, column);
|
|
293
312
|
return this;
|
|
294
313
|
};
|
|
295
314
|
/** @internal called to top gravity pack the items back OR revert back to original Y positions when floating */
|
|
@@ -509,11 +528,12 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
509
528
|
};
|
|
510
529
|
/** find the first available empty spot for the given node width/height, updating the x,y attributes. return true if found.
|
|
511
530
|
* optionally you can pass your own existing node list and column count, otherwise defaults to that engine data.
|
|
531
|
+
* Optionally pass a widget to start search AFTER, meaning the order will remain the same but possibly have empty slots we skipped
|
|
512
532
|
*/
|
|
513
|
-
GridStackEngine.prototype.findEmptyPosition = function (node, nodeList, column) {
|
|
533
|
+
GridStackEngine.prototype.findEmptyPosition = function (node, nodeList, column, after) {
|
|
514
534
|
if (nodeList === void 0) { nodeList = this.nodes; }
|
|
515
535
|
if (column === void 0) { column = this.column; }
|
|
516
|
-
|
|
536
|
+
var start = after ? after.y * column + (after.x + after.w) : 0;
|
|
517
537
|
var found = false;
|
|
518
538
|
var _loop_1 = function (i) {
|
|
519
539
|
var x = i % column;
|
|
@@ -523,19 +543,21 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
523
543
|
}
|
|
524
544
|
var box = { x: x, y: y, w: node.w, h: node.h };
|
|
525
545
|
if (!nodeList.find(function (n) { return utils_1.Utils.isIntercepted(box, n); })) {
|
|
546
|
+
if (node.x !== x || node.y !== y)
|
|
547
|
+
node._dirty = true;
|
|
526
548
|
node.x = x;
|
|
527
549
|
node.y = y;
|
|
528
550
|
delete node.autoPosition;
|
|
529
551
|
found = true;
|
|
530
552
|
}
|
|
531
553
|
};
|
|
532
|
-
for (var i =
|
|
554
|
+
for (var i = start; !found; ++i) {
|
|
533
555
|
_loop_1(i);
|
|
534
556
|
}
|
|
535
557
|
return found;
|
|
536
558
|
};
|
|
537
559
|
/** call to add the given node to our list, fixing collision and re-packing */
|
|
538
|
-
GridStackEngine.prototype.addNode = function (node, triggerAddEvent) {
|
|
560
|
+
GridStackEngine.prototype.addNode = function (node, triggerAddEvent, after) {
|
|
539
561
|
if (triggerAddEvent === void 0) { triggerAddEvent = false; }
|
|
540
562
|
var dup = this.nodes.find(function (n) { return n._id === node._id; });
|
|
541
563
|
if (dup)
|
|
@@ -544,14 +566,17 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
544
566
|
node = this._inColumnResize ? this.nodeBoundFix(node) : this.prepareNode(node);
|
|
545
567
|
delete node._temporaryRemoved;
|
|
546
568
|
delete node._removeDOM;
|
|
547
|
-
|
|
569
|
+
var skipCollision;
|
|
570
|
+
if (node.autoPosition && this.findEmptyPosition(node, this.nodes, this.column, after)) {
|
|
548
571
|
delete node.autoPosition; // found our slot
|
|
572
|
+
skipCollision = true;
|
|
549
573
|
}
|
|
550
574
|
this.nodes.push(node);
|
|
551
575
|
if (triggerAddEvent) {
|
|
552
576
|
this.addedNodes.push(node);
|
|
553
577
|
}
|
|
554
|
-
|
|
578
|
+
if (!skipCollision)
|
|
579
|
+
this._fixCollisions(node);
|
|
555
580
|
if (!this.batchMode) {
|
|
556
581
|
this._packNodes()._notify();
|
|
557
582
|
}
|
|
@@ -571,8 +596,10 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
571
596
|
node._removeDOM = true; // let CB remove actual HTML (used to set _id to null, but then we loose layout info)
|
|
572
597
|
// don't use 'faster' .splice(findIndex(),1) in case node isn't in our list, or in multiple times.
|
|
573
598
|
this.nodes = this.nodes.filter(function (n) { return n._id !== node._id; });
|
|
574
|
-
|
|
575
|
-
.
|
|
599
|
+
if (!node._isAboutToRemove)
|
|
600
|
+
this._packNodes(); // if dragged out, no need to relayout as already done...
|
|
601
|
+
this._notify([node]);
|
|
602
|
+
return this;
|
|
576
603
|
};
|
|
577
604
|
GridStackEngine.prototype.removeAll = function (removeDOM) {
|
|
578
605
|
if (removeDOM === void 0) { removeDOM = true; }
|
|
@@ -848,17 +875,23 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
848
875
|
* @param layout specify the type of re-layout that will happen (position, size, etc...).
|
|
849
876
|
* Note: items will never be outside of the current column boundaries. default (moveScale). Ignored for 1 column
|
|
850
877
|
*/
|
|
851
|
-
GridStackEngine.prototype.
|
|
878
|
+
GridStackEngine.prototype.columnChanged = function (prevColumn, column, nodes, layout) {
|
|
852
879
|
var _this = this;
|
|
853
880
|
var _a;
|
|
854
881
|
if (layout === void 0) { layout = 'moveScale'; }
|
|
855
882
|
if (!this.nodes.length || !column || prevColumn === column)
|
|
856
883
|
return this;
|
|
857
|
-
//
|
|
858
|
-
|
|
884
|
+
// simpler shortcuts layouts
|
|
885
|
+
var doCompact = layout === 'compact' || layout === 'list';
|
|
886
|
+
if (doCompact) {
|
|
887
|
+
this.sortNodes(1, prevColumn); // sort with original layout once and only once (new column will affect order otherwise)
|
|
888
|
+
}
|
|
889
|
+
// 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)
|
|
890
|
+
if (column < prevColumn)
|
|
891
|
+
this.cacheLayout(this.nodes, prevColumn);
|
|
859
892
|
this.batchUpdate(); // do this EARLY as it will call saveInitial() so we can detect where we started for _dirty and collision
|
|
860
893
|
var newNodes = [];
|
|
861
|
-
// if we're going to 1 column and using DOM order rather than default sorting, then generate that layout
|
|
894
|
+
// if we're going to 1 column and using DOM order (item passed in) rather than default sorting, then generate that layout
|
|
862
895
|
var domOrder = false;
|
|
863
896
|
if (column === 1 && (nodes === null || nodes === void 0 ? void 0 : nodes.length)) {
|
|
864
897
|
domOrder = true;
|
|
@@ -873,13 +906,12 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
873
906
|
nodes = [];
|
|
874
907
|
}
|
|
875
908
|
else {
|
|
876
|
-
nodes = utils_1.Utils.sort(this.nodes, -1, prevColumn); // current column reverse sorting so we can insert last to front (limit collision)
|
|
909
|
+
nodes = doCompact ? this.nodes : utils_1.Utils.sort(this.nodes, -1, prevColumn); // current column reverse sorting so we can insert last to front (limit collision)
|
|
877
910
|
}
|
|
878
911
|
// see if we have cached previous layout IFF we are going up in size (restore) otherwise always
|
|
879
912
|
// generate next size down from where we are (looks more natural as you gradually size down).
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
cacheNodes = this._layouts[column] || [];
|
|
913
|
+
if (column > prevColumn && this._layouts) {
|
|
914
|
+
var cacheNodes = this._layouts[column] || [];
|
|
883
915
|
// ...if not, start with the largest layout (if not already there) as down-scaling is more accurate
|
|
884
916
|
// by pretending we came from that larger column by assigning those values as starting point
|
|
885
917
|
var lastIndex = this._layouts.length - 1;
|
|
@@ -889,59 +921,71 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
889
921
|
var n = nodes.find(function (n) { return n._id === cacheNode._id; });
|
|
890
922
|
if (n) {
|
|
891
923
|
// still current, use cache info positions
|
|
892
|
-
|
|
893
|
-
|
|
924
|
+
if (!doCompact) {
|
|
925
|
+
n.x = cacheNode.x;
|
|
926
|
+
n.y = cacheNode.y;
|
|
927
|
+
}
|
|
894
928
|
n.w = cacheNode.w;
|
|
895
929
|
}
|
|
896
930
|
});
|
|
897
931
|
}
|
|
932
|
+
// if we found cache re-use those nodes that are still current
|
|
933
|
+
cacheNodes.forEach(function (cacheNode) {
|
|
934
|
+
var j = nodes.findIndex(function (n) { return n._id === cacheNode._id; });
|
|
935
|
+
if (j !== -1) {
|
|
936
|
+
// still current, use cache info positions
|
|
937
|
+
if (doCompact) {
|
|
938
|
+
nodes[j].w = cacheNode.w; // only w is used, and don't trim the list
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
if (cacheNode.autoPosition || isNaN(cacheNode.x) || isNaN(cacheNode.y)) {
|
|
942
|
+
_this.findEmptyPosition(cacheNode, newNodes);
|
|
943
|
+
}
|
|
944
|
+
if (!cacheNode.autoPosition) {
|
|
945
|
+
nodes[j].x = cacheNode.x;
|
|
946
|
+
nodes[j].y = cacheNode.y;
|
|
947
|
+
nodes[j].w = cacheNode.w;
|
|
948
|
+
newNodes.push(nodes[j]);
|
|
949
|
+
}
|
|
950
|
+
nodes.splice(j, 1);
|
|
951
|
+
}
|
|
952
|
+
});
|
|
898
953
|
}
|
|
899
|
-
//
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
954
|
+
// much simpler layout that just compacts
|
|
955
|
+
if (doCompact) {
|
|
956
|
+
this.compact(layout, false);
|
|
957
|
+
}
|
|
958
|
+
else {
|
|
959
|
+
// ...and add any extra non-cached ones
|
|
960
|
+
if (nodes.length) {
|
|
961
|
+
if (typeof layout === 'function') {
|
|
962
|
+
layout(column, prevColumn, newNodes, nodes);
|
|
906
963
|
}
|
|
907
|
-
if (!
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
964
|
+
else if (!domOrder) {
|
|
965
|
+
var ratio_2 = (doCompact || layout === 'none') ? 1 : column / prevColumn;
|
|
966
|
+
var move_1 = (layout === 'move' || layout === 'moveScale');
|
|
967
|
+
var scale_1 = (layout === 'scale' || layout === 'moveScale');
|
|
968
|
+
nodes.forEach(function (node) {
|
|
969
|
+
// NOTE: x + w could be outside of the grid, but addNode() below will handle that
|
|
970
|
+
node.x = (column === 1 ? 0 : (move_1 ? Math.round(node.x * ratio_2) : Math.min(node.x, column - 1)));
|
|
971
|
+
node.w = ((column === 1 || prevColumn === 1) ? 1 : scale_1 ? (Math.round(node.w * ratio_2) || 1) : (Math.min(node.w, column)));
|
|
972
|
+
newNodes.push(node);
|
|
973
|
+
});
|
|
974
|
+
nodes = [];
|
|
912
975
|
}
|
|
913
|
-
nodes.splice(j, 1);
|
|
914
|
-
}
|
|
915
|
-
});
|
|
916
|
-
// ...and add any extra non-cached ones
|
|
917
|
-
if (nodes.length) {
|
|
918
|
-
if (typeof layout === 'function') {
|
|
919
|
-
layout(column, prevColumn, newNodes, nodes);
|
|
920
|
-
}
|
|
921
|
-
else if (!domOrder) {
|
|
922
|
-
var ratio_2 = column / prevColumn;
|
|
923
|
-
var move_1 = (layout === 'move' || layout === 'moveScale');
|
|
924
|
-
var scale_1 = (layout === 'scale' || layout === 'moveScale');
|
|
925
|
-
nodes.forEach(function (node) {
|
|
926
|
-
// NOTE: x + w could be outside of the grid, but addNode() below will handle that
|
|
927
|
-
node.x = (column === 1 ? 0 : (move_1 ? Math.round(node.x * ratio_2) : Math.min(node.x, column - 1)));
|
|
928
|
-
node.w = ((column === 1 || prevColumn === 1) ? 1 :
|
|
929
|
-
scale_1 ? (Math.round(node.w * ratio_2) || 1) : (Math.min(node.w, column)));
|
|
930
|
-
newNodes.push(node);
|
|
931
|
-
});
|
|
932
|
-
nodes = [];
|
|
933
976
|
}
|
|
977
|
+
// finally re-layout them in reverse order (to get correct placement)
|
|
978
|
+
if (!domOrder)
|
|
979
|
+
newNodes = utils_1.Utils.sort(newNodes, -1, column);
|
|
980
|
+
this._inColumnResize = true; // prevent cache update
|
|
981
|
+
this.nodes = []; // pretend we have no nodes to start with (add() will use same structures) to simplify layout
|
|
982
|
+
newNodes.forEach(function (node) {
|
|
983
|
+
_this.addNode(node, false); // 'false' for add event trigger
|
|
984
|
+
delete node._orig; // make sure the commit doesn't try to restore things back to original
|
|
985
|
+
});
|
|
934
986
|
}
|
|
935
|
-
//
|
|
936
|
-
|
|
937
|
-
newNodes = utils_1.Utils.sort(newNodes, -1, column);
|
|
938
|
-
this._inColumnResize = true; // prevent cache update
|
|
939
|
-
this.nodes = []; // pretend we have no nodes to start with (add() will use same structures) to simplify layout
|
|
940
|
-
newNodes.forEach(function (node) {
|
|
941
|
-
_this.addNode(node, false); // 'false' for add event trigger
|
|
942
|
-
delete node._orig; // make sure the commit doesn't try to restore things back to original
|
|
943
|
-
});
|
|
944
|
-
this.batchUpdate(false);
|
|
987
|
+
this.nodes.forEach(function (n) { return delete n._orig; }); // clear _orig before batch=false so it doesn't handle float=true restore
|
|
988
|
+
this.batchUpdate(false, !doCompact);
|
|
945
989
|
delete this._inColumnResize;
|
|
946
990
|
return this;
|
|
947
991
|
};
|