@lumico/angular-gridster2
Version:
Angular gridster 2
1,316 lines (1,304 loc) • 173 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define('angular-gridster2', ['exports', '@angular/core', '@angular/common'], factory) :
(global = global || self, factory(global['angular-gridster2'] = {}, global.ng.core, global.ng.common));
}(this, function (exports, core, common) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {string} */
var GridType = {
Fit: 'fit',
ScrollVertical: 'scrollVertical',
ScrollHorizontal: 'scrollHorizontal',
Fixed: 'fixed',
VerticalFixed: 'verticalFixed',
HorizontalFixed: 'horizontalFixed',
};
/** @enum {string} */
var DisplayGrid = {
Always: 'always',
OnDragAndResize: 'onDrag&Resize',
None: 'none',
};
/** @enum {string} */
var CompactType = {
None: 'none',
CompactUp: 'compactUp',
CompactLeft: 'compactLeft',
CompactUpAndLeft: 'compactUp&Left',
CompactLeftAndUp: 'compactLeft&Up',
CompactRight: 'compactRight',
CompactUpAndRight: 'compactUp&Right',
CompactRightAndUp: 'compactRight&Up',
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var GridsterConfigService = {
gridType: GridType.Fit,
// 'fit' will fit the items in the container without scroll;
// 'scrollVertical' will fit on width and height of the items will be the same as the width
// 'scrollHorizontal' will fit on height and width of the items will be the same as the height
// 'fixed' will set the rows and columns dimensions based on fixedColWidth and fixedRowHeight options
// 'verticalFixed' will set the rows to fixedRowHeight and columns width will fit the space available
// 'horizontalFixed' will set the columns to fixedColWidth and rows height will fit the space available
fixedColWidth: 250,
// fixed col width for gridType: 'fixed'
fixedRowHeight: 250,
// fixed row height for gridType: 'fixed'
keepFixedHeightInMobile: false,
// keep the height from fixed gridType in mobile layout
keepFixedWidthInMobile: false,
// keep the width from fixed gridType in mobile layout
setGridSize: false,
// sets grid size depending on content
compactType: CompactType.None,
// compact items: 'none' | 'compactUp' | 'compactLeft' | 'compactUp&Left' | 'compactLeft&Up'
mobileBreakpoint: 640,
// if the screen is not wider that this, remove the grid layout and stack the items
minCols: 1,
// minimum amount of columns in the grid
maxCols: 100,
// maximum amount of columns in the grid
minRows: 1,
// minimum amount of rows in the grid
maxRows: 100,
// maximum amount of rows in the grid
defaultItemCols: 1,
// default width of an item in columns
defaultItemRows: 1,
// default height of an item in rows
maxItemCols: 50,
// max item number of cols
maxItemRows: 50,
// max item number of rows
minItemCols: 1,
// min item number of columns
minItemRows: 1,
// min item number of rows
minItemArea: 1,
// min item area: cols * rows
maxItemArea: 2500,
// max item area: cols * rows
margin: 10,
// margin between grid items
outerMargin: true,
// if margins will apply to the sides of the container
outerMarginTop: null,
// override outer margin for grid
outerMarginRight: null,
// override outer margin for grid
outerMarginBottom: null,
// override outer margin for grid
outerMarginLeft: null,
// override outer margin for grid
useTransformPositioning: true,
// toggle between transform or top/left positioning of items
scrollSensitivity: 10,
// margin of the dashboard where to start scrolling
scrollSpeed: 20,
// how much to scroll each mouse move when in the scrollSensitivity zone
initCallback: undefined,
// callback to call after grid has initialized. Arguments: gridsterComponent
destroyCallback: undefined,
// callback to call after grid has destroyed. Arguments: gridsterComponent
gridSizeChangedCallback: undefined,
// callback to call after grid has changed size. Arguments: gridsterComponent
itemChangeCallback: undefined,
// callback to call for each item when is changes x, y, rows, cols.
// Arguments: gridsterItem, gridsterItemComponent
itemResizeCallback: undefined,
// callback to call for each item when width/height changes.
// Arguments: gridsterItem, gridsterItemComponent
itemInitCallback: undefined,
// callback to call for each item when is initialized.
// Arguments: gridsterItem, gridsterItemComponent
itemRemovedCallback: undefined,
// callback to call for each item when is initialized.
// Arguments: gridsterItem, gridsterItemComponent
itemValidateCallback: undefined,
// callback to call to validate item position/size. Return true if valid.
// Arguments: gridsterItem
enableEmptyCellClick: false,
// enable empty cell click events
enableEmptyCellContextMenu: false,
// enable empty cell context menu (right click) events
enableEmptyCellDrop: false,
// enable empty cell drop events
enableEmptyCellDrag: false,
// enable empty cell drag events
emptyCellClickCallback: undefined,
// empty cell click callback
emptyCellContextMenuCallback: undefined,
// empty cell context menu (right click) callback
emptyCellDropCallback: undefined,
// empty cell drag drop callback. HTML5 Drag & Drop
emptyCellDragCallback: undefined,
// empty cell drag and create item like excel cell selection
emptyCellDragMaxCols: 50,
// limit empty cell drag max cols
emptyCellDragMaxRows: 50,
// limit empty cell drag max rows
// Arguments: event, gridsterItem{x, y, rows: defaultItemRows, cols: defaultItemCols}
ignoreMarginInRow: false,
// ignore the gap between rows for items which span multiple rows (see #162, #224)
draggable: {
delayStart: 0,
// milliseconds to delay the start of drag, useful for touch interaction
enabled: false,
// enable/disable draggable items
ignoreContentClass: 'gridster-item-content',
// default content class to ignore the drag event from
ignoreContent: false,
// if true drag will start only from elements from `dragHandleClass`
dragHandleClass: 'drag-handler',
// drag event only from this class. If `ignoreContent` is true.
stop: undefined,
// callback when dragging an item stops. Accepts Promise return to cancel/approve drag.
start: undefined,
// callback when dragging an item starts.
// Arguments: item, gridsterItem, event
dropOverItems: false,
// enable drop items on top other item
dropOverItemsCallback: undefined // callback on drop over another item
// Arguments: source, target, gridComponent
},
resizable: {
delayStart: 0,
// milliseconds to delay the start of resize, useful for touch interaction
enabled: false,
// enable/disable resizable items
handles: {
s: true,
e: true,
n: true,
w: true,
se: true,
ne: true,
sw: true,
nw: true
},
// resizable edges of an item
stop: undefined,
// callback when resizing an item stops. Accepts Promise return to cancel/approve resize.
start: undefined // callback when resizing an item starts.
// Arguments: item, gridsterItem, event
},
swap: true,
// allow items to switch position if drop on top of another
pushItems: false,
// push items when resizing and dragging
disablePushOnDrag: false,
// disable push on drag
disablePushOnResize: false,
// disable push on resize
pushDirections: { north: true, east: true, south: true, west: true },
// control the directions items are pushed
pushResizeItems: false,
// on resize of item will shrink adjacent items
displayGrid: DisplayGrid.OnDragAndResize,
// display background grid of rows and columns
disableWindowResize: false,
// disable the window on resize listener. This will stop grid to recalculate on window resize.
disableWarnings: false,
// disable console log warnings about misplacement of grid items
scrollToNewItems: false,
// scroll to new items placed in a scrollable view
disableScrollHorizontal: false,
// disable horizontal scrolling
disableScrollVertical: false,
// disable vertical scrolling
disableAutoPositionOnConflict: false // disable auto-position of items on conflict state
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var GridsterUtils = /** @class */ (function () {
function GridsterUtils() {
}
/**
* @param {?} obj1
* @param {?} obj2
* @param {?} properties
* @return {?}
*/
GridsterUtils.merge = /**
* @param {?} obj1
* @param {?} obj2
* @param {?} properties
* @return {?}
*/
function (obj1, obj2, properties) {
for (var p in obj2) {
if (obj2[p] !== void 0 && properties.hasOwnProperty(p)) {
if (typeof obj2[p] === 'object') {
obj1[p] = GridsterUtils.merge(obj1[p], obj2[p], properties[p]);
}
else {
obj1[p] = obj2[p];
}
}
}
return obj1;
};
/**
* @param {?} func
* @param {?} wait
* @return {?}
*/
GridsterUtils.debounce = /**
* @param {?} func
* @param {?} wait
* @return {?}
*/
function (func, wait) {
/** @type {?} */
var timeout;
return (/**
* @return {?}
*/
function () {
/** @type {?} */
var context = this;
/** @type {?} */
var args = arguments;
/** @type {?} */
var later = (/**
* @return {?}
*/
function () {
timeout = null;
func.apply(context, args);
});
clearTimeout(timeout);
timeout = setTimeout(later, wait);
});
};
/**
* @param {?} e
* @return {?}
*/
GridsterUtils.checkTouchEvent = /**
* @param {?} e
* @return {?}
*/
function (e) {
if (e.clientX === undefined && e.touches) {
if (e.touches && e.touches.length) {
e.clientX = e.touches[0].clientX;
e.clientY = e.touches[0].clientY;
}
else if (e.changedTouches && e.changedTouches.length) {
e.clientX = e.changedTouches[0].clientX;
e.clientY = e.changedTouches[0].clientY;
}
}
};
/**
* @param {?} gridster
* @param {?} e
* @return {?}
*/
GridsterUtils.checkContentClassForEvent = /**
* @param {?} gridster
* @param {?} e
* @return {?}
*/
function (gridster, e) {
if (gridster.$options.draggable.ignoreContent) {
if (!GridsterUtils.checkContentClass(e.target, e.currentTarget, gridster.$options.draggable.dragHandleClass)) {
return true;
}
}
else {
if (GridsterUtils.checkContentClass(e.target, e.currentTarget, gridster.$options.draggable.ignoreContentClass)) {
return true;
}
}
return false;
};
/**
* @param {?} gridster
* @param {?} e
* @return {?}
*/
GridsterUtils.checkContentClassForEmptyCellClickEvent = /**
* @param {?} gridster
* @param {?} e
* @return {?}
*/
function (gridster, e) {
return GridsterUtils.checkContentClass(e.target, e.currentTarget, gridster.$options.draggable.ignoreContentClass)
|| GridsterUtils.checkContentClass(e.target, e.currentTarget, gridster.$options.draggable.dragHandleClass);
};
/**
* @param {?} target
* @param {?} current
* @param {?} contentClass
* @return {?}
*/
GridsterUtils.checkContentClass = /**
* @param {?} target
* @param {?} current
* @param {?} contentClass
* @return {?}
*/
function (target, current, contentClass) {
if (!target || target === current) {
return false;
}
if (target.hasAttribute('class') && target.getAttribute('class').split(' ').indexOf(contentClass) > -1) {
return true;
}
else {
return GridsterUtils.checkContentClass(target.parentNode, current, contentClass);
}
};
/**
* @param {?} a
* @param {?} b
* @return {?}
*/
GridsterUtils.compareItems = /**
* @param {?} a
* @param {?} b
* @return {?}
*/
function (a, b) {
if (a.y > b.y) {
return -1;
}
else if (a.y < b.y) {
return 1;
}
else if (a.x > b.x) {
return -1;
}
else {
return 1;
}
};
GridsterUtils.decorators = [
{ type: core.Injectable }
];
return GridsterUtils;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @abstract
*/
var /**
* @abstract
*/
GridsterComponentInterface = /** @class */ (function () {
function GridsterComponentInterface() {
}
return GridsterComponentInterface;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var GridsterEmptyCell = /** @class */ (function () {
function GridsterEmptyCell(gridster) {
this.gridster = gridster;
}
/**
* @return {?}
*/
GridsterEmptyCell.prototype.destroy = /**
* @return {?}
*/
function () {
delete this.initialItem;
delete this.gridster.movingItem;
if (this.gridster.previewStyle) {
this.gridster.previewStyle();
}
delete this.gridster;
if (this.emptyCellExit) {
this.emptyCellExit();
this.emptyCellExit = null;
}
};
/**
* @return {?}
*/
GridsterEmptyCell.prototype.updateOptions = /**
* @return {?}
*/
function () {
var _this = this;
if (this.gridster.$options.enableEmptyCellClick && !this.emptyCellClick && this.gridster.options.emptyCellClickCallback) {
this.emptyCellClick = this.gridster.renderer.listen(this.gridster.el, 'click', this.emptyCellClickCb.bind(this));
this.emptyCellClickTouch = this.gridster.renderer.listen(this.gridster.el, 'touchend', this.emptyCellClickCb.bind(this));
}
else if (!this.gridster.$options.enableEmptyCellClick && this.emptyCellClick && this.emptyCellClickTouch) {
this.emptyCellClick();
this.emptyCellClickTouch();
this.emptyCellClick = null;
this.emptyCellClickTouch = null;
}
if (this.gridster.$options.enableEmptyCellContextMenu && !this.emptyCellContextMenu &&
this.gridster.options.emptyCellContextMenuCallback) {
this.emptyCellContextMenu = this.gridster.renderer.listen(this.gridster.el, 'contextmenu', this.emptyCellContextMenuCb.bind(this));
}
else if (!this.gridster.$options.enableEmptyCellContextMenu && this.emptyCellContextMenu) {
this.emptyCellContextMenu();
this.emptyCellContextMenu = null;
}
if (this.gridster.$options.enableEmptyCellDrop && !this.emptyCellDrop && this.gridster.options.emptyCellDropCallback) {
this.emptyCellDrop = this.gridster.renderer.listen(this.gridster.el, 'drop', this.emptyCellDragDrop.bind(this));
this.gridster.zone.runOutsideAngular((/**
* @return {?}
*/
function () {
_this.emptyCellMove = _this.gridster.renderer.listen(_this.gridster.el, 'dragover', _this.emptyCellDragOver.bind(_this));
}));
this.emptyCellExit = this.gridster.renderer.listen('document', 'dragend', (/**
* @return {?}
*/
function () {
_this.gridster.movingItem = null;
_this.gridster.previewStyle();
}));
}
else if (!this.gridster.$options.enableEmptyCellDrop && this.emptyCellDrop && this.emptyCellMove && this.emptyCellExit) {
this.emptyCellDrop();
this.emptyCellMove();
this.emptyCellExit();
this.emptyCellMove = null;
this.emptyCellDrop = null;
this.emptyCellExit = null;
}
if (this.gridster.$options.enableEmptyCellDrag && !this.emptyCellDrag && this.gridster.options.emptyCellDragCallback) {
this.emptyCellDrag = this.gridster.renderer.listen(this.gridster.el, 'mousedown', this.emptyCellMouseDown.bind(this));
this.emptyCellDragTouch = this.gridster.renderer.listen(this.gridster.el, 'touchstart', this.emptyCellMouseDown.bind(this));
}
else if (!this.gridster.$options.enableEmptyCellDrag && this.emptyCellDrag && this.emptyCellDragTouch) {
this.emptyCellDrag();
this.emptyCellDragTouch();
this.emptyCellDrag = null;
this.emptyCellDragTouch = null;
}
};
/**
* @param {?} e
* @return {?}
*/
GridsterEmptyCell.prototype.emptyCellClickCb = /**
* @param {?} e
* @return {?}
*/
function (e) {
if (this.gridster.movingItem || GridsterUtils.checkContentClassForEmptyCellClickEvent(this.gridster, e)) {
return;
}
/** @type {?} */
var item = this.getValidItemFromEvent(e);
if (!item) {
return;
}
if (this.gridster.options.emptyCellClickCallback) {
this.gridster.options.emptyCellClickCallback(e, item);
}
this.gridster.cdRef.markForCheck();
};
/**
* @param {?} e
* @return {?}
*/
GridsterEmptyCell.prototype.emptyCellContextMenuCb = /**
* @param {?} e
* @return {?}
*/
function (e) {
if (this.gridster.movingItem || GridsterUtils.checkContentClassForEmptyCellClickEvent(this.gridster, e)) {
return;
}
e.preventDefault();
e.stopPropagation();
/** @type {?} */
var item = this.getValidItemFromEvent(e);
if (!item) {
return;
}
if (this.gridster.options.emptyCellContextMenuCallback) {
this.gridster.options.emptyCellContextMenuCallback(e, item);
}
this.gridster.cdRef.markForCheck();
};
/**
* @param {?} e
* @return {?}
*/
GridsterEmptyCell.prototype.emptyCellDragDrop = /**
* @param {?} e
* @return {?}
*/
function (e) {
/** @type {?} */
var item = this.getValidItemFromEvent(e);
if (!item) {
return;
}
if (this.gridster.options.emptyCellDropCallback) {
this.gridster.options.emptyCellDropCallback(e, item);
}
this.gridster.cdRef.markForCheck();
};
/**
* @param {?} e
* @return {?}
*/
GridsterEmptyCell.prototype.emptyCellDragOver = /**
* @param {?} e
* @return {?}
*/
function (e) {
e.preventDefault();
e.stopPropagation();
/** @type {?} */
var item = this.getValidItemFromEvent(e);
if (item) {
e.dataTransfer.dropEffect = 'move';
this.gridster.movingItem = item;
}
else {
e.dataTransfer.dropEffect = 'none';
this.gridster.movingItem = null;
}
this.gridster.previewStyle();
};
/**
* @param {?} e
* @return {?}
*/
GridsterEmptyCell.prototype.emptyCellMouseDown = /**
* @param {?} e
* @return {?}
*/
function (e) {
var _this = this;
if (GridsterUtils.checkContentClassForEmptyCellClickEvent(this.gridster, e)) {
return;
}
e.preventDefault();
e.stopPropagation();
/** @type {?} */
var item = this.getValidItemFromEvent(e);
/** @type {?} */
var leftMouseButtonCode = 1;
if (!item || e.buttons !== leftMouseButtonCode) {
return;
}
this.initialItem = item;
this.gridster.movingItem = item;
this.gridster.previewStyle();
this.gridster.zone.runOutsideAngular((/**
* @return {?}
*/
function () {
_this.emptyCellMMove = _this.gridster.renderer.listen('window', 'mousemove', _this.emptyCellMouseMove.bind(_this));
_this.emptyCellMMoveTouch = _this.gridster.renderer.listen('window', 'touchmove', _this.emptyCellMouseMove.bind(_this));
}));
this.emptyCellUp = this.gridster.renderer.listen('window', 'mouseup', this.emptyCellMouseUp.bind(this));
this.emptyCellUpTouch = this.gridster.renderer.listen('window', 'touchend', this.emptyCellMouseUp.bind(this));
};
/**
* @param {?} e
* @return {?}
*/
GridsterEmptyCell.prototype.emptyCellMouseMove = /**
* @param {?} e
* @return {?}
*/
function (e) {
e.preventDefault();
e.stopPropagation();
/** @type {?} */
var item = this.getValidItemFromEvent(e, this.initialItem);
if (!item) {
return;
}
this.gridster.movingItem = item;
this.gridster.previewStyle();
};
/**
* @param {?} e
* @return {?}
*/
GridsterEmptyCell.prototype.emptyCellMouseUp = /**
* @param {?} e
* @return {?}
*/
function (e) {
var _this = this;
this.emptyCellMMove();
this.emptyCellMMoveTouch();
this.emptyCellUp();
this.emptyCellUpTouch();
/** @type {?} */
var item = this.getValidItemFromEvent(e, this.initialItem);
if (item) {
this.gridster.movingItem = item;
}
if (this.gridster.options.emptyCellDragCallback && this.gridster.movingItem) {
this.gridster.options.emptyCellDragCallback(e, this.gridster.movingItem);
}
setTimeout((/**
* @return {?}
*/
function () {
_this.initialItem = null;
if (_this.gridster) {
_this.gridster.movingItem = null;
_this.gridster.previewStyle();
}
}));
this.gridster.cdRef.markForCheck();
};
/**
* @param {?} e
* @param {?=} oldItem
* @return {?}
*/
GridsterEmptyCell.prototype.getValidItemFromEvent = /**
* @param {?} e
* @param {?=} oldItem
* @return {?}
*/
function (e, oldItem) {
e.preventDefault();
e.stopPropagation();
GridsterUtils.checkTouchEvent(e);
/** @type {?} */
var rect = this.gridster.el.getBoundingClientRect();
/** @type {?} */
var x = e.clientX + this.gridster.el.scrollLeft - rect.left - this.gridster.$options.margin;
/** @type {?} */
var y = e.clientY + this.gridster.el.scrollTop - rect.top - this.gridster.$options.margin;
/** @type {?} */
var item = {
x: this.gridster.pixelsToPositionX(x, Math.floor, true),
y: this.gridster.pixelsToPositionY(y, Math.floor, true),
cols: this.gridster.$options.defaultItemCols,
rows: this.gridster.$options.defaultItemRows
};
if (oldItem) {
item.cols = Math.min(Math.abs(oldItem.x - item.x) + 1, this.gridster.$options.emptyCellDragMaxCols);
item.rows = Math.min(Math.abs(oldItem.y - item.y) + 1, this.gridster.$options.emptyCellDragMaxRows);
if (oldItem.x < item.x) {
item.x = oldItem.x;
}
else if (oldItem.x - item.x > this.gridster.$options.emptyCellDragMaxCols - 1) {
item.x = this.gridster.movingItem ? this.gridster.movingItem.x : 0;
}
if (oldItem.y < item.y) {
item.y = oldItem.y;
}
else if (oldItem.y - item.y > this.gridster.$options.emptyCellDragMaxRows - 1) {
item.y = this.gridster.movingItem ? this.gridster.movingItem.y : 0;
}
}
if (this.gridster.checkCollision(item)) {
return;
}
return item;
};
GridsterEmptyCell.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
GridsterEmptyCell.ctorParameters = function () { return [
{ type: GridsterComponentInterface }
]; };
return GridsterEmptyCell;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var GridsterCompact = /** @class */ (function () {
function GridsterCompact(gridster) {
this.gridster = gridster;
}
/**
* @return {?}
*/
GridsterCompact.prototype.destroy = /**
* @return {?}
*/
function () {
delete this.gridster;
};
/**
* @return {?}
*/
GridsterCompact.prototype.checkCompact = /**
* @return {?}
*/
function () {
if (this.gridster.$options.compactType !== CompactType.None) {
if (this.gridster.$options.compactType === CompactType.CompactUp) {
this.checkCompactUp();
}
else if (this.gridster.$options.compactType === CompactType.CompactLeft) {
this.checkCompactLeft();
}
else if (this.gridster.$options.compactType === CompactType.CompactUpAndLeft) {
this.checkCompactUp();
this.checkCompactLeft();
}
else if (this.gridster.$options.compactType === CompactType.CompactLeftAndUp) {
this.checkCompactLeft();
this.checkCompactUp();
}
else if (this.gridster.$options.compactType === CompactType.CompactRight) {
this.checkCompactRight();
}
else if (this.gridster.$options.compactType === CompactType.CompactUpAndRight) {
this.checkCompactUp();
this.checkCompactRight();
}
else if (this.gridster.$options.compactType === CompactType.CompactRightAndUp) {
this.checkCompactRight();
this.checkCompactUp();
}
}
};
/**
* @param {?} item
* @return {?}
*/
GridsterCompact.prototype.checkCompactItem = /**
* @param {?} item
* @return {?}
*/
function (item) {
if (this.gridster.$options.compactType !== CompactType.None) {
if (this.gridster.$options.compactType === CompactType.CompactUp) {
this.moveUpTillCollision(item);
}
else if (this.gridster.$options.compactType === CompactType.CompactLeft) {
this.moveLeftTillCollision(item);
}
else if (this.gridster.$options.compactType === CompactType.CompactUpAndLeft) {
this.moveUpTillCollision(item);
this.moveLeftTillCollision(item);
}
else if (this.gridster.$options.compactType === CompactType.CompactLeftAndUp) {
this.moveLeftTillCollision(item);
this.moveUpTillCollision(item);
}
else if (this.gridster.$options.compactType === CompactType.CompactUpAndRight) {
this.moveUpTillCollision(item);
this.moveRightTillCollision(item);
}
}
};
/**
* @return {?}
*/
GridsterCompact.prototype.checkCompactUp = /**
* @return {?}
*/
function () {
/** @type {?} */
var widgetMovedUp = false;
/** @type {?} */
var widget;
/** @type {?} */
var moved;
/** @type {?} */
var l = this.gridster.grid.length;
for (var i = 0; i < l; i++) {
widget = this.gridster.grid[i];
if (widget.$item.compactEnabled === false) {
continue;
}
moved = this.moveUpTillCollision(widget.$item);
if (moved) {
widgetMovedUp = true;
widget.item.y = widget.$item.y;
widget.itemChanged();
}
}
if (widgetMovedUp) {
this.checkCompact();
}
};
/**
* @param {?} item
* @return {?}
*/
GridsterCompact.prototype.moveUpTillCollision = /**
* @param {?} item
* @return {?}
*/
function (item) {
item.y -= 1;
if (this.gridster.checkCollision(item)) {
item.y += 1;
return false;
}
else {
this.moveUpTillCollision(item);
return true;
}
};
/**
* @return {?}
*/
GridsterCompact.prototype.checkCompactLeft = /**
* @return {?}
*/
function () {
/** @type {?} */
var widgetMovedUp = false;
/** @type {?} */
var widget;
/** @type {?} */
var moved;
/** @type {?} */
var l = this.gridster.grid.length;
for (var i = 0; i < l; i++) {
widget = this.gridster.grid[i];
if (widget.$item.compactEnabled === false) {
continue;
}
moved = this.moveLeftTillCollision(widget.$item);
if (moved) {
widgetMovedUp = true;
widget.item.x = widget.$item.x;
widget.itemChanged();
}
}
if (widgetMovedUp) {
this.checkCompact();
}
};
/**
* @return {?}
*/
GridsterCompact.prototype.checkCompactRight = /**
* @return {?}
*/
function () {
/** @type {?} */
var widgetMovedUp = false;
/** @type {?} */
var widget;
/** @type {?} */
var moved;
/** @type {?} */
var l = this.gridster.grid.length;
for (var i = 0; i < l; i++) {
widget = this.gridster.grid[i];
if (widget.$item.compactEnabled === false) {
continue;
}
moved = this.moveRightTillCollision(widget.$item);
if (moved) {
widgetMovedUp = true;
widget.item.x = widget.$item.x;
widget.itemChanged();
}
}
if (widgetMovedUp) {
this.checkCompact();
}
};
/**
* @param {?} item
* @return {?}
*/
GridsterCompact.prototype.moveLeftTillCollision = /**
* @param {?} item
* @return {?}
*/
function (item) {
item.x -= 1;
if (this.gridster.checkCollision(item)) {
item.x += 1;
return false;
}
else {
this.moveLeftTillCollision(item);
return true;
}
};
/**
* @param {?} item
* @return {?}
*/
GridsterCompact.prototype.moveRightTillCollision = /**
* @param {?} item
* @return {?}
*/
function (item) {
item.x += 1;
if (this.gridster.checkCollision(item)) {
item.x -= 1;
return false;
}
else {
this.moveRightTillCollision(item);
return true;
}
};
GridsterCompact.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
GridsterCompact.ctorParameters = function () { return [
{ type: GridsterComponentInterface }
]; };
return GridsterCompact;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var GridsterRenderer = /** @class */ (function () {
function GridsterRenderer(gridster) {
this.gridster = gridster;
}
/**
* @return {?}
*/
GridsterRenderer.prototype.destroy = /**
* @return {?}
*/
function () {
delete this.gridster;
};
/**
* @param {?} el
* @param {?} item
* @param {?} renderer
* @return {?}
*/
GridsterRenderer.prototype.updateItem = /**
* @param {?} el
* @param {?} item
* @param {?} renderer
* @return {?}
*/
function (el, item, renderer) {
if (this.gridster.mobile) {
this.clearCellPosition(renderer, el);
if (this.gridster.$options.keepFixedHeightInMobile) {
renderer.setStyle(el, 'height', (item.rows * this.gridster.$options.fixedRowHeight) + 'px');
}
else {
renderer.setStyle(el, 'height', (this.gridster.curWidth / 2 * item.rows) + 'px');
}
if (this.gridster.$options.keepFixedWidthInMobile) {
renderer.setStyle(el, 'width', this.gridster.$options.fixedColWidth + 'px');
}
else {
renderer.setStyle(el, 'width', '');
}
renderer.setStyle(el, 'margin-bottom', this.gridster.$options.margin + 'px');
renderer.setStyle(el, 'margin-right', '');
}
else {
/** @type {?} */
var x = Math.round(this.gridster.curColWidth * item.x);
/** @type {?} */
var y = Math.round(this.gridster.curRowHeight * item.y);
/** @type {?} */
var width = this.gridster.curColWidth * item.cols - this.gridster.$options.margin;
/** @type {?} */
var height = (this.gridster.curRowHeight * item.rows - this.gridster.$options.margin);
// set the cell style
this.setCellPosition(renderer, el, x, y);
renderer.setStyle(el, 'width', width + 'px');
renderer.setStyle(el, 'height', height + 'px');
/** @type {?} */
var marginBottom = null;
/** @type {?} */
var marginRight = null;
if (this.gridster.$options.outerMargin) {
if (this.gridster.rows === item.rows + item.y) {
if (this.gridster.$options.outerMarginBottom !== null) {
marginBottom = this.gridster.$options.outerMarginBottom + 'px';
}
else {
marginBottom = this.gridster.$options.margin + 'px';
}
}
if (this.gridster.columns === item.cols + item.x) {
if (this.gridster.$options.outerMarginBottom !== null) {
marginRight = this.gridster.$options.outerMarginRight + 'px';
}
else {
marginRight = this.gridster.$options.margin + 'px';
}
}
}
renderer.setStyle(el, 'margin-bottom', marginBottom);
renderer.setStyle(el, 'margin-right', marginRight);
}
};
/**
* @return {?}
*/
GridsterRenderer.prototype.updateGridster = /**
* @return {?}
*/
function () {
/** @type {?} */
var addClass = '';
/** @type {?} */
var removeClass1 = '';
/** @type {?} */
var removeClass2 = '';
/** @type {?} */
var removeClass3 = '';
if (this.gridster.$options.gridType === GridType.Fit) {
addClass = GridType.Fit;
removeClass1 = GridType.ScrollVertical;
removeClass2 = GridType.ScrollHorizontal;
removeClass3 = GridType.Fixed;
}
else if (this.gridster.$options.gridType === GridType.ScrollVertical) {
this.gridster.curRowHeight = this.gridster.curColWidth;
addClass = GridType.ScrollVertical;
removeClass1 = GridType.Fit;
removeClass2 = GridType.ScrollHorizontal;
removeClass3 = GridType.Fixed;
}
else if (this.gridster.$options.gridType === GridType.ScrollHorizontal) {
this.gridster.curColWidth = this.gridster.curRowHeight;
addClass = GridType.ScrollHorizontal;
removeClass1 = GridType.Fit;
removeClass2 = GridType.ScrollVertical;
removeClass3 = GridType.Fixed;
}
else if (this.gridster.$options.gridType === GridType.Fixed) {
this.gridster.curColWidth = this.gridster.$options.fixedColWidth +
(this.gridster.$options.ignoreMarginInRow ? 0 : this.gridster.$options.margin);
this.gridster.curRowHeight = this.gridster.$options.fixedRowHeight +
(this.gridster.$options.ignoreMarginInRow ? 0 : this.gridster.$options.margin);
addClass = GridType.Fixed;
removeClass1 = GridType.Fit;
removeClass2 = GridType.ScrollVertical;
removeClass3 = GridType.ScrollHorizontal;
}
else if (this.gridster.$options.gridType === GridType.VerticalFixed) {
this.gridster.curRowHeight = this.gridster.$options.fixedRowHeight +
(this.gridster.$options.ignoreMarginInRow ? 0 : this.gridster.$options.margin);
addClass = GridType.ScrollVertical;
removeClass1 = GridType.Fit;
removeClass2 = GridType.ScrollHorizontal;
removeClass3 = GridType.Fixed;
}
else if (this.gridster.$options.gridType === GridType.HorizontalFixed) {
this.gridster.curColWidth = this.gridster.$options.fixedColWidth +
(this.gridster.$options.ignoreMarginInRow ? 0 : this.gridster.$options.margin);
addClass = GridType.ScrollHorizontal;
removeClass1 = GridType.Fit;
removeClass2 = GridType.ScrollVertical;
removeClass3 = GridType.Fixed;
}
if (this.gridster.mobile) {
this.gridster.renderer.removeClass(this.gridster.el, addClass);
}
else {
this.gridster.renderer.addClass(this.gridster.el, addClass);
}
this.gridster.renderer.removeClass(this.gridster.el, removeClass1);
this.gridster.renderer.removeClass(this.gridster.el, removeClass2);
this.gridster.renderer.removeClass(this.gridster.el, removeClass3);
};
/**
* @param {?} i
* @return {?}
*/
GridsterRenderer.prototype.getGridColumnStyle = /**
* @param {?} i
* @return {?}
*/
function (i) {
return __assign({}, this.getLeftPosition(this.gridster.curColWidth * i), { width: this.gridster.curColWidth - this.gridster.$options.margin + 'px', height: this.gridster.gridRows.length * this.gridster.curRowHeight - this.gridster.$options.margin + 'px' });
};
/**
* @param {?} i
* @return {?}
*/
GridsterRenderer.prototype.getGridRowStyle = /**
* @param {?} i
* @return {?}
*/
function (i) {
return __assign({}, this.getTopPosition(this.gridster.curRowHeight * i), { width: this.gridster.gridColumns.length * this.gridster.curColWidth - this.gridster.$options.margin + 'px', height: this.gridster.curRowHeight - this.gridster.$options.margin + 'px' });
};
/**
* @param {?} d
* @return {?}
*/
GridsterRenderer.prototype.getLeftPosition = /**
* @param {?} d
* @return {?}
*/
function (d) {
if (this.gridster.$options.useTransformPositioning) {
return {
transform: 'translateX(' + d + 'px)',
};
}
else {
return {
left: (this.getLeftMargin() + d) + 'px'
};
}
};
/**
* @param {?} d
* @return {?}
*/
GridsterRenderer.prototype.getTopPosition = /**
* @param {?} d
* @return {?}
*/
function (d) {
if (this.gridster.$options.useTransformPositioning) {
return {
transform: 'translateY(' + d + 'px)',
};
}
else {
return {
top: this.getTopMargin() + d + 'px'
};
}
};
/**
* @param {?} renderer
* @param {?} el
* @return {?}
*/
GridsterRenderer.prototype.clearCellPosition = /**
* @param {?} renderer
* @param {?} el
* @return {?}
*/
function (renderer, el) {
if (this.gridster.$options.useTransformPositioning) {
renderer.setStyle(el, 'transform', '');
}
else {
renderer.setStyle(el, 'top', '');
renderer.setStyle(el, 'left', '');
}
};
/**
* @param {?} renderer
* @param {?} el
* @param {?} x
* @param {?} y
* @return {?}
*/
GridsterRenderer.prototype.setCellPosition = /**
* @param {?} renderer
* @param {?} el
* @param {?} x
* @param {?} y
* @return {?}
*/
function (renderer, el, x, y) {
if (this.gridster.$options.useTransformPositioning) {
/** @type {?} */
var transform = 'translate3d(' + x + 'px, ' + y + 'px, 0)';
renderer.setStyle(el, 'transform', transform);
}
else {
renderer.setStyle(el, 'left', this.getLeftMargin() + x + 'px');
renderer.setStyle(el, 'top', this.getTopMargin() + y + 'px');
}
};
/**
* @return {?}
*/
GridsterRenderer.prototype.getLeftMargin = /**
* @return {?}
*/
function () {
if (this.gridster.$options.outerMargin) {
if (this.gridster.$options.outerMarginLeft !== null) {
return this.gridster.$options.outerMarginLeft;
}
else {
return this.gridster.$options.margin;
}
}
else {
return 0;
}
};
/**
* @return {?}
*/
GridsterRenderer.prototype.getTopMargin = /**
* @return {?}
*/
function () {
if (this.gridster.$options.outerMargin) {
if (this.gridster.$options.outerMarginTop !== null) {
return this.gridster.$options.outerMarginTop;
}
else {
return this.gridster.$options.margin;
}
}
else {
return 0;
}
};
GridsterRenderer.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
GridsterRenderer.ctorParameters = function () { return [
{ type: GridsterComponentInterface }
]; };
return GridsterRenderer;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var GridsterComponent = /** @class */ (function () {
fun