@constela/core 0.15.0 → 0.15.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/README.md +21 -1
  2. package/dist/index.js +18 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -60,7 +60,7 @@ String state can use a cookie expression to read initial value from cookies (SSR
60
60
 
61
61
  ## Expression Types
62
62
 
63
- 17 expression types for constrained computation:
63
+ 18 expression types for constrained computation:
64
64
 
65
65
  | Type | JSON Example | Description |
66
66
  |------|-------------|-------------|
@@ -81,6 +81,7 @@ String state can use a cookie expression to read initial value from cookies (SSR
81
81
  | `cookie` | `{ "expr": "cookie", "key": "theme", "default": "dark" }` | Cookie value (SSR-safe) |
82
82
  | `call` | `{ "expr": "call", "target": ..., "method": "filter", "args": [...] }` | Method call |
83
83
  | `lambda` | `{ "expr": "lambda", "param": "item", "body": ... }` | Anonymous function |
84
+ | `array` | `{ "expr": "array", "elements": [...] }` | Array construction |
84
85
 
85
86
  **Binary Operators:** `+`, `-`, `*`, `/`, `==`, `!=`, `<`, `<=`, `>`, `>=`, `&&`, `||`
86
87
 
@@ -103,6 +104,25 @@ Concatenate multiple expressions into a single string:
103
104
  - `null`/`undefined` values become empty strings
104
105
  - Numbers and booleans are converted to strings
105
106
 
107
+ **Array Expression:**
108
+
109
+ Construct arrays dynamically from expressions:
110
+
111
+ ```json
112
+ {
113
+ "expr": "array",
114
+ "elements": [
115
+ { "expr": "var", "name": "basicSetup" },
116
+ { "expr": "call", "target": { "expr": "var", "name": "json" }, "method": "apply", "args": [] },
117
+ { "expr": "state", "name": "config" }
118
+ ]
119
+ }
120
+ ```
121
+
122
+ - Each element can be any expression type
123
+ - Elements are evaluated and collected into an array
124
+ - Useful for dynamic configurations (e.g., CodeMirror extensions: `[basicSetup, json()]`)
125
+
106
126
  ## View Node Types
107
127
 
108
128
  8 node types for building UI:
package/dist/index.js CHANGED
@@ -845,7 +845,7 @@ function isObject2(value) {
845
845
  var VALID_VIEW_KINDS = ["element", "text", "if", "each", "component", "slot", "markdown", "code", "portal"];
846
846
  var VALID_EXPR_TYPES = ["lit", "state", "var", "bin", "not", "param", "cond", "get", "style", "validity", "index", "call", "lambda", "array"];
847
847
  var VALID_PARAM_TYPES = ["string", "number", "boolean", "json"];
848
- var VALID_ACTION_TYPES = ["set", "update", "fetch", "delay", "interval", "clearTimer", "focus", "if"];
848
+ var VALID_ACTION_TYPES = ["set", "update", "setPath", "fetch", "delay", "interval", "clearTimer", "focus", "if"];
849
849
  var VALID_STATE_TYPES = ["number", "string", "list", "boolean", "object"];
850
850
  var VALID_BIN_OPS = BINARY_OPERATORS;
851
851
  var VALID_UPDATE_OPS = UPDATE_OPERATIONS;
@@ -981,7 +981,7 @@ function validateExpression(expr, path) {
981
981
  return { path: path + "/expr", message: "expr is required" };
982
982
  }
983
983
  if (!VALID_EXPR_TYPES.includes(exprType)) {
984
- return { path: path + "/expr", message: "must be one of: lit, state, var, bin, not, param, cond, get, style, validity, index, call, lambda" };
984
+ return { path: path + "/expr", message: `must be one of: ${VALID_EXPR_TYPES.join(", ")}` };
985
985
  }
986
986
  switch (exprType) {
987
987
  case "lit":
@@ -1148,7 +1148,7 @@ function validateActionStep(step, path) {
1148
1148
  return { path: path + "/do", message: "do is required" };
1149
1149
  }
1150
1150
  if (!VALID_ACTION_TYPES.includes(doType)) {
1151
- return { path: path + "/do", message: "must be one of: set, update, fetch, delay, interval, clearTimer, focus, if" };
1151
+ return { path: path + "/do", message: `must be one of: ${VALID_ACTION_TYPES.join(", ")}` };
1152
1152
  }
1153
1153
  switch (doType) {
1154
1154
  case "set":
@@ -1173,6 +1173,21 @@ function validateActionStep(step, path) {
1173
1173
  return validateExpression(step["value"], path + "/value");
1174
1174
  }
1175
1175
  break;
1176
+ case "setPath":
1177
+ if (typeof step["target"] !== "string") {
1178
+ return { path: path + "/target", message: "target is required" };
1179
+ }
1180
+ if (!("path" in step)) {
1181
+ return { path: path + "/path", message: "path is required" };
1182
+ }
1183
+ {
1184
+ const pathError = validateExpression(step["path"], path + "/path");
1185
+ if (pathError) return pathError;
1186
+ }
1187
+ if (!("value" in step)) {
1188
+ return { path: path + "/value", message: "value is required" };
1189
+ }
1190
+ return validateExpression(step["value"], path + "/value");
1176
1191
  case "fetch":
1177
1192
  if (!("url" in step)) {
1178
1193
  return { path: path + "/url", message: "url is required" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/core",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "description": "Core types, schema, and validator for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",