@gem-sdk/core 1.13.42 → 1.14.0-dev.286
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 +1 -18
- package/dist/cjs/components/ComponentWrapper.js +1 -28
- package/dist/cjs/components/ComponentWrapperPreview.js +1 -72
- package/dist/cjs/components/Empty.js +1 -7
- package/dist/cjs/components/Render.js +1 -65
- package/dist/cjs/components/Render.liquid.js +15 -158
- package/dist/cjs/components/RenderBlock.js +1 -54
- package/dist/cjs/components/RenderCustomCode.js +5 -0
- package/dist/cjs/components/RenderPreview.js +1 -66
- package/dist/cjs/components/RenderSection.js +1 -23
- package/dist/cjs/components/constant.js +1 -39
- package/dist/cjs/components/src/product/helpers/variant-presets.js +1 -0
- package/dist/cjs/contexts/AddonContext.js +1 -36
- package/dist/cjs/contexts/BuilderComponent.js +1 -34
- package/dist/cjs/contexts/BuilderContext.js +1 -35
- package/dist/cjs/contexts/BuilderPreviewContext.js +1 -370
- package/dist/cjs/contexts/CartLineContext.js +1 -29
- package/dist/cjs/contexts/CollectionContext.js +1 -38
- package/dist/cjs/contexts/ModalContext.js +1 -47
- package/dist/cjs/contexts/ProductContext.js +1 -149
- package/dist/cjs/contexts/ProductListContext.js +1 -32
- package/dist/cjs/contexts/SectionContext.js +1 -53
- package/dist/cjs/contexts/ShopContext.js +1 -70
- package/dist/cjs/graphql/fragments/analytic.generated.js +2 -6
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +2 -6
- package/dist/cjs/graphql/fragments/collection-product.generated.js +2 -6
- package/dist/cjs/graphql/fragments/collection.generated.js +2 -6
- package/dist/cjs/graphql/fragments/custom-code.generated.js +2 -6
- package/dist/cjs/graphql/fragments/data-seo.generated.js +2 -6
- package/dist/cjs/graphql/fragments/media.generated.js +3 -6
- package/dist/cjs/graphql/fragments/product-little.generated.js +2 -6
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +2 -6
- package/dist/cjs/graphql/fragments/product-option.generated.js +2 -6
- package/dist/cjs/graphql/fragments/product.generated.js +2 -6
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +2 -6
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +2 -6
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +2 -6
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +2 -6
- package/dist/cjs/graphql/fragments/selected-option.generated.js +2 -6
- package/dist/cjs/graphql/fragments/variant.generated.js +2 -6
- package/dist/cjs/graphql/mutations/page-view-up.generated.js +3 -7
- package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +2 -16
- package/dist/cjs/graphql/queries/collection.generated.js +2 -14
- package/dist/cjs/graphql/queries/collections.generated.js +2 -9
- package/dist/cjs/graphql/queries/preview-page.generated.js +2 -14
- package/dist/cjs/graphql/queries/product-little-detail.generated.js +2 -11
- package/dist/cjs/graphql/queries/product-medias.generated.js +2 -8
- package/dist/cjs/graphql/queries/product-value-label.generated.js +7 -0
- package/dist/cjs/graphql/queries/product-variants.generated.js +2 -10
- package/dist/cjs/graphql/queries/products.generated.js +3 -17
- package/dist/cjs/graphql/queries/published-theme-pages.generated.js +2 -14
- package/dist/cjs/graphql/queries/store-property.generated.js +2 -6
- package/dist/cjs/helpers/GlobalEvent.js +1 -19
- package/dist/cjs/helpers/background.js +1 -109
- package/dist/cjs/helpers/borders.js +4 -183
- package/dist/cjs/helpers/clone-deep.js +1 -5
- package/dist/cjs/helpers/cls.js +1 -16
- package/dist/cjs/helpers/colors.js +1 -183
- package/dist/cjs/helpers/compose-advance-style.js +1 -188
- package/dist/cjs/helpers/constant.js +1 -23
- package/dist/cjs/helpers/convert.js +1 -7
- package/dist/cjs/helpers/css-variable.js +1 -7
- package/dist/cjs/helpers/email.js +1 -11
- package/dist/cjs/helpers/flatten-connection.js +1 -9
- package/dist/cjs/helpers/get-resonsive-value.js +1 -31
- package/dist/cjs/helpers/get-shortname.js +1 -92
- package/dist/cjs/helpers/is-browser.js +1 -9
- package/dist/cjs/helpers/is-defined.js +1 -7
- package/dist/cjs/helpers/is-empty-children.js +1 -12
- package/dist/cjs/helpers/is-safari.js +1 -9
- package/dist/cjs/helpers/layout.js +1 -59
- package/dist/cjs/helpers/load-script.js +1 -31
- package/dist/cjs/helpers/make-style.js +1 -128
- package/dist/cjs/helpers/normalize-builder-data.js +1 -23
- package/dist/cjs/helpers/prefetch-queries.js +1 -78
- package/dist/cjs/helpers/product.js +1 -45
- package/dist/cjs/helpers/queries/get-collection.js +1 -220
- package/dist/cjs/helpers/queries/get-collections.js +1 -21
- package/dist/cjs/helpers/queries/get-product-by-slug.js +1 -125
- package/dist/cjs/helpers/queries/get-product.js +1 -154
- package/dist/cjs/helpers/queries/get-products.js +1 -161
- package/dist/cjs/helpers/query.js +1 -29
- package/dist/cjs/helpers/radius.js +6 -134
- package/dist/cjs/helpers/render.js +1 -71
- package/dist/cjs/helpers/shadow.js +1 -56
- package/dist/cjs/helpers/size.js +4 -35
- package/dist/cjs/helpers/spacing.js +1 -43
- package/dist/cjs/helpers/tracking/fpixel.js +1 -28
- package/dist/cjs/helpers/tracking/gtag.js +1 -93
- package/dist/cjs/helpers/tracking/tiktokpixel.js +1 -17
- package/dist/cjs/helpers/typography.js +17 -105
- package/dist/cjs/helpers/variant.js +1 -8
- package/dist/cjs/hooks/cart/use-add-to-cart.js +1 -20
- package/dist/cjs/hooks/cart/use-cart-data.js +1 -28
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +1 -20
- package/dist/cjs/hooks/cart/use-cart-note-update.js +1 -20
- package/dist/cjs/hooks/cart/use-create-cart.js +1 -22
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +1 -20
- package/dist/cjs/hooks/cart/use-update-cart-item.js +1 -20
- package/dist/cjs/hooks/shop/use-collection-query.js +1 -22
- package/dist/cjs/hooks/shop/use-collections-query.js +1 -17
- package/dist/cjs/hooks/shop/use-product-query.js +1 -22
- package/dist/cjs/hooks/shop/use-products-query.js +1 -22
- package/dist/cjs/hooks/shop.js +1 -126
- package/dist/cjs/hooks/use-current-device.js +1 -21
- package/dist/cjs/hooks/use-lazy-video.js +1 -15
- package/dist/cjs/hooks/useCartId.js +1 -44
- package/dist/cjs/hooks/useCartLine.js +1 -11
- package/dist/cjs/hooks/useCartUI.js +1 -48
- package/dist/cjs/hooks/useCollection.js +1 -9
- package/dist/cjs/hooks/useFetchHandle.js +1 -13
- package/dist/cjs/hooks/useFormatMoney.js +1 -58
- package/dist/cjs/hooks/useInitialSwatchesOptions.js +1 -0
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -10
- package/dist/cjs/hooks/useLoadScript.js +1 -32
- package/dist/cjs/hooks/useMoney.js +1 -84
- package/dist/cjs/hooks/usePrevious.js +1 -19
- package/dist/cjs/hooks/useProduct.js +1 -124
- package/dist/cjs/hooks/useProductList.js +1 -21
- package/dist/cjs/hooks/useSuspenseFetch.js +1 -27
- package/dist/cjs/hooks/useSwatchesOptions.js +1 -41
- package/dist/cjs/index.js +1 -291
- package/dist/cjs/types/global-style.js +1 -14
- package/dist/cjs/types/shop.js +1 -2
- package/dist/esm/components/AddOn.js +1 -14
- package/dist/esm/components/ComponentWrapper.js +1 -24
- package/dist/esm/components/ComponentWrapperPreview.js +1 -68
- package/dist/esm/components/Empty.js +1 -3
- package/dist/esm/components/Render.js +1 -61
- package/dist/esm/components/Render.liquid.js +15 -153
- package/dist/esm/components/RenderBlock.js +1 -50
- package/dist/esm/components/RenderCustomCode.js +5 -0
- package/dist/esm/components/RenderPreview.js +1 -62
- package/dist/esm/components/RenderSection.js +1 -19
- package/dist/esm/components/constant.js +1 -37
- package/dist/esm/components/src/product/helpers/variant-presets.js +1 -0
- package/dist/esm/contexts/AddonContext.js +1 -32
- package/dist/esm/contexts/BuilderComponent.js +1 -31
- package/dist/esm/contexts/BuilderContext.js +1 -32
- package/dist/esm/contexts/BuilderPreviewContext.js +1 -367
- package/dist/esm/contexts/CartLineContext.js +1 -26
- package/dist/esm/contexts/CollectionContext.js +1 -35
- package/dist/esm/contexts/ModalContext.js +1 -44
- package/dist/esm/contexts/ProductContext.js +1 -146
- package/dist/esm/contexts/ProductListContext.js +1 -28
- package/dist/esm/contexts/SectionContext.js +1 -49
- package/dist/esm/contexts/ShopContext.js +1 -67
- package/dist/esm/graphql/fragments/analytic.generated.js +2 -4
- package/dist/esm/graphql/fragments/collection-detail.generated.js +2 -4
- package/dist/esm/graphql/fragments/collection-product.generated.js +2 -4
- package/dist/esm/graphql/fragments/collection.generated.js +2 -4
- package/dist/esm/graphql/fragments/custom-code.generated.js +2 -4
- package/dist/esm/graphql/fragments/data-seo.generated.js +2 -4
- package/dist/esm/graphql/fragments/media.generated.js +3 -4
- package/dist/esm/graphql/fragments/product-little.generated.js +2 -4
- package/dist/esm/graphql/fragments/product-option-value.generated.js +2 -4
- package/dist/esm/graphql/fragments/product-option.generated.js +2 -4
- package/dist/esm/graphql/fragments/product.generated.js +2 -4
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +2 -4
- package/dist/esm/graphql/fragments/published-page-section.generated.js +2 -4
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +2 -4
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +2 -4
- package/dist/esm/graphql/fragments/selected-option.generated.js +2 -4
- package/dist/esm/graphql/fragments/variant.generated.js +2 -4
- package/dist/esm/graphql/mutations/page-view-up.generated.js +3 -5
- package/dist/esm/graphql/queries/collection-detail-filter.generated.js +10 -22
- package/dist/esm/graphql/queries/collection.generated.js +8 -18
- package/dist/esm/graphql/queries/collections.generated.js +3 -8
- package/dist/esm/graphql/queries/preview-page.generated.js +8 -18
- package/dist/esm/graphql/queries/product-little-detail.generated.js +5 -12
- package/dist/esm/graphql/queries/product-medias.generated.js +2 -6
- package/dist/esm/graphql/queries/product-value-label.generated.js +7 -0
- package/dist/esm/graphql/queries/product-variants.generated.js +4 -10
- package/dist/esm/graphql/queries/products.generated.js +9 -20
- package/dist/esm/graphql/queries/published-theme-pages.generated.js +8 -18
- package/dist/esm/graphql/queries/store-property.generated.js +2 -4
- package/dist/esm/helpers/GlobalEvent.js +1 -15
- package/dist/esm/helpers/background.js +1 -106
- package/dist/esm/helpers/borders.js +4 -175
- package/dist/esm/helpers/clone-deep.js +1 -3
- package/dist/esm/helpers/cls.js +1 -14
- package/dist/esm/helpers/colors.js +1 -168
- package/dist/esm/helpers/compose-advance-style.js +1 -185
- package/dist/esm/helpers/constant.js +1 -19
- package/dist/esm/helpers/convert.js +1 -4
- package/dist/esm/helpers/css-variable.js +1 -5
- package/dist/esm/helpers/email.js +1 -6
- package/dist/esm/helpers/flatten-connection.js +1 -7
- package/dist/esm/helpers/get-resonsive-value.js +1 -27
- package/dist/esm/helpers/get-shortname.js +1 -90
- package/dist/esm/helpers/is-browser.js +1 -5
- package/dist/esm/helpers/is-defined.js +1 -5
- package/dist/esm/helpers/is-empty-children.js +1 -7
- package/dist/esm/helpers/is-safari.js +1 -5
- package/dist/esm/helpers/layout.js +1 -54
- package/dist/esm/helpers/load-script.js +1 -29
- package/dist/esm/helpers/make-style.js +1 -117
- package/dist/esm/helpers/normalize-builder-data.js +1 -21
- package/dist/esm/helpers/prefetch-queries.js +1 -76
- package/dist/esm/helpers/product.js +1 -41
- package/dist/esm/helpers/queries/get-collection.js +1 -217
- package/dist/esm/helpers/queries/get-collections.js +1 -19
- package/dist/esm/helpers/queries/get-product-by-slug.js +1 -123
- package/dist/esm/helpers/queries/get-product.js +1 -150
- package/dist/esm/helpers/queries/get-products.js +1 -159
- package/dist/esm/helpers/query.js +1 -25
- package/dist/esm/helpers/radius.js +6 -127
- package/dist/esm/helpers/render.js +1 -64
- package/dist/esm/helpers/shadow.js +1 -51
- package/dist/esm/helpers/size.js +4 -31
- package/dist/esm/helpers/spacing.js +1 -40
- package/dist/esm/helpers/tracking/fpixel.js +1 -24
- package/dist/esm/helpers/tracking/gtag.js +1 -87
- package/dist/esm/helpers/tracking/tiktokpixel.js +1 -15
- package/dist/esm/helpers/typography.js +17 -96
- package/dist/esm/helpers/variant.js +1 -6
- package/dist/esm/hooks/cart/use-add-to-cart.js +1 -18
- package/dist/esm/hooks/cart/use-cart-data.js +1 -26
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +1 -18
- package/dist/esm/hooks/cart/use-cart-note-update.js +1 -18
- package/dist/esm/hooks/cart/use-create-cart.js +1 -20
- package/dist/esm/hooks/cart/use-remove-cart-item.js +1 -18
- package/dist/esm/hooks/cart/use-update-cart-item.js +1 -18
- package/dist/esm/hooks/shop/use-collection-query.js +1 -20
- package/dist/esm/hooks/shop/use-collections-query.js +1 -15
- package/dist/esm/hooks/shop/use-product-query.js +1 -20
- package/dist/esm/hooks/shop/use-products-query.js +1 -20
- package/dist/esm/hooks/shop.js +1 -111
- package/dist/esm/hooks/use-current-device.js +1 -19
- package/dist/esm/hooks/use-lazy-video.js +1 -13
- package/dist/esm/hooks/useCartId.js +1 -40
- package/dist/esm/hooks/useCartLine.js +1 -7
- package/dist/esm/hooks/useCartUI.js +1 -44
- package/dist/esm/hooks/useCollection.js +1 -7
- package/dist/esm/hooks/useFetchHandle.js +1 -11
- package/dist/esm/hooks/useFormatMoney.js +1 -56
- package/dist/esm/hooks/useInitialSwatchesOptions.js +1 -0
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -6
- package/dist/esm/hooks/useLoadScript.js +1 -28
- package/dist/esm/hooks/useMoney.js +1 -80
- package/dist/esm/hooks/usePrevious.js +1 -17
- package/dist/esm/hooks/useProduct.js +1 -111
- package/dist/esm/hooks/useProductList.js +1 -16
- package/dist/esm/hooks/useSuspenseFetch.js +1 -23
- package/dist/esm/hooks/useSwatchesOptions.js +1 -37
- package/dist/esm/index.js +1 -92
- package/dist/esm/types/global-style.js +1 -11
- package/dist/types/index.d.ts +1228 -1031
- package/package.json +3 -3
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var adapterShopify = require('@gem-sdk/adapter-shopify');
|
|
4
|
-
var useSWR = require('swr');
|
|
5
|
-
var useSWRMutation = require('swr/mutation');
|
|
6
|
-
var shop = require('../shop.js');
|
|
7
|
-
|
|
8
|
-
const useUpdateCartItem = (options)=>{
|
|
9
|
-
const shop$1 = shop.useStoreFront();
|
|
10
|
-
const { mutate } = useSWR.useSWRConfig();
|
|
11
|
-
return useSWRMutation('update-cart-item', (_, { arg })=>adapterShopify.updateCartLineOperation(shop$1)(arg), {
|
|
12
|
-
...options,
|
|
13
|
-
onSuccess: (result, key, config)=>{
|
|
14
|
-
mutate('cart', result, false);
|
|
15
|
-
options?.onSuccess?.(result, key, config);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
exports.useUpdateCartItem = useUpdateCartItem;
|
|
1
|
+
"use strict";var adapterShopify=require("@gem-sdk/adapter-shopify"),useSWR=require("swr"),useSWRMutation=require("swr/mutation"),shop=require("../shop.js");const useUpdateCartItem=e=>{let t=shop.useStoreFront(),{mutate:r}=useSWR.useSWRConfig();return useSWRMutation("update-cart-item",(e,{arg:r})=>adapterShopify.updateCartLineOperation(t)(r),{...e,onSuccess:(t,s,a)=>{r("cart",t,!1),e?.onSuccess?.(t,s,a)}})};exports.useUpdateCartItem=useUpdateCartItem;
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var useSWR = require('swr');
|
|
4
|
-
var getCollection = require('../../helpers/queries/get-collection.js');
|
|
5
|
-
var shop = require('../shop.js');
|
|
6
|
-
var useFetchHandle = require('../useFetchHandle.js');
|
|
7
|
-
var query = require('../../helpers/query.js');
|
|
8
|
-
|
|
9
|
-
const useCollectionQuery = (args, options)=>{
|
|
10
|
-
const fetcher = useFetchHandle.useFetchHandle();
|
|
11
|
-
const isSample = shop.useIsSampleProduct();
|
|
12
|
-
const isStorefront = shop.useIsStorefrontProduct();
|
|
13
|
-
return useSWR(args ? query.generateCollectionQueryKey({
|
|
14
|
-
...args,
|
|
15
|
-
isSample,
|
|
16
|
-
isStorefront
|
|
17
|
-
}) : null, ([, arg])=>{
|
|
18
|
-
return getCollection.getCollection(fetcher, arg);
|
|
19
|
-
}, options);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
exports.useCollectionQuery = useCollectionQuery;
|
|
1
|
+
"use strict";var useSWR=require("swr"),getCollection=require("../../helpers/queries/get-collection.js"),shop=require("../shop.js"),useFetchHandle=require("../useFetchHandle.js"),query=require("../../helpers/query.js");const useCollectionQuery=(e,r)=>{let s=useFetchHandle.useFetchHandle(),u=shop.useIsSampleProduct(),t=shop.useIsStorefrontProduct();return useSWR(e?query.generateCollectionQueryKey({...e,isSample:u,isStorefront:t}):null,([,e])=>getCollection.getCollection(s,e),r)};exports.useCollectionQuery=useCollectionQuery;
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var useSWR = require('swr');
|
|
4
|
-
var getCollections = require('../../helpers/queries/get-collections.js');
|
|
5
|
-
var useFetchHandle = require('../useFetchHandle.js');
|
|
6
|
-
|
|
7
|
-
const useCollectionsQuery = (variable, options)=>{
|
|
8
|
-
const fetcher = useFetchHandle.useFetchHandle();
|
|
9
|
-
return useSWR(variable ? [
|
|
10
|
-
'query/collections',
|
|
11
|
-
variable
|
|
12
|
-
] : null, async ([, arg])=>{
|
|
13
|
-
return getCollections.getCollections(fetcher, arg);
|
|
14
|
-
}, options);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
exports.useCollectionsQuery = useCollectionsQuery;
|
|
1
|
+
"use strict";var useSWR=require("swr"),getCollections=require("../../helpers/queries/get-collections.js"),useFetchHandle=require("../useFetchHandle.js");const useCollectionsQuery=(e,s)=>{let l=useFetchHandle.useFetchHandle();return useSWR(e?["query/collections",e]:null,async([,e])=>getCollections.getCollections(l,e),s)};exports.useCollectionsQuery=useCollectionsQuery;
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var useSWR = require('swr');
|
|
4
|
-
var getProduct = require('../../helpers/queries/get-product.js');
|
|
5
|
-
var shop = require('../shop.js');
|
|
6
|
-
var useFetchHandle = require('../useFetchHandle.js');
|
|
7
|
-
var query = require('../../helpers/query.js');
|
|
8
|
-
|
|
9
|
-
const useProductQuery = (productId, options)=>{
|
|
10
|
-
const fetcher = useFetchHandle.useFetchHandle();
|
|
11
|
-
const isSample = shop.useIsSampleProduct();
|
|
12
|
-
const isStorefront = shop.useIsStorefrontProduct();
|
|
13
|
-
return useSWR(productId ? query.generateProductQueryKey({
|
|
14
|
-
id: productId,
|
|
15
|
-
isSample,
|
|
16
|
-
isStorefront
|
|
17
|
-
}) : null, async ([, arg])=>{
|
|
18
|
-
return getProduct.getProduct(fetcher, arg);
|
|
19
|
-
}, options);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
exports.useProductQuery = useProductQuery;
|
|
1
|
+
"use strict";var useSWR=require("swr"),getProduct=require("../../helpers/queries/get-product.js"),shop=require("../shop.js"),useFetchHandle=require("../useFetchHandle.js"),query=require("../../helpers/query.js");const useProductQuery=(e,r)=>{let u=useFetchHandle.useFetchHandle(),s=shop.useIsSampleProduct(),t=shop.useIsStorefrontProduct();return useSWR(e?query.generateProductQueryKey({id:e,isSample:s,isStorefront:t}):null,async([,e])=>getProduct.getProduct(u,e),r)};exports.useProductQuery=useProductQuery;
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var useSWR = require('swr');
|
|
4
|
-
var getProducts = require('../../helpers/queries/get-products.js');
|
|
5
|
-
var query = require('../../helpers/query.js');
|
|
6
|
-
var shop = require('../shop.js');
|
|
7
|
-
var useFetchHandle = require('../useFetchHandle.js');
|
|
8
|
-
|
|
9
|
-
const useProductsQuery = (ids, options)=>{
|
|
10
|
-
const fetcher = useFetchHandle.useFetchHandle();
|
|
11
|
-
const isSample = shop.useIsSampleProduct();
|
|
12
|
-
const isStorefront = shop.useIsStorefrontProduct();
|
|
13
|
-
return useSWR(ids ? query.generateProductsQueryKey({
|
|
14
|
-
ids,
|
|
15
|
-
isSample,
|
|
16
|
-
isStorefront
|
|
17
|
-
}) : null, async ([, arg])=>{
|
|
18
|
-
return getProducts.getProducts(fetcher, arg);
|
|
19
|
-
}, options);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
exports.useProductsQuery = useProductsQuery;
|
|
1
|
+
"use strict";var useSWR=require("swr"),getProducts=require("../../helpers/queries/get-products.js"),query=require("../../helpers/query.js"),shop=require("../shop.js"),useFetchHandle=require("../useFetchHandle.js");const useProductsQuery=(e,r,s)=>{let u=useFetchHandle.useFetchHandle(),t=shop.useIsSampleProduct(),o=shop.useIsStorefrontProduct();return useSWR(e?query.generateProductsQueryKey({ids:e,isSample:t,isStorefront:o,defaultSelectedProductCount:s}):null,async([,e])=>getProducts.getProducts(u,e),r)};exports.useProductsQuery=useProductsQuery;
|
package/dist/cjs/hooks/shop.js
CHANGED
|
@@ -1,126 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
var useSWR = require('swr');
|
|
5
|
-
var ShopContext = require('../contexts/ShopContext.js');
|
|
6
|
-
|
|
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 useMoneyFormat = ()=>{
|
|
30
|
-
const moneyFormat = ShopContext.useShopStore((state)=>state.moneyFormat);
|
|
31
|
-
const moneyWithCurrencyFormat = ShopContext.useShopStore((state)=>state.moneyWithCurrencyFormat);
|
|
32
|
-
return react.useMemo(()=>({
|
|
33
|
-
moneyFormat,
|
|
34
|
-
moneyWithCurrencyFormat
|
|
35
|
-
}), [
|
|
36
|
-
moneyFormat,
|
|
37
|
-
moneyWithCurrencyFormat
|
|
38
|
-
]);
|
|
39
|
-
};
|
|
40
|
-
const useSwatches = ()=>{
|
|
41
|
-
const swatches = ShopContext.useShopStore((state)=>state.swatches);
|
|
42
|
-
const changeSwatches = ShopContext.useShopStore((state)=>state.changeSwatches);
|
|
43
|
-
return react.useMemo(()=>({
|
|
44
|
-
swatches,
|
|
45
|
-
changeSwatches
|
|
46
|
-
}), [
|
|
47
|
-
swatches,
|
|
48
|
-
changeSwatches
|
|
49
|
-
]);
|
|
50
|
-
};
|
|
51
|
-
const usePageType = ()=>{
|
|
52
|
-
const pageType = ShopContext.useShopStore((state)=>state.pageType);
|
|
53
|
-
return react.useMemo(()=>pageType || 'STATIC', [
|
|
54
|
-
pageType
|
|
55
|
-
]);
|
|
56
|
-
};
|
|
57
|
-
const useStoreFront = ()=>{
|
|
58
|
-
const provider = ShopContext.useShopStore((state)=>state.provider);
|
|
59
|
-
const storefrontToken = ShopContext.useShopStore((state)=>state.storefrontToken);
|
|
60
|
-
const storefrontUrl = ShopContext.useShopStore((state)=>state.storefrontUrl);
|
|
61
|
-
return {
|
|
62
|
-
provider,
|
|
63
|
-
storefrontToken,
|
|
64
|
-
storefrontUrl
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
const usePluginEnable = ()=>{
|
|
68
|
-
return ShopContext.useShopStore((state)=>state.plugins);
|
|
69
|
-
};
|
|
70
|
-
const useEditorMode = ()=>{
|
|
71
|
-
return ShopContext.useShopStore((state)=>state.mode);
|
|
72
|
-
};
|
|
73
|
-
const useMobileOnly = ()=>{
|
|
74
|
-
return ShopContext.useShopStore((state)=>state.mobileOnly);
|
|
75
|
-
};
|
|
76
|
-
const useMatchMutate = ()=>{
|
|
77
|
-
const { cache, mutate } = useSWR.useSWRConfig();
|
|
78
|
-
return (matcher, opts)=>{
|
|
79
|
-
if (!(cache instanceof Map)) {
|
|
80
|
-
throw new Error('matchMutate requires the cache provider to be a Map instance');
|
|
81
|
-
}
|
|
82
|
-
const keys = [];
|
|
83
|
-
cache.forEach((_, key)=>{
|
|
84
|
-
if (matcher.test(key)) {
|
|
85
|
-
keys.push(key);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
const mutations = keys.map((key)=>{
|
|
89
|
-
const cacheData = cache.get(key);
|
|
90
|
-
return mutate(key, cacheData?.data, opts);
|
|
91
|
-
});
|
|
92
|
-
return Promise.all(mutations);
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
function useConnectedShopify() {
|
|
96
|
-
const { storefrontToken } = useStoreFront();
|
|
97
|
-
return !!storefrontToken;
|
|
98
|
-
}
|
|
99
|
-
function useIsSampleProduct() {
|
|
100
|
-
const { storefrontToken } = useStoreFront();
|
|
101
|
-
const isStorefront = ShopContext.useShopStore((state)=>state.isStorefront);
|
|
102
|
-
return isStorefront && !storefrontToken;
|
|
103
|
-
}
|
|
104
|
-
function useIsStorefrontProduct() {
|
|
105
|
-
return ShopContext.useShopStore((state)=>state.isStorefront);
|
|
106
|
-
}
|
|
107
|
-
function useCheckoutUrl(url) {
|
|
108
|
-
const { storefrontToken } = useStoreFront();
|
|
109
|
-
if (!url) return undefined;
|
|
110
|
-
return storefrontToken ? `${url}?access_token=${storefrontToken}` : url;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
exports.useCheckoutUrl = useCheckoutUrl;
|
|
114
|
-
exports.useConnectedShopify = useConnectedShopify;
|
|
115
|
-
exports.useCurrency = useCurrency;
|
|
116
|
-
exports.useEditorMode = useEditorMode;
|
|
117
|
-
exports.useIsSampleProduct = useIsSampleProduct;
|
|
118
|
-
exports.useIsStorefrontProduct = useIsStorefrontProduct;
|
|
119
|
-
exports.useLocale = useLocale;
|
|
120
|
-
exports.useMatchMutate = useMatchMutate;
|
|
121
|
-
exports.useMobileOnly = useMobileOnly;
|
|
122
|
-
exports.useMoneyFormat = useMoneyFormat;
|
|
123
|
-
exports.usePageType = usePageType;
|
|
124
|
-
exports.usePluginEnable = usePluginEnable;
|
|
125
|
-
exports.useStoreFront = useStoreFront;
|
|
126
|
-
exports.useSwatches = useSwatches;
|
|
1
|
+
"use strict";var react=require("react"),useSWR=require("swr"),ShopContext=require("../contexts/ShopContext.js");const useLocale=()=>{let e=ShopContext.useShopStore(e=>e.locale),t=ShopContext.useShopStore(e=>e.changeLocale);return react.useMemo(()=>({locale:e,changeLocale:t}),[e,t])},useCurrency=()=>{let e=ShopContext.useShopStore(e=>e.currency),t=ShopContext.useShopStore(e=>e.changeCurrency);return react.useMemo(()=>({currency:e,changeCurrency:t}),[e,t])},useMoneyFormat=()=>{let e=ShopContext.useShopStore(e=>e.moneyFormat),t=ShopContext.useShopStore(e=>e.moneyWithCurrencyFormat);return react.useMemo(()=>({moneyFormat:e,moneyWithCurrencyFormat:t}),[e,t])},useSwatches=()=>{let e=ShopContext.useShopStore(e=>e.swatches),t=ShopContext.useShopStore(e=>e.changeSwatches);return react.useMemo(()=>({swatches:e,changeSwatches:t}),[e,t])},usePageType=()=>{let e=ShopContext.useShopStore(e=>e.pageType);return react.useMemo(()=>e||"STATIC",[e])},useStoreFront=()=>{let e=ShopContext.useShopStore(e=>e.provider),t=ShopContext.useShopStore(e=>e.storefrontToken),o=ShopContext.useShopStore(e=>e.storefrontUrl);return{provider:e,storefrontToken:t,storefrontUrl:o}},usePluginEnable=()=>ShopContext.useShopStore(e=>e.plugins),useEditorMode=()=>ShopContext.useShopStore(e=>e.mode),useMobileOnly=()=>ShopContext.useShopStore(e=>e.mobileOnly),useMatchMutate=()=>{let{cache:e,mutate:t}=useSWR.useSWRConfig();return(o,r)=>{if(!(e instanceof Map))throw Error("matchMutate requires the cache provider to be a Map instance");let u=[];e.forEach((e,t)=>{o.test(t)&&u.push(t)});let s=u.map(o=>{let u=e.get(o);return t(o,u?.data,r)});return Promise.all(s)}};function useConnectedShopify(){let{storefrontToken:e}=useStoreFront();return!!e}function useIsSampleProduct(){let{storefrontToken:e}=useStoreFront(),t=ShopContext.useShopStore(e=>e.isStorefront);return t&&!e}function useIsStorefrontProduct(){return ShopContext.useShopStore(e=>e.isStorefront)}function useCheckoutUrl(e){let{storefrontToken:t}=useStoreFront();if(e)return t?`${e}?access_token=${t}`:e}exports.useCheckoutUrl=useCheckoutUrl,exports.useConnectedShopify=useConnectedShopify,exports.useCurrency=useCurrency,exports.useEditorMode=useEditorMode,exports.useIsSampleProduct=useIsSampleProduct,exports.useIsStorefrontProduct=useIsStorefrontProduct,exports.useLocale=useLocale,exports.useMatchMutate=useMatchMutate,exports.useMobileOnly=useMobileOnly,exports.useMoneyFormat=useMoneyFormat,exports.usePageType=usePageType,exports.usePluginEnable=usePluginEnable,exports.useStoreFront=useStoreFront,exports.useSwatches=useSwatches;
|
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
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');
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
exports.useCurrentDevice = useCurrentDevice;
|
|
1
|
+
"use strict";var react=require("react");function subscribe(e){return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)}const useCurrentDevice=()=>react.useSyncExternalStore(subscribe,()=>window.innerWidth<768?"mobile":window.innerWidth>=768&&window.innerWidth<1024?"tablet":"desktop",()=>"desktop");exports.useCurrentDevice=useCurrentDevice;
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
var LazyLoad = require('vanilla-lazyload');
|
|
5
|
-
|
|
6
|
-
const useLazyVideo = ()=>{
|
|
7
|
-
react.useEffect(()=>{
|
|
8
|
-
const lazyLoadInstance = new LazyLoad({
|
|
9
|
-
use_native: true
|
|
10
|
-
});
|
|
11
|
-
lazyLoadInstance.update();
|
|
12
|
-
}, []);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.useLazyVideo = useLazyVideo;
|
|
1
|
+
"use strict";var react=require("react"),LazyLoad=require("vanilla-lazyload");const useLazyVideo=()=>{react.useEffect(()=>{let e=new LazyLoad({use_native:!0});e.update()},[])};exports.useLazyVideo=useLazyVideo;
|
|
@@ -1,44 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var react = require('react');
|
|
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, ()=>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
|
-
]);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
exports.default = useCartId;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");const cartKey="cart-id",getCartId=()=>window.localStorage.getItem(cartKey),writeCartId=e=>{e&&window.localStorage.setItem(cartKey,e)},removeCartId=()=>{window.localStorage.removeItem(cartKey)},subscribeStorage=e=>(window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}),useCartId=()=>{let e=react.useSyncExternalStore(subscribeStorage,getCartId,()=>void 0),t=react.useCallback(e=>{writeCartId(e)},[]),r=react.useCallback(()=>{removeCartId()},[]);return react.useMemo(()=>({cartId:e,updateCartId:t,clearCartId:r}),[e,r,t])};exports.default=useCartId;
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var CartLineContext = require('../contexts/CartLineContext.js');
|
|
6
|
-
|
|
7
|
-
const useCartLine = ()=>{
|
|
8
|
-
return CartLineContext.useCartLineStore((s)=>s.line);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
exports.default = useCartLine;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var CartLineContext=require("../contexts/CartLineContext.js");const useCartLine=()=>CartLineContext.useCartLineStore(e=>e.line);exports.default=useCartLine;
|
|
@@ -1,48 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var react = require('react');
|
|
6
|
-
var zustand = require('zustand');
|
|
7
|
-
var shop = require('./shop.js');
|
|
8
|
-
|
|
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
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
exports.default = useCartUI;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react"),zustand=require("zustand"),shop=require("./shop.js");const useStore=zustand.create(e=>({isCartOpen:!1,setOpen:t=>{let r=window.innerWidth-document.documentElement.clientWidth,d=parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"),10);t?(document.body.style.overflow="hidden",document.body.style.paddingRight=`${d+r}px`):(document.body.style.overflow="",document.body.style.paddingRight=""),e({isCartOpen:t})}}));function useCartUI(){let e=shop.usePluginEnable(),t=useStore(e=>e.isCartOpen),r=useStore(e=>e.setOpen),d=react.useCallback(()=>{e?.includes("cart-drawer")&&r(!0)},[e,r]),n=react.useCallback(()=>r(!1),[r]);return{isCartOpen:t,openCart:d,closeCart:n}}exports.default=useCartUI;
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var CollectionContext = require('../contexts/CollectionContext.js');
|
|
4
|
-
|
|
5
|
-
const useCollection = ()=>{
|
|
6
|
-
return CollectionContext.useCollectionStore((s)=>s.collection);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
exports.useCollection = useCollection;
|
|
1
|
+
"use strict";var CollectionContext=require("../contexts/CollectionContext.js");const useCollection=()=>CollectionContext.useCollectionStore(o=>o.collection);exports.useCollection=useCollection;
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var useSWR = require('swr');
|
|
4
|
-
|
|
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
|
-
};
|
|
12
|
-
|
|
13
|
-
exports.useFetchHandle = useFetchHandle;
|
|
1
|
+
"use strict";var useSWR=require("swr");const useFetchHandle=()=>{let{fetcher:e}=useSWR.useSWRConfig();if(!e)throw Error("Application must be init within a fetcher");return e};exports.useFetchHandle=useFetchHandle;
|
|
@@ -1,58 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var shop = require('./shop.js');
|
|
4
|
-
|
|
5
|
-
const useFormatMoney = (amount, withCurrency)=>{
|
|
6
|
-
const { moneyFormat, moneyWithCurrencyFormat } = shop.useMoneyFormat();
|
|
7
|
-
const formatMoney = function(cents, format) {
|
|
8
|
-
let value = '';
|
|
9
|
-
const placeholderRegex = /\{\{\s*(\w+)\s*\}\}/;
|
|
10
|
-
const formatString = format || '${{amount}}';
|
|
11
|
-
/**
|
|
12
|
-
* check default
|
|
13
|
-
* @param opt opt
|
|
14
|
-
* @param def def
|
|
15
|
-
* @returns any
|
|
16
|
-
*/ function defaultOption(opt, def) {
|
|
17
|
-
return typeof opt == 'undefined' ? def : opt;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* formatWithDelimiters
|
|
21
|
-
* @param number number
|
|
22
|
-
* @param precision precision
|
|
23
|
-
* @param thousands thousands
|
|
24
|
-
* @param decimal decimal
|
|
25
|
-
* @returns any
|
|
26
|
-
*/ // eslint-disable-next-line max-params
|
|
27
|
-
function formatWithDelimiters(number, precision, thousands, decimal) {
|
|
28
|
-
precision = defaultOption(precision, 2);
|
|
29
|
-
thousands = defaultOption(thousands, ',');
|
|
30
|
-
decimal = defaultOption(decimal, '.');
|
|
31
|
-
if (isNaN(number) || number == null) {
|
|
32
|
-
return 0;
|
|
33
|
-
}
|
|
34
|
-
// shopify làm tròn bằng cách cắt đi các số ở đằng sau chứ không sử dụng toFixed để làm tròn như toán học
|
|
35
|
-
number = parseFloat(`${number}`).toFixed(Number(precision) + 1).slice(0, -1);
|
|
36
|
-
const parts = number.split('.'), dollars = parts[0]?.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1' + thousands), cents = parts[1] ? decimal + parts[1] : '';
|
|
37
|
-
return dollars + cents;
|
|
38
|
-
}
|
|
39
|
-
switch(formatString.match(placeholderRegex)[1]){
|
|
40
|
-
case 'amount':
|
|
41
|
-
value = formatWithDelimiters(cents, 2);
|
|
42
|
-
break;
|
|
43
|
-
case 'amount_no_decimals':
|
|
44
|
-
value = formatWithDelimiters(cents, 0);
|
|
45
|
-
break;
|
|
46
|
-
case 'amount_with_comma_separator':
|
|
47
|
-
value = formatWithDelimiters(cents, 2, '.', ',');
|
|
48
|
-
break;
|
|
49
|
-
case 'amount_no_decimals_with_comma_separator':
|
|
50
|
-
value = formatWithDelimiters(cents, 0, '.', ',');
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
return formatString.replace(placeholderRegex, value);
|
|
54
|
-
};
|
|
55
|
-
return withCurrency ? formatMoney(`${amount}`, moneyWithCurrencyFormat || moneyFormat) : formatMoney(`${amount}`, moneyFormat);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
exports.useFormatMoney = useFormatMoney;
|
|
1
|
+
"use strict";var shop=require("./shop.js");const useFormatMoney=(e,t)=>{let{moneyFormat:a,moneyWithCurrencyFormat:o}=shop.useMoneyFormat(),r=function(e,t){let a="",o=/\{\{\s*(\w+)\s*\}\}/,r=t||"${{amount}}";function s(e,t){return void 0===e?t:e}function n(e,t,a,o){if(t=s(t,2),a=s(a,","),o=s(o,"."),isNaN(e)||null==e)return 0;e=parseFloat(`${e}`).toFixed(Number(t)+1).slice(0,-1);let r=e.split("."),n=r[0]?.replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+a),u=r[1]?o+r[1]:"";return n+u}switch(r.match(o)[1]){case"amount":a=n(e,2);break;case"amount_no_decimals":a=n(e,0);break;case"amount_with_comma_separator":a=n(e,2,".",",");break;case"amount_no_decimals_with_comma_separator":a=n(e,0,".",",")}return r.replace(o,a)};return r(`${e}`,t&&o||a)};exports.useFormatMoney=useFormatMoney;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var useSWR=require("swr"),productValueLabel_generated=require("../graphql/queries/product-value-label.generated.js"),variantPresets=require("../components/src/product/helpers/variant-presets.js"),shop=require("./shop.js"),useFetchHandle=require("./useFetchHandle.js"),ShopContext=require("../contexts/ShopContext.js");let swatchChange=!1,colorChange=!1;const useInitialSwatchesOptions=e=>{let t=useFetchHandle.useFetchHandle(),a=ShopContext.useShopStore(e=>e.changeSwatches),{swatches:o}=shop.useSwatches(),{data:s}=useSWR(["/query/productOptionName",{}],async()=>fetchProductValueLabel(t),{revalidateOnMount:!0}),r=[];if(o?.forEach(e=>{r.push(e.optionTitle)}),s?.productOptionName?.forEach(e=>{r.includes(e)||(swatchChange=!0,o?.push({optionTitle:e,optionType:"rectangle_list",optionValues:[]}))}),!e)return[];setDefaultSwatches(o,e),o?.length&&(swatchChange||colorChange)&&(window?.parent?.postMessage?.(JSON.stringify({type:"update-swatches",swatches:o}),"*"),a(o))},getColorDefault=(e,t)=>{let a=e?variantPresets.colorPreset[e.toLocaleLowerCase()]:void 0,o=a?[a]:[],s=t?.[0];return!s&&o.length&&(colorChange=!0),s?[s]:o},getProductOptionsLabelByName=(e,t)=>{let a=[],o=e.find(e=>e.name===t);return o?.values.forEach(e=>{a.push(e.label??"")}),a},getSwatchesOptionsLabel=e=>{let t=[];return e.forEach(e=>{t.push(e.label??"")}),t},setDefaultSwatches=(e,t)=>(e&&e?.map(e=>{let a=getProductOptionsLabelByName(t,e.optionTitle),o=getSwatchesOptionsLabel(e.optionValues);a.forEach(t=>{o.includes(t)||e.optionValues.push({label:t,colors:getColorDefault(t),imageUrl:""})}),e.optionValues.map(e=>({...e,colors:getColorDefault(e.label,e.colors)}))}),e),fetchProductValueLabel=async e=>{let t={},a=async t=>{let a=await e([productValueLabel_generated.ProductOptionNameDocument,t]);return a};return a(t)};exports.default=useInitialSwatchesOptions;
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var react = require('react');
|
|
6
|
-
|
|
7
|
-
// const isBrowser = typeof window !== 'undefined';
|
|
8
|
-
const useIsomorphicLayoutEffect = react.useLayoutEffect;
|
|
9
|
-
|
|
10
|
-
exports.default = useIsomorphicLayoutEffect;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react");const useIsomorphicLayoutEffect=react.useLayoutEffect;exports.default=useIsomorphicLayoutEffect;
|
|
@@ -1,32 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var react = require('react');
|
|
6
|
-
var loadScript = require('../helpers/load-script.js');
|
|
7
|
-
|
|
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;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
exports.default = useLoadScript;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react"),loadScript=require("../helpers/load-script.js");function useLoadScript(e,r){let[t,a]=react.useState("loading"),c=JSON.stringify(r);return react.useEffect(()=>{(async function(){try{a("loading"),await loadScript.loadScript(e,r),a("done")}catch(e){a("error")}})()},[e,c,r]),t}exports.default=useLoadScript;
|
|
@@ -1,84 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var react = require('react');
|
|
6
|
-
var shop = require('./shop.js');
|
|
7
|
-
|
|
8
|
-
const useMoney = (amount)=>{
|
|
9
|
-
const { locale } = shop.useLocale();
|
|
10
|
-
const { currency } = shop.useCurrency();
|
|
11
|
-
const options = react.useMemo(()=>({
|
|
12
|
-
style: 'currency',
|
|
13
|
-
currency: currency
|
|
14
|
-
}), [
|
|
15
|
-
currency
|
|
16
|
-
]);
|
|
17
|
-
const defaultFormatter = useLazyFormatter(locale, options);
|
|
18
|
-
const nameFormatter = useLazyFormatter(locale, {
|
|
19
|
-
...options,
|
|
20
|
-
currencyDisplay: 'name'
|
|
21
|
-
});
|
|
22
|
-
const narrowSymbolFormatter = useLazyFormatter(locale, {
|
|
23
|
-
...options,
|
|
24
|
-
currencyDisplay: 'narrowSymbol'
|
|
25
|
-
});
|
|
26
|
-
const withoutTrailingZerosFormatter = useLazyFormatter(locale, {
|
|
27
|
-
...options,
|
|
28
|
-
minimumFractionDigits: 0,
|
|
29
|
-
maximumFractionDigits: 0
|
|
30
|
-
});
|
|
31
|
-
const withoutCurrencyFormatter = useLazyFormatter(locale);
|
|
32
|
-
const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {
|
|
33
|
-
minimumFractionDigits: 0,
|
|
34
|
-
maximumFractionDigits: 0
|
|
35
|
-
});
|
|
36
|
-
const isPartCurrency = (part)=>part.type === 'currency';
|
|
37
|
-
// By wrapping these properties in functions, we only
|
|
38
|
-
// create formatters if they are going to be used.
|
|
39
|
-
const lazyFormatters = react.useMemo(()=>({
|
|
40
|
-
currencyCode: ()=>currency,
|
|
41
|
-
localizedString: ()=>defaultFormatter().format(amount),
|
|
42
|
-
parts: ()=>defaultFormatter().formatToParts(amount),
|
|
43
|
-
withoutTrailingZeros: ()=>amount % 1 === 0 ? withoutTrailingZerosFormatter().format(amount) : defaultFormatter().format(amount),
|
|
44
|
-
withoutTrailingZerosAndCurrency: ()=>amount % 1 === 0 ? withoutTrailingZerosOrCurrencyFormatter().format(amount) : withoutCurrencyFormatter().format(amount),
|
|
45
|
-
currencyName: ()=>nameFormatter().formatToParts(amount).find(isPartCurrency)?.value ?? currency,
|
|
46
|
-
currencySymbol: ()=>defaultFormatter().formatToParts(amount).find(isPartCurrency)?.value ?? currency,
|
|
47
|
-
currencyNarrowSymbol: ()=>narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)?.value ?? '',
|
|
48
|
-
amount: ()=>defaultFormatter().formatToParts(amount).filter((part)=>[
|
|
49
|
-
'decimal',
|
|
50
|
-
'fraction',
|
|
51
|
-
'group',
|
|
52
|
-
'integer',
|
|
53
|
-
'literal'
|
|
54
|
-
].includes(part.type)).map((part)=>part.value).join('')
|
|
55
|
-
}), [
|
|
56
|
-
currency,
|
|
57
|
-
amount,
|
|
58
|
-
nameFormatter,
|
|
59
|
-
defaultFormatter,
|
|
60
|
-
narrowSymbolFormatter,
|
|
61
|
-
withoutCurrencyFormatter,
|
|
62
|
-
withoutTrailingZerosFormatter,
|
|
63
|
-
withoutTrailingZerosOrCurrencyFormatter
|
|
64
|
-
]);
|
|
65
|
-
// Call functions automatically when the properties are accessed
|
|
66
|
-
// to keep these functions as an implementation detail.
|
|
67
|
-
return react.useMemo(()=>new Proxy(lazyFormatters, {
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
69
|
-
get: (target, key)=>Reflect.get(target, key)?.call(null)
|
|
70
|
-
}), [
|
|
71
|
-
lazyFormatters
|
|
72
|
-
]);
|
|
73
|
-
};
|
|
74
|
-
function useLazyFormatter(locale, options) {
|
|
75
|
-
return react.useMemo(()=>{
|
|
76
|
-
let memoized;
|
|
77
|
-
return ()=>memoized ??= new Intl.NumberFormat(locale, options);
|
|
78
|
-
}, [
|
|
79
|
-
locale,
|
|
80
|
-
options
|
|
81
|
-
]);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
exports.default = useMoney;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react"),shop=require("./shop.js");const useMoney=r=>{let{locale:e}=shop.useLocale(),{currency:t}=shop.useCurrency(),a=react.useMemo(()=>({style:"currency",currency:t}),[t]),o=useLazyFormatter(e,a),u=useLazyFormatter(e,{...a,currencyDisplay:"name"}),n=useLazyFormatter(e,{...a,currencyDisplay:"narrowSymbol"}),i=useLazyFormatter(e,{...a,minimumFractionDigits:0,maximumFractionDigits:0}),m=useLazyFormatter(e),s=useLazyFormatter(e,{minimumFractionDigits:0,maximumFractionDigits:0}),c=r=>"currency"===r.type,l=react.useMemo(()=>({currencyCode:()=>t,localizedString:()=>o().format(r),parts:()=>o().formatToParts(r),withoutTrailingZeros:()=>r%1==0?i().format(r):o().format(r),withoutTrailingZerosAndCurrency:()=>r%1==0?s().format(r):m().format(r),currencyName:()=>u().formatToParts(r).find(c)?.value??t,currencySymbol:()=>o().formatToParts(r).find(c)?.value??t,currencyNarrowSymbol:()=>n().formatToParts(r).find(c)?.value??"",amount:()=>o().formatToParts(r).filter(r=>["decimal","fraction","group","integer","literal"].includes(r.type)).map(r=>r.value).join("")}),[t,r,u,o,n,m,i,s]);return react.useMemo(()=>new Proxy(l,{get:(r,e)=>Reflect.get(r,e)?.call(null)}),[l])};function useLazyFormatter(r,e){return react.useMemo(()=>{let t;return()=>t??=new Intl.NumberFormat(r,e)},[r,e])}exports.default=useMoney;
|
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
5
|
-
const usePrevious = (value)=>{
|
|
6
|
-
// The ref object is a generic container whose current property is mutable ...
|
|
7
|
-
// ... and can hold any value, similar to an instance property on a class
|
|
8
|
-
const ref = react.useRef();
|
|
9
|
-
// Store current value in ref
|
|
10
|
-
react.useEffect(()=>{
|
|
11
|
-
ref.current = value;
|
|
12
|
-
}, [
|
|
13
|
-
value
|
|
14
|
-
]); // Only re-run if value changes
|
|
15
|
-
// Return previous value (happens before update in useEffect above)
|
|
16
|
-
return ref.current;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
exports.usePrevious = usePrevious;
|
|
1
|
+
"use strict";var react=require("react");const usePrevious=e=>{let r=react.useRef();return react.useEffect(()=>{r.current=e},[e]),r.current};exports.usePrevious=usePrevious;
|