@weaverse/react 0.3.7 → 0.4.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.
Files changed (3) hide show
  1. package/dist/index.js +148 -38
  2. package/dist/index.mjs +148 -38
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -70,29 +70,70 @@ BaseElement.defaultProps = {
70
70
  style: {}
71
71
  };
72
72
  var schema = {
73
- type: "base"
73
+ type: "base",
74
+ title: "Base",
75
+ settings: []
74
76
  };
75
77
  var base_default = BaseElement;
76
78
 
77
79
  // src/elements/button.tsx
78
80
  var React2 = __toESM(require("react"));
79
81
  var Button = React2.forwardRef((props, ref) => {
82
+ const _a = props, { style, buttonType, css } = _a, rest = __objRest(_a, ["style", "buttonType", "css"]);
80
83
  return /* @__PURE__ */ React2.createElement("button", __spreadValues({
81
- ref
82
- }, props), props.value);
84
+ ref,
85
+ style
86
+ }, rest), props.value);
83
87
  });
84
88
  Button.defaultProps = {
85
- value: "Click me",
86
- style: {
87
- borderRadius: "9999px",
88
- fontSize: "13px",
89
- padding: "10px 15px"
90
- }
89
+ value: "Click me"
91
90
  };
92
91
  var schema2 = {
93
92
  title: "Button",
94
93
  type: "button",
95
94
  settings: [
95
+ {
96
+ tab: "Settings",
97
+ label: "Alignment",
98
+ inspectors: [
99
+ {
100
+ binding: "style",
101
+ type: "alignment"
102
+ }
103
+ ]
104
+ },
105
+ {
106
+ tab: "Settings",
107
+ label: "Spacing",
108
+ inspectors: [
109
+ {
110
+ binding: "style",
111
+ type: "spacing"
112
+ }
113
+ ]
114
+ },
115
+ {
116
+ tab: "Settings",
117
+ label: "Overlay",
118
+ inspectors: [
119
+ {
120
+ binding: "data",
121
+ key: "applyOverlay",
122
+ label: "Apply Overlay",
123
+ type: "switch"
124
+ },
125
+ {
126
+ binding: "data",
127
+ key: "buttonType",
128
+ label: "Button Type",
129
+ type: "select",
130
+ options: [
131
+ { value: 1, label: "One" },
132
+ { value: 2, label: "Two" }
133
+ ]
134
+ }
135
+ ]
136
+ },
96
137
  {
97
138
  tab: "Settings",
98
139
  label: "Group 1",
@@ -100,12 +141,14 @@ var schema2 = {
100
141
  {
101
142
  binding: "data",
102
143
  key: "value",
103
- componentType: "textarea"
144
+ type: "textarea",
145
+ label: "",
146
+ default: ""
104
147
  },
105
148
  {
106
149
  binding: "style",
107
150
  key: "backgroundColor",
108
- componentType: "color"
151
+ type: "color"
109
152
  }
110
153
  ]
111
154
  },
@@ -116,19 +159,65 @@ var schema2 = {
116
159
  {
117
160
  binding: "style",
118
161
  key: "color",
119
- componentType: "color"
162
+ type: "color"
120
163
  }
121
164
  ]
122
165
  }
123
- ]
166
+ ],
167
+ toolbar: [],
168
+ data: {
169
+ css: {
170
+ "@desktop": {
171
+ borderRadius: "9999px",
172
+ fontSize: "13px",
173
+ padding: "10px 15px"
174
+ }
175
+ }
176
+ }
124
177
  };
125
178
  var button_default = Button;
126
179
 
180
+ // src/elements/grid.tsx
181
+ var import_react2 = __toESM(require("react"));
182
+ var Grid = (0, import_react2.forwardRef)((props, ref) => {
183
+ return /* @__PURE__ */ import_react2.default.createElement("div", __spreadValues({
184
+ ref
185
+ }, props));
186
+ });
187
+ var schema3 = {
188
+ title: "Grid",
189
+ type: "grid",
190
+ data: {
191
+ css: {
192
+ "@desktop": {
193
+ display: "grid",
194
+ gridTemplateRows: "repeat(auto-fill, 48px)",
195
+ gridTemplateColumns: "repeat(24, 1fr)",
196
+ gridGap: "8px",
197
+ minHeight: "480px",
198
+ backgroundColor: "#c7c7c7"
199
+ }
200
+ }
201
+ },
202
+ settings: [
203
+ {
204
+ tab: "Layout",
205
+ label: "Grid",
206
+ inspectors: [
207
+ {
208
+ type: "grid"
209
+ }
210
+ ]
211
+ }
212
+ ]
213
+ };
214
+ var grid_default = Grid;
215
+
127
216
  // src/elements/text.tsx
