@wix/headless-stores 0.0.35 → 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.
Files changed (131) hide show
  1. package/cjs/dist/react/Category.d.ts +83 -31
  2. package/cjs/dist/react/Category.js +68 -35
  3. package/cjs/dist/react/CategoryList.d.ts +184 -0
  4. package/cjs/dist/react/CategoryList.js +174 -0
  5. package/cjs/dist/react/Product.d.ts +3 -3
  6. package/cjs/dist/react/Product.js +6 -6
  7. package/cjs/dist/react/ProductActions.d.ts +1 -1
  8. package/cjs/dist/react/ProductActions.js +2 -2
  9. package/{dist/react/ProductsList.d.ts → cjs/dist/react/ProductList.d.ts} +71 -38
  10. package/{dist/react/ProductsList.js → cjs/dist/react/ProductList.js} +30 -26
  11. package/cjs/dist/react/ProductListFilters.d.ts +244 -0
  12. package/cjs/dist/react/ProductListFilters.js +216 -0
  13. package/cjs/dist/react/ProductListPagination.d.ts +246 -0
  14. package/cjs/dist/react/ProductListPagination.js +207 -0
  15. package/cjs/dist/react/ProductListSort.d.ts +87 -0
  16. package/cjs/dist/react/ProductListSort.js +85 -0
  17. package/cjs/dist/react/ProductModifiers.d.ts +5 -5
  18. package/cjs/dist/react/ProductModifiers.js +10 -10
  19. package/cjs/dist/react/ProductVariantSelector.d.ts +5 -5
  20. package/cjs/dist/react/ProductVariantSelector.js +13 -10
  21. package/cjs/dist/react/SelectedVariant.d.ts +3 -3
  22. package/cjs/dist/react/SelectedVariant.js +6 -6
  23. package/cjs/dist/react/index.d.ts +7 -9
  24. package/cjs/dist/react/index.js +7 -9
  25. package/cjs/dist/services/buy-now-service.d.ts +208 -0
  26. package/cjs/dist/services/buy-now-service.js +132 -1
  27. package/cjs/dist/services/categories-list-service.d.ts +163 -0
  28. package/cjs/dist/services/categories-list-service.js +148 -0
  29. package/cjs/dist/services/category-service.d.ts +115 -70
  30. package/cjs/dist/services/category-service.js +101 -110
  31. package/cjs/dist/services/index.d.ts +6 -7
  32. package/cjs/dist/services/index.js +5 -16
  33. package/cjs/dist/services/pay-now-service.d.ts +146 -0
  34. package/cjs/dist/services/pay-now-service.js +112 -1
  35. package/cjs/dist/services/product-service.d.ts +71 -0
  36. package/cjs/dist/services/product-service.js +47 -0
  37. package/cjs/dist/services/products-list-filters-service.d.ts +292 -0
  38. package/cjs/dist/services/products-list-filters-service.js +446 -0
  39. package/cjs/dist/services/products-list-pagination-service.d.ts +186 -0
  40. package/cjs/dist/services/products-list-pagination-service.js +179 -0
  41. package/cjs/dist/services/products-list-service.d.ts +138 -52
  42. package/cjs/dist/services/products-list-service.js +98 -51
  43. package/cjs/dist/services/products-list-sort-service.d.ts +117 -0
  44. package/cjs/dist/services/products-list-sort-service.js +144 -0
  45. package/cjs/dist/services/selected-variant-service.js +0 -1
  46. package/cjs/dist/utils/url-params.d.ts +68 -0
  47. package/cjs/dist/utils/url-params.js +72 -4
  48. package/dist/react/Category.d.ts +83 -31
  49. package/dist/react/Category.js +68 -35
  50. package/dist/react/CategoryList.d.ts +184 -0
  51. package/dist/react/CategoryList.js +174 -0
  52. package/dist/react/Product.d.ts +3 -3
  53. package/dist/react/Product.js +6 -6
  54. package/dist/react/ProductActions.d.ts +1 -1
  55. package/dist/react/ProductActions.js +2 -2
  56. package/{cjs/dist/react/ProductsList.d.ts → dist/react/ProductList.d.ts} +71 -38
  57. package/{cjs/dist/react/ProductsList.js → dist/react/ProductList.js} +30 -26
  58. package/dist/react/ProductListFilters.d.ts +244 -0
  59. package/dist/react/ProductListFilters.js +216 -0
  60. package/dist/react/ProductListPagination.d.ts +246 -0
  61. package/dist/react/ProductListPagination.js +207 -0
  62. package/dist/react/ProductListSort.d.ts +87 -0
  63. package/dist/react/ProductListSort.js +85 -0
  64. package/dist/react/ProductModifiers.d.ts +5 -5
  65. package/dist/react/ProductModifiers.js +10 -10
  66. package/dist/react/ProductVariantSelector.d.ts +5 -5
  67. package/dist/react/ProductVariantSelector.js +13 -10
  68. package/dist/react/SelectedVariant.d.ts +3 -3
  69. package/dist/react/SelectedVariant.js +6 -6
  70. package/dist/react/index.d.ts +7 -9
  71. package/dist/react/index.js +7 -9
  72. package/dist/services/buy-now-service.d.ts +208 -0
  73. package/dist/services/buy-now-service.js +132 -1
  74. package/dist/services/categories-list-service.d.ts +163 -0
  75. package/dist/services/categories-list-service.js +148 -0
  76. package/dist/services/category-service.d.ts +115 -70
  77. package/dist/services/category-service.js +101 -110
  78. package/dist/services/index.d.ts +6 -7
  79. package/dist/services/index.js +5 -16
  80. package/dist/services/pay-now-service.d.ts +146 -0
  81. package/dist/services/pay-now-service.js +112 -1
  82. package/dist/services/product-service.d.ts +71 -0
  83. package/dist/services/product-service.js +47 -0
  84. package/dist/services/products-list-filters-service.d.ts +292 -0
  85. package/dist/services/products-list-filters-service.js +446 -0
  86. package/dist/services/products-list-pagination-service.d.ts +186 -0
  87. package/dist/services/products-list-pagination-service.js +179 -0
  88. package/dist/services/products-list-service.d.ts +138 -52
  89. package/dist/services/products-list-service.js +98 -51
  90. package/dist/services/products-list-sort-service.d.ts +117 -0
  91. package/dist/services/products-list-sort-service.js +144 -0
  92. package/dist/services/selected-variant-service.js +0 -1
  93. package/dist/utils/url-params.d.ts +68 -0
  94. package/dist/utils/url-params.js +72 -4
  95. package/package.json +3 -3
  96. package/cjs/dist/react/Collection.d.ts +0 -294
  97. package/cjs/dist/react/Collection.js +0 -345
  98. package/cjs/dist/react/FilteredCollection.d.ts +0 -216
  99. package/cjs/dist/react/FilteredCollection.js +0 -256
  100. package/cjs/dist/react/RelatedProducts.d.ts +0 -169
  101. package/cjs/dist/react/RelatedProducts.js +0 -180
  102. package/cjs/dist/react/Sort.d.ts +0 -37
  103. package/cjs/dist/react/Sort.js +0 -36
  104. package/cjs/dist/services/catalog-service.d.ts +0 -36
  105. package/cjs/dist/services/catalog-service.js +0 -193
  106. package/cjs/dist/services/collection-service.d.ts +0 -124
  107. package/cjs/dist/services/collection-service.js +0 -628
  108. package/cjs/dist/services/filter-service.d.ts +0 -35
  109. package/cjs/dist/services/filter-service.js +0 -119
  110. package/cjs/dist/services/related-products-service.d.ts +0 -100
  111. package/cjs/dist/services/related-products-service.js +0 -127
  112. package/cjs/dist/services/sort-service.d.ts +0 -20
  113. package/cjs/dist/services/sort-service.js +0 -27
  114. package/dist/react/Collection.d.ts +0 -294
  115. package/dist/react/Collection.js +0 -345
  116. package/dist/react/FilteredCollection.d.ts +0 -216
  117. package/dist/react/FilteredCollection.js +0 -256
  118. package/dist/react/RelatedProducts.d.ts +0 -169
  119. package/dist/react/RelatedProducts.js +0 -180
  120. package/dist/react/Sort.d.ts +0 -37
  121. package/dist/react/Sort.js +0 -36
  122. package/dist/services/catalog-service.d.ts +0 -36
  123. package/dist/services/catalog-service.js +0 -193
  124. package/dist/services/collection-service.d.ts +0 -124
  125. package/dist/services/collection-service.js +0 -628
  126. package/dist/services/filter-service.d.ts +0 -35
  127. package/dist/services/filter-service.js +0 -119
  128. package/dist/services/related-products-service.d.ts +0 -100
  129. package/dist/services/related-products-service.js +0 -127
  130. package/dist/services/sort-service.d.ts +0 -20
  131. 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
