@wix/headless-stores 0.0.41 → 0.0.42

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 (41) hide show
  1. package/cjs/dist/react/ProductList.d.ts +31 -3
  2. package/cjs/dist/react/ProductList.js +33 -5
  3. package/cjs/dist/react/ProductListFilters.d.ts +91 -111
  4. package/cjs/dist/react/ProductListFilters.js +98 -115
  5. package/cjs/dist/react/ProductListPagination.d.ts +89 -96
  6. package/cjs/dist/react/ProductListPagination.js +96 -104
  7. package/cjs/dist/react/ProductListSort.d.ts +26 -57
  8. package/cjs/dist/react/ProductListSort.js +26 -58
  9. package/cjs/dist/services/index.d.ts +1 -3
  10. package/cjs/dist/services/index.js +1 -3
  11. package/cjs/dist/services/products-list-search-service.d.ts +219 -0
  12. package/cjs/dist/services/products-list-search-service.js +794 -0
  13. package/cjs/dist/services/products-list-service.d.ts +28 -11
  14. package/cjs/dist/services/products-list-service.js +26 -6
  15. package/dist/react/ProductList.d.ts +31 -3
  16. package/dist/react/ProductList.js +33 -5
  17. package/dist/react/ProductListFilters.d.ts +91 -111
  18. package/dist/react/ProductListFilters.js +98 -115
  19. package/dist/react/ProductListPagination.d.ts +89 -96
  20. package/dist/react/ProductListPagination.js +96 -104
  21. package/dist/react/ProductListSort.d.ts +26 -57
  22. package/dist/react/ProductListSort.js +26 -58
  23. package/dist/services/index.d.ts +1 -3
  24. package/dist/services/index.js +1 -3
  25. package/dist/services/products-list-search-service.d.ts +219 -0
  26. package/dist/services/products-list-search-service.js +794 -0
  27. package/dist/services/products-list-service.d.ts +28 -11
  28. package/dist/services/products-list-service.js +26 -6
  29. package/package.json +2 -2
  30. package/cjs/dist/services/products-list-filters-service.d.ts +0 -309
  31. package/cjs/dist/services/products-list-filters-service.js +0 -504
  32. package/cjs/dist/services/products-list-pagination-service.d.ts +0 -186
  33. package/cjs/dist/services/products-list-pagination-service.js +0 -179
  34. package/cjs/dist/services/products-list-sort-service.d.ts +0 -117
  35. package/cjs/dist/services/products-list-sort-service.js +0 -144
  36. package/dist/services/products-list-filters-service.d.ts +0 -309
  37. package/dist/services/products-list-filters-service.js +0 -504
  38. package/dist/services/products-list-pagination-service.d.ts +0 -186
  39. package/dist/services/products-list-pagination-service.js +0 -179
  40. package/dist/services/products-list-sort-service.d.ts +0 -117
  41. package/dist/services/products-list-sort-service.js +0 -144
@@ -1,5 +1,6 @@
1
1
  import { type ProductsListServiceConfig } from "../services/products-list-service.js";
2
2
  import { productsV3 } from "@wix/stores";
3
+ import { ProductsListSearchServiceConfig } from "../services/products-list-search-service.js";
3
4
  /**
4
5
  * Props for Root headless component
5
6
  */
@@ -8,16 +9,19 @@ export interface RootProps {
8
9
  children: React.ReactNode;
9
10
  /** Configuration for the ProductList service */
10
11
  productsListConfig: ProductsListServiceConfig;
12
+ /** Configuration for the ProductListSearch service */
13
+ productsListSearchConfig?: ProductsListSearchServiceConfig;
11
14
  }
