@constela/runtime 0.3.0 → 0.3.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.
- package/dist/index.d.ts +103 -0
- package/dist/index.js +13 -2
- package/package.json +13 -12
- package/LICENSE +0 -21
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { CompiledExpression, CompiledAction, CompiledNode, CompiledProgram } from '@constela/compiler';
|
|
2
|
+
|
|
3
|
+
interface Signal<T> {
|
|
4
|
+
get(): T;
|
|
5
|
+
set(value: T): void;
|
|
6
|
+
subscribe?(fn: (value: T) => void): () => void;
|
|
7
|
+
}
|
|
8
|
+
declare function createSignal<T>(initial: T): Signal<T>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Effect - Reactive side effect
|
|
12
|
+
*
|
|
13
|
+
* An effect runs a function and automatically tracks signal dependencies.
|
|
14
|
+
* When any tracked signal changes, the effect re-runs.
|
|
15
|
+
*/
|
|
16
|
+
type CleanupFn = () => void;
|
|
17
|
+
type EffectFn = () => void | CleanupFn;
|
|
18
|
+
declare function createEffect(fn: EffectFn): () => void;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* StateStore - Centralized state management
|
|
22
|
+
*
|
|
23
|
+
* Creates signals for each state field defined in the program.
|
|
24
|
+
* Provides get/set methods for accessing state.
|
|
25
|
+
*/
|
|
26
|
+
interface StateStore {
|
|
27
|
+
get(name: string): unknown;
|
|
28
|
+
set(name: string, value: unknown): void;
|
|
29
|
+
}
|
|
30
|
+
interface StateDefinition {
|
|
31
|
+
type: string;
|
|
32
|
+
initial: unknown;
|
|
33
|
+
}
|
|
34
|
+
declare function createStateStore(definitions: Record<string, StateDefinition>): StateStore;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Expression Evaluator - Evaluates compiled expressions
|
|
38
|
+
*
|
|
39
|
+
* Supports:
|
|
40
|
+
* - Literal values (lit)
|
|
41
|
+
* - State reads (state)
|
|
42
|
+
* - Variable reads (var)
|
|
43
|
+
* - Binary operations (bin)
|
|
44
|
+
* - Not operation (not)
|
|
45
|
+
* - Conditional expressions (cond)
|
|
46
|
+
* - Property access (get)
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
interface EvaluationContext {
|
|
50
|
+
state: StateStore;
|
|
51
|
+
locals: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
declare function evaluate(expr: CompiledExpression, ctx: EvaluationContext): unknown;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Action Executor - Executes compiled action steps
|
|
57
|
+
*
|
|
58
|
+
* Supports:
|
|
59
|
+
* - set: Update state with value
|
|
60
|
+
* - update: Increment/decrement numbers, push/pop/remove for arrays
|
|
61
|
+
* - fetch: Make HTTP requests with onSuccess/onError handlers
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
interface ActionContext {
|
|
65
|
+
state: StateStore;
|
|
66
|
+
actions: Record<string, CompiledAction>;
|
|
67
|
+
locals: Record<string, unknown>;
|
|
68
|
+
eventPayload?: unknown;
|
|
69
|
+
}
|
|
70
|
+
declare function executeAction(action: CompiledAction, ctx: ActionContext): Promise<void>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Renderer - DOM rendering for compiled view nodes
|
|
74
|
+
*
|
|
75
|
+
* Renders:
|
|
76
|
+
* - element: Creates DOM elements with props and event handlers
|
|
77
|
+
* - text: Creates text nodes
|
|
78
|
+
* - if: Conditional rendering with reactive updates
|
|
79
|
+
* - each: List rendering with reactive updates
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
interface RenderContext {
|
|
83
|
+
state: StateStore;
|
|
84
|
+
actions: Record<string, CompiledAction>;
|
|
85
|
+
locals: Record<string, unknown>;
|
|
86
|
+
cleanups?: (() => void)[];
|
|
87
|
+
}
|
|
88
|
+
declare function render(node: CompiledNode, ctx: RenderContext): Node;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* App - Main entry point for creating Constela applications
|
|
92
|
+
*
|
|
93
|
+
* Creates a reactive application from a CompiledProgram and mounts it to the DOM.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
interface AppInstance {
|
|
97
|
+
destroy(): void;
|
|
98
|
+
setState(name: string, value: unknown): void;
|
|
99
|
+
getState(name: string): unknown;
|
|
100
|
+
}
|
|
101
|
+
declare function createApp(program: CompiledProgram, mount: HTMLElement): AppInstance;
|
|
102
|
+
|
|
103
|
+
export { type ActionContext, type AppInstance, type EvaluationContext, type RenderContext, type Signal, type StateStore, createApp, createEffect, createSignal, createStateStore, evaluate, executeAction, render };
|
package/dist/index.js
CHANGED
|
@@ -409,14 +409,25 @@ function renderElement(node, ctx) {
|
|
|
409
409
|
el.addEventListener(eventName, async (event) => {
|
|
410
410
|
const action = ctx.actions[handler.action];
|
|
411
411
|
if (action) {
|
|
412
|
+
const eventLocals = {};
|
|
413
|
+
const target = event.target;
|
|
414
|
+
if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) {
|
|
415
|
+
eventLocals["value"] = target.value;
|
|
416
|
+
if (target instanceof HTMLInputElement && target.type === "checkbox") {
|
|
417
|
+
eventLocals["checked"] = target.checked;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
412
420
|
let payload = void 0;
|
|
413
421
|
if (handler.payload) {
|
|
414
|
-
payload = evaluate(handler.payload, {
|
|
422
|
+
payload = evaluate(handler.payload, {
|
|
423
|
+
state: ctx.state,
|
|
424
|
+
locals: { ...ctx.locals, ...eventLocals }
|
|
425
|
+
});
|
|
415
426
|
}
|
|
416
427
|
const actionCtx = {
|
|
417
428
|
state: ctx.state,
|
|
418
429
|
actions: ctx.actions,
|
|
419
|
-
locals: { ...ctx.locals, payload },
|
|
430
|
+
locals: { ...ctx.locals, ...eventLocals, payload },
|
|
420
431
|
eventPayload: payload
|
|
421
432
|
};
|
|
422
433
|
await executeAction(action, actionCtx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/runtime",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Runtime DOM renderer for Constela UI framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,9 +14,17 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
19
|
+
"type-check": "tsc --noEmit",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"test:watch": "vitest",
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"prepublishOnly": "pnpm run build"
|
|
24
|
+
},
|
|
17
25
|
"dependencies": {
|
|
18
|
-
"@constela/core": "
|
|
19
|
-
"@constela/compiler": "
|
|
26
|
+
"@constela/core": "workspace:*",
|
|
27
|
+
"@constela/compiler": "workspace:*"
|
|
20
28
|
},
|
|
21
29
|
"devDependencies": {
|
|
22
30
|
"@types/node": "^20.10.0",
|
|
@@ -29,12 +37,5 @@
|
|
|
29
37
|
"engines": {
|
|
30
38
|
"node": ">=20.0.0"
|
|
31
39
|
},
|
|
32
|
-
"license": "MIT"
|
|
33
|
-
|
|
34
|
-
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
35
|
-
"type-check": "tsc --noEmit",
|
|
36
|
-
"test": "vitest run",
|
|
37
|
-
"test:watch": "vitest",
|
|
38
|
-
"clean": "rm -rf dist"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
40
|
+
"license": "MIT"
|
|
41
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Constela Contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|