@tsplc/tmp-debug 0.0.0-stage → 0.6.2
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 +38 -2
- package/dist/api.js +744 -0
- package/dist/api.js.map +12 -0
- package/dist/constant.js +33 -0
- package/dist/constant.js.map +10 -0
- package/dist/explain-file.js +468 -0
- package/dist/explain-file.js.map +11 -0
- package/dist/explain.js +1310 -0
- package/dist/explain.js.map +19 -0
- package/dist/format.js +214 -0
- package/dist/format.js.map +12 -0
- package/dist/index.js +4066 -0
- package/dist/index.js.map +44 -0
- package/dist/manifest.js +240 -0
- package/dist/manifest.js.map +10 -0
- package/dist/paths.js +242 -0
- package/dist/paths.js.map +10 -0
- package/package.json +72 -4
- package/src/adapter.ts +77 -0
- package/src/api.ts +446 -0
- package/src/app-server.ts +151 -0
- package/src/build-files.ts +46 -0
- package/src/constant.ts +41 -0
- package/src/debugger.ts +237 -0
- package/src/errors.ts +13 -0
- package/src/explain-expressions.ts +484 -0
- package/src/explain-file.ts +325 -0
- package/src/explain-frames.ts +155 -0
- package/src/explain-loops.ts +151 -0
- package/src/explain-operations.ts +232 -0
- package/src/explain-tables.ts +345 -0
- package/src/explain-value.ts +203 -0
- package/src/explain-verdicts.ts +548 -0
- package/src/explain.ts +82 -0
- package/src/hardware.ts +159 -0
- package/src/http.ts +218 -0
- package/src/index.ts +44 -0
- package/src/jobs.ts +139 -0
- package/src/login-value.ts +165 -0
- package/src/login.ts +315 -0
- package/src/manifest.ts +328 -0
- package/src/opcua.ts +80 -0
- package/src/paths.ts +363 -0
- package/src/requests.ts +99 -0
- package/src/server-cursor.ts +22 -0
- package/src/shown.ts +229 -0
- package/src/telemetry.ts +125 -0
- package/src/timeline.ts +148 -0
- package/src/trace.ts +62 -0
- package/src/ui/bits.ts +48 -0
- package/src/ui/client.ts +87 -0
- package/src/ui/dom.ts +61 -0
- package/src/ui/explain-read.ts +105 -0
- package/src/ui/format.ts +261 -0
- package/src/ui/hardware.ts +425 -0
- package/src/ui/header.ts +207 -0
- package/src/ui/health.ts +64 -0
- package/src/ui/index.ts +27 -0
- package/src/ui/jobs.ts +263 -0
- package/src/ui/links.ts +59 -0
- package/src/ui/live-value.ts +85 -0
- package/src/ui/main.ts +76 -0
- package/src/ui/overview.ts +178 -0
- package/src/ui/page.ts +286 -0
- package/src/ui/pages.ts +64 -0
- package/src/ui/recent-window.ts +49 -0
- package/src/ui/recent.ts +355 -0
- package/src/ui/request-trace.ts +38 -0
- package/src/ui/requests.ts +80 -0
- package/src/ui/routes.ts +98 -0
- package/src/ui/store.ts +295 -0
- package/src/ui/success-cache.ts +11 -0
- package/src/ui/tree.ts +162 -0
- package/src/ui/variables.ts +597 -0
- package/src/ui/why-watch.ts +11 -0
- package/src/ui/why.ts +694 -0
- package/src/values.ts +170 -0
- package/src/watch.ts +32 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import { isPattern, typeOf } from "../paths";
|
|
2
|
+
import { empty, fill, h, type View, wrappingPath } from "./dom";
|
|
3
|
+
import { typeLabel } from "./format";
|
|
4
|
+
import { pathLink, sourceLink, whyLink } from "./links";
|
|
5
|
+
import { LiveValue } from "./live-value";
|
|
6
|
+
import type { Page } from "./pages";
|
|
7
|
+
import { href, type Place } from "./routes";
|
|
8
|
+
import type { Store, Topic } from "./store";
|
|
9
|
+
import { ancestorPaths, parentPath, type TreeNode, type TreeRow } from "./tree";
|
|
10
|
+
|
|
11
|
+
const ROW_HEIGHT = 26;
|
|
12
|
+
const OVERSCAN = 10;
|
|
13
|
+
const SEARCH_LIMIT = 5000;
|
|
14
|
+
const DEFAULT_GROUP = "Watch";
|
|
15
|
+
const LIVE_TOPICS: Topic[] = ["samples", "clock", "session", "stream"];
|
|
16
|
+
|
|
17
|
+
// Kept across visits, so leaving the page and coming back keeps the tree as it was.
|
|
18
|
+
const expanded = new Set<string>();
|
|
19
|
+
let showGenerated = false;
|
|
20
|
+
let query = "";
|
|
21
|
+
let activeGroup: string | undefined;
|
|
22
|
+
|
|
23
|
+
const highlight = (path: string, needle: string) => {
|
|
24
|
+
const at = path.toLowerCase().indexOf(needle.toLowerCase());
|
|
25
|
+
return h(
|
|
26
|
+
"span",
|
|
27
|
+
{},
|
|
28
|
+
path.slice(0, at),
|
|
29
|
+
h("mark", {}, path.slice(at, at + needle.length)),
|
|
30
|
+
path.slice(at + needle.length),
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** How a node's value is known at runtime. */
|
|
35
|
+
const runtimeNote = (node: TreeNode) => {
|
|
36
|
+
if (node.constant) {
|
|
37
|
+
return "folded by the compiler: no storage";
|
|
38
|
+
}
|
|
39
|
+
return node.readable ? "read live" : "not readable in this build";
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const variablesView = (
|
|
43
|
+
store: Store,
|
|
44
|
+
page: Page,
|
|
45
|
+
place: Extract<Place, { route: "variables" }>,
|
|
46
|
+
): View => {
|
|
47
|
+
const { tree, manifest } = store;
|
|
48
|
+
let selected = place.path;
|
|
49
|
+
let rows: TreeRow[] = [];
|
|
50
|
+
let windowStart = -1;
|
|
51
|
+
let windowEnd = -1;
|
|
52
|
+
let rowValues: LiveValue[] = [];
|
|
53
|
+
let groupValues: LiveValue[] = [];
|
|
54
|
+
let detailValue: LiveValue | undefined;
|
|
55
|
+
let searchTimer: ReturnType<typeof setTimeout> | undefined;
|
|
56
|
+
|
|
57
|
+
const search = h("input", {
|
|
58
|
+
type: "search",
|
|
59
|
+
class: "search",
|
|
60
|
+
placeholder: "Search TypeScript paths, e.g. sampleCounters[3].bin",
|
|
61
|
+
value: query,
|
|
62
|
+
spellcheck: "false",
|
|
63
|
+
});
|
|
64
|
+
const generatedToggle = h("input", {
|
|
65
|
+
type: "checkbox",
|
|
66
|
+
checked: showGenerated,
|
|
67
|
+
});
|
|
68
|
+
const count = h("span", { class: "count" });
|
|
69
|
+
const windowElement = h("div", { class: "vwindow" });
|
|
70
|
+
const spacer = h("div", { class: "vspacer" }, windowElement);
|
|
71
|
+
const list = h("div", { class: "vlist", tabindex: 0, role: "tree" }, spacer);
|
|
72
|
+
const detail = h("section", { class: "panel detail" });
|
|
73
|
+
const groups = h("section", { class: "panel groups" });
|
|
74
|
+
const element = h(
|
|
75
|
+
"div",
|
|
76
|
+
{ class: "page variables" },
|
|
77
|
+
h(
|
|
78
|
+
"div",
|
|
79
|
+
{ class: "toolbar" },
|
|
80
|
+
search,
|
|
81
|
+
h("label", { class: "check" }, generatedToggle, "show generated"),
|
|
82
|
+
count,
|
|
83
|
+
),
|
|
84
|
+
h(
|
|
85
|
+
"div",
|
|
86
|
+
{ class: "split" },
|
|
87
|
+
h(
|
|
88
|
+
"div",
|
|
89
|
+
{ class: "listwrap" },
|
|
90
|
+
h(
|
|
91
|
+
"div",
|
|
92
|
+
{ class: "row head" },
|
|
93
|
+
h("span", {}, "Path"),
|
|
94
|
+
h("span", {}, "Value"),
|
|
95
|
+
h("span", {}, "Quality · read"),
|
|
96
|
+
h("span", {}, "Type"),
|
|
97
|
+
h("span", { title: "In the active watch group" }, "Watch"),
|
|
98
|
+
h("span", {}, "Declared"),
|
|
99
|
+
),
|
|
100
|
+
list,
|
|
101
|
+
),
|
|
102
|
+
h("aside", { class: "side" }, detail, groups),
|
|
103
|
+
),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const watched = (path: string) =>
|
|
107
|
+
Object.values(store.watch.groups).some((paths) => paths.includes(path));
|
|
108
|
+
const inActiveGroup = (path: string) =>
|
|
109
|
+
activeGroup !== undefined &&
|
|
110
|
+
(store.watch.groups[activeGroup] ?? []).includes(path);
|
|
111
|
+
|
|
112
|
+
const watchMark = (path: string) => {
|
|
113
|
+
if (inActiveGroup(path)) {
|
|
114
|
+
return " on";
|
|
115
|
+
}
|
|
116
|
+
return watched(path) ? " elsewhere" : "";
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const liveValues = () => [
|
|
120
|
+
...rowValues,
|
|
121
|
+
...groupValues,
|
|
122
|
+
...(detailValue ? [detailValue] : []),
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
const subscribe = () =>
|
|
126
|
+
page.show({
|
|
127
|
+
watch: liveValues()
|
|
128
|
+
.filter((value) => value.subscribed)
|
|
129
|
+
.map((value) => value.node.path),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const toggleWatch = (path: string) => {
|
|
133
|
+
const group = activeGroup ?? DEFAULT_GROUP;
|
|
134
|
+
activeGroup = group;
|
|
135
|
+
const members = store.watch.groups[group] ?? [];
|
|
136
|
+
void store.saveWatch({
|
|
137
|
+
...store.watch.groups,
|
|
138
|
+
[group]: members.includes(path)
|
|
139
|
+
? members.filter((member) => member !== path)
|
|
140
|
+
: [...members, path],
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const renderRow = ({ node, depth }: TreeRow, index: number) => {
|
|
145
|
+
const expandable = tree.expandable(node);
|
|
146
|
+
const value = expandable ? undefined : new LiveValue(store, node);
|
|
147
|
+
if (value) {
|
|
148
|
+
rowValues.push(value);
|
|
149
|
+
}
|
|
150
|
+
const type = typeOf(manifest, node.type);
|
|
151
|
+
const open = expanded.has(node.path);
|
|
152
|
+
const inGroup = inActiveGroup(node.path);
|
|
153
|
+
return h(
|
|
154
|
+
"div",
|
|
155
|
+
{
|
|
156
|
+
class: `row${node.path === selected ? " selected" : ""}${node.generated ? " generated" : ""}`,
|
|
157
|
+
"data-index": index,
|
|
158
|
+
role: "treeitem",
|
|
159
|
+
"aria-level": depth + 1,
|
|
160
|
+
"aria-expanded": expandable && !query ? String(open) : undefined,
|
|
161
|
+
},
|
|
162
|
+
h(
|
|
163
|
+
"span",
|
|
164
|
+
{
|
|
165
|
+
class: "name",
|
|
166
|
+
style: `padding-left:${depth * 16 + 4}px`,
|
|
167
|
+
title: node.path,
|
|
168
|
+
},
|
|
169
|
+
expandable && !query
|
|
170
|
+
? h(
|
|
171
|
+
"button",
|
|
172
|
+
{ class: "twisty", "data-action": "toggle", tabindex: -1 },
|
|
173
|
+
open ? "▾" : "▸",
|
|
174
|
+
)
|
|
175
|
+
: h("span", { class: "twisty" }),
|
|
176
|
+
query ? highlight(node.path, query) : node.name,
|
|
177
|
+
node.generated ? h("span", { class: "tag" }, "generated") : undefined,
|
|
178
|
+
),
|
|
179
|
+
value?.value ??
|
|
180
|
+
h(
|
|
181
|
+
"span",
|
|
182
|
+
{ class: "value s-group" },
|
|
183
|
+
type.kind === "array" ? `[${type.length}]` : "{…}",
|
|
184
|
+
),
|
|
185
|
+
value?.meta ?? h("span"),
|
|
186
|
+
h("span", { class: "type" }, typeLabel(manifest, node.type)),
|
|
187
|
+
value?.subscribed
|
|
188
|
+
? h(
|
|
189
|
+
"button",
|
|
190
|
+
{
|
|
191
|
+
class: `rec${watchMark(node.path)}`,
|
|
192
|
+
"data-action": "watch",
|
|
193
|
+
tabindex: -1,
|
|
194
|
+
title: inGroup
|
|
195
|
+
? `Watched in “${activeGroup}”: click to remove`
|
|
196
|
+
: `Watch: add to “${activeGroup ?? DEFAULT_GROUP}”`,
|
|
197
|
+
},
|
|
198
|
+
"●",
|
|
199
|
+
)
|
|
200
|
+
: h("span"),
|
|
201
|
+
node.declaration ? sourceLink(store, node.declaration) : h("span"),
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const renderWindow = (force: boolean) => {
|
|
206
|
+
const start = Math.max(
|
|
207
|
+
0,
|
|
208
|
+
Math.floor(list.scrollTop / ROW_HEIGHT) - OVERSCAN,
|
|
209
|
+
);
|
|
210
|
+
const end = Math.min(
|
|
211
|
+
rows.length,
|
|
212
|
+
Math.ceil((list.scrollTop + list.clientHeight) / ROW_HEIGHT) + OVERSCAN,
|
|
213
|
+
);
|
|
214
|
+
if (!force && start === windowStart && end === windowEnd) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
windowStart = start;
|
|
218
|
+
windowEnd = end;
|
|
219
|
+
rowValues = [];
|
|
220
|
+
windowElement.style.transform = `translateY(${start * ROW_HEIGHT}px)`;
|
|
221
|
+
windowElement.replaceChildren(
|
|
222
|
+
...rows
|
|
223
|
+
.slice(start, end)
|
|
224
|
+
.map((row, offset) => renderRow(row, start + offset)),
|
|
225
|
+
);
|
|
226
|
+
subscribe();
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const recompute = () => {
|
|
230
|
+
if (query) {
|
|
231
|
+
const result = tree.search(query, {
|
|
232
|
+
showGenerated,
|
|
233
|
+
limit: SEARCH_LIMIT,
|
|
234
|
+
});
|
|
235
|
+
rows = result.nodes.map((node) => ({ node, depth: 0 }));
|
|
236
|
+
count.textContent =
|
|
237
|
+
result.total > rows.length
|
|
238
|
+
? `first ${rows.length} of ${result.total} matches`
|
|
239
|
+
: `${result.total} matches`;
|
|
240
|
+
} else {
|
|
241
|
+
rows = tree.rows(expanded, { showGenerated });
|
|
242
|
+
count.textContent = `${rows.length} rows`;
|
|
243
|
+
}
|
|
244
|
+
spacer.style.height = `${rows.length * ROW_HEIGHT}px`;
|
|
245
|
+
renderWindow(true);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const scrollToIndex = (index: number) => {
|
|
249
|
+
const top = index * ROW_HEIGHT;
|
|
250
|
+
if (top < list.scrollTop) {
|
|
251
|
+
list.scrollTop = top;
|
|
252
|
+
} else if (top + ROW_HEIGHT > list.scrollTop + list.clientHeight) {
|
|
253
|
+
list.scrollTop = top + ROW_HEIGHT - list.clientHeight;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const reveal = (path: string) => {
|
|
258
|
+
for (const ancestor of ancestorPaths(path)) {
|
|
259
|
+
expanded.add(ancestor);
|
|
260
|
+
}
|
|
261
|
+
recompute();
|
|
262
|
+
const index = rows.findIndex((row) => row.node.path === path);
|
|
263
|
+
if (index >= 0) {
|
|
264
|
+
list.scrollTop = Math.max(0, index * ROW_HEIGHT - list.clientHeight / 2);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const renderDetail = () => {
|
|
269
|
+
detailValue = undefined;
|
|
270
|
+
if (!selected) {
|
|
271
|
+
return detail.replaceChildren(
|
|
272
|
+
h("h2", {}, "Selection"),
|
|
273
|
+
empty("Select a row for its declaration and value."),
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
const node = tree.resolve(selected);
|
|
277
|
+
if (!node) {
|
|
278
|
+
return detail.replaceChildren(
|
|
279
|
+
h("h2", {}, "Selection"),
|
|
280
|
+
empty(`${selected} is not in this build's manifest.`),
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
const leaf = !tree.expandable(node);
|
|
284
|
+
if (leaf) {
|
|
285
|
+
detailValue = new LiveValue(store, node);
|
|
286
|
+
}
|
|
287
|
+
const io = manifest.io.filter((entry) => entry.path === node.path);
|
|
288
|
+
const sites = manifest.events.filter((site) => site.path === node.path);
|
|
289
|
+
fill(
|
|
290
|
+
detail,
|
|
291
|
+
h("h2", {}, "Selection"),
|
|
292
|
+
h(
|
|
293
|
+
"div",
|
|
294
|
+
{ class: "detail-path mono" },
|
|
295
|
+
node.path,
|
|
296
|
+
leaf && node.readable ? whyLink(node.path) : "",
|
|
297
|
+
),
|
|
298
|
+
detailValue &&
|
|
299
|
+
h(
|
|
300
|
+
"div",
|
|
301
|
+
{ class: "detail-value" },
|
|
302
|
+
detailValue.value,
|
|
303
|
+
detailValue.meta,
|
|
304
|
+
),
|
|
305
|
+
h(
|
|
306
|
+
"dl",
|
|
307
|
+
{},
|
|
308
|
+
h("dt", {}, "Type"),
|
|
309
|
+
h("dd", { class: "mono" }, typeLabel(manifest, node.type)),
|
|
310
|
+
h("dt", {}, "Declared"),
|
|
311
|
+
h(
|
|
312
|
+
"dd",
|
|
313
|
+
{},
|
|
314
|
+
node.declaration ? sourceLink(store, node.declaration) : "not known",
|
|
315
|
+
),
|
|
316
|
+
h("dt", {}, "Runtime"),
|
|
317
|
+
h("dd", {}, runtimeNote(node)),
|
|
318
|
+
...io.flatMap((entry) => [
|
|
319
|
+
h("dt", {}, entry.direction === "input" ? "Input" : "Output"),
|
|
320
|
+
h(
|
|
321
|
+
"dd",
|
|
322
|
+
{},
|
|
323
|
+
entry.device
|
|
324
|
+
? h(
|
|
325
|
+
"a",
|
|
326
|
+
{ href: href({ route: "hardware", device: entry.device }) },
|
|
327
|
+
entry.device,
|
|
328
|
+
)
|
|
329
|
+
: "no device",
|
|
330
|
+
entry.channel ? ` · ${entry.channel}` : "",
|
|
331
|
+
entry.address ? ` · ${entry.address}` : "",
|
|
332
|
+
entry.inverted ? " · inverted" : "",
|
|
333
|
+
),
|
|
334
|
+
]),
|
|
335
|
+
),
|
|
336
|
+
sites.length > 0 &&
|
|
337
|
+
h(
|
|
338
|
+
"div",
|
|
339
|
+
{ class: "sites" },
|
|
340
|
+
h("h3", {}, "Traced writes"),
|
|
341
|
+
...sites.map((site) =>
|
|
342
|
+
h(
|
|
343
|
+
"div",
|
|
344
|
+
{ class: "site" },
|
|
345
|
+
h("code", {}, site.text),
|
|
346
|
+
" ",
|
|
347
|
+
sourceLink(store, site.range),
|
|
348
|
+
),
|
|
349
|
+
),
|
|
350
|
+
),
|
|
351
|
+
query &&
|
|
352
|
+
h(
|
|
353
|
+
"button",
|
|
354
|
+
{
|
|
355
|
+
onclick: () => {
|
|
356
|
+
query = "";
|
|
357
|
+
search.value = "";
|
|
358
|
+
reveal(node.path);
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
"Show in tree",
|
|
362
|
+
),
|
|
363
|
+
);
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const renderGroups = () => {
|
|
367
|
+
groupValues = [];
|
|
368
|
+
const names = Object.keys(store.watch.groups);
|
|
369
|
+
if (activeGroup === undefined || !names.includes(activeGroup)) {
|
|
370
|
+
activeGroup = names[0];
|
|
371
|
+
}
|
|
372
|
+
const nameInput = h("input", { placeholder: "New group", size: 12 });
|
|
373
|
+
const members =
|
|
374
|
+
activeGroup === undefined ? [] : (store.watch.groups[activeGroup] ?? []);
|
|
375
|
+
groups.replaceChildren(
|
|
376
|
+
h("h2", {}, "Watch groups"),
|
|
377
|
+
h(
|
|
378
|
+
"p",
|
|
379
|
+
{ class: "hint" },
|
|
380
|
+
"Paths in a group are read live while this page shows them; nothing is recorded.",
|
|
381
|
+
),
|
|
382
|
+
h(
|
|
383
|
+
"div",
|
|
384
|
+
{ class: "tabs" },
|
|
385
|
+
...Object.entries(store.watch.groups).map(([name, paths]) =>
|
|
386
|
+
h(
|
|
387
|
+
"button",
|
|
388
|
+
{
|
|
389
|
+
class: `tab${name === activeGroup ? " on" : ""}`,
|
|
390
|
+
onclick: () => {
|
|
391
|
+
activeGroup = name;
|
|
392
|
+
renderGroups();
|
|
393
|
+
renderWindow(true);
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
name,
|
|
397
|
+
h("span", { class: "n" }, String(paths.length)),
|
|
398
|
+
),
|
|
399
|
+
),
|
|
400
|
+
h(
|
|
401
|
+
"form",
|
|
402
|
+
{
|
|
403
|
+
onsubmit: (event: Event) => {
|
|
404
|
+
event.preventDefault();
|
|
405
|
+
const name = nameInput.value.trim();
|
|
406
|
+
if (!name || name in store.watch.groups) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
activeGroup = name;
|
|
410
|
+
void store.saveWatch({ ...store.watch.groups, [name]: [] });
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
nameInput,
|
|
414
|
+
),
|
|
415
|
+
),
|
|
416
|
+
...(members.length
|
|
417
|
+
? members.flatMap((member) => {
|
|
418
|
+
const remove = h(
|
|
419
|
+
"button",
|
|
420
|
+
{
|
|
421
|
+
class: "remove",
|
|
422
|
+
title: "Remove from group",
|
|
423
|
+
onclick: () => toggleWatch(member),
|
|
424
|
+
},
|
|
425
|
+
"×",
|
|
426
|
+
);
|
|
427
|
+
const row = (path: string, removable: boolean) => {
|
|
428
|
+
const node = tree.resolve(path);
|
|
429
|
+
const value = node && new LiveValue(store, node);
|
|
430
|
+
if (value) {
|
|
431
|
+
groupValues.push(value);
|
|
432
|
+
}
|
|
433
|
+
return h(
|
|
434
|
+
"div",
|
|
435
|
+
{ class: "member" },
|
|
436
|
+
pathLink(path, wrappingPath(path)),
|
|
437
|
+
value
|
|
438
|
+
? value.value
|
|
439
|
+
: h(
|
|
440
|
+
"span",
|
|
441
|
+
{ class: "value s-unavailable" },
|
|
442
|
+
"not in this build",
|
|
443
|
+
),
|
|
444
|
+
value?.meta,
|
|
445
|
+
removable ? remove : "",
|
|
446
|
+
);
|
|
447
|
+
};
|
|
448
|
+
if (!isPattern(member)) {
|
|
449
|
+
return [row(member, true)];
|
|
450
|
+
}
|
|
451
|
+
// A pattern from the config or a saved group: one row per path it matches.
|
|
452
|
+
const matched = tree.paths.expand([member]);
|
|
453
|
+
return [
|
|
454
|
+
h(
|
|
455
|
+
"div",
|
|
456
|
+
{ class: "member" },
|
|
457
|
+
h("span", { class: "mono" }, wrappingPath(member)),
|
|
458
|
+
h("span", { class: "dim" }, `${matched.length} paths`),
|
|
459
|
+
remove,
|
|
460
|
+
),
|
|
461
|
+
...matched.map((path) => row(path, false)),
|
|
462
|
+
];
|
|
463
|
+
})
|
|
464
|
+
: [
|
|
465
|
+
empty(
|
|
466
|
+
activeGroup
|
|
467
|
+
? "Empty: use ● on a row to add it."
|
|
468
|
+
: "No groups yet.",
|
|
469
|
+
),
|
|
470
|
+
]),
|
|
471
|
+
);
|
|
472
|
+
subscribe();
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
const select = (path: string) => {
|
|
476
|
+
selected = path;
|
|
477
|
+
history.replaceState(null, "", href({ route: "variables", path }));
|
|
478
|
+
renderWindow(true);
|
|
479
|
+
renderDetail();
|
|
480
|
+
subscribe();
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
const move = (index: number) => {
|
|
484
|
+
const row = rows[index];
|
|
485
|
+
if (!row) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
select(row.node.path);
|
|
489
|
+
scrollToIndex(index);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
const toggle = (node: TreeNode) => {
|
|
493
|
+
if (expanded.has(node.path)) {
|
|
494
|
+
expanded.delete(node.path);
|
|
495
|
+
} else {
|
|
496
|
+
expanded.add(node.path);
|
|
497
|
+
}
|
|
498
|
+
recompute();
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
list.addEventListener("click", (event) => {
|
|
502
|
+
if (!(event.target instanceof Element) || event.target.closest("a")) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const rowElement = event.target.closest<HTMLElement>(".row");
|
|
506
|
+
const row = rows[Number(rowElement?.dataset.index)];
|
|
507
|
+
if (!row) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const action =
|
|
511
|
+
event.target.closest<HTMLElement>("[data-action]")?.dataset.action;
|
|
512
|
+
if (action === "toggle") {
|
|
513
|
+
toggle(row.node);
|
|
514
|
+
} else if (action === "watch") {
|
|
515
|
+
toggleWatch(row.node.path);
|
|
516
|
+
} else {
|
|
517
|
+
select(row.node.path);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
list.addEventListener("keydown", (event) => {
|
|
521
|
+
const index = rows.findIndex((row) => row.node.path === selected);
|
|
522
|
+
const node = rows[index]?.node;
|
|
523
|
+
switch (event.key) {
|
|
524
|
+
case "ArrowDown":
|
|
525
|
+
move(index + 1);
|
|
526
|
+
break;
|
|
527
|
+
case "ArrowUp":
|
|
528
|
+
move(Math.max(0, index - 1));
|
|
529
|
+
break;
|
|
530
|
+
case "ArrowRight":
|
|
531
|
+
if (
|
|
532
|
+
node &&
|
|
533
|
+
!query &&
|
|
534
|
+
tree.expandable(node) &&
|
|
535
|
+
!expanded.has(node.path)
|
|
536
|
+
) {
|
|
537
|
+
toggle(node);
|
|
538
|
+
}
|
|
539
|
+
break;
|
|
540
|
+
case "ArrowLeft":
|
|
541
|
+
if (node && !query && expanded.has(node.path)) {
|
|
542
|
+
toggle(node);
|
|
543
|
+
} else if (node) {
|
|
544
|
+
move(
|
|
545
|
+
rows.findIndex((row) => row.node.path === parentPath(node.path)),
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
break;
|
|
549
|
+
default:
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
event.preventDefault();
|
|
553
|
+
});
|
|
554
|
+
list.addEventListener("scroll", () => renderWindow(false), { passive: true });
|
|
555
|
+
const resize = new ResizeObserver(() => renderWindow(false));
|
|
556
|
+
resize.observe(list);
|
|
557
|
+
|
|
558
|
+
search.addEventListener("input", () => {
|
|
559
|
+
clearTimeout(searchTimer);
|
|
560
|
+
searchTimer = setTimeout(() => {
|
|
561
|
+
query = search.value.trim();
|
|
562
|
+
list.scrollTop = 0;
|
|
563
|
+
recompute();
|
|
564
|
+
renderDetail();
|
|
565
|
+
}, 150);
|
|
566
|
+
});
|
|
567
|
+
generatedToggle.addEventListener("change", () => {
|
|
568
|
+
showGenerated = generatedToggle.checked;
|
|
569
|
+
recompute();
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
renderGroups();
|
|
573
|
+
renderDetail();
|
|
574
|
+
requestAnimationFrame(() =>
|
|
575
|
+
selected && !query ? reveal(selected) : recompute(),
|
|
576
|
+
);
|
|
577
|
+
|
|
578
|
+
return {
|
|
579
|
+
element,
|
|
580
|
+
update(topics) {
|
|
581
|
+
if (topics.has("watch")) {
|
|
582
|
+
renderGroups();
|
|
583
|
+
renderWindow(true);
|
|
584
|
+
renderDetail();
|
|
585
|
+
}
|
|
586
|
+
if (LIVE_TOPICS.some((topic) => topics.has(topic))) {
|
|
587
|
+
for (const value of liveValues()) {
|
|
588
|
+
value.update();
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
dispose() {
|
|
593
|
+
resize.disconnect();
|
|
594
|
+
clearTimeout(searchTimer);
|
|
595
|
+
},
|
|
596
|
+
};
|
|
597
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The most stored values one explanation watches; the rest are shown as not read. */
|
|
2
|
+
export const maxWatched = 128;
|
|
3
|
+
|
|
4
|
+
/** What the page watches: the explained path first, then the values the last evaluation needed. */
|
|
5
|
+
export const watchList = (
|
|
6
|
+
target: string,
|
|
7
|
+
needed: Iterable<string>,
|
|
8
|
+
): { watched: string[]; unread: string[] } => {
|
|
9
|
+
const all = [...new Set([target, ...needed])];
|
|
10
|
+
return { watched: all.slice(0, maxWatched), unread: all.slice(maxWatched) };
|
|
11
|
+
};
|