@constela/compiler 0.14.4 → 0.14.5

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
@@ -54,6 +54,37 @@ The compiler transforms JSON programs through three passes:
54
54
  - **Object payloads** - Supports object-shaped event handler payloads with expression fields
55
55
  - **call/lambda expressions** - Compiles method calls and anonymous functions for array/string/Math/Date operations
56
56
  - **array expression** - Compiles dynamic array construction from expressions
57
+ - **localState/localActions** - Component-scoped state with instance isolation
58
+
59
+ ## Component Local State
60
+
61
+ Components can define `localState` and `localActions` for instance-scoped state:
62
+
63
+ ```json
64
+ {
65
+ "components": {
66
+ "Accordion": {
67
+ "params": { "title": { "type": "string" } },
68
+ "localState": {
69
+ "isExpanded": { "type": "boolean", "initial": false }
70
+ },
71
+ "localActions": [
72
+ {
73
+ "name": "toggle",
74
+ "steps": [{ "do": "update", "target": "isExpanded", "operation": "toggle" }]
75
+ }
76
+ ],
77
+ "view": { ... }
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ The compiler:
84
+ 1. Validates local state types and initial values
85
+ 2. Wraps component views with `localState` nodes
86
+ 3. Transforms local actions with instance-scoped store references
87
+ 4. Handles param substitution within component views
57
88
 
58
89
  ## CompiledProgram Structure
59
90
 
package/dist/index.d.ts CHANGED
@@ -102,7 +102,7 @@ interface CompiledAction {
102
102
  name: string;
103
103
  steps: CompiledActionStep[];
104
104
  }
105
- type CompiledActionStep = CompiledSetStep | CompiledUpdateStep | CompiledSetPathStep | CompiledFetchStep | CompiledStorageStep | CompiledClipboardStep | CompiledNavigateStep | CompiledImportStep | CompiledCallStep | CompiledSubscribeStep | CompiledDisposeStep | CompiledDomStep | CompiledIfStep | CompiledSendStep | CompiledCloseStep | CompiledDelayStep | CompiledIntervalStep | CompiledClearTimerStep | CompiledFocusStep;
105
+ type CompiledActionStep = CompiledSetStep | CompiledUpdateStep | CompiledSetPathStep | CompiledFetchStep | CompiledStorageStep | CompiledClipboardStep | CompiledNavigateStep | CompiledImportStep | CompiledCallStep | CompiledSubscribeStep | CompiledDisposeStep | CompiledDomStep | CompiledIfStep | CompiledSendStep | CompiledCloseStep | CompiledDelayStep | CompiledIntervalStep | CompiledClearTimerStep | CompiledFocusStep | CompiledGenerateStep;
106
106
  interface CompiledSetStep {
107
107
  do: 'set';
108
108
  target: string;
@@ -265,6 +265,19 @@ interface CompiledFocusStep {
265
265
  onSuccess?: CompiledActionStep[];
266
266
  onError?: CompiledActionStep[];
267
267
  }
268
+ /**
269
+ * Compiled generate step for AI generation
270
+ */
271
+ interface CompiledGenerateStep {
272
+ do: 'generate';
273
+ provider: 'anthropic' | 'openai';
274
+ prompt: CompiledExpression;
275
+ output: 'component' | 'view';
276
+ result: string;
277
+ model?: string;
278
+ onSuccess?: CompiledActionStep[];
279
+ onError?: CompiledActionStep[];
280
+ }
268
281
  /**
269
282
  * Compiled local action
270
283
  */
@@ -563,4 +576,4 @@ declare function transformLayoutPass(layout: LayoutProgram, _context: LayoutAnal
563
576
  */
564
577
  declare function composeLayoutWithPage(layout: CompiledProgram, page: CompiledProgram, layoutParams?: Record<string, Expression>, slots?: Record<string, ViewNode>): CompiledProgram;
565
578
 
566
- export { type AnalysisContext, type AnalyzePassFailure, type AnalyzePassResult, type AnalyzePassSuccess, type CompileFailure, type CompileResult, type CompileSuccess, type CompiledAction, type CompiledActionStep, type CompiledArrayExpr, type CompiledBinExpr, type CompiledCallExpr, type CompiledCallStep, type CompiledClearTimerStep, type CompiledClipboardStep, type CompiledCloseStep, type CompiledCodeNode, type CompiledConcatExpr, type CompiledCondExpr, type CompiledDataExpr, type CompiledDelayStep, type CompiledDisposeStep, type CompiledDomStep, type CompiledEachNode, type CompiledElementNode, type CompiledEventHandler, type CompiledEventHandlerOptions, type CompiledExpression, type CompiledFetchStep, type CompiledFocusStep, type CompiledGetExpr, type CompiledIfNode, type CompiledIfStep, type CompiledImportExpr, type CompiledImportStep, type CompiledIndexExpr, type CompiledIntervalStep, type CompiledLambdaExpr, type CompiledLayoutProgram, type CompiledLifecycleHooks, type CompiledLitExpr, type CompiledLocalAction, type CompiledLocalStateNode, type CompiledMarkdownNode, type CompiledNavigateStep, type CompiledNode, type CompiledNotExpr, type CompiledParamExpr, type CompiledPortalNode, type CompiledProgram, type CompiledRefExpr, type CompiledRouteDefinition, type CompiledRouteExpr, type CompiledSendStep, type CompiledSetPathStep, type CompiledSetStep, type CompiledSlotNode, type CompiledStateExpr, type CompiledStorageStep, type CompiledStyleExpr, type CompiledSubscribeStep, type CompiledTextNode, type CompiledUpdateStep, type CompiledValidityExpr, type CompiledVarExpr, type LayoutAnalysisContext, type LayoutAnalysisFailure, type LayoutAnalysisResult, type LayoutAnalysisSuccess, type ValidatePassFailure, type ValidatePassResult, type ValidatePassSuccess, analyzeLayoutPass, analyzePass, compile, composeLayoutWithPage, transformLayoutPass, transformPass, validatePass };
579
+ export { type AnalysisContext, type AnalyzePassFailure, type AnalyzePassResult, type AnalyzePassSuccess, type CompileFailure, type CompileResult, type CompileSuccess, type CompiledAction, type CompiledActionStep, type CompiledArrayExpr, type CompiledBinExpr, type CompiledCallExpr, type CompiledCallStep, type CompiledClearTimerStep, type CompiledClipboardStep, type CompiledCloseStep, type CompiledCodeNode, type CompiledConcatExpr, type CompiledCondExpr, type CompiledDataExpr, type CompiledDelayStep, type CompiledDisposeStep, type CompiledDomStep, type CompiledEachNode, type CompiledElementNode, type CompiledEventHandler, type CompiledEventHandlerOptions, type CompiledExpression, type CompiledFetchStep, type CompiledFocusStep, type CompiledGenerateStep, type CompiledGetExpr, type CompiledIfNode, type CompiledIfStep, type CompiledImportExpr, type CompiledImportStep, type CompiledIndexExpr, type CompiledIntervalStep, type CompiledLambdaExpr, type CompiledLayoutProgram, type CompiledLifecycleHooks, type CompiledLitExpr, type CompiledLocalAction, type CompiledLocalStateNode, type CompiledMarkdownNode, type CompiledNavigateStep, type CompiledNode, type CompiledNotExpr, type CompiledParamExpr, type CompiledPortalNode, type CompiledProgram, type CompiledRefExpr, type CompiledRouteDefinition, type CompiledRouteExpr, type CompiledSendStep, type CompiledSetPathStep, type CompiledSetStep, type CompiledSlotNode, type CompiledStateExpr, type CompiledStorageStep, type CompiledStyleExpr, type CompiledSubscribeStep, type CompiledTextNode, type CompiledUpdateStep, type CompiledValidityExpr, type CompiledVarExpr, type LayoutAnalysisContext, type LayoutAnalysisFailure, type LayoutAnalysisResult, type LayoutAnalysisSuccess, type ValidatePassFailure, type ValidatePassResult, type ValidatePassSuccess, analyzeLayoutPass, analyzePass, compile, composeLayoutWithPage, transformLayoutPass, transformPass, validatePass };
package/dist/index.js CHANGED
@@ -1667,6 +1667,26 @@ function transformActionStep(step) {
1667
1667
  }
1668
1668
  return compiledIfStep;
1669
1669
  }
1670
+ case "generate": {
1671
+ const generateStep = step;
1672
+ const compiledGenerateStep = {
1673
+ do: "generate",
1674
+ provider: generateStep.provider,
1675
+ prompt: transformExpression(generateStep.prompt, emptyContext),
1676
+ output: generateStep.output,
1677
+ result: generateStep.result
1678
+ };
1679
+ if (generateStep.model) {
1680
+ compiledGenerateStep.model = generateStep.model;
1681
+ }
1682
+ if (generateStep.onSuccess) {
1683
+ compiledGenerateStep.onSuccess = generateStep.onSuccess.map(transformActionStep);
1684
+ }
1685
+ if (generateStep.onError) {
1686
+ compiledGenerateStep.onError = generateStep.onError.map(transformActionStep);
1687
+ }
1688
+ return compiledGenerateStep;
1689
+ }
1670
1690
  }
1671
1691
  }
1672
1692
  function flattenSlotChildren(children, ctx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/compiler",
3
- "version": "0.14.4",
3
+ "version": "0.14.5",
4
4
  "description": "Compiler for Constela UI framework - AST to Program transformation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@constela/core": "0.15.2"
18
+ "@constela/core": "0.16.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^20.10.0",