@weaverse/core 0.6.22 → 0.6.26
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 +21 -7
- package/dist/index.js +40 -41
- package/dist/index.mjs +40 -41
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -48,6 +48,13 @@ interface ProjectDataType {
|
|
|
48
48
|
css: string;
|
|
49
49
|
js: string;
|
|
50
50
|
};
|
|
51
|
+
pageId?: string;
|
|
52
|
+
}
|
|
53
|
+
interface InitializeData {
|
|
54
|
+
id: string;
|
|
55
|
+
handle: string;
|
|
56
|
+
data: ProjectDataType;
|
|
57
|
+
published: boolean;
|
|
51
58
|
}
|
|
52
59
|
interface WeaverseType {
|
|
53
60
|
mediaBreakPoints?: any;
|
|
@@ -70,8 +77,9 @@ interface ElementCatalog {
|
|
|
70
77
|
name: string;
|
|
71
78
|
icon?: string;
|
|
72
79
|
group?: CatalogGroup;
|
|
80
|
+
data?: ElementData[];
|
|
73
81
|
}
|
|
74
|
-
declare type FlagType = "draggable" | "resizable" | "sortable";
|
|
82
|
+
declare type FlagType = "draggable" | "resizable" | "sortable" | "droppable";
|
|
75
83
|
declare type ElementFlags = Partial<Record<FlagType, boolean>>;
|
|
76
84
|
declare type ToolbarAction = "duplicate" | "delete" | "edit-button" | "insert-link" | "select-template" | "copy-styles" | "paste-styles";
|
|
77
85
|
interface ChildElement {
|
|
@@ -90,7 +98,7 @@ interface ElementSchema {
|
|
|
90
98
|
gridSize?: GridSize;
|
|
91
99
|
inspector?: ElementInspector;
|
|
92
100
|
toolbar?: (ToolbarAction | ToolbarAction[])[];
|
|
93
|
-
|
|
101
|
+
childElements?: ChildElement[];
|
|
94
102
|
catalog?: ElementCatalog;
|
|
95
103
|
flags?: ElementFlags;
|
|
96
104
|
}
|
|
@@ -121,7 +129,7 @@ declare type BasicGroup = {
|
|
|
121
129
|
label: string;
|
|
122
130
|
inputs: BasicInput[];
|
|
123
131
|
};
|
|
124
|
-
declare type AdvancedInput = "alignment" | "background" | "border" | "countdown" | "dimensions" | "form" | "
|
|
132
|
+
declare type AdvancedInput = "alignment" | "background" | "border" | "countdown" | "dimensions" | "form" | "product" | "spacing" | "visibility";
|
|
125
133
|
interface BasicInput {
|
|
126
134
|
type: InputType;
|
|
127
135
|
label: string;
|
|
@@ -132,14 +140,19 @@ interface BasicInput {
|
|
|
132
140
|
options?: {
|
|
133
141
|
value: string;
|
|
134
142
|
label: string;
|
|
143
|
+
icon?: string;
|
|
135
144
|
}[];
|
|
145
|
+
min?: number;
|
|
146
|
+
max?: number;
|
|
147
|
+
step?: number;
|
|
136
148
|
conditions?: TODO[];
|
|
137
149
|
}
|
|
138
|
-
declare type InputType = "
|
|
150
|
+
declare type InputType = "color" | "image" | "instagram" | "range" | "select" | "switch" | "text" | "textarea" | "toggle-group";
|
|
139
151
|
declare global {
|
|
140
152
|
interface Window {
|
|
141
153
|
WeaverseStudioBridge: TODO;
|
|
142
154
|
weaverseShopifyProducts: TODO;
|
|
155
|
+
weaverseGlobalSettings: TODO;
|
|
143
156
|
}
|
|
144
157
|
}
|
|
145
158
|
|
|
@@ -241,13 +254,15 @@ declare class Weaverse {
|
|
|
241
254
|
* @param ssrMode {boolean} Use in element to optionally render special HTML for hydration
|
|
242
255
|
*/
|
|
243
256
|
constructor({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode }?: WeaverseType);
|
|
257
|
+
init({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode }?: WeaverseType): void;
|
|
258
|
+
initialized: boolean;
|
|
259
|
+
initializeData: (data: InitializeData) => void;
|
|
244
260
|
loadStudio(): void;
|
|
245
261
|
/**
|
|
246
262
|
* register the custom React Component to Weaverse, store it into Weaverse.elementInstances
|
|
247
263
|
* @param element {WeaverseElement} custom React Component
|
|
248
264
|
*/
|
|
249
265
|
registerElement(element: WeaverseElement): void;
|
|
250
|
-
init(): void;
|
|
251
266
|
initStitches: () => void;
|
|
252
267
|
subscribe(fn: any): void;
|
|
253
268
|
unsubscribe(fn: any): void;
|
|
@@ -267,7 +282,6 @@ declare class Weaverse {
|
|
|
267
282
|
/**
|
|
268
283
|
* fetch and update the project data, then trigger update to re-render the WeaverseRoot
|
|
269
284
|
*/
|
|
270
|
-
updateProjectData(): void;
|
|
271
285
|
initProjectItemData(): void;
|
|
272
286
|
}
|
|
273
287
|
|
|
@@ -275,4 +289,4 @@ declare const isReactNative: boolean;
|
|
|
275
289
|
declare const isBrowser: boolean;
|
|
276
290
|
declare const isIframe: boolean;
|
|
277
291
|
|
|
278
|
-
export { AdvancedGroup, AdvancedInput, BasicGroup, BasicInput, CatalogGroup, ChildElement, ChildElementCSS, ElementCSS, ElementCatalog, ElementData, ElementFlags, ElementInspector, ElementSchema, ElementsMap, FlagType, GridSize, InputType, ParentType, ProjectDataType, TODO, ToolbarAction, Weaverse, WeaverseCSSProperties, WeaverseElement, WeaverseItemStore, WeaverseType, isBrowser, isIframe, isReactNative };
|
|
292
|
+
export { AdvancedGroup, AdvancedInput, BasicGroup, BasicInput, CatalogGroup, ChildElement, ChildElementCSS, ElementCSS, ElementCatalog, ElementData, ElementFlags, ElementInspector, ElementSchema, ElementsMap, FlagType, GridSize, InitializeData, InputType, ParentType, ProjectDataType, TODO, ToolbarAction, Weaverse, WeaverseCSSProperties, WeaverseElement, WeaverseItemStore, WeaverseType, isBrowser, isIframe, isReactNative };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
@@ -18,6 +20,7 @@ var __spreadValues = (a, b) => {
|
|
|
18
20
|
}
|
|
19
21
|
return a;
|
|
20
22
|
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
24
|
var __export = (target, all) => {
|
|
22
25
|
for (var name in all)
|
|
23
26
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -141,7 +144,7 @@ var WeaverseItemStore = class {
|
|
|
141
144
|
return __spreadValues(__spreadValues({}, (_b = (_a = this.Element) == null ? void 0 : _a.Component) == null ? void 0 : _b.defaultProps), this._data);
|
|
142
145
|
}
|
|
143
146
|
};
|
|
144
|
-
var
|
|
147
|
+
var Weaverse = class {
|
|
145
148
|
constructor({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode } = {}) {
|
|
146
149
|
this.elementInstances = /* @__PURE__ */ new Map();
|
|
147
150
|
this.itemInstances = /* @__PURE__ */ new Map();
|
|
@@ -159,37 +162,55 @@ var _Weaverse = class {
|
|
|
159
162
|
desktop: "all",
|
|
160
163
|
mobile: "(max-width: 767.98px)"
|
|
161
164
|
};
|
|
165
|
+
this.initialized = false;
|
|
166
|
+
this.initializeData = (data) => {
|
|
167
|
+
if (!this.initialized) {
|
|
168
|
+
let { data: pageData, published, id } = data;
|
|
169
|
+
this.projectData = __spreadProps(__spreadValues({}, pageData), { pageId: id });
|
|
170
|
+
this.isDesignMode = !published;
|
|
171
|
+
this.initProjectItemData();
|
|
172
|
+
this.triggerUpdate();
|
|
173
|
+
this.loadStudio();
|
|
174
|
+
}
|
|
175
|
+
this.initialized = true;
|
|
176
|
+
};
|
|
162
177
|
this.initStitches = () => {
|
|
163
|
-
this.stitchesInstance = stitches.createStitches({
|
|
178
|
+
this.stitchesInstance = this.stitchesInstance || stitches.createStitches({
|
|
164
179
|
prefix: "weaverse",
|
|
165
180
|
media: this.mediaBreakPoints,
|
|
166
181
|
utils: stichesUtils
|
|
167
182
|
});
|
|
168
183
|
};
|
|
184
|
+
this.init({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode });
|
|
185
|
+
}
|
|
186
|
+
init({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode } = {}) {
|
|
169
187
|
this.appUrl = appUrl || this.appUrl;
|
|
170
188
|
this.projectKey = projectKey || this.projectKey;
|
|
171
189
|
this.mediaBreakPoints = mediaBreakPoints || this.mediaBreakPoints;
|
|
172
190
|
this.isDesignMode = isDesignMode || this.isDesignMode;
|
|
173
191
|
this.ssrMode = ssrMode || this.ssrMode;
|
|
174
|
-
|
|
175
|
-
this.
|
|
192
|
+
this.projectData = projectData || this.projectData;
|
|
193
|
+
this.initStitches();
|
|
194
|
+
this.initProjectItemData();
|
|
176
195
|
}
|
|
177
196
|
loadStudio() {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
197
|
+
setTimeout(() => {
|
|
198
|
+
if (isIframe && this.isDesignMode && !this.studioBridge) {
|
|
199
|
+
const initStudio = () => {
|
|
200
|
+
this.studioBridge = new window.WeaverseStudioBridge(this);
|
|
201
|
+
this.triggerUpdate();
|
|
202
|
+
};
|
|
203
|
+
if (!window.WeaverseStudioBridge) {
|
|
204
|
+
const studioBridgeScript = document.createElement("script");
|
|
205
|
+
studioBridgeScript.src = `${this.appUrl}/assets/studio/studio-bridge.js`;
|
|
206
|
+
studioBridgeScript.type = "module";
|
|
207
|
+
studioBridgeScript.onload = initStudio;
|
|
208
|
+
document.body.appendChild(studioBridgeScript);
|
|
209
|
+
} else {
|
|
210
|
+
initStudio();
|
|
211
|
+
}
|
|
191
212
|
}
|
|
192
|
-
}
|
|
213
|
+
}, 2e3);
|
|
193
214
|
}
|
|
194
215
|
registerElement(element) {
|
|
195
216
|
if (element == null ? void 0 : element.type) {
|
|
@@ -201,13 +222,6 @@ var _Weaverse = class {
|
|
|
201
222
|
throw new Error("Weaverse: registerElement: `type` is required");
|
|
202
223
|
}
|
|
203
224
|
}
|
|
204
|
-
init() {
|
|
205
|
-
this.initStitches();
|
|
206
|
-
this.initProjectItemData();
|
|
207
|
-
setTimeout(() => {
|
|
208
|
-
this.loadStudio();
|
|
209
|
-
}, 1e3);
|
|
210
|
-
}
|
|
211
225
|
subscribe(fn) {
|
|
212
226
|
this.listeners.add(fn);
|
|
213
227
|
}
|
|
@@ -222,7 +236,6 @@ var _Weaverse = class {
|
|
|
222
236
|
appUrl,
|
|
223
237
|
projectKey
|
|
224
238
|
}) {
|
|
225
|
-
console.log("Weaverse: fetchProjectData", appUrl, projectKey);
|
|
226
239
|
return fetch(appUrl + `/api/public/${projectKey}`).then((r) => r.json()).catch(console.error);
|
|
227
240
|
}
|
|
228
241
|
setProjectData(projectData) {
|
|
@@ -230,22 +243,9 @@ var _Weaverse = class {
|
|
|
230
243
|
this.initProjectItemData();
|
|
231
244
|
this.triggerUpdate();
|
|
232
245
|
}
|
|
233
|
-
updateProjectData() {
|
|
234
|
-
if (this.projectKey && !this.projectData.rootId) {
|
|
235
|
-
_Weaverse.fetchProjectData({ appUrl: this.appUrl, projectKey: this.projectKey }).then((data) => {
|
|
236
|
-
if (data) {
|
|
237
|
-
this.projectData = data;
|
|
238
|
-
this.initProjectItemData();
|
|
239
|
-
this.triggerUpdate();
|
|
240
|
-
}
|
|
241
|
-
}).catch((err) => {
|
|
242
|
-
console.error(err);
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
246
|
initProjectItemData() {
|
|
247
247
|
const data = this.projectData;
|
|
248
|
-
if (data.items) {
|
|
248
|
+
if (data == null ? void 0 : data.items) {
|
|
249
249
|
data.items.forEach((item) => {
|
|
250
250
|
if (!this.itemInstances.get(item.id)) {
|
|
251
251
|
new WeaverseItemStore(item, this);
|
|
@@ -254,7 +254,6 @@ var _Weaverse = class {
|
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
};
|
|
257
|
-
var Weaverse = _Weaverse;
|
|
258
257
|
Weaverse.WeaverseItemStore = WeaverseItemStore;
|
|
259
258
|
// Annotate the CommonJS export names for ESM import in node:
|
|
260
259
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
|
|
18
21
|
// src/core.ts
|
|
19
22
|
import * as stitches from "@stitches/core";
|
|
@@ -112,7 +115,7 @@ var WeaverseItemStore = class {
|
|
|
112
115
|
return __spreadValues(__spreadValues({}, (_b = (_a = this.Element) == null ? void 0 : _a.Component) == null ? void 0 : _b.defaultProps), this._data);
|
|
113
116
|
}
|
|
114
117
|
};
|
|
115
|
-
var
|
|
118
|
+
var Weaverse = class {
|
|
116
119
|
constructor({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode } = {}) {
|
|
117
120
|
this.elementInstances = /* @__PURE__ */ new Map();
|
|
118
121
|
this.itemInstances = /* @__PURE__ */ new Map();
|
|
@@ -130,37 +133,55 @@ var _Weaverse = class {
|
|
|
130
133
|
desktop: "all",
|
|
131
134
|
mobile: "(max-width: 767.98px)"
|
|
132
135
|
};
|
|
136
|
+
this.initialized = false;
|
|
137
|
+
this.initializeData = (data) => {
|
|
138
|
+
if (!this.initialized) {
|
|
139
|
+
let { data: pageData, published, id } = data;
|
|
140
|
+
this.projectData = __spreadProps(__spreadValues({}, pageData), { pageId: id });
|
|
141
|
+
this.isDesignMode = !published;
|
|
142
|
+
this.initProjectItemData();
|
|
143
|
+
this.triggerUpdate();
|
|
144
|
+
this.loadStudio();
|
|
145
|
+
}
|
|
146
|
+
this.initialized = true;
|
|
147
|
+
};
|
|
133
148
|
this.initStitches = () => {
|
|
134
|
-
this.stitchesInstance = stitches.createStitches({
|
|
149
|
+
this.stitchesInstance = this.stitchesInstance || stitches.createStitches({
|
|
135
150
|
prefix: "weaverse",
|
|
136
151
|
media: this.mediaBreakPoints,
|
|
137
152
|
utils: stichesUtils
|
|
138
153
|
});
|
|
139
154
|
};
|
|
155
|
+
this.init({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode });
|
|
156
|
+
}
|
|
157
|
+
init({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode } = {}) {
|
|
140
158
|
this.appUrl = appUrl || this.appUrl;
|
|
141
159
|
this.projectKey = projectKey || this.projectKey;
|
|
142
160
|
this.mediaBreakPoints = mediaBreakPoints || this.mediaBreakPoints;
|
|
143
161
|
this.isDesignMode = isDesignMode || this.isDesignMode;
|
|
144
162
|
this.ssrMode = ssrMode || this.ssrMode;
|
|
145
|
-
|
|
146
|
-
this.
|
|
163
|
+
this.projectData = projectData || this.projectData;
|
|
164
|
+
this.initStitches();
|
|
165
|
+
this.initProjectItemData();
|
|
147
166
|
}
|
|
148
167
|
loadStudio() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
168
|
+
setTimeout(() => {
|
|
169
|
+
if (isIframe && this.isDesignMode && !this.studioBridge) {
|
|
170
|
+
const initStudio = () => {
|
|
171
|
+
this.studioBridge = new window.WeaverseStudioBridge(this);
|
|
172
|
+
this.triggerUpdate();
|
|
173
|
+
};
|
|
174
|
+
if (!window.WeaverseStudioBridge) {
|
|
175
|
+
const studioBridgeScript = document.createElement("script");
|
|
176
|
+
studioBridgeScript.src = `${this.appUrl}/assets/studio/studio-bridge.js`;
|
|
177
|
+
studioBridgeScript.type = "module";
|
|
178
|
+
studioBridgeScript.onload = initStudio;
|
|
179
|
+
document.body.appendChild(studioBridgeScript);
|
|
180
|
+
} else {
|
|
181
|
+
initStudio();
|
|
182
|
+
}
|
|
162
183
|
}
|
|
163
|
-
}
|
|
184
|
+
}, 2e3);
|
|
164
185
|
}
|
|
165
186
|
registerElement(element) {
|
|
166
187
|
if (element == null ? void 0 : element.type) {
|
|
@@ -172,13 +193,6 @@ var _Weaverse = class {
|
|
|
172
193
|
throw new Error("Weaverse: registerElement: `type` is required");
|
|
173
194
|
}
|
|
174
195
|
}
|
|
175
|
-
init() {
|
|
176
|
-
this.initStitches();
|
|
177
|
-
this.initProjectItemData();
|
|
178
|
-
setTimeout(() => {
|
|
179
|
-
this.loadStudio();
|
|
180
|
-
}, 1e3);
|
|
181
|
-
}
|
|
182
196
|
subscribe(fn) {
|
|
183
197
|
this.listeners.add(fn);
|
|
184
198
|
}
|
|
@@ -193,7 +207,6 @@ var _Weaverse = class {
|
|
|
193
207
|
appUrl,
|
|
194
208
|
projectKey
|
|
195
209
|
}) {
|
|
196
|
-
console.log("Weaverse: fetchProjectData", appUrl, projectKey);
|
|
197
210
|
return fetch(appUrl + `/api/public/${projectKey}`).then((r) => r.json()).catch(console.error);
|
|
198
211
|
}
|
|
199
212
|
setProjectData(projectData) {
|
|
@@ -201,22 +214,9 @@ var _Weaverse = class {
|
|
|
201
214
|
this.initProjectItemData();
|
|
202
215
|
this.triggerUpdate();
|
|
203
216
|
}
|
|
204
|
-
updateProjectData() {
|
|
205
|
-
if (this.projectKey && !this.projectData.rootId) {
|
|
206
|
-
_Weaverse.fetchProjectData({ appUrl: this.appUrl, projectKey: this.projectKey }).then((data) => {
|
|
207
|
-
if (data) {
|
|
208
|
-
this.projectData = data;
|
|
209
|
-
this.initProjectItemData();
|
|
210
|
-
this.triggerUpdate();
|
|
211
|
-
}
|
|
212
|
-
}).catch((err) => {
|
|
213
|
-
console.error(err);
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
217
|
initProjectItemData() {
|
|
218
218
|
const data = this.projectData;
|
|
219
|
-
if (data.items) {
|
|
219
|
+
if (data == null ? void 0 : data.items) {
|
|
220
220
|
data.items.forEach((item) => {
|
|
221
221
|
if (!this.itemInstances.get(item.id)) {
|
|
222
222
|
new WeaverseItemStore(item, this);
|
|
@@ -225,7 +225,6 @@ var _Weaverse = class {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
};
|
|
228
|
-
var Weaverse = _Weaverse;
|
|
229
228
|
Weaverse.WeaverseItemStore = WeaverseItemStore;
|
|
230
229
|
export {
|
|
231
230
|
Weaverse,
|
package/package.json
CHANGED