@veloceapps/sdk 6.0.0-32 → 6.0.0-33

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.
Files changed (79) hide show
  1. package/bundles/veloceapps-sdk-cms.umd.js +1214 -783
  2. package/bundles/veloceapps-sdk-cms.umd.js.map +1 -1
  3. package/bundles/veloceapps-sdk.umd.js +5 -5
  4. package/bundles/veloceapps-sdk.umd.js.map +1 -1
  5. package/cms/components/element-children/element-children.component.d.ts +13 -3
  6. package/cms/components/element-children/element-children.module.d.ts +4 -2
  7. package/cms/components/element-drop-handle/element-drop-handle.component.d.ts +12 -0
  8. package/cms/components/element-drop-handle/element-drop-handle.module.d.ts +9 -0
  9. package/cms/components/element-renderer/element-renderer.component.d.ts +3 -3
  10. package/cms/components/preview/index.d.ts +1 -0
  11. package/cms/components/preview/preview.component.d.ts +9 -8
  12. package/cms/components/preview/preview.module.d.ts +2 -1
  13. package/cms/components/preview/preview.types.d.ts +11 -0
  14. package/cms/index.d.ts +1 -0
  15. package/cms/launcher.module.d.ts +3 -1
  16. package/cms/modules/runtime/index.d.ts +2 -0
  17. package/cms/modules/runtime/runtime.module.d.ts +8 -0
  18. package/cms/modules/runtime/services/compilation.service.d.ts +18 -0
  19. package/cms/modules/runtime/services/runtime-editor.service.d.ts +18 -0
  20. package/cms/modules/runtime/services/runtime.service.d.ts +27 -0
  21. package/cms/modules/runtime/tokens.d.ts +3 -0
  22. package/cms/{types → modules/runtime/types}/compilation.types.d.ts +1 -1
  23. package/cms/modules/runtime/types/runtime.actions.d.ts +9 -0
  24. package/cms/plugins/element-hover.plugin.d.ts +32 -0
  25. package/cms/services/index.d.ts +0 -1
  26. package/cms/services/io-provider.service.d.ts +3 -3
  27. package/cms/types/common.types.d.ts +1 -1
  28. package/cms/types/configuration.types.d.ts +1 -0
  29. package/cms/types/index.d.ts +1 -1
  30. package/cms/utils/elements-resolver.d.ts +2 -1
  31. package/cms/utils/index.d.ts +1 -0
  32. package/cms/utils/path.utils.d.ts +0 -1
  33. package/cms/utils/ui-definition.utils.d.ts +6 -0
  34. package/esm2015/cms/cms.elements.js +17 -4
  35. package/esm2015/cms/components/element-children/element-children.component.js +23 -7
  36. package/esm2015/cms/components/element-children/element-children.module.js +6 -4
  37. package/esm2015/cms/components/element-drop-handle/element-drop-handle.component.js +32 -0
  38. package/esm2015/cms/components/element-drop-handle/element-drop-handle.module.js +19 -0
  39. package/esm2015/cms/components/element-renderer/element-renderer.component.js +7 -7
  40. package/esm2015/cms/components/preview/index.js +2 -1
  41. package/esm2015/cms/components/preview/preview.component.js +20 -35
  42. package/esm2015/cms/components/preview/preview.module.js +5 -4
  43. package/esm2015/cms/components/preview/preview.types.js +2 -0
  44. package/esm2015/cms/index.js +2 -1
  45. package/esm2015/cms/launcher.module.js +8 -7
  46. package/esm2015/cms/modules/runtime/index.js +3 -0
  47. package/esm2015/cms/modules/runtime/runtime.module.js +32 -0
  48. package/esm2015/cms/modules/runtime/services/compilation.service.js +81 -0
  49. package/esm2015/cms/modules/runtime/services/runtime-editor.service.js +27 -0
  50. package/esm2015/cms/modules/runtime/services/runtime.service.js +74 -0
  51. package/esm2015/cms/modules/runtime/tokens.js +3 -0
  52. package/esm2015/cms/modules/runtime/types/compilation.types.js +2 -0
  53. package/esm2015/cms/modules/runtime/types/runtime.actions.js +2 -0
  54. package/esm2015/cms/plugins/configuration.plugin.js +9 -1
  55. package/esm2015/cms/plugins/element-hover.plugin.js +157 -0
  56. package/esm2015/cms/services/index.js +1 -2
  57. package/esm2015/cms/services/io-provider.service.js +7 -7
  58. package/esm2015/cms/types/common.types.js +1 -1
  59. package/esm2015/cms/types/configuration.types.js +1 -1
  60. package/esm2015/cms/types/index.js +2 -2
  61. package/esm2015/cms/utils/elements-resolver.js +13 -6
  62. package/esm2015/cms/utils/index.js +2 -1
  63. package/esm2015/cms/utils/path.utils.js +2 -13
  64. package/esm2015/cms/utils/ui-definition.utils.js +82 -0
  65. package/esm2015/src/components/doc-gen/doc-gen.component.js +1 -1
  66. package/esm2015/src/pages/catalog/catalog.component.js +1 -1
  67. package/esm2015/src/pages/product/product.component.js +1 -1
  68. package/esm2015/src/pages/remote/remote.component.js +1 -1
  69. package/esm2015/src/pages/shopping-cart/shopping-cart.component.js +1 -1
  70. package/fesm2015/veloceapps-sdk-cms.js +1109 -713
  71. package/fesm2015/veloceapps-sdk-cms.js.map +1 -1
  72. package/fesm2015/veloceapps-sdk.js +5 -5
  73. package/fesm2015/veloceapps-sdk.js.map +1 -1
  74. package/package.json +5 -3
  75. package/cms/services/dynamic-module.service.d.ts +0 -15
  76. package/cms/services/launcher.service.d.ts +0 -18
  77. package/esm2015/cms/services/dynamic-module.service.js +0 -33
  78. package/esm2015/cms/services/launcher.service.js +0 -58
  79. package/esm2015/cms/types/compilation.types.js +0 -2
@@ -1,26 +1,29 @@
1
- import { __decorate, __param, __awaiter, __rest } from 'tslib';
1
+ import { __decorate, __param, __awaiter } from 'tslib';
2
2
  import * as i0 from '@angular/core';
3
- import { InjectionToken, Component, ChangeDetectionStrategy, Inject, Injector, Injectable, Directive, ViewContainerRef, SkipSelf, ViewChild, Input, NgModule, ViewEncapsulation } from '@angular/core';
3
+ import { InjectionToken, Component, ChangeDetectionStrategy, Inject, Injector, Injectable, ViewContainerRef, SkipSelf, ViewChild, Input, ViewEncapsulation, NgModule, Directive, ElementRef } from '@angular/core';
4
4
  import * as rxjs from 'rxjs';
5
- import { BehaviorSubject, Subject, takeUntil, map, filter, from, tap, of, switchMap, forkJoin, catchError } from 'rxjs';
5
+ import { BehaviorSubject, Subject, of, map, tap, switchMap, startWith, distinctUntilChanged, filter, takeUntil, forkJoin, catchError, ReplaySubject, combineLatest, from } from 'rxjs';
6
6
  import * as lodash from 'lodash';
7
- import { compact, flatten, isArray, pull, set, kebabCase } from 'lodash';
7
+ import { compact, isArray, pull, merge, flatten, set, kebabCase, omit } from 'lodash';
8
+ import { applyPatch } from 'rfc6902';
9
+ import * as i2 from '@veloceapps/sdk/core';
10
+ import { ConfigurationService, LineItemWorker, generateLineItem, getAttributeValue, QuoteDraftService, FlowConfigurationService, ProductImagesService, ContextService, lineItemUtils, SdkCoreModule } from '@veloceapps/sdk/core';
11
+ import * as i3 from 'primeng/api';
12
+ import * as i5 from '@veloceapps/components';
13
+ import { LetDirectiveModule, LoaderModule, ToastService } from '@veloceapps/components';
14
+ import { UUID, isDefined, CoreModule } from '@veloceapps/core';
8
15
  import * as i7 from '@angular/common';
9
- import { DOCUMENT, CommonModule } from '@angular/common';
10
- import { UUID, CoreModule } from '@veloceapps/core';
16
+ import { CommonModule, DOCUMENT } from '@angular/common';
17
+ import * as i2$1 from 'ngx-drag-drop';
18
+ import { DndModule } from 'ngx-drag-drop';
19
+ import { SalesforceApiService, QuoteApiService, DocumentTemplatesApiService, DocumentAttachmentApiService, RampApiService, CatalogApiService, DeltaApiService, PicklistsApiService, PriceApiService, ShoppingCartSettingsApiService, ConfigurationSettingsApiService, ApiModule } from '@veloceapps/api';
20
+ import { DialogService } from 'primeng/dynamicdialog';
11
21
  import { DragDropModule } from '@angular/cdk/drag-drop';
12
22
  import { ScrollingModule } from '@angular/cdk/scrolling';
13
23
  import * as angularForms from '@angular/forms';
14
24
  import { FormsModule, ReactiveFormsModule } from '@angular/forms';
15
- import * as i2 from '@veloceapps/sdk/core';
16
- import { ConfigurationService, LineItemWorker, generateLineItem, getAttributeValue, QuoteDraftService, FlowConfigurationService, ProductImagesService, ContextService, lineItemUtils, SdkCoreModule } from '@veloceapps/sdk/core';
17
- import * as i1 from '@veloceapps/components';
18
- import { LoaderModule, ToastService } from '@veloceapps/components';
19
25
  import { transform } from '@babel/standalone';
20
- import { SalesforceApiService, QuoteApiService, DocumentTemplatesApiService, DocumentAttachmentApiService, RampApiService, CatalogApiService, DeltaApiService, PicklistsApiService, PriceApiService, ShoppingCartSettingsApiService, ConfigurationSettingsApiService, ApiModule } from '@veloceapps/api';
21
26
  import * as rxjsOperators from 'rxjs/operators';
22
- import * as i3 from 'primeng/api';
23
- import { DialogService } from 'primeng/dynamicdialog';
24
27
 
25
28
  var FlowAction;
