@gem-sdk/core 1.13.24 → 1.13.42

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.
Files changed (88) hide show
  1. package/dist/cjs/components/AddOn.js +1 -1
  2. package/dist/cjs/components/ComponentWrapper.js +1 -1
  3. package/dist/cjs/components/ComponentWrapperPreview.js +1 -1
  4. package/dist/cjs/components/Render.js +2 -2
  5. package/dist/cjs/components/Render.liquid.js +1 -1
  6. package/dist/cjs/components/RenderBlock.js +2 -2
  7. package/dist/cjs/components/RenderPreview.js +2 -2
  8. package/dist/cjs/components/RenderSection.js +1 -1
  9. package/dist/cjs/contexts/AddonContext.js +1 -1
  10. package/dist/cjs/contexts/BuilderComponent.js +1 -1
  11. package/dist/cjs/contexts/BuilderContext.js +1 -1
  12. package/dist/cjs/contexts/BuilderPreviewContext.js +4 -4
  13. package/dist/cjs/contexts/CartLineContext.js +1 -1
  14. package/dist/cjs/contexts/CollectionContext.js +2 -2
  15. package/dist/cjs/contexts/ModalContext.js +1 -1
  16. package/dist/cjs/contexts/ProductContext.js +1 -1
  17. package/dist/cjs/contexts/ProductListContext.js +1 -1
  18. package/dist/cjs/contexts/SectionContext.js +2 -2
  19. package/dist/cjs/contexts/ShopContext.js +2 -2
  20. package/dist/cjs/graphql/fragments/collection.generated.js +1 -0
  21. package/dist/cjs/helpers/borders.js +1 -1
  22. package/dist/cjs/helpers/compose-advance-style.js +2 -2
  23. package/dist/cjs/helpers/product.js +15 -1
  24. package/dist/cjs/helpers/queries/get-collection.js +1 -1
  25. package/dist/cjs/helpers/queries/get-product.js +4 -4
  26. package/dist/cjs/helpers/queries/get-products.js +4 -4
  27. package/dist/cjs/helpers/radius.js +1 -1
  28. package/dist/cjs/helpers/shadow.js +5 -5
  29. package/dist/cjs/helpers/typography.js +4 -4
  30. package/dist/cjs/hooks/cart/use-add-to-cart.js +2 -2
  31. package/dist/cjs/hooks/cart/use-cart-data.js +1 -1
  32. package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +2 -2
  33. package/dist/cjs/hooks/cart/use-cart-note-update.js +2 -2
  34. package/dist/cjs/hooks/cart/use-create-cart.js +2 -2
  35. package/dist/cjs/hooks/cart/use-remove-cart-item.js +2 -2
  36. package/dist/cjs/hooks/cart/use-update-cart-item.js +2 -2
  37. package/dist/cjs/hooks/shop.js +4 -4
  38. package/dist/cjs/hooks/useFetchHandle.js +1 -1
  39. package/dist/cjs/hooks/useFormatMoney.js +1 -1
  40. package/dist/cjs/hooks/useMoney.js +2 -2
  41. package/dist/cjs/hooks/useProduct.js +8 -11
  42. package/dist/cjs/hooks/useSwatchesOptions.js +1 -1
  43. package/dist/cjs/index.js +1 -0
  44. package/dist/esm/components/AddOn.js +1 -1
  45. package/dist/esm/components/ComponentWrapper.js +1 -1
  46. package/dist/esm/components/ComponentWrapperPreview.js +1 -1
  47. package/dist/esm/components/Render.js +2 -2
  48. package/dist/esm/components/Render.liquid.js +1 -1
  49. package/dist/esm/components/RenderBlock.js +2 -2
  50. package/dist/esm/components/RenderPreview.js +2 -2
  51. package/dist/esm/components/RenderSection.js +1 -1
  52. package/dist/esm/contexts/AddonContext.js +1 -1
  53. package/dist/esm/contexts/BuilderComponent.js +1 -1
  54. package/dist/esm/contexts/BuilderContext.js +1 -1
  55. package/dist/esm/contexts/BuilderPreviewContext.js +4 -4
  56. package/dist/esm/contexts/CartLineContext.js +1 -1
  57. package/dist/esm/contexts/CollectionContext.js +2 -2
  58. package/dist/esm/contexts/ModalContext.js +1 -1
  59. package/dist/esm/contexts/ProductContext.js +1 -1
  60. package/dist/esm/contexts/ProductListContext.js +1 -1
  61. package/dist/esm/contexts/SectionContext.js +2 -2
  62. package/dist/esm/contexts/ShopContext.js +2 -2
  63. package/dist/esm/graphql/fragments/collection.generated.js +1 -0
  64. package/dist/esm/helpers/borders.js +1 -1
  65. package/dist/esm/helpers/compose-advance-style.js +2 -2
  66. package/dist/esm/helpers/product.js +15 -2
  67. package/dist/esm/helpers/queries/get-collection.js +1 -1
  68. package/dist/esm/helpers/queries/get-product.js +4 -4
  69. package/dist/esm/helpers/queries/get-products.js +4 -4
  70. package/dist/esm/helpers/radius.js +1 -1
  71. package/dist/esm/helpers/shadow.js +5 -5
  72. package/dist/esm/helpers/typography.js +4 -4
  73. package/dist/esm/hooks/cart/use-add-to-cart.js +2 -2
  74. package/dist/esm/hooks/cart/use-cart-data.js +1 -1
  75. package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +2 -2
  76. package/dist/esm/hooks/cart/use-cart-note-update.js +2 -2
  77. package/dist/esm/hooks/cart/use-create-cart.js +2 -2
  78. package/dist/esm/hooks/cart/use-remove-cart-item.js +2 -2
  79. package/dist/esm/hooks/cart/use-update-cart-item.js +2 -2
  80. package/dist/esm/hooks/shop.js +4 -4
  81. package/dist/esm/hooks/useFetchHandle.js +1 -1
  82. package/dist/esm/hooks/useFormatMoney.js +1 -1
  83. package/dist/esm/hooks/useMoney.js +2 -2
  84. package/dist/esm/hooks/useProduct.js +8 -11
  85. package/dist/esm/hooks/useSwatchesOptions.js +1 -1
  86. package/dist/esm/index.js +1 -1
  87. package/dist/types/index.d.ts +6 -3
  88. package/package.json +4 -4
