@shopify/hydrogen-react 2026.4.1 → 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 +28 -66
- 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 +28 -66
- 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 +27 -56
- package/dist/node-dev/cart-queries.js.map +1 -1
- package/dist/node-dev/cart-queries.mjs +28 -66
- 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 +27 -56
- package/dist/node-prod/cart-queries.js.map +1 -1
- package/dist/node-prod/cart-queries.mjs +28 -66
- 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/umd/hydrogen-react.dev.js +3930 -4418
- package/dist/umd/hydrogen-react.dev.js.map +1 -1
- package/dist/umd/hydrogen-react.prod.js +35 -49
- 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,49 +1,44 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect, useCallback } from "react";
|
|
3
1
|
import { useCart } from "./CartProvider.mjs";
|
|
4
2
|
import { BaseButton } from "./BaseButton.mjs";
|
|
3
|
+
import { useCallback, useEffect, useState } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/BuyNowButton.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The `BuyNowButton` component renders a button that adds an item to the cart and redirects the customer to checkout.
|
|
8
|
+
* Must be a child of a `CartProvider` component.
|
|
9
|
+
* @publicDocs
|
|
10
|
+
*/
|
|
5
11
|
function BuyNowButton(props) {
|
|
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
|
-
}, [cartCreate, quantity, variantId, attributes, sellingPlanId]);
|
|
35
|
-
return /* @__PURE__ */ jsx(
|
|
36
|
-
BaseButton,
|
|
37
|
-
{
|
|
38
|
-
disabled: loading ?? passthroughProps.disabled,
|
|
39
|
-
...passthroughProps,
|
|
40
|
-
onClick,
|
|
41
|
-
defaultOnClick: handleBuyNow,
|
|
42
|
-
children
|
|
43
|
-
}
|
|
44
|
-
);
|
|
12
|
+
const { cartCreate, checkoutUrl } = useCart();
|
|
13
|
+
const [loading, setLoading] = useState(false);
|
|
14
|
+
const { quantity, variantId, sellingPlanId, onClick, attributes, children, ...passthroughProps } = props;
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (loading && checkoutUrl) window.location.href = checkoutUrl;
|
|
17
|
+
}, [loading, checkoutUrl]);
|
|
18
|
+
const handleBuyNow = useCallback(() => {
|
|
19
|
+
setLoading(true);
|
|
20
|
+
cartCreate({ lines: [{
|
|
21
|
+
quantity: quantity ?? 1,
|
|
22
|
+
merchandiseId: variantId,
|
|
23
|
+
attributes,
|
|
24
|
+
sellingPlanId
|
|
25
|
+
}] });
|
|
26
|
+
}, [
|
|
27
|
+
cartCreate,
|
|
28
|
+
quantity,
|
|
29
|
+
variantId,
|
|
30
|
+
attributes,
|
|
31
|
+
sellingPlanId
|
|
32
|
+
]);
|
|
33
|
+
return /* @__PURE__ */ jsx(BaseButton, {
|
|
34
|
+
disabled: loading ?? passthroughProps.disabled,
|
|
35
|
+
...passthroughProps,
|
|
36
|
+
onClick,
|
|
37
|
+
defaultOnClick: handleBuyNow,
|
|
38
|
+
children
|
|
39
|
+
});
|
|
45
40
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//# sourceMappingURL=BuyNowButton.mjs.map
|
|
41
|
+
//#endregion
|
|
42
|
+
export { BuyNowButton };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=BuyNowButton.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuyNowButton.mjs","sources":["../../src/BuyNowButton.tsx"],"sourcesContent":["import {useEffect, useState, useCallback} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {\n BaseButton,\n type BaseButtonProps,\n type CustomBaseButtonProps,\n} from './BaseButton.js';\n\ninterface BuyNowButtonPropsBase {\n /** The item quantity. Defaults to 1. */\n quantity?: number;\n /** The ID of the variant. */\n variantId: string;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n}\n\ntype BuyNowButtonProps<AsType extends React.ElementType = 'button'> =\n BuyNowButtonPropsBase & BaseButtonProps<AsType>;\n\n/**\n * The `BuyNowButton` component renders a button that adds an item to the cart and redirects the customer to checkout.\n * Must be a child of a `CartProvider` component.\n * @publicDocs\n */\nexport function BuyNowButton<AsType extends React.ElementType = 'button'>(\n props: BuyNowButtonProps<AsType>,\n): JSX.Element {\n const {cartCreate, checkoutUrl} = useCart();\n const [loading, setLoading] = useState<boolean>(false);\n\n const {\n quantity,\n variantId,\n sellingPlanId,\n onClick,\n attributes,\n children,\n ...passthroughProps\n } = props;\n\n useEffect(() => {\n if (loading && checkoutUrl) {\n window.location.href = checkoutUrl;\n }\n }, [loading, checkoutUrl]);\n\n const handleBuyNow = useCallback(() => {\n setLoading(true);\n cartCreate({\n lines: [\n {\n quantity: quantity ?? 1,\n merchandiseId: variantId,\n attributes,\n sellingPlanId,\n },\n ],\n });\n }, [cartCreate, quantity, variantId, attributes, sellingPlanId]);\n\n return (\n <BaseButton\n // Only certain 'as' types such as 'button' contain `disabled`\n disabled={loading ?? (passthroughProps as {disabled?: boolean}).disabled}\n {...passthroughProps}\n onClick={onClick}\n defaultOnClick={handleBuyNow}\n >\n {children}\n </BaseButton>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\n/** @publicDocs */\nexport interface BuyNowButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n>\n extends BuyNowButtonPropsBase, CustomBaseButtonProps<AsType> {}\n"],"
|
|
1
|
+
{"version":3,"file":"BuyNowButton.mjs","names":[],"sources":["../../src/BuyNowButton.tsx"],"sourcesContent":["import {useEffect, useState, useCallback} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {\n BaseButton,\n type BaseButtonProps,\n type CustomBaseButtonProps,\n} from './BaseButton.js';\n\ninterface BuyNowButtonPropsBase {\n /** The item quantity. Defaults to 1. */\n quantity?: number;\n /** The ID of the variant. */\n variantId: string;\n /** The selling plan ID of the subscription variant */\n sellingPlanId?: string;\n /** An array of cart line attributes that belong to the item being added to the cart. */\n attributes?: {\n key: string;\n value: string;\n }[];\n}\n\ntype BuyNowButtonProps<AsType extends React.ElementType = 'button'> =\n BuyNowButtonPropsBase & BaseButtonProps<AsType>;\n\n/**\n * The `BuyNowButton` component renders a button that adds an item to the cart and redirects the customer to checkout.\n * Must be a child of a `CartProvider` component.\n * @publicDocs\n */\nexport function BuyNowButton<AsType extends React.ElementType = 'button'>(\n props: BuyNowButtonProps<AsType>,\n): JSX.Element {\n const {cartCreate, checkoutUrl} = useCart();\n const [loading, setLoading] = useState<boolean>(false);\n\n const {\n quantity,\n variantId,\n sellingPlanId,\n onClick,\n attributes,\n children,\n ...passthroughProps\n } = props;\n\n useEffect(() => {\n if (loading && checkoutUrl) {\n window.location.href = checkoutUrl;\n }\n }, [loading, checkoutUrl]);\n\n const handleBuyNow = useCallback(() => {\n setLoading(true);\n cartCreate({\n lines: [\n {\n quantity: quantity ?? 1,\n merchandiseId: variantId,\n attributes,\n sellingPlanId,\n },\n ],\n });\n }, [cartCreate, quantity, variantId, attributes, sellingPlanId]);\n\n return (\n <BaseButton\n // Only certain 'as' types such as 'button' contain `disabled`\n disabled={loading ?? (passthroughProps as {disabled?: boolean}).disabled}\n {...passthroughProps}\n onClick={onClick}\n defaultOnClick={handleBuyNow}\n >\n {children}\n </BaseButton>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\n/** @publicDocs */\nexport interface BuyNowButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n>\n extends BuyNowButtonPropsBase, CustomBaseButtonProps<AsType> {}\n"],"mappings":";;;;;;;;;;AA8BA,SAAgB,aACd,OACa;CACb,MAAM,EAAC,YAAY,gBAAe,SAAS;CAC3C,MAAM,CAAC,SAAS,cAAc,SAAkB,MAAM;CAEtD,MAAM,EACJ,UACA,WACA,eACA,SACA,YACA,UACA,GAAG,qBACD;AAEJ,iBAAgB;AACd,MAAI,WAAW,YACb,QAAO,SAAS,OAAO;IAExB,CAAC,SAAS,YAAY,CAAC;CAE1B,MAAM,eAAe,kBAAkB;AACrC,aAAW,KAAK;AAChB,aAAW,EACT,OAAO,CACL;GACE,UAAU,YAAY;GACtB,eAAe;GACf;GACA;GACD,CACF,EACF,CAAC;IACD;EAAC;EAAY;EAAU;EAAW;EAAY;EAAc,CAAC;AAEhE,QACE,oBAAC,YAAD;EAEE,UAAU,WAAY,iBAA0C;EAChE,GAAI;EACK;EACT,gBAAgB;EAEf;EACU,CAAA"}
|
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect } from "react";
|
|
3
1
|
import { useCart } from "./CartProvider.mjs";
|
|
4
2
|
import { BaseButton } from "./BaseButton.mjs";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/CartCheckoutButton.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The `CartCheckoutButton` component renders a button that redirects to the checkout URL for the cart.
|
|
8
|
+
* It must be a descendent of a `CartProvider` component.
|
|
9
|
+
* @publicDocs
|
|
10
|
+
*/
|
|
5
11
|
function CartCheckoutButton(props) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
);
|
|
12
|
+
const [requestedCheckout, setRequestedCheckout] = useState(false);
|
|
13
|
+
const { status, checkoutUrl } = useCart();
|
|
14
|
+
const { children, ...passthroughProps } = props;
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (requestedCheckout && checkoutUrl && status === "idle") window.location.href = checkoutUrl;
|
|
17
|
+
}, [
|
|
18
|
+
requestedCheckout,
|
|
19
|
+
status,
|
|
20
|
+
checkoutUrl
|
|
21
|
+
]);
|
|
22
|
+
return /* @__PURE__ */ jsx(BaseButton, {
|
|
23
|
+
...passthroughProps,
|
|
24
|
+
disabled: requestedCheckout || passthroughProps.disabled,
|
|
25
|
+
onClick: () => setRequestedCheckout(true),
|
|
26
|
+
children
|
|
27
|
+
});
|
|
23
28
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=CartCheckoutButton.mjs.map
|
|
29
|
+
//#endregion
|
|
30
|
+
export { CartCheckoutButton };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=CartCheckoutButton.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CartCheckoutButton.mjs","sources":["../../src/CartCheckoutButton.tsx"],"sourcesContent":["import {ReactNode, useEffect, useState} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {\n BaseButton,\n type BaseButtonProps,\n type CustomBaseButtonProps,\n} from './BaseButton.js';\n\ntype ChildrenProps = {\n /** A `ReactNode` element. */\n children: ReactNode;\n};\ntype CartCheckoutButtonProps = Omit<BaseButtonProps<'button'>, 'onClick'> &\n ChildrenProps;\n\n/**\n * The `CartCheckoutButton` component renders a button that redirects to the checkout URL for the cart.\n * It must be a descendent of a `CartProvider` component.\n * @publicDocs\n */\nexport function CartCheckoutButton(\n props: CartCheckoutButtonProps,\n): JSX.Element {\n const [requestedCheckout, setRequestedCheckout] = useState(false);\n const {status, checkoutUrl} = useCart();\n const {children, ...passthroughProps} = props;\n\n useEffect(() => {\n if (requestedCheckout && checkoutUrl && status === 'idle') {\n window.location.href = checkoutUrl;\n }\n }, [requestedCheckout, status, checkoutUrl]);\n\n return (\n <BaseButton\n {...passthroughProps}\n disabled={requestedCheckout || passthroughProps.disabled}\n onClick={(): void => setRequestedCheckout(true)}\n >\n {children}\n </BaseButton>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\n// we ignore this issue because it makes the documentation look better than the equivalent `type` that it wants us to convert to\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\n/** @publicDocs */\nexport interface CartCheckoutButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n> extends Omit<CustomBaseButtonProps<AsType>, 'onClick'> {}\n"],"
|
|
1
|
+
{"version":3,"file":"CartCheckoutButton.mjs","names":[],"sources":["../../src/CartCheckoutButton.tsx"],"sourcesContent":["import {ReactNode, useEffect, useState} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {\n BaseButton,\n type BaseButtonProps,\n type CustomBaseButtonProps,\n} from './BaseButton.js';\n\ntype ChildrenProps = {\n /** A `ReactNode` element. */\n children: ReactNode;\n};\ntype CartCheckoutButtonProps = Omit<BaseButtonProps<'button'>, 'onClick'> &\n ChildrenProps;\n\n/**\n * The `CartCheckoutButton` component renders a button that redirects to the checkout URL for the cart.\n * It must be a descendent of a `CartProvider` component.\n * @publicDocs\n */\nexport function CartCheckoutButton(\n props: CartCheckoutButtonProps,\n): JSX.Element {\n const [requestedCheckout, setRequestedCheckout] = useState(false);\n const {status, checkoutUrl} = useCart();\n const {children, ...passthroughProps} = props;\n\n useEffect(() => {\n if (requestedCheckout && checkoutUrl && status === 'idle') {\n window.location.href = checkoutUrl;\n }\n }, [requestedCheckout, status, checkoutUrl]);\n\n return (\n <BaseButton\n {...passthroughProps}\n disabled={requestedCheckout || passthroughProps.disabled}\n onClick={(): void => setRequestedCheckout(true)}\n >\n {children}\n </BaseButton>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\n// we ignore this issue because it makes the documentation look better than the equivalent `type` that it wants us to convert to\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\n/** @publicDocs */\nexport interface CartCheckoutButtonPropsForDocs<\n AsType extends React.ElementType = 'button',\n> extends Omit<CustomBaseButtonProps<AsType>, 'onClick'> {}\n"],"mappings":";;;;;;;;;;AAoBA,SAAgB,mBACd,OACa;CACb,MAAM,CAAC,mBAAmB,wBAAwB,SAAS,MAAM;CACjE,MAAM,EAAC,QAAQ,gBAAe,SAAS;CACvC,MAAM,EAAC,UAAU,GAAG,qBAAoB;AAExC,iBAAgB;AACd,MAAI,qBAAqB,eAAe,WAAW,OACjD,QAAO,SAAS,OAAO;IAExB;EAAC;EAAmB;EAAQ;EAAY,CAAC;AAE5C,QACE,oBAAC,YAAD;EACE,GAAI;EACJ,UAAU,qBAAqB,iBAAiB;EAChD,eAAqB,qBAAqB,KAAK;EAE9C;EACU,CAAA"}
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Money } from "./Money.mjs";
|
|
3
1
|
import { useCart } from "./CartProvider.mjs";
|
|
2
|
+
import { Money } from "./Money.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/CartCost.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The `CartCost` component renders a `Money` component with the cost associated with the `amountType` prop.
|
|
7
|
+
* If no `amountType` prop is specified, then it defaults to `totalAmount`.
|
|
8
|
+
* Depends on `useCart()` and must be a child of `<CartProvider/>`
|
|
9
|
+
* @publicDocs
|
|
10
|
+
*/
|
|
4
11
|
function CartCost(props) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
return /* @__PURE__ */ jsx(Money, { ...passthroughProps, data: amount, children });
|
|
12
|
+
const { cost } = useCart();
|
|
13
|
+
const { amountType = "total", children, ...passthroughProps } = props;
|
|
14
|
+
let amount;
|
|
15
|
+
if (amountType == "total") amount = cost?.totalAmount;
|
|
16
|
+
else if (amountType == "subtotal") amount = cost?.subtotalAmount;
|
|
17
|
+
else if (amountType == "tax") amount = cost?.totalTaxAmount;
|
|
18
|
+
else if (amountType == "duty") amount = cost?.totalDutyAmount;
|
|
19
|
+
if (amount == null) return null;
|
|
20
|
+
return /* @__PURE__ */ jsx(Money, {
|
|
21
|
+
...passthroughProps,
|
|
22
|
+
data: amount,
|
|
23
|
+
children
|
|
24
|
+
});
|
|
21
25
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=CartCost.mjs.map
|
|
26
|
+
//#endregion
|
|
27
|
+
export { CartCost };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=CartCost.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CartCost.mjs","sources":["../../src/CartCost.tsx"],"sourcesContent":["import {Money, type MoneyPropsBase} from './Money.js';\nimport {useCart} from './CartProvider.js';\n\ninterface CartCostPropsBase {\n /** A string type that defines the type of cost needed. Valid values: `total`, `subtotal`, `tax`, or `duty`. */\n amountType?: 'total' | 'subtotal' | 'tax' | 'duty';\n /** Any `ReactNode` elements. */\n children?: React.ReactNode;\n}\n\ntype CartCostProps = Omit<React.ComponentProps<typeof Money>, 'data'> &\n CartCostPropsBase;\n\n/**\n * The `CartCost` component renders a `Money` component with the cost associated with the `amountType` prop.\n * If no `amountType` prop is specified, then it defaults to `totalAmount`.\n * Depends on `useCart()` and must be a child of `<CartProvider/>`\n * @publicDocs\n */\nexport function CartCost(props: CartCostProps): JSX.Element | null {\n const {cost} = useCart();\n const {amountType = 'total', children, ...passthroughProps} = props;\n let amount;\n\n if (amountType == 'total') {\n amount = cost?.totalAmount;\n } else if (amountType == 'subtotal') {\n amount = cost?.subtotalAmount;\n } else if (amountType == 'tax') {\n amount = cost?.totalTaxAmount;\n } else if (amountType == 'duty') {\n amount = cost?.totalDutyAmount;\n }\n\n if (amount == null) {\n return null;\n }\n\n return (\n <Money {...passthroughProps} data={amount}>\n {children}\n </Money>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\n/** @publicDocs */\nexport interface CartCostPropsForDocs<AsType extends React.ElementType = 'div'>\n extends Omit<MoneyPropsBase<AsType>, 'data'>, CartCostPropsBase {}\n"],"
|
|
1
|
+
{"version":3,"file":"CartCost.mjs","names":[],"sources":["../../src/CartCost.tsx"],"sourcesContent":["import {Money, type MoneyPropsBase} from './Money.js';\nimport {useCart} from './CartProvider.js';\n\ninterface CartCostPropsBase {\n /** A string type that defines the type of cost needed. Valid values: `total`, `subtotal`, `tax`, or `duty`. */\n amountType?: 'total' | 'subtotal' | 'tax' | 'duty';\n /** Any `ReactNode` elements. */\n children?: React.ReactNode;\n}\n\ntype CartCostProps = Omit<React.ComponentProps<typeof Money>, 'data'> &\n CartCostPropsBase;\n\n/**\n * The `CartCost` component renders a `Money` component with the cost associated with the `amountType` prop.\n * If no `amountType` prop is specified, then it defaults to `totalAmount`.\n * Depends on `useCart()` and must be a child of `<CartProvider/>`\n * @publicDocs\n */\nexport function CartCost(props: CartCostProps): JSX.Element | null {\n const {cost} = useCart();\n const {amountType = 'total', children, ...passthroughProps} = props;\n let amount;\n\n if (amountType == 'total') {\n amount = cost?.totalAmount;\n } else if (amountType == 'subtotal') {\n amount = cost?.subtotalAmount;\n } else if (amountType == 'tax') {\n amount = cost?.totalTaxAmount;\n } else if (amountType == 'duty') {\n amount = cost?.totalDutyAmount;\n }\n\n if (amount == null) {\n return null;\n }\n\n return (\n <Money {...passthroughProps} data={amount}>\n {children}\n </Money>\n );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\n/** @publicDocs */\nexport interface CartCostPropsForDocs<AsType extends React.ElementType = 'div'>\n extends Omit<MoneyPropsBase<AsType>, 'data'>, CartCostPropsBase {}\n"],"mappings":";;;;;;;;;;AAmBA,SAAgB,SAAS,OAA0C;CACjE,MAAM,EAAC,SAAQ,SAAS;CACxB,MAAM,EAAC,aAAa,SAAS,UAAU,GAAG,qBAAoB;CAC9D,IAAI;AAEJ,KAAI,cAAc,QAChB,UAAS,MAAM;UACN,cAAc,WACvB,UAAS,MAAM;UACN,cAAc,MACvB,UAAS,MAAM;UACN,cAAc,OACvB,UAAS,MAAM;AAGjB,KAAI,UAAU,KACZ,QAAO;AAGT,QACE,oBAAC,OAAD;EAAO,GAAI;EAAkB,MAAM;EAChC;EACK,CAAA"}
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
1
2
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
//#region src/CartLineProvider.tsx
|
|
4
|
+
var CartLineContext = createContext(null);
|
|
5
|
+
/**
|
|
6
|
+
* The `useCartLine` hook provides access to the [CartLine object](https://shopify.dev/api/storefront/2026-04/objects/cartline) from the Storefront API. It must be a descendent of a `CartProvider` component.
|
|
7
|
+
* @publicDocs
|
|
8
|
+
*/
|
|
4
9
|
function useCartLine() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
return context;
|
|
10
|
+
const context = useContext(CartLineContext);
|
|
11
|
+
if (context == null) throw new Error("Expected a cart line context but none was found");
|
|
12
|
+
return context;
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The `CartLineProvider` component creates a context for using a cart line.
|
|
16
|
+
* @publicDocs
|
|
17
|
+
*/
|
|
18
|
+
function CartLineProvider({ children, line }) {
|
|
19
|
+
return /* @__PURE__ */ jsx(CartLineContext.Provider, {
|
|
20
|
+
value: line,
|
|
21
|
+
children
|
|
22
|
+
});
|
|
16
23
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=CartLineProvider.mjs.map
|
|
24
|
+
//#endregion
|
|
25
|
+
export { CartLineProvider, useCartLine };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=CartLineProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CartLineProvider.mjs","sources":["../../src/CartLineProvider.tsx"],"sourcesContent":["import {useContext, createContext, type ReactNode} from 'react';\nimport {\n ComponentizableCartLine,\n type CartLine,\n} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\ntype CartLinePartialDeep = PartialDeep<\n CartLine | ComponentizableCartLine,\n {recurseIntoArrays: true}\n>;\n\nexport const CartLineContext = createContext<CartLinePartialDeep | null>(null);\n\n/**\n * The `useCartLine` hook provides access to the [CartLine object](https://shopify.dev/api/storefront/2026-04/objects/cartline) from the Storefront API. It must be a descendent of a `CartProvider` component.\n * @publicDocs\n */\nexport function useCartLine(): CartLinePartialDeep {\n const context = useContext(CartLineContext);\n\n if (context == null) {\n throw new Error('Expected a cart line context but none was found');\n }\n\n return context;\n}\n\ntype CartLineProviderProps = {\n /** Any `ReactNode` elements. */\n children: ReactNode;\n /** A cart line object. */\n line: CartLinePartialDeep;\n};\n\n/**\n * The `CartLineProvider` component creates a context for using a cart line.\n * @publicDocs\n */\nexport function CartLineProvider({\n children,\n line,\n}: CartLineProviderProps): JSX.Element {\n return (\n <CartLineContext.Provider value={line}>{children}</CartLineContext.Provider>\n );\n}\n"],"
|
|
1
|
+
{"version":3,"file":"CartLineProvider.mjs","names":[],"sources":["../../src/CartLineProvider.tsx"],"sourcesContent":["import {useContext, createContext, type ReactNode} from 'react';\nimport {\n ComponentizableCartLine,\n type CartLine,\n} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\ntype CartLinePartialDeep = PartialDeep<\n CartLine | ComponentizableCartLine,\n {recurseIntoArrays: true}\n>;\n\nexport const CartLineContext = createContext<CartLinePartialDeep | null>(null);\n\n/**\n * The `useCartLine` hook provides access to the [CartLine object](https://shopify.dev/api/storefront/2026-04/objects/cartline) from the Storefront API. It must be a descendent of a `CartProvider` component.\n * @publicDocs\n */\nexport function useCartLine(): CartLinePartialDeep {\n const context = useContext(CartLineContext);\n\n if (context == null) {\n throw new Error('Expected a cart line context but none was found');\n }\n\n return context;\n}\n\ntype CartLineProviderProps = {\n /** Any `ReactNode` elements. */\n children: ReactNode;\n /** A cart line object. */\n line: CartLinePartialDeep;\n};\n\n/**\n * The `CartLineProvider` component creates a context for using a cart line.\n * @publicDocs\n */\nexport function CartLineProvider({\n children,\n line,\n}: CartLineProviderProps): JSX.Element {\n return (\n <CartLineContext.Provider value={line}>{children}</CartLineContext.Provider>\n );\n}\n"],"mappings":";;;AAYA,IAAa,kBAAkB,cAA0C,KAAK;;;;;AAM9E,SAAgB,cAAmC;CACjD,MAAM,UAAU,WAAW,gBAAgB;AAE3C,KAAI,WAAW,KACb,OAAM,IAAI,MAAM,kDAAkD;AAGpE,QAAO;;;;;;AAcT,SAAgB,iBAAiB,EAC/B,UACA,QACqC;AACrC,QACE,oBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAAO;EAAoC,CAAA"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
1
|
import { useCartLine } from "./CartLineProvider.mjs";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
//#region src/CartLineQuantity.tsx
|
|
4
|
+
/**
|
|
5
|
+
* The `<CartLineQuantity/>` component renders a `span` (or another element / component that can be customized by the `as` prop) with the cart line's quantity.
|
|
6
|
+
*
|
|
7
|
+
* It must be a descendent of a `<CartLineProvider/>` component, and uses the `useCartLine()` hook internally.
|
|
8
|
+
* @publicDocs
|
|
9
|
+
*/
|
|
3
10
|
function CartLineQuantity(props) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
const cartLine = useCartLine();
|
|
12
|
+
const { as, ...passthroughProps } = props;
|
|
13
|
+
return /* @__PURE__ */ jsx(as ? as : "span", {
|
|
14
|
+
...passthroughProps,
|
|
15
|
+
children: cartLine.quantity
|
|
16
|
+
});
|
|
8
17
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=CartLineQuantity.mjs.map
|
|
18
|
+
//#endregion
|
|
19
|
+
export { CartLineQuantity };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=CartLineQuantity.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CartLineQuantity.mjs","sources":["../../src/CartLineQuantity.tsx"],"sourcesContent":["import type {ComponentPropsWithoutRef, ElementType} from 'react';\nimport {useCartLine} from './CartLineProvider.js';\n\n/** @publicDocs */\ninterface CartLineQuantityBaseProps<\n ComponentGeneric extends ElementType = 'span',\n> {\n /** An HTML tag or React Component to be rendered as the base element wrapper. The default is `span`. */\n as?: ComponentGeneric;\n}\n\nexport type CartLineQuantityProps<ComponentGeneric extends ElementType> =\n CartLineQuantityBaseProps<ComponentGeneric> &\n Omit<\n ComponentPropsWithoutRef<ComponentGeneric>,\n keyof CartLineQuantityBaseProps<ComponentGeneric>\n >;\n\n/**\n * The `<CartLineQuantity/>` component renders a `span` (or another element / component that can be customized by the `as` prop) with the cart line's quantity.\n *\n * It must be a descendent of a `<CartLineProvider/>` component, and uses the `useCartLine()` hook internally.\n * @publicDocs\n */\nexport function CartLineQuantity<ComponentGeneric extends ElementType = 'span'>(\n props: CartLineQuantityProps<ComponentGeneric>,\n): JSX.Element {\n const cartLine = useCartLine();\n const {as, ...passthroughProps} = props;\n\n const Wrapper = as ? as : 'span';\n\n return <Wrapper {...passthroughProps}>{cartLine.quantity}</Wrapper>;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"CartLineQuantity.mjs","names":[],"sources":["../../src/CartLineQuantity.tsx"],"sourcesContent":["import type {ComponentPropsWithoutRef, ElementType} from 'react';\nimport {useCartLine} from './CartLineProvider.js';\n\n/** @publicDocs */\ninterface CartLineQuantityBaseProps<\n ComponentGeneric extends ElementType = 'span',\n> {\n /** An HTML tag or React Component to be rendered as the base element wrapper. The default is `span`. */\n as?: ComponentGeneric;\n}\n\nexport type CartLineQuantityProps<ComponentGeneric extends ElementType> =\n CartLineQuantityBaseProps<ComponentGeneric> &\n Omit<\n ComponentPropsWithoutRef<ComponentGeneric>,\n keyof CartLineQuantityBaseProps<ComponentGeneric>\n >;\n\n/**\n * The `<CartLineQuantity/>` component renders a `span` (or another element / component that can be customized by the `as` prop) with the cart line's quantity.\n *\n * It must be a descendent of a `<CartLineProvider/>` component, and uses the `useCartLine()` hook internally.\n * @publicDocs\n */\nexport function CartLineQuantity<ComponentGeneric extends ElementType = 'span'>(\n props: CartLineQuantityProps<ComponentGeneric>,\n): JSX.Element {\n const cartLine = useCartLine();\n const {as, ...passthroughProps} = props;\n\n const Wrapper = as ? as : 'span';\n\n return <Wrapper {...passthroughProps}>{cartLine.quantity}</Wrapper>;\n}\n"],"mappings":";;;;;;;;;AAwBA,SAAgB,iBACd,OACa;CACb,MAAM,WAAW,aAAa;CAC9B,MAAM,EAAC,IAAI,GAAG,qBAAoB;AAIlC,QAAO,oBAFS,KAAK,KAAK,QAEnB;EAAS,GAAI;YAAmB,SAAS;EAAmB,CAAA"}
|
|
@@ -1,49 +1,52 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback } from "react";
|
|
3
1
|
import { useCart } from "./CartProvider.mjs";
|
|
4
|
-
import { useCartLine } from "./CartLineProvider.mjs";
|
|
5
2
|
import { BaseButton } from "./BaseButton.mjs";
|
|
3
|
+
import { useCartLine } from "./CartLineProvider.mjs";
|
|
4
|
+
import { useCallback } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
//#region src/CartLineQuantityAdjustButton.tsx
|
|
7
|
+
/**
|
|
8
|
+
* The `<CartLineQuantityAdjustButton />` component renders a button that adjusts the cart line's quantity when pressed.
|
|
9
|
+
*
|
|
10
|
+
* It must be a descendent of `<CartLineProvider/>` and `<CartProvider/>`.
|
|
11
|
+
* @publicDocs
|
|
12
|
+
*/
|
|
6
13
|
function CartLineQuantityAdjustButton(props) {
|
|
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
|
-
disabled: typeof disabledAttr !== "undefined" ? disabledAttr : status !== "idle",
|
|
42
|
-
children
|
|
43
|
-
}
|
|
44
|
-
);
|
|
14
|
+
const { status, linesRemove, linesUpdate } = useCart();
|
|
15
|
+
const cartLine = useCartLine();
|
|
16
|
+
const { children, adjust, onClick, ...passthroughProps } = props;
|
|
17
|
+
const handleAdjust = useCallback(() => {
|
|
18
|
+
if (adjust === "remove") {
|
|
19
|
+
linesRemove([cartLine?.id ?? ""]);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const quantity = adjust === "decrease" ? (cartLine?.quantity ?? 0) - 1 : (cartLine?.quantity ?? 0) + 1;
|
|
23
|
+
if (quantity <= 0) {
|
|
24
|
+
linesRemove([cartLine?.id ?? ""]);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
linesUpdate([{
|
|
28
|
+
id: cartLine?.id ?? "",
|
|
29
|
+
quantity,
|
|
30
|
+
attributes: cartLine?.attributes ?? []
|
|
31
|
+
}]);
|
|
32
|
+
}, [
|
|
33
|
+
adjust,
|
|
34
|
+
cartLine?.attributes,
|
|
35
|
+
cartLine?.id,
|
|
36
|
+
cartLine?.quantity,
|
|
37
|
+
linesRemove,
|
|
38
|
+
linesUpdate
|
|
39
|
+
]);
|
|
40
|
+
const disabledAttr = passthroughProps.disabled;
|
|
41
|
+
return /* @__PURE__ */ jsx(BaseButton, {
|
|
42
|
+
...passthroughProps,
|
|
43
|
+
onClick,
|
|
44
|
+
defaultOnClick: handleAdjust,
|
|
45
|
+
disabled: typeof disabledAttr !== "undefined" ? disabledAttr : status !== "idle",
|
|
46
|
+
children
|
|
47
|
+
});
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//# sourceMappingURL=CartLineQuantityAdjustButton.mjs.map
|
|
49
|
+
//#endregion
|
|
50
|
+
export { CartLineQuantityAdjustButton };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=CartLineQuantityAdjustButton.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CartLineQuantityAdjustButton.mjs","sources":["../../src/CartLineQuantityAdjustButton.tsx"],"sourcesContent":["import {useCallback} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {useCartLine} from './CartLineProvider.js';\nimport {BaseButton, type BaseButtonProps} from './BaseButton.js';\nimport type {CartLineUpdateInput} from './storefront-api-types.js';\n\ninterface CartLineQuantityAdjustButtonBaseProps {\n /** The adjustment for a cart line's quantity. Valid values: `increase` (default), `decrease`, or `remove`. */\n adjust?: 'increase' | 'decrease' | 'remove';\n}\n\ntype CartLineQuantityAdjustButtonProps<\n AsType extends React.ElementType = 'button',\n> = BaseButtonProps<AsType> & CartLineQuantityAdjustButtonBaseProps;\n\n/**\n * The `<CartLineQuantityAdjustButton />` component renders a button that adjusts the cart line's quantity when pressed.\n *\n * It must be a descendent of `<CartLineProvider/>` and `<CartProvider/>`.\n * @publicDocs\n */\nexport function CartLineQuantityAdjustButton<\n AsType extends React.ElementType = 'button',\n>(props: CartLineQuantityAdjustButtonProps<AsType>): JSX.Element {\n const {status, linesRemove, linesUpdate} = useCart();\n const cartLine = useCartLine();\n const {children, adjust, onClick, ...passthroughProps} = props;\n\n const handleAdjust = useCallback(() => {\n if (adjust === 'remove') {\n linesRemove([cartLine?.id ?? '']);\n return;\n }\n\n const quantity =\n adjust === 'decrease'\n ? (cartLine?.quantity ?? 0) - 1\n : (cartLine?.quantity ?? 0) + 1;\n\n if (quantity <= 0) {\n linesRemove([cartLine?.id ?? '']);\n return;\n }\n\n const lineUpdate = {\n id: cartLine?.id ?? '',\n quantity,\n attributes: (cartLine?.attributes ??\n []) as CartLineUpdateInput['attributes'],\n } satisfies CartLineUpdateInput;\n\n linesUpdate([lineUpdate]);\n }, [\n adjust,\n cartLine?.attributes,\n cartLine?.id,\n cartLine?.quantity,\n linesRemove,\n linesUpdate,\n ]);\n\n // Only certain 'as' types such as 'button' contain `disabled`\n const disabledAttr = (passthroughProps as {disabled?: boolean}).disabled;\n\n return (\n <BaseButton\n {...passthroughProps}\n onClick={onClick}\n defaultOnClick={handleAdjust}\n disabled={\n typeof disabledAttr !== 'undefined' ? disabledAttr : status !== 'idle'\n }\n >\n {children}\n </BaseButton>\n );\n}\n"],"
|
|
1
|
+
{"version":3,"file":"CartLineQuantityAdjustButton.mjs","names":[],"sources":["../../src/CartLineQuantityAdjustButton.tsx"],"sourcesContent":["import {useCallback} from 'react';\nimport {useCart} from './CartProvider.js';\nimport {useCartLine} from './CartLineProvider.js';\nimport {BaseButton, type BaseButtonProps} from './BaseButton.js';\nimport type {CartLineUpdateInput} from './storefront-api-types.js';\n\ninterface CartLineQuantityAdjustButtonBaseProps {\n /** The adjustment for a cart line's quantity. Valid values: `increase` (default), `decrease`, or `remove`. */\n adjust?: 'increase' | 'decrease' | 'remove';\n}\n\ntype CartLineQuantityAdjustButtonProps<\n AsType extends React.ElementType = 'button',\n> = BaseButtonProps<AsType> & CartLineQuantityAdjustButtonBaseProps;\n\n/**\n * The `<CartLineQuantityAdjustButton />` component renders a button that adjusts the cart line's quantity when pressed.\n *\n * It must be a descendent of `<CartLineProvider/>` and `<CartProvider/>`.\n * @publicDocs\n */\nexport function CartLineQuantityAdjustButton<\n AsType extends React.ElementType = 'button',\n>(props: CartLineQuantityAdjustButtonProps<AsType>): JSX.Element {\n const {status, linesRemove, linesUpdate} = useCart();\n const cartLine = useCartLine();\n const {children, adjust, onClick, ...passthroughProps} = props;\n\n const handleAdjust = useCallback(() => {\n if (adjust === 'remove') {\n linesRemove([cartLine?.id ?? '']);\n return;\n }\n\n const quantity =\n adjust === 'decrease'\n ? (cartLine?.quantity ?? 0) - 1\n : (cartLine?.quantity ?? 0) + 1;\n\n if (quantity <= 0) {\n linesRemove([cartLine?.id ?? '']);\n return;\n }\n\n const lineUpdate = {\n id: cartLine?.id ?? '',\n quantity,\n attributes: (cartLine?.attributes ??\n []) as CartLineUpdateInput['attributes'],\n } satisfies CartLineUpdateInput;\n\n linesUpdate([lineUpdate]);\n }, [\n adjust,\n cartLine?.attributes,\n cartLine?.id,\n cartLine?.quantity,\n linesRemove,\n linesUpdate,\n ]);\n\n // Only certain 'as' types such as 'button' contain `disabled`\n const disabledAttr = (passthroughProps as {disabled?: boolean}).disabled;\n\n return (\n <BaseButton\n {...passthroughProps}\n onClick={onClick}\n defaultOnClick={handleAdjust}\n disabled={\n typeof disabledAttr !== 'undefined' ? disabledAttr : status !== 'idle'\n }\n >\n {children}\n </BaseButton>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,SAAgB,6BAEd,OAA+D;CAC/D,MAAM,EAAC,QAAQ,aAAa,gBAAe,SAAS;CACpD,MAAM,WAAW,aAAa;CAC9B,MAAM,EAAC,UAAU,QAAQ,SAAS,GAAG,qBAAoB;CAEzD,MAAM,eAAe,kBAAkB;AACrC,MAAI,WAAW,UAAU;AACvB,eAAY,CAAC,UAAU,MAAM,GAAG,CAAC;AACjC;;EAGF,MAAM,WACJ,WAAW,cACN,UAAU,YAAY,KAAK,KAC3B,UAAU,YAAY,KAAK;AAElC,MAAI,YAAY,GAAG;AACjB,eAAY,CAAC,UAAU,MAAM,GAAG,CAAC;AACjC;;AAUF,cAAY,CAPO;GACjB,IAAI,UAAU,MAAM;GACpB;GACA,YAAa,UAAU,cACrB,EAAE;GACL,CAEuB,CAAC;IACxB;EACD;EACA,UAAU;EACV,UAAU;EACV,UAAU;EACV;EACA;EACD,CAAC;CAGF,MAAM,eAAgB,iBAA0C;AAEhE,QACE,oBAAC,YAAD;EACE,GAAI;EACK;EACT,gBAAgB;EAChB,UACE,OAAO,iBAAiB,cAAc,eAAe,WAAW;EAGjE;EACU,CAAA"}
|