@angular/cdk
Version:
Angular Material Component Development Kit
1,018 lines (1,012 loc) • 125 kB
JavaScript
import { i as isDataSource } from './data-source-d79c6e09.mjs';
export { D as DataSource } from './data-source-d79c6e09.mjs';
import { DOCUMENT } from '@angular/common';
import * as i0 from '@angular/core';
import { InjectionToken, inject, TemplateRef, Directive, booleanAttribute, Input, ContentChild, ElementRef, NgZone, Injectable, IterableDiffers, ViewContainerRef, Component, ChangeDetectionStrategy, ViewEncapsulation, afterNextRender, ChangeDetectorRef, EventEmitter, Injector, HostAttributeToken, Output, ContentChildren, ViewChild, NgModule } from '@angular/core';
import { Subject, BehaviorSubject, isObservable, of } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { b as _VIEW_REPEATER_STRATEGY, _ as _RecycleViewRepeaterStrategy, a as _ViewRepeaterOperation } from './recycle-view-repeater-strategy-0f32b0a8.mjs';
import { _ as _DisposeViewRepeaterStrategy } from './dispose-view-repeater-strategy-4c6df00e.mjs';
import { D as Directionality } from './directionality-9d44e426.mjs';
import { P as Platform } from './platform-20fc4de8.mjs';
import { V as ViewportRuler, a as ScrollingModule } from './scrolling-module-722545e3.mjs';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import './element-15999318.mjs';
import './scrolling-59340c46.mjs';
import './bidi-module-04c03e58.mjs';
/**
* 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');
/**
* Cell definition for a CDK table.
* Captures the template of a column's data row cell as well as cell-specific properties.
*/
class CdkCellDef {
/** @docs-private */
template = inject(TemplateRef);
constructor() { }
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkCellDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.0", type: CdkCellDef, isStandalone: true, selector: "[cdkCellDef]", ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkCellDef, decorators: [{
type: Directive,
args: [{
selector: '[cdkCellDef]',
}]
}], ctorParameters: () => [] });
/**
* 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 {
/** @docs-private */
template = inject(TemplateRef);
constructor() { }
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkHeaderCellDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.0", type: CdkHeaderCellDef, isStandalone: true, selector: "[cdkHeaderCellDef]", ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkHeaderCellDef, decorators: [{
type: Directive,
args: [{
selector: '[cdkHeaderCellDef]',
}]
}], ctorParameters: () => [] });
/**
* 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 {
/** @docs-private */
template = inject(TemplateRef);
constructor() { }
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkFooterCellDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.0", type: CdkFooterCellDef, isStandalone: true, selector: "[cdkFooterCellDef]", ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkFooterCellDef, decorators: [{
type: Directive,
args: [{
selector: '[cdkFooterCellDef]',
}]
}], ctorParameters: () => [] });
/**
* Column definition for the CDK table.
* Defines a set of cells available for a table column.
*/
class CdkColumnDef {
_table = inject(CDK_TABLE, { optional: true });
_hasStickyChanged = false;
/** Unique name for this column. */
get name() {
return this._name;
}
set name(name) {
this._setNameInput(name);
}
_name;
/** Whether the cell is sticky. */
get sticky() {
return this._sticky;
}
set sticky(value) {
if (value !== this._sticky) {
this._sticky = value;
this._hasStickyChanged = true;
}
}
_sticky = false;
/**
* 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(value) {
if (value !== this._stickyEnd) {
this._stickyEnd = value;
this._hasStickyChanged = true;
}
}
_stickyEnd = false;
/** @docs-private */
cell;
/** @docs-private */
headerCell;
/** @docs-private */
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.
*/
cssClassFriendlyName;
/**
* Class name for cells in this column.
* @docs-private
*/
_columnCssClassName;
constructor() { }
/** Whether the sticky state has changed. */
hasStickyChanged() {
const hasStickyChanged = this._hasStickyChanged;
this.resetStickyChanged();
return hasStickyChanged;
}
/** Resets the sticky changed state. */
resetStickyChanged() {
this._hasStickyChanged = false;
}
/**
* 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();
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkColumnDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.0", type: CdkColumnDef, isStandalone: true, selector: "[cdkColumnDef]", inputs: { name: ["cdkColumnDef", "name"], sticky: ["sticky", "sticky", booleanAttribute], stickyEnd: ["stickyEnd", "stickyEnd", booleanAttribute] }, 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 }], ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkColumnDef, decorators: [{
type: Directive,
args: [{
selector: '[cdkColumnDef]',
providers: [{ provide: 'MAT_SORT_HEADER_COLUMN_DEF', useExisting: CdkColumnDef }],
}]
}], ctorParameters: () => [], propDecorators: { name: [{
type: Input,
args: ['cdkColumnDef']
}], sticky: [{
type: Input,
args: [{ transform: booleanAttribute }]
}], stickyEnd: [{
type: Input,
args: [{ transform: booleanAttribute }]
}], 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() {
super(inject(CdkColumnDef), inject(ElementRef));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkHeaderCell, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.0", type: CdkHeaderCell, isStandalone: true, 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: "19.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: () => [] });
/** Footer cell template container that adds the right classes and role. */
class CdkFooterCell extends BaseCdkCell {
constructor() {
const columnDef = inject(CdkColumnDef);
const elementRef = inject(ElementRef);
super(columnDef, elementRef);
const role = columnDef._table?._getCellRole();
if (role) {
elementRef.nativeElement.setAttribute('role', role);
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkFooterCell, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.0", type: CdkFooterCell, isStandalone: true, selector: "cdk-footer-cell, td[cdk-footer-cell]", host: { classAttribute: "cdk-footer-cell" }, usesInheritance: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkFooterCell, decorators: [{
type: Directive,
args: [{
selector: 'cdk-footer-cell, td[cdk-footer-cell]',
host: {
'class': 'cdk-footer-cell',
},
}]
}], ctorParameters: () => [] });
/** Cell template container that adds the right classes and role. */
class CdkCell extends BaseCdkCell {
constructor() {
const columnDef = inject(CdkColumnDef);
const elementRef = inject(ElementRef);
super(columnDef, elementRef);
const role = columnDef._table?._getCellRole();
if (role) {
elementRef.nativeElement.setAttribute('role', role);
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkCell, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.0", type: CdkCell, isStandalone: true, selector: "cdk-cell, td[cdk-cell]", host: { classAttribute: "cdk-cell" }, usesInheritance: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkCell, decorators: [{
type: Directive,
args: [{
selector: 'cdk-cell, td[cdk-cell]',
host: {
'class': 'cdk-cell',
},
}]
}], ctorParameters: () => [] });
/**
* @docs-private
*/
class _Schedule {
tasks = [];
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 {
_currentSchedule = null;
_ngZone = inject(NgZone);
constructor() { }
/**
* 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);
}
_createScheduleIfNeeded() {
if (this._currentSchedule) {
return;
}
this._currentSchedule = new _Schedule();
this._ngZone.runOutsideAngular(() =>
// TODO(mmalerba): Scheduling this using something that runs less frequently
// (e.g. requestAnimationFrame, setTimeout, etc.) causes noticeable jank with the column
// resizer. We should audit the usages of schedule / scheduleEnd in that component and see
// if we can refactor it so that we don't need to flush the tasks quite so frequently.
queueMicrotask(() => {
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;
}));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: _CoalescedStyleScheduler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: _CoalescedStyleScheduler });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: _CoalescedStyleScheduler, decorators: [{
type: Injectable
}], ctorParameters: () => [] });
/**
* 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 {
template = inject(TemplateRef);
_differs = inject(IterableDiffers);
/** The columns to be displayed on this row. */
columns;
/** Differ used to check if any changes were made to the columns. */
_columnsDiffer;
constructor() { }
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;
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: BaseRowDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.0", type: BaseRowDef, isStandalone: true, usesOnChanges: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: BaseRowDef, decorators: [{
type: Directive
}], ctorParameters: () => [] });
/**
* 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 BaseRowDef {
_table = inject(CDK_TABLE, { optional: true });
_hasStickyChanged = false;
/** Whether the row is sticky. */
get sticky() {
return this._sticky;
}
set sticky(value) {
if (value !== this._sticky) {
this._sticky = value;
this._hasStickyChanged = true;
}
}
_sticky = false;
constructor() {
super(inject(TemplateRef), inject(IterableDiffers));
}
// 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);
}
/** Whether the sticky state has changed. */
hasStickyChanged() {
const hasStickyChanged = this._hasStickyChanged;
this.resetStickyChanged();
return hasStickyChanged;
}
/** Resets the sticky changed state. */
resetStickyChanged() {
this._hasStickyChanged = false;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkHeaderRowDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.0", type: CdkHeaderRowDef, isStandalone: true, selector: "[cdkHeaderRowDef]", inputs: { columns: ["cdkHeaderRowDef", "columns"], sticky: ["cdkHeaderRowDefSticky", "sticky", booleanAttribute] }, usesInheritance: true, usesOnChanges: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkHeaderRowDef, decorators: [{
type: Directive,
args: [{
selector: '[cdkHeaderRowDef]',
inputs: [{ name: 'columns', alias: 'cdkHeaderRowDef' }],
}]
}], ctorParameters: () => [], propDecorators: { sticky: [{
type: Input,
args: [{ alias: 'cdkHeaderRowDefSticky', transform: booleanAttribute }]
}] } });
/**
* 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 BaseRowDef {
_table = inject(CDK_TABLE, { optional: true });
_hasStickyChanged = false;
/** Whether the row is sticky. */
get sticky() {
return this._sticky;
}
set sticky(value) {
if (value !== this._sticky) {
this._sticky = value;
this._hasStickyChanged = true;
}
}
_sticky = false;
constructor() {
super(inject(TemplateRef), inject(IterableDiffers));
}
// 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);
}
/** Whether the sticky state has changed. */
hasStickyChanged() {
const hasStickyChanged = this._hasStickyChanged;
this.resetStickyChanged();
return hasStickyChanged;
}
/** Resets the sticky changed state. */
resetStickyChanged() {
this._hasStickyChanged = false;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkFooterRowDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.0", type: CdkFooterRowDef, isStandalone: true, selector: "[cdkFooterRowDef]", inputs: { columns: ["cdkFooterRowDef", "columns"], sticky: ["cdkFooterRowDefSticky", "sticky", booleanAttribute] }, usesInheritance: true, usesOnChanges: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkFooterRowDef, decorators: [{
type: Directive,
args: [{
selector: '[cdkFooterRowDef]',
inputs: [{ name: 'columns', alias: 'cdkFooterRowDef' }],
}]
}], ctorParameters: () => [], propDecorators: { sticky: [{
type: Input,
args: [{ alias: 'cdkFooterRowDefSticky', transform: booleanAttribute }]
}] } });
/**
* 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 {
_table = inject(CDK_TABLE, { optional: true });
/**
* 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.
*/
when;
constructor() {
// TODO(andrewseguin): Add an input for providing a switch function to determine
// if this template should be used.
super(inject(TemplateRef), inject(IterableDiffers));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkRowDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.0", type: CdkRowDef, isStandalone: true, selector: "[cdkRowDef]", inputs: { columns: ["cdkRowDefColumns", "columns"], when: ["cdkRowDefWhen", "when"] }, usesInheritance: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkRowDef, decorators: [{
type: Directive,
args: [{
selector: '[cdkRowDef]',
inputs: [
{ name: 'columns', alias: 'cdkRowDefColumns' },
{ name: 'when', alias: 'cdkRowDefWhen' },
],
}]
}], ctorParameters: () => [] });
/**
* Outlet for rendering cells inside of a row or header row.
* @docs-private
*/
class CdkCellOutlet {
_viewContainer = inject(ViewContainerRef);
/** The ordered list of cells to render within this outlet's view container */
cells;
/** The data context to be provided to each cell */
context;
/**
* 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.
*/
static mostRecentCellOutlet = null;
constructor() {
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 ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkCellOutlet, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.0", type: CdkCellOutlet, isStandalone: true, selector: "[cdkCellOutlet]", ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkCellOutlet, decorators: [{
type: Directive,
args: [{
selector: '[cdkCellOutlet]',
}]
}], ctorParameters: () => [] });
/** Header template container that contains the cell outlet. Adds the right class and role. */
class CdkHeaderRow {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkHeaderRow, deps: [], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.0", type: CdkHeaderRow, isStandalone: true, 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, dependencies: [{ kind: "directive", type: CdkCellOutlet, selector: "[cdkCellOutlet]" }], changeDetection: i0.ChangeDetectionStrategy.Default, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.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,
imports: [CdkCellOutlet],
}]
}] });
/** Footer template container that contains the cell outlet. Adds the right class and role. */
class CdkFooterRow {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkFooterRow, deps: [], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.0", type: CdkFooterRow, isStandalone: true, 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, dependencies: [{ kind: "directive", type: CdkCellOutlet, selector: "[cdkCellOutlet]" }], changeDetection: i0.ChangeDetectionStrategy.Default, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.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,
imports: [CdkCellOutlet],
}]
}] });
/** Data row template container that contains the cell outlet. Adds the right class and role. */
class CdkRow {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkRow, deps: [], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.0", type: CdkRow, isStandalone: true, selector: "cdk-row, tr[cdk-row]", host: { attributes: { "role": "row" }, classAttribute: "cdk-row" }, ngImport: i0, template: "<ng-container cdkCellOutlet></ng-container>", isInline: true, dependencies: [{ kind: "directive", type: CdkCellOutlet, selector: "[cdkCellOutlet]" }], changeDetection: i0.ChangeDetectionStrategy.Default, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.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,
imports: [CdkCellOutlet],
}]
}] });
/** Row that can be used to display a message when no data is shown in the table. */
class CdkNoDataRow {
templateRef = inject(TemplateRef);
_contentClassName = 'cdk-no-data-row';
constructor() { }
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkNoDataRow, deps: [], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.0", type: CdkNoDataRow, isStandalone: true, selector: "ng-template[cdkNoDataRow]", ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CdkNoDataRow, decorators: [{
type: Directive,
args: [{
selector: 'ng-template[cdkNoDataRow]',
}]
}], ctorParameters: () => [] });
/**
* Directions that can be used when setting sticky positioning.
* @docs-private
*/
/**
* 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 {
_isNativeHtmlTable;
_stickCellCss;
direction;
_coalescedStyleScheduler;
_isBrowser;
_needsPositionStickyOnElement;
_positionListener;
_tableInjector;
_elemSizeCache = new WeakMap();
_resizeObserver = globalThis?.ResizeObserver
? new globalThis.ResizeObserver(entries => this._updateCachedSizes(entries))
: null;
_updatedStickyColumnsParamsToReplay = [];
_stickyColumnsReplayTimeout = null;
_cachedCellWidths = [];
_borderCellCss;
_destroyed = false;
/**
* @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.
* @param _tableInjector The table's Injector.
*/
constructor(_isNativeHtmlTable, _stickCellCss, direction, _coalescedStyleScheduler, _isBrowser = true, _needsPositionStickyOnElement = true, _positionListener, _tableInjector) {
this._isNativeHtmlTable = _isNativeHtmlTable;
this._stickCellCss = _stickCellCss;
this.direction = direction;
this._coalescedStyleScheduler = _coalescedStyleScheduler;
this._isBrowser = _isBrowser;
this._needsPositionStickyOnElement = _needsPositionStickyOnElement;
this._positionListener = _positionListener;
this._tableInjector = _tableInjector;
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) {
if (stickyDirections.includes('left') || stickyDirections.includes('right')) {
this._removeFromStickyColumnReplayQueue(rows);
}
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, ...Array.from(row.children));
}
// Coalesce with sticky row/column updates (and potentially other changes like column resize).
this._afterNextRender({
write: () => {
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.
* @param replay Whether to enqueue this call for replay after a ResizeObserver update.
*/
updateStickyColumns(rows, stickyStartStates, stickyEndStates, recalculateCellWidths = true, replay = true) {
// Don't cache any state if none of the columns are sticky.
if (!rows.length ||
!this._isBrowser ||
!(stickyStartStates.some(state => state) || stickyEndStates.some(state => state))) {
this._positionListener?.stickyColumnsUpdated({ sizes: [] });
this._positionListener?.stickyEndColumnsUpdated({ sizes: [] });
return;
}
// Coalesce with sticky row updates (and potentially other changes like column resize).
const firstRow = rows[0];
const numCells = firstRow.children.length;
const isRtl = this.direction === 'rtl';
const start = isRtl ? 'right' : 'left';
const end = isRtl ? 'left' : 'right';
const lastStickyStart = stickyStartStates.lastIndexOf(true);
const firstStickyEnd = stickyEndStates.indexOf(true);
let cellWidths;
let startPositions;
let endPositions;
if (replay) {
this._updateStickyColumnReplayQueue({
rows: [...rows],
stickyStartStates: [...stickyStartStates],
stickyEndStates: [...stickyEndStates],
});
}
this._afterNextRender({
earlyRead: () => {
cellWidths = this._getCellWidths(firstRow, recalculateCellWidths);
startPositions = this._getStickyStartColumnPositions(cellWidths, stickyStartStates);
endPositions = this._getStickyEndColumnPositions(cellWidths, stickyEndStates);
},
write: () => {
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 && cellWidths.some(w => !!w)) {
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 = [];
// Coalesce with other sticky row updates (top/bottom), sticky columns updates
// (and potentially other changes like column resize).
this._afterNextRender({
earlyRead: () => {
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 = this._retrieveElementSize(row).height;
stickyOffset += height;
stickyCellHeights[rowIndex] = height;
}
},
write: () => {
const borderedRowIndex = states.lastIndexOf(true);
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
if (!states[rowIndex]) {
continue;
}
const offset = stickyOffsets[rowIndex];
const isBorderedRowIndex = rowIndex === borderedRowIndex;
for (const element of elementsToStick[rowIndex]) {
this._addStickyStyle(element, position, offset, isBorderedRowIndex);
}
}
if (position === 'top') {
this._positionListener?.stickyHeaderRowsUpdated({
sizes: stickyCellHeights,
offsets: stickyOffsets,
elements: elementsToStick,
});
}
else {
this._positionListener?.stickyFooterRowsUpdated({
sizes: stickyCellHeights,
offsets: stickyOffsets,
elements: elementsToStick,
});
}
},
});
}
/**
* When using the native table in Safari, sticky footer cells do not stick. The only way to stick
* footer rows is to apply sticky styling to the tfoot container. This should only be done if
* all footer rows are sticky. If not all footer rows are sticky, remove sticky positioning from
* the tfoot element.
*/
updateStickyFooterContainer(tableElement, stickyStates) {
if (!this._isNativeHtmlTable) {
return;
}
// Coalesce with other sticky updates (and potentially other changes like column resize).
this._afterNextRender({
write: () => {
const tfoot = tableElement.querySelector('tfoot');
if (tfoot) {
if (stickyStates.some(state => !state)) {
this._removeStickyStyle(tfoot, ['bottom']);
}
else {
this._addStickyStyle(tfoot, 'bottom', 0, false);
}
}
},
});
}
/** Triggered by the table's OnDestroy hook. */
destroy() {
if (this._stickyColumnsReplayTimeout) {
clearTimeout(this._stickyColumnsReplayTimeout);
}
this._resizeObserver?.disconnect();
this._destroyed = true;
}
/**
* 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) {
if (!element.classList.contains(this._stickCellCss)) {
return;
}
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++) {
const cell = firstRowCells[i];
cellWidths.push(this._retrieveElementSize(cell).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;