@wix/headless-stores 0.0.37 → 0.0.39

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.
Files changed (37) hide show
  1. package/cjs/dist/react/Category.d.ts +9 -8
  2. package/cjs/dist/react/CategoryList.d.ts +12 -11
  3. package/cjs/dist/react/Product.d.ts +5 -4
  4. package/cjs/dist/react/ProductListFilters.d.ts +9 -5
  5. package/cjs/dist/react/ProductListFilters.js +14 -5
  6. package/cjs/dist/react/ProductListPagination.d.ts +14 -12
  7. package/cjs/dist/react/ProductListSort.d.ts +6 -4
  8. package/cjs/dist/react/ProductModifiers.d.ts +4 -2
  9. package/cjs/dist/react/ProductVariantSelector.d.ts +5 -4
  10. package/cjs/dist/react/SelectedVariant.d.ts +68 -4
  11. package/cjs/dist/react/SelectedVariant.js +97 -0
  12. package/cjs/dist/react/index.d.ts +0 -1
  13. package/cjs/dist/react/index.js +0 -1
  14. package/cjs/dist/services/products-list-filters-service.d.ts +41 -24
  15. package/cjs/dist/services/products-list-filters-service.js +150 -92
  16. package/cjs/dist/services/products-list-service.js +87 -3
  17. package/dist/react/Category.d.ts +9 -8
  18. package/dist/react/CategoryList.d.ts +12 -11
  19. package/dist/react/Product.d.ts +5 -4
  20. package/dist/react/ProductListFilters.d.ts +9 -5
  21. package/dist/react/ProductListFilters.js +14 -5
  22. package/dist/react/ProductListPagination.d.ts +14 -12
  23. package/dist/react/ProductListSort.d.ts +6 -4
  24. package/dist/react/ProductModifiers.d.ts +4 -2
  25. package/dist/react/ProductVariantSelector.d.ts +5 -4
  26. package/dist/react/SelectedVariant.d.ts +68 -4
  27. package/dist/react/SelectedVariant.js +97 -0
  28. package/dist/react/index.d.ts +0 -1
  29. package/dist/react/index.js +0 -1
  30. package/dist/services/products-list-filters-service.d.ts +41 -24
  31. package/dist/services/products-list-filters-service.js +150 -92
  32. package/dist/services/products-list-service.js +87 -3
  33. package/package.json +2 -2
  34. package/cjs/dist/react/ProductActions.d.ts +0 -70
  35. package/cjs/dist/react/ProductActions.js +0 -104
  36. package/dist/react/ProductActions.d.ts +0 -70
  37. package/dist/react/ProductActions.js +0 -104
@@ -1,5 +1,8 @@
1
- import type { PropsWithChildren, ReactNode } from "react";
2
1
  import { type CategoryServiceConfig } from "../services/category-service.js";
2
+ export interface RootProps {
3
+ children: React.ReactNode;
4
+ categoryServiceConfig: CategoryServiceConfig;
5
+ }
3
6
  /**
4
7
  * Root component that provides the Category service context to its children.
5
8
  * This component sets up the necessary services for managing category state.
@@ -24,15 +27,13 @@ import { type CategoryServiceConfig } from "../services/category-service.js";
24
27
  * }
25
28
  * ```
26
29
  */
27
- export declare function Root(props: PropsWithChildren<{
28
- categoryServiceConfig: CategoryServiceConfig;
29
- }>): import("react/jsx-runtime").JSX.Element;
30
+ export declare function Root(props: RootProps): React.ReactNode;
30
31
  /**
31
32
  * Props for Name headless component
32
33
  */
33
34
  export interface NameProps {
34
35
  /** Content to display (can be a render function receiving name data or ReactNode) */
35
- children: ((props: NameRenderProps) => ReactNode) | ReactNode;
36
+ children: ((props: NameRenderProps) => React.ReactNode) | React.ReactNode;
36
37
  }
37
38
  /**
38
39
  * Render props for Name component
@@ -60,13 +61,13 @@ export interface NameRenderProps {
60
61
  * }
61
62
  * ```
62
63
  */
63
- export declare function Name(props: NameProps): ReactNode;
64
+ export declare function Name(props: NameProps): import("react").ReactNode;
64
65
  /**
65
66
  * Props for Slug headless component
66
67
  */
