@anker-in/shopify-react 1.3.0-beta.2 → 1.3.0-beta.4
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 +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +84 -24
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +86 -26
- 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 +87 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -27
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +1 -1
- package/dist/provider/index.d.ts +1 -1
- package/dist/provider/index.js +40 -6
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +40 -6
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-CM5QrlnE.d.mts → types-C0UyuPrG.d.mts} +10 -0
- package/dist/{types-CM5QrlnE.d.ts → types-C0UyuPrG.d.ts} +10 -0
- package/package.json +4 -4
|
@@ -4,7 +4,7 @@ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, Attrib
|
|
|
4
4
|
import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter, P as PerformanceAdapter } from '../types-SKDHauqk.mjs';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
7
|
-
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-
|
|
7
|
+
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-C0UyuPrG.mjs';
|
|
8
8
|
import 'decimal.js';
|
|
9
9
|
|
|
10
10
|
interface ShopifyContextValue {
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, Attrib
|
|
|
4
4
|
import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter, P as PerformanceAdapter } from '../types-SKDHauqk.js';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
7
|
-
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-
|
|
7
|
+
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-C0UyuPrG.js';
|
|
8
8
|
import 'decimal.js';
|
|
9
9
|
|
|
10
10
|
interface ShopifyContextValue {
|
package/dist/provider/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
var Decimal3 = require('decimal.js');
|
|
8
8
|
var shopifyCore = require('@anker-in/shopify-core');
|
|
9
9
|
var useSWR = require('swr');
|
|
10
|
-
var
|
|
10
|
+
var useSWRMutation6 = require('swr/mutation');
|
|
11
11
|
var ahooks = require('ahooks');
|
|
12
12
|
|
|
13
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -15,7 +15,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
15
15
|
var Cookies5__default = /*#__PURE__*/_interopDefault(Cookies5);
|
|
16
16
|
var Decimal3__default = /*#__PURE__*/_interopDefault(Decimal3);
|
|
17
17
|
var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
|
|
18
|
-
var
|
|
18
|
+
var useSWRMutation6__default = /*#__PURE__*/_interopDefault(useSWRMutation6);
|
|
19
19
|
|
|
20
20
|
// src/provider/context.ts
|
|
21
21
|
var ShopifyContext = react.createContext(null);
|
|
@@ -796,7 +796,7 @@ function useRemoveCartLines(options) {
|
|
|
796
796
|
},
|
|
797
797
|
[client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
|
|
798
798
|
);
|
|
799
|
-
return
|
|
799
|
+
return useSWRMutation6__default.default("remove-cart-lines", removeLines, options);
|
|
800
800
|
}
|
|
801
801
|
|
|
802
802
|
// src/hooks/cart/feature/use-auto-remove-free-gifts.ts
|
|
@@ -804,9 +804,13 @@ function useAutoRemoveFreeGifts(options = {}) {
|
|
|
804
804
|
const {
|
|
805
805
|
removeFunctionGifts = true,
|
|
806
806
|
removeScriptGifts = true,
|
|
807
|
-
isGiftLineItem
|
|
807
|
+
isGiftLineItem,
|
|
808
|
+
runOnlyOnceAfterInit = false,
|
|
809
|
+
initDelay = 500
|
|
808
810
|
} = options;
|
|
809
811
|
const [isRemoving, setIsRemoving] = react.useState(false);
|
|
812
|
+
const [isInitialized, setIsInitialized] = react.useState(!runOnlyOnceAfterInit);
|
|
813
|
+
const [isFinished, setIsFinished] = react.useState(false);
|
|
810
814
|
const { cart } = useCartContext();
|
|
811
815
|
const { trigger: removeCartLines2 } = useRemoveCartLines();
|
|
812
816
|
const giftsToRemove = react.useMemo(() => {
|
|
@@ -843,7 +847,29 @@ function useAutoRemoveFreeGifts(options = {}) {
|
|
|
843
847
|
return false;
|
|
844
848
|
});
|
|
845
849
|
}, [cart, removeFunctionGifts, removeScriptGifts, isGiftLineItem]);
|
|
850
|
+
ahooks.useDebounceEffect(
|
|
851
|
+
() => {
|
|
852
|
+
if (!runOnlyOnceAfterInit || isInitialized || isFinished) {
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
if (!cart?.lineItems?.length) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
setIsInitialized(true);
|
|
859
|
+
if (giftsToRemove.length === 0) {
|
|
860
|
+
setIsFinished(true);
|
|
861
|
+
}
|
|
862
|
+
},
|
|
863
|
+
[runOnlyOnceAfterInit, isInitialized, isFinished, cart?.lineItems, giftsToRemove.length],
|
|
864
|
+
{
|
|
865
|
+
trailing: true,
|
|
866
|
+
wait: initDelay
|
|
867
|
+
}
|
|
868
|
+
);
|
|
846
869
|
react.useEffect(() => {
|
|
870
|
+
if (runOnlyOnceAfterInit && (!isInitialized || isFinished)) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
847
873
|
if (isRemoving || giftsToRemove.length === 0) {
|
|
848
874
|
return;
|
|
849
875
|
}
|
|
@@ -857,10 +883,16 @@ function useAutoRemoveFreeGifts(options = {}) {
|
|
|
857
883
|
console.error("Failed to remove free gifts:", error);
|
|
858
884
|
} finally {
|
|
859
885
|
setIsRemoving(false);
|
|
886
|
+
if (runOnlyOnceAfterInit) {
|
|
887
|
+
setIsFinished(true);
|
|
888
|
+
}
|
|
860
889
|
}
|
|
861
890
|
};
|
|
862
891
|
performRemoval();
|
|
863
892
|
}, [
|
|
893
|
+
runOnlyOnceAfterInit,
|
|
894
|
+
isInitialized,
|
|
895
|
+
isFinished,
|
|
864
896
|
isRemoving,
|
|
865
897
|
giftsToRemove,
|
|
866
898
|
removeCartLines2
|
|
@@ -1285,7 +1317,7 @@ function useUpdateCartAttributes({
|
|
|
1285
1317
|
},
|
|
1286
1318
|
[client, locale, cartCookieAdapter, mutate, metafieldIdentifiers, disabled]
|
|
1287
1319
|
);
|
|
1288
|
-
return
|
|
1320
|
+
return useSWRMutation6__default.default("update-cart-attributes", updateAttributes, swrOptions);
|
|
1289
1321
|
}
|
|
1290
1322
|
var CartContext = react.createContext(null);
|
|
1291
1323
|
function AutoRemoveGiftsHandler({
|
|
@@ -1485,7 +1517,9 @@ function CartProvider({
|
|
|
1485
1517
|
const autoRemoveFreeGiftsOptions = react.useMemo(() => {
|
|
1486
1518
|
return {
|
|
1487
1519
|
removeFunctionGifts: !!functionAutoFreeGiftConfig,
|
|
1488
|
-
removeScriptGifts: !!scriptAutoFreeGiftConfig
|
|
1520
|
+
removeScriptGifts: !!scriptAutoFreeGiftConfig,
|
|
1521
|
+
runOnlyOnceAfterInit: true,
|
|
1522
|
+
initDelay: 500
|
|
1489
1523
|
};
|
|
1490
1524
|
}, [functionAutoFreeGiftConfig, scriptAutoFreeGiftConfig]);
|
|
1491
1525
|
const value = react.useMemo(
|