@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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Per-viewer preferences kept in browser storage, and everything that happens when storage is unavailable. */
|
|
2
|
+
|
|
3
|
+
export type ThemePref = "system" | "light" | "dark";
|
|
4
|
+
|
|
5
|
+
export interface Prefs {
|
|
6
|
+
theme: ThemePref;
|
|
7
|
+
lastPanel: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const PANEL_IDS = ["overview", "notes", "note", "promote", "lint", "log", "graph", "settings", "proposals", "assertions", "history"] as const;
|
|
11
|
+
export type PanelId = (typeof PANEL_IDS)[number];
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_PREFS: Prefs = { theme: "system", lastPanel: "overview" };
|
|
14
|
+
|
|
15
|
+
const KEY = "vmem-ui:prefs";
|
|
16
|
+
const THEMES: readonly ThemePref[] = ["system", "light", "dark"];
|
|
17
|
+
|
|
18
|
+
/** The part of `Storage` the client uses; a stub is enough in tests. */
|
|
19
|
+
export interface StorageLike {
|
|
20
|
+
getItem(key: string): string | null;
|
|
21
|
+
setItem(key: string, value: string): void;
|
|
22
|
+
removeItem?(key: string): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The panel id when it is one of ours, so a stored or hand-edited value cannot select a panel that does not exist. */
|
|
26
|
+
export function isPanelId(value: unknown): value is PanelId {
|
|
27
|
+
return typeof value === "string" && (PANEL_IDS as readonly string[]).includes(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function checked(raw: unknown): Prefs {
|
|
31
|
+
const value = raw && typeof raw === "object" ? (raw as Record<string, unknown>) : {};
|
|
32
|
+
const theme = THEMES.includes(value.theme as ThemePref) ? (value.theme as ThemePref) : DEFAULT_PREFS.theme;
|
|
33
|
+
const lastPanel = isPanelId(value.lastPanel) ? value.lastPanel : DEFAULT_PREFS.lastPanel;
|
|
34
|
+
return { theme, lastPanel };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Stored preferences, or the defaults. Unreadable or malformed storage is the default, never an error. */
|
|
38
|
+
export function readPrefs(storage?: StorageLike): Prefs {
|
|
39
|
+
if (!storage) return DEFAULT_PREFS;
|
|
40
|
+
try {
|
|
41
|
+
const text = storage.getItem(KEY);
|
|
42
|
+
return text ? checked(JSON.parse(text)) : DEFAULT_PREFS;
|
|
43
|
+
} catch {
|
|
44
|
+
return DEFAULT_PREFS;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Store preferences; a storage that refuses the write leaves the session working with what it already has. */
|
|
49
|
+
export function writePrefs(prefs: Prefs, storage?: StorageLike): Prefs {
|
|
50
|
+
const value = checked(prefs);
|
|
51
|
+
if (!storage) return value;
|
|
52
|
+
try {
|
|
53
|
+
storage.setItem(KEY, JSON.stringify(value));
|
|
54
|
+
} catch {
|
|
55
|
+
// Quota, private mode or a disabled store: the preference applies to this view only.
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* `localStorage` when the browser lets this page use it. Reading the property itself throws in some
|
|
62
|
+
* configurations (third-party cookie blocking, sandboxed frames), so the access is guarded.
|
|
63
|
+
*/
|
|
64
|
+
export function browserStorage(source?: StorageLike | null): StorageLike | undefined {
|
|
65
|
+
if (source) return source;
|
|
66
|
+
try {
|
|
67
|
+
const storage = (globalThis as { localStorage?: StorageLike }).localStorage;
|
|
68
|
+
if (!storage) return undefined;
|
|
69
|
+
const probe = `${KEY}:probe`;
|
|
70
|
+
storage.setItem(probe, "1");
|
|
71
|
+
storage.removeItem?.(probe);
|
|
72
|
+
return storage;
|
|
73
|
+
} catch {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Same-origin transport for the standalone loopback server. */
|
|
2
|
+
import type { ActionInput, ActionResult, Host, SnapshotInput, SnapshotReply, Theme } from "./host.ts";
|
|
3
|
+
|
|
4
|
+
export function createStandaloneHost(mount: HTMLElement, request: (url: string, init: RequestInit) => Promise<Response> = fetch): Host {
|
|
5
|
+
const media = typeof matchMedia === "function" ? matchMedia("(prefers-color-scheme: dark)") : null;
|
|
6
|
+
const theme = (): Theme => ({ mode: media?.matches ? "dark" : "light" });
|
|
7
|
+
|
|
8
|
+
async function post(endpoint: "/api/snapshot" | "/api/action", input: SnapshotInput | ActionInput): Promise<Record<string, unknown>> {
|
|
9
|
+
let response: Response;
|
|
10
|
+
try {
|
|
11
|
+
response = await request(endpoint, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
credentials: "same-origin",
|
|
14
|
+
mode: "same-origin",
|
|
15
|
+
headers: { "content-type": "application/json" },
|
|
16
|
+
body: JSON.stringify(input),
|
|
17
|
+
});
|
|
18
|
+
} catch {
|
|
19
|
+
throw new Error("The vmem-ui server may have stopped; restart vmem-ui and open its new sign-in link");
|
|
20
|
+
}
|
|
21
|
+
const data: unknown = await response.json().catch(() => null);
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
const message = data && typeof data === "object" && "error" in data && typeof data.error === "string"
|
|
24
|
+
? data.error : `Request failed (${response.status}); reopen the standalone page and retry`;
|
|
25
|
+
throw new Error(message);
|
|
26
|
+
}
|
|
27
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) throw new Error("The server returned invalid data; reopen the page and retry");
|
|
28
|
+
return data as Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
mount,
|
|
33
|
+
confirm: "client",
|
|
34
|
+
snapshot: (input) => post("/api/snapshot", input) as Promise<SnapshotReply>,
|
|
35
|
+
action: (input) => post("/api/action", input) as Promise<ActionResult>,
|
|
36
|
+
theme,
|
|
37
|
+
onTheme(listener) {
|
|
38
|
+
if (!media) return () => {};
|
|
39
|
+
const changed = () => listener(theme());
|
|
40
|
+
media.addEventListener("change", changed);
|
|
41
|
+
return () => media.removeEventListener("change", changed);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/** One store for the panel: the active panel, its snapshot, the theme and the write flow. */
|
|
2
|
+
|
|
3
|
+
import type { ActionInput, Host, SnapshotReply, Theme } from "./host.ts";
|
|
4
|
+
import { browserStorage, readPrefs, writePrefs, type Prefs, type StorageLike, type ThemePref } from "./prefs.ts";
|
|
5
|
+
import { confirmWrite, startWrite, type WriteState } from "./write.ts";
|
|
6
|
+
import { assembleGraphPages } from "../graph/view/graph-snapshot.ts";
|
|
7
|
+
|
|
8
|
+
export interface ClientState {
|
|
9
|
+
panel: string;
|
|
10
|
+
params: Record<string, string>;
|
|
11
|
+
reply: SnapshotReply | null;
|
|
12
|
+
phase: "loading" | "ready" | "error";
|
|
13
|
+
error?: string;
|
|
14
|
+
prefs: Prefs;
|
|
15
|
+
theme: Theme;
|
|
16
|
+
write: WriteState;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface StoreOptions {
|
|
20
|
+
storage?: StorageLike;
|
|
21
|
+
/** Poll interval when the host does not push snapshots. */
|
|
22
|
+
intervalMs?: number;
|
|
23
|
+
initialPanel?: string;
|
|
24
|
+
/** Time before a pending confirmation can be dismissed. */
|
|
25
|
+
confirmWaitMs?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ClientStore {
|
|
29
|
+
getState(): ClientState;
|
|
30
|
+
subscribe(listener: (state: ClientState) => void): () => void;
|
|
31
|
+
show(panel: string, params?: Record<string, string>): void;
|
|
32
|
+
navigate(panel: string, params?: Record<string, string>): void;
|
|
33
|
+
refresh(): Promise<void>;
|
|
34
|
+
setTheme(theme: ThemePref): void;
|
|
35
|
+
setWrite(state: WriteState): void;
|
|
36
|
+
beginWrite(input: ActionInput): Promise<void>;
|
|
37
|
+
confirmWriteNow(): Promise<void>;
|
|
38
|
+
start(): () => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `system` follows the host's mode; `light` and `dark` are the person's own choice for this panel. */
|
|
42
|
+
export function resolveTheme(pref: ThemePref, hostTheme: Theme): Theme {
|
|
43
|
+
return pref === "system" ? hostTheme : { mode: pref, tokens: hostTheme.tokens };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createStore(host: Host, options: StoreOptions = {}): ClientStore {
|
|
47
|
+
const storage = browserStorage(options.storage);
|
|
48
|
+
const prefs = readPrefs(storage);
|
|
49
|
+
const listeners = new Set<(state: ClientState) => void>();
|
|
50
|
+
let state: ClientState = {
|
|
51
|
+
panel: options.initialPanel ?? prefs.lastPanel,
|
|
52
|
+
params: {},
|
|
53
|
+
reply: null,
|
|
54
|
+
phase: "loading",
|
|
55
|
+
prefs,
|
|
56
|
+
theme: resolveTheme(prefs.theme, host.theme()),
|
|
57
|
+
write: { phase: "idle" },
|
|
58
|
+
};
|
|
59
|
+
const set = (next: Partial<ClientState>) => {
|
|
60
|
+
state = { ...state, ...next };
|
|
61
|
+
for (const listener of listeners) listener(state);
|
|
62
|
+
};
|
|
63
|
+
let asked = 0;
|
|
64
|
+
// The write flow that owns the dialog right now. A pending preview or confirmation may only land while its ticket
|
|
65
|
+
// is still current, so a reply cannot reopen a write on a panel or view the person already left, or after Cancel.
|
|
66
|
+
let ticket = 0;
|
|
67
|
+
let hostWritePending = false;
|
|
68
|
+
// A write changes what the graph pages say, so the cursor the panel holds may predate it. Until the provider sends
|
|
69
|
+
// the graph itself (not a cursor-only `changed: false` stub), it is asked for its first page instead of
|
|
70
|
+
// `after: cursor`, which would answer `changed: false` and keep the graph the person just changed.
|
|
71
|
+
let freshGraph = false;
|
|
72
|
+
const acceptSnapshot = async (reply: SnapshotReply, seq: number, panel: string, params: Record<string, string>) => {
|
|
73
|
+
if (seq !== asked) return;
|
|
74
|
+
const stats = state.reply?.graphStats as { cursor?: unknown; vault?: unknown; revision?: unknown } | undefined;
|
|
75
|
+
if (panel === "graph" && state.reply?.graph && stats && reply.schema === 1 && reply.kind === "nodes" && reply.offset === 0 && typeof reply.cursor === "number" && Number.isSafeInteger(reply.cursor) && reply.cursor >= 0 && reply.vault === stats.vault && reply.revision === stats.revision) {
|
|
76
|
+
// The same revision as the graph the panel holds, so no first-page read is owed any more.
|
|
77
|
+
freshGraph = false;
|
|
78
|
+
if (reply.cursor !== stats.cursor) set({ reply: { ...state.reply, graphStats: { ...stats, cursor: reply.cursor } }, phase: "ready", error: undefined });
|
|
79
|
+
else if (state.phase !== "ready" || state.error) set({ phase: "ready", error: undefined });
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const assembled = panel === "graph" ? await assembleGraphPages((input) => host.snapshot(input), reply, params, () => seq === asked) : reply;
|
|
83
|
+
if (seq !== asked) return;
|
|
84
|
+
if (assembled.changed === false && state.reply) {
|
|
85
|
+
// A stub carries no graph, so the first-page demand stands for the next refresh.
|
|
86
|
+
if (state.phase !== "ready" || state.error) set({ phase: "ready", error: undefined });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (panel === "graph") freshGraph = false;
|
|
90
|
+
set({ reply: assembled, phase: "ready", error: undefined });
|
|
91
|
+
};
|
|
92
|
+
const own = (write: WriteState) => {
|
|
93
|
+
ticket += 1;
|
|
94
|
+
set({ write });
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const store: ClientStore = {
|
|
98
|
+
getState: () => state,
|
|
99
|
+
subscribe(listener) {
|
|
100
|
+
listeners.add(listener);
|
|
101
|
+
return () => listeners.delete(listener);
|
|
102
|
+
},
|
|
103
|
+
show(panel, params = {}) {
|
|
104
|
+
// A panel the browser stored, or an unknown id from a link, falls back to the first panel.
|
|
105
|
+
const next = panel.trim() || "overview";
|
|
106
|
+
if (next !== state.prefs.lastPanel) set({ prefs: writePrefs({ ...state.prefs, lastPanel: next }, storage) });
|
|
107
|
+
// The reply belongs to the panel and parameters it was asked for: keeping it would show the previous note's
|
|
108
|
+
// content, and let its delete or move run under the newly chosen vault. An open preview goes with it, since
|
|
109
|
+
// its input carries the old path.
|
|
110
|
+
ticket += 1;
|
|
111
|
+
set({ panel: next, params, phase: "loading", error: undefined, reply: null, write: { phase: "idle" } });
|
|
112
|
+
void store.refresh();
|
|
113
|
+
},
|
|
114
|
+
navigate(panel, params = {}) {
|
|
115
|
+
if (host.navigate) host.navigate(panel, params);
|
|
116
|
+
else store.show(panel, params);
|
|
117
|
+
},
|
|
118
|
+
async refresh() {
|
|
119
|
+
// Every request gets a number, and only the newest one may land: a slow reply must not overwrite the panel
|
|
120
|
+
// the person already moved to, nor the same panel asked with different parameters.
|
|
121
|
+
const seq = ++asked;
|
|
122
|
+
const stats = state.reply?.graphStats as { cursor?: unknown } | undefined;
|
|
123
|
+
const input = { panel: state.panel, ...state.params, ...(state.panel === "graph" && state.reply?.graph && !freshGraph && typeof stats?.cursor === "number" ? { after: stats.cursor } : {}) };
|
|
124
|
+
try {
|
|
125
|
+
const reply = await host.snapshot(input);
|
|
126
|
+
await acceptSnapshot(reply, seq, input.panel, state.params);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (seq !== asked) return;
|
|
129
|
+
const cause = error instanceof Error ? error.message : String(error ?? "");
|
|
130
|
+
set({ phase: "error", error: cause ? `Could not load this panel: ${cause}. Retry, or check the host connection.` : "Could not load this panel. Retry, or check the host connection." });
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
setTheme(theme) {
|
|
134
|
+
set({ prefs: writePrefs({ ...state.prefs, theme }, storage), theme: resolveTheme(theme, host.theme()) });
|
|
135
|
+
},
|
|
136
|
+
setWrite(write) {
|
|
137
|
+
if (state.write.phase === "confirming") return;
|
|
138
|
+
// Closing or replacing the dialog also supersedes whatever is still being asked for.
|
|
139
|
+
own(write);
|
|
140
|
+
},
|
|
141
|
+
async beginWrite(input) {
|
|
142
|
+
if (state.write.phase === "confirming" || state.write.phase === "waiting" || hostWritePending) return;
|
|
143
|
+
const mine = ++ticket;
|
|
144
|
+
if (host.confirm === "host") hostWritePending = true;
|
|
145
|
+
const result = await startWrite(host, input).finally(() => { hostWritePending = false; });
|
|
146
|
+
// The person moved to another panel, another note or another write while this preview was in flight.
|
|
147
|
+
if (mine !== ticket) return;
|
|
148
|
+
// A host that owns the confirmation already told the person through its own notification (`quiet`), so the
|
|
149
|
+
// panel keeps no dialog state for it; anything else is shown here.
|
|
150
|
+
set({ write: result.phase === "done" && result.quiet ? { phase: "idle" } : result });
|
|
151
|
+
if (result.phase === "done") {
|
|
152
|
+
if (state.panel === "graph") freshGraph = true;
|
|
153
|
+
void store.refresh();
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
async confirmWriteNow() {
|
|
157
|
+
const current = state.write;
|
|
158
|
+
if (current.phase !== "preview") return;
|
|
159
|
+
const mine = ++ticket;
|
|
160
|
+
set({ write: { phase: "confirming", verb: current.verb } });
|
|
161
|
+
const timer = setTimeout(() => {
|
|
162
|
+
if (mine === ticket) set({ write: { phase: "waiting", message: "Still waiting for the vault. It may already be applied; reload the panel to see the current state." } });
|
|
163
|
+
}, options.confirmWaitMs ?? 30_000);
|
|
164
|
+
const result = await confirmWrite(host, current);
|
|
165
|
+
clearTimeout(timer);
|
|
166
|
+
if (mine !== ticket) return;
|
|
167
|
+
set({ write: result });
|
|
168
|
+
if (result.phase === "done") {
|
|
169
|
+
if (state.panel === "graph") freshGraph = true;
|
|
170
|
+
void store.refresh();
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
start() {
|
|
174
|
+
const stops: (() => void)[] = [];
|
|
175
|
+
if (host.subscribe) stops.push(host.subscribe((reply) => {
|
|
176
|
+
const seq = ++asked, panel = state.panel, params = state.params;
|
|
177
|
+
void acceptSnapshot(reply, seq, panel, params).catch((error) => {
|
|
178
|
+
if (seq === asked) set({ phase: "error", error: error instanceof Error ? error.message : String(error) });
|
|
179
|
+
});
|
|
180
|
+
}));
|
|
181
|
+
else {
|
|
182
|
+
// A background tab must not keep a standalone server alive indefinitely.
|
|
183
|
+
const page = typeof document !== "undefined" && typeof document.addEventListener === "function" && typeof document.removeEventListener === "function" ? document : undefined;
|
|
184
|
+
let hidden = page?.hidden ?? false;
|
|
185
|
+
const timer = setInterval(() => { if (!page?.hidden) void store.refresh(); }, options.intervalMs ?? 5000);
|
|
186
|
+
const visibility = () => {
|
|
187
|
+
const wasHidden = hidden;
|
|
188
|
+
hidden = page?.hidden ?? false;
|
|
189
|
+
if (wasHidden && !hidden) void store.refresh();
|
|
190
|
+
};
|
|
191
|
+
page?.addEventListener("visibilitychange", visibility);
|
|
192
|
+
stops.push(() => { clearInterval(timer); page?.removeEventListener("visibilitychange", visibility); });
|
|
193
|
+
}
|
|
194
|
+
if (host.onTheme) stops.push(host.onTheme((theme) => set({ theme: resolveTheme(state.prefs.theme, theme) })));
|
|
195
|
+
return () => {
|
|
196
|
+
for (const stop of stops) stop();
|
|
197
|
+
};
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
return store;
|
|
201
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/** Assertions: the journal's answer for this vault, with every coverage gap named. Read-only. */
|
|
2
|
+
|
|
3
|
+
import { Empty, List, Notice, type ListItem } from "../components.tsx";
|
|
4
|
+
import { list, rec, str, when } from "../data.ts";
|
|
5
|
+
import type { ViewProps } from "./common.ts";
|
|
6
|
+
import { vaultParam } from "./common.ts";
|
|
7
|
+
|
|
8
|
+
type NoticeTone = "info" | "warn" | "err";
|
|
9
|
+
|
|
10
|
+
/** The provider's coverage tones: "neutral" is information, not a gap. */
|
|
11
|
+
const NOTICE_TONE: Record<string, NoticeTone> = { err: "err", warn: "warn", neutral: "info" };
|
|
12
|
+
|
|
13
|
+
/** The one reason a row is not plain reading, in the order the provider reports them. */
|
|
14
|
+
function chipOf(item: Record<string, unknown>, value: unknown): ListItem["chip"] {
|
|
15
|
+
const withheld = value && typeof value === "object" ? str(rec(value).withheld) : "";
|
|
16
|
+
if (withheld) return { text: `withheld (${withheld})`, tone: "warn" };
|
|
17
|
+
if (item.availability === "unavailable" || item.purged === true) return { text: "payload unavailable", tone: "warn" };
|
|
18
|
+
if (item.revisionConflict === true) return { text: "revision conflict", tone: "err" };
|
|
19
|
+
if (str(item.replacedAt)) return { text: "replaced", tone: "neutral" };
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A state holds from..to and an event happened on / held on: without it an ended state reads like a current one. */
|
|
24
|
+
function validityOf(item: Record<string, unknown>): string[] {
|
|
25
|
+
return [
|
|
26
|
+
str(item.from) ? `from ${str(item.from)}` : "",
|
|
27
|
+
str(item.to) ? `to ${str(item.to)}` : "",
|
|
28
|
+
str(item.on) ? `on ${str(item.on)}` : "",
|
|
29
|
+
str(item.held_on) ? `held ${str(item.held_on)}` : "",
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function row(item: Record<string, unknown>, params: Record<string, string>, navigate: ViewProps["navigate"]): ListItem {
|
|
34
|
+
const value = item.value;
|
|
35
|
+
const subjectNote = rec(item.subjectNote);
|
|
36
|
+
const notePath = str(subjectNote.path);
|
|
37
|
+
const chip = chipOf(item, value);
|
|
38
|
+
const status = str(subjectNote.status);
|
|
39
|
+
const sub = [
|
|
40
|
+
str(item.op),
|
|
41
|
+
item.rev === undefined ? "" : `rev ${str(item.rev)}`,
|
|
42
|
+
str(item.kind),
|
|
43
|
+
...validityOf(item),
|
|
44
|
+
when(item.recordedAt),
|
|
45
|
+
str(item.reason),
|
|
46
|
+
status && status !== "present" ? `note ${status}` : "",
|
|
47
|
+
].filter(Boolean).join(" · ");
|
|
48
|
+
return {
|
|
49
|
+
key: `${str(item.id)}:${str(item.rev)}:${str(item.op)}`,
|
|
50
|
+
// A purged assertion can have neither subject nor value left, and the id is then the only thing to name it by.
|
|
51
|
+
title: [str(item.subject), str(item.relation), typeof value === "string" ? value : ""].filter(Boolean).join(" ") || str(item.id) || "assertion",
|
|
52
|
+
sub,
|
|
53
|
+
...(chip ? { chip } : {}),
|
|
54
|
+
...(notePath && status === "present" ? { onOpen: () => navigate("note", { path: notePath, ...vaultParam(params) }) } : {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** When the answer was evaluated, and against which instant when the person asked for one. */
|
|
59
|
+
function asOfText(result: Record<string, unknown>, asOf: Record<string, unknown>): string {
|
|
60
|
+
const cutoff = str(asOf.cutoff);
|
|
61
|
+
if (cutoff) return ` · as of ${when(cutoff)}${asOf.cutoffInclusive === false ? " (exclusive)" : ""}`;
|
|
62
|
+
const at = str(result.at);
|
|
63
|
+
return at ? ` · evaluated ${when(at)}` : "";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function AssertionsView({ reply, params, navigate }: ViewProps) {
|
|
67
|
+
const error = str(reply.error);
|
|
68
|
+
if (error) return <Notice tone="err">{error}</Notice>;
|
|
69
|
+
const result = rec(reply.result);
|
|
70
|
+
const warnings = list<Record<string, unknown>>(reply.warnings);
|
|
71
|
+
const items = list<Record<string, unknown>>(result.items);
|
|
72
|
+
const evaluated = asOfText(result, rec(result.asOf));
|
|
73
|
+
const continuation = str(result.continuation);
|
|
74
|
+
const nav = (extra: Record<string, string>) => navigate("assertions", { ...vaultParam(params), ...extra });
|
|
75
|
+
return (
|
|
76
|
+
<>
|
|
77
|
+
<h1>Assertions</h1>
|
|
78
|
+
{warnings.map((warning, index) => (
|
|
79
|
+
<Notice key={`${str(warning.tone)}:${index}`} tone={NOTICE_TONE[str(warning.tone)] ?? "info"}>
|
|
80
|
+
{str(warning.message)}
|
|
81
|
+
</Notice>
|
|
82
|
+
))}
|
|
83
|
+
<p className="vmem-sub">
|
|
84
|
+
{items.length ? `${items.length} ${items.length === 1 ? "assertion" : "assertions"}` : "No assertions"}
|
|
85
|
+
{evaluated}
|
|
86
|
+
</p>
|
|
87
|
+
<List
|
|
88
|
+
label="Assertions"
|
|
89
|
+
items={items.map((item) => row(item, params, navigate))}
|
|
90
|
+
empty={<Empty title="No assertions" hint="Record one with vmem assert, then reload this panel." />}
|
|
91
|
+
/>
|
|
92
|
+
<div className="vmem-bar">
|
|
93
|
+
{params.cursor ? (
|
|
94
|
+
<button type="button" className="vmem-button" onClick={() => nav({})}>
|
|
95
|
+
First page
|
|
96
|
+
</button>
|
|
97
|
+
) : null}
|
|
98
|
+
{continuation ? (
|
|
99
|
+
<button type="button" className="vmem-button" onClick={() => nav({ cursor: continuation })}>
|
|
100
|
+
Next page
|
|
101
|
+
</button>
|
|
102
|
+
) : null}
|
|
103
|
+
</div>
|
|
104
|
+
{result.truncated === true ? (
|
|
105
|
+
<p className="vmem-sub">The provider stopped at its page limit; continue to the next page or narrow the query with the CLI.</p>
|
|
106
|
+
) : null}
|
|
107
|
+
</>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** What every panel view receives: its snapshot, the panel parameters, navigation and the write entry point. */
|
|
2
|
+
|
|
3
|
+
import type { ActionInput, SnapshotReply, Theme } from "../host.ts";
|
|
4
|
+
|
|
5
|
+
export interface ViewProps {
|
|
6
|
+
reply: SnapshotReply;
|
|
7
|
+
params: Record<string, string>;
|
|
8
|
+
navigate(panel: string, params?: Record<string, string>): void;
|
|
9
|
+
beginWrite(input: ActionInput): void;
|
|
10
|
+
/** The resolved theme; views that paint outside CSS (the graph canvas) redraw when it changes. */
|
|
11
|
+
theme?: Theme;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const vaultParam = (params: Record<string, string>): Record<string, string> =>
|
|
15
|
+
params.vault ? { vault: params.vault } : {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/** History: a note's revisions, and the changes between two of them picked from that list. Read-only. */
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Empty, List, Notice } from "../components.tsx";
|
|
5
|
+
import { list, num, rec, str, when } from "../data.ts";
|
|
6
|
+
import type { ViewProps } from "./common.ts";
|
|
7
|
+
import { vaultParam } from "./common.ts";
|
|
8
|
+
|
|
9
|
+
/** Git's change letters as the words a person reads; anything else is shown as given. */
|
|
10
|
+
const CHANGE_TEXT: Record<string, string> = { A: "added", M: "modified", D: "deleted", T: "type changed" };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The picked pair travels in these params. Every navigation remounts this view, so a half-picked pair would be lost
|
|
14
|
+
* between two pages; vmem_history declares only vault, path, limit and cursor, and the provider's forward() copies
|
|
15
|
+
* just declared properties, so the provider never sees these two.
|
|
16
|
+
*/
|
|
17
|
+
const PICK_FROM = "pickFrom";
|
|
18
|
+
const PICK_TO = "pickTo";
|
|
19
|
+
|
|
20
|
+
const short = (value: string): string => (value.length > 12 ? value.slice(0, 12) : value);
|
|
21
|
+
|
|
22
|
+
export function HistoryView({ reply, params, navigate }: ViewProps) {
|
|
23
|
+
const vault = str(reply.vault) || str(params.vault);
|
|
24
|
+
const path = str(reply.path) || str(params.path);
|
|
25
|
+
const history = rec(reply.history);
|
|
26
|
+
const changes = rec(reply.changes);
|
|
27
|
+
const revisions = list<Record<string, unknown>>(history.revisions);
|
|
28
|
+
const changed = list<Record<string, unknown>>(changes.changed);
|
|
29
|
+
const error = str(reply.error);
|
|
30
|
+
const coverage = rec(history.coverage);
|
|
31
|
+
const reason = str(coverage.reason);
|
|
32
|
+
const incomplete = coverage.complete === false;
|
|
33
|
+
// `from`/`to` are the pair whose changes are on screen; the pick is what the person is still choosing, and it is
|
|
34
|
+
// read back from the params so a page turn does not throw away half of it.
|
|
35
|
+
const [pending, setPending] = useState({ from: str(params[PICK_FROM]) || str(params.from), to: str(params[PICK_TO]) || str(params.to) });
|
|
36
|
+
const pick = (end: "from" | "to", revision: string) => setPending((pair) => ({ ...pair, [end]: revision }));
|
|
37
|
+
const ready = pending.from !== "" && pending.to !== "" && pending.from !== pending.to;
|
|
38
|
+
const nav = (extra: Record<string, string>) =>
|
|
39
|
+
navigate("history", { ...(vault ? { vault } : {}), ...(path ? { path } : {}), ...extra });
|
|
40
|
+
// Every chosen end is carried, including one that also appears as from/to: the revisions buttons send the cursor and
|
|
41
|
+
// this pick only, so a skipped end would leave a shown pair behind on the next page.
|
|
42
|
+
const pickParams = (): Record<string, string> => ({
|
|
43
|
+
...(pending.from ? { [PICK_FROM]: pending.from } : {}),
|
|
44
|
+
...(pending.to ? { [PICK_TO]: pending.to } : {}),
|
|
45
|
+
});
|
|
46
|
+
// Changes paging stays on the pair that produced the list: an old changesCursor sent with a newer pick would page a
|
|
47
|
+
// list the person is no longer looking at. The pick rides along, so choosing a new pair survives a page turn too.
|
|
48
|
+
const shownFrom = str(changes.from);
|
|
49
|
+
const shownTo = str(changes.to);
|
|
50
|
+
// Each list keeps its own page while the other one turns: both cursors belong to their own list (the changes cursor
|
|
51
|
+
// to the pair, the revisions cursor to HEAD), so carrying the other one is safe. Each first-page button still drops
|
|
52
|
+
// only its own cursor.
|
|
53
|
+
const changesNav = (extra: Record<string, string>) =>
|
|
54
|
+
nav({ from: shownFrom, to: shownTo, ...pickParams(), ...(params.cursor ? { cursor: params.cursor } : {}), ...extra });
|
|
55
|
+
// A revisions page turn keeps the changes list on screen too: the pair that produced it travels with the cursor, so
|
|
56
|
+
// only the revisions under it change.
|
|
57
|
+
const revisionsNav = (extra: Record<string, string>) =>
|
|
58
|
+
nav({
|
|
59
|
+
...pickParams(),
|
|
60
|
+
...(shownFrom && shownTo
|
|
61
|
+
? { from: shownFrom, to: shownTo, ...(params.changesCursor ? { changesCursor: params.changesCursor } : {}) }
|
|
62
|
+
: {}),
|
|
63
|
+
...extra,
|
|
64
|
+
});
|
|
65
|
+
const historyMore = str(history.continuation);
|
|
66
|
+
const changesMore = str(changes.continuation);
|
|
67
|
+
const stop = str(history.stopReason);
|
|
68
|
+
|
|
69
|
+
if (!path) {
|
|
70
|
+
return <Empty title="No note selected" hint="Open a note, then choose History on that note." />;
|
|
71
|
+
}
|
|
72
|
+
// A refusal (unknown vault, a cursor the provider no longer knows, a half pair) answers no history at all, and the
|
|
73
|
+
// refusal already names its cause and next step. A carried cursor is the one refusal the panel can undo by itself:
|
|
74
|
+
// the next reload or poll lands on it again, so the way back to a clean first page is offered here.
|
|
75
|
+
if (error && !reply.history) {
|
|
76
|
+
const stuck = str(params.cursor) || str(params.changesCursor);
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
<Notice tone="err">{error}</Notice>
|
|
80
|
+
{stuck ? (
|
|
81
|
+
<div className="vmem-bar">
|
|
82
|
+
<button type="button" className="vmem-button" onClick={() => nav({})}>
|
|
83
|
+
Start over
|
|
84
|
+
</button>
|
|
85
|
+
</div>
|
|
86
|
+
) : null}
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
<h1>History</h1>
|
|
93
|
+
{error ? <Notice tone="err">{error}</Notice> : null}
|
|
94
|
+
<p className="vmem-sub">{path}</p>
|
|
95
|
+
<section className="vmem-section" aria-label="Revisions">
|
|
96
|
+
<h2 className="vmem-card-title">Revisions</h2>
|
|
97
|
+
{incomplete && reason ? <Notice tone="warn">{reason}</Notice> : null}
|
|
98
|
+
{revisions.length === 0 && !incomplete ? (
|
|
99
|
+
<Empty title="No history" hint="This note has no commit yet, or the path is not in the vault's first-parent history." />
|
|
100
|
+
) : null}
|
|
101
|
+
<List
|
|
102
|
+
label="Revisions"
|
|
103
|
+
items={revisions.map((revision) => {
|
|
104
|
+
const id = str(revision.revision);
|
|
105
|
+
return {
|
|
106
|
+
key: id,
|
|
107
|
+
title: `Revision ${short(id)}`,
|
|
108
|
+
sub: [when(revision.committedAt), `${str(revision.bytes)} bytes`, revision.blob ? `blob ${short(str(revision.blob))}` : ""].filter(Boolean).join(" · "),
|
|
109
|
+
verbs: (
|
|
110
|
+
<>
|
|
111
|
+
<button type="button" className="vmem-button" aria-pressed={pending.from === id} onClick={() => pick("from", id)}>
|
|
112
|
+
From
|
|
113
|
+
</button>
|
|
114
|
+
<button type="button" className="vmem-button" aria-pressed={pending.to === id} onClick={() => pick("to", id)}>
|
|
115
|
+
To
|
|
116
|
+
</button>
|
|
117
|
+
</>
|
|
118
|
+
),
|
|
119
|
+
};
|
|
120
|
+
})}
|
|
121
|
+
/>
|
|
122
|
+
<div className="vmem-bar">
|
|
123
|
+
{params.cursor ? (
|
|
124
|
+
<button type="button" className="vmem-button" onClick={() => revisionsNav({})}>
|
|
125
|
+
Newest revisions
|
|
126
|
+
</button>
|
|
127
|
+
) : null}
|
|
128
|
+
{historyMore ? (
|
|
129
|
+
<button type="button" className="vmem-button" onClick={() => revisionsNav({ cursor: historyMore })}>
|
|
130
|
+
Older revisions
|
|
131
|
+
</button>
|
|
132
|
+
) : null}
|
|
133
|
+
</div>
|
|
134
|
+
{stop === "scan_limit" || stop === "transport_limit" ? (
|
|
135
|
+
<Notice tone="warn">The provider stopped reading history at its {stop === "scan_limit" ? "scan limit" : "transport limit"}; older commits exist beyond this page.</Notice>
|
|
136
|
+
) : null}
|
|
137
|
+
</section>
|
|
138
|
+
<section className="vmem-section" aria-label="Changes">
|
|
139
|
+
<h2 className="vmem-card-title">Changes</h2>
|
|
140
|
+
<p className="vmem-sub">
|
|
141
|
+
From {pending.from ? short(pending.from) : "not chosen"} to {pending.to ? short(pending.to) : "not chosen"}
|
|
142
|
+
</p>
|
|
143
|
+
<div className="vmem-bar">
|
|
144
|
+
<button type="button" className="vmem-button vmem-button-primary" disabled={!ready} onClick={() => nav({ from: pending.from, to: pending.to })}>
|
|
145
|
+
Show changes
|
|
146
|
+
</button>
|
|
147
|
+
{pending.from || pending.to ? (
|
|
148
|
+
<button
|
|
149
|
+
type="button"
|
|
150
|
+
className="vmem-button"
|
|
151
|
+
onClick={() => {
|
|
152
|
+
setPending({ from: "", to: "" });
|
|
153
|
+
nav({});
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
Clear
|
|
157
|
+
</button>
|
|
158
|
+
) : null}
|
|
159
|
+
</div>
|
|
160
|
+
{shownFrom && shownTo ? (
|
|
161
|
+
<>
|
|
162
|
+
<p className="vmem-sub">
|
|
163
|
+
{changed.length} {changed.length === 1 ? "note" : "notes"} changed between {short(shownFrom)} and {short(shownTo)}
|
|
164
|
+
{changes.total !== undefined ? ` of ${str(changes.total)}` : ""}
|
|
165
|
+
</p>
|
|
166
|
+
<List
|
|
167
|
+
label="Changed notes"
|
|
168
|
+
items={changed.map((note) => {
|
|
169
|
+
const status = str(note.status);
|
|
170
|
+
const notePath = str(note.path);
|
|
171
|
+
return {
|
|
172
|
+
key: `${status}:${notePath}`,
|
|
173
|
+
title: notePath,
|
|
174
|
+
sub: [CHANGE_TEXT[status] ?? status, note.before ? `before ${short(str(note.before))}` : "", note.after ? `after ${short(str(note.after))}` : ""].filter(Boolean).join(" · "),
|
|
175
|
+
chip: { text: status || "?", tone: status === "D" ? "err" : status === "A" ? "neutral" : "warn" },
|
|
176
|
+
...(notePath && status !== "D" ? { onOpen: () => navigate("note", { path: notePath, ...vaultParam(params) }) } : {}),
|
|
177
|
+
};
|
|
178
|
+
})}
|
|
179
|
+
empty={<Empty title="No changes" hint="These revisions change no notes in this vault." />}
|
|
180
|
+
/>
|
|
181
|
+
<div className="vmem-bar">
|
|
182
|
+
{params.changesCursor ? (
|
|
183
|
+
<button type="button" className="vmem-button" onClick={() => changesNav({})}>
|
|
184
|
+
First page
|
|
185
|
+
</button>
|
|
186
|
+
) : null}
|
|
187
|
+
{changesMore ? (
|
|
188
|
+
<button type="button" className="vmem-button" onClick={() => changesNav({ changesCursor: changesMore })}>
|
|
189
|
+
More changes
|
|
190
|
+
</button>
|
|
191
|
+
) : null}
|
|
192
|
+
</div>
|
|
193
|
+
{num(changes.skippedDenied) || num(changes.skippedSymlink) ? (
|
|
194
|
+
<Notice tone="warn">
|
|
195
|
+
{num(changes.skippedDenied)} denied {num(changes.skippedDenied) === 1 ? "path" : "paths"} and {num(changes.skippedSymlink)} symlink
|
|
196
|
+
{num(changes.skippedSymlink) === 1 ? "" : "s"} are left out of this list.
|
|
197
|
+
</Notice>
|
|
198
|
+
) : null}
|
|
199
|
+
{changes.truncated === true ? <p className="vmem-sub">The provider stopped at its page limit; continue to the next page.</p> : null}
|
|
200
|
+
</>
|
|
201
|
+
) : null}
|
|
202
|
+
</section>
|
|
203
|
+
</>
|
|
204
|
+
);
|
|
205
|
+
}
|