@shopify/hydrogen-react 2024.7.1 → 2024.7.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.
- package/dist/browser-dev/analytics.mjs +8 -0
- package/dist/browser-dev/analytics.mjs.map +1 -1
- package/dist/browser-dev/useMoney.mjs +43 -29
- package/dist/browser-dev/useMoney.mjs.map +1 -1
- package/dist/browser-prod/analytics.mjs +8 -0
- package/dist/browser-prod/analytics.mjs.map +1 -1
- package/dist/browser-prod/useMoney.mjs +43 -29
- package/dist/browser-prod/useMoney.mjs.map +1 -1
- package/dist/node-dev/analytics.js +8 -0
- package/dist/node-dev/analytics.js.map +1 -1
- package/dist/node-dev/analytics.mjs +8 -0
- package/dist/node-dev/analytics.mjs.map +1 -1
- package/dist/node-dev/useMoney.js +43 -29
- package/dist/node-dev/useMoney.js.map +1 -1
- package/dist/node-dev/useMoney.mjs +43 -29
- package/dist/node-dev/useMoney.mjs.map +1 -1
- package/dist/node-prod/analytics.js +8 -0
- package/dist/node-prod/analytics.js.map +1 -1
- package/dist/node-prod/analytics.mjs +8 -0
- package/dist/node-prod/analytics.mjs.map +1 -1
- package/dist/node-prod/useMoney.js +43 -29
- package/dist/node-prod/useMoney.js.map +1 -1
- package/dist/node-prod/useMoney.mjs +43 -29
- package/dist/node-prod/useMoney.mjs.map +1 -1
- package/dist/umd/hydrogen-react.dev.js +51 -29
- package/dist/umd/hydrogen-react.dev.js.map +1 -1
- package/dist/umd/hydrogen-react.prod.js +17 -17
- package/dist/umd/hydrogen-react.prod.js.map +1 -1
- package/package.json +2 -2
|
@@ -9,32 +9,40 @@ function useMoney(money) {
|
|
|
9
9
|
);
|
|
10
10
|
}
|
|
11
11
|
const amount = parseFloat(money.amount);
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const {
|
|
13
|
+
defaultFormatter,
|
|
14
|
+
nameFormatter,
|
|
15
|
+
narrowSymbolFormatter,
|
|
16
|
+
withoutTrailingZerosFormatter,
|
|
17
|
+
withoutCurrencyFormatter,
|
|
18
|
+
withoutTrailingZerosOrCurrencyFormatter
|
|
19
|
+
} = useMemo(() => {
|
|
20
|
+
const options = {
|
|
14
21
|
style: "currency",
|
|
15
22
|
currency: money.currencyCode
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
defaultFormatter: getLazyFormatter(locale, options),
|
|
26
|
+
nameFormatter: getLazyFormatter(locale, {
|
|
27
|
+
...options,
|
|
28
|
+
currencyDisplay: "name"
|
|
29
|
+
}),
|
|
30
|
+
narrowSymbolFormatter: getLazyFormatter(locale, {
|
|
31
|
+
...options,
|
|
32
|
+
currencyDisplay: "narrowSymbol"
|
|
33
|
+
}),
|
|
34
|
+
withoutTrailingZerosFormatter: getLazyFormatter(locale, {
|
|
35
|
+
...options,
|
|
36
|
+
minimumFractionDigits: 0,
|
|
37
|
+
maximumFractionDigits: 0
|
|
38
|
+
}),
|
|
39
|
+
withoutCurrencyFormatter: getLazyFormatter(locale),
|
|
40
|
+
withoutTrailingZerosOrCurrencyFormatter: getLazyFormatter(locale, {
|
|
41
|
+
minimumFractionDigits: 0,
|
|
42
|
+
maximumFractionDigits: 0
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}, [money.currencyCode, locale]);
|
|
38
46
|
const isPartCurrency = (part) => part.type === "currency";
|
|
39
47
|
const lazyFormatters = useMemo(
|
|
40
48
|
() => ({
|
|
@@ -87,11 +95,17 @@ function useMoney(money) {
|
|
|
87
95
|
[lazyFormatters]
|
|
88
96
|
);
|
|
89
97
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
const formatterCache = /* @__PURE__ */ new Map();
|
|
99
|
+
function getLazyFormatter(locale, options) {
|
|
100
|
+
const key = JSON.stringify([locale, options]);
|
|
101
|
+
return function() {
|
|
102
|
+
let formatter = formatterCache.get(key);
|
|
103
|
+
if (!formatter) {
|
|
104
|
+
formatter = new Intl.NumberFormat(locale, options);
|
|
105
|
+
formatterCache.set(key, formatter);
|
|
106
|
+
}
|
|
107
|
+
return formatter;
|
|
108
|
+
};
|
|
95
109
|
}
|
|
96
110
|
export {
|
|
97
111
|
useMoney
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMoney.mjs","sources":["../../src/useMoney.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {CurrencyCode, MoneyV2} from './storefront-api-types.js';\n\nexport type UseMoneyValue = {\n /**\n * The currency code from the `MoneyV2` object.\n */\n currencyCode: CurrencyCode;\n /**\n * The name for the currency code, returned by `Intl.NumberFormat`.\n */\n currencyName?: string;\n /**\n * The currency symbol returned by `Intl.NumberFormat`.\n */\n currencySymbol?: string;\n /**\n * The currency narrow symbol returned by `Intl.NumberFormat`.\n */\n currencyNarrowSymbol?: string;\n /**\n * The localized amount, without any currency symbols or non-number types from the `Intl.NumberFormat.formatToParts` parts.\n */\n amount: string;\n /**\n * All parts returned by `Intl.NumberFormat.formatToParts`.\n */\n parts: Intl.NumberFormatPart[];\n /**\n * A string returned by `new Intl.NumberFormat` for the amount and currency code,\n * using the `locale` value in the [`LocalizationProvider` component](https://shopify.dev/api/hydrogen/components/localization/localizationprovider).\n */\n localizedString: string;\n /**\n * The `MoneyV2` object provided as an argument to the hook.\n */\n original: MoneyV2;\n /**\n * A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `$640`.\n * `$640.42` remains `$640.42`.\n */\n withoutTrailingZeros: string;\n /**\n * A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `640`.\n * `$640.42` turns into `640.42`.\n */\n withoutTrailingZerosAndCurrency: string;\n};\n\n/**\n * The `useMoney` hook takes a [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) and returns a\n * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by\n * [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\n * Uses `locale` from `ShopifyProvider`\n * \n * @see {@link https://shopify.dev/api/hydrogen/hooks/usemoney}\n * @example initialize the money object\n * ```ts\n * const money = useMoney({\n * amount: '100.00',\n * currencyCode: 'USD'\n * })\n * ```\n * \n *\n * @example basic usage, outputs: $100.00\n * ```ts\n * money.localizedString\n * ```\n * \n *\n * @example without currency, outputs: 100.00\n * ```ts\n * money.amount\n * ```\n * \n *\n * @example without trailing zeros, outputs: $100\n * ```ts\n * money.withoutTrailingZeros\n * ```\n * \n *\n * @example currency name, outputs: US dollars\n * ```ts\n * money.currencyCode\n * ```\n * \n *\n * @example currency symbol, outputs: $\n * ```ts\n * money.currencySymbol\n * ```\n * \n *\n * @example without currency and without trailing zeros, outputs: 100\n * ```ts\n * money.withoutTrailingZerosAndCurrency\n * ```\n */\nexport function useMoney(money: MoneyV2): UseMoneyValue {\n const {countryIsoCode, languageIsoCode} = useShop();\n const locale = languageIsoCode.includes('_')\n ? languageIsoCode.replace('_', '-')\n : `${languageIsoCode}-${countryIsoCode}`;\n\n if (!locale) {\n throw new Error(\n `useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`,\n );\n }\n\n const amount = parseFloat(money.amount);\n\n const
|
|
1
|
+
{"version":3,"file":"useMoney.mjs","sources":["../../src/useMoney.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {CurrencyCode, MoneyV2} from './storefront-api-types.js';\n\nexport type UseMoneyValue = {\n /**\n * The currency code from the `MoneyV2` object.\n */\n currencyCode: CurrencyCode;\n /**\n * The name for the currency code, returned by `Intl.NumberFormat`.\n */\n currencyName?: string;\n /**\n * The currency symbol returned by `Intl.NumberFormat`.\n */\n currencySymbol?: string;\n /**\n * The currency narrow symbol returned by `Intl.NumberFormat`.\n */\n currencyNarrowSymbol?: string;\n /**\n * The localized amount, without any currency symbols or non-number types from the `Intl.NumberFormat.formatToParts` parts.\n */\n amount: string;\n /**\n * All parts returned by `Intl.NumberFormat.formatToParts`.\n */\n parts: Intl.NumberFormatPart[];\n /**\n * A string returned by `new Intl.NumberFormat` for the amount and currency code,\n * using the `locale` value in the [`LocalizationProvider` component](https://shopify.dev/api/hydrogen/components/localization/localizationprovider).\n */\n localizedString: string;\n /**\n * The `MoneyV2` object provided as an argument to the hook.\n */\n original: MoneyV2;\n /**\n * A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `$640`.\n * `$640.42` remains `$640.42`.\n */\n withoutTrailingZeros: string;\n /**\n * A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains.\n * For example, `$640.00` turns into `640`.\n * `$640.42` turns into `640.42`.\n */\n withoutTrailingZerosAndCurrency: string;\n};\n\n/**\n * The `useMoney` hook takes a [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) and returns a\n * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by\n * [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\n * Uses `locale` from `ShopifyProvider`\n * \n * @see {@link https://shopify.dev/api/hydrogen/hooks/usemoney}\n * @example initialize the money object\n * ```ts\n * const money = useMoney({\n * amount: '100.00',\n * currencyCode: 'USD'\n * })\n * ```\n * \n *\n * @example basic usage, outputs: $100.00\n * ```ts\n * money.localizedString\n * ```\n * \n *\n * @example without currency, outputs: 100.00\n * ```ts\n * money.amount\n * ```\n * \n *\n * @example without trailing zeros, outputs: $100\n * ```ts\n * money.withoutTrailingZeros\n * ```\n * \n *\n * @example currency name, outputs: US dollars\n * ```ts\n * money.currencyCode\n * ```\n * \n *\n * @example currency symbol, outputs: $\n * ```ts\n * money.currencySymbol\n * ```\n * \n *\n * @example without currency and without trailing zeros, outputs: 100\n * ```ts\n * money.withoutTrailingZerosAndCurrency\n * ```\n */\nexport function useMoney(money: MoneyV2): UseMoneyValue {\n const {countryIsoCode, languageIsoCode} = useShop();\n const locale = languageIsoCode.includes('_')\n ? languageIsoCode.replace('_', '-')\n : `${languageIsoCode}-${countryIsoCode}`;\n\n if (!locale) {\n throw new Error(\n `useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work`,\n );\n }\n\n const amount = parseFloat(money.amount);\n\n const {\n defaultFormatter,\n nameFormatter,\n narrowSymbolFormatter,\n withoutTrailingZerosFormatter,\n withoutCurrencyFormatter,\n withoutTrailingZerosOrCurrencyFormatter,\n } = useMemo(() => {\n const options = {\n style: 'currency' as const,\n currency: money.currencyCode,\n };\n\n return {\n defaultFormatter: getLazyFormatter(locale, options),\n nameFormatter: getLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'name',\n }),\n narrowSymbolFormatter: getLazyFormatter(locale, {\n ...options,\n currencyDisplay: 'narrowSymbol',\n }),\n withoutTrailingZerosFormatter: getLazyFormatter(locale, {\n ...options,\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n }),\n withoutCurrencyFormatter: getLazyFormatter(locale),\n withoutTrailingZerosOrCurrencyFormatter: getLazyFormatter(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n }),\n };\n }, [money.currencyCode, locale]);\n\n const isPartCurrency = (part: Intl.NumberFormatPart): boolean =>\n part.type === 'currency';\n\n // By wrapping these properties in functions, we only\n // create formatters if they are going to be used.\n const lazyFormatters = useMemo(\n () => ({\n original: () => money,\n currencyCode: () => money.currencyCode,\n\n localizedString: () => defaultFormatter().format(amount),\n\n parts: () => defaultFormatter().formatToParts(amount),\n\n withoutTrailingZeros: () =>\n amount % 1 === 0\n ? withoutTrailingZerosFormatter().format(amount)\n : defaultFormatter().format(amount),\n\n withoutTrailingZerosAndCurrency: () =>\n amount % 1 === 0\n ? withoutTrailingZerosOrCurrencyFormatter().format(amount)\n : withoutCurrencyFormatter().format(amount),\n\n currencyName: () =>\n nameFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"US dollars\"\n\n currencySymbol: () =>\n defaultFormatter().formatToParts(amount).find(isPartCurrency)?.value ??\n money.currencyCode, // e.g. \"USD\"\n\n currencyNarrowSymbol: () =>\n narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)\n ?.value ?? '', // e.g. \"$\"\n\n amount: () =>\n defaultFormatter()\n .formatToParts(amount)\n .filter((part) =>\n ['decimal', 'fraction', 'group', 'integer', 'literal'].includes(\n part.type,\n ),\n )\n .map((part) => part.value)\n .join(''),\n }),\n [\n money,\n amount,\n nameFormatter,\n defaultFormatter,\n narrowSymbolFormatter,\n withoutCurrencyFormatter,\n withoutTrailingZerosFormatter,\n withoutTrailingZerosOrCurrencyFormatter,\n ],\n );\n\n // Call functions automatically when the properties are accessed\n // to keep these functions as an implementation detail.\n return useMemo(\n () =>\n new Proxy(lazyFormatters as unknown as UseMoneyValue, {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n get: (target, key) => Reflect.get(target, key)?.call(null),\n }),\n [lazyFormatters],\n );\n}\n\nconst formatterCache = new Map<string, Intl.NumberFormat>();\n\nfunction getLazyFormatter(\n locale: string,\n options?: Intl.NumberFormatOptions,\n): () => Intl.NumberFormat {\n const key = JSON.stringify([locale, options]);\n\n return function (): Intl.NumberFormat {\n let formatter = formatterCache.get(key);\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, options);\n formatterCache.set(key, formatter);\n }\n return formatter;\n };\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -2649,8 +2649,16 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
|
|
|
2649
2649
|
return Promise.resolve();
|
|
2650
2650
|
}
|
|
2651
2651
|
}
|
|
2652
|
+
function isLighthouseUserAgent() {
|
|
2653
|
+
if (typeof window === "undefined" || !window.navigator)
|
|
2654
|
+
return false;
|
|
2655
|
+
return /Chrome-Lighthouse/.test(window.navigator.userAgent);
|
|
2656
|
+
}
|
|
2652
2657
|
const ERROR_MESSAGE = "sendShopifyAnalytics request is unsuccessful";
|
|
2653
2658
|
function sendToShopify(events, shopDomain) {
|
|
2659
|
+
if (isLighthouseUserAgent()) {
|
|
2660
|
+
return Promise.resolve();
|
|
2661
|
+
}
|
|
2654
2662
|
const eventsToBeSent = {
|
|
2655
2663
|
events,
|
|
2656
2664
|
metadata: {
|
|
@@ -2844,32 +2852,40 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
|
|
|
2844
2852
|
);
|
|
2845
2853
|
}
|
|
2846
2854
|
const amount = parseFloat(money.amount);
|
|
2847
|
-
const
|
|
2848
|
-
|
|
2855
|
+
const {
|
|
2856
|
+
defaultFormatter,
|
|
2857
|
+
nameFormatter,
|
|
2858
|
+
narrowSymbolFormatter,
|
|
2859
|
+
withoutTrailingZerosFormatter,
|
|
2860
|
+
withoutCurrencyFormatter,
|
|
2861
|
+
withoutTrailingZerosOrCurrencyFormatter
|
|
2862
|
+
} = React$1.useMemo(() => {
|
|
2863
|
+
const options = {
|
|
2849
2864
|
style: "currency",
|
|
2850
2865
|
currency: money.currencyCode
|
|
2851
|
-
}
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2866
|
+
};
|
|
2867
|
+
return {
|
|
2868
|
+
defaultFormatter: getLazyFormatter(locale, options),
|
|
2869
|
+
nameFormatter: getLazyFormatter(locale, {
|
|
2870
|
+
...options,
|
|
2871
|
+
currencyDisplay: "name"
|
|
2872
|
+
}),
|
|
2873
|
+
narrowSymbolFormatter: getLazyFormatter(locale, {
|
|
2874
|
+
...options,
|
|
2875
|
+
currencyDisplay: "narrowSymbol"
|
|
2876
|
+
}),
|
|
2877
|
+
withoutTrailingZerosFormatter: getLazyFormatter(locale, {
|
|
2878
|
+
...options,
|
|
2879
|
+
minimumFractionDigits: 0,
|
|
2880
|
+
maximumFractionDigits: 0
|
|
2881
|
+
}),
|
|
2882
|
+
withoutCurrencyFormatter: getLazyFormatter(locale),
|
|
2883
|
+
withoutTrailingZerosOrCurrencyFormatter: getLazyFormatter(locale, {
|
|
2884
|
+
minimumFractionDigits: 0,
|
|
2885
|
+
maximumFractionDigits: 0
|
|
2886
|
+
})
|
|
2887
|
+
};
|
|
2888
|
+
}, [money.currencyCode, locale]);
|
|
2873
2889
|
const isPartCurrency = (part) => part.type === "currency";
|
|
2874
2890
|
const lazyFormatters = React$1.useMemo(
|
|
2875
2891
|
() => ({
|
|
@@ -2922,11 +2938,17 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
|
|
|
2922
2938
|
[lazyFormatters]
|
|
2923
2939
|
);
|
|
2924
2940
|
}
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2941
|
+
const formatterCache = /* @__PURE__ */ new Map();
|
|
2942
|
+
function getLazyFormatter(locale, options) {
|
|
2943
|
+
const key = JSON.stringify([locale, options]);
|
|
2944
|
+
return function() {
|
|
2945
|
+
let formatter = formatterCache.get(key);
|
|
2946
|
+
if (!formatter) {
|
|
2947
|
+
formatter = new Intl.NumberFormat(locale, options);
|
|
2948
|
+
formatterCache.set(key, formatter);
|
|
2949
|
+
}
|
|
2950
|
+
return formatter;
|
|
2951
|
+
};
|
|
2930
2952
|
}
|
|
2931
2953
|
function Money({
|
|
2932
2954
|
data,
|