diff --git a/package.json b/package.json index 046d30b..90c9d3b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deneb-ui", - "version": "4.1.1", + "version": "4.1.2", "scripts": { "ng": "ng", "start": "ng serve --project Deneb-UI-Demo", diff --git a/projects/irohalab/deneb-ui/package.json b/projects/irohalab/deneb-ui/package.json index db3f7df..a53b3ff 100644 --- a/projects/irohalab/deneb-ui/package.json +++ b/projects/irohalab/deneb-ui/package.json @@ -1,6 +1,6 @@ { "name": "@irohalab/deneb-ui", - "version": "4.1.1", + "version": "4.1.2", "description": "Building blocks for mira-ui", "author": "Everett Summer", "license": "Apache-2.0", diff --git a/projects/irohalab/deneb-ui/src/dialog/dialog.ts b/projects/irohalab/deneb-ui/src/dialog/dialog.ts index cbb1691..e2777d7 100644 --- a/projects/irohalab/deneb-ui/src/dialog/dialog.ts +++ b/projects/irohalab/deneb-ui/src/dialog/dialog.ts @@ -28,7 +28,9 @@ export class UIDialog { const environmentInjector = this._appRef.injector; container = createComponent(UIDialogContainer, {environmentInjector}); this._appRef.attachView(container.hostView); - document.body.appendChild(this.getComponentRootNode(container)); + if (document) { + document.body.appendChild(this.getComponentRootNode(container)); + } } container.instance.dialogConfig = config; container.instance.insideParent = !!viewContainer; diff --git a/projects/irohalab/deneb-ui/src/dropdown/dropdown.ts b/projects/irohalab/deneb-ui/src/dropdown/dropdown.ts index 786f222..6cd026e 100644 --- a/projects/irohalab/deneb-ui/src/dropdown/dropdown.ts +++ b/projects/irohalab/deneb-ui/src/dropdown/dropdown.ts @@ -1,8 +1,9 @@ -import {fromEvent as observableFromEvent, Observable, Subscription } from 'rxjs'; +import {fromEvent as observableFromEvent, Subscription } from 'rxjs'; import {takeUntil, delay, takeWhile, mergeMap, tap} from 'rxjs/operators'; -import { Directive, ElementRef, HostListener, Input, OnDestroy, OnInit } from '@angular/core'; +import { Directive, ElementRef, HostListener, Inject, Input, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core'; +import { isPlatformServer } from '@angular/common'; @Directive({ selector: '[uiDropdown]', @@ -44,7 +45,8 @@ export class UIDropdown implements OnInit, OnDestroy { return this._menuOpen; } - constructor(private _element: ElementRef) { + constructor(private _element: ElementRef, + @Inject(PLATFORM_ID) private platformId: object) { } @HostListener('click', ['$event']) @@ -58,6 +60,9 @@ export class UIDropdown implements OnInit, OnDestroy { } ngOnInit(): void { + if (isPlatformServer(this.platformId)) { + return; + } let _el = this._element.nativeElement; this._subscription.add( observableFromEvent(document.body, 'click') diff --git a/projects/irohalab/deneb-ui/src/toast/toast.ts b/projects/irohalab/deneb-ui/src/toast/toast.ts index 7a782dc..d35f3ca 100644 --- a/projects/irohalab/deneb-ui/src/toast/toast.ts +++ b/projects/irohalab/deneb-ui/src/toast/toast.ts @@ -1,13 +1,14 @@ import { Injectable, Injector, ApplicationRef, Type, ComponentRef, EmbeddedViewRef, - createComponent + createComponent, Inject, PLATFORM_ID } from '@angular/core'; import {UIToastRef} from './toast-ref'; import {UIToastComponent} from './toast.component'; import {ToastInjector} from './toast-injector'; import {Subscription} from 'rxjs'; import {UIToastAnimation} from './toast-interface'; +import { isPlatformServer } from '@angular/common'; @Injectable() export class UIToast { @@ -22,7 +23,8 @@ export class UIToast { private timerId: any; constructor(private _injector: Injector, - private _appRef: ApplicationRef) { + private _appRef: ApplicationRef, + @Inject(PLATFORM_ID) private platformId: object) { } make(componentType?: Type): UIToastRef { @@ -39,6 +41,9 @@ export class UIToast { } activeToast(component: ComponentRef, duration: number) { + if (isPlatformServer(this.platformId)) { + return; + } if (this._pendingToast) { this._pendingToast = component; this._pendingToastDuration = duration; @@ -60,13 +65,15 @@ export class UIToast { this._appRef.attachView(this._currentActiveToast.hostView); document.body.appendChild(this._getComponentRootNode(this._currentActiveToast)); - this.timerId = setTimeout(() => { this.deactiveToast(); }, duration); } deactiveToast() { + if (isPlatformServer(this.platformId)) { + return; + } clearTimeout(this.timerId); if (this._currentActiveToast) { if (this._currentActiveToast.instance['animationEvent'] && this._currentActiveToast.instance['uiLeaveAnimationDone']) {