55} from '../column-visibility/columnVisibilityFeature.utils'
66import { buildHeaderGroups } from '../../core/headers/buildHeaderGroups'
77import { callMemoOrStaticFn } from '../../utils'
8+ import type { HeaderGroup } from '../../types/HeaderGroup'
89import type { Cell } from '../../types/Cell'
910import type { Row } from '../../types/Row'
1011import type { CellData , RowData , Updater } from '../../types/type-utils'
@@ -121,7 +122,7 @@ export function row_getCenterVisibleCells<
121122 TFeatures extends TableFeatures ,
122123 TData extends RowData ,
123124> ( row : Row < TFeatures , TData > ) {
124- const allCells = row_getAllVisibleCells ( row )
125+ const allCells = callMemoOrStaticFn ( row , row_getAllVisibleCells )
125126 const { left, right } =
126127 row . table . options . state ?. columnPinning ?? getDefaultColumnPinningState ( )
127128 const leftAndRight : Array < string > = [ ...left , ...right ]
@@ -131,31 +132,29 @@ export function row_getCenterVisibleCells<
131132export function row_getLeftVisibleCells <
132133 TFeatures extends TableFeatures ,
133134 TData extends RowData ,
134- > ( row : Row < TFeatures , TData > ) {
135- const allCells = row_getAllVisibleCells ( row )
135+ > ( row : Row < TFeatures , TData > ) : Array < Cell < TFeatures , TData , unknown > > {
136+ const allCells = callMemoOrStaticFn ( row , row_getAllVisibleCells )
136137 const { left } =
137138 row . table . options . state ?. columnPinning ?? getDefaultColumnPinningState ( )
138139 const cells = left
139140 . map ( ( columnId ) => allCells . find ( ( cell ) => cell . column . id === columnId ) ! )
140141 . filter ( Boolean )
141142 . map ( ( d ) => ( { ...d , position : 'left' } ) )
142-
143- return cells as Array < Cell < TFeatures , TData > >
143+ return cells as any
144144}
145145
146146export function row_getRightVisibleCells <
147147 TFeatures extends TableFeatures ,
148148 TData extends RowData ,
149149> ( row : Row < TFeatures , TData > ) {
150- const allCells = row_getAllVisibleCells ( row )
150+ const allCells = callMemoOrStaticFn ( row , row_getAllVisibleCells )
151151 const { right } =
152152 row . table . options . state ?. columnPinning ?? getDefaultColumnPinningState ( )
153153 const cells = right
154154 . map ( ( columnId ) => allCells . find ( ( cell ) => cell . column . id === columnId ) ! )
155155 . filter ( Boolean )
156156 . map ( ( d ) => ( { ...d , position : 'right' } ) )
157-
158- return cells as Array < Cell < TFeatures , TData > >
157+ return cells as any
159158}
160159
161160// Table APIs
@@ -201,7 +200,10 @@ export function table_getLeftHeaderGroups<
201200 TData extends RowData ,
202201> ( table : Table_Internal < TFeatures , TData > ) {
203202 const allColumns = table . getAllColumns ( )
204- const leafColumns = table_getVisibleLeafColumns ( table )
203+ const leafColumns = callMemoOrStaticFn (
204+ table ,
205+ table_getVisibleLeafColumns ,
206+ ) as unknown as Array < Column < TFeatures , TData , unknown > >
205207 const { left } =
206208 table . options . state ?. columnPinning ?? getDefaultColumnPinningState ( )
207209
@@ -217,7 +219,10 @@ export function table_getRightHeaderGroups<
217219 TData extends RowData ,
218220> ( table : Table_Internal < TFeatures , TData > ) {
219221 const allColumns = table . getAllColumns ( )
220- const leafColumns = table_getVisibleLeafColumns ( table )
222+ const leafColumns = callMemoOrStaticFn (
223+ table ,
224+ table_getVisibleLeafColumns ,
225+ ) as unknown as Array < Column < TFeatures , TData , unknown > >
221226 const { right } =
222227 table . options . state ?. columnPinning ?? getDefaultColumnPinningState ( )
223228
@@ -231,9 +236,14 @@ export function table_getRightHeaderGroups<
231236export function table_getCenterHeaderGroups <
232237 TFeatures extends TableFeatures ,
233238 TData extends RowData ,
234- > ( table : Table_Internal < TFeatures , TData > ) {
239+ > (
240+ table : Table_Internal < TFeatures , TData > ,
241+ ) : Array < HeaderGroup < TFeatures , TData > > {
235242 const allColumns = table . getAllColumns ( )
236- let leafColumns = table_getVisibleLeafColumns ( table )
243+ let leafColumns = callMemoOrStaticFn (
244+ table ,
245+ table_getVisibleLeafColumns ,
246+ ) as unknown as Array < Column < TFeatures , TData , unknown > >
237247 const { left, right } =
238248 table . options . state ?. columnPinning ?? getDefaultColumnPinningState ( )
239249 const leftAndRight : Array < string > = [ ...left , ...right ]
@@ -250,23 +260,23 @@ export function table_getLeftFooterGroups<
250260 TFeatures extends TableFeatures ,
251261 TData extends RowData ,
252262> ( table : Table_Internal < TFeatures , TData > ) {
253- const headerGroups = table_getLeftHeaderGroups ( table )
263+ const headerGroups = callMemoOrStaticFn ( table , table_getLeftHeaderGroups )
254264 return [ ...headerGroups ] . reverse ( )
255265}
256266
257267export function table_getRightFooterGroups <
258268 TFeatures extends TableFeatures ,
259269 TData extends RowData ,
260270> ( table : Table_Internal < TFeatures , TData > ) {
261- const headerGroups = table_getRightHeaderGroups ( table )
271+ const headerGroups = callMemoOrStaticFn ( table , table_getRightHeaderGroups )
262272 return [ ...headerGroups ] . reverse ( )
263273}
264274
265275export function table_getCenterFooterGroups <
266276 TFeatures extends TableFeatures ,
267277 TData extends RowData ,
268278> ( table : Table_Internal < TFeatures , TData > ) {
269- const headerGroups = table_getCenterHeaderGroups ( table )
279+ const headerGroups = callMemoOrStaticFn ( table , table_getCenterHeaderGroups )
270280 return [ ...headerGroups ] . reverse ( )
271281}
272282
@@ -276,7 +286,7 @@ export function table_getLeftFlatHeaders<
276286 TFeatures extends TableFeatures ,
277287 TData extends RowData ,
278288> ( table : Table_Internal < TFeatures , TData > ) {
279- const leftHeaderGroups = table_getLeftHeaderGroups ( table )
289+ const leftHeaderGroups = callMemoOrStaticFn ( table , table_getLeftHeaderGroups )
280290 return leftHeaderGroups
281291 . map ( ( headerGroup ) => {
282292 return headerGroup . headers
@@ -288,7 +298,10 @@ export function table_getRightFlatHeaders<
288298 TFeatures extends TableFeatures ,
289299 TData extends RowData ,
290300> ( table : Table_Internal < TFeatures , TData > ) {
291- const rightHeaderGroups = table_getRightHeaderGroups ( table )
301+ const rightHeaderGroups = callMemoOrStaticFn (
302+ table ,
303+ table_getRightHeaderGroups ,
304+ )
292305 return rightHeaderGroups
293306 . map ( ( headerGroup ) => {
294307 return headerGroup . headers
@@ -300,7 +313,10 @@ export function table_getCenterFlatHeaders<
300313 TFeatures extends TableFeatures ,
301314 TData extends RowData ,
302315> ( table : Table_Internal < TFeatures , TData > ) {
303- const centerHeaderGroups = table_getCenterHeaderGroups ( table )
316+ const centerHeaderGroups = callMemoOrStaticFn (
317+ table ,
318+ table_getCenterHeaderGroups ,
319+ )
304320 return centerHeaderGroups
305321 . map ( ( headerGroup ) => {
306322 return headerGroup . headers
@@ -314,7 +330,7 @@ export function table_getLeftLeafHeaders<
314330 TFeatures extends TableFeatures ,
315331 TData extends RowData ,
316332> ( table : Table_Internal < TFeatures , TData > ) {
317- return table_getLeftFlatHeaders ( table ) . filter (
333+ return callMemoOrStaticFn ( table , table_getLeftFlatHeaders ) . filter (
318334 ( header ) => ! header . subHeaders . length ,
319335 )
320336}
@@ -323,7 +339,7 @@ export function table_getRightLeafHeaders<
323339 TFeatures extends TableFeatures ,
324340 TData extends RowData ,
325341> ( table : Table_Internal < TFeatures , TData > ) {
326- return table_getRightFlatHeaders ( table ) . filter (
342+ return callMemoOrStaticFn ( table , table_getRightFlatHeaders ) . filter (
327343 ( header ) => ! header . subHeaders . length ,
328344 )
329345}
@@ -332,7 +348,7 @@ export function table_getCenterLeafHeaders<
332348 TFeatures extends TableFeatures ,
333349 TData extends RowData ,
334350> ( table : Table_Internal < TFeatures , TData > ) {
335- return table_getCenterFlatHeaders ( table ) . filter (
351+ return callMemoOrStaticFn ( table , table_getCenterFlatHeaders ) . filter (
336352 ( header ) => ! header . subHeaders . length ,
337353 )
338354}
@@ -399,26 +415,26 @@ export function table_getLeftVisibleLeafColumns<
399415 TFeatures extends TableFeatures ,
400416 TData extends RowData ,
401417> ( table : Table_Internal < TFeatures , TData > ) {
402- return table_getLeftLeafColumns ( table ) . filter ( ( column ) =>
403- column_getIsVisible ( column ) ,
418+ return callMemoOrStaticFn ( table , table_getLeftLeafColumns ) . filter ( ( column ) =>
419+ callMemoOrStaticFn ( column , column_getIsVisible ) ,
404420 )
405421}
406422
407423export function table_getRightVisibleLeafColumns <
408424 TFeatures extends TableFeatures ,
409425 TData extends RowData ,
410426> ( table : Table_Internal < TFeatures , TData > ) {
411- return table_getRightLeafColumns ( table ) . filter ( ( column ) =>
412- column_getIsVisible ( column ) ,
427+ return callMemoOrStaticFn ( table , table_getRightLeafColumns ) . filter ( ( column ) =>
428+ callMemoOrStaticFn ( column , column_getIsVisible ) ,
413429 )
414430}
415431
416432export function table_getCenterVisibleLeafColumns <
417433 TFeatures extends TableFeatures ,
418434 TData extends RowData ,
419435> ( table : Table_Internal < TFeatures , TData > ) {
420- return table_getCenterLeafColumns ( table ) . filter ( ( column ) =>
421- column_getIsVisible ( column ) ,
436+ return callMemoOrStaticFn ( table , table_getCenterLeafColumns ) . filter (
437+ ( column ) => callMemoOrStaticFn ( column , column_getIsVisible ) ,
422438 )
423439}
424440
0 commit comments