UNPKG

8.1 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("ngx-bootstrap/utils"),require("ngx-bootstrap/positioning")):"function"==typeof define&&define.amd?define("ngx-bootstrap/component-loader",["exports","@angular/core","ngx-bootstrap/utils","ngx-bootstrap/positioning"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["ngx-bootstrap"]=e["ngx-bootstrap"]||{},e["ngx-bootstrap"]["component-loader"]={}),e.ng.core,e.utils,e.i1)}(this,(function(e,t,n,i){"use strict";var o=function(){},s=function(e,t,n){this.nodes=e,this.viewRef=t,this.componentRef=n},r=function(){function e(e,n,i,o,s,r,c,h){this._viewContainerRef=e,this._renderer=n,this._elementRef=i,this._injector=o,this._componentFactoryResolver=s,this._ngZone=r,this._applicationRef=c,this._posService=h,this.onBeforeShow=new t.EventEmitter,this.onShown=new t.EventEmitter,this.onBeforeHide=new t.EventEmitter,this.onHidden=new t.EventEmitter,this._providers=[],this._isHiding=!1,this.containerDefaultSelector="body",this._listenOpts={},this._globalListener=Function.prototype}return Object.defineProperty(e.prototype,"isShown",{get:function(){return!this._isHiding&&!!this._componentRef},enumerable:!1,configurable:!0}),e.prototype.attach=function(e){return this._componentFactory=this._componentFactoryResolver.resolveComponentFactory(e),this},e.prototype.to=function(e){return this.container=e||this.container,this},e.prototype.position=function(e){return e?(this.attachment=e.attachment||this.attachment,this._elementRef=e.target||this._elementRef,this):this},e.prototype.provide=function(e){return this._providers.push(e),this},e.prototype.show=function(e){if(void 0===e&&(e={}),this._subscribePositioning(),this._innerComponent=void 0,!this._componentRef){this.onBeforeShow.emit(),this._contentRef=this._getContentRef(e.content,e.context,e.initialState);var n=t.Injector.create({providers:this._providers,parent:this._injector});if(!this._componentFactory)return;if(this._componentRef=this._componentFactory.create(n,this._contentRef.nodes),this._applicationRef.attachView(this._componentRef.hostView),this.instance=this._componentRef.instance,Object.assign(this._componentRef.instance,e),this.container instanceof t.ElementRef&&this.container.nativeElement.appendChild(this._componentRef.location.nativeElement),"string"==typeof this.container&&"undefined"!=typeof document){var i=document.querySelector(this.container)||document.querySelector(this.containerDefaultSelector);if(!i)return;i.appendChild(this._componentRef.location.nativeElement)}!this.container&&this._elementRef&&this._elementRef.nativeElement.parentElement&&this._elementRef.nativeElement.parentElement.appendChild(this._componentRef.location.nativeElement),this._contentRef.componentRef&&(this._innerComponent=this._contentRef.componentRef.instance,this._contentRef.componentRef.changeDetectorRef.markForCheck(),this._contentRef.componentRef.changeDetectorRef.detectChanges()),this._componentRef.changeDetectorRef.markForCheck(),this._componentRef.changeDetectorRef.detectChanges(),this.onShown.emit(e.id?{id:e.id}:this._componentRef.instance)}return this._registerOutsideClick(),this._componentRef},e.prototype.hide=function(e){var t,n,i;if(!this._componentRef)return this;this._posService.deletePositionElement(this._componentRef.location),this.onBeforeHide.emit(this._componentRef.instance);var o=this._componentRef.location.nativeElement;return o.parentNode.removeChild(o),(null===(t=this._contentRef)||void 0===t?void 0:t.componentRef)&&this._contentRef.componentRef.destroy(),this._viewContainerRef&&(null===(n=this._contentRef)||void 0===n?void 0:n.viewRef)&&this._viewContainerRef.remove(this._viewContainerRef.indexOf(this._contentRef.viewRef)),(null===(i=this._contentRef)||void 0===i?void 0:i.viewRef)&&this._contentRef.viewRef.destroy(),this._contentRef=void 0,this._componentRef=void 0,this._removeGlobalListener(),this.onHidden.emit(e?{id:e}:null),this},e.prototype.toggle=function(){this.isShown?this.hide():this.show()},e.prototype.dispose=function(){this.isShown&&this.hide(),this._unsubscribePositioning(),this._unregisterListenersFn&&this._unregisterListenersFn()},e.prototype.listen=function(e){var t,i=this;this.triggers=e.triggers||this.triggers,this._listenOpts.outsideClick=e.outsideClick,this._listenOpts.outsideEsc=e.outsideEsc,e.target=e.target||(null===(t=this._elementRef)||void 0===t?void 0:t.nativeElement);var o=this._listenOpts.hide=function(){return e.hide?e.hide():void i.hide()},s=this._listenOpts.show=function(t){e.show?e.show(t):i.show(t),t()};return this._renderer&&(this._unregisterListenersFn=n.listenToTriggersV2(this._renderer,{target:e.target,triggers:e.triggers,show:s,hide:o,toggle:function(e){i.isShown?o():s(e)}})),this},e.prototype._removeGlobalListener=function(){this._globalListener&&(this._globalListener(),this._globalListener=Function.prototype)},e.prototype.attachInline=function(e,t){return e&&t&&(this._inlineViewRef=e.createEmbeddedView(t)),this},e.prototype._registerOutsideClick=function(){var e=this;if(this._componentRef&&this._componentRef.location){if(this._listenOpts.outsideClick){var t=this._componentRef.location.nativeElement;setTimeout((function(){e._renderer&&e._elementRef&&(e._globalListener=n.registerOutsideClick(e._renderer,{targets:[t,e._elementRef.nativeElement],outsideClick:e._listenOpts.outsideClick,hide:function(){return e._listenOpts.hide&&e._listenOpts.hide()}}))}))}if(this._listenOpts.outsideEsc&&this._renderer&&this._elementRef){var i=this._componentRef.location.nativeElement;this._globalListener=n.registerEscClick(this._renderer,{targets:[i,this._elementRef.nativeElement],outsideEsc:this._listenOpts.outsideEsc,hide:function(){return e._listenOpts.hide&&e._listenOpts.hide()}})}}},e.prototype.getInnerComponent=function(){return this._innerComponent},e.prototype._subscribePositioning=function(){var e=this;!this._zoneSubscription&&this.attachment&&(this.onShown.subscribe((function(){var t;e._posService.position({element:null===(t=e._componentRef)||void 0===t?void 0:t.location,target:e._elementRef,attachment:e.attachment,appendToBody:"body"===e.container})})),this._zoneSubscription=this._ngZone.onStable.subscribe((function(){e._componentRef&&e._posService.calcPosition()})))},e.prototype._unsubscribePositioning=function(){this._zoneSubscription&&(this._zoneSubscription.unsubscribe(),this._zoneSubscription=void 0)},e.prototype._getContentRef=function(e,n,i){if(!e)return new s([]);if(e instanceof t.TemplateRef){if(this._viewContainerRef){var o=this._viewContainerRef.createEmbeddedView(e,n);return o.markForCheck(),new s([o.rootNodes],o)}var r=e.createEmbeddedView({});return this._applicationRef.attachView(r),new s([r.rootNodes],r)}if("function"==typeof e){var c=this._componentFactoryResolver.resolveComponentFactory(e),h=t.Injector.create({providers:this._providers,parent:this._injector}),a=c.create(h);return Object.assign(a.instance,i),this._applicationRef.attachView(a.hostView),new s([[a.location.nativeElement]],a.hostView,a)}var p=this._renderer?[this._renderer.createText(""+e)]:[];return new s([p])},e}(),c=function(){function e(e,t,n,i,o){this._componentFactoryResolver=e,this._ngZone=t,this._injector=n,this._posService=i,this._applicationRef=o}return e.prototype.createLoader=function(e,t,n){return new r(t,n,e,this._injector,this._componentFactoryResolver,this._ngZone,this._applicationRef,this._posService)},e}();c.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new c(t.ɵɵinject(t.ComponentFactoryResolver),t.ɵɵinject(t.NgZone),t.ɵɵinject(t.INJECTOR),t.ɵɵinject(i.PositioningService),t.ɵɵinject(t.ApplicationRef))},token:c,providedIn:"root"}),c.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],c.ctorParameters=function(){return[{type:t.ComponentFactoryResolver},{type:t.NgZone},{type:t.Injector},{type:i.PositioningService},{type:t.ApplicationRef}]},e.BsComponentRef=o,e.ComponentLoader=r,e.ComponentLoaderFactory=c,e.ContentRef=s,Object.defineProperty(e,"__esModule",{value:!0})}));
2//# sourceMappingURL=ngx-bootstrap-component-loader.umd.min.js.map
\No newline at end of file