@wix/headless-stores 0.0.55 → 0.0.57

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.
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { renderAsChild } from '../utils/index.js';
3
+ import { AsChildSlot } from '@wix/headless-utils/react';
4
4
  import { MediaGallery } from '@wix/headless-media/react';
5
5
  import * as CoreProduct from './core/Product.js';
6
6
  import * as ProductVariantSelector from './core/ProductVariantSelector.js';
@@ -99,21 +99,7 @@ export function Root(props) {
99
99
  export const Name = React.forwardRef((props, ref) => {
100
100
  const { asChild, children, className } = props;
101
101
  return (_jsx(CoreProduct.Name, { children: ({ name }) => {
102
- const attributes = {
103
- 'data-testid': TestIds.productName,
104
- };
105
- if (asChild) {
106
- const rendered = renderAsChild({
107
- children,
108
- props: { name },
109
- ref,
110
- content: name,
111
- attributes,
112
- });
113
- if (rendered)
114
- return rendered;
115
- }
116
- return (_jsx("div", { className: className, ...attributes, children: name }));
102
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productName, customElement: children, customElementProps: { name }, content: name, children: _jsx("div", { children: name }) }));
117
103
  } }));
118
104
  });
119
105
  /**
@@ -142,9 +128,6 @@ export const Name = React.forwardRef((props, ref) => {
142
128
  export const Description = React.forwardRef((props, ref) => {
143
129
  const { asChild, children, className, as = AsContent.Plain } = props;
144
130
  return (_jsx(CoreProduct.Description, { children: ({ description: richDescription, plainDescription }) => {
145
- const attributes = {
146
- 'data-testid': TestIds.productDescription,
147
- };
148
131
  // Determine which description to use based on the 'as' prop
149
132
  let description;
150
133
  switch (as) {
@@ -162,22 +145,13 @@ export const Description = React.forwardRef((props, ref) => {
162
145
  : '';
163
146
  break;
164
147
  }
165
- if (asChild) {
166
- const rendered = renderAsChild({
167
- children,
168
- props: { description },
169
- ref,
170
- content: description,
171
- attributes,
172
- });
173
- if (rendered)
174
- return rendered;
175
- }
176
- // Default rendering based on format
177
- if (as === AsContent.Html) {
178
- return (_jsx("div", { className: className, ...attributes, dangerouslySetInnerHTML: { __html: description } }));
148
+ // Handle default rendering based on format
149
+ if (!asChild || !children) {
150
+ if (as === AsContent.Html) {
151
+ return (_jsx("div", { ref: ref, className: className, "data-testid": TestIds.productDescription, dangerouslySetInnerHTML: { __html: description } }));
152
+ }
179
153
  }
180
- return (_jsx("div", { className: className, ...attributes, children: description }));
154
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productDescription, customElement: children, customElementProps: { description }, content: description, children: _jsx("div", { children: description }) }));
181
155
  } }));
182
156
  });
183
157
  /**
@@ -207,26 +181,10 @@ export const Description = React.forwardRef((props, ref) => {
207
181
  export const Price = React.forwardRef((props, ref) => {
208
182
  const { asChild, children, className } = props;
209
183
  return (_jsx(SelectedVariant.Price, { children: ({ price, compareAtPrice }) => {
210
- const attributes = {
211
- 'data-testid': TestIds.productPrice,
212
- 'data-discounted': compareAtPrice !== null,
213
- };
214
- const priceData = {
215
- price,
216
- formattedPrice: price,
217
- };
218
- if (asChild) {
219
- const rendered = renderAsChild({
220
- children,
221
- props: priceData,
222
- ref,
223
- content: price,
224
- attributes,
225
- });
226
- if (rendered)
227
- return rendered;
228
- }
229
- return (_jsx("span", { className: className, ...attributes, ref: ref, children: price }));
184
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productPrice, "data-discounted": compareAtPrice !== null, customElement: children, customElementProps: {
185
+ price,
186
+ formattedPrice: price,
187
+ }, content: price, children: _jsx("span", { children: price }) }));
230
188
  } }));
231
189
  });
232
190
  /**
@@ -261,30 +219,14 @@ export const CompareAtPrice = React.forwardRef((props, ref) => {
261
219
  const { asChild, children, className } = props;
262
220
  const testId = TestIds.productCompareAtPrice;
263
221
  return (_jsx(SelectedVariant.Price, { children: ({ compareAtPrice }) => {
264
- const attributes = {
265
- 'data-testid': testId,
266
- 'data-discounted': compareAtPrice !== null,
267
- };
268
222
  // Don't render anything if there's no compare-at price
269
223
  if (!compareAtPrice) {
270
224
  return null;
271
225
  }
272
- const priceData = {
273
- price: compareAtPrice,
274
- formattedPrice: compareAtPrice,
275
- };
276
- if (asChild) {
277
- const rendered = renderAsChild({
278
- children,
279
- props: priceData,
280
- ref,
281
- content: compareAtPrice,
282
- attributes,
283
- });
284
- if (rendered)
285
- return rendered;
286
- }
287
- return (_jsx("span", { className: className, ...attributes, ref: ref, children: compareAtPrice }));
226
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": testId, "data-discounted": compareAtPrice !== null, customElement: children, customElementProps: {
227
+ price: compareAtPrice,
228
+ formattedPrice: compareAtPrice,
229
+ }, content: compareAtPrice, children: _jsx("span", { children: compareAtPrice }) }));
288
230
  } }));
289
231
  });
290
232
  /**
@@ -310,25 +252,10 @@ export const CompareAtPrice = React.forwardRef((props, ref) => {
310
252
  * ```
311
253
  */