+ });
@@ -9,7 +9,6 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
9
9
  const signalsService = getService(SignalsServiceDefinition);
10
10
  const cartService = getService(CurrentCartServiceDefinition);
11
11
  const productService = getService(ProductServiceDefinition);
12
- // const mediaService = getService(MediaGalleryServiceDefinition);
13
12
  const selectedChoices = signalsService.signal({});
14
13
  const preOrderMessage = signalsService.signal(null);
15
14
  const initialProduct = productService.product.get();
@@ -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
  }
@@ -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 === 'undefined')
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({}, '', newURL);
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 === 'undefined')
110
+ if (typeof window === "undefined")
43
111
  return {};
44
112
  return this.parseSearchParams(new URLSearchParams(window.location.search));
45
113
  }
@@ -1,45 +1,97 @@
1
- import { type Category } from "@wix/auto_sdk_categories_categories";
2
- import React, { type ReactNode } from "react";
3
- export interface CategoryListProps {
4
- children: (data: {
5
- categories: Category[];
6
- selectedCategory: string | null;
7
- setSelectedCategory: (categoryId: string | null) => void;
8
- }) => ReactNode;
1
+ import type { PropsWithChildren, ReactNode } from "react";
2
+ import { type CategoryServiceConfig } from "../services/category-service.js";
3
+ /**
4
+ * Root component that provides the Category service context to its children.
5
+ * This component sets up the necessary services for managing category state.
6
+ *
7
+ * @order 1
8
+ * @component
9
+ * @example
10
+ * ```tsx
11
+ * import { Category } from '@wix/stores/components';
12
+ *
13
+ * function CategoryPage() {
14
+ * return (
15
+ * <Category.Root categoryServiceConfig={{ category: myCategory }}>
16
+ * <Category.Name>
17
+ * {({ name }) => <h1>{name}</h1>}
18
+ * </Category.Name>
19
+ * <Category.Slug>
20
+ * {({ slug }) => <p>Slug: {slug}</p>}
21
+ * </Category.Slug>
22
+ * </Category.Root>
23
+ * );
24
+ * }
25
+ * ```
26
+ */
27
+ export declare function Root(props: PropsWithChildren<{
28
+ categoryServiceConfig: CategoryServiceConfig;
29
+ }>): import("react/jsx-runtime").JSX.Element;
30
+ /**
31
+ * Props for Name headless component
32
+ */
33
+ export interface NameProps {
34
+ /** Content to display (can be a render function receiving name data or ReactNode) */
35
+ children: ((props: NameRenderProps) => ReactNode) | ReactNode;
36
+ }
37
+ /**
38
+ * Render props for Name component
39
+ */
40
+ export interface NameRenderProps {
41
+ /** Category name */
42
+ name: string;
43
+ }
44
+ /**
45
+ * Headless component for category name display
46
+ *
47
+ * @component
48
+ * @example
49
+ * ```tsx
50
+ * import { Category } from '@wix/stores/components';
51
+ *
52
+ * function CategoryHeader() {
53
+ * return (
54
+ * <Category.Name>
55
+ * {({ name }) => (
56
+ * <h1 className="category-title">{name}</h1>
57
+ * )}
58
+ * </Category.Name>
59
+ * );
60
+ * }
61
+ * ```
62
+ */
63
+ export declare function Name(props: NameProps): ReactNode;
64
+ /**
65
+ * Props for Slug headless component
66
+ */
67
+ export interface SlugProps {
68
+ /** Content to display (can be a render function receiving slug data or ReactNode) */
69
+ children: ((props: SlugRenderProps) => ReactNode) | ReactNode;
70
+ }
71
+ /**
72
+ * Render props for Slug component
73
+ */
74
+ export interface SlugRenderProps {
75
+ /** Category slug */
76
+ slug: string;
9
77
  }
10
78
  /**
11
- * Headless component for displaying a list of categories
79
+ * Headless component for category slug display
12
80
  *
13
81
  * @component
14
82
  * @example
15
83
  * ```tsx
16
84
  * import { Category } from '@wix/stores/components';
17
85
  *
18
- * function CategoryNavigation() {
86
+ * function CategoryInfo() {
19
87
  * return (
20
- * <Category.List>
21
- * {({ categories, selectedCategory, setSelectedCategory }) => (
22
- * <nav>
23
- * <button
24
- * onClick={() => setSelectedCategory(null)}
25
- * className={selectedCategory === null ? 'active' : ''}
26
- * >
27
- * All Categories
28
- * </button>
29
- * {categories.map(category => (
30
- * <button
31
- * key={category.id}
32
- * onClick={() => setSelectedCategory(category.id)}
33
- * className={selectedCategory === category.id ? 'active' : ''}
34
- * >
35
- * {category.name}
36
- * </button>
37
- * ))}
38
- * </nav>
88
+ * <Category.Slug>
89
+ * {({ slug }) => (
90
+ * <p className="category-slug">Category slug: {slug}</p>
39
91
  * )}
40
- * </Category.List>
92
+ * </Category.Slug>
41
93
  * );
42
94
  * }
43
95
  * ```
44
96
  */
45
- export declare const List: React.FC<CategoryListProps>;
97
+ export declare function Slug(props: SlugProps): ReactNode;