@plattar/plattar-ar-adapter 1.155.3 → 1.155.4-b2

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.
@@ -976,12 +976,58 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
976
976
  return;
977
977
  }
978
978
  }
979
+ async startARQRCode(options) {
980
+ try {
981
+ const dState = await this.getConfiguratorState();
982
+ // if this is declared, we have a furniture scene that we need to re-create the embed
983
+ // with new attributes
984
+ const product = dState.state.firstOfType("product");
985
+ if (product) {
986
+ this.parent.lockObserver();
987
+ this.parent.destroy();
988
+ this.setAttribute("product-id", product.scene_product_id);
989
+ this.parent.unlockObserver();
990
+ const controller = this.parent.create();
991
+ if (controller) {
992
+ return controller.startARQRCode(options);
993
+ }
994
+ return Promise.reject(new Error("ConfiguratorController.startARQRCode() - legacy product transition failed"));
995
+ }
996
+ }
997
+ catch (_err) {
998
+ }
999
+ return super.startARQRCode(options);
1000
+ }
979
1001
  async startViewerQRCode(options) {
980
1002
  // remove the old renderer instance if any
981
1003
  this.removeRenderer();
982
1004
  const sceneID = this.getAttribute("scene-id");
983
1005
  if (!sceneID) {
984
- throw new Error("ConfiguratorController.startQRCode() - minimum required attributes not set, use scene-id as a minimum");
1006
+ throw new Error("ConfiguratorController.startViewerQRCode() - minimum required attributes not set, use scene-id as a minimum");
1007
+ }
1008
+ // optional attributes
1009
+ let configState = null;
1010
+ try {
1011
+ const dState = await this.getConfiguratorState();
1012
+ // if this is declared, we have a furniture scene that we need to re-create the embed
1013
+ // with new attributes
1014
+ const product = dState.state.firstOfType("product");
1015
+ if (product) {
1016
+ this.parent.lockObserver();
1017
+ this.parent.destroy();
1018
+ this.setAttribute("product-id", product.scene_product_id);
1019
+ this.parent.unlockObserver();
1020
+ const controller = this.parent.create();
1021
+ if (controller) {
1022
+ return controller.startViewerQRCode(options);
1023
+ }
1024
+ return Promise.reject(new Error("ConfiguratorController.startViewerQRCode() - legacy product transition failed"));
1025
+ }
1026
+ configState = dState.state.encode();
1027
+ }
1028
+ catch (_err) {
1029
+ // config state is not available
1030
+ configState = null;
985
1031
  }
986
1032
  const opt = options || this._GetDefaultQROptions();
987
1033
  const viewer = document.createElement("plattar-qrcode");
@@ -1002,17 +1048,8 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
1002
1048
  }
1003
1049
  viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
1004
1050
  let dst = plattar_api_1.Server.location().base + "renderer/configurator.html?scene_id=" + sceneID;
1005
- // optional attributes
1006
- let configState = null;
1007
1051
  const showAR = this.getAttribute("show-ar");
1008
1052
  const showUI = this.getAttribute("show-ui");
1009
- try {
1010
- configState = (await this.getConfiguratorState()).state.encode();
1011
- }
1012
- catch (_err) {
1013
- // config state is not available
1014
- configState = null;
1015
- }
1016
1053
  if (showUI && showUI === "true") {
1017
1054
  dst = plattar_api_1.Server.location().base + "configurator/dist/index.html?scene_id=" + sceneID;
1018
1055
  }
@@ -1039,6 +1076,30 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
1039
1076
  if (!sceneID) {
1040
1077
  throw new Error("ConfiguratorController.startRenderer() - minimum required attributes not set, use scene-id as a minimum");
1041
1078
  }
1079
+ // optional attributes
1080
+ let configState = null;
1081
+ try {
1082
+ const dState = await this.getConfiguratorState();
1083
+ // if this is declared, we have a furniture scene that we need to re-create the embed
1084
+ // with new attributes
1085
+ const product = dState.state.firstOfType("product");
1086
+ if (product) {
1087
+ this.parent.lockObserver();
1088
+ this.parent.destroy();
1089
+ this.setAttribute("product-id", product.scene_product_id);
1090
+ this.parent.unlockObserver();
1091
+ const controller = this.parent.create();
1092
+ if (controller) {
1093
+ return controller.startRenderer();
1094
+ }
1095
+ return Promise.reject(new Error("ConfiguratorController.startRenderer() - legacy product transition failed"));
1096
+ }
1097
+ configState = dState;
1098
+ }
1099
+ catch (_err) {
1100
+ // config state is not available
1101
+ configState = null;
1102
+ }
1042
1103
  // required attributes with defaults for plattar-configurator node