312
254
  export const Slug = React.forwardRef((props, ref) => {
313
- const { asChild, children } = props;
255
+ const { asChild, children, className } = props;
314
256
  const testId = TestIds.productSlug;
315
257
  return (_jsx(CoreProduct.Slug, { children: ({ slug }) => {
316
- const attributes = {
317
- 'data-testid': testId,
318
- };
319
- const slugData = { slug };
320
- if (asChild) {
321
- const rendered = renderAsChild({
322
- children,
323
- props: slugData,
324
- ref,
325
- content: slug,
326
- attributes,
327
- });
328
- if (rendered)
329
- return rendered;
330
- }
331
- return (_jsx("span", { ...attributes, ref: ref, children: slug }));
258
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": testId, customElement: children, customElementProps: { slug }, content: slug, children: _jsx("span", { children: slug }) }));
332
259
  } }));
333
260
  });
334
261
  /**
@@ -351,24 +278,13 @@ export const Slug = React.forwardRef((props, ref) => {
351
278
  * ```
352
279
  */
353
280
  export const Raw = React.forwardRef((props, ref) => {
354
- const { asChild, children } = props;
281
+ const { asChild, children, className } = props;
355
282
  return (_jsx(CoreProduct.Content, { children: ({ product }) => {
356
- const attributes = {
357
- 'data-testid': TestIds.productRaw,
358
- };
359
- if (asChild) {
360
- const rendered = renderAsChild({
361
- children,
362
- props: { product },
363
- ref,
364
- content: null,
365
- attributes,
366
- });
367
- if (rendered)
368
- return rendered;
369
- }
370
283
  // Raw component should not render anything by default when not using asChild
371
- return null;
284
+ if (!asChild || !children) {
285
+ return null;
286
+ }
287
+ return (_jsx(AsChildSlot, { ref: ref, className: className, "data-testid": TestIds.productRaw, customElement: children, customElementProps: { product } }));
372
288
  } }));
373
289
  });
374
290
  /**
@@ -414,7 +330,7 @@ export const Raw = React.forwardRef((props, ref) => {
414
330
  * ```
415
331
  */
