@pelcro/react-pelcro-js 3.2.0-beta.30 → 3.2.0-beta.31

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.
package/dist/index.cjs.js CHANGED
@@ -6849,6 +6849,53 @@ var ReactGA = _objectSpread({}, Defaults, {
6849
6849
  OutboundLink: OutboundLink
6850
6850
  });
6851
6851
 
6852
+ // Polyfill
6853
+ (() => {
6854
+ if (typeof window.CustomEvent === "function") return false;
6855
+
6856
+ function CustomEvent(event, params = {
6857
+ bubbles: false,
6858
+ cancelable: false,
6859
+ detail: undefined
6860
+ }) {
6861
+ const evt = document.createEvent("CustomEvent");
6862
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
6863
+ return evt;
6864
+ }
6865
+
6866
+ CustomEvent.prototype = window.Event.prototype;
6867
+ window.CustomEvent = CustomEvent;
6868
+ })();
6869
+ /**
6870
+ * Should fire when the cart is opened and expects the cartItems inside the card to be sent
6871
+ */
6872
+
6873
+
6874
+ const cartOpened = detail => createCustomEvent("PelcroElementsCartOpened", detail);
6875
+ /**
6876
+ * Should fire when an item added to the cart and expects the added item to be sent
6877
+ */
6878
+
6879
+ const cartItemAdded = detail => createCustomEvent("PelcroElementsCartItemAdded", detail);
6880
+ /**
6881
+ * Should fire when an item removed from the cart and expects the removed item to be sent
6882
+ */
6883
+
6884
+ const cartItemRemoved = detail => createCustomEvent("PelcroElementsCartItemRemoved", detail);
6885
+ /**
6886
+ * Check if the browser support custom events
6887
+ */
6888
+
6889
+ function createCustomEvent(name, detail) {
6890
+ try {
6891
+ return new CustomEvent(name, {
6892
+ detail
6893
+ });
6894
+ } catch (e) {
6895
+ console.warn("Pelcro - Events are not supported in the browser");
6896
+ }
6897
+ }
6898
+
6852
6899
  class PelcroActions {
6853
6900
  constructor(storeSetter, storeGetter) {
6854
6901
  _defineProperty$3(this, "resetState", () => {
@@ -7010,14 +7057,16 @@ class PelcroActions {
7010
7057
  switchView("login");
7011
7058
  });
7012
7059
 
7013
- _defineProperty$3(this, "addToCart", itemSkuId => {
7014
- const itemToAdd = window.Pelcro.ecommerce.products.getBySkuId(Number(itemSkuId));
7060
+ _defineProperty$3(this, "addToCart", item => {
7061
+ const itemToAdd = window.Pelcro.ecommerce.products.getBySkuId(Number(item.id));
7015
7062
 
7016
7063
  if (!itemToAdd) {
7017
7064
  console.error("invalid item SKU id");
7018
7065
  return false;
7019
- }
7066
+ } //Dispatch PelcroElementsCartItemAdded event when the item got added successfully
7020
7067
 
7068
+
7069
+ document.dispatchEvent(cartItemAdded(item));
7021
7070
  const {
7022
7071
  cartItems
7023
7072
  } = this.get();
@@ -20523,53 +20572,6 @@ const CartTotalPrice = () => {
20523
20572
  return null;
20524
20573
  };
20525
20574
 
20526
- // Polyfill
20527
- (() => {
20528
- if (typeof window.CustomEvent === "function") return false;
20529
-
20530
- function CustomEvent(event, params = {
20531
- bubbles: false,
20532
- cancelable: false,
20533
- detail: undefined
20534
- }) {
20535
- const evt = document.createEvent("CustomEvent");
20536
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
20537
- return evt;
20538
- }
20539
-
20540
- CustomEvent.prototype = window.Event.prototype;
20541
- window.CustomEvent = CustomEvent;
20542
- })();
20543
- /**
20544
- * Should fire when the cart is opened and expects the cartItems inside the card to be sent
20545
- */
20546
-
20547
-
20548
- const cartOpened = detail => createCustomEvent("PelcroElementsCartOpened", detail);
20549
- /**
20550
- * Should fire when an item added to the cart and expects the added item to be sent
20551
- */
20552
-
20553
- const cartItemAdded = detail => createCustomEvent("PelcroElementsCartItemAdded", detail);
20554
- /**
20555
- * Should fire when an item removed from the cart and expects the removed item to be sent
20556
- */
20557
-
20558
- const cartItemRemoved = detail => createCustomEvent("PelcroElementsCartItemRemoved", detail);
20559
- /**
20560
- * Check if the browser support custom events
20561
- */
20562
-
20563
- function createCustomEvent(name, detail) {
20564
- try {
20565
- return new CustomEvent(name, {
20566
- detail
20567
- });
20568
- } catch (e) {
20569
- console.warn("Pelcro - Events are not supported in the browser");
20570
- }
20571
- }
20572
-
20573
20575
  const CartView = props => {
20574
20576
  const {
20575
20577
  cartItems
@@ -20676,8 +20678,7 @@ const ShopSelectProductButton = ({
20676
20678
  const handleClick = () => {
20677
20679
  setDisabled(true);
20678
20680
  setTextContent(t("buttons.added"));
20679
- addToCart(item.id);
20680
- document.dispatchEvent(cartItemAdded(item));
20681
+ addToCart(item);
20681
20682
  onClick === null || onClick === void 0 ? void 0 : onClick();
20682
20683
  setTimeout(() => {
20683
20684
  setDisabled(false);
package/dist/index.esm.js CHANGED
@@ -6819,6 +6819,53 @@ var ReactGA = _objectSpread({}, Defaults, {
6819
6819
  OutboundLink: OutboundLink
6820
6820
  });
6821
6821
 
6822
+ // Polyfill
6823
+ (() => {
6824
+ if (typeof window.CustomEvent === "function") return false;
6825
+
6826
+ function CustomEvent(event, params = {
6827
+ bubbles: false,
6828
+ cancelable: false,
6829
+ detail: undefined
6830
+ }) {
6831
+ const evt = document.createEvent("CustomEvent");
6832
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
6833
+ return evt;
6834
+ }
6835
+
6836
+ CustomEvent.prototype = window.Event.prototype;
6837
+ window.CustomEvent = CustomEvent;
6838
+ })();
6839
+ /**
6840
+ * Should fire when the cart is opened and expects the cartItems inside the card to be sent
6841
+ */
6842
+
6843
+
6844
+ const cartOpened = detail => createCustomEvent("PelcroElementsCartOpened", detail);
6845
+ /**
6846
+ * Should fire when an item added to the cart and expects the added item to be sent
6847
+ */
6848
+
6849
+ const cartItemAdded = detail => createCustomEvent("PelcroElementsCartItemAdded", detail);
6850
+ /**
6851
+ * Should fire when an item removed from the cart and expects the removed item to be sent
6852
+ */
6853
+
6854
+ const cartItemRemoved = detail => createCustomEvent("PelcroElementsCartItemRemoved", detail);
6855
+ /**
6856
+ * Check if the browser support custom events
6857
+ */
6858
+
6859
+ function createCustomEvent(name, detail) {
6860
+ try {
6861
+ return new CustomEvent(name, {
6862
+ detail
6863
+ });
6864
+ } catch (e) {
6865
+ console.warn("Pelcro - Events are not supported in the browser");
6866
+ }
6867
+ }
6868
+
6822
6869
  class PelcroActions {
6823
6870
  constructor(storeSetter, storeGetter) {
6824
6871
  _defineProperty$3(this, "resetState", () => {
@@ -6980,14 +7027,16 @@ class PelcroActions {
6980
7027
  switchView("login");
6981
7028
  });
6982
7029
 
6983
- _defineProperty$3(this, "addToCart", itemSkuId => {
6984
- const itemToAdd = window.Pelcro.ecommerce.products.getBySkuId(Number(itemSkuId));
7030
+ _defineProperty$3(this, "addToCart", item => {
7031
+ const itemToAdd = window.Pelcro.ecommerce.products.getBySkuId(Number(item.id));
6985
7032
 
6986
7033
  if (!itemToAdd) {
6987
7034
  console.error("invalid item SKU id");
6988
7035
  return false;
6989
- }
7036
+ } //Dispatch PelcroElementsCartItemAdded event when the item got added successfully
6990
7037
 
7038
+
7039
+ document.dispatchEvent(cartItemAdded(item));
6991
7040
  const {
6992
7041
  cartItems
6993
7042
  } = this.get();
@@ -20493,53 +20542,6 @@ const CartTotalPrice = () => {
20493
20542
  return null;
20494
20543
  };
20495
20544
 
20496
- // Polyfill
20497
- (() => {
20498
- if (typeof window.CustomEvent === "function") return false;
20499
-
20500
- function CustomEvent(event, params = {
20501
- bubbles: false,
20502
- cancelable: false,
20503
- detail: undefined
20504
- }) {
20505
- const evt = document.createEvent("CustomEvent");
20506
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
20507
- return evt;
20508
- }
20509
-
20510
- CustomEvent.prototype = window.Event.prototype;
20511
- window.CustomEvent = CustomEvent;
20512
- })();
20513
- /**
20514
- * Should fire when the cart is opened and expects the cartItems inside the card to be sent
20515
- */
20516
-
20517
-
20518
- const cartOpened = detail => createCustomEvent("PelcroElementsCartOpened", detail);
20519
- /**
20520
- * Should fire when an item added to the cart and expects the added item to be sent
20521
- */
20522
-
20523
- const cartItemAdded = detail => createCustomEvent("PelcroElementsCartItemAdded", detail);
20524
- /**
20525
- * Should fire when an item removed from the cart and expects the removed item to be sent
20526
- */
20527
-
20528
- const cartItemRemoved = detail => createCustomEvent("PelcroElementsCartItemRemoved", detail);
20529
- /**
20530
- * Check if the browser support custom events
20531
- */
20532
-
20533
- function createCustomEvent(name, detail) {
20534
- try {
20535
- return new CustomEvent(name, {
20536
- detail
20537
- });
20538
- } catch (e) {
20539
- console.warn("Pelcro - Events are not supported in the browser");
20540
- }
20541
- }
20542
-
20543
20545
  const CartView = props => {
20544
20546
  const {
20545
20547
  cartItems
@@ -20646,8 +20648,7 @@ const ShopSelectProductButton = ({
20646
20648
  const handleClick = () => {
20647
20649
  setDisabled(true);
20648
20650
  setTextContent(t("buttons.added"));
20649
- addToCart(item.id);
20650
- document.dispatchEvent(cartItemAdded(item));
20651
+ addToCart(item);
20651
20652
  onClick === null || onClick === void 0 ? void 0 : onClick();
20652
20653
  setTimeout(() => {
20653
20654
  setDisabled(false);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pelcro/react-pelcro-js",
3
3
  "description": "Pelcro's React UI Elements",
4
- "version": "3.2.0-beta.30",
4
+ "version": "3.2.0-beta.31",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",