@weaverse/hydrogen 5.16.3 → 5.17.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 +69 -19
- package/dist/index.d.ts +69 -19
- package/dist/index.js +75 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -65
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -15,14 +15,15 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
15
15
|
/**
|
|
16
16
|
* Minimal mutable store for design-mode static text overrides.
|
|
17
17
|
*
|
|
18
|
-
* useSyncExternalStore-compatible. Passed into
|
|
18
|
+
* useSyncExternalStore-compatible. Passed into TranslationProvider which
|
|
19
19
|
* subscribes internally and merges overrides into merchantOverrides.
|
|
20
|
-
* The studio bridge calls updateOverrides() via weaverse.internal.
|
|
20
|
+
* The studio bridge calls updateOverrides() via weaverse.internal.translationStore
|
|
21
|
+
* (also exposed as the deprecated weaverse.internal.themeTextStore alias).
|
|
21
22
|
*
|
|
22
23
|
* Shape: flat Record<string, string> — dot-notation keys map to values
|
|
23
24
|
* (e.g. "cart.title" → "Shopping Cart").
|
|
24
25
|
*/
|
|
25
|
-
declare class
|
|
26
|
+
declare class TranslationStore {
|
|
26
27
|
overrides: Record<string, string>;
|
|
27
28
|
private listeners;
|
|
28
29
|
setOverrides: (overrides: Record<string, string>) => void;
|
|
@@ -32,6 +33,16 @@ declare class ThemeTextStore {
|
|
|
32
33
|
subscribe: (callback: () => void) => () => void;
|
|
33
34
|
private emit;
|
|
34
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use {@link TranslationStore} instead. Kept as a backward-compatible
|
|
38
|
+
* alias and will remain exported for existing integrations.
|
|
39
|
+
*/
|
|
40
|
+
declare const ThemeTextStore: typeof TranslationStore;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use {@link TranslationStore} instead. Kept as a backward-compatible
|
|
43
|
+
* alias and will remain exported for existing integrations.
|
|
44
|
+
*/
|
|
45
|
+
type ThemeTextStore = TranslationStore;
|
|
35
46
|
|
|
36
47
|
type WeaverseThemeData = {
|
|
37
48
|
theme: HydrogenThemeSettings;
|
|
@@ -74,12 +85,12 @@ declare function interpolate(template: string, variables?: Record<string, string
|
|
|
74
85
|
* Signature for a translation function.
|
|
75
86
|
*/
|
|
76
87
|
type TranslateFunction = (key: string, variables?: Record<string, string | number>) => string;
|
|
77
|
-
type
|
|
88
|
+
type TranslationValue = {
|
|
78
89
|
/**
|
|
79
90
|
* Translate a key with optional variable interpolation.
|
|
80
91
|
*
|
|
81
92
|
* Priority chain (highest wins):
|
|
82
|
-
* 1. External `t` (passed into `withWeaverse` / `
|
|
93
|
+
* 1. External `t` (passed into `withWeaverse` / `TranslationProvider`)
|
|
83
94
|
* 2. `merchantOverrides` (DB overrides for the current locale + design overrides)
|
|
84
95
|
* 3. `staticContent` (theme default JSON)
|
|
85
96
|
* 4. The key itself (fallback)
|
|
@@ -90,11 +101,16 @@ type ThemeTextValue = {
|
|
|
90
101
|
*/
|
|
91
102
|
t: TranslateFunction;
|
|
92
103
|
/** Exposed for useStudio to attach to weaverse.internal. Null in production. */
|
|
93
|
-
|
|
104
|
+
translationStore: TranslationStore | null;
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Use {@link TranslationValue.translationStore} instead. Kept as a
|
|
107
|
+
* backward-compatible alias pointing at the same store instance.
|
|
108
|
+
*/
|
|
109
|
+
themeTextStore: TranslationStore | null;
|
|
94
110
|
/** Active-locale translated keys loaded from the storefront API. */
|
|
95
111
|
merchantOverrides: Record<string, unknown> | null;
|
|
96
112
|
};
|
|
97
|
-
type
|
|
113
|
+
type TranslationProviderProps = {
|
|
98
114
|
staticContent: Record<string, unknown>;
|
|
99
115
|
merchantOverrides?: Record<string, unknown>;
|
|
100
116
|
/**
|
|
@@ -105,7 +121,13 @@ type ThemeTextProviderProps = {
|
|
|
105
121
|
*/
|
|
106
122
|
t?: TranslateFunction;
|
|
107
123
|
/** Optional store for live design-mode text overrides from the builder. */
|
|
108
|
-
|
|
124
|
+
translationStore?: TranslationStore | null;
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated Use {@link TranslationProviderProps.translationStore} instead.
|
|
127
|
+
* Still accepted for backward compatibility; ignored when `translationStore`
|
|
128
|
+
* is also provided.
|
|
129
|
+
*/
|
|
130
|
+
themeTextStore?: TranslationStore | null;
|
|
109
131
|
children: ReactNode;
|
|
110
132
|
};
|
|
111
133
|
/**
|
|
@@ -113,23 +135,40 @@ type ThemeTextProviderProps = {
|
|
|
113
135
|
*
|
|
114
136
|
* - `staticContent` – the theme's default locale JSON (from themeSchema.i18n)
|
|
115
137
|
* - `merchantOverrides` – locale-specific overrides fetched from the API
|
|
116
|
-
* - `
|
|
138
|
+
* - `translationStore` – optional store for live design-mode text overrides
|
|
139
|
+
* (the deprecated `themeTextStore` prop is accepted as a fallback)
|
|
117
140
|
*/
|
|
118
|
-
declare function
|
|
141
|
+
declare function TranslationProvider({ staticContent, merchantOverrides, t: externalT, translationStore, themeTextStore, children, }: TranslationProviderProps): react_jsx_runtime.JSX.Element;
|
|
119
142
|
/**
|
|
120
|
-
* Hook to access the
|
|
143
|
+
* Hook to access the translation `t()` function.
|
|
121
144
|
*
|
|
122
|
-
* Must be used inside a component wrapped by `withWeaverse` or `
|
|
145
|
+
* Must be used inside a component wrapped by `withWeaverse` or `TranslationProvider`.
|
|
123
146
|
*
|
|
124
147
|
* @example
|
|
125
148
|
* ```tsx
|
|
126
149
|
* function CartTitle() {
|
|
127
|
-
* const { t } =
|
|
150
|
+
* const { t } = useTranslation()
|
|
128
151
|
* return <h2>{t('cart.title')}</h2>
|
|
129
152
|
* }
|
|
130
153
|
* ```
|
|
131
154
|
*/
|
|
132
|
-
declare function
|
|
155
|
+
declare function useTranslation(): TranslationValue;
|
|
156
|
+
/**
|
|
157
|
+
* @deprecated Use {@link TranslationProvider} instead.
|
|
158
|
+
*/
|
|
159
|
+
declare const ThemeTextProvider: typeof TranslationProvider;
|
|
160
|
+
/**
|
|
161
|
+
* @deprecated Use {@link useTranslation} instead.
|
|
162
|
+
*/
|
|
163
|
+
declare const useThemeText: typeof useTranslation;
|
|
164
|
+
/**
|
|
165
|
+
* @deprecated Use {@link TranslationValue} instead.
|
|
166
|
+
*/
|
|
167
|
+
type ThemeTextValue = TranslationValue;
|
|
168
|
+
/**
|
|
169
|
+
* @deprecated Use {@link TranslationProviderProps} instead.
|
|
170
|
+
*/
|
|
171
|
+
type ThemeTextProviderProps = TranslationProviderProps;
|
|
133
172
|
|
|
134
173
|
type WeaverseDataValue = WeaverseLoaderData | Promise<WeaverseLoaderData> | null;
|
|
135
174
|
|
|
@@ -251,7 +290,7 @@ type WithWeaverseOptions = {
|
|
|
251
290
|
/**
|
|
252
291
|
* Optional external translation function (e.g. from Shopify i18n).
|
|
253
292
|
* When provided it becomes the **highest-priority** source
|
|
254
|
-
* in the `t()` resolution chain exposed by `
|
|
293
|
+
* in the `t()` resolution chain exposed by `useTranslation()`.
|
|
255
294
|
*/
|
|
256
295
|
t?: TranslateFunction;
|
|
257
296
|
};
|
|
@@ -468,7 +507,7 @@ declare class WeaverseClient {
|
|
|
468
507
|
* Fetches page content, executes component loaders, and handles empty items fallback.
|
|
469
508
|
*
|
|
470
509
|
* @param params - Optional page loading parameters
|
|
471
|
-
* @param params.type - Page type (
|
|
510
|
+
* @param params.type - Page type (INDEX, PAGE, PRODUCT, COLLECTION, etc.)
|
|
472
511
|
* @param params.handle - Page handle for dynamic routes
|
|
473
512
|
* @param params.locale - Locale override
|
|
474
513
|
* @param params.projectId - Route-level project ID override (for multi-project)
|
|
@@ -481,7 +520,7 @@ declare class WeaverseClient {
|
|
|
481
520
|
* const data = await weaverse.loadPage()
|
|
482
521
|
*
|
|
483
522
|
* // With page type
|
|
484
|
-
* const data = await weaverse.loadPage({ type: '
|
|
523
|
+
* const data = await weaverse.loadPage({ type: 'INDEX' })
|
|
485
524
|
*
|
|
486
525
|
* // Route-level project override
|
|
487
526
|
* const data = await weaverse.loadPage({
|
|
@@ -549,7 +588,9 @@ type WeaverseInternal = {
|
|
|
549
588
|
navigate: NavigateFunction;
|
|
550
589
|
revalidate: () => void;
|
|
551
590
|
themeSettingsStore: ThemeSettingsStore;
|
|
552
|
-
|
|
591
|
+
translationStore?: TranslationStore | null;
|
|
592
|
+
/** @deprecated Use translationStore instead. */
|
|
593
|
+
themeTextStore?: TranslationStore | null;
|
|
553
594
|
merchantOverrides?: Record<string, unknown> | null;
|
|
554
595
|
};
|
|
555
596
|
/**
|
|
@@ -913,6 +954,15 @@ type CreateHydrogenSchemaOptions = {
|
|
|
913
954
|
pages?: PageType[];
|
|
914
955
|
groups?: ('*' | 'header' | 'footer' | 'body')[];
|
|
915
956
|
};
|
|
957
|
+
enabled?: boolean | ((context: {
|
|
958
|
+
page: {
|
|
959
|
+
id: string;
|
|
960
|
+
type: PageType;
|
|
961
|
+
handle: string;
|
|
962
|
+
locale: string;
|
|
963
|
+
};
|
|
964
|
+
group: 'body' | 'header' | 'footer';
|
|
965
|
+
}) => boolean);
|
|
916
966
|
presets?: {
|
|
917
967
|
children?: ComponentPresets[];
|
|
918
968
|
[key: string]: any;
|
|
@@ -1216,4 +1266,4 @@ declare const IMAGES_PLACEHOLDERS: {
|
|
|
1216
1266
|
product_18: string;
|
|
1217
1267
|
};
|
|
1218
1268
|
|
|
1219
|
-
export { type CacheResponseValidator, type ComponentDataValue, type ComponentLoaderArgs, type CreateHydrogenSchemaOptions, type CustomPageEntry, type DirectFetchResponse, type FetchProjectPayload, type FetchProjectRequestBody, type HydrogenComponent, type HydrogenComponentData, type HydrogenComponentPresets, type HydrogenComponentProps, type HydrogenComponentSchema, type HydrogenElement, type HydrogenPageAssignment, type HydrogenPageData, type HydrogenProjectType, type HydrogenSchemaValidationResult, type HydrogenThemeSchema, type HydrogenThemeSettings, IMAGES_PLACEHOLDERS, type LoadPageParams, type ProjectIdValidationResult, type ProjectIdValue, type PublicEnv, type RouteLoaderArgs, type ThemeSettingsResponse, ThemeTextProvider, type ThemeTextProviderProps, ThemeTextStore, type ThemeTextValue, type TranslateFunction, type TranslationChanges, type TranslationEntry, type TranslationItemEntry, type TranslationMap, type TranslationMapEntry, type WeaverseArticle, type WeaverseBlog, WeaverseClient, type WeaverseClientArgs, type WeaverseCollection, type WeaverseDataContext, WeaverseError, WeaverseHydrogen, WeaverseHydrogenItem, type WeaverseHydrogenParams, WeaverseHydrogenRoot, type WeaverseI18n, type WeaverseInternal, type WeaverseLoaderData, type WeaverseLoaderRequestInfo, type WeaverseMetaObject, type WeaverseProduct, type WeaverseProjectConfigs, type WeaverseStudioQueries, type WithCacheFetchResponse, type WithWeaverseOptions, createWeaverseDataContext, defaultComponents, formatMetaDescriptors, generateDataFromSchema, getNestedKey, getPreviewData, getRequestQueries, getSelectedProductOptions, getWeaverseConfigs, getWeaverseSeoMeta, hasError, hasWeaverseStudio, interpolate, isFetchProjectPayload, isProjectIdFunction, isThemeSettingsResponse, isValidHydrogenSchema, isWithCacheFetchResponse, registerComponent, useThemeSettings, useThemeText, useWeaverseDataContext, withWeaverse };
|
|
1269
|
+
export { type CacheResponseValidator, type ComponentDataValue, type ComponentLoaderArgs, type CreateHydrogenSchemaOptions, type CustomPageEntry, type DirectFetchResponse, type FetchProjectPayload, type FetchProjectRequestBody, type HydrogenComponent, type HydrogenComponentData, type HydrogenComponentPresets, type HydrogenComponentProps, type HydrogenComponentSchema, type HydrogenElement, type HydrogenPageAssignment, type HydrogenPageData, type HydrogenProjectType, type HydrogenSchemaValidationResult, type HydrogenThemeSchema, type HydrogenThemeSettings, IMAGES_PLACEHOLDERS, type LoadPageParams, type ProjectIdValidationResult, type ProjectIdValue, type PublicEnv, type RouteLoaderArgs, type ThemeSettingsResponse, ThemeTextProvider, type ThemeTextProviderProps, ThemeTextStore, type ThemeTextValue, type TranslateFunction, type TranslationChanges, type TranslationEntry, type TranslationItemEntry, type TranslationMap, type TranslationMapEntry, TranslationProvider, type TranslationProviderProps, TranslationStore, type TranslationValue, type WeaverseArticle, type WeaverseBlog, WeaverseClient, type WeaverseClientArgs, type WeaverseCollection, type WeaverseDataContext, WeaverseError, WeaverseHydrogen, WeaverseHydrogenItem, type WeaverseHydrogenParams, WeaverseHydrogenRoot, type WeaverseI18n, type WeaverseInternal, type WeaverseLoaderData, type WeaverseLoaderRequestInfo, type WeaverseMetaObject, type WeaverseProduct, type WeaverseProjectConfigs, type WeaverseStudioQueries, type WithCacheFetchResponse, type WithWeaverseOptions, createWeaverseDataContext, defaultComponents, formatMetaDescriptors, generateDataFromSchema, getNestedKey, getPreviewData, getRequestQueries, getSelectedProductOptions, getWeaverseConfigs, getWeaverseSeoMeta, hasError, hasWeaverseStudio, interpolate, isFetchProjectPayload, isProjectIdFunction, isThemeSettingsResponse, isValidHydrogenSchema, isWithCacheFetchResponse, registerComponent, useThemeSettings, useThemeText, useTranslation, useWeaverseDataContext, withWeaverse };
|
package/dist/index.d.ts
CHANGED
|
@@ -15,14 +15,15 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
15
15
|
/**
|
|
16
16
|
* Minimal mutable store for design-mode static text overrides.
|
|
17
17
|
*
|
|
18
|
-
* useSyncExternalStore-compatible. Passed into
|
|
18
|
+
* useSyncExternalStore-compatible. Passed into TranslationProvider which
|
|
19
19
|
* subscribes internally and merges overrides into merchantOverrides.
|
|
20
|
-
* The studio bridge calls updateOverrides() via weaverse.internal.
|
|
20
|
+
* The studio bridge calls updateOverrides() via weaverse.internal.translationStore
|
|
21
|
+
* (also exposed as the deprecated weaverse.internal.themeTextStore alias).
|
|
21
22
|
*
|
|
22
23
|
* Shape: flat Record<string, string> — dot-notation keys map to values
|
|
23
24
|
* (e.g. "cart.title" → "Shopping Cart").
|
|
24
25
|
*/
|
|
25
|
-
declare class
|
|
26
|
+
declare class TranslationStore {
|
|
26
27
|
overrides: Record<string, string>;
|
|
27
28
|
private listeners;
|
|
28
29
|
setOverrides: (overrides: Record<string, string>) => void;
|
|
@@ -32,6 +33,16 @@ declare class ThemeTextStore {
|
|
|
32
33
|
subscribe: (callback: () => void) => () => void;
|
|
33
34
|
private emit;
|
|
34
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use {@link TranslationStore} instead. Kept as a backward-compatible
|
|
38
|
+
* alias and will remain exported for existing integrations.
|
|
39
|
+
*/
|
|
40
|
+
declare const ThemeTextStore: typeof TranslationStore;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use {@link TranslationStore} instead. Kept as a backward-compatible
|
|
43
|
+
* alias and will remain exported for existing integrations.
|
|
44
|
+
*/
|
|
45
|
+
type ThemeTextStore = TranslationStore;
|
|
35
46
|
|
|
36
47
|
type WeaverseThemeData = {
|
|
37
48
|
theme: HydrogenThemeSettings;
|
|
@@ -74,12 +85,12 @@ declare function interpolate(template: string, variables?: Record<string, string
|
|
|
74
85
|
* Signature for a translation function.
|
|
75
86
|
*/
|
|
76
87
|
type TranslateFunction = (key: string, variables?: Record<string, string | number>) => string;
|
|
77
|
-
type
|
|
88
|
+
type TranslationValue = {
|
|
78
89
|
/**
|
|
79
90
|
* Translate a key with optional variable interpolation.
|
|
80
91
|
*
|
|
81
92
|
* Priority chain (highest wins):
|
|
82
|
-
* 1. External `t` (passed into `withWeaverse` / `
|
|
93
|
+
* 1. External `t` (passed into `withWeaverse` / `TranslationProvider`)
|
|
83
94
|
* 2. `merchantOverrides` (DB overrides for the current locale + design overrides)
|
|
84
95
|
* 3. `staticContent` (theme default JSON)
|
|
85
96
|
* 4. The key itself (fallback)
|
|
@@ -90,11 +101,16 @@ type ThemeTextValue = {
|
|
|
90
101
|
*/
|
|
91
102
|
t: TranslateFunction;
|
|
92
103
|
/** Exposed for useStudio to attach to weaverse.internal. Null in production. */
|
|
93
|
-
|
|
104
|
+
translationStore: TranslationStore | null;
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Use {@link TranslationValue.translationStore} instead. Kept as a
|
|
107
|
+
* backward-compatible alias pointing at the same store instance.
|
|
108
|
+
*/
|
|
109
|
+
themeTextStore: TranslationStore | null;
|
|
94
110
|
/** Active-locale translated keys loaded from the storefront API. */
|
|
95
111
|
merchantOverrides: Record<string, unknown> | null;
|
|
96
112
|
};
|
|
97
|
-
type
|
|
113
|
+
type TranslationProviderProps = {
|
|
98
114
|
staticContent: Record<string, unknown>;
|
|
99
115
|
merchantOverrides?: Record<string, unknown>;
|
|
100
116
|
/**
|
|
@@ -105,7 +121,13 @@ type ThemeTextProviderProps = {
|
|
|
105
121
|
*/
|
|
106
122
|
t?: TranslateFunction;
|
|
107
123
|
/** Optional store for live design-mode text overrides from the builder. */
|
|
108
|
-
|
|
124
|
+
translationStore?: TranslationStore | null;
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated Use {@link TranslationProviderProps.translationStore} instead.
|
|
127
|
+
* Still accepted for backward compatibility; ignored when `translationStore`
|
|
128
|
+
* is also provided.
|
|
129
|
+
*/
|
|
130
|
+
themeTextStore?: TranslationStore | null;
|
|
109
131
|
children: ReactNode;
|
|
110
132
|
};
|
|
111
133
|
/**
|
|
@@ -113,23 +135,40 @@ type ThemeTextProviderProps = {
|
|
|
113
135
|
*
|
|
114
136
|
* - `staticContent` – the theme's default locale JSON (from themeSchema.i18n)
|
|
115
137
|
* - `merchantOverrides` – locale-specific overrides fetched from the API
|
|
116
|
-
* - `
|
|
138
|
+
* - `translationStore` – optional store for live design-mode text overrides
|
|
139
|
+
* (the deprecated `themeTextStore` prop is accepted as a fallback)
|
|
117
140
|
*/
|
|
118
|
-
declare function
|
|
141
|
+
declare function TranslationProvider({ staticContent, merchantOverrides, t: externalT, translationStore, themeTextStore, children, }: TranslationProviderProps): react_jsx_runtime.JSX.Element;
|
|
119
142
|
/**
|
|
120
|
-
* Hook to access the
|
|
143
|
+
* Hook to access the translation `t()` function.
|
|
121
144
|
*
|
|
122
|
-
* Must be used inside a component wrapped by `withWeaverse` or `
|
|
145
|
+
* Must be used inside a component wrapped by `withWeaverse` or `TranslationProvider`.
|
|
123
146
|
*
|
|
124
147
|
* @example
|
|
125
148
|
* ```tsx
|
|
126
149
|
* function CartTitle() {
|
|
127
|
-
* const { t } =
|
|
150
|
+
* const { t } = useTranslation()
|
|
128
151
|
* return <h2>{t('cart.title')}</h2>
|
|
129
152
|
* }
|
|
130
153
|
* ```
|
|
131
154
|
*/
|
|
132
|
-
declare function
|
|
155
|
+
declare function useTranslation(): TranslationValue;
|
|
156
|
+
/**
|
|
157
|
+
* @deprecated Use {@link TranslationProvider} instead.
|
|
158
|
+
*/
|
|
159
|
+
declare const ThemeTextProvider: typeof TranslationProvider;
|
|
160
|
+
/**
|
|
161
|
+
* @deprecated Use {@link useTranslation} instead.
|
|
162
|
+
*/
|
|
163
|
+
declare const useThemeText: typeof useTranslation;
|
|
164
|
+
/**
|
|
165
|
+
* @deprecated Use {@link TranslationValue} instead.
|
|
166
|
+
*/
|
|
167
|
+
type ThemeTextValue = TranslationValue;
|
|
168
|
+
/**
|
|
169
|
+
* @deprecated Use {@link TranslationProviderProps} instead.
|
|
170
|
+
*/
|
|
171
|
+
type ThemeTextProviderProps = TranslationProviderProps;
|
|
133
172
|
|
|
134
173
|
type WeaverseDataValue = WeaverseLoaderData | Promise<WeaverseLoaderData> | null;
|
|
135
174
|
|
|
@@ -251,7 +290,7 @@ type WithWeaverseOptions = {
|
|
|
251
290
|
/**
|
|
252
291
|
* Optional external translation function (e.g. from Shopify i18n).
|
|
253
292
|
* When provided it becomes the **highest-priority** source
|
|
254
|
-
* in the `t()` resolution chain exposed by `
|
|
293
|
+
* in the `t()` resolution chain exposed by `useTranslation()`.
|
|
255
294
|
*/
|
|
256
295
|
t?: TranslateFunction;
|
|
257
296
|
};
|
|
@@ -468,7 +507,7 @@ declare class WeaverseClient {
|
|
|
468
507
|
* Fetches page content, executes component loaders, and handles empty items fallback.
|
|
469
508
|
*
|
|
470
509
|
* @param params - Optional page loading parameters
|
|
471
|
-
* @param params.type - Page type (
|
|
510
|
+
* @param params.type - Page type (INDEX, PAGE, PRODUCT, COLLECTION, etc.)
|
|
472
511
|
* @param params.handle - Page handle for dynamic routes
|
|
473
512
|
* @param params.locale - Locale override
|
|
474
513
|
* @param params.projectId - Route-level project ID override (for multi-project)
|
|
@@ -481,7 +520,7 @@ declare class WeaverseClient {
|
|
|
481
520
|
* const data = await weaverse.loadPage()
|
|
482
521
|
*
|
|
483
522
|
* // With page type
|
|
484
|
-
* const data = await weaverse.loadPage({ type: '
|
|
523
|
+
* const data = await weaverse.loadPage({ type: 'INDEX' })
|
|
485
524
|
*
|
|
486
525
|
* // Route-level project override
|
|
487
526
|
* const data = await weaverse.loadPage({
|
|
@@ -549,7 +588,9 @@ type WeaverseInternal = {
|
|
|
549
588
|
navigate: NavigateFunction;
|
|
550
589
|
revalidate: () => void;
|
|
551
590
|
themeSettingsStore: ThemeSettingsStore;
|
|
552
|
-
|
|
591
|
+
translationStore?: TranslationStore | null;
|
|
592
|
+
/** @deprecated Use translationStore instead. */
|
|
593
|
+
themeTextStore?: TranslationStore | null;
|
|
553
594
|
merchantOverrides?: Record<string, unknown> | null;
|
|
554
595
|
};
|
|
555
596
|
/**
|
|
@@ -913,6 +954,15 @@ type CreateHydrogenSchemaOptions = {
|
|
|
913
954
|
pages?: PageType[];
|
|
914
955
|
groups?: ('*' | 'header' | 'footer' | 'body')[];
|
|
915
956
|
};
|
|
957
|
+
enabled?: boolean | ((context: {
|
|
958
|
+
page: {
|
|
959
|
+
id: string;
|
|
960
|
+
type: PageType;
|
|
961
|
+
handle: string;
|
|
962
|
+
locale: string;
|
|
963
|
+
};
|
|
964
|
+
group: 'body' | 'header' | 'footer';
|
|
965
|
+
}) => boolean);
|
|
916
966
|
presets?: {
|
|
917
967
|
children?: ComponentPresets[];
|
|
918
968
|
[key: string]: any;
|
|
@@ -1216,4 +1266,4 @@ declare const IMAGES_PLACEHOLDERS: {
|
|
|
1216
1266
|
product_18: string;
|
|
1217
1267
|
};
|
|
1218
1268
|
|
|
1219
|
-
export { type CacheResponseValidator, type ComponentDataValue, type ComponentLoaderArgs, type CreateHydrogenSchemaOptions, type CustomPageEntry, type DirectFetchResponse, type FetchProjectPayload, type FetchProjectRequestBody, type HydrogenComponent, type HydrogenComponentData, type HydrogenComponentPresets, type HydrogenComponentProps, type HydrogenComponentSchema, type HydrogenElement, type HydrogenPageAssignment, type HydrogenPageData, type HydrogenProjectType, type HydrogenSchemaValidationResult, type HydrogenThemeSchema, type HydrogenThemeSettings, IMAGES_PLACEHOLDERS, type LoadPageParams, type ProjectIdValidationResult, type ProjectIdValue, type PublicEnv, type RouteLoaderArgs, type ThemeSettingsResponse, ThemeTextProvider, type ThemeTextProviderProps, ThemeTextStore, type ThemeTextValue, type TranslateFunction, type TranslationChanges, type TranslationEntry, type TranslationItemEntry, type TranslationMap, type TranslationMapEntry, type WeaverseArticle, type WeaverseBlog, WeaverseClient, type WeaverseClientArgs, type WeaverseCollection, type WeaverseDataContext, WeaverseError, WeaverseHydrogen, WeaverseHydrogenItem, type WeaverseHydrogenParams, WeaverseHydrogenRoot, type WeaverseI18n, type WeaverseInternal, type WeaverseLoaderData, type WeaverseLoaderRequestInfo, type WeaverseMetaObject, type WeaverseProduct, type WeaverseProjectConfigs, type WeaverseStudioQueries, type WithCacheFetchResponse, type WithWeaverseOptions, createWeaverseDataContext, defaultComponents, formatMetaDescriptors, generateDataFromSchema, getNestedKey, getPreviewData, getRequestQueries, getSelectedProductOptions, getWeaverseConfigs, getWeaverseSeoMeta, hasError, hasWeaverseStudio, interpolate, isFetchProjectPayload, isProjectIdFunction, isThemeSettingsResponse, isValidHydrogenSchema, isWithCacheFetchResponse, registerComponent, useThemeSettings, useThemeText, useWeaverseDataContext, withWeaverse };
|
|
1269
|
+
export { type CacheResponseValidator, type ComponentDataValue, type ComponentLoaderArgs, type CreateHydrogenSchemaOptions, type CustomPageEntry, type DirectFetchResponse, type FetchProjectPayload, type FetchProjectRequestBody, type HydrogenComponent, type HydrogenComponentData, type HydrogenComponentPresets, type HydrogenComponentProps, type HydrogenComponentSchema, type HydrogenElement, type HydrogenPageAssignment, type HydrogenPageData, type HydrogenProjectType, type HydrogenSchemaValidationResult, type HydrogenThemeSchema, type HydrogenThemeSettings, IMAGES_PLACEHOLDERS, type LoadPageParams, type ProjectIdValidationResult, type ProjectIdValue, type PublicEnv, type RouteLoaderArgs, type ThemeSettingsResponse, ThemeTextProvider, type ThemeTextProviderProps, ThemeTextStore, type ThemeTextValue, type TranslateFunction, type TranslationChanges, type TranslationEntry, type TranslationItemEntry, type TranslationMap, type TranslationMapEntry, TranslationProvider, type TranslationProviderProps, TranslationStore, type TranslationValue, type WeaverseArticle, type WeaverseBlog, WeaverseClient, type WeaverseClientArgs, type WeaverseCollection, type WeaverseDataContext, WeaverseError, WeaverseHydrogen, WeaverseHydrogenItem, type WeaverseHydrogenParams, WeaverseHydrogenRoot, type WeaverseI18n, type WeaverseInternal, type WeaverseLoaderData, type WeaverseLoaderRequestInfo, type WeaverseMetaObject, type WeaverseProduct, type WeaverseProjectConfigs, type WeaverseStudioQueries, type WithCacheFetchResponse, type WithWeaverseOptions, createWeaverseDataContext, defaultComponents, formatMetaDescriptors, generateDataFromSchema, getNestedKey, getPreviewData, getRequestQueries, getSelectedProductOptions, getWeaverseConfigs, getWeaverseSeoMeta, hasError, hasWeaverseStudio, interpolate, isFetchProjectPayload, isProjectIdFunction, isThemeSettingsResponse, isValidHydrogenSchema, isWithCacheFetchResponse, registerComponent, useThemeSettings, useThemeText, useTranslation, useWeaverseDataContext, withWeaverse };
|
package/dist/index.js
CHANGED
|
@@ -56,77 +56,70 @@ function interpolate(template, variables) {
|
|
|
56
56
|
return value === void 0 ? match : String(value);
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
function
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (!(k in current) || typeof current[k] !== "object") {
|
|
69
|
-
current[k] = {};
|
|
59
|
+
var TranslationContext = react$1.createContext(null);
|
|
60
|
+
TranslationContext.displayName = "WeaverseTranslationContext";
|
|
61
|
+
function createTranslate(sources) {
|
|
62
|
+
const { staticContent, merchantOverrides, designOverrides, externalT } = sources;
|
|
63
|
+
return (key, variables) => {
|
|
64
|
+
if (externalT) {
|
|
65
|
+
const external = externalT(key, variables);
|
|
66
|
+
if (external && external !== key) {
|
|
67
|
+
return external;
|
|
70
68
|
}
|
|
71
|
-
current = current[k];
|
|
72
69
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
const design = designOverrides && Object.hasOwn(designOverrides, key) ? designOverrides[key] : void 0;
|
|
71
|
+
const override = merchantOverrides ? getNestedKey(merchantOverrides, key) : void 0;
|
|
72
|
+
const staticValue = getNestedKey(staticContent, key);
|
|
73
|
+
const raw = design ?? override ?? staticValue ?? key;
|
|
74
|
+
return interpolate(raw, variables);
|
|
75
|
+
};
|
|
76
76
|
}
|
|
77
77
|
var EMPTY = {};
|
|
78
78
|
var NOOP_SUBSCRIBE = () => () => {
|
|
79
79
|
};
|
|
80
80
|
var NOOP_SNAPSHOT = () => EMPTY;
|
|
81
|
-
function
|
|
81
|
+
function TranslationProvider({
|
|
82
82
|
staticContent,
|
|
83
83
|
merchantOverrides,
|
|
84
84
|
t: externalT,
|
|
85
|
+
translationStore,
|
|
85
86
|
themeTextStore,
|
|
86
87
|
children
|
|
87
88
|
}) {
|
|
89
|
+
const store = translationStore ?? themeTextStore ?? null;
|
|
88
90
|
const designOverrides = react.useSafeExternalStore(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
store?.subscribe ?? NOOP_SUBSCRIBE,
|
|
92
|
+
store?.getSnapshot ?? NOOP_SNAPSHOT,
|
|
93
|
+
store?.getServerSnapshot ?? NOOP_SNAPSHOT
|
|
92
94
|
);
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const raw = override ?? staticValue ?? key;
|
|
105
|
-
return interpolate(raw, variables);
|
|
106
|
-
};
|
|
107
|
-
return {
|
|
108
|
-
t,
|
|
109
|
-
themeTextStore: themeTextStore ?? null,
|
|
95
|
+
const value = react$1.useMemo(
|
|
96
|
+
() => ({
|
|
97
|
+
t: createTranslate({
|
|
98
|
+
staticContent,
|
|
99
|
+
merchantOverrides,
|
|
100
|
+
designOverrides,
|
|
101
|
+
externalT
|
|
102
|
+
}),
|
|
103
|
+
translationStore: store,
|
|
104
|
+
// Deprecated alias — same instance, kept for backward compatibility.
|
|
105
|
+
themeTextStore: store,
|
|
110
106
|
merchantOverrides: merchantOverrides ?? null
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
mergedOverrides,
|
|
116
|
-
externalT,
|
|
117
|
-
themeTextStore
|
|
118
|
-
]);
|
|
119
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ThemeTextContext.Provider, { value, children });
|
|
107
|
+
}),
|
|
108
|
+
[staticContent, merchantOverrides, designOverrides, externalT, store]
|
|
109
|
+
);
|
|
110
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TranslationContext.Provider, { value, children });
|
|
120
111
|
}
|
|
121
|
-
function
|
|
122
|
-
const ctx = react$1.useContext(
|
|
112
|
+
function useTranslation() {
|
|
113
|
+
const ctx = react$1.useContext(TranslationContext);
|
|
123
114
|
if (!ctx) {
|
|
124
115
|
throw new Error(
|
|
125
|
-
"
|
|
116
|
+
"useTranslation must be used within <TranslationProvider>. Wrap your app with withWeaverse()."
|
|
126
117
|
);
|
|
127
118
|
}
|
|
128
119
|
return ctx;
|
|
129
120
|
}
|
|
121
|
+
var ThemeTextProvider = TranslationProvider;
|
|
122
|
+
var useThemeText = useTranslation;
|
|
130
123
|
function createFlatDataContext(matches) {
|
|
131
124
|
const context = {};
|
|
132
125
|
for (const match of matches) {
|
|
@@ -520,8 +513,8 @@ function getPreviewData(type, components, weaverseHost) {
|
|
|
520
513
|
};
|
|
521
514
|
}
|
|
522
515
|
|
|
523
|
-
// src/utils/
|
|
524
|
-
var
|
|
516
|
+
// src/utils/translation-store.ts
|
|
517
|
+
var TranslationStore = class {
|
|
525
518
|
overrides = {};
|
|
526
519
|
listeners = /* @__PURE__ */ new Set();
|
|
527
520
|
setOverrides = (overrides) => {
|
|
@@ -545,11 +538,12 @@ var ThemeTextStore = class {
|
|
|
545
538
|
try {
|
|
546
539
|
listener();
|
|
547
540
|
} catch (error) {
|
|
548
|
-
console.error("
|
|
541
|
+
console.error("TranslationStore: Listener error", error);
|
|
549
542
|
}
|
|
550
543
|
}
|
|
551
544
|
};
|
|
552
545
|
};
|
|
546
|
+
var ThemeTextStore = TranslationStore;
|
|
553
547
|
|
|
554
548
|
// src/utils/pick-weaverse-data.ts
|
|
555
549
|
function pickWeaverseData(dataProp, ownLoaderData, matches) {
|
|
@@ -639,11 +633,14 @@ function syncReusedInstance(weaverse, params) {
|
|
|
639
633
|
var currentNavigationKey = null;
|
|
640
634
|
var firedPageIds = /* @__PURE__ */ new Set();
|
|
641
635
|
var mountedInstances = 0;
|
|
642
|
-
function
|
|
636
|
+
function observeNavigation(navigationKey) {
|
|
643
637
|
if (navigationKey !== currentNavigationKey) {
|
|
644
638
|
currentNavigationKey = navigationKey;
|
|
645
639
|
firedPageIds.clear();
|
|
646
640
|
}
|
|
641
|
+
}
|
|
642
|
+
function shouldFirePixel(navigationKey, pageId) {
|
|
643
|
+
observeNavigation(navigationKey);
|
|
647
644
|
if (firedPageIds.has(pageId)) {
|
|
648
645
|
return false;
|
|
649
646
|
}
|
|
@@ -798,7 +795,7 @@ function useStudio(weaverse) {
|
|
|
798
795
|
let { pathname, search } = reactRouter.useLocation();
|
|
799
796
|
let navigate = reactRouter.useNavigate();
|
|
800
797
|
let themeSettingsStore = useThemeSettingsStore();
|
|
801
|
-
let { themeTextStore, merchantOverrides } =
|
|
798
|
+
let { translationStore, themeTextStore, merchantOverrides } = useTranslation();
|
|
802
799
|
let {
|
|
803
800
|
isDesignMode,
|
|
804
801
|
weaverseHost,
|
|
@@ -829,6 +826,8 @@ function useStudio(weaverse) {
|
|
|
829
826
|
revalidate,
|
|
830
827
|
merchantOverrides,
|
|
831
828
|
themeSettingsStore,
|
|
829
|
+
translationStore,
|
|
830
|
+
// Deprecated alias for existing Studio bridge integrations.
|
|
832
831
|
themeTextStore
|
|
833
832
|
};
|
|
834
833
|
react.loadScript(src).then(waitForStudio).then((studio) => studio?.init(weaverse)).catch(console.error);
|
|
@@ -839,6 +838,12 @@ function useStudio(weaverse) {
|
|
|
839
838
|
function usePixel(context) {
|
|
840
839
|
let { projectId, pageId, isDesignMode, weaverseHost } = context;
|
|
841
840
|
let { key: navigationKey } = reactRouter.useLocation();
|
|
841
|
+
react$1.useEffect(() => {
|
|
842
|
+
if (!(projectId && pageId) || isDesignMode) {
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
observeNavigation(navigationKey);
|
|
846
|
+
}, [navigationKey, projectId, pageId, isDesignMode]);
|
|
842
847
|
react$1.useEffect(() => {
|
|
843
848
|
if (!(projectId && pageId) || isDesignMode) {
|
|
844
849
|
return;
|
|
@@ -1126,18 +1131,18 @@ var WeaverseHydrogenRoot = react$1.memo(
|
|
|
1126
1131
|
function withWeaverse(Component, options) {
|
|
1127
1132
|
return (props) => {
|
|
1128
1133
|
const themeSettingsStore = useCreateThemeSettingsStore();
|
|
1129
|
-
const
|
|
1130
|
-
const
|
|
1131
|
-
if (!
|
|
1132
|
-
|
|
1134
|
+
const translationData = useTranslationData();
|
|
1135
|
+
const translationStoreRef = react$1.useRef(null);
|
|
1136
|
+
if (!translationStoreRef.current) {
|
|
1137
|
+
translationStoreRef.current = new TranslationStore();
|
|
1133
1138
|
}
|
|
1134
1139
|
return /* @__PURE__ */ jsxRuntime.jsx(ThemeSettingsStoreContext.Provider, { value: themeSettingsStore, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1135
|
-
|
|
1140
|
+
TranslationProvider,
|
|
1136
1141
|
{
|
|
1137
|
-
merchantOverrides:
|
|
1138
|
-
staticContent:
|
|
1142
|
+
merchantOverrides: translationData.merchantOverrides,
|
|
1143
|
+
staticContent: translationData.staticContent,
|
|
1139
1144
|
t: options?.t,
|
|
1140
|
-
|
|
1145
|
+
translationStore: translationStoreRef.current,
|
|
1141
1146
|
children: [
|
|
1142
1147
|
/* @__PURE__ */ jsxRuntime.jsx(StudioConnect, {}),
|
|
1143
1148
|
/* @__PURE__ */ jsxRuntime.jsx(Component, { ...props })
|
|
@@ -1146,7 +1151,7 @@ function withWeaverse(Component, options) {
|
|
|
1146
1151
|
) });
|
|
1147
1152
|
};
|
|
1148
1153
|
}
|
|
1149
|
-
function
|
|
1154
|
+
function useTranslationData() {
|
|
1150
1155
|
const data = reactRouter.useRouteLoaderData("root");
|
|
1151
1156
|
return {
|
|
1152
1157
|
staticContent: data?.weaverseTheme?.staticContent ?? {},
|
|
@@ -1724,6 +1729,9 @@ var WeaverseClient = class {
|
|
|
1724
1729
|
try {
|
|
1725
1730
|
const { projectId, weaverseHost } = this.configs;
|
|
1726
1731
|
const i18n = this.storefront.i18n;
|
|
1732
|
+
if (!this.themeSchema?.i18n) {
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1727
1735
|
if (!(projectId && weaverseHost)) {
|
|
1728
1736
|
return;
|
|
1729
1737
|
}
|
|
@@ -1824,7 +1832,7 @@ var WeaverseClient = class {
|
|
|
1824
1832
|
* Fetches page content, executes component loaders, and handles empty items fallback.
|
|
1825
1833
|
*
|
|
1826
1834
|
* @param params - Optional page loading parameters
|
|
1827
|
-
* @param params.type - Page type (
|
|
1835
|
+
* @param params.type - Page type (INDEX, PAGE, PRODUCT, COLLECTION, etc.)
|
|
1828
1836
|
* @param params.handle - Page handle for dynamic routes
|
|
1829
1837
|
* @param params.locale - Locale override
|
|
1830
1838
|
* @param params.projectId - Route-level project ID override (for multi-project)
|
|
@@ -1837,7 +1845,7 @@ var WeaverseClient = class {
|
|
|
1837
1845
|
* const data = await weaverse.loadPage()
|
|
1838
1846
|
*
|
|
1839
1847
|
* // With page type
|
|
1840
|
-
* const data = await weaverse.loadPage({ type: '
|
|
1848
|
+
* const data = await weaverse.loadPage({ type: 'INDEX' })
|
|
1841
1849
|
*
|
|
1842
1850
|
* // Route-level project override
|
|
1843
1851
|
* const data = await weaverse.loadPage({
|
|
@@ -2080,6 +2088,8 @@ Object.defineProperty(exports, "useWeaverse", {
|
|
|
2080
2088
|
exports.IMAGES_PLACEHOLDERS = IMAGES_PLACEHOLDERS;
|
|
2081
2089
|
exports.ThemeTextProvider = ThemeTextProvider;
|
|
2082
2090
|
exports.ThemeTextStore = ThemeTextStore;
|
|
2091
|
+
exports.TranslationProvider = TranslationProvider;
|
|
2092
|
+
exports.TranslationStore = TranslationStore;
|
|
2083
2093
|
exports.WeaverseClient = WeaverseClient;
|
|
2084
2094
|
exports.WeaverseError = WeaverseError;
|
|
2085
2095
|
exports.WeaverseHydrogen = WeaverseHydrogen;
|
|
@@ -2106,6 +2116,7 @@ exports.isWithCacheFetchResponse = isWithCacheFetchResponse;
|
|
|
2106
2116
|
exports.registerComponent = registerComponent;
|
|
2107
2117
|
exports.useThemeSettings = useThemeSettings;
|
|
2108
2118
|
exports.useThemeText = useThemeText;
|
|
2119
|
+
exports.useTranslation = useTranslation;
|
|
2109
2120
|
exports.useWeaverseDataContext = useWeaverseDataContext;
|
|
2110
2121
|
exports.withWeaverse = withWeaverse;
|
|
2111
2122
|
Object.keys(schema$1).forEach(function (k) {
|