@gem-sdk/core 1.0.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.
Files changed (214) hide show
  1. package/dist/cjs/components/AddOn.js +18 -0
  2. package/dist/cjs/components/ComponentWrapper.js +45 -0
  3. package/dist/cjs/components/ComponentWrapperPreview.js +58 -0
  4. package/dist/cjs/components/Empty.js +7 -0
  5. package/dist/cjs/components/Render.js +28 -0
  6. package/dist/cjs/components/RenderBlock.js +21 -0
  7. package/dist/cjs/components/RenderPreview.js +28 -0
  8. package/dist/cjs/components/RenderSection.js +19 -0
  9. package/dist/cjs/contexts/AddonContext.js +25 -0
  10. package/dist/cjs/contexts/BuilderComponent.js +30 -0
  11. package/dist/cjs/contexts/BuilderContext.js +29 -0
  12. package/dist/cjs/contexts/BuilderPreviewContext.js +353 -0
  13. package/dist/cjs/contexts/CartLineContext.js +24 -0
  14. package/dist/cjs/contexts/CollectionContext.js +24 -0
  15. package/dist/cjs/contexts/ProductContext.js +126 -0
  16. package/dist/cjs/contexts/ProductListContext.js +24 -0
  17. package/dist/cjs/contexts/SectionContext.js +49 -0
  18. package/dist/cjs/contexts/ShopContext.js +43 -0
  19. package/dist/cjs/graphql/fragments/analytic.generated.js +11 -0
  20. package/dist/cjs/graphql/fragments/collection-detail.generated.js +13 -0
  21. package/dist/cjs/graphql/fragments/collection-product.generated.js +26 -0
  22. package/dist/cjs/graphql/fragments/data-seo.generated.js +11 -0
  23. package/dist/cjs/graphql/fragments/media.generated.js +14 -0
  24. package/dist/cjs/graphql/fragments/product-little.generated.js +25 -0
  25. package/dist/cjs/graphql/fragments/product-option-value.generated.js +13 -0
  26. package/dist/cjs/graphql/fragments/product-option.generated.js +14 -0
  27. package/dist/cjs/graphql/fragments/product.generated.js +33 -0
  28. package/dist/cjs/graphql/fragments/published-custom-section.generated.js +12 -0
  29. package/dist/cjs/graphql/fragments/published-page-section.generated.js +11 -0
  30. package/dist/cjs/graphql/fragments/published-theme-page.generated.js +27 -0
  31. package/dist/cjs/graphql/fragments/published-theme-style.generated.js +11 -0
  32. package/dist/cjs/graphql/fragments/selected-option.generated.js +11 -0
  33. package/dist/cjs/graphql/fragments/variant.generated.js +35 -0
  34. package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +34 -0
  35. package/dist/cjs/graphql/queries/collection.generated.js +52 -0
  36. package/dist/cjs/graphql/queries/preview-page.generated.js +23 -0
  37. package/dist/cjs/graphql/queries/product-little-detail.generated.js +24 -0
  38. package/dist/cjs/graphql/queries/product-medias.generated.js +29 -0
  39. package/dist/cjs/graphql/queries/product-variants.generated.js +33 -0
  40. package/dist/cjs/graphql/queries/products.generated.js +41 -0
  41. package/dist/cjs/graphql/queries/published-theme-pages.generated.js +23 -0
  42. package/dist/cjs/graphql/queries/storeProperty.generated.js +12 -0
  43. package/dist/cjs/helpers/GlobalEvent.js +17 -0
  44. package/dist/cjs/helpers/background.js +104 -0
  45. package/dist/cjs/helpers/borders.js +138 -0
  46. package/dist/cjs/helpers/clone-deep.js +5 -0
  47. package/dist/cjs/helpers/cls.js +20 -0
  48. package/dist/cjs/helpers/colors.js +157 -0
  49. package/dist/cjs/helpers/compose-advance-style.js +132 -0
  50. package/dist/cjs/helpers/constant.js +17 -0
  51. package/dist/cjs/helpers/css-variable.js +7 -0
  52. package/dist/cjs/helpers/email.js +11 -0
  53. package/dist/cjs/helpers/flatten-connection.js +10 -0
  54. package/dist/cjs/helpers/fpixel.js +29 -0
  55. package/dist/cjs/helpers/get-resonsive-value.js +32 -0
  56. package/dist/cjs/helpers/get-shortname.js +92 -0
  57. package/dist/cjs/helpers/gtag.js +48 -0
  58. package/dist/cjs/helpers/is-browser.js +9 -0
  59. package/dist/cjs/helpers/is-defined.js +7 -0
  60. package/dist/cjs/helpers/is-empty-children.js +12 -0
  61. package/dist/cjs/helpers/layout.js +17 -0
  62. package/dist/cjs/helpers/load-script.js +32 -0
  63. package/dist/cjs/helpers/make-style.js +99 -0
  64. package/dist/cjs/helpers/normalize-builder-data.js +17 -0
  65. package/dist/cjs/helpers/prefetch-queries.js +68 -0
  66. package/dist/cjs/helpers/product.js +35 -0
  67. package/dist/cjs/helpers/queries/get-collection.js +173 -0
  68. package/dist/cjs/helpers/queries/get-product-by-slug.js +99 -0
  69. package/dist/cjs/helpers/queries/get-product.js +113 -0
  70. package/dist/cjs/helpers/queries/get-products.js +135 -0
  71. package/dist/cjs/helpers/radius.js +91 -0
  72. package/dist/cjs/helpers/shadow.js +48 -0
  73. package/dist/cjs/helpers/size.js +20 -0
  74. package/dist/cjs/helpers/spacing.js +45 -0
  75. package/dist/cjs/helpers/tiktokpixel.js +17 -0
  76. package/dist/cjs/helpers/typography.js +7 -0
  77. package/dist/cjs/hooks/cart/use-add-to-cart.js +20 -0
  78. package/dist/cjs/hooks/cart/use-cart-data.js +26 -0
  79. package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +20 -0
  80. package/dist/cjs/hooks/cart/use-cart-note-update.js +20 -0
  81. package/dist/cjs/hooks/cart/use-create-cart.js +22 -0
  82. package/dist/cjs/hooks/cart/use-remove-cart-item.js +20 -0
  83. package/dist/cjs/hooks/cart/use-update-cart-item.js +20 -0
  84. package/dist/cjs/hooks/shop/use-collection-query.js +16 -0
  85. package/dist/cjs/hooks/shop/use-product-query.js +16 -0
  86. package/dist/cjs/hooks/shop/use-products-query.js +16 -0
  87. package/dist/cjs/hooks/shop.js +80 -0
  88. package/dist/cjs/hooks/use-current-device.js +23 -0
  89. package/dist/cjs/hooks/use-lazy-video.js +15 -0
  90. package/dist/cjs/hooks/useCartId.js +36 -0
  91. package/dist/cjs/hooks/useCartLine.js +11 -0
  92. package/dist/cjs/hooks/useCartUI.js +42 -0
  93. package/dist/cjs/hooks/useCollection.js +9 -0
  94. package/dist/cjs/hooks/useFetchHandle.js +13 -0
  95. package/dist/cjs/hooks/useFormatMoney.js +17 -0
  96. package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +10 -0
  97. package/dist/cjs/hooks/useLoadScript.js +30 -0
  98. package/dist/cjs/hooks/useMoney.js +52 -0
  99. package/dist/cjs/hooks/usePrevious.js +17 -0
  100. package/dist/cjs/hooks/useProduct.js +90 -0
  101. package/dist/cjs/hooks/useProductList.js +21 -0
  102. package/dist/cjs/hooks/useSuspenseFetch.js +24 -0
  103. package/dist/cjs/hooks/useSwatchesOptions.js +39 -0
  104. package/dist/cjs/index.js +229 -0
  105. package/dist/cjs/types/global-style.js +7 -0
  106. package/dist/cjs/types/shop.js +2 -0
  107. package/dist/esm/components/AddOn.js +14 -0
  108. package/dist/esm/components/ComponentWrapper.js +40 -0
  109. package/dist/esm/components/ComponentWrapperPreview.js +54 -0
  110. package/dist/esm/components/Empty.js +3 -0
  111. package/dist/esm/components/Render.js +24 -0
  112. package/dist/esm/components/RenderBlock.js +17 -0
  113. package/dist/esm/components/RenderPreview.js +24 -0
  114. package/dist/esm/components/RenderSection.js +15 -0
  115. package/dist/esm/contexts/AddonContext.js +21 -0
  116. package/dist/esm/contexts/BuilderComponent.js +27 -0
  117. package/dist/esm/contexts/BuilderContext.js +26 -0
  118. package/dist/esm/contexts/BuilderPreviewContext.js +350 -0
  119. package/dist/esm/contexts/CartLineContext.js +21 -0
  120. package/dist/esm/contexts/CollectionContext.js +20 -0
  121. package/dist/esm/contexts/ProductContext.js +123 -0
  122. package/dist/esm/contexts/ProductListContext.js +20 -0
  123. package/dist/esm/contexts/SectionContext.js +45 -0
  124. package/dist/esm/contexts/ShopContext.js +40 -0
  125. package/dist/esm/graphql/fragments/analytic.generated.js +9 -0
  126. package/dist/esm/graphql/fragments/collection-detail.generated.js +11 -0
  127. package/dist/esm/graphql/fragments/collection-product.generated.js +24 -0
  128. package/dist/esm/graphql/fragments/data-seo.generated.js +9 -0
  129. package/dist/esm/graphql/fragments/media.generated.js +12 -0
  130. package/dist/esm/graphql/fragments/product-little.generated.js +23 -0
  131. package/dist/esm/graphql/fragments/product-option-value.generated.js +11 -0
  132. package/dist/esm/graphql/fragments/product-option.generated.js +12 -0
  133. package/dist/esm/graphql/fragments/product.generated.js +31 -0
  134. package/dist/esm/graphql/fragments/published-custom-section.generated.js +10 -0
  135. package/dist/esm/graphql/fragments/published-page-section.generated.js +9 -0
  136. package/dist/esm/graphql/fragments/published-theme-page.generated.js +25 -0
  137. package/dist/esm/graphql/fragments/published-theme-style.generated.js +9 -0
  138. package/dist/esm/graphql/fragments/selected-option.generated.js +9 -0
  139. package/dist/esm/graphql/fragments/variant.generated.js +33 -0
  140. package/dist/esm/graphql/queries/collection-detail-filter.generated.js +32 -0
  141. package/dist/esm/graphql/queries/collection.generated.js +50 -0
  142. package/dist/esm/graphql/queries/preview-page.generated.js +21 -0
  143. package/dist/esm/graphql/queries/product-little-detail.generated.js +22 -0
  144. package/dist/esm/graphql/queries/product-medias.generated.js +27 -0
  145. package/dist/esm/graphql/queries/product-variants.generated.js +31 -0
  146. package/dist/esm/graphql/queries/products.generated.js +38 -0
  147. package/dist/esm/graphql/queries/published-theme-pages.generated.js +21 -0
  148. package/dist/esm/graphql/queries/storeProperty.generated.js +10 -0
  149. package/dist/esm/helpers/GlobalEvent.js +13 -0
  150. package/dist/esm/helpers/background.js +102 -0
  151. package/dist/esm/helpers/borders.js +133 -0
  152. package/dist/esm/helpers/clone-deep.js +3 -0
  153. package/dist/esm/helpers/cls.js +18 -0
  154. package/dist/esm/helpers/colors.js +145 -0
  155. package/dist/esm/helpers/compose-advance-style.js +130 -0
  156. package/dist/esm/helpers/constant.js +13 -0
  157. package/dist/esm/helpers/css-variable.js +5 -0
  158. package/dist/esm/helpers/email.js +6 -0
  159. package/dist/esm/helpers/flatten-connection.js +8 -0
  160. package/dist/esm/helpers/fpixel.js +25 -0
  161. package/dist/esm/helpers/get-resonsive-value.js +28 -0
  162. package/dist/esm/helpers/get-shortname.js +90 -0
  163. package/dist/esm/helpers/gtag.js +45 -0
  164. package/dist/esm/helpers/is-browser.js +5 -0
  165. package/dist/esm/helpers/is-defined.js +5 -0
  166. package/dist/esm/helpers/is-empty-children.js +7 -0
  167. package/dist/esm/helpers/layout.js +15 -0
  168. package/dist/esm/helpers/load-script.js +30 -0
  169. package/dist/esm/helpers/make-style.js +91 -0
  170. package/dist/esm/helpers/normalize-builder-data.js +15 -0
  171. package/dist/esm/helpers/prefetch-queries.js +66 -0
  172. package/dist/esm/helpers/product.js +32 -0
  173. package/dist/esm/helpers/queries/get-collection.js +170 -0
  174. package/dist/esm/helpers/queries/get-product-by-slug.js +97 -0
  175. package/dist/esm/helpers/queries/get-product.js +109 -0
  176. package/dist/esm/helpers/queries/get-products.js +133 -0
  177. package/dist/esm/helpers/radius.js +86 -0
  178. package/dist/esm/helpers/shadow.js +45 -0
  179. package/dist/esm/helpers/size.js +18 -0
  180. package/dist/esm/helpers/spacing.js +42 -0
  181. package/dist/esm/helpers/tiktokpixel.js +15 -0
  182. package/dist/esm/helpers/typography.js +5 -0
  183. package/dist/esm/hooks/cart/use-add-to-cart.js +18 -0
  184. package/dist/esm/hooks/cart/use-cart-data.js +24 -0
  185. package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +18 -0
  186. package/dist/esm/hooks/cart/use-cart-note-update.js +18 -0
  187. package/dist/esm/hooks/cart/use-create-cart.js +20 -0
  188. package/dist/esm/hooks/cart/use-remove-cart-item.js +18 -0
  189. package/dist/esm/hooks/cart/use-update-cart-item.js +18 -0
  190. package/dist/esm/hooks/shop/use-collection-query.js +14 -0
  191. package/dist/esm/hooks/shop/use-product-query.js +14 -0
  192. package/dist/esm/hooks/shop/use-products-query.js +14 -0
  193. package/dist/esm/hooks/shop.js +68 -0
  194. package/dist/esm/hooks/use-current-device.js +21 -0
  195. package/dist/esm/hooks/use-lazy-video.js +13 -0
  196. package/dist/esm/hooks/useCartId.js +32 -0
  197. package/dist/esm/hooks/useCartLine.js +7 -0
  198. package/dist/esm/hooks/useCartUI.js +38 -0
  199. package/dist/esm/hooks/useCollection.js +7 -0
  200. package/dist/esm/hooks/useFetchHandle.js +11 -0
  201. package/dist/esm/hooks/useFormatMoney.js +13 -0
  202. package/dist/esm/hooks/useIsomorphicLayoutEffect.js +6 -0
  203. package/dist/esm/hooks/useLoadScript.js +26 -0
  204. package/dist/esm/hooks/useMoney.js +48 -0
  205. package/dist/esm/hooks/usePrevious.js +15 -0
  206. package/dist/esm/hooks/useProduct.js +78 -0
  207. package/dist/esm/hooks/useProductList.js +16 -0
  208. package/dist/esm/hooks/useSuspenseFetch.js +20 -0
  209. package/dist/esm/hooks/useSwatchesOptions.js +35 -0
  210. package/dist/esm/index.js +82 -0
  211. package/dist/esm/types/global-style.js +4 -0
  212. package/dist/esm/types/shop.js +1 -0
  213. package/dist/types/index.d.ts +7393 -0
  214. package/package.json +50 -0
