@shopify/hydrogen 2026.10.0-preview.4 → 2026.10.0
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/cli/index.mjs +23 -12
- package/dist/client/client.d.mts +18 -15
- package/dist/client/client.mjs +8 -3
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/errors.d.mts +35 -13
- package/dist/client/errors.mjs +23 -13
- package/dist/client/errors.mjs.map +1 -1
- package/dist/client/types.d.mts +140 -90
- package/dist/core/analytics/cart-tracker.d.mts +19 -10
- package/dist/core/analytics/cart-tracker.mjs +18 -10
- package/dist/core/analytics/cart-tracker.mjs.map +1 -1
- package/dist/core/analytics/events.d.mts +17 -11
- package/dist/core/analytics/events.mjs +13 -4
- package/dist/core/analytics/events.mjs.map +1 -1
- package/dist/core/analytics/types.d.mts +207 -118
- package/dist/core/analytics/utils/flatten-connection.d.mts +11 -9
- package/dist/core/analytics/utils/flatten-connection.mjs +7 -6
- package/dist/core/analytics/utils/flatten-connection.mjs.map +1 -1
- package/dist/core/cache/fetch-with-cache.d.mts +24 -4
- package/dist/core/cache/fetch-with-cache.mjs +17 -2
- package/dist/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/core/cache/key.d.mts +2 -0
- package/dist/core/cache/key.mjs.map +1 -1
- package/dist/core/cache/run-with-cache.d.mts +56 -8
- package/dist/core/cache/run-with-cache.mjs +17 -6
- package/dist/core/cache/run-with-cache.mjs.map +1 -1
- package/dist/core/cache/store.d.mts +8 -6
- package/dist/core/cache/store.mjs.map +1 -1
- package/dist/core/cache/strategies.d.mts +27 -2
- package/dist/core/cache/strategies.mjs +6 -0
- package/dist/core/cache/strategies.mjs.map +1 -1
- package/dist/core/cart/actions.d.mts +37 -30
- package/dist/core/cart/actions.mjs +21 -9
- package/dist/core/cart/actions.mjs.map +1 -1
- package/dist/core/cart/attach-quantity-input.d.mts +8 -7
- package/dist/core/cart/attach-quantity-input.mjs +8 -7
- package/dist/core/cart/attach-quantity-input.mjs.map +1 -1
- package/dist/core/cart/buyer-identity-sync.d.mts +7 -6
- package/dist/core/cart/buyer-identity-sync.mjs.map +1 -1
- package/dist/core/cart/cart.d.mts +59 -46
- package/dist/core/cart/cart.mjs +46 -29
- package/dist/core/cart/cart.mjs.map +1 -1
- package/dist/core/cart/cookie.d.mts +8 -4
- package/dist/core/cart/cookie.mjs +8 -4
- package/dist/core/cart/cookie.mjs.map +1 -1
- package/dist/core/cart/form.d.mts +34 -20
- package/dist/core/cart/form.mjs +6 -4
- package/dist/core/cart/form.mjs.map +1 -1
- package/dist/core/cart/get-cart.d.mts +27 -15
- package/dist/core/cart/get-cart.mjs +13 -8
- package/dist/core/cart/get-cart.mjs.map +1 -1
- package/dist/core/cart/quantity.d.mts +16 -5
- package/dist/core/cart/quantity.mjs +16 -5
- package/dist/core/cart/quantity.mjs.map +1 -1
- package/dist/core/cart/queries.d.mts +25 -19
- package/dist/core/cart/queries.mjs +15 -1
- package/dist/core/cart/queries.mjs.map +1 -1
- package/dist/core/cart/server-handlers.d.mts +82 -45
- package/dist/core/cart/server-handlers.mjs +4 -0
- package/dist/core/cart/server-handlers.mjs.map +1 -1
- package/dist/core/cart/state.d.mts +110 -64
- package/dist/core/cart/state.mjs +24 -6
- package/dist/core/cart/state.mjs.map +1 -1
- package/dist/core/collection/collection.d.mts +52 -53
- package/dist/core/collection/collection.mjs +5 -3
- package/dist/core/collection/collection.mjs.map +1 -1
- package/dist/core/collection/reconciler.d.mts +23 -16
- package/dist/core/collection/reconciler.mjs +8 -4
- package/dist/core/collection/reconciler.mjs.map +1 -1
- package/dist/core/collection/state.d.mts +31 -26
- package/dist/core/collection/state.mjs +4 -3
- package/dist/core/collection/state.mjs.map +1 -1
- package/dist/core/collection/url.d.mts +70 -29
- package/dist/core/collection/url.mjs +63 -25
- package/dist/core/collection/url.mjs.map +1 -1
- package/dist/core/constants.d.mts +1 -0
- package/dist/core/constants.mjs +1 -0
- package/dist/core/constants.mjs.map +1 -1
- package/dist/core/logging/logging.d.mts +14 -8
- package/dist/core/logging/logging.mjs +15 -10
- package/dist/core/logging/logging.mjs.map +1 -1
- package/dist/core/logging/types.d.mts +28 -11
- package/dist/core/logging/types.mjs.map +1 -1
- package/dist/core/money/format.d.mts +6 -4
- package/dist/core/money/format.mjs +19 -9
- package/dist/core/money/format.mjs.map +1 -1
- package/dist/core/money/types.d.mts +41 -25
- package/dist/core/predictive-search/form.d.mts +37 -7
- package/dist/core/predictive-search/form.mjs +21 -3
- package/dist/core/predictive-search/form.mjs.map +1 -1
- package/dist/core/predictive-search/queries.d.mts +18 -30
- package/dist/core/predictive-search/queries.mjs +7 -3
- package/dist/core/predictive-search/queries.mjs.map +1 -1
- package/dist/core/predictive-search/search.d.mts +25 -27
- package/dist/core/predictive-search/search.mjs +20 -19
- package/dist/core/predictive-search/search.mjs.map +1 -1
- package/dist/core/predictive-search/server-handlers.d.mts +25 -26
- package/dist/core/predictive-search/server-handlers.mjs +4 -0
- package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/core/predictive-search/store.d.mts +65 -24
- package/dist/core/predictive-search/store.mjs +12 -1
- package/dist/core/predictive-search/store.mjs.map +1 -1
- package/dist/core/predictive-search/url.d.mts +36 -37
- package/dist/core/predictive-search/url.mjs +14 -6
- package/dist/core/predictive-search/url.mjs.map +1 -1
- package/dist/core/product/form.d.mts +63 -16
- package/dist/core/product/form.mjs +8 -2
- package/dist/core/product/form.mjs.map +1 -1
- package/dist/core/product/options.d.mts +8 -10
- package/dist/core/product/options.mjs +8 -10
- package/dist/core/product/options.mjs.map +1 -1
- package/dist/core/product/product-form.d.mts +77 -29
- package/dist/core/product/product-form.mjs +32 -10
- package/dist/core/product/product-form.mjs.map +1 -1
- package/dist/core/product/state.d.mts +55 -32
- package/dist/core/product/url.d.mts +19 -13
- package/dist/core/product/url.mjs +10 -10
- package/dist/core/product/url.mjs.map +1 -1
- package/dist/core/request-context.d.mts +77 -19
- package/dist/core/request-context.mjs +5 -1
- package/dist/core/request-context.mjs.map +1 -1
- package/dist/core/request-routing/handle-shopify-redirects.d.mts +12 -4
- package/dist/core/request-routing/handle-shopify-redirects.mjs +9 -2
- package/dist/core/request-routing/handle-shopify-redirects.mjs.map +1 -1
- package/dist/core/request-routing/handle-shopify-routes.d.mts +5 -5
- package/dist/core/request-routing/handle-shopify-routes.mjs +7 -5
- package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/proxy.mjs +79 -43
- package/dist/core/request-routing/interceptors/proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/ucp-profile-proxy.mjs +69 -0
- package/dist/core/request-routing/interceptors/ucp-profile-proxy.mjs.map +1 -0
- package/dist/core/request-routing/interceptors/url-redirects.mjs +6 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/well-known.mjs +1 -1
- package/dist/core/request-routing/interceptors/well-known.mjs.map +1 -1
- package/dist/core/request-routing/registered-routes.d.mts +12 -0
- package/dist/core/request-routing/registered-routes.mjs +12 -0
- package/dist/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/core/request-routing/route-types.d.mts +43 -18
- package/dist/core/shop-pay/shop-pay.d.mts +71 -35
- package/dist/core/shop-pay/shop-pay.mjs +36 -10
- package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/core/shopify-scripts/index.d.mts +15 -5
- package/dist/core/shopify-scripts/index.mjs +15 -5
- package/dist/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/core/shopify-scripts/initialize.d.mts +12 -4
- package/dist/core/shopify-scripts/initialize.mjs +12 -4
- package/dist/core/shopify-scripts/initialize.mjs.map +1 -1
- package/dist/core/shopify-scripts/types.d.mts +58 -25
- package/dist/core/standard-routes/build.d.mts +11 -12
- package/dist/core/standard-routes/build.mjs +11 -12
- package/dist/core/standard-routes/build.mjs.map +1 -1
- package/dist/core/standard-routes/types.d.mts +30 -24
- package/dist/core/url.mjs +2 -1
- package/dist/core/url.mjs.map +1 -1
- package/dist/customer-account/client.d.mts +36 -69
- package/dist/customer-account/client.mjs +7 -8
- package/dist/customer-account/client.mjs.map +1 -1
- package/dist/customer-account/errors.d.mts +45 -36
- package/dist/customer-account/errors.mjs +21 -36
- package/dist/customer-account/errors.mjs.map +1 -1
- package/dist/customer-account/graphql.d.mts +11 -23
- package/dist/customer-account/graphql.mjs +3 -9
- package/dist/customer-account/graphql.mjs.map +1 -1
- package/dist/customer-account/session.d.mts +130 -100
- package/dist/customer-account/session.mjs +32 -10
- package/dist/customer-account/session.mjs.map +1 -1
- package/dist/customer-account/type-resolver.d.mts +7 -8
- package/dist/development/client/client.d.mts +18 -15
- package/dist/development/client/client.mjs +8 -3
- package/dist/development/client/client.mjs.map +1 -1
- package/dist/development/client/errors.d.mts +35 -13
- package/dist/development/client/errors.mjs +23 -13
- package/dist/development/client/errors.mjs.map +1 -1
- package/dist/development/client/types.d.mts +140 -90
- package/dist/development/core/analytics/cart-tracker.d.mts +19 -10
- package/dist/development/core/analytics/cart-tracker.mjs +18 -10
- package/dist/development/core/analytics/cart-tracker.mjs.map +1 -1
- package/dist/development/core/analytics/events.d.mts +17 -11
- package/dist/development/core/analytics/events.mjs +13 -4
- package/dist/development/core/analytics/events.mjs.map +1 -1
- package/dist/development/core/analytics/types.d.mts +207 -118
- package/dist/development/core/analytics/utils/flatten-connection.d.mts +11 -9
- package/dist/development/core/analytics/utils/flatten-connection.mjs +7 -6
- package/dist/development/core/analytics/utils/flatten-connection.mjs.map +1 -1
- package/dist/development/core/cache/fetch-with-cache.d.mts +24 -4
- package/dist/development/core/cache/fetch-with-cache.mjs +17 -2
- package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/development/core/cache/key.d.mts +2 -0
- package/dist/development/core/cache/key.mjs.map +1 -1
- package/dist/development/core/cache/run-with-cache.d.mts +56 -8
- package/dist/development/core/cache/run-with-cache.mjs +17 -6
- package/dist/development/core/cache/run-with-cache.mjs.map +1 -1
- package/dist/development/core/cache/store.d.mts +8 -6
- package/dist/development/core/cache/store.mjs.map +1 -1
- package/dist/development/core/cache/strategies.d.mts +27 -2
- package/dist/development/core/cache/strategies.mjs +6 -0
- package/dist/development/core/cache/strategies.mjs.map +1 -1
- package/dist/development/core/cart/actions.d.mts +37 -30
- package/dist/development/core/cart/actions.mjs +21 -9
- package/dist/development/core/cart/actions.mjs.map +1 -1
- package/dist/development/core/cart/attach-quantity-input.d.mts +8 -7
- package/dist/development/core/cart/attach-quantity-input.mjs +8 -7
- package/dist/development/core/cart/attach-quantity-input.mjs.map +1 -1
- package/dist/development/core/cart/buyer-identity-sync.d.mts +6 -5
- package/dist/development/core/cart/buyer-identity-sync.mjs.map +1 -1
- package/dist/development/core/cart/cart.d.mts +59 -46
- package/dist/development/core/cart/cart.mjs +46 -29
- package/dist/development/core/cart/cart.mjs.map +1 -1
- package/dist/development/core/cart/cookie.d.mts +8 -4
- package/dist/development/core/cart/cookie.mjs +8 -4
- package/dist/development/core/cart/cookie.mjs.map +1 -1
- package/dist/development/core/cart/form.d.mts +34 -20
- package/dist/development/core/cart/form.mjs +6 -4
- package/dist/development/core/cart/form.mjs.map +1 -1
- package/dist/development/core/cart/get-cart.d.mts +27 -15
- package/dist/development/core/cart/get-cart.mjs +13 -8
- package/dist/development/core/cart/get-cart.mjs.map +1 -1
- package/dist/development/core/cart/quantity.d.mts +16 -5
- package/dist/development/core/cart/quantity.mjs +16 -5
- package/dist/development/core/cart/quantity.mjs.map +1 -1
- package/dist/development/core/cart/queries.d.mts +25 -19
- package/dist/development/core/cart/queries.mjs +15 -1
- package/dist/development/core/cart/queries.mjs.map +1 -1
- package/dist/development/core/cart/server-handlers.d.mts +82 -45
- package/dist/development/core/cart/server-handlers.mjs +4 -0
- package/dist/development/core/cart/server-handlers.mjs.map +1 -1
- package/dist/development/core/cart/state.d.mts +110 -64
- package/dist/development/core/cart/state.mjs +24 -6
- package/dist/development/core/cart/state.mjs.map +1 -1
- package/dist/development/core/collection/collection.d.mts +52 -53
- package/dist/development/core/collection/collection.mjs +5 -3
- package/dist/development/core/collection/collection.mjs.map +1 -1
- package/dist/development/core/collection/reconciler.d.mts +23 -16
- package/dist/development/core/collection/reconciler.mjs +8 -4
- package/dist/development/core/collection/reconciler.mjs.map +1 -1
- package/dist/development/core/collection/state.d.mts +31 -26
- package/dist/development/core/collection/state.mjs +4 -3
- package/dist/development/core/collection/state.mjs.map +1 -1
- package/dist/development/core/collection/url.d.mts +70 -29
- package/dist/development/core/collection/url.mjs +63 -25
- package/dist/development/core/collection/url.mjs.map +1 -1
- package/dist/development/core/constants.mjs.map +1 -1
- package/dist/development/core/logging/logging.d.mts +14 -8
- package/dist/development/core/logging/logging.mjs +15 -10
- package/dist/development/core/logging/logging.mjs.map +1 -1
- package/dist/development/core/logging/types.d.mts +28 -11
- package/dist/development/core/logging/types.mjs.map +1 -1
- package/dist/development/core/money/format.d.mts +6 -4
- package/dist/development/core/money/format.mjs +19 -9
- package/dist/development/core/money/format.mjs.map +1 -1
- package/dist/development/core/money/types.d.mts +41 -25
- package/dist/development/core/predictive-search/form.d.mts +37 -7
- package/dist/development/core/predictive-search/form.mjs +21 -3
- package/dist/development/core/predictive-search/form.mjs.map +1 -1
- package/dist/development/core/predictive-search/queries.d.mts +18 -30
- package/dist/development/core/predictive-search/queries.mjs +7 -3
- package/dist/development/core/predictive-search/queries.mjs.map +1 -1
- package/dist/development/core/predictive-search/search.d.mts +25 -27
- package/dist/development/core/predictive-search/search.mjs +20 -19
- package/dist/development/core/predictive-search/search.mjs.map +1 -1
- package/dist/development/core/predictive-search/server-handlers.d.mts +25 -26
- package/dist/development/core/predictive-search/server-handlers.mjs +4 -0
- package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/development/core/predictive-search/store.d.mts +65 -24
- package/dist/development/core/predictive-search/store.mjs +12 -1
- package/dist/development/core/predictive-search/store.mjs.map +1 -1
- package/dist/development/core/predictive-search/url.d.mts +36 -37
- package/dist/development/core/predictive-search/url.mjs +14 -6
- package/dist/development/core/predictive-search/url.mjs.map +1 -1
- package/dist/development/core/product/form.d.mts +63 -16
- package/dist/development/core/product/form.mjs +8 -2
- package/dist/development/core/product/form.mjs.map +1 -1
- package/dist/development/core/product/options.d.mts +8 -10
- package/dist/development/core/product/options.mjs +8 -10
- package/dist/development/core/product/options.mjs.map +1 -1
- package/dist/development/core/product/product-form.d.mts +77 -29
- package/dist/development/core/product/product-form.mjs +32 -10
- package/dist/development/core/product/product-form.mjs.map +1 -1
- package/dist/development/core/product/state.d.mts +55 -32
- package/dist/development/core/product/url.d.mts +19 -13
- package/dist/development/core/product/url.mjs +10 -10
- package/dist/development/core/product/url.mjs.map +1 -1
- package/dist/development/core/request-context.d.mts +77 -19
- package/dist/development/core/request-context.mjs +5 -1
- package/dist/development/core/request-context.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-redirects.d.mts +12 -4
- package/dist/development/core/request-routing/handle-shopify-redirects.mjs +9 -2
- package/dist/development/core/request-routing/handle-shopify-redirects.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-routes.development.d.mts +9 -1
- package/dist/development/core/request-routing/handle-shopify-routes.development.mjs +7 -0
- package/dist/development/core/request-routing/handle-shopify-routes.development.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-routes.mjs +7 -5
- package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/proxy.mjs +79 -43
- package/dist/development/core/request-routing/interceptors/proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/ucp-profile-proxy.mjs +69 -0
- package/dist/development/core/request-routing/interceptors/ucp-profile-proxy.mjs.map +1 -0
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs +6 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/well-known.mjs +1 -1
- package/dist/development/core/request-routing/interceptors/well-known.mjs.map +1 -1
- package/dist/development/core/request-routing/registered-routes.d.mts +12 -0
- package/dist/development/core/request-routing/registered-routes.mjs +12 -0
- package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/route-types.d.mts +43 -18
- package/dist/development/core/shop-pay/shop-pay.d.mts +71 -35
- package/dist/development/core/shop-pay/shop-pay.mjs +36 -10
- package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/index.d.mts +15 -5
- package/dist/development/core/shopify-scripts/index.mjs +15 -5
- package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/initialize.d.mts +12 -4
- package/dist/development/core/shopify-scripts/initialize.mjs +12 -4
- package/dist/development/core/shopify-scripts/initialize.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/types.d.mts +58 -25
- package/dist/development/core/standard-routes/build.d.mts +11 -12
- package/dist/development/core/standard-routes/build.mjs +11 -12
- package/dist/development/core/standard-routes/build.mjs.map +1 -1
- package/dist/development/core/standard-routes/types.d.mts +30 -24
- package/dist/development/core/url.mjs +2 -1
- package/dist/development/core/url.mjs.map +1 -1
- package/dist/development/customer-account/session.d.mts +45 -54
- package/dist/development/customer-account/session.mjs +20 -4
- package/dist/development/customer-account/session.mjs.map +1 -1
- package/dist/development/globals.d.mts +20 -11
- package/dist/development/graphql/generated/storefront-api-types.d.mts +127 -1
- package/dist/development/graphql/graphql.d.mts +17 -16
- package/dist/development/graphql/graphql.mjs +7 -8
- package/dist/development/graphql/graphql.mjs.map +1 -1
- package/dist/development/graphql/type-resolver.d.mts +15 -8
- package/dist/development/react/cart.d.mts +78 -32
- package/dist/development/react/cart.mjs +56 -29
- package/dist/development/react/cart.mjs.map +1 -1
- package/dist/development/react/collection.d.mts +40 -22
- package/dist/development/react/collection.mjs +27 -7
- package/dist/development/react/collection.mjs.map +1 -1
- package/dist/development/react/predictive-search.d.mts +65 -50
- package/dist/development/react/predictive-search.mjs +23 -21
- package/dist/development/react/predictive-search.mjs.map +1 -1
- package/dist/development/react/product.d.mts +45 -16
- package/dist/development/react/product.mjs +13 -11
- package/dist/development/react/product.mjs.map +1 -1
- package/dist/development/react/shop-pay.d.mts +15 -0
- package/dist/development/react/shop-pay.mjs +9 -0
- package/dist/development/react/shop-pay.mjs.map +1 -1
- package/dist/development/react/shopify-scripts.d.mts +23 -2
- package/dist/development/react/shopify-scripts.mjs +9 -0
- package/dist/development/react/shopify-scripts.mjs.map +1 -1
- package/dist/development/vue/cart.d.mts +28 -23
- package/dist/development/vue/cart.mjs +42 -25
- package/dist/development/vue/cart.mjs.map +1 -1
- package/dist/development/vue/collection.d.mts +20 -12
- package/dist/development/vue/collection.mjs +15 -7
- package/dist/development/vue/collection.mjs.map +1 -1
- package/dist/development/vue/index.d.mts +2 -2
- package/dist/development/vue/index.mjs +2 -2
- package/dist/development/vue/predictive-search.d.mts +31 -36
- package/dist/development/vue/predictive-search.mjs +16 -22
- package/dist/development/vue/predictive-search.mjs.map +1 -1
- package/dist/development/vue/product.d.mts +16 -15
- package/dist/development/vue/product.mjs +11 -11
- package/dist/development/vue/product.mjs.map +1 -1
- package/dist/development/vue/shop-pay.d.mts +14 -17
- package/dist/development/vue/shop-pay.mjs +8 -0
- package/dist/development/vue/shop-pay.mjs.map +1 -1
- package/dist/development/vue/shopify-scripts.d.mts +11 -0
- package/dist/development/vue/shopify-scripts.mjs +6 -0
- package/dist/development/vue/shopify-scripts.mjs.map +1 -1
- package/dist/globals.d.mts +20 -11
- package/dist/graphql/generated/storefront-api-types.d.mts +127 -1
- package/dist/graphql/graphql.d.mts +17 -16
- package/dist/graphql/graphql.mjs +7 -8
- package/dist/graphql/graphql.mjs.map +1 -1
- package/dist/graphql/type-resolver.d.mts +15 -8
- package/dist/react/cart.d.mts +78 -32
- package/dist/react/cart.mjs +56 -29
- package/dist/react/cart.mjs.map +1 -1
- package/dist/react/collection.d.mts +40 -22
- package/dist/react/collection.mjs +27 -7
- package/dist/react/collection.mjs.map +1 -1
- package/dist/react/predictive-search.d.mts +65 -50
- package/dist/react/predictive-search.mjs +23 -21
- package/dist/react/predictive-search.mjs.map +1 -1
- package/dist/react/product.d.mts +45 -16
- package/dist/react/product.mjs +13 -11
- package/dist/react/product.mjs.map +1 -1
- package/dist/react/shop-pay.d.mts +15 -0
- package/dist/react/shop-pay.mjs +9 -0
- package/dist/react/shop-pay.mjs.map +1 -1
- package/dist/react/shopify-scripts.d.mts +23 -2
- package/dist/react/shopify-scripts.mjs +9 -0
- package/dist/react/shopify-scripts.mjs.map +1 -1
- package/dist/ts-plugin/index.cjs +6 -0
- package/dist/ts-plugin/index.cjs.map +1 -1
- package/dist/ts-plugin/index.d.cts +6 -0
- package/dist/vite/local-https.d.mts +51 -17
- package/dist/vite/local-https.mjs +26 -5
- package/dist/vite/local-https.mjs.map +1 -1
- package/dist/vue/cart.d.mts +28 -23
- package/dist/vue/cart.mjs +42 -25
- package/dist/vue/cart.mjs.map +1 -1
- package/dist/vue/collection.d.mts +20 -12
- package/dist/vue/collection.mjs +15 -7
- package/dist/vue/collection.mjs.map +1 -1
- package/dist/vue/index.d.mts +2 -2
- package/dist/vue/index.mjs +2 -2
- package/dist/vue/predictive-search.d.mts +31 -36
- package/dist/vue/predictive-search.mjs +16 -22
- package/dist/vue/predictive-search.mjs.map +1 -1
- package/dist/vue/product.d.mts +16 -15
- package/dist/vue/product.mjs +11 -11
- package/dist/vue/product.mjs.map +1 -1
- package/dist/vue/shop-pay.d.mts +14 -17
- package/dist/vue/shop-pay.mjs +8 -0
- package/dist/vue/shop-pay.mjs.map +1 -1
- package/dist/vue/shopify-scripts.d.mts +11 -0
- package/dist/vue/shopify-scripts.mjs +6 -0
- package/dist/vue/shopify-scripts.mjs.map +1 -1
- package/package.json +3 -1
- package/skills/hydrogen-analytics/SKILL.md +1 -1
- package/skills/hydrogen-cart-ui/SKILL.md +28 -2
- package/skills/hydrogen-collection-browser/SKILL.md +9 -1
- package/skills/hydrogen-collection-browser/references/nextjs.md +1 -1
- package/skills/hydrogen-collection-browser/references/nuxt.md +1 -1
- package/skills/hydrogen-collection-browser/references/react.md +151 -32
- package/skills/hydrogen-customer-account/SKILL.md +2 -0
- package/skills/hydrogen-request-handlers/SKILL.md +21 -11
- package/skills/hydrogen-setup/references/analytics.md +14 -8
- package/skills/hydrogen-setup/steps/1-inspect-app.md +2 -2
- package/skills/hydrogen-setup/steps/6-product-detail-page.md +21 -11
- package/skills/hydrogen-storefront-client/SKILL.md +1 -1
- package/skills/hydrogen-storefront-client/references/caching.md +2 -0
- package/skills/hydrogen-variant-form/SKILL.md +25 -7
- package/skills/hydrogen-variant-form/references/nextjs.md +39 -4
- package/skills/hydrogen-variant-form/references/nuxt.md +83 -42
- package/skills/hydrogen-variant-form/references/react.md +45 -9
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createCartComponents,
|
|
1
|
+
import { createCartComponents, useCartAnalytics } from "./cart.mjs";
|
|
2
2
|
import { CollectionProvider, useCollection, useCollectionActions, useCollectionForm } from "./collection.mjs";
|
|
3
3
|
import { PredictiveSearchProvider, usePredictiveSearch, usePredictiveSearchActions, usePredictiveSearchForm } from "./predictive-search.mjs";
|
|
4
4
|
import { createProductComponents, useProductForm } from "./product.mjs";
|
|
5
5
|
import { ShopPayButton } from "./shop-pay.mjs";
|
|
6
6
|
import { ShopifyScripts } from "./shopify-scripts.mjs";
|
|
7
7
|
|
|
8
|
-
export { CollectionProvider, PredictiveSearchProvider, ShopPayButton, ShopifyScripts, createCartComponents, createProductComponents,
|
|
8
|
+
export { CollectionProvider, PredictiveSearchProvider, ShopPayButton, ShopifyScripts, createCartComponents, createProductComponents, useCartAnalytics, useCollection, useCollectionActions, useCollectionForm, usePredictiveSearch, usePredictiveSearchActions, usePredictiveSearchForm, useProductForm };
|
|
@@ -5,28 +5,35 @@ import * as _$vue from "vue";
|
|
|
5
5
|
import { PropType, ShallowRef } from "vue";
|
|
6
6
|
|
|
7
7
|
//#region src/vue/predictive-search.d.ts
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Options for the form props function of the predictive search form composable.
|
|
10
|
+
*
|
|
11
|
+
* Accepts any form attribute. Attributes that you pass override the default action, method, and role.
|
|
12
|
+
*/
|
|
9
13
|
type PredictiveSearchFormPropsOptions = {
|
|
10
|
-
/**
|
|
14
|
+
/** Set to `true` to cancel the native submission and run a client-side search with the submitted term. */preventDefault?: boolean; /** Runs on submit with the submit event and the search term. Calling preventDefault on the event cancels the native submission and the client-side search. */
|
|
11
15
|
onSubmit?: (event: SubmitEvent, term: string) => void;
|
|
12
16
|
[key: string]: unknown;
|
|
13
17
|
};
|
|
14
|
-
/** Options for the query input
|
|
18
|
+
/** Options for the query input attributes that the register function returns. */
|
|
15
19
|
type PredictiveSearchQueryInputPropsOptions = {
|
|
16
|
-
/**
|
|
20
|
+
/** Runs on input with the input event and the input value. Calling preventDefault on the event skips the automatic search. */onInput?: (event: Event, term: string) => void;
|
|
17
21
|
[key: string]: unknown;
|
|
18
22
|
};
|
|
19
|
-
/**
|
|
23
|
+
/** Functions that build a predictive search form that works without JavaScript. */
|
|
20
24
|
type PredictiveSearchFormResult = {
|
|
21
|
-
/**
|
|
25
|
+
/** Returns the form attributes, including the search action and a submit handler. */formProps(options?: PredictiveSearchFormPropsOptions): Record<string, unknown>; /** Returns the query input attributes, including an input handler that searches on every input event. The function accepts only the `query` field and throws for any other field name. */
|
|
22
26
|
register: (field: "query", options?: PredictiveSearchQueryInputPropsOptions) => Record<string, unknown>;
|
|
23
27
|
};
|
|
24
28
|
/**
|
|
25
|
-
* Creates and
|
|
26
|
-
*
|
|
29
|
+
* Creates a predictive search store and shares the store with the predictive search composables in the default slot.
|
|
30
|
+
*
|
|
31
|
+
* The provider connects the store on mount and destroys the store on unmount. A change to a store option prop replaces the store with a new one. The provider compares the types and searchable fields arrays by their values.
|
|
27
32
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
33
|
+
* The provider throws when neither the fetch prop nor a global fetch function exists.
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} When neither the fetch prop nor a global fetch function exists.
|
|
36
|
+
* @publicDocs
|
|
30
37
|
*/
|
|
31
38
|
declare const PredictiveSearchProvider: _$vue.DefineComponent<_$vue.ExtractPropTypes<{
|
|
32
39
|
predictiveSearchEndpoint: {
|
|
@@ -125,45 +132,33 @@ declare const PredictiveSearchProvider: _$vue.DefineComponent<_$vue.ExtractPropT
|
|
|
125
132
|
unavailableProducts: SearchUnavailableProductsType;
|
|
126
133
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
127
134
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* Without arguments, returns a `ShallowRef` of the full
|
|
131
|
-
* {@link PredictiveSearchState}. With a `selector`, returns a ref of the
|
|
132
|
-
* derived value that only updates when the selected value changes
|
|
133
|
-
* (reference equality by default, or a custom `isEqual`).
|
|
135
|
+
* Returns the predictive search state as a read-only shallow ref that updates when the state changes.
|
|
134
136
|
*
|
|
135
|
-
*
|
|
137
|
+
* With a selector, the ref holds the selected value and updates only when that value changes.
|
|
138
|
+
* The composable compares values by reference unless you pass an equality function.
|
|
136
139
|
*
|
|
137
|
-
* @throws {Error} When
|
|
140
|
+
* @throws {Error} When you call it outside a PredictiveSearchProvider.
|
|
141
|
+
* @publicDocs
|
|
138
142
|
*/
|
|
139
143
|
declare function usePredictiveSearch<TData extends PredictiveSearchData = PredictiveSearchData>(): Readonly<ShallowRef<PredictiveSearchState<TData>>>;
|
|
140
144
|
declare function usePredictiveSearch<TData extends PredictiveSearchData = PredictiveSearchData, S = PredictiveSearchState<TData>>(selector: (state: PredictiveSearchState<TData>) => S, isEqual?: (a: S, b: S) => boolean): Readonly<ShallowRef<S>>;
|
|
141
145
|
/**
|
|
142
|
-
* Returns
|
|
146
|
+
* Returns methods that search and clear results in the provider's current store.
|
|
143
147
|
*
|
|
144
|
-
*
|
|
145
|
-
* so they always target the active store even after a provider prop change
|
|
146
|
-
* triggers store recreation.
|
|
148
|
+
* After a store option prop change replaces the store, the methods act on the new store.
|
|
147
149
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* @throws {Error} When called outside a PredictiveSearchProvider.
|
|
150
|
+
* @throws {Error} When you call it outside a PredictiveSearchProvider.
|
|
151
|
+
* @publicDocs
|
|
151
152
|
*/
|
|
152
153
|
declare function usePredictiveSearchActions(): PredictiveSearchActions;
|
|
153
154
|
/**
|
|
154
|
-
* Returns
|
|
155
|
-
* search form.
|
|
156
|
-
*
|
|
157
|
-
* `formProps()` generates form element attributes including the search
|
|
158
|
-
* action URL. `register("query")` generates input attributes and calls the
|
|
159
|
-
* store's search action on every `input` event. The store debounces requests
|
|
160
|
-
* and resets state for terms shorter than `minTermLength`.
|
|
161
|
-
* Both support an optional callback that receives the event and extracted
|
|
162
|
-
* term, and respect `event.preventDefault()` to cancel the automatic behavior.
|
|
155
|
+
* Returns functions that build a predictive search form that works without JavaScript.
|
|
163
156
|
*
|
|
164
|
-
*
|
|
157
|
+
* The form props function returns the form attributes. The register function returns the query input attributes and searches on every input event.
|
|
158
|
+
* Both functions accept a callback that receives the event and the search term. Calling preventDefault on the event cancels the automatic behavior.
|
|
165
159
|
*
|
|
166
|
-
* @throws {Error} When
|
|
160
|
+
* @throws {Error} When you call it outside a PredictiveSearchProvider.
|
|
161
|
+
* @publicDocs
|
|
167
162
|
*/
|
|
168
163
|
declare function usePredictiveSearchForm(): PredictiveSearchFormResult;
|
|
169
164
|
//#endregion
|
|
@@ -6,11 +6,14 @@ import { defineComponent, inject, onMounted, onUnmounted, provide, shallowRef, w
|
|
|
6
6
|
const CONFIG_ARRAY_SEPARATOR = "\0";
|
|
7
7
|
const PredictiveSearchKey = Symbol("PredictiveSearch");
|
|
8
8
|
/**
|
|
9
|
-
* Creates and
|
|
10
|
-
* composables via Vue's provide/inject.
|
|
9
|
+
* Creates a predictive search store and shares the store with the predictive search composables in the default slot.
|
|
11
10
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* The provider connects the store on mount and destroys the store on unmount. A change to a store option prop replaces the store with a new one. The provider compares the types and searchable fields arrays by their values.
|
|
12
|
+
*
|
|
13
|
+
* The provider throws when neither the fetch prop nor a global fetch function exists.
|
|
14
|
+
*
|
|
15
|
+
* @throws {Error} When neither the fetch prop nor a global fetch function exists.
|
|
16
|
+
* @publicDocs
|
|
14
17
|
*/
|
|
15
18
|
const PredictiveSearchProvider = defineComponent({
|
|
16
19
|
name: "PredictiveSearchProvider",
|
|
@@ -129,15 +132,12 @@ function usePredictiveSearch(selector, isEqual) {
|
|
|
129
132
|
return selected;
|
|
130
133
|
}
|
|
131
134
|
/**
|
|
132
|
-
* Returns
|
|
135
|
+
* Returns methods that search and clear results in the provider's current store.
|
|
133
136
|
*
|
|
134
|
-
*
|
|
135
|
-
* so they always target the active store even after a provider prop change
|
|
136
|
-
* triggers store recreation.
|
|
137
|
+
* After a store option prop change replaces the store, the methods act on the new store.
|
|
137
138
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* @throws {Error} When called outside a PredictiveSearchProvider.
|
|
139
|
+
* @throws {Error} When you call it outside a PredictiveSearchProvider.
|
|
140
|
+
* @publicDocs
|
|
141
141
|
*/
|
|
142
142
|
function usePredictiveSearchActions() {
|
|
143
143
|
const { storeRef } = useRequiredContext("usePredictiveSearchActions");
|
|
@@ -147,19 +147,13 @@ function usePredictiveSearchActions() {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
|
-
* Returns
|
|
151
|
-
* search form.
|
|
152
|
-
*
|
|
153
|
-
* `formProps()` generates form element attributes including the search
|
|
154
|
-
* action URL. `register("query")` generates input attributes and calls the
|
|
155
|
-
* store's search action on every `input` event. The store debounces requests
|
|
156
|
-
* and resets state for terms shorter than `minTermLength`.
|
|
157
|
-
* Both support an optional callback that receives the event and extracted
|
|
158
|
-
* term, and respect `event.preventDefault()` to cancel the automatic behavior.
|
|
150
|
+
* Returns functions that build a predictive search form that works without JavaScript.
|
|
159
151
|
*
|
|
160
|
-
*
|
|
152
|
+
* The form props function returns the form attributes. The register function returns the query input attributes and searches on every input event.
|
|
153
|
+
* Both functions accept a callback that receives the event and the search term. Calling preventDefault on the event cancels the automatic behavior.
|
|
161
154
|
*
|
|
162
|
-
* @throws {Error} When
|
|
155
|
+
* @throws {Error} When you call it outside a PredictiveSearchProvider.
|
|
156
|
+
* @publicDocs
|
|
163
157
|
*/
|
|
164
158
|
function usePredictiveSearchForm() {
|
|
165
159
|
const { storeRef, searchActionRef } = useRequiredContext("usePredictiveSearchForm");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predictive-search.mjs","names":[],"sources":["../../../src/vue/predictive-search.ts"],"sourcesContent":["import {\n defineComponent,\n inject,\n onMounted,\n onUnmounted,\n provide,\n shallowRef,\n watch,\n type InjectionKey,\n type PropType,\n type ShallowRef,\n} from \"vue\";\n\nimport {\n createPredictiveSearchFormRegister,\n createPredictiveSearchStore,\n getPredictiveSearchFormAttributes,\n readPredictiveSearchFormTerm,\n type CreatePredictiveSearchStoreOptions,\n type PredictiveSearchActions,\n type PredictiveSearchData,\n type PredictiveSearchState,\n type PredictiveSearchStore,\n} from \"../core/predictive-search\";\nimport type {\n PredictiveSearchLimitScope,\n PredictiveSearchType,\n SearchableField,\n SearchUnavailableProductsType,\n} from \"../graphql/generated/storefront-api-types\";\n\nconst CONFIG_ARRAY_SEPARATOR = \"\\0\";\n\ntype PredictiveSearchContextValue = {\n storeRef: ShallowRef<PredictiveSearchStore>;\n searchActionRef: ShallowRef<string | undefined>;\n};\n\nconst PredictiveSearchKey: InjectionKey<PredictiveSearchContextValue> = Symbol(\"PredictiveSearch\");\n\nexport type { PredictiveSearchActions };\n\n/** Options for the form props builder returned by {@link usePredictiveSearchForm}. */\nexport type PredictiveSearchFormPropsOptions = {\n /** When `true`, prevents the native form submission and triggers a client-side search instead. */\n preventDefault?: boolean;\n /** Called on submit with the submit event and the extracted search term. Calling `event.preventDefault()` cancels both the native submission and Hydrogen's client-side search. */\n onSubmit?: (event: SubmitEvent, term: string) => void;\n [key: string]: unknown;\n};\n\n/** Options for the query input props builder returned by {@link usePredictiveSearchForm}'s `register` method. */\nexport type PredictiveSearchQueryInputPropsOptions = {\n /** Called on input with the input event and the current input value. Call `event.preventDefault()` to skip the automatic search trigger. */\n onInput?: (event: Event, term: string) => void;\n [key: string]: unknown;\n};\n\n/** Return type of {@link usePredictiveSearchForm}, providing methods to build a progressively-enhanced search form. */\nexport type PredictiveSearchFormResult = {\n /** Generates form element attributes including the search action and submit handler. */\n formProps(options?: PredictiveSearchFormPropsOptions): Record<string, unknown>;\n /** Generates input element attributes for a named form field and wires up the search trigger. */\n register: (\n field: \"query\",\n options?: PredictiveSearchQueryInputPropsOptions,\n ) => Record<string, unknown>;\n};\n\n/**\n * Creates and manages a predictive search store, providing it to descendant\n * composables via Vue's provide/inject.\n *\n * Recreates the store when configuration props change. Connects the store\n * on mount and destroys it on unmount.\n */\nexport const PredictiveSearchProvider = defineComponent({\n name: \"PredictiveSearchProvider\",\n props: {\n predictiveSearchEndpoint: { type: String, default: undefined },\n searchAction: { type: String, default: undefined },\n debounceInMs: { type: Number, default: undefined },\n minTermLength: { type: Number, default: undefined },\n fetch: { type: Function as PropType<typeof globalThis.fetch>, default: undefined },\n limit: { type: Number, default: undefined },\n limitScope: { type: String as PropType<PredictiveSearchLimitScope>, default: undefined },\n types: { type: Array as PropType<PredictiveSearchType[]>, default: undefined },\n searchableFields: { type: Array as PropType<SearchableField[]>, default: undefined },\n unavailableProducts: {\n type: String as PropType<SearchUnavailableProductsType>,\n default: undefined,\n },\n },\n setup(props, { slots }) {\n function buildStoreOptions(): CreatePredictiveSearchStoreOptions {\n return {\n predictiveSearchEndpoint: props.predictiveSearchEndpoint,\n debounceInMs: props.debounceInMs,\n minTermLength: props.minTermLength,\n fetch: props.fetch as typeof globalThis.fetch | undefined,\n limit: props.limit,\n limitScope: props.limitScope,\n types: props.types,\n searchableFields: props.searchableFields,\n unavailableProducts: props.unavailableProducts,\n };\n }\n\n const storeRef = shallowRef<PredictiveSearchStore>(\n createPredictiveSearchStore(buildStoreOptions()),\n );\n const searchActionRef = shallowRef(props.searchAction);\n\n provide(PredictiveSearchKey, { storeRef, searchActionRef });\n\n watch(\n () => props.searchAction,\n (next) => {\n searchActionRef.value = next;\n },\n );\n\n watch(\n () => [\n props.predictiveSearchEndpoint,\n props.debounceInMs,\n props.minTermLength,\n props.fetch,\n props.limit,\n props.limitScope,\n getArrayKey(props.types),\n getArrayKey(props.searchableFields),\n props.unavailableProducts,\n ],\n () => {\n storeRef.value.destroy();\n storeRef.value = createPredictiveSearchStore(buildStoreOptions());\n storeRef.value.connect();\n },\n );\n\n onMounted(() => {\n storeRef.value.connect();\n });\n\n onUnmounted(() => {\n storeRef.value.destroy();\n });\n\n return () => slots.default?.();\n },\n});\n\nfunction getArrayKey(values: readonly string[] | undefined): string {\n return values?.join(CONFIG_ARRAY_SEPARATOR) ?? \"\";\n}\n\nfunction useRequiredContext(composableName: string): PredictiveSearchContextValue {\n const context = inject(PredictiveSearchKey, null);\n if (!context) {\n throw new Error(`${composableName} must be used inside a <PredictiveSearchProvider>.`);\n }\n return context;\n}\n\n/**\n * Subscribes to the predictive search store's state as a reactive ref.\n *\n * Without arguments, returns a `ShallowRef` of the full\n * {@link PredictiveSearchState}. With a `selector`, returns a ref of the\n * derived value that only updates when the selected value changes\n * (reference equality by default, or a custom `isEqual`).\n *\n * Must be used inside a {@link PredictiveSearchProvider}.\n *\n * @throws {Error} When called outside a PredictiveSearchProvider.\n */\nexport function usePredictiveSearch<\n TData extends PredictiveSearchData = PredictiveSearchData,\n>(): Readonly<ShallowRef<PredictiveSearchState<TData>>>;\nexport function usePredictiveSearch<\n TData extends PredictiveSearchData = PredictiveSearchData,\n S = PredictiveSearchState<TData>,\n>(\n selector: (state: PredictiveSearchState<TData>) => S,\n isEqual?: (a: S, b: S) => boolean,\n): Readonly<ShallowRef<S>>;\nexport function usePredictiveSearch<\n TData extends PredictiveSearchData = PredictiveSearchData,\n S = PredictiveSearchState<TData>,\n>(\n selector?: (state: PredictiveSearchState<TData>) => S,\n isEqual?: (a: S, b: S) => boolean,\n): Readonly<ShallowRef<PredictiveSearchState<TData> | S>> {\n const { storeRef } = useRequiredContext(\"usePredictiveSearch\");\n const resolve = selector ?? ((state: PredictiveSearchState<TData>) => state as unknown as S);\n const selected = shallowRef<PredictiveSearchState<TData> | S>(\n resolve((storeRef.value as PredictiveSearchStore<TData>).getState()),\n );\n\n watch(\n () => storeRef.value,\n (store, _, onCleanup) => {\n const typedStore = store as PredictiveSearchStore<TData>;\n selected.value = resolve(typedStore.getState());\n\n const unsubscribe = typedStore.subscribe(() => {\n const next = resolve(typedStore.getState());\n if (isEqual && selector) {\n if (isEqual(selected.value as S, next)) return;\n }\n selected.value = next;\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n );\n\n return selected as Readonly<ShallowRef<PredictiveSearchState<TData> | S>>;\n}\n\n/**\n * Returns `search` and `clear` methods that delegate to the current store.\n *\n * These are thin wrappers that read from the reactive store ref on each call,\n * so they always target the active store even after a provider prop change\n * triggers store recreation.\n *\n * Must be used inside a {@link PredictiveSearchProvider}.\n *\n * @throws {Error} When called outside a PredictiveSearchProvider.\n */\nexport function usePredictiveSearchActions(): PredictiveSearchActions {\n const { storeRef } = useRequiredContext(\"usePredictiveSearchActions\");\n\n return {\n search: (term) => storeRef.value.search(term),\n clear: () => storeRef.value.clear(),\n };\n}\n\n/**\n * Returns `formProps` and `register` for building a progressively-enhanced\n * search form.\n *\n * `formProps()` generates form element attributes including the search\n * action URL. `register(\"query\")` generates input attributes and calls the\n * store's search action on every `input` event. The store debounces requests\n * and resets state for terms shorter than `minTermLength`.\n * Both support an optional callback that receives the event and extracted\n * term, and respect `event.preventDefault()` to cancel the automatic behavior.\n *\n * Must be used inside a {@link PredictiveSearchProvider}.\n *\n * @throws {Error} When called outside a PredictiveSearchProvider.\n */\nexport function usePredictiveSearchForm(): PredictiveSearchFormResult {\n const { storeRef, searchActionRef } = useRequiredContext(\"usePredictiveSearchForm\");\n const coreRegister = createPredictiveSearchFormRegister();\n\n function register(\n field: \"query\",\n options: PredictiveSearchQueryInputPropsOptions = {},\n ): Record<string, unknown> {\n const { onInput, ...attributes } = options;\n const coreAttributes = coreRegister(field);\n\n return {\n ...attributes,\n ...coreAttributes,\n onInput: (event: Event) => {\n const term = (event.target as HTMLInputElement).value;\n onInput?.(event, term);\n if (event.defaultPrevented) return;\n void storeRef.value.search(term);\n },\n };\n }\n\n function formProps(options: PredictiveSearchFormPropsOptions = {}): Record<string, unknown> {\n const { onSubmit, preventDefault, ...attributes } = options;\n\n return {\n ...getPredictiveSearchFormAttributes(searchActionRef.value),\n ...attributes,\n onSubmit: (event: SubmitEvent) => {\n const term = readPredictiveSearchFormTerm(\n new FormData(event.currentTarget as HTMLFormElement),\n );\n onSubmit?.(event, term);\n if (event.defaultPrevented) return;\n if (!preventDefault) return;\n event.preventDefault();\n void storeRef.value.search(term);\n },\n };\n }\n\n return { formProps, register };\n}\n"],"mappings":";;;;;AA+BA,MAAM,yBAAyB;AAO/B,MAAM,sBAAkE,OAAO,mBAAmB;;;;;;;;AAsClG,MAAa,2BAA2B,gBAAgB;CACtD,MAAM;CACN,OAAO;EACL,0BAA0B;GAAE,MAAM;GAAQ,SAAS;GAAW;EAC9D,cAAc;GAAE,MAAM;GAAQ,SAAS;GAAW;EAClD,cAAc;GAAE,MAAM;GAAQ,SAAS;GAAW;EAClD,eAAe;GAAE,MAAM;GAAQ,SAAS;GAAW;EACnD,OAAO;GAAE,MAAM;GAA+C,SAAS;GAAW;EAClF,OAAO;GAAE,MAAM;GAAQ,SAAS;GAAW;EAC3C,YAAY;GAAE,MAAM;GAAgD,SAAS;GAAW;EACxF,OAAO;GAAE,MAAM;GAA2C,SAAS;GAAW;EAC9E,kBAAkB;GAAE,MAAM;GAAsC,SAAS;GAAW;EACpF,qBAAqB;GAC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AO;EAAE;EAAW;EAAU"}
|
|
1
|
+
{"version":3,"file":"predictive-search.mjs","names":[],"sources":["../../../src/vue/predictive-search.ts"],"sourcesContent":["import {\n defineComponent,\n inject,\n onMounted,\n onUnmounted,\n provide,\n shallowRef,\n watch,\n type InjectionKey,\n type PropType,\n type ShallowRef,\n} from \"vue\";\n\nimport {\n createPredictiveSearchFormRegister,\n createPredictiveSearchStore,\n getPredictiveSearchFormAttributes,\n readPredictiveSearchFormTerm,\n type CreatePredictiveSearchStoreOptions,\n type PredictiveSearchActions,\n type PredictiveSearchData,\n type PredictiveSearchState,\n type PredictiveSearchStore,\n} from \"../core/predictive-search\";\nimport type {\n PredictiveSearchLimitScope,\n PredictiveSearchType,\n SearchableField,\n SearchUnavailableProductsType,\n} from \"../graphql/generated/storefront-api-types\";\n\nconst CONFIG_ARRAY_SEPARATOR = \"\\0\";\n\ntype PredictiveSearchContextValue = {\n storeRef: ShallowRef<PredictiveSearchStore>;\n searchActionRef: ShallowRef<string | undefined>;\n};\n\nconst PredictiveSearchKey: InjectionKey<PredictiveSearchContextValue> = Symbol(\"PredictiveSearch\");\n\nexport type { PredictiveSearchActions };\n\n/**\n * Options for the form props function of the predictive search form composable.\n *\n * Accepts any form attribute. Attributes that you pass override the default action, method, and role.\n */\nexport type PredictiveSearchFormPropsOptions = {\n /** Set to `true` to cancel the native submission and run a client-side search with the submitted term. */\n preventDefault?: boolean;\n /** Runs on submit with the submit event and the search term. Calling preventDefault on the event cancels the native submission and the client-side search. */\n onSubmit?: (event: SubmitEvent, term: string) => void;\n [key: string]: unknown;\n};\n\n/** Options for the query input attributes that the register function returns. */\nexport type PredictiveSearchQueryInputPropsOptions = {\n /** Runs on input with the input event and the input value. Calling preventDefault on the event skips the automatic search. */\n onInput?: (event: Event, term: string) => void;\n [key: string]: unknown;\n};\n\n/** Functions that build a predictive search form that works without JavaScript. */\nexport type PredictiveSearchFormResult = {\n /** Returns the form attributes, including the search action and a submit handler. */\n formProps(options?: PredictiveSearchFormPropsOptions): Record<string, unknown>;\n /** Returns the query input attributes, including an input handler that searches on every input event. The function accepts only the `query` field and throws for any other field name. */\n register: (\n field: \"query\",\n options?: PredictiveSearchQueryInputPropsOptions,\n ) => Record<string, unknown>;\n};\n\n/**\n * Creates a predictive search store and shares the store with the predictive search composables in the default slot.\n *\n * The provider connects the store on mount and destroys the store on unmount. A change to a store option prop replaces the store with a new one. The provider compares the types and searchable fields arrays by their values.\n *\n * The provider throws when neither the fetch prop nor a global fetch function exists.\n *\n * @throws {Error} When neither the fetch prop nor a global fetch function exists.\n * @publicDocs\n */\nexport const PredictiveSearchProvider = defineComponent({\n name: \"PredictiveSearchProvider\",\n props: {\n predictiveSearchEndpoint: { type: String, default: undefined },\n searchAction: { type: String, default: undefined },\n debounceInMs: { type: Number, default: undefined },\n minTermLength: { type: Number, default: undefined },\n fetch: { type: Function as PropType<typeof globalThis.fetch>, default: undefined },\n limit: { type: Number, default: undefined },\n limitScope: { type: String as PropType<PredictiveSearchLimitScope>, default: undefined },\n types: { type: Array as PropType<PredictiveSearchType[]>, default: undefined },\n searchableFields: { type: Array as PropType<SearchableField[]>, default: undefined },\n unavailableProducts: {\n type: String as PropType<SearchUnavailableProductsType>,\n default: undefined,\n },\n },\n setup(props, { slots }) {\n function buildStoreOptions(): CreatePredictiveSearchStoreOptions {\n return {\n predictiveSearchEndpoint: props.predictiveSearchEndpoint,\n debounceInMs: props.debounceInMs,\n minTermLength: props.minTermLength,\n fetch: props.fetch as typeof globalThis.fetch | undefined,\n limit: props.limit,\n limitScope: props.limitScope,\n types: props.types,\n searchableFields: props.searchableFields,\n unavailableProducts: props.unavailableProducts,\n };\n }\n\n const storeRef = shallowRef<PredictiveSearchStore>(\n createPredictiveSearchStore(buildStoreOptions()),\n );\n const searchActionRef = shallowRef(props.searchAction);\n\n provide(PredictiveSearchKey, { storeRef, searchActionRef });\n\n watch(\n () => props.searchAction,\n (next) => {\n searchActionRef.value = next;\n },\n );\n\n watch(\n () => [\n props.predictiveSearchEndpoint,\n props.debounceInMs,\n props.minTermLength,\n props.fetch,\n props.limit,\n props.limitScope,\n getArrayKey(props.types),\n getArrayKey(props.searchableFields),\n props.unavailableProducts,\n ],\n () => {\n storeRef.value.destroy();\n storeRef.value = createPredictiveSearchStore(buildStoreOptions());\n storeRef.value.connect();\n },\n );\n\n onMounted(() => {\n storeRef.value.connect();\n });\n\n onUnmounted(() => {\n storeRef.value.destroy();\n });\n\n return () => slots.default?.();\n },\n});\n\nfunction getArrayKey(values: readonly string[] | undefined): string {\n return values?.join(CONFIG_ARRAY_SEPARATOR) ?? \"\";\n}\n\nfunction useRequiredContext(composableName: string): PredictiveSearchContextValue {\n const context = inject(PredictiveSearchKey, null);\n if (!context) {\n throw new Error(`${composableName} must be used inside a <PredictiveSearchProvider>.`);\n }\n return context;\n}\n\n/**\n * Returns the predictive search state as a read-only shallow ref that updates when the state changes.\n *\n * With a selector, the ref holds the selected value and updates only when that value changes.\n * The composable compares values by reference unless you pass an equality function.\n *\n * @throws {Error} When you call it outside a PredictiveSearchProvider.\n * @publicDocs\n */\nexport function usePredictiveSearch<\n TData extends PredictiveSearchData = PredictiveSearchData,\n>(): Readonly<ShallowRef<PredictiveSearchState<TData>>>;\nexport function usePredictiveSearch<\n TData extends PredictiveSearchData = PredictiveSearchData,\n S = PredictiveSearchState<TData>,\n>(\n selector: (state: PredictiveSearchState<TData>) => S,\n isEqual?: (a: S, b: S) => boolean,\n): Readonly<ShallowRef<S>>;\nexport function usePredictiveSearch<\n TData extends PredictiveSearchData = PredictiveSearchData,\n S = PredictiveSearchState<TData>,\n>(\n selector?: (state: PredictiveSearchState<TData>) => S,\n isEqual?: (a: S, b: S) => boolean,\n): Readonly<ShallowRef<PredictiveSearchState<TData> | S>> {\n const { storeRef } = useRequiredContext(\"usePredictiveSearch\");\n const resolve = selector ?? ((state: PredictiveSearchState<TData>) => state as unknown as S);\n const selected = shallowRef<PredictiveSearchState<TData> | S>(\n resolve((storeRef.value as PredictiveSearchStore<TData>).getState()),\n );\n\n watch(\n () => storeRef.value,\n (store, _, onCleanup) => {\n const typedStore = store as PredictiveSearchStore<TData>;\n selected.value = resolve(typedStore.getState());\n\n const unsubscribe = typedStore.subscribe(() => {\n const next = resolve(typedStore.getState());\n if (isEqual && selector) {\n if (isEqual(selected.value as S, next)) return;\n }\n selected.value = next;\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n );\n\n return selected as Readonly<ShallowRef<PredictiveSearchState<TData> | S>>;\n}\n\n/**\n * Returns methods that search and clear results in the provider's current store.\n *\n * After a store option prop change replaces the store, the methods act on the new store.\n *\n * @throws {Error} When you call it outside a PredictiveSearchProvider.\n * @publicDocs\n */\nexport function usePredictiveSearchActions(): PredictiveSearchActions {\n const { storeRef } = useRequiredContext(\"usePredictiveSearchActions\");\n\n return {\n search: (term) => storeRef.value.search(term),\n clear: () => storeRef.value.clear(),\n };\n}\n\n/**\n * Returns functions that build a predictive search form that works without JavaScript.\n *\n * The form props function returns the form attributes. The register function returns the query input attributes and searches on every input event.\n * Both functions accept a callback that receives the event and the search term. Calling preventDefault on the event cancels the automatic behavior.\n *\n * @throws {Error} When you call it outside a PredictiveSearchProvider.\n * @publicDocs\n */\nexport function usePredictiveSearchForm(): PredictiveSearchFormResult {\n const { storeRef, searchActionRef } = useRequiredContext(\"usePredictiveSearchForm\");\n const coreRegister = createPredictiveSearchFormRegister();\n\n function register(\n field: \"query\",\n options: PredictiveSearchQueryInputPropsOptions = {},\n ): Record<string, unknown> {\n const { onInput, ...attributes } = options;\n const coreAttributes = coreRegister(field);\n\n return {\n ...attributes,\n ...coreAttributes,\n onInput: (event: Event) => {\n const term = (event.target as HTMLInputElement).value;\n onInput?.(event, term);\n if (event.defaultPrevented) return;\n void storeRef.value.search(term);\n },\n };\n }\n\n function formProps(options: PredictiveSearchFormPropsOptions = {}): Record<string, unknown> {\n const { onSubmit, preventDefault, ...attributes } = options;\n\n return {\n ...getPredictiveSearchFormAttributes(searchActionRef.value),\n ...attributes,\n onSubmit: (event: SubmitEvent) => {\n const term = readPredictiveSearchFormTerm(\n new FormData(event.currentTarget as HTMLFormElement),\n );\n onSubmit?.(event, term);\n if (event.defaultPrevented) return;\n if (!preventDefault) return;\n event.preventDefault();\n void storeRef.value.search(term);\n },\n };\n }\n\n return { formProps, register };\n}\n"],"mappings":";;;;;AA+BA,MAAM,yBAAyB;AAO/B,MAAM,sBAAkE,OAAO,mBAAmB;;;;;;;;;;;AA6ClG,MAAa,2BAA2B,gBAAgB;CACtD,MAAM;CACN,OAAO;EACL,0BAA0B;GAAE,MAAM;GAAQ,SAAS;GAAW;EAC9D,cAAc;GAAE,MAAM;GAAQ,SAAS;GAAW;EAClD,cAAc;GAAE,MAAM;GAAQ,SAAS;GAAW;EAClD,eAAe;GAAE,MAAM;GAAQ,SAAS;GAAW;EACnD,OAAO;GAAE,MAAM;GAA+C,SAAS;GAAW;EAClF,OAAO;GAAE,MAAM;GAAQ,SAAS;GAAW;EAC3C,YAAY;GAAE,MAAM;GAAgD,SAAS;GAAW;EACxF,OAAO;GAAE,MAAM;GAA2C,SAAS;GAAW;EAC9E,kBAAkB;GAAE,MAAM;GAAsC,SAAS;GAAW;EACpF,qBAAqB;GACnB,MAAM;GACN,SAAS;GACV;EACF;CACD,MAAM,OAAO,EAAE,SAAS;EACtB,SAAS,oBAAwD;AAC/D,UAAO;IACL,0BAA0B,MAAM;IAChC,cAAc,MAAM;IACpB,eAAe,MAAM;IACrB,OAAO,MAAM;IACb,OAAO,MAAM;IACb,YAAY,MAAM;IAClB,OAAO,MAAM;IACb,kBAAkB,MAAM;IACxB,qBAAqB,MAAM;IAC5B;;EAGH,MAAM,WAAW,WACf,4BAA4B,mBAAmB,CAAC,CACjD;EACD,MAAM,kBAAkB,WAAW,MAAM,aAAa;AAEtD,UAAQ,qBAAqB;GAAE;GAAU;GAAiB,CAAC;AAE3D,cACQ,MAAM,eACX,SAAS;AACR,mBAAgB,QAAQ;IAE3B;AAED,cACQ;GACJ,MAAM;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pE,MAAM,EAAE,UAAU,oBAAoB,mBAAmB,0BAA0B;CACnF,MAAM,eAAe,oCAAoC;CAEzD,SAAS,SACP,OACA,UAAkD,EAAE,EAC3B;EACzB,MAAM,EAAE,SAAS,GAAG,eAAe;EACnC,MAAM,iBAAiB,aAAa,MAAM;AAE1C,SAAO;GACL,GAAG;GACH,GAAG;GACH,UAAU,UAAiB;IACzB,MAAM,OAAQ,MAAM,OAA4B;AAChD,cAAU,OAAO,KAAK;AACtB,QAAI,MAAM,iBAAkB;AAC5B,IAAK,SAAS,MAAM,OAAO,KAAK;;GAEnC;;CAGH,SAAS,UAAU,UAA4C,EAAE,EAA2B;EAC1F,MAAM,EAAE,UAAU,gBAAgB,GAAG,eAAe;AAEpD,SAAO;GACL,GAAG,kCAAkC,gBAAgB,MAAM;GAC3D,GAAG;GACH,WAAW,UAAuB;IAChC,MAAM,OAAO,6BACX,IAAI,SAAS,MAAM,cAAiC,CACrD;AACD,eAAW,OAAO,KAAK;AACvB,QAAI,MAAM,iBAAkB;AAC5B,QAAI,CAAC,eAAgB;AACrB,UAAM,gBAAgB;AACtB,IAAK,SAAS,MAAM,OAAO,KAAK;;GAEnC;;AAGH,QAAO;EAAE;EAAW;EAAU"}
|
|
@@ -5,11 +5,12 @@ import { ProductFormRegister } from "../core/product/form.mjs";
|
|
|
5
5
|
import { ShallowRef, defineComponent } from "vue";
|
|
6
6
|
|
|
7
7
|
//#region src/vue/product.d.ts
|
|
8
|
-
/** Options for
|
|
8
|
+
/** Options for the standalone product form composable. */
|
|
9
9
|
interface UseProductFormOptions<TProduct extends ProductInput> {
|
|
10
|
+
/** Runs after each resolved or unresolved option selection. The composable captures the callback at setup time. */
|
|
10
11
|
onSelect?: (result: ValidProductSelectionResult<TProduct>) => void;
|
|
11
12
|
}
|
|
12
|
-
/** Return value of
|
|
13
|
+
/** Return value of the product form composables. */
|
|
13
14
|
interface UseProductFormResult<TProduct extends ProductInput> {
|
|
14
15
|
options: ProductFormOptions<TProduct>;
|
|
15
16
|
selectedVariant: ProductVariantFrom<TProduct> | null;
|
|
@@ -20,11 +21,11 @@ interface UseProductFormResult<TProduct extends ProductInput> {
|
|
|
20
21
|
}) => Record<string, unknown>;
|
|
21
22
|
errors: ProductFormErrors;
|
|
22
23
|
matchedLineItem: CartLine | null;
|
|
23
|
-
/**
|
|
24
|
+
/** Shallow ref that holds `true` while a form submission is in flight. */
|
|
24
25
|
pending: ShallowRef<boolean>;
|
|
25
26
|
selectOption: (name: string, value: string) => VariantSelectionResult<ProductVariantFrom<TProduct>>;
|
|
26
27
|
}
|
|
27
|
-
/** Return value of the
|
|
28
|
+
/** Return value of the product state composable that the product components factory returns. */
|
|
28
29
|
interface UseProductResult<TProduct extends ProductInput> {
|
|
29
30
|
options: ProductFormOptions<TProduct>;
|
|
30
31
|
selectedVariant: ProductVariantFrom<TProduct> | null;
|
|
@@ -33,23 +34,23 @@ interface UseProductResult<TProduct extends ProductInput> {
|
|
|
33
34
|
matchedLineItem: CartLine | null;
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
|
-
*
|
|
37
|
+
* Returns form state from a product form store and updates on each store change.
|
|
37
38
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* The composable subscribes to the store and leaves the store lifecycle to you. Create the store with createProductFormStore, then hydrate and destroy the store yourself. For a provider that manages the store, use createProductComponents.
|
|
40
|
+
*
|
|
41
|
+
* Read properties from the returned object. Destructuring reads each getter once and loses reactivity.
|
|
42
|
+
*
|
|
43
|
+
* @publicDocs
|
|
42
44
|
*/
|
|
43
45
|
declare function useProductForm<TProduct extends ProductInput>(store: ProductFormStore<TProduct>, options?: UseProductFormOptions<TProduct>): UseProductFormResult<TProduct>;
|
|
44
46
|
/**
|
|
45
|
-
*
|
|
47
|
+
* Returns a product provider and composables typed to your product query.
|
|
48
|
+
*
|
|
49
|
+
* The provider creates a product form store, hydrates the store when the product changes, and destroys the store on unmount. The product composable returns option state and variant selection. The form composable adds field registration, form props, and pending state. Both composables read the latest `onSelect` prop.
|
|
46
50
|
*
|
|
47
|
-
*
|
|
48
|
-
* - `ProductProvider` manages store lifecycle (creation, hydration, cleanup)
|
|
49
|
-
* - `useProduct` provides read-only state and variant selection
|
|
50
|
-
* - `useProductForm` provides form-binding utilities (register, formProps, pending)
|
|
51
|
+
* The provider throws an error without a cart provider ancestor. Each composable throws an error outside the product provider.
|
|
51
52
|
*
|
|
52
|
-
*
|
|
53
|
+
* @publicDocs
|
|
53
54
|
*/
|
|
54
55
|
declare function createProductComponents<TProduct extends ProductInput>(): {
|
|
55
56
|
ProductProvider: ReturnType<typeof defineComponent>;
|
|
@@ -62,26 +62,26 @@ function useProductFormImpl(store, getOnSelect) {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* Returns form state from a product form store and updates on each store change.
|
|
66
66
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
67
|
+
* The composable subscribes to the store and leaves the store lifecycle to you. Create the store with createProductFormStore, then hydrate and destroy the store yourself. For a provider that manages the store, use createProductComponents.
|
|
68
|
+
*
|
|
69
|
+
* Read properties from the returned object. Destructuring reads each getter once and loses reactivity.
|
|
70
|
+
*
|
|
71
|
+
* @publicDocs
|
|
71
72
|
*/
|
|
72
73
|
function useProductForm(store, options) {
|
|
73
74
|
const onSelect = options?.onSelect;
|
|
74
75
|
return useProductFormImpl(store, () => onSelect);
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
|
-
*
|
|
78
|
+
* Returns a product provider and composables typed to your product query.
|
|
79
|
+
*
|
|
80
|
+
* The provider creates a product form store, hydrates the store when the product changes, and destroys the store on unmount. The product composable returns option state and variant selection. The form composable adds field registration, form props, and pending state. Both composables read the latest `onSelect` prop.
|
|
78
81
|
*
|
|
79
|
-
*
|
|
80
|
-
* - `ProductProvider` manages store lifecycle (creation, hydration, cleanup)
|
|
81
|
-
* - `useProduct` provides read-only state and variant selection
|
|
82
|
-
* - `useProductForm` provides form-binding utilities (register, formProps, pending)
|
|
82
|
+
* The provider throws an error without a cart provider ancestor. Each composable throws an error outside the product provider.
|
|
83
83
|
*
|
|
84
|
-
*
|
|
84
|
+
* @publicDocs
|
|
85
85
|
*/
|
|
86
86
|
function createProductComponents() {
|
|
87
87
|
const ProductStoreKey = Symbol("ProductFormStore");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.mjs","names":[],"sources":["../../../src/vue/product.ts"],"sourcesContent":["import {\n defineComponent,\n inject,\n onScopeDispose,\n onUnmounted,\n provide,\n shallowRef,\n watch,\n type InjectionKey,\n type PropType,\n type ShallowRef,\n} from \"vue\";\n\nimport type { CartLine } from \"../core/cart/state\";\nimport { getLogger } from \"../core/logging\";\nimport {\n createProductFormRegister,\n createProductFormStore,\n type ProductFormErrors,\n type ProductFormOptions,\n type ProductFormRegister,\n type ProductFormStore,\n type ProductInput,\n type ProductVariantFrom,\n type ValidProductSelectionResult,\n type VariantSelectionResult,\n} from \"../core/product\";\nimport { getCartEndpoint, useCartStore } from \"./cart\";\n\nconst log = getLogger(\"product\");\n\n// ---------------------------------------------------------------------------\n// Shared types\n// ---------------------------------------------------------------------------\n\nexport type { ValidProductSelectionResult } from \"../core/product\";\n\n/** Options for {@link useProductForm}. */\nexport interface UseProductFormOptions<TProduct extends ProductInput> {\n onSelect?: (result: ValidProductSelectionResult<TProduct>) => void;\n}\n\n/** Return value of {@link useProductForm}. */\nexport interface UseProductFormResult<TProduct extends ProductInput> {\n options: ProductFormOptions<TProduct>;\n selectedVariant: ProductVariantFrom<TProduct> | null;\n register: ProductFormRegister;\n formProps: (opts?: {\n beforeSubmit?: (e: SubmitEvent) => void;\n afterSubmit?: (e: SubmitEvent) => void;\n }) => Record<string, unknown>;\n errors: ProductFormErrors;\n matchedLineItem: CartLine | null;\n /** Reactive ref that is `true` while a form submission is in flight. */\n pending: ShallowRef<boolean>;\n selectOption: (\n name: string,\n value: string,\n ) => VariantSelectionResult<ProductVariantFrom<TProduct>>;\n}\n\n/** Return value of the `useProduct` composable from {@link createProductComponents}. */\nexport interface UseProductResult<TProduct extends ProductInput> {\n options: ProductFormOptions<TProduct>;\n selectedVariant: ProductVariantFrom<TProduct> | null;\n selectOption: (\n name: string,\n value: string,\n ) => VariantSelectionResult<ProductVariantFrom<TProduct>>;\n errors: ProductFormErrors;\n matchedLineItem: CartLine | null;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\ninterface ProductContextValue<TProduct extends ProductInput> {\n store: ProductFormStore<TProduct>;\n getOnSelect: () => ((result: ValidProductSelectionResult<TProduct>) => void) | undefined;\n}\n\n/**\n * Shared implementation backing both the standalone composable and the factory\n * composable. Accepts a `getOnSelect` getter so the factory version can always\n * read the latest provider prop, while the standalone version captures the\n * caller's callback at setup time.\n */\nfunction useProductFormImpl<TProduct extends ProductInput>(\n store: ProductFormStore<TProduct>,\n getOnSelect: () => ((result: ValidProductSelectionResult<TProduct>) => void) | undefined,\n): UseProductFormResult<TProduct> {\n const state = shallowRef(store.getState());\n const pending = shallowRef(false);\n\n const unsubscribe = store.subscribe(() => {\n state.value = store.getState();\n });\n onScopeDispose(unsubscribe);\n\n function selectOption(\n name: string,\n value: string,\n ): VariantSelectionResult<ProductVariantFrom<TProduct>> {\n const result = store.selectOption(name, value);\n if (result.status !== \"invalid\") {\n getOnSelect()?.(result);\n }\n return result;\n }\n\n function formProps(opts?: {\n beforeSubmit?: (e: SubmitEvent) => void;\n afterSubmit?: (e: SubmitEvent) => void;\n }): Record<string, unknown> {\n return {\n onSubmit: (e: SubmitEvent) => {\n opts?.beforeSubmit?.(e);\n if (e.defaultPrevented) return;\n e.preventDefault();\n pending.value = true;\n store\n .handleFormSubmit(e)\n .then(\n () => opts?.afterSubmit?.(e),\n (error: unknown) => {\n log.error(\"form submission error\", { error });\n },\n )\n .finally(() => {\n pending.value = false;\n });\n },\n method: \"post\",\n action: getCartEndpoint(),\n };\n }\n\n return {\n get options() {\n return state.value.options;\n },\n get selectedVariant() {\n return state.value.selectedVariant;\n },\n get register() {\n return createProductFormRegister(state.value.selectedVariant, selectOption);\n },\n formProps,\n get errors() {\n return state.value.errors;\n },\n get matchedLineItem() {\n return state.value.matchedLineItem;\n },\n pending,\n selectOption,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Standalone composable\n// ---------------------------------------------------------------------------\n\n/**\n * Subscribes to a {@link ProductFormStore} and returns form-ready state.\n *\n * This is a pure subscription composable — it does **not** manage store\n * lifecycle. Create the store with `createProductFormStore` and manage its\n * lifecycle (hydration, destruction) yourself, or use\n * `createProductComponents` for a provider-based approach.\n */\nexport function useProductForm<TProduct extends ProductInput>(\n store: ProductFormStore<TProduct>,\n options?: UseProductFormOptions<TProduct>,\n): UseProductFormResult<TProduct> {\n const onSelect = options?.onSelect;\n return useProductFormImpl(store, () => onSelect);\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a typed set of product components bound to a specific product type.\n *\n * Returns `{ ProductProvider, useProduct, useProductForm }` where:\n * - `ProductProvider` manages store lifecycle (creation, hydration, cleanup)\n * - `useProduct` provides read-only state and variant selection\n * - `useProductForm` provides form-binding utilities (register, formProps, pending)\n *\n * Requires a `<CartProvider>` ancestor.\n */\nexport function createProductComponents<TProduct extends ProductInput>(): {\n ProductProvider: ReturnType<typeof defineComponent>;\n useProduct: () => UseProductResult<TProduct>;\n useProductForm: () => UseProductFormResult<TProduct>;\n} {\n const ProductStoreKey: InjectionKey<ProductContextValue<TProduct>> = Symbol(\"ProductFormStore\");\n\n function useProductContext(composableName: string): ProductContextValue<TProduct> {\n const ctx = inject(ProductStoreKey);\n if (!ctx) {\n throw new Error(\n `${composableName} must be used inside a <ProductProvider>. ` +\n \"Wrap your component tree with the ProductProvider from createProductComponents(), \" +\n \"or use the standalone useProductForm(store) composable instead.\",\n );\n }\n return ctx;\n }\n\n const ProductProvider = defineComponent({\n name: \"ProductProvider\",\n props: {\n product: {\n type: Object as PropType<TProduct>,\n required: true,\n },\n onSelect: {\n type: Function as PropType<(result: ValidProductSelectionResult<TProduct>) => void>,\n default: undefined,\n },\n },\n setup(props, { slots }) {\n const product = props.product as TProduct;\n const cartStore = useCartStore();\n const store = createProductFormStore<TProduct>(product, cartStore);\n\n provide(ProductStoreKey, {\n store,\n getOnSelect: () =>\n props.onSelect as ((result: ValidProductSelectionResult<TProduct>) => void) | undefined,\n });\n\n let mounted = false;\n watch(\n () => {\n const p = props.product as TProduct;\n return `${p.id}:${p.selectedOrFirstAvailableVariant?.id ?? \"\"}`;\n },\n () => {\n if (!mounted) {\n mounted = true;\n return;\n }\n store.hydrate(props.product as TProduct);\n },\n { immediate: true },\n );\n\n onUnmounted(() => store.destroy());\n\n return () => slots.default?.();\n },\n });\n\n function useProduct(): UseProductResult<TProduct> {\n const ctx = useProductContext(\"useProduct\");\n const state = shallowRef(ctx.store.getState());\n\n const unsubscribe = ctx.store.subscribe(() => {\n state.value = ctx.store.getState();\n });\n onScopeDispose(unsubscribe);\n\n function selectOption(\n name: string,\n value: string,\n ): VariantSelectionResult<ProductVariantFrom<TProduct>> {\n const result = ctx.store.selectOption(name, value);\n if (result.status !== \"invalid\") {\n ctx.getOnSelect()?.(result);\n }\n return result;\n }\n\n return {\n get options() {\n return state.value.options;\n },\n get selectedVariant() {\n return state.value.selectedVariant;\n },\n selectOption,\n get errors() {\n return state.value.errors;\n },\n get matchedLineItem() {\n return state.value.matchedLineItem;\n },\n };\n }\n\n function useProductFormHook(): UseProductFormResult<TProduct> {\n const ctx = useProductContext(\"useProductForm\");\n return useProductFormImpl(ctx.store, ctx.getOnSelect);\n }\n\n return {\n ProductProvider,\n useProduct,\n useProductForm: useProductFormHook,\n };\n}\n"],"mappings":";;;;;;;AA6BA,MAAM,MAAM,UAAU,UAAU;;;;;;;AA2DhC,SAAS,mBACP,OACA,aACgC;CAChC,MAAM,QA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
|
+
{"version":3,"file":"product.mjs","names":[],"sources":["../../../src/vue/product.ts"],"sourcesContent":["import {\n defineComponent,\n inject,\n onScopeDispose,\n onUnmounted,\n provide,\n shallowRef,\n watch,\n type InjectionKey,\n type PropType,\n type ShallowRef,\n} from \"vue\";\n\nimport type { CartLine } from \"../core/cart/state\";\nimport { getLogger } from \"../core/logging\";\nimport {\n createProductFormRegister,\n createProductFormStore,\n type ProductFormErrors,\n type ProductFormOptions,\n type ProductFormRegister,\n type ProductFormStore,\n type ProductInput,\n type ProductVariantFrom,\n type ValidProductSelectionResult,\n type VariantSelectionResult,\n} from \"../core/product\";\nimport { getCartEndpoint, useCartStore } from \"./cart\";\n\nconst log = getLogger(\"product\");\n\n// ---------------------------------------------------------------------------\n// Shared types\n// ---------------------------------------------------------------------------\n\nexport type { ValidProductSelectionResult } from \"../core/product\";\n\n/** Options for the standalone product form composable. */\nexport interface UseProductFormOptions<TProduct extends ProductInput> {\n /** Runs after each resolved or unresolved option selection. The composable captures the callback at setup time. */\n onSelect?: (result: ValidProductSelectionResult<TProduct>) => void;\n}\n\n/** Return value of the product form composables. */\nexport interface UseProductFormResult<TProduct extends ProductInput> {\n options: ProductFormOptions<TProduct>;\n selectedVariant: ProductVariantFrom<TProduct> | null;\n register: ProductFormRegister;\n formProps: (opts?: {\n beforeSubmit?: (e: SubmitEvent) => void;\n afterSubmit?: (e: SubmitEvent) => void;\n }) => Record<string, unknown>;\n errors: ProductFormErrors;\n matchedLineItem: CartLine | null;\n /** Shallow ref that holds `true` while a form submission is in flight. */\n pending: ShallowRef<boolean>;\n selectOption: (\n name: string,\n value: string,\n ) => VariantSelectionResult<ProductVariantFrom<TProduct>>;\n}\n\n/** Return value of the product state composable that the product components factory returns. */\nexport interface UseProductResult<TProduct extends ProductInput> {\n options: ProductFormOptions<TProduct>;\n selectedVariant: ProductVariantFrom<TProduct> | null;\n selectOption: (\n name: string,\n value: string,\n ) => VariantSelectionResult<ProductVariantFrom<TProduct>>;\n errors: ProductFormErrors;\n matchedLineItem: CartLine | null;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\ninterface ProductContextValue<TProduct extends ProductInput> {\n store: ProductFormStore<TProduct>;\n getOnSelect: () => ((result: ValidProductSelectionResult<TProduct>) => void) | undefined;\n}\n\n/**\n * Shared implementation backing both the standalone composable and the factory\n * composable. Accepts a `getOnSelect` getter so the factory version can always\n * read the latest provider prop, while the standalone version captures the\n * caller's callback at setup time.\n */\nfunction useProductFormImpl<TProduct extends ProductInput>(\n store: ProductFormStore<TProduct>,\n getOnSelect: () => ((result: ValidProductSelectionResult<TProduct>) => void) | undefined,\n): UseProductFormResult<TProduct> {\n const state = shallowRef(store.getState());\n const pending = shallowRef(false);\n\n const unsubscribe = store.subscribe(() => {\n state.value = store.getState();\n });\n onScopeDispose(unsubscribe);\n\n function selectOption(\n name: string,\n value: string,\n ): VariantSelectionResult<ProductVariantFrom<TProduct>> {\n const result = store.selectOption(name, value);\n if (result.status !== \"invalid\") {\n getOnSelect()?.(result);\n }\n return result;\n }\n\n function formProps(opts?: {\n beforeSubmit?: (e: SubmitEvent) => void;\n afterSubmit?: (e: SubmitEvent) => void;\n }): Record<string, unknown> {\n return {\n onSubmit: (e: SubmitEvent) => {\n opts?.beforeSubmit?.(e);\n if (e.defaultPrevented) return;\n e.preventDefault();\n pending.value = true;\n store\n .handleFormSubmit(e)\n .then(\n () => opts?.afterSubmit?.(e),\n (error: unknown) => {\n log.error(\"form submission error\", { error });\n },\n )\n .finally(() => {\n pending.value = false;\n });\n },\n method: \"post\",\n action: getCartEndpoint(),\n };\n }\n\n return {\n get options() {\n return state.value.options;\n },\n get selectedVariant() {\n return state.value.selectedVariant;\n },\n get register() {\n return createProductFormRegister(state.value.selectedVariant, selectOption);\n },\n formProps,\n get errors() {\n return state.value.errors;\n },\n get matchedLineItem() {\n return state.value.matchedLineItem;\n },\n pending,\n selectOption,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Standalone composable\n// ---------------------------------------------------------------------------\n\n/**\n * Returns form state from a product form store and updates on each store change.\n *\n * The composable subscribes to the store and leaves the store lifecycle to you. Create the store with createProductFormStore, then hydrate and destroy the store yourself. For a provider that manages the store, use createProductComponents.\n *\n * Read properties from the returned object. Destructuring reads each getter once and loses reactivity.\n *\n * @publicDocs\n */\nexport function useProductForm<TProduct extends ProductInput>(\n store: ProductFormStore<TProduct>,\n options?: UseProductFormOptions<TProduct>,\n): UseProductFormResult<TProduct> {\n const onSelect = options?.onSelect;\n return useProductFormImpl(store, () => onSelect);\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Returns a product provider and composables typed to your product query.\n *\n * The provider creates a product form store, hydrates the store when the product changes, and destroys the store on unmount. The product composable returns option state and variant selection. The form composable adds field registration, form props, and pending state. Both composables read the latest `onSelect` prop.\n *\n * The provider throws an error without a cart provider ancestor. Each composable throws an error outside the product provider.\n *\n * @publicDocs\n */\nexport function createProductComponents<TProduct extends ProductInput>(): {\n ProductProvider: ReturnType<typeof defineComponent>;\n useProduct: () => UseProductResult<TProduct>;\n useProductForm: () => UseProductFormResult<TProduct>;\n} {\n const ProductStoreKey: InjectionKey<ProductContextValue<TProduct>> = Symbol(\"ProductFormStore\");\n\n function useProductContext(composableName: string): ProductContextValue<TProduct> {\n const ctx = inject(ProductStoreKey);\n if (!ctx) {\n throw new Error(\n `${composableName} must be used inside a <ProductProvider>. ` +\n \"Wrap your component tree with the ProductProvider from createProductComponents(), \" +\n \"or use the standalone useProductForm(store) composable instead.\",\n );\n }\n return ctx;\n }\n\n const ProductProvider = defineComponent({\n name: \"ProductProvider\",\n props: {\n product: {\n type: Object as PropType<TProduct>,\n required: true,\n },\n onSelect: {\n type: Function as PropType<(result: ValidProductSelectionResult<TProduct>) => void>,\n default: undefined,\n },\n },\n setup(props, { slots }) {\n const product = props.product as TProduct;\n const cartStore = useCartStore();\n const store = createProductFormStore<TProduct>(product, cartStore);\n\n provide(ProductStoreKey, {\n store,\n getOnSelect: () =>\n props.onSelect as ((result: ValidProductSelectionResult<TProduct>) => void) | undefined,\n });\n\n let mounted = false;\n watch(\n () => {\n const p = props.product as TProduct;\n return `${p.id}:${p.selectedOrFirstAvailableVariant?.id ?? \"\"}`;\n },\n () => {\n if (!mounted) {\n mounted = true;\n return;\n }\n store.hydrate(props.product as TProduct);\n },\n { immediate: true },\n );\n\n onUnmounted(() => store.destroy());\n\n return () => slots.default?.();\n },\n });\n\n function useProduct(): UseProductResult<TProduct> {\n const ctx = useProductContext(\"useProduct\");\n const state = shallowRef(ctx.store.getState());\n\n const unsubscribe = ctx.store.subscribe(() => {\n state.value = ctx.store.getState();\n });\n onScopeDispose(unsubscribe);\n\n function selectOption(\n name: string,\n value: string,\n ): VariantSelectionResult<ProductVariantFrom<TProduct>> {\n const result = ctx.store.selectOption(name, value);\n if (result.status !== \"invalid\") {\n ctx.getOnSelect()?.(result);\n }\n return result;\n }\n\n return {\n get options() {\n return state.value.options;\n },\n get selectedVariant() {\n return state.value.selectedVariant;\n },\n selectOption,\n get errors() {\n return state.value.errors;\n },\n get matchedLineItem() {\n return state.value.matchedLineItem;\n },\n };\n }\n\n function useProductFormHook(): UseProductFormResult<TProduct> {\n const ctx = useProductContext(\"useProductForm\");\n return useProductFormImpl(ctx.store, ctx.getOnSelect);\n }\n\n return {\n ProductProvider,\n useProduct,\n useProductForm: useProductFormHook,\n };\n}\n"],"mappings":";;;;;;;AA6BA,MAAM,MAAM,UAAU,UAAU;;;;;;;AA4DhC,SAAS,mBACP,OACA,aACgC;CAChC,MAAM,QAAQ,WAAW,MAAM,UAAU,CAAC;CAC1C,MAAM,UAAU,WAAW,MAAM;AAKjC,gBAHoB,MAAM,gBAAgB;AACxC,QAAM,QAAQ,MAAM,UAAU;GAEN,CAAC;CAE3B,SAAS,aACP,MACA,OACsD;EACtD,MAAM,SAAS,MAAM,aAAa,MAAM,MAAM;AAC9C,MAAI,OAAO,WAAW,UACpB,cAAa,G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,CAAC;GAEF,IAAI,UAAU;AACd,eACQ;IACJ,MAAM,IAAI,MAAM;AAChB,WAAO,GAAG,EAAE,GAAG,GAAG,EAAE,iCAAiC,MAAM;YAEvD;AACJ,QAAI,CAAC,SAAS;AACZ,eAAU;AACV;;AAEF,UAAM,QAAQ,MAAM,QAAoB;MAE1C,EAAE,WAAW,MAAM,CACpB;AAED,qBAAkB,MAAM,SAAS,CAAC;AAElC,gBAAa,MAAM,WAAW;;EAEjC,CAAC;CAEF,SAAS,aAAyC;EAChD,MAAM,MAAM,kBAAkB,aAAa;EAC3C,MAAM,QAAQ,WAAW,IAAI,MAAM,UAAU,CAAC;AAK9C,iBAHoB,IAAI,MAAM,gBAAgB;AAC5C,SAAM,QAAQ,IAAI,MAAM,UAAU;IAEV,CAAC;EAE3B,SAAS,aACP,MACA,OACsD;GACtD,MAAM,SAAS,IAAI,MAAM,aAAa,MAAM,MAAM;AAClD,OAAI,OAAO,WAAW,UACpB,KAAI,aAAa,GAAG,OAAO;AAE7B,UAAO;;AAGT,SAAO;GACL,IAAI,UAAU;AACZ,WAAO,MAAM,MAAM;;GAErB,IAAI,kBAAkB;AACpB,WAAO,MAAM,MAAM;;GAErB;GACA,IAAI,SAAS;AACX,WAAO,MAAM,MAAM;;GAErB,IAAI,kBAAkB;AACpB,WAAO,MAAM,MAAM;;GAEtB;;CAGH,SAAS,qBAAqD;EAC5D,MAAM,MAAM,kBAAkB,iBAAiB;AAC/C,SAAO,mBAAmB,IAAI,OAAO,IAAI,YAAY;;AAGvD,QAAO;EACL;EACA;EACA,gBAAgB;EACjB"}
|
|
@@ -2,24 +2,21 @@ import { ShopPayButtonOptions } from "../core/shop-pay/shop-pay.mjs";
|
|
|
2
2
|
import * as _$vue from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/vue/shop-pay.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Props for the Vue ShopPayButton component.
|
|
7
|
+
*
|
|
8
|
+
* @publicDocs
|
|
9
|
+
*/
|
|
5
10
|
type ShopPayButtonProps = ShopPayButtonOptions;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
borderRadius?: string;
|
|
16
|
-
accessibilityLabel?: string;
|
|
17
|
-
} & {
|
|
18
|
-
variants?: readonly string[] | readonly {
|
|
19
|
-
id: string;
|
|
20
|
-
quantity?: number;
|
|
21
|
-
}[];
|
|
22
|
-
} & {}, _$vue.PublicProps>;
|
|
11
|
+
/**
|
|
12
|
+
* Renders the Shop Pay button custom element. During server rendering, the component outputs
|
|
13
|
+
* declarative shadow DOM, which displays the button before scripts load.
|
|
14
|
+
*
|
|
15
|
+
* The component takes the createShopPayButton options as Vue props. The component renders no slot content and drops extra attributes, including `class` and `style`. Vue templates can pass the props in kebab-case, such as `border-radius` and `accessibility-label`.
|
|
16
|
+
*
|
|
17
|
+
* @publicDocs
|
|
18
|
+
*/
|
|
19
|
+
declare const ShopPayButton: _$vue.DefineSetupFnComponent<ShopPayButtonOptions, {}, {}, ShopPayButtonOptions & {}, _$vue.PublicProps>;
|
|
23
20
|
//#endregion
|
|
24
21
|
export { ShopPayButton, ShopPayButtonProps };
|
|
25
22
|
//# sourceMappingURL=shop-pay.d.mts.map
|
|
@@ -4,6 +4,14 @@ import { defineComponent, h } from "vue";
|
|
|
4
4
|
//#region src/vue/shop-pay.ts
|
|
5
5
|
const canUseDom = typeof document !== "undefined";
|
|
6
6
|
defineShopPayButton();
|
|
7
|
+
/**
|
|
8
|
+
* Renders the Shop Pay button custom element. During server rendering, the component outputs
|
|
9
|
+
* declarative shadow DOM, which displays the button before scripts load.
|
|
10
|
+
*
|
|
11
|
+
* The component takes the createShopPayButton options as Vue props. The component renders no slot content and drops extra attributes, including `class` and `style`. Vue templates can pass the props in kebab-case, such as `border-radius` and `accessibility-label`.
|
|
12
|
+
*
|
|
13
|
+
* @publicDocs
|
|
14
|
+
*/
|
|
7
15
|
const ShopPayButton = defineComponent((props) => {
|
|
8
16
|
return () => {
|
|
9
17
|
const attributes = getShopPayButtonElementAttributes(props);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shop-pay.mjs","names":[],"sources":["../../../src/vue/shop-pay.ts"],"sourcesContent":["import { defineComponent, h } from \"vue\";\n\nimport {\n defineShopPayButton,\n getShopPayButtonDeclarativeShadowDomHtml,\n getShopPayButtonElementAttributes,\n SHOP_PAY_BUTTON_TAG_NAME,\n type ShopPayButtonOptions,\n} from \"../core/shop-pay/shop-pay\";\n\nexport type ShopPayButtonProps = ShopPayButtonOptions;\n\ntype CompletePropOptions<T> = {\n [K in keyof T]-?: unknown;\n};\n\nconst canUseDom = typeof document !== \"undefined\";\ndefineShopPayButton();\n\nexport const ShopPayButton = defineComponent(\n (props: ShopPayButtonProps) => {\n return () => {\n const attributes = getShopPayButtonElementAttributes(props);\n return canUseDom\n ? h(SHOP_PAY_BUTTON_TAG_NAME, attributes)\n : h(SHOP_PAY_BUTTON_TAG_NAME, {\n ...attributes,\n innerHTML: getShopPayButtonDeclarativeShadowDomHtml(props),\n });\n };\n },\n {\n name: \"ShopPayButton\",\n inheritAttrs: false,\n props: {\n variants: null,\n channel: null,\n checkoutUrl: String,\n paymentOption: null,\n source: String,\n sourceToken: String,\n nonce: String,\n disabled: Boolean,\n width: String,\n borderRadius: String,\n accessibilityLabel: String,\n } satisfies CompletePropOptions<ShopPayButtonProps>,\n },\n);\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"shop-pay.mjs","names":[],"sources":["../../../src/vue/shop-pay.ts"],"sourcesContent":["import { defineComponent, h } from \"vue\";\n\nimport {\n defineShopPayButton,\n getShopPayButtonDeclarativeShadowDomHtml,\n getShopPayButtonElementAttributes,\n SHOP_PAY_BUTTON_TAG_NAME,\n type ShopPayButtonOptions,\n} from \"../core/shop-pay/shop-pay\";\n\n/**\n * Props for the Vue ShopPayButton component.\n *\n * @publicDocs\n */\nexport type ShopPayButtonProps = ShopPayButtonOptions;\n\ntype CompletePropOptions<T> = {\n [K in keyof T]-?: unknown;\n};\n\nconst canUseDom = typeof document !== \"undefined\";\ndefineShopPayButton();\n\n/**\n * Renders the Shop Pay button custom element. During server rendering, the component outputs\n * declarative shadow DOM, which displays the button before scripts load.\n *\n * The component takes the createShopPayButton options as Vue props. The component renders no slot content and drops extra attributes, including `class` and `style`. Vue templates can pass the props in kebab-case, such as `border-radius` and `accessibility-label`.\n *\n * @publicDocs\n */\nexport const ShopPayButton = defineComponent(\n (props: ShopPayButtonProps) => {\n return () => {\n const attributes = getShopPayButtonElementAttributes(props);\n return canUseDom\n ? h(SHOP_PAY_BUTTON_TAG_NAME, attributes)\n : h(SHOP_PAY_BUTTON_TAG_NAME, {\n ...attributes,\n innerHTML: getShopPayButtonDeclarativeShadowDomHtml(props),\n });\n };\n },\n {\n name: \"ShopPayButton\",\n inheritAttrs: false,\n props: {\n variants: null,\n channel: null,\n checkoutUrl: String,\n paymentOption: null,\n source: String,\n sourceToken: String,\n nonce: String,\n disabled: Boolean,\n width: String,\n borderRadius: String,\n accessibilityLabel: String,\n } satisfies CompletePropOptions<ShopPayButtonProps>,\n },\n);\n"],"mappings":";;;;AAqBA,MAAM,YAAY,OAAO,aAAa;AACtC,qBAAqB;;;;;;;;;AAUrB,MAAa,gBAAgB,iBAC1B,UAA8B;AAC7B,cAAa;EACX,MAAM,aAAa,kCAAkC,MAAM;AAC3D,SAAO,YACH,EAAE,0BAA0B,WAAW,GACvC,EAAE,0BAA0B;GAC1B,GAAG;GACH,WAAW,yCAAyC,MAAM;GAC3D,CAAC;;GAGV;CACE,MAAM;CACN,cAAc;CACd,OAAO;EACL,UAAU;EACV,SAAS;EACT,aAAa;EACb,eAAe;EACf,QAAQ;EACR,aAAa;EACb,OAAO;EACP,UAAU;EACV,OAAO;EACP,cAAc;EACd,oBAAoB;EACrB;CACF,CACF"}
|
|
@@ -3,11 +3,22 @@ import { ConsentConfig, ConsentSetup } from "../core/analytics/types.mjs";
|
|
|
3
3
|
import * as _$vue from "vue";
|
|
4
4
|
|
|
5
5
|
//#region src/vue/shopify-scripts.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Props for the Vue ShopifyScripts component.
|
|
8
|
+
*
|
|
9
|
+
* @publicDocs
|
|
10
|
+
*/
|
|
6
11
|
type ShopifyScriptsProps = ShopifyScriptTagsOptions & {
|
|
7
12
|
navigate?: ShopifyRoutesOptions["navigate"];
|
|
8
13
|
routes?: ShopifyRoutesOptions["routes"];
|
|
9
14
|
webMcp?: boolean;
|
|
10
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Renders Shopify's script tags during server rendering and starts the scripts once, when the
|
|
18
|
+
* component mounts.
|
|
19
|
+
*
|
|
20
|
+
* @publicDocs
|
|
21
|
+
*/
|
|
11
22
|
declare const ShopifyScripts: _$vue.DefineComponent<_$vue.ExtractPropTypes<{
|
|
12
23
|
i18n: {
|
|
13
24
|
type: () => ShopifyScriptsI18n;
|
|
@@ -12,6 +12,12 @@ const analyticsProp = Object;
|
|
|
12
12
|
const debugProp = Object;
|
|
13
13
|
const inboxProp = Boolean;
|
|
14
14
|
const accountProp = Boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Renders Shopify's script tags during server rendering and starts the scripts once, when the
|
|
17
|
+
* component mounts.
|
|
18
|
+
*
|
|
19
|
+
* @publicDocs
|
|
20
|
+
*/
|
|
15
21
|
const ShopifyScripts = defineComponent({
|
|
16
22
|
name: "ShopifyScripts",
|
|
17
23
|
props: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shopify-scripts.mjs","names":[],"sources":["../../../src/vue/shopify-scripts.ts"],"sourcesContent":["import { defineComponent, h, onMounted, type PropType } from \"vue\";\n\nimport {\n getShopifyScriptTags,\n initializeShopifyScripts,\n type ShopifyScriptsShop,\n type ShopifyScriptsI18n,\n type ShopifyScriptTagsOptions,\n type ShopifyRoutesOptions,\n} from \"../core/shopify-scripts/index\";\n\nexport type ShopifyScriptsProps = ShopifyScriptTagsOptions & {\n navigate?: ShopifyRoutesOptions[\"navigate\"];\n routes?: ShopifyRoutesOptions[\"routes\"];\n webMcp?: boolean;\n};\n\ntype CompletePropOptions<T> = {\n [K in keyof T]-?: unknown;\n};\n\nconst i18nProp: PropType<ShopifyScriptsI18n> = Object;\nconst navigateProp: PropType<NonNullable<ShopifyRoutesOptions[\"navigate\"]>> | null = null;\nconst routesProp: PropType<NonNullable<ShopifyRoutesOptions[\"routes\"]>> | null = null;\nconst shopProp: PropType<ShopifyScriptsShop> = Object;\nconst consentProp: PropType<ShopifyScriptTagsOptions[\"consent\"]> = Object;\nconst analyticsProp: PropType<ShopifyScriptTagsOptions[\"analytics\"]> = Object;\nconst debugProp: PropType<ShopifyScriptTagsOptions[\"debug\"]> = Object;\nconst inboxProp: PropType<ShopifyScriptTagsOptions[\"inbox\"]> = Boolean;\nconst accountProp: PropType<ShopifyScriptTagsOptions[\"account\"]> = Boolean;\n\nexport const ShopifyScripts = defineComponent({\n name: \"ShopifyScripts\",\n props: {\n i18n: {\n type: i18nProp,\n default: undefined,\n },\n nonce: {\n type: String,\n default: undefined,\n },\n routes: {\n type: routesProp,\n default: undefined,\n },\n navigate: {\n type: navigateProp,\n default: undefined,\n },\n consent: {\n type: consentProp,\n default: undefined,\n },\n analytics: {\n type: analyticsProp,\n default: undefined,\n },\n debug: {\n type: debugProp,\n default: undefined,\n },\n webMcp: {\n type: Boolean,\n default: undefined,\n },\n inbox: {\n type: inboxProp,\n default: undefined,\n },\n account: {\n type: accountProp,\n default: undefined,\n },\n shopifyAnalytics: {\n type: Boolean,\n default: undefined,\n },\n shop: {\n type: shopProp,\n required: true as const,\n },\n } satisfies CompletePropOptions<ShopifyScriptsProps>,\n setup(props) {\n onMounted(() => {\n void initializeShopifyScripts({\n consent: props.consent,\n navigate: props.navigate,\n routes: props.routes,\n webMcp: props.webMcp !== false,\n });\n });\n\n return () =>\n getShopifyScriptTags(props).tags.map(({ tagName, attributes, innerHTML }) =>\n h(tagName, {\n ...attributes,\n ...(innerHTML ? { innerHTML } : {}),\n }),\n );\n },\n});\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"shopify-scripts.mjs","names":[],"sources":["../../../src/vue/shopify-scripts.ts"],"sourcesContent":["import { defineComponent, h, onMounted, type PropType } from \"vue\";\n\nimport {\n getShopifyScriptTags,\n initializeShopifyScripts,\n type ShopifyScriptsShop,\n type ShopifyScriptsI18n,\n type ShopifyScriptTagsOptions,\n type ShopifyRoutesOptions,\n} from \"../core/shopify-scripts/index\";\n\n/**\n * Props for the Vue ShopifyScripts component.\n *\n * @publicDocs\n */\nexport type ShopifyScriptsProps = ShopifyScriptTagsOptions & {\n navigate?: ShopifyRoutesOptions[\"navigate\"];\n routes?: ShopifyRoutesOptions[\"routes\"];\n webMcp?: boolean;\n};\n\ntype CompletePropOptions<T> = {\n [K in keyof T]-?: unknown;\n};\n\nconst i18nProp: PropType<ShopifyScriptsI18n> = Object;\nconst navigateProp: PropType<NonNullable<ShopifyRoutesOptions[\"navigate\"]>> | null = null;\nconst routesProp: PropType<NonNullable<ShopifyRoutesOptions[\"routes\"]>> | null = null;\nconst shopProp: PropType<ShopifyScriptsShop> = Object;\nconst consentProp: PropType<ShopifyScriptTagsOptions[\"consent\"]> = Object;\nconst analyticsProp: PropType<ShopifyScriptTagsOptions[\"analytics\"]> = Object;\nconst debugProp: PropType<ShopifyScriptTagsOptions[\"debug\"]> = Object;\nconst inboxProp: PropType<ShopifyScriptTagsOptions[\"inbox\"]> = Boolean;\nconst accountProp: PropType<ShopifyScriptTagsOptions[\"account\"]> = Boolean;\n\n/**\n * Renders Shopify's script tags during server rendering and starts the scripts once, when the\n * component mounts.\n *\n * @publicDocs\n */\nexport const ShopifyScripts = defineComponent({\n name: \"ShopifyScripts\",\n props: {\n i18n: {\n type: i18nProp,\n default: undefined,\n },\n nonce: {\n type: String,\n default: undefined,\n },\n routes: {\n type: routesProp,\n default: undefined,\n },\n navigate: {\n type: navigateProp,\n default: undefined,\n },\n consent: {\n type: consentProp,\n default: undefined,\n },\n analytics: {\n type: analyticsProp,\n default: undefined,\n },\n debug: {\n type: debugProp,\n default: undefined,\n },\n webMcp: {\n type: Boolean,\n default: undefined,\n },\n inbox: {\n type: inboxProp,\n default: undefined,\n },\n account: {\n type: accountProp,\n default: undefined,\n },\n shopifyAnalytics: {\n type: Boolean,\n default: undefined,\n },\n shop: {\n type: shopProp,\n required: true as const,\n },\n } satisfies CompletePropOptions<ShopifyScriptsProps>,\n setup(props) {\n onMounted(() => {\n void initializeShopifyScripts({\n consent: props.consent,\n navigate: props.navigate,\n routes: props.routes,\n webMcp: props.webMcp !== false,\n });\n });\n\n return () =>\n getShopifyScriptTags(props).tags.map(({ tagName, attributes, innerHTML }) =>\n h(tagName, {\n ...attributes,\n ...(innerHTML ? { innerHTML } : {}),\n }),\n );\n },\n});\n"],"mappings":";;;;;AA0BA,MAAM,WAAyC;AAC/C,MAAM,eAA+E;AACrF,MAAM,aAA2E;AACjF,MAAM,WAAyC;AAC/C,MAAM,cAA6D;AACnE,MAAM,gBAAiE;AACvE,MAAM,YAAyD;AAC/D,MAAM,YAAyD;AAC/D,MAAM,cAA6D;;;;;;;AAQnE,MAAa,iBAAiB,gBAAgB;CAC5C,MAAM;CACN,OAAO;EACL,MAAM;GACJ,MAAM;GACN,SAAS;GACV;EACD,OAAO;GACL,MAAM;GACN,SAAS;GACV;EACD,QAAQ;GACN,MAAM;GACN,SAAS;GACV;EACD,UAAU;GACR,MAAM;GACN,SAAS;GACV;EACD,SAAS;GACP,MAAM;GACN,SAAS;GACV;EACD,WAAW;GACT,MAAM;GACN,SAAS;GACV;EACD,OAAO;GACL,MAAM;GACN,SAAS;GACV;EACD,QAAQ;GACN,MAAM;GACN,SAAS;GACV;EACD,OAAO;GACL,MAAM;GACN,SAAS;GACV;EACD,SAAS;GACP,MAAM;GACN,SAAS;GACV;EACD,kBAAkB;GAChB,MAAM;GACN,SAAS;GACV;EACD,MAAM;GACJ,MAAM;GACN,UAAU;GACX;EACF;CACD,MAAM,OAAO;AACX,kBAAgB;AACd,GAAK,yBAAyB;IAC5B,SAAS,MAAM;IACf,UAAU,MAAM;IAChB,QAAQ,MAAM;IACd,QAAQ,MAAM,WAAW;IAC1B,CAAC;IACF;AAEF,eACE,qBAAqB,MAAM,CAAC,KAAK,KAAK,EAAE,SAAS,YAAY,gBAC3D,EAAE,SAAS;GACT,GAAG;GACH,GAAI,YAAY,EAAE,WAAW,GAAG,EAAE;GACnC,CAAC,CACH;;CAEN,CAAC"}
|
package/dist/globals.d.mts
CHANGED
|
@@ -4,9 +4,14 @@ import { ShopifyStandardActions } from "./vendor/standard-actions.mjs";
|
|
|
4
4
|
import { StorefrontAnalytics } from "./core/analytics/types.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/globals.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* The `window.Shopify` object that Shopify's scripts and Hydrogen share in the browser.
|
|
9
|
+
*
|
|
10
|
+
* @publicDocs
|
|
11
|
+
*/
|
|
7
12
|
type ShopifyGlobal = {
|
|
8
13
|
actions: ShopifyStandardActions;
|
|
9
|
-
analytics?: StorefrontAnalytics;
|
|
14
|
+
analytics?: StorefrontAnalytics; /** The store settings that Shopify's storefront web components read. */
|
|
10
15
|
components: {
|
|
11
16
|
config: {
|
|
12
17
|
storeDomain: string;
|
|
@@ -15,11 +20,11 @@ type ShopifyGlobal = {
|
|
|
15
20
|
country?: string;
|
|
16
21
|
language?: string;
|
|
17
22
|
};
|
|
18
|
-
};
|
|
19
|
-
country: I18nConfig["country"] | string;
|
|
23
|
+
}; /** The customer's country code. Defaults to `US`. */
|
|
24
|
+
country: I18nConfig["country"] | string; /** The active currency code, in uppercase. */
|
|
20
25
|
currency?: {
|
|
21
26
|
active: string;
|
|
22
|
-
};
|
|
27
|
+
}; /** Shopify's Customer Privacy API, which reads and updates the customer's consent. */
|
|
23
28
|
customerPrivacy: {
|
|
24
29
|
config?: {
|
|
25
30
|
isHeadless?: boolean;
|
|
@@ -36,14 +41,18 @@ type ShopifyGlobal = {
|
|
|
36
41
|
setTrackingConsent: (consent: Record<string, unknown>) => Promise<unknown>;
|
|
37
42
|
shouldShowBanner: () => boolean;
|
|
38
43
|
shouldShowGDPRBanner: () => boolean;
|
|
39
|
-
};
|
|
40
|
-
locale: Lowercase<I18nConfig["language"]> | string;
|
|
41
|
-
|
|
44
|
+
}; /** The customer's language code, in lowercase. Defaults to `en`. */
|
|
45
|
+
locale: Lowercase<I18nConfig["language"]> | string;
|
|
46
|
+
/**
|
|
47
|
+
* Navigates to a storefront URL.
|
|
48
|
+
* @deprecated Use `Shopify.routes.navigate` instead.
|
|
49
|
+
*/
|
|
50
|
+
navigate?: (url: string) => void | Promise<void>; /** The storefront's route settings and navigation helper. */
|
|
42
51
|
routes: {
|
|
43
|
-
root: string; /** @
|
|
44
|
-
apiProxyPrefix?: string; /** @
|
|
45
|
-
match?: (url: string) => ShopifyStandardRouteMatch | null; /** @
|
|
46
|
-
resolve?: (url: string) => string; /**
|
|
52
|
+
/** The locale path prefix with a trailing slash, or `"/"` when the storefront has no prefix. */root: string; /** @private */
|
|
53
|
+
apiProxyPrefix?: string; /** @private */
|
|
54
|
+
match?: (url: string) => ShopifyStandardRouteMatch | null; /** @private */
|
|
55
|
+
resolve?: (url: string) => string; /** Navigates to a storefront URL after resolving it to your app's route. */
|
|
47
56
|
navigate?: (url: string) => void | Promise<void>;
|
|
48
57
|
[key: string]: unknown;
|
|
49
58
|
}; /** The shop's permanent `*.myshopify.com` domain. */
|