@shopify/hydrogen 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/esnext/components/CartLineImage/CartLineImage.client.d.ts +1 -1
- package/dist/esnext/components/CartLineImage/CartLineImage.client.js +1 -1
- package/dist/esnext/components/CartLineProvider/context.d.ts +1 -1
- package/dist/esnext/components/CartLineProvider/index.d.ts +1 -1
- package/dist/esnext/components/CartLineProvider/index.js +1 -1
- package/dist/esnext/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.js +3 -2
- package/dist/esnext/components/CartProvider/CartProvider.client.js +52 -23
- package/dist/esnext/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartCreateMutation.d.ts +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartLineAddMutation.d.ts +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartQuery.d.ts +1 -0
- package/dist/esnext/components/CartProvider/hooks.d.ts +0 -11
- package/dist/esnext/components/CartProvider/hooks.js +0 -54
- package/dist/esnext/components/CartProvider/index.d.ts +12 -1
- package/dist/esnext/components/CartProvider/index.js +12 -1
- package/dist/esnext/components/Image/Image.d.ts +2 -2
- package/dist/esnext/components/Image/Image.js +1 -1
- package/dist/esnext/components/Image/ImageFragment.d.ts +1 -1
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +1 -1
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +5 -2
- package/dist/esnext/components/LocalizationProvider/index.d.ts +2 -1
- package/dist/esnext/components/LocalizationProvider/index.js +2 -1
- package/dist/esnext/components/Model3D/Model3D.client.d.ts +1 -1
- package/dist/esnext/components/Model3D/Model3D.client.js +2 -2
- package/dist/esnext/components/Model3D/Model3DFragment.d.ts +1 -1
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.d.ts +1 -1
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +1 -1
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.js +1 -1
- package/dist/esnext/components/SelectedVariantBuyNowButton/SelectedVariantBuyNowButton.js +1 -1
- package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.d.ts +1 -1
- package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.js +1 -1
- package/dist/esnext/components/Video/Video.d.ts +1 -1
- package/dist/esnext/components/Video/Video.js +1 -1
- package/dist/esnext/components/Video/VideoFragment.d.ts +1 -1
- package/dist/esnext/components/index.d.ts +2 -1
- package/dist/esnext/components/index.js +2 -1
- package/dist/esnext/entry-client.js +2 -1
- package/dist/esnext/entry-server.js +12 -5
- package/dist/esnext/foundation/Router/ServerStateRouter.client.js +1 -1
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +2 -1
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.d.ts +1 -1
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.js +1 -1
- package/dist/esnext/foundation/useServerState/use-server-state.d.ts +1 -1
- package/dist/esnext/foundation/useServerState/use-server-state.js +1 -1
- package/dist/esnext/framework/Hydration/react-utils.js +1 -1
- package/dist/esnext/framework/cache.js +4 -2
- package/dist/esnext/framework/config.d.ts +6 -0
- package/dist/esnext/framework/config.js +6 -0
- package/dist/esnext/framework/runtime.d.ts +2 -2
- package/dist/esnext/framework/runtime.js +4 -3
- package/dist/esnext/graphql/graphql-constants.d.ts +31 -30
- package/dist/esnext/graphql/graphql-constants.js +62 -60
- package/dist/esnext/graphql/types/types.d.ts +234 -56
- package/dist/esnext/graphql/types/types.js +22 -0
- package/dist/esnext/handle-event.js +64 -71
- package/dist/esnext/hooks/useAvailableCountries/index.d.ts +1 -0
- package/dist/esnext/hooks/useAvailableCountries/index.js +1 -0
- package/dist/esnext/hooks/useAvailableCountries/useAvailableCountries.d.ts +11 -0
- package/dist/esnext/{components/LocalizationProvider/hooks.js → hooks/useAvailableCountries/useAvailableCountries.js} +5 -5
- package/dist/esnext/hooks/useCart/index.d.ts +1 -0
- package/dist/esnext/hooks/useCart/index.js +1 -0
- package/dist/esnext/hooks/useCart/useCart.d.ts +4 -0
- package/dist/esnext/hooks/useCart/useCart.js +12 -0
- package/dist/esnext/hooks/useCartAttributesUpdateCallback/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartAttributesUpdateCallback/index.js +1 -0
- package/dist/esnext/hooks/useCartAttributesUpdateCallback/useCartAttributesUpdateCallback.d.ts +4 -0
- package/dist/esnext/hooks/useCartAttributesUpdateCallback/useCartAttributesUpdateCallback.js +8 -0
- package/dist/esnext/hooks/useCartBuyerIdentityUpdateCallback/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartBuyerIdentityUpdateCallback/index.js +1 -0
- package/dist/esnext/hooks/useCartBuyerIdentityUpdateCallback/useCartBuyerIdentityUpdateCallback.d.ts +4 -0
- package/dist/esnext/hooks/useCartBuyerIdentityUpdateCallback/useCartBuyerIdentityUpdateCallback.js +8 -0
- package/dist/esnext/hooks/useCartCheckoutUrl/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartCheckoutUrl/index.js +1 -0
- package/dist/esnext/hooks/useCartCheckoutUrl/useCartCheckoutUrl.d.ts +4 -0
- package/dist/esnext/hooks/useCartCheckoutUrl/useCartCheckoutUrl.js +8 -0
- package/dist/esnext/hooks/useCartCreateCallback/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartCreateCallback/index.js +1 -0
- package/dist/esnext/hooks/useCartCreateCallback/useCartCreateCallback.d.ts +4 -0
- package/dist/esnext/hooks/useCartCreateCallback/useCartCreateCallback.js +8 -0
- package/dist/esnext/hooks/useCartDiscountCodesUpdateCallback/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartDiscountCodesUpdateCallback/index.js +1 -0
- package/dist/esnext/hooks/useCartDiscountCodesUpdateCallback/useCartDiscountCodesUpdateCallback.d.ts +4 -0
- package/dist/esnext/hooks/useCartDiscountCodesUpdateCallback/useCartDiscountCodesUpdateCallback.js +8 -0
- package/dist/esnext/hooks/useCartLine/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartLine/index.js +1 -0
- package/dist/esnext/{components/CartLineProvider/hooks.d.ts → hooks/useCartLine/useCartLine.d.ts} +7 -2
- package/dist/esnext/{components/CartLineProvider/hooks.js → hooks/useCartLine/useCartLine.js} +4 -1
- package/dist/esnext/hooks/useCartLinesAddCallback/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartLinesAddCallback/index.js +1 -0
- package/dist/esnext/hooks/useCartLinesAddCallback/useCartLinesAddCallback.d.ts +5 -0
- package/dist/esnext/hooks/useCartLinesAddCallback/useCartLinesAddCallback.js +9 -0
- package/dist/esnext/hooks/useCartLinesRemoveCallback/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartLinesRemoveCallback/index.js +1 -0
- package/dist/esnext/hooks/useCartLinesRemoveCallback/useCartLinesRemoveCallback.d.ts +4 -0
- package/dist/esnext/hooks/useCartLinesRemoveCallback/useCartLinesRemoveCallback.js +8 -0
- package/dist/esnext/hooks/useCartLinesTotalQuantity/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartLinesTotalQuantity/index.js +1 -0
- package/dist/esnext/hooks/useCartLinesTotalQuantity/useCartLinesTotalQuantity.d.ts +4 -0
- package/dist/esnext/hooks/useCartLinesTotalQuantity/useCartLinesTotalQuantity.js +15 -0
- package/dist/esnext/hooks/useCartLinesUpdateCallback/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartLinesUpdateCallback/index.js +1 -0
- package/dist/esnext/hooks/useCartLinesUpdateCallback/useCartLinesUpdateCallback.d.ts +4 -0
- package/dist/esnext/hooks/useCartLinesUpdateCallback/useCartLinesUpdateCallback.js +8 -0
- package/dist/esnext/hooks/useCartNoteUpdateCallback/index.d.ts +1 -0
- package/dist/esnext/hooks/useCartNoteUpdateCallback/index.js +1 -0
- package/dist/esnext/hooks/useCartNoteUpdateCallback/useCartNoteUpdateCallback.d.ts +4 -0
- package/dist/esnext/hooks/useCartNoteUpdateCallback/useCartNoteUpdateCallback.js +8 -0
- package/dist/esnext/hooks/useCountry/index.d.ts +1 -0
- package/dist/esnext/hooks/useCountry/index.js +1 -0
- package/dist/esnext/{components/LocalizationProvider/hooks.d.ts → hooks/useCountry/useCountry.d.ts} +4 -7
- package/dist/esnext/hooks/useCountry/useCountry.js +17 -0
- package/dist/esnext/hooks/useMoney/hooks.js +18 -4
- package/dist/esnext/hooks/useProductOptions/useProductOptions.d.ts +1 -1
- package/dist/esnext/hooks/useProductOptions/useProductOptions.js +1 -1
- package/dist/esnext/hooks/useQuery/hooks.d.ts +9 -7
- package/dist/esnext/hooks/useQuery/hooks.js +15 -5
- package/dist/esnext/hooks/useShopQuery/hooks.d.ts +1 -0
- package/dist/esnext/hooks/useShopQuery/hooks.js +4 -0
- package/dist/esnext/types.d.ts +1 -0
- package/dist/esnext/utilities/error.d.ts +1 -0
- package/dist/esnext/utilities/error.js +15 -0
- package/dist/esnext/utilities/flattenConnection/flattenConnection.d.ts +12 -0
- package/dist/esnext/utilities/flattenConnection/flattenConnection.js +14 -0
- package/dist/esnext/utilities/flattenConnection/index.d.ts +1 -0
- package/dist/esnext/utilities/flattenConnection/index.js +1 -0
- package/dist/esnext/utilities/image_size.d.ts +1 -1
- package/dist/esnext/utilities/index.d.ts +3 -3
- package/dist/esnext/utilities/index.js +3 -3
- package/dist/esnext/utilities/{meaurement.d.ts → measurement.d.ts} +0 -0
- package/dist/esnext/utilities/{meaurement.js → measurement.js} +0 -0
- package/dist/esnext/utilities/{metafields → parseMetafieldValue}/index.d.ts +0 -0
- package/dist/esnext/utilities/{metafields → parseMetafieldValue}/index.js +0 -0
- package/dist/esnext/utilities/{metafields → parseMetafieldValue}/parseMetafieldValue.d.ts +1 -6
- package/dist/esnext/utilities/{metafields → parseMetafieldValue}/parseMetafieldValue.js +1 -6
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +2 -1
- package/dist/node/foundation/ShopifyProvider/ShopifyProvider.d.ts +1 -1
- package/dist/node/foundation/ShopifyProvider/ShopifyProvider.js +1 -1
- package/dist/node/framework/Hydration/react-utils.js +1 -1
- package/dist/node/framework/cache.js +4 -2
- package/dist/node/framework/config.d.ts +6 -0
- package/dist/node/framework/config.js +11 -0
- package/dist/node/framework/runtime.d.ts +2 -2
- package/dist/node/framework/runtime.js +4 -3
- package/dist/node/graphql/types/types.d.ts +234 -56
- package/dist/node/graphql/types/types.js +23 -1
- package/dist/node/handle-event.js +64 -71
- package/dist/node/hooks/useQuery/hooks.d.ts +9 -7
- package/dist/node/hooks/useQuery/hooks.js +15 -5
- package/dist/node/types.d.ts +1 -0
- package/dist/node/utilities/flattenConnection/flattenConnection.d.ts +12 -0
- package/dist/node/utilities/flattenConnection/flattenConnection.js +18 -0
- package/dist/node/utilities/flattenConnection/index.d.ts +1 -0
- package/dist/node/utilities/flattenConnection/index.js +5 -0
- package/dist/node/utilities/image_size.d.ts +1 -1
- package/dist/node/utilities/index.d.ts +3 -3
- package/dist/node/utilities/index.js +7 -7
- package/dist/node/utilities/{meaurement.d.ts → measurement.d.ts} +0 -0
- package/dist/node/utilities/{meaurement.js → measurement.js} +0 -0
- package/dist/node/utilities/{metafields → parseMetafieldValue}/index.d.ts +0 -0
- package/dist/node/utilities/{metafields → parseMetafieldValue}/index.js +0 -0
- package/dist/node/utilities/{metafields → parseMetafieldValue}/parseMetafieldValue.d.ts +1 -6
- package/dist/node/utilities/{metafields → parseMetafieldValue}/parseMetafieldValue.js +1 -6
- package/dist/node/version.d.ts +1 -1
- package/dist/node/version.js +1 -1
- package/dist/worker/framework/cache.js +4 -2
- package/dist/worker/framework/config.d.ts +6 -0
- package/dist/worker/framework/config.js +6 -0
- package/dist/worker/framework/runtime.d.ts +2 -2
- package/dist/worker/framework/runtime.js +4 -3
- package/dist/worker/graphql/types/types.d.ts +234 -56
- package/dist/worker/graphql/types/types.js +22 -0
- package/dist/worker/handle-event.js +64 -71
- package/dist/worker/types.d.ts +1 -0
- package/package.json +2 -2
- package/dist/esnext/utilities/connections.d.ts +0 -2
- package/dist/esnext/utilities/connections.js +0 -4
- package/dist/node/utilities/connections.d.ts +0 -2
- package/dist/node/utilities/connections.js +0 -8
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Hydrogen is a React framework and SDK that you can use to build fast and dynamic Shopify custom storefronts.
|
|
4
4
|
|
|
5
|
-
[Check out the docs](https://shopify.dev/
|
|
5
|
+
[Check out the docs](https://shopify.dev/custom-storefronts/hydrogen)
|
|
6
6
|
|
|
7
7
|
## Getting started
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import { ElementType } from 'react';
|
|
|
2
2
|
import { Props } from '../types';
|
|
3
3
|
import { ImageSizeOptions } from '../../utilities';
|
|
4
4
|
/**
|
|
5
|
-
* The `CartLineImage` component renders
|
|
5
|
+
* The `CartLineImage` component renders an `Image` component for the cart line merchandise's image.
|
|
6
6
|
* It must be a descendent of a `CartLineProvider` component.
|
|
7
7
|
*/
|
|
8
8
|
export declare function CartLineImage<TTag extends ElementType = 'img'>(props: Props<TTag> & {
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { useCartLine } from '../CartLineProvider';
|
|
3
3
|
import { Image as ImageComponent } from '../Image';
|
|
4
4
|
/**
|
|
5
|
-
* The `CartLineImage` component renders
|
|
5
|
+
* The `CartLineImage` component renders an `Image` component for the cart line merchandise's image.
|
|
6
6
|
* It must be a descendent of a `CartLineProvider` component.
|
|
7
7
|
*/
|
|
8
8
|
export function CartLineImage(props) {
|
|
@@ -21,7 +21,7 @@ export declare const CartLineContext: import("react").Context<({
|
|
|
21
21
|
__typename?: "Image" | undefined;
|
|
22
22
|
} & {
|
|
23
23
|
__typename?: "Image" | undefined;
|
|
24
|
-
} & Pick<import("../../graphql/types/types").Image, "height" | "width" | "
|
|
24
|
+
} & Pick<import("../../graphql/types/types").Image, "height" | "width" | "url" | "id" | "altText">> | undefined;
|
|
25
25
|
product: {
|
|
26
26
|
__typename?: "Product" | undefined;
|
|
27
27
|
} & Pick<import("../../graphql/types/types").Product, "title" | "handle">;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { CartLineProvider } from './CartLineProvider.client';
|
|
2
|
-
export { useCartLine } from '
|
|
2
|
+
export { useCartLine } from '../../hooks/useCartLine';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { CartLineProvider } from './CartLineProvider.client';
|
|
2
|
-
export { useCartLine } from '
|
|
2
|
+
export { useCartLine } from '../../hooks/useCartLine';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useCartLinesRemoveCallback, useCartLinesUpdateCallback, } from '../CartProvider';
|
|
2
|
+
import { useCart, useCartLinesRemoveCallback, useCartLinesUpdateCallback, } from '../CartProvider';
|
|
3
3
|
import { useCartLine } from '../CartLineProvider';
|
|
4
4
|
/**
|
|
5
5
|
* The `CartLineQuantityAdjustButton` component renders a button that adjusts the cart line's quantity when pressed.
|
|
@@ -8,9 +8,10 @@ import { useCartLine } from '../CartLineProvider';
|
|
|
8
8
|
export function CartLineQuantityAdjustButton(props) {
|
|
9
9
|
const updateLines = useCartLinesUpdateCallback();
|
|
10
10
|
const removeLines = useCartLinesRemoveCallback();
|
|
11
|
+
const { status } = useCart();
|
|
11
12
|
const cartLine = useCartLine();
|
|
12
13
|
const { children, adjust, ...passthroughProps } = props;
|
|
13
|
-
return (React.createElement("button", { onClick: () => {
|
|
14
|
+
return (React.createElement("button", { disabled: status !== 'idle', onClick: () => {
|
|
14
15
|
if (adjust === 'remove') {
|
|
15
16
|
removeLines([cartLine.id]);
|
|
16
17
|
return;
|
|
@@ -4,6 +4,7 @@ import { CartLineAdd, CartCreate, CartLineRemove, CartLineUpdate, CartNoteUpdate
|
|
|
4
4
|
import { useCartFetch } from './hooks';
|
|
5
5
|
import { CartContext } from './context';
|
|
6
6
|
import { CART_ID_STORAGE_KEY } from './constants';
|
|
7
|
+
import { useServerState } from '../../foundation/useServerState';
|
|
7
8
|
function cartReducer(state, action) {
|
|
8
9
|
switch (action.type) {
|
|
9
10
|
case 'cartFetch': {
|
|
@@ -149,16 +150,23 @@ function cartReducer(state, action) {
|
|
|
149
150
|
* You must use this component if you want to use the `useCart` hook or related hooks, or if you would like to use the `AddToCartButton` component.
|
|
150
151
|
*/
|
|
151
152
|
export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLineRemove, onLineUpdate, onNoteUpdate, onBuyerIdentityUpdate, onAttributesUpdate, onDiscountCodesUpdate, cart, }) {
|
|
153
|
+
var _a;
|
|
154
|
+
const { serverState } = useServerState();
|
|
155
|
+
const countryCode = (_a = serverState === null || serverState === void 0 ? void 0 : serverState.country) === null || _a === void 0 ? void 0 : _a.isoCode;
|
|
152
156
|
const initialStatus = cart
|
|
153
157
|
? { status: 'idle', cart: cartFromGraphQL(cart) }
|
|
154
158
|
: { status: 'uninitialized' };
|
|
155
159
|
const [state, dispatch] = useReducer((state, dispatch) => cartReducer(state, dispatch), initialStatus);
|
|
156
|
-
const
|
|
160
|
+
const fetchCart = useCartFetch();
|
|
157
161
|
const cartFetch = useCallback(async (cartId) => {
|
|
158
162
|
dispatch({ type: 'cartFetch' });
|
|
159
|
-
const { data } = await
|
|
163
|
+
const { data } = await fetchCart({
|
|
160
164
|
query: CartQuery,
|
|
161
|
-
variables: {
|
|
165
|
+
variables: {
|
|
166
|
+
id: cartId,
|
|
167
|
+
numCartLines,
|
|
168
|
+
country: countryCode,
|
|
169
|
+
},
|
|
162
170
|
});
|
|
163
171
|
if (!(data === null || data === void 0 ? void 0 : data.cart)) {
|
|
164
172
|
window.localStorage.removeItem(CART_ID_STORAGE_KEY);
|
|
@@ -166,16 +174,23 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
166
174
|
return;
|
|
167
175
|
}
|
|
168
176
|
dispatch({ type: 'resolve', cart: cartFromGraphQL(data.cart) });
|
|
169
|
-
}, [
|
|
177
|
+
}, [fetchCart, numCartLines, countryCode]);
|
|
170
178
|
const cartCreate = useCallback(async (cart) => {
|
|
171
|
-
var _a;
|
|
179
|
+
var _a, _b;
|
|
172
180
|
dispatch({ type: 'cartCreate' });
|
|
173
181
|
onCreate === null || onCreate === void 0 ? void 0 : onCreate();
|
|
174
|
-
|
|
182
|
+
if (countryCode && !((_a = cart.buyerIdentity) === null || _a === void 0 ? void 0 : _a.countryCode)) {
|
|
183
|
+
if (cart.buyerIdentity == null) {
|
|
184
|
+
cart.buyerIdentity = {};
|
|
185
|
+
}
|
|
186
|
+
cart.buyerIdentity.countryCode = countryCode;
|
|
187
|
+
}
|
|
188
|
+
const { data, error } = await fetchCart({
|
|
175
189
|
query: CartCreate,
|
|
176
190
|
variables: {
|
|
177
191
|
input: cart,
|
|
178
192
|
numCartLines,
|
|
193
|
+
country: countryCode,
|
|
179
194
|
},
|
|
180
195
|
});
|
|
181
196
|
if (error) {
|
|
@@ -184,25 +199,26 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
184
199
|
error: error,
|
|
185
200
|
});
|
|
186
201
|
}
|
|
187
|
-
if ((
|
|
202
|
+
if ((_b = data === null || data === void 0 ? void 0 : data.cartCreate) === null || _b === void 0 ? void 0 : _b.cart) {
|
|
188
203
|
dispatch({
|
|
189
204
|
type: 'resolve',
|
|
190
205
|
cart: cartFromGraphQL(data.cartCreate.cart),
|
|
191
206
|
});
|
|
192
207
|
window.localStorage.setItem(CART_ID_STORAGE_KEY, data.cartCreate.cart.id);
|
|
193
208
|
}
|
|
194
|
-
}, [onCreate,
|
|
209
|
+
}, [onCreate, fetchCart, numCartLines, countryCode]);
|
|
195
210
|
const addLineItem = useCallback(async (lines, state) => {
|
|
196
211
|
var _a;
|
|
197
212
|
if (state.status === 'idle') {
|
|
198
213
|
dispatch({ type: 'addLineItem' });
|
|
199
214
|
onLineAdd === null || onLineAdd === void 0 ? void 0 : onLineAdd();
|
|
200
|
-
const { data, error } = await
|
|
215
|
+
const { data, error } = await fetchCart({
|
|
201
216
|
query: CartLineAdd,
|
|
202
217
|
variables: {
|
|
203
218
|
cartId: state.cart.id,
|
|
204
219
|
lines: lines,
|
|
205
220
|
numCartLines,
|
|
221
|
+
country: countryCode,
|
|
206
222
|
},
|
|
207
223
|
});
|
|
208
224
|
if (error) {
|
|
@@ -218,18 +234,19 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
218
234
|
});
|
|
219
235
|
}
|
|
220
236
|
}
|
|
221
|
-
}, [
|
|
237
|
+
}, [fetchCart, numCartLines, onLineAdd, countryCode]);
|
|
222
238
|
const removeLineItem = useCallback(async (lines, state) => {
|
|
223
239
|
var _a;
|
|
224
240
|
if (state.status === 'idle') {
|
|
225
241
|
dispatch({ type: 'removeLineItem', lines });
|
|
226
242
|
onLineRemove === null || onLineRemove === void 0 ? void 0 : onLineRemove();
|
|
227
|
-
const { data, error } = await
|
|
243
|
+
const { data, error } = await fetchCart({
|
|
228
244
|
query: CartLineRemove,
|
|
229
245
|
variables: {
|
|
230
246
|
cartId: state.cart.id,
|
|
231
247
|
lines: lines,
|
|
232
248
|
numCartLines,
|
|
249
|
+
country: countryCode,
|
|
233
250
|
},
|
|
234
251
|
});
|
|
235
252
|
if (error) {
|
|
@@ -245,18 +262,19 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
245
262
|
});
|
|
246
263
|
}
|
|
247
264
|
}
|
|
248
|
-
}, [
|
|
265
|
+
}, [fetchCart, onLineRemove, numCartLines, countryCode]);
|
|
249
266
|
const updateLineItem = useCallback(async (lines, state) => {
|
|
250
267
|
var _a;
|
|
251
268
|
if (state.status === 'idle') {
|
|
252
269
|
dispatch({ type: 'updateLineItem', lines });
|
|
253
270
|
onLineUpdate === null || onLineUpdate === void 0 ? void 0 : onLineUpdate();
|
|
254
|
-
const { data, error } = await
|
|
271
|
+
const { data, error } = await fetchCart({
|
|
255
272
|
query: CartLineUpdate,
|
|
256
273
|
variables: {
|
|
257
274
|
cartId: state.cart.id,
|
|
258
275
|
lines: lines,
|
|
259
276
|
numCartLines,
|
|
277
|
+
country: countryCode,
|
|
260
278
|
},
|
|
261
279
|
});
|
|
262
280
|
if (error) {
|
|
@@ -272,18 +290,19 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
272
290
|
});
|
|
273
291
|
}
|
|
274
292
|
}
|
|
275
|
-
}, [
|
|
293
|
+
}, [fetchCart, onLineUpdate, numCartLines, countryCode]);
|
|
276
294
|
const noteUpdate = useCallback(async (note, state) => {
|
|
277
295
|
var _a;
|
|
278
296
|
if (state.status === 'idle') {
|
|
279
297
|
dispatch({ type: 'noteUpdate' });
|
|
280
298
|
onNoteUpdate === null || onNoteUpdate === void 0 ? void 0 : onNoteUpdate();
|
|
281
|
-
const { data, error } = await
|
|
299
|
+
const { data, error } = await fetchCart({
|
|
282
300
|
query: CartNoteUpdate,
|
|
283
301
|
variables: {
|
|
284
302
|
cartId: state.cart.id,
|
|
285
303
|
note: note,
|
|
286
304
|
numCartLines,
|
|
305
|
+
country: countryCode,
|
|
287
306
|
},
|
|
288
307
|
});
|
|
289
308
|
if (error) {
|
|
@@ -299,18 +318,19 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
299
318
|
});
|
|
300
319
|
}
|
|
301
320
|
}
|
|
302
|
-
}, [
|
|
321
|
+
}, [fetchCart, onNoteUpdate, numCartLines, countryCode]);
|
|
303
322
|
const buyerIdentityUpdate = useCallback(async (buyerIdentity, state) => {
|
|
304
323
|
var _a;
|
|
305
324
|
if (state.status === 'idle') {
|
|
306
325
|
dispatch({ type: 'buyerIdentityUpdate' });
|
|
307
326
|
onBuyerIdentityUpdate === null || onBuyerIdentityUpdate === void 0 ? void 0 : onBuyerIdentityUpdate();
|
|
308
|
-
const { data, error } = await
|
|
327
|
+
const { data, error } = await fetchCart({
|
|
309
328
|
query: CartBuyerIdentityUpdate,
|
|
310
329
|
variables: {
|
|
311
330
|
cartId: state.cart.id,
|
|
312
|
-
buyerIdentity
|
|
331
|
+
buyerIdentity,
|
|
313
332
|
numCartLines,
|
|
333
|
+
country: countryCode,
|
|
314
334
|
},
|
|
315
335
|
});
|
|
316
336
|
if (error) {
|
|
@@ -326,18 +346,19 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
326
346
|
});
|
|
327
347
|
}
|
|
328
348
|
}
|
|
329
|
-
}, [
|
|
349
|
+
}, [fetchCart, onBuyerIdentityUpdate, numCartLines, countryCode]);
|
|
330
350
|
const cartAttributesUpdate = useCallback(async (attributes, state) => {
|
|
331
351
|
var _a;
|
|
332
352
|
if (state.status === 'idle') {
|
|
333
353
|
dispatch({ type: 'cartAttributesUpdate' });
|
|
334
354
|
onAttributesUpdate === null || onAttributesUpdate === void 0 ? void 0 : onAttributesUpdate();
|
|
335
|
-
const { data, error } = await
|
|
355
|
+
const { data, error } = await fetchCart({
|
|
336
356
|
query: CartAttributesUpdate,
|
|
337
357
|
variables: {
|
|
338
358
|
cartId: state.cart.id,
|
|
339
359
|
attributes: attributes,
|
|
340
360
|
numCartLines,
|
|
361
|
+
country: countryCode,
|
|
341
362
|
},
|
|
342
363
|
});
|
|
343
364
|
if (error) {
|
|
@@ -353,18 +374,19 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
353
374
|
});
|
|
354
375
|
}
|
|
355
376
|
}
|
|
356
|
-
}, [
|
|
377
|
+
}, [fetchCart, onAttributesUpdate, numCartLines, countryCode]);
|
|
357
378
|
const discountCodesUpdate = useCallback(async (discountCodes, state) => {
|
|
358
379
|
var _a;
|
|
359
380
|
if (state.status === 'idle') {
|
|
360
381
|
dispatch({ type: 'discountCodesUpdate' });
|
|
361
382
|
onDiscountCodesUpdate === null || onDiscountCodesUpdate === void 0 ? void 0 : onDiscountCodesUpdate();
|
|
362
|
-
const { data, error } = await
|
|
383
|
+
const { data, error } = await fetchCart({
|
|
363
384
|
query: CartDiscountCodesUpdate,
|
|
364
385
|
variables: {
|
|
365
386
|
cartId: state.cart.id,
|
|
366
387
|
discountCodes: discountCodes,
|
|
367
388
|
numCartLines,
|
|
389
|
+
country: countryCode,
|
|
368
390
|
},
|
|
369
391
|
});
|
|
370
392
|
if (error) {
|
|
@@ -380,7 +402,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
380
402
|
});
|
|
381
403
|
}
|
|
382
404
|
}
|
|
383
|
-
}, [
|
|
405
|
+
}, [fetchCart, onDiscountCodesUpdate, numCartLines, countryCode]);
|
|
384
406
|
const didFetchCart = useRef(false);
|
|
385
407
|
useEffect(() => {
|
|
386
408
|
if (localStorage.getItem(CART_ID_STORAGE_KEY) &&
|
|
@@ -390,6 +412,13 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
390
412
|
cartFetch(localStorage.getItem(CART_ID_STORAGE_KEY));
|
|
391
413
|
}
|
|
392
414
|
}, [cartFetch, state]);
|
|
415
|
+
useEffect(() => {
|
|
416
|
+
if (state.status !== 'idle') {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
buyerIdentityUpdate({ countryCode }, state);
|
|
420
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
421
|
+
}, [countryCode]);
|
|
393
422
|
const cartContextValue = useMemo(() => {
|
|
394
423
|
return {
|
|
395
424
|
...('cart' in state
|
|
@@ -4,6 +4,7 @@ export declare type CartAttributesUpdateMutationVariables = Types.Exact<{
|
|
|
4
4
|
attributes: Array<Types.AttributeInput> | Types.AttributeInput;
|
|
5
5
|
cartId: Types.Scalars['ID'];
|
|
6
6
|
numCartLines?: Types.Maybe<Types.Scalars['Int']>;
|
|
7
|
+
country?: Types.Maybe<Types.CountryCode>;
|
|
7
8
|
}>;
|
|
8
9
|
export declare type CartAttributesUpdateMutation = {
|
|
9
10
|
__typename?: 'Mutation';
|
|
@@ -4,6 +4,7 @@ export declare type CartBuyerIdentityUpdateMutationVariables = Types.Exact<{
|
|
|
4
4
|
cartId: Types.Scalars['ID'];
|
|
5
5
|
buyerIdentity: Types.CartBuyerIdentityInput;
|
|
6
6
|
numCartLines?: Types.Maybe<Types.Scalars['Int']>;
|
|
7
|
+
country?: Types.Maybe<Types.CountryCode>;
|
|
7
8
|
}>;
|
|
8
9
|
export declare type CartBuyerIdentityUpdateMutation = {
|
|
9
10
|
__typename?: 'Mutation';
|
|
@@ -3,6 +3,7 @@ import { CartFragmentFragment } from './CartFragment';
|
|
|
3
3
|
export declare type CartCreateMutationVariables = Types.Exact<{
|
|
4
4
|
input: Types.CartInput;
|
|
5
5
|
numCartLines?: Types.Maybe<Types.Scalars['Int']>;
|
|
6
|
+
country?: Types.Maybe<Types.CountryCode>;
|
|
6
7
|
}>;
|
|
7
8
|
export declare type CartCreateMutation = {
|
|
8
9
|
__typename?: 'Mutation';
|
|
@@ -4,6 +4,7 @@ export declare type CartDiscountCodesUpdateMutationVariables = Types.Exact<{
|
|
|
4
4
|
cartId: Types.Scalars['ID'];
|
|
5
5
|
discountCodes?: Types.Maybe<Array<Types.Scalars['String']> | Types.Scalars['String']>;
|
|
6
6
|
numCartLines?: Types.Maybe<Types.Scalars['Int']>;
|
|
7
|
+
country?: Types.Maybe<Types.CountryCode>;
|
|
7
8
|
}>;
|
|
8
9
|
export declare type CartDiscountCodesUpdateMutation = {
|
|
9
10
|
__typename?: 'Mutation';
|
|
@@ -4,6 +4,7 @@ export declare type CartLineAddMutationVariables = Types.Exact<{
|
|
|
4
4
|
cartId: Types.Scalars['ID'];
|
|
5
5
|
lines: Array<Types.CartLineInput> | Types.CartLineInput;
|
|
6
6
|
numCartLines?: Types.Maybe<Types.Scalars['Int']>;
|
|
7
|
+
country?: Types.Maybe<Types.CountryCode>;
|
|
7
8
|
}>;
|
|
8
9
|
export declare type CartLineAddMutation = {
|
|
9
10
|
__typename?: 'Mutation';
|
|
@@ -4,6 +4,7 @@ export declare type CartLineRemoveMutationVariables = Types.Exact<{
|
|
|
4
4
|
cartId: Types.Scalars['ID'];
|
|
5
5
|
lines: Array<Types.Scalars['ID']> | Types.Scalars['ID'];
|
|
6
6
|
numCartLines?: Types.Maybe<Types.Scalars['Int']>;
|
|
7
|
+
country?: Types.Maybe<Types.CountryCode>;
|
|
7
8
|
}>;
|
|
8
9
|
export declare type CartLineRemoveMutation = {
|
|
9
10
|
__typename?: 'Mutation';
|
|
@@ -4,6 +4,7 @@ export declare type CartLineUpdateMutationVariables = Types.Exact<{
|
|
|
4
4
|
cartId: Types.Scalars['ID'];
|
|
5
5
|
lines: Array<Types.CartLineUpdateInput> | Types.CartLineUpdateInput;
|
|
6
6
|
numCartLines?: Types.Maybe<Types.Scalars['Int']>;
|
|
7
|
+
country?: Types.Maybe<Types.CountryCode>;
|
|
7
8
|
}>;
|
|
8
9
|
export declare type CartLineUpdateMutation = {
|
|
9
10
|
__typename?: 'Mutation';
|
|
@@ -4,6 +4,7 @@ export declare type CartNoteUpdateMutationVariables = Types.Exact<{
|
|
|
4
4
|
cartId: Types.Scalars['ID'];
|
|
5
5
|
note?: Types.Maybe<Types.Scalars['String']>;
|
|
6
6
|
numCartLines?: Types.Maybe<Types.Scalars['Int']>;
|
|
7
|
+
country?: Types.Maybe<Types.CountryCode>;
|
|
7
8
|
}>;
|
|
8
9
|
export declare type CartNoteUpdateMutation = {
|
|
9
10
|
__typename?: 'Mutation';
|
|
@@ -3,6 +3,7 @@ import { CartFragmentFragment } from './CartFragment';
|
|
|
3
3
|
export declare type CartQueryQueryVariables = Types.Exact<{
|
|
4
4
|
id: Types.Scalars['ID'];
|
|
5
5
|
numCartLines?: Types.Maybe<Types.Scalars['Int']>;
|
|
6
|
+
country?: Types.Maybe<Types.CountryCode>;
|
|
6
7
|
}>;
|
|
7
8
|
export declare type CartQueryQuery = {
|
|
8
9
|
__typename?: 'QueryRoot';
|
|
@@ -7,17 +7,6 @@ export declare function useCartFetch(): <T, K>({ query, variables, }: {
|
|
|
7
7
|
data: K | undefined;
|
|
8
8
|
error: any;
|
|
9
9
|
}>;
|
|
10
|
-
export declare function useCart(): import("./types").CartWithActions;
|
|
11
|
-
export declare function useCartCheckoutUrl(): string | undefined;
|
|
12
|
-
export declare function useCartLinesTotalQuantity(): number;
|
|
13
|
-
export declare function useCartCreateCallback(): (cart: CartInput) => void;
|
|
14
|
-
export declare function useCartLinesAddCallback(): (lines: import("../../graphql/types/types").CartLineInput[]) => void;
|
|
15
|
-
export declare function useCartLinesRemoveCallback(): (lines: string[]) => void;
|
|
16
|
-
export declare function useCartLinesUpdateCallback(): (lines: import("../../graphql/types/types").CartLineUpdateInput[]) => void;
|
|
17
|
-
export declare function useCartNoteUpdateCallback(): (note: import("../../graphql/types/types").Maybe<string> | undefined) => void;
|
|
18
|
-
export declare function useCartBuyerIdentityUpdateCallback(): (buyerIdenity: import("../../graphql/types/types").CartBuyerIdentityInput) => void;
|
|
19
|
-
export declare function useCartAttributesUpdateCallback(): (attributes: import("../../graphql/types/types").AttributeInput[]) => void;
|
|
20
|
-
export declare function useCartDiscountCodesUpdateCallback(): (discountCodes: string[]) => void;
|
|
21
10
|
export declare function useInstantCheckout(): {
|
|
22
11
|
cart: Cart | undefined;
|
|
23
12
|
checkoutUrl: string | undefined;
|
|
@@ -2,7 +2,6 @@ import React from 'react';
|
|
|
2
2
|
import { useShop } from '../../foundation';
|
|
3
3
|
import { flattenConnection } from '../../utilities';
|
|
4
4
|
import { CartCreate } from '../../graphql/graphql-constants';
|
|
5
|
-
import { CartContext } from './context';
|
|
6
5
|
export function useCartFetch() {
|
|
7
6
|
const { storeDomain, graphqlApiVersion, storefrontToken } = useShop();
|
|
8
7
|
return React.useCallback(({ query, variables, }) => {
|
|
@@ -26,59 +25,6 @@ export function useCartFetch() {
|
|
|
26
25
|
});
|
|
27
26
|
}, [storeDomain, graphqlApiVersion, storefrontToken]);
|
|
28
27
|
}
|
|
29
|
-
export function useCart() {
|
|
30
|
-
const context = React.useContext(CartContext);
|
|
31
|
-
if (!context) {
|
|
32
|
-
throw new Error('Expected a Cart Context, but no Cart Context was found');
|
|
33
|
-
}
|
|
34
|
-
return context;
|
|
35
|
-
}
|
|
36
|
-
export function useCartCheckoutUrl() {
|
|
37
|
-
const { checkoutUrl } = useCart();
|
|
38
|
-
return checkoutUrl;
|
|
39
|
-
}
|
|
40
|
-
export function useCartLinesTotalQuantity() {
|
|
41
|
-
var _a;
|
|
42
|
-
const { lines } = useCart();
|
|
43
|
-
const itemCount = (_a = React.useMemo(() => {
|
|
44
|
-
return lines.reduce((accumulator, line) => {
|
|
45
|
-
return accumulator + line.quantity;
|
|
46
|
-
}, 0);
|
|
47
|
-
}, [lines])) !== null && _a !== void 0 ? _a : 0;
|
|
48
|
-
return itemCount;
|
|
49
|
-
}
|
|
50
|
-
export function useCartCreateCallback() {
|
|
51
|
-
const { cartCreate } = useCart();
|
|
52
|
-
return cartCreate;
|
|
53
|
-
}
|
|
54
|
-
export function useCartLinesAddCallback() {
|
|
55
|
-
const { linesAdd } = useCart();
|
|
56
|
-
return linesAdd;
|
|
57
|
-
}
|
|
58
|
-
export function useCartLinesRemoveCallback() {
|
|
59
|
-
const { linesRemove } = useCart();
|
|
60
|
-
return linesRemove;
|
|
61
|
-
}
|
|
62
|
-
export function useCartLinesUpdateCallback() {
|
|
63
|
-
const { linesUpdate } = useCart();
|
|
64
|
-
return linesUpdate;
|
|
65
|
-
}
|
|
66
|
-
export function useCartNoteUpdateCallback() {
|
|
67
|
-
const { noteUpdate } = useCart();
|
|
68
|
-
return noteUpdate;
|
|
69
|
-
}
|
|
70
|
-
export function useCartBuyerIdentityUpdateCallback() {
|
|
71
|
-
const { buyerIdentityUpdate } = useCart();
|
|
72
|
-
return buyerIdentityUpdate;
|
|
73
|
-
}
|
|
74
|
-
export function useCartAttributesUpdateCallback() {
|
|
75
|
-
const { cartAttributesUpdate } = useCart();
|
|
76
|
-
return cartAttributesUpdate;
|
|
77
|
-
}
|
|
78
|
-
export function useCartDiscountCodesUpdateCallback() {
|
|
79
|
-
const { discountCodesUpdate } = useCart();
|
|
80
|
-
return discountCodesUpdate;
|
|
81
|
-
}
|
|
82
28
|
export function useInstantCheckout() {
|
|
83
29
|
const [cart, updateCart] = React.useState();
|
|
84
30
|
const [checkoutUrl, updateCheckoutUrl] = React.useState();
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
export { CartProvider } from './CartProvider.client';
|
|
2
|
-
export {
|
|
2
|
+
export { useCartFetch, useInstantCheckout } from './hooks';
|
|
3
|
+
export { useCart } from '../../hooks/useCart';
|
|
4
|
+
export { useCartAttributesUpdateCallback } from '../../hooks/useCartAttributesUpdateCallback';
|
|
5
|
+
export { useCartBuyerIdentityUpdateCallback } from '../../hooks/useCartBuyerIdentityUpdateCallback';
|
|
6
|
+
export { useCartNoteUpdateCallback } from '../../hooks/useCartNoteUpdateCallback';
|
|
7
|
+
export { useCartCheckoutUrl } from '../../hooks/useCartCheckoutUrl';
|
|
8
|
+
export { useCartCreateCallback } from '../../hooks/useCartCreateCallback';
|
|
9
|
+
export { useCartDiscountCodesUpdateCallback } from '../../hooks/useCartDiscountCodesUpdateCallback';
|
|
10
|
+
export { useCartLinesAddCallback } from '../../hooks/useCartLinesAddCallback';
|
|
11
|
+
export { useCartLinesRemoveCallback } from '../../hooks/useCartLinesRemoveCallback';
|
|
12
|
+
export { useCartLinesTotalQuantity } from '../../hooks/useCartLinesTotalQuantity';
|
|
13
|
+
export { useCartLinesUpdateCallback } from '../../hooks/useCartLinesUpdateCallback';
|
|
3
14
|
export type { State, Status, Cart, CartWithActions, CartAction } from './types';
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
export { CartProvider } from './CartProvider.client';
|
|
2
|
-
export {
|
|
2
|
+
export { useCartFetch, useInstantCheckout } from './hooks';
|
|
3
|
+
export { useCart } from '../../hooks/useCart';
|
|
4
|
+
export { useCartAttributesUpdateCallback } from '../../hooks/useCartAttributesUpdateCallback';
|
|
5
|
+
export { useCartBuyerIdentityUpdateCallback } from '../../hooks/useCartBuyerIdentityUpdateCallback';
|
|
6
|
+
export { useCartNoteUpdateCallback } from '../../hooks/useCartNoteUpdateCallback';
|
|
7
|
+
export { useCartCheckoutUrl } from '../../hooks/useCartCheckoutUrl';
|
|
8
|
+
export { useCartCreateCallback } from '../../hooks/useCartCreateCallback';
|
|
9
|
+
export { useCartDiscountCodesUpdateCallback } from '../../hooks/useCartDiscountCodesUpdateCallback';
|
|
10
|
+
export { useCartLinesAddCallback } from '../../hooks/useCartLinesAddCallback';
|
|
11
|
+
export { useCartLinesRemoveCallback } from '../../hooks/useCartLinesRemoveCallback';
|
|
12
|
+
export { useCartLinesTotalQuantity } from '../../hooks/useCartLinesTotalQuantity';
|
|
13
|
+
export { useCartLinesUpdateCallback } from '../../hooks/useCartLinesUpdateCallback';
|
|
@@ -13,10 +13,10 @@ export interface BaseImageProps {
|
|
|
13
13
|
loaderOptions?: ImageLoaderOptions['options'];
|
|
14
14
|
}
|
|
15
15
|
export interface MediaImageProps extends BaseImageProps {
|
|
16
|
-
/** An object with the keys `
|
|
16
|
+
/** An object with the keys `url`, `altText`, `id`, `width` and `height`. Refer to the
|
|
17
17
|
* Storefront API's [`Image` object](/api/storefront/reference/common-objects/image).
|
|
18
18
|
*/
|
|
19
|
-
image: Pick<ImageType, 'altText' | '
|
|
19
|
+
image: Pick<ImageType, 'altText' | 'url' | 'id' | 'width' | 'height'>;
|
|
20
20
|
/** An object of image size options for Shopify CDN images. */
|
|
21
21
|
options?: ImageSizeOptions;
|
|
22
22
|
}
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { ImageFragment as Fragment } from '../../graphql/graphql-constants';
|
|
3
3
|
import { shopifyImageLoader, getShopifyImageDimensions, } from '../../utilities';
|
|
4
4
|
function convertShopifyImageData({ image, options, loader, loaderOptions, id: propId, alt, }) {
|
|
5
|
-
const {
|
|
5
|
+
const { url: src, altText, id } = image;
|
|
6
6
|
const { width, height } = getShopifyImageDimensions(image, options);
|
|
7
7
|
return {
|
|
8
8
|
src,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as Types from '../../graphql/types/types';
|
|
2
2
|
export declare type ImageFragmentFragment = {
|
|
3
3
|
__typename?: 'Image';
|
|
4
|
-
} & Pick<Types.Image, 'id' | '
|
|
4
|
+
} & Pick<Types.Image, 'id' | 'url' | 'altText' | 'width' | 'height'>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* The `LocalizationProvider` component automatically queries the Storefront API's
|
|
4
|
-
* [`localization`](/api/storefront/reference/common-objects/queryroot
|
|
4
|
+
* [`localization`](/api/storefront/reference/common-objects/queryroot) field
|
|
5
5
|
* for the `isoCode` and `name` of the `country` and `availableCountries` and keeps this information in a context.
|
|
6
6
|
*
|
|
7
7
|
* Any descendents of this provider can use the `useCountry` and `useAvailableCountries` hooks.
|
|
@@ -4,7 +4,7 @@ import { useShopQuery } from '../../hooks/useShopQuery';
|
|
|
4
4
|
import { Localization } from '../../graphql/graphql-constants';
|
|
5
5
|
/**
|
|
6
6
|
* The `LocalizationProvider` component automatically queries the Storefront API's
|
|
7
|
-
* [`localization`](/api/storefront/reference/common-objects/queryroot
|
|
7
|
+
* [`localization`](/api/storefront/reference/common-objects/queryroot) field
|
|
8
8
|
* for the `isoCode` and `name` of the `country` and `availableCountries` and keeps this information in a context.
|
|
9
9
|
*
|
|
10
10
|
* Any descendents of this provider can use the `useCountry` and `useAvailableCountries` hooks.
|
|
@@ -12,6 +12,9 @@ import { Localization } from '../../graphql/graphql-constants';
|
|
|
12
12
|
* [`@inContext`](/api/storefront/reference/directives/incontext) directive as the `country` value.
|
|
13
13
|
*/
|
|
14
14
|
export function LocalizationProvider({ children }) {
|
|
15
|
-
const { data: { localization }, } = useShopQuery({
|
|
15
|
+
const { data: { localization }, } = useShopQuery({
|
|
16
|
+
query: Localization,
|
|
17
|
+
cache: { maxAge: 60 * 60, staleWhileRevalidate: 60 * 60 * 23 },
|
|
18
|
+
});
|
|
16
19
|
return (React.createElement(LocalizationClientProvider, { localization: localization }, children));
|
|
17
20
|
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { useCountry
|
|
1
|
+
export { useCountry } from '../../hooks/useCountry/useCountry';
|
|
2
|
+
export { useAvailableCountries } from '../../hooks/useAvailableCountries/useAvailableCountries';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { useCountry
|
|
1
|
+
export { useCountry } from '../../hooks/useCountry/useCountry';
|
|
2
|
+
export { useAvailableCountries } from '../../hooks/useAvailableCountries/useAvailableCountries';
|
|
@@ -10,7 +10,7 @@ export interface Model3DProps {
|
|
|
10
10
|
model: {
|
|
11
11
|
id?: Model3DType['id'];
|
|
12
12
|
alt: Model3DType['alt'];
|
|
13
|
-
previewImage?: Pick<Image, '
|
|
13
|
+
previewImage?: Pick<Image, 'url'>;
|
|
14
14
|
sources: Pick<Model3dSource, 'url'>[];
|
|
15
15
|
};
|
|
16
16
|
/** A string of either `auto`, `lazy`, or `eager` to indicate the conditions for preloading. Refer to [`loading` in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-attributes-loading). */
|
|
@@ -6,7 +6,7 @@ import { Model3DFragment as Fragment } from '../../graphql/graphql-constants';
|
|
|
6
6
|
* the Storefront API's [`Model3d` object](/api/storefront/reference/products/model3d).
|
|
7
7
|
*/
|
|
8
8
|
export function Model3D(props) {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f
|
|
9
|
+
var _a, _b, _c, _d, _e, _f;
|
|
10
10
|
const [modelViewer, setModelViewer] = useState(undefined);
|
|
11
11
|
const callbackRef = useCallback((node) => {
|
|
12
12
|
setModelViewer(node);
|
|
@@ -109,7 +109,7 @@ export function Model3D(props) {
|
|
|
109
109
|
// TODO: What do we want to display while the model-viewer library loads?
|
|
110
110
|
return null;
|
|
111
111
|
}
|
|
112
|
-
return (React.createElement("model-viewer", { ref: callbackRef, ...passthroughProps, class: className, id: id, src: model.sources[0].url, alt: model.alt, "camera-controls": (_a = passthroughProps.cameraControls) !== null && _a !== void 0 ? _a : true, poster: (_b = model.previewImage) === null || _b === void 0 ? void 0 : _b.
|
|
112
|
+
return (React.createElement("model-viewer", { ref: callbackRef, ...passthroughProps, class: className, id: id, src: model.sources[0].url, alt: model.alt, "camera-controls": (_a = passthroughProps.cameraControls) !== null && _a !== void 0 ? _a : true, poster: (_b = model.previewImage) === null || _b === void 0 ? void 0 : _b.url, autoplay: (_c = passthroughProps.autoplay) !== null && _c !== void 0 ? _c : true, loading: passthroughProps.loading, reveal: passthroughProps.reveal, ar: passthroughProps.ar, "ar-modes": passthroughProps.arModes, "ar-scale": passthroughProps.arScale, "ar-placement": passthroughProps.arPlacement, "ios-src": passthroughProps.iosSrc, "touch-action": passthroughProps.touchAction, "disable-zoom": passthroughProps.disableZoom, "orbit-sensitivity": passthroughProps.orbitSensitivity, "auto-rotate": passthroughProps.autoRotate, "auto-rotate-delay": passthroughProps.autoRotateDelay, "rotation-per-second": passthroughProps.rotationPerSecond, "interaction-policy": passthroughProps.interactionPolicy, "interaction-prompt": passthroughProps.interactionPrompt, "interaction-prompt-style": passthroughProps.interactionPromptStyle, "interaction-prompt-threshold": passthroughProps.interactionPromptThreshold, "camera-orbit": passthroughProps.cameraOrbit, "camera-target": passthroughProps.cameraTarget, "field-of-view": passthroughProps.fieldOfView, "max-camera-orbit": passthroughProps.maxCameraOrbit, "min-camera-orbit": passthroughProps.minCameraOrbit, "max-field-of-view": passthroughProps.maxFieldOfView, "min-field-of-view": passthroughProps.minFieldOfView, bounds: passthroughProps.bounds, "interpolation-decay": (_d = passthroughProps.interpolationDecay) !== null && _d !== void 0 ? _d : 100, "skybox-image": passthroughProps.skyboxImage, "environment-image": passthroughProps.environmentImage, exposure: passthroughProps.exposure, "shadow-intensity": (_e = passthroughProps.shadowIntensity) !== null && _e !== void 0 ? _e : 0, "shadow-softness": (_f = passthroughProps.shadowSoftness) !== null && _f !== void 0 ? _f : 0, "animation-name": passthroughProps.animationName, "animation-crossfade-duration": passthroughProps.animationCrossfadeDuration, "variant-name": passthroughProps.variantName, orientation: passthroughProps.orientation, scale: passthroughProps.scale }, children));
|
|
113
113
|
}
|
|
114
114
|
Model3D.Fragment = Fragment;
|
|
115
115
|
export const Model3DFragment = Fragment;
|