@weaverse/hydrogen 5.15.1 → 5.16.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/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +66 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -297,6 +297,7 @@ function getWeaverseConfigs(request, env) {
|
|
|
297
297
|
WEAVERSE_PROJECT_ID,
|
|
298
298
|
WEAVERSE_API_KEY,
|
|
299
299
|
WEAVERSE_HOST,
|
|
300
|
+
WEAVERSE_PUBLIC_API_BASE,
|
|
300
301
|
PUBLIC_STORE_DOMAIN,
|
|
301
302
|
PUBLIC_STOREFRONT_API_TOKEN
|
|
302
303
|
} = env || {};
|
|
@@ -312,11 +313,14 @@ function getWeaverseConfigs(request, env) {
|
|
|
312
313
|
} = queries;
|
|
313
314
|
let url = new URL(request.url);
|
|
314
315
|
let isRevisionPreview = url.searchParams.has("__revisionId");
|
|
315
|
-
let
|
|
316
|
+
let configuredWeaverseHost = WEAVERSE_HOST || envFromProcess.WEAVERSE_HOST;
|
|
317
|
+
let resolvedWeaverseHost = weaverseHost || configuredWeaverseHost || "https://studio.weaverse.io";
|
|
318
|
+
let resolvedWeaverseApiBase = weaverseHost ? weaverseHost : WEAVERSE_PUBLIC_API_BASE || envFromProcess.WEAVERSE_PUBLIC_API_BASE || (configuredWeaverseHost && configuredWeaverseHost !== "https://studio.weaverse.io" ? configuredWeaverseHost : "https://api.weaverse.io");
|
|
316
319
|
return {
|
|
317
320
|
projectId: weaverseProjectId || WEAVERSE_PROJECT_ID || envFromProcess.WEAVERSE_PROJECT_ID || "",
|
|
318
321
|
weaverseHost: resolvedWeaverseHost,
|
|
319
|
-
weaverseApiBase:
|
|
322
|
+
weaverseApiBase: resolvedWeaverseApiBase,
|
|
323
|
+
weaversePublicApiBase: resolvedWeaverseApiBase,
|
|
320
324
|
weaverseApiKey: weaverseApiKey || WEAVERSE_API_KEY || envFromProcess.WEAVERSE_API_KEY || "",
|
|
321
325
|
weaverseVersion: weaverseVersion || "",
|
|
322
326
|
isDesignMode,
|
|
@@ -568,6 +572,32 @@ function syncReusedInstance(weaverse, params) {
|
|
|
568
572
|
weaverse.triggerUpdate();
|
|
569
573
|
}
|
|
570
574
|
}
|
|
575
|
+
|
|
576
|
+
// src/utils/pixel.ts
|
|
577
|
+
var currentNavigationKey = null;
|
|
578
|
+
var firedPageIds = /* @__PURE__ */ new Set();
|
|
579
|
+
var mountedInstances = 0;
|
|
580
|
+
function shouldFirePixel(navigationKey, pageId) {
|
|
581
|
+
if (navigationKey !== currentNavigationKey) {
|
|
582
|
+
currentNavigationKey = navigationKey;
|
|
583
|
+
firedPageIds.clear();
|
|
584
|
+
}
|
|
585
|
+
if (firedPageIds.has(pageId)) {
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
firedPageIds.add(pageId);
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
function registerPixelInstance() {
|
|
592
|
+
mountedInstances += 1;
|
|
593
|
+
return () => {
|
|
594
|
+
mountedInstances -= 1;
|
|
595
|
+
if (mountedInstances === 0) {
|
|
596
|
+
currentNavigationKey = null;
|
|
597
|
+
firedPageIds.clear();
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
}
|
|
571
601
|
var ThemeSettingsStore = class {
|
|
572
602
|
settings = {};
|
|
573
603
|
schema;
|
|
@@ -727,13 +757,18 @@ function useStudio(weaverse) {
|
|
|
727
757
|
}
|
|
728
758
|
function usePixel(context) {
|
|
729
759
|
let { projectId, pageId, isDesignMode, weaverseHost } = context;
|
|
760
|
+
let { key: navigationKey } = useLocation();
|
|
730
761
|
useEffect(() => {
|
|
731
762
|
if (!(projectId && pageId) || isDesignMode) {
|
|
732
763
|
return;
|
|
733
764
|
}
|
|
734
|
-
let
|
|
735
|
-
|
|
736
|
-
|
|
765
|
+
let unregister = registerPixelInstance();
|
|
766
|
+
if (shouldFirePixel(navigationKey, pageId)) {
|
|
767
|
+
let img = new Image();
|
|
768
|
+
img.onload = () => img.remove();
|
|
769
|
+
img.src = `${weaverseHost}/api/public/px?projectId=${projectId}&pageId=${pageId}`;
|
|
770
|
+
}
|
|
771
|
+
return unregister;
|
|
737
772
|
}, []);
|
|
738
773
|
}
|
|
739
774
|
var WeaverseHydrogenItem = class extends WeaverseItemStore {
|
|
@@ -924,15 +959,21 @@ var StudioBridge = memo(({ context }) => {
|
|
|
924
959
|
useStudio(context);
|
|
925
960
|
return null;
|
|
926
961
|
});
|
|
962
|
+
var registeredComponentLists = /* @__PURE__ */ new WeakSet();
|
|
927
963
|
function RenderRoot(props) {
|
|
928
964
|
const { data, components, dataContext } = props;
|
|
929
|
-
|
|
930
|
-
comp
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
965
|
+
if (!registeredComponentLists.has(components)) {
|
|
966
|
+
for (const comp of [...components, ...defaultComponents]) {
|
|
967
|
+
if (comp?.schema?.type) {
|
|
968
|
+
registerComponent({
|
|
969
|
+
type: comp.schema.type,
|
|
970
|
+
Component: comp.default,
|
|
971
|
+
schema: comp.schema,
|
|
972
|
+
loader: comp.loader
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
registeredComponentLists.add(components);
|
|
936
977
|
}
|
|
937
978
|
const { page, configs, project, pageAssignment } = data || {};
|
|
938
979
|
const weaverse = createWeaverseInstance({
|
|
@@ -957,7 +998,10 @@ var WeaverseHydrogenRoot = memo(
|
|
|
957
998
|
errorComponent: ErrorComponent = ({ error }) => /* @__PURE__ */ jsx("div", { children: error instanceof Error ? error.message : "An unexpected error occurred" })
|
|
958
999
|
}) => {
|
|
959
1000
|
const matches = useMatches();
|
|
960
|
-
const enhancedDataContext =
|
|
1001
|
+
const enhancedDataContext = useMemo(
|
|
1002
|
+
() => createWeaverseDataContext(matches),
|
|
1003
|
+
[matches]
|
|
1004
|
+
);
|
|
961
1005
|
const ownLoaderData = useLoaderData();
|
|
962
1006
|
const weaverseData = useMemo(
|
|
963
1007
|
() => pickWeaverseData(dataProp, ownLoaderData, matches),
|
|
@@ -1398,8 +1442,12 @@ var WeaverseClient = class {
|
|
|
1398
1442
|
};
|
|
1399
1443
|
// Helper method for building API URLs consistently
|
|
1400
1444
|
getApiUrl(endpoint) {
|
|
1401
|
-
const {
|
|
1402
|
-
return `${
|
|
1445
|
+
const { weaverseApiBase } = this.configs;
|
|
1446
|
+
return `${weaverseApiBase}/api/public/${endpoint}`;
|
|
1447
|
+
}
|
|
1448
|
+
isExternalPublicApiUrl(url) {
|
|
1449
|
+
const { weaverseApiBase, weaverseHost } = this.configs;
|
|
1450
|
+
return weaverseApiBase !== weaverseHost && url.startsWith(`${weaverseApiBase}/api/public/`);
|
|
1403
1451
|
}
|
|
1404
1452
|
/**
|
|
1405
1453
|
* Fetch data with caching support for both design mode and production.
|
|
@@ -1432,7 +1480,7 @@ var WeaverseClient = class {
|
|
|
1432
1480
|
cacheTarget || "default"
|
|
1433
1481
|
];
|
|
1434
1482
|
let result;
|
|
1435
|
-
if (this.configs.isDesignMode || this.configs.isRevisionPreview) {
|
|
1483
|
+
if (this.configs.isDesignMode || this.configs.isRevisionPreview || this.isExternalPublicApiUrl(url)) {
|
|
1436
1484
|
result = await this.directFetch(url, fetchOptions);
|
|
1437
1485
|
} else {
|
|
1438
1486
|
result = await this.withCache.fetch(url, fetchOptions, {
|
|
@@ -1613,7 +1661,7 @@ var WeaverseClient = class {
|
|
|
1613
1661
|
* Paginates automatically, never throws, returns accumulated results on partial failure.
|
|
1614
1662
|
*/
|
|
1615
1663
|
async fetchCustomPages(opts) {
|
|
1616
|
-
const {
|
|
1664
|
+
const { weaverseApiBase, projectId } = this.configs;
|
|
1617
1665
|
const entries = [];
|
|
1618
1666
|
const MAX_PAGES = 100;
|
|
1619
1667
|
let cursor = null;
|
|
@@ -1629,7 +1677,7 @@ var WeaverseClient = class {
|
|
|
1629
1677
|
params.set("cursor", cursor);
|
|
1630
1678
|
}
|
|
1631
1679
|
const qs = params.toString();
|
|
1632
|
-
const url = `${
|
|
1680
|
+
const url = `${weaverseApiBase}/api/public/v1/projects/${projectId}/custom-pages${qs ? `?${qs}` : ""}`;
|
|
1633
1681
|
try {
|
|
1634
1682
|
const result = await this.fetchWithCache(url, { cacheTarget: "custom-pages" });
|
|
1635
1683
|
entries.push(...result.data || []);
|