@wix/headless-stores 0.0.0

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 (150) hide show
  1. package/astro/actions/package.json +4 -0
  2. package/cjs/dist/astro/actions/custom-checkout.d.ts +50 -0
  3. package/cjs/dist/astro/actions/custom-checkout.js +53 -0
  4. package/cjs/dist/astro/actions/index.d.ts +1 -0
  5. package/cjs/dist/astro/actions/index.js +1 -0
  6. package/cjs/dist/data-component-tags.d.ts +8 -0
  7. package/cjs/dist/data-component-tags.js +9 -0
  8. package/cjs/dist/enums/index.d.ts +2 -0
  9. package/cjs/dist/enums/index.js +2 -0
  10. package/cjs/dist/enums/social-platform-enums.d.ts +25 -0
  11. package/cjs/dist/enums/social-platform-enums.js +27 -0
  12. package/cjs/dist/enums/sort-enums.d.ts +17 -0
  13. package/cjs/dist/enums/sort-enums.js +18 -0
  14. package/cjs/dist/react/Category.d.ts +242 -0
  15. package/cjs/dist/react/Category.js +235 -0
  16. package/cjs/dist/react/CategoryList.d.ts +107 -0
  17. package/cjs/dist/react/CategoryList.js +91 -0
  18. package/cjs/dist/react/Choice.d.ts +211 -0
  19. package/cjs/dist/react/Choice.js +213 -0
  20. package/cjs/dist/react/Option.d.ts +242 -0
  21. package/cjs/dist/react/Option.js +346 -0
  22. package/cjs/dist/react/Product.d.ts +1065 -0
  23. package/cjs/dist/react/Product.js +1157 -0
  24. package/cjs/dist/react/ProductList.d.ts +400 -0
  25. package/cjs/dist/react/ProductList.js +368 -0
  26. package/cjs/dist/react/core/CategoryList.d.ts +194 -0
  27. package/cjs/dist/react/core/CategoryList.js +180 -0
  28. package/cjs/dist/react/core/Product.d.ts +225 -0
  29. package/cjs/dist/react/core/Product.js +190 -0
  30. package/cjs/dist/react/core/ProductList.d.ts +235 -0
  31. package/cjs/dist/react/core/ProductList.js +217 -0
  32. package/cjs/dist/react/core/ProductListFilters.d.ts +138 -0
  33. package/cjs/dist/react/core/ProductListFilters.js +242 -0
  34. package/cjs/dist/react/core/ProductListPagination.d.ts +49 -0
  35. package/cjs/dist/react/core/ProductListPagination.js +41 -0
  36. package/cjs/dist/react/core/ProductListSort.d.ts +19 -0
  37. package/cjs/dist/react/core/ProductListSort.js +52 -0
  38. package/cjs/dist/react/core/ProductModifiers.d.ts +416 -0
  39. package/cjs/dist/react/core/ProductModifiers.js +413 -0
  40. package/cjs/dist/react/core/ProductVariantSelector.d.ts +313 -0
  41. package/cjs/dist/react/core/ProductVariantSelector.js +291 -0
  42. package/cjs/dist/react/core/SelectedVariant.d.ts +230 -0
  43. package/cjs/dist/react/core/SelectedVariant.js +269 -0
  44. package/cjs/dist/react/index.d.ts +6 -0
  45. package/cjs/dist/react/index.js +6 -0
  46. package/cjs/dist/react/types.d.ts +8 -0
  47. package/cjs/dist/react/types.js +9 -0
  48. package/cjs/dist/server-actions/custom-checkout-action.d.ts +49 -0
  49. package/cjs/dist/server-actions/custom-checkout-action.js +64 -0
  50. package/cjs/dist/server-actions/index.d.ts +1 -0
  51. package/cjs/dist/server-actions/index.js +1 -0
  52. package/cjs/dist/services/buy-now-service.d.ts +346 -0
  53. package/cjs/dist/services/buy-now-service.js +197 -0
  54. package/cjs/dist/services/categories-list-service.d.ts +164 -0
  55. package/cjs/dist/services/categories-list-service.js +148 -0
  56. package/cjs/dist/services/index.d.ts +5 -0
  57. package/cjs/dist/services/index.js +5 -0
  58. package/cjs/dist/services/pay-now-service.d.ts +214 -0
  59. package/cjs/dist/services/pay-now-service.js +156 -0
  60. package/cjs/dist/services/product-modifiers-service.d.ts +34 -0
  61. package/cjs/dist/services/product-modifiers-service.js +107 -0
  62. package/cjs/dist/services/product-service.d.ts +177 -0
  63. package/cjs/dist/services/product-service.js +190 -0
  64. package/cjs/dist/services/products-list-search-service.d.ts +1 -0
  65. package/cjs/dist/services/products-list-search-service.js +1 -0
  66. package/cjs/dist/services/products-list-service.d.ts +429 -0
  67. package/cjs/dist/services/products-list-service.js +893 -0
  68. package/cjs/dist/services/selected-variant-service.d.ts +66 -0
  69. package/cjs/dist/services/selected-variant-service.js +527 -0
  70. package/cjs/dist/utils/index.d.ts +1 -0
  71. package/cjs/dist/utils/index.js +30 -0
  72. package/cjs/dist/utils/url-params.d.ts +73 -0
  73. package/cjs/dist/utils/url-params.js +114 -0
  74. package/cjs/package.json +3 -0
  75. package/dist/astro/actions/custom-checkout.d.ts +50 -0
  76. package/dist/astro/actions/custom-checkout.js +53 -0
  77. package/dist/astro/actions/index.d.ts +1 -0
  78. package/dist/astro/actions/index.js +1 -0
  79. package/dist/data-component-tags.d.ts +8 -0
  80. package/dist/data-component-tags.js +9 -0
  81. package/dist/enums/index.d.ts +2 -0
  82. package/dist/enums/index.js +2 -0
  83. package/dist/enums/social-platform-enums.d.ts +25 -0
  84. package/dist/enums/social-platform-enums.js +27 -0
  85. package/dist/enums/sort-enums.d.ts +17 -0
  86. package/dist/enums/sort-enums.js +18 -0
  87. package/dist/react/Category.d.ts +242 -0
  88. package/dist/react/Category.js +235 -0
  89. package/dist/react/CategoryList.d.ts +107 -0
  90. package/dist/react/CategoryList.js +91 -0
  91. package/dist/react/Choice.d.ts +211 -0
  92. package/dist/react/Choice.js +213 -0
  93. package/dist/react/Option.d.ts +242 -0
  94. package/dist/react/Option.js +346 -0
  95. package/dist/react/Product.d.ts +1065 -0
  96. package/dist/react/Product.js +1157 -0
  97. package/dist/react/ProductList.d.ts +400 -0
  98. package/dist/react/ProductList.js +368 -0
  99. package/dist/react/core/CategoryList.d.ts +194 -0
  100. package/dist/react/core/CategoryList.js +180 -0
  101. package/dist/react/core/Product.d.ts +225 -0
  102. package/dist/react/core/Product.js +190 -0
  103. package/dist/react/core/ProductList.d.ts +235 -0
  104. package/dist/react/core/ProductList.js +217 -0
  105. package/dist/react/core/ProductListFilters.d.ts +138 -0
  106. package/dist/react/core/ProductListFilters.js +242 -0
  107. package/dist/react/core/ProductListPagination.d.ts +49 -0
  108. package/dist/react/core/ProductListPagination.js +41 -0
  109. package/dist/react/core/ProductListSort.d.ts +19 -0
  110. package/dist/react/core/ProductListSort.js +52 -0
  111. package/dist/react/core/ProductModifiers.d.ts +416 -0
  112. package/dist/react/core/ProductModifiers.js +413 -0
  113. package/dist/react/core/ProductVariantSelector.d.ts +313 -0
  114. package/dist/react/core/ProductVariantSelector.js +291 -0
  115. package/dist/react/core/SelectedVariant.d.ts +230 -0
  116. package/dist/react/core/SelectedVariant.js +269 -0
  117. package/dist/react/index.d.ts +6 -0
  118. package/dist/react/index.js +6 -0
  119. package/dist/react/types.d.ts +8 -0
  120. package/dist/react/types.js +9 -0
  121. package/dist/server-actions/custom-checkout-action.d.ts +49 -0
  122. package/dist/server-actions/custom-checkout-action.js +64 -0
  123. package/dist/server-actions/index.d.ts +1 -0
  124. package/dist/server-actions/index.js +1 -0
  125. package/dist/services/buy-now-service.d.ts +346 -0
  126. package/dist/services/buy-now-service.js +197 -0
  127. package/dist/services/categories-list-service.d.ts +164 -0
  128. package/dist/services/categories-list-service.js +148 -0
  129. package/dist/services/index.d.ts +5 -0
  130. package/dist/services/index.js +5 -0
  131. package/dist/services/pay-now-service.d.ts +214 -0
  132. package/dist/services/pay-now-service.js +156 -0
  133. package/dist/services/product-modifiers-service.d.ts +34 -0
  134. package/dist/services/product-modifiers-service.js +107 -0
  135. package/dist/services/product-service.d.ts +177 -0
  136. package/dist/services/product-service.js +190 -0
  137. package/dist/services/products-list-search-service.d.ts +0 -0
  138. package/dist/services/products-list-search-service.js +1 -0
  139. package/dist/services/products-list-service.d.ts +429 -0
  140. package/dist/services/products-list-service.js +893 -0
  141. package/dist/services/selected-variant-service.d.ts +66 -0
  142. package/dist/services/selected-variant-service.js +527 -0
  143. package/dist/utils/index.d.ts +1 -0
  144. package/dist/utils/index.js +30 -0
  145. package/dist/utils/url-params.d.ts +73 -0
  146. package/dist/utils/url-params.js +114 -0
  147. package/package.json +89 -0
  148. package/react/package.json +4 -0
  149. package/server-actions/package.json +4 -0
  150. package/services/package.json +4 -0
