@veloceapps/sdk 7.0.1-0 → 7.0.1-2

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.
@@ -2,7 +2,7 @@ import { __decorate, __param, __metadata, __rest } from 'tslib';
2
2
  import * as i0 from '@angular/core';
3
3
  import { InjectionToken, Component, ChangeDetectionStrategy, Inject, Injector, Injectable, ViewContainerRef, SkipSelf, ViewChild, Input, ViewEncapsulation, NgModule, Directive, ElementRef, createNgModule } from '@angular/core';
4
4
  import * as rxjs from 'rxjs';
5
- import { BehaviorSubject, Subject, of, map, tap, switchMap, startWith, distinctUntilChanged, filter, ReplaySubject, noop, take, Observable, takeUntil, forkJoin, catchError, combineLatest, from } from 'rxjs';
5
+ import { BehaviorSubject, Subject, of, map, tap, switchMap, startWith, distinctUntilChanged, filter, ReplaySubject, noop, take, Observable, takeUntil, forkJoin, catchError, combineLatest } from 'rxjs';
6
6
  import * as lodash from 'lodash';
7
7
  import { compact, isArray, pull, merge, omit, flatten, set, kebabCase, cloneDeep } from 'lodash';
8
8
  import { applyPatch } from 'rfc6902';
@@ -311,8 +311,8 @@ const CMS_COMPILATION_SERVICE = new InjectionToken('VENDOR_MAP');
311
311
  class RuntimeService {
312
312
  constructor(injector) {
313
313
  this.injector = injector;
314
- this.modules = [];
315
- this.componentFactories = {};
314
+ this.moduleRefs = [];
315
+ this.componentTypes = {};
316
316
  this.applicationTree = [];
317
317
  this.isInitialized$ = new BehaviorSubject(false);
318
318
  this.updated$ = new Subject();
@@ -325,7 +325,8 @@ class RuntimeService {
325
325
  }
326
326
  return this.compilationService.compileUIDefinition$(uiDefinition).pipe(map(result => {
327
327
  this.applicationTree = result.elements;
328
- this.addComponentFactories(result.module.componentFactories);
328
+ this.componentTypes = Object.assign(Object.assign({}, this.componentTypes), result.componentTypes);
329
+ this.moduleRefs.push(result.moduleRef);
329
330
  return result.elements;
330
331
  }), tap(() => this.isInitialized$.next(true)));
331
332
  }
@@ -351,24 +352,23 @@ class RuntimeService {
351
352
  return this.updated$.pipe(startWith(undefined), map(() => findElementByPath(this.applicationTree, path)), distinctUntilChanged());
352
353
  }
353
354
  clear() {
354
- this.compilationService.clearModuleCache(this.modules);
355
- this.modules = [];
355
+ this.compilationService.clear();
356
+ this.moduleRefs.forEach(m => m.destroy());
357
+ this.moduleRefs = [];
356
358
  this.applicationTree = [];
357
- this.componentFactories = {};
359
+ this.componentTypes = {};
358
360
  this.isInitialized$.next(false);
359
361
  }
360
362
  addElement$(operation) {
361
363
  return this.compilationService.compileElement$(operation.value).pipe(map(result => {
362
- this.addComponentFactories(result.module.componentFactories);
364
+ this.componentTypes = Object.assign(Object.assign({}, this.componentTypes), result.componentTypes);
365
+ this.moduleRefs.push(result.moduleRef);
363
366
  applyPatch(this.applicationTree, [Object.assign(Object.assign({}, operation), { value: result.elements[0] })]);
364
367
  }));
365
368
  }
366
369
  deleteElement(operation) {
367
370
  applyPatch(this.applicationTree, [operation]);
368
371
  }
369
- addComponentFactories(list) {
370
- list.forEach(item => (this.componentFactories[item.componentType.path] = item));
371
- }
372
372
  }
373
373
  RuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: RuntimeService, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
374
374
  RuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: RuntimeService });
@@ -556,7 +556,7 @@ class ElementRendererComponent {
556
556
  }
