table.mjs 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602
  1. import { i as isDataSource } from './data-source-D34wiQZj.mjs';
  2. export { D as DataSource } from './data-source-D34wiQZj.mjs';
  3. import { DOCUMENT } from '@angular/common';
  4. import * as i0 from '@angular/core';
  5. 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';
  6. import { Subject, BehaviorSubject, isObservable, of } from 'rxjs';
  7. import { takeUntil } from 'rxjs/operators';
  8. import { b as _VIEW_REPEATER_STRATEGY, _ as _RecycleViewRepeaterStrategy, a as _ViewRepeaterOperation } from './recycle-view-repeater-strategy-DoWdPqVw.mjs';
  9. import { _ as _DisposeViewRepeaterStrategy } from './dispose-view-repeater-strategy-D_JReLI1.mjs';
  10. import { D as Directionality } from './directionality-CBXD4hga.mjs';
  11. import { P as Platform } from './platform-DmdVEw_C.mjs';
  12. import { ViewportRuler, ScrollingModule } from './scrolling.mjs';
  13. import { c as coerceBooleanProperty } from './boolean-property-DaaVhX5A.mjs';
  14. import './element-x4z00URv.mjs';
  15. import './scrolling-BkvA05C8.mjs';
  16. import './bidi.mjs';
  17. /**
  18. * Used to provide a table to some of the sub-components without causing a circular dependency.
  19. * @docs-private
  20. */
  21. const CDK_TABLE = new InjectionToken('CDK_TABLE');
  22. /** Injection token that can be used to specify the text column options. */
  23. const TEXT_COLUMN_OPTIONS = new InjectionToken('text-column-options');
  24. /**
  25. * Cell definition for a CDK table.
  26. * Captures the template of a column's data row cell as well as cell-specific properties.
  27. */
  28. class CdkCellDef {
  29. /** @docs-private */
  30. template = inject(TemplateRef);
  31. constructor() { }
  32. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkCellDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  33. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: CdkCellDef, isStandalone: true, selector: "[cdkCellDef]", ngImport: i0 });
  34. }
  35. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkCellDef, decorators: [{
  36. type: Directive,
  37. args: [{
  38. selector: '[cdkCellDef]',
  39. }]
  40. }], ctorParameters: () => [] });
  41. /**
  42. * Header cell definition for a CDK table.
  43. * Captures the template of a column's header cell and as well as cell-specific properties.
  44. */
  45. class CdkHeaderCellDef {
  46. /** @docs-private */
  47. template = inject(TemplateRef);
  48. constructor() { }
  49. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkHeaderCellDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  50. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: CdkHeaderCellDef, isStandalone: true, selector: "[cdkHeaderCellDef]", ngImport: i0 });
  51. }
  52. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkHeaderCellDef, decorators: [{
  53. type: Directive,
  54. args: [{
  55. selector: '[cdkHeaderCellDef]',
  56. }]
  57. }], ctorParameters: () => [] });
  58. /**
  59. * Footer cell definition for a CDK table.
  60. * Captures the template of a column's footer cell and as well as cell-specific properties.
  61. */
  62. class CdkFooterCellDef {
  63. /** @docs-private */
  64. template = inject(TemplateRef);
  65. constructor() { }
  66. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkFooterCellDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  67. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: CdkFooterCellDef, isStandalone: true, selector: "[cdkFooterCellDef]", ngImport: i0 });
  68. }
  69. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkFooterCellDef, decorators: [{
  70. type: Directive,
  71. args: [{
  72. selector: '[cdkFooterCellDef]',
  73. }]
  74. }], ctorParameters: () => [] });
  75. /**
  76. * Column definition for the CDK table.
  77. * Defines a set of cells available for a table column.
  78. */
  79. class CdkColumnDef {
  80. _table = inject(CDK_TABLE, { optional: true });
  81. _hasStickyChanged = false;
  82. /** Unique name for this column. */
  83. get name() {
  84. return this._name;
  85. }
  86. set name(name) {
  87. this._setNameInput(name);
  88. }
  89. _name;
  90. /** Whether the cell is sticky. */
  91. get sticky() {
  92. return this._sticky;
  93. }
  94. set sticky(value) {
  95. if (value !== this._sticky) {
  96. this._sticky = value;
  97. this._hasStickyChanged = true;
  98. }
  99. }
  100. _sticky = false;
  101. /**
  102. * Whether this column should be sticky positioned on the end of the row. Should make sure
  103. * that it mimics the `CanStick` mixin such that `_hasStickyChanged` is set to true if the value
  104. * has been changed.
  105. */
  106. get stickyEnd() {
  107. return this._stickyEnd;
  108. }
  109. set stickyEnd(value) {
  110. if (value !== this._stickyEnd) {
  111. this._stickyEnd = value;
  112. this._hasStickyChanged = true;
  113. }
  114. }
  115. _stickyEnd = false;
  116. /** @docs-private */
  117. cell;
  118. /** @docs-private */
  119. headerCell;
  120. /** @docs-private */
  121. footerCell;
  122. /**
  123. * Transformed version of the column name that can be used as part of a CSS classname. Excludes
  124. * all non-alphanumeric characters and the special characters '-' and '_'. Any characters that
  125. * do not match are replaced by the '-' character.
  126. */
  127. cssClassFriendlyName;
  128. /**
  129. * Class name for cells in this column.
  130. * @docs-private
  131. */
  132. _columnCssClassName;
  133. constructor() { }
  134. /** Whether the sticky state has changed. */
  135. hasStickyChanged() {
  136. const hasStickyChanged = this._hasStickyChanged;
  137. this.resetStickyChanged();
  138. return hasStickyChanged;
  139. }
  140. /** Resets the sticky changed state. */
  141. resetStickyChanged() {
  142. this._hasStickyChanged = false;
  143. }
  144. /**
  145. * Overridable method that sets the css classes that will be added to every cell in this
  146. * column.
  147. * In the future, columnCssClassName will change from type string[] to string and this
  148. * will set a single string value.
  149. * @docs-private
  150. */
  151. _updateColumnCssClassName() {
  152. this._columnCssClassName = [`cdk-column-${this.cssClassFriendlyName}`];
  153. }
  154. /**
  155. * This has been extracted to a util because of TS 4 and VE.
  156. * View Engine doesn't support property rename inheritance.
  157. * TS 4.0 doesn't allow properties to override accessors or vice-versa.
  158. * @docs-private
  159. */
  160. _setNameInput(value) {
  161. // If the directive is set without a name (updated programmatically), then this setter will
  162. // trigger with an empty string and should not overwrite the programmatically set value.
  163. if (value) {
  164. this._name = value;
  165. this.cssClassFriendlyName = value.replace(/[^a-z0-9_-]/gi, '-');
  166. this._updateColumnCssClassName();
  167. }
  168. }
  169. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkColumnDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  170. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.6", 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 });
  171. }
  172. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkColumnDef, decorators: [{
  173. type: Directive,
  174. args: [{
  175. selector: '[cdkColumnDef]',
  176. providers: [{ provide: 'MAT_SORT_HEADER_COLUMN_DEF', useExisting: CdkColumnDef }],
  177. }]
  178. }], ctorParameters: () => [], propDecorators: { name: [{
  179. type: Input,
  180. args: ['cdkColumnDef']
  181. }], sticky: [{
  182. type: Input,
  183. args: [{ transform: booleanAttribute }]
  184. }], stickyEnd: [{
  185. type: Input,
  186. args: [{ transform: booleanAttribute }]
  187. }], cell: [{
  188. type: ContentChild,
  189. args: [CdkCellDef]
  190. }], headerCell: [{
  191. type: ContentChild,
  192. args: [CdkHeaderCellDef]
  193. }], footerCell: [{
  194. type: ContentChild,
  195. args: [CdkFooterCellDef]
  196. }] } });
  197. /** Base class for the cells. Adds a CSS classname that identifies the column it renders in. */
  198. class BaseCdkCell {
  199. constructor(columnDef, elementRef) {
  200. elementRef.nativeElement.classList.add(...columnDef._columnCssClassName);
  201. }
  202. }
  203. /** Header cell template container that adds the right classes and role. */
  204. class CdkHeaderCell extends BaseCdkCell {
  205. constructor() {
  206. super(inject(CdkColumnDef), inject(ElementRef));
  207. }
  208. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkHeaderCell, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  209. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: CdkHeaderCell, isStandalone: true, selector: "cdk-header-cell, th[cdk-header-cell]", host: { attributes: { "role": "columnheader" }, classAttribute: "cdk-header-cell" }, usesInheritance: true, ngImport: i0 });
  210. }
  211. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkHeaderCell, decorators: [{
  212. type: Directive,
  213. args: [{
  214. selector: 'cdk-header-cell, th[cdk-header-cell]',
  215. host: {
  216. 'class': 'cdk-header-cell',
  217. 'role': 'columnheader',
  218. },
  219. }]
  220. }], ctorParameters: () => [] });
  221. /** Footer cell template container that adds the right classes and role. */
  222. class CdkFooterCell extends BaseCdkCell {
  223. constructor() {
  224. const columnDef = inject(CdkColumnDef);
  225. const elementRef = inject(ElementRef);
  226. super(columnDef, elementRef);
  227. const role = columnDef._table?._getCellRole();
  228. if (role) {
  229. elementRef.nativeElement.setAttribute('role', role);
  230. }
  231. }
  232. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkFooterCell, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  233. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: CdkFooterCell, isStandalone: true, selector: "cdk-footer-cell, td[cdk-footer-cell]", host: { classAttribute: "cdk-footer-cell" }, usesInheritance: true, ngImport: i0 });
  234. }
  235. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkFooterCell, decorators: [{
  236. type: Directive,
  237. args: [{
  238. selector: 'cdk-footer-cell, td[cdk-footer-cell]',
  239. host: {
  240. 'class': 'cdk-footer-cell',
  241. },
  242. }]
  243. }], ctorParameters: () => [] });
  244. /** Cell template container that adds the right classes and role. */
  245. class CdkCell extends BaseCdkCell {
  246. constructor() {
  247. const columnDef = inject(CdkColumnDef);
  248. const elementRef = inject(ElementRef);
  249. super(columnDef, elementRef);
  250. const role = columnDef._table?._getCellRole();
  251. if (role) {
  252. elementRef.nativeElement.setAttribute('role', role);
  253. }
  254. }
  255. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkCell, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  256. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: CdkCell, isStandalone: true, selector: "cdk-cell, td[cdk-cell]", host: { classAttribute: "cdk-cell" }, usesInheritance: true, ngImport: i0 });
  257. }
  258. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkCell, decorators: [{
  259. type: Directive,
  260. args: [{
  261. selector: 'cdk-cell, td[cdk-cell]',
  262. host: {
  263. 'class': 'cdk-cell',
  264. },
  265. }]
  266. }], ctorParameters: () => [] });
  267. /**
  268. * @docs-private
  269. */
  270. class _Schedule {
  271. tasks = [];
  272. endTasks = [];
  273. }
  274. /** Injection token used to provide a coalesced style scheduler. */
  275. const _COALESCED_STYLE_SCHEDULER = new InjectionToken('_COALESCED_STYLE_SCHEDULER');
  276. /**
  277. * Allows grouping up CSSDom mutations after the current execution context.
  278. * This can significantly improve performance when separate consecutive functions are
  279. * reading from the CSSDom and then mutating it.
  280. *
  281. * @docs-private
  282. */
  283. class _CoalescedStyleScheduler {
  284. _currentSchedule = null;
  285. _ngZone = inject(NgZone);
  286. constructor() { }
  287. /**
  288. * Schedules the specified task to run at the end of the current VM turn.
  289. */
  290. schedule(task) {
  291. this._createScheduleIfNeeded();
  292. this._currentSchedule.tasks.push(task);
  293. }
  294. /**
  295. * Schedules the specified task to run after other scheduled tasks at the end of the current
  296. * VM turn.
  297. */
  298. scheduleEnd(task) {
  299. this._createScheduleIfNeeded();
  300. this._currentSchedule.endTasks.push(task);
  301. }
  302. _createScheduleIfNeeded() {
  303. if (this._currentSchedule) {
  304. return;
  305. }
  306. this._currentSchedule = new _Schedule();
  307. this._ngZone.runOutsideAngular(() =>
  308. // TODO(mmalerba): Scheduling this using something that runs less frequently
  309. // (e.g. requestAnimationFrame, setTimeout, etc.) causes noticeable jank with the column
  310. // resizer. We should audit the usages of schedule / scheduleEnd in that component and see
  311. // if we can refactor it so that we don't need to flush the tasks quite so frequently.
  312. queueMicrotask(() => {
  313. while (this._currentSchedule.tasks.length || this._currentSchedule.endTasks.length) {
  314. const schedule = this._currentSchedule;
  315. // Capture new tasks scheduled by the current set of tasks.
  316. this._currentSchedule = new _Schedule();
  317. for (const task of schedule.tasks) {
  318. task();
  319. }
  320. for (const task of schedule.endTasks) {
  321. task();
  322. }
  323. }
  324. this._currentSchedule = null;
  325. }));
  326. }
  327. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: _CoalescedStyleScheduler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  328. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: _CoalescedStyleScheduler });
  329. }
  330. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: _CoalescedStyleScheduler, decorators: [{
  331. type: Injectable
  332. }], ctorParameters: () => [] });
  333. /**
  334. * The row template that can be used by the mat-table. Should not be used outside of the
  335. * material library.
  336. */
  337. const CDK_ROW_TEMPLATE = `<ng-container cdkCellOutlet></ng-container>`;
  338. /**
  339. * Base class for the CdkHeaderRowDef and CdkRowDef that handles checking their columns inputs
  340. * for changes and notifying the table.
  341. */
  342. class BaseRowDef {
  343. template = inject(TemplateRef);
  344. _differs = inject(IterableDiffers);
  345. /** The columns to be displayed on this row. */
  346. columns;
  347. /** Differ used to check if any changes were made to the columns. */
  348. _columnsDiffer;
  349. constructor() { }
  350. ngOnChanges(changes) {
  351. // Create a new columns differ if one does not yet exist. Initialize it based on initial value
  352. // of the columns property or an empty array if none is provided.
  353. if (!this._columnsDiffer) {
  354. const columns = (changes['columns'] && changes['columns'].currentValue) || [];
  355. this._columnsDiffer = this._differs.find(columns).create();
  356. this._columnsDiffer.diff(columns);
  357. }
  358. }
  359. /**
  360. * Returns the difference between the current columns and the columns from the last diff, or null
  361. * if there is no difference.
  362. */
  363. getColumnsDiff() {
  364. return this._columnsDiffer.diff(this.columns);
  365. }
  366. /** Gets this row def's relevant cell template from the provided column def. */
  367. extractCellTemplate(column) {
  368. if (this instanceof CdkHeaderRowDef) {
  369. return column.headerCell.template;
  370. }
  371. if (this instanceof CdkFooterRowDef) {
  372. return column.footerCell.template;
  373. }
  374. else {
  375. return column.cell.template;
  376. }
  377. }
  378. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: BaseRowDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  379. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: BaseRowDef, isStandalone: true, usesOnChanges: true, ngImport: i0 });
  380. }
  381. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: BaseRowDef, decorators: [{
  382. type: Directive
  383. }], ctorParameters: () => [] });
  384. /**
  385. * Header row definition for the CDK table.
  386. * Captures the header row's template and other header properties such as the columns to display.
  387. */
  388. class CdkHeaderRowDef extends BaseRowDef {
  389. _table = inject(CDK_TABLE, { optional: true });
  390. _hasStickyChanged = false;
  391. /** Whether the row is sticky. */
  392. get sticky() {
  393. return this._sticky;
  394. }
  395. set sticky(value) {
  396. if (value !== this._sticky) {
  397. this._sticky = value;
  398. this._hasStickyChanged = true;
  399. }
  400. }
  401. _sticky = false;
  402. constructor() {
  403. super(inject(TemplateRef), inject(IterableDiffers));
  404. }
  405. // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
  406. // Explicitly define it so that the method is called as part of the Angular lifecycle.
  407. ngOnChanges(changes) {
  408. super.ngOnChanges(changes);
  409. }
  410. /** Whether the sticky state has changed. */
  411. hasStickyChanged() {
  412. const hasStickyChanged = this._hasStickyChanged;
  413. this.resetStickyChanged();
  414. return hasStickyChanged;
  415. }
  416. /** Resets the sticky changed state. */
  417. resetStickyChanged() {
  418. this._hasStickyChanged = false;
  419. }
  420. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkHeaderRowDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  421. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.6", type: CdkHeaderRowDef, isStandalone: true, selector: "[cdkHeaderRowDef]", inputs: { columns: ["cdkHeaderRowDef", "columns"], sticky: ["cdkHeaderRowDefSticky", "sticky", booleanAttribute] }, usesInheritance: true, usesOnChanges: true, ngImport: i0 });
  422. }
  423. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkHeaderRowDef, decorators: [{
  424. type: Directive,
  425. args: [{
  426. selector: '[cdkHeaderRowDef]',
  427. inputs: [{ name: 'columns', alias: 'cdkHeaderRowDef' }],
  428. }]
  429. }], ctorParameters: () => [], propDecorators: { sticky: [{
  430. type: Input,
  431. args: [{ alias: 'cdkHeaderRowDefSticky', transform: booleanAttribute }]
  432. }] } });
  433. /**
  434. * Footer row definition for the CDK table.
  435. * Captures the footer row's template and other footer properties such as the columns to display.
  436. */
  437. class CdkFooterRowDef extends BaseRowDef {
  438. _table = inject(CDK_TABLE, { optional: true });
  439. _hasStickyChanged = false;
  440. /** Whether the row is sticky. */
  441. get sticky() {
  442. return this._sticky;
  443. }
  444. set sticky(value) {
  445. if (value !== this._sticky) {
  446. this._sticky = value;
  447. this._hasStickyChanged = true;
  448. }
  449. }
  450. _sticky = false;
  451. constructor() {
  452. super(inject(TemplateRef), inject(IterableDiffers));
  453. }
  454. // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
  455. // Explicitly define it so that the method is called as part of the Angular lifecycle.
  456. ngOnChanges(changes) {
  457. super.ngOnChanges(changes);
  458. }
  459. /** Whether the sticky state has changed. */
  460. hasStickyChanged() {
  461. const hasStickyChanged = this._hasStickyChanged;
  462. this.resetStickyChanged();
  463. return hasStickyChanged;
  464. }
  465. /** Resets the sticky changed state. */
  466. resetStickyChanged() {
  467. this._hasStickyChanged = false;
  468. }
  469. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkFooterRowDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  470. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.6", type: CdkFooterRowDef, isStandalone: true, selector: "[cdkFooterRowDef]", inputs: { columns: ["cdkFooterRowDef", "columns"], sticky: ["cdkFooterRowDefSticky", "sticky", booleanAttribute] }, usesInheritance: true, usesOnChanges: true, ngImport: i0 });
  471. }
  472. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkFooterRowDef, decorators: [{
  473. type: Directive,
  474. args: [{
  475. selector: '[cdkFooterRowDef]',
  476. inputs: [{ name: 'columns', alias: 'cdkFooterRowDef' }],
  477. }]
  478. }], ctorParameters: () => [], propDecorators: { sticky: [{
  479. type: Input,
  480. args: [{ alias: 'cdkFooterRowDefSticky', transform: booleanAttribute }]
  481. }] } });
  482. /**
  483. * Data row definition for the CDK table.
  484. * Captures the header row's template and other row properties such as the columns to display and
  485. * a when predicate that describes when this row should be used.
  486. */
  487. class CdkRowDef extends BaseRowDef {
  488. _table = inject(CDK_TABLE, { optional: true });
  489. /**
  490. * Function that should return true if this row template should be used for the provided index
  491. * and row data. If left undefined, this row will be considered the default row template to use
  492. * when no other when functions return true for the data.
  493. * For every row, there must be at least one when function that passes or an undefined to default.
  494. */
  495. when;
  496. constructor() {
  497. // TODO(andrewseguin): Add an input for providing a switch function to determine
  498. // if this template should be used.
  499. super(inject(TemplateRef), inject(IterableDiffers));
  500. }
  501. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkRowDef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  502. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: CdkRowDef, isStandalone: true, selector: "[cdkRowDef]", inputs: { columns: ["cdkRowDefColumns", "columns"], when: ["cdkRowDefWhen", "when"] }, usesInheritance: true, ngImport: i0 });
  503. }
  504. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkRowDef, decorators: [{
  505. type: Directive,
  506. args: [{
  507. selector: '[cdkRowDef]',
  508. inputs: [
  509. { name: 'columns', alias: 'cdkRowDefColumns' },
  510. { name: 'when', alias: 'cdkRowDefWhen' },
  511. ],
  512. }]
  513. }], ctorParameters: () => [] });
  514. /**
  515. * Outlet for rendering cells inside of a row or header row.
  516. * @docs-private
  517. */
  518. class CdkCellOutlet {
  519. _viewContainer = inject(ViewContainerRef);
  520. /** The ordered list of cells to render within this outlet's view container */
  521. cells;
  522. /** The data context to be provided to each cell */
  523. context;
  524. /**
  525. * Static property containing the latest constructed instance of this class.
  526. * Used by the CDK table when each CdkHeaderRow and CdkRow component is created using
  527. * createEmbeddedView. After one of these components are created, this property will provide
  528. * a handle to provide that component's cells and context. After init, the CdkCellOutlet will
  529. * construct the cells with the provided context.
  530. */
  531. static mostRecentCellOutlet = null;
  532. constructor() {
  533. CdkCellOutlet.mostRecentCellOutlet = this;
  534. }
  535. ngOnDestroy() {
  536. // If this was the last outlet being rendered in the view, remove the reference
  537. // from the static property after it has been destroyed to avoid leaking memory.
  538. if (CdkCellOutlet.mostRecentCellOutlet === this) {
  539. CdkCellOutlet.mostRecentCellOutlet = null;
  540. }
  541. }
  542. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkCellOutlet, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  543. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: CdkCellOutlet, isStandalone: true, selector: "[cdkCellOutlet]", ngImport: i0 });
  544. }
  545. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkCellOutlet, decorators: [{
  546. type: Directive,
  547. args: [{
  548. selector: '[cdkCellOutlet]',
  549. }]
  550. }], ctorParameters: () => [] });
  551. /** Header template container that contains the cell outlet. Adds the right class and role. */
  552. class CdkHeaderRow {
  553. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkHeaderRow, deps: [], target: i0.ɵɵFactoryTarget.Component });
  554. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", 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 });
  555. }
  556. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkHeaderRow, decorators: [{
  557. type: Component,
  558. args: [{
  559. selector: 'cdk-header-row, tr[cdk-header-row]',
  560. template: CDK_ROW_TEMPLATE,
  561. host: {
  562. 'class': 'cdk-header-row',
  563. 'role': 'row',
  564. },
  565. // See note on CdkTable for explanation on why this uses the default change detection strategy.
  566. // tslint:disable-next-line:validate-decorators
  567. changeDetection: ChangeDetectionStrategy.Default,
  568. encapsulation: ViewEncapsulation.None,
  569. imports: [CdkCellOutlet],
  570. }]
  571. }] });
  572. /** Footer template container that contains the cell outlet. Adds the right class and role. */
  573. class CdkFooterRow {
  574. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkFooterRow, deps: [], target: i0.ɵɵFactoryTarget.Component });
  575. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", 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 });
  576. }
  577. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkFooterRow, decorators: [{
  578. type: Component,
  579. args: [{
  580. selector: 'cdk-footer-row, tr[cdk-footer-row]',
  581. template: CDK_ROW_TEMPLATE,
  582. host: {
  583. 'class': 'cdk-footer-row',
  584. 'role': 'row',
  585. },
  586. // See note on CdkTable for explanation on why this uses the default change detection strategy.
  587. // tslint:disable-next-line:validate-decorators
  588. changeDetection: ChangeDetectionStrategy.Default,
  589. encapsulation: ViewEncapsulation.None,
  590. imports: [CdkCellOutlet],
  591. }]
  592. }] });
  593. /** Data row template container that contains the cell outlet. Adds the right class and role. */
  594. class CdkRow {
  595. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkRow, deps: [], target: i0.ɵɵFactoryTarget.Component });
  596. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", 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 });
  597. }
  598. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkRow, decorators: [{
  599. type: Component,
  600. args: [{
  601. selector: 'cdk-row, tr[cdk-row]',
  602. template: CDK_ROW_TEMPLATE,
  603. host: {
  604. 'class': 'cdk-row',
  605. 'role': 'row',
  606. },
  607. // See note on CdkTable for explanation on why this uses the default change detection strategy.
  608. // tslint:disable-next-line:validate-decorators
  609. changeDetection: ChangeDetectionStrategy.Default,
  610. encapsulation: ViewEncapsulation.None,
  611. imports: [CdkCellOutlet],
  612. }]
  613. }] });
  614. /** Row that can be used to display a message when no data is shown in the table. */
  615. class CdkNoDataRow {
  616. templateRef = inject(TemplateRef);
  617. _contentClassName = 'cdk-no-data-row';
  618. constructor() { }
  619. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkNoDataRow, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  620. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: CdkNoDataRow, isStandalone: true, selector: "ng-template[cdkNoDataRow]", ngImport: i0 });
  621. }
  622. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkNoDataRow, decorators: [{
  623. type: Directive,
  624. args: [{
  625. selector: 'ng-template[cdkNoDataRow]',
  626. }]
  627. }], ctorParameters: () => [] });
  628. /**
  629. * Directions that can be used when setting sticky positioning.
  630. * @docs-private
  631. */
  632. /**
  633. * List of all possible directions that can be used for sticky positioning.
  634. * @docs-private
  635. */
  636. const STICKY_DIRECTIONS = ['top', 'bottom', 'left', 'right'];
  637. /**
  638. * Applies and removes sticky positioning styles to the `CdkTable` rows and columns cells.
  639. * @docs-private
  640. */
  641. class StickyStyler {
  642. _isNativeHtmlTable;
  643. _stickCellCss;
  644. direction;
  645. _coalescedStyleScheduler;
  646. _isBrowser;
  647. _needsPositionStickyOnElement;
  648. _positionListener;
  649. _tableInjector;
  650. _elemSizeCache = new WeakMap();
  651. _resizeObserver = globalThis?.ResizeObserver
  652. ? new globalThis.ResizeObserver(entries => this._updateCachedSizes(entries))
  653. : null;
  654. _updatedStickyColumnsParamsToReplay = [];
  655. _stickyColumnsReplayTimeout = null;
  656. _cachedCellWidths = [];
  657. _borderCellCss;
  658. _destroyed = false;
  659. /**
  660. * @param _isNativeHtmlTable Whether the sticky logic should be based on a table
  661. * that uses the native `<table>` element.
  662. * @param _stickCellCss The CSS class that will be applied to every row/cell that has
  663. * sticky positioning applied.
  664. * @param direction The directionality context of the table (ltr/rtl); affects column positioning
  665. * by reversing left/right positions.
  666. * @param _isBrowser Whether the table is currently being rendered on the server or the client.
  667. * @param _needsPositionStickyOnElement Whether we need to specify position: sticky on cells
  668. * using inline styles. If false, it is assumed that position: sticky is included in
  669. * the component stylesheet for _stickCellCss.
  670. * @param _positionListener A listener that is notified of changes to sticky rows/columns
  671. * and their dimensions.
  672. * @param _tableInjector The table's Injector.
  673. */
  674. constructor(_isNativeHtmlTable, _stickCellCss, direction, _coalescedStyleScheduler, _isBrowser = true, _needsPositionStickyOnElement = true, _positionListener, _tableInjector) {
  675. this._isNativeHtmlTable = _isNativeHtmlTable;
  676. this._stickCellCss = _stickCellCss;
  677. this.direction = direction;
  678. this._coalescedStyleScheduler = _coalescedStyleScheduler;
  679. this._isBrowser = _isBrowser;
  680. this._needsPositionStickyOnElement = _needsPositionStickyOnElement;
  681. this._positionListener = _positionListener;
  682. this._tableInjector = _tableInjector;
  683. this._borderCellCss = {
  684. 'top': `${_stickCellCss}-border-elem-top`,
  685. 'bottom': `${_stickCellCss}-border-elem-bottom`,
  686. 'left': `${_stickCellCss}-border-elem-left`,
  687. 'right': `${_stickCellCss}-border-elem-right`,
  688. };
  689. }
  690. /**
  691. * Clears the sticky positioning styles from the row and its cells by resetting the `position`
  692. * style, setting the zIndex to 0, and unsetting each provided sticky direction.
  693. * @param rows The list of rows that should be cleared from sticking in the provided directions
  694. * @param stickyDirections The directions that should no longer be set as sticky on the rows.
  695. */
  696. clearStickyPositioning(rows, stickyDirections) {
  697. if (stickyDirections.includes('left') || stickyDirections.includes('right')) {
  698. this._removeFromStickyColumnReplayQueue(rows);
  699. }
  700. const elementsToClear = [];
  701. for (const row of rows) {
  702. // If the row isn't an element (e.g. if it's an `ng-container`),
  703. // it won't have inline styles or `children` so we skip it.
  704. if (row.nodeType !== row.ELEMENT_NODE) {
  705. continue;
  706. }
  707. elementsToClear.push(row, ...Array.from(row.children));
  708. }
  709. // Coalesce with sticky row/column updates (and potentially other changes like column resize).
  710. this._afterNextRender({
  711. write: () => {
  712. for (const element of elementsToClear) {
  713. this._removeStickyStyle(element, stickyDirections);
  714. }
  715. },
  716. });
  717. }
  718. /**
  719. * Applies sticky left and right positions to the cells of each row according to the sticky
  720. * states of the rendered column definitions.
  721. * @param rows The rows that should have its set of cells stuck according to the sticky states.
  722. * @param stickyStartStates A list of boolean states where each state represents whether the cell
  723. * in this index position should be stuck to the start of the row.
  724. * @param stickyEndStates A list of boolean states where each state represents whether the cell
  725. * in this index position should be stuck to the end of the row.
  726. * @param recalculateCellWidths Whether the sticky styler should recalculate the width of each
  727. * column cell. If `false` cached widths will be used instead.
  728. * @param replay Whether to enqueue this call for replay after a ResizeObserver update.
  729. */
  730. updateStickyColumns(rows, stickyStartStates, stickyEndStates, recalculateCellWidths = true, replay = true) {
  731. // Don't cache any state if none of the columns are sticky.
  732. if (!rows.length ||
  733. !this._isBrowser ||
  734. !(stickyStartStates.some(state => state) || stickyEndStates.some(state => state))) {
  735. this._positionListener?.stickyColumnsUpdated({ sizes: [] });
  736. this._positionListener?.stickyEndColumnsUpdated({ sizes: [] });
  737. return;
  738. }
  739. // Coalesce with sticky row updates (and potentially other changes like column resize).
  740. const firstRow = rows[0];
  741. const numCells = firstRow.children.length;
  742. const isRtl = this.direction === 'rtl';
  743. const start = isRtl ? 'right' : 'left';
  744. const end = isRtl ? 'left' : 'right';
  745. const lastStickyStart = stickyStartStates.lastIndexOf(true);
  746. const firstStickyEnd = stickyEndStates.indexOf(true);
  747. let cellWidths;
  748. let startPositions;
  749. let endPositions;
  750. if (replay) {
  751. this._updateStickyColumnReplayQueue({
  752. rows: [...rows],
  753. stickyStartStates: [...stickyStartStates],
  754. stickyEndStates: [...stickyEndStates],
  755. });
  756. }
  757. this._afterNextRender({
  758. earlyRead: () => {
  759. cellWidths = this._getCellWidths(firstRow, recalculateCellWidths);
  760. startPositions = this._getStickyStartColumnPositions(cellWidths, stickyStartStates);
  761. endPositions = this._getStickyEndColumnPositions(cellWidths, stickyEndStates);
  762. },
  763. write: () => {
  764. for (const row of rows) {
  765. for (let i = 0; i < numCells; i++) {
  766. const cell = row.children[i];
  767. if (stickyStartStates[i]) {
  768. this._addStickyStyle(cell, start, startPositions[i], i === lastStickyStart);
  769. }
  770. if (stickyEndStates[i]) {
  771. this._addStickyStyle(cell, end, endPositions[i], i === firstStickyEnd);
  772. }
  773. }
  774. }
  775. if (this._positionListener && cellWidths.some(w => !!w)) {
  776. this._positionListener.stickyColumnsUpdated({
  777. sizes: lastStickyStart === -1
  778. ? []
  779. : cellWidths
  780. .slice(0, lastStickyStart + 1)
  781. .map((width, index) => (stickyStartStates[index] ? width : null)),
  782. });
  783. this._positionListener.stickyEndColumnsUpdated({
  784. sizes: firstStickyEnd === -1
  785. ? []
  786. : cellWidths
  787. .slice(firstStickyEnd)
  788. .map((width, index) => (stickyEndStates[index + firstStickyEnd] ? width : null))
  789. .reverse(),
  790. });
  791. }
  792. },
  793. });
  794. }
  795. /**
  796. * Applies sticky positioning to the row's cells if using the native table layout, and to the
  797. * row itself otherwise.
  798. * @param rowsToStick The list of rows that should be stuck according to their corresponding
  799. * sticky state and to the provided top or bottom position.
  800. * @param stickyStates A list of boolean states where each state represents whether the row
  801. * should be stuck in the particular top or bottom position.
  802. * @param position The position direction in which the row should be stuck if that row should be
  803. * sticky.
  804. *
  805. */
  806. stickRows(rowsToStick, stickyStates, position) {
  807. // Since we can't measure the rows on the server, we can't stick the rows properly.
  808. if (!this._isBrowser) {
  809. return;
  810. }
  811. // If positioning the rows to the bottom, reverse their order when evaluating the sticky
  812. // position such that the last row stuck will be "bottom: 0px" and so on. Note that the
  813. // sticky states need to be reversed as well.
  814. const rows = position === 'bottom' ? rowsToStick.slice().reverse() : rowsToStick;
  815. const states = position === 'bottom' ? stickyStates.slice().reverse() : stickyStates;
  816. // Measure row heights all at once before adding sticky styles to reduce layout thrashing.
  817. const stickyOffsets = [];
  818. const stickyCellHeights = [];
  819. const elementsToStick = [];
  820. // Coalesce with other sticky row updates (top/bottom), sticky columns updates
  821. // (and potentially other changes like column resize).
  822. this._afterNextRender({
  823. earlyRead: () => {
  824. for (let rowIndex = 0, stickyOffset = 0; rowIndex < rows.length; rowIndex++) {
  825. if (!states[rowIndex]) {
  826. continue;
  827. }
  828. stickyOffsets[rowIndex] = stickyOffset;
  829. const row = rows[rowIndex];
  830. elementsToStick[rowIndex] = this._isNativeHtmlTable
  831. ? Array.from(row.children)
  832. : [row];
  833. const height = this._retrieveElementSize(row).height;
  834. stickyOffset += height;
  835. stickyCellHeights[rowIndex] = height;
  836. }
  837. },
  838. write: () => {
  839. const borderedRowIndex = states.lastIndexOf(true);
  840. for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
  841. if (!states[rowIndex]) {
  842. continue;
  843. }
  844. const offset = stickyOffsets[rowIndex];
  845. const isBorderedRowIndex = rowIndex === borderedRowIndex;
  846. for (const element of elementsToStick[rowIndex]) {
  847. this._addStickyStyle(element, position, offset, isBorderedRowIndex);
  848. }
  849. }
  850. if (position === 'top') {
  851. this._positionListener?.stickyHeaderRowsUpdated({
  852. sizes: stickyCellHeights,
  853. offsets: stickyOffsets,
  854. elements: elementsToStick,
  855. });
  856. }
  857. else {
  858. this._positionListener?.stickyFooterRowsUpdated({
  859. sizes: stickyCellHeights,
  860. offsets: stickyOffsets,
  861. elements: elementsToStick,
  862. });
  863. }
  864. },
  865. });
  866. }
  867. /**
  868. * When using the native table in Safari, sticky footer cells do not stick. The only way to stick
  869. * footer rows is to apply sticky styling to the tfoot container. This should only be done if
  870. * all footer rows are sticky. If not all footer rows are sticky, remove sticky positioning from
  871. * the tfoot element.
  872. */
  873. updateStickyFooterContainer(tableElement, stickyStates) {
  874. if (!this._isNativeHtmlTable) {
  875. return;
  876. }
  877. // Coalesce with other sticky updates (and potentially other changes like column resize).
  878. this._afterNextRender({
  879. write: () => {
  880. const tfoot = tableElement.querySelector('tfoot');
  881. if (tfoot) {
  882. if (stickyStates.some(state => !state)) {
  883. this._removeStickyStyle(tfoot, ['bottom']);
  884. }
  885. else {
  886. this._addStickyStyle(tfoot, 'bottom', 0, false);
  887. }
  888. }
  889. },
  890. });
  891. }
  892. /** Triggered by the table's OnDestroy hook. */
  893. destroy() {
  894. if (this._stickyColumnsReplayTimeout) {
  895. clearTimeout(this._stickyColumnsReplayTimeout);
  896. }
  897. this._resizeObserver?.disconnect();
  898. this._destroyed = true;
  899. }
  900. /**
  901. * Removes the sticky style on the element by removing the sticky cell CSS class, re-evaluating
  902. * the zIndex, removing each of the provided sticky directions, and removing the
  903. * sticky position if there are no more directions.
  904. */
  905. _removeStickyStyle(element, stickyDirections) {
  906. if (!element.classList.contains(this._stickCellCss)) {
  907. return;
  908. }
  909. for (const dir of stickyDirections) {
  910. element.style[dir] = '';
  911. element.classList.remove(this._borderCellCss[dir]);
  912. }
  913. // If the element no longer has any more sticky directions, remove sticky positioning and
  914. // the sticky CSS class.
  915. // Short-circuit checking element.style[dir] for stickyDirections as they
  916. // were already removed above.
  917. const hasDirection = STICKY_DIRECTIONS.some(dir => stickyDirections.indexOf(dir) === -1 && element.style[dir]);
  918. if (hasDirection) {
  919. element.style.zIndex = this._getCalculatedZIndex(element);
  920. }
  921. else {
  922. // When not hasDirection, _getCalculatedZIndex will always return ''.
  923. element.style.zIndex = '';
  924. if (this._needsPositionStickyOnElement) {
  925. element.style.position = '';
  926. }
  927. element.classList.remove(this._stickCellCss);
  928. }
  929. }
  930. /**
  931. * Adds the sticky styling to the element by adding the sticky style class, changing position
  932. * to be sticky (and -webkit-sticky), setting the appropriate zIndex, and adding a sticky
  933. * direction and value.
  934. */
  935. _addStickyStyle(element, dir, dirValue, isBorderElement) {
  936. element.classList.add(this._stickCellCss);
  937. if (isBorderElement) {
  938. element.classList.add(this._borderCellCss[dir]);
  939. }
  940. element.style[dir] = `${dirValue}px`;
  941. element.style.zIndex = this._getCalculatedZIndex(element);
  942. if (this._needsPositionStickyOnElement) {
  943. element.style.cssText += 'position: -webkit-sticky; position: sticky; ';
  944. }
  945. }
  946. /**
  947. * Calculate what the z-index should be for the element, depending on what directions (top,
  948. * bottom, left, right) have been set. It should be true that elements with a top direction
  949. * should have the highest index since these are elements like a table header. If any of those
  950. * elements are also sticky in another direction, then they should appear above other elements
  951. * that are only sticky top (e.g. a sticky column on a sticky header). Bottom-sticky elements
  952. * (e.g. footer rows) should then be next in the ordering such that they are below the header
  953. * but above any non-sticky elements. Finally, left/right sticky elements (e.g. sticky columns)
  954. * should minimally increment so that they are above non-sticky elements but below top and bottom
  955. * elements.
  956. */
  957. _getCalculatedZIndex(element) {
  958. const zIndexIncrements = {
  959. top: 100,
  960. bottom: 10,
  961. left: 1,
  962. right: 1,
  963. };
  964. let zIndex = 0;
  965. // Use `Iterable` instead of `Array` because TypeScript, as of 3.6.3,
  966. // loses the array generic type in the `for of`. But we *also* have to use `Array` because
  967. // typescript won't iterate over an `Iterable` unless you compile with `--downlevelIteration`
  968. for (const dir of STICKY_DIRECTIONS) {
  969. if (element.style[dir]) {
  970. zIndex += zIndexIncrements[dir];
  971. }
  972. }
  973. return zIndex ? `${zIndex}` : '';
  974. }
  975. /** Gets the widths for each cell in the provided row. */
  976. _getCellWidths(row, recalculateCellWidths = true) {
  977. if (!recalculateCellWidths && this._cachedCellWidths.length) {
  978. return this._cachedCellWidths;
  979. }
  980. const cellWidths = [];
  981. const firstRowCells = row.children;
  982. for (let i = 0; i < firstRowCells.length; i++) {
  983. const cell = firstRowCells[i];
  984. cellWidths.push(this._retrieveElementSize(cell).width);
  985. }
  986. this._cachedCellWidths = cellWidths;
  987. return cellWidths;
  988. }
  989. /**
  990. * Determines the left and right positions of each sticky column cell, which will be the
  991. * accumulation of all sticky column cell widths to the left and right, respectively.
  992. * Non-sticky cells do not need to have a value set since their positions will not be applied.
  993. */
  994. _getStickyStartColumnPositions(widths, stickyStates) {
  995. const positions = [];
  996. let nextPosition = 0;
  997. for (let i = 0; i < widths.length; i++) {
  998. if (stickyStates[i]) {
  999. positions[i] = nextPosition;
  1000. nextPosition += widths[i];
  1001. }
  1002. }
  1003. return positions;
  1004. }
  1005. /**
  1006. * Determines the left and right positions of each sticky column cell, which will be the
  1007. * accumulation of all sticky column cell widths to the left and right, respectively.
  1008. * Non-sticky cells do not need to have a value set since their positions will not be applied.
  1009. */
  1010. _getStickyEndColumnPositions(widths, stickyStates) {
  1011. const positions = [];
  1012. let nextPosition = 0;
  1013. for (let i = widths.length; i > 0; i--) {
  1014. if (stickyStates[i]) {
  1015. positions[i] = nextPosition;
  1016. nextPosition += widths[i];
  1017. }
  1018. }
  1019. return positions;
  1020. }
  1021. /**
  1022. * Retreives the most recently observed size of the specified element from the cache, or
  1023. * meaures it directly if not yet cached.
  1024. */
  1025. _retrieveElementSize(element) {
  1026. const cachedSize = this._elemSizeCache.get(element);
  1027. if (cachedSize) {
  1028. return cachedSize;
  1029. }
  1030. const clientRect = element.getBoundingClientRect();
  1031. const size = { width: clientRect.width, height: clientRect.height };
  1032. if (!this._resizeObserver) {
  1033. return size;
  1034. }
  1035. this._elemSizeCache.set(element, size);
  1036. this._resizeObserver.observe(element, { box: 'border-box' });
  1037. return size;
  1038. }
  1039. /**
  1040. * Conditionally enqueue the requested sticky update and clear previously queued updates
  1041. * for the same rows.
  1042. */
  1043. _updateStickyColumnReplayQueue(params) {
  1044. this._removeFromStickyColumnReplayQueue(params.rows);
  1045. // No need to replay if a flush is pending.
  1046. if (!this._stickyColumnsReplayTimeout) {
  1047. this._updatedStickyColumnsParamsToReplay.push(params);
  1048. }
  1049. }
  1050. /** Remove updates for the specified rows from the queue. */
  1051. _removeFromStickyColumnReplayQueue(rows) {
  1052. const rowsSet = new Set(rows);
  1053. for (const update of this._updatedStickyColumnsParamsToReplay) {
  1054. update.rows = update.rows.filter(row => !rowsSet.has(row));
  1055. }
  1056. this._updatedStickyColumnsParamsToReplay = this._updatedStickyColumnsParamsToReplay.filter(update => !!update.rows.length);
  1057. }
  1058. /** Update _elemSizeCache with the observed sizes. */
  1059. _updateCachedSizes(entries) {
  1060. let needsColumnUpdate = false;
  1061. for (const entry of entries) {
  1062. const newEntry = entry.borderBoxSize?.length
  1063. ? {
  1064. width: entry.borderBoxSize[0].inlineSize,
  1065. height: entry.borderBoxSize[0].blockSize,
  1066. }
  1067. : {
  1068. width: entry.contentRect.width,
  1069. height: entry.contentRect.height,
  1070. };
  1071. if (newEntry.width !== this._elemSizeCache.get(entry.target)?.width &&
  1072. isCell(entry.target)) {
  1073. needsColumnUpdate = true;
  1074. }
  1075. this._elemSizeCache.set(entry.target, newEntry);
  1076. }
  1077. if (needsColumnUpdate && this._updatedStickyColumnsParamsToReplay.length) {
  1078. if (this._stickyColumnsReplayTimeout) {
  1079. clearTimeout(this._stickyColumnsReplayTimeout);
  1080. }
  1081. this._stickyColumnsReplayTimeout = setTimeout(() => {
  1082. if (this._destroyed) {
  1083. return;
  1084. }
  1085. for (const update of this._updatedStickyColumnsParamsToReplay) {
  1086. this.updateStickyColumns(update.rows, update.stickyStartStates, update.stickyEndStates, true, false);
  1087. }
  1088. this._updatedStickyColumnsParamsToReplay = [];
  1089. this._stickyColumnsReplayTimeout = null;
  1090. }, 0);
  1091. }
  1092. }
  1093. /**
  1094. * Invoke afterNextRender with the table's injector, falling back to CoalescedStyleScheduler
  1095. * if the injector was not provided.
  1096. */
  1097. _afterNextRender(spec) {
  1098. if (this._tableInjector) {
  1099. afterNextRender(spec, { injector: this._tableInjector });
  1100. }
  1101. else {
  1102. this._coalescedStyleScheduler.schedule(() => {
  1103. spec.earlyRead?.();
  1104. spec.write();
  1105. });
  1106. }
  1107. }
  1108. }
  1109. function isCell(element) {
  1110. return ['cdk-cell', 'cdk-header-cell', 'cdk-footer-cell'].some(klass => element.classList.contains(klass));
  1111. }
  1112. /**
  1113. * Returns an error to be thrown when attempting to find an nonexistent column.
  1114. * @param id Id whose lookup failed.
  1115. * @docs-private
  1116. */
  1117. function getTableUnknownColumnError(id) {
  1118. return Error(`Could not find column with id "${id}".`);
  1119. }
  1120. /**
  1121. * Returns an error to be thrown when two column definitions have the same name.
  1122. * @docs-private
  1123. */
  1124. function getTableDuplicateColumnNameError(name) {
  1125. return Error(`Duplicate column definition name provided: "${name}".`);
  1126. }
  1127. /**
  1128. * Returns an error to be thrown when there are multiple rows that are missing a when function.
  1129. * @docs-private
  1130. */
  1131. function getTableMultipleDefaultRowDefsError() {
  1132. return Error(`There can only be one default row without a when predicate function.`);
  1133. }
  1134. /**
  1135. * Returns an error to be thrown when there are no matching row defs for a particular set of data.
  1136. * @docs-private
  1137. */
  1138. function getTableMissingMatchingRowDefError(data) {
  1139. return Error(`Could not find a matching row definition for the` +
  1140. `provided row data: ${JSON.stringify(data)}`);
  1141. }
  1142. /**
  1143. * Returns an error to be thrown when there is no row definitions present in the content.
  1144. * @docs-private
  1145. */
  1146. function getTableMissingRowDefsError() {
  1147. return Error('Missing definitions for header, footer, and row; ' +
  1148. 'cannot determine which columns should be rendered.');
  1149. }
  1150. /**
  1151. * Returns an error to be thrown when the data source does not match the compatible types.
  1152. * @docs-private
  1153. */
  1154. function getTableUnknownDataSourceError() {
  1155. return Error(`Provided data source did not match an array, Observable, or DataSource`);
  1156. }
  1157. /**
  1158. * Returns an error to be thrown when the text column cannot find a parent table to inject.
  1159. * @docs-private
  1160. */
  1161. function getTableTextColumnMissingParentTableError() {
  1162. return Error(`Text column could not find a parent table for registration.`);
  1163. }
  1164. /**
  1165. * Returns an error to be thrown when a table text column doesn't have a name.
  1166. * @docs-private
  1167. */
  1168. function getTableTextColumnMissingNameError() {
  1169. return Error(`Table text column must have a name.`);
  1170. }
  1171. /** The injection token used to specify the StickyPositioningListener. */
  1172. const STICKY_POSITIONING_LISTENER = new InjectionToken('CDK_SPL');
  1173. /**
  1174. * Enables the recycle view repeater strategy, which reduces rendering latency. Not compatible with
  1175. * tables that animate rows.
  1176. */
  1177. class CdkRecycleRows {
  1178. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkRecycleRows, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  1179. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: CdkRecycleRows, isStandalone: true, selector: "cdk-table[recycleRows], table[cdk-table][recycleRows]", providers: [{ provide: _VIEW_REPEATER_STRATEGY, useClass: _RecycleViewRepeaterStrategy }], ngImport: i0 });
  1180. }
  1181. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkRecycleRows, decorators: [{
  1182. type: Directive,
  1183. args: [{
  1184. selector: 'cdk-table[recycleRows], table[cdk-table][recycleRows]',
  1185. providers: [{ provide: _VIEW_REPEATER_STRATEGY, useClass: _RecycleViewRepeaterStrategy }],
  1186. }]
  1187. }] });
  1188. /**
  1189. * Provides a handle for the table to grab the view container's ng-container to insert data rows.
  1190. * @docs-private
  1191. */
  1192. class DataRowOutlet {
  1193. viewContainer = inject(ViewContainerRef);
  1194. elementRef = inject(ElementRef);
  1195. constructor() {
  1196. const table = inject(CDK_TABLE);
  1197. table._rowOutlet = this;
  1198. table._outletAssigned();
  1199. }
  1200. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: DataRowOutlet, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  1201. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: DataRowOutlet, isStandalone: true, selector: "[rowOutlet]", ngImport: i0 });
  1202. }
  1203. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: DataRowOutlet, decorators: [{
  1204. type: Directive,
  1205. args: [{
  1206. selector: '[rowOutlet]',
  1207. }]
  1208. }], ctorParameters: () => [] });
  1209. /**
  1210. * Provides a handle for the table to grab the view container's ng-container to insert the header.
  1211. * @docs-private
  1212. */
  1213. class HeaderRowOutlet {
  1214. viewContainer = inject(ViewContainerRef);
  1215. elementRef = inject(ElementRef);
  1216. constructor() {
  1217. const table = inject(CDK_TABLE);
  1218. table._headerRowOutlet = this;
  1219. table._outletAssigned();
  1220. }
  1221. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: HeaderRowOutlet, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  1222. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: HeaderRowOutlet, isStandalone: true, selector: "[headerRowOutlet]", ngImport: i0 });
  1223. }
  1224. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: HeaderRowOutlet, decorators: [{
  1225. type: Directive,
  1226. args: [{
  1227. selector: '[headerRowOutlet]',
  1228. }]
  1229. }], ctorParameters: () => [] });
  1230. /**
  1231. * Provides a handle for the table to grab the view container's ng-container to insert the footer.
  1232. * @docs-private
  1233. */
  1234. class FooterRowOutlet {
  1235. viewContainer = inject(ViewContainerRef);
  1236. elementRef = inject(ElementRef);
  1237. constructor() {
  1238. const table = inject(CDK_TABLE);
  1239. table._footerRowOutlet = this;
  1240. table._outletAssigned();
  1241. }
  1242. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: FooterRowOutlet, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  1243. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: FooterRowOutlet, isStandalone: true, selector: "[footerRowOutlet]", ngImport: i0 });
  1244. }
  1245. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: FooterRowOutlet, decorators: [{
  1246. type: Directive,
  1247. args: [{
  1248. selector: '[footerRowOutlet]',
  1249. }]
  1250. }], ctorParameters: () => [] });
  1251. /**
  1252. * Provides a handle for the table to grab the view
  1253. * container's ng-container to insert the no data row.
  1254. * @docs-private
  1255. */
  1256. class NoDataRowOutlet {
  1257. viewContainer = inject(ViewContainerRef);
  1258. elementRef = inject(ElementRef);
  1259. constructor() {
  1260. const table = inject(CDK_TABLE);
  1261. table._noDataRowOutlet = this;
  1262. table._outletAssigned();
  1263. }
  1264. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NoDataRowOutlet, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  1265. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: NoDataRowOutlet, isStandalone: true, selector: "[noDataRowOutlet]", ngImport: i0 });
  1266. }
  1267. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NoDataRowOutlet, decorators: [{
  1268. type: Directive,
  1269. args: [{
  1270. selector: '[noDataRowOutlet]',
  1271. }]
  1272. }], ctorParameters: () => [] });
  1273. /**
  1274. * The table template that can be used by the mat-table. Should not be used outside of the
  1275. * material library.
  1276. * @docs-private
  1277. */
  1278. const CDK_TABLE_TEMPLATE =
  1279. // Note that according to MDN, the `caption` element has to be projected as the **first**
  1280. // element in the table. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption
  1281. `
  1282. <ng-content select="caption"/>
  1283. <ng-content select="colgroup, col"/>
  1284. <!--
  1285. Unprojected content throws a hydration error so we need this to capture it.
  1286. It gets removed on the client so it doesn't affect the layout.
  1287. -->
  1288. @if (_isServer) {
  1289. <ng-content/>
  1290. }
  1291. @if (_isNativeHtmlTable) {
  1292. <thead role="rowgroup">
  1293. <ng-container headerRowOutlet/>
  1294. </thead>
  1295. <tbody role="rowgroup">
  1296. <ng-container rowOutlet/>
  1297. <ng-container noDataRowOutlet/>
  1298. </tbody>
  1299. <tfoot role="rowgroup">
  1300. <ng-container footerRowOutlet/>
  1301. </tfoot>
  1302. } @else {
  1303. <ng-container headerRowOutlet/>
  1304. <ng-container rowOutlet/>
  1305. <ng-container noDataRowOutlet/>
  1306. <ng-container footerRowOutlet/>
  1307. }
  1308. `;
  1309. /**
  1310. * A data table that can render a header row, data rows, and a footer row.
  1311. * Uses the dataSource input to determine the data to be rendered. The data can be provided either
  1312. * as a data array, an Observable stream that emits the data array to render, or a DataSource with a
  1313. * connect function that will return an Observable stream that emits the data array to render.
  1314. */
  1315. class CdkTable {
  1316. _differs = inject(IterableDiffers);
  1317. _changeDetectorRef = inject(ChangeDetectorRef);
  1318. _elementRef = inject(ElementRef);
  1319. _dir = inject(Directionality, { optional: true });
  1320. _platform = inject(Platform);
  1321. _viewRepeater = inject(_VIEW_REPEATER_STRATEGY);
  1322. _coalescedStyleScheduler = inject(_COALESCED_STYLE_SCHEDULER);
  1323. _viewportRuler = inject(ViewportRuler);
  1324. _stickyPositioningListener = inject(STICKY_POSITIONING_LISTENER, { optional: true, skipSelf: true });
  1325. _document = inject(DOCUMENT);
  1326. /** Latest data provided by the data source. */
  1327. _data;
  1328. /** Subject that emits when the component has been destroyed. */
  1329. _onDestroy = new Subject();
  1330. /** List of the rendered rows as identified by their `RenderRow` object. */
  1331. _renderRows;
  1332. /** Subscription that listens for the data provided by the data source. */
  1333. _renderChangeSubscription;
  1334. /**
  1335. * Map of all the user's defined columns (header, data, and footer cell template) identified by
  1336. * name. Collection populated by the column definitions gathered by `ContentChildren` as well as
  1337. * any custom column definitions added to `_customColumnDefs`.
  1338. */
  1339. _columnDefsByName = new Map();
  1340. /**
  1341. * Set of all row definitions that can be used by this table. Populated by the rows gathered by
  1342. * using `ContentChildren` as well as any custom row definitions added to `_customRowDefs`.
  1343. */
  1344. _rowDefs;
  1345. /**
  1346. * Set of all header row definitions that can be used by this table. Populated by the rows
  1347. * gathered by using `ContentChildren` as well as any custom row definitions added to
  1348. * `_customHeaderRowDefs`.
  1349. */
  1350. _headerRowDefs;
  1351. /**
  1352. * Set of all row definitions that can be used by this table. Populated by the rows gathered by
  1353. * using `ContentChildren` as well as any custom row definitions added to
  1354. * `_customFooterRowDefs`.
  1355. */
  1356. _footerRowDefs;
  1357. /** Differ used to find the changes in the data provided by the data source. */
  1358. _dataDiffer;
  1359. /** Stores the row definition that does not have a when predicate. */
  1360. _defaultRowDef;
  1361. /**
  1362. * Column definitions that were defined outside of the direct content children of the table.
  1363. * These will be defined when, e.g., creating a wrapper around the cdkTable that has
  1364. * column definitions as *its* content child.
  1365. */
  1366. _customColumnDefs = new Set();
  1367. /**
  1368. * Data row definitions that were defined outside of the direct content children of the table.
  1369. * These will be defined when, e.g., creating a wrapper around the cdkTable that has
  1370. * built-in data rows as *its* content child.
  1371. */
  1372. _customRowDefs = new Set();
  1373. /**
  1374. * Header row definitions that were defined outside of the direct content children of the table.
  1375. * These will be defined when, e.g., creating a wrapper around the cdkTable that has
  1376. * built-in header rows as *its* content child.
  1377. */
  1378. _customHeaderRowDefs = new Set();
  1379. /**
  1380. * Footer row definitions that were defined outside of the direct content children of the table.
  1381. * These will be defined when, e.g., creating a wrapper around the cdkTable that has a
  1382. * built-in footer row as *its* content child.
  1383. */
  1384. _customFooterRowDefs = new Set();
  1385. /** No data row that was defined outside of the direct content children of the table. */
  1386. _customNoDataRow;
  1387. /**
  1388. * Whether the header row definition has been changed. Triggers an update to the header row after
  1389. * content is checked. Initialized as true so that the table renders the initial set of rows.
  1390. */
  1391. _headerRowDefChanged = true;
  1392. /**
  1393. * Whether the footer row definition has been changed. Triggers an update to the footer row after
  1394. * content is checked. Initialized as true so that the table renders the initial set of rows.
  1395. */
  1396. _footerRowDefChanged = true;
  1397. /**
  1398. * Whether the sticky column styles need to be updated. Set to `true` when the visible columns
  1399. * change.
  1400. */
  1401. _stickyColumnStylesNeedReset = true;
  1402. /**
  1403. * Whether the sticky styler should recalculate cell widths when applying sticky styles. If
  1404. * `false`, cached values will be used instead. This is only applicable to tables with
  1405. * {@link fixedLayout} enabled. For other tables, cell widths will always be recalculated.
  1406. */
  1407. _forceRecalculateCellWidths = true;
  1408. /**
  1409. * Cache of the latest rendered `RenderRow` objects as a map for easy retrieval when constructing
  1410. * a new list of `RenderRow` objects for rendering rows. Since the new list is constructed with
  1411. * the cached `RenderRow` objects when possible, the row identity is preserved when the data
  1412. * and row template matches, which allows the `IterableDiffer` to check rows by reference
  1413. * and understand which rows are added/moved/removed.
  1414. *
  1415. * Implemented as a map of maps where the first key is the `data: T` object and the second is the
  1416. * `CdkRowDef<T>` object. With the two keys, the cache points to a `RenderRow<T>` object that
  1417. * contains an array of created pairs. The array is necessary to handle cases where the data
  1418. * array contains multiple duplicate data objects and each instantiated `RenderRow` must be
  1419. * stored.
  1420. */
  1421. _cachedRenderRowsMap = new Map();
  1422. /** Whether the table is applied to a native `<table>`. */
  1423. _isNativeHtmlTable;
  1424. /**
  1425. * Utility class that is responsible for applying the appropriate sticky positioning styles to
  1426. * the table's rows and cells.
  1427. */
  1428. _stickyStyler;
  1429. /**
  1430. * CSS class added to any row or cell that has sticky positioning applied. May be overridden by
  1431. * table subclasses.
  1432. */
  1433. stickyCssClass = 'cdk-table-sticky';
  1434. /**
  1435. * Whether to manually add position: sticky to all sticky cell elements. Not needed if
  1436. * the position is set in a selector associated with the value of stickyCssClass. May be
  1437. * overridden by table subclasses
  1438. */
  1439. needsPositionStickyOnElement = true;
  1440. /** Whether the component is being rendered on the server. */
  1441. _isServer;
  1442. /** Whether the no data row is currently showing anything. */
  1443. _isShowingNoDataRow = false;
  1444. /** Whether the table has rendered out all the outlets for the first time. */
  1445. _hasAllOutlets = false;
  1446. /** Whether the table is done initializing. */
  1447. _hasInitialized = false;
  1448. /** Aria role to apply to the table's cells based on the table's own role. */
  1449. _getCellRole() {
  1450. // Perform this lazily in case the table's role was updated by a directive after construction.
  1451. if (this._cellRoleInternal === undefined) {
  1452. // Note that we set `role="cell"` even on native `td` elements,
  1453. // because some browsers seem to require it. See #29784.
  1454. const tableRole = this._elementRef.nativeElement.getAttribute('role');
  1455. return tableRole === 'grid' || tableRole === 'treegrid' ? 'gridcell' : 'cell';
  1456. }
  1457. return this._cellRoleInternal;
  1458. }
  1459. _cellRoleInternal = undefined;
  1460. /**
  1461. * Tracking function that will be used to check the differences in data changes. Used similarly
  1462. * to `ngFor` `trackBy` function. Optimize row operations by identifying a row based on its data
  1463. * relative to the function to know if a row should be added/removed/moved.
  1464. * Accepts a function that takes two parameters, `index` and `item`.
  1465. */
  1466. get trackBy() {
  1467. return this._trackByFn;
  1468. }
  1469. set trackBy(fn) {
  1470. if ((typeof ngDevMode === 'undefined' || ngDevMode) && fn != null && typeof fn !== 'function') {
  1471. console.warn(`trackBy must be a function, but received ${JSON.stringify(fn)}.`);
  1472. }
  1473. this._trackByFn = fn;
  1474. }
  1475. _trackByFn;
  1476. /**
  1477. * The table's source of data, which can be provided in three ways (in order of complexity):
  1478. * - Simple data array (each object represents one table row)
  1479. * - Stream that emits a data array each time the array changes
  1480. * - `DataSource` object that implements the connect/disconnect interface.
  1481. *
  1482. * If a data array is provided, the table must be notified when the array's objects are
  1483. * added, removed, or moved. This can be done by calling the `renderRows()` function which will
  1484. * render the diff since the last table render. If the data array reference is changed, the table
  1485. * will automatically trigger an update to the rows.
  1486. *
  1487. * When providing an Observable stream, the table will trigger an update automatically when the
  1488. * stream emits a new array of data.
  1489. *
  1490. * Finally, when providing a `DataSource` object, the table will use the Observable stream
  1491. * provided by the connect function and trigger updates when that stream emits new data array
  1492. * values. During the table's ngOnDestroy or when the data source is removed from the table, the
  1493. * table will call the DataSource's `disconnect` function (may be useful for cleaning up any
  1494. * subscriptions registered during the connect process).
  1495. */
  1496. get dataSource() {
  1497. return this._dataSource;
  1498. }
  1499. set dataSource(dataSource) {
  1500. if (this._dataSource !== dataSource) {
  1501. this._switchDataSource(dataSource);
  1502. }
  1503. }
  1504. _dataSource;
  1505. /**
  1506. * Whether to allow multiple rows per data object by evaluating which rows evaluate their 'when'
  1507. * predicate to true. If `multiTemplateDataRows` is false, which is the default value, then each
  1508. * dataobject will render the first row that evaluates its when predicate to true, in the order
  1509. * defined in the table, or otherwise the default row which does not have a when predicate.
  1510. */
  1511. get multiTemplateDataRows() {
  1512. return this._multiTemplateDataRows;
  1513. }
  1514. set multiTemplateDataRows(value) {
  1515. this._multiTemplateDataRows = value;
  1516. // In Ivy if this value is set via a static attribute (e.g. <table multiTemplateDataRows>),
  1517. // this setter will be invoked before the row outlet has been defined hence the null check.
  1518. if (this._rowOutlet && this._rowOutlet.viewContainer.length) {
  1519. this._forceRenderDataRows();
  1520. this.updateStickyColumnStyles();
  1521. }
  1522. }
  1523. _multiTemplateDataRows = false;
  1524. /**
  1525. * Whether to use a fixed table layout. Enabling this option will enforce consistent column widths
  1526. * and optimize rendering sticky styles for native tables. No-op for flex tables.
  1527. */
  1528. get fixedLayout() {
  1529. return this._fixedLayout;
  1530. }
  1531. set fixedLayout(value) {
  1532. this._fixedLayout = value;
  1533. // Toggling `fixedLayout` may change column widths. Sticky column styles should be recalculated.
  1534. this._forceRecalculateCellWidths = true;
  1535. this._stickyColumnStylesNeedReset = true;
  1536. }
  1537. _fixedLayout = false;
  1538. /**
  1539. * Emits when the table completes rendering a set of data rows based on the latest data from the
  1540. * data source, even if the set of rows is empty.
  1541. */
  1542. contentChanged = new EventEmitter();
  1543. // TODO(andrewseguin): Remove max value as the end index
  1544. // and instead calculate the view on init and scroll.
  1545. /**
  1546. * Stream containing the latest information on what rows are being displayed on screen.
  1547. * Can be used by the data source to as a heuristic of what data should be provided.
  1548. *
  1549. * @docs-private
  1550. */
  1551. viewChange = new BehaviorSubject({
  1552. start: 0,
  1553. end: Number.MAX_VALUE,
  1554. });
  1555. // Outlets in the table's template where the header, data rows, and footer will be inserted.
  1556. _rowOutlet;
  1557. _headerRowOutlet;
  1558. _footerRowOutlet;
  1559. _noDataRowOutlet;
  1560. /**
  1561. * The column definitions provided by the user that contain what the header, data, and footer
  1562. * cells should render for each column.
  1563. */
  1564. _contentColumnDefs;
  1565. /** Set of data row definitions that were provided to the table as content children. */
  1566. _contentRowDefs;
  1567. /** Set of header row definitions that were provided to the table as content children. */
  1568. _contentHeaderRowDefs;
  1569. /** Set of footer row definitions that were provided to the table as content children. */
  1570. _contentFooterRowDefs;
  1571. /** Row definition that will only be rendered if there's no data in the table. */
  1572. _noDataRow;
  1573. _injector = inject(Injector);
  1574. constructor() {
  1575. const role = inject(new HostAttributeToken('role'), { optional: true });
  1576. if (!role) {
  1577. this._elementRef.nativeElement.setAttribute('role', 'table');
  1578. }
  1579. this._isServer = !this._platform.isBrowser;
  1580. this._isNativeHtmlTable = this._elementRef.nativeElement.nodeName === 'TABLE';
  1581. // Set up the trackBy function so that it uses the `RenderRow` as its identity by default. If
  1582. // the user has provided a custom trackBy, return the result of that function as evaluated
  1583. // with the values of the `RenderRow`'s data and index.
  1584. this._dataDiffer = this._differs.find([]).create((_i, dataRow) => {
  1585. return this.trackBy ? this.trackBy(dataRow.dataIndex, dataRow.data) : dataRow;
  1586. });
  1587. }
  1588. ngOnInit() {
  1589. this._setupStickyStyler();
  1590. this._viewportRuler
  1591. .change()
  1592. .pipe(takeUntil(this._onDestroy))
  1593. .subscribe(() => {
  1594. this._forceRecalculateCellWidths = true;
  1595. });
  1596. }
  1597. ngAfterContentInit() {
  1598. this._hasInitialized = true;
  1599. }
  1600. ngAfterContentChecked() {
  1601. // Only start re-rendering in `ngAfterContentChecked` after the first render.
  1602. if (this._canRender()) {
  1603. this._render();
  1604. }
  1605. }
  1606. ngOnDestroy() {
  1607. this._stickyStyler?.destroy();
  1608. [
  1609. this._rowOutlet?.viewContainer,
  1610. this._headerRowOutlet?.viewContainer,
  1611. this._footerRowOutlet?.viewContainer,
  1612. this._cachedRenderRowsMap,
  1613. this._customColumnDefs,
  1614. this._customRowDefs,
  1615. this._customHeaderRowDefs,
  1616. this._customFooterRowDefs,
  1617. this._columnDefsByName,
  1618. ].forEach((def) => {
  1619. def?.clear();
  1620. });
  1621. this._headerRowDefs = [];
  1622. this._footerRowDefs = [];
  1623. this._defaultRowDef = null;
  1624. this._onDestroy.next();
  1625. this._onDestroy.complete();
  1626. if (isDataSource(this.dataSource)) {
  1627. this.dataSource.disconnect(this);
  1628. }
  1629. }
  1630. /**
  1631. * Renders rows based on the table's latest set of data, which was either provided directly as an
  1632. * input or retrieved through an Observable stream (directly or from a DataSource).
  1633. * Checks for differences in the data since the last diff to perform only the necessary
  1634. * changes (add/remove/move rows).
  1635. *
  1636. * If the table's data source is a DataSource or Observable, this will be invoked automatically
  1637. * each time the provided Observable stream emits a new data array. Otherwise if your data is
  1638. * an array, this function will need to be called to render any changes.
  1639. */
  1640. renderRows() {
  1641. this._renderRows = this._getAllRenderRows();
  1642. const changes = this._dataDiffer.diff(this._renderRows);
  1643. if (!changes) {
  1644. this._updateNoDataRow();
  1645. this.contentChanged.next();
  1646. return;
  1647. }
  1648. const viewContainer = this._rowOutlet.viewContainer;
  1649. this._viewRepeater.applyChanges(changes, viewContainer, (record, _adjustedPreviousIndex, currentIndex) => this._getEmbeddedViewArgs(record.item, currentIndex), record => record.item.data, (change) => {
  1650. if (change.operation === _ViewRepeaterOperation.INSERTED && change.context) {
  1651. this._renderCellTemplateForItem(change.record.item.rowDef, change.context);
  1652. }
  1653. });
  1654. // Update the meta context of a row's context data (index, count, first, last, ...)
  1655. this._updateRowIndexContext();
  1656. // Update rows that did not get added/removed/moved but may have had their identity changed,
  1657. // e.g. if trackBy matched data on some property but the actual data reference changed.
  1658. changes.forEachIdentityChange((record) => {
  1659. const rowView = viewContainer.get(record.currentIndex);
  1660. rowView.context.$implicit = record.item.data;
  1661. });
  1662. this._updateNoDataRow();
  1663. this.contentChanged.next();
  1664. this.updateStickyColumnStyles();
  1665. }
  1666. /** Adds a column definition that was not included as part of the content children. */
  1667. addColumnDef(columnDef) {
  1668. this._customColumnDefs.add(columnDef);
  1669. }
  1670. /** Removes a column definition that was not included as part of the content children. */
  1671. removeColumnDef(columnDef) {
  1672. this._customColumnDefs.delete(columnDef);
  1673. }
  1674. /** Adds a row definition that was not included as part of the content children. */
  1675. addRowDef(rowDef) {
  1676. this._customRowDefs.add(rowDef);
  1677. }
  1678. /** Removes a row definition that was not included as part of the content children. */
  1679. removeRowDef(rowDef) {
  1680. this._customRowDefs.delete(rowDef);
  1681. }
  1682. /** Adds a header row definition that was not included as part of the content children. */
  1683. addHeaderRowDef(headerRowDef) {
  1684. this._customHeaderRowDefs.add(headerRowDef);
  1685. this._headerRowDefChanged = true;
  1686. }
  1687. /** Removes a header row definition that was not included as part of the content children. */
  1688. removeHeaderRowDef(headerRowDef) {
  1689. this._customHeaderRowDefs.delete(headerRowDef);
  1690. this._headerRowDefChanged = true;
  1691. }
  1692. /** Adds a footer row definition that was not included as part of the content children. */
  1693. addFooterRowDef(footerRowDef) {
  1694. this._customFooterRowDefs.add(footerRowDef);
  1695. this._footerRowDefChanged = true;
  1696. }
  1697. /** Removes a footer row definition that was not included as part of the content children. */
  1698. removeFooterRowDef(footerRowDef) {
  1699. this._customFooterRowDefs.delete(footerRowDef);
  1700. this._footerRowDefChanged = true;
  1701. }
  1702. /** Sets a no data row definition that was not included as a part of the content children. */
  1703. setNoDataRow(noDataRow) {
  1704. this._customNoDataRow = noDataRow;
  1705. }
  1706. /**
  1707. * Updates the header sticky styles. First resets all applied styles with respect to the cells
  1708. * sticking to the top. Then, evaluating which cells need to be stuck to the top. This is
  1709. * automatically called when the header row changes its displayed set of columns, or if its
  1710. * sticky input changes. May be called manually for cases where the cell content changes outside
  1711. * of these events.
  1712. */
  1713. updateStickyHeaderRowStyles() {
  1714. const headerRows = this._getRenderedRows(this._headerRowOutlet);
  1715. // Hide the thead element if there are no header rows. This is necessary to satisfy
  1716. // overzealous a11y checkers that fail because the `rowgroup` element does not contain
  1717. // required child `row`.
  1718. if (this._isNativeHtmlTable) {
  1719. const thead = closestTableSection(this._headerRowOutlet, 'thead');
  1720. if (thead) {
  1721. thead.style.display = headerRows.length ? '' : 'none';
  1722. }
  1723. }
  1724. const stickyStates = this._headerRowDefs.map(def => def.sticky);
  1725. this._stickyStyler.clearStickyPositioning(headerRows, ['top']);
  1726. this._stickyStyler.stickRows(headerRows, stickyStates, 'top');
  1727. // Reset the dirty state of the sticky input change since it has been used.
  1728. this._headerRowDefs.forEach(def => def.resetStickyChanged());
  1729. }
  1730. /**
  1731. * Updates the footer sticky styles. First resets all applied styles with respect to the cells
  1732. * sticking to the bottom. Then, evaluating which cells need to be stuck to the bottom. This is
  1733. * automatically called when the footer row changes its displayed set of columns, or if its
  1734. * sticky input changes. May be called manually for cases where the cell content changes outside
  1735. * of these events.
  1736. */
  1737. updateStickyFooterRowStyles() {
  1738. const footerRows = this._getRenderedRows(this._footerRowOutlet);
  1739. // Hide the tfoot element if there are no footer rows. This is necessary to satisfy
  1740. // overzealous a11y checkers that fail because the `rowgroup` element does not contain
  1741. // required child `row`.
  1742. if (this._isNativeHtmlTable) {
  1743. const tfoot = closestTableSection(this._footerRowOutlet, 'tfoot');
  1744. if (tfoot) {
  1745. tfoot.style.display = footerRows.length ? '' : 'none';
  1746. }
  1747. }
  1748. const stickyStates = this._footerRowDefs.map(def => def.sticky);
  1749. this._stickyStyler.clearStickyPositioning(footerRows, ['bottom']);
  1750. this._stickyStyler.stickRows(footerRows, stickyStates, 'bottom');
  1751. this._stickyStyler.updateStickyFooterContainer(this._elementRef.nativeElement, stickyStates);
  1752. // Reset the dirty state of the sticky input change since it has been used.
  1753. this._footerRowDefs.forEach(def => def.resetStickyChanged());
  1754. }
  1755. /**
  1756. * Updates the column sticky styles. First resets all applied styles with respect to the cells
  1757. * sticking to the left and right. Then sticky styles are added for the left and right according
  1758. * to the column definitions for each cell in each row. This is automatically called when
  1759. * the data source provides a new set of data or when a column definition changes its sticky
  1760. * input. May be called manually for cases where the cell content changes outside of these events.
  1761. */
  1762. updateStickyColumnStyles() {
  1763. const headerRows = this._getRenderedRows(this._headerRowOutlet);
  1764. const dataRows = this._getRenderedRows(this._rowOutlet);
  1765. const footerRows = this._getRenderedRows(this._footerRowOutlet);
  1766. // For tables not using a fixed layout, the column widths may change when new rows are rendered.
  1767. // In a table using a fixed layout, row content won't affect column width, so sticky styles
  1768. // don't need to be cleared unless either the sticky column config changes or one of the row
  1769. // defs change.
  1770. if ((this._isNativeHtmlTable && !this._fixedLayout) || this._stickyColumnStylesNeedReset) {
  1771. // Clear the left and right positioning from all columns in the table across all rows since
  1772. // sticky columns span across all table sections (header, data, footer)
  1773. this._stickyStyler.clearStickyPositioning([...headerRows, ...dataRows, ...footerRows], ['left', 'right']);
  1774. this._stickyColumnStylesNeedReset = false;
  1775. }
  1776. // Update the sticky styles for each header row depending on the def's sticky state
  1777. headerRows.forEach((headerRow, i) => {
  1778. this._addStickyColumnStyles([headerRow], this._headerRowDefs[i]);
  1779. });
  1780. // Update the sticky styles for each data row depending on its def's sticky state
  1781. this._rowDefs.forEach(rowDef => {
  1782. // Collect all the rows rendered with this row definition.
  1783. const rows = [];
  1784. for (let i = 0; i < dataRows.length; i++) {
  1785. if (this._renderRows[i].rowDef === rowDef) {
  1786. rows.push(dataRows[i]);
  1787. }
  1788. }
  1789. this._addStickyColumnStyles(rows, rowDef);
  1790. });
  1791. // Update the sticky styles for each footer row depending on the def's sticky state
  1792. footerRows.forEach((footerRow, i) => {
  1793. this._addStickyColumnStyles([footerRow], this._footerRowDefs[i]);
  1794. });
  1795. // Reset the dirty state of the sticky input change since it has been used.
  1796. Array.from(this._columnDefsByName.values()).forEach(def => def.resetStickyChanged());
  1797. }
  1798. /** Invoked whenever an outlet is created and has been assigned to the table. */
  1799. _outletAssigned() {
  1800. // Trigger the first render once all outlets have been assigned. We do it this way, as
  1801. // opposed to waiting for the next `ngAfterContentChecked`, because we don't know when
  1802. // the next change detection will happen.
  1803. // Also we can't use queries to resolve the outlets, because they're wrapped in a
  1804. // conditional, so we have to rely on them being assigned via DI.
  1805. if (!this._hasAllOutlets &&
  1806. this._rowOutlet &&
  1807. this._headerRowOutlet &&
  1808. this._footerRowOutlet &&
  1809. this._noDataRowOutlet) {
  1810. this._hasAllOutlets = true;
  1811. // In some setups this may fire before `ngAfterContentInit`
  1812. // so we need a check here. See #28538.
  1813. if (this._canRender()) {
  1814. this._render();
  1815. }
  1816. }
  1817. }
  1818. /** Whether the table has all the information to start rendering. */
  1819. _canRender() {
  1820. return this._hasAllOutlets && this._hasInitialized;
  1821. }
  1822. /** Renders the table if its state has changed. */
  1823. _render() {
  1824. // Cache the row and column definitions gathered by ContentChildren and programmatic injection.
  1825. this._cacheRowDefs();
  1826. this._cacheColumnDefs();
  1827. // Make sure that the user has at least added header, footer, or data row def.
  1828. if (!this._headerRowDefs.length &&
  1829. !this._footerRowDefs.length &&
  1830. !this._rowDefs.length &&
  1831. (typeof ngDevMode === 'undefined' || ngDevMode)) {
  1832. throw getTableMissingRowDefsError();
  1833. }
  1834. // Render updates if the list of columns have been changed for the header, row, or footer defs.
  1835. const columnsChanged = this._renderUpdatedColumns();
  1836. const rowDefsChanged = columnsChanged || this._headerRowDefChanged || this._footerRowDefChanged;
  1837. // Ensure sticky column styles are reset if set to `true` elsewhere.
  1838. this._stickyColumnStylesNeedReset = this._stickyColumnStylesNeedReset || rowDefsChanged;
  1839. this._forceRecalculateCellWidths = rowDefsChanged;
  1840. // If the header row definition has been changed, trigger a render to the header row.
  1841. if (this._headerRowDefChanged) {
  1842. this._forceRenderHeaderRows();
  1843. this._headerRowDefChanged = false;
  1844. }
  1845. // If the footer row definition has been changed, trigger a render to the footer row.
  1846. if (this._footerRowDefChanged) {
  1847. this._forceRenderFooterRows();
  1848. this._footerRowDefChanged = false;
  1849. }
  1850. // If there is a data source and row definitions, connect to the data source unless a
  1851. // connection has already been made.
  1852. if (this.dataSource && this._rowDefs.length > 0 && !this._renderChangeSubscription) {
  1853. this._observeRenderChanges();
  1854. }
  1855. else if (this._stickyColumnStylesNeedReset) {
  1856. // In the above case, _observeRenderChanges will result in updateStickyColumnStyles being
  1857. // called when it row data arrives. Otherwise, we need to call it proactively.
  1858. this.updateStickyColumnStyles();
  1859. }
  1860. this._checkStickyStates();
  1861. }
  1862. /**
  1863. * Get the list of RenderRow objects to render according to the current list of data and defined
  1864. * row definitions. If the previous list already contained a particular pair, it should be reused
  1865. * so that the differ equates their references.
  1866. */
  1867. _getAllRenderRows() {
  1868. const renderRows = [];
  1869. // Store the cache and create a new one. Any re-used RenderRow objects will be moved into the
  1870. // new cache while unused ones can be picked up by garbage collection.
  1871. const prevCachedRenderRows = this._cachedRenderRowsMap;
  1872. this._cachedRenderRowsMap = new Map();
  1873. if (!this._data) {
  1874. return renderRows;
  1875. }
  1876. // For each data object, get the list of rows that should be rendered, represented by the
  1877. // respective `RenderRow` object which is the pair of `data` and `CdkRowDef`.
  1878. for (let i = 0; i < this._data.length; i++) {
  1879. let data = this._data[i];
  1880. const renderRowsForData = this._getRenderRowsForData(data, i, prevCachedRenderRows.get(data));
  1881. if (!this._cachedRenderRowsMap.has(data)) {
  1882. this._cachedRenderRowsMap.set(data, new WeakMap());
  1883. }
  1884. for (let j = 0; j < renderRowsForData.length; j++) {
  1885. let renderRow = renderRowsForData[j];
  1886. const cache = this._cachedRenderRowsMap.get(renderRow.data);
  1887. if (cache.has(renderRow.rowDef)) {
  1888. cache.get(renderRow.rowDef).push(renderRow);
  1889. }
  1890. else {
  1891. cache.set(renderRow.rowDef, [renderRow]);
  1892. }
  1893. renderRows.push(renderRow);
  1894. }
  1895. }
  1896. return renderRows;
  1897. }
  1898. /**
  1899. * Gets a list of `RenderRow<T>` for the provided data object and any `CdkRowDef` objects that
  1900. * should be rendered for this data. Reuses the cached RenderRow objects if they match the same
  1901. * `(T, CdkRowDef)` pair.
  1902. */
  1903. _getRenderRowsForData(data, dataIndex, cache) {
  1904. const rowDefs = this._getRowDefs(data, dataIndex);
  1905. return rowDefs.map(rowDef => {
  1906. const cachedRenderRows = cache && cache.has(rowDef) ? cache.get(rowDef) : [];
  1907. if (cachedRenderRows.length) {
  1908. const dataRow = cachedRenderRows.shift();
  1909. dataRow.dataIndex = dataIndex;
  1910. return dataRow;
  1911. }
  1912. else {
  1913. return { data, rowDef, dataIndex };
  1914. }
  1915. });
  1916. }
  1917. /** Update the map containing the content's column definitions. */
  1918. _cacheColumnDefs() {
  1919. this._columnDefsByName.clear();
  1920. const columnDefs = mergeArrayAndSet(this._getOwnDefs(this._contentColumnDefs), this._customColumnDefs);
  1921. columnDefs.forEach(columnDef => {
  1922. if (this._columnDefsByName.has(columnDef.name) &&
  1923. (typeof ngDevMode === 'undefined' || ngDevMode)) {
  1924. throw getTableDuplicateColumnNameError(columnDef.name);
  1925. }
  1926. this._columnDefsByName.set(columnDef.name, columnDef);
  1927. });
  1928. }
  1929. /** Update the list of all available row definitions that can be used. */
  1930. _cacheRowDefs() {
  1931. this._headerRowDefs = mergeArrayAndSet(this._getOwnDefs(this._contentHeaderRowDefs), this._customHeaderRowDefs);
  1932. this._footerRowDefs = mergeArrayAndSet(this._getOwnDefs(this._contentFooterRowDefs), this._customFooterRowDefs);
  1933. this._rowDefs = mergeArrayAndSet(this._getOwnDefs(this._contentRowDefs), this._customRowDefs);
  1934. // After all row definitions are determined, find the row definition to be considered default.
  1935. const defaultRowDefs = this._rowDefs.filter(def => !def.when);
  1936. if (!this.multiTemplateDataRows &&
  1937. defaultRowDefs.length > 1 &&
  1938. (typeof ngDevMode === 'undefined' || ngDevMode)) {
  1939. throw getTableMultipleDefaultRowDefsError();
  1940. }
  1941. this._defaultRowDef = defaultRowDefs[0];
  1942. }
  1943. /**
  1944. * Check if the header, data, or footer rows have changed what columns they want to display or
  1945. * whether the sticky states have changed for the header or footer. If there is a diff, then
  1946. * re-render that section.
  1947. */
  1948. _renderUpdatedColumns() {
  1949. const columnsDiffReducer = (acc, def) => {
  1950. // The differ should be run for every column, even if `acc` is already
  1951. // true (see #29922)
  1952. const diff = !!def.getColumnsDiff();
  1953. return acc || diff;
  1954. };
  1955. // Force re-render data rows if the list of column definitions have changed.
  1956. const dataColumnsChanged = this._rowDefs.reduce(columnsDiffReducer, false);
  1957. if (dataColumnsChanged) {
  1958. this._forceRenderDataRows();
  1959. }
  1960. // Force re-render header/footer rows if the list of column definitions have changed.
  1961. const headerColumnsChanged = this._headerRowDefs.reduce(columnsDiffReducer, false);
  1962. if (headerColumnsChanged) {
  1963. this._forceRenderHeaderRows();
  1964. }
  1965. const footerColumnsChanged = this._footerRowDefs.reduce(columnsDiffReducer, false);
  1966. if (footerColumnsChanged) {
  1967. this._forceRenderFooterRows();
  1968. }
  1969. return dataColumnsChanged || headerColumnsChanged || footerColumnsChanged;
  1970. }
  1971. /**
  1972. * Switch to the provided data source by resetting the data and unsubscribing from the current
  1973. * render change subscription if one exists. If the data source is null, interpret this by
  1974. * clearing the row outlet. Otherwise start listening for new data.
  1975. */
  1976. _switchDataSource(dataSource) {
  1977. this._data = [];
  1978. if (isDataSource(this.dataSource)) {
  1979. this.dataSource.disconnect(this);
  1980. }
  1981. // Stop listening for data from the previous data source.
  1982. if (this._renderChangeSubscription) {
  1983. this._renderChangeSubscription.unsubscribe();
  1984. this._renderChangeSubscription = null;
  1985. }
  1986. if (!dataSource) {
  1987. if (this._dataDiffer) {
  1988. this._dataDiffer.diff([]);
  1989. }
  1990. if (this._rowOutlet) {
  1991. this._rowOutlet.viewContainer.clear();
  1992. }
  1993. }
  1994. this._dataSource = dataSource;
  1995. }
  1996. /** Set up a subscription for the data provided by the data source. */
  1997. _observeRenderChanges() {
  1998. // If no data source has been set, there is nothing to observe for changes.
  1999. if (!this.dataSource) {
  2000. return;
  2001. }
  2002. let dataStream;
  2003. if (isDataSource(this.dataSource)) {
  2004. dataStream = this.dataSource.connect(this);
  2005. }
  2006. else if (isObservable(this.dataSource)) {
  2007. dataStream = this.dataSource;
  2008. }
  2009. else if (Array.isArray(this.dataSource)) {
  2010. dataStream = of(this.dataSource);
  2011. }
  2012. if (dataStream === undefined && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  2013. throw getTableUnknownDataSourceError();
  2014. }
  2015. this._renderChangeSubscription = dataStream
  2016. .pipe(takeUntil(this._onDestroy))
  2017. .subscribe(data => {
  2018. this._data = data || [];
  2019. this.renderRows();
  2020. });
  2021. }
  2022. /**
  2023. * Clears any existing content in the header row outlet and creates a new embedded view
  2024. * in the outlet using the header row definition.
  2025. */
  2026. _forceRenderHeaderRows() {
  2027. // Clear the header row outlet if any content exists.
  2028. if (this._headerRowOutlet.viewContainer.length > 0) {
  2029. this._headerRowOutlet.viewContainer.clear();
  2030. }
  2031. this._headerRowDefs.forEach((def, i) => this._renderRow(this._headerRowOutlet, def, i));
  2032. this.updateStickyHeaderRowStyles();
  2033. }
  2034. /**
  2035. * Clears any existing content in the footer row outlet and creates a new embedded view
  2036. * in the outlet using the footer row definition.
  2037. */
  2038. _forceRenderFooterRows() {
  2039. // Clear the footer row outlet if any content exists.
  2040. if (this._footerRowOutlet.viewContainer.length > 0) {
  2041. this._footerRowOutlet.viewContainer.clear();
  2042. }
  2043. this._footerRowDefs.forEach((def, i) => this._renderRow(this._footerRowOutlet, def, i));
  2044. this.updateStickyFooterRowStyles();
  2045. }
  2046. /** Adds the sticky column styles for the rows according to the columns' stick states. */
  2047. _addStickyColumnStyles(rows, rowDef) {
  2048. const columnDefs = Array.from(rowDef?.columns || []).map(columnName => {
  2049. const columnDef = this._columnDefsByName.get(columnName);
  2050. if (!columnDef && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  2051. throw getTableUnknownColumnError(columnName);
  2052. }
  2053. return columnDef;
  2054. });
  2055. const stickyStartStates = columnDefs.map(columnDef => columnDef.sticky);
  2056. const stickyEndStates = columnDefs.map(columnDef => columnDef.stickyEnd);
  2057. this._stickyStyler.updateStickyColumns(rows, stickyStartStates, stickyEndStates, !this._fixedLayout || this._forceRecalculateCellWidths);
  2058. }
  2059. /** Gets the list of rows that have been rendered in the row outlet. */
  2060. _getRenderedRows(rowOutlet) {
  2061. const renderedRows = [];
  2062. for (let i = 0; i < rowOutlet.viewContainer.length; i++) {
  2063. const viewRef = rowOutlet.viewContainer.get(i);
  2064. renderedRows.push(viewRef.rootNodes[0]);
  2065. }
  2066. return renderedRows;
  2067. }
  2068. /**
  2069. * Get the matching row definitions that should be used for this row data. If there is only
  2070. * one row definition, it is returned. Otherwise, find the row definitions that has a when
  2071. * predicate that returns true with the data. If none return true, return the default row
  2072. * definition.
  2073. */
  2074. _getRowDefs(data, dataIndex) {
  2075. if (this._rowDefs.length == 1) {
  2076. return [this._rowDefs[0]];
  2077. }
  2078. let rowDefs = [];
  2079. if (this.multiTemplateDataRows) {
  2080. rowDefs = this._rowDefs.filter(def => !def.when || def.when(dataIndex, data));
  2081. }
  2082. else {
  2083. let rowDef = this._rowDefs.find(def => def.when && def.when(dataIndex, data)) || this._defaultRowDef;
  2084. if (rowDef) {
  2085. rowDefs.push(rowDef);
  2086. }
  2087. }
  2088. if (!rowDefs.length && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  2089. throw getTableMissingMatchingRowDefError(data);
  2090. }
  2091. return rowDefs;
  2092. }
  2093. _getEmbeddedViewArgs(renderRow, index) {
  2094. const rowDef = renderRow.rowDef;
  2095. const context = { $implicit: renderRow.data };
  2096. return {
  2097. templateRef: rowDef.template,
  2098. context,
  2099. index,
  2100. };
  2101. }
  2102. /**
  2103. * Creates a new row template in the outlet and fills it with the set of cell templates.
  2104. * Optionally takes a context to provide to the row and cells, as well as an optional index
  2105. * of where to place the new row template in the outlet.
  2106. */
  2107. _renderRow(outlet, rowDef, index, context = {}) {
  2108. // TODO(andrewseguin): enforce that one outlet was instantiated from createEmbeddedView
  2109. const view = outlet.viewContainer.createEmbeddedView(rowDef.template, context, index);
  2110. this._renderCellTemplateForItem(rowDef, context);
  2111. return view;
  2112. }
  2113. _renderCellTemplateForItem(rowDef, context) {
  2114. for (let cellTemplate of this._getCellTemplates(rowDef)) {
  2115. if (CdkCellOutlet.mostRecentCellOutlet) {
  2116. CdkCellOutlet.mostRecentCellOutlet._viewContainer.createEmbeddedView(cellTemplate, context);
  2117. }
  2118. }
  2119. this._changeDetectorRef.markForCheck();
  2120. }
  2121. /**
  2122. * Updates the index-related context for each row to reflect any changes in the index of the rows,
  2123. * e.g. first/last/even/odd.
  2124. */
  2125. _updateRowIndexContext() {
  2126. const viewContainer = this._rowOutlet.viewContainer;
  2127. for (let renderIndex = 0, count = viewContainer.length; renderIndex < count; renderIndex++) {
  2128. const viewRef = viewContainer.get(renderIndex);
  2129. const context = viewRef.context;
  2130. context.count = count;
  2131. context.first = renderIndex === 0;
  2132. context.last = renderIndex === count - 1;
  2133. context.even = renderIndex % 2 === 0;
  2134. context.odd = !context.even;
  2135. if (this.multiTemplateDataRows) {
  2136. context.dataIndex = this._renderRows[renderIndex].dataIndex;
  2137. context.renderIndex = renderIndex;
  2138. }
  2139. else {
  2140. context.index = this._renderRows[renderIndex].dataIndex;
  2141. }
  2142. }
  2143. }
  2144. /** Gets the column definitions for the provided row def. */
  2145. _getCellTemplates(rowDef) {
  2146. if (!rowDef || !rowDef.columns) {
  2147. return [];
  2148. }
  2149. return Array.from(rowDef.columns, columnId => {
  2150. const column = this._columnDefsByName.get(columnId);
  2151. if (!column && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  2152. throw getTableUnknownColumnError(columnId);
  2153. }
  2154. return rowDef.extractCellTemplate(column);
  2155. });
  2156. }
  2157. /**
  2158. * Forces a re-render of the data rows. Should be called in cases where there has been an input
  2159. * change that affects the evaluation of which rows should be rendered, e.g. toggling
  2160. * `multiTemplateDataRows` or adding/removing row definitions.
  2161. */
  2162. _forceRenderDataRows() {
  2163. this._dataDiffer.diff([]);
  2164. this._rowOutlet.viewContainer.clear();
  2165. this.renderRows();
  2166. }
  2167. /**
  2168. * Checks if there has been a change in sticky states since last check and applies the correct
  2169. * sticky styles. Since checking resets the "dirty" state, this should only be performed once
  2170. * during a change detection and after the inputs are settled (after content check).
  2171. */
  2172. _checkStickyStates() {
  2173. const stickyCheckReducer = (acc, d) => {
  2174. return acc || d.hasStickyChanged();
  2175. };
  2176. // Note that the check needs to occur for every definition since it notifies the definition
  2177. // that it can reset its dirty state. Using another operator like `some` may short-circuit
  2178. // remaining definitions and leave them in an unchecked state.
  2179. if (this._headerRowDefs.reduce(stickyCheckReducer, false)) {
  2180. this.updateStickyHeaderRowStyles();
  2181. }
  2182. if (this._footerRowDefs.reduce(stickyCheckReducer, false)) {
  2183. this.updateStickyFooterRowStyles();
  2184. }
  2185. if (Array.from(this._columnDefsByName.values()).reduce(stickyCheckReducer, false)) {
  2186. this._stickyColumnStylesNeedReset = true;
  2187. this.updateStickyColumnStyles();
  2188. }
  2189. }
  2190. /**
  2191. * Creates the sticky styler that will be used for sticky rows and columns. Listens
  2192. * for directionality changes and provides the latest direction to the styler. Re-applies column
  2193. * stickiness when directionality changes.
  2194. */
  2195. _setupStickyStyler() {
  2196. const direction = this._dir ? this._dir.value : 'ltr';
  2197. this._stickyStyler = new StickyStyler(this._isNativeHtmlTable, this.stickyCssClass, direction, this._coalescedStyleScheduler, this._platform.isBrowser, this.needsPositionStickyOnElement, this._stickyPositioningListener, this._injector);
  2198. (this._dir ? this._dir.change : of())
  2199. .pipe(takeUntil(this._onDestroy))
  2200. .subscribe(value => {
  2201. this._stickyStyler.direction = value;
  2202. this.updateStickyColumnStyles();
  2203. });
  2204. }
  2205. /** Filters definitions that belong to this table from a QueryList. */
  2206. _getOwnDefs(items) {
  2207. return items.filter(item => !item._table || item._table === this);
  2208. }
  2209. /** Creates or removes the no data row, depending on whether any data is being shown. */
  2210. _updateNoDataRow() {
  2211. const noDataRow = this._customNoDataRow || this._noDataRow;
  2212. if (!noDataRow) {
  2213. return;
  2214. }
  2215. const shouldShow = this._rowOutlet.viewContainer.length === 0;
  2216. if (shouldShow === this._isShowingNoDataRow) {
  2217. return;
  2218. }
  2219. const container = this._noDataRowOutlet.viewContainer;
  2220. if (shouldShow) {
  2221. const view = container.createEmbeddedView(noDataRow.templateRef);
  2222. const rootNode = view.rootNodes[0];
  2223. // Only add the attributes if we have a single root node since it's hard
  2224. // to figure out which one to add it to when there are multiple.
  2225. if (view.rootNodes.length === 1 && rootNode?.nodeType === this._document.ELEMENT_NODE) {
  2226. rootNode.setAttribute('role', 'row');
  2227. rootNode.classList.add(noDataRow._contentClassName);
  2228. }
  2229. }
  2230. else {
  2231. container.clear();
  2232. }
  2233. this._isShowingNoDataRow = shouldShow;
  2234. this._changeDetectorRef.markForCheck();
  2235. }
  2236. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkTable, deps: [], target: i0.ɵɵFactoryTarget.Component });
  2237. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.6", type: CdkTable, isStandalone: true, selector: "cdk-table, table[cdk-table]", inputs: { trackBy: "trackBy", dataSource: "dataSource", multiTemplateDataRows: ["multiTemplateDataRows", "multiTemplateDataRows", booleanAttribute], fixedLayout: ["fixedLayout", "fixedLayout", booleanAttribute] }, outputs: { contentChanged: "contentChanged" }, host: { properties: { "class.cdk-table-fixed-layout": "fixedLayout" }, classAttribute: "cdk-table" }, providers: [
  2238. { provide: CDK_TABLE, useExisting: CdkTable },
  2239. { provide: _VIEW_REPEATER_STRATEGY, useClass: _DisposeViewRepeaterStrategy },
  2240. { provide: _COALESCED_STYLE_SCHEDULER, useClass: _CoalescedStyleScheduler },
  2241. // Prevent nested tables from seeing this table's StickyPositioningListener.
  2242. { provide: STICKY_POSITIONING_LISTENER, useValue: null },
  2243. ], queries: [{ propertyName: "_noDataRow", first: true, predicate: CdkNoDataRow, descendants: true }, { propertyName: "_contentColumnDefs", predicate: CdkColumnDef, descendants: true }, { propertyName: "_contentRowDefs", predicate: CdkRowDef, descendants: true }, { propertyName: "_contentHeaderRowDefs", predicate: CdkHeaderRowDef, descendants: true }, { propertyName: "_contentFooterRowDefs", predicate: CdkFooterRowDef, descendants: true }], exportAs: ["cdkTable"], ngImport: i0, template: "\n <ng-content select=\"caption\"/>\n <ng-content select=\"colgroup, col\"/>\n\n <!--\n Unprojected content throws a hydration error so we need this to capture it.\n It gets removed on the client so it doesn't affect the layout.\n -->\n @if (_isServer) {\n <ng-content/>\n }\n\n @if (_isNativeHtmlTable) {\n <thead role=\"rowgroup\">\n <ng-container headerRowOutlet/>\n </thead>\n <tbody role=\"rowgroup\">\n <ng-container rowOutlet/>\n <ng-container noDataRowOutlet/>\n </tbody>\n <tfoot role=\"rowgroup\">\n <ng-container footerRowOutlet/>\n </tfoot>\n } @else {\n <ng-container headerRowOutlet/>\n <ng-container rowOutlet/>\n <ng-container noDataRowOutlet/>\n <ng-container footerRowOutlet/>\n }\n", isInline: true, styles: [".cdk-table-fixed-layout{table-layout:fixed}\n"], dependencies: [{ kind: "directive", type: HeaderRowOutlet, selector: "[headerRowOutlet]" }, { kind: "directive", type: DataRowOutlet, selector: "[rowOutlet]" }, { kind: "directive", type: NoDataRowOutlet, selector: "[noDataRowOutlet]" }, { kind: "directive", type: FooterRowOutlet, selector: "[footerRowOutlet]" }], changeDetection: i0.ChangeDetectionStrategy.Default, encapsulation: i0.ViewEncapsulation.None });
  2244. }
  2245. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkTable, decorators: [{
  2246. type: Component,
  2247. args: [{ selector: 'cdk-table, table[cdk-table]', exportAs: 'cdkTable', template: CDK_TABLE_TEMPLATE, host: {
  2248. 'class': 'cdk-table',
  2249. '[class.cdk-table-fixed-layout]': 'fixedLayout',
  2250. }, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.Default, providers: [
  2251. { provide: CDK_TABLE, useExisting: CdkTable },
  2252. { provide: _VIEW_REPEATER_STRATEGY, useClass: _DisposeViewRepeaterStrategy },
  2253. { provide: _COALESCED_STYLE_SCHEDULER, useClass: _CoalescedStyleScheduler },
  2254. // Prevent nested tables from seeing this table's StickyPositioningListener.
  2255. { provide: STICKY_POSITIONING_LISTENER, useValue: null },
  2256. ], imports: [HeaderRowOutlet, DataRowOutlet, NoDataRowOutlet, FooterRowOutlet], styles: [".cdk-table-fixed-layout{table-layout:fixed}\n"] }]
  2257. }], ctorParameters: () => [], propDecorators: { trackBy: [{
  2258. type: Input
  2259. }], dataSource: [{
  2260. type: Input
  2261. }], multiTemplateDataRows: [{
  2262. type: Input,
  2263. args: [{ transform: booleanAttribute }]
  2264. }], fixedLayout: [{
  2265. type: Input,
  2266. args: [{ transform: booleanAttribute }]
  2267. }], contentChanged: [{
  2268. type: Output
  2269. }], _contentColumnDefs: [{
  2270. type: ContentChildren,
  2271. args: [CdkColumnDef, { descendants: true }]
  2272. }], _contentRowDefs: [{
  2273. type: ContentChildren,
  2274. args: [CdkRowDef, { descendants: true }]
  2275. }], _contentHeaderRowDefs: [{
  2276. type: ContentChildren,
  2277. args: [CdkHeaderRowDef, {
  2278. descendants: true,
  2279. }]
  2280. }], _contentFooterRowDefs: [{
  2281. type: ContentChildren,
  2282. args: [CdkFooterRowDef, {
  2283. descendants: true,
  2284. }]
  2285. }], _noDataRow: [{
  2286. type: ContentChild,
  2287. args: [CdkNoDataRow]
  2288. }] } });
  2289. /** Utility function that gets a merged list of the entries in an array and values of a Set. */
  2290. function mergeArrayAndSet(array, set) {
  2291. return array.concat(Array.from(set));
  2292. }
  2293. /**
  2294. * Finds the closest table section to an outlet. We can't use `HTMLElement.closest` for this,
  2295. * because the node representing the outlet is a comment.
  2296. */
  2297. function closestTableSection(outlet, section) {
  2298. const uppercaseSection = section.toUpperCase();
  2299. let current = outlet.viewContainer.element.nativeElement;
  2300. while (current) {
  2301. // 1 is an element node.
  2302. const nodeName = current.nodeType === 1 ? current.nodeName : null;
  2303. if (nodeName === uppercaseSection) {
  2304. return current;
  2305. }
  2306. else if (nodeName === 'TABLE') {
  2307. // Stop traversing past the `table` node.
  2308. break;
  2309. }
  2310. current = current.parentNode;
  2311. }
  2312. return null;
  2313. }
  2314. /**
  2315. * Column that simply shows text content for the header and row cells. Assumes that the table
  2316. * is using the native table implementation (`<table>`).
  2317. *
  2318. * By default, the name of this column will be the header text and data property accessor.
  2319. * The header text can be overridden with the `headerText` input. Cell values can be overridden with
  2320. * the `dataAccessor` input. Change the text justification to the start or end using the `justify`
  2321. * input.
  2322. */
  2323. class CdkTextColumn {
  2324. _table = inject(CdkTable, { optional: true });
  2325. _options = inject(TEXT_COLUMN_OPTIONS, { optional: true });
  2326. /** Column name that should be used to reference this column. */
  2327. get name() {
  2328. return this._name;
  2329. }
  2330. set name(name) {
  2331. this._name = name;
  2332. // With Ivy, inputs can be initialized before static query results are
  2333. // available. In that case, we defer the synchronization until "ngOnInit" fires.
  2334. this._syncColumnDefName();
  2335. }
  2336. _name;
  2337. /**
  2338. * Text label that should be used for the column header. If this property is not
  2339. * set, the header text will default to the column name with its first letter capitalized.
  2340. */
  2341. headerText;
  2342. /**
  2343. * Accessor function to retrieve the data rendered for each cell. If this
  2344. * property is not set, the data cells will render the value found in the data's property matching
  2345. * the column's name. For example, if the column is named `id`, then the rendered value will be
  2346. * value defined by the data's `id` property.
  2347. */
  2348. dataAccessor;
  2349. /** Alignment of the cell values. */
  2350. justify = 'start';
  2351. /** @docs-private */
  2352. columnDef;
  2353. /**
  2354. * The column cell is provided to the column during `ngOnInit` with a static query.
  2355. * Normally, this will be retrieved by the column using `ContentChild`, but that assumes the
  2356. * column definition was provided in the same view as the table, which is not the case with this
  2357. * component.
  2358. * @docs-private
  2359. */
  2360. cell;
  2361. /**
  2362. * The column headerCell is provided to the column during `ngOnInit` with a static query.
  2363. * Normally, this will be retrieved by the column using `ContentChild`, but that assumes the
  2364. * column definition was provided in the same view as the table, which is not the case with this
  2365. * component.
  2366. * @docs-private
  2367. */
  2368. headerCell;
  2369. constructor() {
  2370. this._options = this._options || {};
  2371. }
  2372. ngOnInit() {
  2373. this._syncColumnDefName();
  2374. if (this.headerText === undefined) {
  2375. this.headerText = this._createDefaultHeaderText();
  2376. }
  2377. if (!this.dataAccessor) {
  2378. this.dataAccessor =
  2379. this._options.defaultDataAccessor || ((data, name) => data[name]);
  2380. }
  2381. if (this._table) {
  2382. // Provide the cell and headerCell directly to the table with the static `ViewChild` query,
  2383. // since the columnDef will not pick up its content by the time the table finishes checking
  2384. // its content and initializing the rows.
  2385. this.columnDef.cell = this.cell;
  2386. this.columnDef.headerCell = this.headerCell;
  2387. this._table.addColumnDef(this.columnDef);
  2388. }
  2389. else if (typeof ngDevMode === 'undefined' || ngDevMode) {
  2390. throw getTableTextColumnMissingParentTableError();
  2391. }
  2392. }
  2393. ngOnDestroy() {
  2394. if (this._table) {
  2395. this._table.removeColumnDef(this.columnDef);
  2396. }
  2397. }
  2398. /**
  2399. * Creates a default header text. Use the options' header text transformation function if one
  2400. * has been provided. Otherwise simply capitalize the column name.
  2401. */
  2402. _createDefaultHeaderText() {
  2403. const name = this.name;
  2404. if (!name && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  2405. throw getTableTextColumnMissingNameError();
  2406. }
  2407. if (this._options && this._options.defaultHeaderTextTransform) {
  2408. return this._options.defaultHeaderTextTransform(name);
  2409. }
  2410. return name[0].toUpperCase() + name.slice(1);
  2411. }
  2412. /** Synchronizes the column definition name with the text column name. */
  2413. _syncColumnDefName() {
  2414. if (this.columnDef) {
  2415. this.columnDef.name = this.name;
  2416. }
  2417. }
  2418. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkTextColumn, deps: [], target: i0.ɵɵFactoryTarget.Component });
  2419. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", type: CdkTextColumn, isStandalone: true, 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: `
  2420. <ng-container cdkColumnDef>
  2421. <th cdk-header-cell *cdkHeaderCellDef [style.text-align]="justify">
  2422. {{headerText}}
  2423. </th>
  2424. <td cdk-cell *cdkCellDef="let data" [style.text-align]="justify">
  2425. {{dataAccessor(data, name)}}
  2426. </td>
  2427. </ng-container>
  2428. `, isInline: true, dependencies: [{ kind: "directive", type: CdkColumnDef, selector: "[cdkColumnDef]", inputs: ["cdkColumnDef", "sticky", "stickyEnd"] }, { kind: "directive", type: CdkHeaderCellDef, selector: "[cdkHeaderCellDef]" }, { kind: "directive", type: CdkHeaderCell, selector: "cdk-header-cell, th[cdk-header-cell]" }, { kind: "directive", type: CdkCellDef, selector: "[cdkCellDef]" }, { kind: "directive", type: CdkCell, selector: "cdk-cell, td[cdk-cell]" }], changeDetection: i0.ChangeDetectionStrategy.Default, encapsulation: i0.ViewEncapsulation.None });
  2429. }
  2430. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkTextColumn, decorators: [{
  2431. type: Component,
  2432. args: [{
  2433. selector: 'cdk-text-column',
  2434. template: `
  2435. <ng-container cdkColumnDef>
  2436. <th cdk-header-cell *cdkHeaderCellDef [style.text-align]="justify">
  2437. {{headerText}}
  2438. </th>
  2439. <td cdk-cell *cdkCellDef="let data" [style.text-align]="justify">
  2440. {{dataAccessor(data, name)}}
  2441. </td>
  2442. </ng-container>
  2443. `,
  2444. encapsulation: ViewEncapsulation.None,
  2445. // Change detection is intentionally not set to OnPush. This component's template will be provided
  2446. // to the table to be inserted into its view. This is problematic when change detection runs since
  2447. // the bindings in this template will be evaluated _after_ the table's view is evaluated, which
  2448. // mean's the template in the table's view will not have the updated value (and in fact will cause
  2449. // an ExpressionChangedAfterItHasBeenCheckedError).
  2450. // tslint:disable-next-line:validate-decorators
  2451. changeDetection: ChangeDetectionStrategy.Default,
  2452. imports: [CdkColumnDef, CdkHeaderCellDef, CdkHeaderCell, CdkCellDef, CdkCell],
  2453. }]
  2454. }], ctorParameters: () => [], propDecorators: { name: [{
  2455. type: Input
  2456. }], headerText: [{
  2457. type: Input
  2458. }], dataAccessor: [{
  2459. type: Input
  2460. }], justify: [{
  2461. type: Input
  2462. }], columnDef: [{
  2463. type: ViewChild,
  2464. args: [CdkColumnDef, { static: true }]
  2465. }], cell: [{
  2466. type: ViewChild,
  2467. args: [CdkCellDef, { static: true }]
  2468. }], headerCell: [{
  2469. type: ViewChild,
  2470. args: [CdkHeaderCellDef, { static: true }]
  2471. }] } });
  2472. const EXPORTED_DECLARATIONS = [
  2473. CdkTable,
  2474. CdkRowDef,
  2475. CdkCellDef,
  2476. CdkCellOutlet,
  2477. CdkHeaderCellDef,
  2478. CdkFooterCellDef,
  2479. CdkColumnDef,
  2480. CdkCell,
  2481. CdkRow,
  2482. CdkHeaderCell,
  2483. CdkFooterCell,
  2484. CdkHeaderRow,
  2485. CdkHeaderRowDef,
  2486. CdkFooterRow,
  2487. CdkFooterRowDef,
  2488. DataRowOutlet,
  2489. HeaderRowOutlet,
  2490. FooterRowOutlet,
  2491. CdkTextColumn,
  2492. CdkNoDataRow,
  2493. CdkRecycleRows,
  2494. NoDataRowOutlet,
  2495. ];
  2496. class CdkTableModule {
  2497. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkTableModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  2498. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.6", ngImport: i0, type: CdkTableModule, imports: [ScrollingModule, CdkTable,
  2499. CdkRowDef,
  2500. CdkCellDef,
  2501. CdkCellOutlet,
  2502. CdkHeaderCellDef,
  2503. CdkFooterCellDef,
  2504. CdkColumnDef,
  2505. CdkCell,
  2506. CdkRow,
  2507. CdkHeaderCell,
  2508. CdkFooterCell,
  2509. CdkHeaderRow,
  2510. CdkHeaderRowDef,
  2511. CdkFooterRow,
  2512. CdkFooterRowDef,
  2513. DataRowOutlet,
  2514. HeaderRowOutlet,
  2515. FooterRowOutlet,
  2516. CdkTextColumn,
  2517. CdkNoDataRow,
  2518. CdkRecycleRows,
  2519. NoDataRowOutlet], exports: [CdkTable,
  2520. CdkRowDef,
  2521. CdkCellDef,
  2522. CdkCellOutlet,
  2523. CdkHeaderCellDef,
  2524. CdkFooterCellDef,
  2525. CdkColumnDef,
  2526. CdkCell,
  2527. CdkRow,
  2528. CdkHeaderCell,
  2529. CdkFooterCell,
  2530. CdkHeaderRow,
  2531. CdkHeaderRowDef,
  2532. CdkFooterRow,
  2533. CdkFooterRowDef,
  2534. DataRowOutlet,
  2535. HeaderRowOutlet,
  2536. FooterRowOutlet,
  2537. CdkTextColumn,
  2538. CdkNoDataRow,
  2539. CdkRecycleRows,
  2540. NoDataRowOutlet] });
  2541. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkTableModule, imports: [ScrollingModule] });
  2542. }
  2543. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: CdkTableModule, decorators: [{
  2544. type: NgModule,
  2545. args: [{
  2546. exports: EXPORTED_DECLARATIONS,
  2547. imports: [ScrollingModule, ...EXPORTED_DECLARATIONS],
  2548. }]
  2549. }] });
  2550. /**
  2551. * Mixin to provide a directive with a function that checks if the sticky input has been
  2552. * changed since the last time the function was called. Essentially adds a dirty-check to the
  2553. * sticky value.
  2554. * @docs-private
  2555. * @deprecated Implement the `CanStick` interface instead.
  2556. * @breaking-change 19.0.0
  2557. */
  2558. function mixinHasStickyInput(base) {
  2559. return class extends base {
  2560. /** Whether sticky positioning should be applied. */
  2561. get sticky() {
  2562. return this._sticky;
  2563. }
  2564. set sticky(v) {
  2565. const prevValue = this._sticky;
  2566. this._sticky = coerceBooleanProperty(v);
  2567. this._hasStickyChanged = prevValue !== this._sticky;
  2568. }
  2569. _sticky = false;
  2570. /** Whether the sticky input has changed since it was last checked. */
  2571. _hasStickyChanged = false;
  2572. /** Whether the sticky value has changed since this was last called. */
  2573. hasStickyChanged() {
  2574. const hasStickyChanged = this._hasStickyChanged;
  2575. this._hasStickyChanged = false;
  2576. return hasStickyChanged;
  2577. }
  2578. /** Resets the dirty check for cases where the sticky state has been used without checking. */
  2579. resetStickyChanged() {
  2580. this._hasStickyChanged = false;
  2581. }
  2582. constructor(...args) {
  2583. super(...args);
  2584. }
  2585. };
  2586. }
  2587. export { BaseCdkCell, BaseRowDef, CDK_ROW_TEMPLATE, CDK_TABLE, CDK_TABLE_TEMPLATE, CdkCell, CdkCellDef, CdkCellOutlet, CdkColumnDef, CdkFooterCell, CdkFooterCellDef, CdkFooterRow, CdkFooterRowDef, CdkHeaderCell, CdkHeaderCellDef, CdkHeaderRow, CdkHeaderRowDef, CdkNoDataRow, CdkRecycleRows, CdkRow, CdkRowDef, CdkTable, CdkTableModule, CdkTextColumn, DataRowOutlet, FooterRowOutlet, HeaderRowOutlet, NoDataRowOutlet, STICKY_DIRECTIONS, STICKY_POSITIONING_LISTENER, StickyStyler, TEXT_COLUMN_OPTIONS, _COALESCED_STYLE_SCHEDULER, _CoalescedStyleScheduler, _Schedule, mixinHasStickyInput };
  2588. //# sourceMappingURL=table.mjs.map