Implement closed typed effect path

This commit is contained in:
tmk241
2026-09-01 00:58:29 +02:00
parent 353174604e
commit 31a0f02211
58 changed files with 4247 additions and 5933 deletions
+18 -27
View File
@@ -1,4 +1,3 @@
// req: ts/001
export type ResourceKind = "slot" | "atom" | "handle" | "form";
export interface ResourceId {
@@ -15,24 +14,27 @@ export interface ResourceRef {
scope: ScopeKey | null;
}
export type Payload =
| { kind: "text"; value: string }
| { kind: "html"; value: string };
export type InsertPosition =
| "first"
| "last"
| { kind: "before"; target: ResourceRef }
| { kind: "after"; target: ResourceRef };
export type ScrollBehavior =
| "preserve"
| "top"
| { kind: "element"; target: ResourceRef };
export type MovePosition = InsertPosition;
export type PatchMode = "morph" | "replace";
export type ScrollBlock = "start" | "center" | "end" | "nearest";
export type ScrollBehavior = "auto" | "instant" | "smooth";
export type HistoryMode = "push" | "replace";
export type Effect =
| { kind: "put"; target: ResourceRef; payload: Payload }
| { kind: "insert"; target: ResourceRef; key: string; payload: Payload }
| { kind: "prepend"; target: ResourceRef; key: string; payload: Payload }
| { kind: "remove"; target: ResourceRef; key: string | null }
| { kind: "move"; target: ResourceRef; key: string; before: string | null }
| { kind: "focus"; target: ResourceRef }
| { kind: "navigate"; url: string; mode: "push" | "replace" | "redirect"; scroll: ScrollBehavior; title: string | null }
| { kind: "emit"; name: string; payload: string };
| { kind: "patch"; target: ResourceRef; mode: PatchMode; html: string }
| { kind: "insert"; target: ResourceRef; position: InsertPosition; html: string }
| { kind: "remove"; target: ResourceRef }
| { kind: "move"; target: ResourceRef; position: MovePosition }
| { kind: "focus"; target: ResourceRef; preventScroll: boolean }
| { kind: "scroll"; target: ResourceRef; block: ScrollBlock; behavior: ScrollBehavior }
| { kind: "visit"; url: string; history: HistoryMode }
| { kind: "dispatch"; event: string; payload: Uint8Array };
export interface EffectBatch {
abiVersion: number;
@@ -45,16 +47,6 @@ export interface AtomSnapshot {
bytes: Uint8Array;
}
export type ClientHandler = (
eventVersion: number,
eventKind: string,
eventValue: string | undefined,
eventChecked: boolean | undefined,
eventKey: string | undefined,
stateVersion: number,
encodedState: string,
) => Uint8Array | Promise<Uint8Array>;
export interface HemxRuntime {
readonly runtimeAbiVersion: number;
roots(): Element[];
@@ -64,7 +56,6 @@ export interface HemxRuntime {
decodeBatch(buffer: ArrayBuffer): EffectBatch;
atomValue(root: Element | ParentNode | null | undefined, id: number): Uint8Array | undefined;
decodeAtomState(encoded: string): AtomSnapshot[];
registerClientHandler(name: string, handler: ClientHandler): ClientHandler | undefined;
}
declare global {