26
29
  (function (FlowAction) {
@@ -156,6 +159,88 @@ ElementComponent = __decorate([
156
159
  __param(0, Inject(Injector))
157
160
  ], ElementComponent);
158
161
 
162
+ function getElementUniqueName(collection, name, comparator) {
163
+ let result = '';
164
+ let index = 0;
165
+ while (!result) {
166
+ const candidate = name + (index ? ` (${index})` : '');
167
+ const exists = collection.some(comparator(candidate));
168
+ if (!exists) {
169
+ result = candidate;
170
+ }
171
+ else {
172
+ index++;
173
+ }
174
+ }
175
+ return result;
176
+ }
177
+ const insertElementAt = (source, target, parentPath, index) => {
178
+ const result = [...source];
179
+ const name = getElementUniqueName(result, target.name, (name) => (el) => el.name === name);
180
+ const path = parentPath ? `${parentPath}/${name}` : name;
181
+ result.splice(index, 0, Object.assign(Object.assign({}, target), { path, name }));
182
+ return result;
183
+ };
184
+ const insertElement = (source, target, path, index) => {
185
+ if (!path) {
186
+ return insertElementAt(source, target, '', index);
187
+ }
188
+ return source.map(element => {
189
+ var _a;
190
+ if (element.path === path) {
191
+ return Object.assign(Object.assign({}, element), { children: insertElementAt(element.children, target, element.path, index) });
192
+ }
193
+ else if ((_a = element.path) === null || _a === void 0 ? void 0 : _a.startsWith(path)) {
194
+ return Object.assign(Object.assign({}, element), { children: insertElement(element.children, target, path, index) });
195
+ }
196
+ else {
197
+ return element;
198
+ }
199
+ });
200
+ };
201
+ const removeElement = (source, path) => {
202
+ return source.reduce((trunk, element) => {
203
+ if (path === element.path) {
204
+ return trunk;
205
+ }
206
+ if (element.path) {
207
+ if (path.startsWith(element.path)) {
208
+ trunk.push(Object.assign(Object.assign({}, element), { children: removeElement(element.children, path) }));
209
+ }
210
+ else {
211
+ trunk.push(element);
212
+ }
213
+ }
214
+ return trunk;
215
+ }, []);
216
+ };
217
+ const findElementByPath = (source, path) => {
218
+ for (const el of source) {
219
+ if (el.path === path) {
220
+ return el;
221
+ }
222
+ if (el.path && path.startsWith(el.path)) {
223
+ const found = findElementByPath(el.children, path);
224
+ if (found) {
225
+ return found;
226
+ }
227
+ }
228
+ }
229
+ return;
230
+ };
231
+ const findElementByModule = (elements, module, elementName) => {
232
+ for (const el of elements) {
233
+ if (el.module === module && el.name === elementName) {
234
+ return el;
235
+ }
236
+ const child = findElementByModule(el.children, module, elementName);
237
+ if (child) {
238
+ return child;
239
+ }
240
+ }
241
+ return;
242
+ };
243
+
159
244
  const parseBoundPath = (path) => {
160
245
  var _a, _b;
161
246
  const regexp = new RegExp(`(?:\\/)(?:\\w+)(?:\\/)(?:ports|attributes)(?:\\/)(?:\\w+)|(?:\\/)(?:\\w+)`, 'g');
@@ -188,18 +273,6 @@ const parsePath = (path) => {
188
273
  variable,
189
274
  };
190
275
  };
191
- const findElementByModule = (elements, module, elementName) => {
192
- for (const el of elements) {
193
- if (el.module === module && el.name === elementName) {
194
- return el;
195
- }
196
- const child = findElementByModule(el.children, module, elementName);
197
- if (child) {
198
- return child;
199
- }
200
- }
201
- return;
202
- };
203
276
  const getAbsolutePath = (elements, subject, path) => {
204
277
  var _a, _b, _c;
205
278
  if (path.module) {
@@ -222,40 +295,79 @@ const getAbsolutePath = (elements, subject, path) => {
222
295
  return subjectSegments.join('/');
223
296
  };
224
297
 
225
- class DynamicModuleService {
226
- constructor() {
227
- this._elementsTree = [];
228
- this._componentFactories = [];
229
- }
230
- set componentFactories(data) {
231
- this._componentFactories = data;
232
- }
233
- get componentFactories() {
234
- return this._componentFactories;
298
+ const CMS_COMPILATION_SERVICE = new InjectionToken('VENDOR_MAP');
299
+
300
+ class RuntimeService {
301
+ constructor(injector) {
302
+ this.injector = injector;
303
+ this.modules = [];
304
+ this.componentFactories = {};
305
+ this.applicationTree = [];
306
+ this.isInitialized$ = new BehaviorSubject(false);
307
+ this.updated$ = new Subject();
308
+ this.compilationService = this.injector.get(CMS_COMPILATION_SERVICE);
309
+ }
310
+ initialize$(uiDefinition, config) {
311
+ this.config = config;
312
+ if (!uiDefinition) {
313
+ return of([]);
314
+ }
315
+ return this.compilationService.compileUIDefinition$(uiDefinition).pipe(map(result => {
316
+ this.applicationTree = result.elements;
317
+ this.addComponentFactories(result.module.componentFactories);
318
+ return result.elements;
319
+ }), tap(() => this.isInitialized$.next(true)));
320
+ }
321
+ applyPatch$(patch) {
322
+ let observable$ = of(undefined);
323
+ patch.forEach(operation => {
324
+ switch (operation.op) {
325
+ case 'add': {
326
+ observable$ = observable$.pipe(switchMap(() => this.addElement$(operation)));
327
+ break;
328
+ }
329
+ case 'remove': {
330
+ observable$ = observable$.pipe(map(() => this.deleteElement(operation)));
331
+ break;
332
+ }
333
+ default:
334
+ observable$ = of();
335
+ }
336
+ });
337
+ return observable$.pipe(tap(() => this.updated$.next()));
235
338
  }
236
- getComponentFactory(element) {
237
- return this.componentFactories.find(f => f.componentType.path === element.path);
339
+ getCompiledElement$(path) {
340
+ return this.updated$.pipe(startWith(undefined), map(() => findElementByPath(this.applicationTree, path)), distinctUntilChanged());
238
341
  }
239
- get elementsTree() {
240
- return this._elementsTree;
342
+ clear() {
343
+ this.compilationService.clearModuleCache(this.modules);
344
+ this.modules = [];
345
+ this.applicationTree = [];
346
+ this.componentFactories = {};
347
+ this.isInitialized$.next(false);
348
+ }
349
+ addElement$(operation) {
350
+ return this.compilationService.compileElement$(operation.value).pipe(map(result => {
351
+ this.addComponentFactories(result.module.componentFactories);
352
+ applyPatch(this.applicationTree, [Object.assign(Object.assign({}, operation), { value: result.elements[0] })]);
353
+ }));
241
354
  }
242
- set elementsTree(tree) {
243
- this._elementsTree = tree;
355
+ deleteElement(operation) {
356
+ applyPatch(this.applicationTree, [operation]);
244
357
  }
245
- clear() {
246
- this._elementsTree = [];
247
- this.componentFactories = [];
358
+ addComponentFactories(list) {
359
+ list.forEach(item => (this.componentFactories[item.componentType.path] = item));
248
360
  }
249
361
  }
250
- DynamicModuleService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: DynamicModuleService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
251
- DynamicModuleService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: DynamicModuleService });
252
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: DynamicModuleService, decorators: [{
362
+ RuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeService, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
363
+ RuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeService });
364
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeService, decorators: [{
253
365
  type: Injectable
254
- }] });
366
+ }], ctorParameters: function () { return [{ type: i0.Injector }]; } });
255
367
 
256
368
  class IOProviderService {
257
- constructor(dynamicModuleService) {
258
- this.dynamicModuleService = dynamicModuleService;
369
+ constructor(runtimeService) {
370
+ this.runtimeService = runtimeService;
259
371
  this.inputs = {};
260
372
  }
261
373
  connect(el, name, target) {
@@ -275,7 +387,7 @@ class IOProviderService {
275
387
  const pathIsValue = elPath.segments.length === 1 && elPath.segments[0].startsWith('"') && elPath.segments[0].endsWith('"');
276
388
  const finalName = (_b = elPath.variable) !== null && _b !== void 0 ? _b : name;
277
389
  const value = pathIsValue ? new BehaviorSubject(elPath.segments[0].slice(1, -1)) : undefined;
278
- const absolutePath = !pathIsValue ? getAbsolutePath(this.dynamicModuleService.elementsTree, el, elPath) : el.path;
390
+ const absolutePath = !pathIsValue ? getAbsolutePath(this.runtimeService.applicationTree, el, elPath) : el.path;
279
391
  return this.createSubjectSafe(absolutePath !== null && absolutePath !== void 0 ? absolutePath : '', finalName, value);
280
392
  }
281
393
  createSubjectSafe(path, name, subject) {
@@ -293,11 +405,11 @@ class IOProviderService {
293
405
  return this.inputs[path][name];
294
406
  }
295
407
  }
296
- IOProviderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IOProviderService, deps: [{ token: DynamicModuleService }], target: i0.ɵɵFactoryTarget.Injectable });
408
+ IOProviderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IOProviderService, deps: [{ token: RuntimeService }], target: i0.ɵɵFactoryTarget.Injectable });
297
409
  IOProviderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IOProviderService });
298
410
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IOProviderService, decorators: [{
299
411
  type: Injectable
300
- }], ctorParameters: function () { return [{ type: DynamicModuleService }]; } });
412
+ }], ctorParameters: function () { return [{ type: RuntimeService }]; } });
301
413
 
302
414
  class TemplatesService {
303
415
  constructor() {
@@ -327,323 +439,84 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
327
439
  type: Injectable
328
440
  }] });
329
441
 
330
- class IOPlugin {
331
- constructor(host) {
332
- var _a, _b;
333
- this.host = host;
334
- const elementMetadata = this.host.injector.get(ELEMENT_METADATA);
335
- const inputProvider = this.host.injector.get(IOProviderService);
336
- const inputs = Object.entries((_a = elementMetadata.inputs) !== null && _a !== void 0 ? _a : {});
337
- const outputs = Object.entries((_b = elementMetadata.outputs) !== null && _b !== void 0 ? _b : {});
338
- inputs.forEach(([key, path]) => {
339
- var _a;
340
- if (path && typeof path !== 'string') {
341
- console.error(`The value of '${key}' input should be a string`);
342
- }
343
- if (((_a = elementMetadata.outputs) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
344
- console.warn(`'${key}' appears both in inputs and outputs. To prevent inconsistent behavior please keep them unique `);
345
- }
346
- this.host[key] = inputProvider.connect(elementMetadata, key, path);
347
- });
348
- outputs.forEach(([key, path]) => {
349
- if (path && typeof path !== 'string') {
350
- console.error(`The value of '${key}' output should be a string`);
351
- }
352
- this.host[key] = inputProvider.provide(elementMetadata, key, path);
353
- });
442
+ const InitAction = { type: 'INIT' };
443
+ const ClearAction = { type: 'CLEAR' };
444
+ class IntegrationState {
445
+ constructor() {
446
+ this.stateSubj$ = new BehaviorSubject({});
447
+ this.action$ = new BehaviorSubject(InitAction);
448
+ }
449
+ get state$() {
450
+ return this.stateSubj$.asObservable();
451
+ }
452
+ get state() {
453
+ return this.stateSubj$.getValue();
454
+ }
455
+ patchState(update) {
456
+ this.stateSubj$.next(Object.assign(Object.assign({}, this.stateSubj$.getValue()), update));
457
+ }
458
+ dispatch(action) {
459
+ this.action$.next(action);
460
+ }
461
+ listen$(actionType) {
462
+ return this.action$.pipe(filter(action => action.type === actionType), map(action => action.payload));
463
+ }
464
+ listenAll$() {
465
+ return this.action$.asObservable();
466
+ }
467
+ clear() {
468
+ this.stateSubj$.next({});
469
+ this.action$.next(ClearAction);
354
470
  }
355
471
  }
356
- IOPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IOPlugin, deps: [{ token: ElementComponent }], target: i0.ɵɵFactoryTarget.Directive });
357
- IOPlugindir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.17", type: IOPlugin, ngImport: i0 });
358
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IOPlugin, decorators: [{
359
- type: Directive
360
- }], ctorParameters: function () { return [{ type: ElementComponent }]; } });
472
+ IntegrationState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IntegrationState, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
473
+ IntegrationStateprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IntegrationState, providedIn: 'root' });
474
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IntegrationState, decorators: [{
475
+ type: Injectable,
476
+ args: [{ providedIn: 'root' }]
477
+ }] });
361
478
 
