@gem-sdk/core 1.5.15 → 1.5.22
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 +7 -7
- package/dist/cjs/components/ComponentWrapper.js +14 -8
- package/dist/cjs/components/ComponentWrapperPreview.js +55 -46
- package/dist/cjs/components/Empty.js +1 -1
- package/dist/cjs/components/Render.js +50 -13
- package/dist/cjs/components/Render.liquid.js +81 -57
- package/dist/cjs/components/RenderBlock.js +41 -8
- package/dist/cjs/components/RenderPreview.js +51 -13
- package/dist/cjs/components/RenderSection.js +11 -7
- package/dist/cjs/components/constant.js +24 -24
- package/dist/cjs/contexts/AddonContext.js +25 -14
- package/dist/cjs/contexts/BuilderComponent.js +23 -19
- package/dist/cjs/contexts/BuilderContext.js +25 -19
- package/dist/cjs/contexts/BuilderPreviewContext.js +349 -341
- package/dist/cjs/contexts/CartLineContext.js +19 -14
- package/dist/cjs/contexts/CollectionContext.js +21 -13
- package/dist/cjs/contexts/ProductContext.js +136 -115
- package/dist/cjs/contexts/ProductListContext.js +21 -13
- package/dist/cjs/contexts/SectionContext.js +41 -37
- package/dist/cjs/contexts/ShopContext.js +49 -31
- package/dist/cjs/graphql/fragments/analytic.generated.js +1 -1
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +1 -1
- package/dist/cjs/graphql/fragments/collection-product.generated.js +1 -1
- package/dist/cjs/graphql/fragments/custom-code.generated.js +1 -1
- package/dist/cjs/graphql/fragments/data-seo.generated.js +1 -1
- package/dist/cjs/graphql/fragments/media.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-little.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-option.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +1 -1
- package/dist/cjs/graphql/fragments/selected-option.generated.js +1 -1
- package/dist/cjs/graphql/fragments/variant.generated.js +1 -1
- package/dist/cjs/graphql/mutations/page-view-up.generated.js +1 -1
- package/dist/cjs/graphql/queries/products.generated.js +1 -1
- package/dist/cjs/graphql/queries/store-property.generated.js +1 -1
- package/dist/cjs/helpers/GlobalEvent.js +12 -10
- package/dist/cjs/helpers/background.js +96 -96
- package/dist/cjs/helpers/borders.js +123 -127
- package/dist/cjs/helpers/clone-deep.js +1 -1
- package/dist/cjs/helpers/cls.js +11 -15
- package/dist/cjs/helpers/colors.js +121 -156
- package/dist/cjs/helpers/compose-advance-style.js +115 -121
- package/dist/cjs/helpers/constant.js +16 -11
- package/dist/cjs/helpers/css-variable.js +2 -2
- package/dist/cjs/helpers/email.js +3 -3
- package/dist/cjs/helpers/flatten-connection.js +4 -5
- package/dist/cjs/helpers/get-resonsive-value.js +24 -25
- package/dist/cjs/helpers/get-shortname.js +87 -87
- package/dist/cjs/helpers/is-browser.js +2 -2
- package/dist/cjs/helpers/is-defined.js +2 -2
- package/dist/cjs/helpers/is-empty-children.js +2 -2
- package/dist/cjs/helpers/layout.js +9 -10
- package/dist/cjs/helpers/load-script.js +26 -27
- package/dist/cjs/helpers/make-style.js +77 -86
- package/dist/cjs/helpers/normalize-builder-data.js +18 -12
- package/dist/cjs/helpers/prefetch-queries.js +72 -52
- package/dist/cjs/helpers/product.js +25 -29
- package/dist/cjs/helpers/queries/get-collection.js +179 -167
- package/dist/cjs/helpers/queries/get-product-by-slug.js +103 -94
- package/dist/cjs/helpers/queries/get-product.js +121 -106
- package/dist/cjs/helpers/queries/get-products.js +137 -125
- package/dist/cjs/helpers/radius.js +78 -81
- package/dist/cjs/helpers/render.js +56 -56
- package/dist/cjs/helpers/shadow.js +38 -38
- package/dist/cjs/helpers/size.js +12 -13
- package/dist/cjs/helpers/spacing.js +35 -37
- package/dist/cjs/helpers/tracking/fpixel.js +21 -22
- package/dist/cjs/helpers/tracking/gtag.js +84 -90
- package/dist/cjs/helpers/tracking/tiktokpixel.js +12 -12
- package/dist/cjs/helpers/typography.js +2 -2
- package/dist/cjs/hooks/cart/use-add-to-cart.js +10 -10
- package/dist/cjs/hooks/cart/use-cart-data.js +18 -16
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +10 -10
- package/dist/cjs/hooks/cart/use-cart-note-update.js +10 -10
- package/dist/cjs/hooks/cart/use-create-cart.js +12 -12
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +10 -10
- package/dist/cjs/hooks/cart/use-update-cart-item.js +10 -10
- package/dist/cjs/hooks/shop/use-collection-query.js +12 -6
- package/dist/cjs/hooks/shop/use-product-query.js +12 -6
- package/dist/cjs/hooks/shop/use-products-query.js +14 -6
- package/dist/cjs/hooks/shop.js +86 -67
- package/dist/cjs/hooks/use-current-device.js +14 -16
- package/dist/cjs/hooks/use-lazy-video.js +7 -7
- package/dist/cjs/hooks/useCartId.js +35 -27
- package/dist/cjs/hooks/useCartLine.js +2 -2
- package/dist/cjs/hooks/useCartUI.js +37 -31
- package/dist/cjs/hooks/useCollection.js +2 -2
- package/dist/cjs/hooks/useFetchHandle.js +6 -6
- package/dist/cjs/hooks/useFormatMoney.js +11 -7
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -1
- package/dist/cjs/hooks/useLoadScript.js +22 -20
- package/dist/cjs/hooks/useMoney.js +59 -42
- package/dist/cjs/hooks/usePrevious.js +12 -10
- package/dist/cjs/hooks/useProduct.js +93 -69
- package/dist/cjs/hooks/useProductList.js +11 -11
- package/dist/cjs/hooks/useSuspenseFetch.js +20 -17
- package/dist/cjs/hooks/useSwatchesOptions.js +32 -30
- package/dist/cjs/types/global-style.js +9 -2
- package/dist/esm/components/AddOn.js +7 -7
- package/dist/esm/components/ComponentWrapper.js +14 -8
- package/dist/esm/components/ComponentWrapperPreview.js +55 -46
- package/dist/esm/components/Empty.js +1 -1
- package/dist/esm/components/Render.js +50 -13
- package/dist/esm/components/Render.liquid.js +81 -57
- package/dist/esm/components/RenderBlock.js +41 -8
- package/dist/esm/components/RenderPreview.js +51 -13
- package/dist/esm/components/RenderSection.js +11 -7
- package/dist/esm/components/constant.js +24 -24
- package/dist/esm/contexts/AddonContext.js +26 -15
- package/dist/esm/contexts/BuilderComponent.js +24 -20
- package/dist/esm/contexts/BuilderContext.js +26 -20
- package/dist/esm/contexts/BuilderPreviewContext.js +350 -342
- package/dist/esm/contexts/CartLineContext.js +20 -15
- package/dist/esm/contexts/CollectionContext.js +22 -14
- package/dist/esm/contexts/ProductContext.js +137 -116
- package/dist/esm/contexts/ProductListContext.js +22 -14
- package/dist/esm/contexts/SectionContext.js +42 -38
- package/dist/esm/contexts/ShopContext.js +50 -32
- package/dist/esm/graphql/fragments/analytic.generated.js +1 -1
- package/dist/esm/graphql/fragments/collection-detail.generated.js +1 -1
- package/dist/esm/graphql/fragments/collection-product.generated.js +1 -1
- package/dist/esm/graphql/fragments/custom-code.generated.js +1 -1
- package/dist/esm/graphql/fragments/data-seo.generated.js +1 -1
- package/dist/esm/graphql/fragments/media.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-little.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-option-value.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-option.generated.js +1 -1
- package/dist/esm/graphql/fragments/product.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-page-section.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +1 -1
- package/dist/esm/graphql/fragments/selected-option.generated.js +1 -1
- package/dist/esm/graphql/fragments/variant.generated.js +1 -1
- package/dist/esm/graphql/mutations/page-view-up.generated.js +1 -1
- package/dist/esm/graphql/queries/products.generated.js +1 -1
- package/dist/esm/graphql/queries/store-property.generated.js +1 -1
- package/dist/esm/helpers/GlobalEvent.js +12 -10
- package/dist/esm/helpers/background.js +96 -96
- package/dist/esm/helpers/borders.js +123 -127
- package/dist/esm/helpers/clone-deep.js +1 -1
- package/dist/esm/helpers/cls.js +11 -15
- package/dist/esm/helpers/colors.js +121 -156
- package/dist/esm/helpers/compose-advance-style.js +115 -121
- package/dist/esm/helpers/constant.js +16 -11
- package/dist/esm/helpers/css-variable.js +2 -2
- package/dist/esm/helpers/email.js +3 -3
- package/dist/esm/helpers/flatten-connection.js +4 -5
- package/dist/esm/helpers/get-resonsive-value.js +24 -25
- package/dist/esm/helpers/get-shortname.js +87 -87
- package/dist/esm/helpers/is-browser.js +2 -2
- package/dist/esm/helpers/is-defined.js +2 -2
- package/dist/esm/helpers/is-empty-children.js +2 -2
- package/dist/esm/helpers/layout.js +9 -10
- package/dist/esm/helpers/load-script.js +26 -27
- package/dist/esm/helpers/make-style.js +77 -86
- package/dist/esm/helpers/normalize-builder-data.js +18 -12
- package/dist/esm/helpers/prefetch-queries.js +72 -52
- package/dist/esm/helpers/product.js +25 -29
- package/dist/esm/helpers/queries/get-collection.js +179 -167
- package/dist/esm/helpers/queries/get-product-by-slug.js +103 -94
- package/dist/esm/helpers/queries/get-product.js +121 -106
- package/dist/esm/helpers/queries/get-products.js +137 -125
- package/dist/esm/helpers/radius.js +78 -81
- package/dist/esm/helpers/render.js +56 -56
- package/dist/esm/helpers/shadow.js +38 -38
- package/dist/esm/helpers/size.js +12 -13
- package/dist/esm/helpers/spacing.js +35 -37
- package/dist/esm/helpers/tracking/fpixel.js +21 -22
- package/dist/esm/helpers/tracking/gtag.js +84 -90
- package/dist/esm/helpers/tracking/tiktokpixel.js +12 -12
- package/dist/esm/helpers/typography.js +2 -2
- package/dist/esm/hooks/cart/use-add-to-cart.js +10 -10
- package/dist/esm/hooks/cart/use-cart-data.js +18 -16
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +10 -10
- package/dist/esm/hooks/cart/use-cart-note-update.js +10 -10
- package/dist/esm/hooks/cart/use-create-cart.js +12 -12
- package/dist/esm/hooks/cart/use-remove-cart-item.js +10 -10
- package/dist/esm/hooks/cart/use-update-cart-item.js +10 -10
- package/dist/esm/hooks/shop/use-collection-query.js +12 -6
- package/dist/esm/hooks/shop/use-product-query.js +12 -6
- package/dist/esm/hooks/shop/use-products-query.js +14 -6
- package/dist/esm/hooks/shop.js +86 -67
- package/dist/esm/hooks/use-current-device.js +14 -16
- package/dist/esm/hooks/use-lazy-video.js +7 -7
- package/dist/esm/hooks/useCartId.js +35 -27
- package/dist/esm/hooks/useCartLine.js +2 -2
- package/dist/esm/hooks/useCartUI.js +37 -31
- package/dist/esm/hooks/useCollection.js +2 -2
- package/dist/esm/hooks/useFetchHandle.js +6 -6
- package/dist/esm/hooks/useFormatMoney.js +11 -7
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -1
- package/dist/esm/hooks/useLoadScript.js +22 -20
- package/dist/esm/hooks/useMoney.js +59 -42
- package/dist/esm/hooks/usePrevious.js +12 -10
- package/dist/esm/hooks/useProduct.js +93 -70
- package/dist/esm/hooks/useProductList.js +11 -11
- package/dist/esm/hooks/useSuspenseFetch.js +20 -17
- package/dist/esm/hooks/useSwatchesOptions.js +32 -30
- package/dist/esm/types/global-style.js +9 -2
- package/dist/types/index.d.ts +24 -2
- package/package.json +1 -1
|
@@ -3,12 +3,20 @@ import { getProducts } from '../../helpers/queries/get-products.js';
|
|
|
3
3
|
import { useIsSampleProduct } from '../shop.js';
|
|
4
4
|
import { useFetchHandle } from '../useFetchHandle.js';
|
|
5
5
|
|
|
6
|
-
const useProductsQuery = (ids, options)
|
|
7
|
-
const fetcher = useFetchHandle();
|
|
8
|
-
const isSample = useIsSampleProduct();
|
|
9
|
-
return useSWR([
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const useProductsQuery = (ids, options)=>{
|
|
7
|
+
const fetcher = useFetchHandle();
|
|
8
|
+
const isSample = useIsSampleProduct();
|
|
9
|
+
return useSWR([
|
|
10
|
+
'query/products',
|
|
11
|
+
{
|
|
12
|
+
ids: [
|
|
13
|
+
...ids ?? []
|
|
14
|
+
]?.sort(),
|
|
15
|
+
isSample
|
|
16
|
+
}
|
|
17
|
+
], async ([, arg])=>{
|
|
18
|
+
return getProducts(fetcher, arg);
|
|
19
|
+
}, options);
|
|
12
20
|
};
|
|
13
21
|
|
|
14
22
|
export { useProductsQuery };
|
package/dist/esm/hooks/shop.js
CHANGED
|
@@ -2,73 +2,92 @@ import { useMemo } from 'react';
|
|
|
2
2
|
import { useSWRConfig } from 'swr';
|
|
3
3
|
import { useShopStore } from '../contexts/ShopContext.js';
|
|
4
4
|
|
|
5
|
-
const useLocale = ()
|
|
6
|
-
const locale = useShopStore((state)
|
|
7
|
-
const changeLocale = useShopStore((state)
|
|
8
|
-
return useMemo(()
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const {
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
5
|
+
const useLocale = ()=>{
|
|
6
|
+
const locale = useShopStore((state)=>state.locale);
|
|
7
|
+
const changeLocale = useShopStore((state)=>state.changeLocale);
|
|
8
|
+
return useMemo(()=>({
|
|
9
|
+
locale,
|
|
10
|
+
changeLocale
|
|
11
|
+
}), [
|
|
12
|
+
locale,
|
|
13
|
+
changeLocale
|
|
14
|
+
]);
|
|
15
|
+
};
|
|
16
|
+
const useCurrency = ()=>{
|
|
17
|
+
const currency = useShopStore((state)=>state.currency);
|
|
18
|
+
const changeCurrency = useShopStore((state)=>state.changeCurrency);
|
|
19
|
+
return useMemo(()=>({
|
|
20
|
+
currency,
|
|
21
|
+
changeCurrency
|
|
22
|
+
}), [
|
|
23
|
+
currency,
|
|
24
|
+
changeCurrency
|
|
25
|
+
]);
|
|
26
|
+
};
|
|
27
|
+
const useSwatches = ()=>{
|
|
28
|
+
const swatches = useShopStore((state)=>state.swatches);
|
|
29
|
+
const changeSwatches = useShopStore((state)=>state.changeSwatches);
|
|
30
|
+
return useMemo(()=>({
|
|
31
|
+
swatches,
|
|
32
|
+
changeSwatches
|
|
33
|
+
}), [
|
|
34
|
+
swatches,
|
|
35
|
+
changeSwatches
|
|
36
|
+
]);
|
|
37
|
+
};
|
|
38
|
+
const usePageType = ()=>{
|
|
39
|
+
const pageType = useShopStore((state)=>state.pageType);
|
|
40
|
+
return useMemo(()=>pageType || 'STATIC', [
|
|
41
|
+
pageType
|
|
42
|
+
]);
|
|
43
|
+
};
|
|
44
|
+
const useStoreFront = ()=>{
|
|
45
|
+
const provider = useShopStore((state)=>state.provider);
|
|
46
|
+
const storefrontToken = useShopStore((state)=>state.storefrontToken);
|
|
47
|
+
const storefrontUrl = useShopStore((state)=>state.storefrontUrl);
|
|
48
|
+
return {
|
|
49
|
+
provider,
|
|
50
|
+
storefrontToken,
|
|
51
|
+
storefrontUrl
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const usePluginEnable = ()=>{
|
|
55
|
+
return useShopStore((state)=>state.plugins);
|
|
56
|
+
};
|
|
57
|
+
const useEditorMode = ()=>{
|
|
58
|
+
return useShopStore((state)=>state.mode);
|
|
59
|
+
};
|
|
60
|
+
const useMobileOnly = ()=>{
|
|
61
|
+
return useShopStore((state)=>state.mobileOnly);
|
|
62
|
+
};
|
|
63
|
+
const useMatchMutate = ()=>{
|
|
64
|
+
const { cache , mutate } = useSWRConfig();
|
|
65
|
+
return (matcher, ...args)=>{
|
|
66
|
+
if (!(cache instanceof Map)) {
|
|
67
|
+
throw new Error('matchMutate requires the cache provider to be a Map instance');
|
|
68
|
+
}
|
|
69
|
+
const keys = [];
|
|
70
|
+
cache.forEach((_, key)=>{
|
|
71
|
+
if (matcher.test(key)) {
|
|
72
|
+
keys.push(key);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const mutations = keys.map((key)=>mutate(key, ...args));
|
|
76
|
+
return Promise.all(mutations);
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
function useConnectedShopify() {
|
|
80
|
+
const { storefrontToken } = useStoreFront();
|
|
81
|
+
return !!storefrontToken;
|
|
82
|
+
}
|
|
83
|
+
function useIsSampleProduct() {
|
|
84
|
+
const { storefrontToken } = useStoreFront();
|
|
85
|
+
return !storefrontToken;
|
|
86
|
+
}
|
|
87
|
+
function useCheckoutUrl(url) {
|
|
88
|
+
const { storefrontToken } = useStoreFront();
|
|
89
|
+
if (!url) return undefined;
|
|
90
|
+
return storefrontToken ? `${url}?access_token=${storefrontToken}` : url;
|
|
72
91
|
}
|
|
73
92
|
|
|
74
93
|
export { useCheckoutUrl, useConnectedShopify, useCurrency, useEditorMode, useIsSampleProduct, useLocale, useMatchMutate, useMobileOnly, usePageType, usePluginEnable, useStoreFront, useSwatches };
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { useSyncExternalStore } from 'react';
|
|
2
2
|
|
|
3
|
-
function subscribe(callback) {
|
|
4
|
-
window.addEventListener('resize', callback);
|
|
5
|
-
return ()
|
|
6
|
-
}
|
|
7
|
-
const useCurrentDevice = ()
|
|
8
|
-
return useSyncExternalStore(subscribe, ()
|
|
9
|
-
if (window.innerWidth < 768) {
|
|
10
|
-
return 'mobile';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}, () => 'desktop');
|
|
3
|
+
function subscribe(callback) {
|
|
4
|
+
window.addEventListener('resize', callback);
|
|
5
|
+
return ()=>window.removeEventListener('resize', callback);
|
|
6
|
+
}
|
|
7
|
+
const useCurrentDevice = ()=>{
|
|
8
|
+
return useSyncExternalStore(subscribe, ()=>{
|
|
9
|
+
if (window.innerWidth < 768) {
|
|
10
|
+
return 'mobile';
|
|
11
|
+
} else if (window.innerWidth >= 768 && window.innerWidth < 1024) {
|
|
12
|
+
return 'tablet';
|
|
13
|
+
} else {
|
|
14
|
+
return 'desktop';
|
|
15
|
+
}
|
|
16
|
+
}, ()=>'desktop');
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
export { useCurrentDevice };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import LazyLoad from 'vanilla-lazyload';
|
|
3
3
|
|
|
4
|
-
const useLazyVideo = ()
|
|
5
|
-
useEffect(()
|
|
6
|
-
const lazyLoadInstance = new LazyLoad({
|
|
7
|
-
use_native: true
|
|
8
|
-
});
|
|
9
|
-
lazyLoadInstance.update();
|
|
10
|
-
}, []);
|
|
4
|
+
const useLazyVideo = ()=>{
|
|
5
|
+
useEffect(()=>{
|
|
6
|
+
const lazyLoadInstance = new LazyLoad({
|
|
7
|
+
use_native: true
|
|
8
|
+
});
|
|
9
|
+
lazyLoadInstance.update();
|
|
10
|
+
}, []);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { useLazyVideo };
|
|
@@ -1,32 +1,40 @@
|
|
|
1
1
|
import { useSyncExternalStore, useCallback, useMemo } from 'react';
|
|
2
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, ()
|
|
23
|
-
const updateCartId = useCallback((val)
|
|
24
|
-
writeCartId(val);
|
|
25
|
-
}, []);
|
|
26
|
-
const clearCartId = useCallback(()
|
|
27
|
-
removeCartId();
|
|
28
|
-
}, []);
|
|
29
|
-
return useMemo(()
|
|
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(()=>({
|
|
30
|
+
cartId,
|
|
31
|
+
updateCartId,
|
|
32
|
+
clearCartId
|
|
33
|
+
}), [
|
|
34
|
+
cartId,
|
|
35
|
+
clearCartId,
|
|
36
|
+
updateCartId
|
|
37
|
+
]);
|
|
30
38
|
};
|
|
31
39
|
|
|
32
40
|
export { useCartId as default };
|
|
@@ -2,37 +2,43 @@ import { useCallback } from 'react';
|
|
|
2
2
|
import { create } from 'zustand';
|
|
3
3
|
import { usePluginEnable } from './shop.js';
|
|
4
4
|
|
|
5
|
-
const useStore = create((set)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
} else {
|
|
14
|
+
document.body.style.overflow = '';
|
|
15
|
+
document.body.style.paddingRight = '';
|
|
16
|
+
}
|
|
17
|
+
set({
|
|
18
|
+
isCartOpen
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
function useCartUI() {
|
|
23
|
+
const plugins = usePluginEnable();
|
|
24
|
+
const isCartOpen = useStore((s)=>s.isCartOpen);
|
|
25
|
+
const setOpen = useStore((s)=>s.setOpen);
|
|
26
|
+
const openCart = useCallback(()=>{
|
|
27
|
+
if (plugins?.includes('cart-drawer')) {
|
|
28
|
+
setOpen(true);
|
|
29
|
+
}
|
|
30
|
+
}, [
|
|
31
|
+
plugins,
|
|
32
|
+
setOpen
|
|
33
|
+
]);
|
|
34
|
+
const closeCart = useCallback(()=>setOpen(false), [
|
|
35
|
+
setOpen
|
|
36
|
+
]);
|
|
37
|
+
return {
|
|
38
|
+
isCartOpen,
|
|
39
|
+
openCart,
|
|
40
|
+
closeCart
|
|
41
|
+
};
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
export { useCartUI as default };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCollectionStore } from '../contexts/CollectionContext.js';
|
|
2
2
|
|
|
3
|
-
const useCollection = ()
|
|
4
|
-
return useCollectionStore((s)
|
|
3
|
+
const useCollection = ()=>{
|
|
4
|
+
return useCollectionStore((s)=>s.collection);
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export { useCollection };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useSWRConfig } from 'swr';
|
|
2
2
|
|
|
3
|
-
const useFetchHandle = ()
|
|
4
|
-
const { fetcher
|
|
5
|
-
if (!fetcher) {
|
|
6
|
-
throw new Error('Application must be init within a fetcher');
|
|
7
|
-
}
|
|
8
|
-
return fetcher;
|
|
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
9
|
};
|
|
10
10
|
|
|
11
11
|
export { useFetchHandle };
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { useLocale } from './shop.js';
|
|
3
3
|
|
|
4
|
-
const useFormatMoney = ()
|
|
5
|
-
const { locale
|
|
6
|
-
const formatMoney = useCallback((value, options)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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), [
|
|
10
|
+
locale
|
|
11
|
+
]);
|
|
12
|
+
return {
|
|
13
|
+
formatMoney
|
|
14
|
+
};
|
|
11
15
|
};
|
|
12
16
|
|
|
13
17
|
export { useFormatMoney as default };
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
2
|
import { loadScript } from '../helpers/load-script.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* The `useLoadScript` hook loads an external script tag on the client-side.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The `useLoadScript` hook loads an external script tag on the client-side.
|
|
6
|
+
*/ function useLoadScript(url, options) {
|
|
7
|
+
const [status, setStatus] = useState('loading');
|
|
8
|
+
const stringifiedOptions = JSON.stringify(options);
|
|
9
|
+
useEffect(()=>{
|
|
10
|
+
async function loadScriptWrapper() {
|
|
11
|
+
try {
|
|
12
|
+
setStatus('loading');
|
|
13
|
+
await loadScript(url, options);
|
|
14
|
+
setStatus('done');
|
|
15
|
+
} catch (error) {
|
|
16
|
+
setStatus('error');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
loadScriptWrapper();
|
|
20
|
+
}, [
|
|
21
|
+
url,
|
|
22
|
+
stringifiedOptions,
|
|
23
|
+
options
|
|
24
|
+
]);
|
|
25
|
+
return status;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export { useLoadScript as default };
|
|
@@ -1,48 +1,65 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { useLocale, useCurrency } from './shop.js';
|
|
3
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
|
|
19
|
-
const { currency
|
|
20
|
-
const options = useMemo(()
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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(()=>({
|
|
21
|
+
style: 'currency',
|
|
22
|
+
currency: currency
|
|
23
|
+
}), [
|
|
24
|
+
currency
|
|
25
|
+
]);
|
|
26
|
+
const value = useMemo(()=>new Intl.NumberFormat(locale, options).format(money), [
|
|
27
|
+
locale,
|
|
28
|
+
options,
|
|
29
|
+
money
|
|
30
|
+
]);
|
|
31
|
+
const baseParts = new Intl.NumberFormat(locale, options).formatToParts(money);
|
|
32
|
+
const nameParts = new Intl.NumberFormat(locale, {
|
|
33
|
+
...options,
|
|
34
|
+
currencyDisplay: 'name'
|
|
35
|
+
}).formatToParts(money);
|
|
36
|
+
const narrowParts = new Intl.NumberFormat(locale, {
|
|
37
|
+
...options,
|
|
38
|
+
currencyDisplay: 'narrowSymbol'
|
|
39
|
+
}).formatToParts(money);
|
|
40
|
+
const moneyValue = useMemo(()=>({
|
|
41
|
+
currencyCode: currency,
|
|
42
|
+
currencyName: nameParts.find((part)=>part.type === 'currency')?.value ?? // e.g. "US dollars"
|
|
43
|
+
currency,
|
|
44
|
+
currencyNarrowSymbol: narrowParts.find((part)=>part.type === 'currency')?.value ?? // e.g. "$"
|
|
45
|
+
(currency ? NARROW_SYMBOL_MAP[currency] : '') ?? '',
|
|
46
|
+
parts: baseParts,
|
|
47
|
+
localizedString: value,
|
|
48
|
+
amount: baseParts.filter((part)=>[
|
|
49
|
+
'decimal',
|
|
50
|
+
'fraction',
|
|
51
|
+
'group',
|
|
52
|
+
'integer',
|
|
53
|
+
'literal'
|
|
54
|
+
].includes(part.type)).map((part)=>part.value).join('')
|
|
55
|
+
}), [
|
|
56
|
+
baseParts,
|
|
57
|
+
nameParts,
|
|
58
|
+
narrowParts,
|
|
59
|
+
value,
|
|
60
|
+
currency
|
|
61
|
+
]);
|
|
62
|
+
return moneyValue;
|
|
46
63
|
};
|
|
47
64
|
|
|
48
65
|
export { useMoney as default };
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { useRef, useEffect } from 'react';
|
|
2
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
|
-
}, [
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
}, [
|
|
11
|
+
value
|
|
12
|
+
]); // Only re-run if value changes
|
|
13
|
+
// Return previous value (happens before update in useEffect above)
|
|
14
|
+
return ref.current;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
export { usePrevious };
|