UNPKG

@angular/cdk

Version:

Angular Material Component Development Kit

1,001 lines (994 loc) 118 kB
import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { _VIEW_REPEATER_STRATEGY, _RecycleViewRepeaterStrategy, isDataSource, _DisposeViewRepeaterStrategy } from '@angular/cdk/collections'; export { DataSource } from '@angular/cdk/collections'; import { DOCUMENT } from '@angular/common'; import * as i0 from '@angular/core'; import { InjectionToken, Directive, Inject, Optional, Input, ContentChild, Injectable, Component, ChangeDetectionStrategy, ViewEncapsulation, EmbeddedViewRef, EventEmitter, NgZone, Attribute, SkipSelf, Output, ViewChild, ContentChildren, NgModule } from '@angular/core'; import { Subject, from, BehaviorSubject, isObservable, of } from 'rxjs'; import { takeUntil, take } from 'rxjs/operators'; import * as i1 from '@angular/cdk/bidi'; import * as i2 from '@angular/cdk/platform'; import * as i3 from '@angular/cdk/scrolling'; import { ScrollingModule } from '@angular/cdk/scrolling'; /** * @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 */ /** * 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 */ function mixinHasStickyInput(base) { return class extends base { 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. */ get sticky() { return this._sticky; } set sticky(v) { const prevValue = this._sticky; this._sticky = coerceBooleanProperty(v); this._hasStickyChanged = prevValue !== this._sticky; } /** Whether the sticky value has changed since this was last called. */ hasStickyChanged() { const hasStickyChanged = this._hasStickyChanged; this._hasStickyChanged = false; return hasStickyChanged; } /** Resets the dirty check for cases where the sticky state has been used without checking. */ resetStickyChanged() { this._hasStickyChanged = false; } }; } /** * @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 */ /** * Used to provide a table to some of the sub-components without causing a circular dependency. * @docs-private */ const CDK_TABLE = new InjectionToken('CDK_TABLE'); /** Injection token that can be used to specify the text column options. */ const TEXT_COLUMN_OPTIONS = new InjectionToken('text-column-options'); /** * @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 */ /** * Cell definition for a CDK table. * Captures the template of a column's data row cell as well as cell-specific properties. */ class CdkCellDef { constructor(/** @docs-private */ template) { this.template = template; } } CdkCellDef.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkCellDef, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive }); CdkCellDef.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkCellDef, selector: "[cdkCellDef]", ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkCellDef, decorators: [{ type: Directive, args: [{ selector: '[cdkCellDef]' }] }], ctorParameters: function () { return [{ type: i0.TemplateRef }]; } }); /** * 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 { constructor(/** @docs-private */ template) { this.template = template; } } CdkHeaderCellDef.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkHeaderCellDef, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive }); CdkHeaderCellDef.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkHeaderCellDef, selector: "[cdkHeaderCellDef]", ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkHeaderCellDef, decorators: [{ type: Directive, args: [{ selector: '[cdkHeaderCellDef]' }] }], ctorParameters: function () { return [{ type: i0.TemplateRef }]; } }); /** * 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 { constructor(/** @docs-private */ template) { this.template = template; } } CdkFooterCellDef.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkFooterCellDef, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive }); CdkFooterCellDef.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkFooterCellDef, selector: "[cdkFooterCellDef]", ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkFooterCellDef, decorators: [{ type: Directive, args: [{ selector: '[cdkFooterCellDef]' }] }], ctorParameters: function () { return [{ type: i0.TemplateRef }]; } }); // Boilerplate for applying mixins to CdkColumnDef. /** @docs-private */ class CdkColumnDefBase { } 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(_table) { super(); this._table = _table; this._stickyEnd = false; } /** Unique name for this column. */ get name() { return this._name; } set name(name) { this._setNameInput(name); } /** * 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 stickyEnd() { return this._stickyEnd; } set stickyEnd(v) { const prevValue = this._stickyEnd; this._stickyEnd = coerceBooleanProperty(v); this._hasStickyChanged = prevValue !== this._stickyEnd; } /** * Overridable method that sets the css classes that will be added to every cell in this * column. * In the future, columnCssClassName will change from type string[] to string and this * will set a single string value. * @docs-private */ _updateColumnCssClassName() { this._columnCssClassName = [`cdk-column-${this.cssClassFriendlyName}`]; } /** * This has been extracted to a util because of TS 4 and VE. * View Engine doesn't support property rename inheritance. * TS 4.0 doesn't allow properties to override accessors or vice-versa. * @docs-private */ _setNameInput(value) { // If the directive is set without a name (updated programmatically), then this setter will // trigger with an empty string and should not overwrite the programmatically set value. if (value) { this._name = value; this.cssClassFriendlyName = value.replace(/[^a-z0-9_-]/gi, '-'); this._updateColumnCssClassName(); } } } CdkColumnDef.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkColumnDef, deps: [{ token: CDK_TABLE, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); CdkColumnDef.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkColumnDef, selector: "[cdkColumnDef]", inputs: { sticky: "sticky", name: ["cdkColumnDef", "name"], stickyEnd: "stickyEnd" }, providers: [{ provide: 'MAT_SORT_HEADER_COLUMN_DEF', useExisting: CdkColumnDef }], queries: [{ propertyName: "cell", first: true, predicate: CdkCellDef, descendants: true }, { propertyName: "headerCell", first: true, predicate: CdkHeaderCellDef, descendants: true }, { propertyName: "footerCell", first: true, predicate: CdkFooterCellDef, descendants: true }], usesInheritance: true, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkColumnDef, decorators: [{ type: Directive, args: [{ selector: '[cdkColumnDef]', inputs: ['sticky'], providers: [{ provide: 'MAT_SORT_HEADER_COLUMN_DEF', useExisting: CdkColumnDef }], }] }], ctorParameters: function () { return [{ type: undefined, decorators: [{ type: Inject, args: [CDK_TABLE] }, { type: Optional }] }]; }, 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] }] } }); /** Base class for the cells. Adds a CSS classname that identifies the column it renders in. */ class BaseCdkCell { constructor(columnDef, elementRef) { elementRef.nativeElement.classList.add(...columnDef._columnCssClassName); } } /** Header cell template container that adds the right classes and role. */ class CdkHeaderCell extends BaseCdkCell { constructor(columnDef, elementRef) { super(columnDef, elementRef); } } CdkHeaderCell.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkHeaderCell, deps: [{ token: CdkColumnDef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); CdkHeaderCell.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkHeaderCell, selector: "cdk-header-cell, th[cdk-header-cell]", host: { attributes: { "role": "columnheader" }, classAttribute: "cdk-header-cell" }, usesInheritance: true, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkHeaderCell, decorators: [{ type: Directive, args: [{ selector: 'cdk-header-cell, th[cdk-header-cell]', host: { 'class': 'cdk-header-cell', 'role': 'columnheader', }, }] }], ctorParameters: function () { return [{ type: CdkColumnDef }, { type: i0.ElementRef }]; } }); /** Footer cell template container that adds the right classes and role. */ class CdkFooterCell extends BaseCdkCell { constructor(columnDef, elementRef) { var _a; super(columnDef, elementRef); if (((_a = columnDef._table) === null || _a === void 0 ? void 0 : _a._elementRef.nativeElement.nodeType) === 1) { const tableRole = columnDef._table._elementRef.nativeElement.getAttribute('role'); const role = tableRole === 'grid' || tableRole === 'treegrid' ? 'gridcell' : 'cell'; elementRef.nativeElement.setAttribute('role', role); } } } CdkFooterCell.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkFooterCell, deps: [{ token: CdkColumnDef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); CdkFooterCell.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkFooterCell, selector: "cdk-footer-cell, td[cdk-footer-cell]", host: { classAttribute: "cdk-footer-cell" }, usesInheritance: true, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkFooterCell, decorators: [{ type: Directive, args: [{ selector: 'cdk-footer-cell, td[cdk-footer-cell]', host: { 'class': 'cdk-footer-cell', }, }] }], ctorParameters: function () { return [{ type: CdkColumnDef }, { type: i0.ElementRef }]; } }); /** Cell template container that adds the right classes and role. */ class CdkCell extends BaseCdkCell { constructor(columnDef, elementRef) { var _a; super(columnDef, elementRef); if (((_a = columnDef._table) === null || _a === void 0 ? void 0 : _a._elementRef.nativeElement.nodeType) === 1) { const tableRole = columnDef._table._elementRef.nativeElement.getAttribute('role'); const role = tableRole === 'grid' || tableRole === 'treegrid' ? 'gridcell' : 'cell'; elementRef.nativeElement.setAttribute('role', role); } } } CdkCell.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkCell, deps: [{ token: CdkColumnDef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); CdkCell.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkCell, selector: "cdk-cell, td[cdk-cell]", host: { classAttribute: "cdk-cell" }, usesInheritance: true, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkCell, decorators: [{ type: Directive, args: [{ selector: 'cdk-cell, td[cdk-cell]', host: { 'class': 'cdk-cell', }, }] }], ctorParameters: function () { return [{ type: CdkColumnDef }, { type: i0.ElementRef }]; } }); /** * @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 */ /** * @docs-private */ class _Schedule { constructor() { this.tasks = []; this.endTasks = []; } } /** Injection token used to provide a coalesced style scheduler. */ const _COALESCED_STYLE_SCHEDULER = new InjectionToken('_COALESCED_STYLE_SCHEDULER'); /** * Allows grouping up CSSDom mutations after the current execution context. * This can significantly improve performance when separate consecutive functions are * reading from the CSSDom and then mutating it. * * @docs-private */ class _CoalescedStyleScheduler { constructor(_ngZone) { this._ngZone = _ngZone; this._currentSchedule = null; this._destroyed = new Subject(); } /** * Schedules the specified task to run at the end of the current VM turn. */ schedule(task) { this._createScheduleIfNeeded(); this._currentSchedule.tasks.push(task); } /** * Schedules the specified task to run after other scheduled tasks at the end of the current * VM turn. */ scheduleEnd(task) { this._createScheduleIfNeeded(); this._currentSchedule.endTasks.push(task); } /** Prevent any further tasks from running. */ ngOnDestroy() { this._destroyed.next(); this._destroyed.complete(); } _createScheduleIfNeeded() { if (this._currentSchedule) { return; } this._currentSchedule = new _Schedule(); this._getScheduleObservable() .pipe(takeUntil(this._destroyed)) .subscribe(() => { while (this._currentSchedule.tasks.length || this._currentSchedule.endTasks.length) { const schedule = this._currentSchedule; // Capture new tasks scheduled by the current set of tasks. this._currentSchedule = new _Schedule(); for (const task of schedule.tasks) { task(); } for (const task of schedule.endTasks) { task(); } } this._currentSchedule = null; }); } _getScheduleObservable() { // Use onStable when in the context of an ongoing change detection cycle so that we // do not accidentally trigger additional cycles. return this._ngZone.isStable ? from(Promise.resolve(undefined)) : this._ngZone.onStable.pipe(take(1)); } } _CoalescedStyleScheduler.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: _CoalescedStyleScheduler, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); _CoalescedStyleScheduler.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: _CoalescedStyleScheduler }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: _CoalescedStyleScheduler, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: i0.NgZone }]; } }); /** * @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 */ /** * The row template that can be used by the mat-table. Should not be used outside of the * material library. */ 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. */ class BaseRowDef { constructor( /** @docs-private */ template, _differs) { this.template = template; this._differs = _differs; } 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) { 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. */ getColumnsDiff() { return this._columnsDiffer.diff(this.columns); } /** Gets this row def's relevant cell template from the provided column def. */ extractCellTemplate(column) { if (this instanceof CdkHeaderRowDef) { return column.headerCell.template; } if (this instanceof CdkFooterRowDef) { return column.footerCell.template; } else { return column.cell.template; } } } BaseRowDef.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: BaseRowDef, deps: [{ token: i0.TemplateRef }, { token: i0.IterableDiffers }], target: i0.ɵɵFactoryTarget.Directive }); BaseRowDef.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: BaseRowDef, usesOnChanges: true, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: BaseRowDef, decorators: [{ type: Directive }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.IterableDiffers }]; } }); // Boilerplate for applying mixins to CdkHeaderRowDef. /** @docs-private */ class CdkHeaderRowDefBase extends BaseRowDef { } 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 { constructor(template, _differs, _table) { super(template, _differs); this._table = _table; } // 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. ngOnChanges(changes) { super.ngOnChanges(changes); } } CdkHeaderRowDef.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkHeaderRowDef, deps: [{ token: i0.TemplateRef }, { token: i0.IterableDiffers }, { token: CDK_TABLE, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); CdkHeaderRowDef.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkHeaderRowDef, selector: "[cdkHeaderRowDef]", inputs: { columns: ["cdkHeaderRowDef", "columns"], sticky: ["cdkHeaderRowDefSticky", "sticky"] }, usesInheritance: true, usesOnChanges: true, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkHeaderRowDef, decorators: [{ type: Directive, args: [{ selector: '[cdkHeaderRowDef]', inputs: ['columns: cdkHeaderRowDef', 'sticky: cdkHeaderRowDefSticky'], }] }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.IterableDiffers }, { type: undefined, decorators: [{ type: Inject, args: [CDK_TABLE] }, { type: Optional }] }]; } }); // Boilerplate for applying mixins to CdkFooterRowDef. /** @docs-private */ class CdkFooterRowDefBase extends BaseRowDef { } 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 { constructor(template, _differs, _table) { super(template, _differs); this._table = _table; } // 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. ngOnChanges(changes) { super.ngOnChanges(changes); } } CdkFooterRowDef.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkFooterRowDef, deps: [{ token: i0.TemplateRef }, { token: i0.IterableDiffers }, { token: CDK_TABLE, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); CdkFooterRowDef.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkFooterRowDef, selector: "[cdkFooterRowDef]", inputs: { columns: ["cdkFooterRowDef", "columns"], sticky: ["cdkFooterRowDefSticky", "sticky"] }, usesInheritance: true, usesOnChanges: true, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkFooterRowDef, decorators: [{ type: Directive, args: [{ selector: '[cdkFooterRowDef]', inputs: ['columns: cdkFooterRowDef', 'sticky: cdkFooterRowDefSticky'], }] }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.IterableDiffers }, { type: undefined, decorators: [{ type: Inject, args: [CDK_TABLE] }, { type: Optional }] }]; } }); /** * 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. */ class CdkRowDef extends BaseRowDef { // TODO(andrewseguin): Add an input for providing a switch function to determine // if this template should be used. constructor(template, _differs, _table) { super(template, _differs); this._table = _table; } } CdkRowDef.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkRowDef, deps: [{ token: i0.TemplateRef }, { token: i0.IterableDiffers }, { token: CDK_TABLE, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); CdkRowDef.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkRowDef, selector: "[cdkRowDef]", inputs: { columns: ["cdkRowDefColumns", "columns"], when: ["cdkRowDefWhen", "when"] }, usesInheritance: true, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkRowDef, decorators: [{ type: Directive, args: [{ selector: '[cdkRowDef]', inputs: ['columns: cdkRowDefColumns', 'when: cdkRowDefWhen'], }] }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.IterableDiffers }, { type: undefined, decorators: [{ type: Inject, args: [CDK_TABLE] }, { type: Optional }] }]; } }); /** * Outlet for rendering cells inside of a row or header row. * @docs-private */ class CdkCellOutlet { constructor(_viewContainer) { this._viewContainer = _viewContainer; CdkCellOutlet.mostRecentCellOutlet = this; } 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.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkCellOutlet, deps: [{ token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); CdkCellOutlet.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkCellOutlet, selector: "[cdkCellOutlet]", ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkCellOutlet, decorators: [{ type: Directive, args: [{ selector: '[cdkCellOutlet]' }] }], ctorParameters: function () { return [{ type: i0.ViewContainerRef }]; } }); /** Header template container that contains the cell outlet. Adds the right class and role. */ class CdkHeaderRow { } CdkHeaderRow.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkHeaderRow, deps: [], target: i0.ɵɵFactoryTarget.Component }); CdkHeaderRow.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.0", type: CdkHeaderRow, selector: "cdk-header-row, tr[cdk-header-row]", host: { attributes: { "role": "row" }, classAttribute: "cdk-header-row" }, ngImport: i0, template: "<ng-container cdkCellOutlet></ng-container>", isInline: true, directives: [{ type: CdkCellOutlet, selector: "[cdkCellOutlet]" }], changeDetection: i0.ChangeDetectionStrategy.Default, encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: 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.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkFooterRow, deps: [], target: i0.ɵɵFactoryTarget.Component }); CdkFooterRow.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.0", type: CdkFooterRow, selector: "cdk-footer-row, tr[cdk-footer-row]", host: { attributes: { "role": "row" }, classAttribute: "cdk-footer-row" }, ngImport: i0, template: "<ng-container cdkCellOutlet></ng-container>", isInline: true, directives: [{ type: CdkCellOutlet, selector: "[cdkCellOutlet]" }], changeDetection: i0.ChangeDetectionStrategy.Default, encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: 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.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkRow, deps: [], target: i0.ɵɵFactoryTarget.Component }); CdkRow.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.0", type: CdkRow, selector: "cdk-row, tr[cdk-row]", host: { attributes: { "role": "row" }, classAttribute: "cdk-row" }, ngImport: i0, template: "<ng-container cdkCellOutlet></ng-container>", isInline: true, directives: [{ type: CdkCellOutlet, selector: "[cdkCellOutlet]" }], changeDetection: i0.ChangeDetectionStrategy.Default, encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: 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, }] }] }); /** Row that can be used to display a message when no data is shown in the table. */ class CdkNoDataRow { constructor(templateRef) { this.templateRef = templateRef; this._contentClassName = 'cdk-no-data-row'; } } CdkNoDataRow.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkNoDataRow, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive }); CdkNoDataRow.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: CdkNoDataRow, selector: "ng-template[cdkNoDataRow]", ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: CdkNoDataRow, decorators: [{ type: Directive, args: [{ selector: 'ng-template[cdkNoDataRow]', }] }], ctorParameters: function () { return [{ type: i0.TemplateRef }]; } }); /** * @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 */ 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. * @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(() => { var _a, _b; 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') { (_a = this._positionListener) === null || _a === void 0 ? void 0 : _a.stickyHeaderRowsUpdated({ sizes: stickyCellHeights, offsets: stickyOffsets, elements: elementsToStick, }); } else { (_b = this._positionListener) === null || _b === void 0 ? void 0 : _b.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; } } /** * @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. * @param id Id whose lookup failed. * @docs-private */ function getTableUnknownColumnError(id) { return Error(`Could not find column with id "${id}".`); } /** * Retur