@gem-sdk/core 1.5.17 → 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 +92 -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 +92 -69
- 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
|
@@ -5,12 +5,20 @@ var getProducts = require('../../helpers/queries/get-products.js');
|
|
|
5
5
|
var shop = require('../shop.js');
|
|
6
6
|
var useFetchHandle = require('../useFetchHandle.js');
|
|
7
7
|
|
|
8
|
-
const useProductsQuery = (ids, options)
|
|
9
|
-
const fetcher = useFetchHandle.useFetchHandle();
|
|
10
|
-
const isSample = shop.useIsSampleProduct();
|
|
11
|
-
return useSWR([
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const useProductsQuery = (ids, options)=>{
|
|
9
|
+
const fetcher = useFetchHandle.useFetchHandle();
|
|
10
|
+
const isSample = shop.useIsSampleProduct();
|
|
11
|
+
return useSWR([
|
|
12
|
+
'query/products',
|
|
13
|
+
{
|
|
14
|
+
ids: [
|
|
15
|
+
...ids ?? []
|
|
16
|
+
]?.sort(),
|
|
17
|
+
isSample
|
|
18
|
+
}
|
|
19
|
+
], async ([, arg])=>{
|
|
20
|
+
return getProducts.getProducts(fetcher, arg);
|
|
21
|
+
}, options);
|
|
14
22
|
};
|
|
15
23
|
|
|
16
24
|
exports.useProductsQuery = useProductsQuery;
|
package/dist/cjs/hooks/shop.js
CHANGED
|
@@ -4,73 +4,92 @@ var react = require('react');
|
|
|
4
4
|
var useSWR = require('swr');
|
|
5
5
|
var ShopContext = require('../contexts/ShopContext.js');
|
|
6
6
|
|
|
7
|
-
const useLocale = ()
|
|
8
|
-
const locale = ShopContext.useShopStore((state)
|
|
9
|
-
const changeLocale = ShopContext.useShopStore((state)
|
|
10
|
-
return react.useMemo(()
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const {
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
7
|
+
const useLocale = ()=>{
|
|
8
|
+
const locale = ShopContext.useShopStore((state)=>state.locale);
|
|
9
|
+
const changeLocale = ShopContext.useShopStore((state)=>state.changeLocale);
|
|
10
|
+
return react.useMemo(()=>({
|
|
11
|
+
locale,
|
|
12
|
+
changeLocale
|
|
13
|
+
}), [
|
|
14
|
+
locale,
|
|
15
|
+
changeLocale
|
|
16
|
+
]);
|
|
17
|
+
};
|
|
18
|
+
const useCurrency = ()=>{
|
|
19
|
+
const currency = ShopContext.useShopStore((state)=>state.currency);
|
|
20
|
+
const changeCurrency = ShopContext.useShopStore((state)=>state.changeCurrency);
|
|
21
|
+
return react.useMemo(()=>({
|
|
22
|
+
currency,
|
|
23
|
+
changeCurrency
|
|
24
|
+
}), [
|
|
25
|
+
currency,
|
|
26
|
+
changeCurrency
|
|
27
|
+
]);
|
|
28
|
+
};
|
|
29
|
+
const useSwatches = ()=>{
|
|
30
|
+
const swatches = ShopContext.useShopStore((state)=>state.swatches);
|
|
31
|
+
const changeSwatches = ShopContext.useShopStore((state)=>state.changeSwatches);
|
|
32
|
+
return react.useMemo(()=>({
|
|
33
|
+
swatches,
|
|
34
|
+
changeSwatches
|
|
35
|
+
}), [
|
|
36
|
+
swatches,
|
|
37
|
+
changeSwatches
|
|
38
|
+
]);
|
|
39
|
+
};
|
|
40
|
+
const usePageType = ()=>{
|
|
41
|
+
const pageType = ShopContext.useShopStore((state)=>state.pageType);
|
|
42
|
+
return react.useMemo(()=>pageType || 'STATIC', [
|
|
43
|
+
pageType
|
|
44
|
+
]);
|
|
45
|
+
};
|
|
46
|
+
const useStoreFront = ()=>{
|
|
47
|
+
const provider = ShopContext.useShopStore((state)=>state.provider);
|
|
48
|
+
const storefrontToken = ShopContext.useShopStore((state)=>state.storefrontToken);
|
|
49
|
+
const storefrontUrl = ShopContext.useShopStore((state)=>state.storefrontUrl);
|
|
50
|
+
return {
|
|
51
|
+
provider,
|
|
52
|
+
storefrontToken,
|
|
53
|
+
storefrontUrl
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const usePluginEnable = ()=>{
|
|
57
|
+
return ShopContext.useShopStore((state)=>state.plugins);
|
|
58
|
+
};
|
|
59
|
+
const useEditorMode = ()=>{
|
|
60
|
+
return ShopContext.useShopStore((state)=>state.mode);
|
|
61
|
+
};
|
|
62
|
+
const useMobileOnly = ()=>{
|
|
63
|
+
return ShopContext.useShopStore((state)=>state.mobileOnly);
|
|
64
|
+
};
|
|
65
|
+
const useMatchMutate = ()=>{
|
|
66
|
+
const { cache , mutate } = useSWR.useSWRConfig();
|
|
67
|
+
return (matcher, ...args)=>{
|
|
68
|
+
if (!(cache instanceof Map)) {
|
|
69
|
+
throw new Error('matchMutate requires the cache provider to be a Map instance');
|
|
70
|
+
}
|
|
71
|
+
const keys = [];
|
|
72
|
+
cache.forEach((_, key)=>{
|
|
73
|
+
if (matcher.test(key)) {
|
|
74
|
+
keys.push(key);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const mutations = keys.map((key)=>mutate(key, ...args));
|
|
78
|
+
return Promise.all(mutations);
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
function useConnectedShopify() {
|
|
82
|
+
const { storefrontToken } = useStoreFront();
|
|
83
|
+
return !!storefrontToken;
|
|
84
|
+
}
|
|
85
|
+
function useIsSampleProduct() {
|
|
86
|
+
const { storefrontToken } = useStoreFront();
|
|
87
|
+
return !storefrontToken;
|
|
88
|
+
}
|
|
89
|
+
function useCheckoutUrl(url) {
|
|
90
|
+
const { storefrontToken } = useStoreFront();
|
|
91
|
+
if (!url) return undefined;
|
|
92
|
+
return storefrontToken ? `${url}?access_token=${storefrontToken}` : url;
|
|
74
93
|
}
|
|
75
94
|
|
|
76
95
|
exports.useCheckoutUrl = useCheckoutUrl;
|
|
@@ -2,22 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
|
|
5
|
-
function subscribe(callback) {
|
|
6
|
-
window.addEventListener('resize', callback);
|
|
7
|
-
return ()
|
|
8
|
-
}
|
|
9
|
-
const useCurrentDevice = ()
|
|
10
|
-
return react.useSyncExternalStore(subscribe, ()
|
|
11
|
-
if (window.innerWidth < 768) {
|
|
12
|
-
return 'mobile';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
}, () => 'desktop');
|
|
5
|
+
function subscribe(callback) {
|
|
6
|
+
window.addEventListener('resize', callback);
|
|
7
|
+
return ()=>window.removeEventListener('resize', callback);
|
|
8
|
+
}
|
|
9
|
+
const useCurrentDevice = ()=>{
|
|
10
|
+
return react.useSyncExternalStore(subscribe, ()=>{
|
|
11
|
+
if (window.innerWidth < 768) {
|
|
12
|
+
return 'mobile';
|
|
13
|
+
} else if (window.innerWidth >= 768 && window.innerWidth < 1024) {
|
|
14
|
+
return 'tablet';
|
|
15
|
+
} else {
|
|
16
|
+
return 'desktop';
|
|
17
|
+
}
|
|
18
|
+
}, ()=>'desktop');
|
|
21
19
|
};
|
|
22
20
|
|
|
23
21
|
exports.useCurrentDevice = useCurrentDevice;
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var LazyLoad = require('vanilla-lazyload');
|
|
5
5
|
|
|
6
|
-
const useLazyVideo = ()
|
|
7
|
-
react.useEffect(()
|
|
8
|
-
const lazyLoadInstance = new LazyLoad({
|
|
9
|
-
use_native: true
|
|
10
|
-
});
|
|
11
|
-
lazyLoadInstance.update();
|
|
12
|
-
}, []);
|
|
6
|
+
const useLazyVideo = ()=>{
|
|
7
|
+
react.useEffect(()=>{
|
|
8
|
+
const lazyLoadInstance = new LazyLoad({
|
|
9
|
+
use_native: true
|
|
10
|
+
});
|
|
11
|
+
lazyLoadInstance.update();
|
|
12
|
+
}, []);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
exports.useLazyVideo = useLazyVideo;
|
|
@@ -4,33 +4,41 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
|
|
7
|
-
const cartKey = 'cart-id';
|
|
8
|
-
const getCartId = ()
|
|
9
|
-
return window.localStorage.getItem(cartKey);
|
|
10
|
-
};
|
|
11
|
-
const writeCartId = (value)
|
|
12
|
-
if (value) {
|
|
13
|
-
window.localStorage.setItem(cartKey, value);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const removeCartId = ()
|
|
17
|
-
window.localStorage.removeItem(cartKey);
|
|
18
|
-
};
|
|
19
|
-
const subscribeStorage = (callback)
|
|
20
|
-
window.addEventListener('storage', callback);
|
|
21
|
-
return ()
|
|
22
|
-
window.removeEventListener('storage', callback);
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
const useCartId = ()
|
|
26
|
-
const cartId = react.useSyncExternalStore(subscribeStorage, getCartId, ()
|
|
27
|
-
const updateCartId = react.useCallback((val)
|
|
28
|
-
writeCartId(val);
|
|
29
|
-
}, []);
|
|
30
|
-
const clearCartId = react.useCallback(()
|
|
31
|
-
removeCartId();
|
|
32
|
-
}, []);
|
|
33
|
-
return react.useMemo(()
|
|
7
|
+
const cartKey = 'cart-id';
|
|
8
|
+
const getCartId = ()=>{
|
|
9
|
+
return window.localStorage.getItem(cartKey);
|
|
10
|
+
};
|
|
11
|
+
const writeCartId = (value)=>{
|
|
12
|
+
if (value) {
|
|
13
|
+
window.localStorage.setItem(cartKey, value);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const removeCartId = ()=>{
|
|
17
|
+
window.localStorage.removeItem(cartKey);
|
|
18
|
+
};
|
|
19
|
+
const subscribeStorage = (callback)=>{
|
|
20
|
+
window.addEventListener('storage', callback);
|
|
21
|
+
return ()=>{
|
|
22
|
+
window.removeEventListener('storage', callback);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const useCartId = ()=>{
|
|
26
|
+
const cartId = react.useSyncExternalStore(subscribeStorage, getCartId, ()=>undefined);
|
|
27
|
+
const updateCartId = react.useCallback((val)=>{
|
|
28
|
+
writeCartId(val);
|
|
29
|
+
}, []);
|
|
30
|
+
const clearCartId = react.useCallback(()=>{
|
|
31
|
+
removeCartId();
|
|
32
|
+
}, []);
|
|
33
|
+
return react.useMemo(()=>({
|
|
34
|
+
cartId,
|
|
35
|
+
updateCartId,
|
|
36
|
+
clearCartId
|
|
37
|
+
}), [
|
|
38
|
+
cartId,
|
|
39
|
+
clearCartId,
|
|
40
|
+
updateCartId
|
|
41
|
+
]);
|
|
34
42
|
};
|
|
35
43
|
|
|
36
44
|
exports.default = useCartId;
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var CartLineContext = require('../contexts/CartLineContext.js');
|
|
6
6
|
|
|
7
|
-
const useCartLine = ()
|
|
8
|
-
return CartLineContext.useCartLineStore((s)
|
|
7
|
+
const useCartLine = ()=>{
|
|
8
|
+
return CartLineContext.useCartLineStore((s)=>s.line);
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
exports.default = useCartLine;
|
|
@@ -6,37 +6,43 @@ var react = require('react');
|
|
|
6
6
|
var zustand = require('zustand');
|
|
7
7
|
var shop = require('./shop.js');
|
|
8
8
|
|
|
9
|
-
const useStore = zustand.create((set)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
9
|
+
const useStore = zustand.create((set)=>({
|
|
10
|
+
isCartOpen: false,
|
|
11
|
+
setOpen: (isCartOpen)=>{
|
|
12
|
+
const scrollBarGap = window.innerWidth - document.documentElement.clientWidth;
|
|
13
|
+
const computedBodyPaddingRight = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'), 10);
|
|
14
|
+
if (isCartOpen) {
|
|
15
|
+
document.body.style.overflow = `hidden`;
|
|
16
|
+
document.body.style.paddingRight = `${computedBodyPaddingRight + scrollBarGap}px`;
|
|
17
|
+
} else {
|
|
18
|
+
document.body.style.overflow = '';
|
|
19
|
+
document.body.style.paddingRight = '';
|
|
20
|
+
}
|
|
21
|
+
set({
|
|
22
|
+
isCartOpen
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
function useCartUI() {
|
|
27
|
+
const plugins = shop.usePluginEnable();
|
|
28
|
+
const isCartOpen = useStore((s)=>s.isCartOpen);
|
|
29
|
+
const setOpen = useStore((s)=>s.setOpen);
|
|
30
|
+
const openCart = react.useCallback(()=>{
|
|
31
|
+
if (plugins?.includes('cart-drawer')) {
|
|
32
|
+
setOpen(true);
|
|
33
|
+
}
|
|
34
|
+
}, [
|
|
35
|
+
plugins,
|
|
36
|
+
setOpen
|
|
37
|
+
]);
|
|
38
|
+
const closeCart = react.useCallback(()=>setOpen(false), [
|
|
39
|
+
setOpen
|
|
40
|
+
]);
|
|
41
|
+
return {
|
|
42
|
+
isCartOpen,
|
|
43
|
+
openCart,
|
|
44
|
+
closeCart
|
|
45
|
+
};
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
exports.default = useCartUI;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var CollectionContext = require('../contexts/CollectionContext.js');
|
|
4
4
|
|
|
5
|
-
const useCollection = ()
|
|
6
|
-
return CollectionContext.useCollectionStore((s)
|
|
5
|
+
const useCollection = ()=>{
|
|
6
|
+
return CollectionContext.useCollectionStore((s)=>s.collection);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
exports.useCollection = useCollection;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var useSWR = require('swr');
|
|
4
4
|
|
|
5
|
-
const useFetchHandle = ()
|
|
6
|
-
const { fetcher
|
|
7
|
-
if (!fetcher) {
|
|
8
|
-
throw new Error('Application must be init within a fetcher');
|
|
9
|
-
}
|
|
10
|
-
return fetcher;
|
|
5
|
+
const useFetchHandle = ()=>{
|
|
6
|
+
const { fetcher } = useSWR.useSWRConfig();
|
|
7
|
+
if (!fetcher) {
|
|
8
|
+
throw new Error('Application must be init within a fetcher');
|
|
9
|
+
}
|
|
10
|
+
return fetcher;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
exports.useFetchHandle = useFetchHandle;
|
|
@@ -5,13 +5,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var shop = require('./shop.js');
|
|
7
7
|
|
|
8
|
-
const useFormatMoney = ()
|
|
9
|
-
const { locale
|
|
10
|
-
const formatMoney = react.useCallback((value, options)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const useFormatMoney = ()=>{
|
|
9
|
+
const { locale } = shop.useLocale();
|
|
10
|
+
const formatMoney = react.useCallback((value, options)=>new Intl.NumberFormat(locale, {
|
|
11
|
+
style: 'currency',
|
|
12
|
+
...options
|
|
13
|
+
}).format(value), [
|
|
14
|
+
locale
|
|
15
|
+
]);
|
|
16
|
+
return {
|
|
17
|
+
formatMoney
|
|
18
|
+
};
|
|
15
19
|
};
|
|
16
20
|
|
|
17
21
|
exports.default = useFormatMoney;
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
|
|
7
|
-
// const isBrowser = typeof window !== 'undefined';
|
|
7
|
+
// const isBrowser = typeof window !== 'undefined';
|
|
8
8
|
const useIsomorphicLayoutEffect = react.useLayoutEffect;
|
|
9
9
|
|
|
10
10
|
exports.default = useIsomorphicLayoutEffect;
|
|
@@ -5,26 +5,28 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var loadScript = require('../helpers/load-script.js');
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* The `useLoadScript` hook loads an external script tag on the client-side.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The `useLoadScript` hook loads an external script tag on the client-side.
|
|
10
|
+
*/ function useLoadScript(url, options) {
|
|
11
|
+
const [status, setStatus] = react.useState('loading');
|
|
12
|
+
const stringifiedOptions = JSON.stringify(options);
|
|
13
|
+
react.useEffect(()=>{
|
|
14
|
+
async function loadScriptWrapper() {
|
|
15
|
+
try {
|
|
16
|
+
setStatus('loading');
|
|
17
|
+
await loadScript.loadScript(url, options);
|
|
18
|
+
setStatus('done');
|
|
19
|
+
} catch (error) {
|
|
20
|
+
setStatus('error');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
loadScriptWrapper();
|
|
24
|
+
}, [
|
|
25
|
+
url,
|
|
26
|
+
stringifiedOptions,
|
|
27
|
+
options
|
|
28
|
+
]);
|
|
29
|
+
return status;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
exports.default = useLoadScript;
|
|
@@ -5,48 +5,65 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var shop = require('./shop.js');
|
|
7
7
|
|
|
8
|
-
const NARROW_SYMBOL_MAP = {
|
|
9
|
-
USD: '$',
|
|
10
|
-
AUD: '$',
|
|
11
|
-
CAD: '$',
|
|
12
|
-
NZD: '$',
|
|
13
|
-
EUR: '€',
|
|
14
|
-
GBP: '£',
|
|
15
|
-
INR: '₹',
|
|
16
|
-
RUB: '₽',
|
|
17
|
-
CNY: '¥',
|
|
18
|
-
JPY: '¥',
|
|
19
|
-
BRL: 'R$'
|
|
20
|
-
};
|
|
21
|
-
const useMoney = (money)
|
|
22
|
-
const { locale
|
|
23
|
-
const { currency
|
|
24
|
-
const options = react.useMemo(()
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
8
|
+
const NARROW_SYMBOL_MAP = {
|
|
9
|
+
USD: '$',
|
|
10
|
+
AUD: '$',
|
|
11
|
+
CAD: '$',
|
|
12
|
+
NZD: '$',
|
|
13
|
+
EUR: '€',
|
|
14
|
+
GBP: '£',
|
|
15
|
+
INR: '₹',
|
|
16
|
+
RUB: '₽',
|
|
17
|
+
CNY: '¥',
|
|
18
|
+
JPY: '¥',
|
|
19
|
+
BRL: 'R$'
|
|
20
|
+
};
|
|
21
|
+
const useMoney = (money)=>{
|
|
22
|
+
const { locale } = shop.useLocale();
|
|
23
|
+
const { currency } = shop.useCurrency();
|
|
24
|
+
const options = react.useMemo(()=>({
|
|
25
|
+
style: 'currency',
|
|
26
|
+
currency: currency
|
|
27
|
+
}), [
|
|
28
|
+
currency
|
|
29
|
+
]);
|
|
30
|
+
const value = react.useMemo(()=>new Intl.NumberFormat(locale, options).format(money), [
|
|
31
|
+
locale,
|
|
32
|
+
options,
|
|
33
|
+
money
|
|
34
|
+
]);
|
|
35
|
+
const baseParts = new Intl.NumberFormat(locale, options).formatToParts(money);
|
|
36
|
+
const nameParts = new Intl.NumberFormat(locale, {
|
|
37
|
+
...options,
|
|
38
|
+
currencyDisplay: 'name'
|
|
39
|
+
}).formatToParts(money);
|
|
40
|
+
const narrowParts = new Intl.NumberFormat(locale, {
|
|
41
|
+
...options,
|
|
42
|
+
currencyDisplay: 'narrowSymbol'
|
|
43
|
+
}).formatToParts(money);
|
|
44
|
+
const moneyValue = react.useMemo(()=>({
|
|
45
|
+
currencyCode: currency,
|
|
46
|
+
currencyName: nameParts.find((part)=>part.type === 'currency')?.value ?? // e.g. "US dollars"
|
|
47
|
+
currency,
|
|
48
|
+
currencyNarrowSymbol: narrowParts.find((part)=>part.type === 'currency')?.value ?? // e.g. "$"
|
|
49
|
+
(currency ? NARROW_SYMBOL_MAP[currency] : '') ?? '',
|
|
50
|
+
parts: baseParts,
|
|
51
|
+
localizedString: value,
|
|
52
|
+
amount: baseParts.filter((part)=>[
|
|
53
|
+
'decimal',
|
|
54
|
+
'fraction',
|
|
55
|
+
'group',
|
|
56
|
+
'integer',
|
|
57
|
+
'literal'
|
|
58
|
+
].includes(part.type)).map((part)=>part.value).join('')
|
|
59
|
+
}), [
|
|
60
|
+
baseParts,
|
|
61
|
+
nameParts,
|
|
62
|
+
narrowParts,
|
|
63
|
+
value,
|
|
64
|
+
currency
|
|
65
|
+
]);
|
|
66
|
+
return moneyValue;
|
|
50
67
|
};
|
|
51
68
|
|
|
52
69
|
exports.default = useMoney;
|