416
332
  export const Variants = React.forwardRef((props, ref) => {
417
- const { asChild, children } = props;
333
+ const { asChild, children, className } = props;
418
334
  return (_jsx(ProductVariantSelector.Options, { children: ({ hasOptions, options }) => {
419
335
  if (!hasOptions)
420
336
  return null;
@@ -422,24 +338,7 @@ export const Variants = React.forwardRef((props, ref) => {
422
338
  hasOptions,
423
339
  options,
424
340
  };
425
- const attributes = {
426
- 'data-testid': TestIds.productVariants,
427
- };
428
- const content = (_jsx(VariantsContext.Provider, { value: contextValue, children: typeof children === 'function'
429
- ? null
430
- : children }));
431
- if (asChild) {
432
- const rendered = renderAsChild({
433
- children,
434
- props: { hasOptions },
435
- ref,
436
- content,
437
- attributes,
438
- });
439
- if (rendered)
440
- return rendered;
441
- }
442
- return (_jsx("div", { ...attributes, ref: ref, children: content }));
341
+ return (_jsx(VariantsContext.Provider, { value: contextValue, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productVariants, customElement: children, children: _jsx("div", { children: React.isValidElement(children) ? children : null }) }) }));
443
342
  } }));
444
343
  });
445
344
  /**
@@ -542,7 +441,7 @@ export const VariantOptionRepeater = React.forwardRef((props, _ref) => {
542
441
  * ```
543
442
  */
544
443
  export const Modifiers = React.forwardRef((props, ref) => {
545
- const { asChild, children } = props;
444
+ const { asChild, children, className } = props;
546
445
  return (_jsx(ProductModifiers.Modifiers, { children: ({ hasModifiers, modifiers }) => {
547
446
  if (!hasModifiers)
548
447
  return null;
@@ -550,24 +449,7 @@ export const Modifiers = React.forwardRef((props, ref) => {
550
449
  hasModifiers,
551
450
  modifiers,
552
451
  };
553
- const attributes = {
554
- 'data-testid': TestIds.productModifiers,
555
- };
556
- const content = (_jsx(ModifiersContext.Provider, { value: contextValue, children: typeof children === 'function'
557
- ? null
558
- : children }));
559
- if (asChild) {
560
- const rendered = renderAsChild({
561
- children,
562
- props: { hasModifiers },
563
- ref,
564
- content,
565
- attributes,
566
- });
567
- if (rendered)
568
- return rendered;
569
- }
570
- return (_jsx("div", { ...attributes, ref: ref, children: content }));
452
+ return (_jsx(ModifiersContext.Provider, { value: contextValue, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productModifiers, customElement: children, children: _jsx("div", { children: React.isValidElement(children) ? children : null }) }) }));
571
453
  } }));
572
454
  });
573
455
  /**
@@ -114,3 +114,55 @@ export interface ProductRepeaterProps {
114
114
  * ```
115
115
  */
116
116
  export declare const ProductRepeater: React.ForwardRefExoticComponent<ProductRepeaterProps & React.RefAttributes<HTMLElement>>;
117
+ /**
118
+ * Props for ProductList LoadMoreTrigger component
119
+ */
120
+ export interface LoadMoreTriggerProps {
121
+ children?: React.ReactNode;
122
+ asChild?: boolean;
123
+ className?: string;
124
+ }
125
+ /**
126
+ * Displays a button to load more products. Not rendered if infiniteScroll is false or no products are left to load.
127
+ * Follows the architecture rules - does not support asChild as it's a simple trigger component.
128
+ *
129
+ * @component
130
+ * @example
131
+ * ```tsx
132
+ * <ProductList.LoadMoreTrigger asChild>
133
+ * <button>Load More</button>
134
+ * </ProductList.LoadMoreTrigger>
135
+ * ```
136
+ */
137
+ export declare const LoadMoreTrigger: React.ForwardRefExoticComponent<LoadMoreTriggerProps & React.RefAttributes<HTMLElement>>;
138
+ /**
139
+ * Props for ProductList Totals Displayed component
140
+ */
141
+ export interface TotalsDisplayedProps {
142
+ /** Whether to render as a child component */
143
+ asChild?: boolean;
144
+ /** Custom render function when using asChild */
145
+ children?: React.ReactNode | React.ForwardRefRenderFunction<HTMLElement, {
146
+ displayedProducts: number;
147
+ }> | React.ForwardRefExoticComponent<any>;
148
+ /** CSS classes to apply to the default element */
149
+ className?: string;
150
+ }
151
+ /**
152
+ * Displays the number of products currently displayed.
153
+ *
154
+ * @component
155
+ * @example
156
+ * ```tsx
157
+ * <ProductList.TotalsDisplayed />
158
+ * // or with asChild
159
+ * <ProductList.TotalsDisplayed asChild>
160
+ * <strong />
161
+ * </ProductList.TotalsDisplayed>
162
+ * // or with render function
163
+ * <ProductList.TotalsDisplayed asChild>
164
+ * {({ displayedProducts }, ref) => <strong ref={ref}>{displayedProducts}</strong>}
165
+ * </ProductList.TotalsDisplayed>
166
+ * ```
167
+ */
168
+ export declare const TotalsDisplayed: React.ForwardRefExoticComponent<TotalsDisplayedProps & React.RefAttributes<HTMLElement>>;
@@ -3,12 +3,16 @@ import { useService } from '@wix/services-manager-react';
3
3
  import React from 'react';