362
- class ScriptPlugin {
363
- constructor(host) {
364
- this.host = host;
365
- this.normalizeImports = (script, elementPath) => {
366
- const regexp = new RegExp(`import([ \\n\\t]*(?:[^ \\n\\t\\{\\}]+[ \\n\\t]*,?)?(?:[ \\n\\t]*\\{(?:[ \\n\\t]*[^ \\n\\t"'\\{\\}]+[ \\n\\t]*,?)+\\})?[ \\n\\t]*)from[ \\n\\t]*(['"])([^'"\\n]+)(?:['"]);`, 'g');
367
- const result = script.replace(regexp, (match, g1, g2, src) => {
368
- const imports = g1
369
- .trim()
370
- .slice(1, -1)
371
- .split(',')
372
- .map(item => item.trim());
373
- imports.forEach(item => {
374
- var _a;
375
- if (!((_a = this.vendorMap[src]) === null || _a === void 0 ? void 0 : _a[item])) {
376
- throw new Error(`Failed to import ${item} from '${src}' in ${elementPath}/script.ts`);
377
- }
378
- });
379
- return `const ${g1} = vendor['${src}'];`;
380
- });
381
- return result;
382
- };
383
- this.document = this.host.injector.get(DOCUMENT);
384
- this.vendorMap = this.host.injector.get(VENDOR_MAP);
385
- const elementMetadata = this.host.injector.get(ELEMENT_METADATA);
386
- const sharedElementMetadata = this.host.injector.get(SHARED_ELEMENT_METADATA);
387
- this.addScript(sharedElementMetadata);
388
- this.addScript(elementMetadata);
479
+ class ElementContextService {
480
+ }
481
+ ElementContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementContextService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
482
+ ElementContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementContextService });
483
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementContextService, decorators: [{
484
+ type: Injectable
485
+ }] });
486
+
487
+ class ElementRendererComponent {
488
+ constructor(parentInjector, runtimeService, elementContext, ioProviderService, configurationService, elementRef, cdr) {
489
+ this.parentInjector = parentInjector;
490
+ this.runtimeService = runtimeService;
491
+ this.elementContext = elementContext;
492
+ this.ioProviderService = ioProviderService;
493
+ this.configurationService = configurationService;
494
+ this.elementRef = elementRef;
495
+ this.cdr = cdr;
496
+ this.refs = {};
497
+ this.destroy$ = new Subject();
389
498
  }
390
- addScript(metadata) {
391
- var _a;
392
- if (!(metadata === null || metadata === void 0 ? void 0 : metadata.script)) {
499
+ ngOnInit() {
500
+ this.elementContext.metadata = this.meta;
501
+ this.factory = this.meta.path ? this.runtimeService.componentFactories[this.meta.path] : undefined;
502
+ this.createComponents();
503
+ }
504
+ ngOnDestroy() {
505
+ this.destroyComponents();
506
+ this.destroy$.next();
507
+ this.destroy$.complete();
508
+ }
509
+ createComponents() {
510
+ const modelMeta = this.meta.model;
511
+ if (!modelMeta) {
512
+ this.refs[UUID.UUID()] = this.createComponent();
393
513
  return;
394
514
  }
395
- const id = btoa(UUID.UUID());
396
- const script = this.document.createElement('script');
397
- script.type = `text/javascript`;
398
- let scriptContent = this.normalizeImports(metadata.script, (_a = metadata.path) !== null && _a !== void 0 ? _a : metadata.name);
399
- const classMatch = /export class (\S+)/.exec(scriptContent);
400
- const className = classMatch === null || classMatch === void 0 ? void 0 : classMatch[1];
401
- if (!classMatch || !className) {
402
- console.error("Script doesn't have exported class");
403
- return;
515
+ if (modelMeta.lineItem) {
516
+ this.createFromLineItem(modelMeta.lineItem);
404
517
  }
405
- scriptContent = scriptContent.replace(classMatch[0], `class ${className}`);
406
- script.text = `var ${id} = function(vendor) {${scriptContent}
407
- return ${className}; };`;
408
- this.document.body.appendChild(script);
409
- const ScriptClass = window[id](this.vendorMap);
410
- if (ScriptClass instanceof Object) {
411
- this.host.registerPlugin(new ScriptClass(this.host));
412
- }
413
- this.document.body.removeChild(script);
414
- }
415
- }
416
- ScriptPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ScriptPlugin, deps: [{ token: ElementComponent }], target: i0.ɵɵFactoryTarget.Directive });
417
- ScriptPlugin.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.17", type: ScriptPlugin, ngImport: i0 });
418
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ScriptPlugin, decorators: [{
419
- type: Directive
420
- }], ctorParameters: function () { return [{ type: ElementComponent }]; } });
421
-
422
- /*
423
- * ScriptPlugin must always be the last plugin in the list to make sure user code is running after all pre-initializers.
424
- */
425
- const CONFIG = {
426
- CUSTOM: {
427
- component: ElementComponent,
428
- plugins: [IOPlugin, ScriptPlugin],
429
- },
430
- CONTAINER: {
431
- component: ElementComponent,
432
- defaultTemplate: '<element-children></element-children>',
433
- plugins: [ScriptPlugin],
434
- },
435
- SERVICE: {
436
- component: ElementComponent,
437
- plugins: [IOPlugin, ScriptPlugin],
438
- suppressTemplate: true,
439
- suppressStyles: true,
440
- },
441
- REFERENCE: {
442
- component: ElementComponent,
443
- plugins: [IOPlugin, ScriptPlugin],
444
- suppressTemplate: true,
445
- },
446
- };
447
-
448
- const EXPORTED_CLASS_REGEX = /export class (\S+)/;
449
- const METADATA_DECORATOR_REGEX = /@ElementDefinition\(([\s\S]+)\)(\n|\r\n|.)*export class/g;
450
- class UiBuildError extends Error {
451
- constructor(message, affectedMetadata) {
452
- super(message);
453
- this.name = this.constructor.name;
454
- this.affectedMetadata = affectedMetadata;
455
- }
456
- }
457
- const elementToMetadata = (el, parentPath) => {
458
- var _a;
459
- const script = el.script && window.atob(el.script);
460
- const template = el.template && window.atob(el.template);
461
- const styles = el.styles && window.atob(el.styles);
462
- const exportedClassName = script && ((_a = EXPORTED_CLASS_REGEX.exec(script)) !== null && _a !== void 0 ? _a : [])[1];
463
- if (!exportedClassName) {
464
- throw new Error("Script doesn't have exported class");
465
- }
466
- const elementMetadata = extractElementMetadata(script || '');
467
- const path = (parentPath ? parentPath + '/' : '') + elementMetadata.name;
468
- return Object.assign(Object.assign({}, elementMetadata), { path, script: script === null || script === void 0 ? void 0 : script.replace(METADATA_DECORATOR_REGEX, 'export class'), template,
469
- styles, children: el.children.map(child => elementToMetadata(child, path)) });
470
- };
471
- const metadataToElement = (metadata, recursive = true) => {
472
- const elMetadata = {
473
- name: metadata.name,
474
- isShared: metadata.isShared,
475
- type: metadata.type,
476
- model: metadata.model,
477
- module: metadata.module,
478
- reference: metadata.reference,
479
- inputs: metadata.inputs,
480
- outputs: metadata.outputs,
481
- children: metadata.children.map(({ name }) => name),
482
- configuredStyles: metadata.configuredStyles,
483
- };
484
- const normalizedElMetadata = normalizeElementMetadata(elMetadata);
485
- if (!metadata.script || !EXPORTED_CLASS_REGEX.test(metadata.script)) {
486
- throw new UiBuildError(`'${metadata.name}' component script is missing an exported class`, metadata);
487
- }
488
- const script = metadata.script &&
489
- window.btoa(metadata.script.replace(EXPORTED_CLASS_REGEX, `@ElementDefinition(${stringifyElementMetadata(normalizedElMetadata)})\nexport class Script`));
490
- const template = metadata.template && window.btoa(metadata.template);
491
- const styles = metadata.styles && window.btoa(metadata.styles);
492
- return {
493
- script,
494
- template,
495
- styles,
496
- children: recursive ? metadata.children.map(meta => metadataToElement(meta)) : [],
497
- };
498
- };
499
- const normalizeElementMetadata = (elementMetadata) => {
500
- var _a, _b, _c, _d;
501
- const metadata = Object.assign({}, elementMetadata);
502
- // model
503
- const { lineItem, path } = (_a = metadata.model) !== null && _a !== void 0 ? _a : {};
504
- const model = lineItem ? { lineItem } : path ? { path } : undefined;
505
- if (model) {
506
- metadata.model = model;
507
- }
508
- else {
509
- delete metadata.model;
510
- }
511
- // module
512
- if (!metadata.module) {
513
- delete metadata.module;
514
- }
515
- // reference
516
- if (!metadata.reference) {
517
- delete metadata.reference;
518
- }
519
- // inputs
520
- const inputs = Object.entries((_b = metadata.inputs) !== null && _b !== void 0 ? _b : {}).reduce((acc, [key, value]) => {
521
- return Object.assign(Object.assign({}, acc), { [key]: value || null });
522
- }, {});
523
- if (inputs && Object.keys(inputs).length > 0) {
524
- metadata.inputs = inputs;
525
- }
526
- else {
527
- delete metadata.inputs;
528
- }
529
- // outputs
530
- const outputs = Object.entries((_c = metadata.outputs) !== null && _c !== void 0 ? _c : {}).reduce((acc, [key, value]) => {
531
- return Object.assign(Object.assign({}, acc), { [key]: value || null });
532
- }, {});
533
- if (outputs && Object.keys(outputs).length > 0) {
534
- metadata.outputs = outputs;
535
- }
536
- else {
537
- delete metadata.outputs;
538
- }
539
- // children
540
- if (!((_d = metadata.children) === null || _d === void 0 ? void 0 : _d.length)) {
541
- delete metadata.children;
542
- }
543
- // isShared
544
- if (!metadata.isShared) {
545
- delete metadata.isShared;
546
- }
547
- // configuredStyles
548
- if (!metadata.configuredStyles) {
549
- delete metadata.configuredStyles;
550
- }
551
- return metadata;
552
- };
553
- const extractElementMetadata = (script) => {
554
- var _a;
555
- const metadataString = ((_a = METADATA_DECORATOR_REGEX.exec(script)) !== null && _a !== void 0 ? _a : [])[1];
556
- // need to reset regex last index to prevent null result for next execution
557
- METADATA_DECORATOR_REGEX.lastIndex = 0;
558
- return new Function(`return ${metadataString}`)();
559
- };
560
- const extendElementMetadata = (script, extend) => {
561
- var _a;
562
- const metadataString = ((_a = METADATA_DECORATOR_REGEX.exec(script)) !== null && _a !== void 0 ? _a : [])[1];
563
- // need to reset regex last index to prevent null result for next execution
564
- METADATA_DECORATOR_REGEX.lastIndex = 0;
565
- if (!metadataString) {
566
- return script;
567
- }
568
- const updated = Object.assign(Object.assign({}, new Function(`return ${metadataString}`)()), extend);
569
- return script.replace(metadataString, stringifyElementMetadata(updated));
570
- };
571
- const getElementConfig = (type) => {
572
- return CONFIG[type];
573
- };
574
- const doesElementSupportIO = (type) => {
575
- var _a, _b;
576
- return (_b = (_a = getElementConfig(type).plugins) === null || _a === void 0 ? void 0 : _a.includes(IOPlugin)) !== null && _b !== void 0 ? _b : false;
577
- };
578
- function stringifyElementMetadata(elementMetadata) {
579
- const cleaned = JSON.stringify(elementMetadata, null, 2);
580
- return cleaned.replace(/^[\t ]*"[^:\n\r]+(?<!\\)":/gm, function (match) {
581
- return match.replace(/"/g, '');
582
- });
583
- }
584
- const isValidScript = (script) => {
585
- var _a;
586
- if (!script) {
587
- return false;
588
- }
589
- const exportedClassName = script && ((_a = EXPORTED_CLASS_REGEX.exec(script)) !== null && _a !== void 0 ? _a : [])[1];
590
- if (!exportedClassName) {
591
- return false;
592
- }
593
- const meta = extractElementMetadata(script);
594
- if (!meta.name || !meta.type) {
595
- return false;
596
- }
597
- return true;
598
- };
599
- function flattenElements(elements) {
600
- return flatten(elements.map(el => [el, ...flattenElements(el.children)]));
601
- }
602
- function isSharedElement(el) {
603
- return Boolean(el.isShared) && el.type !== 'REFERENCE';
604
- }
605
-
606
- class ElementContextService {
607
- }
608
- ElementContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementContextService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
609
- ElementContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementContextService });
610
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementContextService, decorators: [{
611
- type: Injectable
612
- }] });
613
-
614
- class ElementRendererComponent {
615
- constructor(parentInjector, dynamicModuleService, elementContext, ioProviderService, configurationService, elementRef, cdr) {
616
- this.parentInjector = parentInjector;
617
- this.dynamicModuleService = dynamicModuleService;
618
- this.elementContext = elementContext;
619
- this.ioProviderService = ioProviderService;
620
- this.configurationService = configurationService;
621
- this.elementRef = elementRef;
622
- this.cdr = cdr;
623
- this.refs = {};
624
- this.destroy$ = new Subject();
625
- }
626
- ngOnInit() {
627
- this.elementContext.metadata = this.meta;
628
- this.factory = this.dynamicModuleService.getComponentFactory(this.meta);
629
- this.createComponents();
630
- }
631
- ngOnDestroy() {
632
- this.destroyComponents();
633
- this.destroy$.next();
634
- this.destroy$.complete();
635
- }
636
- createComponents() {
637
- const modelMeta = this.meta.model;
638
- if (!modelMeta) {
639
- this.refs[UUID.UUID()] = this.createComponent();
640
- return;
641
- }
642
- if (modelMeta.lineItem) {
643
- this.createFromLineItem(modelMeta.lineItem);
644
- }
645
- else if (modelMeta.path) {
646
- this.createFromPath(modelMeta.path);
518
+ else if (modelMeta.path) {
519
+ this.createFromPath(modelMeta.path);
647
520
  }
648
521
  }
649
522
  createFromPath(path) {
@@ -749,7 +622,7 @@ class ElementRendererComponent {
749
622
  this.refs = {};
750
623
  }
751
624
  }
752
- ElementRendererComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererComponent, deps: [{ token: i0.Injector, skipSelf: true }, { token: DynamicModuleService }, { token: ElementContextService }, { token: IOProviderService }, { token: i2.ConfigurationService }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
625
+ ElementRendererComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererComponent, deps: [{ token: i0.Injector, skipSelf: true }, { token: RuntimeService }, { token: ElementContextService }, { token: IOProviderService }, { token: i2.ConfigurationService }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
753
626
  ElementRendererComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: ElementRendererComponent, selector: "vl-cms-element-renderer", inputs: { meta: "meta" }, providers: [ElementContextService], viewQueries: [{ propertyName: "el", first: true, predicate: ["el"], descendants: true, read: ViewContainerRef, static: true }], ngImport: i0, template: "<ng-template #el></ng-template>\n", styles: [":host{display:contents}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
754
627
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererComponent, decorators: [{
755
628
  type: Component,
@@ -762,183 +635,696 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
762
635
  }]
763
636
  }], ctorParameters: function () { return [{ type: i0.Injector, decorators: [{
764
637
  type: SkipSelf
765
- }] }, { type: DynamicModuleService }, { type: ElementContextService }, { type: IOProviderService }, { type: i2.ConfigurationService }, { type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { el: [{
638
+ }] }, { type: RuntimeService }, { type: ElementContextService }, { type: IOProviderService }, { type: i2.ConfigurationService }, { type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { el: [{
766
639
  type: ViewChild,
767
640
  args: ['el', { read: ViewContainerRef, static: true }]
768
641
  }], meta: [{
769
642
  type: Input
770
643
  }] } });
771
644
 
772
- class ElementChildrenComponent {
773
- constructor(elementContext) {
774
- this.elementContext = elementContext;
775
- this.metadata = this.elementContext.metadata;
645
+ class PreviewComponent {
646
+ constructor(runtimeService, configurationService, messageService, configurationRuntimeService, integrationState, cdr) {
647
+ this.runtimeService = runtimeService;
648
+ this.configurationService = configurationService;
649
+ this.messageService = messageService;
650
+ this.configurationRuntimeService = configurationRuntimeService;
651
+ this.integrationState = integrationState;
652
+ this.cdr = cdr;
653
+ this.state$ = new BehaviorSubject({ loading: true, failure: false });
654
+ this.elements = [];
655
+ this.destroy$ = new Subject();
656
+ this.runtimeService.updated$.pipe(takeUntil(this.destroy$)).subscribe(() => this.cdr.detectChanges());
657
+ }
658
+ ngOnInit() {
659
+ var _a;
660
+ if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.suppressClearState)) {
661
+ this.integrationState.clear();
662
+ }
663
+ this.startPreview();
664
+ }
665
+ ngOnDestroy() {
666
+ this.destroy$.next();
667
+ this.destroy$.complete();
668
+ this.configurationService.reset();
669
+ this.runtimeService.clear();
670
+ }
671
+ initializeConfiguration$() {
672
+ const isAlreadyInitialized = this.configurationRuntimeService.isInitialized;
673
+ if (!this.uiDefinition || this.uiDefinition.type !== 'CONFIGURATION' || isAlreadyInitialized) {
674
+ return of({});
675
+ }
676
+ if (!this.modelId) {
677
+ console.warn(`No modelId is given for uiDefinition with '${this.uiDefinition.type}' type`);
678
+ return of({});
679
+ }
680
+ // If still not initialized - init configuration in Test mode
681
+ return this.configurationRuntimeService
682
+ .initTestMode(this.modelId, this.uiDefinition)
683
+ .pipe(switchMap(() => this.configurationService.configure()));
684
+ }
685
+ startPreview() {
686
+ if (!this.uiDefinition) {
687
+ return;
688
+ }
689
+ forkJoin([this.runtimeService.initialize$(this.uiDefinition, this.config), this.initializeConfiguration$()])
690
+ .pipe(tap(([elements]) => {
691
+ this.elements = elements;
692
+ this.state$.next({ loading: false, failure: false });
693
+ }), catchError(error => {
694
+ var _a, _b;
695
+ console.error(error);
696
+ if (!((_b = (_a = this.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.suppressToastMessages)) {
697
+ this.messageService.add({ severity: 'error', summary: error });
698
+ }
699
+ this.state$.next({ loading: false, failure: true });
700
+ return of();
701
+ }), takeUntil(this.destroy$))
702
+ .subscribe();
776
703
  }
777
704
  }
778
- ElementChildrenComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenComponent, deps: [{ token: ElementContextService }], target: i0.ɵɵFactoryTarget.Component });
779
- ElementChildrenComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: ElementChildrenComponent, selector: "element-children", ngImport: i0, template: "<ng-container *ngIf=\"metadata?.children.length\">\n <ng-container *ngFor=\"let child of metadata.children\">\n <vl-cms-element-renderer [meta]=\"child\"></vl-cms-element-renderer>\n </ng-container>\n</ng-container>\n", styles: [":host{display:contents}\n"], components: [{ type: ElementRendererComponent, selector: "vl-cms-element-renderer", inputs: ["meta"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
780
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenComponent, decorators: [{
705
+ PreviewComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewComponent, deps: [{ token: RuntimeService }, { token: i2.ConfigurationService }, { token: i3.MessageService }, { token: i2.ConfigurationRuntimeService }, { token: IntegrationState }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
706
+ PreviewComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: PreviewComponent, selector: "vl-cms-preview", inputs: { modelId: "modelId", uiDefinition: "uiDefinition", config: "config" }, providers: [IOProviderService, TemplatesService], ngImport: i0, template: "<ng-container *ngIf=\"state$ | async as state\">\n <vl-loader *ngIf=\"state.loading; else content\" [label]=\"'Loading UI'\"></vl-loader>\n\n <ng-template #content>\n <ng-container *ngIf=\"!state.failure\">\n <vl-cms-element-renderer *ngFor=\"let el of elements\" [meta]=\"el\"></vl-cms-element-renderer>\n </ng-container>\n </ng-template>\n</ng-container>\n", styles: [":host{flex-grow:1;display:flex;flex-direction:column;height:100%}\n"], components: [{ type: i5.LoaderComponent, selector: "vl-loader", inputs: ["label", "overlayVisible"] }, { type: ElementRendererComponent, selector: "vl-cms-element-renderer", inputs: ["meta"] }], directives: [{ type: i7.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i7.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], pipes: { "async": i7.AsyncPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.ShadowDom });
707
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewComponent, decorators: [{
781
708
  type: Component,
782
709
  args: [{
783
- // eslint-disable-next-line @angular-eslint/component-selector
784
- selector: 'element-children',
785
- templateUrl: 'element-children.component.html',
786
- styleUrls: ['./element-children.component.scss'],
710
+ selector: 'vl-cms-preview',
711
+ templateUrl: './preview.component.html',
712
+ styleUrls: ['./preview.component.scss'],
787
713
  changeDetection: ChangeDetectionStrategy.OnPush,
788
- }]
789
- }], ctorParameters: function () { return [{ type: ElementContextService }]; } });
790
-
714
+ providers: [IOProviderService, TemplatesService],
715
+ // use shadow DOM to prevent UI from being affected by global styles
716
+ encapsulation: ViewEncapsulation.ShadowDom,
717
+ }]
718
+ }], ctorParameters: function () { return [{ type: RuntimeService }, { type: i2.ConfigurationService }, { type: i3.MessageService }, { type: i2.ConfigurationRuntimeService }, { type: IntegrationState }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { modelId: [{
719
+ type: Input
720
+ }], uiDefinition: [{
721
+ type: Input
722
+ }], config: [{
723
+ type: Input
724
+ }] } });
725
+
726
+ class RuntimeEditorService {
727
+ constructor(runtimeService) {
728
+ this.runtimeService = runtimeService;
729
+ this.editorModeSubj$ = new BehaviorSubject(false);
730
+ this.dragMode$ = new BehaviorSubject(false);
731
+ this.elementDropped$ = new ReplaySubject();
732
+ this.elementDeleted$ = new ReplaySubject();
733
+ this.editorMode$ = this.editorModeSubj$.asObservable();
734
+ this.runtimeService.isInitialized$.subscribe(() => { var _a; return this.editorModeSubj$.next(Boolean((_a = this.runtimeService.config) === null || _a === void 0 ? void 0 : _a.uiBuilderMode)); });
735
+ }
736
+ applyPatch$(patch) {
737
+ return this.runtimeService.applyPatch$(patch);
738
+ }
739
+ toggleEditorMode() {
740
+ this.editorModeSubj$.next(!this.editorModeSubj$.value);
741
+ }
742
+ }
743
+ RuntimeEditorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeEditorService, deps: [{ token: RuntimeService }], target: i0.ɵɵFactoryTarget.Injectable });
744
+ RuntimeEditorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeEditorService });
745
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeEditorService, decorators: [{
746
+ type: Injectable
747
+ }], ctorParameters: function () { return [{ type: RuntimeService }]; } });
748
+
749
+ class ElementDropHandleComponent {
750
+ constructor(runtimeService) {
751
+ this.runtimeService = runtimeService;
752
+ }
753
+ handleDrop(e) {
754
+ this.runtimeService.elementDropped$.next({
755
+ element: e.data,
756
+ index: this.index,
757
+ path: this.parentPath,
758
+ });
759
+ }
760
+ }
761
+ ElementDropHandleComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementDropHandleComponent, deps: [{ token: RuntimeEditorService }], target: i0.ɵɵFactoryTarget.Component });
762
+ ElementDropHandleComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: ElementDropHandleComponent, selector: "vl-element-drop-handle", inputs: { index: "index", parentPath: "parentPath" }, ngImport: i0, template: "<div class=\"container\" dndDropzone (dndDrop)=\"handleDrop($event)\">\n <div class=\"handle\"></div>\n</div>\n", styles: [":host{width:0;position:relative}.container{width:40px;height:100%;position:absolute;transform:translate(-50%);display:flex;justify-content:center;align-items:center}.handle{display:none;background:red;height:calc(100% - 10px);width:2px;pointer-events:none}.container.dndDragover .handle{display:block}\n"], directives: [{ type: i2$1.DndDropzoneDirective, selector: "[dndDropzone]", inputs: ["dndDropzone", "dndEffectAllowed", "dndAllowExternal", "dndHorizontal", "dndDragoverClass", "dndDropzoneDisabledClass", "dndDisableIf", "dndDisableDropIf"], outputs: ["dndDragover", "dndDrop"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
763
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementDropHandleComponent, decorators: [{
764
+ type: Component,
765
+ args: [{
766
+ selector: 'vl-element-drop-handle',
767
+ templateUrl: './element-drop-handle.component.html',
768
+ styleUrls: ['./element-drop-handle.component.scss'],
769
+ changeDetection: ChangeDetectionStrategy.OnPush,
770
+ }]
771
+ }], ctorParameters: function () { return [{ type: RuntimeEditorService }]; }, propDecorators: { index: [{
772
+ type: Input
773
+ }], parentPath: [{
774
+ type: Input
775
+ }] } });
776
+
777
+ class ElementDropHandleModule {
778
+ }
779
+ ElementDropHandleModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementDropHandleModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
780
+ ElementDropHandleModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementDropHandleModule, declarations: [ElementDropHandleComponent], imports: [CommonModule, DndModule], exports: [ElementDropHandleComponent] });
781
+ ElementDropHandleModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementDropHandleModule, imports: [[CommonModule, DndModule]] });
782
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementDropHandleModule, decorators: [{
783
+ type: NgModule,
784
+ args: [{
785
+ declarations: [ElementDropHandleComponent],
786
+ imports: [CommonModule, DndModule],
787
+ exports: [ElementDropHandleComponent],
788
+ }]
789
+ }] });
790
+
791
+ class ElementRendererModule {
792
+ }
793
+ ElementRendererModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
794
+ ElementRendererModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererModule, declarations: [ElementRendererComponent], exports: [ElementRendererComponent] });
795
+ ElementRendererModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererModule });
796
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererModule, decorators: [{
797
+ type: NgModule,
798
+ args: [{
799
+ declarations: [ElementRendererComponent],
800
+ exports: [ElementRendererComponent],
801
+ }]
802
+ }] });
803
+
804
+ class ElementChildrenComponent {
805
+ constructor(elementContext, runtimeService, runtimeEditorService, cdr) {
806
+ var _a, _b;
807
+ this.elementContext = elementContext;
808
+ this.runtimeService = runtimeService;
809
+ this.runtimeEditorService = runtimeEditorService;
810
+ this.cdr = cdr;
811
+ this.destroyed$ = new Subject();
812
+ const path = (_b = (_a = this.elementContext) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.path;
813
+ this.metadata$ = path ? this.runtimeService.getCompiledElement$(path) : of(undefined);
814
+ this.dragMode$ = combineLatest([this.runtimeEditorService.editorMode$, this.runtimeEditorService.dragMode$]).pipe(map(flags => flags.every(Boolean)));
815
+ this.runtimeService.updated$.pipe(takeUntil(this.destroyed$)).subscribe(() => this.cdr.detectChanges());
816
+ }
817
+ ngOnDestroy() {
818
+ this.destroyed$.next();
819
+ this.destroyed$.complete();
820
+ }
821
+ }
822
+ ElementChildrenComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenComponent, deps: [{ token: ElementContextService }, { token: RuntimeService }, { token: RuntimeEditorService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
823
+ ElementChildrenComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", 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"], components: [{ type: ElementDropHandleComponent, selector: "vl-element-drop-handle", inputs: ["index", "parentPath"] }, { type: ElementRendererComponent, selector: "vl-cms-element-renderer", inputs: ["meta"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
824
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenComponent, decorators: [{
825
+ type: Component,
826
+ args: [{
827
+ // eslint-disable-next-line @angular-eslint/component-selector
828
+ selector: 'element-children',
829
+ templateUrl: 'element-children.component.html',
830
+ styleUrls: ['./element-children.component.scss'],
831
+ changeDetection: ChangeDetectionStrategy.OnPush,
832
+ }]
833
+ }], ctorParameters: function () { return [{ type: ElementContextService }, { type: RuntimeService }, { type: RuntimeEditorService }, { type: i0.ChangeDetectorRef }]; } });
834
+
835
+ class ElementChildrenModule {
836
+ }
837
+ ElementChildrenModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
838
+ ElementChildrenModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenModule, declarations: [ElementChildrenComponent], imports: [LetDirectiveModule, ElementRendererModule, ElementDropHandleModule], exports: [ElementChildrenComponent] });
839
+ ElementChildrenModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenModule, imports: [[LetDirectiveModule, ElementRendererModule, ElementDropHandleModule]] });
840
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenModule, decorators: [{
841
+ type: NgModule,
842
+ args: [{
843
+ declarations: [ElementChildrenComponent],
844
+ imports: [LetDirectiveModule, ElementRendererModule, ElementDropHandleModule],
845
+ exports: [ElementChildrenComponent],
846
+ }]
847
+ }] });
848
+
849
+ class PreviewModule {
850
+ }
851
+ PreviewModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
852
+ PreviewModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewModule, declarations: [PreviewComponent], imports: [CommonModule, LoaderModule, ElementRendererModule, ElementChildrenModule, ElementDropHandleModule], exports: [PreviewComponent] });
853
+ PreviewModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewModule, providers: [IntegrationState], imports: [[CommonModule, LoaderModule, ElementRendererModule, ElementChildrenModule, ElementDropHandleModule]] });
854
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewModule, decorators: [{
855
+ type: NgModule,
856
+ args: [{
857
+ declarations: [PreviewComponent],
858
+ imports: [CommonModule, LoaderModule, ElementRendererModule, ElementChildrenModule, ElementDropHandleModule],
859
+ providers: [IntegrationState],
860
+ exports: [PreviewComponent],
861
+ }]
862
+ }] });
863
+
864
+ function ElementDefinition(definition) {
865
+ return function (constructor) {
866
+ return constructor;
867
+ };
868
+ }
869
+
791
870
  // eslint-disable-next-line @angular-eslint/directive-selector
