@shopify/hydrogen-react 0.0.0-next-81b4528 → 0.0.0-next-182fb2f

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.
@@ -766,7 +766,7 @@ query CartQuery($id: ID!, $numCartLines: Int = 250, $country: CountryCode = ZZ)
766
766
  ${cartFragment}
767
767
  `;
768
768
  const SFAPI_VERSION = "2022-10";
769
- var _jsxFileName$b = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopifyProvider.tsx";
769
+ var _jsxFileName$c = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopifyProvider.tsx";
770
770
  const ShopifyContext = React.createContext({
771
771
  storeDomain: "test.myshopify.com",
772
772
  storefrontToken: "abc123",
@@ -797,7 +797,7 @@ ${cartFragment}
797
797
  value: finalConfig,
798
798
  __self: this,
799
799
  __source: {
800
- fileName: _jsxFileName$b,
800
+ fileName: _jsxFileName$c,
801
801
  lineNumber: 49,
802
802
  columnNumber: 5
803
803
  }
@@ -1312,7 +1312,7 @@ ${cartFragment}
1312
1312
  function isCartFetchResultEvent(event) {
1313
1313
  return event.type === "RESOLVE" || event.type === "ERROR" || event.type === "CART_COMPLETED";
1314
1314
  }
1315
- var _jsxFileName$a = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/CartProvider.tsx";
1315
+ var _jsxFileName$b = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/CartProvider.tsx";
1316
1316
  const CartContext = React.createContext(null);
1317
1317
  function useCart() {
1318
1318
  const context = React.useContext(CartContext);
@@ -1625,7 +1625,7 @@ ${cartFragment}
1625
1625
  value: cartContextValue,
1626
1626
  __self: this,
1627
1627
  __source: {
1628
- fileName: _jsxFileName$a,
1628
+ fileName: _jsxFileName$b,
1629
1629
  lineNumber: 425,
1630
1630
  columnNumber: 5
1631
1631
  }
@@ -1791,7 +1791,266 @@ fragment ImageFragment on Image {
1791
1791
  height
1792
1792
  }
1793
1793
  `;
