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: series of blocking issues #390

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -258,9 +258,9 @@
/**
* Retrieve the data attached to the modal instance
*/
public getData(): unknown {
public getData<T>(): T {
this.assignComponentDataToModalData(this._componentRef);
return this._data;
return this._data as T;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ export class NgxSmartModalStackService {
*
* @returns the opened modal with highest z-index.
*/
public getTopOpenedModal(): NgxSmartModalComponent {
if (!this.getOpenedModals().length) {
throw new Error('No modal is opened');
public getTopOpenedModal(): NgxSmartModalComponent | undefined {
const openedModals = this.getOpenedModals();

if (!openedModals.length) {
return undefined;
}

return this.getOpenedModals()
return openedModals
.map((o: ModalInstance) => o.modal)
.reduce((highest, item) => item.layerPosition > highest.layerPosition ? item : highest, this.getOpenedModals()[0].modal);
.reduce((highest, item) => item.layerPosition > highest.layerPosition ? item : highest, openedModals[0].modal);
}

/**
Expand Down Expand Up @@ -107,13 +109,8 @@ export class NgxSmartModalStackService {
* @param id The modal identifier.
* @returns the removed modal instance.
*/
public removeModal(id: string): undefined | ModalInstance {
public removeModal(id: string): ModalInstance | undefined {
const i: number = this._modalStack.findIndex((o: any) => o.id === id);
if (i < 0) {
return;
}

const modalInstance = this._modalStack.splice(i, 1)[0];
return modalInstance;
return i >= 0 ? this._modalStack.splice(i, 1)[0] : undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class NgxSmartModalService {
private _appRef: ApplicationRef,
private _injector: Injector,
private _modalStack: NgxSmartModalStackService,
private applicationRef: ApplicationRef,
@Inject(DOCUMENT) private _document: any,
@Inject(PLATFORM_ID) private _platformId: any
) {
Expand Down Expand Up @@ -116,7 +115,7 @@ export class NgxSmartModalService {
*
* @returns the opened modal with highest z-index.
*/
public getTopOpenedModal(): NgxSmartModalComponent {
public getTopOpenedModal(): NgxSmartModalComponent | undefined {
return this._modalStack.getTopOpenedModal();
}

Expand Down Expand Up @@ -209,7 +208,7 @@ export class NgxSmartModalService {
* Close the latest opened modal
*/
public closeLatestModal(): void {
this.getTopOpenedModal().close();
this.getTopOpenedModal()?.close();
}

/**
Expand Down Expand Up @@ -426,7 +425,7 @@ export class NgxSmartModalService {

if (content instanceof TemplateRef) {
const viewRef = content.createEmbeddedView(null as any);
this.applicationRef.attachView(viewRef);
this._appRef.attachView(viewRef);
return [viewRef.rootNodes];
}

Expand All @@ -442,7 +441,7 @@ export class NgxSmartModalService {
try {
const modal = this.getTopOpenedModal();

if (!modal.escapable) {
if (!modal?.escapable) {
return false;
}

Expand Down Expand Up @@ -474,7 +473,7 @@ export class NgxSmartModalService {
try {
const modal = this.getTopOpenedModal();

if (!modal.nsmDialog.first.nativeElement.contains(document.activeElement)) {
if (modal && !modal.nsmDialog.first.nativeElement.contains(document.activeElement)) {
event.preventDefault();
event.stopPropagation();
modal.nsmDialog.first.nativeElement.focus();
Expand All @@ -498,6 +497,8 @@ export class NgxSmartModalService {
return;
}

this._document.body.removeChild(modal.elementRef.nativeElement);
if (modal.elementRef.nativeElement && this._document.body.contains(modal.elementRef.nativeElement)) {
this._document.body.removeChild(modal.elementRef.nativeElement);
}
}
}
Loading