557
557
  ngOnInit() {
558
558
  this.elementContext.metadata = this.meta;
559
- this.factory = this.meta.path ? this.runtimeService.componentFactories[this.meta.path] : undefined;
559
+ this.type = this.meta.path ? this.runtimeService.componentTypes[this.meta.path] : undefined;
560
560
  this.createComponents();
561
561
  }
562
562
  ngOnDestroy() {
@@ -626,46 +626,55 @@ class ElementRendererComponent {
626
626
  });
627
627
  }
628
628
  processChildren(children) {
629
- const refs = children.reduce((acc, data, index) => {
630
- var _a;
631
- const key = String((_a = data === null || data === void 0 ? void 0 : data.id) !== null && _a !== void 0 ? _a : UUID.UUID());
632
- const existingRef = this.refs[key];
633
- const ref = existingRef !== null && existingRef !== void 0 ? existingRef : this.createComponent(data, index);
634
- if (existingRef) {
635
- this.updateComponent(existingRef, data, index);
636
- }
637
- return ref ? Object.assign(Object.assign({}, acc), { [key]: ref }) : acc;
638
- }, {});
639
- const existingKeys = Object.keys(this.refs);
640
- const newKeys = Object.keys(refs);
641
- pull(existingKeys, ...newKeys).forEach(key => {
642
- this.destroyComponent(key);
629
+ this.runtimeService.moduleRefs[0].injector.runInContext(() => {
630
+ const refs = children.reduce((acc, data, index) => {
631
+ var _a;
632
+ const key = String((_a = data === null || data === void 0 ? void 0 : data.id) !== null && _a !== void 0 ? _a : UUID.UUID());
633
+ const existingRef = this.refs[key];
634
+ const ref = existingRef !== null && existingRef !== void 0 ? existingRef : this.createComponent(data, index);
635
+ if (existingRef) {
636
+ this.updateComponent(existingRef, data, index);
637
+ }
638
+ return ref ? Object.assign(Object.assign({}, acc), { [key]: ref }) : acc;
639
+ }, {});
640
+ const existingKeys = Object.keys(this.refs);
641
+ const newKeys = Object.keys(refs);
642
+ pull(existingKeys, ...newKeys).forEach(key => {
643
+ this.destroyComponent(key);
644
+ });
645
+ this.refs = refs;
646
+ this.cdr.detectChanges();
643
647
  });
644
- this.refs = refs;
645
- this.cdr.detectChanges();
646
648
  }
647
649
  getParentLineItem$(parentComp) {
648
650
  var _a;
649
651
  const parentRefs = Object.values((_a = parentComp === null || parentComp === void 0 ? void 0 : parentComp.refs) !== null && _a !== void 0 ? _a : {});
650
652
  const parentRef = parentRefs.find(ref => { var _a; return (_a = ref === null || ref === void 0 ? void 0 : ref.location.nativeElement) === null || _a === void 0 ? void 0 : _a.contains(this.elementRef.nativeElement); });
651
- const parentModel$ = parentRef === null || parentRef === void 0 ? void 0 : parentRef.instance.model$;
653
+ let parentModel$;
654
+ if ((parentRef === null || parentRef === void 0 ? void 0 : parentRef.instance) instanceof ElementComponent) {
655
+ parentModel$ = parentRef === null || parentRef === void 0 ? void 0 : parentRef.instance.model$;
656
+ }
652
657
  return parentModel$ !== null && parentModel$ !== void 0 ? parentModel$ : this.configurationService.get();
653
658
  }
654
659
  createComponent(data, index) {
655
- var _a, _b;
656
- if (!this.factory) {
660
+ var _a;
661
+ if (!this.type) {
657
662
  return;
658
663
  }
659
- const componentRef = (_a = this.el) === null || _a === void 0 ? void 0 : _a.createComponent(this.factory, index);
664
+ const componentRef = (_a = this.el) === null || _a === void 0 ? void 0 : _a.createComponent(this.type, { index });
660
665
  if (componentRef) {
661
666
  componentRef.location.nativeElement.setAttribute('name', this.meta.name);
662
667
  componentRef.location.nativeElement.setAttribute('path', this.meta.path);
663
- (_b = componentRef.instance) === null || _b === void 0 ? void 0 : _b.model$.next(data);
668
+ if (componentRef.instance instanceof ElementComponent) {
669
+ componentRef.instance.model$.next(data);
670
+ }
664
671
  }
665
672
  return componentRef;
666
673
  }
667
674
  updateComponent(ref, data, index) {
668
- ref.instance.model$.next(data);
675
+ if (ref.instance instanceof ElementComponent) {
676
+ ref.instance.model$.next(data);
677
+ }
669
678
  if (this.el && this.el.indexOf(ref.hostView) !== index) {
670
679
  this.el.move(ref.hostView, index);
671
680
  }
@@ -877,7 +886,7 @@ class ElementChildrenComponent {
877
886
  }
878
887
  }
879
888
  ElementChildrenComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenComponent, deps: [{ token: ElementContextService }, { token: RuntimeService }, { token: RuntimeEditorService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
880
- ElementChildrenComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.8", type: ElementChildrenComponent, selector: "element-children", ngImport: i0, template: "<ng-container *ngIf=\"metadata$ | async as metadata\">\n <vl-element-drop-handle *ngIf=\"dragMode$ | async\" [index]=\"0\" [parentPath]=\"metadata.path\"></vl-element-drop-handle>\n <ng-container *ngFor=\"let child of metadata.children; let i = index\">\n <vl-cms-element-renderer [meta]=\"child\"></vl-cms-element-renderer>\n <vl-element-drop-handle\n *ngIf=\"dragMode$ | async\"\n [index]=\"i + 1\"\n [parentPath]=\"metadata.path\"\n ></vl-element-drop-handle>\n </ng-container>\n</ng-container>\n", styles: [":host{display:contents}\n"], dependencies: [{ kind: "component", type: ElementRendererComponent, selector: "vl-cms-element-renderer", inputs: ["meta"] }, { kind: "component", type: ElementDropHandleComponent, selector: "vl-element-drop-handle", inputs: ["index", "parentPath"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
889
+ ElementChildrenComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.8", type: ElementChildrenComponent, selector: "element-children", ngImport: i0, template: "<ng-container *ngIf=\"metadata$ | async as metadata\">\n <vl-element-drop-handle *ngIf=\"dragMode$ | async\" [index]=\"0\" [parentPath]=\"metadata.path\"></vl-element-drop-handle>\n <ng-container *ngFor=\"let child of metadata.children; let i = index\">\n <vl-cms-element-renderer [meta]=\"child\"></vl-cms-element-renderer>\n <vl-element-drop-handle\n *ngIf=\"dragMode$ | async\"\n [index]=\"i + 1\"\n [parentPath]=\"metadata.path\"\n ></vl-element-drop-handle>\n </ng-container>\n</ng-container>\n", styles: [":host{display:contents}\n"], dependencies: [{ kind: "directive", type: i5.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: ElementRendererComponent, selector: "vl-cms-element-renderer", inputs: ["meta"] }, { kind: "component", type: ElementDropHandleComponent, selector: "vl-element-drop-handle", inputs: ["index", "parentPath"] }, { kind: "pipe", type: i5.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
881
890
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenComponent, decorators: [{
882
891
  type: Component,
883
892
  args: [{ selector: 'element-children', changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-container *ngIf=\"metadata$ | async as metadata\">\n <vl-element-drop-handle *ngIf=\"dragMode$ | async\" [index]=\"0\" [parentPath]=\"metadata.path\"></vl-element-drop-handle>\n <ng-container *ngFor=\"let child of metadata.children; let i = index\">\n <vl-cms-element-renderer [meta]=\"child\"></vl-cms-element-renderer>\n <vl-element-drop-handle\n *ngIf=\"dragMode$ | async\"\n [index]=\"i + 1\"\n [parentPath]=\"metadata.path\"\n ></vl-element-drop-handle>\n </ng-container>\n</ng-container>\n", styles: [":host{display:contents}\n"] }]
@@ -886,13 +895,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
886
895
  class ElementChildrenModule {
887
896
  }
888
897
  ElementChildrenModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
889
- ElementChildrenModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, declarations: [ElementChildrenComponent], imports: [LetDirectiveModule, ElementRendererModule, ElementDropHandleModule], exports: [ElementChildrenComponent] });
890
- ElementChildrenModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, imports: [LetDirectiveModule, ElementRendererModule, ElementDropHandleModule] });
898
+ ElementChildrenModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, declarations: [ElementChildrenComponent], imports: [CommonModule, LetDirectiveModule, ElementRendererModule, ElementDropHandleModule], exports: [ElementChildrenComponent] });
899
+ ElementChildrenModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, imports: [CommonModule, LetDirectiveModule, ElementRendererModule, ElementDropHandleModule] });
891
900
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, decorators: [{
892
901
  type: NgModule,
893
902
  args: [{
894
903
  declarations: [ElementChildrenComponent],
895
- imports: [LetDirectiveModule, ElementRendererModule, ElementDropHandleModule],
904
+ imports: [CommonModule, LetDirectiveModule, ElementRendererModule, ElementDropHandleModule],
896
905
  exports: [ElementChildrenComponent],
897
906
  }]
898
907
  }] });
@@ -939,6 +948,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
939
948
  }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: TemplatesService }]; }, propDecorators: { customTemplate: [{
940
949
  type: Input
941
950
  }] } });
