@zdigambar/ngx-element 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/bundles/zdigambar-ngx-element.umd.js +579 -0
- package/bundles/zdigambar-ngx-element.umd.js.map +1 -0
- package/bundles/zdigambar-ngx-element.umd.min.js +16 -0
- package/bundles/zdigambar-ngx-element.umd.min.js.map +1 -0
- package/esm2015/lib/lazy-component-loaded-event.js +2 -0
- package/esm2015/lib/ngx-element.component.js +105 -0
- package/esm2015/lib/ngx-element.module.js +33 -0
- package/esm2015/lib/ngx-element.service.js +136 -0
- package/esm2015/lib/tokens.js +4 -0
- package/esm2015/public-api.js +5 -0
- package/esm2015/zdigambar-ngx-element.js +8 -0
- package/fesm2015/zdigambar-ngx-element.js +279 -0
- package/fesm2015/zdigambar-ngx-element.js.map +1 -0
- package/lib/lazy-component-loaded-event.d.ts +5 -0
- package/lib/ngx-element.component.d.ts +27 -0
- package/lib/ngx-element.module.d.ts +7 -0
- package/lib/ngx-element.service.d.ts +28 -0
- package/lib/tokens.d.ts +7 -0
- package/package.json +39 -0
- package/public-api.d.ts +1 -0
- package/zdigambar-ngx-element.d.ts +7 -0
- package/zdigambar-ngx-element.metadata.json +1 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { InjectionToken, ComponentFactoryResolver, NgModuleFactory, ɵɵdefineInjectable, ɵɵinject, Compiler, INJECTOR, Injectable, Inject, Injector, ReflectiveInjector, Component, ElementRef, Input, ViewChild, ViewContainerRef, NgModule } from '@angular/core';
|
|
2
|
+
import { createCustomElement } from '@angular/elements';
|
|
3
|
+
import { from, merge } from 'rxjs';
|
|
4
|
+
import { map } from 'rxjs/operators';
|
|
5
|
+
|
|
6
|
+
/* Injection token to provide the element path modules. */
|
|
7
|
+
const LAZY_CMPS_PATH_TOKEN = new InjectionToken('ngx-lazy-cmp-registry');
|
|
8
|
+
|
|
9
|
+
class NgxElementService {
|
|
10
|
+
constructor(modulePaths, compiler, injector) {
|
|
11
|
+
this.compiler = compiler;
|
|
12
|
+
this.injector = injector;
|
|
13
|
+
this.loadedComponents = new Map();
|
|
14
|
+
this.elementsLoading = new Map();
|
|
15
|
+
this.injectors = new Map();
|
|
16
|
+
this.componentFactoryResolvers = new Map();
|
|
17
|
+
const ELEMENT_MODULE_PATHS = new Map();
|
|
18
|
+
modulePaths.forEach(route => {
|
|
19
|
+
ELEMENT_MODULE_PATHS.set(route.selector, route);
|
|
20
|
+
});
|
|
21
|
+
this.componentsToLoad = ELEMENT_MODULE_PATHS;
|
|
22
|
+
}
|
|
23
|
+
receiveContext(component, injector) {
|
|
24
|
+
this.injectors.set(component, injector);
|
|
25
|
+
this.componentFactoryResolvers.set(component, injector.get(ComponentFactoryResolver));
|
|
26
|
+
}
|
|
27
|
+
getInjector(component) {
|
|
28
|
+
return this.injectors.get(component);
|
|
29
|
+
}
|
|
30
|
+
getComponentFactoryResolver(component) {
|
|
31
|
+
return this.componentFactoryResolvers.get(component);
|
|
32
|
+
}
|
|
33
|
+
getComponentsToLoad() {
|
|
34
|
+
return this.componentsToLoad;
|
|
35
|
+
}
|
|
36
|
+
getComponentToLoad(selector) {
|
|
37
|
+
// Returns observable that completes when the lazy module has been loaded.
|
|
38
|
+
const registered = this.loadComponent(selector);
|
|
39
|
+
return from(registered);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Allows to lazy load a component given its selector.
|
|
43
|
+
* If the component selector has been registered, it's according module
|
|
44
|
+
* will be fetched lazily
|
|
45
|
+
* @param componentTag selector of the component to load
|
|
46
|
+
*/
|
|
47
|
+
loadComponent(componentSelector) {
|
|
48
|
+
if (this.elementsLoading.has(componentSelector)) {
|
|
49
|
+
return this.elementsLoading.get(componentSelector);
|
|
50
|
+
}
|
|
51
|
+
if (this.componentsToLoad.has(componentSelector)) {
|
|
52
|
+
const cmpRegistryEntry = this.componentsToLoad.get(componentSelector);
|
|
53
|
+
const path = cmpRegistryEntry.loadChildren;
|
|
54
|
+
const loadPromise = new Promise((resolve, reject) => {
|
|
55
|
+
path()
|
|
56
|
+
.then(elementModuleOrFactory => {
|
|
57
|
+
/**
|
|
58
|
+
* With View Engine, the NgModule factory is created and provided when loaded.
|
|
59
|
+
* With Ivy, only the NgModule class is provided loaded and must be compiled.
|
|
60
|
+
* This uses the same mechanism as the deprecated `SystemJsNgModuleLoader` in
|
|
61
|
+
* in `packages/core/src/linker/system_js_ng_module_factory_loader.ts`
|
|
62
|
+
* to pass on the NgModuleFactory, or compile the NgModule and return its NgModuleFactory.
|
|
63
|
+
*/
|
|
64
|
+
if (elementModuleOrFactory instanceof NgModuleFactory) {
|
|
65
|
+
return elementModuleOrFactory;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
try {
|
|
69
|
+
return this.compiler.compileModuleAsync(elementModuleOrFactory);
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
// return the error
|
|
73
|
+
reject(err);
|
|
74
|
+
// break the promise chain
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
.then(moduleFactory => {
|
|
80
|
+
const elementModuleRef = moduleFactory.create(this.injector);
|
|
81
|
+
let componentClass;
|
|
82
|
+
if (typeof elementModuleRef.instance.customElementComponent === 'object') {
|
|
83
|
+
componentClass = elementModuleRef.instance.customElementComponent[componentSelector];
|
|
84
|
+
if (!componentClass) {
|
|
85
|
+
// tslint:disable-next-line: no-string-throw
|
|
86
|
+
throw `You specified multiple component elements in module ${elementModuleRef} but there was no match for tag
|
|
87
|
+
${componentSelector} in ${JSON.stringify(elementModuleRef.instance.customElementComponent)}.
|
|
88
|
+
Make sure the selector in the module is aligned with the one specified in the lazy module definition.`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
componentClass = elementModuleRef.instance.customElementComponent;
|
|
93
|
+
}
|
|
94
|
+
// Register injector of the lazy module.
|
|
95
|
+
// This is needed to share the entryComponents between the lazy module and the application
|
|
96
|
+
const moduleInjector = elementModuleRef.injector;
|
|
97
|
+
this.receiveContext(componentClass, moduleInjector);
|
|
98
|
+
this.loadedComponents.set(componentSelector, componentClass);
|
|
99
|
+
this.elementsLoading.delete(componentSelector);
|
|
100
|
+
this.componentsToLoad.delete(componentSelector);
|
|
101
|
+
resolve({
|
|
102
|
+
selector: componentSelector,
|
|
103
|
+
componentClass
|
|
104
|
+
});
|
|
105
|
+
})
|
|
106
|
+
.catch(err => {
|
|
107
|
+
this.elementsLoading.delete(componentSelector);
|
|
108
|
+
return Promise.reject(err);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
this.elementsLoading.set(componentSelector, loadPromise);
|
|
112
|
+
return loadPromise;
|
|
113
|
+
}
|
|
114
|
+
else if (this.loadedComponents.has(componentSelector)) {
|
|
115
|
+
// component already loaded
|
|
116
|
+
return new Promise(resolve => {
|
|
117
|
+
resolve({
|
|
118
|
+
selector: componentSelector,
|
|
119
|
+
componentClass: this.loadedComponents.get(componentSelector)
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw new Error(`Unrecognized component "${componentSelector}". Make sure it is registered in the component registry`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
NgxElementService.ɵprov = ɵɵdefineInjectable({ factory: function NgxElementService_Factory() { return new NgxElementService(ɵɵinject(LAZY_CMPS_PATH_TOKEN), ɵɵinject(Compiler), ɵɵinject(INJECTOR)); }, token: NgxElementService, providedIn: "root" });
|
|
129
|
+
NgxElementService.decorators = [
|
|
130
|
+
{ type: Injectable, args: [{
|
|
131
|
+
providedIn: 'root'
|
|
132
|
+
},] }
|
|
133
|
+
];
|
|
134
|
+
NgxElementService.ctorParameters = () => [
|
|
135
|
+
{ type: Array, decorators: [{ type: Inject, args: [LAZY_CMPS_PATH_TOKEN,] }] },
|
|
136
|
+
{ type: Compiler },
|
|
137
|
+
{ type: Injector }
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
class NgxElementComponent {
|
|
141
|
+
constructor(ngxElementService, elementRef) {
|
|
142
|
+
this.ngxElementService = ngxElementService;
|
|
143
|
+
this.elementRef = elementRef;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Subscribe to event emitters of a lazy loaded and dynamically instantiated Angular component
|
|
147
|
+
* and dispatch them as Custom Events on the NgxElementComponent that is used in a template.
|
|
148
|
+
*/
|
|
149
|
+
setProxiedOutputs(factory) {
|
|
150
|
+
const eventEmitters = factory.outputs.map(({ propName, templateName }) => {
|
|
151
|
+
const emitter = this.componentRef.instance[propName];
|
|
152
|
+
return emitter.pipe(map((value) => ({ name: templateName, value })));
|
|
153
|
+
});
|
|
154
|
+
const outputEvents = merge(...eventEmitters);
|
|
155
|
+
this.ngElementEventsSubscription = outputEvents.subscribe(subscription => {
|
|
156
|
+
const customEvent = document.createEvent('CustomEvent');
|
|
157
|
+
customEvent.initCustomEvent(subscription.name, false, false, subscription.value);
|
|
158
|
+
this.elementRef.nativeElement.dispatchEvent(customEvent);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
ngOnInit() {
|
|
162
|
+
this.ngxElementService.getComponentToLoad(this.selector).subscribe(event => {
|
|
163
|
+
this.componentToLoad = event.componentClass;
|
|
164
|
+
this.componentFactoryResolver = this.ngxElementService.getComponentFactoryResolver(this.componentToLoad);
|
|
165
|
+
this.injector = this.ngxElementService.getInjector(this.componentToLoad);
|
|
166
|
+
const attributes = this.getElementAttributes();
|
|
167
|
+
this.createComponent(attributes);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
createComponent(attributes) {
|
|
171
|
+
this.container.clear();
|
|
172
|
+
const factory = this.componentFactoryResolver.resolveComponentFactory(this.componentToLoad);
|
|
173
|
+
this.refInjector = ReflectiveInjector.resolveAndCreate([{ provide: this.componentToLoad, useValue: this.componentToLoad }], this.injector);
|
|
174
|
+
this.componentRef = this.container.createComponent(factory, 0, this.refInjector);
|
|
175
|
+
this.setAttributes(attributes);
|
|
176
|
+
this.listenToAttributeChanges();
|
|
177
|
+
this.setProxiedOutputs(factory);
|
|
178
|
+
}
|
|
179
|
+
setAttributes(attributes) {
|
|
180
|
+
attributes.forEach(attr => {
|
|
181
|
+
this.componentRef.instance[attr.name] = attr.value;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
getElementAttributes() {
|
|
185
|
+
const attrs = this.elementRef.nativeElement.attributes;
|
|
186
|
+
const attributes = [];
|
|
187
|
+
for (let attr, i = 0; i < attrs.length; i++) {
|
|
188
|
+
attr = attrs[i];
|
|
189
|
+
if (attr.nodeName.match('^data-')) {
|
|
190
|
+
attributes.push({
|
|
191
|
+
name: this.camelCaseAttribute(attr.nodeName),
|
|
192
|
+
value: attr.nodeValue
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return attributes;
|
|
197
|
+
}
|
|
198
|
+
camelCaseAttribute(attribute) {
|
|
199
|
+
const attr = attribute.replace('data-', '');
|
|
200
|
+
const chunks = attr.split('-');
|
|
201
|
+
if (chunks.length > 1) {
|
|
202
|
+
return chunks[0] + chunks.slice(1).map(chunk => chunk.replace(/^\w/, c => c.toUpperCase())).join('');
|
|
203
|
+
}
|
|
204
|
+
return attr;
|
|
205
|
+
}
|
|
206
|
+
listenToAttributeChanges() {
|
|
207
|
+
const observer = new MutationObserver(mutations => {
|
|
208
|
+
mutations.forEach(mutation => {
|
|
209
|
+
if (mutation.type === 'attributes') {
|
|
210
|
+
const attributes = this.getElementAttributes();
|
|
211
|
+
this.setAttributes(attributes);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
observer.observe(this.elementRef.nativeElement, {
|
|
216
|
+
attributes: true
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
ngOnDestroy() {
|
|
220
|
+
this.componentRef.destroy();
|
|
221
|
+
this.ngElementEventsSubscription.unsubscribe();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
NgxElementComponent.decorators = [
|
|
225
|
+
{ type: Component, args: [{
|
|
226
|
+
selector: 'lib-ngx-element',
|
|
227
|
+
template: `
|
|
228
|
+
<ng-template #container></ng-template>
|
|
229
|
+
`
|
|
230
|
+
},] }
|
|
231
|
+
];
|
|
232
|
+
NgxElementComponent.ctorParameters = () => [
|
|
233
|
+
{ type: NgxElementService },
|
|
234
|
+
{ type: ElementRef }
|
|
235
|
+
];
|
|
236
|
+
NgxElementComponent.propDecorators = {
|
|
237
|
+
selector: [{ type: Input }],
|
|
238
|
+
container: [{ type: ViewChild, args: ['container', { read: ViewContainerRef },] }]
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
class NgxElementModule {
|
|
242
|
+
constructor(injector) {
|
|
243
|
+
this.injector = injector;
|
|
244
|
+
const ngxElement = createCustomElement(NgxElementComponent, { injector });
|
|
245
|
+
customElements.define('ngx-element', ngxElement);
|
|
246
|
+
}
|
|
247
|
+
static forRoot(modulePaths) {
|
|
248
|
+
return {
|
|
249
|
+
ngModule: NgxElementModule,
|
|
250
|
+
providers: [
|
|
251
|
+
{
|
|
252
|
+
provide: LAZY_CMPS_PATH_TOKEN,
|
|
253
|
+
useValue: modulePaths
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
ngDoBootstrap() { }
|
|
259
|
+
}
|
|
260
|
+
NgxElementModule.decorators = [
|
|
261
|
+
{ type: NgModule, args: [{
|
|
262
|
+
declarations: [NgxElementComponent],
|
|
263
|
+
entryComponents: [NgxElementComponent]
|
|
264
|
+
},] }
|
|
265
|
+
];
|
|
266
|
+
NgxElementModule.ctorParameters = () => [
|
|
267
|
+
{ type: Injector }
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
/*
|
|
271
|
+
* Public API Surface of ngx-element
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Generated bundle index. Do not edit.
|
|
276
|
+
*/
|
|
277
|
+
|
|
278
|
+
export { NgxElementModule, NgxElementComponent as ɵa, NgxElementService as ɵb, LAZY_CMPS_PATH_TOKEN as ɵc };
|
|
279
|
+
//# sourceMappingURL=zdigambar-ngx-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zdigambar-ngx-element.js","sources":["../../../projects/ngx-element/src/lib/tokens.ts","../../../projects/ngx-element/src/lib/ngx-element.service.ts","../../../projects/ngx-element/src/lib/ngx-element.component.ts","../../../projects/ngx-element/src/lib/ngx-element.module.ts","../../../projects/ngx-element/src/public-api.ts","../../../projects/ngx-element/src/zdigambar-ngx-element.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { LoadChildrenCallback } from '@angular/router';\n\n/* Injection token to provide the element path modules. */\nexport const LAZY_CMPS_PATH_TOKEN = new InjectionToken('ngx-lazy-cmp-registry');\n\nexport interface LazyComponentDef {\n selector: string;\n loadChildren: LoadChildrenCallback; // prop needs to be named like this\n}\n","import { Injectable, Inject, NgModuleFactory, Type, Compiler, Injector, ComponentFactoryResolver } from '@angular/core';\nimport { LAZY_CMPS_PATH_TOKEN, LazyComponentDef } from './tokens';\nimport { LazyCmpLoadedEvent } from './lazy-component-loaded-event';\nimport { Observable, from } from 'rxjs';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class NgxElementService {\n private componentsToLoad: Map<string, LazyComponentDef>;\n private loadedComponents = new Map<string, Type<any>>();\n private elementsLoading = new Map<string, Promise<LazyCmpLoadedEvent>>();\n\n injectors = new Map<Type<any>, Injector>();\n componentFactoryResolvers = new Map<Type<any>, ComponentFactoryResolver>();\n\n constructor(\n @Inject(LAZY_CMPS_PATH_TOKEN)\n modulePaths: {\n selector: string\n }[],\n private compiler: Compiler,\n private injector: Injector\n ) {\n const ELEMENT_MODULE_PATHS = new Map<string, any>();\n modulePaths.forEach(route => {\n ELEMENT_MODULE_PATHS.set(route.selector, route);\n });\n\n this.componentsToLoad = ELEMENT_MODULE_PATHS;\n }\n\n receiveContext(component: Type<any>, injector: Injector) {\n this.injectors.set(component, injector);\n this.componentFactoryResolvers.set(component, injector.get(ComponentFactoryResolver));\n }\n\n getInjector(component: Type<any>): Injector {\n return this.injectors.get(component);\n }\n\n getComponentFactoryResolver(component: Type<any>): ComponentFactoryResolver {\n return this.componentFactoryResolvers.get(component);\n }\n\n getComponentsToLoad() {\n return this.componentsToLoad;\n }\n\n getComponentToLoad(selector: string): Observable<LazyCmpLoadedEvent> {\n // Returns observable that completes when the lazy module has been loaded.\n const registered = this.loadComponent(selector);\n return from(registered);\n }\n\n /**\n * Allows to lazy load a component given its selector.\n * If the component selector has been registered, it's according module\n * will be fetched lazily\n * @param componentTag selector of the component to load\n */\n loadComponent(componentSelector: string): Promise<LazyCmpLoadedEvent> {\n if (this.elementsLoading.has(componentSelector)) {\n return this.elementsLoading.get(componentSelector);\n }\n\n if (this.componentsToLoad.has(componentSelector)) {\n const cmpRegistryEntry = this.componentsToLoad.get(componentSelector);\n const path = cmpRegistryEntry.loadChildren;\n\n const loadPromise = new Promise<LazyCmpLoadedEvent>((resolve, reject) => {\n (path() as Promise<NgModuleFactory<any> | Type<any>>)\n .then(elementModuleOrFactory => {\n /**\n * With View Engine, the NgModule factory is created and provided when loaded.\n * With Ivy, only the NgModule class is provided loaded and must be compiled.\n * This uses the same mechanism as the deprecated `SystemJsNgModuleLoader` in\n * in `packages/core/src/linker/system_js_ng_module_factory_loader.ts`\n * to pass on the NgModuleFactory, or compile the NgModule and return its NgModuleFactory.\n */\n if (elementModuleOrFactory instanceof NgModuleFactory) {\n return elementModuleOrFactory;\n } else {\n try {\n return this.compiler.compileModuleAsync(elementModuleOrFactory);\n } catch (err) {\n // return the error\n reject(err);\n\n // break the promise chain\n throw err;\n }\n }\n })\n .then(moduleFactory => {\n const elementModuleRef = moduleFactory.create(this.injector);\n let componentClass;\n\n if (typeof elementModuleRef.instance.customElementComponent === 'object') {\n componentClass = elementModuleRef.instance.customElementComponent[componentSelector];\n\n if (!componentClass) {\n // tslint:disable-next-line: no-string-throw\n throw `You specified multiple component elements in module ${elementModuleRef} but there was no match for tag\n ${componentSelector} in ${JSON.stringify(elementModuleRef.instance.customElementComponent)}.\n Make sure the selector in the module is aligned with the one specified in the lazy module definition.`;\n }\n } else {\n componentClass = elementModuleRef.instance.customElementComponent;\n }\n\n // Register injector of the lazy module.\n // This is needed to share the entryComponents between the lazy module and the application\n const moduleInjector = elementModuleRef.injector;\n this.receiveContext(componentClass, moduleInjector);\n\n this.loadedComponents.set(componentSelector, componentClass);\n this.elementsLoading.delete(componentSelector);\n this.componentsToLoad.delete(componentSelector);\n\n resolve({\n selector: componentSelector,\n componentClass\n });\n })\n .catch(err => {\n this.elementsLoading.delete(componentSelector);\n return Promise.reject(err);\n });\n });\n\n this.elementsLoading.set(componentSelector, loadPromise);\n return loadPromise;\n\n } else if (this.loadedComponents.has(componentSelector)) {\n // component already loaded\n return new Promise(resolve => {\n resolve({\n selector: componentSelector,\n componentClass: this.loadedComponents.get(componentSelector)\n });\n });\n } else {\n throw new Error(\n `Unrecognized component \"${componentSelector}\". Make sure it is registered in the component registry`\n );\n }\n }\n}","import {\n Component,\n ComponentFactory,\n ComponentRef,\n OnInit,\n Input,\n Output,\n Type,\n ViewChild,\n ViewContainerRef,\n ComponentFactoryResolver,\n OnDestroy,\n EventEmitter,\n ElementRef,\n Injector,\n ReflectiveInjector\n} from '@angular/core';\nimport {NgxElementService} from './ngx-element.service';\nimport {merge, Subscription} from 'rxjs';\nimport {map} from 'rxjs/operators';\n\n@Component({\n selector: 'lib-ngx-element',\n template: `\n <ng-template #container></ng-template>\n `,\n styles: []\n})\nexport class NgxElementComponent implements OnInit, OnDestroy {\n\n private ngElementEventsSubscription: Subscription;\n @Input() selector: string;\n @ViewChild('container', {read: ViewContainerRef}) container;\n\n componentRef: ComponentRef<any>;\n componentToLoad: Type<any>;\n componentFactoryResolver: ComponentFactoryResolver;\n injector: Injector;\n refInjector: ReflectiveInjector;\n\n constructor(\n private ngxElementService: NgxElementService,\n private elementRef: ElementRef\n ) {}\n\n /**\n * Subscribe to event emitters of a lazy loaded and dynamically instantiated Angular component\n * and dispatch them as Custom Events on the NgxElementComponent that is used in a template.\n */\n private setProxiedOutputs(factory: ComponentFactory<any>): void {\n const eventEmitters = factory.outputs.map(({propName, templateName}) => {\n const emitter = (this.componentRef.instance as any)[propName] as EventEmitter<any>;\n return emitter.pipe(map((value: any) => ({name: templateName, value})));\n });\n const outputEvents = merge(...eventEmitters);\n this.ngElementEventsSubscription = outputEvents.subscribe(subscription => {\n const customEvent = document.createEvent('CustomEvent');\n customEvent.initCustomEvent(subscription.name, false, false, subscription.value);\n this.elementRef.nativeElement.dispatchEvent(customEvent);\n });\n }\n\n ngOnInit(): void {\n this.ngxElementService.getComponentToLoad(this.selector).subscribe(event => {\n this.componentToLoad = event.componentClass;\n this.componentFactoryResolver = this.ngxElementService.getComponentFactoryResolver(this.componentToLoad);\n this.injector = this.ngxElementService.getInjector(this.componentToLoad);\n\n const attributes = this.getElementAttributes();\n this.createComponent(attributes);\n });\n }\n\n createComponent(attributes) {\n this.container.clear();\n const factory = this.componentFactoryResolver.resolveComponentFactory(this.componentToLoad);\n\n this.refInjector = ReflectiveInjector.resolveAndCreate(\n [{provide: this.componentToLoad, useValue: this.componentToLoad}], this.injector\n );\n this.componentRef = this.container.createComponent(factory, 0, this.refInjector);\n\n this.setAttributes(attributes);\n this.listenToAttributeChanges();\n this.setProxiedOutputs(factory);\n }\n\n setAttributes(attributes) {\n attributes.forEach(attr => {\n this.componentRef.instance[attr.name] = attr.value;\n });\n }\n\n getElementAttributes() {\n const attrs = this.elementRef.nativeElement.attributes;\n const attributes = [];\n\n for (let attr, i = 0; i < attrs.length; i++) {\n attr = attrs[i];\n\n if (attr.nodeName.match('^data-')) {\n attributes.push({\n name: this.camelCaseAttribute(attr.nodeName),\n value: attr.nodeValue\n });\n }\n }\n\n return attributes;\n }\n\n camelCaseAttribute(attribute: string) {\n const attr = attribute.replace('data-', '');\n const chunks = attr.split('-');\n\n if (chunks.length > 1) {\n return chunks[0] + chunks.slice(1).map(chunk => chunk.replace(/^\\w/, c => c.toUpperCase())).join('');\n }\n\n return attr;\n }\n\n listenToAttributeChanges() {\n const observer = new MutationObserver(mutations => {\n mutations.forEach(mutation => {\n if (mutation.type === 'attributes') {\n const attributes = this.getElementAttributes();\n this.setAttributes(attributes);\n }\n });\n });\n\n observer.observe(this.elementRef.nativeElement, {\n attributes: true\n });\n }\n\n ngOnDestroy() {\n this.componentRef.destroy();\n this.ngElementEventsSubscription.unsubscribe();\n }\n}","import { NgModule, Injector, ModuleWithProviders } from '@angular/core';\nimport { createCustomElement } from '@angular/elements';\nimport { NgxElementComponent } from './ngx-element.component';\nimport { LAZY_CMPS_PATH_TOKEN } from './tokens';\n\n@NgModule({\n declarations: [NgxElementComponent],\n entryComponents: [NgxElementComponent]\n})\nexport class NgxElementModule {\n\n constructor(private injector: Injector) {\n const ngxElement = createCustomElement(NgxElementComponent, { injector });\n customElements.define('ngx-element', ngxElement);\n }\n\n static forRoot(modulePaths: any[]): ModuleWithProviders<NgxElementModule> {\n return {\n ngModule: NgxElementModule,\n providers: [\n {\n provide: LAZY_CMPS_PATH_TOKEN,\n useValue: modulePaths\n }\n ]\n };\n }\n\n ngDoBootstrap() {}\n}\n","/*\n * Public API Surface of ngx-element\n */\n\nexport * from './lib/ngx-element.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n\nexport {NgxElementComponent as ɵa} from './lib/ngx-element.component';\nexport {NgxElementService as ɵb} from './lib/ngx-element.service';\nexport {LAZY_CMPS_PATH_TOKEN as ɵc} from './lib/tokens';"],"names":[],"mappings":";;;;;AAGA;MACa,oBAAoB,GAAG,IAAI,cAAc,CAAC,uBAAuB;;MCIjE,iBAAiB;IAQ5B,YAEE,WAEG,EACK,QAAkB,EAClB,QAAkB;QADlB,aAAQ,GAAR,QAAQ,CAAU;Q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AiB;gBAC3B,QAAQ,EAAE;;GAET;aAEF;;;YAVO,iBAAiB;YAJvB,UAAU;;;uBAkBT,KAAK;wBACL,SAAS,SAAC,WAAW,EAAE,EAAC,IAAI,EAAE,gBAAgB,EAAC;;;MCvBrC,gBAAgB;IAE3B,YAAoB,QAAkB;QAAlB,aAAQ,GAAR,QAAQ,CAAU;QACpC,MAAM,UAAU,GAAG,mBAAmB,CAAC,mBAAmB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC1E,cAAc,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;KAClD;IAED,OAAO,OAAO,CAAC,WAAkB;QAC/B,OAAO;YACL,QAAQ,EAAE,gBAAgB;YAC1B,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,oBAAoB;oBAC7B,QAAQ,EAAE,WAAW;iBACtB;aACF;SACF,CAAC;KACH;IAED,aAAa,MAAK;;;YAvBnB,QAAQ,SAAC;gBACR,YAAY,EAAE,CAAC,mBAAmB,CAAC;gBACnC,eAAe,EAAE,CAAC,mBAAmB,CAAC;aACvC;;;YARkB,QAAQ;;;ACA3B;;;;ACAA;;;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ComponentRef, OnInit, Type, ComponentFactoryResolver, OnDestroy, ElementRef, Injector, ReflectiveInjector } from '@angular/core';
|
|
2
|
+
import { NgxElementService } from './ngx-element.service';
|
|
3
|
+
export declare class NgxElementComponent implements OnInit, OnDestroy {
|
|
4
|
+
private ngxElementService;
|
|
5
|
+
private elementRef;
|
|
6
|
+
private ngElementEventsSubscription;
|
|
7
|
+
selector: string;
|
|
8
|
+
container: any;
|
|
9
|
+
componentRef: ComponentRef<any>;
|
|
10
|
+
componentToLoad: Type<any>;
|
|
11
|
+
componentFactoryResolver: ComponentFactoryResolver;
|
|
12
|
+
injector: Injector;
|
|
13
|
+
refInjector: ReflectiveInjector;
|
|
14
|
+
constructor(ngxElementService: NgxElementService, elementRef: ElementRef);
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to event emitters of a lazy loaded and dynamically instantiated Angular component
|
|
17
|
+
* and dispatch them as Custom Events on the NgxElementComponent that is used in a template.
|
|
18
|
+
*/
|
|
19
|
+
private setProxiedOutputs;
|
|
20
|
+
ngOnInit(): void;
|
|
21
|
+
createComponent(attributes: any): void;
|
|
22
|
+
setAttributes(attributes: any): void;
|
|
23
|
+
getElementAttributes(): any[];
|
|
24
|
+
camelCaseAttribute(attribute: string): string;
|
|
25
|
+
listenToAttributeChanges(): void;
|
|
26
|
+
ngOnDestroy(): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Type, Compiler, Injector, ComponentFactoryResolver } from '@angular/core';
|
|
2
|
+
import { LazyComponentDef } from './tokens';
|
|
3
|
+
import { LazyCmpLoadedEvent } from './lazy-component-loaded-event';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
export declare class NgxElementService {
|
|
6
|
+
private compiler;
|
|
7
|
+
private injector;
|
|
8
|
+
private componentsToLoad;
|
|
9
|
+
private loadedComponents;
|
|
10
|
+
private elementsLoading;
|
|
11
|
+
injectors: Map<Type<any>, Injector>;
|
|
12
|
+
componentFactoryResolvers: Map<Type<any>, ComponentFactoryResolver>;
|
|
13
|
+
constructor(modulePaths: {
|
|
14
|
+
selector: string;
|
|
15
|
+
}[], compiler: Compiler, injector: Injector);
|
|
16
|
+
receiveContext(component: Type<any>, injector: Injector): void;
|
|
17
|
+
getInjector(component: Type<any>): Injector;
|
|
18
|
+
getComponentFactoryResolver(component: Type<any>): ComponentFactoryResolver;
|
|
19
|
+
getComponentsToLoad(): Map<string, LazyComponentDef>;
|
|
20
|
+
getComponentToLoad(selector: string): Observable<LazyCmpLoadedEvent>;
|
|
21
|
+
/**
|
|
22
|
+
* Allows to lazy load a component given its selector.
|
|
23
|
+
* If the component selector has been registered, it's according module
|
|
24
|
+
* will be fetched lazily
|
|
25
|
+
* @param componentTag selector of the component to load
|
|
26
|
+
*/
|
|
27
|
+
loadComponent(componentSelector: string): Promise<LazyCmpLoadedEvent>;
|
|
28
|
+
}
|
package/lib/tokens.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { LoadChildrenCallback } from '@angular/router';
|
|
3
|
+
export declare const LAZY_CMPS_PATH_TOKEN: InjectionToken<unknown>;
|
|
4
|
+
export interface LazyComponentDef {
|
|
5
|
+
selector: string;
|
|
6
|
+
loadChildren: LoadChildrenCallback;
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zdigambar/ngx-element",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A simple way to lazy load Angular components in non-angular projects",
|
|
5
|
+
"author": "Digambar Zurkale",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/zdigambar/dz-ngx-element.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/zdigambar/dz-ngx-element/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/zdigambar/dz-ngx-element",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"angular",
|
|
16
|
+
"elements",
|
|
17
|
+
"angular elements",
|
|
18
|
+
"web components",
|
|
19
|
+
"lazy loading",
|
|
20
|
+
"non-angular"
|
|
21
|
+
],
|
|
22
|
+
"licence": "MIT",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@angular/common": "~10.2.5",
|
|
25
|
+
"@angular/core": "~10.2.5",
|
|
26
|
+
"@angular/elements": "~10.2.5"
|
|
27
|
+
},
|
|
28
|
+
"main": "bundles/zdigambar-ngx-element.umd.js",
|
|
29
|
+
"module": "fesm2015/zdigambar-ngx-element.js",
|
|
30
|
+
"es2015": "fesm2015/zdigambar-ngx-element.js",
|
|
31
|
+
"esm2015": "esm2015/zdigambar-ngx-element.js",
|
|
32
|
+
"fesm2015": "fesm2015/zdigambar-ngx-element.js",
|
|
33
|
+
"typings": "zdigambar-ngx-element.d.ts",
|
|
34
|
+
"metadata": "zdigambar-ngx-element.metadata.json",
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"tslib": "^1.10.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/public-api.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/ngx-element.module';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated bundle index. Do not edit.
|
|
3
|
+
*/
|
|
4
|
+
export * from './public-api';
|
|
5
|
+
export { NgxElementComponent as ɵa } from './lib/ngx-element.component';
|
|
6
|
+
export { NgxElementService as ɵb } from './lib/ngx-element.service';
|
|
7
|
+
export { LAZY_CMPS_PATH_TOKEN as ɵc } from './lib/tokens';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"__symbolic":"module","version":4,"metadata":{"NgxElementModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":5,"character":1},"arguments":[{"declarations":[{"__symbolic":"reference","name":"ɵa"}],"entryComponents":[{"__symbolic":"reference","name":"ɵa"}]}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"Injector","line":11,"character":32}]}],"ngDoBootstrap":[{"__symbolic":"method"}]},"statics":{"forRoot":{"__symbolic":"function","parameters":["modulePaths"],"value":{"ngModule":{"__symbolic":"reference","name":"NgxElementModule"},"providers":[{"provide":{"__symbolic":"reference","name":"ɵc"},"useValue":{"__symbolic":"reference","name":"modulePaths"}}]}}}},"ɵa":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":21,"character":1},"arguments":[{"selector":"lib-ngx-element","template":"\n <ng-template #container></ng-template>\n ","styles":[]}]}],"members":{"selector":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":31,"character":3}}]}],"container":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild","line":32,"character":3},"arguments":["container",{"read":{"__symbolic":"reference","module":"@angular/core","name":"ViewContainerRef","line":32,"character":33}}]}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"ɵb"},{"__symbolic":"reference","module":"@angular/core","name":"ElementRef","line":42,"character":24}]}],"setProxiedOutputs":[{"__symbolic":"method"}],"ngOnInit":[{"__symbolic":"method"}],"createComponent":[{"__symbolic":"method"}],"setAttributes":[{"__symbolic":"method"}],"getElementAttributes":[{"__symbolic":"method"}],"camelCaseAttribute":[{"__symbolic":"method"}],"listenToAttributeChanges":[{"__symbolic":"method"}],"ngOnDestroy":[{"__symbolic":"method"}]}},"ɵb":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":5,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":17,"character":5},"arguments":[{"__symbolic":"reference","name":"ɵc"}]}],null,null],"parameters":[{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"error","message":"Expression form not supported","line":18,"character":17,"module":"./lib/ngx-element.service"}]},{"__symbolic":"reference","module":"@angular/core","name":"Compiler","line":21,"character":22},{"__symbolic":"reference","module":"@angular/core","name":"Injector","line":22,"character":22}]}],"receiveContext":[{"__symbolic":"method"}],"getInjector":[{"__symbolic":"method"}],"getComponentFactoryResolver":[{"__symbolic":"method"}],"getComponentsToLoad":[{"__symbolic":"method"}],"getComponentToLoad":[{"__symbolic":"method"}],"loadComponent":[{"__symbolic":"method"}]},"statics":{"ɵprov":{}}},"ɵc":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":4,"character":40},"arguments":["ngx-lazy-cmp-registry"]}},"origins":{"NgxElementModule":"./lib/ngx-element.module","ɵa":"./lib/ngx-element.component","ɵb":"./lib/ngx-element.service","ɵc":"./lib/tokens"},"importAs":"@zdigambar/ngx-element"}
|