@gem-sdk/core 1.21.10 → 1.22.0-hotfix.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.
- package/dist/cjs/hooks/useProduct.js +28 -4
- package/dist/esm/hooks/useProduct.js +29 -5
- package/dist/types/index.d.ts +41 -11
- package/package.json +1 -1
|
@@ -28,11 +28,32 @@ const useQuantity = ()=>{
|
|
|
28
28
|
const decrement = ProductContext.useProductStore((s)=>s.decrementQuantity);
|
|
29
29
|
const increment = ProductContext.useProductStore((s)=>s.incrementQuantity);
|
|
30
30
|
const updateQuantity = ProductContext.useProductStore((s)=>s.setQuantity);
|
|
31
|
+
const isSyncProduct = ProductContext.useProductStore((s)=>s.isSyncProduct);
|
|
32
|
+
const product = ProductContext.useProductStore((s)=>s.product);
|
|
33
|
+
const productId = product?.id;
|
|
31
34
|
const reset = react.useCallback(()=>{
|
|
32
35
|
updateQuantity(1);
|
|
33
36
|
}, [
|
|
34
37
|
updateQuantity
|
|
35
38
|
]);
|
|
39
|
+
react.useEffect(()=>{
|
|
40
|
+
if (isSyncProduct) {
|
|
41
|
+
const setOption = new CustomEvent('set-product-quantity', {
|
|
42
|
+
bubbles: true,
|
|
43
|
+
cancelable: true,
|
|
44
|
+
composed: true,
|
|
45
|
+
detail: {
|
|
46
|
+
quantity,
|
|
47
|
+
productId
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
window.dispatchEvent(setOption);
|
|
51
|
+
}
|
|
52
|
+
}, [
|
|
53
|
+
quantity,
|
|
54
|
+
isSyncProduct,
|
|
55
|
+
productId
|
|
56
|
+
]);
|
|
36
57
|
return react.useMemo(()=>({
|
|
37
58
|
quantity,
|
|
38
59
|
increment,
|
|
@@ -51,8 +72,9 @@ const useSelectedOption = ()=>{
|
|
|
51
72
|
const setSelectedOption = ProductContext.useProductStore((s)=>s.setSelectedOption);
|
|
52
73
|
const selectedOptions = ProductContext.useProductStore((s)=>s.selectedOptions);
|
|
53
74
|
const forceSelectedOption = ProductContext.useProductStore((s)=>s.forceSelectedOption);
|
|
75
|
+
const isSyncProduct = ProductContext.useProductStore((s)=>s.isSyncProduct);
|
|
54
76
|
const updateOption = react.useCallback((optionId, optionValue, productId, noEmit)=>{
|
|
55
|
-
if (!noEmit) {
|
|
77
|
+
if (!noEmit && isSyncProduct) {
|
|
56
78
|
const setOption = new CustomEvent('set-selected-option', {
|
|
57
79
|
bubbles: true,
|
|
58
80
|
cancelable: true,
|
|
@@ -67,10 +89,11 @@ const useSelectedOption = ()=>{
|
|
|
67
89
|
}
|
|
68
90
|
setSelectedOption(optionId, optionValue);
|
|
69
91
|
}, [
|
|
70
|
-
setSelectedOption
|
|
92
|
+
setSelectedOption,
|
|
93
|
+
isSyncProduct
|
|
71
94
|
]);
|
|
72
95
|
const forceOption = react.useCallback((selectedOption, productId, noEmit)=>{
|
|
73
|
-
if (!noEmit) {
|
|
96
|
+
if (!noEmit && isSyncProduct) {
|
|
74
97
|
const forceOption = new CustomEvent('force-selected-option', {
|
|
75
98
|
bubbles: true,
|
|
76
99
|
cancelable: true,
|
|
@@ -84,7 +107,8 @@ const useSelectedOption = ()=>{
|
|
|
84
107
|
}
|
|
85
108
|
forceSelectedOption(selectedOption);
|
|
86
109
|
}, [
|
|
87
|
-
forceSelectedOption
|
|
110
|
+
forceSelectedOption,
|
|
111
|
+
isSyncProduct
|
|
88
112
|
]);
|
|
89
113
|
return react.useMemo(()=>({
|
|
90
114
|
selectedOptions,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
2
2
|
import { useProductStore } from '../contexts/ProductContext.js';
|
|
3
3
|
import { flattenConnection } from '../helpers/flatten-connection.js';
|
|
4
4
|
import 'swr';
|
|
@@ -26,11 +26,32 @@ const useQuantity = ()=>{
|
|
|
26
26
|
const decrement = useProductStore((s)=>s.decrementQuantity);
|
|
27
27
|
const increment = useProductStore((s)=>s.incrementQuantity);
|
|
28
28
|
const updateQuantity = useProductStore((s)=>s.setQuantity);
|
|
29
|
+
const isSyncProduct = useProductStore((s)=>s.isSyncProduct);
|
|
30
|
+
const product = useProductStore((s)=>s.product);
|
|
31
|
+
const productId = product?.id;
|
|
29
32
|
const reset = useCallback(()=>{
|
|
30
33
|
updateQuantity(1);
|
|
31
34
|
}, [
|
|
32
35
|
updateQuantity
|
|
33
36
|
]);
|
|
37
|
+
useEffect(()=>{
|
|
38
|
+
if (isSyncProduct) {
|
|
39
|
+
const setOption = new CustomEvent('set-product-quantity', {
|
|
40
|
+
bubbles: true,
|
|
41
|
+
cancelable: true,
|
|
42
|
+
composed: true,
|
|
43
|
+
detail: {
|
|
44
|
+
quantity,
|
|
45
|
+
productId
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
window.dispatchEvent(setOption);
|
|
49
|
+
}
|
|
50
|
+
}, [
|
|
51
|
+
quantity,
|
|
52
|
+
isSyncProduct,
|
|
53
|
+
productId
|
|
54
|
+
]);
|
|
34
55
|
return useMemo(()=>({
|
|
35
56
|
quantity,
|
|
36
57
|
increment,
|
|
@@ -49,8 +70,9 @@ const useSelectedOption = ()=>{
|
|
|
49
70
|
const setSelectedOption = useProductStore((s)=>s.setSelectedOption);
|
|
50
71
|
const selectedOptions = useProductStore((s)=>s.selectedOptions);
|
|
51
72
|
const forceSelectedOption = useProductStore((s)=>s.forceSelectedOption);
|
|
73
|
+
const isSyncProduct = useProductStore((s)=>s.isSyncProduct);
|
|
52
74
|
const updateOption = useCallback((optionId, optionValue, productId, noEmit)=>{
|
|
53
|
-
if (!noEmit) {
|
|
75
|
+
if (!noEmit && isSyncProduct) {
|
|
54
76
|
const setOption = new CustomEvent('set-selected-option', {
|
|
55
77
|
bubbles: true,
|
|
56
78
|
cancelable: true,
|
|
@@ -65,10 +87,11 @@ const useSelectedOption = ()=>{
|
|
|
65
87
|
}
|
|
66
88
|
setSelectedOption(optionId, optionValue);
|
|
67
89
|
}, [
|
|
68
|
-
setSelectedOption
|
|
90
|
+
setSelectedOption,
|
|
91
|
+
isSyncProduct
|
|
69
92
|
]);
|
|
70
93
|
const forceOption = useCallback((selectedOption, productId, noEmit)=>{
|
|
71
|
-
if (!noEmit) {
|
|
94
|
+
if (!noEmit && isSyncProduct) {
|
|
72
95
|
const forceOption = new CustomEvent('force-selected-option', {
|
|
73
96
|
bubbles: true,
|
|
74
97
|
cancelable: true,
|
|
@@ -82,7 +105,8 @@ const useSelectedOption = ()=>{
|
|
|
82
105
|
}
|
|
83
106
|
forceSelectedOption(selectedOption);
|
|
84
107
|
}, [
|
|
85
|
-
forceSelectedOption
|
|
108
|
+
forceSelectedOption,
|
|
109
|
+
isSyncProduct
|
|
86
110
|
]);
|
|
87
111
|
return useMemo(()=>({
|
|
88
112
|
selectedOptions,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -171,7 +171,7 @@ type HyperlinkInfo = {
|
|
|
171
171
|
link?: string;
|
|
172
172
|
modal?: CommonModalApp;
|
|
173
173
|
};
|
|
174
|
-
type Mapped$
|
|
174
|
+
type Mapped$5<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
175
175
|
id: K;
|
|
176
176
|
label?: string;
|
|
177
177
|
info?: string;
|
|
@@ -237,7 +237,7 @@ type Mapped$4<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
|
237
237
|
default?: T;
|
|
238
238
|
};
|
|
239
239
|
type SharedControlType<T> = {
|
|
240
|
-
[K in keyof T]-?: Mapped$
|
|
240
|
+
[K in keyof T]-?: Mapped$5<K, T[K]>;
|
|
241
241
|
}[keyof T];
|
|
242
242
|
|
|
243
243
|
type AngleControlType<T> = SharedControlType<T> & {
|
|
@@ -254,7 +254,7 @@ type Option$3<T> = {
|
|
|
254
254
|
text: string | number;
|
|
255
255
|
desc?: any;
|
|
256
256
|
};
|
|
257
|
-
type Mapped$
|
|
257
|
+
type Mapped$4<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
258
258
|
id: K;
|
|
259
259
|
label: string;
|
|
260
260
|
hideOnMode?: {
|
|
@@ -292,7 +292,7 @@ type Mapped$3<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
|
292
292
|
default?: T;
|
|
293
293
|
};
|
|
294
294
|
type CheckboxControlType<T> = {
|
|
295
|
-
[K in keyof T]-?: Mapped$
|
|
295
|
+
[K in keyof T]-?: Mapped$4<K, T[K]>;
|
|
296
296
|
}[keyof T];
|
|
297
297
|
|
|
298
298
|
type ChildrensControlType = {
|
|
@@ -428,7 +428,7 @@ type Option$2<T> = {
|
|
|
428
428
|
type?: string;
|
|
429
429
|
icon?: string;
|
|
430
430
|
};
|
|
431
|
-
type Mapped$
|
|
431
|
+
type Mapped$3<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
432
432
|
id: K;
|
|
433
433
|
label?: string;
|
|
434
434
|
info?: string;
|
|
@@ -472,7 +472,7 @@ type Mapped$2<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
|
472
472
|
default?: T;
|
|
473
473
|
};
|
|
474
474
|
type SegmentControlType<T> = {
|
|
475
|
-
[K in keyof T]-?: Mapped$
|
|
475
|
+
[K in keyof T]-?: Mapped$3<K, T[K]>;
|
|
476
476
|
}[keyof T];
|
|
477
477
|
|
|
478
478
|
type Option$1<T> = {
|
|
@@ -480,7 +480,7 @@ type Option$1<T> = {
|
|
|
480
480
|
label: string | number;
|
|
481
481
|
hideOnPage?: string[];
|
|
482
482
|
};
|
|
483
|
-
type Mapped$
|
|
483
|
+
type Mapped$2<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
484
484
|
id: K;
|
|
485
485
|
label?: string;
|
|
486
486
|
info?: string;
|
|
@@ -522,7 +522,7 @@ type Mapped$1<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
|
522
522
|
default?: T;
|
|
523
523
|
};
|
|
524
524
|
type SelectControlType<T> = {
|
|
525
|
-
[K in keyof T]-?: Mapped$
|
|
525
|
+
[K in keyof T]-?: Mapped$2<K, T[K]>;
|
|
526
526
|
}[keyof T];
|
|
527
527
|
|
|
528
528
|
type TextareaControlType<T> = SharedControlType<T> & {
|
|
@@ -729,7 +729,7 @@ type Option<T> = {
|
|
|
729
729
|
type?: string;
|
|
730
730
|
icon?: string;
|
|
731
731
|
};
|
|
732
|
-
type Mapped<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
732
|
+
type Mapped$1<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
733
733
|
id: K;
|
|
734
734
|
label: string;
|
|
735
735
|
info?: string;
|
|
@@ -775,7 +775,7 @@ type Mapped<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
|
775
775
|
default?: T;
|
|
776
776
|
};
|
|
777
777
|
type LayoutSegmentControlType<T> = {
|
|
778
|
-
[K in keyof T]-?: Mapped<K, T[K]>;
|
|
778
|
+
[K in keyof T]-?: Mapped$1<K, T[K]>;
|
|
779
779
|
}[keyof T];
|
|
780
780
|
|
|
781
781
|
type InputSpacing<T> = SharedControlType<T> & {
|
|
@@ -858,7 +858,36 @@ type SyncProductPropertiesControlType<T> = SharedControlType<T> & {
|
|
|
858
858
|
type: 'sync-product-properties';
|
|
859
859
|
};
|
|
860
860
|
|
|
861
|
-
type
|
|
861
|
+
type Steps<T> = {
|
|
862
|
+
label?: string | number;
|
|
863
|
+
type?: string;
|
|
864
|
+
icon?: string;
|
|
865
|
+
value: T;
|
|
866
|
+
actions?: Actions[];
|
|
867
|
+
};
|
|
868
|
+
type Actions = {
|
|
869
|
+
label?: string | number;
|
|
870
|
+
type?: 'tertiary' | 'primary';
|
|
871
|
+
size?: 'large' | 'medium' | 'small';
|
|
872
|
+
icon?: string;
|
|
873
|
+
iconPosition?: 'left' | 'right';
|
|
874
|
+
buttonType?: 'link' | 'action';
|
|
875
|
+
actionHandle?: string;
|
|
876
|
+
link?: string;
|
|
877
|
+
};
|
|
878
|
+
type Mapped<K, T> = {
|
|
879
|
+
id: K;
|
|
880
|
+
label: string;
|
|
881
|
+
info?: string;
|
|
882
|
+
type: 'steps-guide';
|
|
883
|
+
steps?: Steps<T>[];
|
|
884
|
+
default?: T;
|
|
885
|
+
};
|
|
886
|
+
type StepsGuide<T> = {
|
|
887
|
+
[K in keyof T]-?: Mapped<K, T[K]>;
|
|
888
|
+
}[keyof T];
|
|
889
|
+
|
|
890
|
+
type ControlProp<T> = AngleControlType<T> | CheckboxControlType<T> | ColorPickerControlType<T> | GroupControlType<T> | IconControlType<T> | InputFixContentControlType<T> | InputNumberControlType<T> | InputUnitControlType<T> | InputUnitSpacingControlType<T> | InputUnitWidthControlType<T> | InputControlType<T> | MarginControlType<T> | PaddingControlType<T> | PositionControlType<T> | RadioGroupControlType | RangeControlType<T> | SegmentControlType<T> | SelectControlType<T> | TextareaControlType<T> | ToggleControlType<T> | ImageControlType<T> | ChildrensControlType | GridControlType<T> | FlexControlType<T> | TextEditorControlType<T> | ProductControlType<T> | TypographyControlType<T> | TypographyV2ControlType<T> | MenuControlType<T> | BehaviorStateControlType<T> | PickLinkControlType<T> | BoxShadowControlType<T> | TextShadowControlType<T> | BorderControlType<T> | BorderRadiusControlType<T> | RadiusPresetControlType<T> | SizeControlType<T> | ChildItemType<T> | PickMultiProductControlType<T> | CollectionControlType<T> | BackgroundControlType<T> | VisibilityControlType<T> | SelectVariantControlType | CountdownEvergreenType | Timezone<T> | CustomContentControlType<T> | DateTimePickerControlType | CountdownDailyType | KlaviyoCodes | YotpoLoyaltyCodes | InputWidthControlType<T> | LayoutSegmentControlType<T> | InputSpacing<T> | UniqueIdControlType<T> | PositionSquareControlType<T> | CustomCodeEditor | LayoutControlType<T> | SwatchesLinkControlType<T> | ProductListControlType<T> | CollectionBannerControlType<T> | Ratio<T> | StickyDisplayControlType<T> | SyncProductPropertiesControlType<T> | StepsGuide<T>;
|
|
862
891
|
type Setting<P extends BaseProps> = {
|
|
863
892
|
id: 'setting';
|
|
864
893
|
note?: string;
|
|
@@ -948,6 +977,7 @@ type ControlUI = {
|
|
|
948
977
|
};
|
|
949
978
|
hideOnPages?: PageType[];
|
|
950
979
|
};
|
|
980
|
+
isMoreSetting?: boolean;
|
|
951
981
|
};
|
|
952
982
|
type PageType = 'ARTICLE' | 'BLOG' | 'COLLECTION' | 'GP_ARTICLE' | 'GP_BLOG' | 'GP_COLLECTION' | 'GP_INDEX' | 'GP_PRODUCT' | 'GP_STATIC' | 'PRODUCT' | 'STATIC';
|
|
953
983
|
type ComponentPreset = {
|