@anker-in/shopify-react 0.1.1-beta.48 → 0.1.1-beta.49
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 -5
- package/dist/hooks/index.d.ts +2 -5
- package/dist/hooks/index.js +0 -9
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +1 -9
- 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 +32 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -39
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +0 -2
- package/dist/provider/index.d.ts +0 -2
- package/dist/provider/index.js +32 -38
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +32 -38
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -270,14 +270,6 @@ var getDiscountEnvAttributeValue = (attributes = []) => {
|
|
|
270
270
|
const attr = attributes.find((attr2) => attr2.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
271
271
|
return safeParse(attr?.value ?? "") ?? {};
|
|
272
272
|
};
|
|
273
|
-
var checkAttributesUpdateNeeded = (oldAttributes, newAttributes, customAttributesNeedRemove) => {
|
|
274
|
-
return oldAttributes.some((attr) => {
|
|
275
|
-
const newAttr = newAttributes.find((newAttr2) => newAttr2.key === attr.key);
|
|
276
|
-
return newAttr ? newAttr.value !== attr.value : true;
|
|
277
|
-
}) || newAttributes.some((attr) => !oldAttributes.some((oldAttr) => oldAttr.key === attr.key)) || customAttributesNeedRemove.some(
|
|
278
|
-
(removeAttr) => oldAttributes.some((oldAttr) => oldAttr.key === removeAttr.key)
|
|
279
|
-
);
|
|
280
|
-
};
|
|
281
273
|
var containsAll = (source, requiredItems = []) => {
|
|
282
274
|
if (!requiredItems?.length) return true;
|
|
283
275
|
const sourceSet = new Set(source);
|
|
@@ -761,6 +753,16 @@ var useScriptAutoFreeGift = ({
|
|
|
761
753
|
giftProductsResult: finalGiftProductsResult
|
|
762
754
|
};
|
|
763
755
|
};
|
|
756
|
+
|
|
757
|
+
// src/hooks/cart/utils/cart-attributes.ts
|
|
758
|
+
var checkAttributesUpdateNeeded = (oldAttributes, newAttributes, customAttributesNeedRemove) => {
|
|
759
|
+
return newAttributes.some((attr) => !oldAttributes.some((oldAttr) => oldAttr.key === attr.key)) || oldAttributes.some((attr) => {
|
|
760
|
+
const newAttr = newAttributes.find((newAttr2) => newAttr2.key === attr.key);
|
|
761
|
+
return newAttr ? newAttr.value !== attr.value : true;
|
|
762
|
+
}) || customAttributesNeedRemove.some(
|
|
763
|
+
(removeAttr) => oldAttributes.some((oldAttr) => oldAttr.key === removeAttr.key)
|
|
764
|
+
);
|
|
765
|
+
};
|
|
764
766
|
function useCreateCart({
|
|
765
767
|
updateCookie = false,
|
|
766
768
|
options
|
|
@@ -3218,7 +3220,7 @@ function CartProvider({
|
|
|
3218
3220
|
}) {
|
|
3219
3221
|
const { client, cartCookieAdapter } = useShopify();
|
|
3220
3222
|
const [customAttributes, setCustomAttributes] = useState([]);
|
|
3221
|
-
const [
|
|
3223
|
+
const [customAttributesNeedRemove, setCustomAttributesNeedRemove] = useState(
|
|
3222
3224
|
[]
|
|
3223
3225
|
);
|
|
3224
3226
|
const [isCodeChanging, setIsCodeChanging] = useState(false);
|
|
@@ -3251,12 +3253,11 @@ function CartProvider({
|
|
|
3251
3253
|
metafieldIdentifiers,
|
|
3252
3254
|
disabled: isCartLoading
|
|
3253
3255
|
});
|
|
3254
|
-
console.log("isCartLoading", isCartLoading);
|
|
3255
3256
|
const { hasPlusMember } = useHasPlusMemberInCart({
|
|
3256
3257
|
memberSetting,
|
|
3257
3258
|
cart
|
|
3258
3259
|
});
|
|
3259
|
-
const { attributes } = useCartAttributes({
|
|
3260
|
+
const { attributes: commonAttributes } = useCartAttributes({
|
|
3260
3261
|
profile,
|
|
3261
3262
|
customer,
|
|
3262
3263
|
cart,
|
|
@@ -3264,16 +3265,17 @@ function CartProvider({
|
|
|
3264
3265
|
});
|
|
3265
3266
|
useRequest(
|
|
3266
3267
|
() => {
|
|
3267
|
-
const
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3268
|
+
const filteredSameCommonAttributes = commonAttributes.filter(
|
|
3269
|
+
(attr) => !customAttributes.some((a) => a.key === attr.key)
|
|
3270
|
+
);
|
|
3271
|
+
const newAttributes = [
|
|
3272
|
+
...filteredSameCommonAttributes,
|
|
3273
|
+
...customAttributes
|
|
3274
|
+
];
|
|
3273
3275
|
const needUpdate = cart && checkAttributesUpdateNeeded(
|
|
3274
3276
|
cart.customAttributes,
|
|
3275
3277
|
newAttributes,
|
|
3276
|
-
|
|
3278
|
+
customAttributesNeedRemove
|
|
3277
3279
|
);
|
|
3278
3280
|
if (needUpdate) {
|
|
3279
3281
|
return updateAttributes({ attributes: newAttributes });
|
|
@@ -3286,7 +3288,7 @@ function CartProvider({
|
|
|
3286
3288
|
// 1 秒内只触发最后一次更新
|
|
3287
3289
|
throttleTrailing: true,
|
|
3288
3290
|
throttleLeading: false,
|
|
3289
|
-
refreshDeps: [
|
|
3291
|
+
refreshDeps: [commonAttributes, customAttributes, customAttributesNeedRemove]
|
|
3290
3292
|
}
|
|
3291
3293
|
);
|
|
3292
3294
|
useUpdateLineCodeAmountAttributes({
|
|
@@ -3297,28 +3299,21 @@ function CartProvider({
|
|
|
3297
3299
|
metafieldIdentifiers
|
|
3298
3300
|
});
|
|
3299
3301
|
const removeCustomAttributes = useCallback(
|
|
3300
|
-
(
|
|
3301
|
-
|
|
3302
|
+
(attributes) => {
|
|
3303
|
+
setCustomAttributesNeedRemove(attributes);
|
|
3302
3304
|
},
|
|
3303
|
-
[
|
|
3305
|
+
[setCustomAttributesNeedRemove]
|
|
3304
3306
|
);
|
|
3305
3307
|
const addCustomAttributes = useCallback(
|
|
3306
|
-
(
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
(attr) => !sameAttributes.some((a) => a.key === attr.key)
|
|
3314
|
-
);
|
|
3315
|
-
return [...removedAttributes, ...attributes2];
|
|
3316
|
-
});
|
|
3317
|
-
} else {
|
|
3318
|
-
setCustomAttributes((prev) => [...prev, ...attributes2]);
|
|
3319
|
-
}
|
|
3308
|
+
(attributes) => {
|
|
3309
|
+
setCustomAttributes((oldCustomAttributes) => {
|
|
3310
|
+
const filteredSameAttributes = oldCustomAttributes.filter(
|
|
3311
|
+
(attr) => !attributes.some((a) => a.key === attr.key)
|
|
3312
|
+
);
|
|
3313
|
+
return [...filteredSameAttributes, ...attributes];
|
|
3314
|
+
});
|
|
3320
3315
|
},
|
|
3321
|
-
[
|
|
3316
|
+
[setCustomAttributes]
|
|
3322
3317
|
);
|
|
3323
3318
|
const functionAutoFreeGiftResult = useCalcAutoFreeGift(cart, autoFreeGiftConfig || [], customer);
|
|
3324
3319
|
const scriptAutoFreeGiftResult = useScriptAutoFreeGift({
|
|
@@ -3390,7 +3385,6 @@ function CartProvider({
|
|
|
3390
3385
|
mutateCart,
|
|
3391
3386
|
addCustomAttributes,
|
|
3392
3387
|
removeCustomAttributes,
|
|
3393
|
-
setCustomAttributes,
|
|
3394
3388
|
locale,
|
|
3395
3389
|
profile,
|
|
3396
3390
|
customer,
|
|
@@ -3450,6 +3444,6 @@ function useCartContext(options) {
|
|
|
3450
3444
|
return context;
|
|
3451
3445
|
}
|
|
3452
3446
|
|
|
3453
|
-
export { BrowserPerformanceAdapter, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, CartProvider, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, ShopifyContext, ShopifyProvider, SpendMoneyType, browserCartCookieAdapter, browserCookieAdapter,
|
|
3447
|
+
export { BrowserPerformanceAdapter, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, CartProvider, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, ShopifyContext, ShopifyProvider, SpendMoneyType, browserCartCookieAdapter, browserCookieAdapter, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, gaTrack, getCachedGeoLocation, getCartAttributes, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, trackAddToCartFBQ, trackAddToCartGA, trackBeginCheckoutGA, trackBuyNowFBQ, trackBuyNowGA, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartContext, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useShopify, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3454
3448
|
//# sourceMappingURL=index.mjs.map
|
|
3455
3449
|
//# sourceMappingURL=index.mjs.map
|