@gem-sdk/core 1.14.0-next.239 → 1.14.0-next.243
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var react=require("react"),ProductContext=require("../contexts/ProductContext.js"),flattenConnection=require("../helpers/flatten-connection.js");require("swr");var product=require("../helpers/product.js");require("../helpers/convert.js");var variant=require("../helpers/variant.js");const useUniqProductID=()=>ProductContext.useProductStore(e=>e.uiqueId),useProduct=()=>ProductContext.useProductStore(e=>e.product),useFeaturedImageGlobal=()=>ProductContext.useProductStore(e=>e.featuredImageGlobal),useProductProperties=()=>ProductContext.useProductStore(e=>e.properties),useIsSyncProduct=()=>ProductContext.useProductStore(e=>e.isSyncProduct),useQuantity=()=>{let e=ProductContext.useProductStore(e=>e.quantity),t=ProductContext.useProductStore(e=>e.decrementQuantity),r=ProductContext.useProductStore(e=>e.incrementQuantity),u=ProductContext.useProductStore(e=>e.setQuantity),o=react.useCallback(()=>{u(1)},[u]);return react.useMemo(()=>({quantity:e,increment:r,decrement:t,reset:
|
|
1
|
+
"use strict";var react=require("react"),ProductContext=require("../contexts/ProductContext.js"),flattenConnection=require("../helpers/flatten-connection.js");require("swr");var product=require("../helpers/product.js");require("../helpers/convert.js");var variant=require("../helpers/variant.js");const useUniqProductID=()=>ProductContext.useProductStore(e=>e.uiqueId),useProduct=()=>ProductContext.useProductStore(e=>e.product),useFeaturedImageGlobal=()=>ProductContext.useProductStore(e=>e.featuredImageGlobal),useProductProperties=()=>ProductContext.useProductStore(e=>e.properties),useIsSyncProduct=()=>ProductContext.useProductStore(e=>e.isSyncProduct),useQuantity=()=>{let e=ProductContext.useProductStore(e=>e.quantity),t=ProductContext.useProductStore(e=>e.decrementQuantity),r=ProductContext.useProductStore(e=>e.incrementQuantity),u=ProductContext.useProductStore(e=>e.setQuantity),o=ProductContext.useProductStore(e=>e.isSyncProduct),n=ProductContext.useProductStore(e=>e.product),s=n?.id,c=react.useCallback(()=>{u(1)},[u]);return react.useEffect(()=>{if(o){let t=new CustomEvent("set-product-quantity",{bubbles:!0,cancelable:!0,composed:!0,detail:{quantity:e,productId:s}});window.dispatchEvent(t)}},[e,o,s]),react.useMemo(()=>({quantity:e,increment:r,decrement:t,reset:c,setQuantity:u}),[t,r,e,c,u])},useSelectedOption=()=>{let e=ProductContext.useProductStore(e=>e.setSelectedOption),t=ProductContext.useProductStore(e=>e.selectedOptions),r=ProductContext.useProductStore(e=>e.forceSelectedOption),u=ProductContext.useProductStore(e=>e.isSyncProduct),o=react.useCallback((t,r,o,n)=>{if(!n&&u){let e=new CustomEvent("set-selected-option",{bubbles:!0,cancelable:!0,composed:!0,detail:{optionId:t,optionValue:r,productId:o}});window.dispatchEvent(e)}e(t,r)},[e,u]),n=react.useCallback((e,t,o)=>{if(!o&&u){let r=new CustomEvent("force-selected-option",{bubbles:!0,cancelable:!0,composed:!0,detail:{selectedOption:e,productId:t}});window.dispatchEvent(r)}r(e)},[r,u]);return react.useMemo(()=>({selectedOptions:t,setSelectedOption:o,forceSelectedOption:n}),[t,o,n])},useVariants=()=>{let e=ProductContext.useProductStore(e=>e.product?.variants);return flattenConnection.flattenConnection(e)},useVariant=e=>{let t=useVariants();return react.useMemo(()=>t?.find(t=>t?.id===e),[e,t])},useCurrentVariant=()=>{let{selectedOptions:e}=useSelectedOption(),t=useVariants();return react.useMemo(()=>product.getSelectedVariant(t,e),[e,t])},useCurrentVariantInStock=()=>{let e=useCurrentVariant(),t=variant.checkInStock(e);return t},useVariantOutStock=(e,t)=>{let{selectedOptions:r}=useSelectedOption(),u=useVariants(),o=product.getSelectedVariant(u,{...r,[e]:t}),n=variant.checkInStock(o);return!n},useCheckAvailableVariantInStock=(e,t)=>{let r=useVariants();return!!r&&r.some(r=>{if(r){let{selectedOptions:u}=r,o=u?.some(r=>r?.name===e&&r.value===t),n=variant.checkInStock(r);return o&&n}return!1})};exports.useCheckAvailableVariantInStock=useCheckAvailableVariantInStock,exports.useCurrentVariant=useCurrentVariant,exports.useCurrentVariantInStock=useCurrentVariantInStock,exports.useFeaturedImageGlobal=useFeaturedImageGlobal,exports.useIsSyncProduct=useIsSyncProduct,exports.useProduct=useProduct,exports.useProductProperties=useProductProperties,exports.useQuantity=useQuantity,exports.useSelectedOption=useSelectedOption,exports.useUniqProductID=useUniqProductID,exports.useVariant=useVariant,exports.useVariantOutStock=useVariantOutStock,exports.useVariants=useVariants;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback as e,useMemo as
|
|
1
|
+
import{useCallback as e,useEffect as t,useMemo as r}from"react";import{useProductStore as n}from"../contexts/ProductContext.js";import{flattenConnection as u}from"../helpers/flatten-connection.js";import"swr";import{getSelectedVariant as s}from"../helpers/product.js";import"../helpers/convert.js";import{checkInStock as o}from"../helpers/variant.js";let useUniqProductID=()=>n(e=>e.uiqueId),useProduct=()=>n(e=>e.product),useFeaturedImageGlobal=()=>n(e=>e.featuredImageGlobal),useProductProperties=()=>n(e=>e.properties),useIsSyncProduct=()=>n(e=>e.isSyncProduct),useQuantity=()=>{let u=n(e=>e.quantity),s=n(e=>e.decrementQuantity),o=n(e=>e.incrementQuantity),a=n(e=>e.setQuantity),i=n(e=>e.isSyncProduct),c=n(e=>e.product),l=c?.id,d=e(()=>{a(1)},[a]);return t(()=>{if(i){let e=new CustomEvent("set-product-quantity",{bubbles:!0,cancelable:!0,composed:!0,detail:{quantity:u,productId:l}});window.dispatchEvent(e)}},[u,i,l]),r(()=>({quantity:u,increment:o,decrement:s,reset:d,setQuantity:a}),[s,o,u,d,a])},useSelectedOption=()=>{let t=n(e=>e.setSelectedOption),u=n(e=>e.selectedOptions),s=n(e=>e.forceSelectedOption),o=n(e=>e.isSyncProduct),a=e((e,r,n,u)=>{if(!u&&o){let t=new CustomEvent("set-selected-option",{bubbles:!0,cancelable:!0,composed:!0,detail:{optionId:e,optionValue:r,productId:n}});window.dispatchEvent(t)}t(e,r)},[t,o]),i=e((e,t,r)=>{if(!r&&o){let r=new CustomEvent("force-selected-option",{bubbles:!0,cancelable:!0,composed:!0,detail:{selectedOption:e,productId:t}});window.dispatchEvent(r)}s(e)},[s,o]);return r(()=>({selectedOptions:u,setSelectedOption:a,forceSelectedOption:i}),[u,a,i])},useVariants=()=>{let e=n(e=>e.product?.variants);return u(e)},useVariant=e=>{let t=useVariants();return r(()=>t?.find(t=>t?.id===e),[e,t])},useCurrentVariant=()=>{let{selectedOptions:e}=useSelectedOption(),t=useVariants();return r(()=>s(t,e),[e,t])},useCurrentVariantInStock=()=>{let e=useCurrentVariant(),t=o(e);return t},useVariantOutStock=(e,t)=>{let{selectedOptions:r}=useSelectedOption(),n=useVariants(),u=s(n,{...r,[e]:t}),a=o(u);return!a},useCheckAvailableVariantInStock=(e,t)=>{let r=useVariants();return!!r&&r.some(r=>{if(r){let{selectedOptions:n}=r,u=n?.some(r=>r?.name===e&&r.value===t),s=o(r);return u&&s}return!1})};export{useCheckAvailableVariantInStock,useCurrentVariant,useCurrentVariantInStock,useFeaturedImageGlobal,useIsSyncProduct,useProduct,useProductProperties,useQuantity,useSelectedOption,useUniqProductID,useVariant,useVariantOutStock,useVariants};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -143,7 +143,7 @@ type HyperlinkInfo = {
|
|
|
143
143
|
link?: string;
|
|
144
144
|
modal?: CommonModalApp;
|
|
145
145
|
};
|
|
146
|
-
type Mapped$
|
|
146
|
+
type Mapped$5<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
147
147
|
id: K;
|
|
148
148
|
label?: string;
|
|
149
149
|
info?: string;
|
|
@@ -211,7 +211,7 @@ type Mapped$4<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
|
211
211
|
default?: T;
|
|
212
212
|
};
|
|
213
213
|
type SharedControlType<T> = {
|
|
214
|
-
[K in keyof T]-?: Mapped$
|
|
214
|
+
[K in keyof T]-?: Mapped$5<K, T[K]>;
|
|
215
215
|
}[keyof T];
|
|
216
216
|
|
|
217
217
|
type AngleControlType<T> = SharedControlType<T> & {
|
|
@@ -228,7 +228,7 @@ type Option$3<T> = {
|
|
|
228
228
|
text: string | number;
|
|
229
229
|
desc?: any;
|
|
230
230
|
};
|
|
231
|
-
type Mapped$
|
|
231
|
+
type Mapped$4<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
232
232
|
id: K;
|
|
233
233
|
label: string;
|
|
234
234
|
hideOnMode?: {
|
|
@@ -266,7 +266,7 @@ type Mapped$3<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
|
266
266
|
default?: T;
|
|
267
267
|
};
|
|
268
268
|
type CheckboxControlType<T> = {
|
|
269
|
-
[K in keyof T]-?: Mapped$
|
|
269
|
+
[K in keyof T]-?: Mapped$4<K, T[K]>;
|
|
270
270
|
}[keyof T];
|
|
271
271
|
|
|
272
272
|
type ChildrensControlType = {
|
|
@@ -402,7 +402,7 @@ type Option$2<T> = {
|
|
|
402
402
|
type?: string;
|
|
403
403
|
icon?: string;
|
|
404
404
|
};
|
|
405
|
-
type Mapped$
|
|
405
|
+
type Mapped$3<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
406
406
|
id: K;
|
|
407
407
|
label?: string;
|
|
408
408
|
info?: string;
|
|
@@ -446,7 +446,7 @@ type Mapped$2<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
|
446
446
|
default?: T;
|
|
447
447
|
};
|
|
448
448
|
type SegmentControlType<T> = {
|
|
449
|
-
[K in keyof T]-?: Mapped$
|
|
449
|
+
[K in keyof T]-?: Mapped$3<K, T[K]>;
|
|
450
450
|
}[keyof T];
|
|
451
451
|
|
|
452
452
|
type Option$1<T> = {
|
|
@@ -454,7 +454,7 @@ type Option$1<T> = {
|
|
|
454
454
|
label: string | number;
|
|
455
455
|
hideOnPage?: string[];
|
|
456
456
|
};
|
|
457
|
-
type Mapped$
|
|
457
|
+
type Mapped$2<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
458
458
|
id: K;
|
|
459
459
|
label?: string;
|
|
460
460
|
info?: string;
|
|
@@ -496,7 +496,7 @@ type Mapped$1<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
|
496
496
|
default?: T;
|
|
497
497
|
};
|
|
498
498
|
type SelectControlType<T> = {
|
|
499
|
-
[K in keyof T]-?: Mapped$
|
|
499
|
+
[K in keyof T]-?: Mapped$2<K, T[K]>;
|
|
500
500
|
}[keyof T];
|
|
501
501
|
|
|
502
502
|
type TextareaControlType<T> = SharedControlType<T> & {
|
|
@@ -707,7 +707,7 @@ type Option<T> = {
|
|
|
707
707
|
icon?: string;
|
|
708
708
|
isTextIcon?: boolean;
|
|
709
709
|
};
|
|
710
|
-
type Mapped<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
710
|
+
type Mapped$1<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
711
711
|
id: K;
|
|
712
712
|
label: string;
|
|
713
713
|
info?: string;
|
|
@@ -756,7 +756,7 @@ type Mapped<K, T> = NonNullable<T> extends ObjectDevices<infer U> ? {
|
|
|
756
756
|
default?: T;
|
|
757
757
|
};
|
|
758
758
|
type LayoutSegmentControlType<T> = {
|
|
759
|
-
[K in keyof T]-?: Mapped<K, T[K]>;
|
|
759
|
+
[K in keyof T]-?: Mapped$1<K, T[K]>;
|
|
760
760
|
}[keyof T];
|
|
761
761
|
|
|
762
762
|
type InputSpacing<T> = SharedControlType<T> & {
|
|
@@ -855,7 +855,36 @@ type SyncProductPropertiesControlType<T> = SharedControlType<T> & {
|
|
|
855
855
|
type: 'sync-product-properties';
|
|
856
856
|
};
|
|
857
857
|
|
|
858
|
-
type
|
|
858
|
+
type Steps<T> = {
|
|
859
|
+
label?: string | number;
|
|
860
|
+
type?: string;
|
|
861
|
+
icon?: string;
|
|
862
|
+
value: T;
|
|
863
|
+
actions?: Actions[];
|
|
864
|
+
};
|
|
865
|
+
type Actions = {
|
|
866
|
+
label?: string | number;
|
|
867
|
+
type?: 'tertiary' | 'primary';
|
|
868
|
+
size?: 'large' | 'medium' | 'small';
|
|
869
|
+
icon?: string;
|
|
870
|
+
iconPosition?: 'left' | 'right';
|
|
871
|
+
buttonType?: 'link' | 'action';
|
|
872
|
+
actionHandle?: string;
|
|
873
|
+
link?: string;
|
|
874
|
+
};
|
|
875
|
+
type Mapped<K, T> = {
|
|
876
|
+
id: K;
|
|
877
|
+
label: string;
|
|
878
|
+
info?: string;
|
|
879
|
+
type: 'steps-guide';
|
|
880
|
+
steps?: Steps<T>[];
|
|
881
|
+
default?: T;
|
|
882
|
+
};
|
|
883
|
+
type StepsGuide<T> = {
|
|
884
|
+
[K in keyof T]-?: Mapped<K, T[K]>;
|
|
885
|
+
}[keyof T];
|
|
886
|
+
|
|
887
|
+
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> | VariantSwatchesPresetControlType<T> | ProductListControlType<T> | CollectionBannerControlType<T> | Ratio<T> | ImageShape<T> | GridArrange<T> | StickyDisplayControlType<T> | SyncProductPropertiesControlType<T> | StepsGuide<T>;
|
|
859
888
|
type Setting<P extends BaseProps> = {
|
|
860
889
|
id: 'setting';
|
|
861
890
|
note?: string;
|