@gem-sdk/core 1.13.42 → 1.14.0-dev.286

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/dist/cjs/components/AddOn.js +1 -18
  2. package/dist/cjs/components/ComponentWrapper.js +1 -28
  3. package/dist/cjs/components/ComponentWrapperPreview.js +1 -72
  4. package/dist/cjs/components/Empty.js +1 -7
  5. package/dist/cjs/components/Render.js +1 -65
  6. package/dist/cjs/components/Render.liquid.js +15 -158
  7. package/dist/cjs/components/RenderBlock.js +1 -54
  8. package/dist/cjs/components/RenderCustomCode.js +5 -0
  9. package/dist/cjs/components/RenderPreview.js +1 -66
  10. package/dist/cjs/components/RenderSection.js +1 -23
  11. package/dist/cjs/components/constant.js +1 -39
  12. package/dist/cjs/components/src/product/helpers/variant-presets.js +1 -0
  13. package/dist/cjs/contexts/AddonContext.js +1 -36
  14. package/dist/cjs/contexts/BuilderComponent.js +1 -34
  15. package/dist/cjs/contexts/BuilderContext.js +1 -35
  16. package/dist/cjs/contexts/BuilderPreviewContext.js +1 -370
  17. package/dist/cjs/contexts/CartLineContext.js +1 -29
  18. package/dist/cjs/contexts/CollectionContext.js +1 -38
  19. package/dist/cjs/contexts/ModalContext.js +1 -47
  20. package/dist/cjs/contexts/ProductContext.js +1 -149
  21. package/dist/cjs/contexts/ProductListContext.js +1 -32
  22. package/dist/cjs/contexts/SectionContext.js +1 -53
  23. package/dist/cjs/contexts/ShopContext.js +1 -70
  24. package/dist/cjs/graphql/fragments/analytic.generated.js +2 -6
  25. package/dist/cjs/graphql/fragments/collection-detail.generated.js +2 -6
  26. package/dist/cjs/graphql/fragments/collection-product.generated.js +2 -6
  27. package/dist/cjs/graphql/fragments/collection.generated.js +2 -6
  28. package/dist/cjs/graphql/fragments/custom-code.generated.js +2 -6
  29. package/dist/cjs/graphql/fragments/data-seo.generated.js +2 -6
  30. package/dist/cjs/graphql/fragments/media.generated.js +3 -6
  31. package/dist/cjs/graphql/fragments/product-little.generated.js +2 -6
  32. package/dist/cjs/graphql/fragments/product-option-value.generated.js +2 -6
  33. package/dist/cjs/graphql/fragments/product-option.generated.js +2 -6
  34. package/dist/cjs/graphql/fragments/product.generated.js +2 -6
  35. package/dist/cjs/graphql/fragments/published-custom-section.generated.js +2 -6
  36. package/dist/cjs/graphql/fragments/published-page-section.generated.js +2 -6
  37. package/dist/cjs/graphql/fragments/published-theme-page.generated.js +2 -6
  38. package/dist/cjs/graphql/fragments/published-theme-style.generated.js +2 -6
  39. package/dist/cjs/graphql/fragments/selected-option.generated.js +2 -6
  40. package/dist/cjs/graphql/fragments/variant.generated.js +2 -6
  41. package/dist/cjs/graphql/mutations/page-view-up.generated.js +3 -7
  42. package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +2 -16
  43. package/dist/cjs/graphql/queries/collection.generated.js +2 -14
  44. package/dist/cjs/graphql/queries/collections.generated.js +2 -9
  45. package/dist/cjs/graphql/queries/preview-page.generated.js +2 -14
  46. package/dist/cjs/graphql/queries/product-little-detail.generated.js +2 -11
  47. package/dist/cjs/graphql/queries/product-medias.generated.js +2 -8
  48. package/dist/cjs/graphql/queries/product-value-label.generated.js +7 -0
  49. package/dist/cjs/graphql/queries/product-variants.generated.js +2 -10
  50. package/dist/cjs/graphql/queries/products.generated.js +3 -17
  51. package/dist/cjs/graphql/queries/published-theme-pages.generated.js +2 -14
  52. package/dist/cjs/graphql/queries/store-property.generated.js +2 -6
  53. package/dist/cjs/helpers/GlobalEvent.js +1 -19
  54. package/dist/cjs/helpers/background.js +1 -109
  55. package/dist/cjs/helpers/borders.js +4 -183
  56. package/dist/cjs/helpers/clone-deep.js +1 -5
  57. package/dist/cjs/helpers/cls.js +1 -16
  58. package/dist/cjs/helpers/colors.js +1 -183
  59. package/dist/cjs/helpers/compose-advance-style.js +1 -188
  60. package/dist/cjs/helpers/constant.js +1 -23
  61. package/dist/cjs/helpers/convert.js +1 -7
  62. package/dist/cjs/helpers/css-variable.js +1 -7
  63. package/dist/cjs/helpers/email.js +1 -11
  64. package/dist/cjs/helpers/flatten-connection.js +1 -9
  65. package/dist/cjs/helpers/get-resonsive-value.js +1 -31
  66. package/dist/cjs/helpers/get-shortname.js +1 -92
  67. package/dist/cjs/helpers/is-browser.js +1 -9
  68. package/dist/cjs/helpers/is-defined.js +1 -7
  69. package/dist/cjs/helpers/is-empty-children.js +1 -12
  70. package/dist/cjs/helpers/is-safari.js +1 -9
  71. package/dist/cjs/helpers/layout.js +1 -59
  72. package/dist/cjs/helpers/load-script.js +1 -31
  73. package/dist/cjs/helpers/make-style.js +1 -128
  74. package/dist/cjs/helpers/normalize-builder-data.js +1 -23
  75. package/dist/cjs/helpers/prefetch-queries.js +1 -78
  76. package/dist/cjs/helpers/product.js +1 -45
  77. package/dist/cjs/helpers/queries/get-collection.js +1 -220
  78. package/dist/cjs/helpers/queries/get-collections.js +1 -21
  79. package/dist/cjs/helpers/queries/get-product-by-slug.js +1 -125
  80. package/dist/cjs/helpers/queries/get-product.js +1 -154
  81. package/dist/cjs/helpers/queries/get-products.js +1 -161
  82. package/dist/cjs/helpers/query.js +1 -29
  83. package/dist/cjs/helpers/radius.js +6 -134
  84. package/dist/cjs/helpers/render.js +1 -71
  85. package/dist/cjs/helpers/shadow.js +1 -56
  86. package/dist/cjs/helpers/size.js +4 -35
  87. package/dist/cjs/helpers/spacing.js +1 -43
  88. package/dist/cjs/helpers/tracking/fpixel.js +1 -28
  89. package/dist/cjs/helpers/tracking/gtag.js +1 -93
  90. package/dist/cjs/helpers/tracking/tiktokpixel.js +1 -17
  91. package/dist/cjs/helpers/typography.js +17 -105
  92. package/dist/cjs/helpers/variant.js +1 -8
  93. package/dist/cjs/hooks/cart/use-add-to-cart.js +1 -20
  94. package/dist/cjs/hooks/cart/use-cart-data.js +1 -28
  95. package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +1 -20
  96. package/dist/cjs/hooks/cart/use-cart-note-update.js +1 -20
  97. package/dist/cjs/hooks/cart/use-create-cart.js +1 -22
  98. package/dist/cjs/hooks/cart/use-remove-cart-item.js +1 -20
  99. package/dist/cjs/hooks/cart/use-update-cart-item.js +1 -20
  100. package/dist/cjs/hooks/shop/use-collection-query.js +1 -22
  101. package/dist/cjs/hooks/shop/use-collections-query.js +1 -17
  102. package/dist/cjs/hooks/shop/use-product-query.js +1 -22
  103. package/dist/cjs/hooks/shop/use-products-query.js +1 -22
  104. package/dist/cjs/hooks/shop.js +1 -126
  105. package/dist/cjs/hooks/use-current-device.js +1 -21
  106. package/dist/cjs/hooks/use-lazy-video.js +1 -15
  107. package/dist/cjs/hooks/useCartId.js +1 -44
  108. package/dist/cjs/hooks/useCartLine.js +1 -11
  109. package/dist/cjs/hooks/useCartUI.js +1 -48
  110. package/dist/cjs/hooks/useCollection.js +1 -9
  111. package/dist/cjs/hooks/useFetchHandle.js +1 -13
  112. package/dist/cjs/hooks/useFormatMoney.js +1 -58
  113. package/dist/cjs/hooks/useInitialSwatchesOptions.js +1 -0
  114. package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -10
  115. package/dist/cjs/hooks/useLoadScript.js +1 -32
  116. package/dist/cjs/hooks/useMoney.js +1 -84
  117. package/dist/cjs/hooks/usePrevious.js +1 -19
  118. package/dist/cjs/hooks/useProduct.js +1 -124
  119. package/dist/cjs/hooks/useProductList.js +1 -21
  120. package/dist/cjs/hooks/useSuspenseFetch.js +1 -27
  121. package/dist/cjs/hooks/useSwatchesOptions.js +1 -41
  122. package/dist/cjs/index.js +1 -291
  123. package/dist/cjs/types/global-style.js +1 -14
  124. package/dist/cjs/types/shop.js +1 -2
  125. package/dist/esm/components/AddOn.js +1 -14
  126. package/dist/esm/components/ComponentWrapper.js +1 -24
  127. package/dist/esm/components/ComponentWrapperPreview.js +1 -68
  128. package/dist/esm/components/Empty.js +1 -3
  129. package/dist/esm/components/Render.js +1 -61
  130. package/dist/esm/components/Render.liquid.js +15 -153
  131. package/dist/esm/components/RenderBlock.js +1 -50
  132. package/dist/esm/components/RenderCustomCode.js +5 -0
  133. package/dist/esm/components/RenderPreview.js +1 -62
  134. package/dist/esm/components/RenderSection.js +1 -19
  135. package/dist/esm/components/constant.js +1 -37
  136. package/dist/esm/components/src/product/helpers/variant-presets.js +1 -0
  137. package/dist/esm/contexts/AddonContext.js +1 -32
  138. package/dist/esm/contexts/BuilderComponent.js +1 -31
  139. package/dist/esm/contexts/BuilderContext.js +1 -32
  140. package/dist/esm/contexts/BuilderPreviewContext.js +1 -367
  141. package/dist/esm/contexts/CartLineContext.js +1 -26
  142. package/dist/esm/contexts/CollectionContext.js +1 -35
  143. package/dist/esm/contexts/ModalContext.js +1 -44
  144. package/dist/esm/contexts/ProductContext.js +1 -146
  145. package/dist/esm/contexts/ProductListContext.js +1 -28
  146. package/dist/esm/contexts/SectionContext.js +1 -49
  147. package/dist/esm/contexts/ShopContext.js +1 -67
  148. package/dist/esm/graphql/fragments/analytic.generated.js +2 -4
  149. package/dist/esm/graphql/fragments/collection-detail.generated.js +2 -4
  150. package/dist/esm/graphql/fragments/collection-product.generated.js +2 -4
  151. package/dist/esm/graphql/fragments/collection.generated.js +2 -4
  152. package/dist/esm/graphql/fragments/custom-code.generated.js +2 -4
  153. package/dist/esm/graphql/fragments/data-seo.generated.js +2 -4
  154. package/dist/esm/graphql/fragments/media.generated.js +3 -4
  155. package/dist/esm/graphql/fragments/product-little.generated.js +2 -4
  156. package/dist/esm/graphql/fragments/product-option-value.generated.js +2 -4
  157. package/dist/esm/graphql/fragments/product-option.generated.js +2 -4
  158. package/dist/esm/graphql/fragments/product.generated.js +2 -4
  159. package/dist/esm/graphql/fragments/published-custom-section.generated.js +2 -4
  160. package/dist/esm/graphql/fragments/published-page-section.generated.js +2 -4
  161. package/dist/esm/graphql/fragments/published-theme-page.generated.js +2 -4
  162. package/dist/esm/graphql/fragments/published-theme-style.generated.js +2 -4
  163. package/dist/esm/graphql/fragments/selected-option.generated.js +2 -4
  164. package/dist/esm/graphql/fragments/variant.generated.js +2 -4
  165. package/dist/esm/graphql/mutations/page-view-up.generated.js +3 -5
  166. package/dist/esm/graphql/queries/collection-detail-filter.generated.js +10 -22
  167. package/dist/esm/graphql/queries/collection.generated.js +8 -18
  168. package/dist/esm/graphql/queries/collections.generated.js +3 -8
  169. package/dist/esm/graphql/queries/preview-page.generated.js +8 -18
  170. package/dist/esm/graphql/queries/product-little-detail.generated.js +5 -12
  171. package/dist/esm/graphql/queries/product-medias.generated.js +2 -6
  172. package/dist/esm/graphql/queries/product-value-label.generated.js +7 -0
  173. package/dist/esm/graphql/queries/product-variants.generated.js +4 -10
  174. package/dist/esm/graphql/queries/products.generated.js +9 -20
  175. package/dist/esm/graphql/queries/published-theme-pages.generated.js +8 -18
  176. package/dist/esm/graphql/queries/store-property.generated.js +2 -4
  177. package/dist/esm/helpers/GlobalEvent.js +1 -15
  178. package/dist/esm/helpers/background.js +1 -106
  179. package/dist/esm/helpers/borders.js +4 -175
  180. package/dist/esm/helpers/clone-deep.js +1 -3
  181. package/dist/esm/helpers/cls.js +1 -14
  182. package/dist/esm/helpers/colors.js +1 -168
  183. package/dist/esm/helpers/compose-advance-style.js +1 -185
  184. package/dist/esm/helpers/constant.js +1 -19
  185. package/dist/esm/helpers/convert.js +1 -4
  186. package/dist/esm/helpers/css-variable.js +1 -5
  187. package/dist/esm/helpers/email.js +1 -6
  188. package/dist/esm/helpers/flatten-connection.js +1 -7
  189. package/dist/esm/helpers/get-resonsive-value.js +1 -27
  190. package/dist/esm/helpers/get-shortname.js +1 -90
  191. package/dist/esm/helpers/is-browser.js +1 -5
  192. package/dist/esm/helpers/is-defined.js +1 -5
  193. package/dist/esm/helpers/is-empty-children.js +1 -7
  194. package/dist/esm/helpers/is-safari.js +1 -5
  195. package/dist/esm/helpers/layout.js +1 -54
  196. package/dist/esm/helpers/load-script.js +1 -29
  197. package/dist/esm/helpers/make-style.js +1 -117
  198. package/dist/esm/helpers/normalize-builder-data.js +1 -21
  199. package/dist/esm/helpers/prefetch-queries.js +1 -76
  200. package/dist/esm/helpers/product.js +1 -41
  201. package/dist/esm/helpers/queries/get-collection.js +1 -217
  202. package/dist/esm/helpers/queries/get-collections.js +1 -19
  203. package/dist/esm/helpers/queries/get-product-by-slug.js +1 -123
  204. package/dist/esm/helpers/queries/get-product.js +1 -150
  205. package/dist/esm/helpers/queries/get-products.js +1 -159
  206. package/dist/esm/helpers/query.js +1 -25
  207. package/dist/esm/helpers/radius.js +6 -127
  208. package/dist/esm/helpers/render.js +1 -64
  209. package/dist/esm/helpers/shadow.js +1 -51
  210. package/dist/esm/helpers/size.js +4 -31
  211. package/dist/esm/helpers/spacing.js +1 -40
  212. package/dist/esm/helpers/tracking/fpixel.js +1 -24
  213. package/dist/esm/helpers/tracking/gtag.js +1 -87
  214. package/dist/esm/helpers/tracking/tiktokpixel.js +1 -15
  215. package/dist/esm/helpers/typography.js +17 -96
  216. package/dist/esm/helpers/variant.js +1 -6
  217. package/dist/esm/hooks/cart/use-add-to-cart.js +1 -18
  218. package/dist/esm/hooks/cart/use-cart-data.js +1 -26
  219. package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +1 -18
  220. package/dist/esm/hooks/cart/use-cart-note-update.js +1 -18
  221. package/dist/esm/hooks/cart/use-create-cart.js +1 -20
  222. package/dist/esm/hooks/cart/use-remove-cart-item.js +1 -18
  223. package/dist/esm/hooks/cart/use-update-cart-item.js +1 -18
  224. package/dist/esm/hooks/shop/use-collection-query.js +1 -20
  225. package/dist/esm/hooks/shop/use-collections-query.js +1 -15
  226. package/dist/esm/hooks/shop/use-product-query.js +1 -20
  227. package/dist/esm/hooks/shop/use-products-query.js +1 -20
  228. package/dist/esm/hooks/shop.js +1 -111
  229. package/dist/esm/hooks/use-current-device.js +1 -19
  230. package/dist/esm/hooks/use-lazy-video.js +1 -13
  231. package/dist/esm/hooks/useCartId.js +1 -40
  232. package/dist/esm/hooks/useCartLine.js +1 -7
  233. package/dist/esm/hooks/useCartUI.js +1 -44
  234. package/dist/esm/hooks/useCollection.js +1 -7
  235. package/dist/esm/hooks/useFetchHandle.js +1 -11
  236. package/dist/esm/hooks/useFormatMoney.js +1 -56
  237. package/dist/esm/hooks/useInitialSwatchesOptions.js +1 -0
  238. package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -6
  239. package/dist/esm/hooks/useLoadScript.js +1 -28
  240. package/dist/esm/hooks/useMoney.js +1 -80
  241. package/dist/esm/hooks/usePrevious.js +1 -17
  242. package/dist/esm/hooks/useProduct.js +1 -111
  243. package/dist/esm/hooks/useProductList.js +1 -16
  244. package/dist/esm/hooks/useSuspenseFetch.js +1 -23
  245. package/dist/esm/hooks/useSwatchesOptions.js +1 -37
  246. package/dist/esm/index.js +1 -92
  247. package/dist/esm/types/global-style.js +1 -11
  248. package/dist/types/index.d.ts +1228 -1031
  249. package/package.json +3 -3
