@shopify/hydrogen-react 0.0.0-next-5c16c78 → 0.0.0-next-dada720

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 (567) hide show
  1. package/README.md +21 -21
  2. package/dist/browser-dev/AddToCartButton.mjs +43 -40
  3. package/dist/browser-dev/AddToCartButton.mjs.map +1 -1
  4. package/dist/browser-dev/BaseButton.mjs +13 -15
  5. package/dist/browser-dev/BaseButton.mjs.map +1 -1
  6. package/dist/browser-dev/BuyNowButton.mjs +19 -17
  7. package/dist/browser-dev/BuyNowButton.mjs.map +1 -1
  8. package/dist/browser-dev/CartCheckoutButton.mjs +12 -15
  9. package/dist/browser-dev/CartCheckoutButton.mjs.map +1 -1
  10. package/dist/browser-dev/CartCost.mjs +25 -0
  11. package/dist/browser-dev/CartCost.mjs.map +1 -0
  12. package/dist/browser-dev/CartLinePrice.mjs +18 -0
  13. package/dist/browser-dev/CartLinePrice.mjs.map +1 -0
  14. package/dist/browser-dev/CartLineProvider.mjs +19 -0
  15. package/dist/browser-dev/CartLineProvider.mjs.map +1 -0
  16. package/dist/browser-dev/CartProvider.mjs +73 -67
  17. package/dist/browser-dev/CartProvider.mjs.map +1 -1
  18. package/dist/browser-dev/ExternalVideo.mjs +13 -11
  19. package/dist/browser-dev/ExternalVideo.mjs.map +1 -1
  20. package/dist/browser-dev/Image.mjs +41 -30
  21. package/dist/browser-dev/Image.mjs.map +1 -1
  22. package/dist/browser-dev/MediaFile.mjs +29 -21
  23. package/dist/browser-dev/MediaFile.mjs.map +1 -1
  24. package/dist/browser-dev/ModelViewer.mjs +138 -76
  25. package/dist/browser-dev/ModelViewer.mjs.map +1 -1
  26. package/dist/browser-dev/Money.mjs +12 -9
  27. package/dist/browser-dev/Money.mjs.map +1 -1
  28. package/dist/browser-dev/ProductPrice.mjs +12 -17
  29. package/dist/browser-dev/ProductPrice.mjs.map +1 -1
  30. package/dist/browser-dev/ProductProvider.mjs +102 -73
  31. package/dist/browser-dev/ProductProvider.mjs.map +1 -1
  32. package/dist/browser-dev/ShopPayButton.mjs +14 -24
  33. package/dist/browser-dev/ShopPayButton.mjs.map +1 -1
  34. package/dist/browser-dev/ShopifyProvider.mjs +22 -29
  35. package/dist/browser-dev/ShopifyProvider.mjs.map +1 -1
  36. package/dist/browser-dev/Video.mjs +30 -21
  37. package/dist/browser-dev/Video.mjs.map +1 -1
  38. package/dist/browser-dev/_virtual/index.mjs +11 -2
  39. package/dist/browser-dev/_virtual/index.mjs.map +1 -1
  40. package/dist/browser-dev/_virtual/with-selector.mjs +11 -2
  41. package/dist/browser-dev/_virtual/with-selector.mjs.map +1 -1
  42. package/dist/browser-dev/analytics-constants.mjs +43 -0
  43. package/dist/browser-dev/analytics-constants.mjs.map +1 -0
  44. package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
  45. package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
  46. package/dist/browser-dev/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
  47. package/dist/browser-dev/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
  48. package/dist/browser-dev/analytics-utils.mjs +49 -0
  49. package/dist/browser-dev/analytics-utils.mjs.map +1 -0
  50. package/dist/browser-dev/analytics.mjs +159 -0
  51. package/dist/browser-dev/analytics.mjs.map +1 -0
  52. package/dist/browser-dev/cart-hooks.mjs +29 -34
  53. package/dist/browser-dev/cart-hooks.mjs.map +1 -1
  54. package/dist/browser-dev/cart-queries.mjs +50 -20
  55. package/dist/browser-dev/cart-queries.mjs.map +1 -1
  56. package/dist/browser-dev/codegen.helpers.mjs +1 -0
  57. package/dist/browser-dev/codegen.helpers.mjs.map +1 -1
  58. package/dist/browser-dev/cookies-utils.mjs +50 -0
  59. package/dist/browser-dev/cookies-utils.mjs.map +1 -0
  60. package/dist/browser-dev/image-size.mjs +8 -8
  61. package/dist/browser-dev/image-size.mjs.map +1 -1
  62. package/dist/browser-dev/index.mjs +20 -2
  63. package/dist/browser-dev/index.mjs.map +1 -1
  64. package/dist/browser-dev/load-script.mjs.map +1 -1
  65. package/dist/browser-dev/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
  66. package/dist/browser-dev/node_modules/@xstate/react/es/fsm.mjs +2 -2
  67. package/dist/browser-dev/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
  68. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -1
  69. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -1
  70. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -1
  71. package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -1
  72. package/dist/browser-dev/node_modules/use-sync-external-store/shim/index.mjs +3 -3
  73. package/dist/browser-dev/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
  74. package/dist/browser-dev/parse-metafield.mjs +4 -5
  75. package/dist/browser-dev/parse-metafield.mjs.map +1 -1
  76. package/dist/browser-dev/storefront-client.mjs +19 -20
  77. package/dist/browser-dev/storefront-client.mjs.map +1 -1
  78. package/dist/browser-dev/useCartAPIStateMachine.mjs +111 -80
  79. package/dist/browser-dev/useCartAPIStateMachine.mjs.map +1 -1
  80. package/dist/browser-dev/useCartActions.mjs +150 -109
  81. package/dist/browser-dev/useCartActions.mjs.map +1 -1
  82. package/dist/browser-dev/useMoney.mjs +62 -36
  83. package/dist/browser-dev/useMoney.mjs.map +1 -1
  84. package/dist/browser-dev/useShopifyCookies.mjs +41 -0
  85. package/dist/browser-dev/useShopifyCookies.mjs.map +1 -0
  86. package/dist/browser-prod/AddToCartButton.mjs +43 -40
  87. package/dist/browser-prod/AddToCartButton.mjs.map +1 -1
  88. package/dist/browser-prod/BaseButton.mjs +13 -15
  89. package/dist/browser-prod/BaseButton.mjs.map +1 -1
  90. package/dist/browser-prod/BuyNowButton.mjs +19 -17
  91. package/dist/browser-prod/BuyNowButton.mjs.map +1 -1
  92. package/dist/browser-prod/CartCheckoutButton.mjs +12 -15
  93. package/dist/browser-prod/CartCheckoutButton.mjs.map +1 -1
  94. package/dist/browser-prod/CartCost.mjs +25 -0
  95. package/dist/browser-prod/CartCost.mjs.map +1 -0
  96. package/dist/browser-prod/CartLinePrice.mjs +18 -0
  97. package/dist/browser-prod/CartLinePrice.mjs.map +1 -0
  98. package/dist/browser-prod/CartLineProvider.mjs +19 -0
  99. package/dist/browser-prod/CartLineProvider.mjs.map +1 -0
  100. package/dist/browser-prod/CartProvider.mjs +73 -67
  101. package/dist/browser-prod/CartProvider.mjs.map +1 -1
  102. package/dist/browser-prod/ExternalVideo.mjs +13 -11
  103. package/dist/browser-prod/ExternalVideo.mjs.map +1 -1
  104. package/dist/browser-prod/Image.mjs +35 -28
  105. package/dist/browser-prod/Image.mjs.map +1 -1
  106. package/dist/browser-prod/MediaFile.mjs +29 -21
  107. package/dist/browser-prod/MediaFile.mjs.map +1 -1
  108. package/dist/browser-prod/ModelViewer.mjs +135 -75
  109. package/dist/browser-prod/ModelViewer.mjs.map +1 -1
  110. package/dist/browser-prod/Money.mjs +12 -9
  111. package/dist/browser-prod/Money.mjs.map +1 -1
  112. package/dist/browser-prod/ProductPrice.mjs +12 -17
  113. package/dist/browser-prod/ProductPrice.mjs.map +1 -1
  114. package/dist/browser-prod/ProductProvider.mjs +102 -73
  115. package/dist/browser-prod/ProductProvider.mjs.map +1 -1
  116. package/dist/browser-prod/ShopPayButton.mjs +14 -24
  117. package/dist/browser-prod/ShopPayButton.mjs.map +1 -1
  118. package/dist/browser-prod/ShopifyProvider.mjs +22 -26
  119. package/dist/browser-prod/ShopifyProvider.mjs.map +1 -1
  120. package/dist/browser-prod/Video.mjs +30 -21
  121. package/dist/browser-prod/Video.mjs.map +1 -1
  122. package/dist/browser-prod/_virtual/index.mjs +11 -2
  123. package/dist/browser-prod/_virtual/index.mjs.map +1 -1
  124. package/dist/browser-prod/_virtual/with-selector.mjs +11 -2
  125. package/dist/browser-prod/_virtual/with-selector.mjs.map +1 -1
  126. package/dist/browser-prod/analytics-constants.mjs +43 -0
  127. package/dist/browser-prod/analytics-constants.mjs.map +1 -0
  128. package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
  129. package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
  130. package/dist/browser-prod/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
  131. package/dist/browser-prod/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
  132. package/dist/browser-prod/analytics-utils.mjs +49 -0
  133. package/dist/browser-prod/analytics-utils.mjs.map +1 -0
  134. package/dist/browser-prod/analytics.mjs +158 -0
  135. package/dist/browser-prod/analytics.mjs.map +1 -0
  136. package/dist/browser-prod/cart-hooks.mjs +29 -34
  137. package/dist/browser-prod/cart-hooks.mjs.map +1 -1
  138. package/dist/browser-prod/cart-queries.mjs +50 -20
  139. package/dist/browser-prod/cart-queries.mjs.map +1 -1
  140. package/dist/browser-prod/codegen.helpers.mjs +1 -0
  141. package/dist/browser-prod/codegen.helpers.mjs.map +1 -1
  142. package/dist/browser-prod/cookies-utils.mjs +50 -0
  143. package/dist/browser-prod/cookies-utils.mjs.map +1 -0
  144. package/dist/browser-prod/image-size.mjs +8 -8
  145. package/dist/browser-prod/image-size.mjs.map +1 -1
  146. package/dist/browser-prod/index.mjs +20 -2
  147. package/dist/browser-prod/index.mjs.map +1 -1
  148. package/dist/browser-prod/load-script.mjs.map +1 -1
  149. package/dist/browser-prod/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
  150. package/dist/browser-prod/node_modules/@xstate/react/es/fsm.mjs +2 -2
  151. package/dist/browser-prod/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
  152. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -1
  153. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -1
  154. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -1
  155. package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -1
  156. package/dist/browser-prod/node_modules/use-sync-external-store/shim/index.mjs +3 -3
  157. package/dist/browser-prod/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
  158. package/dist/browser-prod/parse-metafield.mjs +4 -5
  159. package/dist/browser-prod/parse-metafield.mjs.map +1 -1
  160. package/dist/browser-prod/storefront-client.mjs +19 -20
  161. package/dist/browser-prod/storefront-client.mjs.map +1 -1
  162. package/dist/browser-prod/useCartAPIStateMachine.mjs +111 -80
  163. package/dist/browser-prod/useCartAPIStateMachine.mjs.map +1 -1
  164. package/dist/browser-prod/useCartActions.mjs +150 -109
  165. package/dist/browser-prod/useCartActions.mjs.map +1 -1
  166. package/dist/browser-prod/useMoney.mjs +62 -36
  167. package/dist/browser-prod/useMoney.mjs.map +1 -1
  168. package/dist/browser-prod/useShopifyCookies.mjs +41 -0
  169. package/dist/browser-prod/useShopifyCookies.mjs.map +1 -0
  170. package/dist/node-dev/AddToCartButton.js +44 -41
  171. package/dist/node-dev/AddToCartButton.js.map +1 -1
  172. package/dist/node-dev/AddToCartButton.mjs +43 -40
  173. package/dist/node-dev/AddToCartButton.mjs.map +1 -1
  174. package/dist/node-dev/BaseButton.js +14 -16
  175. package/dist/node-dev/BaseButton.js.map +1 -1
  176. package/dist/node-dev/BaseButton.mjs +13 -15
  177. package/dist/node-dev/BaseButton.mjs.map +1 -1
  178. package/dist/node-dev/BuyNowButton.js +20 -18
  179. package/dist/node-dev/BuyNowButton.js.map +1 -1
  180. package/dist/node-dev/BuyNowButton.mjs +19 -17
  181. package/dist/node-dev/BuyNowButton.mjs.map +1 -1
  182. package/dist/node-dev/CartCheckoutButton.js +13 -16
  183. package/dist/node-dev/CartCheckoutButton.js.map +1 -1
  184. package/dist/node-dev/CartCheckoutButton.mjs +12 -15
  185. package/dist/node-dev/CartCheckoutButton.mjs.map +1 -1
  186. package/dist/node-dev/CartCost.js +25 -0
  187. package/dist/node-dev/CartCost.js.map +1 -0
  188. package/dist/node-dev/CartCost.mjs +25 -0
  189. package/dist/node-dev/CartCost.mjs.map +1 -0
  190. package/dist/node-dev/CartLinePrice.js +18 -0
  191. package/dist/node-dev/CartLinePrice.js.map +1 -0
  192. package/dist/node-dev/CartLinePrice.mjs +18 -0
  193. package/dist/node-dev/CartLinePrice.mjs.map +1 -0
  194. package/dist/node-dev/CartLineProvider.js +19 -0
  195. package/dist/node-dev/CartLineProvider.js.map +1 -0
  196. package/dist/node-dev/CartLineProvider.mjs +19 -0
  197. package/dist/node-dev/CartLineProvider.mjs.map +1 -0
  198. package/dist/node-dev/CartProvider.js +74 -68
  199. package/dist/node-dev/CartProvider.js.map +1 -1
  200. package/dist/node-dev/CartProvider.mjs +73 -67
  201. package/dist/node-dev/CartProvider.mjs.map +1 -1
  202. package/dist/node-dev/ExternalVideo.js +14 -12
  203. package/dist/node-dev/ExternalVideo.js.map +1 -1
  204. package/dist/node-dev/ExternalVideo.mjs +13 -11
  205. package/dist/node-dev/ExternalVideo.mjs.map +1 -1
  206. package/dist/node-dev/Image.js +42 -31
  207. package/dist/node-dev/Image.js.map +1 -1
  208. package/dist/node-dev/Image.mjs +41 -30
  209. package/dist/node-dev/Image.mjs.map +1 -1
  210. package/dist/node-dev/MediaFile.js +30 -22
  211. package/dist/node-dev/MediaFile.js.map +1 -1
  212. package/dist/node-dev/MediaFile.mjs +29 -21
  213. package/dist/node-dev/MediaFile.mjs.map +1 -1
  214. package/dist/node-dev/ModelViewer.js +139 -77
  215. package/dist/node-dev/ModelViewer.js.map +1 -1
  216. package/dist/node-dev/ModelViewer.mjs +138 -76
  217. package/dist/node-dev/ModelViewer.mjs.map +1 -1
  218. package/dist/node-dev/Money.js +13 -10
  219. package/dist/node-dev/Money.js.map +1 -1
  220. package/dist/node-dev/Money.mjs +12 -9
  221. package/dist/node-dev/Money.mjs.map +1 -1
  222. package/dist/node-dev/ProductPrice.js +13 -18
  223. package/dist/node-dev/ProductPrice.js.map +1 -1
  224. package/dist/node-dev/ProductPrice.mjs +12 -17
  225. package/dist/node-dev/ProductPrice.mjs.map +1 -1
  226. package/dist/node-dev/ProductProvider.js +103 -74
  227. package/dist/node-dev/ProductProvider.js.map +1 -1
  228. package/dist/node-dev/ProductProvider.mjs +102 -73
  229. package/dist/node-dev/ProductProvider.mjs.map +1 -1
  230. package/dist/node-dev/ShopPayButton.js +14 -24
  231. package/dist/node-dev/ShopPayButton.js.map +1 -1
  232. package/dist/node-dev/ShopPayButton.mjs +14 -24
  233. package/dist/node-dev/ShopPayButton.mjs.map +1 -1
  234. package/dist/node-dev/ShopifyProvider.js +23 -30
  235. package/dist/node-dev/ShopifyProvider.js.map +1 -1
  236. package/dist/node-dev/ShopifyProvider.mjs +22 -29
  237. package/dist/node-dev/ShopifyProvider.mjs.map +1 -1
  238. package/dist/node-dev/Video.js +31 -22
  239. package/dist/node-dev/Video.js.map +1 -1
  240. package/dist/node-dev/Video.mjs +30 -21
  241. package/dist/node-dev/Video.mjs.map +1 -1
  242. package/dist/node-dev/_virtual/index.js +11 -3
  243. package/dist/node-dev/_virtual/index.js.map +1 -1
  244. package/dist/node-dev/_virtual/index.mjs +11 -2
  245. package/dist/node-dev/_virtual/index.mjs.map +1 -1
  246. package/dist/node-dev/_virtual/use-sync-external-store-shim.development.js +1 -1
  247. package/dist/node-dev/_virtual/use-sync-external-store-shim.production.min.js +1 -1
  248. package/dist/node-dev/_virtual/with-selector.development.js +1 -1
  249. package/dist/node-dev/_virtual/with-selector.js +11 -3
  250. package/dist/node-dev/_virtual/with-selector.js.map +1 -1
  251. package/dist/node-dev/_virtual/with-selector.mjs +11 -2
  252. package/dist/node-dev/_virtual/with-selector.mjs.map +1 -1
  253. package/dist/node-dev/_virtual/with-selector.production.min.js +1 -1
  254. package/dist/node-dev/analytics-constants.js +43 -0
  255. package/dist/node-dev/analytics-constants.js.map +1 -0
  256. package/dist/node-dev/analytics-constants.mjs +43 -0
  257. package/dist/node-dev/analytics-constants.mjs.map +1 -0
  258. package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js +145 -0
  259. package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js.map +1 -0
  260. package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
  261. package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
  262. package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.js +58 -0
  263. package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.js.map +1 -0
  264. package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
  265. package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
  266. package/dist/node-dev/analytics-utils.js +49 -0
  267. package/dist/node-dev/analytics-utils.js.map +1 -0
  268. package/dist/node-dev/analytics-utils.mjs +49 -0
  269. package/dist/node-dev/analytics-utils.mjs.map +1 -0
  270. package/dist/node-dev/analytics.js +159 -0
  271. package/dist/node-dev/analytics.js.map +1 -0
  272. package/dist/node-dev/analytics.mjs +159 -0
  273. package/dist/node-dev/analytics.mjs.map +1 -0
  274. package/dist/node-dev/cart-constants.js +1 -1
  275. package/dist/node-dev/cart-hooks.js +29 -34
  276. package/dist/node-dev/cart-hooks.js.map +1 -1
  277. package/dist/node-dev/cart-hooks.mjs +29 -34
  278. package/dist/node-dev/cart-hooks.mjs.map +1 -1
  279. package/dist/node-dev/cart-queries.js +51 -21
  280. package/dist/node-dev/cart-queries.js.map +1 -1
  281. package/dist/node-dev/cart-queries.mjs +50 -20
  282. package/dist/node-dev/cart-queries.mjs.map +1 -1
  283. package/dist/node-dev/codegen.helpers.js +2 -1
  284. package/dist/node-dev/codegen.helpers.js.map +1 -1
  285. package/dist/node-dev/codegen.helpers.mjs +1 -0
  286. package/dist/node-dev/codegen.helpers.mjs.map +1 -1
  287. package/dist/node-dev/cookies-utils.js +50 -0
  288. package/dist/node-dev/cookies-utils.js.map +1 -0
  289. package/dist/node-dev/cookies-utils.mjs +50 -0
  290. package/dist/node-dev/cookies-utils.mjs.map +1 -0
  291. package/dist/node-dev/flatten-connection.js +1 -1
  292. package/dist/node-dev/image-size.js +9 -9
  293. package/dist/node-dev/image-size.js.map +1 -1
  294. package/dist/node-dev/image-size.mjs +8 -8
  295. package/dist/node-dev/image-size.mjs.map +1 -1
  296. package/dist/node-dev/index.js +21 -3
  297. package/dist/node-dev/index.js.map +1 -1
  298. package/dist/node-dev/index.mjs +20 -2
  299. package/dist/node-dev/index.mjs.map +1 -1
  300. package/dist/node-dev/load-script.js +1 -1
  301. package/dist/node-dev/load-script.js.map +1 -1
  302. package/dist/node-dev/load-script.mjs.map +1 -1
  303. package/dist/node-dev/node_modules/@xstate/fsm/es/index.js +1 -1
  304. package/dist/node-dev/node_modules/@xstate/fsm/es/index.js.map +1 -1
  305. package/dist/node-dev/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
  306. package/dist/node-dev/node_modules/@xstate/react/es/fsm.js +2 -2
  307. package/dist/node-dev/node_modules/@xstate/react/es/fsm.js.map +1 -1
  308. package/dist/node-dev/node_modules/@xstate/react/es/fsm.mjs +2 -2
  309. package/dist/node-dev/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
  310. package/dist/node-dev/node_modules/@xstate/react/es/useConstant.js +2 -4
  311. package/dist/node-dev/node_modules/@xstate/react/es/useConstant.js.map +1 -1
  312. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +2 -4
  313. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -1
  314. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -1
  315. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +2 -4
  316. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -1
  317. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -1
  318. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +2 -4
  319. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -1
  320. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -1
  321. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +2 -4
  322. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -1
  323. package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -1
  324. package/dist/node-dev/node_modules/use-sync-external-store/shim/index.js +4 -4
  325. package/dist/node-dev/node_modules/use-sync-external-store/shim/index.mjs +3 -3
  326. package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.js +1 -1
  327. package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
  328. package/dist/node-dev/parse-metafield.js +5 -6
  329. package/dist/node-dev/parse-metafield.js.map +1 -1
  330. package/dist/node-dev/parse-metafield.mjs +4 -5
  331. package/dist/node-dev/parse-metafield.mjs.map +1 -1
  332. package/dist/node-dev/storefront-api-constants.js +1 -1
  333. package/dist/node-dev/storefront-client.js +20 -21
  334. package/dist/node-dev/storefront-client.js.map +1 -1
  335. package/dist/node-dev/storefront-client.mjs +19 -20
  336. package/dist/node-dev/storefront-client.mjs.map +1 -1
  337. package/dist/node-dev/useCartAPIStateMachine.js +112 -81
  338. package/dist/node-dev/useCartAPIStateMachine.js.map +1 -1
  339. package/dist/node-dev/useCartAPIStateMachine.mjs +111 -80
  340. package/dist/node-dev/useCartAPIStateMachine.mjs.map +1 -1
  341. package/dist/node-dev/useCartActions.js +151 -110
  342. package/dist/node-dev/useCartActions.js.map +1 -1
  343. package/dist/node-dev/useCartActions.mjs +150 -109
  344. package/dist/node-dev/useCartActions.mjs.map +1 -1
  345. package/dist/node-dev/useMoney.js +63 -37
  346. package/dist/node-dev/useMoney.js.map +1 -1
  347. package/dist/node-dev/useMoney.mjs +62 -36
  348. package/dist/node-dev/useMoney.mjs.map +1 -1
  349. package/dist/node-dev/useShopifyCookies.js +41 -0
  350. package/dist/node-dev/useShopifyCookies.js.map +1 -0
  351. package/dist/node-dev/useShopifyCookies.mjs +41 -0
  352. package/dist/node-dev/useShopifyCookies.mjs.map +1 -0
  353. package/dist/node-prod/AddToCartButton.js +44 -41
  354. package/dist/node-prod/AddToCartButton.js.map +1 -1
  355. package/dist/node-prod/AddToCartButton.mjs +43 -40
  356. package/dist/node-prod/AddToCartButton.mjs.map +1 -1
  357. package/dist/node-prod/BaseButton.js +14 -16
  358. package/dist/node-prod/BaseButton.js.map +1 -1
  359. package/dist/node-prod/BaseButton.mjs +13 -15
  360. package/dist/node-prod/BaseButton.mjs.map +1 -1
  361. package/dist/node-prod/BuyNowButton.js +20 -18
  362. package/dist/node-prod/BuyNowButton.js.map +1 -1
  363. package/dist/node-prod/BuyNowButton.mjs +19 -17
  364. package/dist/node-prod/BuyNowButton.mjs.map +1 -1
  365. package/dist/node-prod/CartCheckoutButton.js +13 -16
  366. package/dist/node-prod/CartCheckoutButton.js.map +1 -1
  367. package/dist/node-prod/CartCheckoutButton.mjs +12 -15
  368. package/dist/node-prod/CartCheckoutButton.mjs.map +1 -1
  369. package/dist/node-prod/CartCost.js +25 -0
  370. package/dist/node-prod/CartCost.js.map +1 -0
  371. package/dist/node-prod/CartCost.mjs +25 -0
  372. package/dist/node-prod/CartCost.mjs.map +1 -0
  373. package/dist/node-prod/CartLinePrice.js +18 -0
  374. package/dist/node-prod/CartLinePrice.js.map +1 -0
  375. package/dist/node-prod/CartLinePrice.mjs +18 -0
  376. package/dist/node-prod/CartLinePrice.mjs.map +1 -0
  377. package/dist/node-prod/CartLineProvider.js +19 -0
  378. package/dist/node-prod/CartLineProvider.js.map +1 -0
  379. package/dist/node-prod/CartLineProvider.mjs +19 -0
  380. package/dist/node-prod/CartLineProvider.mjs.map +1 -0
  381. package/dist/node-prod/CartProvider.js +74 -68
  382. package/dist/node-prod/CartProvider.js.map +1 -1
  383. package/dist/node-prod/CartProvider.mjs +73 -67
  384. package/dist/node-prod/CartProvider.mjs.map +1 -1
  385. package/dist/node-prod/ExternalVideo.js +14 -12
  386. package/dist/node-prod/ExternalVideo.js.map +1 -1
  387. package/dist/node-prod/ExternalVideo.mjs +13 -11
  388. package/dist/node-prod/ExternalVideo.mjs.map +1 -1
  389. package/dist/node-prod/Image.js +36 -29
  390. package/dist/node-prod/Image.js.map +1 -1
  391. package/dist/node-prod/Image.mjs +35 -28
  392. package/dist/node-prod/Image.mjs.map +1 -1
  393. package/dist/node-prod/MediaFile.js +30 -22
  394. package/dist/node-prod/MediaFile.js.map +1 -1
  395. package/dist/node-prod/MediaFile.mjs +29 -21
  396. package/dist/node-prod/MediaFile.mjs.map +1 -1
  397. package/dist/node-prod/ModelViewer.js +136 -76
  398. package/dist/node-prod/ModelViewer.js.map +1 -1
  399. package/dist/node-prod/ModelViewer.mjs +135 -75
  400. package/dist/node-prod/ModelViewer.mjs.map +1 -1
  401. package/dist/node-prod/Money.js +13 -10
  402. package/dist/node-prod/Money.js.map +1 -1
  403. package/dist/node-prod/Money.mjs +12 -9
  404. package/dist/node-prod/Money.mjs.map +1 -1
  405. package/dist/node-prod/ProductPrice.js +13 -18
  406. package/dist/node-prod/ProductPrice.js.map +1 -1
  407. package/dist/node-prod/ProductPrice.mjs +12 -17
  408. package/dist/node-prod/ProductPrice.mjs.map +1 -1
  409. package/dist/node-prod/ProductProvider.js +103 -74
  410. package/dist/node-prod/ProductProvider.js.map +1 -1
  411. package/dist/node-prod/ProductProvider.mjs +102 -73
  412. package/dist/node-prod/ProductProvider.mjs.map +1 -1
  413. package/dist/node-prod/ShopPayButton.js +14 -24
  414. package/dist/node-prod/ShopPayButton.js.map +1 -1
  415. package/dist/node-prod/ShopPayButton.mjs +14 -24
  416. package/dist/node-prod/ShopPayButton.mjs.map +1 -1
  417. package/dist/node-prod/ShopifyProvider.js +23 -27
  418. package/dist/node-prod/ShopifyProvider.js.map +1 -1
  419. package/dist/node-prod/ShopifyProvider.mjs +22 -26
  420. package/dist/node-prod/ShopifyProvider.mjs.map +1 -1
  421. package/dist/node-prod/Video.js +31 -22
  422. package/dist/node-prod/Video.js.map +1 -1
  423. package/dist/node-prod/Video.mjs +30 -21
  424. package/dist/node-prod/Video.mjs.map +1 -1
  425. package/dist/node-prod/_virtual/index.js +11 -3
  426. package/dist/node-prod/_virtual/index.js.map +1 -1
  427. package/dist/node-prod/_virtual/index.mjs +11 -2
  428. package/dist/node-prod/_virtual/index.mjs.map +1 -1
  429. package/dist/node-prod/_virtual/use-sync-external-store-shim.development.js +1 -1
  430. package/dist/node-prod/_virtual/use-sync-external-store-shim.production.min.js +1 -1
  431. package/dist/node-prod/_virtual/with-selector.development.js +1 -1
  432. package/dist/node-prod/_virtual/with-selector.js +11 -3
  433. package/dist/node-prod/_virtual/with-selector.js.map +1 -1
  434. package/dist/node-prod/_virtual/with-selector.mjs +11 -2
  435. package/dist/node-prod/_virtual/with-selector.mjs.map +1 -1
  436. package/dist/node-prod/_virtual/with-selector.production.min.js +1 -1
  437. package/dist/node-prod/analytics-constants.js +43 -0
  438. package/dist/node-prod/analytics-constants.js.map +1 -0
  439. package/dist/node-prod/analytics-constants.mjs +43 -0
  440. package/dist/node-prod/analytics-constants.mjs.map +1 -0
  441. package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js +145 -0
  442. package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js.map +1 -0
  443. package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
  444. package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
  445. package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.js +58 -0
  446. package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.js.map +1 -0
  447. package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
  448. package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
  449. package/dist/node-prod/analytics-utils.js +49 -0
  450. package/dist/node-prod/analytics-utils.js.map +1 -0
  451. package/dist/node-prod/analytics-utils.mjs +49 -0
  452. package/dist/node-prod/analytics-utils.mjs.map +1 -0
  453. package/dist/node-prod/analytics.js +158 -0
  454. package/dist/node-prod/analytics.js.map +1 -0
  455. package/dist/node-prod/analytics.mjs +158 -0
  456. package/dist/node-prod/analytics.mjs.map +1 -0
  457. package/dist/node-prod/cart-constants.js +1 -1
  458. package/dist/node-prod/cart-hooks.js +29 -34
  459. package/dist/node-prod/cart-hooks.js.map +1 -1
  460. package/dist/node-prod/cart-hooks.mjs +29 -34
  461. package/dist/node-prod/cart-hooks.mjs.map +1 -1
  462. package/dist/node-prod/cart-queries.js +51 -21
  463. package/dist/node-prod/cart-queries.js.map +1 -1
  464. package/dist/node-prod/cart-queries.mjs +50 -20
  465. package/dist/node-prod/cart-queries.mjs.map +1 -1
  466. package/dist/node-prod/codegen.helpers.js +2 -1
  467. package/dist/node-prod/codegen.helpers.js.map +1 -1
  468. package/dist/node-prod/codegen.helpers.mjs +1 -0
  469. package/dist/node-prod/codegen.helpers.mjs.map +1 -1
  470. package/dist/node-prod/cookies-utils.js +50 -0
  471. package/dist/node-prod/cookies-utils.js.map +1 -0
  472. package/dist/node-prod/cookies-utils.mjs +50 -0
  473. package/dist/node-prod/cookies-utils.mjs.map +1 -0
  474. package/dist/node-prod/flatten-connection.js +1 -1
  475. package/dist/node-prod/image-size.js +9 -9
  476. package/dist/node-prod/image-size.js.map +1 -1
  477. package/dist/node-prod/image-size.mjs +8 -8
  478. package/dist/node-prod/image-size.mjs.map +1 -1
  479. package/dist/node-prod/index.js +21 -3
  480. package/dist/node-prod/index.js.map +1 -1
  481. package/dist/node-prod/index.mjs +20 -2
  482. package/dist/node-prod/index.mjs.map +1 -1
  483. package/dist/node-prod/load-script.js +1 -1
  484. package/dist/node-prod/load-script.js.map +1 -1
  485. package/dist/node-prod/load-script.mjs.map +1 -1
  486. package/dist/node-prod/node_modules/@xstate/fsm/es/index.js +1 -1
  487. package/dist/node-prod/node_modules/@xstate/fsm/es/index.js.map +1 -1
  488. package/dist/node-prod/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
  489. package/dist/node-prod/node_modules/@xstate/react/es/fsm.js +2 -2
  490. package/dist/node-prod/node_modules/@xstate/react/es/fsm.js.map +1 -1
  491. package/dist/node-prod/node_modules/@xstate/react/es/fsm.mjs +2 -2
  492. package/dist/node-prod/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
  493. package/dist/node-prod/node_modules/@xstate/react/es/useConstant.js +2 -4
  494. package/dist/node-prod/node_modules/@xstate/react/es/useConstant.js.map +1 -1
  495. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +2 -4
  496. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -1
  497. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -1
  498. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +2 -4
  499. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -1
  500. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -1
  501. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +2 -4
  502. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -1
  503. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -1
  504. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +2 -4
  505. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -1
  506. package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -1
  507. package/dist/node-prod/node_modules/use-sync-external-store/shim/index.js +4 -4
  508. package/dist/node-prod/node_modules/use-sync-external-store/shim/index.mjs +3 -3
  509. package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.js +1 -1
  510. package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
  511. package/dist/node-prod/parse-metafield.js +5 -6
  512. package/dist/node-prod/parse-metafield.js.map +1 -1
  513. package/dist/node-prod/parse-metafield.mjs +4 -5
  514. package/dist/node-prod/parse-metafield.mjs.map +1 -1
  515. package/dist/node-prod/storefront-api-constants.js +1 -1
  516. package/dist/node-prod/storefront-client.js +20 -21
  517. package/dist/node-prod/storefront-client.js.map +1 -1
  518. package/dist/node-prod/storefront-client.mjs +19 -20
  519. package/dist/node-prod/storefront-client.mjs.map +1 -1
  520. package/dist/node-prod/useCartAPIStateMachine.js +112 -81
  521. package/dist/node-prod/useCartAPIStateMachine.js.map +1 -1
  522. package/dist/node-prod/useCartAPIStateMachine.mjs +111 -80
  523. package/dist/node-prod/useCartAPIStateMachine.mjs.map +1 -1
  524. package/dist/node-prod/useCartActions.js +151 -110
  525. package/dist/node-prod/useCartActions.js.map +1 -1
  526. package/dist/node-prod/useCartActions.mjs +150 -109
  527. package/dist/node-prod/useCartActions.mjs.map +1 -1
  528. package/dist/node-prod/useMoney.js +63 -37
  529. package/dist/node-prod/useMoney.js.map +1 -1
  530. package/dist/node-prod/useMoney.mjs +62 -36
  531. package/dist/node-prod/useMoney.mjs.map +1 -1
  532. package/dist/node-prod/useShopifyCookies.js +41 -0
  533. package/dist/node-prod/useShopifyCookies.js.map +1 -0
  534. package/dist/node-prod/useShopifyCookies.mjs +41 -0
  535. package/dist/node-prod/useShopifyCookies.mjs.map +1 -0
  536. package/dist/types/AddToCartButton.d.ts +3 -2
  537. package/dist/types/BuyNowButton.d.ts +7 -3
  538. package/dist/types/CartCheckoutButton.d.ts +6 -5
  539. package/dist/types/CartCost.d.ts +7 -5
  540. package/dist/types/CartLinePrice.d.ts +4 -4
  541. package/dist/types/CartLineProvider.d.ts +8 -6
  542. package/dist/types/CartProvider.d.ts +12 -2
  543. package/dist/types/ExternalVideo.d.ts +1 -2
  544. package/dist/types/Image.d.ts +5 -3
  545. package/dist/types/MediaFile.d.ts +12 -11
  546. package/dist/types/ModelViewer.d.ts +2 -2
  547. package/dist/types/ProductPrice.d.ts +1 -1
  548. package/dist/types/ProductProvider.d.ts +1 -1
  549. package/dist/types/ShopPayButton.d.ts +10 -10
  550. package/dist/types/ShopifyProvider.d.ts +35 -39
  551. package/dist/types/analytics-constants.d.ts +48 -0
  552. package/dist/types/analytics-schema-custom-storefront-customer-tracking.d.ts +3 -0
  553. package/dist/types/analytics-schema-trekkie-storefront-page-view.d.ts +2 -0
  554. package/dist/types/analytics-types.d.ts +108 -0
  555. package/dist/types/analytics-utils.d.ts +36 -0
  556. package/dist/types/analytics.d.ts +9 -0
  557. package/dist/types/cookies-utils.d.ts +4 -0
  558. package/dist/types/index.d.cts +11 -3
  559. package/dist/types/index.d.ts +11 -3
  560. package/dist/types/parse-metafield.d.ts +2 -4
  561. package/dist/types/storefront-client.d.ts +14 -14
  562. package/dist/types/useShopifyCookies.d.ts +14 -0
  563. package/dist/umd/hydrogen-react.dev.js +1625 -979
  564. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  565. package/dist/umd/hydrogen-react.prod.js +18 -16
  566. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  567. package/package.json +24 -19
