@popcorn245/cornfield 0.54.0 → 0.55.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/core/contrast.js +17 -0
- package/core/schema.js +18 -0
- package/core/strings.js +1 -0
- package/explorer/engine/layers.js +5 -2
- package/explorer/engine/map-style.js +5 -1
- package/explorer/engine/render.js +2 -1
- package/explorer/forge-panel.js +1 -0
- package/explorer/index.html +6 -3
- package/explorer/layer-model.js +1 -0
- package/explorer/page.js +3 -1
- package/explorer/pieces/layers.js +1 -1
- package/explorer/pieces/node-panel.js +18 -0
- package/explorer/pieces/search.js +9 -3
- package/explorer/pieces/work-markup.js +2 -3
- package/explorer/pieces/work-paint.js +3 -8
- package/explorer/pieces/work-threads.js +2 -2
- package/explorer/pieces/work.js +12 -0
- package/explorer/scene.js +17 -8
- package/explorer/search-match.js +3 -2
- package/explorer/tokens.css +7 -0
- package/explorer/view.js +8 -1
- package/explorer/work-model.js +681 -0
- package/explorer/work-view.css +51 -0
- package/explorer/work-view.js +542 -0
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* The Work view (explorer/work-view.js, spec 0012): the toggle at the top left of the stage, the line of what could not be read, and the node panel's work detail. */
|
|
2
|
+
.hx-work-bar { position: absolute; z-index: 4; left: var(--corn-space-4); top: var(--corn-space-4); display: flex; gap: var(--corn-space-2); }
|
|
3
|
+
.hx-work-bar { align-items: center; }
|
|
4
|
+
.hx-work-bar[hidden] { display: none; }
|
|
5
|
+
.hx-work-chip { box-sizing: border-box; min-height: 2rem; padding: 0 var(--corn-space-4); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); background: var(--corn-surface-1); color: var(--corn-text-2); font-family: inherit; font-size: var(--corn-text-xs); font-weight: 600; cursor: pointer; }
|
|
6
|
+
.hx-work-chip[aria-pressed="true"] { background: var(--corn-accent); border-color: var(--corn-accent); color: var(--corn-text-on-accent); }
|
|
7
|
+
.hx-work-chip:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: var(--corn-focus-offset); }
|
|
8
|
+
.hx-work-note { position: absolute; z-index: 3; left: var(--corn-space-4); bottom: var(--corn-space-4); max-width: min(32rem, calc(100% - var(--corn-space-8))); margin: 0; padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius); background: var(--corn-surface-1); color: var(--corn-text-2); font-size: var(--corn-text-xs); }
|
|
9
|
+
.hx-work-note[hidden] { display: none; }
|
|
10
|
+
.hx-view-badge { margin-left: var(--corn-space-2); }
|
|
11
|
+
.hx-work-links { list-style: none; margin: 0; padding: 0; }
|
|
12
|
+
.hx-work-links li { display: flex; align-items: center; gap: var(--corn-space-2); min-height: 2.25rem; border-bottom: var(--corn-border) solid var(--corn-line); }
|
|
13
|
+
.hx-work-rel { flex: none; width: 6.5rem; color: var(--corn-text-3); font-size: var(--corn-text-xs); }
|
|
14
|
+
.hx-work-dot { flex: none; width: 0.6rem; height: 0.6rem; border-radius: var(--corn-radius-sm); background: var(--corn-text-3); }
|
|
15
|
+
.hx-work-head, .hx-work-actions { display: flex; flex-direction: column; gap: var(--corn-space-2); margin: var(--corn-space-3) 0; }
|
|
16
|
+
.hx-work-pills { display: flex; flex-wrap: wrap; gap: var(--corn-space-2); margin: 0; }
|
|
17
|
+
.hx-work-actions .hx-foot-btn { align-self: flex-start; }
|
|
18
|
+
/* The lanes' titles: lines over the map, in screen space (work-view.js `paintLanes`), so they read at any zoom */
|
|
19
|
+
.hx-work-lanes { position: absolute; inset: 0; z-index: 2; overflow: hidden; pointer-events: none; }
|
|
20
|
+
.hx-work-lanes[hidden] { display: none; }
|
|
21
|
+
.hx-work-lane-title { position: absolute; display: flex; gap: var(--corn-space-2); align-items: baseline; max-width: 100%; overflow: hidden; white-space: nowrap; font-size: var(--corn-text-xs); font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--corn-text-2); }
|
|
22
|
+
.hx-work-lane-title.is-held { padding: 0 var(--corn-space-2); border-radius: var(--corn-radius-sm); background: color-mix(in srgb, var(--corn-surface-1) 85%, transparent); } /* held under the toggles over the lane's nodes: a ground of its own */
|
|
23
|
+
.hx-work-lane-title > :first-child { overflow: hidden; text-overflow: ellipsis; }
|
|
24
|
+
.hx-work-lane-count { flex: none; font-weight: 600; letter-spacing: 0; }
|
|
25
|
+
.hx-work-busy { margin-left: var(--corn-space-2); font-size: var(--corn-text-xs); color: var(--corn-text-2); }
|
|
26
|
+
.hx-work-busy[hidden] { display: none; }
|
|
27
|
+
/* While the first answer is on its way: the lanes, empty, with the words; nothing on the page waits for it */
|
|
28
|
+
.hx-work-loading { position: absolute; z-index: 2; inset: 0; pointer-events: none; }
|
|
29
|
+
.hx-work-loading[hidden] { display: none; }
|
|
30
|
+
.hx-work-skeleton { position: absolute; left: var(--corn-space-4); right: var(--corn-space-4); top: 3.5rem; bottom: var(--corn-space-6); display: grid; grid-template-columns: repeat(4, 1fr) 1.6fr; gap: var(--corn-space-3); }
|
|
31
|
+
.hx-work-skel-lane { display: flex; flex-direction: column; gap: var(--corn-space-4); padding: var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius); background: color-mix(in srgb, var(--corn-surface-1) 55%, transparent); }
|
|
32
|
+
.hx-work-skel-lane .hx-work-lane-title { position: static; }
|
|
33
|
+
.hx-work-skel-lane i { display: block; height: 2.25rem; border-radius: var(--corn-radius-sm); background: var(--corn-surface-3); opacity: 0.7; animation: hx-work-pulse 1.6s ease-in-out infinite; }
|
|
34
|
+
.hx-work-skel-lane i:nth-of-type(2) { animation-delay: 0.2s; width: 80%; }
|
|
35
|
+
.hx-work-skel-lane i:nth-of-type(3) { animation-delay: 0.4s; width: 65%; }
|
|
36
|
+
.hx-work-skel-lane i:nth-of-type(4) { animation-delay: 0.6s; width: 90%; }
|
|
37
|
+
@keyframes hx-work-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.8; } }
|
|
38
|
+
@media (prefers-reduced-motion: reduce) { .hx-work-skel-lane i { animation: none; opacity: 0.6; } }
|
|
39
|
+
.hx-work-loading-text { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(26rem, calc(100% - var(--corn-space-8))); margin: 0; padding: var(--corn-space-3) var(--corn-space-4); border-radius: var(--corn-radius); border: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-1); color: var(--corn-text); font-size: var(--corn-text-sm); text-align: center; box-shadow: var(--corn-shadow); }
|
|
40
|
+
@container corn-box (max-width: 767px) {
|
|
41
|
+
/* The Layers chip and Fit sit on the map's top row (layers.css, header.css); the toggles go on the row under them, and the lanes run top to bottom */
|
|
42
|
+
.hx-work-bar { top: calc(var(--corn-space-4) + var(--hx-control-h) + var(--corn-space-3)); }
|
|
43
|
+
.hx-work-note { bottom: var(--corn-space-4); }
|
|
44
|
+
.hx-stage.is-work .hx-hint { display: none; } /* the toggles' row is where the hint would sit */
|
|
45
|
+
.hx-work-skeleton { grid-template-columns: 1fr; grid-auto-rows: min-content; top: calc(var(--corn-space-4) + var(--hx-control-h) * 2 + var(--corn-space-6)); overflow: hidden; }
|
|
46
|
+
.hx-work-skel-lane i:nth-of-type(n + 3) { display: none; }
|
|
47
|
+
/* The header's own Work button (the panel, until step 3 of spec 0012 retires it) is not on a phone: the view switch's Work carries the badge */
|
|
48
|
+
.hx-work[data-corn="forge-button"] { display: none; }
|
|
49
|
+
}
|
|
50
|
+
/* The Layers menu in the Work view lists the Work view's rows; the map's keys (its kinds of line, the cloud's, the runs' and the proposal marks') are about the map */
|
|
51
|
+
body:has(.hx-stage.is-work) .hx-layers :is([data-corn="legend-key"], [data-corn="menu-section"]) { display: none; }
|
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/work-view
|
|
3
|
+
*
|
|
4
|
+
* The Work view in cornfield's page (spec 0012 D1 to D5 and D8); its pure half is work-model.js, the server's half `GET /api/forge/work-graph`
|
|
5
|
+
* (server/work-graph.js). Page code, as house.js is for the House view: it reads `location` and listens on `document`.
|
|
6
|
+
*
|
|
7
|
+
* initWorkView({ offered }) once, after the config: the Work button of the view switch (shown when the config names a forge), the toggle, the clicks
|
|
8
|
+
* openWork({ select }) opens the view (the camera fits), asks the server for the work graph (once; again on Refresh and on the poll the Work
|
|
9
|
+
* panel makes), and selects a node of it when `select` names one; closeWork() goes back to the map
|
|
10
|
+
* followWorkAddress() `?view=work`, `?pr=`, `?issue=`, `?run=`, `?thread=` and `?spec=` (work-model.js `workAddress`)
|
|
11
|
+
*
|
|
12
|
+
* What it puts on the page: the view switch's Work button, with "waiting on you" as its badge (the number the Work panel's button used to say, in the same
|
|
13
|
+
* words), the toggle at the top left of the stage ("All work" and "Waiting on you"), the lanes' titles in screen space (the map draws the lanes' panels), the words
|
|
14
|
+
* and the empty lanes shown at once while the first answer is on its way (the page stays usable: the views, the Layers menu, search), "Updating…" while a refresh
|
|
15
|
+
* is (the last answer stays on the map, and a refresh that fails keeps it and says so), the map's own card when the answer is refused (signed out, not a maintainer,
|
|
16
|
+
* offline: pieces/status.js), and a quiet line naming what the server could not read (`problems`). It answers the node panel's `work:panel` ask with what a node says in
|
|
17
|
+
* the Work view, and holds the keys of the view: N and P step through the lanes, an arrow goes to the nearest node that way. Every request goes through `credentialed`;
|
|
18
|
+
* every word that comes from the forge is escaped or set as text, every link goes through `safeUrl` (work-model.js).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { state, pageInstance } from './state.js';
|
|
22
|
+
import { setView } from './view.js';
|
|
23
|
+
import { closeDrawer } from './panels.js';
|
|
24
|
+
import { announce } from './engine/keyboard.js';
|
|
25
|
+
import { credentialed } from './engine/connection.js';
|
|
26
|
+
import { selectNode } from './engine/selection.js';
|
|
27
|
+
import { closeProposal } from './engine/proposal.js';
|
|
28
|
+
import { signInUrl } from './engine/source.js';
|
|
29
|
+
import { mapStyleOf, workToken } from './engine/map-style.js';
|
|
30
|
+
import { t } from './engine/strings.js';
|
|
31
|
+
import { mount as mountStatus } from './pieces/status.js';
|
|
32
|
+
import { fitGraphToViewport, fitPadding, onPaint, render } from './render.js';
|
|
33
|
+
import { isPhone } from './sheets.js';
|
|
34
|
+
import { WORK_KINDS, WORK_THEMES } from '../core/schema.js';
|
|
35
|
+
import { workButtonName } from './waiting-model.js';
|
|
36
|
+
import { stepFrom } from './keyboard-model.js';
|
|
37
|
+
import { checksWords, pullUrl } from './forge-panel-model.js';
|
|
38
|
+
import { RUNS_POLL_MS } from './pieces/work-common.js';
|
|
39
|
+
import { openWorkAt, openRunLink, openIssueLink } from './forge-panel.js';
|
|
40
|
+
import {
|
|
41
|
+
CODE_LAYER, DRAFT_LAYER, KIND_WORDS, applyFilters, arrowTarget, landingWords, applyWorkLayout, codePanelHtml, layerRowsOf, newWorkState, nodeForAddress, openedWords, panelOf, setWorkGraph, showWork, touchedBy, workAddress, workPanelHtml,
|
|
42
|
+
} from './work-model.js';
|
|
43
|
+
|
|
44
|
+
const GRAPH_URL = '/api/forge/work-graph';
|
|
45
|
+
const $ = (id) => document.getElementById(id);
|
|
46
|
+
|
|
47
|
+
let wired = false;
|
|
48
|
+
let offered = false;
|
|
49
|
+
let els = null; // { stage, bar, all, waiting, busy, note, lanes, loading }
|
|
50
|
+
let laneEls = []; // the lanes' titles on the stage, in screen space: [{ el, name, count }]
|
|
51
|
+
let laneKey = null; // the lanes they were made for
|
|
52
|
+
let offPaint = null;
|
|
53
|
+
let card = null; // the map's own card (pieces/status.js)
|
|
54
|
+
let timer = 0;
|
|
55
|
+
let seq = 0; // the answer that is waited for: an older one is dropped
|
|
56
|
+
let pullDetail = new Map(); // pull number -> { head, text } what the checks said of the head (the node panel's line)
|
|
57
|
+
let wasOn = false;
|
|
58
|
+
|
|
59
|
+
const inst = () => pageInstance();
|
|
60
|
+
const work = () => state.work || (state.work = newWorkState());
|
|
61
|
+
const on = () => state.view === 'work';
|
|
62
|
+
|
|
63
|
+
/** Starts the Work view's machinery. Nothing is asked of the server until the view opens. */
|
|
64
|
+
export function initWorkView(opts = {}) {
|
|
65
|
+
offered = opts.offered === true;
|
|
66
|
+
const btn = $('preset-work-btn');
|
|
67
|
+
if (btn) btn.hidden = !offered;
|
|
68
|
+
work();
|
|
69
|
+
mount();
|
|
70
|
+
if (!wired) {
|
|
71
|
+
wired = true;
|
|
72
|
+
const i = inst();
|
|
73
|
+
document.addEventListener('click', onClick);
|
|
74
|
+
document.addEventListener('keydown', onKey, true); // before the map's own keys: in this view N and P step through the lanes, and an arrow goes to the nearest node that way
|
|
75
|
+
i.on('view', syncWork);
|
|
76
|
+
i.on('layers', refilter);
|
|
77
|
+
i.on('work:open', ({ id }) => openWork({ select: id }));
|
|
78
|
+
i.on('search:more', () => (work().status === 'ok' && !on() ? work().nodes.filter((n) => n.work) : null));
|
|
79
|
+
i.on('work:waiting', ({ total }) => paintBadge(total));
|
|
80
|
+
i.on('work:panel', (node) => panelFor(node));
|
|
81
|
+
mapStyleOf(i).onChange(() => { if (on()) { state.workRows = layerRowsOf(work().nodes).map(themed); i.emit('layers:redraw'); } });
|
|
82
|
+
}
|
|
83
|
+
syncWork();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The Work button's badge and its spoken name: "Work, 3 waiting on you" (the Work panel's own words: waiting-model.js) */
|
|
87
|
+
function paintBadge(total) {
|
|
88
|
+
const btn = $('preset-work-btn');
|
|
89
|
+
if (!btn) return;
|
|
90
|
+
const n = Number.isFinite(total) ? total : 0;
|
|
91
|
+
const badge = btn.querySelector('[data-corn="waiting-badge"]');
|
|
92
|
+
if (badge) { badge.textContent = n ? String(n) : ''; badge.hidden = !n; }
|
|
93
|
+
btn.setAttribute('aria-label', workButtonName(t(inst(), 'issuesAndPrs'), n, (key) => t(inst(), key)));
|
|
94
|
+
if (els) paintBar();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// The page's parts
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
function mount() {
|
|
101
|
+
const stage = state.canvas ? state.canvas.parentElement : null;
|
|
102
|
+
if (!stage || (els && els.stage === stage && stage.contains(els.bar))) return;
|
|
103
|
+
const bar = document.createElement('div');
|
|
104
|
+
bar.className = 'hx-work-bar';
|
|
105
|
+
bar.dataset.corn = 'work-bar';
|
|
106
|
+
bar.setAttribute('role', 'group');
|
|
107
|
+
bar.setAttribute('aria-label', 'Show');
|
|
108
|
+
bar.hidden = true;
|
|
109
|
+
bar.innerHTML = '<button type="button" class="hx-work-chip" data-corn="work-chip" data-corn-kind="quiet" data-work-show="all" aria-pressed="true">All work</button>'
|
|
110
|
+
+ '<button type="button" class="hx-work-chip" data-corn="work-chip" data-corn-kind="quiet" data-work-show="waiting" aria-pressed="false">Waiting on you</button>'
|
|
111
|
+
+ '<span class="hx-work-busy" hidden>Updating…</span>';
|
|
112
|
+
const note = document.createElement('p');
|
|
113
|
+
note.className = 'hx-work-note';
|
|
114
|
+
note.dataset.corn = 'work-note';
|
|
115
|
+
note.hidden = true;
|
|
116
|
+
// The lanes' titles: lines of the page over the map, in screen space, so they read at any zoom (the map draws the lanes' panels)
|
|
117
|
+
const lanes = document.createElement('div');
|
|
118
|
+
lanes.className = 'hx-work-lanes';
|
|
119
|
+
lanes.dataset.corn = 'work-lanes';
|
|
120
|
+
lanes.setAttribute('aria-hidden', 'true');
|
|
121
|
+
lanes.hidden = true;
|
|
122
|
+
// What the page shows while the first answer is on its way (a big repository takes seconds): the lanes, empty, and the words; the page stays usable under it
|
|
123
|
+
const loading = document.createElement('div');
|
|
124
|
+
loading.className = 'hx-work-loading';
|
|
125
|
+
loading.dataset.corn = 'work-loading';
|
|
126
|
+
loading.hidden = true;
|
|
127
|
+
loading.innerHTML = `<div class="hx-work-skeleton" aria-hidden="true">${['Talk', 'Decide', 'Build', 'Ship', 'Code it touches'].map((name) => `<div class="hx-work-skel-lane"><span class="hx-work-lane-title">${name}</span><i></i><i></i><i></i><i></i></div>`).join('')}</div>`
|
|
128
|
+
+ '<p class="hx-work-loading-text" role="status">Reading the work from the forge. A big repository can take several seconds the first time; the page works meanwhile.</p>';
|
|
129
|
+
stage.append(lanes, loading, bar, note);
|
|
130
|
+
els = { stage, bar, all: bar.children[0], waiting: bar.children[1], busy: bar.children[2], note, lanes, loading };
|
|
131
|
+
if (offPaint) offPaint();
|
|
132
|
+
offPaint = onPaint(paintLanes);
|
|
133
|
+
watchSize(stage);
|
|
134
|
+
card = mountStatus(stage, inst(), { follow: false, onRetry: () => load({ again: true }), focusMap: () => { if (state.canvas) state.canvas.focus(); } });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The map's box changed (a window resized, a phone turned): the lanes are laid out again for it, and fitted, as they were when the answer came */
|
|
138
|
+
let sizeKey = '';
|
|
139
|
+
let sizeTimer = 0;
|
|
140
|
+
function watchSize(stage) {
|
|
141
|
+
const Observer = typeof ResizeObserver === 'undefined' ? null : ResizeObserver;
|
|
142
|
+
if (!Observer) return;
|
|
143
|
+
sizeKey = `${stage.clientWidth}x${stage.clientHeight}`;
|
|
144
|
+
new Observer(() => {
|
|
145
|
+
const key = `${stage.clientWidth}x${stage.clientHeight}`;
|
|
146
|
+
if (key === sizeKey) return;
|
|
147
|
+
sizeKey = key;
|
|
148
|
+
clearTimeout(sizeTimer);
|
|
149
|
+
sizeTimer = setTimeout(() => {
|
|
150
|
+
if (!on() || work().status !== 'ok') return;
|
|
151
|
+
applyWorkLayout(state, { phone: isPhone() });
|
|
152
|
+
inst().touchScene();
|
|
153
|
+
fitGraphToViewport(fitPadding());
|
|
154
|
+
render();
|
|
155
|
+
}, 150);
|
|
156
|
+
}).observe(stage);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The lanes' titles, over the map in screen space: centred over their lane and held under the toggles while the lane is in view (a phone's: at the lane's top left) */
|
|
160
|
+
function paintLanes(scene, camera) {
|
|
161
|
+
if (!els) return;
|
|
162
|
+
const w = work();
|
|
163
|
+
const show = on() && w.status === 'ok' && w.lanes.length > 0;
|
|
164
|
+
els.lanes.hidden = !show;
|
|
165
|
+
if (!show) return;
|
|
166
|
+
if (laneKey !== w.lanes) {
|
|
167
|
+
laneKey = w.lanes;
|
|
168
|
+
els.lanes.textContent = '';
|
|
169
|
+
laneEls = w.lanes.map((l) => {
|
|
170
|
+
const el = document.createElement('div');
|
|
171
|
+
el.className = 'hx-work-lane-title';
|
|
172
|
+
const name = document.createElement('span');
|
|
173
|
+
name.textContent = l.name;
|
|
174
|
+
const count = document.createElement('span');
|
|
175
|
+
count.className = 'hx-work-lane-count';
|
|
176
|
+
count.textContent = String(l.count);
|
|
177
|
+
el.append(name, count);
|
|
178
|
+
els.lanes.append(el);
|
|
179
|
+
return { el, lane: l };
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const phone = isPhone();
|
|
183
|
+
const top = phone ? STICKY_TOP_PHONE : STICKY_TOP;
|
|
184
|
+
for (const { el, lane } of laneEls) {
|
|
185
|
+
const left = camera.x + lane.x * camera.zoom;
|
|
186
|
+
const right = left + lane.w * camera.zoom;
|
|
187
|
+
const topPx = camera.y + lane.y * camera.zoom;
|
|
188
|
+
const bottomPx = topPx + lane.h * camera.zoom;
|
|
189
|
+
// a phone's title stays at its lane's top and goes when that is under the toggles; a desktop's is held under them while the lane is in view
|
|
190
|
+
const seen = right > 0 && left < els.stage.clientWidth && bottomPx > 40 && topPx < els.stage.clientHeight && !(phone && topPx + 8 < top);
|
|
191
|
+
el.style.visibility = seen ? 'visible' : 'hidden';
|
|
192
|
+
if (!seen) continue;
|
|
193
|
+
const y = phone ? topPx + 8 : Math.min(Math.max(topPx + 10, top), bottomPx - 44);
|
|
194
|
+
el.classList.toggle('is-held', !phone && y > topPx + 12);
|
|
195
|
+
el.style.maxWidth = `${Math.max(40, right - left - 12)}px`;
|
|
196
|
+
el.style.top = `${Math.round(y)}px`;
|
|
197
|
+
if (phone) { el.style.left = `${Math.round(Math.max(left, 0) + 10)}px`; el.style.transform = 'none'; } else { el.style.left = `${Math.round((left + right) / 2)}px`; el.style.transform = 'translateX(-50%)'; }
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** The line the lanes' titles hold under, in px from the top of the stage: below the toggles (a phone's are on a second row, under the Layers chip) */
|
|
201
|
+
const STICKY_TOP = 58;
|
|
202
|
+
const STICKY_TOP_PHONE = 108;
|
|
203
|
+
|
|
204
|
+
function paintBar() {
|
|
205
|
+
if (!els) return;
|
|
206
|
+
const w = work();
|
|
207
|
+
const n = w.counts.waiting;
|
|
208
|
+
els.bar.hidden = !on();
|
|
209
|
+
els.all.setAttribute('aria-pressed', String(!w.waiting));
|
|
210
|
+
els.waiting.setAttribute('aria-pressed', String(w.waiting));
|
|
211
|
+
els.waiting.textContent = `Waiting on you · ${n}`;
|
|
212
|
+
els.busy.hidden = !(on() && w.status === 'ok' && w.updating);
|
|
213
|
+
els.loading.hidden = !(on() && w.status === 'loading');
|
|
214
|
+
const lines = [...(w.stale ? [w.stale] : []), ...(w.lastError ? [w.lastError] : []), ...w.problems.map((p) => p.text)];
|
|
215
|
+
els.note.hidden = !on() || !lines.length;
|
|
216
|
+
els.note.textContent = lines.length ? lines.slice(0, 2).join(' ') + (lines.length > 2 ? ` and ${lines.length - 2} more.` : '') : '';
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** The view opened or closed: the button, the bar, the stage; the map's own layers are back when it closed (work-model.js `leaveWork`) */
|
|
220
|
+
function syncWork() {
|
|
221
|
+
const open = on();
|
|
222
|
+
const btn = $('preset-work-btn');
|
|
223
|
+
if (btn) btn.setAttribute('aria-pressed', String(open));
|
|
224
|
+
const stage = state.canvas ? state.canvas.parentElement : null;
|
|
225
|
+
if (stage) stage.classList.toggle('is-work', open);
|
|
226
|
+
paintBar();
|
|
227
|
+
if (open !== wasOn) {
|
|
228
|
+
if (open) { paintBadge(work().counts.waiting); inst().emit('layers:redraw'); } // the Layers menu lists the Work view's rows from the first moment, the answer here or not
|
|
229
|
+
wasOn = open;
|
|
230
|
+
clearTimeout(timer);
|
|
231
|
+
if (open) timer = setTimeout(poll, RUNS_POLL_MS);
|
|
232
|
+
else if (card) card.clear();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function poll() {
|
|
237
|
+
clearTimeout(timer);
|
|
238
|
+
if (!on()) return;
|
|
239
|
+
if (document.visibilityState !== 'hidden') load({ again: true, quiet: true });
|
|
240
|
+
timer = setTimeout(poll, RUNS_POLL_MS);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ---------------------------------------------------------------------------
|
|
244
|
+
// Opening, and the answer
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Opens the Work view, asks for the work graph (once per opening; again on Refresh and on the poll), and selects `select` (a node id) when the answer has it.
|
|
249
|
+
* @param {{ select?: string | null, ask?: { kind: string, key: string } | null }} [opts]
|
|
250
|
+
* @returns {Promise<boolean>} whether the answer arrived
|
|
251
|
+
*/
|
|
252
|
+
export async function openWork({ select = null, ask = null } = {}) {
|
|
253
|
+
const i = inst();
|
|
254
|
+
if (!on()) {
|
|
255
|
+
if (state.proposal) closeProposal(i); // a review holds the map: it ends before the view of work begins
|
|
256
|
+
closeDrawer();
|
|
257
|
+
setView('work');
|
|
258
|
+
}
|
|
259
|
+
syncWork();
|
|
260
|
+
const ok = await load({ select, ask });
|
|
261
|
+
return ok;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Back to the map (the Map button's way) */
|
|
265
|
+
export function closeWork() {
|
|
266
|
+
if (!on()) return;
|
|
267
|
+
closeDrawer();
|
|
268
|
+
setView('orbit');
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function load({ select = null, ask = null, again = false, quiet = false } = {}) {
|
|
272
|
+
const i = inst();
|
|
273
|
+
const mine = ++seq;
|
|
274
|
+
const w = work();
|
|
275
|
+
const have = w.status === 'ok';
|
|
276
|
+
if (!have) {
|
|
277
|
+
// The first answer: the page says so at once (the lanes, empty, and the words) and stays usable; the answer may take seconds on a big repository
|
|
278
|
+
w.status = 'loading';
|
|
279
|
+
card.clear();
|
|
280
|
+
paintBar();
|
|
281
|
+
announce(i, 'Work: reading the work from the forge.');
|
|
282
|
+
} else if (!quiet) { w.updating = true; paintBar(); } // a refresh keeps the last answer on the map until the new one is here
|
|
283
|
+
let res;
|
|
284
|
+
try {
|
|
285
|
+
res = await credentialed(i)(GRAPH_URL, { headers: { accept: 'application/json', ...(again && !quiet ? { 'cache-control': 'no-cache' } : {}) } }); // Refresh asks the forge again
|
|
286
|
+
} catch {
|
|
287
|
+
if (mine !== seq) return false;
|
|
288
|
+
return refuse(i.offline() ? { state: 'offline' } : { state: 'server', message: 'cornfield could not be reached.' }, quiet);
|
|
289
|
+
}
|
|
290
|
+
if (mine !== seq) return false;
|
|
291
|
+
if (res.status === 401 || res.status === 403) return refuse({ state: 'sign-in', status: res.status, signIn: signInUrl(location.origin, location.href) }, quiet);
|
|
292
|
+
let body = null;
|
|
293
|
+
try { body = await res.json(); } catch { body = null; }
|
|
294
|
+
if (mine !== seq) return false;
|
|
295
|
+
if (!res.ok || !body || body.ok === false || !Array.isArray(body.nodes)) {
|
|
296
|
+
const words = res.status === 404 ? 'This server does not answer for the map of work yet: update cornfield.' : body && typeof body.error === 'string' ? body.error.slice(0, 200) : `The server answered ${res.status}.`;
|
|
297
|
+
return refuse({ state: 'server', message: words }, quiet);
|
|
298
|
+
}
|
|
299
|
+
return arrive(body, { select, ask, quiet });
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* The answer could not be had. With nothing read yet, it is said in the map's own card. With an answer on the map, the map keeps it (a refresh that fails does not wipe
|
|
304
|
+
* what is drawn): the line under the toggles says what failed, except for a sign-in that ended, which the card says over the map.
|
|
305
|
+
*/
|
|
306
|
+
function refuse(detail, quiet) {
|
|
307
|
+
const w = work();
|
|
308
|
+
w.updating = false;
|
|
309
|
+
if (w.status === 'ok' && detail.state !== 'sign-in') {
|
|
310
|
+
if (!quiet) { w.lastError = `Could not update the work: ${detail.state === 'offline' ? 'you are offline' : detail.message || 'it could not be read'}. This is what was read earlier.`; announce(inst(), 'Work: it could not be updated. Showing what was read earlier.'); }
|
|
311
|
+
paintBar();
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
if (quiet && w.status === 'ok') return false;
|
|
315
|
+
const again = quiet && w.status === detail.state; // the minute's poll found the same refusal: the card stays, and nothing is said again
|
|
316
|
+
w.status = detail.state;
|
|
317
|
+
w.nodes = [];
|
|
318
|
+
w.edges = [];
|
|
319
|
+
w.counts = { work: 0, code: 0, waiting: 0 };
|
|
320
|
+
w.problems = [];
|
|
321
|
+
w.stale = '';
|
|
322
|
+
w.lastError = '';
|
|
323
|
+
if (on()) { showWork(state); applyWorkLayout(state, { phone: isPhone() }); inst().touchScene(); inst().emit('layers:redraw'); render(); }
|
|
324
|
+
card.show(detail);
|
|
325
|
+
paintBar();
|
|
326
|
+
paintBadge(0);
|
|
327
|
+
if (!again) announce(inst(), `Work: ${detail.state === 'sign-in' ? (detail.status === 403 ? 'this map is for the maintainers.' : 'sign in to see the work.') : detail.state === 'offline' ? 'you are offline.' : 'it could not be read.'}`);
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function arrive(body, { select, ask, quiet }) {
|
|
332
|
+
const i = inst();
|
|
333
|
+
const w = work();
|
|
334
|
+
const first = w.status !== 'ok';
|
|
335
|
+
const before = state.selectedNode ? state.selectedNode.id : null;
|
|
336
|
+
const base = state.baseNodes && state.baseNodes.length ? state.baseNodes : (w.saved ? w.saved.nodes : state.nodes);
|
|
337
|
+
setWorkGraph(state, body, base);
|
|
338
|
+
w.status = 'ok';
|
|
339
|
+
w.updating = false;
|
|
340
|
+
w.lastError = '';
|
|
341
|
+
w.stale = typeof body.stale === 'string' ? body.stale.slice(0, 200) : '';
|
|
342
|
+
card.clear();
|
|
343
|
+
if (on()) {
|
|
344
|
+
showWork(state);
|
|
345
|
+
applyWorkLayout(state, { phone: isPhone() });
|
|
346
|
+
state.workRows = layerRowsOf(w.nodes).map(themed);
|
|
347
|
+
i.touchScene();
|
|
348
|
+
i.emit('layers:redraw');
|
|
349
|
+
if (first || !quiet) fitGraphToViewport(fitPadding()); // the lanes under the toggles, the names at the edge on screen too (work-model.js `layoutWork`)
|
|
350
|
+
render();
|
|
351
|
+
if (before && !state.selectedNode) i.emit('node:close');
|
|
352
|
+
}
|
|
353
|
+
paintBar();
|
|
354
|
+
paintBadge(w.counts.waiting);
|
|
355
|
+
// One sentence: the live region says only the last thing it is given, so what the view opened on and the node an address asked for are said together
|
|
356
|
+
const opened = first || !quiet ? openedWords(w.counts) : '';
|
|
357
|
+
const id = select || nodeForAddress(ask, w.nodes);
|
|
358
|
+
if (id && pick(id)) {
|
|
359
|
+
const shown = shownInOrder();
|
|
360
|
+
const node = state.selectedNode;
|
|
361
|
+
announce(i, `${opened} ${landingWords(node, shown.indexOf(node), shown.length)}`.trim());
|
|
362
|
+
} else if (ask && ask.kind) {
|
|
363
|
+
// A run or an issue older than the graph's window (a link posted in chat weeks ago) is still in the Work panel's lists: the panel opens at it, as these links did before
|
|
364
|
+
const older = !ask.bad && (ask.kind === 'run' || ask.kind === 'issue');
|
|
365
|
+
announce(i, `${ask.bad || `There is no ${KIND_WORDS[ask.kind].toLowerCase()} ${ask.key} in the work now${older ? ': the Work panel looks for it' : ''}.`} ${opened}`.trim());
|
|
366
|
+
if (older) (ask.kind === 'run' ? openRunLink(ask.key) : openIssueLink(Number(ask.key))).catch(() => {});
|
|
367
|
+
} else if (opened) announce(i, opened);
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** The nodes N and P step through, in the lanes' order: what is shown */
|
|
372
|
+
const shownInOrder = () => work().order.map((id) => state.nodes.find((n) => n.id === id)).filter((n) => n && !n.hidden);
|
|
373
|
+
|
|
374
|
+
/** The row's dot is the colour the map draws the kind in, the theme's token when it sets one */
|
|
375
|
+
function themed(row) {
|
|
376
|
+
const kind = WORK_KINDS.find((k) => `work-${k}` === row.key);
|
|
377
|
+
const values = mapStyleOf(inst()).get().values;
|
|
378
|
+
return kind && values[workToken(kind)] ? { ...row, color: values[workToken(kind)] } : row;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** A layer went on or off: what is hidden is worked out again, the lanes are laid out for what is shown, and the camera fits them */
|
|
382
|
+
function refilter() {
|
|
383
|
+
if (!on()) return;
|
|
384
|
+
const w = work();
|
|
385
|
+
applyFilters(w.nodes, w.edges, { layers: w.layers, waiting: w.waiting });
|
|
386
|
+
const sel = state.selectedNode;
|
|
387
|
+
applyWorkLayout(state, { phone: isPhone() });
|
|
388
|
+
state.workRows = layerRowsOf(w.nodes).map(themed);
|
|
389
|
+
inst().touchScene();
|
|
390
|
+
if (sel && sel.hidden) inst().emit('node:close');
|
|
391
|
+
fitGraphToViewport(fitPadding());
|
|
392
|
+
render();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** Selects a node of the view by id: the panel opens, the camera follows (as a search's choice does) */
|
|
396
|
+
export function pick(id, { frame = true, source = 'link' } = {}) {
|
|
397
|
+
const node = state.nodes.find((n) => n.id === id);
|
|
398
|
+
if (!node) return false;
|
|
399
|
+
if (node.hidden) { work().layers[node.draft ? DRAFT_LAYER : node.work ? `work-${node.work}` : CODE_LAYER] = true; refilter(); }
|
|
400
|
+
selectNode(inst(), node, { frame, source });
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** "Waiting on you" on or off: everything that does not wait is dimmed (spec 0012 D3) */
|
|
405
|
+
function setWaiting(on_) {
|
|
406
|
+
const w = work();
|
|
407
|
+
if (w.waiting === on_) return;
|
|
408
|
+
w.waiting = on_;
|
|
409
|
+
applyFilters(w.nodes, w.edges, { layers: w.layers, waiting: w.waiting });
|
|
410
|
+
inst().touchScene();
|
|
411
|
+
paintBar();
|
|
412
|
+
render();
|
|
413
|
+
announce(inst(), on_ ? `Showing what waits on you: ${w.counts.waiting}.` : 'Showing all work.');
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// ---------------------------------------------------------------------------
|
|
417
|
+
// The node panel's words for a node
|
|
418
|
+
// ---------------------------------------------------------------------------
|
|
419
|
+
/** The kind's colour as the map draws it: the theme's token, else the default (the style goes on through `data-style`, which a host's CSP allows) */
|
|
420
|
+
const colorOf = (kind) => { const v = mapStyleOf(inst()).get().values[workToken(kind)]; return /^#[0-9a-f]{3,8}$/i.test(v || '') ? v : WORK_THEMES[kind] ? WORK_THEMES[kind].color : ''; };
|
|
421
|
+
|
|
422
|
+
/** What the node panel shows for a node while the Work view is open (`work:panel`): a piece of work, replaced; a node of code, with the work that touches it first (work-model.js builds the markup) */
|
|
423
|
+
function panelFor(node) {
|
|
424
|
+
if (!on() || !node) return undefined;
|
|
425
|
+
const w = work();
|
|
426
|
+
if (node.work) {
|
|
427
|
+
const p = panelOf(node, w.nodes, w.edges);
|
|
428
|
+
if (node.item.kind === 'pull') loadChecks(node);
|
|
429
|
+
return { replace: true, badge: p.kind, title: p.title, html: workPanelHtml(p, node, { color: colorOf, checks: checksLine(node) }) };
|
|
430
|
+
}
|
|
431
|
+
return { replace: false, html: codePanelHtml(node, touchedBy(node, w.nodes, w.edges), { color: colorOf }) };
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** What the checks of a pull request's head say, once read; "Reading the checks…" until then */
|
|
435
|
+
const checksLine = (node) => {
|
|
436
|
+
const got = pullDetail.get(node.item.number);
|
|
437
|
+
return got ? got.text : 'Reading the checks…';
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
/** The checks are not in the graph: they are read from the pull request's own route when its node is opened, and painted into the panel when they arrive */
|
|
441
|
+
async function loadChecks(node) {
|
|
442
|
+
const n = node.item.number;
|
|
443
|
+
const i = inst();
|
|
444
|
+
let text = 'The checks could not be read.';
|
|
445
|
+
try {
|
|
446
|
+
const res = await credentialed(i)(pullUrl(n), { headers: { accept: 'application/json' } });
|
|
447
|
+
const body = res.ok ? await res.json() : null;
|
|
448
|
+
if (body && Array.isArray(body.checks)) text = checksWords(body.checks);
|
|
449
|
+
} catch { /* said in the panel */ }
|
|
450
|
+
pullDetail.set(n, { text });
|
|
451
|
+
const el = document.getElementById('work-checks');
|
|
452
|
+
if (el && state.selectedNode && state.selectedNode.id === node.id) el.textContent = text;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// ---------------------------------------------------------------------------
|
|
456
|
+
// Keys (the map's own are for the other views: Shift and an arrow still pan, the rest are the map's)
|
|
457
|
+
// ---------------------------------------------------------------------------
|
|
458
|
+
function onKey(e) {
|
|
459
|
+
if (!on() || e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey || !state.canvas || e.target !== state.canvas) return;
|
|
460
|
+
const shown = shownInOrder();
|
|
461
|
+
if (!shown.length) return;
|
|
462
|
+
const from = state.selectedNode;
|
|
463
|
+
let to = null;
|
|
464
|
+
if (e.key === 'n' || e.key === 'N' || e.key === ']') to = stepFrom(shown, from && from.id, 1);
|
|
465
|
+
else if (e.key === 'p' || e.key === 'P' || e.key === '[') to = stepFrom(shown, from && from.id, -1);
|
|
466
|
+
else if (e.key.startsWith('Arrow') && !e.shiftKey) to = from ? arrowTarget(state.nodes, from, e.key) : shown[0];
|
|
467
|
+
else return;
|
|
468
|
+
e.preventDefault();
|
|
469
|
+
e.stopImmediatePropagation();
|
|
470
|
+
if (!to) { announce(inst(), 'No node that way.'); return; }
|
|
471
|
+
selectNode(inst(), to, { frame: true, source: 'keyboard' });
|
|
472
|
+
announce(inst(), landingWords(to, shown.indexOf(to), shown.length));
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// ---------------------------------------------------------------------------
|
|
476
|
+
// Clicks
|
|
477
|
+
// ---------------------------------------------------------------------------
|
|
478
|
+
function onClick(e) {
|
|
479
|
+
const t_ = e.target && e.target.closest ? e.target : null;
|
|
480
|
+
if (!t_) return;
|
|
481
|
+
if (t_.closest('[data-action="preset-work"]')) { if (on()) closeWork(); else openWork(); return; }
|
|
482
|
+
if (t_.closest('[data-action="refresh-forge"]') && on()) { load({ again: true }); return; }
|
|
483
|
+
const show = t_.closest('[data-work-show]');
|
|
484
|
+
if (show && on()) { setWaiting(show.dataset.workShow === 'waiting'); return; }
|
|
485
|
+
const act = t_.closest('[data-work-action]');
|
|
486
|
+
if (!act) return;
|
|
487
|
+
const node = state.nodes.find((n) => n.id === act.dataset.id);
|
|
488
|
+
if (!node) return;
|
|
489
|
+
if (act.dataset.workAction === 'open-in-work') openWorkAt(node.item);
|
|
490
|
+
else if (act.dataset.workAction === 'show-on-map') showOnMap(node.id);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** A node of code, on the map: the view goes back to it, the node selected and in view */
|
|
494
|
+
function showOnMap(id) {
|
|
495
|
+
closeWork();
|
|
496
|
+
const node = state.nodes.find((n) => n.id === id);
|
|
497
|
+
if (node) selectNode(inst(), node, { frame: true, source: 'link' });
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// ---------------------------------------------------------------------------
|
|
501
|
+
// Addresses (spec 0012 D8)
|
|
502
|
+
// ---------------------------------------------------------------------------
|
|
503
|
+
|
|
504
|
+
/** Follows `?view=work`, `?pr=`, `?issue=`, `?run=`, `?thread=` and `?spec=`, once; the ones that ask for a node are taken out of the address when followed */
|
|
505
|
+
export async function followWorkAddress(search = location.search) {
|
|
506
|
+
const ask = workAddress(search);
|
|
507
|
+
if (!ask) return false;
|
|
508
|
+
if (!offered) { announce(inst(), 'The map of work needs a forge in the config.'); return false; }
|
|
509
|
+
spend();
|
|
510
|
+
return openWork({ ask: ask.kind ? ask : null });
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/** What an address that asks for work is, for the page to decide whether it is the Work view's (the old Work panel's links are `?run=` and `?issue=` too: step 3 of spec 0012 moves them) */
|
|
514
|
+
export const asksForWork = (search) => workAddress(search) !== null;
|
|
515
|
+
|
|
516
|
+
function spend() {
|
|
517
|
+
if (typeof history === 'undefined') return;
|
|
518
|
+
try {
|
|
519
|
+
const params = new URLSearchParams(location.search);
|
|
520
|
+
for (const k of ['pr', 'issue', 'run', 'thread', 'spec']) params.delete(k);
|
|
521
|
+
const query = params.toString();
|
|
522
|
+
history.replaceState(null, '', `${location.pathname}${query ? `?${query}` : ''}${location.hash}`);
|
|
523
|
+
} catch { /* the address is a convenience */ }
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** For tests: forget the page this was wired to */
|
|
527
|
+
export function resetWorkViewForTests() {
|
|
528
|
+
clearTimeout(timer);
|
|
529
|
+
if (offPaint) offPaint();
|
|
530
|
+
offPaint = null;
|
|
531
|
+
laneEls = [];
|
|
532
|
+
laneKey = null;
|
|
533
|
+
wired = false;
|
|
534
|
+
offered = false;
|
|
535
|
+
els = null;
|
|
536
|
+
card = null;
|
|
537
|
+
seq++;
|
|
538
|
+
pullDetail = new Map();
|
|
539
|
+
wasOn = false;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export { WORK_THEMES };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@popcorn245/cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|