@angular/cdk
Version:
Angular Material Component Development Kit
1,257 lines (1,248 loc) • 114 kB
JavaScript
/**
* @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
*/
import { __extends } from 'tslib';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { ContentChild, Directive, ElementRef, Input, TemplateRef, ChangeDetectionStrategy, Component, IterableDiffers, ViewContainerRef, ViewEncapsulation, Attribute, ChangeDetectorRef, ContentChildren, EmbeddedViewRef, isDevMode, Optional, ViewChild, Inject, NgModule } from '@angular/core';
import { isDataSource } from '@angular/cdk/collections';
export { DataSource } from '@angular/cdk/collections';
import { DOCUMENT, CommonModule } from '@angular/common';
import { BehaviorSubject, Observable, of, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { Directionality } from '@angular/cdk/bidi';
import { Platform } from '@angular/cdk/platform';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* 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 */ (function (_super) {
__extends(class_1, _super);
function class_1() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
_this._sticky = false;
/**
* Whether the sticky input has changed since it was last checked.
*/
_this._hasStickyChanged = false;
return _this;
}
Object.defineProperty(class_1.prototype, "sticky", {
/** Whether sticky positioning should be applied. */
get: /**
* Whether sticky positioning should be applied.
* @return {?}
*/
function () { return this._sticky; },
set: /**
* @param {?} v
* @return {?}
*/
function (v) {
/** @type {?} */
var prevValue = this._sticky;
this._sticky = coerceBooleanProperty(v);
this._hasStickyChanged = prevValue !== this._sticky;
},
enumerable: true,
configurable: true
});
/** Whether the sticky value has changed since this was last called. */
/**
* Whether the sticky value has changed since this was last called.
* @return {?}
*/
class_1.prototype.hasStickyChanged = /**
* Whether the sticky value has changed since this was last called.
* @return {?}
*/
function () {
/** @type {?} */
var hasStickyChanged = this._hasStickyChanged;
this._hasStickyChanged = false;
return hasStickyChanged;
};
/** Resets the dirty check for cases where the sticky state has been used without checking. */
/**
* Resets the dirty check for cases where the sticky state has been used without checking.
* @return {?}
*/
class_1.prototype.resetStickyChanged = /**
* Resets the dirty check for cases where the sticky state has been used without checking.
* @return {?}
*/
function () {
this._hasStickyChanged = false;
};
return class_1;
}(base));
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Cell definition for a CDK table.
* Captures the template of a column's data row cell as well as cell-specific properties.
*/
var CdkCellDef = /** @class */ (function () {
function CdkCellDef(/** @docs-private */ template) {
this.template = template;
}
CdkCellDef.decorators = [
{ type: Directive, args: [{ selector: '[cdkCellDef]' },] },
];
/** @nocollapse */
CdkCellDef.ctorParameters = function () { return [
{ type: TemplateRef }
]; };
return CdkCellDef;
}());
/**
* Header cell definition for a CDK table.
* Captures the template of a column's header cell and as well as cell-specific properties.
*/
var CdkHeaderCellDef = /** @class */ (function () {
function CdkHeaderCellDef(/** @docs-private */ template) {
this.template = template;
}
CdkHeaderCellDef.decorators = [
{ type: Directive, args: [{ selector: '[cdkHeaderCellDef]' },] },
];
/** @nocollapse */
CdkHeaderCellDef.ctorParameters = function () { return [
{ type: TemplateRef }
]; };
return CdkHeaderCellDef;
}());
/**
* Footer cell definition for a CDK table.
* Captures the template of a column's footer cell and as well as cell-specific properties.
*/
var CdkFooterCellDef = /** @class */ (function () {
function CdkFooterCellDef(/** @docs-private */ template) {
this.template = template;
}
CdkFooterCellDef.decorators = [
{ type: Directive, args: [{ selector: '[cdkFooterCellDef]' },] },
];
/** @nocollapse */
CdkFooterCellDef.ctorParameters = function () { return [
{ type: TemplateRef }
]; };
return CdkFooterCellDef;
}());
// Boilerplate for applying mixins to CdkColumnDef.
/**
* \@docs-private
*/
var
// Boilerplate for applying mixins to CdkColumnDef.
/**
* \@docs-private
*/
CdkColumnDefBase = /** @class */ (function () {
function CdkColumnDefBase() {
}
return CdkColumnDefBase;
}());
/** @type {?} */
var _CdkColumnDefBase = mixinHasStickyInput(CdkColumnDefBase);
/**
* Column definition for the CDK table.
* Defines a set of cells available for a table column.
*/
var CdkColumnDef = /** @class */ (function (_super) {
__extends(CdkColumnDef, _super);
function CdkColumnDef() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._stickyEnd = false;
return _this;
}
Object.defineProperty(CdkColumnDef.prototype, "name", {
/** Unique name for this column. */
get: /**
* Unique name for this column.
* @return {?}
*/
function () { return this._name; },
set: /**
* @param {?} name
* @return {?}
*/
function (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, '-');
},
enumerable: true,
configurable: true
});
Object.defineProperty(CdkColumnDef.prototype, "stickyEnd", {
/**
* 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.
*/
get: /**
* 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 {?}
*/
function () { return this._stickyEnd; },
set: /**
* @param {?} v
* @return {?}
*/
function (v) {
/** @type {?} */
var prevValue = this._stickyEnd;
this._stickyEnd = coerceBooleanProperty(v);
this._hasStickyChanged = prevValue !== this._stickyEnd;
},
enumerable: true,
configurable: true
});
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,] }]
};
return CdkColumnDef;
}(_CdkColumnDefBase));
/**
* Base class for the cells. Adds a CSS classname that identifies the column it renders in.
*/
var /**
* Base class for the cells. Adds a CSS classname that identifies the column it renders in.
*/
BaseCdkCell = /** @class */ (function () {
function BaseCdkCell(columnDef, elementRef) {
/** @type {?} */
var columnClassName = "cdk-column-" + columnDef.cssClassFriendlyName;
elementRef.nativeElement.classList.add(columnClassName);
}
return BaseCdkCell;
}());
/**
* Header cell template container that adds the right classes and role.
*/
var CdkHeaderCell = /** @class */ (function (_super) {
__extends(CdkHeaderCell, _super);
function CdkHeaderCell(columnDef, elementRef) {
return _super.call(this, columnDef, elementRef) || this;
}
CdkHeaderCell.decorators = [
{ type: Directive, args: [{
selector: 'cdk-header-cell, th[cdk-header-cell]',
host: {
'class': 'cdk-header-cell',
'role': 'columnheader',
},
},] },
];
/** @nocollapse */
CdkHeaderCell.ctorParameters = function () { return [
{ type: CdkColumnDef },
{ type: ElementRef }
]; };
return CdkHeaderCell;
}(BaseCdkCell));
/**
* Footer cell template container that adds the right classes and role.
*/
var CdkFooterCell = /** @class */ (function (_super) {
__extends(CdkFooterCell, _super);
function CdkFooterCell(columnDef, elementRef) {
return _super.call(this, columnDef, elementRef) || this;
}
CdkFooterCell.decorators = [
{ type: Directive, args: [{
selector: 'cdk-footer-cell, td[cdk-footer-cell]',
host: {
'class': 'cdk-footer-cell',
'role': 'gridcell',
},
},] },
];
/** @nocollapse */
CdkFooterCell.ctorParameters = function () { return [
{ type: CdkColumnDef },
{ type: ElementRef }
]; };
return CdkFooterCell;
}(BaseCdkCell));
/**
* Cell template container that adds the right classes and role.
*/
var CdkCell = /** @class */ (function (_super) {
__extends(CdkCell, _super);
function CdkCell(columnDef, elementRef) {
return _super.call(this, columnDef, elementRef) || this;
}
CdkCell.decorators = [
{ type: Directive, args: [{
selector: 'cdk-cell, td[cdk-cell]',
host: {
'class': 'cdk-cell',
'role': 'gridcell',
},
},] },
];
/** @nocollapse */
CdkCell.ctorParameters = function () { return [
{ type: CdkColumnDef },
{ type: ElementRef }
]; };
return CdkCell;
}(BaseCdkCell));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,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 {?}
*/
var 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
*/
var /**
* Base class for the CdkHeaderRowDef and CdkRowDef that handles checking their columns inputs
* for changes and notifying the table.
* @abstract
*/
BaseRowDef = /** @class */ (function () {
function BaseRowDef(/** @docs-private */ template, _differs) {
this.template = template;
this._differs = _differs;
}
/**
* @param {?} changes
* @return {?}
*/
BaseRowDef.prototype.ngOnChanges = /**
* @param {?} changes
* @return {?}
*/
function (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 {?} */
var 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.
*/
/**
* Returns the difference between the current columns and the columns from the last diff, or null
* if there is no difference.
* @return {?}
*/
BaseRowDef.prototype.getColumnsDiff = /**
* Returns the difference between the current columns and the columns from the last diff, or null
* if there is no difference.
* @return {?}
*/
function () {
return this._columnsDiffer.diff(this.columns);
};
/** Gets this row def's relevant cell template from the provided column def. */
/**
* Gets this row def's relevant cell template from the provided column def.
* @param {?} column
* @return {?}
*/
BaseRowDef.prototype.extractCellTemplate = /**
* Gets this row def's relevant cell template from the provided column def.
* @param {?} column
* @return {?}
*/
function (column) {
if (this instanceof CdkHeaderRowDef) {
return column.headerCell.template;
}
if (this instanceof CdkFooterRowDef) {
return column.footerCell.template;
}
else {
return column.cell.template;
}
};
return BaseRowDef;
}());
// Boilerplate for applying mixins to CdkHeaderRowDef.
/**
* \@docs-private
*/
var
// Boilerplate for applying mixins to CdkHeaderRowDef.
/**
* \@docs-private
*/
CdkHeaderRowDefBase = /** @class */ (function (_super) {
__extends(CdkHeaderRowDefBase, _super);
function CdkHeaderRowDefBase() {
return _super !== null && _super.apply(this, arguments) || this;
}
return CdkHeaderRowDefBase;
}(BaseRowDef));
/** @type {?} */
var _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.
*/
var CdkHeaderRowDef = /** @class */ (function (_super) {
__extends(CdkHeaderRowDef, _super);
function CdkHeaderRowDef(template, _differs) {
return _super.call(this, template, _differs) || this;
}
// 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.
// 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 {?}
*/
CdkHeaderRowDef.prototype.ngOnChanges =
// 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 {?}
*/
function (changes) {
_super.prototype.ngOnChanges.call(this, changes);
};
CdkHeaderRowDef.decorators = [
{ type: Directive, args: [{
selector: '[cdkHeaderRowDef]',
inputs: ['columns: cdkHeaderRowDef', 'sticky: cdkHeaderRowDefSticky'],
},] },
];
/** @nocollapse */
CdkHeaderRowDef.ctorParameters = function () { return [
{ type: TemplateRef },
{ type: IterableDiffers }
]; };
return CdkHeaderRowDef;
}(_CdkHeaderRowDefBase));
// Boilerplate for applying mixins to CdkFooterRowDef.
/**
* \@docs-private
*/
var
// Boilerplate for applying mixins to CdkFooterRowDef.
/**
* \@docs-private
*/
CdkFooterRowDefBase = /** @class */ (function (_super) {
__extends(CdkFooterRowDefBase, _super);
function CdkFooterRowDefBase() {
return _super !== null && _super.apply(this, arguments) || this;
}
return CdkFooterRowDefBase;
}(BaseRowDef));
/** @type {?} */
var _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.
*/
var CdkFooterRowDef = /** @class */ (function (_super) {
__extends(CdkFooterRowDef, _super);
function CdkFooterRowDef(template, _differs) {
return _super.call(this, template, _differs) || this;
}
// 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.
// 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 {?}
*/
CdkFooterRowDef.prototype.ngOnChanges =
// 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 {?}
*/
function (changes) {
_super.prototype.ngOnChanges.call(this, changes);
};
CdkFooterRowDef.decorators = [
{ type: Directive, args: [{
selector: '[cdkFooterRowDef]',
inputs: ['columns: cdkFooterRowDef', 'sticky: cdkFooterRowDefSticky'],
},] },
];
/** @nocollapse */
CdkFooterRowDef.ctorParameters = function () { return [
{ type: TemplateRef },
{ type: IterableDiffers }
]; };
return CdkFooterRowDef;
}(_CdkFooterRowDefBase));
/**
* 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
*/
var CdkRowDef = /** @class */ (function (_super) {
__extends(CdkRowDef, _super);
// TODO(andrewseguin): Add an input for providing a switch function to determine
// if this template should be used.
function CdkRowDef(template, _differs) {
return _super.call(this, template, _differs) || this;
}
CdkRowDef.decorators = [
{ type: Directive, args: [{
selector: '[cdkRowDef]',
inputs: ['columns: cdkRowDefColumns', 'when: cdkRowDefWhen'],
},] },
];
/** @nocollapse */
CdkRowDef.ctorParameters = function () { return [
{ type: TemplateRef },
{ type: IterableDiffers }
]; };
return CdkRowDef;
}(BaseRowDef));
/**
* Outlet for rendering cells inside of a row or header row.
* \@docs-private
*/
var CdkCellOutlet = /** @class */ (function () {
function CdkCellOutlet(_viewContainer) {
this._viewContainer = _viewContainer;
CdkCellOutlet.mostRecentCellOutlet = this;
}
/**
* @return {?}
*/
CdkCellOutlet.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
// 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 = function () { return [
{ type: ViewContainerRef }
]; };
return CdkCellOutlet;
}());
/**
* Header template container that contains the cell outlet. Adds the right class and role.
*/
var CdkHeaderRow = /** @class */ (function () {
function 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',
},
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
},] },
];
return CdkHeaderRow;
}());
/**
* Footer template container that contains the cell outlet. Adds the right class and role.
*/
var CdkFooterRow = /** @class */ (function () {
function 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',
},
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
},] },
];
return CdkFooterRow;
}());
/**
* Data row template container that contains the cell outlet. Adds the right class and role.
*/
var CdkRow = /** @class */ (function () {
function CdkRow() {
}
CdkRow.decorators = [
{ type: Component, args: [{selector: 'cdk-row, tr[cdk-row]',
template: CDK_ROW_TEMPLATE,
host: {
'class': 'cdk-row',
'role': 'row',
},
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
},] },
];
return CdkRow;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* 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");
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* List of all possible directions that can be used for sticky positioning.
* \@docs-private
* @type {?}
*/
var STICKY_DIRECTIONS = ['top', 'bottom', 'left', 'right'];
/**
* Applies and removes sticky positioning styles to the `CdkTable` rows and columns cells.
* \@docs-private
*/
var /**
* Applies and removes sticky positioning styles to the `CdkTable` rows and columns cells.
* \@docs-private
*/
StickyStyler = /** @class */ (function () {
/**
* @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.
*/
function StickyStyler(isNativeHtmlTable, stickCellCss, direction, _isBrowser) {
if (_isBrowser === void 0) { _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.
*/
/**
* 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 {?}
*/
StickyStyler.prototype.clearStickyPositioning = /**
* 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 {?}
*/
function (rows, stickyDirections) {
for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
var row = rows_1[_i];
// 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 (var i = 0; i < row.children.length; i++) {
/** @type {?} */
var 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.
*/
/**
* 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 {?}
*/
StickyStyler.prototype.updateStickyColumns = /**
* 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 {?}
*/
function (rows, stickyStartStates, stickyEndStates) {
/** @type {?} */
var hasStickyColumns = stickyStartStates.some(function (state) { return state; }) || stickyEndStates.some(function (state) { return state; });
if (!rows.length || !hasStickyColumns || !this._isBrowser) {
return;
}
/** @type {?} */
var firstRow = rows[0];
/** @type {?} */
var numCells = firstRow.children.length;
/** @type {?} */
var cellWidths = this._getCellWidths(firstRow);
/** @type {?} */
var startPositions = this._getStickyStartColumnPositions(cellWidths, stickyStartStates);
/** @type {?} */
var endPositions = this._getStickyEndColumnPositions(cellWidths, stickyEndStates);
/** @type {?} */
var isRtl = this.direction === 'rtl';
for (var _i = 0, rows_2 = rows; _i < rows_2.length; _i++) {
var row = rows_2[_i];
for (var i = 0; i < numCells; i++) {
/** @type {?} */
var 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.
*
*/
/**
* 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 {?}
*/
StickyStyler.prototype.stickRows = /**
* 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 {?}
*/
function (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 {?} */
var rows = position === 'bottom' ? rowsToStick.reverse() : rowsToStick;
/** @type {?} */
var stickyHeight = 0;
for (var rowIndex = 0; rowIndex < rows.length; rowIndex++) {
if (!stickyStates[rowIndex]) {
continue;
}
/** @type {?} */
var row = rows[rowIndex];
if (this.isNativeHtmlTable) {
for (var j = 0; j < row.children.length; j++) {
/** @type {?} */
var 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.
*/
/**
* 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 {?}
*/
StickyStyler.prototype.updateStickyFooterContainer = /**
* 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 {?}
*/
function (tableElement, stickyStates) {
if (!this.isNativeHtmlTable) {
return;
}
/** @type {?} */
var tfoot = (/** @type {?} */ (tableElement.querySelector('tfoot')));
if (stickyStates.some(function (state) { return !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.
*/
/**
* 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 {?}
*/
StickyStyler.prototype._removeStickyStyle = /**
* 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 {?}
*/
function (element, stickyDirections) {
for (var _i = 0, stickyDirections_1 = stickyDirections; _i < stickyDirections_1.length; _i++) {
var dir = stickyDirections_1[_i];
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 {?} */
var hasDirection = STICKY_DIRECTIONS.some(function (dir) { return !!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.
*/
/**
* 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 {?}
*/
StickyStyler.prototype._addStickyStyle = /**
* 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 {?}
*/
function (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.
*/
/**
* 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 {?}
*/
StickyStyler.prototype._getCalculatedZIndex = /**
* 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 {?}
*/
function (element) {
/** @type {?} */
var zIndexIncrements = {
top: 100,
bottom: 10,
left: 1,
right: 1,
};
/** @type {?} */
var zIndex = 0;
for (var _i = 0, STICKY_DIRECTIONS_1 = STICKY_DIRECTIONS; _i < STICKY_DIRECTIONS_1.length; _i++) {
var dir = STICKY_DIRECTIONS_1[_i];
if (element.style[dir]) {
zIndex += zIndexIncrements[dir];
}
}
return zIndex ? "" + zIndex : '';
};
/** Gets the widths for each cell in the provided row. */
/**
* Gets the widths for each cell in the provided row.
* @param {?} row
* @return {?}
*/
StickyStyler.prototype._getCellWidths = /**
* Gets the widths for each cell in the provided row.
* @param {?} row
* @return {?}
*/
function (row) {
/** @type {?} */
var cellWidths = [];
/** @type {?} */
var firstRowCells = row.children;
for (var i = 0; i < firstRowCells.length; i++) {
/** @type {?} */
var 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.
*/
/**
* 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 {?}
*/
StickyStyler.prototype._getStickyStartColumnPositions = /**
* 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 {?}
*/
function (widths, stickyStates) {
/** @type {?} */
var positions = [];
/** @type {?} */
var nextPosition = 0;
for (var 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.
*/
/**
* 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 {?}
*/
StickyStyler.prototype._getStickyEndColumnPositions = /**
* 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 {?}
*/
function (widths, stickyStates) {
/** @type {?} */
var positions = [];
/** @type {?} */
var nextPosition = 0;
for (var i = widths.length; i > 0; i--) {
if (stickyStates[i]) {
positions[i] = nextPosition;
nextPosition += widths[i];
}
}
return positions;
};
return StickyStyler;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Provides a handle for the table to grab the view container's ng-container to insert data rows.
* \@docs-private
*/
var DataRowOutlet = /** @class */ (function () {
function DataRowOutlet(viewContainer, elementRef) {
this.viewContainer = viewContainer;
this.elementRef = elementRef;
}
DataRowOutlet.decorators = [
{ type: Directive, args: [{ selector: '[rowOutlet]' },] },
];
/** @nocollapse */
DataRowOutlet.ctorParameters = function () { return [
{ type: ViewContainerRef },
{ type: ElementRef }
]; };
return DataRowOutlet;
}());
/**
* Provides a handle for the table to grab the view container's ng-container to insert the header.
* \@docs-private
*/
var HeaderRowOutlet = /** @class */ (function () {
function HeaderRowOutlet(viewContainer, elementRef) {
this.viewContainer = viewContainer;
this.elementRef = elementRef;
}
HeaderRowOutlet.decorators = [
{ type: Directive, args: [{ selector: '[headerRowOutlet]' },] },
];
/** @nocollapse */
HeaderRowOutlet.ctorParameters = function () { return [
{ type: ViewContainerRef },
{ type: ElementRef }
]; };
return HeaderRowOutlet;
}());
/**
* Provides a handle for the table to grab the view container's ng-container to insert the footer.
* \@docs-private
*/
var FooterRowOutlet = /** @class */ (function () {
function FooterRowOutlet(viewContainer, elementRef) {
this.viewContainer = viewContainer;
this.elementRef = elementRef;
}
FooterRowOutlet.decorators = [
{ type: Directive, args: [{ selector: '[footerRowOutlet]' },] },
];
/** @nocollapse */
FooterRowOutlet.ctorParameters = function () { return [
{ type: ViewContainerRef },
{ type: ElementRef }
]; };
return FooterRowOutlet;
}());
/**
* The table template that can be used by the mat-table. Should not be used outside of the
* material library.
* \@docs-private
* @type {?}
*/
var 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
"\n <ng-content select=\"caption\"></ng-content>\n <ng-container headerRowOutlet></ng-container>\n <ng-container rowOutlet></ng-container>\n <ng-container footerRowOutlet></ng-container>\n";
/**
* Class used to conveniently type the embedded view ref for rows with a context.
* \@docs-private
* @abstract
* @template T
*/
var /**
* Class used to conveniently type the embedded view ref for rows with a context.
* \@docs-private
* @abstract
* @template T
*/
RowViewRef = /** @class */ (function (_super) {