@veloceapps/sdk 7.0.1-0 → 7.0.1-2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ import { __decorate, __param, __metadata } 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 i2 from '@veloceapps/sdk/core';
7
7
  import { ConfigurationService, LineItemWorker, generateLineItem, getAttributeValue, QuoteDraftService, FlowConfigurationService, ProductImagesService, ContextService, lineItemUtils, SdkCoreModule, UI_DEFINITION_VERSION } from '@veloceapps/sdk/core';
8
8
  import * as i3 from 'primeng/api';
@@ -261,8 +261,8 @@ const CMS_COMPILATION_SERVICE = new InjectionToken('VENDOR_MAP');
261
261
  class RuntimeService {
262
262
  constructor(injector) {
263
263
  this.injector = injector;
264
- this.modules = [];
265
- this.componentFactories = {};
264
+ this.moduleRefs = [];
265
+ this.componentTypes = {};
266
266
  this.applicationTree = [];
267
267
  this.isInitialized$ = new BehaviorSubject(false);
268
268
  this.updated$ = new Subject();
@@ -275,7 +275,11 @@ class RuntimeService {
275
275
  }
276
276
  return this.compilationService.compileUIDefinition$(uiDefinition).pipe(map(result => {
277
277
  this.applicationTree = result.elements;
278
- this.addComponentFactories(result.module.componentFactories);
278
+ this.componentTypes = {
279
+ ...this.componentTypes,
280
+ ...result.componentTypes,
281
+ };
282
+ this.moduleRefs.push(result.moduleRef);
279
283
  return result.elements;
280
284
  }), tap(() => this.isInitialized$.next(true)));
281
285
  }
@@ -301,24 +305,26 @@ class RuntimeService {
301
305
  return this.updated$.pipe(startWith(undefined), map(() => findElementByPath(this.applicationTree, path)), distinctUntilChanged());
302
306
  }
303
307
  clear() {
304
- this.compilationService.clearModuleCache(this.modules);
305
- this.modules = [];
308
+ this.compilationService.clear();
309
+ this.moduleRefs.forEach(m => m.destroy());
310
+ this.moduleRefs = [];
306
311
  this.applicationTree = [];
307
- this.componentFactories = {};
312
+ this.componentTypes = {};
308
313
  this.isInitialized$.next(false);
309
314
  }
310
315
  addElement$(operation) {
311
316
  return this.compilationService.compileElement$(operation.value).pipe(map(result => {
312
- this.addComponentFactories(result.module.componentFactories);
317
+ this.componentTypes = {
318
+ ...this.componentTypes,
319
+ ...result.componentTypes,
320
+ };
321
+ this.moduleRefs.push(result.moduleRef);
313
322
  applyPatch(this.applicationTree, [{ ...operation, value: result.elements[0] }]);
314
323
  }));
315
324
  }
316
325
  deleteElement(operation) {
317
326
  applyPatch(this.applicationTree, [operation]);
318
327
  }
319
- addComponentFactories(list) {
320
- list.forEach(item => (this.componentFactories[item.componentType.path] = item));
321
- }
322
328
  }
323
329
  RuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: RuntimeService, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
324
330
  RuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: RuntimeService });
@@ -554,7 +560,7 @@ class ElementRendererComponent {
554
560
  }
555
561
  ngOnInit() {
556
562
  this.elementContext.metadata = this.meta;
557
- this.factory = this.meta.path ? this.runtimeService.componentFactories[this.meta.path] : undefined;
563
+ this.type = this.meta.path ? this.runtimeService.componentTypes[this.meta.path] : undefined;
558
564
  this.createComponents();
559
565
  }
560
566
  ngOnDestroy() {
@@ -622,43 +628,52 @@ class ElementRendererComponent {
622
628
  });
623
629
  }
