@atomic-solutions/woocommerce-react 0.6.1 → 0.7.0
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 +38 -43
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +38 -44
- package/dist/hooks/index.js.map +1 -1
- package/dist/{index-Dmlapl9c.d.ts → index-BmWcF7aq.d.ts} +12 -5
- package/dist/{index-DEvJWFSF.d.cts → index-UkshfFwm.d.cts} +12 -5
- package/dist/index.cjs +98 -101
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +98 -102
- package/dist/index.js.map +1 -1
- package/dist/provider/index.d.cts +2 -2
- package/dist/provider/index.d.ts +2 -2
- package/dist/{types-Dnq60zh-.d.cts → types-4MW3Y__g.d.cts} +2 -1
- package/dist/{types-Dnq60zh-.d.ts → types-4MW3Y__g.d.ts} +2 -1
- package/package.json +2 -2
package/dist/hooks/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AppliedCoupon, C as CartTotals,
|
|
2
|
-
export { Q as QueryKeys, p as createQueryKeys } from '../types-
|
|
1
|
+
export { A as AppliedCoupon, C as CartTotals, ak as InfiniteQueryOptions, al as MutationOptions, a as PaymentMethod, b as ProcessedCartItem, c as ProcessedCategory, d as ProcessedOrderDetails, e as ProcessedOrderLineItem, f as ProcessedProduct, g as ProcessedProductDetails, h as ProductCartState, i as ProductCategoryTreeNode, am as QueryOptions, R as ReorderInputItem, j as ReorderItemView, k as ReorderUnavailableReason, S as ShippingRate, n as UseCartViewOptions, o as UseCartViewReturn, p as UseOrderViewOptions, q as UseOrderViewReturn, r as UseProductViewOptions, s as UseProductViewReturn, t as UseProductsFeedOptions, u as UseProductsFeedReturn, v as UseReorderViewOptions, w as UseReorderViewReturn, E as getOrderStatusLabel, Q as useAddManyToCart, T as useAddToCart, V as useApplyCoupon, W as useCart, X as useCartView, Y as useCheckout, Z as useInfiniteProducts, _ as useOrder, $ as useOrderView, a0 as useProcessCheckout, a1 as useProduct, a2 as useProductCategories, a3 as useProductCategoryTree, a4 as useProductTags, a5 as useProductView, a6 as useProducts, a7 as useProductsFeed, a8 as useRemoveCoupon, a9 as useRemoveFromCart, aa as useReorderView, ab as useSelectShippingRate, ac as useStore, ad as useStoreFeatures, ae as useStoreLocale, af as useStoreTheme, ag as useUpdateCartItem, ah as useUpdateCustomer, ai as useWooCommerceClient, aj as useWooCommerceQueryKeys } from '../index-UkshfFwm.cjs';
|
|
2
|
+
export { Q as QueryKeys, p as createQueryKeys } from '../types-4MW3Y__g.cjs';
|
|
3
3
|
export { OrderStatus } from '@atomic-solutions/woocommerce-api-client';
|
|
4
4
|
import '@tanstack/react-query';
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AppliedCoupon, C as CartTotals,
|
|
2
|
-
export { Q as QueryKeys, p as createQueryKeys } from '../types-
|
|
1
|
+
export { A as AppliedCoupon, C as CartTotals, ak as InfiniteQueryOptions, al as MutationOptions, a as PaymentMethod, b as ProcessedCartItem, c as ProcessedCategory, d as ProcessedOrderDetails, e as ProcessedOrderLineItem, f as ProcessedProduct, g as ProcessedProductDetails, h as ProductCartState, i as ProductCategoryTreeNode, am as QueryOptions, R as ReorderInputItem, j as ReorderItemView, k as ReorderUnavailableReason, S as ShippingRate, n as UseCartViewOptions, o as UseCartViewReturn, p as UseOrderViewOptions, q as UseOrderViewReturn, r as UseProductViewOptions, s as UseProductViewReturn, t as UseProductsFeedOptions, u as UseProductsFeedReturn, v as UseReorderViewOptions, w as UseReorderViewReturn, E as getOrderStatusLabel, Q as useAddManyToCart, T as useAddToCart, V as useApplyCoupon, W as useCart, X as useCartView, Y as useCheckout, Z as useInfiniteProducts, _ as useOrder, $ as useOrderView, a0 as useProcessCheckout, a1 as useProduct, a2 as useProductCategories, a3 as useProductCategoryTree, a4 as useProductTags, a5 as useProductView, a6 as useProducts, a7 as useProductsFeed, a8 as useRemoveCoupon, a9 as useRemoveFromCart, aa as useReorderView, ab as useSelectShippingRate, ac as useStore, ad as useStoreFeatures, ae as useStoreLocale, af as useStoreTheme, ag as useUpdateCartItem, ah as useUpdateCustomer, ai as useWooCommerceClient, aj as useWooCommerceQueryKeys } from '../index-BmWcF7aq.js';
|
|
2
|
+
export { Q as QueryKeys, p as createQueryKeys } from '../types-4MW3Y__g.js';
|
|
3
3
|
export { OrderStatus } from '@atomic-solutions/woocommerce-api-client';
|
|
4
4
|
import '@tanstack/react-query';
|
package/dist/hooks/index.js
CHANGED
|
@@ -40,6 +40,8 @@ var StaleTimes = {
|
|
|
40
40
|
product: STALE_TIME_SHORT,
|
|
41
41
|
/** Product categories - always fresh */
|
|
42
42
|
categories: STALE_TIME_NONE,
|
|
43
|
+
/** Product tags - names rarely change, 1 hour */
|
|
44
|
+
tags: STALE_TIME_LONG,
|
|
43
45
|
/** Orders - always fresh */
|
|
44
46
|
orders: STALE_TIME_NONE,
|
|
45
47
|
/** Default for infinite queries - 1 hour */
|
|
@@ -137,6 +139,16 @@ var processCategoriesToTree = (data) => {
|
|
|
137
139
|
});
|
|
138
140
|
return rootCategories?.map(processCategory) ?? [];
|
|
139
141
|
};
|
|
142
|
+
var useProductTags = (params, options) => {
|
|
143
|
+
const client = useWooCommerceClient();
|
|
144
|
+
const queryKeys = useWooCommerceQueryKeys();
|
|
145
|
+
return useQuery({
|
|
146
|
+
queryKey: queryKeys.products.tags(params),
|
|
147
|
+
queryFn: () => client.products.tags(params),
|
|
148
|
+
staleTime: StaleTimes.tags,
|
|
149
|
+
...options
|
|
150
|
+
});
|
|
151
|
+
};
|
|
140
152
|
var useProductCategoryTree = () => {
|
|
141
153
|
const query = useProductCategories();
|
|
142
154
|
const flatData = query.data ?? [];
|
|
@@ -461,7 +473,9 @@ var createQueryKeys = (prefix = ["woocommerce"]) => ({
|
|
|
461
473
|
list: (params) => [...prefix, "products", "list", params],
|
|
462
474
|
details: () => [...prefix, "products", "detail"],
|
|
463
475
|
detail: (id) => [...prefix, "products", "detail", id],
|
|
464
|
-
categories: () => [...prefix, "products", "categories"]
|
|
476
|
+
categories: () => [...prefix, "products", "categories"],
|
|
477
|
+
// Params are in the key, so each set of tag ids is cached apart.
|
|
478
|
+
tags: (params) => [...prefix, "products", "tags", params]
|
|
465
479
|
},
|
|
466
480
|
// Cart
|
|
467
481
|
cart: {
|
|
@@ -751,6 +765,18 @@ function getAllImageUrls(images, size = "full") {
|
|
|
751
765
|
}
|
|
752
766
|
return images.map((img) => getSizedImageUrl(img.src, size));
|
|
753
767
|
}
|
|
768
|
+
var useProcessedImageUrl = (imageSize, fallbackOverride) => {
|
|
769
|
+
const config = useContext(WooCommerceStoreContext)?.config;
|
|
770
|
+
const transformer = config?.imageUrlTransformer;
|
|
771
|
+
const fallbackImageUrl = fallbackOverride ?? config?.fallbackImageUrl;
|
|
772
|
+
return useCallback(
|
|
773
|
+
(images) => {
|
|
774
|
+
const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
|
|
775
|
+
return baseUrl && transformer ? transformer(baseUrl, imageSize) : baseUrl;
|
|
776
|
+
},
|
|
777
|
+
[imageSize, fallbackImageUrl, transformer]
|
|
778
|
+
);
|
|
779
|
+
};
|
|
754
780
|
|
|
755
781
|
// src/hooks/useProductsFeed.ts
|
|
756
782
|
function useProductsFeed(options = {}) {
|
|
@@ -758,8 +784,6 @@ function useProductsFeed(options = {}) {
|
|
|
758
784
|
const storeContext = useContext(WooCommerceStoreContext);
|
|
759
785
|
const storeConfig = storeContext?.config;
|
|
760
786
|
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
787
|
const {
|
|
764
788
|
data: productsData,
|
|
765
789
|
isLoading,
|
|
@@ -771,16 +795,7 @@ function useProductsFeed(options = {}) {
|
|
|
771
795
|
isRefetching
|
|
772
796
|
} = useInfiniteProducts(params);
|
|
773
797
|
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
|
-
);
|
|
798
|
+
const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
|
|
784
799
|
const products = useMemo(() => {
|
|
785
800
|
if (!productsData) return [];
|
|
786
801
|
const productList = Array.isArray(productsData) ? productsData : [];
|
|
@@ -832,7 +847,6 @@ function useProductView(options) {
|
|
|
832
847
|
const storeContext = useContext(WooCommerceStoreContext);
|
|
833
848
|
const storeConfig = storeContext?.config;
|
|
834
849
|
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
835
|
-
const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
|
|
836
850
|
const imageUrlTransformer = storeConfig?.imageUrlTransformer;
|
|
837
851
|
const [draftQuantity, setDraftQuantity] = useState(1);
|
|
838
852
|
const { data: productData, isLoading, error, refetch } = useProduct(productId);
|
|
@@ -840,6 +854,7 @@ function useProductView(options) {
|
|
|
840
854
|
const addToCartMutation = useAddToCart();
|
|
841
855
|
const removeFromCartMutation = useRemoveFromCart();
|
|
842
856
|
const updateCartMutation = useUpdateCartItem();
|
|
857
|
+
const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
|
|
843
858
|
const processImageUrl = useCallback(
|
|
844
859
|
(url) => {
|
|
845
860
|
if (!url) return url;
|
|
@@ -855,7 +870,6 @@ function useProductView(options) {
|
|
|
855
870
|
const currencyCode = productData.prices?.currency_code;
|
|
856
871
|
const stockStatus = productData.is_on_backorder ? "onbackorder" : productData.is_in_stock ? "instock" : "outofstock";
|
|
857
872
|
const lowStockRemaining = productData.low_stock_remaining;
|
|
858
|
-
const baseImageUrl = getImageUrl(productData.images, imageSize, fallbackImageUrl);
|
|
859
873
|
const baseImageUrls = getAllImageUrls(productData.images, imageSize);
|
|
860
874
|
return {
|
|
861
875
|
id: productData.id,
|
|
@@ -865,7 +879,7 @@ function useProductView(options) {
|
|
|
865
879
|
description: productData.description,
|
|
866
880
|
shortDescription: productData.short_description,
|
|
867
881
|
sku: productData.sku,
|
|
868
|
-
imageUrl:
|
|
882
|
+
imageUrl: getProcessedImageUrl(productData.images),
|
|
869
883
|
imageUrls: baseImageUrls.map((url) => processImageUrl(url) ?? url),
|
|
870
884
|
price: formatStoreApiPriceIntl(productData.prices?.price, currencyCode, localeTag),
|
|
871
885
|
regularPrice: formatStoreApiPriceIntl(
|
|
@@ -895,7 +909,7 @@ function useProductView(options) {
|
|
|
895
909
|
minQuantity: productData.add_to_cart?.minimum ?? 1,
|
|
896
910
|
raw: productData
|
|
897
911
|
};
|
|
898
|
-
}, [productData, localeTag,
|
|
912
|
+
}, [productData, localeTag, imageSize, lowStockThreshold, getProcessedImageUrl, processImageUrl]);
|
|
899
913
|
const cartItem = useMemo(() => {
|
|
900
914
|
return cartData?.items.find((item) => item.id === productId);
|
|
901
915
|
}, [cartData?.items, productId]);
|
|
@@ -978,24 +992,13 @@ function useCartView(options = {}) {
|
|
|
978
992
|
const storeContext = useContext(WooCommerceStoreContext);
|
|
979
993
|
const storeConfig = storeContext?.config;
|
|
980
994
|
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
995
|
const { data: cartData, isLoading, error, refetch } = useCart();
|
|
984
996
|
const updateItemMutation = useUpdateCartItem();
|
|
985
997
|
const removeItemMutation = useRemoveFromCart();
|
|
986
998
|
const applyCouponMutation = useApplyCoupon();
|
|
987
999
|
const removeCouponMutation = useRemoveCoupon();
|
|
988
1000
|
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
|
-
);
|
|
1001
|
+
const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
|
|
999
1002
|
const items = useMemo(() => {
|
|
1000
1003
|
if (!cartData?.items) return [];
|
|
1001
1004
|
const currencyCode = cartData.totals.currency_code;
|
|
@@ -1141,8 +1144,6 @@ function useReorderView(items, options = {}) {
|
|
|
1141
1144
|
const storeContext = useContext(WooCommerceStoreContext);
|
|
1142
1145
|
const storeConfig = storeContext?.config;
|
|
1143
1146
|
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
1147
|
const productIds = useMemo(() => [...new Set(items.map((item) => item.productId))], [items]);
|
|
1147
1148
|
const {
|
|
1148
1149
|
data: productsPage,
|
|
@@ -1153,16 +1154,7 @@ function useReorderView(items, options = {}) {
|
|
|
1153
1154
|
{ enabled: productIds.length > 0 }
|
|
1154
1155
|
);
|
|
1155
1156
|
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
|
-
);
|
|
1157
|
+
const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
|
|
1166
1158
|
const views = useMemo(() => {
|
|
1167
1159
|
const products = new Map((productsPage?.data ?? []).map((product) => [product.id, product]));
|
|
1168
1160
|
return items.map((item) => {
|
|
@@ -1244,6 +1236,8 @@ function useOrderView(input, options = {}) {
|
|
|
1244
1236
|
const storeContext = useContext(WooCommerceStoreContext);
|
|
1245
1237
|
const storeConfig = storeContext?.config;
|
|
1246
1238
|
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
1239
|
+
const { imageSize = "thumbnail" } = options;
|
|
1240
|
+
const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
|
|
1247
1241
|
const { data: rawOrder, isLoading, error } = useOrder(input);
|
|
1248
1242
|
const order = useMemo(() => {
|
|
1249
1243
|
if (!rawOrder) return void 0;
|
|
@@ -1254,7 +1248,7 @@ function useOrderView(input, options = {}) {
|
|
|
1254
1248
|
quantity: item.quantity,
|
|
1255
1249
|
price: formatStoreApiPriceIntl(item.prices.price, currencyCode, localeTag),
|
|
1256
1250
|
total: formatStoreApiPriceIntl(item.totals.line_total, currencyCode, localeTag),
|
|
1257
|
-
imageUrl: item.images
|
|
1251
|
+
imageUrl: getProcessedImageUrl(item.images)
|
|
1258
1252
|
}));
|
|
1259
1253
|
const status = rawOrder.status;
|
|
1260
1254
|
return {
|
|
@@ -1269,7 +1263,7 @@ function useOrderView(input, options = {}) {
|
|
|
1269
1263
|
paymentMethod: rawOrder.payment_method ?? "",
|
|
1270
1264
|
raw: rawOrder
|
|
1271
1265
|
};
|
|
1272
|
-
}, [rawOrder, localeTag]);
|
|
1266
|
+
}, [rawOrder, localeTag, getProcessedImageUrl]);
|
|
1273
1267
|
return {
|
|
1274
1268
|
order,
|
|
1275
1269
|
isLoading,
|
|
@@ -1277,6 +1271,6 @@ function useOrderView(input, options = {}) {
|
|
|
1277
1271
|
};
|
|
1278
1272
|
}
|
|
1279
1273
|
|
|
1280
|
-
export { createQueryKeys, getOrderStatusLabel, useAddManyToCart, useAddToCart, useApplyCoupon, useCart, useCartView, useCheckout, useInfiniteProducts, useOrder, useOrderView, useProcessCheckout, useProduct, useProductCategories, useProductCategoryTree, useProductView, useProducts, useProductsFeed, useRemoveCoupon, useRemoveFromCart, useReorderView, useSelectShippingRate, useStore, useStoreFeatures, useStoreLocale, useStoreTheme, useUpdateCartItem, useUpdateCustomer, useWooCommerceClient, useWooCommerceQueryKeys };
|
|
1274
|
+
export { createQueryKeys, getOrderStatusLabel, useAddManyToCart, useAddToCart, useApplyCoupon, useCart, useCartView, useCheckout, useInfiniteProducts, useOrder, useOrderView, useProcessCheckout, useProduct, useProductCategories, useProductCategoryTree, useProductTags, useProductView, useProducts, useProductsFeed, useRemoveCoupon, useRemoveFromCart, useReorderView, useSelectShippingRate, useStore, useStoreFeatures, useStoreLocale, useStoreTheme, useUpdateCartItem, useUpdateCustomer, useWooCommerceClient, useWooCommerceQueryKeys };
|
|
1281
1275
|
//# sourceMappingURL=index.js.map
|
|
1282
1276
|
//# sourceMappingURL=index.js.map
|