es-grid-template
Version:
es-grid-template
30 lines • 903 B
JavaScript
/**
* During table cell rendering, the colSpan/rowSpan of previously rendered cells
* affects whether subsequent cells should be rendered.
*
* `SpanManager` internally maintains a state that records the colSpan/rowSpan
* of the most recently rendered cells, allowing subsequent cells to quickly
* determine whether they should skip rendering.
*/
export default class SpanManager {
rects = [];
testSkip(rowIndex, colIndex) {
return this.rects.some(({
left,
right,
top,
bottom
}) => left <= colIndex && colIndex < right && top <= rowIndex && rowIndex < bottom);
}
stripUpwards(rowIndex) {
this.rects = this.rects.filter(rect => rect.bottom > rowIndex);
}
add(rowIndex, colIndex, colSpan, rowSpan) {
this.rects.push({
left: colIndex,
right: colIndex + colSpan,
top: rowIndex,
bottom: rowIndex + rowSpan
});
}
}