@@ -6,8 +6,8 @@ var react = require('react');
6
6
  var shop = require('./shop.js');
7
7
 
8
8
  const useMoney = (amount)=>{
9
- const { locale } = shop.useLocale();
10
- const { currency } = shop.useCurrency();
9
+ const { locale } = shop.useLocale();
10
+ const { currency } = shop.useCurrency();
11
11
  const options = react.useMemo(()=>({
12
12
  style: 'currency',
13
13
  currency: currency
@@ -75,7 +75,7 @@ const useVariant = (id)=>{
75
75
  ]);
76
76
  };
77
77
  const useCurrentVariant = ()=>{
78
- const { selectedOptions } = useSelectedOption();
78
+ const { selectedOptions } = useSelectedOption();
79
79
  const variants = useVariants();
80
80
  return react.useMemo(()=>product.getSelectedVariant(variants, selectedOptions), [
81
81
  selectedOptions,
@@ -88,7 +88,7 @@ const useCurrentVariantInStock = ()=>{
88
88
  return isInStock;
89
89
  };
90
90
  const useVariantOutStock = (optionId, optionValue)=>{
91
- const { selectedOptions } = useSelectedOption();
91
+ const { selectedOptions } = useSelectedOption();
92
92
  const variants = useVariants();
93
93
  const matchedVariant = product.getSelectedVariant(variants, {
94
94
  ...selectedOptions,
@@ -99,18 +99,15 @@ const useVariantOutStock = (optionId, optionValue)=>{
99
99
  };
100
100
  const useCheckAvailableVariantInStock = (optionId, optionValue)=>{
101
101
  const variants = useVariants();
102
- let available = false;
103
- variants.forEach((item)=>{
102
+ return variants ? variants.some((item)=>{
104
103
  if (item) {
105
- const { selectedOptions } = item;
106
- const opt = selectedOptions?.find((option)=>option?.name === optionId && option.value === optionValue);
104
+ const { selectedOptions } = item;
105
+ const opt = selectedOptions?.some((option)=>option?.name === optionId && option.value === optionValue);
107
106
  const isInStock = variant.checkInStock(item);
108
- if (opt && isInStock) {
109
- available = true;
110
- }
107
+ return opt && isInStock;
111
108
  }
112
- });
113
- return available;
109
+ return false;
110
+ }) : false;
114
111
  };
115
112
 
116
113
  exports.useCheckAvailableVariantInStock = useCheckAvailableVariantInStock;
@@ -15,7 +15,7 @@ const initialGlobalSwatchesData = {
15
15
  optionValues: []
16
16
  };
17
17
  const useSwatchesOptions = (options)=>{
18
- const { swatches } = shop.useSwatches();
18
+ const { swatches } = shop.useSwatches();
19
19
  if (!options) return [];
20
20
  return options?.map((option)=>{
21
21
  const swatchOption = swatches?.find((sw)=>sw?.optionTitle === option?.name) || {
package/dist/cjs/index.js CHANGED
@@ -194,6 +194,7 @@ exports.getCornerCSSFromGlobal = radius.getCornerCSSFromGlobal;
194
194
  exports.getCustomRadius = radius.getCustomRadius;
195
195
  exports.getRadiusCSSFromGlobal = radius.getRadiusCSSFromGlobal;
196
196
  exports.getRadiusStyleActiveState = radius.getRadiusStyleActiveState;
197
+ exports.checkAvailableVariantInStock = product.checkAvailableVariantInStock;
197
198
  exports.getSelectedVariant = product.getSelectedVariant;
198
199
  exports.parseSelectedOption = product.parseSelectedOption;
199
200
  exports.fpixel = fpixel;
@@ -2,7 +2,7 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import { useAddon } from '../contexts/AddonContext.js';
3
3
  import { usePluginEnable } from '../hooks/shop.js';
4
4
 
5
- const AddOn = ({ name })=>{
5
+ const AddOn = ({ name })=>{
6
6
  const Comp = useAddon(name);
7
7
  const plugins = usePluginEnable();
8
8
  if (!plugins?.includes(name)) {
@@ -3,7 +3,7 @@ import { isValidElement } from 'react';
3
3
  import { composeAdvanceStyle } from '../helpers/compose-advance-style.js';
4
4
  import { disableWrap } from './constant.js';
5
5
 
6
- const ComponentWrapper = ({ children , ...props })=>{
6
+ const ComponentWrapper = ({ children, ...props })=>{
7
7
  if (props.type === 'section') return null;
8
8
  const style = composeAdvanceStyle(props.advanced, props.tag);
9
9
  const advanced = props.advanced;
@@ -3,7 +3,7 @@ import { isValidElement } from 'react';
3
3
  import { composeAdvanceStyle } from '../helpers/compose-advance-style.js';
4
4
  import { disableWrap } from './constant.js';
5
5
 
6
- const ComponentWrapperPreview = ({ children , ...props })=>{
6
+ const ComponentWrapperPreview = ({ children, ...props })=>{
7
7
  if (props.type === 'section') {
8
8
  return null;
9
9
  }
@@ -6,7 +6,7 @@ import { useBuilderStore } from '../contexts/BuilderContext.js';
6
6
  import ComponentWrapper from './ComponentWrapper.js';
7
7
  import RenderSectionMemo from './RenderSection.js';
8
8
 
9
- const Render = ({ uid , ...passProps })=>{
9
+ const Render = ({ uid, ...passProps })=>{
10
10
  const item = useBuilderStore((s)=>s.getItem(uid));
11
11
  const Component = useBuilderComponent(item?.tag);
12
12
  if (!item) return null;
@@ -16,7 +16,7 @@ const Render = ({ uid , ...passProps })=>{
16
16
  });
17
17
  } else {
18
18
  return /*#__PURE__*/ jsx(ErrorBoundary, {
19
- fallbackRender: ({ error , resetErrorBoundary })=>/*#__PURE__*/ jsxs(Fragment, {
19
+ fallbackRender: ({ error, resetErrorBoundary })=>/*#__PURE__*/ jsxs(Fragment, {
20
20
  children: [
21
21
  /*#__PURE__*/ jsx("span", {
22
22
  "aria-label": "Error message",
@@ -12,7 +12,7 @@ const componentTexts = [
12
12
  'Text',
13
13
  'Heading'
14
14
  ];
15
- const Render = ({ uid , builder , components , parentId , extraFiles ={} , ...passProps })=>{
15
+ const Render = ({ uid, builder, components, parentId, extraFiles = {}, ...passProps })=>{
16
16
  const item = builder[uid];
17
17
  const Component = components[item?.tag];
18
18
  if (!Component) {
@@ -5,12 +5,12 @@ import { useBuilderComponent } from '../contexts/BuilderComponent.js';
5
5
  import { useBuilderStore } from '../contexts/BuilderContext.js';
6
6
  import ComponentWrapper from './ComponentWrapper.js';
7
7
 
8
- const RenderBlock = ({ uid })=>{
8
+ const RenderBlock = ({ uid })=>{
9
9
  const item = useBuilderStore((s)=>s.getItem(uid));
10
10
  const Component = useBuilderComponent(item?.tag);
11
11
  if (!item || item.type === 'section') return null;
12
12
  return /*#__PURE__*/ jsx(ErrorBoundary, {
13
- fallbackRender: ({ error , resetErrorBoundary })=>/*#__PURE__*/ jsxs(ComponentWrapper, {
13
+ fallbackRender: ({ error, resetErrorBoundary })=>/*#__PURE__*/ jsxs(ComponentWrapper, {
14
14
  ...item,
15
15
  children: [
16
16
  /*#__PURE__*/ jsx("span", {
@@ -6,7 +6,7 @@ import { useBuilderPreviewStore } from '../contexts/BuilderPreviewContext.js';
6
6
  import ComponentWrapperPreview from './ComponentWrapperPreview.js';
7
7
  import RenderSectionMemo from './RenderSection.js';
8
8
 
9
- const RenderPreview = ({ uid , ...passProps })=>{
9
+ const RenderPreview = ({ uid, ...passProps })=>{
10
10
  const item = useBuilderPreviewStore((s)=>s.getItem(uid));
11
11
  const Component = useBuilderComponent(item?.tag);
12
12
  if (!item) return null;
@@ -16,7 +16,7 @@ const RenderPreview = ({ uid , ...passProps })=>{
16
16
  });
17
17
  } else {
18
18
  return /*#__PURE__*/ jsx(ErrorBoundary, {
19
- fallbackRender: ({ error , resetErrorBoundary })=>/*#__PURE__*/ jsxs(ComponentWrapperPreview, {
19
+ fallbackRender: ({ error, resetErrorBoundary })=>/*#__PURE__*/ jsxs(ComponentWrapperPreview, {
20
20
  ...item,
21
21
  children: [
22
22
  /*#__PURE__*/ jsx("span", {
@@ -4,7 +4,7 @@ import { BuilderProvider } from '../contexts/BuilderContext.js';
4
4
  import { useSection } from '../contexts/SectionContext.js';
5
5
  import RenderBlockMemo from './RenderBlock.js';
6
6
 
7
- const RenderSection = ({ sectionId })=>{
7
+ const RenderSection = ({ sectionId })=>{
8
8
  const state = useSection(sectionId);
9
9
  if (!state) return null;
10
10
  return /*#__PURE__*/ jsx(BuilderProvider, {
@@ -3,7 +3,7 @@ import { useContext, useMemo, createContext } from 'react';
3
3
  import Empty from '../components/Empty.js';
4
4
 
5
5
  const AddonContext = /*#__PURE__*/ createContext(null);
6
- const AddonProvider = ({ children , components , ...passProps })=>{
6
+ const AddonProvider = ({ children, components, ...passProps })=>{
7
7
  return /*#__PURE__*/ jsx(AddonContext.Provider, {
8
8
  ...passProps,
9
9
  value: {
@@ -10,7 +10,7 @@ const createBuilderComponentStore = (components)=>createStore((_, get)=>({
10
10
  return get().components[id];
11
11
  }
12
12
  }));
13
- const BuilderComponentProvider = ({ children , components , ...passProps })=>{
13
+ const BuilderComponentProvider = ({ children, components, ...passProps })=>{
14
14
  return /*#__PURE__*/ jsx(BuilderComponentContext.Provider, {
15
15
  ...passProps,
16
16
  value: createBuilderComponentStore(components),
@@ -9,7 +9,7 @@ const createBuilderProvider = (data)=>createStore((_, get)=>({
9
9
  return get().state[id];
10
10
  }
11
11
  }));
12
- const BuilderProvider = ({ children , state , lazy , priority , ...passProps })=>{
12
+ const BuilderProvider = ({ children, state, lazy, priority, ...passProps })=>{
13
13
  const Component = lazy ? Suspense : Fragment;
14
14
  const store = createBuilderProvider(state);
15
15
  return /*#__PURE__*/ jsx(Component, {
@@ -30,7 +30,7 @@ const createBuilderPreviewProvider = (args)=>createStore((set, get)=>({
30
30
  state: args,
31
31
  loaded: false,
32
32
  addItem: (args)=>{
33
- const { position , data } = args;
33
+ const { position, data } = args;
34
34
  const state = get().state;
35
35
  const dateModified = Date.now();
36
36
  if (args.type === 'section') {
@@ -59,7 +59,7 @@ const createBuilderPreviewProvider = (args)=>createStore((set, get)=>({
59
59
  });
60
60
  }
61
61
  } else {
62
- const { id , data } = args;
62
+ const { id, data } = args;
63
63
  const parent = id ? state[id] ?? state.ROOT : state.ROOT;
64
64
  // Can't add item to section
65
65
  if (parent.type === 'section') return;
@@ -156,7 +156,7 @@ const createBuilderPreviewProvider = (args)=>createStore((set, get)=>({
156
156
  }
157
157
  }
158
158
  },
159
- changeItemPropByKey: ({ id , key , data , group })=>{
159
+ changeItemPropByKey: ({ id, key, data, group })=>{
160
160
  if (!group || ![
161
161
  'setting',
162
162
  'style',
@@ -340,7 +340,7 @@ const createBuilderPreviewProvider = (args)=>createStore((set, get)=>({
340
340
  });
341
341
  }
342
342
  }));
343
- const BuilderPreviewProvider = ({ children , state , lazy , ...passProps })=>{
343
+ const BuilderPreviewProvider = ({ children, state, lazy, ...passProps })=>{
344
344
  const Component = lazy ? Suspense : Fragment;
345
345
  const value = useMemo(()=>{
346
346
  return createBuilderPreviewProvider(state);
@@ -6,7 +6,7 @@ const CartLineContext = /*#__PURE__*/ createContext(null);
6
6
  const createCartLineStore = (data)=>createStore(()=>({
7
7
  ...data
8
8
  }));
9
- const CartLineProvider = ({ children , line })=>{
9
+ const CartLineProvider = ({ children, line })=>{
10
10
  return /*#__PURE__*/ jsx(CartLineContext.Provider, {
11
11
  value: createCartLineStore({
12
12
  line
@@ -5,13 +5,13 @@ import { useStore, createStore } from 'zustand';
5
5
  const CollectionContext = /*#__PURE__*/ createContext(null);
6
6
  const createCollectionProvider = (data)=>createStore((set)=>({
7
7
  ...data,
8
- changeCollectionStore: ({ collection })=>{
8
+ changeCollectionStore: ({ collection })=>{
9
9
  set({
10
10
  collection: collection
11
11
  });
12
12
  }
13
13
  }));
14
- const CollectionProvider = ({ collection , children })=>{
14
+ const CollectionProvider = ({ collection, children })=>{
15
15
  const store = useMemo(()=>{
16
16
  return createCollectionProvider({
17
17
  collection
@@ -24,7 +24,7 @@ const createModalProvider = (data)=>createStore((set)=>({
24
24
  });
25
25
  }
26
26
  }));
27
- const ModalProvider = ({ children , activeId , ...passProps })=>{
27
+ const ModalProvider = ({ children, activeId, ...passProps })=>{
28
28
  const store = createModalProvider(activeId);
29
29
  return /*#__PURE__*/ jsx(ModalContext.Provider, {
30
30
  ...passProps,
@@ -94,7 +94,7 @@ const createProductStoreProvider = (data)=>createStore((set, get)=>({
94
94
  });
95
95
  }
96
96
  }));
97
- const ProductProvider = ({ children , product , initialVariantId , quantity =1 })=>{
97
+ const ProductProvider = ({ children, product, initialVariantId, quantity = 1 })=>{
98
98
  const uiqueId = useId();
99
99
  const store = useMemo(()=>{
100
100
  let selectedOptions = {};
@@ -6,7 +6,7 @@ const ProductListContext = /*#__PURE__*/ createContext(null);
6
6
  const createProductListProvider = (data)=>createStore(()=>({
7
7
  ...data
8
8
  }));
9
- const ProductListProvider = ({ children , collection , products , settings , styles })=>{
9
+ const ProductListProvider = ({ children, collection, products, settings, styles })=>{
10
10
  return /*#__PURE__*/ jsx(ProductListContext.Provider, {
11
11
  value: createProductListProvider({
12
12
  products,
@@ -22,14 +22,14 @@ const createSectionProvider = (data)=>createStore((set, get)=>({
22
22
  },
23
23
  removeSection: (id)=>{
24
24
  set((prev)=>{
25
- const { [id]: _ , ...rest } = prev.data;
25
+ const { [id]: _, ...rest } = prev.data;
26
26
  return {
27
27
  data: rest
28
28
  };
29
29
  });
30
30
  }
31
31
  }));
32
- const SectionProvider = ({ children , data , ...passProps })=>{
32
+ const SectionProvider = ({ children, data, ...passProps })=>{
33
33
  return /*#__PURE__*/ jsx(SectionContext.Provider, {
34
34
  ...passProps,
35
35
  value: createSectionProvider(data),
@@ -30,14 +30,14 @@ const createShopStoreProvider = (data)=>createStore((set)=>({
30
30
  layoutSettings
31
31
  });
32
32
  },
33
- changeStorefrontInfo: ({ url , token })=>{
33
+ changeStorefrontInfo: ({ url, token })=>{
34
34
  set({
35
35
  storefrontUrl: url,
36
36
  storefrontToken: token
37
37
  });
38
38
  }
39
39
  }));
40
- const ShopProvider = ({ children , addons , storeOption , queryOption , ...passProps })=>{
40
+ const ShopProvider = ({ children, addons, storeOption, queryOption, ...passProps })=>{
41
41
  const store = useMemo(()=>createShopStoreProvider(storeOption), [
42
42
  storeOption
43
43
  ]);
@@ -14,6 +14,7 @@
14
14
  }
15
15
  }
16
16
  }
17
+ totalCount
17
18
  }
18
19
  }
19
20
  `;
@@ -165,7 +165,7 @@ const handleConvertClassColorDynamicBtn = (value)=>{
165
165
  };
166
166
  const composeBorderCss = (borderV)=>{
167
167
  if (!borderV) return '';
168
- const { border , width , color } = borderV;
168
+ const { border, width, color } = borderV;
169
169
  return `${border ? `border-style: ${border};` : ''}
170
170
  ${width ? `border-width: ${width};` : ''}
171
171
  ${color ? `border-color: ${getSingleColorVariable(color)};` : ''}
@@ -5,8 +5,8 @@ import { makeStyleKey } from './make-style.js';
5
5
  import { composeRadius, getCornerCSSFromGlobal } from './radius.js';
6
6
  import { getStyleShadowState, getStyleShadow } from './shadow.js';
7
7
 
8
- const composeSpacing = ({ source , spacing , type , suffix ='' })=>{
9
- const { top , left , bottom , right } = spacing;
8
+ const composeSpacing = ({ source, spacing, type, suffix = '' })=>{
9
+ const { top, left, bottom, right } = spacing;
10
10
  if (top) source[`--${type}t${suffix}`] = top;
11
11
  if (left) source[`--${type}l${suffix}`] = left;
12
12
  if (bottom) source[`--${type}b${suffix}`] = bottom;
@@ -1,3 +1,5 @@
1
+ import { checkInStock } from './variant.js';
2
+
1
3
  function getSelectedVariant(variants, choices) {
2
4
  /**
3
5
  * Ensure the user has selected all the required options, not just some.
@@ -14,7 +16,7 @@ function parseSelectedOption(options) {
14
16
  if (!options || options && options.length === 0) {
15
17
  return;
16
18
  }
17
- return options.reduce((acc, { name , value })=>{
19
+ return options.reduce((acc, { name, value })=>{
18
20
  if (name && value) {
19
21
  return {
20
22
  ...acc,
@@ -24,5 +26,16 @@ function parseSelectedOption(options) {
24
26
  return acc;
25
27
  }, {});
26
28
  }
29
+ function checkAvailableVariantInStock(variants, optionId, optionValue) {
30
+ return variants ? variants.some((item)=>{
31
+ if (item) {
32
+ const { selectedOptions } = item;
33
+ const opt = selectedOptions?.some((option)=>option?.name === optionId && option.value === optionValue);
34
+ const isInStock = checkInStock(item);
35
+ return opt && isInStock;
36
+ }
37
+ return false;
38
+ }) : false;
39
+ }
27
40
 
28
- export { getSelectedVariant, parseSelectedOption };
41
+ export { checkAvailableVariantInStock, getSelectedVariant, parseSelectedOption };
@@ -169,7 +169,7 @@ const mergeProductCollectionVariant = async (fetcher, collection, isSample)=>{
169
169
  };
170
170
  return newCollection;
171
171
  };
172
- const fetchVariantsByBaseIds = async (fetcher, { ids , isSample , isStorefront })=>{
172
+ const fetchVariantsByBaseIds = async (fetcher, { ids, isSample, isStorefront })=>{
173
173
  const chunkedIds = chunkArray(ids ?? [], 8);
174
174
  const defaultEdges = [];
175
175
  const query = async (variables)=>{
@@ -2,7 +2,7 @@ import { ProductLittleDetailDocument } from '../../graphql/queries/product-littl
2
2
  import { ProductMediasDocument } from '../../graphql/queries/product-medias.generated.js';
3
3
  import { ProductVariantsDocument } from '../../graphql/queries/product-variants.generated.js';
4
4
 
5
- const getProduct = async (fetcher, { id , isSample , isStorefront })=>{
5
+ const getProduct = async (fetcher, { id, isSample, isStorefront })=>{
6
6
  const [product, variants, medias] = await Promise.all([
7
7
  fetchProduct(fetcher, {
8
8
  id,
@@ -37,7 +37,7 @@ const orderBy = {
37
37
  field: 'CREATED_AT',
38
38
  direction: 'DESC'
39
39
  };
40
- const fetchProduct = async (fetcher, { id , isSample , isStorefront })=>{
40
+ const fetchProduct = async (fetcher, { id, isSample, isStorefront })=>{
41
41
  const variables = {
42
42
  orderBy,
43
43
  where: {
@@ -59,7 +59,7 @@ const fetchProduct = async (fetcher, { id , isSample , isStorefront })=>{
59
59
  ]);
60
60
  return response.product?.edges?.[0]?.node;
61
61
  };
62
- const fetchVariants = async (fetcher, { id , isSample , isStorefront })=>{
62
+ const fetchVariants = async (fetcher, { id, isSample, isStorefront })=>{
63
63
  const initVariables = {
64
64
  orderBy,
65
65
  where: {
@@ -100,7 +100,7 @@ const fetchVariants = async (fetcher, { id , isSample , isStorefront })=>{
100
100
  };
101
101
  return query(initVariables, []);
102
102
  };
103
- const fetchMedias = async (fetcher, { id , isSample , isStorefront })=>{
103
+ const fetchMedias = async (fetcher, { id, isSample, isStorefront })=>{
104
104
  const initVariables = {
105
105
  orderBy,
106
106
  where: {
@@ -2,7 +2,7 @@ import { ProductsDocument } from '../../graphql/queries/products.generated.js';
2
2
  import { calculateFirstProduct } from './get-collection.js';
3
3
  import { fetchVariants, fetchMedias } from './get-product.js';
4
4
 
5
- const getProducts = async (fetcher, { ids , isSample , isStorefront })=>{
5
+ const getProducts = async (fetcher, { ids, isSample, isStorefront })=>{
6
6
  const products = await loopFetchProducts(fetcher, {
7
7
  ids,
8
8
  isSample,
@@ -59,7 +59,7 @@ const fetchProducts = async (fetcher, variables)=>{
59
59
  variables
60
60
  ]);
61
61
  };
62
- const loopFetchProducts = async (fetcher, { ids , isSample , isStorefront })=>{
62
+ const loopFetchProducts = async (fetcher, { ids, isSample, isStorefront })=>{
63
63
  const numberOfProducts = (ids?.length == 0 ? 4 : ids?.length) ?? 4;
64
64
  const productsPerPage = 8; // number of products per page
65
65
  let variables; // variables of collection query
@@ -116,7 +116,7 @@ const loopFetchProducts = async (fetcher, { ids , isSample , isStorefront })=>{
116
116
  }
117
117
  return dataProducts;
118
118
  };
119
- const mergeVariantsToProducts = async ({ fetcher , products , isSample , isStorefront })=>{
119
+ const mergeVariantsToProducts = async ({ fetcher, products, isSample, isStorefront })=>{
120
120
  const productsWithVariants = await Promise.all(products?.products?.edges?.map(async (product)=>{
121
121
  const variants = await fetchVariants(fetcher, {
122
122
  id: product?.node?.baseID,
@@ -130,7 +130,7 @@ const mergeVariantsToProducts = async ({ fetcher , products , isSample , isStore
130
130
  }) ?? []);
131
131
  return productsWithVariants;
132
132
  };
133
- const mergeMediasToProducts = async ({ fetcher , products , isSample , isStorefront })=>{
133
+ const mergeMediasToProducts = async ({ fetcher, products, isSample, isStorefront })=>{
134
134
  const productsWithMedias = await Promise.all(products?.products?.edges?.map(async (product)=>{
135
135
  const medias = await fetchMedias(fetcher, {
136
136
  id: product?.node?.baseID,
@@ -99,7 +99,7 @@ const composeCornerCss = (value)=>{
99
99
  if (!value) {
100
100
  return;
101
101
  }
102
- const { radiusType , bblr , bbrr , btlr , btrr } = value;
102
+ const { radiusType, bblr, bbrr, btlr, btrr } = value;
103
103
  let radiusValue = undefined;
104
104
  switch(radiusType){
105
105
  case 'medium':
@@ -18,12 +18,12 @@ const parseValueWithUnit = (valueWithUnit)=>{
18
18
  };
19
19
  };
20
20
  const getStyleShadow = (shadowStyle, isActiveState = false)=>{
21
- const { styleAppliedFor , value , isEnableShadow } = shadowStyle || {};
22
- let { state } = shadowStyle || {};
21
+ const { styleAppliedFor, value, isEnableShadow } = shadowStyle || {};
22
+ let { state } = shadowStyle || {};
23
23
  if (!state) state = 'normal';
24
24
  if (!styleAppliedFor || !value) return {};
25
25
  if (typeof value.distance == 'undefined') return {};
26
- const { value: distance , unit: unitDistance } = parseValueWithUnit(`${value?.distance}`);
26
+ const { value: distance, unit: unitDistance } = parseValueWithUnit(`${value?.distance}`);
27
27
  return {
28
28
  [`-${!isActiveState ? stateMapping?.[state] : ''}-${getShortName(styleAppliedFor)}`]: isEnableShadow ? `${Math.cos(parseFloat(`${value?.angle}`) * Math.PI / 180) * parseFloat(`${distance}`)}${unitDistance} ${Math.sin(parseFloat(`${value?.angle}`) * Math.PI / 180) * parseFloat(`${distance}`)}${unitDistance} ${value?.blur} ${styleAppliedFor === 'box-shadow' ? value?.spread + ' ' : ''}${getSingleColorVariable(value?.color)}` : 'none'
29
29
  };
@@ -41,10 +41,10 @@ const getStyleShadowState = (shadow, styleAppliedFor, isEnableShadow)=>{
41
41
  }
42
42
  return style;
43
43
  };
44
- const composeShadowCss = ({ hasBoxShadow , boxShadowValue })=>{
44
+ const composeShadowCss = ({ hasBoxShadow, boxShadowValue })=>{
45
45
  if (!hasBoxShadow) return undefined;
46
46
  if (!boxShadowValue) return undefined;
47
- const { value: distance , unit: unitDistance } = parseValueWithUnit(`${boxShadowValue?.distance}`);
47
+ const { value: distance, unit: unitDistance } = parseValueWithUnit(`${boxShadowValue?.distance}`);
48
48
  return `box-shadow: ${Math.cos(parseFloat(`${boxShadowValue?.angle}`) * Math.PI / 180) * parseFloat(`${distance}`)}${unitDistance} ${Math.sin(parseFloat(`${boxShadowValue?.angle}`) * Math.PI / 180) * parseFloat(`${distance}`)}${unitDistance} ${boxShadowValue?.blur} ${boxShadowValue?.spread + ' '}${getSingleColorVariable(boxShadowValue?.color)};`;
49
49
  };
50
50
 
@@ -6,7 +6,7 @@ const genTypoClass = (name)=>{
6
6
  };
7
7
  const composeTypographyCss = (typography)=>{
8
8
  const typographyCustom = typography?.custom;
9
- const { fontFamily , fontSize , fontStyle , fontWeight , lineHeight , letterSpacing } = typographyCustom?.desktop ?? {};
9
+ const { fontFamily, fontSize, fontStyle, fontWeight, lineHeight, letterSpacing } = typographyCustom?.desktop ?? {};
10
10
  return `
11
11
  ${fontFamily ? `font-family: var(--g-font-${fontFamily}, ${fontFamily});` : ''}
12
12
  ${fontSize ? `font-size: ${fontSize};` : ''}
@@ -18,9 +18,9 @@ const composeTypographyCss = (typography)=>{
18
18
  };
19
19
  const composeTypographyV2Css = (typography)=>{
20
20
  const typographyCustom = typography?.custom;
21
- const { fontFamily , fontSize , fontWeight , lineHeight , letterSpacing } = typographyCustom ?? {};
21
+ const { fontFamily, fontSize, fontWeight, lineHeight, letterSpacing } = typographyCustom ?? {};
22
22
  const typographyAttrs = typography?.attrs;
23
- const { bold , italic , underline , transform } = typographyAttrs ?? {};
23
+ const { bold, italic, underline, transform } = typographyAttrs ?? {};
24
24
  return `
25
25
  ${fontFamily ? `font-family: var(--g-font-${fontFamily}, ${fontFamily});` : ''}
26
26
  ${fontSize?.desktop ? `font-size: ${fontSize?.desktop};` : ''}
@@ -35,7 +35,7 @@ const composeTypographyV2Css = (typography)=>{
35
35
  function getCustomCSSByDevice(typography, device) {
36
36
  if (!typography || !device) return {};
37
37
  const suffix = device === 'desktop' || !device ? '' : `-${device}`;
38
- const { fontFamily } = typography?.[device] ?? {};
38
+ const { fontFamily } = typography?.[device] ?? {};
39
39
  return {
40
40
  [`--size${suffix}`]: typography?.[device]?.fontSize,
41
41
  [`--lh${suffix}`]: typography?.[device]?.lineHeight,
@@ -5,8 +5,8 @@ import { useStoreFront } from '../shop.js';
5
5
 
6
6
  const useAddToCart = (options)=>{
7
7
  const shop = useStoreFront();
8
- const { mutate } = useSWRConfig();
9
- return useSWRMutation('add-to-cart', (_, { arg })=>addToCartOperation(shop)(arg), {
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('add-to-cart', (_, { arg })=>addToCartOperation(shop)(arg), {
10
10
  ...options,
11
11
  onSuccess: (result, key, config)=>{
12
12
  mutate('cart', result, false);
@@ -4,7 +4,7 @@ import { useStoreFront } from '../shop.js';
4
4
  import useCartId from '../useCartId.js';
5
5
 
6
6
  const useCartData = (options)=>{
7
- const { cartId , clearCartId } = useCartId();
7
+ const { cartId, clearCartId } = useCartId();
8
8
  const shop = useStoreFront();
9
9
  return useSWR(cartId ? 'cart' : null, ()=>getCartOperation(shop)({
10
10
  cartId: cartId
@@ -5,8 +5,8 @@ import { useStoreFront } from '../shop.js';
5
5
 
6
6
  const useCartDiscountCodesUpdate = (options)=>{
7
7
  const shop = useStoreFront();
8
- const { mutate } = useSWRConfig();
9
- return useSWRMutation('cart-discount-codes-update', (_, { arg })=>cartDiscountCodesUpdateOperation(shop)(arg), {
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('cart-discount-codes-update', (_, { arg })=>cartDiscountCodesUpdateOperation(shop)(arg), {
10
10
  ...options,
11
11
  onSuccess: (result, key, config)=>{
12
12
  mutate('cart', result, false);
@@ -5,8 +5,8 @@ import { useStoreFront } from '../shop.js';
5
5
 
6
6
  const useCartNoteUpdate = (options)=>{
7
7
  const shop = useStoreFront();
8
- const { mutate } = useSWRConfig();
9
- return useSWRMutation('cart-note-update', (_, { arg })=>cartNoteUpdateOperation(shop)(arg), {
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('cart-note-update', (_, { arg })=>cartNoteUpdateOperation(shop)(arg), {
10
10
  ...options,
11
11
  onSuccess: (result, key, config)=>{
12
12
  mutate('cart', result, false);
@@ -5,8 +5,8 @@ import { useStoreFront } from '../shop.js';
5
5
 
6
6
  const useCreateCart = (options)=>{
7
7
  const shop = useStoreFront();
8
- const { mutate } = useSWRConfig();
9
- return useSWRMutation('create-cart', (_, { arg })=>{
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('create-cart', (_, { arg })=>{
10
10
  return createCartOperation(shop)(arg);
11
11
  }, {
12
12
  ...options,
@@ -5,8 +5,8 @@ import { useStoreFront } from '../shop.js';
5
5
 
6
6
  const useRemoveCartItem = (options)=>{
7
7
  const shop = useStoreFront();
8
- const { mutate } = useSWRConfig();
9
- return useSWRMutation('remove-cart-item', (_, { arg })=>removeCartItemOperation(shop)(arg), {
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('remove-cart-item', (_, { arg })=>removeCartItemOperation(shop)(arg), {
10
10
  ...options,
11
11
  onSuccess: (result, key, config)=>{
12
12
  mutate('cart', result, false);