diffdesk 0.1.0__py3-none-any.whl
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.
- diffdesk/__init__.py +3 -0
- diffdesk/agent.py +414 -0
- diffdesk/agent_guide.md +112 -0
- diffdesk/cli.py +329 -0
- diffdesk/config.py +130 -0
- diffdesk/gitio.py +391 -0
- diffdesk/index.py +635 -0
- diffdesk/mcp.py +472 -0
- diffdesk/server.py +750 -0
- diffdesk/static/app.js +402 -0
- diffdesk/static/index.html +129 -0
- diffdesk/static/js/api.js +58 -0
- diffdesk/static/js/boot.js +12 -0
- diffdesk/static/js/diffview.js +359 -0
- diffdesk/static/js/dom.js +82 -0
- diffdesk/static/js/editor-cm.js +225 -0
- diffdesk/static/js/editor-monaco.js +116 -0
- diffdesk/static/js/flow.js +227 -0
- diffdesk/static/js/hunks.js +40 -0
- diffdesk/static/js/markdown.js +102 -0
- diffdesk/static/js/settings.js +228 -0
- diffdesk/static/js/subject.js +127 -0
- diffdesk/static/js/tree.js +492 -0
- diffdesk/static/js/treemap.js +217 -0
- diffdesk/static/style.css +508 -0
- diffdesk/static/vendor/LICENSES.txt +603 -0
- diffdesk/static/vendor/codemirror.js +24 -0
- diffdesk/static/vendor/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Main-Bold.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Main-Italic.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Main-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Math-Italic.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Script-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- diffdesk/static/vendor/fonts/OFL.txt +102 -0
- diffdesk/static/vendor/katex.css +2 -0
- diffdesk/static/vendor/katex.js +258 -0
- diffdesk/static/vendor/marked.js +72 -0
- diffdesk/subject.schema.json +59 -0
- diffdesk-0.1.0.dist-info/METADATA +520 -0
- diffdesk-0.1.0.dist-info/RECORD +59 -0
- diffdesk-0.1.0.dist-info/WHEEL +4 -0
- diffdesk-0.1.0.dist-info/entry_points.txt +2 -0
- diffdesk-0.1.0.dist-info/licenses/LICENSE +21 -0
- diffdesk-0.1.0.dist-info/licenses/src/diffdesk/static/vendor/LICENSES.txt +603 -0
- diffdesk-0.1.0.dist-info/licenses/src/diffdesk/static/vendor/fonts/OFL.txt +102 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
// Tree view: package > branch > subjects (commit order) > files.
|
|
2
|
+
// The whole tree is one virtual list: only the rows in view are in the DOM.
|
|
3
|
+
import { api } from './api.js';
|
|
4
|
+
import { h, statusBar, reviewedOf, frameOnce, STATUS_LABEL } from './dom.js';
|
|
5
|
+
|
|
6
|
+
// Page size of /api/subjects requests; it is the API's default `limit`.
|
|
7
|
+
const PAGE = 200;
|
|
8
|
+
const SEP = '\u0001';
|
|
9
|
+
|
|
10
|
+
const append = (el, ...nodes) => el.append(...nodes.filter(Boolean));
|
|
11
|
+
const pkgKey = (p) => `p${SEP}${p}`;
|
|
12
|
+
// Branch rows are keyed by repository too: two checkouts can have a branch of the same name.
|
|
13
|
+
const branchKey = (p, b, repo) => `b${SEP}${p}${SEP}${b ?? ''}${SEP}${repo ?? ''}`;
|
|
14
|
+
const subjectKey = (p, id) => `s${SEP}${p}${SEP}${id}`;
|
|
15
|
+
|
|
16
|
+
export class Tree {
|
|
17
|
+
/**
|
|
18
|
+
* @param {HTMLElement} el Scroll container.
|
|
19
|
+
* @param {{onOpen: (target: {id: string, package: string, path?: string}) => void}} hooks
|
|
20
|
+
*/
|
|
21
|
+
constructor(el, hooks) {
|
|
22
|
+
this.el = el;
|
|
23
|
+
this.hooks = hooks;
|
|
24
|
+
this.packages = [];
|
|
25
|
+
this.expanded = new Set();
|
|
26
|
+
this.lists = new Map();
|
|
27
|
+
this.files = new Map();
|
|
28
|
+
this.filter = { q: '', status: '', pkg: null };
|
|
29
|
+
this.flat = null;
|
|
30
|
+
this.flatAbort = null;
|
|
31
|
+
this.rows = [];
|
|
32
|
+
this.focus = 0;
|
|
33
|
+
this.activeKey = null;
|
|
34
|
+
this.rowH = 0;
|
|
35
|
+
this.viewH = 0;
|
|
36
|
+
this.drawn = [-1, -1];
|
|
37
|
+
|
|
38
|
+
this.spacer = h('div', { class: 'vl-spacer' });
|
|
39
|
+
this.win = h('div', { class: 'vl-window', role: 'presentation' });
|
|
40
|
+
el.append(this.spacer, this.win);
|
|
41
|
+
this.schedule = frameOnce(() => this.draw());
|
|
42
|
+
el.addEventListener('scroll', this.schedule, { passive: true });
|
|
43
|
+
new ResizeObserver((entries) => {
|
|
44
|
+
this.viewH = entries[0].contentRect.height;
|
|
45
|
+
this.schedule();
|
|
46
|
+
}).observe(el);
|
|
47
|
+
el.addEventListener('keydown', (e) => this.onKey(e));
|
|
48
|
+
el.addEventListener('click', (e) => this.onClick(e));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Data */
|
|
52
|
+
|
|
53
|
+
async load() {
|
|
54
|
+
this.packages = await api.tree();
|
|
55
|
+
if (this.packages.length === 1) this.expanded.add(pkgKey(this.packages[0].package));
|
|
56
|
+
this.rebuild();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Re-read the tree, every open branch list, every open file list and the search result. */
|
|
60
|
+
async refresh() {
|
|
61
|
+
this.packages = await api.tree();
|
|
62
|
+
const jobs = [];
|
|
63
|
+
for (const [key, list] of this.lists) {
|
|
64
|
+
if (this.expanded.has(key)) jobs.push(this.fetchList(list, Math.max(list.items.length, 1)));
|
|
65
|
+
else this.lists.delete(key);
|
|
66
|
+
}
|
|
67
|
+
for (const key of [...this.files.keys()]) {
|
|
68
|
+
if (this.expanded.has(key)) jobs.push(this.fetchFiles(key));
|
|
69
|
+
else this.files.delete(key);
|
|
70
|
+
}
|
|
71
|
+
if (this.flat) jobs.push(this.fetchList(this.flat, Math.max(this.flat.items.length, 1)));
|
|
72
|
+
await Promise.all(jobs);
|
|
73
|
+
this.rebuild();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
newList(params) {
|
|
77
|
+
return { params, total: null, items: [], loading: false, error: null };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Fetch pages from offset 0 until `want` items (or all) are loaded; replaces `list.items`. */
|
|
81
|
+
async fetchList(list, want = PAGE, signal) {
|
|
82
|
+
list.loading = true;
|
|
83
|
+
list.error = null;
|
|
84
|
+
try {
|
|
85
|
+
const items = [];
|
|
86
|
+
let total = Infinity;
|
|
87
|
+
while (items.length < Math.min(want, total)) {
|
|
88
|
+
const page = await api.subjects({ ...list.params, offset: items.length, limit: PAGE }, signal);
|
|
89
|
+
total = page.total;
|
|
90
|
+
items.push(...page.items);
|
|
91
|
+
if (!page.items.length) break;
|
|
92
|
+
}
|
|
93
|
+
list.items = items;
|
|
94
|
+
list.total = total === Infinity ? items.length : total;
|
|
95
|
+
} catch (err) {
|
|
96
|
+
if (err.name === 'AbortError') return;
|
|
97
|
+
list.error = err.message;
|
|
98
|
+
} finally {
|
|
99
|
+
list.loading = false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async loadMore(list) {
|
|
104
|
+
if (list.loading || list.items.length >= list.total) return;
|
|
105
|
+
list.loading = true;
|
|
106
|
+
this.rebuild();
|
|
107
|
+
try {
|
|
108
|
+
const page = await api.subjects({ ...list.params, offset: list.items.length, limit: PAGE });
|
|
109
|
+
list.items.push(...page.items);
|
|
110
|
+
list.total = page.total;
|
|
111
|
+
} catch (err) {
|
|
112
|
+
list.error = err.message;
|
|
113
|
+
} finally {
|
|
114
|
+
list.loading = false;
|
|
115
|
+
}
|
|
116
|
+
this.rebuild();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async fetchFiles(key) {
|
|
120
|
+
const entry = this.files.get(key) || { files: null, error: null };
|
|
121
|
+
this.files.set(key, entry);
|
|
122
|
+
const [, pkg, id] = key.split(SEP);
|
|
123
|
+
try {
|
|
124
|
+
const subject = await api.subject(id, pkg);
|
|
125
|
+
entry.files = subject.files || [];
|
|
126
|
+
entry.error = null;
|
|
127
|
+
} catch (err) {
|
|
128
|
+
entry.error = err.message;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async expand(row) {
|
|
133
|
+
if (this.expanded.has(row.key)) return;
|
|
134
|
+
this.expanded.add(row.key);
|
|
135
|
+
if (row.kind === 'branch' && !this.lists.has(row.key)) {
|
|
136
|
+
const list = this.newList({ package: row.pkg, branch: row.branch, repo: row.repo });
|
|
137
|
+
this.lists.set(row.key, list);
|
|
138
|
+
this.rebuild();
|
|
139
|
+
await this.fetchList(list);
|
|
140
|
+
} else if (row.kind === 'subject' && !this.files.has(row.key)) {
|
|
141
|
+
this.files.set(row.key, { files: null, error: null });
|
|
142
|
+
this.rebuild();
|
|
143
|
+
await this.fetchFiles(row.key);
|
|
144
|
+
}
|
|
145
|
+
this.rebuild();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
collapse(row) {
|
|
149
|
+
this.expanded.delete(row.key);
|
|
150
|
+
this.rebuild();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Search text and status filter. A non-empty filter shows a flat result list. */
|
|
154
|
+
async setFilter({ q, status }) {
|
|
155
|
+
this.filter.q = q;
|
|
156
|
+
this.filter.status = status;
|
|
157
|
+
await this.runFilter();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Show only package `pkg` (or all packages for `null`). */
|
|
161
|
+
async setPackage(pkg) {
|
|
162
|
+
this.filter.pkg = pkg;
|
|
163
|
+
if (pkg) this.expanded.add(pkgKey(pkg));
|
|
164
|
+
await this.runFilter();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async runFilter() {
|
|
168
|
+
this.flatAbort?.abort();
|
|
169
|
+
if (!this.filter.q && !this.filter.status) {
|
|
170
|
+
this.flat = null;
|
|
171
|
+
this.rebuild();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.flatAbort = new AbortController();
|
|
175
|
+
const list = this.newList({ q: this.filter.q, status: this.filter.status, package: this.filter.pkg });
|
|
176
|
+
this.flat = list;
|
|
177
|
+
this.rebuild();
|
|
178
|
+
await this.fetchList(list, PAGE, this.flatAbort.signal);
|
|
179
|
+
if (this.flat === list) this.rebuild();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Expand the path to a subject and scroll it into view. */
|
|
183
|
+
async reveal(pkg, id, branch, repo) {
|
|
184
|
+
this.activeKey = subjectKey(pkg, id);
|
|
185
|
+
if (!this.flat) {
|
|
186
|
+
if (this.filter.pkg && this.filter.pkg !== pkg) this.filter.pkg = null;
|
|
187
|
+
this.expanded.add(pkgKey(pkg));
|
|
188
|
+
const known = this.packages.find((p) => p.package === pkg)?.branches?.find((b) => b.name === branch && (repo === undefined || b.repo === repo));
|
|
189
|
+
if (known) {
|
|
190
|
+
const bk = branchKey(pkg, known.name, known.repo);
|
|
191
|
+
this.expanded.add(bk);
|
|
192
|
+
let list = this.lists.get(bk);
|
|
193
|
+
if (!list) {
|
|
194
|
+
list = this.newList({ package: pkg, branch: known.name, repo: known.repo });
|
|
195
|
+
this.lists.set(bk, list);
|
|
196
|
+
await this.fetchList(list);
|
|
197
|
+
}
|
|
198
|
+
while (!list.items.some((s) => s.id === id) && list.items.length < list.total && !list.error) {
|
|
199
|
+
await this.loadMore(list);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
this.rebuild();
|
|
204
|
+
const i = this.rows.findIndex((r) => r.key === this.activeKey);
|
|
205
|
+
if (i >= 0) {
|
|
206
|
+
this.focus = i;
|
|
207
|
+
this.scrollTo(i);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
setActive(pkg, id) {
|
|
212
|
+
this.activeKey = id == null ? null : subjectKey(pkg, id);
|
|
213
|
+
this.drawn = [-1, -1];
|
|
214
|
+
this.schedule();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/* Rows */
|
|
218
|
+
|
|
219
|
+
rebuild() {
|
|
220
|
+
const rows = [];
|
|
221
|
+
if (this.flat) this.flatRows(rows);
|
|
222
|
+
else this.treeRows(rows);
|
|
223
|
+
const focusKey = this.rows[this.focus]?.key;
|
|
224
|
+
this.rows = rows;
|
|
225
|
+
const i = focusKey ? rows.findIndex((r) => r.key === focusKey) : -1;
|
|
226
|
+
this.focus = i >= 0 ? i : Math.min(this.focus, Math.max(rows.length - 1, 0));
|
|
227
|
+
this.drawn = [-1, -1];
|
|
228
|
+
this.schedule();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
treeRows(rows) {
|
|
232
|
+
const pkgs = this.filter.pkg ? this.packages.filter((p) => p.package === this.filter.pkg) : this.packages;
|
|
233
|
+
if (!pkgs.length) rows.push({ kind: 'note', depth: 0, key: 'none', text: 'No subjects yet. Click Refresh later.' });
|
|
234
|
+
for (const p of pkgs) {
|
|
235
|
+
const pk = pkgKey(p.package);
|
|
236
|
+
rows.push({ kind: 'package', depth: 0, key: pk, pkg: p.package, node: p, open: this.expanded.has(pk) });
|
|
237
|
+
if (!this.expanded.has(pk)) continue;
|
|
238
|
+
for (const b of p.branches || []) {
|
|
239
|
+
const bk = branchKey(p.package, b.name, b.repo);
|
|
240
|
+
const open = this.expanded.has(bk);
|
|
241
|
+
rows.push({ kind: 'branch', depth: 1, key: bk, pkg: p.package, branch: b.name, repo: b.repo, node: b, open });
|
|
242
|
+
if (open) this.listRows(rows, this.lists.get(bk), 2, false);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
flatRows(rows) {
|
|
248
|
+
this.listRows(rows, this.flat, 1, true);
|
|
249
|
+
if (!this.flat.loading && !this.flat.error && !this.flat.items.length) {
|
|
250
|
+
rows.push({ kind: 'note', depth: 0, key: 'nomatch', text: 'No subject matches the filter.' });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
listRows(rows, list, depth, grouped) {
|
|
255
|
+
if (!list) return;
|
|
256
|
+
let group = null;
|
|
257
|
+
for (const s of list.items) {
|
|
258
|
+
if (grouped) {
|
|
259
|
+
const g = `${s.package}${SEP}${s.branch ?? ''}`;
|
|
260
|
+
if (g !== group) {
|
|
261
|
+
group = g;
|
|
262
|
+
rows.push({ kind: 'group', depth: 0, key: `g${SEP}${g}`, text: s.branch ? `${s.package} / ${s.branch}` : s.package });
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const sk = subjectKey(s.package, s.id);
|
|
266
|
+
const open = this.expanded.has(sk);
|
|
267
|
+
rows.push({ kind: 'subject', depth, key: sk, pkg: s.package, item: s, open });
|
|
268
|
+
if (!open) continue;
|
|
269
|
+
const entry = this.files.get(sk);
|
|
270
|
+
if (!entry || (!entry.files && !entry.error)) {
|
|
271
|
+
rows.push({ kind: 'note', depth: depth + 1, key: `${sk}${SEP}loading`, text: 'Loading files...' });
|
|
272
|
+
} else if (entry.error) {
|
|
273
|
+
rows.push({ kind: 'note', depth: depth + 1, key: `${sk}${SEP}error`, text: entry.error, error: true });
|
|
274
|
+
} else if (!entry.files.length) {
|
|
275
|
+
rows.push({ kind: 'note', depth: depth + 1, key: `${sk}${SEP}empty`, text: 'No isolable diff' });
|
|
276
|
+
} else {
|
|
277
|
+
for (const f of entry.files) {
|
|
278
|
+
rows.push({ kind: 'file', depth: depth + 1, key: `f${SEP}${s.package}${SEP}${s.id}${SEP}${f.path}`, pkg: s.package, item: s, file: f });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const key = `m${SEP}${JSON.stringify(list.params)}`;
|
|
283
|
+
if (list.error) rows.push({ kind: 'note', depth, key: `${key}e`, text: list.error, error: true });
|
|
284
|
+
else if (list.loading) rows.push({ kind: 'note', depth, key: `${key}l`, text: 'Loading...' });
|
|
285
|
+
else if (list.total != null && list.items.length < list.total) {
|
|
286
|
+
rows.push({ kind: 'more', depth, key, list, text: `Load ${list.total - list.items.length} more` });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/* Drawing */
|
|
291
|
+
|
|
292
|
+
measure() {
|
|
293
|
+
const probe = this.rowEl({ kind: 'note', depth: 0, key: 'probe', text: 'M' }, 0);
|
|
294
|
+
probe.style.visibility = 'hidden';
|
|
295
|
+
this.win.append(probe);
|
|
296
|
+
this.rowH = probe.getBoundingClientRect().height || 24;
|
|
297
|
+
probe.remove();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Call after the UI font size changes. */
|
|
301
|
+
remeasure() {
|
|
302
|
+
this.rowH = 0;
|
|
303
|
+
this.drawn = [-1, -1];
|
|
304
|
+
this.schedule();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
draw() {
|
|
308
|
+
if (!this.rowH) this.measure();
|
|
309
|
+
const top = this.el.scrollTop;
|
|
310
|
+
const start = Math.max(0, Math.floor(top / this.rowH));
|
|
311
|
+
const end = Math.min(this.rows.length, Math.ceil((top + this.viewH) / this.rowH) + 1);
|
|
312
|
+
this.spacer.style.height = `${this.rows.length * this.rowH}px`;
|
|
313
|
+
if (start === this.drawn[0] && end === this.drawn[1]) return;
|
|
314
|
+
this.drawn = [start, end];
|
|
315
|
+
this.win.style.transform = `translateY(${start * this.rowH}px)`;
|
|
316
|
+
const nodes = [];
|
|
317
|
+
for (let i = start; i < end; i++) {
|
|
318
|
+
const row = this.rows[i];
|
|
319
|
+
nodes.push(this.rowEl(row, i));
|
|
320
|
+
if (row.kind === 'more') this.loadMore(row.list);
|
|
321
|
+
}
|
|
322
|
+
this.win.replaceChildren(...nodes);
|
|
323
|
+
this.el.setAttribute('aria-activedescendant', this.focus >= start && this.focus < end ? `tr-${this.focus}` : '');
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
rowEl(row, i) {
|
|
327
|
+
const cls = ['row', `row-${row.kind}`];
|
|
328
|
+
if (i === this.focus) cls.push('focus');
|
|
329
|
+
if (row.key === this.activeKey) cls.push('active');
|
|
330
|
+
const expandable = row.kind === 'package' || row.kind === 'branch' || (row.kind === 'subject' && row.item.files_count > 0);
|
|
331
|
+
const el = h('div', {
|
|
332
|
+
id: `tr-${i}`,
|
|
333
|
+
class: cls.join(' '),
|
|
334
|
+
role: row.kind === 'group' || row.kind === 'note' ? 'presentation' : 'treeitem',
|
|
335
|
+
'aria-level': String(row.depth + 1),
|
|
336
|
+
'aria-expanded': expandable ? String(Boolean(row.open)) : null,
|
|
337
|
+
'aria-selected': row.key === this.activeKey ? 'true' : null,
|
|
338
|
+
dataset: { i: String(i) },
|
|
339
|
+
style: { paddingLeft: `calc(${row.depth} * 1.1em + 4px)` },
|
|
340
|
+
});
|
|
341
|
+
el.append(h('span', { class: 'caret', 'aria-hidden': 'true', text: expandable ? (row.open ? '▾' : '▸') : '' }));
|
|
342
|
+
if (row.kind === 'package' || row.kind === 'branch') {
|
|
343
|
+
const n = row.node;
|
|
344
|
+
const label = row.kind === 'branch' ? (n.name ?? '(no branch)') : row.pkg;
|
|
345
|
+
el.title = row.kind === 'branch' && n.repo ? `${label}\n${n.repo}` : label;
|
|
346
|
+
append(el,
|
|
347
|
+
h('span', { class: 'name', text: label }),
|
|
348
|
+
h('span', { class: 'count', text: `${reviewedOf(n)}/${n.total}` }),
|
|
349
|
+
statusBar(n.by_status, n.total),
|
|
350
|
+
);
|
|
351
|
+
} else if (row.kind === 'subject') {
|
|
352
|
+
const s = row.item;
|
|
353
|
+
el.title = `${s.id}: ${s.title}\n${STATUS_LABEL[s.status] || s.status}${s.edited ? ', edited' : ''}`;
|
|
354
|
+
append(el,
|
|
355
|
+
h('span', { class: 'sid', text: s.id }),
|
|
356
|
+
h('span', { class: 'name dim', text: s.title }),
|
|
357
|
+
s.edited ? h('span', { class: 'mark', text: 'edited' }) : null,
|
|
358
|
+
h('span', { class: 'count', text: s.status === 'pending' ? '0/1' : '1/1' }),
|
|
359
|
+
statusBar({ [s.status]: 1 }, 1),
|
|
360
|
+
);
|
|
361
|
+
} else if (row.kind === 'file') {
|
|
362
|
+
const f = row.file;
|
|
363
|
+
el.title = f.path;
|
|
364
|
+
append(el,
|
|
365
|
+
h('span', { class: 'name mono', text: f.path }),
|
|
366
|
+
f.edited ? h('span', { class: 'mark', text: 'edited' }) : null,
|
|
367
|
+
h('span', { class: 'count' }, h('span', { class: 'add', text: `+${f.lines_added ?? 0}` }), ' ', h('span', { class: 'del', text: `−${f.lines_deleted ?? 0}` })),
|
|
368
|
+
);
|
|
369
|
+
} else if (row.kind === 'group') {
|
|
370
|
+
el.append(h('span', { class: 'name group', text: row.text }));
|
|
371
|
+
} else {
|
|
372
|
+
el.append(h('span', { class: `name ${row.error ? 'error' : 'dim'}`, text: row.text }));
|
|
373
|
+
}
|
|
374
|
+
return el;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
scrollTo(i) {
|
|
378
|
+
if (!this.rowH) this.measure();
|
|
379
|
+
const top = i * this.rowH;
|
|
380
|
+
const view = this.viewH || this.el.clientHeight;
|
|
381
|
+
if (top < this.el.scrollTop) this.el.scrollTop = top;
|
|
382
|
+
else if (top + this.rowH > this.el.scrollTop + view) this.el.scrollTop = top + this.rowH - view;
|
|
383
|
+
this.drawn = [-1, -1];
|
|
384
|
+
this.schedule();
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/* Input */
|
|
388
|
+
|
|
389
|
+
activate(row) {
|
|
390
|
+
if (!row) return;
|
|
391
|
+
// Mark the target at once, so a quick second j or k steps on from it.
|
|
392
|
+
if (row.kind === 'subject' || row.kind === 'file') this.setActive(row.pkg, row.item.id);
|
|
393
|
+
if (row.kind === 'subject') this.hooks.onOpen({ id: row.item.id, package: row.pkg, branch: row.item.branch });
|
|
394
|
+
else if (row.kind === 'file') this.hooks.onOpen({ id: row.item.id, package: row.pkg, branch: row.item.branch, path: row.file.path });
|
|
395
|
+
else if (row.kind === 'more') this.loadMore(row.list);
|
|
396
|
+
else if (row.kind === 'package' || row.kind === 'branch') {
|
|
397
|
+
if (row.open) this.collapse(row);
|
|
398
|
+
else this.expand(row);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
onClick(e) {
|
|
403
|
+
const rowEl = e.target.closest('.row');
|
|
404
|
+
if (!rowEl) return;
|
|
405
|
+
const i = Number(rowEl.dataset.i);
|
|
406
|
+
const row = this.rows[i];
|
|
407
|
+
if (!row || row.kind === 'note' || row.kind === 'group') return;
|
|
408
|
+
this.focus = i;
|
|
409
|
+
if (e.target.closest('.caret') && row.kind === 'subject' && row.item.files_count > 0) {
|
|
410
|
+
if (row.open) this.collapse(row);
|
|
411
|
+
else this.expand(row);
|
|
412
|
+
} else {
|
|
413
|
+
this.activate(row);
|
|
414
|
+
}
|
|
415
|
+
this.drawn = [-1, -1];
|
|
416
|
+
this.schedule();
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
moveFocus(i) {
|
|
420
|
+
if (!this.rows.length) return;
|
|
421
|
+
this.focus = Math.max(0, Math.min(this.rows.length - 1, i));
|
|
422
|
+
this.scrollTo(this.focus);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
onKey(e) {
|
|
426
|
+
if (e.metaKey || e.ctrlKey || e.altKey) return;
|
|
427
|
+
const row = this.rows[this.focus];
|
|
428
|
+
const page = Math.max(1, Math.floor((this.viewH || this.el.clientHeight) / (this.rowH || 24)));
|
|
429
|
+
switch (e.key) {
|
|
430
|
+
case 'ArrowDown': this.moveFocus(this.focus + 1); break;
|
|
431
|
+
case 'ArrowUp': this.moveFocus(this.focus - 1); break;
|
|
432
|
+
case 'PageDown': this.moveFocus(this.focus + page); break;
|
|
433
|
+
case 'PageUp': this.moveFocus(this.focus - page); break;
|
|
434
|
+
case 'Home': this.moveFocus(0); break;
|
|
435
|
+
case 'End': this.moveFocus(this.rows.length - 1); break;
|
|
436
|
+
case 'ArrowRight':
|
|
437
|
+
if (row && !row.open && (row.kind === 'package' || row.kind === 'branch' || (row.kind === 'subject' && row.item.files_count > 0))) this.expand(row);
|
|
438
|
+
else this.moveFocus(this.focus + 1);
|
|
439
|
+
break;
|
|
440
|
+
case 'ArrowLeft':
|
|
441
|
+
if (row?.open) this.collapse(row);
|
|
442
|
+
else if (row) {
|
|
443
|
+
for (let i = this.focus - 1; i >= 0; i--) {
|
|
444
|
+
if (this.rows[i].depth < row.depth && this.rows[i].kind !== 'group') {
|
|
445
|
+
this.moveFocus(i);
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
break;
|
|
451
|
+
case 'Enter':
|
|
452
|
+
case ' ':
|
|
453
|
+
this.activate(row);
|
|
454
|
+
break;
|
|
455
|
+
default:
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
e.preventDefault();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** Open the next (`dir` = 1) or previous (`dir` = -1) subject, expanding groups on the way. */
|
|
462
|
+
async step(dir) {
|
|
463
|
+
let i = this.rows.findIndex((r) => r.key === this.activeKey);
|
|
464
|
+
if (i < 0) i = dir > 0 ? -1 : this.rows.length;
|
|
465
|
+
for (;;) {
|
|
466
|
+
i += dir;
|
|
467
|
+
if (i < 0 || i >= this.rows.length) return;
|
|
468
|
+
const row = this.rows[i];
|
|
469
|
+
if (row.kind === 'subject') {
|
|
470
|
+
this.focus = i;
|
|
471
|
+
this.scrollTo(i);
|
|
472
|
+
this.activate(row);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if ((row.kind === 'package' || row.kind === 'branch') && !row.open) {
|
|
476
|
+
await this.expand(row);
|
|
477
|
+
const at = this.rows.findIndex((r) => r.key === row.key);
|
|
478
|
+
if (dir > 0) i = at;
|
|
479
|
+
else {
|
|
480
|
+
let end = at + 1;
|
|
481
|
+
while (end < this.rows.length && this.rows[end].depth > row.depth) end++;
|
|
482
|
+
i = end;
|
|
483
|
+
}
|
|
484
|
+
} else if (row.kind === 'more' && dir > 0) {
|
|
485
|
+
const before = this.rows.length;
|
|
486
|
+
await this.loadMore(row.list);
|
|
487
|
+
if (this.rows.length === before) return;
|
|
488
|
+
i -= dir;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|