UNPKG

@angular/cdk

Version:

Angular Material Component Development Kit

30 lines (28 loc) 9.51 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("@angular/cdk/portal",["exports","@angular/core","@angular/common"],e):e(((t=t||self).ng=t.ng||{},t.ng.cdk=t.ng.cdk||{},t.ng.cdk.portal={}),t.ng.core,t.ng.common)}(this,(function(t,e,o){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])})(t,e)};function r(t,e){function o(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var a=function(){function t(){}return t.prototype.attach=function(t){return this._attachedHost=t,t.attach(this)},t.prototype.detach=function(){var t=this._attachedHost;null!=t&&(this._attachedHost=null,t.detach())},Object.defineProperty(t.prototype,"isAttached",{get:function(){return null!=this._attachedHost},enumerable:!1,configurable:!0}),t.prototype.setAttachedHost=function(t){this._attachedHost=t},t}(),i=function(t){function e(e,o,n,r){var a=t.call(this)||this;return a.component=e,a.viewContainerRef=o,a.injector=n,a.componentFactoryResolver=r,a}return r(e,t),e}(a),c=function(t){function e(e,o,n){var r=t.call(this)||this;return r.templateRef=e,r.viewContainerRef=o,r.context=n,r}return r(e,t),Object.defineProperty(e.prototype,"origin",{get:function(){return this.templateRef.elementRef},enumerable:!1,configurable:!0}),e.prototype.attach=function(e,o){return void 0===o&&(o=this.context),this.context=o,t.prototype.attach.call(this,e)},e.prototype.detach=function(){return this.context=void 0,t.prototype.detach.call(this)},e}(a),s=function(t){function o(o){var n=t.call(this)||this;return n.element=o instanceof e.ElementRef?o.nativeElement:o,n}return r(o,t),o}(a),p=function(){function t(){this._isDisposed=!1,this.attachDomPortal=null}return t.prototype.hasAttached=function(){return!!this._attachedPortal},t.prototype.attach=function(t){return t instanceof i?(this._attachedPortal=t,this.attachComponentPortal(t)):t instanceof c?(this._attachedPortal=t,this.attachTemplatePortal(t)):this.attachDomPortal&&t instanceof s?(this._attachedPortal=t,this.attachDomPortal(t)):void 0},t.prototype.detach=function(){this._attachedPortal&&(this._attachedPortal.setAttachedHost(null),this._attachedPortal=null),this._invokeDisposeFn()},t.prototype.dispose=function(){this.hasAttached()&&this.detach(),this._invokeDisposeFn(),this._isDisposed=!0},t.prototype.setDisposeFn=function(t){this._disposeFn=t},t.prototype._invokeDisposeFn=function(){this._disposeFn&&(this._disposeFn(),this._disposeFn=null)},t}(),l=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e}(p),h=function(t){function e(e,o,n,r,a){var i=t.call(this)||this;return i.outletElement=e,i._componentFactoryResolver=o,i._appRef=n,i._defaultInjector=r,i.attachDomPortal=function(e){var o=e.element,n=i._document.createComment("dom-portal");o.parentNode.insertBefore(n,o),i.outletElement.appendChild(o),t.prototype.setDisposeFn.call(i,(function(){n.parentNode&&n.parentNode.replaceChild(o,n)}))},i._document=a,i}return r(e,t),e.prototype.attachComponentPortal=function(t){var e,o=this,n=(t.componentFactoryResolver||this._componentFactoryResolver).resolveComponentFactory(t.component);return t.viewContainerRef?(e=t.viewContainerRef.createComponent(n,t.viewContainerRef.length,t.injector||t.viewContainerRef.injector),this.setDisposeFn((function(){return e.destroy()}))):(e=n.create(t.injector||this._defaultInjector),this._appRef.attachView(e.hostView),this.setDisposeFn((function(){o._appRef.detachView(e.hostView),e.destroy()}))),this.outletElement.appendChild(this._getComponentRootNode(e)),e},e.prototype.attachTemplatePortal=function(t){var e=this,o=t.viewContainerRef,n=o.createEmbeddedView(t.templateRef,t.context);return n.rootNodes.forEach((function(t){return e.outletElement.appendChild(t)})),n.detectChanges(),this.setDisposeFn((function(){var t=o.indexOf(n);-1!==t&&o.remove(t)})),n},e.prototype.dispose=function(){t.prototype.dispose.call(this),null!=this.outletElement.parentNode&&this.outletElement.parentNode.removeChild(this.outletElement)},e.prototype._getComponentRootNode=function(t){return t.hostView.rootNodes[0]},e}(p),u=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e}(h),d=function(t){function e(e,o){return t.call(this,e,o)||this}return r(e,t),e}(c);d.decorators=[{type:e.Directive,args:[{selector:"[cdkPortal]",exportAs:"cdkPortal"}]}],d.ctorParameters=function(){return[{type:e.TemplateRef},{type:e.ViewContainerRef}]};var f=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e}(d);f.decorators=[{type:e.Directive,args:[{selector:"[cdk-portal], [portal]",exportAs:"cdkPortal",providers:[{provide:d,useExisting:f}]}]}];var m=function(t){function o(o,n,r){var a=t.call(this)||this;return a._componentFactoryResolver=o,a._viewContainerRef=n,a._isInitialized=!1,a.attached=new e.EventEmitter,a.attachDomPortal=function(e){var o=e.element,n=a._document.createComment("dom-portal");e.setAttachedHost(a),o.parentNode.insertBefore(n,o),a._getRootNode().appendChild(o),t.prototype.setDisposeFn.call(a,(function(){n.parentNode&&n.parentNode.replaceChild(o,n)}))},a._document=r,a}return r(o,t),Object.defineProperty(o.prototype,"portal",{get:function(){return this._attachedPortal},set:function(e){(!this.hasAttached()||e||this._isInitialized)&&(this.hasAttached()&&t.prototype.detach.call(this),e&&t.prototype.attach.call(this,e),this._attachedPortal=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"attachedRef",{get:function(){return this._attachedRef},enumerable:!1,configurable:!0}),o.prototype.ngOnInit=function(){this._isInitialized=!0},o.prototype.ngOnDestroy=function(){t.prototype.dispose.call(this),this._attachedPortal=null,this._attachedRef=null},o.prototype.attachComponentPortal=function(e){e.setAttachedHost(this);var o=null!=e.viewContainerRef?e.viewContainerRef:this._viewContainerRef,n=(e.componentFactoryResolver||this._componentFactoryResolver).resolveComponentFactory(e.component),r=o.createComponent(n,o.length,e.injector||o.injector);return o!==this._viewContainerRef&&this._getRootNode().appendChild(r.hostView.rootNodes[0]),t.prototype.setDisposeFn.call(this,(function(){return r.destroy()})),this._attachedPortal=e,this._attachedRef=r,this.attached.emit(r),r},o.prototype.attachTemplatePortal=function(e){var o=this;e.setAttachedHost(this);var n=this._viewContainerRef.createEmbeddedView(e.templateRef,e.context);return t.prototype.setDisposeFn.call(this,(function(){return o._viewContainerRef.clear()})),this._attachedPortal=e,this._attachedRef=n,this.attached.emit(n),n},o.prototype._getRootNode=function(){var t=this._viewContainerRef.element.nativeElement;return t.nodeType===t.ELEMENT_NODE?t:t.parentNode},o}(p);m.decorators=[{type:e.Directive,args:[{selector:"[cdkPortalOutlet]",exportAs:"cdkPortalOutlet",inputs:["portal: cdkPortalOutlet"]}]}],m.ctorParameters=function(){return[{type:e.ComponentFactoryResolver},{type:e.ViewContainerRef},{type:void 0,decorators:[{type:e.Inject,args:[o.DOCUMENT]}]}]},m.propDecorators={attached:[{type:e.Output}]};var y,v=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e}(m);v.decorators=[{type:e.Directive,args:[{selector:"[cdkPortalHost], [portalHost]",exportAs:"cdkPortalHost",inputs:["portal: cdkPortalHost"],providers:[{provide:m,useExisting:v}]}]}],(y=function y(){}).decorators=[{type:e.NgModule,args:[{exports:[d,m,f,v],declarations:[d,m,f,v]}]}]; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var _=function(){function t(t,e){this._parentInjector=t,this._customTokens=e}return t.prototype.get=function(t,e){var o=this._customTokens.get(t);return void 0!==o?o:this._parentInjector.get(t,e)},t}(); /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */t.BasePortalHost=l,t.BasePortalOutlet=p,t.CdkPortal=d,t.CdkPortalOutlet=m,t.ComponentPortal=i,t.DomPortal=s,t.DomPortalHost=u,t.DomPortalOutlet=h,t.Portal=a,t.PortalHostDirective=v,t.PortalInjector=_,t.PortalModule=y,t.TemplatePortal=c,t.TemplatePortalDirective=f,Object.defineProperty(t,"__esModule",{value:!0})}));