@@ -1,11 +1,8 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react")) : typeof define === "function" && define.amd ? define(["exports", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.hydrogenreact = {}, global.React));
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react")) : typeof define === "function" && define.amd ? define(["exports", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.storefrontkitreact = {}, global.React));
3
3
  })(this, function(exports2, React) {
4
4
  "use strict";
5
- const _interopDefaultLegacy = (e2) => e2 && typeof e2 === "object" && "default" in e2 ? e2 : { default: e2 };
6
- function _interopNamespace(e2) {
7
- if (e2 && e2.__esModule)
8
- return e2;
5
+ function _interopNamespaceDefault(e2) {
9
6
  const n2 = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
10
7
  if (e2) {
11
8
  for (const k in e2) {
@@ -21,8 +18,7 @@
21
18
  n2.default = e2;
22
19
  return Object.freeze(n2);
23
20
  }
24
- const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
25
- const React__namespace = /* @__PURE__ */ _interopNamespace(React);
21
+ const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
26
22
  /*! *****************************************************************************
27
23
  Copyright (c) Microsoft Corporation.
28
24
 
@@ -144,7 +140,7 @@
144
140
  } };
145
141
  return y;
146
142
  }
147
- var l = function(t2, n2) {
143
+ var l$1 = function(t2, n2) {
148
144
  return t2.actions.forEach(function(e2) {
149
145
  var r2 = e2.exec;
150
146
  return r2 && r2(t2.context, n2);
@@ -152,7 +148,7 @@
152
148
  };
153
149
  function v(t2) {
154
150
  var r2 = t2.initialState, i2 = n.NotStarted, o2 = /* @__PURE__ */ new Set(), c2 = { _machine: t2, send: function(e2) {
155
- i2 === n.Running && (r2 = t2.transition(r2, e2), l(r2, u$1(e2)), o2.forEach(function(t3) {
151
+ i2 === n.Running && (r2 = t2.transition(r2, e2), l$1(r2, u$1(e2)), o2.forEach(function(t3) {
156
152
  return t3(r2);
157
153
  }));
158
154
  }, subscribe: function(t3) {
@@ -165,7 +161,7 @@
165
161
  r2 = { value: u2.value, actions: [], context: u2.context, matches: a(u2.value) };
166
162
  } else
167
163
  r2 = t2.initialState;
168
- return i2 = n.Running, l(r2, e), c2;
164
+ return i2 = n.Running, l$1(r2, e), c2;
169
165
  }, stop: function() {
170
166
  return i2 = n.Stopped, o2.clear(), c2;
171
167
  }, get state() {
@@ -176,9 +172,25 @@
176
172
  return c2;
177
173
  }
178
174
  var index = React.useLayoutEffect;
179
- var withSelector = { exports: {} };
175
+ var withSelectorExports = {};
176
+ var withSelector = {
177
+ get exports() {
178
+ return withSelectorExports;
179
+ },
180
+ set exports(v2) {
181
+ withSelectorExports = v2;
182
+ }
183
+ };
180
184
  var withSelector_production_min = {};
181
- var shim = { exports: {} };
185
+ var shimExports = {};
186
+ var shim = {
187
+ get exports() {
188
+ return shimExports;
189
+ },
190
+ set exports(v2) {
191
+ shimExports = v2;
192
+ }
193
+ };
182
194
  var useSyncExternalStoreShim_production_min = {};
183
195
  /**
184
196
  * @license React
@@ -194,7 +206,7 @@
194
206
  if (hasRequiredUseSyncExternalStoreShim_production_min)
195
207
  return useSyncExternalStoreShim_production_min;
196
208
  hasRequiredUseSyncExternalStoreShim_production_min = 1;
197
- var e2 = React__default.default;
209
+ var e2 = React;
198
210
  function h(a2, b) {
199
211
  return a2 === b && (0 !== a2 || 1 / a2 === 1 / b) || a2 !== a2 && b !== b;
200
212
  }
@@ -252,8 +264,8 @@
252
264
  if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
253
265
  __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
254
266
  }
255
- var React2 = React__default.default;
256
- var ReactSharedInternals = React2.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
267
+ var React$1 = React;
268
+ var ReactSharedInternals = React$1.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
257
269
  function error(format) {
258
270
  {
259
271
  {
@@ -283,13 +295,13 @@
283
295
  return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
284
296
  }
285
297
  var objectIs = typeof Object.is === "function" ? Object.is : is;
286
- var useState = React2.useState, useEffect = React2.useEffect, useLayoutEffect = React2.useLayoutEffect, useDebugValue = React2.useDebugValue;
298
+ var useState = React$1.useState, useEffect = React$1.useEffect, useLayoutEffect = React$1.useLayoutEffect, useDebugValue = React$1.useDebugValue;
287
299
  var didWarnOld18Alpha = false;
288
300
  var didWarnUncachedGetSnapshot = false;
289
301
  function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
290
302
  {
291
303
  if (!didWarnOld18Alpha) {
292
- if (React2.startTransition !== void 0) {
304
+ if (React$1.startTransition !== void 0) {
293
305
  didWarnOld18Alpha = true;
294
306
  error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release.");
295
307
  }
@@ -354,7 +366,7 @@
354
366
  var canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
355
367
  var isServerEnvironment = !canUseDOM;
356
368
  var shim2 = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
357
- var useSyncExternalStore$2 = React2.useSyncExternalStore !== void 0 ? React2.useSyncExternalStore : shim2;
369
+ var useSyncExternalStore$2 = React$1.useSyncExternalStore !== void 0 ? React$1.useSyncExternalStore : shim2;
358
370
  useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
359
371
  if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
360
372
  __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
@@ -366,7 +378,7 @@
366
378
  var hasRequiredShim;
367
379
  function requireShim() {
368
380
  if (hasRequiredShim)
369
- return shim.exports;
381
+ return shimExports;
370
382
  hasRequiredShim = 1;
371
383
  (function(module2) {
372
384
  if (process.env.NODE_ENV === "production") {
@@ -375,7 +387,7 @@
375
387
  module2.exports = requireUseSyncExternalStoreShim_development();
376
388
  }
377
389
  })(shim);
378
- return shim.exports;
390
+ return shimExports;
379
391
  }
380
392
  /**
381
393
  * @license React
@@ -391,7 +403,7 @@
391
403
  if (hasRequiredWithSelector_production_min)
392
404
  return withSelector_production_min;
393
405
  hasRequiredWithSelector_production_min = 1;
394
- var h = React__default.default, n2 = requireShim();
406
+ var h = React, n2 = requireShim();
395
407
  function p(a2, b) {
396
408
  return a2 === b && (0 !== a2 || 1 / a2 === 1 / b) || a2 !== a2 && b !== b;
397
409
  }
@@ -462,14 +474,14 @@
462
474
  if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
463
475
  __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
464
476
  }
465
- var React2 = React__default.default;
477
+ var React$1 = React;
466
478
  var shim2 = requireShim();
467
479
  function is(x, y) {
468
480
  return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
469
481
  }
470
482
  var objectIs = typeof Object.is === "function" ? Object.is : is;
471
483
  var useSyncExternalStore = shim2.useSyncExternalStore;
472
- var useRef = React2.useRef, useEffect = React2.useEffect, useMemo = React2.useMemo, useDebugValue = React2.useDebugValue;
484
+ var useRef = React$1.useRef, useEffect = React$1.useEffect, useMemo = React$1.useMemo, useDebugValue = React$1.useDebugValue;
473
485
  function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual2) {
474
486
  var instRef = useRef(null);
475
487
  var inst;
@@ -635,7 +647,7 @@
635
647
  var unsubscribe = service.subscribe(handleStoreChange).unsubscribe;
636
648
  return unsubscribe;
637
649
  }, [service]);
638
- var storeSnapshot = withSelector.exports.useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);
650
+ var storeSnapshot = withSelectorExports.useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);
639
651
  return [storeSnapshot, service.send, service];
640
652
  }
641
653
  function flattenConnection(connection) {
@@ -665,7 +677,9 @@
665
677
  }
666
678
  return [];
667
679
  }
668
- const CartLineAdd = (cartFragment) => `
680
+ const CartLineAdd = (cartFragment) => (
681
+ /* GraphQL */
682
+ `
669
683
  mutation CartLineAdd(
670
684
  $cartId: ID!
671
685
  $lines: [CartLineInput!]!
@@ -680,8 +694,11 @@
680
694
  }
681
695
 
682
696
  ${cartFragment}
683
- `;
684
- const CartCreate = (cartFragment) => `
697
+ `
698
+ );
699
+ const CartCreate = (cartFragment) => (
700
+ /* GraphQL */
701
+ `
685
702
  mutation CartCreate(
686
703
  $input: CartInput!
687
704
  $numCartLines: Int = 250
@@ -695,8 +712,11 @@
695
712
  }
696
713
 
697
714
  ${cartFragment}
698
- `;
699
- const CartLineRemove = (cartFragment) => `
715
+ `
716
+ );
717
+ const CartLineRemove = (cartFragment) => (
718
+ /* GraphQL */
719
+ `
700
720
  mutation CartLineRemove(
701
721
  $cartId: ID!
702
722
  $lines: [ID!]!
@@ -711,8 +731,11 @@
711
731
  }
712
732
 
713
733
  ${cartFragment}
714
- `;
715
- const CartLineUpdate = (cartFragment) => `
734
+ `
735
+ );
736
+ const CartLineUpdate = (cartFragment) => (
737
+ /* GraphQL */
738
+ `
716
739
  mutation CartLineUpdate(
717
740
  $cartId: ID!
718
741
  $lines: [CartLineUpdateInput!]!
@@ -727,8 +750,11 @@
727
750
  }
728
751
 
729
752
  ${cartFragment}
730
- `;
731
- const CartNoteUpdate = (cartFragment) => `
753
+ `
754
+ );
755
+ const CartNoteUpdate = (cartFragment) => (
756
+ /* GraphQL */
757
+ `
732
758
  mutation CartNoteUpdate(
733
759
  $cartId: ID!
734
760
  $note: String
@@ -743,8 +769,11 @@
743
769
  }
744
770
 
745
771
  ${cartFragment}
746
- `;
747
- const CartBuyerIdentityUpdate = (cartFragment) => `
772
+ `
773
+ );
774
+ const CartBuyerIdentityUpdate = (cartFragment) => (
775
+ /* GraphQL */
776
+ `
748
777
  mutation CartBuyerIdentityUpdate(
749
778
  $cartId: ID!
750
779
  $buyerIdentity: CartBuyerIdentityInput!
@@ -759,8 +788,11 @@
759
788
  }
760
789
 
761
790
  ${cartFragment}
762
- `;
763
- const CartAttributesUpdate = (cartFragment) => `
791
+ `
792
+ );
793
+ const CartAttributesUpdate = (cartFragment) => (
794
+ /* GraphQL */
795
+ `
764
796
  mutation CartAttributesUpdate(
765
797
  $attributes: [AttributeInput!]!
766
798
  $cartId: ID!
@@ -775,8 +807,11 @@
775
807
  }
776
808
 
777
809
  ${cartFragment}
778
- `;
779
- const CartDiscountCodesUpdate = (cartFragment) => `
810
+ `
811
+ );
812
+ const CartDiscountCodesUpdate = (cartFragment) => (
813
+ /* GraphQL */
814
+ `
780
815
  mutation CartDiscountCodesUpdate(
781
816
  $cartId: ID!
782
817
  $discountCodes: [String!]
@@ -791,8 +826,11 @@
791
826
  }
792
827
 
793
828
  ${cartFragment}
794
- `;
795
- const CartQuery = (cartFragment) => `
829
+ `
830
+ );
831
+ const CartQuery = (cartFragment) => (
832
+ /* GraphQL */
833
+ `
796
834
  query CartQuery(
797
835
  $id: ID!
798
836
  $numCartLines: Int = 250
@@ -804,8 +842,11 @@
804
842
  }
805
843
 
806
844
  ${cartFragment}
807
- `;
808
- const defaultCartFragment = `
845
+ `
846
+ );
847
+ const defaultCartFragment = (
848
+ /* GraphQL */
849
+ `
809
850
  fragment CartFragment on Cart {
810
851
  id
811
852
  checkoutUrl
@@ -905,15 +946,9 @@
905
946
  width
906
947
  height
907
948
  }
908
- `;
949
+ `
950
+ );
909
951
  const SFAPI_VERSION = "2023-01";
910
- const warnings = /* @__PURE__ */ new Set();
911
- const warnOnce = (string) => {
912
- if (!warnings.has(string)) {
913
- console.warn(string);
914
- warnings.add(string);
915
- }
916
- };
917
952
  function createStorefrontClient({
918
953
  storeDomain,
919
954
  privateStorefrontToken,
@@ -923,7 +958,7 @@
923
958
  }) {
924
959
  if (storefrontApiVersion !== SFAPI_VERSION) {
925
960
  warnOnce(
926
- `StorefrontClient: The Storefront API version that you're using is different than the version this build of Hydrogen-UI is targeting. You may run into unexpected errors if these versions don't match. Received verion: "${storefrontApiVersion}"; expected version "${SFAPI_VERSION}"`
961
+ `StorefrontClient: The Storefront API version that you're using is different than the version this build of Hydrogen React is targeting. You may run into unexpected errors if these versions don't match. Received verion: "${storefrontApiVersion}"; expected version "${SFAPI_VERSION}"`
927
962
  );
928
963
  }
929
964
  if (!privateStorefrontToken && !globalThis.document) {
@@ -938,15 +973,13 @@
938
973
  }
939
974
  return {
940
975
  getShopifyDomain(overrideProps) {
941
- var _a;
942
- return `https://${(_a = overrideProps == null ? void 0 : overrideProps.storeDomain) != null ? _a : storeDomain}.myshopify.com`;
976
+ return (overrideProps == null ? void 0 : overrideProps.storeDomain) ?? storeDomain;
943
977
  },
944
978
  getStorefrontApiUrl(overrideProps) {
945
- var _a, _b;
946
- return `https://${(_a = overrideProps == null ? void 0 : overrideProps.storeDomain) != null ? _a : storeDomain}.myshopify.com/api/${(_b = overrideProps == null ? void 0 : overrideProps.storefrontApiVersion) != null ? _b : storefrontApiVersion}/graphql.json`;
979
+ const finalDomainUrl = (overrideProps == null ? void 0 : overrideProps.storeDomain) ?? storeDomain;
980
+ return `${finalDomainUrl}${finalDomainUrl.endsWith("/") ? "" : "/"}api/${(overrideProps == null ? void 0 : overrideProps.storefrontApiVersion) ?? storefrontApiVersion}/graphql.json`;
947
981
  },
948
982
  getPrivateTokenHeaders(overrideProps) {
949
- var _a, _b, _c;
950
983
  if (!privateStorefrontToken && !(overrideProps == null ? void 0 : overrideProps.privateStorefrontToken)) {
951
984
  throw new Error(
952
985
  `StorefrontClient: You did not pass in a 'privateStorefrontToken' while using 'getPrivateTokenHeaders()'`
@@ -957,53 +990,55 @@
957
990
  `StorefrontClient: it is recommended to pass in the 'buyerIp' property which improves analytics and data in the admin.`
958
991
  );
959
992
  }
960
- const finalContentType = (_a = overrideProps == null ? void 0 : overrideProps.contentType) != null ? _a : contentType;
993
+ const finalContentType = (overrideProps == null ? void 0 : overrideProps.contentType) ?? contentType;
961
994
  return {
995
+ // default to json
962
996
  "content-type": finalContentType === "graphql" ? "application/graphql" : "application/json",
963
- "X-SDK-Variant": "hydrogen-ui",
997
+ "X-SDK-Variant": "hydrogen-react",
964
998
  "X-SDK-Variant-Source": "react",
965
999
  "X-SDK-Version": storefrontApiVersion,
966
- "Shopify-Storefront-Private-Token": (_c = (_b = overrideProps == null ? void 0 : overrideProps.privateStorefrontToken) != null ? _b : privateStorefrontToken) != null ? _c : "",
1000
+ "Shopify-Storefront-Private-Token": (overrideProps == null ? void 0 : overrideProps.privateStorefrontToken) ?? privateStorefrontToken ?? "",
967
1001
  ...(overrideProps == null ? void 0 : overrideProps.buyerIp) ? { "Shopify-Storefront-Buyer-IP": overrideProps.buyerIp } : {}
968
1002
  };
969
1003
  },
970
1004
  getPublicTokenHeaders(overrideProps) {
971
- var _a, _b, _c, _d;
972
1005
  if (!publicStorefrontToken && !(overrideProps == null ? void 0 : overrideProps.publicStorefrontToken)) {
973
1006
  throw new Error(
974
1007
  `StorefrontClient: You did not pass in a 'publicStorefrontToken' while using 'getPublicTokenHeaders()'`
975
1008
  );
976
1009
  }
977
- const finalContentType = (_b = (_a = overrideProps == null ? void 0 : overrideProps.contentType) != null ? _a : contentType) != null ? _b : "json";
1010
+ const finalContentType = (overrideProps == null ? void 0 : overrideProps.contentType) ?? contentType ?? "json";
978
1011
  return getPublicTokenHeadersRaw(
979
1012
  finalContentType,
980
1013
  storefrontApiVersion,
981
- (_d = (_c = overrideProps == null ? void 0 : overrideProps.publicStorefrontToken) != null ? _c : publicStorefrontToken) != null ? _d : ""
1014
+ (overrideProps == null ? void 0 : overrideProps.publicStorefrontToken) ?? publicStorefrontToken ?? ""
982
1015
  );
983
1016
  }
984
1017
  };
985
1018
  }
986
1019
  function getPublicTokenHeadersRaw(contentType, storefrontApiVersion, accessToken) {
987
1020
  return {
1021
+ // default to json
988
1022
  "content-type": contentType === "graphql" ? "application/graphql" : "application/json",
989
- "X-SDK-Variant": "hydrogen-ui",
1023
+ "X-SDK-Variant": "hydrogen-react",
990
1024
  "X-SDK-Variant-Source": "react",
991
1025
  "X-SDK-Version": storefrontApiVersion,
992
1026
  "X-Shopify-Storefront-Access-Token": accessToken
993
1027
  };
994
1028
  }
995
- var _jsxFileName$e = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopifyProvider.tsx";
1029
+ const warnings = /* @__PURE__ */ new Set();
1030
+ const warnOnce = (string) => {
1031
+ if (!warnings.has(string)) {
1032
+ console.warn(string);
1033
+ warnings.add(string);
1034
+ }
1035
+ };
996
1036
  const ShopifyContext = React.createContext({
997
1037
  storeDomain: "test",
998
1038
  storefrontToken: "abc123",
999
1039
  storefrontApiVersion: SFAPI_VERSION,
1000
- country: {
1001
- isoCode: "US"
1002
- },
1003
- language: {
1004
- isoCode: "EN"
1005
- },
1006
- locale: "EN-US",
1040
+ countryIsoCode: "US",
1041
+ languageIsoCode: "EN",
1007
1042
  getStorefrontApiUrl() {
1008
1043
  return "";
1009
1044
  },
@@ -1016,48 +1051,41 @@
1016
1051
  });
1017
1052
  function ShopifyProvider({
1018
1053
  children,
1019
- shopifyConfig
1054
+ ...shopifyConfig
1020
1055
  }) {
1021
- if (!shopifyConfig) {
1022
- throw new Error(`The 'shopifyConfig' prop must be passed to '<ShopifyProvider/>'`);
1056
+ if (!shopifyConfig.countryIsoCode || !shopifyConfig.languageIsoCode || !shopifyConfig.storeDomain || !shopifyConfig.storefrontToken || !shopifyConfig.storefrontApiVersion) {
1057
+ throw new Error(
1058
+ `Please provide the necessary props to '<ShopifyProvider/>'`
1059
+ );
1023
1060
  }
1024
1061
  if (shopifyConfig.storefrontApiVersion !== SFAPI_VERSION) {
1025
- console.warn(`<ShopifyProvider/>: This version of Hydrogen-UI is built for Shopify's Storefront API version ${SFAPI_VERSION}, but it looks like you're using version ${shopifyConfig.storefrontApiVersion}. There may be issues or bugs if you use a mismatched version of Hydrogen-UI and the Storefront API.`);
1062
+ console.warn(
1063
+ `<ShopifyProvider/>: This version of Hydrogen React is built for Shopify's Storefront API version ${SFAPI_VERSION}, but it looks like you're using version ${shopifyConfig.storefrontApiVersion}. There may be issues or bugs if you use a mismatched version of Hydrogen React and the Storefront API.`
1064
+ );
1026
1065
  }
1027
1066
  const finalConfig = React.useMemo(() => {
1028
1067
  function getShopifyDomain(overrideProps) {
1029
- var _a;
1030
- return (_a = overrideProps == null ? void 0 : overrideProps.storeDomain) != null ? _a : shopifyConfig.storeDomain;
1068
+ return (overrideProps == null ? void 0 : overrideProps.storeDomain) ?? shopifyConfig.storeDomain;
1031
1069
  }
1032
1070
  return {
1033
1071
  ...shopifyConfig,
1034
1072
  getPublicTokenHeaders(overrideProps) {
1035
- var _a;
1036
- return getPublicTokenHeadersRaw(overrideProps.contentType, shopifyConfig.storefrontApiVersion, (_a = overrideProps.storefrontToken) != null ? _a : shopifyConfig.storefrontToken);
1073
+ return getPublicTokenHeadersRaw(
1074
+ overrideProps.contentType,
1075
+ shopifyConfig.storefrontApiVersion,
1076
+ overrideProps.storefrontToken ?? shopifyConfig.storefrontToken
1077
+ );
1037
1078
  },
1038
1079
  getShopifyDomain,
1039
1080
  getStorefrontApiUrl(overrideProps) {
1040
- var _a, _b, _c;
1041
- if ((_a = overrideProps == null ? void 0 : overrideProps.storeDomain) == null ? void 0 : _a.includes(".myshopify.com")) {
1042
- {
1043
- console.warn(`<ShopifyProvider/>: passing a 'storeDomain' prop that includes '.myshopify.com' will be unsupported in the future. Passing only the subdomain (for example, if the URL is 'test.myshopify.com', passing in 'test') will be the supported way going forward.`);
1044
- }
1045
- }
1046
- return `${getShopifyDomain({
1047
- storeDomain: (_b = overrideProps == null ? void 0 : overrideProps.storeDomain) != null ? _b : shopifyConfig.storeDomain
1048
- })}/api/${(_c = overrideProps == null ? void 0 : overrideProps.storefrontApiVersion) != null ? _c : shopifyConfig.storefrontApiVersion}/graphql.json`;
1081
+ const finalDomainUrl = getShopifyDomain({
1082
+ storeDomain: (overrideProps == null ? void 0 : overrideProps.storeDomain) ?? shopifyConfig.storeDomain
1083
+ });
1084
+ return `${finalDomainUrl}${finalDomainUrl.endsWith("/") ? "" : "/"}api/${(overrideProps == null ? void 0 : overrideProps.storefrontApiVersion) ?? shopifyConfig.storefrontApiVersion}/graphql.json`;
1049
1085
  }
1050
1086
  };
1051
1087
  }, [shopifyConfig]);
1052
- return /* @__PURE__ */ React__default.default.createElement(ShopifyContext.Provider, {
1053
- value: finalConfig,
1054
- __self: this,
1055
- __source: {
1056
- fileName: _jsxFileName$e,
1057
- lineNumber: 84,
1058
- columnNumber: 5
1059
- }
1060
- }, children);
1088
+ return /* @__PURE__ */ React.createElement(ShopifyContext.Provider, { value: finalConfig }, children);
1061
1089
  }
1062
1090
  function useShop() {
1063
1091
  const shopContext = React.useContext(ShopifyContext);
@@ -1095,41 +1123,82 @@
1095
1123
  (s2 = t2.trim().toLowerCase()) && (s2 === "httponly" || s2 === "secure") && (r2[s2] = true);
1096
1124
  return r2;
1097
1125
  }
1126
+ function l(a2, r2, e2 = {}) {
1127
+ let t2 = a2 + "=" + encodeURIComponent(r2);
1128
+ return e2.expires && (t2 += "; Expires=" + new Date(e2.expires).toUTCString()), e2.maxage != null && e2.maxage >= 0 && (t2 += "; Max-Age=" + (e2.maxage | 0)), e2.domain && (t2 += "; Domain=" + e2.domain), e2.path && (t2 += "; Path=" + e2.path), e2.samesite && (t2 += "; SameSite=" + e2.samesite), (e2.secure || e2.samesite === "None") && (t2 += "; Secure"), e2.httponly && (t2 += "; HttpOnly"), t2;
1129
+ }
1130
+ const tokenHash = "xxxx-4xxx-xxxx-xxxxxxxxxxxx";
1131
+ function buildUUID() {
1132
+ let hash = "";
1133
+ try {
1134
+ const crypto = window.crypto;
1135
+ const randomValuesArray = new Uint16Array(31);
1136
+ crypto.getRandomValues(randomValuesArray);
1137
+ let i2 = 0;
1138
+ hash = tokenHash.replace(/[x]/g, (c2) => {
1139
+ const r2 = randomValuesArray[i2] % 16;
1140
+ const v2 = c2 === "x" ? r2 : r2 & 3 | 8;
1141
+ i2++;
1142
+ return v2.toString(16);
1143
+ }).toUpperCase();
1144
+ } catch (err) {
1145
+ hash = tokenHash.replace(/[x]/g, (c2) => {
1146
+ const r2 = Math.random() * 16 | 0;
1147
+ const v2 = c2 === "x" ? r2 : r2 & 3 | 8;
1148
+ return v2.toString(16);
1149
+ }).toUpperCase();
1150
+ }
1151
+ return `${hexTime()}-${hash}`;
1152
+ }
1153
+ function hexTime() {
1154
+ let dateNumber = 0;
1155
+ let perfNumber = 0;
1156
+ dateNumber = new Date().getTime() >>> 0;
1157
+ try {
1158
+ perfNumber = performance.now() >>> 0;
1159
+ } catch (err) {
1160
+ perfNumber = 0;
1161
+ }
1162
+ const output = Math.abs(dateNumber + perfNumber).toString(16).toLowerCase();
1163
+ return output.padStart(8 - output.length, "0");
1164
+ }
1165
+ function getShopifyCookies(cookies) {
1166
+ const cookieData = u(cookies);
1167
+ return {
1168
+ [SHOPIFY_Y]: cookieData[SHOPIFY_Y] || "",
1169
+ [SHOPIFY_S]: cookieData[SHOPIFY_S] || ""
1170
+ };
1171
+ }
1098
1172
  function useCartFetch() {
1099
- const {
1100
- storefrontId,
1101
- getPublicTokenHeaders,
1102
- getStorefrontApiUrl
1103
- } = useShop();
1104
- return React.useCallback(({
1105
- query,
1106
- variables
1107
- }) => {
1108
- const headers = getPublicTokenHeaders({
1109
- contentType: "json"
1110
- });
1111
- if (storefrontId) {
1112
- headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;
1113
- }
1114
- const cookieData = u(document.cookie);
1115
- if (cookieData[SHOPIFY_Y] && cookieData[SHOPIFY_S]) {
1173
+ const { storefrontId, getPublicTokenHeaders, getStorefrontApiUrl } = useShop();
1174
+ return React.useCallback(
1175
+ ({
1176
+ query,
1177
+ variables
1178
+ }) => {
1179
+ const headers = getPublicTokenHeaders({ contentType: "json" });
1180
+ if (storefrontId) {
1181
+ headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;
1182
+ }
1183
+ const cookieData = getShopifyCookies(document.cookie);
1116
1184
  headers[SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[SHOPIFY_Y];
1117
1185
  headers[SHOPIFY_STOREFRONT_S_HEADER] = cookieData[SHOPIFY_S];
1118
- }
1119
- return fetch(getStorefrontApiUrl(), {
1120
- method: "POST",
1121
- headers,
1122
- body: JSON.stringify({
1123
- query: query.toString(),
1124
- variables
1125
- })
1126
- }).then((res) => res.json()).catch((error) => {
1127
- return {
1128
- data: void 0,
1129
- errors: error.toString()
1130
- };
1131
- });
1132
- }, [getPublicTokenHeaders, storefrontId, getStorefrontApiUrl]);
1186
+ return fetch(getStorefrontApiUrl(), {
1187
+ method: "POST",
1188
+ headers,
1189
+ body: JSON.stringify({
1190
+ query: query.toString(),
1191
+ variables
1192
+ })
1193
+ }).then((res) => res.json()).catch((error) => {
1194
+ return {
1195
+ data: void 0,
1196
+ errors: error.toString()
1197
+ };
1198
+ });
1199
+ },
1200
+ [getPublicTokenHeaders, storefrontId, getStorefrontApiUrl]
1201
+ );
1133
1202
  }
1134
1203
  function useCartActions({
1135
1204
  numCartLines,
@@ -1137,155 +1206,212 @@
1137
1206
  countryCode = "US"
1138
1207
  }) {
1139
1208
  const fetchCart = useCartFetch();
1140
- const cartFetch = React.useCallback((cartId) => {
1141
- return fetchCart({
1142
- query: CartQuery(cartFragment),
1143
- variables: {
1144
- id: cartId,
1145
- numCartLines,
1146
- country: countryCode
1147
- }
1148
- });
1149
- }, [fetchCart, cartFragment, numCartLines, countryCode]);
1150
- const cartCreate = React.useCallback((cart) => {
1151
- return fetchCart({
1152
- query: CartCreate(cartFragment),
1153
- variables: {
1154
- input: cart,
1155
- numCartLines,
1156
- country: countryCode
1157
- }
1158
- });
1159
- }, [cartFragment, countryCode, fetchCart, numCartLines]);
1160
- const cartLineAdd = React.useCallback((cartId, lines) => {
1161
- return fetchCart({
1162
- query: CartLineAdd(cartFragment),
1163
- variables: {
1164
- cartId,
1165
- lines,
1166
- numCartLines,
1167
- country: countryCode
1168
- }
1169
- });
1170
- }, [cartFragment, countryCode, fetchCart, numCartLines]);
1171
- const cartLineUpdate = React.useCallback((cartId, lines) => {
1172
- return fetchCart({
1173
- query: CartLineUpdate(cartFragment),
1174
- variables: {
1175
- cartId,
1176
- lines,
1177
- numCartLines,
1178
- country: countryCode
1179
- }
1180
- });
1181
- }, [cartFragment, countryCode, fetchCart, numCartLines]);
1182
- const cartLineRemove = React.useCallback((cartId, lines) => {
1183
- return fetchCart({
1184
- query: CartLineRemove(cartFragment),
1185
- variables: {
1186
- cartId,
1187
- lines,
1188
- numCartLines,
1189
- country: countryCode
1190
- }
1191
- });
1192
- }, [cartFragment, countryCode, fetchCart, numCartLines]);
1193
- const noteUpdate = React.useCallback((cartId, note) => {
1194
- return fetchCart({
1195
- query: CartNoteUpdate(cartFragment),
1196
- variables: {
1197
- cartId,
1198
- note,
1199
- numCartLines,
1200
- country: countryCode
1201
- }
1202
- });
1203
- }, [fetchCart, cartFragment, numCartLines, countryCode]);
1204
- const buyerIdentityUpdate = React.useCallback((cartId, buyerIdentity) => {
1205
- return fetchCart({
1206
- query: CartBuyerIdentityUpdate(cartFragment),
1207
- variables: {
1208
- cartId,
1209
- buyerIdentity,
1210
- numCartLines,
1211
- country: countryCode
1212
- }
1213
- });
1214
- }, [cartFragment, countryCode, fetchCart, numCartLines]);
1215
- const cartAttributesUpdate = React.useCallback((cartId, attributes) => {
1216
- return fetchCart({
1217
- query: CartAttributesUpdate(cartFragment),
1218
- variables: {
1219
- cartId,
1220
- attributes,
1221
- numCartLines,
1222
- country: countryCode
1223
- }
1224
- });
1225
- }, [cartFragment, countryCode, fetchCart, numCartLines]);
1226
- const discountCodesUpdate = React.useCallback((cartId, discountCodes) => {
1227
- return fetchCart({
1228
- query: CartDiscountCodesUpdate(cartFragment),
1229
- variables: {
1230
- cartId,
1231
- discountCodes,
1232
- numCartLines,
1233
- country: countryCode
1234
- }
1235
- });
1236
- }, [cartFragment, countryCode, fetchCart, numCartLines]);
1237
- return React.useMemo(() => ({
1238
- cartFetch,
1239
- cartCreate,
1240
- cartLineAdd,
1241
- cartLineUpdate,
1242
- cartLineRemove,
1243
- noteUpdate,
1244
- buyerIdentityUpdate,
1245
- cartAttributesUpdate,
1246
- discountCodesUpdate,
1247
- cartFragment
1248
- }), [cartFetch, cartCreate, cartLineAdd, cartLineUpdate, cartLineRemove, noteUpdate, buyerIdentityUpdate, cartAttributesUpdate, discountCodesUpdate, cartFragment]);
1209
+ const cartFetch = React.useCallback(
1210
+ (cartId) => {
1211
+ return fetchCart({
1212
+ query: CartQuery(cartFragment),
1213
+ variables: {
1214
+ id: cartId,
1215
+ numCartLines,
1216
+ country: countryCode
1217
+ }
1218
+ });
1219
+ },
1220
+ [fetchCart, cartFragment, numCartLines, countryCode]
1221
+ );
1222
+ const cartCreate = React.useCallback(
1223
+ (cart) => {
1224
+ return fetchCart({
1225
+ query: CartCreate(cartFragment),
1226
+ variables: {
1227
+ input: cart,
1228
+ numCartLines,
1229
+ country: countryCode
1230
+ }
1231
+ });
1232
+ },
1233
+ [cartFragment, countryCode, fetchCart, numCartLines]
1234
+ );
1235
+ const cartLineAdd = React.useCallback(
1236
+ (cartId, lines) => {
1237
+ return fetchCart({
1238
+ query: CartLineAdd(cartFragment),
1239
+ variables: {
1240
+ cartId,
1241
+ lines,
1242
+ numCartLines,
1243
+ country: countryCode
1244
+ }
1245
+ });
1246
+ },
1247
+ [cartFragment, countryCode, fetchCart, numCartLines]
1248
+ );
1249
+ const cartLineUpdate = React.useCallback(
1250
+ (cartId, lines) => {
1251
+ return fetchCart({
1252
+ query: CartLineUpdate(cartFragment),
1253
+ variables: {
1254
+ cartId,
1255
+ lines,
1256
+ numCartLines,
1257
+ country: countryCode
1258
+ }
1259
+ });
1260
+ },
1261
+ [cartFragment, countryCode, fetchCart, numCartLines]
1262
+ );
1263
+ const cartLineRemove = React.useCallback(
1264
+ (cartId, lines) => {
1265
+ return fetchCart({
1266
+ query: CartLineRemove(cartFragment),
1267
+ variables: {
1268
+ cartId,
1269
+ lines,
1270
+ numCartLines,
1271
+ country: countryCode
1272
+ }
1273
+ });
1274
+ },
1275
+ [cartFragment, countryCode, fetchCart, numCartLines]
1276
+ );
1277
+ const noteUpdate = React.useCallback(
1278
+ (cartId, note) => {
1279
+ return fetchCart({
1280
+ query: CartNoteUpdate(cartFragment),
1281
+ variables: {
1282
+ cartId,
1283
+ note,
1284
+ numCartLines,
1285
+ country: countryCode
1286
+ }
1287
+ });
1288
+ },
1289
+ [fetchCart, cartFragment, numCartLines, countryCode]
1290
+ );
1291
+ const buyerIdentityUpdate = React.useCallback(
1292
+ (cartId, buyerIdentity) => {
1293
+ return fetchCart({
1294
+ query: CartBuyerIdentityUpdate(cartFragment),
1295
+ variables: {
1296
+ cartId,
1297
+ buyerIdentity,
1298
+ numCartLines,
1299
+ country: countryCode
1300
+ }
1301
+ });
1302
+ },
1303
+ [cartFragment, countryCode, fetchCart, numCartLines]
1304
+ );
1305
+ const cartAttributesUpdate = React.useCallback(
1306
+ (cartId, attributes) => {
1307
+ return fetchCart({
1308
+ query: CartAttributesUpdate(cartFragment),
1309
+ variables: {
1310
+ cartId,
1311
+ attributes,
1312
+ numCartLines,
1313
+ country: countryCode
1314
+ }
1315
+ });
1316
+ },
1317
+ [cartFragment, countryCode, fetchCart, numCartLines]
1318
+ );
1319
+ const discountCodesUpdate = React.useCallback(
1320
+ (cartId, discountCodes) => {
1321
+ return fetchCart({
1322
+ query: CartDiscountCodesUpdate(cartFragment),
1323
+ variables: {
1324
+ cartId,
1325
+ discountCodes,
1326
+ numCartLines,
1327
+ country: countryCode
1328
+ }
1329
+ });
1330
+ },
1331
+ [cartFragment, countryCode, fetchCart, numCartLines]
1332
+ );
1333
+ return React.useMemo(
1334
+ () => ({
1335
+ cartFetch,
1336
+ cartCreate,
1337
+ cartLineAdd,
1338
+ cartLineUpdate,
1339
+ cartLineRemove,
1340
+ noteUpdate,
1341
+ buyerIdentityUpdate,
1342
+ cartAttributesUpdate,
1343
+ discountCodesUpdate,
1344
+ cartFragment
1345
+ }),
1346
+ [
1347
+ cartFetch,
1348
+ cartCreate,
1349
+ cartLineAdd,
1350
+ cartLineUpdate,
1351
+ cartLineRemove,
1352
+ noteUpdate,
1353
+ buyerIdentityUpdate,
1354
+ cartAttributesUpdate,
1355
+ discountCodesUpdate,
1356
+ cartFragment
1357
+ ]
1358
+ );
1249
1359
  }
1250
1360
  function invokeCart(action, options) {
1251
1361
  return {
1252
- entry: [...(options == null ? void 0 : options.entryActions) || [], i({
1253
- lastValidCart: (context) => context == null ? void 0 : context.cart
1254
- }), "onCartActionEntry", "onCartActionOptimisticUI", action],
1362
+ entry: [
1363
+ ...(options == null ? void 0 : options.entryActions) || [],
1364
+ i({
1365
+ lastValidCart: (context) => context == null ? void 0 : context.cart
1366
+ }),
1367
+ "onCartActionEntry",
1368
+ "onCartActionOptimisticUI",
1369
+ action
1370
+ ],
1255
1371
  on: {
1256
1372
  RESOLVE: {
1257
1373
  target: (options == null ? void 0 : options.resolveTarget) || "idle",
1258
- actions: [i({
1259
- prevCart: (context) => context == null ? void 0 : context.lastValidCart,
1260
- cart: (_, event) => {
1261
- var _a;
1262
- return (_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.cart;
1263
- },
1264
- rawCartResult: (_, event) => {
1265
- var _a;
1266
- return (_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.rawCartResult;
1267
- },
1268
- errors: (_) => void 0
1269
- })]
1374
+ actions: [
1375
+ i({
1376
+ prevCart: (context) => context == null ? void 0 : context.lastValidCart,
1377
+ cart: (_, event) => {
1378
+ var _a;
1379
+ return (_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.cart;
1380
+ },
1381
+ rawCartResult: (_, event) => {
1382
+ var _a;
1383
+ return (_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.rawCartResult;
1384
+ },
1385
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1386
+ errors: (_) => void 0
1387
+ })
1388
+ ]
1270
1389
  },
1271
1390
  ERROR: {
1272
1391
  target: (options == null ? void 0 : options.errorTarget) || "error",
1273
- actions: [i({
1274
- prevCart: (context) => context == null ? void 0 : context.lastValidCart,
1275
- cart: (context) => context == null ? void 0 : context.lastValidCart,
1276
- errors: (_, event) => {
1277
- var _a;
1278
- return (_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.errors;
1279
- }
1280
- })]
1392
+ actions: [
1393
+ i({
1394
+ prevCart: (context) => context == null ? void 0 : context.lastValidCart,
1395
+ cart: (context) => context == null ? void 0 : context.lastValidCart,
1396
+ errors: (_, event) => {
1397
+ var _a;
1398
+ return (_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.errors;
1399
+ }
1400
+ })
1401
+ ]
1281
1402
  },
1282
1403
  CART_COMPLETED: {
1283
1404
  target: "cartCompleted",
1284
1405
  actions: i({
1406
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1285
1407
  prevCart: (_) => void 0,
1408
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1286
1409
  cart: (_) => void 0,
1410
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1287
1411
  lastValidCart: (_) => void 0,
1412
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1288
1413
  rawCartResult: (_) => void 0,
1414
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1289
1415
  errors: (_) => void 0
1290
1416
  })
1291
1417
  }
@@ -1302,10 +1428,12 @@
1302
1428
  },
1303
1429
  CART_SET: {
1304
1430
  target: "idle",
1305
- actions: [i({
1306
- rawCartResult: (_, event) => event.payload.cart,
1307
- cart: (_, event) => cartFromGraphQL(event.payload.cart)
1308
- })]
1431
+ actions: [
1432
+ i({
1433
+ rawCartResult: (_, event) => event.payload.cart,
1434
+ cart: (_, event) => cartFromGraphQL(event.payload.cart)
1435
+ })
1436
+ ]
1309
1437
  }
1310
1438
  };
1311
1439
  const UPDATING_CART_EVENTS = {
@@ -1349,16 +1477,10 @@
1349
1477
  on: INITIALIZING_CART_EVENTS
1350
1478
  },
1351
1479
  idle: {
1352
- on: {
1353
- ...INITIALIZING_CART_EVENTS,
1354
- ...UPDATING_CART_EVENTS
1355
- }
1480
+ on: { ...INITIALIZING_CART_EVENTS, ...UPDATING_CART_EVENTS }
1356
1481
  },
1357
1482
  error: {
1358
- on: {
1359
- ...INITIALIZING_CART_EVENTS,
1360
- ...UPDATING_CART_EVENTS
1361
- }
1483
+ on: { ...INITIALIZING_CART_EVENTS, ...UPDATING_CART_EVENTS }
1362
1484
  },
1363
1485
  cartFetching: invokeCart("cartFetchAction", {
1364
1486
  errorTarget: "initializationError"
@@ -1407,10 +1529,7 @@
1407
1529
  var _a;
1408
1530
  if (event.type !== "CART_FETCH")
1409
1531
  return;
1410
- const {
1411
- data,
1412
- errors
1413
- } = await cartFetch((_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.cartId);
1532
+ const { data, errors } = await cartFetch((_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.cartId);
1414
1533
  const resultEvent = eventFromFetchResult(event, data == null ? void 0 : data.cart, errors);
1415
1534
  send(resultEvent);
1416
1535
  },
@@ -1418,88 +1537,117 @@
1418
1537
  var _a;
1419
1538
  if (event.type !== "CART_CREATE")
1420
1539
  return;
1421
- const {
1422
- data,
1540
+ const { data, errors } = await cartCreate(event == null ? void 0 : event.payload);
1541
+ const resultEvent = eventFromFetchResult(
1542
+ event,
1543
+ (_a = data == null ? void 0 : data.cartCreate) == null ? void 0 : _a.cart,
1423
1544
  errors
1424
- } = await cartCreate(event == null ? void 0 : event.payload);
1425
- const resultEvent = eventFromFetchResult(event, (_a = data == null ? void 0 : data.cartCreate) == null ? void 0 : _a.cart, errors);
1545
+ );
1426
1546
  send(resultEvent);
1427
1547
  },
1428
1548
  cartLineAddAction: async (context, event) => {
1429
1549
  var _a, _b;
1430
1550
  if (event.type !== "CARTLINE_ADD" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
1431
1551
  return;
1432
- const {
1433
- data,
1552
+ const { data, errors } = await cartLineAdd(
1553
+ context.cart.id,
1554
+ event.payload.lines
1555
+ );
1556
+ const resultEvent = eventFromFetchResult(
1557
+ event,
1558
+ (_b = data == null ? void 0 : data.cartLinesAdd) == null ? void 0 : _b.cart,
1434
1559
  errors
1435
- } = await cartLineAdd(context.cart.id, event.payload.lines);
1436
- const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartLinesAdd) == null ? void 0 : _b.cart, errors);
1560
+ );
1437
1561
  send(resultEvent);
1438
1562
  },
1439
1563
  cartLineUpdateAction: async (context, event) => {
1440
1564
  var _a, _b;
1441
1565
  if (event.type !== "CARTLINE_UPDATE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
1442
1566
  return;
1443
- const {
1444
- data,
1567
+ const { data, errors } = await cartLineUpdate(
1568
+ context.cart.id,
1569
+ event.payload.lines
1570
+ );
1571
+ const resultEvent = eventFromFetchResult(
1572
+ event,
1573
+ (_b = data == null ? void 0 : data.cartLinesUpdate) == null ? void 0 : _b.cart,
1445
1574
  errors
1446
- } = await cartLineUpdate(context.cart.id, event.payload.lines);
1447
- const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartLinesUpdate) == null ? void 0 : _b.cart, errors);
1575
+ );
1448
1576
  send(resultEvent);
1449
1577
  },
1450
1578
  cartLineRemoveAction: async (context, event) => {
1451
1579
  var _a, _b;
1452
1580
  if (event.type !== "CARTLINE_REMOVE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
1453
1581
  return;
1454
- const {
1455
- data,
1582
+ const { data, errors } = await cartLineRemove(
1583
+ context.cart.id,
1584
+ event.payload.lines
1585
+ );
1586
+ const resultEvent = eventFromFetchResult(
1587
+ event,
1588
+ (_b = data == null ? void 0 : data.cartLinesRemove) == null ? void 0 : _b.cart,
1456
1589
  errors
1457
- } = await cartLineRemove(context.cart.id, event.payload.lines);
1458
- const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartLinesRemove) == null ? void 0 : _b.cart, errors);
1590
+ );
1459
1591
  send(resultEvent);
1460
1592
  },
1461
1593
  noteUpdateAction: async (context, event) => {
1462
1594
  var _a, _b;
1463
1595
  if (event.type !== "NOTE_UPDATE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
1464
1596
  return;
1465
- const {
1466
- data,
1597
+ const { data, errors } = await noteUpdate(
1598
+ context.cart.id,
1599
+ event.payload.note
1600
+ );
1601
+ const resultEvent = eventFromFetchResult(
1602
+ event,
1603
+ (_b = data == null ? void 0 : data.cartNoteUpdate) == null ? void 0 : _b.cart,
1467
1604
  errors
1468
- } = await noteUpdate(context.cart.id, event.payload.note);
1469
- const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartNoteUpdate) == null ? void 0 : _b.cart, errors);
1605
+ );
1470
1606
  send(resultEvent);
1471
1607
  },
1472
1608
  buyerIdentityUpdateAction: async (context, event) => {
1473
1609
  var _a, _b;
1474
1610
  if (event.type !== "BUYER_IDENTITY_UPDATE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
1475
1611
  return;
1476
- const {
1477
- data,
1612
+ const { data, errors } = await buyerIdentityUpdate(
1613
+ context.cart.id,
1614
+ event.payload.buyerIdentity
1615
+ );
1616
+ const resultEvent = eventFromFetchResult(
1617
+ event,
1618
+ (_b = data == null ? void 0 : data.cartBuyerIdentityUpdate) == null ? void 0 : _b.cart,
1478
1619
  errors
1479
- } = await buyerIdentityUpdate(context.cart.id, event.payload.buyerIdentity);
1480
- const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartBuyerIdentityUpdate) == null ? void 0 : _b.cart, errors);
1620
+ );
1481
1621
  send(resultEvent);
1482
1622
  },
1483
1623
  cartAttributesUpdateAction: async (context, event) => {
1484
1624
  var _a, _b;
1485
1625
  if (event.type !== "CART_ATTRIBUTES_UPDATE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
1486
1626
  return;
1487
- const {
1488
- data,
1627
+ const { data, errors } = await cartAttributesUpdate(
1628
+ context.cart.id,
1629
+ event.payload.attributes
1630
+ );
1631
+ const resultEvent = eventFromFetchResult(
1632
+ event,
1633
+ (_b = data == null ? void 0 : data.cartAttributesUpdate) == null ? void 0 : _b.cart,
1489
1634
  errors
1490
- } = await cartAttributesUpdate(context.cart.id, event.payload.attributes);
1491
- const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartAttributesUpdate) == null ? void 0 : _b.cart, errors);
1635
+ );
1492
1636
  send(resultEvent);
1493
1637
  },
1494
1638
  discountCodesUpdateAction: async (context, event) => {
1495
1639
  var _a, _b;
1496
1640
  if (event.type !== "DISCOUNT_CODES_UPDATE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
1497
1641
  return;
1498
- const {
1499
- data,
1642
+ const { data, errors } = await discountCodesUpdate(
1643
+ context.cart.id,
1644
+ event.payload.discountCodes
1645
+ );
1646
+ const resultEvent = eventFromFetchResult(
1647
+ event,
1648
+ (_b = data == null ? void 0 : data.cartDiscountCodesUpdate) == null ? void 0 : _b.cart,
1500
1649
  errors
1501
- } = await discountCodesUpdate(context.cart.id, event.payload.discountCodes);
1502
- const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartDiscountCodesUpdate) == null ? void 0 : _b.cart, errors);
1650
+ );
1503
1651
  send(resultEvent);
1504
1652
  },
1505
1653
  ...onCartActionEntry && {
@@ -1526,22 +1674,15 @@
1526
1674
  return React.useMemo(() => [state, send, service], [state, send, service]);
1527
1675
  }
1528
1676
  function cartFromGraphQL(cart) {
1529
- var _a;
1530
1677
  return {
1531
1678
  ...cart,
1532
1679
  lines: flattenConnection(cart == null ? void 0 : cart.lines),
1533
- note: (_a = cart.note) != null ? _a : void 0
1680
+ note: cart.note ?? void 0
1534
1681
  };
1535
1682
  }
1536
1683
  function eventFromFetchResult(cartActionEvent, cart, errors) {
1537
1684
  if (errors) {
1538
- return {
1539
- type: "ERROR",
1540
- payload: {
1541
- errors,
1542
- cartActionEvent
1543
- }
1544
- };
1685
+ return { type: "ERROR", payload: { errors, cartActionEvent } };
1545
1686
  }
1546
1687
  if (!cart) {
1547
1688
  return {
@@ -1566,7 +1707,6 @@
1566
1707
  function isCartFetchResultEvent(event) {
1567
1708
  return event.type === "RESOLVE" || event.type === "ERROR" || event.type === "CART_COMPLETED";
1568
1709
  }
1569
- var _jsxFileName$d = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/CartProvider.tsx";
1570
1710
  const CartContext = React.createContext(null);
1571
1711
  function useCart() {
1572
1712
  const context = React.useContext(CartContext);
@@ -1642,16 +1782,16 @@
1642
1782
  onCartActionOptimisticUI(context, event) {
1643
1783
  var _a2, _b2, _c2, _d2;
1644
1784
  if (!context.cart)
1645
- return {
1646
- ...context
1647
- };
1785
+ return { ...context };
1648
1786
  switch (event.type) {
1649
1787
  case "CARTLINE_REMOVE":
1650
1788
  return {
1651
1789
  ...context,
1652
1790
  cart: {
1653
1791
  ...context.cart,
1654
- lines: (_b2 = (_a2 = context == null ? void 0 : context.cart) == null ? void 0 : _a2.lines) == null ? void 0 : _b2.filter((line) => (line == null ? void 0 : line.id) && !event.payload.lines.includes(line == null ? void 0 : line.id))
1792
+ lines: (_b2 = (_a2 = context == null ? void 0 : context.cart) == null ? void 0 : _a2.lines) == null ? void 0 : _b2.filter(
1793
+ (line) => (line == null ? void 0 : line.id) && !event.payload.lines.includes(line == null ? void 0 : line.id)
1794
+ )
1655
1795
  }
1656
1796
  };
1657
1797
  case "CARTLINE_UPDATE":
@@ -1660,9 +1800,9 @@
1660
1800
  cart: {
1661
1801
  ...context.cart,
1662
1802
  lines: (_d2 = (_c2 = context == null ? void 0 : context.cart) == null ? void 0 : _c2.lines) == null ? void 0 : _d2.map((line) => {
1663
- const updatedLine = event.payload.lines.find(({
1664
- id
1665
- }) => id === (line == null ? void 0 : line.id));
1803
+ const updatedLine = event.payload.lines.find(
1804
+ ({ id }) => id === (line == null ? void 0 : line.id)
1805
+ );
1666
1806
  if (updatedLine && updatedLine.quantity) {
1667
1807
  return {
1668
1808
  ...line,
@@ -1674,9 +1814,7 @@
1674
1814
  }
1675
1815
  };
1676
1816
  }
1677
- return {
1678
- ...context
1679
- };
1817
+ return { ...context };
1680
1818
  },
1681
1819
  onCartActionComplete(context, event) {
1682
1820
  const cartActionEvent = event.payload.cartActionEvent;
@@ -1721,12 +1859,7 @@
1721
1859
  try {
1722
1860
  const cartId = window.localStorage.getItem(CART_ID_STORAGE_KEY);
1723
1861
  if (cartId) {
1724
- cartSend({
1725
- type: "CART_FETCH",
1726
- payload: {
1727
- cartId
1728
- }
1729
- });
1862
+ cartSend({ type: "CART_FETCH", payload: { cartId } });
1730
1863
  }
1731
1864
  } catch (error) {
1732
1865
  console.warn("error fetching cartId");
@@ -1741,25 +1874,32 @@
1741
1874
  return;
1742
1875
  cartSend({
1743
1876
  type: "BUYER_IDENTITY_UPDATE",
1744
- payload: {
1745
- buyerIdentity: {
1746
- countryCode,
1747
- customerAccessToken
1748
- }
1749
- }
1877
+ payload: { buyerIdentity: { countryCode, customerAccessToken } }
1750
1878
  });
1751
- }, [countryCode, customerAccessToken, countryChanged, customerOverridesCountryCode, cartSend]);
1752
- const onCartReadySend = React.useCallback((cartEvent) => {
1753
- if (!cartReady.current) {
1754
- return console.warn("Cart isn't ready yet");
1755
- }
1756
- cartSend(cartEvent);
1757
- }, [cartSend]);
1879
+ }, [
1880
+ countryCode,
1881
+ customerAccessToken,
1882
+ countryChanged,
1883
+ customerOverridesCountryCode,
1884
+ cartSend
1885
+ ]);
1886
+ const onCartReadySend = React.useCallback(
1887
+ (cartEvent) => {
1888
+ if (!cartReady.current) {
1889
+ return console.warn("Cart isn't ready yet");
1890
+ }
1891
+ cartSend(cartEvent);
1892
+ },
1893
+ [cartSend]
1894
+ );
1758
1895
  React.useEffect(() => {
1759
1896
  var _a2, _b2, _c2;
1760
1897
  if (((_b2 = (_a2 = cartState == null ? void 0 : cartState.context) == null ? void 0 : _a2.cart) == null ? void 0 : _b2.id) && storageAvailable("localStorage")) {
1761
1898
  try {
1762
- window.localStorage.setItem(CART_ID_STORAGE_KEY, (_c2 = cartState.context.cart) == null ? void 0 : _c2.id);
1899
+ window.localStorage.setItem(
1900
+ CART_ID_STORAGE_KEY,
1901
+ (_c2 = cartState.context.cart) == null ? void 0 : _c2.id
1902
+ );
1763
1903
  } catch (error) {
1764
1904
  console.warn("Failed to save cartId to localStorage", error);
1765
1905
  }
@@ -1774,50 +1914,46 @@
1774
1914
  }
1775
1915
  }
1776
1916
  }, [cartCompleted]);
1777
- const cartCreate = React.useCallback((cartInput) => {
1778
- var _a2, _b2;
1779
- if (countryCode && !((_a2 = cartInput.buyerIdentity) == null ? void 0 : _a2.countryCode)) {
1780
- if (cartInput.buyerIdentity == null) {
1781
- cartInput.buyerIdentity = {};
1917
+ const cartCreate = React.useCallback(
1918
+ (cartInput) => {
1919
+ var _a2, _b2;
1920
+ if (countryCode && !((_a2 = cartInput.buyerIdentity) == null ? void 0 : _a2.countryCode)) {
1921
+ if (cartInput.buyerIdentity == null) {
1922
+ cartInput.buyerIdentity = {};
1923
+ }
1924
+ cartInput.buyerIdentity.countryCode = countryCode;
1782
1925
  }
1783
- cartInput.buyerIdentity.countryCode = countryCode;
1784
- }
1785
- if (customerAccessToken && !((_b2 = cartInput.buyerIdentity) == null ? void 0 : _b2.customerAccessToken)) {
1786
- if (cartInput.buyerIdentity == null) {
1787
- cartInput.buyerIdentity = {};
1926
+ if (customerAccessToken && !((_b2 = cartInput.buyerIdentity) == null ? void 0 : _b2.customerAccessToken)) {
1927
+ if (cartInput.buyerIdentity == null) {
1928
+ cartInput.buyerIdentity = {};
1929
+ }
1930
+ cartInput.buyerIdentity.customerAccessToken = customerAccessToken;
1788
1931
  }
1789
- cartInput.buyerIdentity.customerAccessToken = customerAccessToken;
1790
- }
1791
- onCartReadySend({
1792
- type: "CART_CREATE",
1793
- payload: cartInput
1794
- });
1795
- }, [countryCode, customerAccessToken, onCartReadySend]);
1932
+ onCartReadySend({
1933
+ type: "CART_CREATE",
1934
+ payload: cartInput
1935
+ });
1936
+ },
1937
+ [countryCode, customerAccessToken, onCartReadySend]
1938
+ );
1796
1939
  const cartDisplayState = useDelayedStateUntilHydration(cartState);
1797
1940
  const cartContextValue = React.useMemo(() => {
1798
- var _a2, _b2, _c2, _d2, _e2, _f2;
1941
+ var _a2, _b2, _c2, _d2;
1799
1942
  return {
1800
- ...(_b2 = (_a2 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _a2.cart) != null ? _b2 : {
1801
- lines: [],
1802
- attributes: []
1803
- },
1943
+ ...((_a2 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _a2.cart) ?? { lines: [], attributes: [] },
1804
1944
  status: transposeStatus(cartDisplayState.value),
1805
- error: (_c2 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _c2.errors,
1806
- totalQuantity: (_f2 = (_e2 = (_d2 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _d2.cart) == null ? void 0 : _e2.totalQuantity) != null ? _f2 : 0,
1945
+ error: (_b2 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _b2.errors,
1946
+ totalQuantity: ((_d2 = (_c2 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _c2.cart) == null ? void 0 : _d2.totalQuantity) ?? 0,
1807
1947
  cartCreate,
1808
1948
  linesAdd(lines) {
1809
1949
  var _a3, _b3;
1810
1950
  if ((_b3 = (_a3 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _a3.cart) == null ? void 0 : _b3.id) {
1811
1951
  onCartReadySend({
1812
1952
  type: "CARTLINE_ADD",
1813
- payload: {
1814
- lines
1815
- }
1953
+ payload: { lines }
1816
1954
  });
1817
1955
  } else {
1818
- cartCreate({
1819
- lines
1820
- });
1956
+ cartCreate({ lines });
1821
1957
  }
1822
1958
  },
1823
1959
  linesRemove(lines) {
@@ -1870,16 +2006,15 @@
1870
2006
  },
1871
2007
  cartFragment
1872
2008
  };
1873
- }, [cartCreate, (_f = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _f.cart, (_g = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _g.errors, cartDisplayState.value, cartFragment, onCartReadySend]);
1874
- return /* @__PURE__ */ React__default.default.createElement(CartContext.Provider, {
1875
- value: cartContextValue,
1876
- __self: this,
1877
- __source: {
1878
- fileName: _jsxFileName$d,
1879
- lineNumber: 424,
1880
- columnNumber: 5
1881
- }
1882
- }, children);
2009
+ }, [
2010
+ cartCreate,
2011
+ (_f = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _f.cart,
2012
+ (_g = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _g.errors,
2013
+ cartDisplayState.value,
2014
+ cartFragment,
2015
+ onCartReadySend
2016
+ ]);
2017
+ return /* @__PURE__ */ React.createElement(CartContext.Provider, { value: cartContextValue }, children);
1883
2018
  }
1884
2019
  function transposeStatus(status) {
1885
2020
  switch (status) {
@@ -1934,65 +2069,76 @@
1934
2069
  storage.removeItem(x);
1935
2070
  return true;
1936
2071
  } catch (e2) {
1937
- return e2 instanceof DOMException && (e2.code === 22 || e2.code === 1014 || e2.name === "QuotaExceededError" || e2.name === "NS_ERROR_DOM_QUOTA_REACHED") && storage && storage.length !== 0;
2072
+ return e2 instanceof DOMException && // everything except Firefox
2073
+ (e2.code === 22 || // Firefox
2074
+ e2.code === 1014 || // test name field too, because code might not be present
2075
+ // everything except Firefox
2076
+ e2.name === "QuotaExceededError" || // Firefox
2077
+ e2.name === "NS_ERROR_DOM_QUOTA_REACHED") && // acknowledge QuotaExceededError only if there's something already stored
2078
+ storage && storage.length !== 0;
1938
2079
  }
1939
2080
  }
1940
2081
  function countryCodeNotUpdated(context, event) {
1941
2082
  var _a, _b;
1942
2083
  return event.payload.buyerIdentity.countryCode && ((_b = (_a = context.cart) == null ? void 0 : _a.buyerIdentity) == null ? void 0 : _b.countryCode) !== event.payload.buyerIdentity.countryCode;
1943
2084
  }
1944
- var _jsxFileName$c = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductProvider.tsx";
1945
2085
  const ProductOptionsContext = React.createContext(null);
1946
2086
  function ProductProvider({
1947
2087
  children,
1948
2088
  data: product,
1949
2089
  initialVariantId: explicitVariantId
1950
2090
  }) {
1951
- const variants = React.useMemo(() => {
1952
- var _a;
1953
- return flattenConnection((_a = product.variants) != null ? _a : {});
1954
- }, [product.variants]);
2091
+ const variants = React.useMemo(
2092
+ () => flattenConnection(product.variants ?? {}),
2093
+ [product.variants]
2094
+ );
1955
2095
  if (!isProductVariantArray(variants)) {
1956
- throw new Error(`<ProductProvider/> requires 'product.variants.nodes' or 'product.variants.edges'`);
2096
+ throw new Error(
2097
+ `<ProductProvider/> requires 'product.variants.nodes' or 'product.variants.edges'`
2098
+ );
1957
2099
  }
1958
2100
  const options = React.useMemo(() => getOptions(variants), [variants]);
1959
2101
  const [selectedVariant, setSelectedVariant] = React.useState(() => getVariantBasedOnIdProp(explicitVariantId, variants));
1960
- const [selectedOptions, setSelectedOptions] = React.useState(() => getSelectedOptions(selectedVariant));
2102
+ const [selectedOptions, setSelectedOptions] = React.useState(
2103
+ () => getSelectedOptions(selectedVariant)
2104
+ );
1961
2105
  React.useEffect(() => {
1962
- const newSelectedVariant = getVariantBasedOnIdProp(explicitVariantId, variants);
2106
+ const newSelectedVariant = getVariantBasedOnIdProp(
2107
+ explicitVariantId,
2108
+ variants
2109
+ );
1963
2110
  setSelectedVariant(newSelectedVariant);
1964
2111
  setSelectedOptions(getSelectedOptions(newSelectedVariant));
1965
2112
  }, [explicitVariantId, variants]);
1966
- const setSelectedOption = React.useCallback((name, value2) => {
1967
- setSelectedOptions((selectedOptions2) => {
1968
- const opts = {
1969
- ...selectedOptions2,
1970
- [name]: value2
1971
- };
1972
- setSelectedVariant(getSelectedVariant(variants, opts));
1973
- return opts;
1974
- });
1975
- }, [setSelectedOptions, variants]);
1976
- const isOptionInStock = React.useCallback((option, value2) => {
1977
- var _a;
1978
- const proposedVariant = getSelectedVariant(variants, {
1979
- ...selectedOptions,
1980
- ...{
1981
- [option]: value2
1982
- }
1983
- });
1984
- return (_a = proposedVariant == null ? void 0 : proposedVariant.availableForSale) != null ? _a : true;
1985
- }, [selectedOptions, variants]);
1986
- const sellingPlanGroups = React.useMemo(() => {
1987
- var _a;
1988
- return flattenConnection((_a = product.sellingPlanGroups) != null ? _a : {}).map((sellingPlanGroup) => {
1989
- var _a2;
1990
- return {
2113
+ const setSelectedOption = React.useCallback(
2114
+ (name, value2) => {
2115
+ setSelectedOptions((selectedOptions2) => {
2116
+ const opts = { ...selectedOptions2, [name]: value2 };
2117
+ setSelectedVariant(getSelectedVariant(variants, opts));
2118
+ return opts;
2119
+ });
2120
+ },
2121
+ [setSelectedOptions, variants]
2122
+ );
2123
+ const isOptionInStock = React.useCallback(
2124
+ (option, value2) => {
2125
+ const proposedVariant = getSelectedVariant(variants, {
2126
+ ...selectedOptions,
2127
+ ...{ [option]: value2 }
2128
+ });
2129
+ return (proposedVariant == null ? void 0 : proposedVariant.availableForSale) ?? true;
2130
+ },
2131
+ [selectedOptions, variants]
2132
+ );
2133
+ const sellingPlanGroups = React.useMemo(
2134
+ () => flattenConnection(product.sellingPlanGroups ?? {}).map(
2135
+ (sellingPlanGroup) => ({
1991
2136
  ...sellingPlanGroup,
1992
- sellingPlans: flattenConnection((_a2 = sellingPlanGroup == null ? void 0 : sellingPlanGroup.sellingPlans) != null ? _a2 : {})
1993
- };
1994
- });
1995
- }, [product.sellingPlanGroups]);
2137
+ sellingPlans: flattenConnection((sellingPlanGroup == null ? void 0 : sellingPlanGroup.sellingPlans) ?? {})
2138
+ })
2139
+ ),
2140
+ [product.sellingPlanGroups]
2141
+ );
1996
2142
  const [selectedSellingPlan, setSelectedSellingPlan] = React.useState(void 0);
1997
2143
  const selectedSellingPlanAllocation = React.useMemo(() => {
1998
2144
  var _a, _b;
@@ -2000,38 +2146,49 @@
2000
2146
  return;
2001
2147
  }
2002
2148
  if (!((_a = selectedVariant.sellingPlanAllocations) == null ? void 0 : _a.nodes) && !((_b = selectedVariant.sellingPlanAllocations) == null ? void 0 : _b.edges)) {
2003
- throw new Error(`<ProductProvider/>: You must include 'sellingPlanAllocations.nodes' or 'sellingPlanAllocations.edges' in your variants in order to calculate selectedSellingPlanAllocation`);
2149
+ throw new Error(
2150
+ `<ProductProvider/>: You must include 'sellingPlanAllocations.nodes' or 'sellingPlanAllocations.edges' in your variants in order to calculate selectedSellingPlanAllocation`
2151
+ );
2004
2152
  }
2005
- return flattenConnection(selectedVariant.sellingPlanAllocations).find((allocation) => {
2006
- var _a2;
2007
- return ((_a2 = allocation == null ? void 0 : allocation.sellingPlan) == null ? void 0 : _a2.id) === selectedSellingPlan.id;
2008
- });
2153
+ return flattenConnection(selectedVariant.sellingPlanAllocations).find(
2154
+ (allocation) => {
2155
+ var _a2;
2156
+ return ((_a2 = allocation == null ? void 0 : allocation.sellingPlan) == null ? void 0 : _a2.id) === selectedSellingPlan.id;
2157
+ }
2158
+ );
2009
2159
  }, [selectedVariant, selectedSellingPlan]);
2010
- const value = React.useMemo(() => ({
2011
- variants,
2012
- variantsConnection: product.variants,
2013
- options,
2014
- selectedVariant,
2015
- setSelectedVariant,
2016
- selectedOptions,
2017
- setSelectedOption,
2018
- setSelectedOptions,
2019
- isOptionInStock,
2020
- selectedSellingPlan,
2021
- setSelectedSellingPlan,
2022
- selectedSellingPlanAllocation,
2023
- sellingPlanGroups,
2024
- sellingPlanGroupsConnection: product.sellingPlanGroups
2025
- }), [isOptionInStock, options, product.sellingPlanGroups, product.variants, selectedOptions, selectedSellingPlan, selectedSellingPlanAllocation, selectedVariant, sellingPlanGroups, setSelectedOption, variants]);
2026
- return /* @__PURE__ */ React__default.default.createElement(ProductOptionsContext.Provider, {
2027
- value,
2028
- __self: this,
2029
- __source: {
2030
- fileName: _jsxFileName$c,
2031
- lineNumber: 201,
2032
- columnNumber: 5
2033
- }
2034
- }, children);
2160
+ const value = React.useMemo(
2161
+ () => ({
2162
+ variants,
2163
+ variantsConnection: product.variants,
2164
+ options,
2165
+ selectedVariant,
2166
+ setSelectedVariant,
2167
+ selectedOptions,
2168
+ setSelectedOption,
2169
+ setSelectedOptions,
2170
+ isOptionInStock,
2171
+ selectedSellingPlan,
2172
+ setSelectedSellingPlan,
2173
+ selectedSellingPlanAllocation,
2174
+ sellingPlanGroups,
2175
+ sellingPlanGroupsConnection: product.sellingPlanGroups
2176
+ }),
2177
+ [
2178
+ isOptionInStock,
2179
+ options,
2180
+ product.sellingPlanGroups,
2181
+ product.variants,
2182
+ selectedOptions,
2183
+ selectedSellingPlan,
2184
+ selectedSellingPlanAllocation,
2185
+ selectedVariant,
2186
+ sellingPlanGroups,
2187
+ setSelectedOption,
2188
+ variants
2189
+ ]
2190
+ );
2191
+ return /* @__PURE__ */ React.createElement(ProductOptionsContext.Provider, { value }, children);
2035
2192
  }
2036
2193
  function useProduct() {
2037
2194
  const context = React.useContext(ProductOptionsContext);
@@ -2048,7 +2205,9 @@
2048
2205
  return variants == null ? void 0 : variants.find((variant) => {
2049
2206
  return Object.entries(choices).every(([name, value]) => {
2050
2207
  var _a2;
2051
- return (_a2 = variant == null ? void 0 : variant.selectedOptions) == null ? void 0 : _a2.some((option) => (option == null ? void 0 : option.name) === name && (option == null ? void 0 : option.value) === value);
2208
+ return (_a2 = variant == null ? void 0 : variant.selectedOptions) == null ? void 0 : _a2.some(
2209
+ (option) => (option == null ? void 0 : option.name) === name && (option == null ? void 0 : option.value) === value
2210
+ );
2052
2211
  });
2053
2212
  });
2054
2213
  }
@@ -2059,9 +2218,8 @@
2059
2218
  throw new Error(`'getOptions' requires 'variant.selectedOptions'`);
2060
2219
  }
2061
2220
  (_a = variant == null ? void 0 : variant.selectedOptions) == null ? void 0 : _a.forEach((opt) => {
2062
- var _a2, _b, _c, _d;
2063
- memo[(_a2 = opt == null ? void 0 : opt.name) != null ? _a2 : ""] = memo[(_b = opt == null ? void 0 : opt.name) != null ? _b : ""] || /* @__PURE__ */ new Set();
2064
- memo[(_c = opt == null ? void 0 : opt.name) != null ? _c : ""].add((_d = opt == null ? void 0 : opt.value) != null ? _d : "");
2221
+ memo[(opt == null ? void 0 : opt.name) ?? ""] = memo[(opt == null ? void 0 : opt.name) ?? ""] || /* @__PURE__ */ new Set();
2222
+ memo[(opt == null ? void 0 : opt.name) ?? ""].add((opt == null ? void 0 : opt.value) ?? "");
2065
2223
  });
2066
2224
  return memo;
2067
2225
  }, {});
@@ -2074,9 +2232,13 @@
2074
2232
  }
2075
2233
  function getVariantBasedOnIdProp(explicitVariantId, variants) {
2076
2234
  if (explicitVariantId) {
2077
- const foundVariant = variants.find((variant) => (variant == null ? void 0 : variant.id) === explicitVariantId);
2235
+ const foundVariant = variants.find(
2236
+ (variant) => (variant == null ? void 0 : variant.id) === explicitVariantId
2237
+ );
2078
2238
  if (!foundVariant) {
2079
- console.warn(`<ProductProvider/> received a 'initialVariantId' prop, but could not actually find a variant with that ID`);
2239
+ console.warn(
2240
+ `<ProductProvider/> received a 'initialVariantId' prop, but could not actually find a variant with that ID`
2241
+ );
2080
2242
  }
2081
2243
  return foundVariant;
2082
2244
  }
@@ -2088,11 +2250,13 @@
2088
2250
  }
2089
2251
  }
2090
2252
  function getSelectedOptions(selectedVariant) {
2091
- return (selectedVariant == null ? void 0 : selectedVariant.selectedOptions) ? selectedVariant.selectedOptions.reduce((memo, optionSet) => {
2092
- var _a, _b;
2093
- memo[(_a = optionSet == null ? void 0 : optionSet.name) != null ? _a : ""] = (_b = optionSet == null ? void 0 : optionSet.value) != null ? _b : "";
2094
- return memo;
2095
- }, {}) : {};
2253
+ return (selectedVariant == null ? void 0 : selectedVariant.selectedOptions) ? selectedVariant.selectedOptions.reduce(
2254
+ (memo, optionSet) => {
2255
+ memo[(optionSet == null ? void 0 : optionSet.name) ?? ""] = (optionSet == null ? void 0 : optionSet.value) ?? "";
2256
+ return memo;
2257
+ },
2258
+ {}
2259
+ ) : {};
2096
2260
  }
2097
2261
  function isProductVariantArray(maybeVariantArray) {
2098
2262
  if (!maybeVariantArray || !Array.isArray(maybeVariantArray)) {
@@ -2100,7 +2264,6 @@
2100
2264
  }
2101
2265
  return true;
2102
2266
  }
2103
- var _jsxFileName$b = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/BaseButton.tsx";
2104
2267
  function BaseButton(props) {
2105
2268
  const {
2106
2269
  as,
@@ -2110,30 +2273,21 @@
2110
2273
  buttonRef,
2111
2274
  ...passthroughProps
2112
2275
  } = props;
2113
- const handleOnClick = React.useCallback((event) => {
2114
- if (onClick) {
2115
- const clickShouldContinue = onClick(event);
2116
- if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
2117
- return;
2118
- }
2119
- defaultOnClick == null ? void 0 : defaultOnClick(event);
2120
- }, [defaultOnClick, onClick]);
2276
+ const handleOnClick = React.useCallback(
2277
+ (event) => {
2278
+ if (onClick) {
2279
+ const clickShouldContinue = onClick(event);
2280
+ if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
2281
+ return;
2282
+ }
2283
+ defaultOnClick == null ? void 0 : defaultOnClick(event);
2284
+ },
2285
+ [defaultOnClick, onClick]
2286
+ );
2121
2287
  const Component = as || "button";
2122
- return /* @__PURE__ */ React__default.default.createElement(Component, {
2123
- ref: buttonRef,
2124
- onClick: handleOnClick,
2125
- ...passthroughProps,
2126
- __self: this,
2127
- __source: {
2128
- fileName: _jsxFileName$b,
2129
- lineNumber: 59,
2130
- columnNumber: 5
2131
- }
2132
- }, children);
2133
- }
2134
- var _jsxFileName$a = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/AddToCartButton.tsx";
2288
+ return /* @__PURE__ */ React.createElement(Component, { ref: buttonRef, onClick: handleOnClick, ...passthroughProps }, children);
2289
+ }
2135
2290
  function AddToCartButton(props) {
2136
- var _a;
2137
2291
  const [addingItem, setAddingItem] = React.useState(false);
2138
2292
  const {
2139
2293
  variantId: explicitVariantId,
@@ -2145,14 +2299,9 @@
2145
2299
  accessibleAddingToCartLabel,
2146
2300
  ...passthroughProps
2147
2301
  } = props;
2148
- const {
2149
- status,
2150
- linesAdd
2151
- } = useCart();
2152
- const {
2153
- selectedVariant
2154
- } = useProduct();
2155
- const variantId = (_a = explicitVariantId != null ? explicitVariantId : selectedVariant == null ? void 0 : selectedVariant.id) != null ? _a : "";
2302
+ const { status, linesAdd } = useCart();
2303
+ const { selectedVariant } = useProduct();
2304
+ const variantId = explicitVariantId ?? (selectedVariant == null ? void 0 : selectedVariant.id) ?? "";
2156
2305
  const disabled = explicitVariantId === null || variantId === "" || selectedVariant === null || addingItem || passthroughProps.disabled;
2157
2306
  React.useEffect(() => {
2158
2307
  if (addingItem && status === "idle") {
@@ -2161,61 +2310,469 @@
2161
2310
  }, [status, addingItem]);
2162
2311
  const handleAddItem = React.useCallback(() => {
2163
2312
  setAddingItem(true);
2164
- linesAdd([{
2165
- quantity,
2166
- merchandiseId: variantId || "",
2167
- attributes,
2168
- sellingPlanId
2169
- }]);
2313
+ linesAdd([
2314
+ {
2315
+ quantity,
2316
+ merchandiseId: variantId || "",
2317
+ attributes,
2318
+ sellingPlanId
2319
+ }
2320
+ ]);
2170
2321
  }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);
2171
- return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement(BaseButton, {
2172
- ...passthroughProps,
2173
- disabled,
2174
- onClick,
2175
- defaultOnClick: handleAddItem,
2176
- __self: this,
2177
- __source: {
2178
- fileName: _jsxFileName$a,
2179
- lineNumber: 71,
2180
- columnNumber: 7
2181
- }
2182
- }, children), accessibleAddingToCartLabel ? /* @__PURE__ */ React__default.default.createElement("p", {
2183
- style: {
2184
- position: "absolute",
2185
- width: "1px",
2186
- height: "1px",
2187
- padding: "0",
2188
- margin: "-1px",
2189
- overflow: "hidden",
2190
- clip: "rect(0, 0, 0, 0)",
2191
- whiteSpace: "nowrap",
2192
- borderWidth: "0"
2322
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
2323
+ BaseButton,
2324
+ {
2325
+ ...passthroughProps,
2326
+ disabled,
2327
+ onClick,
2328
+ defaultOnClick: handleAddItem
2329
+ },
2330
+ children
2331
+ ), accessibleAddingToCartLabel ? /* @__PURE__ */ React.createElement(
2332
+ "p",
2333
+ {
2334
+ style: {
2335
+ position: "absolute",
2336
+ width: "1px",
2337
+ height: "1px",
2338
+ padding: "0",
2339
+ margin: "-1px",
2340
+ overflow: "hidden",
2341
+ clip: "rect(0, 0, 0, 0)",
2342
+ whiteSpace: "nowrap",
2343
+ borderWidth: "0"
2344
+ },
2345
+ role: "alert",
2346
+ "aria-live": "assertive"
2193
2347
  },
2194
- role: "alert",
2195
- "aria-live": "assertive",
2196
- __self: this,
2197
- __source: {
2198
- fileName: _jsxFileName$a,
2199
- lineNumber: 80,
2200
- columnNumber: 9
2348
+ addingItem ? accessibleAddingToCartLabel : null
2349
+ ) : null);
2350
+ }
2351
+ const AnalyticsEventName = {
2352
+ PAGE_VIEW: "PAGE_VIEW",
2353
+ ADD_TO_CART: "ADD_TO_CART"
2354
+ };
2355
+ const AnalyticsPageType = {
2356
+ article: "article",
2357
+ blog: "blog",
2358
+ captcha: "captcha",
2359
+ cart: "cart",
2360
+ collection: "collection",
2361
+ customersAccount: "customers/account",
2362
+ customersActivateAccount: "customers/activate_account",
2363
+ customersAddresses: "customers/addresses",
2364
+ customersLogin: "customers/login",
2365
+ customersOrder: "customers/order",
2366
+ customersRegister: "customers/register",
2367
+ customersResetPassword: "customers/reset_password",
2368
+ giftCard: "gift_card",
2369
+ home: "index",
2370
+ listCollections: "list-collections",
2371
+ forbidden: "403",
2372
+ notFound: "404",
2373
+ page: "page",
2374
+ password: "password",
2375
+ product: "product",
2376
+ policy: "policy",
2377
+ search: "search"
2378
+ };
2379
+ const ShopifySalesChannel = {
2380
+ hydrogen: "hydrogen",
2381
+ headless: "headless"
2382
+ };
2383
+ const ShopifyAppId = {
2384
+ hydrogen: "6167201",
2385
+ headless: "12875497473"
2386
+ };
2387
+ function schemaWrapper(schemaId, payload) {
2388
+ return {
2389
+ schema_id: schemaId,
2390
+ payload,
2391
+ metadata: {
2392
+ event_created_at_ms: Date.now()
2201
2393
  }
2202
- }, addingItem ? accessibleAddingToCartLabel : null) : null);
2394
+ };
2203
2395
  }
2204
- var _jsxFileName$9 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/BuyNowButton.tsx";
2205
- function BuyNowButton(props) {
2206
- const {
2207
- cartCreate,
2208
- checkoutUrl
2209
- } = useCart();
2210
- const [loading, setLoading] = React.useState(false);
2211
- const {
2212
- quantity,
2213
- variantId,
2214
- onClick,
2215
- attributes,
2216
- children,
2217
- ...passthroughProps
2218
- } = props;
2396
+ function parseGid(gid) {
2397
+ const defaultReturn = { id: "", resource: null };
2398
+ if (typeof gid !== "string") {
2399
+ return defaultReturn;
2400
+ }
2401
+ const matches = gid.match(/^gid:\/\/shopify\/(\w+)\/([a-z0-9]+)/);
2402
+ if (!matches || matches.length === 1) {
2403
+ return defaultReturn;
2404
+ }
2405
+ const id = matches[2] ?? null;
2406
+ const resource = matches[1] ?? null;
2407
+ return { id, resource };
2408
+ }
2409
+ function addDataIf(keyValuePairs, formattedData) {
2410
+ if (typeof keyValuePairs !== "object") {
2411
+ return {};
2412
+ }
2413
+ Object.entries(keyValuePairs).forEach(([key, value]) => {
2414
+ if (value) {
2415
+ formattedData[key] = value;
2416
+ }
2417
+ });
2418
+ return formattedData;
2419
+ }
2420
+ function errorIfServer(fnName) {
2421
+ if (typeof document === "undefined") {
2422
+ console.error(
2423
+ `${fnName} should only be used within the useEffect callback or event handlers`
2424
+ );
2425
+ return true;
2426
+ }
2427
+ return false;
2428
+ }
2429
+ const SCHEMA_ID$1 = "trekkie_storefront_page_view/1.4";
2430
+ const OXYGEN_DOMAIN = "myshopify.dev";
2431
+ function pageView$1(payload) {
2432
+ const pageViewPayload = payload;
2433
+ const { id, resource } = parseGid(pageViewPayload.resourceId);
2434
+ const resourceType = resource ? resource.toLowerCase() : void 0;
2435
+ return [
2436
+ schemaWrapper(
2437
+ SCHEMA_ID$1,
2438
+ addDataIf(
2439
+ {
2440
+ pageType: pageViewPayload.pageType,
2441
+ customerId: pageViewPayload.customerId,
2442
+ resourceType,
2443
+ resourceId: parseInt(id)
2444
+ },
2445
+ formatPayload$1(pageViewPayload)
2446
+ )
2447
+ )
2448
+ ];
2449
+ }
2450
+ function formatPayload$1(payload) {
2451
+ return {
2452
+ appClientId: payload.shopifySalesChannel ? ShopifyAppId[payload.shopifySalesChannel] : ShopifyAppId.headless,
2453
+ isMerchantRequest: isMerchantRequest(payload.url),
2454
+ hydrogenSubchannelId: payload.storefrontId || "0",
2455
+ isPersistentCookie: payload.hasUserConsent,
2456
+ uniqToken: payload.uniqueToken,
2457
+ visitToken: payload.visitToken,
2458
+ microSessionId: buildUUID(),
2459
+ microSessionCount: 1,
2460
+ url: payload.url,
2461
+ path: payload.path,
2462
+ search: payload.search,
2463
+ referrer: payload.referrer,
2464
+ title: payload.title,
2465
+ shopId: parseInt(parseGid(payload.shopId).id),
2466
+ currency: payload.currency,
2467
+ contentLanguage: payload.acceptedLanguage || "en"
2468
+ };
2469
+ }
2470
+ function isMerchantRequest(url) {
2471
+ if (typeof url !== "string") {
2472
+ return false;
2473
+ }
2474
+ const hostname = new URL(url).hostname;
2475
+ if (hostname.indexOf(OXYGEN_DOMAIN) !== -1 || hostname === "localhost") {
2476
+ return true;
2477
+ }
2478
+ return false;
2479
+ }
2480
+ const SCHEMA_ID = "custom_storefront_customer_tracking/1.0";
2481
+ const PAGE_RENDERED_EVENT_NAME = "page_rendered";
2482
+ const COLLECTION_PAGE_RENDERED_EVENT_NAME = "collection_page_rendered";
2483
+ const PRODUCT_PAGE_RENDERED_EVENT_NAME = "product_page_rendered";
2484
+ const PRODUCT_ADDED_TO_CART_EVENT_NAME = "product_added_to_cart";
2485
+ const SEARCH_SUBMITTED_EVENT_NAME = "search_submitted";
2486
+ function pageView(payload) {
2487
+ const pageViewPayload = payload;
2488
+ const additionalPayload = {
2489
+ canonical_url: pageViewPayload.canonicalUrl || pageViewPayload.url,
2490
+ customer_id: pageViewPayload.customerId
2491
+ };
2492
+ const pageType = pageViewPayload.pageType;
2493
+ const pageViewEvents = [];
2494
+ pageViewEvents.push(
2495
+ schemaWrapper(
2496
+ SCHEMA_ID,
2497
+ addDataIf(
2498
+ {
2499
+ event_name: PAGE_RENDERED_EVENT_NAME,
2500
+ ...additionalPayload
2501
+ },
2502
+ formatPayload(pageViewPayload)
2503
+ )
2504
+ )
2505
+ );
2506
+ switch (pageType) {
2507
+ case AnalyticsPageType.collection:
2508
+ pageViewEvents.push(
2509
+ schemaWrapper(
2510
+ SCHEMA_ID,
2511
+ addDataIf(
2512
+ {
2513
+ event_name: COLLECTION_PAGE_RENDERED_EVENT_NAME,
2514
+ ...additionalPayload,
2515
+ collection_name: pageViewPayload.collectionHandle
2516
+ },
2517
+ formatPayload(pageViewPayload)
2518
+ )
2519
+ )
2520
+ );
2521
+ break;
2522
+ case AnalyticsPageType.product:
2523
+ pageViewEvents.push(
2524
+ schemaWrapper(
2525
+ SCHEMA_ID,
2526
+ addDataIf(
2527
+ {
2528
+ event_name: PRODUCT_PAGE_RENDERED_EVENT_NAME,
2529
+ ...additionalPayload,
2530
+ products: formatProductPayload(pageViewPayload.products),
2531
+ total_value: pageViewPayload.totalValue
2532
+ },
2533
+ formatPayload(pageViewPayload)
2534
+ )
2535
+ )
2536
+ );
2537
+ break;
2538
+ case AnalyticsPageType.search:
2539
+ pageViewEvents.push(
2540
+ schemaWrapper(
2541
+ SCHEMA_ID,
2542
+ addDataIf(
2543
+ {
2544
+ event_name: SEARCH_SUBMITTED_EVENT_NAME,
2545
+ ...additionalPayload,
2546
+ search_string: pageViewPayload.searchString
2547
+ },
2548
+ formatPayload(pageViewPayload)
2549
+ )
2550
+ )
2551
+ );
2552
+ break;
2553
+ }
2554
+ return pageViewEvents;
2555
+ }
2556
+ function addToCart(payload) {
2557
+ const addToCartPayload = payload;
2558
+ const cartToken = parseGid(addToCartPayload.cartId);
2559
+ const cart_token = (cartToken == null ? void 0 : cartToken.id) ? `${cartToken.id}` : null;
2560
+ return [
2561
+ schemaWrapper(
2562
+ SCHEMA_ID,
2563
+ addDataIf(
2564
+ {
2565
+ event_name: PRODUCT_ADDED_TO_CART_EVENT_NAME,
2566
+ customerId: addToCartPayload.customerId,
2567
+ cart_token,
2568
+ total_value: addToCartPayload.totalValue,
2569
+ products: formatProductPayload(addToCartPayload.products)
2570
+ },
2571
+ formatPayload(addToCartPayload)
2572
+ )
2573
+ )
2574
+ ];
2575
+ }
2576
+ function formatPayload(payload) {
2577
+ return {
2578
+ source: payload.shopifySalesChannel || ShopifySalesChannel.headless,
2579
+ hydrogenSubchannelId: payload.storefrontId || "0",
2580
+ is_persistent_cookie: payload.hasUserConsent,
2581
+ ccpa_enforced: false,
2582
+ gdpr_enforced: false,
2583
+ unique_token: payload.uniqueToken,
2584
+ event_time: Date.now(),
2585
+ event_id: buildUUID(),
2586
+ event_source_url: payload.url,
2587
+ referrer: payload.referrer,
2588
+ user_agent: payload.userAgent,
2589
+ navigation_type: payload.navigationType,
2590
+ navigation_api: payload.navigationApi,
2591
+ shop_id: parseInt(parseGid(payload.shopId).id),
2592
+ currency: payload.currency
2593
+ };
2594
+ }
2595
+ function formatProductPayload(products) {
2596
+ return products ? products.map((p) => {
2597
+ const product = addDataIf(
2598
+ {
2599
+ variant_gid: p.variantGid,
2600
+ category: p.category,
2601
+ sku: p.sku,
2602
+ product_id: parseInt(parseGid(p.productGid).id),
2603
+ variant_id: parseInt(parseGid(p.variantGid).id)
2604
+ },
2605
+ {
2606
+ product_gid: p.productGid,
2607
+ name: p.name,
2608
+ variant: p.variantName || "",
2609
+ brand: p.brand,
2610
+ price: p.price,
2611
+ quantity: Number(p.quantity || 0)
2612
+ }
2613
+ );
2614
+ return JSON.stringify(product);
2615
+ }) : [];
2616
+ }
2617
+ function sendShopifyAnalytics(event, shopDomain) {
2618
+ const { eventName, payload } = event;
2619
+ if (!payload.hasUserConsent)
2620
+ return Promise.resolve();
2621
+ let events = [];
2622
+ if (eventName === AnalyticsEventName.PAGE_VIEW) {
2623
+ const pageViewPayload = payload;
2624
+ events = events.concat(
2625
+ pageView$1(pageViewPayload),
2626
+ pageView(pageViewPayload)
2627
+ );
2628
+ } else if (eventName === AnalyticsEventName.ADD_TO_CART) {
2629
+ events = events.concat(
2630
+ addToCart(payload)
2631
+ );
2632
+ }
2633
+ if (events.length) {
2634
+ return sendToShopify(events, shopDomain);
2635
+ } else {
2636
+ return Promise.resolve();
2637
+ }
2638
+ }
2639
+ const ERROR_MESSAGE = "sendShopifyAnalytics request is unsuccessful";
2640
+ function sendToShopify(events, shopDomain) {
2641
+ const eventsToBeSent = {
2642
+ events,
2643
+ metadata: {
2644
+ event_sent_at_ms: Date.now()
2645
+ }
2646
+ };
2647
+ try {
2648
+ return fetch(
2649
+ shopDomain ? `https://${shopDomain}/.well-known/shopify/monorail/unstable/produce_batch` : "https://monorail-edge.shopifysvc.com/unstable/produce_batch",
2650
+ {
2651
+ method: "post",
2652
+ headers: {
2653
+ "content-type": "text/plain"
2654
+ },
2655
+ body: JSON.stringify(eventsToBeSent)
2656
+ }
2657
+ ).then((response) => {
2658
+ if (!response.ok) {
2659
+ throw new Error("Response failed");
2660
+ }
2661
+ return response.text();
2662
+ }).then((data) => {
2663
+ if (data) {
2664
+ const jsonResponse = JSON.parse(data);
2665
+ jsonResponse.result.forEach((eventResponse) => {
2666
+ if (eventResponse.status !== 200) {
2667
+ console.error(ERROR_MESSAGE, "\n\n", eventResponse.message);
2668
+ }
2669
+ });
2670
+ }
2671
+ }).catch((err) => {
2672
+ console.error(ERROR_MESSAGE, err);
2673
+ if (true) {
2674
+ throw new Error(ERROR_MESSAGE);
2675
+ }
2676
+ });
2677
+ } catch (error) {
2678
+ return Promise.resolve();
2679
+ }
2680
+ }
2681
+ function getClientBrowserParameters() {
2682
+ if (errorIfServer("getClientBrowserParameters")) {
2683
+ return {
2684
+ uniqueToken: "",
2685
+ visitToken: "",
2686
+ url: "",
2687
+ path: "",
2688
+ search: "",
2689
+ referrer: "",
2690
+ title: "",
2691
+ userAgent: "",
2692
+ navigationType: "",
2693
+ navigationApi: ""
2694
+ };
2695
+ }
2696
+ const [navigationType, navigationApi] = getNavigationType();
2697
+ const cookies = getShopifyCookies(document.cookie);
2698
+ return {
2699
+ uniqueToken: cookies[SHOPIFY_Y],
2700
+ visitToken: cookies[SHOPIFY_S],
2701
+ url: location.href,
2702
+ path: location.pathname,
2703
+ search: location.search,
2704
+ referrer: document.referrer,
2705
+ title: document.title,
2706
+ userAgent: navigator.userAgent,
2707
+ navigationType,
2708
+ navigationApi
2709
+ };
2710
+ }
2711
+ function getNavigationTypeExperimental() {
2712
+ try {
2713
+ const navigationEntries = (performance == null ? void 0 : performance.getEntriesByType) && (performance == null ? void 0 : performance.getEntriesByType("navigation"));
2714
+ if (navigationEntries && navigationEntries[0]) {
2715
+ const rawType = window.performance.getEntriesByType(
2716
+ "navigation"
2717
+ )[0]["type"];
2718
+ const navType = rawType && rawType.toString();
2719
+ return navType;
2720
+ }
2721
+ } catch (err) {
2722
+ }
2723
+ return void 0;
2724
+ }
2725
+ function getNavigationTypeLegacy() {
2726
+ var _a, _b;
2727
+ try {
2728
+ if (PerformanceNavigation && ((_a = performance == null ? void 0 : performance.navigation) == null ? void 0 : _a.type) !== null && ((_b = performance == null ? void 0 : performance.navigation) == null ? void 0 : _b.type) !== void 0) {
2729
+ const rawType = performance.navigation.type;
2730
+ switch (rawType) {
2731
+ case PerformanceNavigation.TYPE_NAVIGATE:
2732
+ return "navigate";
2733
+ break;
2734
+ case PerformanceNavigation.TYPE_RELOAD:
2735
+ return "reload";
2736
+ break;
2737
+ case PerformanceNavigation.TYPE_BACK_FORWARD:
2738
+ return "back_forward";
2739
+ break;
2740
+ default:
2741
+ return `unknown: ${rawType}`;
2742
+ }
2743
+ }
2744
+ } catch (err) {
2745
+ }
2746
+ return void 0;
2747
+ }
2748
+ function getNavigationType() {
2749
+ try {
2750
+ let navApi = "PerformanceNavigationTiming";
2751
+ let navType = getNavigationTypeExperimental();
2752
+ if (!navType) {
2753
+ navType = getNavigationTypeLegacy();
2754
+ navApi = "performance.navigation";
2755
+ }
2756
+ if (navType) {
2757
+ return [navType, navApi];
2758
+ } else {
2759
+ return ["unknown", "unknown"];
2760
+ }
2761
+ } catch (err) {
2762
+ }
2763
+ return ["error", "error"];
2764
+ }
2765
+ function BuyNowButton(props) {
2766
+ const { cartCreate, checkoutUrl } = useCart();
2767
+ const [loading, setLoading] = React.useState(false);
2768
+ const {
2769
+ quantity,
2770
+ variantId,
2771
+ onClick,
2772
+ attributes,
2773
+ children,
2774
+ ...passthroughProps
2775
+ } = props;
2219
2776
  React.useEffect(() => {
2220
2777
  if (checkoutUrl) {
2221
2778
  window.location.href = checkoutUrl;
@@ -2224,55 +2781,211 @@
2224
2781
  const handleBuyNow = React.useCallback(() => {
2225
2782
  setLoading(true);
2226
2783
  cartCreate({
2227
- lines: [{
2228
- quantity: quantity != null ? quantity : 1,
2229
- merchandiseId: variantId,
2230
- attributes
2231
- }]
2784
+ lines: [
2785
+ {
2786
+ quantity: quantity ?? 1,
2787
+ merchandiseId: variantId,
2788
+ attributes
2789
+ }
2790
+ ]
2232
2791
  });
2233
2792
  }, [cartCreate, quantity, variantId, attributes]);
2234
- return /* @__PURE__ */ React__default.default.createElement(BaseButton, {
2235
- disabled: loading != null ? loading : passthroughProps.disabled,
2236
- ...passthroughProps,
2237
- onClick,
2238
- defaultOnClick: handleBuyNow,
2239
- __self: this,
2240
- __source: {
2241
- fileName: _jsxFileName$9,
2242
- lineNumber: 53,
2243
- columnNumber: 5
2244
- }
2245
- }, children);
2793
+ return /* @__PURE__ */ React.createElement(
2794
+ BaseButton,
2795
+ {
2796
+ disabled: loading ?? passthroughProps.disabled,
2797
+ ...passthroughProps,
2798
+ onClick,
2799
+ defaultOnClick: handleBuyNow
2800
+ },
2801
+ children
2802
+ );
2246
2803
  }
2247
- var _jsxFileName$8 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/CartCheckoutButton.tsx";
2248
2804
  function CartCheckoutButton(props) {
2249
2805
  const [requestedCheckout, setRequestedCheckout] = React.useState(false);
2250
- const {
2251
- status,
2252
- checkoutUrl
2253
- } = useCart();
2254
- const {
2255
- children,
2256
- ...passthroughProps
2257
- } = props;
2806
+ const { status, checkoutUrl } = useCart();
2807
+ const { children, ...passthroughProps } = props;
2258
2808
  React.useEffect(() => {
2259
2809
  if (requestedCheckout && checkoutUrl && status === "idle") {
2260
2810
  window.location.href = checkoutUrl;
2261
2811
  }
2262
2812
  }, [requestedCheckout, status, checkoutUrl]);
2263
- return /* @__PURE__ */ React__default.default.createElement(BaseButton, {
2264
- ...passthroughProps,
2265
- disabled: requestedCheckout || passthroughProps.disabled,
2266
- onClick: () => setRequestedCheckout(true),
2267
- __self: this,
2268
- __source: {
2269
- fileName: _jsxFileName$8,
2270
- lineNumber: 28,
2271
- columnNumber: 5
2272
- }
2273
- }, children);
2813
+ return /* @__PURE__ */ React.createElement(
2814
+ BaseButton,
2815
+ {
2816
+ ...passthroughProps,
2817
+ disabled: requestedCheckout || passthroughProps.disabled,
2818
+ onClick: () => setRequestedCheckout(true)
2819
+ },
2820
+ children
2821
+ );
2822
+ }
2823
+ function useMoney(money) {
2824
+ const { countryIsoCode, languageIsoCode } = useShop();
2825
+ const locale = `${languageIsoCode}-${countryIsoCode}`;
2826
+ if (!locale) {
2827
+ throw new Error(
2828
+ `useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`
2829
+ );
2830
+ }
2831
+ const amount = parseFloat(money.amount);
2832
+ const options = React.useMemo(
2833
+ () => ({
2834
+ style: "currency",
2835
+ currency: money.currencyCode
2836
+ }),
2837
+ [money.currencyCode]
2838
+ );
2839
+ const defaultFormatter = useLazyFormatter(locale, options);
2840
+ const nameFormatter = useLazyFormatter(locale, {
2841
+ ...options,
2842
+ currencyDisplay: "name"
2843
+ });
2844
+ const narrowSymbolFormatter = useLazyFormatter(locale, {
2845
+ ...options,
2846
+ currencyDisplay: "narrowSymbol"
2847
+ });
2848
+ const withoutTrailingZerosFormatter = useLazyFormatter(locale, {
2849
+ ...options,
2850
+ minimumFractionDigits: 0,
2851
+ maximumFractionDigits: 0
2852
+ });
2853
+ const withoutCurrencyFormatter = useLazyFormatter(locale);
2854
+ const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {
2855
+ minimumFractionDigits: 0,
2856
+ maximumFractionDigits: 0
2857
+ });
2858
+ const isPartCurrency = (part) => part.type === "currency";
2859
+ const lazyFormatters = React.useMemo(
2860
+ () => ({
2861
+ original: () => money,
2862
+ currencyCode: () => money.currencyCode,
2863
+ localizedString: () => defaultFormatter().format(amount),
2864
+ parts: () => defaultFormatter().formatToParts(amount),
2865
+ withoutTrailingZeros: () => amount % 1 === 0 ? withoutTrailingZerosFormatter().format(amount) : defaultFormatter().format(amount),
2866
+ withoutTrailingZerosAndCurrency: () => amount % 1 === 0 ? withoutTrailingZerosOrCurrencyFormatter().format(amount) : withoutCurrencyFormatter().format(amount),
2867
+ currencyName: () => {
2868
+ var _a;
2869
+ return ((_a = nameFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) ?? money.currencyCode;
2870
+ },
2871
+ // e.g. "US dollars"
2872
+ currencySymbol: () => {
2873
+ var _a;
2874
+ return ((_a = defaultFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) ?? money.currencyCode;
2875
+ },
2876
+ // e.g. "USD"
2877
+ currencyNarrowSymbol: () => {
2878
+ var _a;
2879
+ return ((_a = narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) ?? "";
2880
+ },
2881
+ // e.g. "$"
2882
+ amount: () => defaultFormatter().formatToParts(amount).filter(
2883
+ (part) => ["decimal", "fraction", "group", "integer", "literal"].includes(
2884
+ part.type
2885
+ )
2886
+ ).map((part) => part.value).join("")
2887
+ }),
2888
+ [
2889
+ money,
2890
+ amount,
2891
+ nameFormatter,
2892
+ defaultFormatter,
2893
+ narrowSymbolFormatter,
2894
+ withoutCurrencyFormatter,
2895
+ withoutTrailingZerosFormatter,
2896
+ withoutTrailingZerosOrCurrencyFormatter
2897
+ ]
2898
+ );
2899
+ return React.useMemo(
2900
+ () => new Proxy(lazyFormatters, {
2901
+ get: (target, key) => {
2902
+ var _a;
2903
+ return (_a = Reflect.get(target, key)) == null ? void 0 : _a.call(null);
2904
+ }
2905
+ }),
2906
+ [lazyFormatters]
2907
+ );
2908
+ }
2909
+ function useLazyFormatter(locale, options) {
2910
+ return React.useMemo(() => {
2911
+ let memoized;
2912
+ return () => memoized ?? (memoized = new Intl.NumberFormat(locale, options));
2913
+ }, [locale, options]);
2914
+ }
2915
+ function Money({
2916
+ data,
2917
+ as,
2918
+ withoutCurrency,
2919
+ withoutTrailingZeros,
2920
+ measurement,
2921
+ measurementSeparator = "/",
2922
+ ...passthroughProps
2923
+ }) {
2924
+ if (!isMoney(data)) {
2925
+ throw new Error(
2926
+ `<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`
2927
+ );
2928
+ }
2929
+ const moneyObject = useMoney(data);
2930
+ const Wrapper = as ?? "div";
2931
+ let output = moneyObject.localizedString;
2932
+ if (withoutCurrency || withoutTrailingZeros) {
2933
+ if (withoutCurrency && !withoutTrailingZeros) {
2934
+ output = moneyObject.amount;
2935
+ } else if (!withoutCurrency && withoutTrailingZeros) {
2936
+ output = moneyObject.withoutTrailingZeros;
2937
+ } else {
2938
+ output = moneyObject.withoutTrailingZerosAndCurrency;
2939
+ }
2940
+ }
2941
+ return /* @__PURE__ */ React.createElement(Wrapper, { ...passthroughProps }, output, measurement && measurement.referenceUnit && /* @__PURE__ */ React.createElement(React.Fragment, null, measurementSeparator, measurement.referenceUnit));
2942
+ }
2943
+ function isMoney(maybeMoney) {
2944
+ return typeof maybeMoney.amount === "string" && !!maybeMoney.amount && typeof maybeMoney.currencyCode === "string" && !!maybeMoney.currencyCode;
2945
+ }
2946
+ function CartCost(props) {
2947
+ const { cost } = useCart();
2948
+ const { amountType = "total", children, ...passthroughProps } = props;
2949
+ let amount;
2950
+ if (amountType == "total") {
2951
+ amount = cost == null ? void 0 : cost.totalAmount;
2952
+ } else if (amountType == "subtotal") {
2953
+ amount = cost == null ? void 0 : cost.subtotalAmount;
2954
+ } else if (amountType == "tax") {
2955
+ amount = cost == null ? void 0 : cost.totalTaxAmount;
2956
+ } else if (amountType == "duty") {
2957
+ amount = cost == null ? void 0 : cost.totalDutyAmount;
2958
+ }
2959
+ if (amount == null) {
2960
+ return null;
2961
+ }
2962
+ return /* @__PURE__ */ React.createElement(Money, { ...passthroughProps, data: amount }, children);
2963
+ }
2964
+ function CartLinePrice(props) {
2965
+ var _a, _b;
2966
+ const { data: cartLine, priceType = "regular", ...passthroughProps } = props;
2967
+ if (cartLine == null) {
2968
+ throw new Error(`<CartLinePrice/> requires a cart line as the 'data' prop`);
2969
+ }
2970
+ const moneyV2 = priceType === "regular" ? (_a = cartLine.cost) == null ? void 0 : _a.totalAmount : (_b = cartLine.cost) == null ? void 0 : _b.compareAtAmountPerQuantity;
2971
+ if (moneyV2 == null) {
2972
+ return null;
2973
+ }
2974
+ return /* @__PURE__ */ React.createElement(Money, { ...passthroughProps, data: moneyV2 });
2975
+ }
2976
+ const CartLineContext = React.createContext(null);
2977
+ function useCartLine() {
2978
+ const context = React.useContext(CartLineContext);
2979
+ if (context == null) {
2980
+ throw new Error("Expected a cart line context but none was found");
2981
+ }
2982
+ return context;
2983
+ }
2984
+ function CartLineProvider({ children, line }) {
2985
+ return /* @__PURE__ */ React.createElement(CartLineContext.Provider, { value: line }, children);
2274
2986
  }
2275
2987
  const storefrontApiCustomScalars = {
2988
+ // Keep in sync with the definitions in the app/nextjs/codegen.ts!
2276
2989
  DateTime: "string",
2277
2990
  Decimal: "string",
2278
2991
  HTML: "string",
@@ -2280,9 +2993,7 @@
2280
2993
  Color: "string",
2281
2994
  UnsignedInt64: "string"
2282
2995
  };
2283
- var _jsxFileName$7 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ExternalVideo.tsx";
2284
2996
  function ExternalVideo(props) {
2285
- var _a, _b;
2286
2997
  const {
2287
2998
  data,
2288
2999
  options,
@@ -2304,22 +3015,19 @@
2304
3015
  }
2305
3016
  finalUrl = urlObject.toString();
2306
3017
  }
2307
- return /* @__PURE__ */ React__default.default.createElement("iframe", {
2308
- ...passthroughProps,
2309
- id: id != null ? id : data.embedUrl,
2310
- title: (_b = (_a = data.alt) != null ? _a : data.id) != null ? _b : "external video",
2311
- frameBorder,
2312
- allow,
2313
- allowFullScreen,
2314
- src: finalUrl,
2315
- loading,
2316
- __self: this,
2317
- __source: {
2318
- fileName: _jsxFileName$7,
2319
- lineNumber: 56,
2320
- columnNumber: 5
3018
+ return /* @__PURE__ */ React.createElement(
3019
+ "iframe",
3020
+ {
3021
+ ...passthroughProps,
3022
+ id: id ?? data.embedUrl,
3023
+ title: data.alt ?? data.id ?? "external video",
3024
+ frameBorder,
3025
+ allow,
3026
+ allowFullScreen,
3027
+ src: finalUrl,
3028
+ loading
2321
3029
  }
2322
- });
3030
+ );
2323
3031
  }
2324
3032
  const PRODUCTION_CDN_HOSTNAMES = [
2325
3033
  "cdn.shopify.com",
@@ -2338,7 +3046,7 @@
2338
3046
  scale
2339
3047
  }) {
2340
3048
  const newUrl = new URL(src);
2341
- const multipliedScale = scale != null ? scale : 1;
3049
+ const multipliedScale = scale ?? 1;
2342
3050
  if (width) {
2343
3051
  let finalWidth;
2344
3052
  if (typeof width === "string") {
@@ -2369,32 +3077,31 @@
2369
3077
  loaderOptions,
2370
3078
  elementProps
2371
3079
  }) {
2372
- var _a, _b, _c, _d, _e, _f;
2373
3080
  let aspectRatio = null;
2374
3081
  if ((sfapiImage == null ? void 0 : sfapiImage.width) && (sfapiImage == null ? void 0 : sfapiImage.height)) {
2375
3082
  aspectRatio = (sfapiImage == null ? void 0 : sfapiImage.width) / (sfapiImage == null ? void 0 : sfapiImage.height);
2376
3083
  }
2377
3084
  if ((loaderOptions == null ? void 0 : loaderOptions.width) || (loaderOptions == null ? void 0 : loaderOptions.height)) {
2378
3085
  return {
2379
- width: (_a = loaderOptions == null ? void 0 : loaderOptions.width) != null ? _a : aspectRatio && typeof loaderOptions.height === "number" ? Math.round(aspectRatio * loaderOptions.height) : null,
2380
- height: (_b = loaderOptions == null ? void 0 : loaderOptions.height) != null ? _b : aspectRatio && typeof loaderOptions.width === "number" ? Math.round(aspectRatio * loaderOptions.width) : null
3086
+ width: (loaderOptions == null ? void 0 : loaderOptions.width) ?? (aspectRatio && typeof loaderOptions.height === "number" ? Math.round(aspectRatio * loaderOptions.height) : null),
3087
+ height: (loaderOptions == null ? void 0 : loaderOptions.height) ?? (aspectRatio && typeof loaderOptions.width === "number" ? Math.round(aspectRatio * loaderOptions.width) : null)
2381
3088
  };
2382
3089
  }
2383
3090
  if ((elementProps == null ? void 0 : elementProps.width) || (elementProps == null ? void 0 : elementProps.height)) {
2384
3091
  return {
2385
- width: (_c = elementProps == null ? void 0 : elementProps.width) != null ? _c : aspectRatio && typeof elementProps.height === "number" ? Math.round(aspectRatio * elementProps.height) : null,
2386
- height: (_d = elementProps == null ? void 0 : elementProps.height) != null ? _d : aspectRatio && typeof elementProps.width === "number" ? Math.round(aspectRatio * elementProps.width) : null
3092
+ width: (elementProps == null ? void 0 : elementProps.width) ?? (aspectRatio && typeof elementProps.height === "number" ? Math.round(aspectRatio * elementProps.height) : null),
3093
+ height: (elementProps == null ? void 0 : elementProps.height) ?? (aspectRatio && typeof elementProps.width === "number" ? Math.round(aspectRatio * elementProps.width) : null)
2387
3094
  };
2388
3095
  }
2389
3096
  if ((sfapiImage == null ? void 0 : sfapiImage.width) || (sfapiImage == null ? void 0 : sfapiImage.height)) {
2390
3097
  return {
2391
- width: (_e = sfapiImage == null ? void 0 : sfapiImage.width) != null ? _e : null,
2392
- height: (_f = sfapiImage == null ? void 0 : sfapiImage.height) != null ? _f : null
3098
+ // can't calculate the aspect ratio here
3099
+ width: (sfapiImage == null ? void 0 : sfapiImage.width) ?? null,
3100
+ height: (sfapiImage == null ? void 0 : sfapiImage.height) ?? null
2393
3101
  };
2394
3102
  }
2395
3103
  return { width: null, height: null };
2396
3104
  }
2397
- var _jsxFileName$6 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Image.tsx";
2398
3105
  function Image({
2399
3106
  data,
2400
3107
  width,
@@ -2406,20 +3113,18 @@
2406
3113
  decoding = "async",
2407
3114
  ...rest
2408
3115
  }) {
2409
- var _a, _b, _c, _d, _e, _f, _g, _h;
2410
3116
  if (!data.url) {
2411
- const missingUrlError = `<Image/>: the 'data' prop requires the 'url' property. Image: ${(_a = data.id) != null ? _a : "no ID provided"}`;
3117
+ const missingUrlError = `<Image/>: the 'data' prop requires the 'url' property. Image: ${data.id ?? "no ID provided"}`;
2412
3118
  {
2413
3119
  throw new Error(missingUrlError);
2414
3120
  }
2415
3121
  }
2416
3122
  if (!data.altText && !rest.alt) {
2417
- console.warn(`<Image/>: the 'data' prop should have the 'altText' property, or the 'alt' prop, and one of them should not be empty. Image: ${(_b = data.id) != null ? _b : data.url}`);
3123
+ console.warn(
3124
+ `<Image/>: the 'data' prop should have the 'altText' property, or the 'alt' prop, and one of them should not be empty. Image: ${data.id ?? data.url}`
3125
+ );
2418
3126
  }
2419
- const {
2420
- width: imgElementWidth,
2421
- height: imgElementHeight
2422
- } = getShopifyImageDimensions({
3127
+ const { width: imgElementWidth, height: imgElementHeight } = getShopifyImageDimensions({
2423
3128
  data,
2424
3129
  loaderOptions,
2425
3130
  elementProps: {
@@ -2428,7 +3133,9 @@
2428
3133
  }
2429
3134
  });
2430
3135
  if (!imgElementWidth || !imgElementHeight) {
2431
- console.warn(`<Image/>: the 'data' prop requires either 'width' or 'data.width', and 'height' or 'data.height' properties. Image: ${(_c = data.id) != null ? _c : data.url}`);
3136
+ console.warn(
3137
+ `<Image/>: the 'data' prop requires either 'width' or 'data.width', and 'height' or 'data.height' properties. Image: ${data.id ?? data.url}`
3138
+ );
2432
3139
  }
2433
3140
  let finalSrc = data.url;
2434
3141
  if (loader) {
@@ -2439,11 +3146,13 @@
2439
3146
  height: imgElementHeight
2440
3147
  });
2441
3148
  if (typeof finalSrc !== "string" || !finalSrc) {
2442
- throw new Error(`<Image/>: 'loader' did not return a valid string. Image: ${(_d = data.id) != null ? _d : data.url}`);
3149
+ throw new Error(
3150
+ `<Image/>: 'loader' did not return a valid string. Image: ${data.id ?? data.url}`
3151
+ );
2443
3152
  }
2444
3153
  }
2445
3154
  const maxWidth = width && imgElementWidth && width < imgElementWidth ? width : imgElementWidth;
2446
- const finalSrcset = (_e = rest.srcSet) != null ? _e : internalImageSrcSet({
3155
+ const finalSrcset = rest.srcSet ?? internalImageSrcSet({
2447
3156
  ...loaderOptions,
2448
3157
  widths,
2449
3158
  src: data.url,
@@ -2451,23 +3160,20 @@
2451
3160
  height: imgElementHeight,
2452
3161
  loader
2453
3162
  });
2454
- return /* @__PURE__ */ React__namespace.createElement("img", {
2455
- id: (_f = data.id) != null ? _f : "",
2456
- alt: (_h = (_g = data.altText) != null ? _g : rest.alt) != null ? _h : "",
2457
- loading: loading != null ? loading : "lazy",
2458
- ...rest,
2459
- src: finalSrc,
2460
- width: imgElementWidth != null ? imgElementWidth : void 0,
2461
- height: imgElementHeight != null ? imgElementHeight : void 0,
2462
- srcSet: finalSrcset,
2463
- decoding,
2464
- __self: this,
2465
- __source: {
2466
- fileName: _jsxFileName$6,
2467
- lineNumber: 150,
2468
- columnNumber: 5
3163
+ return /* @__PURE__ */ React__namespace.createElement(
3164
+ "img",
3165
+ {
3166
+ id: data.id ?? "",
3167
+ alt: data.altText ?? rest.alt ?? "",
3168
+ loading: loading ?? "lazy",
3169
+ ...rest,
3170
+ src: finalSrc,
3171
+ width: imgElementWidth ?? void 0,
3172
+ height: imgElementHeight ?? void 0,
3173
+ srcSet: finalSrcset,
3174
+ decoding
2469
3175
  }
2470
- });
3176
+ );
2471
3177
  }
2472
3178
  function internalImageSrcSet({
2473
3179
  src,
@@ -2480,7 +3186,9 @@
2480
3186
  }) {
2481
3187
  const hasCustomWidths = widths && Array.isArray(widths);
2482
3188
  if (hasCustomWidths && widths.some((size) => isNaN(size))) {
2483
- throw new Error(`<Image/>: the 'widths' must be an array of numbers. Image: ${src}`);
3189
+ throw new Error(
3190
+ `<Image/>: the 'widths' must be an array of numbers. Image: ${src}`
3191
+ );
2484
3192
  }
2485
3193
  let aspectRatio = 1;
2486
3194
  if (width && height) {
@@ -2491,17 +3199,20 @@
2491
3199
  setSizes = IMG_SRC_SET_SIZES.filter((size) => size <= width);
2492
3200
  }
2493
3201
  const srcGenerator = loader ? loader : addImageSizeParametersToUrl;
2494
- return setSizes.map((size) => `${srcGenerator({
2495
- src,
2496
- width: size,
2497
- height: crop ? Number(size) * aspectRatio : void 0,
2498
- crop,
2499
- scale
2500
- })} ${size}w`).join(", ");
2501
- }
2502
- var _jsxFileName$5 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Video.tsx";
3202
+ return setSizes.map(
3203
+ (size) => `${srcGenerator({
3204
+ src,
3205
+ width: size,
3206
+ // height is not applied if there is no crop
3207
+ // if there is crop, then height is applied as a ratio of the original width + height aspect ratio * size
3208
+ height: crop ? Number(size) * aspectRatio : void 0,
3209
+ crop,
3210
+ scale
3211
+ })} ${size}w`
3212
+ ).join(", ");
3213
+ }
2503
3214
  function Video(props) {
2504
- var _a, _b;
3215
+ var _a;
2505
3216
  const {
2506
3217
  data,
2507
3218
  previewImageOptions,
@@ -2512,41 +3223,39 @@
2512
3223
  ...passthroughProps
2513
3224
  } = props;
2514
3225
  const posterUrl = shopifyImageLoader({
2515
- src: (_b = (_a = data.previewImage) == null ? void 0 : _a.url) != null ? _b : "",
3226
+ src: ((_a = data.previewImage) == null ? void 0 : _a.url) ?? "",
2516
3227
  ...previewImageOptions
2517
3228
  });
2518
3229
  if (!data.sources) {
2519
3230
  throw new Error(`<Video/> requires a 'data.sources' array`);
2520
3231
  }
2521
- return /* @__PURE__ */ React__default.default.createElement("video", {
2522
- ...passthroughProps,
2523
- id,
2524
- playsInline,
2525
- controls,
2526
- poster: posterUrl,
2527
- __self: this,
2528
- __source: {
2529
- fileName: _jsxFileName$5,
2530
- lineNumber: 42,
2531
- columnNumber: 5
2532
- }
2533
- }, data.sources.map((source) => {
2534
- if (!((source == null ? void 0 : source.url) && (source == null ? void 0 : source.mimeType))) {
2535
- throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);
2536
- }
2537
- return /* @__PURE__ */ React__default.default.createElement("source", {
2538
- ...sourceProps,
2539
- key: source.url,
2540
- src: source.url,
2541
- type: source.mimeType,
2542
- __self: this,
2543
- __source: {
2544
- fileName: _jsxFileName$5,
2545
- lineNumber: 54,
2546
- columnNumber: 11
2547
- }
2548
- });
2549
- }));
3232
+ return (
3233
+ // eslint-disable-next-line jsx-a11y/media-has-caption
3234
+ /* @__PURE__ */ React.createElement(
3235
+ "video",
3236
+ {
3237
+ ...passthroughProps,
3238
+ id,
3239
+ playsInline,
3240
+ controls,
3241
+ poster: posterUrl
3242
+ },
3243
+ data.sources.map((source) => {
3244
+ if (!((source == null ? void 0 : source.url) && (source == null ? void 0 : source.mimeType))) {
3245
+ throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);
3246
+ }
3247
+ return /* @__PURE__ */ React.createElement(
3248
+ "source",
3249
+ {
3250
+ ...sourceProps,
3251
+ key: source.url,
3252
+ src: source.url,
3253
+ type: source.mimeType
3254
+ }
3255
+ );
3256
+ })
3257
+ )
3258
+ );
2550
3259
  }
2551
3260
  const SCRIPTS_LOADED = {};
2552
3261
  function loadScript(src, options) {
@@ -2594,22 +3303,21 @@
2594
3303
  }, [url, stringifiedOptions, options]);
2595
3304
  return status;
2596
3305
  }
2597
- var _jsxFileName$4 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ModelViewer.tsx";
2598
3306
  function ModelViewer(props) {
2599
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2600
- const [modelViewer, setModelViewer] = React.useState(void 0);
3307
+ var _a, _b, _c;
3308
+ const [modelViewer, setModelViewer] = React.useState(
3309
+ void 0
3310
+ );
2601
3311
  const callbackRef = React.useCallback((node) => {
2602
3312
  setModelViewer(node);
2603
3313
  }, []);
2604
- const {
2605
- data,
2606
- children,
2607
- className,
2608
- ...passthroughProps
2609
- } = props;
2610
- const modelViewerLoadedStatus = useLoadScript("https://unpkg.com/@google/model-viewer@v1.12.1/dist/model-viewer.min.js", {
2611
- module: true
2612
- });
3314
+ const { data, children, className, ...passthroughProps } = props;
3315
+ const modelViewerLoadedStatus = useLoadScript(
3316
+ "https://unpkg.com/@google/model-viewer@v1.12.1/dist/model-viewer.min.js",
3317
+ {
3318
+ module: true
3319
+ }
3320
+ );
2613
3321
  React.useEffect(() => {
2614
3322
  if (!modelViewer) {
2615
3323
  return;
@@ -2621,25 +3329,43 @@
2621
3329
  if (passthroughProps.onPreload)
2622
3330
  modelViewer.addEventListener("preload", passthroughProps.onPreload);
2623
3331
  if (passthroughProps.onModelVisibility)
2624
- modelViewer.addEventListener("model-visibility", passthroughProps.onModelVisibility);
3332
+ modelViewer.addEventListener(
3333
+ "model-visibility",
3334
+ passthroughProps.onModelVisibility
3335
+ );
2625
3336
  if (passthroughProps.onProgress)
2626
3337
  modelViewer.addEventListener("progress", passthroughProps.onProgress);
2627
3338
  if (passthroughProps.onArStatus)
2628
3339
  modelViewer.addEventListener("ar-status", passthroughProps.onArStatus);
2629
3340
  if (passthroughProps.onArTracking)
2630
- modelViewer.addEventListener("ar-tracking", passthroughProps.onArTracking);
3341
+ modelViewer.addEventListener(
3342
+ "ar-tracking",
3343
+ passthroughProps.onArTracking
3344
+ );
2631
3345
  if (passthroughProps.onQuickLookButtonTapped)
2632
- modelViewer.addEventListener("quick-look-button-tapped", passthroughProps.onQuickLookButtonTapped);
3346
+ modelViewer.addEventListener(
3347
+ "quick-look-button-tapped",
3348
+ passthroughProps.onQuickLookButtonTapped
3349
+ );
2633
3350
  if (passthroughProps.onCameraChange)
2634
- modelViewer.addEventListener("camera-change", passthroughProps.onCameraChange);
3351
+ modelViewer.addEventListener(
3352
+ "camera-change",
3353
+ passthroughProps.onCameraChange
3354
+ );
2635
3355
  if (passthroughProps.onEnvironmentChange)
2636
- modelViewer.addEventListener("environment-change", passthroughProps.onEnvironmentChange);
3356
+ modelViewer.addEventListener(
3357
+ "environment-change",
3358
+ passthroughProps.onEnvironmentChange
3359
+ );
2637
3360
  if (passthroughProps.onPlay)
2638
3361
  modelViewer.addEventListener("play", passthroughProps.onPlay);
2639
3362
  if (passthroughProps.onPause)
2640
3363
  modelViewer.addEventListener("ar-status", passthroughProps.onPause);
2641
3364
  if (passthroughProps.onSceneGraphReady)
2642
- modelViewer.addEventListener("scene-graph-ready", passthroughProps.onSceneGraphReady);
3365
+ modelViewer.addEventListener(
3366
+ "scene-graph-ready",
3367
+ passthroughProps.onSceneGraphReady
3368
+ );
2643
3369
  return () => {
2644
3370
  if (modelViewer == null) {
2645
3371
  return;
@@ -2651,27 +3377,66 @@
2651
3377
  if (passthroughProps.onPreload)
2652
3378
  modelViewer.removeEventListener("preload", passthroughProps.onPreload);
2653
3379
  if (passthroughProps.onModelVisibility)
2654
- modelViewer.removeEventListener("model-visibility", passthroughProps.onModelVisibility);
3380
+ modelViewer.removeEventListener(
3381
+ "model-visibility",
3382
+ passthroughProps.onModelVisibility
3383
+ );
2655
3384
  if (passthroughProps.onProgress)
2656
- modelViewer.removeEventListener("progress", passthroughProps.onProgress);
3385
+ modelViewer.removeEventListener(
3386
+ "progress",
3387
+ passthroughProps.onProgress
3388
+ );
2657
3389
  if (passthroughProps.onArStatus)
2658
- modelViewer.removeEventListener("ar-status", passthroughProps.onArStatus);
3390
+ modelViewer.removeEventListener(
3391
+ "ar-status",
3392
+ passthroughProps.onArStatus
3393
+ );
2659
3394
  if (passthroughProps.onArTracking)
2660
- modelViewer.removeEventListener("ar-tracking", passthroughProps.onArTracking);
3395
+ modelViewer.removeEventListener(
3396
+ "ar-tracking",
3397
+ passthroughProps.onArTracking
3398
+ );
2661
3399
  if (passthroughProps.onQuickLookButtonTapped)
2662
- modelViewer.removeEventListener("quick-look-button-tapped", passthroughProps.onQuickLookButtonTapped);
3400
+ modelViewer.removeEventListener(
3401
+ "quick-look-button-tapped",
3402
+ passthroughProps.onQuickLookButtonTapped
3403
+ );
2663
3404
  if (passthroughProps.onCameraChange)
2664
- modelViewer.removeEventListener("camera-change", passthroughProps.onCameraChange);
3405
+ modelViewer.removeEventListener(
3406
+ "camera-change",
3407
+ passthroughProps.onCameraChange
3408
+ );
2665
3409
  if (passthroughProps.onEnvironmentChange)
2666
- modelViewer.removeEventListener("environment-change", passthroughProps.onEnvironmentChange);
3410
+ modelViewer.removeEventListener(
3411
+ "environment-change",
3412
+ passthroughProps.onEnvironmentChange
3413
+ );
2667
3414
  if (passthroughProps.onPlay)
2668
3415
  modelViewer.removeEventListener("play", passthroughProps.onPlay);
2669
3416
  if (passthroughProps.onPause)
2670
3417
  modelViewer.removeEventListener("ar-status", passthroughProps.onPause);
2671
3418
  if (passthroughProps.onSceneGraphReady)
2672
- modelViewer.removeEventListener("scene-graph-ready", passthroughProps.onSceneGraphReady);
3419
+ modelViewer.removeEventListener(
3420
+ "scene-graph-ready",
3421
+ passthroughProps.onSceneGraphReady
3422
+ );
2673
3423
  };
2674
- }, [modelViewer, passthroughProps.onArStatus, passthroughProps.onArTracking, passthroughProps.onCameraChange, passthroughProps.onEnvironmentChange, passthroughProps.onError, passthroughProps.onLoad, passthroughProps.onModelVisibility, passthroughProps.onPause, passthroughProps.onPlay, passthroughProps.onPreload, passthroughProps.onProgress, passthroughProps.onQuickLookButtonTapped, passthroughProps.onSceneGraphReady]);
3424
+ }, [
3425
+ modelViewer,
3426
+ passthroughProps.onArStatus,
3427
+ passthroughProps.onArTracking,
3428
+ passthroughProps.onCameraChange,
3429
+ passthroughProps.onEnvironmentChange,
3430
+ passthroughProps.onError,
3431
+ passthroughProps.onLoad,
3432
+ passthroughProps.onModelVisibility,
3433
+ passthroughProps.onPause,
3434
+ passthroughProps.onPlay,
3435
+ passthroughProps.onPreload,
3436
+ passthroughProps.onProgress,
3437
+ passthroughProps.onQuickLookButtonTapped,
3438
+ passthroughProps.onSceneGraphReady
3439
+ ]);
2675
3440
  if (modelViewerLoadedStatus !== "done") {
2676
3441
  return null;
2677
3442
  }
@@ -2682,63 +3447,62 @@
2682
3447
  }
2683
3448
  }
2684
3449
  if (!data.alt) {
2685
- console.warn(`<ModelViewer/> requires the 'data.alt' prop for accessibility`);
2686
- }
2687
- return /* @__PURE__ */ React__default.default.createElement("model-viewer", {
2688
- ref: callbackRef,
2689
- ...passthroughProps,
2690
- className,
2691
- id: (_c = passthroughProps.id) != null ? _c : data.id,
2692
- src: data.sources[0].url,
2693
- alt: (_d = data.alt) != null ? _d : null,
2694
- "camera-controls": (_e = passthroughProps.cameraControls) != null ? _e : true,
2695
- poster: (_g = passthroughProps.poster || ((_f = data.previewImage) == null ? void 0 : _f.url)) != null ? _g : null,
2696
- autoplay: (_h = passthroughProps.autoplay) != null ? _h : true,
2697
- loading: passthroughProps.loading,
2698
- reveal: passthroughProps.reveal,
2699
- ar: passthroughProps.ar,
2700
- "ar-modes": passthroughProps.arModes,
2701
- "ar-scale": passthroughProps.arScale,
2702
- "ar-placement": passthroughProps.arPlacement,
2703
- "ios-src": passthroughProps.iosSrc,
2704
- "touch-action": passthroughProps.touchAction,
2705
- "disable-zoom": passthroughProps.disableZoom,
2706
- "orbit-sensitivity": passthroughProps.orbitSensitivity,
2707
- "auto-rotate": passthroughProps.autoRotate,
2708
- "auto-rotate-delay": passthroughProps.autoRotateDelay,
2709
- "rotation-per-second": passthroughProps.rotationPerSecond,
2710
- "interaction-policy": passthroughProps.interactionPolicy,
2711
- "interaction-prompt": passthroughProps.interactionPrompt,
2712
- "interaction-prompt-style": passthroughProps.interactionPromptStyle,
2713
- "interaction-prompt-threshold": passthroughProps.interactionPromptThreshold,
2714
- "camera-orbit": passthroughProps.cameraOrbit,
2715
- "camera-target": passthroughProps.cameraTarget,
2716
- "field-of-view": passthroughProps.fieldOfView,
2717
- "max-camera-orbit": passthroughProps.maxCameraOrbit,
2718
- "min-camera-orbit": passthroughProps.minCameraOrbit,
2719
- "max-field-of-view": passthroughProps.maxFieldOfView,
2720
- "min-field-of-view": passthroughProps.minFieldOfView,
2721
- bounds: passthroughProps.bounds,
2722
- "interpolation-decay": (_i = passthroughProps.interpolationDecay) != null ? _i : 100,
2723
- "skybox-image": passthroughProps.skyboxImage,
2724
- "environment-image": passthroughProps.environmentImage,
2725
- exposure: passthroughProps.exposure,
2726
- "shadow-intensity": (_j = passthroughProps.shadowIntensity) != null ? _j : 0,
2727
- "shadow-softness": (_k = passthroughProps.shadowSoftness) != null ? _k : 0,
2728
- "animation-name": passthroughProps.animationName,
2729
- "animation-crossfade-duration": passthroughProps.animationCrossfadeDuration,
2730
- "variant-name": passthroughProps.variantName,
2731
- orientation: passthroughProps.orientation,
2732
- scale: passthroughProps.scale,
2733
- __self: this,
2734
- __source: {
2735
- fileName: _jsxFileName$4,
2736
- lineNumber: 222,
2737
- columnNumber: 5
2738
- }
2739
- }, children);
2740
- }
2741
- var _jsxFileName$3 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/MediaFile.tsx";
3450
+ console.warn(
3451
+ `<ModelViewer/> requires the 'data.alt' prop for accessibility`
3452
+ );
3453
+ }
3454
+ return /* @__PURE__ */ React.createElement(
3455
+ "model-viewer",
3456
+ {
3457
+ ref: callbackRef,
3458
+ ...passthroughProps,
3459
+ className,
3460
+ id: passthroughProps.id ?? data.id,
3461
+ src: data.sources[0].url,
3462
+ alt: data.alt ?? null,
3463
+ "camera-controls": passthroughProps.cameraControls ?? true,
3464
+ poster: (passthroughProps.poster || ((_c = data.previewImage) == null ? void 0 : _c.url)) ?? null,
3465
+ autoplay: passthroughProps.autoplay ?? true,
3466
+ loading: passthroughProps.loading,
3467
+ reveal: passthroughProps.reveal,
3468
+ ar: passthroughProps.ar,
3469
+ "ar-modes": passthroughProps.arModes,
3470
+ "ar-scale": passthroughProps.arScale,
3471
+ "ar-placement": passthroughProps.arPlacement,
3472
+ "ios-src": passthroughProps.iosSrc,
3473
+ "touch-action": passthroughProps.touchAction,
3474
+ "disable-zoom": passthroughProps.disableZoom,
3475
+ "orbit-sensitivity": passthroughProps.orbitSensitivity,
3476
+ "auto-rotate": passthroughProps.autoRotate,
3477
+ "auto-rotate-delay": passthroughProps.autoRotateDelay,
3478
+ "rotation-per-second": passthroughProps.rotationPerSecond,
3479
+ "interaction-policy": passthroughProps.interactionPolicy,
3480
+ "interaction-prompt": passthroughProps.interactionPrompt,
3481
+ "interaction-prompt-style": passthroughProps.interactionPromptStyle,
3482
+ "interaction-prompt-threshold": passthroughProps.interactionPromptThreshold,
3483
+ "camera-orbit": passthroughProps.cameraOrbit,
3484
+ "camera-target": passthroughProps.cameraTarget,
3485
+ "field-of-view": passthroughProps.fieldOfView,
3486
+ "max-camera-orbit": passthroughProps.maxCameraOrbit,
3487
+ "min-camera-orbit": passthroughProps.minCameraOrbit,
3488
+ "max-field-of-view": passthroughProps.maxFieldOfView,
3489
+ "min-field-of-view": passthroughProps.minFieldOfView,
3490
+ bounds: passthroughProps.bounds,
3491
+ "interpolation-decay": passthroughProps.interpolationDecay ?? 100,
3492
+ "skybox-image": passthroughProps.skyboxImage,
3493
+ "environment-image": passthroughProps.environmentImage,
3494
+ exposure: passthroughProps.exposure,
3495
+ "shadow-intensity": passthroughProps.shadowIntensity ?? 0,
3496
+ "shadow-softness": passthroughProps.shadowSoftness ?? 0,
3497
+ "animation-name": passthroughProps.animationName,
3498
+ "animation-crossfade-duration": passthroughProps.animationCrossfadeDuration,
3499
+ "variant-name": passthroughProps.variantName,
3500
+ orientation: passthroughProps.orientation,
3501
+ scale: passthroughProps.scale
3502
+ },
3503
+ children
3504
+ );
3505
+ }
2742
3506
  function MediaFile({
2743
3507
  data,
2744
3508
  mediaOptions,
@@ -2752,56 +3516,40 @@
2752
3516
  throw new Error(noDataImage);
2753
3517
  }
2754
3518
  }
2755
- return /* @__PURE__ */ React__default.default.createElement(Image, {
2756
- ...passthroughProps,
2757
- ...mediaOptions == null ? void 0 : mediaOptions.image,
2758
- data: data.image,
2759
- __self: this,
2760
- __source: {
2761
- fileName: _jsxFileName$3,
2762
- lineNumber: 54,
2763
- columnNumber: 9
3519
+ return /* @__PURE__ */ React.createElement(
3520
+ Image,
3521
+ {
3522
+ ...passthroughProps,
3523
+ ...mediaOptions == null ? void 0 : mediaOptions.image,
3524
+ data: data.image
2764
3525
  }
2765
- });
3526
+ );
2766
3527
  }
2767
3528
  case "Video": {
2768
- return /* @__PURE__ */ React__default.default.createElement(Video, {
2769
- ...passthroughProps,
2770
- ...mediaOptions == null ? void 0 : mediaOptions.video,
2771
- data,
2772
- __self: this,
2773
- __source: {
2774
- fileName: _jsxFileName$3,
2775
- lineNumber: 63,
2776
- columnNumber: 9
2777
- }
2778
- });
3529
+ return /* @__PURE__ */ React.createElement(Video, { ...passthroughProps, ...mediaOptions == null ? void 0 : mediaOptions.video, data });
2779
3530
  }
2780
3531
  case "ExternalVideo": {
2781
- return /* @__PURE__ */ React__default.default.createElement(ExternalVideo, {
2782
- ...passthroughProps,
2783
- ...mediaOptions == null ? void 0 : mediaOptions.externalVideo,
2784
- data,
2785
- __self: this,
2786
- __source: {
2787
- fileName: _jsxFileName$3,
2788
- lineNumber: 68,
2789
- columnNumber: 9
3532
+ return /* @__PURE__ */ React.createElement(
3533
+ ExternalVideo,
3534
+ {
3535
+ ...passthroughProps,
3536
+ ...mediaOptions == null ? void 0 : mediaOptions.externalVideo,
3537
+ data
2790
3538
  }
2791
- });
3539
+ );
2792
3540
  }
2793
3541
  case "Model3d": {
2794
- return /* @__PURE__ */ React__default.default.createElement(ModelViewer, {
2795
- ...passthroughProps,
2796
- ...mediaOptions == null ? void 0 : mediaOptions.modelViewer,
2797
- data,
2798
- __self: this,
2799
- __source: {
2800
- fileName: _jsxFileName$3,
2801
- lineNumber: 78,
2802
- columnNumber: 9
2803
- }
2804
- });
3542
+ return (
3543
+ // @ts-expect-error There are issues with the inferred HTML attribute types here for ModelViewer (and contentEditable), but I think that's a little bit beyond me at the moment
3544
+ /* @__PURE__ */ React.createElement(
3545
+ ModelViewer,
3546
+ {
3547
+ ...passthroughProps,
3548
+ ...mediaOptions == null ? void 0 : mediaOptions.modelViewer,
3549
+ data
3550
+ }
3551
+ )
3552
+ );
2805
3553
  }
2806
3554
  default: {
2807
3555
  const typenameMissingMessage = `<MediaFile /> requires the '__typename' property to exist on the 'data' prop in order to render the matching sub-component for this type of media.`;
@@ -2812,7 +3560,6 @@
2812
3560
  }
2813
3561
  }
2814
3562
  function parseMetafield(metafield) {
2815
- var _a, _b, _c, _d;
2816
3563
  if (!metafield.type) {
2817
3564
  const noTypeError = `parseMetafield(): The 'type' field is required in order to parse the Metafield.`;
2818
3565
  {
@@ -2859,7 +3606,7 @@
2859
3606
  case "list.weight": {
2860
3607
  let parsedValue = null;
2861
3608
  try {
2862
- parsedValue = parseJSON((_a = metafield.value) != null ? _a : "");
3609
+ parsedValue = parseJSON(metafield.value ?? "");
2863
3610
  } catch (err) {
2864
3611
  const parseError = `parseMetafield(): attempted to JSON.parse the 'metafield.value' property, but failed.`;
2865
3612
  {
@@ -2875,11 +3622,11 @@
2875
3622
  case "date_time":
2876
3623
  return {
2877
3624
  ...metafield,
2878
- parsedValue: new Date((_b = metafield.value) != null ? _b : "")
3625
+ parsedValue: new Date(metafield.value ?? "")
2879
3626
  };
2880
3627
  case "list.date":
2881
3628
  case "list.date_time": {
2882
- const jsonParseValue = parseJSON((_c = metafield == null ? void 0 : metafield.value) != null ? _c : "");
3629
+ const jsonParseValue = parseJSON((metafield == null ? void 0 : metafield.value) ?? "");
2883
3630
  return {
2884
3631
  ...metafield,
2885
3632
  parsedValue: jsonParseValue.map((dateString) => new Date(dateString))
@@ -2898,7 +3645,7 @@
2898
3645
  case "list.variant_reference":
2899
3646
  return {
2900
3647
  ...metafield,
2901
- parsedValue: flattenConnection((_d = metafield.references) != null ? _d : void 0)
3648
+ parsedValue: flattenConnection(metafield.references ?? void 0)
2902
3649
  };
2903
3650
  default: {
2904
3651
  const typeNotFoundError = `parseMetafield(): the 'metafield.type' you passed in is not supported. Your type: "${metafield.type}". If you believe this is an error, please open an issue on GitHub.`;
@@ -2917,113 +3664,8 @@
2917
3664
  }
2918
3665
  return JSON.parse(json);
2919
3666
  }
2920
- function useMoney(money) {
2921
- const {
2922
- locale
2923
- } = useShop();
2924
- if (!locale) {
2925
- throw new Error(`useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`);
2926
- }
2927
- const amount = parseFloat(money.amount);
2928
- const options = React.useMemo(() => ({
2929
- style: "currency",
2930
- currency: money.currencyCode
2931
- }), [money.currencyCode]);
2932
- const defaultFormatter = useLazyFormatter(locale, options);
2933
- const nameFormatter = useLazyFormatter(locale, {
2934
- ...options,
2935
- currencyDisplay: "name"
2936
- });
2937
- const narrowSymbolFormatter = useLazyFormatter(locale, {
2938
- ...options,
2939
- currencyDisplay: "narrowSymbol"
2940
- });
2941
- const withoutTrailingZerosFormatter = useLazyFormatter(locale, {
2942
- ...options,
2943
- minimumFractionDigits: 0,
2944
- maximumFractionDigits: 0
2945
- });
2946
- const withoutCurrencyFormatter = useLazyFormatter(locale);
2947
- const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {
2948
- minimumFractionDigits: 0,
2949
- maximumFractionDigits: 0
2950
- });
2951
- const isPartCurrency = (part) => part.type === "currency";
2952
- const lazyFormatters = React.useMemo(() => ({
2953
- original: () => money,
2954
- currencyCode: () => money.currencyCode,
2955
- localizedString: () => defaultFormatter().format(amount),
2956
- parts: () => defaultFormatter().formatToParts(amount),
2957
- withoutTrailingZeros: () => amount % 1 === 0 ? withoutTrailingZerosFormatter().format(amount) : defaultFormatter().format(amount),
2958
- withoutTrailingZerosAndCurrency: () => amount % 1 === 0 ? withoutTrailingZerosOrCurrencyFormatter().format(amount) : withoutCurrencyFormatter().format(amount),
2959
- currencyName: () => {
2960
- var _a, _b;
2961
- return (_b = (_a = nameFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : money.currencyCode;
2962
- },
2963
- currencySymbol: () => {
2964
- var _a, _b;
2965
- return (_b = (_a = defaultFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : money.currencyCode;
2966
- },
2967
- currencyNarrowSymbol: () => {
2968
- var _a, _b;
2969
- return (_b = (_a = narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) != null ? _b : "";
2970
- },
2971
- amount: () => defaultFormatter().formatToParts(amount).filter((part) => ["decimal", "fraction", "group", "integer", "literal"].includes(part.type)).map((part) => part.value).join("")
2972
- }), [money, amount, nameFormatter, defaultFormatter, narrowSymbolFormatter, withoutCurrencyFormatter, withoutTrailingZerosFormatter, withoutTrailingZerosOrCurrencyFormatter]);
2973
- return React.useMemo(() => new Proxy(lazyFormatters, {
2974
- get: (target, key) => {
2975
- var _a;
2976
- return (_a = Reflect.get(target, key)) == null ? void 0 : _a.call(null);
2977
- }
2978
- }), [lazyFormatters]);
2979
- }
2980
- function useLazyFormatter(locale, options) {
2981
- return React.useMemo(() => {
2982
- let memoized;
2983
- return () => memoized != null ? memoized : memoized = new Intl.NumberFormat(locale, options);
2984
- }, [locale, options]);
2985
- }
2986
- var _jsxFileName$2 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Money.tsx";
2987
- function Money({
2988
- data,
2989
- as,
2990
- withoutCurrency,
2991
- withoutTrailingZeros,
2992
- measurement,
2993
- measurementSeparator = "/",
2994
- ...passthroughProps
2995
- }) {
2996
- if (!isMoney(data)) {
2997
- throw new Error(`<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`);
2998
- }
2999
- const moneyObject = useMoney(data);
3000
- const Wrapper = as != null ? as : "div";
3001
- let output = moneyObject.localizedString;
3002
- if (withoutCurrency || withoutTrailingZeros) {
3003
- if (withoutCurrency && !withoutTrailingZeros) {
3004
- output = moneyObject.amount;
3005
- } else if (!withoutCurrency && withoutTrailingZeros) {
3006
- output = moneyObject.withoutTrailingZeros;
3007
- } else {
3008
- output = moneyObject.withoutTrailingZerosAndCurrency;
3009
- }
3010
- }
3011
- return /* @__PURE__ */ React__default.default.createElement(Wrapper, {
3012
- ...passthroughProps,
3013
- __self: this,
3014
- __source: {
3015
- fileName: _jsxFileName$2,
3016
- lineNumber: 65,
3017
- columnNumber: 5
3018
- }
3019
- }, output, measurement && measurement.referenceUnit && /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, measurementSeparator, measurement.referenceUnit));
3020
- }
3021
- function isMoney(maybeMoney) {
3022
- return typeof maybeMoney.amount === "string" && !!maybeMoney.amount && typeof maybeMoney.currencyCode === "string" && !!maybeMoney.currencyCode;
3023
- }
3024
- var _jsxFileName$1 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductPrice.tsx";
3025
3667
  function ProductPrice(props) {
3026
- var _a, _b, _c, _d, _e, _f, _g, _h;
3668
+ var _a, _b, _c, _d, _e, _f;
3027
3669
  const {
3028
3670
  priceType = "regular",
3029
3671
  variantId,
@@ -3036,17 +3678,19 @@
3036
3678
  }
3037
3679
  let price;
3038
3680
  let measurement;
3039
- const variant = variantId ? (_b = flattenConnection((_a = product == null ? void 0 : product.variants) != null ? _a : {}).find((variant2) => (variant2 == null ? void 0 : variant2.id) === variantId)) != null ? _b : null : null;
3681
+ const variant = variantId ? flattenConnection((product == null ? void 0 : product.variants) ?? {}).find(
3682
+ (variant2) => (variant2 == null ? void 0 : variant2.id) === variantId
3683
+ ) ?? null : null;
3040
3684
  if (priceType === "compareAt") {
3041
3685
  if (variantId && variant) {
3042
- if (((_c = variant.compareAtPriceV2) == null ? void 0 : _c.amount) === ((_d = variant.priceV2) == null ? void 0 : _d.amount)) {
3686
+ if (((_a = variant.compareAtPriceV2) == null ? void 0 : _a.amount) === ((_b = variant.priceV2) == null ? void 0 : _b.amount)) {
3043
3687
  return null;
3044
3688
  }
3045
3689
  price = variant.compareAtPriceV2;
3046
3690
  } else if (valueType === "max") {
3047
- price = (_e = product == null ? void 0 : product.compareAtPriceRange) == null ? void 0 : _e.maxVariantPrice;
3691
+ price = (_c = product == null ? void 0 : product.compareAtPriceRange) == null ? void 0 : _c.maxVariantPrice;
3048
3692
  } else {
3049
- price = (_f = product == null ? void 0 : product.compareAtPriceRange) == null ? void 0 : _f.minVariantPrice;
3693
+ price = (_d = product == null ? void 0 : product.compareAtPriceRange) == null ? void 0 : _d.minVariantPrice;
3050
3694
  }
3051
3695
  } else {
3052
3696
  if (variantId && variant) {
@@ -3056,39 +3700,19 @@
3056
3700
  measurement = variant.unitPriceMeasurement;
3057
3701
  }
3058
3702
  } else if (valueType === "max") {
3059
- price = (_g = product.priceRange) == null ? void 0 : _g.maxVariantPrice;
3703
+ price = (_e = product.priceRange) == null ? void 0 : _e.maxVariantPrice;
3060
3704
  } else {
3061
- price = (_h = product.priceRange) == null ? void 0 : _h.minVariantPrice;
3705
+ price = (_f = product.priceRange) == null ? void 0 : _f.minVariantPrice;
3062
3706
  }
3063
3707
  }
3064
3708
  if (!price) {
3065
3709
  return null;
3066
3710
  }
3067
3711
  if (measurement) {
3068
- return /* @__PURE__ */ React__default.default.createElement(Money, {
3069
- ...passthroughProps,
3070
- data: price,
3071
- measurement,
3072
- __self: this,
3073
- __source: {
3074
- fileName: _jsxFileName$1,
3075
- lineNumber: 81,
3076
- columnNumber: 7
3077
- }
3078
- });
3712
+ return /* @__PURE__ */ React.createElement(Money, { ...passthroughProps, data: price, measurement });
3079
3713
  }
3080
- return /* @__PURE__ */ React__default.default.createElement(Money, {
3081
- ...passthroughProps,
3082
- data: price,
3083
- __self: this,
3084
- __source: {
3085
- fileName: _jsxFileName$1,
3086
- lineNumber: 85,
3087
- columnNumber: 10
3088
- }
3089
- });
3714
+ return /* @__PURE__ */ React.createElement(Money, { ...passthroughProps, data: price });
3090
3715
  }
3091
- var _jsxFileName = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopPayButton.tsx";
3092
3716
  const SHOPJS_URL = "https://cdn.shopify.com/shopifycloud/shop-js/v1.0/client.js";
3093
3717
  function ShopPayButton({
3094
3718
  variantIds,
@@ -3096,17 +3720,15 @@
3096
3720
  variantIdsAndQuantities,
3097
3721
  width
3098
3722
  }) {
3099
- const {
3100
- storeDomain
3101
- } = useShop();
3723
+ const { storeDomain } = useShop();
3102
3724
  const shopPayLoadedStatus = useLoadScript(SHOPJS_URL);
3103
- let ids;
3725
+ let ids = [];
3104
3726
  if (variantIds && variantIdsAndQuantities) {
3105
3727
  throw new Error(DoublePropsErrorMessage);
3106
3728
  }
3107
3729
  if (variantIds) {
3108
3730
  ids = variantIds.reduce((prev, curr) => {
3109
- const bareId = getIdFromGid(curr);
3731
+ const bareId = parseGid(curr).id;
3110
3732
  if (bareId) {
3111
3733
  prev.push(bareId);
3112
3734
  }
@@ -3114,49 +3736,67 @@
3114
3736
  }, []);
3115
3737
  } else if (variantIdsAndQuantities) {
3116
3738
  ids = variantIdsAndQuantities.reduce((prev, curr) => {
3117
- var _a;
3118
- const bareId = getIdFromGid(curr == null ? void 0 : curr.id);
3739
+ const bareId = parseGid(curr == null ? void 0 : curr.id).id;
3119
3740
  if (bareId) {
3120
- prev.push(`${bareId}:${(_a = curr == null ? void 0 : curr.quantity) != null ? _a : 1}`);
3741
+ prev.push(`${bareId}:${(curr == null ? void 0 : curr.quantity) ?? 1}`);
3121
3742
  }
3122
3743
  return prev;
3123
3744
  }, []);
3124
3745
  } else {
3125
3746
  throw new Error(MissingPropsErrorMessage);
3126
3747
  }
3748
+ if (ids.length === 0) {
3749
+ throw new Error(InvalidPropsErrorMessage);
3750
+ }
3127
3751
  const style = width ? {
3128
3752
  "--shop-pay-button-width": width
3129
3753
  } : void 0;
3130
- return /* @__PURE__ */ React__default.default.createElement("div", {
3131
- className,
3132
- style,
3133
- __self: this,
3134
- __source: {
3135
- fileName: _jsxFileName,
3136
- lineNumber: 90,
3137
- columnNumber: 5
3138
- }
3139
- }, shopPayLoadedStatus === "done" && /* @__PURE__ */ React__default.default.createElement("shop-pay-button", {
3140
- "store-url": storeDomain,
3141
- variants: ids.join(","),
3142
- __self: this,
3143
- __source: {
3144
- fileName: _jsxFileName,
3145
- lineNumber: 92,
3146
- columnNumber: 9
3147
- }
3148
- }));
3149
- }
3150
- function getIdFromGid(id) {
3151
- if (!id)
3152
- return;
3153
- return id.split("/").pop();
3754
+ return /* @__PURE__ */ React.createElement("div", { className, style }, shopPayLoadedStatus === "done" && /* @__PURE__ */ React.createElement("shop-pay-button", { "store-url": storeDomain, variants: ids.join(",") }));
3154
3755
  }
3756
+ const InvalidPropsErrorMessage = `You must pass in "variantIds" in the form of ["gid://shopify/ProductVariant/1"]`;
3155
3757
  const MissingPropsErrorMessage = `You must pass in either "variantIds" or "variantIdsAndQuantities" to ShopPayButton`;
3156
3758
  const DoublePropsErrorMessage = `You must provide either a variantIds or variantIdsAndQuantities prop, but not both in the ShopPayButton component`;
3759
+ const longTermLength = 60 * 60 * 24 * 360 * 1;
3760
+ const shortTermLength = 60 * 30;
3761
+ function useShopifyCookies(options) {
3762
+ const { hasUserConsent = false, domain = "" } = options || {};
3763
+ React.useEffect(() => {
3764
+ const cookies = getShopifyCookies(document.cookie);
3765
+ if (hasUserConsent) {
3766
+ setCookie(
3767
+ SHOPIFY_Y,
3768
+ cookies[SHOPIFY_Y] || buildUUID(),
3769
+ longTermLength,
3770
+ domain
3771
+ );
3772
+ setCookie(
3773
+ SHOPIFY_S,
3774
+ cookies[SHOPIFY_S] || buildUUID(),
3775
+ shortTermLength,
3776
+ domain
3777
+ );
3778
+ } else {
3779
+ setCookie(SHOPIFY_Y, "", 0, domain);
3780
+ setCookie(SHOPIFY_S, "", 0, domain);
3781
+ }
3782
+ });
3783
+ }
3784
+ function setCookie(name, value, maxage, domain) {
3785
+ document.cookie = l(name, value, {
3786
+ maxage,
3787
+ domain,
3788
+ samesite: "Lax",
3789
+ path: "/"
3790
+ });
3791
+ }
3157
3792
  exports2.AddToCartButton = AddToCartButton;
3793
+ exports2.AnalyticsEventName = AnalyticsEventName;
3794
+ exports2.AnalyticsPageType = AnalyticsPageType;
3158
3795
  exports2.BuyNowButton = BuyNowButton;
3159
3796
  exports2.CartCheckoutButton = CartCheckoutButton;
3797
+ exports2.CartCost = CartCost;
3798
+ exports2.CartLinePrice = CartLinePrice;
3799
+ exports2.CartLineProvider = CartLineProvider;
3160
3800
  exports2.CartProvider = CartProvider;
3161
3801
  exports2.ExternalVideo = ExternalVideo;
3162
3802
  exports2.Image = Image;
@@ -3167,15 +3807,21 @@
3167
3807
  exports2.ProductProvider = ProductProvider;
3168
3808
  exports2.ShopPayButton = ShopPayButton;
3169
3809
  exports2.ShopifyProvider = ShopifyProvider;
3810
+ exports2.ShopifySalesChannel = ShopifySalesChannel;
3170
3811
  exports2.Video = Video;
3171
3812
  exports2.createStorefrontClient = createStorefrontClient;
3172
3813
  exports2.flattenConnection = flattenConnection;
3814
+ exports2.getClientBrowserParameters = getClientBrowserParameters;
3815
+ exports2.getShopifyCookies = getShopifyCookies;
3173
3816
  exports2.parseMetafield = parseMetafield;
3817
+ exports2.sendShopifyAnalytics = sendShopifyAnalytics;
3174
3818
  exports2.storefrontApiCustomScalars = storefrontApiCustomScalars;
3175
3819
  exports2.useCart = useCart;
3820
+ exports2.useCartLine = useCartLine;
3176
3821
  exports2.useMoney = useMoney;
3177
3822
  exports2.useProduct = useProduct;
3178
3823
  exports2.useShop = useShop;
3179
- Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3824
+ exports2.useShopifyCookies = useShopifyCookies;
3825
+ Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
3180
3826
  });
3181
3827
  //# sourceMappingURL=hydrogen-react.dev.js.map