{"version":3,"file":"7079.js","sources":["webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/aggregationStage.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/groupStage.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/pivotColDefService.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/pivotStage.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/aggFuncService.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/columnDropZones/dropZoneColumnComp.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/columnDropZones/baseDropZonePanel.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/columnDropZones/rowGroupDropZonePanel.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/columnDropZones/pivotDropZonePanel.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/columnDropZones/gridHeaderDropZones.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/filterAggregatesStage.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/columnDropZones/valueDropZonePanel.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGrouping/batchRemover.js","webpack://frontend/./node_modules/@ag-grid-enterprise/row-grouping/dist/esm/es5/rowGroupingModule.js"],"sourcesContent":["var __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n 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;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nimport { Bean, BeanStub, Autowired, _ } from \"@ag-grid-community/core\";\nvar AggregationStage = /** @class */ (function (_super) {\n __extends(AggregationStage, _super);\n function AggregationStage() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n // it's possible to recompute the aggregate without doing the other parts\n // + gridApi.recomputeAggregates()\n AggregationStage.prototype.execute = function (params) {\n // if changed path is active, it means we came from a) change detection or b) transaction update.\n // for both of these, if no value columns are present, it means there is nothing to aggregate now\n // and there is no cleanup to be done (as value columns don't change between transactions or change\n // detections). if no value columns and no changed path, means we have to go through all nodes in\n // case we need to clean up agg data from before.\n var noValueColumns = _.missingOrEmpty(this.columnModel.getValueColumns());\n var noUserAgg = !this.gridOptionsWrapper.getGroupRowAggFunc();\n var changedPathActive = params.changedPath && params.changedPath.isActive();\n if (noValueColumns && noUserAgg && changedPathActive) {\n return;\n }\n var aggDetails = this.createAggDetails(params);\n this.recursivelyCreateAggData(aggDetails);\n };\n AggregationStage.prototype.createAggDetails = function (params) {\n var pivotActive = this.columnModel.isPivotActive();\n var measureColumns = this.columnModel.getValueColumns();\n var pivotColumns = pivotActive ? this.columnModel.getPivotColumns() : [];\n var aggDetails = {\n changedPath: params.changedPath,\n valueColumns: measureColumns,\n pivotColumns: pivotColumns\n };\n return aggDetails;\n };\n AggregationStage.prototype.recursivelyCreateAggData = function (aggDetails) {\n var _this = this;\n // update prop, in case changed since last time\n this.filteredOnly = !this.gridOptionsWrapper.isSuppressAggFilteredOnly();\n var callback = function (rowNode) {\n var hasNoChildren = !rowNode.hasChildren();\n if (hasNoChildren) {\n // this check is needed for TreeData, in case the node is no longer a child,\n // but it was a child previously.\n if (rowNode.aggData) {\n rowNode.setAggData(null);\n }\n // never agg data for leaf nodes\n return;\n }\n //Optionally prevent the aggregation at the root Node\n //https://ag-grid.atlassian.net/browse/AG-388\n var isRootNode = rowNode.level === -1;\n if (isRootNode) {\n var notPivoting = !_this.columnModel.isPivotMode();\n var suppressAggAtRootLevel = _this.gridOptionsWrapper.isSuppressAggAtRootLevel();\n if (suppressAggAtRootLevel && notPivoting) {\n return;\n }\n }\n _this.aggregateRowNode(rowNode, aggDetails);\n };\n aggDetails.changedPath.forEachChangedNodeDepthFirst(callback, true);\n };\n AggregationStage.prototype.aggregateRowNode = function (rowNode, aggDetails) {\n var measureColumnsMissing = aggDetails.valueColumns.length === 0;\n var pivotColumnsMissing = aggDetails.pivotColumns.length === 0;\n var userFunc = this.gridOptionsWrapper.getGroupRowAggFunc();\n var aggResult;\n if (userFunc) {\n var params = { nodes: rowNode.childrenAfterFilter };\n aggResult = userFunc(params);\n }\n else if (measureColumnsMissing) {\n aggResult = null;\n }\n else if (pivotColumnsMissing) {\n aggResult = this.aggregateRowNodeUsingValuesOnly(rowNode, aggDetails);\n }\n else {\n aggResult = this.aggregateRowNodeUsingValuesAndPivot(rowNode);\n }\n rowNode.setAggData(aggResult);\n // if we are grouping, then it's possible there is a sibling footer\n // to the group, so update the data here also if there is one\n if (rowNode.sibling) {\n rowNode.sibling.setAggData(aggResult);\n }\n };\n AggregationStage.prototype.aggregateRowNodeUsingValuesAndPivot = function (rowNode) {\n var _this = this;\n var result = {};\n var pivotColumnDefs = this.pivotStage.getPivotColumnDefs();\n // Step 1: process value columns\n pivotColumnDefs\n .filter(function (v) { return !_.exists(v.pivotTotalColumnIds); }) // only process pivot value columns\n .forEach(function (valueColDef) {\n var keys = valueColDef.pivotKeys || [];\n var values;\n var valueColumn = valueColDef.pivotValueColumn;\n var colId = valueColDef.colId;\n if (rowNode.leafGroup) {\n // lowest level group, get the values from the mapped set\n values = _this.getValuesFromMappedSet(rowNode.childrenMapped, keys, valueColumn);\n }\n else {\n // value columns and pivot columns, non-leaf group\n values = _this.getValuesPivotNonLeaf(rowNode, colId);\n }\n result[colId] = _this.aggregateValues(values, valueColumn.getAggFunc(), valueColumn, rowNode);\n });\n // Step 2: process total columns\n pivotColumnDefs\n .filter(function (v) { return _.exists(v.pivotTotalColumnIds); }) // only process pivot total columns\n .forEach(function (totalColDef) {\n var aggResults = [];\n var pivotValueColumn = totalColDef.pivotValueColumn, pivotTotalColumnIds = totalColDef.pivotTotalColumnIds, colId = totalColDef.colId;\n //retrieve results for colIds associated with this pivot total column\n if (!pivotTotalColumnIds || !pivotTotalColumnIds.length) {\n return;\n }\n pivotTotalColumnIds.forEach(function (currentColId) {\n aggResults.push(result[currentColId]);\n });\n result[colId] = _this.aggregateValues(aggResults, pivotValueColumn.getAggFunc(), pivotValueColumn, rowNode);\n });\n return result;\n };\n AggregationStage.prototype.aggregateRowNodeUsingValuesOnly = function (rowNode, aggDetails) {\n var _this = this;\n var result = {};\n var changedValueColumns = aggDetails.changedPath.isActive() ?\n aggDetails.changedPath.getValueColumnsForNode(rowNode, aggDetails.valueColumns)\n : aggDetails.valueColumns;\n var notChangedValueColumns = aggDetails.changedPath.isActive() ?\n aggDetails.changedPath.getNotValueColumnsForNode(rowNode, aggDetails.valueColumns)\n : null;\n var values2d = this.getValuesNormal(rowNode, changedValueColumns);\n var oldValues = rowNode.aggData;\n changedValueColumns.forEach(function (valueColumn, index) {\n result[valueColumn.getId()] = _this.aggregateValues(values2d[index], valueColumn.getAggFunc(), valueColumn, rowNode);\n });\n if (notChangedValueColumns && oldValues) {\n notChangedValueColumns.forEach(function (valueColumn) {\n result[valueColumn.getId()] = oldValues[valueColumn.getId()];\n });\n }\n return result;\n };\n AggregationStage.prototype.getValuesPivotNonLeaf = function (rowNode, colId) {\n var values = [];\n rowNode.childrenAfterFilter.forEach(function (node) {\n var value = node.aggData[colId];\n values.push(value);\n });\n return values;\n };\n AggregationStage.prototype.getValuesFromMappedSet = function (mappedSet, keys, valueColumn) {\n var _this = this;\n var mapPointer = mappedSet;\n keys.forEach(function (key) { return (mapPointer = mapPointer ? mapPointer[key] : null); });\n if (!mapPointer) {\n return [];\n }\n var values = [];\n mapPointer.forEach(function (rowNode) {\n var value = _this.valueService.getValue(valueColumn, rowNode);\n values.push(value);\n });\n return values;\n };\n AggregationStage.prototype.getValuesNormal = function (rowNode, valueColumns) {\n // create 2d array, of all values for all valueColumns\n var values = [];\n valueColumns.forEach(function () { return values.push([]); });\n var valueColumnCount = valueColumns.length;\n var nodeList = this.filteredOnly ? rowNode.childrenAfterFilter : rowNode.childrenAfterGroup;\n var rowCount = nodeList.length;\n for (var i = 0; i < rowCount; i++) {\n var childNode = nodeList[i];\n for (var j = 0; j < valueColumnCount; j++) {\n var valueColumn = valueColumns[j];\n // if the row is a group, then it will only have an agg result value,\n // which means valueGetter is never used.\n var value = this.valueService.getValue(valueColumn, childNode);\n values[j].push(value);\n }\n }\n return values;\n };\n AggregationStage.prototype.aggregateValues = function (values, aggFuncOrString, column, rowNode) {\n var aggFunc = typeof aggFuncOrString === 'string' ?\n this.aggFuncService.getAggFunc(aggFuncOrString) :\n aggFuncOrString;\n if (typeof aggFunc !== 'function') {\n console.error(\"AG Grid: unrecognised aggregation function \" + aggFuncOrString);\n return null;\n }\n var deprecationWarning = function () {\n _.doOnce(function () {\n console.warn('AG Grid: since v24.0, custom aggregation functions take a params object. Please alter your aggregation function to use params.values');\n }, 'aggregationStage.aggregateValues Deprecation');\n };\n var aggFuncAny = aggFunc;\n var params = {\n values: values,\n column: column,\n colDef: column ? column.getColDef() : undefined,\n rowNode: rowNode,\n data: rowNode ? rowNode.data : undefined,\n api: this.gridApi,\n columnApi: this.columnApi,\n context: this.gridOptionsWrapper.getContext(),\n }; // the \"as any\" is needed to allow the deprecation warning messages\n return aggFuncAny(params);\n };\n __decorate([\n Autowired('columnModel')\n ], AggregationStage.prototype, \"columnModel\", void 0);\n __decorate([\n Autowired('valueService')\n ], AggregationStage.prototype, \"valueService\", void 0);\n __decorate([\n Autowired('pivotStage')\n ], AggregationStage.prototype, \"pivotStage\", void 0);\n __decorate([\n Autowired('aggFuncService')\n ], AggregationStage.prototype, \"aggFuncService\", void 0);\n __decorate([\n Autowired('gridApi')\n ], AggregationStage.prototype, \"gridApi\", void 0);\n __decorate([\n Autowired('columnApi')\n ], AggregationStage.prototype, \"columnApi\", void 0);\n AggregationStage = __decorate([\n Bean('aggregationStage')\n ], AggregationStage);\n return AggregationStage;\n}(BeanStub));\nexport { AggregationStage };\n","var __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n 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;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __read = (this && this.__read) || function (o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n};\nvar __spread = (this && this.__spread) || function () {\n for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));\n return ar;\n};\nimport { _, Autowired, Bean, BeanStub, NumberSequence, PostConstruct, RowNode } from \"@ag-grid-community/core\";\nimport { BatchRemover } from \"./batchRemover\";\nvar GroupStage = /** @class */ (function (_super) {\n __extends(GroupStage, _super);\n function GroupStage() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n // we use a sequence variable so that each time we do a grouping, we don't\n // reuse the ids - otherwise the rowRenderer will confuse rowNodes between redraws\n // when it tries to animate between rows.\n _this.groupIdSequence = new NumberSequence();\n return _this;\n }\n GroupStage.prototype.postConstruct = function () {\n this.usingTreeData = this.gridOptionsWrapper.isTreeData();\n if (this.usingTreeData) {\n this.getDataPath = this.gridOptionsWrapper.getDataPathFunc();\n }\n };\n GroupStage.prototype.execute = function (params) {\n var details = this.createGroupingDetails(params);\n if (details.transactions) {\n this.handleTransaction(details);\n }\n else {\n var afterColsChanged = params.afterColumnsChanged === true;\n this.shotgunResetEverything(details, afterColsChanged);\n }\n this.positionLeafsAboveGroups(params.changedPath);\n this.orderGroups(details.rootNode);\n this.selectableService.updateSelectableAfterGrouping(details.rootNode);\n };\n GroupStage.prototype.positionLeafsAboveGroups = function (changedPath) {\n // we don't do group sorting for tree data\n if (this.usingTreeData) {\n return;\n }\n changedPath.forEachChangedNodeDepthFirst(function (group) {\n if (group.childrenAfterGroup) {\n var leafNodes_1 = [];\n var groupNodes_1 = [];\n group.childrenAfterGroup.forEach(function (row) {\n var _a;\n if (!((_a = row.childrenAfterGroup) === null || _a === void 0 ? void 0 : _a.length)) {\n leafNodes_1.push(row);\n }\n else {\n groupNodes_1.push(row);\n }\n });\n group.childrenAfterGroup = __spread(leafNodes_1, groupNodes_1);\n }\n }, false);\n };\n GroupStage.prototype.createGroupingDetails = function (params) {\n var rowNode = params.rowNode, changedPath = params.changedPath, rowNodeTransactions = params.rowNodeTransactions, rowNodeOrder = params.rowNodeOrder;\n var groupedCols = this.usingTreeData ? null : this.columnModel.getRowGroupColumns();\n var details = {\n // someone complained that the parent attribute was causing some change detection\n // to break is some angular add-on - which i never used. taking the parent out breaks\n // a cyclic dependency, hence this flag got introduced.\n includeParents: !this.gridOptionsWrapper.isSuppressParentsInRowNodes(),\n expandByDefault: this.gridOptionsWrapper.getGroupDefaultExpanded(),\n groupedCols: groupedCols,\n rootNode: rowNode,\n pivotMode: this.columnModel.isPivotMode(),\n groupedColCount: this.usingTreeData || !groupedCols ? 0 : groupedCols.length,\n rowNodeOrder: rowNodeOrder,\n transactions: rowNodeTransactions,\n // if no transaction, then it's shotgun, changed path would be 'not active' at this point anyway\n changedPath: changedPath\n };\n return details;\n };\n GroupStage.prototype.handleTransaction = function (details) {\n var _this = this;\n details.transactions.forEach(function (tran) {\n // we don't allow batch remover for tree data as tree data uses Filler Nodes,\n // and creating/deleting filler nodes needs to be done alongside the node deleting\n // and moving. if we want to Batch Remover working with tree data then would need\n // to consider how Filler Nodes would be impacted (it's possible that it can be easily\n // modified to work, however for now I don't have the brain energy to work it all out).\n var batchRemover = !_this.usingTreeData ? new BatchRemover() : undefined;\n // the order here of [add, remove, update] needs to be the same as in ClientSideNodeManager,\n // as the order is important when a record with the same id is added and removed in the same\n // transaction.\n if (_.existsAndNotEmpty(tran.remove)) {\n _this.removeNodes(tran.remove, details, batchRemover);\n }\n if (_.existsAndNotEmpty(tran.update)) {\n _this.moveNodesInWrongPath(tran.update, details, batchRemover);\n }\n if (_.existsAndNotEmpty(tran.add)) {\n _this.insertNodes(tran.add, details, false);\n }\n // must flush here, and not allow another transaction to be applied,\n // as each transaction must finish leaving the data in a consistent state.\n if (batchRemover) {\n var parentsWithChildrenRemoved = batchRemover.getAllParents().slice();\n batchRemover.flush();\n _this.removeEmptyGroups(parentsWithChildrenRemoved, details);\n }\n });\n if (details.rowNodeOrder) {\n this.sortChildren(details);\n }\n };\n // this is used when doing delta updates, eg Redux, keeps nodes in right order\n GroupStage.prototype.sortChildren = function (details) {\n details.changedPath.forEachChangedNodeDepthFirst(function (node) {\n if (!node.childrenAfterGroup) {\n return;\n }\n var didSort = _.sortRowNodesByOrder(node.childrenAfterGroup, details.rowNodeOrder);\n if (didSort) {\n details.changedPath.addParentNode(node);\n }\n }, false, true);\n };\n GroupStage.prototype.orderGroups = function (rootNode) {\n // we don't do group sorting for tree data\n if (this.usingTreeData) {\n return;\n }\n var comparator = this.gridOptionsWrapper.getInitialGroupOrderComparator();\n if (_.exists(comparator)) {\n recursiveSort(rootNode);\n }\n function recursiveSort(rowNode) {\n var doSort = _.exists(rowNode.childrenAfterGroup) &&\n // we only want to sort groups, so we do not sort leafs (a leaf group has leafs as children)\n !rowNode.leafGroup;\n if (doSort) {\n rowNode.childrenAfterGroup.sort(function (nodeA, nodeB) { return comparator({ nodeA: nodeA, nodeB: nodeB }); });\n rowNode.childrenAfterGroup.forEach(function (childNode) { return recursiveSort(childNode); });\n }\n }\n };\n GroupStage.prototype.getExistingPathForNode = function (node, details) {\n var res = [];\n // when doing tree data, the node is part of the path,\n // but when doing grid grouping, the node is not part of the path so we start with the parent.\n var pointer = this.usingTreeData ? node : node.parent;\n while (pointer && pointer !== details.rootNode) {\n res.push({\n key: pointer.key,\n rowGroupColumn: pointer.rowGroupColumn,\n field: pointer.field\n });\n pointer = pointer.parent;\n }\n res.reverse();\n return res;\n };\n GroupStage.prototype.moveNodesInWrongPath = function (childNodes, details, batchRemover) {\n var _this = this;\n childNodes.forEach(function (childNode) {\n // we add node, even if parent has not changed, as the data could have\n // changed, hence aggregations will be wrong\n if (details.changedPath.isActive()) {\n details.changedPath.addParentNode(childNode.parent);\n }\n var infoToKeyMapper = function (item) { return item.key; };\n var oldPath = _this.getExistingPathForNode(childNode, details).map(infoToKeyMapper);\n var newPath = _this.getGroupInfo(childNode, details).map(infoToKeyMapper);\n var nodeInCorrectPath = _.areEqual(oldPath, newPath);\n if (!nodeInCorrectPath) {\n _this.moveNode(childNode, details, batchRemover);\n }\n });\n };\n GroupStage.prototype.moveNode = function (childNode, details, batchRemover) {\n this.removeNodesInStages([childNode], details, batchRemover);\n this.insertOneNode(childNode, details, true);\n // hack - if we didn't do this, then renaming a tree item (ie changing rowNode.key) wouldn't get\n // refreshed into the gui.\n // this is needed to kick off the event that rowComp listens to for refresh. this in turn\n // then will get each cell in the row to refresh - which is what we need as we don't know which\n // columns will be displaying the rowNode.key info.\n childNode.setData(childNode.data);\n // we add both old and new parents to changed path, as both will need to be refreshed.\n // we already added the old parent (in calling method), so just add the new parent here\n if (details.changedPath.isActive()) {\n var newParent = childNode.parent;\n details.changedPath.addParentNode(newParent);\n }\n };\n GroupStage.prototype.removeNodes = function (leafRowNodes, details, batchRemover) {\n this.removeNodesInStages(leafRowNodes, details, batchRemover);\n if (details.changedPath.isActive()) {\n leafRowNodes.forEach(function (rowNode) { return details.changedPath.addParentNode(rowNode.parent); });\n }\n };\n GroupStage.prototype.removeNodesInStages = function (leafRowNodes, details, batchRemover) {\n this.removeNodesFromParents(leafRowNodes, details, batchRemover);\n if (this.usingTreeData) {\n this.postRemoveCreateFillerNodes(leafRowNodes, details);\n // When not TreeData, then removeEmptyGroups is called just before the BatchRemover is flushed.\n // However for TreeData, there is no BatchRemover, so we have to call removeEmptyGroups here.\n var nodeParents = leafRowNodes.map(function (n) { return n.parent; });\n this.removeEmptyGroups(nodeParents, details);\n }\n };\n GroupStage.prototype.forEachParentGroup = function (details, group, callback) {\n var pointer = group;\n while (pointer && pointer !== details.rootNode) {\n callback(pointer);\n pointer = pointer.parent;\n }\n };\n GroupStage.prototype.removeNodesFromParents = function (nodesToRemove, details, provided) {\n var _this = this;\n // this method can be called with BatchRemover as optional. if it is missed, we created a local version\n // and flush it at the end. if one is provided, we add to the provided one and it gets flushed elsewhere.\n var batchRemoverIsLocal = provided == null;\n var batchRemoverToUse = provided ? provided : new BatchRemover();\n nodesToRemove.forEach(function (nodeToRemove) {\n _this.removeFromParent(nodeToRemove, batchRemoverToUse);\n // remove from allLeafChildren. we clear down all parents EXCEPT the Root Node, as\n // the ClientSideNodeManager is responsible for the Root Node.\n _this.forEachParentGroup(details, nodeToRemove.parent, function (parentNode) {\n batchRemoverToUse.removeFromAllLeafChildren(parentNode, nodeToRemove);\n });\n });\n if (batchRemoverIsLocal) {\n batchRemoverToUse.flush();\n }\n };\n GroupStage.prototype.postRemoveCreateFillerNodes = function (nodesToRemove, details) {\n var _this = this;\n nodesToRemove.forEach(function (nodeToRemove) {\n // if not group, and children are present, need to move children to a group.\n // otherwise if no children, we can just remove without replacing.\n var replaceWithGroup = nodeToRemove.hasChildren();\n if (replaceWithGroup) {\n var oldPath = _this.getExistingPathForNode(nodeToRemove, details);\n // because we just removed the userGroup, this will always return new support group\n var newGroupNode_1 = _this.findParentForNode(nodeToRemove, oldPath, details);\n // these properties are the ones that will be incorrect in the newly created group,\n // so copy them from the old childNode\n newGroupNode_1.expanded = nodeToRemove.expanded;\n newGroupNode_1.allLeafChildren = nodeToRemove.allLeafChildren;\n newGroupNode_1.childrenAfterGroup = nodeToRemove.childrenAfterGroup;\n newGroupNode_1.childrenMapped = nodeToRemove.childrenMapped;\n newGroupNode_1.updateHasChildren();\n newGroupNode_1.childrenAfterGroup.forEach(function (rowNode) { return rowNode.parent = newGroupNode_1; });\n }\n });\n };\n GroupStage.prototype.removeEmptyGroups = function (possibleEmptyGroups, details) {\n var _this = this;\n // we do this multiple times, as when we remove groups, that means the parent of just removed\n // group can then be empty. to get around this, if we remove, then we check everything again for\n // newly emptied groups. the max number of times this will execute is the depth of the group tree.\n var checkAgain = true;\n var groupShouldBeRemoved = function (rowNode) {\n // because of the while loop below, it's possible we already moved the node,\n // so double check before trying to remove again.\n var mapKey = _this.getChildrenMappedKey(rowNode.key, rowNode.rowGroupColumn);\n var parentRowNode = rowNode.parent;\n var groupAlreadyRemoved = (parentRowNode && parentRowNode.childrenMapped) ?\n !parentRowNode.childrenMapped[mapKey] : true;\n if (groupAlreadyRemoved) {\n // if not linked, then group was already removed\n return false;\n }\n // if still not removed, then we remove if this group is empty\n return !!rowNode.isEmptyRowGroupNode();\n };\n var _loop_1 = function () {\n checkAgain = false;\n var batchRemover = new BatchRemover();\n possibleEmptyGroups.forEach(function (possibleEmptyGroup) {\n // remove empty groups\n _this.forEachParentGroup(details, possibleEmptyGroup, function (rowNode) {\n if (groupShouldBeRemoved(rowNode)) {\n checkAgain = true;\n _this.removeFromParent(rowNode, batchRemover);\n // we remove selection on filler nodes here, as the selection would not be removed\n // from the RowNodeManager, as filler nodes don't exist on the RowNodeManager\n rowNode.setSelected(false);\n }\n });\n });\n batchRemover.flush();\n };\n while (checkAgain) {\n _loop_1();\n }\n };\n // removes the node from the parent by:\n // a) removing from childrenAfterGroup (using batchRemover if present, otherwise immediately)\n // b) removing from childrenMapped (immediately)\n // c) setRowTop(null) - as the rowRenderer uses this to know the RowNode is no longer needed\n // d) setRowIndex(null) - as the rowNode will no longer be displayed.\n GroupStage.prototype.removeFromParent = function (child, batchRemover) {\n if (child.parent) {\n if (batchRemover) {\n batchRemover.removeFromChildrenAfterGroup(child.parent, child);\n }\n else {\n _.removeFromArray(child.parent.childrenAfterGroup, child);\n child.parent.updateHasChildren();\n }\n }\n var mapKey = this.getChildrenMappedKey(child.key, child.rowGroupColumn);\n if (child.parent && child.parent.childrenMapped) {\n child.parent.childrenMapped[mapKey] = undefined;\n }\n // this is important for transition, see rowComp removeFirstPassFuncs. when doing animation and\n // remove, if rowTop is still present, the rowComp thinks it's just moved position.\n child.setRowTop(null);\n child.setRowIndex(null);\n };\n GroupStage.prototype.addToParent = function (child, parent) {\n var mapKey = this.getChildrenMappedKey(child.key, child.rowGroupColumn);\n if (parent) {\n var children = parent.childrenMapped != null;\n if (children) {\n parent.childrenMapped[mapKey] = child;\n }\n parent.childrenAfterGroup.push(child);\n parent.updateHasChildren();\n }\n };\n GroupStage.prototype.areGroupColsEqual = function (d1, d2) {\n if (d1 == null || d2 == null || d1.pivotMode !== d2.pivotMode) {\n return false;\n }\n return _.areEqual(d1.groupedCols, d2.groupedCols);\n };\n GroupStage.prototype.checkAllGroupDataAfterColsChanged = function (details) {\n var _this = this;\n var recurse = function (rowNodes) {\n if (!rowNodes) {\n return;\n }\n rowNodes.forEach(function (rowNode) {\n var isLeafNode = !_this.usingTreeData && !rowNode.group;\n if (isLeafNode) {\n return;\n }\n var groupInfo = {\n field: rowNode.field,\n key: rowNode.key,\n rowGroupColumn: rowNode.rowGroupColumn\n };\n _this.setGroupData(rowNode, groupInfo);\n recurse(rowNode.childrenAfterGroup);\n });\n };\n recurse(details.rootNode.childrenAfterGroup);\n };\n GroupStage.prototype.shotgunResetEverything = function (details, afterColumnsChanged) {\n if (this.noChangeInGroupingColumns(details, afterColumnsChanged)) {\n return;\n }\n // groups are about to get disposed, so need to deselect any that are selected\n this.selectionService.removeGroupsFromSelection();\n var rootNode = details.rootNode, groupedCols = details.groupedCols;\n // because we are not creating the root node each time, we have the logic\n // here to change leafGroup once.\n // we set .leafGroup to false for tree data, as .leafGroup is only used when pivoting, and pivoting\n // isn't allowed with treeData, so the grid never actually use .leafGroup when doing treeData.\n rootNode.leafGroup = this.usingTreeData ? false : groupedCols.length === 0;\n // we are doing everything from scratch, so reset childrenAfterGroup and childrenMapped from the rootNode\n rootNode.childrenAfterGroup = [];\n rootNode.childrenMapped = {};\n rootNode.updateHasChildren();\n var sibling = rootNode.sibling;\n if (sibling) {\n sibling.childrenAfterGroup = rootNode.childrenAfterGroup;\n sibling.childrenMapped = rootNode.childrenMapped;\n }\n this.insertNodes(rootNode.allLeafChildren, details, false);\n };\n GroupStage.prototype.noChangeInGroupingColumns = function (details, afterColumnsChanged) {\n var noFurtherProcessingNeeded = false;\n var groupDisplayColumns = this.columnModel.getGroupDisplayColumns();\n var newGroupDisplayColIds = groupDisplayColumns ?\n groupDisplayColumns.map(function (c) { return c.getId(); }).join('-') : '';\n if (afterColumnsChanged) {\n // we only need to redo grouping if doing normal grouping (ie not tree data)\n // and the group cols have changed.\n noFurtherProcessingNeeded = this.usingTreeData || this.areGroupColsEqual(details, this.oldGroupingDetails);\n // if the group display cols have changed, then we need to update rowNode.groupData\n // (regardless of tree data or row grouping)\n if (this.oldGroupDisplayColIds !== newGroupDisplayColIds) {\n this.checkAllGroupDataAfterColsChanged(details);\n }\n }\n this.oldGroupingDetails = details;\n this.oldGroupDisplayColIds = newGroupDisplayColIds;\n return noFurtherProcessingNeeded;\n };\n GroupStage.prototype.insertNodes = function (newRowNodes, details, isMove) {\n var _this = this;\n newRowNodes.forEach(function (rowNode) {\n _this.insertOneNode(rowNode, details, isMove);\n if (details.changedPath.isActive()) {\n details.changedPath.addParentNode(rowNode.parent);\n }\n });\n };\n GroupStage.prototype.insertOneNode = function (childNode, details, isMove) {\n var path = this.getGroupInfo(childNode, details);\n var parentGroup = this.findParentForNode(childNode, path, details);\n if (!parentGroup.group) {\n console.warn(\"AG Grid: duplicate group keys for row data, keys should be unique\", [parentGroup.data, childNode.data]);\n }\n if (this.usingTreeData) {\n this.swapGroupWithUserNode(parentGroup, childNode, isMove);\n }\n else {\n childNode.parent = parentGroup;\n childNode.level = path.length;\n parentGroup.childrenAfterGroup.push(childNode);\n parentGroup.updateHasChildren();\n }\n };\n GroupStage.prototype.findParentForNode = function (childNode, path, details) {\n var _this = this;\n var nextNode = details.rootNode;\n path.forEach(function (groupInfo, level) {\n nextNode = _this.getOrCreateNextNode(nextNode, groupInfo, level, details);\n // node gets added to all group nodes.\n // note: we do not add to rootNode here, as the rootNode is the master list of rowNodes\n nextNode.allLeafChildren.push(childNode);\n });\n return nextNode;\n };\n GroupStage.prototype.swapGroupWithUserNode = function (fillerGroup, userGroup, isMove) {\n userGroup.parent = fillerGroup.parent;\n userGroup.key = fillerGroup.key;\n userGroup.field = fillerGroup.field;\n userGroup.groupData = fillerGroup.groupData;\n userGroup.level = fillerGroup.level;\n // AG-3441 - preserve the existing expanded status of the node if we're moving it, so that\n // you can drag a sub tree from one parent to another without changing its expansion\n if (!isMove) {\n userGroup.expanded = fillerGroup.expanded;\n }\n // we set .leafGroup to false for tree data, as .leafGroup is only used when pivoting, and pivoting\n // isn't allowed with treeData, so the grid never actually use .leafGroup when doing treeData.\n userGroup.leafGroup = fillerGroup.leafGroup;\n // always null for userGroups, as row grouping is not allowed when doing tree data\n userGroup.rowGroupIndex = fillerGroup.rowGroupIndex;\n userGroup.allLeafChildren = fillerGroup.allLeafChildren;\n userGroup.childrenAfterGroup = fillerGroup.childrenAfterGroup;\n userGroup.childrenMapped = fillerGroup.childrenMapped;\n userGroup.updateHasChildren();\n this.removeFromParent(fillerGroup);\n userGroup.childrenAfterGroup.forEach(function (rowNode) { return rowNode.parent = userGroup; });\n this.addToParent(userGroup, fillerGroup.parent);\n };\n GroupStage.prototype.getOrCreateNextNode = function (parentGroup, groupInfo, level, details) {\n var key = this.getChildrenMappedKey(groupInfo.key, groupInfo.rowGroupColumn);\n var nextNode = parentGroup.childrenMapped ? parentGroup.childrenMapped[key] : undefined;\n if (!nextNode) {\n nextNode = this.createGroup(groupInfo, parentGroup, level, details);\n // attach the new group to the parent\n this.addToParent(nextNode, parentGroup);\n }\n return nextNode;\n };\n GroupStage.prototype.createGroup = function (groupInfo, parent, level, details) {\n var groupNode = new RowNode(this.beans);\n groupNode.group = true;\n groupNode.field = groupInfo.field;\n groupNode.rowGroupColumn = groupInfo.rowGroupColumn;\n this.setGroupData(groupNode, groupInfo);\n // we put 'row-group-' before the group id, so it doesn't clash with standard row id's. we also use 't-' and 'b-'\n // for top pinned and bottom pinned rows.\n groupNode.id = RowNode.ID_PREFIX_ROW_GROUP + this.groupIdSequence.next();\n groupNode.key = groupInfo.key;\n groupNode.level = level;\n groupNode.leafGroup = this.usingTreeData ? false : level === (details.groupedColCount - 1);\n groupNode.allLeafChildren = [];\n // why is this done here? we are not updating the children count as we go,\n // i suspect this is updated in the filter stage\n groupNode.setAllChildrenCount(0);\n groupNode.rowGroupIndex = this.usingTreeData ? null : level;\n groupNode.childrenAfterGroup = [];\n groupNode.childrenMapped = {};\n groupNode.updateHasChildren();\n groupNode.parent = details.includeParents ? parent : null;\n this.setExpandedInitialValue(details, groupNode);\n return groupNode;\n };\n GroupStage.prototype.setGroupData = function (groupNode, groupInfo) {\n var _this = this;\n groupNode.groupData = {};\n var groupDisplayCols = this.columnModel.getGroupDisplayColumns();\n groupDisplayCols.forEach(function (col) {\n // newGroup.rowGroupColumn=null when working off GroupInfo, and we always display the group in the group column\n // if rowGroupColumn is present, then it's grid row grouping and we only include if configuration says so\n var displayGroupForCol = _this.usingTreeData || (groupNode.rowGroupColumn ? col.isRowGroupDisplayed(groupNode.rowGroupColumn.getId()) : false);\n if (displayGroupForCol) {\n groupNode.groupData[col.getColId()] = groupInfo.key;\n }\n });\n };\n GroupStage.prototype.getChildrenMappedKey = function (key, rowGroupColumn) {\n if (rowGroupColumn) {\n // grouping by columns\n return rowGroupColumn.getId() + '-' + key;\n }\n // tree data - we don't have rowGroupColumns\n return key;\n };\n GroupStage.prototype.setExpandedInitialValue = function (details, groupNode) {\n // if pivoting the leaf group is never expanded as we do not show leaf rows\n if (details.pivotMode && groupNode.leafGroup) {\n groupNode.expanded = false;\n return;\n }\n // use callback if exists\n var userCallback = this.gridOptionsWrapper.getIsGroupOpenByDefaultFunc();\n if (userCallback) {\n var params = {\n rowNode: groupNode,\n field: groupNode.field,\n key: groupNode.key,\n level: groupNode.level,\n rowGroupColumn: groupNode.rowGroupColumn\n };\n groupNode.expanded = userCallback(params) == true;\n return;\n }\n // use expandByDefault if exists\n var expandByDefault = details.expandByDefault;\n if (details.expandByDefault === -1) {\n groupNode.expanded = true;\n return;\n }\n // otherwise\n groupNode.expanded = groupNode.level < expandByDefault;\n };\n GroupStage.prototype.getGroupInfo = function (rowNode, details) {\n if (this.usingTreeData) {\n return this.getGroupInfoFromCallback(rowNode);\n }\n return this.getGroupInfoFromGroupColumns(rowNode, details);\n };\n GroupStage.prototype.getGroupInfoFromCallback = function (rowNode) {\n var keys = this.getDataPath ? this.getDataPath(rowNode.data) : null;\n if (keys === null || keys === undefined || keys.length === 0) {\n _.doOnce(function () { return console.warn(\"AG Grid: getDataPath() should not return an empty path for data\", rowNode.data); }, 'groupStage.getGroupInfoFromCallback');\n }\n var groupInfoMapper = function (key) { return ({ key: key, field: null, rowGroupColumn: null }); };\n return keys ? keys.map(groupInfoMapper) : [];\n };\n GroupStage.prototype.getGroupInfoFromGroupColumns = function (rowNode, details) {\n var _this = this;\n var res = [];\n details.groupedCols.forEach(function (groupCol) {\n var key = _this.valueService.getKeyForNode(groupCol, rowNode);\n var keyExists = key !== null && key !== undefined;\n // unbalanced tree and pivot mode don't work together - not because of the grid, it doesn't make\n // mathematical sense as you are building up a cube. so if pivot mode, we put in a blank key where missing.\n // this keeps the tree balanced and hence can be represented as a group.\n if (details.pivotMode && !keyExists) {\n key = ' ';\n keyExists = true;\n }\n if (keyExists) {\n var item = {\n key: key,\n field: groupCol.getColDef().field,\n rowGroupColumn: groupCol\n };\n res.push(item);\n }\n });\n return res;\n };\n __decorate([\n Autowired('columnModel')\n ], GroupStage.prototype, \"columnModel\", void 0);\n __decorate([\n Autowired('selectableService')\n ], GroupStage.prototype, \"selectableService\", void 0);\n __decorate([\n Autowired('valueService')\n ], GroupStage.prototype, \"valueService\", void 0);\n __decorate([\n Autowired('beans')\n ], GroupStage.prototype, \"beans\", void 0);\n __decorate([\n Autowired('selectionService')\n ], GroupStage.prototype, \"selectionService\", void 0);\n __decorate([\n PostConstruct\n ], GroupStage.prototype, \"postConstruct\", null);\n GroupStage = __decorate([\n Bean('groupStage')\n ], GroupStage);\n return GroupStage;\n}(BeanStub));\nexport { GroupStage };\n","var __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n 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;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __read = (this && this.__read) || function (o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n};\nvar __spread = (this && this.__spread) || function () {\n for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));\n return ar;\n};\nimport { Autowired, Bean, BeanStub, _ } from \"@ag-grid-community/core\";\nvar PivotColDefService = /** @class */ (function (_super) {\n __extends(PivotColDefService, _super);\n function PivotColDefService() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n PivotColDefService_1 = PivotColDefService;\n PivotColDefService.prototype.createPivotColumnDefs = function (uniqueValues) {\n // this is passed to the columnModel, to configure the columns and groups we show\n var pivotColumns = this.columnModel.getPivotColumns();\n var valueColumns = this.columnModel.getValueColumns();\n var levelsDeep = pivotColumns.length;\n var pivotColumnGroupDefs = this.recursiveBuildGroup(0, uniqueValues, [], levelsDeep, pivotColumns);\n function extractColDefs(input, arr) {\n if (arr === void 0) { arr = []; }\n input.forEach(function (def) {\n if (def.children !== undefined) {\n extractColDefs(def.children, arr);\n }\n else {\n arr.push(def);\n }\n });\n return arr;\n }\n var pivotColumnDefs = extractColDefs(pivotColumnGroupDefs);\n // additional columns that contain the aggregated total for each value column per row\n this.addRowGroupTotals(pivotColumnGroupDefs, pivotColumnDefs, valueColumns);\n // additional group columns that contain child totals for each collapsed child column / group\n this.addExpandablePivotGroups(pivotColumnGroupDefs, pivotColumnDefs);\n // additional group columns that contain an aggregated total across all child columns\n this.addPivotTotalsToGroups(pivotColumnGroupDefs, pivotColumnDefs);\n // we clone, so the colDefs in pivotColumnsGroupDefs and pivotColumnDefs are not shared. this is so that\n // any changes the user makes (via processSecondaryColumnDefinitions) don't impact the internal aggregations,\n // as these use the col defs also\n var pivotColumnDefsClone = pivotColumnDefs.map(function (colDef) { return _.cloneObject(colDef); });\n return {\n pivotColumnGroupDefs: pivotColumnGroupDefs,\n pivotColumnDefs: pivotColumnDefsClone\n };\n };\n PivotColDefService.prototype.recursiveBuildGroup = function (index, uniqueValue, pivotKeys, maxDepth, primaryPivotColumns) {\n var _this = this;\n var measureColumns = this.columnModel.getValueColumns();\n if (index >= maxDepth) { // Base case - build the measure columns\n return this.buildMeasureCols(pivotKeys);\n }\n // sort by either user provided comparator, or our own one\n var primaryPivotColumnDefs = primaryPivotColumns[index].getColDef();\n var comparator = this.headerNameComparator.bind(this, primaryPivotColumnDefs.pivotComparator);\n // Base case for the compact layout, instead of recursing build the last layer of groups as measure columns instead\n if (measureColumns.length === 1 && this.gridOptionsWrapper.isRemovePivotHeaderRowWhenSingleValueColumn() && index === maxDepth - 1) {\n var leafCols_1 = [];\n _.iterateObject(uniqueValue, function (key) {\n var newPivotKeys = __spread(pivotKeys, [key]);\n leafCols_1.push(__assign(__assign({}, _this.createColDef(measureColumns[0], key, newPivotKeys)), { columnGroupShow: 'open' }));\n });\n leafCols_1.sort(comparator);\n return leafCols_1;\n }\n // Recursive case\n var groups = [];\n _.iterateObject(uniqueValue, function (key, value) {\n var newPivotKeys = __spread(pivotKeys, [key]);\n groups.push({\n children: _this.recursiveBuildGroup(index + 1, value, newPivotKeys, maxDepth, primaryPivotColumns),\n headerName: key,\n pivotKeys: newPivotKeys,\n columnGroupShow: 'open',\n groupId: _this.generateColumnGroupId(newPivotKeys),\n });\n });\n groups.sort(comparator);\n return groups;\n };\n PivotColDefService.prototype.buildMeasureCols = function (pivotKeys) {\n var _this = this;\n var measureColumns = this.columnModel.getValueColumns();\n if (measureColumns.length === 0) {\n // if no value columns selected, then we insert one blank column, so the user at least sees columns\n // rendered. otherwise the grid would render with no columns (just empty groups) which would give the\n // impression that the grid is broken\n return [this.createColDef(null, '-', pivotKeys)];\n }\n return measureColumns.map(function (measureCol) {\n var columnName = _this.columnModel.getDisplayNameForColumn(measureCol, 'header');\n return __assign(__assign({}, _this.createColDef(measureCol, columnName, pivotKeys)), { columnGroupShow: 'open' });\n });\n };\n ;\n PivotColDefService.prototype.addExpandablePivotGroups = function (pivotColumnGroupDefs, pivotColumnDefs) {\n var _this = this;\n if (this.gridOptionsWrapper.isSuppressExpandablePivotGroups() ||\n this.gridOptionsWrapper.getPivotColumnGroupTotals()) {\n return;\n }\n var recursivelyAddSubTotals = function (groupDef, currentPivotColumnDefs, acc) {\n var group = groupDef;\n if (group.children) {\n var childAcc_1 = new Map();\n group.children.forEach(function (grp) {\n recursivelyAddSubTotals(grp, currentPivotColumnDefs, childAcc_1);\n });\n var firstGroup_1 = !group.children.some(function (child) { return child.children; });\n _this.columnModel.getValueColumns().forEach(function (valueColumn) {\n var columnName = _this.columnModel.getDisplayNameForColumn(valueColumn, 'header');\n var totalColDef = _this.createColDef(valueColumn, columnName, groupDef.pivotKeys);\n totalColDef.pivotTotalColumnIds = childAcc_1.get(valueColumn.getColId());\n totalColDef.columnGroupShow = 'closed';\n totalColDef.aggFunc = valueColumn.getAggFunc();\n if (!firstGroup_1) {\n // add total colDef to group and pivot colDefs array\n var children = groupDef.children;\n children.push(totalColDef);\n currentPivotColumnDefs.push(totalColDef);\n }\n });\n _this.merge(acc, childAcc_1);\n }\n else {\n var def = groupDef;\n // check that value column exists, i.e. aggFunc is supplied\n if (!def.pivotValueColumn) {\n return;\n }\n var pivotValueColId = def.pivotValueColumn.getColId();\n var arr = acc.has(pivotValueColId) ? acc.get(pivotValueColId) : [];\n arr.push(def.colId);\n acc.set(pivotValueColId, arr);\n }\n };\n pivotColumnGroupDefs.forEach(function (groupDef) {\n recursivelyAddSubTotals(groupDef, pivotColumnDefs, new Map());\n });\n };\n PivotColDefService.prototype.addPivotTotalsToGroups = function (pivotColumnGroupDefs, pivotColumnDefs) {\n var _this = this;\n if (!this.gridOptionsWrapper.getPivotColumnGroupTotals()) {\n return;\n }\n var insertAfter = this.gridOptionsWrapper.getPivotColumnGroupTotals() === 'after';\n var valueCols = this.columnModel.getValueColumns();\n var aggFuncs = valueCols.map(function (valueCol) { return valueCol.getAggFunc(); });\n // don't add pivot totals if there is less than 1 aggFunc or they are not all the same\n if (!aggFuncs || aggFuncs.length < 1 || !this.sameAggFuncs(aggFuncs)) {\n // console.warn('AG Grid: aborting adding pivot total columns - value columns require same aggFunc');\n return;\n }\n // arbitrarily select a value column to use as a template for pivot columns\n var valueColumn = valueCols[0];\n pivotColumnGroupDefs.forEach(function (groupDef) {\n _this.recursivelyAddPivotTotal(groupDef, pivotColumnDefs, valueColumn, insertAfter);\n });\n };\n PivotColDefService.prototype.recursivelyAddPivotTotal = function (groupDef, pivotColumnDefs, valueColumn, insertAfter) {\n var _this = this;\n var group = groupDef;\n if (!group.children) {\n var def = groupDef;\n return def.colId ? [def.colId] : null;\n }\n var colIds = [];\n // need to recurse children first to obtain colIds used in the aggregation stage\n group.children\n .forEach(function (grp) {\n var childColIds = _this.recursivelyAddPivotTotal(grp, pivotColumnDefs, valueColumn, insertAfter);\n if (childColIds) {\n colIds = colIds.concat(childColIds);\n }\n });\n // only add total colDef if there is more than 1 child node\n if (group.children.length > 1) {\n var localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc();\n var headerName = localeTextFunc('pivotColumnGroupTotals', 'Total');\n //create total colDef using an arbitrary value column as a template\n var totalColDef = this.createColDef(valueColumn, headerName, groupDef.pivotKeys, true);\n totalColDef.pivotTotalColumnIds = colIds;\n totalColDef.aggFunc = valueColumn.getAggFunc();\n // add total colDef to group and pivot colDefs array\n var children = groupDef.children;\n insertAfter ? children.push(totalColDef) : children.unshift(totalColDef);\n pivotColumnDefs.push(totalColDef);\n }\n return colIds;\n };\n PivotColDefService.prototype.addRowGroupTotals = function (pivotColumnGroupDefs, pivotColumnDefs, valueColumns) {\n var _this = this;\n if (!this.gridOptionsWrapper.getPivotRowTotals()) {\n return;\n }\n var insertAfter = this.gridOptionsWrapper.getPivotRowTotals() === 'after';\n // order of row group totals depends on position\n var valueCols = insertAfter ? valueColumns.slice() : valueColumns.slice().reverse();\n var _loop_1 = function (i) {\n var valueCol = valueCols[i];\n var colIds = [];\n pivotColumnGroupDefs.forEach(function (groupDef) {\n colIds = colIds.concat(_this.extractColIdsForValueColumn(groupDef, valueCol));\n });\n var withGroup = valueCols.length > 1 || !this_1.gridOptionsWrapper.isRemovePivotHeaderRowWhenSingleValueColumn();\n this_1.createRowGroupTotal(pivotColumnGroupDefs, pivotColumnDefs, valueCol, colIds, insertAfter, withGroup);\n };\n var this_1 = this;\n for (var i = 0; i < valueCols.length; i++) {\n _loop_1(i);\n }\n };\n PivotColDefService.prototype.extractColIdsForValueColumn = function (groupDef, valueColumn) {\n var _this = this;\n var group = groupDef;\n if (!group.children) {\n var colDef = group;\n return colDef.pivotValueColumn === valueColumn && colDef.colId ? [colDef.colId] : [];\n }\n var colIds = [];\n group.children\n .forEach(function (grp) {\n _this.extractColIdsForValueColumn(grp, valueColumn);\n var childColIds = _this.extractColIdsForValueColumn(grp, valueColumn);\n colIds = colIds.concat(childColIds);\n });\n return colIds;\n };\n PivotColDefService.prototype.createRowGroupTotal = function (parentChildren, pivotColumnDefs, valueColumn, colIds, insertAfter, addGroup) {\n var measureColumns = this.columnModel.getValueColumns();\n var colDef;\n if (measureColumns.length === 0) {\n colDef = this.createColDef(null, '-', []);\n }\n else {\n var columnName = this.columnModel.getDisplayNameForColumn(valueColumn, 'header');\n colDef = this.createColDef(valueColumn, columnName, []);\n colDef.pivotTotalColumnIds = colIds;\n }\n colDef.colId = PivotColDefService_1.PIVOT_ROW_TOTAL_PREFIX + colDef.colId;\n pivotColumnDefs.push(colDef);\n var valueGroup = addGroup ? {\n children: [colDef],\n pivotKeys: [],\n groupId: PivotColDefService_1.PIVOT_ROW_TOTAL_PREFIX + \"_pivotGroup_\" + valueColumn.getColId(),\n } : colDef;\n insertAfter ? parentChildren.push(valueGroup) : parentChildren.unshift(valueGroup);\n };\n PivotColDefService.prototype.createColDef = function (valueColumn, headerName, pivotKeys, totalColumn) {\n if (totalColumn === void 0) { totalColumn = false; }\n var colDef = {};\n // This is null when there are no measure columns and we're creating placeholder columns\n if (valueColumn) {\n var colDefToCopy = valueColumn.getColDef();\n Object.assign(colDef, colDefToCopy);\n // even if original column was hidden, we always show the pivot value column, otherwise it would be\n // very confusing for people thinking the pivot is broken\n colDef.hide = false;\n }\n colDef.headerName = headerName;\n colDef.colId = this.generateColumnId(pivotKeys || [], valueColumn && !totalColumn ? valueColumn.getColId() : '');\n // pivot columns repeat over field, so it makes sense to use the unique id instead. For example if you want to\n // assign values to pinned bottom rows using setPinnedBottomRowData the value service will use this colId.\n colDef.field = colDef.colId;\n // this is to support using pinned rows, normally the data will be extracted from the aggData object using the colId\n // however pinned rows still access the data object by field, this prevents values with dots from being treated as complex objects\n colDef.valueGetter = function (params) { var _a; return (_a = params.data) === null || _a === void 0 ? void 0 : _a[params.colDef.field]; };\n colDef.pivotKeys = pivotKeys;\n colDef.pivotValueColumn = valueColumn;\n if (colDef.filter === true) {\n colDef.filter = 'agNumberColumnFilter';\n }\n return colDef;\n };\n PivotColDefService.prototype.sameAggFuncs = function (aggFuncs) {\n if (aggFuncs.length == 1) {\n return true;\n }\n //check if all aggFunc's match\n for (var i = 1; i < aggFuncs.length; i++) {\n if (aggFuncs[i] !== aggFuncs[0]) {\n return false;\n }\n }\n return true;\n };\n PivotColDefService.prototype.headerNameComparator = function (userComparator, a, b) {\n if (userComparator) {\n return userComparator(a.headerName, b.headerName);\n }\n else {\n if (a.headerName && !b.headerName) {\n return 1;\n }\n else if (!a.headerName && b.headerName) {\n return -1;\n }\n // slightly naff here - just to satify typescript\n // really should be &&, but if so ts complains\n // the above if/else checks would deal with either being falsy, so at this stage if either are falsy, both are\n // ..still naff though\n if (!a.headerName || !b.headerName) {\n return 0;\n }\n if (a.headerName < b.headerName) {\n return -1;\n }\n if (a.headerName > b.headerName) {\n return 1;\n }\n return 0;\n }\n };\n PivotColDefService.prototype.merge = function (m1, m2) {\n m2.forEach(function (value, key, map) {\n var existingList = m1.has(key) ? m1.get(key) : [];\n var updatedList = __spread(existingList, value);\n m1.set(key, updatedList);\n });\n };\n PivotColDefService.prototype.generateColumnGroupId = function (pivotKeys) {\n var pivotCols = this.columnModel.getPivotColumns().map(function (col) { return col.getColId(); });\n return \"pivotGroup_\" + pivotCols.join('-') + \"_\" + pivotKeys.join('-');\n };\n PivotColDefService.prototype.generateColumnId = function (pivotKeys, measureColumnId) {\n var pivotCols = this.columnModel.getPivotColumns().map(function (col) { return col.getColId(); });\n return \"pivot_\" + pivotCols.join('-') + \"_\" + pivotKeys.join('-') + \"_\" + measureColumnId;\n };\n var PivotColDefService_1;\n PivotColDefService.PIVOT_ROW_TOTAL_PREFIX = 'PivotRowTotal_';\n __decorate([\n Autowired('columnModel')\n ], PivotColDefService.prototype, \"columnModel\", void 0);\n PivotColDefService = PivotColDefService_1 = __decorate([\n Bean('pivotColDefService')\n ], PivotColDefService);\n return PivotColDefService;\n}(BeanStub));\nexport { PivotColDefService };\n","var __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n 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;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nimport { Autowired, Bean, BeanStub, _ } from \"@ag-grid-community/core\";\nvar PivotStage = /** @class */ (function (_super) {\n __extends(PivotStage, _super);\n function PivotStage() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.uniqueValues = {};\n return _this;\n }\n PivotStage.prototype.execute = function (params) {\n var rootNode = params.rowNode;\n var changedPath = params.changedPath;\n if (this.columnModel.isPivotActive()) {\n this.executePivotOn(rootNode, changedPath);\n }\n else {\n this.executePivotOff(changedPath);\n }\n };\n PivotStage.prototype.executePivotOff = function (changedPath) {\n this.aggregationColumnsHashLastTime = null;\n this.uniqueValues = {};\n if (this.columnModel.isSecondaryColumnsPresent()) {\n this.columnModel.setSecondaryColumns(null, \"rowModelUpdated\");\n if (changedPath) {\n changedPath.setInactive();\n }\n }\n };\n PivotStage.prototype.executePivotOn = function (rootNode, changedPath) {\n var uniqueValues = this.bucketUpRowNodes(rootNode);\n var uniqueValuesChanged = this.setUniqueValues(uniqueValues);\n var aggregationColumns = this.columnModel.getValueColumns();\n var aggregationColumnsHash = aggregationColumns.map(function (column) { return column.getId() + \"-\" + column.getColDef().headerName; }).join('#');\n var aggregationFuncsHash = aggregationColumns.map(function (column) { return column.getAggFunc().toString(); }).join('#');\n var aggregationColumnsChanged = this.aggregationColumnsHashLastTime !== aggregationColumnsHash;\n var aggregationFuncsChanged = this.aggregationFuncsHashLastTime !== aggregationFuncsHash;\n this.aggregationColumnsHashLastTime = aggregationColumnsHash;\n this.aggregationFuncsHashLastTime = aggregationFuncsHash;\n var groupColumnsHash = this.columnModel.getRowGroupColumns().map(function (column) { return column.getId(); }).join('#');\n var groupColumnsChanged = groupColumnsHash !== this.groupColumnsHashLastTime;\n this.groupColumnsHashLastTime = groupColumnsHash;\n if (uniqueValuesChanged || aggregationColumnsChanged || groupColumnsChanged || aggregationFuncsChanged) {\n var _a = this.pivotColDefService.createPivotColumnDefs(this.uniqueValues), pivotColumnGroupDefs = _a.pivotColumnGroupDefs, pivotColumnDefs = _a.pivotColumnDefs;\n this.pivotColumnDefs = pivotColumnDefs;\n this.columnModel.setSecondaryColumns(pivotColumnGroupDefs, \"rowModelUpdated\");\n // because the secondary columns have changed, then the aggregation needs to visit the whole\n // tree again, so we make the changedPath not active, to force aggregation to visit all paths.\n if (changedPath) {\n changedPath.setInactive();\n }\n }\n };\n PivotStage.prototype.setUniqueValues = function (newValues) {\n var json1 = JSON.stringify(newValues);\n var json2 = JSON.stringify(this.uniqueValues);\n var uniqueValuesChanged = json1 !== json2;\n // we only continue the below if the unique values are different, as otherwise\n // the result will be the same as the last time we did it\n if (uniqueValuesChanged) {\n this.uniqueValues = newValues;\n return true;\n }\n else {\n return false;\n }\n };\n // returns true if values were different\n PivotStage.prototype.bucketUpRowNodes = function (rootNode) {\n var _this = this;\n // accessed from inside inner function\n var uniqueValues = {};\n // finds all leaf groups and calls mapRowNode with it\n var recursivelySearchForLeafNodes = function (rowNode) {\n if (rowNode.leafGroup) {\n _this.bucketRowNode(rowNode, uniqueValues);\n }\n else {\n rowNode.childrenAfterFilter.forEach(function (child) {\n recursivelySearchForLeafNodes(child);\n });\n }\n };\n recursivelySearchForLeafNodes(rootNode);\n return uniqueValues;\n };\n PivotStage.prototype.bucketRowNode = function (rowNode, uniqueValues) {\n var pivotColumns = this.columnModel.getPivotColumns();\n if (pivotColumns.length === 0) {\n rowNode.childrenMapped = null;\n }\n else {\n rowNode.childrenMapped = this.bucketChildren(rowNode.childrenAfterFilter, pivotColumns, 0, uniqueValues);\n }\n if (rowNode.sibling) {\n rowNode.sibling.childrenMapped = rowNode.childrenMapped;\n }\n };\n PivotStage.prototype.bucketChildren = function (children, pivotColumns, pivotIndex, uniqueValues) {\n var _this = this;\n var mappedChildren = {};\n var pivotColumn = pivotColumns[pivotIndex];\n // map the children out based on the pivot column\n children.forEach(function (child) {\n var key = _this.valueService.getKeyForNode(pivotColumn, child);\n if (_.missing(key)) {\n key = '';\n }\n if (!uniqueValues[key]) {\n uniqueValues[key] = {};\n }\n if (!mappedChildren[key]) {\n mappedChildren[key] = [];\n }\n mappedChildren[key].push(child);\n });\n // if it's the last pivot column, return as is, otherwise go one level further in the map\n if (pivotIndex === pivotColumns.length - 1) {\n return mappedChildren;\n }\n else {\n var result_1 = {};\n _.iterateObject(mappedChildren, function (key, value) {\n result_1[key] = _this.bucketChildren(value, pivotColumns, pivotIndex + 1, uniqueValues[key]);\n });\n return result_1;\n }\n };\n PivotStage.prototype.getPivotColumnDefs = function () {\n return this.pivotColumnDefs;\n };\n __decorate([\n Autowired('valueService')\n ], PivotStage.prototype, \"valueService\", void 0);\n __decorate([\n Autowired('columnModel')\n ], PivotStage.prototype, \"columnModel\", void 0);\n __decorate([\n Autowired('pivotColDefService')\n ], PivotStage.prototype, \"pivotColDefService\", void 0);\n PivotStage = __decorate([\n Bean('pivotStage')\n ], PivotStage);\n return PivotStage;\n}(BeanStub));\nexport { PivotStage };\n","var __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n 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;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nimport { Bean, BeanStub, PostConstruct, _ } from '@ag-grid-community/core';\n// @ts-ignore\nvar AGBigInt = typeof BigInt === 'undefined' ? null : BigInt;\nvar AggFuncService = /** @class */ (function (_super) {\n __extends(AggFuncService, _super);\n function AggFuncService() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.aggFuncsMap = {};\n _this.initialised = false;\n return _this;\n }\n AggFuncService_1 = AggFuncService;\n AggFuncService.prototype.init = function () {\n if (this.initialised) {\n return;\n }\n this.initialiseWithDefaultAggregations();\n this.addAggFuncs(this.gridOptionsWrapper.getAggFuncs());\n };\n AggFuncService.prototype.initialiseWithDefaultAggregations = function () {\n this.aggFuncsMap[AggFuncService_1.AGG_SUM] = aggSum;\n this.aggFuncsMap[AggFuncService_1.AGG_FIRST] = aggFirst;\n this.aggFuncsMap[AggFuncService_1.AGG_LAST] = aggLast;\n this.aggFuncsMap[AggFuncService_1.AGG_MIN] = aggMin;\n this.aggFuncsMap[AggFuncService_1.AGG_MAX] = aggMax;\n this.aggFuncsMap[AggFuncService_1.AGG_COUNT] = aggCount;\n this.aggFuncsMap[AggFuncService_1.AGG_AVG] = aggAvg;\n this.initialised = true;\n };\n AggFuncService.prototype.isAggFuncPossible = function (column, func) {\n var allKeys = this.getFuncNames(column);\n var allowed = _.includes(allKeys, func);\n var funcExists = _.exists(this.aggFuncsMap[func]);\n return allowed && funcExists;\n };\n AggFuncService.prototype.getDefaultAggFunc = function (column) {\n var defaultAgg = column.getColDef().defaultAggFunc;\n if (_.exists(defaultAgg) && this.isAggFuncPossible(column, defaultAgg)) {\n return defaultAgg;\n }\n if (this.isAggFuncPossible(column, AggFuncService_1.AGG_SUM)) {\n return AggFuncService_1.AGG_SUM;\n }\n var allKeys = this.getFuncNames(column);\n return _.existsAndNotEmpty(allKeys) ? allKeys[0] : null;\n };\n AggFuncService.prototype.addAggFuncs = function (aggFuncs) {\n _.iterateObject(aggFuncs, this.addAggFunc.bind(this));\n };\n AggFuncService.prototype.addAggFunc = function (key, aggFunc) {\n this.init();\n this.aggFuncsMap[key] = aggFunc;\n };\n AggFuncService.prototype.getAggFunc = function (name) {\n this.init();\n return this.aggFuncsMap[name];\n };\n AggFuncService.prototype.getFuncNames = function (column) {\n var userAllowedFuncs = column.getColDef().allowedAggFuncs;\n return userAllowedFuncs == null ? Object.keys(this.aggFuncsMap).sort() : userAllowedFuncs;\n };\n AggFuncService.prototype.clear = function () {\n this.aggFuncsMap = {};\n };\n var AggFuncService_1;\n AggFuncService.AGG_SUM = 'sum';\n AggFuncService.AGG_FIRST = 'first';\n AggFuncService.AGG_LAST = 'last';\n AggFuncService.AGG_MIN = 'min';\n AggFuncService.AGG_MAX = 'max';\n AggFuncService.AGG_COUNT = 'count';\n AggFuncService.AGG_AVG = 'avg';\n __decorate([\n PostConstruct\n ], AggFuncService.prototype, \"init\", null);\n AggFuncService = AggFuncService_1 = __decorate([\n Bean('aggFuncService')\n ], AggFuncService);\n return AggFuncService;\n}(BeanStub));\nexport { AggFuncService };\nfunction aggSum(params) {\n var values = params.values;\n var result = null; // the logic ensures that we never combine bigint arithmetic with numbers, but TS is hard to please\n // for optimum performance, we use a for loop here rather than calling any helper methods or using functional code\n for (var i = 0; i < values.length; i++) {\n var value = values[i];\n if (typeof value === 'number') {\n if (result === null) {\n result = value;\n }\n else {\n if (AGBigInt) {\n result += typeof result === 'number' ? value : AGBigInt(value);\n }\n else {\n result += value;\n }\n }\n }\n else if (typeof value === 'bigint') {\n if (result === null) {\n result = value;\n }\n else {\n result = (typeof result === 'bigint' ? result : AGBigInt(result)) + value;\n }\n }\n }\n return result;\n}\nfunction aggFirst(params) {\n return params.values.length > 0 ? params.values[0] : null;\n}\nfunction aggLast(params) {\n return params.values.length > 0 ? _.last(params.values) : null;\n}\nfunction aggMin(params) {\n var values = params.values;\n var result = null;\n // for optimum performance, we use a for loop here rather than calling any helper methods or using functional code\n for (var i = 0; i < values.length; i++) {\n var value = values[i];\n if ((typeof value === 'number' || typeof value === 'bigint') && (result === null || result > value)) {\n result = value;\n }\n }\n return result;\n}\nfunction aggMax(params) {\n var values = params.values;\n var result = null;\n // for optimum performance, we use a for loop here rather than calling any helper methods or using functional code\n for (var i = 0; i < values.length; i++) {\n var value = values[i];\n if ((typeof value === 'number' || typeof value === 'bigint') && (result === null || result < value)) {\n result = value;\n }\n }\n return result;\n}\nfunction aggCount(params) {\n var values = params.values;\n var result = 0;\n // for optimum performance, we use a for loop here rather than calling any helper methods or using functional code\n for (var i = 0; i < values.length; i++) {\n var value = values[i];\n // check if the value is from a group, in which case use the group's count\n result += value != null && typeof value.value === 'number' ? value.value : 1;\n }\n return result;\n}\n// the average function is tricky as the multiple levels require weighted averages\n// for the non-leaf node aggregations.\nfunction aggAvg(params) {\n var _a, _b, _c;\n var values = params.values;\n var sum = 0; // the logic ensures that we never combine bigint arithmetic with numbers, but TS is hard to please\n var count = 0;\n // for optimum performance, we use a for loop here rather than calling any helper methods or using functional code\n for (var i = 0; i < values.length; i++) {\n var currentValue = values[i];\n var valueToAdd = null;\n if (typeof currentValue === 'number' || typeof currentValue === 'bigint') {\n valueToAdd = currentValue;\n count++;\n }\n else if (currentValue != null && (typeof currentValue.value === 'number' || typeof currentValue.value === 'bigint') && typeof currentValue.count === 'number') {\n // we are aggregating groups, so we take the aggregated values to calculated a weighted average\n if (AGBigInt) {\n valueToAdd = currentValue.value * (typeof currentValue.value === 'number' ? currentValue.count : AGBigInt(currentValue.count));\n }\n else {\n valueToAdd = currentValue.value * currentValue.count;\n }\n count += currentValue.count;\n }\n if (typeof valueToAdd === 'number') {\n if (AGBigInt) {\n sum += typeof sum === 'number' ? valueToAdd : AGBigInt(valueToAdd);\n }\n else {\n sum += valueToAdd;\n }\n }\n else if (typeof valueToAdd === 'bigint') {\n sum = (typeof sum === 'bigint' ? sum : AGBigInt(sum)) + valueToAdd;\n }\n }\n var value = null;\n // avoid divide by zero error\n if (count > 0) {\n if (AGBigInt) {\n value = sum / (typeof sum === 'number' ? count : AGBigInt(count));\n }\n else {\n value = sum / count;\n }\n }\n // the previous aggregation data\n var existingAggData = (_b = (_a = params.rowNode) === null || _a === void 0 ? void 0 : _a.aggData) === null || _b === void 0 ? void 0 : _b[(_c = params.column) === null || _c === void 0 ? void 0 : _c.getColId()];\n if (existingAggData && existingAggData.count === count && existingAggData.value === value) {\n // the underlying values haven't changed, return the old object to avoid triggering change detection\n return existingAggData;\n }\n // the result will be an object. when this cell is rendered, only the avg is shown.\n // however when this cell is part of another aggregation, the count is also needed\n // to create a weighted average for the next level.\n return {\n count: count,\n value: value,\n // the grid by default uses toString to render values for an object, so this\n // is a trick to get the default cellRenderer to display the avg value\n toString: function () {\n return typeof this.value === 'number' || typeof this.value === 'bigint' ? this.value.toString() : '';\n },\n // used for sorting\n toNumber: function () {\n return this.value;\n }\n };\n}\n","var __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n 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;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nimport { DragSourceType, Component, Autowired, Events, TouchListener, DragAndDropService, PostConstruct, Column, RefSelector, Optional, VirtualList, KeyCode, _, } from \"@ag-grid-community/core\";\nvar DropZoneColumnComp = /** @class */ (function (_super) {\n __extends(DropZoneColumnComp, _super);\n function DropZoneColumnComp(column, dragSourceDropTarget, ghost, dropZonePurpose, horizontal) {\n var _this = _super.call(this) || this;\n _this.column = column;\n _this.dragSourceDropTarget = dragSourceDropTarget;\n _this.ghost = ghost;\n _this.dropZonePurpose = dropZonePurpose;\n _this.horizontal = horizontal;\n _this.popupShowing = false;\n return _this;\n }\n DropZoneColumnComp.prototype.init = function () {\n var _this = this;\n this.setTemplate(DropZoneColumnComp.TEMPLATE);\n var eGui = this.getGui();\n var isFunctionsReadOnly = this.gridOptionsWrapper.isFunctionsReadOnly();\n this.addElementClasses(eGui);\n this.addElementClasses(this.eDragHandle, 'drag-handle');\n this.addElementClasses(this.eText, 'text');\n this.addElementClasses(this.eButton, 'button');\n this.eDragHandle.appendChild(_.createIconNoSpan('columnDrag', this.gridOptionsWrapper));\n this.eButton.appendChild(_.createIconNoSpan('cancel', this.gridOptionsWrapper));\n this.setupSort();\n this.displayName = this.columnModel.getDisplayNameForColumn(this.column, 'columnDrop');\n this.setupComponents();\n if (!this.ghost && !isFunctionsReadOnly) {\n this.addDragSource();\n }\n this.setupAria();\n this.addManagedListener(this.column, Column.EVENT_SORT_CHANGED, function () {\n _this.setupAria();\n });\n this.setupTooltip();\n };\n DropZoneColumnComp.prototype.setupAria = function () {\n var translate = this.gridOptionsWrapper.getLocaleTextFunc();\n var _a = this.getColumnAndAggFuncName(), name = _a.name, aggFuncName = _a.aggFuncName;\n var aggSeparator = translate('ariaDropZoneColumnComponentAggFuncSeperator', ' of ');\n var sortDirection = {\n asc: translate('ariaDropZoneColumnComponentSortAscending', 'ascending'),\n desc: translate('ariaDropZoneColumnComponentSortDescending', 'descending'),\n };\n var columnSort = this.column.getSort();\n var isSortSuppressed = this.gridOptionsWrapper.isRowGroupPanelSuppressSort();\n var ariaInstructions = [\n [\n aggFuncName && \"\" + aggFuncName + aggSeparator,\n name,\n this.isGroupingZone() && !isSortSuppressed && columnSort && \", \" + sortDirection[columnSort]\n ].filter(function (part) { return !!part; }).join(''),\n ];\n var isFunctionsReadOnly = this.gridOptionsWrapper.isFunctionsReadOnly();\n if (this.isAggregationZone() && !isFunctionsReadOnly) {\n var aggregationMenuAria = translate('ariaDropZoneColumnValueItemDescription', 'Press ENTER to change the aggregation type');\n ariaInstructions.push(aggregationMenuAria);\n }\n if (this.isGroupingZone() && this.column.getColDef().sortable && !isSortSuppressed) {\n var sortProgressAria = translate('ariaDropZoneColumnGroupItemDescription', 'Press ENTER to sort');\n ariaInstructions.push(sortProgressAria);\n }\n var deleteAria = translate('ariaDropZoneColumnComponentDescription', 'Press DELETE to remove');\n ariaInstructions.push(deleteAria);\n _.setAriaLabel(this.getGui(), ariaInstructions.join('. '));\n };\n DropZoneColumnComp.prototype.setupTooltip = function () {\n var _this = this;\n var refresh = function () {\n var newTooltipText = _this.column.getColDef().headerTooltip;\n _this.setTooltip(newTooltipText);\n };\n refresh();\n this.addManagedListener(this.eventService, Events.EVENT_NEW_COLUMNS_LOADED, refresh);\n };\n DropZoneColumnComp.prototype.setupSort = function () {\n var _this = this;\n var canSort = this.column.getColDef().sortable;\n var isGroupingZone = this.isGroupingZone();\n if (!canSort || !isGroupingZone) {\n return;\n }\n if (!this.gridOptionsWrapper.isRowGroupPanelSuppressSort()) {\n this.eSortIndicator.setupSort(this.column, true);\n var performSort_1 = function (event) {\n event.preventDefault();\n var sortUsingCtrl = _this.gridOptionsWrapper.isMultiSortKeyCtrl();\n var multiSort = sortUsingCtrl ? (event.ctrlKey || event.metaKey) : event.shiftKey;\n _this.sortController.progressSort(_this.column, multiSort, 'uiColumnSorted');\n };\n this.addGuiEventListener('click', performSort_1);\n this.addGuiEventListener('keydown', function (e) {\n var isEnter = e.key === KeyCode.ENTER;\n if (isEnter && _this.isGroupingZone()) {\n performSort_1(e);\n }\n });\n }\n };\n DropZoneColumnComp.prototype.addDragSource = function () {\n var _this = this;\n var dragSource = {\n type: DragSourceType.ToolPanel,\n eElement: this.eDragHandle,\n defaultIconName: DragAndDropService.ICON_HIDE,\n getDragItem: function () { return _this.createDragItem(); },\n dragItemName: this.displayName,\n dragSourceDropTarget: this.dragSourceDropTarget\n };\n this.dragAndDropService.addDragSource(dragSource, true);\n this.addDestroyFunc(function () { return _this.dragAndDropService.removeDragSource(dragSource); });\n };\n DropZoneColumnComp.prototype.createDragItem = function () {\n var visibleState = {};\n visibleState[this.column.getId()] = this.column.isVisible();\n return {\n columns: [this.column],\n visibleState: visibleState\n };\n };\n DropZoneColumnComp.prototype.setupComponents = function () {\n this.setTextValue();\n this.setupRemove();\n if (this.ghost) {\n this.addCssClass('ag-column-drop-cell-ghost');\n }\n if (this.isAggregationZone() && !this.gridOptionsWrapper.isFunctionsReadOnly()) {\n this.addGuiEventListener('click', this.onShowAggFuncSelection.bind(this));\n }\n };\n DropZoneColumnComp.prototype.setupRemove = function () {\n var _this = this;\n _.setDisplayed(this.eButton, !this.gridOptionsWrapper.isFunctionsReadOnly());\n var agEvent = { type: DropZoneColumnComp.EVENT_COLUMN_REMOVE };\n this.addGuiEventListener('keydown', function (e) {\n var isEnter = e.key === KeyCode.ENTER;\n var isDelete = e.key === KeyCode.DELETE;\n if (isDelete) {\n e.preventDefault();\n _this.dispatchEvent(agEvent);\n }\n if (isEnter && _this.isAggregationZone() && !_this.gridOptionsWrapper.isFunctionsReadOnly()) {\n e.preventDefault();\n _this.onShowAggFuncSelection();\n }\n });\n this.addManagedListener(this.eButton, 'click', function (mouseEvent) {\n _this.dispatchEvent(agEvent);\n mouseEvent.stopPropagation();\n });\n var touchListener = new TouchListener(this.eButton);\n this.addManagedListener(touchListener, TouchListener.EVENT_TAP, function () {\n _this.dispatchEvent(agEvent);\n });\n this.addDestroyFunc(touchListener.destroy.bind(touchListener));\n };\n DropZoneColumnComp.prototype.getColumnAndAggFuncName = function () {\n var name = this.displayName;\n var aggFuncName = '';\n if (this.isAggregationZone()) {\n var aggFunc = this.column.getAggFunc();\n // if aggFunc is a string, we can use it, but if it's a function, then we swap with 'func'\n var aggFuncString = typeof aggFunc === 'string' ? aggFunc : 'agg';\n var localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc();\n aggFuncName = localeTextFunc(aggFuncString, aggFuncString);\n }\n return { name: name, aggFuncName: aggFuncName };\n };\n DropZoneColumnComp.prototype.setTextValue = function () {\n var _a = this.getColumnAndAggFuncName(), name = _a.name, aggFuncName = _a.aggFuncName;\n var displayValue = this.isAggregationZone() ? aggFuncName + \"(\" + name + \")\" : name;\n var displayValueSanitised = _.escapeString(displayValue);\n this.eText.innerHTML = displayValueSanitised;\n };\n DropZoneColumnComp.prototype.onShowAggFuncSelection = function () {\n var _this = this;\n if (this.popupShowing) {\n return;\n }\n this.popupShowing = true;\n var virtualList = new VirtualList('select-agg-func');\n var rows = this.aggFuncService.getFuncNames(this.column);\n var eGui = this.getGui();\n var virtualListGui = virtualList.getGui();\n virtualList.setModel({\n getRow: function (index) { return rows[index]; },\n getRowCount: function () { return rows.length; }\n });\n this.getContext().createBean(virtualList);\n var ePopup = _.loadTemplate(/* html*/ \"
\");\n ePopup.style.top = '0px';\n ePopup.style.left = '0px';\n ePopup.appendChild(virtualListGui);\n // ePopup.style.height = this.gridOptionsWrapper.getAggFuncPopupHeight() + 'px';\n ePopup.style.width = eGui.clientWidth + \"px\";\n var popupHiddenFunc = function () {\n _this.destroyBean(virtualList);\n _this.popupShowing = false;\n eGui.focus();\n };\n var translate = this.gridOptionsWrapper.getLocaleTextFunc();\n var addPopupRes = this.popupService.addPopup({\n modal: true,\n eChild: ePopup,\n closeOnEsc: true,\n closedCallback: popupHiddenFunc,\n ariaLabel: translate('ariaLabelAggregationFunction', 'Aggregation Function')\n });\n if (addPopupRes) {\n virtualList.setComponentCreator(this.createAggSelect.bind(this, addPopupRes.hideFunc));\n }\n virtualList.addGuiEventListener('keydown', function (e) {\n if (e.key === KeyCode.ENTER || e.key === KeyCode.SPACE) {\n var row = virtualList.getLastFocusedRow();\n if (row == null) {\n return;\n }\n var comp = virtualList.getComponentAt(row);\n if (comp) {\n comp.selectItem();\n }\n }\n });\n this.popupService.positionPopupUnderComponent({\n type: 'aggFuncSelect',\n eventSource: eGui,\n ePopup: ePopup,\n keepWithinBounds: true,\n column: this.column\n });\n virtualList.refresh();\n var rowToFocus = rows.findIndex(function (r) { return r === _this.column.getAggFunc(); });\n if (rowToFocus === -1) {\n rowToFocus = 0;\n }\n virtualList.focusRow(rowToFocus);\n };\n DropZoneColumnComp.prototype.createAggSelect = function (hidePopup, value) {\n var _this = this;\n var itemSelected = function () {\n hidePopup();\n if (_this.gridOptionsWrapper.isFunctionsPassive()) {\n var event_1 = {\n type: Events.EVENT_COLUMN_AGG_FUNC_CHANGE_REQUEST,\n columns: [_this.column],\n aggFunc: value\n };\n _this.eventService.dispatchEvent(event_1);\n }\n else {\n _this.columnModel.setColumnAggFunc(_this.column, value, \"toolPanelDragAndDrop\");\n }\n };\n var localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc();\n var aggFuncString = value.toString();\n var aggFuncStringTranslated = localeTextFunc(aggFuncString, aggFuncString);\n var comp = new AggItemComp(itemSelected, aggFuncStringTranslated);\n return comp;\n };\n DropZoneColumnComp.prototype.addElementClasses = function (el, suffix) {\n suffix = suffix ? \"-\" + suffix : '';\n var direction = this.horizontal ? 'horizontal' : 'vertical';\n el.classList.add(\"ag-column-drop-cell\" + suffix, \"ag-column-drop-\" + direction + \"-cell\" + suffix);\n };\n DropZoneColumnComp.prototype.isAggregationZone = function () {\n return this.dropZonePurpose === 'aggregation';\n };\n DropZoneColumnComp.prototype.isGroupingZone = function () {\n return this.dropZonePurpose === 'rowGroup';\n };\n DropZoneColumnComp.EVENT_COLUMN_REMOVE = 'columnRemove';\n DropZoneColumnComp.TEMPLATE = \"\\n \\n \\n