@wix/headless-stores 0.0.9 → 0.0.11
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/enums/index.d.ts +2 -0
- package/cjs/dist/enums/index.js +18 -0
- package/cjs/dist/enums/social-platform-enums.d.ts +25 -0
- package/cjs/dist/enums/social-platform-enums.js +30 -0
- package/cjs/dist/enums/sort-enums.d.ts +17 -0
- package/cjs/dist/enums/sort-enums.js +21 -0
- package/cjs/dist/react/BuyNow.d.ts +2 -4
- package/cjs/dist/react/Category.d.ts +15 -0
- package/cjs/dist/react/Category.js +22 -0
- package/cjs/dist/react/Collection.d.ts +151 -0
- package/cjs/dist/react/Collection.js +209 -0
- package/cjs/dist/react/FilteredCollection.d.ts +95 -0
- package/cjs/dist/react/FilteredCollection.js +150 -0
- package/cjs/dist/react/PayNow.d.ts +2 -4
- package/cjs/dist/react/Product.d.ts +43 -0
- package/cjs/dist/react/Product.js +35 -0
- package/cjs/dist/react/ProductActions.d.ts +42 -0
- package/cjs/dist/react/ProductActions.js +83 -0
- package/cjs/dist/react/ProductModifiers.d.ts +164 -0
- package/cjs/dist/react/ProductModifiers.js +168 -0
- package/cjs/dist/react/ProductVariantSelector.d.ts +153 -0
- package/cjs/dist/react/ProductVariantSelector.js +138 -0
- package/cjs/dist/react/RelatedProducts.d.ts +64 -0
- package/cjs/dist/react/RelatedProducts.js +73 -0
- package/cjs/dist/react/SelectedVariant.d.ts +66 -0
- package/cjs/dist/react/SelectedVariant.js +52 -0
- package/cjs/dist/react/SocialSharing.d.ts +112 -0
- package/cjs/dist/react/SocialSharing.js +86 -0
- package/cjs/dist/react/Sort.d.ts +14 -0
- package/cjs/dist/react/Sort.js +17 -0
- package/cjs/dist/react/index.d.ts +11 -0
- package/cjs/dist/react/index.js +34 -0
- package/cjs/dist/services/buy-now-service.js +2 -2
- package/cjs/dist/services/catalog-options-service.d.ts +30 -0
- package/cjs/dist/services/catalog-options-service.js +156 -0
- package/cjs/dist/services/catalog-price-range-service.d.ts +23 -0
- package/cjs/dist/services/catalog-price-range-service.js +97 -0
- package/cjs/dist/services/category-service.d.ts +26 -0
- package/cjs/dist/services/category-service.js +71 -0
- package/cjs/dist/services/collection-service.d.ts +37 -0
- package/cjs/dist/services/collection-service.js +569 -0
- package/cjs/dist/services/filter-service.d.ts +56 -0
- package/cjs/dist/services/filter-service.js +147 -0
- package/cjs/dist/services/product-media-gallery-service.d.ts +25 -0
- package/cjs/dist/services/product-media-gallery-service.js +105 -0
- package/cjs/dist/services/product-modifiers-service.d.ts +34 -0
- package/cjs/dist/services/product-modifiers-service.js +111 -0
- package/cjs/dist/services/product-service.d.ts +28 -0
- package/cjs/dist/services/product-service.js +68 -0
- package/cjs/dist/services/related-products-service.d.ts +25 -0
- package/cjs/dist/services/related-products-service.js +54 -0
- package/cjs/dist/services/selected-variant-service.d.ts +59 -0
- package/cjs/dist/services/selected-variant-service.js +541 -0
- package/cjs/dist/services/social-sharing-service.d.ts +41 -0
- package/cjs/dist/services/social-sharing-service.js +141 -0
- package/cjs/dist/services/sort-service.d.ts +20 -0
- package/cjs/dist/services/sort-service.js +32 -0
- package/cjs/dist/utils/url-params.d.ts +5 -0
- package/cjs/dist/utils/url-params.js +50 -0
- package/dist/enums/index.d.ts +2 -0
- package/dist/enums/index.js +2 -0
- package/dist/enums/social-platform-enums.d.ts +25 -0
- package/dist/enums/social-platform-enums.js +27 -0
- package/dist/enums/sort-enums.d.ts +17 -0
- package/dist/enums/sort-enums.js +18 -0
- package/dist/react/BuyNow.d.ts +2 -4
- package/dist/react/Category.d.ts +15 -0
- package/dist/react/Category.js +18 -0
- package/dist/react/Collection.d.ts +151 -0
- package/dist/react/Collection.js +201 -0
- package/dist/react/FilteredCollection.d.ts +95 -0
- package/dist/react/FilteredCollection.js +140 -0
- package/dist/react/PayNow.d.ts +2 -4
- package/dist/react/Product.d.ts +43 -0
- package/dist/react/Product.js +30 -0
- package/dist/react/ProductActions.d.ts +42 -0
- package/dist/react/ProductActions.js +79 -0
- package/dist/react/ProductModifiers.d.ts +164 -0
- package/dist/react/ProductModifiers.js +160 -0
- package/dist/react/ProductVariantSelector.d.ts +153 -0
- package/dist/react/ProductVariantSelector.js +130 -0
- package/dist/react/RelatedProducts.d.ts +64 -0
- package/dist/react/RelatedProducts.js +65 -0
- package/dist/react/SelectedVariant.d.ts +66 -0
- package/dist/react/SelectedVariant.js +46 -0
- package/dist/react/SocialSharing.d.ts +112 -0
- package/dist/react/SocialSharing.js +77 -0
- package/dist/react/Sort.d.ts +14 -0
- package/dist/react/Sort.js +14 -0
- package/dist/react/index.d.ts +11 -0
- package/dist/react/index.js +11 -0
- package/dist/services/buy-now-service.js +2 -2
- package/dist/services/catalog-options-service.d.ts +30 -0
- package/dist/services/catalog-options-service.js +152 -0
- package/dist/services/catalog-price-range-service.d.ts +23 -0
- package/dist/services/catalog-price-range-service.js +93 -0
- package/dist/services/category-service.d.ts +26 -0
- package/dist/services/category-service.js +67 -0
- package/dist/services/collection-service.d.ts +37 -0
- package/dist/services/collection-service.js +532 -0
- package/dist/services/filter-service.d.ts +56 -0
- package/dist/services/filter-service.js +144 -0
- package/dist/services/product-media-gallery-service.d.ts +25 -0
- package/dist/services/product-media-gallery-service.js +101 -0
- package/dist/services/product-modifiers-service.d.ts +34 -0
- package/dist/services/product-modifiers-service.js +107 -0
- package/dist/services/product-service.d.ts +28 -0
- package/dist/services/product-service.js +64 -0
- package/dist/services/related-products-service.d.ts +25 -0
- package/dist/services/related-products-service.js +50 -0
- package/dist/services/selected-variant-service.d.ts +59 -0
- package/dist/services/selected-variant-service.js +538 -0
- package/dist/services/social-sharing-service.d.ts +41 -0
- package/dist/services/social-sharing-service.js +137 -0
- package/dist/services/sort-service.d.ts +20 -0
- package/dist/services/sort-service.js +29 -0
- package/dist/utils/url-params.d.ts +5 -0
- package/dist/utils/url-params.js +46 -0
- package/package.json +8 -1
- package/dist/astro/BuyNowServiceContext.d.ts +0 -2
- package/dist/astro/BuyNowServiceContext.js +0 -6
- package/dist/astro/ManagerProviderContext.d.ts +0 -2
- package/dist/astro/ManagerProviderContext.js +0 -7
- package/dist/astro/withBuyButtonService.d.ts +0 -2
- package/dist/astro/withBuyButtonService.js +0 -16
- package/dist/react/CurrentCartServiceProvider.d.ts +0 -5
- package/dist/react/CurrentCartServiceProvider.js +0 -12
- package/dist/react/VariantSelectorServiceProvider.d.ts +0 -7
- package/dist/react/VariantSelectorServiceProvider.js +0 -22
- package/dist/react/hookim/index.d.ts +0 -5
- package/dist/react/hookim/index.js +0 -22
- package/dist/services/CurrentCartService.d.ts +0 -18
- package/dist/services/CurrentCartService.js +0 -9
- package/dist/services/VariantSelectorServices.d.ts +0 -8
- package/dist/services/VariantSelectorServices.js +0 -20
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToggleFreeText = exports.FreeText = exports.Choice = exports.Modifier = exports.Modifiers = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const services_manager_react_1 = require("@wix/services-manager-react");
|
|
6
|
+
const product_modifiers_service_1 = require("../services/product-modifiers-service");
|
|
7
|
+
const auto_sdk_stores_products_v_3_1 = require("@wix/auto_sdk_stores_products-v-3");
|
|
8
|
+
/**
|
|
9
|
+
* Custom hook to safely get the modifiers service
|
|
10
|
+
*/
|
|
11
|
+
function useModifiersService() {
|
|
12
|
+
try {
|
|
13
|
+
return (0, services_manager_react_1.useService)(product_modifiers_service_1.ProductModifiersServiceDefinition);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Headless component for all product modifiers
|
|
21
|
+
*/
|
|
22
|
+
const Modifiers = (props) => {
|
|
23
|
+
const modifiersService = useModifiersService();
|
|
24
|
+
if (!modifiersService) {
|
|
25
|
+
return props.children({
|
|
26
|
+
modifiers: [],
|
|
27
|
+
hasModifiers: false,
|
|
28
|
+
selectedModifiers: {},
|
|
29
|
+
areAllRequiredModifiersFilled: true,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const modifiers = modifiersService.modifiers.get();
|
|
33
|
+
const hasModifiers = modifiersService.hasModifiers.get();
|
|
34
|
+
const selectedModifiers = modifiersService.selectedModifiers.get();
|
|
35
|
+
const areAllRequiredModifiersFilled = modifiersService.areAllRequiredModifiersFilled();
|
|
36
|
+
return props.children({
|
|
37
|
+
modifiers,
|
|
38
|
+
hasModifiers,
|
|
39
|
+
selectedModifiers,
|
|
40
|
+
areAllRequiredModifiersFilled,
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.Modifiers = Modifiers;
|
|
44
|
+
/**
|
|
45
|
+
* Headless component for a specific product modifier
|
|
46
|
+
*
|
|
47
|
+
* @component
|
|
48
|
+
*/
|
|
49
|
+
const Modifier = (props) => {
|
|
50
|
+
const modifiersService = useModifiersService();
|
|
51
|
+
const { modifier } = props;
|
|
52
|
+
const name = modifier.name || '';
|
|
53
|
+
const type = modifier.modifierRenderType;
|
|
54
|
+
const mandatory = modifier.mandatory || false;
|
|
55
|
+
const choices = modifier.choicesSettings?.choices || [];
|
|
56
|
+
const hasChoices = choices.length > 0;
|
|
57
|
+
const isFreeText = type === auto_sdk_stores_products_v_3_1.ModifierRenderType.FREE_TEXT;
|
|
58
|
+
const freeTextSettings = modifier.freeTextSettings;
|
|
59
|
+
const maxChars = freeTextSettings?.maxLength;
|
|
60
|
+
const placeholder = freeTextSettings?.placeholder;
|
|
61
|
+
const selectedValue = modifiersService?.selectedModifiers.get()[name] || null;
|
|
62
|
+
return props.children({
|
|
63
|
+
name,
|
|
64
|
+
type,
|
|
65
|
+
mandatory,
|
|
66
|
+
choices,
|
|
67
|
+
selectedValue,
|
|
68
|
+
hasChoices,
|
|
69
|
+
isFreeText,
|
|
70
|
+
maxChars,
|
|
71
|
+
placeholder,
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
exports.Modifier = Modifier;
|
|
75
|
+
/**
|
|
76
|
+
* Headless component for individual modifier choice selection
|
|
77
|
+
*
|
|
78
|
+
* @component
|
|
79
|
+
*/
|
|
80
|
+
const Choice = (props) => {
|
|
81
|
+
const modifiersService = useModifiersService();
|
|
82
|
+
const { modifier, choice } = props;
|
|
83
|
+
const modifierName = modifier.name || '';
|
|
84
|
+
const renderType = modifier.modifierRenderType;
|
|
85
|
+
// For TEXT_CHOICES, use choice.key; for SWATCH_CHOICES, use choice.name
|
|
86
|
+
const choiceValue = renderType === auto_sdk_stores_products_v_3_1.ModifierRenderType.TEXT_CHOICES
|
|
87
|
+
? choice.key || choice.name || ''
|
|
88
|
+
: choice.name || '';
|
|
89
|
+
const value = choice.name || ''; // Display name is always choice.name
|
|
90
|
+
const description = choice.description;
|
|
91
|
+
const colorCode = choice.colorCode;
|
|
92
|
+
const selectedValue = modifiersService?.getModifierValue(modifierName);
|
|
93
|
+
const isSelected = selectedValue?.choiceValue === choiceValue;
|
|
94
|
+
const onSelect = () => {
|
|
95
|
+
modifiersService?.setModifierChoice(modifierName, choiceValue);
|
|
96
|
+
};
|
|
97
|
+
return props.children({
|
|
98
|
+
value,
|
|
99
|
+
description,
|
|
100
|
+
isSelected,
|
|
101
|
+
onSelect,
|
|
102
|
+
modifierName,
|
|
103
|
+
choiceValue,
|
|
104
|
+
colorCode,
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
exports.Choice = Choice;
|
|
108
|
+
/**
|
|
109
|
+
* Headless component for free text modifier input
|
|
110
|
+
*
|
|
111
|
+
* @component
|
|
112
|
+
*/
|
|
113
|
+
const FreeText = (props) => {
|
|
114
|
+
const modifiersService = useModifiersService();
|
|
115
|
+
const { modifier } = props;
|
|
116
|
+
const modifierName = modifier.name || '';
|
|
117
|
+
const mandatory = modifier.mandatory || false;
|
|
118
|
+
const freeTextSettings = modifier.freeTextSettings;
|
|
119
|
+
const maxChars = freeTextSettings?.maxLength;
|
|
120
|
+
const placeholder = freeTextSettings?.placeholder;
|
|
121
|
+
const selectedValue = modifiersService?.getModifierValue(modifierName);
|
|
122
|
+
const value = selectedValue?.freeTextValue || '';
|
|
123
|
+
const charCount = value.length;
|
|
124
|
+
const isOverLimit = maxChars ? charCount > maxChars : false;
|
|
125
|
+
const onChange = (newValue) => {
|
|
126
|
+
if (maxChars && newValue.length > maxChars)
|
|
127
|
+
return;
|
|
128
|
+
modifiersService?.setModifierFreeText(modifierName, newValue);
|
|
129
|
+
};
|
|
130
|
+
return props.children({
|
|
131
|
+
value,
|
|
132
|
+
onChange,
|
|
133
|
+
mandatory,
|
|
134
|
+
maxChars,
|
|
135
|
+
placeholder,
|
|
136
|
+
charCount,
|
|
137
|
+
isOverLimit,
|
|
138
|
+
modifierName,
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
exports.FreeText = FreeText;
|
|
142
|
+
/**
|
|
143
|
+
* Headless component for toggling free text modifier input
|
|
144
|
+
* Used for optional free text modifiers where a checkbox shows/hides the input
|
|
145
|
+
*
|
|
146
|
+
* @component
|
|
147
|
+
*/
|
|
148
|
+
const ToggleFreeText = (props) => {
|
|
149
|
+
const modifiersService = useModifiersService();
|
|
150
|
+
const { modifier } = props;
|
|
151
|
+
const modifierName = modifier.name || '';
|
|
152
|
+
const mandatory = modifier.mandatory || false;
|
|
153
|
+
const [isTextInputShown, setIsTextInputShown] = (0, react_1.useState)(mandatory);
|
|
154
|
+
const onToggle = () => {
|
|
155
|
+
const newState = !isTextInputShown;
|
|
156
|
+
setIsTextInputShown(newState);
|
|
157
|
+
if (!newState) {
|
|
158
|
+
modifiersService?.clearModifier(modifierName);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
return props.children({
|
|
162
|
+
isTextInputShown,
|
|
163
|
+
onToggle,
|
|
164
|
+
mandatory,
|
|
165
|
+
modifierName,
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
exports.ToggleFreeText = ToggleFreeText;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type ConnectedOption, type ConnectedOptionChoice, InventoryAvailabilityStatus } from '@wix/auto_sdk_stores_products-v-3';
|
|
2
|
+
/**
|
|
3
|
+
* Props for Options headless component
|
|
4
|
+
*/
|
|
5
|
+
export interface OptionsProps {
|
|
6
|
+
/** Render prop function that receives options data */
|
|
7
|
+
children: (props: OptionsRenderProps) => React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Render props for Options component
|
|
11
|
+
*/
|
|
12
|
+
export interface OptionsRenderProps {
|
|
13
|
+
/** Array of product options */
|
|
14
|
+
options: ConnectedOption[];
|
|
15
|
+
/** Whether product has options */
|
|
16
|
+
hasOptions: boolean;
|
|
17
|
+
/** Currently selected choices */
|
|
18
|
+
selectedChoices: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Headless component for all product options
|
|
22
|
+
*
|
|
23
|
+
* @component
|
|
24
|
+
*/
|
|
25
|
+
export declare const Options: (props: OptionsProps) => import("react").ReactNode;
|
|
26
|
+
/**
|
|
27
|
+
* Props for Option headless component
|
|
28
|
+
*/
|
|
29
|
+
export interface OptionProps {
|
|
30
|
+
/** Product option data */
|
|
31
|
+
option: ConnectedOption;
|
|
32
|
+
/** Render prop function that receives option data */
|
|
33
|
+
children: (props: OptionRenderProps) => React.ReactNode;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Render props for Option component
|
|
37
|
+
*/
|
|
38
|
+
export interface OptionRenderProps {
|
|
39
|
+
/** Option name */
|
|
40
|
+
name: string;
|
|
41
|
+
/** Option type */
|
|
42
|
+
type: any;
|
|
43
|
+
/** Array of choices for this option */
|
|
44
|
+
choices: ConnectedOptionChoice[];
|
|
45
|
+
/** Currently selected value for this option */
|
|
46
|
+
selectedValue: string | null;
|
|
47
|
+
/** Whether this option has choices */
|
|
48
|
+
hasChoices: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Headless component for choices within a specific product option
|
|
52
|
+
*
|
|
53
|
+
* @component
|
|
54
|
+
*/
|
|
55
|
+
export declare const Option: (props: OptionProps) => import("react").ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* Props for Choice headless component
|
|
58
|
+
*/
|
|
59
|
+
export interface ChoiceProps {
|
|
60
|
+
/** Product option data */
|
|
61
|
+
option: ConnectedOption;
|
|
62
|
+
/** Choice data */
|
|
63
|
+
choice: ConnectedOptionChoice;
|
|
64
|
+
/** Render prop function that receives choice data */
|
|
65
|
+
children: (props: ChoiceRenderProps) => React.ReactNode;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Render props for Choice component
|
|
69
|
+
*/
|
|
70
|
+
export interface ChoiceRenderProps {
|
|
71
|
+
/** Choice value to display */
|
|
72
|
+
value: string;
|
|
73
|
+
/** Choice description (for color options) */
|
|
74
|
+
description: string | undefined;
|
|
75
|
+
/** Whether this choice is currently selected */
|
|
76
|
+
isSelected: boolean;
|
|
77
|
+
/** Whether this choice is visible */
|
|
78
|
+
isVisible: boolean;
|
|
79
|
+
/** Whether this choice is in stock */
|
|
80
|
+
isInStock: boolean;
|
|
81
|
+
/** Whether this choice is available for pre-order */
|
|
82
|
+
isPreOrderEnabled: boolean;
|
|
83
|
+
/** Function to select this choice */
|
|
84
|
+
onSelect: () => void;
|
|
85
|
+
/** Option name */
|
|
86
|
+
optionName: string;
|
|
87
|
+
/** Choice value */
|
|
88
|
+
choiceValue: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Headless component for individual choice selection
|
|
92
|
+
*
|
|
93
|
+
* @component
|
|
94
|
+
*/
|
|
95
|
+
export declare const Choice: (props: ChoiceProps) => import("react").ReactNode;
|
|
96
|
+
/**
|
|
97
|
+
* Props for Stock headless component
|
|
98
|
+
*/
|
|
99
|
+
export interface StockProps {
|
|
100
|
+
/** Render prop function that receives stock data */
|
|
101
|
+
children: (props: StockRenderProps) => React.ReactNode;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Render props for Stock component
|
|
105
|
+
*/
|
|
106
|
+
export interface StockRenderProps {
|
|
107
|
+
/** Whether product is in stock */
|
|
108
|
+
inStock: boolean;
|
|
109
|
+
/** Whether pre-order is enabled */
|
|
110
|
+
isPreOrderEnabled: boolean;
|
|
111
|
+
/** Raw inventory availability status */
|
|
112
|
+
availabilityStatus: InventoryAvailabilityStatus | string;
|
|
113
|
+
/** Whether stock tracking is enabled */
|
|
114
|
+
trackInventory: boolean;
|
|
115
|
+
/** Current variant id */
|
|
116
|
+
currentVariantId: string | null;
|
|
117
|
+
/** Available quantity */
|
|
118
|
+
availableQuantity: number | null;
|
|
119
|
+
/** Currently selected quantity */
|
|
120
|
+
selectedQuantity: number;
|
|
121
|
+
/** Function to increment quantity */
|
|
122
|
+
incrementQuantity: () => void;
|
|
123
|
+
/** Function to decrement quantity */
|
|
124
|
+
decrementQuantity: () => void;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Headless component for product stock status
|
|
128
|
+
*
|
|
129
|
+
* @component
|
|
130
|
+
*/
|
|
131
|
+
export declare const Stock: (props: StockProps) => import("react").ReactNode;
|
|
132
|
+
/**
|
|
133
|
+
* Props for Reset headless component
|
|
134
|
+
*/
|
|
135
|
+
export interface ResetProps {
|
|
136
|
+
/** Render prop function that receives reset data */
|
|
137
|
+
children: (props: ResetRenderProps) => React.ReactNode;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Render props for Reset component
|
|
141
|
+
*/
|
|
142
|
+
export interface ResetRenderProps {
|
|
143
|
+
/** Function to reset all selections */
|
|
144
|
+
onReset: () => void;
|
|
145
|
+
/** Whether the reset button should be rendered */
|
|
146
|
+
hasSelections: boolean;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Headless component for resetting variant selections
|
|
150
|
+
*
|
|
151
|
+
* @component
|
|
152
|
+
*/
|
|
153
|
+
export declare const Reset: (props: ResetProps) => import("react").ReactNode;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Reset = exports.Stock = exports.Choice = exports.Option = exports.Options = void 0;
|
|
4
|
+
const services_manager_react_1 = require("@wix/services-manager-react");
|
|
5
|
+
const selected_variant_service_1 = require("../services/selected-variant-service");
|
|
6
|
+
const auto_sdk_stores_products_v_3_1 = require("@wix/auto_sdk_stores_products-v-3");
|
|
7
|
+
/**
|
|
8
|
+
* Headless component for all product options
|
|
9
|
+
*
|
|
10
|
+
* @component
|
|
11
|
+
*/
|
|
12
|
+
const Options = (props) => {
|
|
13
|
+
const variantService = (0, services_manager_react_1.useService)(selected_variant_service_1.SelectedVariantServiceDefinition);
|
|
14
|
+
const selectedChoices = variantService.selectedChoices.get();
|
|
15
|
+
const options = variantService.productOptions.get();
|
|
16
|
+
return props.children({
|
|
17
|
+
options,
|
|
18
|
+
hasOptions: options.length > 0,
|
|
19
|
+
selectedChoices,
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
exports.Options = Options;
|
|
23
|
+
/**
|
|
24
|
+
* Headless component for choices within a specific product option
|
|
25
|
+
*
|
|
26
|
+
* @component
|
|
27
|
+
*/
|
|
28
|
+
const Option = (props) => {
|
|
29
|
+
const variantService = (0, services_manager_react_1.useService)(selected_variant_service_1.SelectedVariantServiceDefinition);
|
|
30
|
+
const selectedChoices = variantService.selectedChoices.get();
|
|
31
|
+
const { option } = props;
|
|
32
|
+
const name = option.name || '';
|
|
33
|
+
const choices = option.choicesSettings?.choices || [];
|
|
34
|
+
const selectedValue = selectedChoices[name] || null;
|
|
35
|
+
return props.children({
|
|
36
|
+
name,
|
|
37
|
+
type: option.optionRenderType,
|
|
38
|
+
choices,
|
|
39
|
+
selectedValue,
|
|
40
|
+
hasChoices: choices.length > 0,
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.Option = Option;
|
|
44
|
+
/**
|
|
45
|
+
* Headless component for individual choice selection
|
|
46
|
+
*
|
|
47
|
+
* @component
|
|
48
|
+
*/
|
|
49
|
+
const Choice = (props) => {
|
|
50
|
+
const variantService = (0, services_manager_react_1.useService)(selected_variant_service_1.SelectedVariantServiceDefinition);
|
|
51
|
+
const selectedChoices = variantService.selectedChoices.get();
|
|
52
|
+
const { option, choice } = props;
|
|
53
|
+
const optionName = option.name || '';
|
|
54
|
+
const choiceValue = choice.name || '';
|
|
55
|
+
const isSelected = selectedChoices[optionName] === choiceValue;
|
|
56
|
+
// Check if this choice is available based on current selections
|
|
57
|
+
const isVisible = variantService.isChoiceAvailable(optionName, choiceValue);
|
|
58
|
+
// Check if this choice results in an in-stock variant
|
|
59
|
+
const isInStock = variantService.isChoiceInStock(optionName, choiceValue);
|
|
60
|
+
// Check if this choice is available for pre-order
|
|
61
|
+
const isPreOrderEnabled = variantService.isChoicePreOrderEnabled(optionName, choiceValue);
|
|
62
|
+
const value = choiceValue;
|
|
63
|
+
const onSelect = () => {
|
|
64
|
+
const newChoices = {
|
|
65
|
+
...selectedChoices,
|
|
66
|
+
[optionName]: choiceValue,
|
|
67
|
+
};
|
|
68
|
+
variantService.setSelectedChoices(newChoices);
|
|
69
|
+
};
|
|
70
|
+
return props.children({
|
|
71
|
+
value,
|
|
72
|
+
description: undefined, // v3 choices don't have separate description field
|
|
73
|
+
isSelected,
|
|
74
|
+
isVisible,
|
|
75
|
+
isInStock,
|
|
76
|
+
isPreOrderEnabled,
|
|
77
|
+
onSelect,
|
|
78
|
+
optionName,
|
|
79
|
+
choiceValue,
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
exports.Choice = Choice;
|
|
83
|
+
/**
|
|
84
|
+
* Headless component for product stock status
|
|
85
|
+
*
|
|
86
|
+
* @component
|
|
87
|
+
*/
|
|
88
|
+
const Stock = (props) => {
|
|
89
|
+
const variantService = (0, services_manager_react_1.useService)(selected_variant_service_1.SelectedVariantServiceDefinition);
|
|
90
|
+
const inStock = variantService.isInStock.get();
|
|
91
|
+
const isPreOrderEnabled = variantService.isPreOrderEnabled.get();
|
|
92
|
+
const trackInventory = variantService.trackQuantity.get();
|
|
93
|
+
const currentVariantId = variantService.selectedVariantId.get();
|
|
94
|
+
const availableQuantity = variantService.quantityAvailable.get();
|
|
95
|
+
const selectedQuantity = variantService.selectedQuantity.get();
|
|
96
|
+
// const currentVariant = variantService.currentVariant.get();
|
|
97
|
+
// const allVariantsAreOutOfStock = variantService.IsAllVariantsAreOutOfStock();
|
|
98
|
+
// Return raw availability status - UI components will handle display conversion
|
|
99
|
+
const availabilityStatus = inStock
|
|
100
|
+
? auto_sdk_stores_products_v_3_1.InventoryAvailabilityStatus.IN_STOCK
|
|
101
|
+
: auto_sdk_stores_products_v_3_1.InventoryAvailabilityStatus.OUT_OF_STOCK;
|
|
102
|
+
const incrementQuantity = () => {
|
|
103
|
+
variantService.incrementQuantity();
|
|
104
|
+
};
|
|
105
|
+
const decrementQuantity = () => {
|
|
106
|
+
variantService.decrementQuantity();
|
|
107
|
+
};
|
|
108
|
+
return props.children({
|
|
109
|
+
inStock,
|
|
110
|
+
availableQuantity,
|
|
111
|
+
isPreOrderEnabled,
|
|
112
|
+
currentVariantId,
|
|
113
|
+
availabilityStatus,
|
|
114
|
+
trackInventory,
|
|
115
|
+
selectedQuantity,
|
|
116
|
+
incrementQuantity,
|
|
117
|
+
decrementQuantity,
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
exports.Stock = Stock;
|
|
121
|
+
/**
|
|
122
|
+
* Headless component for resetting variant selections
|
|
123
|
+
*
|
|
124
|
+
* @component
|
|
125
|
+
*/
|
|
126
|
+
const Reset = (props) => {
|
|
127
|
+
const variantService = (0, services_manager_react_1.useService)(selected_variant_service_1.SelectedVariantServiceDefinition);
|
|
128
|
+
const selectedChoices = variantService.selectedChoices.get();
|
|
129
|
+
const hasSelections = Object.keys(selectedChoices).length > 0;
|
|
130
|
+
const onReset = () => {
|
|
131
|
+
variantService.resetSelections();
|
|
132
|
+
};
|
|
133
|
+
return props.children({
|
|
134
|
+
onReset,
|
|
135
|
+
hasSelections,
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
exports.Reset = Reset;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type V3Product } from '@wix/auto_sdk_stores_products-v-3';
|
|
3
|
+
/**
|
|
4
|
+
* Props for List headless component
|
|
5
|
+
*/
|
|
6
|
+
export interface ListProps {
|
|
7
|
+
/** Render prop function that receives list data */
|
|
8
|
+
children: (props: ListRenderProps) => React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Render props for List component
|
|
12
|
+
*/
|
|
13
|
+
export interface ListRenderProps {
|
|
14
|
+
/** Array of related products */
|
|
15
|
+
products: V3Product[];
|
|
16
|
+
/** Whether products are loading */
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
/** Error message if any */
|
|
19
|
+
error: string | null;
|
|
20
|
+
/** Whether there are products available */
|
|
21
|
+
hasProducts: boolean;
|
|
22
|
+
/** Function to refresh products */
|
|
23
|
+
refresh: () => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Headless component for displaying related products list
|
|
27
|
+
*
|
|
28
|
+
* @component
|
|
29
|
+
*/
|
|
30
|
+
export declare const List: (props: ListProps) => React.ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* Props for Item headless component
|
|
33
|
+
*/
|
|
34
|
+
export interface ItemProps {
|
|
35
|
+
/** Product data */
|
|
36
|
+
product: V3Product;
|
|
37
|
+
/** Render prop function that receives item data */
|
|
38
|
+
children: (props: ItemRenderProps) => React.ReactNode;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Render props for Item component
|
|
42
|
+
*/
|
|
43
|
+
export interface ItemRenderProps {
|
|
44
|
+
/** Product title */
|
|
45
|
+
title: string;
|
|
46
|
+
/** Product image URL */
|
|
47
|
+
image: string | null;
|
|
48
|
+
/** Formatted price */
|
|
49
|
+
price: string;
|
|
50
|
+
/** Whether product is available */
|
|
51
|
+
available: boolean;
|
|
52
|
+
/** Product page URL */
|
|
53
|
+
href: string;
|
|
54
|
+
/** Product description */
|
|
55
|
+
description: string;
|
|
56
|
+
/** Function to add product to cart quickly */
|
|
57
|
+
onQuickAdd: () => void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Headless component for individual related product item
|
|
61
|
+
*
|
|
62
|
+
* @component
|
|
63
|
+
*/
|
|
64
|
+
export declare const Item: (props: ItemProps) => React.ReactNode;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Item = exports.List = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const services_manager_react_1 = require("@wix/services-manager-react");
|
|
9
|
+
const related_products_service_1 = require("../services/related-products-service");
|
|
10
|
+
const auto_sdk_stores_products_v_3_1 = require("@wix/auto_sdk_stores_products-v-3");
|
|
11
|
+
/**
|
|
12
|
+
* Headless component for displaying related products list
|
|
13
|
+
*
|
|
14
|
+
* @component
|
|
15
|
+
*/
|
|
16
|
+
const List = (props) => {
|
|
17
|
+
const service = (0, services_manager_react_1.useService)(related_products_service_1.RelatedProductsServiceDefinition);
|
|
18
|
+
const [products, setProducts] = react_1.default.useState([]);
|
|
19
|
+
const [isLoading, setIsLoading] = react_1.default.useState(false);
|
|
20
|
+
const [error, setError] = react_1.default.useState(null);
|
|
21
|
+
const [hasProducts, setHasProducts] = react_1.default.useState(false);
|
|
22
|
+
react_1.default.useEffect(() => {
|
|
23
|
+
const unsubscribes = [
|
|
24
|
+
service.relatedProducts.subscribe(setProducts),
|
|
25
|
+
service.isLoading.subscribe(setIsLoading),
|
|
26
|
+
service.error.subscribe(setError),
|
|
27
|
+
service.hasRelatedProducts.subscribe(setHasProducts),
|
|
28
|
+
];
|
|
29
|
+
return () => unsubscribes.forEach(fn => fn());
|
|
30
|
+
}, [service]);
|
|
31
|
+
return props.children({
|
|
32
|
+
products,
|
|
33
|
+
isLoading,
|
|
34
|
+
error,
|
|
35
|
+
hasProducts,
|
|
36
|
+
refresh: service.refreshRelatedProducts,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
exports.List = List;
|
|
40
|
+
/**
|
|
41
|
+
* Headless component for individual related product item
|
|
42
|
+
*
|
|
43
|
+
* @component
|
|
44
|
+
*/
|
|
45
|
+
const Item = (props) => {
|
|
46
|
+
const { product } = props;
|
|
47
|
+
const title = product.name || 'Unknown Product';
|
|
48
|
+
// Use actual v3 media structure - image is directly a string URL
|
|
49
|
+
const image = product.media?.main?.image || null;
|
|
50
|
+
// Create formatted price from raw amount since formattedAmount may not be available
|
|
51
|
+
const rawPrice = product.actualPriceRange?.minValue?.amount;
|
|
52
|
+
const price = rawPrice ? `$${rawPrice}` : 'Price unavailable';
|
|
53
|
+
const availabilityStatus = product.inventory?.availabilityStatus;
|
|
54
|
+
const available = availabilityStatus === auto_sdk_stores_products_v_3_1.InventoryAvailabilityStatus.IN_STOCK ||
|
|
55
|
+
availabilityStatus === auto_sdk_stores_products_v_3_1.InventoryAvailabilityStatus.PARTIALLY_OUT_OF_STOCK;
|
|
56
|
+
const href = `/store/example-2/${product.slug}`;
|
|
57
|
+
const description = typeof product.description === 'string' ? product.description : '';
|
|
58
|
+
const handleQuickAdd = () => {
|
|
59
|
+
// This would typically add the product to cart
|
|
60
|
+
// For now, we'll just log it
|
|
61
|
+
console.log('Quick add:', product.name);
|
|
62
|
+
};
|
|
63
|
+
return props.children({
|
|
64
|
+
title,
|
|
65
|
+
image,
|
|
66
|
+
price,
|
|
67
|
+
available,
|
|
68
|
+
href,
|
|
69
|
+
description,
|
|
70
|
+
onQuickAdd: handleQuickAdd,
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
exports.Item = Item;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Props for ProductDetails headless component
|
|
3
|
+
*/
|
|
4
|
+
export interface ProductDetailsProps {
|
|
5
|
+
/** Render prop function that receives product details data */
|
|
6
|
+
children: (props: ProductDetailsRenderProps) => React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Render props for ProductDetails component
|
|
10
|
+
*/
|
|
11
|
+
export interface ProductDetailsRenderProps {
|
|
12
|
+
/** Product SKU */
|
|
13
|
+
sku: string | null;
|
|
14
|
+
/** Product weight */
|
|
15
|
+
weight: string | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Headless component for selected variant details display
|
|
19
|
+
*
|
|
20
|
+
* @component
|
|
21
|
+
*/
|
|
22
|
+
export declare const Details: (props: ProductDetailsProps) => import("react").ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Props for Price headless component
|
|
25
|
+
*/
|
|
26
|
+
export interface PriceProps {
|
|
27
|
+
/** Render prop function that receives price data */
|
|
28
|
+
children: (props: PriceRenderProps) => React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Render props for Price component
|
|
32
|
+
*/
|
|
33
|
+
export interface PriceRenderProps {
|
|
34
|
+
/** Current price (formatted) */
|
|
35
|
+
price: string;
|
|
36
|
+
/** Compare at price (formatted) - null if no compare price */
|
|
37
|
+
compareAtPrice: string | null;
|
|
38
|
+
/** Currency code */
|
|
39
|
+
currency: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Headless component for product price display
|
|
43
|
+
*
|
|
44
|
+
* @component
|
|
45
|
+
*/
|
|
46
|
+
export declare const Price: (props: PriceProps) => import("react").ReactNode;
|
|
47
|
+
/**
|
|
48
|
+
* Props for SKU headless component
|
|
49
|
+
*/
|
|
50
|
+
export interface SKUProps {
|
|
51
|
+
/** Render prop function that receives SKU data */
|
|
52
|
+
children: (props: SKURenderProps) => React.ReactNode;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Render props for SKU component
|
|
56
|
+
*/
|
|
57
|
+
export interface SKURenderProps {
|
|
58
|
+
/** Product SKU */
|
|
59
|
+
sku: string | null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Headless component for product SKU display
|
|
63
|
+
*
|
|
64
|
+
* @component
|
|
65
|
+
*/
|
|
66
|
+
export declare const SKU: (props: SKUProps) => import("react").ReactNode;
|