@veloceapps/sdk 2.0.6 → 2.0.8

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.
@@ -577,6 +577,65 @@
577
577
  type: i0.Injectable
578
578
  }] });
579
579
 
580
+ var IOPlugin = /** @class */ (function () {
581
+ function IOPlugin(host) {
582
+ var _this = this;
583
+ var _a, _b;
584
+ this.host = host;
585
+ var elementMetadata = this.host.injector.get(ELEMENT_METADATA);
586
+ var inputProvider = this.host.injector.get(IOProviderService);
587
+ var inputs = Object.entries((_a = elementMetadata.inputs) !== null && _a !== void 0 ? _a : {});
588
+ var outputs = Object.entries((_b = elementMetadata.outputs) !== null && _b !== void 0 ? _b : {});
589
+ inputs.forEach(function (_c) {
590
+ var _d = __read(_c, 2), key = _d[0], path = _d[1];
591
+ var _a;
592
+ if (path && typeof path !== 'string') {
593
+ console.error("The value of '" + key + "' input should be a string");
594
+ }
595
+ if (((_a = elementMetadata.outputs) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
596
+ console.warn("'" + key + "' appears both in inputs and outputs. To prevent inconsistent behavior please keep them unique ");
597
+ }
598
+ _this.host[key] = inputProvider.connect(elementMetadata, key, path);
599
+ });
600
+ outputs.forEach(function (_c) {
601
+ var _d = __read(_c, 2), key = _d[0], path = _d[1];
602
+ if (path && typeof path !== 'string') {
603
+ console.error("The value of '" + key + "' output should be a string");
604
+ }
605
+ _this.host[key] = inputProvider.provide(elementMetadata, key, path);
606
+ });
607
+ }
608
+ return IOPlugin;
609
+ }());
610
+ IOPlugin.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: IOPlugin, deps: [{ token: exports.ElementComponent }], target: i0__namespace.ɵɵFactoryTarget.Directive });
611
+ IOPlugin.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: IOPlugin, ngImport: i0__namespace });
612
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: IOPlugin, decorators: [{
613
+ type: i0.Directive
614
+ }], ctorParameters: function () { return [{ type: exports.ElementComponent }]; } });
615
+
616
+ var CONFIG = {
617
+ CUSTOM: {
618
+ component: exports.ElementComponent,
619
+ plugins: [IOPlugin],
620
+ },
621
+ CONTAINER: {
622
+ component: exports.ElementComponent,
623
+ defaultTemplate: '<element-children></element-children>',
624
+ plugins: [],
625
+ },
626
+ SERVICE: {
627
+ component: exports.ElementComponent,
628
+ plugins: [IOPlugin],
629
+ suppressTemplate: true,
630
+ suppressStyles: true,
631
+ },
632
+ REFERENCE: {
633
+ component: exports.ElementComponent,
634
+ plugins: [IOPlugin],
635
+ suppressTemplate: true,
636
+ },
637
+ };
638
+
580
639
  var EXPORTED_CLASS_REGEX = /export class (\S+)/;
581
640
  var METADATA_DECORATOR_REGEX = /@ElementDefinition\(([\s\S]+)\)(\n|.)*export class/g;
