@weaverse/core 0.3.1 → 0.3.2
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 +6 -2
- package/dist/index.js +37 -50
- package/dist/index.mjs +37 -78
- package/package.json +3 -7
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ interface ProjectDataItemType {
|
|
|
12
12
|
}
|
|
13
13
|
interface ProjectDataType {
|
|
14
14
|
items: ProjectDataItemType[];
|
|
15
|
+
rootId: string | number;
|
|
15
16
|
}
|
|
16
17
|
declare type WeaverseType = {
|
|
17
18
|
[key: string]: any;
|
|
@@ -76,20 +77,23 @@ declare class Weaverse {
|
|
|
76
77
|
*/
|
|
77
78
|
registerElement(name: string, element: any): void;
|
|
78
79
|
init(): void;
|
|
80
|
+
listen(callback: any): void;
|
|
79
81
|
loadStudio(): void;
|
|
80
82
|
subscribe(fn: any): void;
|
|
81
83
|
unsubscribe(fn: any): void;
|
|
82
84
|
triggerUpdate(): void;
|
|
83
85
|
/**
|
|
84
86
|
* fetch data from Weaverse API (https://weaverse.io/api/v1/projects/:projectKey)
|
|
87
|
+
* @param fetch {fetch} custom fetch function, pass in custom fetch function if you want to use your own fetch function
|
|
85
88
|
*/
|
|
86
|
-
fetchProjectData(): Promise<any>;
|
|
89
|
+
fetchProjectData(fetch?: typeof globalThis.fetch): Promise<any>;
|
|
87
90
|
/**
|
|
88
91
|
* fetch and update the project data, then trigger update to re-render the WeaverseRoot
|
|
89
92
|
*/
|
|
90
93
|
updateProjectData(): void;
|
|
91
94
|
triggerEditorUpdate(type?: string): void;
|
|
92
|
-
|
|
95
|
+
initProjectItemData(): void;
|
|
96
|
+
addItem(item: any): WeaverseItemStore;
|
|
93
97
|
}
|
|
94
98
|
/**
|
|
95
99
|
* WeaverseItemStore is a store for Weaverse item, it can be used to subscribe/update the item data
|
package/dist/index.js
CHANGED
|
@@ -5,12 +5,6 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
-
var __esm = (fn, res) => function __init() {
|
|
9
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
-
};
|
|
11
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
-
};
|
|
14
8
|
var __export = (target, all) => {
|
|
15
9
|
for (var name in all)
|
|
16
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -32,25 +26,6 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
|
32
26
|
};
|
|
33
27
|
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
34
28
|
|
|
35
|
-
// ../../node_modules/tsup/assets/cjs_shims.js
|
|
36
|
-
var init_cjs_shims = __esm({
|
|
37
|
-
"../../node_modules/tsup/assets/cjs_shims.js"() {
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// src/utils/fetch.js
|
|
42
|
-
var require_fetch = __commonJS({
|
|
43
|
-
"src/utils/fetch.js"(exports, module2) {
|
|
44
|
-
init_cjs_shims();
|
|
45
|
-
function r(m) {
|
|
46
|
-
return m && m.default || m;
|
|
47
|
-
}
|
|
48
|
-
module2.exports = globalThis.fetch = globalThis.fetch || (typeof process == "undefined" ? r(require("unfetch")) : function(url, opts) {
|
|
49
|
-
return r(require("node-fetch"))(String(url).replace(/^\/\//g, "https://"), opts);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
29
|
// src/index.ts
|
|
55
30
|
var src_exports = {};
|
|
56
31
|
__export(src_exports, {
|
|
@@ -60,14 +35,8 @@ __export(src_exports, {
|
|
|
60
35
|
isIframe: () => isIframe,
|
|
61
36
|
isReactNative: () => isReactNative
|
|
62
37
|
});
|
|
63
|
-
init_cjs_shims();
|
|
64
|
-
|
|
65
|
-
// src/core.ts
|
|
66
|
-
init_cjs_shims();
|
|
67
|
-
var import_fetch = __toESM(require_fetch());
|
|
68
38
|
|
|
69
39
|
// src/utils/index.ts
|
|
70
|
-
init_cjs_shims();
|
|
71
40
|
var isReactNative = typeof navigator === "object" && navigator.product === "ReactNative";
|
|
72
41
|
var isBrowser = typeof window !== "undefined" && !isReactNative;
|
|
73
42
|
var isIframe = isBrowser && window.top !== window.self;
|
|
@@ -81,7 +50,8 @@ var Weaverse = class {
|
|
|
81
50
|
this.appUrl = process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://weaverse.io";
|
|
82
51
|
this.projectKey = "";
|
|
83
52
|
this.projectData = {
|
|
84
|
-
items: []
|
|
53
|
+
items: [],
|
|
54
|
+
rootId: 0
|
|
85
55
|
};
|
|
86
56
|
this.listeners = /* @__PURE__ */ new Set();
|
|
87
57
|
this.isEditor = false;
|
|
@@ -104,8 +74,16 @@ var Weaverse = class {
|
|
|
104
74
|
});
|
|
105
75
|
this.loadStudio();
|
|
106
76
|
}
|
|
77
|
+
listen(callback) {
|
|
78
|
+
if (window.addEventListener) {
|
|
79
|
+
window.addEventListener("message", callback, false);
|
|
80
|
+
} else {
|
|
81
|
+
window.attachEvent("onmessage", callback);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
107
84
|
loadStudio() {
|
|
108
85
|
if (isIframe) {
|
|
86
|
+
console.log("Weaverse SDK is initializing...", isIframe);
|
|
109
87
|
let initStudio = () => {
|
|
110
88
|
let StudioBridge = window.WeaverseStudioBridge;
|
|
111
89
|
this.studioBridge = new StudioBridge(this);
|
|
@@ -113,19 +91,22 @@ var Weaverse = class {
|
|
|
113
91
|
this.triggerUpdate();
|
|
114
92
|
console.log("studio bridge initialized", this.studioBridge);
|
|
115
93
|
};
|
|
116
|
-
window.addEventListener("
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
94
|
+
window.addEventListener("load", () => {
|
|
95
|
+
window.addEventListener("message", (e) => {
|
|
96
|
+
var _a;
|
|
97
|
+
if (((_a = e.data) == null ? void 0 : _a.type) === "weaverse.editor.ready") {
|
|
98
|
+
console.log("studio message", e.data);
|
|
99
|
+
this.isEditor = true;
|
|
100
|
+
if (!window.WeaverseStudioBridge) {
|
|
101
|
+
const studioBridgeScript = document.createElement("script");
|
|
102
|
+
studioBridgeScript.src = `${this.appUrl}/assets/studio/studio-bridge.js?t=1`;
|
|
103
|
+
studioBridgeScript.onload = initStudio;
|
|
104
|
+
document.body.appendChild(studioBridgeScript);
|
|
105
|
+
} else {
|
|
106
|
+
initStudio();
|
|
107
|
+
}
|
|
127
108
|
}
|
|
128
|
-
}
|
|
109
|
+
});
|
|
129
110
|
});
|
|
130
111
|
}
|
|
131
112
|
}
|
|
@@ -139,15 +120,16 @@ var Weaverse = class {
|
|
|
139
120
|
this.listeners.forEach((fn) => fn());
|
|
140
121
|
this.triggerEditorUpdate();
|
|
141
122
|
}
|
|
142
|
-
fetchProjectData() {
|
|
143
|
-
|
|
123
|
+
fetchProjectData(fetch = globalThis.fetch) {
|
|
124
|
+
console.log("fetching project data...");
|
|
125
|
+
return fetch(this.appUrl + `/api/public/${this.projectKey}`).then((r) => r.json()).catch(console.error);
|
|
144
126
|
}
|
|
145
127
|
updateProjectData() {
|
|
146
128
|
if (this.projectKey) {
|
|
147
129
|
this.fetchProjectData().then((data) => {
|
|
148
130
|
if (data) {
|
|
149
131
|
this.projectData = data;
|
|
150
|
-
this.
|
|
132
|
+
this.initProjectItemData();
|
|
151
133
|
this.triggerUpdate();
|
|
152
134
|
}
|
|
153
135
|
}).catch((err) => {
|
|
@@ -164,7 +146,7 @@ var Weaverse = class {
|
|
|
164
146
|
});
|
|
165
147
|
}
|
|
166
148
|
}
|
|
167
|
-
|
|
149
|
+
initProjectItemData() {
|
|
168
150
|
let data = this.projectData;
|
|
169
151
|
if (data.items) {
|
|
170
152
|
data.items.forEach((item) => {
|
|
@@ -173,6 +155,11 @@ var Weaverse = class {
|
|
|
173
155
|
});
|
|
174
156
|
}
|
|
175
157
|
}
|
|
158
|
+
addItem(item) {
|
|
159
|
+
let itemStore = new WeaverseItemStore(item, this);
|
|
160
|
+
this.itemInstances.set(item.id, itemStore);
|
|
161
|
+
return itemStore;
|
|
162
|
+
}
|
|
176
163
|
};
|
|
177
164
|
var WeaverseItemStore = class {
|
|
178
165
|
constructor(itemData = {}, weaverse) {
|
|
@@ -197,8 +184,8 @@ var WeaverseItemStore = class {
|
|
|
197
184
|
});
|
|
198
185
|
};
|
|
199
186
|
this.data = itemData;
|
|
200
|
-
let { type } = itemData;
|
|
201
|
-
if (type) {
|
|
187
|
+
let { type, id } = itemData;
|
|
188
|
+
if (type && id) {
|
|
202
189
|
this.Component = weaverse.elementInstances.get(type);
|
|
203
190
|
}
|
|
204
191
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,63 +1,4 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
-
}) : x)(function(x) {
|
|
11
|
-
if (typeof require !== "undefined")
|
|
12
|
-
return require.apply(this, arguments);
|
|
13
|
-
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
-
});
|
|
15
|
-
var __esm = (fn, res) => function __init() {
|
|
16
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
17
|
-
};
|
|
18
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
19
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
20
|
-
};
|
|
21
|
-
var __reExport = (target, module, copyDefault, desc) => {
|
|
22
|
-
if (module && typeof module === "object" || typeof module === "function") {
|
|
23
|
-
for (let key of __getOwnPropNames(module))
|
|
24
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
25
|
-
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (module, isNodeMode) => {
|
|
30
|
-
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", !isNodeMode && module && module.__esModule ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// ../../node_modules/tsup/assets/esm_shims.js
|
|
34
|
-
var init_esm_shims = __esm({
|
|
35
|
-
"../../node_modules/tsup/assets/esm_shims.js"() {
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// src/utils/fetch.js
|
|
40
|
-
var require_fetch = __commonJS({
|
|
41
|
-
"src/utils/fetch.js"(exports, module) {
|
|
42
|
-
init_esm_shims();
|
|
43
|
-
function r(m) {
|
|
44
|
-
return m && m.default || m;
|
|
45
|
-
}
|
|
46
|
-
module.exports = globalThis.fetch = globalThis.fetch || (typeof process == "undefined" ? r(__require("unfetch")) : function(url, opts) {
|
|
47
|
-
return r(__require("node-fetch"))(String(url).replace(/^\/\//g, "https://"), opts);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// src/index.ts
|
|
53
|
-
init_esm_shims();
|
|
54
|
-
|
|
55
|
-
// src/core.ts
|
|
56
|
-
init_esm_shims();
|
|
57
|
-
var import_fetch = __toESM(require_fetch());
|
|
58
|
-
|
|
59
1
|
// src/utils/index.ts
|
|
60
|
-
init_esm_shims();
|
|
61
2
|
var isReactNative = typeof navigator === "object" && navigator.product === "ReactNative";
|
|
62
3
|
var isBrowser = typeof window !== "undefined" && !isReactNative;
|
|
63
4
|
var isIframe = isBrowser && window.top !== window.self;
|
|
@@ -71,7 +12,8 @@ var Weaverse = class {
|
|
|
71
12
|
this.appUrl = process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://weaverse.io";
|
|
72
13
|
this.projectKey = "";
|
|
73
14
|
this.projectData = {
|
|
74
|
-
items: []
|
|
15
|
+
items: [],
|
|
16
|
+
rootId: 0
|
|
75
17
|
};
|
|
76
18
|
this.listeners = /* @__PURE__ */ new Set();
|
|
77
19
|
this.isEditor = false;
|
|
@@ -94,8 +36,16 @@ var Weaverse = class {
|
|
|
94
36
|
});
|
|
95
37
|
this.loadStudio();
|
|
96
38
|
}
|
|
39
|
+
listen(callback) {
|
|
40
|
+
if (window.addEventListener) {
|
|
41
|
+
window.addEventListener("message", callback, false);
|
|
42
|
+
} else {
|
|
43
|
+
window.attachEvent("onmessage", callback);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
97
46
|
loadStudio() {
|
|
98
47
|
if (isIframe) {
|
|
48
|
+
console.log("Weaverse SDK is initializing...", isIframe);
|
|
99
49
|
let initStudio = () => {
|
|
100
50
|
let StudioBridge = window.WeaverseStudioBridge;
|
|
101
51
|
this.studioBridge = new StudioBridge(this);
|
|
@@ -103,19 +53,22 @@ var Weaverse = class {
|
|
|
103
53
|
this.triggerUpdate();
|
|
104
54
|
console.log("studio bridge initialized", this.studioBridge);
|
|
105
55
|
};
|
|
106
|
-
window.addEventListener("
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
56
|
+
window.addEventListener("load", () => {
|
|
57
|
+
window.addEventListener("message", (e) => {
|
|
58
|
+
var _a;
|
|
59
|
+
if (((_a = e.data) == null ? void 0 : _a.type) === "weaverse.editor.ready") {
|
|
60
|
+
console.log("studio message", e.data);
|
|
61
|
+
this.isEditor = true;
|
|
62
|
+
if (!window.WeaverseStudioBridge) {
|
|
63
|
+
const studioBridgeScript = document.createElement("script");
|
|
64
|
+
studioBridgeScript.src = `${this.appUrl}/assets/studio/studio-bridge.js?t=1`;
|
|
65
|
+
studioBridgeScript.onload = initStudio;
|
|
66
|
+
document.body.appendChild(studioBridgeScript);
|
|
67
|
+
} else {
|
|
68
|
+
initStudio();
|
|
69
|
+
}
|
|
117
70
|
}
|
|
118
|
-
}
|
|
71
|
+
});
|
|
119
72
|
});
|
|
120
73
|
}
|
|
121
74
|
}
|
|
@@ -129,15 +82,16 @@ var Weaverse = class {
|
|
|
129
82
|
this.listeners.forEach((fn) => fn());
|
|
130
83
|
this.triggerEditorUpdate();
|
|
131
84
|
}
|
|
132
|
-
fetchProjectData() {
|
|
133
|
-
|
|
85
|
+
fetchProjectData(fetch = globalThis.fetch) {
|
|
86
|
+
console.log("fetching project data...");
|
|
87
|
+
return fetch(this.appUrl + `/api/public/${this.projectKey}`).then((r) => r.json()).catch(console.error);
|
|
134
88
|
}
|
|
135
89
|
updateProjectData() {
|
|
136
90
|
if (this.projectKey) {
|
|
137
91
|
this.fetchProjectData().then((data) => {
|
|
138
92
|
if (data) {
|
|
139
93
|
this.projectData = data;
|
|
140
|
-
this.
|
|
94
|
+
this.initProjectItemData();
|
|
141
95
|
this.triggerUpdate();
|
|
142
96
|
}
|
|
143
97
|
}).catch((err) => {
|
|
@@ -154,7 +108,7 @@ var Weaverse = class {
|
|
|
154
108
|
});
|
|
155
109
|
}
|
|
156
110
|
}
|
|
157
|
-
|
|
111
|
+
initProjectItemData() {
|
|
158
112
|
let data = this.projectData;
|
|
159
113
|
if (data.items) {
|
|
160
114
|
data.items.forEach((item) => {
|
|
@@ -163,6 +117,11 @@ var Weaverse = class {
|
|
|
163
117
|
});
|
|
164
118
|
}
|
|
165
119
|
}
|
|
120
|
+
addItem(item) {
|
|
121
|
+
let itemStore = new WeaverseItemStore(item, this);
|
|
122
|
+
this.itemInstances.set(item.id, itemStore);
|
|
123
|
+
return itemStore;
|
|
124
|
+
}
|
|
166
125
|
};
|
|
167
126
|
var WeaverseItemStore = class {
|
|
168
127
|
constructor(itemData = {}, weaverse) {
|
|
@@ -187,8 +146,8 @@ var WeaverseItemStore = class {
|
|
|
187
146
|
});
|
|
188
147
|
};
|
|
189
148
|
this.data = itemData;
|
|
190
|
-
let { type } = itemData;
|
|
191
|
-
if (type) {
|
|
149
|
+
let { type, id } = itemData;
|
|
150
|
+
if (type && id) {
|
|
192
151
|
this.Component = weaverse.elementInstances.get(type);
|
|
193
152
|
}
|
|
194
153
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.3.
|
|
2
|
+
"version": "0.3.2",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
|
-
"type": "commonjs",
|
|
11
10
|
"files": [
|
|
12
11
|
"dist"
|
|
13
12
|
],
|
|
@@ -22,10 +21,7 @@
|
|
|
22
21
|
"name": "@weaverse/core",
|
|
23
22
|
"author": "Paul",
|
|
24
23
|
"dependencies": {
|
|
25
|
-
"@stitches/core": "^1.2.
|
|
26
|
-
|
|
27
|
-
"peerDependencies": {
|
|
28
|
-
"node-fetch": "^3",
|
|
29
|
-
"unfetch": "^4"
|
|
24
|
+
"@stitches/core": "^1.2.7",
|
|
25
|
+
"uuid": "^8.3.2"
|
|
30
26
|
}
|
|
31
27
|
}
|