128
- var React3 = __toESM(require("react"));
129
- var Text = React3.forwardRef((props, ref) => {
217
+ var React4 = __toESM(require("react"));
218
+ var Text = React4.forwardRef((props, ref) => {
130
219
  let _a = props, { children, value } = _a, rest = __objRest(_a, ["children", "value"]);
131
- return /* @__PURE__ */ React3.createElement("span", __spreadProps(__spreadValues({
220
+ return /* @__PURE__ */ React4.createElement("span", __spreadProps(__spreadValues({
132
221
  ref
133
222
  }, rest), {
134
223
  contentEditable: true,
@@ -139,18 +228,25 @@ Text.defaultProps = {
139
228
  value: "sample text",
140
229
  tag: "span"
141
230
  };
142
- var schema3 = {
231
+ var schema4 = {
143
232
  type: "text",
144
- inspectors: [
145
- {
146
- binding: "data",
147
- key: "value",
148
- componentType: "textarea"
149
- },
233
+ title: "Text Settings",
234
+ settings: [
150
235
  {
151
- binding: "style",
152
- key: "color",
153
- componentType: "color"
236
+ tab: "General",
237
+ label: "Text",
238
+ inspectors: [
239
+ {
240
+ binding: "data",
241
+ key: "value",
242
+ type: "textarea"
243
+ },
244
+ {
245
+ binding: "style",
246
+ key: "color",
247
+ type: "color"
248
+ }
249
+ ]
154
250
  }
155
251
  ]
156
252
  };
@@ -168,14 +264,27 @@ var elements = {
168
264
  },
169
265
  Text: {
170
266
  Component: text_default,
267
+ schema: schema4
268
+ },
269
+ Grid: {
270
+ Component: grid_default,
171
271
  schema: schema3
172
272
  }
173
273
  };
174
274
  var elements_default = elements;
175
275
 
276
+ // src/utils/css.ts
277
+ var shortCssObject = (css) => {
278
+ return {
279
+ "@desktop": css[`@desktop`],
280
+ "@tablet": css[`@tablet`],
281
+ "@mobile": css[`@mobile`]
282
+ };
283
+ };
284
+
176
285
  // src/renderer.tsx
177
286
  var import_core = require("@weaverse/core");
178
- var React4 = __toESM(require("react"));
287
+ var React5 = __toESM(require("react"));
179
288
  var createRootContext = (configs) => {
180
289
  const rootContext = new import_core.Weaverse(configs);
181
290
  Object.keys(elements_default).forEach((key) => {
@@ -188,8 +297,8 @@ var WeaverseRoot = ({
188
297
  defaultData
189
298
  }) => {
190
299
  var _a, _b, _c;
191
- let [, setData] = React4.useState(context.projectData);
192
- React4.useEffect(() => {
300
+ let [, setData] = React5.useState(context.projectData);
301
+ React5.useEffect(() => {
193
302
  let handleUpdate = () => {
194
303
  setData(__spreadValues({}, context.projectData));
195
304
  };
@@ -204,18 +313,18 @@ var WeaverseRoot = ({
204
313
  context.initProjectItemData();
205
314
  }
206
315
  let handleProps = ((_c = context == null ? void 0 : context.studioBridge) == null ? void 0 : _c.handleProps) || {};
207
- return /* @__PURE__ */ React4.createElement("div", __spreadValues({
316
+ return /* @__PURE__ */ React5.createElement("div", __spreadValues({
208
317
  className: `weaverse-root`,
209
318
  id: "weaverse-root"
210
- }, handleProps), /* @__PURE__ */ React4.createElement(RenderItem, {
319
+ }, handleProps), /* @__PURE__ */ React5.createElement(RenderItem, {
211
320
  itemId: context.projectData.rootId || 0,
212
321
  context
213
322
  }));
214
323
  };
215
324
  var Item = ({ itemInstance, elementInstances, context }) => {
216
- let [data, setData] = React4.useState(itemInstance.data);
325
+ let [data, setData] = React5.useState(itemInstance.data);
217
326
  let _a = data, { id, type, childIds, css, className } = _a, rest = __objRest(_a, ["id", "type", "childIds", "css", "className"]);
218
- React4.useEffect(() => {
327
+ React5.useEffect(() => {
219
328
  let handleUpdate = (update) => {
220
329
  setData(__spreadValues({}, update));
221
330
  };
@@ -231,7 +340,8 @@ var Item = ({ itemInstance, elementInstances, context }) => {
231
340
  }, []);
232
341
  let realClassName = className;
233
342
  if (css) {
234
- let selector = context.stitchesInstance.css(css)().className;
343
+ let formattedCss = shortCssObject(css);
344
+ let selector = context.stitchesInstance.css(formattedCss)().className;
235
345
  realClassName = realClassName ? `${selector} ${realClassName}` : selector;
236
346
  }
237
347
  let element = elementInstances.get(type) || elementInstances.get("base");
@@ -240,12 +350,12 @@ var Item = ({ itemInstance, elementInstances, context }) => {
240
350
  if (Component.$$typeof === Symbol.for("react.forward_ref")) {
241
351
  rest.ref = itemInstance.ref;
242
352
  }
243
- return /* @__PURE__ */ React4.createElement(Component, __spreadProps(__spreadValues({
353
+ return /* @__PURE__ */ React5.createElement(Component, __spreadProps(__spreadValues({
244
354
  key: id,
245
355
  "data-wv-id": id
246
356
  }, rest), {
247
357
  className: realClassName
248
- }), Array.isArray(childIds) && childIds.map((childId) => /* @__PURE__ */ React4.createElement(RenderItem, {
358
+ }), Array.isArray(childIds) && childIds.map((childId) => /* @__PURE__ */ React5.createElement(RenderItem, {
249
359
  key: childId,
250
360
  itemId: childId,
251
361
  context
@@ -260,13 +370,13 @@ var RenderItem = ({
260
370
  let { itemInstances, elementInstances } = context;
261
371
  let itemInstance = itemInstances.get(itemId);
262
372
  if (itemInstance) {
263
- return /* @__PURE__ */ React4.createElement(Item, {
373
+ return /* @__PURE__ */ React5.createElement(Item, {
264
374
  itemInstance,
265
375
  elementInstances,
266
376
  context
267
377
  });
268
378
  }
269
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null);
379
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null);
270
380
  };
271
381
 
272
382
  // src/index.ts
package/dist/index.mjs CHANGED
@@ -43,29 +43,70 @@ BaseElement.defaultProps = {
43
43
  style: {}
44
44
  };
45
45
  var schema = {
46
- type: "base"
46
+ type: "base",
47
+ title: "Base",
48
+ settings: []
47
49
  };
48
50
  var base_default = BaseElement;
49
51
 
50
52
  // src/elements/button.tsx
51
53
  import * as React2 from "react";
52
54
  var Button = React2.forwardRef((props, ref) => {
55
+ const _a = props, { style, buttonType, css } = _a, rest = __objRest(_a, ["style", "buttonType", "css"]);
53
56
  return /* @__PURE__ */ React2.createElement("button", __spreadValues({
54
- ref
55
- }, props), props.value);
57
+ ref,
58
+ style
59
+ }, rest), props.value);
56
60
  });
57
61
  Button.defaultProps = {
58
- value: "Click me",
59
- style: {
60
- borderRadius: "9999px",
61
- fontSize: "13px",
62
- padding: "10px 15px"
63
- }
62
+ value: "Click me"
64
63
  };
65
64
  var schema2 = {
66
65
  title: "Button",
67
66
  type: "button",
68
67
  settings: [
68
+ {
69
+ tab: "Settings",
70
+ label: "Alignment",
71
+ inspectors: [
72
+ {
73
+ binding: "style",
74
+ type: "alignment"
75
+ }
76
+ ]
77
+ },
78
+ {
79
+ tab: "Settings",
80
+ label: "Spacing",
81
+ inspectors: [
82
+ {
83
+ binding: "style",
84
+ type: "spacing"
85
+ }
86
+ ]
87
+ },
88
+ {
89
+ tab: "Settings",
90
+ label: "Overlay",
91
+ inspectors: [
92
+ {
93
+ binding: "data",
94
+ key: "applyOverlay",
95
+ label: "Apply Overlay",
96
+ type: "switch"
97
+ },
98
+ {
99
+ binding: "data",
100
+ key: "buttonType",
101
+ label: "Button Type",
102
+ type: "select",
103
+ options: [
104
+ { value: 1, label: "One" },
105
+ { value: 2, label: "Two" }
106
+ ]
107
+ }
108
+ ]
109
+ },
69
110
  {
70
111
  tab: "Settings",
71
112
  label: "Group 1",
@@ -73,12 +114,14 @@ var schema2 = {
73
114
  {
74
115
  binding: "data",
75
116
  key: "value",
76
- componentType: "textarea"
117
+ type: "textarea",
118
+ label: "",
119
+ default: ""
77
120
  },
78
121
  {
79
122
  binding: "style",
80
123
  key: "backgroundColor",
81
- componentType: "color"
124
+ type: "color"
82
125
  }
83
126
  ]
84
127
  },
@@ -89,19 +132,65 @@ var schema2 = {
89
132
  {
90
133
  binding: "style",
91
134
  key: "color",
92
- componentType: "color"
135
+ type: "color"
93
136
  }
94
137
  ]
95
138
  }
96
- ]
139
+ ],
140
+ toolbar: [],
141
+ data: {
142
+ css: {
143
+ "@desktop": {
144
+ borderRadius: "9999px",
145
+ fontSize: "13px",
146
+ padding: "10px 15px"
147
+ }
148
+ }
149
+ }
97
150
  };
98
151
  var button_default = Button;
99
152
 
153
+ // src/elements/grid.tsx
154
+ import React3, { forwardRef as forwardRef2 } from "react";
155
+ var Grid = forwardRef2((props, ref) => {
156
+ return /* @__PURE__ */ React3.createElement("div", __spreadValues({
157
+ ref
158
+ }, props));
159
+ });
160
+ var schema3 = {
161
+ title: "Grid",
162
+ type: "grid",
163
+ data: {
164
+ css: {
165
+ "@desktop": {
166
+ display: "grid",
167
+ gridTemplateRows: "repeat(auto-fill, 48px)",
168
+ gridTemplateColumns: "repeat(24, 1fr)",
169
+ gridGap: "8px",
170
+ minHeight: "480px",
171
+ backgroundColor: "#c7c7c7"
172
+ }
173
+ }
174
+ },
175
+ settings: [
176
+ {
177
+ tab: "Layout",
178
+ label: "Grid",
179
+ inspectors: [
180
+ {
181
+ type: "grid"
182
+ }
183
+ ]
184
+ }
185
+ ]
186
+ };
187
+ var grid_default = Grid;
188
+
100
189
  // src/elements/text.tsx
101
- import * as React3 from "react";
102
- var Text = React3.forwardRef((props, ref) => {
190
+ import * as React4 from "react";
191
+ var Text = React4.forwardRef((props, ref) => {
103
192
  let _a = props, { children, value } = _a, rest = __objRest(_a, ["children", "value"]);
104
- return /* @__PURE__ */ React3.createElement("span", __spreadProps(__spreadValues({
193
+ return /* @__PURE__ */ React4.createElement("span", __spreadProps(__spreadValues({
105
194
  ref
106
195
  }, rest), {
107
196
  contentEditable: true,
@@ -112,18 +201,25 @@ Text.defaultProps = {
112
201
  value: "sample text",
113
202
  tag: "span"
114
203
  };
115
- var schema3 = {
204
+ var schema4 = {
116
205
  type: "text",
117
- inspectors: [
118
- {
119
- binding: "data",
120
- key: "value",
121
- componentType: "textarea"
122
- },
206
+ title: "Text Settings",
207
+ settings: [
123
208
  {
124
- binding: "style",
125
- key: "color",
126
- componentType: "color"
209
+ tab: "General",
210
+ label: "Text",
211
+ inspectors: [
212
+ {
213
+ binding: "data",
214
+ key: "value",
215
+ type: "textarea"
216
+ },
217
+ {
218
+ binding: "style",
219
+ key: "color",
220
+ type: "color"
221
+ }
222
+ ]
127
223
  }
128
224
  ]
129
225
  };
@@ -141,17 +237,30 @@ var elements = {
141
237
  },
142
238
  Text: {
143
239
  Component: text_default,
240
+ schema: schema4
241
+ },
242
+ Grid: {
243
+ Component: grid_default,
144
244
  schema: schema3
145
245
  }
146
246
  };
147
247
  var elements_default = elements;
148
248
 
249
+ // src/utils/css.ts
250
+ var shortCssObject = (css) => {
251
+ return {
252
+ "@desktop": css[`@desktop`],
253
+ "@tablet": css[`@tablet`],
254
+ "@mobile": css[`@mobile`]
255
+ };
256
+ };
257
+
149
258
  // src/renderer.tsx
150
259
  import {
151
260
  isBrowser,
152
261
  Weaverse
153
262
  } from "@weaverse/core";
154
- import * as React4 from "react";
263
+ import * as React5 from "react";
155
264
  var createRootContext = (configs) => {
156
265
  const rootContext = new Weaverse(configs);
157
266
  Object.keys(elements_default).forEach((key) => {
@@ -164,8 +273,8 @@ var WeaverseRoot = ({
164
273
  defaultData
165
274
  }) => {
166
275
  var _a, _b, _c;
167
- let [, setData] = React4.useState(context.projectData);
168
- React4.useEffect(() => {
276
+ let [, setData] = React5.useState(context.projectData);
277
+ React5.useEffect(() => {
169
278
  let handleUpdate = () => {
170
279
  setData(__spreadValues({}, context.projectData));
171
280
  };
@@ -180,18 +289,18 @@ var WeaverseRoot = ({
180
289
  context.initProjectItemData();
181
290
  }
182
291
  let handleProps = ((_c = context == null ? void 0 : context.studioBridge) == null ? void 0 : _c.handleProps) || {};
183
- return /* @__PURE__ */ React4.createElement("div", __spreadValues({
292
+ return /* @__PURE__ */ React5.createElement("div", __spreadValues({
184
293
  className: `weaverse-root`,
185
294
  id: "weaverse-root"
186
- }, handleProps), /* @__PURE__ */ React4.createElement(RenderItem, {
295
+ }, handleProps), /* @__PURE__ */ React5.createElement(RenderItem, {
187
296
  itemId: context.projectData.rootId || 0,
188
297
  context
189
298
  }));
190
299
  };
191
300
  var Item = ({ itemInstance, elementInstances, context }) => {
192
- let [data, setData] = React4.useState(itemInstance.data);
301
+ let [data, setData] = React5.useState(itemInstance.data);
193
302
  let _a = data, { id, type, childIds, css, className } = _a, rest = __objRest(_a, ["id", "type", "childIds", "css", "className"]);
194
- React4.useEffect(() => {
303
+ React5.useEffect(() => {
195
304
  let handleUpdate = (update) => {
196
305
  setData(__spreadValues({}, update));
197
306
  };
@@ -207,7 +316,8 @@ var Item = ({ itemInstance, elementInstances, context }) => {
207
316
  }, []);
208
317
  let realClassName = className;
209
318
  if (css) {
210
- let selector = context.stitchesInstance.css(css)().className;
319
+ let formattedCss = shortCssObject(css);
320
+ let selector = context.stitchesInstance.css(formattedCss)().className;
211
321
  realClassName = realClassName ? `${selector} ${realClassName}` : selector;
212
322
  }
213
323
  let element = elementInstances.get(type) || elementInstances.get("base");
@@ -216,12 +326,12 @@ var Item = ({ itemInstance, elementInstances, context }) => {
216
326
  if (Component.$$typeof === Symbol.for("react.forward_ref")) {
217
327
  rest.ref = itemInstance.ref;
218
328
  }
219
- return /* @__PURE__ */ React4.createElement(Component, __spreadProps(__spreadValues({
329
+ return /* @__PURE__ */ React5.createElement(Component, __spreadProps(__spreadValues({
220
330
  key: id,
221
331
  "data-wv-id": id
222
332
  }, rest), {
223
333
  className: realClassName
224
- }), Array.isArray(childIds) && childIds.map((childId) => /* @__PURE__ */ React4.createElement(RenderItem, {
334
+ }), Array.isArray(childIds) && childIds.map((childId) => /* @__PURE__ */ React5.createElement(RenderItem, {
225
335
  key: childId,
226
336
  itemId: childId,
227
337
  context
@@ -236,13 +346,13 @@ var RenderItem = ({
236
346
  let { itemInstances, elementInstances } = context;
237
347
  let itemInstance = itemInstances.get(itemId);
238
348
  if (itemInstance) {
239
- return /* @__PURE__ */ React4.createElement(Item, {
349
+ return /* @__PURE__ */ React5.createElement(Item, {
240
350
  itemInstance,
241
351
  elementInstances,
242
352
  context
243
353
  });
244
354
  }
245
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null);
355
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null);
246
356
  };
247
357
 
248
358
  // src/index.ts
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.7",
2
+ "version": "0.4.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -31,6 +31,6 @@
31
31
  "name": "@weaverse/react",
32
32
  "author": "Weaverse Team",
33
33
  "dependencies": {
34
- "@weaverse/core": "^0.3.6"
34
+ "@weaverse/core": "^0.4.2"
35
35
  }
36
36
  }