/**
* @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 { ChangeDetectionStrategy, Component, Inject, Input, Optional, ViewChild, ViewEncapsulation, } from '@angular/core';
import { CdkCellDef, CdkColumnDef, CdkHeaderCellDef } from './cell';
import { CdkTable } from './table';
import { getTableTextColumnMissingParentTableError, getTableTextColumnMissingNameError, } from './table-errors';
import { TEXT_COLUMN_OPTIONS } from './tokens';
import * as i0 from "@angular/core";
import * as i1 from "./table";
import * as i2 from "./cell";
/**
* Column that simply shows text content for the header and row cells. Assumes that the table
* is using the native table implementation (`
`).
*
* By default, the name of this column will be the header text and data property accessor.
* The header text can be overridden with the `headerText` input. Cell values can be overridden with
* the `dataAccessor` input. Change the text justification to the start or end using the `justify`
* input.
*/
export class CdkTextColumn {
/** Column name that should be used to reference this column. */
get name() {
return this._name;
}
set name(name) {
this._name = name;
// With Ivy, inputs can be initialized before static query results are
// available. In that case, we defer the synchronization until "ngOnInit" fires.
this._syncColumnDefName();
}
constructor(
// `CdkTextColumn` is always requiring a table, but we just assert it manually
// for better error reporting.
// tslint:disable-next-line: lightweight-tokens
_table, _options) {
this._table = _table;
this._options = _options;
/** Alignment of the cell values. */
this.justify = 'start';
this._options = _options || {};
}
ngOnInit() {
this._syncColumnDefName();
if (this.headerText === undefined) {
this.headerText = this._createDefaultHeaderText();
}
if (!this.dataAccessor) {
this.dataAccessor =
this._options.defaultDataAccessor || ((data, name) => data[name]);
}
if (this._table) {
// Provide the cell and headerCell directly to the table with the static `ViewChild` query,
// since the columnDef will not pick up its content by the time the table finishes checking
// its content and initializing the rows.
this.columnDef.cell = this.cell;
this.columnDef.headerCell = this.headerCell;
this._table.addColumnDef(this.columnDef);
}
else if (typeof ngDevMode === 'undefined' || ngDevMode) {
throw getTableTextColumnMissingParentTableError();
}
}
ngOnDestroy() {
if (this._table) {
this._table.removeColumnDef(this.columnDef);
}
}
/**
* Creates a default header text. Use the options' header text transformation function if one
* has been provided. Otherwise simply capitalize the column name.
*/
_createDefaultHeaderText() {
const name = this.name;
if (!name && (typeof ngDevMode === 'undefined' || ngDevMode)) {
throw getTableTextColumnMissingNameError();
}
if (this._options && this._options.defaultHeaderTextTransform) {
return this._options.defaultHeaderTextTransform(name);
}
return name[0].toUpperCase() + name.slice(1);
}
/** Synchronizes the column definition name with the text column name. */
_syncColumnDefName() {
if (this.columnDef) {
this.columnDef.name = this.name;
}
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkTextColumn, deps: [{ token: i1.CdkTable, optional: true }, { token: TEXT_COLUMN_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.1", type: CdkTextColumn, selector: "cdk-text-column", inputs: { name: "name", headerText: "headerText", dataAccessor: "dataAccessor", justify: "justify" }, viewQueries: [{ propertyName: "columnDef", first: true, predicate: CdkColumnDef, descendants: true, static: true }, { propertyName: "cell", first: true, predicate: CdkCellDef, descendants: true, static: true }, { propertyName: "headerCell", first: true, predicate: CdkHeaderCellDef, descendants: true, static: true }], ngImport: i0, template: `
{{headerText}}
|
{{dataAccessor(data, name)}}
|
`, isInline: true, dependencies: [{ kind: "directive", type: i2.CdkCellDef, selector: "[cdkCellDef]" }, { kind: "directive", type: i2.CdkHeaderCellDef, selector: "[cdkHeaderCellDef]" }, { kind: "directive", type: i2.CdkColumnDef, selector: "[cdkColumnDef]", inputs: ["sticky", "cdkColumnDef", "stickyEnd"] }, { kind: "directive", type: i2.CdkCell, selector: "cdk-cell, td[cdk-cell]" }, { kind: "directive", type: i2.CdkHeaderCell, selector: "cdk-header-cell, th[cdk-header-cell]" }], changeDetection: i0.ChangeDetectionStrategy.Default, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkTextColumn, decorators: [{
type: Component,
args: [{
selector: 'cdk-text-column',
template: `
{{headerText}}
|
{{dataAccessor(data, name)}}
|
`,
encapsulation: ViewEncapsulation.None,
// Change detection is intentionally not set to OnPush. This component's template will be provided
// to the table to be inserted into its view. This is problematic when change detection runs since
// the bindings in this template will be evaluated _after_ the table's view is evaluated, which
// mean's the template in the table's view will not have the updated value (and in fact will cause
// an ExpressionChangedAfterItHasBeenCheckedError).
// tslint:disable-next-line:validate-decorators
changeDetection: ChangeDetectionStrategy.Default,
}]
}], ctorParameters: function () { return [{ type: i1.CdkTable, decorators: [{
type: Optional
}] }, { type: undefined, decorators: [{
type: Optional
}, {
type: Inject,
args: [TEXT_COLUMN_OPTIONS]
}] }]; }, propDecorators: { name: [{
type: Input
}], headerText: [{
type: Input
}], dataAccessor: [{
type: Input
}], justify: [{
type: Input
}], columnDef: [{
type: ViewChild,
args: [CdkColumnDef, { static: true }]
}], cell: [{
type: ViewChild,
args: [CdkCellDef, { static: true }]
}], headerCell: [{
type: ViewChild,
args: [CdkHeaderCellDef, { static: true }]
}] } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGV4dC1jb2x1bW4uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL3RhYmxlL3RleHQtY29sdW1uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFDTCx1QkFBdUIsRUFDdkIsU0FBUyxFQUNULE1BQU0sRUFDTixLQUFLLEVBR0wsUUFBUSxFQUNSLFNBQVMsRUFDVCxpQkFBaUIsR0FDbEIsTUFBTSxlQUFlLENBQUM7QUFDdkIsT0FBTyxFQUFDLFVBQVUsRUFBRSxZQUFZLEVBQUUsZ0JBQWdCLEVBQUMsTUFBTSxRQUFRLENBQUM7QUFDbEUsT0FBTyxFQUFDLFFBQVEsR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