582
641
  var elementToMetadata = function (el, parentPath) {
@@ -586,7 +645,7 @@
586
645
  var styles = el.styles && window.atob(el.styles);
587
646
  var exportedClassName = script && ((_a = EXPORTED_CLASS_REGEX.exec(script)) !== null && _a !== void 0 ? _a : [])[1];
588
647
  if (!exportedClassName) {
589
- console.error("Script doesn't have exported class");
648
+ throw new Error("Script doesn't have exported class");
590
649
  }
591
650
  var elementMetadata = extractElementMetadata(script || '');
592
651
  var path = (parentPath ? parentPath + '/' : '') + elementMetadata.name;
@@ -595,17 +654,21 @@
595
654
  var metadataToElement = function (metadata) {
596
655
  var elMetadata = {
597
656
  name: metadata.name,
657
+ isShared: metadata.isShared,
598
658
  type: metadata.type,
599
659
  model: metadata.model,
600
660
  module: metadata.module,
601
661
  reference: metadata.reference,
602
662
  inputs: metadata.inputs,
603
663
  outputs: metadata.outputs,
604
- children: metadata.children.map(function (_b) {
605
- var name = _b.name;
664
+ children: metadata.children.map(function (_c) {
665
+ var name = _c.name;
606
666
  return name;
607
667
  }),
608
668
  };
669
+ if (!metadata.script || !EXPORTED_CLASS_REGEX.test(metadata.script)) {
670
+ throw new Error("'" + metadata.name + "' element script doesn't have exported class");
671
+ }
609
672
  var script = metadata.script &&
610
673
  window.btoa(metadata.script.replace(EXPORTED_CLASS_REGEX, "@ElementDefinition(" + JSON.stringify(elMetadata) + ") export class Script"));
611
674
  var template = metadata.template && window.btoa(metadata.template);
@@ -635,6 +698,13 @@
635
698
  var updated = Object.assign(Object.assign({}, eval("(" + metadataString + ")")), extend);
636
699
  return script.replace(metadataString, JSON.stringify(updated));
637
700
  };
701
+ var getElementConfig = function (type) {
702
+ return CONFIG[type];
703
+ };
704
+ var doesElementSupportIO = function (type) {
705
+ var _a, _b;
706
+ return (_b = (_a = getElementConfig(type).plugins) === null || _a === void 0 ? void 0 : _a.includes(IOPlugin)) !== null && _b !== void 0 ? _b : false;
707
+ };
638
708
 
639
709
  var ElementContextService = /** @class */ (function () {
640
710
  function ElementContextService() {
@@ -854,11 +924,14 @@
854
924
  this.apiService = apiService;
855
925
  this.contextService = contextService;
856
926
  this.runtimeContextService = runtimeContextService;
857
- this._isInitialized = new rxjs.BehaviorSubject(false);
927
+ this._isInitialized = false;
858
928
  this.uiDefinitionProperties = {};
859
929
  }
860
930
  ConfigurationRuntimeService.prototype.reset = function () {
861
- this._isInitialized.next(false);
931
+ this._isInitialized = false;
932
+ this._runtimeContext = undefined;
933
+ this._assets = undefined;
934
+ this.uiDefinitionProperties = {};
862
935
  };
863
936
  ConfigurationRuntimeService.prototype.initTestMode = function (modelId, uiDefinitionProperties) {
864
937
  var _this = this;
@@ -875,7 +948,7 @@
875
948
  runtimeMode: i2.RuntimeMode.TEST,
876
949
  };
877
950
  _this._runtimeContext = runtimeContext;
878
- _this._isInitialized.next(true);
951
+ _this._isInitialized = true;
879
952
  }));
880
953
  };
881
954
  ConfigurationRuntimeService.prototype.init = function (props) {
@@ -896,7 +969,7 @@
896
969
  });
897
970
  }
898
971
  _this._runtimeContext = mergeContext;
899
- _this._isInitialized.next(true);
972
+ _this._isInitialized = true;
900
973
  }));
901
974
  };