@@ -1,59 +1 @@
1
- 'use strict';
2
-
3
- var constant = require('./constant.js');
4
- var getResonsiveValue = require('./get-resonsive-value.js');
5
-
6
- const gridToArrayRegex = // eslint-disable-next-line regexp/no-super-linear-backtracking
7
- /[^\s()]+(?:\([^\s()]+(?:\([^()]+\))?(?:, *[^\s()]+(?:\([^()]+\))?)*\))?/g; // Regex convert css grid to array
8
- const optionLayoutStyle = (column)=>{
9
- if (!column) return {};
10
- const style = {};
11
- for (const [key, value] of Object.entries(column)){
12
- Object.assign(style, {
13
- [`--gtc${constant.devicesMapping?.[key]}`]: `repeat(${parseFloat(value + '') || 1}, minmax(0, 1fr))`
14
- });
15
- }
16
- return style;
17
- };
18
- const composeGridLayout = (layout)=>{
19
- const display = getResonsiveValue.getResponsiveValue(layout, 'display');
20
- const desktop = (getResonsiveValue.getResponsiveValueByScreen(display, 'desktop') === 'fit' ? layout?.desktop?.cols?.map(()=>`minmax(0, auto)`) : layout?.desktop?.cols?.map((col)=>`minmax(0, ${col}fr)`))?.join(' ');
21
- const tablet = (getResonsiveValue.getResponsiveValueByScreen(display, 'tablet') === 'fit' ? layout?.tablet?.cols?.map(()=>`minmax(0, auto)`) : layout?.tablet?.cols?.map((col)=>`minmax(0, ${col}fr)`))?.join(' ');
22
- const mobile = (getResonsiveValue.getResponsiveValueByScreen(display, 'mobile') === 'fit' ? layout?.mobile?.cols?.map(()=>`minmax(0, auto)`) : layout?.mobile?.cols?.map((col)=>`minmax(0, ${col}fr)`))?.join(' ');
23
- return {
24
- [`--gtc`]: desktop,
25
- [`--gtc-tablet`]: tablet,
26
- [`--gtc-mobile`]: mobile
27
- };
28
- };
29
- const gridToArray = (layout)=>{
30
- return layout ? layout.match(gridToArrayRegex) ?? [] : [];
31
- };
32
- const convertOldLayout = (layout)=>{
33
- const desktopCol = gridToArray(layout?.desktop).length;
34
- const tabletCol = gridToArray(layout?.tablet).length;
35
- const mobileCol = gridToArray(layout?.mobile).length;
36
- return {
37
- desktop: {
38
- cols: desktopCol ? Array.from({
39
- length: desktopCol
40
- }, ()=>12 / desktopCol) : undefined,
41
- display: 'fill'
42
- },
43
- tablet: {
44
- cols: tabletCol ? Array.from({
45
- length: tabletCol
46
- }, ()=>12 / tabletCol) : undefined
47
- },
48
- mobile: {
49
- cols: mobileCol ? Array.from({
50
- length: mobileCol
51
- }, ()=>12 / mobileCol) : undefined
52
- }
53
- };
54
- };
55
-
56
- exports.composeGridLayout = composeGridLayout;
57
- exports.convertOldLayout = convertOldLayout;
58
- exports.gridToArrayRegex = gridToArrayRegex;
59
- exports.optionLayoutStyle = optionLayoutStyle;
1
+ "use strict";var constant=require("./constant.js"),getResonsiveValue=require("./get-resonsive-value.js");const gridToArrayRegex=/[^\s()]+(?:\([^\s()]+(?:\([^()]+\))?(?:, *[^\s()]+(?:\([^()]+\))?)*\))?/g,optionLayoutStyle=e=>{if(!e)return{};let t={};for(let[o,r]of Object.entries(e))Object.assign(t,{[`--gtc${constant.devicesMapping?.[o]}`]:`repeat(${parseFloat(r+"")||1}, minmax(0, 1fr))`});return t},composeGridLayout=e=>{let t=getResonsiveValue.getResponsiveValue(e,"display"),o=("fit"===getResonsiveValue.getResponsiveValueByScreen(t,"desktop")?e?.desktop?.cols?.map(()=>"minmax(0, auto)"):e?.desktop?.cols?.map(e=>`minmax(0, ${e}fr)`))?.join(" "),r=("fit"===getResonsiveValue.getResponsiveValueByScreen(t,"tablet")?e?.tablet?.cols?.map(()=>"minmax(0, auto)"):e?.tablet?.cols?.map(e=>`minmax(0, ${e}fr)`))?.join(" "),a=("fit"===getResonsiveValue.getResponsiveValueByScreen(t,"mobile")?e?.mobile?.cols?.map(()=>"minmax(0, auto)"):e?.mobile?.cols?.map(e=>`minmax(0, ${e}fr)`))?.join(" ");return{"--gtc":o,"--gtc-tablet":r,"--gtc-mobile":a}},gridToArray=e=>e?e.match(gridToArrayRegex)??[]:[],convertOldLayout=e=>{let t=gridToArray(e?.desktop).length,o=gridToArray(e?.tablet).length,r=gridToArray(e?.mobile).length;return{desktop:{cols:t?Array.from({length:t},()=>12/t):void 0,display:"fill"},tablet:{cols:o?Array.from({length:o},()=>12/o):void 0},mobile:{cols:r?Array.from({length:r},()=>12/r):void 0}}};exports.composeGridLayout=composeGridLayout,exports.convertOldLayout=convertOldLayout,exports.gridToArrayRegex=gridToArrayRegex,exports.optionLayoutStyle=optionLayoutStyle;
@@ -1,31 +1 @@
1
- 'use strict';
2
-
3
- const SCRIPTS_LOADED = {};
4
- function loadScript(src, options) {
5
- const isScriptLoaded = SCRIPTS_LOADED[src];
6
- if (isScriptLoaded) {
7
- return isScriptLoaded;
8
- }
9
- const promise = new Promise((resolve, reject)=>{
10
- const script = document.createElement('script');
11
- if (options?.module) {
12
- script.type = 'module';
13
- }
14
- script.src = src;
15
- script.onload = ()=>{
16
- resolve(true);
17
- };
18
- script.onerror = ()=>{
19
- reject(false);
20
- };
21
- if (options?.in === 'head') {
22
- document.head.appendChild(script);
23
- } else {
24
- document.body.appendChild(script);
25
- }
26
- });
27
- SCRIPTS_LOADED[src] = promise;
28
- return promise;
29
- }
30
-
31
- exports.loadScript = loadScript;
1
+ "use strict";const SCRIPTS_LOADED={};function loadScript(e,t){let o=SCRIPTS_LOADED[e];if(o)return o;let d=new Promise((o,d)=>{let r=document.createElement("script");t?.module&&(r.type="module"),r.src=e,r.onload=()=>{o(!0)},r.onerror=()=>{d(!1)},t?.in==="head"?document.head.appendChild(r):document.body.appendChild(r)});return SCRIPTS_LOADED[e]=d,d}exports.loadScript=loadScript;
@@ -1,128 +1 @@
1
- 'use strict';
2
-
3
- var getResonsiveValue = require('./get-resonsive-value.js');
4
-
5
- const removeNullUndefined = (obj)=>Object.entries(obj).reduce((a, [k, v])=>{
6
- if (v === null || v === undefined) return a;
7
- return {
8
- ...a,
9
- [k]: v
10
- };
11
- }, {});
12
- const makeStyleKey = (name)=>{
13
- return [
14
- name,
15
- `hvr-${name}`,
16
- `focus-${name}`,
17
- `${name}-tablet`,
18
- `hvr-${name}-tablet`,
19
- `focus-${name}-tablet`,
20
- `${name}-mobile`,
21
- `hvr-${name}-mobile`,
22
- `focus-${name}-mobile`
23
- ].map((key)=>`--${key}`);
24
- };
25
- const makeStyle = (style)=>{
26
- return removeNullUndefined(Object.fromEntries(Object.entries(style).map(([key, value])=>[
27
- `--${key}`,
28
- value
29
- ])));
30
- };
31
- const makeStyleState = (name, value)=>{
32
- if (!value) return {};
33
- return {
34
- [`--${name}`]: value?.normal,
35
- [`--hvr-${name}`]: value?.hover,
36
- [`--focus-${name}`]: value?.focus
37
- };
38
- };
39
- const makeStyleResponsiveState = (name, value)=>{
40
- if (!value) return {};
41
- return {
42
- [`--${name}`]: value?.desktop?.normal,
43
- [`--hvr-${name}`]: value?.desktop?.hover,
44
- [`--focus-${name}`]: value?.desktop?.focus,
45
- [`--${name}-tablet`]: value?.tablet?.normal,
46
- [`--hvr-${name}-tablet`]: value?.tablet?.hover,
47
- [`--focus-${name}-tablet`]: value?.tablet?.focus,
48
- [`--${name}-mobile`]: value?.mobile?.normal,
49
- [`--hvr-${name}-mobile`]: value?.mobile?.hover,
50
- [`--focus-${name}-mobile`]: value?.mobile?.focus
51
- };
52
- };
53
- const makeStyleResponsive = (name, value)=>{
54
- return {
55
- [`--${name}`]: value?.desktop,
56
- [`--${name}-tablet`]: value?.tablet,
57
- [`--${name}-mobile`]: value?.mobile
58
- };
59
- };
60
- const makeWidth = (widthValue, fullWidthValue)=>{
61
- const getVal = (deviceValue, widthValue, fullWidthValue)=>{
62
- const widthVal = widthValue?.[deviceValue] === undefined ? widthValue?.['desktop'] : widthValue?.[deviceValue];
63
- const fullWidthVal = fullWidthValue?.[deviceValue] === undefined ? fullWidthValue?.['desktop'] : fullWidthValue?.[deviceValue];
64
- if (fullWidthVal) {
65
- return '100%';
66
- } else if (fullWidthVal === false) {
67
- return widthVal ?? widthVal;
68
- } else {
69
- return widthVal || 'auto';
70
- }
71
- };
72
- return {
73
- desktop: getVal('desktop', widthValue, fullWidthValue),
74
- tablet: getVal('tablet', widthValue, fullWidthValue),
75
- mobile: getVal('mobile', widthValue, fullWidthValue)
76
- };
77
- };
78
- const makeHeight = (heighValue, autoHeight)=>{
79
- const getVal = (deviceValue, heighValue, autoHeight)=>{
80
- const heightVal = heighValue?.[deviceValue];
81
- const isAuto = autoHeight?.[deviceValue];
82
- if (isAuto) {
83
- return 'auto';
84
- } else if (isAuto === false) {
85
- return heightVal ?? heightVal;
86
- } else {
87
- return heightVal;
88
- }
89
- };
90
- return {
91
- desktop: getVal('desktop', heighValue, autoHeight),
92
- tablet: getVal('tablet', heighValue, autoHeight),
93
- mobile: getVal('mobile', heighValue, autoHeight)
94
- };
95
- };
96
- const makeAspectRatio = (aspectRatio, aspectWidth, aspectHeight)=>{
97
- return {
98
- desktop: aspectRatio?.desktop === 'custom' ? `${getResonsiveValue.getResponsiveValueByScreen(aspectWidth, 'desktop')}/${getResonsiveValue.getResponsiveValueByScreen(aspectHeight, 'desktop')}` : aspectRatio?.desktop,
99
- tablet: aspectRatio?.tablet === 'custom' ? `${getResonsiveValue.getResponsiveValueByScreen(aspectWidth, 'tablet')}/${getResonsiveValue.getResponsiveValueByScreen(aspectHeight, 'tablet')}` : aspectRatio?.tablet,
100
- mobile: aspectRatio?.mobile === 'custom' ? `${getResonsiveValue.getResponsiveValueByScreen(aspectWidth, 'mobile')}/${getResonsiveValue.getResponsiveValueByScreen(aspectHeight, 'mobile')}` : aspectRatio?.mobile
101
- };
102
- };
103
- const makeLineClamp = (lineClampValue, hasLineClampValue)=>{
104
- const getVal = (deviceValue, lineClampValue, hasLineClampValue)=>{
105
- const lineClamp = lineClampValue?.[deviceValue];
106
- const hasLineClamp = hasLineClampValue?.[deviceValue] || hasLineClampValue?.['desktop'];
107
- if (hasLineClamp || hasLineClamp === undefined) {
108
- return lineClamp;
109
- }
110
- return 'unset';
111
- };
112
- return {
113
- desktop: getVal('desktop', lineClampValue, hasLineClampValue),
114
- tablet: getVal('tablet', lineClampValue, hasLineClampValue),
115
- mobile: getVal('mobile', lineClampValue, hasLineClampValue)
116
- };
117
- };
118
-
119
- exports.makeAspectRatio = makeAspectRatio;
120
- exports.makeHeight = makeHeight;
121
- exports.makeLineClamp = makeLineClamp;
122
- exports.makeStyle = makeStyle;
123
- exports.makeStyleKey = makeStyleKey;
124
- exports.makeStyleResponsive = makeStyleResponsive;
125
- exports.makeStyleResponsiveState = makeStyleResponsiveState;
126
- exports.makeStyleState = makeStyleState;
127
- exports.makeWidth = makeWidth;
128
- exports.removeNullUndefined = removeNullUndefined;
1
+ "use strict";var getResonsiveValue=require("./get-resonsive-value.js");const removeNullUndefined=e=>Object.entries(e).reduce((e,[t,o])=>null==o?e:{...e,[t]:o},{}),makeStyleKey=e=>[e,`hvr-${e}`,`focus-${e}`,`${e}-tablet`,`hvr-${e}-tablet`,`focus-${e}-tablet`,`${e}-mobile`,`hvr-${e}-mobile`,`focus-${e}-mobile`].map(e=>`--${e}`),makeStyle=e=>removeNullUndefined(Object.fromEntries(Object.entries(e).map(([e,t])=>[`--${e}`,t]))),makeStyleState=(e,t)=>t?{[`--${e}`]:t?.normal,[`--hvr-${e}`]:t?.hover,[`--focus-${e}`]:t?.focus}:{},makeStyleResponsiveState=(e,t)=>t?{[`--${e}`]:t?.desktop?.normal,[`--hvr-${e}`]:t?.desktop?.hover,[`--focus-${e}`]:t?.desktop?.focus,[`--${e}-tablet`]:t?.tablet?.normal,[`--hvr-${e}-tablet`]:t?.tablet?.hover,[`--focus-${e}-tablet`]:t?.tablet?.focus,[`--${e}-mobile`]:t?.mobile?.normal,[`--hvr-${e}-mobile`]:t?.mobile?.hover,[`--focus-${e}-mobile`]:t?.mobile?.focus}:{},makeStyleResponsive=(e,t)=>({[`--${e}`]:t?.desktop,[`--${e}-tablet`]:t?.tablet,[`--${e}-mobile`]:t?.mobile}),makeWidth=(e,t)=>{let o=(e,t,o)=>{let l=t?.[e]===void 0?t?.desktop:t?.[e],s=o?.[e]===void 0?o?.desktop:o?.[e];return s?"100%":!1===s?l??l:l||"auto"};return{desktop:o("desktop",e,t),tablet:o("tablet",e,t),mobile:o("mobile",e,t)}},makeGlobalSizeWidthResponsive=e=>({"--w":e?.desktop?.width,"--w-tablet":e?.tablet?.width,"--w-mobile":e?.mobile?.width}),makeHeight=(e,t)=>{let o=(e,t,o)=>{let l=t?.[e],s=o?.[e];return s?"auto":!1===s?l??l:l};return{desktop:o("desktop",e,t),tablet:o("tablet",e,t),mobile:o("mobile",e,t)}},makeAspectRatio=(e,t,o)=>{let l={},s=["desktop","mobile","tablet"];return s.forEach(s=>{let a=getResonsiveValue.getResponsiveValueByScreen(e,s);"none"!==a&&(l={...l,[s]:"custom"!==a?a:`${getResonsiveValue.getResponsiveValueByScreen(t,"desktop")}/${getResonsiveValue.getResponsiveValueByScreen(o,"desktop")}`})}),l},makeLineClamp=(e,t)=>{let o=(e,t,o)=>{let l=t?.[e],s=o?.[e]||o?.desktop;return s||void 0===s?l:"unset"};return{desktop:o("desktop",e,t),tablet:o("tablet",e,t),mobile:o("mobile",e,t)}};exports.makeAspectRatio=makeAspectRatio,exports.makeGlobalSizeWidthResponsive=makeGlobalSizeWidthResponsive,exports.makeHeight=makeHeight,exports.makeLineClamp=makeLineClamp,exports.makeStyle=makeStyle,exports.makeStyleKey=makeStyleKey,exports.makeStyleResponsive=makeStyleResponsive,exports.makeStyleResponsiveState=makeStyleResponsiveState,exports.makeStyleState=makeStyleState,exports.makeWidth=makeWidth,exports.removeNullUndefined=removeNullUndefined;
@@ -1,23 +1 @@
1
- 'use strict';
2
-
3
- function normalizeBuilderData(data) {
4
- const result = {};
5
- function compose(data, res = {}) {
6
- const childrens = data.childrens;
7
- const items = childrens?.map((child)=>child.uid) ?? [];
8
- res[data.uid] = {
9
- ...data,
10
- childrens: items,
11
- type: 'component'
12
- };
13
- if (childrens) {
14
- childrens.map((child)=>compose(child, res));
15
- }
16
- }
17
- compose(data, result);
18
- return {
19
- ...result
20
- };
21
- }
22
-
23
- exports.normalizeBuilderData = normalizeBuilderData;
1
+ "use strict";function normalizeBuilderData(e){let i={};return!function e(i,t={}){let n=i.childrens,r=n?.map(e=>e.uid)??[];t[i.uid]={...i,childrens:r,type:"component"},n&&n.map(i=>e(i,t))}(e,i),{...i}}exports.normalizeBuilderData=normalizeBuilderData;
@@ -1,78 +1 @@
1
- 'use strict';
2
-
3
- var useSWR = require('swr');
4
- var getCollection = require('./queries/get-collection.js');
5
- var getProduct = require('./queries/get-product.js');
6
- var getProducts = require('./queries/get-products.js');
7
- var query = require('./query.js');
8
-
9
- const prefetchQueries = (input, options)=>{
10
- const queries = [];
11
- Object.keys(input).forEach((key)=>{
12
- const item = input[key];
13
- let data = undefined;
14
- switch(item.tag){
15
- case 'Product':
16
- {
17
- if (item.settings?.isAuto) break;
18
- const variables = {
19
- id: item.settings?.productSetting?.productId ?? 'latest',
20
- isSample: options?.isSample,
21
- isStorefront: options?.isStorefront
22
- };
23
- data = {
24
- key: useSWR.unstable_serialize(query.generateProductQueryKey(variables)),
25
- func: getProduct.getProduct,
26
- variables
27
- };
28
- break;
29
- }
30
- case 'ProductList':
31
- {
32
- const productSetting = item.settings?.productSetting;
33
- if (productSetting?.productSrc === 'Collection') {
34
- const variables = {
35
- id: productSetting?.collectionId ?? 'latest',
36
- numberOfProducts: item.settings?.numberOfProducts ?? 4,
37
- orderBy: item.settings?.orderBy,
38
- isSample: options?.isSample,
39
- isStorefront: options?.isStorefront
40
- };
41
- data = {
42
- key: useSWR.unstable_serialize(query.generateCollectionQueryKey(variables)),
43
- func: getCollection.getCollection,
44
- variables
45
- };
46
- } else {
47
- const variables = {
48
- ids: [
49
- ...productSetting?.productIds ?? []
50
- ].sort(),
51
- isSample: options?.isSample,
52
- isStorefront: options?.isStorefront
53
- };
54
- data = {
55
- key: useSWR.unstable_serialize(query.generateProductsQueryKey(variables)),
56
- func: getProducts.getProducts,
57
- variables
58
- };
59
- }
60
- break;
61
- }
62
- }
63
- if (data) {
64
- queries.push(data);
65
- }
66
- });
67
- return queries.reduce((accumulator, current)=>{
68
- if (!accumulator.some((x)=>x.key === current.key)) {
69
- return [
70
- ...accumulator,
71
- current
72
- ];
73
- }
74
- return accumulator;
75
- }, []);
76
- };
77
-
78
- exports.prefetchQueries = prefetchQueries;
1
+ "use strict";var useSWR=require("swr"),getCollection=require("./queries/get-collection.js"),getProduct=require("./queries/get-product.js"),getProducts=require("./queries/get-products.js"),query=require("./query.js");const prefetchQueries=(e,t)=>{let r=[];return Object.keys(e).forEach(s=>{let u;let o=e[s];switch(o.tag){case"Product":{if(o.settings?.isAuto)break;let e={id:o.settings?.productSetting?.productId??"latest",isSample:t?.isSample,isStorefront:t?.isStorefront};u={key:useSWR.unstable_serialize(query.generateProductQueryKey(e)),func:getProduct.getProduct,variables:e};break}case"ProductList":{let e=o.settings?.productSetting;if(e?.productSrc==="Collection"){let r={id:e?.collectionId??"latest",numberOfProducts:o.settings?.numberOfProducts??4,orderBy:o.settings?.orderBy,isSample:t?.isSample,isStorefront:t?.isStorefront};u={key:useSWR.unstable_serialize(query.generateCollectionQueryKey(r)),func:getCollection.getCollection,variables:r}}else{let r={ids:[...e?.productIds??[]].sort(),isSample:t?.isSample,isStorefront:t?.isStorefront};u={key:useSWR.unstable_serialize(query.generateProductsQueryKey(r)),func:getProducts.getProducts,variables:r}}}}u&&r.push(u)}),r.reduce((e,t)=>e.some(e=>e.key===t.key)?e:[...e,t],[])};exports.prefetchQueries=prefetchQueries;
@@ -1,45 +1 @@
1
- 'use strict';
2
-
3
- var variant = require('./variant.js');
4
-
5
- function getSelectedVariant(variants, choices) {
6
- /**
7
- * Ensure the user has selected all the required options, not just some.
8
- */ if (!variants || !variants.length || !choices || variants[0]?.selectedOptions.length !== Object.keys(choices).length) {
9
- return;
10
- }
11
- return variants.find((variant)=>{
12
- return Object.entries(choices).every(([name, value])=>{
13
- return variant?.selectedOptions.some((option)=>option.name === name && option.value === value);
14
- });
15
- });
16
- }
17
- function parseSelectedOption(options) {
18
- if (!options || options && options.length === 0) {
19
- return;
20
- }
21
- return options.reduce((acc, { name, value })=>{
22
- if (name && value) {
23
- return {
24
- ...acc,
25
- [name]: value
26
- };
27
- }
28
- return acc;
29
- }, {});
30
- }
31
- function checkAvailableVariantInStock(variants, optionId, optionValue) {
32
- return variants ? variants.some((item)=>{
33
- if (item) {
34
- const { selectedOptions } = item;
35
- const opt = selectedOptions?.some((option)=>option?.name === optionId && option.value === optionValue);
36
- const isInStock = variant.checkInStock(item);
37
- return opt && isInStock;
38
- }
39
- return false;
40
- }) : false;
41
- }
42
-
43
- exports.checkAvailableVariantInStock = checkAvailableVariantInStock;
44
- exports.getSelectedVariant = getSelectedVariant;
45
- exports.parseSelectedOption = parseSelectedOption;
1
+ "use strict";var variant=require("./variant.js");function getSelectedVariant(e,t){if(e&&e.length&&t&&e[0]?.selectedOptions.length===Object.keys(t).length)return e.find(e=>Object.entries(t).every(([t,n])=>e?.selectedOptions.some(e=>e.name===t&&e.value===n)))}function parseSelectedOption(e){if(e&&(!e||0!==e.length))return e.reduce((e,{name:t,value:n})=>t&&n?{...e,[t]:n}:e,{})}function checkAvailableVariantInStock(e,t,n){return!!e&&e.some(e=>{if(e){let{selectedOptions:a}=e,r=a?.some(e=>e?.name===t&&e.value===n),c=variant.checkInStock(e);return r&&c}return!1})}exports.checkAvailableVariantInStock=checkAvailableVariantInStock,exports.getSelectedVariant=getSelectedVariant,exports.parseSelectedOption=parseSelectedOption;
@@ -1,220 +1 @@
1
- 'use strict';
2
-
3
- var collectionDetailFilter_generated = require('../../graphql/queries/collection-detail-filter.generated.js');
4
- var productVariants_generated = require('../../graphql/queries/product-variants.generated.js');
5
- var isDefined = require('../is-defined.js');
6
-
7
- const PRODUCT_PER_PAGE = 8; // number of products per page
8
- function productSortedByOrder(key) {
9
- switch(key){
10
- case 'TITLE_ASC':
11
- return {
12
- direction: 'ASC',
13
- field: 'TITLE'
14
- };
15
- case 'TITLE_DESC':
16
- return {
17
- direction: 'DESC',
18
- field: 'TITLE'
19
- };
20
- case 'CREATED_AT_ASC':
21
- return {
22
- direction: 'ASC',
23
- field: 'CREATED_AT'
24
- };
25
- case 'CREATED_AT_DESC':
26
- return {
27
- direction: 'DESC',
28
- field: 'CREATED_AT'
29
- };
30
- case 'none':
31
- default:
32
- return {
33
- direction: 'ASC',
34
- field: 'TITLE'
35
- };
36
- }
37
- }
38
- const getCollection = async (fetcher, arg)=>{
39
- const collections = await loopFetchCollection(fetcher, arg);
40
- if (!collections) {
41
- throw new Error('collections not found');
42
- }
43
- // merge product collection variant
44
- const mergeProducts = await mergeProductCollectionVariant(fetcher, collections, arg.isSample);
45
- return mergeProducts;
46
- };
47
- const fetchCollection = async (fetcher, variables)=>{
48
- return fetcher([
49
- collectionDetailFilter_generated.CollectionDetailFilterDocument,
50
- variables
51
- ]);
52
- };
53
- const calculateFirstProduct = (numberOfProducts, currentPage, productsPerPage)=>{
54
- const remainingProducts = numberOfProducts - productsPerPage * currentPage;
55
- if (numberOfProducts < productsPerPage) return numberOfProducts;
56
- return remainingProducts > 0 ? productsPerPage : productsPerPage + remainingProducts;
57
- };
58
- const chunkArray = (array, size)=>{
59
- const chunked_arr = [];
60
- let index = 0;
61
- while(index < array.length){
62
- chunked_arr.push(array.slice(index, size + index));
63
- index += size;
64
- }
65
- return chunked_arr;
66
- };
67
- const loopFetchCollection = async (fetcher, arg)=>{
68
- let variables; // variables of collection query
69
- let productAfterFetcher; // product after of collection query
70
- let dataCollection; // data of collection query
71
- let hasNextPage; //
72
- let firstCollection;
73
- let currentPage = 1;
74
- if (arg.numberOfProducts) {
75
- const pages = Math.ceil(arg.numberOfProducts / PRODUCT_PER_PAGE);
76
- while(currentPage <= pages && hasNextPage !== false){
77
- variables = {
78
- firstVariant: 1,
79
- firstMedia: 30,
80
- orderBy: {
81
- field: 'PLATFORM_CREATED_AT',
82
- direction: 'DESC'
83
- },
84
- orderByMedia: {
85
- field: 'POSITION',
86
- direction: 'ASC'
87
- },
88
- firstProduct: calculateFirstProduct(arg.numberOfProducts, currentPage, PRODUCT_PER_PAGE),
89
- ...!arg.id || arg.id.toLowerCase() === 'latest' ? {
90
- where: {
91
- hasCollectionProducts: true,
92
- isSample: arg.isSample
93
- }
94
- } : {
95
- where: {
96
- baseID: arg.id
97
- }
98
- },
99
- orderByProduct: productSortedByOrder(arg.orderBy),
100
- whereProduct: {
101
- status: 'ACTIVE',
102
- ...arg.isStorefront && {
103
- isStorefront: arg.isStorefront
104
- },
105
- isSample: arg.isSample
106
- },
107
- ...productAfterFetcher ? {
108
- productsAfter: productAfterFetcher
109
- } : undefined
110
- };
111
- const pageData = await fetchCollection(fetcher, variables);
112
- productAfterFetcher = pageData?.collections?.edges?.[0]?.node?.products?.pageInfo?.endCursor;
113
- if (currentPage === 1) {
114
- dataCollection = pageData; // set data of first page
115
- firstCollection = dataCollection?.collections?.edges?.[0];
116
- } else if (firstCollection?.node?.products && pageData?.collections?.edges?.[0]?.node?.products?.edges) {
117
- // concat new values to the old ones
118
- firstCollection.node.products = {
119
- pageInfo: pageData?.collections?.edges?.[0]?.node?.products?.pageInfo,
120
- edges: firstCollection.node?.products?.edges.concat(pageData?.collections?.edges?.[0]?.node?.products?.edges)
121
- };
122
- }
123
- currentPage++;
124
- // hasNextPage = false if there is no more pages then break the loop
125
- if (!firstCollection?.node?.products?.pageInfo?.hasNextPage) {
126
- hasNextPage = false;
127
- break;
128
- }
129
- }
130
- return dataCollection;
131
- }
132
- };
133
- const mergeProductCollectionVariant = async (fetcher, collection, isSample)=>{
134
- const node = collection?.collections?.edges?.[0]?.node;
135
- if (!node) return collection;
136
- const productList = node?.products?.edges;
137
- const listBaseId = productList?.map((product)=>product?.node?.baseID).filter(isDefined.isDefined);
138
- const ProductListWithVariants = await fetchVariantsByBaseIds(fetcher, {
139
- ids: listBaseId,
140
- isSample
141
- });
142
- // mapping variant to product list in collections
143
- const newProductList = productList?.map((product)=>{
144
- const productVariants = ProductListWithVariants?.variants?.edges?.filter((productV)=>productV?.node?.id === product?.node?.id);
145
- return {
146
- ...product,
147
- node: product.node ? {
148
- ...product.node,
149
- variants: product.node?.variants ? {
150
- ...product.node?.variants,
151
- edges: productVariants?.[0]?.node?.variants?.edges ?? []
152
- } : undefined
153
- } : undefined
154
- };
155
- }) ?? [];
156
- const newCollection = {
157
- ...collection,
158
- collections: {
159
- edges: [
160
- {
161
- node: {
162
- ...node,
163
- products: {
164
- edges: newProductList
165
- }
166
- },
167
- cursor: undefined
168
- }
169
- ]
170
- }
171
- };
172
- return newCollection;
173
- };
174
- const fetchVariantsByBaseIds = async (fetcher, { ids, isSample, isStorefront })=>{
175
- const chunkedIds = chunkArray(ids ?? [], 8);
176
- const defaultEdges = [];
177
- const query = async (variables)=>{
178
- try {
179
- return await fetcher([
180
- productVariants_generated.ProductVariantsDocument,
181
- variables
182
- ]);
183
- } catch {
184
- return {};
185
- }
186
- };
187
- const promises = chunkedIds.map((chunkedId)=>{
188
- const variables = {
189
- firstVariant: 100,
190
- first: chunkedId.length,
191
- orderBy: {
192
- field: 'TITLE',
193
- direction: 'ASC'
194
- },
195
- where: {
196
- status: 'ACTIVE',
197
- isSample,
198
- ...isStorefront && {
199
- isStorefront
200
- },
201
- ...chunkedId.length && {
202
- baseIDIn: chunkedId.sort()
203
- }
204
- }
205
- };
206
- return query(variables);
207
- });
208
- const responses = await Promise.all(promises);
209
- const edges = responses?.reduce((acc, response)=>{
210
- return acc.concat(response?.variants?.edges ?? []);
211
- }, defaultEdges);
212
- return {
213
- variants: {
214
- edges
215
- }
216
- };
217
- };
218
-
219
- exports.calculateFirstProduct = calculateFirstProduct;
220
- exports.getCollection = getCollection;
1
+ "use strict";var collectionDetailFilter_generated=require("../../graphql/queries/collection-detail-filter.generated.js"),productVariants_generated=require("../../graphql/queries/product-variants.generated.js"),isDefined=require("../is-defined.js");const PRODUCT_PER_PAGE=8;function productSortedByOrder(e){switch(e){case"TITLE_ASC":case"none":default:return{direction:"ASC",field:"TITLE"};case"TITLE_DESC":return{direction:"DESC",field:"TITLE"};case"CREATED_AT_ASC":return{direction:"ASC",field:"PLATFORM_CREATED_AT"};case"CREATED_AT_DESC":return{direction:"DESC",field:"PLATFORM_CREATED_AT"}}}const getCollection=async(e,t)=>{let r=await loopFetchCollection(e,t);if(!r)throw Error("collections not found");let o=await mergeProductCollectionVariant(e,r,t.isSample);return o},fetchCollection=async(e,t)=>e([collectionDetailFilter_generated.CollectionDetailFilterDocument,t]),calculateFirstProduct=(e,t,r)=>{let o=e-r*t;return e<r?e:o>0?r:r+o},chunkArray=(e,t)=>{let r=[],o=0;for(;o<e.length;)r.push(e.slice(o,t+o)),o+=t;return r},loopFetchCollection=async(e,t)=>{let r,o,i,n,d;let s=1;if(t.numberOfProducts){let a=Math.ceil(t.numberOfProducts/8);for(;s<=a&&!1!==n;){r={firstVariant:1,firstMedia:30,orderBy:{field:"PLATFORM_UPDATED_AT",direction:"DESC"},orderByMedia:{field:"POSITION",direction:"ASC"},firstProduct:calculateFirstProduct(t.numberOfProducts,s,8),...t.id&&"latest"!==t.id.toLowerCase()?{where:{baseID:t.id}}:{where:{isSample:t.isSample}},orderByProduct:productSortedByOrder(t.orderBy),whereProduct:{status:"ACTIVE",...t.isStorefront&&{isStorefront:t.isStorefront},isSample:t.isSample},...o?{productsAfter:o}:void 0};let a=await fetchCollection(e,r);if(o=a?.collections?.edges?.[0]?.node?.products?.pageInfo?.endCursor,1===s?(i=a,d=i?.collections?.edges?.[0]):d?.node?.products&&a?.collections?.edges?.[0]?.node?.products?.edges&&(d.node.products={pageInfo:a?.collections?.edges?.[0]?.node?.products?.pageInfo,edges:d.node?.products?.edges.concat(a?.collections?.edges?.[0]?.node?.products?.edges)}),s++,!d?.node?.products?.pageInfo?.hasNextPage){n=!1;break}}return i}},mergeProductCollectionVariant=async(e,t,r)=>{let o=t?.collections?.edges?.[0]?.node;if(!o)return t;let i=o?.products?.edges,n=i?.map(e=>e?.node?.baseID).filter(isDefined.isDefined),d=await fetchVariantsByBaseIds(e,{ids:n,isSample:r}),s=i?.map(e=>{let t=d?.variants?.edges?.filter(t=>t?.node?.id===e?.node?.id);return{...e,node:e.node?{...e.node,variants:e.node?.variants?{...e.node?.variants,edges:t?.[0]?.node?.variants?.edges??[]}:void 0}:void 0}})??[],a={...t,collections:{edges:[{node:{...o,products:{edges:s}},cursor:void 0}]}};return a},fetchVariantsByBaseIds=async(e,{ids:t,isSample:r,isStorefront:o})=>{let i=chunkArray(t??[],8),n=[],d=async t=>{try{return await e([productVariants_generated.ProductVariantsDocument,t])}catch{return{}}},s=i.map(e=>{let t={firstVariant:100,first:e.length,orderBy:{field:"TITLE",direction:"ASC"},where:{status:"ACTIVE",isSample:r,...o&&{isStorefront:o},...e.length&&{baseIDIn:e.sort()}}};return d(t)}),a=await Promise.all(s),c=a?.reduce((e,t)=>e.concat(t?.variants?.edges??[]),n);return{variants:{edges:c}}};exports.calculateFirstProduct=calculateFirstProduct,exports.getCollection=getCollection;
@@ -1,21 +1 @@
1
- 'use strict';
2
-
3
- var collections_generated = require('../../graphql/queries/collections.generated.js');
4
-
5
- const getCollections = async (fetcher, variable)=>{
6
- const collections = await fetchCollections(fetcher, variable ?? {});
7
- if (!collections) {
8
- throw new Error('Collection not found');
9
- }
10
- return {
11
- ...collections
12
- };
13
- };
14
- const fetchCollections = async (fetcher, variables)=>{
15
- return fetcher([
16
- collections_generated.CollectionsDocument,
17
- variables
18
- ]);
19
- };
20
-
21
- exports.getCollections = getCollections;
1
+ "use strict";var collections_generated=require("../../graphql/queries/collections.generated.js");const getCollections=async(e,t)=>{let o=await fetchCollections(e,t??{});if(!o)throw Error("Collection not found");return{...o}},fetchCollections=async(e,t)=>e([collections_generated.CollectionsDocument,t]);exports.getCollections=getCollections;