UNPKG

@ag-grid-community/client-side-row-model

Version:

Advanced Data Grid / Data Table supporting Javascript / Typescript / React / Angular / Vue

2 lines (1 loc) 32.7 kB
import{_defineModule as T}from"@ag-grid-community/core";import{ModuleNames as M,RowModelHelperService as W,_CsrmSsrmSharedApiModule as Y}from"@ag-grid-community/core";import{BeanStub as j,ChangedPath as $,ClientSideRowModelSteps as d,RowHighlightPosition as S,RowNode as I,_debounce as z,_errorOnce as P,_exists as D,_getGrandTotalRow as K,_getGroupSelectsDescendants as O,_getGroupTotalRowCallback as Q,_getRowHeightForNode as b,_insertIntoArray as q,_isAnimateRows as N,_isDomLayout as X,_last as J,_missing as C,_missingOrEmpty as Z,_removeFromArray as ee}from"@ag-grid-community/core";import{RowNode as te,_cloneObject as oe,_errorOnce as y,_getRowIdCallback as se,_missingOrEmpty as G,_warnOnce as H}from"@ag-grid-community/core";var ie="ROOT_NODE_ID",E=0,re=class{constructor(e,t,o,s,i,r){this.nextId=0,this.rowCountReady=!1,this.allNodesMap={},this.rootNode=e,this.gos=t,this.eventService=o,this.funcColsService=s,this.beans=r,this.selectionService=i,this.rootNode.group=!0,this.rootNode.level=-1,this.rootNode.id=ie,this.rootNode.allLeafChildren=[],this.rootNode.childrenAfterGroup=[],this.rootNode.childrenAfterSort=[],this.rootNode.childrenAfterAggFilter=[],this.rootNode.childrenAfterFilter=[]}getCopyOfNodesMap(){return oe(this.allNodesMap)}getRowNode(e){return this.allNodesMap[e]}setRowData(e){if(typeof e=="string"){H("rowData must be an array.");return}this.rowCountReady=!0,this.dispatchRowDataUpdateStartedEvent(e);const t=this.rootNode,o=this.rootNode.sibling;t.childrenAfterFilter=null,t.childrenAfterGroup=null,t.childrenAfterAggFilter=null,t.childrenAfterSort=null,t.childrenMapped=null,t.updateHasChildren(),this.nextId=0,this.allNodesMap={},e?t.allLeafChildren=e.map((s,i)=>this.createNode(s,this.rootNode,E,i)):(t.allLeafChildren=[],t.childrenAfterGroup=[]),o&&(o.childrenAfterFilter=t.childrenAfterFilter,o.childrenAfterGroup=t.childrenAfterGroup,o.childrenAfterAggFilter=t.childrenAfterAggFilter,o.childrenAfterSort=t.childrenAfterSort,o.childrenMapped=t.childrenMapped,o.allLeafChildren=t.allLeafChildren)}updateRowData(e){this.rowCountReady=!0,this.dispatchRowDataUpdateStartedEvent(e.add);const t={rowNodeTransaction:{remove:[],update:[],add:[]},rowsInserted:!1},o=[];return this.executeRemove(e,t,o),this.executeUpdate(e,t,o),this.executeAdd(e,t),this.updateSelection(o,"rowDataChanged"),t}updateRowOrderFromRowData(e){const t=this.rootNode.allLeafChildren,o=t?.length??0,s=new Map;let i=-1,r=-1;for(let n=0;n<o;++n){const a=t[n],l=a.data;l!==e[n]&&(r<0&&(i=n),r=n,s.set(l,a))}if(i<0)return!1;for(let n=i;n<=r;++n){const a=s.get(e[n]);a!==void 0&&(t[n]=a,a.sourceRowIndex=n)}return!0}isRowCountReady(){return this.rowCountReady}dispatchRowDataUpdateStartedEvent(e){this.eventService.dispatchEvent({type:"rowDataUpdateStarted",firstRowData:e?.length?e[0]:null})}updateSelection(e,t){const o=e.length>0;o&&this.selectionService.setNodesSelected({newValue:!1,nodes:e,suppressFinishActions:!0,source:t}),this.selectionService.updateGroupsFromChildrenSelections(t),o&&this.eventService.dispatchEvent({type:"selectionChanged",source:t})}executeAdd(e,t){const o=e.add;if(G(o))return;const s=this.rootNode.allLeafChildren;let i=s.length;if(typeof e.addIndex=="number"&&(i=this.sanitizeAddIndex(e.addIndex),i>0&&this.gos.get("treeData"))){for(let l=0;l<s.length;l++)if(s[l]?.rowIndex==i-1){i=l+1;break}}const r=o.map((a,l)=>this.createNode(a,this.rootNode,E,i+l));if(i<s.length){const a=s.slice(0,i),l=s.slice(i,s.length),u=a.length+r.length;for(let g=0,c=l.length;g<c;++g)l[g].sourceRowIndex=u+g;this.rootNode.allLeafChildren=[...a,...r,...l],t.rowsInserted=!0}else this.rootNode.allLeafChildren=s.concat(r);const n=this.rootNode.sibling;n&&(n.allLeafChildren=s),t.rowNodeTransaction.add=r}sanitizeAddIndex(e){const t=this.rootNode.allLeafChildren?.length??0;return e<0||e>=t||Number.isNaN(e)?t:Math.ceil(e)}executeRemove(e,{rowNodeTransaction:t},o){const{remove:s}=e;if(G(s))return;const i={};s.forEach(n=>{const a=this.lookupRowNode(n);a&&(a.isSelected()&&o.push(a),a.clearRowTopAndRowIndex(),i[a.id]=!0,delete this.allNodesMap[a.id],t.remove.push(a))}),this.rootNode.allLeafChildren=this.rootNode.allLeafChildren?.filter(n=>!i[n.id])??null,this.rootNode.allLeafChildren?.forEach((n,a)=>{n.sourceRowIndex=a});const r=this.rootNode.sibling;r&&(r.allLeafChildren=this.rootNode.allLeafChildren)}executeUpdate(e,{rowNodeTransaction:t},o){const{update:s}=e;G(s)||s.forEach(i=>{const r=this.lookupRowNode(i);r&&(r.updateData(i),!r.selectable&&r.isSelected()&&o.push(r),this.setMasterForRow(r,i,E,!1),t.update.push(r))})}lookupRowNode(e){const t=se(this.gos);let o;if(t){const s=t({data:e,level:0});if(o=this.allNodesMap[s],!o)return y(`could not find row id=${s}, data item was not found for this id`),null}else if(o=this.rootNode.allLeafChildren?.find(s=>s.data===e),!o)return y("could not find data item as object was not found",e),y("Consider using getRowId to help the Grid find matching row data"),null;return o||null}createNode(e,t,o,s){const i=new te(this.beans);return i.sourceRowIndex=s,i.group=!1,this.setMasterForRow(i,e,o,!0),t&&(i.parent=t),i.level=o,i.setDataAndId(e,this.nextId.toString()),this.allNodesMap[i.id]&&H(`duplicate node id '${i.id}' detected from getRowId callback, this could cause issues in your grid.`),this.allNodesMap[i.id]=i,this.nextId++,i}setMasterForRow(e,t,o,s){if(this.gos.get("treeData"))e.setMaster(!1),s&&(e.expanded=!1);else{if(this.gos.get("masterDetail")){const n=this.gos.get("isRowMaster");n?e.setMaster(n(t)):e.setMaster(!0)}else e.setMaster(!1);if(s){const n=this.funcColsService.getRowGroupColumns(),a=n?n.length:0,l=o+a;e.expanded=e.master?this.isExpanded(l):!1}}}isExpanded(e){const t=this.gos.get("groupDefaultExpanded");return t===-1?!0:e<t}},ne=class extends j{constructor(){super(...arguments),this.beanName="rowModel",this.onRowHeightChanged_debounced=z(this.onRowHeightChanged.bind(this),100),this.rowsToDisplay=[],this.hasStarted=!1,this.shouldSkipSettingDataOnStart=!1,this.isRefreshingModel=!1,this.rowCountReady=!1}wireBeans(e){this.beans=e,this.columnModel=e.columnModel,this.funcColsService=e.funcColsService,this.selectionService=e.selectionService,this.valueCache=e.valueCache,this.environment=e.environment,this.filterStage=e.filterStage,this.sortStage=e.sortStage,this.flattenStage=e.flattenStage,this.groupStage=e.groupStage,this.aggregationStage=e.aggregationStage,this.pivotStage=e.pivotStage,this.filterAggregatesStage=e.filterAggregatesStage}postConstruct(){const e=this.refreshModel.bind(this,{step:d.EVERYTHING}),t=!this.gos.get("suppressAnimationFrame"),o=this.refreshModel.bind(this,{step:d.EVERYTHING,afterColumnsChanged:!0,keepRenderedRows:!0,animate:t});this.addManagedEventListeners({newColumnsLoaded:o,columnRowGroupChanged:e,columnValueChanged:this.onValueChanged.bind(this),columnPivotChanged:this.refreshModel.bind(this,{step:d.PIVOT}),filterChanged:this.onFilterChanged.bind(this),sortChanged:this.onSortChanged.bind(this),columnPivotModeChanged:e,gridStylesChanged:this.onGridStylesChanges.bind(this),gridReady:this.onGridReady.bind(this)}),this.addPropertyListeners(),this.rootNode=new I(this.beans),this.nodeManager=new re(this.rootNode,this.gos,this.eventService,this.funcColsService,this.selectionService,this.beans)}addPropertyListeners(){const e=new Set(["treeData","masterDetail"]),t=new Set(["groupDefaultExpanded","groupAllowUnbalanced","initialGroupOrderComparator","groupHideOpenParents","groupDisplayType"]),o=new Set(["excludeChildrenWhenTreeDataFiltering"]),s=new Set(["removePivotHeaderRowWhenSingleValueColumn","pivotRowTotals","pivotColumnGroupTotals","suppressExpandablePivotGroups"]),i=new Set(["getGroupRowAgg","alwaysAggregateAtRootLevel","groupIncludeTotalFooter","suppressAggFilteredOnly","grandTotalRow"]),r=new Set(["postSortRows","groupDisplayType","accentedSort"]),n=new Set([]),a=new Set(["groupRemoveSingleChildren","groupRemoveLowestSingleChildren","groupIncludeFooter","groupTotalRow"]),l=[...e,...t,...o,...s,...s,...i,...r,...n,...a];this.addManagedPropertyListeners(l,u=>{const g=u.changeSet?.properties;if(!g)return;const c=h=>g.some(R=>h.has(R));if(c(e)){this.setRowData(this.rootNode.allLeafChildren.map(h=>h.data));return}if(c(t)){this.refreshModel({step:d.EVERYTHING});return}if(c(o)){this.refreshModel({step:d.FILTER});return}if(c(s)){this.refreshModel({step:d.PIVOT});return}if(c(i)){this.refreshModel({step:d.AGGREGATE});return}if(c(r)){this.refreshModel({step:d.SORT});return}if(c(n)){this.refreshModel({step:d.FILTER_AGGREGATES});return}c(a)&&this.refreshModel({step:d.MAP})}),this.addManagedPropertyListener("rowHeight",()=>this.resetRowHeights())}start(){this.hasStarted=!0,this.shouldSkipSettingDataOnStart?this.dispatchUpdateEventsAndRefresh():this.setInitialData()}setInitialData(){const e=this.gos.get("rowData");e&&(this.shouldSkipSettingDataOnStart=!0,this.setRowData(e))}ensureRowHeightsValid(e,t,o,s){let i,r=!1;do{i=!1;const n=this.getRowIndexAtPixel(e),a=this.getRowIndexAtPixel(t),l=Math.max(n,o),u=Math.min(a,s);for(let g=l;g<=u;g++){const c=this.getRow(g);if(c.rowHeightEstimated){const h=b(this.gos,c);c.setRowHeight(h.height),i=!0,r=!0}}i&&this.setRowTopAndRowIndex()}while(i);return r}setRowTopAndRowIndex(){const e=this.environment.getDefaultRowHeight();let t=0;const o=new Set,s=X(this.gos,"normal");for(let i=0;i<this.rowsToDisplay.length;i++){const r=this.rowsToDisplay[i];if(r.id!=null&&o.add(r.id),r.rowHeight==null){const n=b(this.gos,r,s,e);r.setRowHeight(n.height,n.estimated)}r.setRowTop(t),r.setRowIndex(i),t+=r.rowHeight}return o}clearRowTopAndRowIndex(e,t){const o=e.isActive(),s=r=>{r&&r.id!=null&&!t.has(r.id)&&r.clearRowTopAndRowIndex()},i=r=>{if(s(r),s(r.detailNode),s(r.sibling),r.hasChildren()&&r.childrenAfterGroup){const n=r.level==-1;o&&!n&&!r.expanded||r.childrenAfterGroup.forEach(i)}};i(this.rootNode)}ensureRowsAtPixel(e,t,o=0){const s=this.getRowIndexAtPixel(t),i=this.getRow(s),r=!this.gos.get("suppressAnimationFrame");if(i===e[0])return!1;const n=this.rootNode.allLeafChildren;return e.forEach(a=>{ee(n,a)}),e.forEach((a,l)=>{q(n,a,Math.max(s+o,0)+l)}),e.forEach((a,l)=>{a.sourceRowIndex=l}),this.refreshModel({step:d.EVERYTHING,keepRenderedRows:!0,keepEditingRows:!0,animate:r,rowNodesOrderChanged:!0}),!0}highlightRowAtPixel(e,t){const o=t!=null?this.getRowIndexAtPixel(t):null,s=o!=null?this.getRow(o):null;if(!s||!e||t==null){this.clearHighlightedRow();return}const i=this.getHighlightPosition(t,s),r=this.isHighlightingCurrentPosition(e,s,i),n=this.lastHighlightedRow!=null&&this.lastHighlightedRow!==s;(r||n)&&(this.clearHighlightedRow(),r)||(s.setHighlighted(i),this.lastHighlightedRow=s)}getHighlightPosition(e,t){if(!t){const i=this.getRowIndexAtPixel(e);if(t=this.getRow(i||0),!t)return S.Below}const{rowTop:o,rowHeight:s}=t;return e-o<s/2?S.Above:S.Below}getLastHighlightedRowNode(){return this.lastHighlightedRow}isHighlightingCurrentPosition(e,t,o){if(e===t)return!0;const s=o===S.Above?-1:1;return this.getRow(t.rowIndex+s)===e}clearHighlightedRow(){this.lastHighlightedRow&&(this.lastHighlightedRow.setHighlighted(null),this.lastHighlightedRow=null)}isLastRowIndexKnown(){return!0}getRowCount(){return this.rowsToDisplay?this.rowsToDisplay.length:0}getTopLevelRowCount(){if(this.rowsToDisplay.length===0)return 0;if(this.rowsToDisplay&&this.rowsToDisplay[0]===this.rootNode)return 1;const t=this.rootNode.childrenAfterAggFilter,o=this.rootNode.sibling?1:0;return(t?t.length:0)+o}getTopLevelRowDisplayedIndex(e){if(this.rowsToDisplay&&this.rowsToDisplay[0]===this.rootNode)return e;let o=e;if(this.rowsToDisplay[0].footer){if(e===0)return 0;o-=1}const s=this.rowsToDisplay[this.rowsToDisplay.length-1],i=o>=this.rootNode.childrenAfterSort.length;if(s.footer&&i)return s.rowIndex;let r=this.rootNode.childrenAfterSort[o];if(this.gos.get("groupHideOpenParents"))for(;r.expanded&&r.childrenAfterSort&&r.childrenAfterSort.length>0;)r=r.childrenAfterSort[0];return r.rowIndex}getRowBounds(e){if(C(this.rowsToDisplay))return null;const t=this.rowsToDisplay[e];return t?{rowTop:t.rowTop,rowHeight:t.rowHeight}:null}onRowGroupOpened(){const e=N(this.gos);this.refreshModel({step:d.MAP,keepRenderedRows:!0,animate:e})}onFilterChanged(e){if(e.afterDataChange)return;const t=N(this.gos),s=e.columns.length===0||e.columns.some(i=>i.isPrimary())?d.FILTER:d.FILTER_AGGREGATES;this.refreshModel({step:s,keepRenderedRows:!0,animate:t})}onSortChanged(){const e=N(this.gos);this.refreshModel({step:d.SORT,keepRenderedRows:!0,animate:e,keepEditingRows:!0})}getType(){return"clientSide"}onValueChanged(){this.columnModel.isPivotActive()?this.refreshModel({step:d.PIVOT}):this.refreshModel({step:d.AGGREGATE})}createChangePath(e){const t=Z(e),o=new $(!1,this.rootNode);return t&&o.setInactive(),o}isSuppressModelUpdateAfterUpdateTransaction(e){if(!this.gos.get("suppressModelUpdateAfterUpdateTransaction")||e.rowNodeTransactions==null)return!1;const t=e.rowNodeTransactions.filter(s=>s.add!=null&&s.add.length>0||s.remove!=null&&s.remove.length>0);return t==null||t.length==0}buildRefreshModelParams(e){let t=d.EVERYTHING;const o={everything:d.EVERYTHING,group:d.EVERYTHING,filter:d.FILTER,map:d.MAP,aggregate:d.AGGREGATE,filter_aggregates:d.FILTER_AGGREGATES,sort:d.SORT,pivot:d.PIVOT,nothing:d.NOTHING};if(D(e)&&(t=o[e]),C(t)){P(`invalid step ${e}, available steps are ${Object.keys(o).join(", ")}`);return}const s=!this.gos.get("suppressAnimationFrame");return{step:t,keepRenderedRows:!0,keepEditingRows:!0,animate:s}}refreshModel(e){if(!this.hasStarted||this.isRefreshingModel||this.columnModel.isChangeEventsDispatching())return;const t=typeof e=="object"&&"step"in e?e:this.buildRefreshModelParams(e);if(!t||this.isSuppressModelUpdateAfterUpdateTransaction(t))return;const o=this.createChangePath(t.rowNodeTransactions);switch(this.isRefreshingModel=!0,t.step){case d.EVERYTHING:this.doRowGrouping(t.rowNodeTransactions,o,!!t.rowNodesOrderChanged,!!t.afterColumnsChanged);case d.FILTER:this.doFilter(o);case d.PIVOT:this.doPivot(o);case d.AGGREGATE:this.doAggregate(o);case d.FILTER_AGGREGATES:this.doFilterAggregates(o);case d.SORT:this.doSort(t.rowNodeTransactions,o);case d.MAP:this.doRowsToDisplay()}const s=this.setRowTopAndRowIndex();this.clearRowTopAndRowIndex(o,s),this.isRefreshingModel=!1,this.eventService.dispatchEvent({type:"modelUpdated",animate:t.animate,keepRenderedRows:t.keepRenderedRows,newData:t.newData,newPage:!1,keepUndoRedoStack:t.keepUndoRedoStack})}isEmpty(){const e=C(this.rootNode.allLeafChildren)||this.rootNode.allLeafChildren.length===0;return C(this.rootNode)||e||!this.columnModel.isReady()}isRowsToRender(){return D(this.rowsToDisplay)&&this.rowsToDisplay.length>0}getNodesInRangeForSelection(e,t){let o=!1,s=!1;const i=[],r=O(this.gos);return this.forEachNodeAfterFilterAndSort(n=>{if(s)return;if(o&&(n===t||n===e)&&(s=!0,n.group&&r)){i.push(...n.allLeafChildren);return}if(!o){if(n!==t&&n!==e)return;o=!0}if(!n.group||!r){i.push(n);return}}),i}setDatasource(e){P("should never call setDatasource on clientSideRowController")}getTopLevelNodes(){return this.rootNode?this.rootNode.childrenAfterGroup:null}getRootNode(){return this.rootNode}getRow(e){return this.rowsToDisplay[e]}isRowPresent(e){return this.rowsToDisplay.indexOf(e)>=0}getRowIndexAtPixel(e){if(this.isEmpty()||this.rowsToDisplay.length===0)return-1;let t=0,o=this.rowsToDisplay.length-1;if(e<=0)return 0;if(J(this.rowsToDisplay).rowTop<=e)return this.rowsToDisplay.length-1;let i=-1,r=-1;for(;;){const n=Math.floor((t+o)/2),a=this.rowsToDisplay[n];if(this.isRowInPixel(a,e)||(a.rowTop<e?t=n+1:a.rowTop>e&&(o=n-1),i===t&&r===o))return n;i=t,r=o}}isRowInPixel(e,t){const o=e.rowTop,s=e.rowTop+e.rowHeight;return o<=t&&s>t}forEachLeafNode(e){this.rootNode.allLeafChildren&&this.rootNode.allLeafChildren.forEach((t,o)=>e(t,o))}forEachNode(e,t=!1){this.recursivelyWalkNodesAndCallback({nodes:[...this.rootNode.childrenAfterGroup||[]],callback:e,recursionType:0,index:0,includeFooterNodes:t})}forEachNodeAfterFilter(e,t=!1){this.recursivelyWalkNodesAndCallback({nodes:[...this.rootNode.childrenAfterAggFilter||[]],callback:e,recursionType:1,index:0,includeFooterNodes:t})}forEachNodeAfterFilterAndSort(e,t=!1){this.recursivelyWalkNodesAndCallback({nodes:[...this.rootNode.childrenAfterSort||[]],callback:e,recursionType:2,index:0,includeFooterNodes:t})}forEachPivotNode(e,t=!1){this.recursivelyWalkNodesAndCallback({nodes:[this.rootNode],callback:e,recursionType:3,index:0,includeFooterNodes:t})}recursivelyWalkNodesAndCallback(e){const{nodes:t,callback:o,recursionType:s,includeFooterNodes:i}=e;let{index:r}=e;const n=a=>{const l=t[0]?.parent;if(!l)return;const u=i&&K(this.gos),g=Q(this.gos),c=i&&g({node:l});if(l===this.rootNode){u===a&&(l.createFooter(),o(l.sibling,r++));return}c===a&&(l.createFooter(),o(l.sibling,r++))};n("top");for(let a=0;a<t.length;a++){const l=t[a];if(o(l,r++),l.hasChildren()&&!l.footer){let u=null;switch(s){case 0:u=l.childrenAfterGroup;break;case 1:u=l.childrenAfterAggFilter;break;case 2:u=l.childrenAfterSort;break;case 3:u=l.leafGroup?null:l.childrenAfterSort;break}u&&(r=this.recursivelyWalkNodesAndCallback({nodes:[...u],callback:o,recursionType:s,index:r,includeFooterNodes:i}))}}return n("bottom"),r}doAggregate(e){this.aggregationStage?.execute({rowNode:this.rootNode,changedPath:e})}doFilterAggregates(e){this.filterAggregatesStage?this.filterAggregatesStage.execute({rowNode:this.rootNode,changedPath:e}):this.rootNode.childrenAfterAggFilter=this.rootNode.childrenAfterFilter}expandOrCollapseAll(e){const t=this.gos.get("treeData"),o=this.columnModel.isPivotActive(),s=i=>{i&&i.forEach(r=>{const n=()=>{r.expanded=e,s(r.childrenAfterGroup)};if(t){D(r.childrenAfterGroup)&&n();return}if(o){!r.leafGroup&&n();return}r.group&&n()})};this.rootNode&&s(this.rootNode.childrenAfterGroup),this.refreshModel({step:d.MAP}),this.eventService.dispatchEvent({type:"expandOrCollapseAll",source:e?"expandAll":"collapseAll"})}doSort(e,t){this.sortStage.execute({rowNode:this.rootNode,rowNodeTransactions:e,changedPath:t})}doRowGrouping(e,t,o,s){if(this.groupStage)e?this.groupStage.execute({rowNode:this.rootNode,rowNodeTransactions:e,rowNodesOrderChanged:o,changedPath:t}):this.groupStage.execute({rowNode:this.rootNode,changedPath:t,afterColumnsChanged:s}),O(this.gos)&&this.selectionService.updateGroupsFromChildrenSelections("rowGroupChanged",t)&&this.eventService.dispatchEvent({type:"selectionChanged",source:"rowGroupChanged"});else{const i=this.rootNode,r=i.sibling;i.childrenAfterGroup=i.allLeafChildren,r&&(r.childrenAfterGroup=i.childrenAfterGroup),this.rootNode.updateHasChildren()}this.nodeManager.isRowCountReady()&&(this.rowCountReady=!0,this.eventService.dispatchEventOnce({type:"rowCountReady"}))}doFilter(e){this.filterStage.execute({rowNode:this.rootNode,changedPath:e})}doPivot(e){this.pivotStage?.execute({rowNode:this.rootNode,changedPath:e})}getNodeManager(){return this.nodeManager}getRowNode(e){if(typeof e=="string"&&e.indexOf(I.ID_PREFIX_ROW_GROUP)==0){let o;return this.forEachNode(s=>{s.id===e&&(o=s)}),o}return this.nodeManager.getRowNode(e)}setRowData(e){this.selectionService.reset("rowDataChanged"),this.nodeManager.setRowData(e),this.hasStarted&&this.dispatchUpdateEventsAndRefresh()}dispatchUpdateEventsAndRefresh(){this.eventService.dispatchEvent({type:"rowDataUpdated"}),this.refreshModel({step:d.EVERYTHING,newData:!0})}batchUpdateRowData(e,t){if(this.applyAsyncTransactionsTimeout==null){this.rowDataTransactionBatch=[];const o=this.gos.get("asyncTransactionWaitMillis");this.applyAsyncTransactionsTimeout=window.setTimeout(()=>{this.isAlive()&&this.executeBatchUpdateRowData()},o)}this.rowDataTransactionBatch.push({rowDataTransaction:e,callback:t})}flushAsyncTransactions(){this.applyAsyncTransactionsTimeout!=null&&(clearTimeout(this.applyAsyncTransactionsTimeout),this.executeBatchUpdateRowData())}executeBatchUpdateRowData(){this.valueCache.onDataChanged();const e=[],t=[];let o=!1;this.rowDataTransactionBatch?.forEach(s=>{const{rowNodeTransaction:i,rowsInserted:r}=this.nodeManager.updateRowData(s.rowDataTransaction);r&&(o=!0),t.push(i),s.callback&&e.push(s.callback.bind(null,i))}),this.commonUpdateRowData(t,o),e.length>0&&window.setTimeout(()=>{e.forEach(s=>s())},0),t.length>0&&this.eventService.dispatchEvent({type:"asyncTransactionsFlushed",results:t}),this.rowDataTransactionBatch=null,this.applyAsyncTransactionsTimeout=void 0}updateRowData(e){this.valueCache.onDataChanged();const{rowNodeTransaction:t,rowsInserted:o}=this.nodeManager.updateRowData(e);return this.commonUpdateRowData([t],o),t}afterImmutableDataChange(e,t){this.commonUpdateRowData([e],t)}commonUpdateRowData(e,t){if(!this.hasStarted)return;const o=!this.gos.get("suppressAnimationFrame");this.eventService.dispatchEvent({type:"rowDataUpdated"}),this.refreshModel({step:d.EVERYTHING,rowNodeTransactions:e,rowNodesOrderChanged:t,keepRenderedRows:!0,keepEditingRows:!0,animate:o})}doRowsToDisplay(){this.rowsToDisplay=this.flattenStage.execute({rowNode:this.rootNode})}onRowHeightChanged(){this.refreshModel({step:d.MAP,keepRenderedRows:!0,keepEditingRows:!0,keepUndoRedoStack:!0})}onRowHeightChangedDebounced(){this.onRowHeightChanged_debounced()}resetRowHeights(){const e=this.resetRowHeightsForAllRowNodes();this.rootNode.setRowHeight(this.rootNode.rowHeight,!0),this.rootNode.sibling&&this.rootNode.sibling.setRowHeight(this.rootNode.sibling.rowHeight,!0),e&&this.onRowHeightChanged()}resetRowHeightsForAllRowNodes(){let e=!1;return this.forEachNode(t=>{t.setRowHeight(t.rowHeight,!0);const o=t.detailNode;o&&o.setRowHeight(o.rowHeight,!0),t.sibling&&t.sibling.setRowHeight(t.sibling.rowHeight,!0),e=!0}),e}onGridStylesChanges(e){if(e.rowHeightChanged){if(this.columnModel.isAutoRowHeightActive())return;this.resetRowHeights()}}onGridReady(){this.hasStarted||this.setInitialData()}isRowDataLoaded(){return this.rowCountReady}destroy(){super.destroy(),this.clearHighlightedRow()}};import{_warnOnce as ae}from"@ag-grid-community/core";function le(e){e.expansionService.onGroupExpandedOrCollapsed()}function de(e,t){e.rowModelHelperService?.getClientSideRowModel()?.refreshModel(t)}function he(e){return e.rowModelHelperService?.getClientSideRowModel()?.isEmpty()??!0}function ce(e,t){e.rowModelHelperService?.getClientSideRowModel()?.forEachLeafNode(t)}function ue(e,t){e.rowModelHelperService?.getClientSideRowModel()?.forEachNodeAfterFilter(t)}function ge(e,t){e.rowModelHelperService?.getClientSideRowModel()?.forEachNodeAfterFilterAndSort(t)}function pe(e){if(e.columnModel.isAutoRowHeightActive()){ae("calling gridApi.resetRowHeights() makes no sense when using Auto Row Height.");return}e.rowModelHelperService?.getClientSideRowModel()?.resetRowHeights()}function fe(e,t){return e.frameworkOverrides.wrapIncoming(()=>e.rowModelHelperService?.getClientSideRowModel()?.updateRowData(t))}function we(e,t,o){e.frameworkOverrides.wrapIncoming(()=>e.rowModelHelperService?.getClientSideRowModel()?.batchUpdateRowData(t,o))}function Re(e){e.frameworkOverrides.wrapIncoming(()=>e.rowModelHelperService?.getClientSideRowModel()?.flushAsyncTransactions())}function Se(e){return e.selectionService.getBestCostNodeSelection()}import{BeanStub as Ce}from"@ag-grid-community/core";var me=class extends Ce{constructor(){super(...arguments),this.beanName="filterStage"}wireBeans(e){this.filterManager=e.filterManager}execute(e){const{changedPath:t}=e;this.filter(t)}filter(e){const t=!!this.filterManager?.isChildFilterPresent();this.filterNodes(t,e)}filterNodes(e,t){const o=(s,i)=>{s.hasChildren()&&e&&!i?s.childrenAfterFilter=s.childrenAfterGroup.filter(r=>{const n=r.childrenAfterFilter&&r.childrenAfterFilter.length>0,a=r.data&&this.filterManager.doesRowPassFilter({rowNode:r});return n||a}):s.childrenAfterFilter=s.childrenAfterGroup,s.sibling&&(s.sibling.childrenAfterFilter=s.childrenAfterFilter)};if(this.doingTreeDataFiltering()){const s=(r,n)=>{if(r.childrenAfterGroup)for(let a=0;a<r.childrenAfterGroup.length;a++){const l=r.childrenAfterGroup[a],u=n||this.filterManager.doesRowPassFilter({rowNode:l});l.childrenAfterGroup?s(r.childrenAfterGroup[a],u):o(l,u)}o(r,n)},i=r=>s(r,!1);t.executeFromRootNode(i)}else{const s=i=>o(i,!1);t.forEachChangedNodeDepthFirst(s,!0)}}doingTreeDataFiltering(){return this.gos.get("treeData")&&!this.gos.get("excludeChildrenWhenTreeDataFiltering")}};import{BeanStub as Ae,RowNode as ve,_exists as k,_getGrandTotalRow as Te,_getGroupTotalRowCallback as Me,_isGroupMultiAutoColumn as De,_missingOrEmpty as Ne}from"@ag-grid-community/core";var ye=class extends Ae{constructor(){super(...arguments),this.beanName="flattenStage"}wireBeans(e){this.beans=e,this.columnModel=e.columnModel}execute(e){const t=e.rowNode,o=[],s=this.columnModel.isPivotMode(),i=s&&t.leafGroup,r=i?[t]:t.childrenAfterSort,n=this.getFlattenDetails();this.recursivelyAddToRowsToDisplay(n,r,o,s,0);const a=o.length>0;if(!i&&a&&n.grandTotalRow){t.createFooter();const u=n.grandTotalRow==="top";this.addRowNodeToRowsToDisplay(n,t.sibling,o,0,u)}return o}getFlattenDetails(){const e=this.gos.get("groupRemoveSingleChildren");return{groupRemoveLowestSingleChildren:!e&&this.gos.get("groupRemoveLowestSingleChildren"),groupRemoveSingleChildren:e,isGroupMultiAutoColumn:De(this.gos),hideOpenParents:this.gos.get("groupHideOpenParents"),grandTotalRow:Te(this.gos),groupTotalRow:Me(this.gos)}}recursivelyAddToRowsToDisplay(e,t,o,s,i){if(!Ne(t))for(let r=0;r<t.length;r++){const n=t[r],a=n.hasChildren(),l=s&&!a,u=e.groupRemoveSingleChildren&&a&&n.childrenAfterGroup.length===1,g=e.groupRemoveLowestSingleChildren&&a&&n.leafGroup&&n.childrenAfterGroup.length===1,c=s&&n.leafGroup,h=e.hideOpenParents&&n.expanded&&!n.master&&!c;if(!l&&!h&&!u&&!g&&this.addRowNodeToRowsToDisplay(e,n,o,i),!(s&&n.leafGroup)){if(a){const f=u||g;if(n.expanded||f){const p=e.groupTotalRow({node:n});p||n.destroyFooter();const w=f?i:i+1;p==="top"&&(n.createFooter(),this.addRowNodeToRowsToDisplay(e,n.sibling,o,w)),this.recursivelyAddToRowsToDisplay(e,n.childrenAfterSort,o,s,w),p==="bottom"&&(n.createFooter(),this.addRowNodeToRowsToDisplay(e,n.sibling,o,w))}}else if(n.master&&n.expanded){const f=this.createDetailNode(n);this.addRowNodeToRowsToDisplay(e,f,o,i)}}}}addRowNodeToRowsToDisplay(e,t,o,s,i){i?o.unshift(t):o.push(t),t.setUiLevel(e.isGroupMultiAutoColumn?0:s)}createDetailNode(e){if(k(e.detailNode))return e.detailNode;const t=new ve(this.beans);return t.detail=!0,t.selectable=!1,t.parent=e,k(e.id)&&(t.id="detail_"+e.id),t.data=e.data,t.level=e.level+1,e.detailNode=t,t}};import{BeanStub as Ge,_errorOnce as L,_exists as Ee,_getRowIdCallback as xe,_isClientSideRowModel as _,_iterateObject as Fe}from"@ag-grid-community/core";var Ie=class extends Ge{constructor(){super(...arguments),this.beanName="immutableService"}wireBeans(e){this.rowModel=e.rowModel,this.selectionService=e.selectionService}postConstruct(){_(this.gos)&&(this.clientSideRowModel=this.rowModel,this.addManagedPropertyListener("rowData",()=>this.onRowDataUpdated()))}isActive(){const e=this.gos.exists("getRowId");return this.gos.get("resetRowDataOnUpdate")?!1:e}setRowData(e){const t=this.createTransactionForRowData(e);if(!t)return;const o=this.clientSideRowModel.getNodeManager(),{rowNodeTransaction:s,rowsInserted:i}=o.updateRowData(t);let r=!1;this.gos.get("suppressMaintainUnsortedOrder")||(r=o.updateRowOrderFromRowData(e)),this.clientSideRowModel.afterImmutableDataChange(s,r||i)}createTransactionForRowData(e){if(!_(this.gos))return L("ImmutableService only works with ClientSideRowModel"),null;const t=xe(this.gos);if(t==null)return L("ImmutableService requires getRowId() callback to be implemented, your row data needs IDs!"),null;const o=this.clientSideRowModel.getNodeManager().getCopyOfNodesMap(),s=[],i=[],r=[];return Ee(e)&&e.forEach(n=>{const a=t({data:n,level:0}),l=o[a];l?(l.data!==n&&i.push(n),o[a]=void 0):r.push(n)}),Fe(o,(n,a)=>{a&&s.push(a.data)}),{remove:s,update:i,add:r}}onRowDataUpdated(){const e=this.gos.get("rowData");e&&(this.isActive()?this.setRowData(e):(this.selectionService.reset("rowDataChanged"),this.clientSideRowModel.setRowData(e)))}};import{BeanStub as Pe,_errorOnce as Oe,_missing as U,_warnOnce as be}from"@ag-grid-community/core";var He=class extends Pe{constructor(){super(...arguments),this.beanName="sortService"}wireBeans(e){this.columnModel=e.columnModel,this.funcColsService=e.funcColsService,this.rowNodeSorter=e.rowNodeSorter,this.showRowGroupColsService=e.showRowGroupColsService}sort(e,t,o,s,i,r){const n=this.gos.get("groupMaintainOrder"),a=this.columnModel.getCols().some(h=>h.isRowGroupActive());let l={};o&&s&&(l=this.calculateDirtyNodes(s));const u=this.columnModel.isPivotMode(),g=this.gos.getCallback("postSortRows"),c=h=>{this.pullDownGroupDataForHideOpenParents(h.childrenAfterAggFilter,!0);const R=u&&h.leafGroup;if(n&&a&&!h.leafGroup&&!r){const w=this.funcColsService.getRowGroupColumns()?.[h.level+1]?.getSort()===null,F=h.childrenAfterAggFilter.slice(0);if(h.childrenAfterSort&&!w){const m={};h.childrenAfterSort.forEach((A,v)=>{m[A.id]=v}),F.sort((A,v)=>(m[A.id]??0)-(m[v.id]??0))}h.childrenAfterSort=F}else!t||R?h.childrenAfterSort=h.childrenAfterAggFilter.slice(0):o?h.childrenAfterSort=this.doDeltaSort(h,l,i,e):h.childrenAfterSort=this.rowNodeSorter.doFullSort(h.childrenAfterAggFilter,e);if(h.sibling&&(h.sibling.childrenAfterSort=h.childrenAfterSort),this.updateChildIndexes(h),g){const p={nodes:h.childrenAfterSort};g(p)}};i&&i.forEachChangedNodeDepthFirst(c),this.updateGroupDataForHideOpenParents(i)}calculateDirtyNodes(e){const t={},o=s=>{s&&s.forEach(i=>t[i.id]=!0)};return e&&e.forEach(s=>{o(s.add),o(s.update),o(s.remove)}),t}doDeltaSort(e,t,o,s){const i=e.childrenAfterAggFilter,r=e.childrenAfterSort;if(!r)return this.rowNodeSorter.doFullSort(i,s);const n={},a=[];i.forEach(c=>{t[c.id]||!o.canSkip(c)?a.push(c):n[c.id]=!0});const l=r.filter(c=>n[c.id]),u=(c,h)=>({currentPos:h,rowNode:c}),g=a.map(u).sort((c,h)=>this.rowNodeSorter.compareRowNodes(s,c,h));return this.mergeSortedArrays(s,g,l.map(u)).map(({rowNode:c})=>c)}mergeSortedArrays(e,t,o){const s=[];let i=0,r=0;for(;i<t.length&&r<o.length;)this.rowNodeSorter.compareRowNodes(e,t[i],o[r])<0?s.push(t[i++]):s.push(o[r++]);for(;i<t.length;)s.push(t[i++]);for(;r<o.length;)s.push(o[r++]);return s}updateChildIndexes(e){if(U(e.childrenAfterSort))return;const t=e.childrenAfterSort;for(let o=0;o<t.length;o++){const s=t[o],i=o===0,r=o===e.childrenAfterSort.length-1;s.setFirstChild(i),s.setLastChild(r),s.setChildIndex(o)}}updateGroupDataForHideOpenParents(e){if(!this.gos.get("groupHideOpenParents"))return;if(this.gos.get("treeData"))return be("The property hideOpenParents dose not work with Tree Data. This is because Tree Data has values at the group level, it doesn't make sense to hide them."),!1;const t=o=>{this.pullDownGroupDataForHideOpenParents(o.childrenAfterSort,!1),o.childrenAfterSort.forEach(s=>{s.hasChildren()&&t(s)})};e&&e.executeFromRootNode(o=>t(o))}pullDownGroupDataForHideOpenParents(e,t){!this.gos.get("groupHideOpenParents")||U(e)||e.forEach(o=>{(this.showRowGroupColsService?.getShowRowGroupCols()??[]).forEach(i=>{const r=i.getColDef().showRowGroup;if(typeof r!="string"){Oe("groupHideOpenParents only works when specifying specific columns for colDef.showRowGroup");return}const n=r,a=this.columnModel.getColDefCol(n);if(a!==o.rowGroupColumn)if(t)o.setGroupValue(i.getId(),void 0);else{const u=this.getFirstChildOfFirstChild(o,a);u&&o.setGroupValue(i.getId(),u.key)}})})}getFirstChildOfFirstChild(e,t){let o=e;for(;o;){const s=o.parent;if(s&&o.firstChild){if(s.rowGroupColumn===t)return s}else return null;o=s}return null}};import{BeanStub as ke,_exists as B,_isColumnsSortingCoupledToGroup as Le}from"@ag-grid-community/core";var _e=class extends ke{constructor(){super(...arguments),this.beanName="sortStage"}wireBeans(e){this.sortService=e.sortService,this.sortController=e.sortController}execute(e){const t=this.sortController.getSortOptions(),o=B(t)&&t.length>0,s=o&&B(e.rowNodeTransactions)&&this.gos.get("deltaSort"),i=t.some(r=>Le(this.gos)?r.column.isPrimary()&&r.column.isRowGroupActive():!!r.column.getColDef().showRowGroup);this.sortService.sort(t,o,s,e.rowNodeTransactions,e.changedPath,i)}},x="32.3.9",V=T({version:x,moduleName:`${M.ClientSideRowModelModule}-core`,rowModel:"clientSide",beans:[ne,me,_e,ye,He,Ie]}),Ue=T({version:x,moduleName:`${M.ClientSideRowModelModule}-api`,beans:[W],apiFunctions:{onGroupExpandedOrCollapsed:le,refreshClientSideRowModel:de,isRowDataEmpty:he,forEachLeafNode:ce,forEachNodeAfterFilter:ue,forEachNodeAfterFilterAndSort:ge,resetRowHeights:pe,applyTransaction:fe,applyTransactionAsync:we,flushAsyncTransactions:Re,getBestCostNodeSelection:Se},dependantModules:[V,Y]}),Be=T({version:x,moduleName:M.ClientSideRowModelModule,dependantModules:[V,Ue]});export{Be as ClientSideRowModelModule};