UNPKG

9.87 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})();
18var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21 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;
22 return c > 3 && r && Object.defineProperty(target, key, r), r;
23};
24var __metadata = (this && this.__metadata) || function (k, v) {
25 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
26};
27Object.defineProperty(exports, "__esModule", { value: true });
28var component_1 = require("../widgets/component");
29var context_1 = require("../context/context");
30var rowNode_1 = require("../entities/rowNode");
31var dragAndDropService_1 = require("../dragAndDrop/dragAndDropService");
32var eventKeys_1 = require("../eventKeys");
33var utils_1 = require("../utils");
34var beanStub_1 = require("../context/beanStub");
35var RowDragComp = (function (_super) {
36 __extends(RowDragComp, _super);
37 function RowDragComp(rowNode, column, cellValue, beans) {
38 var _this = _super.call(this, "<span class=\"ag-row-drag\"></span>") || this;
39 _this.rowNode = rowNode;
40 _this.column = column;
41 _this.cellValue = cellValue;
42 _this.beans = beans;
43 return _this;
44 }
45 RowDragComp.prototype.postConstruct = function () {
46 this.addDragSource();
47 this.checkCompatibility();
48 if (this.beans.gridOptionsWrapper.isRowDragManaged()) {
49 this.addFeature(this.beans.context, new ManagedVisibilityStrategy(this, this.beans, this.rowNode, this.column));
50 }
51 else {
52 this.addFeature(this.beans.context, new NonManagedVisibilityStrategy(this, this.beans, this.rowNode, this.column));
53 }
54 };
55 // returns true if all compatibility items work out
56 RowDragComp.prototype.checkCompatibility = function () {
57 var managed = this.beans.gridOptionsWrapper.isRowDragManaged();
58 var treeData = this.beans.gridOptionsWrapper.isTreeData();
59 if (treeData && managed) {
60 utils_1._.doOnce(function () {
61 return console.warn('ag-Grid: If using row drag with tree data, you cannot have rowDragManaged=true');
62 }, 'RowDragComp.managedAndTreeData');
63 }
64 };
65 RowDragComp.prototype.addDragSource = function () {
66 var _this = this;
67 var dragItem = {
68 rowNode: this.rowNode
69 };
70 var dragSource = {
71 type: dragAndDropService_1.DragSourceType.RowDrag,
72 eElement: this.getGui(),
73 dragItemName: this.cellValue,
74 dragItemCallback: function () { return dragItem; },
75 dragStartPixels: 0
76 };
77 this.beans.dragAndDropService.addDragSource(dragSource, true);
78 this.addDestroyFunc(function () { return _this.beans.dragAndDropService.removeDragSource(dragSource); });
79 };
80 __decorate([
81 context_1.PostConstruct,
82 __metadata("design:type", Function),
83 __metadata("design:paramtypes", []),
84 __metadata("design:returntype", void 0)
85 ], RowDragComp.prototype, "postConstruct", null);
86 return RowDragComp;
87}(component_1.Component));
88exports.RowDragComp = RowDragComp;
89// when non managed, the visibility depends on suppressRowDrag property only
90var NonManagedVisibilityStrategy = (function (_super) {
91 __extends(NonManagedVisibilityStrategy, _super);
92 function NonManagedVisibilityStrategy(parent, beans, rowNode, column) {
93 var _this = _super.call(this) || this;
94 _this.parent = parent;
95 _this.beans = beans;
96 _this.column = column;
97 _this.rowNode = rowNode;
98 return _this;
99 }
100 NonManagedVisibilityStrategy.prototype.postConstruct = function () {
101 this.addDestroyableEventListener(this.beans.gridOptionsWrapper, 'suppressRowDrag', this.onSuppressRowDrag.bind(this));
102 // in case data changes, then we need to update visibility of drag item
103 this.addDestroyableEventListener(this.rowNode, rowNode_1.RowNode.EVENT_DATA_CHANGED, this.workOutVisibility.bind(this));
104 this.addDestroyableEventListener(this.rowNode, rowNode_1.RowNode.EVENT_CELL_CHANGED, this.workOutVisibility.bind(this));
105 this.workOutVisibility();
106 };
107 NonManagedVisibilityStrategy.prototype.onSuppressRowDrag = function () {
108 this.workOutVisibility();
109 };
110 NonManagedVisibilityStrategy.prototype.workOutVisibility = function () {
111 // only show the drag if both sort and filter are not present
112 var suppressRowDrag = this.beans.gridOptionsWrapper.isSuppressRowDrag();
113 if (suppressRowDrag) {
114 this.parent.setVisible(false);
115 }
116 else {
117 var visible = this.column.isRowDrag(this.rowNode);
118 this.parent.setVisible(visible);
119 }
120 };
121 __decorate([
122 context_1.PostConstruct,
123 __metadata("design:type", Function),
124 __metadata("design:paramtypes", []),
125 __metadata("design:returntype", void 0)
126 ], NonManagedVisibilityStrategy.prototype, "postConstruct", null);
127 return NonManagedVisibilityStrategy;
128}(beanStub_1.BeanStub));
129// when managed, the visibility depends on sort, filter and row group, as well as suppressRowDrag property
130var ManagedVisibilityStrategy = (function (_super) {
131 __extends(ManagedVisibilityStrategy, _super);
132 function ManagedVisibilityStrategy(parent, beans, rowNode, column) {
133 var _this = _super.call(this) || this;
134 _this.parent = parent;
135 _this.beans = beans;
136 _this.column = column;
137 _this.rowNode = rowNode;
138 return _this;
139 }
140 ManagedVisibilityStrategy.prototype.postConstruct = function () {
141 // we do not show the component if sort, filter or grouping is active
142 this.addDestroyableEventListener(this.beans.eventService, eventKeys_1.Events.EVENT_SORT_CHANGED, this.onSortChanged.bind(this));
143 this.addDestroyableEventListener(this.beans.eventService, eventKeys_1.Events.EVENT_FILTER_CHANGED, this.onFilterChanged.bind(this));
144 this.addDestroyableEventListener(this.beans.eventService, eventKeys_1.Events.EVENT_COLUMN_ROW_GROUP_CHANGED, this.onRowGroupChanged.bind(this));
145 // in case data changes, then we need to update visibility of drag item
146 this.addDestroyableEventListener(this.rowNode, rowNode_1.RowNode.EVENT_DATA_CHANGED, this.workOutVisibility.bind(this));
147 this.addDestroyableEventListener(this.rowNode, rowNode_1.RowNode.EVENT_CELL_CHANGED, this.workOutVisibility.bind(this));
148 this.addDestroyableEventListener(this.beans.gridOptionsWrapper, 'suppressRowDrag', this.onSuppressRowDrag.bind(this));
149 this.updateSortActive();
150 this.updateFilterActive();
151 this.updateRowGroupActive();
152 this.workOutVisibility();
153 };
154 ManagedVisibilityStrategy.prototype.updateRowGroupActive = function () {
155 var rowGroups = this.beans.columnController.getRowGroupColumns();
156 this.rowGroupActive = !utils_1._.missingOrEmpty(rowGroups);
157 };
158 ManagedVisibilityStrategy.prototype.onRowGroupChanged = function () {
159 this.updateRowGroupActive();
160 this.workOutVisibility();
161 };
162 ManagedVisibilityStrategy.prototype.updateSortActive = function () {
163 var sortModel = this.beans.sortController.getSortModel();
164 this.sortActive = !utils_1._.missingOrEmpty(sortModel);
165 };
166 ManagedVisibilityStrategy.prototype.onSortChanged = function () {
167 this.updateSortActive();
168 this.workOutVisibility();
169 };
170 ManagedVisibilityStrategy.prototype.updateFilterActive = function () {
171 this.filterActive = this.beans.filterManager.isAnyFilterPresent();
172 };
173 ManagedVisibilityStrategy.prototype.onFilterChanged = function () {
174 this.updateFilterActive();
175 this.workOutVisibility();
176 };
177 ManagedVisibilityStrategy.prototype.onSuppressRowDrag = function () {
178 this.workOutVisibility();
179 };
180 ManagedVisibilityStrategy.prototype.workOutVisibility = function () {
181 // only show the drag if both sort and filter are not present
182 var sortOrFilterOrGroupActive = this.sortActive || this.filterActive || this.rowGroupActive;
183 var suppressRowDrag = this.beans.gridOptionsWrapper.isSuppressRowDrag();
184 var alwaysHide = sortOrFilterOrGroupActive || suppressRowDrag;
185 if (alwaysHide) {
186 this.parent.setVisible(false);
187 }
188 else {
189 var visible = this.column.isRowDrag(this.rowNode);
190 this.parent.setVisible(visible);
191 }
192 };
193 __decorate([
194 context_1.PostConstruct,
195 __metadata("design:type", Function),
196 __metadata("design:paramtypes", []),
197 __metadata("design:returntype", void 0)
198 ], ManagedVisibilityStrategy.prototype, "postConstruct", null);
199 return ManagedVisibilityStrategy;
200}(beanStub_1.BeanStub));