@weaverse/react 0.3.4 → 0.3.7
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 +5 -3
- package/dist/index.js +126 -83
- package/dist/index.mjs +122 -70
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { WeaverseType, Weaverse } from '@weaverse/core';
|
|
2
|
+
export * from '@weaverse/core';
|
|
2
3
|
|
|
3
4
|
declare const createRootContext: (configs: WeaverseType) => Weaverse;
|
|
4
|
-
declare
|
|
5
|
+
declare type WeaverseRootPropsType = {
|
|
5
6
|
context: Weaverse;
|
|
6
7
|
defaultData: any;
|
|
7
|
-
}
|
|
8
|
+
};
|
|
9
|
+
declare const WeaverseRoot: ({ context, defaultData, }: WeaverseRootPropsType) => JSX.Element;
|
|
8
10
|
|
|
9
|
-
export { WeaverseRoot, createRootContext };
|
|
11
|
+
export { WeaverseRoot, WeaverseRootPropsType, createRootContext };
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,6 @@ var __spreadValues = (a, b) => {
|
|
|
21
21
|
return a;
|
|
22
22
|
};
|
|
23
23
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
25
24
|
var __objRest = (source, exclude) => {
|
|
26
25
|
var target = {};
|
|
27
26
|
for (var prop in source)
|
|
@@ -38,22 +37,17 @@ var __export = (target, all) => {
|
|
|
38
37
|
for (var name in all)
|
|
39
38
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
39
|
};
|
|
41
|
-
var
|
|
42
|
-
if (
|
|
43
|
-
for (let key of __getOwnPropNames(
|
|
44
|
-
if (!__hasOwnProp.call(
|
|
45
|
-
__defProp(
|
|
40
|
+
var __copyProps = (to, from, except, desc) => {
|
|
41
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
+
for (let key of __getOwnPropNames(from))
|
|
43
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
44
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
45
|
}
|
|
47
|
-
return
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (module2, isNodeMode) => {
|
|
50
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
46
|
+
return to;
|
|
51
47
|
};
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
48
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
50
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
57
51
|
|
|
58
52
|
// src/index.ts
|
|
59
53
|
var src_exports = {};
|
|
@@ -61,31 +55,7 @@ __export(src_exports, {
|
|
|
61
55
|
WeaverseRoot: () => WeaverseRoot,
|
|
62
56
|
createRootContext: () => createRootContext
|
|
63
57
|
});
|
|
64
|
-
|
|
65
|
-
// src/renderer.tsx
|
|
66
|
-
var React5 = __toESM(require("react"));
|
|
67
|
-
var import_core = require("@weaverse/core");
|
|
68
|
-
|
|
69
|
-
// src/elements/button.tsx
|
|
70
|
-
var React = __toESM(require("react"));
|
|
71
|
-
var Button = React.forwardRef((props, ref) => {
|
|
72
|
-
let [count, setCount] = React.useState(0);
|
|
73
|
-
return /* @__PURE__ */ React.createElement("button", __spreadProps(__spreadValues({
|
|
74
|
-
ref
|
|
75
|
-
}, props), {
|
|
76
|
-
onClick: () => setCount(count + 1)
|
|
77
|
-
}), "Test Button ", count);
|
|
78
|
-
});
|
|
79
|
-
Button.defaultProps = {
|
|
80
|
-
style: {
|
|
81
|
-
borderRadius: "9999px",
|
|
82
|
-
fontSize: "13px",
|
|
83
|
-
padding: "10px 15px"
|
|
84
|
-
},
|
|
85
|
-
type: "button",
|
|
86
|
-
tag: "button"
|
|
87
|
-
};
|
|
88
|
-
var button_default = Button;
|
|
58
|
+
module.exports = __toCommonJS(src_exports);
|
|
89
59
|
|
|
90
60
|
// src/elements/base.tsx
|
|
91
61
|
var import_react = __toESM(require("react"));
|
|
@@ -96,65 +66,130 @@ var BaseElement = import_react.default.forwardRef((_a, ref) => {
|
|
|
96
66
|
}, props), children);
|
|
97
67
|
});
|
|
98
68
|
BaseElement.defaultProps = {
|
|
99
|
-
type: "base",
|
|
100
69
|
tag: "div",
|
|
101
70
|
style: {}
|
|
102
71
|
};
|
|
72
|
+
var schema = {
|
|
73
|
+
type: "base"
|
|
74
|
+
};
|
|
103
75
|
var base_default = BaseElement;
|
|
104
76
|
|
|
105
|
-
// src/elements/
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
return /* @__PURE__ */
|
|
109
|
-
|
|
110
|
-
|
|
77
|
+
// src/elements/button.tsx
|
|
78
|
+
var React2 = __toESM(require("react"));
|
|
79
|
+
var Button = React2.forwardRef((props, ref) => {
|
|
80
|
+
return /* @__PURE__ */ React2.createElement("button", __spreadValues({
|
|
81
|
+
ref
|
|
82
|
+
}, props), props.value);
|
|
83
|
+
});
|
|
84
|
+
Button.defaultProps = {
|
|
85
|
+
value: "Click me",
|
|
111
86
|
style: {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
87
|
+
borderRadius: "9999px",
|
|
88
|
+
fontSize: "13px",
|
|
89
|
+
padding: "10px 15px"
|
|
90
|
+
}
|
|
116
91
|
};
|
|
92
|
+
var schema2 = {
|
|
93
|
+
title: "Button",
|
|
94
|
+
type: "button",
|
|
95
|
+
settings: [
|
|
96
|
+
{
|
|
97
|
+
tab: "Settings",
|
|
98
|
+
label: "Group 1",
|
|
99
|
+
inspectors: [
|
|
100
|
+
{
|
|
101
|
+
binding: "data",
|
|
102
|
+
key: "value",
|
|
103
|
+
componentType: "textarea"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
binding: "style",
|
|
107
|
+
key: "backgroundColor",
|
|
108
|
+
componentType: "color"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
tab: "Settings",
|
|
114
|
+
label: "Group 2",
|
|
115
|
+
inspectors: [
|
|
116
|
+
{
|
|
117
|
+
binding: "style",
|
|
118
|
+
key: "color",
|
|
119
|
+
componentType: "color"
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
};
|
|
125
|
+
var button_default = Button;
|
|
117
126
|
|
|
118
127
|
// src/elements/text.tsx
|
|
119
|
-
var
|
|
120
|
-
var Text =
|
|
121
|
-
let _a = props, { children } = _a, rest = __objRest(_a, ["children"]);
|
|
122
|
-
return /* @__PURE__ */
|
|
128
|
+
var React3 = __toESM(require("react"));
|
|
129
|
+
var Text = React3.forwardRef((props, ref) => {
|
|
130
|
+
let _a = props, { children, value } = _a, rest = __objRest(_a, ["children", "value"]);
|
|
131
|
+
return /* @__PURE__ */ React3.createElement("span", __spreadProps(__spreadValues({
|
|
123
132
|
ref
|
|
124
133
|
}, rest), {
|
|
125
134
|
contentEditable: true,
|
|
126
|
-
dangerouslySetInnerHTML: { __html:
|
|
135
|
+
dangerouslySetInnerHTML: { __html: value }
|
|
127
136
|
}));
|
|
128
137
|
});
|
|
129
138
|
Text.defaultProps = {
|
|
130
|
-
|
|
131
|
-
type: "text",
|
|
139
|
+
value: "sample text",
|
|
132
140
|
tag: "span"
|
|
133
141
|
};
|
|
142
|
+
var schema3 = {
|
|
143
|
+
type: "text",
|
|
144
|
+
inspectors: [
|
|
145
|
+
{
|
|
146
|
+
binding: "data",
|
|
147
|
+
key: "value",
|
|
148
|
+
componentType: "textarea"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
binding: "style",
|
|
152
|
+
key: "color",
|
|
153
|
+
componentType: "color"
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
};
|
|
134
157
|
var text_default = Text;
|
|
135
158
|
|
|
136
159
|
// src/elements/index.ts
|
|
137
160
|
var elements = {
|
|
138
|
-
Button:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
161
|
+
Button: {
|
|
162
|
+
Component: button_default,
|
|
163
|
+
schema: schema2
|
|
164
|
+
},
|
|
165
|
+
BaseElement: {
|
|
166
|
+
Component: base_default,
|
|
167
|
+
schema
|
|
168
|
+
},
|
|
169
|
+
Text: {
|
|
170
|
+
Component: text_default,
|
|
171
|
+
schema: schema3
|
|
172
|
+
}
|
|
142
173
|
};
|
|
143
174
|
var elements_default = elements;
|
|
144
175
|
|
|
145
176
|
// src/renderer.tsx
|
|
177
|
+
var import_core = require("@weaverse/core");
|
|
178
|
+
var React4 = __toESM(require("react"));
|
|
146
179
|
var createRootContext = (configs) => {
|
|
147
180
|
const rootContext = new import_core.Weaverse(configs);
|
|
148
181
|
Object.keys(elements_default).forEach((key) => {
|
|
149
|
-
|
|
150
|
-
((_b = (_a = elements_default[key]) == null ? void 0 : _a.defaultProps) == null ? void 0 : _b.type) && rootContext.registerElement(elements_default[key].defaultProps.type, elements_default[key]);
|
|
182
|
+
rootContext.registerElement(elements_default[key]);
|
|
151
183
|
});
|
|
152
184
|
return rootContext;
|
|
153
185
|
};
|
|
154
|
-
var WeaverseRoot = ({
|
|
186
|
+
var WeaverseRoot = ({
|
|
187
|
+
context,
|
|
188
|
+
defaultData
|
|
189
|
+
}) => {
|
|
155
190
|
var _a, _b, _c;
|
|
156
|
-
let [, setData] =
|
|
157
|
-
|
|
191
|
+
let [, setData] = React4.useState(context.projectData);
|
|
192
|
+
React4.useEffect(() => {
|
|
158
193
|
let handleUpdate = () => {
|
|
159
194
|
setData(__spreadValues({}, context.projectData));
|
|
160
195
|
};
|
|
@@ -169,45 +204,48 @@ var WeaverseRoot = ({ context, defaultData }) => {
|
|
|
169
204
|
context.initProjectItemData();
|
|
170
205
|
}
|
|
171
206
|
let handleProps = ((_c = context == null ? void 0 : context.studioBridge) == null ? void 0 : _c.handleProps) || {};
|
|
172
|
-
return /* @__PURE__ */
|
|
207
|
+
return /* @__PURE__ */ React4.createElement("div", __spreadValues({
|
|
173
208
|
className: `weaverse-root`,
|
|
174
209
|
id: "weaverse-root"
|
|
175
|
-
}, handleProps), /* @__PURE__ */
|
|
210
|
+
}, handleProps), /* @__PURE__ */ React4.createElement(RenderItem, {
|
|
176
211
|
itemId: context.projectData.rootId || 0,
|
|
177
212
|
context
|
|
178
213
|
}));
|
|
179
214
|
};
|
|
180
215
|
var Item = ({ itemInstance, elementInstances, context }) => {
|
|
181
|
-
let [data, setData] =
|
|
216
|
+
let [data, setData] = React4.useState(itemInstance.data);
|
|
182
217
|
let _a = data, { id, type, childIds, css, className } = _a, rest = __objRest(_a, ["id", "type", "childIds", "css", "className"]);
|
|
183
|
-
|
|
218
|
+
React4.useEffect(() => {
|
|
184
219
|
let handleUpdate = (update) => {
|
|
185
220
|
setData(__spreadValues({}, update));
|
|
186
221
|
};
|
|
187
222
|
itemInstance.subscribe(handleUpdate);
|
|
188
|
-
if (!itemInstance.ref.current
|
|
189
|
-
Object.assign(itemInstance.ref, {
|
|
223
|
+
if (import_core.isBrowser && !itemInstance.ref.current) {
|
|
224
|
+
Object.assign(itemInstance.ref, {
|
|
225
|
+
current: document.querySelector(`[data-wv-id="${id}"]`)
|
|
226
|
+
});
|
|
190
227
|
}
|
|
191
228
|
return () => {
|
|
192
229
|
itemInstance.unsubscribe(handleUpdate);
|
|
193
230
|
};
|
|
194
231
|
}, []);
|
|
195
|
-
let realClassName = className
|
|
232
|
+
let realClassName = className;
|
|
196
233
|
if (css) {
|
|
197
234
|
let selector = context.stitchesInstance.css(css)().className;
|
|
198
|
-
realClassName
|
|
235
|
+
realClassName = realClassName ? `${selector} ${realClassName}` : selector;
|
|
199
236
|
}
|
|
200
|
-
let
|
|
201
|
-
if (Component) {
|
|
237
|
+
let element = elementInstances.get(type) || elementInstances.get("base");
|
|
238
|
+
if (element == null ? void 0 : element.Component) {
|
|
239
|
+
let Component = element.Component;
|
|
202
240
|
if (Component.$$typeof === Symbol.for("react.forward_ref")) {
|
|
203
241
|
rest.ref = itemInstance.ref;
|
|
204
242
|
}
|
|
205
|
-
return /* @__PURE__ */
|
|
243
|
+
return /* @__PURE__ */ React4.createElement(Component, __spreadProps(__spreadValues({
|
|
206
244
|
key: id,
|
|
207
245
|
"data-wv-id": id
|
|
208
246
|
}, rest), {
|
|
209
247
|
className: realClassName
|
|
210
|
-
}), Array.isArray(childIds) && childIds.map((childId) => /* @__PURE__ */
|
|
248
|
+
}), Array.isArray(childIds) && childIds.map((childId) => /* @__PURE__ */ React4.createElement(RenderItem, {
|
|
211
249
|
key: childId,
|
|
212
250
|
itemId: childId,
|
|
213
251
|
context
|
|
@@ -215,19 +253,24 @@ var Item = ({ itemInstance, elementInstances, context }) => {
|
|
|
215
253
|
}
|
|
216
254
|
return null;
|
|
217
255
|
};
|
|
218
|
-
var RenderItem = ({
|
|
256
|
+
var RenderItem = ({
|
|
257
|
+
itemId,
|
|
258
|
+
context
|
|
259
|
+
}) => {
|
|
219
260
|
let { itemInstances, elementInstances } = context;
|
|
220
261
|
let itemInstance = itemInstances.get(itemId);
|
|
221
262
|
if (itemInstance) {
|
|
222
|
-
return /* @__PURE__ */
|
|
263
|
+
return /* @__PURE__ */ React4.createElement(Item, {
|
|
223
264
|
itemInstance,
|
|
224
265
|
elementInstances,
|
|
225
266
|
context
|
|
226
267
|
});
|
|
227
268
|
}
|
|
228
|
-
return /* @__PURE__ */
|
|
269
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null);
|
|
229
270
|
};
|
|
230
|
-
|
|
271
|
+
|
|
272
|
+
// src/index.ts
|
|
273
|
+
__reExport(src_exports, require("@weaverse/core"), module.exports);
|
|
231
274
|
// Annotate the CommonJS export names for ESM import in node:
|
|
232
275
|
0 && (module.exports = {
|
|
233
276
|
WeaverseRoot,
|
package/dist/index.mjs
CHANGED
|
@@ -30,99 +30,142 @@ var __objRest = (source, exclude) => {
|
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
// src/renderer.tsx
|
|
34
|
-
import * as React5 from "react";
|
|
35
|
-
import { isBrowser, Weaverse } from "@weaverse/core";
|
|
36
|
-
|
|
37
|
-
// src/elements/button.tsx
|
|
38
|
-
import * as React from "react";
|
|
39
|
-
var Button = React.forwardRef((props, ref) => {
|
|
40
|
-
let [count, setCount] = React.useState(0);
|
|
41
|
-
return /* @__PURE__ */ React.createElement("button", __spreadProps(__spreadValues({
|
|
42
|
-
ref
|
|
43
|
-
}, props), {
|
|
44
|
-
onClick: () => setCount(count + 1)
|
|
45
|
-
}), "Test Button ", count);
|
|
46
|
-
});
|
|
47
|
-
Button.defaultProps = {
|
|
48
|
-
style: {
|
|
49
|
-
borderRadius: "9999px",
|
|
50
|
-
fontSize: "13px",
|
|
51
|
-
padding: "10px 15px"
|
|
52
|
-
},
|
|
53
|
-
type: "button",
|
|
54
|
-
tag: "button"
|
|
55
|
-
};
|
|
56
|
-
var button_default = Button;
|
|
57
|
-
|
|
58
33
|
// src/elements/base.tsx
|
|
59
|
-
import
|
|
60
|
-
var BaseElement =
|
|
34
|
+
import React from "react";
|
|
35
|
+
var BaseElement = React.forwardRef((_a, ref) => {
|
|
61
36
|
var _b = _a, { tag, children } = _b, props = __objRest(_b, ["tag", "children"]);
|
|
62
|
-
return
|
|
37
|
+
return React.createElement(tag, __spreadValues({
|
|
63
38
|
ref
|
|
64
39
|
}, props), children);
|
|
65
40
|
});
|
|
66
41
|
BaseElement.defaultProps = {
|
|
67
|
-
type: "base",
|
|
68
42
|
tag: "div",
|
|
69
43
|
style: {}
|
|
70
44
|
};
|
|
45
|
+
var schema = {
|
|
46
|
+
type: "base"
|
|
47
|
+
};
|
|
71
48
|
var base_default = BaseElement;
|
|
72
49
|
|
|
73
|
-
// src/elements/
|
|
74
|
-
import
|
|
75
|
-
|
|
76
|
-
return /* @__PURE__ */
|
|
77
|
-
|
|
78
|
-
|
|
50
|
+
// src/elements/button.tsx
|
|
51
|
+
import * as React2 from "react";
|
|
52
|
+
var Button = React2.forwardRef((props, ref) => {
|
|
53
|
+
return /* @__PURE__ */ React2.createElement("button", __spreadValues({
|
|
54
|
+
ref
|
|
55
|
+
}, props), props.value);
|
|
56
|
+
});
|
|
57
|
+
Button.defaultProps = {
|
|
58
|
+
value: "Click me",
|
|
79
59
|
style: {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
borderRadius: "9999px",
|
|
61
|
+
fontSize: "13px",
|
|
62
|
+
padding: "10px 15px"
|
|
63
|
+
}
|
|
84
64
|
};
|
|
65
|
+
var schema2 = {
|
|
66
|
+
title: "Button",
|
|
67
|
+
type: "button",
|
|
68
|
+
settings: [
|
|
69
|
+
{
|
|
70
|
+
tab: "Settings",
|
|
71
|
+
label: "Group 1",
|
|
72
|
+
inspectors: [
|
|
73
|
+
{
|
|
74
|
+
binding: "data",
|
|
75
|
+
key: "value",
|
|
76
|
+
componentType: "textarea"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
binding: "style",
|
|
80
|
+
key: "backgroundColor",
|
|
81
|
+
componentType: "color"
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
tab: "Settings",
|
|
87
|
+
label: "Group 2",
|
|
88
|
+
inspectors: [
|
|
89
|
+
{
|
|
90
|
+
binding: "style",
|
|
91
|
+
key: "color",
|
|
92
|
+
componentType: "color"
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
};
|
|
98
|
+
var button_default = Button;
|
|
85
99
|
|
|
86
100
|
// src/elements/text.tsx
|
|
87
|
-
import * as
|
|
88
|
-
var Text =
|
|
89
|
-
let _a = props, { children } = _a, rest = __objRest(_a, ["children"]);
|
|
90
|
-
return /* @__PURE__ */
|
|
101
|
+
import * as React3 from "react";
|
|
102
|
+
var Text = React3.forwardRef((props, ref) => {
|
|
103
|
+
let _a = props, { children, value } = _a, rest = __objRest(_a, ["children", "value"]);
|
|
104
|
+
return /* @__PURE__ */ React3.createElement("span", __spreadProps(__spreadValues({
|
|
91
105
|
ref
|
|
92
106
|
}, rest), {
|
|
93
107
|
contentEditable: true,
|
|
94
|
-
dangerouslySetInnerHTML: { __html:
|
|
108
|
+
dangerouslySetInnerHTML: { __html: value }
|
|
95
109
|
}));
|
|
96
110
|
});
|
|
97
111
|
Text.defaultProps = {
|
|
98
|
-
|
|
99
|
-
type: "text",
|
|
112
|
+
value: "sample text",
|
|
100
113
|
tag: "span"
|
|
101
114
|
};
|
|
115
|
+
var schema3 = {
|
|
116
|
+
type: "text",
|
|
117
|
+
inspectors: [
|
|
118
|
+
{
|
|
119
|
+
binding: "data",
|
|
120
|
+
key: "value",
|
|
121
|
+
componentType: "textarea"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
binding: "style",
|
|
125
|
+
key: "color",
|
|
126
|
+
componentType: "color"
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
};
|
|
102
130
|
var text_default = Text;
|
|
103
131
|
|
|
104
132
|
// src/elements/index.ts
|
|
105
133
|
var elements = {
|
|
106
|
-
Button:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
134
|
+
Button: {
|
|
135
|
+
Component: button_default,
|
|
136
|
+
schema: schema2
|
|
137
|
+
},
|
|
138
|
+
BaseElement: {
|
|
139
|
+
Component: base_default,
|
|
140
|
+
schema
|
|
141
|
+
},
|
|
142
|
+
Text: {
|
|
143
|
+
Component: text_default,
|
|
144
|
+
schema: schema3
|
|
145
|
+
}
|
|
110
146
|
};
|
|
111
147
|
var elements_default = elements;
|
|
112
148
|
|
|
113
149
|
// src/renderer.tsx
|
|
150
|
+
import {
|
|
151
|
+
isBrowser,
|
|
152
|
+
Weaverse
|
|
153
|
+
} from "@weaverse/core";
|
|
154
|
+
import * as React4 from "react";
|
|
114
155
|
var createRootContext = (configs) => {
|
|
115
156
|
const rootContext = new Weaverse(configs);
|
|
116
157
|
Object.keys(elements_default).forEach((key) => {
|
|
117
|
-
|
|
118
|
-
((_b = (_a = elements_default[key]) == null ? void 0 : _a.defaultProps) == null ? void 0 : _b.type) && rootContext.registerElement(elements_default[key].defaultProps.type, elements_default[key]);
|
|
158
|
+
rootContext.registerElement(elements_default[key]);
|
|
119
159
|
});
|
|
120
160
|
return rootContext;
|
|
121
161
|
};
|
|
122
|
-
var WeaverseRoot = ({
|
|
162
|
+
var WeaverseRoot = ({
|
|
163
|
+
context,
|
|
164
|
+
defaultData
|
|
165
|
+
}) => {
|
|
123
166
|
var _a, _b, _c;
|
|
124
|
-
let [, setData] =
|
|
125
|
-
|
|
167
|
+
let [, setData] = React4.useState(context.projectData);
|
|
168
|
+
React4.useEffect(() => {
|
|
126
169
|
let handleUpdate = () => {
|
|
127
170
|
setData(__spreadValues({}, context.projectData));
|
|
128
171
|
};
|
|
@@ -137,45 +180,48 @@ var WeaverseRoot = ({ context, defaultData }) => {
|
|
|
137
180
|
context.initProjectItemData();
|
|
138
181
|
}
|
|
139
182
|
let handleProps = ((_c = context == null ? void 0 : context.studioBridge) == null ? void 0 : _c.handleProps) || {};
|
|
140
|
-
return /* @__PURE__ */
|
|
183
|
+
return /* @__PURE__ */ React4.createElement("div", __spreadValues({
|
|
141
184
|
className: `weaverse-root`,
|
|
142
185
|
id: "weaverse-root"
|
|
143
|
-
}, handleProps), /* @__PURE__ */
|
|
186
|
+
}, handleProps), /* @__PURE__ */ React4.createElement(RenderItem, {
|
|
144
187
|
itemId: context.projectData.rootId || 0,
|
|
145
188
|
context
|
|
146
189
|
}));
|
|
147
190
|
};
|
|
148
191
|
var Item = ({ itemInstance, elementInstances, context }) => {
|
|
149
|
-
let [data, setData] =
|
|
192
|
+
let [data, setData] = React4.useState(itemInstance.data);
|
|
150
193
|
let _a = data, { id, type, childIds, css, className } = _a, rest = __objRest(_a, ["id", "type", "childIds", "css", "className"]);
|
|
151
|
-
|
|
194
|
+
React4.useEffect(() => {
|
|
152
195
|
let handleUpdate = (update) => {
|
|
153
196
|
setData(__spreadValues({}, update));
|
|
154
197
|
};
|
|
155
198
|
itemInstance.subscribe(handleUpdate);
|
|
156
|
-
if (!itemInstance.ref.current
|
|
157
|
-
Object.assign(itemInstance.ref, {
|
|
199
|
+
if (isBrowser && !itemInstance.ref.current) {
|
|
200
|
+
Object.assign(itemInstance.ref, {
|
|
201
|
+
current: document.querySelector(`[data-wv-id="${id}"]`)
|
|
202
|
+
});
|
|
158
203
|
}
|
|
159
204
|
return () => {
|
|
160
205
|
itemInstance.unsubscribe(handleUpdate);
|
|
161
206
|
};
|
|
162
207
|
}, []);
|
|
163
|
-
let realClassName = className
|
|
208
|
+
let realClassName = className;
|
|
164
209
|
if (css) {
|
|
165
210
|
let selector = context.stitchesInstance.css(css)().className;
|
|
166
|
-
realClassName
|
|
211
|
+
realClassName = realClassName ? `${selector} ${realClassName}` : selector;
|
|
167
212
|
}
|
|
168
|
-
let
|
|
169
|
-
if (Component) {
|
|
213
|
+
let element = elementInstances.get(type) || elementInstances.get("base");
|
|
214
|
+
if (element == null ? void 0 : element.Component) {
|
|
215
|
+
let Component = element.Component;
|
|
170
216
|
if (Component.$$typeof === Symbol.for("react.forward_ref")) {
|
|
171
217
|
rest.ref = itemInstance.ref;
|
|
172
218
|
}
|
|
173
|
-
return /* @__PURE__ */
|
|
219
|
+
return /* @__PURE__ */ React4.createElement(Component, __spreadProps(__spreadValues({
|
|
174
220
|
key: id,
|
|
175
221
|
"data-wv-id": id
|
|
176
222
|
}, rest), {
|
|
177
223
|
className: realClassName
|
|
178
|
-
}), Array.isArray(childIds) && childIds.map((childId) => /* @__PURE__ */
|
|
224
|
+
}), Array.isArray(childIds) && childIds.map((childId) => /* @__PURE__ */ React4.createElement(RenderItem, {
|
|
179
225
|
key: childId,
|
|
180
226
|
itemId: childId,
|
|
181
227
|
context
|
|
@@ -183,18 +229,24 @@ var Item = ({ itemInstance, elementInstances, context }) => {
|
|
|
183
229
|
}
|
|
184
230
|
return null;
|
|
185
231
|
};
|
|
186
|
-
var RenderItem = ({
|
|
232
|
+
var RenderItem = ({
|
|
233
|
+
itemId,
|
|
234
|
+
context
|
|
235
|
+
}) => {
|
|
187
236
|
let { itemInstances, elementInstances } = context;
|
|
188
237
|
let itemInstance = itemInstances.get(itemId);
|
|
189
238
|
if (itemInstance) {
|
|
190
|
-
return /* @__PURE__ */
|
|
239
|
+
return /* @__PURE__ */ React4.createElement(Item, {
|
|
191
240
|
itemInstance,
|
|
192
241
|
elementInstances,
|
|
193
242
|
context
|
|
194
243
|
});
|
|
195
244
|
}
|
|
196
|
-
return /* @__PURE__ */
|
|
245
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null);
|
|
197
246
|
};
|
|
247
|
+
|
|
248
|
+
// src/index.ts
|
|
249
|
+
export * from "@weaverse/core";
|
|
198
250
|
export {
|
|
199
251
|
WeaverseRoot,
|
|
200
252
|
createRootContext
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.3.
|
|
2
|
+
"version": "0.3.7",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -25,13 +25,12 @@
|
|
|
25
25
|
},
|
|
26
26
|
"prettier": {
|
|
27
27
|
"printWidth": 80,
|
|
28
|
-
"semi":
|
|
29
|
-
"singleQuote": true
|
|
30
|
-
"trailingComma": "es5"
|
|
28
|
+
"semi": false,
|
|
29
|
+
"singleQuote": true
|
|
31
30
|
},
|
|
32
31
|
"name": "@weaverse/react",
|
|
33
32
|
"author": "Weaverse Team",
|
|
34
33
|
"dependencies": {
|
|
35
|
-
"@weaverse/core": "^0.3.
|
|
34
|
+
"@weaverse/core": "^0.3.6"
|
|
36
35
|
}
|
|
37
36
|
}
|