gridstack 8.2.2 → 8.3.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/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 +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/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 +1 -1
- package/dist/es5/dd-droppable.js.map +1 -1
- package/dist/es5/dd-element.d.ts +1 -1
- package/dist/es5/dd-element.js +1 -1
- package/dist/es5/dd-element.js.map +1 -1
- package/dist/es5/dd-gridstack.d.ts +1 -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 +3 -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 +115 -73
- 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 +15 -7
- package/dist/es5/gridstack.js.map +1 -1
- package/dist/es5/types.d.ts +11 -4
- package/dist/es5/types.js +1 -1
- package/dist/es5/types.js.map +1 -1
- package/dist/es5/utils.d.ts +2 -2
- package/dist/es5/utils.js +2 -1
- package/dist/es5/utils.js.map +1 -1
- package/dist/gridstack-all.js +3 -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 +110 -73
- 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 +13 -7
- package/dist/gridstack.js.map +1 -1
- package/dist/src/gridstack.scss +1 -1
- package/dist/types.d.ts +11 -4
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +2 -2
- package/dist/utils.js.map +1 -1
- package/doc/CHANGES.md +6 -2
- package/doc/README.md +16 -7
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* gridstack-engine.ts 8.
|
|
2
|
+
* gridstack-engine.ts 8.3.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.3.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
|
}
|
|
@@ -848,17 +873,23 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
848
873
|
* @param layout specify the type of re-layout that will happen (position, size, etc...).
|
|
849
874
|
* Note: items will never be outside of the current column boundaries. default (moveScale). Ignored for 1 column
|
|
850
875
|
*/
|
|
851
|
-
GridStackEngine.prototype.
|
|
876
|
+
GridStackEngine.prototype.columnChanged = function (prevColumn, column, nodes, layout) {
|
|
852
877
|
var _this = this;
|
|
853
878
|
var _a;
|
|
854
879
|
if (layout === void 0) { layout = 'moveScale'; }
|
|
855
880
|
if (!this.nodes.length || !column || prevColumn === column)
|
|
856
881
|
return this;
|
|
857
|
-
//
|
|
858
|
-
|
|
882
|
+
// simpler shortcuts layouts
|
|
883
|
+
var doCompact = layout === 'compact' || layout === 'list';
|
|
884
|
+
if (doCompact) {
|
|
885
|
+
this.sortNodes(1, prevColumn); // sort with original layout once and only once (new column will affect order otherwise)
|
|
886
|
+
}
|
|
887
|
+
// 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)
|
|
888
|
+
if (column < prevColumn)
|
|
889
|
+
this.cacheLayout(this.nodes, prevColumn);
|
|
859
890
|
this.batchUpdate(); // do this EARLY as it will call saveInitial() so we can detect where we started for _dirty and collision
|
|
860
891
|
var newNodes = [];
|
|
861
|
-
// if we're going to 1 column and using DOM order rather than default sorting, then generate that layout
|
|
892
|
+
// if we're going to 1 column and using DOM order (item passed in) rather than default sorting, then generate that layout
|
|
862
893
|
var domOrder = false;
|
|
863
894
|
if (column === 1 && (nodes === null || nodes === void 0 ? void 0 : nodes.length)) {
|
|
864
895
|
domOrder = true;
|
|
@@ -873,13 +904,12 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
873
904
|
nodes = [];
|
|
874
905
|
}
|
|
875
906
|
else {
|
|
876
|
-
nodes = utils_1.Utils.sort(this.nodes, -1, prevColumn); // current column reverse sorting so we can insert last to front (limit collision)
|
|
907
|
+
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
908
|
}
|
|
878
909
|
// see if we have cached previous layout IFF we are going up in size (restore) otherwise always
|
|
879
910
|
// generate next size down from where we are (looks more natural as you gradually size down).
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
cacheNodes = this._layouts[column] || [];
|
|
911
|
+
if (column > prevColumn && this._layouts) {
|
|
912
|
+
var cacheNodes = this._layouts[column] || [];
|
|
883
913
|
// ...if not, start with the largest layout (if not already there) as down-scaling is more accurate
|
|
884
914
|
// by pretending we came from that larger column by assigning those values as starting point
|
|
885
915
|
var lastIndex = this._layouts.length - 1;
|
|
@@ -889,59 +919,71 @@ var GridStackEngine = exports.GridStackEngine = /** @class */ (function () {
|
|
|
889
919
|
var n = nodes.find(function (n) { return n._id === cacheNode._id; });
|
|
890
920
|
if (n) {
|
|
891
921
|
// still current, use cache info positions
|
|
892
|
-
|
|
893
|
-
|
|
922
|
+
if (!doCompact) {
|
|
923
|
+
n.x = cacheNode.x;
|
|
924
|
+
n.y = cacheNode.y;
|
|
925
|
+
}
|
|
894
926
|
n.w = cacheNode.w;
|
|
895
927
|
}
|
|
896
928
|
});
|
|
897
929
|
}
|
|
930
|
+
// if we found cache re-use those nodes that are still current
|
|
931
|
+
cacheNodes.forEach(function (cacheNode) {
|
|
932
|
+
var j = nodes.findIndex(function (n) { return n._id === cacheNode._id; });
|
|
933
|
+
if (j !== -1) {
|
|
934
|
+
// still current, use cache info positions
|
|
935
|
+
if (doCompact) {
|
|
936
|
+
nodes[j].w = cacheNode.w; // only w is used, and don't trim the list
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
if (cacheNode.autoPosition || isNaN(cacheNode.x) || isNaN(cacheNode.y)) {
|
|
940
|
+
_this.findEmptyPosition(cacheNode, newNodes);
|
|
941
|
+
}
|
|
942
|
+
if (!cacheNode.autoPosition) {
|
|
943
|
+
nodes[j].x = cacheNode.x;
|
|
944
|
+
nodes[j].y = cacheNode.y;
|
|
945
|
+
nodes[j].w = cacheNode.w;
|
|
946
|
+
newNodes.push(nodes[j]);
|
|
947
|
+
}
|
|
948
|
+
nodes.splice(j, 1);
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
// much simpler layout that just compacts
|
|
953
|
+
if (doCompact) {
|
|
954
|
+
this.compact(layout, false);
|
|
898
955
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
if (cacheNode.autoPosition || isNaN(cacheNode.x) || isNaN(cacheNode.y)) {
|
|
905
|
-
_this.findEmptyPosition(cacheNode, newNodes);
|
|
956
|
+
else {
|
|
957
|
+
// ...and add any extra non-cached ones
|
|
958
|
+
if (nodes.length) {
|
|
959
|
+
if (typeof layout === 'function') {
|
|
960
|
+
layout(column, prevColumn, newNodes, nodes);
|
|
906
961
|
}
|
|
907
|
-
if (!
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
962
|
+
else if (!domOrder) {
|
|
963
|
+
var ratio_2 = (doCompact || layout === 'none') ? 1 : column / prevColumn;
|
|
964
|
+
var move_1 = (layout === 'move' || layout === 'moveScale');
|
|
965
|
+
var scale_1 = (layout === 'scale' || layout === 'moveScale');
|
|
966
|
+
nodes.forEach(function (node) {
|
|
967
|
+
// NOTE: x + w could be outside of the grid, but addNode() below will handle that
|
|
968
|
+
node.x = (column === 1 ? 0 : (move_1 ? Math.round(node.x * ratio_2) : Math.min(node.x, column - 1)));
|
|
969
|
+
node.w = ((column === 1 || prevColumn === 1) ? 1 : scale_1 ? (Math.round(node.w * ratio_2) || 1) : (Math.min(node.w, column)));
|
|
970
|
+
newNodes.push(node);
|
|
971
|
+
});
|
|
972
|
+
nodes = [];
|
|
912
973
|
}
|
|
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
974
|
}
|
|
975
|
+
// finally re-layout them in reverse order (to get correct placement)
|
|
976
|
+
if (!domOrder)
|
|
977
|
+
newNodes = utils_1.Utils.sort(newNodes, -1, column);
|
|
978
|
+
this._inColumnResize = true; // prevent cache update
|
|
979
|
+
this.nodes = []; // pretend we have no nodes to start with (add() will use same structures) to simplify layout
|
|
980
|
+
newNodes.forEach(function (node) {
|
|
981
|
+
_this.addNode(node, false); // 'false' for add event trigger
|
|
982
|
+
delete node._orig; // make sure the commit doesn't try to restore things back to original
|
|
983
|
+
});
|
|
934
984
|
}
|
|
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);
|
|
985
|
+
this.nodes.forEach(function (n) { return delete n._orig; }); // clear _orig before batch=false so it doesn't handle float=true restore
|
|
986
|
+
this.batchUpdate(false, !doCompact);
|
|
945
987
|
delete this._inColumnResize;
|
|
946
988
|
return this;
|
|
947
989
|
};
|