@colijnit/configurator 1.0.8 → 1.0.9

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 (31) hide show
  1. package/app/builder.d.ts +10 -0
  2. package/app/components/answers/answers.component.d.ts +6 -0
  3. package/app/components/answers/answers.module.d.ts +2 -0
  4. package/app/components/selections/selections.component.d.ts +16 -0
  5. package/app/components/selections/selections.module.d.ts +2 -0
  6. package/bundles/colijnit-configurator.umd.js +224 -55
  7. package/bundles/colijnit-configurator.umd.js.map +1 -1
  8. package/bundles/colijnit-configurator.umd.min.js +2 -2
  9. package/bundles/colijnit-configurator.umd.min.js.map +1 -1
  10. package/colijnit-configurator.metadata.json +1 -1
  11. package/esm2015/app/builder.js +62 -38
  12. package/esm2015/app/components/answers/answers.component.js +29 -0
  13. package/esm2015/app/components/answers/answers.module.js +21 -0
  14. package/esm2015/app/components/selections/selections.component.js +83 -0
  15. package/esm2015/app/components/selections/selections.module.js +21 -0
  16. package/esm2015/public_api.js +5 -1
  17. package/esm2015/utils/threed.utils.js +3 -2
  18. package/esm5/app/builder.js +87 -51
  19. package/esm5/app/components/answers/answers.component.js +24 -0
  20. package/esm5/app/components/answers/answers.module.js +24 -0
  21. package/esm5/app/components/selections/selections.component.js +73 -0
  22. package/esm5/app/components/selections/selections.module.js +24 -0
  23. package/esm5/public_api.js +5 -1
  24. package/esm5/utils/threed.utils.js +3 -2
  25. package/fesm2015/colijnit-configurator.js +205 -40
  26. package/fesm2015/colijnit-configurator.js.map +1 -1
  27. package/fesm5/colijnit-configurator.js +221 -53
  28. package/fesm5/colijnit-configurator.js.map +1 -1
  29. package/package.json +2 -2
  30. package/public_api.d.ts +4 -0
  31. package/utils/threed.utils.d.ts +0 -1
@@ -1,4 +1,4 @@
1
- import { __awaiter, __generator, __extends } from 'tslib';
1
+ import { __awaiter, __generator, __extends, __decorate } from 'tslib';
2
2
  import { Mesh, ObjectLoader, Camera, Group, TextureLoader, RepeatWrapping, Object3D, Box3, Vector3, Vector2, Euler, Quaternion, Color, Texture, sRGBEncoding, MeshPhongMaterial, MeshStandardMaterial } from 'three';
3
3
  import { Configurator } from '@colijnit/configuratorapi/build/src/configurator';
4
4
  import { DecoNode } from '@colijnit/configuratorapi/build/src/model/deco-node';
@@ -10,6 +10,9 @@ import { DecoNodeKind } from '@colijnit/configuratorapi/build/src/enum/deco-node
10
10
  import * as JSZip from 'jszip';
11
11
  import { Article } from '@colijnit/configuratorapi/build/src/model/article';
12
12
  import { BehaviorSubject } from 'rxjs';
13
+ import { EventEmitter, Input, Output, Component, NgModule } from '@angular/core';
14
+ import { CommonModule } from '@angular/common';
15
+ import { trigger, state, style, transition, animate } from '@angular/animations';
13
16
 
