@angular/cdk
Version:
Angular Material Component Development Kit
1,477 lines (1,470 loc) • 107 kB
JavaScript
import { Directionality } from '@angular/cdk/bidi';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { isDataSource } from '@angular/cdk/collections';
export { DataSource } from '@angular/cdk/collections';
import { Platform } from '@angular/cdk/platform';
import { DOCUMENT, CommonModule } from '@angular/common';
import { Directive, TemplateRef, Input, ContentChild, ElementRef, IterableDiffers, ViewContainerRef, Component, ChangeDetectionStrategy, ViewEncapsulation, EmbeddedViewRef, isDevMode, ChangeDetectorRef, Attribute, Optional, Inject, ViewChild, ContentChildren, InjectionToken, NgModule } from '@angular/core';
import { Subject, BehaviorSubject, Observable, of } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
/**
* @fileoverview added by tsickle
* Generated from: src/cdk/table/can-stick.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Interface for a mixin to provide a directive with a function that checks if the sticky input has
* been changed since the last time the function was called. Essentially adds a dirty-check to the
* sticky value.
* \@docs-private
* @record
*/
function CanStick() { }
if (false) {
/**
* Whether sticky positioning should be applied.
* @type {?}
*/
CanStick.prototype.sticky;
/**
* Whether the sticky input has changed since it was last checked.
* @type {?}
*/
CanStick.prototype._hasStickyChanged;
/**
* Whether the sticky value has changed since this was last called.
* @return {?}
*/
CanStick.prototype.hasStickyChanged = function () { };
/**
* Resets the dirty check for cases where the sticky state has been used without checking.
* @return {?}
*/
CanStick.prototype.resetStickyChanged = function () { };
}
/**
* Mixin to provide a directive with a function that checks if the sticky input has been
* changed since the last time the function was called. Essentially adds a dirty-check to the
* sticky value.
* \@docs-private
* @template T
* @param {?} base
* @return {?}
*/
function mixinHasStickyInput(base) {
return class extends base {
/**
* @param {...?} args
*/
constructor(...args) {
super(...args);
this._sticky = false;
/**
* Whether the sticky input has changed since it was last checked.
*/
this._hasStickyChanged = false;
}
/**
* Whether sticky positioning should be applied.
* @return {?}
*/
get sticky() { return this._sticky; }
/**
* @param {?} v
* @return {?}
*/
set sticky(v) {
/** @type {?} */
const prevValue = this._sticky;
this._sticky = coerceBooleanProperty(v);
this._hasStickyChanged = prevValue !== this._sticky;
}
/**
* Whether the sticky value has changed since this was last called.
* @return {?}
*/
hasStickyChanged() {
/** @type {?} */
const hasStickyChanged = this._hasStickyChanged;
this._hasStickyChanged = false;
return hasStickyChanged;
}
/**
* Resets the dirty check for cases where the sticky state has been used without checking.
* @return {?}
*/
resetStickyChanged() {
this._hasStickyChanged = false;
}
};
}
/**
* @fileoverview added by tsickle
* Generated from: src/cdk/table/cell.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Base interface for a cell definition. Captures a column's cell template definition.
* @record
*/
function CellDef() { }
if (false) {
/** @type {?} */
CellDef.prototype.template;
}
/**
* Cell definition for a CDK table.
* Captures the template of a column's data row cell as well as cell-specific properties.
*/
class CdkCellDef {
/**
* @param {?} template
*/
constructor(/** @docs-private */ template) {
this.template = template;
}
}
CdkCellDef.decorators = [
{ type: Directive, args: [{ selector: '[cdkCellDef]' },] }
];
/** @nocollapse */
CdkCellDef.ctorParameters = () => [
{ type: TemplateRef }
];
if (false) {
/**
* \@docs-private
* @type {?}
*/
CdkCellDef.prototype.template;
}
/**
* Header cell definition for a CDK table.
* Captures the template of a column's header cell and as well as cell-specific properties.
*/
class CdkHeaderCellDef {
/**
* @param {?} template
*/
constructor(/** @docs-private */ template) {
this.template = template;
}
}
CdkHeaderCellDef.decorators = [
{ type: Directive, args: [{ selector: '[cdkHeaderCellDef]' },] }
];
/** @nocollapse */
CdkHeaderCellDef.ctorParameters = () => [
{ type: TemplateRef }
];
if (false) {
/**
* \@docs-private
* @type {?}
*/
CdkHeaderCellDef.prototype.template;
}
/**
* Footer cell definition for a CDK table.
* Captures the template of a column's footer cell and as well as cell-specific properties.
*/
class CdkFooterCellDef {
/**
* @param {?} template
*/
constructor(/** @docs-private */ template) {
this.template = template;
}
}
CdkFooterCellDef.decorators = [
{ type: Directive, args: [{ selector: '[cdkFooterCellDef]' },] }
];
/** @nocollapse */
CdkFooterCellDef.ctorParameters = () => [
{ type: TemplateRef }
];
if (false) {
/**
* \@docs-private
* @type {?}
*/
CdkFooterCellDef.prototype.template;
}
// Boilerplate for applying mixins to CdkColumnDef.
/**
* \@docs-private
*/
class CdkColumnDefBase {
}
/** @type {?} */
const _CdkColumnDefBase = mixinHasStickyInput(CdkColumnDefBase);
/**
* Column definition for the CDK table.
* Defines a set of cells available for a table column.
*/
class CdkColumnDef extends _CdkColumnDefBase {
constructor() {
super(...arguments);
this._stickyEnd = false;
}
/**
* Unique name for this column.
* @return {?}
*/
get name() {
return this._name;
}
/**
* @param {?} name
* @return {?}
*/
set name(name) {
// If the directive is set without a name (updated programatically), then this setter will
// trigger with an empty string and should not overwrite the programatically set value.
if (!name) {
return;
}
this._name = name;
this.cssClassFriendlyName = name.replace(/[^a-z0-9_-]/ig, '-');
}
/**
* Whether this column should be sticky positioned on the end of the row. Should make sure
* that it mimics the `CanStick` mixin such that `_hasStickyChanged` is set to true if the value
* has been changed.
* @return {?}
*/
get stickyEnd() {
return this._stickyEnd;
}
/**
* @param {?} v
* @return {?}
*/
set stickyEnd(v) {
/** @type {?} */
const prevValue = this._stickyEnd;
this._stickyEnd = coerceBooleanProperty(v);
this._hasStickyChanged = prevValue !== this._stickyEnd;
}
}
CdkColumnDef.decorators = [
{ type: Directive, args: [{
selector: '[cdkColumnDef]',
inputs: ['sticky'],
providers: [{ provide: 'MAT_SORT_HEADER_COLUMN_DEF', useExisting: CdkColumnDef }],
},] }
];
CdkColumnDef.propDecorators = {
name: [{ type: Input, args: ['cdkColumnDef',] }],
stickyEnd: [{ type: Input, args: ['stickyEnd',] }],
cell: [{ type: ContentChild, args: [CdkCellDef,] }],
headerCell: [{ type: ContentChild, args: [CdkHeaderCellDef,] }],
footerCell: [{ type: ContentChild, args: [CdkFooterCellDef,] }]
};
if (false) {
/** @type {?} */
CdkColumnDef.ngAcceptInputType_sticky;
/** @type {?} */
CdkColumnDef.ngAcceptInputType_stickyEnd;
/** @type {?} */
CdkColumnDef.prototype._name;
/** @type {?} */
CdkColumnDef.prototype._stickyEnd;
/**
* \@docs-private
* @type {?}
*/
CdkColumnDef.prototype.cell;
/**
* \@docs-private
* @type {?}
*/
CdkColumnDef.prototype.headerCell;
/**
* \@docs-private
* @type {?}
*/
CdkColumnDef.prototype.footerCell;
/**
* Transformed version of the column name that can be used as part of a CSS classname. Excludes
* all non-alphanumeric characters and the special characters '-' and '_'. Any characters that
* do not match are replaced by the '-' character.
* @type {?}
*/
CdkColumnDef.prototype.cssClassFriendlyName;
}
/**
* Base class for the cells. Adds a CSS classname that identifies the column it renders in.
*/
class BaseCdkCell {
/**
* @param {?} columnDef
* @param {?} elementRef
*/
constructor(columnDef, elementRef) {
/** @type {?} */
const columnClassName = `cdk-column-${columnDef.cssClassFriendlyName}`;
elementRef.nativeElement.classList.add(columnClassName);
}
}
/**
* Header cell template container that adds the right classes and role.
*/
class CdkHeaderCell extends BaseCdkCell {
/**
* @param {?} columnDef
* @param {?} elementRef
*/
constructor(columnDef, elementRef) {
super(columnDef, elementRef);
}
}
CdkHeaderCell.decorators = [
{ type: Directive, args: [{
selector: 'cdk-header-cell, th[cdk-header-cell]',
host: {
'class': 'cdk-header-cell',
'role': 'columnheader',
},
},] }
];
/** @nocollapse */
CdkHeaderCell.ctorParameters = () => [
{ type: CdkColumnDef },
{ type: ElementRef }
];
/**
* Footer cell template container that adds the right classes and role.
*/
class CdkFooterCell extends BaseCdkCell {
/**
* @param {?} columnDef
* @param {?} elementRef
*/
constructor(columnDef, elementRef) {
super(columnDef, elementRef);
}
}
CdkFooterCell.decorators = [
{ type: Directive, args: [{
selector: 'cdk-footer-cell, td[cdk-footer-cell]',
host: {
'class': 'cdk-footer-cell',
'role': 'gridcell',
},
},] }
];
/** @nocollapse */
CdkFooterCell.ctorParameters = () => [
{ type: CdkColumnDef },
{ type: ElementRef }
];
/**
* Cell template container that adds the right classes and role.
*/
class CdkCell extends BaseCdkCell {
/**
* @param {?} columnDef
* @param {?} elementRef
*/
constructor(columnDef, elementRef) {
super(columnDef, elementRef);
}
}
CdkCell.decorators = [
{ type: Directive, args: [{
selector: 'cdk-cell, td[cdk-cell]',
host: {
'class': 'cdk-cell',
'role': 'gridcell',
},
},] }
];
/** @nocollapse */
CdkCell.ctorParameters = () => [
{ type: CdkColumnDef },
{ type: ElementRef }
];
/**
* @fileoverview added by tsickle
* Generated from: src/cdk/table/row.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* The row template that can be used by the mat-table. Should not be used outside of the
* material library.
* @type {?}
*/
const CDK_ROW_TEMPLATE = `<ng-container cdkCellOutlet></ng-container>`;
/**
* Base class for the CdkHeaderRowDef and CdkRowDef that handles checking their columns inputs
* for changes and notifying the table.
* @abstract
*/
class BaseRowDef {
/**
* @param {?} template
* @param {?} _differs
*/
constructor(template, _differs) {
this.template = template;
this._differs = _differs;
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
// Create a new columns differ if one does not yet exist. Initialize it based on initial value
// of the columns property or an empty array if none is provided.
if (!this._columnsDiffer) {
/** @type {?} */
const columns = (changes['columns'] && changes['columns'].currentValue) || [];
this._columnsDiffer = this._differs.find(columns).create();
this._columnsDiffer.diff(columns);
}
}
/**
* Returns the difference between the current columns and the columns from the last diff, or null
* if there is no difference.
* @return {?}
*/
getColumnsDiff() {
return this._columnsDiffer.diff(this.columns);
}
/**
* Gets this row def's relevant cell template from the provided column def.
* @param {?} column
* @return {?}
*/
extractCellTemplate(column) {
if (this instanceof CdkHeaderRowDef) {
return column.headerCell.template;
}
if (this instanceof CdkFooterRowDef) {
return column.footerCell.template;
}
else {
return column.cell.template;
}
}
}
if (false) {
/**
* The columns to be displayed on this row.
* @type {?}
*/
BaseRowDef.prototype.columns;
/**
* Differ used to check if any changes were made to the columns.
* @type {?}
* @protected
*/
BaseRowDef.prototype._columnsDiffer;
/**
* \@docs-private
* @type {?}
*/
BaseRowDef.prototype.template;
/**
* @type {?}
* @protected
*/
BaseRowDef.prototype._differs;
}
// Boilerplate for applying mixins to CdkHeaderRowDef.
/**
* \@docs-private
*/
class CdkHeaderRowDefBase extends BaseRowDef {
}
/** @type {?} */
const _CdkHeaderRowDefBase = mixinHasStickyInput(CdkHeaderRowDefBase);
/**
* Header row definition for the CDK table.
* Captures the header row's template and other header properties such as the columns to display.
*/
class CdkHeaderRowDef extends _CdkHeaderRowDefBase {
/**
* @param {?} template
* @param {?} _differs
*/
constructor(template, _differs) {
super(template, _differs);
}
// Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
// Explicitly define it so that the method is called as part of the Angular lifecycle.
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
super.ngOnChanges(changes);
}
}
CdkHeaderRowDef.decorators = [
{ type: Directive, args: [{
selector: '[cdkHeaderRowDef]',
inputs: ['columns: cdkHeaderRowDef', 'sticky: cdkHeaderRowDefSticky'],
},] }
];
/** @nocollapse */
CdkHeaderRowDef.ctorParameters = () => [
{ type: TemplateRef },
{ type: IterableDiffers }
];
if (false) {
/** @type {?} */
CdkHeaderRowDef.ngAcceptInputType_sticky;
}
// Boilerplate for applying mixins to CdkFooterRowDef.
/**
* \@docs-private
*/
class CdkFooterRowDefBase extends BaseRowDef {
}
/** @type {?} */
const _CdkFooterRowDefBase = mixinHasStickyInput(CdkFooterRowDefBase);
/**
* Footer row definition for the CDK table.
* Captures the footer row's template and other footer properties such as the columns to display.
*/
class CdkFooterRowDef extends _CdkFooterRowDefBase {
/**
* @param {?} template
* @param {?} _differs
*/
constructor(template, _differs) {
super(template, _differs);
}
// Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
// Explicitly define it so that the method is called as part of the Angular lifecycle.
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
super.ngOnChanges(changes);
}
}
CdkFooterRowDef.decorators = [
{ type: Directive, args: [{
selector: '[cdkFooterRowDef]',
inputs: ['columns: cdkFooterRowDef', 'sticky: cdkFooterRowDefSticky'],
},] }
];
/** @nocollapse */
CdkFooterRowDef.ctorParameters = () => [
{ type: TemplateRef },
{ type: IterableDiffers }
];
if (false) {
/** @type {?} */
CdkFooterRowDef.ngAcceptInputType_sticky;
}
/**
* Data row definition for the CDK table.
* Captures the header row's template and other row properties such as the columns to display and
* a when predicate that describes when this row should be used.
* @template T
*/
class CdkRowDef extends BaseRowDef {
// TODO(andrewseguin): Add an input for providing a switch function to determine
// if this template should be used.
/**
* @param {?} template
* @param {?} _differs
*/
constructor(template, _differs) {
super(template, _differs);
}
}
CdkRowDef.decorators = [
{ type: Directive, args: [{
selector: '[cdkRowDef]',
inputs: ['columns: cdkRowDefColumns', 'when: cdkRowDefWhen'],
},] }
];
/** @nocollapse */
CdkRowDef.ctorParameters = () => [
{ type: TemplateRef },
{ type: IterableDiffers }
];
if (false) {
/**
* Function that should return true if this row template should be used for the provided index
* and row data. If left undefined, this row will be considered the default row template to use
* when no other when functions return true for the data.
* For every row, there must be at least one when function that passes or an undefined to default.
* @type {?}
*/
CdkRowDef.prototype.when;
}
/**
* Context provided to the row cells when `multiTemplateDataRows` is false
* @record
* @template T
*/
function CdkCellOutletRowContext() { }
if (false) {
/**
* Data for the row that this cell is located within.
* @type {?|undefined}
*/
CdkCellOutletRowContext.prototype.$implicit;
/**
* Index of the data object in the provided data array.
* @type {?|undefined}
*/
CdkCellOutletRowContext.prototype.index;
/**
* Length of the number of total rows.
* @type {?|undefined}
*/
CdkCellOutletRowContext.prototype.count;
/**
* True if this cell is contained in the first row.
* @type {?|undefined}
*/
CdkCellOutletRowContext.prototype.first;
/**
* True if this cell is contained in the last row.
* @type {?|undefined}
*/
CdkCellOutletRowContext.prototype.last;
/**
* True if this cell is contained in a row with an even-numbered index.
* @type {?|undefined}
*/
CdkCellOutletRowContext.prototype.even;
/**
* True if this cell is contained in a row with an odd-numbered index.
* @type {?|undefined}
*/
CdkCellOutletRowContext.prototype.odd;
}
/**
* Context provided to the row cells when `multiTemplateDataRows` is true. This context is the same
* as CdkCellOutletRowContext except that the single `index` value is replaced by `dataIndex` and
* `renderIndex`.
* @record
* @template T
*/
function CdkCellOutletMultiRowContext() { }
if (false) {
/**
* Data for the row that this cell is located within.
* @type {?|undefined}
*/
CdkCellOutletMultiRowContext.prototype.$implicit;
/**
* Index of the data object in the provided data array.
* @type {?|undefined}
*/
CdkCellOutletMultiRowContext.prototype.dataIndex;
/**
* Index location of the rendered row that this cell is located within.
* @type {?|undefined}
*/
CdkCellOutletMultiRowContext.prototype.renderIndex;
/**
* Length of the number of total rows.
* @type {?|undefined}
*/
CdkCellOutletMultiRowContext.prototype.count;
/**
* True if this cell is contained in the first row.
* @type {?|undefined}
*/
CdkCellOutletMultiRowContext.prototype.first;
/**
* True if this cell is contained in the last row.
* @type {?|undefined}
*/
CdkCellOutletMultiRowContext.prototype.last;
/**
* True if this cell is contained in a row with an even-numbered index.
* @type {?|undefined}
*/
CdkCellOutletMultiRowContext.prototype.even;
/**
* True if this cell is contained in a row with an odd-numbered index.
* @type {?|undefined}
*/
CdkCellOutletMultiRowContext.prototype.odd;
}
/**
* Outlet for rendering cells inside of a row or header row.
* \@docs-private
*/
class CdkCellOutlet {
/**
* @param {?} _viewContainer
*/
constructor(_viewContainer) {
this._viewContainer = _viewContainer;
CdkCellOutlet.mostRecentCellOutlet = this;
}
/**
* @return {?}
*/
ngOnDestroy() {
// If this was the last outlet being rendered in the view, remove the reference
// from the static property after it has been destroyed to avoid leaking memory.
if (CdkCellOutlet.mostRecentCellOutlet === this) {
CdkCellOutlet.mostRecentCellOutlet = null;
}
}
}
/**
* Static property containing the latest constructed instance of this class.
* Used by the CDK table when each CdkHeaderRow and CdkRow component is created using
* createEmbeddedView. After one of these components are created, this property will provide
* a handle to provide that component's cells and context. After init, the CdkCellOutlet will
* construct the cells with the provided context.
*/
CdkCellOutlet.mostRecentCellOutlet = null;
CdkCellOutlet.decorators = [
{ type: Directive, args: [{ selector: '[cdkCellOutlet]' },] }
];
/** @nocollapse */
CdkCellOutlet.ctorParameters = () => [
{ type: ViewContainerRef }
];
if (false) {
/**
* Static property containing the latest constructed instance of this class.
* Used by the CDK table when each CdkHeaderRow and CdkRow component is created using
* createEmbeddedView. After one of these components are created, this property will provide
* a handle to provide that component's cells and context. After init, the CdkCellOutlet will
* construct the cells with the provided context.
* @type {?}
*/
CdkCellOutlet.mostRecentCellOutlet;
/**
* The ordered list of cells to render within this outlet's view container
* @type {?}
*/
CdkCellOutlet.prototype.cells;
/**
* The data context to be provided to each cell
* @type {?}
*/
CdkCellOutlet.prototype.context;
/** @type {?} */
CdkCellOutlet.prototype._viewContainer;
}
/**
* Header template container that contains the cell outlet. Adds the right class and role.
*/
class CdkHeaderRow {
}
CdkHeaderRow.decorators = [
{ type: Component, args: [{
selector: 'cdk-header-row, tr[cdk-header-row]',
template: CDK_ROW_TEMPLATE,
host: {
'class': 'cdk-header-row',
'role': 'row',
},
// See note on CdkTable for explanation on why this uses the default change detection strategy.
// tslint:disable-next-line:validate-decorators
changeDetection: ChangeDetectionStrategy.Default,
encapsulation: ViewEncapsulation.None
}] }
];
/**
* Footer template container that contains the cell outlet. Adds the right class and role.
*/
class CdkFooterRow {
}
CdkFooterRow.decorators = [
{ type: Component, args: [{
selector: 'cdk-footer-row, tr[cdk-footer-row]',
template: CDK_ROW_TEMPLATE,
host: {
'class': 'cdk-footer-row',
'role': 'row',
},
// See note on CdkTable for explanation on why this uses the default change detection strategy.
// tslint:disable-next-line:validate-decorators
changeDetection: ChangeDetectionStrategy.Default,
encapsulation: ViewEncapsulation.None
}] }
];
/**
* Data row template container that contains the cell outlet. Adds the right class and role.
*/
class CdkRow {
}
CdkRow.decorators = [
{ type: Component, args: [{
selector: 'cdk-row, tr[cdk-row]',
template: CDK_ROW_TEMPLATE,
host: {
'class': 'cdk-row',
'role': 'row',
},
// See note on CdkTable for explanation on why this uses the default change detection strategy.
// tslint:disable-next-line:validate-decorators
changeDetection: ChangeDetectionStrategy.Default,
encapsulation: ViewEncapsulation.None
}] }
];
/**
* @fileoverview added by tsickle
* Generated from: src/cdk/table/sticky-styler.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @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
* @type {?}
*/
const STICKY_DIRECTIONS = ['top', 'bottom', 'left', 'right'];
/**
* Applies and removes sticky positioning styles to the `CdkTable` rows and columns cells.
* \@docs-private
*/
class StickyStyler {
/**
* @param {?} _isNativeHtmlTable Whether the sticky logic should be based on a table
* that uses the native `<table>` 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.
*/
constructor(_isNativeHtmlTable, _stickCellCss, direction, _isBrowser = true) {
this._isNativeHtmlTable = _isNativeHtmlTable;
this._stickCellCss = _stickCellCss;
this.direction = direction;
this._isBrowser = _isBrowser;
}
/**
* 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.
* @return {?}
*/
clearStickyPositioning(rows, stickyDirections) {
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;
}
this._removeStickyStyle(row, stickyDirections);
for (let i = 0; i < row.children.length; i++) {
/** @type {?} */
const cell = (/** @type {?} */ (row.children[i]));
this._removeStickyStyle(cell, 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.
* @return {?}
*/
updateStickyColumns(rows, stickyStartStates, stickyEndStates) {
/** @type {?} */
const hasStickyColumns = stickyStartStates.some((/**
* @param {?} state
* @return {?}
*/
state => state)) || stickyEndStates.some((/**
* @param {?} state
* @return {?}
*/
state => state));
if (!rows.length || !hasStickyColumns || !this._isBrowser) {
return;
}
/** @type {?} */
const firstRow = rows[0];
/** @type {?} */
const numCells = firstRow.children.length;
/** @type {?} */
const cellWidths = this._getCellWidths(firstRow);
/** @type {?} */
const startPositions = this._getStickyStartColumnPositions(cellWidths, stickyStartStates);
/** @type {?} */
const endPositions = this._getStickyEndColumnPositions(cellWidths, stickyEndStates);
/** @type {?} */
const isRtl = this.direction === 'rtl';
for (const row of rows) {
for (let i = 0; i < numCells; i++) {
/** @type {?} */
const cell = (/** @type {?} */ (row.children[i]));
if (stickyStartStates[i]) {
this._addStickyStyle(cell, isRtl ? 'right' : 'left', startPositions[i]);
}
if (stickyEndStates[i]) {
this._addStickyStyle(cell, isRtl ? 'left' : 'right', endPositions[i]);
}
}
}
}
/**
* 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.
*
* @return {?}
*/
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.
/** @type {?} */
const rows = position === 'bottom' ? rowsToStick.reverse() : rowsToStick;
/** @type {?} */
let stickyHeight = 0;
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
if (!stickyStates[rowIndex]) {
continue;
}
/** @type {?} */
const row = rows[rowIndex];
if (this._isNativeHtmlTable) {
for (let j = 0; j < row.children.length; j++) {
/** @type {?} */
const cell = (/** @type {?} */ (row.children[j]));
this._addStickyStyle(cell, position, stickyHeight);
}
}
else {
// Flex does not respect the stick positioning on the cells, needs to be applied to the row.
// If this is applied on a native table, Safari causes the header to fly in wrong direction.
this._addStickyStyle(row, position, stickyHeight);
}
if (rowIndex === rows.length - 1) {
// prevent unnecessary reflow from getBoundingClientRect()
return;
}
stickyHeight += row.getBoundingClientRect().height;
}
}
/**
* 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.
* @param {?} tableElement
* @param {?} stickyStates
* @return {?}
*/
updateStickyFooterContainer(tableElement, stickyStates) {
if (!this._isNativeHtmlTable) {
return;
}
/** @type {?} */
const tfoot = (/** @type {?} */ (tableElement.querySelector('tfoot')));
if (stickyStates.some((/**
* @param {?} state
* @return {?}
*/
state => !state))) {
this._removeStickyStyle(tfoot, ['bottom']);
}
else {
this._addStickyStyle(tfoot, 'bottom', 0);
}
}
/**
* 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.
* @param {?} element
* @param {?} stickyDirections
* @return {?}
*/
_removeStickyStyle(element, stickyDirections) {
for (const dir of stickyDirections) {
element.style[dir] = '';
}
element.style.zIndex = this._getCalculatedZIndex(element);
// If the element no longer has any more sticky directions, remove sticky positioning and
// the sticky CSS class.
/** @type {?} */
const hasDirection = STICKY_DIRECTIONS.some((/**
* @param {?} dir
* @return {?}
*/
dir => !!element.style[dir]));
if (!hasDirection) {
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.
* @param {?} element
* @param {?} dir
* @param {?} dirValue
* @return {?}
*/
_addStickyStyle(element, dir, dirValue) {
element.classList.add(this._stickCellCss);
element.style[dir] = `${dirValue}px`;
element.style.cssText += 'position: -webkit-sticky; position: sticky; ';
element.style.zIndex = this._getCalculatedZIndex(element);
}
/**
* 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.
* @param {?} element
* @return {?}
*/
_getCalculatedZIndex(element) {
/** @type {?} */
const zIndexIncrements = {
top: 100,
bottom: 10,
left: 1,
right: 1,
};
/** @type {?} */
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 (/** @type {?} */ (STICKY_DIRECTIONS))) {
if (element.style[dir]) {
zIndex += zIndexIncrements[dir];
}
}
return zIndex ? `${zIndex}` : '';
}
/**
* Gets the widths for each cell in the provided row.
* @param {?} row
* @return {?}
*/
_getCellWidths(row) {
/** @type {?} */
const cellWidths = [];
/** @type {?} */
const firstRowCells = row.children;
for (let i = 0; i < firstRowCells.length; i++) {
/** @type {?} */
let cell = (/** @type {?} */ (firstRowCells[i]));
cellWidths.push(cell.getBoundingClientRect().width);
}
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.
* @param {?} widths
* @param {?} stickyStates
* @return {?}
*/
_getStickyStartColumnPositions(widths, stickyStates) {
/** @type {?} */
const positions = [];
/** @type {?} */
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.
* @param {?} widths
* @param {?} stickyStates
* @return {?}
*/
_getStickyEndColumnPositions(widths, stickyStates) {
/** @type {?} */
const positions = [];
/** @type {?} */
let nextPosition = 0;
for (let i = widths.length; i > 0; i--) {
if (stickyStates[i]) {
positions[i] = nextPosition;
nextPosition += widths[i];
}
}
return positions;
}
}
if (false) {
/**
* @type {?}
* @private
*/
StickyStyler.prototype._isNativeHtmlTable;
/**
* @type {?}
* @private
*/
StickyStyler.prototype._stickCellCss;
/** @type {?} */
StickyStyler.prototype.direction;
/**
* @type {?}
* @private
*/
StickyStyler.prototype._isBrowser;
}
/**
* @fileoverview added by tsickle
* Generated from: src/cdk/table/table-errors.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @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
*/
/**
* Returns an error to be thrown when attempting to find an unexisting column.
* \@docs-private
* @param {?} id Id whose lookup failed.
* @return {?}
*/
function getTableUnknownColumnError(id) {
return Error(`Could not find column with id "${id}".`);
}
/**
* Returns an error to be thrown when two column definitions have the same name.
* \@docs-private
* @param {?} name
* @return {?}
*/
function getTableDuplicateColumnNameError(name) {
return Error(`Duplicate column definition name provided: "${name}".`);
}
/**
* Returns an error to be thrown when there are multiple rows that are missing a when function.
* \@docs-private
* @return {?}
*/
function getTableMultipleDefaultRowDefsError() {
return Error(`There can only be one default row without a when predicate function.`);
}
/**
* Returns an error to be thrown when there are no matching row defs for a particular set of data.
* \@docs-private
* @param {?} data
* @return {?}
*/
function getTableMissingMatchingRowDefError(data) {
return Error(`Could not find a matching row definition for the` +
`provided row data: ${JSON.stringify(data)}`);
}
/**
* Returns an error to be thrown when there is no row definitions present in the content.
* \@docs-private
* @return {?}
*/
function getTableMissingRowDefsError() {
return Error('Missing definitions for header, footer, and row; ' +
'cannot determine which columns should be rendered.');
}
/**
* Returns an error to be thrown when the data source does not match the compatible types.
* \@docs-private
* @return {?}
*/
function getTableUnknownDataSourceError() {
return Error(`Provided data source did not match an array, Observable, or DataSource`);
}
/**
* Returns an error to be thrown when the text column cannot find a parent table to inject.
* \@docs-private
* @return {?}
*/
function getTableTextColumnMissingParentTableError() {
return Error(`Text column could not find a parent table for registration.`);
}
/**
* Returns an error to be thrown when a table text column doesn't have a name.
* \@docs-private
* @return {?}
*/
function getTableTextColumnMissingNameError() {
return Error(`Table text column must have a name.`);
}
/**
* @fileoverview added by tsickle
* Generated from: src/cdk/table/table.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Interface used to provide an outlet for rows to be inserted into.
* @record
*/
function RowOutlet() { }
if (false) {
/** @type {?} */
RowOutlet.prototype.viewContainer;
}
/**
* Provides a handle for the table to grab the view container's ng-container to insert data rows.
* \@docs-private
*/
class DataRowOutlet {
/**
* @param {?} viewContainer
* @param {?} elementRef
*/
constructor(viewContainer, elementRef) {
this.viewContainer = viewContainer;
this.elementRef = elementRef;
}
}
DataRowOutlet.decorators = [
{ type: Directive, args: [{ selector: '[rowOutlet]' },] }
];
/** @nocollapse */
DataRowOutlet.ctorParameters = () => [
{ type: ViewContainerRef },
{ type: ElementRef }
];
if (false) {
/** @type {?} */
DataRowOutlet.prototype.viewContainer;
/** @type {?} */
DataRowOutlet.prototype.elementRef;
}
/**
* Provides a handle for the table to grab the view container's ng-container to insert the header.
* \@docs-private
*/
class HeaderRowOutlet {
/**
* @param {?} viewContainer
* @param {?} elementRef
*/
constructor(viewContainer, elementRef) {
this.viewContainer = viewContainer;
this.elementRef = elementRef;
}
}
HeaderRowOutlet.decorators = [
{ type: Directive, args: [{ selector: '[headerRowOutlet]' },] }
];
/** @nocollapse */
HeaderRowOutlet.ctorParameters = () => [
{ type: ViewContainerRef },
{ type: ElementRef }
];
if (false) {
/** @type {?} */
HeaderRowOutlet.prototype.viewContainer;
/** @type {?} */
HeaderRowOutlet.prototype.elementRef;
}
/**
* Provides a handle for the table to grab the view container's ng-container to insert the footer.
* \@docs-private
*/
class FooterRowOutlet {
/**
* @param {?} viewContainer
* @param {?} elementRef
*/
constructor(viewContainer, elementRef) {
this.viewContainer = viewContainer;
this.elementRef = elementRef;
}
}
FooterRowOutlet.decorators = [
{ type: Directive, args: [{ selector: '[footerRowOutlet]' },] }
];
/** @nocollapse */
FooterRowOutlet.ctorParameters = () => [
{ type: ViewContainerRef },
{ type: ElementRef }
];
if (false) {
/** @type {?} */
FooterRowOutlet.prototype.viewContainer;
/** @type {?} */
FooterRowOutlet.prototype.elementRef;
}
/**
* The table template that can be used by the mat-table. Should not be used outside of the
* material library.
* \@docs-private
* @type {?}
*/
const CDK_TABLE_TEMPLATE =
// Note that according to MDN, the `caption` element has to be projected as the **first**
// element in the table. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption
`
<ng-content select="caption"></ng-content>
<ng-container headerRowOutlet></ng-container>
<ng-container rowOutlet></ng-container>
<ng-container footerRowOutlet></ng-container>
`;
/**
* Interface used to conveniently type the possible context interfaces for the render row.
* \@docs-private
* @record
* @template T
*/
function RowContext() { }
/**
* Class used to conveniently type the embedded view ref for rows with a context.
* \@docs-private
* @abstract
* @template T
*/
class RowViewRef extends EmbeddedViewRef {
}
/**
* Set of properties that represents the identity of a single rendered row.
*
* When the table needs to determine the list of rows to render, it will do so by iterating through
* each data object and evaluating its list of row templates to display (when multiTemplateDataRows
* is false, there is only one template per data object). For each pair of data object and row
* template, a `RenderRow` is added to the list of rows to render. If the data object and row
* template pair has already been rendered, the previously used `RenderRow` is added; else a new
* `RenderRow` is * created. Once the list is complete and all data objects have been itereated
* through, a diff is performed to determine the changes that need to be made to the rendered rows.
*
* \@docs-private
* @record
* @template T
*/
function RenderRow() { }
if (false) {
/** @type {?} */
RenderRow.prototype.data;
/** @type {?} */
RenderRow.prototype.dataIndex;
/** @type {?} */
RenderRow.prototype.rowDef;
}
/**
* A data table that can render a header row, data rows, and a footer row.
* Uses the dataSource input to determine the data to be rendered. The data can be provided either
* as a data array, an Observable stream that emits the data array to render, or a DataSource with a
* connect function that will return an Observable stream that emits the data array to render.
* @template T
*/
class CdkTable {
/**
* @param {?} _differs
* @param {?} _changeDetectorRef
* @param {?} _elementRef
* @param {?} role
* @param {?} _dir
* @param {?} _document
* @param {?} _platform
*/
constructor(_differs, _changeDetectorRef, _elementRef, role, _dir, _document, _platform) {
this._differs = _differs;
this._changeDetectorRef = _changeDetectorRef;
this._elementRef = _elementRef;
this._dir = _dir;
this._platform = _platform;
/**
* Subject that emits when the component has been destroyed.
*/
this._onDestroy = new Subject();
/**
* Map of all the user's defined columns (header, data, and footer cell template) identified by
* name. Collection populated by the column definitions gathered by `ContentChildren` as well as
* any custom column definitions added to `_customColumnDefs`.
*/
this._columnDefsByName = new Map();
/**
* Column definitions that were defined outside of the direct content children of the table.
* These will be defined when, e.g., creating a wrapper around the cdkTable that has
* column definitions as *its* content child.
*/
this._customColumnDefs = new Set();
/**
* Data row definitions that were defined outside of the direct content children of the table.
* These will be defined when, e.g., creating a wrapper around the cdkTable that has
* built-in data rows as *its* content child.
*/
this._customRowDefs = new Set();
/**
* Header row definitions that were defined outside of the direct content children of the table.
* These will be defined when, e.g., creating a wrapper around the cdkTable that has
* built-in header rows as *its* content child.
*/
this._customHeaderRowDefs = new Set();
/**
* Footer row definitions that were defined outside of the direct content children of the table.
* These will be defined when, e.g., creating a wrapper around the cdkTable that has a
* built-in footer row as *its* content child.
*/
this._customFooterRowDefs = new Set();
/**
* Whether the header row definition has been changed. Triggers an update to the header row after
* content is checked. Initialized as true so that the table renders the initial set of rows.
*/
this._headerRowDefChanged = true;
/**
* Whether the footer row definition has been changed. Triggers an update to the footer row after
* content is checked. Initialized as true so that the table renders the initial set of rows.
*/
this._footerRowDefChanged = true;
/**
* Cache of the latest rendered `RenderRow` objects as a map for easy retrieval when constructing
* a new list of `RenderRow` objects for rendering rows. Since the new list is constructed with
* the cached `RenderRow` objects when possible, the row identity is preserved when the data
* and row template matches, which allows the `IterableDiffer` to check rows by reference
* and understand which rows are added/moved/removed.
*
* Implemented as a map of maps where the first key is the `data: T` object and the second is the
* `CdkRowDef<T>` object. With the two keys, the cache points to a `RenderRow<T>` object that
* contains an array of created pairs. The array is necessary to handle cases where the data
* array contains multiple duplicate data objects and each instantiated `RenderRow` must be
* stored.
*/
this._cachedRenderRowsMap = new Map();
/**
* CSS class added to any row or cell that has sticky positioning applied. May be overriden by
* table subclasses.
*/
this.stickyCssClass = 'cdk-table-sticky';
this._multiTemplateDataRows = false;
// TODO(andrewseguin): Remove max value as the end index