@@ -82,12 +82,9 @@ export class StickyStyler {
82
82
}
83
83
}
84
84
85
- // Coalesce with sticky row/column updates (and potentially other changes like column resize).
86
- this . _coalescedStyleScheduler . schedule ( ( ) => {
87
- for ( const element of elementsToClear ) {
88
- this . _removeStickyStyle ( element , stickyDirections ) ;
89
- }
90
- } ) ;
85
+ for ( const element of elementsToClear ) {
86
+ this . _removeStickyStyle ( element , stickyDirections ) ;
87
+ }
91
88
}
92
89
93
90
/**
@@ -113,61 +110,63 @@ export class StickyStyler {
113
110
! ( stickyStartStates . some ( state => state ) || stickyEndStates . some ( state => state ) )
114
111
) {
115
112
if ( this . _positionListener ) {
116
- this . _positionListener . stickyColumnsUpdated ( { sizes : [ ] } ) ;
117
- this . _positionListener . stickyEndColumnsUpdated ( { sizes : [ ] } ) ;
113
+ this . _coalescedStyleScheduler . scheduleWrite ( ( ) => {
114
+ this . _positionListener ! . stickyColumnsUpdated ( { sizes : [ ] } ) ;
115
+ this . _positionListener ! . stickyEndColumnsUpdated ( { sizes : [ ] } ) ;
116
+ } ) ;
118
117
}
119
118
120
119
return ;
121
120
}
122
121
123
- // Coalesce with sticky row updates (and potentially other changes like column resize).
124
- this . _coalescedStyleScheduler . schedule ( ( ) => {
122
+ this . _coalescedStyleScheduler . scheduleEarlyRead ( ( ) => {
125
123
const firstRow = rows [ 0 ] ;
126
124
const numCells = firstRow . children . length ;
127
- const cellWidths : number [ ] = this . _getCellWidths ( firstRow , recalculateCellWidths ) ;
128
-
129
- const startPositions = this . _getStickyStartColumnPositions ( cellWidths , stickyStartStates ) ;
130
- const endPositions = this . _getStickyEndColumnPositions ( cellWidths , stickyEndStates ) ;
131
-
132
125
const lastStickyStart = stickyStartStates . lastIndexOf ( true ) ;
133
126
const firstStickyEnd = stickyEndStates . indexOf ( true ) ;
134
127
135
- const isRtl = this . direction === 'rtl' ;
136
- const start = isRtl ? 'right' : 'left' ;
137
- const end = isRtl ? 'left' : 'right' ;
138
-
139
- for ( const row of rows ) {
140
- for ( let i = 0 ; i < numCells ; i ++ ) {
141
- const cell = row . children [ i ] as HTMLElement ;
142
- if ( stickyStartStates [ i ] ) {
143
- this . _addStickyStyle ( cell , start , startPositions [ i ] , i === lastStickyStart ) ;
144
- }
128
+ const cellWidths = this . _getCellWidths ( firstRow , recalculateCellWidths ) ;
129
+ const startPositions = this . _getStickyStartColumnPositions ( cellWidths , stickyStartStates ) ;
130
+ const endPositions = this . _getStickyEndColumnPositions ( cellWidths , stickyEndStates ) ;
145
131
146
- if ( stickyEndStates [ i ] ) {
147
- this . _addStickyStyle ( cell , end , endPositions [ i ] , i === firstStickyEnd ) ;
132
+ this . _coalescedStyleScheduler . scheduleWrite ( ( ) => {
133
+ const isRtl = this . direction === 'rtl' ;
134
+ const start = isRtl ? 'right' : 'left' ;
135
+ const end = isRtl ? 'left' : 'right' ;
136
+
137
+ for ( const row of rows ) {
138
+ for ( let i = 0 ; i < numCells ; i ++ ) {
139
+ const cell = row . children [ i ] as HTMLElement ;
140
+ if ( stickyStartStates [ i ] ) {
141
+ this . _addStickyStyle ( cell , start , startPositions ! [ i ] , i === lastStickyStart ) ;
142
+ }
143
+
144
+ if ( stickyEndStates [ i ] ) {
145
+ this . _addStickyStyle ( cell , end , endPositions ! [ i ] , i === firstStickyEnd ) ;
146
+ }
148
147
}
149
148
}
150
- }
151
149
152
- if ( this . _positionListener ) {
153
- this . _positionListener . stickyColumnsUpdated ( {
154
- sizes :
155
- lastStickyStart === - 1
156
- ? [ ]
157
- : cellWidths
158
- . slice ( 0 , lastStickyStart + 1 )
159
- . map ( ( width , index ) => ( stickyStartStates [ index ] ? width : null ) ) ,
160
- } ) ;
161
- this . _positionListener . stickyEndColumnsUpdated ( {
162
- sizes :
163
- firstStickyEnd === - 1
164
- ? [ ]
165
- : cellWidths
166
- . slice ( firstStickyEnd )
167
- . map ( ( width , index ) => ( stickyEndStates [ index + firstStickyEnd ] ? width : null ) )
168
- . reverse ( ) ,
169
- } ) ;
170
- }
150
+ if ( this . _positionListener ) {
151
+ this . _positionListener . stickyColumnsUpdated ( {
152
+ sizes :
153
+ lastStickyStart === - 1
154
+ ? [ ]
155
+ : cellWidths !
156
+ . slice ( 0 , lastStickyStart + 1 )
157
+ . map ( ( width , index ) => ( stickyStartStates [ index ] ? width : null ) ) ,
158
+ } ) ;
159
+ this . _positionListener . stickyEndColumnsUpdated ( {
160
+ sizes :
161
+ firstStickyEnd === - 1
162
+ ? [ ]
163
+ : cellWidths !
164
+ . slice ( firstStickyEnd )
165
+ . map ( ( width , index ) => ( stickyEndStates [ index + firstStickyEnd ] ? width : null ) )
166
+ . reverse ( ) ,
167
+ } ) ;
168
+ }
169
+ } ) ;
171
170
} ) ;
172
171
}
173
172
@@ -188,9 +187,7 @@ export class StickyStyler {
188
187
return ;
189
188
}
190
189
191
- // Coalesce with other sticky row updates (top/bottom), sticky columns updates
192
- // (and potentially other changes like column resize).
193
- this . _coalescedStyleScheduler . schedule ( ( ) => {
190
+ this . _coalescedStyleScheduler . scheduleEarlyRead ( ( ) => {
194
191
// If positioning the rows to the bottom, reverse their order when evaluating the sticky
195
192
// position such that the last row stuck will be "bottom: 0px" and so on. Note that the
196
193
// sticky states need to be reversed as well.
@@ -219,32 +216,33 @@ export class StickyStyler {
219
216
}
220
217
221
218
const borderedRowIndex = states . lastIndexOf ( true ) ;
219
+ this . _coalescedStyleScheduler . scheduleWrite ( ( ) => {
220
+ for ( let rowIndex = 0 ; rowIndex < rows . length ; rowIndex ++ ) {
221
+ if ( ! states [ rowIndex ] ) {
222
+ continue ;
223
+ }
222
224
223
- for ( let rowIndex = 0 ; rowIndex < rows . length ; rowIndex ++ ) {
224
- if ( ! states [ rowIndex ] ) {
225
- continue ;
225
+ const offset = stickyOffsets [ rowIndex ] ;
226
+ const isBorderedRowIndex = rowIndex === borderedRowIndex ;
227
+ for ( const element of elementsToStick [ rowIndex ] ) {
228
+ this . _addStickyStyle ( element , position , offset , isBorderedRowIndex ) ;
229
+ }
226
230
}
227
231
228
- const offset = stickyOffsets [ rowIndex ] ;
229
- const isBorderedRowIndex = rowIndex === borderedRowIndex ;
230
- for ( const element of elementsToStick [ rowIndex ] ) {
231
- this . _addStickyStyle ( element , position , offset , isBorderedRowIndex ) ;
232
+ if ( position === 'top' ) {
233
+ this . _positionListener ?. stickyHeaderRowsUpdated ( {
234
+ sizes : stickyCellHeights ,
235
+ offsets : stickyOffsets ,
236
+ elements : elementsToStick ,
237
+ } ) ;
238
+ } else {
239
+ this . _positionListener ?. stickyFooterRowsUpdated ( {
240
+ sizes : stickyCellHeights ,
241
+ offsets : stickyOffsets ,
242
+ elements : elementsToStick ,
243
+ } ) ;
232
244
}
233
- }
234
-
235
- if ( position === 'top' ) {
236
- this . _positionListener ?. stickyHeaderRowsUpdated ( {
237
- sizes : stickyCellHeights ,
238
- offsets : stickyOffsets ,
239
- elements : elementsToStick ,
240
- } ) ;
241
- } else {
242
- this . _positionListener ?. stickyFooterRowsUpdated ( {
243
- sizes : stickyCellHeights ,
244
- offsets : stickyOffsets ,
245
- elements : elementsToStick ,
246
- } ) ;
247
- }
245
+ } ) ;
248
246
} ) ;
249
247
}
250
248
@@ -260,7 +258,7 @@ export class StickyStyler {
260
258
}
261
259
262
260
// Coalesce with other sticky updates (and potentially other changes like column resize).
263
- this . _coalescedStyleScheduler . schedule ( ( ) => {
261
+ this . _coalescedStyleScheduler . scheduleWrite ( ( ) => {
264
262
const tfoot = tableElement . querySelector ( 'tfoot' ) ! ;
265
263
266
264
if ( stickyStates . some ( state => ! state ) ) {
0 commit comments