@one-commerce/sdk-core 1.11.0 → 1.13.0

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.
@@ -201,6 +201,8 @@ exports.Errors = exports.Message = void 0;
201
201
  Message["METHOD_CALL_ERROR"] = "one:method:error";
202
202
  Message["METHOD_RESULT"] = "one:method:result";
203
203
  Message["NAVIGATION_PUSH"] = "one:navigation:push";
204
+ Message["FRAME_HEIGHT_REQUEST"] = "one:frameheight:request";
205
+ Message["FRAME_HEIGHT_CHANGE"] = "one:frameheight:change";
204
206
  })(exports.Message || (exports.Message = {}));
205
207
  (function (Errors) {
206
208
  Errors["METHOD_DOES_NOT_EXISTS"] = "Method does not exists";
@@ -723,6 +725,10 @@ var Sdk = /*#__PURE__*/function (_Events) {
723
725
 
724
726
  _defineProperty(_assertThisInitialized(_this), "channel", void 0);
725
727
 
728
+ _defineProperty(_assertThisInitialized(_this), "autoheight", true);
729
+
730
+ _defineProperty(_assertThisInitialized(_this), "heightMutationObserver", null);
731
+
726
732
  _defineProperty(_assertThisInitialized(_this), "origin", void 0);
727
733
 
728
734
  _defineProperty(_assertThisInitialized(_this), "isInitialized", false);
@@ -769,8 +775,20 @@ var Sdk = /*#__PURE__*/function (_Events) {
769
775
  _this.emit(SdkInternalEvents.UPDATE, payload);
770
776
  });
771
777
 
778
+ _this.channel.subscribe(main.Message.FRAME_HEIGHT_REQUEST, function (payload) {
779
+ if (_this.autoheight) {
780
+ Sdk.log('Request for iframe height');
781
+
782
+ _this.sendFrameHeight();
783
+ }
784
+ });
785
+
772
786
  _this.channel.connect().then(function () {
773
787
  Sdk.log('Connected with ONe SDK');
788
+
789
+ if (_this.autoheight) {
790
+ _this.initializeHeightObserver();
791
+ }
774
792
  });
775
793
 
776
794
  _this.setupOptions(options);
@@ -794,6 +812,40 @@ var Sdk = /*#__PURE__*/function (_Events) {
794
812
  });
795
813
  }
796
814
  }
