@weaverse/hydrogen 5.12.1 → 5.13.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 +31 -3
- package/dist/index.d.ts +31 -3
- package/dist/index.js +82 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { createSchema, isValidSchema } from '@weaverse/schema';
|
|
|
5
5
|
export * from '@weaverse/schema';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
7
|
import { createContext, memo, useMemo, Suspense, useEffect, useContext, useRef } from 'react';
|
|
8
|
-
import { useMatches, Await, useRevalidator, useNavigation, useLocation, useNavigate, useRouteLoaderData } from 'react-router';
|
|
8
|
+
import { useMatches, useLoaderData, Await, useRevalidator, useNavigation, useLocation, useNavigate, useRouteLoaderData } from 'react-router';
|
|
9
9
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
10
10
|
|
|
11
11
|
// src/index.ts
|
|
@@ -417,6 +417,29 @@ var ThemeTextStore = class {
|
|
|
417
417
|
}
|
|
418
418
|
};
|
|
419
419
|
};
|
|
420
|
+
|
|
421
|
+
// src/utils/pick-weaverse-data.ts
|
|
422
|
+
function pickWeaverseData(dataProp, ownLoaderData, matches) {
|
|
423
|
+
if (dataProp !== void 0) {
|
|
424
|
+
return dataProp;
|
|
425
|
+
}
|
|
426
|
+
if (hasWeaverseData(ownLoaderData)) {
|
|
427
|
+
return ownLoaderData.weaverseData;
|
|
428
|
+
}
|
|
429
|
+
for (let i = matches.length - 1; i >= 0; i--) {
|
|
430
|
+
const loaderData = matches[i].loaderData;
|
|
431
|
+
if (hasWeaverseData(loaderData)) {
|
|
432
|
+
return loaderData.weaverseData;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
function hasWeaverseData(value) {
|
|
438
|
+
if (typeof value !== "object" || value === null || !("weaverseData" in value)) {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
return value.weaverseData !== void 0;
|
|
442
|
+
}
|
|
420
443
|
var ThemeSettingsStore = class {
|
|
421
444
|
settings = {};
|
|
422
445
|
schema;
|
|
@@ -709,7 +732,7 @@ var WeaverseHydrogen = class extends Weaverse {
|
|
|
709
732
|
const entries = [];
|
|
710
733
|
const languageId = this.translationLanguageId;
|
|
711
734
|
if (!(this.translationLocale && languageId)) {
|
|
712
|
-
return
|
|
735
|
+
return;
|
|
713
736
|
}
|
|
714
737
|
for (const [itemId, fields] of Object.entries(this.translationMap)) {
|
|
715
738
|
for (const [key, entry] of Object.entries(fields)) {
|
|
@@ -722,7 +745,7 @@ var WeaverseHydrogen = class extends Weaverse {
|
|
|
722
745
|
}
|
|
723
746
|
}
|
|
724
747
|
if (entries.length === 0) {
|
|
725
|
-
return
|
|
748
|
+
return;
|
|
726
749
|
}
|
|
727
750
|
return { languageId, entries };
|
|
728
751
|
};
|
|
@@ -786,20 +809,19 @@ function registerComponent(element) {
|
|
|
786
809
|
var WeaverseHydrogenRoot = memo(
|
|
787
810
|
({
|
|
788
811
|
components,
|
|
812
|
+
data: dataProp,
|
|
789
813
|
errorComponent: ErrorComponent = ({ error }) => /* @__PURE__ */ jsx("div", { children: error instanceof Error ? error.message : "An unexpected error occurred" })
|
|
790
814
|
}) => {
|
|
791
815
|
const matches = useMatches();
|
|
792
816
|
const enhancedDataContext = createWeaverseDataContext(matches);
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
}
|
|
800
|
-
}
|
|
817
|
+
const ownLoaderData = useLoaderData();
|
|
818
|
+
const weaverseData = useMemo(
|
|
819
|
+
() => pickWeaverseData(dataProp, ownLoaderData, matches),
|
|
820
|
+
[dataProp, ownLoaderData, matches]
|
|
821
|
+
);
|
|
822
|
+
if (dataProp === null) {
|
|
801
823
|
return null;
|
|
802
|
-
}
|
|
824
|
+
}
|
|
803
825
|
if (weaverseData) {
|
|
804
826
|
if (weaverseData instanceof Promise) {
|
|
805
827
|
return /* @__PURE__ */ jsx(ErrorBoundary, { fallbackRender: ErrorComponent, children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(Await, { resolve: weaverseData, children: (resolvedData) => /* @__PURE__ */ jsx(
|
|
@@ -1355,7 +1377,7 @@ var WeaverseClient = class {
|
|
|
1355
1377
|
const { projectId, weaverseHost } = this.configs;
|
|
1356
1378
|
const i18n = this.storefront.i18n;
|
|
1357
1379
|
if (!(projectId && weaverseHost)) {
|
|
1358
|
-
return
|
|
1380
|
+
return;
|
|
1359
1381
|
}
|
|
1360
1382
|
const language = (i18n?.language || "en").toLowerCase();
|
|
1361
1383
|
const country = (i18n?.country || "us").toLowerCase();
|
|
@@ -1374,13 +1396,13 @@ var WeaverseClient = class {
|
|
|
1374
1396
|
if (typeof overrides === "object" && overrides !== null) {
|
|
1375
1397
|
return overrides;
|
|
1376
1398
|
}
|
|
1377
|
-
return
|
|
1399
|
+
return;
|
|
1378
1400
|
} catch (error) {
|
|
1379
1401
|
console.warn(
|
|
1380
1402
|
"Unable to load merchant overrides, using theme defaults:",
|
|
1381
1403
|
this.extractErrorMessage(error)
|
|
1382
1404
|
);
|
|
1383
|
-
return
|
|
1405
|
+
return;
|
|
1384
1406
|
}
|
|
1385
1407
|
};
|
|
1386
1408
|
/**
|
|
@@ -1405,6 +1427,49 @@ var WeaverseClient = class {
|
|
|
1405
1427
|
]
|
|
1406
1428
|
};
|
|
1407
1429
|
};
|
|
1430
|
+
/**
|
|
1431
|
+
* Fetch all published custom pages for sitemap generation.
|
|
1432
|
+
* Paginates automatically, never throws, returns accumulated results on partial failure.
|
|
1433
|
+
*/
|
|
1434
|
+
async fetchCustomPages(opts) {
|
|
1435
|
+
const { weaverseHost, projectId } = this.configs;
|
|
1436
|
+
const entries = [];
|
|
1437
|
+
const MAX_PAGES = 100;
|
|
1438
|
+
let cursor = null;
|
|
1439
|
+
for (let i = 0; i < MAX_PAGES; i++) {
|
|
1440
|
+
const params = new URLSearchParams();
|
|
1441
|
+
if (opts?.locale) {
|
|
1442
|
+
params.set("locale", opts.locale);
|
|
1443
|
+
}
|
|
1444
|
+
if (opts?.limit) {
|
|
1445
|
+
params.set("limit", String(opts.limit));
|
|
1446
|
+
}
|
|
1447
|
+
if (cursor) {
|
|
1448
|
+
params.set("cursor", cursor);
|
|
1449
|
+
}
|
|
1450
|
+
const qs = params.toString();
|
|
1451
|
+
const url = `${weaverseHost}/api/public/v1/projects/${projectId}/custom-pages${qs ? `?${qs}` : ""}`;
|
|
1452
|
+
try {
|
|
1453
|
+
const result = await this.fetchWithCache(url);
|
|
1454
|
+
entries.push(...result.data || []);
|
|
1455
|
+
if (!result.nextCursor) {
|
|
1456
|
+
return entries;
|
|
1457
|
+
}
|
|
1458
|
+
cursor = result.nextCursor;
|
|
1459
|
+
} catch (err) {
|
|
1460
|
+
const status = err?.status;
|
|
1461
|
+
const msg = err?.message || String(err);
|
|
1462
|
+
console.warn(
|
|
1463
|
+
entries.length === 0 ? `[Weaverse] Failed to fetch custom pages: ${msg}${status ? ` (HTTP ${status})` : ""}` : `[Weaverse] Custom pages pagination interrupted: ${msg}`
|
|
1464
|
+
);
|
|
1465
|
+
return entries;
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
console.warn(
|
|
1469
|
+
"[Weaverse] Custom pages pagination cap reached (100 iterations)"
|
|
1470
|
+
);
|
|
1471
|
+
return entries;
|
|
1472
|
+
}
|
|
1408
1473
|
/**
|
|
1409
1474
|
* Load page data from Weaverse API with optional route-level project override.
|
|
1410
1475
|
* Fetches page content, executes component loaders, and handles empty items fallback.
|
|
@@ -1516,7 +1581,9 @@ var WeaverseClient = class {
|
|
|
1516
1581
|
};
|
|
1517
1582
|
}
|
|
1518
1583
|
if (!page) {
|
|
1519
|
-
page = this.generateFallbackPage(
|
|
1584
|
+
page = this.generateFallbackPage(
|
|
1585
|
+
'<div style="text-align: center;">Please add new section to start.</div>'
|
|
1586
|
+
);
|
|
1520
1587
|
}
|
|
1521
1588
|
if (page?.items?.length === 0) {
|
|
1522
1589
|
page.items.push({
|