@atomic-solutions/woocommerce-react 0.6.1 → 0.6.2
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.cjs +18 -40
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.js +18 -40
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +78 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +78 -98
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/hooks/index.js
CHANGED
|
@@ -751,6 +751,18 @@ function getAllImageUrls(images, size = "full") {
|
|
|
751
751
|
}
|
|
752
752
|
return images.map((img) => getSizedImageUrl(img.src, size));
|
|
753
753
|
}
|
|
754
|
+
var useProcessedImageUrl = (imageSize, fallbackOverride) => {
|
|
755
|
+
const config = useContext(WooCommerceStoreContext)?.config;
|
|
756
|
+
const transformer = config?.imageUrlTransformer;
|
|
757
|
+
const fallbackImageUrl = fallbackOverride ?? config?.fallbackImageUrl;
|
|
758
|
+
return useCallback(
|
|
759
|
+
(images) => {
|
|
760
|
+
const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
|
|
761
|
+
return baseUrl && transformer ? transformer(baseUrl, imageSize) : baseUrl;
|
|
762
|
+
},
|
|
763
|
+
[imageSize, fallbackImageUrl, transformer]
|
|
764
|
+
);
|
|
765
|
+
};
|
|
754
766
|
|
|
755
767
|
// src/hooks/useProductsFeed.ts
|
|
756
768
|
function useProductsFeed(options = {}) {
|
|
@@ -758,8 +770,6 @@ function useProductsFeed(options = {}) {
|
|
|
758
770
|
const storeContext = useContext(WooCommerceStoreContext);
|
|
759
771
|
const storeConfig = storeContext?.config;
|
|
760
772
|
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
761
|
-
const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
|
|
762
|
-
const imageUrlTransformer = storeConfig?.imageUrlTransformer;
|
|
763
773
|
const {
|
|
764
774
|
data: productsData,
|
|
765
775
|
isLoading,
|
|
@@ -771,16 +781,7 @@ function useProductsFeed(options = {}) {
|
|
|
771
781
|
isRefetching
|
|
772
782
|
} = useInfiniteProducts(params);
|
|
773
783
|
const { treeData: categoryTree = [], findById } = useProductCategoryTree();
|
|
774
|
-
const getProcessedImageUrl =
|
|
775
|
-
(images) => {
|
|
776
|
-
const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
|
|
777
|
-
if (baseUrl && imageUrlTransformer) {
|
|
778
|
-
return imageUrlTransformer(baseUrl, imageSize);
|
|
779
|
-
}
|
|
780
|
-
return baseUrl;
|
|
781
|
-
},
|
|
782
|
-
[imageSize, fallbackImageUrl, imageUrlTransformer]
|
|
783
|
-
);
|
|
784
|
+
const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
|
|
784
785
|
const products = useMemo(() => {
|
|
785
786
|
if (!productsData) return [];
|
|
786
787
|
const productList = Array.isArray(productsData) ? productsData : [];
|
|
@@ -832,7 +833,6 @@ function useProductView(options) {
|
|
|
832
833
|
const storeContext = useContext(WooCommerceStoreContext);
|
|
833
834
|
const storeConfig = storeContext?.config;
|
|
834
835
|
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
835
|
-
const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
|
|
836
836
|
const imageUrlTransformer = storeConfig?.imageUrlTransformer;
|
|
837
837
|
const [draftQuantity, setDraftQuantity] = useState(1);
|
|
838
838
|
const { data: productData, isLoading, error, refetch } = useProduct(productId);
|
|
@@ -840,6 +840,7 @@ function useProductView(options) {
|
|
|
840
840
|
const addToCartMutation = useAddToCart();
|
|
841
841
|
const removeFromCartMutation = useRemoveFromCart();
|
|
842
842
|
const updateCartMutation = useUpdateCartItem();
|
|
843
|
+
const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
|
|
843
844
|
const processImageUrl = useCallback(
|
|
844
845
|
(url) => {
|
|
845
846
|
if (!url) return url;
|
|
@@ -855,7 +856,6 @@ function useProductView(options) {
|
|
|
855
856
|
const currencyCode = productData.prices?.currency_code;
|
|
856
857
|
const stockStatus = productData.is_on_backorder ? "onbackorder" : productData.is_in_stock ? "instock" : "outofstock";
|
|
857
858
|
const lowStockRemaining = productData.low_stock_remaining;
|
|
858
|
-
const baseImageUrl = getImageUrl(productData.images, imageSize, fallbackImageUrl);
|
|
859
859
|
const baseImageUrls = getAllImageUrls(productData.images, imageSize);
|
|
860
860
|
return {
|
|
861
861
|
id: productData.id,
|
|
@@ -865,7 +865,7 @@ function useProductView(options) {
|
|
|
865
865
|
description: productData.description,
|
|
866
866
|
shortDescription: productData.short_description,
|
|
867
867
|
sku: productData.sku,
|
|
868
|
-
imageUrl:
|
|
868
|
+
imageUrl: getProcessedImageUrl(productData.images),
|
|
869
869
|
imageUrls: baseImageUrls.map((url) => processImageUrl(url) ?? url),
|
|
870
870
|
price: formatStoreApiPriceIntl(productData.prices?.price, currencyCode, localeTag),
|
|
871
871
|
regularPrice: formatStoreApiPriceIntl(
|
|
@@ -895,7 +895,7 @@ function useProductView(options) {
|
|
|
895
895
|
minQuantity: productData.add_to_cart?.minimum ?? 1,
|
|
896
896
|
raw: productData
|
|
897
897
|
};
|
|
898
|
-
}, [productData, localeTag,
|
|
898
|
+
}, [productData, localeTag, imageSize, lowStockThreshold, getProcessedImageUrl, processImageUrl]);
|
|
899
899
|
const cartItem = useMemo(() => {
|
|
900
900
|
return cartData?.items.find((item) => item.id === productId);
|
|
901
901
|
}, [cartData?.items, productId]);
|
|
@@ -978,24 +978,13 @@ function useCartView(options = {}) {
|
|
|
978
978
|
const storeContext = useContext(WooCommerceStoreContext);
|
|
979
979
|
const storeConfig = storeContext?.config;
|
|
980
980
|
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
981
|
-
const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
|
|
982
|
-
const imageUrlTransformer = storeConfig?.imageUrlTransformer;
|
|
983
981
|
const { data: cartData, isLoading, error, refetch } = useCart();
|
|
984
982
|
const updateItemMutation = useUpdateCartItem();
|
|
985
983
|
const removeItemMutation = useRemoveFromCart();
|
|
986
984
|
const applyCouponMutation = useApplyCoupon();
|
|
987
985
|
const removeCouponMutation = useRemoveCoupon();
|
|
988
986
|
const selectShippingMutation = useSelectShippingRate();
|
|
989
|
-
const getProcessedImageUrl =
|
|
990
|
-
(images) => {
|
|
991
|
-
const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
|
|
992
|
-
if (baseUrl && imageUrlTransformer) {
|
|
993
|
-
return imageUrlTransformer(baseUrl, imageSize);
|
|
994
|
-
}
|
|
995
|
-
return baseUrl;
|
|
996
|
-
},
|
|
997
|
-
[imageSize, fallbackImageUrl, imageUrlTransformer]
|
|
998
|
-
);
|
|
987
|
+
const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
|
|
999
988
|
const items = useMemo(() => {
|
|
1000
989
|
if (!cartData?.items) return [];
|
|
1001
990
|
const currencyCode = cartData.totals.currency_code;
|
|
@@ -1141,8 +1130,6 @@ function useReorderView(items, options = {}) {
|
|
|
1141
1130
|
const storeContext = useContext(WooCommerceStoreContext);
|
|
1142
1131
|
const storeConfig = storeContext?.config;
|
|
1143
1132
|
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
1144
|
-
const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
|
|
1145
|
-
const imageUrlTransformer = storeConfig?.imageUrlTransformer;
|
|
1146
1133
|
const productIds = useMemo(() => [...new Set(items.map((item) => item.productId))], [items]);
|
|
1147
1134
|
const {
|
|
1148
1135
|
data: productsPage,
|
|
@@ -1153,16 +1140,7 @@ function useReorderView(items, options = {}) {
|
|
|
1153
1140
|
{ enabled: productIds.length > 0 }
|
|
1154
1141
|
);
|
|
1155
1142
|
const { data: cart } = useCart();
|
|
1156
|
-
const getProcessedImageUrl =
|
|
1157
|
-
(images) => {
|
|
1158
|
-
const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
|
|
1159
|
-
if (baseUrl && imageUrlTransformer) {
|
|
1160
|
-
return imageUrlTransformer(baseUrl, imageSize);
|
|
1161
|
-
}
|
|
1162
|
-
return baseUrl;
|
|
1163
|
-
},
|
|
1164
|
-
[imageSize, fallbackImageUrl, imageUrlTransformer]
|
|
1165
|
-
);
|
|
1143
|
+
const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
|
|
1166
1144
|
const views = useMemo(() => {
|
|
1167
1145
|
const products = new Map((productsPage?.data ?? []).map((product) => [product.id, product]));
|
|
1168
1146
|
return items.map((item) => {
|