815
+ }, {
816
+ key: "sendFrameHeight",
817
+ value: function sendFrameHeight() {
818
+ var body = document.body,
819
+ html = document.documentElement;
820
+ var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
821
+ this.channel.postMessage(main.Message.FRAME_HEIGHT_CHANGE, height);
822
+ }
823
+ }, {
824
+ key: "initializeHeightObserver",
825
+ value: function initializeHeightObserver() {
826
+ var _this3 = this;
827
+
828
+ if ("MutationObserver" in window) {
829
+ var onMutationObserved = function onMutationObserved() {
830
+ _this3.sendFrameHeight();
831
+ };
832
+
833
+ var target = document.querySelector('body'),
834
+ config = {
835
+ attributes: true,
836
+ attributeOldValue: false,
837
+ characterData: true,
838
+ characterDataOldValue: false,
839
+ childList: true,
840
+ subtree: true
841
+ };
842
+ this.heightMutationObserver = new MutationObserver(onMutationObserved);
843
+ Sdk.log('Create body MutationObserver');
844
+ this.heightMutationObserver.observe(target, config);
845
+ } else {
846
+ Sdk.warn('MutationObserver not available. Auto-height functionality disabled.');
847
+ }
848
+ }
797
849
  }, {
798
850
  key: "setupOptions",
799
851
  value: function setupOptions(options) {
@@ -801,12 +853,16 @@ var Sdk = /*#__PURE__*/function (_Events) {
801
853
  if (typeof options.debug !== 'undefined') {
802
854
  Sdk.debug = options.debug;
803
855
  }
856
+
857
+ if (typeof options.autoheight !== 'undefined') {
858
+ this.autoheight = options.autoheight;
859
+ }
804
860
  }
805
861
  }
806
862
  }, {
807
863
  key: "callFunction",
808
864
  value: function callFunction(service, fun) {
809
- var _this3 = this;
865
+ var _this4 = this;
810
866
 
811
867
  var callId = generateCallId();
812
868
 
@@ -825,13 +881,13 @@ var Sdk = /*#__PURE__*/function (_Events) {
825
881
  return new Promise(function (resolve) {
826
882
  var onChannelMessage = function onChannelMessage(response) {
827
883
  if (response.callId === callId) {
828
- _this3.channel.unsubscribe(main.Message.METHOD_RESULT, onChannelMessage);
884
+ _this4.channel.unsubscribe(main.Message.METHOD_RESULT, onChannelMessage);
829
885
 
830
886
  return resolve(response.result);
831
887
  }
832
888
  };
833
889
 
834
- _this3.channel.subscribe(main.Message.METHOD_RESULT, onChannelMessage);
890
+ _this4.channel.subscribe(main.Message.METHOD_RESULT, onChannelMessage);
835
891
  });
836
892
  }
837
893
 
@@ -878,7 +934,7 @@ var BackofficeSdk = /*#__PURE__*/function (_Sdk) {
878
934
  var _super2 = _createSuper(BackofficeSdk);
879
935
 
880
936
  function BackofficeSdk() {
881
- var _this4;
937
+ var _this5;
882
938
 
883
939
  _classCallCheck(this, BackofficeSdk);
884
940
 
@@ -886,21 +942,21 @@ var BackofficeSdk = /*#__PURE__*/function (_Sdk) {
886
942
  args[_key4] = arguments[_key4];
887
943
  }
888
944
 
889
- _this4 = _super2.call.apply(_super2, [this].concat(args));
945
+ _this5 = _super2.call.apply(_super2, [this].concat(args));
890
946
 
891
- _defineProperty(_assertThisInitialized(_this4), "instances", {
947
+ _defineProperty(_assertThisInitialized(_this5), "instances", {
892
948
  route: {
893
949
  hash: '',
894
950
  query: {}
895
951
  },
896
- orderpath: new BackofficeOrderpath(_this4.callFunction.bind(_assertThisInitialized(_this4))),
897
- catalog: new BackofficeCatalog(_this4.callFunction.bind(_assertThisInitialized(_this4))),
898
- user: new BackofficeUser(_this4.callFunction.bind(_assertThisInitialized(_this4))),
899
- tenant: new BackofficeTenant(_this4.callFunction.bind(_assertThisInitialized(_this4))),
900
- layout: new BackofficeLayout(_this4.callFunction.bind(_assertThisInitialized(_this4)))
952
+ orderpath: new BackofficeOrderpath(_this5.callFunction.bind(_assertThisInitialized(_this5))),
953
+ catalog: new BackofficeCatalog(_this5.callFunction.bind(_assertThisInitialized(_this5))),
954
+ user: new BackofficeUser(_this5.callFunction.bind(_assertThisInitialized(_this5))),
955
+ tenant: new BackofficeTenant(_this5.callFunction.bind(_assertThisInitialized(_this5))),
956
+ layout: new BackofficeLayout(_this5.callFunction.bind(_assertThisInitialized(_this5)))
901
957
  });
902
958
 
903
- return _this4;
959
+ return _this5;
904
960
  }
905
961
 
906
962
  return _createClass(BackofficeSdk);
@@ -911,7 +967,7 @@ var ShopSdk = /*#__PURE__*/function (_Sdk2) {
911
967
  var _super3 = _createSuper(ShopSdk);
912
968
 
913
969
  function ShopSdk() {
914
- var _this5;
970
+ var _this6;
915
971
 
916
972
  _classCallCheck(this, ShopSdk);
917
973
 
@@ -919,21 +975,21 @@ var ShopSdk = /*#__PURE__*/function (_Sdk2) {
919
975
  args[_key5] = arguments[_key5];
920
976
  }
921
977
 
922
- _this5 = _super3.call.apply(_super3, [this].concat(args));
978
+ _this6 = _super3.call.apply(_super3, [this].concat(args));
923
979
 
924
- _defineProperty(_assertThisInitialized(_this5), "instances", {
980
+ _defineProperty(_assertThisInitialized(_this6), "instances", {
925
981
  route: {
926
982
  hash: '',
927
983
  query: {}
928
984
  },
929
- cart: new ShopCart(_this5.callFunction.bind(_assertThisInitialized(_this5))),
930
- catalog: new ShopCatalog(_this5.callFunction.bind(_assertThisInitialized(_this5))),
931
- account: new ShopAccount(_this5.callFunction.bind(_assertThisInitialized(_this5))),
932
- utils: new ShopUtils(_this5.callFunction.bind(_assertThisInitialized(_this5))),
933
- config: new ShopConfig(_this5.callFunction.bind(_assertThisInitialized(_this5)))
985
+ cart: new ShopCart(_this6.callFunction.bind(_assertThisInitialized(_this6))),
986
+ catalog: new ShopCatalog(_this6.callFunction.bind(_assertThisInitialized(_this6))),
987
+ account: new ShopAccount(_this6.callFunction.bind(_assertThisInitialized(_this6))),
988
+ utils: new ShopUtils(_this6.callFunction.bind(_assertThisInitialized(_this6))),
989
+ config: new ShopConfig(_this6.callFunction.bind(_assertThisInitialized(_this6)))
934
990
  });
935
991
 
936
- return _this5;
992
+ return _this6;
937
993
  }
938
994
 
939
995
  return _createClass(ShopSdk);