12
15
  /**
13
- * Root component that provides the ProductList service context to its children.
14
- * This component sets up the necessary services for managing products list state.
16
+ * Root component that provides both ProductList and ProductListSearch service contexts to its children.
17
+ * This component sets up the necessary services for managing products list state, including search,
18
+ * filtering, sorting, and pagination functionality.
15
19
  *
16
20
  * @order 1
17
21
  * @component
18
22
  * @example
19
23
  * ```tsx
20
- * import { ProductList } from '@wix/stores/components';
24
+ * import { ProductList, ProductListFilters, ProductListSort, ProductListPagination } from '@wix/stores/components';
21
25
  *
22
26
  * function ProductListPage() {
23
27
  * return (
@@ -28,7 +32,25 @@ export interface RootProps {
28
32
  * pagingMetadata: { count: 10, hasNext: true },
29
33
  * aggregations: {}
30
34
  * }}
35
+ * productsListSearchConfig={{
36
+ * customizations: [],
37
+ * initialSearchState: { sort: 'name_asc', limit: 20 }
38
+ * }}
31
39
  * >
40
+ * <ProductListSort.Options>
41
+ * {({ selectedSortOption, updateSortOption, sortOptions }) => (
42
+ * <select value={selectedSortOption} onChange={(e) => updateSortOption(e.target.value)}>
43
+ * {sortOptions.map(option => <option key={option} value={option}>{option}</option>)}
44
+ * </select>
45
+ * )}
46
+ * </ProductListSort.Options>
47
+ *
48
+ * <ProductListFilters.PriceRange>
49
+ * {({ selectedMinPrice, setSelectedMinPrice }) => (
50
+ * <input value={selectedMinPrice} onChange={(e) => setSelectedMinPrice(Number(e.target.value))} />
51
+ * )}
52
+ * </ProductListFilters.PriceRange>
53
+ *
32
54
  * <ProductList.ItemContent>
33
55
  * {({ product }) => (
34
56
  * <div key={product._id}>
@@ -37,6 +59,12 @@ export interface RootProps {
37
59
  * </div>
38
60
  * )}
39
61
  * </ProductList.ItemContent>
62
+ *
63
+ * <ProductListPagination.NextPageTrigger>
64
+ * {({ nextPage, hasNextPage }) => (
65
+ * <button onClick={nextPage} disabled={!hasNextPage}>Next</button>
66
+ * )}
67
+ * </ProductListPagination.NextPageTrigger>
40
68
  * </ProductList.Root>
41
69
  * );
42
70
  * }
@@ -2,16 +2,18 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useService, WixServices } from "@wix/services-manager-react";
3
3
  import { createServicesMap } from "@wix/services-manager";
4
4
  import { ProductListService, ProductsListServiceDefinition, } from "../services/products-list-service.js";
5
- import { ProductService, ProductServiceDefinition, } from "@wix/headless-stores/services";
5
+ import { ProductService, ProductServiceDefinition, } from "../services/product-service.js";
6
+ import { ProductsListSearchService, ProductsListSearchServiceDefinition, } from "../services/products-list-search-service.js";
6
7
  /**
7
- * Root component that provides the ProductList service context to its children.
8
- * This component sets up the necessary services for managing products list state.
8
+ * Root component that provides both ProductList and ProductListSearch service contexts to its children.
9
+ * This component sets up the necessary services for managing products list state, including search,
10
+ * filtering, sorting, and pagination functionality.
9
11
  *
10
12
  * @order 1
11
13
  * @component
12
14
  * @example
13
15
  * ```tsx
14
- * import { ProductList } from '@wix/stores/components';
16
+ * import { ProductList, ProductListFilters, ProductListSort, ProductListPagination } from '@wix/stores/components';
15
17
  *
16
18
  * function ProductListPage() {
17
19
  * return (
@@ -22,7 +24,25 @@ import { ProductService, ProductServiceDefinition, } from "@wix/headless-stores/
22
24
  * pagingMetadata: { count: 10, hasNext: true },
23
25
  * aggregations: {}
24
26
  * }}
27
+ * productsListSearchConfig={{
28
+ * customizations: [],
29
+ * initialSearchState: { sort: 'name_asc', limit: 20 }
30
+ * }}
25
31
  * >
32
+ * <ProductListSort.Options>
33
+ * {({ selectedSortOption, updateSortOption, sortOptions }) => (
34
+ * <select value={selectedSortOption} onChange={(e) => updateSortOption(e.target.value)}>
35
+ * {sortOptions.map(option => <option key={option} value={option}>{option}</option>)}
36
+ * </select>
37
+ * )}
38
+ * </ProductListSort.Options>
39
+ *
40
+ * <ProductListFilters.PriceRange>
41
+ * {({ selectedMinPrice, setSelectedMinPrice }) => (
42
+ * <input value={selectedMinPrice} onChange={(e) => setSelectedMinPrice(Number(e.target.value))} />
43
+ * )}
44
+ * </ProductListFilters.PriceRange>
45
+ *
26
46
  * <ProductList.ItemContent>
27
47
  * {({ product }) => (
28
48
  * <div key={product._id}>
@@ -31,13 +51,21 @@ import { ProductService, ProductServiceDefinition, } from "@wix/headless-stores/
31
51
  * </div>
32
52
  * )}
33
53
  * </ProductList.ItemContent>
54
+ *
55
+ * <ProductListPagination.NextPageTrigger>
56
+ * {({ nextPage, hasNextPage }) => (
57
+ * <button onClick={nextPage} disabled={!hasNextPage}>Next</button>
58
+ * )}
59
+ * </ProductListPagination.NextPageTrigger>
34
60
  * </ProductList.Root>
35
61
  * );
36
62
  * }
37
63
  * ```
38
64
  */
