carbon-components-angular
Version:
Next generation components
1 lines • 10.3 kB
Source Map (JSON)
{"version":3,"file":"carbon-components-angular-placeholder.mjs","sources":["../../src/placeholder/placeholder.service.ts","../../src/placeholder/placeholder.component.ts","../../src/placeholder/placeholder.module.ts","../../src/placeholder/carbon-components-angular-placeholder.ts"],"sourcesContent":["import {\n\tComponentRef,\n\tViewContainerRef,\n\tInjector,\n\tEnvironmentInjector,\n\tinject\n} from \"@angular/core\";\nimport { Injectable } from \"@angular/core\";\n\n/**\n * Singleton service used to register the container for out-of-flow components to insert into.\n * Also used to insert/remove components from that view.\n */\n@Injectable()\nexport class PlaceholderService {\n\t/**\n\t * Main `ViewContainerRef` to insert components into\n\t */\n\tprotected viewContainerRef: ViewContainerRef = null;\n\t/**\n\t * Map of id's to secondary `ViewContainerRef`s\n\t */\n\tprotected viewContainerMap: Map<any, ViewContainerRef> = new Map();\n\t/**\n\t * Used by `Placeholder` to register view-container reference.\n\t */\n\tregisterViewContainerRef(vcRef: ViewContainerRef, id?: any): void {\n\t\tif (id) {\n\t\t\tthis.viewContainerMap.set(id, vcRef);\n\t\t} else {\n\t\t\tthis.viewContainerRef = vcRef;\n\t\t}\n\t}\n\n\t/**\n\t * Creates and returns component in the view.\n\t */\n\tcreateComponent(\n\t\tcomponent: ComponentRef<any>,\n\t\tinjector: Injector,\n\t\tid?: any,\n\t\tenvironment: EnvironmentInjector = undefined\n\t): ComponentRef<any> {\n\t\tif (id) {\n\t\t\tif (!this.viewContainerMap.has(id)) {\n\t\t\t\tconsole.error(`No view container with id ${id} found`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn this.viewContainerMap.get(id).createComponent(component as any, { index: this.viewContainerMap.size, injector });\n\t\t}\n\t\tif (!this.viewContainerRef) {\n\t\t\tconsole.error(\"No view container defined! Likely due to a missing `cds-placeholder`\");\n\t\t\treturn;\n\t\t}\n\t\treturn this.viewContainerRef.createComponent(component as any,\n\t\t\t{\n\t\t\t\tindex: this.viewContainerRef.length,\n\t\t\t\tinjector,\n\t\t\t\tenvironmentInjector: environment\n\t\t\t}\n\t\t);\n\t}\n\n\tdestroyComponent(component: ComponentRef<any>) {\n\t\tcomponent.destroy();\n\t}\n\n\thasComponentRef(component: ComponentRef<any>, id?: any) {\n\t\tif (id) {\n\t\t\treturn !(this.viewContainerMap.get(id).indexOf(component.hostView) < 0);\n\t\t}\n\n\t\treturn !(this.viewContainerRef.indexOf(component.hostView) < 0);\n\t}\n\n\thasPlaceholderRef(id?: any) {\n\t\tif (id) {\n\t\t\treturn this.viewContainerMap.has(id);\n\t\t}\n\t\treturn !!this.viewContainerRef;\n\t}\n\n\tappendElement(element: HTMLElement, id?: any): HTMLElement {\n\t\tif (id) {\n\t\t\treturn this.viewContainerMap.get(id).element.nativeElement.appendChild(element);\n\t\t}\n\t\treturn this.viewContainerRef.element.nativeElement.appendChild(element);\n\t}\n\n\tremoveElement(element: HTMLElement, id?: any): HTMLElement {\n\t\tif (id) {\n\t\t\treturn this.viewContainerMap.get(id).element.nativeElement.removeChild(element);\n\t\t}\n\t\treturn this.viewContainerRef.element.nativeElement.removeChild(element);\n\t}\n\n\thasElement(element: HTMLElement, id?: any): boolean {\n\t\tif (id) {\n\t\t\treturn this.viewContainerMap.get(id).element.nativeElement.contains(element);\n\t\t}\n\t\treturn this.viewContainerRef.element.nativeElement.contains(element);\n\t}\n}\n","import {\n\tComponent,\n\tOnInit,\n\tViewContainerRef,\n\tViewChild,\n\tInput\n} from \"@angular/core\";\nimport { PlaceholderService } from \"./placeholder.service\";\n\n/**\n * Using a modal, dialog (Tooltip, OverflowMenu), or any other component that draws out of the normal page flow\n * in your application *requires* this component (`cds-placeholder`).\n * It would generally be placed near the end of your root app component template\n * (app.component.ts or app.component.html) as:\n *\n * ```\n * <cds-placeholder></cds-placeholder>\n * ```\n */\n@Component({\n\tselector: \"cds-placeholder, ibm-placeholder\",\n\ttemplate: `<div #placeholder></div>`\n})\nexport class Placeholder implements OnInit {\n\t@Input() id: any;\n\t/**\n\t * Maintains a reference to the view DOM element of the `Placeholder`.\n\t */\n\t@ViewChild(\"placeholder\", { read: ViewContainerRef, static: true }) viewContainerRef: ViewContainerRef;\n\n\t/**\n\t * Creates an instance of `Placeholder`.\n\t */\n\tconstructor(public placeholderService: PlaceholderService) { }\n\n\t/**\n\t * Registers the components view with `PlaceholderService`\n\t */\n\tngOnInit() {\n\t\t// TODO use `id` to register with the placeholderService\n\t\tthis.placeholderService.registerViewContainerRef(this.viewContainerRef);\n\t}\n}\n","// modules\nimport { NgModule, SkipSelf, Optional } from \"@angular/core\";\nimport { CommonModule } from \"@angular/common\";\n\n// imports\nimport { Placeholder } from \"./placeholder.component\";\nimport { PlaceholderService } from \"./placeholder.service\";\n\n// either provides a new instance of PlaceholderService, or returns the parent\nexport function PLACEHOLDER_SERVICE_PROVIDER_FACTORY(parentService: PlaceholderService) {\n\treturn parentService || new PlaceholderService();\n}\n\n// placeholder service *must* be a singleton to ensure the placeholder viewRef is accessible globally\nexport const PLACEHOLDER_SERVICE_PROVIDER = {\n\tprovide: PlaceholderService,\n\tdeps: [[new Optional(), new SkipSelf(), PlaceholderService]],\n\tuseFactory: PLACEHOLDER_SERVICE_PROVIDER_FACTORY\n};\n\n@NgModule({\n\tdeclarations: [ Placeholder ],\n\texports: [ Placeholder ],\n\tproviders: [ PLACEHOLDER_SERVICE_PROVIDER ],\n\timports: [ CommonModule ]\n})\nexport class PlaceholderModule { }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["i1.PlaceholderService"],"mappings":";;;;AASA;;;AAGG;MAEU,kBAAkB,CAAA;AAD/B,IAAA,WAAA,GAAA;AAEC;;AAEG;AACO,QAAA,IAAgB,CAAA,gBAAA,GAAqB,IAAI,CAAC;AACpD;;AAEG;AACO,QAAA,IAAA,CAAA,gBAAgB,GAA+B,IAAI,GAAG,EAAE,CAAC;KAgFnE;AA/EA;;AAEG;IACH,wBAAwB,CAAC,KAAuB,EAAE,EAAQ,EAAA;AACzD,Q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