4
4
  import { ProductsListServiceDefinition } from '../services/products-list-service.js';
5
5
  import * as CoreProductList from './core/ProductList.js';
6
+ import * as CoreProductListPagination from './core/ProductListPagination.js';
6
7
  import * as Product from './Product.js';
8
+ import { AsChildSlot } from '@wix/headless-utils/react';
7
9
  var TestIds;
8
10
  (function (TestIds) {
9
11
  TestIds["productListRoot"] = "product-list-root";
10
12
  TestIds["productListProducts"] = "product-list-products";
11
13
  TestIds["productListItem"] = "product-list-item";
14
+ TestIds["productListLoadMore"] = "product-list-load-more";
15
+ TestIds["productListTotalsDisplayed"] = "product-list-totals-displayed";
12
16
  })(TestIds || (TestIds = {}));
13
17
  /**
14
18
  * Root component that provides the ProductList service context for rendering product lists.
@@ -154,3 +158,49 @@ export const ProductRepeater = React.forwardRef((props, _ref) => {
154
158
  return null;
155
159
  return (_jsx(_Fragment, { children: products.map((product) => (_jsx(Product.Root, { product: product, "data-testid": TestIds.productListItem, "data-product-id": product._id, "data-product-available": true, children: children }, product._id))) }));
156
160
  });
161
+ /**
162
+ * Displays a button to load more products. Not rendered if infiniteScroll is false or no products are left to load.
163
+ * Follows the architecture rules - does not support asChild as it's a simple trigger component.
164
+ *
165
+ * @component
166
+ * @example
167
+ * ```tsx
168
+ * <ProductList.LoadMoreTrigger asChild>
169
+ * <button>Load More</button>
170
+ * </ProductList.LoadMoreTrigger>
171
+ * ```
172
+ */
173
+ export const LoadMoreTrigger = React.forwardRef((props, ref) => {
174
+ const { asChild, children, className } = props;
175
+ return (_jsx(CoreProductListPagination.LoadMoreTrigger, { children: ({ loadMore, hasMoreProducts, isLoading }) => {
176
+ // Don't render if no more products to load
177
+ if (!hasMoreProducts)
178
+ return null;
179
+ const handleClick = () => loadMore(10);
180
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, onClick: handleClick, disabled: isLoading, "data-testid": TestIds.productListLoadMore, customElement: children, children: _jsx("button", { children: children }) }));
181
+ } }));
182
+ });
183
+ /**
184
+ * Displays the number of products currently displayed.
185
+ *
186
+ * @component
187
+ * @example
188
+ * ```tsx
189
+ * <ProductList.TotalsDisplayed />
190
+ * // or with asChild
191
+ * <ProductList.TotalsDisplayed asChild>
192
+ * <strong />
193
+ * </ProductList.TotalsDisplayed>
194
+ * // or with render function
195
+ * <ProductList.TotalsDisplayed asChild>
196
+ * {({ displayedProducts }, ref) => <strong ref={ref}>{displayedProducts}</strong>}
197
+ * </ProductList.TotalsDisplayed>
198
+ * ```
199
+ */
200
+ export const TotalsDisplayed = React.forwardRef((props, ref) => {
201
+ const { asChild, children, className } = props;
202
+ const productsListService = useService(ProductsListServiceDefinition);
203
+ const products = productsListService.products.get();
204
+ const displayedProducts = products.length;
205
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListTotalsDisplayed, "data-displayed": displayedProducts, customElement: children, customElementProps: { displayedProducts }, content: displayedProducts, children: _jsx("span", { children: displayedProducts }) }));
206
+ });
@@ -3,7 +3,7 @@ import { useService, WixServices } from '@wix/services-manager-react';
3
3
  import { SelectedVariantServiceDefinition, SelectedVariantService, } from '../../services/selected-variant-service.js';
