@weaverse/hydrogen 5.10.1 → 5.11.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.js +33 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ export { isBrowser, isIframe, useChildInstances, useItemInstance, useParentInsta
|
|
|
4
4
|
import { createSchema, isValidSchema } from '@weaverse/schema';
|
|
5
5
|
export * from '@weaverse/schema';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
|
-
import { createContext, memo, useMemo, Suspense, useEffect, useContext } from 'react';
|
|
7
|
+
import { createContext, memo, useMemo, Suspense, useEffect, useContext, useRef } from 'react';
|
|
8
8
|
import { useMatches, Await, useRevalidator, useNavigation, useLocation, useNavigate, useRouteLoaderData } from 'react-router';
|
|
9
9
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
10
10
|
|
|
@@ -48,12 +48,12 @@ function getNestedKey(obj, path, fallback) {
|
|
|
48
48
|
return fallback;
|
|
49
49
|
}
|
|
50
50
|
function interpolate(template, variables) {
|
|
51
|
-
if (!variables
|
|
51
|
+
if (!variables) {
|
|
52
52
|
return template;
|
|
53
53
|
}
|
|
54
54
|
return template.replace(/\{\{(\w+)\}\}/g, (match, key) => {
|
|
55
55
|
const value = variables[key];
|
|
56
|
-
return value
|
|
56
|
+
return value === void 0 ? match : String(value);
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
var ThemeTextContext = createContext(null);
|
|
@@ -408,7 +408,6 @@ var ThemeSettingsStore = class {
|
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
};
|
|
411
|
-
// Method to properly clean up the store
|
|
412
411
|
destroy = () => {
|
|
413
412
|
if (this.isDestroyed) {
|
|
414
413
|
return;
|
|
@@ -420,12 +419,37 @@ var ThemeSettingsStore = class {
|
|
|
420
419
|
}
|
|
421
420
|
};
|
|
422
421
|
};
|
|
422
|
+
var ThemeSettingsStoreContext = createContext(null);
|
|
423
|
+
ThemeSettingsStoreContext.displayName = "ThemeSettingsStoreContext";
|
|
424
|
+
function useCreateThemeSettingsStore() {
|
|
425
|
+
const data = useRouteLoaderData("root");
|
|
426
|
+
const storeRef = useRef(null);
|
|
427
|
+
if (!storeRef.current) {
|
|
428
|
+
storeRef.current = new ThemeSettingsStore(data?.weaverseTheme);
|
|
429
|
+
}
|
|
430
|
+
const theme = data?.weaverseTheme?.theme;
|
|
431
|
+
useEffect(() => {
|
|
432
|
+
if (storeRef.current && theme) {
|
|
433
|
+
storeRef.current.updateThemeSettings(theme);
|
|
434
|
+
}
|
|
435
|
+
}, [theme]);
|
|
436
|
+
return storeRef.current;
|
|
437
|
+
}
|
|
423
438
|
function useThemeSettingsStore() {
|
|
439
|
+
const fromContext = useContext(ThemeSettingsStoreContext);
|
|
424
440
|
const data = useRouteLoaderData("root");
|
|
425
|
-
|
|
426
|
-
|
|
441
|
+
const fallbackRef = useRef(null);
|
|
442
|
+
if (!(fallbackRef.current || fromContext)) {
|
|
443
|
+
fallbackRef.current = new ThemeSettingsStore(data?.weaverseTheme);
|
|
427
444
|
}
|
|
428
|
-
|
|
445
|
+
const store = fromContext ?? fallbackRef.current;
|
|
446
|
+
const theme = data?.weaverseTheme?.theme;
|
|
447
|
+
useEffect(() => {
|
|
448
|
+
if (!fromContext && theme) {
|
|
449
|
+
store.updateThemeSettings(theme);
|
|
450
|
+
}
|
|
451
|
+
}, [fromContext, store, theme]);
|
|
452
|
+
return store;
|
|
429
453
|
}
|
|
430
454
|
|
|
431
455
|
// src/utils/use-studio.ts
|
|
@@ -617,14 +641,11 @@ var WeaverseHydrogenRoot = memo(
|
|
|
617
641
|
);
|
|
618
642
|
}
|
|
619
643
|
);
|
|
620
|
-
var ThemeSettingsProvider = createContext(null);
|
|
621
|
-
ThemeSettingsProvider.displayName = "WeaverseThemeSettingsProvider";
|
|
622
644
|
function withWeaverse(Component, options) {
|
|
623
645
|
return (props) => {
|
|
624
|
-
const themeSettingsStore =
|
|
625
|
-
const { settings } = themeSettingsStore;
|
|
646
|
+
const themeSettingsStore = useCreateThemeSettingsStore();
|
|
626
647
|
const themeTextData = useThemeTextData();
|
|
627
|
-
return /* @__PURE__ */ jsx(
|
|
648
|
+
return /* @__PURE__ */ jsx(ThemeSettingsStoreContext.Provider, { value: themeSettingsStore, children: /* @__PURE__ */ jsx(
|
|
628
649
|
ThemeTextProvider,
|
|
629
650
|
{
|
|
630
651
|
merchantOverrides: themeTextData.merchantOverrides,
|
|
@@ -1076,7 +1097,7 @@ var WeaverseClient = class {
|
|
|
1076
1097
|
type: typeof result,
|
|
1077
1098
|
isString: typeof result === "string",
|
|
1078
1099
|
length: typeof result === "string" ? result.length : "N/A",
|
|
1079
|
-
preview: typeof result === "string" ? `${result.
|
|
1100
|
+
preview: typeof result === "string" ? `${result.slice(0, 50)}...` : String(result)
|
|
1080
1101
|
}
|
|
1081
1102
|
);
|
|
1082
1103
|
result = { theme: defaultThemeSettings };
|