@shopify/hydrogen 2023.1.0-alpha.1 → 2023.1.0-alpha.2

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.
@@ -1,8 +1,8 @@
1
1
  import { __commonJS, __toESM, logSeoTags } from './chunk-5MQMAYYE.js';
2
- import { createStorefrontClient as createStorefrontClient$1 } from '@shopify/storefront-kit-react';
3
- export { AnalyticsEventName, AnalyticsPageType, ExternalVideo, Image, MediaFile, ModelViewer, Money, ShopPayButton, ShopifyAppSource, Video, flattenConnection, getClientBrowserParameters, getShopifyCookies, parseMetafield, sendShopifyAnalytics, storefrontApiCustomScalars, useMoney, useShopifyCookies } from '@shopify/storefront-kit-react';
2
+ import { createStorefrontClient as createStorefrontClient$1 } from '@shopify/hydrogen-react';
3
+ export { AnalyticsEventName, AnalyticsPageType, ExternalVideo, Image, MediaFile, ModelViewer, Money, ShopPayButton, ShopifySalesChannel, Video, flattenConnection, getClientBrowserParameters, getShopifyCookies, parseMetafield, sendShopifyAnalytics, storefrontApiCustomScalars, useMoney, useShopifyCookies } from '@shopify/hydrogen-react';
4
4
  import { redirect } from '@remix-run/server-runtime';
5
- import { useMatches, useLocation } from '@remix-run/react';
5
+ import { useMatches, useFetchers, useLocation } from '@remix-run/react';
6
6
 
7
7
  // ../../node_modules/react/cjs/react.development.js
8
8
  var require_react_development = __commonJS({
@@ -2119,11 +2119,12 @@ var isMutationRE = /(^|}\s)mutation[\s({]/im;
2119
2119
  function minifyQuery(string) {
2120
2120
  return string.replace(/\s*#.*$/gm, "").replace(/\s+/gm, " ").trim();
2121
2121
  }
2122
+ var defaultI18n = { language: "EN", country: "US" };
2122
2123
  function createStorefrontClient({
2123
2124
  cache,
2124
2125
  waitUntil,
2125
2126
  buyerIp,
2126
- i18n = { language: "EN", country: "US" },
2127
+ i18n,
2127
2128
  requestGroupId = generateUUID(),
2128
2129
  ...clientOptions
2129
2130
  }) {
@@ -2216,7 +2217,7 @@ function createStorefrontClient({
2216
2217
  getShopifyDomain,
2217
2218
  getApiUrl: getStorefrontApiUrl,
2218
2219
  isApiError: isStorefrontApiError,
2219
- i18n: { pathPrefix: "", ...i18n }
2220
+ i18n: i18n ?? defaultI18n
2220
2221
  }
2221
2222
  };
2222
2223
  }
@@ -2438,9 +2439,43 @@ function graphiqlLoader({ context } = {}) {
2438
2439
  { status: 200, headers: { "content-type": "text/html" } }
2439
2440
  );
2440
2441
  }
2442
+ function useDataFromMatches(dataKey) {
2443
+ const matches = useMatches();
2444
+ const data = {};
2445
+ matches.forEach((event) => {
2446
+ const eventData = event?.data;
2447
+ if (eventData && eventData[dataKey]) {
2448
+ Object.assign(data, eventData[dataKey]);
2449
+ }
2450
+ });
2451
+ return data;
2452
+ }
2453
+ function useDataFromFetchers({
2454
+ formDataKey,
2455
+ formDataValue,
2456
+ dataKey
2457
+ }) {
2458
+ const fetchers = useFetchers();
2459
+ const data = {};
2460
+ for (const fetcher of fetchers) {
2461
+ const formData = fetcher.submission?.formData;
2462
+ const fetcherData = fetcher.data;
2463
+ if (formData && formData.get(formDataKey) === formDataValue && fetcherData && fetcherData[dataKey]) {
2464
+ Object.assign(data, fetcherData[dataKey]);
2465
+ try {
2466
+ if (formData.get(dataKey)) {
2467
+ const dataInForm = JSON.parse(String(formData.get(dataKey)));
2468
+ Object.assign(data, dataInForm);
2469
+ }
2470
+ } catch {
2471
+ }
2472
+ }
2473
+ }
2474
+ return Object.keys(data).length ? data : void 0;
2475
+ }
2441
2476
 
2442
2477
  // src/seo/seo.ts
2443
- var import_react = __toESM(require_react(), 1);
2478
+ var import_react2 = __toESM(require_react(), 1);
2444
2479
 
2445
2480
  // src/seo/generate-seo-tags.ts
2446
2481
  function generateSeoTags(input) {
@@ -2683,7 +2718,7 @@ function inferSchemaType(url) {
2683
2718
  }
2684
2719
 
2685
2720
  // src/seo/seo.ts
2686
- var SeoLogger = import_react.default.lazy(() => import('./log-seo-tags-7SUOHHPI.js'));
2721
+ var SeoLogger = import_react2.default.lazy(() => import('./log-seo-tags-7SUOHHPI.js'));
2687
2722
  function Seo({ debug }) {
2688
2723
  const matches = useMatches();
2689
2724
  const location = useLocation();
@@ -2705,24 +2740,24 @@ function Seo({ debug }) {
2705
2740
  logSeoTags(headTags);
2706
2741
  const html = headTags.map((tag) => {
2707
2742
  if (tag.tag === "script") {
2708
- return import_react.default.createElement(tag.tag, {
2743
+ return import_react2.default.createElement(tag.tag, {
2709
2744
  ...tag.props,
2710
2745
  key: tag.key,
2711
2746
  dangerouslySetInnerHTML: { __html: tag.children }
2712
2747
  });
2713
2748
  }
2714
- return import_react.default.createElement(
2749
+ return import_react2.default.createElement(
2715
2750
  tag.tag,
2716
2751
  { ...tag.props, key: tag.key },
2717
2752
  tag.children
2718
2753
  );
2719
2754
  });
2720
- const loggerMarkup = import_react.default.createElement(
2721
- import_react.default.Suspense,
2755
+ const loggerMarkup = import_react2.default.createElement(
2756
+ import_react2.default.Suspense,
2722
2757
  { fallback: null },
2723
- import_react.default.createElement(SeoLogger, { headTags })
2758
+ import_react2.default.createElement(SeoLogger, { headTags })
2724
2759
  );
2725
- return import_react.default.createElement(import_react.default.Fragment, null, html, debug && loggerMarkup);
2760
+ return import_react2.default.createElement(import_react2.default.Fragment, null, html, debug && loggerMarkup);
2726
2761
  }
2727
2762
  function recursivelyInvokeOrReturn(value, ...rest) {
2728
2763
  if (value instanceof Function) {
@@ -2754,6 +2789,6 @@ function recursivelyInvokeOrReturn(value, ...rest) {
2754
2789
  * LICENSE file in the root directory of this source tree.
2755
2790
  */
2756
2791
 
2757
- export { CacheCustom, CacheLong, CacheNone, CacheShort, InMemoryCache, Seo, createStorefrontClient, generateCacheControlHeader, graphiqlLoader, isStorefrontApiError, storefrontRedirect };
2792
+ export { CacheCustom, CacheLong, CacheNone, CacheShort, InMemoryCache, Seo, createStorefrontClient, generateCacheControlHeader, graphiqlLoader, isStorefrontApiError, storefrontRedirect, useDataFromFetchers, useDataFromMatches };
2758
2793
  //# sourceMappingURL=out.js.map
2759
2794
  //# sourceMappingURL=index.js.map