UNPKG

@angular/cdk

Version:

Angular Material Component Development Kit

39 lines (37 loc) 10.7 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)e.hasOwnProperty(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)}function a(){throw Error("Host already has a portal attached")} /** * @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 i=function(){function t(){}return t.prototype.attach=function(t){return null==t&&function e(){throw Error("Attempting to attach a portal to a null PortalOutlet")}(),t.hasAttached()&&a(),this._attachedHost=t,t.attach(this)},t.prototype.detach=function(){var t=this._attachedHost;null==t?function e(){throw Error("Attempting to detach a portal that is not attached to a host")}():(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}(),c=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}(i),s=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}(i),p=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}(i),l=function(){function t(){this._isDisposed=!1,this.attachDomPortal=null}return t.prototype.hasAttached=function(){return!!this._attachedPortal},t.prototype.attach=function(t){return 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 */ function e(){throw Error("Must provide a portal to attach")}(),this.hasAttached()&&a(),this._isDisposed&&function o(){throw Error("This PortalOutlet has already been disposed")}(),t instanceof c?(this._attachedPortal=t,this.attachComponentPortal(t)):t instanceof s?(this._attachedPortal=t,this.attachTemplatePortal(t)):this.attachDomPortal&&t instanceof p?(this._attachedPortal=t,this.attachDomPortal(t)):void function n(){throw Error("Attempting to attach an unknown Portal type. BasePortalOutlet accepts either a ComponentPortal or a TemplatePortal.")}()},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}(),h=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e}(l),u=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){if(!i._document)throw Error("Cannot attach DOM portal without _document constructor parameter");var o=e.element;if(!o.parentNode)throw Error("DOM portal content must be attached to a parent node.");var 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.detectChanges(),n.rootNodes.forEach((function(t){return e.outletElement.appendChild(t)})),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}(l),d=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e}(u),f=function(t){function o(e,o){return t.call(this,e,o)||this}return r(o,t),o.decorators=[{type:e.Directive,args:[{selector:"[cdkPortal]",exportAs:"cdkPortal"}]}],o.ctorParameters=function(){return[{type:e.TemplateRef},{type:e.ViewContainerRef}]},o}(s),m=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return r(o,t),o.decorators=[{type:e.Directive,args:[{selector:"[cdk-portal], [portal]",exportAs:"cdkPortal",providers:[{provide:f,useExisting:o}]}]}],o}(f),y=function(t){function n(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){if(!a._document)throw Error("Cannot attach DOM portal without _document constructor parameter");var o=e.element;if(!o.parentNode)throw Error("DOM portal content must be attached to a parent node.");var 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(n,t),Object.defineProperty(n.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(n.prototype,"attachedRef",{get:function(){return this._attachedRef},enumerable:!1,configurable:!0}),n.prototype.ngOnInit=function(){this._isInitialized=!0},n.prototype.ngOnDestroy=function(){t.prototype.dispose.call(this),this._attachedPortal=null,this._attachedRef=null},n.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},n.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},n.prototype._getRootNode=function(){var t=this._viewContainerRef.element.nativeElement;return t.nodeType===t.ELEMENT_NODE?t:t.parentNode},n.decorators=[{type:e.Directive,args:[{selector:"[cdkPortalOutlet]",exportAs:"cdkPortalOutlet",inputs:["portal: cdkPortalOutlet"]}]}],n.ctorParameters=function(){return[{type:e.ComponentFactoryResolver},{type:e.ViewContainerRef},{type:void 0,decorators:[{type:e.Inject,args:[o.DOCUMENT]}]}]},n.propDecorators={attached:[{type:e.Output}]},n}(l),_=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return r(o,t),o.decorators=[{type:e.Directive,args:[{selector:"[cdkPortalHost], [portalHost]",exportAs:"cdkPortalHost",inputs:["portal: cdkPortalHost"],providers:[{provide:y,useExisting:o}]}]}],o}(y),v=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{exports:[f,y,m,_],declarations:[f,y,m,_]}]}],t}(),P=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=h,t.BasePortalOutlet=l,t.CdkPortal=f,t.CdkPortalOutlet=y,t.ComponentPortal=c,t.DomPortal=p,t.DomPortalHost=d,t.DomPortalOutlet=u,t.Portal=i,t.PortalHostDirective=_,t.PortalInjector=P,t.PortalModule=v,t.TemplatePortal=s,t.TemplatePortalDirective=m,Object.defineProperty(t,"__esModule",{value:!0})}));