UNPKG

ngx-gridster

Version:
1,391 lines (1,384 loc) 168 kB
import { Injectable, Component, ViewEncapsulation, ElementRef, Inject, Renderer2, ChangeDetectorRef, NgZone, Input, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {string} */ const GridType = { Fit: 'fit', FitToGridOptions: 'fitToGridOptions', ScrollVertical: 'scrollVertical', ScrollHorizontal: 'scrollHorizontal', Fixed: 'fixed', VerticalFixed: 'verticalFixed', HorizontalFixed: 'horizontalFixed', }; /** @enum {string} */ const DisplayGrid = { Always: 'always', OnDragAndResize: 'onDrag&Resize', None: 'none', }; /** @enum {string} */ const 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 {?} */ const 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 */ class GridsterUtils { /** * @param {?} obj1 * @param {?} obj2 * @param {?} properties * @return {?} */ static merge(obj1, obj2, properties) { if (!obj1 || !obj2) { return obj1; } for (const 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 {?} */ static debounce(func, wait) { /** @type {?} */ let timeout; return (/** * @return {?} */ function () { /** @type {?} */ const context = this; /** @type {?} */ const args = arguments; /** @type {?} */ const later = (/** * @return {?} */ function () { timeout = null; func.apply(context, args); }); clearTimeout(timeout); timeout = setTimeout(later, wait); }); } /** * @param {?} e * @return {?} */ static checkTouchEvent(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 {?} */ static checkContentClassForEvent(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 {?} */ static checkContentClassForEmptyCellClickEvent(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 {?} */ static checkContentClass(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 {?} */ static compareItems(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: Injectable } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @abstract */ class 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 */ class GridsterEmptyCell { /** * @param {?} gridster */ constructor(gridster) { this.gridster = gridster; } /** * @return {?} */ destroy() { 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 {?} */ updateOptions() { 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 {?} */ () => { this.emptyCellMove = this.gridster.renderer.listen(this.gridster.el, 'dragover', this.emptyCellDragOver.bind(this)); })); this.emptyCellExit = this.gridster.renderer.listen('document', 'dragend', (/** * @return {?} */ () => { 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 {?} */ emptyCellClickCb(e) { if (this.gridster.movingItem || GridsterUtils.checkContentClassForEmptyCellClickEvent(this.gridster, e)) { return; } /** @type {?} */ const 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 {?} */ emptyCellContextMenuCb(e) { if (this.gridster.movingItem || GridsterUtils.checkContentClassForEmptyCellClickEvent(this.gridster, e)) { return; } e.preventDefault(); e.stopPropagation(); /** @type {?} */ const 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 {?} */ emptyCellDragDrop(e) { /** @type {?} */ const 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 {?} */ emptyCellDragOver(e) { e.preventDefault(); e.stopPropagation(); /** @type {?} */ const 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 {?} */ emptyCellMouseDown(e) { if (GridsterUtils.checkContentClassForEmptyCellClickEvent(this.gridster, e)) { return; } e.preventDefault(); e.stopPropagation(); /** @type {?} */ const item = this.getValidItemFromEvent(e); /** @type {?} */ const leftMouseButtonCode = 1; if (!item || e.buttons !== leftMouseButtonCode) { return; } this.initialItem = item; this.gridster.movingItem = item; this.gridster.previewStyle(); this.gridster.zone.runOutsideAngular((/** * @return {?} */ () => { 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 {?} */ emptyCellMouseMove(e) { e.preventDefault(); e.stopPropagation(); /** @type {?} */ const item = this.getValidItemFromEvent(e, this.initialItem); if (!item) { return; } this.gridster.movingItem = item; this.gridster.previewStyle(); } /** * @param {?} e * @return {?} */ emptyCellMouseUp(e) { this.emptyCellMMove(); this.emptyCellMMoveTouch(); this.emptyCellUp(); this.emptyCellUpTouch(); /** @type {?} */ const 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 {?} */ () => { this.initialItem = null; if (this.gridster) { this.gridster.movingItem = null; this.gridster.previewStyle(); } })); this.gridster.cdRef.markForCheck(); } /** * @param {?} e * @param {?=} oldItem * @return {?} */ getValidItemFromEvent(e, oldItem) { e.preventDefault(); e.stopPropagation(); GridsterUtils.checkTouchEvent(e); /** @type {?} */ const rect = this.gridster.el.getBoundingClientRect(); /** @type {?} */ const x = e.clientX + this.gridster.el.scrollLeft - rect.left - this.gridster.$options.margin; /** @type {?} */ const y = e.clientY + this.gridster.el.scrollTop - rect.top - this.gridster.$options.margin; /** @type {?} */ const 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: Injectable } ]; /** @nocollapse */ GridsterEmptyCell.ctorParameters = () => [ { type: GridsterComponentInterface } ]; if (false) { /** @type {?} */ GridsterEmptyCell.prototype.initialItem; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellClick; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellClickTouch; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellContextMenu; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellDrop; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellDrag; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellDragTouch; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellMMove; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellMMoveTouch; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellUp; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellUpTouch; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellMove; /** @type {?} */ GridsterEmptyCell.prototype.emptyCellExit; /** * @type {?} * @private */ GridsterEmptyCell.prototype.gridster; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class GridsterCompact { /** * @param {?} gridster */ constructor(gridster) { this.gridster = gridster; } /** * @return {?} */ destroy() { delete this.gridster; } /** * @return {?} */ checkCompact() { 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 {?} */ checkCompactItem(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 {?} */ checkCompactUp() { /** @type {?} */ let widgetMovedUp = false; /** @type {?} */ let widget; /** @type {?} */ let moved; /** @type {?} */ const l = this.gridster.grid.length; for (let 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 {?} */ moveUpTillCollision(item) { item.y -= 1; if (this.gridster.checkCollision(item)) { item.y += 1; return false; } else { this.moveUpTillCollision(item); return true; } } /** * @return {?} */ checkCompactLeft() { /** @type {?} */ let widgetMovedUp = false; /** @type {?} */ let widget; /** @type {?} */ let moved; /** @type {?} */ const l = this.gridster.grid.length; for (let 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 {?} */ checkCompactRight() { /** @type {?} */ let widgetMovedUp = false; /** @type {?} */ let widget; /** @type {?} */ let moved; /** @type {?} */ const l = this.gridster.grid.length; for (let 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 {?} */ moveLeftTillCollision(item) { item.x -= 1; if (this.gridster.checkCollision(item)) { item.x += 1; return false; } else { this.moveLeftTillCollision(item); return true; } } /** * @param {?} item * @return {?} */ moveRightTillCollision(item) { item.x += 1; if (this.gridster.checkCollision(item)) { item.x -= 1; return false; } else { this.moveRightTillCollision(item); return true; } } } GridsterCompact.decorators = [ { type: Injectable } ]; /** @nocollapse */ GridsterCompact.ctorParameters = () => [ { type: GridsterComponentInterface } ]; if (false) { /** * @type {?} * @private */ GridsterCompact.prototype.gridster; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class GridsterRenderer { /** * @param {?} gridster */ constructor(gridster) { this.gridster = gridster; } /** * @return {?} */ destroy() { delete this.gridster; } /** * @param {?} el * @param {?} item * @param {?} renderer * @return {?} */ updateItem(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', (item.rows * this.gridster.curWidth / item.cols) + '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 {?} */ const x = Math.round(this.gridster.curColWidth * item.x); /** @type {?} */ const y = Math.round(this.gridster.curRowHeight * item.y); /** @type {?} */ const width = this.gridster.curColWidth * item.cols - this.gridster.$options.margin; /** @type {?} */ const 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 {?} */ let marginBottom = null; /** @type {?} */ let 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 {?} */ updateGridster() { /** @type {?} */ let addClass = ''; /** @type {?} */ let removeClass1 = ''; /** @type {?} */ let removeClass2 = ''; /** @type {?} */ let 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.$options.gridType === GridType.FitToGridOptions) { 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 {?} */ getGridColumnStyle(i) { return Object.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 {?} */ getGridRowStyle(i) { return Object.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 {?} */ getLeftPosition(d) { if (this.gridster.$options.useTransformPositioning) { return { transform: 'translateX(' + d + 'px)', }; } else { return { left: (this.getLeftMargin() + d) + 'px' }; } } /** * @param {?} d * @return {?} */ getTopPosition(d) { if (this.gridster.$options.useTransformPositioning) { return { transform: 'translateY(' + d + 'px)', }; } else { return { top: this.getTopMargin() + d + 'px' }; } } /** * @param {?} renderer * @param {?} el * @return {?} */ clearCellPosition(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 {?} */ setCellPosition(renderer, el, x, y) { if (this.gridster.$options.useTransformPositioning) { /** @type {?} */ const transform = 'translate3d(' + x + 'px, ' + y + 'px, 0)'; renderer.setStyle(el, 'transform', transfo