UNPKG

2.79 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";
8Object.defineProperty(exports, "__esModule", { value: true });
9var ChangedPath = (function () {
10 function ChangedPath(keepingColumns) {
11 this.active = true;
12 this.nodeIdsToBoolean = {};
13 this.nodeIdsToColumns = {};
14 this.keepingColumns = keepingColumns;
15 }
16 ChangedPath.prototype.setInactive = function () {
17 this.active = false;
18 };
19 ChangedPath.prototype.isActive = function () {
20 return this.active;
21 };
22 ChangedPath.prototype.addParentNode = function (rowNode, columns) {
23 var _this = this;
24 this.validateActive();
25 var pointer = rowNode;
26 while (pointer) {
27 // add this item to the path, all the way to parent
28 this.nodeIdsToBoolean[pointer.id] = true;
29 // if columns, add the columns in all the way to parent, merging
30 // in any other columns that might be there already
31 if (this.keepingColumns && columns) {
32 if (!this.nodeIdsToColumns[pointer.id]) {
33 this.nodeIdsToColumns[pointer.id] = {};
34 }
35 columns.forEach(function (col) { return _this.nodeIdsToColumns[pointer.id][col.getId()] = true; });
36 }
37 pointer = pointer.parent;
38 }
39 };
40 ChangedPath.prototype.isInPath = function (rowNode) {
41 this.validateActive();
42 return this.nodeIdsToBoolean[rowNode.id];
43 };
44 ChangedPath.prototype.getValueColumnsForNode = function (rowNode, valueColumns) {
45 this.validateActive();
46 if (!this.keepingColumns) {
47 return valueColumns;
48 }
49 var colsForThisNode = this.nodeIdsToColumns[rowNode.id];
50 var result = valueColumns.filter(function (col) { return colsForThisNode[col.getId()]; });
51 return result;
52 };
53 ChangedPath.prototype.getNotValueColumnsForNode = function (rowNode, valueColumns) {
54 this.validateActive();
55 if (!this.keepingColumns) {
56 return null;
57 }
58 var colsForThisNode = this.nodeIdsToColumns[rowNode.id];
59 var result = valueColumns.filter(function (col) { return !colsForThisNode[col.getId()]; });
60 return result;
61 };
62 // this is to check for a bug in our code. each part that uses ChangePath should check
63 // if it is valid first, and not use it if it is not valid
64 ChangedPath.prototype.validateActive = function () {
65 if (!this.active) {
66 throw "ag-Grid: tried to work on an invalid changed path";
67 }
68 };
69 return ChangedPath;
70}());
71exports.ChangedPath = ChangedPath;