@gem-sdk/core 1.5.15 → 1.5.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/AddOn.js +7 -7
- package/dist/cjs/components/ComponentWrapper.js +14 -8
- package/dist/cjs/components/ComponentWrapperPreview.js +55 -46
- package/dist/cjs/components/Empty.js +1 -1
- package/dist/cjs/components/Render.js +50 -13
- package/dist/cjs/components/Render.liquid.js +81 -57
- package/dist/cjs/components/RenderBlock.js +41 -8
- package/dist/cjs/components/RenderPreview.js +51 -13
- package/dist/cjs/components/RenderSection.js +11 -7
- package/dist/cjs/components/constant.js +24 -24
- package/dist/cjs/contexts/AddonContext.js +25 -14
- package/dist/cjs/contexts/BuilderComponent.js +23 -19
- package/dist/cjs/contexts/BuilderContext.js +25 -19
- package/dist/cjs/contexts/BuilderPreviewContext.js +349 -341
- package/dist/cjs/contexts/CartLineContext.js +19 -14
- package/dist/cjs/contexts/CollectionContext.js +21 -13
- package/dist/cjs/contexts/ProductContext.js +136 -115
- package/dist/cjs/contexts/ProductListContext.js +21 -13
- package/dist/cjs/contexts/SectionContext.js +41 -37
- package/dist/cjs/contexts/ShopContext.js +49 -31
- package/dist/cjs/graphql/fragments/analytic.generated.js +1 -1
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +1 -1
- package/dist/cjs/graphql/fragments/collection-product.generated.js +1 -1
- package/dist/cjs/graphql/fragments/custom-code.generated.js +1 -1
- package/dist/cjs/graphql/fragments/data-seo.generated.js +1 -1
- package/dist/cjs/graphql/fragments/media.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-little.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-option.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +1 -1
- package/dist/cjs/graphql/fragments/selected-option.generated.js +1 -1
- package/dist/cjs/graphql/fragments/variant.generated.js +1 -1
- package/dist/cjs/graphql/mutations/page-view-up.generated.js +1 -1
- package/dist/cjs/graphql/queries/products.generated.js +1 -1
- package/dist/cjs/graphql/queries/store-property.generated.js +1 -1
- package/dist/cjs/helpers/GlobalEvent.js +12 -10
- package/dist/cjs/helpers/background.js +96 -96
- package/dist/cjs/helpers/borders.js +123 -127
- package/dist/cjs/helpers/clone-deep.js +1 -1
- package/dist/cjs/helpers/cls.js +11 -15
- package/dist/cjs/helpers/colors.js +121 -156
- package/dist/cjs/helpers/compose-advance-style.js +115 -121
- package/dist/cjs/helpers/constant.js +16 -11
- package/dist/cjs/helpers/css-variable.js +2 -2
- package/dist/cjs/helpers/email.js +3 -3
- package/dist/cjs/helpers/flatten-connection.js +4 -5
- package/dist/cjs/helpers/get-resonsive-value.js +24 -25
- package/dist/cjs/helpers/get-shortname.js +87 -87
- package/dist/cjs/helpers/is-browser.js +2 -2
- package/dist/cjs/helpers/is-defined.js +2 -2
- package/dist/cjs/helpers/is-empty-children.js +2 -2
- package/dist/cjs/helpers/layout.js +9 -10
- package/dist/cjs/helpers/load-script.js +26 -27
- package/dist/cjs/helpers/make-style.js +77 -86
- package/dist/cjs/helpers/normalize-builder-data.js +18 -12
- package/dist/cjs/helpers/prefetch-queries.js +72 -52
- package/dist/cjs/helpers/product.js +25 -29
- package/dist/cjs/helpers/queries/get-collection.js +179 -167
- package/dist/cjs/helpers/queries/get-product-by-slug.js +103 -94
- package/dist/cjs/helpers/queries/get-product.js +121 -106
- package/dist/cjs/helpers/queries/get-products.js +137 -125
- package/dist/cjs/helpers/radius.js +78 -81
- package/dist/cjs/helpers/render.js +56 -56
- package/dist/cjs/helpers/shadow.js +38 -38
- package/dist/cjs/helpers/size.js +12 -13
- package/dist/cjs/helpers/spacing.js +35 -37
- package/dist/cjs/helpers/tracking/fpixel.js +21 -22
- package/dist/cjs/helpers/tracking/gtag.js +84 -90
- package/dist/cjs/helpers/tracking/tiktokpixel.js +12 -12
- package/dist/cjs/helpers/typography.js +2 -2
- package/dist/cjs/hooks/cart/use-add-to-cart.js +10 -10
- package/dist/cjs/hooks/cart/use-cart-data.js +18 -16
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +10 -10
- package/dist/cjs/hooks/cart/use-cart-note-update.js +10 -10
- package/dist/cjs/hooks/cart/use-create-cart.js +12 -12
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +10 -10
- package/dist/cjs/hooks/cart/use-update-cart-item.js +10 -10
- package/dist/cjs/hooks/shop/use-collection-query.js +12 -6
- package/dist/cjs/hooks/shop/use-product-query.js +12 -6
- package/dist/cjs/hooks/shop/use-products-query.js +14 -6
- package/dist/cjs/hooks/shop.js +86 -67
- package/dist/cjs/hooks/use-current-device.js +14 -16
- package/dist/cjs/hooks/use-lazy-video.js +7 -7
- package/dist/cjs/hooks/useCartId.js +35 -27
- package/dist/cjs/hooks/useCartLine.js +2 -2
- package/dist/cjs/hooks/useCartUI.js +37 -31
- package/dist/cjs/hooks/useCollection.js +2 -2
- package/dist/cjs/hooks/useFetchHandle.js +6 -6
- package/dist/cjs/hooks/useFormatMoney.js +11 -7
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -1
- package/dist/cjs/hooks/useLoadScript.js +22 -20
- package/dist/cjs/hooks/useMoney.js +59 -42
- package/dist/cjs/hooks/usePrevious.js +12 -10
- package/dist/cjs/hooks/useProduct.js +93 -69
- package/dist/cjs/hooks/useProductList.js +11 -11
- package/dist/cjs/hooks/useSuspenseFetch.js +20 -17
- package/dist/cjs/hooks/useSwatchesOptions.js +32 -30
- package/dist/cjs/types/global-style.js +9 -2
- package/dist/esm/components/AddOn.js +7 -7
- package/dist/esm/components/ComponentWrapper.js +14 -8
- package/dist/esm/components/ComponentWrapperPreview.js +55 -46
- package/dist/esm/components/Empty.js +1 -1
- package/dist/esm/components/Render.js +50 -13
- package/dist/esm/components/Render.liquid.js +81 -57
- package/dist/esm/components/RenderBlock.js +41 -8
- package/dist/esm/components/RenderPreview.js +51 -13
- package/dist/esm/components/RenderSection.js +11 -7
- package/dist/esm/components/constant.js +24 -24
- package/dist/esm/contexts/AddonContext.js +26 -15
- package/dist/esm/contexts/BuilderComponent.js +24 -20
- package/dist/esm/contexts/BuilderContext.js +26 -20
- package/dist/esm/contexts/BuilderPreviewContext.js +350 -342
- package/dist/esm/contexts/CartLineContext.js +20 -15
- package/dist/esm/contexts/CollectionContext.js +22 -14
- package/dist/esm/contexts/ProductContext.js +137 -116
- package/dist/esm/contexts/ProductListContext.js +22 -14
- package/dist/esm/contexts/SectionContext.js +42 -38
- package/dist/esm/contexts/ShopContext.js +50 -32
- package/dist/esm/graphql/fragments/analytic.generated.js +1 -1
- package/dist/esm/graphql/fragments/collection-detail.generated.js +1 -1
- package/dist/esm/graphql/fragments/collection-product.generated.js +1 -1
- package/dist/esm/graphql/fragments/custom-code.generated.js +1 -1
- package/dist/esm/graphql/fragments/data-seo.generated.js +1 -1
- package/dist/esm/graphql/fragments/media.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-little.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-option-value.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-option.generated.js +1 -1
- package/dist/esm/graphql/fragments/product.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-page-section.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +1 -1
- package/dist/esm/graphql/fragments/selected-option.generated.js +1 -1
- package/dist/esm/graphql/fragments/variant.generated.js +1 -1
- package/dist/esm/graphql/mutations/page-view-up.generated.js +1 -1
- package/dist/esm/graphql/queries/products.generated.js +1 -1
- package/dist/esm/graphql/queries/store-property.generated.js +1 -1
- package/dist/esm/helpers/GlobalEvent.js +12 -10
- package/dist/esm/helpers/background.js +96 -96
- package/dist/esm/helpers/borders.js +123 -127
- package/dist/esm/helpers/clone-deep.js +1 -1
- package/dist/esm/helpers/cls.js +11 -15
- package/dist/esm/helpers/colors.js +121 -156
- package/dist/esm/helpers/compose-advance-style.js +115 -121
- package/dist/esm/helpers/constant.js +16 -11
- package/dist/esm/helpers/css-variable.js +2 -2
- package/dist/esm/helpers/email.js +3 -3
- package/dist/esm/helpers/flatten-connection.js +4 -5
- package/dist/esm/helpers/get-resonsive-value.js +24 -25
- package/dist/esm/helpers/get-shortname.js +87 -87
- package/dist/esm/helpers/is-browser.js +2 -2
- package/dist/esm/helpers/is-defined.js +2 -2
- package/dist/esm/helpers/is-empty-children.js +2 -2
- package/dist/esm/helpers/layout.js +9 -10
- package/dist/esm/helpers/load-script.js +26 -27
- package/dist/esm/helpers/make-style.js +77 -86
- package/dist/esm/helpers/normalize-builder-data.js +18 -12
- package/dist/esm/helpers/prefetch-queries.js +72 -52
- package/dist/esm/helpers/product.js +25 -29
- package/dist/esm/helpers/queries/get-collection.js +179 -167
- package/dist/esm/helpers/queries/get-product-by-slug.js +103 -94
- package/dist/esm/helpers/queries/get-product.js +121 -106
- package/dist/esm/helpers/queries/get-products.js +137 -125
- package/dist/esm/helpers/radius.js +78 -81
- package/dist/esm/helpers/render.js +56 -56
- package/dist/esm/helpers/shadow.js +38 -38
- package/dist/esm/helpers/size.js +12 -13
- package/dist/esm/helpers/spacing.js +35 -37
- package/dist/esm/helpers/tracking/fpixel.js +21 -22
- package/dist/esm/helpers/tracking/gtag.js +84 -90
- package/dist/esm/helpers/tracking/tiktokpixel.js +12 -12
- package/dist/esm/helpers/typography.js +2 -2
- package/dist/esm/hooks/cart/use-add-to-cart.js +10 -10
- package/dist/esm/hooks/cart/use-cart-data.js +18 -16
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +10 -10
- package/dist/esm/hooks/cart/use-cart-note-update.js +10 -10
- package/dist/esm/hooks/cart/use-create-cart.js +12 -12
- package/dist/esm/hooks/cart/use-remove-cart-item.js +10 -10
- package/dist/esm/hooks/cart/use-update-cart-item.js +10 -10
- package/dist/esm/hooks/shop/use-collection-query.js +12 -6
- package/dist/esm/hooks/shop/use-product-query.js +12 -6
- package/dist/esm/hooks/shop/use-products-query.js +14 -6
- package/dist/esm/hooks/shop.js +86 -67
- package/dist/esm/hooks/use-current-device.js +14 -16
- package/dist/esm/hooks/use-lazy-video.js +7 -7
- package/dist/esm/hooks/useCartId.js +35 -27
- package/dist/esm/hooks/useCartLine.js +2 -2
- package/dist/esm/hooks/useCartUI.js +37 -31
- package/dist/esm/hooks/useCollection.js +2 -2
- package/dist/esm/hooks/useFetchHandle.js +6 -6
- package/dist/esm/hooks/useFormatMoney.js +11 -7
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -1
- package/dist/esm/hooks/useLoadScript.js +22 -20
- package/dist/esm/hooks/useMoney.js +59 -42
- package/dist/esm/hooks/usePrevious.js +12 -10
- package/dist/esm/hooks/useProduct.js +93 -70
- package/dist/esm/hooks/useProductList.js +11 -11
- package/dist/esm/hooks/useSuspenseFetch.js +20 -17
- package/dist/esm/hooks/useSwatchesOptions.js +32 -30
- package/dist/esm/types/global-style.js +9 -2
- package/dist/types/index.d.ts +24 -2
- package/package.json +1 -1
package/dist/esm/helpers/size.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { devicesMapping } from './constant.js';
|
|
2
2
|
|
|
3
|
-
function getCustomSizeCSSByDevice(size, device) {
|
|
4
|
-
if (!size || !device)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[`--
|
|
9
|
-
[`--
|
|
10
|
-
[`--
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return Object.assign({}, getCustomSizeCSSByDevice(size, 'desktop'), getCustomSizeCSSByDevice(size, 'tablet'), getCustomSizeCSSByDevice(size, 'mobile'));
|
|
3
|
+
function getCustomSizeCSSByDevice(size, device) {
|
|
4
|
+
if (!size || !device) return {};
|
|
5
|
+
const suffix = devicesMapping[device] ?? '';
|
|
6
|
+
return {
|
|
7
|
+
[`--pl${suffix}`]: size?.[device]?.horizontal,
|
|
8
|
+
[`--pr${suffix}`]: size?.[device]?.horizontal,
|
|
9
|
+
[`--pt${suffix}`]: size?.[device]?.vertical,
|
|
10
|
+
[`--pb${suffix}`]: size?.[device]?.vertical
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const composeSize = (size)=>{
|
|
14
|
+
return Object.assign({}, getCustomSizeCSSByDevice(size, 'desktop'), getCustomSizeCSSByDevice(size, 'tablet'), getCustomSizeCSSByDevice(size, 'mobile'));
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
export { composeSize };
|
|
@@ -1,42 +1,40 @@
|
|
|
1
1
|
import { devicesMapping } from './constant.js';
|
|
2
2
|
|
|
3
|
-
function getSpacingCSSByType(key, device) {
|
|
4
|
-
if (!key)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
case '
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
case '
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
case '
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
return style;
|
|
3
|
+
function getSpacingCSSByType(key, device) {
|
|
4
|
+
if (!key) return {};
|
|
5
|
+
const suffix = device ? devicesMapping?.[device] ?? '' : '';
|
|
6
|
+
return {
|
|
7
|
+
[`--p${suffix}`]: `var(--g-s-${key})`
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function getSpacingVariable(key) {
|
|
11
|
+
if (!key) return '';
|
|
12
|
+
return `var(--g-s-${key})`;
|
|
13
|
+
}
|
|
14
|
+
const composeSpacing = (spacingValue)=>{
|
|
15
|
+
const style = {};
|
|
16
|
+
switch(spacingValue?.desktop){
|
|
17
|
+
case 'm':
|
|
18
|
+
case 'l':
|
|
19
|
+
case 's':
|
|
20
|
+
Object.assign(style, getSpacingCSSByType(spacingValue.desktop));
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
switch(spacingValue?.tablet){
|
|
24
|
+
case 'm':
|
|
25
|
+
case 'l':
|
|
26
|
+
case 's':
|
|
27
|
+
Object.assign(style, getSpacingCSSByType(spacingValue.tablet, 'tablet'));
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
switch(spacingValue?.mobile){
|
|
31
|
+
case 'm':
|
|
32
|
+
case 'l':
|
|
33
|
+
case 's':
|
|
34
|
+
Object.assign(style, getSpacingCSSByType(spacingValue.mobile, 'mobile'));
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
return style;
|
|
40
38
|
};
|
|
41
39
|
|
|
42
40
|
export { composeSpacing, getSpacingVariable };
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
const pageview = ()
|
|
2
|
-
if (!window.fbq)
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
1
|
+
const pageview = ()=>{
|
|
2
|
+
if (!window.fbq) return;
|
|
3
|
+
window.fbq('track', 'PageView');
|
|
4
|
+
};
|
|
5
|
+
// https://developers.facebook.com/docs/facebook-pixel/advanced/
|
|
6
|
+
const event = (name, options = {})=>{
|
|
7
|
+
if (!window.fbq) return;
|
|
8
|
+
window.fbq('track', name, options);
|
|
9
|
+
};
|
|
10
|
+
const addToCart = (product)=>{
|
|
11
|
+
if (!window.fbq) return;
|
|
12
|
+
window.fbq('track', 'AddToCart', {
|
|
13
|
+
content_ids: [
|
|
14
|
+
product.id
|
|
15
|
+
],
|
|
16
|
+
content_name: product.name,
|
|
17
|
+
content_category: product.category,
|
|
18
|
+
content_type: 'product',
|
|
19
|
+
value: product.price,
|
|
20
|
+
currency: product.currency
|
|
21
|
+
});
|
|
23
22
|
};
|
|
24
23
|
|
|
25
24
|
export { addToCart, event, pageview };
|
|
@@ -1,93 +1,87 @@
|
|
|
1
|
-
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
|
2
|
-
const pageview = (url, trackingId)
|
|
3
|
-
// GA 4
|
|
4
|
-
if (window.gtag && trackingId) {
|
|
5
|
-
window.gtag('config', trackingId, {
|
|
6
|
-
page_path: url
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
// GA 3
|
|
10
|
-
if (window.ga) {
|
|
11
|
-
window.ga('send', 'pageview', url);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
/** Addition to cart events
|
|
15
|
-
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
window.ga('
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
ga('
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
ga('ec:setAction', 'remove');
|
|
87
|
-
ga('send', 'event', {
|
|
88
|
-
eventAction: 'Click',
|
|
89
|
-
eventCategory: 'Remove from cart',
|
|
90
|
-
});
|
|
1
|
+
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
|
2
|
+
const pageview = (url, trackingId)=>{
|
|
3
|
+
// GA 4
|
|
4
|
+
if (window.gtag && trackingId) {
|
|
5
|
+
window.gtag('config', trackingId, {
|
|
6
|
+
page_path: url
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
// GA 3
|
|
10
|
+
if (window.ga) {
|
|
11
|
+
window.ga('send', 'pageview', url);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/** Addition to cart events
|
|
15
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
16
|
+
*/ const addToCart = (product)=>{
|
|
17
|
+
// GA 3
|
|
18
|
+
if (!window.ga || !product) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
window.ga('ec:addProduct', {
|
|
22
|
+
...product,
|
|
23
|
+
id: product.sku,
|
|
24
|
+
name: product.variant === 'Default Title' ? product.name : `${product.name} - ${product.variant}`,
|
|
25
|
+
variant: product.variant === 'Default Title' ? product.name : product.variant
|
|
26
|
+
});
|
|
27
|
+
window.ga('ec:setAction', 'add');
|
|
28
|
+
window.ga('send', 'event', {
|
|
29
|
+
eventCategory: 'EnhancedEcommerce',
|
|
30
|
+
eventAction: 'Added Product',
|
|
31
|
+
nonInteraction: true
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
/** Product clicked event
|
|
35
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-click
|
|
36
|
+
*/ const productClick = (product)=>{
|
|
37
|
+
if (!window.ga) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
ga('ec:addProduct', {
|
|
41
|
+
id: product.id,
|
|
42
|
+
name: product.name,
|
|
43
|
+
category: product.category,
|
|
44
|
+
brand: product.brand,
|
|
45
|
+
variant: product.variant
|
|
46
|
+
});
|
|
47
|
+
ga('ec:setAction', 'click');
|
|
48
|
+
ga('send', 'event', {
|
|
49
|
+
eventAction: 'Click',
|
|
50
|
+
eventCategory: 'Product'
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
/** Product viewed event
|
|
54
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-actvities
|
|
55
|
+
*/ const productDetail = (product)=>{
|
|
56
|
+
if (!product || !window.ga) return;
|
|
57
|
+
ga('ec:addProduct', {
|
|
58
|
+
brand: product.brand,
|
|
59
|
+
category: product.category,
|
|
60
|
+
id: product.id,
|
|
61
|
+
name: product.name,
|
|
62
|
+
variant: product.variant
|
|
63
|
+
});
|
|
64
|
+
ga('ec:setAction', 'detail');
|
|
65
|
+
ga('send', 'event', {
|
|
66
|
+
eventAction: 'Detail',
|
|
67
|
+
eventCategory: 'Ecommerce',
|
|
68
|
+
nonInteraction: 1
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
/** Removal from cart events
|
|
72
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
73
|
+
*/ const removeFromCart = (product, price)=>{
|
|
74
|
+
if (!product || !window.ga) return;
|
|
75
|
+
ga('ec:addProduct', {
|
|
76
|
+
id: product.id,
|
|
77
|
+
name: product.name,
|
|
78
|
+
price
|
|
79
|
+
});
|
|
80
|
+
ga('ec:setAction', 'remove');
|
|
81
|
+
ga('send', 'event', {
|
|
82
|
+
eventAction: 'Click',
|
|
83
|
+
eventCategory: 'Remove from cart'
|
|
84
|
+
});
|
|
91
85
|
};
|
|
92
86
|
|
|
93
87
|
export { addToCart, pageview, productClick, productDetail, removeFromCart };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
window.ttq.track('AddToCart', {
|
|
5
|
-
content_id: product.id,
|
|
6
|
-
content_type: 'product',
|
|
7
|
-
content_name: product.name,
|
|
8
|
-
quantity: product.quantity,
|
|
9
|
-
price: product.price,
|
|
10
|
-
value: (product.price ?? 0) * (product.quantity ?? 0),
|
|
11
|
-
currency: product.currency
|
|
12
|
-
});
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
const addToCart = (product)=>{
|
|
3
|
+
if (!window?.ttq?.track) return;
|
|
4
|
+
window.ttq.track('AddToCart', {
|
|
5
|
+
content_id: product.id,
|
|
6
|
+
content_type: 'product',
|
|
7
|
+
content_name: product.name,
|
|
8
|
+
quantity: product.quantity,
|
|
9
|
+
price: product.price,
|
|
10
|
+
value: (product.price ?? 0) * (product.quantity ?? 0),
|
|
11
|
+
currency: product.currency
|
|
12
|
+
});
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export { addToCart };
|
|
@@ -3,16 +3,16 @@ import { useSWRConfig } from 'swr';
|
|
|
3
3
|
import useSWRMutation from 'swr/mutation';
|
|
4
4
|
import { useStoreFront } from '../shop.js';
|
|
5
5
|
|
|
6
|
-
const useAddToCart = (options)
|
|
7
|
-
const shop = useStoreFront();
|
|
8
|
-
const { mutate
|
|
9
|
-
return useSWRMutation('add-to-cart', (_, { arg
|
|
10
|
-
...options,
|
|
11
|
-
onSuccess: (result, key, config)
|
|
12
|
-
mutate('cart', result, false);
|
|
13
|
-
options?.onSuccess?.(result, key, config);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
6
|
+
const useAddToCart = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('add-to-cart', (_, { arg })=>addToCartOperation(shop)(arg), {
|
|
10
|
+
...options,
|
|
11
|
+
onSuccess: (result, key, config)=>{
|
|
12
|
+
mutate('cart', result, false);
|
|
13
|
+
options?.onSuccess?.(result, key, config);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export { useAddToCart };
|
|
@@ -3,22 +3,24 @@ import useSWR from 'swr';
|
|
|
3
3
|
import { useStoreFront } from '../shop.js';
|
|
4
4
|
import useCartId from '../useCartId.js';
|
|
5
5
|
|
|
6
|
-
const useCartData = (options)
|
|
7
|
-
const { cartId, clearCartId
|
|
8
|
-
const shop = useStoreFront();
|
|
9
|
-
return useSWR(cartId ? 'cart' : null, ()
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
const useCartData = (options)=>{
|
|
7
|
+
const { cartId , clearCartId } = useCartId();
|
|
8
|
+
const shop = useStoreFront();
|
|
9
|
+
return useSWR(cartId ? 'cart' : null, ()=>getCartOperation(shop)({
|
|
10
|
+
cartId: cartId
|
|
11
|
+
}), {
|
|
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
|
+
});
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
export { useCartData };
|
|
@@ -3,16 +3,16 @@ import { useSWRConfig } from 'swr';
|
|
|
3
3
|
import useSWRMutation from 'swr/mutation';
|
|
4
4
|
import { useStoreFront } from '../shop.js';
|
|
5
5
|
|
|
6
|
-
const useCartDiscountCodesUpdate = (options)
|
|
7
|
-
const shop = useStoreFront();
|
|
8
|
-
const { mutate
|
|
9
|
-
return useSWRMutation('cart-discount-codes-update', (_, { arg
|
|
10
|
-
...options,
|
|
11
|
-
onSuccess: (result, key, config)
|
|
12
|
-
mutate('cart', result, false);
|
|
13
|
-
options?.onSuccess?.(result, key, config);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
6
|
+
const useCartDiscountCodesUpdate = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('cart-discount-codes-update', (_, { arg })=>cartDiscountCodesUpdateOperation(shop)(arg), {
|
|
10
|
+
...options,
|
|
11
|
+
onSuccess: (result, key, config)=>{
|
|
12
|
+
mutate('cart', result, false);
|
|
13
|
+
options?.onSuccess?.(result, key, config);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export { useCartDiscountCodesUpdate };
|
|
@@ -3,16 +3,16 @@ import { useSWRConfig } from 'swr';
|
|
|
3
3
|
import useSWRMutation from 'swr/mutation';
|
|
4
4
|
import { useStoreFront } from '../shop.js';
|
|
5
5
|
|
|
6
|
-
const useCartNoteUpdate = (options)
|
|
7
|
-
const shop = useStoreFront();
|
|
8
|
-
const { mutate
|
|
9
|
-
return useSWRMutation('cart-note-update', (_, { arg
|
|
10
|
-
...options,
|
|
11
|
-
onSuccess: (result, key, config)
|
|
12
|
-
mutate('cart', result, false);
|
|
13
|
-
options?.onSuccess?.(result, key, config);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
6
|
+
const useCartNoteUpdate = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('cart-note-update', (_, { arg })=>cartNoteUpdateOperation(shop)(arg), {
|
|
10
|
+
...options,
|
|
11
|
+
onSuccess: (result, key, config)=>{
|
|
12
|
+
mutate('cart', result, false);
|
|
13
|
+
options?.onSuccess?.(result, key, config);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export { useCartNoteUpdate };
|
|
@@ -3,18 +3,18 @@ import { useSWRConfig } from 'swr';
|
|
|
3
3
|
import useSWRMutation from 'swr/mutation';
|
|
4
4
|
import { useStoreFront } from '../shop.js';
|
|
5
5
|
|
|
6
|
-
const useCreateCart = (options)
|
|
7
|
-
const shop = useStoreFront();
|
|
8
|
-
const { mutate
|
|
9
|
-
return useSWRMutation('create-cart', (_, { arg
|
|
10
|
-
return createCartOperation(shop)(arg);
|
|
11
|
-
}, {
|
|
12
|
-
...options,
|
|
13
|
-
onSuccess: (result, key, config)
|
|
14
|
-
mutate('cart', result, false);
|
|
15
|
-
options?.onSuccess?.(result, key, config);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
6
|
+
const useCreateCart = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('create-cart', (_, { arg })=>{
|
|
10
|
+
return createCartOperation(shop)(arg);
|
|
11
|
+
}, {
|
|
12
|
+
...options,
|
|
13
|
+
onSuccess: (result, key, config)=>{
|
|
14
|
+
mutate('cart', result, false);
|
|
15
|
+
options?.onSuccess?.(result, key, config);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export { useCreateCart };
|
|
@@ -3,16 +3,16 @@ import { useSWRConfig } from 'swr';
|
|
|
3
3
|
import useSWRMutation from 'swr/mutation';
|
|
4
4
|
import { useStoreFront } from '../shop.js';
|
|
5
5
|
|
|
6
|
-
const useRemoveCartItem = (options)
|
|
7
|
-
const shop = useStoreFront();
|
|
8
|
-
const { mutate
|
|
9
|
-
return useSWRMutation('remove-cart-item', (_, { arg
|
|
10
|
-
...options,
|
|
11
|
-
onSuccess: (result, key, config)
|
|
12
|
-
mutate('cart', result, false);
|
|
13
|
-
options?.onSuccess?.(result, key, config);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
6
|
+
const useRemoveCartItem = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('remove-cart-item', (_, { arg })=>removeCartItemOperation(shop)(arg), {
|
|
10
|
+
...options,
|
|
11
|
+
onSuccess: (result, key, config)=>{
|
|
12
|
+
mutate('cart', result, false);
|
|
13
|
+
options?.onSuccess?.(result, key, config);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export { useRemoveCartItem };
|
|
@@ -3,16 +3,16 @@ import { useSWRConfig } from 'swr';
|
|
|
3
3
|
import useSWRMutation from 'swr/mutation';
|
|
4
4
|
import { useStoreFront } from '../shop.js';
|
|
5
5
|
|
|
6
|
-
const useUpdateCartItem = (options)
|
|
7
|
-
const shop = useStoreFront();
|
|
8
|
-
const { mutate
|
|
9
|
-
return useSWRMutation('update-cart-item', (_, { arg
|
|
10
|
-
...options,
|
|
11
|
-
onSuccess: (result, key, config)
|
|
12
|
-
mutate('cart', result, false);
|
|
13
|
-
options?.onSuccess?.(result, key, config);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
6
|
+
const useUpdateCartItem = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('update-cart-item', (_, { arg })=>updateCartLineOperation(shop)(arg), {
|
|
10
|
+
...options,
|
|
11
|
+
onSuccess: (result, key, config)=>{
|
|
12
|
+
mutate('cart', result, false);
|
|
13
|
+
options?.onSuccess?.(result, key, config);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export { useUpdateCartItem };
|
|
@@ -3,12 +3,18 @@ import { getCollection } from '../../helpers/queries/get-collection.js';
|
|
|
3
3
|
import { useIsSampleProduct } from '../shop.js';
|
|
4
4
|
import { useFetchHandle } from '../useFetchHandle.js';
|
|
5
5
|
|
|
6
|
-
const useCollectionQuery = (args, options)
|
|
7
|
-
const fetcher = useFetchHandle();
|
|
8
|
-
const isSample = useIsSampleProduct();
|
|
9
|
-
return useSWR([
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const useCollectionQuery = (args, options)=>{
|
|
7
|
+
const fetcher = useFetchHandle();
|
|
8
|
+
const isSample = useIsSampleProduct();
|
|
9
|
+
return useSWR([
|
|
10
|
+
'query/collection',
|
|
11
|
+
{
|
|
12
|
+
...args,
|
|
13
|
+
isSample
|
|
14
|
+
}
|
|
15
|
+
], ([, arg])=>{
|
|
16
|
+
return getCollection(fetcher, arg);
|
|
17
|
+
}, options);
|
|
12
18
|
};
|
|
13
19
|
|
|
14
20
|
export { useCollectionQuery };
|
|
@@ -3,12 +3,18 @@ import { getProduct } from '../../helpers/queries/get-product.js';
|
|
|
3
3
|
import { useIsSampleProduct } from '../shop.js';
|
|
4
4
|
import { useFetchHandle } from '../useFetchHandle.js';
|
|
5
5
|
|
|
6
|
-
const useProductQuery = (productId, options)
|
|
7
|
-
const fetcher = useFetchHandle();
|
|
8
|
-
const isSample = useIsSampleProduct();
|
|
9
|
-
return useSWR(productId ? [
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const useProductQuery = (productId, options)=>{
|
|
7
|
+
const fetcher = useFetchHandle();
|
|
8
|
+
const isSample = useIsSampleProduct();
|
|
9
|
+
return useSWR(productId ? [
|
|
10
|
+
'query/product',
|
|
11
|
+
{
|
|
12
|
+
id: productId ?? 'latest',
|
|
13
|
+
isSample
|
|
14
|
+
}
|
|
15
|
+
] : null, async ([, arg])=>{
|
|
16
|
+
return getProduct(fetcher, arg);
|
|
17
|
+
}, options);
|
|
12
18
|
};
|
|
13
19
|
|
|
14
20
|
export { useProductQuery };
|