@weaverse/hydrogen 1.3.2 → 1.3.3
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 +162 -140
- package/dist/index.mjs +162 -140
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -50,7 +50,7 @@ var import_hydrogen = require("@shopify/hydrogen");
|
|
|
50
50
|
|
|
51
51
|
// package.json
|
|
52
52
|
var package_default = {
|
|
53
|
-
version: "1.3.
|
|
53
|
+
version: "1.3.3",
|
|
54
54
|
license: "MIT",
|
|
55
55
|
main: "dist/index.js",
|
|
56
56
|
typings: "dist/index.d.ts",
|
|
@@ -62,7 +62,7 @@ var package_default = {
|
|
|
62
62
|
"dist/*"
|
|
63
63
|
],
|
|
64
64
|
engines: {
|
|
65
|
-
node: ">=
|
|
65
|
+
node: ">=16"
|
|
66
66
|
},
|
|
67
67
|
scripts: {
|
|
68
68
|
start: "npm run dev",
|
|
@@ -85,7 +85,7 @@ var package_default = {
|
|
|
85
85
|
dependencies: {
|
|
86
86
|
"@remix-run/react": "1.19.1",
|
|
87
87
|
"@shopify/hydrogen": "2023.7.8",
|
|
88
|
-
"@weaverse/react": "1.3.
|
|
88
|
+
"@weaverse/react": "1.3.3",
|
|
89
89
|
"react-error-boundary": "^4.0.11"
|
|
90
90
|
},
|
|
91
91
|
devDependencies: {
|
|
@@ -151,24 +151,56 @@ function getWeaverseCsp(request) {
|
|
|
151
151
|
|
|
152
152
|
// src/client.ts
|
|
153
153
|
var WeaverseClient = class {
|
|
154
|
+
API = "api/public/project";
|
|
155
|
+
clientVersion = package_default.version;
|
|
156
|
+
storefront;
|
|
157
|
+
components;
|
|
158
|
+
countries;
|
|
159
|
+
themeSchema;
|
|
160
|
+
configs;
|
|
161
|
+
basePageConfigs;
|
|
162
|
+
basePageRequestBody;
|
|
163
|
+
withCache;
|
|
154
164
|
constructor(args) {
|
|
155
|
-
|
|
156
|
-
this.
|
|
157
|
-
this.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
let { configs, storefront, components, countries, withCache, themeSchema } = args;
|
|
166
|
+
this.storefront = storefront;
|
|
167
|
+
this.components = components;
|
|
168
|
+
this.countries = countries;
|
|
169
|
+
this.themeSchema = themeSchema;
|
|
170
|
+
this.configs = configs;
|
|
171
|
+
this.withCache = withCache;
|
|
172
|
+
this.basePageConfigs = {
|
|
173
|
+
projectId: configs.projectId,
|
|
174
|
+
weaverseHost: configs.weaverseHost,
|
|
175
|
+
weaverseVersion: configs.weaverseVersion,
|
|
176
|
+
isDesignMode: configs.isDesignMode
|
|
177
|
+
};
|
|
178
|
+
this.basePageRequestBody = {
|
|
179
|
+
countries,
|
|
180
|
+
isDesignMode: this.configs.isDesignMode,
|
|
181
|
+
i18n: storefront.i18n,
|
|
182
|
+
projectId: this.configs.projectId
|
|
168
183
|
};
|
|
169
|
-
|
|
184
|
+
}
|
|
185
|
+
fetchWithCache = (url, options) => {
|
|
186
|
+
let cacheKey = [url, options.body];
|
|
187
|
+
let { strategy = this.storefront.CacheShort(), ...reqInit } = options;
|
|
188
|
+
let res = this.withCache(cacheKey, strategy, async () => {
|
|
189
|
+
let response = await fetch(url, reqInit);
|
|
190
|
+
if (!response.ok) {
|
|
191
|
+
throw new Error("Something went wrong. Skipping cache.");
|
|
192
|
+
}
|
|
193
|
+
return await response.json();
|
|
194
|
+
});
|
|
195
|
+
return res;
|
|
196
|
+
};
|
|
197
|
+
loadThemeSettings = async (strategy) => {
|
|
198
|
+
try {
|
|
170
199
|
let { API, configs } = this;
|
|
171
200
|
let { weaverseHost, projectId } = configs;
|
|
201
|
+
if (!projectId) {
|
|
202
|
+
throw new Error("Missing Weaverse projectId!");
|
|
203
|
+
}
|
|
172
204
|
let res = await this.fetchWithCache(
|
|
173
205
|
`${weaverseHost}/${API}/${projectId}/configs`,
|
|
174
206
|
{ strategy }
|
|
@@ -186,109 +218,96 @@ var WeaverseClient = class {
|
|
|
186
218
|
}
|
|
187
219
|
}
|
|
188
220
|
return data;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
};
|
|
200
|
-
let reqInit = {
|
|
201
|
-
method: "POST",
|
|
202
|
-
body: JSON.stringify(body)
|
|
203
|
-
};
|
|
204
|
-
let url = `${this.configs.weaverseHost}/${this.API}`;
|
|
205
|
-
let payload;
|
|
206
|
-
if (this.configs.isDesignMode) {
|
|
207
|
-
payload = await fetch(url, reqInit).then((res) => res.json());
|
|
208
|
-
} else {
|
|
209
|
-
payload = await this.fetchWithCache(url, {
|
|
210
|
-
...reqInit,
|
|
211
|
-
strategy
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
let { page, project, pageAssignment } = payload;
|
|
215
|
-
if (!page || !project || !pageAssignment) {
|
|
216
|
-
return reject(
|
|
217
|
-
new Error(
|
|
218
|
-
// @ts-ignore
|
|
219
|
-
payload?.error || "Invalid Weaverse project payload!"
|
|
220
|
-
)
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
if (page?.items) {
|
|
224
|
-
let items = page.items;
|
|
225
|
-
page.items = await Promise.all(
|
|
226
|
-
items.map((item) => this.execComponentLoader(item, args))
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
let data = {
|
|
230
|
-
page,
|
|
231
|
-
project,
|
|
232
|
-
pageAssignment,
|
|
233
|
-
configs: {
|
|
234
|
-
...this.basePageConfigs,
|
|
235
|
-
requestInfo: {
|
|
236
|
-
params,
|
|
237
|
-
i18n: this.storefront.i18n,
|
|
238
|
-
queries: getRequestQueries(request),
|
|
239
|
-
pathname: new URL(request.url).pathname,
|
|
240
|
-
search: new URL(request.url).search
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
return resolve(data);
|
|
245
|
-
} catch (err) {
|
|
246
|
-
console.log(`\u274C [Weaverse page]`, err);
|
|
247
|
-
reject(err);
|
|
221
|
+
} catch (err) {
|
|
222
|
+
console.log(`\u274C [Weaverse theme settings]`, err);
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
loadPage = async (args, configs = {}) => {
|
|
227
|
+
return new Promise(async (resolve, reject) => {
|
|
228
|
+
try {
|
|
229
|
+
if (!this.configs.projectId) {
|
|
230
|
+
reject(new Error("Missing Weaverse projectId!"));
|
|
248
231
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
232
|
+
let { request, params } = args;
|
|
233
|
+
let { strategy, ...pageLoadParams } = configs;
|
|
234
|
+
let body = {
|
|
235
|
+
...this.basePageRequestBody,
|
|
236
|
+
params: pageLoadParams,
|
|
237
|
+
url: request.url
|
|
238
|
+
};
|
|
239
|
+
let reqInit = {
|
|
240
|
+
method: "POST",
|
|
241
|
+
body: JSON.stringify(body)
|
|
242
|
+
};
|
|
243
|
+
let url = `${this.configs.weaverseHost}/${this.API}`;
|
|
244
|
+
let payload;
|
|
245
|
+
if (this.configs.isDesignMode) {
|
|
246
|
+
payload = await fetch(url, reqInit).then((res) => res.json());
|
|
247
|
+
} else {
|
|
248
|
+
payload = await this.fetchWithCache(url, {
|
|
249
|
+
...reqInit,
|
|
250
|
+
strategy
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
let { page, project, pageAssignment } = payload;
|
|
254
|
+
if (!page || !project || !pageAssignment) {
|
|
255
|
+
return reject(
|
|
256
|
+
new Error(
|
|
257
|
+
// @ts-ignore
|
|
258
|
+
payload?.error || "Invalid Weaverse project payload!"
|
|
259
|
+
)
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
if (page?.items) {
|
|
263
|
+
let items = page.items;
|
|
264
|
+
page.items = await Promise.all(
|
|
265
|
+
items.map((item) => this.execComponentLoader(item, args))
|
|
266
|
+
);
|
|
268
267
|
}
|
|
268
|
+
let data = {
|
|
269
|
+
page,
|
|
270
|
+
project,
|
|
271
|
+
pageAssignment,
|
|
272
|
+
configs: {
|
|
273
|
+
...this.basePageConfigs,
|
|
274
|
+
requestInfo: {
|
|
275
|
+
params,
|
|
276
|
+
i18n: this.storefront.i18n,
|
|
277
|
+
queries: getRequestQueries(request),
|
|
278
|
+
pathname: new URL(request.url).pathname,
|
|
279
|
+
search: new URL(request.url).search
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
return resolve(data);
|
|
284
|
+
} catch (err) {
|
|
285
|
+
console.log(`\u274C [Weaverse page]`, err);
|
|
286
|
+
reject(err);
|
|
269
287
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
execComponentLoader = async (item, args) => {
|
|
291
|
+
let schema = this.components.find(
|
|
292
|
+
({ schema: schema2 }) => schema2?.type === item.type
|
|
293
|
+
);
|
|
294
|
+
let { loader } = schema || {};
|
|
295
|
+
if (loader && typeof loader === "function") {
|
|
296
|
+
try {
|
|
297
|
+
return {
|
|
298
|
+
...item,
|
|
299
|
+
loaderData: await loader({
|
|
300
|
+
itemData: item,
|
|
301
|
+
...args
|
|
302
|
+
})
|
|
303
|
+
};
|
|
304
|
+
} catch (err) {
|
|
305
|
+
console.log(`\u274C [Weaverse item loader]`, item.id, err);
|
|
306
|
+
return item;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return item;
|
|
310
|
+
};
|
|
292
311
|
};
|
|
293
312
|
|
|
294
313
|
// src/hooks/use-theme-settings.ts
|
|
@@ -352,36 +371,39 @@ function useThemeContext() {
|
|
|
352
371
|
|
|
353
372
|
// src/hooks/use-theme-settings.ts
|
|
354
373
|
var ThemeSettingsStore = class {
|
|
374
|
+
settings = null;
|
|
375
|
+
listeners = [];
|
|
376
|
+
countries;
|
|
377
|
+
schema;
|
|
378
|
+
publicEnv;
|
|
355
379
|
constructor(data) {
|
|
356
|
-
this.settings = null;
|
|
357
|
-
this.listeners = [];
|
|
358
|
-
this.updateThemeSettings = (newSettings) => {
|
|
359
|
-
this.settings = { ...this.settings, ...newSettings };
|
|
360
|
-
this.emitChange();
|
|
361
|
-
};
|
|
362
|
-
this.subscribe = (listener) => {
|
|
363
|
-
this.listeners = [...this.listeners, listener];
|
|
364
|
-
return () => {
|
|
365
|
-
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
366
|
-
};
|
|
367
|
-
};
|
|
368
|
-
this.getSnapshot = () => {
|
|
369
|
-
return this.settings;
|
|
370
|
-
};
|
|
371
|
-
this.getServerSnapshot = () => {
|
|
372
|
-
return this.settings;
|
|
373
|
-
};
|
|
374
|
-
this.emitChange = () => {
|
|
375
|
-
for (let listener of this.listeners) {
|
|
376
|
-
listener();
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
380
|
let { theme, countries, schema, publicEnv } = data || {};
|
|
380
381
|
this.settings = theme || null;
|
|
381
382
|
this.countries = countries;
|
|
382
383
|
this.schema = schema;
|
|
383
384
|
this.publicEnv = publicEnv;
|
|
384
385
|
}
|
|
386
|
+
updateThemeSettings = (newSettings) => {
|
|
387
|
+
this.settings = { ...this.settings, ...newSettings };
|
|
388
|
+
this.emitChange();
|
|
389
|
+
};
|
|
390
|
+
subscribe = (listener) => {
|
|
391
|
+
this.listeners = [...this.listeners, listener];
|
|
392
|
+
return () => {
|
|
393
|
+
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
getSnapshot = () => {
|
|
397
|
+
return this.settings;
|
|
398
|
+
};
|
|
399
|
+
getServerSnapshot = () => {
|
|
400
|
+
return this.settings;
|
|
401
|
+
};
|
|
402
|
+
emitChange = () => {
|
|
403
|
+
for (let listener of this.listeners) {
|
|
404
|
+
listener();
|
|
405
|
+
}
|
|
406
|
+
};
|
|
385
407
|
};
|
|
386
408
|
function useThemeSettings() {
|
|
387
409
|
let themeSettingsStore = useThemeContext();
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import "@shopify/hydrogen";
|
|
|
6
6
|
|
|
7
7
|
// package.json
|
|
8
8
|
var package_default = {
|
|
9
|
-
version: "1.3.
|
|
9
|
+
version: "1.3.3",
|
|
10
10
|
license: "MIT",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
typings: "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@ var package_default = {
|
|
|
18
18
|
"dist/*"
|
|
19
19
|
],
|
|
20
20
|
engines: {
|
|
21
|
-
node: ">=
|
|
21
|
+
node: ">=16"
|
|
22
22
|
},
|
|
23
23
|
scripts: {
|
|
24
24
|
start: "npm run dev",
|
|
@@ -41,7 +41,7 @@ var package_default = {
|
|
|
41
41
|
dependencies: {
|
|
42
42
|
"@remix-run/react": "1.19.1",
|
|
43
43
|
"@shopify/hydrogen": "2023.7.8",
|
|
44
|
-
"@weaverse/react": "1.3.
|
|
44
|
+
"@weaverse/react": "1.3.3",
|
|
45
45
|
"react-error-boundary": "^4.0.11"
|
|
46
46
|
},
|
|
47
47
|
devDependencies: {
|
|
@@ -107,24 +107,56 @@ function getWeaverseCsp(request) {
|
|
|
107
107
|
|
|
108
108
|
// src/client.ts
|
|
109
109
|
var WeaverseClient = class {
|
|
110
|
+
API = "api/public/project";
|
|
111
|
+
clientVersion = package_default.version;
|
|
112
|
+
storefront;
|
|
113
|
+
components;
|
|
114
|
+
countries;
|
|
115
|
+
themeSchema;
|
|
116
|
+
configs;
|
|
117
|
+
basePageConfigs;
|
|
118
|
+
basePageRequestBody;
|
|
119
|
+
withCache;
|
|
110
120
|
constructor(args) {
|
|
111
|
-
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
let { configs, storefront, components, countries, withCache, themeSchema } = args;
|
|
122
|
+
this.storefront = storefront;
|
|
123
|
+
this.components = components;
|
|
124
|
+
this.countries = countries;
|
|
125
|
+
this.themeSchema = themeSchema;
|
|
126
|
+
this.configs = configs;
|
|
127
|
+
this.withCache = withCache;
|
|
128
|
+
this.basePageConfigs = {
|
|
129
|
+
projectId: configs.projectId,
|
|
130
|
+
weaverseHost: configs.weaverseHost,
|
|
131
|
+
weaverseVersion: configs.weaverseVersion,
|
|
132
|
+
isDesignMode: configs.isDesignMode
|
|
133
|
+
};
|
|
134
|
+
this.basePageRequestBody = {
|
|
135
|
+
countries,
|
|
136
|
+
isDesignMode: this.configs.isDesignMode,
|
|
137
|
+
i18n: storefront.i18n,
|
|
138
|
+
projectId: this.configs.projectId
|
|
124
139
|
};
|
|
125
|
-
|
|
140
|
+
}
|
|
141
|
+
fetchWithCache = (url, options) => {
|
|
142
|
+
let cacheKey = [url, options.body];
|
|
143
|
+
let { strategy = this.storefront.CacheShort(), ...reqInit } = options;
|
|
144
|
+
let res = this.withCache(cacheKey, strategy, async () => {
|
|
145
|
+
let response = await fetch(url, reqInit);
|
|
146
|
+
if (!response.ok) {
|
|
147
|
+
throw new Error("Something went wrong. Skipping cache.");
|
|
148
|
+
}
|
|
149
|
+
return await response.json();
|
|
150
|
+
});
|
|
151
|
+
return res;
|
|
152
|
+
};
|
|
153
|
+
loadThemeSettings = async (strategy) => {
|
|
154
|
+
try {
|
|
126
155
|
let { API, configs } = this;
|
|
127
156
|
let { weaverseHost, projectId } = configs;
|
|
157
|
+
if (!projectId) {
|
|
158
|
+
throw new Error("Missing Weaverse projectId!");
|
|
159
|
+
}
|
|
128
160
|
let res = await this.fetchWithCache(
|
|
129
161
|
`${weaverseHost}/${API}/${projectId}/configs`,
|
|
130
162
|
{ strategy }
|
|
@@ -142,109 +174,96 @@ var WeaverseClient = class {
|
|
|
142
174
|
}
|
|
143
175
|
}
|
|
144
176
|
return data;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
};
|
|
156
|
-
let reqInit = {
|
|
157
|
-
method: "POST",
|
|
158
|
-
body: JSON.stringify(body)
|
|
159
|
-
};
|
|
160
|
-
let url = `${this.configs.weaverseHost}/${this.API}`;
|
|
161
|
-
let payload;
|
|
162
|
-
if (this.configs.isDesignMode) {
|
|
163
|
-
payload = await fetch(url, reqInit).then((res) => res.json());
|
|
164
|
-
} else {
|
|
165
|
-
payload = await this.fetchWithCache(url, {
|
|
166
|
-
...reqInit,
|
|
167
|
-
strategy
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
let { page, project, pageAssignment } = payload;
|
|
171
|
-
if (!page || !project || !pageAssignment) {
|
|
172
|
-
return reject(
|
|
173
|
-
new Error(
|
|
174
|
-
// @ts-ignore
|
|
175
|
-
payload?.error || "Invalid Weaverse project payload!"
|
|
176
|
-
)
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
if (page?.items) {
|
|
180
|
-
let items = page.items;
|
|
181
|
-
page.items = await Promise.all(
|
|
182
|
-
items.map((item) => this.execComponentLoader(item, args))
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
let data = {
|
|
186
|
-
page,
|
|
187
|
-
project,
|
|
188
|
-
pageAssignment,
|
|
189
|
-
configs: {
|
|
190
|
-
...this.basePageConfigs,
|
|
191
|
-
requestInfo: {
|
|
192
|
-
params,
|
|
193
|
-
i18n: this.storefront.i18n,
|
|
194
|
-
queries: getRequestQueries(request),
|
|
195
|
-
pathname: new URL(request.url).pathname,
|
|
196
|
-
search: new URL(request.url).search
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
return resolve(data);
|
|
201
|
-
} catch (err) {
|
|
202
|
-
console.log(`\u274C [Weaverse page]`, err);
|
|
203
|
-
reject(err);
|
|
177
|
+
} catch (err) {
|
|
178
|
+
console.log(`\u274C [Weaverse theme settings]`, err);
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
loadPage = async (args, configs = {}) => {
|
|
183
|
+
return new Promise(async (resolve, reject) => {
|
|
184
|
+
try {
|
|
185
|
+
if (!this.configs.projectId) {
|
|
186
|
+
reject(new Error("Missing Weaverse projectId!"));
|
|
204
187
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
188
|
+
let { request, params } = args;
|
|
189
|
+
let { strategy, ...pageLoadParams } = configs;
|
|
190
|
+
let body = {
|
|
191
|
+
...this.basePageRequestBody,
|
|
192
|
+
params: pageLoadParams,
|
|
193
|
+
url: request.url
|
|
194
|
+
};
|
|
195
|
+
let reqInit = {
|
|
196
|
+
method: "POST",
|
|
197
|
+
body: JSON.stringify(body)
|
|
198
|
+
};
|
|
199
|
+
let url = `${this.configs.weaverseHost}/${this.API}`;
|
|
200
|
+
let payload;
|
|
201
|
+
if (this.configs.isDesignMode) {
|
|
202
|
+
payload = await fetch(url, reqInit).then((res) => res.json());
|
|
203
|
+
} else {
|
|
204
|
+
payload = await this.fetchWithCache(url, {
|
|
205
|
+
...reqInit,
|
|
206
|
+
strategy
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
let { page, project, pageAssignment } = payload;
|
|
210
|
+
if (!page || !project || !pageAssignment) {
|
|
211
|
+
return reject(
|
|
212
|
+
new Error(
|
|
213
|
+
// @ts-ignore
|
|
214
|
+
payload?.error || "Invalid Weaverse project payload!"
|
|
215
|
+
)
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
if (page?.items) {
|
|
219
|
+
let items = page.items;
|
|
220
|
+
page.items = await Promise.all(
|
|
221
|
+
items.map((item) => this.execComponentLoader(item, args))
|
|
222
|
+
);
|
|
224
223
|
}
|
|
224
|
+
let data = {
|
|
225
|
+
page,
|
|
226
|
+
project,
|
|
227
|
+
pageAssignment,
|
|
228
|
+
configs: {
|
|
229
|
+
...this.basePageConfigs,
|
|
230
|
+
requestInfo: {
|
|
231
|
+
params,
|
|
232
|
+
i18n: this.storefront.i18n,
|
|
233
|
+
queries: getRequestQueries(request),
|
|
234
|
+
pathname: new URL(request.url).pathname,
|
|
235
|
+
search: new URL(request.url).search
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return resolve(data);
|
|
240
|
+
} catch (err) {
|
|
241
|
+
console.log(`\u274C [Weaverse page]`, err);
|
|
242
|
+
reject(err);
|
|
225
243
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
execComponentLoader = async (item, args) => {
|
|
247
|
+
let schema = this.components.find(
|
|
248
|
+
({ schema: schema2 }) => schema2?.type === item.type
|
|
249
|
+
);
|
|
250
|
+
let { loader } = schema || {};
|
|
251
|
+
if (loader && typeof loader === "function") {
|
|
252
|
+
try {
|
|
253
|
+
return {
|
|
254
|
+
...item,
|
|
255
|
+
loaderData: await loader({
|
|
256
|
+
itemData: item,
|
|
257
|
+
...args
|
|
258
|
+
})
|
|
259
|
+
};
|
|
260
|
+
} catch (err) {
|
|
261
|
+
console.log(`\u274C [Weaverse item loader]`, item.id, err);
|
|
262
|
+
return item;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return item;
|
|
266
|
+
};
|
|
248
267
|
};
|
|
249
268
|
|
|
250
269
|
// src/hooks/use-theme-settings.ts
|
|
@@ -308,36 +327,39 @@ function useThemeContext() {
|
|
|
308
327
|
|
|
309
328
|
// src/hooks/use-theme-settings.ts
|
|
310
329
|
var ThemeSettingsStore = class {
|
|
330
|
+
settings = null;
|
|
331
|
+
listeners = [];
|
|
332
|
+
countries;
|
|
333
|
+
schema;
|
|
334
|
+
publicEnv;
|
|
311
335
|
constructor(data) {
|
|
312
|
-
this.settings = null;
|
|
313
|
-
this.listeners = [];
|
|
314
|
-
this.updateThemeSettings = (newSettings) => {
|
|
315
|
-
this.settings = { ...this.settings, ...newSettings };
|
|
316
|
-
this.emitChange();
|
|
317
|
-
};
|
|
318
|
-
this.subscribe = (listener) => {
|
|
319
|
-
this.listeners = [...this.listeners, listener];
|
|
320
|
-
return () => {
|
|
321
|
-
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
322
|
-
};
|
|
323
|
-
};
|
|
324
|
-
this.getSnapshot = () => {
|
|
325
|
-
return this.settings;
|
|
326
|
-
};
|
|
327
|
-
this.getServerSnapshot = () => {
|
|
328
|
-
return this.settings;
|
|
329
|
-
};
|
|
330
|
-
this.emitChange = () => {
|
|
331
|
-
for (let listener of this.listeners) {
|
|
332
|
-
listener();
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
336
|
let { theme, countries, schema, publicEnv } = data || {};
|
|
336
337
|
this.settings = theme || null;
|
|
337
338
|
this.countries = countries;
|
|
338
339
|
this.schema = schema;
|
|
339
340
|
this.publicEnv = publicEnv;
|
|
340
341
|
}
|
|
342
|
+
updateThemeSettings = (newSettings) => {
|
|
343
|
+
this.settings = { ...this.settings, ...newSettings };
|
|
344
|
+
this.emitChange();
|
|
345
|
+
};
|
|
346
|
+
subscribe = (listener) => {
|
|
347
|
+
this.listeners = [...this.listeners, listener];
|
|
348
|
+
return () => {
|
|
349
|
+
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
getSnapshot = () => {
|
|
353
|
+
return this.settings;
|
|
354
|
+
};
|
|
355
|
+
getServerSnapshot = () => {
|
|
356
|
+
return this.settings;
|
|
357
|
+
};
|
|
358
|
+
emitChange = () => {
|
|
359
|
+
for (let listener of this.listeners) {
|
|
360
|
+
listener();
|
|
361
|
+
}
|
|
362
|
+
};
|
|
341
363
|
};
|
|
342
364
|
function useThemeSettings() {
|
|
343
365
|
let themeSettingsStore = useThemeContext();
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.3",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dist/*"
|
|
12
12
|
],
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
14
|
+
"node": ">=16"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"start": "npm run dev",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@remix-run/react": "1.19.1",
|
|
36
36
|
"@shopify/hydrogen": "2023.7.8",
|
|
37
|
-
"@weaverse/react": "1.3.
|
|
37
|
+
"@weaverse/react": "1.3.3",
|
|
38
38
|
"react-error-boundary": "^4.0.11"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|