@shopify/hydrogen-react 2022.10.8 → 2023.1.5
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/README.md +41 -47
- package/dist/browser-dev/AddToCartButton.mjs +43 -40
- package/dist/browser-dev/AddToCartButton.mjs.map +1 -1
- package/dist/browser-dev/BaseButton.mjs +13 -15
- package/dist/browser-dev/BaseButton.mjs.map +1 -1
- package/dist/browser-dev/BuyNowButton.mjs +19 -17
- package/dist/browser-dev/BuyNowButton.mjs.map +1 -1
- package/dist/browser-dev/CartCheckoutButton.mjs +12 -15
- package/dist/browser-dev/CartCheckoutButton.mjs.map +1 -1
- package/dist/browser-dev/CartCost.mjs +25 -0
- package/dist/browser-dev/CartCost.mjs.map +1 -0
- package/dist/browser-dev/CartLinePrice.mjs +21 -0
- package/dist/browser-dev/CartLinePrice.mjs.map +1 -0
- package/dist/browser-dev/CartLineProvider.mjs +22 -0
- package/dist/browser-dev/CartLineProvider.mjs.map +1 -0
- package/dist/browser-dev/CartLineQuantity.mjs +12 -0
- package/dist/browser-dev/CartLineQuantity.mjs.map +1 -0
- package/dist/browser-dev/CartLineQuantityAdjustButton.mjs +48 -0
- package/dist/browser-dev/CartLineQuantityAdjustButton.mjs.map +1 -0
- package/dist/browser-dev/CartProvider.mjs +74 -68
- package/dist/browser-dev/CartProvider.mjs.map +1 -1
- package/dist/browser-dev/ExternalVideo.mjs +13 -11
- package/dist/browser-dev/ExternalVideo.mjs.map +1 -1
- package/dist/browser-dev/Image.mjs +41 -30
- package/dist/browser-dev/Image.mjs.map +1 -1
- package/dist/browser-dev/MediaFile.mjs +29 -21
- package/dist/browser-dev/MediaFile.mjs.map +1 -1
- package/dist/browser-dev/ModelViewer.mjs +138 -76
- package/dist/browser-dev/ModelViewer.mjs.map +1 -1
- package/dist/browser-dev/Money.mjs +12 -9
- package/dist/browser-dev/Money.mjs.map +1 -1
- package/dist/browser-dev/ProductPrice.mjs +12 -17
- package/dist/browser-dev/ProductPrice.mjs.map +1 -1
- package/dist/browser-dev/ProductProvider.mjs +102 -73
- package/dist/browser-dev/ProductProvider.mjs.map +1 -1
- package/dist/browser-dev/ShopPayButton.mjs +14 -24
- package/dist/browser-dev/ShopPayButton.mjs.map +1 -1
- package/dist/browser-dev/ShopifyProvider.mjs +22 -38
- package/dist/browser-dev/ShopifyProvider.mjs.map +1 -1
- package/dist/browser-dev/Video.mjs +30 -21
- package/dist/browser-dev/Video.mjs.map +1 -1
- package/dist/browser-dev/_virtual/index.mjs +11 -2
- package/dist/browser-dev/_virtual/index.mjs.map +1 -1
- package/dist/browser-dev/_virtual/with-selector.mjs +11 -2
- package/dist/browser-dev/_virtual/with-selector.mjs.map +1 -1
- package/dist/browser-dev/analytics-constants.mjs +43 -0
- package/dist/browser-dev/analytics-constants.mjs.map +1 -0
- package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
- package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
- package/dist/browser-dev/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
- package/dist/browser-dev/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
- package/dist/browser-dev/analytics-utils.mjs +49 -0
- package/dist/browser-dev/analytics-utils.mjs.map +1 -0
- package/dist/browser-dev/analytics.mjs +159 -0
- package/dist/browser-dev/analytics.mjs.map +1 -0
- package/dist/browser-dev/cart-hooks.mjs +32 -34
- package/dist/browser-dev/cart-hooks.mjs.map +1 -1
- package/dist/browser-dev/cart-queries.mjs +50 -28
- package/dist/browser-dev/cart-queries.mjs.map +1 -1
- package/dist/browser-dev/codegen.helpers.mjs +1 -0
- package/dist/browser-dev/codegen.helpers.mjs.map +1 -1
- package/dist/browser-dev/cookies-utils.mjs +50 -0
- package/dist/browser-dev/cookies-utils.mjs.map +1 -0
- package/dist/browser-dev/flatten-connection.mjs +7 -5
- package/dist/browser-dev/flatten-connection.mjs.map +1 -1
- package/dist/browser-dev/image-size.mjs +8 -8
- package/dist/browser-dev/image-size.mjs.map +1 -1
- package/dist/browser-dev/index.mjs +24 -6
- package/dist/browser-dev/index.mjs.map +1 -1
- package/dist/browser-dev/load-script.mjs +3 -1
- package/dist/browser-dev/load-script.mjs.map +1 -1
- package/dist/browser-dev/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/browser-dev/node_modules/@xstate/react/es/fsm.mjs +2 -2
- package/dist/browser-dev/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
- package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -1
- package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -1
- package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -1
- package/dist/browser-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -1
- package/dist/browser-dev/node_modules/use-sync-external-store/shim/index.mjs +3 -3
- package/dist/browser-dev/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
- package/dist/browser-dev/{metafield-parser.mjs → parse-metafield.mjs} +20 -12
- package/dist/browser-dev/parse-metafield.mjs.map +1 -0
- package/dist/browser-dev/storefront-api-constants.mjs +1 -1
- package/dist/browser-dev/storefront-api-constants.mjs.map +1 -1
- package/dist/browser-dev/storefront-client.mjs +27 -27
- package/dist/browser-dev/storefront-client.mjs.map +1 -1
- package/dist/browser-dev/useCartAPIStateMachine.mjs +120 -80
- package/dist/browser-dev/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/browser-dev/useCartActions.mjs +150 -109
- package/dist/browser-dev/useCartActions.mjs.map +1 -1
- package/dist/browser-dev/useMoney.mjs +63 -36
- package/dist/browser-dev/useMoney.mjs.map +1 -1
- package/dist/browser-dev/useShopifyCookies.mjs +41 -0
- package/dist/browser-dev/useShopifyCookies.mjs.map +1 -0
- package/dist/browser-prod/AddToCartButton.mjs +43 -40
- package/dist/browser-prod/AddToCartButton.mjs.map +1 -1
- package/dist/browser-prod/BaseButton.mjs +13 -15
- package/dist/browser-prod/BaseButton.mjs.map +1 -1
- package/dist/browser-prod/BuyNowButton.mjs +19 -17
- package/dist/browser-prod/BuyNowButton.mjs.map +1 -1
- package/dist/browser-prod/CartCheckoutButton.mjs +12 -15
- package/dist/browser-prod/CartCheckoutButton.mjs.map +1 -1
- package/dist/browser-prod/CartCost.mjs +25 -0
- package/dist/browser-prod/CartCost.mjs.map +1 -0
- package/dist/browser-prod/CartLinePrice.mjs +18 -0
- package/dist/browser-prod/CartLinePrice.mjs.map +1 -0
- package/dist/browser-prod/CartLineProvider.mjs +22 -0
- package/dist/browser-prod/CartLineProvider.mjs.map +1 -0
- package/dist/browser-prod/CartLineQuantity.mjs +12 -0
- package/dist/browser-prod/CartLineQuantity.mjs.map +1 -0
- package/dist/browser-prod/CartLineQuantityAdjustButton.mjs +48 -0
- package/dist/browser-prod/CartLineQuantityAdjustButton.mjs.map +1 -0
- package/dist/browser-prod/CartProvider.mjs +74 -68
- package/dist/browser-prod/CartProvider.mjs.map +1 -1
- package/dist/browser-prod/ExternalVideo.mjs +13 -11
- package/dist/browser-prod/ExternalVideo.mjs.map +1 -1
- package/dist/browser-prod/Image.mjs +35 -28
- package/dist/browser-prod/Image.mjs.map +1 -1
- package/dist/browser-prod/MediaFile.mjs +29 -21
- package/dist/browser-prod/MediaFile.mjs.map +1 -1
- package/dist/browser-prod/ModelViewer.mjs +135 -75
- package/dist/browser-prod/ModelViewer.mjs.map +1 -1
- package/dist/browser-prod/Money.mjs +12 -9
- package/dist/browser-prod/Money.mjs.map +1 -1
- package/dist/browser-prod/ProductPrice.mjs +12 -17
- package/dist/browser-prod/ProductPrice.mjs.map +1 -1
- package/dist/browser-prod/ProductProvider.mjs +102 -73
- package/dist/browser-prod/ProductProvider.mjs.map +1 -1
- package/dist/browser-prod/ShopPayButton.mjs +14 -24
- package/dist/browser-prod/ShopPayButton.mjs.map +1 -1
- package/dist/browser-prod/ShopifyProvider.mjs +22 -32
- package/dist/browser-prod/ShopifyProvider.mjs.map +1 -1
- package/dist/browser-prod/Video.mjs +30 -21
- package/dist/browser-prod/Video.mjs.map +1 -1
- package/dist/browser-prod/_virtual/index.mjs +11 -2
- package/dist/browser-prod/_virtual/index.mjs.map +1 -1
- package/dist/browser-prod/_virtual/with-selector.mjs +11 -2
- package/dist/browser-prod/_virtual/with-selector.mjs.map +1 -1
- package/dist/browser-prod/analytics-constants.mjs +43 -0
- package/dist/browser-prod/analytics-constants.mjs.map +1 -0
- package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
- package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
- package/dist/browser-prod/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
- package/dist/browser-prod/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
- package/dist/browser-prod/analytics-utils.mjs +49 -0
- package/dist/browser-prod/analytics-utils.mjs.map +1 -0
- package/dist/browser-prod/analytics.mjs +158 -0
- package/dist/browser-prod/analytics.mjs.map +1 -0
- package/dist/browser-prod/cart-hooks.mjs +32 -34
- package/dist/browser-prod/cart-hooks.mjs.map +1 -1
- package/dist/browser-prod/cart-queries.mjs +50 -28
- package/dist/browser-prod/cart-queries.mjs.map +1 -1
- package/dist/browser-prod/codegen.helpers.mjs +1 -0
- package/dist/browser-prod/codegen.helpers.mjs.map +1 -1
- package/dist/browser-prod/cookies-utils.mjs +50 -0
- package/dist/browser-prod/cookies-utils.mjs.map +1 -0
- package/dist/browser-prod/flatten-connection.mjs +7 -5
- package/dist/browser-prod/flatten-connection.mjs.map +1 -1
- package/dist/browser-prod/image-size.mjs +8 -8
- package/dist/browser-prod/image-size.mjs.map +1 -1
- package/dist/browser-prod/index.mjs +24 -6
- package/dist/browser-prod/index.mjs.map +1 -1
- package/dist/browser-prod/load-script.mjs +3 -1
- package/dist/browser-prod/load-script.mjs.map +1 -1
- package/dist/browser-prod/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/browser-prod/node_modules/@xstate/react/es/fsm.mjs +2 -2
- package/dist/browser-prod/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
- package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -1
- package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -1
- package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -1
- package/dist/browser-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -1
- package/dist/browser-prod/node_modules/use-sync-external-store/shim/index.mjs +3 -3
- package/dist/browser-prod/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
- package/dist/browser-prod/{metafield-parser.mjs → parse-metafield.mjs} +20 -12
- package/dist/browser-prod/parse-metafield.mjs.map +1 -0
- package/dist/browser-prod/storefront-api-constants.mjs +1 -1
- package/dist/browser-prod/storefront-api-constants.mjs.map +1 -1
- package/dist/browser-prod/storefront-client.mjs +27 -27
- package/dist/browser-prod/storefront-client.mjs.map +1 -1
- package/dist/browser-prod/useCartAPIStateMachine.mjs +120 -80
- package/dist/browser-prod/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/browser-prod/useCartActions.mjs +150 -109
- package/dist/browser-prod/useCartActions.mjs.map +1 -1
- package/dist/browser-prod/useMoney.mjs +63 -36
- package/dist/browser-prod/useMoney.mjs.map +1 -1
- package/dist/browser-prod/useShopifyCookies.mjs +41 -0
- package/dist/browser-prod/useShopifyCookies.mjs.map +1 -0
- package/dist/node-dev/AddToCartButton.js +44 -41
- package/dist/node-dev/AddToCartButton.js.map +1 -1
- package/dist/node-dev/AddToCartButton.mjs +43 -40
- package/dist/node-dev/AddToCartButton.mjs.map +1 -1
- package/dist/node-dev/BaseButton.js +14 -16
- package/dist/node-dev/BaseButton.js.map +1 -1
- package/dist/node-dev/BaseButton.mjs +13 -15
- package/dist/node-dev/BaseButton.mjs.map +1 -1
- package/dist/node-dev/BuyNowButton.js +20 -18
- package/dist/node-dev/BuyNowButton.js.map +1 -1
- package/dist/node-dev/BuyNowButton.mjs +19 -17
- package/dist/node-dev/BuyNowButton.mjs.map +1 -1
- package/dist/node-dev/CartCheckoutButton.js +13 -16
- package/dist/node-dev/CartCheckoutButton.js.map +1 -1
- package/dist/node-dev/CartCheckoutButton.mjs +12 -15
- package/dist/node-dev/CartCheckoutButton.mjs.map +1 -1
- package/dist/node-dev/CartCost.js +25 -0
- package/dist/node-dev/CartCost.js.map +1 -0
- package/dist/node-dev/CartCost.mjs +25 -0
- package/dist/node-dev/CartCost.mjs.map +1 -0
- package/dist/node-dev/CartLinePrice.js +21 -0
- package/dist/node-dev/CartLinePrice.js.map +1 -0
- package/dist/node-dev/CartLinePrice.mjs +21 -0
- package/dist/node-dev/CartLinePrice.mjs.map +1 -0
- package/dist/node-dev/CartLineProvider.js +22 -0
- package/dist/node-dev/CartLineProvider.js.map +1 -0
- package/dist/node-dev/CartLineProvider.mjs +22 -0
- package/dist/node-dev/CartLineProvider.mjs.map +1 -0
- package/dist/node-dev/CartLineQuantity.js +12 -0
- package/dist/node-dev/CartLineQuantity.js.map +1 -0
- package/dist/node-dev/CartLineQuantity.mjs +12 -0
- package/dist/node-dev/CartLineQuantity.mjs.map +1 -0
- package/dist/node-dev/CartLineQuantityAdjustButton.js +48 -0
- package/dist/node-dev/CartLineQuantityAdjustButton.js.map +1 -0
- package/dist/node-dev/CartLineQuantityAdjustButton.mjs +48 -0
- package/dist/node-dev/CartLineQuantityAdjustButton.mjs.map +1 -0
- package/dist/node-dev/CartProvider.js +75 -69
- package/dist/node-dev/CartProvider.js.map +1 -1
- package/dist/node-dev/CartProvider.mjs +74 -68
- package/dist/node-dev/CartProvider.mjs.map +1 -1
- package/dist/node-dev/ExternalVideo.js +14 -12
- package/dist/node-dev/ExternalVideo.js.map +1 -1
- package/dist/node-dev/ExternalVideo.mjs +13 -11
- package/dist/node-dev/ExternalVideo.mjs.map +1 -1
- package/dist/node-dev/Image.js +42 -31
- package/dist/node-dev/Image.js.map +1 -1
- package/dist/node-dev/Image.mjs +41 -30
- package/dist/node-dev/Image.mjs.map +1 -1
- package/dist/node-dev/MediaFile.js +30 -22
- package/dist/node-dev/MediaFile.js.map +1 -1
- package/dist/node-dev/MediaFile.mjs +29 -21
- package/dist/node-dev/MediaFile.mjs.map +1 -1
- package/dist/node-dev/ModelViewer.js +139 -77
- package/dist/node-dev/ModelViewer.js.map +1 -1
- package/dist/node-dev/ModelViewer.mjs +138 -76
- package/dist/node-dev/ModelViewer.mjs.map +1 -1
- package/dist/node-dev/Money.js +13 -10
- package/dist/node-dev/Money.js.map +1 -1
- package/dist/node-dev/Money.mjs +12 -9
- package/dist/node-dev/Money.mjs.map +1 -1
- package/dist/node-dev/ProductPrice.js +13 -18
- package/dist/node-dev/ProductPrice.js.map +1 -1
- package/dist/node-dev/ProductPrice.mjs +12 -17
- package/dist/node-dev/ProductPrice.mjs.map +1 -1
- package/dist/node-dev/ProductProvider.js +103 -74
- package/dist/node-dev/ProductProvider.js.map +1 -1
- package/dist/node-dev/ProductProvider.mjs +102 -73
- package/dist/node-dev/ProductProvider.mjs.map +1 -1
- package/dist/node-dev/ShopPayButton.js +14 -24
- package/dist/node-dev/ShopPayButton.js.map +1 -1
- package/dist/node-dev/ShopPayButton.mjs +14 -24
- package/dist/node-dev/ShopPayButton.mjs.map +1 -1
- package/dist/node-dev/ShopifyProvider.js +23 -39
- package/dist/node-dev/ShopifyProvider.js.map +1 -1
- package/dist/node-dev/ShopifyProvider.mjs +22 -38
- package/dist/node-dev/ShopifyProvider.mjs.map +1 -1
- package/dist/node-dev/Video.js +31 -22
- package/dist/node-dev/Video.js.map +1 -1
- package/dist/node-dev/Video.mjs +30 -21
- package/dist/node-dev/Video.mjs.map +1 -1
- package/dist/node-dev/_virtual/index.js +11 -3
- package/dist/node-dev/_virtual/index.js.map +1 -1
- package/dist/node-dev/_virtual/index.mjs +11 -2
- package/dist/node-dev/_virtual/index.mjs.map +1 -1
- package/dist/node-dev/_virtual/use-sync-external-store-shim.development.js +1 -1
- package/dist/node-dev/_virtual/use-sync-external-store-shim.production.min.js +1 -1
- package/dist/node-dev/_virtual/with-selector.development.js +1 -1
- package/dist/node-dev/_virtual/with-selector.js +11 -3
- package/dist/node-dev/_virtual/with-selector.js.map +1 -1
- package/dist/node-dev/_virtual/with-selector.mjs +11 -2
- package/dist/node-dev/_virtual/with-selector.mjs.map +1 -1
- package/dist/node-dev/_virtual/with-selector.production.min.js +1 -1
- package/dist/node-dev/analytics-constants.js +43 -0
- package/dist/node-dev/analytics-constants.js.map +1 -0
- package/dist/node-dev/analytics-constants.mjs +43 -0
- package/dist/node-dev/analytics-constants.mjs.map +1 -0
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js +145 -0
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js.map +1 -0
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.js +58 -0
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.js.map +1 -0
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
- package/dist/node-dev/analytics-utils.js +49 -0
- package/dist/node-dev/analytics-utils.js.map +1 -0
- package/dist/node-dev/analytics-utils.mjs +49 -0
- package/dist/node-dev/analytics-utils.mjs.map +1 -0
- package/dist/node-dev/analytics.js +159 -0
- package/dist/node-dev/analytics.js.map +1 -0
- package/dist/node-dev/analytics.mjs +159 -0
- package/dist/node-dev/analytics.mjs.map +1 -0
- package/dist/node-dev/cart-constants.js +1 -1
- package/dist/node-dev/cart-hooks.js +32 -34
- package/dist/node-dev/cart-hooks.js.map +1 -1
- package/dist/node-dev/cart-hooks.mjs +32 -34
- package/dist/node-dev/cart-hooks.mjs.map +1 -1
- package/dist/node-dev/cart-queries.js +51 -29
- package/dist/node-dev/cart-queries.js.map +1 -1
- package/dist/node-dev/cart-queries.mjs +50 -28
- package/dist/node-dev/cart-queries.mjs.map +1 -1
- package/dist/node-dev/codegen.helpers.js +2 -1
- package/dist/node-dev/codegen.helpers.js.map +1 -1
- package/dist/node-dev/codegen.helpers.mjs +1 -0
- package/dist/node-dev/codegen.helpers.mjs.map +1 -1
- package/dist/node-dev/cookies-utils.js +50 -0
- package/dist/node-dev/cookies-utils.js.map +1 -0
- package/dist/node-dev/cookies-utils.mjs +50 -0
- package/dist/node-dev/cookies-utils.mjs.map +1 -0
- package/dist/node-dev/flatten-connection.js +8 -6
- package/dist/node-dev/flatten-connection.js.map +1 -1
- package/dist/node-dev/flatten-connection.mjs +7 -5
- package/dist/node-dev/flatten-connection.mjs.map +1 -1
- package/dist/node-dev/image-size.js +9 -9
- package/dist/node-dev/image-size.js.map +1 -1
- package/dist/node-dev/image-size.mjs +8 -8
- package/dist/node-dev/image-size.mjs.map +1 -1
- package/dist/node-dev/index.js +25 -7
- package/dist/node-dev/index.js.map +1 -1
- package/dist/node-dev/index.mjs +24 -6
- package/dist/node-dev/index.mjs.map +1 -1
- package/dist/node-dev/load-script.js +4 -2
- package/dist/node-dev/load-script.js.map +1 -1
- package/dist/node-dev/load-script.mjs +3 -1
- package/dist/node-dev/load-script.mjs.map +1 -1
- package/dist/node-dev/node_modules/@xstate/fsm/es/index.js +1 -1
- package/dist/node-dev/node_modules/@xstate/fsm/es/index.js.map +1 -1
- package/dist/node-dev/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/node-dev/node_modules/@xstate/react/es/fsm.js +2 -2
- package/dist/node-dev/node_modules/@xstate/react/es/fsm.js.map +1 -1
- package/dist/node-dev/node_modules/@xstate/react/es/fsm.mjs +2 -2
- package/dist/node-dev/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
- package/dist/node-dev/node_modules/@xstate/react/es/useConstant.js +2 -4
- package/dist/node-dev/node_modules/@xstate/react/es/useConstant.js.map +1 -1
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +2 -4
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -1
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -1
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +2 -4
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -1
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -1
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +2 -4
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -1
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -1
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +2 -4
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -1
- package/dist/node-dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -1
- package/dist/node-dev/node_modules/use-sync-external-store/shim/index.js +4 -4
- package/dist/node-dev/node_modules/use-sync-external-store/shim/index.mjs +3 -3
- package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.js +1 -1
- package/dist/node-dev/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
- package/dist/node-dev/{metafield-parser.js → parse-metafield.js} +21 -13
- package/dist/node-dev/parse-metafield.js.map +1 -0
- package/dist/node-dev/{metafield-parser.mjs → parse-metafield.mjs} +20 -12
- package/dist/node-dev/parse-metafield.mjs.map +1 -0
- package/dist/node-dev/storefront-api-constants.js +2 -2
- package/dist/node-dev/storefront-api-constants.js.map +1 -1
- package/dist/node-dev/storefront-api-constants.mjs +1 -1
- package/dist/node-dev/storefront-api-constants.mjs.map +1 -1
- package/dist/node-dev/storefront-client.js +28 -28
- package/dist/node-dev/storefront-client.js.map +1 -1
- package/dist/node-dev/storefront-client.mjs +27 -27
- package/dist/node-dev/storefront-client.mjs.map +1 -1
- package/dist/node-dev/useCartAPIStateMachine.js +121 -81
- package/dist/node-dev/useCartAPIStateMachine.js.map +1 -1
- package/dist/node-dev/useCartAPIStateMachine.mjs +120 -80
- package/dist/node-dev/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/node-dev/useCartActions.js +151 -110
- package/dist/node-dev/useCartActions.js.map +1 -1
- package/dist/node-dev/useCartActions.mjs +150 -109
- package/dist/node-dev/useCartActions.mjs.map +1 -1
- package/dist/node-dev/useMoney.js +64 -37
- package/dist/node-dev/useMoney.js.map +1 -1
- package/dist/node-dev/useMoney.mjs +63 -36
- package/dist/node-dev/useMoney.mjs.map +1 -1
- package/dist/node-dev/useShopifyCookies.js +41 -0
- package/dist/node-dev/useShopifyCookies.js.map +1 -0
- package/dist/node-dev/useShopifyCookies.mjs +41 -0
- package/dist/node-dev/useShopifyCookies.mjs.map +1 -0
- package/dist/node-prod/AddToCartButton.js +44 -41
- package/dist/node-prod/AddToCartButton.js.map +1 -1
- package/dist/node-prod/AddToCartButton.mjs +43 -40
- package/dist/node-prod/AddToCartButton.mjs.map +1 -1
- package/dist/node-prod/BaseButton.js +14 -16
- package/dist/node-prod/BaseButton.js.map +1 -1
- package/dist/node-prod/BaseButton.mjs +13 -15
- package/dist/node-prod/BaseButton.mjs.map +1 -1
- package/dist/node-prod/BuyNowButton.js +20 -18
- package/dist/node-prod/BuyNowButton.js.map +1 -1
- package/dist/node-prod/BuyNowButton.mjs +19 -17
- package/dist/node-prod/BuyNowButton.mjs.map +1 -1
- package/dist/node-prod/CartCheckoutButton.js +13 -16
- package/dist/node-prod/CartCheckoutButton.js.map +1 -1
- package/dist/node-prod/CartCheckoutButton.mjs +12 -15
- package/dist/node-prod/CartCheckoutButton.mjs.map +1 -1
- package/dist/node-prod/CartCost.js +25 -0
- package/dist/node-prod/CartCost.js.map +1 -0
- package/dist/node-prod/CartCost.mjs +25 -0
- package/dist/node-prod/CartCost.mjs.map +1 -0
- package/dist/node-prod/CartLinePrice.js +18 -0
- package/dist/node-prod/CartLinePrice.js.map +1 -0
- package/dist/node-prod/CartLinePrice.mjs +18 -0
- package/dist/node-prod/CartLinePrice.mjs.map +1 -0
- package/dist/node-prod/CartLineProvider.js +22 -0
- package/dist/node-prod/CartLineProvider.js.map +1 -0
- package/dist/node-prod/CartLineProvider.mjs +22 -0
- package/dist/node-prod/CartLineProvider.mjs.map +1 -0
- package/dist/node-prod/CartLineQuantity.js +12 -0
- package/dist/node-prod/CartLineQuantity.js.map +1 -0
- package/dist/node-prod/CartLineQuantity.mjs +12 -0
- package/dist/node-prod/CartLineQuantity.mjs.map +1 -0
- package/dist/node-prod/CartLineQuantityAdjustButton.js +48 -0
- package/dist/node-prod/CartLineQuantityAdjustButton.js.map +1 -0
- package/dist/node-prod/CartLineQuantityAdjustButton.mjs +48 -0
- package/dist/node-prod/CartLineQuantityAdjustButton.mjs.map +1 -0
- package/dist/node-prod/CartProvider.js +75 -69
- package/dist/node-prod/CartProvider.js.map +1 -1
- package/dist/node-prod/CartProvider.mjs +74 -68
- package/dist/node-prod/CartProvider.mjs.map +1 -1
- package/dist/node-prod/ExternalVideo.js +14 -12
- package/dist/node-prod/ExternalVideo.js.map +1 -1
- package/dist/node-prod/ExternalVideo.mjs +13 -11
- package/dist/node-prod/ExternalVideo.mjs.map +1 -1
- package/dist/node-prod/Image.js +36 -29
- package/dist/node-prod/Image.js.map +1 -1
- package/dist/node-prod/Image.mjs +35 -28
- package/dist/node-prod/Image.mjs.map +1 -1
- package/dist/node-prod/MediaFile.js +30 -22
- package/dist/node-prod/MediaFile.js.map +1 -1
- package/dist/node-prod/MediaFile.mjs +29 -21
- package/dist/node-prod/MediaFile.mjs.map +1 -1
- package/dist/node-prod/ModelViewer.js +136 -76
- package/dist/node-prod/ModelViewer.js.map +1 -1
- package/dist/node-prod/ModelViewer.mjs +135 -75
- package/dist/node-prod/ModelViewer.mjs.map +1 -1
- package/dist/node-prod/Money.js +13 -10
- package/dist/node-prod/Money.js.map +1 -1
- package/dist/node-prod/Money.mjs +12 -9
- package/dist/node-prod/Money.mjs.map +1 -1
- package/dist/node-prod/ProductPrice.js +13 -18
- package/dist/node-prod/ProductPrice.js.map +1 -1
- package/dist/node-prod/ProductPrice.mjs +12 -17
- package/dist/node-prod/ProductPrice.mjs.map +1 -1
- package/dist/node-prod/ProductProvider.js +103 -74
- package/dist/node-prod/ProductProvider.js.map +1 -1
- package/dist/node-prod/ProductProvider.mjs +102 -73
- package/dist/node-prod/ProductProvider.mjs.map +1 -1
- package/dist/node-prod/ShopPayButton.js +14 -24
- package/dist/node-prod/ShopPayButton.js.map +1 -1
- package/dist/node-prod/ShopPayButton.mjs +14 -24
- package/dist/node-prod/ShopPayButton.mjs.map +1 -1
- package/dist/node-prod/ShopifyProvider.js +23 -33
- package/dist/node-prod/ShopifyProvider.js.map +1 -1
- package/dist/node-prod/ShopifyProvider.mjs +22 -32
- package/dist/node-prod/ShopifyProvider.mjs.map +1 -1
- package/dist/node-prod/Video.js +31 -22
- package/dist/node-prod/Video.js.map +1 -1
- package/dist/node-prod/Video.mjs +30 -21
- package/dist/node-prod/Video.mjs.map +1 -1
- package/dist/node-prod/_virtual/index.js +11 -3
- package/dist/node-prod/_virtual/index.js.map +1 -1
- package/dist/node-prod/_virtual/index.mjs +11 -2
- package/dist/node-prod/_virtual/index.mjs.map +1 -1
- package/dist/node-prod/_virtual/use-sync-external-store-shim.development.js +1 -1
- package/dist/node-prod/_virtual/use-sync-external-store-shim.production.min.js +1 -1
- package/dist/node-prod/_virtual/with-selector.development.js +1 -1
- package/dist/node-prod/_virtual/with-selector.js +11 -3
- package/dist/node-prod/_virtual/with-selector.js.map +1 -1
- package/dist/node-prod/_virtual/with-selector.mjs +11 -2
- package/dist/node-prod/_virtual/with-selector.mjs.map +1 -1
- package/dist/node-prod/_virtual/with-selector.production.min.js +1 -1
- package/dist/node-prod/analytics-constants.js +43 -0
- package/dist/node-prod/analytics-constants.js.map +1 -0
- package/dist/node-prod/analytics-constants.mjs +43 -0
- package/dist/node-prod/analytics-constants.mjs.map +1 -0
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js +145 -0
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js.map +1 -0
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.js +58 -0
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.js.map +1 -0
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
- package/dist/node-prod/analytics-utils.js +49 -0
- package/dist/node-prod/analytics-utils.js.map +1 -0
- package/dist/node-prod/analytics-utils.mjs +49 -0
- package/dist/node-prod/analytics-utils.mjs.map +1 -0
- package/dist/node-prod/analytics.js +158 -0
- package/dist/node-prod/analytics.js.map +1 -0
- package/dist/node-prod/analytics.mjs +158 -0
- package/dist/node-prod/analytics.mjs.map +1 -0
- package/dist/node-prod/cart-constants.js +1 -1
- package/dist/node-prod/cart-hooks.js +32 -34
- package/dist/node-prod/cart-hooks.js.map +1 -1
- package/dist/node-prod/cart-hooks.mjs +32 -34
- package/dist/node-prod/cart-hooks.mjs.map +1 -1
- package/dist/node-prod/cart-queries.js +51 -29
- package/dist/node-prod/cart-queries.js.map +1 -1
- package/dist/node-prod/cart-queries.mjs +50 -28
- package/dist/node-prod/cart-queries.mjs.map +1 -1
- package/dist/node-prod/codegen.helpers.js +2 -1
- package/dist/node-prod/codegen.helpers.js.map +1 -1
- package/dist/node-prod/codegen.helpers.mjs +1 -0
- package/dist/node-prod/codegen.helpers.mjs.map +1 -1
- package/dist/node-prod/cookies-utils.js +50 -0
- package/dist/node-prod/cookies-utils.js.map +1 -0
- package/dist/node-prod/cookies-utils.mjs +50 -0
- package/dist/node-prod/cookies-utils.mjs.map +1 -0
- package/dist/node-prod/flatten-connection.js +8 -6
- package/dist/node-prod/flatten-connection.js.map +1 -1
- package/dist/node-prod/flatten-connection.mjs +7 -5
- package/dist/node-prod/flatten-connection.mjs.map +1 -1
- package/dist/node-prod/image-size.js +9 -9
- package/dist/node-prod/image-size.js.map +1 -1
- package/dist/node-prod/image-size.mjs +8 -8
- package/dist/node-prod/image-size.mjs.map +1 -1
- package/dist/node-prod/index.js +25 -7
- package/dist/node-prod/index.js.map +1 -1
- package/dist/node-prod/index.mjs +24 -6
- package/dist/node-prod/index.mjs.map +1 -1
- package/dist/node-prod/load-script.js +4 -2
- package/dist/node-prod/load-script.js.map +1 -1
- package/dist/node-prod/load-script.mjs +3 -1
- package/dist/node-prod/load-script.mjs.map +1 -1
- package/dist/node-prod/node_modules/@xstate/fsm/es/index.js +1 -1
- package/dist/node-prod/node_modules/@xstate/fsm/es/index.js.map +1 -1
- package/dist/node-prod/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/node-prod/node_modules/@xstate/react/es/fsm.js +2 -2
- package/dist/node-prod/node_modules/@xstate/react/es/fsm.js.map +1 -1
- package/dist/node-prod/node_modules/@xstate/react/es/fsm.mjs +2 -2
- package/dist/node-prod/node_modules/@xstate/react/es/fsm.mjs.map +1 -1
- package/dist/node-prod/node_modules/@xstate/react/es/useConstant.js +2 -4
- package/dist/node-prod/node_modules/@xstate/react/es/useConstant.js.map +1 -1
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +2 -4
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -1
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -1
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +2 -4
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -1
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -1
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +2 -4
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -1
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -1
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +2 -4
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -1
- package/dist/node-prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -1
- package/dist/node-prod/node_modules/use-sync-external-store/shim/index.js +4 -4
- package/dist/node-prod/node_modules/use-sync-external-store/shim/index.mjs +3 -3
- package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.js +1 -1
- package/dist/node-prod/node_modules/use-sync-external-store/shim/with-selector.mjs +1 -1
- package/dist/node-prod/{metafield-parser.js → parse-metafield.js} +21 -13
- package/dist/node-prod/parse-metafield.js.map +1 -0
- package/dist/node-prod/{metafield-parser.mjs → parse-metafield.mjs} +20 -12
- package/dist/node-prod/parse-metafield.mjs.map +1 -0
- package/dist/node-prod/storefront-api-constants.js +2 -2
- package/dist/node-prod/storefront-api-constants.js.map +1 -1
- package/dist/node-prod/storefront-api-constants.mjs +1 -1
- package/dist/node-prod/storefront-api-constants.mjs.map +1 -1
- package/dist/node-prod/storefront-client.js +28 -28
- package/dist/node-prod/storefront-client.js.map +1 -1
- package/dist/node-prod/storefront-client.mjs +27 -27
- package/dist/node-prod/storefront-client.mjs.map +1 -1
- package/dist/node-prod/useCartAPIStateMachine.js +121 -81
- package/dist/node-prod/useCartAPIStateMachine.js.map +1 -1
- package/dist/node-prod/useCartAPIStateMachine.mjs +120 -80
- package/dist/node-prod/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/node-prod/useCartActions.js +151 -110
- package/dist/node-prod/useCartActions.js.map +1 -1
- package/dist/node-prod/useCartActions.mjs +150 -109
- package/dist/node-prod/useCartActions.mjs.map +1 -1
- package/dist/node-prod/useMoney.js +64 -37
- package/dist/node-prod/useMoney.js.map +1 -1
- package/dist/node-prod/useMoney.mjs +63 -36
- package/dist/node-prod/useMoney.mjs.map +1 -1
- package/dist/node-prod/useShopifyCookies.js +41 -0
- package/dist/node-prod/useShopifyCookies.js.map +1 -0
- package/dist/node-prod/useShopifyCookies.mjs +41 -0
- package/dist/node-prod/useShopifyCookies.mjs.map +1 -0
- package/dist/types/AddToCartButton.d.ts +7 -3
- package/dist/types/BaseButton.d.ts +2 -2
- package/dist/types/BuyNowButton.d.ts +10 -4
- package/dist/types/CartCheckoutButton.d.ts +9 -6
- package/dist/types/CartCost.d.ts +10 -6
- package/dist/types/CartLinePrice.d.ts +19 -5
- package/dist/types/CartLineProvider.d.ts +18 -10
- package/dist/types/CartLineQuantity.d.ts +13 -0
- package/dist/types/CartLineQuantityAdjustButton.d.ts +13 -0
- package/dist/types/CartProvider.d.ts +13 -3
- package/dist/types/ExternalVideo.d.ts +2 -3
- package/dist/types/Image.d.ts +5 -3
- package/dist/types/MediaFile.d.ts +12 -11
- package/dist/types/ModelViewer.d.ts +2 -2
- package/dist/types/Money.d.ts +2 -3
- package/dist/types/ProductPrice.d.ts +4 -2
- package/dist/types/ProductProvider.d.ts +1 -1
- package/dist/types/ShopPayButton.d.ts +10 -10
- package/dist/types/ShopifyProvider.d.ts +42 -43
- package/dist/types/analytics-constants.d.ts +48 -0
- package/dist/types/analytics-schema-custom-storefront-customer-tracking.d.ts +3 -0
- package/dist/types/analytics-schema-trekkie-storefront-page-view.d.ts +2 -0
- package/dist/types/analytics-types.d.ts +157 -0
- package/dist/types/analytics-utils.d.ts +36 -0
- package/dist/types/analytics.d.ts +9 -0
- package/dist/types/cart-queries.d.ts +1 -1
- package/dist/types/cookies-utils.d.ts +4 -0
- package/dist/types/flatten-connection.d.ts +32 -8
- package/dist/types/image-size.d.ts +1 -1
- package/dist/types/index.d.cts +13 -4
- package/dist/types/index.d.ts +13 -4
- package/dist/types/{metafield-parser.d.ts → parse-metafield.d.ts} +11 -9
- package/dist/types/storefront-api-constants.d.ts +1 -1
- package/dist/types/storefront-api-response.types.d.ts +1 -1
- package/dist/types/storefront-api-types.d.ts +121 -2
- package/dist/types/storefront-client.d.ts +14 -14
- package/dist/types/useCartActions.d.ts +1 -1
- package/dist/types/useShopifyCookies.d.ts +14 -0
- package/dist/umd/hydrogen-react.dev.js +1714 -1382
- package/dist/umd/hydrogen-react.dev.js.map +1 -1
- package/dist/umd/hydrogen-react.prod.js +18 -25
- package/dist/umd/hydrogen-react.prod.js.map +1 -1
- package/package.json +34 -19
- package/storefront.schema.json +1 -1
- package/dist/browser-dev/Metafield.mjs +0 -301
- package/dist/browser-dev/Metafield.mjs.map +0 -1
- package/dist/browser-dev/metafield-parser.mjs.map +0 -1
- package/dist/browser-prod/Metafield.mjs +0 -288
- package/dist/browser-prod/Metafield.mjs.map +0 -1
- package/dist/browser-prod/metafield-parser.mjs.map +0 -1
- package/dist/node-dev/Metafield.js +0 -301
- package/dist/node-dev/Metafield.js.map +0 -1
- package/dist/node-dev/Metafield.mjs +0 -301
- package/dist/node-dev/Metafield.mjs.map +0 -1
- package/dist/node-dev/metafield-parser.js.map +0 -1
- package/dist/node-dev/metafield-parser.mjs.map +0 -1
- package/dist/node-prod/Metafield.js +0 -288
- package/dist/node-prod/Metafield.js.map +0 -1
- package/dist/node-prod/Metafield.mjs +0 -288
- package/dist/node-prod/Metafield.mjs.map +0 -1
- package/dist/node-prod/metafield-parser.js.map +0 -1
- package/dist/node-prod/metafield-parser.mjs.map +0 -1
- package/dist/types/Metafield.d.ts +0 -61
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCartActions.mjs","sources":["../../src/useCartActions.tsx"],"sourcesContent":["import {useCallback, useMemo} from 'react';\nimport {\n AttributeInput,\n CartBuyerIdentityInput,\n CartInput,\n CartLineInput,\n CartLineUpdateInput,\n CountryCode,\n Cart as CartType,\n MutationCartDiscountCodesUpdateArgs,\n MutationCartNoteUpdateArgs,\n} from './storefront-api-types.js';\nimport {\n CartAttributesUpdate,\n CartBuyerIdentityUpdate,\n CartCreate,\n CartDiscountCodesUpdate,\n CartLineAdd,\n CartLineRemove,\n CartLineUpdate,\n CartNoteUpdate,\n CartQuery,\n} from './cart-queries.js';\nimport {useCartFetch} from './cart-hooks.js';\nimport {PartialDeep} from 'type-fest';\n\ntype CartResponse = PartialDeep<CartType, {recurseIntoArrays: true}>;\n\n/**\n * The `useCartActions` hook returns helper graphql functions for Storefront Cart API\n *\n * See [cart API graphql mutations](https://shopify.dev/api/storefront/
|
|
1
|
+
{"version":3,"file":"useCartActions.mjs","sources":["../../src/useCartActions.tsx"],"sourcesContent":["import {useCallback, useMemo} from 'react';\nimport {\n AttributeInput,\n CartBuyerIdentityInput,\n CartInput,\n CartLineInput,\n CartLineUpdateInput,\n CountryCode,\n Cart as CartType,\n MutationCartDiscountCodesUpdateArgs,\n MutationCartNoteUpdateArgs,\n} from './storefront-api-types.js';\nimport {\n CartAttributesUpdate,\n CartBuyerIdentityUpdate,\n CartCreate,\n CartDiscountCodesUpdate,\n CartLineAdd,\n CartLineRemove,\n CartLineUpdate,\n CartNoteUpdate,\n CartQuery,\n} from './cart-queries.js';\nimport {useCartFetch} from './cart-hooks.js';\nimport {PartialDeep} from 'type-fest';\n\ntype CartResponse = PartialDeep<CartType, {recurseIntoArrays: true}>;\n\n/**\n * The `useCartActions` hook returns helper graphql functions for Storefront Cart API\n *\n * See [cart API graphql mutations](https://shopify.dev/api/storefront/2023-01/objects/Cart)\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function useCartActions({\n numCartLines,\n cartFragment,\n countryCode = 'US',\n}: {\n /** Maximum number of cart lines to fetch. Defaults to 250 cart lines. */\n numCartLines?: number;\n /** A fragment used to query the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart) for all queries and mutations. A default value is used if no argument is provided. */\n cartFragment: string;\n /** The ISO country code for i18n. */\n countryCode?: CountryCode;\n}) {\n const fetchCart = useCartFetch();\n\n const cartFetch = useCallback(\n (cartId: string) => {\n return fetchCart<{cart: CartResponse}>({\n query: CartQuery(cartFragment),\n variables: {\n id: cartId,\n numCartLines,\n country: countryCode,\n },\n });\n },\n [fetchCart, cartFragment, numCartLines, countryCode]\n );\n\n const cartCreate = useCallback(\n (cart: CartInput) => {\n return fetchCart<{cartCreate: {cart: CartResponse}}>({\n query: CartCreate(cartFragment),\n variables: {\n input: cart,\n numCartLines,\n country: countryCode,\n },\n });\n },\n [cartFragment, countryCode, fetchCart, numCartLines]\n );\n\n const cartLineAdd = useCallback(\n (cartId: string, lines: CartLineInput[]) => {\n return fetchCart<{cartLinesAdd: {cart: CartResponse}}>({\n query: CartLineAdd(cartFragment),\n variables: {\n cartId,\n lines,\n numCartLines,\n country: countryCode,\n },\n });\n },\n [cartFragment, countryCode, fetchCart, numCartLines]\n );\n\n const cartLineUpdate = useCallback(\n (cartId: string, lines: CartLineUpdateInput[]) => {\n return fetchCart<{cartLinesUpdate: {cart: CartResponse}}>({\n query: CartLineUpdate(cartFragment),\n variables: {\n cartId,\n lines,\n numCartLines,\n country: countryCode,\n },\n });\n },\n [cartFragment, countryCode, fetchCart, numCartLines]\n );\n\n const cartLineRemove = useCallback(\n (cartId: string, lines: string[]) => {\n return fetchCart<{cartLinesRemove: {cart: CartResponse}}>({\n query: CartLineRemove(cartFragment),\n variables: {\n cartId,\n lines,\n numCartLines,\n country: countryCode,\n },\n });\n },\n [cartFragment, countryCode, fetchCart, numCartLines]\n );\n\n const noteUpdate = useCallback(\n (cartId: string, note: MutationCartNoteUpdateArgs['note']) => {\n return fetchCart<{cartNoteUpdate: {cart: CartResponse}}>({\n query: CartNoteUpdate(cartFragment),\n variables: {\n cartId,\n note,\n numCartLines,\n country: countryCode,\n },\n });\n },\n [fetchCart, cartFragment, numCartLines, countryCode]\n );\n\n const buyerIdentityUpdate = useCallback(\n (cartId: string, buyerIdentity: CartBuyerIdentityInput) => {\n return fetchCart<{cartBuyerIdentityUpdate: {cart: CartResponse}}>({\n query: CartBuyerIdentityUpdate(cartFragment),\n variables: {\n cartId,\n buyerIdentity,\n numCartLines,\n country: countryCode,\n },\n });\n },\n [cartFragment, countryCode, fetchCart, numCartLines]\n );\n\n const cartAttributesUpdate = useCallback(\n (cartId: string, attributes: AttributeInput[]) => {\n return fetchCart<{cartAttributesUpdate: {cart: CartResponse}}>({\n query: CartAttributesUpdate(cartFragment),\n variables: {\n cartId,\n attributes,\n numCartLines,\n country: countryCode,\n },\n });\n },\n [cartFragment, countryCode, fetchCart, numCartLines]\n );\n\n const discountCodesUpdate = useCallback(\n (\n cartId: string,\n discountCodes: MutationCartDiscountCodesUpdateArgs['discountCodes']\n ) => {\n return fetchCart<{cartDiscountCodesUpdate: {cart: CartResponse}}>({\n query: CartDiscountCodesUpdate(cartFragment),\n variables: {\n cartId,\n discountCodes,\n numCartLines,\n country: countryCode,\n },\n });\n },\n [cartFragment, countryCode, fetchCart, numCartLines]\n );\n\n return useMemo(\n () => ({\n cartFetch,\n cartCreate,\n cartLineAdd,\n cartLineUpdate,\n cartLineRemove,\n noteUpdate,\n buyerIdentityUpdate,\n cartAttributesUpdate,\n discountCodesUpdate,\n cartFragment,\n }),\n [\n cartFetch,\n cartCreate,\n cartLineAdd,\n cartLineUpdate,\n cartLineRemove,\n noteUpdate,\n buyerIdentityUpdate,\n cartAttributesUpdate,\n discountCodesUpdate,\n cartFragment,\n ]\n );\n}\n"],"names":[],"mappings":";;;AAkCO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAOG;AACD,QAAM,YAAY;AAElB,QAAM,YAAY;AAAA,IAChB,CAAC,WAAmB;AAClB,aAAO,UAAgC;AAAA,QACrC,OAAO,UAAU,YAAY;AAAA,QAC7B,WAAW;AAAA,UACT,IAAI;AAAA,UACJ;AAAA,UACA,SAAS;AAAA,QACX;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,WAAW,cAAc,cAAc,WAAW;AAAA,EAAA;AAGrD,QAAM,aAAa;AAAA,IACjB,CAAC,SAAoB;AACnB,aAAO,UAA8C;AAAA,QACnD,OAAO,WAAW,YAAY;AAAA,QAC9B,WAAW;AAAA,UACT,OAAO;AAAA,UACP;AAAA,UACA,SAAS;AAAA,QACX;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,cAAc,aAAa,WAAW,YAAY;AAAA,EAAA;AAGrD,QAAM,cAAc;AAAA,IAClB,CAAC,QAAgB,UAA2B;AAC1C,aAAO,UAAgD;AAAA,QACrD,OAAO,YAAY,YAAY;AAAA,QAC/B,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS;AAAA,QACX;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,cAAc,aAAa,WAAW,YAAY;AAAA,EAAA;AAGrD,QAAM,iBAAiB;AAAA,IACrB,CAAC,QAAgB,UAAiC;AAChD,aAAO,UAAmD;AAAA,QACxD,OAAO,eAAe,YAAY;AAAA,QAClC,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS;AAAA,QACX;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,cAAc,aAAa,WAAW,YAAY;AAAA,EAAA;AAGrD,QAAM,iBAAiB;AAAA,IACrB,CAAC,QAAgB,UAAoB;AACnC,aAAO,UAAmD;AAAA,QACxD,OAAO,eAAe,YAAY;AAAA,QAClC,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS;AAAA,QACX;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,cAAc,aAAa,WAAW,YAAY;AAAA,EAAA;AAGrD,QAAM,aAAa;AAAA,IACjB,CAAC,QAAgB,SAA6C;AAC5D,aAAO,UAAkD;AAAA,QACvD,OAAO,eAAe,YAAY;AAAA,QAClC,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS;AAAA,QACX;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,WAAW,cAAc,cAAc,WAAW;AAAA,EAAA;AAGrD,QAAM,sBAAsB;AAAA,IAC1B,CAAC,QAAgB,kBAA0C;AACzD,aAAO,UAA2D;AAAA,QAChE,OAAO,wBAAwB,YAAY;AAAA,QAC3C,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS;AAAA,QACX;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,cAAc,aAAa,WAAW,YAAY;AAAA,EAAA;AAGrD,QAAM,uBAAuB;AAAA,IAC3B,CAAC,QAAgB,eAAiC;AAChD,aAAO,UAAwD;AAAA,QAC7D,OAAO,qBAAqB,YAAY;AAAA,QACxC,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS;AAAA,QACX;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,cAAc,aAAa,WAAW,YAAY;AAAA,EAAA;AAGrD,QAAM,sBAAsB;AAAA,IAC1B,CACE,QACA,kBACG;AACH,aAAO,UAA2D;AAAA,QAChE,OAAO,wBAAwB,YAAY;AAAA,QAC3C,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS;AAAA,QACX;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,cAAc,aAAa,WAAW,YAAY;AAAA,EAAA;AAG9C,SAAA;AAAA,IACL,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,IAEF;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require$$0 = require("react");
|
|
4
4
|
const ShopifyProvider = require("./ShopifyProvider.js");
|
|
5
5
|
function useMoney(money) {
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
} = ShopifyProvider.useShop();
|
|
6
|
+
const { countryIsoCode, languageIsoCode } = ShopifyProvider.useShop();
|
|
7
|
+
const locale = `${languageIsoCode}-${countryIsoCode}`;
|
|
9
8
|
if (!locale) {
|
|
10
|
-
throw new Error(
|
|
9
|
+
throw new Error(
|
|
10
|
+
`useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`
|
|
11
|
+
);
|
|
11
12
|
}
|
|
12
13
|
const amount = parseFloat(money.amount);
|
|
13
|
-
const options = require$$0.useMemo(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const options = require$$0.useMemo(
|
|
15
|
+
() => ({
|
|
16
|
+
style: "currency",
|
|
17
|
+
currency: money.currencyCode
|
|
18
|
+
}),
|
|
19
|
+
[money.currencyCode]
|
|
20
|
+
);
|
|
17
21
|
const defaultFormatter = useLazyFormatter(locale, options);
|
|
18
22
|
const nameFormatter = useLazyFormatter(locale, {
|
|
19
23
|
...options,
|
|
@@ -34,38 +38,61 @@ function useMoney(money) {
|
|
|
34
38
|
maximumFractionDigits: 0
|
|
35
39
|
});
|
|
36
40
|
const isPartCurrency = (part) => part.type === "currency";
|
|
37
|
-
const lazyFormatters = require$$0.useMemo(
|
|
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
|
-
|
|
41
|
+
const lazyFormatters = require$$0.useMemo(
|
|
42
|
+
() => ({
|
|
43
|
+
original: () => money,
|
|
44
|
+
currencyCode: () => money.currencyCode,
|
|
45
|
+
localizedString: () => defaultFormatter().format(amount),
|
|
46
|
+
parts: () => defaultFormatter().formatToParts(amount),
|
|
47
|
+
withoutTrailingZeros: () => amount % 1 === 0 ? withoutTrailingZerosFormatter().format(amount) : defaultFormatter().format(amount),
|
|
48
|
+
withoutTrailingZerosAndCurrency: () => amount % 1 === 0 ? withoutTrailingZerosOrCurrencyFormatter().format(amount) : withoutCurrencyFormatter().format(amount),
|
|
49
|
+
currencyName: () => {
|
|
50
|
+
var _a;
|
|
51
|
+
return ((_a = nameFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) ?? money.currencyCode;
|
|
52
|
+
},
|
|
53
|
+
// e.g. "US dollars"
|
|
54
|
+
currencySymbol: () => {
|
|
55
|
+
var _a;
|
|
56
|
+
return ((_a = defaultFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) ?? money.currencyCode;
|
|
57
|
+
},
|
|
58
|
+
// e.g. "USD"
|
|
59
|
+
currencyNarrowSymbol: () => {
|
|
60
|
+
var _a;
|
|
61
|
+
return ((_a = narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) ?? "";
|
|
62
|
+
},
|
|
63
|
+
// e.g. "$"
|
|
64
|
+
amount: () => defaultFormatter().formatToParts(amount).filter(
|
|
65
|
+
(part) => ["decimal", "fraction", "group", "integer", "literal"].includes(
|
|
66
|
+
part.type
|
|
67
|
+
)
|
|
68
|
+
).map((part) => part.value).join("")
|
|
69
|
+
}),
|
|
70
|
+
[
|
|
71
|
+
money,
|
|
72
|
+
amount,
|
|
73
|
+
nameFormatter,
|
|
74
|
+
defaultFormatter,
|
|
75
|
+
narrowSymbolFormatter,
|
|
76
|
+
withoutCurrencyFormatter,
|
|
77
|
+
withoutTrailingZerosFormatter,
|
|
78
|
+
withoutTrailingZerosOrCurrencyFormatter
|
|
79
|
+
]
|
|
80
|
+
);
|
|
81
|
+
return require$$0.useMemo(
|
|
82
|
+
() => new Proxy(lazyFormatters, {
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
84
|
+
get: (target, key) => {
|
|
85
|
+
var _a;
|
|
86
|
+
return (_a = Reflect.get(target, key)) == null ? void 0 : _a.call(null);
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
[lazyFormatters]
|
|
90
|
+
);
|
|
64
91
|
}
|
|
65
92
|
function useLazyFormatter(locale, options) {
|
|
66
93
|
return require$$0.useMemo(() => {
|
|
67
94
|
let memoized;
|
|
68
|
-
return () => memoized
|
|
95
|
+
return () => memoized ?? (memoized = new Intl.NumberFormat(locale, options));
|
|
69
96
|
}, [locale, options]);
|
|
70
97
|
}
|
|
71
98
|
exports.useMoney = useMoney;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMoney.js","sources":["../../src/useMoney.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {CurrencyCode, MoneyV2} from './storefront-api-types.js';\n\nexport type UseMoneyValue = {\n /**\n * The currency code from the `MoneyV2` object.\n */\n currencyCode: CurrencyCode;\n /**\n * The name for the currency code, returned by `Intl.NumberFormat`.\n */\n currencyName?: string;\n /**\n * The currency symbol returned by `Intl.NumberFormat`.\n */\n currencySymbol?: string;\n /**\n * The currency narrow symbol returned by `Intl.NumberFormat`.\n */\n currencyNarrowSymbol?: string;\n /**\n * The localized amount, without any currency symbols or non-number types from the `Intl.NumberFormat.formatToParts` parts.\n */\n amount: string;\n /**\n * All parts returned by `Intl.NumberFormat.formatToParts`.\n */\n parts: Intl.NumberFormatPart[];\n /**\n * A string returned by `new Intl.NumberFormat` for the amount and currency code,\n * using the `locale` value in the [`LocalizationProvider` component](https://shopify.dev/api/hydrogen/components/localization/localizationprovider).\n */\n localizedString: string;\n /**\n * The `MoneyV2` object provided as an argument to the hook.\n */\n original: MoneyV2;\n /**\n * A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `$640`.\n * `$640.42` remains `$640.42`.\n */\n withoutTrailingZeros: string;\n /**\n * A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `640`.\n * `$640.42` turns into `640.42`.\n */\n withoutTrailingZerosAndCurrency: string;\n};\n\n/**\n * The `useMoney` hook takes a [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) and returns a\n * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by\n * [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\n * Uses `locale` from `ShopifyProvider`\n */\nexport function useMoney(money: MoneyV2): UseMoneyValue {\n const {
|
|
1
|
+
{"version":3,"file":"useMoney.js","sources":["../../src/useMoney.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {CurrencyCode, MoneyV2} from './storefront-api-types.js';\n\nexport type UseMoneyValue = {\n /**\n * The currency code from the `MoneyV2` object.\n */\n currencyCode: CurrencyCode;\n /**\n * The name for the currency code, returned by `Intl.NumberFormat`.\n */\n currencyName?: string;\n /**\n * The currency symbol returned by `Intl.NumberFormat`.\n */\n currencySymbol?: string;\n /**\n * The currency narrow symbol returned by `Intl.NumberFormat`.\n */\n currencyNarrowSymbol?: string;\n /**\n * The localized amount, without any currency symbols or non-number types from the `Intl.NumberFormat.formatToParts` parts.\n */\n amount: string;\n /**\n * All parts returned by `Intl.NumberFormat.formatToParts`.\n */\n parts: Intl.NumberFormatPart[];\n /**\n * A string returned by `new Intl.NumberFormat` for the amount and currency code,\n * using the `locale` value in the [`LocalizationProvider` component](https://shopify.dev/api/hydrogen/components/localization/localizationprovider).\n */\n localizedString: string;\n /**\n * The `MoneyV2` object provided as an argument to the hook.\n */\n original: MoneyV2;\n /**\n * A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `$640`.\n * `$640.42` remains `$640.42`.\n */\n withoutTrailingZeros: string;\n /**\n * A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `640`.\n * `$640.42` turns into `640.42`.\n */\n withoutTrailingZerosAndCurrency: string;\n};\n\n/**\n * The `useMoney` hook takes a [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) and returns a\n * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by\n * [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\n * Uses `locale` from `ShopifyProvider`\n */\nexport function useMoney(money: MoneyV2): UseMoneyValue {\n const {countryIsoCode, languageIsoCode} = useShop();\n const locale = `${languageIsoCode}-${countryIsoCode}`;\n\n if (!locale) {\n throw new Error(\n `useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`\n );\n }\n\n const amount = parseFloat(money.amount);\n\n const options = useMemo(\n () => ({\n style: 'currency',\n currency: money.currencyCode,\n }),\n [money.currencyCode]\n );\n\n const defaultFormatter = useLazyFormatter(locale, options);\n\n const nameFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'name',\n });\n\n const narrowSymbolFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'narrowSymbol',\n });\n\n const withoutTrailingZerosFormatter = useLazyFormatter(locale, {\n ...options,\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const withoutCurrencyFormatter = useLazyFormatter(locale);\n\n const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const isPartCurrency = (part: Intl.NumberFormatPart): boolean =>\n part.type === 'currency';\n\n // By wrapping these properties in functions, we only\n // create formatters if they are going to be used.\n const lazyFormatters = useMemo(\n () => ({\n original: () => money,\n currencyCode: () => money.currencyCode,\n\n localizedString: () => defaultFormatter().format(amount),\n\n parts: () => defaultFormatter().formatToParts(amount),\n\n withoutTrailingZeros: () =>\n amount % 1 === 0\n ? withoutTrailingZerosFormatter().format(amount)\n : defaultFormatter().format(amount),\n\n withoutTrailingZerosAndCurrency: () =>\n amount % 1 === 0\n ? withoutTrailingZerosOrCurrencyFormatter().format(amount)\n : withoutCurrencyFormatter().format(amount),\n\n currencyName: () =>\n nameFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"US dollars\"\n\n currencySymbol: () =>\n defaultFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"USD\"\n\n currencyNarrowSymbol: () =>\n narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)\n ?.value ?? '', // e.g. \"$\"\n\n amount: () =>\n defaultFormatter()\n .formatToParts(amount)\n .filter((part) =>\n ['decimal', 'fraction', 'group', 'integer', 'literal'].includes(\n part.type\n )\n )\n .map((part) => part.value)\n .join(''),\n }),\n [\n money,\n amount,\n nameFormatter,\n defaultFormatter,\n narrowSymbolFormatter,\n withoutCurrencyFormatter,\n withoutTrailingZerosFormatter,\n withoutTrailingZerosOrCurrencyFormatter,\n ]\n );\n\n // Call functions automatically when the properties are accessed\n // to keep these functions as an implementation detail.\n return useMemo(\n () =>\n new Proxy(lazyFormatters as unknown as UseMoneyValue, {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n get: (target, key) => Reflect.get(target, key)?.call(null),\n }),\n [lazyFormatters]\n );\n}\n\nfunction useLazyFormatter(\n locale: string,\n options?: Intl.NumberFormatOptions\n): () => Intl.NumberFormat {\n return useMemo(() => {\n let memoized: Intl.NumberFormat;\n return () => (memoized ??= new Intl.NumberFormat(locale, options));\n }, [locale, options]);\n}\n"],"names":["useShop","useMemo"],"mappings":";;;;AA0DO,SAAS,SAAS,OAA+B;AACtD,QAAM,EAAC,gBAAgB,gBAAe,IAAIA,gBAAQ,QAAA;AAC5C,QAAA,SAAS,GAAG,mBAAmB;AAErC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEM,QAAA,SAAS,WAAW,MAAM,MAAM;AAEtC,QAAM,UAAUC,WAAA;AAAA,IACd,OAAO;AAAA,MACL,OAAO;AAAA,MACP,UAAU,MAAM;AAAA,IAAA;AAAA,IAElB,CAAC,MAAM,YAAY;AAAA,EAAA;AAGf,QAAA,mBAAmB,iBAAiB,QAAQ,OAAO;AAEnD,QAAA,gBAAgB,iBAAiB,QAAQ;AAAA,IAC7C,GAAG;AAAA,IACH,iBAAiB;AAAA,EAAA,CAClB;AAEK,QAAA,wBAAwB,iBAAiB,QAAQ;AAAA,IACrD,GAAG;AAAA,IACH,iBAAiB;AAAA,EAAA,CAClB;AAEK,QAAA,gCAAgC,iBAAiB,QAAQ;AAAA,IAC7D,GAAG;AAAA,IACH,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,EAAA,CACxB;AAEK,QAAA,2BAA2B,iBAAiB,MAAM;AAElD,QAAA,0CAA0C,iBAAiB,QAAQ;AAAA,IACvE,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,EAAA,CACxB;AAED,QAAM,iBAAiB,CAAC,SACtB,KAAK,SAAS;AAIhB,QAAM,iBAAiBA,WAAA;AAAA,IACrB,OAAO;AAAA,MACL,UAAU,MAAM;AAAA,MAChB,cAAc,MAAM,MAAM;AAAA,MAE1B,iBAAiB,MAAM,mBAAmB,OAAO,MAAM;AAAA,MAEvD,OAAO,MAAM,mBAAmB,cAAc,MAAM;AAAA,MAEpD,sBAAsB,MACpB,SAAS,MAAM,IACX,8BAAA,EAAgC,OAAO,MAAM,IAC7C,mBAAmB,OAAO,MAAM;AAAA,MAEtC,iCAAiC,MAC/B,SAAS,MAAM,IACX,wCAAA,EAA0C,OAAO,MAAM,IACvD,2BAA2B,OAAO,MAAM;AAAA,MAE9C,cAAc,MACZ;;AAAA,sCAAgB,cAAc,MAAM,EAAE,KAAK,cAAc,MAAzD,mBAA4D,UAC5D,MAAM;AAAA;AAAA;AAAA,MAER,gBAAgB,MACd;;AAAA,yCAAmB,cAAc,MAAM,EAAE,KAAK,cAAc,MAA5D,mBAA+D,UAC/D,MAAM;AAAA;AAAA;AAAA,MAER,sBAAsB,MAAA;;AACpB,4CAAwB,EAAA,cAAc,MAAM,EAAE,KAAK,cAAc,MAAjE,mBACI,UAAS;AAAA;AAAA;AAAA,MAEf,QAAQ,MACN,iBAAA,EACG,cAAc,MAAM,EACpB;AAAA,QAAO,CAAC,SACP,CAAC,WAAW,YAAY,SAAS,WAAW,SAAS,EAAE;AAAA,UACrD,KAAK;AAAA,QACP;AAAA,MAAA,EAED,IAAI,CAAC,SAAS,KAAK,KAAK,EACxB,KAAK,EAAE;AAAA,IAAA;AAAA,IAEd;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAKK,SAAAA,WAAA;AAAA,IACL,MACE,IAAI,MAAM,gBAA4C;AAAA;AAAA,MAEpD,KAAK,CAAC,QAAQ;;AAAQ,6BAAQ,IAAI,QAAQ,GAAG,MAAvB,mBAA0B,KAAK;AAAA;AAAA,IAAI,CAC1D;AAAA,IACH,CAAC,cAAc;AAAA,EAAA;AAEnB;AAEA,SAAS,iBACP,QACA,SACyB;AACzB,SAAOA,mBAAQ,MAAM;AACf,QAAA;AACJ,WAAO,MAAO,wBAAa,IAAI,KAAK,aAAa,QAAQ,OAAO;AAAA,EAAA,GAC/D,CAAC,QAAQ,OAAO,CAAC;AACtB;;"}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { useShop } from "./ShopifyProvider.mjs";
|
|
3
3
|
function useMoney(money) {
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
} = useShop();
|
|
4
|
+
const { countryIsoCode, languageIsoCode } = useShop();
|
|
5
|
+
const locale = `${languageIsoCode}-${countryIsoCode}`;
|
|
7
6
|
if (!locale) {
|
|
8
|
-
throw new Error(
|
|
7
|
+
throw new Error(
|
|
8
|
+
`useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`
|
|
9
|
+
);
|
|
9
10
|
}
|
|
10
11
|
const amount = parseFloat(money.amount);
|
|
11
|
-
const options = useMemo(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const options = useMemo(
|
|
13
|
+
() => ({
|
|
14
|
+
style: "currency",
|
|
15
|
+
currency: money.currencyCode
|
|
16
|
+
}),
|
|
17
|
+
[money.currencyCode]
|
|
18
|
+
);
|
|
15
19
|
const defaultFormatter = useLazyFormatter(locale, options);
|
|
16
20
|
const nameFormatter = useLazyFormatter(locale, {
|
|
17
21
|
...options,
|
|
@@ -32,38 +36,61 @@ function useMoney(money) {
|
|
|
32
36
|
maximumFractionDigits: 0
|
|
33
37
|
});
|
|
34
38
|
const isPartCurrency = (part) => part.type === "currency";
|
|
35
|
-
const lazyFormatters = useMemo(
|
|
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
|
-
|
|
39
|
+
const lazyFormatters = useMemo(
|
|
40
|
+
() => ({
|
|
41
|
+
original: () => money,
|
|
42
|
+
currencyCode: () => money.currencyCode,
|
|
43
|
+
localizedString: () => defaultFormatter().format(amount),
|
|
44
|
+
parts: () => defaultFormatter().formatToParts(amount),
|
|
45
|
+
withoutTrailingZeros: () => amount % 1 === 0 ? withoutTrailingZerosFormatter().format(amount) : defaultFormatter().format(amount),
|
|
46
|
+
withoutTrailingZerosAndCurrency: () => amount % 1 === 0 ? withoutTrailingZerosOrCurrencyFormatter().format(amount) : withoutCurrencyFormatter().format(amount),
|
|
47
|
+
currencyName: () => {
|
|
48
|
+
var _a;
|
|
49
|
+
return ((_a = nameFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) ?? money.currencyCode;
|
|
50
|
+
},
|
|
51
|
+
// e.g. "US dollars"
|
|
52
|
+
currencySymbol: () => {
|
|
53
|
+
var _a;
|
|
54
|
+
return ((_a = defaultFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) ?? money.currencyCode;
|
|
55
|
+
},
|
|
56
|
+
// e.g. "USD"
|
|
57
|
+
currencyNarrowSymbol: () => {
|
|
58
|
+
var _a;
|
|
59
|
+
return ((_a = narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)) == null ? void 0 : _a.value) ?? "";
|
|
60
|
+
},
|
|
61
|
+
// e.g. "$"
|
|
62
|
+
amount: () => defaultFormatter().formatToParts(amount).filter(
|
|
63
|
+
(part) => ["decimal", "fraction", "group", "integer", "literal"].includes(
|
|
64
|
+
part.type
|
|
65
|
+
)
|
|
66
|
+
).map((part) => part.value).join("")
|
|
67
|
+
}),
|
|
68
|
+
[
|
|
69
|
+
money,
|
|
70
|
+
amount,
|
|
71
|
+
nameFormatter,
|
|
72
|
+
defaultFormatter,
|
|
73
|
+
narrowSymbolFormatter,
|
|
74
|
+
withoutCurrencyFormatter,
|
|
75
|
+
withoutTrailingZerosFormatter,
|
|
76
|
+
withoutTrailingZerosOrCurrencyFormatter
|
|
77
|
+
]
|
|
78
|
+
);
|
|
79
|
+
return useMemo(
|
|
80
|
+
() => new Proxy(lazyFormatters, {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
82
|
+
get: (target, key) => {
|
|
83
|
+
var _a;
|
|
84
|
+
return (_a = Reflect.get(target, key)) == null ? void 0 : _a.call(null);
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
[lazyFormatters]
|
|
88
|
+
);
|
|
62
89
|
}
|
|
63
90
|
function useLazyFormatter(locale, options) {
|
|
64
91
|
return useMemo(() => {
|
|
65
92
|
let memoized;
|
|
66
|
-
return () => memoized
|
|
93
|
+
return () => memoized ?? (memoized = new Intl.NumberFormat(locale, options));
|
|
67
94
|
}, [locale, options]);
|
|
68
95
|
}
|
|
69
96
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMoney.mjs","sources":["../../src/useMoney.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {CurrencyCode, MoneyV2} from './storefront-api-types.js';\n\nexport type UseMoneyValue = {\n /**\n * The currency code from the `MoneyV2` object.\n */\n currencyCode: CurrencyCode;\n /**\n * The name for the currency code, returned by `Intl.NumberFormat`.\n */\n currencyName?: string;\n /**\n * The currency symbol returned by `Intl.NumberFormat`.\n */\n currencySymbol?: string;\n /**\n * The currency narrow symbol returned by `Intl.NumberFormat`.\n */\n currencyNarrowSymbol?: string;\n /**\n * The localized amount, without any currency symbols or non-number types from the `Intl.NumberFormat.formatToParts` parts.\n */\n amount: string;\n /**\n * All parts returned by `Intl.NumberFormat.formatToParts`.\n */\n parts: Intl.NumberFormatPart[];\n /**\n * A string returned by `new Intl.NumberFormat` for the amount and currency code,\n * using the `locale` value in the [`LocalizationProvider` component](https://shopify.dev/api/hydrogen/components/localization/localizationprovider).\n */\n localizedString: string;\n /**\n * The `MoneyV2` object provided as an argument to the hook.\n */\n original: MoneyV2;\n /**\n * A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `$640`.\n * `$640.42` remains `$640.42`.\n */\n withoutTrailingZeros: string;\n /**\n * A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `640`.\n * `$640.42` turns into `640.42`.\n */\n withoutTrailingZerosAndCurrency: string;\n};\n\n/**\n * The `useMoney` hook takes a [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) and returns a\n * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by\n * [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\n * Uses `locale` from `ShopifyProvider`\n */\nexport function useMoney(money: MoneyV2): UseMoneyValue {\n const {
|
|
1
|
+
{"version":3,"file":"useMoney.mjs","sources":["../../src/useMoney.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {CurrencyCode, MoneyV2} from './storefront-api-types.js';\n\nexport type UseMoneyValue = {\n /**\n * The currency code from the `MoneyV2` object.\n */\n currencyCode: CurrencyCode;\n /**\n * The name for the currency code, returned by `Intl.NumberFormat`.\n */\n currencyName?: string;\n /**\n * The currency symbol returned by `Intl.NumberFormat`.\n */\n currencySymbol?: string;\n /**\n * The currency narrow symbol returned by `Intl.NumberFormat`.\n */\n currencyNarrowSymbol?: string;\n /**\n * The localized amount, without any currency symbols or non-number types from the `Intl.NumberFormat.formatToParts` parts.\n */\n amount: string;\n /**\n * All parts returned by `Intl.NumberFormat.formatToParts`.\n */\n parts: Intl.NumberFormatPart[];\n /**\n * A string returned by `new Intl.NumberFormat` for the amount and currency code,\n * using the `locale` value in the [`LocalizationProvider` component](https://shopify.dev/api/hydrogen/components/localization/localizationprovider).\n */\n localizedString: string;\n /**\n * The `MoneyV2` object provided as an argument to the hook.\n */\n original: MoneyV2;\n /**\n * A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `$640`.\n * `$640.42` remains `$640.42`.\n */\n withoutTrailingZeros: string;\n /**\n * A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `640`.\n * `$640.42` turns into `640.42`.\n */\n withoutTrailingZerosAndCurrency: string;\n};\n\n/**\n * The `useMoney` hook takes a [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) and returns a\n * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by\n * [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\n * Uses `locale` from `ShopifyProvider`\n */\nexport function useMoney(money: MoneyV2): UseMoneyValue {\n const {countryIsoCode, languageIsoCode} = useShop();\n const locale = `${languageIsoCode}-${countryIsoCode}`;\n\n if (!locale) {\n throw new Error(\n `useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`\n );\n }\n\n const amount = parseFloat(money.amount);\n\n const options = useMemo(\n () => ({\n style: 'currency',\n currency: money.currencyCode,\n }),\n [money.currencyCode]\n );\n\n const defaultFormatter = useLazyFormatter(locale, options);\n\n const nameFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'name',\n });\n\n const narrowSymbolFormatter = useLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'narrowSymbol',\n });\n\n const withoutTrailingZerosFormatter = useLazyFormatter(locale, {\n ...options,\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const withoutCurrencyFormatter = useLazyFormatter(locale);\n\n const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n });\n\n const isPartCurrency = (part: Intl.NumberFormatPart): boolean =>\n part.type === 'currency';\n\n // By wrapping these properties in functions, we only\n // create formatters if they are going to be used.\n const lazyFormatters = useMemo(\n () => ({\n original: () => money,\n currencyCode: () => money.currencyCode,\n\n localizedString: () => defaultFormatter().format(amount),\n\n parts: () => defaultFormatter().formatToParts(amount),\n\n withoutTrailingZeros: () =>\n amount % 1 === 0\n ? withoutTrailingZerosFormatter().format(amount)\n : defaultFormatter().format(amount),\n\n withoutTrailingZerosAndCurrency: () =>\n amount % 1 === 0\n ? withoutTrailingZerosOrCurrencyFormatter().format(amount)\n : withoutCurrencyFormatter().format(amount),\n\n currencyName: () =>\n nameFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"US dollars\"\n\n currencySymbol: () =>\n defaultFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"USD\"\n\n currencyNarrowSymbol: () =>\n narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)\n ?.value ?? '', // e.g. \"$\"\n\n amount: () =>\n defaultFormatter()\n .formatToParts(amount)\n .filter((part) =>\n ['decimal', 'fraction', 'group', 'integer', 'literal'].includes(\n part.type\n )\n )\n .map((part) => part.value)\n .join(''),\n }),\n [\n money,\n amount,\n nameFormatter,\n defaultFormatter,\n narrowSymbolFormatter,\n withoutCurrencyFormatter,\n withoutTrailingZerosFormatter,\n withoutTrailingZerosOrCurrencyFormatter,\n ]\n );\n\n // Call functions automatically when the properties are accessed\n // to keep these functions as an implementation detail.\n return useMemo(\n () =>\n new Proxy(lazyFormatters as unknown as UseMoneyValue, {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n get: (target, key) => Reflect.get(target, key)?.call(null),\n }),\n [lazyFormatters]\n );\n}\n\nfunction useLazyFormatter(\n locale: string,\n options?: Intl.NumberFormatOptions\n): () => Intl.NumberFormat {\n return useMemo(() => {\n let memoized: Intl.NumberFormat;\n return () => (memoized ??= new Intl.NumberFormat(locale, options));\n }, [locale, options]);\n}\n"],"names":[],"mappings":";;AA0DO,SAAS,SAAS,OAA+B;AACtD,QAAM,EAAC,gBAAgB,gBAAe,IAAI,QAAQ;AAC5C,QAAA,SAAS,GAAG,mBAAmB;AAErC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEM,QAAA,SAAS,WAAW,MAAM,MAAM;AAEtC,QAAM,UAAU;AAAA,IACd,OAAO;AAAA,MACL,OAAO;AAAA,MACP,UAAU,MAAM;AAAA,IAAA;AAAA,IAElB,CAAC,MAAM,YAAY;AAAA,EAAA;AAGf,QAAA,mBAAmB,iBAAiB,QAAQ,OAAO;AAEnD,QAAA,gBAAgB,iBAAiB,QAAQ;AAAA,IAC7C,GAAG;AAAA,IACH,iBAAiB;AAAA,EAAA,CAClB;AAEK,QAAA,wBAAwB,iBAAiB,QAAQ;AAAA,IACrD,GAAG;AAAA,IACH,iBAAiB;AAAA,EAAA,CAClB;AAEK,QAAA,gCAAgC,iBAAiB,QAAQ;AAAA,IAC7D,GAAG;AAAA,IACH,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,EAAA,CACxB;AAEK,QAAA,2BAA2B,iBAAiB,MAAM;AAElD,QAAA,0CAA0C,iBAAiB,QAAQ;AAAA,IACvE,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,EAAA,CACxB;AAED,QAAM,iBAAiB,CAAC,SACtB,KAAK,SAAS;AAIhB,QAAM,iBAAiB;AAAA,IACrB,OAAO;AAAA,MACL,UAAU,MAAM;AAAA,MAChB,cAAc,MAAM,MAAM;AAAA,MAE1B,iBAAiB,MAAM,mBAAmB,OAAO,MAAM;AAAA,MAEvD,OAAO,MAAM,mBAAmB,cAAc,MAAM;AAAA,MAEpD,sBAAsB,MACpB,SAAS,MAAM,IACX,8BAAA,EAAgC,OAAO,MAAM,IAC7C,mBAAmB,OAAO,MAAM;AAAA,MAEtC,iCAAiC,MAC/B,SAAS,MAAM,IACX,wCAAA,EAA0C,OAAO,MAAM,IACvD,2BAA2B,OAAO,MAAM;AAAA,MAE9C,cAAc,MACZ;;AAAA,sCAAgB,cAAc,MAAM,EAAE,KAAK,cAAc,MAAzD,mBAA4D,UAC5D,MAAM;AAAA;AAAA;AAAA,MAER,gBAAgB,MACd;;AAAA,yCAAmB,cAAc,MAAM,EAAE,KAAK,cAAc,MAA5D,mBAA+D,UAC/D,MAAM;AAAA;AAAA;AAAA,MAER,sBAAsB,MAAA;;AACpB,4CAAwB,EAAA,cAAc,MAAM,EAAE,KAAK,cAAc,MAAjE,mBACI,UAAS;AAAA;AAAA;AAAA,MAEf,QAAQ,MACN,iBAAA,EACG,cAAc,MAAM,EACpB;AAAA,QAAO,CAAC,SACP,CAAC,WAAW,YAAY,SAAS,WAAW,SAAS,EAAE;AAAA,UACrD,KAAK;AAAA,QACP;AAAA,MAAA,EAED,IAAI,CAAC,SAAS,KAAK,KAAK,EACxB,KAAK,EAAE;AAAA,IAAA;AAAA,IAEd;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAKK,SAAA;AAAA,IACL,MACE,IAAI,MAAM,gBAA4C;AAAA;AAAA,MAEpD,KAAK,CAAC,QAAQ;;AAAQ,6BAAQ,IAAI,QAAQ,GAAG,MAAvB,mBAA0B,KAAK;AAAA;AAAA,IAAI,CAC1D;AAAA,IACH,CAAC,cAAc;AAAA,EAAA;AAEnB;AAEA,SAAS,iBACP,QACA,SACyB;AACzB,SAAO,QAAQ,MAAM;AACf,QAAA;AACJ,WAAO,MAAO,wBAAa,IAAI,KAAK,aAAa,QAAQ,OAAO;AAAA,EAAA,GAC/D,CAAC,QAAQ,OAAO,CAAC;AACtB;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const require$$0 = require("react");
|
|
4
|
+
const cookie = require("worktop/cookie");
|
|
5
|
+
const cartConstants = require("./cart-constants.js");
|
|
6
|
+
const cookiesUtils = require("./cookies-utils.js");
|
|
7
|
+
const longTermLength = 60 * 60 * 24 * 360 * 1;
|
|
8
|
+
const shortTermLength = 60 * 30;
|
|
9
|
+
function useShopifyCookies(options) {
|
|
10
|
+
const { hasUserConsent = false, domain = "" } = options || {};
|
|
11
|
+
require$$0.useEffect(() => {
|
|
12
|
+
const cookies = cookiesUtils.getShopifyCookies(document.cookie);
|
|
13
|
+
if (hasUserConsent) {
|
|
14
|
+
setCookie(
|
|
15
|
+
cartConstants.SHOPIFY_Y,
|
|
16
|
+
cookies[cartConstants.SHOPIFY_Y] || cookiesUtils.buildUUID(),
|
|
17
|
+
longTermLength,
|
|
18
|
+
domain
|
|
19
|
+
);
|
|
20
|
+
setCookie(
|
|
21
|
+
cartConstants.SHOPIFY_S,
|
|
22
|
+
cookies[cartConstants.SHOPIFY_S] || cookiesUtils.buildUUID(),
|
|
23
|
+
shortTermLength,
|
|
24
|
+
domain
|
|
25
|
+
);
|
|
26
|
+
} else {
|
|
27
|
+
setCookie(cartConstants.SHOPIFY_Y, "", 0, domain);
|
|
28
|
+
setCookie(cartConstants.SHOPIFY_S, "", 0, domain);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function setCookie(name, value, maxage, domain) {
|
|
33
|
+
document.cookie = cookie.stringify(name, value, {
|
|
34
|
+
maxage,
|
|
35
|
+
domain,
|
|
36
|
+
samesite: "Lax",
|
|
37
|
+
path: "/"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.useShopifyCookies = useShopifyCookies;
|
|
41
|
+
//# sourceMappingURL=useShopifyCookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useShopifyCookies.js","sources":["../../src/useShopifyCookies.tsx"],"sourcesContent":["import {useEffect} from 'react';\nimport {stringify} from 'worktop/cookie';\nimport {SHOPIFY_Y, SHOPIFY_S} from './cart-constants.js';\nimport {buildUUID, getShopifyCookies} from './cookies-utils.js';\n\nconst longTermLength = 60 * 60 * 24 * 360 * 1; // ~1 year expiry\nconst shortTermLength = 60 * 30; // 30 mins\n\ntype UseShopifyCookiesOptions = {\n /**\n * If set to `false`, Shopify cookies will be removed.\n * If set to `true`, Shopify unique user token cookie will have cookie expiry of 1 year.\n * Defaults to false.\n **/\n hasUserConsent?: boolean;\n /**\n * The domain scope of the cookie. Defaults to empty string.\n **/\n domain?: string;\n};\n\nexport function useShopifyCookies(options?: UseShopifyCookiesOptions): void {\n const {hasUserConsent = false, domain = ''} = options || {};\n useEffect(() => {\n const cookies = getShopifyCookies(document.cookie);\n\n /**\n * Set user and session cookies and refresh the expiry time\n */\n if (hasUserConsent) {\n setCookie(\n SHOPIFY_Y,\n cookies[SHOPIFY_Y] || buildUUID(),\n longTermLength,\n domain\n );\n setCookie(\n SHOPIFY_S,\n cookies[SHOPIFY_S] || buildUUID(),\n shortTermLength,\n domain\n );\n } else {\n setCookie(SHOPIFY_Y, '', 0, domain);\n setCookie(SHOPIFY_S, '', 0, domain);\n }\n });\n}\n\nfunction setCookie(\n name: string,\n value: string,\n maxage: number,\n domain: string\n): void {\n document.cookie = stringify(name, value, {\n maxage,\n domain,\n samesite: 'Lax',\n path: '/',\n });\n}\n"],"names":["useEffect","getShopifyCookies","SHOPIFY_Y","buildUUID","SHOPIFY_S","stringify"],"mappings":";;;;;;AAKA,MAAM,iBAAiB,KAAK,KAAK,KAAK,MAAM;AAC5C,MAAM,kBAAkB,KAAK;AAetB,SAAS,kBAAkB,SAA0C;AAC1E,QAAM,EAAC,iBAAiB,OAAO,SAAS,GAAE,IAAI,WAAW;AACzDA,aAAAA,UAAU,MAAM;AACR,UAAA,UAAUC,aAAAA,kBAAkB,SAAS,MAAM;AAKjD,QAAI,gBAAgB;AAClB;AAAA,QACEC,cAAA;AAAA,QACA,QAAQA,cAAAA,SAAS,KAAKC,uBAAU;AAAA,QAChC;AAAA,QACA;AAAA,MAAA;AAEF;AAAA,QACEC,cAAA;AAAA,QACA,QAAQA,cAAAA,SAAS,KAAKD,uBAAU;AAAA,QAChC;AAAA,QACA;AAAA,MAAA;AAAA,IACF,OACK;AACK,gBAAAD,cAAAA,WAAW,IAAI,GAAG,MAAM;AACxB,gBAAAE,cAAAA,WAAW,IAAI,GAAG,MAAM;AAAA,IACpC;AAAA,EAAA,CACD;AACH;AAEA,SAAS,UACP,MACA,OACA,QACA,QACM;AACG,WAAA,SAASC,iBAAU,MAAM,OAAO;AAAA,IACvC;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,MAAM;AAAA,EAAA,CACP;AACH;;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { stringify } from "worktop/cookie";
|
|
3
|
+
import { SHOPIFY_Y, SHOPIFY_S } from "./cart-constants.mjs";
|
|
4
|
+
import { getShopifyCookies, buildUUID } from "./cookies-utils.mjs";
|
|
5
|
+
const longTermLength = 60 * 60 * 24 * 360 * 1;
|
|
6
|
+
const shortTermLength = 60 * 30;
|
|
7
|
+
function useShopifyCookies(options) {
|
|
8
|
+
const { hasUserConsent = false, domain = "" } = options || {};
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const cookies = getShopifyCookies(document.cookie);
|
|
11
|
+
if (hasUserConsent) {
|
|
12
|
+
setCookie(
|
|
13
|
+
SHOPIFY_Y,
|
|
14
|
+
cookies[SHOPIFY_Y] || buildUUID(),
|
|
15
|
+
longTermLength,
|
|
16
|
+
domain
|
|
17
|
+
);
|
|
18
|
+
setCookie(
|
|
19
|
+
SHOPIFY_S,
|
|
20
|
+
cookies[SHOPIFY_S] || buildUUID(),
|
|
21
|
+
shortTermLength,
|
|
22
|
+
domain
|
|
23
|
+
);
|
|
24
|
+
} else {
|
|
25
|
+
setCookie(SHOPIFY_Y, "", 0, domain);
|
|
26
|
+
setCookie(SHOPIFY_S, "", 0, domain);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function setCookie(name, value, maxage, domain) {
|
|
31
|
+
document.cookie = stringify(name, value, {
|
|
32
|
+
maxage,
|
|
33
|
+
domain,
|
|
34
|
+
samesite: "Lax",
|
|
35
|
+
path: "/"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
useShopifyCookies
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=useShopifyCookies.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useShopifyCookies.mjs","sources":["../../src/useShopifyCookies.tsx"],"sourcesContent":["import {useEffect} from 'react';\nimport {stringify} from 'worktop/cookie';\nimport {SHOPIFY_Y, SHOPIFY_S} from './cart-constants.js';\nimport {buildUUID, getShopifyCookies} from './cookies-utils.js';\n\nconst longTermLength = 60 * 60 * 24 * 360 * 1; // ~1 year expiry\nconst shortTermLength = 60 * 30; // 30 mins\n\ntype UseShopifyCookiesOptions = {\n /**\n * If set to `false`, Shopify cookies will be removed.\n * If set to `true`, Shopify unique user token cookie will have cookie expiry of 1 year.\n * Defaults to false.\n **/\n hasUserConsent?: boolean;\n /**\n * The domain scope of the cookie. Defaults to empty string.\n **/\n domain?: string;\n};\n\nexport function useShopifyCookies(options?: UseShopifyCookiesOptions): void {\n const {hasUserConsent = false, domain = ''} = options || {};\n useEffect(() => {\n const cookies = getShopifyCookies(document.cookie);\n\n /**\n * Set user and session cookies and refresh the expiry time\n */\n if (hasUserConsent) {\n setCookie(\n SHOPIFY_Y,\n cookies[SHOPIFY_Y] || buildUUID(),\n longTermLength,\n domain\n );\n setCookie(\n SHOPIFY_S,\n cookies[SHOPIFY_S] || buildUUID(),\n shortTermLength,\n domain\n );\n } else {\n setCookie(SHOPIFY_Y, '', 0, domain);\n setCookie(SHOPIFY_S, '', 0, domain);\n }\n });\n}\n\nfunction setCookie(\n name: string,\n value: string,\n maxage: number,\n domain: string\n): void {\n document.cookie = stringify(name, value, {\n maxage,\n domain,\n samesite: 'Lax',\n path: '/',\n });\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,iBAAiB,KAAK,KAAK,KAAK,MAAM;AAC5C,MAAM,kBAAkB,KAAK;AAetB,SAAS,kBAAkB,SAA0C;AAC1E,QAAM,EAAC,iBAAiB,OAAO,SAAS,GAAE,IAAI,WAAW;AACzD,YAAU,MAAM;AACR,UAAA,UAAU,kBAAkB,SAAS,MAAM;AAKjD,QAAI,gBAAgB;AAClB;AAAA,QACE;AAAA,QACA,QAAQ,SAAS,KAAK,UAAU;AAAA,QAChC;AAAA,QACA;AAAA,MAAA;AAEF;AAAA,QACE;AAAA,QACA,QAAQ,SAAS,KAAK,UAAU;AAAA,QAChC;AAAA,QACA;AAAA,MAAA;AAAA,IACF,OACK;AACK,gBAAA,WAAW,IAAI,GAAG,MAAM;AACxB,gBAAA,WAAW,IAAI,GAAG,MAAM;AAAA,IACpC;AAAA,EAAA,CACD;AACH;AAEA,SAAS,UACP,MACA,OACA,QACA,QACM;AACG,WAAA,SAAS,UAAU,MAAM,OAAO;AAAA,IACvC;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,MAAM;AAAA,EAAA,CACP;AACH;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BaseButtonProps } from './BaseButton.js';
|
|
2
|
-
|
|
1
|
+
import { type CustomBaseButtonProps, type BaseButtonProps } from './BaseButton.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export interface AddToCartButtonPropsBase {
|
|
3
4
|
/** An array of cart line attributes that belong to the item being added to the cart. */
|
|
4
5
|
attributes?: {
|
|
5
6
|
key: string;
|
|
@@ -14,8 +15,11 @@ export interface AddToCartButtonProps {
|
|
|
14
15
|
/** The selling plan ID of the subscription variant */
|
|
15
16
|
sellingPlanId?: string;
|
|
16
17
|
}
|
|
18
|
+
export type AddToCartButtonProps<AsType extends React.ElementType = 'button'> = AddToCartButtonPropsBase & BaseButtonProps<AsType>;
|
|
17
19
|
/**
|
|
18
20
|
* The `AddToCartButton` component renders a button that adds an item to the cart when pressed.
|
|
19
21
|
* It must be a descendent of the `CartProvider` component.
|
|
20
22
|
*/
|
|
21
|
-
export declare function AddToCartButton<AsType extends React.ElementType = 'button'>(props: AddToCartButtonProps
|
|
23
|
+
export declare function AddToCartButton<AsType extends React.ElementType = 'button'>(props: AddToCartButtonProps<AsType>): JSX.Element;
|
|
24
|
+
export interface AddToCartButtonPropsForDocs<AsType extends React.ElementType = 'button'> extends AddToCartButtonPropsBase, CustomBaseButtonProps<AsType> {
|
|
25
|
+
}
|
|
@@ -6,9 +6,9 @@ export interface CustomBaseButtonProps<AsType> {
|
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
/** Click event handler. Default behaviour triggers unless prevented */
|
|
8
8
|
onClick?: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | boolean;
|
|
9
|
-
/** A default onClick behavior */
|
|
9
|
+
/** A default `onClick` behavior */
|
|
10
10
|
defaultOnClick?: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | boolean;
|
|
11
|
-
/** A ref to the underlying button */
|
|
11
|
+
/** A `ref` to the underlying button */
|
|
12
12
|
buttonRef?: Ref<HTMLButtonElement>;
|
|
13
13
|
}
|
|
14
14
|
export type BaseButtonProps<AsType extends React.ElementType> = CustomBaseButtonProps<AsType> & Omit<React.ComponentPropsWithoutRef<AsType>, keyof CustomBaseButtonProps<AsType>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseButtonProps } from './BaseButton.js';
|
|
2
|
-
interface
|
|
1
|
+
import { type BaseButtonProps, type CustomBaseButtonProps } from './BaseButton.js';
|
|
2
|
+
interface BuyNowButtonPropsBase {
|
|
3
3
|
/** The item quantity. Defaults to 1. */
|
|
4
4
|
quantity?: number;
|
|
5
5
|
/** The ID of the variant. */
|
|
@@ -10,6 +10,12 @@ interface BuyNowButtonProps {
|
|
|
10
10
|
value: string;
|
|
11
11
|
}[];
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
type BuyNowButtonProps<AsType extends React.ElementType = 'button'> = BuyNowButtonPropsBase & BaseButtonProps<AsType>;
|
|
14
|
+
/**
|
|
15
|
+
* The `BuyNowButton` component renders a button that adds an item to the cart and redirects the customer to checkout.
|
|
16
|
+
* Must be a child of a `CartProvider` component.
|
|
17
|
+
*/
|
|
18
|
+
export declare function BuyNowButton<AsType extends React.ElementType = 'button'>(props: BuyNowButtonProps<AsType>): JSX.Element;
|
|
19
|
+
export interface BuyNowButtonPropsForDocs<AsType extends React.ElementType = 'button'> extends BuyNowButtonPropsBase, CustomBaseButtonProps<AsType> {
|
|
20
|
+
}
|
|
15
21
|
export {};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { BaseButtonProps } from './BaseButton.js';
|
|
3
|
-
type
|
|
2
|
+
import { type BaseButtonProps, type CustomBaseButtonProps } from './BaseButton.js';
|
|
3
|
+
type ChildrenProps = {
|
|
4
|
+
/** A `ReactNode` element. */
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
type CartCheckoutButtonProps = Omit<BaseButtonProps<'button'>, 'onClick'> & ChildrenProps;
|
|
4
8
|
/**
|
|
5
9
|
* The `CartCheckoutButton` component renders a button that redirects to the checkout URL for the cart.
|
|
6
10
|
* It must be a descendent of a `CartProvider` component.
|
|
7
11
|
*/
|
|
8
|
-
export declare function CartCheckoutButton(props:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}): JSX.Element;
|
|
12
|
+
export declare function CartCheckoutButton(props: CartCheckoutButtonProps): JSX.Element;
|
|
13
|
+
export interface CartCheckoutButtonPropsForDocs<AsType extends React.ElementType = 'button'> extends Omit<CustomBaseButtonProps<AsType>, 'onClick'> {
|
|
14
|
+
}
|
|
12
15
|
export {};
|