UNPKG

ag-grid

Version:

Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components

92 lines (91 loc) 4.11 kB
/** * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components * @version v18.1.2 * @link http://www.ag-grid.com/ * @license MIT */ "use strict"; var __extends = (this && this.__extends) || (function () { var 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 function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var utils_1 = require("../../utils"); var column_1 = require("../../entities/column"); var beanStub_1 = require("../../context/beanStub"); var SetLeftFeature = (function (_super) { __extends(SetLeftFeature, _super); function SetLeftFeature(columnOrGroup, eCell, beans, colsSpanning) { var _this = _super.call(this) || this; _this.columnOrGroup = columnOrGroup; _this.eCell = eCell; _this.colsSpanning = colsSpanning; _this.beans = beans; return _this; } SetLeftFeature.prototype.setColsSpanning = function (colsSpanning) { this.colsSpanning = colsSpanning; this.onLeftChanged(); }; SetLeftFeature.prototype.getColumnOrGroup = function () { if (this.beans.gridOptionsWrapper.isEnableRtl() && this.colsSpanning) { return this.colsSpanning[this.colsSpanning.length - 1]; } else { return this.columnOrGroup; } }; SetLeftFeature.prototype.init = function () { this.addDestroyableEventListener(this.columnOrGroup, column_1.Column.EVENT_LEFT_CHANGED, this.onLeftChanged.bind(this)); this.setLeftFirstTime(); }; SetLeftFeature.prototype.setLeftFirstTime = function () { var suppressMoveAnimation = this.beans.gridOptionsWrapper.isSuppressColumnMoveAnimation(); var oldLeftExists = utils_1.Utils.exists(this.columnOrGroup.getOldLeft()); var animateColumnMove = this.beans.columnAnimationService.isActive() && oldLeftExists && !suppressMoveAnimation; if (animateColumnMove) { this.animateInLeft(); } else { this.onLeftChanged(); } }; SetLeftFeature.prototype.animateInLeft = function () { var _this = this; var left = this.getColumnOrGroup().getLeft(); var oldLeft = this.getColumnOrGroup().getOldLeft(); this.setLeft(oldLeft); // we must keep track of the left we want to set to, as this would otherwise lead to a race // condition, if the user changed the left value many times in one VM turn, then we want to make // make sure the actualLeft we set in the timeout below (in the next VM turn) is the correct left // position. eg if user changes column position twice, then setLeft() below executes twice in next // VM turn, but only one (the correct one) should get applied. this.actualLeft = left; this.beans.columnAnimationService.executeNextVMTurn(function () { // test this left value is the latest one to be applied, and if not, do nothing if (_this.actualLeft === left) { _this.setLeft(left); } }); }; SetLeftFeature.prototype.onLeftChanged = function () { this.actualLeft = this.getColumnOrGroup().getLeft(); this.setLeft(this.actualLeft); }; SetLeftFeature.prototype.setLeft = function (value) { // if the value is null, then that means the column is no longer // displayed. there is logic in the rendering to fade these columns // out, so we don't try and change their left positions. if (utils_1.Utils.exists(value)) { this.eCell.style.left = value + 'px'; } }; return SetLeftFeature; }(beanStub_1.BeanStub)); exports.SetLeftFeature = SetLeftFeature;