4
4
  import { ProductModifiersServiceDefinition } from '../../services/product-modifiers-service.js';
5
5
  import { createServicesMap } from '@wix/services-manager';
6
- import { Checkout } from '@wix/headless-ecom/react';
6
+ import { CheckoutCore } from '@wix/headless-ecom/react';
7
7
  import { CheckoutServiceDefinition, CurrentCartServiceDefinition, } from '@wix/headless-ecom/services';
8
8
  /**
9
9
  * Root component that provides the SelectedVariant service context to its children.
@@ -254,7 +254,7 @@ export function Actions(props) {
254
254
  error,
255
255
  };
256
256
  if (checkoutService) {
257
- return (_jsx(Checkout.Trigger, { children: ({ createCheckout, isLoading: checkoutLoading, error: checkoutError, }) => props.children({
257
+ return (_jsx(CheckoutCore.Trigger, { children: ({ createCheckout, isLoading: checkoutLoading, error: checkoutError, }) => props.children({
258
258
  ...commonProps,
259
259
  isLoading: isLoading || checkoutLoading,
260
260
  error: error || checkoutError,
@@ -9,6 +9,7 @@ export interface RenderChildrenParams<THTMLElement = HTMLElement, TProps = any>
9
9
  props: TProps;
10
10
  /** Ref to forward to the rendered element */
11
11
  ref: React.Ref<THTMLElement>;
12
+ content?: string | null;
12
13
  }
13
14
  /**
14
15
  * Utility function to handle children rendering.
@@ -38,4 +39,4 @@ export interface RenderChildrenParams<THTMLElement = HTMLElement, TProps = any>
38
39
  * });
39
40
  * ```
40
41
  */
41
- export declare function renderChildren<THTMLElement = HTMLElement, TProps = any>({ children, props, ref, }: RenderChildrenParams<THTMLElement, TProps>): React.ReactNode | null;
42
+ export declare function renderChildren<THTMLElement = HTMLElement, TProps = any>({ children, props, ref, content, }: RenderChildrenParams<THTMLElement, TProps>): React.ReactNode | null;
@@ -27,13 +27,16 @@ import React from 'react';
27
27
  * });
28
28
  * ```
29
29
  */
30
- export function renderChildren({ children, props, ref, }) {
30
+ export function renderChildren({ children, props, ref, content, }) {
31
31
  // Early return if no children provided
32
32
  if (!children)
33
33
  return null;
34
34
  // Handle React element pattern
35
35
  if (React.isValidElement(children)) {
36
- return children;
36
+ return React.cloneElement(children, {
37
+ ref,
38
+ ...(content ? { children: content } : {}),
39
+ });
37
40
  }
38
41
  // Handle render function pattern
39
42
  if (typeof children === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-stores",
3
- "version": "0.0.55",
3
+ "version": "0.0.57",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",
@@ -62,8 +62,9 @@
62
62
  "@wix/auto_sdk_stores_read-only-variants-v-3": "^1.0.23",
63
63
  "@wix/ecom": "^1.0.1278",
64
64
  "@wix/essentials": "^0.1.24",
65
- "@wix/headless-ecom": "^0.0.14",
66
- "@wix/headless-media": "^0.0.10",
65
+ "@wix/headless-ecom": "workspace:*",
66
+ "@wix/headless-media": "workspace:*",
67
+ "@wix/headless-utils": "workspace:*",
67
68
  "@wix/redirects": "^1.0.83",
68
69
  "@wix/services-definitions": "^0.1.4",
69
70
  "@wix/services-manager-react": "^0.1.26"