@shopify/hydrogen 0.11.0-experimental.1 → 0.11.1-experimental.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/CHANGELOG.md +504 -0
- package/dist/esnext/client.d.ts +1 -1
- package/dist/esnext/client.js +1 -1
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.d.ts +1 -1
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +11 -2
- package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.js +1 -1
- package/dist/esnext/components/CartLineImage/CartLineImage.client.js +2 -2
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.d.ts +1 -1
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.js +1 -1
- package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +2 -2
- package/dist/esnext/components/CartProvider/CartProvider.client.js +1 -1
- package/dist/esnext/components/ExternalVideo/ExternalVideo.d.ts +1 -1
- package/dist/esnext/components/ExternalVideo/ExternalVideo.js +2 -2
- package/dist/esnext/components/Image/Image.d.ts +1 -1
- package/dist/esnext/components/Image/Image.js +9 -9
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +13 -4
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +5 -3
- package/dist/esnext/components/MediaFile/MediaFile.d.ts +8 -6
- package/dist/esnext/components/MediaFile/MediaFile.js +6 -6
- package/dist/esnext/components/Metafield/Metafield.client.d.ts +1 -1
- package/dist/esnext/components/Metafield/Metafield.client.js +16 -16
- package/dist/esnext/components/ModelViewer/ModelViewer.client.d.ts +1 -1
- package/dist/esnext/components/ModelViewer/ModelViewer.client.js +1 -1
- package/dist/esnext/components/Money/Money.client.d.ts +1 -1
- package/dist/esnext/components/Money/Money.client.js +2 -2
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.d.ts +3 -1
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +21 -4
- package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +5 -3
- package/dist/esnext/components/ProductPrice/ProductPrice.client.js +30 -9
- package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.d.ts +8 -0
- package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.js +12 -0
- package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +8 -7
- package/dist/esnext/components/ProductProvider/ProductProvider.client.js +9 -35
- package/dist/esnext/components/ProductProvider/context.d.ts +10 -6
- package/dist/esnext/components/ProductProvider/context.js +1 -0
- package/dist/esnext/components/Seo/DefaultPageSeo.client.js +2 -2
- package/dist/esnext/components/Seo/DescriptionSeo.client.js +2 -2
- package/dist/esnext/components/Seo/HomePageSeo.client.js +2 -2
- package/dist/esnext/components/Seo/ImageSeo.client.js +2 -2
- package/dist/esnext/components/Seo/ProductSeo.client.js +5 -3
- package/dist/esnext/components/Seo/TitleSeo.client.js +2 -2
- package/dist/esnext/components/Seo/TwitterSeo.client.js +2 -2
- package/dist/esnext/components/Seo/types.d.ts +1 -1
- package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +2 -2
- package/dist/esnext/components/UnitPrice/UnitPrice.client.js +3 -3
- package/dist/esnext/components/Video/Video.d.ts +1 -1
- package/dist/esnext/components/Video/Video.js +3 -3
- package/dist/esnext/components/index.d.ts +0 -8
- package/dist/esnext/components/index.js +0 -8
- package/dist/esnext/entry-client.js +1 -1
- package/dist/esnext/entry-server.d.ts +18 -2
- package/dist/esnext/entry-server.js +347 -329
- package/dist/esnext/foundation/Head/Head.client.d.ts +5 -0
- package/dist/esnext/foundation/Head/Head.client.js +10 -0
- package/dist/esnext/foundation/Head/index.d.ts +1 -0
- package/dist/esnext/foundation/Head/index.js +1 -0
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +2 -1
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +43 -4
- package/dist/esnext/foundation/useQuery/hooks.d.ts +11 -3
- package/dist/esnext/foundation/useQuery/hooks.js +21 -5
- package/dist/esnext/framework/CachingStrategy/index.d.ts +10 -0
- package/dist/esnext/framework/CachingStrategy/index.js +96 -0
- package/dist/esnext/framework/Hydration/Html.js +5 -12
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.d.ts +20 -2
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.js +51 -2
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.d.ts +2 -2
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +2 -11
- package/dist/esnext/framework/cache/in-memory.js +6 -5
- package/dist/esnext/framework/cache.d.ts +3 -3
- package/dist/esnext/framework/cache.js +4 -18
- package/dist/esnext/framework/middleware.d.ts +7 -7
- package/dist/esnext/framework/middleware.js +15 -43
- package/dist/esnext/framework/plugin.js +14 -3
- package/dist/esnext/framework/plugins/vite-plugin-hydration-auto-import.d.ts +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydration-auto-import.js +38 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-middleware.d.ts +9 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-middleware.js +37 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +2 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +3 -1
- package/dist/esnext/framework/plugins/vite-plugin-platform-entry.d.ts +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-platform-entry.js +70 -0
- package/dist/esnext/hooks/useProduct/useProduct.d.ts +150 -1
- package/dist/esnext/hooks/useProduct/useProduct.js +36 -3
- package/dist/esnext/hooks/useProductOptions/types.d.ts +1 -1
- package/dist/esnext/hooks/useProductOptions/useProductOptions.d.ts +1 -1
- package/dist/esnext/hooks/useProductOptions/useProductOptions.js +6 -6
- package/dist/esnext/hooks/useShopQuery/hooks.d.ts +11 -4
- package/dist/esnext/hooks/useShopQuery/hooks.js +6 -3
- package/dist/esnext/index.d.ts +2 -1
- package/dist/esnext/index.js +2 -1
- package/dist/esnext/platforms/node.d.ts +10 -0
- package/dist/esnext/platforms/node.js +38 -0
- package/dist/esnext/platforms/worker-event.d.ts +9 -0
- package/dist/esnext/platforms/worker-event.js +24 -0
- package/dist/esnext/streaming.server.d.ts +17 -7
- package/dist/esnext/streaming.server.js +44 -0
- package/dist/esnext/types.d.ts +25 -25
- package/dist/esnext/utilities/apiRoutes.d.ts +1 -2
- package/dist/esnext/utilities/apiRoutes.js +4 -3
- package/dist/esnext/utilities/bot-ua.d.ts +4 -0
- package/dist/esnext/utilities/bot-ua.js +54 -0
- package/dist/esnext/utilities/fetch.js +1 -26
- package/dist/esnext/utilities/log/index.d.ts +4 -1
- package/dist/esnext/utilities/log/index.js +4 -1
- package/dist/esnext/utilities/log/log-cache-api-status.d.ts +1 -0
- package/dist/esnext/utilities/log/log-cache-api-status.js +9 -0
- package/dist/esnext/utilities/log/log-cache-header.d.ts +10 -0
- package/dist/esnext/utilities/log/log-cache-header.js +30 -0
- package/dist/esnext/utilities/log/log-query-timeline.d.ts +12 -0
- package/dist/esnext/utilities/log/log-query-timeline.js +83 -0
- package/dist/esnext/utilities/log/log.d.ts +11 -8
- package/dist/esnext/utilities/log/log.js +24 -35
- package/dist/esnext/utilities/log/utils.d.ts +3 -0
- package/dist/esnext/utilities/log/utils.js +13 -0
- package/dist/esnext/utilities/template.d.ts +9 -0
- package/dist/esnext/utilities/template.js +23 -0
- package/dist/{worker/foundation/ShopifyProvider/types.js → esnext/utilities/web-api-polyfill.d.ts} +0 -0
- package/dist/esnext/utilities/web-api-polyfill.js +19 -0
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/entry-server.d.ts +22 -0
- package/dist/node/entry-server.js +581 -0
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +23 -0
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +132 -0
- package/dist/node/foundation/ServerRequestProvider/index.d.ts +1 -0
- package/dist/node/foundation/ServerRequestProvider/index.js +13 -0
- package/dist/node/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +25 -0
- package/dist/node/foundation/ServerStateProvider/ServerStateProvider.client.js +68 -0
- package/dist/node/foundation/ServerStateProvider/index.d.ts +2 -0
- package/dist/node/foundation/ServerStateProvider/index.js +6 -0
- package/dist/node/framework/CachingStrategy/index.d.ts +10 -0
- package/dist/node/framework/CachingStrategy/index.js +108 -0
- package/dist/node/framework/Hydration/Html.js +5 -12
- package/dist/node/framework/Hydration/ServerComponentRequest.server.d.ts +20 -2
- package/dist/node/framework/Hydration/ServerComponentRequest.server.js +50 -1
- package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +2 -2
- package/dist/node/framework/Hydration/ServerComponentResponse.server.js +2 -11
- package/dist/node/framework/cache/in-memory.js +6 -5
- package/dist/node/framework/cache.d.ts +3 -3
- package/dist/node/framework/cache.js +6 -20
- package/dist/node/framework/middleware.d.ts +7 -7
- package/dist/node/framework/middleware.js +14 -46
- package/dist/node/framework/plugin.js +33 -3
- package/dist/node/framework/plugins/vite-plugin-hydration-auto-import.d.ts +3 -0
- package/dist/node/framework/plugins/vite-plugin-hydration-auto-import.js +43 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-client-middleware.d.ts +9 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-client-middleware.js +39 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +2 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +4 -1
- package/dist/node/framework/plugins/vite-plugin-platform-entry.d.ts +3 -0
- package/dist/node/framework/plugins/vite-plugin-platform-entry.js +75 -0
- package/dist/node/streaming.server.d.ts +21 -0
- package/dist/node/streaming.server.js +59 -0
- package/dist/node/types.d.ts +25 -25
- package/dist/node/utilities/apiRoutes.d.ts +1 -2
- package/dist/node/utilities/apiRoutes.js +4 -3
- package/dist/node/utilities/bot-ua.d.ts +4 -0
- package/dist/node/utilities/bot-ua.js +58 -0
- package/dist/node/utilities/defer.d.ts +6 -0
- package/dist/node/utilities/defer.js +18 -0
- package/dist/node/utilities/error.d.ts +1 -0
- package/dist/node/utilities/error.js +10 -0
- package/dist/node/utilities/log/index.d.ts +4 -0
- package/dist/node/utilities/log/index.js +18 -0
- package/dist/node/utilities/log/log-cache-api-status.d.ts +1 -0
- package/dist/node/utilities/log/log-cache-api-status.js +13 -0
- package/dist/node/utilities/log/log-cache-header.d.ts +10 -0
- package/dist/node/utilities/log/log-cache-header.js +35 -0
- package/dist/node/utilities/log/log-query-timeline.d.ts +12 -0
- package/dist/node/utilities/log/log-query-timeline.js +88 -0
- package/dist/node/utilities/log/log.d.ts +11 -8
- package/dist/node/utilities/log/log.js +27 -37
- package/dist/node/utilities/log/utils.d.ts +3 -0
- package/dist/node/utilities/log/utils.js +18 -0
- package/dist/node/utilities/template.d.ts +9 -0
- package/dist/node/utilities/template.js +27 -0
- package/dist/{worker/types.js → node/utilities/web-api-polyfill.d.ts} +0 -0
- package/dist/node/utilities/web-api-polyfill.js +43 -0
- package/package.json +20 -10
- package/web-polyfills.js +1 -0
- package/LICENSE.md +0 -7
- package/dist/esnext/components/CartLineAttributes/CartLineAttributes.client.d.ts +0 -22
- package/dist/esnext/components/CartLineAttributes/CartLineAttributes.client.js +0 -13
- package/dist/esnext/components/CartLineAttributes/index.d.ts +0 -1
- package/dist/esnext/components/CartLineAttributes/index.js +0 -1
- package/dist/esnext/components/CartLineSelectedOptions/CartLineSelectedOptions.client.d.ts +0 -21
- package/dist/esnext/components/CartLineSelectedOptions/CartLineSelectedOptions.client.js +0 -13
- package/dist/esnext/components/CartLineSelectedOptions/index.d.ts +0 -1
- package/dist/esnext/components/CartLineSelectedOptions/index.js +0 -1
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.d.ts +0 -11
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.js +0 -17
- package/dist/esnext/components/SelectedVariantAddToCartButton/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantAddToCartButton/index.js +0 -1
- package/dist/esnext/components/SelectedVariantBuyNowButton/SelectedVariantBuyNowButton.d.ts +0 -9
- package/dist/esnext/components/SelectedVariantBuyNowButton/SelectedVariantBuyNowButton.js +0 -17
- package/dist/esnext/components/SelectedVariantBuyNowButton/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantBuyNowButton/index.js +0 -1
- package/dist/esnext/components/SelectedVariantImage/SelectedVariantImage.client.d.ts +0 -10
- package/dist/esnext/components/SelectedVariantImage/SelectedVariantImage.client.js +0 -16
- package/dist/esnext/components/SelectedVariantImage/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantImage/index.js +0 -1
- package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.d.ts +0 -15
- package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.js +0 -24
- package/dist/esnext/components/SelectedVariantMetafield/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantMetafield/index.js +0 -1
- package/dist/esnext/components/SelectedVariantPrice/SelectedVariantPrice.client.d.ts +0 -12
- package/dist/esnext/components/SelectedVariantPrice/SelectedVariantPrice.client.js +0 -22
- package/dist/esnext/components/SelectedVariantPrice/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantPrice/index.js +0 -1
- package/dist/esnext/components/SelectedVariantShopPayButton/SelectedVariantShopPayButton.client.d.ts +0 -8
- package/dist/esnext/components/SelectedVariantShopPayButton/SelectedVariantShopPayButton.client.js +0 -18
- package/dist/esnext/components/SelectedVariantShopPayButton/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantShopPayButton/index.js +0 -1
- package/dist/esnext/components/SelectedVariantUnitPrice/SelectedVariantUnitPrice.client.d.ts +0 -7
- package/dist/esnext/components/SelectedVariantUnitPrice/SelectedVariantUnitPrice.client.js +0 -16
- package/dist/esnext/components/SelectedVariantUnitPrice/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantUnitPrice/index.js +0 -1
- package/dist/esnext/foundation/Helmet/Helmet.client.d.ts +0 -10
- package/dist/esnext/foundation/Helmet/Helmet.client.js +0 -10
- package/dist/esnext/foundation/Helmet/index.d.ts +0 -1
- package/dist/esnext/foundation/Helmet/index.js +0 -1
- package/dist/esnext/handle-event.d.ts +0 -23
- package/dist/esnext/handle-event.js +0 -132
- package/dist/esnext/handle-worker-event.d.ts +0 -11
- package/dist/esnext/handle-worker-event.js +0 -14
- package/dist/node/foundation/Helmet/Helmet.client.d.ts +0 -10
- package/dist/node/foundation/Helmet/Helmet.client.js +0 -17
- package/dist/node/foundation/Helmet/index.d.ts +0 -1
- package/dist/node/foundation/Helmet/index.js +0 -5
- package/dist/node/foundation/ssr-interop.d.ts +0 -29
- package/dist/node/foundation/ssr-interop.js +0 -39
- package/dist/node/handle-event.d.ts +0 -23
- package/dist/node/handle-event.js +0 -135
- package/dist/worker/constants.d.ts +0 -1
- package/dist/worker/constants.js +0 -1
- package/dist/worker/foundation/Helmet/Helmet.client.d.ts +0 -10
- package/dist/worker/foundation/Helmet/Helmet.client.js +0 -10
- package/dist/worker/foundation/Helmet/index.d.ts +0 -1
- package/dist/worker/foundation/Helmet/index.js +0 -1
- package/dist/worker/foundation/ShopifyProvider/types.d.ts +0 -15
- package/dist/worker/foundation/ssr-interop.d.ts +0 -29
- package/dist/worker/foundation/ssr-interop.js +0 -35
- package/dist/worker/framework/Hydration/ServerComponentRequest.server.d.ts +0 -23
- package/dist/worker/framework/Hydration/ServerComponentRequest.server.js +0 -57
- package/dist/worker/framework/config.d.ts +0 -6
- package/dist/worker/framework/config.js +0 -6
- package/dist/worker/framework/runtime.d.ts +0 -13
- package/dist/worker/framework/runtime.js +0 -27
- package/dist/worker/graphql/types/types.d.ts +0 -5761
- package/dist/worker/graphql/types/types.js +0 -1436
- package/dist/worker/handle-event.d.ts +0 -23
- package/dist/worker/handle-event.js +0 -132
- package/dist/worker/handle-worker-event.d.ts +0 -11
- package/dist/worker/handle-worker-event.js +0 -14
- package/dist/worker/types.d.ts +0 -96
- package/dist/worker/utilities/apiRoutes.d.ts +0 -21
- package/dist/worker/utilities/apiRoutes.js +0 -87
- package/dist/worker/utilities/log/log.d.ts +0 -18
- package/dist/worker/utilities/log/log.js +0 -77
- package/dist/worker/utilities/matchPath.d.ts +0 -10
- package/dist/worker/utilities/matchPath.js +0 -54
- package/dist/worker/utilities/timing.d.ts +0 -7
- package/dist/worker/utilities/timing.js +0 -14
- package/worker.js +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ImageFragment as Fragment } from '../../graphql/graphql-constants';
|
|
3
3
|
import { shopifyImageLoader, getShopifyImageDimensions, } from '../../utilities';
|
|
4
|
-
function convertShopifyImageData({
|
|
5
|
-
const { url: src, altText, id } =
|
|
6
|
-
const { width, height } = getShopifyImageDimensions(
|
|
4
|
+
function convertShopifyImageData({ data, options, loader, loaderOptions, id: propId, alt, }) {
|
|
5
|
+
const { url: src, altText, id } = data;
|
|
6
|
+
const { width, height } = getShopifyImageDimensions(data, options);
|
|
7
7
|
return {
|
|
8
8
|
src,
|
|
9
9
|
id: propId ? propId : id,
|
|
@@ -20,16 +20,16 @@ function convertShopifyImageData({ image, options, loader, loaderOptions, id: pr
|
|
|
20
20
|
*/
|
|
21
21
|
export function Image(props) {
|
|
22
22
|
var _a, _b, _c, _d;
|
|
23
|
-
const {
|
|
24
|
-
if (!
|
|
25
|
-
throw new Error('Image component: requires either an `
|
|
23
|
+
const { data, options, src, id, alt, width, height, loader, loaderOptions, ...passthroughProps } = props;
|
|
24
|
+
if (!data && !src) {
|
|
25
|
+
throw new Error('Image component: requires either an `data` or `src` prop.');
|
|
26
26
|
}
|
|
27
|
-
if (!
|
|
27
|
+
if (!data && src && (!width || !height)) {
|
|
28
28
|
throw new Error(`Image component: when 'src' is provided, 'width' and 'height' are required and needs to be valid values (i.e. greater than zero). Provided values: 'src': ${src}, 'width': ${width}, 'height': ${height}`);
|
|
29
29
|
}
|
|
30
|
-
const imgProps =
|
|
30
|
+
const imgProps = data
|
|
31
31
|
? convertShopifyImageData({
|
|
32
|
-
|
|
32
|
+
data,
|
|
33
33
|
options,
|
|
34
34
|
loader,
|
|
35
35
|
loaderOptions,
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
1
|
+
import { ReactNode, ElementType } from 'react';
|
|
2
|
+
import { PreloadOptions } from '../../types';
|
|
3
|
+
import { Props } from '../types';
|
|
4
|
+
export interface LocalizationProviderProps {
|
|
5
|
+
/** A `ReactNode` element. */
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
/** Whether to preload the query. Defaults to `false`. Specify `true` to
|
|
8
|
+
* [preload the query](/custom-storefronts/hydrogen/framework/preloaded-queries) for the URL
|
|
9
|
+
* or `'*'` to preload the query for all requests.
|
|
10
|
+
*/
|
|
11
|
+
preload: PreloadOptions;
|
|
12
|
+
}
|
|
2
13
|
/**
|
|
3
14
|
* The `LocalizationProvider` component automatically queries the Storefront API's
|
|
4
15
|
* [`localization`](/api/storefront/reference/common-objects/queryroot) field
|
|
@@ -8,6 +19,4 @@ import { ReactNode } from 'react';
|
|
|
8
19
|
* The `isoCode` of the `country` can be used in the Storefront API's
|
|
9
20
|
* `@inContext` directive as the `country` value.
|
|
10
21
|
*/
|
|
11
|
-
export declare function LocalizationProvider(
|
|
12
|
-
children: ReactNode;
|
|
13
|
-
}): JSX.Element;
|
|
22
|
+
export declare function LocalizationProvider<TTag extends ElementType>(props: Props<TTag> & LocalizationProviderProps): JSX.Element;
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import LocalizationClientProvider from './LocalizationClientProvider.client';
|
|
3
3
|
import { useShopQuery } from '../../hooks/useShopQuery';
|
|
4
4
|
import { Localization } from '../../graphql/graphql-constants';
|
|
5
|
+
import { CacheDays } from '../../framework/CachingStrategy';
|
|
5
6
|
/**
|
|
6
7
|
* The `LocalizationProvider` component automatically queries the Storefront API's
|
|
7
8
|
* [`localization`](/api/storefront/reference/common-objects/queryroot) field
|
|
@@ -11,10 +12,11 @@ import { Localization } from '../../graphql/graphql-constants';
|
|
|
11
12
|
* The `isoCode` of the `country` can be used in the Storefront API's
|
|
12
13
|
* `@inContext` directive as the `country` value.
|
|
13
14
|
*/
|
|
14
|
-
export function LocalizationProvider(
|
|
15
|
+
export function LocalizationProvider(props) {
|
|
15
16
|
const { data: { localization }, } = useShopQuery({
|
|
16
17
|
query: Localization,
|
|
17
|
-
cache:
|
|
18
|
+
cache: CacheDays(),
|
|
19
|
+
preload: props.preload,
|
|
18
20
|
});
|
|
19
|
-
return (React.createElement(LocalizationClientProvider, { localization: localization }, children));
|
|
21
|
+
return (React.createElement(LocalizationClientProvider, { localization: localization }, props.children));
|
|
20
22
|
}
|
|
@@ -4,13 +4,15 @@ import { ExternalVideoProps } from '../ExternalVideo';
|
|
|
4
4
|
import { ModelViewerProps } from '../ModelViewer';
|
|
5
5
|
import { Media as MediaType } from '../../graphql/types/types';
|
|
6
6
|
export declare type Media = Pick<MediaType, 'mediaContentType'>;
|
|
7
|
-
declare type MediaImageMedia = Media &
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
declare type
|
|
7
|
+
declare type MediaImageMedia = Media & {
|
|
8
|
+
image: MediaImageProps['data'];
|
|
9
|
+
};
|
|
10
|
+
declare type ModelViewerMedia = Media & ModelViewerProps['data'];
|
|
11
|
+
declare type ExternalVideoMedia = Media & ExternalVideoProps['data'];
|
|
12
|
+
declare type VideoMedia = Media & VideoProps['data'];
|
|
11
13
|
export interface MediaFileProps {
|
|
12
14
|
/** A [Media object](/api/storefront/reference/products/media). */
|
|
13
|
-
|
|
15
|
+
data: MediaImageMedia | ModelViewerMedia | ExternalVideoMedia | VideoMedia;
|
|
14
16
|
/** The options for the `Image`, `Video`, `ExternalVideo`, or `ModelViewer` components. */
|
|
15
17
|
options?: VideoProps['options'] | ExternalVideoProps['options'];
|
|
16
18
|
}
|
|
@@ -20,7 +22,7 @@ export interface MediaFileProps {
|
|
|
20
22
|
* `Video`, an `ExternalVideo`, or a `ModelViewer` depending on the `mediaContentType` of the
|
|
21
23
|
* `media` provided as a prop.
|
|
22
24
|
*/
|
|
23
|
-
export declare function MediaFile({
|
|
25
|
+
export declare function MediaFile({ data, options, ...passthroughProps }: MediaFileProps): JSX.Element | null;
|
|
24
26
|
export declare namespace MediaFile {
|
|
25
27
|
var Fragment: string;
|
|
26
28
|
}
|
|
@@ -10,17 +10,17 @@ import { MediaFileFragment as Fragment } from '../../graphql/graphql-constants';
|
|
|
10
10
|
* `Video`, an `ExternalVideo`, or a `ModelViewer` depending on the `mediaContentType` of the
|
|
11
11
|
* `media` provided as a prop.
|
|
12
12
|
*/
|
|
13
|
-
export function MediaFile({
|
|
14
|
-
switch (
|
|
13
|
+
export function MediaFile({ data, options, ...passthroughProps }) {
|
|
14
|
+
switch (data.mediaContentType) {
|
|
15
15
|
case 'IMAGE': {
|
|
16
|
-
return (React.createElement(Image, { ...passthroughProps,
|
|
16
|
+
return (React.createElement(Image, { ...passthroughProps, data: data.image, options: options }));
|
|
17
17
|
}
|
|
18
18
|
case 'VIDEO':
|
|
19
|
-
return (React.createElement(Video, { ...passthroughProps,
|
|
19
|
+
return (React.createElement(Video, { ...passthroughProps, data: data, options: options }));
|
|
20
20
|
case 'EXTERNAL_VIDEO':
|
|
21
|
-
return (React.createElement(ExternalVideo, { ...passthroughProps,
|
|
21
|
+
return (React.createElement(ExternalVideo, { ...passthroughProps, data: data, options: options }));
|
|
22
22
|
case 'MODEL_3D':
|
|
23
|
-
return (React.createElement(ModelViewer, { ...passthroughProps,
|
|
23
|
+
return (React.createElement(ModelViewer, { ...passthroughProps, data: data }));
|
|
24
24
|
default:
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
@@ -3,7 +3,7 @@ import { Props } from '../types';
|
|
|
3
3
|
import { ParsedMetafield } from '../../types';
|
|
4
4
|
export interface MetafieldProps {
|
|
5
5
|
/** A [Metafield object](/api/storefront/reference/common-objects/metafield) from the Storefront API. */
|
|
6
|
-
|
|
6
|
+
data: ParsedMetafield;
|
|
7
7
|
/** An HTML tag to be rendered as the base element wrapper. The default value varies depending on [metafield.type](/apps/metafields/types). */
|
|
8
8
|
as?: ElementType;
|
|
9
9
|
}
|
|
@@ -13,51 +13,51 @@ import { Image } from '../Image';
|
|
|
13
13
|
*/
|
|
14
14
|
export function Metafield(props) {
|
|
15
15
|
var _a;
|
|
16
|
-
const {
|
|
16
|
+
const { data, children, as, ...passthroughProps } = props;
|
|
17
17
|
const { locale } = useShop();
|
|
18
|
-
if (
|
|
19
|
-
console.warn(`No metafield value for ${
|
|
18
|
+
if (data.value == null) {
|
|
19
|
+
console.warn(`No metafield value for ${data}`);
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
|
-
switch (
|
|
22
|
+
switch (data.type) {
|
|
23
23
|
case 'date': {
|
|
24
24
|
const Wrapper = as !== null && as !== void 0 ? as : 'time';
|
|
25
|
-
return (React.createElement(Wrapper, { ...passthroughProps },
|
|
25
|
+
return (React.createElement(Wrapper, { ...passthroughProps }, data.value.toLocaleDateString(locale)));
|
|
26
26
|
}
|
|
27
27
|
case 'date_time': {
|
|
28
28
|
const Wrapper = as !== null && as !== void 0 ? as : 'time';
|
|
29
|
-
return (React.createElement(Wrapper, { ...passthroughProps },
|
|
29
|
+
return (React.createElement(Wrapper, { ...passthroughProps }, data.value.toLocaleString(locale)));
|
|
30
30
|
}
|
|
31
31
|
case 'weight':
|
|
32
32
|
case 'dimension':
|
|
33
33
|
case 'volume': {
|
|
34
34
|
const Wrapper = as !== null && as !== void 0 ? as : 'span';
|
|
35
|
-
return (React.createElement(Wrapper, { ...passthroughProps }, getMeasurementAsString(
|
|
35
|
+
return (React.createElement(Wrapper, { ...passthroughProps }, getMeasurementAsString(data.value, locale)));
|
|
36
36
|
}
|
|
37
37
|
case 'rating': {
|
|
38
38
|
const Wrapper = as !== null && as !== void 0 ? as : 'span';
|
|
39
|
-
return (React.createElement(Wrapper, { ...passthroughProps },
|
|
39
|
+
return (React.createElement(Wrapper, { ...passthroughProps }, data.value.value));
|
|
40
40
|
}
|
|
41
41
|
case 'single_line_text_field': {
|
|
42
|
-
return (React.createElement(RawHtml, { ...passthroughProps, as: as !== null && as !== void 0 ? as : 'span', string:
|
|
42
|
+
return (React.createElement(RawHtml, { ...passthroughProps, as: as !== null && as !== void 0 ? as : 'span', string: data.value }));
|
|
43
43
|
}
|
|
44
44
|
case 'multi_line_text_field': {
|
|
45
|
-
return (React.createElement(RawHtml, { ...passthroughProps, as: as !== null && as !== void 0 ? as : 'span', string:
|
|
45
|
+
return (React.createElement(RawHtml, { ...passthroughProps, as: as !== null && as !== void 0 ? as : 'span', string: data.value.split('\n').join('<br/>') }));
|
|
46
46
|
}
|
|
47
47
|
case 'url':
|
|
48
|
-
return (React.createElement("a", { href:
|
|
48
|
+
return (React.createElement("a", { href: data.value, ...passthroughProps }, data.value));
|
|
49
49
|
case 'json':
|
|
50
50
|
const Wrapper = as !== null && as !== void 0 ? as : 'span';
|
|
51
|
-
return (React.createElement(Wrapper, { ...passthroughProps }, JSON.stringify(
|
|
51
|
+
return (React.createElement(Wrapper, { ...passthroughProps }, JSON.stringify(data.value)));
|
|
52
52
|
case 'file_reference': {
|
|
53
|
-
if (((_a =
|
|
54
|
-
const ref =
|
|
55
|
-
return ref.
|
|
53
|
+
if (((_a = data.reference) === null || _a === void 0 ? void 0 : _a.__typename) === 'MediaImage') {
|
|
54
|
+
const ref = data.reference;
|
|
55
|
+
return ref.data ? (React.createElement(Image, { data: ref.data, ...passthroughProps })) : null;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
default: {
|
|
59
59
|
const Wrapper = as !== null && as !== void 0 ? as : 'span';
|
|
60
|
-
return
|
|
60
|
+
return React.createElement(Wrapper, { ...passthroughProps }, data.value.toString());
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -5,7 +5,7 @@ export interface ModelViewerProps {
|
|
|
5
5
|
/** Any ReactNode elements. */
|
|
6
6
|
children?: ReactNode;
|
|
7
7
|
/** An object with the same fields as the [GraphQL fragment](#graphql-fragment). */
|
|
8
|
-
|
|
8
|
+
data: {
|
|
9
9
|
id?: Model3DType['id'];
|
|
10
10
|
alt: Model3DType['alt'];
|
|
11
11
|
previewImage?: Pick<Image, 'url'>;
|
|
@@ -11,7 +11,7 @@ export function ModelViewer(props) {
|
|
|
11
11
|
const callbackRef = useCallback((node) => {
|
|
12
12
|
setModelViewer(node);
|
|
13
13
|
}, []);
|
|
14
|
-
const { model, id = model.id, children, className, ...passthroughProps } = props;
|
|
14
|
+
const { data: model, id = model.id, children, className, ...passthroughProps } = props;
|
|
15
15
|
const modelViewerLoadedStatus = useLoadScript('https://unpkg.com/@google/model-viewer@v1.8.0/dist/model-viewer.min.js', {
|
|
16
16
|
module: true,
|
|
17
17
|
});
|
|
@@ -5,7 +5,7 @@ export interface MoneyProps {
|
|
|
5
5
|
/** An HTML tag to be rendered as the base element wrapper. The default is `div`. */
|
|
6
6
|
as?: ElementType;
|
|
7
7
|
/** A [`MoneyV2` object](/api/storefront/reference/common-objects/moneyv2). */
|
|
8
|
-
|
|
8
|
+
data: MoneyV2;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* The `Money` component renders a string of the Storefront API's
|
|
@@ -7,8 +7,8 @@ import { MoneyFragment as Fragment } from '../../graphql/graphql-constants';
|
|
|
7
7
|
* `defaultLocale` in the `shopify.config.js` file.
|
|
8
8
|
*/
|
|
9
9
|
export function Money(props) {
|
|
10
|
-
const {
|
|
11
|
-
const moneyObject = useMoney(
|
|
10
|
+
const { data, as, ...passthroughProps } = props;
|
|
11
|
+
const moneyObject = useMoney(data);
|
|
12
12
|
const Wrapper = as !== null && as !== void 0 ? as : 'div';
|
|
13
13
|
return React.createElement(Wrapper, { ...passthroughProps }, moneyObject.localizedString);
|
|
14
14
|
}
|
|
@@ -10,10 +10,12 @@ export interface ProductMetafieldProps extends Omit<MetafieldProps, 'metafield'>
|
|
|
10
10
|
* product's metafield.
|
|
11
11
|
*/
|
|
12
12
|
namespace: string;
|
|
13
|
+
/** The ID of the variant. If provided, then use the metafield corresponding to the variant ID instead of the product's metafield. */
|
|
14
|
+
variantId?: string;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* The `ProductMetafield` component renders a
|
|
16
18
|
* [`Metafield`](/api/hydrogen/components/primitive/metafield) component with the product metafield.
|
|
17
19
|
* It must be a descendent of a `ProductProvider` component.
|
|
18
20
|
*/
|
|
19
|
-
export declare function ProductMetafield<TTag extends ElementType>(props: Props<TTag> & ProductMetafieldProps): JSX.Element | null;
|
|
21
|
+
export declare function ProductMetafield<TTag extends ElementType>(props: Props<TTag> & Omit<ProductMetafieldProps, 'data'>): JSX.Element | null;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Metafield } from '../Metafield';
|
|
3
3
|
import { useProduct } from '../../hooks/useProduct/useProduct';
|
|
4
|
+
import { flattenConnection } from '../../utilities';
|
|
4
5
|
/**
|
|
5
6
|
* The `ProductMetafield` component renders a
|
|
6
7
|
* [`Metafield`](/api/hydrogen/components/primitive/metafield) component with the product metafield.
|
|
7
8
|
* It must be a descendent of a `ProductProvider` component.
|
|
8
9
|
*/
|
|
9
10
|
export function ProductMetafield(props) {
|
|
11
|
+
var _a, _b, _c;
|
|
10
12
|
const product = useProduct();
|
|
11
13
|
if (product == null) {
|
|
12
14
|
throw new Error('Expected a ProductProvider context, but none was found');
|
|
@@ -15,11 +17,26 @@ export function ProductMetafield(props) {
|
|
|
15
17
|
console.warn('No metafields available for product');
|
|
16
18
|
return null;
|
|
17
19
|
}
|
|
18
|
-
const { namespace, keyName, ...passthroughProps } = props;
|
|
19
|
-
const
|
|
20
|
+
const { namespace, keyName, variantId, ...passthroughProps } = props;
|
|
21
|
+
const metafields = variantId
|
|
22
|
+
? flattenConnection((_c = (_b = (_a = product.variants) === null || _a === void 0 ? void 0 : _a.find(({ id }) => id === variantId)) === null || _b === void 0 ? void 0 : _b.metafields) !== null && _c !== void 0 ? _c : {})
|
|
23
|
+
: product.metafields;
|
|
24
|
+
const field = metafields === null || metafields === void 0 ? void 0 : metafields.find((metafield) => metafield.namespace === namespace && metafield.key === keyName);
|
|
20
25
|
if (field === null || field === undefined) {
|
|
21
|
-
|
|
26
|
+
const message = 'does not have a value for metafield.';
|
|
27
|
+
const productOrVariant = variantId ? `Variant` : 'Product';
|
|
28
|
+
const logItems = {
|
|
29
|
+
variantId: variantId,
|
|
30
|
+
ProductId: product.id,
|
|
31
|
+
namespace,
|
|
32
|
+
keyName,
|
|
33
|
+
};
|
|
34
|
+
console.warn([
|
|
35
|
+
productOrVariant,
|
|
36
|
+
message,
|
|
37
|
+
...Object.entries(logItems).map(([key, val]) => `${key}: ${val}`),
|
|
38
|
+
].join(' '));
|
|
22
39
|
return null;
|
|
23
40
|
}
|
|
24
|
-
return React.createElement(Metafield, {
|
|
41
|
+
return React.createElement(Metafield, { data: field, ...passthroughProps });
|
|
25
42
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ElementType } from 'react';
|
|
2
2
|
import { MoneyProps } from '../Money';
|
|
3
3
|
import { Props } from '../types';
|
|
4
|
-
export interface ProductPriceProps extends Omit<MoneyProps, '
|
|
4
|
+
export interface ProductPriceProps extends Omit<MoneyProps, 'data'> {
|
|
5
5
|
/** The type of price. Valid values: `regular` (default) or `compareAt`. */
|
|
6
6
|
priceType?: 'regular' | 'compareAt';
|
|
7
|
-
/** The type of value. Valid values: `min` (default) or `
|
|
8
|
-
valueType?: 'max' | 'min';
|
|
7
|
+
/** The type of value. Valid values: `min` (default), `max` or `unit`. */
|
|
8
|
+
valueType?: 'max' | 'min' | 'unit';
|
|
9
|
+
/** The ID of the variant. */
|
|
10
|
+
variantId?: string;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* The `ProductPrice` component renders a `Money` component with the product
|
|
@@ -1,36 +1,57 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Money } from '../Money';
|
|
3
3
|
import { useProduct } from '../ProductProvider';
|
|
4
|
+
import { UnitPrice } from '../UnitPrice';
|
|
4
5
|
/**
|
|
5
6
|
* The `ProductPrice` component renders a `Money` component with the product
|
|
6
7
|
* [`priceRange`](/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range. It must be a descendent of the `ProductProvider` component.
|
|
7
8
|
*/
|
|
8
9
|
export function ProductPrice(props) {
|
|
9
|
-
var _a, _b, _c, _d;
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
10
11
|
const product = useProduct();
|
|
11
|
-
const { priceType = 'regular', valueType = 'min', ...passthroughProps } = props;
|
|
12
|
+
const { priceType = 'regular', variantId, valueType = 'min', ...passthroughProps } = props;
|
|
12
13
|
if (product == null) {
|
|
13
14
|
throw new Error('Expected a ProductProvider context, but none was found');
|
|
14
15
|
}
|
|
15
16
|
let price;
|
|
17
|
+
let measurement;
|
|
18
|
+
const variant = variantId
|
|
19
|
+
? (_a = product === null || product === void 0 ? void 0 : product.variants) === null || _a === void 0 ? void 0 : _a.find((variant) => variant.id === variantId)
|
|
20
|
+
: null;
|
|
16
21
|
if (priceType === 'compareAt') {
|
|
17
|
-
if (
|
|
18
|
-
|
|
22
|
+
if (variantId && variant) {
|
|
23
|
+
if (((_b = variant.compareAtPriceV2) === null || _b === void 0 ? void 0 : _b.amount) === ((_c = variant.priceV2) === null || _c === void 0 ? void 0 : _c.amount)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
price = variant.compareAtPriceV2;
|
|
27
|
+
}
|
|
28
|
+
else if (valueType === 'max') {
|
|
29
|
+
price = (_d = product === null || product === void 0 ? void 0 : product.compareAtPriceRange) === null || _d === void 0 ? void 0 : _d.maxVariantPrice;
|
|
19
30
|
}
|
|
20
31
|
else {
|
|
21
|
-
price = (
|
|
32
|
+
price = (_e = product === null || product === void 0 ? void 0 : product.compareAtPriceRange) === null || _e === void 0 ? void 0 : _e.minVariantPrice;
|
|
22
33
|
}
|
|
23
34
|
}
|
|
24
35
|
else {
|
|
25
|
-
if (
|
|
26
|
-
price =
|
|
36
|
+
if (variantId && variant) {
|
|
37
|
+
price = variant.priceV2;
|
|
38
|
+
if (valueType === 'unit') {
|
|
39
|
+
price = variant.unitPrice;
|
|
40
|
+
measurement = variant.unitPriceMeasurement;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (valueType === 'max') {
|
|
44
|
+
price = (_f = product.priceRange) === null || _f === void 0 ? void 0 : _f.maxVariantPrice;
|
|
27
45
|
}
|
|
28
46
|
else {
|
|
29
|
-
price = (
|
|
47
|
+
price = (_g = product.priceRange) === null || _g === void 0 ? void 0 : _g.minVariantPrice;
|
|
30
48
|
}
|
|
31
49
|
}
|
|
32
50
|
if (price == null) {
|
|
33
51
|
return null;
|
|
34
52
|
}
|
|
35
|
-
|
|
53
|
+
if (measurement) {
|
|
54
|
+
return (React.createElement(UnitPrice, { ...passthroughProps, data: price, measurement: measurement }));
|
|
55
|
+
}
|
|
56
|
+
return React.createElement(Money, { ...passthroughProps, data: price });
|
|
36
57
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ProductProviderProps } from './ProductProvider.client';
|
|
3
|
+
interface ProductOptionsProviderProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
initialVariantId: ProductProviderProps['initialVariantId'];
|
|
6
|
+
}
|
|
7
|
+
export declare function ProductOptionsProvider({ children, initialVariantId, }: ProductOptionsProviderProps): JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ProductOptionsContext } from './context';
|
|
3
|
+
import { useProductOptions } from '../../hooks';
|
|
4
|
+
import { useProduct } from '../../hooks/useProduct';
|
|
5
|
+
export function ProductOptionsProvider({ children, initialVariantId, }) {
|
|
6
|
+
const product = useProduct();
|
|
7
|
+
const productOptions = useProductOptions({
|
|
8
|
+
variants: product.variantsConnection,
|
|
9
|
+
initialVariantId: initialVariantId,
|
|
10
|
+
});
|
|
11
|
+
return (React.createElement(ProductOptionsContext.Provider, { value: productOptions }, children));
|
|
12
|
+
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { useProductOptions } from '../../hooks';
|
|
3
3
|
import { Product } from './types';
|
|
4
|
-
|
|
5
|
-
* The `ProductProvider` component sets up a context with product details. Descendents of
|
|
6
|
-
* this component can use the `useProduct` hook and the related `ProductX` or `SelectedVariantX` hooks.
|
|
7
|
-
*/
|
|
8
|
-
export declare function ProductProvider({ children, product, initialVariantId, }: {
|
|
4
|
+
export interface ProductProviderProps {
|
|
9
5
|
/** A `ReactNode` element. */
|
|
10
6
|
children: ReactNode;
|
|
11
7
|
/** A [Product object](/api/storefront/reference/products/product). */
|
|
12
|
-
|
|
8
|
+
data: Product;
|
|
13
9
|
/** The initially selected variant. This is required only if you're using a `SelectedVariantX` hook in the `ProductProvider` component.*/
|
|
14
10
|
initialVariantId?: Parameters<typeof useProductOptions>['0']['initialVariantId'];
|
|
15
|
-
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The `ProductProvider` component sets up a context with product details. Descendents of
|
|
14
|
+
* this component can use the `useProduct` hook and the related `ProductX` or `SelectedVariantX` hooks.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ProductProvider({ children, data: product, initialVariantId, }: ProductProviderProps): JSX.Element;
|
|
16
17
|
export declare namespace ProductProvider {
|
|
17
18
|
var Fragment: string;
|
|
18
19
|
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useParsedMetafields } from '../../hooks';
|
|
3
3
|
import { flattenConnection } from '../../utilities';
|
|
4
4
|
import { ProductContext } from './context';
|
|
5
5
|
import { ProductProviderFragment as Fragment } from '../../graphql/graphql-constants';
|
|
6
|
+
import { ProductOptionsProvider } from './ProductOptionsProvider.client';
|
|
6
7
|
/**
|
|
7
8
|
* The `ProductProvider` component sets up a context with product details. Descendents of
|
|
8
9
|
* this component can use the `useProduct` hook and the related `ProductX` or `SelectedVariantX` hooks.
|
|
9
10
|
*/
|
|
10
|
-
export function ProductProvider({ children, product, initialVariantId, }) {
|
|
11
|
-
const { variants, options, selectedVariant, setSelectedVariant, selectedOptions, setSelectedOption, setSelectedOptions, isOptionInStock, selectedSellingPlan, selectedSellingPlanAllocation, setSelectedSellingPlan, sellingPlanGroups, } = useProductOptions({
|
|
12
|
-
variants: product.variants,
|
|
13
|
-
initialVariantId: initialVariantId,
|
|
14
|
-
});
|
|
11
|
+
export function ProductProvider({ children, data: product, initialVariantId, }) {
|
|
15
12
|
const metafields = useParsedMetafields(product.metafields);
|
|
16
13
|
const providerValue = useMemo(() => {
|
|
17
14
|
return {
|
|
@@ -20,7 +17,9 @@ export function ProductProvider({ children, product, initialVariantId, }) {
|
|
|
20
17
|
metafieldsConnection: product.metafields,
|
|
21
18
|
media: product.media ? flattenConnection(product.media) : undefined,
|
|
22
19
|
mediaConnection: product.media,
|
|
23
|
-
variants: variants
|
|
20
|
+
variants: product.variants
|
|
21
|
+
? flattenConnection(product.variants)
|
|
22
|
+
: undefined,
|
|
24
23
|
variantsConnection: product.variants,
|
|
25
24
|
images: product.images ? flattenConnection(product.images) : undefined,
|
|
26
25
|
imagesConnection: product.images,
|
|
@@ -28,35 +27,10 @@ export function ProductProvider({ children, product, initialVariantId, }) {
|
|
|
28
27
|
? flattenConnection(product.collections)
|
|
29
28
|
: undefined,
|
|
30
29
|
collectionsConnection: product.collections,
|
|
31
|
-
options,
|
|
32
|
-
selectedVariant,
|
|
33
|
-
setSelectedVariant,
|
|
34
|
-
selectedOptions,
|
|
35
|
-
setSelectedOption,
|
|
36
|
-
setSelectedOptions,
|
|
37
|
-
isOptionInStock,
|
|
38
|
-
selectedSellingPlan,
|
|
39
|
-
selectedSellingPlanAllocation,
|
|
40
|
-
setSelectedSellingPlan,
|
|
41
|
-
sellingPlanGroups,
|
|
42
30
|
};
|
|
43
|
-
}, [
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
options,
|
|
47
|
-
product,
|
|
48
|
-
selectedOptions,
|
|
49
|
-
selectedSellingPlan,
|
|
50
|
-
selectedSellingPlanAllocation,
|
|
51
|
-
selectedVariant,
|
|
52
|
-
sellingPlanGroups,
|
|
53
|
-
setSelectedOption,
|
|
54
|
-
setSelectedOptions,
|
|
55
|
-
setSelectedSellingPlan,
|
|
56
|
-
setSelectedVariant,
|
|
57
|
-
variants,
|
|
58
|
-
]);
|
|
59
|
-
return (React.createElement(ProductContext.Provider, { value: providerValue }, children));
|
|
31
|
+
}, [metafields, product]);
|
|
32
|
+
return (React.createElement(ProductContext.Provider, { value: providerValue },
|
|
33
|
+
React.createElement(ProductOptionsProvider, { initialVariantId: initialVariantId }, children)));
|
|
60
34
|
}
|
|
61
35
|
ProductProvider.Fragment = Fragment;
|
|
62
36
|
export const ProductProviderFragment = Fragment;
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { ProductOptionsHookValue } from '../../hooks';
|
|
2
|
-
import {
|
|
2
|
+
import { ParsedMetafield } from '../../types';
|
|
3
3
|
import { ProductProviderFragmentFragment } from './ProductProviderFragment';
|
|
4
4
|
import { Product } from './types';
|
|
5
5
|
import { Collection, Image } from '../../graphql/types/types';
|
|
6
|
+
import type { Variant } from '../../hooks/useProductOptions';
|
|
6
7
|
export declare const ProductContext: import("react").Context<ProductContextType | null>;
|
|
7
|
-
export declare type ProductContextType = Omit<Product, 'media' | 'metafields' | 'images' | 'collections' | 'variants' | 'sellingPlanGroups' | 'options'> &
|
|
8
|
+
export declare type ProductContextType = Omit<Product, 'media' | 'metafields' | 'images' | 'collections' | 'variants' | 'sellingPlanGroups' | 'options'> & {
|
|
8
9
|
media?: ProductProviderFragmentFragment['media']['edges'][0]['node'][];
|
|
9
|
-
mediaConnection?:
|
|
10
|
+
mediaConnection?: Product['media'];
|
|
10
11
|
metafields?: ParsedMetafield[];
|
|
11
|
-
metafieldsConnection?:
|
|
12
|
+
metafieldsConnection?: Product['metafields'];
|
|
12
13
|
images?: Partial<Image>[];
|
|
13
|
-
imagesConnection?:
|
|
14
|
+
imagesConnection?: Product['images'];
|
|
14
15
|
collections?: Partial<Collection>[];
|
|
15
|
-
collectionsConnection?:
|
|
16
|
+
collectionsConnection?: Product['collections'];
|
|
17
|
+
variants?: Partial<Variant>[];
|
|
18
|
+
variantsConnection?: Product['variants'];
|
|
16
19
|
};
|
|
20
|
+
export declare const ProductOptionsContext: import("react").Context<ProductOptionsHookValue | null>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useShop } from '../../foundation';
|
|
3
|
-
import {
|
|
3
|
+
import { Head } from '../../client';
|
|
4
4
|
import { TitleSeo } from './TitleSeo.client';
|
|
5
5
|
import { DescriptionSeo } from './DescriptionSeo.client';
|
|
6
6
|
import { TwitterSeo } from './TwitterSeo.client';
|
|
@@ -8,7 +8,7 @@ export function DefaultPageSeo({ title, description, url, titleTemplate, lang, }
|
|
|
8
8
|
const { locale } = useShop();
|
|
9
9
|
const fallBacklang = locale.split(/[-_]/)[0];
|
|
10
10
|
return (React.createElement(React.Fragment, null,
|
|
11
|
-
React.createElement(
|
|
11
|
+
React.createElement(Head, { defaultTitle: title, titleTemplate: titleTemplate !== null && titleTemplate !== void 0 ? titleTemplate : `%s - ${title}` },
|
|
12
12
|
React.createElement("html", { lang: lang !== null && lang !== void 0 ? lang : fallBacklang }),
|
|
13
13
|
React.createElement("meta", { property: "og:type", content: "website" }),
|
|
14
14
|
React.createElement("meta", { property: "og:site_name", content: title }),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Head } from '../../client';
|
|
3
3
|
export function DescriptionSeo({ description }) {
|
|
4
4
|
if (!description) {
|
|
5
5
|
return null;
|
|
6
6
|
}
|
|
7
|
-
return (React.createElement(
|
|
7
|
+
return (React.createElement(Head, null,
|
|
8
8
|
React.createElement("meta", { name: "description", content: description }),
|
|
9
9
|
React.createElement("meta", { property: "og:description", content: description })));
|
|
10
10
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Head } from '../../client';
|
|
3
3
|
import { TitleSeo } from './TitleSeo.client';
|
|
4
4
|
import { DescriptionSeo } from './DescriptionSeo.client';
|
|
5
5
|
export function HomePageSeo({ title, description, url }) {
|
|
@@ -16,7 +16,7 @@ export function HomePageSeo({ title, description, url }) {
|
|
|
16
16
|
url,
|
|
17
17
|
};
|
|
18
18
|
return (React.createElement(React.Fragment, null,
|
|
19
|
-
React.createElement(
|
|
19
|
+
React.createElement(Head, null,
|
|
20
20
|
React.createElement("meta", { property: "og:url", content: url }),
|
|
21
21
|
React.createElement("script", { type: "application/ld+json" }, JSON.stringify(organizationSchema)),
|
|
22
22
|
React.createElement("script", { type: "application/ld+json" }, JSON.stringify(webSiteSchema))),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Head } from '../../client';
|
|
3
3
|
export function ImageSeo({ url, width, height, altText }) {
|
|
4
|
-
return (React.createElement(
|
|
4
|
+
return (React.createElement(Head, null,
|
|
5
5
|
url && React.createElement("meta", { property: "og:image", content: url }),
|
|
6
6
|
url && React.createElement("meta", { property: "og:image:secure_url", content: url }),
|
|
7
7
|
width && React.createElement("meta", { property: "og:image:width", content: `${width}` }),
|