@webstudio-is/react-sdk 0.91.0 → 0.93.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/app/index.js +1 -0
- package/lib/app/root.js +2 -4
- package/lib/component-renderer.js +3 -5
- package/lib/components/component-meta.js +6 -11
- package/lib/components/components-utils.js +1 -0
- package/lib/context.js +2 -4
- package/lib/css/css.js +4 -9
- package/lib/css/global-rules.js +3 -5
- package/lib/css/index.js +1 -0
- package/lib/css/normalize-type-check.js +1 -0
- package/lib/css/normalize.js +48 -96
- package/lib/css/presets.js +3 -6
- package/lib/css/style-rules.js +3 -6
- package/{src/css/style-rules.test.ts → lib/css/style-rules.test.js} +23 -28
- package/lib/embed-template.js +7 -22
- package/{src/embed-template.test.ts → lib/embed-template.test.js} +165 -176
- package/lib/expression.js +11 -22
- package/{src/expression.test.ts → lib/expression.test.js} +55 -83
- package/lib/generator.js +2 -4
- package/{src/generator.test.ts → lib/generator.test.js} +28 -31
- package/lib/hook.js +2 -4
- package/{src/hook.test.ts → lib/hook.test.js} +4 -4
- package/lib/index.js +9 -31
- package/lib/instance-utils.js +2 -4
- package/{src/instance-utils.test.ts → lib/instance-utils.test.js} +19 -43
- package/lib/prop-meta.js +150 -0
- package/lib/props.js +8 -16
- package/{src/props.test.ts → lib/props.test.js} +39 -68
- package/lib/pubsub/create.js +2 -4
- package/lib/pubsub/index.js +1 -0
- package/lib/pubsub/raf-queue.js +2 -4
- package/lib/tree/create-elements-tree.js +2 -4
- package/lib/tree/index.js +1 -0
- package/lib/tree/root.js +2 -5
- package/lib/tree/webstudio-component.js +10 -20
- package/lib/types/component-renderer.d.ts +1 -1
- package/lib/types/components/component-meta.d.ts +526 -526
- package/lib/types/context.d.ts +1 -2
- package/lib/types/css/css.d.ts +22 -23
- package/lib/types/css/global-rules.d.ts +19 -19
- package/lib/types/css/normalize.d.ts +2444 -2444
- package/lib/types/css/style-rules.d.ts +2 -2
- package/lib/types/embed-template.d.ts +648 -648
- package/lib/types/generator.d.ts +1 -1
- package/lib/types/hook.d.ts +3 -3
- package/lib/types/index.d.ts +1 -0
- package/lib/types/instance-utils.d.ts +3 -3
- package/lib/types/prop-meta.d.ts +396 -0
- package/lib/types/props.d.ts +52 -53
- package/lib/types/tree/create-elements-tree.d.ts +3 -4
- package/lib/types/tree/root.d.ts +8 -8
- package/lib/types/tree/webstudio-component.d.ts +1 -1
- package/package.json +14 -22
- package/lib/cjs/app/index.js +0 -18
- package/lib/cjs/app/root.js +0 -40
- package/lib/cjs/component-renderer.js +0 -143
- package/lib/cjs/components/component-meta.js +0 -87
- package/lib/cjs/components/components-utils.js +0 -17
- package/lib/cjs/context.js +0 -43
- package/lib/cjs/css/css.js +0 -84
- package/lib/cjs/css/global-rules.js +0 -37
- package/lib/cjs/css/index.js +0 -20
- package/lib/cjs/css/normalize-type-check.js +0 -26
- package/lib/cjs/css/normalize.js +0 -349
- package/lib/cjs/css/presets.js +0 -48
- package/lib/cjs/css/style-rules.js +0 -86
- package/lib/cjs/embed-template.js +0 -368
- package/lib/cjs/expression.js +0 -371
- package/lib/cjs/generator.js +0 -128
- package/lib/cjs/hook.js +0 -34
- package/lib/cjs/index.js +0 -59
- package/lib/cjs/instance-utils.js +0 -65
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/props.js +0 -204
- package/lib/cjs/pubsub/create.js +0 -78
- package/lib/cjs/pubsub/index.js +0 -18
- package/lib/cjs/pubsub/raf-queue.js +0 -42
- package/lib/cjs/tree/create-elements-tree.js +0 -152
- package/lib/cjs/tree/index.js +0 -20
- package/lib/cjs/tree/root.js +0 -100
- package/lib/cjs/tree/webstudio-component.js +0 -91
- package/src/app/index.ts +0 -1
- package/src/app/root.tsx +0 -25
- package/src/component-renderer.tsx +0 -146
- package/src/components/component-meta.ts +0 -86
- package/src/components/components-utils.ts +0 -13
- package/src/context.tsx +0 -73
- package/src/css/css.ts +0 -88
- package/src/css/global-rules.ts +0 -26
- package/src/css/index.ts +0 -3
- package/src/css/normalize-type-check.ts +0 -13
- package/src/css/normalize.ts +0 -507
- package/src/css/presets.ts +0 -27
- package/src/css/style-rules.ts +0 -101
- package/src/embed-template.ts +0 -438
- package/src/expression.ts +0 -401
- package/src/generator.ts +0 -147
- package/src/hook.ts +0 -52
- package/src/index.ts +0 -39
- package/src/instance-utils.ts +0 -65
- package/src/props.ts +0 -231
- package/src/pubsub/create.ts +0 -77
- package/src/pubsub/index.ts +0 -1
- package/src/pubsub/raf-queue.ts +0 -25
- package/src/tree/create-elements-tree.tsx +0 -186
- package/src/tree/index.ts +0 -3
- package/src/tree/root.ts +0 -131
- package/src/tree/webstudio-component.tsx +0 -97
package/lib/expression.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import jsep from "jsep";
|
|
2
3
|
import jsepAssignment from "@jsep-plugin/assignment";
|
|
3
4
|
jsep.plugins.register(jsepAssignment);
|
|
@@ -134,7 +135,7 @@ const generateCode = (node, failOnForbidden, effectful, transformIdentifier) =>
|
|
|
134
135
|
node;
|
|
135
136
|
return "";
|
|
136
137
|
};
|
|
137
|
-
const validateExpression = (code, options) => {
|
|
138
|
+
export const validateExpression = (code, options) => {
|
|
138
139
|
const { effectful = false, transformIdentifier = (id) => id } = options ?? {};
|
|
139
140
|
const expression = jsep(code);
|
|
140
141
|
return generateCode(expression, true, effectful, transformIdentifier);
|
|
@@ -153,7 +154,7 @@ const sortTopologically = (list, depsById, explored = /* @__PURE__ */ new Set(),
|
|
|
153
154
|
}
|
|
154
155
|
return sorted;
|
|
155
156
|
};
|
|
156
|
-
const generateComputingExpressions = (expressions, allowedVariables) => {
|
|
157
|
+
export const generateComputingExpressions = (expressions, allowedVariables) => {
|
|
157
158
|
const depsById = /* @__PURE__ */ new Map();
|
|
158
159
|
const inputVariables = /* @__PURE__ */ new Set();
|
|
159
160
|
for (const [id, code] of expressions) {
|
|
@@ -199,7 +200,7 @@ const generateComputingExpressions = (expressions, allowedVariables) => {
|
|
|
199
200
|
generatedCode += `]);`;
|
|
200
201
|
return generatedCode;
|
|
201
202
|
};
|
|
202
|
-
const executeComputingExpressions = (expressions, variables) => {
|
|
203
|
+
export const executeComputingExpressions = (expressions, variables) => {
|
|
203
204
|
const generatedCode = generateComputingExpressions(
|
|
204
205
|
expressions,
|
|
205
206
|
new Set(variables.keys())
|
|
@@ -208,7 +209,7 @@ const executeComputingExpressions = (expressions, variables) => {
|
|
|
208
209
|
const values = executeFn(variables);
|
|
209
210
|
return values;
|
|
210
211
|
};
|
|
211
|
-
const generateEffectfulExpression = (code, args, allowedVariables) => {
|
|
212
|
+
export const generateEffectfulExpression = (code, args, allowedVariables) => {
|
|
212
213
|
const inputVariables = /* @__PURE__ */ new Set();
|
|
213
214
|
const outputVariables = /* @__PURE__ */ new Set();
|
|
214
215
|
validateExpression(code, {
|
|
@@ -254,7 +255,7 @@ const generateEffectfulExpression = (code, args, allowedVariables) => {
|
|
|
254
255
|
generatedCode += `]);`;
|
|
255
256
|
return generatedCode;
|
|
256
257
|
};
|
|
257
|
-
const executeEffectfulExpression = (code, args, variables) => {
|
|
258
|
+
export const executeEffectfulExpression = (code, args, variables) => {
|
|
258
259
|
const generatedCode = generateEffectfulExpression(
|
|
259
260
|
code,
|
|
260
261
|
new Set(args.keys()),
|
|
@@ -291,7 +292,7 @@ const computeExpressionDependencies = (expressions, expressionId, dependencies)
|
|
|
291
292
|
});
|
|
292
293
|
return parentDeps;
|
|
293
294
|
};
|
|
294
|
-
const computeExpressionsDependencies = (expressions) => {
|
|
295
|
+
export const computeExpressionsDependencies = (expressions) => {
|
|
295
296
|
const dependencies = /* @__PURE__ */ new Map();
|
|
296
297
|
for (const id of expressions.keys()) {
|
|
297
298
|
computeExpressionDependencies(expressions, id, dependencies);
|
|
@@ -299,25 +300,25 @@ const computeExpressionsDependencies = (expressions) => {
|
|
|
299
300
|
return dependencies;
|
|
300
301
|
};
|
|
301
302
|
const dataSourceVariablePrefix = "$ws$dataSource$";
|
|
302
|
-
const encodeDataSourceVariable = (id) => {
|
|
303
|
+
export const encodeDataSourceVariable = (id) => {
|
|
303
304
|
const encoded = id.replaceAll("-", "__DASH__");
|
|
304
305
|
return `${dataSourceVariablePrefix}${encoded}`;
|
|
305
306
|
};
|
|
306
|
-
const encodeVariablesMap = (values) => {
|
|
307
|
+
export const encodeVariablesMap = (values) => {
|
|
307
308
|
const encodedValues = /* @__PURE__ */ new Map();
|
|
308
309
|
for (const [id, value] of values) {
|
|
309
310
|
encodedValues.set(encodeDataSourceVariable(id), value);
|
|
310
311
|
}
|
|
311
312
|
return encodedValues;
|
|
312
313
|
};
|
|
313
|
-
const decodeDataSourceVariable = (name) => {
|
|
314
|
+
export const decodeDataSourceVariable = (name) => {
|
|
314
315
|
if (name.startsWith(dataSourceVariablePrefix)) {
|
|
315
316
|
const encoded = name.slice(dataSourceVariablePrefix.length);
|
|
316
317
|
return encoded.replaceAll("__DASH__", "-");
|
|
317
318
|
}
|
|
318
319
|
return;
|
|
319
320
|
};
|
|
320
|
-
const decodeVariablesMap = (values) => {
|
|
321
|
+
export const decodeVariablesMap = (values) => {
|
|
321
322
|
const decodedValues = /* @__PURE__ */ new Map();
|
|
322
323
|
for (const [name, value] of values) {
|
|
323
324
|
const id = decodeDataSourceVariable(name);
|
|
@@ -327,15 +328,3 @@ const decodeVariablesMap = (values) => {
|
|
|
327
328
|
}
|
|
328
329
|
return decodedValues;
|
|
329
330
|
};
|
|
330
|
-
export {
|
|
331
|
-
computeExpressionsDependencies,
|
|
332
|
-
decodeDataSourceVariable,
|
|
333
|
-
decodeVariablesMap,
|
|
334
|
-
encodeDataSourceVariable,
|
|
335
|
-
encodeVariablesMap,
|
|
336
|
-
executeComputingExpressions,
|
|
337
|
-
executeEffectfulExpression,
|
|
338
|
-
generateComputingExpressions,
|
|
339
|
-
generateEffectfulExpression,
|
|
340
|
-
validateExpression
|
|
341
|
-
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { expect, test } from "@jest/globals";
|
|
2
3
|
import {
|
|
3
4
|
decodeDataSourceVariable,
|
|
@@ -7,38 +8,32 @@ import {
|
|
|
7
8
|
computeExpressionsDependencies,
|
|
8
9
|
generateComputingExpressions,
|
|
9
10
|
generateEffectfulExpression,
|
|
10
|
-
validateExpression
|
|
11
|
+
validateExpression
|
|
11
12
|
} from "./expression";
|
|
12
|
-
|
|
13
13
|
test("allow literals and array expressions", () => {
|
|
14
14
|
expect(
|
|
15
15
|
validateExpression(`["", '', 0, true, false, null, undefined]`)
|
|
16
16
|
).toEqual(`["", '', 0, true, false, null, undefined]`);
|
|
17
17
|
});
|
|
18
|
-
|
|
19
18
|
test("allow unary and binary expressions", () => {
|
|
20
19
|
expect(validateExpression(`[-1, 1 + 1]`)).toEqual(`[-1, 1 + 1]`);
|
|
21
20
|
});
|
|
22
|
-
|
|
23
21
|
test("optionally allow assignment expressions", () => {
|
|
24
22
|
expect(() => {
|
|
25
23
|
validateExpression(`a = 2`);
|
|
26
24
|
}).toThrowError(/Cannot use assignment in this expression/);
|
|
27
25
|
expect(validateExpression(`a = 2`, { effectful: true })).toEqual(`a = 2`);
|
|
28
26
|
});
|
|
29
|
-
|
|
30
27
|
test("forbid member expressions", () => {
|
|
31
28
|
expect(() => {
|
|
32
29
|
validateExpression("var1 + obj.param");
|
|
33
30
|
}).toThrowError(/Cannot access "param" of "obj"/);
|
|
34
31
|
});
|
|
35
|
-
|
|
36
32
|
test("forbid this expressions", () => {
|
|
37
33
|
expect(() => {
|
|
38
34
|
validateExpression("var1 + this");
|
|
39
35
|
}).toThrowError(/"this" is not supported/);
|
|
40
36
|
});
|
|
41
|
-
|
|
42
37
|
test("forbid call expressions", () => {
|
|
43
38
|
expect(() => {
|
|
44
39
|
validateExpression("var1 + fn1()");
|
|
@@ -47,13 +42,11 @@ test("forbid call expressions", () => {
|
|
|
47
42
|
validateExpression("var1 + this.fn1()");
|
|
48
43
|
}).toThrowError(/Cannot call "this.fn1"/);
|
|
49
44
|
});
|
|
50
|
-
|
|
51
45
|
test("forbid ternary", () => {
|
|
52
46
|
expect(() => {
|
|
53
47
|
validateExpression("var1 ? var2 : var3");
|
|
54
48
|
}).toThrowError(/Ternary operator is not supported/);
|
|
55
49
|
});
|
|
56
|
-
|
|
57
50
|
test("forbid increment and decrement", () => {
|
|
58
51
|
expect(() => {
|
|
59
52
|
validateExpression("++var1");
|
|
@@ -68,7 +61,6 @@ test("forbid increment and decrement", () => {
|
|
|
68
61
|
validateExpression("var1--");
|
|
69
62
|
}).toThrowError(/"--" operator is not supported/);
|
|
70
63
|
});
|
|
71
|
-
|
|
72
64
|
test("forbid multiple expressions", () => {
|
|
73
65
|
expect(() => {
|
|
74
66
|
validateExpression("a b");
|
|
@@ -80,25 +72,22 @@ test("forbid multiple expressions", () => {
|
|
|
80
72
|
validateExpression("a; b");
|
|
81
73
|
}).toThrowError(/Cannot use multiple expressions/);
|
|
82
74
|
});
|
|
83
|
-
|
|
84
75
|
test("transform identifiers", () => {
|
|
85
76
|
expect(
|
|
86
77
|
validateExpression(`a + b`, {
|
|
87
|
-
transformIdentifier: (id) => `$ws$${id}
|
|
78
|
+
transformIdentifier: (id) => `$ws$${id}`
|
|
88
79
|
})
|
|
89
80
|
).toEqual(`$ws$a + $ws$b`);
|
|
90
81
|
});
|
|
91
|
-
|
|
92
82
|
test("generate computing expressions", () => {
|
|
93
|
-
const variables = new Set(["var0"]);
|
|
94
|
-
const expressions = new Map([
|
|
83
|
+
const variables = /* @__PURE__ */ new Set(["var0"]);
|
|
84
|
+
const expressions = /* @__PURE__ */ new Map([
|
|
95
85
|
["exp3", "exp2 + exp1"],
|
|
96
86
|
["exp1", "var0"],
|
|
97
87
|
["exp2", "exp1"],
|
|
98
|
-
["exp4", "exp2"]
|
|
88
|
+
["exp4", "exp2"]
|
|
99
89
|
]);
|
|
100
|
-
expect(generateComputingExpressions(expressions, variables))
|
|
101
|
-
.toMatchInlineSnapshot(`
|
|
90
|
+
expect(generateComputingExpressions(expressions, variables)).toMatchInlineSnapshot(`
|
|
102
91
|
"const var0 = _variables.get('var0');
|
|
103
92
|
const exp1 = (var0);
|
|
104
93
|
const exp2 = (exp1);
|
|
@@ -112,11 +101,9 @@ test("generate computing expressions", () => {
|
|
|
112
101
|
]);"
|
|
113
102
|
`);
|
|
114
103
|
});
|
|
115
|
-
|
|
116
104
|
test("add only used variables in computing expression", () => {
|
|
117
|
-
const expressions = new Map([["exp1", "var0"]]);
|
|
118
|
-
expect(generateComputingExpressions(expressions, new Set(["var0", "var1"])))
|
|
119
|
-
.toMatchInlineSnapshot(`
|
|
105
|
+
const expressions = /* @__PURE__ */ new Map([["exp1", "var0"]]);
|
|
106
|
+
expect(generateComputingExpressions(expressions, /* @__PURE__ */ new Set(["var0", "var1"]))).toMatchInlineSnapshot(`
|
|
120
107
|
"const var0 = _variables.get('var0');
|
|
121
108
|
const exp1 = (var0);
|
|
122
109
|
return new Map([
|
|
@@ -124,57 +111,51 @@ test("add only used variables in computing expression", () => {
|
|
|
124
111
|
]);"
|
|
125
112
|
`);
|
|
126
113
|
});
|
|
127
|
-
|
|
128
114
|
test("execute expression", () => {
|
|
129
|
-
const variables = new Map();
|
|
130
|
-
const expressions = new Map([["exp1", "1 + 1"]]);
|
|
115
|
+
const variables = /* @__PURE__ */ new Map();
|
|
116
|
+
const expressions = /* @__PURE__ */ new Map([["exp1", "1 + 1"]]);
|
|
131
117
|
expect(executeComputingExpressions(expressions, variables)).toEqual(
|
|
132
|
-
new Map([["exp1", 2]])
|
|
118
|
+
/* @__PURE__ */ new Map([["exp1", 2]])
|
|
133
119
|
);
|
|
134
120
|
});
|
|
135
|
-
|
|
136
121
|
test("execute expression dependent on variables", () => {
|
|
137
|
-
const variables = new Map([["var1", 5]]);
|
|
138
|
-
const expressions = new Map([["exp1", "var1 + 1"]]);
|
|
122
|
+
const variables = /* @__PURE__ */ new Map([["var1", 5]]);
|
|
123
|
+
const expressions = /* @__PURE__ */ new Map([["exp1", "var1 + 1"]]);
|
|
139
124
|
expect(executeComputingExpressions(expressions, variables)).toEqual(
|
|
140
|
-
new Map([["exp1", 6]])
|
|
125
|
+
/* @__PURE__ */ new Map([["exp1", 6]])
|
|
141
126
|
);
|
|
142
127
|
});
|
|
143
|
-
|
|
144
128
|
test("execute expression dependent on another expressions", () => {
|
|
145
|
-
const variables = new Map([["var1", 3]]);
|
|
146
|
-
const expressions = new Map([
|
|
129
|
+
const variables = /* @__PURE__ */ new Map([["var1", 3]]);
|
|
130
|
+
const expressions = /* @__PURE__ */ new Map([
|
|
147
131
|
["exp1", "exp0 + 1"],
|
|
148
|
-
["exp0", "var1 + 2"]
|
|
132
|
+
["exp0", "var1 + 2"]
|
|
149
133
|
]);
|
|
150
134
|
expect(executeComputingExpressions(expressions, variables)).toEqual(
|
|
151
|
-
new Map([
|
|
135
|
+
/* @__PURE__ */ new Map([
|
|
152
136
|
["exp1", 6],
|
|
153
|
-
["exp0", 5]
|
|
137
|
+
["exp0", 5]
|
|
154
138
|
])
|
|
155
139
|
);
|
|
156
140
|
});
|
|
157
|
-
|
|
158
141
|
test("forbid circular expressions", () => {
|
|
159
|
-
const variables = new Map([["var1", 3]]);
|
|
160
|
-
const expressions = new Map([
|
|
142
|
+
const variables = /* @__PURE__ */ new Map([["var1", 3]]);
|
|
143
|
+
const expressions = /* @__PURE__ */ new Map([
|
|
161
144
|
["exp0", "exp2 + 1"],
|
|
162
145
|
["exp1", "exp0 + 2"],
|
|
163
|
-
["exp2", "exp1 + 3"]
|
|
146
|
+
["exp2", "exp1 + 3"]
|
|
164
147
|
]);
|
|
165
148
|
expect(() => {
|
|
166
149
|
executeComputingExpressions(expressions, variables);
|
|
167
150
|
}).toThrowError(/Cannot access 'exp0' before initialization/);
|
|
168
151
|
});
|
|
169
|
-
|
|
170
152
|
test("make sure dependency exists", () => {
|
|
171
|
-
const variables = new Map();
|
|
172
|
-
const expressions = new Map([["exp1", "var1 + 1"]]);
|
|
153
|
+
const variables = /* @__PURE__ */ new Map();
|
|
154
|
+
const expressions = /* @__PURE__ */ new Map([["exp1", "var1 + 1"]]);
|
|
173
155
|
expect(() => {
|
|
174
156
|
executeComputingExpressions(expressions, variables);
|
|
175
157
|
}).toThrowError(/Unknown dependency "var1"/);
|
|
176
158
|
});
|
|
177
|
-
|
|
178
159
|
test("encode/decode variable names", () => {
|
|
179
160
|
expect(encodeDataSourceVariable("my--id")).toEqual(
|
|
180
161
|
"$ws$dataSource$my__DASH____DASH__id"
|
|
@@ -182,15 +163,14 @@ test("encode/decode variable names", () => {
|
|
|
182
163
|
expect(decodeDataSourceVariable(encodeDataSourceVariable("my--id"))).toEqual(
|
|
183
164
|
"my--id"
|
|
184
165
|
);
|
|
185
|
-
expect(decodeDataSourceVariable("myVarName")).toEqual(
|
|
166
|
+
expect(decodeDataSourceVariable("myVarName")).toEqual(void 0);
|
|
186
167
|
});
|
|
187
|
-
|
|
188
168
|
test("generate effectful expression", () => {
|
|
189
169
|
expect(
|
|
190
170
|
generateEffectfulExpression(
|
|
191
171
|
`var0 = var0 + var1`,
|
|
192
|
-
new Set(),
|
|
193
|
-
new Set(["var0", "var1"])
|
|
172
|
+
/* @__PURE__ */ new Set(),
|
|
173
|
+
/* @__PURE__ */ new Set(["var0", "var1"])
|
|
194
174
|
)
|
|
195
175
|
).toMatchInlineSnapshot(`
|
|
196
176
|
"let var0 = _variables.get('var0');
|
|
@@ -200,12 +180,11 @@ test("generate effectful expression", () => {
|
|
|
200
180
|
['var0', var0],
|
|
201
181
|
]);"
|
|
202
182
|
`);
|
|
203
|
-
|
|
204
183
|
expect(
|
|
205
184
|
generateEffectfulExpression(
|
|
206
185
|
`var0 = var1 + 1`,
|
|
207
|
-
new Set(),
|
|
208
|
-
new Set(["var0", "var1"])
|
|
186
|
+
/* @__PURE__ */ new Set(),
|
|
187
|
+
/* @__PURE__ */ new Set(["var0", "var1"])
|
|
209
188
|
)
|
|
210
189
|
).toMatchInlineSnapshot(`
|
|
211
190
|
"let var1 = _variables.get('var1');
|
|
@@ -216,13 +195,12 @@ test("generate effectful expression", () => {
|
|
|
216
195
|
]);"
|
|
217
196
|
`);
|
|
218
197
|
});
|
|
219
|
-
|
|
220
198
|
test("add only used variables in effectful expression", () => {
|
|
221
199
|
expect(
|
|
222
200
|
generateEffectfulExpression(
|
|
223
201
|
`var0 = var1 + 1`,
|
|
224
|
-
new Set(),
|
|
225
|
-
new Set(["var0", "var1", "var2"])
|
|
202
|
+
/* @__PURE__ */ new Set(),
|
|
203
|
+
/* @__PURE__ */ new Set(["var0", "var1", "var2"])
|
|
226
204
|
)
|
|
227
205
|
).toMatchInlineSnapshot(`
|
|
228
206
|
"let var1 = _variables.get('var1');
|
|
@@ -233,13 +211,12 @@ test("add only used variables in effectful expression", () => {
|
|
|
233
211
|
]);"
|
|
234
212
|
`);
|
|
235
213
|
});
|
|
236
|
-
|
|
237
214
|
test("support effectful expression arguments", () => {
|
|
238
215
|
expect(
|
|
239
216
|
generateEffectfulExpression(
|
|
240
217
|
`var0 = arg0 + 1`,
|
|
241
|
-
new Set(["arg0"]),
|
|
242
|
-
new Set(["var0"])
|
|
218
|
+
/* @__PURE__ */ new Set(["arg0"]),
|
|
219
|
+
/* @__PURE__ */ new Set(["var0"])
|
|
243
220
|
)
|
|
244
221
|
).toMatchInlineSnapshot(`
|
|
245
222
|
"let arg0 = _args.get('arg0');
|
|
@@ -250,60 +227,55 @@ test("support effectful expression arguments", () => {
|
|
|
250
227
|
]);"
|
|
251
228
|
`);
|
|
252
229
|
});
|
|
253
|
-
|
|
254
230
|
test("forbid not allowed variables or arguments in effectful expression", () => {
|
|
255
231
|
expect(() => {
|
|
256
232
|
generateEffectfulExpression(
|
|
257
233
|
`var0 = var0 + var1`,
|
|
258
|
-
new Set(),
|
|
259
|
-
new Set(["var0"])
|
|
234
|
+
/* @__PURE__ */ new Set(),
|
|
235
|
+
/* @__PURE__ */ new Set(["var0"])
|
|
260
236
|
);
|
|
261
237
|
}).toThrowError(/Unknown dependency "var1"/);
|
|
262
238
|
expect(() => {
|
|
263
|
-
generateEffectfulExpression(`var0 = arg0`, new Set(), new Set(["var0"]));
|
|
239
|
+
generateEffectfulExpression(`var0 = arg0`, /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(["var0"]));
|
|
264
240
|
}).toThrowError(/Unknown dependency "arg0"/);
|
|
265
241
|
});
|
|
266
|
-
|
|
267
242
|
test("execute effectful expression", () => {
|
|
268
|
-
const variables = new Map([
|
|
243
|
+
const variables = /* @__PURE__ */ new Map([
|
|
269
244
|
["var0", 2],
|
|
270
|
-
["var1", 3]
|
|
245
|
+
["var1", 3]
|
|
271
246
|
]);
|
|
272
247
|
expect(
|
|
273
|
-
executeEffectfulExpression(`var0 = var0 + var1`, new Map(), variables)
|
|
274
|
-
).toEqual(new Map([["var0", 5]]));
|
|
275
|
-
|
|
248
|
+
executeEffectfulExpression(`var0 = var0 + var1`, /* @__PURE__ */ new Map(), variables)
|
|
249
|
+
).toEqual(/* @__PURE__ */ new Map([["var0", 5]]));
|
|
276
250
|
expect(
|
|
277
|
-
executeEffectfulExpression(`arg0 = 5`, new Map([["arg0", 0]]), new Map())
|
|
278
|
-
).toEqual(new Map());
|
|
251
|
+
executeEffectfulExpression(`arg0 = 5`, /* @__PURE__ */ new Map([["arg0", 0]]), /* @__PURE__ */ new Map())
|
|
252
|
+
).toEqual(/* @__PURE__ */ new Map());
|
|
279
253
|
});
|
|
280
|
-
|
|
281
254
|
test("compute expressions dependencies", () => {
|
|
282
|
-
const expressions = new Map([
|
|
255
|
+
const expressions = /* @__PURE__ */ new Map([
|
|
283
256
|
["exp1", `var1`],
|
|
284
257
|
["exp2", `exp1 + exp1`],
|
|
285
258
|
["exp3", `exp1 + exp2`],
|
|
286
|
-
["exp4", `var1 + exp1`]
|
|
259
|
+
["exp4", `var1 + exp1`]
|
|
287
260
|
]);
|
|
288
261
|
expect(computeExpressionsDependencies(expressions)).toEqual(
|
|
289
|
-
new Map([
|
|
290
|
-
["exp4", new Set(["var1", "exp1"])],
|
|
291
|
-
["exp3", new Set(["var1", "exp1", "exp2"])],
|
|
292
|
-
["exp2", new Set(["var1", "exp1"])],
|
|
293
|
-
["exp1", new Set(["var1"])]
|
|
262
|
+
/* @__PURE__ */ new Map([
|
|
263
|
+
["exp4", /* @__PURE__ */ new Set(["var1", "exp1"])],
|
|
264
|
+
["exp3", /* @__PURE__ */ new Set(["var1", "exp1", "exp2"])],
|
|
265
|
+
["exp2", /* @__PURE__ */ new Set(["var1", "exp1"])],
|
|
266
|
+
["exp1", /* @__PURE__ */ new Set(["var1"])]
|
|
294
267
|
])
|
|
295
268
|
);
|
|
296
269
|
});
|
|
297
|
-
|
|
298
270
|
test("handle cyclic dependencies", () => {
|
|
299
|
-
const expressions = new Map([
|
|
271
|
+
const expressions = /* @__PURE__ */ new Map([
|
|
300
272
|
["exp1", `exp2 + var1`],
|
|
301
|
-
["exp2", `exp1 + var1`]
|
|
273
|
+
["exp2", `exp1 + var1`]
|
|
302
274
|
]);
|
|
303
275
|
expect(computeExpressionsDependencies(expressions)).toEqual(
|
|
304
|
-
new Map([
|
|
305
|
-
["exp2", new Set(["var1", "exp1", "exp2"])],
|
|
306
|
-
["exp1", new Set(["var1", "exp1", "exp2"])]
|
|
276
|
+
/* @__PURE__ */ new Map([
|
|
277
|
+
["exp2", /* @__PURE__ */ new Set(["var1", "exp1", "exp2"])],
|
|
278
|
+
["exp1", /* @__PURE__ */ new Set(["var1", "exp1", "exp2"])]
|
|
307
279
|
])
|
|
308
280
|
);
|
|
309
281
|
});
|
package/lib/generator.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import {
|
|
2
3
|
getIndexesWithinAncestors
|
|
3
4
|
} from "./instance-utils";
|
|
@@ -6,7 +7,7 @@ import {
|
|
|
6
7
|
generateComputingExpressions,
|
|
7
8
|
generateEffectfulExpression
|
|
8
9
|
} from "./expression";
|
|
9
|
-
const generateUtilsExport = (siteData) => {
|
|
10
|
+
export const generateUtilsExport = (siteData) => {
|
|
10
11
|
const indexesWithinAncestors = getIndexesWithinAncestors(
|
|
11
12
|
siteData.metas,
|
|
12
13
|
siteData.instances,
|
|
@@ -109,6 +110,3 @@ const generateUtilsExport = (siteData) => {
|
|
|
109
110
|
/* eslint-enable */
|
|
110
111
|
`;
|
|
111
112
|
};
|
|
112
|
-
export {
|
|
113
|
-
generateUtilsExport
|
|
114
|
-
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { expect, test } from "@jest/globals";
|
|
2
3
|
import { generateUtilsExport } from "./generator";
|
|
3
|
-
|
|
4
4
|
test("generates utils", () => {
|
|
5
5
|
expect(
|
|
6
6
|
generateUtilsExport({
|
|
@@ -10,9 +10,9 @@ test("generates utils", () => {
|
|
|
10
10
|
name: "",
|
|
11
11
|
title: "",
|
|
12
12
|
meta: {},
|
|
13
|
-
rootInstanceId: "tabs"
|
|
13
|
+
rootInstanceId: "tabs"
|
|
14
14
|
},
|
|
15
|
-
metas: new Map([
|
|
15
|
+
metas: /* @__PURE__ */ new Map([
|
|
16
16
|
["Tabs", { type: "container", label: "", icon: "" }],
|
|
17
17
|
[
|
|
18
18
|
"TabsContent",
|
|
@@ -20,11 +20,11 @@ test("generates utils", () => {
|
|
|
20
20
|
type: "container",
|
|
21
21
|
label: "",
|
|
22
22
|
icon: "",
|
|
23
|
-
indexWithinAncestor: "Tabs"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
23
|
+
indexWithinAncestor: "Tabs"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
26
|
]),
|
|
27
|
-
instances: new Map([
|
|
27
|
+
instances: /* @__PURE__ */ new Map([
|
|
28
28
|
[
|
|
29
29
|
"tabs",
|
|
30
30
|
{
|
|
@@ -33,32 +33,30 @@ test("generates utils", () => {
|
|
|
33
33
|
component: "Tabs",
|
|
34
34
|
children: [
|
|
35
35
|
{ type: "id", value: "content1" },
|
|
36
|
-
{ type: "id", value: "content2" }
|
|
37
|
-
]
|
|
38
|
-
}
|
|
36
|
+
{ type: "id", value: "content2" }
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
39
|
],
|
|
40
|
-
|
|
41
40
|
[
|
|
42
41
|
"content1",
|
|
43
42
|
{
|
|
44
43
|
id: "content1",
|
|
45
44
|
type: "instance",
|
|
46
45
|
component: "TabsContent",
|
|
47
|
-
children: []
|
|
48
|
-
}
|
|
46
|
+
children: []
|
|
47
|
+
}
|
|
49
48
|
],
|
|
50
|
-
|
|
51
49
|
[
|
|
52
50
|
"content2",
|
|
53
51
|
{
|
|
54
52
|
id: "content2",
|
|
55
53
|
type: "instance",
|
|
56
54
|
component: "TabsContent",
|
|
57
|
-
children: []
|
|
58
|
-
}
|
|
59
|
-
]
|
|
55
|
+
children: []
|
|
56
|
+
}
|
|
57
|
+
]
|
|
60
58
|
]),
|
|
61
|
-
props: new Map([
|
|
59
|
+
props: /* @__PURE__ */ new Map([
|
|
62
60
|
[
|
|
63
61
|
"open",
|
|
64
62
|
{
|
|
@@ -66,10 +64,9 @@ test("generates utils", () => {
|
|
|
66
64
|
id: "open",
|
|
67
65
|
instanceId: "tabs",
|
|
68
66
|
name: "open",
|
|
69
|
-
value: "tabsOpen"
|
|
70
|
-
}
|
|
67
|
+
value: "tabsOpen"
|
|
68
|
+
}
|
|
71
69
|
],
|
|
72
|
-
|
|
73
70
|
[
|
|
74
71
|
"onOpenChange",
|
|
75
72
|
{
|
|
@@ -81,13 +78,13 @@ test("generates utils", () => {
|
|
|
81
78
|
{
|
|
82
79
|
type: "execute",
|
|
83
80
|
args: ["open"],
|
|
84
|
-
code: `$ws$dataSource$tabsOpen = open
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
]
|
|
81
|
+
code: `$ws$dataSource$tabsOpen = open`
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
]
|
|
89
86
|
]),
|
|
90
|
-
dataSources: new Map([
|
|
87
|
+
dataSources: /* @__PURE__ */ new Map([
|
|
91
88
|
[
|
|
92
89
|
"tabsOpen",
|
|
93
90
|
{
|
|
@@ -95,10 +92,10 @@ test("generates utils", () => {
|
|
|
95
92
|
name: "tabsOpen",
|
|
96
93
|
scopeInstanceId: "tabs",
|
|
97
94
|
type: "variable",
|
|
98
|
-
value: { type: "string", value: "0" }
|
|
99
|
-
}
|
|
100
|
-
]
|
|
101
|
-
])
|
|
95
|
+
value: { type: "string", value: "0" }
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
])
|
|
102
99
|
})
|
|
103
100
|
).toMatchInlineSnapshot(`
|
|
104
101
|
"
|
package/lib/hook.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
export const getClosestInstance = (instancePath, currentInstance, closestComponent) => {
|
|
2
3
|
let matched = false;
|
|
3
4
|
for (const instance of instancePath) {
|
|
4
5
|
if (currentInstance === instance) {
|
|
@@ -9,6 +10,3 @@ const getClosestInstance = (instancePath, currentInstance, closestComponent) =>
|
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
};
|
|
12
|
-
export {
|
|
13
|
-
getClosestInstance
|
|
14
|
-
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { expect, test } from "@jest/globals";
|
|
2
|
-
import { getClosestInstance
|
|
3
|
-
|
|
3
|
+
import { getClosestInstance } from ".";
|
|
4
4
|
test("get closest instance", () => {
|
|
5
|
-
const instancePath
|
|
5
|
+
const instancePath = [
|
|
6
6
|
{ type: "instance", id: "4", component: "Content", children: [] },
|
|
7
7
|
{ type: "instance", id: "3", component: "Tabs", children: [] },
|
|
8
8
|
{ type: "instance", id: "2", component: "Content", children: [] },
|
|
9
9
|
{ type: "instance", id: "1", component: "Tabs", children: [] },
|
|
10
|
-
{ type: "instance", id: "0", component: "Body", children: [] }
|
|
10
|
+
{ type: "instance", id: "0", component: "Body", children: [] }
|
|
11
11
|
];
|
|
12
12
|
const [content2, tabs2, content1, tabs1, _body] = instancePath;
|
|
13
13
|
expect(getClosestInstance(instancePath, content2, "Tabs")).toBe(tabs2);
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
export * from "./css";
|
|
2
3
|
export * from "./tree";
|
|
3
4
|
export * from "./pubsub";
|
|
4
5
|
export * from "./app";
|
|
5
6
|
export * from "./components/components-utils";
|
|
6
|
-
|
|
7
|
+
export { PropMeta } from "./prop-meta";
|
|
8
|
+
export {
|
|
7
9
|
componentCategories,
|
|
8
10
|
stateCategories,
|
|
9
11
|
defaultStates
|
|
10
12
|
} from "./components/component-meta";
|
|
11
13
|
export * from "./embed-template";
|
|
12
|
-
|
|
14
|
+
export {
|
|
13
15
|
useInstanceProps,
|
|
14
16
|
usePropUrl,
|
|
15
17
|
usePropAsset,
|
|
16
18
|
getInstanceIdFromComponentProps,
|
|
17
19
|
getIndexWithinAncestorFromComponentProps
|
|
18
20
|
} from "./props";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
export { ReactSdkContext } from "./context";
|
|
22
|
+
export {
|
|
21
23
|
validateExpression,
|
|
22
24
|
generateComputingExpressions,
|
|
23
25
|
executeComputingExpressions,
|
|
@@ -29,31 +31,7 @@ import {
|
|
|
29
31
|
decodeDataSourceVariable,
|
|
30
32
|
decodeVariablesMap
|
|
31
33
|
} from "./expression";
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
export { renderComponentTemplate } from "./component-renderer";
|
|
35
|
+
export { getIndexesWithinAncestors } from "./instance-utils";
|
|
34
36
|
export * from "./hook";
|
|
35
|
-
|
|
36
|
-
export {
|
|
37
|
-
ReactSdkContext,
|
|
38
|
-
componentCategories,
|
|
39
|
-
computeExpressionsDependencies,
|
|
40
|
-
decodeDataSourceVariable,
|
|
41
|
-
decodeVariablesMap,
|
|
42
|
-
defaultStates,
|
|
43
|
-
encodeDataSourceVariable,
|
|
44
|
-
encodeVariablesMap,
|
|
45
|
-
executeComputingExpressions,
|
|
46
|
-
executeEffectfulExpression,
|
|
47
|
-
generateComputingExpressions,
|
|
48
|
-
generateEffectfulExpression,
|
|
49
|
-
generateUtilsExport,
|
|
50
|
-
getIndexWithinAncestorFromComponentProps,
|
|
51
|
-
getIndexesWithinAncestors,
|
|
52
|
-
getInstanceIdFromComponentProps,
|
|
53
|
-
renderComponentTemplate,
|
|
54
|
-
stateCategories,
|
|
55
|
-
useInstanceProps,
|
|
56
|
-
usePropAsset,
|
|
57
|
-
usePropUrl,
|
|
58
|
-
validateExpression
|
|
59
|
-
};
|
|
37
|
+
export { generateUtilsExport } from "./generator";
|