@veloceapps/sdk 2.0.5 → 2.0.7

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.
@@ -1,6 +1,6 @@
1
1
  import { __decorate, __param, __awaiter, __rest } from 'tslib';
2
2
  import * as i0 from '@angular/core';
3
- import { InjectionToken, Component, ChangeDetectionStrategy, Inject, Injector, Injectable, ViewContainerRef, SkipSelf, ViewChild, Input, Directive, EventEmitter, TemplateRef, Output, NgModule } from '@angular/core';
3
+ import { InjectionToken, Component, ChangeDetectionStrategy, Inject, Injector, Injectable, Directive, ViewContainerRef, SkipSelf, ViewChild, Input, EventEmitter, TemplateRef, Output, NgModule } from '@angular/core';
4
4
  import * as rxjs from 'rxjs';
5
5
  import { BehaviorSubject, combineLatest, of, shareReplay, throwError, Subject, takeUntil, map as map$1, from, tap as tap$1, switchMap, forkJoin, catchError as catchError$1 } from 'rxjs';
6
6
  import * as i7 from '@angular/common';
@@ -220,6 +220,60 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
220
220
  type: Injectable
221
221
  }] });
222
222
 
223
+ class IOPlugin {
224
+ constructor(host) {
225
+ var _a, _b;
226
+ this.host = host;
227
+ const elementMetadata = this.host.injector.get(ELEMENT_METADATA);
228
+ const inputProvider = this.host.injector.get(IOProviderService);
229
+ const inputs = Object.entries((_a = elementMetadata.inputs) !== null && _a !== void 0 ? _a : {});
230
+ const outputs = Object.entries((_b = elementMetadata.outputs) !== null && _b !== void 0 ? _b : {});
231
+ inputs.forEach(([key, path]) => {
232
+ var _a;
233
+ if (path && typeof path !== 'string') {
234
+ console.error(`The value of '${key}' input should be a string`);
235
+ }
236
+ if (((_a = elementMetadata.outputs) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
237
+ console.warn(`'${key}' appears both in inputs and outputs. To prevent inconsistent behavior please keep them unique `);
238
+ }
239
+ this.host[key] = inputProvider.connect(elementMetadata, key, path);
240
+ });
241
+ outputs.forEach(([key, path]) => {
242
+ if (path && typeof path !== 'string') {
243
+ console.error(`The value of '${key}' output should be a string`);
244
+ }
245
+ this.host[key] = inputProvider.provide(elementMetadata, key, path);
246
+ });
247
+ }
248
+ }
249
+ IOPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: IOPlugin, deps: [{ token: ElementComponent }], target: i0.ɵɵFactoryTarget.Directive });
250
+ IOPlugin.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: IOPlugin, ngImport: i0 });
251
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: IOPlugin, decorators: [{
252
+ type: Directive
253
+ }], ctorParameters: function () { return [{ type: ElementComponent }]; } });
254
+
255
+ const CONFIG = {
256
+ CUSTOM: {
257
+ component: ElementComponent,
258
+ plugins: [IOPlugin],
259
+ },
260
+ CONTAINER: {
261
+ component: ElementComponent,
262
+ defaultTemplate: '<element-children></element-children>',
263
+ plugins: [],
264
+ },
265
+ SERVICE: {
266
+ component: ElementComponent,
267
+ plugins: [IOPlugin],
268
+ suppressTemplate: true,
269
+ suppressStyles: true,
270
+ },
271
+ REFERENCE: {
272
+ component: ElementComponent,
273
+ plugins: [IOPlugin],
274
+ },
275
+ };
276
+
223
277
  const EXPORTED_CLASS_REGEX = /export class (\S+)/;
224
278
  const METADATA_DECORATOR_REGEX = /@ElementDefinition\(([\s\S]+)\)(\n|.)*export class/g;