624
630
  processChildren(children) {
625
- const refs = children.reduce((acc, data, index) => {
626
- const key = String(data?.id ?? UUID.UUID());
627
- const existingRef = this.refs[key];
628
- const ref = existingRef ?? this.createComponent(data, index);
629
- if (existingRef) {
630
- this.updateComponent(existingRef, data, index);
631
- }
632
- return ref ? { ...acc, [key]: ref } : acc;
633
- }, {});
634
- const existingKeys = Object.keys(this.refs);
635
- const newKeys = Object.keys(refs);
636
- pull(existingKeys, ...newKeys).forEach(key => {
637
- this.destroyComponent(key);
631
+ this.runtimeService.moduleRefs[0].injector.runInContext(() => {
632
+ const refs = children.reduce((acc, data, index) => {
633
+ const key = String(data?.id ?? UUID.UUID());
634
+ const existingRef = this.refs[key];
635
+ const ref = existingRef ?? this.createComponent(data, index);
636
+ if (existingRef) {
637
+ this.updateComponent(existingRef, data, index);
638
+ }
639
+ return ref ? { ...acc, [key]: ref } : acc;
640
+ }, {});
641
+ const existingKeys = Object.keys(this.refs);
642
+ const newKeys = Object.keys(refs);
643
+ pull(existingKeys, ...newKeys).forEach(key => {
644
+ this.destroyComponent(key);
645
+ });
646
+ this.refs = refs;
647
+ this.cdr.detectChanges();
638
648
  });
639
- this.refs = refs;
640
- this.cdr.detectChanges();
641
649
  }
642
650
  getParentLineItem$(parentComp) {
643
651
  const parentRefs = Object.values(parentComp?.refs ?? {});
644
652
  const parentRef = parentRefs.find(ref => ref?.location.nativeElement?.contains(this.elementRef.nativeElement));
645
- const parentModel$ = parentRef?.instance.model$;
653
+ let parentModel$;
654
+ if (parentRef?.instance instanceof ElementComponent) {
655
+ parentModel$ = parentRef?.instance.model$;
656
+ }
646
657
  return parentModel$ ?? this.configurationService.get();
647
658
  }
648
659
  createComponent(data, index) {
649
- if (!this.factory) {
660
+ if (!this.type) {
650
661
  return;
651
662
  }
652
- const componentRef = this.el?.createComponent(this.factory, index);
663
+ const componentRef = this.el?.createComponent(this.type, { index });
653
664
  if (componentRef) {
654
665
  componentRef.location.nativeElement.setAttribute('name', this.meta.name);
655
666
  componentRef.location.nativeElement.setAttribute('path', this.meta.path);
656
- componentRef.instance?.model$.next(data);
667
+ if (componentRef.instance instanceof ElementComponent) {
668
+ componentRef.instance.model$.next(data);
669
+ }
657
670
  }
658
671
  return componentRef;
659
672
  }
660
673
  updateComponent(ref, data, index) {
661
- ref.instance.model$.next(data);
674
+ if (ref.instance instanceof ElementComponent) {
675
+ ref.instance.model$.next(data);
676
+ }
662
677
  if (this.el && this.el.indexOf(ref.hostView) !== index) {
663
678
  this.el.move(ref.hostView, index);
664
679
  }
@@ -863,7 +878,7 @@ class ElementChildrenComponent {
863
878
  }
864
879
  }
865
880
  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 });
866
- 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 });
881
+ 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 });
867
882
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenComponent, decorators: [{
868
883
  type: Component,
869
884
  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"] }]
@@ -872,13 +887,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
872
887
  class ElementChildrenModule {
873
888
  }
874
889
  ElementChildrenModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
875
- ElementChildrenModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, declarations: [ElementChildrenComponent], imports: [LetDirectiveModule, ElementRendererModule, ElementDropHandleModule], exports: [ElementChildrenComponent] });
876
- ElementChildrenModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, imports: [LetDirectiveModule, ElementRendererModule, ElementDropHandleModule] });
890
+ 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] });
891
+ ElementChildrenModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, imports: [CommonModule, LetDirectiveModule, ElementRendererModule, ElementDropHandleModule] });
877
892
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ElementChildrenModule, decorators: [{
878
893
  type: NgModule,
879
894
  args: [{
880
895
  declarations: [ElementChildrenComponent],
881
- imports: [LetDirectiveModule, ElementRendererModule, ElementDropHandleModule],
896
+ imports: [CommonModule, LetDirectiveModule, ElementRendererModule, ElementDropHandleModule],
882
897
  exports: [ElementChildrenComponent],
883
898
  }]
884
899
  }] });
@@ -925,6 +940,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
925
940
  }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: TemplatesService }]; }, propDecorators: { customTemplate: [{
926
941
  type: Input
927
942
  }] } });
943
+ class CustomTemplateDirectiveModule {
944
+ }
945
+ CustomTemplateDirectiveModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CustomTemplateDirectiveModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
946
+ CustomTemplateDirectiveModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: CustomTemplateDirectiveModule, declarations: [CustomTemplateDirective], exports: [CustomTemplateDirective] });
947
+ CustomTemplateDirectiveModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CustomTemplateDirectiveModule });
948
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CustomTemplateDirectiveModule, decorators: [{
949
+ type: NgModule,
950
+ args: [{
951
+ declarations: [CustomTemplateDirective],
952
+ exports: [CustomTemplateDirective],
953
+ }]
954
+ }] });
928
955
 
