@constela/runtime 0.17.1 → 0.18.1
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/README.md +54 -0
- package/dist/index.js +4 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -163,6 +163,60 @@ Close connection:
|
|
|
163
163
|
{ "do": "close", "connection": "chat" }
|
|
164
164
|
```
|
|
165
165
|
|
|
166
|
+
### Call/Lambda Expressions
|
|
167
|
+
|
|
168
|
+
Call methods on arrays, strings, Math, and Date:
|
|
169
|
+
|
|
170
|
+
```json
|
|
171
|
+
// Filter completed todos
|
|
172
|
+
{
|
|
173
|
+
"expr": "call",
|
|
174
|
+
"target": { "expr": "state", "name": "todos" },
|
|
175
|
+
"method": "filter",
|
|
176
|
+
"args": [{
|
|
177
|
+
"expr": "lambda",
|
|
178
|
+
"param": "todo",
|
|
179
|
+
"body": { "expr": "get", "base": { "expr": "var", "name": "todo" }, "path": "completed" }
|
|
180
|
+
}]
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Get array length
|
|
184
|
+
{ "expr": "call", "target": { "expr": "state", "name": "items" }, "method": "length" }
|
|
185
|
+
|
|
186
|
+
// Math.max
|
|
187
|
+
{
|
|
188
|
+
"expr": "call",
|
|
189
|
+
"target": { "expr": "var", "name": "Math" },
|
|
190
|
+
"method": "max",
|
|
191
|
+
"args": [{ "expr": "lit", "value": 10 }, { "expr": "state", "name": "count" }]
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Supported methods:**
|
|
196
|
+
- Array: length, at, includes, slice, indexOf, join, filter, map, find, findIndex, some, every
|
|
197
|
+
- String: length, charAt, substring, slice, split, trim, toUpperCase, toLowerCase, replace, includes, startsWith, endsWith, indexOf
|
|
198
|
+
- Math: min, max, round, floor, ceil, abs, sqrt, pow, random, sin, cos, tan
|
|
199
|
+
- Date: now, parse, toISOString, getTime, getFullYear, getMonth, getDate, getHours, getMinutes, getSeconds, getMilliseconds
|
|
200
|
+
|
|
201
|
+
### Array Expression
|
|
202
|
+
|
|
203
|
+
Construct arrays dynamically from expressions:
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"expr": "array",
|
|
208
|
+
"elements": [
|
|
209
|
+
{ "expr": "var", "name": "basicSetup" },
|
|
210
|
+
{ "expr": "call", "target": { "expr": "var", "name": "json" }, "method": "apply", "args": [] }
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Use cases:
|
|
216
|
+
- CodeMirror extensions: `[basicSetup, json()]`
|
|
217
|
+
- Dynamic configuration arrays
|
|
218
|
+
- Combining variables, literals, and call results in a single array
|
|
219
|
+
|
|
166
220
|
### Markdown Rendering
|
|
167
221
|
|
|
168
222
|
```json
|
package/dist/index.js
CHANGED
|
@@ -846,6 +846,10 @@ function evaluate(expr, ctx) {
|
|
|
846
846
|
}
|
|
847
847
|
case "lambda":
|
|
848
848
|
return void 0;
|
|
849
|
+
case "array": {
|
|
850
|
+
const arrayExpr = expr;
|
|
851
|
+
return arrayExpr.elements.map((elem) => evaluate(elem, ctx));
|
|
852
|
+
}
|
|
849
853
|
default: {
|
|
850
854
|
const _exhaustiveCheck = expr;
|
|
851
855
|
throw new Error(`Unknown expression type: ${JSON.stringify(_exhaustiveCheck)}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Runtime DOM renderer for Constela UI framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dompurify": "^3.3.1",
|
|
19
19
|
"marked": "^17.0.1",
|
|
20
20
|
"shiki": "^3.20.0",
|
|
21
|
-
"@constela/
|
|
22
|
-
"@constela/
|
|
21
|
+
"@constela/core": "0.15.1",
|
|
22
|
+
"@constela/compiler": "0.14.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/dompurify": "^3.2.0",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"tsup": "^8.0.0",
|
|
30
30
|
"typescript": "^5.3.0",
|
|
31
31
|
"vitest": "^2.0.0",
|
|
32
|
-
"@constela/server": "
|
|
32
|
+
"@constela/server": "11.0.1"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=20.0.0"
|