/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * List of all possible directions that can be used for sticky positioning. * @docs-private */ export const STICKY_DIRECTIONS = ['top', 'bottom', 'left', 'right']; /** * Applies and removes sticky positioning styles to the `CdkTable` rows and columns cells. * @docs-private */ export class StickyStyler { /** * @param _isNativeHtmlTable Whether the sticky logic should be based on a table * that uses the native `` element. * @param _stickCellCss The CSS class that will be applied to every row/cell that has * sticky positioning applied. * @param direction The directionality context of the table (ltr/rtl); affects column positioning * by reversing left/right positions. * @param _isBrowser Whether the table is currently being rendered on the server or the client. * @param _needsPositionStickyOnElement Whether we need to specify position: sticky on cells * using inline styles. If false, it is assumed that position: sticky is included in * the component stylesheet for _stickCellCss. * @param _positionListener A listener that is notified of changes to sticky rows/columns * and their dimensions. */ constructor(_isNativeHtmlTable, _stickCellCss, direction, _coalescedStyleScheduler, _isBrowser = true, _needsPositionStickyOnElement = true, _positionListener) { this._isNativeHtmlTable = _isNativeHtmlTable; this._stickCellCss = _stickCellCss; this.direction = direction; this._coalescedStyleScheduler = _coalescedStyleScheduler; this._isBrowser = _isBrowser; this._needsPositionStickyOnElement = _needsPositionStickyOnElement; this._positionListener = _positionListener; this._cachedCellWidths = []; this._borderCellCss = { 'top': `${_stickCellCss}-border-elem-top`, 'bottom': `${_stickCellCss}-border-elem-bottom`, 'left': `${_stickCellCss}-border-elem-left`, 'right': `${_stickCellCss}-border-elem-right`, }; } /** * Clears the sticky positioning styles from the row and its cells by resetting the `position` * style, setting the zIndex to 0, and unsetting each provided sticky direction. * @param rows The list of rows that should be cleared from sticking in the provided directions * @param stickyDirections The directions that should no longer be set as sticky on the rows. */ clearStickyPositioning(rows, stickyDirections) { const elementsToClear = []; for (const row of rows) { // If the row isn't an element (e.g. if it's an `ng-container`), // it won't have inline styles or `children` so we skip it. if (row.nodeType !== row.ELEMENT_NODE) { continue; } elementsToClear.push(row); for (let i = 0; i < row.children.length; i++) { elementsToClear.push(row.children[i]); } } // Coalesce with sticky row/column updates (and potentially other changes like column resize). this._coalescedStyleScheduler.schedule(() => { for (const element of elementsToClear) { this._removeStickyStyle(element, stickyDirections); } }); } /** * Applies sticky left and right positions to the cells of each row according to the sticky * states of the rendered column definitions. * @param rows The rows that should have its set of cells stuck according to the sticky states. * @param stickyStartStates A list of boolean states where each state represents whether the cell * in this index position should be stuck to the start of the row. * @param stickyEndStates A list of boolean states where each state represents whether the cell * in this index position should be stuck to the end of the row. * @param recalculateCellWidths Whether the sticky styler should recalculate the width of each * column cell. If `false` cached widths will be used instead. */ updateStickyColumns(rows, stickyStartStates, stickyEndStates, recalculateCellWidths = true) { if (!rows.length || !this._isBrowser || !(stickyStartStates.some(state => state) || stickyEndStates.some(state => state))) { if (this._positionListener) { this._positionListener.stickyColumnsUpdated({ sizes: [] }); this._positionListener.stickyEndColumnsUpdated({ sizes: [] }); } return; } const firstRow = rows[0]; const numCells = firstRow.children.length; const cellWidths = this._getCellWidths(firstRow, recalculateCellWidths); const startPositions = this._getStickyStartColumnPositions(cellWidths, stickyStartStates); const endPositions = this._getStickyEndColumnPositions(cellWidths, stickyEndStates); const lastStickyStart = stickyStartStates.lastIndexOf(true); const firstStickyEnd = stickyEndStates.indexOf(true); // Coalesce with sticky row updates (and potentially other changes like column resize). this._coalescedStyleScheduler.schedule(() => { const isRtl = this.direction === 'rtl'; const start = isRtl ? 'right' : 'left'; const end = isRtl ? 'left' : 'right'; for (const row of rows) { for (let i = 0; i < numCells; i++) { const cell = row.children[i]; if (stickyStartStates[i]) { this._addStickyStyle(cell, start, startPositions[i], i === lastStickyStart); } if (stickyEndStates[i]) { this._addStickyStyle(cell, end, endPositions[i], i === firstStickyEnd); } } } if (this._positionListener) { this._positionListener.stickyColumnsUpdated({ sizes: lastStickyStart === -1 ? [] : cellWidths .slice(0, lastStickyStart + 1) .map((width, index) => (stickyStartStates[index] ? width : null)), }); this._positionListener.stickyEndColumnsUpdated({ sizes: firstStickyEnd === -1 ? [] : cellWidths .slice(firstStickyEnd) .map((width, index) => (stickyEndStates[index + firstStickyEnd] ? width : null)) .reverse(), }); } }); } /** * Applies sticky positioning to the row's cells if using the native table layout, and to the * row itself otherwise. * @param rowsToStick The list of rows that should be stuck according to their corresponding * sticky state and to the provided top or bottom position. * @param stickyStates A list of boolean states where each state represents whether the row * should be stuck in the particular top or bottom position. * @param position The position direction in which the row should be stuck if that row should be * sticky. * */ stickRows(rowsToStick, stickyStates, position) { // Since we can't measure the rows on the server, we can't stick the rows properly. if (!this._isBrowser) { return; } // If positioning the rows to the bottom, reverse their order when evaluating the sticky // position such that the last row stuck will be "bottom: 0px" and so on. Note that the // sticky states need to be reversed as well. const rows = position === 'bottom' ? rowsToStick.slice().reverse() : rowsToStick; const states = position === 'bottom' ? stickyStates.slice().reverse() : stickyStates; // Measure row heights all at once before adding sticky styles to reduce layout thrashing. const stickyOffsets = []; const stickyCellHeights = []; const elementsToStick = []; for (let rowIndex = 0, stickyOffset = 0; rowIndex < rows.length; rowIndex++) { if (!states[rowIndex]) { continue; } stickyOffsets[rowIndex] = stickyOffset; const row = rows[rowIndex]; elementsToStick[rowIndex] = this._isNativeHtmlTable ? Array.from(row.children) : [row]; const height = row.getBoundingClientRect().height; stickyOffset += height; stickyCellHeights[rowIndex] = height; } const borderedRowIndex = states.lastIndexOf(true); // Coalesce with other sticky row updates (top/bottom), sticky columns updates // (and potentially other changes like column resize). this._coalescedStyleScheduler.schedule(() => { for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) { if (!states[rowIndex]) { continue; } const offset = stickyOffsets[rowIndex]; const isBorderedRowIndex = rowIndex === borderedRowIndex; for (const element of elementsToStick[rowIndex]) { this._addStickyStyle(element, position, offset, isBorderedRowIndex); } } if (position === 'top') { this._positionListener?.stickyHeaderRowsUpdated({ sizes: stickyCellHeights, offsets: stickyOffsets, elements: elementsToStick, }); } else { this._positionListener?.stickyFooterRowsUpdated({ sizes: stickyCellHeights, offsets: stickyOffsets, elements: elementsToStick, }); } }); } /** * When using the native table in Safari, sticky footer cells do not stick. The only way to stick * footer rows is to apply sticky styling to the tfoot container. This should only be done if * all footer rows are sticky. If not all footer rows are sticky, remove sticky positioning from * the tfoot element. */ updateStickyFooterContainer(tableElement, stickyStates) { if (!this._isNativeHtmlTable) { return; } const tfoot = tableElement.querySelector('tfoot'); // Coalesce with other sticky updates (and potentially other changes like column resize). this._coalescedStyleScheduler.schedule(() => { if (stickyStates.some(state => !state)) { this._removeStickyStyle(tfoot, ['bottom']); } else { this._addStickyStyle(tfoot, 'bottom', 0, false); } }); } /** * Removes the sticky style on the element by removing the sticky cell CSS class, re-evaluating * the zIndex, removing each of the provided sticky directions, and removing the * sticky position if there are no more directions. */ _removeStickyStyle(element, stickyDirections) { for (const dir of stickyDirections) { element.style[dir] = ''; element.classList.remove(this._borderCellCss[dir]); } // If the element no longer has any more sticky directions, remove sticky positioning and // the sticky CSS class. // Short-circuit checking element.style[dir] for stickyDirections as they // were already removed above. const hasDirection = STICKY_DIRECTIONS.some(dir => stickyDirections.indexOf(dir) === -1 && element.style[dir]); if (hasDirection) { element.style.zIndex = this._getCalculatedZIndex(element); } else { // When not hasDirection, _getCalculatedZIndex will always return ''. element.style.zIndex = ''; if (this._needsPositionStickyOnElement) { element.style.position = ''; } element.classList.remove(this._stickCellCss); } } /** * Adds the sticky styling to the element by adding the sticky style class, changing position * to be sticky (and -webkit-sticky), setting the appropriate zIndex, and adding a sticky * direction and value. */ _addStickyStyle(element, dir, dirValue, isBorderElement) { element.classList.add(this._stickCellCss); if (isBorderElement) { element.classList.add(this._borderCellCss[dir]); } element.style[dir] = `${dirValue}px`; element.style.zIndex = this._getCalculatedZIndex(element); if (this._needsPositionStickyOnElement) { element.style.cssText += 'position: -webkit-sticky; position: sticky; '; } } /** * Calculate what the z-index should be for the element, depending on what directions (top, * bottom, left, right) have been set. It should be true that elements with a top direction * should have the highest index since these are elements like a table header. If any of those * elements are also sticky in another direction, then they should appear above other elements * that are only sticky top (e.g. a sticky column on a sticky header). Bottom-sticky elements * (e.g. footer rows) should then be next in the ordering such that they are below the header * but above any non-sticky elements. Finally, left/right sticky elements (e.g. sticky columns) * should minimally increment so that they are above non-sticky elements but below top and bottom * elements. */ _getCalculatedZIndex(element) { const zIndexIncrements = { top: 100, bottom: 10, left: 1, right: 1, }; let zIndex = 0; // Use `Iterable` instead of `Array` because TypeScript, as of 3.6.3, // loses the array generic type in the `for of`. But we *also* have to use `Array` because // typescript won't iterate over an `Iterable` unless you compile with `--downlevelIteration` for (const dir of STICKY_DIRECTIONS) { if (element.style[dir]) { zIndex += zIndexIncrements[dir]; } } return zIndex ? `${zIndex}` : ''; } /** Gets the widths for each cell in the provided row. */ _getCellWidths(row, recalculateCellWidths = true) { if (!recalculateCellWidths && this._cachedCellWidths.length) { return this._cachedCellWidths; } const cellWidths = []; const firstRowCells = row.children; for (let i = 0; i < firstRowCells.length; i++) { let cell = firstRowCells[i]; cellWidths.push(cell.getBoundingClientRect().width); } this._cachedCellWidths = cellWidths; return cellWidths; } /** * Determines the left and right positions of each sticky column cell, which will be the * accumulation of all sticky column cell widths to the left and right, respectively. * Non-sticky cells do not need to have a value set since their positions will not be applied. */ _getStickyStartColumnPositions(widths, stickyStates) { const positions = []; let nextPosition = 0; for (let i = 0; i < widths.length; i++) { if (stickyStates[i]) { positions[i] = nextPosition; nextPosition += widths[i]; } } return positions; } /** * Determines the left and right positions of each sticky column cell, which will be the * accumulation of all sticky column cell widths to the left and right, respectively. * Non-sticky cells do not need to have a value set since their positions will not be applied. */ _getStickyEndColumnPositions(widths, stickyStates) { const positions = []; let nextPosition = 0; for (let i = widths.length; i > 0; i--) { if (stickyStates[i]) { positions[i] = nextPosition; nextPosition += widths[i]; } } return positions; } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RpY2t5LXN0eWxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4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RoaXMuX2FkZFN0aWNreVN0eWxlKGNlbGwsIGVuZCwgZW5kUG9zaXRpb25zW2ldLCBpID09PSBmaXJzdFN0aWNreUVuZCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIGlmICh0aGlzLl9wb3NpdGlvbkxpc3RlbmVyKSB7XG4gICAgICAgIHRoaXMuX3Bvc2l0aW9uTGlzdGVuZXIuc3RpY2t5Q29sdW1uc1VwZGF0ZWQoe1xuICAgICAgICAgIHNpemVzOlxuICAgICAgICAgICAgbGFzdFN0aWNreVN0YXJ0ID09PSAtMVxuICAgICAgICAgICAgICA/IFtdXG4gICAgICAgICAgICAgIDogY2VsbFdpZHRoc1xuICAgICAgICAgICAgICAgICAgLnNsaWNlKDAsIGxhc3RTdGlja3lTdGFydCArIDEpXG4gICAgICAgICAgICAgICAgICAubWFwKCh3aWR0aCwgaW5kZXgpID0+IChzdGlja3lTdGFydFN0YXRlc1tpbmRleF0gPyB3aWR0aCA6IG51bGwpKSxcbiAgICAgICAgfSk7XG4gICAgICAgIHRoaXMuX3Bvc2l0aW9uTGlzdGVuZXIuc3RpY2t5RW5kQ29sdW1uc1VwZGF0ZWQoe1xuICAgICAgICAgIHNpemVzOlxuICAgICAgICAgICAgZmlyc3RTdGlja3lFbmQgPT09IC0xXG4gICAgICAgICAgICAgID8gW11cbiAgICAgICAgICAgICAgOiBjZWxsV2lkdGhzXG4gICAgICAgICAgICAgICAgICAuc2xpY2UoZmlyc3RTdGlja3lFbmQpXG4gICAgICAgICAgICAgICAgICAubWFwKCh3aWR0aCwgaW5kZXgpID0+IChzdGlja3lFbmRTdGF0ZXNbaW5kZXggKyBmaXJzdFN0aWNreUVuZF0gPyB3aWR0aCA6IG51bGwpKVxuICAgICAgICAgICAgICAgICAgLnJldmVyc2UoKSxcbiAgICAgICAgfSk7XG4gICAgICB9XG4gICAgfSk7XG4gIH1cblxuICAvKipcbiAgICogQXBwbGllcyBzdGlja3kgcG9zaXRpb25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