792
871
  class CustomTemplateDirective {
793
872
  constructor(templateRef, templatesService) {
794
873
  this.templateRef = templateRef;
795
874
  this.templatesService = templatesService;
796
875
  }
797
- ngAfterViewInit() {
798
- if (!this.customTemplate) {
799
- return;
800
- }
801
- this.templatesService.register(this.customTemplate, this.templateRef);
876
+ ngAfterViewInit() {
877
+ if (!this.customTemplate) {
878
+ return;
879
+ }
880
+ this.templatesService.register(this.customTemplate, this.templateRef);
881
+ }
882
+ }
883
+ CustomTemplateDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: CustomTemplateDirective, deps: [{ token: i0.TemplateRef }, { token: TemplatesService }], target: i0.ɵɵFactoryTarget.Directive });
884
+ CustomTemplateDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.17", type: CustomTemplateDirective, selector: "[customTemplate]", inputs: { customTemplate: "customTemplate" }, ngImport: i0 });
885
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: CustomTemplateDirective, decorators: [{
886
+ type: Directive,
887
+ args: [{ selector: '[customTemplate]' }]
888
+ }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: TemplatesService }]; }, propDecorators: { customTemplate: [{
889
+ type: Input
890
+ }] } });
891
+
892
+ class ElementHoverPlugin {
893
+ constructor(host) {
894
+ this.host = host;
895
+ this.hoverClassName = 'element-hover';
896
+ this.color = 'red';
897
+ this.highlighted = false;
898
+ this.destroyed$ = new Subject();
899
+ this.el = this.host.injector.get(ElementRef);
900
+ this.metadata = this.host.injector.get(ELEMENT_METADATA);
901
+ this.document = this.host.injector.get(DOCUMENT);
902
+ this.runtimeEditorService = this.host.injector.get(RuntimeEditorService);
903
+ this.mouseOverListenerBound = this.mouseOverListener.bind(this);
904
+ this.mouseLeaveListenerBound = this.mouseLeaveListener.bind(this);
905
+ this.runtimeEditorService.editorMode$.pipe(takeUntil(this.destroyed$)).subscribe(editorMode => {
906
+ if (editorMode) {
907
+ this.attachListeners();
908
+ }
909
+ else {
910
+ this.detachListeners();
911
+ }
912
+ });
913
+ }
914
+ ngOnDestroy() {
915
+ this.destroyed$.next();
916
+ this.destroyed$.complete();
917
+ this.detachListeners();
918
+ }
919
+ attachListeners() {
920
+ this.el.nativeElement.addEventListener('mouseover', this.mouseOverListenerBound);
921
+ this.el.nativeElement.addEventListener('mouseleave', this.mouseLeaveListenerBound);
922
+ }
923
+ detachListeners() {
924
+ this.el.nativeElement.removeEventListener('mouseover', this.mouseOverListenerBound);
925
+ this.el.nativeElement.removeEventListener('mouseleave', this.mouseLeaveListenerBound);
926
+ }
927
+ mouseOverListener(e) {
928
+ const path = e.composedPath();
929
+ const innerPath = path.slice(0, path.indexOf(this.el.nativeElement));
930
+ const hasChildHovered = innerPath.some(target => {
931
+ const t = target;
932
+ return t.tagName === 'VL-ELEMENT' && t.classList.contains(this.hoverClassName);
933
+ });
934
+ if (hasChildHovered) {
935
+ this.removeHighlight();
936
+ }
937
+ else {
938
+ this.addHighlight();
939
+ }
940
+ }
941
+ mouseLeaveListener() {
942
+ this.removeHighlight();
943
+ }
944
+ addHighlight() {
945
+ if (this.highlighted) {
946
+ return;
947
+ }
948
+ this.highlighted = true;
949
+ this.el.nativeElement.classList.add(this.hoverClassName);
950
+ const overlay = this.createContainer();
951
+ this.addRemoveButton(overlay);
952
+ this.addElementName(overlay);
953
+ this.el.nativeElement.appendChild(overlay);
954
+ this.overlayEl = overlay;
955
+ }
956
+ removeHighlight() {
957
+ if (!this.highlighted) {
958
+ return;
959
+ }
960
+ this.highlighted = false;
961
+ this.el.nativeElement.style.boxShadow = '';
962
+ this.el.nativeElement.classList.remove(this.hoverClassName);
963
+ this.deleteRemoveButton();
964
+ }
965
+ createContainer() {
966
+ const hostRect = this.el.nativeElement.getBoundingClientRect();
967
+ const div = this.document.createElement('div');
968
+ merge(div.style, {
969
+ position: 'fixed',
970
+ display: 'block',
971
+ pointerEvents: 'none',
972
+ left: '0',
973
+ top: '0',
974
+ fontSize: '10px',
975
+ lineHeight: `12px`,
976
+ fontWeight: '400',
977
+ color: '#fff',
978
+ width: `${hostRect.width}px`,
979
+ height: `${hostRect.height}px`,
980
+ transform: `translate(${hostRect.left}px, ${hostRect.top}px)`,
981
+ boxSizing: 'border-box',
982
+ boxShadow: `inset 0 0 0 1px ${this.color}`,
983
+ });
984
+ return div;
985
+ }
986
+ addRemoveButton(container) {
987
+ if (this.metadata.type === 'LAYOUT_REGION') {
988
+ return;
989
+ }
990
+ const buttonEl = this.document.createElement('div');
991
+ const buttonSize = 12;
992
+ merge(buttonEl.style, {
993
+ bottom: '100%',
994
+ right: '0',
995
+ width: `${buttonSize}px`,
996
+ height: `${buttonSize}px`,
997
+ padding: '1px',
998
+ textAlign: 'center',
999
+ backgroundColor: this.color,
1000
+ position: 'absolute',
1001
+ cursor: 'pointer',
1002
+ display: 'block',
1003
+ pointerEvents: 'all',
1004
+ });
1005
+ buttonEl.innerHTML = '&#10005;';
1006
+ buttonEl.addEventListener('click', () => {
1007
+ if (this.metadata.path) {
1008
+ this.runtimeEditorService.elementDeleted$.next({ path: this.metadata.path });
1009
+ }
1010
+ });
1011
+ container.appendChild(buttonEl);
1012
+ }
1013
+ addElementName(container) {
1014
+ const nameEl = this.document.createElement('div');
1015
+ merge(nameEl.style, {
1016
+ bottom: '100%',
1017
+ left: '0',
1018
+ height: `12px`,
1019
+ backgroundColor: this.color,
1020
+ position: 'absolute',
1021
+ padding: '1px 2px',
1022
+ display: 'block',
1023
+ pointerEvents: 'all',
1024
+ });
1025
+ nameEl.innerHTML = this.metadata.name;
1026
+ container.appendChild(nameEl);
1027
+ }
1028
+ deleteRemoveButton() {
1029
+ if (this.overlayEl) {
1030
+ this.el.nativeElement.removeChild(this.overlayEl);
1031
+ this.overlayEl = undefined;
1032
+ }
1033
+ }
1034
+ }
1035
+ ElementHoverPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementHoverPlugin, deps: [{ token: ElementComponent }], target: i0.ɵɵFactoryTarget.Directive });
1036
+ ElementHoverPlugin.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.17", type: ElementHoverPlugin, ngImport: i0 });
1037
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementHoverPlugin, decorators: [{
1038
+ type: Directive
1039
+ }], ctorParameters: function () { return [{ type: ElementComponent }]; } });
1040
+
1041
+ class IOPlugin {
1042
+ constructor(host) {
1043
+ var _a, _b;
1044
+ this.host = host;
1045
+ const elementMetadata = this.host.injector.get(ELEMENT_METADATA);
1046
+ const inputProvider = this.host.injector.get(IOProviderService);
1047
+ const inputs = Object.entries((_a = elementMetadata.inputs) !== null && _a !== void 0 ? _a : {});
1048
+ const outputs = Object.entries((_b = elementMetadata.outputs) !== null && _b !== void 0 ? _b : {});
1049
+ inputs.forEach(([key, path]) => {
1050
+ var _a;
1051
+ if (path && typeof path !== 'string') {
1052
+ console.error(`The value of '${key}' input should be a string`);
1053
+ }
1054
+ if (((_a = elementMetadata.outputs) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
1055
+ console.warn(`'${key}' appears both in inputs and outputs. To prevent inconsistent behavior please keep them unique `);
1056
+ }
1057
+ this.host[key] = inputProvider.connect(elementMetadata, key, path);
1058
+ });
1059
+ outputs.forEach(([key, path]) => {
1060
+ if (path && typeof path !== 'string') {
1061
+ console.error(`The value of '${key}' output should be a string`);
1062
+ }
1063
+ this.host[key] = inputProvider.provide(elementMetadata, key, path);
1064
+ });
1065
+ }
1066
+ }
1067
+ IOPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IOPlugin, deps: [{ token: ElementComponent }], target: i0.ɵɵFactoryTarget.Directive });
1068
+ IOPlugin.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.17", type: IOPlugin, ngImport: i0 });
1069
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IOPlugin, decorators: [{
1070
+ type: Directive
1071
+ }], ctorParameters: function () { return [{ type: ElementComponent }]; } });
1072
+
1073
+ class ScriptPlugin {
1074
+ constructor(host) {
1075
+ this.host = host;
1076
+ this.normalizeImports = (script, elementPath) => {
1077
+ const regexp = new RegExp(`import([ \\n\\t]*(?:[^ \\n\\t\\{\\}]+[ \\n\\t]*,?)?(?:[ \\n\\t]*\\{(?:[ \\n\\t]*[^ \\n\\t"'\\{\\}]+[ \\n\\t]*,?)+\\})?[ \\n\\t]*)from[ \\n\\t]*(['"])([^'"\\n]+)(?:['"]);`, 'g');
1078
+ const result = script.replace(regexp, (match, g1, g2, src) => {
1079
+ const imports = g1
1080
+ .trim()
1081
+ .slice(1, -1)
1082
+ .split(',')
1083
+ .map(item => item.trim());
1084
+ imports.forEach(item => {
1085
+ var _a;
1086
+ if (!((_a = this.vendorMap[src]) === null || _a === void 0 ? void 0 : _a[item])) {
1087
+ throw new Error(`Failed to import ${item} from '${src}' in ${elementPath}/script.ts`);
1088
+ }
1089
+ });
1090
+ return `const ${g1} = vendor['${src}'];`;
1091
+ });
1092
+ return result;
1093
+ };
1094
+ this.document = this.host.injector.get(DOCUMENT);
1095
+ this.vendorMap = this.host.injector.get(VENDOR_MAP);
1096
+ const elementMetadata = this.host.injector.get(ELEMENT_METADATA);
1097
+ const sharedElementMetadata = this.host.injector.get(SHARED_ELEMENT_METADATA);
1098
+ this.addScript(sharedElementMetadata);
1099
+ this.addScript(elementMetadata);
1100
+ }
1101
+ addScript(metadata) {
1102
+ var _a;
1103
+ if (!(metadata === null || metadata === void 0 ? void 0 : metadata.script)) {
1104
+ return;
1105
+ }
1106
+ const id = btoa(UUID.UUID());
1107
+ const script = this.document.createElement('script');
1108
+ script.type = `text/javascript`;
1109
+ let scriptContent = this.normalizeImports(metadata.script, (_a = metadata.path) !== null && _a !== void 0 ? _a : metadata.name);
1110
+ const classMatch = /export class (\S+)/.exec(scriptContent);
1111
+ const className = classMatch === null || classMatch === void 0 ? void 0 : classMatch[1];
1112
+ if (!classMatch || !className) {
1113
+ console.error("Script doesn't have exported class");
1114
+ return;
1115
+ }
1116
+ scriptContent = scriptContent.replace(classMatch[0], `class ${className}`);
1117
+ script.text = `var ${id} = function(vendor) {${scriptContent}
1118
+ return ${className}; };`;
1119
+ this.document.body.appendChild(script);
1120
+ const ScriptClass = window[id](this.vendorMap);
1121
+ if (ScriptClass instanceof Object) {
1122
+ this.host.registerPlugin(new ScriptClass(this.host));
1123
+ }
1124
+ this.document.body.removeChild(script);
1125
+ }
1126
+ }
1127
+ ScriptPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ScriptPlugin, deps: [{ token: ElementComponent }], target: i0.ɵɵFactoryTarget.Directive });
1128
+ ScriptPlugin.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.17", type: ScriptPlugin, ngImport: i0 });
1129
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ScriptPlugin, decorators: [{
1130
+ type: Directive
1131
+ }], ctorParameters: function () { return [{ type: ElementComponent }]; } });
1132
+
1133
+ /*
1134
+ * ScriptPlugin must always be the last plugin in the list to make sure user code is running after all pre-initializers.
1135
+ */
1136
+ const CONFIG = {
1137
+ CUSTOM: {
1138
+ component: ElementComponent,
1139
+ plugins: [ElementHoverPlugin, IOPlugin, ScriptPlugin],
1140
+ },
1141
+ CONTAINER: {
1142
+ component: ElementComponent,
1143
+ defaultTemplate: '<element-children></element-children>',
1144
+ plugins: [ElementHoverPlugin, ScriptPlugin],
1145
+ },
1146
+ SERVICE: {
1147
+ component: ElementComponent,
1148
+ plugins: [IOPlugin, ScriptPlugin],
1149
+ suppressTemplate: true,
1150
+ suppressStyles: true,
1151
+ },
1152
+ REFERENCE: {
1153
+ component: ElementComponent,
1154
+ plugins: [ElementHoverPlugin, IOPlugin, ScriptPlugin],
1155
+ suppressTemplate: true,
1156
+ },
1157
+ PAGE: {
1158
+ component: ElementComponent,
1159
+ plugins: [ElementHoverPlugin, IOPlugin, ScriptPlugin],
1160
+ },
1161
+ PAGE_LAYOUT: {
1162
+ component: ElementComponent,
1163
+ plugins: [ElementHoverPlugin, IOPlugin, ScriptPlugin],
1164
+ },
1165
+ LAYOUT_REGION: {
1166
+ component: ElementComponent,
1167
+ plugins: [ElementHoverPlugin, IOPlugin, ScriptPlugin],
1168
+ },
1169
+ };
1170
+
1171
+ const EXPORTED_CLASS_REGEX = /export class (\S+)/;
1172
+ const METADATA_DECORATOR_REGEX = /@ElementDefinition\(([\s\S]+)\)(\n|\r\n|.)*export class/g;
1173
+ class UiBuildError extends Error {
1174
+ constructor(message, affectedMetadata) {
1175
+ super(message);
1176
+ this.name = this.constructor.name;
1177
+ this.affectedMetadata = affectedMetadata;
1178
+ }
1179
+ }
1180
+ const elementToMetadata = (el, parentPath) => {
1181
+ var _a;
1182
+ const script = el.script && window.atob(el.script);
1183
+ const template = el.template && window.atob(el.template);
1184
+ const styles = el.styles && window.atob(el.styles);
1185
+ const exportedClassName = script && ((_a = EXPORTED_CLASS_REGEX.exec(script)) !== null && _a !== void 0 ? _a : [])[1];
1186
+ if (!exportedClassName) {
1187
+ throw new Error("Script doesn't have exported class");
1188
+ }
1189
+ const elementMetadata = extractElementMetadata(script || '');
1190
+ const path = (parentPath ? parentPath + '/' : '') + elementMetadata.name;
1191
+ return Object.assign(Object.assign({}, elementMetadata), { path, script: script === null || script === void 0 ? void 0 : script.replace(METADATA_DECORATOR_REGEX, 'export class'), template,
1192
+ styles, children: el.children.map(child => elementToMetadata(child, path)) });
1193
+ };
1194
+ const metadataToElement = (metadata, recursive = true) => {
1195
+ const elMetadata = {
1196
+ name: metadata.name,
1197
+ isShared: metadata.isShared,
1198
+ type: metadata.type,
1199
+ model: metadata.model,
1200
+ module: metadata.module,
1201
+ reference: metadata.reference,
1202
+ inputs: metadata.inputs,
1203
+ outputs: metadata.outputs,
1204
+ children: metadata.children.map(({ name }) => name),
1205
+ configuredStyles: metadata.configuredStyles,
1206
+ };
1207
+ const normalizedElMetadata = normalizeElementMetadata(elMetadata);
1208
+ if (!metadata.script || !EXPORTED_CLASS_REGEX.test(metadata.script)) {
1209
+ throw new UiBuildError(`'${metadata.name}' component script is missing an exported class`, metadata);
1210
+ }
1211
+ const script = metadata.script &&
1212
+ window.btoa(metadata.script.replace(EXPORTED_CLASS_REGEX, `@ElementDefinition(${stringifyElementMetadata(normalizedElMetadata)})\nexport class Script`));
1213
+ const template = metadata.template && window.btoa(metadata.template);
1214
+ const styles = metadata.styles && window.btoa(metadata.styles);
1215
+ return {
1216
+ script,
1217
+ template,
1218
+ styles,
1219
+ children: recursive ? metadata.children.map(meta => metadataToElement(meta)) : [],
1220
+ };
1221
+ };
1222
+ const normalizeElementMetadata = (elementMetadata) => {
1223
+ var _a, _b, _c, _d;
1224
+ const metadata = Object.assign({}, elementMetadata);
1225
+ // model
1226
+ const { lineItem, path } = (_a = metadata.model) !== null && _a !== void 0 ? _a : {};
1227
+ const model = lineItem ? { lineItem } : path ? { path } : undefined;
1228
+ if (model) {
1229
+ metadata.model = model;
802
1230
  }
803
- }
804
- CustomTemplateDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: CustomTemplateDirective, deps: [{ token: i0.TemplateRef }, { token: TemplatesService }], target: i0.ɵɵFactoryTarget.Directive });
805
- CustomTemplateDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.17", type: CustomTemplateDirective, selector: "[customTemplate]", inputs: { customTemplate: "customTemplate" }, ngImport: i0 });
806
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: CustomTemplateDirective, decorators: [{
807
- type: Directive,
808
- args: [{ selector: '[customTemplate]' }]
809
- }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: TemplatesService }]; }, propDecorators: { customTemplate: [{
810
- type: Input
811
- }] } });
812
-
813
- const defaultOptions = {
814
- suppressLoading: false,
815
- loadingLabel: 'LOADING',
1231
+ else {
1232
+ delete metadata.model;
1233
+ }
1234
+ // module
1235
+ if (!metadata.module) {
1236
+ delete metadata.module;
1237
+ }
1238
+ // reference
1239
+ if (!metadata.reference) {
1240
+ delete metadata.reference;
1241
+ }
1242
+ // inputs
1243
+ const inputs = Object.entries((_b = metadata.inputs) !== null && _b !== void 0 ? _b : {}).reduce((acc, [key, value]) => {
1244
+ return Object.assign(Object.assign({}, acc), { [key]: value || null });
1245
+ }, {});
1246
+ if (inputs && Object.keys(inputs).length > 0) {
1247
+ metadata.inputs = inputs;
1248
+ }
1249
+ else {
1250
+ delete metadata.inputs;
1251
+ }
1252
+ // outputs
1253
+ const outputs = Object.entries((_c = metadata.outputs) !== null && _c !== void 0 ? _c : {}).reduce((acc, [key, value]) => {
1254
+ return Object.assign(Object.assign({}, acc), { [key]: value || null });
1255
+ }, {});
1256
+ if (outputs && Object.keys(outputs).length > 0) {
1257
+ metadata.outputs = outputs;
1258
+ }
1259
+ else {
1260
+ delete metadata.outputs;
1261
+ }
1262
+ // children
1263
+ if (!((_d = metadata.children) === null || _d === void 0 ? void 0 : _d.length)) {
1264
+ delete metadata.children;
1265
+ }
1266
+ // isShared
1267
+ if (!metadata.isShared) {
1268
+ delete metadata.isShared;
1269
+ }
1270
+ // configuredStyles
1271
+ if (!metadata.configuredStyles) {
1272
+ delete metadata.configuredStyles;
1273
+ }
1274
+ return metadata;
816
1275
  };
