Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/issue 379 #380

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,332 changes: 3,676 additions & 3,656 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
},
"private": true,
"dependencies": {
"@angular/animations": "^14.2.0",
"@angular/common": "^14.2.0",
"@angular/compiler": "^14.2.0",
"@angular/core": "^14.2.0",
"@angular/forms": "^14.2.0",
"@angular/platform-browser": "^14.2.0",
"@angular/platform-browser-dynamic": "^14.2.0",
"@angular/router": "^14.2.0",
"@angular/animations": "^16.2.10",
"@angular/common": "^16.2.10",
"@angular/compiler": "^16.2.10",
"@angular/core": "^16.2.10",
"@angular/forms": "^16.2.10",
"@angular/platform-browser": "^16.2.10",
"@angular/platform-browser-dynamic": "^16.2.10",
"@angular/router": "^16.2.10",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
"zone.js": "~0.13.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "^14.2.12",
"@angular-devkit/build-angular": "^16.2.7",
"@angular-eslint/builder": "^14.2.0",
"@angular-eslint/eslint-plugin": "^14.2.0",
"@angular-eslint/eslint-plugin-template": "^14.2.0",
"@angular-eslint/template-parser": "^14.2.0",
"@angular/cli": "~14.2.12",
"@angular/compiler-cli": "^14.2.0",
"@angular/cli": "~16.2.7",
"@angular/compiler-cli": "^16.2.10",
"@types/jasmine": "~4.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.5",
Expand All @@ -48,14 +48,14 @@
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"ng-packagr": "^14.2.0",
"ng-packagr": "^16.2.3",
"sass": "^1.64.1",
"semantic-release": "^21.0.7",
"typescript": "~4.7.2"
"typescript": "~5.1.6"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
import {
AfterViewInit,
AfterViewChecked,
ChangeDetectorRef,
Component,
ComponentRef,
Expand Down Expand Up @@ -62,7 +62,7 @@
styles: [
]
})
export class NgxSmartModalComponent implements OnInit, OnDestroy, AfterViewInit {
export class NgxSmartModalComponent implements OnInit, OnDestroy, AfterViewChecked {

@Input() public closable = true;
@Input() public escapable = true;
Expand All @@ -81,11 +81,11 @@
@Input() public refocus = true;

@Output() public visibleChange: EventEmitter<boolean> = new EventEmitter<boolean>();
@Output() public onClose: EventEmitter<any> = new EventEmitter();

Check warning on line 84 in projects/ngx-smart-modal/src/lib/components/ngx-smart-modal.component.ts

View workflow job for this annotation

GitHub Actions / build

Output bindings, including aliases, should not be named "on", nor prefixed with it (https://angular.io/guide/styleguide#style-05-16)

Check warning on line 84 in projects/ngx-smart-modal/src/lib/components/ngx-smart-modal.component.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
@Output() public onCloseFinished: EventEmitter<any> = new EventEmitter();

Check warning on line 85 in projects/ngx-smart-modal/src/lib/components/ngx-smart-modal.component.ts

View workflow job for this annotation

GitHub Actions / build

Output bindings, including aliases, should not be named "on", nor prefixed with it (https://angular.io/guide/styleguide#style-05-16)

Check warning on line 85 in projects/ngx-smart-modal/src/lib/components/ngx-smart-modal.component.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
@Output() public onDismiss: EventEmitter<any> = new EventEmitter();

Check warning on line 86 in projects/ngx-smart-modal/src/lib/components/ngx-smart-modal.component.ts

View workflow job for this annotation

GitHub Actions / build

Output bindings, including aliases, should not be named "on", nor prefixed with it (https://angular.io/guide/styleguide#style-05-16)

Check warning on line 86 in projects/ngx-smart-modal/src/lib/components/ngx-smart-modal.component.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
@Output() public onDismissFinished: EventEmitter<any> = new EventEmitter();

Check warning on line 87 in projects/ngx-smart-modal/src/lib/components/ngx-smart-modal.component.ts

View workflow job for this annotation

GitHub Actions / build

Output bindings, including aliases, should not be named "on", nor prefixed with it (https://angular.io/guide/styleguide#style-05-16)

Check warning on line 87 in projects/ngx-smart-modal/src/lib/components/ngx-smart-modal.component.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
@Output() public onAnyCloseEvent: EventEmitter<any> = new EventEmitter();

Check warning on line 88 in projects/ngx-smart-modal/src/lib/components/ngx-smart-modal.component.ts

View workflow job for this annotation

GitHub Actions / build

Output bindings, including aliases, should not be named "on", nor prefixed with it (https://angular.io/guide/styleguide#style-05-16)

Check warning on line 88 in projects/ngx-smart-modal/src/lib/components/ngx-smart-modal.component.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
@Output() public onAnyCloseEventFinished: EventEmitter<any> = new EventEmitter();
@Output() public onOpen: EventEmitter<any> = new EventEmitter();
@Output() public onOpenFinished: EventEmitter<any> = new EventEmitter();
Expand Down Expand Up @@ -125,10 +125,14 @@
this._sendEvent('create');
}

public ngAfterViewInit() {
if (this.contentComponent) {
const componentRef = this._viewContainerRef.createComponent(this.contentComponent);
this.createDynamicContent(this.dynamicContentContainer, componentRef);
public ngAfterViewChecked() {
if (
this.overlayVisible &&
this.contentComponent &&
this.dynamicContentContainer &&
this.dynamicContentContainer.length === 0
) {
this.createDynamicContent();
}
}

Expand Down Expand Up @@ -367,9 +371,10 @@
/**
* Creates content inside provided ViewContainerRef
*/
private createDynamicContent(viewContainerRef: ViewContainerRef, componentRef: ComponentRef<Component>): void {
viewContainerRef.clear();
this.assignModalDataToComponentData(componentRef);
private createDynamicContent(): void {
this.dynamicContentContainer.clear();
this._componentRef = this.dynamicContentContainer.createComponent(this.contentComponent);
this.assignModalDataToComponentData(this._componentRef);
this.markForCheck();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ export class NgxSmartModalService {
if (typeof options.ariaDescribedBy === 'string') { componentRef.instance.ariaDescribedBy = options.ariaDescribedBy; }
if (typeof options.refocus === 'boolean') { componentRef.instance.refocus = options.refocus; }

this._appRef.attachView(componentRef.hostView);

const domElem = (componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;
this._document.body.appendChild(domElem);

Expand Down
12 changes: 0 additions & 12 deletions projects/ngx-smart-modal/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,8 @@ import {
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
<T>(id: string): T;
keys(): string[];
};
};

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting(),
);

// Then we find all the tests.
const context = require.context('./tests', true, /\.spec\.ts$/);
// And load the modules.
context.keys().forEach(context);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed, waitForAsync, ComponentFixture } from '@angular/core/testing';
import { NgxSmartModalComponent, NgxSmartModalService } from '../../public-api';
import { NgxSmartModalComponent, NgxSmartModalConfig, NgxSmartModalService } from '../../public-api';

describe('NgxSmartModalComponent', () => {
let component: NgxSmartModalComponent;
Expand Down Expand Up @@ -174,10 +174,19 @@ describe('NgxSmartModalComponent', () => {

it('should add body class', waitForAsync(() => {
component.addBodyClass();

const body = document.body;

expect(body.classList.contains(NgxSmartModalConfig.bodyClassOpen)).toBeTrue();
}));

it('should remove body class', waitForAsync(() => {
const body = document.body;
body.classList.add(NgxSmartModalConfig.bodyClassOpen);

component.removeBodyClass();

expect(body.classList.contains(NgxSmartModalConfig.bodyClassOpen)).toBeFalse();
}));

it('should targetPlacement if no target', waitForAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { NgxSmartModalStackService } from '../../lib/services/ngx-smart-modal-st

@Component({
selector: 'ngx-smart-modal-test-fake',
template: 'test fake component<ng-template #tpl></ng-template>'
template: 'test fake component<ng-template #tpl><div>test fake tpl content div</div>test fake tpl content</ng-template>'
})
export class FakeComponent {
@ViewChild(TemplateRef) public tpl: TemplateRef<any> = {} as any;

constructor(public viewRef: ViewContainerRef) {}
}

describe('NgxSmartModalService', () => {
Expand All @@ -30,19 +32,13 @@ describe('NgxSmartModalService', () => {
NgxSmartModalService,
NgxSmartModalStackService
],
}).overrideModule(BrowserDynamicTestingModule, {
set: {
entryComponents: [
NgxSmartModalComponent,
FakeComponent
],
}
});
}).compileComponents();
}));

beforeEach(() => {
const fixture = TestBed.createComponent(FakeComponent);
fakeComponent = fixture.componentInstance;
fixture.detectChanges();
});

it('should add events (_private)', inject([NgxSmartModalService], (service: NgxSmartModalService) => {
Expand Down Expand Up @@ -352,14 +348,19 @@ describe('NgxSmartModalService', () => {
ariaDescribedBy: 'test',
};

const fixture = TestBed.createComponent(NgxSmartModalComponent);
const vcr = {
createComponent: () => fixture.componentRef
} as any;
const fixture = TestBed.createComponent(FakeComponent);
fixture.detectChanges();
const vcr = fixture.componentInstance.viewRef;

service.create('test', 'test content', vcr, options);

service.create('test2', 'test content', vcr);

const tmp = document.querySelectorAll('body > ngx-smart-modal:nth-last-child(-n + 2)');

expect(tmp).toBeInstanceOf(NodeList);
expect(tmp.length).toBe(2);

}));

it('should destroy modal', inject([NgxSmartModalService, NgxSmartModalStackService], (service: NgxSmartModalService, stackService: NgxSmartModalStackService) => {
Expand Down Expand Up @@ -442,9 +443,21 @@ describe('NgxSmartModalService', () => {
})));

it('should resolve content', inject([NgxSmartModalService], (service: NgxSmartModalService) => {
(service as any)._resolveNgContent('test content');
(service as any)._resolveNgContent(FakeComponent);
(service as any)._resolveNgContent(fakeComponent.tpl);
const strRes = (service as any)._resolveNgContent('test content');
const compRes = (service as any)._resolveNgContent(FakeComponent);
const tplRes = (service as any)._resolveNgContent(fakeComponent.tpl);

expect(strRes).toHaveSize(1);
expect(strRes[0]).toHaveSize(1);
expect(strRes[0][0]).toBeInstanceOf(Node);
expect(strRes[0][0].nodeType).toBe(Node.TEXT_NODE);

expect(tplRes).toHaveSize(1);
expect(tplRes[0]).toHaveSize(2);
expect(tplRes[0][0].nodeType).toEqual(Node.ELEMENT_NODE);
expect(tplRes[0][1].nodeType).toEqual(Node.TEXT_NODE);

expect(compRes).toHaveSize(0);
}));

it('should escape keyboard event', fakeAsync(inject([NgxSmartModalService], (service: NgxSmartModalService) => {
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2020",
"target": "ES2022",
"module": "es2020",
"lib": [
"es2020",
"dom"
]
],
"useDefineForClassFields": false
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
Expand Down