@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.
- package/cjs/dist/react/ProductList.d.ts +31 -3
- package/cjs/dist/react/ProductList.js +33 -5
- package/cjs/dist/react/ProductListFilters.d.ts +91 -111
- package/cjs/dist/react/ProductListFilters.js +98 -115
- package/cjs/dist/react/ProductListPagination.d.ts +89 -96
- package/cjs/dist/react/ProductListPagination.js +96 -104
- package/cjs/dist/react/ProductListSort.d.ts +26 -57
- package/cjs/dist/react/ProductListSort.js +26 -58
- package/cjs/dist/services/index.d.ts +1 -3
- package/cjs/dist/services/index.js +1 -3
- package/cjs/dist/services/products-list-search-service.d.ts +219 -0
- package/cjs/dist/services/products-list-search-service.js +794 -0
- package/cjs/dist/services/products-list-service.d.ts +28 -11
- package/cjs/dist/services/products-list-service.js +26 -6
- package/dist/react/ProductList.d.ts +31 -3
- package/dist/react/ProductList.js +33 -5
- package/dist/react/ProductListFilters.d.ts +91 -111
- package/dist/react/ProductListFilters.js +98 -115
- package/dist/react/ProductListPagination.d.ts +89 -96
- package/dist/react/ProductListPagination.js +96 -104
- package/dist/react/ProductListSort.d.ts +26 -57
- package/dist/react/ProductListSort.js +26 -58
- package/dist/services/index.d.ts +1 -3
- package/dist/services/index.js +1 -3
- package/dist/services/products-list-search-service.d.ts +219 -0
- package/dist/services/products-list-search-service.js +794 -0
- package/dist/services/products-list-service.d.ts +28 -11
- package/dist/services/products-list-service.js +26 -6
- package/package.json +2 -2
- package/cjs/dist/services/products-list-filters-service.d.ts +0 -309
- package/cjs/dist/services/products-list-filters-service.js +0 -504
- package/cjs/dist/services/products-list-pagination-service.d.ts +0 -186
- package/cjs/dist/services/products-list-pagination-service.js +0 -179
- package/cjs/dist/services/products-list-sort-service.d.ts +0 -117
- package/cjs/dist/services/products-list-sort-service.js +0 -144
- package/dist/services/products-list-filters-service.d.ts +0 -309
- package/dist/services/products-list-filters-service.js +0 -504
- package/dist/services/products-list-pagination-service.d.ts +0 -186
- package/dist/services/products-list-pagination-service.js +0 -179
- package/dist/services/products-list-sort-service.d.ts +0 -117
- package/dist/services/products-list-sort-service.js +0 -144
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
2
|
import { productsV3 } from "@wix/stores";
|
|
3
|
+
export declare const DEFAULT_QUERY_LIMIT = 100;
|
|
3
4
|
/**
|
|
4
5
|
* Configuration interface for the Products List service.
|
|
5
6
|
* Contains the initial products data, search options, and metadata.
|
|
@@ -10,7 +11,7 @@ export type ProductsListServiceConfig = {
|
|
|
10
11
|
/** Array of product objects to initialize the service with */
|
|
11
12
|
products: productsV3.V3Product[];
|
|
12
13
|
/** Search options used to fetch the products */
|
|
13
|
-
searchOptions:
|
|
14
|
+
searchOptions: productsV3.V3ProductSearch;
|
|
14
15
|
/** Pagination metadata from the search response */
|
|
15
16
|
pagingMetadata: productsV3.CommonCursorPagingMetadata;
|
|
16
17
|
/** Aggregation data containing filters, facets, and counts */
|
|
@@ -21,7 +22,7 @@ export type ProductsListServiceConfig = {
|
|
|
21
22
|
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
22
23
|
* a list of products based on search criteria.
|
|
23
24
|
*
|
|
24
|
-
* @param {
|
|
25
|
+
* @param {productsV3.V3ProductSearch} searchOptions - The search options for querying products
|
|
25
26
|
* @returns {Promise<ProductsListServiceConfig>} Promise that resolves to the products list configuration
|
|
26
27
|
*
|
|
27
28
|
* @example
|
|
@@ -99,7 +100,7 @@ export type ProductsListServiceConfig = {
|
|
|
99
100
|
* }
|
|
100
101
|
* ```
|
|
101
102
|
*/
|
|
102
|
-
export declare function loadProductsListServiceConfig(searchOptions:
|
|
103
|
+
export declare function loadProductsListServiceConfig(searchOptions: productsV3.V3ProductSearch): Promise<ProductsListServiceConfig>;
|
|
103
104
|
/**
|
|
104
105
|
* Service definition for the Products List service.
|
|
105
106
|
* This defines the reactive API contract for managing a list of products with search, pagination, and filtering capabilities.
|
|
@@ -115,13 +116,17 @@ export declare const ProductsListServiceDefinition: string & {
|
|
|
115
116
|
/** Reactive signal containing pagination metadata */
|
|
116
117
|
pagingMetadata: Signal<productsV3.CommonCursorPagingMetadata>;
|
|
117
118
|
/** Reactive signal containing current search options */
|
|
118
|
-
searchOptions: Signal<
|
|
119
|
+
searchOptions: Signal<productsV3.V3ProductSearch>;
|
|
119
120
|
/** Reactive signal indicating if products are currently being loaded */
|
|
120
121
|
isLoading: Signal<boolean>;
|
|
121
122
|
/** Reactive signal containing any error message, or null if no error */
|
|
122
123
|
error: Signal<string | null>;
|
|
123
124
|
/** Function to update search options and trigger a new search */
|
|
124
|
-
setSearchOptions: (searchOptions:
|
|
125
|
+
setSearchOptions: (searchOptions: productsV3.V3ProductSearch) => void;
|
|
126
|
+
/** Function to update only the sort part of search options */
|
|
127
|
+
setSort: (sort: productsV3.V3ProductSearch["sort"]) => void;
|
|
128
|
+
/** Function to update only the filter part of search options */
|
|
129
|
+
setFilter: (filter: productsV3.V3ProductSearch["filter"]) => void;
|
|
125
130
|
};
|
|
126
131
|
__config: ProductsListServiceConfig;
|
|
127
132
|
isServiceDefinition?: boolean;
|
|
@@ -133,13 +138,17 @@ export declare const ProductsListServiceDefinition: string & {
|
|
|
133
138
|
/** Reactive signal containing pagination metadata */
|
|
134
139
|
pagingMetadata: Signal<productsV3.CommonCursorPagingMetadata>;
|
|
135
140
|
/** Reactive signal containing current search options */
|
|
136
|
-
searchOptions: Signal<
|
|
141
|
+
searchOptions: Signal<productsV3.V3ProductSearch>;
|
|
137
142
|
/** Reactive signal indicating if products are currently being loaded */
|
|
138
143
|
isLoading: Signal<boolean>;
|
|
139
144
|
/** Reactive signal containing any error message, or null if no error */
|
|
140
145
|
error: Signal<string | null>;
|
|
141
146
|
/** Function to update search options and trigger a new search */
|
|
142
|
-
setSearchOptions: (searchOptions:
|
|
147
|
+
setSearchOptions: (searchOptions: productsV3.V3ProductSearch) => void;
|
|
148
|
+
/** Function to update only the sort part of search options */
|
|
149
|
+
setSort: (sort: productsV3.V3ProductSearch["sort"]) => void;
|
|
150
|
+
/** Function to update only the filter part of search options */
|
|
151
|
+
setFilter: (filter: productsV3.V3ProductSearch["filter"]) => void;
|
|
143
152
|
};
|
|
144
153
|
/**
|
|
145
154
|
* Implementation of the Products List service that manages reactive products data.
|
|
@@ -204,13 +213,17 @@ export declare const ProductListService: import("@wix/services-definitions").Ser
|
|
|
204
213
|
/** Reactive signal containing pagination metadata */
|
|
205
214
|
pagingMetadata: Signal<productsV3.CommonCursorPagingMetadata>;
|
|
206
215
|
/** Reactive signal containing current search options */
|
|
207
|
-
searchOptions: Signal<
|
|
216
|
+
searchOptions: Signal<productsV3.V3ProductSearch>;
|
|
208
217
|
/** Reactive signal indicating if products are currently being loaded */
|
|
209
218
|
isLoading: Signal<boolean>;
|
|
210
219
|
/** Reactive signal containing any error message, or null if no error */
|
|
211
220
|
error: Signal<string | null>;
|
|
212
221
|
/** Function to update search options and trigger a new search */
|
|
213
|
-
setSearchOptions: (searchOptions:
|
|
222
|
+
setSearchOptions: (searchOptions: productsV3.V3ProductSearch) => void;
|
|
223
|
+
/** Function to update only the sort part of search options */
|
|
224
|
+
setSort: (sort: productsV3.V3ProductSearch["sort"]) => void;
|
|
225
|
+
/** Function to update only the filter part of search options */
|
|
226
|
+
setFilter: (filter: productsV3.V3ProductSearch["filter"]) => void;
|
|
214
227
|
};
|
|
215
228
|
__config: ProductsListServiceConfig;
|
|
216
229
|
isServiceDefinition?: boolean;
|
|
@@ -222,11 +235,15 @@ export declare const ProductListService: import("@wix/services-definitions").Ser
|
|
|
222
235
|
/** Reactive signal containing pagination metadata */
|
|
223
236
|
pagingMetadata: Signal<productsV3.CommonCursorPagingMetadata>;
|
|
224
237
|
/** Reactive signal containing current search options */
|
|
225
|
-
searchOptions: Signal<
|
|
238
|
+
searchOptions: Signal<productsV3.V3ProductSearch>;
|
|
226
239
|
/** Reactive signal indicating if products are currently being loaded */
|
|
227
240
|
isLoading: Signal<boolean>;
|
|
228
241
|
/** Reactive signal containing any error message, or null if no error */
|
|
229
242
|
error: Signal<string | null>;
|
|
230
243
|
/** Function to update search options and trigger a new search */
|
|
231
|
-
setSearchOptions: (searchOptions:
|
|
244
|
+
setSearchOptions: (searchOptions: productsV3.V3ProductSearch) => void;
|
|
245
|
+
/** Function to update only the sort part of search options */
|
|
246
|
+
setSort: (sort: productsV3.V3ProductSearch["sort"]) => void;
|
|
247
|
+
/** Function to update only the filter part of search options */
|
|
248
|
+
setFilter: (filter: productsV3.V3ProductSearch["filter"]) => void;
|
|
232
249
|
}, ProductsListServiceConfig>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
2
|
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
3
|
import { productsV3, readOnlyVariantsV3 } from "@wix/stores";
|
|
4
|
+
export const DEFAULT_QUERY_LIMIT = 100;
|
|
4
5
|
/**
|
|
5
6
|
* Loads products list service configuration from the Wix Stores API for SSR initialization.
|
|
6
7
|
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
7
8
|
* a list of products based on search criteria.
|
|
8
9
|
*
|
|
9
|
-
* @param {
|
|
10
|
+
* @param {productsV3.V3ProductSearch} searchOptions - The search options for querying products
|
|
10
11
|
* @returns {Promise<ProductsListServiceConfig>} Promise that resolves to the products list configuration
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
@@ -85,12 +86,17 @@ import { productsV3, readOnlyVariantsV3 } from "@wix/stores";
|
|
|
85
86
|
* ```
|
|
86
87
|
*/
|
|
87
88
|
export async function loadProductsListServiceConfig(searchOptions) {
|
|
88
|
-
const
|
|
89
|
+
const searchWithoutFilter = { ...searchOptions, filter: {} };
|
|
90
|
+
const [resultWithoutFilter, resultWithFilter] = await Promise.all([
|
|
91
|
+
fetchProducts(searchWithoutFilter),
|
|
92
|
+
fetchProducts(searchOptions),
|
|
93
|
+
]);
|
|
94
|
+
const products = resultWithFilter?.products ?? resultWithoutFilter?.products ?? [];
|
|
89
95
|
return {
|
|
90
|
-
products
|
|
96
|
+
products,
|
|
91
97
|
searchOptions,
|
|
92
|
-
pagingMetadata:
|
|
93
|
-
aggregations:
|
|
98
|
+
pagingMetadata: resultWithFilter.pagingMetadata,
|
|
99
|
+
aggregations: resultWithoutFilter.aggregationData ?? {},
|
|
94
100
|
};
|
|
95
101
|
}
|
|
96
102
|
/**
|
|
@@ -136,7 +142,7 @@ const fetchMissingVariants = async (products) => {
|
|
|
136
142
|
const res = await readOnlyVariantsV3
|
|
137
143
|
.queryVariants({})
|
|
138
144
|
.in("productData.productId", productIds)
|
|
139
|
-
.limit(
|
|
145
|
+
.limit(DEFAULT_QUERY_LIMIT)
|
|
140
146
|
.find();
|
|
141
147
|
items.push(...res.items);
|
|
142
148
|
let nextRes = res;
|
|
@@ -284,6 +290,20 @@ export const ProductListService = implementService.withConfig()(ProductsListServ
|
|
|
284
290
|
pagingMetadata: pagingMetadataSignal,
|
|
285
291
|
aggregations: aggregationsSignal,
|
|
286
292
|
setSearchOptions: (searchOptions) => searchOptionsSignal.set(searchOptions),
|
|
293
|
+
setSort: (sort) => {
|
|
294
|
+
const currentOptions = searchOptionsSignal.peek();
|
|
295
|
+
searchOptionsSignal.set({
|
|
296
|
+
...currentOptions,
|
|
297
|
+
sort,
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
setFilter: (filter) => {
|
|
301
|
+
const currentOptions = searchOptionsSignal.peek();
|
|
302
|
+
searchOptionsSignal.set({
|
|
303
|
+
...currentOptions,
|
|
304
|
+
filter,
|
|
305
|
+
});
|
|
306
|
+
},
|
|
287
307
|
isLoading: isLoadingSignal,
|
|
288
308
|
error: errorSignal,
|
|
289
309
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-stores",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@wix/auto_sdk_stores_inventory-items-v-3": "^1.0.26",
|
|
57
57
|
"@wix/auto_sdk_stores_products-v-3": "^1.0.53",
|
|
58
58
|
"@wix/auto_sdk_stores_read-only-variants-v-3": "^1.0.23",
|
|
59
|
-
"@wix/ecom": "^1.0.
|
|
59
|
+
"@wix/ecom": "^1.0.1278",
|
|
60
60
|
"@wix/essentials": "^0.1.24",
|
|
61
61
|
"@wix/headless-ecom": "^0.0.11",
|
|
62
62
|
"@wix/headless-media": "^0.0.8",
|
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
|
-
import { customizationsV3 } from "@wix/stores";
|
|
3
|
-
/**
|
|
4
|
-
* Interface representing a product option (like Size, Color, etc.).
|
|
5
|
-
* Contains the option metadata and available choices.
|
|
6
|
-
*
|
|
7
|
-
* @interface ProductOption
|
|
8
|
-
*/
|
|
9
|
-
export interface ProductOption {
|
|
10
|
-
/** Unique identifier for the product option */
|
|
11
|
-
id: string;
|
|
12
|
-
/** Display name of the option (e.g., "Size", "Color") */
|
|
13
|
-
name: string;
|
|
14
|
-
/** Array of available choices for this option */
|
|
15
|
-
choices: ProductChoice[];
|
|
16
|
-
/** Optional render type for UI display purposes */
|
|
17
|
-
optionRenderType?: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Interface representing a choice within a product option.
|
|
21
|
-
* For example, "Red" would be a choice within a "Color" option.
|
|
22
|
-
*
|
|
23
|
-
* @interface ProductChoice
|
|
24
|
-
*/
|
|
25
|
-
export interface ProductChoice {
|
|
26
|
-
/** Unique identifier for the choice */
|
|
27
|
-
id: string;
|
|
28
|
-
/** Display name of the choice (e.g., "Red", "Large") */
|
|
29
|
-
name: string;
|
|
30
|
-
/** Optional color code for color-based choices */
|
|
31
|
-
colorCode?: string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Enumeration of inventory status types available for filtering.
|
|
35
|
-
* Maps to the Wix Stores API inventory availability statuses.
|
|
36
|
-
*
|
|
37
|
-
* @enum {string}
|
|
38
|
-
*/
|
|
39
|
-
export declare enum InventoryStatusType {
|
|
40
|
-
/** Product is in stock and available for purchase */
|
|
41
|
-
IN_STOCK = "IN_STOCK",
|
|
42
|
-
/** Product is out of stock */
|
|
43
|
-
OUT_OF_STOCK = "OUT_OF_STOCK",
|
|
44
|
-
/** Product is partially out of stock (some variants available) */
|
|
45
|
-
PARTIALLY_OUT_OF_STOCK = "PARTIALLY_OUT_OF_STOCK"
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Configuration interface for the Products List Filters service.
|
|
49
|
-
* Contains customizations data used to build filter options.
|
|
50
|
-
*
|
|
51
|
-
* @interface ProductsListFiltersServiceConfig
|
|
52
|
-
*/
|
|
53
|
-
export type ProductsListFiltersServiceConfig = {
|
|
54
|
-
/** Array of product customizations for building filter options */
|
|
55
|
-
customizations: customizationsV3.Customization[];
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Loads products list filters service configuration from the Wix Stores API for SSR initialization.
|
|
59
|
-
* This function fetches customization data that will be used to build product filter options.
|
|
60
|
-
*
|
|
61
|
-
* @returns {Promise<ProductsListFiltersServiceConfig>} Promise that resolves to the filters configuration
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```astro
|
|
65
|
-
* ---
|
|
66
|
-
* // Astro page example - pages/products.astro
|
|
67
|
-
* import { loadProductsListFiltersServiceConfig } from '@wix/stores/services';
|
|
68
|
-
* import { ProductsListFilters } from '@wix/stores/components';
|
|
69
|
-
*
|
|
70
|
-
* // Load filters configuration during SSR
|
|
71
|
-
* const filtersConfig = await loadProductsListFiltersServiceConfig();
|
|
72
|
-
* ---
|
|
73
|
-
*
|
|
74
|
-
* <ProductsListFilters.Root filtersConfig={filtersConfig}>
|
|
75
|
-
* <ProductsListFilters.MinPrice>
|
|
76
|
-
* {({ minPrice, setMinPrice }) => (
|
|
77
|
-
* <input
|
|
78
|
-
* type="number"
|
|
79
|
-
* value={minPrice}
|
|
80
|
-
* onChange={(e) => setMinPrice(parseFloat(e.target.value))}
|
|
81
|
-
* placeholder="Min Price"
|
|
82
|
-
* />
|
|
83
|
-
* )}
|
|
84
|
-
* </ProductsListFilters.MinPrice>
|
|
85
|
-
* </ProductsListFilters.Root>
|
|
86
|
-
* ```
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```tsx
|
|
90
|
-
* // Next.js page example
|
|
91
|
-
* import { GetServerSideProps } from 'next';
|
|
92
|
-
* import { loadProductsListFiltersServiceConfig } from '@wix/stores/services';
|
|
93
|
-
*
|
|
94
|
-
* export const getServerSideProps: GetServerSideProps = async () => {
|
|
95
|
-
* const filtersConfig = await loadProductsListFiltersServiceConfig();
|
|
96
|
-
*
|
|
97
|
-
* return {
|
|
98
|
-
* props: {
|
|
99
|
-
* filtersConfig,
|
|
100
|
-
* },
|
|
101
|
-
* };
|
|
102
|
-
* };
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
export declare function loadProductsListFiltersServiceConfig(): Promise<ProductsListFiltersServiceConfig>;
|
|
106
|
-
/**
|
|
107
|
-
* Service definition for the Products List Filters service.
|
|
108
|
-
* This defines the reactive API contract for managing product list filtering capabilities
|
|
109
|
-
* including price, inventory status, and product option filters.
|
|
110
|
-
*
|
|
111
|
-
* @constant
|
|
112
|
-
*/
|
|
113
|
-
export declare const ProductsListFiltersServiceDefinition: string & {
|
|
114
|
-
__api: {
|
|
115
|
-
/** Reactive signal containing the user's selected minimum price filter value */
|
|
116
|
-
selectedMinPrice: Signal<number>;
|
|
117
|
-
/** Reactive signal containing the user's selected maximum price filter value */
|
|
118
|
-
selectedMaxPrice: Signal<number>;
|
|
119
|
-
/** Reactive signal containing the catalog minimum price (for UI bounds) */
|
|
120
|
-
availableMinPrice: Signal<number>;
|
|
121
|
-
/** Reactive signal containing the catalog maximum price (for UI bounds) */
|
|
122
|
-
availableMaxPrice: Signal<number>;
|
|
123
|
-
/** Reactive signal containing available inventory status options */
|
|
124
|
-
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
125
|
-
/** Reactive signal containing selected inventory status filters */
|
|
126
|
-
selectedInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
127
|
-
/** Reactive signal containing available product options for filtering */
|
|
128
|
-
availableProductOptions: Signal<ProductOption[]>;
|
|
129
|
-
/** Reactive signal containing selected product option filters */
|
|
130
|
-
selectedProductOptions: Signal<Record<string, string[]>>;
|
|
131
|
-
/** Function to set the minimum price filter */
|
|
132
|
-
setSelectedMinPrice: (minPrice: number) => void;
|
|
133
|
-
/** Function to set the maximum price filter */
|
|
134
|
-
setSelectedMaxPrice: (maxPrice: number) => void;
|
|
135
|
-
/** Function to toggle an inventory status filter */
|
|
136
|
-
toggleInventoryStatus: (status: InventoryStatusType) => void;
|
|
137
|
-
/** Function to toggle a product option choice filter */
|
|
138
|
-
toggleProductOption: (optionId: string, choiceId: string) => void;
|
|
139
|
-
/** Reactive signal indicating if any filters are currently applied */
|
|
140
|
-
isFiltered: Signal<boolean>;
|
|
141
|
-
/** Function to reset all filters to their default state */
|
|
142
|
-
reset: () => void;
|
|
143
|
-
};
|
|
144
|
-
__config: {};
|
|
145
|
-
isServiceDefinition?: boolean;
|
|
146
|
-
} & {
|
|
147
|
-
/** Reactive signal containing the user's selected minimum price filter value */
|
|
148
|
-
selectedMinPrice: Signal<number>;
|
|
149
|
-
/** Reactive signal containing the user's selected maximum price filter value */
|
|
150
|
-
selectedMaxPrice: Signal<number>;
|
|
151
|
-
/** Reactive signal containing the catalog minimum price (for UI bounds) */
|
|
152
|
-
availableMinPrice: Signal<number>;
|
|
153
|
-
/** Reactive signal containing the catalog maximum price (for UI bounds) */
|
|
154
|
-
availableMaxPrice: Signal<number>;
|
|
155
|
-
/** Reactive signal containing available inventory status options */
|
|
156
|
-
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
157
|
-
/** Reactive signal containing selected inventory status filters */
|
|
158
|
-
selectedInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
159
|
-
/** Reactive signal containing available product options for filtering */
|
|
160
|
-
availableProductOptions: Signal<ProductOption[]>;
|
|
161
|
-
/** Reactive signal containing selected product option filters */
|
|
162
|
-
selectedProductOptions: Signal<Record<string, string[]>>;
|
|
163
|
-
/** Function to set the minimum price filter */
|
|
164
|
-
setSelectedMinPrice: (minPrice: number) => void;
|
|
165
|
-
/** Function to set the maximum price filter */
|
|
166
|
-
setSelectedMaxPrice: (maxPrice: number) => void;
|
|
167
|
-
/** Function to toggle an inventory status filter */
|
|
168
|
-
toggleInventoryStatus: (status: InventoryStatusType) => void;
|
|
169
|
-
/** Function to toggle a product option choice filter */
|
|
170
|
-
toggleProductOption: (optionId: string, choiceId: string) => void;
|
|
171
|
-
/** Reactive signal indicating if any filters are currently applied */
|
|
172
|
-
isFiltered: Signal<boolean>;
|
|
173
|
-
/** Function to reset all filters to their default state */
|
|
174
|
-
reset: () => void;
|
|
175
|
-
};
|
|
176
|
-
/**
|
|
177
|
-
* Implementation of the Products List Filters service that manages reactive filtering state.
|
|
178
|
-
* This service provides signals for all filter types (price, inventory, product options) and
|
|
179
|
-
* automatically updates the products list search options when filters change.
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```tsx
|
|
183
|
-
* import { ProductsListFiltersService, ProductsListFiltersServiceDefinition } from '@wix/stores/services';
|
|
184
|
-
* import { useService } from '@wix/services-manager-react';
|
|
185
|
-
*
|
|
186
|
-
* function FiltersComponent({ filtersConfig }) {
|
|
187
|
-
* return (
|
|
188
|
-
* <ServiceProvider services={createServicesMap([
|
|
189
|
-
* [ProductsListFiltersServiceDefinition, ProductsListFiltersService.withConfig(filtersConfig)]
|
|
190
|
-
* ])}>
|
|
191
|
-
* <FilterControls />
|
|
192
|
-
* </ServiceProvider>
|
|
193
|
-
* );
|
|
194
|
-
* }
|
|
195
|
-
*
|
|
196
|
-
* function FilterControls() {
|
|
197
|
-
* const filtersService = useService(ProductsListFiltersServiceDefinition);
|
|
198
|
-
* const minPrice = filtersService.minPrice.get();
|
|
199
|
-
* const maxPrice = filtersService.maxPrice.get();
|
|
200
|
-
* const selectedInventoryStatuses = filtersService.selectedInventoryStatuses.get();
|
|
201
|
-
* const availableProductOptions = filtersService.availableProductOptions.get();
|
|
202
|
-
* const isFiltered = filtersService.isFiltered.get();
|
|
203
|
-
*
|
|
204
|
-
* return (
|
|
205
|
-
* <div>
|
|
206
|
-
* <div>
|
|
207
|
-
* <input
|
|
208
|
-
* type="number"
|
|
209
|
-
* value={minPrice}
|
|
210
|
-
* onChange={(e) => filtersService.setMinPrice(parseFloat(e.target.value))}
|
|
211
|
-
* placeholder="Min Price"
|
|
212
|
-
* />
|
|
213
|
-
* <input
|
|
214
|
-
* type="number"
|
|
215
|
-
* value={maxPrice}
|
|
216
|
-
* onChange={(e) => filtersService.setMaxPrice(parseFloat(e.target.value))}
|
|
217
|
-
* placeholder="Max Price"
|
|
218
|
-
* />
|
|
219
|
-
* </div>
|
|
220
|
-
*
|
|
221
|
-
* {availableProductOptions.map(option => (
|
|
222
|
-
* <div key={option.id}>
|
|
223
|
-
* <h4>{option.name}</h4>
|
|
224
|
-
* {option.choices.map(choice => (
|
|
225
|
-
* <label key={choice.id}>
|
|
226
|
-
* <input
|
|
227
|
-
* type="checkbox"
|
|
228
|
-
* onChange={() => filtersService.toggleProductOption(option.id, choice.id)}
|
|
229
|
-
* />
|
|
230
|
-
* {choice.name}
|
|
231
|
-
* </label>
|
|
232
|
-
* ))}
|
|
233
|
-
* </div>
|
|
234
|
-
* ))}
|
|
235
|
-
*
|
|
236
|
-
* {isFiltered && (
|
|
237
|
-
* <button onClick={() => filtersService.reset()}>
|
|
238
|
-
* Clear All Filters
|
|
239
|
-
* </button>
|
|
240
|
-
* )}
|
|
241
|
-
* </div>
|
|
242
|
-
* );
|
|
243
|
-
* }
|
|
244
|
-
* }
|
|
245
|
-
* ```
|
|
246
|
-
*/
|
|
247
|
-
export declare const ProductsListFiltersService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
248
|
-
__api: {
|
|
249
|
-
/** Reactive signal containing the user's selected minimum price filter value */
|
|
250
|
-
selectedMinPrice: Signal<number>;
|
|
251
|
-
/** Reactive signal containing the user's selected maximum price filter value */
|
|
252
|
-
selectedMaxPrice: Signal<number>;
|
|
253
|
-
/** Reactive signal containing the catalog minimum price (for UI bounds) */
|
|
254
|
-
availableMinPrice: Signal<number>;
|
|
255
|
-
/** Reactive signal containing the catalog maximum price (for UI bounds) */
|
|
256
|
-
availableMaxPrice: Signal<number>;
|
|
257
|
-
/** Reactive signal containing available inventory status options */
|
|
258
|
-
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
259
|
-
/** Reactive signal containing selected inventory status filters */
|
|
260
|
-
selectedInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
261
|
-
/** Reactive signal containing available product options for filtering */
|
|
262
|
-
availableProductOptions: Signal<ProductOption[]>;
|
|
263
|
-
/** Reactive signal containing selected product option filters */
|
|
264
|
-
selectedProductOptions: Signal<Record<string, string[]>>;
|
|
265
|
-
/** Function to set the minimum price filter */
|
|
266
|
-
setSelectedMinPrice: (minPrice: number) => void;
|
|
267
|
-
/** Function to set the maximum price filter */
|
|
268
|
-
setSelectedMaxPrice: (maxPrice: number) => void;
|
|
269
|
-
/** Function to toggle an inventory status filter */
|
|
270
|
-
toggleInventoryStatus: (status: InventoryStatusType) => void;
|
|
271
|
-
/** Function to toggle a product option choice filter */
|
|
272
|
-
toggleProductOption: (optionId: string, choiceId: string) => void;
|
|
273
|
-
/** Reactive signal indicating if any filters are currently applied */
|
|
274
|
-
isFiltered: Signal<boolean>;
|
|
275
|
-
/** Function to reset all filters to their default state */
|
|
276
|
-
reset: () => void;
|
|
277
|
-
};
|
|
278
|
-
__config: {};
|
|
279
|
-
isServiceDefinition?: boolean;
|
|
280
|
-
} & {
|
|
281
|
-
/** Reactive signal containing the user's selected minimum price filter value */
|
|
282
|
-
selectedMinPrice: Signal<number>;
|
|
283
|
-
/** Reactive signal containing the user's selected maximum price filter value */
|
|
284
|
-
selectedMaxPrice: Signal<number>;
|
|
285
|
-
/** Reactive signal containing the catalog minimum price (for UI bounds) */
|
|
286
|
-
availableMinPrice: Signal<number>;
|
|
287
|
-
/** Reactive signal containing the catalog maximum price (for UI bounds) */
|
|
288
|
-
availableMaxPrice: Signal<number>;
|
|
289
|
-
/** Reactive signal containing available inventory status options */
|
|
290
|
-
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
291
|
-
/** Reactive signal containing selected inventory status filters */
|
|
292
|
-
selectedInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
293
|
-
/** Reactive signal containing available product options for filtering */
|
|
294
|
-
availableProductOptions: Signal<ProductOption[]>;
|
|
295
|
-
/** Reactive signal containing selected product option filters */
|
|
296
|
-
selectedProductOptions: Signal<Record<string, string[]>>;
|
|
297
|
-
/** Function to set the minimum price filter */
|
|
298
|
-
setSelectedMinPrice: (minPrice: number) => void;
|
|
299
|
-
/** Function to set the maximum price filter */
|
|
300
|
-
setSelectedMaxPrice: (maxPrice: number) => void;
|
|
301
|
-
/** Function to toggle an inventory status filter */
|
|
302
|
-
toggleInventoryStatus: (status: InventoryStatusType) => void;
|
|
303
|
-
/** Function to toggle a product option choice filter */
|
|
304
|
-
toggleProductOption: (optionId: string, choiceId: string) => void;
|
|
305
|
-
/** Reactive signal indicating if any filters are currently applied */
|
|
306
|
-
isFiltered: Signal<boolean>;
|
|
307
|
-
/** Function to reset all filters to their default state */
|
|
308
|
-
reset: () => void;
|
|
309
|
-
}, ProductsListFiltersServiceConfig>;
|