@hpcc-js/layout 2.49.22 → 2.49.23

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/dist/index.js CHANGED
@@ -20,8 +20,8 @@
20
20
  }
21
21
 
22
22
  var PKG_NAME = "@hpcc-js/layout";
23
- var PKG_VERSION = "2.49.22";
24
- var BUILD_VERSION = "2.105.9";
23
+ var PKG_VERSION = "2.49.23";
24
+ var BUILD_VERSION = "2.105.12";
25
25
 
26
26
  /******************************************************************************
27
27
  Copyright (c) Microsoft Corporation.
@@ -3501,703 +3501,708 @@
3501
3501
 
3502
3502
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3503
3503
 
3504
+ function getDefaultExportFromCjs (x) {
3505
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3506
+ }
3507
+
3504
3508
  var gridList$1 = {exports: {}};
3505
3509
 
3506
3510
  (function (module, exports) {
3507
- (function (root, factory) {
3508
- {
3509
- // Node. Does not work with strict CommonJS, but
3510
- // only CommonJS-like environments that support module.exports,
3511
- // like Node.
3512
- module.exports = factory();
3513
- }
3514
- }(commonjsGlobal, function() {
3515
-
3516
- var GridList = function(items, options) {
3517
- /**
3518
- * A GridList manages the two-dimensional positions from a list of items,
3519
- * within a virtual matrix.
3520
- *
3521
- * The GridList's main function is to convert the item positions from one
3522
- * grid size to another, maintaining as much of their order as possible.
3523
- *
3524
- * The GridList's second function is to handle collisions when moving an item
3525
- * over another.
3526
- *
3527
- * The positioning algorithm places items in columns. Starting from left to
3528
- * right, going through each column top to bottom.
3529
- *
3530
- * The size of an item is expressed using the number of cols and rows it
3531
- * takes up within the grid (w and h)
3532
- *
3533
- * The position of an item is express using the col and row position within
3534
- * the grid (x and y)
3535
- *
3536
- * An item is an object of structure:
3537
- * {
3538
- * w: 3, h: 1,
3539
- * x: 0, y: 1
3540
- * }
3541
- */
3542
-
3543
- this._options = options;
3544
- for (var k in this.defaults) {
3545
- if (!this._options.hasOwnProperty(k)) {
3546
- this._options[k] = this.defaults[k];
3547
- }
3548
- }
3549
-
3550
- this.items = items;
3551
-
3552
- this._adjustSizeOfItems();
3553
-
3554
- this.generateGrid();
3555
- };
3556
-
3557
- GridList.cloneItems = function(items, _items) {
3558
- /**
3559
- * Clone items with a deep level of one. Items are not referenced but their
3560
- * properties are
3561
- */
3562
- var i,
3563
- k;
3564
- if (_items === undefined) {
3565
- _items = [];
3566
- }
3567
- for (i = 0; i < items.length; i++) {
3568
- // XXX: this is good because we don't want to lose item reference, but
3569
- // maybe we should clear their properties since some might be optional
3570
- if (!_items[i]) {
3571
- _items[i] = {};
3572
- }
3573
- for (k in items[i]) {
3574
- _items[i][k] = items[i][k];
3575
- }
3576
- }
3577
- return _items;
3578
- };
3579
-
3580
- GridList.prototype = {
3581
-
3582
- defaults: {
3583
- lanes: 5,
3584
- direction: 'horizontal'
3585
- },
3586
-
3587
- /**
3588
- * Illustates grid as text-based table, using a number identifier for each
3589
- * item. E.g.
3590
- *
3591
- * #| 0 1 2 3 4 5 6 7 8 9 10 11 12 13
3592
- * --------------------------------------------
3593
- * 0| 00 02 03 04 04 06 08 08 08 12 12 13 14 16
3594
- * 1| 01 -- 03 05 05 07 09 10 11 11 -- 13 15 --
3595
- *
3596
- * Warn: Does not work if items don't have a width or height specified
3597
- * besides their position in the grid.
3598
- */
3599
- toString: function() {
3600
- var widthOfGrid = this.grid.length,
3601
- output = '\n #|',
3602
- border = '\n --',
3603
- item,
3604
- i,
3605
- j;
3606
-
3607
- // Render the table header
3608
- for (i = 0; i < widthOfGrid; i++) {
3609
- output += ' ' + this._padNumber(i, ' ');
3610
- border += '---';
3611
- } output += border;
3612
-
3613
- // Render table contents row by row, as we go on the y axis
3614
- for (i = 0; i < this._options.lanes; i++) {
3615
- output += '\n' + this._padNumber(i, ' ') + '|';
3616
- for (j = 0; j < widthOfGrid; j++) {
3617
- output += ' ';
3618
- item = this.grid[j][i];
3619
- output += item ? this._padNumber(this.items.indexOf(item), '0') : '--';
3620
- }
3621
- } output += '\n';
3622
- return output;
3623
- },
3624
-
3625
- generateGrid: function() {
3626
- /**
3627
- * Build the grid structure from scratch, with the current item positions
3628
- */
3629
- var i;
3630
- this._resetGrid();
3631
- for (i = 0; i < this.items.length; i++) {
3632
- this._markItemPositionToGrid(this.items[i]);
3633
- }
3634
- },
3635
-
3636
- resizeGrid: function(lanes) {
3637
- var currentColumn = 0;
3638
-
3639
- this._options.lanes = lanes;
3640
- this._adjustSizeOfItems();
3641
-
3642
- this._sortItemsByPosition();
3643
- this._resetGrid();
3644
-
3645
- // The items will be sorted based on their index within the this.items array,
3646
- // that is their "1d position"
3647
- for (var i = 0; i < this.items.length; i++) {
3648
- var item = this.items[i],
3649
- position = this._getItemPosition(item);
3650
-
3651
- this._updateItemPosition(
3652
- item, this.findPositionForItem(item, {x: currentColumn, y: 0}));
3653
-
3654
- // New items should never be placed to the left of previous items
3655
- currentColumn = Math.max(currentColumn, position.x);
3656
- }
3657
-
3658
- this._pullItemsToLeft();
3659
- },
3660
-
3661
- findPositionForItem: function(item, start, fixedRow) {
3662
- /**
3663
- * This method has two options for the position we want for the item:
3664
- * - Starting from a certain row/column number and only looking for
3665
- * positions to its right
3666
- * - Accepting positions for a certain row number only (use-case: items
3667
- * being shifted to the left/right as a result of collisions)
3668
- *
3669
- * @param {Object<x:Number, y:Number, w:Number, h:Number} item
3670
- * @param {Object<x:Number, y:Number} start Position from which to start
3671
- * the search.
3672
- * @param {Number} [fixedRow] If provided, we're going to try to find a
3673
- * position for the new item on it. If doesn't fit there, we're going
3674
- * to put it on the first row.
3675
- *
3676
- * @returns {Number[2]} x and y.
3677
- */
3678
-
3679
- var x, y, position;
3680
-
3681
- // Start searching for a position from the horizontal position of the
3682
- // rightmost item from the grid
3683
- for (x = start.x; x < this.grid.length; x++) {
3684
- if (fixedRow !== undefined) {
3685
- position = [x, fixedRow];
3686
-
3687
- if (this._itemFitsAtPosition(item, position)) {
3688
- return position;
3689
- }
3690
- } else {
3691
- for (y = start.y; y < this._options.lanes; y++) {
3692
- position = [x, y];
3693
-
3694
- if (this._itemFitsAtPosition(item, position)) {
3695
- return position;
3696
- }
3697
- }
3698
- }
3699
- }
3700
-
3701
- // If we've reached this point, we need to start a new column
3702
- var newCol = this.grid.length,
3703
- newRow = 0;
3704
-
3705
- if (fixedRow !== undefined &&
3706
- this._itemFitsAtPosition(item, [newCol, fixedRow])) {
3707
- newRow = fixedRow;
3708
- }
3709
-
3710
- return [newCol, newRow];
3711
- },
3712
-
3713
- moveItemToPosition: function(item, newPosition) {
3714
- var position = this._getItemPosition({
3715
- x: newPosition[0],
3716
- y: newPosition[1],
3717
- w: item.w,
3718
- h: item.h
3719
- });
3720
-
3721
- this._updateItemPosition(item, [position.x, position.y]);
3722
- this._resolveCollisions(item);
3723
- },
3724
-
3725
- resizeItem: function(item, size) {
3726
- /**
3727
- * Resize an item and resolve collisions.
3728
- *
3729
- * @param {Object} item A reference to an item that's part of the grid.
3730
- * @param {Object} size
3731
- * @param {Number} [size.w=item.w] The new width.
3732
- * @param {Number} [size.h=item.h] The new height.
3733
- */
3734
-
3735
- var width = size.w || item.w,
3736
- height = size.h || item.h;
3737
-
3738
- this._updateItemSize(item, width, height);
3739
-
3740
- this._resolveCollisions(item);
3741
-
3742
- this._pullItemsToLeft();
3743
- },
3744
-
3745
- getChangedItems: function(initialItems, idAttribute) {
3746
- /**
3747
- * Compare the current items against a previous snapshot and return only
3748
- * the ones that changed their attributes in the meantime. This includes both
3749
- * position (x, y) and size (w, h)
3750
- *
3751
- * Since both their position and size can change, the items need an
3752
- * additional identifier attribute to match them with their previous state
3753
- */
3754
- var changedItems = [];
3755
-
3756
- for (var i = 0; i < initialItems.length; i++) {
3757
- var item = this._getItemByAttribute(idAttribute,
3758
- initialItems[i][idAttribute]);
3759
-
3760
- if (item.x !== initialItems[i].x ||
3761
- item.y !== initialItems[i].y ||
3762
- item.w !== initialItems[i].w ||
3763
- item.h !== initialItems[i].h) {
3764
- changedItems.push(item);
3765
- }
3766
- }
3767
-
3768
- return changedItems;
3769
- },
3770
-
3771
- _sortItemsByPosition: function() {
3772
- this.items.sort(function(item1, item2) {
3773
- var position1 = this._getItemPosition(item1),
3774
- position2 = this._getItemPosition(item2);
3775
-
3776
- // Try to preserve columns.
3777
- if (position1.x != position2.x) {
3778
- return position1.x - position2.x;
3779
- }
3780
-
3781
- if (position1.y != position2.y) {
3782
- return position1.y - position2.y;
3783
- }
3784
-
3785
- // The items are placed on the same position.
3786
- return 0;
3787
- }.bind(this));
3788
- },
3789
-
3790
- _adjustSizeOfItems: function() {
3791
- /**
3792
- * Some items can have 100% height or 100% width. Those dimmensions are
3793
- * expressed as 0. We need to ensure a valid width and height for each of
3794
- * those items as the number of items per lane.
3795
- */
3796
-
3797
- for (var i = 0; i < this.items.length; i++) {
3798
- var item = this.items[i];
3799
-
3800
- // This can happen only the first time items are checked.
3801
- // We need the property to have a value for all the items so that the
3802
- // `cloneItems` method will merge the properties properly. If we only set
3803
- // it to the items that need it then the following can happen:
3804
- //
3805
- // cloneItems([{id: 1, autoSize: true}, {id: 2}],
3806
- // [{id: 2}, {id: 1, autoSize: true}]);
3807
- //
3808
- // will result in
3809
- //
3810
- // [{id: 1, autoSize: true}, {id: 2, autoSize: true}]
3811
- if (item.autoSize === undefined) {
3812
- item.autoSize = item.w === 0 || item.h === 0;
3813
- }
3814
-
3815
- if (item.autoSize) {
3816
- if (this._options.direction === 'horizontal') {
3817
- item.h = this._options.lanes;
3818
- } else {
3819
- item.w = this._options.lanes;
3820
- }
3821
- }
3822
- }
3823
- },
3824
-
3825
- _resetGrid: function() {
3826
- this.grid = [];
3827
- },
3828
-
3829
- _itemFitsAtPosition: function(item, newPosition) {
3830
- /**
3831
- * Check that an item wouldn't overlap with another one if placed at a
3832
- * certain position within the grid
3833
- */
3834
-
3835
- var position = this._getItemPosition(item),
3836
- x, y;
3837
-
3838
- // No coordonate can be negative
3839
- if (newPosition[0] < 0 || newPosition[1] < 0) {
3840
- return false;
3841
- }
3842
-
3843
- // Make sure the item isn't larger than the entire grid
3844
- if (newPosition[1] + position.h > this._options.lanes) {
3845
- return false;
3846
- }
3847
-
3848
- // Make sure the position doesn't overlap with an already positioned
3849
- // item.
3850
- for (x = newPosition[0]; x < newPosition[0] + position.w; x++) {
3851
- var col = this.grid[x];
3852
-
3853
- // Surely a column that hasn't even been created yet is available
3854
- if (!col) {
3855
- continue;
3856
- }
3857
-
3858
- for (y = newPosition[1]; y < newPosition[1] + position.h; y++) {
3859
- // Any space occupied by an item can continue to be occupied by the
3860
- // same item.
3861
- if (col[y] && col[y] !== item) {
3862
- return false;
3863
- }
3864
- }
3865
- }
3866
-
3867
- return true;
3868
- },
3869
-
3870
- _updateItemPosition: function(item, position) {
3871
- if (item.x !== null && item.y !== null) {
3872
- this._deleteItemPositionFromGrid(item);
3873
- }
3874
-
3875
- this._setItemPosition(item, position);
3876
-
3877
- this._markItemPositionToGrid(item);
3878
- },
3879
-
3880
- _updateItemSize: function(item, width, height) {
3881
- /**
3882
- * @param {Object} item A reference to a grid item.
3883
- * @param {Number} width The new width.
3884
- * @param {Number} height The new height.
3885
- */
3886
-
3887
- if (item.x !== null && item.y !== null) {
3888
- this._deleteItemPositionFromGrid(item);
3889
- }
3890
-
3891
- item.w = width;
3892
- item.h = height;
3893
-
3894
- this._markItemPositionToGrid(item);
3895
- },
3896
-
3897
- _markItemPositionToGrid: function(item) {
3898
- /**
3899
- * Mark the grid cells that are occupied by an item. This prevents items
3900
- * from overlapping in the grid
3901
- */
3902
-
3903
- var position = this._getItemPosition(item),
3904
- x, y;
3905
-
3906
- // Ensure that the grid has enough columns to accomodate the current item.
3907
- this._ensureColumns(position.x + position.w);
3908
-
3909
- for (x = position.x; x < position.x + position.w; x++) {
3910
- for (y = position.y; y < position.y + position.h; y++) {
3911
- this.grid[x][y] = item;
3912
- }
3913
- }
3914
- },
3915
-
3916
- _deleteItemPositionFromGrid: function(item) {
3917
- var position = this._getItemPosition(item),
3918
- x, y;
3919
-
3920
- for (x = position.x; x < position.x + position.w; x++) {
3921
- // It can happen to try to remove an item from a position not generated
3922
- // in the grid, probably when loading a persisted grid of items. No need
3923
- // to create a column to be able to remove something from it, though
3924
- if (!this.grid[x]) {
3925
- continue;
3926
- }
3927
-
3928
- for (y = position.y; y < position.y + position.h; y++) {
3929
- // Don't clear the cell if it's been occupied by a different widget in
3930
- // the meantime (e.g. when an item has been moved over this one, and
3931
- // thus by continuing to clear this item's previous position you would
3932
- // cancel the first item's move, leaving it without any position even)
3933
- if (this.grid[x][y] == item) {
3934
- this.grid[x][y] = null;
3935
- }
3936
- }
3937
- }
3938
- },
3939
-
3940
- _ensureColumns: function(N) {
3941
- /**
3942
- * Ensure that the grid has at least N columns available.
3943
- */
3944
- var i;
3945
- for (i = 0; i < N; i++) {
3946
- if (!this.grid[i]) {
3947
- this.grid.push(new GridCol(this._options.lanes));
3948
- }
3949
- }
3950
- },
3951
-
3952
- _getItemsCollidingWithItem: function(item) {
3953
- var collidingItems = [];
3954
- for (var i = 0; i < this.items.length; i++) {
3955
- if (item != this.items[i] &&
3956
- this._itemsAreColliding(item, this.items[i])) {
3957
- collidingItems.push(i);
3958
- }
3959
- }
3960
- return collidingItems;
3961
- },
3962
-
3963
- _itemsAreColliding: function(item1, item2) {
3964
- var position1 = this._getItemPosition(item1),
3965
- position2 = this._getItemPosition(item2);
3966
-
3967
- return !(position2.x >= position1.x + position1.w ||
3968
- position2.x + position2.w <= position1.x ||
3969
- position2.y >= position1.y + position1.h ||
3970
- position2.y + position2.h <= position1.y);
3971
- },
3972
-
3973
- _resolveCollisions: function(item) {
3974
- if (!this._tryToResolveCollisionsLocally(item)) {
3975
- this._pullItemsToLeft(item);
3976
- }
3977
- this._pullItemsToLeft();
3978
- },
3979
-
3980
- _tryToResolveCollisionsLocally: function(item) {
3981
- /**
3982
- * Attempt to resolve the collisions after moving a an item over one or more
3983
- * other items within the grid, by shifting the position of the colliding
3984
- * items around the moving one. This might result in subsequent collisions,
3985
- * in which case we will revert all position permutations. To be able to
3986
- * revert to the initial item positions, we create a virtual grid in the
3987
- * process
3988
- */
3989
- var collidingItems = this._getItemsCollidingWithItem(item);
3990
- if (!collidingItems.length) {
3991
- return true;
3992
- }
3993
- var _gridList = new GridList([], this._options),
3994
- leftOfItem,
3995
- rightOfItem,
3996
- aboveOfItem,
3997
- belowOfItem;
3998
-
3999
- GridList.cloneItems(this.items, _gridList.items);
4000
- _gridList.generateGrid();
4001
-
4002
- for (var i = 0; i < collidingItems.length; i++) {
4003
- var collidingItem = _gridList.items[collidingItems[i]],
4004
- collidingPosition = this._getItemPosition(collidingItem);
4005
-
4006
- // We use a simple algorithm for moving items around when collisions occur:
4007
- // In this prioritized order, we try to move a colliding item around the
4008
- // moving one:
4009
- // 1. to its left side
4010
- // 2. above it
4011
- // 3. under it
4012
- // 4. to its right side
4013
- var position = this._getItemPosition(item);
4014
-
4015
- leftOfItem = [position.x - collidingPosition.w, collidingPosition.y];
4016
- rightOfItem = [position.x + position.w, collidingPosition.y];
4017
- aboveOfItem = [collidingPosition.x, position.y - collidingPosition.h];
4018
- belowOfItem = [collidingPosition.x, position.y + position.h];
4019
-
4020
- if (_gridList._itemFitsAtPosition(collidingItem, leftOfItem)) {
4021
- _gridList._updateItemPosition(collidingItem, leftOfItem);
4022
- } else if (_gridList._itemFitsAtPosition(collidingItem, aboveOfItem)) {
4023
- _gridList._updateItemPosition(collidingItem, aboveOfItem);
4024
- } else if (_gridList._itemFitsAtPosition(collidingItem, belowOfItem)) {
4025
- _gridList._updateItemPosition(collidingItem, belowOfItem);
4026
- } else if (_gridList._itemFitsAtPosition(collidingItem, rightOfItem)) {
4027
- _gridList._updateItemPosition(collidingItem, rightOfItem);
4028
- } else {
4029
- // Collisions failed, we must use the pullItemsToLeft method to arrange
4030
- // the other items around this item with fixed position. This is our
4031
- // plan B for when local collision resolving fails.
4032
- return false;
4033
- }
4034
- }
4035
- // If we reached this point it means we managed to resolve the collisions
4036
- // from one single iteration, just by moving the colliding items around. So
4037
- // we accept this scenario and marge the brached-out grid instance into the
4038
- // original one
4039
- GridList.cloneItems(_gridList.items, this.items);
4040
- this.generateGrid();
4041
- return true;
4042
- },
4043
-
4044
- _pullItemsToLeft: function(fixedItem) {
4045
- /**
4046
- * Build the grid from scratch, by using the current item positions and
4047
- * pulling them as much to the left as possible, removing as space between
4048
- * them as possible.
4049
- *
4050
- * If a "fixed item" is provided, its position will be kept intact and the
4051
- * rest of the items will be layed around it.
4052
- */
4053
-
4054
-
4055
- // Start a fresh grid with the fixed item already placed inside
4056
- this._sortItemsByPosition();
4057
- this._resetGrid();
4058
-
4059
- // Start the grid with the fixed item as the first positioned item
4060
- if (fixedItem) {
4061
- var fixedPosition = this._getItemPosition(fixedItem);
4062
- this._updateItemPosition(fixedItem, [fixedPosition.x, fixedPosition.y]);
4063
- }
4064
-
4065
- for (var i = 0; i < this.items.length; i++) {
4066
- var item = this.items[i],
4067
- position = this._getItemPosition(item);
4068
-
4069
- // The fixed item keeps its exact position
4070
- if (fixedItem && item == fixedItem) {
4071
- continue;
4072
- }
4073
-
4074
- var x = this._findLeftMostPositionForItem(item),
4075
- newPosition = this.findPositionForItem(
4076
- item, {x: x, y: 0}, position.y);
4077
-
4078
- this._updateItemPosition(item, newPosition);
4079
- }
4080
- },
4081
-
4082
- _findLeftMostPositionForItem: function(item) {
4083
- /**
4084
- * When pulling items to the left, we need to find the leftmost position for
4085
- * an item, with two considerations in mind:
4086
- * - preserving its current row
4087
- * - preserving the previous horizontal order between items
4088
- */
4089
-
4090
- var tail = 0,
4091
- position = this._getItemPosition(item);
4092
-
4093
- for (var i = 0; i < this.grid.length; i++) {
4094
- for (var j = position.y; j < position.y + position.h; j++) {
4095
- var otherItem = this.grid[i][j];
4096
-
4097
- if (!otherItem) {
4098
- continue;
4099
- }
4100
-
4101
- var otherPosition = this._getItemPosition(otherItem);
4102
-
4103
- if (this.items.indexOf(otherItem) < this.items.indexOf(item)) {
4104
- tail = otherPosition.x + otherPosition.w;
4105
- }
4106
- }
4107
- }
4108
-
4109
- return tail;
4110
- },
4111
-
4112
- _getItemByAttribute: function(key, value) {
4113
- for (var i = 0; i < this.items.length; i++) {
4114
- if (this.items[i][key] === value) {
4115
- return this.items[i];
4116
- }
4117
- }
4118
- return null;
4119
- },
4120
-
4121
- _padNumber: function(nr, prefix) {
4122
- // Currently works for 2-digit numbers (<100)
4123
- return nr >= 10 ? nr : prefix + nr;
4124
- },
4125
-
4126
- _getItemPosition: function(item) {
4127
- /**
4128
- * If the direction is vertical we need to rotate the grid 90 deg to the
4129
- * left. Thus, we simulate the fact that items are being pulled to the top.
4130
- *
4131
- * Since the items have widths and heights, if we apply the classic
4132
- * counter-clockwise 90 deg rotation
4133
- *
4134
- * [0 -1]
4135
- * [1 0]
4136
- *
4137
- * then the top left point of an item will become the bottom left point of
4138
- * the rotated item. To adjust for this, we need to subtract from the y
4139
- * position the height of the original item - the width of the rotated item.
4140
- *
4141
- * However, if we do this then we'll reverse some actions: resizing the
4142
- * width of an item will stretch the item to the left instead of to the
4143
- * right; resizing an item that doesn't fit into the grid will push the
4144
- * items around it instead of going on a new row, etc.
4145
- *
4146
- * We found it better to do a vertical flip of the grid after rotating it.
4147
- * This restores the direction of the actions and greatly simplifies the
4148
- * transformations.
4149
- */
4150
-
4151
- if (this._options.direction === 'horizontal') {
4152
- return item;
4153
- } else {
4154
- return {
4155
- x: item.y,
4156
- y: item.x,
4157
- w: item.h,
4158
- h: item.w
4159
- };
4160
- }
4161
- },
4162
-
4163
- _setItemPosition: function(item, position) {
4164
- /**
4165
- * See _getItemPosition.
4166
- */
4167
-
4168
- if (this._options.direction === 'horizontal') {
4169
- item.x = position[0];
4170
- item.y = position[1];
4171
- } else {
4172
- // We're supposed to subtract the rotated item's height which is actually
4173
- // the non-rotated item's width.
4174
- item.x = position[1];
4175
- item.y = position[0];
4176
- }
4177
- }
4178
- };
4179
-
4180
- var GridCol = function(lanes) {
4181
- for (var i = 0; i < lanes; i++) {
4182
- this.push(null);
4183
- }
4184
- };
4185
-
4186
- // Extend the Array prototype
4187
- GridCol.prototype = [];
4188
-
4189
- // This module will have direct access to the GridList class
4190
- return GridList;
4191
-
4192
- }));
4193
- }(gridList$1));
4194
-
4195
- var gridList = gridList$1.exports;
3511
+ (function (root, factory) {
3512
+ {
3513
+ // Node. Does not work with strict CommonJS, but
3514
+ // only CommonJS-like environments that support module.exports,
3515
+ // like Node.
3516
+ module.exports = factory();
3517
+ }
3518
+ }(commonjsGlobal, function() {
3519
+
3520
+ var GridList = function(items, options) {
3521
+ /**
3522
+ * A GridList manages the two-dimensional positions from a list of items,
3523
+ * within a virtual matrix.
3524
+ *
3525
+ * The GridList's main function is to convert the item positions from one
3526
+ * grid size to another, maintaining as much of their order as possible.
3527
+ *
3528
+ * The GridList's second function is to handle collisions when moving an item
3529
+ * over another.
3530
+ *
3531
+ * The positioning algorithm places items in columns. Starting from left to
3532
+ * right, going through each column top to bottom.
3533
+ *
3534
+ * The size of an item is expressed using the number of cols and rows it
3535
+ * takes up within the grid (w and h)
3536
+ *
3537
+ * The position of an item is express using the col and row position within
3538
+ * the grid (x and y)
3539
+ *
3540
+ * An item is an object of structure:
3541
+ * {
3542
+ * w: 3, h: 1,
3543
+ * x: 0, y: 1
3544
+ * }
3545
+ */
3546
+
3547
+ this._options = options;
3548
+ for (var k in this.defaults) {
3549
+ if (!this._options.hasOwnProperty(k)) {
3550
+ this._options[k] = this.defaults[k];
3551
+ }
3552
+ }
3553
+
3554
+ this.items = items;
3555
+
3556
+ this._adjustSizeOfItems();
3557
+
3558
+ this.generateGrid();
3559
+ };
3560
+
3561
+ GridList.cloneItems = function(items, _items) {
3562
+ /**
3563
+ * Clone items with a deep level of one. Items are not referenced but their
3564
+ * properties are
3565
+ */
3566
+ var i,
3567
+ k;
3568
+ if (_items === undefined) {
3569
+ _items = [];
3570
+ }
3571
+ for (i = 0; i < items.length; i++) {
3572
+ // XXX: this is good because we don't want to lose item reference, but
3573
+ // maybe we should clear their properties since some might be optional
3574
+ if (!_items[i]) {
3575
+ _items[i] = {};
3576
+ }
3577
+ for (k in items[i]) {
3578
+ _items[i][k] = items[i][k];
3579
+ }
3580
+ }
3581
+ return _items;
3582
+ };
3583
+
3584
+ GridList.prototype = {
3585
+
3586
+ defaults: {
3587
+ lanes: 5,
3588
+ direction: 'horizontal'
3589
+ },
3590
+
3591
+ /**
3592
+ * Illustates grid as text-based table, using a number identifier for each
3593
+ * item. E.g.
3594
+ *
3595
+ * #| 0 1 2 3 4 5 6 7 8 9 10 11 12 13
3596
+ * --------------------------------------------
3597
+ * 0| 00 02 03 04 04 06 08 08 08 12 12 13 14 16
3598
+ * 1| 01 -- 03 05 05 07 09 10 11 11 -- 13 15 --
3599
+ *
3600
+ * Warn: Does not work if items don't have a width or height specified
3601
+ * besides their position in the grid.
3602
+ */
3603
+ toString: function() {
3604
+ var widthOfGrid = this.grid.length,
3605
+ output = '\n #|',
3606
+ border = '\n --',
3607
+ item,
3608
+ i,
3609
+ j;
3610
+
3611
+ // Render the table header
3612
+ for (i = 0; i < widthOfGrid; i++) {
3613
+ output += ' ' + this._padNumber(i, ' ');
3614
+ border += '---';
3615
+ } output += border;
3616
+
3617
+ // Render table contents row by row, as we go on the y axis
3618
+ for (i = 0; i < this._options.lanes; i++) {
3619
+ output += '\n' + this._padNumber(i, ' ') + '|';
3620
+ for (j = 0; j < widthOfGrid; j++) {
3621
+ output += ' ';
3622
+ item = this.grid[j][i];
3623
+ output += item ? this._padNumber(this.items.indexOf(item), '0') : '--';
3624
+ }
3625
+ } output += '\n';
3626
+ return output;
3627
+ },
3628
+
3629
+ generateGrid: function() {
3630
+ /**
3631
+ * Build the grid structure from scratch, with the current item positions
3632
+ */
3633
+ var i;
3634
+ this._resetGrid();
3635
+ for (i = 0; i < this.items.length; i++) {
3636
+ this._markItemPositionToGrid(this.items[i]);
3637
+ }
3638
+ },
3639
+
3640
+ resizeGrid: function(lanes) {
3641
+ var currentColumn = 0;
3642
+
3643
+ this._options.lanes = lanes;
3644
+ this._adjustSizeOfItems();
3645
+
3646
+ this._sortItemsByPosition();
3647
+ this._resetGrid();
3648
+
3649
+ // The items will be sorted based on their index within the this.items array,
3650
+ // that is their "1d position"
3651
+ for (var i = 0; i < this.items.length; i++) {
3652
+ var item = this.items[i],
3653
+ position = this._getItemPosition(item);
3654
+
3655
+ this._updateItemPosition(
3656
+ item, this.findPositionForItem(item, {x: currentColumn, y: 0}));
3657
+
3658
+ // New items should never be placed to the left of previous items
3659
+ currentColumn = Math.max(currentColumn, position.x);
3660
+ }
3661
+
3662
+ this._pullItemsToLeft();
3663
+ },
3664
+
3665
+ findPositionForItem: function(item, start, fixedRow) {
3666
+ /**
3667
+ * This method has two options for the position we want for the item:
3668
+ * - Starting from a certain row/column number and only looking for
3669
+ * positions to its right
3670
+ * - Accepting positions for a certain row number only (use-case: items
3671
+ * being shifted to the left/right as a result of collisions)
3672
+ *
3673
+ * @param {Object<x:Number, y:Number, w:Number, h:Number} item
3674
+ * @param {Object<x:Number, y:Number} start Position from which to start
3675
+ * the search.
3676
+ * @param {Number} [fixedRow] If provided, we're going to try to find a
3677
+ * position for the new item on it. If doesn't fit there, we're going
3678
+ * to put it on the first row.
3679
+ *
3680
+ * @returns {Number[2]} x and y.
3681
+ */
3682
+
3683
+ var x, y, position;
3684
+
3685
+ // Start searching for a position from the horizontal position of the
3686
+ // rightmost item from the grid
3687
+ for (x = start.x; x < this.grid.length; x++) {
3688
+ if (fixedRow !== undefined) {
3689
+ position = [x, fixedRow];
3690
+
3691
+ if (this._itemFitsAtPosition(item, position)) {
3692
+ return position;
3693
+ }
3694
+ } else {
3695
+ for (y = start.y; y < this._options.lanes; y++) {
3696
+ position = [x, y];
3697
+
3698
+ if (this._itemFitsAtPosition(item, position)) {
3699
+ return position;
3700
+ }
3701
+ }
3702
+ }
3703
+ }
3704
+
3705
+ // If we've reached this point, we need to start a new column
3706
+ var newCol = this.grid.length,
3707
+ newRow = 0;
3708
+
3709
+ if (fixedRow !== undefined &&
3710
+ this._itemFitsAtPosition(item, [newCol, fixedRow])) {
3711
+ newRow = fixedRow;
3712
+ }
3713
+
3714
+ return [newCol, newRow];
3715
+ },
3716
+
3717
+ moveItemToPosition: function(item, newPosition) {
3718
+ var position = this._getItemPosition({
3719
+ x: newPosition[0],
3720
+ y: newPosition[1],
3721
+ w: item.w,
3722
+ h: item.h
3723
+ });
3724
+
3725
+ this._updateItemPosition(item, [position.x, position.y]);
3726
+ this._resolveCollisions(item);
3727
+ },
3728
+
3729
+ resizeItem: function(item, size) {
3730
+ /**
3731
+ * Resize an item and resolve collisions.
3732
+ *
3733
+ * @param {Object} item A reference to an item that's part of the grid.
3734
+ * @param {Object} size
3735
+ * @param {Number} [size.w=item.w] The new width.
3736
+ * @param {Number} [size.h=item.h] The new height.
3737
+ */
3738
+
3739
+ var width = size.w || item.w,
3740
+ height = size.h || item.h;
3741
+
3742
+ this._updateItemSize(item, width, height);
3743
+
3744
+ this._resolveCollisions(item);
3745
+
3746
+ this._pullItemsToLeft();
3747
+ },
3748
+
3749
+ getChangedItems: function(initialItems, idAttribute) {
3750
+ /**
3751
+ * Compare the current items against a previous snapshot and return only
3752
+ * the ones that changed their attributes in the meantime. This includes both
3753
+ * position (x, y) and size (w, h)
3754
+ *
3755
+ * Since both their position and size can change, the items need an
3756
+ * additional identifier attribute to match them with their previous state
3757
+ */
3758
+ var changedItems = [];
3759
+
3760
+ for (var i = 0; i < initialItems.length; i++) {
3761
+ var item = this._getItemByAttribute(idAttribute,
3762
+ initialItems[i][idAttribute]);
3763
+
3764
+ if (item.x !== initialItems[i].x ||
3765
+ item.y !== initialItems[i].y ||
3766
+ item.w !== initialItems[i].w ||
3767
+ item.h !== initialItems[i].h) {
3768
+ changedItems.push(item);
3769
+ }
3770
+ }
3771
+
3772
+ return changedItems;
3773
+ },
3774
+
3775
+ _sortItemsByPosition: function() {
3776
+ this.items.sort(function(item1, item2) {
3777
+ var position1 = this._getItemPosition(item1),
3778
+ position2 = this._getItemPosition(item2);
3779
+
3780
+ // Try to preserve columns.
3781
+ if (position1.x != position2.x) {
3782
+ return position1.x - position2.x;
3783
+ }
3784
+
3785
+ if (position1.y != position2.y) {
3786
+ return position1.y - position2.y;
3787
+ }
3788
+
3789
+ // The items are placed on the same position.
3790
+ return 0;
3791
+ }.bind(this));
3792
+ },
3793
+
3794
+ _adjustSizeOfItems: function() {
3795
+ /**
3796
+ * Some items can have 100% height or 100% width. Those dimmensions are
3797
+ * expressed as 0. We need to ensure a valid width and height for each of
3798
+ * those items as the number of items per lane.
3799
+ */
3800
+
3801
+ for (var i = 0; i < this.items.length; i++) {
3802
+ var item = this.items[i];
3803
+
3804
+ // This can happen only the first time items are checked.
3805
+ // We need the property to have a value for all the items so that the
3806
+ // `cloneItems` method will merge the properties properly. If we only set
3807
+ // it to the items that need it then the following can happen:
3808
+ //
3809
+ // cloneItems([{id: 1, autoSize: true}, {id: 2}],
3810
+ // [{id: 2}, {id: 1, autoSize: true}]);
3811
+ //
3812
+ // will result in
3813
+ //
3814
+ // [{id: 1, autoSize: true}, {id: 2, autoSize: true}]
3815
+ if (item.autoSize === undefined) {
3816
+ item.autoSize = item.w === 0 || item.h === 0;
3817
+ }
3818
+
3819
+ if (item.autoSize) {
3820
+ if (this._options.direction === 'horizontal') {
3821
+ item.h = this._options.lanes;
3822
+ } else {
3823
+ item.w = this._options.lanes;
3824
+ }
3825
+ }
3826
+ }
3827
+ },
3828
+
3829
+ _resetGrid: function() {
3830
+ this.grid = [];
3831
+ },
3832
+
3833
+ _itemFitsAtPosition: function(item, newPosition) {
3834
+ /**
3835
+ * Check that an item wouldn't overlap with another one if placed at a
3836
+ * certain position within the grid
3837
+ */
3838
+
3839
+ var position = this._getItemPosition(item),
3840
+ x, y;
3841
+
3842
+ // No coordonate can be negative
3843
+ if (newPosition[0] < 0 || newPosition[1] < 0) {
3844
+ return false;
3845
+ }
3846
+
3847
+ // Make sure the item isn't larger than the entire grid
3848
+ if (newPosition[1] + position.h > this._options.lanes) {
3849
+ return false;
3850
+ }
3851
+
3852
+ // Make sure the position doesn't overlap with an already positioned
3853
+ // item.
3854
+ for (x = newPosition[0]; x < newPosition[0] + position.w; x++) {
3855
+ var col = this.grid[x];
3856
+
3857
+ // Surely a column that hasn't even been created yet is available
3858
+ if (!col) {
3859
+ continue;
3860
+ }
3861
+
3862
+ for (y = newPosition[1]; y < newPosition[1] + position.h; y++) {
3863
+ // Any space occupied by an item can continue to be occupied by the
3864
+ // same item.
3865
+ if (col[y] && col[y] !== item) {
3866
+ return false;
3867
+ }
3868
+ }
3869
+ }
3870
+
3871
+ return true;
3872
+ },
3873
+
3874
+ _updateItemPosition: function(item, position) {
3875
+ if (item.x !== null && item.y !== null) {
3876
+ this._deleteItemPositionFromGrid(item);
3877
+ }
3878
+
3879
+ this._setItemPosition(item, position);
3880
+
3881
+ this._markItemPositionToGrid(item);
3882
+ },
3883
+
3884
+ _updateItemSize: function(item, width, height) {
3885
+ /**
3886
+ * @param {Object} item A reference to a grid item.
3887
+ * @param {Number} width The new width.
3888
+ * @param {Number} height The new height.
3889
+ */
3890
+
3891
+ if (item.x !== null && item.y !== null) {
3892
+ this._deleteItemPositionFromGrid(item);
3893
+ }
3894
+
3895
+ item.w = width;
3896
+ item.h = height;
3897
+
3898
+ this._markItemPositionToGrid(item);
3899
+ },
3900
+
3901
+ _markItemPositionToGrid: function(item) {
3902
+ /**
3903
+ * Mark the grid cells that are occupied by an item. This prevents items
3904
+ * from overlapping in the grid
3905
+ */
3906
+
3907
+ var position = this._getItemPosition(item),
3908
+ x, y;
3909
+
3910
+ // Ensure that the grid has enough columns to accomodate the current item.
3911
+ this._ensureColumns(position.x + position.w);
3912
+
3913
+ for (x = position.x; x < position.x + position.w; x++) {
3914
+ for (y = position.y; y < position.y + position.h; y++) {
3915
+ this.grid[x][y] = item;
3916
+ }
3917
+ }
3918
+ },
3919
+
3920
+ _deleteItemPositionFromGrid: function(item) {
3921
+ var position = this._getItemPosition(item),
3922
+ x, y;
3923
+
3924
+ for (x = position.x; x < position.x + position.w; x++) {
3925
+ // It can happen to try to remove an item from a position not generated
3926
+ // in the grid, probably when loading a persisted grid of items. No need
3927
+ // to create a column to be able to remove something from it, though
3928
+ if (!this.grid[x]) {
3929
+ continue;
3930
+ }
3931
+
3932
+ for (y = position.y; y < position.y + position.h; y++) {
3933
+ // Don't clear the cell if it's been occupied by a different widget in
3934
+ // the meantime (e.g. when an item has been moved over this one, and
3935
+ // thus by continuing to clear this item's previous position you would
3936
+ // cancel the first item's move, leaving it without any position even)
3937
+ if (this.grid[x][y] == item) {
3938
+ this.grid[x][y] = null;
3939
+ }
3940
+ }
3941
+ }
3942
+ },
3943
+
3944
+ _ensureColumns: function(N) {
3945
+ /**
3946
+ * Ensure that the grid has at least N columns available.
3947
+ */
3948
+ var i;
3949
+ for (i = 0; i < N; i++) {
3950
+ if (!this.grid[i]) {
3951
+ this.grid.push(new GridCol(this._options.lanes));
3952
+ }
3953
+ }
3954
+ },
3955
+
3956
+ _getItemsCollidingWithItem: function(item) {
3957
+ var collidingItems = [];
3958
+ for (var i = 0; i < this.items.length; i++) {
3959
+ if (item != this.items[i] &&
3960
+ this._itemsAreColliding(item, this.items[i])) {
3961
+ collidingItems.push(i);
3962
+ }
3963
+ }
3964
+ return collidingItems;
3965
+ },
3966
+
3967
+ _itemsAreColliding: function(item1, item2) {
3968
+ var position1 = this._getItemPosition(item1),
3969
+ position2 = this._getItemPosition(item2);
3970
+
3971
+ return !(position2.x >= position1.x + position1.w ||
3972
+ position2.x + position2.w <= position1.x ||
3973
+ position2.y >= position1.y + position1.h ||
3974
+ position2.y + position2.h <= position1.y);
3975
+ },
3976
+
3977
+ _resolveCollisions: function(item) {
3978
+ if (!this._tryToResolveCollisionsLocally(item)) {
3979
+ this._pullItemsToLeft(item);
3980
+ }
3981
+ this._pullItemsToLeft();
3982
+ },
3983
+
3984
+ _tryToResolveCollisionsLocally: function(item) {
3985
+ /**
3986
+ * Attempt to resolve the collisions after moving a an item over one or more
3987
+ * other items within the grid, by shifting the position of the colliding
3988
+ * items around the moving one. This might result in subsequent collisions,
3989
+ * in which case we will revert all position permutations. To be able to
3990
+ * revert to the initial item positions, we create a virtual grid in the
3991
+ * process
3992
+ */
3993
+ var collidingItems = this._getItemsCollidingWithItem(item);
3994
+ if (!collidingItems.length) {
3995
+ return true;
3996
+ }
3997
+ var _gridList = new GridList([], this._options),
3998
+ leftOfItem,
3999
+ rightOfItem,
4000
+ aboveOfItem,
4001
+ belowOfItem;
4002
+
4003
+ GridList.cloneItems(this.items, _gridList.items);
4004
+ _gridList.generateGrid();
4005
+
4006
+ for (var i = 0; i < collidingItems.length; i++) {
4007
+ var collidingItem = _gridList.items[collidingItems[i]],
4008
+ collidingPosition = this._getItemPosition(collidingItem);
4009
+
4010
+ // We use a simple algorithm for moving items around when collisions occur:
4011
+ // In this prioritized order, we try to move a colliding item around the
4012
+ // moving one:
4013
+ // 1. to its left side
4014
+ // 2. above it
4015
+ // 3. under it
4016
+ // 4. to its right side
4017
+ var position = this._getItemPosition(item);
4018
+
4019
+ leftOfItem = [position.x - collidingPosition.w, collidingPosition.y];
4020
+ rightOfItem = [position.x + position.w, collidingPosition.y];
4021
+ aboveOfItem = [collidingPosition.x, position.y - collidingPosition.h];
4022
+ belowOfItem = [collidingPosition.x, position.y + position.h];
4023
+
4024
+ if (_gridList._itemFitsAtPosition(collidingItem, leftOfItem)) {
4025
+ _gridList._updateItemPosition(collidingItem, leftOfItem);
4026
+ } else if (_gridList._itemFitsAtPosition(collidingItem, aboveOfItem)) {
4027
+ _gridList._updateItemPosition(collidingItem, aboveOfItem);
4028
+ } else if (_gridList._itemFitsAtPosition(collidingItem, belowOfItem)) {
4029
+ _gridList._updateItemPosition(collidingItem, belowOfItem);
4030
+ } else if (_gridList._itemFitsAtPosition(collidingItem, rightOfItem)) {
4031
+ _gridList._updateItemPosition(collidingItem, rightOfItem);
4032
+ } else {
4033
+ // Collisions failed, we must use the pullItemsToLeft method to arrange
4034
+ // the other items around this item with fixed position. This is our
4035
+ // plan B for when local collision resolving fails.
4036
+ return false;
4037
+ }
4038
+ }
4039
+ // If we reached this point it means we managed to resolve the collisions
4040
+ // from one single iteration, just by moving the colliding items around. So
4041
+ // we accept this scenario and marge the brached-out grid instance into the
4042
+ // original one
4043
+ GridList.cloneItems(_gridList.items, this.items);
4044
+ this.generateGrid();
4045
+ return true;
4046
+ },
4047
+
4048
+ _pullItemsToLeft: function(fixedItem) {
4049
+ /**
4050
+ * Build the grid from scratch, by using the current item positions and
4051
+ * pulling them as much to the left as possible, removing as space between
4052
+ * them as possible.
4053
+ *
4054
+ * If a "fixed item" is provided, its position will be kept intact and the
4055
+ * rest of the items will be layed around it.
4056
+ */
4057
+
4058
+
4059
+ // Start a fresh grid with the fixed item already placed inside
4060
+ this._sortItemsByPosition();
4061
+ this._resetGrid();
4062
+
4063
+ // Start the grid with the fixed item as the first positioned item
4064
+ if (fixedItem) {
4065
+ var fixedPosition = this._getItemPosition(fixedItem);
4066
+ this._updateItemPosition(fixedItem, [fixedPosition.x, fixedPosition.y]);
4067
+ }
4068
+
4069
+ for (var i = 0; i < this.items.length; i++) {
4070
+ var item = this.items[i],
4071
+ position = this._getItemPosition(item);
4072
+
4073
+ // The fixed item keeps its exact position
4074
+ if (fixedItem && item == fixedItem) {
4075
+ continue;
4076
+ }
4077
+
4078
+ var x = this._findLeftMostPositionForItem(item),
4079
+ newPosition = this.findPositionForItem(
4080
+ item, {x: x, y: 0}, position.y);
4081
+
4082
+ this._updateItemPosition(item, newPosition);
4083
+ }
4084
+ },
4085
+
4086
+ _findLeftMostPositionForItem: function(item) {
4087
+ /**
4088
+ * When pulling items to the left, we need to find the leftmost position for
4089
+ * an item, with two considerations in mind:
4090
+ * - preserving its current row
4091
+ * - preserving the previous horizontal order between items
4092
+ */
4093
+
4094
+ var tail = 0,
4095
+ position = this._getItemPosition(item);
4096
+
4097
+ for (var i = 0; i < this.grid.length; i++) {
4098
+ for (var j = position.y; j < position.y + position.h; j++) {
4099
+ var otherItem = this.grid[i][j];
4100
+
4101
+ if (!otherItem) {
4102
+ continue;
4103
+ }
4104
+
4105
+ var otherPosition = this._getItemPosition(otherItem);
4106
+
4107
+ if (this.items.indexOf(otherItem) < this.items.indexOf(item)) {
4108
+ tail = otherPosition.x + otherPosition.w;
4109
+ }
4110
+ }
4111
+ }
4112
+
4113
+ return tail;
4114
+ },
4115
+
4116
+ _getItemByAttribute: function(key, value) {
4117
+ for (var i = 0; i < this.items.length; i++) {
4118
+ if (this.items[i][key] === value) {
4119
+ return this.items[i];
4120
+ }
4121
+ }
4122
+ return null;
4123
+ },
4124
+
4125
+ _padNumber: function(nr, prefix) {
4126
+ // Currently works for 2-digit numbers (<100)
4127
+ return nr >= 10 ? nr : prefix + nr;
4128
+ },
4129
+
4130
+ _getItemPosition: function(item) {
4131
+ /**
4132
+ * If the direction is vertical we need to rotate the grid 90 deg to the
4133
+ * left. Thus, we simulate the fact that items are being pulled to the top.
4134
+ *
4135
+ * Since the items have widths and heights, if we apply the classic
4136
+ * counter-clockwise 90 deg rotation
4137
+ *
4138
+ * [0 -1]
4139
+ * [1 0]
4140
+ *
4141
+ * then the top left point of an item will become the bottom left point of
4142
+ * the rotated item. To adjust for this, we need to subtract from the y
4143
+ * position the height of the original item - the width of the rotated item.
4144
+ *
4145
+ * However, if we do this then we'll reverse some actions: resizing the
4146
+ * width of an item will stretch the item to the left instead of to the
4147
+ * right; resizing an item that doesn't fit into the grid will push the
4148
+ * items around it instead of going on a new row, etc.
4149
+ *
4150
+ * We found it better to do a vertical flip of the grid after rotating it.
4151
+ * This restores the direction of the actions and greatly simplifies the
4152
+ * transformations.
4153
+ */
4154
+
4155
+ if (this._options.direction === 'horizontal') {
4156
+ return item;
4157
+ } else {
4158
+ return {
4159
+ x: item.y,
4160
+ y: item.x,
4161
+ w: item.h,
4162
+ h: item.w
4163
+ };
4164
+ }
4165
+ },
4166
+
4167
+ _setItemPosition: function(item, position) {
4168
+ /**
4169
+ * See _getItemPosition.
4170
+ */
4171
+
4172
+ if (this._options.direction === 'horizontal') {
4173
+ item.x = position[0];
4174
+ item.y = position[1];
4175
+ } else {
4176
+ // We're supposed to subtract the rotated item's height which is actually
4177
+ // the non-rotated item's width.
4178
+ item.x = position[1];
4179
+ item.y = position[0];
4180
+ }
4181
+ }
4182
+ };
4183
+
4184
+ var GridCol = function(lanes) {
4185
+ for (var i = 0; i < lanes; i++) {
4186
+ this.push(null);
4187
+ }
4188
+ };
4189
+
4190
+ // Extend the Array prototype
4191
+ GridCol.prototype = [];
4192
+
4193
+ // This module will have direct access to the GridList class
4194
+ return GridList;
4195
+
4196
+ }));
4197
+ } (gridList$1));
4198
+
4199
+ var gridListExports = gridList$1.exports;
4200
+ var gridList = /*@__PURE__*/getDefaultExportFromCjs(gridListExports);
4196
4201
 
