@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
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
|
+
/**
|
|
3
|
+
* Service definition for the Products List Sort service.
|
|
4
|
+
* This defines the reactive API contract for managing product list sorting options.
|
|
5
|
+
*
|
|
6
|
+
* @constant
|
|
7
|
+
*/
|
|
8
|
+
export declare const ProductsListSortServiceDefinition: string & {
|
|
9
|
+
__api: {
|
|
10
|
+
/** Reactive signal containing the currently selected sort option */
|
|
11
|
+
selectedSortOption: Signal<string>;
|
|
12
|
+
/** Function to update the selected sort option */
|
|
13
|
+
setSelectedSortOption: (sort: string) => void;
|
|
14
|
+
/** Array of available sort types */
|
|
15
|
+
sortOptions: SortType[];
|
|
16
|
+
};
|
|
17
|
+
__config: {};
|
|
18
|
+
isServiceDefinition?: boolean;
|
|
19
|
+
} & {
|
|
20
|
+
/** Reactive signal containing the currently selected sort option */
|
|
21
|
+
selectedSortOption: Signal<string>;
|
|
22
|
+
/** Function to update the selected sort option */
|
|
23
|
+
setSelectedSortOption: (sort: string) => void;
|
|
24
|
+
/** Array of available sort types */
|
|
25
|
+
sortOptions: SortType[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Configuration interface for the Products List Sort service.
|
|
29
|
+
* Currently empty as this service doesn't require initial configuration.
|
|
30
|
+
*
|
|
31
|
+
* @interface ProductsListSortServiceConfig
|
|
32
|
+
*/
|
|
33
|
+
export type ProductsListSortServiceConfig = {};
|
|
34
|
+
/**
|
|
35
|
+
* Enumeration of available product sort types.
|
|
36
|
+
* These values correspond to how products can be sorted in the product list.
|
|
37
|
+
*
|
|
38
|
+
* @enum {string}
|
|
39
|
+
*/
|
|
40
|
+
export declare enum SortType {
|
|
41
|
+
/** Sort by newest products first */
|
|
42
|
+
NEWEST = "newest",
|
|
43
|
+
/** Sort by product name in ascending order (A-Z) */
|
|
44
|
+
NAME_ASC = "name_asc",
|
|
45
|
+
/** Sort by product name in descending order (Z-A) */
|
|
46
|
+
NAME_DESC = "name_desc",
|
|
47
|
+
/** Sort by price in ascending order (lowest first) */
|
|
48
|
+
PRICE_ASC = "price_asc",
|
|
49
|
+
/** Sort by price in descending order (highest first) */
|
|
50
|
+
PRICE_DESC = "price_desc",
|
|
51
|
+
/** Sort by recommended products (algorithm-based) */
|
|
52
|
+
RECOMMENDED = "recommended"
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Implementation of the Products List Sort service that manages reactive sorting state.
|
|
56
|
+
* This service provides signals for the current sort option and automatically updates
|
|
57
|
+
* the products list search options when the sort selection changes.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```tsx
|
|
61
|
+
* import { ProductsListSortService, ProductsListSortServiceDefinition, SortType } from '@wix/stores/services';
|
|
62
|
+
* import { useService } from '@wix/services-manager-react';
|
|
63
|
+
*
|
|
64
|
+
* function SortComponent() {
|
|
65
|
+
* return (
|
|
66
|
+
* <ServiceProvider services={createServicesMap([
|
|
67
|
+
* [ProductsListSortServiceDefinition, ProductsListSortService.withConfig({})]
|
|
68
|
+
* ])}>
|
|
69
|
+
* <SortSelector />
|
|
70
|
+
* </ServiceProvider>
|
|
71
|
+
* );
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* function SortSelector() {
|
|
75
|
+
* const sortService = useService(ProductsListSortServiceDefinition);
|
|
76
|
+
* const selectedSort = sortService.selectedSortOption.get();
|
|
77
|
+
* const sortOptions = sortService.sortOptions;
|
|
78
|
+
*
|
|
79
|
+
* return (
|
|
80
|
+
* <select
|
|
81
|
+
* value={selectedSort}
|
|
82
|
+
* onChange={(e) => sortService.setSelectedSortOption(e.target.value)}
|
|
83
|
+
* >
|
|
84
|
+
* {sortOptions.map(option => (
|
|
85
|
+
* <option key={option} value={option}>
|
|
86
|
+
* {option === SortType.NAME_ASC ? 'Name A-Z' :
|
|
87
|
+
* option === SortType.NAME_DESC ? 'Name Z-A' :
|
|
88
|
+
* option === SortType.PRICE_ASC ? 'Price Low to High' :
|
|
89
|
+
* option === SortType.PRICE_DESC ? 'Price High to Low' :
|
|
90
|
+
* option === SortType.NEWEST ? 'Newest First' :
|
|
91
|
+
* 'Recommended'}
|
|
92
|
+
* </option>
|
|
93
|
+
* ))}
|
|
94
|
+
* </select>
|
|
95
|
+
* );
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare const ProductsListSortService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
100
|
+
__api: {
|
|
101
|
+
/** Reactive signal containing the currently selected sort option */
|
|
102
|
+
selectedSortOption: Signal<string>;
|
|
103
|
+
/** Function to update the selected sort option */
|
|
104
|
+
setSelectedSortOption: (sort: string) => void;
|
|
105
|
+
/** Array of available sort types */
|
|
106
|
+
sortOptions: SortType[];
|
|
107
|
+
};
|
|
108
|
+
__config: {};
|
|
109
|
+
isServiceDefinition?: boolean;
|
|
110
|
+
} & {
|
|
111
|
+
/** Reactive signal containing the currently selected sort option */
|
|
112
|
+
selectedSortOption: Signal<string>;
|
|
113
|
+
/** Function to update the selected sort option */
|
|
114
|
+
setSelectedSortOption: (sort: string) => void;
|
|
115
|
+
/** Array of available sort types */
|
|
116
|
+
sortOptions: SortType[];
|
|
117
|
+
}, ProductsListSortServiceConfig>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
|
+
import { SignalsServiceDefinition } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
import { ProductsListServiceDefinition } from "./products-list-service.js";
|
|
4
|
+
import { productsV3 } from "@wix/stores";
|
|
5
|
+
/**
|
|
6
|
+
* Service definition for the Products List Sort service.
|
|
7
|
+
* This defines the reactive API contract for managing product list sorting options.
|
|
8
|
+
*
|
|
9
|
+
* @constant
|
|
10
|
+
*/
|
|
11
|
+
export const ProductsListSortServiceDefinition = defineService("products-list-sort");
|
|
12
|
+
/**
|
|
13
|
+
* Enumeration of available product sort types.
|
|
14
|
+
* These values correspond to how products can be sorted in the product list.
|
|
15
|
+
*
|
|
16
|
+
* @enum {string}
|
|
17
|
+
*/
|
|
18
|
+
export var SortType;
|
|
19
|
+
(function (SortType) {
|
|
20
|
+
/** Sort by newest products first */
|
|
21
|
+
SortType["NEWEST"] = "newest";
|
|
22
|
+
/** Sort by product name in ascending order (A-Z) */
|
|
23
|
+
SortType["NAME_ASC"] = "name_asc";
|
|
24
|
+
/** Sort by product name in descending order (Z-A) */
|
|
25
|
+
SortType["NAME_DESC"] = "name_desc";
|
|
26
|
+
/** Sort by price in ascending order (lowest first) */
|
|
27
|
+
SortType["PRICE_ASC"] = "price_asc";
|
|
28
|
+
/** Sort by price in descending order (highest first) */
|
|
29
|
+
SortType["PRICE_DESC"] = "price_desc";
|
|
30
|
+
/** Sort by recommended products (algorithm-based) */
|
|
31
|
+
SortType["RECOMMENDED"] = "recommended";
|
|
32
|
+
})(SortType || (SortType = {}));
|
|
33
|
+
/**
|
|
34
|
+
* Implementation of the Products List Sort service that manages reactive sorting state.
|
|
35
|
+
* This service provides signals for the current sort option and automatically updates
|
|
36
|
+
* the products list search options when the sort selection changes.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* import { ProductsListSortService, ProductsListSortServiceDefinition, SortType } from '@wix/stores/services';
|
|
41
|
+
* import { useService } from '@wix/services-manager-react';
|
|
42
|
+
*
|
|
43
|
+
* function SortComponent() {
|
|
44
|
+
* return (
|
|
45
|
+
* <ServiceProvider services={createServicesMap([
|
|
46
|
+
* [ProductsListSortServiceDefinition, ProductsListSortService.withConfig({})]
|
|
47
|
+
* ])}>
|
|
48
|
+
* <SortSelector />
|
|
49
|
+
* </ServiceProvider>
|
|
50
|
+
* );
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* function SortSelector() {
|
|
54
|
+
* const sortService = useService(ProductsListSortServiceDefinition);
|
|
55
|
+
* const selectedSort = sortService.selectedSortOption.get();
|
|
56
|
+
* const sortOptions = sortService.sortOptions;
|
|
57
|
+
*
|
|
58
|
+
* return (
|
|
59
|
+
* <select
|
|
60
|
+
* value={selectedSort}
|
|
61
|
+
* onChange={(e) => sortService.setSelectedSortOption(e.target.value)}
|
|
62
|
+
* >
|
|
63
|
+
* {sortOptions.map(option => (
|
|
64
|
+
* <option key={option} value={option}>
|
|
65
|
+
* {option === SortType.NAME_ASC ? 'Name A-Z' :
|
|
66
|
+
* option === SortType.NAME_DESC ? 'Name Z-A' :
|
|
67
|
+
* option === SortType.PRICE_ASC ? 'Price Low to High' :
|
|
68
|
+
* option === SortType.PRICE_DESC ? 'Price High to Low' :
|
|
69
|
+
* option === SortType.NEWEST ? 'Newest First' :
|
|
70
|
+
* 'Recommended'}
|
|
71
|
+
* </option>
|
|
72
|
+
* ))}
|
|
73
|
+
* </select>
|
|
74
|
+
* );
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export const ProductsListSortService = implementService.withConfig()(ProductsListSortServiceDefinition, ({ getService }) => {
|
|
79
|
+
let firstRun = true;
|
|
80
|
+
const signalsService = getService(SignalsServiceDefinition);
|
|
81
|
+
const productsListService = getService(ProductsListServiceDefinition);
|
|
82
|
+
const selectedSortOptionSignal = signalsService.signal("name");
|
|
83
|
+
if (typeof window !== "undefined") {
|
|
84
|
+
signalsService.effect(() => {
|
|
85
|
+
const sort = selectedSortOptionSignal.get();
|
|
86
|
+
if (firstRun) {
|
|
87
|
+
firstRun = false;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const newSearchOptions = {
|
|
91
|
+
...productsListService.searchOptions.peek(),
|
|
92
|
+
};
|
|
93
|
+
if (!newSearchOptions.sort) {
|
|
94
|
+
newSearchOptions.sort = [];
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// Copy existing filter to avoid mutation
|
|
98
|
+
newSearchOptions.sort = [...newSearchOptions.sort];
|
|
99
|
+
}
|
|
100
|
+
switch (sort) {
|
|
101
|
+
case SortType.NAME_ASC:
|
|
102
|
+
newSearchOptions.sort = [
|
|
103
|
+
{ fieldName: "name", order: productsV3.SortDirection.ASC },
|
|
104
|
+
];
|
|
105
|
+
break;
|
|
106
|
+
case SortType.NAME_DESC:
|
|
107
|
+
newSearchOptions.sort = [
|
|
108
|
+
{ fieldName: "name", order: productsV3.SortDirection.DESC },
|
|
109
|
+
];
|
|
110
|
+
break;
|
|
111
|
+
case SortType.PRICE_ASC:
|
|
112
|
+
newSearchOptions.sort = [
|
|
113
|
+
{
|
|
114
|
+
fieldName: "actualPriceRange.minValue.amount",
|
|
115
|
+
order: productsV3.SortDirection.ASC,
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
break;
|
|
119
|
+
case SortType.PRICE_DESC:
|
|
120
|
+
newSearchOptions.sort = [
|
|
121
|
+
{
|
|
122
|
+
fieldName: "actualPriceRange.minValue.amount",
|
|
123
|
+
order: productsV3.SortDirection.DESC,
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
break;
|
|
127
|
+
case SortType.RECOMMENDED:
|
|
128
|
+
newSearchOptions.sort = [
|
|
129
|
+
{
|
|
130
|
+
fieldName: "name",
|
|
131
|
+
order: productsV3.SortDirection.DESC,
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
productsListService.setSearchOptions(newSearchOptions);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
selectedSortOption: selectedSortOptionSignal,
|
|
141
|
+
sortOptions: Object.values(SortType),
|
|
142
|
+
setSelectedSortOption: (sort) => selectedSortOptionSignal.set(sort),
|
|
143
|
+
};
|
|
144
|
+
});
|
|
@@ -1,5 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for managing URL parameters in web applications.
|
|
3
|
+
* Provides methods to parse, update, and retrieve URL search parameters with support for multiple values.
|
|
4
|
+
*
|
|
5
|
+
* @class URLParamsUtils
|
|
6
|
+
*/
|
|
1
7
|
export declare class URLParamsUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Parses URLSearchParams into a more convenient format that supports multiple values for the same key.
|
|
10
|
+
* Converts multiple parameters with the same key into an array.
|
|
11
|
+
*
|
|
12
|
+
* @static
|
|
13
|
+
* @param {URLSearchParams} searchParams - The URLSearchParams object to parse
|
|
14
|
+
* @returns {Record<string, string | string[]>} Object with parameter names as keys and values as strings or arrays
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // URL: ?color=red&color=blue&size=large
|
|
19
|
+
* const params = new URLSearchParams('color=red&color=blue&size=large');
|
|
20
|
+
* const parsed = URLParamsUtils.parseSearchParams(params);
|
|
21
|
+
* // Result: { color: ['red', 'blue'], size: 'large' }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
2
24
|
static parseSearchParams(searchParams: URLSearchParams): Record<string, string | string[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Updates the current page URL with new parameters without causing a page reload.
|
|
27
|
+
* Supports multiple values for the same parameter key.
|
|
28
|
+
*
|
|
29
|
+
* @static
|
|
30
|
+
* @param {Record<string, string | string[]>} params - Object with parameter names and values to set
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Update URL with single and multiple values
|
|
35
|
+
* URLParamsUtils.updateURL({
|
|
36
|
+
* category: 'electronics',
|
|
37
|
+
* color: ['red', 'blue'],
|
|
38
|
+
* price: '100'
|
|
39
|
+
* });
|
|
40
|
+
* // URL becomes: ?category=electronics&color=red&color=blue&price=100
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Clear all parameters by passing empty object
|
|
46
|
+
* URLParamsUtils.updateURL({});
|
|
47
|
+
* // URL becomes: current-path (no query string)
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
3
50
|
static updateURL(params: Record<string, string | string[]>): void;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the current URL parameters parsed into a convenient format.
|
|
53
|
+
* Returns an empty object when running in server-side environment.
|
|
54
|
+
*
|
|
55
|
+
* @static
|
|
56
|
+
* @returns {Record<string, string | string[]>} Object with current URL parameters
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Current URL: ?category=electronics&color=red&color=blue
|
|
61
|
+
* const params = URLParamsUtils.getURLParams();
|
|
62
|
+
* // Result: { category: 'electronics', color: ['red', 'blue'] }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* // Server-side usage
|
|
68
|
+
* const params = URLParamsUtils.getURLParams();
|
|
69
|
+
* // Result: {} (empty object)
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
4
72
|
static getURLParams(): Record<string, string | string[]>;
|
|
5
73
|
}
|
package/dist/utils/url-params.js
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for managing URL parameters in web applications.
|
|
3
|
+
* Provides methods to parse, update, and retrieve URL search parameters with support for multiple values.
|
|
4
|
+
*
|
|
5
|
+
* @class URLParamsUtils
|
|
6
|
+
*/
|
|
1
7
|
export class URLParamsUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Parses URLSearchParams into a more convenient format that supports multiple values for the same key.
|
|
10
|
+
* Converts multiple parameters with the same key into an array.
|
|
11
|
+
*
|
|
12
|
+
* @static
|
|
13
|
+
* @param {URLSearchParams} searchParams - The URLSearchParams object to parse
|
|
14
|
+
* @returns {Record<string, string | string[]>} Object with parameter names as keys and values as strings or arrays
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // URL: ?color=red&color=blue&size=large
|
|
19
|
+
* const params = new URLSearchParams('color=red&color=blue&size=large');
|
|
20
|
+
* const parsed = URLParamsUtils.parseSearchParams(params);
|
|
21
|
+
* // Result: { color: ['red', 'blue'], size: 'large' }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
2
24
|
static parseSearchParams(searchParams) {
|
|
3
25
|
const params = {};
|
|
4
26
|
// Parse all parameters
|
|
@@ -18,15 +40,40 @@ export class URLParamsUtils {
|
|
|
18
40
|
}
|
|
19
41
|
return params;
|
|
20
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Updates the current page URL with new parameters without causing a page reload.
|
|
45
|
+
* Supports multiple values for the same parameter key.
|
|
46
|
+
*
|
|
47
|
+
* @static
|
|
48
|
+
* @param {Record<string, string | string[]>} params - Object with parameter names and values to set
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Update URL with single and multiple values
|
|
53
|
+
* URLParamsUtils.updateURL({
|
|
54
|
+
* category: 'electronics',
|
|
55
|
+
* color: ['red', 'blue'],
|
|
56
|
+
* price: '100'
|
|
57
|
+
* });
|
|
58
|
+
* // URL becomes: ?category=electronics&color=red&color=blue&price=100
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // Clear all parameters by passing empty object
|
|
64
|
+
* URLParamsUtils.updateURL({});
|
|
65
|
+
* // URL becomes: current-path (no query string)
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
21
68
|
static updateURL(params) {
|
|
22
|
-
if (typeof window ===
|
|
69
|
+
if (typeof window === "undefined")
|
|
23
70
|
return;
|
|
24
71
|
const url = new URL(window.location.href);
|
|
25
72
|
const urlParams = new URLSearchParams();
|
|
26
73
|
// Add all parameters
|
|
27
74
|
Object.entries(params).forEach(([key, value]) => {
|
|
28
75
|
if (Array.isArray(value)) {
|
|
29
|
-
value.forEach(v => urlParams.append(key, v));
|
|
76
|
+
value.forEach((v) => urlParams.append(key, v));
|
|
30
77
|
}
|
|
31
78
|
else if (value) {
|
|
32
79
|
urlParams.set(key, value);
|
|
@@ -36,10 +83,31 @@ export class URLParamsUtils {
|
|
|
36
83
|
const newURL = urlParams.toString()
|
|
37
84
|
? `${url.pathname}?${urlParams.toString()}`
|
|
38
85
|
: url.pathname;
|
|
39
|
-
window.history.replaceState({},
|
|
86
|
+
window.history.replaceState({}, "", newURL);
|
|
40
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Gets the current URL parameters parsed into a convenient format.
|
|
90
|
+
* Returns an empty object when running in server-side environment.
|
|
91
|
+
*
|
|
92
|
+
* @static
|
|
93
|
+
* @returns {Record<string, string | string[]>} Object with current URL parameters
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // Current URL: ?category=electronics&color=red&color=blue
|
|
98
|
+
* const params = URLParamsUtils.getURLParams();
|
|
99
|
+
* // Result: { category: 'electronics', color: ['red', 'blue'] }
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // Server-side usage
|
|
105
|
+
* const params = URLParamsUtils.getURLParams();
|
|
106
|
+
* // Result: {} (empty object)
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
41
109
|
static getURLParams() {
|
|
42
|
-
if (typeof window ===
|
|
110
|
+
if (typeof window === "undefined")
|
|
43
111
|
return {};
|
|
44
112
|
return this.parseSearchParams(new URLSearchParams(window.location.search));
|
|
45
113
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-stores",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"@wix/auto_sdk_stores_read-only-variants-v-3": "^1.0.23",
|
|
59
59
|
"@wix/ecom": "^1.0.1238",
|
|
60
60
|
"@wix/essentials": "^0.1.24",
|
|
61
|
-
"@wix/headless-ecom": "^0.0.
|
|
62
|
-
"@wix/headless-media": "^0.0.
|
|
61
|
+
"@wix/headless-ecom": "^0.0.10",
|
|
62
|
+
"@wix/headless-media": "^0.0.7",
|
|
63
63
|
"@wix/redirects": "^1.0.83",
|
|
64
64
|
"@wix/services-definitions": "^0.1.4",
|
|
65
65
|
"@wix/services-manager-react": "^0.1.26"
|