@weaverse/hydrogen 5.13.0 → 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 +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +39 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -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
|
/**
|
|
@@ -1559,7 +1581,9 @@ var WeaverseClient = class {
|
|
|
1559
1581
|
};
|
|
1560
1582
|
}
|
|
1561
1583
|
if (!page) {
|
|
1562
|
-
page = this.generateFallbackPage(
|
|
1584
|
+
page = this.generateFallbackPage(
|
|
1585
|
+
'<div style="text-align: center;">Please add new section to start.</div>'
|
|
1586
|
+
);
|
|
1563
1587
|
}
|
|
1564
1588
|
if (page?.items?.length === 0) {
|
|
1565
1589
|
page.items.push({
|