67
68
  export interface SlugProps {
68
69
  /** Content to display (can be a render function receiving slug data or ReactNode) */
69
- children: ((props: SlugRenderProps) => ReactNode) | ReactNode;
70
+ children: ((props: SlugRenderProps) => React.ReactNode) | React.ReactNode;
70
71
  }
71
72
  /**
72
73
  * Render props for Slug component
@@ -94,4 +95,4 @@ export interface SlugRenderProps {
94
95
  * }
95
96
  * ```
96
97
  */
97
- export declare function Slug(props: SlugProps): ReactNode;
98
+ export declare function Slug(props: SlugProps): import("react").ReactNode;
@@ -1,6 +1,9 @@
1
1
  import { type CategoriesListServiceConfig } from "../services/categories-list-service.js";
2
- import type { PropsWithChildren, ReactNode } from "react";
3
2
  import { categories } from "@wix/categories";
3
+ export interface RootProps {
4
+ children: React.ReactNode;
5
+ categoriesListConfig: CategoriesListServiceConfig;
6
+ }
4
7
  /**
5
8
  * Root component that provides the CategoryList service context to its children.
6
9
  * This component sets up the necessary services for managing categories list state.
@@ -26,15 +29,13 @@ import { categories } from "@wix/categories";
26
29
  * }
27
30
  * ```
28
31
  */
29
- export declare function Root(props: PropsWithChildren<{
30
- categoriesListConfig: CategoriesListServiceConfig;
31
- }>): import("react/jsx-runtime").JSX.Element;
32
+ export declare function Root(props: RootProps): React.ReactNode;
32
33
  /**
33
34
  * Props for EmptyState headless component
34
35
  */
35
36
  export interface EmptyStateProps {
36
37
  /** Content to display when categories list is empty (can be a render function or ReactNode) */
37
- children: ((props: EmptyStateRenderProps) => ReactNode) | ReactNode;
38
+ children: ((props: EmptyStateRenderProps) => React.ReactNode) | React.ReactNode;
38
39
  }
39
40
  /**
40
41
  * Render props for EmptyState component
@@ -64,13 +65,13 @@ export interface EmptyStateRenderProps {
64
65
  * }
65
66
  * ```
66
67
  */
67
- export declare function EmptyState(props: EmptyStateProps): ReactNode;
68
+ export declare function EmptyState(props: EmptyStateProps): import("react").ReactNode;
68
69
  /**
69
70
  * Props for Loading headless component
70
71
  */
71
72
  export interface LoadingProps {
72
73
  /** Content to display during loading (can be a render function or ReactNode) */
73
- children: ((props: LoadingRenderProps) => ReactNode) | ReactNode;
74
+ children: ((props: LoadingRenderProps) => React.ReactNode) | React.ReactNode;
74
75
  }
75
76
  /**
76
77
  * Render props for Loading component
@@ -100,13 +101,13 @@ export interface LoadingRenderProps {
100
101
  * }
101
102
  * ```
102
103
  */
103
- export declare function Loading(props: LoadingProps): ReactNode;
104
+ export declare function Loading(props: LoadingProps): import("react").ReactNode;
104
105
  /**
105
106
  * Props for Error headless component
106
107
  */
107
108
  export interface ErrorProps {
108
109
  /** Content to display during error state (can be a render function or ReactNode) */
109
- children: ((props: ErrorRenderProps) => ReactNode) | ReactNode;
110
+ children: ((props: ErrorRenderProps) => React.ReactNode) | React.ReactNode;
110
111
  }
111
112
  /**
112
113
  * Render props for Error component
@@ -141,13 +142,13 @@ export interface ErrorRenderProps {
141
142
  * }
142
143
  * ```
143
144
  */
144
- export declare function Error(props: ErrorProps): ReactNode;
145
+ export declare function Error(props: ErrorProps): import("react").ReactNode;
145
146
  /**
146
147
  * Props for ItemContent headless component
147
148
  */
148
149
  export interface ItemContentProps {
149
150
  /** Content to display for each category (can be a render function receiving category data or ReactNode) */
150
- children: ((props: ItemContentRenderProps) => ReactNode) | ReactNode;
151
+ children: ((props: ItemContentRenderProps) => React.ReactNode) | React.ReactNode;
151
152
  }