@@ -0,0 +1,32 @@
1
+ import { useSyncExternalStore, useCallback, useMemo } from 'react';
2
+
3
+ const cartKey = 'cart-id';
4
+ const getCartId = () => {
5
+ return window.localStorage.getItem(cartKey);
6
+ };
7
+ const writeCartId = (value) => {
8
+ if (value) {
9
+ window.localStorage.setItem(cartKey, value);
10
+ }
11
+ };
12
+ const removeCartId = () => {
13
+ window.localStorage.removeItem(cartKey);
14
+ };
15
+ const subscribeStorage = (callback) => {
16
+ window.addEventListener('storage', callback);
17
+ return () => {
18
+ window.removeEventListener('storage', callback);
19
+ };
20
+ };
21
+ const useCartId = () => {
22
+ const cartId = useSyncExternalStore(subscribeStorage, getCartId, () => undefined);
23
+ const updateCartId = useCallback((val) => {
24
+ writeCartId(val);
25
+ }, []);
26
+ const clearCartId = useCallback(() => {
27
+ removeCartId();
28
+ }, []);
29
+ return useMemo(() => ({ cartId, updateCartId, clearCartId }), [cartId, clearCartId, updateCartId]);
30
+ };
31
+
32
+ export { useCartId as default };
@@ -0,0 +1,7 @@
1
+ import { useCartLineStore } from '../contexts/CartLineContext.js';
2
+
3
+ const useCartLine = () => {
4
+ return useCartLineStore((s) => s.line);
5
+ };
6
+
7
+ export { useCartLine as default };
@@ -0,0 +1,38 @@
1
+ import { useCallback } from 'react';
2
+ import create from 'zustand';
3
+ import { usePluginEnable } from './shop.js';
4
+
5
+ const useStore = create((set) => ({
6
+ isCartOpen: false,
7
+ setOpen: (isCartOpen) => {
8
+ const scrollBarGap = window.innerWidth - document.documentElement.clientWidth;
9
+ const computedBodyPaddingRight = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'), 10);
10
+ if (isCartOpen) {
11
+ document.body.style.overflow = `hidden`;
12
+ document.body.style.paddingRight = `${computedBodyPaddingRight + scrollBarGap}px`;
13
+ }
14
+ else {
15
+ document.body.style.overflow = '';
16
+ document.body.style.paddingRight = '';
17
+ }
18
+ set({ isCartOpen });
19
+ },
20
+ }));
21
+ function useCartUI() {
22
+ const plugins = usePluginEnable();
23
+ const isCartOpen = useStore((s) => s.isCartOpen);
24
+ const setOpen = useStore((s) => s.setOpen);
25
+ const openCart = useCallback(() => {
26
+ if (plugins?.includes('cart-drawer')) {
27
+ setOpen(true);
28
+ }
29
+ }, [plugins, setOpen]);
30
+ const closeCart = useCallback(() => setOpen(false), [setOpen]);
31
+ return {
32
+ isCartOpen,
33
+ openCart,
34
+ closeCart,
35
+ };
36
+ }
37
+
38
+ export { useCartUI as default };
@@ -0,0 +1,7 @@
1
+ import { useCollectionStore } from '../contexts/CollectionContext.js';
2
+
3
+ const useCollection = () => {
4
+ return useCollectionStore((s) => s.collection);
5
+ };
6
+
7
+ export { useCollection };
@@ -0,0 +1,11 @@
1
+ import { useSWRConfig } from 'swr';
2
+
3
+ const useFetchHandle = () => {
4
+ const { fetcher } = useSWRConfig();
5
+ if (!fetcher) {
6
+ throw new Error('Application must be init within a fetcher');
7
+ }
8
+ return fetcher;
9
+ };
10
+
11
+ export { useFetchHandle };
@@ -0,0 +1,13 @@
1
+ import { useCallback } from 'react';
2
+ import { useLocale } from './shop.js';
3
+
4
+ const useFormatMoney = () => {
5
+ const { locale } = useLocale();
6
+ const formatMoney = useCallback((value, options) => new Intl.NumberFormat(locale, {
7
+ style: 'currency',
8
+ ...options,
9
+ }).format(value), [locale]);
10
+ return { formatMoney };
11
+ };
12
+
13
+ export { useFormatMoney as default };
@@ -0,0 +1,6 @@
1
+ import { useLayoutEffect } from 'react';
2
+
3
+ // const isBrowser = typeof window !== 'undefined';
4
+ const useIsomorphicLayoutEffect = useLayoutEffect;
5
+
6
+ export { useIsomorphicLayoutEffect as default };
@@ -0,0 +1,26 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { loadScript } from '../helpers/load-script.js';
3
+
4
+ /**
5
+ * The `useLoadScript` hook loads an external script tag on the client-side.
6
+ */
7
+ function useLoadScript(url, options) {
8
+ const [status, setStatus] = useState('loading');
9
+ const stringifiedOptions = JSON.stringify(options);
10
+ useEffect(() => {
11
+ async function loadScriptWrapper() {
12
+ try {
13
+ setStatus('loading');
14
+ await loadScript(url, options);
15
+ setStatus('done');
16
+ }
17
+ catch (error) {
18
+ setStatus('error');
19
+ }
20
+ }
21
+ loadScriptWrapper();
22
+ }, [url, stringifiedOptions, options]);
23
+ return status;
24
+ }
25
+
26
+ export { useLoadScript as default };
@@ -0,0 +1,48 @@
1
+ import { useMemo } from 'react';
2
+ import { useLocale, useCurrency } from './shop.js';
3
+
4
+ const NARROW_SYMBOL_MAP = {
5
+ USD: '$',
6
+ AUD: '$',
7
+ CAD: '$',
8
+ NZD: '$',
9
+ EUR: '€',
10
+ GBP: '£',
11
+ INR: '₹',
12
+ RUB: '₽',
13
+ CNY: '¥',
14
+ JPY: '¥',
15
+ BRL: 'R$',
16
+ };
17
+ const useMoney = (money) => {
18
+ const { locale } = useLocale();
19
+ const { currency } = useCurrency();
20
+ const options = useMemo(() => ({ style: 'currency', currency: currency }), [currency]);
21
+ const value = useMemo(() => new Intl.NumberFormat(locale, options).format(money), [locale, options, money]);
22
+ const baseParts = new Intl.NumberFormat(locale, options).formatToParts(money);
23
+ const nameParts = new Intl.NumberFormat(locale, {
24
+ ...options,
25
+ currencyDisplay: 'name',
26
+ }).formatToParts(money);
27
+ const narrowParts = new Intl.NumberFormat(locale, {
28
+ ...options,
29
+ currencyDisplay: 'narrowSymbol',
30
+ }).formatToParts(money);
31
+ const moneyValue = useMemo(() => ({
32
+ currencyCode: currency,
33
+ currencyName: nameParts.find((part) => part.type === 'currency')?.value ?? // e.g. "US dollars"
34
+ currency,
35
+ currencyNarrowSymbol: narrowParts.find((part) => part.type === 'currency')?.value ?? // e.g. "$"
36
+ (currency ? NARROW_SYMBOL_MAP[currency] : '') ??
37
+ '',
38
+ parts: baseParts,
39
+ localizedString: value,
40
+ amount: baseParts
41
+ .filter((part) => ['decimal', 'fraction', 'group', 'integer', 'literal'].includes(part.type))
42
+ .map((part) => part.value)
43
+ .join(''),
44
+ }), [baseParts, nameParts, narrowParts, value, currency]);
45
+ return moneyValue;
46
+ };
47
+
48
+ export { useMoney as default };
@@ -0,0 +1,15 @@
1
+ import { useRef, useEffect } from 'react';
2
+
3
+ const usePrevious = (value) => {
4
+ // The ref object is a generic container whose current property is mutable ...
5
+ // ... and can hold any value, similar to an instance property on a class
6
+ const ref = useRef();
7
+ // Store current value in ref
8
+ useEffect(() => {
9
+ ref.current = value;
10
+ }, [value]); // Only re-run if value changes
11
+ // Return previous value (happens before update in useEffect above)
12
+ return ref.current;
13
+ };
14
+
15
+ export { usePrevious };
@@ -0,0 +1,78 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import { useProductStore } from '../contexts/ProductContext.js';
3
+ import { flattenConnection } from '../helpers/flatten-connection.js';
4
+ import 'swr';
5
+ import { getSelectedVariant } from '../helpers/product.js';
6
+
7
+ const useUniqProductID = () => {
8
+ return useProductStore((s) => s.uiqueId);
9
+ };
10
+ const useProduct = () => {
11
+ return useProductStore((s) => s.product);
12
+ };
13
+ const useFeaturedImageGlobal = () => {
14
+ return useProductStore((s) => s.featuredImageGlobal);
15
+ };
16
+ const useProductProperties = () => {
17
+ return useProductStore((s) => s.properties);
18
+ };
19
+ const useQuantity = () => {
20
+ const quantity = useProductStore((s) => s.quantity);
21
+ const decrement = useProductStore((s) => s.decrementQuantity);
22
+ const increment = useProductStore((s) => s.incrementQuantity);
23
+ const updateQuantity = useProductStore((s) => s.setQuantity);
24
+ const reset = useCallback(() => {
25
+ updateQuantity(1);
26
+ }, [updateQuantity]);
27
+ return useMemo(() => ({ quantity, increment, decrement, reset, setQuantity: updateQuantity }), [decrement, increment, quantity, reset, updateQuantity]);
28
+ };
29
+ const useSelectedOption = () => {
30
+ const setSelectedOption = useProductStore((s) => s.setSelectedOption);
31
+ const selectedOptions = useProductStore((s) => s.selectedOptions);
32
+ const forceSelectedOption = useProductStore((s) => s.forceSelectedOption);
33
+ const updateOption = useCallback((optionId, optionValue) => {
34
+ setSelectedOption(optionId, optionValue);
35
+ }, [setSelectedOption]);
36
+ return useMemo(() => ({
37
+ selectedOptions,
38
+ setSelectedOption: updateOption,
39
+ forceSelectedOption,
40
+ }), [selectedOptions, updateOption, forceSelectedOption]);
41
+ };
42
+ const useVariants = () => {
43
+ const variants = useProductStore((s) => s.product?.variants);
44
+ return flattenConnection(variants);
45
+ };
46
+ const useVariant = (id) => {
47
+ const variants = useVariants();
48
+ return useMemo(() => variants?.find((v) => v?.id === id), [id, variants]);
49
+ };
50
+ const useCurrentVariant = () => {
51
+ const { selectedOptions } = useSelectedOption();
52
+ const variants = useVariants();
53
+ return useMemo(() => getSelectedVariant(variants, selectedOptions), [selectedOptions, variants]);
54
+ };
55
+ function checkInStock(variant) {
56
+ if (!variant)
57
+ return false;
58
+ return ((variant?.inventoryQuantity && variant.inventoryQuantity > 0) ||
59
+ !variant?.manageInventory ||
60
+ variant.inventoryPolicy === 'continue');
61
+ }
62
+ const useCurrentVariantInStock = () => {
63
+ const currentVariant = useCurrentVariant();
64
+ const isInStock = checkInStock(currentVariant);
65
+ return isInStock;
66
+ };
67
+ const useVariantOutStock = (optionId, optionValue) => {
68
+ const { selectedOptions } = useSelectedOption();
69
+ const variants = useVariants();
70
+ const matchedVariant = getSelectedVariant(variants, {
71
+ ...selectedOptions,
72
+ [optionId]: optionValue,
73
+ });
74
+ const isInStock = checkInStock(matchedVariant);
75
+ return !isInStock;
76
+ };
77
+
78
+ export { useCurrentVariant, useCurrentVariantInStock, useFeaturedImageGlobal, useProduct, useProductProperties, useQuantity, useSelectedOption, useUniqProductID, useVariant, useVariantOutStock, useVariants };
@@ -0,0 +1,16 @@
1
+ import { useProductListStore } from '../contexts/ProductListContext.js';
2
+
3
+ const useProductList = () => {
4
+ return useProductListStore((s) => s.collection);
5
+ };
6
+ const useProductListProducts = () => {
7
+ return useProductListStore((s) => s.products);
8
+ };
9
+ const useProductListSettings = () => {
10
+ return useProductListStore((s) => s.settings);
11
+ };
12
+ const useProductListStyles = () => {
13
+ return useProductListStore((s) => s.styles);
14
+ };
15
+
16
+ export { useProductList, useProductListProducts, useProductListSettings, useProductListStyles };
@@ -0,0 +1,20 @@
1
+ const cache = new Map();
2
+ const useSuspenseFetch = (key, promise) => {
3
+ const value = cache.get(key) || { status: 'new', data: null };
4
+ if (value.status === 'resolved') {
5
+ return { data: value.data };
6
+ }
7
+ promise()
8
+ .then((data) => {
9
+ value.status = 'resolved';
10
+ value.data = data;
11
+ cache.set(key, value);
12
+ })
13
+ .catch(() => {
14
+ value.status = 'error';
15
+ value.data = null;
16
+ });
17
+ throw promise();
18
+ };
19
+
20
+ export { useSuspenseFetch as default };
@@ -0,0 +1,35 @@
1
+ import { useSwatches } from './shop.js';
2
+
3
+ const initialSwatchOptionValue = {
4
+ label: '',
5
+ colors: [],
6
+ imageUrl: '',
7
+ };
8
+ const initialGlobalSwatchesData = {
9
+ optionTitle: '',
10
+ optionType: '',
11
+ optionValues: [],
12
+ };
13
+ const useSwatchesOptions = (options) => {
14
+ const { swatches } = useSwatches();
15
+ if (!options)
16
+ return [];
17
+ return options?.map((option) => {
18
+ const swatchOption = swatches?.find((sw) => sw?.optionTitle === option?.name) || { ...initialGlobalSwatchesData };
19
+ return {
20
+ ...option,
21
+ optionType: swatchOption ? swatchOption.optionType : '',
22
+ values: option.values?.map((val) => {
23
+ const swatchValue = (swatchOption &&
24
+ swatchOption?.optionValues?.find((swatOp) => swatOp?.label === val?.label)) || { ...initialSwatchOptionValue };
25
+ return {
26
+ ...val,
27
+ colors: swatchValue?.colors || [],
28
+ imageUrl: swatchValue?.imageUrl || '',
29
+ };
30
+ }),
31
+ };
32
+ });
33
+ };
34
+
35
+ export { useSwatchesOptions as default };
@@ -0,0 +1,82 @@
1
+ export { default as AddOn } from './components/AddOn.js';
2
+ export { default as Render } from './components/Render.js';
3
+ export { default as RenderPreview } from './components/RenderPreview.js';
4
+ export { AddonProvider, useAddon, useAddons } from './contexts/AddonContext.js';
5
+ export { BuilderComponentProvider, useBuilderComponent } from './contexts/BuilderComponent.js';
6
+ export { BuilderProvider, useBuilderStore } from './contexts/BuilderContext.js';
7
+ export { BuilderPreviewProvider, useBuilderPreviewStore } from './contexts/BuilderPreviewContext.js';
8
+ export { CartLineProvider, useCartLineStore } from './contexts/CartLineContext.js';
9
+ export { ProductListProvider, useProductListStore } from './contexts/ProductListContext.js';
10
+ export { ProductProvider, useProductStore } from './contexts/ProductContext.js';
11
+ export { SectionProvider, useSection, useSectionStore } from './contexts/SectionContext.js';
12
+ export { ShopProvider, useShopStore } from './contexts/ShopContext.js';
13
+ export { CollectionProvider, useCollectionStore } from './contexts/CollectionContext.js';
14
+ export { CollectionDetailFilterDocument } from './graphql/queries/collection-detail-filter.generated.js';
15
+ export { CollectionDocument } from './graphql/queries/collection.generated.js';
16
+ export { PublishedThemePagesDocument } from './graphql/queries/published-theme-pages.generated.js';
17
+ export { ProductsDocument } from './graphql/queries/products.generated.js';
18
+ export { StorePropertyDocument } from './graphql/queries/storeProperty.generated.js';
19
+ export { PreviewPageDocument } from './graphql/queries/preview-page.generated.js';
20
+ export { handleConvertBorderColor, handleConvertBorderStyle, handleConvertBorderWidth, handleConvertClassColor } from './helpers/borders.js';
21
+ export { cls } from './helpers/cls.js';
22
+ export { flattenConnection } from './helpers/flatten-connection.js';
23
+ export { getResponsiveStateValue, getResponsiveValue, getResponsiveValueByScreen } from './helpers/get-resonsive-value.js';
24
+ export { getShortName } from './helpers/get-shortname.js';
25
+ export { default as globalEvent } from './helpers/GlobalEvent.js';
26
+ export { default as isBrowser } from './helpers/is-browser.js';
27
+ export { isEmptyChildren } from './helpers/is-empty-children.js';
28
+ export { makeAspectRatio, makeHeight, makeStyle, makeStyleResponsive, makeStyleResponsiveState, makeStyleState, makeWidth } from './helpers/make-style.js';
29
+ export { normalizeBuilderData } from './helpers/normalize-builder-data.js';
30
+ export { prefetchQueries } from './helpers/prefetch-queries.js';
31
+ export { getStyleShadow, getStyleShadowState } from './helpers/shadow.js';
32
+ export { composeSize } from './helpers/size.js';
33
+ export { composeSpacing, getSpacingVariable } from './helpers/spacing.js';
34
+ export { loadScript } from './helpers/load-script.js';
35
+ export { validateEmail } from './helpers/email.js';
36
+ export { optionLayoutStyle } from './helpers/layout.js';
37
+ export { getStyleBackgroundByDevice } from './helpers/background.js';
38
+ export { genVariable } from './helpers/css-variable.js';
39
+ export { isDefined } from './helpers/is-defined.js';
40
+ export { getGlobalColorCSSProp, getGlobalColorClass, getGlobalColorResponsiveClass, getGlobalColorResponsiveStyle, getGlobalColorStateClass, getGlobalColorStateResponsiveClass, getGlobalColorStateResponsiveStyle, getGlobalColorStateStyle, getGlobalColorStyle, getSingleColorVariable, isColor } from './helpers/colors.js';
41
+ export { genTypoClass } from './helpers/typography.js';
42
+ export { composeRadius, getCustomRadius, getRadiusCSSFromGlobal, getRadiusStyleActiveState } from './helpers/radius.js';
43
+ export { getSelectedVariant, parseSelectedOption } from './helpers/product.js';
44
+ import * as fpixel from './helpers/fpixel.js';
45
+ export { fpixel };
46
+ import * as gtag from './helpers/gtag.js';
47
+ export { gtag };
48
+ import * as tiktokpixel from './helpers/tiktokpixel.js';
49
+ export { tiktokpixel };
50
+ export { useAddToCart } from './hooks/cart/use-add-to-cart.js';
51
+ export { useCartData } from './hooks/cart/use-cart-data.js';
52
+ export { useCartDiscountCodesUpdate } from './hooks/cart/use-cart-discount-codes-update.js';
53
+ export { useCartNoteUpdate } from './hooks/cart/use-cart-note-update.js';
54
+ export { useCreateCart } from './hooks/cart/use-create-cart.js';
55
+ export { useRemoveCartItem } from './hooks/cart/use-remove-cart-item.js';
56
+ export { useUpdateCartItem } from './hooks/cart/use-update-cart-item.js';
57
+ export { useConnectedShopify, useCurrency, useEditorMode, useIsSampleProduct, useLocale, useMatchMutate, useMobileOnly, usePageType, usePluginEnable, useStoreFront } from './hooks/shop.js';
58
+ export { useCollectionQuery } from './hooks/shop/use-collection-query.js';
59
+ export { useProductQuery } from './hooks/shop/use-product-query.js';
60
+ export { useProductsQuery } from './hooks/shop/use-products-query.js';
61
+ export { useCurrentDevice } from './hooks/use-current-device.js';
62
+ export { useLazyVideo } from './hooks/use-lazy-video.js';
63
+ export { default as useCartId } from './hooks/useCartId.js';
64
+ export { default as useCartLine } from './hooks/useCartLine.js';
65
+ export { default as useCartUI } from './hooks/useCartUI.js';
66
+ export { useCollection } from './hooks/useCollection.js';
67
+ export { default as useFormatMoney } from './hooks/useFormatMoney.js';
68
+ export { useId } from 'react';
69
+ export { default as useIsomorphicLayoutEffect } from './hooks/useIsomorphicLayoutEffect.js';
70
+ export { default as useLoadScript } from './hooks/useLoadScript.js';
71
+ export { default as useMoney } from './hooks/useMoney.js';
72
+ export { usePrevious } from './hooks/usePrevious.js';
73
+ export { useCurrentVariant, useCurrentVariantInStock, useFeaturedImageGlobal, useProduct, useProductProperties, useQuantity, useSelectedOption, useUniqProductID, useVariant, useVariantOutStock, useVariants } from './hooks/useProduct.js';
74
+ export { useProductList, useProductListProducts, useProductListSettings, useProductListStyles } from './hooks/useProductList.js';
75
+ export { default as useSuspenseFetch } from './hooks/useSuspenseFetch.js';
76
+ export { default as useSwatchesOptions } from './hooks/useSwatchesOptions.js';
77
+ import * as shop from './types/shop.js';
78
+ export { shop as ShopType };
79
+ export { OptionNormalStyle, OptionSpecialStyle } from './types/global-style.js';
80
+ export { calculateFirstProduct, getCollection } from './helpers/queries/get-collection.js';
81
+ export { fetchMedias, fetchVariants, getProduct } from './helpers/queries/get-product.js';
82
+ export { getProductBySlug } from './helpers/queries/get-product-by-slug.js';
@@ -0,0 +1,4 @@
1
+ const OptionNormalStyle = ['radio_buttons', 'dropdown'];
2
+ const OptionSpecialStyle = ['color', 'image', 'rectangle_list'];
3
+
4
+ export { OptionNormalStyle, OptionSpecialStyle };
@@ -0,0 +1 @@
1
+