aktion-runtime 0.5.4 → 0.5.6
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 +206 -125
- package/dist/aktion.iife.js +106 -460
- package/dist/aktion.iife.js.map +1 -1
- package/dist/aktion.js +13612 -12644
- package/dist/aktion.js.map +1 -1
- package/dist/aktion.umd.cjs +106 -460
- package/dist/aktion.umd.cjs.map +1 -1
- package/dist/devtools.js +1367 -0
- package/dist/devtools.js.map +1 -0
- package/dist/{node/index-8OvnOYPI.js → language.js} +14789 -12298
- package/dist/language.js.map +1 -0
- package/dist/plugin.cjs +2660 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.js +2660 -0
- package/dist/plugin.js.map +1 -0
- package/dist/system_prompt.txt +200 -451
- package/dist/system_prompt_chat.txt +35 -85
- package/dist/testing.js +30190 -0
- package/dist/testing.js.map +1 -0
- package/dist/types/aktion-modules.d.ts +6 -10
- package/dist/types/compiler/index.d.ts +9 -11
- package/dist/types/compiler/linker.d.ts +11 -11
- package/dist/types/compiler/project.d.ts +45 -0
- package/dist/types/compiler/runtime.d.ts +22 -26
- package/dist/types/devtools/hook.d.ts +88 -0
- package/dist/types/devtools/index.d.ts +35 -0
- package/dist/types/devtools/panel.d.ts +109 -0
- package/dist/types/devtools/protocol.d.ts +130 -0
- package/dist/types/devtools/styles.d.ts +7 -0
- package/dist/types/element.d.ts +56 -25
- package/dist/types/index.d.ts +1 -1
- package/dist/types/language/builtins.d.ts +52 -0
- package/dist/types/language/index.d.ts +5 -2
- package/dist/types/language-api.d.ts +12 -8
- package/dist/types/library/components/helpers.d.ts +0 -5
- package/dist/types/library/components/wrappers.d.ts +1 -0
- package/dist/types/parser/types.d.ts +8 -9
- package/dist/types/plugin/index.d.ts +13 -6
- package/dist/types/renderer/renderer.d.ts +28 -0
- package/dist/types/runtime/builtins.d.ts +5 -11
- package/dist/types/runtime/effects.d.ts +16 -18
- package/dist/types/runtime/evaluator.d.ts +46 -5
- package/dist/types/runtime/http.d.ts +41 -1
- package/dist/types/runtime/index.d.ts +2 -1
- package/dist/types/runtime/router.d.ts +28 -2
- package/dist/types/runtime/toast.d.ts +45 -0
- package/dist/types/runtime/util.d.ts +11 -1
- package/dist/types/testing/index.d.ts +201 -0
- package/dist/types/theme/index.d.ts +3 -3
- package/dist/types/theme/styles.d.ts +1 -1
- package/dist/types/tooling/formatter.d.ts +7 -1
- package/dist/types/tooling/index.d.ts +6 -3
- package/dist/types/tooling/language-service.d.ts +10 -5
- package/dist/types/tooling/navigation.d.ts +91 -0
- package/dist/types/tooling/semantic-tokens.d.ts +24 -0
- package/dist/types/tooling/signature-help.d.ts +21 -0
- package/package.json +21 -19
- package/dist/node/compile-BUw0GAvN.cjs +0 -491
- package/dist/node/compile-BUw0GAvN.cjs.map +0 -1
- package/dist/node/compile-DxttTzo8.js +0 -492
- package/dist/node/compile-DxttTzo8.js.map +0 -1
- package/dist/node/compiler.cjs +0 -11
- package/dist/node/compiler.cjs.map +0 -1
- package/dist/node/compiler.js +0 -11
- package/dist/node/compiler.js.map +0 -1
- package/dist/node/index-8OvnOYPI.js.map +0 -1
- package/dist/node/index-DBgA3bHQ.cjs +0 -14069
- package/dist/node/index-DBgA3bHQ.cjs.map +0 -1
- package/dist/node/language.cjs +0 -1244
- package/dist/node/language.cjs.map +0 -1
- package/dist/node/language.js +0 -1244
- package/dist/node/language.js.map +0 -1
- package/dist/node/vite.cjs +0 -65
- package/dist/node/vite.cjs.map +0 -1
- package/dist/node/vite.js +0 -65
- package/dist/node/vite.js.map +0 -1
- package/dist/types/compiler/compile.d.ts +0 -54
- package/dist/types/compiler/emit.d.ts +0 -15
- package/dist/types/compiler/sourcemap.d.ts +0 -40
- package/dist/types/library/components/theme.d.ts +0 -2
- package/dist/types/plugin/vite.d.ts +0 -21
- package/dist/types/tooling/codemod.d.ts +0 -36
package/dist/types/element.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ export declare class AktionElement extends HTMLElement {
|
|
|
13
13
|
private library;
|
|
14
14
|
private readonly http;
|
|
15
15
|
private readonly effectRunner;
|
|
16
|
-
private readonly actionDeclRunner;
|
|
17
16
|
private renderer;
|
|
18
17
|
private context;
|
|
19
18
|
private root;
|
|
@@ -21,8 +20,8 @@ export declare class AktionElement extends HTMLElement {
|
|
|
21
20
|
private errorEl;
|
|
22
21
|
private currentResponse;
|
|
23
22
|
/**
|
|
24
|
-
* Pre-parsed AST injected by `mountCompiled(...)` (the
|
|
25
|
-
*
|
|
23
|
+
* Pre-parsed AST injected by `mountCompiled(...)` (the multi-file linker
|
|
24
|
+
* path). When set, `replan()` consumes it instead of calling
|
|
26
25
|
* `parse(currentResponse)`, then clears it so a later string update
|
|
27
26
|
* (`setResponse` / `appendChunk`) re-parses normally. `null` for the
|
|
28
27
|
* ordinary streamed-string path.
|
|
@@ -30,9 +29,8 @@ export declare class AktionElement extends HTMLElement {
|
|
|
30
29
|
private pendingCompiled;
|
|
31
30
|
/**
|
|
32
31
|
* Module id of the compiled program currently mounted (from
|
|
33
|
-
* `CompiledProgram.path`), or `null` for the string path.
|
|
34
|
-
*
|
|
35
|
-
* `<aktion-app>` instances when a `.aktion` file changes.
|
|
32
|
+
* `CompiledProgram.path`), or `null` for the string path. Exposed via the
|
|
33
|
+
* `sourceId` getter so HMR / host tooling can target the right instances.
|
|
36
34
|
*/
|
|
37
35
|
private compiledSourceId;
|
|
38
36
|
private renderScheduled;
|
|
@@ -63,12 +61,18 @@ export declare class AktionElement extends HTMLElement {
|
|
|
63
61
|
private forceFullRender;
|
|
64
62
|
private parseErrors;
|
|
65
63
|
/**
|
|
66
|
-
* Token keys most recently applied by an in-script
|
|
64
|
+
* Token keys most recently applied by an in-script `$theme({...})`
|
|
67
65
|
* declaration. We remember them so the next render can clear stale
|
|
68
|
-
* overrides — otherwise switching from a
|
|
66
|
+
* overrides — otherwise switching from a `$theme(...)` block to the
|
|
69
67
|
* base theme would leave the previous tokens stuck on the host.
|
|
70
68
|
*/
|
|
71
69
|
private scriptThemeKeys;
|
|
70
|
+
/** Stable DevTools id for this element (`aktion-app-N`). */
|
|
71
|
+
private readonly devtoolsId;
|
|
72
|
+
/** Monotonic commit sequence for the render profiler (0 = initial mount). */
|
|
73
|
+
private devtoolsCommitId;
|
|
74
|
+
/** True once this element has been registered with the DevTools hook. */
|
|
75
|
+
private devtoolsRegistered;
|
|
72
76
|
constructor();
|
|
73
77
|
connectedCallback(): void;
|
|
74
78
|
disconnectedCallback(): void;
|
|
@@ -132,23 +136,21 @@ export declare class AktionElement extends HTMLElement {
|
|
|
132
136
|
state: Record<string, unknown>;
|
|
133
137
|
}): void;
|
|
134
138
|
/**
|
|
135
|
-
* Mount a
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
139
|
+
* Mount a linked / compiled program — the artefact produced by `linkProject`
|
|
140
|
+
* (multi-file modules) or `compileLite`. The pre-parsed AST is rendered
|
|
141
|
+
* directly, skipping the runtime parser; the runtime still re-validates
|
|
142
|
+
* against the active library on `replan()`, so a host that has called
|
|
143
|
+
* `registerComponents(...)` stays correct even if the program was linked
|
|
144
|
+
* against the default library.
|
|
141
145
|
*
|
|
142
146
|
* The string path (`setResponse`, `appendChunk`, `response`) is unaffected.
|
|
143
|
-
* Pass `state` to seed reactive values before the first render (
|
|
144
|
-
* hydration
|
|
145
|
-
* runtime, which snapshots via `serializeState()` and replays it here).
|
|
147
|
+
* Pass `state` to seed reactive values before the first render (SSR
|
|
148
|
+
* hydration; preserving live `$state` across a re-mount / hot edit).
|
|
146
149
|
*/
|
|
147
150
|
mountCompiled(compiled: CompiledProgram, state?: Record<string, unknown>): void;
|
|
148
151
|
/**
|
|
149
152
|
* Module id of the compiled program currently mounted, or `null` when the
|
|
150
|
-
* element is driven by the streamed-string path.
|
|
151
|
-
* HMR runtime to find the instances that host a changed `.aktion` file.
|
|
153
|
+
* element is driven by the streamed-string path.
|
|
152
154
|
*/
|
|
153
155
|
get sourceId(): string | null;
|
|
154
156
|
/** Append a streaming chunk and re-render. */
|
|
@@ -174,6 +176,34 @@ export declare class AktionElement extends HTMLElement {
|
|
|
174
176
|
set showErrors(value: boolean);
|
|
175
177
|
/** Dispatch a custom event from `emit()` calls in effect/action bodies. */
|
|
176
178
|
private emitCustomEvent;
|
|
179
|
+
/**
|
|
180
|
+
* Register this element with the global DevTools hook (idempotent). The
|
|
181
|
+
* exposed record only grants a debugger the operations it legitimately
|
|
182
|
+
* needs — read state, push an edit, read the program, force a render —
|
|
183
|
+
* never the raw runtime internals. A no-op when no hook is installed.
|
|
184
|
+
*/
|
|
185
|
+
private registerWithDevtools;
|
|
186
|
+
/**
|
|
187
|
+
* Public DevTools entry point: attach to a hook that was installed *after*
|
|
188
|
+
* this element mounted. The in-page panel calls this on every
|
|
189
|
+
* `<aktion-app>` it finds when it opens, so late-attaching DevTools picks up
|
|
190
|
+
* already-running apps. Idempotent; safe to call repeatedly.
|
|
191
|
+
*/
|
|
192
|
+
connectDevtools(): void;
|
|
193
|
+
/**
|
|
194
|
+
* Apply a DevTools-originated edit to a reactive atom. Dotted paths
|
|
195
|
+
* (`user.name`) write through `setPath` so the root is reconstructed
|
|
196
|
+
* immutably and dependents wake; bare names go through `set`. Either way the
|
|
197
|
+
* normal reactive flush → render pipeline runs, so the edit behaves exactly
|
|
198
|
+
* like one an event handler would make.
|
|
199
|
+
*/
|
|
200
|
+
private applyDevtoolsStateEdit;
|
|
201
|
+
/**
|
|
202
|
+
* Stamp `appId` + `time` onto an effect-runner payload and forward it to the
|
|
203
|
+
* hook. The runner already gated on `isDevtoolsActive()` before calling, so
|
|
204
|
+
* by the time we're here a frontend is listening.
|
|
205
|
+
*/
|
|
206
|
+
private emitDevtoolsEffect;
|
|
177
207
|
private buildInlineStyle;
|
|
178
208
|
/**
|
|
179
209
|
* Start the router so the hash listener is attached and `route` is
|
|
@@ -195,12 +225,13 @@ export declare class AktionElement extends HTMLElement {
|
|
|
195
225
|
private handleRouteChange;
|
|
196
226
|
private applyThemeFromAttribute;
|
|
197
227
|
/**
|
|
198
|
-
* Look for
|
|
199
|
-
* `
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
228
|
+
* Look for the reserved `theme` binding in the active program — set by a
|
|
229
|
+
* bare `$theme({...})` statement or an explicit `theme = $theme({...})`
|
|
230
|
+
* assignment (or any binding returning a `ThemeNode`). If found, write
|
|
231
|
+
* its tokens to the host as CSS custom properties so the in-script
|
|
232
|
+
* declaration layers on top of the attribute / `setTheme()` base. The
|
|
233
|
+
* previous render's keys are cleared first so removing a `$theme(...)`
|
|
234
|
+
* line snaps the renderer back to the underlying theme without a reload.
|
|
204
235
|
*/
|
|
205
236
|
private applyScriptThemeOverrides;
|
|
206
237
|
private scheduleRender;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from './renderer/index.js';
|
|
|
7
7
|
export * from './prompt/index.js';
|
|
8
8
|
export * from './theme/index.js';
|
|
9
9
|
export * from './language/index.js';
|
|
10
|
-
export * from './compiler/
|
|
10
|
+
export * from './compiler/index.js';
|
|
11
11
|
declare global {
|
|
12
12
|
interface HTMLElementTagNameMap {
|
|
13
13
|
"aktion-app": AktionElement;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Catalog of Aktion's `$`-prefixed builtins — the single source of truth for
|
|
3
|
+
* editor tooling (completions, hover, semantic highlighting, the TextMate
|
|
4
|
+
* grammar generator, and signature help).
|
|
5
|
+
*
|
|
6
|
+
* Aktion's runtime "builtins" are all `$`-prefixed forms. Some are hooks
|
|
7
|
+
* (`$state`, `$memo`, …), some are reactive factories (`$store`, `$http`, …),
|
|
8
|
+
* some register the app / router / theme, and some resolve to a namespace
|
|
9
|
+
* object (`$util.format(...)`, `$storage.local`, …). The legacy `@`-builtin
|
|
10
|
+
* catalog was removed in 0.5; programs use native JavaScript or `$util`.
|
|
11
|
+
*
|
|
12
|
+
* Keep this list in sync with the runtime dispatch in
|
|
13
|
+
* `src/runtime/evaluator.ts` (`evaluateInvoke` for `StateRef` callees) and the
|
|
14
|
+
* namespace implementations in `src/runtime/*`. Anything added here is
|
|
15
|
+
* automatically surfaced to every editor that consumes `aktion-runtime/language`.
|
|
16
|
+
*/
|
|
17
|
+
export type BuiltinCategory = "hook" | "effect" | "data" | "app" | "routing" | "theme" | "event" | "namespace";
|
|
18
|
+
export interface BuiltinEntry {
|
|
19
|
+
/** Name WITHOUT the leading `$` sigil (e.g. `"state"`, `"util"`). */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Reference form WITH the sigil (e.g. `"$state"`). */
|
|
22
|
+
sigil: string;
|
|
23
|
+
category: BuiltinCategory;
|
|
24
|
+
/** Completion label / signature skeleton, e.g. `"$state(initial)"`. */
|
|
25
|
+
signature: string;
|
|
26
|
+
/** One-line description for hover popups and completion detail. */
|
|
27
|
+
summary: string;
|
|
28
|
+
/**
|
|
29
|
+
* True when the name resolves to a namespace object whose members are
|
|
30
|
+
* reached via `.` (`$util.format`, `$storage.local`, `$toast.show`, …).
|
|
31
|
+
* Namespaces are NOT necessarily callable.
|
|
32
|
+
*/
|
|
33
|
+
namespace?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Every `$`-prefixed builtin Aktion exposes, grouped loosely by purpose.
|
|
37
|
+
* The order is the order editors surface them in the after-`$` completion
|
|
38
|
+
* list, so the most common authoring tools (hooks, effects) come first.
|
|
39
|
+
*/
|
|
40
|
+
export declare const builtinCatalog: readonly BuiltinEntry[];
|
|
41
|
+
/** Bare builtin names (without the `$` sigil), for O(1) membership tests. */
|
|
42
|
+
export declare const builtinNames: ReadonlySet<string>;
|
|
43
|
+
/** Catalog indexed by the bare name (`"state"`, `"util"`, …). */
|
|
44
|
+
export declare const builtinsByName: Readonly<Record<string, BuiltinEntry>>;
|
|
45
|
+
/**
|
|
46
|
+
* Resolve a `$`-prefixed builtin by its bare name (the value carried on a
|
|
47
|
+
* `StateIdentifier` token, e.g. `"state"` for `$state`). Returns `undefined`
|
|
48
|
+
* for user atoms / hooks that are not part of the runtime catalog.
|
|
49
|
+
*/
|
|
50
|
+
export declare function findBuiltin(bareName: string): BuiltinEntry | undefined;
|
|
51
|
+
/** True when `bareName` (no `$`) names a runtime builtin. */
|
|
52
|
+
export declare function isBuiltinName(bareName: string): boolean;
|
|
@@ -2,8 +2,9 @@ import { ComponentLibrary } from '../library/types.js';
|
|
|
2
2
|
import { grammarSpec, createStreamTokenizer, defaultTagMap, keywordDocs, GrammarSpec, GrammarTokenKind, StreamTokenizer, KeywordDoc } from './grammar.js';
|
|
3
3
|
import { getComponentCatalog, indexCatalog, ComponentEntry, ComponentParam } from './components.js';
|
|
4
4
|
import { getSnippets, SnippetEntry } from './snippets.js';
|
|
5
|
-
|
|
6
|
-
export {
|
|
5
|
+
import { builtinCatalog, builtinNames, builtinsByName, findBuiltin, isBuiltinName, BuiltinEntry, BuiltinCategory } from './builtins.js';
|
|
6
|
+
export type { GrammarSpec, GrammarTokenKind, StreamTokenizer, KeywordDoc, ComponentEntry, ComponentParam, SnippetEntry, BuiltinEntry, BuiltinCategory, };
|
|
7
|
+
export { grammarSpec, createStreamTokenizer, defaultTagMap, keywordDocs, getComponentCatalog, indexCatalog, getSnippets, builtinCatalog, builtinNames, builtinsByName, findBuiltin, isBuiltinName, };
|
|
7
8
|
/**
|
|
8
9
|
* Diagnostic severity buckets that map to common editor lint levels.
|
|
9
10
|
* Editors typically map: `error` → red squiggle, `warning` → yellow,
|
|
@@ -18,6 +19,8 @@ export interface LanguageSpec {
|
|
|
18
19
|
tagMap: Record<GrammarTokenKind, string | null>;
|
|
19
20
|
components: ComponentEntry[];
|
|
20
21
|
componentsByName: Record<string, ComponentEntry>;
|
|
22
|
+
/** Catalog of `$`-prefixed builtins (hooks, factories, namespaces). */
|
|
23
|
+
builtins: readonly BuiltinEntry[];
|
|
21
24
|
snippets: readonly SnippetEntry[];
|
|
22
25
|
/**
|
|
23
26
|
* Reserved-keyword documentation (definition + syntax + example),
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `aktion-runtime/language` — the DOM-free language + tooling surface.
|
|
3
3
|
*
|
|
4
|
-
* Editors (VS Code, a future LSP), CLIs, and any host that
|
|
5
|
-
* diagnostics / completions / hover / snippets / grammar metadata
|
|
6
|
-
* this
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* Editors (the VS Code extension, a future LSP), CLIs, and any Node host that
|
|
5
|
+
* needs diagnostics / completions / hover / snippets / grammar metadata import
|
|
6
|
+
* this instead of the package root. The root entry (`aktion-runtime`) defines
|
|
7
|
+
* the `<aktion-app>` custom element — `class AktionElement extends HTMLElement`
|
|
8
|
+
* plus a top-level `defineElement()` — which throws in a non-DOM runtime. This
|
|
9
|
+
* module pulls in NONE of that: everything re-exported here is pure and
|
|
10
|
+
* Node-safe (no DOM access at import time).
|
|
10
11
|
*/
|
|
11
12
|
export { getDiagnostics, getCompletions, getHoverInfo, type Position, type Diagnostic, type CompletionItem, type HoverInfo, } from './tooling/language-service.js';
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
13
|
+
export { getDefinition, getDefinitionTarget, findDeclaration, getReferences, getDocumentHighlights, getDocumentSymbols, getRenameEdits, type Range, type TextEdit, type RenameResult, type DocumentSymbol, type SymbolKind, type DefinitionTarget, } from './tooling/navigation.js';
|
|
14
|
+
export { getSemanticTokens, semanticTokenTypes, semanticTokenModifiers, type SemanticToken, type SemanticTokenType, type SemanticTokenModifier, } from './tooling/semantic-tokens.js';
|
|
15
|
+
export { getSignatureHelp, type SignatureHelp, type SignatureInfo, type ParameterInfo, } from './tooling/signature-help.js';
|
|
16
|
+
export { getLanguageSpec, grammarSpec, keywordDocs, getComponentCatalog, getSnippets, builtinCatalog, findBuiltin, isBuiltinName, type LanguageSpec, type GrammarSpec, type ComponentEntry, type ComponentParam, type SnippetEntry, type KeywordDoc, type BuiltinEntry, type BuiltinCategory, } from './language/index.js';
|
|
17
|
+
export { formatProgram, type FormatResult } from './tooling/formatter.js';
|
|
14
18
|
export { defaultLibrary } from './library/index.js';
|
|
15
19
|
export type { ComponentLibrary } from './library/types.js';
|
|
@@ -20,11 +20,6 @@ export declare const Portal: ComponentSpec;
|
|
|
20
20
|
* recognises the rendered output and redirects the router immediately.
|
|
21
21
|
*/
|
|
22
22
|
export declare const Redirect: ComponentSpec;
|
|
23
|
-
/**
|
|
24
|
-
* `Lazy(loader, fallback?)` — Defer the children until the `loader`
|
|
25
|
-
* promise resolves. The `loader` can be either a function returning a
|
|
26
|
-
* promise or a promise directly.
|
|
27
|
-
*/
|
|
28
23
|
export declare const Lazy: ComponentSpec;
|
|
29
24
|
/**
|
|
30
25
|
* `ErrorBoundary(fallback?, onError?, children)` — catches rendering
|
|
@@ -4,6 +4,7 @@ export declare const OnMouse: ComponentSpec;
|
|
|
4
4
|
export declare const OnKeyboard: ComponentSpec;
|
|
5
5
|
export declare const OnFocus: ComponentSpec;
|
|
6
6
|
export declare const OnIntersect: ComponentSpec;
|
|
7
|
+
export declare const OnMount: ComponentSpec;
|
|
7
8
|
export declare const Link: ComponentSpec;
|
|
8
9
|
export declare const Css: ComponentSpec;
|
|
9
10
|
export declare function attachOnChange(element: HTMLElement, callback: unknown, helpers: RenderHelpers, options: {
|
|
@@ -202,8 +202,8 @@ export interface AssignmentStatement {
|
|
|
202
202
|
isState: boolean;
|
|
203
203
|
expression: Expression;
|
|
204
204
|
/**
|
|
205
|
-
* True when prefixed with `export` (multi-file modules).
|
|
206
|
-
*
|
|
205
|
+
* True when prefixed with `export` (multi-file modules). Used by the linker
|
|
206
|
+
* to decide importability; the streaming runtime ignores it.
|
|
207
207
|
*/
|
|
208
208
|
exported?: boolean;
|
|
209
209
|
loc?: SourceLocation;
|
|
@@ -223,9 +223,9 @@ export interface ImportSpecifier {
|
|
|
223
223
|
}
|
|
224
224
|
/**
|
|
225
225
|
* `import { A, B as C, $shared } from "./other.aktion"` — named imports for
|
|
226
|
-
* multi-file `.aktion` programs. Resolved +
|
|
227
|
-
*
|
|
228
|
-
*
|
|
226
|
+
* multi-file `.aktion` programs. Resolved + merged into a single program by the
|
|
227
|
+
* linker (`linkProgram` / `linkProject`); the streaming runtime treats `Import`
|
|
228
|
+
* as a no-op (it has no module map to resolve against).
|
|
229
229
|
*/
|
|
230
230
|
export interface ImportStatement {
|
|
231
231
|
kind: "Import";
|
|
@@ -246,7 +246,7 @@ export interface ComponentDeclaration {
|
|
|
246
246
|
/** Names of the declared slots (from props object convention). */
|
|
247
247
|
slots: ReadonlyArray<string>;
|
|
248
248
|
body: BlockExpr;
|
|
249
|
-
/** True when prefixed with `export` (multi-file modules
|
|
249
|
+
/** True when prefixed with `export` (multi-file modules). */
|
|
250
250
|
exported?: boolean;
|
|
251
251
|
loc?: SourceLocation;
|
|
252
252
|
}
|
|
@@ -325,9 +325,8 @@ export interface ActionDeclaration {
|
|
|
325
325
|
kind: "ActionDeclaration";
|
|
326
326
|
name: string;
|
|
327
327
|
params: ReadonlyArray<DeclParam>;
|
|
328
|
-
optimistic: boolean;
|
|
329
328
|
body: BlockExpr;
|
|
330
|
-
/** True when prefixed with `export` (multi-file modules
|
|
329
|
+
/** True when prefixed with `export` (multi-file modules). */
|
|
331
330
|
exported?: boolean;
|
|
332
331
|
loc?: SourceLocation;
|
|
333
332
|
}
|
|
@@ -354,7 +353,7 @@ export interface HookDeclaration {
|
|
|
354
353
|
name: string;
|
|
355
354
|
params: ReadonlyArray<DeclParam>;
|
|
356
355
|
body: BlockExpr;
|
|
357
|
-
/** True when prefixed with `export` (multi-file modules
|
|
356
|
+
/** True when prefixed with `export` (multi-file modules). */
|
|
358
357
|
exported?: boolean;
|
|
359
358
|
loc?: SourceLocation;
|
|
360
359
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
export interface AktionPluginOptions {
|
|
3
|
+
/** Treat linker warnings (e.g. a missing `aktion` entry) as build errors. Default: false. */
|
|
4
|
+
strict?: boolean;
|
|
5
|
+
/** Specifier the emitted module imports the runtime helper from. Default: `"aktion-runtime"`. */
|
|
6
|
+
runtimeModuleId?: string;
|
|
7
|
+
}
|
|
1
8
|
/**
|
|
2
|
-
* `
|
|
3
|
-
*
|
|
4
|
-
* Default export is the plugin factory, so consumers can write either:
|
|
9
|
+
* Add to `vite.config.ts`:
|
|
5
10
|
*
|
|
6
11
|
* import aktion from "aktion-runtime/vite";
|
|
7
|
-
*
|
|
12
|
+
* export default { plugins: [aktion()] };
|
|
8
13
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
14
|
+
export declare function aktionPlugin(options?: AktionPluginOptions): Plugin;
|
|
15
|
+
/** True for `*.aktion` ids (query/hash stripped). Exported for tests. */
|
|
16
|
+
export declare function isAktionId(id: string): boolean;
|
|
17
|
+
export { aktionPlugin as default };
|
|
@@ -2,6 +2,7 @@ import { EvaluationContext, ScopedEffectDecl } from '../runtime/evaluator.js';
|
|
|
2
2
|
import { StateStore } from '../runtime/state.js';
|
|
3
3
|
import { Router } from '../runtime/router.js';
|
|
4
4
|
import { ComponentLibrary } from '../library/types.js';
|
|
5
|
+
import { ComponentRenderRecord } from '../devtools/protocol.js';
|
|
5
6
|
export interface RenderOptions {
|
|
6
7
|
library: ComponentLibrary;
|
|
7
8
|
state: StateStore;
|
|
@@ -94,7 +95,32 @@ export declare class Renderer {
|
|
|
94
95
|
private changedPaths;
|
|
95
96
|
/** Whether memoization may apply this render (false on mount / replan / notify). */
|
|
96
97
|
private memoEnabled;
|
|
98
|
+
/**
|
|
99
|
+
* When `true`, each render appends a {@link ComponentRenderRecord} per
|
|
100
|
+
* visited instance to {@link profilerRecords}. Toggled by the host element
|
|
101
|
+
* once a DevTools frontend is actually listening, so a closed inspector
|
|
102
|
+
* costs nothing. See `setProfiling`.
|
|
103
|
+
*/
|
|
104
|
+
private profiling;
|
|
105
|
+
/** Per-commit profiler records, drained by the host after each render. */
|
|
106
|
+
private profilerRecords;
|
|
107
|
+
/**
|
|
108
|
+
* Every instance key seen in a *previous* render, so the profiler can label
|
|
109
|
+
* a record `mount` (first sighting) vs `update`. Pruned in `endRender` so it
|
|
110
|
+
* tracks exactly the live tree. Only maintained while profiling.
|
|
111
|
+
*/
|
|
112
|
+
private profiledInstances;
|
|
97
113
|
constructor(options: RenderOptions);
|
|
114
|
+
/**
|
|
115
|
+
* Enable/disable the render profiler. The host element flips this on when a
|
|
116
|
+
* DevTools frontend subscribes and off when it disconnects, so the common
|
|
117
|
+
* (no-DevTools) path never allocates a record or reads the clock.
|
|
118
|
+
*/
|
|
119
|
+
setProfiling(enabled: boolean): void;
|
|
120
|
+
/** Hand the current commit's component records to the host, then clear. */
|
|
121
|
+
drainProfilerRecords(): ComponentRenderRecord[];
|
|
122
|
+
/** Tree depth for flamegraph indentation — one level per `#instance` segment. */
|
|
123
|
+
private depthOf;
|
|
98
124
|
/**
|
|
99
125
|
* Swap the component library backing this renderer. Used when the host
|
|
100
126
|
* element calls `registerComponents(...)` after first paint — preserves
|
|
@@ -124,6 +150,8 @@ export declare class Renderer {
|
|
|
124
150
|
* disappeared from the tree so the map doesn't grow unbounded.
|
|
125
151
|
*/
|
|
126
152
|
endRender(): void;
|
|
153
|
+
/** Record one component instance's contribution to the current commit. */
|
|
154
|
+
private profile;
|
|
127
155
|
private safeDispose;
|
|
128
156
|
/**
|
|
129
157
|
* Apply a state write addressed by either a plain atom name
|
|
@@ -5,24 +5,18 @@
|
|
|
5
5
|
* has been removed. Programs now reach for equivalent native
|
|
6
6
|
* JavaScript or the `Util` namespace (see `./util.ts`).
|
|
7
7
|
*/
|
|
8
|
-
export type BuiltinFn = (args: unknown[]) => unknown;
|
|
9
|
-
/**
|
|
10
|
-
* Empty registry kept as a structural placeholder so the parser's
|
|
11
|
-
* synthetic `BuiltinCall` nodes (`__rui_assign__`, `__rui_postfix__`,
|
|
12
|
-
* `__rui_prefix__`, `__rui_await__`) flow through the evaluator without
|
|
13
|
-
* a surprise lookup.
|
|
14
|
-
*/
|
|
15
|
-
export declare const dataBuiltins: Record<string, BuiltinFn>;
|
|
16
8
|
/**
|
|
17
9
|
* Marker emitted by the `Theme({...})` construct. Carries an arbitrary token
|
|
18
10
|
* map that the element applies on top of the base theme between render
|
|
19
11
|
* cycles. Distinct from `ComponentNode` so the renderer can ignore it (it is
|
|
20
12
|
* a side-effect, not a piece of UI to draw).
|
|
21
13
|
*
|
|
22
|
-
* Authors
|
|
14
|
+
* Authors apply a theme with a bare top-level `$theme({...})` statement
|
|
15
|
+
* (no binding needed); the equivalent `theme = $theme({...})` form also
|
|
16
|
+
* works and registers the same reserved `theme` binding:
|
|
23
17
|
*
|
|
24
|
-
* theme
|
|
25
|
-
* root
|
|
18
|
+
* $theme({ colors: { primary: "#0969da" }, radius: { button: "6px" } })
|
|
19
|
+
* root = Stack([...])
|
|
26
20
|
*/
|
|
27
21
|
export interface ThemeNode {
|
|
28
22
|
kind: "Theme";
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EffectDeclaration } from '../parser/types.js';
|
|
2
2
|
import { EvaluationContext, ScopedEffectDecl } from './evaluator.js';
|
|
3
3
|
import { StateStore } from './state.js';
|
|
4
|
+
import { EffectEventPayload } from '../devtools/protocol.js';
|
|
4
5
|
export interface EffectRunnerOptions {
|
|
5
6
|
state: StateStore;
|
|
6
7
|
/** Called whenever an effect mutates state or completes — schedules render. */
|
|
7
8
|
notify: () => void;
|
|
8
9
|
/** Called when the effect/action body emits a CustomEvent via `emit()`. */
|
|
9
10
|
onEmit?: (eventName: string, detail: unknown) => void;
|
|
11
|
+
/**
|
|
12
|
+
* DevTools instrumentation sink. Called on every effect lifecycle
|
|
13
|
+
* transition (mount / run / cleanup / unmount / error) with everything the
|
|
14
|
+
* runner can compute on its own; the host stamps on `appId` + `time`. Only
|
|
15
|
+
* invoked while a DevTools frontend is actually attached, so it costs
|
|
16
|
+
* nothing when the inspector is closed.
|
|
17
|
+
*/
|
|
18
|
+
onEffectEvent?: (payload: EffectEventPayload) => void;
|
|
10
19
|
}
|
|
11
20
|
export declare class EffectRunner {
|
|
12
21
|
private readonly options;
|
|
@@ -42,22 +51,11 @@ export declare class EffectRunner {
|
|
|
42
51
|
unmountInstance(instanceKey: string): void;
|
|
43
52
|
reset(): void;
|
|
44
53
|
private mount;
|
|
54
|
+
/**
|
|
55
|
+
* Build and dispatch one DevTools effect event. Returns immediately when no
|
|
56
|
+
* frontend is attached, so the only cost on the hot path is a single
|
|
57
|
+
* global-property read.
|
|
58
|
+
*/
|
|
59
|
+
private emitEffect;
|
|
45
60
|
private unmount;
|
|
46
61
|
}
|
|
47
|
-
export interface ActionRunnerOptions {
|
|
48
|
-
state: StateStore;
|
|
49
|
-
notify: () => void;
|
|
50
|
-
onEmit?: (eventName: string, detail: unknown) => void;
|
|
51
|
-
onAssistantMessage?: (message: string) => void;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Run an `action` declaration. When the declaration is `optimistic` we
|
|
55
|
-
* snapshot every state atom touched before the first `await`; if any
|
|
56
|
-
* subsequent step throws, the snapshot is restored.
|
|
57
|
-
*/
|
|
58
|
-
export declare class ActionDeclRunner {
|
|
59
|
-
private readonly options;
|
|
60
|
-
constructor(options: ActionRunnerOptions);
|
|
61
|
-
run(decl: ActionDeclaration, callArgs: unknown[], ctx: EvaluationContext): Promise<unknown>;
|
|
62
|
-
private runStatement;
|
|
63
|
-
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Expression, Program, Statement, ComponentDeclaration, EffectDeclaration, ActionDeclaration, HookDeclaration, DestructuringPattern } from '../parser/types.js';
|
|
2
2
|
import { StateStore } from './state.js';
|
|
3
|
-
import { HttpRuntime } from './http.js';
|
|
4
|
-
import { ActionDeclRunner } from './effects.js';
|
|
3
|
+
import { HttpRuntime, EndpointResource } from './http.js';
|
|
5
4
|
import { Router } from './router.js';
|
|
6
5
|
import { ComponentLibrary } from '../library/types.js';
|
|
6
|
+
import { ToastManager } from './toast.js';
|
|
7
7
|
/**
|
|
8
8
|
* Runtime safety budget — bounds the work a single render can perform
|
|
9
9
|
* so a partial / accidentally-recursive program (e.g. while the user is
|
|
@@ -208,6 +208,17 @@ export type HookCell = {
|
|
|
208
208
|
kind: "memo";
|
|
209
209
|
deps: ReadonlyArray<unknown> | undefined;
|
|
210
210
|
value: unknown;
|
|
211
|
+
} | {
|
|
212
|
+
kind: "ref";
|
|
213
|
+
box: {
|
|
214
|
+
current: unknown;
|
|
215
|
+
};
|
|
216
|
+
} | {
|
|
217
|
+
kind: "reducer";
|
|
218
|
+
value: unknown;
|
|
219
|
+
} | {
|
|
220
|
+
kind: "id";
|
|
221
|
+
value: string;
|
|
211
222
|
};
|
|
212
223
|
/**
|
|
213
224
|
* Active hook scope — the component instance currently rendering, plus a
|
|
@@ -313,12 +324,41 @@ export interface EvaluationContext {
|
|
|
313
324
|
stores: Map<string, StoreHandle>;
|
|
314
325
|
/** HTTP runtime (`Http({...})` calls + interceptor configuration). */
|
|
315
326
|
http?: HttpRuntime;
|
|
316
|
-
/**
|
|
317
|
-
|
|
327
|
+
/**
|
|
328
|
+
* Shared cache of `$query({...})` resources, keyed by the query's `key`
|
|
329
|
+
* (or a value derived from method + url + query + body). Lets repeated and
|
|
330
|
+
* cross-component queries share one in-flight request / cached result.
|
|
331
|
+
* Lives as long as the program; rebuilt on replan with a fresh context.
|
|
332
|
+
*/
|
|
333
|
+
queryCache: Map<string, EndpointResource>;
|
|
334
|
+
/**
|
|
335
|
+
* Lazily-created singleton backing the reserved `$toast` namespace
|
|
336
|
+
* (`$toast.show(...)`, `$toast.items`, …). Created on first reference via
|
|
337
|
+
* `getToastManager`; its auto-dismiss timers are cleared on dispose.
|
|
338
|
+
*/
|
|
339
|
+
toastManager?: ToastManager;
|
|
318
340
|
/** Notify the host that something changed and a re-render is needed. */
|
|
319
341
|
notify?: () => void;
|
|
320
342
|
/** Dispatch a custom event from an `emit("name", detail)` call. */
|
|
321
343
|
onEmit?: (eventName: string, detail: unknown) => void;
|
|
344
|
+
/**
|
|
345
|
+
* Active teardown sink during an effect-body run. When set, a bare
|
|
346
|
+
* `cleanup` identifier resolves to a real bound function that pushes into
|
|
347
|
+
* the running effect's cleanup list — so `cleanup(fn)` keeps working even
|
|
348
|
+
* when aliased (`const c = cleanup; c(fn)`) or used inside a nested block,
|
|
349
|
+
* rather than being detected only by literal callee name (feedback §2.5).
|
|
350
|
+
* Unset outside effect runs, where `cleanup` has no meaning.
|
|
351
|
+
*/
|
|
352
|
+
cleanupSink?: ((fn: () => void) => void) | null;
|
|
353
|
+
/**
|
|
354
|
+
* Dev/strict mode (opt-in via the `strict` attribute on `<aktion-app>`).
|
|
355
|
+
* When set, the evaluator surfaces silent failures — currently unknown
|
|
356
|
+
* bare identifiers that would otherwise resolve to `null` — as
|
|
357
|
+
* `console.warn`s. Off by default so production behaviour is unchanged.
|
|
358
|
+
*/
|
|
359
|
+
strict?: boolean;
|
|
360
|
+
/** De-dupes strict-mode warnings to one per identifier per program. */
|
|
361
|
+
strictWarned: Set<string>;
|
|
322
362
|
/**
|
|
323
363
|
* Cleanup callbacks attached to this context. Populated during
|
|
324
364
|
* `planProgram` for resources that outlive a single evaluation pass —
|
|
@@ -361,9 +401,10 @@ export interface CreateContextOptions {
|
|
|
361
401
|
router?: Router;
|
|
362
402
|
library?: ComponentLibrary;
|
|
363
403
|
http?: HttpRuntime;
|
|
364
|
-
actionRunner?: ActionDeclRunner;
|
|
365
404
|
notify?: () => void;
|
|
366
405
|
onEmit?: (eventName: string, detail: unknown) => void;
|
|
406
|
+
/** Enable dev/strict-mode warnings for silent failures. */
|
|
407
|
+
strict?: boolean;
|
|
367
408
|
/**
|
|
368
409
|
* Runtime safety budget for this context.
|
|
369
410
|
* - omitted (default): a fresh budget with `DEFAULT_RUNTIME_BUDGET` limits.
|
|
@@ -70,7 +70,6 @@ export declare class HttpRuntime {
|
|
|
70
70
|
/**
|
|
71
71
|
* Issue a single HTTP request. Runs through `onRequest`/`onResponse`
|
|
72
72
|
* interceptors and surfaces a `retry()` one-shot inside `onResponse`.
|
|
73
|
-
* Honours `defaults.timeoutMs` via `AbortController`.
|
|
74
73
|
*/
|
|
75
74
|
request(input: HttpRequest): Promise<HttpResponse>;
|
|
76
75
|
}
|
|
@@ -88,3 +87,44 @@ export declare class HttpRuntime {
|
|
|
88
87
|
* is what makes back-to-back refetches and cancels deterministic.
|
|
89
88
|
*/
|
|
90
89
|
export declare function createHttpResource(config: unknown, ctx: EvaluationContext): EndpointResource;
|
|
90
|
+
/**
|
|
91
|
+
* `$query({ url, key?, ttl?, ... })` — a cached, deduplicated `$http` read.
|
|
92
|
+
*
|
|
93
|
+
* Unlike `$http`, which fires a fresh request on every call, `$query` keys
|
|
94
|
+
* the resource by `key` (or a value derived from method + url + query + body)
|
|
95
|
+
* and reuses the same reactive bag across renders and across components. The
|
|
96
|
+
* first caller creates the request; everyone else with the same key shares
|
|
97
|
+
* the in-flight result (deduplication). Pass `ttl` (ms) to auto-refetch when
|
|
98
|
+
* the cached data is older than the TTL.
|
|
99
|
+
*/
|
|
100
|
+
export declare function createQueryResource(config: unknown, ctx: EvaluationContext): EndpointResource;
|
|
101
|
+
/** Reactive bag returned by `$mutation({...})`. Fires only on `mutate()`. */
|
|
102
|
+
export interface MutationResource {
|
|
103
|
+
data: unknown;
|
|
104
|
+
error: unknown;
|
|
105
|
+
loading: boolean;
|
|
106
|
+
status?: number;
|
|
107
|
+
/**
|
|
108
|
+
* Fire the request. Optionally pass an overrides object (shallow-merged
|
|
109
|
+
* over the base config) to set the `body` / `query` / `url` for this call:
|
|
110
|
+
* $save.mutate({ body: { title: $title } })
|
|
111
|
+
* Resolves with the response body (or `undefined` on error / supersede).
|
|
112
|
+
*/
|
|
113
|
+
mutate: (overrides?: unknown) => Promise<unknown>;
|
|
114
|
+
/** Clear `data` / `error` / `loading` back to the resting state. */
|
|
115
|
+
reset: () => void;
|
|
116
|
+
/** Optional completion callback; fires once each time a mutation settles. */
|
|
117
|
+
onDone?: (resource: MutationResource) => void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* `$mutation({ url, method?, ... })` — a write that fires only when you call
|
|
121
|
+
* `.mutate(...)`, not on render. The canonical create/update/delete pattern:
|
|
122
|
+
*
|
|
123
|
+
* $save = $mutation({ url: "/todos", method: "POST" })
|
|
124
|
+
* ...
|
|
125
|
+
* Button("Add", { onClick: () => $save.mutate({ body: { title: $title } }) })
|
|
126
|
+
*
|
|
127
|
+
* Method defaults to `POST` when unspecified. The bag exposes reactive
|
|
128
|
+
* `loading` / `error` / `data` plus `reset()` and an `onDone` hook.
|
|
129
|
+
*/
|
|
130
|
+
export declare function createMutationResource(baseConfig: unknown, ctx: EvaluationContext): MutationResource;
|
|
@@ -6,4 +6,5 @@ export * from './http.js';
|
|
|
6
6
|
export * from './i18n.js';
|
|
7
7
|
export { storage, type CookieOptions, type StorageNamespace, type StorageRoot } from './storage.js';
|
|
8
8
|
export { consoleNs, type ConsoleNamespace } from './console.js';
|
|
9
|
-
export {
|
|
9
|
+
export { createToastManager, type ToastManager, type ToastItem, type ToastOptions, } from './toast.js';
|
|
10
|
+
export { EffectRunner, type EffectRunnerOptions, } from './effects.js';
|