225
279
  const elementToMetadata = (el, parentPath) => {
@@ -276,6 +330,13 @@ const extendElementMetadata = (script, extend) => {
276
330
  const updated = Object.assign(Object.assign({}, eval(`(${metadataString})`)), extend);
277
331
  return script.replace(metadataString, JSON.stringify(updated));
278
332
  };
333
+ const getElementConfig = (type) => {
334
+ return CONFIG[type];
335
+ };
336
+ const doesElementSupportIO = (type) => {
337
+ var _a, _b;
338
+ return (_b = (_a = getElementConfig(type).plugins) === null || _a === void 0 ? void 0 : _a.includes(IOPlugin)) !== null && _b !== void 0 ? _b : false;
339
+ };
279
340
 
280
341
  class ElementContextService {
281
342
  }
@@ -470,7 +531,13 @@ class ConfigurationRuntimeService {
470
531
  this.apiService = apiService;
471
532
  this.contextService = contextService;
472
533
  this.runtimeContextService = runtimeContextService;
473
- this._isInitialized = new BehaviorSubject(false);
534
+ this._isInitialized = false;
535
+ this.uiDefinitionProperties = {};
536
+ }
537
+ reset() {
538
+ this._isInitialized = false;
539
+ this._runtimeContext = undefined;
540
+ this._assets = undefined;
474
541
  this.uiDefinitionProperties = {};
475
542
  }
476
543
  initTestMode(modelId, uiDefinitionProperties) {
@@ -486,7 +553,7 @@ class ConfigurationRuntimeService {
486
553
  runtimeMode: RuntimeMode.TEST,
487
554
  };
488
555
  this._runtimeContext = runtimeContext;
489
- this._isInitialized.next(true);
556
+ this._isInitialized = true;
490
557
  }));
491
558
  }
492
559
  init(props) {
@@ -506,7 +573,7 @@ class ConfigurationRuntimeService {
506
573
  });
507
574
  }
508
575
  this._runtimeContext = mergeContext;
509
- this._isInitialized.next(true);
576
+ this._isInitialized = true;
510
577
  }));
511
578
  }
