@gem-sdk/core 2.2.0-staging.33 → 2.2.0-staging.50
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/dist/cjs/contexts/ProductContext.js +5 -0
- package/dist/cjs/helpers/third-party/getAppBlockConfig.js +1 -1
- package/dist/cjs/hooks/useProduct.js +6 -1
- package/dist/esm/contexts/ProductContext.js +5 -0
- package/dist/esm/helpers/third-party/getAppBlockConfig.js +1 -1
- package/dist/esm/hooks/useProduct.js +6 -1
- package/dist/types/index.d.ts +3 -0
- package/package.json +1 -1
|
@@ -120,6 +120,11 @@ const createProductStoreProvider = (data)=>zustand.createStore((set, get)=>({
|
|
|
120
120
|
set({
|
|
121
121
|
hasPreSelected: value
|
|
122
122
|
});
|
|
123
|
+
},
|
|
124
|
+
setIsChangeSelectedOption: (value)=>{
|
|
125
|
+
set({
|
|
126
|
+
isChangeSelectedOption: value
|
|
127
|
+
});
|
|
123
128
|
}
|
|
124
129
|
}));
|
|
125
130
|
const ProductProvider = ({ children, product, initialVariantId, quantity = 1, isSyncProduct })=>{
|
|
@@ -39,7 +39,7 @@ const getAppBlockConfig = (tag, appBlockId, settings)=>{
|
|
|
39
39
|
tag,
|
|
40
40
|
widgetType
|
|
41
41
|
});
|
|
42
|
-
const settingByWidget = appSetting.composeSettingsByWidgetType[tag][
|
|
42
|
+
const settingByWidget = appSetting.composeSettingsByWidgetType?.[tag]?.[widgetType];
|
|
43
43
|
const appSettings = appSetting.overrideSettings(tag, settingByWidget, settings);
|
|
44
44
|
return {
|
|
45
45
|
key: appBlockId,
|
|
@@ -110,6 +110,8 @@ const useSelectedOption = ()=>{
|
|
|
110
110
|
const selectedOptions = ProductContext.useProductStore((s)=>s.selectedOptions);
|
|
111
111
|
const forceSelectedOption = ProductContext.useProductStore((s)=>s.forceSelectedOption);
|
|
112
112
|
const isSyncProduct = ProductContext.useProductStore((s)=>s.isSyncProduct);
|
|
113
|
+
const isChangeSelectedOption = ProductContext.useProductStore((s)=>s.isChangeSelectedOption);
|
|
114
|
+
const setIsChangeSelectedOption = ProductContext.useProductStore((s)=>s.setIsChangeSelectedOption);
|
|
113
115
|
const updateOption = react.useCallback((optionId, optionValue, productId, noEmit)=>{
|
|
114
116
|
if (!noEmit && isSyncProduct) {
|
|
115
117
|
const setOption = new CustomEvent('set-selected-option', {
|
|
@@ -125,9 +127,11 @@ const useSelectedOption = ()=>{
|
|
|
125
127
|
window.dispatchEvent(setOption);
|
|
126
128
|
}
|
|
127
129
|
setSelectedOption(optionId, optionValue);
|
|
130
|
+
setIsChangeSelectedOption(true);
|
|
128
131
|
}, [
|
|
132
|
+
isSyncProduct,
|
|
129
133
|
setSelectedOption,
|
|
130
|
-
|
|
134
|
+
setIsChangeSelectedOption
|
|
131
135
|
]);
|
|
132
136
|
const forceOption = react.useCallback((selectedOption, productId, noEmit)=>{
|
|
133
137
|
if (!noEmit && isSyncProduct) {
|
|
@@ -148,6 +152,7 @@ const useSelectedOption = ()=>{
|
|
|
148
152
|
isSyncProduct
|
|
149
153
|
]);
|
|
150
154
|
return react.useMemo(()=>({
|
|
155
|
+
isChangeSelectedOption,
|
|
151
156
|
selectedOptions,
|
|
152
157
|
setSelectedOption: updateOption,
|
|
153
158
|
forceSelectedOption: forceOption
|
|
@@ -118,6 +118,11 @@ const createProductStoreProvider = (data)=>createStore((set, get)=>({
|
|
|
118
118
|
set({
|
|
119
119
|
hasPreSelected: value
|
|
120
120
|
});
|
|
121
|
+
},
|
|
122
|
+
setIsChangeSelectedOption: (value)=>{
|
|
123
|
+
set({
|
|
124
|
+
isChangeSelectedOption: value
|
|
125
|
+
});
|
|
121
126
|
}
|
|
122
127
|
}));
|
|
123
128
|
const ProductProvider = ({ children, product, initialVariantId, quantity = 1, isSyncProduct })=>{
|
|
@@ -37,7 +37,7 @@ const getAppBlockConfig = (tag, appBlockId, settings)=>{
|
|
|
37
37
|
tag,
|
|
38
38
|
widgetType
|
|
39
39
|
});
|
|
40
|
-
const settingByWidget = composeSettingsByWidgetType[tag][
|
|
40
|
+
const settingByWidget = composeSettingsByWidgetType?.[tag]?.[widgetType];
|
|
41
41
|
const appSettings = overrideSettings(tag, settingByWidget, settings);
|
|
42
42
|
return {
|
|
43
43
|
key: appBlockId,
|
|
@@ -108,6 +108,8 @@ const useSelectedOption = ()=>{
|
|
|
108
108
|
const selectedOptions = useProductStore((s)=>s.selectedOptions);
|
|
109
109
|
const forceSelectedOption = useProductStore((s)=>s.forceSelectedOption);
|
|
110
110
|
const isSyncProduct = useProductStore((s)=>s.isSyncProduct);
|
|
111
|
+
const isChangeSelectedOption = useProductStore((s)=>s.isChangeSelectedOption);
|
|
112
|
+
const setIsChangeSelectedOption = useProductStore((s)=>s.setIsChangeSelectedOption);
|
|
111
113
|
const updateOption = useCallback((optionId, optionValue, productId, noEmit)=>{
|
|
112
114
|
if (!noEmit && isSyncProduct) {
|
|
113
115
|
const setOption = new CustomEvent('set-selected-option', {
|
|
@@ -123,9 +125,11 @@ const useSelectedOption = ()=>{
|
|
|
123
125
|
window.dispatchEvent(setOption);
|
|
124
126
|
}
|
|
125
127
|
setSelectedOption(optionId, optionValue);
|
|
128
|
+
setIsChangeSelectedOption(true);
|
|
126
129
|
}, [
|
|
130
|
+
isSyncProduct,
|
|
127
131
|
setSelectedOption,
|
|
128
|
-
|
|
132
|
+
setIsChangeSelectedOption
|
|
129
133
|
]);
|
|
130
134
|
const forceOption = useCallback((selectedOption, productId, noEmit)=>{
|
|
131
135
|
if (!noEmit && isSyncProduct) {
|
|
@@ -146,6 +150,7 @@ const useSelectedOption = ()=>{
|
|
|
146
150
|
isSyncProduct
|
|
147
151
|
]);
|
|
148
152
|
return useMemo(()=>({
|
|
153
|
+
isChangeSelectedOption,
|
|
149
154
|
selectedOptions,
|
|
150
155
|
setSelectedOption: updateOption,
|
|
151
156
|
forceSelectedOption: forceOption
|
package/dist/types/index.d.ts
CHANGED
|
@@ -36178,6 +36178,8 @@ type ProductContextProps = {
|
|
|
36178
36178
|
setHasPreSelected: (value: boolean) => void;
|
|
36179
36179
|
useProductCompareAtPrice?: boolean;
|
|
36180
36180
|
setUseProductCompareAtPrice: (value?: boolean) => void;
|
|
36181
|
+
isChangeSelectedOption?: boolean;
|
|
36182
|
+
setIsChangeSelectedOption: (value: boolean) => void;
|
|
36181
36183
|
};
|
|
36182
36184
|
type ProductProviderProps = Pick<ProductContextProps, 'product' | 'quantity' | 'selectedOptions' | 'isSyncProduct'> & {
|
|
36183
36185
|
initialVariantId?: string;
|
|
@@ -44918,6 +44920,7 @@ declare const useHasPreSelected: () => {
|
|
|
44918
44920
|
setHasPreSelected: (value: boolean) => void;
|
|
44919
44921
|
};
|
|
44920
44922
|
declare const useSelectedOption: () => {
|
|
44923
|
+
isChangeSelectedOption: boolean | undefined;
|
|
44921
44924
|
selectedOptions: Record<string, string> | undefined;
|
|
44922
44925
|
setSelectedOption: (optionId?: Maybe$1<string>, optionValue?: Maybe$1<string>, productId?: Maybe$1<string>, noEmit?: boolean) => void;
|
|
44923
44926
|
forceSelectedOption: (selectedOption?: Record<string, string>, productId?: Maybe$1<string>, noEmit?: boolean) => void;
|