ngx-gridster
Version:
1,205 lines (1,175 loc) • 217 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('ngx-gridster', ['exports', '@angular/core', '@angular/common'], factory) :
(global = global || self, factory(global['ngx-gridster'] = {}, 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.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
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);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {string} */
var GridType = {
Fit: 'fit',
FitToGridOptions: 'fitToGridOptions',
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',
};
/**
* @record
*/
function GridsterConfig() { }
if (false) {
/** @type {?|undefined} */
GridsterConfig.prototype.gridType;
/** @type {?|undefined} */
GridsterConfig.prototype.fixedColWidth;
/** @type {?|undefined} */
GridsterConfig.prototype.fixedRowHeight;
/** @type {?|undefined} */
GridsterConfig.prototype.keepFixedHeightInMobile;
/** @type {?|undefined} */
GridsterConfig.prototype.keepFixedWidthInMobile;
/** @type {?|undefined} */
GridsterConfig.prototype.setGridSize;
/** @type {?|undefined} */
GridsterConfig.prototype.compactType;
/** @type {?|undefined} */
GridsterConfig.prototype.mobileBreakpoint;
/** @type {?|undefined} */
GridsterConfig.prototype.minCols;
/** @type {?|undefined} */
GridsterConfig.prototype.maxCols;
/** @type {?|undefined} */
GridsterConfig.prototype.minRows;
/** @type {?|undefined} */
GridsterConfig.prototype.maxRows;
/** @type {?|undefined} */
GridsterConfig.prototype.defaultItemCols;
/** @type {?|undefined} */
GridsterConfig.prototype.defaultItemRows;
/** @type {?|undefined} */
GridsterConfig.prototype.maxItemCols;
/** @type {?|undefined} */
GridsterConfig.prototype.maxItemRows;
/** @type {?|undefined} */
GridsterConfig.prototype.minItemCols;
/** @type {?|undefined} */
GridsterConfig.prototype.minItemRows;
/** @type {?|undefined} */
GridsterConfig.prototype.minItemArea;
/** @type {?|undefined} */
GridsterConfig.prototype.maxItemArea;
/** @type {?|undefined} */
GridsterConfig.prototype.margin;
/** @type {?|undefined} */
GridsterConfig.prototype.outerMargin;
/** @type {?|undefined} */
GridsterConfig.prototype.outerMarginTop;
/** @type {?|undefined} */
GridsterConfig.prototype.outerMarginRight;
/** @type {?|undefined} */
GridsterConfig.prototype.outerMarginBottom;
/** @type {?|undefined} */
GridsterConfig.prototype.outerMarginLeft;
/** @type {?|undefined} */
GridsterConfig.prototype.useTransformPositioning;
/** @type {?|undefined} */
GridsterConfig.prototype.scrollSensitivity;
/** @type {?|undefined} */
GridsterConfig.prototype.scrollSpeed;
/** @type {?|undefined} */
GridsterConfig.prototype.initCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.destroyCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.gridSizeChangedCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.itemChangeCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.itemResizeCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.itemInitCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.itemRemovedCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.itemValidateCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.draggable;
/** @type {?|undefined} */
GridsterConfig.prototype.resizable;
/** @type {?|undefined} */
GridsterConfig.prototype.swap;
/** @type {?|undefined} */
GridsterConfig.prototype.swapWhileDragging;
/** @type {?|undefined} */
GridsterConfig.prototype.pushItems;
/** @type {?|undefined} */
GridsterConfig.prototype.disablePushOnDrag;
/** @type {?|undefined} */
GridsterConfig.prototype.disablePushOnResize;
/** @type {?|undefined} */
GridsterConfig.prototype.disableAutoPositionOnConflict;
/** @type {?|undefined} */
GridsterConfig.prototype.pushDirections;
/** @type {?|undefined} */
GridsterConfig.prototype.pushResizeItems;
/** @type {?|undefined} */
GridsterConfig.prototype.displayGrid;
/** @type {?|undefined} */
GridsterConfig.prototype.disableWindowResize;
/** @type {?|undefined} */
GridsterConfig.prototype.disableWarnings;
/** @type {?|undefined} */
GridsterConfig.prototype.scrollToNewItems;
/** @type {?|undefined} */
GridsterConfig.prototype.disableScrollHorizontal;
/** @type {?|undefined} */
GridsterConfig.prototype.disableScrollVertical;
/** @type {?|undefined} */
GridsterConfig.prototype.enableEmptyCellClick;
/** @type {?|undefined} */
GridsterConfig.prototype.enableEmptyCellContextMenu;
/** @type {?|undefined} */
GridsterConfig.prototype.enableEmptyCellDrop;
/** @type {?|undefined} */
GridsterConfig.prototype.enableEmptyCellDrag;
/** @type {?|undefined} */
GridsterConfig.prototype.enableOccupiedCellDrop;
/** @type {?|undefined} */
GridsterConfig.prototype.emptyCellClickCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.emptyCellContextMenuCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.emptyCellDropCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.emptyCellDragCallback;
/** @type {?|undefined} */
GridsterConfig.prototype.emptyCellDragMaxCols;
/** @type {?|undefined} */
GridsterConfig.prototype.emptyCellDragMaxRows;
/** @type {?|undefined} */
GridsterConfig.prototype.ignoreMarginInRow;
/** @type {?|undefined} */
GridsterConfig.prototype.api;
/* Skipping unhandled member: [propName: string]: any;*/
}
/**
* @record
*/
function DragBase() { }
if (false) {
/** @type {?|undefined} */
DragBase.prototype.enabled;
/** @type {?|undefined} */
DragBase.prototype.stop;
/** @type {?|undefined} */
DragBase.prototype.start;
/** @type {?|undefined} */
DragBase.prototype.delayStart;
}
/**
* @record
*/
function Draggable() { }
if (false) {
/** @type {?|undefined} */
Draggable.prototype.ignoreContentClass;
/** @type {?|undefined} */
Draggable.prototype.ignoreContent;
/** @type {?|undefined} */
Draggable.prototype.dragHandleClass;
/** @type {?|undefined} */
Draggable.prototype.dropOverItems;
/** @type {?|undefined} */
Draggable.prototype.dropOverItemsCallback;
}
/**
* @record
*/
function Resizable() { }
if (false) {
/** @type {?|undefined} */
Resizable.prototype.handles;
}
/**
* @record
*/
function PushDirections() { }
if (false) {
/** @type {?} */
PushDirections.prototype.north;
/** @type {?} */
PushDirections.prototype.east;
/** @type {?} */
PushDirections.prototype.south;
/** @type {?} */
PushDirections.prototype.west;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,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
enableOccupiedCellDrop: false,
// enable occupied cell drop 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
swapWhileDragging: false,
// allow items to switch position while dragging
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,constantProperty,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) {
if (!obj1 || !obj2) {
return obj1;
}
for (var p in properties) {
if (obj2[p] !== void 0) {
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,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @abstract
*/
var /**
* @abstract
*/
GridsterComponentInterface = /** @class */ (function () {
function GridsterComponentInterface() {
}
return GridsterComponentInterface;
}());
if (false) {
/** @type {?} */
GridsterComponentInterface.prototype.$options;
/** @type {?} */
GridsterComponentInterface.prototype.grid;
/** @type {?} */
GridsterComponentInterface.prototype.checkCollision;
/** @type {?} */
GridsterComponentInterface.prototype.checkCollisionForSwaping;
/** @type {?} */
GridsterComponentInterface.prototype.positionXToPixels;
/** @type {?} */
GridsterComponentInterface.prototype.pixelsToPositionX;
/** @type {?} */
GridsterComponentInterface.prototype.positionYToPixels;
/** @type {?} */
GridsterComponentInterface.prototype.pixelsToPositionY;
/** @type {?} */
GridsterComponentInterface.prototype.findItemWithItem;
/** @type {?} */
GridsterComponentInterface.prototype.findItemsWithItem;
/** @type {?} */
GridsterComponentInterface.prototype.checkGridCollision;
/** @type {?} */
GridsterComponentInterface.prototype.el;
/** @type {?} */
GridsterComponentInterface.prototype.renderer;
/** @type {?} */
GridsterComponentInterface.prototype.gridRenderer;
/** @type {?} */
GridsterComponentInterface.prototype.cdRef;
/** @type {?} */
GridsterComponentInterface.prototype.options;
/** @type {?} */
GridsterComponentInterface.prototype.calculateLayoutDebounce;
/** @type {?} */
GridsterComponentInterface.prototype.updateGrid;
/** @type {?} */
GridsterComponentInterface.prototype.movingItem;
/** @type {?} */
GridsterComponentInterface.prototype.addItem;
/** @type {?} */
GridsterComponentInterface.prototype.removeItem;
/** @type {?} */
GridsterComponentInterface.prototype.previewStyle;
/** @type {?} */
GridsterComponentInterface.prototype.mobile;
/** @type {?} */
GridsterComponentInterface.prototype.curWidth;
/** @type {?} */
GridsterComponentInterface.prototype.curHeight;
/** @type {?} */
GridsterComponentInterface.prototype.columns;
/** @type {?} */
GridsterComponentInterface.prototype.rows;
/** @type {?} */
GridsterComponentInterface.prototype.curColWidth;
/** @type {?} */
GridsterComponentInterface.prototype.curRowHeight;
/** @type {?} */
GridsterComponentInterface.prototype.windowResize;
/** @type {?} */
GridsterComponentInterface.prototype.setGridDimensions;
/** @type {?} */
GridsterComponentInterface.prototype.dragInProgress;
/** @type {?} */
GridsterComponentInterface.prototype.emptyCell;
/** @type {?} */
GridsterComponentInterface.prototype.compact;
/** @type {?} */
GridsterComponentInterface.prototype.zone;
/** @type {?} */
GridsterComponentInterface.prototype.gridRows;
/** @type {?} */
GridsterComponentInterface.prototype.gridColumns;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,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.$options.enableOccupiedCellDrop && this.gridster.checkCollision(item)) {
return;
}
return item;
};
GridsterEmptyCell.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
GridsterEmptyCell.ctorParameters = function () { return [
{ type: GridsterComponentInterface }
]; };
return GridsterEmptyCell;
}());
if (false) {
/** @type {?} */