817
-
818
- const moduleMap = {};
819
- function loadRemoteEntry(remoteEntry) {
820
- return new Promise((resolve, reject) => {
821
- if (moduleMap[remoteEntry]) {
822
- resolve();
823
- return;
824
- }
825
- const script = document.createElement('script');
826
- script.src = remoteEntry;
827
- script.onerror = reject;
828
- script.onload = () => {
829
- moduleMap[remoteEntry] = true;
830
- resolve(); // window is the global namespace
831
- };
832
- document.body.append(script);
833
- });
834
- }
835
- function lookupExposedModule(remoteName, exposedModule) {
836
- return __awaiter(this, void 0, void 0, function* () {
837
- // Initializes the share scope. This fills it with known provided modules from this build and all remotes
838
- yield __webpack_init_sharing__('default');
839
- const container = window[remoteName]; // or get the container somewhere else
840
- // Initialize the container, it may provide shared modules
841
- yield container.init(__webpack_share_scopes__.default);
842
- const factory = yield container.get(exposedModule);
843
- const Module = factory();
844
- return Module;
845
- });
846
- }
847
- function loadRemoteModule(remoteEntry, remoteName, exposedModule) {
848
- return __awaiter(this, void 0, void 0, function* () {
849
- yield loadRemoteEntry(remoteEntry);
850
- return yield lookupExposedModule(remoteName, exposedModule);
1276
+ const extractElementMetadata = (script) => {
1277
+ var _a;
1278
+ const metadataString = ((_a = METADATA_DECORATOR_REGEX.exec(script)) !== null && _a !== void 0 ? _a : [])[1];
1279
+ // need to reset regex last index to prevent null result for next execution
1280
+ METADATA_DECORATOR_REGEX.lastIndex = 0;
1281
+ return new Function(`return ${metadataString}`)();
1282
+ };
1283
+ const extendElementMetadata = (script, extend) => {
1284
+ var _a;
1285
+ const metadataString = ((_a = METADATA_DECORATOR_REGEX.exec(script)) !== null && _a !== void 0 ? _a : [])[1];
1286
+ // need to reset regex last index to prevent null result for next execution
1287
+ METADATA_DECORATOR_REGEX.lastIndex = 0;
1288
+ if (!metadataString) {
1289
+ return script;
1290
+ }
1291
+ const updated = Object.assign(Object.assign({}, new Function(`return ${metadataString}`)()), extend);
1292
+ return script.replace(metadataString, stringifyElementMetadata(updated));
1293
+ };
1294
+ const getElementConfig = (type) => {
1295
+ return CONFIG[type];
1296
+ };
1297
+ const doesElementSupportIO = (type) => {
1298
+ var _a, _b;
1299
+ return (_b = (_a = getElementConfig(type).plugins) === null || _a === void 0 ? void 0 : _a.includes(IOPlugin)) !== null && _b !== void 0 ? _b : false;
1300
+ };
1301
+ function stringifyElementMetadata(elementMetadata) {
1302
+ const cleaned = JSON.stringify(elementMetadata, null, 2);
1303
+ return cleaned.replace(/^[\t ]*"[^:\n\r]+(?<!\\)":/gm, function (match) {
1304
+ return match.replace(/"/g, '');
851
1305
  });
852
1306
  }
853
-
854
- class FederatedComponent {
855
- constructor(injector, compiler, appRef, renderer) {
856
- this.injector = injector;
857
- this.compiler = compiler;
858
- this.appRef = appRef;
859
- this.renderer = renderer;
860
- this.isLoading$ = new BehaviorSubject(false);
861
- // configs
862
- this.suppressLoading = defaultOptions.suppressLoading;
863
- this.loadingLabel = defaultOptions.loadingLabel;
864
- }
865
- ngOnChanges(changes) {
866
- var _a, _b, _c, _d;
867
- if (changes.data && this.instance) {
868
- this.instance.data = this.data;
869
- }
870
- if (changes.options) {
871
- this.suppressLoading = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.suppressLoading) !== null && _b !== void 0 ? _b : defaultOptions.suppressLoading;
872
- this.loadingLabel = (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.loadingLabel) !== null && _d !== void 0 ? _d : defaultOptions.loadingLabel;
873
- }
1307
+ const isValidScript = (script) => {
1308
+ var _a;
1309
+ if (!script) {
1310
+ return false;
874
1311
  }
875
- ngOnInit() {
876
- this.isLoading$.next(true);
1312
+ const exportedClassName = script && ((_a = EXPORTED_CLASS_REGEX.exec(script)) !== null && _a !== void 0 ? _a : [])[1];
1313
+ if (!exportedClassName) {
1314
+ return false;
877
1315
  }
878
- ngAfterViewInit() {
879
- var _a, _b, _c, _d, _e, _f;
880
- const remoteEntry = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.remoteEntry) !== null && _b !== void 0 ? _b : this.remoteEntry;
881
- const remoteName = (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.remoteName) !== null && _d !== void 0 ? _d : this.remoteName;
882
- const exposedModule = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.exposedModule) !== null && _f !== void 0 ? _f : this.exposedModule;
883
- if (!remoteEntry || !remoteName || !exposedModule) {
884
- return;
885
- }
886
- loadRemoteModule(remoteEntry, remoteName, exposedModule).then(federated => {
887
- this.compiler.compileModuleAsync(federated[exposedModule]).then(moduleFactory => {
888
- var _a, _b, _c;
889
- const rootModuleRef = moduleFactory.create(this.injector);
890
- const rootComponentFactory = rootModuleRef.componentFactoryResolver.resolveComponentFactory(federated[exposedModule].rootComponent);
891
- const node = document.createElement('div');
892
- const { instance, hostView } = rootComponentFactory.create(this.injector, [], node);
893
- this.instance = instance;
894
- this.instance.data = this.data;
895
- this.renderer.appendChild((_a = this.moduleHostRef) === null || _a === void 0 ? void 0 : _a.nativeElement, node);
896
- this.appRef.attachView(hostView);
897
- (_c = (_b = this.options) === null || _b === void 0 ? void 0 : _b.onReady) === null || _c === void 0 ? void 0 : _c.call(_b);
898
- this.isLoading$.next(false);
899
- });
900
- });
1316
+ const meta = extractElementMetadata(script);
1317
+ if (!meta.name || !meta.type) {
1318
+ return false;
901
1319
  }
1320
+ return true;
1321
+ };
1322
+ function flattenElements(elements) {
1323
+ return flatten(elements.map(el => [el, ...flattenElements(el.children)]));
902
1324
  }
903
- FederatedComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedComponent, deps: [{ token: i0.Injector }, { token: i0.Compiler }, { token: i0.ApplicationRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
904
- FederatedComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: FederatedComponent, selector: "veloce-host-federated", inputs: { remoteEntry: "remoteEntry", remoteName: "remoteName", exposedModule: "exposedModule", data: "data", options: "options" }, viewQueries: [{ propertyName: "moduleHostRef", first: true, predicate: ["moduleHost"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<div #moduleHost></div>\n\n<vl-loader *ngIf=\"!suppressLoading && (isLoading$ | async)\" [label]=\"loadingLabel\"></vl-loader>\n", styles: [":host{display:block}div{height:100%}\n"], components: [{ type: i1.LoaderComponent, selector: "vl-loader", inputs: ["label", "overlayVisible"] }], directives: [{ type: i7.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "async": i7.AsyncPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
905
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedComponent, decorators: [{
906
- type: Component,
907
- args: [{
908
- // eslint-disable-next-line @angular-eslint/component-selector
909
- selector: 'veloce-host-federated',
910
- templateUrl: './federated.component.html',
911
- styleUrls: ['./federated.component.scss'],
912
- changeDetection: ChangeDetectionStrategy.OnPush,
913
- }]
914
- }], ctorParameters: function () { return [{ type: i0.Injector }, { type: i0.Compiler }, { type: i0.ApplicationRef }, { type: i0.Renderer2 }]; }, propDecorators: { moduleHostRef: [{
915
- type: ViewChild,
916
- args: ['moduleHost', { static: false }]
917
- }], remoteEntry: [{
918
- type: Input
919
- }], remoteName: [{
920
- type: Input
921
- }], exposedModule: [{
922
- type: Input
923
- }], data: [{
924
- type: Input
925
- }], options: [{
926
- type: Input
927
- }] } });
928
-
929
- class FederatedModule {
1325
+ function isSharedElement(el) {
1326
+ return Boolean(el.isShared) && el.type !== 'REFERENCE';
930
1327
  }
931
- FederatedModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
932
- FederatedModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedModule, declarations: [FederatedComponent], imports: [CommonModule, LoaderModule], exports: [FederatedComponent] });
933
- FederatedModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedModule, imports: [[CommonModule, LoaderModule]] });
934
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedModule, decorators: [{
935
- type: NgModule,
936
- args: [{
937
- declarations: [FederatedComponent],
938
- imports: [CommonModule, LoaderModule],
939
- exports: [FederatedComponent],
940
- }]
941
- }] });
942
1328
 
943
1329
  class ConfigurationPlugin {
944
1330
  constructor(host) {
@@ -979,9 +1365,17 @@ class ConfigurationPlugin {
979
1365
  if (!rootLineItem || !this.modelSnapshot) {
980
1366
  return;
981
1367
  }
982
- this.configurationService.patch(new LineItemWorker(rootLineItem).remove(this.modelSnapshot.id).li);
1368
+ this.configurationService.patch(new LineItemWorker(rootLineItem).remove(this.modelSnapshot.id).li);
1369
+ };
1370
+ const updateQty = (qty) => {
1371
+ const rootLineItem = this.configurationService.getSnapshot();
1372
+ if (!rootLineItem || !this.modelSnapshot) {
1373
+ return;
1374
+ }
1375
+ this.configurationService.patch(new LineItemWorker(rootLineItem).replace(Object.assign(Object.assign({}, this.modelSnapshot), { qty })).li);
983
1376
  };
984
1377
  this.typeHost.remove = remove;
1378
+ this.typeHost.updateQty = updateQty;
985
1379
  }
986
1380
  registerPort(name) {
987
1381
  const model$ = this.host.model$;
@@ -1037,43 +1431,6 @@ const DEFAULT_PLUGINS = {
1037
1431
  DEFAULT: [],
1038
1432
  };
1039
1433
 
1040
- const InitAction = { type: 'INIT' };
1041
- const ClearAction = { type: 'CLEAR' };
1042
- class IntegrationState {
1043
- constructor() {
1044
- this.stateSubj$ = new BehaviorSubject({});
1045
- this.action$ = new BehaviorSubject(InitAction);
1046
- }
1047
- get state$() {
1048
- return this.stateSubj$.asObservable();
1049
- }
1050
- get state() {
1051
- return this.stateSubj$.getValue();
1052
- }
1053
- patchState(update) {
1054
- this.stateSubj$.next(Object.assign(Object.assign({}, this.stateSubj$.getValue()), update));
1055
- }
1056
- dispatch(action) {
1057
- this.action$.next(action);
1058
- }
1059
- listen$(actionType) {
1060
- return this.action$.pipe(filter(action => action.type === actionType), map(action => action.payload));
1061
- }
1062
- listenAll$() {
1063
- return this.action$.asObservable();
1064
- }
1065
- clear() {
1066
- this.stateSubj$.next({});
1067
- this.action$.next(ClearAction);
1068
- }
1069
- }
1070
- IntegrationState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IntegrationState, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1071
- IntegrationState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IntegrationState, providedIn: 'root' });
1072
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IntegrationState, decorators: [{
1073
- type: Injectable,
1074
- args: [{ providedIn: 'root' }]
1075
- }] });
1076
-
1077
1434
  const VELOCE_LIBS = {
1078
1435
  '@veloceapps/sdk/core': Object.assign({ ConfigurationService,
1079
1436
  QuoteDraftService,
@@ -1110,11 +1467,19 @@ class ElementsResolver {
1110
1467
  this.sharedElements = [];
1111
1468
  const transpiledElements = this.transpileScripts(elements);
1112
1469
  this.sharedElements = this.flattenElements(transpiledElements).filter(el => this.isSharedElement(el));
1113
- this.elements = transpiledElements.map(el => this.processElementMetadata(el)).filter(Boolean);
1470
+ this.elements = transpiledElements.map(el => this.processElementMetadata(el)).filter(isDefined);
1471
+ this.renderableElements = this.getRenderableElements(this.elements);
1472
+ }
1473
+ addElement(element) {
1474
+ if (element.isShared) {
1475
+ return;
1476
+ }
1477
+ const transpiledElements = this.transpileScripts([element]);
1478
+ this.elements = transpiledElements.map(el => this.processElementMetadata(el)).filter(isDefined);
1114
1479
  this.renderableElements = this.getRenderableElements(this.elements);
1115
1480
  }
1116
1481
  getNgComponents() {
1117
- return this.renderableElements.map(el => this.resolveElement(el)).filter(Boolean);
1482
+ return this.renderableElements.map(el => this.resolveElement(el)).filter(isDefined);
1118
1483
  }
1119
1484
  transpile(el) {
1120
1485
  var _a;
@@ -1181,9 +1546,7 @@ class ElementsResolver {
1181
1546
  }
1182
1547
  finalElement.template = this.resolveElementTemplate(finalElement);
1183
1548
  finalElement.styles = this.resolveElementStyles(finalElement);
1184
- return Object.assign(Object.assign({}, finalElement), { children: finalElement.children
1185
- .map(child => this.processElementMetadata(child))
1186
- .filter(Boolean) });
1549
+ return Object.assign(Object.assign({}, finalElement), { children: finalElement.children.map(child => this.processElementMetadata(child)).filter(isDefined) });
1187
1550
  }
1188
1551
  getSharedChildren(children, parentPath) {
1189
1552
  return children.map(c => {
@@ -1243,202 +1606,235 @@ class ElementsResolver {
1243
1606
  }
1244
1607
  }
1245
1608
 
1246
- class LauncherService {
1247
- constructor(compiler, dynamicModuleService) {
1248
- this.compiler = compiler;
1249
- this.dynamicModuleService = dynamicModuleService;
1250
- }
1251
- compileModule(uiDef, elements) {
1252
- const elementsResolver = new ElementsResolver(uiDef, elements);
1253
- this.dynamicModuleService.elementsTree = elementsResolver.elements;
1254
- this.module = this.getModule(elementsResolver.getNgComponents());
1255
- return from(this.compiler.compileModuleAndAllComponentsAsync(this.module)).pipe(tap(m => {
1256
- this.dynamicModuleService.componentFactories = m.componentFactories;
1257
- this.moduleInstance = m;
1258
- }), map(m => ({ module: m, elements: elementsResolver.elements })));
1259
- }
1260
- destroy() {
1261
- if (this.moduleInstance) {
1262
- this.dynamicModuleService.clear();
1263
- this.moduleInstance = undefined;
1264
- }
1265
- if (this.module) {
1266
- this.compiler.clearCacheFor(this.module);
1267
- this.module = undefined;
1609
+ const defaultOptions = {
1610
+ suppressLoading: false,
1611
+ loadingLabel: 'LOADING',
1612
+ };
1613
+
1614
+ const moduleMap = {};
1615
+ function loadRemoteEntry(remoteEntry) {
1616
+ return new Promise((resolve, reject) => {
1617
+ if (moduleMap[remoteEntry]) {
1618
+ resolve();
1619
+ return;
1268
1620
  }
1269
- }
1270
- getModule(components) {
1271
- const staticComponents = [ElementChildrenComponent, ElementRendererComponent, CustomTemplateDirective];
1272
- let DynamicModule = class DynamicModule {
1621
+ const script = document.createElement('script');
1622
+ script.src = remoteEntry;
1623
+ script.onerror = reject;
1624
+ script.onload = () => {
1625
+ moduleMap[remoteEntry] = true;
1626
+ resolve(); // window is the global namespace
1273
1627
  };
1274
- DynamicModule = __decorate([
1275
- NgModule({
1276
- imports: [CommonModule, FormsModule, ReactiveFormsModule, FederatedModule, DragDropModule, ScrollingModule],
1277
- declarations: [...staticComponents, ...components],
1278
- jit: true,
1279
- })
1280
- ], DynamicModule);
1281
- return DynamicModule;
1282
- }
1628
+ document.body.append(script);
1629
+ });
1630
+ }
1631
+ function lookupExposedModule(remoteName, exposedModule) {
1632
+ return __awaiter(this, void 0, void 0, function* () {
1633
+ // Initializes the share scope. This fills it with known provided modules from this build and all remotes
1634
+ yield __webpack_init_sharing__('default');
1635
+ const container = window[remoteName]; // or get the container somewhere else
1636
+ // Initialize the container, it may provide shared modules
1637
+ yield container.init(__webpack_share_scopes__.default);
1638
+ const factory = yield container.get(exposedModule);
1639
+ const Module = factory();
1640
+ return Module;
1641
+ });
1642
+ }
1643
+ function loadRemoteModule(remoteEntry, remoteName, exposedModule) {
1644
+ return __awaiter(this, void 0, void 0, function* () {
1645
+ yield loadRemoteEntry(remoteEntry);
1646
+ return yield lookupExposedModule(remoteName, exposedModule);
1647
+ });
1283
1648
  }
1284
- LauncherService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LauncherService, deps: [{ token: i0.Compiler }, { token: DynamicModuleService }], target: i0.ɵɵFactoryTarget.Injectable });
1285
- LauncherService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LauncherService });
1286
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LauncherService, decorators: [{
1287
- type: Injectable
1288
- }], ctorParameters: function () { return [{ type: i0.Compiler }, { type: DynamicModuleService }]; } });
1289
1649
 
1290
- class PreviewComponent {
1291
- constructor(launcherService, configurationService, messageService, runtimeService, integrationState) {
1292
- this.launcherService = launcherService;
1293
- this.configurationService = configurationService;
1294
- this.messageService = messageService;
1295
- this.runtimeService = runtimeService;
1296
- this.integrationState = integrationState;
1297
- this.clearState = false;
1298
- this.state$ = new BehaviorSubject({ loading: true, failure: false });
1299
- this.elements = [];
1300
- this.destroy$ = new Subject();
1301
- }
1302
- ngOnInit() {
1303
- if (this.clearState) {
1304
- this.integrationState.clear();
1305
- }
1306
- this.startPreview();
1307
- }
1308
- ngOnDestroy() {
1309
- this.destroy$.next();
1310
- this.destroy$.complete();
1311
- this.configurationService.reset();
1650
+ class FederatedComponent {
1651
+ constructor(injector, compiler, appRef, renderer) {
1652
+ this.injector = injector;
1653
+ this.compiler = compiler;
1654
+ this.appRef = appRef;
1655
+ this.renderer = renderer;
1656
+ this.isLoading$ = new BehaviorSubject(false);
1657
+ // configs
1658
+ this.suppressLoading = defaultOptions.suppressLoading;
1659
+ this.loadingLabel = defaultOptions.loadingLabel;
1312
1660
  }
1313
- initializeConfiguration$() {
1314
- const isAlreadyInitialized = this.runtimeService.isInitialized;
1315
- if (!this.uiDefinition || this.uiDefinition.type !== 'CONFIGURATION' || isAlreadyInitialized) {
1316
- return of({});
1661
+ ngOnChanges(changes) {
1662
+ var _a, _b, _c, _d;
1663
+ if (changes.data && this.instance) {
1664
+ this.instance.data = this.data;
1317
1665
  }
1318
- if (!this.modelId) {
1319
- console.warn(`No modelId is given for uiDefinition with '${this.uiDefinition.type}' type`);
1320
- return of({});
1666
+ if (changes.options) {
1667
+ this.suppressLoading = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.suppressLoading) !== null && _b !== void 0 ? _b : defaultOptions.suppressLoading;
1668
+ this.loadingLabel = (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.loadingLabel) !== null && _d !== void 0 ? _d : defaultOptions.loadingLabel;
1321
1669
  }
1322
- // If still not initialized - init configuration in Test mode
1323
- return this.runtimeService
1324
- .initTestMode(this.modelId, this.uiDefinition)
1325
- .pipe(switchMap(() => this.configurationService.configure()));
1326
1670
  }
1327
- elementToMetadataSafe(elements) {
1328
- var _a, _b;
1329
- try {
1330
- return elements.map(element => elementToMetadata(element));
1331
- }
1332
- catch (e) {
1333
- console.error(e);
1334
- if (!((_b = (_a = this.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.suppressToastMessages)) {
1335
- this.messageService.add({ severity: 'error', summary: String(e) });
1336
- }
1337
- return [];
1338
- }
1671
+ ngOnInit() {
1672
+ this.isLoading$.next(true);
1339
1673
  }
1340
- startPreview() {
1341
- if (!this.uiDefinition) {
1674
+ ngAfterViewInit() {
1675
+ var _a, _b, _c, _d, _e, _f;
1676
+ const remoteEntry = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.remoteEntry) !== null && _b !== void 0 ? _b : this.remoteEntry;
1677
+ const remoteName = (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.remoteName) !== null && _d !== void 0 ? _d : this.remoteName;
1678
+ const exposedModule = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.exposedModule) !== null && _f !== void 0 ? _f : this.exposedModule;
1679
+ if (!remoteEntry || !remoteName || !exposedModule) {
1342
1680
  return;
1343
1681
  }
1344
- const _a = this.uiDefinition, { children } = _a, uiDefinitionMeta = __rest(_a, ["children"]);
1345
- const elements = this.elementToMetadataSafe(children);
1346
- const compilation$ = this.launcherService.compileModule(uiDefinitionMeta, elements);
1347
- forkJoin([compilation$, this.initializeConfiguration$()])
1348
- .pipe(tap(([result]) => {
1349
- this.elements = result.elements;
1350
- this.state$.next({ loading: false, failure: false });
1351
- }), catchError(error => {
1352
- var _a, _b;
1353
- console.error(error);
1354
- if (!((_b = (_a = this.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.suppressToastMessages)) {
1355
- this.messageService.add({ severity: 'error', summary: error });
1356
- }
1357
- this.state$.next({ loading: false, failure: true });
1358
- return of();
1359
- }), takeUntil(this.destroy$))
1360
- .subscribe();
1682
+ loadRemoteModule(remoteEntry, remoteName, exposedModule).then(federated => {
1683
+ this.compiler.compileModuleAsync(federated[exposedModule]).then(moduleFactory => {
1684
+ var _a, _b, _c;
1685
+ const rootModuleRef = moduleFactory.create(this.injector);
1686
+ const rootComponentFactory = rootModuleRef.componentFactoryResolver.resolveComponentFactory(federated[exposedModule].rootComponent);
1687
+ const node = document.createElement('div');
1688
+ const { instance, hostView } = rootComponentFactory.create(this.injector, [], node);
1689
+ this.instance = instance;
1690
+ this.instance.data = this.data;
1691
+ this.renderer.appendChild((_a = this.moduleHostRef) === null || _a === void 0 ? void 0 : _a.nativeElement, node);
1692
+ this.appRef.attachView(hostView);
1693
+ (_c = (_b = this.options) === null || _b === void 0 ? void 0 : _b.onReady) === null || _c === void 0 ? void 0 : _c.call(_b);
1694
+ this.isLoading$.next(false);
1695
+ });
1696
+ });
1361
1697
  }
1362
1698
  }
1363
- PreviewComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewComponent, deps: [{ token: LauncherService }, { token: i2.ConfigurationService }, { token: i3.MessageService }, { token: i2.ConfigurationRuntimeService }, { token: IntegrationState }], target: i0.ɵɵFactoryTarget.Component });
1364
- PreviewComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: PreviewComponent, selector: "vl-cms-preview", inputs: { modelId: "modelId", uiDefinition: "uiDefinition", clearState: "clearState" }, providers: [IOProviderService, TemplatesService], ngImport: i0, template: "<ng-container *ngIf=\"state$ | async as state\">\n <vl-loader *ngIf=\"state.loading; else content\" [label]=\"'Loading UI'\"></vl-loader>\n\n <ng-template #content>\n <ng-container *ngIf=\"!state.failure\">\n <vl-cms-element-renderer *ngFor=\"let el of elements\" [meta]=\"el\"></vl-cms-element-renderer>\n </ng-container>\n </ng-template>\n</ng-container>\n", styles: [":host{flex-grow:1;display:flex;flex-direction:column;height:100%}\n"], components: [{ type: i1.LoaderComponent, selector: "vl-loader", inputs: ["label", "overlayVisible"] }, { type: ElementRendererComponent, selector: "vl-cms-element-renderer", inputs: ["meta"] }], directives: [{ type: i7.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i7.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], pipes: { "async": i7.AsyncPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.ShadowDom });
1365
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewComponent, decorators: [{
1699
+ FederatedComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedComponent, deps: [{ token: i0.Injector }, { token: i0.Compiler }, { token: i0.ApplicationRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
1700
+ FederatedComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: FederatedComponent, selector: "veloce-host-federated", inputs: { remoteEntry: "remoteEntry", remoteName: "remoteName", exposedModule: "exposedModule", data: "data", options: "options" }, viewQueries: [{ propertyName: "moduleHostRef", first: true, predicate: ["moduleHost"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<div #moduleHost></div>\n\n<vl-loader *ngIf=\"!suppressLoading && (isLoading$ | async)\" [label]=\"loadingLabel\"></vl-loader>\n", styles: [":host{display:block}div{height:100%}\n"], components: [{ type: i5.LoaderComponent, selector: "vl-loader", inputs: ["label", "overlayVisible"] }], directives: [{ type: i7.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "async": i7.AsyncPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
1701
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedComponent, decorators: [{
1366
1702
  type: Component,
1367
1703
  args: [{
1368
- selector: 'vl-cms-preview',
1369
- templateUrl: './preview.component.html',
1370
- styleUrls: ['./preview.component.scss'],
1704
+ // eslint-disable-next-line @angular-eslint/component-selector
1705
+ selector: 'veloce-host-federated',
1706
+ templateUrl: './federated.component.html',
1707
+ styleUrls: ['./federated.component.scss'],
1371
1708
  changeDetection: ChangeDetectionStrategy.OnPush,
1372
- providers: [IOProviderService, TemplatesService],
1373
- // use shadow DOM to prevent UI from being affected by global styles
1374
- encapsulation: ViewEncapsulation.ShadowDom,
1375
1709
  }]
1376
- }], ctorParameters: function () { return [{ type: LauncherService }, { type: i2.ConfigurationService }, { type: i3.MessageService }, { type: i2.ConfigurationRuntimeService }, { type: IntegrationState }]; }, propDecorators: { modelId: [{
1710
+ }], ctorParameters: function () { return [{ type: i0.Injector }, { type: i0.Compiler }, { type: i0.ApplicationRef }, { type: i0.Renderer2 }]; }, propDecorators: { moduleHostRef: [{
1711
+ type: ViewChild,
1712
+ args: ['moduleHost', { static: false }]
1713
+ }], remoteEntry: [{
1377
1714
  type: Input
1378
- }], uiDefinition: [{
1715
+ }], remoteName: [{
1716
+ type: Input
1717
+ }], exposedModule: [{
1718
+ type: Input
1719
+ }], data: [{
1379
1720
  type: Input
1380
- }], clearState: [{
1721
+ }], options: [{
1381
1722
  type: Input
1382
1723
  }] } });
1383
1724
 
1384
- class ElementRendererModule {
1725
+ class FederatedModule {
1385
1726
  }
1386
- ElementRendererModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1387
- ElementRendererModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererModule, declarations: [ElementRendererComponent], exports: [ElementRendererComponent] });
1388
- ElementRendererModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererModule });
1389
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementRendererModule, decorators: [{
1727
+ FederatedModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1728
+ FederatedModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedModule, declarations: [FederatedComponent], imports: [CommonModule, LoaderModule], exports: [FederatedComponent] });
1729
+ FederatedModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedModule, imports: [[CommonModule, LoaderModule]] });
1730
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FederatedModule, decorators: [{
1390
1731
  type: NgModule,
1391
1732
  args: [{
1392
- declarations: [ElementRendererComponent],
1393
- exports: [ElementRendererComponent],
1733
+ declarations: [FederatedComponent],
1734
+ imports: [CommonModule, LoaderModule],
1735
+ exports: [FederatedComponent],
1394
1736
  }]
1395
1737
  }] });
1396
1738
 
1397
- class ElementChildrenModule {
1739
+ class CompilationService {
1740
+ constructor(compiler) {
1741
+ this.compiler = compiler;
1742
+ }
1743
+ compileUIDefinition$(uiDefinition) {
1744
+ this.uiDefinitionMeta = omit(uiDefinition, 'children');
1745
+ return of([]).pipe(switchMap(() => {
1746
+ const metadata = uiDefinition.children.map(element => elementToMetadata(element));
1747
+ this.elementsResolver = new ElementsResolver(uiDefinition, metadata);
1748
+ const module = this.getModule(this.elementsResolver.getNgComponents());
1749
+ return combineLatest([
1750
+ from(this.compiler.compileModuleAndAllComponentsAsync(module)),
1751
+ of(this.elementsResolver),
1752
+ ]);
1753
+ }), map(([module, elementsResolver]) => ({ module, elements: elementsResolver.elements })));
1754
+ }
1755
+ compileElement$(element) {
1756
+ if (!this.uiDefinitionMeta) {
1757
+ throw 'No UI Definition context';
1758
+ }
1759
+ return of(this.uiDefinitionMeta).pipe(switchMap(uiDefinition => {
1760
+ var _a;
1761
+ const elementsResolver = (_a = this.elementsResolver) !== null && _a !== void 0 ? _a : new ElementsResolver(uiDefinition, []);
1762
+ elementsResolver.addElement(element);
1763
+ const module = this.getModule(elementsResolver.getNgComponents());
1764
+ return combineLatest([from(this.compiler.compileModuleAndAllComponentsAsync(module)), of(elementsResolver)]);
1765
+ }), map(([module, elementsResolver]) => ({ module, elements: elementsResolver.elements })));
1766
+ }
1767
+ clearModuleCache(modules) {
1768
+ modules.forEach(module => this.compiler.clearCacheFor(module));
1769
+ this.uiDefinitionMeta = undefined;
1770
+ }
1771
+ getModule(components) {
1772
+ const staticComponents = [
1773
+ ElementChildrenComponent,
1774
+ ElementRendererComponent,
1775
+ ElementDropHandleComponent,
1776
+ CustomTemplateDirective,
1777
+ ];
1778
+ let DynamicModule = class DynamicModule {
1779
+ };
1780
+ DynamicModule = __decorate([
1781
+ NgModule({
1782
+ imports: [
1783
+ CommonModule,
1784
+ FormsModule,
1785
+ ReactiveFormsModule,
1786
+ FederatedModule,
1787
+ DragDropModule,
1788
+ DndModule,
1789
+ ScrollingModule,
1790
+ ],
1791
+ declarations: [...staticComponents, ...components],
1792
+ jit: true,
1793
+ })
1794
+ ], DynamicModule);
1795
+ return DynamicModule;
1796
+ }
1398
1797
  }
1399
- ElementChildrenModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1400
- ElementChildrenModulemod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenModule, declarations: [ElementChildrenComponent], imports: [ElementRendererModule], exports: [ElementChildrenComponent] });
1401
- ElementChildrenModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenModule, imports: [[ElementRendererModule]] });
1402
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ElementChildrenModule, decorators: [{
1403
- type: NgModule,
1404
- args: [{
1405
- declarations: [ElementChildrenComponent],
1406
- imports: [ElementRendererModule],
1407
- exports: [ElementChildrenComponent],
1408
- }]
1409
- }] });
1798
+ CompilationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: CompilationService, deps: [{ token: i0.Compiler }], target: i0.ɵɵFactoryTarget.Injectable });
1799
+ CompilationServiceprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: CompilationService });
1800
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: CompilationService, decorators: [{
1801
+ type: Injectable
1802
+ }], ctorParameters: function () { return [{ type: i0.Compiler }]; } });
1410
1803
 
