sort.mjs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. import * as i0 from '@angular/core';
  2. import { InjectionToken, EventEmitter, booleanAttribute, Directive, Optional, Inject, Input, Output, Injectable, SkipSelf, inject, ChangeDetectorRef, ElementRef, ANIMATION_MODULE_TYPE, signal, Component, ViewEncapsulation, ChangeDetectionStrategy, NgModule } from '@angular/core';
  3. import { FocusMonitor, AriaDescriber } from '@angular/cdk/a11y';
  4. import { SPACE, ENTER } from '@angular/cdk/keycodes';
  5. import { ReplaySubject, Subject, merge } from 'rxjs';
  6. import { _CdkPrivateStyleLoader } from '@angular/cdk/private';
  7. import { _ as _StructuralStylesLoader } from './structural-styles-BQUT6wsL.mjs';
  8. import { M as MatCommonModule } from './common-module-WayjW0Pb.mjs';
  9. import '@angular/cdk/bidi';
  10. /** @docs-private */
  11. function getSortDuplicateSortableIdError(id) {
  12. return Error(`Cannot have two MatSortables with the same id (${id}).`);
  13. }
  14. /** @docs-private */
  15. function getSortHeaderNotContainedWithinSortError() {
  16. return Error(`MatSortHeader must be placed within a parent element with the MatSort directive.`);
  17. }
  18. /** @docs-private */
  19. function getSortHeaderMissingIdError() {
  20. return Error(`MatSortHeader must be provided with a unique id.`);
  21. }
  22. /** @docs-private */
  23. function getSortInvalidDirectionError(direction) {
  24. return Error(`${direction} is not a valid sort direction ('asc' or 'desc').`);
  25. }
  26. /** Injection token to be used to override the default options for `mat-sort`. */
  27. const MAT_SORT_DEFAULT_OPTIONS = new InjectionToken('MAT_SORT_DEFAULT_OPTIONS');
  28. /** Container for MatSortables to manage the sort state and provide default sort parameters. */
  29. class MatSort {
  30. _defaultOptions;
  31. _initializedStream = new ReplaySubject(1);
  32. /** Collection of all registered sortables that this directive manages. */
  33. sortables = new Map();
  34. /** Used to notify any child components listening to state changes. */
  35. _stateChanges = new Subject();
  36. /** The id of the most recently sorted MatSortable. */
  37. active;
  38. /**
  39. * The direction to set when an MatSortable is initially sorted.
  40. * May be overridden by the MatSortable's sort start.
  41. */
  42. start = 'asc';
  43. /** The sort direction of the currently active MatSortable. */
  44. get direction() {
  45. return this._direction;
  46. }
  47. set direction(direction) {
  48. if (direction &&
  49. direction !== 'asc' &&
  50. direction !== 'desc' &&
  51. (typeof ngDevMode === 'undefined' || ngDevMode)) {
  52. throw getSortInvalidDirectionError(direction);
  53. }
  54. this._direction = direction;
  55. }
  56. _direction = '';
  57. /**
  58. * Whether to disable the user from clearing the sort by finishing the sort direction cycle.
  59. * May be overridden by the MatSortable's disable clear input.
  60. */
  61. disableClear;
  62. /** Whether the sortable is disabled. */
  63. disabled = false;
  64. /** Event emitted when the user changes either the active sort or sort direction. */
  65. sortChange = new EventEmitter();
  66. /** Emits when the paginator is initialized. */
  67. initialized = this._initializedStream;
  68. constructor(_defaultOptions) {
  69. this._defaultOptions = _defaultOptions;
  70. }
  71. /**
  72. * Register function to be used by the contained MatSortables. Adds the MatSortable to the
  73. * collection of MatSortables.
  74. */
  75. register(sortable) {
  76. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  77. if (!sortable.id) {
  78. throw getSortHeaderMissingIdError();
  79. }
  80. if (this.sortables.has(sortable.id)) {
  81. throw getSortDuplicateSortableIdError(sortable.id);
  82. }
  83. }
  84. this.sortables.set(sortable.id, sortable);
  85. }
  86. /**
  87. * Unregister function to be used by the contained MatSortables. Removes the MatSortable from the
  88. * collection of contained MatSortables.
  89. */
  90. deregister(sortable) {
  91. this.sortables.delete(sortable.id);
  92. }
  93. /** Sets the active sort id and determines the new sort direction. */
  94. sort(sortable) {
  95. if (this.active != sortable.id) {
  96. this.active = sortable.id;
  97. this.direction = sortable.start ? sortable.start : this.start;
  98. }
  99. else {
  100. this.direction = this.getNextSortDirection(sortable);
  101. }
  102. this.sortChange.emit({ active: this.active, direction: this.direction });
  103. }
  104. /** Returns the next sort direction of the active sortable, checking for potential overrides. */
  105. getNextSortDirection(sortable) {
  106. if (!sortable) {
  107. return '';
  108. }
  109. // Get the sort direction cycle with the potential sortable overrides.
  110. const disableClear = sortable?.disableClear ?? this.disableClear ?? !!this._defaultOptions?.disableClear;
  111. let sortDirectionCycle = getSortDirectionCycle(sortable.start || this.start, disableClear);
  112. // Get and return the next direction in the cycle
  113. let nextDirectionIndex = sortDirectionCycle.indexOf(this.direction) + 1;
  114. if (nextDirectionIndex >= sortDirectionCycle.length) {
  115. nextDirectionIndex = 0;
  116. }
  117. return sortDirectionCycle[nextDirectionIndex];
  118. }
  119. ngOnInit() {
  120. this._initializedStream.next();
  121. }
  122. ngOnChanges() {
  123. this._stateChanges.next();
  124. }
  125. ngOnDestroy() {
  126. this._stateChanges.complete();
  127. this._initializedStream.complete();
  128. }
  129. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSort, deps: [{ token: MAT_SORT_DEFAULT_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
  130. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.6", type: MatSort, isStandalone: true, selector: "[matSort]", inputs: { active: ["matSortActive", "active"], start: ["matSortStart", "start"], direction: ["matSortDirection", "direction"], disableClear: ["matSortDisableClear", "disableClear", booleanAttribute], disabled: ["matSortDisabled", "disabled", booleanAttribute] }, outputs: { sortChange: "matSortChange" }, host: { classAttribute: "mat-sort" }, exportAs: ["matSort"], usesOnChanges: true, ngImport: i0 });
  131. }
  132. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSort, decorators: [{
  133. type: Directive,
  134. args: [{
  135. selector: '[matSort]',
  136. exportAs: 'matSort',
  137. host: {
  138. 'class': 'mat-sort',
  139. },
  140. }]
  141. }], ctorParameters: () => [{ type: undefined, decorators: [{
  142. type: Optional
  143. }, {
  144. type: Inject,
  145. args: [MAT_SORT_DEFAULT_OPTIONS]
  146. }] }], propDecorators: { active: [{
  147. type: Input,
  148. args: ['matSortActive']
  149. }], start: [{
  150. type: Input,
  151. args: ['matSortStart']
  152. }], direction: [{
  153. type: Input,
  154. args: ['matSortDirection']
  155. }], disableClear: [{
  156. type: Input,
  157. args: [{ alias: 'matSortDisableClear', transform: booleanAttribute }]
  158. }], disabled: [{
  159. type: Input,
  160. args: [{ alias: 'matSortDisabled', transform: booleanAttribute }]
  161. }], sortChange: [{
  162. type: Output,
  163. args: ['matSortChange']
  164. }] } });
  165. /** Returns the sort direction cycle to use given the provided parameters of order and clear. */
  166. function getSortDirectionCycle(start, disableClear) {
  167. let sortOrder = ['asc', 'desc'];
  168. if (start == 'desc') {
  169. sortOrder.reverse();
  170. }
  171. if (!disableClear) {
  172. sortOrder.push('');
  173. }
  174. return sortOrder;
  175. }
  176. /**
  177. * To modify the labels and text displayed, create a new instance of MatSortHeaderIntl and
  178. * include it in a custom provider.
  179. */
  180. class MatSortHeaderIntl {
  181. /**
  182. * Stream that emits whenever the labels here are changed. Use this to notify
  183. * components if the labels have changed after initialization.
  184. */
  185. changes = new Subject();
  186. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSortHeaderIntl, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  187. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSortHeaderIntl, providedIn: 'root' });
  188. }
  189. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSortHeaderIntl, decorators: [{
  190. type: Injectable,
  191. args: [{ providedIn: 'root' }]
  192. }] });
  193. /**
  194. * @docs-private
  195. * @deprecated No longer used, will be removed.
  196. * @breaking-change 21.0.0
  197. */
  198. function MAT_SORT_HEADER_INTL_PROVIDER_FACTORY(parentIntl) {
  199. return parentIntl || new MatSortHeaderIntl();
  200. }
  201. /**
  202. * @docs-private
  203. * @deprecated No longer used, will be removed.
  204. * @breaking-change 21.0.0
  205. */
  206. const MAT_SORT_HEADER_INTL_PROVIDER = {
  207. // If there is already an MatSortHeaderIntl available, use that. Otherwise, provide a new one.
  208. provide: MatSortHeaderIntl,
  209. deps: [[new Optional(), new SkipSelf(), MatSortHeaderIntl]],
  210. useFactory: MAT_SORT_HEADER_INTL_PROVIDER_FACTORY,
  211. };
  212. /**
  213. * Applies sorting behavior (click to change sort) and styles to an element, including an
  214. * arrow to display the current sort direction.
  215. *
  216. * Must be provided with an id and contained within a parent MatSort directive.
  217. *
  218. * If used on header cells in a CdkTable, it will automatically default its id from its containing
  219. * column definition.
  220. */
  221. class MatSortHeader {
  222. _intl = inject(MatSortHeaderIntl);
  223. _sort = inject(MatSort, { optional: true });
  224. _columnDef = inject('MAT_SORT_HEADER_COLUMN_DEF', {
  225. optional: true,
  226. });
  227. _changeDetectorRef = inject(ChangeDetectorRef);
  228. _focusMonitor = inject(FocusMonitor);
  229. _elementRef = inject(ElementRef);
  230. _ariaDescriber = inject(AriaDescriber, { optional: true });
  231. _renderChanges;
  232. _animationModule = inject(ANIMATION_MODULE_TYPE, { optional: true });
  233. /**
  234. * Indicates which state was just cleared from the sort header.
  235. * Will be reset on the next interaction. Used for coordinating animations.
  236. */
  237. _recentlyCleared = signal(null);
  238. /**
  239. * The element with role="button" inside this component's view. We need this
  240. * in order to apply a description with AriaDescriber.
  241. */
  242. _sortButton;
  243. /**
  244. * ID of this sort header. If used within the context of a CdkColumnDef, this will default to
  245. * the column's name.
  246. */
  247. id;
  248. /** Sets the position of the arrow that displays when sorted. */
  249. arrowPosition = 'after';
  250. /** Overrides the sort start value of the containing MatSort for this MatSortable. */
  251. start;
  252. /** whether the sort header is disabled. */
  253. disabled = false;
  254. /**
  255. * Description applied to MatSortHeader's button element with aria-describedby. This text should
  256. * describe the action that will occur when the user clicks the sort header.
  257. */
  258. get sortActionDescription() {
  259. return this._sortActionDescription;
  260. }
  261. set sortActionDescription(value) {
  262. this._updateSortActionDescription(value);
  263. }
  264. // Default the action description to "Sort" because it's better than nothing.
  265. // Without a description, the button's label comes from the sort header text content,
  266. // which doesn't give any indication that it performs a sorting operation.
  267. _sortActionDescription = 'Sort';
  268. /** Overrides the disable clear value of the containing MatSort for this MatSortable. */
  269. disableClear;
  270. constructor() {
  271. inject(_CdkPrivateStyleLoader).load(_StructuralStylesLoader);
  272. const defaultOptions = inject(MAT_SORT_DEFAULT_OPTIONS, {
  273. optional: true,
  274. });
  275. // Note that we use a string token for the `_columnDef`, because the value is provided both by
  276. // `material/table` and `cdk/table` and we can't have the CDK depending on Material,
  277. // and we want to avoid having the sort header depending on the CDK table because
  278. // of this single reference.
  279. if (!this._sort && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  280. throw getSortHeaderNotContainedWithinSortError();
  281. }
  282. if (defaultOptions?.arrowPosition) {
  283. this.arrowPosition = defaultOptions?.arrowPosition;
  284. }
  285. }
  286. ngOnInit() {
  287. if (!this.id && this._columnDef) {
  288. this.id = this._columnDef.name;
  289. }
  290. this._sort.register(this);
  291. this._renderChanges = merge(this._sort._stateChanges, this._sort.sortChange).subscribe(() => this._changeDetectorRef.markForCheck());
  292. this._sortButton = this._elementRef.nativeElement.querySelector('.mat-sort-header-container');
  293. this._updateSortActionDescription(this._sortActionDescription);
  294. }
  295. ngAfterViewInit() {
  296. // We use the focus monitor because we also want to style
  297. // things differently based on the focus origin.
  298. this._focusMonitor
  299. .monitor(this._elementRef, true)
  300. .subscribe(() => this._recentlyCleared.set(null));
  301. }
  302. ngOnDestroy() {
  303. this._focusMonitor.stopMonitoring(this._elementRef);
  304. this._sort.deregister(this);
  305. this._renderChanges?.unsubscribe();
  306. if (this._sortButton) {
  307. this._ariaDescriber?.removeDescription(this._sortButton, this._sortActionDescription);
  308. }
  309. }
  310. /** Triggers the sort on this sort header and removes the indicator hint. */
  311. _toggleOnInteraction() {
  312. if (!this._isDisabled()) {
  313. const wasSorted = this._isSorted();
  314. const prevDirection = this._sort.direction;
  315. this._sort.sort(this);
  316. this._recentlyCleared.set(wasSorted && !this._isSorted() ? prevDirection : null);
  317. }
  318. }
  319. _handleKeydown(event) {
  320. if (event.keyCode === SPACE || event.keyCode === ENTER) {
  321. event.preventDefault();
  322. this._toggleOnInteraction();
  323. }
  324. }
  325. /** Whether this MatSortHeader is currently sorted in either ascending or descending order. */
  326. _isSorted() {
  327. return (this._sort.active == this.id &&
  328. (this._sort.direction === 'asc' || this._sort.direction === 'desc'));
  329. }
  330. _isDisabled() {
  331. return this._sort.disabled || this.disabled;
  332. }
  333. /**
  334. * Gets the aria-sort attribute that should be applied to this sort header. If this header
  335. * is not sorted, returns null so that the attribute is removed from the host element. Aria spec
  336. * says that the aria-sort property should only be present on one header at a time, so removing
  337. * ensures this is true.
  338. */
  339. _getAriaSortAttribute() {
  340. if (!this._isSorted()) {
  341. return 'none';
  342. }
  343. return this._sort.direction == 'asc' ? 'ascending' : 'descending';
  344. }
  345. /** Whether the arrow inside the sort header should be rendered. */
  346. _renderArrow() {
  347. return !this._isDisabled() || this._isSorted();
  348. }
  349. _updateSortActionDescription(newDescription) {
  350. // We use AriaDescriber for the sort button instead of setting an `aria-label` because some
  351. // screen readers (notably VoiceOver) will read both the column header *and* the button's label
  352. // for every *cell* in the table, creating a lot of unnecessary noise.
  353. // If _sortButton is undefined, the component hasn't been initialized yet so there's
  354. // nothing to update in the DOM.
  355. if (this._sortButton) {
  356. // removeDescription will no-op if there is no existing message.
  357. // TODO(jelbourn): remove optional chaining when AriaDescriber is required.
  358. this._ariaDescriber?.removeDescription(this._sortButton, this._sortActionDescription);
  359. this._ariaDescriber?.describe(this._sortButton, newDescription);
  360. }
  361. this._sortActionDescription = newDescription;
  362. }
  363. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSortHeader, deps: [], target: i0.ɵɵFactoryTarget.Component });
  364. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.6", type: MatSortHeader, isStandalone: true, selector: "[mat-sort-header]", inputs: { id: ["mat-sort-header", "id"], arrowPosition: "arrowPosition", start: "start", disabled: ["disabled", "disabled", booleanAttribute], sortActionDescription: "sortActionDescription", disableClear: ["disableClear", "disableClear", booleanAttribute] }, host: { listeners: { "click": "_toggleOnInteraction()", "keydown": "_handleKeydown($event)", "mouseleave": "_recentlyCleared.set(null)" }, properties: { "attr.aria-sort": "_getAriaSortAttribute()", "class.mat-sort-header-disabled": "_isDisabled()" }, classAttribute: "mat-sort-header" }, exportAs: ["matSortHeader"], ngImport: i0, template: "<!--\n We set the `tabindex` on an element inside the table header, rather than the header itself,\n because of a bug in NVDA where having a `tabindex` on a `th` breaks keyboard navigation in the\n table (see https://github.com/nvaccess/nvda/issues/7718). This allows for the header to both\n be focusable, and have screen readers read out its `aria-sort` state. We prefer this approach\n over having a button with an `aria-label` inside the header, because the button's `aria-label`\n will be read out as the user is navigating the table's cell (see #13012).\n\n The approach is based off of: https://dequeuniversity.com/library/aria/tables/sf-sortable-grid\n-->\n<div class=\"mat-sort-header-container mat-focus-indicator\"\n [class.mat-sort-header-sorted]=\"_isSorted()\"\n [class.mat-sort-header-position-before]=\"arrowPosition === 'before'\"\n [class.mat-sort-header-descending]=\"this._sort.direction === 'desc'\"\n [class.mat-sort-header-ascending]=\"this._sort.direction === 'asc'\"\n [class.mat-sort-header-recently-cleared-ascending]=\"_recentlyCleared() === 'asc'\"\n [class.mat-sort-header-recently-cleared-descending]=\"_recentlyCleared() === 'desc'\"\n [class.mat-sort-header-animations-disabled]=\"_animationModule === 'NoopAnimations'\"\n [attr.tabindex]=\"_isDisabled() ? null : 0\"\n [attr.role]=\"_isDisabled() ? null : 'button'\">\n\n <!--\n TODO(crisbeto): this div isn't strictly necessary, but we have to keep it due to a large\n number of screenshot diff failures. It should be removed eventually. Note that the difference\n isn't visible with a shorter header, but once it breaks up into multiple lines, this element\n causes it to be center-aligned, whereas removing it will keep the text to the left.\n -->\n <div class=\"mat-sort-header-content\">\n <ng-content></ng-content>\n </div>\n\n <!-- Disable animations while a current animation is running -->\n @if (_renderArrow()) {\n <div class=\"mat-sort-header-arrow\">\n <svg viewBox=\"0 -960 960 960\" focusable=\"false\" aria-hidden=\"true\">\n <path d=\"M440-240v-368L296-464l-56-56 240-240 240 240-56 56-144-144v368h-80Z\"/>\n </svg>\n </div>\n }\n</div>\n", styles: [".mat-sort-header{cursor:pointer}.mat-sort-header-disabled{cursor:default}.mat-sort-header-container{display:flex;align-items:center;letter-spacing:normal;outline:0}[mat-sort-header].cdk-keyboard-focused .mat-sort-header-container,[mat-sort-header].cdk-program-focused .mat-sort-header-container{border-bottom:solid 1px currentColor}.mat-sort-header-container::before{margin:calc(calc(var(--mat-focus-indicator-border-width, 3px) + 2px)*-1)}.mat-sort-header-content{display:flex;align-items:center}.mat-sort-header-position-before{flex-direction:row-reverse}@keyframes _mat-sort-header-recently-cleared-ascending{from{transform:translateY(0);opacity:1}to{transform:translateY(-25%);opacity:0}}@keyframes _mat-sort-header-recently-cleared-descending{from{transform:translateY(0) rotate(180deg);opacity:1}to{transform:translateY(25%) rotate(180deg);opacity:0}}.mat-sort-header-arrow{height:12px;width:12px;position:relative;transition:transform 225ms cubic-bezier(0.4, 0, 0.2, 1),opacity 225ms cubic-bezier(0.4, 0, 0.2, 1);opacity:0;overflow:visible;color:var(--mat-sort-arrow-color, var(--mat-sys-on-surface))}.mat-sort-header.cdk-keyboard-focused .mat-sort-header-arrow,.mat-sort-header.cdk-program-focused .mat-sort-header-arrow,.mat-sort-header:hover .mat-sort-header-arrow{opacity:.54}.mat-sort-header .mat-sort-header-sorted .mat-sort-header-arrow{opacity:1}.mat-sort-header-descending .mat-sort-header-arrow{transform:rotate(180deg)}.mat-sort-header-recently-cleared-ascending .mat-sort-header-arrow{transform:translateY(-25%)}.mat-sort-header-recently-cleared-ascending .mat-sort-header-arrow{transition:none;animation:_mat-sort-header-recently-cleared-ascending 225ms cubic-bezier(0.4, 0, 0.2, 1) forwards}.mat-sort-header-recently-cleared-descending .mat-sort-header-arrow{transition:none;animation:_mat-sort-header-recently-cleared-descending 225ms cubic-bezier(0.4, 0, 0.2, 1) forwards}.mat-sort-header-animations-disabled .mat-sort-header-arrow{transition-duration:0ms;animation-duration:0ms}.mat-sort-header-arrow svg{width:24px;height:24px;fill:currentColor;position:absolute;top:50%;left:50%;margin:-12px 0 0 -12px;transform:translateZ(0)}.mat-sort-header-arrow,[dir=rtl] .mat-sort-header-position-before .mat-sort-header-arrow{margin:0 0 0 6px}.mat-sort-header-position-before .mat-sort-header-arrow,[dir=rtl] .mat-sort-header-arrow{margin:0 6px 0 0}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  365. }
  366. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSortHeader, decorators: [{
  367. type: Component,
  368. args: [{ selector: '[mat-sort-header]', exportAs: 'matSortHeader', host: {
  369. 'class': 'mat-sort-header',
  370. '(click)': '_toggleOnInteraction()',
  371. '(keydown)': '_handleKeydown($event)',
  372. '(mouseleave)': '_recentlyCleared.set(null)',
  373. '[attr.aria-sort]': '_getAriaSortAttribute()',
  374. '[class.mat-sort-header-disabled]': '_isDisabled()',
  375. }, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "<!--\n We set the `tabindex` on an element inside the table header, rather than the header itself,\n because of a bug in NVDA where having a `tabindex` on a `th` breaks keyboard navigation in the\n table (see https://github.com/nvaccess/nvda/issues/7718). This allows for the header to both\n be focusable, and have screen readers read out its `aria-sort` state. We prefer this approach\n over having a button with an `aria-label` inside the header, because the button's `aria-label`\n will be read out as the user is navigating the table's cell (see #13012).\n\n The approach is based off of: https://dequeuniversity.com/library/aria/tables/sf-sortable-grid\n-->\n<div class=\"mat-sort-header-container mat-focus-indicator\"\n [class.mat-sort-header-sorted]=\"_isSorted()\"\n [class.mat-sort-header-position-before]=\"arrowPosition === 'before'\"\n [class.mat-sort-header-descending]=\"this._sort.direction === 'desc'\"\n [class.mat-sort-header-ascending]=\"this._sort.direction === 'asc'\"\n [class.mat-sort-header-recently-cleared-ascending]=\"_recentlyCleared() === 'asc'\"\n [class.mat-sort-header-recently-cleared-descending]=\"_recentlyCleared() === 'desc'\"\n [class.mat-sort-header-animations-disabled]=\"_animationModule === 'NoopAnimations'\"\n [attr.tabindex]=\"_isDisabled() ? null : 0\"\n [attr.role]=\"_isDisabled() ? null : 'button'\">\n\n <!--\n TODO(crisbeto): this div isn't strictly necessary, but we have to keep it due to a large\n number of screenshot diff failures. It should be removed eventually. Note that the difference\n isn't visible with a shorter header, but once it breaks up into multiple lines, this element\n causes it to be center-aligned, whereas removing it will keep the text to the left.\n -->\n <div class=\"mat-sort-header-content\">\n <ng-content></ng-content>\n </div>\n\n <!-- Disable animations while a current animation is running -->\n @if (_renderArrow()) {\n <div class=\"mat-sort-header-arrow\">\n <svg viewBox=\"0 -960 960 960\" focusable=\"false\" aria-hidden=\"true\">\n <path d=\"M440-240v-368L296-464l-56-56 240-240 240 240-56 56-144-144v368h-80Z\"/>\n </svg>\n </div>\n }\n</div>\n", styles: [".mat-sort-header{cursor:pointer}.mat-sort-header-disabled{cursor:default}.mat-sort-header-container{display:flex;align-items:center;letter-spacing:normal;outline:0}[mat-sort-header].cdk-keyboard-focused .mat-sort-header-container,[mat-sort-header].cdk-program-focused .mat-sort-header-container{border-bottom:solid 1px currentColor}.mat-sort-header-container::before{margin:calc(calc(var(--mat-focus-indicator-border-width, 3px) + 2px)*-1)}.mat-sort-header-content{display:flex;align-items:center}.mat-sort-header-position-before{flex-direction:row-reverse}@keyframes _mat-sort-header-recently-cleared-ascending{from{transform:translateY(0);opacity:1}to{transform:translateY(-25%);opacity:0}}@keyframes _mat-sort-header-recently-cleared-descending{from{transform:translateY(0) rotate(180deg);opacity:1}to{transform:translateY(25%) rotate(180deg);opacity:0}}.mat-sort-header-arrow{height:12px;width:12px;position:relative;transition:transform 225ms cubic-bezier(0.4, 0, 0.2, 1),opacity 225ms cubic-bezier(0.4, 0, 0.2, 1);opacity:0;overflow:visible;color:var(--mat-sort-arrow-color, var(--mat-sys-on-surface))}.mat-sort-header.cdk-keyboard-focused .mat-sort-header-arrow,.mat-sort-header.cdk-program-focused .mat-sort-header-arrow,.mat-sort-header:hover .mat-sort-header-arrow{opacity:.54}.mat-sort-header .mat-sort-header-sorted .mat-sort-header-arrow{opacity:1}.mat-sort-header-descending .mat-sort-header-arrow{transform:rotate(180deg)}.mat-sort-header-recently-cleared-ascending .mat-sort-header-arrow{transform:translateY(-25%)}.mat-sort-header-recently-cleared-ascending .mat-sort-header-arrow{transition:none;animation:_mat-sort-header-recently-cleared-ascending 225ms cubic-bezier(0.4, 0, 0.2, 1) forwards}.mat-sort-header-recently-cleared-descending .mat-sort-header-arrow{transition:none;animation:_mat-sort-header-recently-cleared-descending 225ms cubic-bezier(0.4, 0, 0.2, 1) forwards}.mat-sort-header-animations-disabled .mat-sort-header-arrow{transition-duration:0ms;animation-duration:0ms}.mat-sort-header-arrow svg{width:24px;height:24px;fill:currentColor;position:absolute;top:50%;left:50%;margin:-12px 0 0 -12px;transform:translateZ(0)}.mat-sort-header-arrow,[dir=rtl] .mat-sort-header-position-before .mat-sort-header-arrow{margin:0 0 0 6px}.mat-sort-header-position-before .mat-sort-header-arrow,[dir=rtl] .mat-sort-header-arrow{margin:0 6px 0 0}\n"] }]
  376. }], ctorParameters: () => [], propDecorators: { id: [{
  377. type: Input,
  378. args: ['mat-sort-header']
  379. }], arrowPosition: [{
  380. type: Input
  381. }], start: [{
  382. type: Input
  383. }], disabled: [{
  384. type: Input,
  385. args: [{ transform: booleanAttribute }]
  386. }], sortActionDescription: [{
  387. type: Input
  388. }], disableClear: [{
  389. type: Input,
  390. args: [{ transform: booleanAttribute }]
  391. }] } });
  392. class MatSortModule {
  393. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSortModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  394. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.6", ngImport: i0, type: MatSortModule, imports: [MatCommonModule, MatSort, MatSortHeader], exports: [MatSort, MatSortHeader] });
  395. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSortModule, providers: [MAT_SORT_HEADER_INTL_PROVIDER], imports: [MatCommonModule] });
  396. }
  397. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSortModule, decorators: [{
  398. type: NgModule,
  399. args: [{
  400. imports: [MatCommonModule, MatSort, MatSortHeader],
  401. exports: [MatSort, MatSortHeader],
  402. providers: [MAT_SORT_HEADER_INTL_PROVIDER],
  403. }]
  404. }] });
  405. /**
  406. * Animations used by MatSort.
  407. * @docs-private
  408. * @deprecated No longer being used, to be removed.
  409. * @breaking-change 21.0.0
  410. */
  411. const matSortAnimations = {
  412. // Represents:
  413. // trigger('indicator', [
  414. // state('active-asc, asc', style({transform: 'translateY(0px)'})),
  415. // // 10px is the height of the sort indicator, minus the width of the pointers
  416. // state('active-desc, desc', style({transform: 'translateY(10px)'})),
  417. // transition('active-asc <=> active-desc', animate(SORT_ANIMATION_TRANSITION)),
  418. // ])
  419. /** Animation that moves the sort indicator. */
  420. indicator: {
  421. type: 7,
  422. name: 'indicator',
  423. definitions: [
  424. {
  425. type: 0,
  426. name: 'active-asc, asc',
  427. styles: { type: 6, styles: { transform: 'translateY(0px)' }, offset: null },
  428. },
  429. {
  430. type: 0,
  431. name: 'active-desc, desc',
  432. styles: { type: 6, styles: { transform: 'translateY(10px)' }, offset: null },
  433. },
  434. {
  435. type: 1,
  436. expr: 'active-asc <=> active-desc',
  437. animation: { type: 4, styles: null, timings: '225ms cubic-bezier(0.4,0.0,0.2,1)' },
  438. options: null,
  439. },
  440. ],
  441. options: {},
  442. },
  443. // Represents:
  444. // trigger('leftPointer', [
  445. // state('active-asc, asc', style({transform: 'rotate(-45deg)'})),
  446. // state('active-desc, desc', style({transform: 'rotate(45deg)'})),
  447. // transition('active-asc <=> active-desc', animate(SORT_ANIMATION_TRANSITION)),
  448. // ])
  449. /** Animation that rotates the left pointer of the indicator based on the sorting direction. */
  450. leftPointer: {
  451. type: 7,
  452. name: 'leftPointer',
  453. definitions: [
  454. {
  455. type: 0,
  456. name: 'active-asc, asc',
  457. styles: { type: 6, styles: { transform: 'rotate(-45deg)' }, offset: null },
  458. },
  459. {
  460. type: 0,
  461. name: 'active-desc, desc',
  462. styles: { type: 6, styles: { transform: 'rotate(45deg)' }, offset: null },
  463. },
  464. {
  465. type: 1,
  466. expr: 'active-asc <=> active-desc',
  467. animation: { type: 4, styles: null, timings: '225ms cubic-bezier(0.4,0.0,0.2,1)' },
  468. options: null,
  469. },
  470. ],
  471. options: {},
  472. },
  473. // Represents:
  474. // trigger('rightPointer', [
  475. // state('active-asc, asc', style({transform: 'rotate(45deg)'})),
  476. // state('active-desc, desc', style({transform: 'rotate(-45deg)'})),
  477. // transition('active-asc <=> active-desc', animate(SORT_ANIMATION_TRANSITION)),
  478. // ])
  479. /** Animation that rotates the right pointer of the indicator based on the sorting direction. */
  480. rightPointer: {
  481. type: 7,
  482. name: 'rightPointer',
  483. definitions: [
  484. {
  485. type: 0,
  486. name: 'active-asc, asc',
  487. styles: { type: 6, styles: { transform: 'rotate(45deg)' }, offset: null },
  488. },
  489. {
  490. type: 0,
  491. name: 'active-desc, desc',
  492. styles: { type: 6, styles: { transform: 'rotate(-45deg)' }, offset: null },
  493. },
  494. {
  495. type: 1,
  496. expr: 'active-asc <=> active-desc',
  497. animation: { type: 4, styles: null, timings: '225ms cubic-bezier(0.4,0.0,0.2,1)' },
  498. options: null,
  499. },
  500. ],
  501. options: {},
  502. },
  503. // Represents:
  504. // trigger('arrowOpacity', [
  505. // state('desc-to-active, asc-to-active, active', style({opacity: 1})),
  506. // state('desc-to-hint, asc-to-hint, hint', style({opacity: 0.54})),
  507. // state(
  508. // 'hint-to-desc, active-to-desc, desc, hint-to-asc, active-to-asc, asc, void',
  509. // style({opacity: 0}),
  510. // ),
  511. // // Transition between all states except for immediate transitions
  512. // transition('* => asc, * => desc, * => active, * => hint, * => void', animate('0ms')),
  513. // transition('* <=> *', animate(SORT_ANIMATION_TRANSITION)),
  514. // ])
  515. /** Animation that controls the arrow opacity. */
  516. arrowOpacity: {
  517. type: 7,
  518. name: 'arrowOpacity',
  519. definitions: [
  520. {
  521. type: 0,
  522. name: 'desc-to-active, asc-to-active, active',
  523. styles: { type: 6, styles: { 'opacity': 1 }, offset: null },
  524. },
  525. {
  526. type: 0,
  527. name: 'desc-to-hint, asc-to-hint, hint',
  528. styles: { type: 6, styles: { 'opacity': 0.54 }, offset: null },
  529. },
  530. {
  531. type: 0,
  532. name: 'hint-to-desc, active-to-desc, desc, hint-to-asc, active-to-asc, asc, void',
  533. styles: { type: 6, styles: { 'opacity': 0 }, offset: null },
  534. },
  535. {
  536. type: 1,
  537. expr: '* => asc, * => desc, * => active, * => hint, * => void',
  538. animation: { type: 4, styles: null, timings: '0ms' },
  539. options: null,
  540. },
  541. {
  542. type: 1,
  543. expr: '* <=> *',
  544. animation: { type: 4, styles: null, timings: '225ms cubic-bezier(0.4,0.0,0.2,1)' },
  545. options: null,
  546. },
  547. ],
  548. options: {},
  549. },
  550. // Represents:
  551. // trigger('arrowPosition', [
  552. // // Hidden Above => Hint Center
  553. // transition(
  554. // '* => desc-to-hint, * => desc-to-active',
  555. // animate(
  556. // SORT_ANIMATION_TRANSITION,
  557. // keyframes([style({transform: 'translateY(-25%)'}), style({transform: 'translateY(0)'})]),
  558. // ),
  559. // ),
  560. // // Hint Center => Hidden Below
  561. // transition(
  562. // '* => hint-to-desc, * => active-to-desc',
  563. // animate(
  564. // SORT_ANIMATION_TRANSITION,
  565. // keyframes([style({transform: 'translateY(0)'}), style({transform: 'translateY(25%)'})]),
  566. // ),
  567. // ),
  568. // // Hidden Below => Hint Center
  569. // transition(
  570. // '* => asc-to-hint, * => asc-to-active',
  571. // animate(
  572. // SORT_ANIMATION_TRANSITION,
  573. // keyframes([style({transform: 'translateY(25%)'}), style({transform: 'translateY(0)'})]),
  574. // ),
  575. // ),
  576. // // Hint Center => Hidden Above
  577. // transition(
  578. // '* => hint-to-asc, * => active-to-asc',
  579. // animate(
  580. // SORT_ANIMATION_TRANSITION,
  581. // keyframes([style({transform: 'translateY(0)'}), style({transform: 'translateY(-25%)'})]),
  582. // ),
  583. // ),
  584. // state(
  585. // 'desc-to-hint, asc-to-hint, hint, desc-to-active, asc-to-active, active',
  586. // style({transform: 'translateY(0)'}),
  587. // ),
  588. // state('hint-to-desc, active-to-desc, desc', style({transform: 'translateY(-25%)'})),
  589. // state('hint-to-asc, active-to-asc, asc', style({transform: 'translateY(25%)'})),
  590. // ])
  591. /**
  592. * Animation for the translation of the arrow as a whole. States are separated into two
  593. * groups: ones with animations and others that are immediate. Immediate states are asc, desc,
  594. * peek, and active. The other states define a specific animation (source-to-destination)
  595. * and are determined as a function of their prev user-perceived state and what the next state
  596. * should be.
  597. */
  598. arrowPosition: {
  599. type: 7,
  600. name: 'arrowPosition',
  601. definitions: [
  602. {
  603. type: 1,
  604. expr: '* => desc-to-hint, * => desc-to-active',
  605. animation: {
  606. type: 4,
  607. styles: {
  608. type: 5,
  609. 'steps': [
  610. { type: 6, styles: { transform: 'translateY(-25%)' }, offset: null },
  611. { type: 6, styles: { transform: 'translateY(0)' }, offset: null },
  612. ],
  613. },
  614. timings: '225ms cubic-bezier(0.4,0.0,0.2,1)',
  615. },
  616. options: null,
  617. },
  618. {
  619. type: 1,
  620. expr: '* => hint-to-desc, * => active-to-desc',
  621. animation: {
  622. type: 4,
  623. styles: {
  624. type: 5,
  625. 'steps': [
  626. { type: 6, styles: { transform: 'translateY(0)' }, offset: null },
  627. { type: 6, styles: { transform: 'translateY(25%)' }, offset: null },
  628. ],
  629. },
  630. timings: '225ms cubic-bezier(0.4,0.0,0.2,1)',
  631. },
  632. options: null,
  633. },
  634. {
  635. type: 1,
  636. expr: '* => asc-to-hint, * => asc-to-active',
  637. animation: {
  638. type: 4,
  639. styles: {
  640. type: 5,
  641. 'steps': [
  642. { type: 6, styles: { transform: 'translateY(25%)' }, offset: null },
  643. { type: 6, styles: { transform: 'translateY(0)' }, offset: null },
  644. ],
  645. },
  646. timings: '225ms cubic-bezier(0.4,0.0,0.2,1)',
  647. },
  648. options: null,
  649. },
  650. {
  651. type: 1,
  652. expr: '* => hint-to-asc, * => active-to-asc',
  653. animation: {
  654. type: 4,
  655. styles: {
  656. type: 5,
  657. 'steps': [
  658. { type: 6, styles: { transform: 'translateY(0)' }, offset: null },
  659. { type: 6, styles: { transform: 'translateY(-25%)' }, offset: null },
  660. ],
  661. },
  662. timings: '225ms cubic-bezier(0.4,0.0,0.2,1)',
  663. },
  664. options: null,
  665. },
  666. {
  667. type: 0,
  668. name: 'desc-to-hint, asc-to-hint, hint, desc-to-active, asc-to-active, active',
  669. styles: { type: 6, styles: { transform: 'translateY(0)' }, offset: null },
  670. },
  671. {
  672. type: 0,
  673. name: 'hint-to-desc, active-to-desc, desc',
  674. styles: { type: 6, styles: { transform: 'translateY(-25%)' }, offset: null },
  675. },
  676. {
  677. type: 0,
  678. name: 'hint-to-asc, active-to-asc, asc',
  679. styles: { type: 6, styles: { transform: 'translateY(25%)' }, offset: null },
  680. },
  681. ],
  682. options: {},
  683. },
  684. // Represents:
  685. // trigger('allowChildren', [
  686. // transition('* <=> *', [query('@*', animateChild(), {optional: true})]),
  687. // ])
  688. /** Necessary trigger that calls animate on children animations. */
  689. allowChildren: {
  690. type: 7,
  691. name: 'allowChildren',
  692. definitions: [
  693. {
  694. type: 1,
  695. expr: '* <=> *',
  696. animation: [
  697. {
  698. type: 11,
  699. selector: '@*',
  700. animation: { type: 9, options: null },
  701. options: { optional: true },
  702. },
  703. ],
  704. options: null,
  705. },
  706. ],
  707. options: {},
  708. },
  709. };
  710. export { MAT_SORT_DEFAULT_OPTIONS, MAT_SORT_HEADER_INTL_PROVIDER, MAT_SORT_HEADER_INTL_PROVIDER_FACTORY, MatSort, MatSortHeader, MatSortHeaderIntl, MatSortModule, matSortAnimations };
  711. //# sourceMappingURL=sort.mjs.map