@wix/headless-stores 0.0.10 → 0.0.11
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/cjs/dist/enums/index.d.ts +2 -0
- package/cjs/dist/enums/index.js +18 -0
- package/cjs/dist/enums/social-platform-enums.d.ts +25 -0
- package/cjs/dist/enums/social-platform-enums.js +30 -0
- package/cjs/dist/enums/sort-enums.d.ts +17 -0
- package/cjs/dist/enums/sort-enums.js +21 -0
- package/cjs/dist/react/BuyNow.d.ts +2 -4
- package/cjs/dist/react/Category.d.ts +9 -11
- package/cjs/dist/react/Category.js +8 -23
- package/cjs/dist/react/Collection.d.ts +13 -3
- package/cjs/dist/react/Collection.js +30 -19
- package/cjs/dist/react/FilteredCollection.d.ts +45 -15
- package/cjs/dist/react/FilteredCollection.js +45 -12
- package/cjs/dist/react/PayNow.d.ts +2 -4
- package/cjs/dist/react/Product.d.ts +8 -35
- package/cjs/dist/react/Product.js +10 -31
- package/cjs/dist/react/ProductActions.d.ts +42 -0
- package/cjs/dist/react/ProductActions.js +83 -0
- package/cjs/dist/react/ProductModifiers.d.ts +16 -8
- package/cjs/dist/react/ProductModifiers.js +19 -10
- package/cjs/dist/react/ProductVariantSelector.d.ts +52 -68
- package/cjs/dist/react/ProductVariantSelector.js +58 -86
- package/cjs/dist/react/RelatedProducts.d.ts +8 -4
- package/cjs/dist/react/RelatedProducts.js +12 -7
- package/cjs/dist/react/SelectedVariant.d.ts +66 -0
- package/cjs/dist/react/SelectedVariant.js +52 -0
- package/cjs/dist/react/SocialSharing.d.ts +24 -31
- package/cjs/dist/react/SocialSharing.js +8 -2
- package/cjs/dist/react/Sort.d.ts +11 -14
- package/cjs/dist/react/Sort.js +10 -34
- package/cjs/dist/react/index.d.ts +11 -10
- package/cjs/dist/react/index.js +3 -2
- package/cjs/dist/services/buy-now-service.js +2 -2
- package/cjs/dist/services/catalog-options-service.d.ts +2 -2
- package/cjs/dist/services/catalog-options-service.js +39 -45
- package/cjs/dist/services/catalog-price-range-service.d.ts +2 -2
- package/cjs/dist/services/catalog-price-range-service.js +13 -11
- package/cjs/dist/services/category-service.d.ts +7 -6
- package/cjs/dist/services/category-service.js +15 -11
- package/cjs/dist/services/collection-service.d.ts +8 -8
- package/cjs/dist/services/collection-service.js +182 -67
- package/cjs/dist/services/filter-service.d.ts +1 -1
- package/cjs/dist/services/filter-service.js +15 -23
- package/cjs/dist/services/product-media-gallery-service.d.ts +3 -3
- package/cjs/dist/services/product-modifiers-service.d.ts +6 -8
- package/cjs/dist/services/product-modifiers-service.js +14 -7
- package/cjs/dist/services/product-service.d.ts +8 -7
- package/cjs/dist/services/product-service.js +36 -19
- package/cjs/dist/services/related-products-service.d.ts +4 -4
- package/cjs/dist/services/related-products-service.js +4 -4
- package/cjs/dist/services/selected-variant-service.d.ts +24 -16
- package/cjs/dist/services/selected-variant-service.js +271 -126
- package/cjs/dist/services/social-sharing-service.d.ts +2 -2
- package/cjs/dist/services/social-sharing-service.js +47 -63
- package/cjs/dist/services/sort-service.d.ts +3 -2
- package/cjs/dist/services/sort-service.js +8 -13
- package/dist/enums/index.d.ts +2 -0
- package/dist/enums/index.js +2 -0
- package/dist/enums/social-platform-enums.d.ts +25 -0
- package/dist/enums/social-platform-enums.js +27 -0
- package/dist/enums/sort-enums.d.ts +17 -0
- package/dist/enums/sort-enums.js +18 -0
- package/dist/react/BuyNow.d.ts +2 -4
- package/dist/react/Category.d.ts +9 -11
- package/dist/react/Category.js +10 -23
- package/dist/react/Collection.d.ts +13 -3
- package/dist/react/Collection.js +32 -21
- package/dist/react/FilteredCollection.d.ts +45 -15
- package/dist/react/FilteredCollection.js +49 -16
- package/dist/react/PayNow.d.ts +2 -4
- package/dist/react/Product.d.ts +8 -35
- package/dist/react/Product.js +11 -31
- package/dist/react/ProductActions.d.ts +42 -0
- package/dist/react/ProductActions.js +79 -0
- package/dist/react/ProductModifiers.d.ts +16 -8
- package/dist/react/ProductModifiers.js +22 -13
- package/dist/react/ProductVariantSelector.d.ts +52 -68
- package/dist/react/ProductVariantSelector.js +57 -84
- package/dist/react/RelatedProducts.d.ts +8 -4
- package/dist/react/RelatedProducts.js +15 -10
- package/dist/react/SelectedVariant.d.ts +66 -0
- package/dist/react/SelectedVariant.js +46 -0
- package/dist/react/SocialSharing.d.ts +24 -31
- package/dist/react/SocialSharing.js +11 -5
- package/dist/react/Sort.d.ts +11 -14
- package/dist/react/Sort.js +12 -34
- package/dist/react/index.d.ts +11 -10
- package/dist/react/index.js +11 -10
- package/dist/services/buy-now-service.js +2 -2
- package/dist/services/catalog-options-service.d.ts +2 -2
- package/dist/services/catalog-options-service.js +41 -47
- package/dist/services/catalog-price-range-service.d.ts +2 -2
- package/dist/services/catalog-price-range-service.js +15 -13
- package/dist/services/category-service.d.ts +7 -6
- package/dist/services/category-service.js +17 -13
- package/dist/services/collection-service.d.ts +8 -8
- package/dist/services/collection-service.js +188 -73
- package/dist/services/filter-service.d.ts +1 -1
- package/dist/services/filter-service.js +20 -28
- package/dist/services/product-media-gallery-service.d.ts +3 -3
- package/dist/services/product-modifiers-service.d.ts +6 -8
- package/dist/services/product-modifiers-service.js +16 -9
- package/dist/services/product-service.d.ts +8 -7
- package/dist/services/product-service.js +38 -21
- package/dist/services/related-products-service.d.ts +4 -4
- package/dist/services/related-products-service.js +6 -6
- package/dist/services/selected-variant-service.d.ts +24 -16
- package/dist/services/selected-variant-service.js +273 -127
- package/dist/services/social-sharing-service.d.ts +2 -2
- package/dist/services/social-sharing-service.js +49 -65
- package/dist/services/sort-service.d.ts +3 -2
- package/dist/services/sort-service.js +11 -16
- package/package.json +7 -1
- package/cjs/dist/react/ProductMediaGallery.d.ts +0 -128
- package/cjs/dist/react/ProductMediaGallery.js +0 -100
- package/dist/astro/BuyNowServiceContext.d.ts +0 -2
- package/dist/astro/BuyNowServiceContext.js +0 -6
- package/dist/astro/ManagerProviderContext.d.ts +0 -2
- package/dist/astro/ManagerProviderContext.js +0 -7
- package/dist/astro/withBuyButtonService.d.ts +0 -2
- package/dist/astro/withBuyButtonService.js +0 -16
- package/dist/react/CurrentCartServiceProvider.d.ts +0 -5
- package/dist/react/CurrentCartServiceProvider.js +0 -12
- package/dist/react/ProductMediaGallery.d.ts +0 -128
- package/dist/react/ProductMediaGallery.js +0 -92
- package/dist/react/VariantSelectorServiceProvider.d.ts +0 -7
- package/dist/react/VariantSelectorServiceProvider.js +0 -22
- package/dist/react/hookim/index.d.ts +0 -5
- package/dist/react/hookim/index.js +0 -22
- package/dist/services/CurrentCartService.d.ts +0 -18
- package/dist/services/CurrentCartService.js +0 -9
- package/dist/services/VariantSelectorServices.d.ts +0 -8
- package/dist/services/VariantSelectorServices.js +0 -20
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type PayNowRedirectToCheckout = () => void;
|
|
2
1
|
/**
|
|
3
2
|
* Props passed to the render function of the PayNow component
|
|
4
3
|
*/
|
|
@@ -6,17 +5,16 @@ export interface PayNowRenderProps {
|
|
|
6
5
|
/** Whether the buy now operation is currently loading */
|
|
7
6
|
isLoading: boolean;
|
|
8
7
|
/** Function to redirect the user to the checkout page */
|
|
9
|
-
redirectToCheckout:
|
|
8
|
+
redirectToCheckout: () => void;
|
|
10
9
|
/** The error message if the buy now operation fails */
|
|
11
10
|
error: string | null;
|
|
12
11
|
}
|
|
13
|
-
export type PayNowChildren = (props: PayNowRenderProps) => React.ReactNode;
|
|
14
12
|
/**
|
|
15
13
|
* Props for the PayNow component
|
|
16
14
|
*/
|
|
17
15
|
export interface PayNowProps {
|
|
18
16
|
/** Render function that receives buy now state and actions */
|
|
19
|
-
children:
|
|
17
|
+
children: (props: PayNowRenderProps) => React.ReactNode;
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
22
20
|
* A headless component that provides pay now functionality using the render props pattern.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { V3Product } from '@wix/auto_sdk_stores_products-v-3';
|
|
1
2
|
/**
|
|
2
3
|
* Props for ProductName headless component
|
|
3
4
|
*/
|
|
@@ -11,11 +12,11 @@ export interface ProductNameProps {
|
|
|
11
12
|
export interface ProductNameRenderProps {
|
|
12
13
|
/** Product name */
|
|
13
14
|
name: string;
|
|
14
|
-
/** Whether product has a name */
|
|
15
|
-
hasName: boolean;
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
17
|
* Headless component for product name display
|
|
18
|
+
*
|
|
19
|
+
* @component
|
|
19
20
|
*/
|
|
20
21
|
export declare const Name: (props: ProductNameProps) => import("react").ReactNode;
|
|
21
22
|
/**
|
|
@@ -30,41 +31,13 @@ export interface ProductDescriptionProps {
|
|
|
30
31
|
*/
|
|
31
32
|
export interface ProductDescriptionRenderProps {
|
|
32
33
|
/** Product description (may contain HTML) */
|
|
33
|
-
description:
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
/** Whether description contains HTML */
|
|
37
|
-
isHtml: boolean;
|
|
34
|
+
description: NonNullable<V3Product['description']>;
|
|
35
|
+
/** Product plain description */
|
|
36
|
+
plainDescription: NonNullable<V3Product['plainDescription']>;
|
|
38
37
|
}
|
|
39
38
|
/**
|
|
40
39
|
* Headless component for product description display
|
|
40
|
+
*
|
|
41
|
+
* @component
|
|
41
42
|
*/
|
|
42
43
|
export declare const Description: (props: ProductDescriptionProps) => import("react").ReactNode;
|
|
43
|
-
/**
|
|
44
|
-
* Props for ProductDetails headless component
|
|
45
|
-
*/
|
|
46
|
-
export interface ProductDetailsProps {
|
|
47
|
-
/** Render prop function that receives product details data */
|
|
48
|
-
children: (props: ProductDetailsRenderProps) => React.ReactNode;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Render props for ProductDetails component
|
|
52
|
-
*/
|
|
53
|
-
export interface ProductDetailsRenderProps {
|
|
54
|
-
/** Product SKU */
|
|
55
|
-
sku: string | null;
|
|
56
|
-
/** Product weight */
|
|
57
|
-
weight: string | null;
|
|
58
|
-
/** Product dimensions (if available) */
|
|
59
|
-
dimensions: string | null;
|
|
60
|
-
/** Whether product has SKU */
|
|
61
|
-
hasSku: boolean;
|
|
62
|
-
/** Whether product has weight */
|
|
63
|
-
hasWeight: boolean;
|
|
64
|
-
/** Whether product has dimensions */
|
|
65
|
-
hasDimensions: boolean;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Headless component for product details display
|
|
69
|
-
*/
|
|
70
|
-
export declare const Details: (props: ProductDetailsProps) => import("react").ReactNode;
|
|
@@ -1,56 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Description = exports.Name = void 0;
|
|
4
4
|
const services_manager_react_1 = require("@wix/services-manager-react");
|
|
5
5
|
const product_service_1 = require("../services/product-service");
|
|
6
|
-
const selected_variant_service_1 = require("../services/selected-variant-service");
|
|
7
6
|
/**
|
|
8
7
|
* Headless component for product name display
|
|
8
|
+
*
|
|
9
|
+
* @component
|
|
9
10
|
*/
|
|
10
11
|
const Name = (props) => {
|
|
11
12
|
const service = (0, services_manager_react_1.useService)(product_service_1.ProductServiceDefinition);
|
|
12
13
|
const product = service.product.get();
|
|
13
|
-
const name = product
|
|
14
|
+
const name = product.name;
|
|
14
15
|
return props.children({
|
|
15
16
|
name,
|
|
16
|
-
hasName: !!name,
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
19
|
exports.Name = Name;
|
|
20
20
|
/**
|
|
21
21
|
* Headless component for product description display
|
|
22
|
+
*
|
|
23
|
+
* @component
|
|
22
24
|
*/
|
|
23
25
|
const Description = (props) => {
|
|
24
26
|
const service = (0, services_manager_react_1.useService)(product_service_1.ProductServiceDefinition);
|
|
25
27
|
const product = service.product.get();
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const description = typeof rawDescription === "string" ? rawDescription : "";
|
|
29
|
-
const hasDescription = !!description;
|
|
30
|
-
const isHtml = description.includes("<") && description.includes(">");
|
|
28
|
+
const descriptionRichContent = product.description;
|
|
29
|
+
const plainDescription = product.plainDescription;
|
|
31
30
|
return props.children({
|
|
32
|
-
description,
|
|
33
|
-
|
|
34
|
-
isHtml,
|
|
31
|
+
description: descriptionRichContent,
|
|
32
|
+
plainDescription: plainDescription,
|
|
35
33
|
});
|
|
36
34
|
};
|
|
37
35
|
exports.Description = Description;
|
|
38
|
-
/**
|
|
39
|
-
* Headless component for product details display
|
|
40
|
-
*/
|
|
41
|
-
const Details = (props) => {
|
|
42
|
-
const selectedVariantService = (0, services_manager_react_1.useService)(selected_variant_service_1.SelectedVariantServiceDefinition);
|
|
43
|
-
const selectedVariant = selectedVariantService.currentVariant?.get();
|
|
44
|
-
let sku = selectedVariant?.sku || null;
|
|
45
|
-
let weight = selectedVariant?.physicalProperties?.weight?.toString() || null;
|
|
46
|
-
let dimensions = null;
|
|
47
|
-
return props.children({
|
|
48
|
-
sku,
|
|
49
|
-
weight,
|
|
50
|
-
dimensions,
|
|
51
|
-
hasSku: !!sku,
|
|
52
|
-
hasWeight: !!weight,
|
|
53
|
-
hasDimensions: false,
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
exports.Details = Details;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Props for Actions headless component
|
|
3
|
+
*/
|
|
4
|
+
export interface ActionsProps {
|
|
5
|
+
/** Quantity to add (optional) */
|
|
6
|
+
quantity?: number;
|
|
7
|
+
/** Render prop function that receives actions data */
|
|
8
|
+
children: (props: ActionsRenderProps) => React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Render props for Actions component
|
|
12
|
+
*/
|
|
13
|
+
export interface ActionsRenderProps {
|
|
14
|
+
/** Function to add product to cart */
|
|
15
|
+
onAddToCart: () => Promise<void>;
|
|
16
|
+
/** Function to buy now (clear cart, add product, proceed to checkout) */
|
|
17
|
+
onBuyNow: () => Promise<void>;
|
|
18
|
+
/** Function to open cart */
|
|
19
|
+
onOpenCart: () => void;
|
|
20
|
+
/** Whether add to cart is available */
|
|
21
|
+
canAddToCart: boolean;
|
|
22
|
+
/** Whether add to cart is currently loading */
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
/** Current variant price */
|
|
25
|
+
price: string;
|
|
26
|
+
/** Whether variant is in stock */
|
|
27
|
+
inStock: boolean;
|
|
28
|
+
/** Whether pre-order is enabled */
|
|
29
|
+
isPreOrderEnabled: boolean;
|
|
30
|
+
/** Pre-order message */
|
|
31
|
+
preOrderMessage: string | null;
|
|
32
|
+
/** Error message if any */
|
|
33
|
+
error: string | null;
|
|
34
|
+
/** Available quantity */
|
|
35
|
+
availableQuantity: number | null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Headless component for product actions (add to cart, buy now)
|
|
39
|
+
*
|
|
40
|
+
* @component
|
|
41
|
+
*/
|
|
42
|
+
export declare const Actions: (props: ActionsProps) => import("react").ReactNode;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Actions = void 0;
|
|
4
|
+
const services_manager_react_1 = require("@wix/services-manager-react");
|
|
5
|
+
const selected_variant_service_1 = require("../services/selected-variant-service");
|
|
6
|
+
const product_modifiers_service_1 = require("../services/product-modifiers-service");
|
|
7
|
+
/**
|
|
8
|
+
* Headless component for product actions (add to cart, buy now)
|
|
9
|
+
*
|
|
10
|
+
* @component
|
|
11
|
+
*/
|
|
12
|
+
const Actions = (props) => {
|
|
13
|
+
const variantService = (0, services_manager_react_1.useService)(selected_variant_service_1.SelectedVariantServiceDefinition);
|
|
14
|
+
// const cartService = useService(CurrentCartServiceDefinition) as ServiceAPI<
|
|
15
|
+
// typeof CurrentCartServiceDefinition
|
|
16
|
+
// >;
|
|
17
|
+
// Try to get modifiers service - it may not exist for all products
|
|
18
|
+
let modifiersService = null;
|
|
19
|
+
try {
|
|
20
|
+
modifiersService = (0, services_manager_react_1.useService)(product_modifiers_service_1.ProductModifiersServiceDefinition);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Modifiers service not available for this product
|
|
24
|
+
modifiersService = null;
|
|
25
|
+
}
|
|
26
|
+
const price = variantService.currentPrice.get();
|
|
27
|
+
const inStock = variantService.isInStock.get();
|
|
28
|
+
const isPreOrderEnabled = variantService.isPreOrderEnabled.get();
|
|
29
|
+
const preOrderMessage = variantService.preOrderMessage.get();
|
|
30
|
+
const isLoading = variantService.isLoading.get();
|
|
31
|
+
const error = variantService.error.get();
|
|
32
|
+
const availableQuantity = variantService.quantityAvailable.get();
|
|
33
|
+
const quantity = variantService.selectedQuantity.get();
|
|
34
|
+
// Check if all required modifiers are filled
|
|
35
|
+
const areAllRequiredModifiersFilled = modifiersService
|
|
36
|
+
? modifiersService.areAllRequiredModifiersFilled()
|
|
37
|
+
: true; // If no modifiers service, assume no required modifiers
|
|
38
|
+
const canAddToCart = (inStock || isPreOrderEnabled) &&
|
|
39
|
+
!isLoading &&
|
|
40
|
+
areAllRequiredModifiersFilled;
|
|
41
|
+
const onAddToCart = async () => {
|
|
42
|
+
// Get modifiers data if available
|
|
43
|
+
let modifiersData;
|
|
44
|
+
if (modifiersService) {
|
|
45
|
+
const selectedModifiers = modifiersService.selectedModifiers.get();
|
|
46
|
+
if (Object.keys(selectedModifiers).length > 0) {
|
|
47
|
+
modifiersData = selectedModifiers;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
await variantService.addToCart(quantity, modifiersData);
|
|
51
|
+
};
|
|
52
|
+
const onBuyNow = async () => {
|
|
53
|
+
try {
|
|
54
|
+
// Clear the cart first
|
|
55
|
+
// await cartService.clearCart();
|
|
56
|
+
// Add the product to cart
|
|
57
|
+
await onAddToCart();
|
|
58
|
+
// Proceed to checkout
|
|
59
|
+
// await cartService.proceedToCheckout();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error('Buy now failed:', error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const onOpenCart = () => {
|
|
67
|
+
// cartService.openCart();
|
|
68
|
+
};
|
|
69
|
+
return props.children({
|
|
70
|
+
onAddToCart,
|
|
71
|
+
onBuyNow,
|
|
72
|
+
onOpenCart,
|
|
73
|
+
canAddToCart,
|
|
74
|
+
isLoading,
|
|
75
|
+
price,
|
|
76
|
+
inStock,
|
|
77
|
+
isPreOrderEnabled,
|
|
78
|
+
preOrderMessage,
|
|
79
|
+
error,
|
|
80
|
+
availableQuantity,
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
exports.Actions = Actions;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ConnectedModifier, type ConnectedModifierChoice } from '@wix/auto_sdk_stores_products-v-3';
|
|
2
2
|
/**
|
|
3
3
|
* Props for Modifiers headless component
|
|
4
4
|
*/
|
|
@@ -11,7 +11,7 @@ export interface ModifiersProps {
|
|
|
11
11
|
*/
|
|
12
12
|
export interface ModifiersRenderProps {
|
|
13
13
|
/** Array of product modifiers */
|
|
14
|
-
modifiers:
|
|
14
|
+
modifiers: ConnectedModifier[];
|
|
15
15
|
/** Whether product has modifiers */
|
|
16
16
|
hasModifiers: boolean;
|
|
17
17
|
/** Currently selected modifier values */
|
|
@@ -28,7 +28,7 @@ export declare const Modifiers: (props: ModifiersProps) => import("react").React
|
|
|
28
28
|
*/
|
|
29
29
|
export interface ModifierProps {
|
|
30
30
|
/** Product modifier data */
|
|
31
|
-
modifier:
|
|
31
|
+
modifier: ConnectedModifier;
|
|
32
32
|
/** Render prop function that receives modifier data */
|
|
33
33
|
children: (props: ModifierRenderProps) => React.ReactNode;
|
|
34
34
|
}
|
|
@@ -43,7 +43,7 @@ export interface ModifierRenderProps {
|
|
|
43
43
|
/** Whether this modifier is mandatory */
|
|
44
44
|
mandatory: boolean;
|
|
45
45
|
/** Array of choices for this modifier (for choice-based modifiers) */
|
|
46
|
-
choices:
|
|
46
|
+
choices: ConnectedModifierChoice[];
|
|
47
47
|
/** Currently selected value for this modifier */
|
|
48
48
|
selectedValue: any;
|
|
49
49
|
/** Whether this modifier has choices */
|
|
@@ -57,6 +57,8 @@ export interface ModifierRenderProps {
|
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* Headless component for a specific product modifier
|
|
60
|
+
*
|
|
61
|
+
* @component
|
|
60
62
|
*/
|
|
61
63
|
export declare const Modifier: (props: ModifierProps) => import("react").ReactNode;
|
|
62
64
|
/**
|
|
@@ -64,9 +66,9 @@ export declare const Modifier: (props: ModifierProps) => import("react").ReactNo
|
|
|
64
66
|
*/
|
|
65
67
|
export interface ChoiceProps {
|
|
66
68
|
/** Product modifier data */
|
|
67
|
-
modifier:
|
|
69
|
+
modifier: ConnectedModifier;
|
|
68
70
|
/** Choice data */
|
|
69
|
-
choice:
|
|
71
|
+
choice: ConnectedModifierChoice;
|
|
70
72
|
/** Render prop function that receives choice data */
|
|
71
73
|
children: (props: ChoiceRenderProps) => React.ReactNode;
|
|
72
74
|
}
|
|
@@ -91,6 +93,8 @@ export interface ChoiceRenderProps {
|
|
|
91
93
|
}
|
|
92
94
|
/**
|
|
93
95
|
* Headless component for individual modifier choice selection
|
|
96
|
+
*
|
|
97
|
+
* @component
|
|
94
98
|
*/
|
|
95
99
|
export declare const Choice: (props: ChoiceProps) => import("react").ReactNode;
|
|
96
100
|
/**
|
|
@@ -98,7 +102,7 @@ export declare const Choice: (props: ChoiceProps) => import("react").ReactNode;
|
|
|
98
102
|
*/
|
|
99
103
|
export interface FreeTextProps {
|
|
100
104
|
/** Product modifier data */
|
|
101
|
-
modifier:
|
|
105
|
+
modifier: ConnectedModifier;
|
|
102
106
|
/** Render prop function that receives free text data */
|
|
103
107
|
children: (props: FreeTextRenderProps) => React.ReactNode;
|
|
104
108
|
}
|
|
@@ -125,6 +129,8 @@ export interface FreeTextRenderProps {
|
|
|
125
129
|
}
|
|
126
130
|
/**
|
|
127
131
|
* Headless component for free text modifier input
|
|
132
|
+
*
|
|
133
|
+
* @component
|
|
128
134
|
*/
|
|
129
135
|
export declare const FreeText: (props: FreeTextProps) => import("react").ReactNode;
|
|
130
136
|
/**
|
|
@@ -132,7 +138,7 @@ export declare const FreeText: (props: FreeTextProps) => import("react").ReactNo
|
|
|
132
138
|
*/
|
|
133
139
|
export interface ToggleFreeTextProps {
|
|
134
140
|
/** Product modifier data */
|
|
135
|
-
modifier:
|
|
141
|
+
modifier: ConnectedModifier;
|
|
136
142
|
/** Render prop function that receives toggle data */
|
|
137
143
|
children: (props: ToggleFreeTextRenderProps) => React.ReactNode;
|
|
138
144
|
}
|
|
@@ -152,5 +158,7 @@ export interface ToggleFreeTextRenderProps {
|
|
|
152
158
|
/**
|
|
153
159
|
* Headless component for toggling free text modifier input
|
|
154
160
|
* Used for optional free text modifiers where a checkbox shows/hides the input
|
|
161
|
+
*
|
|
162
|
+
* @component
|
|
155
163
|
*/
|
|
156
164
|
export declare const ToggleFreeText: (props: ToggleFreeTextProps) => import("react").ReactNode;
|
|
@@ -4,6 +4,7 @@ exports.ToggleFreeText = exports.FreeText = exports.Choice = exports.Modifier =
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const services_manager_react_1 = require("@wix/services-manager-react");
|
|
6
6
|
const product_modifiers_service_1 = require("../services/product-modifiers-service");
|
|
7
|
+
const auto_sdk_stores_products_v_3_1 = require("@wix/auto_sdk_stores_products-v-3");
|
|
7
8
|
/**
|
|
8
9
|
* Custom hook to safely get the modifiers service
|
|
9
10
|
*/
|
|
@@ -42,16 +43,18 @@ const Modifiers = (props) => {
|
|
|
42
43
|
exports.Modifiers = Modifiers;
|
|
43
44
|
/**
|
|
44
45
|
* Headless component for a specific product modifier
|
|
46
|
+
*
|
|
47
|
+
* @component
|
|
45
48
|
*/
|
|
46
49
|
const Modifier = (props) => {
|
|
47
50
|
const modifiersService = useModifiersService();
|
|
48
51
|
const { modifier } = props;
|
|
49
|
-
const name = modifier.name ||
|
|
52
|
+
const name = modifier.name || '';
|
|
50
53
|
const type = modifier.modifierRenderType;
|
|
51
54
|
const mandatory = modifier.mandatory || false;
|
|
52
55
|
const choices = modifier.choicesSettings?.choices || [];
|
|
53
56
|
const hasChoices = choices.length > 0;
|
|
54
|
-
const isFreeText = type ===
|
|
57
|
+
const isFreeText = type === auto_sdk_stores_products_v_3_1.ModifierRenderType.FREE_TEXT;
|
|
55
58
|
const freeTextSettings = modifier.freeTextSettings;
|
|
56
59
|
const maxChars = freeTextSettings?.maxLength;
|
|
57
60
|
const placeholder = freeTextSettings?.placeholder;
|
|
@@ -71,17 +74,19 @@ const Modifier = (props) => {
|
|
|
71
74
|
exports.Modifier = Modifier;
|
|
72
75
|
/**
|
|
73
76
|
* Headless component for individual modifier choice selection
|
|
77
|
+
*
|
|
78
|
+
* @component
|
|
74
79
|
*/
|
|
75
80
|
const Choice = (props) => {
|
|
76
81
|
const modifiersService = useModifiersService();
|
|
77
82
|
const { modifier, choice } = props;
|
|
78
|
-
const modifierName = modifier.name ||
|
|
83
|
+
const modifierName = modifier.name || '';
|
|
79
84
|
const renderType = modifier.modifierRenderType;
|
|
80
85
|
// For TEXT_CHOICES, use choice.key; for SWATCH_CHOICES, use choice.name
|
|
81
|
-
const choiceValue = renderType ===
|
|
82
|
-
?
|
|
83
|
-
:
|
|
84
|
-
const value = choice.name ||
|
|
86
|
+
const choiceValue = renderType === auto_sdk_stores_products_v_3_1.ModifierRenderType.TEXT_CHOICES
|
|
87
|
+
? choice.key || choice.name || ''
|
|
88
|
+
: choice.name || '';
|
|
89
|
+
const value = choice.name || ''; // Display name is always choice.name
|
|
85
90
|
const description = choice.description;
|
|
86
91
|
const colorCode = choice.colorCode;
|
|
87
92
|
const selectedValue = modifiersService?.getModifierValue(modifierName);
|
|
@@ -102,17 +107,19 @@ const Choice = (props) => {
|
|
|
102
107
|
exports.Choice = Choice;
|
|
103
108
|
/**
|
|
104
109
|
* Headless component for free text modifier input
|
|
110
|
+
*
|
|
111
|
+
* @component
|
|
105
112
|
*/
|
|
106
113
|
const FreeText = (props) => {
|
|
107
114
|
const modifiersService = useModifiersService();
|
|
108
115
|
const { modifier } = props;
|
|
109
|
-
const modifierName = modifier.name ||
|
|
116
|
+
const modifierName = modifier.name || '';
|
|
110
117
|
const mandatory = modifier.mandatory || false;
|
|
111
118
|
const freeTextSettings = modifier.freeTextSettings;
|
|
112
119
|
const maxChars = freeTextSettings?.maxLength;
|
|
113
120
|
const placeholder = freeTextSettings?.placeholder;
|
|
114
121
|
const selectedValue = modifiersService?.getModifierValue(modifierName);
|
|
115
|
-
const value = selectedValue?.freeTextValue ||
|
|
122
|
+
const value = selectedValue?.freeTextValue || '';
|
|
116
123
|
const charCount = value.length;
|
|
117
124
|
const isOverLimit = maxChars ? charCount > maxChars : false;
|
|
118
125
|
const onChange = (newValue) => {
|
|
@@ -135,11 +142,13 @@ exports.FreeText = FreeText;
|
|
|
135
142
|
/**
|
|
136
143
|
* Headless component for toggling free text modifier input
|
|
137
144
|
* Used for optional free text modifiers where a checkbox shows/hides the input
|
|
145
|
+
*
|
|
146
|
+
* @component
|
|
138
147
|
*/
|
|
139
148
|
const ToggleFreeText = (props) => {
|
|
140
149
|
const modifiersService = useModifiersService();
|
|
141
150
|
const { modifier } = props;
|
|
142
|
-
const modifierName = modifier.name ||
|
|
151
|
+
const modifierName = modifier.name || '';
|
|
143
152
|
const mandatory = modifier.mandatory || false;
|
|
144
153
|
const [isTextInputShown, setIsTextInputShown] = (0, react_1.useState)(mandatory);
|
|
145
154
|
const onToggle = () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ConnectedOption, type ConnectedOptionChoice, InventoryAvailabilityStatus } from '@wix/auto_sdk_stores_products-v-3';
|
|
2
2
|
/**
|
|
3
3
|
* Props for Options headless component
|
|
4
4
|
*/
|
|
@@ -11,7 +11,7 @@ export interface OptionsProps {
|
|
|
11
11
|
*/
|
|
12
12
|
export interface OptionsRenderProps {
|
|
13
13
|
/** Array of product options */
|
|
14
|
-
options:
|
|
14
|
+
options: ConnectedOption[];
|
|
15
15
|
/** Whether product has options */
|
|
16
16
|
hasOptions: boolean;
|
|
17
17
|
/** Currently selected choices */
|
|
@@ -19,6 +19,8 @@ export interface OptionsRenderProps {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Headless component for all product options
|
|
22
|
+
*
|
|
23
|
+
* @component
|
|
22
24
|
*/
|
|
23
25
|
export declare const Options: (props: OptionsProps) => import("react").ReactNode;
|
|
24
26
|
/**
|
|
@@ -26,7 +28,7 @@ export declare const Options: (props: OptionsProps) => import("react").ReactNode
|
|
|
26
28
|
*/
|
|
27
29
|
export interface OptionProps {
|
|
28
30
|
/** Product option data */
|
|
29
|
-
option:
|
|
31
|
+
option: ConnectedOption;
|
|
30
32
|
/** Render prop function that receives option data */
|
|
31
33
|
children: (props: OptionRenderProps) => React.ReactNode;
|
|
32
34
|
}
|
|
@@ -39,7 +41,7 @@ export interface OptionRenderProps {
|
|
|
39
41
|
/** Option type */
|
|
40
42
|
type: any;
|
|
41
43
|
/** Array of choices for this option */
|
|
42
|
-
choices:
|
|
44
|
+
choices: ConnectedOptionChoice[];
|
|
43
45
|
/** Currently selected value for this option */
|
|
44
46
|
selectedValue: string | null;
|
|
45
47
|
/** Whether this option has choices */
|
|
@@ -47,6 +49,8 @@ export interface OptionRenderProps {
|
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
49
51
|
* Headless component for choices within a specific product option
|
|
52
|
+
*
|
|
53
|
+
* @component
|
|
50
54
|
*/
|
|
51
55
|
export declare const Option: (props: OptionProps) => import("react").ReactNode;
|
|
52
56
|
/**
|
|
@@ -54,9 +58,9 @@ export declare const Option: (props: OptionProps) => import("react").ReactNode;
|
|
|
54
58
|
*/
|
|
55
59
|
export interface ChoiceProps {
|
|
56
60
|
/** Product option data */
|
|
57
|
-
option:
|
|
61
|
+
option: ConnectedOption;
|
|
58
62
|
/** Choice data */
|
|
59
|
-
choice:
|
|
63
|
+
choice: ConnectedOptionChoice;
|
|
60
64
|
/** Render prop function that receives choice data */
|
|
61
65
|
children: (props: ChoiceRenderProps) => React.ReactNode;
|
|
62
66
|
}
|
|
@@ -70,8 +74,12 @@ export interface ChoiceRenderProps {
|
|
|
70
74
|
description: string | undefined;
|
|
71
75
|
/** Whether this choice is currently selected */
|
|
72
76
|
isSelected: boolean;
|
|
73
|
-
/** Whether this choice is
|
|
74
|
-
|
|
77
|
+
/** Whether this choice is visible */
|
|
78
|
+
isVisible: boolean;
|
|
79
|
+
/** Whether this choice is in stock */
|
|
80
|
+
isInStock: boolean;
|
|
81
|
+
/** Whether this choice is available for pre-order */
|
|
82
|
+
isPreOrderEnabled: boolean;
|
|
75
83
|
/** Function to select this choice */
|
|
76
84
|
onSelect: () => void;
|
|
77
85
|
/** Option name */
|
|
@@ -81,64 +89,10 @@ export interface ChoiceRenderProps {
|
|
|
81
89
|
}
|
|
82
90
|
/**
|
|
83
91
|
* Headless component for individual choice selection
|
|
92
|
+
*
|
|
93
|
+
* @component
|
|
84
94
|
*/
|
|
85
95
|
export declare const Choice: (props: ChoiceProps) => import("react").ReactNode;
|
|
86
|
-
/**
|
|
87
|
-
* Props for Trigger headless component
|
|
88
|
-
*/
|
|
89
|
-
export interface TriggerProps {
|
|
90
|
-
/** Quantity to add (optional) */
|
|
91
|
-
quantity?: number;
|
|
92
|
-
/** Render prop function that receives trigger data */
|
|
93
|
-
children: (props: TriggerRenderProps) => React.ReactNode;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Render props for Trigger component
|
|
97
|
-
*/
|
|
98
|
-
export interface TriggerRenderProps {
|
|
99
|
-
/** Function to add product to cart */
|
|
100
|
-
onAddToCart: () => Promise<void>;
|
|
101
|
-
/** Whether add to cart is available */
|
|
102
|
-
canAddToCart: boolean;
|
|
103
|
-
/** Whether add to cart is currently loading */
|
|
104
|
-
isLoading: boolean;
|
|
105
|
-
/** Current product price */
|
|
106
|
-
price: string;
|
|
107
|
-
/** Whether product is in stock */
|
|
108
|
-
inStock: boolean;
|
|
109
|
-
/** Whether pre-order is enabled */
|
|
110
|
-
isPreOrderEnabled: boolean;
|
|
111
|
-
/** Error message if any */
|
|
112
|
-
error: string | null;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Headless component for add to cart trigger
|
|
116
|
-
*/
|
|
117
|
-
export declare const Trigger: (props: TriggerProps) => import("react").ReactNode;
|
|
118
|
-
/**
|
|
119
|
-
* Props for Price headless component
|
|
120
|
-
*/
|
|
121
|
-
export interface PriceProps {
|
|
122
|
-
/** Render prop function that receives price data */
|
|
123
|
-
children: (props: PriceRenderProps) => React.ReactNode;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Render props for Price component
|
|
127
|
-
*/
|
|
128
|
-
export interface PriceRenderProps {
|
|
129
|
-
/** Current price (formatted) */
|
|
130
|
-
price: string;
|
|
131
|
-
/** Compare at price (formatted) - null if no compare price */
|
|
132
|
-
compareAtPrice: string | null;
|
|
133
|
-
/** Whether price is for a variant */
|
|
134
|
-
isVariantPrice: boolean;
|
|
135
|
-
/** Currency code */
|
|
136
|
-
currency: string;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Headless component for product price display
|
|
140
|
-
*/
|
|
141
|
-
export declare const Price: (props: PriceProps) => import("react").ReactNode;
|
|
142
96
|
/**
|
|
143
97
|
* Props for Stock headless component
|
|
144
98
|
*/
|
|
@@ -154,16 +108,46 @@ export interface StockRenderProps {
|
|
|
154
108
|
inStock: boolean;
|
|
155
109
|
/** Whether pre-order is enabled */
|
|
156
110
|
isPreOrderEnabled: boolean;
|
|
157
|
-
/**
|
|
158
|
-
|
|
159
|
-
/** Stock quantity (if available) */
|
|
160
|
-
quantity: number | null;
|
|
111
|
+
/** Raw inventory availability status */
|
|
112
|
+
availabilityStatus: InventoryAvailabilityStatus | string;
|
|
161
113
|
/** Whether stock tracking is enabled */
|
|
162
114
|
trackInventory: boolean;
|
|
163
115
|
/** Current variant id */
|
|
164
116
|
currentVariantId: string | null;
|
|
117
|
+
/** Available quantity */
|
|
118
|
+
availableQuantity: number | null;
|
|
119
|
+
/** Currently selected quantity */
|
|
120
|
+
selectedQuantity: number;
|
|
121
|
+
/** Function to increment quantity */
|
|
122
|
+
incrementQuantity: () => void;
|
|
123
|
+
/** Function to decrement quantity */
|
|
124
|
+
decrementQuantity: () => void;
|
|
165
125
|
}
|
|
166
126
|
/**
|
|
167
127
|
* Headless component for product stock status
|
|
128
|
+
*
|
|
129
|
+
* @component
|
|
168
130
|
*/
|
|
169
131
|
export declare const Stock: (props: StockProps) => import("react").ReactNode;
|
|
132
|
+
/**
|
|
133
|
+
* Props for Reset headless component
|
|
134
|
+
*/
|
|
135
|
+
export interface ResetProps {
|
|
136
|
+
/** Render prop function that receives reset data */
|
|
137
|
+
children: (props: ResetRenderProps) => React.ReactNode;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Render props for Reset component
|
|
141
|
+
*/
|
|
142
|
+
export interface ResetRenderProps {
|
|
143
|
+
/** Function to reset all selections */
|
|
144
|
+
onReset: () => void;
|
|
145
|
+
/** Whether the reset button should be rendered */
|
|
146
|
+
hasSelections: boolean;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Headless component for resetting variant selections
|
|
150
|
+
*
|
|
151
|
+
* @component
|
|
152
|
+
*/
|
|
153
|
+
export declare const Reset: (props: ResetProps) => import("react").ReactNode;
|