951
+ class CustomTemplateDirectiveModule {
952
+ }
953
+ CustomTemplateDirectiveModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CustomTemplateDirectiveModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
954
+ CustomTemplateDirectiveModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: CustomTemplateDirectiveModule, declarations: [CustomTemplateDirective], exports: [CustomTemplateDirective] });
955
+ CustomTemplateDirectiveModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CustomTemplateDirectiveModule });
956
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CustomTemplateDirectiveModule, decorators: [{
957
+ type: NgModule,
958
+ args: [{
959
+ declarations: [CustomTemplateDirective],
960
+ exports: [CustomTemplateDirective],
961
+ }]
962
+ }] });
942
963
 
943
964
  class IOPlugin {
944
965
  constructor(host) {
@@ -1615,7 +1636,7 @@ class ElementsResolver {
1615
1636
  this.renderableElements = this.getRenderableElements(this.elements);
1616
1637
  }
1617
1638
  getNgComponents() {
1618
- return this.renderableElements.map(el => this.resolveElement(el)).filter(isDefined);
1639
+ return this.renderableElements.filter(isDefined).reduce((trunk, el) => (Object.assign(Object.assign({}, trunk), { [el.path]: this.resolveElement(el) })), {});
1619
1640
  }
1620
1641
  transpile(el) {
1621
1642
  var _a;
@@ -1770,7 +1791,6 @@ class FederatedComponent {
1770
1791
  constructor(injector) {
1771
1792
  this.injector = injector;
1772
1793
  this.isLoading$ = new BehaviorSubject(false);
1773
- // configs
1774
1794
  this.suppressLoading = defaultOptions.suppressLoading;
1775
1795
  this.loadingLabel = defaultOptions.loadingLabel;
1776
1796
  }
@@ -1839,11 +1859,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
1839
1859
  }] });
