@gem-sdk/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/AddOn.js +18 -0
- package/dist/cjs/components/ComponentWrapper.js +45 -0
- package/dist/cjs/components/ComponentWrapperPreview.js +58 -0
- package/dist/cjs/components/Empty.js +7 -0
- package/dist/cjs/components/Render.js +28 -0
- package/dist/cjs/components/RenderBlock.js +21 -0
- package/dist/cjs/components/RenderPreview.js +28 -0
- package/dist/cjs/components/RenderSection.js +19 -0
- package/dist/cjs/contexts/AddonContext.js +25 -0
- package/dist/cjs/contexts/BuilderComponent.js +30 -0
- package/dist/cjs/contexts/BuilderContext.js +29 -0
- package/dist/cjs/contexts/BuilderPreviewContext.js +353 -0
- package/dist/cjs/contexts/CartLineContext.js +24 -0
- package/dist/cjs/contexts/CollectionContext.js +24 -0
- package/dist/cjs/contexts/ProductContext.js +126 -0
- package/dist/cjs/contexts/ProductListContext.js +24 -0
- package/dist/cjs/contexts/SectionContext.js +49 -0
- package/dist/cjs/contexts/ShopContext.js +43 -0
- package/dist/cjs/graphql/fragments/analytic.generated.js +11 -0
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +13 -0
- package/dist/cjs/graphql/fragments/collection-product.generated.js +26 -0
- package/dist/cjs/graphql/fragments/data-seo.generated.js +11 -0
- package/dist/cjs/graphql/fragments/media.generated.js +14 -0
- package/dist/cjs/graphql/fragments/product-little.generated.js +25 -0
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +13 -0
- package/dist/cjs/graphql/fragments/product-option.generated.js +14 -0
- package/dist/cjs/graphql/fragments/product.generated.js +33 -0
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +12 -0
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +11 -0
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +27 -0
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +11 -0
- package/dist/cjs/graphql/fragments/selected-option.generated.js +11 -0
- package/dist/cjs/graphql/fragments/variant.generated.js +35 -0
- package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +34 -0
- package/dist/cjs/graphql/queries/collection.generated.js +52 -0
- package/dist/cjs/graphql/queries/preview-page.generated.js +23 -0
- package/dist/cjs/graphql/queries/product-little-detail.generated.js +24 -0
- package/dist/cjs/graphql/queries/product-medias.generated.js +29 -0
- package/dist/cjs/graphql/queries/product-variants.generated.js +33 -0
- package/dist/cjs/graphql/queries/products.generated.js +41 -0
- package/dist/cjs/graphql/queries/published-theme-pages.generated.js +23 -0
- package/dist/cjs/graphql/queries/storeProperty.generated.js +12 -0
- package/dist/cjs/helpers/GlobalEvent.js +17 -0
- package/dist/cjs/helpers/background.js +104 -0
- package/dist/cjs/helpers/borders.js +138 -0
- package/dist/cjs/helpers/clone-deep.js +5 -0
- package/dist/cjs/helpers/cls.js +20 -0
- package/dist/cjs/helpers/colors.js +157 -0
- package/dist/cjs/helpers/compose-advance-style.js +132 -0
- package/dist/cjs/helpers/constant.js +17 -0
- package/dist/cjs/helpers/css-variable.js +7 -0
- package/dist/cjs/helpers/email.js +11 -0
- package/dist/cjs/helpers/flatten-connection.js +10 -0
- package/dist/cjs/helpers/fpixel.js +29 -0
- package/dist/cjs/helpers/get-resonsive-value.js +32 -0
- package/dist/cjs/helpers/get-shortname.js +92 -0
- package/dist/cjs/helpers/gtag.js +48 -0
- package/dist/cjs/helpers/is-browser.js +9 -0
- package/dist/cjs/helpers/is-defined.js +7 -0
- package/dist/cjs/helpers/is-empty-children.js +12 -0
- package/dist/cjs/helpers/layout.js +17 -0
- package/dist/cjs/helpers/load-script.js +32 -0
- package/dist/cjs/helpers/make-style.js +99 -0
- package/dist/cjs/helpers/normalize-builder-data.js +17 -0
- package/dist/cjs/helpers/prefetch-queries.js +68 -0
- package/dist/cjs/helpers/product.js +35 -0
- package/dist/cjs/helpers/queries/get-collection.js +173 -0
- package/dist/cjs/helpers/queries/get-product-by-slug.js +99 -0
- package/dist/cjs/helpers/queries/get-product.js +113 -0
- package/dist/cjs/helpers/queries/get-products.js +135 -0
- package/dist/cjs/helpers/radius.js +91 -0
- package/dist/cjs/helpers/shadow.js +48 -0
- package/dist/cjs/helpers/size.js +20 -0
- package/dist/cjs/helpers/spacing.js +45 -0
- package/dist/cjs/helpers/tiktokpixel.js +17 -0
- package/dist/cjs/helpers/typography.js +7 -0
- package/dist/cjs/hooks/cart/use-add-to-cart.js +20 -0
- package/dist/cjs/hooks/cart/use-cart-data.js +26 -0
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +20 -0
- package/dist/cjs/hooks/cart/use-cart-note-update.js +20 -0
- package/dist/cjs/hooks/cart/use-create-cart.js +22 -0
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +20 -0
- package/dist/cjs/hooks/cart/use-update-cart-item.js +20 -0
- package/dist/cjs/hooks/shop/use-collection-query.js +16 -0
- package/dist/cjs/hooks/shop/use-product-query.js +16 -0
- package/dist/cjs/hooks/shop/use-products-query.js +16 -0
- package/dist/cjs/hooks/shop.js +80 -0
- package/dist/cjs/hooks/use-current-device.js +23 -0
- package/dist/cjs/hooks/use-lazy-video.js +15 -0
- package/dist/cjs/hooks/useCartId.js +36 -0
- package/dist/cjs/hooks/useCartLine.js +11 -0
- package/dist/cjs/hooks/useCartUI.js +42 -0
- package/dist/cjs/hooks/useCollection.js +9 -0
- package/dist/cjs/hooks/useFetchHandle.js +13 -0
- package/dist/cjs/hooks/useFormatMoney.js +17 -0
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +10 -0
- package/dist/cjs/hooks/useLoadScript.js +30 -0
- package/dist/cjs/hooks/useMoney.js +52 -0
- package/dist/cjs/hooks/usePrevious.js +17 -0
- package/dist/cjs/hooks/useProduct.js +90 -0
- package/dist/cjs/hooks/useProductList.js +21 -0
- package/dist/cjs/hooks/useSuspenseFetch.js +24 -0
- package/dist/cjs/hooks/useSwatchesOptions.js +39 -0
- package/dist/cjs/index.js +229 -0
- package/dist/cjs/types/global-style.js +7 -0
- package/dist/cjs/types/shop.js +2 -0
- package/dist/esm/components/AddOn.js +14 -0
- package/dist/esm/components/ComponentWrapper.js +40 -0
- package/dist/esm/components/ComponentWrapperPreview.js +54 -0
- package/dist/esm/components/Empty.js +3 -0
- package/dist/esm/components/Render.js +24 -0
- package/dist/esm/components/RenderBlock.js +17 -0
- package/dist/esm/components/RenderPreview.js +24 -0
- package/dist/esm/components/RenderSection.js +15 -0
- package/dist/esm/contexts/AddonContext.js +21 -0
- package/dist/esm/contexts/BuilderComponent.js +27 -0
- package/dist/esm/contexts/BuilderContext.js +26 -0
- package/dist/esm/contexts/BuilderPreviewContext.js +350 -0
- package/dist/esm/contexts/CartLineContext.js +21 -0
- package/dist/esm/contexts/CollectionContext.js +20 -0
- package/dist/esm/contexts/ProductContext.js +123 -0
- package/dist/esm/contexts/ProductListContext.js +20 -0
- package/dist/esm/contexts/SectionContext.js +45 -0
- package/dist/esm/contexts/ShopContext.js +40 -0
- package/dist/esm/graphql/fragments/analytic.generated.js +9 -0
- package/dist/esm/graphql/fragments/collection-detail.generated.js +11 -0
- package/dist/esm/graphql/fragments/collection-product.generated.js +24 -0
- package/dist/esm/graphql/fragments/data-seo.generated.js +9 -0
- package/dist/esm/graphql/fragments/media.generated.js +12 -0
- package/dist/esm/graphql/fragments/product-little.generated.js +23 -0
- package/dist/esm/graphql/fragments/product-option-value.generated.js +11 -0
- package/dist/esm/graphql/fragments/product-option.generated.js +12 -0
- package/dist/esm/graphql/fragments/product.generated.js +31 -0
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +10 -0
- package/dist/esm/graphql/fragments/published-page-section.generated.js +9 -0
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +25 -0
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +9 -0
- package/dist/esm/graphql/fragments/selected-option.generated.js +9 -0
- package/dist/esm/graphql/fragments/variant.generated.js +33 -0
- package/dist/esm/graphql/queries/collection-detail-filter.generated.js +32 -0
- package/dist/esm/graphql/queries/collection.generated.js +50 -0
- package/dist/esm/graphql/queries/preview-page.generated.js +21 -0
- package/dist/esm/graphql/queries/product-little-detail.generated.js +22 -0
- package/dist/esm/graphql/queries/product-medias.generated.js +27 -0
- package/dist/esm/graphql/queries/product-variants.generated.js +31 -0
- package/dist/esm/graphql/queries/products.generated.js +38 -0
- package/dist/esm/graphql/queries/published-theme-pages.generated.js +21 -0
- package/dist/esm/graphql/queries/storeProperty.generated.js +10 -0
- package/dist/esm/helpers/GlobalEvent.js +13 -0
- package/dist/esm/helpers/background.js +102 -0
- package/dist/esm/helpers/borders.js +133 -0
- package/dist/esm/helpers/clone-deep.js +3 -0
- package/dist/esm/helpers/cls.js +18 -0
- package/dist/esm/helpers/colors.js +145 -0
- package/dist/esm/helpers/compose-advance-style.js +130 -0
- package/dist/esm/helpers/constant.js +13 -0
- package/dist/esm/helpers/css-variable.js +5 -0
- package/dist/esm/helpers/email.js +6 -0
- package/dist/esm/helpers/flatten-connection.js +8 -0
- package/dist/esm/helpers/fpixel.js +25 -0
- package/dist/esm/helpers/get-resonsive-value.js +28 -0
- package/dist/esm/helpers/get-shortname.js +90 -0
- package/dist/esm/helpers/gtag.js +45 -0
- package/dist/esm/helpers/is-browser.js +5 -0
- package/dist/esm/helpers/is-defined.js +5 -0
- package/dist/esm/helpers/is-empty-children.js +7 -0
- package/dist/esm/helpers/layout.js +15 -0
- package/dist/esm/helpers/load-script.js +30 -0
- package/dist/esm/helpers/make-style.js +91 -0
- package/dist/esm/helpers/normalize-builder-data.js +15 -0
- package/dist/esm/helpers/prefetch-queries.js +66 -0
- package/dist/esm/helpers/product.js +32 -0
- package/dist/esm/helpers/queries/get-collection.js +170 -0
- package/dist/esm/helpers/queries/get-product-by-slug.js +97 -0
- package/dist/esm/helpers/queries/get-product.js +109 -0
- package/dist/esm/helpers/queries/get-products.js +133 -0
- package/dist/esm/helpers/radius.js +86 -0
- package/dist/esm/helpers/shadow.js +45 -0
- package/dist/esm/helpers/size.js +18 -0
- package/dist/esm/helpers/spacing.js +42 -0
- package/dist/esm/helpers/tiktokpixel.js +15 -0
- package/dist/esm/helpers/typography.js +5 -0
- package/dist/esm/hooks/cart/use-add-to-cart.js +18 -0
- package/dist/esm/hooks/cart/use-cart-data.js +24 -0
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +18 -0
- package/dist/esm/hooks/cart/use-cart-note-update.js +18 -0
- package/dist/esm/hooks/cart/use-create-cart.js +20 -0
- package/dist/esm/hooks/cart/use-remove-cart-item.js +18 -0
- package/dist/esm/hooks/cart/use-update-cart-item.js +18 -0
- package/dist/esm/hooks/shop/use-collection-query.js +14 -0
- package/dist/esm/hooks/shop/use-product-query.js +14 -0
- package/dist/esm/hooks/shop/use-products-query.js +14 -0
- package/dist/esm/hooks/shop.js +68 -0
- package/dist/esm/hooks/use-current-device.js +21 -0
- package/dist/esm/hooks/use-lazy-video.js +13 -0
- package/dist/esm/hooks/useCartId.js +32 -0
- package/dist/esm/hooks/useCartLine.js +7 -0
- package/dist/esm/hooks/useCartUI.js +38 -0
- package/dist/esm/hooks/useCollection.js +7 -0
- package/dist/esm/hooks/useFetchHandle.js +11 -0
- package/dist/esm/hooks/useFormatMoney.js +13 -0
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +6 -0
- package/dist/esm/hooks/useLoadScript.js +26 -0
- package/dist/esm/hooks/useMoney.js +48 -0
- package/dist/esm/hooks/usePrevious.js +15 -0
- package/dist/esm/hooks/useProduct.js +78 -0
- package/dist/esm/hooks/useProductList.js +16 -0
- package/dist/esm/hooks/useSuspenseFetch.js +20 -0
- package/dist/esm/hooks/useSwatchesOptions.js +35 -0
- package/dist/esm/index.js +82 -0
- package/dist/esm/types/global-style.js +4 -0
- package/dist/esm/types/shop.js +1 -0
- package/dist/types/index.d.ts +7393 -0
- package/package.json +50 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constant = require('./constant.js');
|
|
4
|
+
|
|
5
|
+
function getCustomSizeCSSByDevice(size, device) {
|
|
6
|
+
if (!size || !device)
|
|
7
|
+
return {};
|
|
8
|
+
const suffix = constant.devicesMapping[device] ?? '';
|
|
9
|
+
return {
|
|
10
|
+
[`--pl${suffix}`]: size?.[device]?.horizontal,
|
|
11
|
+
[`--pr${suffix}`]: size?.[device]?.horizontal,
|
|
12
|
+
[`--pt${suffix}`]: size?.[device]?.vertical,
|
|
13
|
+
[`--pb${suffix}`]: size?.[device]?.vertical,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const composeSize = (size) => {
|
|
17
|
+
return Object.assign({}, getCustomSizeCSSByDevice(size, 'desktop'), getCustomSizeCSSByDevice(size, 'tablet'), getCustomSizeCSSByDevice(size, 'mobile'));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.composeSize = composeSize;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constant = require('./constant.js');
|
|
4
|
+
|
|
5
|
+
function getSpacingCSSByType(key, device) {
|
|
6
|
+
if (!key)
|
|
7
|
+
return {};
|
|
8
|
+
const suffix = device ? constant.devicesMapping?.[device] ?? '' : '';
|
|
9
|
+
return {
|
|
10
|
+
[`--p${suffix}`]: `var(--g-s-${key})`,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function getSpacingVariable(key) {
|
|
14
|
+
if (!key)
|
|
15
|
+
return '';
|
|
16
|
+
return `var(--g-s-${key})`;
|
|
17
|
+
}
|
|
18
|
+
const composeSpacing = (spacingValue) => {
|
|
19
|
+
const style = {};
|
|
20
|
+
switch (spacingValue?.desktop) {
|
|
21
|
+
case 'm':
|
|
22
|
+
case 'l':
|
|
23
|
+
case 's':
|
|
24
|
+
Object.assign(style, getSpacingCSSByType(spacingValue.desktop));
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
switch (spacingValue?.tablet) {
|
|
28
|
+
case 'm':
|
|
29
|
+
case 'l':
|
|
30
|
+
case 's':
|
|
31
|
+
Object.assign(style, getSpacingCSSByType(spacingValue.tablet, 'tablet'));
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
switch (spacingValue?.mobile) {
|
|
35
|
+
case 'm':
|
|
36
|
+
case 'l':
|
|
37
|
+
case 's':
|
|
38
|
+
Object.assign(style, getSpacingCSSByType(spacingValue.mobile, 'mobile'));
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
return style;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.composeSpacing = composeSpacing;
|
|
45
|
+
exports.getSpacingVariable = getSpacingVariable;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const addToCart = (product) => {
|
|
4
|
+
if (!window?.ttq?.track)
|
|
5
|
+
return;
|
|
6
|
+
window.ttq.track('AddToCart', {
|
|
7
|
+
content_id: product.id,
|
|
8
|
+
content_type: 'product',
|
|
9
|
+
content_name: product.name,
|
|
10
|
+
quantity: product.quantity,
|
|
11
|
+
price: product.price,
|
|
12
|
+
value: (product.price ?? 0) * (product.quantity ?? 0),
|
|
13
|
+
currency: product.currency,
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.addToCart = addToCart;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
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 useAddToCart = (options) => {
|
|
9
|
+
const shop$1 = shop.useStoreFront();
|
|
10
|
+
const { mutate } = useSWR.useSWRConfig();
|
|
11
|
+
return useSWRMutation('add-to-cart', (_, { arg }) => adapterShopify.addToCartOperation(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.useAddToCart = useAddToCart;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var adapterShopify = require('@gem-sdk/adapter-shopify');
|
|
4
|
+
var useSWR = require('swr');
|
|
5
|
+
var shop = require('../shop.js');
|
|
6
|
+
var useCartId = require('../useCartId.js');
|
|
7
|
+
|
|
8
|
+
const useCartData = (options) => {
|
|
9
|
+
const { cartId, clearCartId } = useCartId.default();
|
|
10
|
+
const shop$1 = shop.useStoreFront();
|
|
11
|
+
return useSWR(cartId ? 'cart' : null, () => adapterShopify.getCartOperation(shop$1)({ cartId: cartId }), {
|
|
12
|
+
revalidateOnMount: true,
|
|
13
|
+
revalidateOnFocus: true,
|
|
14
|
+
keepPreviousData: false,
|
|
15
|
+
dedupingInterval: 2000,
|
|
16
|
+
...options,
|
|
17
|
+
onSuccess(data, key, config) {
|
|
18
|
+
if (!data) {
|
|
19
|
+
clearCartId();
|
|
20
|
+
}
|
|
21
|
+
options?.onSuccess?.(data, key, config);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.useCartData = useCartData;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
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 useCartDiscountCodesUpdate = (options) => {
|
|
9
|
+
const shop$1 = shop.useStoreFront();
|
|
10
|
+
const { mutate } = useSWR.useSWRConfig();
|
|
11
|
+
return useSWRMutation('cart-discount-codes-update', (_, { arg }) => adapterShopify.cartDiscountCodesUpdateOperation(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.useCartDiscountCodesUpdate = useCartDiscountCodesUpdate;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
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 useCartNoteUpdate = (options) => {
|
|
9
|
+
const shop$1 = shop.useStoreFront();
|
|
10
|
+
const { mutate } = useSWR.useSWRConfig();
|
|
11
|
+
return useSWRMutation('cart-note-update', (_, { arg }) => adapterShopify.cartNoteUpdateOperation(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.useCartNoteUpdate = useCartNoteUpdate;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
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 useCreateCart = (options) => {
|
|
9
|
+
const shop$1 = shop.useStoreFront();
|
|
10
|
+
const { mutate } = useSWR.useSWRConfig();
|
|
11
|
+
return useSWRMutation('create-cart', (_, { arg }) => {
|
|
12
|
+
return adapterShopify.createCartOperation(shop$1)(arg);
|
|
13
|
+
}, {
|
|
14
|
+
...options,
|
|
15
|
+
onSuccess: (result, key, config) => {
|
|
16
|
+
mutate('cart', result, false);
|
|
17
|
+
options?.onSuccess?.(result, key, config);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.useCreateCart = useCreateCart;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
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 useRemoveCartItem = (options) => {
|
|
9
|
+
const shop$1 = shop.useStoreFront();
|
|
10
|
+
const { mutate } = useSWR.useSWRConfig();
|
|
11
|
+
return useSWRMutation('remove-cart-item', (_, { arg }) => adapterShopify.removeCartItemOperation(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.useRemoveCartItem = useRemoveCartItem;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
|
|
8
|
+
const useCollectionQuery = (args, options) => {
|
|
9
|
+
const fetcher = useFetchHandle.useFetchHandle();
|
|
10
|
+
const isSample = shop.useIsSampleProduct();
|
|
11
|
+
return useSWR(['query/collection', { ...args, isSample }], ([, arg]) => {
|
|
12
|
+
return getCollection.getCollection(fetcher, arg);
|
|
13
|
+
}, options);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.useCollectionQuery = useCollectionQuery;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
|
|
8
|
+
const useProductQuery = (productId, options) => {
|
|
9
|
+
const fetcher = useFetchHandle.useFetchHandle();
|
|
10
|
+
const isSample = shop.useIsSampleProduct();
|
|
11
|
+
return useSWR(productId ? ['query/product', { id: productId ?? 'latest', isSample }] : null, async ([, arg]) => {
|
|
12
|
+
return getProduct.getProduct(fetcher, arg);
|
|
13
|
+
}, options);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.useProductQuery = useProductQuery;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var useSWR = require('swr');
|
|
4
|
+
var getProducts = require('../../helpers/queries/get-products.js');
|
|
5
|
+
var shop = require('../shop.js');
|
|
6
|
+
var useFetchHandle = require('../useFetchHandle.js');
|
|
7
|
+
|
|
8
|
+
const useProductsQuery = (ids, options) => {
|
|
9
|
+
const fetcher = useFetchHandle.useFetchHandle();
|
|
10
|
+
const isSample = shop.useIsSampleProduct();
|
|
11
|
+
return useSWR(['query/products', { ids, isSample }], async ([, arg]) => {
|
|
12
|
+
return getProducts.getProducts(fetcher, arg);
|
|
13
|
+
}, options);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.useProductsQuery = useProductsQuery;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
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(() => ({ locale, changeLocale }), [locale, changeLocale]);
|
|
11
|
+
};
|
|
12
|
+
const useCurrency = () => {
|
|
13
|
+
const currency = ShopContext.useShopStore((state) => state.currency);
|
|
14
|
+
const changeCurrency = ShopContext.useShopStore((state) => state.changeCurrency);
|
|
15
|
+
return react.useMemo(() => ({ currency, changeCurrency }), [currency, changeCurrency]);
|
|
16
|
+
};
|
|
17
|
+
const useSwatches = () => {
|
|
18
|
+
const swatches = ShopContext.useShopStore((state) => state.swatches);
|
|
19
|
+
const changeSwatches = ShopContext.useShopStore((state) => state.changeSwatches);
|
|
20
|
+
return react.useMemo(() => ({ swatches, changeSwatches }), [swatches, changeSwatches]);
|
|
21
|
+
};
|
|
22
|
+
const usePageType = () => {
|
|
23
|
+
const pageType = ShopContext.useShopStore((state) => state.pageType);
|
|
24
|
+
return react.useMemo(() => pageType || 'STATIC', [pageType]);
|
|
25
|
+
};
|
|
26
|
+
const useStoreFront = () => {
|
|
27
|
+
const provider = ShopContext.useShopStore((state) => state.provider);
|
|
28
|
+
const storefrontToken = ShopContext.useShopStore((state) => state.storefrontToken);
|
|
29
|
+
const storefrontUrl = ShopContext.useShopStore((state) => state.storefrontUrl);
|
|
30
|
+
return {
|
|
31
|
+
provider,
|
|
32
|
+
storefrontToken,
|
|
33
|
+
storefrontUrl,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const usePluginEnable = () => {
|
|
37
|
+
return ShopContext.useShopStore((state) => state.plugins);
|
|
38
|
+
};
|
|
39
|
+
const useEditorMode = () => {
|
|
40
|
+
return ShopContext.useShopStore((state) => state.mode);
|
|
41
|
+
};
|
|
42
|
+
const useMobileOnly = () => {
|
|
43
|
+
return ShopContext.useShopStore((state) => state.mobileOnly);
|
|
44
|
+
};
|
|
45
|
+
const useMatchMutate = () => {
|
|
46
|
+
const { cache, mutate } = useSWR.useSWRConfig();
|
|
47
|
+
return (matcher, ...args) => {
|
|
48
|
+
if (!(cache instanceof Map)) {
|
|
49
|
+
throw new Error('matchMutate requires the cache provider to be a Map instance');
|
|
50
|
+
}
|
|
51
|
+
const keys = [];
|
|
52
|
+
cache.forEach((_, key) => {
|
|
53
|
+
if (matcher.test(key)) {
|
|
54
|
+
keys.push(key);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const mutations = keys.map((key) => mutate(key, ...args));
|
|
58
|
+
return Promise.all(mutations);
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
function useConnectedShopify() {
|
|
62
|
+
const { storefrontToken } = useStoreFront();
|
|
63
|
+
return !!storefrontToken;
|
|
64
|
+
}
|
|
65
|
+
function useIsSampleProduct() {
|
|
66
|
+
const { storefrontToken } = useStoreFront();
|
|
67
|
+
return !storefrontToken;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
exports.useConnectedShopify = useConnectedShopify;
|
|
71
|
+
exports.useCurrency = useCurrency;
|
|
72
|
+
exports.useEditorMode = useEditorMode;
|
|
73
|
+
exports.useIsSampleProduct = useIsSampleProduct;
|
|
74
|
+
exports.useLocale = useLocale;
|
|
75
|
+
exports.useMatchMutate = useMatchMutate;
|
|
76
|
+
exports.useMobileOnly = useMobileOnly;
|
|
77
|
+
exports.usePageType = usePageType;
|
|
78
|
+
exports.usePluginEnable = usePluginEnable;
|
|
79
|
+
exports.useStoreFront = useStoreFront;
|
|
80
|
+
exports.useSwatches = useSwatches;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
}
|
|
14
|
+
else if (window.innerWidth >= 768 && window.innerWidth < 1024) {
|
|
15
|
+
return 'tablet';
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return 'desktop';
|
|
19
|
+
}
|
|
20
|
+
}, () => 'desktop');
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.useCurrentDevice = useCurrentDevice;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
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;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
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(() => ({ cartId, updateCartId, clearCartId }), [cartId, clearCartId, updateCartId]);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.default = useCartId;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
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;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var create = require('zustand');
|
|
7
|
+
var shop = require('./shop.js');
|
|
8
|
+
|
|
9
|
+
const useStore = 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
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
document.body.style.overflow = '';
|
|
20
|
+
document.body.style.paddingRight = '';
|
|
21
|
+
}
|
|
22
|
+
set({ isCartOpen });
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
function useCartUI() {
|
|
26
|
+
const plugins = shop.usePluginEnable();
|
|
27
|
+
const isCartOpen = useStore((s) => s.isCartOpen);
|
|
28
|
+
const setOpen = useStore((s) => s.setOpen);
|
|
29
|
+
const openCart = react.useCallback(() => {
|
|
30
|
+
if (plugins?.includes('cart-drawer')) {
|
|
31
|
+
setOpen(true);
|
|
32
|
+
}
|
|
33
|
+
}, [plugins, setOpen]);
|
|
34
|
+
const closeCart = react.useCallback(() => setOpen(false), [setOpen]);
|
|
35
|
+
return {
|
|
36
|
+
isCartOpen,
|
|
37
|
+
openCart,
|
|
38
|
+
closeCart,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.default = useCartUI;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
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;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var shop = require('./shop.js');
|
|
7
|
+
|
|
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), [locale]);
|
|
14
|
+
return { formatMoney };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.default = useFormatMoney;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
*/
|
|
11
|
+
function useLoadScript(url, options) {
|
|
12
|
+
const [status, setStatus] = react.useState('loading');
|
|
13
|
+
const stringifiedOptions = JSON.stringify(options);
|
|
14
|
+
react.useEffect(() => {
|
|
15
|
+
async function loadScriptWrapper() {
|
|
16
|
+
try {
|
|
17
|
+
setStatus('loading');
|
|
18
|
+
await loadScript.loadScript(url, options);
|
|
19
|
+
setStatus('done');
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
setStatus('error');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
loadScriptWrapper();
|
|
26
|
+
}, [url, stringifiedOptions, options]);
|
|
27
|
+
return status;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.default = useLoadScript;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var shop = require('./shop.js');
|
|
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 } = shop.useLocale();
|
|
23
|
+
const { currency } = shop.useCurrency();
|
|
24
|
+
const options = react.useMemo(() => ({ style: 'currency', currency: currency }), [currency]);
|
|
25
|
+
const value = react.useMemo(() => new Intl.NumberFormat(locale, options).format(money), [locale, options, money]);
|
|
26
|
+
const baseParts = new Intl.NumberFormat(locale, options).formatToParts(money);
|
|
27
|
+
const nameParts = new Intl.NumberFormat(locale, {
|
|
28
|
+
...options,
|
|
29
|
+
currencyDisplay: 'name',
|
|
30
|
+
}).formatToParts(money);
|
|
31
|
+
const narrowParts = new Intl.NumberFormat(locale, {
|
|
32
|
+
...options,
|
|
33
|
+
currencyDisplay: 'narrowSymbol',
|
|
34
|
+
}).formatToParts(money);
|
|
35
|
+
const moneyValue = react.useMemo(() => ({
|
|
36
|
+
currencyCode: currency,
|
|
37
|
+
currencyName: nameParts.find((part) => part.type === 'currency')?.value ?? // e.g. "US dollars"
|
|
38
|
+
currency,
|
|
39
|
+
currencyNarrowSymbol: narrowParts.find((part) => part.type === 'currency')?.value ?? // e.g. "$"
|
|
40
|
+
(currency ? NARROW_SYMBOL_MAP[currency] : '') ??
|
|
41
|
+
'',
|
|
42
|
+
parts: baseParts,
|
|
43
|
+
localizedString: value,
|
|
44
|
+
amount: baseParts
|
|
45
|
+
.filter((part) => ['decimal', 'fraction', 'group', 'integer', 'literal'].includes(part.type))
|
|
46
|
+
.map((part) => part.value)
|
|
47
|
+
.join(''),
|
|
48
|
+
}), [baseParts, nameParts, narrowParts, value, currency]);
|
|
49
|
+
return moneyValue;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.default = useMoney;
|