4197
4202
  var _GridList = /*#__PURE__*/_mergeNamespaces({
4198
4203
  __proto__: null,
4199
- 'default': gridList
4200
- }, [gridList$1.exports]);
4204
+ default: gridList
4205
+ }, [gridListExports]);
4201
4206
 
4202
4207
  var css_248z$3 = ".layout_Grid>.ddCell{position:absolute}.layout_Grid>.laneBackground{background:#f5f5f5;border-style:solid;border-width:1px;position:absolute}.layout_Grid>.lane{border-radius:0;border-style:none;opacity:.25;pointer-events:none;position:absolute}.layout_Grid>.ddCell.draggable{background-color:#f8f8ff;border-radius:0;border-style:solid;border-width:1px;cursor:move}.layout_Grid>.ddCell.draggable>.resizeHandle{border-style:none;bottom:0;cursor:nwse-resize;height:8px;position:absolute;right:0;width:8px}.layout_Grid>.ddCell.draggable .resizeHandleDisplay{background-color:none;border-color:#a9a9a9;border-style:solid;border-width:0 2px 2px 0;bottom:2px;height:4px;position:absolute;right:2px;width:4px}.layout_Grid>.ddCell.draggable .resizeHandleDisplay:hover{border-color:orange}.layout_Grid>.dragging{background:repeating-linear-gradient(-45deg,transparent,transparent 4px,hsla(0,0%,39%,.1) 0,hsla(0,0%,39%,.1) 8px)}.layout_Grid>.dragging,.layout_Grid>.resizing{border:1px solid gray;border-radius:0;position:absolute}.layout_Grid>.resizing{background-color:orange;background:repeating-linear-gradient(-45deg,transparent,transparent 4px,orange 0,orange 8px);opacity:.3}.layout_Grid>.ddCell.draggable .common_Widget.selected{background-color:gray;background:repeating-linear-gradient(-45deg,transparent,transparent 4px,rgba(100,0,0,.1) 0,rgba(100,0,0,.1) 8px);border:1px solid red;border-radius:0;position:absolute}.layout_Grid #drag-me:before{content:\"#\" attr(id);font-weight:700}";
4203
4208
  styleInject(css_248z$3);
@@ -5120,7 +5125,5 @@
5120
5125
  exports.VerticalList = VerticalList;
5121
5126
  exports.WidgetDiv = WidgetDiv;
5122
5127
 
5123
- Object.defineProperty(exports, '__esModule', { value: true });
5124
-
5125
5128
  }));
5126
5129
  //# sourceMappingURL=index.js.map