Skip to content

Commit

Permalink
Revert "feat: Add provider function, convert to standalone and use in…
Browse files Browse the repository at this point in the history
…ject (scttcper#991)"

This reverts commit 94dba28.
  • Loading branch information
Xavier Asensio committed Nov 22, 2023
1 parent 55d3e46 commit 51f5d37
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 75 deletions.
7 changes: 3 additions & 4 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { GhButtonModule } from '@ctrl/ngx-github-buttons';

import { ToastNoAnimationModule, ToastContainerDirective } from '../lib/public_api';
import { ToastrModule, ToastContainerModule, ToastNoAnimationModule } from '../lib/public_api';

import { AppComponent } from './app.component';
import { FooterComponent } from './footer/footer.component';
Expand All @@ -14,7 +14,6 @@ import { HomeComponent } from './home/home.component';
import { NotyfToast } from './notyf.toast';
import { PinkToast } from './pink.toast';
import { BootstrapToast } from './bootstrap.toast';
import { provideToastr } from '../lib/toastr/toast.provider';

@NgModule({
declarations: [
Expand All @@ -31,10 +30,10 @@ import { provideToastr } from '../lib/toastr/toast.provider';
FormsModule,
BrowserAnimationsModule,
ToastNoAnimationModule,
ToastContainerDirective,
ToastrModule.forRoot(),
ToastContainerModule,
GhButtonModule,
],
providers: [provideToastr()],
bootstrap: [AppComponent],
})
export class AppModule {}
5 changes: 3 additions & 2 deletions src/lib/overlay/overlay-container.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { DOCUMENT } from '@angular/common';
import { inject, Injectable, OnDestroy } from '@angular/core';
import { Inject, Injectable, OnDestroy } from '@angular/core';

/** Container inside which all toasts will render. */
@Injectable({ providedIn: 'root' })
export class OverlayContainer implements OnDestroy {
protected _document = inject(DOCUMENT);
protected _containerElement!: HTMLElement;

constructor(@Inject(DOCUMENT) protected _document: any) {}

ngOnDestroy() {
if (this._containerElement && this._containerElement.parentNode) {
this._containerElement.parentNode.removeChild(this._containerElement);
Expand Down
13 changes: 7 additions & 6 deletions src/lib/overlay/overlay.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { DOCUMENT } from '@angular/common';
import { ApplicationRef, ComponentFactoryResolver, inject, Inject, Injectable } from '@angular/core';
import { ApplicationRef, ComponentFactoryResolver, Inject, Injectable } from '@angular/core';

import { DomPortalHost } from '../portal/dom-portal-host';
import { ToastContainerDirective } from '../toastr/toast.directive';
Expand All @@ -17,14 +17,15 @@ import { OverlayRef } from './overlay-ref';
*/
@Injectable({ providedIn: 'root' })
export class Overlay {
private _overlayContainer = inject(OverlayContainer);
private _componentFactoryResolver = inject(ComponentFactoryResolver);
private _appRef = inject(ApplicationRef);
private _document = inject(DOCUMENT);

// Namespace panes by overlay container
private _paneElements: Map<ToastContainerDirective, Record<string, HTMLElement>> = new Map();

constructor(
private _overlayContainer: OverlayContainer,
private _componentFactoryResolver: ComponentFactoryResolver,
private _appRef: ApplicationRef,
@Inject(DOCUMENT) private _document: any,
) {}
/**
* Creates an overlay.
* @returns A reference to the created overlay.
Expand Down
1 change: 0 additions & 1 deletion src/lib/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from './toastr/toast.component';
export * from './toastr/toastr.service';
export * from './toastr/toastr-config';
export * from './toastr/toastr.module';
export * from './toastr/toast.provider';
export * from './toastr/toast-ref';
export * from './toastr/toast-noanimation.component';

Expand Down
7 changes: 3 additions & 4 deletions src/lib/toastr/toast-noanimation.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NgIf } from '@angular/common';
import { CommonModule } from '@angular/common';
import { ModuleWithProviders } from '@angular/core';
import {
ApplicationRef,
Expand Down Expand Up @@ -40,8 +40,6 @@ import { ToastrService } from './toastr.service';
<div class="toast-progress" [style.width]="width + '%'"></div>
</div>
`,
standalone: true,
imports: [NgIf]
})
export class ToastNoAnimation implements OnDestroy {
message?: string | null;
Expand Down Expand Up @@ -222,7 +220,8 @@ export const DefaultNoAnimationsGlobalConfig: GlobalConfig = {
};

@NgModule({
imports: [ToastNoAnimation],
imports: [CommonModule],
declarations: [ToastNoAnimation],
exports: [ToastNoAnimation],
})
export class ToastNoAnimationModule {
Expand Down
17 changes: 7 additions & 10 deletions src/lib/toastr/toast.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import {
HostBinding,
HostListener,
NgZone,
OnDestroy,
OnDestroy
} from '@angular/core';
import { NgIf } from '@angular/common';
import { Subscription } from 'rxjs';
import { IndividualConfig, ToastPackage } from './toastr-config';
import { ToastrService } from './toastr.service';
Expand Down Expand Up @@ -44,17 +43,15 @@ import { ToastrService } from './toastr.service';
state('removed', style({ opacity: 0 })),
transition(
'inactive => active',
animate('{{ easeTime }}ms {{ easing }}'),
animate('{{ easeTime }}ms {{ easing }}')
),
transition(
'active => removed',
animate('{{ easeTime }}ms {{ easing }}'),
),
]),
animate('{{ easeTime }}ms {{ easing }}')
)
])
],
preserveWhitespaces: false,
standalone: true,
imports: [ NgIf ],
preserveWhitespaces: false
})
export class Toast<ConfigPayload = any> implements OnDestroy {
message?: string | null;
Expand Down Expand Up @@ -209,7 +206,7 @@ export class Toast<ConfigPayload = any> implements OnDestroy {
clearTimeout(this.timeout);
this.options.timeOut = 0;
this.hideTime = 0;

// disable progressBar
clearInterval(this.intervalId);
this.width = 0;
Expand Down
13 changes: 11 additions & 2 deletions src/lib/toastr/toast.directive.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { Directive, ElementRef } from '@angular/core';
import {
Directive,
ElementRef,
NgModule,
} from '@angular/core';

@Directive({
selector: '[toastContainer]',
exportAs: 'toastContainer',
standalone: true
})
export class ToastContainerDirective {
constructor(private el: ElementRef) { }
getContainerElement(): HTMLElement {
return this.el.nativeElement;
}
}

@NgModule({
declarations: [ToastContainerDirective],
exports: [ToastContainerDirective],
})
export class ToastContainerModule {}
42 changes: 0 additions & 42 deletions src/lib/toastr/toast.provider.ts

This file was deleted.

24 changes: 20 additions & 4 deletions src/lib/toastr/toastr.module.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import { CommonModule } from '@angular/common';
import { ModuleWithProviders, NgModule } from '@angular/core';

import { Toast } from './toast.component';
import { DefaultNoComponentGlobalConfig, GlobalConfig, TOAST_CONFIG } from './toastr-config';
import { provideToastr } from './toast.provider';

export const DefaultGlobalConfig: GlobalConfig = {
...DefaultNoComponentGlobalConfig,
toastComponent: Toast,
};

@NgModule({
imports: [Toast],
imports: [CommonModule],
declarations: [Toast],
exports: [Toast],
})
export class ToastrModule {
static forRoot(config: Partial<GlobalConfig> = {}): ModuleWithProviders<ToastrModule> {
return {
ngModule: ToastrModule,
providers: [provideToastr(config)],
providers: [
{
provide: TOAST_CONFIG,
useValue: {
default: DefaultGlobalConfig,
config,
},
},
],
};
}
}

@NgModule({})
@NgModule({
imports: [CommonModule],
})
export class ToastrComponentlessModule {
static forRoot(config: Partial<GlobalConfig> = {}): ModuleWithProviders<ToastrModule> {
return {
Expand Down

0 comments on commit 51f5d37

Please sign in to comment.