@popcorn245/cornfield 0.55.0 → 0.56.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.
Files changed (39) hide show
  1. package/core/contrast.js +12 -1
  2. package/core/schema.js +6 -0
  3. package/core/strings.js +0 -1
  4. package/explorer/css/page.css +0 -8
  5. package/explorer/css/work.css +3 -26
  6. package/explorer/deep-link.js +11 -24
  7. package/explorer/engine/map-style.js +4 -1
  8. package/explorer/forge-panel-model.js +2 -36
  9. package/explorer/forge-panel.js +3 -8
  10. package/explorer/index.html +1 -10
  11. package/explorer/instance-state.js +0 -6
  12. package/explorer/instance.js +9 -5
  13. package/explorer/page.js +5 -4
  14. package/explorer/pieces/node-panel.js +9 -5
  15. package/explorer/pieces/work-agent.js +3 -2
  16. package/explorer/pieces/work-common.js +14 -15
  17. package/explorer/pieces/work-confirm.js +11 -10
  18. package/explorer/pieces/work-data.js +24 -31
  19. package/explorer/pieces/work-deploys.js +42 -41
  20. package/explorer/pieces/work-issues.js +32 -29
  21. package/explorer/pieces/work-list.js +406 -0
  22. package/explorer/pieces/work-markup.js +9 -14
  23. package/explorer/pieces/work-notes.js +0 -1
  24. package/explorer/pieces/work-paint.js +57 -62
  25. package/explorer/pieces/work-prs.js +25 -66
  26. package/explorer/pieces/work-runs.js +47 -57
  27. package/explorer/pieces/work-specs.js +19 -2
  28. package/explorer/pieces/work-threads.js +28 -48
  29. package/explorer/pieces/work.js +28 -40
  30. package/explorer/proposal-model.js +5 -5
  31. package/explorer/runs-view.js +10 -18
  32. package/explorer/scene.js +1 -3
  33. package/explorer/tokens.css +4 -0
  34. package/explorer/waiting-view.js +3 -3
  35. package/explorer/work-model.js +79 -38
  36. package/explorer/work-view.css +3 -4
  37. package/explorer/work-view.js +77 -49
  38. package/package.json +1 -1
  39. package/explorer/pieces/work-events.js +0 -285
