@@ -21,7 +21,7 @@ import type {
2121} from './types/internal' ;
2222import {
2323 areCellEqual ,
24- findOriginalRowIndex ,
24+ flatten ,
2525 isCellInRange , sequence , sumArray ,
2626} from './utils' ;
2727
@@ -30,6 +30,8 @@ export type SpanningCellManager = {
3030 inSameRange : ( cell1 : CellCoordinates , cell2 : CellCoordinates ) => boolean ,
3131 rowHeights : number [ ] ,
3232 setRowHeights : ( rowHeights : number [ ] ) => void ,
33+ rowIndexMapping : number [ ] ,
34+ setRowIndexMapping : ( mappedRowHeights : number [ ] ) => void ,
3335} ;
3436
3537export type SpanningCellParameters = {
@@ -114,9 +116,10 @@ export const createSpanningCellManager = (parameters: SpanningCellParameters): S
114116 const rangeCache : Record < string , ResolvedRangeConfig | undefined > = { } ;
115117
116118 let rowHeights : number [ ] = [ ] ;
119+ let rowIndexMapping : number [ ] = [ ] ;
117120
118121 return { getContainingRange : ( cell , options ) => {
119- const originalRow = options ?. mapped ? findOriginalRowIndex ( rowHeights , cell . row ) : cell . row ;
122+ const originalRow = options ?. mapped ? rowIndexMapping [ cell . row ] : cell . row ;
120123
121124 const range = findRangeConfig ( { ...cell ,
122125 row : originalRow } , ranges ) ;
@@ -139,7 +142,15 @@ export const createSpanningCellManager = (parameters: SpanningCellParameters): S
139142 return inSameRange ( cell1 , cell2 , ranges ) ;
140143 } ,
141144 rowHeights,
145+ rowIndexMapping,
142146 setRowHeights : ( _rowHeights : number [ ] ) => {
143147 rowHeights = _rowHeights ;
148+ } ,
149+ setRowIndexMapping : ( mappedRowHeights : number [ ] ) => {
150+ rowIndexMapping = flatten ( mappedRowHeights . map ( ( height , index ) => {
151+ return Array . from ( { length : height } , ( ) => {
152+ return index ;
153+ } ) ;
154+ } ) ) ;
144155 } } ;
145156} ;
0 commit comments