1043
1104
  const width = this.getAttribute("width") || "500px";
1044
1105
  const height = this.getAttribute("height") || "500px";
@@ -1049,15 +1110,6 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
1049
1110
  viewer.setAttribute("height", height);
1050
1111
  viewer.setAttribute("server", server);
1051
1112
  viewer.setAttribute("scene-id", sceneID);
1052
- // optional attributes
1053
- let configState = null;
1054
- try {
1055
- configState = await this.getConfiguratorState();
1056
- }
1057
- catch (_err) {
1058
- // config state is not available
1059
- configState = null;
1060
- }
1061
1113
  const showAR = this.getAttribute("show-ar");
1062
1114
  const showUI = this.getAttribute("show-ui");
1063
1115
  if (configState) {
@@ -1082,6 +1134,26 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
1082
1134
  if (!util_1.Util.canAugment()) {
1083
1135
  throw new Error("ConfiguratorController.initAR() - cannot proceed as AR not available in context");
1084
1136
  }
1137
+ try {
1138
+ const dState = await this.getConfiguratorState();
1139
+ // if this is declared, we have a furniture scene that we need to re-create the embed
1140
+ // with new attributes
1141
+ const product = dState.state.firstOfType("product");
1142
+ if (product) {
1143
+ this.parent.lockObserver();
1144
+ this.parent.destroy();
1145
+ this.setAttribute("product-id", product.scene_product_id);
1146
+ this.parent.unlockObserver();
1147
+ const controller = this.parent.create();
1148
+ if (controller) {
1149
+ return controller.initAR();
1150
+ }
1151
+ return Promise.reject(new Error("ConfiguratorController.initAR() - legacy product transition failed"));
1152
+ }
1153
+ }
1154
+ catch (_err) {
1155
+ // config state is not available
1156
+ }
1085
1157
  const arMode = this.getAttribute("ar-mode") || "generated";
1086
1158
  switch (arMode.toLowerCase()) {
1087
1159
  case "inherited":
@@ -1341,12 +1413,23 @@ class PlattarController {
1341
1413
  }
1342
1414
  /**
1343
1415
  * Returns the specified attribute from the parent
1344
- * @param attribute - The name of thhe attribute
1416
+ * @param attribute - The name of the attribute
1345
1417
  * @returns - The attribute value or null
1346
1418
  */
1347
1419
  getAttribute(attribute) {
1348
1420
  return this.parent ? (this.parent.hasAttribute(attribute) ? this.parent.getAttribute(attribute) : null) : null;
1349
1421
  }
1422
+ /**
1423
+ * Sets a particular attribute into the HTML DOM
1424
+ *
1425
+ * @param attribute - The name of the attribute
1426
+ * @param value - The value of the attribute
1427
+ */
1428
+ setAttribute(attribute, value) {
1429
+ if (this.parent) {
1430
+ this.parent.setAttribute(attribute, value);
1431
+ }
1432
+ }
1350
1433
  /**
1351
1434
  * Appends the provided element into the shadow-root of the parent element
1352
1435
  * @param element - The element to append
@@ -1376,11 +1459,6 @@ class ProductController extends plattar_controller_1.PlattarController {
1376
1459
  async getConfiguratorState() {
1377
1460
  throw new Error("ProductController.getConfiguratorState() - legacy embeds do not support configurator states");
1378
1461
  }
1379
- constructor(parent) {
1380
- // this is a hack against DecodedConfiguratorState that's now stored in PlattarController
1381
- // this is not used in legacy mode
1382
- super(parent);
1383
- }
1384
1462
  async onAttributesUpdated(attributeName) {
1385
1463
  const state = this._state;
1386
1464
  // re-render the QR Code when attributes have changed
@@ -1848,6 +1926,14 @@ var EmbedType;
1848
1926
  EmbedType[EmbedType["VTO"] = 2] = "VTO";
1849
1927
  EmbedType[EmbedType["None"] = 3] = "None";
1850
1928
  })(EmbedType || (EmbedType = {}));
1929
+ /**
1930
+ * Controls the state of the observer
1931
+ */
1932
+ var ObserverState;
1933
+ (function (ObserverState) {
1934
+ ObserverState[ObserverState["Locked"] = 0] = "Locked";
1935
+ ObserverState[ObserverState["Unlocked"] = 1] = "Unlocked";
1936
+ })(ObserverState || (ObserverState = {}));
1851
1937
  /**
1852
1938
  * This is the primary <plattar-embed /> node that allows easy embedding
1853
1939
  * of Plattar related content
@@ -1857,6 +1943,7 @@ class PlattarEmbed extends HTMLElement {
1857
1943
  super();
1858
1944
  // this is the current embed type, viewer by default
1859
1945
  this._currentType = EmbedType.None;
1946
+ this._observerState = ObserverState.Unlocked;
1860
1947
  this._controller = null;
1861
1948
  this._currentSceneID = null;
1862
1949
  this._observer = null;
@@ -1879,17 +1966,19 @@ class PlattarEmbed extends HTMLElement {
1879
1966
  plattar_api_1.Server.create(plattar_api_1.Server.match(server || "production"));
1880
1967
  if (!this._observer) {
1881
1968
  this._observer = new MutationObserver((mutations) => {
1882
- mutations.forEach((mutation) => {
1883
- if (mutation.type === "attributes") {
1884
- const attributeName = mutation.attributeName ? mutation.attributeName : "none";
1885
- if (this._currentType !== EmbedType.Legacy) {
1886
- this._CreateEmbed(attributeName);
1887
- }
1888
- else {
1889
- this._OnAttributesUpdated(attributeName);
1969
+ if (this._observerState === ObserverState.Unlocked) {
1970
+ mutations.forEach((mutation) => {
1971
+ if (mutation.type === "attributes") {
1972
+ const attributeName = mutation.attributeName ? mutation.attributeName : "none";
1973
+ if (this._currentType !== EmbedType.Legacy) {
1974
+ this._CreateEmbed(attributeName);
1975
+ }
1976
+ else {
1977
+ this._OnAttributesUpdated(attributeName);
1978
+ }
1890
1979
  }
1891
- }
1892
- });
1980
+ });
1981
+ }
1893
1982
  });
1894
1983
  this._observer.observe(this, {
1895
1984
  attributes: true
@@ -1899,9 +1988,22 @@ class PlattarEmbed extends HTMLElement {
1899
1988
  if (productID) {
1900
1989
  this._currentType = EmbedType.Legacy;
1901
1990
  this._CreateLegacyEmbed();
1902
- return;
1991
+ return this._controller;
1903
1992
  }
1904
1993
  this._CreateEmbed("none");
1994
+ return this._controller;
1995
+ }
1996
+ /**
1997
+ * Locks the observer so attribute changes do not trigger anything
1998
+ */
1999
+ lockObserver() {
2000
+ this._observerState = ObserverState.Locked;
2001
+ }
2002
+ /**
2003
+ * Unlocks the observer so attribute changes will start to re-trigger properly
2004
+ */
2005
+ unlockObserver() {
2006
+ this._observerState = ObserverState.Unlocked;
1905
2007
  }
1906
2008
  /**
1907
2009
  * Destroys the active instance of this embed and resets internal state to default
@@ -2111,6 +2213,7 @@ class ConfiguratorState {
2111
2213
  meta: {
2112
2214
  scene_product_index: 0,
2113
2215
  scene_model_index: 0,
2216
+ product_index: 0,
2114
2217
  product_variation_index: 1,
2115
2218
  meta_index: 2,
2116
2219
  },
@@ -2124,6 +2227,7 @@ class ConfiguratorState {
2124
2227
  if (parsedState.meta) {
2125
2228
  defaultState.meta.scene_product_index = parsedState.meta.scene_product_index || 0;
2126
2229
  defaultState.meta.scene_model_index = parsedState.meta.scene_model_index || 0;
2230
+ defaultState.meta.product_index = parsedState.meta.product_index || 0;
2127
2231
  defaultState.meta.product_variation_index = parsedState.meta.product_variation_index || 1;
2128
2232
  defaultState.meta.meta_index = parsedState.meta.meta_index || 2;
2129
2233
  }
@@ -2200,6 +2304,33 @@ class ConfiguratorState {
2200
2304
  newData[meta.meta_index] = metaData;
2201
2305
  }
2202
2306
  }
2307
+ /**
2308
+ * Adds a new Product with meta-data into the Configurator State
2309
+ *
2310
+ * @param productID - The Product ID to add
2311
+ * @param metaData - Arbitrary meta-data that can be used against certain operaions
2312
+ */
2313
+ setProduct(productID, productVariationID, metaData = null) {
2314
+ if (productID && productVariationID) {
2315
+ metaData = metaData || { augment: true, type: "product" };
2316
+ metaData.type = "product";
2317
+ const states = this._state.states;
2318
+ const meta = this._state.meta;
2319
+ let newData = null;
2320
+ const existingData = this.findSceneProductIndex(productID);
2321
+ if (existingData) {
2322
+ newData = existingData;
2323
+ }
2324
+ else {
2325
+ newData = [];
2326
+ // push the new data into the stack
2327
+ states.push(newData);
2328
+ }
2329
+ newData[meta.product_index] = productID;
2330
+ newData[meta.product_variation_index] = productVariationID;
2331
+ newData[meta.meta_index] = metaData;
2332
+ }
2333
+ }
2203
2334
  /**
2204
2335
  * Adds a new Scene Product/Variation combo with meta-data into the Configurator State
2205
2336
  *
@@ -2343,6 +2474,35 @@ class ConfiguratorState {
2343
2474
  }
2344
2475
  return null;
2345
2476
  }
2477
+ /**
2478
+ * @returns Returns the first reference of data in the stack that matches a type, otherwise returns null
2479
+ */
2480
+ firstOfType(type) {
2481
+ const states = this._state.states;
2482
+ if (states.length > 0) {
2483
+ const meta = this._state.meta;
2484
+ const found = states.find((productState) => {
2485
+ const check = productState[meta.scene_product_index];
2486
+ if (check !== null && check !== undefined) {
2487
+ return productState.length === 3 && productState[meta.meta_index].type === type;
2488
+ }
2489
+ return false;
2490
+ });
2491
+ if (!found) {
2492
+ return null;
2493
+ }
2494
+ const data = {
2495
+ scene_product_id: found[meta.scene_product_index],
2496
+ product_variation_id: found[meta.product_variation_index],
2497
+ meta_data: {
2498
+ augment: found[meta.meta_index].augment || true,
2499
+ type: found[meta.meta_index].type || type
2500
+ }
2501
+ };
2502
+ return data;
2503
+ }
2504
+ return null;
2505
+ }
2346
2506
  get length() {
2347
2507
  return this._state.states.length;
2348
2508
  }
@@ -2368,6 +2528,7 @@ class ConfiguratorState {
2368
2528
  const configState = new ConfiguratorState(state);
2369
2529
  const fscene = new plattar_api_1.Scene(sceneID);
2370
2530
  fscene.include(plattar_api_1.Project);
2531
+ fscene.include(plattar_api_1.Product);
2371
2532
  fscene.include(plattar_api_1.SceneProduct);
2372
2533
  fscene.include(plattar_api_1.SceneModel);
2373
2534
  fscene.include(plattar_api_1.SceneProduct.include(plattar_api_1.Product.include(plattar_api_1.ProductVariation)));
@@ -2392,18 +2553,29 @@ class ConfiguratorState {
2392
2553
  fscene.include(plattar_api_1.Project);
2393
2554
  fscene.include(plattar_api_1.SceneProduct);
2394
2555
  fscene.include(plattar_api_1.SceneModel);
2556
+ fscene.include(plattar_api_1.Product);
2395
2557
  fscene.include(plattar_api_1.SceneProduct.include(plattar_api_1.Product.include(plattar_api_1.ProductVariation)));
2396
2558
  const scene = await fscene.get();
2397
2559
  const sceneProducts = scene.relationships.filter(plattar_api_1.SceneProduct);
2398
2560
  const sceneModels = scene.relationships.filter(plattar_api_1.SceneModel);
2399
- // add out scene models
2561
+ const products = scene.relationships.filter(plattar_api_1.Product);
2562
+ // add our scene models
2400
2563
  sceneModels.forEach((sceneModel) => {
2401
2564
  configState.setSceneModel(sceneModel.id, {
2402
2565
  augment: sceneModel.attributes.include_in_augment,
2403
2566
  type: "scenemodel"
2404
2567
  });
2405
2568
  });
2406
- // add out scene products
2569
+ // add our products - this is used when scene == furniture
2570
+ products.forEach((product) => {
2571
+ if (product.attributes.product_variation_id) {
2572
+ configState.setProduct(product.id, product.attributes.product_variation_id, {
2573
+ augment: true,
2574
+ type: "product"
2575
+ });
2576
+ }
2577
+ });
2578
+ // add our scene products
2407
2579
  sceneProducts.forEach((sceneProduct) => {
2408
2580
  const product = sceneProduct.relationships.find(plattar_api_1.Product);
2409
2581
  if (product) {
@@ -2521,7 +2693,7 @@ exports.Util = Util;
2521
2693
  },{}],16:[function(require,module,exports){
2522
2694
  "use strict";
2523
2695
  Object.defineProperty(exports, "__esModule", { value: true });
2524
- exports.default = "1.155.3";
2696
+ exports.default = "1.155.4-b2";
2525
2697
 
2526
2698
  },{}],17:[function(require,module,exports){
2527
2699
  "use strict";