@wix/headless-stores 0.0.45 → 0.0.47

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.
@@ -132,3 +132,17 @@ export interface ProductMediaRenderProps {
132
132
  media: ProductMedia[];
133
133
  }
134
134
  export declare function Media(props: ProductMediaProps): import("react").ReactNode;
135
+ export interface ProductProps {
136
+ children: (props: ProductRenderProps) => React.ReactNode;
137
+ }
138
+ export interface ProductRenderProps {
139
+ product: V3Product;
140
+ }
141
+ export declare function Content(props: ProductProps): import("react").ReactNode;
142
+ export interface LoadingProps {
143
+ children: (props: LoadingRenderProps) => React.ReactNode;
144
+ }
145
+ export interface LoadingRenderProps {
146
+ isLoading: boolean;
147
+ }
148
+ export declare function Loading(props: LoadingProps): import("react").ReactNode;
@@ -110,3 +110,17 @@ export function Media(props) {
110
110
  media,
111
111
  });
112
112
  }
113
+ export function Content(props) {
114
+ const service = useService(ProductServiceDefinition);
115
+ const product = service.product.get();
116
+ return props.children({
117
+ product,
118
+ });
119
+ }
120
+ export function Loading(props) {
121
+ const service = useService(ProductServiceDefinition);
122
+ const isLoading = service.isLoading.get();
123
+ return props.children({
124
+ isLoading,
125
+ });
126
+ }
@@ -35,7 +35,8 @@ export declare const ProductServiceDefinition: string & {
35
35
  */
36
36
  export interface ProductServiceConfig {
37
37
  /** The initial product data to configure the service with */
38
- product: productsV3.V3Product;
38
+ product?: productsV3.V3Product;
39
+ productSlug?: string;
39
40
  }
40
41
  /**
41
42
  * Implementation of the Product service that manages reactive product data.
@@ -44,7 +44,7 @@ export const ProductServiceDefinition = defineService("product");
44
44
  export const ProductService = implementService.withConfig()(ProductServiceDefinition, ({ getService, config }) => {
45
45
  const signalsService = getService(SignalsServiceDefinition);
46
46
  const product = signalsService.signal(config.product);
47
- const isLoading = signalsService.signal(false);
47
+ const isLoading = signalsService.signal(!!config.productSlug);
48
48
  const error = signalsService.signal(null);
49
49
  const loadProduct = async (slug) => {
50
50
  isLoading.set(true);
@@ -58,6 +58,9 @@ export const ProductService = implementService.withConfig()(ProductServiceDefini
58
58
  }
59
59
  isLoading.set(false);
60
60
  };
61
+ if (config.productSlug) {
62
+ loadProduct(config.productSlug);
63
+ }
61
64
  return {
62
65
  product,
63
66
  isLoading,
@@ -143,8 +143,19 @@ function updateUrlWithSearchState(searchState) {
143
143
  let baseUrl = window.location.pathname;
144
144
  // If categorySlug is provided, update the path
145
145
  if (categorySlug) {
146
- if (categorySlug) {
147
- baseUrl = `/category/${categorySlug}`;
146
+ // Find if there's already a /category/ segment in the current path
147
+ const pathSegments = baseUrl.split("/").filter(Boolean);
148
+ const categoryIndex = pathSegments.findIndex((segment) => segment === "category");
149
+ if (categoryIndex !== -1) {
150
+ // Replace existing category slug
151
+ pathSegments[categoryIndex + 1] = categorySlug;
152
+ baseUrl = "/" + pathSegments.join("/");
153
+ }
154
+ else {
155
+ // Append category path to existing base
156
+ baseUrl = baseUrl.endsWith("/")
157
+ ? `${baseUrl}category/${categorySlug}`
158
+ : `${baseUrl}/category/${categorySlug}`;
148
159
  }
149
160
  }
150
161
  // Build the new URL
@@ -132,3 +132,17 @@ export interface ProductMediaRenderProps {
132
132
  media: ProductMedia[];
133
133
  }
134
134
  export declare function Media(props: ProductMediaProps): import("react").ReactNode;
135
+ export interface ProductProps {
136
+ children: (props: ProductRenderProps) => React.ReactNode;
137
+ }
138
+ export interface ProductRenderProps {
139
+ product: V3Product;
140
+ }
141
+ export declare function Content(props: ProductProps): import("react").ReactNode;
142
+ export interface LoadingProps {
143
+ children: (props: LoadingRenderProps) => React.ReactNode;
144
+ }
145
+ export interface LoadingRenderProps {
146
+ isLoading: boolean;
147
+ }
148
+ export declare function Loading(props: LoadingProps): import("react").ReactNode;
@@ -110,3 +110,17 @@ export function Media(props) {
110
110
  media,
111
111
  });
112
112
  }
113
+ export function Content(props) {
114
+ const service = useService(ProductServiceDefinition);
115
+ const product = service.product.get();
116
+ return props.children({
117
+ product,
118
+ });
119
+ }
120
+ export function Loading(props) {
121
+ const service = useService(ProductServiceDefinition);
122
+ const isLoading = service.isLoading.get();
123
+ return props.children({
124
+ isLoading,
125
+ });
126
+ }
@@ -35,7 +35,8 @@ export declare const ProductServiceDefinition: string & {
35
35
  */
36
36
  export interface ProductServiceConfig {
37
37
  /** The initial product data to configure the service with */
38
- product: productsV3.V3Product;
38
+ product?: productsV3.V3Product;
39
+ productSlug?: string;
39
40
  }
40
41
  /**
41
42
  * Implementation of the Product service that manages reactive product data.
@@ -44,7 +44,7 @@ export const ProductServiceDefinition = defineService("product");
44
44
  export const ProductService = implementService.withConfig()(ProductServiceDefinition, ({ getService, config }) => {
45
45
  const signalsService = getService(SignalsServiceDefinition);
46
46
  const product = signalsService.signal(config.product);
47
- const isLoading = signalsService.signal(false);
47
+ const isLoading = signalsService.signal(!!config.productSlug);
48
48
  const error = signalsService.signal(null);
49
49
  const loadProduct = async (slug) => {
50
50
  isLoading.set(true);
@@ -58,6 +58,9 @@ export const ProductService = implementService.withConfig()(ProductServiceDefini
58
58
  }
59
59
  isLoading.set(false);
60
60
  };
61
+ if (config.productSlug) {
62
+ loadProduct(config.productSlug);
63
+ }
61
64
  return {
62
65
  product,
63
66
  isLoading,
@@ -143,8 +143,19 @@ function updateUrlWithSearchState(searchState) {
143
143
  let baseUrl = window.location.pathname;
144
144
  // If categorySlug is provided, update the path
145
145
  if (categorySlug) {
146
- if (categorySlug) {
147
- baseUrl = `/category/${categorySlug}`;
146
+ // Find if there's already a /category/ segment in the current path
147
+ const pathSegments = baseUrl.split("/").filter(Boolean);
148
+ const categoryIndex = pathSegments.findIndex((segment) => segment === "category");
149
+ if (categoryIndex !== -1) {
150
+ // Replace existing category slug
151
+ pathSegments[categoryIndex + 1] = categorySlug;
152
+ baseUrl = "/" + pathSegments.join("/");
153
+ }
154
+ else {
155
+ // Append category path to existing base
156
+ baseUrl = baseUrl.endsWith("/")
157
+ ? `${baseUrl}category/${categorySlug}`
158
+ : `${baseUrl}/category/${categorySlug}`;
148
159
  }
149
160
  }
150
161
  // Build the new URL
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-stores",
3
- "version": "0.0.45",
3
+ "version": "0.0.47",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",