@anker-in/shopify-react 0.1.1-beta.19 → 0.1.1-beta.20
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/adapters/index.d.mts +2 -2
- package/dist/adapters/index.d.ts +2 -2
- package/dist/hooks/index.d.mts +12 -14
- package/dist/hooks/index.d.ts +12 -14
- package/dist/hooks/index.js +5 -19
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +5 -17
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +18 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -18
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +7 -9
- package/dist/provider/index.d.ts +7 -9
- package/dist/provider/index.js +12 -17
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +11 -16
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-DX-2ABDs.d.mts → types-C1So3siD.d.mts} +2 -16
- package/dist/{types-DX-2ABDs.d.ts → types-C1So3siD.d.ts} +2 -16
- package/dist/{types-BLMoxbOk.d.mts → types-Dt0DUG00.d.mts} +1 -9
- package/dist/{types-BLMoxbOk.d.ts → types-Dt0DUG00.d.ts} +1 -9
- package/package.json +3 -3
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default from 'react';
|
|
3
|
-
import { ShopifyClient, ShopifyConfig, CartCookieAdapter
|
|
4
|
-
import { C as CookieAdapter,
|
|
3
|
+
import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, AttributeInput, HasMetafieldsIdentifier } from '@anker-in/shopify-sdk';
|
|
4
|
+
import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter } from '../types-Dt0DUG00.mjs';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
7
|
-
import { e as PlusMemberSettingsMetafields } from '../types-
|
|
7
|
+
import { e as PlusMemberSettingsMetafields } from '../types-C1So3siD.mjs';
|
|
8
8
|
import 'swr/mutation';
|
|
9
9
|
|
|
10
10
|
interface ShopifyContextValue {
|
|
@@ -24,7 +24,7 @@ interface ShopifyProviderProps {
|
|
|
24
24
|
locale: string;
|
|
25
25
|
locales?: string[];
|
|
26
26
|
cookieAdapter?: CookieAdapter;
|
|
27
|
-
cartCookieAdapter?: CartCookieAdapter
|
|
27
|
+
cartCookieAdapter?: CartCookieAdapter;
|
|
28
28
|
routerAdapter?: RouterAdapter;
|
|
29
29
|
userAdapter?: UserContextAdapter;
|
|
30
30
|
children: React__default.ReactNode;
|
|
@@ -41,10 +41,6 @@ declare function ShopifyProvider({ config, locale, locales, cookieAdapter, cartC
|
|
|
41
41
|
*/
|
|
42
42
|
declare function useShopify(): ShopifyContextValue;
|
|
43
43
|
|
|
44
|
-
type AttributeInput = {
|
|
45
|
-
key: string;
|
|
46
|
-
value: string;
|
|
47
|
-
};
|
|
48
44
|
type LoadingState = {
|
|
49
45
|
editLineQuantityLoading: boolean;
|
|
50
46
|
editLineCodeAmountLoading: boolean;
|
|
@@ -54,6 +50,8 @@ type LoadingState = {
|
|
|
54
50
|
interface CartContextValue {
|
|
55
51
|
/** Current cart data */
|
|
56
52
|
cart: NormalizedCart | undefined;
|
|
53
|
+
/** Total quantity of items in cart */
|
|
54
|
+
totalQuantity: number;
|
|
57
55
|
/** Whether cart is loading */
|
|
58
56
|
isCartLoading: boolean;
|
|
59
57
|
/** Manually trigger cart fetch */
|
|
@@ -161,4 +159,4 @@ declare function CartProvider({ children, autoFreeGiftConfig, gradientGiftsConfi
|
|
|
161
159
|
*/
|
|
162
160
|
declare function useCartContext(): CartContextValue;
|
|
163
161
|
|
|
164
|
-
export { type
|
|
162
|
+
export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default from 'react';
|
|
3
|
-
import { ShopifyClient, ShopifyConfig, CartCookieAdapter
|
|
4
|
-
import { C as CookieAdapter,
|
|
3
|
+
import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, AttributeInput, HasMetafieldsIdentifier } from '@anker-in/shopify-sdk';
|
|
4
|
+
import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter } from '../types-Dt0DUG00.js';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
7
|
-
import { e as PlusMemberSettingsMetafields } from '../types-
|
|
7
|
+
import { e as PlusMemberSettingsMetafields } from '../types-C1So3siD.js';
|
|
8
8
|
import 'swr/mutation';
|
|
9
9
|
|
|
10
10
|
interface ShopifyContextValue {
|
|
@@ -24,7 +24,7 @@ interface ShopifyProviderProps {
|
|
|
24
24
|
locale: string;
|
|
25
25
|
locales?: string[];
|
|
26
26
|
cookieAdapter?: CookieAdapter;
|
|
27
|
-
cartCookieAdapter?: CartCookieAdapter
|
|
27
|
+
cartCookieAdapter?: CartCookieAdapter;
|
|
28
28
|
routerAdapter?: RouterAdapter;
|
|
29
29
|
userAdapter?: UserContextAdapter;
|
|
30
30
|
children: React__default.ReactNode;
|
|
@@ -41,10 +41,6 @@ declare function ShopifyProvider({ config, locale, locales, cookieAdapter, cartC
|
|
|
41
41
|
*/
|
|
42
42
|
declare function useShopify(): ShopifyContextValue;
|
|
43
43
|
|
|
44
|
-
type AttributeInput = {
|
|
45
|
-
key: string;
|
|
46
|
-
value: string;
|
|
47
|
-
};
|
|
48
44
|
type LoadingState = {
|
|
49
45
|
editLineQuantityLoading: boolean;
|
|
50
46
|
editLineCodeAmountLoading: boolean;
|
|
@@ -54,6 +50,8 @@ type LoadingState = {
|
|
|
54
50
|
interface CartContextValue {
|
|
55
51
|
/** Current cart data */
|
|
56
52
|
cart: NormalizedCart | undefined;
|
|
53
|
+
/** Total quantity of items in cart */
|
|
54
|
+
totalQuantity: number;
|
|
57
55
|
/** Whether cart is loading */
|
|
58
56
|
isCartLoading: boolean;
|
|
59
57
|
/** Manually trigger cart fetch */
|
|
@@ -161,4 +159,4 @@ declare function CartProvider({ children, autoFreeGiftConfig, gradientGiftsConfi
|
|
|
161
159
|
*/
|
|
162
160
|
declare function useCartContext(): CartContextValue;
|
|
163
161
|
|
|
164
|
-
export { type
|
|
162
|
+
export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
package/dist/provider/index.js
CHANGED
|
@@ -196,22 +196,12 @@ var getQuery = () => {
|
|
|
196
196
|
}
|
|
197
197
|
return theRequest;
|
|
198
198
|
};
|
|
199
|
-
function atobID(id) {
|
|
200
|
-
if (id && typeof id === "string" && id.includes("/")) {
|
|
201
|
-
return id.split("/").pop()?.split("?")?.shift();
|
|
202
|
-
} else {
|
|
203
|
-
return id;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
function btoaID(id, type = "ProductVariant") {
|
|
207
|
-
return `gid://shopify/${type}/${id}`;
|
|
208
|
-
}
|
|
209
199
|
var getMatchedMainProductSubTotal = (cartData, variant_list, main_product) => {
|
|
210
200
|
const isAllStoreVariant = main_product?.all_store_variant ?? false;
|
|
211
201
|
const matchedList = cartData?.lineItems?.filter((line) => {
|
|
212
202
|
const { is_gift } = getDiscountEnvAttributeValue(line.customAttributes);
|
|
213
203
|
return isAllStoreVariant ? !is_gift : variant_list?.find((item) => {
|
|
214
|
-
return !is_gift && atobID(line.variantId) === item;
|
|
204
|
+
return !is_gift && shopifySdk.atobID(line.variantId) === item;
|
|
215
205
|
});
|
|
216
206
|
});
|
|
217
207
|
return matchedList?.reduce((acc, line) => {
|
|
@@ -451,7 +441,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
451
441
|
if (!giftProduct) return null;
|
|
452
442
|
return {
|
|
453
443
|
variant: {
|
|
454
|
-
id: btoaID(giftProduct.variant_id),
|
|
444
|
+
id: shopifySdk.btoaID(giftProduct.variant_id),
|
|
455
445
|
handle: giftProduct.handle,
|
|
456
446
|
sku: giftProduct.sku
|
|
457
447
|
},
|
|
@@ -727,12 +717,10 @@ function useHasPlusMemberInCart({
|
|
|
727
717
|
};
|
|
728
718
|
}, [cart?.lineItems, plus_monthly_product, plus_annual_product]);
|
|
729
719
|
}
|
|
730
|
-
|
|
731
|
-
// src/hooks/cart/feature/use-cart-attributes.ts
|
|
732
720
|
var getReferralAttributes = () => {
|
|
733
|
-
const inviteCode = Cookies5__default.default.get("invite_code");
|
|
734
|
-
const playModeId = Cookies5__default.default.get("playModeId");
|
|
735
|
-
const popup = Cookies5__default.default.get("_popup");
|
|
721
|
+
const inviteCode = shopifySdk.getLocalStorage("invite_code") || Cookies5__default.default.get("invite_code");
|
|
722
|
+
const playModeId = shopifySdk.getLocalStorage("playModeId") || Cookies5__default.default.get("playModeId");
|
|
723
|
+
const popup = shopifySdk.getLocalStorage("_popup") || Cookies5__default.default.get("_popup");
|
|
736
724
|
if (inviteCode && playModeId) {
|
|
737
725
|
return popup ? [
|
|
738
726
|
{ key: "_invite_code", value: inviteCode ? inviteCode : "" },
|
|
@@ -1224,8 +1212,14 @@ function CartProvider({
|
|
|
1224
1212
|
);
|
|
1225
1213
|
return result;
|
|
1226
1214
|
}, [cart?.lineItems, scriptAutoFreeGift, functionAutoFreeGift]);
|
|
1215
|
+
const totalQuantity = react.useMemo(() => {
|
|
1216
|
+
const cartLinesCount = cart?.lineItems.reduce((acc, item) => acc + item.quantity, 0) || 0;
|
|
1217
|
+
const giftLinesCount = giftNeedAddToCartLines?.reduce((acc, item) => acc + (item.quantity || 1), 0) || 0;
|
|
1218
|
+
return cartLinesCount + giftLinesCount;
|
|
1219
|
+
}, [cart?.lineItems, giftNeedAddToCartLines]);
|
|
1227
1220
|
const value = react.useMemo(
|
|
1228
1221
|
() => ({
|
|
1222
|
+
totalQuantity,
|
|
1229
1223
|
cart,
|
|
1230
1224
|
isCartLoading,
|
|
1231
1225
|
triggerFetch: fetchCart,
|
|
@@ -1253,6 +1247,7 @@ function CartProvider({
|
|
|
1253
1247
|
}),
|
|
1254
1248
|
[
|
|
1255
1249
|
cart,
|
|
1250
|
+
totalQuantity,
|
|
1256
1251
|
isCartLoading,
|
|
1257
1252
|
fetchCart,
|
|
1258
1253
|
mutateCart,
|