@@ -1,285 +0,0 @@
1
- /**
2
- * @module explorer/pieces/work-events
3
- *
4
- * Opening and closing the panel, and what a click, a change, an input and a key in it do. Part of the Work piece (pieces/work.js): `install(ctx)` makes this part's functions for one mount, and hands the ones other parts call
5
- * to `ctx.fn`; nothing is shared between two mounts.
6
- */
7
-
8
- import { workStatus } from '../agents-model.js';
9
- import { defaultFilters, filterItems } from '../forge-panel-model.js';
10
- import { waiting, specGroups } from '../waiting-model.js';
11
- import { plural, TABS, SEARCH_ANNOUNCE_MS } from './work-common.js';
12
-
13
- export function install(ctx) {
14
- const { inst, ui, m, fn, state, $ } = ctx;
15
- const { announce, t, isPhone, expandSheet, collapseSheet, showSheet, nodeById, selectNode, clearResult, resultOf, showResultIn, setT, clearT } = ctx.h;
16
-
17
- const isForgeOpen = () => ui.open;
18
-
19
- /**
20
- * Opens the panel with the focus on its title; the first time, loads what its tab shows (the proposals, to start with).
21
- * `tab` opens it on that tab ('specs', 'pulls', 'issues', 'threads', 'work' for Runs, 'deploys'), whichever was shown last otherwise.
22
- */
23
- function openForge({ load = true, tab } = {}) {
24
- const panel = $('forge-panel');
25
- if (!panel || panel.hidden) return;
26
- if (tab && tab !== (ui.kind === 'notes' ? 'pulls' : ui.kind) && TABS.includes(tab)) { // the Release notes are one level down on PRs
27
- ui.kind = tab;
28
- ui.filters = defaultFilters(tab);
29
- ui.actNote = null;
30
- } else if (!tab && load && !ui.open) {
31
- // Opened by a toggle: on the tab with the oldest thing waiting on you, else the tab used last (spec 0010 D2)
32
- const oldest = fn.waitingNow().oldest;
33
- if (oldest && oldest !== ui.kind) {
34
- ui.kind = oldest;
35
- ui.filters = defaultFilters(oldest);
36
- ui.actNote = null;
37
- fn.paintFilters();
38
- }
39
- }
40
- ui.open = true;
41
- panel.inert = false;
42
- panel.classList.add('forge-open');
43
- if (isPhone()) { showSheet('forge'); if (tab) expandSheet('forge'); } // a peek; only a link that names a tab (a deep link, "Open the Specs list") opens it expanded
44
- fn.paintButton();
45
- const title = $('forge-title');
46
- title.focus();
47
- announce('Work');
48
- if (!load) return; // a deep link loads the list it wants itself (openTab)
49
- if (!tab) fn.primeCounts(); // opened by a toggle, not for a tab: the other tabs' counts are read quietly
50
- if (ui.kind === 'notes') { if (!ui.notes.data && !ui.notes.loading) fn.loadNotes(); else fn.paint(); return; }
51
- if (ui.kind === 'specs' || !fn.current()) { fn.paintFilters(); fn.loadList(); } else fn.paint();
52
- }
53
-
54
- /** Shows `tab` in the panel, opened (and, on a phone, expanded), with its list read; resolves when the list is in */
55
- async function openTab(tab) {
56
- ui.kind = tab;
57
- ui.filters = defaultFilters(tab); // a filter left from before must not hide what the link names
58
- ui.actNote = null;
59
- fn.paintFilters();
60
- if (!ui.open) openForge({ load: false });
61
- if (isPhone()) expandSheet('forge');
62
- if (fn.current()) fn.paint(); else await fn.loadList();
63
- }
64
-
65
- /** What a link names is not there: a line in the panel, said through the live region */
66
- function linkMissing(words) {
67
- ui.actNote = { ok: false, text: words };
68
- fn.paint();
69
- announce(words);
70
- return false;
71
- }
72
-
73
- /** Moves the focus to `el` (made focusable if it is a row) and brings it into view */
74
- function bringIntoView(el) {
75
- if (!el) return;
76
- if (!el.matches('button, a, input, select, textarea')) el.setAttribute('tabindex', '-1');
77
- el.focus();
78
- if (typeof el.scrollIntoView === 'function') el.scrollIntoView({ block: 'nearest' });
79
- }
80
-
81
- /** Closes the panel. What a selected pull request lit stays lit (the button says which); Clear lets go of it. */
82
- function closeForge({ restoreFocus = true } = {}) {
83
- const panel = $('forge-panel');
84
- if (!panel || !ui.open) return;
85
- const hadFocus = panel.contains(inst.active());
86
- ui.open = false;
87
- panel.classList.remove('forge-open');
88
- panel.inert = true;
89
- collapseSheet('forge');
90
- fn.paintButton();
91
- const back = m.openerEl && m.openerEl.isConnected ? m.openerEl : $('forge-btn');
92
- if (restoreFocus && hadFocus && back) back.focus();
93
- announce('Work closed');
94
- }
95
-
96
- const toggleForge = () => (ui.open ? closeForge() : openForge());
97
-
98
- /** After a filter changes: the list again, and how many it holds */
99
- function filtersChanged(announceNow = true) {
100
- fn.paint();
101
- const list = fn.current();
102
- if (announceNow && list && ui.kind === 'work') announce(workStatus(fn.groupsShown(), '', m.now()));
103
- else if (announceNow && list) announce(`${filterItems(list.items, ui.kind, ui.filters).length} of ${plural(list.items.length, fn.kindWords())} shown`);
104
- }
105
-
106
- function onClick(e) {
107
- const t = e.target;
108
- if (!t.closest) return;
109
- const kind = t.closest('[data-forge-kind]');
110
- if (kind) {
111
- if (kind.dataset.forgeKind === ui.kind) return;
112
- ui.kind = kind.dataset.forgeKind;
113
- ui.actNote = null;
114
- ui.filters = defaultFilters(ui.kind);
115
- fn.paintFilters();
116
- // The proposals are asked for again each time (worktrees come and go); the other lists keep what they have
117
- if (ui.kind === 'specs') { fn.paint(); fn.loadList(false, true); announce(fn.current() ? `${plural(fn.current().items.length, 'spec')} shown` : 'Looking for proposals'); } else if (fn.current()) filtersChanged(); else { fn.paint(); fn.loadList(); }
118
- return;
119
- }
120
- const fold = t.closest('[data-spec-group-toggle]');
121
- if (fold) {
122
- // Drafts folded behind their header, opened by hand and folded again; the focus stays on the header (findAgain)
123
- const drafts = specGroups(fn.specsList() ? fn.specsList().items : [], { query: ui.specQuery }).find((g) => g.key === 'drafts');
124
- const folded = ui.draftsOpen === null ? !!(drafts && drafts.collapsed) : !ui.draftsOpen;
125
- ui.draftsOpen = folded;
126
- fn.paint();
127
- return;
128
- }
129
- const pr = t.closest('[data-forge-pr]');
130
- if (pr) {
131
- const n = Number(pr.dataset.forgePr);
132
- m.returnTo = fn.findAgain(pr); // the row to give the focus back to when the selection is let go of
133
- if (ui.selected === n) fn.clearPull(); else fn.selectPull(n);
134
- return;
135
- }
136
- const thr = t.closest('[data-forge-thread]');
137
- if (thr) {
138
- const n = Number(thr.dataset.forgeThread);
139
- m.returnTo = fn.findAgain(thr);
140
- if (ui.thread === n) fn.clearThread(); else fn.selectThread(n);
141
- return;
142
- }
143
- const dep = t.closest('[data-forge-deploy]');
144
- if (dep) {
145
- m.returnTo = fn.findAgain(dep);
146
- if (ui.deploy === dep.dataset.forgeDeploy) fn.clearDeploy(); else fn.selectDeploy(dep.dataset.forgeDeploy);
147
- return;
148
- }
149
- const nodeBtn = t.closest('[data-forge-node]');
150
- if (nodeBtn) {
151
- const node = nodeById(nodeBtn.dataset.forgeNode);
152
- if (!node) return;
153
- selectNode(node, { frame: true });
154
- if (isPhone()) collapseSheet('forge'); // the map and the node's sheet are what is wanted now
155
- announce(`${node.label}, ${node.type}`);
156
- return;
157
- }
158
- const agent = t.closest('[data-forge-agent]');
159
- if (agent) { fn.openAgent(agent.dataset.forgeAgent, `[data-forge-agent="${agent.dataset.forgeAgent}"]`); return; }
160
- const stop = t.closest('[data-forge-stop]');
161
- if (stop) { fn.stopRun(stop.dataset.forgeStop); return; }
162
- const retry = t.closest('[data-forge-retry]');
163
- if (retry) { fn.startAgain(retry.dataset.forgeRetry); return; }
164
- const goto = t.closest('[data-run-goto]');
165
- if (goto) { fn.goToRun(goto.dataset.runGoto); return; }
166
- const answer = t.closest('[data-run-answer]');
167
- if (answer) { fn.answerRun(answer.dataset.runId, answer.dataset.runAnswer); return; }
168
- const discard = t.closest('[data-run-discard]');
169
- if (discard) { fn.discardReply(discard.dataset.runDiscard); return; }
170
- const pick = t.closest('[data-run-select]');
171
- if (pick) { fn.selectRun(pick.dataset.runSelect); return; }
172
- const timeline = t.closest('[data-run-timeline]');
173
- if (timeline) { fn.toggleTimeline(timeline.dataset.runTimeline); return; }
174
- const unland = t.closest('[data-forge-landing-cancel]');
175
- if (unland) { fn.cancelLanding(Number(unland.dataset.forgeLandingCancel)); return; }
176
- const merge = t.closest('[data-forge-merge]');
177
- if (merge) { fn.openConfirm('[data-forge-merge]'); return; }
178
- const spec = t.closest('[data-forge-spec]');
179
- if (spec) { fn.askPlan('spec', Number(spec.dataset.forgeSpec), null, `[data-forge-spec="${spec.dataset.forgeSpec}"]`); return; }
180
- const build = t.closest('[data-forge-build]');
181
- if (build && ui.selected !== null) { fn.askPlan('build', ui.selected, build.dataset.forgeBuild, `[data-forge-build="${build.dataset.forgeBuild}"]`); return; }
182
- const rerun = t.closest('[data-forge-rerun]');
183
- if (rerun) { fn.rerunCheck(rerun.dataset.forgeRerun); return; }
184
- const action = t.closest('[data-action]');
185
- if (!action) return;
186
- if (action.dataset.action === 'close-forge') closeForge();
187
- else if (action.dataset.action === 'refresh-forge' || action.dataset.action === 'retry-forge') fn.refreshForge();
188
- else if (action.dataset.action === 'clear-specs-search') {
189
- ui.specQuery = '';
190
- const box = $('specs-search');
191
- if (box) { box.value = ''; }
192
- fn.paint();
193
- announce(fn.specsShownWords());
194
- if (box) box.focus();
195
- }
196
- else if (action.dataset.action === 'copy-notes') fn.copyNotes();
197
- else if (action.dataset.action === 'post-notes') { if (ui.notes.confirm) fn.closeNotesConfirm(); else fn.openNotesConfirm(); }
198
- else if (action.dataset.action === 'confirm-notes') fn.postDraft();
199
- else if (action.dataset.action === 'cancel-notes') { fn.closeNotesConfirm(); announce('Cancelled. Nothing was posted.'); }
200
- else if (action.dataset.action === 'clear-forge-pr') fn.clearPull();
201
- else if (action.dataset.action === 'clear-forge-deploy') fn.clearDeploy();
202
- else if (action.dataset.action === 'clear-forge-thread') fn.clearThread();
203
- else if (action.dataset.action === 'toggle-filters') { ui.filtersOpen = !ui.filtersOpen; fn.paintChip(); }
204
- else if (action.dataset.action === 'open-notes') fn.openNotes();
205
- else if (action.dataset.action === 'close-notes') fn.closeNotes();
206
- else if (action.dataset.action === 'open-proposal' && isPhone()) collapseSheet('forge'); // the proposal's own bar and the map are what is wanted now
207
- else if (action.dataset.action === 'idea-open') fn.toggleIdea(!ui.idea.open);
208
- else if (action.dataset.action === 'idea-send') {
209
- // Nothing of it may escape as an unhandled rejection: what went wrong is said, and the form is usable again
210
- fn.sendIdea().catch((err) => {
211
- ui.idea.busy = false;
212
- ui.idea.message = `Something went wrong in the page: ${err instanceof Error ? err.message : err}`;
213
- ui.idea.bad = true;
214
- fn.paintIdea();
215
- announce(ui.idea.message);
216
- });
217
- }
218
- else if (action.dataset.action === 'idea-cancel') { fn.toggleIdea(false); announce('Cancelled. Nothing was opened.'); }
219
- }
220
-
221
- function onChange(e) {
222
- const id = e.target.id;
223
- if (id === 'notes-since') {
224
- ui.notes.since = e.target.value;
225
- ui.notes.message = '';
226
- fn.loadNotes();
227
- } else if (id === 'forge-state') {
228
- ui.filters.state = e.target.value;
229
- fn.paintFilters();
230
- if (fn.current()) filtersChanged(); else { fn.paint(); fn.loadList(); }
231
- } else if (id === 'forge-work-agents' || id === 'forge-work-finished') {
232
- if (id === 'forge-work-agents') ui.workFilters.agentsOnly = e.target.checked;
233
- else ui.workFilters.finished = e.target.checked;
234
- fn.paint();
235
- announce(workStatus(fn.groupsShown(), '', m.now()));
236
- } else if (id === 'forge-label') {
237
- ui.filters.label = e.target.value;
238
- filtersChanged();
239
- } else if (id === 'forge-author') {
240
- ui.filters.author = e.target.value;
241
- filtersChanged();
242
- }
243
- }
244
-
245
- function onInput(e) {
246
- if (e.target.dataset && e.target.dataset.runReply) {
247
- const id = e.target.dataset.runReply;
248
- ui.runReplies.set(id, e.target.value);
249
- // "Write a reply first" goes once something is written: a refusal does not outlive what it was about
250
- const said = resultOf(id);
251
- if (said && !said.ok && e.target.value.trim()) { clearResult(id); showResultIn(e.target.closest('[data-run]') && e.target.closest('[data-run]').querySelector(`[data-run-result="${id}"]`), id); }
252
- return;
253
- }
254
- if (e.target.id === 'specs-search') {
255
- ui.specQuery = e.target.value;
256
- fn.paint();
257
- clearT(m.searchTimer);
258
- m.searchTimer = setT(() => announce(fn.specsShownWords()), SEARCH_ANNOUNCE_MS);
259
- return;
260
- }
261
- if (e.target.id !== 'forge-text') return;
262
- ui.filters.text = e.target.value;
263
- filtersChanged(false);
264
- clearT(m.searchTimer);
265
- m.searchTimer = setT(() => filtersChanged(), SEARCH_ANNOUNCE_MS);
266
- }
267
-
268
- /** Escape anywhere in the panel closes it, and the button has the focus again (a field's own Escape comes first) */
269
- function onKey(e) {
270
- if (e.key === 'Enter' && e.target.dataset && e.target.dataset.runReply && !e.defaultPrevented) { e.preventDefault(); fn.answerRun(e.target.dataset.runReply, 'reply'); return; }
271
- if (e.key === 'Enter' && e.target.id === 'notes-tag' && !e.defaultPrevented) { e.preventDefault(); fn.postDraft(); return; }
272
- if (e.key === 'Escape' && !e.defaultPrevented && ui.notes.confirm && e.target.closest && e.target.closest('#notes-confirm')) {
273
- e.preventDefault();
274
- fn.closeNotesConfirm();
275
- announce('Cancelled. Nothing was posted.');
276
- return;
277
- }
278
- if (e.key !== 'Escape' || e.defaultPrevented) return;
279
- if (e.target.closest && e.target.closest('select, input, textarea')) return;
280
- e.preventDefault();
281
- closeForge();
282
- }
283
-
284
- Object.assign(fn, { isForgeOpen, openForge, openTab, linkMissing, bringIntoView, closeForge, toggleForge, filtersChanged, onClick, onChange, onInput, onKey });
285
- }