@angular/cdk
Version:
Angular Material Component Development Kit
24 lines • 9.66 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib"),require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("@angular/cdk/portal",["exports","tslib","@angular/core","@angular/common"],e):e(((t=t||self).ng=t.ng||{},t.ng.cdk=t.ng.cdk||{},t.ng.cdk.portal={}),t.tslib,t.ng.core,t.ng.common)}(this,(function(t,e,o,n){"use strict";
/**
* @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 r(){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 a=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()&&r(),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:!0,configurable:!0}),t.prototype.setAttachedHost=function(t){this._attachedHost=t},t}(),i=function(t){function o(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 e.__extends(o,t),o}(a),s=function(t){function o(e,o,n){var r=t.call(this)||this;return r.templateRef=e,r.viewContainerRef=o,r.context=n,r}return e.__extends(o,t),Object.defineProperty(o.prototype,"origin",{get:function(){return this.templateRef.elementRef},enumerable:!0,configurable:!0}),o.prototype.attach=function(e,o){return void 0===o&&(o=this.context),this.context=o,t.prototype.attach.call(this,e)},o.prototype.detach=function(){return this.context=void 0,t.prototype.detach.call(this)},o}(a),c=function(t){function n(e){var n=t.call(this)||this;return n.element=e instanceof o.ElementRef?e.nativeElement:e,n}return e.__extends(n,t),n}(a),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||function e(){throw Error("Must provide a portal to attach")}(),this.hasAttached()&&r(),this._isDisposed&&function o(){throw Error("This PortalOutlet has already been disposed")}(),t instanceof i?(this._attachedPortal=t,this.attachComponentPortal(t)):t instanceof s?(this._attachedPortal=t,this.attachTemplatePortal(t)):this.attachDomPortal&&t instanceof c?(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}(),p=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return e.__extends(o,t),o}(l),h=function(t){function o(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 e.__extends(o,t),o.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},o.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},o.prototype.dispose=function(){t.prototype.dispose.call(this),null!=this.outletElement.parentNode&&this.outletElement.parentNode.removeChild(this.outletElement)},o.prototype._getComponentRootNode=function(t){return t.hostView.rootNodes[0]},o}(l),u=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return e.__extends(o,t),o}(h),d=function(t){function n(e,o){return t.call(this,e,o)||this}return e.__extends(n,t),n.decorators=[{type:o.Directive,args:[{selector:"[cdkPortal]",exportAs:"cdkPortal"}]}],n.ctorParameters=function(){return[{type:o.TemplateRef},{type:o.ViewContainerRef}]},n}(s),f=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e.__extends(n,t),n.decorators=[{type:o.Directive,args:[{selector:"[cdk-portal], [portal]",exportAs:"cdkPortal",providers:[{provide:d,useExisting:n}]}]}],n}(d),m=function(t){function r(e,n,r){var a=t.call(this)||this;return a._componentFactoryResolver=e,a._viewContainerRef=n,a._isInitialized=!1,a.attached=new o.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 e.__extends(r,t),Object.defineProperty(r.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:!0,configurable:!0}),Object.defineProperty(r.prototype,"attachedRef",{get:function(){return this._attachedRef},enumerable:!0,configurable:!0}),r.prototype.ngOnInit=function(){this._isInitialized=!0},r.prototype.ngOnDestroy=function(){t.prototype.dispose.call(this),this._attachedPortal=null,this._attachedRef=null},r.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},r.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},r.prototype._getRootNode=function(){var t=this._viewContainerRef.element.nativeElement;return t.nodeType===t.ELEMENT_NODE?t:t.parentNode},r.decorators=[{type:o.Directive,args:[{selector:"[cdkPortalOutlet]",exportAs:"cdkPortalOutlet",inputs:["portal: cdkPortalOutlet"]}]}],r.ctorParameters=function(){return[{type:o.ComponentFactoryResolver},{type:o.ViewContainerRef},{type:void 0,decorators:[{type:o.Inject,args:[n.DOCUMENT]}]}]},r.propDecorators={attached:[{type:o.Output}]},r}(l),_=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e.__extends(n,t),n.decorators=[{type:o.Directive,args:[{selector:"[cdkPortalHost], [portalHost]",exportAs:"cdkPortalHost",inputs:["portal: cdkPortalHost"],providers:[{provide:m,useExisting:n}]}]}],n}(m),y=function(){function t(){}return t.decorators=[{type:o.NgModule,args:[{exports:[d,m,f,_],declarations:[d,m,f,_]}]}],t}(),v=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=p,t.BasePortalOutlet=l,t.CdkPortal=d,t.CdkPortalOutlet=m,t.ComponentPortal=i,t.DomPortal=c,t.DomPortalHost=u,t.DomPortalOutlet=h,t.Portal=a,t.PortalHostDirective=_,t.PortalInjector=v,t.PortalModule=y,t.TemplatePortal=s,t.TemplatePortalDirective=f,Object.defineProperty(t,"__esModule",{value:!0})}));