@weaverse/core 0.7.71 → 1.0.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.ts +27 -28
- package/dist/index.js +42 -41
- package/dist/index.mjs +42 -41
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as Stitches from '@stitches/core';
|
|
|
2
2
|
import { ForwardRefExoticComponent, RefObject } from 'react';
|
|
3
3
|
import Stitches$1 from '@stitches/core/types/stitches';
|
|
4
4
|
|
|
5
|
-
declare let
|
|
5
|
+
declare let stitchesUtils: {
|
|
6
6
|
m: (value: string) => {
|
|
7
7
|
margin: string;
|
|
8
8
|
};
|
|
@@ -40,7 +40,7 @@ declare let stichesUtils: {
|
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
interface
|
|
43
|
+
interface WeaverseProjectDataType {
|
|
44
44
|
items: ElementData[];
|
|
45
45
|
rootId: string;
|
|
46
46
|
script: {
|
|
@@ -53,13 +53,16 @@ interface BreakPoints {
|
|
|
53
53
|
mobile: string;
|
|
54
54
|
desktop: string;
|
|
55
55
|
}
|
|
56
|
+
type PlatformTypeEnum = "shopify-section" | "react-ssr";
|
|
56
57
|
interface WeaverseType {
|
|
57
58
|
mediaBreakPoints?: BreakPoints;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
weaverseHost?: string;
|
|
60
|
+
projectId?: string;
|
|
61
|
+
data?: WeaverseProjectDataType;
|
|
61
62
|
isDesignMode?: boolean;
|
|
62
63
|
ssrMode?: boolean;
|
|
64
|
+
elementSchemas?: ElementSchema[];
|
|
65
|
+
platformType?: PlatformTypeEnum;
|
|
63
66
|
}
|
|
64
67
|
interface WeaverseElement {
|
|
65
68
|
Component: ForwardRefExoticComponent<any>;
|
|
@@ -109,7 +112,7 @@ interface ElementData {
|
|
|
109
112
|
css?: ElementCSS;
|
|
110
113
|
[key: string]: any;
|
|
111
114
|
}
|
|
112
|
-
type WeaverseCSSProperties = Stitches.CSS & Partial<Record<keyof typeof
|
|
115
|
+
type WeaverseCSSProperties = Stitches.CSS & Partial<Record<keyof typeof stitchesUtils, string | number>>;
|
|
113
116
|
type ChildElementCSS = Partial<{
|
|
114
117
|
[selector: string]: WeaverseCSSProperties & ChildElementCSS;
|
|
115
118
|
}>;
|
|
@@ -250,17 +253,17 @@ declare class Weaverse {
|
|
|
250
253
|
* Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
|
|
251
254
|
* @type {string}
|
|
252
255
|
*/
|
|
253
|
-
|
|
256
|
+
weaverseHost: string;
|
|
254
257
|
/**
|
|
255
258
|
* Weaverse project key to access project data via API
|
|
256
259
|
* @type {string}
|
|
257
260
|
*/
|
|
258
|
-
|
|
261
|
+
projectId: string;
|
|
259
262
|
/**
|
|
260
263
|
* Weaverse project data, by default, user can provide project data via React Component:
|
|
261
|
-
* <WeaverseRoot
|
|
264
|
+
* <WeaverseRoot data={data} /> it will be used to server-side rendering
|
|
262
265
|
*/
|
|
263
|
-
|
|
266
|
+
data: WeaverseProjectDataType;
|
|
264
267
|
/**
|
|
265
268
|
* Storing subscribe callback function for any component that want to listen to the change of WeaverseRoot
|
|
266
269
|
* @type {Map<string, (data: any) => void>}
|
|
@@ -273,6 +276,10 @@ declare class Weaverse {
|
|
|
273
276
|
* @type {boolean}
|
|
274
277
|
*/
|
|
275
278
|
isDesignMode: boolean;
|
|
279
|
+
/**
|
|
280
|
+
* Check the platform, shopify-section or react-ssr(hydrogen)
|
|
281
|
+
*/
|
|
282
|
+
platformType: PlatformTypeEnum;
|
|
276
283
|
/**
|
|
277
284
|
* Check whether the sdk is in preview mode or not
|
|
278
285
|
* @type {boolean}
|
|
@@ -288,19 +295,22 @@ declare class Weaverse {
|
|
|
288
295
|
*/
|
|
289
296
|
stitchesInstance: Stitches$1 | any;
|
|
290
297
|
studioBridge?: any;
|
|
298
|
+
elementSchemas?: ElementSchema[];
|
|
291
299
|
static WeaverseItemStore: typeof WeaverseItemStore;
|
|
292
300
|
mediaBreakPoints: BreakPoints;
|
|
293
301
|
/**
|
|
294
302
|
* constructor
|
|
295
|
-
* @param
|
|
296
|
-
* @param
|
|
297
|
-
* @param
|
|
303
|
+
* @param weaverseHost {string} Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
|
|
304
|
+
* @param projectId {string} Weaverse project key to access project data via API
|
|
305
|
+
* @param data {WeaverseProjectDataType} Weaverse project data, by default, user can provide project data via React Component.
|
|
298
306
|
* @param mediaBreakPoints {object} Pass down custom media query breakpoints or just use the default.
|
|
299
307
|
* @param isDesignMode {boolean} check whether the sdk is isDesignMode or not
|
|
300
308
|
* @param ssrMode {boolean} Use in element to optionally render special HTML for hydration
|
|
309
|
+
* @param elementSchemas {Array<ElementSchema>} List of element schemas
|
|
310
|
+
* @param platformType {PlatformTypeEnum} Check the platform, shopify-section or react-ssr(hydrogen)
|
|
301
311
|
*/
|
|
302
|
-
constructor({
|
|
303
|
-
init({
|
|
312
|
+
constructor({ weaverseHost, projectId, data, mediaBreakPoints, isDesignMode, ssrMode, elementSchemas, platformType }?: WeaverseType);
|
|
313
|
+
init({ weaverseHost, elementSchemas, platformType, projectId, data, mediaBreakPoints, isDesignMode, ssrMode }?: WeaverseType): void;
|
|
304
314
|
initialized: boolean;
|
|
305
315
|
initializeData: (data: any) => void;
|
|
306
316
|
loadStudio(version?: string): void;
|
|
@@ -313,18 +323,7 @@ declare class Weaverse {
|
|
|
313
323
|
subscribe(fn: any): void;
|
|
314
324
|
unsubscribe(fn: any): void;
|
|
315
325
|
triggerUpdate(): void;
|
|
316
|
-
|
|
317
|
-
* Fetch data from Weaverse API (https://weaverse.io/api/v1/project/:projectKey)
|
|
318
|
-
* @param fetch {fetch} custom fetch function, pass in custom fetch function if you want to use your own fetch function
|
|
319
|
-
* @param appUrl
|
|
320
|
-
* @param projectKey
|
|
321
|
-
*/
|
|
322
|
-
static fetchProjectData({ fetch, appUrl, projectKey, }: {
|
|
323
|
-
fetch?: any;
|
|
324
|
-
appUrl?: string;
|
|
325
|
-
projectKey?: string;
|
|
326
|
-
}): any;
|
|
327
|
-
setProjectData(projectData: ProjectDataType): void;
|
|
326
|
+
setProjectData(data: WeaverseProjectDataType): void;
|
|
328
327
|
initProjectItemData(): void;
|
|
329
328
|
}
|
|
330
329
|
|
|
@@ -340,4 +339,4 @@ declare function merge(target: Record<string, any>, source: Record<string, any>)
|
|
|
340
339
|
[x: string]: any;
|
|
341
340
|
};
|
|
342
341
|
|
|
343
|
-
export { AdditionalInputConfigs, AdvancedGroup, AdvancedGroupType, BasicGroup, BasicInput, BreakPoints, CatalogGroup, ChildElement, ChildElementCSS, ChildElementSelector, ElementCSS, ElementCatalog, ElementData, ElementDataInCatalog, ElementFlags, ElementInspector, ElementSchema, FlagType, GridSize, InputType, ParentType,
|
|
342
|
+
export { AdditionalInputConfigs, AdvancedGroup, AdvancedGroupType, BasicGroup, BasicInput, BreakPoints, CatalogGroup, ChildElement, ChildElementCSS, ChildElementSelector, ElementCSS, ElementCatalog, ElementData, ElementDataInCatalog, ElementFlags, ElementInspector, ElementSchema, FlagType, GridSize, InputType, ParentType, PlatformTypeEnum, RangeInputConfigs, SelectInputConfigs, SortableInputConfigs, SortableItemAction, ToggleGroupConfigs, ToolbarAction, Weaverse, WeaverseCSSProperties, WeaverseElement, WeaverseItemStore, WeaverseProjectDataType, WeaverseType, isBrowser, isIframe, isReactNative, merge };
|
package/dist/index.js
CHANGED
|
@@ -58,7 +58,7 @@ function merge(target, source) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// src/utils/styles.ts
|
|
61
|
-
var
|
|
61
|
+
var stitchesUtils = {
|
|
62
62
|
// Abbreviated margin properties
|
|
63
63
|
m: (value) => ({
|
|
64
64
|
margin: value
|
|
@@ -155,14 +155,25 @@ var WeaverseItemStore = class {
|
|
|
155
155
|
var Weaverse = class {
|
|
156
156
|
/**
|
|
157
157
|
* constructor
|
|
158
|
-
* @param
|
|
159
|
-
* @param
|
|
160
|
-
* @param
|
|
158
|
+
* @param weaverseHost {string} Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
|
|
159
|
+
* @param projectId {string} Weaverse project key to access project data via API
|
|
160
|
+
* @param data {WeaverseProjectDataType} Weaverse project data, by default, user can provide project data via React Component.
|
|
161
161
|
* @param mediaBreakPoints {object} Pass down custom media query breakpoints or just use the default.
|
|
162
162
|
* @param isDesignMode {boolean} check whether the sdk is isDesignMode or not
|
|
163
163
|
* @param ssrMode {boolean} Use in element to optionally render special HTML for hydration
|
|
164
|
+
* @param elementSchemas {Array<ElementSchema>} List of element schemas
|
|
165
|
+
* @param platformType {PlatformTypeEnum} Check the platform, shopify-section or react-ssr(hydrogen)
|
|
164
166
|
*/
|
|
165
|
-
constructor({
|
|
167
|
+
constructor({
|
|
168
|
+
weaverseHost,
|
|
169
|
+
projectId,
|
|
170
|
+
data,
|
|
171
|
+
mediaBreakPoints,
|
|
172
|
+
isDesignMode,
|
|
173
|
+
ssrMode,
|
|
174
|
+
elementSchemas,
|
|
175
|
+
platformType
|
|
176
|
+
} = {}) {
|
|
166
177
|
/**
|
|
167
178
|
* For storing, registering element React component from Weaverse or created by user/developer
|
|
168
179
|
*/
|
|
@@ -175,17 +186,17 @@ var Weaverse = class {
|
|
|
175
186
|
* Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
|
|
176
187
|
* @type {string}
|
|
177
188
|
*/
|
|
178
|
-
this.
|
|
189
|
+
this.weaverseHost = process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://studio.weaverse.io";
|
|
179
190
|
/**
|
|
180
191
|
* Weaverse project key to access project data via API
|
|
181
192
|
* @type {string}
|
|
182
193
|
*/
|
|
183
|
-
this.
|
|
194
|
+
this.projectId = "";
|
|
184
195
|
/**
|
|
185
196
|
* Weaverse project data, by default, user can provide project data via React Component:
|
|
186
|
-
* <WeaverseRoot
|
|
197
|
+
* <WeaverseRoot data={data} /> it will be used to server-side rendering
|
|
187
198
|
*/
|
|
188
|
-
this.
|
|
199
|
+
this.data = {
|
|
189
200
|
rootId: "",
|
|
190
201
|
items: [],
|
|
191
202
|
script: { css: "", js: "" }
|
|
@@ -202,6 +213,10 @@ var Weaverse = class {
|
|
|
202
213
|
* @type {boolean}
|
|
203
214
|
*/
|
|
204
215
|
this.isDesignMode = false;
|
|
216
|
+
/**
|
|
217
|
+
* Check the platform, shopify-section or react-ssr(hydrogen)
|
|
218
|
+
*/
|
|
219
|
+
this.platformType = "shopify-section";
|
|
205
220
|
/**
|
|
206
221
|
* Check whether the sdk is in preview mode or not
|
|
207
222
|
* @type {boolean}
|
|
@@ -221,14 +236,13 @@ var Weaverse = class {
|
|
|
221
236
|
this.initialized = false;
|
|
222
237
|
this.initializeData = (data) => {
|
|
223
238
|
if (!this.initialized) {
|
|
224
|
-
let {
|
|
225
|
-
this.
|
|
226
|
-
this.
|
|
227
|
-
this.
|
|
228
|
-
this.isDesignMode =
|
|
239
|
+
let { data: d, isDesignMode, id, projectId, weaverseHost } = data;
|
|
240
|
+
this.projectId = projectId || this.projectId;
|
|
241
|
+
this.weaverseHost = weaverseHost || this.weaverseHost;
|
|
242
|
+
this.data = { ...d, pageId: id };
|
|
243
|
+
this.isDesignMode = isDesignMode;
|
|
229
244
|
this.initProjectItemData();
|
|
230
245
|
if (this.isDesignMode) {
|
|
231
|
-
this.initStitches();
|
|
232
246
|
this.triggerUpdate();
|
|
233
247
|
this.loadStudio();
|
|
234
248
|
}
|
|
@@ -239,34 +253,34 @@ var Weaverse = class {
|
|
|
239
253
|
this.stitchesInstance = this.stitchesInstance || stitches.createStitches({
|
|
240
254
|
prefix: "weaverse",
|
|
241
255
|
media: this.mediaBreakPoints,
|
|
242
|
-
utils:
|
|
256
|
+
utils: stitchesUtils
|
|
243
257
|
});
|
|
244
258
|
};
|
|
245
|
-
this.init({
|
|
259
|
+
this.init({ weaverseHost, projectId, data, platformType, mediaBreakPoints, isDesignMode, ssrMode, elementSchemas });
|
|
246
260
|
}
|
|
247
|
-
init({
|
|
248
|
-
this.
|
|
249
|
-
this.
|
|
261
|
+
init({ weaverseHost, elementSchemas, platformType, projectId, data, mediaBreakPoints, isDesignMode, ssrMode } = {}) {
|
|
262
|
+
this.elementSchemas = elementSchemas || this.elementSchemas;
|
|
263
|
+
this.weaverseHost = weaverseHost || this.weaverseHost;
|
|
264
|
+
this.projectId = projectId || this.projectId;
|
|
250
265
|
this.mediaBreakPoints = mediaBreakPoints || this.mediaBreakPoints;
|
|
251
266
|
this.isDesignMode = isDesignMode || this.isDesignMode;
|
|
252
267
|
this.ssrMode = ssrMode || this.ssrMode;
|
|
253
|
-
this.
|
|
254
|
-
this.
|
|
268
|
+
this.platformType = platformType || this.platformType;
|
|
269
|
+
this.data = data || this.data;
|
|
255
270
|
this.initProjectItemData();
|
|
271
|
+
this.initStitches();
|
|
256
272
|
}
|
|
257
273
|
loadStudio(version) {
|
|
258
|
-
console.log("load studio");
|
|
259
274
|
if (isIframe && this.isDesignMode && !this.studioBridge) {
|
|
260
275
|
const initStudio = () => {
|
|
261
276
|
this.studioBridge = new window.WeaverseStudioBridge(this);
|
|
262
277
|
this.triggerUpdate();
|
|
263
|
-
console.log("Studio loaded", this);
|
|
264
278
|
clearInterval(i);
|
|
265
279
|
};
|
|
266
280
|
let i = setInterval(() => {
|
|
267
281
|
if (!window.WeaverseStudioBridge) {
|
|
268
282
|
let studioBridgeScript = document.createElement("script");
|
|
269
|
-
studioBridgeScript.src = `${this.
|
|
283
|
+
studioBridgeScript.src = `${this.weaverseHost}/assets/studio/studio-bridge.js?v=${version}`;
|
|
270
284
|
studioBridgeScript.type = "module";
|
|
271
285
|
studioBridgeScript.onload = initStudio;
|
|
272
286
|
document.body.appendChild(studioBridgeScript);
|
|
@@ -299,26 +313,13 @@ var Weaverse = class {
|
|
|
299
313
|
triggerUpdate() {
|
|
300
314
|
this.listeners.forEach((fn) => fn());
|
|
301
315
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
* @param fetch {fetch} custom fetch function, pass in custom fetch function if you want to use your own fetch function
|
|
305
|
-
* @param appUrl
|
|
306
|
-
* @param projectKey
|
|
307
|
-
*/
|
|
308
|
-
static fetchProjectData({
|
|
309
|
-
fetch = globalThis.fetch,
|
|
310
|
-
appUrl,
|
|
311
|
-
projectKey
|
|
312
|
-
}) {
|
|
313
|
-
return fetch(appUrl + `/api/public/project/${projectKey}`).then((res) => res.json()).catch((err) => console.log("Error fetching project data:", err));
|
|
314
|
-
}
|
|
315
|
-
setProjectData(projectData) {
|
|
316
|
-
this.projectData = projectData;
|
|
316
|
+
setProjectData(data) {
|
|
317
|
+
this.data = data;
|
|
317
318
|
this.initProjectItemData();
|
|
318
319
|
this.triggerUpdate();
|
|
319
320
|
}
|
|
320
321
|
initProjectItemData() {
|
|
321
|
-
const data = this.
|
|
322
|
+
const data = this.data;
|
|
322
323
|
if (data?.items) {
|
|
323
324
|
data.items.forEach((item) => {
|
|
324
325
|
if (!this.itemInstances.get(item.id)) {
|
package/dist/index.mjs
CHANGED
|
@@ -17,7 +17,7 @@ function merge(target, source) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// src/utils/styles.ts
|
|
20
|
-
var
|
|
20
|
+
var stitchesUtils = {
|
|
21
21
|
// Abbreviated margin properties
|
|
22
22
|
m: (value) => ({
|
|
23
23
|
margin: value
|
|
@@ -114,14 +114,25 @@ var WeaverseItemStore = class {
|
|
|
114
114
|
var Weaverse = class {
|
|
115
115
|
/**
|
|
116
116
|
* constructor
|
|
117
|
-
* @param
|
|
118
|
-
* @param
|
|
119
|
-
* @param
|
|
117
|
+
* @param weaverseHost {string} Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
|
|
118
|
+
* @param projectId {string} Weaverse project key to access project data via API
|
|
119
|
+
* @param data {WeaverseProjectDataType} Weaverse project data, by default, user can provide project data via React Component.
|
|
120
120
|
* @param mediaBreakPoints {object} Pass down custom media query breakpoints or just use the default.
|
|
121
121
|
* @param isDesignMode {boolean} check whether the sdk is isDesignMode or not
|
|
122
122
|
* @param ssrMode {boolean} Use in element to optionally render special HTML for hydration
|
|
123
|
+
* @param elementSchemas {Array<ElementSchema>} List of element schemas
|
|
124
|
+
* @param platformType {PlatformTypeEnum} Check the platform, shopify-section or react-ssr(hydrogen)
|
|
123
125
|
*/
|
|
124
|
-
constructor({
|
|
126
|
+
constructor({
|
|
127
|
+
weaverseHost,
|
|
128
|
+
projectId,
|
|
129
|
+
data,
|
|
130
|
+
mediaBreakPoints,
|
|
131
|
+
isDesignMode,
|
|
132
|
+
ssrMode,
|
|
133
|
+
elementSchemas,
|
|
134
|
+
platformType
|
|
135
|
+
} = {}) {
|
|
125
136
|
/**
|
|
126
137
|
* For storing, registering element React component from Weaverse or created by user/developer
|
|
127
138
|
*/
|
|
@@ -134,17 +145,17 @@ var Weaverse = class {
|
|
|
134
145
|
* Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
|
|
135
146
|
* @type {string}
|
|
136
147
|
*/
|
|
137
|
-
this.
|
|
148
|
+
this.weaverseHost = process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://studio.weaverse.io";
|
|
138
149
|
/**
|
|
139
150
|
* Weaverse project key to access project data via API
|
|
140
151
|
* @type {string}
|
|
141
152
|
*/
|
|
142
|
-
this.
|
|
153
|
+
this.projectId = "";
|
|
143
154
|
/**
|
|
144
155
|
* Weaverse project data, by default, user can provide project data via React Component:
|
|
145
|
-
* <WeaverseRoot
|
|
156
|
+
* <WeaverseRoot data={data} /> it will be used to server-side rendering
|
|
146
157
|
*/
|
|
147
|
-
this.
|
|
158
|
+
this.data = {
|
|
148
159
|
rootId: "",
|
|
149
160
|
items: [],
|
|
150
161
|
script: { css: "", js: "" }
|
|
@@ -161,6 +172,10 @@ var Weaverse = class {
|
|
|
161
172
|
* @type {boolean}
|
|
162
173
|
*/
|
|
163
174
|
this.isDesignMode = false;
|
|
175
|
+
/**
|
|
176
|
+
* Check the platform, shopify-section or react-ssr(hydrogen)
|
|
177
|
+
*/
|
|
178
|
+
this.platformType = "shopify-section";
|
|
164
179
|
/**
|
|
165
180
|
* Check whether the sdk is in preview mode or not
|
|
166
181
|
* @type {boolean}
|
|
@@ -180,14 +195,13 @@ var Weaverse = class {
|
|
|
180
195
|
this.initialized = false;
|
|
181
196
|
this.initializeData = (data) => {
|
|
182
197
|
if (!this.initialized) {
|
|
183
|
-
let {
|
|
184
|
-
this.
|
|
185
|
-
this.
|
|
186
|
-
this.
|
|
187
|
-
this.isDesignMode =
|
|
198
|
+
let { data: d, isDesignMode, id, projectId, weaverseHost } = data;
|
|
199
|
+
this.projectId = projectId || this.projectId;
|
|
200
|
+
this.weaverseHost = weaverseHost || this.weaverseHost;
|
|
201
|
+
this.data = { ...d, pageId: id };
|
|
202
|
+
this.isDesignMode = isDesignMode;
|
|
188
203
|
this.initProjectItemData();
|
|
189
204
|
if (this.isDesignMode) {
|
|
190
|
-
this.initStitches();
|
|
191
205
|
this.triggerUpdate();
|
|
192
206
|
this.loadStudio();
|
|
193
207
|
}
|
|
@@ -198,34 +212,34 @@ var Weaverse = class {
|
|
|
198
212
|
this.stitchesInstance = this.stitchesInstance || stitches.createStitches({
|
|
199
213
|
prefix: "weaverse",
|
|
200
214
|
media: this.mediaBreakPoints,
|
|
201
|
-
utils:
|
|
215
|
+
utils: stitchesUtils
|
|
202
216
|
});
|
|
203
217
|
};
|
|
204
|
-
this.init({
|
|
218
|
+
this.init({ weaverseHost, projectId, data, platformType, mediaBreakPoints, isDesignMode, ssrMode, elementSchemas });
|
|
205
219
|
}
|
|
206
|
-
init({
|
|
207
|
-
this.
|
|
208
|
-
this.
|
|
220
|
+
init({ weaverseHost, elementSchemas, platformType, projectId, data, mediaBreakPoints, isDesignMode, ssrMode } = {}) {
|
|
221
|
+
this.elementSchemas = elementSchemas || this.elementSchemas;
|
|
222
|
+
this.weaverseHost = weaverseHost || this.weaverseHost;
|
|
223
|
+
this.projectId = projectId || this.projectId;
|
|
209
224
|
this.mediaBreakPoints = mediaBreakPoints || this.mediaBreakPoints;
|
|
210
225
|
this.isDesignMode = isDesignMode || this.isDesignMode;
|
|
211
226
|
this.ssrMode = ssrMode || this.ssrMode;
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
227
|
+
this.platformType = platformType || this.platformType;
|
|
228
|
+
this.data = data || this.data;
|
|
214
229
|
this.initProjectItemData();
|
|
230
|
+
this.initStitches();
|
|
215
231
|
}
|
|
216
232
|
loadStudio(version) {
|
|
217
|
-
console.log("load studio");
|
|
218
233
|
if (isIframe && this.isDesignMode && !this.studioBridge) {
|
|
219
234
|
const initStudio = () => {
|
|
220
235
|
this.studioBridge = new window.WeaverseStudioBridge(this);
|
|
221
236
|
this.triggerUpdate();
|
|
222
|
-
console.log("Studio loaded", this);
|
|
223
237
|
clearInterval(i);
|
|
224
238
|
};
|
|
225
239
|
let i = setInterval(() => {
|
|
226
240
|
if (!window.WeaverseStudioBridge) {
|
|
227
241
|
let studioBridgeScript = document.createElement("script");
|
|
228
|
-
studioBridgeScript.src = `${this.
|
|
242
|
+
studioBridgeScript.src = `${this.weaverseHost}/assets/studio/studio-bridge.js?v=${version}`;
|
|
229
243
|
studioBridgeScript.type = "module";
|
|
230
244
|
studioBridgeScript.onload = initStudio;
|
|
231
245
|
document.body.appendChild(studioBridgeScript);
|
|
@@ -258,26 +272,13 @@ var Weaverse = class {
|
|
|
258
272
|
triggerUpdate() {
|
|
259
273
|
this.listeners.forEach((fn) => fn());
|
|
260
274
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
* @param fetch {fetch} custom fetch function, pass in custom fetch function if you want to use your own fetch function
|
|
264
|
-
* @param appUrl
|
|
265
|
-
* @param projectKey
|
|
266
|
-
*/
|
|
267
|
-
static fetchProjectData({
|
|
268
|
-
fetch = globalThis.fetch,
|
|
269
|
-
appUrl,
|
|
270
|
-
projectKey
|
|
271
|
-
}) {
|
|
272
|
-
return fetch(appUrl + `/api/public/project/${projectKey}`).then((res) => res.json()).catch((err) => console.log("Error fetching project data:", err));
|
|
273
|
-
}
|
|
274
|
-
setProjectData(projectData) {
|
|
275
|
-
this.projectData = projectData;
|
|
275
|
+
setProjectData(data) {
|
|
276
|
+
this.data = data;
|
|
276
277
|
this.initProjectItemData();
|
|
277
278
|
this.triggerUpdate();
|
|
278
279
|
}
|
|
279
280
|
initProjectItemData() {
|
|
280
|
-
const data = this.
|
|
281
|
+
const data = this.data;
|
|
281
282
|
if (data?.items) {
|
|
282
283
|
data.items.forEach((item) => {
|
|
283
284
|
if (!this.itemInstances.get(item.id)) {
|
package/package.json
CHANGED