@constela/core 0.8.0 → 0.9.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/README.md CHANGED
@@ -42,7 +42,7 @@ All fields except `version`, `state`, `actions`, and `view` are optional.
42
42
 
43
43
  ## Expression Types
44
44
 
45
- 12 expression types for constrained computation:
45
+ 13 expression types for constrained computation:
46
46
 
47
47
  | Type | JSON Example | Description |
48
48
  |------|-------------|-------------|
@@ -58,6 +58,7 @@ All fields except `version`, `state`, `actions`, and `view` are optional.
58
58
  | `import` | `{ "expr": "import", "name": "config" }` | External data |
59
59
  | `data` | `{ "expr": "data", "name": "posts" }` | Build-time data |
60
60
  | `ref` | `{ "expr": "ref", "name": "inputEl" }` | DOM element ref |
61
+ | `style` | `{ "expr": "style", "name": "button", "variants": {...} }` | Style reference |
61
62
 
62
63
  **Binary Operators:** `+`, `-`, `*`, `/`, `==`, `!=`, `<`, `<=`, `>`, `>=`, `&&`, `||`
63
64
 
@@ -160,6 +161,54 @@ All fields except `version`, `state`, `actions`, and `view` are optional.
160
161
  }
161
162
  ```
162
163
 
164
+ ## Style System
165
+
166
+ Define reusable style presets with variants (similar to CVA/Tailwind Variants):
167
+
168
+ ```json
169
+ {
170
+ "styles": {
171
+ "button": {
172
+ "base": "px-4 py-2 rounded font-medium",
173
+ "variants": {
174
+ "variant": {
175
+ "primary": "bg-blue-500 text-white",
176
+ "secondary": "bg-gray-200 text-gray-800"
177
+ },
178
+ "size": {
179
+ "sm": "text-sm",
180
+ "md": "text-base",
181
+ "lg": "text-lg"
182
+ }
183
+ },
184
+ "defaultVariants": {
185
+ "variant": "primary",
186
+ "size": "md"
187
+ }
188
+ }
189
+ }
190
+ }
191
+ ```
192
+
193
+ Use styles with `StyleExpr`:
194
+
195
+ ```json
196
+ {
197
+ "kind": "element",
198
+ "tag": "button",
199
+ "props": {
200
+ "className": {
201
+ "expr": "style",
202
+ "name": "button",
203
+ "variants": {
204
+ "variant": { "expr": "lit", "value": "primary" },
205
+ "size": { "expr": "state", "name": "buttonSize" }
206
+ }
207
+ }
208
+ }
209
+ }
210
+ ```
211
+
163
212
  ## Error Codes
164
213
 
165
214
  | Code | Description |
@@ -191,6 +240,20 @@ All fields except `version`, `state`, `actions`, and `view` are optional.
191
240
  | `INVALID_STORAGE_OPERATION` | Invalid storage operation |
192
241
  | `INVALID_CLIPBOARD_OPERATION` | Invalid clipboard operation |
193
242
  | `INVALID_NAVIGATE_TARGET` | Invalid navigate target |
243
+ | `UNDEFINED_STYLE` | Reference to undefined style preset |
244
+ | `UNDEFINED_VARIANT` | Reference to undefined style variant |
245
+
246
+ ### Error Suggestions
247
+
248
+ Errors for undefined references include "Did you mean?" suggestions using Levenshtein distance:
249
+
250
+ ```typescript
251
+ import { findSimilarNames } from '@constela/core';
252
+
253
+ const candidates = new Set(['counter', 'items', 'query']);
254
+ const similar = findSimilarNames('count', candidates);
255
+ // Returns: ['counter'] - similar names within distance 2
256
+ ```
194
257
 
195
258
  ## Internal API
196
259
 
package/dist/index.d.ts CHANGED
@@ -208,6 +208,22 @@ interface UpdateStep {
208
208
  index?: Expression;
209
209
  deleteCount?: Expression;
210
210
  }
211
+ /**
212
+ * SetPath step - sets a value at a specific path within a state field
213
+ *
214
+ * This enables fine-grained state updates like `posts[5].liked = true`
215
+ * without re-creating the entire state.
216
+ *
217
+ * @property target - The state field name (e.g., "posts")
218
+ * @property path - The path within the state field (Expression that evaluates to string or array)
219
+ * @property value - The value to set at the path
220
+ */
221
+ interface SetPathStep {
222
+ do: 'setPath';
223
+ target: string;
224
+ path: Expression;
225
+ value: Expression;
226
+ }
211
227
  /**
212
228
  * Fetch step - makes an HTTP request
213
229
  */
@@ -302,7 +318,22 @@ interface DomStep {
302
318
  value?: Expression;
303
319
  attribute?: string;
304
320
  }
305
- type ActionStep = SetStep | UpdateStep | FetchStep | StorageStep | ClipboardStep | NavigateStep | ImportStep | CallStep | SubscribeStep | DisposeStep | DomStep;
321
+ /**
322
+ * Send step - sends data through a named WebSocket connection
323
+ */
324
+ interface SendStep {
325
+ do: 'send';
326
+ connection: string;
327
+ data: Expression;
328
+ }
329
+ /**
330
+ * Close step - closes a named WebSocket connection
331
+ */
332
+ interface CloseStep {
333
+ do: 'close';
334
+ connection: string;
335
+ }
336
+ type ActionStep = SetStep | UpdateStep | SetPathStep | FetchStep | StorageStep | ClipboardStep | NavigateStep | ImportStep | CallStep | SubscribeStep | DisposeStep | DomStep | SendStep | CloseStep;
306
337
  /**
307
338
  * Event handler - binds an event to an action
308
339
  */
@@ -1678,4 +1709,4 @@ declare const astSchema: {
1678
1709
  };
1679
1710
  };
1680
1711
 
1681
- export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallStep, type ClipboardOperation, type ClipboardStep, type CodeNode, type ComponentDef, type ComponentNode, type ComponentsRef, type CompoundVariant, type CondExpr, type ConstelaAst, ConstelaError, type ConstelaProgram, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type DisposeStep, type DomStep, type EachNode, type ElementNode, type ErrorCode, type ErrorOptions, type EventHandler, type Expression, type FetchStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type ImportExpr, type ImportStep, type LayoutProgram, type LifecycleHooks, type ListField, type LitExpr, type MarkdownNode, NAVIGATE_TARGETS, type NavigateStep, type NavigateTarget, type NotExpr, type NumberField, type ObjectField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type Program, type RefExpr, type RouteDefinition, type RouteExpr, STORAGE_OPERATIONS, STORAGE_TYPES, type SetStep, type SlotNode, type StateExpr, type StateField, type StaticPathsDefinition, type StorageOperation, type StorageStep, type StorageType, type StringField, type StyleExpr, type StylePreset, type SubscribeStep, type TextNode, UPDATE_OPERATIONS, type UpdateOperation, type UpdateStep, type ValidationFailure, type ValidationResult, type ValidationSuccess, type VarExpr, type ViewNode, astSchema, createClipboardWriteMissingValueError, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDataNotDefinedError, createDuplicateActionError, createDuplicateDefaultSlotError, createDuplicateSlotNameError, createImportsNotDefinedError, createInvalidClipboardOperationError, createInvalidDataSourceError, createInvalidNavigateTargetError, createInvalidSlotNameError, createInvalidStorageOperationError, createInvalidStorageTypeError, createLayoutMissingSlotError, createLayoutNotFoundError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createRouteNotDefinedError, createSchemaError, createSlotInLoopError, createStorageSetMissingValueError, createUndefinedActionError, createUndefinedDataError, createUndefinedDataSourceError, createUndefinedImportError, createUndefinedParamError, createUndefinedRefError, createUndefinedRouteParamError, createUndefinedStateError, createUndefinedStyleError, createUndefinedVarError, createUndefinedVariantError, createUnsupportedVersionError, findSimilarNames, isActionStep, isBinExpr, isBooleanField, isCallStep, isClipboardStep, isCodeNode, isComponentNode, isCondExpr, isConstelaError, isDataExpr, isDataSource, isDisposeStep, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isGetExpr, isIfNode, isImportExpr, isImportStep, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isRefExpr, isRouteDefinition, isRouteExpr, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStringField, isStyleExpr, isSubscribeStep, isTextNode, isUpdateStep, isVarExpr, isViewNode, validateAst };
1712
+ export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallStep, type ClipboardOperation, type ClipboardStep, type CloseStep, type CodeNode, type ComponentDef, type ComponentNode, type ComponentsRef, type CompoundVariant, type CondExpr, type ConstelaAst, ConstelaError, type ConstelaProgram, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type DisposeStep, type DomStep, type EachNode, type ElementNode, type ErrorCode, type ErrorOptions, type EventHandler, type Expression, type FetchStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type ImportExpr, type ImportStep, type LayoutProgram, type LifecycleHooks, type ListField, type LitExpr, type MarkdownNode, NAVIGATE_TARGETS, type NavigateStep, type NavigateTarget, type NotExpr, type NumberField, type ObjectField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type Program, type RefExpr, type RouteDefinition, type RouteExpr, STORAGE_OPERATIONS, STORAGE_TYPES, type SendStep, type SetPathStep, type SetStep, type SlotNode, type StateExpr, type StateField, type StaticPathsDefinition, type StorageOperation, type StorageStep, type StorageType, type StringField, type StyleExpr, type StylePreset, type SubscribeStep, type TextNode, UPDATE_OPERATIONS, type UpdateOperation, type UpdateStep, type ValidationFailure, type ValidationResult, type ValidationSuccess, type VarExpr, type ViewNode, astSchema, createClipboardWriteMissingValueError, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDataNotDefinedError, createDuplicateActionError, createDuplicateDefaultSlotError, createDuplicateSlotNameError, createImportsNotDefinedError, createInvalidClipboardOperationError, createInvalidDataSourceError, createInvalidNavigateTargetError, createInvalidSlotNameError, createInvalidStorageOperationError, createInvalidStorageTypeError, createLayoutMissingSlotError, createLayoutNotFoundError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createRouteNotDefinedError, createSchemaError, createSlotInLoopError, createStorageSetMissingValueError, createUndefinedActionError, createUndefinedDataError, createUndefinedDataSourceError, createUndefinedImportError, createUndefinedParamError, createUndefinedRefError, createUndefinedRouteParamError, createUndefinedStateError, createUndefinedStyleError, createUndefinedVarError, createUndefinedVariantError, createUnsupportedVersionError, findSimilarNames, isActionStep, isBinExpr, isBooleanField, isCallStep, isClipboardStep, isCodeNode, isComponentNode, isCondExpr, isConstelaError, isDataExpr, isDataSource, isDisposeStep, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isGetExpr, isIfNode, isImportExpr, isImportStep, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isRefExpr, isRouteDefinition, isRouteExpr, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStringField, isStyleExpr, isSubscribeStep, isTextNode, isUpdateStep, isVarExpr, isViewNode, validateAst };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/core",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Core types, schema, and validator for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",