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C,CAAC,CAAC;YACvB,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,qCAAY,GAAZ,UAAa,EAAc;QACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IACH,qBAAC;AAAD,CAhEA,AAgEC,IAAA","file":"core/portal/portal.js","sourcesContent":["import {\n TemplateRef,\n ViewContainerRef,\n ElementRef,\n ComponentRef,\n Injector\n} from '@angular/core';\nimport {\n MdNullPortalHostError,\n MdPortalAlreadyAttachedError,\n MdNoPortalAttachedError,\n MdNullPortalError,\n MdPortalHostAlreadyDisposedError,\n MdUnknownPortalTypeError\n} from './portal-errors';\nimport {ComponentType} from '../overlay/generic-component-type';\n\n\n\n/**\n * A `Portal` is something that you want to render somewhere else.\n * It can be attach to / detached from a `PortalHost`.\n */\nexport abstract class Portal<T> {\n private _attachedHost: PortalHost;\n\n /** Attach this portal to a host. */\n attach(host: PortalHost): T {\n if (host == null) {\n throw new MdNullPortalHostError();\n }\n\n if (host.hasAttached()) {\n throw new MdPortalAlreadyAttachedError();\n }\n\n this._attachedHost = host;\n return <T> host.attach(this);\n }\n\n /** Detach this portal from its host */\n detach(): void {\n let host = this._attachedHost;\n if (host == null) {\n throw new MdNoPortalAttachedError();\n }\n\n this._attachedHost = null;\n return host.detach();\n }\n\n /** Whether this portal is attached to a host. */\n get isAttached(): boolean {\n return this._attachedHost != null;\n }\n\n /**\n * Sets the PortalHost reference without performing `attach()`. This is used directly by\n * the PortalHost when it is performing an `attach()` or `detatch()`.\n */\n setAttachedHost(host: PortalHost) {\n this._attachedHost = host;\n }\n}\n\n\n/**\n * A `ComponentPortal` is a portal that instantiates some Component upon attachment.\n */\nexport class ComponentPortal<T> extends Portal<ComponentRef<T>> {\n /** The type of the component that will be instantiated for attachment. */\n component: ComponentType<T>;\n\n /**\n * [Optional] Where the attached component should live in Angular's *logical* component tree.\n * This is different from where the component *renders*, which is determined by the PortalHost.\n * The origin necessary when the host is outside of the Angular application context.\n */\n viewContainerRef: ViewContainerRef;\n\n /** [Optional] Injector used for the instantiation of the component. */\n injector: Injector;\n\n constructor(\n component: ComponentType<T>,\n viewContainerRef: ViewContainerRef = null,\n injector: Injector = null) {\n super();\n this.component = component;\n this.viewContainerRef = viewContainerRef;\n this.injector = injector;\n }\n}\n\n\n/**\n * A `TemplatePortal` is a portal that represents some embedded template (TemplateRef).\n */\nexport class TemplatePortal extends Portal<Map<string, any>> {\n /** The embedded template that will be used to instantiate an embedded View in the host. */\n templateRef: TemplateRef<any>;\n\n /** Reference to the ViewContainer into which the template will be stamped out. */\n viewContainerRef: ViewContainerRef;\n\n /**\n * Additional locals for the instantiated embedded view.\n * These locals can be seen as \"exports\" for the template, such as how ngFor has\n * index / event / odd.\n * See https://angular.io/docs/ts/latest/api/core/EmbeddedViewRef-class.html\n */\n locals: Map<string, any> = new Map<string, any>();\n\n constructor(template: TemplateRef<any>, viewContainerRef: ViewContainerRef) {\n super();\n this.templateRef = template;\n this.viewContainerRef = viewContainerRef;\n }\n\n get origin(): ElementRef {\n return this.templateRef.elementRef;\n }\n\n attach(host: PortalHost, locals?: Map<string, any>): Map<string, any> {\n this.locals = locals == null ? new Map<string, any>() : locals;\n return super.attach(host);\n }\n\n detach(): void {\n this.locals = new Map<string, any>();\n return super.detach();\n }\n}\n\n\n/**\n * A `PortalHost` is an space that can contain a single `Portal`.\n */\nexport interface PortalHost {\n attach(portal: Portal<any>): any;\n\n detach(): any;\n\n dispose(): void;\n\n hasAttached(): boolean;\n}\n\n\n/**\n * Partial implementation of PortalHost that only deals with attaching either a\n * ComponentPortal or a TemplatePortal.\n */\nexport abstract class BasePortalHost implements PortalHost {\n /** The portal currently attached to the host. */\n private _attachedPortal: Portal<any>;\n\n /** A function that will permanently dispose this host. */\n private _disposeFn: () => void;\n\n /** Whether this host has already been permanently disposed. */\n private _isDisposed: boolean = false;\n\n /** Whether this host has an attached portal. */\n hasAttached() {\n return this._attachedPortal != null;\n }\n\n attach(portal: Portal<any>): any {\n if (portal == null) {\n throw new MdNullPortalError();\n }\n\n if (this.hasAttached()) {\n throw new MdPortalAlreadyAttachedError();\n }\n\n if (this._isDisposed) {\n throw new MdPortalHostAlreadyDisposedError();\n }\n\n if (portal instanceof ComponentPortal) {\n this._attachedPortal = portal;\n return this.attachComponentPortal(portal);\n } else if (portal instanceof TemplatePortal) {\n this._attachedPortal = portal;\n return this.attachTemplatePortal(portal);\n }\n\n throw new MdUnknownPortalTypeError();\n }\n\n abstract attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T>;\n\n abstract attachTemplatePortal(portal: TemplatePortal): Map<string, any>;\n\n detach(): void {\n if (this._attachedPortal) { this._attachedPortal.setAttachedHost(null); }\n\n this._attachedPortal = null;\n if (this._disposeFn != null) {\n this._disposeFn();\n this._disposeFn = null;\n }\n }\n\n dispose() {\n if (this.hasAttached()) {\n this.detach();\n }\n\n this._isDisposed = true;\n }\n\n setDisposeFn(fn: () => void) {\n this._disposeFn = fn;\n }\n}\n"],"sourceRoot":"/source/"}
\No newline at end of file