diff --git a/backlog.md b/backlog.md index 6c0848f..66fa3d8 100644 --- a/backlog.md +++ b/backlog.md @@ -1,4 +1,2 @@ -* change library to standalone -* publish v17 * add prettier * add ssr diff --git a/projects/mat-datatable-demo/src/app/app.component.spec.ts b/projects/mat-datatable-demo/src/app/app.component.spec.ts index 2112f1e..df0fc33 100644 --- a/projects/mat-datatable-demo/src/app/app.component.spec.ts +++ b/projects/mat-datatable-demo/src/app/app.component.spec.ts @@ -11,24 +11,22 @@ import { NgxRerenderModule } from 'ngx-rerender'; import { AppComponent } from './app.component'; -import { MatDatatableModule } from 'mat-datatable'; +import { MatDatatableComponent } from 'mat-datatable'; describe('AppComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ - AppComponent - ], imports: [ + AppComponent, BrowserAnimationsModule, HttpClientModule, MatButtonModule, MatChipsModule, + MatDatatableComponent, MatFormFieldModule, MatIconModule, MatSelectModule, MatSlideToggleModule, - MatDatatableModule, NgxRerenderModule ] }).compileComponents(); diff --git a/projects/mat-datatable-demo/src/app/app.component.ts b/projects/mat-datatable-demo/src/app/app.component.ts index f5f50a6..42d77e8 100644 --- a/projects/mat-datatable-demo/src/app/app.component.ts +++ b/projects/mat-datatable-demo/src/app/app.component.ts @@ -1,8 +1,15 @@ import { trigger, transition, style, animate } from '@angular/animations'; +import { NgIf, NgFor, AsyncPipe } from '@angular/common'; import { AfterViewInit, Component, OnDestroy, ViewChild } from '@angular/core'; -import { MatIconRegistry } from '@angular/material/icon'; -import { MatSlideToggleChange } from '@angular/material/slide-toggle'; +import { MatButton, MatMiniFabButton } from '@angular/material/button'; +import { MatChipListbox, MatChip, MatChipRemove } from '@angular/material/chips'; +import { MatOption } from '@angular/material/core'; +import { MatLabel, MatFormField } from '@angular/material/form-field'; +import { MatIconRegistry, MatIcon } from '@angular/material/icon'; +import { MatSelect } from '@angular/material/select'; +import { MatSlideToggleChange, MatSlideToggle } from '@angular/material/slide-toggle'; import { DomSanitizer } from '@angular/platform-browser'; +import { NgxRerenderModule } from 'ngx-rerender'; import { BehaviorSubject, delay, Subject, takeUntil } from 'rxjs'; import { ARROW_UPWARD, ARROW_DOWNWARD } from './app.svg'; @@ -18,20 +25,39 @@ import { } from 'mat-datatable'; @Component({ - selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], - animations: [ - trigger('slideInBottom', [ - transition(':enter', [ - style({ transform: 'translateY(100%)' }), - animate('500ms ease-out', style({ transform: 'translateY(0)' })) - ]), - transition(':leave', [ - animate('500ms ease-out', style({ transform: 'translateY(100%)' })) + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.scss'], + animations: [ + trigger('slideInBottom', [ + transition(':enter', [ + style({ transform: 'translateY(100%)' }), + animate('500ms ease-out', style({ transform: 'translateY(0)' })) + ]), + transition(':leave', [ + animate('500ms ease-out', style({ transform: 'translateY(100%)' })) + ]) ]) - ]) - ] + ], + standalone: true, + imports: [ + AsyncPipe, + MatButton, + MatChip, + MatChipListbox, + MatChipRemove, + MatDatatableComponent, + MatFormField, + MatIcon, + MatLabel, + MatMiniFabButton, + MatOption, + MatSelect, + MatSlideToggle, + NgIf, + NgFor, + NgxRerenderModule + ] }) export class AppComponent implements AfterViewInit, OnDestroy { @ViewChild('datatable') table!: MatDatatableComponent; diff --git a/projects/mat-datatable-demo/src/app/app.module.ts b/projects/mat-datatable-demo/src/app/app.module.ts deleted file mode 100644 index 316ab0c..0000000 --- a/projects/mat-datatable-demo/src/app/app.module.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { HttpClientModule } from '@angular/common/http'; -import { NgModule } from '@angular/core'; -import { MatButtonModule } from '@angular/material/button'; -import { MatChipsModule } from '@angular/material/chips'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatIconModule } from '@angular/material/icon'; -import { MatSelectModule } from '@angular/material/select'; -import { MatSlideToggleModule } from '@angular/material/slide-toggle'; -import { BrowserModule } from '@angular/platform-browser'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { NgxRerenderModule } from 'ngx-rerender'; - -import { AppComponent } from './app.component'; - -import { MatDatatableModule } from 'mat-datatable'; - -@NgModule({ - declarations: [ - AppComponent - ], - imports: [ - BrowserAnimationsModule, - BrowserModule, - HttpClientModule, - MatButtonModule, - MatChipsModule, - MatFormFieldModule, - MatIconModule, - MatSelectModule, - MatSlideToggleModule, - MatDatatableModule, - NgxRerenderModule - ], - providers: [], - bootstrap: [AppComponent] -}) -export class AppModule { } diff --git a/projects/mat-datatable-demo/src/main.ts b/projects/mat-datatable-demo/src/main.ts index 0a62114..bbedf87 100644 --- a/projects/mat-datatable-demo/src/main.ts +++ b/projects/mat-datatable-demo/src/main.ts @@ -1,6 +1,31 @@ -import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +import { withInterceptorsFromDi, provideHttpClient } from '@angular/common/http'; +import { importProvidersFrom } from '@angular/core'; +import { MatButtonModule } from '@angular/material/button'; +import { MatChipsModule } from '@angular/material/chips'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatIconModule } from '@angular/material/icon'; +import { MatSelectModule } from '@angular/material/select'; +import { MatSlideToggleModule } from '@angular/material/slide-toggle'; +import { BrowserModule, bootstrapApplication } from '@angular/platform-browser'; +import { provideAnimations } from '@angular/platform-browser/animations'; +import { NgxRerenderModule } from 'ngx-rerender'; -import { AppModule } from './app/app.module'; +import { AppComponent } from './app/app.component'; -platformBrowserDynamic().bootstrapModule(AppModule) +bootstrapApplication(AppComponent, { + providers: [ + importProvidersFrom( + BrowserModule, + MatButtonModule, + MatChipsModule, + MatFormFieldModule, + MatIconModule, + MatSelectModule, + MatSlideToggleModule, + NgxRerenderModule + ), + provideAnimations(), + provideHttpClient(withInterceptorsFromDi()) + ] +}) .catch(err => console.error(err)); diff --git a/projects/mat-datatable-lib/src/directives/datatable-header-align.directive.spec.ts b/projects/mat-datatable-lib/src/directives/datatable-header-align.directive.spec.ts index 852d800..59319c3 100644 --- a/projects/mat-datatable-lib/src/directives/datatable-header-align.directive.spec.ts +++ b/projects/mat-datatable-lib/src/directives/datatable-header-align.directive.spec.ts @@ -10,13 +10,13 @@ describe('MatDatatableHeaderAlignDirective', () => { beforeEach(() => { fixture = TestBed.configureTestingModule({ - declarations: [ - MatDatatableHeaderAlignDirective, + imports: [ TestComponent ] - }) - .createComponent(TestComponent); - fixture.detectChanges(); // initial binding + }).createComponent(TestComponent); + + // initial binding + fixture.detectChanges(); // all elements with an attached MatDatatableHeaderAlignDirective directiveElements = fixture.debugElement.queryAll(By.directive(MatDatatableHeaderAlignDirective)); @@ -97,6 +97,10 @@ describe('MatDatatableHeaderAlignDirective', () => { - ` + `, + standalone: true, + imports: [ + MatDatatableHeaderAlignDirective + ] }) class TestComponent { } diff --git a/projects/mat-datatable-lib/src/directives/datatable-header-align.directive.ts b/projects/mat-datatable-lib/src/directives/datatable-header-align.directive.ts index a2c340b..754dacd 100644 --- a/projects/mat-datatable-lib/src/directives/datatable-header-align.directive.ts +++ b/projects/mat-datatable-lib/src/directives/datatable-header-align.directive.ts @@ -3,7 +3,8 @@ import { AfterViewInit, Directive, ElementRef, Input, Renderer2 } from '@angular import { ColumnAlignmentType } from '../interfaces/datatable-column-definition.interface'; @Directive({ - selector: '[matHeaderAlignment]' + selector: '[matHeaderAlignment]', + standalone: true }) export class MatDatatableHeaderAlignDirective implements AfterViewInit { @Input() matHeaderAlignment: ColumnAlignmentType | undefined; diff --git a/projects/mat-datatable-lib/src/directives/datatable-resizable.directive.spec.ts b/projects/mat-datatable-lib/src/directives/datatable-resizable.directive.spec.ts index d8fc840..70045b1 100644 --- a/projects/mat-datatable-lib/src/directives/datatable-resizable.directive.spec.ts +++ b/projects/mat-datatable-lib/src/directives/datatable-resizable.directive.spec.ts @@ -10,11 +10,9 @@ describe('MatResizableDirective', () => { beforeEach(() => { fixture = TestBed.configureTestingModule({ - declarations: [ - MatDatatableResizableDirective, - TestComponent - ] - }) + imports: [MatDatatableResizableDirective, + TestComponent] +}) .createComponent(TestComponent); fixture.detectChanges(); // initial binding @@ -66,23 +64,27 @@ describe('MatResizableDirective', () => { @Component({ template: ` - - -
default header
- - -
resizable header
- - -
not resizable header
- - -
not resizable header
- - -
not resizable header
- - - ` + + +
default header
+ + +
resizable header
+ + +
not resizable header
+ + +
not resizable header
+ + +
not resizable header
+ + + `, + standalone: true, + imports: [ + MatDatatableResizableDirective + ] }) class TestComponent { } diff --git a/projects/mat-datatable-lib/src/directives/datatable-resizable.directive.ts b/projects/mat-datatable-lib/src/directives/datatable-resizable.directive.ts index b788ead..75a53ef 100644 --- a/projects/mat-datatable-lib/src/directives/datatable-resizable.directive.ts +++ b/projects/mat-datatable-lib/src/directives/datatable-resizable.directive.ts @@ -10,7 +10,8 @@ import { } from '@angular/core'; @Directive({ - selector: '[matResizable]' + selector: '[matResizable]', + standalone: true }) export class MatDatatableResizableDirective implements OnInit, OnDestroy { @Input() diff --git a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-badge.directive.spec.ts b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-badge.directive.spec.ts index 6ba082e..a2966d5 100644 --- a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-badge.directive.spec.ts +++ b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-badge.directive.spec.ts @@ -14,10 +14,9 @@ describe('MatMultiSortBadgeDirective', () => { beforeEach(() => { fixture = TestBed.configureTestingModule({ - declarations: [ - BadgeTestApp, - MatMultiSortBadgeDirective - ] + imports: [ + BadgeTestApp + ] }).createComponent(BadgeTestApp); testComponent = fixture.debugElement.componentInstance as BadgeTestApp; fixture.detectChanges(); // initial binding @@ -181,15 +180,19 @@ describe('MatMultiSortBadgeDirective', () => { encapsulation: ViewEncapsulation.Emulated, styles: ['span { color: hotpink; }'], template: ` - - home - - ` + + home + + `, + standalone: true, + imports: [ + MatMultiSortBadgeDirective + ] }) class BadgeTestApp { @ViewChild(MatMultiSortBadgeDirective) badgeInstance!: MatMultiSortBadgeDirective; @@ -203,10 +206,10 @@ class BadgeTestApp { @Component({ template: ` - - home -
Pre-existing badge
-
+ + home +
Pre-existing badge
+
` }) class PreExistingBadge {} diff --git a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-badge.directive.ts b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-badge.directive.ts index c88a4f7..b3db524 100644 --- a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-badge.directive.ts +++ b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-badge.directive.ts @@ -26,17 +26,18 @@ const BADGE_CONTENT_CLASS = 'mat-multi-sort-badge-content'; /** Directive to display a text badge. */ @Directive({ - selector: '[matMultiSortBadge]', - inputs: ['disabled: matMultiSortBadgeDisabled'], - host: { - 'class': 'mat-multi-sort-badge', - '[class.mat-multi-sort-badge-above]': '!isAscending()', - '[class.mat-multi-sort-badge-below]': 'isAscending()', - '[class.mat-multi-sort-badge-before]': '!isAfter()', - '[class.mat-multi-sort-badge-after]': 'isAfter()', - '[class.mat-multi-sort-badge-hidden]': 'hidden || !content', - '[class.mat-multi-sort-badge-disabled]': 'disabled' - } + selector: '[matMultiSortBadge]', + inputs: ['disabled: matMultiSortBadgeDisabled'], + host: { + 'class': 'mat-multi-sort-badge', + '[class.mat-multi-sort-badge-above]': '!isAscending()', + '[class.mat-multi-sort-badge-below]': 'isAscending()', + '[class.mat-multi-sort-badge-before]': '!isAfter()', + '[class.mat-multi-sort-badge-after]': 'isAfter()', + '[class.mat-multi-sort-badge-hidden]': 'hidden || !content', + '[class.mat-multi-sort-badge-disabled]': 'disabled' + }, + standalone: true }) export class MatMultiSortBadgeDirective implements OnInit, OnDestroy { /** diff --git a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-header.component.ts b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-header.component.ts index 0a9d757..be3d5b0 100644 --- a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-header.component.ts +++ b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort-header.component.ts @@ -2,6 +2,7 @@ /* eslint-disable @angular-eslint/no-host-metadata-property */ import { AriaDescriber, FocusMonitor } from '@angular/cdk/a11y'; +import { NgIf } from '@angular/common'; import { AfterViewInit, ChangeDetectionStrategy, @@ -26,6 +27,7 @@ import { } from '@angular/material/sort'; import { Subject, takeUntil } from 'rxjs'; +import { MatMultiSortBadgeDirective } from './mat-multi-sort-badge.directive'; import { getMultiSortHeaderNotContainedWithinMultiSortError } from './mat-multi-sort-errors'; import { MatMultiSort } from './mat-multi-sort.directive'; @@ -52,6 +54,11 @@ interface MatSortHeaderColumnDef { changeDetection: ChangeDetectionStrategy.OnPush, // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property inputs: ['disabled'], + standalone: true, + imports: [ + MatMultiSortBadgeDirective, + NgIf + ], animations: [ matSortAnimations.indicator, matSortAnimations.leftPointer, diff --git a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.directive.spec.ts b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.directive.spec.ts index 860f7fc..f2e308d 100644 --- a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.directive.spec.ts +++ b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.directive.spec.ts @@ -10,13 +10,17 @@ import { MAT_SORT_DEFAULT_OPTIONS , } from '@angular/material/sort'; import { MatTableModule } from '@angular/material/table'; import { By } from '@angular/platform-browser'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { provideNoopAnimations } from '@angular/platform-browser/animations'; import { Observable, map } from 'rxjs'; -import { getMultiSortDuplicateSortableIdError, getMultiSortHeaderMissingIdError, getMultiSortHeaderNotContainedWithinMultiSortError, getSortInvalidDirectionError } from './mat-multi-sort-errors'; +import { + getMultiSortDuplicateSortableIdError, + getMultiSortHeaderMissingIdError, + getMultiSortHeaderNotContainedWithinMultiSortError, + getSortInvalidDirectionError +} from './mat-multi-sort-errors'; import { MatMultiSortHeader } from './mat-multi-sort-header.component'; import { MatMultiSort } from './mat-multi-sort.directive'; -import { MatMultiSortModule } from './mat-multi-sort.module'; import { dispatchMouseEvent } from './testbed/fake-events/dispatch-events'; import { createFakeEvent, createMouseEvent } from './testbed/fake-events/event-objects'; import { wrappedErrorMessage } from './wrapped-error-message'; @@ -29,23 +33,12 @@ describe('MatMultiSorDirective', () => { beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatMultiSortModule, - MatTableModule, - CdkTableModule, - NoopAnimationsModule + SimpleMatMultiSortApp ], - declarations: [ - SimpleMatMultiSortApp, - CdkTableMatMultiSortApp, - MatTableMatMultiSortApp, - MatMultiSortHeaderMissingMatMultiSortApp, - MatMultiSortDuplicateMatSortableIdsApp, - MatSortableMissingIdApp, - MatMultiSortableInvalidDirection, - MatMultiSortWithArrowPosition + providers: [ + provideNoopAnimations() ] - }) - .compileComponents(); + }).compileComponents(); })); beforeEach(() => { @@ -388,7 +381,7 @@ describe('MatMultiSorDirective', () => { it('should throw an error if the provided direction is invalid', () => { expect(() => - TestBed.createComponent(MatMultiSortableInvalidDirection).detectChanges() + TestBed.createComponent(MatMultiSortableInvalidDirectionApp).detectChanges() ).toThrowError(wrappedErrorMessage(getSortInvalidDirectionError('ascending'))); }); @@ -545,7 +538,7 @@ describe('MatMultiSorDirective', () => { it('should render arrows after sort header by default', () => { // create component with 'arrowPosition = undefined' - const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPosition); + const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPositionApp); matSortWithArrowPositionFixture.detectChanges(); @@ -559,7 +552,7 @@ describe('MatMultiSorDirective', () => { }); it('should render arrows before if appropriate parameter passed', () => { - const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPosition); + const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPositionApp); const matSortWithArrowPositionComponent = matSortWithArrowPositionFixture.componentInstance; matSortWithArrowPositionComponent.arrowPosition = 'before'; @@ -576,7 +569,7 @@ describe('MatMultiSorDirective', () => { it('should render arrows in proper position based on arrowPosition parameter', () => { // create component with 'arrowPosition = undefined' - const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPosition); + const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPositionApp); const matSortWithArrowPositionComponent = matSortWithArrowPositionFixture.componentInstance; matSortWithArrowPositionFixture.detectChanges(); @@ -599,7 +592,7 @@ describe('MatMultiSorDirective', () => { it('should render sorting position badge after sort header by default', () => { // create component with 'arrowPosition = undefined' - const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPosition); + const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPositionApp); matSortWithArrowPositionFixture.detectChanges(); @@ -613,7 +606,7 @@ describe('MatMultiSorDirective', () => { }); it('should render sorting position badge before if appropriate parameter passed', () => { - const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPosition); + const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPositionApp); const matSortWithArrowPositionComponent = matSortWithArrowPositionFixture.componentInstance; matSortWithArrowPositionComponent.arrowPosition = 'before'; @@ -630,7 +623,7 @@ describe('MatMultiSorDirective', () => { it('should render sorting position badge in proper position based on arrowPosition parameter', () => { // create component with 'arrowPosition = undefined' - const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPosition); + const matSortWithArrowPositionFixture = TestBed.createComponent(MatMultiSortWithArrowPositionApp); const matSortWithArrowPositionComponent = matSortWithArrowPositionFixture.componentInstance; matSortWithArrowPositionComponent.arrowPosition = 'after'; @@ -671,19 +664,13 @@ describe('MatMultiSorDirective', () => { }); describe('with default options', () => { - let fixture: ComponentFixture; - let component: MatMultiSortWithoutExplicitInputs; + let fixture: ComponentFixture; + let component: MatMultiSortWithoutExplicitInputsApp; beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatMultiSortModule, - MatTableModule, - CdkTableModule, - NoopAnimationsModule - ], - declarations: [ - MatMultiSortWithoutExplicitInputs + MatMultiSortWithoutExplicitInputsApp ], providers: [ { @@ -691,13 +678,14 @@ describe('MatMultiSorDirective', () => { useValue: { disableClear: true } - } + }, + provideNoopAnimations() ] }).compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(MatMultiSortWithoutExplicitInputs); + fixture = TestBed.createComponent(MatMultiSortWithoutExplicitInputsApp); component = fixture.componentInstance; fixture.detectChanges(); }); @@ -714,17 +702,13 @@ describe('MatMultiSorDirective', () => { }); describe('with default arrowPosition', () => { - let fixture: ComponentFixture; + let fixture: ComponentFixture; beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatMultiSortModule, - MatTableModule, - CdkTableModule, - NoopAnimationsModule + MatSortWithoutInputsApp ], - declarations: [MatSortWithoutInputs], providers: [ { provide: MAT_SORT_DEFAULT_OPTIONS, @@ -732,13 +716,14 @@ describe('MatMultiSorDirective', () => { disableClear: true, arrowPosition: 'before' } - } + }, + provideNoopAnimations() ] }).compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(MatSortWithoutInputs); + fixture = TestBed.createComponent(MatSortWithoutInputsApp); fixture.detectChanges(); }); @@ -762,7 +747,7 @@ describe('MatMultiSorDirective', () => { */ // eslint-disable-next-line prefer-arrow/prefer-arrow-functions function testSingleColumnSortDirectionSequence( - fixture: ComponentFixture, + fixture: ComponentFixture, expectedSequence: SortDirection[], id: SimpleMatSortAppColumnIds = 'defaultA' ) { @@ -805,38 +790,43 @@ type SimpleMatSortAppColumnIds = 'defaultA' | 'defaultB' | 'overrideStart' | 'ov @Component({ template: ` -
-
- A -
-
- B -
-
- D -
-
- E -
-
- ` +
+
+ A +
+
+ B +
+
+ D +
+
+ E +
+
+ `, + standalone: true, + imports: [ + MatMultiSort, + MatMultiSortHeader + ] }) class SimpleMatMultiSortApp { latestSortEvent!: Sort[]; @@ -903,26 +893,32 @@ class FakeDataSource extends DataSource { @Component({ template: ` - - - Column A - {{row.a}} - - - - Column B - {{row.b}} - - - - Column C - {{row.c}} - - - - - - ` + + + Column A + {{row.a}} + + + + Column B + {{row.b}} + + + + Column C + {{row.c}} + + + + + + `, + standalone: true, + imports: [ + CdkTableModule, + MatMultiSort, + MatMultiSortHeader + ] }) class CdkTableMatMultiSortApp { @ViewChild(MatMultiSort) matMultiSort: MatMultiSort | undefined; @@ -933,26 +929,32 @@ class CdkTableMatMultiSortApp { @Component({ template: ` - - - Column A - {{row.a}} - - - - Column B - {{row.b}} - - - - Column C - {{row.c}} - - - - - - ` + + + Column A + {{row.a}} + + + + Column B + {{row.b}} + + + + Column C + {{row.c}} + + + + + + `, + standalone: true, + imports: [ + MatMultiSort, + MatMultiSortHeader, + MatTableModule + ] }) class MatTableMatMultiSortApp { @ViewChild(MatMultiSort) matMultiSort: MatMultiSort | undefined; @@ -962,17 +964,26 @@ class MatTableMatMultiSortApp { } @Component({ - template: '
A
' + template: '
A
', + standalone: true, + imports: [ + MatMultiSortHeader + ] }) class MatMultiSortHeaderMissingMatMultiSortApp {} @Component({ template: ` -
-
A
-
B
-
- ` +
+
A
+
B
+
+ `, + standalone: true, + imports: [ + MatMultiSort, + MatMultiSortHeader + ] }) class MatMultiSortDuplicateMatSortableIdsApp { @ViewChild(MatMultiSort) matMultiSort!: MatMultiSort; @@ -980,35 +991,50 @@ class MatMultiSortDuplicateMatSortableIdsApp { @Component({ template: ` -
-
A
-
- ` +
+
A
+
+ `, + standalone: true, + imports: [ + MatMultiSort, + MatMultiSortHeader + ] }) class MatSortableMissingIdApp {} @Component({ template: ` -
-
A
-
- ` +
+
A
+
+ `, + standalone: true, + imports: [ + MatMultiSort, + MatMultiSortHeader + ] }) -class MatMultiSortableInvalidDirection {} +class MatMultiSortableInvalidDirectionApp {} @Component({ template: ` -
-
- A -
-
- ` +
+
+ A +
+
+ `, + standalone: true, + imports: [ + MatMultiSort, + MatMultiSortHeader + ] }) -class MatMultiSortWithoutExplicitInputs { +class MatMultiSortWithoutExplicitInputsApp { latestSortEvent!: Sort[]; @@ -1034,17 +1060,22 @@ class MatMultiSortWithoutExplicitInputs { @Component({ template: ` -
-
- A -
-
- B -
-
- ` +
+
+ A +
+
+ B +
+
+ `, + standalone: true, + imports: [ + MatMultiSort, + MatMultiSortHeader + ] }) -class MatMultiSortWithArrowPosition { +class MatMultiSortWithArrowPositionApp { // component with default value of 'arrowPosition' = undefined arrowPosition?: 'before' | 'after'; @ViewChild(MatMultiSort) matMultiSort!: MatMultiSort; @@ -1054,17 +1085,22 @@ class MatMultiSortWithArrowPosition { @Component({ template: ` -
-
- A -
-
- B -
-
- ` +
+
+ A +
+
+ B +
+
+ `, + standalone: true, + imports: [ + MatMultiSort, + MatMultiSortHeader + ] }) -class MatSortWithoutInputs { +class MatSortWithoutInputsApp { @ViewChild(MatMultiSort) matMultiSort!: MatMultiSort; @ViewChild('defaultA') defaultA!: MatMultiSortHeader; @ViewChild('defaultB') defaultB!: MatMultiSortHeader; diff --git a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.directive.ts b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.directive.ts index c99040b..ba2ed94 100644 --- a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.directive.ts +++ b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.directive.ts @@ -27,11 +27,12 @@ import { // Container for MatSortables to manage the sort state and provide default sort parameters. @Directive({ - selector: '[matMultiSort]', - exportAs: 'matMultiSort', - host: { - 'class': 'mat-multi-sort' - } + selector: '[matMultiSort]', + exportAs: 'matMultiSort', + host: { + 'class': 'mat-multi-sort' + }, + standalone: true }) export class MatMultiSort extends MatSort { // The currently active sort definition. diff --git a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.module.ts b/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.module.ts deleted file mode 100644 index 32455bf..0000000 --- a/projects/mat-datatable-lib/src/directives/datatable-sort/mat-multi-sort.module.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { CommonModule } from '@angular/common'; -import { NgModule } from '@angular/core'; -import { MatSortModule } from '@angular/material/sort'; - -import { MatMultiSortBadgeDirective } from './mat-multi-sort-badge.directive'; -import { MatMultiSortHeader } from './mat-multi-sort-header.component'; -import { MatMultiSort } from './mat-multi-sort.directive'; - -@NgModule({ - imports: [ - CommonModule, - MatSortModule - ], - exports: [ - MatMultiSortHeader, - MatMultiSort - ], - declarations: [ - MatMultiSortHeader, - MatMultiSortBadgeDirective, - MatMultiSort - ] -}) -export class MatMultiSortModule { -} diff --git a/projects/mat-datatable-lib/src/directives/datatable-sort/public-api.ts b/projects/mat-datatable-lib/src/directives/datatable-sort/public-api.ts index 7c375e9..caf2212 100644 --- a/projects/mat-datatable-lib/src/directives/datatable-sort/public-api.ts +++ b/projects/mat-datatable-lib/src/directives/datatable-sort/public-api.ts @@ -17,4 +17,4 @@ export * from './mat-multi-sort.directive'; export * from './mat-multi-sort-header.component'; // MatMultiSortModule -export * from './mat-multi-sort.module'; + diff --git a/projects/mat-datatable-lib/src/directives/virtual-scroll/table-item-size.directive.ts b/projects/mat-datatable-lib/src/directives/virtual-scroll/table-item-size.directive.ts index e8f271f..de94fcc 100644 --- a/projects/mat-datatable-lib/src/directives/virtual-scroll/table-item-size.directive.ts +++ b/projects/mat-datatable-lib/src/directives/virtual-scroll/table-item-size.directive.ts @@ -77,13 +77,14 @@ const defaults = { }; @Directive({ - // eslint-disable-next-line @angular-eslint/directive-selector - selector: 'cdk-virtual-scroll-viewport[tvsItemSize]', - exportAs: 'table-virtual-scroll', - providers: [{ - provide: VIRTUAL_SCROLL_STRATEGY, - useFactory: () => new FixedSizeTableVirtualScrollStrategy() - }] + // eslint-disable-next-line @angular-eslint/directive-selector + selector: 'cdk-virtual-scroll-viewport[tvsItemSize]', + exportAs: 'table-virtual-scroll', + standalone: true, + providers: [{ + provide: VIRTUAL_SCROLL_STRATEGY, + useFactory: () => new FixedSizeTableVirtualScrollStrategy() + }] }) export class TableItemSizeDirective implements OnChanges, AfterContentInit, OnDestroy { @HostListener('window:keyup', ['$event']) diff --git a/projects/mat-datatable-lib/src/lib/mat-datatable.component.spec.ts b/projects/mat-datatable-lib/src/lib/mat-datatable.component.spec.ts index a3d3c85..89f325e 100644 --- a/projects/mat-datatable-lib/src/lib/mat-datatable.component.spec.ts +++ b/projects/mat-datatable-lib/src/lib/mat-datatable.component.spec.ts @@ -2,7 +2,7 @@ import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { Component, TrackByFunction, ViewChild } from '@angular/core'; import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { provideNoopAnimations } from '@angular/platform-browser/animations'; import { BehaviorSubject, first, Observable, of } from 'rxjs'; import { MatDatatableHarness, MatHeaderRowHarness, MatFooterRowHarness, MatMultiSortHarness } from '../../testing/src'; @@ -11,7 +11,6 @@ import { MatColumnDefinition } from '../interfaces/datatable-column-definition.i import { MatSortDefinition } from '../interfaces/datatable-sort-definition.interface'; import { MatDatatableComponent, RowSelectionType } from './mat-datatable.component'; -import { MatDatatableModule } from './mat-datatable.module'; import SINGLE_PAGE_DATA from './mocking-data/mock-data.simple'; describe('MatDatatableComponent', () => { @@ -31,15 +30,13 @@ describe('MatDatatableComponent', () => { beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatDatatableModule, - NoopAnimationsModule + DatatableEmptyTestComponent, + DatatableTestComponent ], - declarations: [ - DatatableTestComponent, - DatatableEmptyTestComponent + providers: [ + provideNoopAnimations() ] - }) - .compileComponents(); + }).compileComponents(); })); beforeEach(() => { @@ -118,15 +115,13 @@ describe('MatDatatableComponent', () => { beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatDatatableModule, - NoopAnimationsModule + DatatableEmptyTestComponent, + DatatableTestComponent ], - declarations: [ - DatatableTestComponent, - DatatableEmptyTestComponent + providers: [ + provideNoopAnimations() ] - }) - .compileComponents(); + }).compileComponents(); })); beforeEach(() => { @@ -367,15 +362,13 @@ describe('MatDatatableComponent', () => { beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatDatatableModule, - NoopAnimationsModule + DatatableEmptyTestComponent, + DatatableTestComponent ], - declarations: [ - DatatableTestComponent, - DatatableEmptyTestComponent + providers: [ + provideNoopAnimations() ] - }) - .compileComponents(); + }).compileComponents(); })); beforeEach(() => { @@ -422,15 +415,13 @@ describe('MatDatatableComponent', () => { beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatDatatableModule, - NoopAnimationsModule + DatatableEmptyTestComponent, + DatatableTestComponent ], - declarations: [ - DatatableTestComponent, - DatatableEmptyTestComponent + providers: [ + provideNoopAnimations() ] - }) - .compileComponents(); + }).compileComponents(); })); beforeEach(() => { @@ -457,15 +448,13 @@ describe('MatDatatableComponent', () => { beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatDatatableModule, - NoopAnimationsModule + DatatableEmptyTestComponent, + DatatableTestComponent ], - declarations: [ - DatatableTestComponent, - DatatableEmptyTestComponent + providers: [ + provideNoopAnimations() ] - }) - .compileComponents(); + }).compileComponents(); })); beforeEach(() => { @@ -595,15 +584,13 @@ describe('MatDatatableComponent', () => { beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatDatatableModule, - NoopAnimationsModule + DatatableEmptyTestComponent, + DatatableTestComponent ], - declarations: [ - DatatableTestComponent, - DatatableEmptyTestComponent + providers: [ + provideNoopAnimations() ] - }) - .compileComponents(); + }).compileComponents(); })); beforeEach(() => { @@ -636,15 +623,13 @@ describe('MatDatatableComponent', () => { beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatDatatableModule, - NoopAnimationsModule + DatatableEmptyTestComponent, + DatatableTestComponent ], - declarations: [ - DatatableTestComponent, - DatatableEmptyTestComponent + providers: [ + provideNoopAnimations() ] - }) - .compileComponents(); + }).compileComponents(); })); beforeEach(() => { @@ -688,14 +673,12 @@ describe('MatDatatableComponent', () => { beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatDatatableModule, - NoopAnimationsModule - ], - declarations: [ DatatableDoubleTestComponent + ], + providers: [ + provideNoopAnimations() ] - }) - .compileComponents(); + }).compileComponents(); })); beforeEach(() => { @@ -742,15 +725,13 @@ describe('MatDatatableComponent', () => { beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ imports: [ - MatDatatableModule, - NoopAnimationsModule + DatatableEmptyTestComponent, + DatatableTestComponent ], - declarations: [ - DatatableTestComponent, - DatatableEmptyTestComponent + providers: [ + provideNoopAnimations() ] - }) - .compileComponents(); + }).compileComponents(); })); beforeEach(() => { @@ -1007,23 +988,27 @@ const datatableTestData: DatatableTestRow[] = SINGLE_PAGE_DATA; @Component({ template: ` -
- - No data to display. - -
+
+ + No data to display. + +
`, - styles: ['.content-table { height: 400px; }'] + styles: ['.content-table { height: 400px; }'], + standalone: true, + imports: [ + MatDatatableComponent + ] }) class DatatableTestComponent { @ViewChild('testTable') matDataTable!: MatDatatableComponent; @@ -1081,22 +1066,26 @@ class DatatableTestComponent { @Component({ template: ` -
- - No data to display. - -
+
+ + No data to display. + +
`, - styles: ['.content-table { height: 400px; }'] + styles: ['.content-table { height: 400px; }'], + standalone: true, + imports: [ + MatDatatableComponent + ] }) class DatatableEmptyTestComponent { dataStore = new StaticTableDataStore([] as DatatableTestRow[], this.trackBy); @@ -1123,30 +1112,34 @@ class DatatableEmptyTestComponent { @Component({ template: ` -
- - No data to display. - - - No data to display. - -
+
+ + No data to display. + + + No data to display. + +
`, - styles: ['.content-table { height: 400px; }'] + styles: ['.content-table { height: 400px; }'], + standalone: true, + imports: [ + MatDatatableComponent + ] }) class DatatableDoubleTestComponent { @ViewChild('testTable1') matDataTable1!: MatDatatableComponent; diff --git a/projects/mat-datatable-lib/src/lib/mat-datatable.component.ts b/projects/mat-datatable-lib/src/lib/mat-datatable.component.ts index 228638c..281193a 100644 --- a/projects/mat-datatable-lib/src/lib/mat-datatable.component.ts +++ b/projects/mat-datatable-lib/src/lib/mat-datatable.component.ts @@ -1,4 +1,5 @@ import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling'; +import { NgClass, NgFor, NgStyle, NgIf, AsyncPipe } from '@angular/common'; import { AfterViewInit, Component, @@ -12,15 +13,34 @@ import { TrackByFunction, ViewChild } from '@angular/core'; -import { MatTable } from '@angular/material/table'; +import { MatProgressBar } from '@angular/material/progress-bar'; +import { + MatColumnDef, + MatCell, + MatCellDef, + MatFooterCell, + MatFooterCellDef, + MatFooterRow, + MatFooterRowDef, + MatHeaderCell, + MatHeaderCellDef, + MatHeaderRow, + MatHeaderRowDef, + MatRow, + MatRowDef, + MatTable +} from '@angular/material/table'; import { Observable, Subject, takeUntil } from 'rxjs'; import { EmptyDataStoreProvider, TableVirtualScrollDataSource } from '../components/data-source.class'; +import { MatDatatableHeaderAlignDirective } from '../directives/datatable-header-align.directive'; +import { MatDatatableResizableDirective } from '../directives/datatable-resizable.directive'; import { MatMultiSort, Sort, SortHeaderArrowPosition } from '../directives/datatable-sort'; +import { MatMultiSortHeader } from '../directives/datatable-sort/mat-multi-sort-header.component'; import { TableItemSizeDirective } from '../directives/virtual-scroll/table-item-size.directive'; import { FieldSortDefinition, FieldFilterDefinition, DataStoreProvider } from '../interfaces/datastore-provider.interface'; import { ColumnAlignmentType, MatColumnDefinition } from '../interfaces/datatable-column-definition.interface'; @@ -35,12 +55,41 @@ export type RowSelectionType = 'none' | 'single' | 'multi'; * @template TRowData - type / interface definition for data of a single row */ @Component({ - selector: 'mat-datatable', - templateUrl: './mat-datatable.component.html', - styleUrls: [ - './mat-datatable.component.scss', - '../directives/datatable-resizable.directive.scss' - ] + selector: 'mat-datatable', + templateUrl: './mat-datatable.component.html', + styleUrls: [ + './mat-datatable.component.scss', + '../directives/datatable-resizable.directive.scss' + ], + standalone: true, + imports: [ + AsyncPipe, + CdkVirtualScrollViewport, + MatCell, + MatCellDef, + MatColumnDef, + MatDatatableHeaderAlignDirective, + MatDatatableResizableDirective, + MatFooterCell, + MatFooterCellDef, + MatFooterRow, + MatFooterRowDef, + MatHeaderCell, + MatHeaderCellDef, + MatHeaderRow, + MatHeaderRowDef, + MatMultiSort, + MatMultiSortHeader, + MatProgressBar, + MatRow, + MatRowDef, + MatTable, + NgClass, + NgFor, + NgIf, + NgStyle, + TableItemSizeDirective + ] }) export class MatDatatableComponent implements AfterViewInit, OnChanges, OnDestroy, OnInit { @Input() columnDefinitions: MatColumnDefinition[] = []; diff --git a/projects/mat-datatable-lib/src/lib/mat-datatable.module.ts b/projects/mat-datatable-lib/src/lib/mat-datatable.module.ts deleted file mode 100644 index 2d8726a..0000000 --- a/projects/mat-datatable-lib/src/lib/mat-datatable.module.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { ScrollingModule } from '@angular/cdk/scrolling'; -import { NgModule } from '@angular/core'; -import { MatProgressBarModule } from '@angular/material/progress-bar'; -import { MatTableModule } from '@angular/material/table'; -import { BrowserModule } from '@angular/platform-browser'; - -import { MatDatatableHeaderAlignDirective } from '../directives/datatable-header-align.directive'; -import { MatDatatableResizableDirective } from '../directives/datatable-resizable.directive'; -import { MatMultiSortModule } from '../directives/datatable-sort'; -import { TableItemSizeDirective } from '../directives/virtual-scroll/table-item-size.directive'; - -import { MatDatatableComponent } from './mat-datatable.component'; - -@NgModule({ - declarations: [ - MatDatatableComponent, - MatDatatableHeaderAlignDirective, - MatDatatableResizableDirective, - TableItemSizeDirective - ], - imports: [ - BrowserModule, - MatProgressBarModule, - MatTableModule, - MatMultiSortModule, - ScrollingModule - ], - exports: [ - MatDatatableComponent - ] -}) -export class MatDatatableModule { } diff --git a/projects/mat-datatable-lib/src/public-api.ts b/projects/mat-datatable-lib/src/public-api.ts index 34ef9ea..729ea52 100644 --- a/projects/mat-datatable-lib/src/public-api.ts +++ b/projects/mat-datatable-lib/src/public-api.ts @@ -5,15 +5,7 @@ // MatDatatableComponent export * from './lib/mat-datatable.component'; -// MatDatatableModule -export * from './lib/mat-datatable.module'; - -export { - MatMultiSort, - MatMultiSortHeader, - MatMultiSortModule, - SortDirectionAscDesc -} from './directives/datatable-sort'; +export { MatMultiSort, MatMultiSortHeader, SortDirectionAscDesc } from './directives/datatable-sort'; export { Sort } from '@angular/material/sort'; diff --git a/projects/mat-datatable-lib/testing/src/mat-datatable-row-harness.ts b/projects/mat-datatable-lib/testing/src/mat-datatable-row-harness.ts index 8ff932b..d191048 100644 --- a/projects/mat-datatable-lib/testing/src/mat-datatable-row-harness.ts +++ b/projects/mat-datatable-lib/testing/src/mat-datatable-row-harness.ts @@ -7,9 +7,9 @@ import { import { _MatCellHarnessBase, - MatRowCellHarness, + MatFooterCellHarness, MatHeaderCellHarness, - MatFooterCellHarness + MatRowCellHarness } from './mat-datatable-cell-harness'; import { CellHarnessFilters, diff --git a/projects/mat-datatable-lib/testing/src/mat-datatable-table-harness.ts b/projects/mat-datatable-lib/testing/src/mat-datatable-table-harness.ts index c162954..4703328 100644 --- a/projects/mat-datatable-lib/testing/src/mat-datatable-table-harness.ts +++ b/projects/mat-datatable-lib/testing/src/mat-datatable-table-harness.ts @@ -6,8 +6,8 @@ import { } from '@angular/cdk/testing'; import { - RowHarnessFilters, - MatDatatableHarnessFilters + MatDatatableHarnessFilters, + RowHarnessFilters } from './mat-datatable-harness-filters'; import { MatFooterRowHarness,