import { BidiModule } from '@angular/cdk/bidi'; import * as i0 from '@angular/core'; import { InjectionToken, EventEmitter, booleanAttribute, Directive, Optional, Inject, Input, Output, Injectable, inject, ChangeDetectorRef, ElementRef, signal, Component, ViewEncapsulation, ChangeDetectionStrategy, NgModule } from '@angular/core'; import { FocusMonitor, AriaDescriber } from '@angular/cdk/a11y'; import { SPACE, ENTER } from '@angular/cdk/keycodes'; import { ReplaySubject, Subject, merge } from 'rxjs'; import { _CdkPrivateStyleLoader } from '@angular/cdk/private'; import { _animationsDisabled } from './_animation-chunk.mjs'; import { _StructuralStylesLoader } from './_structural-styles-chunk.mjs'; import '@angular/cdk/layout'; function getSortDuplicateSortableIdError(id) { return Error(`Cannot have two MatSortables with the same id (${id}).`); } function getSortHeaderNotContainedWithinSortError() { return Error(`MatSortHeader must be placed within a parent element with the MatSort directive.`); } function getSortHeaderMissingIdError() { return Error(`MatSortHeader must be provided with a unique id.`); } function getSortInvalidDirectionError(direction) { return Error(`${direction} is not a valid sort direction ('asc' or 'desc').`); } const MAT_SORT_DEFAULT_OPTIONS = new InjectionToken('MAT_SORT_DEFAULT_OPTIONS'); class MatSort { _defaultOptions; _initializedStream = new ReplaySubject(1); sortables = new Map(); _stateChanges = new Subject(); active; start = 'asc'; get direction() { return this._direction; } set direction(direction) { if (direction && direction !== 'asc' && direction !== 'desc' && (typeof ngDevMode === 'undefined' || ngDevMode)) { throw getSortInvalidDirectionError(direction); } this._direction = direction; } _direction = ''; disableClear; disabled = false; sortChange = new EventEmitter(); initialized = this._initializedStream; constructor(_defaultOptions) { this._defaultOptions = _defaultOptions; } register(sortable) { if (typeof ngDevMode === 'undefined' || ngDevMode) { if (!sortable.id) { throw getSortHeaderMissingIdError(); } if (this.sortables.has(sortable.id)) { throw getSortDuplicateSortableIdError(sortable.id); } } this.sortables.set(sortable.id, sortable); } deregister(sortable) { this.sortables.delete(sortable.id); } sort(sortable) { if (this.active != sortable.id) { this.active = sortable.id; this.direction = sortable.start ? sortable.start : this.start; } else { this.direction = this.getNextSortDirection(sortable); } this.sortChange.emit({ active: this.active, direction: this.direction }); } getNextSortDirection(sortable) { if (!sortable) { return ''; } const disableClear = sortable?.disableClear ?? this.disableClear ?? !!this._defaultOptions?.disableClear; let sortDirectionCycle = getSortDirectionCycle(sortable.start || this.start, disableClear); let nextDirectionIndex = sortDirectionCycle.indexOf(this.direction) + 1; if (nextDirectionIndex >= sortDirectionCycle.length) { nextDirectionIndex = 0; } return sortDirectionCycle[nextDirectionIndex]; } ngOnInit() { this._initializedStream.next(); } ngOnChanges() { this._stateChanges.next(); } ngOnDestroy() { this._stateChanges.complete(); this._initializedStream.complete(); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: MatSort, deps: [{ token: MAT_SORT_DEFAULT_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "21.0.3", 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 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: MatSort, decorators: [{ type: Directive, args: [{ selector: '[matSort]', exportAs: 'matSort', host: { 'class': 'mat-sort' } }] }], ctorParameters: () => [{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_SORT_DEFAULT_OPTIONS] }] }], propDecorators: { active: [{ type: Input, args: ['matSortActive'] }], start: [{ type: Input, args: ['matSortStart'] }], direction: [{ type: Input, args: ['matSortDirection'] }], disableClear: [{ type: Input, args: [{ alias: 'matSortDisableClear', transform: booleanAttribute }] }], disabled: [{ type: Input, args: [{ alias: 'matSortDisabled', transform: booleanAttribute }] }], sortChange: [{ type: Output, args: ['matSortChange'] }] } }); function getSortDirectionCycle(start, disableClear) { let sortOrder = ['asc', 'desc']; if (start == 'desc') { sortOrder.reverse(); } if (!disableClear) { sortOrder.push(''); } return sortOrder; } class MatSortHeaderIntl { changes = new Subject(); static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: MatSortHeaderIntl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: MatSortHeaderIntl, providedIn: 'root' }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: MatSortHeaderIntl, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }] }); class MatSortHeader { _intl = inject(MatSortHeaderIntl); _sort = inject(MatSort, { optional: true }); _columnDef = inject('MAT_SORT_HEADER_COLUMN_DEF', { optional: true }); _changeDetectorRef = inject(ChangeDetectorRef); _focusMonitor = inject(FocusMonitor); _elementRef = inject(ElementRef); _ariaDescriber = inject(AriaDescriber, { optional: true }); _renderChanges; _animationsDisabled = _animationsDisabled(); _recentlyCleared = signal(null, ...(ngDevMode ? [{ debugName: "_recentlyCleared" }] : [])); _sortButton; id; arrowPosition = 'after'; start; disabled = false; get sortActionDescription() { return this._sortActionDescription; } set sortActionDescription(value) { this._updateSortActionDescription(value); } _sortActionDescription = 'Sort'; disableClear; constructor() { inject(_CdkPrivateStyleLoader).load(_StructuralStylesLoader); const defaultOptions = inject(MAT_SORT_DEFAULT_OPTIONS, { optional: true }); if (!this._sort && (typeof ngDevMode === 'undefined' || ngDevMode)) { throw getSortHeaderNotContainedWithinSortError(); } if (defaultOptions?.arrowPosition) { this.arrowPosition = defaultOptions?.arrowPosition; } } ngOnInit() { if (!this.id && this._columnDef) { this.id = this._columnDef.name; } this._sort.register(this); this._renderChanges = merge(this._sort._stateChanges, this._sort.sortChange).subscribe(() => this._changeDetectorRef.markForCheck()); this._sortButton = this._elementRef.nativeElement.querySelector('.mat-sort-header-container'); this._updateSortActionDescription(this._sortActionDescription); } ngAfterViewInit() { this._focusMonitor.monitor(this._elementRef, true).subscribe(() => { Promise.resolve().then(() => this._recentlyCleared.set(null)); }); } ngOnDestroy() { this._focusMonitor.stopMonitoring(this._elementRef); this._sort.deregister(this); this._renderChanges?.unsubscribe(); if (this._sortButton) { this._ariaDescriber?.removeDescription(this._sortButton, this._sortActionDescription); } } _toggleOnInteraction() { if (!this._isDisabled()) { const wasSorted = this._isSorted(); const prevDirection = this._sort.direction; this._sort.sort(this); this._recentlyCleared.set(wasSorted && !this._isSorted() ? prevDirection : null); } } _handleKeydown(event) { if (event.keyCode === SPACE || event.keyCode === ENTER) { event.preventDefault(); this._toggleOnInteraction(); } } _isSorted() { return this._sort.active == this.id && (this._sort.direction === 'asc' || this._sort.direction === 'desc'); } _isDisabled() { return this._sort.disabled || this.disabled; } _getAriaSortAttribute() { if (!this._isSorted()) { return 'none'; } return this._sort.direction == 'asc' ? 'ascending' : 'descending'; } _renderArrow() { return !this._isDisabled() || this._isSorted(); } _updateSortActionDescription(newDescription) { if (this._sortButton) { this._ariaDescriber?.removeDescription(this._sortButton, this._sortActionDescription); this._ariaDescriber?.describe(this._sortButton, newDescription); } this._sortActionDescription = newDescription; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: MatSortHeader, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", 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