1840
1860
 
1841
1861
  class CompilationService {
1842
- constructor(compiler) {
1843
- this.compiler = compiler;
1862
+ constructor(injector) {
1863
+ this.injector = injector;
1844
1864
  }
1845
1865
  compileUIDefinition$(uiDefinition) {
1846
- return of([]).pipe(switchMap(() => {
1866
+ return of([]).pipe(map(() => {
1867
+ var _a, _b;
1847
1868
  const { children, pages, components } = uiDefinition, uiDefinitionMeta = __rest(uiDefinition, ["children", "pages", "components"]);
1848
1869
  this.uiDefinitionMeta = uiDefinitionMeta;
1849
1870
  const elements = [...(children !== null && children !== void 0 ? children : []), ...(pages !== null && pages !== void 0 ? pages : [])];
@@ -1851,36 +1872,36 @@ class CompilationService {
1851
1872
  const metadata = elements.map(element => elementToMetadata(element));
1852
1873
  const sharedMetadata = sharedElements.map(element => elementToMetadata(element));
1853
1874
  this.elementsResolver = new ElementsResolver(uiDefinition, metadata, sharedMetadata);
1854
- const module = this.getModule(this.elementsResolver.getNgComponents());
1855
- return combineLatest([
1856
- from(this.compiler.compileModuleAndAllComponentsAsync(module)),
1857
- of(this.elementsResolver),
1858
- ]);
1859
- }), map(([module, elementsResolver]) => ({ module, elements: elementsResolver.elements })));
1875
+ const componentTypes = this.elementsResolver.getNgComponents();
1876
+ const module = this.getModule(componentTypes);
1877
+ return {
1878
+ moduleRef: createNgModule(module, this.injector),
1879
+ elements: (_b = (_a = this.elementsResolver) === null || _a === void 0 ? void 0 : _a.elements) !== null && _b !== void 0 ? _b : [],
1880
+ componentTypes,
1881
+ };
1882
+ }));
1860
1883
  }
1861
1884
  compileElement$(element) {
1862
1885
  if (!this.uiDefinitionMeta) {
1863
1886
  throw 'No UI Definition context';
1864
1887
  }
1865
- return of(this.uiDefinitionMeta).pipe(switchMap(uiDefinition => {
1866
- var _a;
1888
+ return of(this.uiDefinitionMeta).pipe(map(uiDefinition => {
1889
+ var _a, _b, _c;
1867
1890
  const elementsResolver = (_a = this.elementsResolver) !== null && _a !== void 0 ? _a : new ElementsResolver(uiDefinition, []);
1868
1891
  elementsResolver.addElement(element);
1869
- const module = this.getModule(elementsResolver.getNgComponents());
1870
- return combineLatest([from(this.compiler.compileModuleAndAllComponentsAsync(module)), of(elementsResolver)]);
1871
- }), map(([module, elementsResolver]) => ({ module, elements: elementsResolver.elements })));
1892
+ const componentTypes = elementsResolver.getNgComponents();
1893
+ const module = this.getModule(componentTypes);
1894
+ return {
1895
+ moduleRef: createNgModule(module, this.injector),
1896
+ elements: (_c = (_b = this.elementsResolver) === null || _b === void 0 ? void 0 : _b.elements) !== null && _c !== void 0 ? _c : [],
1897
+ componentTypes,
1898
+ };
1899
+ }));
1872
1900
  }
1873
- clearModuleCache(modules) {
1874
- modules.forEach(module => this.compiler.clearCacheFor(module));
1901
+ clear() {
1875
1902
  this.uiDefinitionMeta = undefined;
1876
1903
  }
1877
1904
  getModule(components) {
1878
- const staticComponents = [
1879
- ElementChildrenComponent,
1880
- ElementRendererComponent,
1881
- ElementDropHandleComponent,
1882
- CustomTemplateDirective,
1883
- ];
1884
1905
  let DynamicModule = class DynamicModule {
1885
1906
  };
1886
1907
  DynamicModule = __decorate([
@@ -1889,23 +1910,27 @@ class CompilationService {
1889
1910
  CommonModule,
1890
1911
  FormsModule,
1891
1912
  ReactiveFormsModule,
1892
- FederatedModule,
1893
1913
  DragDropModule,
1894
1914
  DndModule,
1895
1915
  ScrollingModule,
1916
+ ElementChildrenModule,
1917
+ ElementRendererModule,
1918
+ ElementDropHandleModule,
1919
+ CustomTemplateDirectiveModule,
1920
+ FederatedModule,
1896
1921
  ],
1897
- declarations: [...staticComponents, ...components],
1922
+ declarations: Object.values(components),
1898
1923
  jit: true,
1899
1924
  })
1900
1925
  ], DynamicModule);
1901
1926
  return DynamicModule;
1902
1927
  }
1903
1928
  }
1904
- CompilationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CompilationService, deps: [{ token: i0.Compiler }], target: i0.ɵɵFactoryTarget.Injectable });
1929
+ CompilationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CompilationService, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
1905
1930
  CompilationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CompilationService });
1906
1931
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CompilationService, decorators: [{
1907
1932
  type: Injectable
1908
- }], ctorParameters: function () { return [{ type: i0.Compiler }]; } });
1933
+ }], ctorParameters: function () { return [{ type: i0.Injector }]; } });
1909
1934
 
1910
1935
  class RuntimeModule {
1911
1936
  }