@shopify/hydrogen-react 0.0.0-next-8ee1ffb → 0.0.0-next-541cac7

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.
Files changed (89) hide show
  1. package/dist/browser-dev/ShopPayButton.mjs +1 -1
  2. package/dist/browser-dev/ShopPayButton.mjs.map +1 -1
  3. package/dist/browser-dev/ShopifyProvider.mjs +2 -11
  4. package/dist/browser-dev/ShopifyProvider.mjs.map +1 -1
  5. package/dist/browser-dev/cart-queries.mjs +0 -8
  6. package/dist/browser-dev/cart-queries.mjs.map +1 -1
  7. package/dist/browser-dev/index.mjs +1 -5
  8. package/dist/browser-dev/index.mjs.map +1 -1
  9. package/dist/browser-dev/{metafield-parser.mjs → parse-metafield.mjs} +16 -7
  10. package/dist/browser-dev/parse-metafield.mjs.map +1 -0
  11. package/dist/browser-prod/ShopPayButton.mjs +1 -1
  12. package/dist/browser-prod/ShopPayButton.mjs.map +1 -1
  13. package/dist/browser-prod/ShopifyProvider.mjs +2 -8
  14. package/dist/browser-prod/ShopifyProvider.mjs.map +1 -1
  15. package/dist/browser-prod/cart-queries.mjs +0 -8
  16. package/dist/browser-prod/cart-queries.mjs.map +1 -1
  17. package/dist/browser-prod/index.mjs +1 -5
  18. package/dist/browser-prod/index.mjs.map +1 -1
  19. package/dist/browser-prod/{metafield-parser.mjs → parse-metafield.mjs} +16 -7
  20. package/dist/browser-prod/parse-metafield.mjs.map +1 -0
  21. package/dist/node-dev/ShopPayButton.js +1 -1
  22. package/dist/node-dev/ShopPayButton.js.map +1 -1
  23. package/dist/node-dev/ShopPayButton.mjs +1 -1
  24. package/dist/node-dev/ShopPayButton.mjs.map +1 -1
  25. package/dist/node-dev/ShopifyProvider.js +2 -11
  26. package/dist/node-dev/ShopifyProvider.js.map +1 -1
  27. package/dist/node-dev/ShopifyProvider.mjs +2 -11
  28. package/dist/node-dev/ShopifyProvider.mjs.map +1 -1
  29. package/dist/node-dev/cart-queries.js +0 -8
  30. package/dist/node-dev/cart-queries.js.map +1 -1
  31. package/dist/node-dev/cart-queries.mjs +0 -8
  32. package/dist/node-dev/cart-queries.mjs.map +1 -1
  33. package/dist/node-dev/index.js +2 -6
  34. package/dist/node-dev/index.js.map +1 -1
  35. package/dist/node-dev/index.mjs +1 -5
  36. package/dist/node-dev/index.mjs.map +1 -1
  37. package/dist/node-dev/{metafield-parser.js → parse-metafield.js} +18 -9
  38. package/dist/node-dev/parse-metafield.js.map +1 -0
  39. package/dist/node-dev/{metafield-parser.mjs → parse-metafield.mjs} +16 -7
  40. package/dist/node-dev/parse-metafield.mjs.map +1 -0
  41. package/dist/node-prod/ShopPayButton.js +1 -1
  42. package/dist/node-prod/ShopPayButton.js.map +1 -1
  43. package/dist/node-prod/ShopPayButton.mjs +1 -1
  44. package/dist/node-prod/ShopPayButton.mjs.map +1 -1
  45. package/dist/node-prod/ShopifyProvider.js +2 -8
  46. package/dist/node-prod/ShopifyProvider.js.map +1 -1
  47. package/dist/node-prod/ShopifyProvider.mjs +2 -8
  48. package/dist/node-prod/ShopifyProvider.mjs.map +1 -1
  49. package/dist/node-prod/cart-queries.js +0 -8
  50. package/dist/node-prod/cart-queries.js.map +1 -1
  51. package/dist/node-prod/cart-queries.mjs +0 -8
  52. package/dist/node-prod/cart-queries.mjs.map +1 -1
  53. package/dist/node-prod/index.js +2 -6
  54. package/dist/node-prod/index.js.map +1 -1
  55. package/dist/node-prod/index.mjs +1 -5
  56. package/dist/node-prod/index.mjs.map +1 -1
  57. package/dist/node-prod/{metafield-parser.js → parse-metafield.js} +18 -9
  58. package/dist/node-prod/parse-metafield.js.map +1 -0
  59. package/dist/node-prod/{metafield-parser.mjs → parse-metafield.mjs} +16 -7
  60. package/dist/node-prod/parse-metafield.mjs.map +1 -0
  61. package/dist/types/ShopifyProvider.d.ts +1 -1
  62. package/dist/types/cart-queries.d.ts +1 -1
  63. package/dist/types/index.d.cts +1 -2
  64. package/dist/types/index.d.ts +1 -2
  65. package/dist/types/{metafield-parser.d.ts → parse-metafield.d.ts} +9 -5
  66. package/dist/umd/hydrogen-react.dev.js +45 -430
  67. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  68. package/dist/umd/hydrogen-react.prod.js +16 -25
  69. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  70. package/package.json +1 -1
  71. package/dist/browser-dev/Metafield.mjs +0 -301
  72. package/dist/browser-dev/Metafield.mjs.map +0 -1
  73. package/dist/browser-dev/metafield-parser.mjs.map +0 -1
  74. package/dist/browser-prod/Metafield.mjs +0 -288
  75. package/dist/browser-prod/Metafield.mjs.map +0 -1
  76. package/dist/browser-prod/metafield-parser.mjs.map +0 -1
  77. package/dist/node-dev/Metafield.js +0 -301
  78. package/dist/node-dev/Metafield.js.map +0 -1
  79. package/dist/node-dev/Metafield.mjs +0 -301
  80. package/dist/node-dev/Metafield.mjs.map +0 -1
  81. package/dist/node-dev/metafield-parser.js.map +0 -1
  82. package/dist/node-dev/metafield-parser.mjs.map +0 -1
  83. package/dist/node-prod/Metafield.js +0 -288
  84. package/dist/node-prod/Metafield.js.map +0 -1
  85. package/dist/node-prod/Metafield.mjs +0 -288
  86. package/dist/node-prod/Metafield.mjs.map +0 -1
  87. package/dist/node-prod/metafield-parser.js.map +0 -1
  88. package/dist/node-prod/metafield-parser.mjs.map +0 -1
  89. package/dist/types/Metafield.d.ts +0 -61