152
153
  /**
153
154
  * Render props for ItemContent component
@@ -1,6 +1,9 @@
1
1
  import { ProductServiceConfig } from "../services/product-service.js";
2
2
  import type { V3Product, ProductMedia } from "@wix/auto_sdk_stores_products-v-3";
3
- import type { PropsWithChildren } from "react";
3
+ export interface RootProps {
4
+ children: React.ReactNode;
5
+ productServiceConfig: ProductServiceConfig;
6
+ }
4
7
  /**
5
8
  * Root component that provides the Product service context to its children.
6
9
  * This component sets up the necessary services for rendering and managing a single product's data.
@@ -31,9 +34,7 @@ import type { PropsWithChildren } from "react";
31
34
  * }
32
35
  * ```
33
36
  */
34
- export declare function Root(props: PropsWithChildren<{
35
- productServiceConfig: ProductServiceConfig;
36
- }>): import("react/jsx-runtime").JSX.Element;
37
+ export declare function Root(props: RootProps): React.ReactNode;
37
38
  /**
38
39
  * Props for ProductName headless component
39
40
  */
@@ -39,7 +39,7 @@ export interface RootProps {
39
39
  * }
40
40
  * ```
41
41
  */
42
- export declare function Root(props: RootProps): import("react/jsx-runtime").JSX.Element;
42
+ export declare function Root(props: RootProps): React.ReactNode;
43
43
  /**
44
44
  * Props for InventoryStatus headless component
45
45
  */
@@ -144,13 +144,17 @@ export interface PriceRangeProps {
144
144
  */
145
145
  export interface PriceRangeRenderProps {
146
146
  /** Current minimum price filter value */
147
- minPrice: number;
147
+ selectedMinPrice: number;
148
148
  /** Current maximum price filter value */
149
- maxPrice: number;
149
+ selectedMaxPrice: number;
150
+ /** Catalog minimum price */
151
+ availableMinPrice: number;
152
+ /** Catalog maximum price */
153
+ availableMaxPrice: number;
150
154
  /** Function to update the minimum price filter */
151
- setMinPrice: (minPrice: number) => void;
155
+ setSelectedMinPrice: (minPrice: number) => void;
152
156
  /** Function to update the maximum price filter */
153
- setMaxPrice: (maxPrice: number) => void;
157
+ setSelectedMaxPrice: (maxPrice: number) => void;
154
158
  }
155
159
  /**
156
160
  * Headless component for managing price range filters (combined min/max)
@@ -153,12 +153,21 @@ export function ResetTrigger(props) {
153
153
  */
154
154
  export function PriceRange(props) {
155
155
  const service = useService(ProductsListFiltersServiceDefinition);
156
- const minPrice = service.minPrice.get();
157
- const maxPrice = service.maxPrice.get();
158
- const setMinPrice = service.setMinPrice;
159
- const setMaxPrice = service.setMaxPrice;
156
+ const selectedMinPrice = service.selectedMinPrice.get();
157
+ const availableMinPrice = service.availableMinPrice.get();
158
+ const selectedMaxPrice = service.selectedMaxPrice.get();
159
+ const availableMaxPrice = service.availableMaxPrice.get();
160
+ const setSelectedMinPrice = service.setSelectedMinPrice;
161
+ const setSelectedMaxPrice = service.setSelectedMaxPrice;
160
162
  return typeof props.children === "function"
161
- ? props.children({ minPrice, maxPrice, setMinPrice, setMaxPrice })
163
+ ? props.children({
164
+ availableMinPrice,
165
+ selectedMinPrice,
166
+ selectedMaxPrice,
167
+ availableMaxPrice,
168
+ setSelectedMinPrice,
169
+ setSelectedMaxPrice,
170
+ })
162
171
  : props.children;
163
172
  }
164
173
  /**
@@ -1,4 +1,6 @@
1
- import type { PropsWithChildren, ReactNode } from "react";
1
+ export interface RootProps {
2
+ children: React.ReactNode;
3
+ }
2
4
  /**
3
5
  * Root component that provides the ProductListPagination service context to its children.
4
6
  * This component sets up the necessary services for managing products list pagination.
@@ -27,13 +29,13 @@ import type { PropsWithChildren, ReactNode } from "react";
27
29
  * }
28
30
  * ```
