@gem-sdk/core 1.5.17 → 1.5.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/dist/cjs/components/AddOn.js +7 -7
  2. package/dist/cjs/components/ComponentWrapper.js +14 -8
  3. package/dist/cjs/components/ComponentWrapperPreview.js +55 -46
  4. package/dist/cjs/components/Empty.js +1 -1
  5. package/dist/cjs/components/Render.js +50 -13
  6. package/dist/cjs/components/Render.liquid.js +81 -57
  7. package/dist/cjs/components/RenderBlock.js +41 -8
  8. package/dist/cjs/components/RenderPreview.js +51 -13
  9. package/dist/cjs/components/RenderSection.js +11 -7
  10. package/dist/cjs/components/constant.js +24 -24
  11. package/dist/cjs/contexts/AddonContext.js +25 -14
  12. package/dist/cjs/contexts/BuilderComponent.js +23 -19
  13. package/dist/cjs/contexts/BuilderContext.js +25 -19
  14. package/dist/cjs/contexts/BuilderPreviewContext.js +349 -341
  15. package/dist/cjs/contexts/CartLineContext.js +19 -14
  16. package/dist/cjs/contexts/CollectionContext.js +21 -13
  17. package/dist/cjs/contexts/ProductContext.js +136 -115
  18. package/dist/cjs/contexts/ProductListContext.js +21 -13
  19. package/dist/cjs/contexts/SectionContext.js +41 -37
  20. package/dist/cjs/contexts/ShopContext.js +49 -31
  21. package/dist/cjs/graphql/fragments/analytic.generated.js +1 -1
  22. package/dist/cjs/graphql/fragments/collection-detail.generated.js +1 -1
  23. package/dist/cjs/graphql/fragments/collection-product.generated.js +1 -1
  24. package/dist/cjs/graphql/fragments/custom-code.generated.js +1 -1
  25. package/dist/cjs/graphql/fragments/data-seo.generated.js +1 -1
  26. package/dist/cjs/graphql/fragments/media.generated.js +1 -1
  27. package/dist/cjs/graphql/fragments/product-little.generated.js +1 -1
  28. package/dist/cjs/graphql/fragments/product-option-value.generated.js +1 -1
  29. package/dist/cjs/graphql/fragments/product-option.generated.js +1 -1
  30. package/dist/cjs/graphql/fragments/product.generated.js +1 -1
  31. package/dist/cjs/graphql/fragments/published-custom-section.generated.js +1 -1
  32. package/dist/cjs/graphql/fragments/published-page-section.generated.js +1 -1
  33. package/dist/cjs/graphql/fragments/published-theme-page.generated.js +1 -1
  34. package/dist/cjs/graphql/fragments/published-theme-style.generated.js +1 -1
  35. package/dist/cjs/graphql/fragments/selected-option.generated.js +1 -1
  36. package/dist/cjs/graphql/fragments/variant.generated.js +1 -1
  37. package/dist/cjs/graphql/mutations/page-view-up.generated.js +1 -1
  38. package/dist/cjs/graphql/queries/products.generated.js +1 -1
  39. package/dist/cjs/graphql/queries/store-property.generated.js +1 -1
  40. package/dist/cjs/helpers/GlobalEvent.js +12 -10
  41. package/dist/cjs/helpers/background.js +96 -96
  42. package/dist/cjs/helpers/borders.js +123 -127
  43. package/dist/cjs/helpers/clone-deep.js +1 -1
  44. package/dist/cjs/helpers/cls.js +11 -15
  45. package/dist/cjs/helpers/colors.js +121 -156
  46. package/dist/cjs/helpers/compose-advance-style.js +115 -121
  47. package/dist/cjs/helpers/constant.js +16 -11
  48. package/dist/cjs/helpers/css-variable.js +2 -2
  49. package/dist/cjs/helpers/email.js +3 -3
  50. package/dist/cjs/helpers/flatten-connection.js +4 -5
  51. package/dist/cjs/helpers/get-resonsive-value.js +24 -25
  52. package/dist/cjs/helpers/get-shortname.js +87 -87
  53. package/dist/cjs/helpers/is-browser.js +2 -2
  54. package/dist/cjs/helpers/is-defined.js +2 -2
  55. package/dist/cjs/helpers/is-empty-children.js +2 -2
  56. package/dist/cjs/helpers/layout.js +9 -10
  57. package/dist/cjs/helpers/load-script.js +26 -27
  58. package/dist/cjs/helpers/make-style.js +77 -86
  59. package/dist/cjs/helpers/normalize-builder-data.js +18 -12
  60. package/dist/cjs/helpers/prefetch-queries.js +72 -52
  61. package/dist/cjs/helpers/product.js +25 -29
  62. package/dist/cjs/helpers/queries/get-collection.js +179 -167
  63. package/dist/cjs/helpers/queries/get-product-by-slug.js +103 -94
  64. package/dist/cjs/helpers/queries/get-product.js +121 -106
  65. package/dist/cjs/helpers/queries/get-products.js +137 -125
  66. package/dist/cjs/helpers/radius.js +78 -81
  67. package/dist/cjs/helpers/render.js +56 -56
  68. package/dist/cjs/helpers/shadow.js +38 -38
  69. package/dist/cjs/helpers/size.js +12 -13
  70. package/dist/cjs/helpers/spacing.js +35 -37
  71. package/dist/cjs/helpers/tracking/fpixel.js +21 -22
  72. package/dist/cjs/helpers/tracking/gtag.js +84 -90
  73. package/dist/cjs/helpers/tracking/tiktokpixel.js +12 -12
  74. package/dist/cjs/helpers/typography.js +2 -2
  75. package/dist/cjs/hooks/cart/use-add-to-cart.js +10 -10
  76. package/dist/cjs/hooks/cart/use-cart-data.js +18 -16
  77. package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +10 -10
  78. package/dist/cjs/hooks/cart/use-cart-note-update.js +10 -10
  79. package/dist/cjs/hooks/cart/use-create-cart.js +12 -12
  80. package/dist/cjs/hooks/cart/use-remove-cart-item.js +10 -10
  81. package/dist/cjs/hooks/cart/use-update-cart-item.js +10 -10
  82. package/dist/cjs/hooks/shop/use-collection-query.js +12 -6
  83. package/dist/cjs/hooks/shop/use-product-query.js +12 -6
  84. package/dist/cjs/hooks/shop/use-products-query.js +14 -6
  85. package/dist/cjs/hooks/shop.js +86 -67
  86. package/dist/cjs/hooks/use-current-device.js +14 -16
  87. package/dist/cjs/hooks/use-lazy-video.js +7 -7
  88. package/dist/cjs/hooks/useCartId.js +35 -27
  89. package/dist/cjs/hooks/useCartLine.js +2 -2
  90. package/dist/cjs/hooks/useCartUI.js +37 -31
  91. package/dist/cjs/hooks/useCollection.js +2 -2
  92. package/dist/cjs/hooks/useFetchHandle.js +6 -6
  93. package/dist/cjs/hooks/useFormatMoney.js +11 -7
  94. package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -1
  95. package/dist/cjs/hooks/useLoadScript.js +22 -20
  96. package/dist/cjs/hooks/useMoney.js +59 -42
  97. package/dist/cjs/hooks/usePrevious.js +12 -10
  98. package/dist/cjs/hooks/useProduct.js +92 -69
  99. package/dist/cjs/hooks/useProductList.js +11 -11
  100. package/dist/cjs/hooks/useSuspenseFetch.js +20 -17
  101. package/dist/cjs/hooks/useSwatchesOptions.js +32 -30
  102. package/dist/cjs/types/global-style.js +9 -2
  103. package/dist/esm/components/AddOn.js +7 -7
  104. package/dist/esm/components/ComponentWrapper.js +14 -8
  105. package/dist/esm/components/ComponentWrapperPreview.js +55 -46
  106. package/dist/esm/components/Empty.js +1 -1
  107. package/dist/esm/components/Render.js +50 -13
  108. package/dist/esm/components/Render.liquid.js +81 -57
  109. package/dist/esm/components/RenderBlock.js +41 -8
  110. package/dist/esm/components/RenderPreview.js +51 -13
  111. package/dist/esm/components/RenderSection.js +11 -7
  112. package/dist/esm/components/constant.js +24 -24
  113. package/dist/esm/contexts/AddonContext.js +26 -15
  114. package/dist/esm/contexts/BuilderComponent.js +24 -20
  115. package/dist/esm/contexts/BuilderContext.js +26 -20
  116. package/dist/esm/contexts/BuilderPreviewContext.js +350 -342
  117. package/dist/esm/contexts/CartLineContext.js +20 -15
  118. package/dist/esm/contexts/CollectionContext.js +22 -14
  119. package/dist/esm/contexts/ProductContext.js +137 -116
  120. package/dist/esm/contexts/ProductListContext.js +22 -14
  121. package/dist/esm/contexts/SectionContext.js +42 -38
  122. package/dist/esm/contexts/ShopContext.js +50 -32
  123. package/dist/esm/graphql/fragments/analytic.generated.js +1 -1
  124. package/dist/esm/graphql/fragments/collection-detail.generated.js +1 -1
  125. package/dist/esm/graphql/fragments/collection-product.generated.js +1 -1
  126. package/dist/esm/graphql/fragments/custom-code.generated.js +1 -1
  127. package/dist/esm/graphql/fragments/data-seo.generated.js +1 -1
  128. package/dist/esm/graphql/fragments/media.generated.js +1 -1
  129. package/dist/esm/graphql/fragments/product-little.generated.js +1 -1
  130. package/dist/esm/graphql/fragments/product-option-value.generated.js +1 -1
  131. package/dist/esm/graphql/fragments/product-option.generated.js +1 -1
  132. package/dist/esm/graphql/fragments/product.generated.js +1 -1
  133. package/dist/esm/graphql/fragments/published-custom-section.generated.js +1 -1
  134. package/dist/esm/graphql/fragments/published-page-section.generated.js +1 -1
  135. package/dist/esm/graphql/fragments/published-theme-page.generated.js +1 -1
  136. package/dist/esm/graphql/fragments/published-theme-style.generated.js +1 -1
  137. package/dist/esm/graphql/fragments/selected-option.generated.js +1 -1
  138. package/dist/esm/graphql/fragments/variant.generated.js +1 -1
  139. package/dist/esm/graphql/mutations/page-view-up.generated.js +1 -1
  140. package/dist/esm/graphql/queries/products.generated.js +1 -1
  141. package/dist/esm/graphql/queries/store-property.generated.js +1 -1
  142. package/dist/esm/helpers/GlobalEvent.js +12 -10
  143. package/dist/esm/helpers/background.js +96 -96
  144. package/dist/esm/helpers/borders.js +123 -127
  145. package/dist/esm/helpers/clone-deep.js +1 -1
  146. package/dist/esm/helpers/cls.js +11 -15
  147. package/dist/esm/helpers/colors.js +121 -156
  148. package/dist/esm/helpers/compose-advance-style.js +115 -121
  149. package/dist/esm/helpers/constant.js +16 -11
  150. package/dist/esm/helpers/css-variable.js +2 -2
  151. package/dist/esm/helpers/email.js +3 -3
  152. package/dist/esm/helpers/flatten-connection.js +4 -5
  153. package/dist/esm/helpers/get-resonsive-value.js +24 -25
  154. package/dist/esm/helpers/get-shortname.js +87 -87
  155. package/dist/esm/helpers/is-browser.js +2 -2
  156. package/dist/esm/helpers/is-defined.js +2 -2
  157. package/dist/esm/helpers/is-empty-children.js +2 -2
  158. package/dist/esm/helpers/layout.js +9 -10
  159. package/dist/esm/helpers/load-script.js +26 -27
  160. package/dist/esm/helpers/make-style.js +77 -86
  161. package/dist/esm/helpers/normalize-builder-data.js +18 -12
  162. package/dist/esm/helpers/prefetch-queries.js +72 -52
  163. package/dist/esm/helpers/product.js +25 -29
  164. package/dist/esm/helpers/queries/get-collection.js +179 -167
  165. package/dist/esm/helpers/queries/get-product-by-slug.js +103 -94
  166. package/dist/esm/helpers/queries/get-product.js +121 -106
  167. package/dist/esm/helpers/queries/get-products.js +137 -125
  168. package/dist/esm/helpers/radius.js +78 -81
  169. package/dist/esm/helpers/render.js +56 -56
  170. package/dist/esm/helpers/shadow.js +38 -38
  171. package/dist/esm/helpers/size.js +12 -13
  172. package/dist/esm/helpers/spacing.js +35 -37
  173. package/dist/esm/helpers/tracking/fpixel.js +21 -22
  174. package/dist/esm/helpers/tracking/gtag.js +84 -90
  175. package/dist/esm/helpers/tracking/tiktokpixel.js +12 -12
  176. package/dist/esm/helpers/typography.js +2 -2
  177. package/dist/esm/hooks/cart/use-add-to-cart.js +10 -10
  178. package/dist/esm/hooks/cart/use-cart-data.js +18 -16
  179. package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +10 -10
  180. package/dist/esm/hooks/cart/use-cart-note-update.js +10 -10
  181. package/dist/esm/hooks/cart/use-create-cart.js +12 -12
  182. package/dist/esm/hooks/cart/use-remove-cart-item.js +10 -10
  183. package/dist/esm/hooks/cart/use-update-cart-item.js +10 -10
  184. package/dist/esm/hooks/shop/use-collection-query.js +12 -6
  185. package/dist/esm/hooks/shop/use-product-query.js +12 -6
  186. package/dist/esm/hooks/shop/use-products-query.js +14 -6
  187. package/dist/esm/hooks/shop.js +86 -67
  188. package/dist/esm/hooks/use-current-device.js +14 -16
  189. package/dist/esm/hooks/use-lazy-video.js +7 -7
  190. package/dist/esm/hooks/useCartId.js +35 -27
  191. package/dist/esm/hooks/useCartLine.js +2 -2
  192. package/dist/esm/hooks/useCartUI.js +37 -31
  193. package/dist/esm/hooks/useCollection.js +2 -2
  194. package/dist/esm/hooks/useFetchHandle.js +6 -6
  195. package/dist/esm/hooks/useFormatMoney.js +11 -7
  196. package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -1
  197. package/dist/esm/hooks/useLoadScript.js +22 -20
  198. package/dist/esm/hooks/useMoney.js +59 -42
  199. package/dist/esm/hooks/usePrevious.js +12 -10
  200. package/dist/esm/hooks/useProduct.js +92 -69
  201. package/dist/esm/hooks/useProductList.js +11 -11
  202. package/dist/esm/hooks/useSuspenseFetch.js +20 -17
  203. package/dist/esm/hooks/useSwatchesOptions.js +32 -30
  204. package/dist/esm/types/global-style.js +9 -2
  205. package/dist/types/index.d.ts +24 -2
  206. package/package.json +1 -1
