@anker-in/shopify-react 0.1.1-beta.30 → 0.1.1-beta.32
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/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +11 -12
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +11 -12
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.js +13 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -13
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +13 -2
- package/dist/provider/index.d.ts +13 -2
- package/dist/provider/index.js +6 -7
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +6 -7
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -148,14 +148,25 @@ declare function CartProvider({ children, autoFreeGiftConfig, gradientGiftsConfi
|
|
|
148
148
|
/**
|
|
149
149
|
* Hook to access cart context
|
|
150
150
|
*
|
|
151
|
-
* @
|
|
152
|
-
* @returns
|
|
151
|
+
* @param options - Optional configuration
|
|
152
|
+
* @param options.optional - If true, returns undefined instead of throwing error when used outside provider
|
|
153
|
+
* @throws Error if used outside CartProvider (unless optional is true)
|
|
154
|
+
* @returns Cart context value (or undefined if optional is true and no provider exists)
|
|
153
155
|
*
|
|
154
156
|
* @example
|
|
155
157
|
* ```tsx
|
|
156
158
|
* const { cart, mutateCart, isCartLoading, loadingState } = useCartContext()
|
|
159
|
+
*
|
|
160
|
+
* // Optional usage (safe for SSR)
|
|
161
|
+
* const cartContext = useCartContext({ optional: true })
|
|
162
|
+
* if (cartContext) {
|
|
163
|
+
* const { cart } = cartContext
|
|
164
|
+
* }
|
|
157
165
|
* ```
|
|
158
166
|
*/
|
|
159
167
|
declare function useCartContext(): CartContextValue;
|
|
168
|
+
declare function useCartContext(options: {
|
|
169
|
+
optional: true;
|
|
170
|
+
}): CartContextValue | null;
|
|
160
171
|
|
|
161
172
|
export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -148,14 +148,25 @@ declare function CartProvider({ children, autoFreeGiftConfig, gradientGiftsConfi
|
|
|
148
148
|
/**
|
|
149
149
|
* Hook to access cart context
|
|
150
150
|
*
|
|
151
|
-
* @
|
|
152
|
-
* @returns
|
|
151
|
+
* @param options - Optional configuration
|
|
152
|
+
* @param options.optional - If true, returns undefined instead of throwing error when used outside provider
|
|
153
|
+
* @throws Error if used outside CartProvider (unless optional is true)
|
|
154
|
+
* @returns Cart context value (or undefined if optional is true and no provider exists)
|
|
153
155
|
*
|
|
154
156
|
* @example
|
|
155
157
|
* ```tsx
|
|
156
158
|
* const { cart, mutateCart, isCartLoading, loadingState } = useCartContext()
|
|
159
|
+
*
|
|
160
|
+
* // Optional usage (safe for SSR)
|
|
161
|
+
* const cartContext = useCartContext({ optional: true })
|
|
162
|
+
* if (cartContext) {
|
|
163
|
+
* const { cart } = cartContext
|
|
164
|
+
* }
|
|
157
165
|
* ```
|
|
158
166
|
*/
|
|
159
167
|
declare function useCartContext(): CartContextValue;
|
|
168
|
+
declare function useCartContext(options: {
|
|
169
|
+
optional: true;
|
|
170
|
+
}): CartContextValue | null;
|
|
160
171
|
|
|
161
172
|
export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
package/dist/provider/index.js
CHANGED
|
@@ -405,7 +405,6 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
405
405
|
const effectiveCart = react.useMemo(() => {
|
|
406
406
|
return cart;
|
|
407
407
|
}, [lines, cart]);
|
|
408
|
-
console.log("effectiveCart useCalcAutoFreeGift", effectiveCart);
|
|
409
408
|
const { activeCampaign, subtotal } = react.useMemo(() => {
|
|
410
409
|
for (const campaign of autoFreeGiftConfig) {
|
|
411
410
|
const { rule_conditions = [], rule_result } = campaign;
|
|
@@ -421,7 +420,6 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
421
420
|
all_store_variant: spend_get_reward.main_product?.all_store_variant || false
|
|
422
421
|
}
|
|
423
422
|
);
|
|
424
|
-
console.log("matchedSubtotal useCalcAutoFreeGift", matchedSubtotal);
|
|
425
423
|
if (matchedSubtotal > 0) {
|
|
426
424
|
return { activeCampaign: campaign, subtotal: matchedSubtotal };
|
|
427
425
|
}
|
|
@@ -699,7 +697,7 @@ function useUpdateCartAttributes(mutate, metafieldIdentifiers, options) {
|
|
|
699
697
|
}
|
|
700
698
|
return updatedCart;
|
|
701
699
|
},
|
|
702
|
-
[client, locale, cartCookieAdapter, mutate]
|
|
700
|
+
[client, locale, cartCookieAdapter, mutate, metafieldIdentifiers]
|
|
703
701
|
);
|
|
704
702
|
return useSWRMutation8__default.default("update-cart-attributes", updateAttributes, options);
|
|
705
703
|
}
|
|
@@ -735,7 +733,7 @@ function useHasPlusMemberInCart({
|
|
|
735
733
|
}, [cart?.lineItems, plus_monthly_product, plus_annual_product]);
|
|
736
734
|
}
|
|
737
735
|
var getReferralAttributes = () => {
|
|
738
|
-
const inviteCode = shopifySdk.getLocalStorage("
|
|
736
|
+
const inviteCode = shopifySdk.getLocalStorage("inviteCode") || Cookies5__default.default.get("inviteCode");
|
|
739
737
|
const playModeId = shopifySdk.getLocalStorage("playModeId") || Cookies5__default.default.get("playModeId");
|
|
740
738
|
const popup = shopifySdk.getLocalStorage("_popup") || Cookies5__default.default.get("_popup");
|
|
741
739
|
if (inviteCode && playModeId) {
|
|
@@ -1141,7 +1139,8 @@ function CartProvider({
|
|
|
1141
1139
|
cart,
|
|
1142
1140
|
mutateCart,
|
|
1143
1141
|
isCartLoading: isCartLoading || isCodeChanging,
|
|
1144
|
-
setLoadingState
|
|
1142
|
+
setLoadingState,
|
|
1143
|
+
metafieldIdentifiers
|
|
1145
1144
|
});
|
|
1146
1145
|
const removeCustomAttributes = react.useCallback(
|
|
1147
1146
|
(attributes2) => {
|
|
@@ -1282,9 +1281,9 @@ function CartProvider({
|
|
|
1282
1281
|
);
|
|
1283
1282
|
return /* @__PURE__ */ jsxRuntime.jsx(CartContext.Provider, { value, children });
|
|
1284
1283
|
}
|
|
1285
|
-
function useCartContext() {
|
|
1284
|
+
function useCartContext(options) {
|
|
1286
1285
|
const context = react.useContext(CartContext);
|
|
1287
|
-
if (!context) {
|
|
1286
|
+
if (!context && !options?.optional) {
|
|
1288
1287
|
throw new Error("useCartContext must be used within a CartProvider");
|
|
1289
1288
|
}
|
|
1290
1289
|
return context;
|