1411
- class PreviewModule {
1804
+ class RuntimeModule {
1412
1805
  }
1413
- PreviewModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1414
- PreviewModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewModule, declarations: [PreviewComponent], imports: [CommonModule, LoaderModule, ElementRendererModule, ElementChildrenModule], exports: [PreviewComponent] });
1415
- PreviewModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewModule, providers: [IntegrationState], imports: [[CommonModule, LoaderModule, ElementRendererModule, ElementChildrenModule]] });
1416
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PreviewModule, decorators: [{
1806
+ RuntimeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1807
+ RuntimeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeModule, imports: [CommonModule, CoreModule] });
1808
+ RuntimeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeModule, providers: [
1809
+ DialogService,
1810
+ RuntimeService,
1811
+ RuntimeEditorService,
1812
+ { provide: CMS_COMPILATION_SERVICE, useClass: CompilationService },
1813
+ ], imports: [[CommonModule, CoreModule]] });
1814
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeModule, decorators: [{
1417
1815
  type: NgModule,
1418
1816
  args: [{
1419
- declarations: [PreviewComponent],
1420
- imports: [CommonModule, LoaderModule, ElementRendererModule, ElementChildrenModule],
1421
- providers: [IntegrationState],
1422
- exports: [PreviewComponent],
1817
+ imports: [CommonModule, CoreModule],
1818
+ providers: [
1819
+ DialogService,
1820
+ RuntimeService,
1821
+ RuntimeEditorService,
1822
+ { provide: CMS_COMPILATION_SERVICE, useClass: CompilationService },
1823
+ ],
1423
1824
  }]
1424
1825
  }] });