@@ -0,0 +1,346 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import * as Choice from './Choice.js';
4
+ import * as ProductModifiersPrimitive from './core/ProductModifiers.js';
5
+ import * as ProductVariantSelectorPrimitive from './core/ProductVariantSelector.js';
6
+ import { AsChildSlot } from '@wix/headless-utils/react';
7
+ import { DataComponentTags } from '../data-component-tags.js';
8
+ var TestIds;
9
+ (function (TestIds) {
10
+ TestIds["optionRoot"] = "option-root";
11
+ TestIds["optionName"] = "option-name";
12
+ TestIds["optionMandatoryIndicator"] = "option-mandatory-indicator";
13
+ TestIds["optionChoices"] = "option-choices";
14
+ })(TestIds || (TestIds = {}));
15
+ /**
16
+ * Root component that provides context for variant options.
17
+ * Automatically detects and sets the option type based on the option name and available choices.
18
+ *
19
+ * @component
20
+ *
21
+ * **Data Attributes**
22
+ *
23
+ * - `data-testid="option-root"` - Applied to option container (TestIds.optionRoot)
24
+ * - `data-type` - The type of the option: 'color' | 'text' | 'free-text'
25
+ * @example
26
+ * ```tsx
27
+ * // Color option (data-type="color")
28
+ * <Option.Root
29
+ * option={{ name: "Color" }}
30
+ * onValueChange={(value) => console.log('Selected:', value)}
31
+ * >
32
+ * <Option.Name />
33
+ * <Option.Choices>
34
+ * <Option.ChoiceRepeater>
35
+ * <Choice.Color />
36
+ * </Option.ChoiceRepeater>
37
+ * </Option.Choices>
38
+ * </Option.Root>
39
+ *
40
+ * // Text option (data-type="text")
41
+ * <Option.Root
42
+ * option={{ name: "Size" }}
43
+ * onValueChange={(value) => console.log('Selected:', value)}
44
+ * >
45
+ * <Option.Name />
46
+ * <Option.Choices>
47
+ * <Option.ChoiceRepeater>
48
+ * <Choice.Text />
49
+ * </Option.ChoiceRepeater>
50
+ * </Option.Choices>
51
+ * </Option.Root>
52
+ *
53
+ * // Free text option (data-type="free-text")
54
+ * <Option.Root
55
+ * option={{ name: "Custom Text" }}
56
+ * onValueChange={(value) => console.log('Entered:', value)}
57
+ * >
58
+ * <Option.Name />
59
+ * <Option.Choices>
60
+ * <Option.ChoiceRepeater>
61
+ * <Choice.FreeText />
62
+ * </Option.ChoiceRepeater>
63
+ * </Option.Choices>
64
+ * </Option.Root>
65
+ *
66
+ * // With allowed types filter
67
+ * <Option.Root
68
+ * option={{ name: "Size" }}
69
+ * allowedTypes={['text']}
70
+ * onValueChange={(value) => console.log('Selected size:', value)}
71
+ * >
72
+ * <Option.Name />
73
+ * <Option.Choices>
74
+ * <Option.ChoiceRepeater>
75
+ * <Choice.Text />
76
+ * </Option.ChoiceRepeater>
77
+ * </Option.Choices>
78
+ * </Option.Root>
79
+ *
80
+ * // asChild with react component
81
+ * <Option.Root
82
+ * asChild
83
+ * option={{ name: "Color" }}
84
+ * onValueChange={(value) => console.log('Selected:', value)}
85
+ * >
86
+ * {React.forwardRef(({option, onValueChange, allowedTypes, ...props}, ref) => (
87
+ * <section ref={ref} {...props} className="option-section">
88
+ * <h3>Option: {option.name}</h3>
89
+ * <p>Allowed types: {allowedTypes.join(', ')}</p>
90
+ * {props.children}
91
+ * </section>
92
+ * ))}
93
+ * </Option.Root>
94
+ * ```
95
+ */
96
+ export const Root = React.forwardRef((props, ref) => {
97
+ const { asChild, children, option, onValueChange, allowedTypes, className, ...otherProps } = props;
98
+ // Determine the option type based on the option name and available choices
99
+ const getOptionType = () => {
100
+ if (option.type === 'FREE_TEXT') {
101
+ return 'free-text';
102
+ }
103
+ if (option.hasChoices &&
104
+ option.choices?.some((choice) => choice.colorCode)) {
105
+ return 'color';
106
+ }
107
+ return 'text';
108
+ };
109
+ const optionType = getOptionType();
110
+ const contextValue = {
111
+ ...option,
112
+ optionType,
113
+ onValueChange,
114
+ allowedTypes,
115
+ mandatory: option?.mandatory || false,
116
+ };
117
+ return (_jsx(OptionContext.Provider, { value: contextValue, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-component-tag": DataComponentTags.optionRoot, "data-testid": TestIds.optionRoot, "data-type": optionType, customElement: children, customElementProps: { option, onValueChange, allowedTypes }, ...otherProps, children: _jsx("div", { children: React.isValidElement(children) ? children : null }) }) }));
118
+ });
119
+ Root.displayName = 'Option.Root';
120
+ // Create a context to pass option data down
121
+ export const OptionContext = React.createContext(null);
122
+ /**
123
+ * Displays the option name.
124
+ * Follows true Radix pattern - use separate components for each styleable element.
125
+ *
126
+ * @component
127
+ * @example
128
+ * ```tsx
129
+ * // True Radix pattern - separate components
130
+ * <div className="flex items-center gap-1">
131
+ * <Option.Name className="text-lg font-medium" />
132
+ * <Option.MandatoryIndicator className="text-red-500" />
133
+ * </div>
134
+ *
135
+ * // Custom rendering
136
+ * <Option.Name asChild>
137
+ * {React.forwardRef<HTMLElement, { name: string }>(({ name, ...props }, ref) => (
138
+ * <h4 ref={ref} {...props} className="text-lg font-medium text-content-primary">
139
+ * {name}
140
+ * </h4>
141
+ * ))}
142
+ * </Option.Name>
143
+ * ```
144
+ */
145
+ export const Name = React.forwardRef((props, ref) => {
146
+ const { asChild, children, className, ...otherProps } = props;
147
+ const optionData = React.useContext(OptionContext);
148
+ if (!optionData)
149
+ return null;
150
+ const name = optionData.name || '';
151
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.optionName, customElement: children, customElementProps: { name }, content: name, ...otherProps, children: _jsx("div", { children: name }) }));
152
+ });
153
+ /**
154
+ * Displays the mandatory indicator (asterisk) when the option is required.
155
+ * Follows true Radix pattern - separate component for each styleable element.
156
+ *
157
+ * @component
158
+ * @example
159
+ * ```tsx
160
+ * // Default usage - only renders if mandatory
161
+ * <Option.MandatoryIndicator className="text-red-500 ml-1" />
162
+ *
163
+ * // Custom rendering
164
+ * <Option.MandatoryIndicator asChild>
165
+ * {React.forwardRef<HTMLElement, { mandatory: boolean }>(({ mandatory, ...props }, ref) => (
166
+ * mandatory ? <span ref={ref} {...props} className="text-red-500">*</span> : null
167
+ * ))}
168
+ * </Option.MandatoryIndicator>
169
+ * ```
170
+ */
171
+ export const MandatoryIndicator = React.forwardRef((props, ref) => {
172
+ const { asChild, children, className } = props;
173
+ const optionData = React.useContext(OptionContext);
174
+ if (!optionData)
175
+ return null;
176
+ const mandatory = optionData.mandatory || false;
177
+ // Don't render anything if not mandatory
178
+ if (!mandatory)
179
+ return null;
180
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.optionMandatoryIndicator, customElement: children, customElementProps: { mandatory }, content: '*', children: _jsx("span", { children: "*" }) }));
181
+ });
182
+ /**
183
+ * Container for the list items with empty state support.
184
+ * Follows List Container Level pattern (inspired by Product.VariantOptions).
185
+ *
186
+ * @component
187
+ *
188
+ * **Data Attributes**
189
+ *
190
+ * - `data-testid="option-choices"` - Applied to choices container (TestIds.optionChoices)
191
+ * - `data-type` - The type of the option 'color' | 'text' | 'free-text'
192
+ *
193
+ * @example
194
+ * ```tsx
195
+ * // Default usage with empty state
196
+ * <Option.Choices emptyState={<div>No choices available</div>}>
197
+ * <Option.ChoiceRepeater>
198
+ * <Choice.Text />
199
+ * <Choice.Color />
200
+ * </Option.ChoiceRepeater>
201
+ * </Option.Choices>
202
+ *
203
+ * // Simple container usage
204
+ * <Option.Choices emptyState={<div>No choices</div>}>
205
+ * <div className="choices-grid">
206
+ * <Option.ChoiceRepeater>
207
+ * <Choice.Text />
208
+ * </Option.ChoiceRepeater>
209
+ * </div>
210
+ * </Option.Choices>
211
+ * ```
212
+ */
213
+ export const Choices = React.forwardRef((props, ref) => {
214
+ const { children, emptyState } = props;
215
+ const optionData = React.useContext(OptionContext);
216
+ if (!optionData)
217
+ return null;
218
+ // Check if we have choices to render (List Container Level pattern)
219
+ const hasChoicesOrFreeText = (optionData.choices && optionData.choices.length > 0) ||
220
+ optionData.optionType === 'free-text';
221
+ if (!hasChoicesOrFreeText) {
222
+ return emptyState || null;
223
+ }
224
+ const attributes = {
225
+ 'data-testid': TestIds.optionChoices,
226
+ 'data-type': optionData.optionType || 'text',
227
+ };
228
+ return (_jsx("div", { ...attributes, ref: ref, children: children }));
229
+ });
230
+ /**
231
+ * Repeater component that renders Choice.Root for each choice.
232
+ * Inspired by Product.VariantOptionRepeater pattern.
233
+ *
234
+ * Now handles ProductVariantSelector.Choice logic and provides ChoiceContext.
235
+ *
236
+ * @component
237
+ *
238
+ * @example
239
+ * ```tsx
240
+ * <Option.ChoiceRepeater>
241
+ * <Choice.Text />
242
+ * <Choice.Color />
243
+ * <Choice.FreeText />
244
+ * </Option.ChoiceRepeater>
245
+ * ```
246
+ */
247
+ export const ChoiceRepeater = React.forwardRef((props, _ref) => {
248
+ const { children } = props;
249
+ const optionData = React.useContext(OptionContext);
250
+ if (!optionData ||
251
+ (!optionData.choices?.length && optionData.optionType !== 'free-text'))
252
+ return null;
253
+ const onValueChange = optionData.onValueChange || (() => { });
254
+ const isModifier = optionData.type;
255
+ const allowedTypes = optionData.allowedTypes || [
256
+ 'color',
257
+ 'text',
258
+ 'free-text',
259
+ ];
260
+ if (optionData.optionType === 'free-text') {
261
+ // Check if free-text is allowed
262
+ if (!allowedTypes.includes('free-text')) {
263
+ return null;
264
+ }
265
+ const choice = {
266
+ ...optionData,
267
+ type: 'free-text',
268
+ };
269
+ return (_jsx(ProductModifiersPrimitive.Choice, { modifier: optionData, choice: choice, children: (renderProps) => {
270
+ const { value, isSelected, select } = renderProps;
271
+ const contextValue = {
272
+ choice,
273
+ onValueChange,
274
+ isSelected,
275
+ isVisible: true,
276
+ isInStock: true,
277
+ isPreOrderEnabled: true,
278
+ shouldRenderAsColor: false,
279
+ shouldRenderAsText: false,
280
+ shouldRenderAsFreeText: true,
281
+ select,
282
+ value,
283
+ };
284
+ return (_jsx(Choice.ChoiceContext.Provider, { value: contextValue, children: _jsx(Choice.Root, { children: children }) }));
285
+ } }));
286
+ }
287
+ return (_jsx(_Fragment, { children: optionData.choices.map((choice) => {
288
+ const choiceKey = choice.choiceId;
289
+ const getChoiceType = () => {
290
+ if (choice?.choiceType === 'ONE_COLOR')
291
+ return 'color';
292
+ if (choice?.choiceType === 'CHOICE_TEXT')
293
+ return 'text';
294
+ return 'text';
295
+ };
296
+ const choiceType = getChoiceType();
297
+ if (!allowedTypes.includes(choiceType)) {
298
+ return null;
299
+ }
300
+ const choiceData = {
301
+ ...choice,
302
+ type: choiceType,
303
+ };
304
+ if (isModifier) {
305
+ return (_jsx(ProductModifiersPrimitive.Choice, { modifier: optionData, choice: choiceData, children: (renderProps) => {
306
+ const { value, isSelected, select } = renderProps;
307
+ const contextValue = {
308
+ choice: choiceData,
309
+ onValueChange,
310
+ shouldRenderAsColor: choiceType === 'color',
311
+ shouldRenderAsText: choiceType === 'text',
312
+ shouldRenderAsFreeText: choiceType === 'free-text',
313
+ isSelected,
314
+ isVisible: true, // ProductModifiers doesn't provide visibility
315
+ isInStock: true, // ProductModifiers doesn't provide stock info
316
+ isPreOrderEnabled: true, // ProductModifiers doesn't provide pre-order info
317
+ select,
318
+ value,
319
+ };
320
+ return (_jsx(Choice.ChoiceContext.Provider, { value: contextValue, children: _jsx(Choice.Root, { children: children }) }));
321
+ } }, choiceKey));
322
+ }
323
+ else {
324
+ return (_jsx(ProductVariantSelectorPrimitive.Choice, { option: optionData, choice: choiceData, children: (renderProps) => {
325
+ const { value, isSelected, select, isVisible, isInStock, isPreOrderEnabled, } = renderProps;
326
+ // Don't render if not visible
327
+ if (!isVisible)
328
+ return null;
329
+ const contextValue = {
330
+ choice: choiceData,
331
+ onValueChange,
332
+ shouldRenderAsColor: choiceType === 'color',
333
+ shouldRenderAsText: choiceType === 'text',
334
+ shouldRenderAsFreeText: choiceType === 'free-text',
335
+ isSelected,
336
+ isVisible,
337
+ isInStock,
338
+ isPreOrderEnabled,
339
+ select,
340
+ value,
341
+ };
342
+ return (_jsx(Choice.ChoiceContext.Provider, { value: contextValue, children: _jsx(Choice.Root, { children: children }) }));
343
+ } }, choiceKey));
344
+ }
345
+ }) }));
346
+ });