39
65
  export function Root(props) {
40
- return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ProductsListServiceDefinition, ProductListService, props.productsListConfig), children: props.children }));
66
+ return (_jsx(WixServices, { servicesMap: createServicesMap()
67
+ .addService(ProductsListServiceDefinition, ProductListService, props.productsListConfig)
68
+ .addService(ProductsListSearchServiceDefinition, ProductsListSearchService, props.productsListSearchConfig), children: props.children }));
41
69
  }
42
70
  /**
43
71
  * Component that renders content when the products list is empty.
@@ -1,45 +1,5 @@
1
1
  import type { ReactNode } from "react";
2
- import { InventoryStatusType, type ProductOption, ProductsListFiltersServiceConfig } from "../services/products-list-filters-service.js";
3
- export interface RootProps {
4
- /** Child components that will have access to the ProductListFilters service */
5
- children: React.ReactNode;
6
- /** Configuration for the ProductListFilters service */
7
- productsListFiltersConfig: ProductsListFiltersServiceConfig;
8
- }
9
- /**
10
- * Root component that provides the ProductListFilters service context to its children.
11
- * This component sets up the necessary services for managing products list filters.
12
- *
13
- * @order 1
14
- * @component
15
- * @example
16
- * ```tsx
17
- * import { ProductListFilters } from '@wix/stores/components';
18
- *
19
- * function FiltersSection() {
20
- * return (
21
- * <ProductListFilters.Root
22
- * productsListFiltersConfig={{
23
- * minPrice: 0,
24
- * maxPrice: 1000
25
- * }}
26
- * >
27
- * <ProductListFilters.MinPrice>
28
- * {({ minPrice, setSelectedMinPrice }) => (
29
- * <input
30
- * type="number"
31
- * value={minPrice}
32
- * onChange={(e) => setSelectedMinPrice(Number(e.target.value))}
33
- * placeholder="Min price"
34
- * />
35
- * )}
36
- * </ProductListFilters.MinPrice>
37
- * </ProductListFilters.Root>
38
- * );
39
- * }
40
- * ```
41
- */
42
- export declare function Root(props: RootProps): React.ReactNode;
2
+ import { type ProductOption, InventoryStatusType } from "../services/products-list-search-service.js";
43
3
  /**
44
4
  * Props for InventoryStatus headless component
45
5
  */
