@weaverse/hydrogen 5.13.1 → 5.14.1
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/index.d.mts +45 -4
- package/dist/index.d.ts +45 -4
- package/dist/index.js +122 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -143,6 +143,73 @@ function useWeaverseDataContext() {
|
|
|
143
143
|
function createWeaverseDataContext(matches) {
|
|
144
144
|
return createFlatDataContext(matches);
|
|
145
145
|
}
|
|
146
|
+
|
|
147
|
+
// src/seo.ts
|
|
148
|
+
function formatMetaDescriptors(seo) {
|
|
149
|
+
if (!seo) {
|
|
150
|
+
return [{ name: "robots", content: "index,follow" }];
|
|
151
|
+
}
|
|
152
|
+
let descriptors = [];
|
|
153
|
+
if (seo.title) {
|
|
154
|
+
descriptors.push({ title: seo.title });
|
|
155
|
+
}
|
|
156
|
+
if (seo.description) {
|
|
157
|
+
descriptors.push({ name: "description", content: seo.description });
|
|
158
|
+
}
|
|
159
|
+
if (seo.keywords) {
|
|
160
|
+
descriptors.push({ name: "keywords", content: seo.keywords });
|
|
161
|
+
}
|
|
162
|
+
if (seo.canonicalUrl) {
|
|
163
|
+
descriptors.push({
|
|
164
|
+
tagName: "link",
|
|
165
|
+
rel: "canonical",
|
|
166
|
+
href: seo.canonicalUrl
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
let og = seo.openGraph;
|
|
170
|
+
if (og && (og.title || og.description || og.image || og.type)) {
|
|
171
|
+
if (og.title) {
|
|
172
|
+
descriptors.push({ property: "og:title", content: og.title });
|
|
173
|
+
}
|
|
174
|
+
if (og.description) {
|
|
175
|
+
descriptors.push({ property: "og:description", content: og.description });
|
|
176
|
+
}
|
|
177
|
+
if (og.image) {
|
|
178
|
+
descriptors.push({ property: "og:image", content: og.image });
|
|
179
|
+
}
|
|
180
|
+
descriptors.push({ property: "og:type", content: og.type || "website" });
|
|
181
|
+
}
|
|
182
|
+
let tw = seo.twitter;
|
|
183
|
+
if (tw && (tw.title || tw.description || tw.image || tw.cardType)) {
|
|
184
|
+
descriptors.push({
|
|
185
|
+
name: "twitter:card",
|
|
186
|
+
content: tw.cardType || "summary"
|
|
187
|
+
});
|
|
188
|
+
if (tw.title) {
|
|
189
|
+
descriptors.push({ name: "twitter:title", content: tw.title });
|
|
190
|
+
}
|
|
191
|
+
if (tw.description) {
|
|
192
|
+
descriptors.push({ name: "twitter:description", content: tw.description });
|
|
193
|
+
}
|
|
194
|
+
if (tw.image) {
|
|
195
|
+
descriptors.push({ name: "twitter:image", content: tw.image });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
let index = seo.robots?.index !== false;
|
|
199
|
+
let follow = seo.robots?.follow !== false;
|
|
200
|
+
descriptors.push({
|
|
201
|
+
name: "robots",
|
|
202
|
+
content: `${index ? "index" : "noindex"},${follow ? "follow" : "nofollow"}`
|
|
203
|
+
});
|
|
204
|
+
return descriptors;
|
|
205
|
+
}
|
|
206
|
+
function getWeaverseSeoMeta(data) {
|
|
207
|
+
if (!data) {
|
|
208
|
+
return formatMetaDescriptors(null);
|
|
209
|
+
}
|
|
210
|
+
let page = "items" in data && "id" in data ? data : data.page ?? null;
|
|
211
|
+
return formatMetaDescriptors(page?.seo ?? null);
|
|
212
|
+
}
|
|
146
213
|
function isProjectIdFunction(projectId) {
|
|
147
214
|
return typeof projectId === "function";
|
|
148
215
|
}
|
|
@@ -230,7 +297,6 @@ function getWeaverseConfigs(request, env) {
|
|
|
230
297
|
WEAVERSE_PROJECT_ID,
|
|
231
298
|
WEAVERSE_API_KEY,
|
|
232
299
|
WEAVERSE_HOST,
|
|
233
|
-
WEAVERSE_API_BASE,
|
|
234
300
|
PUBLIC_STORE_DOMAIN,
|
|
235
301
|
PUBLIC_STOREFRONT_API_TOKEN
|
|
236
302
|
} = env || {};
|
|
@@ -246,10 +312,11 @@ function getWeaverseConfigs(request, env) {
|
|
|
246
312
|
} = queries;
|
|
247
313
|
let url = new URL(request.url);
|
|
248
314
|
let isRevisionPreview = url.searchParams.has("__revisionId");
|
|
315
|
+
let resolvedWeaverseHost = weaverseHost || WEAVERSE_HOST || envFromProcess.WEAVERSE_HOST || "https://studio.weaverse.io";
|
|
249
316
|
return {
|
|
250
317
|
projectId: weaverseProjectId || WEAVERSE_PROJECT_ID || envFromProcess.WEAVERSE_PROJECT_ID || "",
|
|
251
|
-
weaverseHost:
|
|
252
|
-
weaverseApiBase:
|
|
318
|
+
weaverseHost: resolvedWeaverseHost,
|
|
319
|
+
weaverseApiBase: resolvedWeaverseHost,
|
|
253
320
|
weaverseApiKey: weaverseApiKey || WEAVERSE_API_KEY || envFromProcess.WEAVERSE_API_KEY || "",
|
|
254
321
|
weaverseVersion: weaverseVersion || "",
|
|
255
322
|
isDesignMode,
|
|
@@ -440,6 +507,46 @@ function hasWeaverseData(value) {
|
|
|
440
507
|
}
|
|
441
508
|
return value.weaverseData !== void 0;
|
|
442
509
|
}
|
|
510
|
+
|
|
511
|
+
// src/utils/studio-request-info.ts
|
|
512
|
+
function getBrowserLocation() {
|
|
513
|
+
if (typeof window === "undefined") {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
return window.location;
|
|
517
|
+
}
|
|
518
|
+
function getQueriesFromSearch(search) {
|
|
519
|
+
let queries = {};
|
|
520
|
+
let params = new URLSearchParams(search);
|
|
521
|
+
for (let [key, value] of params.entries()) {
|
|
522
|
+
if (value === "true") {
|
|
523
|
+
queries[key] = true;
|
|
524
|
+
} else if (value === "false") {
|
|
525
|
+
queries[key] = false;
|
|
526
|
+
} else {
|
|
527
|
+
queries[key] = value;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return queries;
|
|
531
|
+
}
|
|
532
|
+
function normalizeDesignModeRequestInfo(params, browserLocation = getBrowserLocation()) {
|
|
533
|
+
if (!(params.isDesignMode && browserLocation)) {
|
|
534
|
+
return params;
|
|
535
|
+
}
|
|
536
|
+
let { pathname, search } = browserLocation;
|
|
537
|
+
if (params.requestInfo.pathname === pathname && params.requestInfo.search === search) {
|
|
538
|
+
return params;
|
|
539
|
+
}
|
|
540
|
+
return {
|
|
541
|
+
...params,
|
|
542
|
+
requestInfo: {
|
|
543
|
+
...params.requestInfo,
|
|
544
|
+
pathname,
|
|
545
|
+
queries: getQueriesFromSearch(search),
|
|
546
|
+
search
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
}
|
|
443
550
|
var ThemeSettingsStore = class {
|
|
444
551
|
settings = {};
|
|
445
552
|
schema;
|
|
@@ -759,22 +866,23 @@ var WeaverseHydrogen = class extends Weaverse {
|
|
|
759
866
|
};
|
|
760
867
|
};
|
|
761
868
|
function createWeaverseInstance(params) {
|
|
869
|
+
const normalizedParams = normalizeDesignModeRequestInfo(params);
|
|
762
870
|
if (isBrowser) {
|
|
763
871
|
window.__weaverses = window.__weaverses || {};
|
|
764
|
-
let weaverse = window.__weaverses[
|
|
765
|
-
if (!weaverse || weaverse?.requestInfo?.pathname !==
|
|
766
|
-
weaverse = new WeaverseHydrogen(
|
|
767
|
-
window.__weaverses[
|
|
872
|
+
let weaverse = window.__weaverses[normalizedParams.pageId];
|
|
873
|
+
if (!weaverse || weaverse?.requestInfo?.pathname !== normalizedParams.requestInfo.pathname || weaverse?.requestInfo?.search !== normalizedParams.requestInfo.search) {
|
|
874
|
+
weaverse = new WeaverseHydrogen(normalizedParams);
|
|
875
|
+
window.__weaverses[normalizedParams.pageId] = weaverse;
|
|
768
876
|
}
|
|
769
877
|
if (weaverse?.isDesignMode) {
|
|
770
|
-
weaverse.requestInfo =
|
|
878
|
+
weaverse.requestInfo = normalizedParams.requestInfo;
|
|
771
879
|
if (hasWeaverseStudio(window)) {
|
|
772
|
-
window.weaverseStudio.refreshStudio(
|
|
880
|
+
window.weaverseStudio.refreshStudio(normalizedParams);
|
|
773
881
|
}
|
|
774
882
|
}
|
|
775
883
|
return weaverse;
|
|
776
884
|
}
|
|
777
|
-
return new WeaverseHydrogen(
|
|
885
|
+
return new WeaverseHydrogen(normalizedParams);
|
|
778
886
|
}
|
|
779
887
|
var StudioBridge = memo(({ context }) => {
|
|
780
888
|
useStudio(context);
|
|
@@ -1219,11 +1327,8 @@ var WeaverseClient = class {
|
|
|
1219
1327
|
}
|
|
1220
1328
|
};
|
|
1221
1329
|
// Helper method for building API URLs consistently
|
|
1222
|
-
getApiUrl(endpoint
|
|
1223
|
-
const { weaverseHost
|
|
1224
|
-
if (useProxy) {
|
|
1225
|
-
return `${weaverseApiBase}/v1/${endpoint}?projectId=${projectId}`;
|
|
1226
|
-
}
|
|
1330
|
+
getApiUrl(endpoint) {
|
|
1331
|
+
const { weaverseHost } = this.configs;
|
|
1227
1332
|
return `${weaverseHost}/api/public/${endpoint}`;
|
|
1228
1333
|
}
|
|
1229
1334
|
/**
|
|
@@ -1701,6 +1806,6 @@ var IMAGES_PLACEHOLDERS = {
|
|
|
1701
1806
|
product_18: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-watch-2-1024x1024.svg"
|
|
1702
1807
|
};
|
|
1703
1808
|
|
|
1704
|
-
export { IMAGES_PLACEHOLDERS, ThemeTextProvider, ThemeTextStore, WeaverseClient, WeaverseError, WeaverseHydrogen, WeaverseHydrogenItem, WeaverseHydrogenRoot, createWeaverseDataContext, defaultComponents, generateDataFromSchema, getNestedKey, getPreviewData, getRequestQueries, getSelectedProductOptions, getWeaverseConfigs, hasError, hasWeaverseStudio, interpolate, isFetchProjectPayload, isProjectIdFunction, isThemeSettingsResponse, isValidHydrogenSchema, isWithCacheFetchResponse, registerComponent, useThemeSettings, useThemeText, useWeaverseDataContext, withWeaverse };
|
|
1809
|
+
export { IMAGES_PLACEHOLDERS, ThemeTextProvider, ThemeTextStore, WeaverseClient, WeaverseError, WeaverseHydrogen, WeaverseHydrogenItem, WeaverseHydrogenRoot, createWeaverseDataContext, defaultComponents, formatMetaDescriptors, generateDataFromSchema, getNestedKey, getPreviewData, getRequestQueries, getSelectedProductOptions, getWeaverseConfigs, getWeaverseSeoMeta, hasError, hasWeaverseStudio, interpolate, isFetchProjectPayload, isProjectIdFunction, isThemeSettingsResponse, isValidHydrogenSchema, isWithCacheFetchResponse, registerComponent, useThemeSettings, useThemeText, useWeaverseDataContext, withWeaverse };
|
|
1705
1810
|
//# sourceMappingURL=index.mjs.map
|
|
1706
1811
|
//# sourceMappingURL=index.mjs.map
|