1794
- var _jsxFileName$9 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ExternalVideo.tsx";
1794
+ var _jsxFileName$a = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductProvider.tsx";
1795
+ const ProductOptionsContext = React.createContext(null);
1796
+ function ProductProvider({
1797
+ children,
1798
+ data: product,
1799
+ initialVariantId: explicitVariantId
1800
+ }) {
1801
+ const variants = React.useMemo(() => {
1802
+ var _a;
1803
+ return flattenConnection((_a = product.variants) != null ? _a : {});
1804
+ }, [product.variants]);
1805
+ if (!isProductVariantArray(variants)) {
1806
+ throw new Error(`<ProductProvider/> requires 'product.variants.nodes' or 'product.variants.edges'`);
1807
+ }
1808
+ const options = React.useMemo(() => getOptions(variants), [variants]);
1809
+ const [selectedVariant, setSelectedVariant] = React.useState(() => getVariantBasedOnIdProp(explicitVariantId, variants));
1810
+ const [selectedOptions, setSelectedOptions] = React.useState(() => getSelectedOptions(selectedVariant));
1811
+ React.useEffect(() => {
1812
+ const newSelectedVariant = getVariantBasedOnIdProp(explicitVariantId, variants);
1813
+ setSelectedVariant(newSelectedVariant);
1814
+ setSelectedOptions(getSelectedOptions(newSelectedVariant));
1815
+ }, [explicitVariantId, variants]);
1816
+ const setSelectedOption = React.useCallback((name, value2) => {
1817
+ setSelectedOptions((selectedOptions2) => {
1818
+ const opts = {
1819
+ ...selectedOptions2,
1820
+ [name]: value2
1821
+ };
1822
+ setSelectedVariant(getSelectedVariant(variants, opts));
1823
+ return opts;
1824
+ });
1825
+ }, [setSelectedOptions, variants]);
1826
+ const isOptionInStock = React.useCallback((option, value2) => {
1827
+ var _a;
1828
+ const proposedVariant = getSelectedVariant(variants, {
1829
+ ...selectedOptions,
1830
+ ...{
1831
+ [option]: value2
1832
+ }
1833
+ });
1834
+ return (_a = proposedVariant == null ? void 0 : proposedVariant.availableForSale) != null ? _a : true;
1835
+ }, [selectedOptions, variants]);
1836
+ const sellingPlanGroups = React.useMemo(() => {
1837
+ var _a;
1838
+ return flattenConnection((_a = product.sellingPlanGroups) != null ? _a : {}).map((sellingPlanGroup) => {
1839
+ var _a2;
1840
+ return {
1841
+ ...sellingPlanGroup,
1842
+ sellingPlans: flattenConnection((_a2 = sellingPlanGroup == null ? void 0 : sellingPlanGroup.sellingPlans) != null ? _a2 : {})
1843
+ };
1844
+ });
1845
+ }, [product.sellingPlanGroups]);
1846
+ const [selectedSellingPlan, setSelectedSellingPlan] = React.useState(void 0);
1847
+ const selectedSellingPlanAllocation = React.useMemo(() => {
1848
+ var _a, _b;
1849
+ if (!selectedVariant || !selectedSellingPlan) {
1850
+ return;
1851
+ }
1852
+ if (!((_a = selectedVariant.sellingPlanAllocations) == null ? void 0 : _a.nodes) && !((_b = selectedVariant.sellingPlanAllocations) == null ? void 0 : _b.edges)) {
1853
+ throw new Error(`<ProductProvider/>: You must include 'sellingPlanAllocations.nodes' or 'sellingPlanAllocations.edges' in your variants in order to calculate selectedSellingPlanAllocation`);
1854
+ }
1855
+ return flattenConnection(selectedVariant.sellingPlanAllocations).find((allocation) => {
1856
+ var _a2;
1857
+ return ((_a2 = allocation == null ? void 0 : allocation.sellingPlan) == null ? void 0 : _a2.id) === selectedSellingPlan.id;
1858
+ });
1859
+ }, [selectedVariant, selectedSellingPlan]);
1860
+ const value = React.useMemo(() => ({
1861
+ variants,
1862
+ variantsConnection: product.variants,
1863
+ options,
1864
+ selectedVariant,
1865
+ setSelectedVariant,
1866
+ selectedOptions,
1867
+ setSelectedOption,
1868
+ setSelectedOptions,
1869
+ isOptionInStock,
1870
+ selectedSellingPlan,
1871
+ setSelectedSellingPlan,
1872
+ selectedSellingPlanAllocation,
1873
+ sellingPlanGroups,
1874
+ sellingPlanGroupsConnection: product.sellingPlanGroups
1875
+ }), [isOptionInStock, options, product.sellingPlanGroups, product.variants, selectedOptions, selectedSellingPlan, selectedSellingPlanAllocation, selectedVariant, sellingPlanGroups, setSelectedOption, variants]);
1876
+ return /* @__PURE__ */ React__default.default.createElement(ProductOptionsContext.Provider, {
1877
+ value,
1878
+ __self: this,
1879
+ __source: {
1880
+ fileName: _jsxFileName$a,
1881
+ lineNumber: 201,
1882
+ columnNumber: 5
1883
+ }
1884
+ }, children);
1885
+ }
1886
+ function useProduct() {
1887
+ const context = React.useContext(ProductOptionsContext);
1888
+ if (!context) {
1889
+ throw new Error(`'useProduct' must be a child of <ProductProvider />`);
1890
+ }
1891
+ return context;
1892
+ }
1893
+ function getSelectedVariant(variants, choices) {
1894
+ var _a, _b;
1895
+ if (!variants.length || ((_b = (_a = variants == null ? void 0 : variants[0]) == null ? void 0 : _a.selectedOptions) == null ? void 0 : _b.length) !== Object.keys(choices).length) {
1896
+ return;
1897
+ }
1898
+ return variants == null ? void 0 : variants.find((variant) => {
1899
+ return Object.entries(choices).every(([name, value]) => {
1900
+ var _a2;
1901
+ return (_a2 = variant == null ? void 0 : variant.selectedOptions) == null ? void 0 : _a2.some((option) => (option == null ? void 0 : option.name) === name && (option == null ? void 0 : option.value) === value);
1902
+ });
1903
+ });
1904
+ }
1905
+ function getOptions(variants) {
1906
+ const map = variants.reduce((memo, variant) => {
1907
+ var _a;
1908
+ if (!variant.selectedOptions) {
1909
+ throw new Error(`'getOptions' requires 'variant.selectedOptions'`);
1910
+ }
1911
+ (_a = variant == null ? void 0 : variant.selectedOptions) == null ? void 0 : _a.forEach((opt) => {
1912
+ var _a2, _b, _c, _d;
1913
+ memo[(_a2 = opt == null ? void 0 : opt.name) != null ? _a2 : ""] = memo[(_b = opt == null ? void 0 : opt.name) != null ? _b : ""] || /* @__PURE__ */ new Set();
1914
+ memo[(_c = opt == null ? void 0 : opt.name) != null ? _c : ""].add((_d = opt == null ? void 0 : opt.value) != null ? _d : "");
1915
+ });
1916
+ return memo;
1917
+ }, {});
1918
+ return Object.keys(map).map((option) => {
1919
+ return {
1920
+ name: option,
1921
+ values: Array.from(map[option])
1922
+ };
1923
+ });
1924
+ }
1925
+ function getVariantBasedOnIdProp(explicitVariantId, variants) {
1926
+ if (explicitVariantId) {
1927
+ const foundVariant = variants.find((variant) => (variant == null ? void 0 : variant.id) === explicitVariantId);
1928
+ if (!foundVariant) {
1929
+ console.warn(`<ProductProvider/> received a 'initialVariantId' prop, but could not actually find a variant with that ID`);
1930
+ }
1931
+ return foundVariant;
1932
+ }
1933
+ if (explicitVariantId === null) {
1934
+ return null;
1935
+ }
1936
+ if (explicitVariantId === void 0) {
1937
+ return variants.find((variant) => variant == null ? void 0 : variant.availableForSale) || variants[0];
1938
+ }
1939
+ }
1940
+ function getSelectedOptions(selectedVariant) {
1941
+ return (selectedVariant == null ? void 0 : selectedVariant.selectedOptions) ? selectedVariant.selectedOptions.reduce((memo, optionSet) => {
1942
+ var _a, _b;
1943
+ memo[(_a = optionSet == null ? void 0 : optionSet.name) != null ? _a : ""] = (_b = optionSet == null ? void 0 : optionSet.value) != null ? _b : "";
1944
+ return memo;
1945
+ }, {}) : {};
1946
+ }
1947
+ function isProductVariantArray(maybeVariantArray) {
1948
+ if (!maybeVariantArray || !Array.isArray(maybeVariantArray)) {
1949
+ return false;
1950
+ }
1951
+ return true;
1952
+ }
1953
+ var _jsxFileName$9 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/AddToCartButton.tsx";
1954
+ function AddToCartButton(props) {
1955
+ var _a;
1956
+ const [addingItem, setAddingItem] = React.useState(false);
1957
+ const {
1958
+ variantId: explicitVariantId,
1959
+ quantity = 1,
1960
+ attributes,
1961
+ sellingPlanId,
1962
+ onClick,
1963
+ children,
1964
+ accessibleAddingToCartLabel,
1965
+ ...passthroughProps
1966
+ } = props;
1967
+ const {
1968
+ status,
1969
+ linesAdd
1970
+ } = useCart();
1971
+ const {
1972
+ selectedVariant
1973
+ } = useProduct();
1974
+ const variantId = (_a = explicitVariantId != null ? explicitVariantId : selectedVariant == null ? void 0 : selectedVariant.id) != null ? _a : "";
1975
+ const disabled = explicitVariantId === null || variantId === "" || selectedVariant === null || addingItem || passthroughProps.disabled;
1976
+ React.useEffect(() => {
1977
+ if (addingItem && status === "idle") {
1978
+ setAddingItem(false);
1979
+ }
1980
+ }, [status, addingItem]);
1981
+ const handleAddItem = React.useCallback(() => {
1982
+ setAddingItem(true);
1983
+ linesAdd([{
1984
+ quantity,
1985
+ merchandiseId: variantId || "",
1986
+ attributes,
1987
+ sellingPlanId
1988
+ }]);
1989
+ }, [linesAdd, quantity, variantId, attributes, sellingPlanId]);
1990
+ return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement(BaseButton, {
1991
+ ...passthroughProps,
1992
+ disabled,
1993
+ onClick,
1994
+ defaultOnClick: handleAddItem,
1995
+ __self: this,
1996
+ __source: {
1997
+ fileName: _jsxFileName$9,
1998
+ lineNumber: 70,
1999
+ columnNumber: 7
2000
+ }
2001
+ }, children), accessibleAddingToCartLabel ? /* @__PURE__ */ React__default.default.createElement("p", {
2002
+ style: {
2003
+ position: "absolute",
2004
+ width: "1px",
2005
+ height: "1px",
2006
+ padding: "0",
2007
+ margin: "-1px",
2008
+ overflow: "hidden",
2009
+ clip: "rect(0, 0, 0, 0)",
2010
+ whiteSpace: "nowrap",
2011
+ borderWidth: "0"
2012
+ },
2013
+ role: "alert",
2014
+ "aria-live": "assertive",
2015
+ __self: this,
2016
+ __source: {
2017
+ fileName: _jsxFileName$9,
2018
+ lineNumber: 79,
2019
+ columnNumber: 9
2020
+ }
2021
+ }, addingItem ? accessibleAddingToCartLabel : null) : null);
2022
+ }
2023
+ function BaseButton(props) {
2024
+ const {
2025
+ as,
2026
+ onClick,
2027
+ defaultOnClick,
2028
+ children,
2029
+ buttonRef,
2030
+ ...passthroughProps
2031
+ } = props;
2032
+ const handleOnClick = React.useCallback((event) => {
2033
+ if (onClick) {
2034
+ const clickShouldContinue = onClick(event);
2035
+ if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
2036
+ return;
2037
+ }
2038
+ defaultOnClick == null ? void 0 : defaultOnClick(event);
2039
+ }, [defaultOnClick, onClick]);
2040
+ const Component = as || "button";
2041
+ return /* @__PURE__ */ React__default.default.createElement(Component, {
2042
+ ref: buttonRef,
2043
+ onClick: handleOnClick,
2044
+ ...passthroughProps,
2045
+ __self: this,
2046
+ __source: {
2047
+ fileName: _jsxFileName$9,
2048
+ lineNumber: 157,
2049
+ columnNumber: 5
2050
+ }
2051
+ }, children);
2052
+ }
2053
+ var _jsxFileName$8 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ExternalVideo.tsx";
1795
2054
  function ExternalVideo(props) {
1796
2055
  var _a, _b;
1797
2056
  const {
@@ -1826,7 +2085,7 @@ fragment ImageFragment on Image {
1826
2085
  loading,
1827
2086
  __self: this,
1828
2087
  __source: {
1829
- fileName: _jsxFileName$9,
2088
+ fileName: _jsxFileName$8,
1830
2089
  lineNumber: 56,
1831
2090
  columnNumber: 5
1832
2091
  }
@@ -1905,7 +2164,7 @@ fragment ImageFragment on Image {
1905
2164
  }
1906
2165
  return { width: null, height: null };
1907
2166
  }
1908
- var _jsxFileName$8 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Image.tsx";
2167
+ var _jsxFileName$7 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Image.tsx";
1909
2168
  function Image({
1910
2169
  data,
1911
2170
  width,
@@ -1974,7 +2233,7 @@ fragment ImageFragment on Image {
1974
2233
  decoding,
1975
2234
  __self: this,
1976
2235
  __source: {
1977
- fileName: _jsxFileName$8,
2236
+ fileName: _jsxFileName$7,
1978
2237
  lineNumber: 150,
1979
2238
  columnNumber: 5
1980
2239
  }
@@ -2010,7 +2269,7 @@ fragment ImageFragment on Image {
2010
2269
  scale
2011
2270
  })} ${size}w`).join(", ");
2012
2271
  }
2013
- var _jsxFileName$7 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Video.tsx";
2272
+ var _jsxFileName$6 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Video.tsx";
2014
2273
  function Video(props) {
2015
2274
  var _a, _b;
2016
2275
  const {
@@ -2037,7 +2296,7 @@ fragment ImageFragment on Image {
2037
2296
  poster: posterUrl,
2038
2297
  __self: this,
2039
2298
  __source: {
2040
- fileName: _jsxFileName$7,
2299
+ fileName: _jsxFileName$6,
2041
2300
  lineNumber: 42,
2042
2301
  columnNumber: 5
2043
2302
  }
@@ -2052,7 +2311,7 @@ fragment ImageFragment on Image {
2052
2311
  type: source.mimeType,
2053
2312
  __self: this,
2054
2313
  __source: {
2055
- fileName: _jsxFileName$7,
2314
+ fileName: _jsxFileName$6,
2056
2315
  lineNumber: 54,
2057
2316
  columnNumber: 11
2058
2317
  }
@@ -2105,7 +2364,7 @@ fragment ImageFragment on Image {
2105
2364
  }, [url, stringifiedOptions, options]);
2106
2365
  return status;
2107
2366
  }
2108
- var _jsxFileName$6 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ModelViewer.tsx";
2367
+ var _jsxFileName$5 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ModelViewer.tsx";
2109
2368
  function ModelViewer(props) {
2110
2369
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2111
2370
  const [modelViewer, setModelViewer] = React.useState(void 0);
@@ -2243,13 +2502,13 @@ fragment ImageFragment on Image {
2243
2502
  scale: passthroughProps.scale,
2244
2503
  __self: this,
2245
2504
  __source: {
2246
- fileName: _jsxFileName$6,
2505
+ fileName: _jsxFileName$5,
2247
2506
  lineNumber: 222,
2248
2507
  columnNumber: 5
2249
2508
  }
2250
2509
  }, children);
2251
2510
  }
2252
- var _jsxFileName$5 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/MediaFile.tsx";
2511
+ var _jsxFileName$4 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/MediaFile.tsx";
2253
2512
  function MediaFile({
2254
2513
  data,
2255
2514
  mediaOptions,
@@ -2269,7 +2528,7 @@ fragment ImageFragment on Image {
2269
2528
  data: data.image,
2270
2529
  __self: this,
2271
2530
  __source: {
2272
- fileName: _jsxFileName$5,
2531
+ fileName: _jsxFileName$4,
2273
2532
  lineNumber: 54,
2274
2533
  columnNumber: 9
2275
2534
  }
@@ -2282,7 +2541,7 @@ fragment ImageFragment on Image {
2282
2541
  data,
2283
2542
  __self: this,
2284
2543
  __source: {
2285
- fileName: _jsxFileName$5,
2544
+ fileName: _jsxFileName$4,
2286
2545
  lineNumber: 63,
2287
2546
  columnNumber: 9
2288
2547
  }
@@ -2295,7 +2554,7 @@ fragment ImageFragment on Image {
2295
2554
  data,
2296
2555
  __self: this,
2297
2556
  __source: {
2298
- fileName: _jsxFileName$5,
2557
+ fileName: _jsxFileName$4,
2299
2558
  lineNumber: 68,
2300
2559
  columnNumber: 9
2301
2560
  }
@@ -2308,7 +2567,7 @@ fragment ImageFragment on Image {
2308
2567
  data,
2309
2568
  __self: this,
2310
2569
  __source: {
2311
- fileName: _jsxFileName$5,
2570
+ fileName: _jsxFileName$4,
2312
2571
  lineNumber: 78,
2313
2572
  columnNumber: 9
2314
2573
  }
@@ -2322,7 +2581,7 @@ fragment ImageFragment on Image {
2322
2581
  }
2323
2582
  }
2324
2583
  }
2325
- var _jsxFileName$4 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Metafield.tsx";
2584
+ var _jsxFileName$3 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Metafield.tsx";
2326
2585
  function Metafield(props) {
2327
2586
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2328
2587
  const {
@@ -2353,7 +2612,7 @@ fragment ImageFragment on Image {
2353
2612
  ...passthroughProps,
2354
2613
  __self: this,
2355
2614
  __source: {
2356
- fileName: _jsxFileName$4,
2615
+ fileName: _jsxFileName$3,
2357
2616
  lineNumber: 68,
2358
2617
  columnNumber: 9
2359
2618
  }
@@ -2365,7 +2624,7 @@ fragment ImageFragment on Image {
2365
2624
  ...passthroughProps,
2366
2625
  __self: this,
2367
2626
  __source: {
2368
- fileName: _jsxFileName$4,
2627
+ fileName: _jsxFileName$3,
2369
2628
  lineNumber: 76,
2370
2629
  columnNumber: 9
2371
2630
  }
@@ -2379,7 +2638,7 @@ fragment ImageFragment on Image {
2379
2638
  ...passthroughProps,
2380
2639
  __self: this,
2381
2640
  __source: {
2382
- fileName: _jsxFileName$4,
2641
+ fileName: _jsxFileName$3,
2383
2642
  lineNumber: 86,
2384
2643
  columnNumber: 9
2385
2644
  }
@@ -2391,7 +2650,7 @@ fragment ImageFragment on Image {
2391
2650
  ...passthroughProps,
2392
2651
  __self: this,
2393
2652
  __source: {
2394
- fileName: _jsxFileName$4,
2653
+ fileName: _jsxFileName$3,
2395
2654
  lineNumber: 94,
2396
2655
  columnNumber: 9
2397
2656
  }
@@ -2406,7 +2665,7 @@ fragment ImageFragment on Image {
2406
2665
  },
2407
2666
  __self: this,
2408
2667
  __source: {
2409
- fileName: _jsxFileName$4,
2668
+ fileName: _jsxFileName$3,
2410
2669
  lineNumber: 102,
2411
2670
  columnNumber: 9
2412
2671
  }
@@ -2421,7 +2680,7 @@ fragment ImageFragment on Image {
2421
2680
  },
2422
2681
  __self: this,
2423
2682
  __source: {
2424
- fileName: _jsxFileName$4,
2683
+ fileName: _jsxFileName$3,
2425
2684
  lineNumber: 111,
2426
2685
  columnNumber: 9
2427
2686
  }
@@ -2434,7 +2693,7 @@ fragment ImageFragment on Image {
2434
2693
  ...passthroughProps,
2435
2694
  __self: this,
2436
2695
  __source: {
2437
- fileName: _jsxFileName$4,
2696
+ fileName: _jsxFileName$3,
2438
2697
  lineNumber: 122,
2439
2698
  columnNumber: 9
2440
2699
  }
@@ -2446,7 +2705,7 @@ fragment ImageFragment on Image {
2446
2705
  ...passthroughProps,
2447
2706
  __self: this,
2448
2707
  __source: {
2449
- fileName: _jsxFileName$4,
2708
+ fileName: _jsxFileName$3,
2450
2709
  lineNumber: 133,
2451
2710
  columnNumber: 9
2452
2711
  }
@@ -2461,7 +2720,7 @@ fragment ImageFragment on Image {
2461
2720
  ...passthroughProps,
2462
2721
  __self: this,
2463
2722
  __source: {
2464
- fileName: _jsxFileName$4,
2723
+ fileName: _jsxFileName$3,
2465
2724
  lineNumber: 144,
2466
2725
  columnNumber: 9
2467
2726
  }
@@ -2474,7 +2733,7 @@ fragment ImageFragment on Image {
2474
2733
  ...passthroughProps,
2475
2734
  __self: this,
2476
2735
  __source: {
2477
- fileName: _jsxFileName$4,
2736
+ fileName: _jsxFileName$3,
2478
2737
  lineNumber: 154,
2479
2738
  columnNumber: 9
2480
2739
  }
@@ -2482,7 +2741,7 @@ fragment ImageFragment on Image {
2482
2741
  key: `${ref != null ? ref : ""}-${index2}`,
2483
2742
  __self: this,
2484
2743
  __source: {
2485
- fileName: _jsxFileName$4,
2744
+ fileName: _jsxFileName$3,
2486
2745
  lineNumber: 158,
2487
2746
  columnNumber: 13
2488
2747
  }
@@ -2496,7 +2755,7 @@ fragment ImageFragment on Image {
2496
2755
  ...passthroughProps,
2497
2756
  __self: this,
2498
2757
  __source: {
2499
- fileName: _jsxFileName$4,
2758
+ fileName: _jsxFileName$3,
2500
2759
  lineNumber: 167,
2501
2760
  columnNumber: 11
2502
2761
  }
@@ -2508,7 +2767,7 @@ fragment ImageFragment on Image {
2508
2767
  ...passthroughProps,
2509
2768
  __self: this,
2510
2769
  __source: {
2511
- fileName: _jsxFileName$4,
2770
+ fileName: _jsxFileName$3,
2512
2771
  lineNumber: 172,
2513
2772
  columnNumber: 11
2514
2773
  }
@@ -2516,7 +2775,7 @@ fragment ImageFragment on Image {
2516
2775
  data: ref.previewImage,
2517
2776
  __self: this,
2518
2777
  __source: {
2519
- fileName: _jsxFileName$4,
2778
+ fileName: _jsxFileName$3,
2520
2779
  lineNumber: 173,
2521
2780
  columnNumber: 13
2522
2781
  }
@@ -2528,7 +2787,7 @@ fragment ImageFragment on Image {
2528
2787
  data: ref,
2529
2788
  __self: this,
2530
2789
  __source: {
2531
- fileName: _jsxFileName$4,
2790
+ fileName: _jsxFileName$3,
2532
2791
  lineNumber: 178,
2533
2792
  columnNumber: 16
2534
2793
  }
@@ -2541,7 +2800,7 @@ fragment ImageFragment on Image {
2541
2800
  ...passthroughProps,
2542
2801
  __self: this,
2543
2802
  __source: {
2544
- fileName: _jsxFileName$4,
2803
+ fileName: _jsxFileName$3,
2545
2804
  lineNumber: 185,
2546
2805
  columnNumber: 5
2547
2806
  }
@@ -2859,7 +3118,7 @@ fragment ImageFragment on Image {
2859
3118
  return () => memoized != null ? memoized : memoized = new Intl.NumberFormat(locale, options);
2860
3119
  }, [locale, options]);
2861
3120
  }
2862
- var _jsxFileName$3 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Money.tsx";
3121
+ var _jsxFileName$2 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Money.tsx";
2863
3122
  function Money({
2864
3123
  data,
2865
3124
  as,
@@ -2888,7 +3147,7 @@ fragment ImageFragment on Image {
2888
3147
  ...passthroughProps,
2889
3148
  __self: this,
2890
3149
  __source: {
2891
- fileName: _jsxFileName$3,
3150
+ fileName: _jsxFileName$2,
2892
3151
  lineNumber: 65,
2893
3152
  columnNumber: 5
2894
3153
  }
@@ -2897,7 +3156,7 @@ fragment ImageFragment on Image {
2897
3156
  function isMoney(maybeMoney) {
2898
3157
  return typeof maybeMoney.amount === "string" && !!maybeMoney.amount && typeof maybeMoney.currencyCode === "string" && !!maybeMoney.currencyCode;
2899
3158
  }
2900
- var _jsxFileName$2 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductPrice.tsx";
3159
+ var _jsxFileName$1 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductPrice.tsx";
2901
3160
  function ProductPrice(props) {
2902
3161
  var _a, _b, _c, _d, _e, _f, _g, _h;
2903
3162
  const {
@@ -2947,7 +3206,7 @@ fragment ImageFragment on Image {
2947
3206
  measurement,
2948
3207
  __self: this,
2949
3208
  __source: {
2950
- fileName: _jsxFileName$2,
3209
+ fileName: _jsxFileName$1,
2951
3210
  lineNumber: 81,
2952
3211
  columnNumber: 7
2953
3212
  }
@@ -2958,171 +3217,12 @@ fragment ImageFragment on Image {
2958
3217
  data: price,
2959
3218
  __self: this,
2960
3219
  __source: {
2961
- fileName: _jsxFileName$2,
3220
+ fileName: _jsxFileName$1,
2962
3221
  lineNumber: 85,
2963
3222
  columnNumber: 10
2964
3223
  }
2965
3224
  });
2966
3225
  }
2967
- var _jsxFileName$1 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductProvider.tsx";
2968
- const ProductOptionsContext = React.createContext(null);
2969
- function ProductProvider({
2970
- children,
2971
- data: product,
2972
- initialVariantId: explicitVariantId
2973
- }) {
2974
- const variants = React.useMemo(() => {
2975
- var _a;
2976
- return flattenConnection((_a = product.variants) != null ? _a : {});
2977
- }, [product.variants]);
2978
- if (!isProductVariantArray(variants)) {
2979
- throw new Error(`<ProductProvider/> requires 'product.variants.nodes' or 'product.variants.edges'`);
2980
- }
2981
- const options = React.useMemo(() => getOptions(variants), [variants]);
2982
- const [selectedVariant, setSelectedVariant] = React.useState(() => getVariantBasedOnIdProp(explicitVariantId, variants));
2983
- const [selectedOptions, setSelectedOptions] = React.useState(() => getSelectedOptions(selectedVariant));
2984
- React.useEffect(() => {
2985
- const newSelectedVariant = getVariantBasedOnIdProp(explicitVariantId, variants);
2986
- setSelectedVariant(newSelectedVariant);
2987
- setSelectedOptions(getSelectedOptions(newSelectedVariant));
2988
- }, [explicitVariantId, variants]);
2989
- const setSelectedOption = React.useCallback((name, value2) => {
2990
- setSelectedOptions((selectedOptions2) => {
2991
- const opts = {
2992
- ...selectedOptions2,
2993
- [name]: value2
2994
- };
2995
- setSelectedVariant(getSelectedVariant(variants, opts));
2996
- return opts;
2997
- });
2998
- }, [setSelectedOptions, variants]);
2999
- const isOptionInStock = React.useCallback((option, value2) => {
3000
- var _a;
3001
- const proposedVariant = getSelectedVariant(variants, {
3002
- ...selectedOptions,
3003
- ...{
3004
- [option]: value2
3005
- }
3006
- });
3007
- return (_a = proposedVariant == null ? void 0 : proposedVariant.availableForSale) != null ? _a : true;
3008
- }, [selectedOptions, variants]);
3009
- const sellingPlanGroups = React.useMemo(() => {
3010
- var _a;
3011
- return flattenConnection((_a = product.sellingPlanGroups) != null ? _a : {}).map((sellingPlanGroup) => {
3012
- var _a2;
3013
- return {
3014
- ...sellingPlanGroup,
3015
- sellingPlans: flattenConnection((_a2 = sellingPlanGroup == null ? void 0 : sellingPlanGroup.sellingPlans) != null ? _a2 : {})
3016
- };
3017
- });
3018
- }, [product.sellingPlanGroups]);
3019
- const [selectedSellingPlan, setSelectedSellingPlan] = React.useState(void 0);
3020
- const selectedSellingPlanAllocation = React.useMemo(() => {
3021
- var _a, _b;
3022
- if (!selectedVariant || !selectedSellingPlan) {
3023
- return;
3024
- }
3025
- if (!((_a = selectedVariant.sellingPlanAllocations) == null ? void 0 : _a.nodes) && !((_b = selectedVariant.sellingPlanAllocations) == null ? void 0 : _b.edges)) {
3026
- throw new Error(`<ProductProvider/>: You must include 'sellingPlanAllocations.nodes' or 'sellingPlanAllocations.edges' in your variants in order to calculate selectedSellingPlanAllocation`);
3027
- }
3028
- return flattenConnection(selectedVariant.sellingPlanAllocations).find((allocation) => {
3029
- var _a2;
3030
- return ((_a2 = allocation == null ? void 0 : allocation.sellingPlan) == null ? void 0 : _a2.id) === selectedSellingPlan.id;
3031
- });
3032
- }, [selectedVariant, selectedSellingPlan]);
3033
- const value = React.useMemo(() => ({
3034
- variants,
3035
- variantsConnection: product.variants,
3036
- options,
3037
- selectedVariant,
3038
- setSelectedVariant,
3039
- selectedOptions,
3040
- setSelectedOption,
3041
- setSelectedOptions,
3042
- isOptionInStock,
3043
- selectedSellingPlan,
3044
- setSelectedSellingPlan,
3045
- selectedSellingPlanAllocation,
3046
- sellingPlanGroups,
3047
- sellingPlanGroupsConnection: product.sellingPlanGroups
3048
- }), [isOptionInStock, options, product.sellingPlanGroups, product.variants, selectedOptions, selectedSellingPlan, selectedSellingPlanAllocation, selectedVariant, sellingPlanGroups, setSelectedOption, variants]);
3049
- return /* @__PURE__ */ React__default.default.createElement(ProductOptionsContext.Provider, {
3050
- value,
3051
- __self: this,
3052
- __source: {
3053
- fileName: _jsxFileName$1,
3054
- lineNumber: 201,
3055
- columnNumber: 5
3056
- }
3057
- }, children);
3058
- }
3059
- function useProduct() {
3060
- const context = React.useContext(ProductOptionsContext);
3061
- if (!context) {
3062
- throw new Error(`'useProduct' must be a child of <ProductProvider />`);
3063
- }
3064
- return context;
3065
- }
3066
- function getSelectedVariant(variants, choices) {
3067
- var _a, _b;
3068
- if (!variants.length || ((_b = (_a = variants == null ? void 0 : variants[0]) == null ? void 0 : _a.selectedOptions) == null ? void 0 : _b.length) !== Object.keys(choices).length) {
3069
- return;
3070
- }
3071
- return variants == null ? void 0 : variants.find((variant) => {
3072
- return Object.entries(choices).every(([name, value]) => {
3073
- var _a2;
3074
- return (_a2 = variant == null ? void 0 : variant.selectedOptions) == null ? void 0 : _a2.some((option) => (option == null ? void 0 : option.name) === name && (option == null ? void 0 : option.value) === value);
3075
- });
3076
- });
3077
- }
3078
- function getOptions(variants) {
3079
- const map = variants.reduce((memo, variant) => {
3080
- var _a;
3081
- if (!variant.selectedOptions) {
3082
- throw new Error(`'getOptions' requires 'variant.selectedOptions'`);
3083
- }
3084
- (_a = variant == null ? void 0 : variant.selectedOptions) == null ? void 0 : _a.forEach((opt) => {
3085
- var _a2, _b, _c, _d;
3086
- memo[(_a2 = opt == null ? void 0 : opt.name) != null ? _a2 : ""] = memo[(_b = opt == null ? void 0 : opt.name) != null ? _b : ""] || /* @__PURE__ */ new Set();
3087
- memo[(_c = opt == null ? void 0 : opt.name) != null ? _c : ""].add((_d = opt == null ? void 0 : opt.value) != null ? _d : "");
3088
- });
3089
- return memo;
3090
- }, {});
3091
- return Object.keys(map).map((option) => {
3092
- return {
3093
- name: option,
3094
- values: Array.from(map[option])
3095
- };
3096
- });
3097
- }
3098
- function getVariantBasedOnIdProp(explicitVariantId, variants) {
3099
- if (explicitVariantId) {
3100
- const foundVariant = variants.find((variant) => (variant == null ? void 0 : variant.id) === explicitVariantId);
3101
- if (!foundVariant) {
3102
- console.warn(`<ProductProvider/> received a 'initialVariantId' prop, but could not actually find a variant with that ID`);
3103
- }
3104
- return foundVariant;
3105
- }
3106
- if (explicitVariantId === null) {
3107
- return null;
3108
- }
3109
- if (explicitVariantId === void 0) {
3110
- return variants.find((variant) => variant == null ? void 0 : variant.availableForSale) || variants[0];
3111
- }
3112
- }
3113
- function getSelectedOptions(selectedVariant) {
3114
- return (selectedVariant == null ? void 0 : selectedVariant.selectedOptions) ? selectedVariant.selectedOptions.reduce((memo, optionSet) => {
3115
- var _a, _b;
3116
- memo[(_a = optionSet == null ? void 0 : optionSet.name) != null ? _a : ""] = (_b = optionSet == null ? void 0 : optionSet.value) != null ? _b : "";
3117
- return memo;
3118
- }, {}) : {};
3119
- }
3120
- function isProductVariantArray(maybeVariantArray) {
3121
- if (!maybeVariantArray || !Array.isArray(maybeVariantArray)) {
3122
- return false;
3123
- }
3124
- return true;
3125
- }
3126
3226
  var _jsxFileName = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopPayButton.tsx";
3127
3227
  const SHOPJS_URL = "https://cdn.shopify.com/shopifycloud/shop-js/v1.0/client.js";
3128
3228
  function ShopPayButton({
@@ -3256,6 +3356,7 @@ fragment ImageFragment on Image {
3256
3356
  }
3257
3357
  };
3258
3358
  }
3359
+ exports2.AddToCartButton = AddToCartButton;
3259
3360
  exports2.CartProvider = CartProvider;
3260
3361
  exports2.ExternalVideo = ExternalVideo;
3261
3362
  exports2.Image = Image;