@weaverse/hydrogen 4.1.2 → 4.2.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 +41 -34
- package/dist/index.d.ts +41 -34
- package/dist/index.js +170 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +170 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventEmitter,
|
|
1
|
+
import { EventEmitter, BasicInput as BasicInput$1, ElementData, WeaverseElement, ElementSchema, WeaverseProjectDataType, WeaverseCoreParams, WeaverseResourcePickerData, Weaverse, PlatformTypeEnum, WeaverseItemStore } from '@weaverse/react';
|
|
2
2
|
export { InputType, PositionInputValue, WeaverseImage, WeaverseVideo, isBrowser, isIframe, useChildInstances, useItemInstance, useParentInstance, useWeaverse } from '@weaverse/react';
|
|
3
3
|
import { NavigateFunction } from '@remix-run/react';
|
|
4
4
|
import { createWithCache, I18nBase, HydrogenContext, HydrogenEnv } from '@shopify/hydrogen';
|
|
@@ -47,7 +47,8 @@ declare class WeaverseClient {
|
|
|
47
47
|
waitUntil: WeaverseClientArgs['waitUntil'];
|
|
48
48
|
countries?: WeaverseClientArgs['countries'];
|
|
49
49
|
constructor(args: WeaverseClientArgs);
|
|
50
|
-
|
|
50
|
+
private directFetch;
|
|
51
|
+
fetchWithCache<T extends object>(url: string, options?: FetchWithCacheOptions): Promise<T>;
|
|
51
52
|
loadThemeSettings: (strategy?: AllCacheOptions) => Promise<any>;
|
|
52
53
|
generateFallbackPage: (message: string) => HydrogenPageData;
|
|
53
54
|
loadPage: (params?: LoadPageParams) => Promise<WeaverseLoaderData | null>;
|
|
@@ -70,9 +71,7 @@ interface AllCacheOptions {
|
|
|
70
71
|
}
|
|
71
72
|
type ComponentLoaderArgs<T = any, E = any> = {
|
|
72
73
|
data: T;
|
|
73
|
-
weaverse:
|
|
74
|
-
env: E;
|
|
75
|
-
};
|
|
74
|
+
weaverse: WeaverseClient;
|
|
76
75
|
};
|
|
77
76
|
interface RouteLoaderArgs extends LoaderFunctionArgs {
|
|
78
77
|
context: AppLoadContext & {
|
|
@@ -175,6 +174,8 @@ type WeaverseStudioQueries = {
|
|
|
175
174
|
weaverseHost: string;
|
|
176
175
|
weaverseVersion: string;
|
|
177
176
|
isDesignMode: boolean;
|
|
177
|
+
isPreviewMode?: boolean;
|
|
178
|
+
sectionType?: string;
|
|
178
179
|
};
|
|
179
180
|
type PublicEnv = {
|
|
180
181
|
PUBLIC_STORE_DOMAIN: string;
|
|
@@ -186,6 +187,8 @@ type WeaverseProjectConfigs = {
|
|
|
186
187
|
weaverseApiKey: string;
|
|
187
188
|
weaverseVersion?: string;
|
|
188
189
|
isDesignMode?: boolean;
|
|
190
|
+
isPreviewMode?: boolean;
|
|
191
|
+
sectionType?: string;
|
|
189
192
|
publicEnv?: PublicEnv;
|
|
190
193
|
};
|
|
191
194
|
type HydrogenPageAssignment = {
|
|
@@ -276,34 +279,6 @@ type RootRouteData = {
|
|
|
276
279
|
};
|
|
277
280
|
[key: string]: any;
|
|
278
281
|
};
|
|
279
|
-
type OptionDisplayType = 'dropdown' | 'button' | 'color' | 'variant-image' | 'custom-image';
|
|
280
|
-
type OptionSize = 'sm' | 'md' | 'lg';
|
|
281
|
-
type OptionShape = 'square' | 'round' | 'circle';
|
|
282
|
-
type OptionData = {
|
|
283
|
-
id: string;
|
|
284
|
-
name: string;
|
|
285
|
-
displayName: string;
|
|
286
|
-
type: OptionDisplayType;
|
|
287
|
-
size: OptionSize;
|
|
288
|
-
shape: OptionShape;
|
|
289
|
-
};
|
|
290
|
-
type SwatchesConfigs = {
|
|
291
|
-
options: OptionData[];
|
|
292
|
-
swatches: {
|
|
293
|
-
colors: ColorSwatch[];
|
|
294
|
-
images: ImageSwatch[];
|
|
295
|
-
};
|
|
296
|
-
};
|
|
297
|
-
type ColorSwatch = {
|
|
298
|
-
id: string;
|
|
299
|
-
name: string;
|
|
300
|
-
value: string;
|
|
301
|
-
};
|
|
302
|
-
type ImageSwatch = {
|
|
303
|
-
id: string;
|
|
304
|
-
name: string;
|
|
305
|
-
value: WeaverseImage | string;
|
|
306
|
-
};
|
|
307
282
|
type WeaverseProduct = WeaverseResourcePickerData;
|
|
308
283
|
type WeaverseCollection = WeaverseResourcePickerData;
|
|
309
284
|
type WeaverseBlog = WeaverseResourcePickerData;
|
|
@@ -352,6 +327,38 @@ declare function generateDataFromSchema({ inspector, }: HydrogenComponentSchema
|
|
|
352
327
|
* resizeImage('https://cdn.shopify.com/image.jpg', '100x100')
|
|
353
328
|
*/
|
|
354
329
|
declare function resizeShopifyImage(imageURL: string, size: string): string;
|
|
330
|
+
declare function recursivelyAddDataItem(type: string, components: HydrogenComponent<any>[], items: any[], initData?: object): `${string}-${string}-${string}-${string}-${string}`;
|
|
331
|
+
declare function getPreviewData(type: string, components: any, weaverseHost: string): {
|
|
332
|
+
page: {
|
|
333
|
+
id: string;
|
|
334
|
+
name: string;
|
|
335
|
+
rootId: string;
|
|
336
|
+
items: any[];
|
|
337
|
+
};
|
|
338
|
+
project: {
|
|
339
|
+
id: string;
|
|
340
|
+
weaverseShopId: string;
|
|
341
|
+
name: string;
|
|
342
|
+
};
|
|
343
|
+
configs: {
|
|
344
|
+
projectId: string;
|
|
345
|
+
weaverseHost: string;
|
|
346
|
+
isDesignMode: boolean;
|
|
347
|
+
isPreviewMode: boolean;
|
|
348
|
+
requestInfo: {
|
|
349
|
+
i18n: {
|
|
350
|
+
label: string;
|
|
351
|
+
language: string;
|
|
352
|
+
country: string;
|
|
353
|
+
currency: string;
|
|
354
|
+
pathPrefix: string;
|
|
355
|
+
};
|
|
356
|
+
queries: {};
|
|
357
|
+
pathname: string;
|
|
358
|
+
search: string;
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
};
|
|
355
362
|
|
|
356
363
|
declare function getSelectedProductOptions(request: Request): SelectedOptionInput[];
|
|
357
364
|
|
|
@@ -405,4 +412,4 @@ declare class WeaverseHydrogenItem extends WeaverseItemStore {
|
|
|
405
412
|
get _schemaData(): Record<string, any>;
|
|
406
413
|
}
|
|
407
414
|
|
|
408
|
-
export { type AllCacheOptions, type BasicInput, type
|
|
415
|
+
export { type AllCacheOptions, type BasicInput, type ComponentLoaderArgs, type FetchProjectPayload, type FetchProjectRequestBody, type FetchWithCacheOptions, type HeadingInput, type HeadingInputType, type HydrogenComponent, type HydrogenComponentData, type HydrogenComponentPresets, type HydrogenComponentProps, type HydrogenComponentSchema, type HydrogenElement, type HydrogenPageAssignment, type HydrogenPageConfigs, type HydrogenPageData, type HydrogenProjectType, type HydrogenThemeInfo, type HydrogenThemeSchema, type HydrogenThemeSettings, type HydrogenToolbarAction, type I18nLocale, IMAGES_PLACEHOLDERS, type InspectorGroup, type LoadPageParams, type Locale, type Localizations, type PageAssignmentParams, type PageType, type PublicEnv, type RootRouteData, type RouteLoaderArgs, type WeaverseArticle, type WeaverseBlog, WeaverseClient, type WeaverseClientArgs, type WeaverseCollection, WeaverseHydrogen, WeaverseHydrogenItem, type WeaverseHydrogenParams, WeaverseHydrogenRoot, type WeaverseHydrogenRootProps, type WeaverseInternal, type WeaverseLoaderData, type WeaverseLoaderRequestInfo, type WeaverseMetaObject, type WeaverseProduct, type WeaverseProjectConfigs, type WeaverseStudioQueries, generateDataFromSchema, getPreviewData, getRequestQueries, getSelectedProductOptions, getWeaverseConfigs, recursivelyAddDataItem, resizeShopifyImage, useThemeSettings, withWeaverse };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventEmitter,
|
|
1
|
+
import { EventEmitter, BasicInput as BasicInput$1, ElementData, WeaverseElement, ElementSchema, WeaverseProjectDataType, WeaverseCoreParams, WeaverseResourcePickerData, Weaverse, PlatformTypeEnum, WeaverseItemStore } from '@weaverse/react';
|
|
2
2
|
export { InputType, PositionInputValue, WeaverseImage, WeaverseVideo, isBrowser, isIframe, useChildInstances, useItemInstance, useParentInstance, useWeaverse } from '@weaverse/react';
|
|
3
3
|
import { NavigateFunction } from '@remix-run/react';
|
|
4
4
|
import { createWithCache, I18nBase, HydrogenContext, HydrogenEnv } from '@shopify/hydrogen';
|
|
@@ -47,7 +47,8 @@ declare class WeaverseClient {
|
|
|
47
47
|
waitUntil: WeaverseClientArgs['waitUntil'];
|
|
48
48
|
countries?: WeaverseClientArgs['countries'];
|
|
49
49
|
constructor(args: WeaverseClientArgs);
|
|
50
|
-
|
|
50
|
+
private directFetch;
|
|
51
|
+
fetchWithCache<T extends object>(url: string, options?: FetchWithCacheOptions): Promise<T>;
|
|
51
52
|
loadThemeSettings: (strategy?: AllCacheOptions) => Promise<any>;
|
|
52
53
|
generateFallbackPage: (message: string) => HydrogenPageData;
|
|
53
54
|
loadPage: (params?: LoadPageParams) => Promise<WeaverseLoaderData | null>;
|
|
@@ -70,9 +71,7 @@ interface AllCacheOptions {
|
|
|
70
71
|
}
|
|
71
72
|
type ComponentLoaderArgs<T = any, E = any> = {
|
|
72
73
|
data: T;
|
|
73
|
-
weaverse:
|
|
74
|
-
env: E;
|
|
75
|
-
};
|
|
74
|
+
weaverse: WeaverseClient;
|
|
76
75
|
};
|
|
77
76
|
interface RouteLoaderArgs extends LoaderFunctionArgs {
|
|
78
77
|
context: AppLoadContext & {
|
|
@@ -175,6 +174,8 @@ type WeaverseStudioQueries = {
|
|
|
175
174
|
weaverseHost: string;
|
|
176
175
|
weaverseVersion: string;
|
|
177
176
|
isDesignMode: boolean;
|
|
177
|
+
isPreviewMode?: boolean;
|
|
178
|
+
sectionType?: string;
|
|
178
179
|
};
|
|
179
180
|
type PublicEnv = {
|
|
180
181
|
PUBLIC_STORE_DOMAIN: string;
|
|
@@ -186,6 +187,8 @@ type WeaverseProjectConfigs = {
|
|
|
186
187
|
weaverseApiKey: string;
|
|
187
188
|
weaverseVersion?: string;
|
|
188
189
|
isDesignMode?: boolean;
|
|
190
|
+
isPreviewMode?: boolean;
|
|
191
|
+
sectionType?: string;
|
|
189
192
|
publicEnv?: PublicEnv;
|
|
190
193
|
};
|
|
191
194
|
type HydrogenPageAssignment = {
|
|
@@ -276,34 +279,6 @@ type RootRouteData = {
|
|
|
276
279
|
};
|
|
277
280
|
[key: string]: any;
|
|
278
281
|
};
|
|
279
|
-
type OptionDisplayType = 'dropdown' | 'button' | 'color' | 'variant-image' | 'custom-image';
|
|
280
|
-
type OptionSize = 'sm' | 'md' | 'lg';
|
|
281
|
-
type OptionShape = 'square' | 'round' | 'circle';
|
|
282
|
-
type OptionData = {
|
|
283
|
-
id: string;
|
|
284
|
-
name: string;
|
|
285
|
-
displayName: string;
|
|
286
|
-
type: OptionDisplayType;
|
|
287
|
-
size: OptionSize;
|
|
288
|
-
shape: OptionShape;
|
|
289
|
-
};
|
|
290
|
-
type SwatchesConfigs = {
|
|
291
|
-
options: OptionData[];
|
|
292
|
-
swatches: {
|
|
293
|
-
colors: ColorSwatch[];
|
|
294
|
-
images: ImageSwatch[];
|
|
295
|
-
};
|
|
296
|
-
};
|
|
297
|
-
type ColorSwatch = {
|
|
298
|
-
id: string;
|
|
299
|
-
name: string;
|
|
300
|
-
value: string;
|
|
301
|
-
};
|
|
302
|
-
type ImageSwatch = {
|
|
303
|
-
id: string;
|
|
304
|
-
name: string;
|
|
305
|
-
value: WeaverseImage | string;
|
|
306
|
-
};
|
|
307
282
|
type WeaverseProduct = WeaverseResourcePickerData;
|
|
308
283
|
type WeaverseCollection = WeaverseResourcePickerData;
|
|
309
284
|
type WeaverseBlog = WeaverseResourcePickerData;
|
|
@@ -352,6 +327,38 @@ declare function generateDataFromSchema({ inspector, }: HydrogenComponentSchema
|
|
|
352
327
|
* resizeImage('https://cdn.shopify.com/image.jpg', '100x100')
|
|
353
328
|
*/
|
|
354
329
|
declare function resizeShopifyImage(imageURL: string, size: string): string;
|
|
330
|
+
declare function recursivelyAddDataItem(type: string, components: HydrogenComponent<any>[], items: any[], initData?: object): `${string}-${string}-${string}-${string}-${string}`;
|
|
331
|
+
declare function getPreviewData(type: string, components: any, weaverseHost: string): {
|
|
332
|
+
page: {
|
|
333
|
+
id: string;
|
|
334
|
+
name: string;
|
|
335
|
+
rootId: string;
|
|
336
|
+
items: any[];
|
|
337
|
+
};
|
|
338
|
+
project: {
|
|
339
|
+
id: string;
|
|
340
|
+
weaverseShopId: string;
|
|
341
|
+
name: string;
|
|
342
|
+
};
|
|
343
|
+
configs: {
|
|
344
|
+
projectId: string;
|
|
345
|
+
weaverseHost: string;
|
|
346
|
+
isDesignMode: boolean;
|
|
347
|
+
isPreviewMode: boolean;
|
|
348
|
+
requestInfo: {
|
|
349
|
+
i18n: {
|
|
350
|
+
label: string;
|
|
351
|
+
language: string;
|
|
352
|
+
country: string;
|
|
353
|
+
currency: string;
|
|
354
|
+
pathPrefix: string;
|
|
355
|
+
};
|
|
356
|
+
queries: {};
|
|
357
|
+
pathname: string;
|
|
358
|
+
search: string;
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
};
|
|
355
362
|
|
|
356
363
|
declare function getSelectedProductOptions(request: Request): SelectedOptionInput[];
|
|
357
364
|
|
|
@@ -405,4 +412,4 @@ declare class WeaverseHydrogenItem extends WeaverseItemStore {
|
|
|
405
412
|
get _schemaData(): Record<string, any>;
|
|
406
413
|
}
|
|
407
414
|
|
|
408
|
-
export { type AllCacheOptions, type BasicInput, type
|
|
415
|
+
export { type AllCacheOptions, type BasicInput, type ComponentLoaderArgs, type FetchProjectPayload, type FetchProjectRequestBody, type FetchWithCacheOptions, type HeadingInput, type HeadingInputType, type HydrogenComponent, type HydrogenComponentData, type HydrogenComponentPresets, type HydrogenComponentProps, type HydrogenComponentSchema, type HydrogenElement, type HydrogenPageAssignment, type HydrogenPageConfigs, type HydrogenPageData, type HydrogenProjectType, type HydrogenThemeInfo, type HydrogenThemeSchema, type HydrogenThemeSettings, type HydrogenToolbarAction, type I18nLocale, IMAGES_PLACEHOLDERS, type InspectorGroup, type LoadPageParams, type Locale, type Localizations, type PageAssignmentParams, type PageType, type PublicEnv, type RootRouteData, type RouteLoaderArgs, type WeaverseArticle, type WeaverseBlog, WeaverseClient, type WeaverseClientArgs, type WeaverseCollection, WeaverseHydrogen, WeaverseHydrogenItem, type WeaverseHydrogenParams, WeaverseHydrogenRoot, type WeaverseHydrogenRootProps, type WeaverseInternal, type WeaverseLoaderData, type WeaverseLoaderRequestInfo, type WeaverseMetaObject, type WeaverseProduct, type WeaverseProjectConfigs, type WeaverseStudioQueries, generateDataFromSchema, getPreviewData, getRequestQueries, getSelectedProductOptions, getWeaverseConfigs, recursivelyAddDataItem, resizeShopifyImage, useThemeSettings, withWeaverse };
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,8 @@ function getWeaverseConfigs(request, env) {
|
|
|
38
38
|
weaverseProjectId,
|
|
39
39
|
weaverseHost,
|
|
40
40
|
isDesignMode,
|
|
41
|
+
isPreviewMode,
|
|
42
|
+
sectionType,
|
|
41
43
|
weaverseVersion,
|
|
42
44
|
weaverseApiKey
|
|
43
45
|
} = queries;
|
|
@@ -47,6 +49,8 @@ function getWeaverseConfigs(request, env) {
|
|
|
47
49
|
weaverseApiKey: weaverseApiKey || WEAVERSE_API_KEY || envFromProcess.WEAVERSE_API_KEY || "",
|
|
48
50
|
weaverseVersion: weaverseVersion || "",
|
|
49
51
|
isDesignMode: isDesignMode || false,
|
|
52
|
+
isPreviewMode: isPreviewMode || false,
|
|
53
|
+
sectionType: sectionType || "",
|
|
50
54
|
publicEnv: {
|
|
51
55
|
PUBLIC_STORE_DOMAIN: PUBLIC_STORE_DOMAIN || "",
|
|
52
56
|
PUBLIC_STOREFRONT_API_TOKEN: PUBLIC_STOREFRONT_API_TOKEN || ""
|
|
@@ -80,6 +84,94 @@ function resizeShopifyImage(imageURL, size) {
|
|
|
80
84
|
return imageURL;
|
|
81
85
|
}
|
|
82
86
|
}
|
|
87
|
+
function recursivelyAddDataItem(type, components, items, initData) {
|
|
88
|
+
const component = components.find((c) => c.schema.type === type);
|
|
89
|
+
if (!component) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
let childIDs = [];
|
|
93
|
+
const id = crypto.randomUUID();
|
|
94
|
+
const { children, ...data } = component.schema?.presets || {};
|
|
95
|
+
if (children) {
|
|
96
|
+
for (const child of children) {
|
|
97
|
+
const { type: type2, children: children2, ...data2 } = child;
|
|
98
|
+
const childID = recursivelyAddDataItem(
|
|
99
|
+
child.type,
|
|
100
|
+
components,
|
|
101
|
+
items,
|
|
102
|
+
data2
|
|
103
|
+
);
|
|
104
|
+
childIDs.push({
|
|
105
|
+
id: childID
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
items.push({
|
|
110
|
+
data: { ...data, ...initData },
|
|
111
|
+
id,
|
|
112
|
+
type,
|
|
113
|
+
children: childIDs
|
|
114
|
+
});
|
|
115
|
+
return id;
|
|
116
|
+
}
|
|
117
|
+
function getPreviewData(type, components, weaverseHost) {
|
|
118
|
+
const initialData = {
|
|
119
|
+
project: {
|
|
120
|
+
id: "x",
|
|
121
|
+
weaverseShopId: "shopid",
|
|
122
|
+
name: "Section Preview"
|
|
123
|
+
},
|
|
124
|
+
// pageAssignment: {
|
|
125
|
+
// projectId: "x",
|
|
126
|
+
// type: "CUSTOM",
|
|
127
|
+
// locale: "en-us",
|
|
128
|
+
// handle: "",
|
|
129
|
+
// },
|
|
130
|
+
configs: {
|
|
131
|
+
projectId: "x",
|
|
132
|
+
weaverseHost,
|
|
133
|
+
isDesignMode: false,
|
|
134
|
+
isPreviewMode: true,
|
|
135
|
+
requestInfo: {
|
|
136
|
+
i18n: {
|
|
137
|
+
label: "United States (USD $)",
|
|
138
|
+
language: "EN",
|
|
139
|
+
country: "US",
|
|
140
|
+
currency: "USD",
|
|
141
|
+
pathPrefix: ""
|
|
142
|
+
},
|
|
143
|
+
queries: {},
|
|
144
|
+
pathname: "/",
|
|
145
|
+
search: ""
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
let items = [];
|
|
150
|
+
const id = recursivelyAddDataItem(type, components, items);
|
|
151
|
+
const page = {
|
|
152
|
+
id: "0",
|
|
153
|
+
name: "Preview section",
|
|
154
|
+
rootId: "1",
|
|
155
|
+
items: [
|
|
156
|
+
{
|
|
157
|
+
data: {},
|
|
158
|
+
id: "1",
|
|
159
|
+
type: "main",
|
|
160
|
+
children: [
|
|
161
|
+
{
|
|
162
|
+
id
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
...items
|
|
167
|
+
]
|
|
168
|
+
};
|
|
169
|
+
const previewData = {
|
|
170
|
+
...initialData,
|
|
171
|
+
page
|
|
172
|
+
};
|
|
173
|
+
return previewData;
|
|
174
|
+
}
|
|
83
175
|
var ThemeSettingsStore = class extends react.EventEmitter {
|
|
84
176
|
settings = {};
|
|
85
177
|
countries;
|
|
@@ -134,19 +226,24 @@ function useStudio(weaverse) {
|
|
|
134
226
|
let { pathname, search } = react$2.useLocation();
|
|
135
227
|
let navigate = react$2.useNavigate();
|
|
136
228
|
let themeSettingsStore = useThemeSettingsStore();
|
|
137
|
-
let { isDesignMode, weaverseHost, weaverseVersion } = weaverse;
|
|
229
|
+
let { isDesignMode, weaverseHost, weaverseVersion, isPreviewMode } = weaverse;
|
|
138
230
|
react$1.useEffect(() => {
|
|
139
|
-
if (navigation.state === "idle"
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
231
|
+
if (navigation.state === "idle") {
|
|
232
|
+
if (isPreviewMode) {
|
|
233
|
+
let previewSrc = `${weaverseHost}/static/studio/hydrogen/preview.js?v=${weaverseVersion}`;
|
|
234
|
+
react.loadScript(previewSrc).catch(console.error);
|
|
235
|
+
} else if (isDesignMode) {
|
|
236
|
+
weaverse.internal = {
|
|
237
|
+
...weaverse.internal,
|
|
238
|
+
navigate,
|
|
239
|
+
revalidate,
|
|
240
|
+
themeSettingsStore
|
|
241
|
+
};
|
|
242
|
+
let studioSrc = `${weaverseHost}/static/studio/hydrogen/index.js?v=${weaverseVersion}`;
|
|
243
|
+
react.loadScript(studioSrc).then(() => {
|
|
244
|
+
window.weaverseStudio?.init(weaverse);
|
|
245
|
+
}).catch(console.error);
|
|
246
|
+
}
|
|
150
247
|
}
|
|
151
248
|
}, [pathname, search, navigation.state]);
|
|
152
249
|
usePixel(weaverse);
|
|
@@ -279,12 +376,19 @@ function withWeaverse(Component) {
|
|
|
279
376
|
function FallbackError({ error }) {
|
|
280
377
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { children: error?.message || "An unexpected error occurred" });
|
|
281
378
|
}
|
|
379
|
+
var API_PATH = "api/public";
|
|
380
|
+
var DEFAULT_CACHE_STRATEGY = {
|
|
381
|
+
maxAge: 5,
|
|
382
|
+
sMaxAge: 5,
|
|
383
|
+
staleWhileRevalidate: 82800
|
|
384
|
+
};
|
|
282
385
|
var WeaverseClient = class {
|
|
283
|
-
API =
|
|
386
|
+
API = API_PATH;
|
|
284
387
|
basePageConfigs;
|
|
285
388
|
basePageRequestBody;
|
|
286
389
|
configs;
|
|
287
390
|
withCache;
|
|
391
|
+
// Required dependencies
|
|
288
392
|
request;
|
|
289
393
|
storefront;
|
|
290
394
|
components;
|
|
@@ -294,7 +398,7 @@ var WeaverseClient = class {
|
|
|
294
398
|
waitUntil;
|
|
295
399
|
countries;
|
|
296
400
|
constructor(args) {
|
|
297
|
-
|
|
401
|
+
const {
|
|
298
402
|
env,
|
|
299
403
|
storefront,
|
|
300
404
|
components,
|
|
@@ -327,50 +431,50 @@ var WeaverseClient = class {
|
|
|
327
431
|
projectId: this.configs.projectId
|
|
328
432
|
};
|
|
329
433
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
434
|
+
// Helper method for direct fetching in design mode
|
|
435
|
+
async directFetch(url, options = {}) {
|
|
436
|
+
try {
|
|
437
|
+
const res = await fetch(url, options);
|
|
438
|
+
if (!res.ok) {
|
|
439
|
+
const error = await res.text();
|
|
440
|
+
throw new Error(`${res.status} ${res.statusText} ${error}`);
|
|
441
|
+
}
|
|
442
|
+
return res.json();
|
|
443
|
+
} catch (err) {
|
|
444
|
+
throw new Error(`Failed to fetch data from ${url}`, { cause: err });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
async fetchWithCache(url, options = {}) {
|
|
448
|
+
const {
|
|
449
|
+
strategy = this.storefront.CacheCustom(DEFAULT_CACHE_STRATEGY),
|
|
338
450
|
...reqInit
|
|
339
451
|
} = options;
|
|
452
|
+
const cacheKey = [url, options.body];
|
|
340
453
|
if (this.configs.isDesignMode) {
|
|
341
|
-
|
|
342
|
-
const res2 = await fetch(url, reqInit);
|
|
343
|
-
return await res2.json();
|
|
344
|
-
} catch (err) {
|
|
345
|
-
throw new Error(`Failed to fetch data from ${url}`, { cause: err });
|
|
346
|
-
}
|
|
454
|
+
return this.directFetch(url, reqInit);
|
|
347
455
|
}
|
|
348
|
-
|
|
456
|
+
return this.withCache.run(
|
|
349
457
|
{
|
|
350
458
|
cacheKey,
|
|
351
459
|
cacheStrategy: strategy,
|
|
352
|
-
// @ts-expect-error
|
|
353
460
|
shouldCacheResult: (result) => result?.data
|
|
354
461
|
},
|
|
355
462
|
async () => {
|
|
356
|
-
|
|
463
|
+
return this.directFetch(url, {
|
|
357
464
|
...reqInit,
|
|
358
465
|
headers: {
|
|
359
466
|
"Cache-Control": hydrogen.generateCacheControlHeader(strategy),
|
|
360
467
|
...reqInit.headers
|
|
361
468
|
}
|
|
362
469
|
});
|
|
363
|
-
if (!response.ok) {
|
|
364
|
-
let error = await response.text();
|
|
365
|
-
let { status, statusText } = response;
|
|
366
|
-
throw new Error(`${status} ${statusText} ${error}`, { cause: error });
|
|
367
|
-
}
|
|
368
|
-
return await response.json();
|
|
369
470
|
}
|
|
370
471
|
);
|
|
371
|
-
|
|
372
|
-
};
|
|
472
|
+
}
|
|
373
473
|
loadThemeSettings = async (strategy) => {
|
|
474
|
+
let defaultThemeSettings = {};
|
|
475
|
+
if (this.themeSchema) {
|
|
476
|
+
defaultThemeSettings = generateDataFromSchema(this.themeSchema);
|
|
477
|
+
}
|
|
374
478
|
try {
|
|
375
479
|
let { API, configs } = this;
|
|
376
480
|
let { weaverseHost, projectId, isDesignMode } = configs;
|
|
@@ -393,10 +497,6 @@ var WeaverseClient = class {
|
|
|
393
497
|
}
|
|
394
498
|
let data = res || {};
|
|
395
499
|
if (data?.theme && this.themeSchema?.inspector) {
|
|
396
|
-
let defaultThemeSettings = {};
|
|
397
|
-
if (this.themeSchema) {
|
|
398
|
-
defaultThemeSettings = generateDataFromSchema(this.themeSchema);
|
|
399
|
-
}
|
|
400
500
|
data.theme = {
|
|
401
501
|
...defaultThemeSettings,
|
|
402
502
|
...data.theme
|
|
@@ -412,8 +512,8 @@ var WeaverseClient = class {
|
|
|
412
512
|
}
|
|
413
513
|
return data;
|
|
414
514
|
} catch (e) {
|
|
415
|
-
console.
|
|
416
|
-
return
|
|
515
|
+
console.info("Unable to load theme settings", e);
|
|
516
|
+
return defaultThemeSettings;
|
|
417
517
|
}
|
|
418
518
|
};
|
|
419
519
|
generateFallbackPage = (message) => {
|
|
@@ -434,7 +534,21 @@ var WeaverseClient = class {
|
|
|
434
534
|
loadPage = async (params = {}) => {
|
|
435
535
|
try {
|
|
436
536
|
let { request, storefront, basePageRequestBody, basePageConfigs } = this;
|
|
437
|
-
let {
|
|
537
|
+
let {
|
|
538
|
+
projectId,
|
|
539
|
+
isDesignMode,
|
|
540
|
+
weaverseHost,
|
|
541
|
+
isPreviewMode,
|
|
542
|
+
sectionType
|
|
543
|
+
} = this.configs;
|
|
544
|
+
if (isPreviewMode) {
|
|
545
|
+
const previewData = getPreviewData(
|
|
546
|
+
sectionType,
|
|
547
|
+
this.components,
|
|
548
|
+
weaverseHost
|
|
549
|
+
);
|
|
550
|
+
return previewData;
|
|
551
|
+
}
|
|
438
552
|
if (!projectId) {
|
|
439
553
|
throw new Error("Missing Weaverse projectId!");
|
|
440
554
|
}
|
|
@@ -463,7 +577,13 @@ var WeaverseClient = class {
|
|
|
463
577
|
}
|
|
464
578
|
let { page, project, pageAssignment } = payload;
|
|
465
579
|
if (!project) {
|
|
466
|
-
|
|
580
|
+
console.error("Weaverse project not found. Id:", projectId);
|
|
581
|
+
project = {
|
|
582
|
+
id: projectId,
|
|
583
|
+
name: "Weaverse project not found.",
|
|
584
|
+
weaverseShopId: ""
|
|
585
|
+
};
|
|
586
|
+
page = this.generateFallbackPage("Weaverse project not found.");
|
|
467
587
|
}
|
|
468
588
|
if (!page) {
|
|
469
589
|
page = this.generateFallbackPage("Please add new section to start.");
|
|
@@ -489,7 +609,7 @@ var WeaverseClient = class {
|
|
|
489
609
|
};
|
|
490
610
|
} catch (e) {
|
|
491
611
|
console.error(`\u274C Page load failed.`, e);
|
|
492
|
-
|
|
612
|
+
return null;
|
|
493
613
|
}
|
|
494
614
|
};
|
|
495
615
|
execComponentLoader = async (item) => {
|
|
@@ -619,9 +739,11 @@ exports.WeaverseHydrogen = WeaverseHydrogen;
|
|
|
619
739
|
exports.WeaverseHydrogenItem = WeaverseHydrogenItem;
|
|
620
740
|
exports.WeaverseHydrogenRoot = WeaverseHydrogenRoot;
|
|
621
741
|
exports.generateDataFromSchema = generateDataFromSchema;
|
|
742
|
+
exports.getPreviewData = getPreviewData;
|
|
622
743
|
exports.getRequestQueries = getRequestQueries;
|
|
623
744
|
exports.getSelectedProductOptions = getSelectedProductOptions;
|
|
624
745
|
exports.getWeaverseConfigs = getWeaverseConfigs;
|
|
746
|
+
exports.recursivelyAddDataItem = recursivelyAddDataItem;
|
|
625
747
|
exports.resizeShopifyImage = resizeShopifyImage;
|
|
626
748
|
exports.useThemeSettings = useThemeSettings;
|
|
627
749
|
exports.withWeaverse = withWeaverse;
|