@go-go-golems/pbui-core 0.1.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 +73 -0
- package/builder.d.ts +74 -0
- package/builder.js +191 -0
- package/command.d.ts +91 -0
- package/command.js +64 -0
- package/docline.d.ts +5 -0
- package/docline.js +43 -0
- package/engine.d.ts +177 -0
- package/engine.js +790 -0
- package/index.d.ts +10 -0
- package/index.js +10 -0
- package/invocation.d.ts +34 -0
- package/invocation.js +71 -0
- package/package.json +25 -0
- package/ptype.d.ts +40 -0
- package/ptype.js +103 -0
- package/registry.d.ts +40 -0
- package/registry.js +143 -0
- package/transcript-text.d.ts +3 -0
- package/transcript-text.js +31 -0
- package/transcript.d.ts +16 -0
- package/transcript.js +49 -0
- package/types.d.ts +83 -0
- package/types.js +29 -0
package/engine.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { ArgValue, ArgValues, ObjectRef, PartLike, PresentationRecord, Unsubscribe } from "./types.js";
|
|
2
|
+
import type { ArgSpec, CommandSpec } from "./command.js";
|
|
3
|
+
import { CommandTable } from "./command.js";
|
|
4
|
+
import { PTypes } from "./ptype.js";
|
|
5
|
+
import { PresentationRegistry } from "./registry.js";
|
|
6
|
+
import { Transcript } from "./transcript.js";
|
|
7
|
+
import { InvocationLog } from "./invocation.js";
|
|
8
|
+
import type { Resolver } from "./types.js";
|
|
9
|
+
export interface AcceptState {
|
|
10
|
+
/** command being filled; null for an ad-hoc api.accept() */
|
|
11
|
+
cmd: CommandSpec<any> | null;
|
|
12
|
+
values: ArgValues;
|
|
13
|
+
spec: ArgSpec;
|
|
14
|
+
resolveAdhoc?: (v: ArgValue | null) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface MenuItem {
|
|
17
|
+
label: string;
|
|
18
|
+
doc?: string;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
run: () => void;
|
|
21
|
+
}
|
|
22
|
+
export interface MenuState {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
title: string;
|
|
26
|
+
items: MenuItem[];
|
|
27
|
+
}
|
|
28
|
+
export interface EngineState {
|
|
29
|
+
accept: AcceptState | null;
|
|
30
|
+
hover: PresentationRecord | null;
|
|
31
|
+
menu: MenuState | null;
|
|
32
|
+
pointer: {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
};
|
|
36
|
+
/** keyboard focus cursor over presentations (CLIM-JSX-004 §6.1) */
|
|
37
|
+
focus: string | null;
|
|
38
|
+
}
|
|
39
|
+
export interface Coercion {
|
|
40
|
+
from: string;
|
|
41
|
+
to: string;
|
|
42
|
+
coerce: (pres: PresentationRecord) => ArgValue;
|
|
43
|
+
}
|
|
44
|
+
export interface EngineOptions<W> {
|
|
45
|
+
ptypes: PTypes<W>;
|
|
46
|
+
commands: CommandTable<W>;
|
|
47
|
+
world: W;
|
|
48
|
+
resolver: Resolver;
|
|
49
|
+
transcriptCap?: number;
|
|
50
|
+
/** idle mouse-doc line text */
|
|
51
|
+
idleDoc?: string;
|
|
52
|
+
}
|
|
53
|
+
export type GestureKind = "click" | "aux" | "context" | "enter" | "leave";
|
|
54
|
+
export declare class PbuiEngine<W = unknown> {
|
|
55
|
+
readonly ptypes: PTypes<W>;
|
|
56
|
+
readonly commands: CommandTable<W>;
|
|
57
|
+
readonly registry: PresentationRegistry;
|
|
58
|
+
readonly transcript: Transcript;
|
|
59
|
+
readonly world: W;
|
|
60
|
+
readonly resolver: Resolver;
|
|
61
|
+
readonly idleDoc: string;
|
|
62
|
+
/** every executed command, with lifecycle state (CLIM-JSX-004 §7) */
|
|
63
|
+
readonly invocations: InvocationLog;
|
|
64
|
+
/** transcript echo line awaiting its invocation (set by startCommand*) */
|
|
65
|
+
private pendingEchoLineId;
|
|
66
|
+
/** bound resolver passthrough handed to spec callbacks (ResolveFn).
|
|
67
|
+
* Invocation refs resolve from the engine's own log; everything else
|
|
68
|
+
* delegates to the app resolver. */
|
|
69
|
+
readonly resolveFn: (ref: ObjectRef) => unknown | undefined;
|
|
70
|
+
private coercions;
|
|
71
|
+
private listeners;
|
|
72
|
+
/** ids of registered presentations eligible for the current accept
|
|
73
|
+
* (CLIM-JSX-005 §6.3); null when no accept is active */
|
|
74
|
+
private eligibleIds;
|
|
75
|
+
private state;
|
|
76
|
+
constructor(opts: EngineOptions<W>);
|
|
77
|
+
getState(): EngineState;
|
|
78
|
+
subscribe(fn: () => void): Unsubscribe;
|
|
79
|
+
private setState;
|
|
80
|
+
/** hover transitions notify exactly the affected presentations: the old
|
|
81
|
+
* and new hover targets plus every presentation of the same objects
|
|
82
|
+
* (related-hover outlines). This is the mouse-frequency hot path. */
|
|
83
|
+
private setHover;
|
|
84
|
+
print(...parts: PartLike[]): void;
|
|
85
|
+
printErr(...parts: PartLike[]): void;
|
|
86
|
+
/** standardized command failure (stale arguments etc.): prints the
|
|
87
|
+
* error line only. api.fail (the wrapper commands receive) additionally
|
|
88
|
+
* marks the current invocation as failed — prefer it inside commands. */
|
|
89
|
+
failInvocation(cmdName: string, ...reason: PartLike[]): void;
|
|
90
|
+
defineCoercion(c: Coercion): void;
|
|
91
|
+
/** turn a presentation into the ArgValue a spec wants, or null */
|
|
92
|
+
private coerceFor;
|
|
93
|
+
/** the full predicate — used to (re)build the cache and for ad-hoc
|
|
94
|
+
* (unregistered) records such as test fixtures */
|
|
95
|
+
private eligibleUncached;
|
|
96
|
+
/** would clicking this presentation supply the currently wanted arg?
|
|
97
|
+
* O(1) for registered presentations via the eligible-set cache. */
|
|
98
|
+
eligible(pres: Pick<PresentationRecord, "type" | "ref" | "label"> & {
|
|
99
|
+
id?: string;
|
|
100
|
+
}): boolean;
|
|
101
|
+
/** registered presentations eligible right now (keyboard Tab-cycling) */
|
|
102
|
+
eligibleList(): PresentationRecord[];
|
|
103
|
+
private recomputeEligible;
|
|
104
|
+
/** accept transitions recompute the cache and broadcast (D3: accept
|
|
105
|
+
* changes are user-paced; hover changes are the targeted hot path) */
|
|
106
|
+
private setAccept;
|
|
107
|
+
/** an input context is active and this presentation does not match */
|
|
108
|
+
inert(pres: Pick<PresentationRecord, "type" | "ref" | "label">): boolean;
|
|
109
|
+
startCommand(nameOrCmd: string | CommandSpec<W>, seed?: PresentationRecord): void;
|
|
110
|
+
/** run with preset values (from the command line's positional args) */
|
|
111
|
+
startCommandWithValues(cmd: CommandSpec<W>, values: ArgValues): void;
|
|
112
|
+
private advance;
|
|
113
|
+
/** supply the current argument by pointing at a presentation */
|
|
114
|
+
supply(pres: PresentationRecord): void;
|
|
115
|
+
/** supply the current argument with an already-built value */
|
|
116
|
+
supplyValue(v: ArgValue): void;
|
|
117
|
+
abort(silent?: boolean): void;
|
|
118
|
+
private execute;
|
|
119
|
+
private makeApi;
|
|
120
|
+
/** promise facade over the FSM (metrics(1)'s prompt(), D6) */
|
|
121
|
+
acceptAdhoc(spec: ArgSpec): Promise<ArgValue | null>;
|
|
122
|
+
/** Enter pressed in the listener input. Routes to the pending argument or
|
|
123
|
+
* to the command line. Returns true if the text was consumed. */
|
|
124
|
+
submitTyped(text: string): boolean;
|
|
125
|
+
/** command line: longest-prefix command match + greedy positional args */
|
|
126
|
+
submitCommandLine(text: string): boolean;
|
|
127
|
+
completions(text: string): string[];
|
|
128
|
+
notePointer(x: number, y: number): void;
|
|
129
|
+
gesture(kind: GestureKind, pres: PresentationRecord, x?: number, y?: number): void;
|
|
130
|
+
backgroundContext(x: number, y: number): void;
|
|
131
|
+
escape(): void;
|
|
132
|
+
/** left-click outside an input context: per-type default command, else Describe */
|
|
133
|
+
defaultAction(pres: PresentationRecord): void;
|
|
134
|
+
defaultCommandFor(pres: PresentationRecord): CommandSpec<W> | undefined;
|
|
135
|
+
/** run a seed-complete duringAccept command WITHOUT touching the pending
|
|
136
|
+
* input context; eligibility recomputes afterwards in case the command's
|
|
137
|
+
* effects changed where-clauses */
|
|
138
|
+
private executeImmediate;
|
|
139
|
+
/** reduced menu on active presentations mid-accept: duringAccept commands
|
|
140
|
+
* only (plus the chrome's Abort footer) */
|
|
141
|
+
private openDuringAcceptMenu;
|
|
142
|
+
describePres(pres: Pick<PresentationRecord, "type" | "ref" | "label">): void;
|
|
143
|
+
commandApplies(cmd: CommandSpec<W>, pres: PresentationRecord): boolean;
|
|
144
|
+
applicableCommands(pres: PresentationRecord): CommandSpec<W>[];
|
|
145
|
+
openCommandMenu(pres: PresentationRecord, x: number, y: number): void;
|
|
146
|
+
openGlobalMenu(x: number, y: number): void;
|
|
147
|
+
private openChoiceMenu;
|
|
148
|
+
closeMenu(): void;
|
|
149
|
+
/** set the keyboard focus cursor; targeted notification like hover */
|
|
150
|
+
setFocus(id: string | null): void;
|
|
151
|
+
/** the presentation that should carry tabIndex=0: the focus cursor if it
|
|
152
|
+
* still exists, else the first registered presentation */
|
|
153
|
+
focusTarget(): string | null;
|
|
154
|
+
/** the focused presentation record, for the doc line */
|
|
155
|
+
focusRecord(): PresentationRecord | null;
|
|
156
|
+
/** move the focus cursor through registry order (arrow keys) */
|
|
157
|
+
moveFocus(dir: 1 | -1): string | null;
|
|
158
|
+
/** Tab during an accept: cycle the eligible presentations */
|
|
159
|
+
moveFocusEligible(dir: 1 | -1): string | null;
|
|
160
|
+
/** Undo the most recent undoable invocation. Linear-only (D4): passing an
|
|
161
|
+
* id that is not the last undoable is refused with a coaching message. */
|
|
162
|
+
undoInvocation(id?: string): Promise<boolean>;
|
|
163
|
+
promptInfo(): {
|
|
164
|
+
accepting: boolean;
|
|
165
|
+
cmdName?: string;
|
|
166
|
+
filled: {
|
|
167
|
+
name: string;
|
|
168
|
+
label: string;
|
|
169
|
+
}[];
|
|
170
|
+
spec?: ArgSpec;
|
|
171
|
+
defaultLabel?: string;
|
|
172
|
+
typedInput: boolean;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/** Register the builtin Undo command, the "invocation" ptype, and the
|
|
176
|
+
* per-invocation Undo command (used by transcript/activity menus). */
|
|
177
|
+
export declare function installUndoCommands<W>(engine: PbuiEngine<W>): void;
|