@shopify/hydrogen 0.18.0 → 0.21.0
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/CHANGELOG.md +200 -0
- package/config.d.ts +1 -0
- package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.d.ts +1 -1
- package/dist/esnext/components/CartLineImage/CartLineImage.client.d.ts +4 -7
- package/dist/esnext/components/CartLineImage/CartLineImage.client.js +1 -2
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.d.ts +1 -1
- package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +3 -1
- package/dist/esnext/components/CartProvider/CartProvider.client.js +22 -20
- package/dist/esnext/components/CartProvider/cart-queries.d.ts +10 -9
- package/dist/esnext/components/CartProvider/cart-queries.js +58 -743
- package/dist/esnext/components/CartProvider/hooks.client.js +4 -2
- package/dist/esnext/components/CartProvider/types.d.ts +2 -0
- package/dist/esnext/components/Image/Image.d.ts +78 -34
- package/dist/esnext/components/Image/Image.js +54 -51
- package/dist/esnext/components/Image/index.d.ts +1 -0
- package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.js +2 -15
- package/dist/esnext/components/LocalizationProvider/LocalizationContext.client.d.ts +0 -1
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +2 -6
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +10 -4
- package/dist/esnext/components/MediaFile/MediaFile.d.ts +2 -2
- package/dist/esnext/components/MediaFile/MediaFile.js +2 -2
- package/dist/esnext/components/Money/Money.client.d.ts +11 -5
- package/dist/esnext/components/Money/Money.client.js +16 -3
- package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +1 -2
- package/dist/esnext/components/ProductPrice/ProductPrice.client.js +1 -2
- package/dist/esnext/components/Video/Video.d.ts +3 -3
- package/dist/esnext/components/Video/Video.js +7 -4
- package/dist/esnext/components/index.d.ts +0 -3
- package/dist/esnext/components/index.js +0 -3
- package/dist/esnext/entry-server.d.ts +13 -1
- package/dist/esnext/entry-server.js +18 -51
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +18 -3
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.js +2 -0
- package/dist/esnext/foundation/fetchSync/server/fetchSync.d.ts +1 -1
- package/dist/esnext/foundation/fetchSync/server/fetchSync.js +1 -1
- package/dist/esnext/foundation/useQuery/hooks.js +8 -9
- package/dist/esnext/foundation/useSession/useSession.d.ts +1 -1
- package/dist/esnext/foundation/useSession/useSession.js +1 -1
- package/dist/esnext/framework/Hydration/Html.js +3 -1
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.d.ts +1 -1
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +2 -1
- package/dist/esnext/framework/Hydration/rsc.d.ts +0 -3
- package/dist/esnext/framework/Hydration/rsc.js +40 -12
- package/dist/esnext/framework/cache/in-memory.js +0 -6
- package/dist/esnext/framework/cache-sub-request.d.ts +17 -0
- package/dist/esnext/framework/cache-sub-request.js +64 -0
- package/dist/esnext/framework/cache.d.ts +6 -6
- package/dist/esnext/framework/cache.js +36 -33
- package/dist/esnext/framework/plugin.js +5 -30
- package/dist/esnext/framework/plugins/vite-plugin-client-imports.d.ts +2 -0
- package/dist/esnext/framework/plugins/vite-plugin-client-imports.js +25 -0
- package/dist/esnext/framework/plugins/vite-plugin-css-modules-rsc.d.ts +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-css-modules-rsc.js +73 -3
- package/dist/esnext/framework/plugins/vite-plugin-hydration-auto-import.js +1 -4
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +6 -4
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +2 -3
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.d.ts +1 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.js +35 -0
- package/dist/esnext/framework/plugins/vite-plugin-platform-entry.js +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-ssr-interop.js +6 -3
- package/dist/esnext/hooks/useCountry/useCountry.d.ts +1 -11
- package/dist/esnext/hooks/useCountry/useCountry.js +1 -1
- package/dist/esnext/index.d.ts +4 -0
- package/dist/esnext/index.js +4 -0
- package/dist/esnext/node.d.ts +1 -0
- package/dist/esnext/node.js +1 -0
- package/dist/esnext/storefront-api-types.d.ts +5 -3
- package/dist/esnext/storefront-api-types.js +5 -3
- package/dist/esnext/types.d.ts +4 -3
- package/dist/esnext/utilities/bot-ua.js +4 -0
- package/dist/esnext/utilities/html-encoding.d.ts +2 -0
- package/dist/esnext/utilities/html-encoding.js +16 -0
- package/dist/esnext/utilities/image_size.d.ts +4 -22
- package/dist/esnext/utilities/image_size.js +15 -33
- package/dist/esnext/utilities/index.d.ts +2 -1
- package/dist/esnext/utilities/index.js +2 -1
- package/dist/esnext/utilities/log/log-cache-api-status.js +5 -1
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/components/Image/Image.d.ts +84 -0
- package/dist/node/components/Image/Image.js +86 -0
- package/dist/node/components/Image/index.d.ts +2 -0
- package/dist/node/components/Image/index.js +5 -0
- package/dist/node/entry-server.d.ts +13 -1
- package/dist/node/entry-server.js +18 -51
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +18 -3
- package/dist/node/framework/Hydration/Html.js +3 -1
- package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +1 -1
- package/dist/node/framework/Hydration/ServerComponentResponse.server.js +2 -1
- package/dist/node/framework/Hydration/rsc.d.ts +0 -3
- package/dist/node/framework/Hydration/rsc.js +40 -12
- package/dist/node/framework/cache/in-memory.js +0 -6
- package/dist/node/framework/cache-sub-request.d.ts +17 -0
- package/dist/node/framework/cache-sub-request.js +95 -0
- package/dist/node/framework/cache.d.ts +6 -6
- package/dist/node/framework/cache.js +38 -35
- package/dist/node/framework/plugin.js +5 -53
- package/dist/node/framework/plugins/vite-plugin-client-imports.d.ts +2 -0
- package/dist/node/framework/plugins/vite-plugin-client-imports.js +28 -0
- package/dist/node/framework/plugins/vite-plugin-css-modules-rsc.d.ts +1 -1
- package/dist/node/framework/plugins/vite-plugin-css-modules-rsc.js +76 -3
- package/dist/node/framework/plugins/vite-plugin-hydration-auto-import.js +1 -4
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +6 -4
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +1 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +2 -3
- package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.d.ts +1 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.js +41 -0
- package/dist/node/framework/plugins/vite-plugin-platform-entry.js +1 -1
- package/dist/node/framework/plugins/vite-plugin-ssr-interop.js +6 -3
- package/dist/node/storefront-api-types.d.ts +5 -3
- package/dist/node/storefront-api-types.js +5 -3
- package/dist/node/types.d.ts +4 -3
- package/dist/node/utilities/bot-ua.js +4 -0
- package/dist/node/utilities/html-encoding.d.ts +2 -0
- package/dist/node/utilities/html-encoding.js +21 -0
- package/dist/node/utilities/image_size.d.ts +4 -22
- package/dist/node/utilities/image_size.js +16 -58
- package/dist/node/utilities/index.d.ts +2 -1
- package/dist/node/utilities/index.js +4 -2
- package/dist/node/utilities/log/log-cache-api-status.js +5 -1
- package/dist/node/version.d.ts +1 -1
- package/dist/node/version.js +1 -1
- package/entry-server.d.ts +1 -1
- package/package.json +3 -3
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +200 -31
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-client-proxy.js +2 -0
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +200 -31
- package/vendor/react-server-dom-vite/package.json +2 -1
- package/dist/esnext/components/ProductDescription/ProductDescription.client.d.ts +0 -13
- package/dist/esnext/components/ProductDescription/ProductDescription.client.js +0 -16
- package/dist/esnext/components/ProductDescription/index.d.ts +0 -1
- package/dist/esnext/components/ProductDescription/index.js +0 -1
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.d.ts +0 -21
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +0 -42
- package/dist/esnext/components/ProductMetafield/index.d.ts +0 -2
- package/dist/esnext/components/ProductMetafield/index.js +0 -1
- package/dist/esnext/components/ProductTitle/ProductTitle.client.d.ts +0 -13
- package/dist/esnext/components/ProductTitle/ProductTitle.client.js +0 -16
- package/dist/esnext/components/ProductTitle/index.d.ts +0 -1
- package/dist/esnext/components/ProductTitle/index.js +0 -1
- package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +0 -15
- package/dist/esnext/components/UnitPrice/UnitPrice.client.js +0 -22
- package/dist/esnext/components/UnitPrice/index.d.ts +0 -1
- package/dist/esnext/components/UnitPrice/index.js +0 -1
|
@@ -9,50 +9,155 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { init, parse } from 'es-module-lexer';
|
|
12
|
+
import MagicString from 'magic-string';
|
|
12
13
|
import { normalizePath, transformWithEsbuild } from 'vite';
|
|
13
14
|
import { promises } from 'fs';
|
|
14
15
|
import path from 'path';
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
18
|
+
if (!o) return;
|
|
19
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
20
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
21
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
22
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
23
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function _arrayLikeToArray(arr, len) {
|
|
27
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
28
|
+
|
|
29
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
30
|
+
|
|
31
|
+
return arr2;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
35
|
+
var it;
|
|
36
|
+
|
|
37
|
+
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
|
|
38
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
39
|
+
if (it) o = it;
|
|
40
|
+
var i = 0;
|
|
41
|
+
|
|
42
|
+
var F = function () {};
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
s: F,
|
|
46
|
+
n: function () {
|
|
47
|
+
if (i >= o.length) return {
|
|
48
|
+
done: true
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
done: false,
|
|
52
|
+
value: o[i++]
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
e: function (e) {
|
|
56
|
+
throw e;
|
|
57
|
+
},
|
|
58
|
+
f: F
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
var normalCompletion = true,
|
|
66
|
+
didErr = false,
|
|
67
|
+
err;
|
|
68
|
+
return {
|
|
69
|
+
s: function () {
|
|
70
|
+
it = o[Symbol.iterator]();
|
|
71
|
+
},
|
|
72
|
+
n: function () {
|
|
73
|
+
var step = it.next();
|
|
74
|
+
normalCompletion = step.done;
|
|
75
|
+
return step;
|
|
76
|
+
},
|
|
77
|
+
e: function (e) {
|
|
78
|
+
didErr = true;
|
|
79
|
+
err = e;
|
|
80
|
+
},
|
|
81
|
+
f: function () {
|
|
82
|
+
try {
|
|
83
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
84
|
+
} finally {
|
|
85
|
+
if (didErr) throw err;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
17
91
|
var rscViteFileRE = /\/react-server-dom-vite.js/;
|
|
18
92
|
function ReactFlightVitePlugin() {
|
|
19
93
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
20
|
-
_ref$clientComponentP = _ref.clientComponentPaths,
|
|
21
|
-
clientComponentPaths = _ref$clientComponentP === void 0 ? [] : _ref$clientComponentP,
|
|
22
94
|
_ref$isServerComponen = _ref.isServerComponentImporterAllowed,
|
|
23
95
|
isServerComponentImporterAllowed = _ref$isServerComponen === void 0 ? function (importer) {
|
|
24
96
|
return false;
|
|
25
|
-
} : _ref$isServerComponen
|
|
97
|
+
} : _ref$isServerComponen,
|
|
98
|
+
_ref$isClientComponen = _ref.isClientComponent,
|
|
99
|
+
isClientComponent = _ref$isClientComponen === void 0 ? function (id) {
|
|
100
|
+
return /\.client\.[jt]sx?($|\?)/.test(id);
|
|
101
|
+
} : _ref$isClientComponen,
|
|
102
|
+
findClientComponentsForClientBuild = _ref.findClientComponentsForClientBuild;
|
|
26
103
|
|
|
27
104
|
var config;
|
|
105
|
+
var server;
|
|
106
|
+
var invalidateTimeout;
|
|
107
|
+
var absoluteImporterPath;
|
|
108
|
+
|
|
109
|
+
function invalidateImporter() {
|
|
110
|
+
clearTimeout(invalidateTimeout);
|
|
111
|
+
invalidateTimeout = setTimeout(function () {
|
|
112
|
+
return server.watcher.emit('change', absoluteImporterPath);
|
|
113
|
+
}, 100);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function wrapIfClientComponent(id) {
|
|
117
|
+
var handle = function (isClient) {
|
|
118
|
+
if (!isClient) return null;
|
|
119
|
+
|
|
120
|
+
if (server) {
|
|
121
|
+
var moduleNode = server.moduleGraph.getModuleById(id);
|
|
122
|
+
|
|
123
|
+
if (!moduleNode.__isClientComponent) {
|
|
124
|
+
moduleNode.__isClientComponent = true;
|
|
125
|
+
if (absoluteImporterPath) invalidateImporter();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return proxyClientComponent(id.split('?')[0]);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
var tmp = isClientComponent(id);
|
|
133
|
+
return typeof tmp === 'boolean' ? handle(tmp) : tmp.then(handle);
|
|
134
|
+
}
|
|
135
|
+
|
|
28
136
|
return {
|
|
29
137
|
name: 'vite-plugin-react-server-components',
|
|
30
138
|
enforce: 'pre',
|
|
139
|
+
configureServer: function (_server) {
|
|
140
|
+
server = _server;
|
|
141
|
+
},
|
|
31
142
|
configResolved: function (_config) {
|
|
32
143
|
config = _config; // By pushing this plugin at the end of the existing array,
|
|
33
144
|
// we enforce running it *after* Vite resolves import.meta.glob.
|
|
34
145
|
|
|
35
146
|
config.plugins.push(hashImportsPlugin);
|
|
36
147
|
},
|
|
37
|
-
resolveId:
|
|
148
|
+
resolveId: function (source, importer) {
|
|
38
149
|
if (!importer) return null;
|
|
39
150
|
/**
|
|
40
151
|
* Throw errors when non-Server Components try to load Server Components.
|
|
41
152
|
*/
|
|
42
153
|
|
|
43
|
-
if (/\.server(\.[jt]sx?)?$/.test(source) && !(/(\.server\.[jt]sx?|
|
|
154
|
+
if (/\.server(\.[jt]sx?)?$/.test(source) && !(/(\.server\.[jt]sx?|index\.html)$/.test(importer) || isServerComponentImporterAllowed(importer, source))) {
|
|
44
155
|
throw new Error("Cannot import " + source + " from \"" + importer + "\". " + 'By react-server convention, .server.js files can only be imported from other .server.js files. ' + 'That way nobody accidentally sends these to the client by indirectly importing it.');
|
|
45
156
|
}
|
|
46
157
|
},
|
|
47
|
-
load:
|
|
158
|
+
load: function (id) {
|
|
48
159
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (/\.client\.[jt]sx?$/.test(id)) {
|
|
52
|
-
return proxyClientComponent(id);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return null;
|
|
160
|
+
return options.ssr && shouldCheckClientComponent(id) ? wrapIfClientComponent(id) : null;
|
|
56
161
|
},
|
|
57
162
|
transform: function (code, id) {
|
|
58
163
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -68,27 +173,53 @@ function ReactFlightVitePlugin() {
|
|
|
68
173
|
*/
|
|
69
174
|
if (rscViteFileRE.test(id)) {
|
|
70
175
|
var INJECTING_RE = /\{\s*__INJECTED_CLIENT_IMPORTERS__[:\s]*null[,\s]*\}\s*;/;
|
|
176
|
+
var s = new MagicString(code);
|
|
177
|
+
id = id.split('?')[0];
|
|
71
178
|
|
|
72
179
|
if (options && options.ssr) {
|
|
73
180
|
// In SSR, directly use components already discovered by RSC
|
|
74
181
|
// instead of globs to avoid bundling unused components.
|
|
75
|
-
|
|
182
|
+
s.replace(INJECTING_RE, 'globalThis.__COMPONENT_INDEX');
|
|
183
|
+
return {
|
|
184
|
+
code: s.toString(),
|
|
185
|
+
map: s.generateMap({
|
|
186
|
+
file: id,
|
|
187
|
+
source: id
|
|
188
|
+
})
|
|
189
|
+
};
|
|
76
190
|
}
|
|
77
191
|
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
192
|
+
var injectGlobs = function (clientComponents) {
|
|
193
|
+
var importerPath = path.dirname(id);
|
|
194
|
+
var importers = clientComponents.map(function (absolutePath) {
|
|
195
|
+
return normalizePath(path.relative(importerPath, absolutePath));
|
|
196
|
+
});
|
|
197
|
+
var injectedGlobs = "Object.assign(Object.create(null), " + importers.map(function (glob) {
|
|
198
|
+
return (// Mark the globs to modify the result after Vite resolves them.
|
|
199
|
+
"/* HASH_BEGIN */ " + ("import.meta.glob('" + normalizePath(glob) + "') /* HASH_END */")
|
|
200
|
+
);
|
|
201
|
+
}).join(', ') + ");";
|
|
202
|
+
s.replace(INJECTING_RE, injectedGlobs);
|
|
203
|
+
return {
|
|
204
|
+
code: s.toString(),
|
|
205
|
+
map: s.generateMap({
|
|
206
|
+
file: id,
|
|
207
|
+
source: id
|
|
208
|
+
})
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
if (config.command === 'serve') {
|
|
213
|
+
absoluteImporterPath = id;
|
|
214
|
+
return injectGlobs(findClientComponentsForDev(server));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!findClientComponentsForClientBuild) {
|
|
218
|
+
throw new Error('[react-server-dom-vite] Parameter findClientComponentsForClientBuild is required for client build');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var tmp = findClientComponentsForClientBuild(config);
|
|
222
|
+
return Array.isArray(tmp) ? injectGlobs(tmp) : tmp.then(injectGlobs);
|
|
92
223
|
}
|
|
93
224
|
}
|
|
94
225
|
};
|
|
@@ -147,20 +278,58 @@ async function proxyClientComponent(filepath, src) {
|
|
|
147
278
|
});
|
|
148
279
|
return proxyCode;
|
|
149
280
|
}
|
|
281
|
+
|
|
282
|
+
function shouldCheckClientComponent(id) {
|
|
283
|
+
return /\.[jt]sx?($|\?)/.test(id) && !/[&?]no-proxy($|&)/.test(id);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function findClientComponentsForDev(server) {
|
|
287
|
+
var clientComponents = []; // eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
|
288
|
+
|
|
289
|
+
var _iterator = _createForOfIteratorHelper(server.moduleGraph.fileToModulesMap.values()),
|
|
290
|
+
_step;
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
294
|
+
var set = _step.value;
|
|
295
|
+
var clientModule = Array.from(set).find(function (moduleNode) {
|
|
296
|
+
return moduleNode.__isClientComponent;
|
|
297
|
+
});
|
|
298
|
+
if (clientModule) clientComponents.push(clientModule.file);
|
|
299
|
+
}
|
|
300
|
+
} catch (err) {
|
|
301
|
+
_iterator.e(err);
|
|
302
|
+
} finally {
|
|
303
|
+
_iterator.f();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return clientComponents;
|
|
307
|
+
}
|
|
308
|
+
|
|
150
309
|
var hashImportsPlugin = {
|
|
151
310
|
name: 'vite-plugin-react-server-components-hash-imports',
|
|
152
311
|
enforce: 'post',
|
|
153
312
|
transform: function (code, id) {
|
|
154
313
|
// Turn relative import paths to lossy hashes
|
|
155
314
|
if (rscViteFileRE.test(id)) {
|
|
156
|
-
|
|
315
|
+
var s = new MagicString(code);
|
|
316
|
+
s.replace(/\/\*\s*HASH_BEGIN\s*\*\/\s*([^]+?)\/\*\s*HASH_END\s*\*\//gm, function (_, imports) {
|
|
157
317
|
return imports.trim().replace(/"([^"]+?)":/gm, function (__, relativePath) {
|
|
158
318
|
var absolutePath = path.resolve(path.dirname(id.split('?')[0]), relativePath);
|
|
159
319
|
return "\"" + getComponentId(normalizePath(absolutePath)) + "\":";
|
|
160
320
|
});
|
|
161
321
|
});
|
|
322
|
+
return {
|
|
323
|
+
code: s.toString(),
|
|
324
|
+
map: s.generateMap({
|
|
325
|
+
file: id,
|
|
326
|
+
source: id
|
|
327
|
+
})
|
|
328
|
+
};
|
|
162
329
|
}
|
|
163
330
|
}
|
|
164
|
-
};
|
|
331
|
+
}; // This can be used in custom findClientComponentsForClientBuild implementations
|
|
332
|
+
|
|
333
|
+
ReactFlightVitePlugin.findClientComponentsFromServer = findClientComponentsForDev;
|
|
165
334
|
|
|
166
335
|
export default ReactFlightVitePlugin;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ElementType } from 'react';
|
|
2
|
-
import { Props } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* The `ProductDescription` component renders a `div` with
|
|
5
|
-
* the product's [`descriptionHtml`](https://shopify.dev/api/storefront/reference/products/product).
|
|
6
|
-
* It must be a descendent of the `ProductProvider` component.
|
|
7
|
-
*/
|
|
8
|
-
export declare function ProductDescription<TTag extends ElementType = 'div'>(props: Props<TTag> & {
|
|
9
|
-
/** An HTML tag to wrap the description. If not specified, then the
|
|
10
|
-
* description is wrapped in a `div` element.
|
|
11
|
-
*/
|
|
12
|
-
as?: TTag;
|
|
13
|
-
}): JSX.Element | null;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useProduct } from '../ProductProvider';
|
|
3
|
-
/**
|
|
4
|
-
* The `ProductDescription` component renders a `div` with
|
|
5
|
-
* the product's [`descriptionHtml`](https://shopify.dev/api/storefront/reference/products/product).
|
|
6
|
-
* It must be a descendent of the `ProductProvider` component.
|
|
7
|
-
*/
|
|
8
|
-
export function ProductDescription(props) {
|
|
9
|
-
var _a;
|
|
10
|
-
const product = useProduct();
|
|
11
|
-
if (product == null) {
|
|
12
|
-
throw new Error('Expected a ProductProvider context, but none was found');
|
|
13
|
-
}
|
|
14
|
-
const Wrapper = (_a = props.as) !== null && _a !== void 0 ? _a : 'div';
|
|
15
|
-
return product.descriptionHtml ? (React.createElement(Wrapper, { dangerouslySetInnerHTML: { __html: product.descriptionHtml }, ...props })) : null;
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ProductDescription } from './ProductDescription.client';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ProductDescription } from './ProductDescription.client';
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ElementType } from 'react';
|
|
2
|
-
import { Props } from '../types';
|
|
3
|
-
import { MetafieldProps } from '../Metafield/Metafield.client';
|
|
4
|
-
export interface ProductMetafieldProps<TTag> extends Omit<MetafieldProps<TTag>, 'metafield'> {
|
|
5
|
-
/** A string corresponding to the [key](https://shopify.dev/api/storefront/reference/common-objects/metafield) of the product's
|
|
6
|
-
* metafield.
|
|
7
|
-
*/
|
|
8
|
-
keyName: string;
|
|
9
|
-
/** A string corresponding to the [namespace](https://shopify.dev/api/storefront/reference/common-objects/metafield) of the
|
|
10
|
-
* product's metafield.
|
|
11
|
-
*/
|
|
12
|
-
namespace: string;
|
|
13
|
-
/** The ID of the variant. If provided, then use the metafield corresponding to the variant ID instead of the product's metafield. */
|
|
14
|
-
variantId?: string;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* The `ProductMetafield` component renders a
|
|
18
|
-
* [`Metafield`](https://shopify.dev/api/hydrogen/components/primitive/metafield) component with the product metafield.
|
|
19
|
-
* It must be a descendent of a `ProductProvider` component.
|
|
20
|
-
*/
|
|
21
|
-
export declare function ProductMetafield<TTag extends ElementType>(props: Props<TTag> & Omit<ProductMetafieldProps<TTag>, 'data'>): JSX.Element | null;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Metafield } from '../Metafield';
|
|
3
|
-
import { useProduct } from '../../hooks/useProduct/useProduct';
|
|
4
|
-
import { flattenConnection } from '../../utilities';
|
|
5
|
-
/**
|
|
6
|
-
* The `ProductMetafield` component renders a
|
|
7
|
-
* [`Metafield`](https://shopify.dev/api/hydrogen/components/primitive/metafield) component with the product metafield.
|
|
8
|
-
* It must be a descendent of a `ProductProvider` component.
|
|
9
|
-
*/
|
|
10
|
-
export function ProductMetafield(props) {
|
|
11
|
-
var _a, _b, _c;
|
|
12
|
-
const product = useProduct();
|
|
13
|
-
if (product == null) {
|
|
14
|
-
throw new Error('Expected a ProductProvider context, but none was found');
|
|
15
|
-
}
|
|
16
|
-
if (product.metafields == null) {
|
|
17
|
-
console.warn('No metafields available for product');
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const { namespace, keyName, variantId, ...passthroughProps } = props;
|
|
21
|
-
const metafields = (variantId
|
|
22
|
-
? flattenConnection((_c = (_b = (_a = product.variants) === null || _a === void 0 ? void 0 : _a.find((variant) => (variant === null || variant === void 0 ? void 0 : variant.id) === variantId)) === null || _b === void 0 ? void 0 : _b.metafields) !== null && _c !== void 0 ? _c : {})
|
|
23
|
-
: product.metafields); // TODO: fix the typing here and ensure it's correct
|
|
24
|
-
const field = metafields === null || metafields === void 0 ? void 0 : metafields.find((metafield) => metafield.namespace === namespace && metafield.key === keyName);
|
|
25
|
-
if (field === null || field === undefined) {
|
|
26
|
-
const message = 'does not have a value for metafield.';
|
|
27
|
-
const productOrVariant = variantId ? `Variant` : 'Product';
|
|
28
|
-
const logItems = {
|
|
29
|
-
variantId,
|
|
30
|
-
ProductId: product.id,
|
|
31
|
-
namespace,
|
|
32
|
-
keyName,
|
|
33
|
-
};
|
|
34
|
-
console.warn([
|
|
35
|
-
productOrVariant,
|
|
36
|
-
message,
|
|
37
|
-
...Object.entries(logItems).map(([key, val]) => `${key}: ${val}`),
|
|
38
|
-
].join(' '));
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
return React.createElement(Metafield, { data: field, ...passthroughProps });
|
|
42
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ProductMetafield } from './ProductMetafield.client';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ElementType } from 'react';
|
|
2
|
-
import { Props } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* The `ProductTitle` component renders a `span` element (or the type of
|
|
5
|
-
* HTML element specified by the `as` prop) with the product's [`title`](https://shopify.dev/api/storefront/reference/products/product).
|
|
6
|
-
* It must be a descendent of the `ProductProvider` component.
|
|
7
|
-
*/
|
|
8
|
-
export declare function ProductTitle<TTag extends ElementType = 'span'>(props: Props<TTag> & {
|
|
9
|
-
/** An HTML tag to wrap the title. If not specified, then the
|
|
10
|
-
* title is wrapped in a `span` element.
|
|
11
|
-
*/
|
|
12
|
-
as?: TTag;
|
|
13
|
-
}): JSX.Element | null;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useProduct } from '../ProductProvider';
|
|
3
|
-
/**
|
|
4
|
-
* The `ProductTitle` component renders a `span` element (or the type of
|
|
5
|
-
* HTML element specified by the `as` prop) with the product's [`title`](https://shopify.dev/api/storefront/reference/products/product).
|
|
6
|
-
* It must be a descendent of the `ProductProvider` component.
|
|
7
|
-
*/
|
|
8
|
-
export function ProductTitle(props) {
|
|
9
|
-
const product = useProduct();
|
|
10
|
-
if (product == null) {
|
|
11
|
-
throw new Error('Expected a ProductProvider context, but none was found');
|
|
12
|
-
}
|
|
13
|
-
const { as, ...passthroughProps } = props;
|
|
14
|
-
const Wrapper = as ? as : 'span';
|
|
15
|
-
return product.title ? (React.createElement(Wrapper, { ...passthroughProps }, product.title)) : null;
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ProductTitle } from './ProductTitle.client';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ProductTitle } from './ProductTitle.client';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { UnitPriceMeasurement, MoneyV2 } from '../../storefront-api-types';
|
|
2
|
-
import type { PartialDeep } from 'type-fest';
|
|
3
|
-
export interface UnitPriceProps<TTag> {
|
|
4
|
-
/** An object with fields that correspond to the Storefront API's [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2). */
|
|
5
|
-
data: PartialDeep<MoneyV2>;
|
|
6
|
-
/** A [UnitPriceMeasurement object](https://shopify.dev/api/storefront/reference/products/unitpricemeasurement). */
|
|
7
|
-
measurement: PartialDeep<UnitPriceMeasurement>;
|
|
8
|
-
/** An HTML tag to be rendered as the base element wrapper. The default is `div`. */
|
|
9
|
-
as?: TTag;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* The `UnitPrice` component renders a string with a [UnitPrice](https://shopify.dev/themes/pricing-payments/unit-pricing) as the
|
|
13
|
-
* Storefront API's [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) with a reference unit from the Storefront API's [UnitPriceMeasurement object](/api/storefront/reference/products/unitpricemeasurement).
|
|
14
|
-
*/
|
|
15
|
-
export declare function UnitPrice<TTag extends keyof JSX.IntrinsicElements = 'div'>(props: JSX.IntrinsicElements[TTag] & UnitPriceProps<TTag>): JSX.Element | null;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Money } from '../Money';
|
|
3
|
-
/**
|
|
4
|
-
* The `UnitPrice` component renders a string with a [UnitPrice](https://shopify.dev/themes/pricing-payments/unit-pricing) as the
|
|
5
|
-
* Storefront API's [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) with a reference unit from the Storefront API's [UnitPriceMeasurement object](/api/storefront/reference/products/unitpricemeasurement).
|
|
6
|
-
*/
|
|
7
|
-
export function UnitPrice(props) {
|
|
8
|
-
const { data, measurement, as, ...passthroughProps } = props;
|
|
9
|
-
if (!data) {
|
|
10
|
-
console.warn(`No "data" prop was passed to <UnitPrice/>`);
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
if (!measurement) {
|
|
14
|
-
console.warn(`No "measurement" prop was passed to <UnitPrice/>`);
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
const Wrapper = as !== null && as !== void 0 ? as : 'div';
|
|
18
|
-
return (React.createElement(Wrapper, { ...passthroughProps },
|
|
19
|
-
React.createElement(Money, { data: data }),
|
|
20
|
-
"/",
|
|
21
|
-
measurement.referenceUnit));
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { UnitPrice } from './UnitPrice.client';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { UnitPrice } from './UnitPrice.client';
|