512
579
  patchContext(context, patch) {
@@ -515,11 +582,8 @@ class ConfigurationRuntimeService {
515
582
  getAsset(lineItem) {
516
583
  return this._assets && this._assets.find(a => a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId);
517
584
  }
518
- get isInitialized$() {
519
- return this._isInitialized.asObservable();
520
- }
521
585
  get isInitialized() {
522
- return this._isInitialized.getValue();
586
+ return this._isInitialized;
523
587
  }
524
588
  get runtimeModel() {
525
589
  var _a;
@@ -546,6 +610,12 @@ class ConfigurationService {
546
610
  this.lineItem = new BehaviorSubject(undefined);
547
611
  this.charges = new BehaviorSubject({});
548
612
  }
613
+ reset() {
614
+ this.runtimeService.reset();
615
+ this.states = {};
616
+ this.lineItem.next(undefined);
617
+ this.charges.next({});
618
+ }
549
619
  patch(lineItem) {
550
620
  if (!this.lineItem.value) {
551
621
  return;
@@ -926,6 +996,8 @@ var vlCmsUtils = /*#__PURE__*/Object.freeze({
926
996
  metadataToElement: metadataToElement,
927
997
  extractElementMetadata: extractElementMetadata,
928
998
  extendElementMetadata: extendElementMetadata,
999
+ getElementConfig: getElementConfig,
1000
+ doesElementSupportIO: doesElementSupportIO,
929
1001
  parseBoundPath: parseBoundPath,
930
1002
  findLineItem: findLineItem,
931
1003
  insertLineItem: insertLineItem,
@@ -1003,58 +1075,6 @@ const DEFAULT_PLUGINS = {
1003
1075
  DEFAULT: [ScriptPlugin],
1004
1076
  };
1005
1077
 
1006
- class IOPlugin {
1007
- constructor(host) {
1008
- var _a, _b;
1009
- this.host = host;
1010
- const elementMetadata = this.host.injector.get(ELEMENT_METADATA);
1011
- const inputProvider = this.host.injector.get(IOProviderService);
1012
- const inputs = Object.entries((_a = elementMetadata.inputs) !== null && _a !== void 0 ? _a : {});
1013
- const outputs = Object.entries((_b = elementMetadata.outputs) !== null && _b !== void 0 ? _b : {});
1014
- inputs.forEach(([key, path]) => {
1015
- var _a;
1016
- if (path && typeof path !== 'string') {
1017
- console.error(`The value of '${key}' input should be a string`);
1018
- }
1019
- if (((_a = elementMetadata.outputs) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
1020
- console.warn(`'${key}' appears both in inputs and outputs. To prevent inconsistent behavior please keep them unique `);
1021
- }
1022
- this.host[key] = inputProvider.connect(elementMetadata, key, path);
1023
- });
1024
- outputs.forEach(([key, path]) => {
1025
- if (path && typeof path !== 'string') {
1026
- console.error(`The value of '${key}' output should be a string`);
1027
- }
1028
- this.host[key] = inputProvider.provide(elementMetadata, key, path);
1029
- });
1030
- }
1031
- }
1032
- IOPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: IOPlugin, deps: [{ token: ElementComponent }], target: i0.ɵɵFactoryTarget.Directive });
1033
- IOPlugin.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: IOPlugin, ngImport: i0 });
1034
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: IOPlugin, decorators: [{
1035
- type: Directive
1036
- }], ctorParameters: function () { return [{ type: ElementComponent }]; } });
1037
-
1038
- const CONFIG = {
1039
- CUSTOM: {
1040
- component: ElementComponent,
1041
- plugins: [IOPlugin],
1042
- },
1043
- CONTAINER: {
1044
- component: ElementComponent,
1045
- template: '<element-children></element-children>',
1046
- plugins: [IOPlugin],
1047
- },
1048
- SERVICE: {
1049
- component: ElementComponent,
1050
- plugins: [IOPlugin],
1051
- },
1052
- REFERENCE: {
1053
- component: ElementComponent,
1054
- plugins: [IOPlugin],
1055
- },
1056
- };
1057
-
1058
1078
  class ElementsResolver {
1059
1079
  constructor(uiDef, elements) {
1060
1080
  this.uiDef = uiDef;
@@ -1096,21 +1116,38 @@ class ElementsResolver {
1096
1116
  if (element.type !== 'REFERENCE') {
1097
1117
  return;
1098
1118
  }
1099
- return this.sharedElements.find(el => element.reference === el.name);
1119
+ return this.sharedElements.find(el => element.reference === el.reference);
1120
+ }
1121
+ resolveElementTemplate(element) {
1122
+ const config = CONFIG[element.type];
1123
+ const template = !config.suppressTemplate ? element.template : '';
1124
+ return template || config.defaultTemplate || '';
1125
+ }
1126
+ resolveElementStyles(element) {
1127
+ var _a;
1128
+ const config = CONFIG[element.type];
1129
+ return !config.suppressStyles ? (_a = element.styles) !== null && _a !== void 0 ? _a : '' : '';
1100
1130
  }
1101
- processElementMetadata(element, sharedElement) {
1102
- if (element.type === 'REFERENCE') {
1131
+ processElementMetadata(sourceElement) {
1132
+ var _a, _b;
1133
+ const sharedElement = this.getSharedElement(sourceElement);
1134
+ let finalElement;
1135
+ if (sourceElement.type === 'REFERENCE') {
1103
1136
  if (!sharedElement) {
1104
- console.warn(`Shared element "${element.reference}" not found`);
1137
+ console.warn(`Shared element "${sourceElement.reference}" not found`);
1105
1138
  return;
1106
1139
  }
1107
- return Object.assign(Object.assign({}, element), { type: sharedElement.type, template: sharedElement.template, styles: sharedElement.styles, inputs: Object.assign(Object.assign({}, sharedElement.inputs), element.inputs), outputs: Object.assign(Object.assign({}, sharedElement.outputs), element.outputs) });
1140
+ finalElement = Object.assign(Object.assign({}, sourceElement), { type: sharedElement.type, template: sharedElement.template, styles: ((_a = sharedElement.styles) !== null && _a !== void 0 ? _a : '') + '\n' + ((_b = sourceElement.styles) !== null && _b !== void 0 ? _b : ''), inputs: Object.assign(Object.assign({}, sharedElement.inputs), sourceElement.inputs), outputs: Object.assign(Object.assign({}, sharedElement.outputs), sourceElement.outputs) });
1108
1141
  }
1109
- return element;
1142
+ else {
1143
+ finalElement = sourceElement;
1144
+ }
1145
+ finalElement.template = this.resolveElementTemplate(finalElement);
1146
+ finalElement.styles = this.resolveElementStyles(finalElement);
1147
+ return finalElement;
1110
1148
  }
1111
1149
  resolveElement(sourceElement) {
1112
- const sharedElement = this.getSharedElement(sourceElement);
1113
- const element = this.processElementMetadata(sourceElement, sharedElement);
1150
+ const element = this.processElementMetadata(sourceElement);
1114
1151
  if (!element) {
1115
1152
  return;
1116
1153
  }
@@ -1120,11 +1157,11 @@ class ElementsResolver {
1120
1157
  console.warn(`Unknown element type "${element.type}"`);
1121
1158
  return;
1122
1159
  }
1123
- const component = Object.assign(Object.assign({ selector: 'vl-element', template: element.template || config.template || '' }, (element.styles ? { styles: [element.styles] } : {})), { providers: [
1160
+ const component = Object.assign(Object.assign({ selector: 'vl-element', template: element.template }, (element.styles ? { styles: [element.styles] } : {})), { providers: [
1124
1161
  { provide: DEFAULT_PLUGINS_TOKEN, useValue: defaultPlugins },
1125
1162
  { provide: UI_DEFINITION_METADATA, useValue: this.uiDef },
1126
1163
  { provide: ELEMENT_METADATA, useValue: element },
1127
- { provide: SHARED_ELEMENT_METADATA, useValue: sharedElement },
1164
+ { provide: SHARED_ELEMENT_METADATA, useValue: this.getSharedElement(sourceElement) },
1128
1165
  { provide: ELEMENT_CONFIG, useValue: config },
1129
1166
  ] });
1130
1167
  const cmp = Component(component)(class C extends config.component {
@@ -1324,6 +1361,7 @@ class PreviewComponent {
1324
1361
  ngOnDestroy() {
1325
1362
  this.destroy$.next();
1326
1363
  this.destroy$.complete();
1364
+ this.configurationService.reset();
1327
1365
  }
1328
1366
  initializeConfiguration$() {
1329
1367
  var _a;
@@ -1469,5 +1507,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
1469
1507
  * Generated bundle index. Do not edit.
1470
1508
  */
1471
1509
 
1472
- export { ConfigurationRuntimeService, ConfigurationService, DEFAULT_PLUGINS_TOKEN, ELEMENT_CONFIG, ELEMENT_METADATA, ElementComponent, ElementDefinition, LauncherModule, LauncherService, LineItemWorker, PreviewComponent, PreviewModule, SHARED_ELEMENT_METADATA, TemplatesService, UI_DEFINITION_METADATA, elementToMetadata, extendElementMetadata, extractElementMetadata, findLineItem, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getRecommendedPrices, insertLineItem, mapAttributes, metadataToElement, parseBoundPath, patchAttributes, removeLineItem, replaceLineItem, upsertAttributes };
1510
+ export { ConfigurationRuntimeService, ConfigurationService, DEFAULT_PLUGINS_TOKEN, ELEMENT_CONFIG, ELEMENT_METADATA, ElementComponent, ElementDefinition, LauncherModule, LauncherService, LineItemWorker, PreviewComponent, PreviewModule, SHARED_ELEMENT_METADATA, TemplatesService, UI_DEFINITION_METADATA, doesElementSupportIO, elementToMetadata, extendElementMetadata, extractElementMetadata, findLineItem, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getElementConfig, getRecommendedPrices, insertLineItem, mapAttributes, metadataToElement, parseBoundPath, patchAttributes, removeLineItem, replaceLineItem, upsertAttributes };
1473
1511
  //# sourceMappingURL=veloce-sdk-cms.js.map