29
31
  */
30
- export declare function Root(props: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
32
+ export declare function Root(props: RootProps): React.ReactNode;
31
33
  /**
32
34
  * Props for PageSize headless component
33
35
  */
34
36
  export interface PageSizeProps {
35
37
  /** Content to display (can be a render function receiving page size controls or ReactNode) */
36
- children: ((props: PageSizeRenderProps) => ReactNode) | ReactNode;
38
+ children: ((props: PageSizeRenderProps) => React.ReactNode) | React.ReactNode;
37
39
  }
38
40
  /**
39
41
  * Render props for PageSize component
@@ -73,13 +75,13 @@ export interface PageSizeRenderProps {
73
75
  * }
74
76
  * ```
75
77
  */
76
- export declare function PageSize(props: PageSizeProps): ReactNode;
78
+ export declare function PageSize(props: PageSizeProps): import("react").ReactNode;
77
79
  /**
78
80
  * Props for NextPageTrigger headless component
79
81
  */
80
82
  export interface NextPageTriggerProps {
81
83
  /** Content to display (can be a render function receiving next page controls or ReactNode) */
82
- children: ((props: NextPageTriggerRenderProps) => ReactNode) | ReactNode;
84
+ children: ((props: NextPageTriggerRenderProps) => React.ReactNode) | React.ReactNode;
83
85
  }
84
86
  /**
85
87
  * Render props for NextPageTrigger component
@@ -115,13 +117,13 @@ export interface NextPageTriggerRenderProps {
115
117
  * }
116
118
  * ```
117
119
  */
118
- export declare function NextPageTrigger(props: NextPageTriggerProps): ReactNode;
120
+ export declare function NextPageTrigger(props: NextPageTriggerProps): import("react").ReactNode;
119
121
  /**
120
122
  * Props for PreviousPageTrigger headless component
121
123
  */
122
124
  export interface PreviousPageTriggerProps {
123
125
  /** Content to display (can be a render function receiving previous page controls or ReactNode) */
124
- children: ((props: PreviousPageTriggerRenderProps) => ReactNode) | ReactNode;
126
+ children: ((props: PreviousPageTriggerRenderProps) => React.ReactNode) | React.ReactNode;
125
127
  }
126
128
  /**
127
129
  * Render props for PreviousPageTrigger component
@@ -157,13 +159,13 @@ export interface PreviousPageTriggerRenderProps {
157
159
  * }
158
160
  * ```
159
161
  */
160
- export declare function PreviousPageTrigger(props: PreviousPageTriggerProps): ReactNode;
162
+ export declare function PreviousPageTrigger(props: PreviousPageTriggerProps): import("react").ReactNode;
161
163
  /**
162
164
  * Props for FirstPageTrigger headless component
163
165
  */
164
166
  export interface FirstPageTriggerProps {
165
167
  /** Content to display (can be a render function receiving first page controls or ReactNode) */
166
- children: ((props: FirstPageTriggerRenderProps) => ReactNode) | ReactNode;
168
+ children: ((props: FirstPageTriggerRenderProps) => React.ReactNode) | React.ReactNode;
167
169
  }
168
170
  /**
169
171
  * Render props for FirstPageTrigger component
@@ -199,13 +201,13 @@ export interface FirstPageTriggerRenderProps {
199
201
  * }
200
202
  * ```
201
203
  */
202
- export declare function FirstPageTrigger(props: FirstPageTriggerProps): ReactNode;
204
+ export declare function FirstPageTrigger(props: FirstPageTriggerProps): import("react").ReactNode;
203
205
  /**
204
206
  * Props for LoadMoreTrigger headless component
205
207
  */
206
208
  export interface LoadMoreTriggerProps {
207
209
  /** Content to display (can be a render function receiving load more controls or ReactNode) */
208
- children: ((props: LoadMoreTriggerRenderProps) => ReactNode) | ReactNode;
210
+ children: ((props: LoadMoreTriggerRenderProps) => React.ReactNode) | React.ReactNode;
209
211
  }
210
212
  /**
211
213
  * Render props for LoadMoreTrigger component
@@ -243,4 +245,4 @@ export interface LoadMoreTriggerRenderProps {
243
245
  * }
244
246
  * ```
245
247
  */
246
- export declare function LoadMoreTrigger(props: LoadMoreTriggerProps): ReactNode;
248
+ export declare function LoadMoreTrigger(props: LoadMoreTriggerProps): import("react").ReactNode;
@@ -1,5 +1,7 @@
1
- import type { PropsWithChildren, ReactNode } from "react";
2
1
  import { SortType } from "../services/products-list-sort-service.js";
2
+ export interface RootProps {
3
+ children: React.ReactNode;
4
+ }
3
5
  /**
4
6
  * Root component that provides the ProductListSort service context to its children.
5
7
  * This component sets up the necessary services for managing products list sorting.
@@ -32,13 +34,13 @@ import { SortType } from "../services/products-list-sort-service.js";
32
34
  * }
33
35
  * ```
34
36
  */
35
- export declare function Root(props: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
37
+ export declare function Root(props: RootProps): React.ReactNode;
36
38
  /**
37
39
  * Props for Options headless component
38
40
  */
39
41
  export interface OptionsProps {
40
42
  /** Content to display (can be a render function receiving sort controls or ReactNode) */
41
- children: ((props: OptionsRenderProps) => ReactNode) | ReactNode;
43
+ children: ((props: OptionsRenderProps) => React.ReactNode) | React.ReactNode;
42
44
  }
43
45
  /**
44
46
  * Render props for Options component
@@ -84,4 +86,4 @@ export interface OptionsRenderProps {
84
86
  * }
85
87
  * ```
86
88
  */
87
- export declare function Options(props: OptionsProps): ReactNode;
89
+ export declare function Options(props: OptionsProps): import("react").ReactNode;
@@ -1,5 +1,7 @@
1
1
  import { type ConnectedModifier, type ConnectedModifierChoice } from "@wix/auto_sdk_stores_products-v-3";
2
- import type { PropsWithChildren } from "react";
2
+ export interface RootProps {
3
+ children: React.ReactNode;
4
+ }
3
5
  /**
4
6
  * Root component that provides the ProductModifiers service context to its children.
5
7
  * This component sets up the necessary services for managing product modifier functionality.
@@ -74,7 +76,7 @@ import type { PropsWithChildren } from "react";
74
76
  * }
75
77
  * ```
76
78
  */
77
- export declare function Root(props: PropsWithChildren<{}>): import("react/jsx-runtime").JSX.Element;
79
+ export declare function Root(props: RootProps): React.ReactNode;
78
80
  /**
79
81
  * Props for Modifiers headless component
80
82
  */
@@ -1,6 +1,9 @@
1
1
  import { SelectedVariantServiceConfig } from "../services/selected-variant-service.js";
2
- import type { PropsWithChildren } from "react";
3
2
  import { type ConnectedOption, type ConnectedOptionChoice, InventoryAvailabilityStatus } from "@wix/auto_sdk_stores_products-v-3";
3
+ export interface RootProps {
4
+ children: React.ReactNode;
5
+ selectedVariantServiceConfig: SelectedVariantServiceConfig;
6
+ }
4
7
  /**
5
8
  * Root component that provides the ProductVariantSelector service context to its children.
6
9
  * This component sets up the necessary services for rendering and managing product variant selection.
@@ -39,9 +42,7 @@ import { type ConnectedOption, type ConnectedOptionChoice, InventoryAvailability
39
42
  * }
40
43
  * ```
41
44
  */
42
- export declare function Root(props: PropsWithChildren<{
43
- selectedVariantServiceConfig?: SelectedVariantServiceConfig;
44
- }>): import("react/jsx-runtime").JSX.Element;
45
+ export declare function Root(props: RootProps): React.ReactNode;
45
46
  /**
46
47
  * Props for Options headless component
47
48
  */
@@ -1,5 +1,8 @@
1
1
  import { SelectedVariantServiceConfig } from "../services/selected-variant-service.js";
2
- import type { PropsWithChildren } from "react";
2
+ export interface RootProps {
3
+ children: React.ReactNode;
4
+ selectedVariantServiceConfig: SelectedVariantServiceConfig;
5
+ }
3
6
  /**
4
7
  * Root component that provides the SelectedVariant service context to its children.
5
8
  * This component sets up the necessary services for rendering and managing selected variant data.
@@ -33,9 +36,7 @@ import type { PropsWithChildren } from "react";
33
36
  * }
34
37
  * ```
35
38
  */
36
- export declare function Root(props: PropsWithChildren<{
37
- selectedVariantServiceConfig?: SelectedVariantServiceConfig;
38
- }>): import("react/jsx-runtime").JSX.Element;
39
+ export declare function Root(props: RootProps): React.ReactNode;
39
40
  /**
40
41
  * Props for ProductDetails headless component
41
42
  */
@@ -161,3 +162,66 @@ export interface SKURenderProps {
161
162
  * ```
162
163
  */
163
164
  export declare function SKU(props: SKUProps): import("react").ReactNode;
165
+ /**
166
+ * Props for Actions headless component
167
+ */
168
+ export interface ActionsProps {
169
+ /** Render prop function that receives actions data */
170
+ children: (props: ActionsRenderProps) => React.ReactNode;
171
+ }
172
+ /**
173
+ * Render props for Actions component
174
+ */
175
+ export interface ActionsRenderProps {
176
+ /** Function to add product to cart */
177
+ onAddToCart: () => Promise<void>;
178
+ /** Function to buy now (clear cart, add product, proceed to checkout) */
179
+ onBuyNow: () => Promise<void>;
180
+ /** Whether add to cart is available */
181
+ canAddToCart: boolean;
182
+ /** Whether add to cart is currently loading */
183
+ isLoading: boolean;
184
+ /** Whether variant is in stock */
185
+ inStock: boolean;
186
+ /** Whether pre-order is enabled */
187
+ isPreOrderEnabled: boolean;
188
+ /** Pre-order message */
189
+ preOrderMessage: string | null;
190
+ /** Error message if any */
191
+ error: string | null;
192
+ }
193
+ /**
194
+ * Headless component for product actions (add to cart, buy now)
195
+ *
196
+ * @component
197
+ * @example
198
+ * ```tsx
199
+ * import { SelectedVariant } from '@wix/stores/components';
200
+ *
201
+ * function AddToCartButton() {
202
+ * return (
203
+ * <SelectedVariant.Actions>
204
+ * {({ onAddToCart, onBuyNow, canAddToCart, isLoading, inStock, error }) => (
205
+ * <div>
206
+ * {error && <div className="error">{error}</div>}
207
+ * {!inStock && <div>Out of stock</div>}
208
+ * <button
209
+ * onClick={onAddToCart}
210
+ * disabled={!canAddToCart || isLoading}
211
+ * >
212
+ * {isLoading ? 'Adding...' : 'Add to Cart'}
213
+ * </button>
214
+ * <button
215
+ * onClick={onBuyNow}
216
+ * disabled={!canAddToCart || isLoading}
217
+ * >
218
+ * Buy Now
219
+ * </button>
220
+ * </div>
221
+ * )}
222
+ * </SelectedVariant.Actions>
223
+ * );
224
+ * }
225
+ * ```
226
+ */
227
+ export declare function Actions(props: ActionsProps): import("react").ReactNode;
@@ -1,6 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useService, WixServices } from "@wix/services-manager-react";
3
3
  import { SelectedVariantServiceDefinition, SelectedVariantService, } from "../services/selected-variant-service.js";
4
+ import { ProductModifiersServiceDefinition } from "../services/product-modifiers-service.js";
5
+ import { CurrentCartServiceDefinition } from "@wix/headless-ecom/services";
4
6
  import { createServicesMap } from "@wix/services-manager";
5
7
  /**
6
8
  * Root component that provides the SelectedVariant service context to its children.
@@ -141,3 +143,98 @@ export function SKU(props) {
141
143
  sku,
142
144
  });
143
145
  }
146
+ /**
147
+ * Headless component for product actions (add to cart, buy now)
148
+ *
149
+ * @component
150
+ * @example
151
+ * ```tsx
152
+ * import { SelectedVariant } from '@wix/stores/components';
153
+ *
154
+ * function AddToCartButton() {
155
+ * return (
156
+ * <SelectedVariant.Actions>
157
+ * {({ onAddToCart, onBuyNow, canAddToCart, isLoading, inStock, error }) => (
158
+ * <div>
159
+ * {error && <div className="error">{error}</div>}
160
+ * {!inStock && <div>Out of stock</div>}
161
+ * <button
162
+ * onClick={onAddToCart}
163
+ * disabled={!canAddToCart || isLoading}
164
+ * >
165
+ * {isLoading ? 'Adding...' : 'Add to Cart'}
166
+ * </button>
167
+ * <button
168
+ * onClick={onBuyNow}
169
+ * disabled={!canAddToCart || isLoading}
170
+ * >
171
+ * Buy Now
172
+ * </button>
173
+ * </div>
174
+ * )}
175
+ * </SelectedVariant.Actions>
176
+ * );
177
+ * }
178
+ * ```
179
+ */
180
+ export function Actions(props) {
181
+ const variantService = useService(SelectedVariantServiceDefinition);
182
+ const cartService = useService(CurrentCartServiceDefinition);
183
+ // Try to get modifiers service - it may not exist for all products
184
+ let modifiersService = null;
185
+ try {
186
+ modifiersService = useService(ProductModifiersServiceDefinition);
187
+ }
188
+ catch {
189
+ // Modifiers service not available for this product
190
+ modifiersService = null;
191
+ }
192
+ const inStock = variantService.isInStock.get();
193
+ const isPreOrderEnabled = variantService.isPreOrderEnabled.get();
194
+ const preOrderMessage = variantService.preOrderMessage.get();
195
+ const isLoading = variantService.isLoading.get();
196
+ const error = variantService.error.get();
197
+ const quantity = variantService.selectedQuantity.get();
198
+ // Check if all required modifiers are filled
199
+ const areAllRequiredModifiersFilled = modifiersService
200
+ ? modifiersService.areAllRequiredModifiersFilled()
201
+ : true; // If no modifiers service, assume no required modifiers
202
+ const canAddToCart = (inStock || isPreOrderEnabled) &&
203
+ !isLoading &&
204
+ areAllRequiredModifiersFilled;
205
+ const onAddToCart = async () => {
206
+ // Get modifiers data if available
207
+ let modifiersData;
208
+ if (modifiersService) {
209
+ const selectedModifiers = modifiersService.selectedModifiers.get();
210
+ if (Object.keys(selectedModifiers).length > 0) {
211
+ modifiersData = selectedModifiers;
212
+ }
213
+ }
214
+ await variantService.addToCart(quantity, modifiersData);
215
+ };
216
+ const onBuyNow = async () => {
217
+ try {
218
+ // Clear the cart first
219
+ await cartService.clearCart();
220
+ // Add the product to cart
221
+ await onAddToCart();
222
+ // Proceed to checkout
223
+ await cartService.proceedToCheckout();
224
+ }
225
+ catch (error) {
226
+ console.error("Buy now failed:", error);
227
+ throw error;
228
+ }
229
+ };
230
+ return props.children({
231
+ onAddToCart,
232
+ onBuyNow,
233
+ canAddToCart,
234
+ isLoading,
235
+ inStock,
236
+ isPreOrderEnabled,
237
+ preOrderMessage,
238
+ error,
239
+ });
240
+ }
@@ -1,7 +1,6 @@
1
1
  export * as CategoryList from "./CategoryList.js";
2
2
  export * as Category from "./Category.js";
3
3
  export * as Product from "./Product.js";
4
- export * as ProductActions from "./ProductActions.js";
5
4
  export * as ProductModifiers from "./ProductModifiers.js";
6
5
  export * as ProductList from "./ProductList.js";
7
6
  export * as ProductListFilters from "./ProductListFilters.js";
@@ -1,7 +1,6 @@
1
1
  export * as CategoryList from "./CategoryList.js";
2
2
  export * as Category from "./Category.js";
3
3
  export * as Product from "./Product.js";
4
- export * as ProductActions from "./ProductActions.js";
5
4
  export * as ProductModifiers from "./ProductModifiers.js";
6
5
  export * as ProductList from "./ProductList.js";
7
6
  export * as ProductListFilters from "./ProductListFilters.js";