@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.
- package/dist/cjs/components/AddOn.js +18 -0
- package/dist/cjs/components/ComponentWrapper.js +45 -0
- package/dist/cjs/components/ComponentWrapperPreview.js +58 -0
- package/dist/cjs/components/Empty.js +7 -0
- package/dist/cjs/components/Render.js +28 -0
- package/dist/cjs/components/RenderBlock.js +21 -0
- package/dist/cjs/components/RenderPreview.js +28 -0
- package/dist/cjs/components/RenderSection.js +19 -0
- package/dist/cjs/contexts/AddonContext.js +25 -0
- package/dist/cjs/contexts/BuilderComponent.js +30 -0
- package/dist/cjs/contexts/BuilderContext.js +29 -0
- package/dist/cjs/contexts/BuilderPreviewContext.js +353 -0
- package/dist/cjs/contexts/CartLineContext.js +24 -0
- package/dist/cjs/contexts/CollectionContext.js +24 -0
- package/dist/cjs/contexts/ProductContext.js +126 -0
- package/dist/cjs/contexts/ProductListContext.js +24 -0
- package/dist/cjs/contexts/SectionContext.js +49 -0
- package/dist/cjs/contexts/ShopContext.js +43 -0
- package/dist/cjs/graphql/fragments/analytic.generated.js +11 -0
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +13 -0
- package/dist/cjs/graphql/fragments/collection-product.generated.js +26 -0
- package/dist/cjs/graphql/fragments/data-seo.generated.js +11 -0
- package/dist/cjs/graphql/fragments/media.generated.js +14 -0
- package/dist/cjs/graphql/fragments/product-little.generated.js +25 -0
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +13 -0
- package/dist/cjs/graphql/fragments/product-option.generated.js +14 -0
- package/dist/cjs/graphql/fragments/product.generated.js +33 -0
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +12 -0
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +11 -0
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +27 -0
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +11 -0
- package/dist/cjs/graphql/fragments/selected-option.generated.js +11 -0
- package/dist/cjs/graphql/fragments/variant.generated.js +35 -0
- package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +34 -0
- package/dist/cjs/graphql/queries/collection.generated.js +52 -0
- package/dist/cjs/graphql/queries/preview-page.generated.js +23 -0
- package/dist/cjs/graphql/queries/product-little-detail.generated.js +24 -0
- package/dist/cjs/graphql/queries/product-medias.generated.js +29 -0
- package/dist/cjs/graphql/queries/product-variants.generated.js +33 -0
- package/dist/cjs/graphql/queries/products.generated.js +41 -0
- package/dist/cjs/graphql/queries/published-theme-pages.generated.js +23 -0
- package/dist/cjs/graphql/queries/storeProperty.generated.js +12 -0
- package/dist/cjs/helpers/GlobalEvent.js +17 -0
- package/dist/cjs/helpers/background.js +104 -0
- package/dist/cjs/helpers/borders.js +138 -0
- package/dist/cjs/helpers/clone-deep.js +5 -0
- package/dist/cjs/helpers/cls.js +20 -0
- package/dist/cjs/helpers/colors.js +157 -0
- package/dist/cjs/helpers/compose-advance-style.js +132 -0
- package/dist/cjs/helpers/constant.js +17 -0
- package/dist/cjs/helpers/css-variable.js +7 -0
- package/dist/cjs/helpers/email.js +11 -0
- package/dist/cjs/helpers/flatten-connection.js +10 -0
- package/dist/cjs/helpers/fpixel.js +29 -0
- package/dist/cjs/helpers/get-resonsive-value.js +32 -0
- package/dist/cjs/helpers/get-shortname.js +92 -0
- package/dist/cjs/helpers/gtag.js +48 -0
- package/dist/cjs/helpers/is-browser.js +9 -0
- package/dist/cjs/helpers/is-defined.js +7 -0
- package/dist/cjs/helpers/is-empty-children.js +12 -0
- package/dist/cjs/helpers/layout.js +17 -0
- package/dist/cjs/helpers/load-script.js +32 -0
- package/dist/cjs/helpers/make-style.js +99 -0
- package/dist/cjs/helpers/normalize-builder-data.js +17 -0
- package/dist/cjs/helpers/prefetch-queries.js +68 -0
- package/dist/cjs/helpers/product.js +35 -0
- package/dist/cjs/helpers/queries/get-collection.js +173 -0
- package/dist/cjs/helpers/queries/get-product-by-slug.js +99 -0
- package/dist/cjs/helpers/queries/get-product.js +113 -0
- package/dist/cjs/helpers/queries/get-products.js +135 -0
- package/dist/cjs/helpers/radius.js +91 -0
- package/dist/cjs/helpers/shadow.js +48 -0
- package/dist/cjs/helpers/size.js +20 -0
- package/dist/cjs/helpers/spacing.js +45 -0
- package/dist/cjs/helpers/tiktokpixel.js +17 -0
- package/dist/cjs/helpers/typography.js +7 -0
- package/dist/cjs/hooks/cart/use-add-to-cart.js +20 -0
- package/dist/cjs/hooks/cart/use-cart-data.js +26 -0
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +20 -0
- package/dist/cjs/hooks/cart/use-cart-note-update.js +20 -0
- package/dist/cjs/hooks/cart/use-create-cart.js +22 -0
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +20 -0
- package/dist/cjs/hooks/cart/use-update-cart-item.js +20 -0
- package/dist/cjs/hooks/shop/use-collection-query.js +16 -0
- package/dist/cjs/hooks/shop/use-product-query.js +16 -0
- package/dist/cjs/hooks/shop/use-products-query.js +16 -0
- package/dist/cjs/hooks/shop.js +80 -0
- package/dist/cjs/hooks/use-current-device.js +23 -0
- package/dist/cjs/hooks/use-lazy-video.js +15 -0
- package/dist/cjs/hooks/useCartId.js +36 -0
- package/dist/cjs/hooks/useCartLine.js +11 -0
- package/dist/cjs/hooks/useCartUI.js +42 -0
- package/dist/cjs/hooks/useCollection.js +9 -0
- package/dist/cjs/hooks/useFetchHandle.js +13 -0
- package/dist/cjs/hooks/useFormatMoney.js +17 -0
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +10 -0
- package/dist/cjs/hooks/useLoadScript.js +30 -0
- package/dist/cjs/hooks/useMoney.js +52 -0
- package/dist/cjs/hooks/usePrevious.js +17 -0
- package/dist/cjs/hooks/useProduct.js +90 -0
- package/dist/cjs/hooks/useProductList.js +21 -0
- package/dist/cjs/hooks/useSuspenseFetch.js +24 -0
- package/dist/cjs/hooks/useSwatchesOptions.js +39 -0
- package/dist/cjs/index.js +229 -0
- package/dist/cjs/types/global-style.js +7 -0
- package/dist/cjs/types/shop.js +2 -0
- package/dist/esm/components/AddOn.js +14 -0
- package/dist/esm/components/ComponentWrapper.js +40 -0
- package/dist/esm/components/ComponentWrapperPreview.js +54 -0
- package/dist/esm/components/Empty.js +3 -0
- package/dist/esm/components/Render.js +24 -0
- package/dist/esm/components/RenderBlock.js +17 -0
- package/dist/esm/components/RenderPreview.js +24 -0
- package/dist/esm/components/RenderSection.js +15 -0
- package/dist/esm/contexts/AddonContext.js +21 -0
- package/dist/esm/contexts/BuilderComponent.js +27 -0
- package/dist/esm/contexts/BuilderContext.js +26 -0
- package/dist/esm/contexts/BuilderPreviewContext.js +350 -0
- package/dist/esm/contexts/CartLineContext.js +21 -0
- package/dist/esm/contexts/CollectionContext.js +20 -0
- package/dist/esm/contexts/ProductContext.js +123 -0
- package/dist/esm/contexts/ProductListContext.js +20 -0
- package/dist/esm/contexts/SectionContext.js +45 -0
- package/dist/esm/contexts/ShopContext.js +40 -0
- package/dist/esm/graphql/fragments/analytic.generated.js +9 -0
- package/dist/esm/graphql/fragments/collection-detail.generated.js +11 -0
- package/dist/esm/graphql/fragments/collection-product.generated.js +24 -0
- package/dist/esm/graphql/fragments/data-seo.generated.js +9 -0
- package/dist/esm/graphql/fragments/media.generated.js +12 -0
- package/dist/esm/graphql/fragments/product-little.generated.js +23 -0
- package/dist/esm/graphql/fragments/product-option-value.generated.js +11 -0
- package/dist/esm/graphql/fragments/product-option.generated.js +12 -0
- package/dist/esm/graphql/fragments/product.generated.js +31 -0
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +10 -0
- package/dist/esm/graphql/fragments/published-page-section.generated.js +9 -0
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +25 -0
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +9 -0
- package/dist/esm/graphql/fragments/selected-option.generated.js +9 -0
- package/dist/esm/graphql/fragments/variant.generated.js +33 -0
- package/dist/esm/graphql/queries/collection-detail-filter.generated.js +32 -0
- package/dist/esm/graphql/queries/collection.generated.js +50 -0
- package/dist/esm/graphql/queries/preview-page.generated.js +21 -0
- package/dist/esm/graphql/queries/product-little-detail.generated.js +22 -0
- package/dist/esm/graphql/queries/product-medias.generated.js +27 -0
- package/dist/esm/graphql/queries/product-variants.generated.js +31 -0
- package/dist/esm/graphql/queries/products.generated.js +38 -0
- package/dist/esm/graphql/queries/published-theme-pages.generated.js +21 -0
- package/dist/esm/graphql/queries/storeProperty.generated.js +10 -0
- package/dist/esm/helpers/GlobalEvent.js +13 -0
- package/dist/esm/helpers/background.js +102 -0
- package/dist/esm/helpers/borders.js +133 -0
- package/dist/esm/helpers/clone-deep.js +3 -0
- package/dist/esm/helpers/cls.js +18 -0
- package/dist/esm/helpers/colors.js +145 -0
- package/dist/esm/helpers/compose-advance-style.js +130 -0
- package/dist/esm/helpers/constant.js +13 -0
- package/dist/esm/helpers/css-variable.js +5 -0
- package/dist/esm/helpers/email.js +6 -0
- package/dist/esm/helpers/flatten-connection.js +8 -0
- package/dist/esm/helpers/fpixel.js +25 -0
- package/dist/esm/helpers/get-resonsive-value.js +28 -0
- package/dist/esm/helpers/get-shortname.js +90 -0
- package/dist/esm/helpers/gtag.js +45 -0
- package/dist/esm/helpers/is-browser.js +5 -0
- package/dist/esm/helpers/is-defined.js +5 -0
- package/dist/esm/helpers/is-empty-children.js +7 -0
- package/dist/esm/helpers/layout.js +15 -0
- package/dist/esm/helpers/load-script.js +30 -0
- package/dist/esm/helpers/make-style.js +91 -0
- package/dist/esm/helpers/normalize-builder-data.js +15 -0
- package/dist/esm/helpers/prefetch-queries.js +66 -0
- package/dist/esm/helpers/product.js +32 -0
- package/dist/esm/helpers/queries/get-collection.js +170 -0
- package/dist/esm/helpers/queries/get-product-by-slug.js +97 -0
- package/dist/esm/helpers/queries/get-product.js +109 -0
- package/dist/esm/helpers/queries/get-products.js +133 -0
- package/dist/esm/helpers/radius.js +86 -0
- package/dist/esm/helpers/shadow.js +45 -0
- package/dist/esm/helpers/size.js +18 -0
- package/dist/esm/helpers/spacing.js +42 -0
- package/dist/esm/helpers/tiktokpixel.js +15 -0
- package/dist/esm/helpers/typography.js +5 -0
- package/dist/esm/hooks/cart/use-add-to-cart.js +18 -0
- package/dist/esm/hooks/cart/use-cart-data.js +24 -0
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +18 -0
- package/dist/esm/hooks/cart/use-cart-note-update.js +18 -0
- package/dist/esm/hooks/cart/use-create-cart.js +20 -0
- package/dist/esm/hooks/cart/use-remove-cart-item.js +18 -0
- package/dist/esm/hooks/cart/use-update-cart-item.js +18 -0
- package/dist/esm/hooks/shop/use-collection-query.js +14 -0
- package/dist/esm/hooks/shop/use-product-query.js +14 -0
- package/dist/esm/hooks/shop/use-products-query.js +14 -0
- package/dist/esm/hooks/shop.js +68 -0
- package/dist/esm/hooks/use-current-device.js +21 -0
- package/dist/esm/hooks/use-lazy-video.js +13 -0
- package/dist/esm/hooks/useCartId.js +32 -0
- package/dist/esm/hooks/useCartLine.js +7 -0
- package/dist/esm/hooks/useCartUI.js +38 -0
- package/dist/esm/hooks/useCollection.js +7 -0
- package/dist/esm/hooks/useFetchHandle.js +11 -0
- package/dist/esm/hooks/useFormatMoney.js +13 -0
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +6 -0
- package/dist/esm/hooks/useLoadScript.js +26 -0
- package/dist/esm/hooks/useMoney.js +48 -0
- package/dist/esm/hooks/usePrevious.js +15 -0
- package/dist/esm/hooks/useProduct.js +78 -0
- package/dist/esm/hooks/useProductList.js +16 -0
- package/dist/esm/hooks/useSuspenseFetch.js +20 -0
- package/dist/esm/hooks/useSwatchesOptions.js +35 -0
- package/dist/esm/index.js +82 -0
- package/dist/esm/types/global-style.js +4 -0
- package/dist/esm/types/shop.js +1 -0
- package/dist/types/index.d.ts +7393 -0
- 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,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,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,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 @@
|
|
|
1
|
+
|