1425
1826
 
1426
- function ElementDefinition(definition) {
1427
- return function (constructor) {
1428
- return constructor;
1429
- };
1430
- }
1431
-
1432
1827
  class LauncherModule {
1433
1828
  }
1434
1829
  LauncherModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LauncherModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1435
- LauncherModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LauncherModule, imports: [CommonModule, CoreModule, ApiModule, SdkCoreModule] });
1436
- LauncherModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LauncherModule, providers: [LauncherService, IntegrationState, DynamicModuleService, DialogService], imports: [[CommonModule, CoreModule, ApiModule, SdkCoreModule]] });
1830
+ LauncherModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LauncherModule, imports: [CommonModule, CoreModule, ApiModule, SdkCoreModule, RuntimeModule, PreviewModule], exports: [PreviewModule] });
1831
+ LauncherModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LauncherModule, providers: [IntegrationState, DialogService], imports: [[CommonModule, CoreModule, ApiModule, SdkCoreModule, RuntimeModule, PreviewModule], PreviewModule] });
1437
1832
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LauncherModule, decorators: [{
1438
1833
  type: NgModule,
1439
1834
  args: [{
1440
- imports: [CommonModule, CoreModule, ApiModule, SdkCoreModule],
1441
- providers: [LauncherService, IntegrationState, DynamicModuleService, DialogService],
1835
+ imports: [CommonModule, CoreModule, ApiModule, SdkCoreModule, RuntimeModule, PreviewModule],
1836
+ providers: [IntegrationState, DialogService],
1837
+ exports: [PreviewModule],
1442
1838
  }]
1443
1839
  }] });