@@ -1,288 +0,0 @@
1
- "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const require$$0 = require("react");
4
- const ShopifyProvider = require("./ShopifyProvider.js");
5
- const Image = require("./Image.js");
6
- const Video = require("./Video.js");
7
- const flattenConnection = require("./flatten-connection.js");
8
- const jsxRuntime = require("react/jsx-runtime");
9
- function Metafield(props) {
10
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
11
- const {
12
- data,
13
- as,
14
- ...passthroughProps
15
- } = props;
16
- const {
17
- locale
18
- } = ShopifyProvider.useShop();
19
- const parsedMetafield = require$$0.useMemo(() => parseMetafield(data), [data]);
20
- if (!parsedMetafield) {
21
- const noDataPropWarning = `<Metafield/>: nothing was passed to the data prop 'data'. Rendering 'null'`;
22
- {
23
- console.warn(noDataPropWarning);
24
- }
25
- return null;
26
- }
27
- if (parsedMetafield.value === null || parsedMetafield.value === void 0) {
28
- const noValueWarning = `<Metafield/>: No metafield value for metafield ${(_a = parsedMetafield.id) != null ? _a : parsedMetafield.key}. Rendering 'null'`;
29
- {
30
- console.warn(noValueWarning);
31
- }
32
- return null;
33
- }
34
- switch (parsedMetafield.type) {
35
- case "date": {
36
- const Wrapper2 = as != null ? as : "time";
37
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper2, {
38
- ...passthroughProps,
39
- children: parsedMetafield.value.toLocaleDateString(locale)
40
- });
41
- }
42
- case "date_time": {
43
- const Wrapper2 = as != null ? as : "time";
44
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper2, {
45
- ...passthroughProps,
46
- children: parsedMetafield.value.toLocaleString(locale)
47
- });
48
- }
49
- case "weight":
50
- case "dimension":
51
- case "volume": {
52
- const Wrapper2 = as != null ? as : "span";
53
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper2, {
54
- ...passthroughProps,
55
- children: getMeasurementAsString(parsedMetafield.value, locale)
56
- });
57
- }
58
- case "rating": {
59
- const Wrapper2 = as != null ? as : "span";
60
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper2, {
61
- ...passthroughProps,
62
- children: parsedMetafield.value.value
63
- });
64
- }
65
- case "single_line_text_field": {
66
- const Wrapper2 = as != null ? as : "span";
67
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper2, {
68
- ...passthroughProps,
69
- dangerouslySetInnerHTML: {
70
- __html: parsedMetafield.value
71
- }
72
- });
73
- }
74
- case "multi_line_text_field": {
75
- const Wrapper2 = as != null ? as : "div";
76
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper2, {
77
- ...passthroughProps,
78
- dangerouslySetInnerHTML: {
79
- __html: parsedMetafield.value.split("\n").join("<br/>")
80
- }
81
- });
82
- }
83
- case "url": {
84
- const protocolLessUrl = new URL(parsedMetafield.value);
85
- return /* @__PURE__ */ jsxRuntime.jsx("a", {
86
- href: protocolLessUrl.href.replace(protocolLessUrl.protocol, ""),
87
- ...passthroughProps,
88
- children: parsedMetafield.value
89
- });
90
- }
91
- case "json": {
92
- const Wrapper2 = as != null ? as : "span";
93
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper2, {
94
- ...passthroughProps,
95
- children: JSON.stringify(parsedMetafield.value)
96
- });
97
- }
98
- case "product_reference":
99
- case "variant_reference":
100
- case "page_reference": {
101
- const Wrapper2 = as != null ? as : "span";
102
- const ref = parsedMetafield.reference;
103
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper2, {
104
- ...passthroughProps,
105
- children: (_c = (_b = ref == null ? void 0 : ref.title) != null ? _b : ref == null ? void 0 : ref.id) != null ? _c : ""
106
- });
107
- }
108
- case "list.single_line_text_field": {
109
- const Wrapper2 = as != null ? as : "ul";
110
- const refArray = parsedMetafield.references ? flattenConnection.flattenConnection(parsedMetafield.references) : [];
111
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper2, {
112
- ...passthroughProps,
113
- children: refArray.map((ref, index) => /* @__PURE__ */ jsxRuntime.jsx("li", {
114
- children: ref
115
- }, `${ref != null ? ref : ""}-${index}`))
116
- });
117
- }
118
- case "file_reference": {
119
- if (((_d = parsedMetafield.reference) == null ? void 0 : _d.__typename) === "MediaImage") {
120
- const ref = parsedMetafield.reference;
121
- return ref.image ? /* @__PURE__ */ jsxRuntime.jsx(Image.Image, {
122
- data: ref.image,
123
- ...passthroughProps
124
- }) : null;
125
- } else if (((_e = parsedMetafield.reference) == null ? void 0 : _e.__typename) === "GenericFile") {
126
- const ref = parsedMetafield.reference;
127
- return ref.previewImage ? /* @__PURE__ */ jsxRuntime.jsx("a", {
128
- href: (_g = (_f = parsedMetafield.reference) == null ? void 0 : _f.url) != null ? _g : "",
129
- ...passthroughProps,
130
- children: /* @__PURE__ */ jsxRuntime.jsx(Image.Image, {
131
- data: ref.previewImage
132
- })
133
- }) : null;
134
- } else if (((_h = parsedMetafield.reference) == null ? void 0 : _h.__typename) === "Video") {
135
- const ref = parsedMetafield.reference;
136
- return /* @__PURE__ */ jsxRuntime.jsx(Video.Video, {
137
- ...passthroughProps,
138
- data: ref
139
- });
140
- }
141
- }
142
- }
143
- const Wrapper = as != null ? as : "span";
144
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper, {
145
- ...passthroughProps,
146
- children: (_i = parsedMetafield.value) == null ? void 0 : _i.toString()
147
- });
148
- }
149
- function parseMetafield(metafield) {
150
- if (!metafield) {
151
- return null;
152
- }
153
- return {
154
- ...metafield,
155
- value: parseMetafieldValue(metafield)
156
- };
157
- }
158
- function parseMetafieldValue(metafield) {
159
- if (!metafield) {
160
- return null;
161
- }
162
- if (metafield.value === null || metafield.value === void 0) {
163
- return metafield.value;
164
- }
165
- switch (metafield.type) {
166
- case "boolean":
167
- return metafield.value === "true";
168
- case "number_integer":
169
- return parseInt(metafield.value);
170
- case "number_decimal":
171
- return parseFloat(metafield.value);
172
- case "date":
173
- case "date_time":
174
- return new Date(metafield.value);
175
- case "json":
176
- case "weight":
177
- case "dimension":
178
- case "volume":
179
- case "rating":
180
- return parseJSON(metafield.value);
181
- case "color":
182
- case "single_line_text_field":
183
- case "multi_line_text_field":
184
- case "product_reference":
185
- case "page_reference":
186
- case "variant_reference":
187
- case "file_reference":
188
- case "url":
189
- default:
190
- return metafield.value;
191
- }
192
- }
193
- function parseJSON(json) {
194
- if (String(json).includes("__proto__")) {
195
- return JSON.parse(json, (k, v) => {
196
- if (k !== "__proto__")
197
- return v;
198
- });
199
- }
200
- return JSON.parse(json);
201
- }
202
- const UNIT_MAPPING = {
203
- mm: "millimeter",
204
- cm: "centimeter",
205
- m: "meter",
206
- in: "inch",
207
- ft: "foot",
208
- yd: "yard",
209
- ml: "milliliter",
210
- l: "liter",
211
- us_fl_oz: "fluid-ounce",
212
- us_gal: "gallon",
213
- kg: "kilogram",
214
- g: "gram",
215
- lb: "pound",
216
- oz: "ounce"
217
- };
218
- function getMeasurementAsString(measurement, locale = "en-us", options = {}) {
219
- let measure = {
220
- value: measurement.value,
221
- unit: UNIT_MAPPING[measurement.unit]
222
- };
223
- if (measure.unit == null) {
224
- measure = convertToSupportedUnit(measurement.value, measurement.unit);
225
- }
226
- return new Intl.NumberFormat(locale, {
227
- ...options,
228
- unit: measure.unit,
229
- style: "unit"
230
- }).format(measure.value);
231
- }
232
- function convertToSupportedUnit(value, unit) {
233
- switch (unit) {
234
- case "cl":
235
- return {
236
- value: value / 1e3,
237
- unit: "liter"
238
- };
239
- case "m3":
240
- return {
241
- value: value * 1e3,
242
- unit: "liter"
243
- };
244
- case "us_pt":
245
- return {
246
- value: value * 0.125,
247
- unit: "gallon"
248
- };
249
- case "us_qt":
250
- return {
251
- value: value * 0.5,
252
- unit: "gallon"
253
- };
254
- case "us_oz":
255
- return {
256
- value: value / 128,
257
- unit: "gallon"
258
- };
259
- case "imp_pt":
260
- return {
261
- value: value / 6.661,
262
- unit: "gallon"
263
- };
264
- case "imp_qt":
265
- return {
266
- value: value / 3.331,
267
- unit: "gallon"
268
- };
269
- case "imp_gal":
270
- return {
271
- value: value / 1.201,
272
- unit: "gallon"
273
- };
274
- case "imp_fl_oz":
275
- return {
276
- value: value * 0.96076,
277
- unit: "fluid-ounce"
278
- };
279
- default:
280
- throw new Error(`Unit not supported: ${unit}`);
281
- }
282
- }
283
- exports.Metafield = Metafield;
284
- exports.getMeasurementAsString = getMeasurementAsString;
285
- exports.parseJSON = parseJSON;
286
- exports.parseMetafield = parseMetafield;
287
- exports.parseMetafieldValue = parseMetafieldValue;
288
- //# sourceMappingURL=Metafield.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Metafield.js","sources":["../../src/Metafield.tsx"],"sourcesContent":["import {type ElementType, useMemo, type ComponentPropsWithoutRef} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {Image} from './Image.js';\nimport type {\n MediaImage,\n Page,\n ProductVariant,\n Product,\n GenericFile,\n Video as VideoType,\n Metafield as MetafieldType,\n} from './storefront-api-types.js';\nimport {Video} from './Video.js';\nimport {flattenConnection} from './flatten-connection.js';\nimport type {PartialDeep, JsonValue} from 'type-fest';\n\ninterface BaseProps<ComponentGeneric extends ElementType> {\n /** An object with fields that correspond to the Storefront API's [Metafield object](https://shopify.dev/api/storefront/reference/common-objects/metafield). */\n data: PartialDeep<MetafieldType, {recurseIntoArrays: true}> | null;\n /** An HTML tag or React component to be rendered as the base element wrapper. The default value varies depending on [metafield.type](https://shopify.dev/apps/metafields/types). */\n as?: ComponentGeneric;\n}\n\nexport type MetafieldProps<ComponentGeneric extends ElementType> =\n ComponentPropsWithoutRef<ComponentGeneric> & BaseProps<ComponentGeneric>;\n\n/**\n * The `Metafield` component renders the value of a Storefront\n * API's [Metafield object](https://shopify.dev/api/storefront/reference/common-objects/metafield).\n * Relies on the `locale` property of the `useShop()` hook, so it must be a desendent of `<ShopifyProvider/>`\n *\n * Renders a smart default of the Metafield's `value`. For more information, refer to the [Default output](#default-output) section.\n */\nexport function Metafield<ComponentGeneric extends ElementType>(\n props: MetafieldProps<ComponentGeneric>\n) {\n const {data, as, ...passthroughProps} = props;\n const {locale} = useShop();\n\n const parsedMetafield = useMemo(() => parseMetafield(data), [data]);\n\n if (!parsedMetafield) {\n const noDataPropWarning = `<Metafield/>: nothing was passed to the data prop 'data'. Rendering 'null'`;\n if (__HYDROGEN_DEV__) {\n throw new Error(noDataPropWarning);\n } else {\n console.warn(noDataPropWarning);\n }\n return null;\n }\n\n if (parsedMetafield.value === null || parsedMetafield.value === undefined) {\n const noValueWarning = `<Metafield/>: No metafield value for metafield ${\n parsedMetafield.id ?? parsedMetafield.key\n }. Rendering 'null'`;\n if (__HYDROGEN_DEV__) {\n throw new Error(noValueWarning);\n } else {\n console.warn(noValueWarning);\n }\n return null;\n }\n\n switch (parsedMetafield.type) {\n case 'date': {\n const Wrapper = as ?? 'time';\n return (\n <Wrapper {...passthroughProps}>\n {(parsedMetafield.value as Date).toLocaleDateString(locale)}\n </Wrapper>\n );\n }\n case 'date_time': {\n const Wrapper = as ?? 'time';\n return (\n <Wrapper {...passthroughProps}>\n {(parsedMetafield.value as Date).toLocaleString(locale)}\n </Wrapper>\n );\n }\n case 'weight':\n case 'dimension':\n case 'volume': {\n const Wrapper = as ?? 'span';\n return (\n <Wrapper {...passthroughProps}>\n {getMeasurementAsString(parsedMetafield.value as Measurement, locale)}\n </Wrapper>\n );\n }\n case 'rating': {\n const Wrapper = as ?? 'span';\n return (\n <Wrapper {...passthroughProps}>\n {(parsedMetafield.value as Rating).value}\n </Wrapper>\n );\n }\n case 'single_line_text_field': {\n const Wrapper = as ?? 'span';\n return (\n <Wrapper\n {...passthroughProps}\n dangerouslySetInnerHTML={{__html: parsedMetafield.value as string}}\n />\n );\n }\n case 'multi_line_text_field': {\n const Wrapper = as ?? 'div';\n return (\n <Wrapper\n {...passthroughProps}\n dangerouslySetInnerHTML={{\n __html: (parsedMetafield.value as string).split('\\n').join('<br/>'),\n }}\n />\n );\n }\n case 'url': {\n const protocolLessUrl = new URL(parsedMetafield.value as string);\n return (\n <a\n href={protocolLessUrl.href.replace(protocolLessUrl.protocol, '')}\n {...passthroughProps}\n >\n {parsedMetafield.value as string}\n </a>\n );\n }\n case 'json': {\n const Wrapper = as ?? 'span';\n return (\n <Wrapper {...passthroughProps}>\n {JSON.stringify(parsedMetafield.value)}\n </Wrapper>\n );\n }\n case 'product_reference':\n case 'variant_reference':\n case 'page_reference': {\n const Wrapper = as ?? 'span';\n const ref = parsedMetafield.reference as Page | ProductVariant | Product;\n return (\n <Wrapper {...passthroughProps}>{ref?.title ?? ref?.id ?? ''}</Wrapper>\n );\n }\n case 'list.single_line_text_field': {\n const Wrapper = as ?? 'ul';\n\n const refArray = parsedMetafield.references\n ? (flattenConnection(parsedMetafield.references) as string[])\n : [];\n return (\n <Wrapper {...passthroughProps}>\n {refArray.map((ref, index) => (\n // there's no unique way to identify these strings, so we do our best by combining the string with the index for the key\n // eslint-disable-next-line react/no-array-index-key\n <li key={`${ref ?? ''}-${index}`}>{ref}</li>\n ))}\n </Wrapper>\n );\n }\n case 'file_reference': {\n if (parsedMetafield.reference?.__typename === 'MediaImage') {\n const ref = parsedMetafield.reference as MediaImage;\n return ref.image ? (\n <Image data={ref.image} {...passthroughProps} />\n ) : null;\n } else if (parsedMetafield.reference?.__typename === 'GenericFile') {\n const ref = parsedMetafield.reference as GenericFile;\n return ref.previewImage ? (\n <a href={parsedMetafield.reference?.url ?? ''} {...passthroughProps}>\n <Image data={ref.previewImage} />\n </a>\n ) : null;\n } else if (parsedMetafield.reference?.__typename === 'Video') {\n const ref = parsedMetafield.reference as VideoType;\n return <Video {...passthroughProps} data={ref} />;\n }\n }\n }\n\n const Wrapper = as ?? 'span';\n return (\n <Wrapper {...passthroughProps}>{parsedMetafield.value?.toString()}</Wrapper>\n );\n}\n\n/**\n * The `parseMetafield` utility transforms a [Metafield](https://shopify.dev/api/storefront/reference/common-objects/Metafield)\n * into a new object whose `values` have been parsed according to the metafield `type`.\n * If the metafield is `null`, then it returns `null` back.\n *\n * Note that `parseMetafield()` will have a breaking change in a future version; it will change to behave like `metafieldParser()`.\n */\nexport function parseMetafield(\n /** A [Metafield](https://shopify.dev/api/storefront/reference/common-objects/Metafield) or null */\n metafield: PartialDeep<MetafieldType, {recurseIntoArrays: true}> | null\n): PartialDeep<ParsedMetafield, {recurseIntoArrays: true}> | null {\n if (__HYDROGEN_DEV__) {\n console.info(\n `'parseMetafield()' will have a breaking change in a future version; its behavior will match that of 'metafieldParser()'`\n );\n }\n\n if (!metafield) {\n if (__HYDROGEN_DEV__) {\n console.warn(\n `'parseMetafield' was not passed any value for the 'metafield' argument`\n );\n }\n return null;\n }\n if (\n __HYDROGEN_DEV__ &&\n (metafield.value === null || metafield.value === undefined)\n ) {\n console.warn(\n `'parseMetafield()' was passed ${metafield.value} for 'metafield.value'`\n );\n }\n\n return {\n ...metafield,\n value: parseMetafieldValue(metafield),\n };\n}\n\n/**\n * The `parseMetafieldValue` function parses a [Metafield](https://shopify.dev/api/storefront/reference/common-objects/metafield)'s `value` from a string into a sensible type corresponding to the [Metafield](https://shopify.dev/api/storefront/reference/common-objects/metafield)'s `type`.\n * @deprecated `parseMetafieldValue()` is unsupported and will be removed in a future version.\n */\nexport function parseMetafieldValue(\n metafield: PartialDeep<MetafieldType, {recurseIntoArrays: true}> | null\n): ParsedMetafield['value'] {\n if (__HYDROGEN_DEV__) {\n console.info(`'parseMetafieldValue()' will be removed in a future version`);\n }\n\n if (!metafield) {\n return null;\n }\n\n if (metafield.value === null || metafield.value === undefined) {\n if (__HYDROGEN_DEV__) {\n console.warn(\n `'parseMetafieldValue()' was passed ${metafield.value} for 'metafield.value'`\n );\n }\n return metafield.value;\n }\n\n switch (metafield.type) {\n case 'boolean':\n return metafield.value === 'true';\n case 'number_integer':\n return parseInt(metafield.value);\n case 'number_decimal':\n return parseFloat(metafield.value);\n case 'date':\n case 'date_time':\n return new Date(metafield.value);\n case 'json':\n case 'weight':\n case 'dimension':\n case 'volume':\n case 'rating':\n return parseJSON(metafield.value);\n case 'color':\n case 'single_line_text_field':\n case 'multi_line_text_field':\n case 'product_reference':\n case 'page_reference':\n case 'variant_reference':\n case 'file_reference':\n case 'url':\n default:\n return metafield.value;\n }\n}\n\n/**\n * Parses a JSON string while preventing prototype injection attacks.\n */\nexport function parseJSON(json: string) {\n if (String(json).includes('__proto__')) {\n return JSON.parse(json, (k, v) => {\n if (k !== '__proto__') return v;\n });\n }\n\n return JSON.parse(json);\n}\n\nconst UNIT_MAPPING: Record<string, string> = {\n // Dimension\n mm: 'millimeter',\n cm: 'centimeter',\n m: 'meter',\n in: 'inch',\n ft: 'foot',\n yd: 'yard',\n // Volume\n ml: 'milliliter',\n l: 'liter',\n us_fl_oz: 'fluid-ounce',\n us_gal: 'gallon',\n // Weight\n kg: 'kilogram',\n g: 'gram',\n lb: 'pound',\n oz: 'ounce',\n};\n\nexport function getMeasurementAsString(\n measurement: Measurement,\n locale = 'en-us',\n options: Intl.NumberFormatOptions = {}\n) {\n let measure: Measurement = {\n value: measurement.value,\n unit: UNIT_MAPPING[measurement.unit],\n };\n\n if (measure.unit == null) {\n measure = convertToSupportedUnit(measurement.value, measurement.unit);\n }\n\n return new Intl.NumberFormat(locale, {\n ...options,\n unit: measure.unit,\n style: 'unit',\n }).format(measure.value);\n}\n\nfunction convertToSupportedUnit(value: number, unit: string): Measurement {\n switch (unit) {\n case 'cl':\n return {\n value: value / 1000,\n unit: 'liter',\n };\n case 'm3':\n return {\n value: value * 1000,\n unit: 'liter',\n };\n case 'us_pt':\n return {\n value: value * 0.125,\n unit: 'gallon',\n };\n case 'us_qt':\n return {\n value: value * 0.5,\n unit: 'gallon',\n };\n case 'us_oz':\n return {\n value: value / 128,\n unit: 'gallon',\n };\n case 'imp_pt':\n return {\n value: value / 6.661, // approximate conversion\n unit: 'gallon',\n };\n case 'imp_qt':\n return {\n value: value / 3.331, // approximate conversion\n unit: 'gallon',\n };\n case 'imp_gal':\n return {\n value: value / 1.201, // approximate conversion\n unit: 'gallon',\n };\n case 'imp_fl_oz':\n return {\n value: value * 0.96076, // approximate conversion\n unit: 'fluid-ounce',\n };\n default:\n throw new Error(`Unit not supported: ${unit}`);\n }\n}\n\ntype ParsedMetafield = Omit<\n PartialDeep<MetafieldType, {recurseIntoArrays: true}>,\n 'value'\n> & {\n value?: string | number | boolean | JsonValue | Date | Rating | Measurement;\n};\n\nexport interface Rating {\n value: number;\n scale_min: number;\n scale_max: number;\n}\n\ninterface Measurement {\n unit: string;\n value: number;\n}\n"],"names":["Metafield","props","data","as","passthroughProps","locale","useShop","parsedMetafield","useMemo","parseMetafield","noDataPropWarning","console","warn","value","undefined","noValueWarning","id","key","type","Wrapper","toLocaleDateString","toLocaleString","getMeasurementAsString","__html","split","join","protocolLessUrl","URL","href","replace","protocol","JSON","stringify","ref","reference","title","refArray","references","flattenConnection","map","index","__typename","image","_jsx","Image","previewImage","url","Video","toString","metafield","parseMetafieldValue","parseInt","parseFloat","Date","parseJSON","json","String","includes","parse","k","v","UNIT_MAPPING","mm","cm","m","in","ft","yd","ml","l","us_fl_oz","us_gal","kg","g","lb","oz","measurement","options","measure","unit","convertToSupportedUnit","Intl","NumberFormat","style","format","Error"],"mappings":";;;;;;;;AAiCO,SAASA,UACdC,OACA;;AACM,QAAA;AAAA,IAACC;AAAAA,IAAMC;AAAAA,OAAOC;AAAAA,EAAoBH,IAAAA;AAClC,QAAA;AAAA,IAACI;AAAAA,MAAUC,gBAAS,QAAA;AAEpBC,QAAAA,kBAAkBC,WAAAA,QAAQ,MAAMC,eAAeP,IAAI,GAAG,CAACA,IAAI,CAAC;AAElE,MAAI,CAACK,iBAAiB;AACpB,UAAMG,oBAAqB;AAGpB;AACLC,cAAQC,KAAKF,iBAAiB;AAAA,IAChC;AACO,WAAA;AAAA,EACT;AAEA,MAAIH,gBAAgBM,UAAU,QAAQN,gBAAgBM,UAAUC,QAAW;AACzE,UAAMC,iBAAkB,mDACtBR,qBAAgBS,OAAhBT,YAAsBA,gBAAgBU;AAIjC;AACLN,cAAQC,KAAKG,cAAc;AAAA,IAC7B;AACO,WAAA;AAAA,EACT;AAEA,UAAQR,gBAAgBW,MAAI;AAAA,IAC1B,KAAK,QAAQ;AACX,YAAMC,WAAUhB,kBAAM;AACtB,4CACGgB,UAAO;AAAA,QAAA,GAAKf;AAAAA,QAAgB,UACzBG,gBAAgBM,MAAeO,mBAAmBf,MAAM;AAAA,MAAA,CAClD;AAAA,IAEd;AAAA,IACA,KAAK,aAAa;AAChB,YAAMc,WAAUhB,kBAAM;AACtB,4CACGgB,UAAO;AAAA,QAAA,GAAKf;AAAAA,QAAgB,UACzBG,gBAAgBM,MAAeQ,eAAehB,MAAM;AAAA,MAAA,CAC9C;AAAA,IAEd;AAAA,IACA,KAAK;A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,KAAK;AACI,aAAA;AAAA,QACLlE,OAAOA,QAAQ;AAAA,QACfkE,MAAM;AAAA,MAAA;AAAA,IAEV,KAAK;AACI,aAAA;AAAA,QACLlE,OAAOA,QAAQ;AAAA,QACfkE,MAAM;AAAA,MAAA;AAAA,IAEV,KAAK;AACI,aAAA;AAAA,QACLlE,OAAOA,QAAQ;AAAA,QACfkE,MAAM;AAAA,MAAA;AAAA,IAEV,KAAK;AACI,aAAA;AAAA,QACLlE,OAAOA,QAAQ;AAAA,QACfkE,MAAM;AAAA,MAAA;AAAA,IAEV,KAAK;AACI,aAAA;AAAA,QACLlE,OAAOA,QAAQ;AAAA,QACfkE,MAAM;AAAA,MAAA;AAAA,IAEV,KAAK;AACI,aAAA;AAAA,QACLlE,OAAOA,QAAQ;AAAA,QACfkE,MAAM;AAAA,MAAA;AAAA,IAEV;AACQ,YAAA,IAAIM,MAAO,uBAAsBN,MAAM;AAAA,EAAE;AAErD;;;;;;"}
@@ -1,288 +0,0 @@
1
- import { useMemo } from "react";
2
- import { useShop } from "./ShopifyProvider.mjs";
3
- import { Image } from "./Image.mjs";
4
- import { Video } from "./Video.mjs";
5
- import { flattenConnection } from "./flatten-connection.mjs";
6
- import { jsx } from "react/jsx-runtime";
7
- function Metafield(props) {
8
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
9
- const {
10
- data,
11
- as,
12
- ...passthroughProps
13
- } = props;
14
- const {
15
- locale
16
- } = useShop();
17
- const parsedMetafield = useMemo(() => parseMetafield(data), [data]);
18
- if (!parsedMetafield) {
19
- const noDataPropWarning = `<Metafield/>: nothing was passed to the data prop 'data'. Rendering 'null'`;
20
- {
21
- console.warn(noDataPropWarning);
22
- }
23
- return null;
24
- }
25
- if (parsedMetafield.value === null || parsedMetafield.value === void 0) {
26
- const noValueWarning = `<Metafield/>: No metafield value for metafield ${(_a = parsedMetafield.id) != null ? _a : parsedMetafield.key}. Rendering 'null'`;
27
- {
28
- console.warn(noValueWarning);
29
- }
30
- return null;
31
- }
32
- switch (parsedMetafield.type) {
33
- case "date": {
34
- const Wrapper2 = as != null ? as : "time";
35
- return /* @__PURE__ */ jsx(Wrapper2, {
36
- ...passthroughProps,
37
- children: parsedMetafield.value.toLocaleDateString(locale)
38
- });
39
- }
40
- case "date_time": {
41
- const Wrapper2 = as != null ? as : "time";
42
- return /* @__PURE__ */ jsx(Wrapper2, {
43
- ...passthroughProps,
44
- children: parsedMetafield.value.toLocaleString(locale)
45
- });
46
- }
47
- case "weight":
48
- case "dimension":
49
- case "volume": {
50
- const Wrapper2 = as != null ? as : "span";
51
- return /* @__PURE__ */ jsx(Wrapper2, {
52
- ...passthroughProps,
53
- children: getMeasurementAsString(parsedMetafield.value, locale)
54
- });
55
- }
56
- case "rating": {
57
- const Wrapper2 = as != null ? as : "span";
58
- return /* @__PURE__ */ jsx(Wrapper2, {
59
- ...passthroughProps,
60
- children: parsedMetafield.value.value
61
- });
62
- }
63
- case "single_line_text_field": {
64
- const Wrapper2 = as != null ? as : "span";
65
- return /* @__PURE__ */ jsx(Wrapper2, {
66
- ...passthroughProps,
67
- dangerouslySetInnerHTML: {
68
- __html: parsedMetafield.value
69
- }
70
- });
71
- }
72
- case "multi_line_text_field": {
73
- const Wrapper2 = as != null ? as : "div";
74
- return /* @__PURE__ */ jsx(Wrapper2, {
75
- ...passthroughProps,
76
- dangerouslySetInnerHTML: {
77
- __html: parsedMetafield.value.split("\n").join("<br/>")
78
- }
79
- });
80
- }
81
- case "url": {
82
- const protocolLessUrl = new URL(parsedMetafield.value);
83
- return /* @__PURE__ */ jsx("a", {
84
- href: protocolLessUrl.href.replace(protocolLessUrl.protocol, ""),
85
- ...passthroughProps,
86
- children: parsedMetafield.value
87
- });
88
- }
89
- case "json": {
90
- const Wrapper2 = as != null ? as : "span";
91
- return /* @__PURE__ */ jsx(Wrapper2, {
92
- ...passthroughProps,
93
- children: JSON.stringify(parsedMetafield.value)
94
- });
95
- }
96
- case "product_reference":
97
- case "variant_reference":
98
- case "page_reference": {
99
- const Wrapper2 = as != null ? as : "span";
100
- const ref = parsedMetafield.reference;
101
- return /* @__PURE__ */ jsx(Wrapper2, {
102
- ...passthroughProps,
103
- children: (_c = (_b = ref == null ? void 0 : ref.title) != null ? _b : ref == null ? void 0 : ref.id) != null ? _c : ""
104
- });
105
- }
106
- case "list.single_line_text_field": {
107
- const Wrapper2 = as != null ? as : "ul";
108
- const refArray = parsedMetafield.references ? flattenConnection(parsedMetafield.references) : [];
109
- return /* @__PURE__ */ jsx(Wrapper2, {
110
- ...passthroughProps,
111
- children: refArray.map((ref, index) => /* @__PURE__ */ jsx("li", {
112
- children: ref
113
- }, `${ref != null ? ref : ""}-${index}`))
114
- });
115
- }
116
- case "file_reference": {
117
- if (((_d = parsedMetafield.reference) == null ? void 0 : _d.__typename) === "MediaImage") {
118
- const ref = parsedMetafield.reference;
119
- return ref.image ? /* @__PURE__ */ jsx(Image, {
120
- data: ref.image,
121
- ...passthroughProps
122
- }) : null;
123
- } else if (((_e = parsedMetafield.reference) == null ? void 0 : _e.__typename) === "GenericFile") {
124
- const ref = parsedMetafield.reference;
125
- return ref.previewImage ? /* @__PURE__ */ jsx("a", {
126
- href: (_g = (_f = parsedMetafield.reference) == null ? void 0 : _f.url) != null ? _g : "",
127
- ...passthroughProps,
128
- children: /* @__PURE__ */ jsx(Image, {
129
- data: ref.previewImage
130
- })
131
- }) : null;
132
- } else if (((_h = parsedMetafield.reference) == null ? void 0 : _h.__typename) === "Video") {
133
- const ref = parsedMetafield.reference;
134
- return /* @__PURE__ */ jsx(Video, {
135
- ...passthroughProps,
136
- data: ref
137
- });
138
- }
139
- }
140
- }
141
- const Wrapper = as != null ? as : "span";
142
- return /* @__PURE__ */ jsx(Wrapper, {
143
- ...passthroughProps,
144
- children: (_i = parsedMetafield.value) == null ? void 0 : _i.toString()
145
- });
146
- }
147
- function parseMetafield(metafield) {
148
- if (!metafield) {
149
- return null;
150
- }
151
- return {
152
- ...metafield,
153
- value: parseMetafieldValue(metafield)
154
- };
155
- }
156
- function parseMetafieldValue(metafield) {
157
- if (!metafield) {
158
- return null;
159
- }
160
- if (metafield.value === null || metafield.value === void 0) {
161
- return metafield.value;
162
- }
163
- switch (metafield.type) {
164
- case "boolean":
165
- return metafield.value === "true";
166
- case "number_integer":
167
- return parseInt(metafield.value);
168
- case "number_decimal":
169
- return parseFloat(metafield.value);
170
- case "date":
171
- case "date_time":
172
- return new Date(metafield.value);
173
- case "json":
174
- case "weight":
175
- case "dimension":
176
- case "volume":
177
- case "rating":
178
- return parseJSON(metafield.value);
179
- case "color":
180
- case "single_line_text_field":
181
- case "multi_line_text_field":
182
- case "product_reference":
183
- case "page_reference":
184
- case "variant_reference":
185
- case "file_reference":
186
- case "url":
187
- default:
188
- return metafield.value;
189
- }
190
- }
191
- function parseJSON(json) {
192
- if (String(json).includes("__proto__")) {
193
- return JSON.parse(json, (k, v) => {
194
- if (k !== "__proto__")
195
- return v;
196
- });
197
- }
198
- return JSON.parse(json);
199
- }
200
- const UNIT_MAPPING = {
201
- mm: "millimeter",
202
- cm: "centimeter",
203
- m: "meter",
204
- in: "inch",
205
- ft: "foot",
206
- yd: "yard",
207
- ml: "milliliter",
208
- l: "liter",
209
- us_fl_oz: "fluid-ounce",
210
- us_gal: "gallon",
211
- kg: "kilogram",
212
- g: "gram",
213
- lb: "pound",
214
- oz: "ounce"
215
- };
216
- function getMeasurementAsString(measurement, locale = "en-us", options = {}) {
217
- let measure = {
218
- value: measurement.value,
219
- unit: UNIT_MAPPING[measurement.unit]
220
- };
221
- if (measure.unit == null) {
222
- measure = convertToSupportedUnit(measurement.value, measurement.unit);
223
- }
224
- return new Intl.NumberFormat(locale, {
225
- ...options,
226
- unit: measure.unit,
227
- style: "unit"
228
- }).format(measure.value);
229
- }
230
- function convertToSupportedUnit(value, unit) {
231
- switch (unit) {
232
- case "cl":
233
- return {
234
- value: value / 1e3,
235
- unit: "liter"
236
- };
237
- case "m3":
238
- return {
239
- value: value * 1e3,
240
- unit: "liter"
241
- };
242
- case "us_pt":
243
- return {
244
- value: value * 0.125,
245
- unit: "gallon"
246
- };
247
- case "us_qt":
248
- return {
249
- value: value * 0.5,
250
- unit: "gallon"
251
- };
252
- case "us_oz":
253
- return {
254
- value: value / 128,
255
- unit: "gallon"
256
- };
257
- case "imp_pt":
258
- return {
259
- value: value / 6.661,
260
- unit: "gallon"
261
- };
262
- case "imp_qt":
263
- return {
264
- value: value / 3.331,
265
- unit: "gallon"
266
- };
267
- case "imp_gal":
268
- return {
269
- value: value / 1.201,
270
- unit: "gallon"
271
- };
272
- case "imp_fl_oz":
273
- return {
274
- value: value * 0.96076,
275
- unit: "fluid-ounce"
276
- };
277
- default:
278
- throw new Error(`Unit not supported: ${unit}`);
279
- }
280
- }
281
- export {
282
- Metafield,
283
- getMeasurementAsString,
284
- parseJSON,
285
- parseMetafield,
286
- parseMetafieldValue
287
- };
288
- //# sourceMappingURL=Metafield.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Metafield.mjs","sources":["../../src/Metafield.tsx"],"sourcesContent":["import {type ElementType, useMemo, type ComponentPropsWithoutRef} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {Image} from './Image.js';\nimport type {\n MediaImage,\n Page,\n ProductVariant,\n Product,\n GenericFile,\n Video as VideoType,\n Metafield as MetafieldType,\n} from './storefront-api-types.js';\nimport {Video} from './Video.js';\nimport {flattenConnection} from './flatten-connection.js';\nimport type {PartialDeep, JsonValue} from 'type-fest';\n\ninterface BaseProps<ComponentGeneric extends ElementType> {\n /** An object with fields that correspond to the Storefront API's [Metafield object](https://shopify.dev/api/storefront/reference/common-objects/metafield). */\n data: PartialDeep<MetafieldType, {recurseIntoArrays: true}> | null;\n /** An HTML tag or React component to be rendered as the base element wrapper. The default value varies depending on [metafield.type](https://shopify.dev/apps/metafields/types). */\n as?: ComponentGeneric;\n}\n\nexport type MetafieldProps<ComponentGeneric extends ElementType> =\n ComponentPropsWithoutRef<ComponentGeneric> & BaseProps<ComponentGeneric>;\n\n/**\n * The `Metafield` component renders the value of a Storefront\n * API's [Metafield object](https://shopify.dev/api/storefront/reference/common-objects/metafield).\n * Relies on the `locale` property of the `useShop()` hook, so it must be a desendent of `<ShopifyProvider/>`\n *\n * Renders a smart default of the Metafield's `value`. For more information, refer to the [Default output](#default-output) section.\n */\nexport function Metafield<ComponentGeneric extends ElementType>(\n props: MetafieldProps<ComponentGeneric>\n) {\n const {data, as, ...passthroughProps} = props;\n const {locale} = useShop();\n\n const parsedMetafield = useMemo(() => parseMetafield(data), [data]);\n\n if (!parsedMetafield) {\n const noDataPropWarning = `<Metafield/>: nothing was passed to the data prop 'data'. Rendering 'null'`;\n if (__HYDROGEN_DEV__) {\n throw new Error(noDataPropWarning);\n } else {\n console.warn(noDataPropWarning);\n }\n return null;\n }\n\n if (parsedMetafield.value === null || parsedMetafield.value === undefined) {\n const noValueWarning = `<Metafield/>: No metafield value for metafield ${\n parsedMetafield.id ?? parsedMetafield.key\n }. Rendering 'null'`;\n if (__HYDROGEN_DEV__) {\n throw new Error(noValueWarning);\n } else {\n console.warn(noValueWarning);\n }\n return null;\n }\n\n switch (parsedMetafield.type) {\n case 'date': {\n const Wrapper = as ?? 'time';\n return (\n <Wrapper {...passthroughProps}>\n {(parsedMetafield.value as Date).toLocaleDateString(locale)}\n </Wrapper>\n );\n }\n case 'date_time': {\n const Wrapper = as ?? 'time';\n return (\n <Wrapper {...passthroughProps}>\n {(parsedMetafield.value as Date).toLocaleString(locale)}\n </Wrapper>\n );\n }\n case 'weight':\n case 'dimension':\n case 'volume': {\n const Wrapper = as ?? 'span';\n return (\n <Wrapper {...passthroughProps}>\n {getMeasurementAsString(parsedMetafield.value as Measurement, locale)}\n </Wrapper>\n );\n }\n case 'rating': {\n const Wrapper = as ?? 'span';\n return (\n <Wrapper {...passthroughProps}>\n {(parsedMetafield.value as Rating).value}\n </Wrapper>\n );\n }\n case 'single_line_text_field': {\n const Wrapper = as ?? 'span';\n return (\n <Wrapper\n {...passthroughProps}\n dangerouslySetInnerHTML={{__html: parsedMetafield.value as string}}\n />\n );\n }\n case 'multi_line_text_field': {\n const Wrapper = as ?? 'div';\n return (\n <Wrapper\n {...passthroughProps}\n dangerouslySetInnerHTML={{\n __html: (parsedMetafield.value as string).split('\\n').join('<br/>'),\n }}\n />\n );\n }\n case 'url': {\n const protocolLessUrl = new URL(parsedMetafield.value as string);\n return (\n <a\n href={protocolLessUrl.href.replace(protocolLessUrl.protocol, '')}\n {...passthroughProps}\n >\n {parsedMetafield.value as string}\n </a>\n );\n }\n case 'json': {\n const Wrapper = as ?? 'span';\n return (\n <Wrapper {...passthroughProps}>\n {JSON.stringify(parsedMetafield.value)}\n </Wrapper>\n );\n }\n case 'product_reference':\n case 'variant_reference':\n case 'page_reference': {\n const Wrapper = as ?? 'span';\n const ref = parsedMetafield.reference as Page | ProductVariant | Product;\n return (\n <Wrapper {...passthroughProps}>{ref?.title ?? ref?.id ?? ''}</Wrapper>\n );\n }\n case 'list.single_line_text_field': {\n const Wrapper = as ?? 'ul';\n\n const refArray = parsedMetafield.references\n ? (flattenConnection(parsedMetafield.references) as string[])\n : [];\n return (\n <Wrapper {...passthroughProps}>\n {refArray.map((ref, index) => (\n // there's no unique way to identify these strings, so we do our best by combining the string with the index for the key\n // eslint-disable-next-line react/no-array-index-key\n <li key={`${ref ?? ''}-${index}`}>{ref}</li>\n ))}\n </Wrapper>\n );\n }\n case 'file_reference': {\n if (parsedMetafield.reference?.__typename === 'MediaImage') {\n const ref = parsedMetafield.reference as MediaImage;\n return ref.image ? (\n <Image data={ref.image} {...passthroughProps} />\n ) : null;\n } else if (parsedMetafield.reference?.__typename === 'GenericFile') {\n const ref = parsedMetafield.reference as GenericFile;\n return ref.previewImage ? (\n <a href={parsedMetafield.reference?.url ?? ''} {...passthroughProps}>\n <Image data={ref.previewImage} />\n </a>\n ) : null;\n } else if (parsedMetafield.reference?.__typename === 'Video') {\n const ref = parsedMetafield.reference as VideoType;\n return <Video {...passthroughProps} data={ref} />;\n }\n }\n }\n\n const Wrapper = as ?? 'span';\n return (\n <Wrapper {...passthroughProps}>{parsedMetafield.value?.toString()}</Wrapper>\n );\n}\n\n/**\n * The `parseMetafield` utility transforms a [Metafield](https://shopify.dev/api/storefront/reference/common-objects/Metafield)\n * into a new object whose `values` have been parsed according to the metafield `type`.\n * If the metafield is `null`, then it returns `null` back.\n *\n * Note that `parseMetafield()` will have a breaking change in a future version; it will change to behave like `metafieldParser()`.\n */\nexport function parseMetafield(\n /** A [Metafield](https://shopify.dev/api/storefront/reference/common-objects/Metafield) or null */\n metafield: PartialDeep<MetafieldType, {recurseIntoArrays: true}> | null\n): PartialDeep<ParsedMetafield, {recurseIntoArrays: true}> | null {\n if (__HYDROGEN_DEV__) {\n console.info(\n `'parseMetafield()' will have a breaking change in a future version; its behavior will match that of 'metafieldParser()'`\n );\n }\n\n if (!metafield) {\n if (__HYDROGEN_DEV__) {\n console.warn(\n `'parseMetafield' was not passed any value for the 'metafield' argument`\n );\n }\n return null;\n }\n if (\n __HYDROGEN_DEV__ &&\n (metafield.value === null || metafield.value === undefined)\n ) {\n console.warn(\n `'parseMetafield()' was passed ${metafield.value} for 'metafield.value'`\n );\n }\n\n return {\n ...metafield,\n value: parseMetafieldValue(metafield),\n };\n}\n\n/**\n * The `parseMetafieldValue` function parses a [Metafield](https://shopify.dev/api/storefront/reference/common-objects/metafield)'s `value` from a string into a sensible type corresponding to the [Metafield](https://shopify.dev/api/storefront/reference/common-objects/metafield)'s `type`.\n * @deprecated `parseMetafieldValue()` is unsupported and will be removed in a future version.\n */\nexport function parseMetafieldValue(\n metafield: PartialDeep<MetafieldType, {recurseIntoArrays: true}> | null\n): ParsedMetafield['value'] {\n if (__HYDROGEN_DEV__) {\n console.info(`'parseMetafieldValue()' will be removed in a future version`);\n }\n\n if (!metafield) {\n return null;\n }\n\n if (metafield.value === null || metafield.value === undefined) {\n if (__HYDROGEN_DEV__) {\n console.warn(\n `'parseMetafieldValue()' was passed ${metafield.value} for 'metafield.value'`\n );\n }\n return metafield.value;\n }\n\n switch (metafield.type) {\n case 'boolean':\n return metafield.value === 'true';\n case 'number_integer':\n return parseInt(metafield.value);\n case 'number_decimal':\n return parseFloat(metafield.value);\n case 'date':\n case 'date_time':\n return new Date(metafield.value);\n case 'json':\n case 'weight':\n case 'dimension':\n case 'volume':\n case 'rating':\n return parseJSON(metafield.value);\n case 'color':\n case 'single_line_text_field':\n case 'multi_line_text_field':\n case 'product_reference':\n case 'page_reference':\n case 'variant_reference':\n case 'file_reference':\n case 'url':\n default:\n return metafield.value;\n }\n}\n\n/**\n * Parses a JSON string while preventing prototype injection attacks.\n */\nexport function parseJSON(json: string) {\n if (String(json).includes('__proto__')) {\n return JSON.parse(json, (k, v) => {\n if (k !== '__proto__') return v;\n });\n }\n\n return JSON.parse(json);\n}\n\nconst UNIT_MAPPING: Record<string, string> = {\n // Dimension\n mm: 'millimeter',\n cm: 'centimeter',\n m: 'meter',\n in: 'inch',\n ft: 'foot',\n yd: 'yard',\n // Volume\n ml: 'milliliter',\n l: 'liter',\n us_fl_oz: 'fluid-ounce',\n us_gal: 'gallon',\n // Weight\n kg: 'kilogram',\n g: 'gram',\n lb: 'pound',\n oz: 'ounce',\n};\n\nexport function getMeasurementAsString(\n measurement: Measurement,\n locale = 'en-us',\n options: Intl.NumberFormatOptions = {}\n) {\n let measure: Measurement = {\n value: measurement.value,\n unit: UNIT_MAPPING[measurement.unit],\n };\n\n if (measure.unit == null) {\n measure = convertToSupportedUnit(measurement.value, measurement.unit);\n }\n\n return new Intl.NumberFormat(locale, {\n ...options,\n unit: measure.unit,\n style: 'unit',\n }).format(measure.value);\n}\n\nfunction convertToSupportedUnit(value: number, unit: string): Measurement {\n switch (unit) {\n case 'cl':\n return {\n value: value / 1000,\n unit: 'liter',\n };\n case 'm3':\n return {\n value: value * 1000,\n unit: 'liter',\n };\n case 'us_pt':\n return {\n value: value * 0.125,\n unit: 'gallon',\n };\n case 'us_qt':\n return {\n value: value * 0.5,\n unit: 'gallon',\n };\n case 'us_oz':\n return {\n value: value / 128,\n unit: 'gallon',\n };\n case 'imp_pt':\n return {\n value: value / 6.661, // approximate conversion\n unit: 'gallon',\n };\n case 'imp_qt':\n return {\n value: value / 3.331, // approximate conversion\n unit: 'gallon',\n };\n case 'imp_gal':\n return {\n value: value / 1.201, // approximate conversion\n unit: 'gallon',\n };\n case 'imp_fl_oz':\n return {\n value: value * 0.96076, // approximate conversion\n unit: 'fluid-ounce',\n };\n default:\n throw new Error(`Unit not supported: ${unit}`);\n }\n}\n\ntype ParsedMetafield = Omit<\n PartialDeep<MetafieldType, {recurseIntoArrays: true}>,\n 'value'\n> & {\n value?: string | number | boolean | JsonValue | Date | Rating | Measurement;\n};\n\nexport interface Rating {\n value: number;\n scale_min: number;\n scale_max: number;\n}\n\ninterface Measurement {\n unit: string;\n value: number;\n}\n"],"names":["Metafield","props","data","as","passthroughProps","locale","useShop","parsedMetafield","useMemo","parseMetafield","noDataPropWarning","console","warn","value","undefined","noValueWarning","id","key","type","Wrapper","toLocaleDateString","toLocaleString","getMeasurementAsString","__html","split","join","protocolLessUrl","URL","href","replace","protocol","JSON","stringify","ref","reference","title","refArray","references","flattenConnection","map","index","__typename","image","_jsx","previewImage","url","toString","metafield","parseMetafieldValue","parseInt","parseFloat","Date","parseJSON","json","String","includes","parse","k","v","UNIT_MAPPING","mm","cm","m","in","ft","yd","ml","l","us_fl_oz","us_gal","kg","g","lb","oz","measurement","options","measure","unit","convertToSupportedUnit","Intl","NumberFormat","style","format","Error"],"mappings":";;;;;;AAiCO,SAASA,UACdC,OACA;;AACM,QAAA;AAAA,IAACC;AAAAA,IAAMC;AAAAA,OAAOC;AAAAA,EAAoBH,IAAAA;AAClC,QAAA;AAAA,IAACI;AAAAA,MAAUC,QAAS;AAEpBC,QAAAA,kBAAkBC,QAAQ,MAAMC,eAAeP,IAAI,GAAG,CAACA,IAAI,CAAC;AAElE,MAAI,CAACK,iBAAiB;AACpB,UAAMG,oBAAqB;AAGpB;AACLC,c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