UNPKG

4.11 kBJavaScriptView Raw
1/**
2 * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
3 * @version v18.1.2
4 * @link http://www.ag-grid.com/
5 * @license MIT
6 */
7"use strict";
8var __extends = (this && this.__extends) || (function () {
9 var extendStatics = Object.setPrototypeOf ||
10 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
12 return function (d, b) {
13 extendStatics(d, b);
14 function __() { this.constructor = d; }
15 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16 };
17})();
18Object.defineProperty(exports, "__esModule", { value: true });
19var utils_1 = require("../../utils");
20var column_1 = require("../../entities/column");
21var beanStub_1 = require("../../context/beanStub");
22var SetLeftFeature = (function (_super) {
23 __extends(SetLeftFeature, _super);
24 function SetLeftFeature(columnOrGroup, eCell, beans, colsSpanning) {
25 var _this = _super.call(this) || this;
26 _this.columnOrGroup = columnOrGroup;
27 _this.eCell = eCell;
28 _this.colsSpanning = colsSpanning;
29 _this.beans = beans;
30 return _this;
31 }
32 SetLeftFeature.prototype.setColsSpanning = function (colsSpanning) {
33 this.colsSpanning = colsSpanning;
34 this.onLeftChanged();
35 };
36 SetLeftFeature.prototype.getColumnOrGroup = function () {
37 if (this.beans.gridOptionsWrapper.isEnableRtl() && this.colsSpanning) {
38 return this.colsSpanning[this.colsSpanning.length - 1];
39 }
40 else {
41 return this.columnOrGroup;
42 }
43 };
44 SetLeftFeature.prototype.init = function () {
45 this.addDestroyableEventListener(this.columnOrGroup, column_1.Column.EVENT_LEFT_CHANGED, this.onLeftChanged.bind(this));
46 this.setLeftFirstTime();
47 };
48 SetLeftFeature.prototype.setLeftFirstTime = function () {
49 var suppressMoveAnimation = this.beans.gridOptionsWrapper.isSuppressColumnMoveAnimation();
50 var oldLeftExists = utils_1.Utils.exists(this.columnOrGroup.getOldLeft());
51 var animateColumnMove = this.beans.columnAnimationService.isActive() && oldLeftExists && !suppressMoveAnimation;
52 if (animateColumnMove) {
53 this.animateInLeft();
54 }
55 else {
56 this.onLeftChanged();
57 }
58 };
59 SetLeftFeature.prototype.animateInLeft = function () {
60 var _this = this;
61 var left = this.getColumnOrGroup().getLeft();
62 var oldLeft = this.getColumnOrGroup().getOldLeft();
63 this.setLeft(oldLeft);
64 // we must keep track of the left we want to set to, as this would otherwise lead to a race
65 // condition, if the user changed the left value many times in one VM turn, then we want to make
66 // make sure the actualLeft we set in the timeout below (in the next VM turn) is the correct left
67 // position. eg if user changes column position twice, then setLeft() below executes twice in next
68 // VM turn, but only one (the correct one) should get applied.
69 this.actualLeft = left;
70 this.beans.columnAnimationService.executeNextVMTurn(function () {
71 // test this left value is the latest one to be applied, and if not, do nothing
72 if (_this.actualLeft === left) {
73 _this.setLeft(left);
74 }
75 });
76 };
77 SetLeftFeature.prototype.onLeftChanged = function () {
78 this.actualLeft = this.getColumnOrGroup().getLeft();
79 this.setLeft(this.actualLeft);
80 };
81 SetLeftFeature.prototype.setLeft = function (value) {
82 // if the value is null, then that means the column is no longer
83 // displayed. there is logic in the rendering to fade these columns
84 // out, so we don't try and change their left positions.
85 if (utils_1.Utils.exists(value)) {
86 this.eCell.style.left = value + 'px';
87 }
88 };
89 return SetLeftFeature;
90}(beanStub_1.BeanStub));
91exports.SetLeftFeature = SetLeftFeature;