@@ -64,27 +24,32 @@ export interface InventoryStatusRenderProps {
64
24
  * @component
65
25
  * @example
66
26
  * ```tsx
67
- * import { ProductListFilters } from '@wix/stores/components';
27
+ * import { ProductList, ProductListFilters } from '@wix/stores/components';
68
28
  *
69
29
  * function InventoryStatusFilter() {
70
30
  * return (
71
- * <ProductListFilters.InventoryStatus>
72
- * {({ availableInventoryStatuses, selectedInventoryStatuses, toggleInventoryStatus }) => (
73
- * <div>
74
- * <h4>Inventory Status:</h4>
75
- * {availableInventoryStatuses.map(status => (
76
- * <label key={status}>
77
- * <input
78
- * type="checkbox"
79
- * checked={selectedInventoryStatuses.includes(status)}
80
- * onChange={() => toggleInventoryStatus(status)}
81
- * />
82
- * {status}
83
- * </label>
84
- * ))}
85
- * </div>
86
- * )}
87
- * </ProductListFilters.InventoryStatus>
31
+ * <ProductList.Root
32
+ * productsListConfig={{ products: [], searchOptions: {}, pagingMetadata: {}, aggregations: {} }}
33
+ * productsListSearchConfig={{ customizations: [] }}
34
+ * >
35
+ * <ProductListFilters.InventoryStatus>
36
+ * {({ availableInventoryStatuses, selectedInventoryStatuses, toggleInventoryStatus }) => (
37
+ * <div>
38
+ * <h4>Inventory Status:</h4>
39
+ * {availableInventoryStatuses.map(status => (
40
+ * <label key={status}>
41
+ * <input
42
+ * type="checkbox"
43
+ * checked={selectedInventoryStatuses.includes(status)}
44
+ * onChange={() => toggleInventoryStatus(status)}
45
+ * />
46
+ * {status}
47
+ * </label>
48
+ * ))}
49
+ * </div>
50
+ * )}
51
+ * </ProductListFilters.InventoryStatus>
52
+ * </ProductList.Root>
88
53
  * );
89
54
  * }
90
55
  * ```
@@ -112,21 +77,26 @@ export interface ResetTriggerRenderProps {
112
77
  * @component
113
78
  * @example
114
79
  * ```tsx
115
- * import { ProductListFilters } from '@wix/stores/components';
80
+ * import { ProductList, ProductListFilters } from '@wix/stores/components';
116
81
  *
117
82
  * function ResetFiltersButton() {
118
83
  * return (
119
- * <ProductListFilters.ResetTrigger>
120
- * {({ resetFilters, isFiltered }) => (
121
- * <button
122
- * onClick={resetFilters}
123
- * disabled={!isFiltered}
124
- * className={isFiltered ? 'active' : 'disabled'}
125
- * >
126
- * {isFiltered ? 'Clear Filters' : 'No Filters Applied'}
127
- * </button>
128
- * )}
129
- * </ProductListFilters.ResetTrigger>
84
+ * <ProductList.Root
85
+ * productsListConfig={{ products: [], searchOptions: {}, pagingMetadata: {}, aggregations: {} }}
86
+ * productsListSearchConfig={{ customizations: [] }}
87
+ * >
88
+ * <ProductListFilters.ResetTrigger>
89
+ * {({ resetFilters, isFiltered }) => (
90
+ * <button
91
+ * onClick={resetFilters}
92
+ * disabled={!isFiltered}
93
+ * className={isFiltered ? 'active' : 'disabled'}
94
+ * >
95
+ * {isFiltered ? 'Clear Filters' : 'No Filters Applied'}
96
+ * </button>
97
+ * )}
98
+ * </ProductListFilters.ResetTrigger>
99
+ * </ProductList.Root>
130
100
  * );
131
101
  * }
132
102
  * ```
@@ -162,32 +132,37 @@ export interface PriceRangeRenderProps {
162
132
  * @component
163
133
  * @example
164
134
  * ```tsx
165
- * import { ProductListFilters } from '@wix/stores/components';
135
+ * import { ProductList, ProductListFilters } from '@wix/stores/components';
166
136
  *
167
137
  * function PriceRangeFilter() {
168
138
  * return (
169
- * <ProductListFilters.PriceRange>
170
- * {({ minPrice, maxPrice, setSelectedMinPrice, setSelectedMaxPrice }) => (
171
- * <div className="price-range">
172
- * <h4>Price Range:</h4>
173
- * <div className="price-inputs">
174
- * <input
175
- * type="number"
176
- * value={minPrice}
177
- * onChange={(e) => setSelectedMinPrice(Number(e.target.value))}
178
- * placeholder="Min"
179
- * />
180
- * <span>to</span>
181
- * <input
182
- * type="number"
183
- * value={maxPrice}
184
- * onChange={(e) => setSelectedMaxPrice(Number(e.target.value))}
185
- * placeholder="Max"
186
- * />
139
+ * <ProductList.Root
140
+ * productsListConfig={{ products: [], searchOptions: {}, pagingMetadata: {}, aggregations: {} }}
141
+ * productsListSearchConfig={{ customizations: [] }}
142
+ * >
143
+ * <ProductListFilters.PriceRange>
144
+ * {({ minPrice, maxPrice, setSelectedMinPrice, setSelectedMaxPrice }) => (
145
+ * <div className="price-range">
146
+ * <h4>Price Range:</h4>
147
+ * <div className="price-inputs">
148
+ * <input
149
+ * type="number"
150
+ * value={minPrice}
151
+ * onChange={(e) => setSelectedMinPrice(Number(e.target.value))}
152
+ * placeholder="Min"
153
+ * />
154
+ * <span>to</span>
155
+ * <input
156
+ * type="number"
157
+ * value={maxPrice}
158
+ * onChange={(e) => setSelectedMaxPrice(Number(e.target.value))}
159
+ * placeholder="Max"
160
+ * />
161
+ * </div>
187
162
  * </div>
188
- * </div>
189
- * )}
190
- * </ProductListFilters.PriceRange>
163
+ * )}
164
+ * </ProductListFilters.PriceRange>
165
+ * </ProductList.Root>
191
166
  * );
192
167
  * }
193
168
  * ```
@@ -220,27 +195,32 @@ export interface ProductOptionRenderProps {
220
195
  * @component
221
196
  * @example
222
197
  * ```tsx
223
- * import { ProductListFilters } from '@wix/stores/components';
198
+ * import { ProductList, ProductListFilters } from '@wix/stores/components';
224
199
  *
225
200
  * function ProductOptionsFilter() {
226
201
  * return (
227
- * <ProductListFilters.ProductOptions>
228
- * {({ option, selectedChoices, toggleChoice }) => (
229
- * <div key={option.id}>
230
- * <h4>{option.name}</h4>
231
- * {option.choices.map(choice => (
232
- * <label key={choice.id}>
233
- * <input
234
- * type="checkbox"
235
- * checked={selectedChoices.includes(choice.id)}
236
- * onChange={() => toggleChoice(choice.id)}
237
- * />
238
- * {choice.name}
239
- * </label>
240
- * ))}
241
- * </div>
242
- * )}
243
- * </ProductListFilters.ProductOptions>
202
+ * <ProductList.Root
203
+ * productsListConfig={{ products: [], searchOptions: {}, pagingMetadata: {}, aggregations: {} }}
204
+ * productsListSearchConfig={{ customizations: [] }}
205
+ * >
206
+ * <ProductListFilters.ProductOptions>
207
+ * {({ option, selectedChoices, toggleChoice }) => (
208
+ * <div key={option.id}>
209
+ * <h4>{option.name}</h4>
210
+ * {option.choices.map(choice => (
211
+ * <label key={choice.id}>
212
+ * <input
213
+ * type="checkbox"
214
+ * checked={selectedChoices.includes(choice.id)}
215
+ * onChange={() => toggleChoice(choice.id)}
216
+ * />
217
+ * {choice.name}
218
+ * </label>
219
+ * ))}
220
+ * </div>
221
+ * )}
222
+ * </ProductListFilters.ProductOptions>
223
+ * </ProductList.Root>
244
224
  * );
245
225
  * }
246
226
  * ```