902
975
  ConfigurationRuntimeService.prototype.patchContext = function (context, patch) {
@@ -905,16 +978,9 @@
905
978
  ConfigurationRuntimeService.prototype.getAsset = function (lineItem) {
906
979
  return this._assets && this._assets.find(function (a) { return a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId; });
907
980
  };
908
- Object.defineProperty(ConfigurationRuntimeService.prototype, "isInitialized$", {
909
- get: function () {
910
- return this._isInitialized.asObservable();
911
- },
912
- enumerable: false,
913
- configurable: true
914
- });
915
981
  Object.defineProperty(ConfigurationRuntimeService.prototype, "isInitialized", {
916
982
  get: function () {
917
- return this._isInitialized.getValue();
983
+ return this._isInitialized;
918
984
  },
919
985
  enumerable: false,
920
986
  configurable: true
@@ -953,6 +1019,12 @@
953
1019
  this.lineItem = new rxjs.BehaviorSubject(undefined);
954
1020
  this.charges = new rxjs.BehaviorSubject({});
955
1021
  }
1022
+ ConfigurationService.prototype.reset = function () {
1023
+ this.runtimeService.reset();
1024
+ this.states = {};
1025
+ this.lineItem.next(undefined);
1026
+ this.charges.next({});
1027
+ };
956
1028
  ConfigurationService.prototype.patch = function (lineItem) {
957
1029
  var _this = this;
958
1030
  if (!this.lineItem.value) {
@@ -1376,6 +1448,8 @@
1376
1448
  metadataToElement: metadataToElement,
1377
1449
  extractElementMetadata: extractElementMetadata,
1378
1450
  extendElementMetadata: extendElementMetadata,
1451
+ getElementConfig: getElementConfig,
1452
+ doesElementSupportIO: doesElementSupportIO,
1379
1453
  parseBoundPath: parseBoundPath,
1380
1454
  findLineItem: findLineItem,
1381
1455
  insertLineItem: insertLineItem,
@@ -1453,65 +1527,9 @@
1453
1527
  DEFAULT: [ScriptPlugin],
1454
1528
  };
1455
1529
 
1456
- var IOPlugin = /** @class */ (function () {
1457
- function IOPlugin(host) {
1458
- var _this = this;
1459
- var _a, _b;
1460
- this.host = host;
1461
- var elementMetadata = this.host.injector.get(ELEMENT_METADATA);
1462
- var inputProvider = this.host.injector.get(IOProviderService);
1463
- var inputs = Object.entries((_a = elementMetadata.inputs) !== null && _a !== void 0 ? _a : {});
1464
- var outputs = Object.entries((_b = elementMetadata.outputs) !== null && _b !== void 0 ? _b : {});
1465
- inputs.forEach(function (_c) {
1466
- var _d = __read(_c, 2), key = _d[0], path = _d[1];
1467
- var _a;
1468
- if (path && typeof path !== 'string') {
1469
- console.error("The value of '" + key + "' input should be a string");
1470
- }
1471
- if (((_a = elementMetadata.outputs) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
1472
- console.warn("'" + key + "' appears both in inputs and outputs. To prevent inconsistent behavior please keep them unique ");
1473
- }
1474
- _this.host[key] = inputProvider.connect(elementMetadata, key, path);
1475
- });
1476
- outputs.forEach(function (_c) {
1477
- var _d = __read(_c, 2), key = _d[0], path = _d[1];
1478
- if (path && typeof path !== 'string') {
1479
- console.error("The value of '" + key + "' output should be a string");
1480
- }
1481
- _this.host[key] = inputProvider.provide(elementMetadata, key, path);
1482
- });
1483
- }
1484
- return IOPlugin;
1485
- }());
1486
- IOPlugin.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: IOPlugin, deps: [{ token: exports.ElementComponent }], target: i0__namespace.ɵɵFactoryTarget.Directive });
1487
- IOPlugin.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: IOPlugin, ngImport: i0__namespace });
1488
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: IOPlugin, decorators: [{
1489
- type: i0.Directive
1490
- }], ctorParameters: function () { return [{ type: exports.ElementComponent }]; } });
1491
-
1492
- var CONFIG = {
1493
- CUSTOM: {
1494
- component: exports.ElementComponent,
1495
- plugins: [IOPlugin],
1496
- },
1497
- CONTAINER: {
1498
- component: exports.ElementComponent,
1499
- template: '<element-children></element-children>',
1500
- plugins: [IOPlugin],
1501
- },
1502
- SERVICE: {
1503
- component: exports.ElementComponent,
1504
- plugins: [IOPlugin],
1505
- },
1506
- REFERENCE: {
1507
- component: exports.ElementComponent,
1508
- plugins: [IOPlugin],
1509
- },
1510
- };
1511
-
1512
1530
  var ElementsResolver = /** @class */ (function () {
1513
1531
  function ElementsResolver(uiDef, elements) {
1514
- var e_1, _b;
1532
+ var e_1, _c;
1515
1533
  this.uiDef = uiDef;
1516
1534
  this.renderableElements = [];
1517
1535
  this.sharedElements = [];
@@ -1531,7 +1549,7 @@
1531
1549
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
1532
1550
  finally {
1533
1551
  try {
1534
- if (flatElements_1_1 && !flatElements_1_1.done && (_b = flatElements_1.return)) _b.call(flatElements_1);
1552
+ if (flatElements_1_1 && !flatElements_1_1.done && (_c = flatElements_1.return)) _c.call(flatElements_1);
1535
1553
  }
1536
1554
  finally { if (e_1) throw e_1.error; }
1537
1555
  }
@@ -1557,7 +1575,7 @@
1557
1575
  return lodash.flatten(elements.map(function (el) { return __spreadArray([el], __read(_this.flattenElements(el.children))); }));
1558
1576
  };
1559
1577
  ElementsResolver.prototype.isSharedElement = function (el) {
1560
- return Boolean(el.reference) && el.type !== 'REFERENCE';
1578
+ return Boolean(el.isShared) && el.type !== 'REFERENCE';
1561
1579
  };
1562
1580
  ElementsResolver.prototype.getSharedElement = function (element) {
1563
1581
  if (element.type !== 'REFERENCE') {
@@ -1565,19 +1583,36 @@
1565
1583
  }
1566
1584
  return this.sharedElements.find(function (el) { return element.reference === el.name; });
1567
1585
  };
1568
- ElementsResolver.prototype.processElementMetadata = function (element, sharedElement) {
1569
- if (element.type === 'REFERENCE') {
1586
+ ElementsResolver.prototype.resolveElementTemplate = function (element) {
1587
+ var config = CONFIG[element.type];
1588
+ var template = !config.suppressTemplate ? element.template : '';
1589
+ return template || config.defaultTemplate || '';
1590
+ };
1591
+ ElementsResolver.prototype.resolveElementStyles = function (element) {
1592
+ var _a;
1593
+ var config = CONFIG[element.type];
1594
+ return !config.suppressStyles ? (_a = element.styles) !== null && _a !== void 0 ? _a : '' : '';
1595
+ };
1596
+ ElementsResolver.prototype.processElementMetadata = function (sourceElement) {
1597
+ var _a, _b;
1598
+ var sharedElement = this.getSharedElement(sourceElement);
1599
+ var finalElement;
1600
+ if (sourceElement.type === 'REFERENCE') {
1570
1601
  if (!sharedElement) {
1571
- console.warn("Shared element \"" + element.reference + "\" not found");
1602
+ console.warn("Shared element \"" + sourceElement.reference + "\" not found");
1572
1603
  return;
1573
1604
  }
1574
- 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) });
1605
+ 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) });
1575
1606
  }
