@plattar/plattar-ar-adapter 1.122.1 → 1.122.2

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.
@@ -698,6 +698,20 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
698
698
  var plattar_api_1 = require("@plattar/plattar-api");
699
699
 
700
700
  var product_ar_1 = require("../ar/product-ar");
701
+ /**
702
+ * This tracks the current state of the Embed
703
+ */
704
+
705
+
706
+ var EmbedState;
707
+
708
+ (function (EmbedState) {
709
+ EmbedState[EmbedState["None"] = 0] = "None";
710
+ EmbedState[EmbedState["SceneViewer"] = 1] = "SceneViewer";
711
+ EmbedState[EmbedState["ProductViewer"] = 2] = "ProductViewer";
712
+ EmbedState[EmbedState["ProductAR"] = 3] = "ProductAR";
713
+ EmbedState[EmbedState["QRCode"] = 4] = "QRCode";
714
+ })(EmbedState || (EmbedState = {}));
701
715
  /**
702
716
  * This is the primary <plattar-embed /> node that allows easy embedding
703
717
  * of Plattar related content
@@ -714,7 +728,14 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
714
728
 
715
729
  _classCallCheck(this, PlattarEmbed);
716
730
 
717
- _this7 = _super5.call(this);
731
+ _this7 = _super5.call(this); // this is the current state of the embed, none by default
732
+
733
+ _this7._currentState = EmbedState.None;
734
+ _this7._qrCodeOptions = {
735
+ color: "#101721",
736
+ qrType: "default",
737
+ margin: 0
738
+ };
718
739
  _this7._sceneID = null;
719
740
  _this7._productID = null;
720
741
  _this7._variationID = null;
@@ -736,6 +757,39 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
736
757
  value: function connectedCallback() {
737
758
  var _this8 = this;
738
759
 
760
+ var observer = new MutationObserver(function (mutations) {
761
+ mutations.forEach(function (mutation) {
762
+ if (mutation.type === "attributes") {
763
+ var sceneID = _this8.hasAttribute("scene-id") ? _this8.getAttribute("scene-id") : null;
764
+ var productID = _this8.hasAttribute("product-id") ? _this8.getAttribute("product-id") : null;
765
+ var variationID = _this8.hasAttribute("variation-id") ? _this8.getAttribute("variation-id") : null;
766
+ var updated = false;
767
+
768
+ if (sceneID !== _this8._sceneID) {
769
+ _this8._sceneID = sceneID;
770
+ updated = true;
771
+ }
772
+
773
+ if (productID !== _this8._productID) {
774
+ _this8._productID = productID;
775
+ updated = true;
776
+ }
777
+
778
+ if (variationID !== _this8._variationID) {
779
+ _this8._variationID = variationID;
780
+ updated = true;
781
+ }
782
+
783
+ if (updated) {
784
+ // re-render based on internal state
785
+ _this8._OnAttributesUpdated();
786
+ }
787
+ }
788
+ });
789
+ });
790
+ observer.observe(this, {
791
+ attributes: true
792
+ });
739
793
  var server = this.hasAttribute("server") ? this.getAttribute("server") : "production";
740
794
  plattar_api_1.Server.create(plattar_api_1.Server.match(server || "production"));
741
795
 
@@ -792,6 +846,15 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
792
846
  if (!_this9._sceneID && _this9._productID) {
793
847
  var product = new product_ar_1.ProductAR(_this9._productID, _this9._variationID);
794
848
  return product.init().then(accept)["catch"](reject);
849
+ } // If Product is set (under any scenario) then use ProductAR
850
+ // NOTE: At some point this should check for Scenes when SceneAR
851
+ // is implemented
852
+
853
+
854
+ if (_this9._productID) {
855
+ var _product = new product_ar_1.ProductAR(_this9._productID, _this9._variationID);
856
+
857
+ return _product.init().then(accept)["catch"](reject);
795
858
  } // otherwise, scene was set so use SceneAR
796
859
 
797
860
 
@@ -860,6 +923,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
860
923
 
861
924
  shadow.append(viewer);
862
925
  _this11._viewer = viewer;
926
+ _this11._currentState = EmbedState.SceneViewer;
863
927
  return;
864
928
  } // if product is set, we use <plattar-product /> node from plattar-web
865
929
 
@@ -890,6 +954,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
890
954
  _shadow.append(_viewer);
891
955
 
892
956
  _this11._viewer = _viewer;
957
+ _this11._currentState = EmbedState.ProductViewer;
893
958
  return;
894
959
  }
895
960
 
@@ -907,11 +972,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
907
972
  return reject(new Error("PlattarEmbed.startQRCode() - cannot execute as page has not loaded yet"));
908
973
  }
909
974
 
910
- var opt = options || {
911
- color: "#101721",
912
- qrType: "default",
913
- margin: 0
914
- };
975
+ var opt = options || _this12._qrCodeOptions; // reset instance for later use
976
+
977
+ _this12._qrCodeOptions = opt;
915
978
 
916
979
  if (_this12._viewer) {
917
980
  _this12._viewer.remove();
@@ -959,6 +1022,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
959
1022
 
960
1023
  shadow.append(viewer);
961
1024
  _this12._viewer = viewer;
1025
+ _this12._currentState = EmbedState.QRCode;
962
1026
  return;
963
1027
  } // if product is set, we embed a QR code that takes us to product.html
964
1028
 
@@ -1001,12 +1065,53 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1001
1065
  _shadow2.append(_viewer2);
1002
1066
 
1003
1067
  _this12._viewer = _viewer2;
1068
+ _this12._currentState = EmbedState.QRCode;
1004
1069
  return;
1005
1070
  }
1006
1071
 
1007
1072
  return reject(new Error("PlattarEmbed.startQRCode() - minimum required attributes not set, use scene-id or product-id as a minimum"));
1008
1073
  });
1009
1074
  }
1075
+ /**
1076
+ * This is called by the observer if any of the embed attributes have changed
1077
+ * based on the state of the embed, we update the internal structure accordingly
1078
+ */
1079
+
1080
+ }, {
1081
+ key: "_OnAttributesUpdated",
1082
+ value: function _OnAttributesUpdated() {
1083
+ // nothing to update in these scenarios
1084
+ if (this._currentState === EmbedState.None || this._currentState === EmbedState.ProductAR) {
1085
+ return;
1086
+ } // re-render the QR Code when attributes have changed
1087
+
1088
+
1089
+ if (this._currentState === EmbedState.QRCode) {
1090
+ this.startQRCode(this._qrCodeOptions);
1091
+ return;
1092
+ } // use the messenger function to change variation when attributes have changed
1093
+
1094
+
1095
+ if (this._currentState === EmbedState.SceneViewer) {
1096
+ var viewer = this.viewer;
1097
+
1098
+ if (viewer) {
1099
+ viewer.messenger.selectVariation(this._productID, this._variationID);
1100
+ }
1101
+
1102
+ return;
1103
+ }
1104
+
1105
+ if (this._currentState === EmbedState.ProductViewer) {
1106
+ var _viewer3 = this.viewer;
1107
+
1108
+ if (_viewer3) {
1109
+ _viewer3.messenger.selectVariation(this._variationID);
1110
+ }
1111
+
1112
+ return;
1113
+ }
1114
+ }
1010
1115
  }]);
1011
1116
 
1012
1117
  return PlattarEmbed;
@@ -1265,7 +1370,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1265
1370
  Object.defineProperty(exports, "__esModule", {
1266
1371
  value: true
1267
1372
  });
1268
- exports["default"] = "1.122.1";
1373
+ exports["default"] = "1.122.2";
1269
1374
  }, {}],
1270
1375
  10: [function (require, module, exports) {
1271
1376
  "use strict";