@webstudio-is/react-sdk 0.78.0 → 0.80.0
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/lib/cjs/context.js +8 -2
- package/lib/cjs/css/normalize.js +23 -43
- package/lib/cjs/css/presets.js +1 -111
- package/lib/cjs/embed-template.js +45 -16
- package/lib/cjs/expression.js +137 -22
- package/lib/cjs/index.js +6 -2
- package/lib/cjs/props.js +32 -2
- package/lib/cjs/tree/create-elements-tree.js +7 -2
- package/lib/cjs/tree/root.js +15 -7
- package/lib/context.js +8 -2
- package/lib/css/normalize.js +23 -33
- package/lib/css/presets.js +1 -111
- package/lib/embed-template.js +45 -16
- package/lib/expression.js +137 -22
- package/lib/index.js +13 -5
- package/lib/props.js +32 -2
- package/lib/tree/create-elements-tree.js +10 -3
- package/lib/tree/root.js +16 -8
- package/lib/types/components/component-meta.d.ts +30 -0
- package/lib/types/context.d.ts +5 -2
- package/lib/types/css/normalize.d.ts +0 -520
- package/lib/types/css/presets.d.ts +0 -282
- package/lib/types/embed-template.d.ts +38 -0
- package/lib/types/expression.d.ts +12 -4
- package/lib/types/index.d.ts +1 -1
- package/lib/types/props.d.ts +10 -0
- package/lib/types/tree/create-elements-tree.d.ts +6 -5
- package/lib/types/tree/root.d.ts +5 -5
- package/package.json +17 -16
- package/src/context.tsx +17 -4
- package/src/css/normalize.ts +23 -32
- package/src/css/presets.ts +0 -110
- package/src/embed-template.test.ts +84 -4
- package/src/embed-template.ts +51 -18
- package/src/expression.test.ts +106 -12
- package/src/expression.ts +157 -26
- package/src/index.ts +6 -2
- package/src/props.ts +33 -3
- package/src/tree/create-elements-tree.tsx +19 -10
- package/src/tree/root.ts +24 -13
package/lib/cjs/context.js
CHANGED
|
@@ -30,7 +30,13 @@ const ReactSdkContext = (0, import_react.createContext)({
|
|
|
30
30
|
assetsStore: (0, import_nanostores.atom)(/* @__PURE__ */ new Map()),
|
|
31
31
|
pagesStore: (0, import_nanostores.atom)(/* @__PURE__ */ new Map()),
|
|
32
32
|
dataSourceValuesStore: (0, import_nanostores.atom)(/* @__PURE__ */ new Map()),
|
|
33
|
-
|
|
34
|
-
throw Error("React SDK
|
|
33
|
+
executeEffectfulExpression: () => {
|
|
34
|
+
throw Error("React SDK executeEffectfulExpression is not implemented");
|
|
35
|
+
},
|
|
36
|
+
setDataSourceValues: () => {
|
|
37
|
+
throw Error("React SDK setBoundDataSourceValue is not implemented");
|
|
38
|
+
},
|
|
39
|
+
setBoundDataSourceValue: () => {
|
|
40
|
+
throw Error("React SDK setBoundDataSourceValue is not implemented");
|
|
35
41
|
}
|
|
36
42
|
});
|
package/lib/cjs/css/normalize.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var normalize_exports = {};
|
|
30
20
|
__export(normalize_exports, {
|
|
@@ -33,7 +23,6 @@ __export(normalize_exports, {
|
|
|
33
23
|
article: () => article,
|
|
34
24
|
aside: () => aside,
|
|
35
25
|
b: () => b,
|
|
36
|
-
blockquote: () => blockquote,
|
|
37
26
|
body: () => body,
|
|
38
27
|
button: () => button,
|
|
39
28
|
code: () => code,
|
|
@@ -78,25 +67,17 @@ __export(normalize_exports, {
|
|
|
78
67
|
ul: () => ul
|
|
79
68
|
});
|
|
80
69
|
module.exports = __toCommonJS(normalize_exports);
|
|
81
|
-
var
|
|
70
|
+
var import_presets = require("./presets");
|
|
82
71
|
const boxSizing = {
|
|
83
72
|
property: "boxSizing",
|
|
84
73
|
value: { type: "keyword", value: "border-box" }
|
|
85
74
|
};
|
|
86
|
-
const baseStyle = [
|
|
87
|
-
boxSizing,
|
|
88
|
-
...presets.borders,
|
|
89
|
-
...presets.outline
|
|
90
|
-
];
|
|
75
|
+
const baseStyle = [boxSizing, ...import_presets.borders, ...import_presets.outline];
|
|
91
76
|
const div = baseStyle;
|
|
92
77
|
const address = baseStyle;
|
|
93
78
|
const article = baseStyle;
|
|
94
79
|
const aside = baseStyle;
|
|
95
|
-
const
|
|
96
|
-
...baseStyle,
|
|
97
|
-
...presets.blockquote
|
|
98
|
-
];
|
|
99
|
-
const figure = [...baseStyle, ...presets.margins];
|
|
80
|
+
const figure = baseStyle;
|
|
100
81
|
const footer = baseStyle;
|
|
101
82
|
const header = baseStyle;
|
|
102
83
|
const main = baseStyle;
|
|
@@ -104,19 +85,19 @@ const nav = baseStyle;
|
|
|
104
85
|
const section = baseStyle;
|
|
105
86
|
const form = baseStyle;
|
|
106
87
|
const label = baseStyle;
|
|
107
|
-
const h1 =
|
|
108
|
-
const h2 =
|
|
109
|
-
const h3 =
|
|
110
|
-
const h4 =
|
|
111
|
-
const h5 =
|
|
112
|
-
const h6 =
|
|
88
|
+
const h1 = baseStyle;
|
|
89
|
+
const h2 = baseStyle;
|
|
90
|
+
const h3 = baseStyle;
|
|
91
|
+
const h4 = baseStyle;
|
|
92
|
+
const h5 = baseStyle;
|
|
93
|
+
const h6 = baseStyle;
|
|
113
94
|
const i = baseStyle;
|
|
114
95
|
const img = baseStyle;
|
|
115
96
|
const a = baseStyle;
|
|
116
97
|
const li = baseStyle;
|
|
117
98
|
const ul = baseStyle;
|
|
118
99
|
const ol = baseStyle;
|
|
119
|
-
const p =
|
|
100
|
+
const p = baseStyle;
|
|
120
101
|
const span = baseStyle;
|
|
121
102
|
const html = [
|
|
122
103
|
/* 1 */
|
|
@@ -135,7 +116,7 @@ const html = [
|
|
|
135
116
|
value: { type: "unit", value: 4, unit: "number" }
|
|
136
117
|
},
|
|
137
118
|
boxSizing,
|
|
138
|
-
...
|
|
119
|
+
...import_presets.borders
|
|
139
120
|
];
|
|
140
121
|
const body = [
|
|
141
122
|
/* 1 */
|
|
@@ -160,7 +141,7 @@ const body = [
|
|
|
160
141
|
property: "fontFamily",
|
|
161
142
|
value: {
|
|
162
143
|
type: "keyword",
|
|
163
|
-
value: "Arial, sans-serif"
|
|
144
|
+
value: "Arial, Roboto, sans-serif"
|
|
164
145
|
}
|
|
165
146
|
},
|
|
166
147
|
{
|
|
@@ -172,7 +153,7 @@ const body = [
|
|
|
172
153
|
value: { type: "unit", unit: "number", value: 1.2 }
|
|
173
154
|
},
|
|
174
155
|
boxSizing,
|
|
175
|
-
...
|
|
156
|
+
...import_presets.borders
|
|
176
157
|
];
|
|
177
158
|
const hr = [
|
|
178
159
|
/* 1 */
|
|
@@ -186,8 +167,7 @@ const hr = [
|
|
|
186
167
|
value: { type: "keyword", value: "inherit" }
|
|
187
168
|
},
|
|
188
169
|
boxSizing,
|
|
189
|
-
...
|
|
190
|
-
...presets.margins
|
|
170
|
+
...import_presets.borders
|
|
191
171
|
];
|
|
192
172
|
const b = [
|
|
193
173
|
{
|
|
@@ -195,7 +175,7 @@ const b = [
|
|
|
195
175
|
value: { type: "keyword", value: "700" }
|
|
196
176
|
},
|
|
197
177
|
boxSizing,
|
|
198
|
-
...
|
|
178
|
+
...import_presets.borders
|
|
199
179
|
];
|
|
200
180
|
const strong = b;
|
|
201
181
|
const code = [
|
|
@@ -213,7 +193,7 @@ const code = [
|
|
|
213
193
|
value: { type: "unit", value: 1, unit: "em" }
|
|
214
194
|
},
|
|
215
195
|
boxSizing,
|
|
216
|
-
...
|
|
196
|
+
...import_presets.borders
|
|
217
197
|
];
|
|
218
198
|
const kbd = code;
|
|
219
199
|
const samp = code;
|
|
@@ -224,7 +204,7 @@ const small = [
|
|
|
224
204
|
value: { type: "unit", value: 80, unit: "%" }
|
|
225
205
|
},
|
|
226
206
|
boxSizing,
|
|
227
|
-
...
|
|
207
|
+
...import_presets.borders
|
|
228
208
|
];
|
|
229
209
|
const subSupBase = [
|
|
230
210
|
{
|
|
@@ -244,7 +224,7 @@ const subSupBase = [
|
|
|
244
224
|
value: { type: "keyword", value: "baseline" }
|
|
245
225
|
},
|
|
246
226
|
boxSizing,
|
|
247
|
-
...
|
|
227
|
+
...import_presets.borders
|
|
248
228
|
];
|
|
249
229
|
const sub = [
|
|
250
230
|
...subSupBase,
|
|
@@ -266,7 +246,7 @@ const table = [
|
|
|
266
246
|
property: "textIndent",
|
|
267
247
|
value: { type: "unit", value: 0, unit: "number" }
|
|
268
248
|
},
|
|
269
|
-
...
|
|
249
|
+
...import_presets.borders,
|
|
270
250
|
/* 2 */
|
|
271
251
|
{
|
|
272
252
|
property: "borderTopColor",
|
|
@@ -318,7 +298,7 @@ const buttonBase = [
|
|
|
318
298
|
value: { type: "unit", value: 0, unit: "number" }
|
|
319
299
|
},
|
|
320
300
|
boxSizing,
|
|
321
|
-
...
|
|
301
|
+
...import_presets.borders
|
|
322
302
|
];
|
|
323
303
|
const input = buttonBase;
|
|
324
304
|
const optgroup = buttonBase;
|
|
@@ -349,7 +329,7 @@ const legend = [
|
|
|
349
329
|
value: { type: "unit", value: 0, unit: "number" }
|
|
350
330
|
},
|
|
351
331
|
boxSizing,
|
|
352
|
-
...
|
|
332
|
+
...import_presets.borders
|
|
353
333
|
];
|
|
354
334
|
const progress = [
|
|
355
335
|
{
|
|
@@ -357,7 +337,7 @@ const progress = [
|
|
|
357
337
|
value: { type: "keyword", value: "baseline" }
|
|
358
338
|
},
|
|
359
339
|
boxSizing,
|
|
360
|
-
...
|
|
340
|
+
...import_presets.borders
|
|
361
341
|
];
|
|
362
342
|
const summary = [
|
|
363
343
|
{
|
|
@@ -365,5 +345,5 @@ const summary = [
|
|
|
365
345
|
value: { type: "keyword", value: "list-item" }
|
|
366
346
|
},
|
|
367
347
|
boxSizing,
|
|
368
|
-
...
|
|
348
|
+
...import_presets.borders
|
|
369
349
|
];
|
package/lib/cjs/css/presets.js
CHANGED
|
@@ -18,17 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var presets_exports = {};
|
|
20
20
|
__export(presets_exports, {
|
|
21
|
-
blockquote: () => blockquote,
|
|
22
21
|
borders: () => borders,
|
|
23
|
-
|
|
24
|
-
h2: () => h2,
|
|
25
|
-
h3: () => h3,
|
|
26
|
-
h4: () => h4,
|
|
27
|
-
h5: () => h5,
|
|
28
|
-
h6: () => h6,
|
|
29
|
-
margins: () => margins,
|
|
30
|
-
outline: () => outline,
|
|
31
|
-
verticalMargins: () => verticalMargins
|
|
22
|
+
outline: () => outline
|
|
32
23
|
});
|
|
33
24
|
module.exports = __toCommonJS(presets_exports);
|
|
34
25
|
const borders = [
|
|
@@ -55,104 +46,3 @@ const outline = [
|
|
|
55
46
|
value: { type: "unit", value: 1, unit: "px" }
|
|
56
47
|
}
|
|
57
48
|
];
|
|
58
|
-
const margins = [
|
|
59
|
-
{
|
|
60
|
-
property: "marginTop",
|
|
61
|
-
value: { type: "unit", value: 0, unit: "px" }
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
property: "marginRight",
|
|
65
|
-
value: { type: "unit", value: 0, unit: "px" }
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
property: "marginBottom",
|
|
69
|
-
value: { type: "unit", value: 0, unit: "px" }
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
property: "marginLeft",
|
|
73
|
-
value: { type: "unit", value: 0, unit: "px" }
|
|
74
|
-
}
|
|
75
|
-
];
|
|
76
|
-
const verticalMargins = [
|
|
77
|
-
{
|
|
78
|
-
property: "marginTop",
|
|
79
|
-
value: { type: "unit", value: 0, unit: "px" }
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
property: "marginBottom",
|
|
83
|
-
value: { type: "unit", value: 0, unit: "px" }
|
|
84
|
-
}
|
|
85
|
-
];
|
|
86
|
-
const blockquote = [
|
|
87
|
-
...margins,
|
|
88
|
-
{
|
|
89
|
-
property: "paddingTop",
|
|
90
|
-
value: { type: "unit", value: 10, unit: "px" }
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
property: "paddingBottom",
|
|
94
|
-
value: { type: "unit", value: 10, unit: "px" }
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
property: "paddingLeft",
|
|
98
|
-
value: { type: "unit", value: 20, unit: "px" }
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
property: "paddingRight",
|
|
102
|
-
value: { type: "unit", value: 20, unit: "px" }
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
property: "borderLeftWidth",
|
|
106
|
-
value: { type: "unit", value: 5, unit: "px" }
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
property: "borderLeftStyle",
|
|
110
|
-
value: { type: "keyword", value: "solid" }
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
property: "borderLeftColor",
|
|
114
|
-
value: { type: "rgb", r: 226, g: 226, b: 226, alpha: 1 }
|
|
115
|
-
}
|
|
116
|
-
];
|
|
117
|
-
const h1 = [
|
|
118
|
-
...verticalMargins,
|
|
119
|
-
{
|
|
120
|
-
property: "fontSize",
|
|
121
|
-
value: { type: "unit", value: 38, unit: "px" }
|
|
122
|
-
}
|
|
123
|
-
];
|
|
124
|
-
const h2 = [
|
|
125
|
-
...verticalMargins,
|
|
126
|
-
{
|
|
127
|
-
property: "fontSize",
|
|
128
|
-
value: { type: "unit", value: 32, unit: "px" }
|
|
129
|
-
}
|
|
130
|
-
];
|
|
131
|
-
const h3 = [
|
|
132
|
-
...verticalMargins,
|
|
133
|
-
{
|
|
134
|
-
property: "fontSize",
|
|
135
|
-
value: { type: "unit", value: 24, unit: "px" }
|
|
136
|
-
}
|
|
137
|
-
];
|
|
138
|
-
const h4 = [
|
|
139
|
-
...verticalMargins,
|
|
140
|
-
{
|
|
141
|
-
property: "fontSize",
|
|
142
|
-
value: { type: "unit", value: 18, unit: "px" }
|
|
143
|
-
}
|
|
144
|
-
];
|
|
145
|
-
const h5 = [
|
|
146
|
-
...verticalMargins,
|
|
147
|
-
{
|
|
148
|
-
property: "fontSize",
|
|
149
|
-
value: { type: "unit", value: 14, unit: "px" }
|
|
150
|
-
}
|
|
151
|
-
];
|
|
152
|
-
const h6 = [
|
|
153
|
-
...verticalMargins,
|
|
154
|
-
{
|
|
155
|
-
property: "fontSize",
|
|
156
|
-
value: { type: "unit", value: 12, unit: "px" }
|
|
157
|
-
}
|
|
158
|
-
];
|
|
@@ -32,11 +32,12 @@ const EmbedTemplateText = import_zod.z.object({
|
|
|
32
32
|
type: import_zod.z.literal("text"),
|
|
33
33
|
value: import_zod.z.string()
|
|
34
34
|
});
|
|
35
|
+
const DataSourceVariableRef = import_zod.z.object({
|
|
36
|
+
type: import_zod.z.literal("variable"),
|
|
37
|
+
name: import_zod.z.string()
|
|
38
|
+
});
|
|
35
39
|
const DataSourceRef = import_zod.z.union([
|
|
36
|
-
|
|
37
|
-
type: import_zod.z.literal("variable"),
|
|
38
|
-
name: import_zod.z.string()
|
|
39
|
-
}),
|
|
40
|
+
DataSourceVariableRef,
|
|
40
41
|
import_zod.z.object({
|
|
41
42
|
type: import_zod.z.literal("expression"),
|
|
42
43
|
name: import_zod.z.string(),
|
|
@@ -67,6 +68,16 @@ const EmbedTemplateProp = import_zod.z.union([
|
|
|
67
68
|
name: import_zod.z.string(),
|
|
68
69
|
dataSourceRef: import_zod.z.optional(DataSourceRef),
|
|
69
70
|
value: import_zod.z.array(import_zod.z.string())
|
|
71
|
+
}),
|
|
72
|
+
import_zod.z.object({
|
|
73
|
+
type: import_zod.z.literal("action"),
|
|
74
|
+
name: import_zod.z.string(),
|
|
75
|
+
value: import_zod.z.array(
|
|
76
|
+
import_zod.z.object({
|
|
77
|
+
type: import_zod.z.literal("execute"),
|
|
78
|
+
code: import_zod.z.string()
|
|
79
|
+
})
|
|
80
|
+
)
|
|
70
81
|
})
|
|
71
82
|
]);
|
|
72
83
|
const EmbedTemplateStyleDeclRaw = import_zod.z.object({
|
|
@@ -97,6 +108,28 @@ const createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceB
|
|
|
97
108
|
if (item.props) {
|
|
98
109
|
for (const prop of item.props) {
|
|
99
110
|
const propId = (0, import_nanoid.nanoid)();
|
|
111
|
+
if (prop.type === "action") {
|
|
112
|
+
props.push({
|
|
113
|
+
id: propId,
|
|
114
|
+
instanceId,
|
|
115
|
+
type: "action",
|
|
116
|
+
name: prop.name,
|
|
117
|
+
value: prop.value.map((value) => {
|
|
118
|
+
return {
|
|
119
|
+
type: "execute",
|
|
120
|
+
// replace all references with variable names
|
|
121
|
+
code: (0, import_expression.validateExpression)(value.code, {
|
|
122
|
+
effectful: true,
|
|
123
|
+
transformIdentifier: (ref) => {
|
|
124
|
+
const id = dataSourceByRef.get(ref)?.id ?? ref;
|
|
125
|
+
return (0, import_expression.encodeDataSourceVariable)(id);
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
};
|
|
129
|
+
})
|
|
130
|
+
});
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
100
133
|
if (prop.dataSourceRef === void 0) {
|
|
101
134
|
props.push({ id: propId, instanceId, ...prop });
|
|
102
135
|
continue;
|
|
@@ -121,7 +154,13 @@ const createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceB
|
|
|
121
154
|
id,
|
|
122
155
|
scopeInstanceId: instanceId,
|
|
123
156
|
name: dataSourceRef.name,
|
|
124
|
-
|
|
157
|
+
// replace all references with variable names
|
|
158
|
+
code: (0, import_expression.validateExpression)(dataSourceRef.code, {
|
|
159
|
+
transformIdentifier: (ref) => {
|
|
160
|
+
const id2 = dataSourceByRef.get(ref)?.id ?? ref;
|
|
161
|
+
return (0, import_expression.encodeDataSourceVariable)(id2);
|
|
162
|
+
}
|
|
163
|
+
})
|
|
125
164
|
};
|
|
126
165
|
dataSourceByRef.set(dataSourceRef.name, dataSource);
|
|
127
166
|
} else {
|
|
@@ -207,21 +246,11 @@ const generateDataFromEmbedTemplate = (treeTemplate, defaultBreakpointId) => {
|
|
|
207
246
|
styles,
|
|
208
247
|
defaultBreakpointId
|
|
209
248
|
);
|
|
210
|
-
const dataSources = [];
|
|
211
|
-
for (const dataSource of dataSourceByRef.values()) {
|
|
212
|
-
if (dataSource.type === "expression") {
|
|
213
|
-
dataSource.code = (0, import_expression.validateExpression)(dataSource.code, (ref) => {
|
|
214
|
-
const id = dataSourceByRef.get(ref)?.id ?? ref;
|
|
215
|
-
return (0, import_expression.encodeDataSourceVariable)(id);
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
dataSources.push(dataSource);
|
|
219
|
-
}
|
|
220
249
|
return {
|
|
221
250
|
children,
|
|
222
251
|
instances,
|
|
223
252
|
props,
|
|
224
|
-
dataSources,
|
|
253
|
+
dataSources: Array.from(dataSourceByRef.values()),
|
|
225
254
|
styleSourceSelections,
|
|
226
255
|
styleSources,
|
|
227
256
|
styles
|