1444
1840
 
@@ -1446,5 +1842,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
1446
1842
  * Generated bundle index. Do not edit.
1447
1843
  */
1448
1844
 
1449
- export { ApplyProductConfigurationAction, CloseDocGenAction, ConfigureProductAction, DEFAULT_PLUGINS_TOKEN, ELEMENT_CONFIG, ELEMENT_METADATA, ElementComponent, ElementDefinition, ElementsResolver, FlowAction, IntegrationState, LauncherModule, LauncherService, NavigateBackAction, NavigateToCatalogAction, OpenDocGenAction, PreviewComponent, PreviewModule, RemoteApplyAction, RemoteCancelAction, SHARED_ELEMENT_METADATA, SetDefaultMetrics, SwitchObjectAction, TemplatesService, UI_DEFINITION_METADATA, UiBuildError, VENDOR_MAP, doesElementSupportIO, elementToMetadata, extendElementMetadata, extractElementMetadata, findElementByModule, flattenElements, getAbsolutePath, getElementConfig, isSharedElement, isValidScript, metadataToElement, normalizeElementMetadata, parseBoundPath, parsePath, stringifyElementMetadata };
1845
+ export { ApplyProductConfigurationAction, CloseDocGenAction, ConfigureProductAction, DEFAULT_PLUGINS_TOKEN, ELEMENT_CONFIG, ELEMENT_METADATA, ElementComponent, ElementDefinition, ElementsResolver, FlowAction, IntegrationState, LauncherModule, NavigateBackAction, NavigateToCatalogAction, OpenDocGenAction, PreviewComponent, PreviewModule, RemoteApplyAction, RemoteCancelAction, RuntimeEditorService, RuntimeModule, SHARED_ELEMENT_METADATA, SetDefaultMetrics, SwitchObjectAction, TemplatesService, UI_DEFINITION_METADATA, UiBuildError, VENDOR_MAP, doesElementSupportIO, elementToMetadata, extendElementMetadata, extractElementMetadata, findElementByModule, findElementByPath, flattenElements, getAbsolutePath, getElementConfig, getElementUniqueName, insertElement, isSharedElement, isValidScript, metadataToElement, normalizeElementMetadata, parseBoundPath, parsePath, removeElement, stringifyElementMetadata };
1450
1846
  //# sourceMappingURL=veloceapps-sdk-cms.js.map