@staix/vault-mem-ui 0.0.0-stage → 0.0.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/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +96 -2
- package/THIRD_PARTY_NOTICES.md +164 -0
- package/bin/vmem-ui.ts +26 -0
- package/dist/panel.css +666 -0
- package/dist/panel.js +355 -0
- package/package.json +53 -4
- package/src/client/App.tsx +167 -0
- package/src/client/a11y.ts +54 -0
- package/src/client/acon.ts +46 -0
- package/src/client/components.tsx +243 -0
- package/src/client/data.ts +66 -0
- package/src/client/fake.ts +48 -0
- package/src/client/graph-export.tsx +21 -0
- package/src/client/host.ts +80 -0
- package/src/client/markdown/parse.ts +620 -0
- package/src/client/markdown/render.tsx +270 -0
- package/src/client/panel.css +666 -0
- package/src/client/panel.tsx +66 -0
- package/src/client/prefs.ts +76 -0
- package/src/client/standalone.ts +44 -0
- package/src/client/store.ts +201 -0
- package/src/client/views/assertions.tsx +109 -0
- package/src/client/views/common.ts +15 -0
- package/src/client/views/history.tsx +205 -0
- package/src/client/views/lint.tsx +27 -0
- package/src/client/views/log.tsx +64 -0
- package/src/client/views/note.tsx +128 -0
- package/src/client/views/notes.tsx +34 -0
- package/src/client/views/overview.tsx +74 -0
- package/src/client/views/promote.tsx +112 -0
- package/src/client/views/proposals.tsx +55 -0
- package/src/client/views/settings.tsx +57 -0
- package/src/client/write.ts +144 -0
- package/src/graph/decisionChains.ts +122 -0
- package/src/graph/derive.ts +338 -0
- package/src/graph/export.ts +44 -0
- package/src/graph/insights.ts +254 -0
- package/src/graph/labels.ts +67 -0
- package/src/graph/layout/client.ts +139 -0
- package/src/graph/layout/engine.ts +107 -0
- package/src/graph/layout/fa2.d.ts +8 -0
- package/src/graph/layout/protocol.ts +70 -0
- package/src/graph/layout/worker.ts +132 -0
- package/src/graph/model.ts +230 -0
- package/src/graph/positions.ts +41 -0
- package/src/graph/search.ts +54 -0
- package/src/graph/style.ts +301 -0
- package/src/graph/target.ts +38 -0
- package/src/graph/types.ts +64 -0
- package/src/graph/view/GraphView.tsx +279 -0
- package/src/graph/view/SidePanels.tsx +141 -0
- package/src/graph/view/cache.ts +42 -0
- package/src/graph/view/canvas.ts +309 -0
- package/src/graph/view/graph-snapshot.ts +75 -0
- package/src/graph/view/lod.ts +30 -0
- package/src/graph/view/motion.ts +4 -0
- package/src/graph/view/state.ts +240 -0
- package/src/plugin/assets.ts +33 -0
- package/src/plugin/graph.ts +71 -0
- package/src/plugin/index.ts +23 -0
- package/src/server/cli.ts +99 -0
- package/src/server/host.ts +287 -0
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@staix/vault-mem-ui",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"bun": ">=1.4.2"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"vmem-ui": "bin/vmem-ui.ts"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./src/plugin/index.ts",
|
|
14
|
+
"./ui-plugin": "./src/plugin/index.ts",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"src/",
|
|
19
|
+
"bin/",
|
|
20
|
+
"dist/panel.js",
|
|
21
|
+
"dist/panel.css",
|
|
22
|
+
"README.md",
|
|
23
|
+
"CHANGELOG.md",
|
|
24
|
+
"THIRD_PARTY_NOTICES.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"provenance": true
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"test": "bun test",
|
|
34
|
+
"build": "bun build src/client/panel.tsx --outdir dist --target browser --format esm --minify --define 'process.env.NODE_ENV=\"production\"' --metafile=dist/metafile.json && cp src/client/panel.css dist/panel.css && bun run scripts/check-notices.ts",
|
|
35
|
+
"check": "bun run build && bun run typecheck && bun run test",
|
|
36
|
+
"smoke:package": "bun scripts/package-smoke.ts",
|
|
37
|
+
"release:tag": "bun scripts/release-tag.ts"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@staix/vault-mem": "0.13.1",
|
|
41
|
+
"graphology": "0.26.0",
|
|
42
|
+
"graphology-layout-forceatlas2": "0.10.1",
|
|
43
|
+
"react": "^19.2.0",
|
|
44
|
+
"react-dom": "^19.2.0",
|
|
45
|
+
"sigma": "3.0.3"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@happy-dom/global-registrator": "^21.0.4",
|
|
49
|
+
"@staix/agent-console": "github:STAIxBWLB/agent-console#8babe31f421682670a17ee2498f485e6f9ea20a5",
|
|
50
|
+
"@types/bun": "^1.4.2",
|
|
51
|
+
"@types/react": "^19",
|
|
52
|
+
"@types/react-dom": "^19",
|
|
53
|
+
"typescript": "^5.9.3"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The panel: `PanelView` renders one client state and is pure (so a test can render it as static markup);
|
|
3
|
+
* `App` wires it to a store, the keyboard shortcuts and the reduced-motion switch.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
7
|
+
import { globalKey, prefersReducedMotion } from "./a11y.ts";
|
|
8
|
+
import { Notice, WriteDialog } from "./components.tsx";
|
|
9
|
+
import type { ActionInput, Host } from "./host.ts";
|
|
10
|
+
import { PANEL_IDS, type ThemePref } from "./prefs.ts";
|
|
11
|
+
import { createStore, type ClientStore, type ClientState } from "./store.ts";
|
|
12
|
+
import { AssertionsView } from "./views/assertions.tsx";
|
|
13
|
+
import { HistoryView } from "./views/history.tsx";
|
|
14
|
+
import { LintView } from "./views/lint.tsx";
|
|
15
|
+
import { LogView } from "./views/log.tsx";
|
|
16
|
+
import { NoteView } from "./views/note.tsx";
|
|
17
|
+
import { NotesView } from "./views/notes.tsx";
|
|
18
|
+
import { OverviewView } from "./views/overview.tsx";
|
|
19
|
+
import { ProposalsView } from "./views/proposals.tsx";
|
|
20
|
+
import { SettingsView } from "./views/settings.tsx";
|
|
21
|
+
import { PromoteView } from "./views/promote.tsx";
|
|
22
|
+
import { GraphPanel } from "../graph/view/GraphView.tsx";
|
|
23
|
+
|
|
24
|
+
const TITLES: Record<string, string> = {
|
|
25
|
+
overview: "Overview",
|
|
26
|
+
notes: "Search",
|
|
27
|
+
note: "Note",
|
|
28
|
+
promote: "Promote",
|
|
29
|
+
lint: "Lint",
|
|
30
|
+
log: "Log",
|
|
31
|
+
graph: "Graph",
|
|
32
|
+
settings: "Settings",
|
|
33
|
+
proposals: "Proposals",
|
|
34
|
+
assertions: "Assertions",
|
|
35
|
+
history: "History",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const VIEWS = {
|
|
39
|
+
overview: OverviewView,
|
|
40
|
+
notes: NotesView,
|
|
41
|
+
note: NoteView,
|
|
42
|
+
promote: PromoteView,
|
|
43
|
+
lint: LintView,
|
|
44
|
+
log: LogView,
|
|
45
|
+
graph: GraphPanel,
|
|
46
|
+
settings: SettingsView,
|
|
47
|
+
proposals: ProposalsView,
|
|
48
|
+
assertions: AssertionsView,
|
|
49
|
+
history: HistoryView,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type Navigate = (panel: string, params?: Record<string, string>) => void;
|
|
53
|
+
|
|
54
|
+
export interface PanelViewProps {
|
|
55
|
+
state: ClientState;
|
|
56
|
+
onNavigate: Navigate;
|
|
57
|
+
onWrite(input: ActionInput): void;
|
|
58
|
+
onTheme(theme: ThemePref): void;
|
|
59
|
+
onConfirm(): void;
|
|
60
|
+
onCancel(): void;
|
|
61
|
+
reducedMotion: boolean;
|
|
62
|
+
onToggleMotion(): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** One rendered panel. No store, no effects: every action is a prop. */
|
|
66
|
+
export function PanelView(props: PanelViewProps) {
|
|
67
|
+
const state = props.state;
|
|
68
|
+
const View = VIEWS[state.panel as keyof typeof VIEWS] ?? OverviewView;
|
|
69
|
+
return (
|
|
70
|
+
<div className="vmem" data-theme={state.theme.mode} data-motion={props.reducedMotion ? "reduced" : undefined}>
|
|
71
|
+
<header className="vmem-head">
|
|
72
|
+
<nav className="vmem-nav" aria-label="Vault panels">
|
|
73
|
+
{PANEL_IDS.map((id) => (
|
|
74
|
+
<button
|
|
75
|
+
key={id}
|
|
76
|
+
type="button"
|
|
77
|
+
className={`vmem-nav-item${id === state.panel ? " vmem-nav-current" : ""}`}
|
|
78
|
+
aria-current={id === state.panel ? "page" : undefined}
|
|
79
|
+
onClick={() => props.onNavigate(id)}
|
|
80
|
+
>
|
|
81
|
+
{TITLES[id]}
|
|
82
|
+
</button>
|
|
83
|
+
))}
|
|
84
|
+
</nav>
|
|
85
|
+
<div className="vmem-tools">
|
|
86
|
+
<label className="vmem-label" htmlFor="vmem-theme">
|
|
87
|
+
Theme
|
|
88
|
+
</label>
|
|
89
|
+
<select
|
|
90
|
+
id="vmem-theme"
|
|
91
|
+
className="vmem-input"
|
|
92
|
+
value={state.prefs.theme}
|
|
93
|
+
onChange={(event) => props.onTheme(event.currentTarget.value as ThemePref)}
|
|
94
|
+
>
|
|
95
|
+
<option value="system">System</option>
|
|
96
|
+
<option value="light">Light</option>
|
|
97
|
+
<option value="dark">Dark</option>
|
|
98
|
+
</select>
|
|
99
|
+
<button type="button" className="vmem-button" aria-pressed={props.reducedMotion} onClick={props.onToggleMotion}>
|
|
100
|
+
{props.reducedMotion ? "Motion off" : "Reduce motion"}
|
|
101
|
+
</button>
|
|
102
|
+
</div>
|
|
103
|
+
</header>
|
|
104
|
+
<p className="vmem-sub vmem-hint">
|
|
105
|
+
Arrow keys move through a list, Enter opens, <kbd>/</kbd> focuses search, <kbd>Esc</kbd> closes a dialog.
|
|
106
|
+
</p>
|
|
107
|
+
<main className="vmem-main">
|
|
108
|
+
{state.phase === "error" && state.error ? <Notice tone="err">{state.error}</Notice> : null}
|
|
109
|
+
{state.phase === "loading" && !state.reply ? <p className="vmem-sub">Loading {TITLES[state.panel] ?? state.panel}…</p> : null}
|
|
110
|
+
{state.reply ? (
|
|
111
|
+
<View reply={state.reply} params={state.params} navigate={props.onNavigate} beginWrite={props.onWrite} theme={state.theme} />
|
|
112
|
+
) : null}
|
|
113
|
+
</main>
|
|
114
|
+
<WriteDialog state={state.write} onConfirm={props.onConfirm} onCancel={props.onCancel} />
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function App({ store }: { store: ClientStore }) {
|
|
120
|
+
const state = useSyncExternalStore(
|
|
121
|
+
(listener) => store.subscribe(listener),
|
|
122
|
+
() => store.getState(),
|
|
123
|
+
() => store.getState(),
|
|
124
|
+
);
|
|
125
|
+
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
126
|
+
const [reduced, setReduced] = useState(() => prefersReducedMotion());
|
|
127
|
+
const openWrite = state.write.phase !== "idle";
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
const onKey = (event: KeyboardEvent) => {
|
|
131
|
+
const action = globalKey(event.key, store.getState().write.phase !== "idle");
|
|
132
|
+
if (action === "close") store.setWrite({ phase: "idle" });
|
|
133
|
+
if (action === "search") {
|
|
134
|
+
const target = event.composedPath()[0];
|
|
135
|
+
if (event.isComposing || event.ctrlKey || event.metaKey || event.altKey || event.shiftKey ||
|
|
136
|
+
(target instanceof Element && (target.closest('input, textarea, select, [contenteditable]:not([contenteditable="false"])') !== null ||
|
|
137
|
+
(target instanceof HTMLElement && target.isContentEditable)))) return;
|
|
138
|
+
const field = rootRef.current?.querySelector<HTMLInputElement>('input[type="search"]');
|
|
139
|
+
if (field) {
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
field.focus();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
document.addEventListener("keydown", onKey);
|
|
146
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
147
|
+
}, [store, openWrite]);
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div ref={rootRef}>
|
|
151
|
+
<PanelView
|
|
152
|
+
state={state}
|
|
153
|
+
onNavigate={(panel, params) => store.navigate(panel, params)}
|
|
154
|
+
onWrite={(input) => void store.beginWrite(input)}
|
|
155
|
+
onTheme={(theme) => store.setTheme(theme)}
|
|
156
|
+
onConfirm={() => void store.confirmWriteNow()}
|
|
157
|
+
onCancel={() => store.setWrite({ phase: "idle" })}
|
|
158
|
+
reducedMotion={reduced}
|
|
159
|
+
onToggleMotion={() => setReduced((value) => !value)}
|
|
160
|
+
/>
|
|
161
|
+
</div>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function createClient(host: Host, options: { initialPanel?: string } = {}): ClientStore {
|
|
166
|
+
return createStore(host, options);
|
|
167
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Keyboard navigation and reduced-motion helpers, kept pure so the views stay testable without a DOM. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The next focus index in a list for one key, or the current index when the key is not a list key.
|
|
5
|
+
* `-1` means "nothing focused", and the first arrow press enters the list.
|
|
6
|
+
*/
|
|
7
|
+
export function nextFocus(count: number, current: number, key: string): number {
|
|
8
|
+
if (count <= 0) return -1;
|
|
9
|
+
const inside = current >= 0 && current < count;
|
|
10
|
+
switch (key) {
|
|
11
|
+
case "ArrowDown":
|
|
12
|
+
return inside ? Math.min(count - 1, current + 1) : 0;
|
|
13
|
+
case "ArrowUp":
|
|
14
|
+
return inside ? Math.max(0, current - 1) : count - 1;
|
|
15
|
+
case "Home":
|
|
16
|
+
return 0;
|
|
17
|
+
case "End":
|
|
18
|
+
return count - 1;
|
|
19
|
+
default:
|
|
20
|
+
return current;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const LIST_KEYS = new Set(["ArrowDown", "ArrowUp", "Home", "End"]);
|
|
25
|
+
|
|
26
|
+
export function isListKey(key: string): boolean {
|
|
27
|
+
return LIST_KEYS.has(key);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MediaQueryLike {
|
|
31
|
+
matches: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Reduced motion for this view. A host that cannot answer (no `matchMedia`) is treated as "no preference",
|
|
36
|
+
* which keeps animation on rather than guessing.
|
|
37
|
+
*/
|
|
38
|
+
export function prefersReducedMotion(
|
|
39
|
+
query?: (query: string) => MediaQueryLike | null,
|
|
40
|
+
): boolean {
|
|
41
|
+
try {
|
|
42
|
+
const ask = query ?? ((text: string) => (globalThis as { matchMedia?: (q: string) => MediaQueryLike }).matchMedia?.(text) ?? null);
|
|
43
|
+
return ask("(prefers-reduced-motion: reduce)")?.matches === true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Keys the panel handles globally: `/` opens search, `Escape` closes the write dialog. */
|
|
50
|
+
export function globalKey(key: string, hasDialog: boolean): "search" | "close" | null {
|
|
51
|
+
if (key === "Escape" && hasDialog) return "close";
|
|
52
|
+
if (key === "/" && !hasDialog) return "search";
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Adapter from `acon`'s `ConsoleHost` to the client's host interface. */
|
|
2
|
+
|
|
3
|
+
import type { ConsoleHost } from "@staix/agent-console/contract";
|
|
4
|
+
import type { ActionResult, ActionInput, Host, SnapshotReply } from "./host.ts";
|
|
5
|
+
|
|
6
|
+
/** Keys the console sets on a confirmed action; its server refuses a page that sends them. */
|
|
7
|
+
const RESERVED = new Set(["confirmed", "fingerprint"]);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `acon` pushes the active panel's snapshots and routes navigation through its own tabs, so `snapshot()` drops the
|
|
11
|
+
* panel id and forwards the panel's parameters. The panel id itself reaches the client through `show()`.
|
|
12
|
+
*
|
|
13
|
+
* Confirmation belongs to the console: `host.action` answers a `needsConfirm` itself — its server stores the
|
|
14
|
+
* fingerprint under a confirm token, the shell renders the preview in its own dialog, and the confirm is a second
|
|
15
|
+
* call carrying that token. So the adapter says `confirm: "host"` and never passes `confirmed` or `fingerprint`
|
|
16
|
+
* through: the console refuses those from a page.
|
|
17
|
+
*/
|
|
18
|
+
export function createAconHost(panel: ConsoleHost): Host {
|
|
19
|
+
return {
|
|
20
|
+
mount: panel.mount as unknown as HTMLElement,
|
|
21
|
+
confirm: "host",
|
|
22
|
+
async snapshot(input) {
|
|
23
|
+
const { panel: _panel, ...rest } = input;
|
|
24
|
+
return (await panel.snapshot(rest)) as SnapshotReply;
|
|
25
|
+
},
|
|
26
|
+
action(input: ActionInput) {
|
|
27
|
+
const forwarded: Record<string, unknown> = { ...input };
|
|
28
|
+
for (const key of RESERVED) delete forwarded[key];
|
|
29
|
+
return panel.action(forwarded as never) as Promise<ActionResult>;
|
|
30
|
+
},
|
|
31
|
+
theme: () => ({ mode: panel.theme.mode, tokens: panel.theme.tokens }),
|
|
32
|
+
subscribe(listener) {
|
|
33
|
+
panel.onSnapshot((snapshot) => listener(snapshot as SnapshotReply));
|
|
34
|
+
return () => {
|
|
35
|
+
// The shell owns the subscription lifetime; unmounting the panel removes its listeners with it.
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
navigate(next, params) {
|
|
39
|
+
panel.navigate(panel.tool, next, params);
|
|
40
|
+
},
|
|
41
|
+
onTheme(listener) {
|
|
42
|
+
panel.onTheme((theme) => listener({ mode: theme.mode, tokens: theme.tokens }));
|
|
43
|
+
return () => {};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/** Shared pieces of the panel: a keyboard-navigable list, notices, chips, fields and the write dialog. */
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, type ReactNode } from "react";
|
|
4
|
+
import { isListKey, nextFocus } from "./a11y.ts";
|
|
5
|
+
import type { WriteState } from "./write.ts";
|
|
6
|
+
|
|
7
|
+
export function Notice({ tone = "info", children }: { tone?: "info" | "warn" | "err"; children: ReactNode }) {
|
|
8
|
+
return (
|
|
9
|
+
<p className={`vmem-notice vmem-notice-${tone}`} role={tone === "err" ? "alert" : "status"}>
|
|
10
|
+
{children}
|
|
11
|
+
</p>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function Empty({ title, hint }: { title: string; hint?: string }) {
|
|
16
|
+
return (
|
|
17
|
+
<div className="vmem-empty">
|
|
18
|
+
<p className="vmem-empty-title">{title}</p>
|
|
19
|
+
{hint ? <p className="vmem-sub">{hint}</p> : null}
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function Chip({ text, tone = "neutral" }: { text: string; tone?: "neutral" | "warn" | "err" }) {
|
|
25
|
+
return <span className={`vmem-chip vmem-chip-${tone}`}>{text}</span>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ListItem {
|
|
29
|
+
key: string;
|
|
30
|
+
title: ReactNode;
|
|
31
|
+
sub?: ReactNode;
|
|
32
|
+
chip?: { text: string; tone?: "neutral" | "warn" | "err" };
|
|
33
|
+
verbs?: ReactNode;
|
|
34
|
+
onOpen?: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A list where the arrow keys, Home and End move between rows and Enter or Space opens the focused one.
|
|
39
|
+
* Rows are buttons, so the list also works with Tab alone when a keyboard layout has no arrows.
|
|
40
|
+
*/
|
|
41
|
+
export function List({ items, label, empty }: { items: ListItem[]; label: string; empty?: ReactNode }) {
|
|
42
|
+
const refs = useRef<(HTMLButtonElement | null)[]>([]);
|
|
43
|
+
if (!items.length) return <>{empty ?? null}</>;
|
|
44
|
+
const move = (event: React.KeyboardEvent<HTMLUListElement>) => {
|
|
45
|
+
if (!isListKey(event.key)) return;
|
|
46
|
+
const at = refs.current.findIndex((el) => el === document.activeElement);
|
|
47
|
+
const next = nextFocus(items.length, at, event.key);
|
|
48
|
+
if (next < 0) return;
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
refs.current[next]?.focus();
|
|
51
|
+
};
|
|
52
|
+
return (
|
|
53
|
+
<ul className="vmem-list" aria-label={label} onKeyDown={move}>
|
|
54
|
+
{items.map((item, index) => (
|
|
55
|
+
<li className="vmem-list-item" key={item.key}>
|
|
56
|
+
<button
|
|
57
|
+
type="button"
|
|
58
|
+
className={`vmem-row${item.onOpen ? "" : " vmem-row-static"}`}
|
|
59
|
+
ref={(el) => {
|
|
60
|
+
refs.current[index] = el;
|
|
61
|
+
}}
|
|
62
|
+
onClick={item.onOpen}
|
|
63
|
+
aria-disabled={item.onOpen ? undefined : true}
|
|
64
|
+
>
|
|
65
|
+
<span className="vmem-row-title">{item.title}</span>
|
|
66
|
+
{item.sub ? <span className="vmem-row-sub">{item.sub}</span> : null}
|
|
67
|
+
{item.chip ? <Chip text={item.chip.text} tone={item.chip.tone} /> : null}
|
|
68
|
+
</button>
|
|
69
|
+
{item.verbs ? <span className="vmem-row-verbs">{item.verbs}</span> : null}
|
|
70
|
+
</li>
|
|
71
|
+
))}
|
|
72
|
+
</ul>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function Field(props: {
|
|
77
|
+
name: string;
|
|
78
|
+
label: string;
|
|
79
|
+
value?: string;
|
|
80
|
+
placeholder?: string;
|
|
81
|
+
required?: boolean;
|
|
82
|
+
type?: string;
|
|
83
|
+
onChange?(value: string): void;
|
|
84
|
+
}) {
|
|
85
|
+
const id = `vmem-${props.name}`;
|
|
86
|
+
return (
|
|
87
|
+
<p className="vmem-field">
|
|
88
|
+
<label className="vmem-label" htmlFor={id}>
|
|
89
|
+
{props.label}
|
|
90
|
+
{props.required ? <span className="vmem-required"> (required)</span> : null}
|
|
91
|
+
</label>
|
|
92
|
+
<input
|
|
93
|
+
id={id}
|
|
94
|
+
name={props.name}
|
|
95
|
+
className="vmem-input"
|
|
96
|
+
type={props.type ?? "text"}
|
|
97
|
+
value={props.value ?? ""}
|
|
98
|
+
placeholder={props.placeholder}
|
|
99
|
+
required={props.required}
|
|
100
|
+
onChange={(event) => props.onChange?.(event.currentTarget.value)}
|
|
101
|
+
/>
|
|
102
|
+
</p>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function SearchForm({ value, onSubmit }: { value: string; onSubmit(q: string): void }) {
|
|
107
|
+
return (
|
|
108
|
+
<form
|
|
109
|
+
className="vmem-bar"
|
|
110
|
+
role="search"
|
|
111
|
+
onSubmit={(event) => {
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
const field = event.currentTarget.elements.namedItem("q");
|
|
114
|
+
onSubmit(field instanceof HTMLInputElement ? field.value.trim() : "");
|
|
115
|
+
}}
|
|
116
|
+
>
|
|
117
|
+
<input
|
|
118
|
+
className="vmem-input vmem-search"
|
|
119
|
+
type="search"
|
|
120
|
+
name="q"
|
|
121
|
+
defaultValue={value}
|
|
122
|
+
placeholder="Search notes"
|
|
123
|
+
aria-label="Search notes"
|
|
124
|
+
/>
|
|
125
|
+
<button type="submit" className="vmem-button">
|
|
126
|
+
Search
|
|
127
|
+
</button>
|
|
128
|
+
</form>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The person's decision on a write: what will change, any warning, and the two buttons. Nothing is sent until
|
|
134
|
+
* Confirm, and Confirm re-sends the fingerprint the preview produced.
|
|
135
|
+
*/
|
|
136
|
+
export function WriteDialog(props: { state: WriteState; onConfirm(): void; onCancel(): void }) {
|
|
137
|
+
const state = props.state;
|
|
138
|
+
const open = state.phase !== "idle" && !(state.phase === "done" && state.quiet);
|
|
139
|
+
const box = useRef<HTMLElement | null>(null);
|
|
140
|
+
const returnTo = useRef<Element | null>(null);
|
|
141
|
+
|
|
142
|
+
// Focus moves into the dialog when it opens and back to the control that opened it when it closes; Tab is
|
|
143
|
+
// contained, so the panel behind the overlay cannot be reached or activated by keyboard.
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (!open) return;
|
|
146
|
+
returnTo.current = typeof document === "undefined" ? null : document.activeElement;
|
|
147
|
+
const inside = box.current;
|
|
148
|
+
inside?.focus();
|
|
149
|
+
return () => {
|
|
150
|
+
const back = returnTo.current;
|
|
151
|
+
if (back instanceof HTMLElement && back.isConnected) back.focus();
|
|
152
|
+
};
|
|
153
|
+
}, [open]);
|
|
154
|
+
useEffect(() => { if (state.phase === "confirming") box.current?.focus(); }, [state.phase]);
|
|
155
|
+
|
|
156
|
+
if (!open) return null;
|
|
157
|
+
const heading = state.phase === "preview" || state.phase === "confirming" ? state.verb : state.phase === "waiting" ? "Still waiting" : state.phase === "done" ? "Done" : state.phase === "cancelled" ? "Cancelled" : "Refused";
|
|
158
|
+
const trap = (event: React.KeyboardEvent<HTMLElement>) => {
|
|
159
|
+
if (event.key !== "Tab") return;
|
|
160
|
+
const inside = box.current;
|
|
161
|
+
if (!inside) return;
|
|
162
|
+
const focusable = [...inside.querySelectorAll<HTMLElement>('button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])')];
|
|
163
|
+
if (!focusable.length) { event.preventDefault(); inside.focus(); return; }
|
|
164
|
+
const first = focusable[0]!;
|
|
165
|
+
const last = focusable[focusable.length - 1]!;
|
|
166
|
+
const at = document.activeElement;
|
|
167
|
+
// The dialog itself holds the focus after opening, so the first Tab enters the controls.
|
|
168
|
+
if (at === inside || !inside.contains(at)) {
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
(event.shiftKey ? last : first).focus();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (!event.shiftKey && at === last) {
|
|
174
|
+
event.preventDefault();
|
|
175
|
+
first.focus();
|
|
176
|
+
} else if (event.shiftKey && at === first) {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
last.focus();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
return (
|
|
182
|
+
<div className="vmem-dialog-backdrop">
|
|
183
|
+
<section
|
|
184
|
+
className="vmem-dialog"
|
|
185
|
+
role="dialog"
|
|
186
|
+
aria-modal="true"
|
|
187
|
+
aria-label={heading}
|
|
188
|
+
tabIndex={-1}
|
|
189
|
+
ref={box}
|
|
190
|
+
onKeyDown={trap}
|
|
191
|
+
>
|
|
192
|
+
<h2 className="vmem-dialog-title">{heading}</h2>
|
|
193
|
+
{state.phase === "confirming" ? (
|
|
194
|
+
<><p role="status">Applying changes...</p><div className="vmem-bar"><button type="button" className="vmem-button vmem-button-danger" disabled>Confirm</button><button type="button" className="vmem-button" disabled>Cancel</button></div></>
|
|
195
|
+
) : state.phase === "preview" ? (
|
|
196
|
+
<>
|
|
197
|
+
<p className="vmem-sub">Nothing has been written yet. These are the planned changes:</p>
|
|
198
|
+
<ul className="vmem-changes">
|
|
199
|
+
{state.preview.map((line) => (
|
|
200
|
+
<li key={line}>{line}</li>
|
|
201
|
+
))}
|
|
202
|
+
{state.changes.map((change) => (
|
|
203
|
+
<li key={`${change.op}:${change.target}`}>
|
|
204
|
+
{change.op} {change.target}
|
|
205
|
+
{change.note ? <span className="vmem-sub"> · {change.note}</span> : null}
|
|
206
|
+
</li>
|
|
207
|
+
))}
|
|
208
|
+
</ul>
|
|
209
|
+
{state.warnings.length ? (
|
|
210
|
+
<ul className="vmem-warnings">
|
|
211
|
+
{state.warnings.map((warning) => (
|
|
212
|
+
<li key={warning}>{warning}</li>
|
|
213
|
+
))}
|
|
214
|
+
</ul>
|
|
215
|
+
) : null}
|
|
216
|
+
<div className="vmem-bar">
|
|
217
|
+
<button type="button" className="vmem-button vmem-button-danger" onClick={props.onConfirm}>
|
|
218
|
+
Confirm
|
|
219
|
+
</button>
|
|
220
|
+
<button type="button" className="vmem-button" onClick={props.onCancel}>
|
|
221
|
+
Cancel
|
|
222
|
+
</button>
|
|
223
|
+
</div>
|
|
224
|
+
</>
|
|
225
|
+
) : (
|
|
226
|
+
<>
|
|
227
|
+
<p
|
|
228
|
+
className={state.phase === "error" ? "vmem-notice vmem-notice-err" : "vmem-notice"}
|
|
229
|
+
role={state.phase === "error" ? "alert" : "status"}
|
|
230
|
+
>
|
|
231
|
+
{state.message}
|
|
232
|
+
</p>
|
|
233
|
+
<div className="vmem-bar">
|
|
234
|
+
<button type="button" className="vmem-button" onClick={props.onCancel}>
|
|
235
|
+
Close
|
|
236
|
+
</button>
|
|
237
|
+
</div>
|
|
238
|
+
</>
|
|
239
|
+
)}
|
|
240
|
+
</section>
|
|
241
|
+
</div>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Narrow readers for provider snapshots: the client never trusts a shape it has not checked. */
|
|
2
|
+
|
|
3
|
+
export type Json = Record<string, unknown>;
|
|
4
|
+
|
|
5
|
+
export const rec = (value: unknown): Json => (value && typeof value === "object" && !Array.isArray(value) ? (value as Json) : {});
|
|
6
|
+
|
|
7
|
+
export const str = (value: unknown): string => (typeof value === "string" ? value : typeof value === "number" ? String(value) : "");
|
|
8
|
+
|
|
9
|
+
export const num = (value: unknown): number => (typeof value === "number" && Number.isFinite(value) ? value : 0);
|
|
10
|
+
|
|
11
|
+
export const list = <T>(value: unknown): T[] => (Array.isArray(value) ? (value as T[]) : []);
|
|
12
|
+
|
|
13
|
+
export interface NoteRow {
|
|
14
|
+
path: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
type?: string;
|
|
17
|
+
domain?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface VaultRow {
|
|
22
|
+
id: string;
|
|
23
|
+
kind?: string;
|
|
24
|
+
write?: string;
|
|
25
|
+
health?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface LogRow {
|
|
29
|
+
raw?: string;
|
|
30
|
+
at?: string;
|
|
31
|
+
type?: string;
|
|
32
|
+
project?: string;
|
|
33
|
+
source?: string;
|
|
34
|
+
dest?: string;
|
|
35
|
+
note?: string;
|
|
36
|
+
agent?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface CandidateRow {
|
|
40
|
+
id: string;
|
|
41
|
+
kind?: string;
|
|
42
|
+
title?: string;
|
|
43
|
+
project?: string;
|
|
44
|
+
at?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface FindingRow {
|
|
48
|
+
code: string;
|
|
49
|
+
severity: string;
|
|
50
|
+
path?: string;
|
|
51
|
+
message: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface LinkRow {
|
|
55
|
+
resolved?: string;
|
|
56
|
+
source?: string;
|
|
57
|
+
target?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** ISO time for a log timestamp that arrived as text, or the text itself when it is not a date. */
|
|
61
|
+
export function when(value: unknown): string {
|
|
62
|
+
const text = str(value);
|
|
63
|
+
if (!text) return "";
|
|
64
|
+
const at = new Date(text);
|
|
65
|
+
return Number.isNaN(at.getTime()) ? text : at.toISOString().slice(0, 16).replace("T", " ");
|
|
66
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** In-memory host: the standalone shell's stand-in until M1-b merges, and the views' test host. */
|
|
2
|
+
|
|
3
|
+
import type { ActionResult, ActionInput, Host, SnapshotInput, SnapshotReply, Theme } from "./host.ts";
|
|
4
|
+
|
|
5
|
+
export type SnapshotSource = SnapshotReply | ((input: SnapshotInput) => SnapshotReply | Promise<SnapshotReply>);
|
|
6
|
+
|
|
7
|
+
export interface FakeSeed {
|
|
8
|
+
snapshots?: Record<string, SnapshotSource>;
|
|
9
|
+
replies?: Record<string, ActionResult>;
|
|
10
|
+
theme?: Theme;
|
|
11
|
+
mount?: HTMLElement;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FakeHost extends Host {
|
|
15
|
+
calls: { snapshot: SnapshotInput[]; action: ActionInput[]; navigate: string[] };
|
|
16
|
+
push(reply: SnapshotReply): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Answers by panel id (falling back to `default`), records every call, and lets a test push a poll reply. */
|
|
20
|
+
export function createFakeHost(seed: FakeSeed = {}): FakeHost {
|
|
21
|
+
const calls: FakeHost["calls"] = { snapshot: [], action: [], navigate: [] };
|
|
22
|
+
const listeners = new Set<(reply: SnapshotReply) => void>();
|
|
23
|
+
const theme: Theme = seed.theme ?? { mode: "light" };
|
|
24
|
+
return {
|
|
25
|
+
mount: seed.mount ?? ({ append() {} } as unknown as HTMLElement),
|
|
26
|
+
calls,
|
|
27
|
+
async snapshot(input) {
|
|
28
|
+
calls.snapshot.push(input);
|
|
29
|
+
const source = seed.snapshots?.[input.panel] ?? seed.snapshots?.default ?? {};
|
|
30
|
+
return typeof source === "function" ? await source(input) : source;
|
|
31
|
+
},
|
|
32
|
+
async action(input) {
|
|
33
|
+
calls.action.push(input);
|
|
34
|
+
return seed.replies?.[input.action] ?? { ok: true, message: `${input.action}: done` };
|
|
35
|
+
},
|
|
36
|
+
theme: () => theme,
|
|
37
|
+
subscribe(listener) {
|
|
38
|
+
listeners.add(listener);
|
|
39
|
+
return () => listeners.delete(listener);
|
|
40
|
+
},
|
|
41
|
+
navigate(next) {
|
|
42
|
+
calls.navigate.push(next);
|
|
43
|
+
},
|
|
44
|
+
push(reply) {
|
|
45
|
+
for (const listener of listeners) listener(reply);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|