929
956
  class IOPlugin {
930
957
  constructor(host) {
@@ -1614,7 +1641,10 @@ class ElementsResolver {
1614
1641
  this.renderableElements = this.getRenderableElements(this.elements);
1615
1642
  }
1616
1643
  getNgComponents() {
1617
- return this.renderableElements.map(el => this.resolveElement(el)).filter(isDefined);
1644
+ return this.renderableElements.filter(isDefined).reduce((trunk, el) => ({
1645
+ ...trunk,
1646
+ [el.path]: this.resolveElement(el),
1647
+ }), {});
1618
1648
  }
1619
1649
  transpile(el) {
1620
1650
  if (!el.script) {
@@ -1795,7 +1825,6 @@ class FederatedComponent {
1795
1825
  constructor(injector) {
1796
1826
  this.injector = injector;
1797
1827
  this.isLoading$ = new BehaviorSubject(false);
1798
- // configs
1799
1828
  this.suppressLoading = defaultOptions.suppressLoading;
1800
1829
  this.loadingLabel = defaultOptions.loadingLabel;
1801
1830
  }
@@ -1861,11 +1890,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
1861
1890
  }] });
1862
1891
 
1863
1892
  class CompilationService {
1864
- constructor(compiler) {
1865
- this.compiler = compiler;
1893
+ constructor(injector) {
1894
+ this.injector = injector;
1866
1895
  }
1867
1896
  compileUIDefinition$(uiDefinition) {
1868
- return of([]).pipe(switchMap(() => {
1897
+ return of([]).pipe(map(() => {
1869
1898
  const { children, pages, components, ...uiDefinitionMeta } = uiDefinition;
1870
1899
  this.uiDefinitionMeta = uiDefinitionMeta;
1871
1900
  const elements = [...(children ?? []), ...(pages ?? [])];
@@ -1873,35 +1902,35 @@ class CompilationService {
1873
1902
  const metadata = elements.map(element => elementToMetadata(element));
1874
1903
  const sharedMetadata = sharedElements.map(element => elementToMetadata(element));
1875
1904
  this.elementsResolver = new ElementsResolver(uiDefinition, metadata, sharedMetadata);
1876
- const module = this.getModule(this.elementsResolver.getNgComponents());
1877
- return combineLatest([
1878
- from(this.compiler.compileModuleAndAllComponentsAsync(module)),
1879
- of(this.elementsResolver),
1880
- ]);
1881
- }), map(([module, elementsResolver]) => ({ module, elements: elementsResolver.elements })));
1905
+ const componentTypes = this.elementsResolver.getNgComponents();
1906
+ const module = this.getModule(componentTypes);
1907
+ return {
1908
+ moduleRef: createNgModule(module, this.injector),
1909
+ elements: this.elementsResolver?.elements ?? [],
1910
+ componentTypes,
1911
+ };
1912
+ }));
1882
1913
  }
1883
1914
  compileElement$(element) {
1884
1915
  if (!this.uiDefinitionMeta) {
1885
1916
  throw 'No UI Definition context';
1886
1917
  }
1887
- return of(this.uiDefinitionMeta).pipe(switchMap(uiDefinition => {
1918
+ return of(this.uiDefinitionMeta).pipe(map(uiDefinition => {
1888
1919
  const elementsResolver = this.elementsResolver ?? new ElementsResolver(uiDefinition, []);
1889
1920
  elementsResolver.addElement(element);
1890
- const module = this.getModule(elementsResolver.getNgComponents());
1891
- return combineLatest([from(this.compiler.compileModuleAndAllComponentsAsync(module)), of(elementsResolver)]);
1892
- }), map(([module, elementsResolver]) => ({ module, elements: elementsResolver.elements })));
1921
+ const componentTypes = elementsResolver.getNgComponents();
1922
+ const module = this.getModule(componentTypes);
1923
+ return {
1924
+ moduleRef: createNgModule(module, this.injector),
1925
+ elements: this.elementsResolver?.elements ?? [],
1926
+ componentTypes,
1927
+ };
1928
+ }));
1893
1929
  }
1894
- clearModuleCache(modules) {
1895
- modules.forEach(module => this.compiler.clearCacheFor(module));
1930
+ clear() {
1896
1931
  this.uiDefinitionMeta = undefined;
1897
1932
  }
1898
1933
  getModule(components) {
1899
- const staticComponents = [
1900
- ElementChildrenComponent,
1901
- ElementRendererComponent,
1902
- ElementDropHandleComponent,
1903
- CustomTemplateDirective,
1904
- ];
1905
1934
  let DynamicModule = class DynamicModule {
1906
1935
  };
1907
1936
  DynamicModule = __decorate([
@@ -1910,23 +1939,27 @@ class CompilationService {
1910
1939
  CommonModule,
1911
1940
  FormsModule,
1912
1941
  ReactiveFormsModule,
1913
- FederatedModule,
1914
1942
  DragDropModule,
1915
1943
  DndModule,
1916
1944
  ScrollingModule,
1945
+ ElementChildrenModule,
1946
+ ElementRendererModule,
1947
+ ElementDropHandleModule,
1948
+ CustomTemplateDirectiveModule,
1949
+ FederatedModule,
1917
1950
  ],
1918
- declarations: [...staticComponents, ...components],
1951
+ declarations: Object.values(components),
1919
1952
  jit: true,
1920
1953
  })
1921
1954
  ], DynamicModule);
1922
1955
  return DynamicModule;
1923
1956
  }
1924
1957
  }
1925
- CompilationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CompilationService, deps: [{ token: i0.Compiler }], target: i0.ɵɵFactoryTarget.Injectable });
1958
+ CompilationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CompilationService, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
1926
1959
  CompilationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CompilationService });
1927
1960
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CompilationService, decorators: [{
1928
1961
  type: Injectable
1929
- }], ctorParameters: function () { return [{ type: i0.Compiler }]; } });
1962
+ }], ctorParameters: function () { return [{ type: i0.Injector }]; } });
1930
1963
 
1931
1964
  class RuntimeModule {
1932
1965
  }