@anker-in/shopify-react 1.3.0-beta.0 → 1.3.0-beta.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.
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { createContext, useMemo, useContext, useRef, useState, useEffect, useCal
2
2
  import { createShopifyClient, getProductsByHandles, createCart, updateCartCodes, addCartLines, removeCartLines, getLocalStorage, updateCartLines, updateCartAttributes, updateBuyerIdentity, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getCart, setLocalStorage } from '@anker-in/shopify-sdk';
3
3
  export * from '@anker-in/shopify-sdk';
4
4
  import Cookies5 from 'js-cookie';
5
- import { jsx } from 'react/jsx-runtime';
5
+ import { jsx, jsxs } from 'react/jsx-runtime';
6
6
  import Decimal3 from 'decimal.js';
7
7
  import { atobID, btoaID } from '@anker-in/shopify-core';
8
8
  import useSWR from 'swr';
@@ -3541,6 +3541,16 @@ function clearGeoLocationCache(cacheKey = "geoLocation") {
3541
3541
  }
3542
3542
  }
3543
3543
  var CartContext = createContext(null);
3544
+ function AutoRemoveGiftsHandler({
3545
+ options,
3546
+ onRemovingChange
3547
+ }) {
3548
+ const { isRemoving } = useAutoRemoveFreeGifts(options);
3549
+ useEffect(() => {
3550
+ onRemovingChange(isRemoving);
3551
+ }, [isRemoving, onRemovingChange]);
3552
+ return null;
3553
+ }
3544
3554
  function CartProvider({
3545
3555
  children,
3546
3556
  // swrOptions,
@@ -3568,6 +3578,7 @@ function CartProvider({
3568
3578
  });
3569
3579
  const [scriptAutoFreeGift, setScriptAutoFreeGift] = useState([]);
3570
3580
  const [functionAutoFreeGift, setFunctionAutoFreeGift] = useState([]);
3581
+ const [isAutoRemovingFreeGifts, setIsAutoRemovingFreeGifts] = useState(false);
3571
3582
  const {
3572
3583
  run: fetchCart,
3573
3584
  data: cart,
@@ -3760,7 +3771,8 @@ function CartProvider({
3760
3771
  metafieldIdentifiers,
3761
3772
  memberSetting,
3762
3773
  appContext,
3763
- autoRemoveFreeGiftsOptions
3774
+ autoRemoveFreeGiftsOptions,
3775
+ isAutoRemovingFreeGifts
3764
3776
  }),
3765
3777
  [
3766
3778
  cart,
@@ -3789,10 +3801,20 @@ function CartProvider({
3789
3801
  profile,
3790
3802
  memberSetting,
3791
3803
  appContext,
3792
- autoRemoveFreeGiftsOptions
3804
+ autoRemoveFreeGiftsOptions,
3805
+ isAutoRemovingFreeGifts
3793
3806
  ]
3794
3807
  );
3795
- return /* @__PURE__ */ jsx(CartContext.Provider, { value, children });
3808
+ return /* @__PURE__ */ jsxs(CartContext.Provider, { value, children: [
3809
+ (functionAutoFreeGiftConfig || scriptAutoFreeGiftConfig) && /* @__PURE__ */ jsx(
3810
+ AutoRemoveGiftsHandler,
3811
+ {
3812
+ options: autoRemoveFreeGiftsOptions,
3813
+ onRemovingChange: setIsAutoRemovingFreeGifts
3814
+ }
3815
+ ),
3816
+ children
3817
+ ] });
3796
3818
  }
3797
3819
  function useCartContext(options) {
3798
3820
  const context = useContext(CartContext);