14
17
  var ObjectUtils = /** @class */ (function () {
15
18
  function ObjectUtils() {
@@ -233,7 +236,8 @@ var ThreedUtils = /** @class */ (function () {
233
236
  fileName = fileName.replace('.unity3d', '');
234
237
  lookupFileName = fileName + (fileName.indexOf('.glb') < 0 ? '.glb' : '');
235
238
  if (this._objectCache.has(lookupFileName)) {
236
- return [2 /*return*/, Promise.resolve(this._objectCache.get(lookupFileName))];
239
+ resolve(this._objectCache.get(lookupFileName));
240
+ return [2 /*return*/];
237
241
  }
238
242
  return [4 /*yield*/, FileUtils.FileExists(lookupFileName, 'https://cdn1.colijn-it.nl/content43/')];
239
243
  case 1:
@@ -1323,13 +1327,18 @@ var VariationHelper = /** @class */ (function () {
1323
1327
 
1324
1328
  var Builder = /** @class */ (function () {
1325
1329
  function Builder(scene, options) {
1330
+ var _this = this;
1326
1331
  this.selectionsReceived = new BehaviorSubject([]);
1332
+ this.answersReceived = new BehaviorSubject([]);
1333
+ this.questionReceived = new BehaviorSubject(undefined);
1327
1334
  this._selections = [];
1328
1335
  this._decos = [];
1329
1336
  this._placedAdjustables = [];
1330
1337
  this._placedAddables = [];
1331
1338
  this._adjustables = [];
1332
1339
  this._addables = [];
1340
+ this._articleCache = new Map();
1341
+ this._subs = [];
1333
1342
  if (!scene) {
1334
1343
  throw 'No scene object provided!';
1335
1344
  }
@@ -1341,64 +1350,41 @@ var Builder = /** @class */ (function () {
1341
1350
  this._boFactory = new BusinessObjectFactory();
1342
1351
  this._threedUtils = new ThreedUtils();
1343
1352
  this._variationHelper = new VariationHelper();
1353
+ this._subs.push(this._configuratorApi.selectionsReceived.subscribe(function (selections) { return _this.selectionsReceived.next(selections); }), this._configuratorApi.answersReceived.subscribe(function (answers) { return _this.answersReceived.next(answers); }), this._configuratorApi.questionReceived.subscribe(function (question) { return _this.questionReceived.next(question); }));
1344
1354
  }
1345
1355
  Builder.prototype.buildModel = function (instanceId, sku, goodId) {
1346
1356
  return __awaiter(this, void 0, void 0, function () {
1347
- var article, _a, promises, e_1;
1348
- return __generator(this, function (_b) {
1349
- switch (_b.label) {
1357
+ var promises, e_1;
1358
+ return __generator(this, function (_a) {
1359
+ switch (_a.label) {
1350
1360
  case 0:
1351
1361
  if (!this._scene && !instanceId) {
1352
1362
  return [2 /*return*/];
1353
1363
  }
1354
- _b.label = 1;
1364
+ _a.label = 1;
1355
1365
  case 1:
1356
- _b.trys.push([1, 12, , 13]);
1357
- if (!!goodId) return [3 /*break*/, 3];
1358
- return [4 /*yield*/, this._getGoodIdFromSku(sku)
1359
- .catch(function (error) {
1360
- throw "Article with sku " + sku + " not found!";
1361
- })];
1366
+ _a.trys.push([1, 7, , 8]);
1367
+ return [4 /*yield*/, this._prepareConfiguration(sku, goodId)];
1362
1368
  case 2:
1363
- goodId = _b.sent();
1364
- _b.label = 3;
1365
- case 3: return [4 /*yield*/, this._getArticle(goodId)];
1366
- case 4:
1367
- article = _b.sent();
1368
- if (!(article && article.assetUrl)) return [3 /*break*/, 10];
1369
- _a = this;
1370
- return [4 /*yield*/, this._threedUtils.download3DSource(article.assetUrl)
1371
- .catch(function (error) {
1372
- throw error;
1373
- })];
1374
- case 5:
1375
- _a._source = _b.sent();
1376
- if (!this._source) return [3 /*break*/, 8];
1377
- if (article.contentDeliveryUrl) {
1378
- this._variationHelper.assetPath =
1379
- article.contentDeliveryUrl +
1380
- (article.contentDeliveryUrl.endsWith('/') ? '' : '/') +
1381
- (article.distSchema ? article.distSchema : 'UP_DBA');
1382
- }
1369
+ _a.sent();
1370
+ if (!this._source) return [3 /*break*/, 5];
1383
1371
  return [4 /*yield*/, this._configuratorApi.setInstanceToConfigure(instanceId)];
1384
- case 6:
1385
- _b.sent();
1372
+ case 3:
1373
+ _a.sent();
1386
1374
  promises = [];
1387
- promises.push(this._getSelections());
1375
+ promises.push(this._getSelections(instanceId));
1388
1376
  promises.push(this._getDecos());
1389
1377
  return [4 /*yield*/, Promise.all(promises)];
1390
- case 7:
1391
- _b.sent();
1378
+ case 4:
1379
+ _a.sent();
1392
1380
  this._linkSelectionsAndDecos();
1393
1381
  return [2 /*return*/, this._build(instanceId)];
1394
- case 8: throw 'GLB source not found!';
1395
- case 9: return [3 /*break*/, 11];
1396
- case 10: return [2 /*return*/, null];
1397
- case 11: return [3 /*break*/, 13];
1398
- case 12:
1399
- e_1 = _b.sent();
1382
+ case 5: throw 'GLB source not found!';
1383
+ case 6: return [3 /*break*/, 8];
1384
+ case 7:
1385
+ e_1 = _a.sent();
1400
1386
  throw e_1;
1401
- case 13: return [2 /*return*/];
1387
+ case 8: return [2 /*return*/];
1402
1388
  }
1403
1389
  });
1404
1390
  });
@@ -1410,6 +1396,47 @@ var Builder = /** @class */ (function () {
1410
1396
  this._threedUtils.clearCache();
1411
1397
  this._variationHelper.clearCache();
1412
1398
  };
1399
+ Builder.prototype.selectSelection = function (selection) {
1400
+ this._configuratorApi.selectSelection(selection, false);
1401
+ };
1402
+ Builder.prototype.getQuestionAndAnswers = function () {
1403
+ return __awaiter(this, void 0, void 0, function () {
1404
+ return __generator(this, function (_a) {
1405
+ return [2 /*return*/, this._configuratorApi.getQuestionAndAnswers(false)];
1406
+ });
1407
+ });
1408
+ };
1409
+ Builder.prototype.selectAnswer = function (answer) {
1410
+ this._configuratorApi.selectAnswer(answer, false);
1411
+ };
1412
+ Builder.prototype._prepareConfiguration = function (sku, goodId) {
1413
+ return __awaiter(this, void 0, void 0, function () {
1414
+ var article, _a;
1415
+ return __generator(this, function (_b) {
1416
+ switch (_b.label) {
1417
+ case 0: return [4 /*yield*/, this._getArticle(sku, goodId)];
1418
+ case 1:
1419
+ article = _b.sent();
1420
+ if (!(article && article.assetUrl)) return [3 /*break*/, 3];
1421
+ _a = this;
1422
+ return [4 /*yield*/, this._threedUtils.download3DSource(article.assetUrl)
1423
+ .catch(function (error) {
1424
+ throw error;
1425
+ })];
1426
+ case 2:
1427
+ _a._source = _b.sent();
1428
+ if (article.contentDeliveryUrl) {
1429
+ this._variationHelper.assetPath =
1430
+ article.contentDeliveryUrl +
1431
+ (article.contentDeliveryUrl.endsWith('/') ? '' : '/') +
1432
+ (article.distSchema ? article.distSchema : 'UP_DBA');
1433
+ }
1434
+ _b.label = 3;
1435
+ case 3: return [2 /*return*/];
1436
+ }
1437
+ });
1438
+ });
1439
+ };
1413
1440
  Builder.prototype._build = function (instanceId) {
1414
1441
  return __awaiter(this, void 0, void 0, function () {
1415
1442
  var adjustables, obj, connected, i, len, adjustable, ii, lenii;
@@ -1630,29 +1657,42 @@ var Builder = /** @class */ (function () {
1630
1657
  });
1631
1658
  });
1632
1659
  };
1633
- Builder.prototype._getArticle = function (id) {
1660
+ Builder.prototype._getArticle = function (sku, goodId) {
1634
1661
  return __awaiter(this, void 0, void 0, function () {
1635
- var articleResponse, obj;
1662
+ var article, articleResponse, obj;
1636
1663
  return __generator(this, function (_a) {
1637
1664
  switch (_a.label) {
1638
- case 0: return [4 /*yield*/, this._configuratorApi.getArticleQuickSel(id, false)];
1665
+ case 0:
1666
+ if (this._articleCache.has(sku)) {
1667
+ return [2 /*return*/, this._articleCache.get(sku)];
1668
+ }
1669
+ if (!!goodId) return [3 /*break*/, 2];
1670
+ return [4 /*yield*/, this._getGoodIdFromSku(sku)
1671
+ .catch(function (error) {
1672
+ throw "Article with sku " + sku + " not found!";
1673
+ })];
1639
1674
  case 1:
1675
+ goodId = _a.sent();
1676
+ _a.label = 2;
1677
+ case 2: return [4 /*yield*/, this._configuratorApi.getArticleQuickSel(goodId, false)];
1678
+ case 3:
1640
1679
  articleResponse = _a.sent();
1641
1680
  if (articleResponse.validationResult.success && articleResponse.resultObject) {
1642
1681
  if (articleResponse.resultObject.hasOwnProperty('oArticle')) {
1643
1682
  obj = Array.isArray(articleResponse.resultObject['oArticle']) ? articleResponse.resultObject['oArticle'][0] : articleResponse.resultObject['oArticle'];
1644
- return [2 /*return*/, this._boFactory.makeWithRawBackendData(Article, obj)];
1683
+ article = this._boFactory.makeWithRawBackendData(Article, obj);
1645
1684
  }
1646
1685
  else {
1647
- return [2 /*return*/, this._boFactory.makeWithRawBackendData(Article, articleResponse.resultObject)];
1686
+ article = this._boFactory.makeWithRawBackendData(Article, articleResponse.resultObject);
1648
1687
  }
1649
1688
  }
1650
- return [2 /*return*/];
1689
+ this._articleCache.set(sku, article);
1690
+ return [2 /*return*/, article];
1651
1691
  }
1652
1692
  });
1653
1693
  });
1654
1694
  };
1655
- Builder.prototype._getSelections = function () {
1695
+ Builder.prototype._getSelections = function (instanceId) {
1656
1696
  return __awaiter(this, void 0, void 0, function () {
1657
1697
  var selectionResponse;
1658
1698
  return __generator(this, function (_a) {
@@ -1664,7 +1704,7 @@ var Builder = /** @class */ (function () {
1664
1704
  selectionResponse = _a.sent();
1665
1705
  if (selectionResponse.resultObjects && selectionResponse.resultObjects.length > 0) {
1666
1706
  this._selections = this._boFactory.makeBOArrayFromRawBackendDataArray(Selection, selectionResponse.resultObjects);
1667
- this.selectionsReceived.next(this._selections);
1707
+ this._selections.forEach(function (s) { return s.instanceId = instanceId; });
1668
1708
  }
1669
1709
  else {
1670
1710
  throw 'No selections found!';
@@ -1767,9 +1807,137 @@ var Builder = /** @class */ (function () {
1767
1807
  return Builder;
1768
1808
  }());
1769
1809
 
1810
+ var AnswersComponent = /** @class */ (function () {
1811
+ function AnswersComponent() {
1812
+ this.answers = [];
1813
+ this.answerClick = new EventEmitter();
1814
+ }
1815
+ __decorate([
1816
+ Input()
1817
+ ], AnswersComponent.prototype, "answers", void 0);
1818
+ __decorate([
1819
+ Output()
1820
+ ], AnswersComponent.prototype, "answerClick", void 0);
1821
+ AnswersComponent = __decorate([
1822
+ Component({
1823
+ selector: "answers",
1824
+ template: "\n <ng-container *ngFor=\"let answer of answers\">\n <div class=\"answers\" (click)=\"answerClick.emit(answer)\">\n <div class=\"answer\" [textContent]=\"answer.commercialAnswer\"></div>\n </div>\n </ng-container>\n ",
1825
+ styles: [":host{position:absolute;top:0;right:0;width:400px;height:100%;background:#fff}:host .answers{cursor:pointer}"]
1826
+ })
1827
+ ], AnswersComponent);
1828
+ return AnswersComponent;
1829
+ }());
1830
+
1831
+ var AnswersModule = /** @class */ (function () {
1832
+ function AnswersModule() {
1833
+ }
1834
+ AnswersModule = __decorate([
1835
+ NgModule({
1836
+ imports: [
1837
+ CommonModule
1838
+ ],
1839
+ declarations: [
1840
+ AnswersComponent
1841
+ ],
1842
+ exports: [
1843
+ AnswersComponent
1844
+ ]
1845
+ })
1846
+ ], AnswersModule);
1847
+ return AnswersModule;
1848
+ }());
1849
+
1850
+ var SelectionViewModel = /** @class */ (function () {
1851
+ function SelectionViewModel() {
1852
+ this.children = [];
1853
+ this.expanded = false;
1854
+ }
1855
+ return SelectionViewModel;
1856
+ }());
1857
+ var SelectionsComponent = /** @class */ (function () {
1858
+ function SelectionsComponent() {
1859
+ this.selectionViewModels = [];
1860
+ this.selectionClick = new EventEmitter();
1861
+ }
1862
+ Object.defineProperty(SelectionsComponent.prototype, "selections", {
1863
+ set: function (value) {
1864
+ this._prepareSelections(value);
1865
+ },
1866
+ enumerable: true,
1867
+ configurable: true
1868
+ });
1869
+ SelectionsComponent.prototype.expandClicked = function (selectionViewModel, mouseEvent) {
1870
+ mouseEvent.preventDefault();
1871
+ mouseEvent.stopImmediatePropagation();
1872
+ selectionViewModel.expanded = !selectionViewModel.expanded;
1873
+ };
1874
+ SelectionsComponent.prototype.selectSelection = function (selection, mouseEvent) {
1875
+ mouseEvent.preventDefault();
1876
+ mouseEvent.stopImmediatePropagation();
1877
+ this.selectionClick.next(selection);
1878
+ };
1879
+ SelectionsComponent.prototype._prepareSelections = function (value) {
1880
+ var _this = this;
1881
+ this.selectionViewModels.length = 0;
1882
+ var selectionViewModel;
1883
+ value.forEach(function (s) {
1884
+ if (s.presentationLevel === 1) {
1885
+ selectionViewModel = new SelectionViewModel();
1886
+ selectionViewModel.selection = s;
1887
+ _this.selectionViewModels.push(selectionViewModel);
1888
+ }
1889
+ else if (s.presentationLevel > 1) {
1890
+ if (selectionViewModel) {
1891
+ selectionViewModel.children.push(s);
1892
+ }
1893
+ }
1894
+ });
1895
+ };
1896
+ __decorate([
1897
+ Input()
1898
+ ], SelectionsComponent.prototype, "selections", null);
1899
+ __decorate([
1900
+ Output()
1901
+ ], SelectionsComponent.prototype, "selectionClick", void 0);
1902
+ SelectionsComponent = __decorate([
1903
+ Component({
1904
+ selector: "selections",
1905
+ template: "\n <ng-container *ngFor=\"let selectionViewModel of selectionViewModels\">\n <div class=\"selection\" (click)=\"selectSelection(selectionViewModel.selection, $event)\">\n <div class=\"question\" [textContent]=\"selectionViewModel.selection.commercialQuestion\"></div>\n <div class=\"answer\" [textContent]=\"selectionViewModel.selection.answer\"></div>\n <div class=\"collapse-handle\" [class.expanded]=\"selectionViewModel.expanded\" \n *ngIf=\"selectionViewModel.children.length > 0\" (click)=\"expandClicked(selectionViewModel, $event)\"></div>\n <div *ngIf=\"selectionViewModel.children.length > 0 && selectionViewModel.expanded\" @showHideChildren>\n <div class=\"child-selection\" *ngFor=\"let selection of selectionViewModel.children\"\n (click)=\"selectSelection(selection, $event)\"\n >\n <div class=\"question\" [textContent]=\"selection.commercialQuestion\"></div>\n <div class=\"answer\" [textContent]=\"selection.answer\"></div>\n </div>\n </div>\n </div>\n </ng-container>\n ",
1906
+ animations: [
1907
+ trigger('showHideChildren', [
1908
+ state('void', style({ 'height': '0' })),
1909
+ state('*', style({ 'height': '*' })),
1910
+ transition('void <=> *', animate(200))
1911
+ ])
1912
+ ],
1913
+ styles: [":host{position:absolute;top:0;right:0;width:300px}:host .selection{position:relative;overflow:hidden;cursor:pointer;font-size:12px;border:1px solid gray}:host .question{font-weight:700}:host .answer{font-size:10px}:host .collapse-handle{position:absolute;top:10px;right:12px;border:solid #000;border-width:0 3px 3px 0;display:inline-block;padding:3px;transform:rotate(45deg);-webkit-transform:rotate(45deg)}:host .collapse-handle.expanded{transform:rotate(-135deg);-webkit-transform:rotate(-135deg)}:host .child-selection{margin-left:10px}"]
1914
+ })
1915
+ ], SelectionsComponent);
1916
+ return SelectionsComponent;
1917
+ }());
1918
+
1919
+ var SelectionsModule = /** @class */ (function () {
1920
+ function SelectionsModule() {
1921
+ }
1922
+ SelectionsModule = __decorate([
1923
+ NgModule({
1924
+ imports: [
1925
+ CommonModule
1926
+ ],
1927
+ declarations: [
1928
+ SelectionsComponent
1929
+ ],
1930
+ exports: [
1931
+ SelectionsComponent
1932
+ ]
1933
+ })
1934
+ ], SelectionsModule);
1935
+ return SelectionsModule;
1936
+ }());
1937
+
1770
1938
  /**
1771
1939
  * Generated bundle index. Do not edit.
1772
1940
  */
1773
1941
 
1774
- export { Builder };
1942
+ export { AnswersComponent, AnswersModule, Builder, SelectionsComponent, SelectionsModule };
1775
1943
  //# sourceMappingURL=colijnit-configurator.js.map