@shopify/hydrogen-react 2026.4.0 → 2026.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-dev/AddToCartButton.mjs +60 -71
- package/dist/browser-dev/AddToCartButton.mjs.map +1 -1
- package/dist/browser-dev/BaseButton.mjs +20 -26
- package/dist/browser-dev/BaseButton.mjs.map +1 -1
- package/dist/browser-dev/BuyNowButton.mjs +40 -45
- package/dist/browser-dev/BuyNowButton.mjs.map +1 -1
- package/dist/browser-dev/CartCheckoutButton.mjs +28 -23
- package/dist/browser-dev/CartCheckoutButton.mjs.map +1 -1
- package/dist/browser-dev/CartCost.mjs +26 -22
- package/dist/browser-dev/CartCost.mjs.map +1 -1
- package/dist/browser-dev/CartLineProvider.mjs +23 -18
- package/dist/browser-dev/CartLineProvider.mjs.map +1 -1
- package/dist/browser-dev/CartLineQuantity.mjs +18 -9
- package/dist/browser-dev/CartLineQuantity.mjs.map +1 -1
- package/dist/browser-dev/CartLineQuantityAdjustButton.mjs +48 -45
- package/dist/browser-dev/CartLineQuantityAdjustButton.mjs.map +1 -1
- package/dist/browser-dev/CartProvider.mjs +315 -385
- package/dist/browser-dev/CartProvider.mjs.map +1 -1
- package/dist/browser-dev/ExternalVideo.mjs +35 -47
- package/dist/browser-dev/ExternalVideo.mjs.map +1 -1
- package/dist/browser-dev/Image.mjs +335 -340
- package/dist/browser-dev/Image.mjs.map +1 -1
- package/dist/browser-dev/MediaFile.mjs +39 -61
- package/dist/browser-dev/MediaFile.mjs.map +1 -1
- package/dist/browser-dev/ModelViewer.mjs +115 -139
- package/dist/browser-dev/ModelViewer.mjs.map +1 -1
- package/dist/browser-dev/Money.mjs +53 -39
- package/dist/browser-dev/Money.mjs.map +1 -1
- package/dist/browser-dev/ProductPrice.mjs +44 -61
- package/dist/browser-dev/ProductPrice.mjs.map +1 -1
- package/dist/browser-dev/ProductProvider.mjs +147 -179
- package/dist/browser-dev/ProductProvider.mjs.map +1 -1
- package/dist/browser-dev/RichText.components.mjs +36 -46
- package/dist/browser-dev/RichText.components.mjs.map +1 -1
- package/dist/browser-dev/RichText.mjs +111 -154
- package/dist/browser-dev/RichText.mjs.map +1 -1
- package/dist/browser-dev/ShopPayButton.mjs +53 -81
- package/dist/browser-dev/ShopPayButton.mjs.map +1 -1
- package/dist/browser-dev/ShopifyProvider.mjs +71 -84
- package/dist/browser-dev/ShopifyProvider.mjs.map +1 -1
- package/dist/browser-dev/Video.mjs +35 -52
- package/dist/browser-dev/Video.mjs.map +1 -1
- package/dist/browser-dev/analytics-constants.mjs +41 -43
- package/dist/browser-dev/analytics-constants.mjs.map +1 -1
- package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs +127 -214
- package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
- package/dist/browser-dev/analytics-schema-trekkie-storefront-page-view.mjs +39 -50
- package/dist/browser-dev/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -1
- package/dist/browser-dev/analytics-utils.mjs +78 -56
- package/dist/browser-dev/analytics-utils.mjs.map +1 -1
- package/dist/browser-dev/analytics.mjs +112 -155
- package/dist/browser-dev/analytics.mjs.map +1 -1
- package/dist/browser-dev/cart-constants.mjs +11 -15
- package/dist/browser-dev/cart-constants.mjs.map +1 -1
- package/dist/browser-dev/cart-hooks.mjs +42 -57
- package/dist/browser-dev/cart-hooks.mjs.map +1 -1
- package/dist/browser-dev/cart-queries.mjs +59 -135
- package/dist/browser-dev/cart-queries.mjs.map +1 -1
- package/dist/browser-dev/codegen.helpers.mjs +31 -20
- package/dist/browser-dev/codegen.helpers.mjs.map +1 -1
- package/dist/browser-dev/cookies-utils.mjs +44 -42
- package/dist/browser-dev/cookies-utils.mjs.map +1 -1
- package/dist/browser-dev/flatten-connection.mjs +23 -29
- package/dist/browser-dev/flatten-connection.mjs.map +1 -1
- package/dist/browser-dev/getProductOptions.mjs +248 -226
- package/dist/browser-dev/getProductOptions.mjs.map +1 -1
- package/dist/browser-dev/index.mjs +15 -70
- package/dist/browser-dev/load-script.mjs +38 -49
- package/dist/browser-dev/load-script.mjs.map +1 -1
- package/dist/browser-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs +175 -123
- package/dist/browser-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/browser-dev/optionValueDecoder.mjs +104 -86
- package/dist/browser-dev/optionValueDecoder.mjs.map +1 -1
- package/dist/browser-dev/packages/hydrogen-react/package.mjs +6 -0
- package/dist/browser-dev/packages/hydrogen-react/package.mjs.map +1 -0
- package/dist/browser-dev/parse-metafield.mjs +122 -134
- package/dist/browser-dev/parse-metafield.mjs.map +1 -1
- package/dist/browser-dev/storefront-api-constants.mjs +6 -5
- package/dist/browser-dev/storefront-api-constants.mjs.map +1 -1
- package/dist/browser-dev/storefront-client.mjs +62 -102
- package/dist/browser-dev/storefront-client.mjs.map +1 -1
- package/dist/browser-dev/tracking-utils.mjs +68 -88
- package/dist/browser-dev/tracking-utils.mjs.map +1 -1
- package/dist/browser-dev/useCartAPIStateMachine.mjs +188 -346
- package/dist/browser-dev/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/browser-dev/useCartActions.mjs +197 -172
- package/dist/browser-dev/useCartActions.mjs.map +1 -1
- package/dist/browser-dev/useMachine.mjs +50 -62
- package/dist/browser-dev/useMachine.mjs.map +1 -1
- package/dist/browser-dev/useMoney.mjs +176 -154
- package/dist/browser-dev/useMoney.mjs.map +1 -1
- package/dist/browser-dev/useSelectedOptionInUrlParam.mjs +17 -27
- package/dist/browser-dev/useSelectedOptionInUrlParam.mjs.map +1 -1
- package/dist/browser-dev/useShopifyCookies.mjs +123 -138
- package/dist/browser-dev/useShopifyCookies.mjs.map +1 -1
- package/dist/browser-prod/AddToCartButton.mjs +60 -71
- package/dist/browser-prod/AddToCartButton.mjs.map +1 -1
- package/dist/browser-prod/BaseButton.mjs +20 -26
- package/dist/browser-prod/BaseButton.mjs.map +1 -1
- package/dist/browser-prod/BuyNowButton.mjs +40 -45
- package/dist/browser-prod/BuyNowButton.mjs.map +1 -1
- package/dist/browser-prod/CartCheckoutButton.mjs +28 -23
- package/dist/browser-prod/CartCheckoutButton.mjs.map +1 -1
- package/dist/browser-prod/CartCost.mjs +26 -22
- package/dist/browser-prod/CartCost.mjs.map +1 -1
- package/dist/browser-prod/CartLineProvider.mjs +23 -18
- package/dist/browser-prod/CartLineProvider.mjs.map +1 -1
- package/dist/browser-prod/CartLineQuantity.mjs +18 -9
- package/dist/browser-prod/CartLineQuantity.mjs.map +1 -1
- package/dist/browser-prod/CartLineQuantityAdjustButton.mjs +48 -45
- package/dist/browser-prod/CartLineQuantityAdjustButton.mjs.map +1 -1
- package/dist/browser-prod/CartProvider.mjs +315 -385
- package/dist/browser-prod/CartProvider.mjs.map +1 -1
- package/dist/browser-prod/ExternalVideo.mjs +35 -47
- package/dist/browser-prod/ExternalVideo.mjs.map +1 -1
- package/dist/browser-prod/Image.mjs +326 -325
- package/dist/browser-prod/Image.mjs.map +1 -1
- package/dist/browser-prod/MediaFile.mjs +44 -63
- package/dist/browser-prod/MediaFile.mjs.map +1 -1
- package/dist/browser-prod/ModelViewer.mjs +117 -135
- package/dist/browser-prod/ModelViewer.mjs.map +1 -1
- package/dist/browser-prod/Money.mjs +53 -39
- package/dist/browser-prod/Money.mjs.map +1 -1
- package/dist/browser-prod/ProductPrice.mjs +44 -61
- package/dist/browser-prod/ProductPrice.mjs.map +1 -1
- package/dist/browser-prod/ProductProvider.mjs +147 -179
- package/dist/browser-prod/ProductProvider.mjs.map +1 -1
- package/dist/browser-prod/RichText.components.mjs +36 -46
- package/dist/browser-prod/RichText.components.mjs.map +1 -1
- package/dist/browser-prod/RichText.mjs +111 -154
- package/dist/browser-prod/RichText.mjs.map +1 -1
- package/dist/browser-prod/ShopPayButton.mjs +53 -81
- package/dist/browser-prod/ShopPayButton.mjs.map +1 -1
- package/dist/browser-prod/ShopifyProvider.mjs +71 -84
- package/dist/browser-prod/ShopifyProvider.mjs.map +1 -1
- package/dist/browser-prod/Video.mjs +35 -52
- package/dist/browser-prod/Video.mjs.map +1 -1
- package/dist/browser-prod/analytics-constants.mjs +41 -43
- package/dist/browser-prod/analytics-constants.mjs.map +1 -1
- package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs +127 -214
- package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
- package/dist/browser-prod/analytics-schema-trekkie-storefront-page-view.mjs +39 -50
- package/dist/browser-prod/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -1
- package/dist/browser-prod/analytics-utils.mjs +78 -56
- package/dist/browser-prod/analytics-utils.mjs.map +1 -1
- package/dist/browser-prod/analytics.mjs +111 -153
- package/dist/browser-prod/analytics.mjs.map +1 -1
- package/dist/browser-prod/cart-constants.mjs +11 -15
- package/dist/browser-prod/cart-constants.mjs.map +1 -1
- package/dist/browser-prod/cart-hooks.mjs +42 -57
- package/dist/browser-prod/cart-hooks.mjs.map +1 -1
- package/dist/browser-prod/cart-queries.mjs +59 -135
- package/dist/browser-prod/cart-queries.mjs.map +1 -1
- package/dist/browser-prod/codegen.helpers.mjs +31 -20
- package/dist/browser-prod/codegen.helpers.mjs.map +1 -1
- package/dist/browser-prod/cookies-utils.mjs +44 -42
- package/dist/browser-prod/cookies-utils.mjs.map +1 -1
- package/dist/browser-prod/flatten-connection.mjs +23 -25
- package/dist/browser-prod/flatten-connection.mjs.map +1 -1
- package/dist/browser-prod/getProductOptions.mjs +248 -226
- package/dist/browser-prod/getProductOptions.mjs.map +1 -1
- package/dist/browser-prod/index.mjs +15 -70
- package/dist/browser-prod/load-script.mjs +38 -49
- package/dist/browser-prod/load-script.mjs.map +1 -1
- package/dist/browser-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs +175 -123
- package/dist/browser-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/browser-prod/optionValueDecoder.mjs +104 -86
- package/dist/browser-prod/optionValueDecoder.mjs.map +1 -1
- package/dist/browser-prod/packages/hydrogen-react/package.mjs +6 -0
- package/dist/browser-prod/packages/hydrogen-react/package.mjs.map +1 -0
- package/dist/browser-prod/parse-metafield.mjs +134 -146
- package/dist/browser-prod/parse-metafield.mjs.map +1 -1
- package/dist/browser-prod/storefront-api-constants.mjs +6 -5
- package/dist/browser-prod/storefront-api-constants.mjs.map +1 -1
- package/dist/browser-prod/storefront-client.mjs +56 -84
- package/dist/browser-prod/storefront-client.mjs.map +1 -1
- package/dist/browser-prod/tracking-utils.mjs +68 -88
- package/dist/browser-prod/tracking-utils.mjs.map +1 -1
- package/dist/browser-prod/useCartAPIStateMachine.mjs +188 -346
- package/dist/browser-prod/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/browser-prod/useCartActions.mjs +197 -172
- package/dist/browser-prod/useCartActions.mjs.map +1 -1
- package/dist/browser-prod/useMachine.mjs +50 -62
- package/dist/browser-prod/useMachine.mjs.map +1 -1
- package/dist/browser-prod/useMoney.mjs +176 -154
- package/dist/browser-prod/useMoney.mjs.map +1 -1
- package/dist/browser-prod/useSelectedOptionInUrlParam.mjs +17 -27
- package/dist/browser-prod/useSelectedOptionInUrlParam.mjs.map +1 -1
- package/dist/browser-prod/useShopifyCookies.mjs +123 -138
- package/dist/browser-prod/useShopifyCookies.mjs.map +1 -1
- package/dist/node-dev/AddToCartButton.js +64 -73
- package/dist/node-dev/AddToCartButton.js.map +1 -1
- package/dist/node-dev/AddToCartButton.mjs +60 -71
- package/dist/node-dev/AddToCartButton.mjs.map +1 -1
- package/dist/node-dev/BaseButton.js +21 -26
- package/dist/node-dev/BaseButton.js.map +1 -1
- package/dist/node-dev/BaseButton.mjs +20 -26
- package/dist/node-dev/BaseButton.mjs.map +1 -1
- package/dist/node-dev/BuyNowButton.js +42 -46
- package/dist/node-dev/BuyNowButton.js.map +1 -1
- package/dist/node-dev/BuyNowButton.mjs +40 -45
- package/dist/node-dev/BuyNowButton.mjs.map +1 -1
- package/dist/node-dev/CartCheckoutButton.js +30 -24
- package/dist/node-dev/CartCheckoutButton.js.map +1 -1
- package/dist/node-dev/CartCheckoutButton.mjs +28 -23
- package/dist/node-dev/CartCheckoutButton.mjs.map +1 -1
- package/dist/node-dev/CartCost.js +27 -22
- package/dist/node-dev/CartCost.js.map +1 -1
- package/dist/node-dev/CartCost.mjs +26 -22
- package/dist/node-dev/CartCost.mjs.map +1 -1
- package/dist/node-dev/CartLineProvider.js +24 -17
- package/dist/node-dev/CartLineProvider.js.map +1 -1
- package/dist/node-dev/CartLineProvider.mjs +23 -18
- package/dist/node-dev/CartLineProvider.mjs.map +1 -1
- package/dist/node-dev/CartLineQuantity.js +19 -9
- package/dist/node-dev/CartLineQuantity.js.map +1 -1
- package/dist/node-dev/CartLineQuantity.mjs +18 -9
- package/dist/node-dev/CartLineQuantity.mjs.map +1 -1
- package/dist/node-dev/CartLineQuantityAdjustButton.js +50 -46
- package/dist/node-dev/CartLineQuantityAdjustButton.js.map +1 -1
- package/dist/node-dev/CartLineQuantityAdjustButton.mjs +48 -45
- package/dist/node-dev/CartLineQuantityAdjustButton.mjs.map +1 -1
- package/dist/node-dev/CartProvider.js +317 -385
- package/dist/node-dev/CartProvider.js.map +1 -1
- package/dist/node-dev/CartProvider.mjs +315 -385
- package/dist/node-dev/CartProvider.mjs.map +1 -1
- package/dist/node-dev/ExternalVideo.js +36 -47
- package/dist/node-dev/ExternalVideo.js.map +1 -1
- package/dist/node-dev/ExternalVideo.mjs +35 -47
- package/dist/node-dev/ExternalVideo.mjs.map +1 -1
- package/dist/node-dev/Image.js +337 -355
- package/dist/node-dev/Image.js.map +1 -1
- package/dist/node-dev/Image.mjs +335 -340
- package/dist/node-dev/Image.mjs.map +1 -1
- package/dist/node-dev/MediaFile.js +42 -63
- package/dist/node-dev/MediaFile.js.map +1 -1
- package/dist/node-dev/MediaFile.mjs +39 -61
- package/dist/node-dev/MediaFile.mjs.map +1 -1
- package/dist/node-dev/ModelViewer.js +116 -139
- package/dist/node-dev/ModelViewer.js.map +1 -1
- package/dist/node-dev/ModelViewer.mjs +115 -139
- package/dist/node-dev/ModelViewer.mjs.map +1 -1
- package/dist/node-dev/Money.js +54 -39
- package/dist/node-dev/Money.js.map +1 -1
- package/dist/node-dev/Money.mjs +53 -39
- package/dist/node-dev/Money.mjs.map +1 -1
- package/dist/node-dev/ProductPrice.js +45 -61
- package/dist/node-dev/ProductPrice.js.map +1 -1
- package/dist/node-dev/ProductPrice.mjs +44 -61
- package/dist/node-dev/ProductPrice.mjs.map +1 -1
- package/dist/node-dev/ProductProvider.js +148 -178
- package/dist/node-dev/ProductProvider.js.map +1 -1
- package/dist/node-dev/ProductProvider.mjs +147 -179
- package/dist/node-dev/ProductProvider.mjs.map +1 -1
- package/dist/node-dev/RichText.components.js +37 -46
- package/dist/node-dev/RichText.components.js.map +1 -1
- package/dist/node-dev/RichText.components.mjs +36 -46
- package/dist/node-dev/RichText.components.mjs.map +1 -1
- package/dist/node-dev/RichText.js +112 -154
- package/dist/node-dev/RichText.js.map +1 -1
- package/dist/node-dev/RichText.mjs +111 -154
- package/dist/node-dev/RichText.mjs.map +1 -1
- package/dist/node-dev/ShopPayButton.js +54 -81
- package/dist/node-dev/ShopPayButton.js.map +1 -1
- package/dist/node-dev/ShopPayButton.mjs +53 -81
- package/dist/node-dev/ShopPayButton.mjs.map +1 -1
- package/dist/node-dev/ShopifyProvider.js +73 -83
- package/dist/node-dev/ShopifyProvider.js.map +1 -1
- package/dist/node-dev/ShopifyProvider.mjs +71 -84
- package/dist/node-dev/ShopifyProvider.mjs.map +1 -1
- package/dist/node-dev/Video.js +36 -52
- package/dist/node-dev/Video.js.map +1 -1
- package/dist/node-dev/Video.mjs +35 -52
- package/dist/node-dev/Video.mjs.map +1 -1
- package/dist/node-dev/_virtual/_rolldown/runtime.js +23 -0
- package/dist/node-dev/analytics-constants.js +40 -39
- package/dist/node-dev/analytics-constants.js.map +1 -1
- package/dist/node-dev/analytics-constants.mjs +41 -43
- package/dist/node-dev/analytics-constants.mjs.map +1 -1
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js +128 -210
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js.map +1 -1
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs +127 -214
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.js +40 -51
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.js.map +1 -1
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.mjs +39 -50
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -1
- package/dist/node-dev/analytics-utils.js +77 -52
- package/dist/node-dev/analytics-utils.js.map +1 -1
- package/dist/node-dev/analytics-utils.mjs +78 -56
- package/dist/node-dev/analytics-utils.mjs.map +1 -1
- package/dist/node-dev/analytics.js +114 -156
- package/dist/node-dev/analytics.js.map +1 -1
- package/dist/node-dev/analytics.mjs +112 -155
- package/dist/node-dev/analytics.mjs.map +1 -1
- package/dist/node-dev/cart-constants.js +10 -9
- package/dist/node-dev/cart-constants.js.map +1 -1
- package/dist/node-dev/cart-constants.mjs +11 -15
- package/dist/node-dev/cart-constants.mjs.map +1 -1
- package/dist/node-dev/cart-hooks.js +43 -57
- package/dist/node-dev/cart-hooks.js.map +1 -1
- package/dist/node-dev/cart-hooks.mjs +42 -57
- package/dist/node-dev/cart-hooks.mjs.map +1 -1
- package/dist/node-dev/cart-queries.js +58 -125
- package/dist/node-dev/cart-queries.js.map +1 -1
- package/dist/node-dev/cart-queries.mjs +59 -135
- package/dist/node-dev/cart-queries.mjs.map +1 -1
- package/dist/node-dev/codegen.helpers.js +30 -18
- package/dist/node-dev/codegen.helpers.js.map +1 -1
- package/dist/node-dev/codegen.helpers.mjs +31 -20
- package/dist/node-dev/codegen.helpers.mjs.map +1 -1
- package/dist/node-dev/cookies-utils.js +45 -42
- package/dist/node-dev/cookies-utils.js.map +1 -1
- package/dist/node-dev/cookies-utils.mjs +44 -42
- package/dist/node-dev/cookies-utils.mjs.map +1 -1
- package/dist/node-dev/flatten-connection.js +22 -28
- package/dist/node-dev/flatten-connection.js.map +1 -1
- package/dist/node-dev/flatten-connection.mjs +23 -29
- package/dist/node-dev/flatten-connection.mjs.map +1 -1
- package/dist/node-dev/getProductOptions.js +248 -224
- package/dist/node-dev/getProductOptions.js.map +1 -1
- package/dist/node-dev/getProductOptions.mjs +248 -226
- package/dist/node-dev/getProductOptions.mjs.map +1 -1
- package/dist/node-dev/index.js +88 -90
- package/dist/node-dev/index.mjs +15 -70
- package/dist/node-dev/load-script.js +38 -48
- package/dist/node-dev/load-script.js.map +1 -1
- package/dist/node-dev/load-script.mjs +38 -49
- package/dist/node-dev/load-script.mjs.map +1 -1
- package/dist/node-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.js +185 -124
- package/dist/node-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.js.map +1 -1
- package/dist/node-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs +175 -123
- package/dist/node-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/node-dev/optionValueDecoder.js +103 -84
- package/dist/node-dev/optionValueDecoder.js.map +1 -1
- package/dist/node-dev/optionValueDecoder.mjs +104 -86
- package/dist/node-dev/optionValueDecoder.mjs.map +1 -1
- package/dist/node-dev/packages/hydrogen-react/package.js +6 -0
- package/dist/node-dev/packages/hydrogen-react/package.js.map +1 -0
- package/dist/node-dev/packages/hydrogen-react/package.mjs +6 -0
- package/dist/node-dev/packages/hydrogen-react/package.mjs.map +1 -0
- package/dist/node-dev/parse-metafield.js +122 -134
- package/dist/node-dev/parse-metafield.js.map +1 -1
- package/dist/node-dev/parse-metafield.mjs +122 -134
- package/dist/node-dev/parse-metafield.mjs.map +1 -1
- package/dist/node-dev/storefront-api-constants.js +5 -4
- package/dist/node-dev/storefront-api-constants.js.map +1 -1
- package/dist/node-dev/storefront-api-constants.mjs +6 -5
- package/dist/node-dev/storefront-api-constants.mjs.map +1 -1
- package/dist/node-dev/storefront-client.js +62 -101
- package/dist/node-dev/storefront-client.js.map +1 -1
- package/dist/node-dev/storefront-client.mjs +62 -102
- package/dist/node-dev/storefront-client.mjs.map +1 -1
- package/dist/node-dev/tracking-utils.js +67 -85
- package/dist/node-dev/tracking-utils.js.map +1 -1
- package/dist/node-dev/tracking-utils.mjs +68 -88
- package/dist/node-dev/tracking-utils.mjs.map +1 -1
- package/dist/node-dev/useCartAPIStateMachine.js +192 -349
- package/dist/node-dev/useCartAPIStateMachine.js.map +1 -1
- package/dist/node-dev/useCartAPIStateMachine.mjs +188 -346
- package/dist/node-dev/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/node-dev/useCartActions.js +198 -172
- package/dist/node-dev/useCartActions.js.map +1 -1
- package/dist/node-dev/useCartActions.mjs +197 -172
- package/dist/node-dev/useCartActions.mjs.map +1 -1
- package/dist/node-dev/useMachine.js +50 -61
- package/dist/node-dev/useMachine.js.map +1 -1
- package/dist/node-dev/useMachine.mjs +50 -62
- package/dist/node-dev/useMachine.mjs.map +1 -1
- package/dist/node-dev/useMoney.js +177 -154
- package/dist/node-dev/useMoney.js.map +1 -1
- package/dist/node-dev/useMoney.mjs +176 -154
- package/dist/node-dev/useMoney.mjs.map +1 -1
- package/dist/node-dev/useSelectedOptionInUrlParam.js +18 -27
- package/dist/node-dev/useSelectedOptionInUrlParam.js.map +1 -1
- package/dist/node-dev/useSelectedOptionInUrlParam.mjs +17 -27
- package/dist/node-dev/useSelectedOptionInUrlParam.mjs.map +1 -1
- package/dist/node-dev/useShopifyCookies.js +124 -138
- package/dist/node-dev/useShopifyCookies.js.map +1 -1
- package/dist/node-dev/useShopifyCookies.mjs +123 -138
- package/dist/node-dev/useShopifyCookies.mjs.map +1 -1
- package/dist/node-prod/AddToCartButton.js +64 -73
- package/dist/node-prod/AddToCartButton.js.map +1 -1
- package/dist/node-prod/AddToCartButton.mjs +60 -71
- package/dist/node-prod/AddToCartButton.mjs.map +1 -1
- package/dist/node-prod/BaseButton.js +21 -26
- package/dist/node-prod/BaseButton.js.map +1 -1
- package/dist/node-prod/BaseButton.mjs +20 -26
- package/dist/node-prod/BaseButton.mjs.map +1 -1
- package/dist/node-prod/BuyNowButton.js +42 -46
- package/dist/node-prod/BuyNowButton.js.map +1 -1
- package/dist/node-prod/BuyNowButton.mjs +40 -45
- package/dist/node-prod/BuyNowButton.mjs.map +1 -1
- package/dist/node-prod/CartCheckoutButton.js +30 -24
- package/dist/node-prod/CartCheckoutButton.js.map +1 -1
- package/dist/node-prod/CartCheckoutButton.mjs +28 -23
- package/dist/node-prod/CartCheckoutButton.mjs.map +1 -1
- package/dist/node-prod/CartCost.js +27 -22
- package/dist/node-prod/CartCost.js.map +1 -1
- package/dist/node-prod/CartCost.mjs +26 -22
- package/dist/node-prod/CartCost.mjs.map +1 -1
- package/dist/node-prod/CartLineProvider.js +24 -17
- package/dist/node-prod/CartLineProvider.js.map +1 -1
- package/dist/node-prod/CartLineProvider.mjs +23 -18
- package/dist/node-prod/CartLineProvider.mjs.map +1 -1
- package/dist/node-prod/CartLineQuantity.js +19 -9
- package/dist/node-prod/CartLineQuantity.js.map +1 -1
- package/dist/node-prod/CartLineQuantity.mjs +18 -9
- package/dist/node-prod/CartLineQuantity.mjs.map +1 -1
- package/dist/node-prod/CartLineQuantityAdjustButton.js +50 -46
- package/dist/node-prod/CartLineQuantityAdjustButton.js.map +1 -1
- package/dist/node-prod/CartLineQuantityAdjustButton.mjs +48 -45
- package/dist/node-prod/CartLineQuantityAdjustButton.mjs.map +1 -1
- package/dist/node-prod/CartProvider.js +317 -385
- package/dist/node-prod/CartProvider.js.map +1 -1
- package/dist/node-prod/CartProvider.mjs +315 -385
- package/dist/node-prod/CartProvider.mjs.map +1 -1
- package/dist/node-prod/ExternalVideo.js +36 -47
- package/dist/node-prod/ExternalVideo.js.map +1 -1
- package/dist/node-prod/ExternalVideo.mjs +35 -47
- package/dist/node-prod/ExternalVideo.mjs.map +1 -1
- package/dist/node-prod/Image.js +328 -340
- package/dist/node-prod/Image.js.map +1 -1
- package/dist/node-prod/Image.mjs +326 -325
- package/dist/node-prod/Image.mjs.map +1 -1
- package/dist/node-prod/MediaFile.js +47 -65
- package/dist/node-prod/MediaFile.js.map +1 -1
- package/dist/node-prod/MediaFile.mjs +44 -63
- package/dist/node-prod/MediaFile.mjs.map +1 -1
- package/dist/node-prod/ModelViewer.js +118 -135
- package/dist/node-prod/ModelViewer.js.map +1 -1
- package/dist/node-prod/ModelViewer.mjs +117 -135
- package/dist/node-prod/ModelViewer.mjs.map +1 -1
- package/dist/node-prod/Money.js +54 -39
- package/dist/node-prod/Money.js.map +1 -1
- package/dist/node-prod/Money.mjs +53 -39
- package/dist/node-prod/Money.mjs.map +1 -1
- package/dist/node-prod/ProductPrice.js +45 -61
- package/dist/node-prod/ProductPrice.js.map +1 -1
- package/dist/node-prod/ProductPrice.mjs +44 -61
- package/dist/node-prod/ProductPrice.mjs.map +1 -1
- package/dist/node-prod/ProductProvider.js +148 -178
- package/dist/node-prod/ProductProvider.js.map +1 -1
- package/dist/node-prod/ProductProvider.mjs +147 -179
- package/dist/node-prod/ProductProvider.mjs.map +1 -1
- package/dist/node-prod/RichText.components.js +37 -46
- package/dist/node-prod/RichText.components.js.map +1 -1
- package/dist/node-prod/RichText.components.mjs +36 -46
- package/dist/node-prod/RichText.components.mjs.map +1 -1
- package/dist/node-prod/RichText.js +112 -154
- package/dist/node-prod/RichText.js.map +1 -1
- package/dist/node-prod/RichText.mjs +111 -154
- package/dist/node-prod/RichText.mjs.map +1 -1
- package/dist/node-prod/ShopPayButton.js +54 -81
- package/dist/node-prod/ShopPayButton.js.map +1 -1
- package/dist/node-prod/ShopPayButton.mjs +53 -81
- package/dist/node-prod/ShopPayButton.mjs.map +1 -1
- package/dist/node-prod/ShopifyProvider.js +73 -83
- package/dist/node-prod/ShopifyProvider.js.map +1 -1
- package/dist/node-prod/ShopifyProvider.mjs +71 -84
- package/dist/node-prod/ShopifyProvider.mjs.map +1 -1
- package/dist/node-prod/Video.js +36 -52
- package/dist/node-prod/Video.js.map +1 -1
- package/dist/node-prod/Video.mjs +35 -52
- package/dist/node-prod/Video.mjs.map +1 -1
- package/dist/node-prod/_virtual/_rolldown/runtime.js +23 -0
- package/dist/node-prod/analytics-constants.js +40 -39
- package/dist/node-prod/analytics-constants.js.map +1 -1
- package/dist/node-prod/analytics-constants.mjs +41 -43
- package/dist/node-prod/analytics-constants.mjs.map +1 -1
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js +128 -210
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js.map +1 -1
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs +127 -214
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.js +40 -51
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.js.map +1 -1
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.mjs +39 -50
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -1
- package/dist/node-prod/analytics-utils.js +77 -52
- package/dist/node-prod/analytics-utils.js.map +1 -1
- package/dist/node-prod/analytics-utils.mjs +78 -56
- package/dist/node-prod/analytics-utils.mjs.map +1 -1
- package/dist/node-prod/analytics.js +113 -154
- package/dist/node-prod/analytics.js.map +1 -1
- package/dist/node-prod/analytics.mjs +111 -153
- package/dist/node-prod/analytics.mjs.map +1 -1
- package/dist/node-prod/cart-constants.js +10 -9
- package/dist/node-prod/cart-constants.js.map +1 -1
- package/dist/node-prod/cart-constants.mjs +11 -15
- package/dist/node-prod/cart-constants.mjs.map +1 -1
- package/dist/node-prod/cart-hooks.js +43 -57
- package/dist/node-prod/cart-hooks.js.map +1 -1
- package/dist/node-prod/cart-hooks.mjs +42 -57
- package/dist/node-prod/cart-hooks.mjs.map +1 -1
- package/dist/node-prod/cart-queries.js +58 -125
- package/dist/node-prod/cart-queries.js.map +1 -1
- package/dist/node-prod/cart-queries.mjs +59 -135
- package/dist/node-prod/cart-queries.mjs.map +1 -1
- package/dist/node-prod/codegen.helpers.js +30 -18
- package/dist/node-prod/codegen.helpers.js.map +1 -1
- package/dist/node-prod/codegen.helpers.mjs +31 -20
- package/dist/node-prod/codegen.helpers.mjs.map +1 -1
- package/dist/node-prod/cookies-utils.js +45 -42
- package/dist/node-prod/cookies-utils.js.map +1 -1
- package/dist/node-prod/cookies-utils.mjs +44 -42
- package/dist/node-prod/cookies-utils.mjs.map +1 -1
- package/dist/node-prod/flatten-connection.js +22 -24
- package/dist/node-prod/flatten-connection.js.map +1 -1
- package/dist/node-prod/flatten-connection.mjs +23 -25
- package/dist/node-prod/flatten-connection.mjs.map +1 -1
- package/dist/node-prod/getProductOptions.js +248 -224
- package/dist/node-prod/getProductOptions.js.map +1 -1
- package/dist/node-prod/getProductOptions.mjs +248 -226
- package/dist/node-prod/getProductOptions.mjs.map +1 -1
- package/dist/node-prod/index.js +88 -90
- package/dist/node-prod/index.mjs +15 -70
- package/dist/node-prod/load-script.js +38 -48
- package/dist/node-prod/load-script.js.map +1 -1
- package/dist/node-prod/load-script.mjs +38 -49
- package/dist/node-prod/load-script.mjs.map +1 -1
- package/dist/node-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.js +185 -124
- package/dist/node-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.js.map +1 -1
- package/dist/node-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs +175 -123
- package/dist/node-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/node-prod/optionValueDecoder.js +103 -84
- package/dist/node-prod/optionValueDecoder.js.map +1 -1
- package/dist/node-prod/optionValueDecoder.mjs +104 -86
- package/dist/node-prod/optionValueDecoder.mjs.map +1 -1
- package/dist/node-prod/packages/hydrogen-react/package.js +6 -0
- package/dist/node-prod/packages/hydrogen-react/package.js.map +1 -0
- package/dist/node-prod/packages/hydrogen-react/package.mjs +6 -0
- package/dist/node-prod/packages/hydrogen-react/package.mjs.map +1 -0
- package/dist/node-prod/parse-metafield.js +134 -146
- package/dist/node-prod/parse-metafield.js.map +1 -1
- package/dist/node-prod/parse-metafield.mjs +134 -146
- package/dist/node-prod/parse-metafield.mjs.map +1 -1
- package/dist/node-prod/storefront-api-constants.js +5 -4
- package/dist/node-prod/storefront-api-constants.js.map +1 -1
- package/dist/node-prod/storefront-api-constants.mjs +6 -5
- package/dist/node-prod/storefront-api-constants.mjs.map +1 -1
- package/dist/node-prod/storefront-client.js +56 -83
- package/dist/node-prod/storefront-client.js.map +1 -1
- package/dist/node-prod/storefront-client.mjs +56 -84
- package/dist/node-prod/storefront-client.mjs.map +1 -1
- package/dist/node-prod/tracking-utils.js +67 -85
- package/dist/node-prod/tracking-utils.js.map +1 -1
- package/dist/node-prod/tracking-utils.mjs +68 -88
- package/dist/node-prod/tracking-utils.mjs.map +1 -1
- package/dist/node-prod/useCartAPIStateMachine.js +192 -349
- package/dist/node-prod/useCartAPIStateMachine.js.map +1 -1
- package/dist/node-prod/useCartAPIStateMachine.mjs +188 -346
- package/dist/node-prod/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/node-prod/useCartActions.js +198 -172
- package/dist/node-prod/useCartActions.js.map +1 -1
- package/dist/node-prod/useCartActions.mjs +197 -172
- package/dist/node-prod/useCartActions.mjs.map +1 -1
- package/dist/node-prod/useMachine.js +50 -61
- package/dist/node-prod/useMachine.js.map +1 -1
- package/dist/node-prod/useMachine.mjs +50 -62
- package/dist/node-prod/useMachine.mjs.map +1 -1
- package/dist/node-prod/useMoney.js +177 -154
- package/dist/node-prod/useMoney.js.map +1 -1
- package/dist/node-prod/useMoney.mjs +176 -154
- package/dist/node-prod/useMoney.mjs.map +1 -1
- package/dist/node-prod/useSelectedOptionInUrlParam.js +18 -27
- package/dist/node-prod/useSelectedOptionInUrlParam.js.map +1 -1
- package/dist/node-prod/useSelectedOptionInUrlParam.mjs +17 -27
- package/dist/node-prod/useSelectedOptionInUrlParam.mjs.map +1 -1
- package/dist/node-prod/useShopifyCookies.js +124 -138
- package/dist/node-prod/useShopifyCookies.js.map +1 -1
- package/dist/node-prod/useShopifyCookies.mjs +123 -138
- package/dist/node-prod/useShopifyCookies.mjs.map +1 -1
- package/dist/types/AddToCartButton.d.ts +2 -0
- package/dist/types/BuyNowButton.d.ts +2 -0
- package/dist/types/CartCheckoutButton.d.ts +2 -0
- package/dist/types/CartCost.d.ts +2 -0
- package/dist/types/CartLineProvider.d.ts +2 -0
- package/dist/types/CartLineQuantity.d.ts +2 -0
- package/dist/types/CartLineQuantityAdjustButton.d.ts +1 -0
- package/dist/types/CartProvider.d.ts +7 -1
- package/dist/types/ExternalVideo.d.ts +4 -0
- package/dist/types/Image.d.ts +2 -0
- package/dist/types/MediaFile.d.ts +4 -0
- package/dist/types/ModelViewer.d.ts +1 -0
- package/dist/types/Money.d.ts +1 -0
- package/dist/types/ProductPrice.d.ts +2 -0
- package/dist/types/ProductProvider.d.ts +2 -0
- package/dist/types/RichText.d.ts +2 -0
- package/dist/types/ShopPayButton.d.ts +1 -0
- package/dist/types/ShopifyProvider.d.ts +2 -0
- package/dist/types/Video.d.ts +2 -0
- package/dist/types/analytics-constants.d.ts +9 -0
- package/dist/types/analytics-types.d.ts +1 -0
- package/dist/types/analytics-utils.d.ts +1 -0
- package/dist/types/analytics.d.ts +6 -1
- package/dist/types/cart-queries.d.ts +13 -9
- package/dist/types/codegen.helpers.d.ts +2 -0
- package/dist/types/cookies-utils.d.ts +2 -1
- package/dist/types/flatten-connection.d.ts +3 -0
- package/dist/types/getProductOptions.d.ts +3 -0
- package/dist/types/load-script.d.ts +3 -1
- package/dist/types/optionValueDecoder.d.ts +3 -0
- package/dist/types/parse-metafield.d.ts +1 -0
- package/dist/types/storefront-client.d.ts +1 -0
- package/dist/types/tracking-utils.d.ts +2 -2
- package/dist/types/useMoney.d.ts +1 -0
- package/dist/types/useSelectedOptionInUrlParam.d.ts +1 -0
- package/dist/types/useShopifyCookies.d.ts +1 -0
- package/dist/umd/hydrogen-react.dev.js +3957 -4483
- package/dist/umd/hydrogen-react.dev.js.map +1 -1
- package/dist/umd/hydrogen-react.prod.js +42 -101
- package/dist/umd/hydrogen-react.prod.js.map +1 -1
- package/package.json +5 -5
- package/dist/browser-dev/index.mjs.map +0 -1
- package/dist/browser-dev/packages/hydrogen-react/package.json.mjs +0 -5
- package/dist/browser-dev/packages/hydrogen-react/package.json.mjs.map +0 -1
- package/dist/browser-prod/index.mjs.map +0 -1
- package/dist/browser-prod/packages/hydrogen-react/package.json.mjs +0 -5
- package/dist/browser-prod/packages/hydrogen-react/package.json.mjs.map +0 -1
- package/dist/node-dev/index.js.map +0 -1
- package/dist/node-dev/index.mjs.map +0 -1
- package/dist/node-dev/packages/hydrogen-react/package.json.js +0 -5
- package/dist/node-dev/packages/hydrogen-react/package.json.js.map +0 -1
- package/dist/node-dev/packages/hydrogen-react/package.json.mjs +0 -5
- package/dist/node-dev/packages/hydrogen-react/package.json.mjs.map +0 -1
- package/dist/node-prod/index.js.map +0 -1
- package/dist/node-prod/index.mjs.map +0 -1
- package/dist/node-prod/packages/hydrogen-react/package.json.js +0 -5
- package/dist/node-prod/packages/hydrogen-react/package.json.js.map +0 -1
- package/dist/node-prod/packages/hydrogen-react/package.json.mjs +0 -5
- package/dist/node-prod/packages/hydrogen-react/package.json.mjs.map +0 -1
|
@@ -1,43 +1,57 @@
|
|
|
1
|
-
import { jsxs, Fragment } from "react/jsx-runtime";
|
|
2
1
|
import { useMoney } from "./useMoney.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
import { Fragment, jsxs } from "react/jsx-runtime";
|
|
3
|
+
//#region src/Money.tsx
|
|
4
|
+
/**
|
|
5
|
+
* The `Money` component renders a string of the [Storefront API's MoneyV2 object](https://shopify.dev/docs/api/storefront/2026-04/objects/MoneyV2)
|
|
6
|
+
* or the [Customer Account API's MoneyV2 object](https://shopify.dev/docs/api/customer/2026-04/objects/moneyv2)
|
|
7
|
+
* according to the `locale` in the `ShopifyProvider` component.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://shopify.dev/api/hydrogen/components/money}
|
|
10
|
+
* @example basic usage, outputs: $100.00
|
|
11
|
+
* ```ts
|
|
12
|
+
* <Money data={{amount: '100.00', currencyCode: 'USD'}} />
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* @example without currency, outputs: 100.00
|
|
17
|
+
* ```ts
|
|
18
|
+
* <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutCurrency />
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
* @example without trailing zeros, outputs: $100
|
|
23
|
+
* ```ts
|
|
24
|
+
* <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutTrailingZeros />
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
*
|
|
28
|
+
* @example with per-unit measurement, outputs: $100.00 per G
|
|
29
|
+
* ```ts
|
|
30
|
+
* <Money
|
|
31
|
+
* data={{amount: '100.00', currencyCode: 'USD'}}
|
|
32
|
+
* measurement={{referenceUnit: 'G'}}
|
|
33
|
+
* measurementSeparator=" per "
|
|
34
|
+
* />
|
|
35
|
+
* ```
|
|
36
|
+
* @publicDocs
|
|
37
|
+
*/
|
|
38
|
+
function Money({ data, as, withoutCurrency, withoutTrailingZeros, measurement, measurementSeparator = "/", ...passthroughProps }) {
|
|
39
|
+
if (!isMoney(data)) throw new Error(`<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`);
|
|
40
|
+
const moneyObject = useMoney(data);
|
|
41
|
+
const Wrapper = as ?? "div";
|
|
42
|
+
let output = moneyObject.localizedString;
|
|
43
|
+
if (withoutCurrency || withoutTrailingZeros) if (withoutCurrency && !withoutTrailingZeros) output = moneyObject.amount;
|
|
44
|
+
else if (!withoutCurrency && withoutTrailingZeros) output = moneyObject.withoutTrailingZeros;
|
|
45
|
+
else output = moneyObject.withoutTrailingZerosAndCurrency;
|
|
46
|
+
return /* @__PURE__ */ jsxs(Wrapper, {
|
|
47
|
+
...passthroughProps,
|
|
48
|
+
children: [output, measurement && measurement.referenceUnit && /* @__PURE__ */ jsxs(Fragment, { children: [measurementSeparator, measurement.referenceUnit] })]
|
|
49
|
+
});
|
|
36
50
|
}
|
|
37
51
|
function isMoney(maybeMoney) {
|
|
38
|
-
|
|
52
|
+
return typeof maybeMoney.amount === "string" && !!maybeMoney.amount && typeof maybeMoney.currencyCode === "string" && !!maybeMoney.currencyCode;
|
|
39
53
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//# sourceMappingURL=Money.mjs.map
|
|
54
|
+
//#endregion
|
|
55
|
+
export { Money };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=Money.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Money.mjs","sources":["../../src/Money.tsx"],"sourcesContent":["import {type ReactNode} from 'react';\nimport {useMoney} from './useMoney.js';\nimport type {\n MoneyV2 as StorefrontApiMoneyV2,\n UnitPriceMeasurement,\n} from './storefront-api-types.js';\nimport type {MoneyV2 as CustomerAccountApiMoneyV2} from './customer-account-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\n/**\n * Supports MoneyV2 from both Storefront API and Customer Account API.\n * The APIs may have different CurrencyCode enums (e.g., Customer Account API added USDC in 2025-10, but Storefront API doesn't support USDC in 2025-10).\n * This union type ensures Money component works with data from either API.\n */\ntype MoneyV2 = StorefrontApiMoneyV2 | CustomerAccountApiMoneyV2;\n\nexport interface MoneyPropsBase<ComponentGeneric extends React.ElementType> {\n /** An HTML tag or React Component to be rendered as the base element wrapper. The default is `div`. */\n as?: ComponentGeneric;\n /** An object with fields that correspond to the [Storefront API's MoneyV2 object](https://shopify.dev/docs/api/storefront/2026-04/objects/MoneyV2) or [Customer Account API's MoneyV2 object](https://shopify.dev/docs/api/customer/2026-04/objects/moneyv2). */\n data: PartialDeep<MoneyV2, {recurseIntoArrays: true}>;\n /** Whether to remove the currency symbol from the output. */\n withoutCurrency?: boolean;\n /** Whether to remove trailing zeros (fractional money) from the output. */\n withoutTrailingZeros?: boolean;\n /** A [UnitPriceMeasurement object](https://shopify.dev/api/storefront/2026-04/objects/unitpricemeasurement). */\n measurement?: PartialDeep<UnitPriceMeasurement, {recurseIntoArrays: true}>;\n /** Customizes the separator between the money output and the measurement output. Used with the `measurement` prop. Defaults to `'/'`. */\n measurementSeparator?: ReactNode;\n}\n\n// This article helps understand the typing here https://www.benmvp.com/blog/polymorphic-react-components-typescript/ Ben is the best :)\nexport type MoneyProps<ComponentGeneric extends React.ElementType> =\n MoneyPropsBase<ComponentGeneric> &\n (ComponentGeneric extends keyof React.JSX.IntrinsicElements\n ? Omit<\n React.ComponentPropsWithoutRef<ComponentGeneric>,\n keyof MoneyPropsBase<ComponentGeneric>\n >\n : React.ComponentPropsWithoutRef<ComponentGeneric>);\n\n/**\n * The `Money` component renders a string of the [Storefront API's MoneyV2 object](https://shopify.dev/docs/api/storefront/2026-04/objects/MoneyV2)\n * or the [Customer Account API's MoneyV2 object](https://shopify.dev/docs/api/customer/2026-04/objects/moneyv2)\n * according to the `locale` in the `ShopifyProvider` component.\n * \n * @see {@link https://shopify.dev/api/hydrogen/components/money}\n * @example basic usage, outputs: $100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} />\n * ```\n * \n *\n * @example without currency, outputs: 100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutCurrency />\n * ```\n * \n *\n * @example without trailing zeros, outputs: $100\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutTrailingZeros />\n * ```\n * \n *\n * @example with per-unit measurement, outputs: $100.00 per G\n * ```ts\n * <Money\n * data={{amount: '100.00', currencyCode: 'USD'}}\n * measurement={{referenceUnit: 'G'}}\n * measurementSeparator=\" per \"\n * />\n * ```\n */\nexport function Money<ComponentGeneric extends React.ElementType = 'div'>({\n data,\n as,\n withoutCurrency,\n withoutTrailingZeros,\n measurement,\n measurementSeparator = '/',\n ...passthroughProps\n}: MoneyProps<ComponentGeneric>): JSX.Element {\n if (!isMoney(data)) {\n throw new Error(\n `<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`,\n );\n }\n const moneyObject = useMoney(data);\n const Wrapper = as ?? 'div';\n\n let output = moneyObject.localizedString;\n\n if (withoutCurrency || withoutTrailingZeros) {\n if (withoutCurrency && !withoutTrailingZeros) {\n output = moneyObject.amount;\n } else if (!withoutCurrency && withoutTrailingZeros) {\n output = moneyObject.withoutTrailingZeros;\n } else {\n // both\n output = moneyObject.withoutTrailingZerosAndCurrency;\n }\n }\n\n return (\n <Wrapper {...passthroughProps}>\n {output}\n {measurement && measurement.referenceUnit && (\n <>\n {measurementSeparator}\n {measurement.referenceUnit}\n </>\n )}\n </Wrapper>\n );\n}\n\n// required in order to narrow the money object down and make TS happy\nfunction isMoney(\n maybeMoney: PartialDeep<MoneyV2, {recurseIntoArrays: true}>,\n): maybeMoney is MoneyV2 {\n return (\n typeof maybeMoney.amount === 'string' &&\n !!maybeMoney.amount &&\n typeof maybeMoney.currencyCode === 'string' &&\n !!maybeMoney.currencyCode\n );\n}\n"],"
|
|
1
|
+
{"version":3,"file":"Money.mjs","names":[],"sources":["../../src/Money.tsx"],"sourcesContent":["import {type ReactNode} from 'react';\nimport {useMoney} from './useMoney.js';\nimport type {\n MoneyV2 as StorefrontApiMoneyV2,\n UnitPriceMeasurement,\n} from './storefront-api-types.js';\nimport type {MoneyV2 as CustomerAccountApiMoneyV2} from './customer-account-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\n/**\n * Supports MoneyV2 from both Storefront API and Customer Account API.\n * The APIs may have different CurrencyCode enums (e.g., Customer Account API added USDC in 2025-10, but Storefront API doesn't support USDC in 2025-10).\n * This union type ensures Money component works with data from either API.\n */\ntype MoneyV2 = StorefrontApiMoneyV2 | CustomerAccountApiMoneyV2;\n\nexport interface MoneyPropsBase<ComponentGeneric extends React.ElementType> {\n /** An HTML tag or React Component to be rendered as the base element wrapper. The default is `div`. */\n as?: ComponentGeneric;\n /** An object with fields that correspond to the [Storefront API's MoneyV2 object](https://shopify.dev/docs/api/storefront/2026-04/objects/MoneyV2) or [Customer Account API's MoneyV2 object](https://shopify.dev/docs/api/customer/2026-04/objects/moneyv2). */\n data: PartialDeep<MoneyV2, {recurseIntoArrays: true}>;\n /** Whether to remove the currency symbol from the output. */\n withoutCurrency?: boolean;\n /** Whether to remove trailing zeros (fractional money) from the output. */\n withoutTrailingZeros?: boolean;\n /** A [UnitPriceMeasurement object](https://shopify.dev/api/storefront/2026-04/objects/unitpricemeasurement). */\n measurement?: PartialDeep<UnitPriceMeasurement, {recurseIntoArrays: true}>;\n /** Customizes the separator between the money output and the measurement output. Used with the `measurement` prop. Defaults to `'/'`. */\n measurementSeparator?: ReactNode;\n}\n\n// This article helps understand the typing here https://www.benmvp.com/blog/polymorphic-react-components-typescript/ Ben is the best :)\nexport type MoneyProps<ComponentGeneric extends React.ElementType> =\n MoneyPropsBase<ComponentGeneric> &\n (ComponentGeneric extends keyof React.JSX.IntrinsicElements\n ? Omit<\n React.ComponentPropsWithoutRef<ComponentGeneric>,\n keyof MoneyPropsBase<ComponentGeneric>\n >\n : React.ComponentPropsWithoutRef<ComponentGeneric>);\n\n/**\n * The `Money` component renders a string of the [Storefront API's MoneyV2 object](https://shopify.dev/docs/api/storefront/2026-04/objects/MoneyV2)\n * or the [Customer Account API's MoneyV2 object](https://shopify.dev/docs/api/customer/2026-04/objects/moneyv2)\n * according to the `locale` in the `ShopifyProvider` component.\n * \n * @see {@link https://shopify.dev/api/hydrogen/components/money}\n * @example basic usage, outputs: $100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} />\n * ```\n * \n *\n * @example without currency, outputs: 100.00\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutCurrency />\n * ```\n * \n *\n * @example without trailing zeros, outputs: $100\n * ```ts\n * <Money data={{amount: '100.00', currencyCode: 'USD'}} withoutTrailingZeros />\n * ```\n * \n *\n * @example with per-unit measurement, outputs: $100.00 per G\n * ```ts\n * <Money\n * data={{amount: '100.00', currencyCode: 'USD'}}\n * measurement={{referenceUnit: 'G'}}\n * measurementSeparator=\" per \"\n * />\n * ```\n * @publicDocs\n */\nexport function Money<ComponentGeneric extends React.ElementType = 'div'>({\n data,\n as,\n withoutCurrency,\n withoutTrailingZeros,\n measurement,\n measurementSeparator = '/',\n ...passthroughProps\n}: MoneyProps<ComponentGeneric>): JSX.Element {\n if (!isMoney(data)) {\n throw new Error(\n `<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'`,\n );\n }\n const moneyObject = useMoney(data);\n const Wrapper = as ?? 'div';\n\n let output = moneyObject.localizedString;\n\n if (withoutCurrency || withoutTrailingZeros) {\n if (withoutCurrency && !withoutTrailingZeros) {\n output = moneyObject.amount;\n } else if (!withoutCurrency && withoutTrailingZeros) {\n output = moneyObject.withoutTrailingZeros;\n } else {\n // both\n output = moneyObject.withoutTrailingZerosAndCurrency;\n }\n }\n\n return (\n <Wrapper {...passthroughProps}>\n {output}\n {measurement && measurement.referenceUnit && (\n <>\n {measurementSeparator}\n {measurement.referenceUnit}\n </>\n )}\n </Wrapper>\n );\n}\n\n// required in order to narrow the money object down and make TS happy\nfunction isMoney(\n maybeMoney: PartialDeep<MoneyV2, {recurseIntoArrays: true}>,\n): maybeMoney is MoneyV2 {\n return (\n typeof maybeMoney.amount === 'string' &&\n !!maybeMoney.amount &&\n typeof maybeMoney.currencyCode === 'string' &&\n !!maybeMoney.currencyCode\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgB,MAA0D,EACxE,MACA,IACA,iBACA,sBACA,aACA,uBAAuB,KACvB,GAAG,oBACyC;AAC5C,KAAI,CAAC,QAAQ,KAAK,CAChB,OAAM,IAAI,MACR,0EACD;CAEH,MAAM,cAAc,SAAS,KAAK;CAClC,MAAM,UAAU,MAAM;CAEtB,IAAI,SAAS,YAAY;AAEzB,KAAI,mBAAmB,qBACrB,KAAI,mBAAmB,CAAC,qBACtB,UAAS,YAAY;UACZ,CAAC,mBAAmB,qBAC7B,UAAS,YAAY;KAGrB,UAAS,YAAY;AAIzB,QACE,qBAAC,SAAD;EAAS,GAAI;YAAb,CACG,QACA,eAAe,YAAY,iBAC1B,qBAAA,UAAA,EAAA,UAAA,CACG,sBACA,YAAY,cACZ,EAAA,CAAA,CAEG;;;AAKd,SAAS,QACP,YACuB;AACvB,QACE,OAAO,WAAW,WAAW,YAC7B,CAAC,CAAC,WAAW,UACb,OAAO,WAAW,iBAAiB,YACnC,CAAC,CAAC,WAAW"}
|
|
@@ -1,64 +1,47 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Money } from "./Money.mjs";
|
|
3
1
|
import { flattenConnection } from "./flatten-connection.mjs";
|
|
2
|
+
import { Money } from "./Money.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/ProductPrice.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The `ProductPrice` component renders a `Money` component with the product
|
|
7
|
+
* [`priceRange`](https://shopify.dev/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range.
|
|
8
|
+
* @publicDocs
|
|
9
|
+
*/
|
|
4
10
|
function ProductPrice(props) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (priceAsNumber >= compareAtPriceAsNumber) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
if (variantId && variant) {
|
|
42
|
-
price = variant.price;
|
|
43
|
-
if (valueType === "unit") {
|
|
44
|
-
price = variant.unitPrice;
|
|
45
|
-
measurement = variant.unitPriceMeasurement;
|
|
46
|
-
}
|
|
47
|
-
} else if (valueType === "max") {
|
|
48
|
-
price = (_e = product.priceRange) == null ? void 0 : _e.maxVariantPrice;
|
|
49
|
-
} else {
|
|
50
|
-
price = (_f = product.priceRange) == null ? void 0 : _f.minVariantPrice;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (!price) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
if (measurement) {
|
|
57
|
-
return /* @__PURE__ */ jsx(Money, { ...passthroughProps, data: price, measurement });
|
|
58
|
-
}
|
|
59
|
-
return /* @__PURE__ */ jsx(Money, { ...passthroughProps, data: price });
|
|
11
|
+
const { priceType = "regular", variantId, valueType = "min", data: product, ...passthroughProps } = props;
|
|
12
|
+
if (product == null) throw new Error(`<ProductPrice/> requires a product as the 'data' prop`);
|
|
13
|
+
let price;
|
|
14
|
+
let measurement;
|
|
15
|
+
const variant = variantId ? flattenConnection(product?.variants ?? {}).find((variant) => variant?.id === variantId) ?? null : null;
|
|
16
|
+
const variantPriceProperty = valueType === "max" ? "maxVariantPrice" : "minVariantPrice";
|
|
17
|
+
if (priceType === "compareAt") {
|
|
18
|
+
if (variantId && variant) price = variant.compareAtPrice;
|
|
19
|
+
else price = product?.compareAtPriceRange?.[variantPriceProperty];
|
|
20
|
+
let priceAsNumber;
|
|
21
|
+
if (variantId && variant) priceAsNumber = parseFloat(variant.price?.amount ?? "0");
|
|
22
|
+
else priceAsNumber = parseFloat(product?.priceRange?.[variantPriceProperty]?.amount ?? "0");
|
|
23
|
+
const compareAtPriceAsNumber = parseFloat(price?.amount ?? "0");
|
|
24
|
+
if (priceAsNumber >= compareAtPriceAsNumber) return null;
|
|
25
|
+
} else if (variantId && variant) {
|
|
26
|
+
price = variant.price;
|
|
27
|
+
if (valueType === "unit") {
|
|
28
|
+
price = variant.unitPrice;
|
|
29
|
+
measurement = variant.unitPriceMeasurement;
|
|
30
|
+
}
|
|
31
|
+
} else if (valueType === "max") price = product.priceRange?.maxVariantPrice;
|
|
32
|
+
else price = product.priceRange?.minVariantPrice;
|
|
33
|
+
if (!price) return null;
|
|
34
|
+
if (measurement) return /* @__PURE__ */ jsx(Money, {
|
|
35
|
+
...passthroughProps,
|
|
36
|
+
data: price,
|
|
37
|
+
measurement
|
|
38
|
+
});
|
|
39
|
+
return /* @__PURE__ */ jsx(Money, {
|
|
40
|
+
...passthroughProps,
|
|
41
|
+
data: price
|
|
42
|
+
});
|
|
60
43
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//# sourceMappingURL=ProductPrice.mjs.map
|
|
44
|
+
//#endregion
|
|
45
|
+
export { ProductPrice };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=ProductPrice.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductPrice.mjs","sources":["../../src/ProductPrice.tsx"],"sourcesContent":["import type {\n MoneyV2,\n UnitPriceMeasurement,\n Product,\n} from './storefront-api-types.js';\nimport {Money, type MoneyProps, type MoneyPropsBase} from './Money.js';\nimport type {PartialDeep} from 'type-fest';\nimport {flattenConnection} from './flatten-connection.js';\n\nexport interface ProductPriceProps {\n /** A Storefront API [Product object](https://shopify.dev/api/storefront/reference/products/product). */\n data: PartialDeep<Product, {recurseIntoArrays: true}>;\n /** The type of price. Valid values: `regular` (default) or `compareAt`. */\n priceType?: 'regular' | 'compareAt';\n /** The type of value. Valid values: `min` (default), `max` or `unit`. */\n valueType?: 'max' | 'min' | 'unit';\n /** The ID of the variant. */\n variantId?: string;\n}\n\n/**\n * The `ProductPrice` component renders a `Money` component with the product\n * [`priceRange`](https://shopify.dev/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range.\n */\nexport function ProductPrice<\n ComponentGeneric extends React.ElementType = 'div',\n>(\n props: ProductPriceProps &\n Omit<MoneyProps<ComponentGeneric>, 'data' | 'measurement'>,\n): JSX.Element | null {\n const {\n priceType = 'regular',\n variantId,\n valueType = 'min',\n data: product,\n ...passthroughProps\n } = props;\n\n if (product == null) {\n throw new Error(`<ProductPrice/> requires a product as the 'data' prop`);\n }\n\n let price: Partial<MoneyV2> | undefined | null;\n let measurement: Partial<UnitPriceMeasurement> | undefined | null;\n\n const variant = variantId\n ? (flattenConnection(product?.variants ?? {}).find(\n (variant) => variant?.id === variantId,\n ) ?? null)\n : null;\n\n const variantPriceProperty =\n valueType === 'max' ? 'maxVariantPrice' : 'minVariantPrice';\n\n if (priceType === 'compareAt') {\n if (variantId && variant) {\n price = variant.compareAtPrice;\n } else {\n price = product?.compareAtPriceRange?.[variantPriceProperty];\n }\n\n let priceAsNumber: number;\n if (variantId && variant) {\n priceAsNumber = parseFloat(variant.price?.amount ?? '0');\n } else {\n priceAsNumber = parseFloat(\n product?.priceRange?.[variantPriceProperty]?.amount ?? '0',\n );\n }\n\n const compareAtPriceAsNumber = parseFloat(price?.amount ?? '0');\n\n if (priceAsNumber >= compareAtPriceAsNumber) {\n return null;\n }\n } else {\n if (variantId && variant) {\n price = variant.price;\n if (valueType === 'unit') {\n price = variant.unitPrice;\n measurement = variant.unitPriceMeasurement;\n }\n } else if (valueType === 'max') {\n price = product.priceRange?.maxVariantPrice;\n } else {\n price = product.priceRange?.minVariantPrice;\n }\n }\n\n if (!price) {\n return null;\n }\n\n if (measurement) {\n return (\n <Money {...passthroughProps} data={price} measurement={measurement} />\n );\n }\n\n return <Money {...passthroughProps} data={price} />;\n}\n\n// This is only for documentation purposes, and it is not used in the code.\nexport interface ProductPricePropsForDocs<\n AsType extends React.ElementType = 'div',\n>\n extends\n Omit<MoneyPropsBase<AsType>, 'data' | 'measurement'>,\n ProductPriceProps {}\n"],"
|
|
1
|
+
{"version":3,"file":"ProductPrice.mjs","names":[],"sources":["../../src/ProductPrice.tsx"],"sourcesContent":["import type {\n MoneyV2,\n UnitPriceMeasurement,\n Product,\n} from './storefront-api-types.js';\nimport {Money, type MoneyProps, type MoneyPropsBase} from './Money.js';\nimport type {PartialDeep} from 'type-fest';\nimport {flattenConnection} from './flatten-connection.js';\n\nexport interface ProductPriceProps {\n /** A Storefront API [Product object](https://shopify.dev/api/storefront/reference/products/product). */\n data: PartialDeep<Product, {recurseIntoArrays: true}>;\n /** The type of price. Valid values: `regular` (default) or `compareAt`. */\n priceType?: 'regular' | 'compareAt';\n /** The type of value. Valid values: `min` (default), `max` or `unit`. */\n valueType?: 'max' | 'min' | 'unit';\n /** The ID of the variant. */\n variantId?: string;\n}\n\n/**\n * The `ProductPrice` component renders a `Money` component with the product\n * [`priceRange`](https://shopify.dev/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range.\n * @publicDocs\n */\nexport function ProductPrice<\n ComponentGeneric extends React.ElementType = 'div',\n>(\n props: ProductPriceProps &\n Omit<MoneyProps<ComponentGeneric>, 'data' | 'measurement'>,\n): JSX.Element | null {\n const {\n priceType = 'regular',\n variantId,\n valueType = 'min',\n data: product,\n ...passthroughProps\n } = props;\n\n if (product == null) {\n throw new Error(`<ProductPrice/> requires a product as the 'data' prop`);\n }\n\n let price: Partial<MoneyV2> | undefined | null;\n let measurement: Partial<UnitPriceMeasurement> | undefined | null;\n\n const variant = variantId\n ? (flattenConnection(product?.variants ?? {}).find(\n (variant) => variant?.id === variantId,\n ) ?? null)\n : null;\n\n const variantPriceProperty =\n valueType === 'max' ? 'maxVariantPrice' : 'minVariantPrice';\n\n if (priceType === 'compareAt') {\n if (variantId && variant) {\n price = variant.compareAtPrice;\n } else {\n price = product?.compareAtPriceRange?.[variantPriceProperty];\n }\n\n let priceAsNumber: number;\n if (variantId && variant) {\n priceAsNumber = parseFloat(variant.price?.amount ?? '0');\n } else {\n priceAsNumber = parseFloat(\n product?.priceRange?.[variantPriceProperty]?.amount ?? '0',\n );\n }\n\n const compareAtPriceAsNumber = parseFloat(price?.amount ?? '0');\n\n if (priceAsNumber >= compareAtPriceAsNumber) {\n return null;\n }\n } else {\n if (variantId && variant) {\n price = variant.price;\n if (valueType === 'unit') {\n price = variant.unitPrice;\n measurement = variant.unitPriceMeasurement;\n }\n } else if (valueType === 'max') {\n price = product.priceRange?.maxVariantPrice;\n } else {\n price = product.priceRange?.minVariantPrice;\n }\n }\n\n if (!price) {\n return null;\n }\n\n if (measurement) {\n return (\n <Money {...passthroughProps} data={price} measurement={measurement} />\n );\n }\n\n return <Money {...passthroughProps} data={price} />;\n}\n\n// This is only for documentation purposes, and it is not used in the code.\n/** @publicDocs */\nexport interface ProductPricePropsForDocs<\n AsType extends React.ElementType = 'div',\n>\n extends\n Omit<MoneyPropsBase<AsType>, 'data' | 'measurement'>,\n ProductPriceProps {}\n"],"mappings":";;;;;;;;;AAyBA,SAAgB,aAGd,OAEoB;CACpB,MAAM,EACJ,YAAY,WACZ,WACA,YAAY,OACZ,MAAM,SACN,GAAG,qBACD;AAEJ,KAAI,WAAW,KACb,OAAM,IAAI,MAAM,wDAAwD;CAG1E,IAAI;CACJ,IAAI;CAEJ,MAAM,UAAU,YACX,kBAAkB,SAAS,YAAY,EAAE,CAAC,CAAC,MACzC,YAAY,SAAS,OAAO,UAC9B,IAAI,OACL;CAEJ,MAAM,uBACJ,cAAc,QAAQ,oBAAoB;AAE5C,KAAI,cAAc,aAAa;AAC7B,MAAI,aAAa,QACf,SAAQ,QAAQ;MAEhB,SAAQ,SAAS,sBAAsB;EAGzC,IAAI;AACJ,MAAI,aAAa,QACf,iBAAgB,WAAW,QAAQ,OAAO,UAAU,IAAI;MAExD,iBAAgB,WACd,SAAS,aAAa,uBAAuB,UAAU,IACxD;EAGH,MAAM,yBAAyB,WAAW,OAAO,UAAU,IAAI;AAE/D,MAAI,iBAAiB,uBACnB,QAAO;YAGL,aAAa,SAAS;AACxB,UAAQ,QAAQ;AAChB,MAAI,cAAc,QAAQ;AACxB,WAAQ,QAAQ;AAChB,iBAAc,QAAQ;;YAEf,cAAc,MACvB,SAAQ,QAAQ,YAAY;KAE5B,SAAQ,QAAQ,YAAY;AAIhC,KAAI,CAAC,MACH,QAAO;AAGT,KAAI,YACF,QACE,oBAAC,OAAD;EAAO,GAAI;EAAkB,MAAM;EAAoB;EAAe,CAAA;AAI1E,QAAO,oBAAC,OAAD;EAAO,GAAI;EAAkB,MAAM;EAAS,CAAA"}
|
|
@@ -1,193 +1,161 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo, useState, useEffect, useCallback, useContext, createContext } from "react";
|
|
3
1
|
import { flattenConnection } from "./flatten-connection.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
selectedVariant,
|
|
105
|
-
sellingPlanGroups,
|
|
106
|
-
setSelectedOption,
|
|
107
|
-
variants
|
|
108
|
-
]
|
|
109
|
-
);
|
|
110
|
-
return /* @__PURE__ */ jsx(ProductOptionsContext.Provider, { value, children });
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/ProductProvider.tsx
|
|
5
|
+
var ProductOptionsContext = createContext(null);
|
|
6
|
+
/**
|
|
7
|
+
* `<ProductProvider />` is a context provider that enables use of the `useProduct()` hook.
|
|
8
|
+
*
|
|
9
|
+
* It helps manage selected options and variants for a product.
|
|
10
|
+
* @publicDocs
|
|
11
|
+
*/
|
|
12
|
+
function ProductProvider({ children, data: product, initialVariantId: explicitVariantId }) {
|
|
13
|
+
const variants = useMemo(() => flattenConnection(product.variants ?? {}), [product.variants]);
|
|
14
|
+
if (!isProductVariantArray(variants)) throw new Error(`<ProductProvider/> requires 'product.variants.nodes' or 'product.variants.edges'`);
|
|
15
|
+
const options = useMemo(() => getOptions(variants), [variants]);
|
|
16
|
+
/**
|
|
17
|
+
* Track the selectedVariant within the provider.
|
|
18
|
+
*/
|
|
19
|
+
const [selectedVariant, setSelectedVariant] = useState(() => getVariantBasedOnIdProp(explicitVariantId, variants));
|
|
20
|
+
/**
|
|
21
|
+
* Track the selectedOptions within the provider. If a `initialVariantId`
|
|
22
|
+
* is passed, use that to select initial options.
|
|
23
|
+
*/
|
|
24
|
+
const [selectedOptions, setSelectedOptions] = useState(() => getSelectedOptions(selectedVariant));
|
|
25
|
+
/**
|
|
26
|
+
* When the initialVariantId changes, we need to make sure we
|
|
27
|
+
* update the selected variant and selected options. If not,
|
|
28
|
+
* then the selected variant and options will reference incorrect
|
|
29
|
+
* values.
|
|
30
|
+
*/
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const newSelectedVariant = getVariantBasedOnIdProp(explicitVariantId, variants);
|
|
33
|
+
setSelectedVariant(newSelectedVariant);
|
|
34
|
+
setSelectedOptions(getSelectedOptions(newSelectedVariant));
|
|
35
|
+
}, [explicitVariantId, variants]);
|
|
36
|
+
/**
|
|
37
|
+
* Allow the developer to select an option.
|
|
38
|
+
*/
|
|
39
|
+
const setSelectedOption = useCallback((name, value) => {
|
|
40
|
+
setSelectedOptions((selectedOptions) => {
|
|
41
|
+
const opts = {
|
|
42
|
+
...selectedOptions,
|
|
43
|
+
[name]: value
|
|
44
|
+
};
|
|
45
|
+
setSelectedVariant(getSelectedVariant(variants, opts));
|
|
46
|
+
return opts;
|
|
47
|
+
});
|
|
48
|
+
}, [setSelectedOptions, variants]);
|
|
49
|
+
const isOptionInStock = useCallback((option, value) => {
|
|
50
|
+
return getSelectedVariant(variants, {
|
|
51
|
+
...selectedOptions,
|
|
52
|
+
[option]: value
|
|
53
|
+
})?.availableForSale ?? true;
|
|
54
|
+
}, [selectedOptions, variants]);
|
|
55
|
+
const sellingPlanGroups = useMemo(() => flattenConnection(product.sellingPlanGroups ?? {}).map((sellingPlanGroup) => ({
|
|
56
|
+
...sellingPlanGroup,
|
|
57
|
+
sellingPlans: flattenConnection(sellingPlanGroup?.sellingPlans ?? {})
|
|
58
|
+
})), [product.sellingPlanGroups]);
|
|
59
|
+
/**
|
|
60
|
+
* Track the selectedSellingPlan within the hook. If `initialSellingPlanId`
|
|
61
|
+
* is passed, use that as an initial value. Look it up from the `selectedVariant`, since
|
|
62
|
+
* that is also a requirement.
|
|
63
|
+
*/
|
|
64
|
+
const [selectedSellingPlan, setSelectedSellingPlan] = useState(void 0);
|
|
65
|
+
const selectedSellingPlanAllocation = useMemo(() => {
|
|
66
|
+
if (!selectedVariant || !selectedSellingPlan) return;
|
|
67
|
+
if (!selectedVariant.sellingPlanAllocations?.nodes && !selectedVariant.sellingPlanAllocations?.edges) throw new Error(`<ProductProvider/>: You must include 'sellingPlanAllocations.nodes' or 'sellingPlanAllocations.edges' in your variants in order to calculate selectedSellingPlanAllocation`);
|
|
68
|
+
return flattenConnection(selectedVariant.sellingPlanAllocations).find((allocation) => allocation?.sellingPlan?.id === selectedSellingPlan.id);
|
|
69
|
+
}, [selectedVariant, selectedSellingPlan]);
|
|
70
|
+
const value = useMemo(() => ({
|
|
71
|
+
product,
|
|
72
|
+
variants,
|
|
73
|
+
variantsConnection: product.variants,
|
|
74
|
+
options,
|
|
75
|
+
selectedVariant,
|
|
76
|
+
setSelectedVariant,
|
|
77
|
+
selectedOptions,
|
|
78
|
+
setSelectedOption,
|
|
79
|
+
setSelectedOptions,
|
|
80
|
+
isOptionInStock,
|
|
81
|
+
selectedSellingPlan,
|
|
82
|
+
setSelectedSellingPlan,
|
|
83
|
+
selectedSellingPlanAllocation,
|
|
84
|
+
sellingPlanGroups,
|
|
85
|
+
sellingPlanGroupsConnection: product.sellingPlanGroups
|
|
86
|
+
}), [
|
|
87
|
+
product,
|
|
88
|
+
isOptionInStock,
|
|
89
|
+
options,
|
|
90
|
+
selectedOptions,
|
|
91
|
+
selectedSellingPlan,
|
|
92
|
+
selectedSellingPlanAllocation,
|
|
93
|
+
selectedVariant,
|
|
94
|
+
sellingPlanGroups,
|
|
95
|
+
setSelectedOption,
|
|
96
|
+
variants
|
|
97
|
+
]);
|
|
98
|
+
return /* @__PURE__ */ jsx(ProductOptionsContext.Provider, {
|
|
99
|
+
value,
|
|
100
|
+
children
|
|
101
|
+
});
|
|
111
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Provides access to the context value provided by `<ProductProvider />`. Must be a descendent of `<ProductProvider />`.
|
|
105
|
+
* @publicDocs
|
|
106
|
+
*/
|
|
112
107
|
function useProduct() {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
return context;
|
|
108
|
+
const context = useContext(ProductOptionsContext);
|
|
109
|
+
if (!context) throw new Error(`'useProduct' must be a child of <ProductProvider />`);
|
|
110
|
+
return context;
|
|
118
111
|
}
|
|
119
112
|
function getSelectedVariant(variants, choices) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
113
|
+
/**
|
|
114
|
+
* Ensure the user has selected all the required options, not just some.
|
|
115
|
+
*/
|
|
116
|
+
if (!variants.length || variants?.[0]?.selectedOptions?.length !== Object.keys(choices).length) return;
|
|
117
|
+
return variants?.find((variant) => {
|
|
118
|
+
return Object.entries(choices).every(([name, value]) => {
|
|
119
|
+
return variant?.selectedOptions?.some((option) => option?.name === name && option?.value === value);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
132
122
|
}
|
|
133
123
|
function getOptions(variants) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return Object.keys(map).map((option) => {
|
|
149
|
-
return {
|
|
150
|
-
name: option,
|
|
151
|
-
values: Array.from(map[option])
|
|
152
|
-
};
|
|
153
|
-
});
|
|
124
|
+
const map = variants.reduce((memo, variant) => {
|
|
125
|
+
if (!variant.selectedOptions) throw new Error(`'getOptions' requires 'variant.selectedOptions'`);
|
|
126
|
+
variant?.selectedOptions?.forEach((opt) => {
|
|
127
|
+
memo[opt?.name ?? ""] = memo[opt?.name ?? ""] || /* @__PURE__ */ new Set();
|
|
128
|
+
memo[opt?.name ?? ""].add(opt?.value ?? "");
|
|
129
|
+
});
|
|
130
|
+
return memo;
|
|
131
|
+
}, {});
|
|
132
|
+
return Object.keys(map).map((option) => {
|
|
133
|
+
return {
|
|
134
|
+
name: option,
|
|
135
|
+
values: Array.from(map[option])
|
|
136
|
+
};
|
|
137
|
+
});
|
|
154
138
|
}
|
|
155
139
|
function getVariantBasedOnIdProp(explicitVariantId, variants) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
return foundVariant;
|
|
166
|
-
}
|
|
167
|
-
if (explicitVariantId === null) {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
if (explicitVariantId === void 0) {
|
|
171
|
-
return variants.find((variant) => variant == null ? void 0 : variant.availableForSale) || variants[0];
|
|
172
|
-
}
|
|
140
|
+
if (explicitVariantId) {
|
|
141
|
+
const foundVariant = variants.find((variant) => variant?.id === explicitVariantId);
|
|
142
|
+
if (!foundVariant) console.warn(`<ProductProvider/> received a 'initialVariantId' prop, but could not actually find a variant with that ID`);
|
|
143
|
+
return foundVariant;
|
|
144
|
+
}
|
|
145
|
+
if (explicitVariantId === null) return null;
|
|
146
|
+
if (explicitVariantId === void 0) return variants.find((variant) => variant?.availableForSale) || variants[0];
|
|
173
147
|
}
|
|
174
148
|
function getSelectedOptions(selectedVariant) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
},
|
|
180
|
-
{}
|
|
181
|
-
) : {};
|
|
149
|
+
return selectedVariant?.selectedOptions ? selectedVariant.selectedOptions.reduce((memo, optionSet) => {
|
|
150
|
+
memo[optionSet?.name ?? ""] = optionSet?.value ?? "";
|
|
151
|
+
return memo;
|
|
152
|
+
}, {}) : {};
|
|
182
153
|
}
|
|
183
154
|
function isProductVariantArray(maybeVariantArray) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
return true;
|
|
155
|
+
if (!maybeVariantArray || !Array.isArray(maybeVariantArray)) return false;
|
|
156
|
+
return true;
|
|
188
157
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
//# sourceMappingURL=ProductProvider.mjs.map
|
|
158
|
+
//#endregion
|
|
159
|
+
export { ProductProvider, useProduct };
|
|
160
|
+
|
|
161
|
+
//# sourceMappingURL=ProductProvider.mjs.map
|