@gem-sdk/core 2.2.0 → 2.4.7
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.
|
@@ -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 })=>{
|
|
@@ -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 })=>{
|
|
@@ -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
|
@@ -36175,6 +36175,8 @@ type ProductContextProps = {
|
|
|
36175
36175
|
setHasPreSelected: (value: boolean) => void;
|
|
36176
36176
|
useProductCompareAtPrice?: boolean;
|
|
36177
36177
|
setUseProductCompareAtPrice: (value?: boolean) => void;
|
|
36178
|
+
isChangeSelectedOption?: boolean;
|
|
36179
|
+
setIsChangeSelectedOption: (value: boolean) => void;
|
|
36178
36180
|
};
|
|
36179
36181
|
type ProductProviderProps = Pick<ProductContextProps, 'product' | 'quantity' | 'selectedOptions' | 'isSyncProduct'> & {
|
|
36180
36182
|
initialVariantId?: string;
|
|
@@ -44915,6 +44917,7 @@ declare const useHasPreSelected: () => {
|
|
|
44915
44917
|
setHasPreSelected: (value: boolean) => void;
|
|
44916
44918
|
};
|
|
44917
44919
|
declare const useSelectedOption: () => {
|
|
44920
|
+
isChangeSelectedOption: boolean | undefined;
|
|
44918
44921
|
selectedOptions: Record<string, string> | undefined;
|
|
44919
44922
|
setSelectedOption: (optionId?: Maybe$1<string>, optionValue?: Maybe$1<string>, productId?: Maybe$1<string>, noEmit?: boolean) => void;
|
|
44920
44923
|
forceSelectedOption: (selectedOption?: Record<string, string>, productId?: Maybe$1<string>, noEmit?: boolean) => void;
|