@wix/headless-stores 0.0.36 → 0.0.37
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/Category.d.ts +65 -59
- package/cjs/dist/react/Category.js +50 -83
- package/cjs/dist/react/CategoryList.d.ts +184 -0
- package/cjs/dist/react/CategoryList.js +174 -0
- package/cjs/dist/react/Product.d.ts +3 -3
- package/cjs/dist/react/Product.js +6 -6
- package/cjs/dist/react/ProductActions.d.ts +1 -1
- package/cjs/dist/react/ProductActions.js +2 -2
- package/{dist/react/ProductsList.d.ts → cjs/dist/react/ProductList.d.ts} +71 -38
- package/cjs/dist/react/{ProductsList.js → ProductList.js} +30 -26
- package/cjs/dist/react/ProductListFilters.d.ts +244 -0
- package/cjs/dist/react/ProductListFilters.js +216 -0
- package/cjs/dist/react/ProductListPagination.d.ts +246 -0
- package/cjs/dist/react/ProductListPagination.js +207 -0
- package/cjs/dist/react/ProductListSort.d.ts +87 -0
- package/cjs/dist/react/ProductListSort.js +85 -0
- package/cjs/dist/react/ProductModifiers.d.ts +5 -5
- package/cjs/dist/react/ProductModifiers.js +10 -10
- package/cjs/dist/react/ProductVariantSelector.d.ts +5 -5
- package/cjs/dist/react/ProductVariantSelector.js +13 -10
- package/cjs/dist/react/SelectedVariant.d.ts +3 -3
- package/cjs/dist/react/SelectedVariant.js +6 -6
- package/cjs/dist/react/index.d.ts +7 -9
- package/cjs/dist/react/index.js +7 -9
- package/cjs/dist/services/buy-now-service.d.ts +208 -0
- package/cjs/dist/services/buy-now-service.js +132 -1
- package/cjs/dist/services/categories-list-service.d.ts +163 -0
- package/cjs/dist/services/categories-list-service.js +148 -0
- package/cjs/dist/services/category-service.d.ts +115 -70
- package/cjs/dist/services/category-service.js +101 -110
- package/cjs/dist/services/index.d.ts +6 -7
- package/cjs/dist/services/index.js +5 -16
- package/cjs/dist/services/pay-now-service.d.ts +146 -0
- package/cjs/dist/services/pay-now-service.js +112 -1
- package/cjs/dist/services/product-service.d.ts +71 -0
- package/cjs/dist/services/product-service.js +47 -0
- package/cjs/dist/services/products-list-filters-service.d.ts +292 -0
- package/cjs/dist/services/products-list-filters-service.js +446 -0
- package/cjs/dist/services/products-list-pagination-service.d.ts +186 -0
- package/cjs/dist/services/products-list-pagination-service.js +179 -0
- package/cjs/dist/services/products-list-service.d.ts +138 -52
- package/cjs/dist/services/products-list-service.js +98 -51
- package/cjs/dist/services/products-list-sort-service.d.ts +117 -0
- package/cjs/dist/services/products-list-sort-service.js +144 -0
- package/cjs/dist/utils/url-params.d.ts +68 -0
- package/cjs/dist/utils/url-params.js +72 -4
- package/dist/react/Category.d.ts +65 -59
- package/dist/react/Category.js +50 -83
- package/dist/react/CategoryList.d.ts +184 -0
- package/dist/react/CategoryList.js +174 -0
- package/dist/react/Product.d.ts +3 -3
- package/dist/react/Product.js +6 -6
- package/dist/react/ProductActions.d.ts +1 -1
- package/dist/react/ProductActions.js +2 -2
- package/{cjs/dist/react/ProductsList.d.ts → dist/react/ProductList.d.ts} +71 -38
- package/dist/react/{ProductsList.js → ProductList.js} +30 -26
- package/dist/react/ProductListFilters.d.ts +244 -0
- package/dist/react/ProductListFilters.js +216 -0
- package/dist/react/ProductListPagination.d.ts +246 -0
- package/dist/react/ProductListPagination.js +207 -0
- package/dist/react/ProductListSort.d.ts +87 -0
- package/dist/react/ProductListSort.js +85 -0
- package/dist/react/ProductModifiers.d.ts +5 -5
- package/dist/react/ProductModifiers.js +10 -10
- package/dist/react/ProductVariantSelector.d.ts +5 -5
- package/dist/react/ProductVariantSelector.js +13 -10
- package/dist/react/SelectedVariant.d.ts +3 -3
- package/dist/react/SelectedVariant.js +6 -6
- package/dist/react/index.d.ts +7 -9
- package/dist/react/index.js +7 -9
- package/dist/services/buy-now-service.d.ts +208 -0
- package/dist/services/buy-now-service.js +132 -1
- package/dist/services/categories-list-service.d.ts +163 -0
- package/dist/services/categories-list-service.js +148 -0
- package/dist/services/category-service.d.ts +115 -70
- package/dist/services/category-service.js +101 -110
- package/dist/services/index.d.ts +6 -7
- package/dist/services/index.js +5 -16
- package/dist/services/pay-now-service.d.ts +146 -0
- package/dist/services/pay-now-service.js +112 -1
- package/dist/services/product-service.d.ts +71 -0
- package/dist/services/product-service.js +47 -0
- package/dist/services/products-list-filters-service.d.ts +292 -0
- package/dist/services/products-list-filters-service.js +446 -0
- package/dist/services/products-list-pagination-service.d.ts +186 -0
- package/dist/services/products-list-pagination-service.js +179 -0
- package/dist/services/products-list-service.d.ts +138 -52
- package/dist/services/products-list-service.js +98 -51
- package/dist/services/products-list-sort-service.d.ts +117 -0
- package/dist/services/products-list-sort-service.js +144 -0
- package/dist/utils/url-params.d.ts +68 -0
- package/dist/utils/url-params.js +72 -4
- package/package.json +3 -3
- package/cjs/dist/react/Collection.d.ts +0 -294
- package/cjs/dist/react/Collection.js +0 -345
- package/cjs/dist/react/FilteredCollection.d.ts +0 -299
- package/cjs/dist/react/FilteredCollection.js +0 -352
- package/cjs/dist/react/RelatedProducts.d.ts +0 -169
- package/cjs/dist/react/RelatedProducts.js +0 -180
- package/cjs/dist/react/Sort.d.ts +0 -37
- package/cjs/dist/react/Sort.js +0 -36
- package/cjs/dist/services/catalog-service.d.ts +0 -36
- package/cjs/dist/services/catalog-service.js +0 -193
- package/cjs/dist/services/collection-service.d.ts +0 -124
- package/cjs/dist/services/collection-service.js +0 -628
- package/cjs/dist/services/filter-service.d.ts +0 -35
- package/cjs/dist/services/filter-service.js +0 -119
- package/cjs/dist/services/related-products-service.d.ts +0 -100
- package/cjs/dist/services/related-products-service.js +0 -127
- package/cjs/dist/services/sort-service.d.ts +0 -20
- package/cjs/dist/services/sort-service.js +0 -27
- package/dist/react/Collection.d.ts +0 -294
- package/dist/react/Collection.js +0 -345
- package/dist/react/FilteredCollection.d.ts +0 -299
- package/dist/react/FilteredCollection.js +0 -352
- package/dist/react/RelatedProducts.d.ts +0 -169
- package/dist/react/RelatedProducts.js +0 -180
- package/dist/react/Sort.d.ts +0 -37
- package/dist/react/Sort.js +0 -36
- package/dist/services/catalog-service.d.ts +0 -36
- package/dist/services/catalog-service.js +0 -193
- package/dist/services/collection-service.d.ts +0 -124
- package/dist/services/collection-service.js +0 -628
- package/dist/services/filter-service.d.ts +0 -35
- package/dist/services/filter-service.js +0 -119
- package/dist/services/related-products-service.d.ts +0 -100
- package/dist/services/related-products-service.js +0 -127
- package/dist/services/sort-service.d.ts +0 -20
- package/dist/services/sort-service.js +0 -27
|
@@ -1,29 +1,100 @@
|
|
|
1
1
|
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
2
|
import * as productsV3 from "@wix/auto_sdk_stores_products-v-3";
|
|
3
|
+
/**
|
|
4
|
+
* API interface for the Product service, providing reactive product data management.
|
|
5
|
+
* This service handles loading and managing a single product's data, loading state, and errors.
|
|
6
|
+
*
|
|
7
|
+
* @interface ProductServiceAPI
|
|
8
|
+
*/
|
|
3
9
|
export interface ProductServiceAPI {
|
|
10
|
+
/** Reactive signal containing the current product data */
|
|
4
11
|
product: Signal<productsV3.V3Product>;
|
|
12
|
+
/** Reactive signal indicating if a product is currently being loaded */
|
|
5
13
|
isLoading: Signal<boolean>;
|
|
14
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
6
15
|
error: Signal<string | null>;
|
|
16
|
+
/** Function to load a product by its slug */
|
|
7
17
|
loadProduct: (slug: string) => Promise<void>;
|
|
8
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Service definition for the Product service.
|
|
21
|
+
* This defines the contract that the ProductService must implement.
|
|
22
|
+
*
|
|
23
|
+
* @constant
|
|
24
|
+
*/
|
|
9
25
|
export declare const ProductServiceDefinition: string & {
|
|
10
26
|
__api: ProductServiceAPI;
|
|
11
27
|
__config: {};
|
|
12
28
|
isServiceDefinition?: boolean;
|
|
13
29
|
} & ProductServiceAPI;
|
|
30
|
+
/**
|
|
31
|
+
* Configuration interface required to initialize the ProductService.
|
|
32
|
+
* Contains the initial product data that will be loaded into the service.
|
|
33
|
+
*
|
|
34
|
+
* @interface ProductServiceConfig
|
|
35
|
+
*/
|
|
14
36
|
export interface ProductServiceConfig {
|
|
37
|
+
/** The initial product data to configure the service with */
|
|
15
38
|
product: productsV3.V3Product;
|
|
16
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Implementation of the Product service that manages reactive product data.
|
|
42
|
+
* This service provides signals for product data, loading state, and error handling,
|
|
43
|
+
* along with methods to dynamically load products.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* import { ProductService, ProductServiceDefinition } from '@wix/stores/services';
|
|
48
|
+
* import { useService } from '@wix/services-manager-react';
|
|
49
|
+
*
|
|
50
|
+
* function ProductComponent({ productConfig }) {
|
|
51
|
+
* return (
|
|
52
|
+
* <ServiceProvider services={createServicesMap([
|
|
53
|
+
* [ProductServiceDefinition, ProductService.withConfig(productConfig)]
|
|
54
|
+
* ])}>
|
|
55
|
+
* <ProductDisplay />
|
|
56
|
+
* </ServiceProvider>
|
|
57
|
+
* );
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* function ProductDisplay() {
|
|
61
|
+
* const productService = useService(ProductServiceDefinition);
|
|
62
|
+
* const product = productService.product.get();
|
|
63
|
+
* const isLoading = productService.isLoading.get();
|
|
64
|
+
* const error = productService.error.get();
|
|
65
|
+
*
|
|
66
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
67
|
+
* if (error) return <div>Error: {error}</div>;
|
|
68
|
+
*
|
|
69
|
+
* return <h1>{product.name}</h1>;
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
17
73
|
export declare const ProductService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
18
74
|
__api: ProductServiceAPI;
|
|
19
75
|
__config: {};
|
|
20
76
|
isServiceDefinition?: boolean;
|
|
21
77
|
} & ProductServiceAPI, ProductServiceConfig>;
|
|
78
|
+
/**
|
|
79
|
+
* Success result interface for product service configuration loading.
|
|
80
|
+
* Returned when a product is successfully found and loaded.
|
|
81
|
+
*
|
|
82
|
+
* @interface SuccessProductServiceConfigResult
|
|
83
|
+
*/
|
|
22
84
|
export interface SuccessProductServiceConfigResult {
|
|
85
|
+
/** Type "success" means that the product was found and the config is valid */
|
|
23
86
|
type: "success";
|
|
87
|
+
/** The product config containing the loaded product data */
|
|
24
88
|
config: ProductServiceConfig;
|
|
25
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Not found result interface for product service configuration loading.
|
|
92
|
+
* Returned when a product with the given slug cannot be found.
|
|
93
|
+
*
|
|
94
|
+
* @interface NotFoundProductServiceConfigResult
|
|
95
|
+
*/
|
|
26
96
|
export interface NotFoundProductServiceConfigResult {
|
|
97
|
+
/** Type "notFound" means that the product was not found */
|
|
27
98
|
type: "notFound";
|
|
28
99
|
}
|
|
29
100
|
/**
|
|
@@ -1,7 +1,46 @@
|
|
|
1
1
|
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
2
|
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
3
|
import * as productsV3 from "@wix/auto_sdk_stores_products-v-3";
|
|
4
|
+
/**
|
|
5
|
+
* Service definition for the Product service.
|
|
6
|
+
* This defines the contract that the ProductService must implement.
|
|
7
|
+
*
|
|
8
|
+
* @constant
|
|
9
|
+
*/
|
|
4
10
|
export const ProductServiceDefinition = defineService("product");
|
|
11
|
+
/**
|
|
12
|
+
* Implementation of the Product service that manages reactive product data.
|
|
13
|
+
* This service provides signals for product data, loading state, and error handling,
|
|
14
|
+
* along with methods to dynamically load products.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { ProductService, ProductServiceDefinition } from '@wix/stores/services';
|
|
19
|
+
* import { useService } from '@wix/services-manager-react';
|
|
20
|
+
*
|
|
21
|
+
* function ProductComponent({ productConfig }) {
|
|
22
|
+
* return (
|
|
23
|
+
* <ServiceProvider services={createServicesMap([
|
|
24
|
+
* [ProductServiceDefinition, ProductService.withConfig(productConfig)]
|
|
25
|
+
* ])}>
|
|
26
|
+
* <ProductDisplay />
|
|
27
|
+
* </ServiceProvider>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* function ProductDisplay() {
|
|
32
|
+
* const productService = useService(ProductServiceDefinition);
|
|
33
|
+
* const product = productService.product.get();
|
|
34
|
+
* const isLoading = productService.isLoading.get();
|
|
35
|
+
* const error = productService.error.get();
|
|
36
|
+
*
|
|
37
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
38
|
+
* if (error) return <div>Error: {error}</div>;
|
|
39
|
+
*
|
|
40
|
+
* return <h1>{product.name}</h1>;
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
5
44
|
export const ProductService = implementService.withConfig()(ProductServiceDefinition, ({ getService, config }) => {
|
|
6
45
|
const signalsService = getService(SignalsServiceDefinition);
|
|
7
46
|
const product = signalsService.signal(config.product);
|
|
@@ -26,6 +65,14 @@ export const ProductService = implementService.withConfig()(ProductServiceDefini
|
|
|
26
65
|
loadProduct,
|
|
27
66
|
};
|
|
28
67
|
});
|
|
68
|
+
/**
|
|
69
|
+
* Internal helper function to load a product by its slug from the Wix Products API.
|
|
70
|
+
* Fetches comprehensive product data including description, categories, media, etc.
|
|
71
|
+
*
|
|
72
|
+
* @private
|
|
73
|
+
* @param {string} slug - The product slug to load
|
|
74
|
+
* @returns {Promise} Product response from the API
|
|
75
|
+
*/
|
|
29
76
|
const loadProductBySlug = async (slug) => {
|
|
30
77
|
const productResponse = await productsV3.getProductBySlug(slug, {
|
|
31
78
|
fields: [
|
|
@@ -0,0 +1,292 @@
|
|
|
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 minimum price filter value */
|
|
116
|
+
minPrice: Signal<number>;
|
|
117
|
+
/** Reactive signal containing the maximum price filter value */
|
|
118
|
+
maxPrice: Signal<number>;
|
|
119
|
+
/** Reactive signal containing available inventory status options */
|
|
120
|
+
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
121
|
+
/** Reactive signal containing selected inventory status filters */
|
|
122
|
+
selectedInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
123
|
+
/** Reactive signal containing available product options for filtering */
|
|
124
|
+
availableProductOptions: Signal<ProductOption[]>;
|
|
125
|
+
/** Reactive signal containing selected product option filters */
|
|
126
|
+
selectedProductOptions: Signal<Record<string, string[]>>;
|
|
127
|
+
/** Function to set the minimum price filter */
|
|
128
|
+
setMinPrice: (minPrice: number) => void;
|
|
129
|
+
/** Function to set the maximum price filter */
|
|
130
|
+
setMaxPrice: (maxPrice: number) => void;
|
|
131
|
+
/** Function to toggle an inventory status filter */
|
|
132
|
+
toggleInventoryStatus: (status: InventoryStatusType) => void;
|
|
133
|
+
/** Function to toggle a product option choice filter */
|
|
134
|
+
toggleProductOption: (optionId: string, choiceId: string) => void;
|
|
135
|
+
/** Reactive signal indicating if any filters are currently applied */
|
|
136
|
+
isFiltered: Signal<boolean>;
|
|
137
|
+
/** Function to reset all filters to their default state */
|
|
138
|
+
reset: () => void;
|
|
139
|
+
};
|
|
140
|
+
__config: {};
|
|
141
|
+
isServiceDefinition?: boolean;
|
|
142
|
+
} & {
|
|
143
|
+
/** Reactive signal containing the minimum price filter value */
|
|
144
|
+
minPrice: Signal<number>;
|
|
145
|
+
/** Reactive signal containing the maximum price filter value */
|
|
146
|
+
maxPrice: Signal<number>;
|
|
147
|
+
/** Reactive signal containing available inventory status options */
|
|
148
|
+
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
149
|
+
/** Reactive signal containing selected inventory status filters */
|
|
150
|
+
selectedInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
151
|
+
/** Reactive signal containing available product options for filtering */
|
|
152
|
+
availableProductOptions: Signal<ProductOption[]>;
|
|
153
|
+
/** Reactive signal containing selected product option filters */
|
|
154
|
+
selectedProductOptions: Signal<Record<string, string[]>>;
|
|
155
|
+
/** Function to set the minimum price filter */
|
|
156
|
+
setMinPrice: (minPrice: number) => void;
|
|
157
|
+
/** Function to set the maximum price filter */
|
|
158
|
+
setMaxPrice: (maxPrice: number) => void;
|
|
159
|
+
/** Function to toggle an inventory status filter */
|
|
160
|
+
toggleInventoryStatus: (status: InventoryStatusType) => void;
|
|
161
|
+
/** Function to toggle a product option choice filter */
|
|
162
|
+
toggleProductOption: (optionId: string, choiceId: string) => void;
|
|
163
|
+
/** Reactive signal indicating if any filters are currently applied */
|
|
164
|
+
isFiltered: Signal<boolean>;
|
|
165
|
+
/** Function to reset all filters to their default state */
|
|
166
|
+
reset: () => void;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Implementation of the Products List Filters service that manages reactive filtering state.
|
|
170
|
+
* This service provides signals for all filter types (price, inventory, product options) and
|
|
171
|
+
* automatically updates the products list search options when filters change.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```tsx
|
|
175
|
+
* import { ProductsListFiltersService, ProductsListFiltersServiceDefinition } from '@wix/stores/services';
|
|
176
|
+
* import { useService } from '@wix/services-manager-react';
|
|
177
|
+
*
|
|
178
|
+
* function FiltersComponent({ filtersConfig }) {
|
|
179
|
+
* return (
|
|
180
|
+
* <ServiceProvider services={createServicesMap([
|
|
181
|
+
* [ProductsListFiltersServiceDefinition, ProductsListFiltersService.withConfig(filtersConfig)]
|
|
182
|
+
* ])}>
|
|
183
|
+
* <FilterControls />
|
|
184
|
+
* </ServiceProvider>
|
|
185
|
+
* );
|
|
186
|
+
* }
|
|
187
|
+
*
|
|
188
|
+
* function FilterControls() {
|
|
189
|
+
* const filtersService = useService(ProductsListFiltersServiceDefinition);
|
|
190
|
+
* const minPrice = filtersService.minPrice.get();
|
|
191
|
+
* const maxPrice = filtersService.maxPrice.get();
|
|
192
|
+
* const selectedInventoryStatuses = filtersService.selectedInventoryStatuses.get();
|
|
193
|
+
* const availableProductOptions = filtersService.availableProductOptions.get();
|
|
194
|
+
* const isFiltered = filtersService.isFiltered.get();
|
|
195
|
+
*
|
|
196
|
+
* return (
|
|
197
|
+
* <div>
|
|
198
|
+
* <div>
|
|
199
|
+
* <input
|
|
200
|
+
* type="number"
|
|
201
|
+
* value={minPrice}
|
|
202
|
+
* onChange={(e) => filtersService.setMinPrice(parseFloat(e.target.value))}
|
|
203
|
+
* placeholder="Min Price"
|
|
204
|
+
* />
|
|
205
|
+
* <input
|
|
206
|
+
* type="number"
|
|
207
|
+
* value={maxPrice}
|
|
208
|
+
* onChange={(e) => filtersService.setMaxPrice(parseFloat(e.target.value))}
|
|
209
|
+
* placeholder="Max Price"
|
|
210
|
+
* />
|
|
211
|
+
* </div>
|
|
212
|
+
*
|
|
213
|
+
* {availableProductOptions.map(option => (
|
|
214
|
+
* <div key={option.id}>
|
|
215
|
+
* <h4>{option.name}</h4>
|
|
216
|
+
* {option.choices.map(choice => (
|
|
217
|
+
* <label key={choice.id}>
|
|
218
|
+
* <input
|
|
219
|
+
* type="checkbox"
|
|
220
|
+
* onChange={() => filtersService.toggleProductOption(option.id, choice.id)}
|
|
221
|
+
* />
|
|
222
|
+
* {choice.name}
|
|
223
|
+
* </label>
|
|
224
|
+
* ))}
|
|
225
|
+
* </div>
|
|
226
|
+
* ))}
|
|
227
|
+
*
|
|
228
|
+
* {isFiltered && (
|
|
229
|
+
* <button onClick={() => filtersService.reset()}>
|
|
230
|
+
* Clear All Filters
|
|
231
|
+
* </button>
|
|
232
|
+
* )}
|
|
233
|
+
* </div>
|
|
234
|
+
* );
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
export declare const ProductsListFiltersService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
239
|
+
__api: {
|
|
240
|
+
/** Reactive signal containing the minimum price filter value */
|
|
241
|
+
minPrice: Signal<number>;
|
|
242
|
+
/** Reactive signal containing the maximum price filter value */
|
|
243
|
+
maxPrice: Signal<number>;
|
|
244
|
+
/** Reactive signal containing available inventory status options */
|
|
245
|
+
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
246
|
+
/** Reactive signal containing selected inventory status filters */
|
|
247
|
+
selectedInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
248
|
+
/** Reactive signal containing available product options for filtering */
|
|
249
|
+
availableProductOptions: Signal<ProductOption[]>;
|
|
250
|
+
/** Reactive signal containing selected product option filters */
|
|
251
|
+
selectedProductOptions: Signal<Record<string, string[]>>;
|
|
252
|
+
/** Function to set the minimum price filter */
|
|
253
|
+
setMinPrice: (minPrice: number) => void;
|
|
254
|
+
/** Function to set the maximum price filter */
|
|
255
|
+
setMaxPrice: (maxPrice: number) => void;
|
|
256
|
+
/** Function to toggle an inventory status filter */
|
|
257
|
+
toggleInventoryStatus: (status: InventoryStatusType) => void;
|
|
258
|
+
/** Function to toggle a product option choice filter */
|
|
259
|
+
toggleProductOption: (optionId: string, choiceId: string) => void;
|
|
260
|
+
/** Reactive signal indicating if any filters are currently applied */
|
|
261
|
+
isFiltered: Signal<boolean>;
|
|
262
|
+
/** Function to reset all filters to their default state */
|
|
263
|
+
reset: () => void;
|
|
264
|
+
};
|
|
265
|
+
__config: {};
|
|
266
|
+
isServiceDefinition?: boolean;
|
|
267
|
+
} & {
|
|
268
|
+
/** Reactive signal containing the minimum price filter value */
|
|
269
|
+
minPrice: Signal<number>;
|
|
270
|
+
/** Reactive signal containing the maximum price filter value */
|
|
271
|
+
maxPrice: Signal<number>;
|
|
272
|
+
/** Reactive signal containing available inventory status options */
|
|
273
|
+
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
274
|
+
/** Reactive signal containing selected inventory status filters */
|
|
275
|
+
selectedInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
276
|
+
/** Reactive signal containing available product options for filtering */
|
|
277
|
+
availableProductOptions: Signal<ProductOption[]>;
|
|
278
|
+
/** Reactive signal containing selected product option filters */
|
|
279
|
+
selectedProductOptions: Signal<Record<string, string[]>>;
|
|
280
|
+
/** Function to set the minimum price filter */
|
|
281
|
+
setMinPrice: (minPrice: number) => void;
|
|
282
|
+
/** Function to set the maximum price filter */
|
|
283
|
+
setMaxPrice: (maxPrice: number) => void;
|
|
284
|
+
/** Function to toggle an inventory status filter */
|
|
285
|
+
toggleInventoryStatus: (status: InventoryStatusType) => void;
|
|
286
|
+
/** Function to toggle a product option choice filter */
|
|
287
|
+
toggleProductOption: (optionId: string, choiceId: string) => void;
|
|
288
|
+
/** Reactive signal indicating if any filters are currently applied */
|
|
289
|
+
isFiltered: Signal<boolean>;
|
|
290
|
+
/** Function to reset all filters to their default state */
|
|
291
|
+
reset: () => void;
|
|
292
|
+
}, ProductsListFiltersServiceConfig>;
|