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