@@ -1,18 +1,17 @@
1
1
  import { devicesMapping } from './constant.js';
2
2
 
3
- function getCustomSizeCSSByDevice(size, device) {
4
- if (!size || !device)
5
- return {};
6
- const suffix = devicesMapping[device] ?? '';
7
- return {
8
- [`--pl${suffix}`]: size?.[device]?.horizontal,
9
- [`--pr${suffix}`]: size?.[device]?.horizontal,
10
- [`--pt${suffix}`]: size?.[device]?.vertical,
11
- [`--pb${suffix}`]: size?.[device]?.vertical,
12
- };
13
- }
14
- const composeSize = (size) => {
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
- return {};
6
- const suffix = device ? devicesMapping?.[device] ?? '' : '';
7
- return {
8
- [`--p${suffix}`]: `var(--g-s-${key})`,
9
- };
10
- }
11
- function getSpacingVariable(key) {
12
- if (!key)
13
- return '';
14
- return `var(--g-s-${key})`;
15
- }
16
- const composeSpacing = (spacingValue) => {
17
- const style = {};
18
- switch (spacingValue?.desktop) {
19
- case 'm':
20
- case 'l':
21
- case 's':
22
- Object.assign(style, getSpacingCSSByType(spacingValue.desktop));
23
- break;
24
- }
25
- switch (spacingValue?.tablet) {
26
- case 'm':
27
- case 'l':
28
- case 's':
29
- Object.assign(style, getSpacingCSSByType(spacingValue.tablet, 'tablet'));
30
- break;
31
- }
32
- switch (spacingValue?.mobile) {
33
- case 'm':
34
- case 'l':
35
- case 's':
36
- Object.assign(style, getSpacingCSSByType(spacingValue.mobile, 'mobile'));
37
- break;
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
- return;
4
- window.fbq('track', 'PageView');
5
- };
6
- // https://developers.facebook.com/docs/facebook-pixel/advanced/
7
- const event = (name, options = {}) => {
8
- if (!window.fbq)
9
- return;
10
- window.fbq('track', name, options);
11
- };
12
- const addToCart = (product) => {
13
- if (!window.fbq)
14
- return;
15
- window.fbq('track', 'AddToCart', {
16
- content_ids: [product.id],
17
- content_name: product.name,
18
- content_category: product.category,
19
- content_type: 'product',
20
- value: product.price,
21
- currency: product.currency,
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
- const addToCart = (product) => {
18
- // GA 3
19
- if (!window.ga || !product) {
20
- return;
21
- }
22
- window.ga('ec:addProduct', {
23
- ...product,
24
- id: product.sku,
25
- name: product.variant === 'Default Title' ? product.name : `${product.name} - ${product.variant}`,
26
- variant: product.variant === 'Default Title' ? product.name : product.variant,
27
- });
28
- window.ga('ec:setAction', 'add');
29
- window.ga('send', 'event', {
30
- eventCategory: 'EnhancedEcommerce',
31
- eventAction: 'Added Product',
32
- nonInteraction: true,
33
- });
34
- };
35
- /** Product clicked event
36
- * https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-click
37
- */
38
- const productClick = (product) => {
39
- if (!window.ga) {
40
- return;
41
- }
42
- ga('ec:addProduct', {
43
- id: product.id,
44
- name: product.name,
45
- category: product.category,
46
- brand: product.brand,
47
- variant: product.variant,
48
- });
49
- ga('ec:setAction', 'click');
50
- ga('send', 'event', {
51
- eventAction: 'Click',
52
- eventCategory: 'Product',
53
- });
54
- };
55
- /** Product viewed event
56
- * https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-actvities
57
- */
58
- const productDetail = (product) => {
59
- if (!product || !window.ga)
60
- return;
61
- ga('ec:addProduct', {
62
- brand: product.brand,
63
- category: product.category,
64
- id: product.id,
65
- name: product.name,
66
- variant: product.variant,
67
- });
68
- ga('ec:setAction', 'detail');
69
- ga('send', 'event', {
70
- eventAction: 'Detail',
71
- eventCategory: 'Ecommerce',
72
- nonInteraction: 1,
73
- });
74
- };
75
- /** Removal from cart events
76
- * https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
77
- */
78
- const removeFromCart = (product, price) => {
79
- if (!product || !window.ga)
80
- return;
81
- ga('ec:addProduct', {
82
- id: product.id,
83
- name: product.name,
84
- price,
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
- const addToCart = (product) => {
2
- if (!window?.ttq?.track)
3
- 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
- });
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 };
@@ -1,5 +1,5 @@
1
- const genTypoClass = (name) => {
2
- return `g-${name}`;
1
+ const genTypoClass = (name)=>{
2
+ return `g-${name}`;
3
3
  };
4
4
 
5
5
  export { genTypoClass };
@@ -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 } = 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
- });
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 } = useCartId();
8
- const shop = useStoreFront();
9
- return useSWR(cartId ? 'cart' : null, () => getCartOperation(shop)({ cartId: cartId }), {
10
- revalidateOnMount: true,
11
- revalidateOnFocus: true,
12
- keepPreviousData: false,
13
- dedupingInterval: 2000,
14
- ...options,
15
- onSuccess(data, key, config) {
16
- if (!data) {
17
- clearCartId();
18
- }
19
- options?.onSuccess?.(data, key, config);
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 } = 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
- });
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 } = 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
- });
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 } = 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
- });
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 } = 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
- });
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 } = 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
- });
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(['query/collection', { ...args, isSample }], ([, arg]) => {
10
- return getCollection(fetcher, arg);
11
- }, options);
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 ? ['query/product', { id: productId ?? 'latest', isSample }] : null, async ([, arg]) => {
10
- return getProduct(fetcher, arg);
11
- }, options);
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 };