1576
- return element;
1607
+ else {
1608
+ finalElement = sourceElement;
1609
+ }
1610
+ finalElement.template = this.resolveElementTemplate(finalElement);
1611
+ finalElement.styles = this.resolveElementStyles(finalElement);
1612
+ return finalElement;
1577
1613
  };
1578
1614
  ElementsResolver.prototype.resolveElement = function (sourceElement) {
1579
- var sharedElement = this.getSharedElement(sourceElement);
1580
- var element = this.processElementMetadata(sourceElement, sharedElement);
1615
+ var element = this.processElementMetadata(sourceElement);
1581
1616
  if (!element) {
1582
1617
  return;
1583
1618
  }
@@ -1587,11 +1622,11 @@
1587
1622
  console.warn("Unknown element type \"" + element.type + "\"");
1588
1623
  return;
1589
1624
  }
1590
- var component = Object.assign(Object.assign({ selector: 'vl-element', template: element.template || config.template || '' }, (element.styles ? { styles: [element.styles] } : {})), { providers: [
1625
+ var component = Object.assign(Object.assign({ selector: 'vl-element', template: element.template }, (element.styles ? { styles: [element.styles] } : {})), { providers: [
1591
1626
  { provide: DEFAULT_PLUGINS_TOKEN, useValue: defaultPlugins },
1592
1627
  { provide: UI_DEFINITION_METADATA, useValue: this.uiDef },
1593
1628
  { provide: ELEMENT_METADATA, useValue: element },
1594
- { provide: SHARED_ELEMENT_METADATA, useValue: sharedElement },
1629
+ { provide: SHARED_ELEMENT_METADATA, useValue: this.getSharedElement(sourceElement) },
1595
1630
  { provide: ELEMENT_CONFIG, useValue: config },
1596
1631
  ] });
1597
1632
  var cmp = i0.Component(component)(/** @class */ (function (_super) {
@@ -1829,7 +1864,7 @@
1829
1864
  PreviewComponent.prototype.ngOnDestroy = function () {
1830
1865
  this.destroy$.next();
1831
1866
  this.destroy$.complete();
1832
- this.runtimeService.reset();
1867
+ this.configurationService.reset();
1833
1868
  };
1834
1869
  PreviewComponent.prototype.initializeConfiguration$ = function () {
1835
1870
  var _this = this;
@@ -1848,13 +1883,23 @@
1848
1883
  .initTestMode(this.modelId, uiDefinitionProps)
1849
1884
  .pipe(rxjs.switchMap(function () { return _this.configurationService.configure(); }));
1850
1885
  };
1886
+ PreviewComponent.prototype.elementToMetadataSafe = function (elements) {
1887
+ try {
1888
+ return elements.map(function (element) { return elementToMetadata(element); });
1889
+ }
1890
+ catch (e) {
1891
+ console.error(e);
1892
+ this.messageService.add({ severity: 'error', summary: String(e) });
1893
+ return [];
1894
+ }
1895
+ };
1851
1896
  PreviewComponent.prototype.startPreview = function () {
1852
1897
  var _this = this;
1853
1898
  if (!this.uiDefinition) {
1854
1899
  return;
1855
1900
  }
1856
1901
  var _a = this.uiDefinition, children = _a.children, uiDefinitionMeta = __rest(_a, ["children"]);
1857
- this.elements = children.map(function (child) { return elementToMetadata(child); });
1902
+ this.elements = this.elementToMetadataSafe(children);
1858
1903
  var compilation$ = this.launcherService.compileModule(this.elements, uiDefinitionMeta);
1859
1904
  rxjs.forkJoin([compilation$, this.initializeConfiguration$()])
1860
1905
  .pipe(rxjs.tap(function () { return _this.state$.next({ loading: false, failure: false }); }), rxjs.catchError(function (error) {
@@ -2007,6 +2052,7 @@
2007
2052
  exports.SHARED_ELEMENT_METADATA = SHARED_ELEMENT_METADATA;
2008
2053
  exports.TemplatesService = TemplatesService;
2009
2054
  exports.UI_DEFINITION_METADATA = UI_DEFINITION_METADATA;
2055
+ exports.doesElementSupportIO = doesElementSupportIO;
2010
2056
  exports.elementToMetadata = elementToMetadata;
2011
2057
  exports.extendElementMetadata = extendElementMetadata;
2012
2058
  exports.extractElementMetadata = extractElementMetadata;
@@ -2015,6 +2061,7 @@
2015
2061
  exports.getAttributeValue = getAttributeValue;
2016
2062
  exports.getAttributes = getAttributes;
2017
2063
  exports.getDefaultLineItem = getDefaultLineItem;
2064
+ exports.getElementConfig = getElementConfig;
2018
2065
  exports.getRecommendedPrices = getRecommendedPrices;
2019
2066
  exports.insertLineItem = insertLineItem;
2020
2067
  exports.mapAttributes = mapAttributes;