@anker-in/shopify-react 1.2.8 → 1.2.9-beta.1
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 +23 -6
- package/dist/hooks/index.d.ts +23 -6
- package/dist/hooks/index.js +139 -171
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +141 -173
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -61
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -63
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +1 -3
- package/dist/provider/index.d.ts +1 -3
- package/dist/provider/index.js +7 -173
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +9 -175
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-C0UyuPrG.d.mts → types-DfR13pDe.d.mts} +5 -12
- package/dist/{types-C0UyuPrG.d.ts → types-DfR13pDe.d.ts} +5 -12
- package/package.json +17 -17
package/dist/index.mjs
CHANGED
|
@@ -2,12 +2,12 @@ import { createContext, useMemo, useContext, useRef, useState, useEffect, useCal
|
|
|
2
2
|
import { createShopifyClient, getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, getLocalStorage, 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
|
|
5
|
+
import { jsx } 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';
|
|
9
9
|
import useSWRMutation from 'swr/mutation';
|
|
10
|
-
import {
|
|
10
|
+
import { useRequest } from 'ahooks';
|
|
11
11
|
|
|
12
12
|
// src/provider/context.ts
|
|
13
13
|
var ShopifyContext = createContext(null);
|
|
@@ -1307,13 +1307,9 @@ function useAutoRemoveFreeGifts(options = {}) {
|
|
|
1307
1307
|
const {
|
|
1308
1308
|
removeFunctionGifts = true,
|
|
1309
1309
|
removeScriptGifts = true,
|
|
1310
|
-
isGiftLineItem
|
|
1311
|
-
runOnlyOnceAfterInit = false,
|
|
1312
|
-
initDelay = 500
|
|
1310
|
+
isGiftLineItem
|
|
1313
1311
|
} = options;
|
|
1314
1312
|
const [isRemoving, setIsRemoving] = useState(false);
|
|
1315
|
-
const [isInitialized, setIsInitialized] = useState(!runOnlyOnceAfterInit);
|
|
1316
|
-
const [isFinished, setIsFinished] = useState(false);
|
|
1317
1313
|
const { cart } = useCartContext();
|
|
1318
1314
|
const { trigger: removeCartLines2 } = useRemoveCartLines();
|
|
1319
1315
|
const giftsToRemove = useMemo(() => {
|
|
@@ -1350,29 +1346,7 @@ function useAutoRemoveFreeGifts(options = {}) {
|
|
|
1350
1346
|
return false;
|
|
1351
1347
|
});
|
|
1352
1348
|
}, [cart, removeFunctionGifts, removeScriptGifts, isGiftLineItem]);
|
|
1353
|
-
useDebounceEffect(
|
|
1354
|
-
() => {
|
|
1355
|
-
if (!runOnlyOnceAfterInit || isInitialized || isFinished) {
|
|
1356
|
-
return;
|
|
1357
|
-
}
|
|
1358
|
-
if (!cart?.lineItems?.length) {
|
|
1359
|
-
return;
|
|
1360
|
-
}
|
|
1361
|
-
setIsInitialized(true);
|
|
1362
|
-
if (giftsToRemove.length === 0) {
|
|
1363
|
-
setIsFinished(true);
|
|
1364
|
-
}
|
|
1365
|
-
},
|
|
1366
|
-
[runOnlyOnceAfterInit, isInitialized, isFinished, cart?.lineItems, giftsToRemove.length],
|
|
1367
|
-
{
|
|
1368
|
-
trailing: true,
|
|
1369
|
-
wait: initDelay
|
|
1370
|
-
}
|
|
1371
|
-
);
|
|
1372
1349
|
useEffect(() => {
|
|
1373
|
-
if (runOnlyOnceAfterInit && (!isInitialized || isFinished)) {
|
|
1374
|
-
return;
|
|
1375
|
-
}
|
|
1376
1350
|
if (isRemoving || giftsToRemove.length === 0) {
|
|
1377
1351
|
return;
|
|
1378
1352
|
}
|
|
@@ -1386,16 +1360,10 @@ function useAutoRemoveFreeGifts(options = {}) {
|
|
|
1386
1360
|
console.error("Failed to remove free gifts:", error);
|
|
1387
1361
|
} finally {
|
|
1388
1362
|
setIsRemoving(false);
|
|
1389
|
-
if (runOnlyOnceAfterInit) {
|
|
1390
|
-
setIsFinished(true);
|
|
1391
|
-
}
|
|
1392
1363
|
}
|
|
1393
1364
|
};
|
|
1394
1365
|
performRemoval();
|
|
1395
1366
|
}, [
|
|
1396
|
-
runOnlyOnceAfterInit,
|
|
1397
|
-
isInitialized,
|
|
1398
|
-
isFinished,
|
|
1399
1367
|
isRemoving,
|
|
1400
1368
|
giftsToRemove,
|
|
1401
1369
|
removeCartLines2
|
|
@@ -3601,16 +3569,6 @@ function clearGeoLocationCache(cacheKey = "geoLocation") {
|
|
|
3601
3569
|
}
|
|
3602
3570
|
}
|
|
3603
3571
|
var CartContext = createContext(null);
|
|
3604
|
-
function AutoRemoveGiftsHandler({
|
|
3605
|
-
options,
|
|
3606
|
-
onRemovingChange
|
|
3607
|
-
}) {
|
|
3608
|
-
const { isRemoving } = useAutoRemoveFreeGifts(options);
|
|
3609
|
-
useEffect(() => {
|
|
3610
|
-
onRemovingChange(isRemoving);
|
|
3611
|
-
}, [isRemoving, onRemovingChange]);
|
|
3612
|
-
return null;
|
|
3613
|
-
}
|
|
3614
3572
|
function CartProvider({
|
|
3615
3573
|
children,
|
|
3616
3574
|
// swrOptions,
|
|
@@ -3638,7 +3596,6 @@ function CartProvider({
|
|
|
3638
3596
|
});
|
|
3639
3597
|
const [scriptAutoFreeGift, setScriptAutoFreeGift] = useState([]);
|
|
3640
3598
|
const [functionAutoFreeGift, setFunctionAutoFreeGift] = useState([]);
|
|
3641
|
-
const [isAutoRemovingFreeGifts, setIsAutoRemovingFreeGifts] = useState(false);
|
|
3642
3599
|
const {
|
|
3643
3600
|
run: fetchCart,
|
|
3644
3601
|
data: cart,
|
|
@@ -3798,9 +3755,7 @@ function CartProvider({
|
|
|
3798
3755
|
const autoRemoveFreeGiftsOptions = useMemo(() => {
|
|
3799
3756
|
return {
|
|
3800
3757
|
removeFunctionGifts: !!functionAutoFreeGiftConfig,
|
|
3801
|
-
removeScriptGifts: !!scriptAutoFreeGiftConfig
|
|
3802
|
-
runOnlyOnceAfterInit: true,
|
|
3803
|
-
initDelay: 500
|
|
3758
|
+
removeScriptGifts: !!scriptAutoFreeGiftConfig
|
|
3804
3759
|
};
|
|
3805
3760
|
}, [functionAutoFreeGiftConfig, scriptAutoFreeGiftConfig]);
|
|
3806
3761
|
const value = useMemo(
|
|
@@ -3833,8 +3788,7 @@ function CartProvider({
|
|
|
3833
3788
|
metafieldIdentifiers,
|
|
3834
3789
|
memberSetting,
|
|
3835
3790
|
appContext,
|
|
3836
|
-
autoRemoveFreeGiftsOptions
|
|
3837
|
-
isAutoRemovingFreeGifts
|
|
3791
|
+
autoRemoveFreeGiftsOptions
|
|
3838
3792
|
}),
|
|
3839
3793
|
[
|
|
3840
3794
|
cart,
|
|
@@ -3863,20 +3817,10 @@ function CartProvider({
|
|
|
3863
3817
|
profile,
|
|
3864
3818
|
memberSetting,
|
|
3865
3819
|
appContext,
|
|
3866
|
-
autoRemoveFreeGiftsOptions
|
|
3867
|
-
isAutoRemovingFreeGifts
|
|
3820
|
+
autoRemoveFreeGiftsOptions
|
|
3868
3821
|
]
|
|
3869
3822
|
);
|
|
3870
|
-
return /* @__PURE__ */
|
|
3871
|
-
(functionAutoFreeGiftConfig || scriptAutoFreeGiftConfig) && /* @__PURE__ */ jsx(
|
|
3872
|
-
AutoRemoveGiftsHandler,
|
|
3873
|
-
{
|
|
3874
|
-
options: autoRemoveFreeGiftsOptions,
|
|
3875
|
-
onRemovingChange: setIsAutoRemovingFreeGifts
|
|
3876
|
-
}
|
|
3877
|
-
),
|
|
3878
|
-
children
|
|
3879
|
-
] });
|
|
3823
|
+
return /* @__PURE__ */ jsx(CartContext.Provider, { value, children });
|
|
3880
3824
|
}
|
|
3881
3825
|
function useCartContext(options) {
|
|
3882
3826
|
const context = useContext(CartContext);
|