cornfield 0.56.0 → 0.57.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/strings.js +1 -1
- package/explorer/css/account.css +1 -1
- package/explorer/css/changes.css +1 -1
- package/explorer/css/dialogs.css +1 -1
- package/explorer/css/node-panel.css +1 -1
- package/explorer/css/sheets.css +1 -1
- package/explorer/css/work.css +6 -4
- package/explorer/engine/hint.js +2 -2
- package/explorer/engine/keyboard.js +1 -1
- package/explorer/engine/layers.js +4 -2
- package/explorer/engine/map-rect.js +2 -2
- package/explorer/engine/proposal.js +3 -3
- package/explorer/engine/sheets.js +3 -3
- package/explorer/focus-room.js +1 -1
- package/explorer/forge-panel.js +1 -1
- package/explorer/index.html +1 -1
- package/explorer/instance.js +6 -4
- package/explorer/page-pieces.js +1 -1
- package/explorer/pieces/decision.js +3 -3
- package/explorer/pieces/layers.js +1 -1
- package/explorer/pieces/node-panel.js +29 -9
- package/explorer/pieces/proposal.js +6 -6
- package/explorer/pieces/review.js +2 -2
- package/explorer/pieces/work-paint.js +17 -0
- package/explorer/pieces/work.js +10 -0
- package/explorer/proposal-model.js +1 -1
- package/explorer/proposal.js +1 -1
- package/explorer/sheets.js +1 -1
- package/explorer/tokens.css +2 -2
- package/explorer/work-badge-model.js +161 -0
- package/explorer/work-badges.js +143 -0
- package/explorer/work-model.js +1 -1
- package/explorer/work-view.css +8 -0
- package/explorer/work-view.js +119 -22
- package/package.json +1 -1
package/explorer/tokens.css
CHANGED
|
@@ -115,8 +115,8 @@
|
|
|
115
115
|
--corn-space-5: 16px;
|
|
116
116
|
--corn-space-6: 24px;
|
|
117
117
|
|
|
118
|
-
/* Density (issue #200). The one height of a control in a bar (the header, the proposal bar, the decision foot, the player, the Work
|
|
119
|
-
32px at a desk, 44px on a phone (the media query after the light blocks). The padding of a panel's body, which the Work
|
|
118
|
+
/* Density (issue #200). The one height of a control in a bar (the header, the proposal bar, the decision foot, the player, the Work list's top row):
|
|
119
|
+
32px at a desk, 44px on a phone (the media query after the light blocks). The padding of a panel's body, which the Work list and the node panel share,
|
|
120
120
|
and the least height of a panel's head: a control and a step of padding */
|
|
121
121
|
--corn-control-height: 32px;
|
|
122
122
|
--corn-panel-pad: calc(var(--corn-space-5) + var(--corn-space-1));
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/work-badge-model
|
|
3
|
+
*
|
|
4
|
+
* The pure half of the Work layer on the Map view (spec 0012 D4): a small badge (`PR #27`, `Issue #14`) on each node that open work touches. No DOM, no state, no fetch;
|
|
5
|
+
* work-badges.js draws them and work-view.js holds the answer they are made of (`state.work`, the one read of `GET /api/forge/work-graph` the Work view shares).
|
|
6
|
+
*
|
|
7
|
+
* badgeIndex(nodes, edges) node id -> the open work touching it, the most pressing first (waiting on you, then the newest)
|
|
8
|
+
* badgeText(items) "PR #27", or "PR #27 +2" when more touch the node
|
|
9
|
+
* badgeWords(items) what a screen reader hears of it: "2 open: PR #27, Issue #14"
|
|
10
|
+
* placeBadges(scene, zoom, index, opts) which badges fit at this zoom, and where: the same placing as the names under the nodes (labels.js `placeLabels`)
|
|
11
|
+
* openWorkHtml(items, opts) the node panel's "Open work" section: each item a link that opens the Work view on it (every word escaped, only http(s) links)
|
|
12
|
+
* badgeRowOf(w, wanted) the Layers menu's row: its count in words
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { escapeHtml as esc } from '../core/text.js';
|
|
16
|
+
import { labelMinOf, placeLabels } from './labels.js';
|
|
17
|
+
import { KIND_WORDS, byLane, stateWordsOf, tagOf } from './work-model.js';
|
|
18
|
+
import { safeUrl } from './pieces/work-common.js';
|
|
19
|
+
|
|
20
|
+
/** The layer's key in the Layers menu and `state.activeLayers` (the Work view's own are `work-<kind>`: work-model.js) */
|
|
21
|
+
export const WORK_BADGE_LAYER = 'work-badges';
|
|
22
|
+
/** The most badges drawn at once (the node panel still lists every item) */
|
|
23
|
+
export const MAX_BADGES = 60;
|
|
24
|
+
/** A badge's text size on screen (px), and the room its pill takes beside the text, in ems of that size */
|
|
25
|
+
export const BADGE_PX = 11;
|
|
26
|
+
const PAD_EM = 1.2;
|
|
27
|
+
/** The height of a label's box in `placeLabels`, in sizes (labels.js: an ascent of 1 and a descent of 0.3) */
|
|
28
|
+
const BOX_EM = 1.3;
|
|
29
|
+
/** What starts the label of a badge in the placing, so its width is the pill's (a character no name begins with) */
|
|
30
|
+
const MARK = '\u0001';
|
|
31
|
+
const MARK_CODE = 1;
|
|
32
|
+
/** The most items a node's spoken words name before "and N more" */
|
|
33
|
+
const SPOKEN = 3;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Which node is touched by which open work. The edges are the work view's (`state.work.edges`): from a piece of work to a node of code, by `changes`, `adds`, `mentions` or
|
|
37
|
+
* `restarts`. Only open work counts, and a proposal that is only a file in the checkout (nobody has been asked to decide it: the Work view's Drafts) does not; a planned node
|
|
38
|
+
* (a proposal's `adds`: the map does not hold it) has no badge, so it is left out here.
|
|
39
|
+
* @param {object[]} nodes the Work view's nodes (work and the code it touches)
|
|
40
|
+
* @param {{ from: string, to: string, tone: string }[]} edges
|
|
41
|
+
* @returns {Map<string, object[]>} node id -> its items (`{ id, kind, tag, title, waiting, state, url }`), most pressing first
|
|
42
|
+
*/
|
|
43
|
+
export function badgeIndex(nodes, edges) {
|
|
44
|
+
const work = new Map();
|
|
45
|
+
const code = new Set();
|
|
46
|
+
for (const n of nodes || []) {
|
|
47
|
+
if (n.work) { if (n.item && n.item.open === true && !n.draft) work.set(n.id, n); } else if (!n.planned) code.add(n.id);
|
|
48
|
+
}
|
|
49
|
+
const index = new Map();
|
|
50
|
+
for (const e of edges || []) {
|
|
51
|
+
if (e.tone !== 'code' || !code.has(e.to)) continue;
|
|
52
|
+
const from = work.get(e.from);
|
|
53
|
+
if (!from) continue;
|
|
54
|
+
const list = index.get(e.to) || index.set(e.to, []).get(e.to);
|
|
55
|
+
if (!list.some((x) => x.id === from.id)) list.push(from);
|
|
56
|
+
}
|
|
57
|
+
for (const [id, list] of index) {
|
|
58
|
+
list.sort(byLane); // waiting on you first, then the newest, then by id: the order of a lane
|
|
59
|
+
index.set(id, list.map((n) => ({ id: n.id, kind: n.work, tag: tagOf(n.item), title: n.title, waiting: n.waiting === true, state: stateWordsOf(n.item), url: safeUrl(n.item.url) })));
|
|
60
|
+
}
|
|
61
|
+
return index;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The badge's text: the most pressing item's tag, then how many more touch the node */
|
|
65
|
+
export const badgeText = (items) => `${items[0].tag}${items.length > 1 ? ` +${items.length - 1}` : ''}`;
|
|
66
|
+
|
|
67
|
+
/** What a screen reader is told of a node: "2 open: PR #27, Issue #14", the first said to wait when it does; empty for a node no open work touches */
|
|
68
|
+
export function badgeWords(items) {
|
|
69
|
+
if (!items || !items.length) return '';
|
|
70
|
+
const named = items.slice(0, SPOKEN).map((i) => `${i.tag}${i.waiting ? ' (waiting on you)' : ''}`);
|
|
71
|
+
return `${items.length} open: ${named.join(', ')}${items.length > SPOKEN ? ` and ${items.length - SPOKEN} more` : ''}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Which badges fit at `zoom`, and where, by the rules the names under the nodes follow (labels.js `placeLabels`): the whole map's placing, kept for as long as the scene and the zoom stay,
|
|
76
|
+
* the same wherever the camera is. The names are placed first and are never moved by a badge (they are the first thing `placeLabels` places here, as the selection's would be); a badge
|
|
77
|
+
* is then placed in priority order, the selected node's first, then those that wait on you, then the rest (the larger the node, the more lines it has, the nearer the front), and
|
|
78
|
+
* is skipped when its box (plus `LABEL_PAD`) touches a name or a badge already placed. A badge sits above its node's disc, centred on it, at its own size on screen whatever the zoom.
|
|
79
|
+
* @param {import('./scene.js').Scene} scene
|
|
80
|
+
* @param {number} zoom
|
|
81
|
+
* @param {Map<string, object[]>} index `badgeIndex`
|
|
82
|
+
* @param {{ measure?: (text: string, size: number, bold: boolean) => number, measurePill?: (text: string, size: number, bold: boolean) => number, height?: number, max?: number }} [opts]
|
|
83
|
+
* `measure`: the width of a name, in the label layer's font (as `placeLabels` takes it); `measurePill`: the width of a badge's text, in the page's font (default: `measure`);
|
|
84
|
+
* `height`: the pill's height on screen, its line and its border (px; default, and at least, the height of a name's box at the badge's size)
|
|
85
|
+
* @returns {{ id: string, items: object[], text: string, l: number, t: number, r: number, b: number }[]} in priority order, boxes in zoom-scaled world coordinates (no camera)
|
|
86
|
+
*/
|
|
87
|
+
export function placeBadges(scene, zoom, index, { measure = null, measurePill = measure, height = 0, max = MAX_BADGES } = {}) {
|
|
88
|
+
const min = labelMinOf(scene);
|
|
89
|
+
const px = Math.max(BADGE_PX, min);
|
|
90
|
+
// placeLabels gives a label a box 1.3 sizes high; a pill is as high as its line and its border, so it is placed as a label of the size whose box is that high, and its width is scaled back
|
|
91
|
+
const box = Math.max(BOX_EM * px, height || 0);
|
|
92
|
+
const boxPx = box / BOX_EM;
|
|
93
|
+
const gap = Math.max(3, 3 * zoom);
|
|
94
|
+
const mine = [];
|
|
95
|
+
for (const n of scene.nodes) {
|
|
96
|
+
const items = index.get(n.id);
|
|
97
|
+
if (!items || !items.length || !(n.alpha > 0.2)) continue;
|
|
98
|
+
const text = badgeText(items);
|
|
99
|
+
// placeLabels puts a label under a disc: a box whose top is `gap` below `y + r`. The badge goes above the disc instead, so the node it is placed for sits higher by the box, the gap before and the gap after
|
|
100
|
+
mine.push({
|
|
101
|
+
id: n.id, type: 'work-badge', label: `${MARK}${text}`, labelAlpha: 1, labelSize: boxPx / zoom, labelBold: true, x: n.x, y: n.y - n.r - (2 * gap + box) / zoom, r: 0, degree: n.degree || 0,
|
|
102
|
+
selected: false, current: n.selected === true || n.current === true, match: items[0].waiting, connected: true, mark: 'none', items, text,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (!mine.length) return [];
|
|
106
|
+
// The names, placed as the label layer places them, stand in the way as if they were selected: first of all, so a badge never takes one's room
|
|
107
|
+
const names = placeLabels(scene, zoom, { measure }).map((p) => ({ ...p.node, selected: true }));
|
|
108
|
+
// one measure for the placing: a badge's label starts with MARK, and is the pill's text in the page's font and its room; every other label is a name, in the label layer's font
|
|
109
|
+
const both = measure && measurePill ? (text, size, bold) => (text.charCodeAt(0) === MARK_CODE ? ((measurePill(text.slice(1), size, bold) + size * PAD_EM) * px) / boxPx : measure(text, size, bold)) : null;
|
|
110
|
+
const placed = placeLabels({ nodes: [...names, ...mine], labelMin: scene.labelMin }, zoom, { measure: both });
|
|
111
|
+
const out = [];
|
|
112
|
+
for (const p of placed) {
|
|
113
|
+
if (p.node.type !== 'work-badge') continue;
|
|
114
|
+
out.push({ id: p.id, items: p.node.items, text: p.node.text, l: p.l, t: p.t, r: p.r, b: p.b });
|
|
115
|
+
if (out.length >= max) break;
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// The node panel's "Open work"
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
const dotOf = (kind, color) => { const c = typeof color === 'function' ? color(kind) : ''; return `<span class="hx-work-dot" data-corn="swatch" data-work-kind="${esc(kind)}" aria-hidden="true"${c ? ` data-style="background-color: ${esc(c)}"` : ''}></span>`; };
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The node panel's section for a node the layer badges: each piece of open work as a link that opens the Work view with it selected (`?view=work&pr=27`: the address is the link's
|
|
128
|
+
* `href`, so a new tab goes there too, and a click opens the view in place), and, for the forge's own page, a second link that is there only when the address is an http(s) one.
|
|
129
|
+
* Every word is the forge's: escaped, and the `url` goes through `safeUrl`.
|
|
130
|
+
* @param {object[]} items `badgeIndex`'s items for the node
|
|
131
|
+
* @param {{ color?: (kind: string) => string, address?: (id: string) => string | null }} [opts] `color`: a kind's colour as the map draws it; `address`: the item's `?pr=27`-style address (work-model.js `addressOf`)
|
|
132
|
+
*/
|
|
133
|
+
export function openWorkHtml(items, { color = () => '', address = () => null } = {}) {
|
|
134
|
+
const rows = items.map((i) => {
|
|
135
|
+
const addr = address(i.id);
|
|
136
|
+
const href = `?view=work${addr ? `&${addr.slice(1)}` : ''}`;
|
|
137
|
+
const out = i.url ? ` <a class="hx-faint" data-corn="open-link" href="${esc(i.url)}" target="_blank" rel="noreferrer" aria-label="Open ${esc(i.tag)} on the forge">↗</a>` : '';
|
|
138
|
+
return `<li data-corn="work-link"><span class="hx-work-rel">${esc(KIND_WORDS[i.kind] || i.kind)}</span>${dotOf(i.kind, color)}<a class="hx-linkbtn" data-corn="node-link" data-work-action="open-item" data-id="${esc(i.id)}" href="${esc(href)}">${esc(i.tag)} · ${esc(i.title)}</a>${i.waiting ? ' <span class="hx-faint">waiting on you</span>' : ` <span class="hx-faint">${esc(i.state)}</span>`}${out}</li>`;
|
|
139
|
+
});
|
|
140
|
+
return `<div class="hx-fact" data-corn="section"><div class="hx-fact-k">Open work</div><div class="hx-fact-v"><ul class="hx-work-links" data-corn="work-links">${rows.join('')}</ul></div></div>`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// The Layers menu's row
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The row the Layers menu shows under Overlays: its count says how many nodes open work touches, or where the answer is: "reading…" while the first read is on its way, "not read yet"
|
|
149
|
+
* until the layer is first on (or the Work view opened), and the refusal when the forge could not be read.
|
|
150
|
+
* @param {{ status: string, badges?: Map<string, object[]> }} w the Work view's state (`state.work`)
|
|
151
|
+
* @param {string} color the row's dot
|
|
152
|
+
*/
|
|
153
|
+
export function badgeRowOf(w, color) {
|
|
154
|
+
const n = w.badges ? w.badges.size : 0;
|
|
155
|
+
const countText = w.status === 'ok' ? `${n} ${n === 1 ? 'node' : 'nodes'}`
|
|
156
|
+
: w.status === 'loading' ? 'reading…'
|
|
157
|
+
: w.status === 'sign-in' ? 'sign in again'
|
|
158
|
+
: w.status === 'offline' ? 'offline'
|
|
159
|
+
: w.status === 'server' ? 'not read' : 'not read yet';
|
|
160
|
+
return { key: WORK_BADGE_LAYER, label: 'Work', color, overlay: true, countText, desc: 'A small badge on each node that open work touches: PR #27, Issue #14, Run 000003, Spec 0100. The one that waits on you comes first, then +N. The same read as the Work view.' };
|
|
161
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/work-badges
|
|
3
|
+
*
|
|
4
|
+
* The Work layer's badges on the Map view (spec 0012 D4), drawn: one small pill over each node open work touches (`PR #27`, `Issue #14 +1`), in screen space, so it reads at any zoom, in the
|
|
5
|
+
* colour of its most pressing item's kind (`--corn-work-<kind>`). A DOM layer over the map like the runs' marks (runs-map.js, which is left as it is), decoration for the eye (`aria-hidden`): what a
|
|
6
|
+
* screen reader gets is the words the keyboard says on landing on a badged node ("2 open: PR #27, Issue #14") and the node panel's "Open work" section. Which badges fit, and where, is
|
|
7
|
+
* work-badge-model.js's (`placeBadges`: the names' own placing); this only holds the elements and moves them with the camera.
|
|
8
|
+
*
|
|
9
|
+
* createWorkBadges({ stage, doc, state, style, colorOf, fontOf }) -> { sync(scene, camera), clear(), destroy() }
|
|
10
|
+
*
|
|
11
|
+
* `sync` is the map's paint hook: it is cheap when nothing moved (a packet frame), and does nothing while the layer is off (no element is made until the first badge).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { BADGE_PX, MAX_BADGES, placeBadges } from './work-badge-model.js';
|
|
15
|
+
import { labelMinOf } from './labels.js';
|
|
16
|
+
import { styledScene } from './engine/map-style.js';
|
|
17
|
+
import { FONT_NODE } from './scene.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {{ stage: HTMLElement, state: object, style: () => object, colorOf: (kind: string) => string, wanted: () => Map<string, object[]> | null, doc?: Document }} deps
|
|
21
|
+
* `wanted`: the index to draw (`badgeIndex`), or null while the layer is off, the view is not the map, the answer is not here
|
|
22
|
+
*/
|
|
23
|
+
export function createWorkBadges({ stage, state, style, colorOf, wanted, doc = document }) {
|
|
24
|
+
let layer = null;
|
|
25
|
+
/** @type {Map<string, HTMLElement>} the pills by node id */
|
|
26
|
+
const pills = new Map();
|
|
27
|
+
let placed = null; // the placing for the scene, zoom, index and style it was made for: a pan only moves the pills
|
|
28
|
+
let placedKey = '';
|
|
29
|
+
let drawnKey = '';
|
|
30
|
+
const widths = new Map();
|
|
31
|
+
let ctx = null;
|
|
32
|
+
|
|
33
|
+
/** The width of a text in a font (a canvas measures it once per string): a name's, in the label layer's font, and the pill's text in the page's own, so the placing leaves the room each takes */
|
|
34
|
+
function measurer(family, weight) {
|
|
35
|
+
if (ctx === null) { try { ctx = doc.createElement('canvas').getContext('2d') || false; } catch { ctx = false; } }
|
|
36
|
+
if (!ctx) return null;
|
|
37
|
+
return (text, size, bold) => {
|
|
38
|
+
const key = `${bold ? 'b' : 'n'}${size}|${family}|${text}`;
|
|
39
|
+
let w = widths.get(key);
|
|
40
|
+
if (w === undefined) {
|
|
41
|
+
if (widths.size > 4000) widths.clear();
|
|
42
|
+
ctx.font = `${bold ? `${weight} ` : ''}${size}px ${family}`;
|
|
43
|
+
w = ctx.measureText(text).width;
|
|
44
|
+
widths.set(key, w);
|
|
45
|
+
}
|
|
46
|
+
return w;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let tall = { key: '', h: 0 };
|
|
51
|
+
/** How high a pill is on screen (its line and its border, the heavier one of a pill that waits): measured once for a size and a look, in the layer, so the placing keeps its room */
|
|
52
|
+
function pillHeight(px, key) {
|
|
53
|
+
if (tall.key === key) return tall.h;
|
|
54
|
+
const probe = doc.createElement('span');
|
|
55
|
+
probe.className = 'hx-work-badge is-waiting';
|
|
56
|
+
probe.style.fontSize = `${px}px`;
|
|
57
|
+
probe.style.visibility = 'hidden';
|
|
58
|
+
probe.textContent = 'Spec 0100';
|
|
59
|
+
const host = ensureLayer();
|
|
60
|
+
host.hidden = false; // (it is drawn into next)
|
|
61
|
+
host.append(probe);
|
|
62
|
+
tall = { key, h: probe.offsetHeight || 0 };
|
|
63
|
+
probe.remove();
|
|
64
|
+
return tall.h;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const ensureLayer = () => {
|
|
68
|
+
if (layer && layer.isConnected) return layer;
|
|
69
|
+
layer = doc.createElement('div');
|
|
70
|
+
layer.className = 'hx-work-badges';
|
|
71
|
+
layer.dataset.corn = 'work-badges';
|
|
72
|
+
layer.setAttribute('part', 'work-badges');
|
|
73
|
+
layer.setAttribute('aria-hidden', 'true');
|
|
74
|
+
stage.append(layer);
|
|
75
|
+
pills.clear();
|
|
76
|
+
return layer;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function clear() {
|
|
80
|
+
for (const el of pills.values()) el.remove();
|
|
81
|
+
pills.clear();
|
|
82
|
+
if (layer) layer.hidden = true;
|
|
83
|
+
placed = null;
|
|
84
|
+
placedKey = '';
|
|
85
|
+
drawnKey = '';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Puts the badges on the nodes the scene drew, at the camera.
|
|
90
|
+
* @param {import('./scene.js').Scene} scene
|
|
91
|
+
* @param {{ x: number, y: number, zoom: number }} camera
|
|
92
|
+
*/
|
|
93
|
+
function sync(scene, camera) {
|
|
94
|
+
const index = wanted();
|
|
95
|
+
if (!index || !index.size) { if (layer && !layer.hidden) clear(); return; }
|
|
96
|
+
const look = style();
|
|
97
|
+
const key = `${scene.version}|${camera.zoom}|${look.plain ? 0 : look.version}|${state.theme}|${state.width}x${state.height}`;
|
|
98
|
+
const sameScene = placed && placed.scene === scene && placed.index === index && placedKey === key;
|
|
99
|
+
if (!sameScene) {
|
|
100
|
+
const styled = styledScene(scene, look);
|
|
101
|
+
const family = (typeof getComputedStyle === 'function' && stage.isConnected ? getComputedStyle(stage).fontFamily : '') || 'sans-serif'; // the pill is set in the page's font
|
|
102
|
+
const px = Math.max(BADGE_PX, labelMinOf(scene));
|
|
103
|
+
const height = pillHeight(px, `${px}|${look.plain ? 0 : look.version}|${state.theme}`);
|
|
104
|
+
placed = { scene, index, list: placeBadges(styled, camera.zoom, index, { measure: measurer(styled.labelFont || FONT_NODE, 'bold'), measurePill: measurer(family, '600'), height, max: MAX_BADGES }) };
|
|
105
|
+
placedKey = key;
|
|
106
|
+
drawnKey = '';
|
|
107
|
+
}
|
|
108
|
+
const at = `${camera.x}|${camera.y}`;
|
|
109
|
+
if (drawnKey === `${placedKey}|${at}`) return;
|
|
110
|
+
drawnKey = `${placedKey}|${at}`;
|
|
111
|
+
const host = ensureLayer();
|
|
112
|
+
host.hidden = false;
|
|
113
|
+
const seen = new Set();
|
|
114
|
+
for (const p of placed.list) {
|
|
115
|
+
const left = camera.x + (p.l + p.r) / 2;
|
|
116
|
+
const top = camera.y + p.t;
|
|
117
|
+
if (camera.x + p.r < 0 || camera.x + p.l > state.width || camera.y + p.b < 0 || camera.y + p.t > state.height) continue; // off the screen: no pill (one partly in is cut by the layer's edge, as a name is)
|
|
118
|
+
seen.add(p.id);
|
|
119
|
+
let el = pills.get(p.id);
|
|
120
|
+
const first = p.items[0];
|
|
121
|
+
const text = p.text;
|
|
122
|
+
if (!el) {
|
|
123
|
+
el = doc.createElement('span');
|
|
124
|
+
el.className = 'hx-work-badge';
|
|
125
|
+
el.dataset.corn = 'work-badge';
|
|
126
|
+
el.setAttribute('part', 'work-badge');
|
|
127
|
+
el.dataset.node = p.id;
|
|
128
|
+
host.append(el);
|
|
129
|
+
pills.set(p.id, el);
|
|
130
|
+
}
|
|
131
|
+
if (el.textContent !== text) el.textContent = text; // the forge's words go in as text, never as markup
|
|
132
|
+
if (el.dataset.workKind !== first.kind) el.dataset.workKind = first.kind;
|
|
133
|
+
el.classList.toggle('is-waiting', first.waiting === true);
|
|
134
|
+
el.style.setProperty('--hx-badge', colorOf(first.kind));
|
|
135
|
+
el.style.fontSize = `${Math.max(BADGE_PX, labelMinOf(scene))}px`;
|
|
136
|
+
el.style.left = `${left.toFixed(1)}px`;
|
|
137
|
+
el.style.top = `${top.toFixed(1)}px`;
|
|
138
|
+
}
|
|
139
|
+
for (const [id, el] of pills) if (!seen.has(id)) { el.remove(); pills.delete(id); }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return { sync, clear, destroy() { clear(); if (layer) layer.remove(); layer = null; } };
|
|
143
|
+
}
|
package/explorer/work-model.js
CHANGED
|
@@ -657,7 +657,7 @@ export function openedWords({ work, code, waiting }) {
|
|
|
657
657
|
// ---------------------------------------------------------------------------
|
|
658
658
|
|
|
659
659
|
/** What the Work view keeps on the state (`state.work`): the answer, the scene made of it, the layers, the toggle, and the map it stands in for while it is open */
|
|
660
|
-
export const newWorkState = () => ({ status: 'idle', graph: null, nodes: [], edges: [], lanes: [], counts: { work: 0, code: 0, waiting: 0 }, problems: [], layers: startLayers(), waiting: false, saved: null, bounds: null, fit: null, order: [], updating: false, stale: '', lastError: '' });
|
|
660
|
+
export const newWorkState = () => ({ status: 'idle', graph: null, nodes: [], edges: [], lanes: [], counts: { work: 0, code: 0, waiting: 0 }, problems: [], badges: new Map(), layers: startLayers(), waiting: false, saved: null, bounds: null, fit: null, order: [], updating: false, stale: '', lastError: '' });
|
|
661
661
|
|
|
662
662
|
/** Makes the scene of an answer (`workScene`), keeps the node a selection named, and sets the filters; the layout is `applyWorkLayout`'s */
|
|
663
663
|
export function setWorkGraph(state, graph, mapNodes) {
|
package/explorer/work-view.css
CHANGED
|
@@ -48,3 +48,11 @@
|
|
|
48
48
|
}
|
|
49
49
|
/* 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 */
|
|
50
50
|
body:has(.hx-stage.is-work) .hx-layers :is([data-corn="legend-key"], [data-corn="menu-section"]) { display: none; }
|
|
51
|
+
/* The Work layer on the Map view (explorer/work-badges.js, spec 0012 D4): a small pill over each node open work touches, in screen space so it reads at any zoom. The kind's colour is the border (`--hx-badge`, set from
|
|
52
|
+
`--corn-work-<kind>`), the words are the page's own text on its own surface, so the pill reads on any theme and the kind is said in words (`PR #27`), never by colour alone.
|
|
53
|
+
Its line is as high as the font's own box (a "p" or a "y" is not cut), and the placing keeps the room the pill takes (work-badges.js measures it). Decoration for the eye (aria-hidden):
|
|
54
|
+
the keyboard's words and the node panel's "Open work" say the rest. The runs' pulse (runs-map.js) is a layer of its own and is not changed. */
|
|
55
|
+
.hx-work-badges { position: absolute; inset: 0; z-index: 2; overflow: hidden; pointer-events: none; }
|
|
56
|
+
.hx-work-badges[hidden] { display: none; }
|
|
57
|
+
.hx-work-badge { position: absolute; box-sizing: border-box; display: inline-block; max-width: 14rem; padding: 0 var(--corn-space-1); border: var(--corn-border-strong) solid var(--hx-badge, var(--corn-line)); border-radius: var(--corn-radius-pill); background: color-mix(in srgb, var(--corn-surface-1) 92%, transparent); color: var(--corn-text); font-weight: 600; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transform: translateX(-50%); }
|
|
58
|
+
.hx-work-badge.is-waiting { border-width: calc(var(--corn-border-strong) + var(--corn-border)); }
|
package/explorer/work-view.js
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
* the Work view (the Work piece draws the actions into it), the Work list's `work:pick` ask by selecting that row's node, and holds the keys of the view: N and P step through
|
|
19
19
|
* the lanes, an arrow goes to the nearest node that way. Every request goes through `credentialed`;
|
|
20
20
|
* every word that comes from the forge is escaped or set as text, every link goes through `safeUrl` (work-model.js).
|
|
21
|
+
*
|
|
22
|
+
* The **Work layer** of the Map view (spec 0012 D4, work-badge-model.js and work-badges.js) shares this file's one read of the graph: turning the layer on asks for it only when the
|
|
23
|
+
* Work view has not read it, shows its loading state in the layer's row, and rides the same once-a-minute poll while it is on. Off (the default) nothing here asks for anything.
|
|
21
24
|
*/
|
|
22
25
|
|
|
23
26
|
import { state, pageInstance } from './state.js';
|
|
@@ -27,6 +30,9 @@ import { announce } from './engine/keyboard.js';
|
|
|
27
30
|
import { credentialed } from './engine/connection.js';
|
|
28
31
|
import { selectNode } from './engine/selection.js';
|
|
29
32
|
import { closeProposal, openProposal } from './engine/proposal.js';
|
|
33
|
+
import { themed as onGround } from './theme-model.js';
|
|
34
|
+
import { WORK_BADGE_LAYER, badgeIndex, badgeRowOf, badgeWords, openWorkHtml } from './work-badge-model.js';
|
|
35
|
+
import { createWorkBadges } from './work-badges.js';
|
|
30
36
|
import { signInUrl } from './engine/source.js';
|
|
31
37
|
import { mapStyleOf, workToken, workEdgeToken } from './engine/map-style.js';
|
|
32
38
|
import { t } from './engine/strings.js';
|
|
@@ -39,7 +45,7 @@ import { stepFrom } from './keyboard-model.js';
|
|
|
39
45
|
import { RUNS_POLL_MS } from './pieces/work-common.js';
|
|
40
46
|
import { showWorkRef, openForge, closeForge } from './forge-panel.js';
|
|
41
47
|
import {
|
|
42
|
-
CODE_LAYER, DRAFT_LAYER, KIND_WORDS, applyFilters, arrowTarget, landingWords, applyWorkLayout, codePanelHtml, layerRowsOf, newWorkState, nodeForAddress, openedWords, panelOf, setWorkGraph, showWork, touchedBy, workAddress, workPanelHtml,
|
|
48
|
+
CODE_LAYER, DRAFT_LAYER, KIND_WORDS, addressOf, applyFilters, arrowTarget, landingWords, applyWorkLayout, codePanelHtml, layerRowsOf, newWorkState, nodeForAddress, openedWords, panelOf, setWorkGraph, showWork, touchedBy, workAddress, workPanelHtml,
|
|
43
49
|
} from './work-model.js';
|
|
44
50
|
|
|
45
51
|
const GRAPH_URL = '/api/forge/work-graph';
|
|
@@ -51,6 +57,8 @@ let els = null; // { stage, bar, all, waiting, busy, note, lanes, loading }
|
|
|
51
57
|
let laneEls = []; // the lanes' titles on the stage, in screen space: [{ el, name, count }]
|
|
52
58
|
let laneKey = null; // the lanes they were made for
|
|
53
59
|
let offPaint = null;
|
|
60
|
+
let badges = null; // the Work layer's pills over the map (work-badges.js)
|
|
61
|
+
let badgeWas = false; // whether the layer wanted the graph at the last look: it asks for it when it comes on
|
|
54
62
|
let card = null; // the map's own card (pieces/status.js)
|
|
55
63
|
let timer = 0;
|
|
56
64
|
let seq = 0; // the answer that is waited for: an older one is dropped
|
|
@@ -74,16 +82,20 @@ export function initWorkView(opts = {}) {
|
|
|
74
82
|
document.addEventListener('click', onClick);
|
|
75
83
|
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
|
|
76
84
|
i.on('view', syncWork);
|
|
77
|
-
i.on('layers', refilter);
|
|
85
|
+
i.on('layers', () => { refilter(); syncBadges(); });
|
|
86
|
+
i.on('node:words', (node) => { const items = on() ? null : badgesOf(node); return items ? `, ${badgeWords(items)}` : undefined; }); // the keyboard's landing on a badged node says its work
|
|
78
87
|
i.on('work:open', ({ id }) => openWork({ select: id }));
|
|
79
88
|
i.on('search:more', () => (work().status === 'ok' && !on() ? work().nodes.filter((n) => n.work) : null));
|
|
80
89
|
i.on('work:waiting', ({ total }) => paintBadge(total));
|
|
81
|
-
i.on('work:available', ({ on: available }) => paintList(available));
|
|
90
|
+
i.on('work:available', ({ on: available }) => { paintList(available); i.emit('layers:redraw'); syncBadges(); });
|
|
82
91
|
i.on('work:panel', (node) => panelFor(node));
|
|
83
92
|
i.on('work:pick', (ref) => pickRef(ref));
|
|
84
93
|
mapStyleOf(i).onChange(() => { paintEdgeColors(); if (on()) { state.workRows = layerRowsOf(work().nodes).map(themed); i.emit('layers:redraw'); i.touchScene(); render(); } });
|
|
85
94
|
}
|
|
95
|
+
state.workRow = () => (offered && inst().ask('work:on') ? badgeRowOf(work(), badgeColor('pull')) : null); // the Layers menu's row under Overlays (engine/layers.js `layerRows`)
|
|
86
96
|
syncWork();
|
|
97
|
+
inst().emit('layers:redraw'); // the Layers menu's Work row, if the piece that says it is signed in has started already
|
|
98
|
+
syncBadges();
|
|
87
99
|
}
|
|
88
100
|
|
|
89
101
|
/** The List toggle is shown while the Work piece is on (a forge in the config and somebody signed in); the piece says its own `aria-expanded` */
|
|
@@ -99,7 +111,7 @@ function paintEdgeColors() {
|
|
|
99
111
|
state.workEdgeColors = colors;
|
|
100
112
|
}
|
|
101
113
|
|
|
102
|
-
/** The Work button's badge and its spoken name: "Work, 3 waiting on you" (the Work
|
|
114
|
+
/** The Work button's badge and its spoken name: "Work, 3 waiting on you" (the Work list's own words: waiting-model.js) */
|
|
103
115
|
function paintBadge(total) {
|
|
104
116
|
const btn = $('preset-work-btn');
|
|
105
117
|
if (!btn) return;
|
|
@@ -147,7 +159,9 @@ function mount() {
|
|
|
147
159
|
els = { stage, bar, all: bar.children[0], waiting: bar.children[1], list: bar.children[2], busy: bar.children[3], note, lanes, loading };
|
|
148
160
|
paintList(!!inst().ask('work:on')); // the List toggle is there while the Work piece is on: a signed-in maintainer of a forge
|
|
149
161
|
if (offPaint) offPaint();
|
|
150
|
-
|
|
162
|
+
if (badges) badges.destroy();
|
|
163
|
+
badges = createWorkBadges({ stage, state, style: () => mapStyleOf(inst()).get(), colorOf: badgeColor, wanted: badgesDrawn });
|
|
164
|
+
offPaint = onPaint((scene, camera) => { paintLanes(scene, camera); badges.sync(scene, camera); });
|
|
151
165
|
watchSize(stage);
|
|
152
166
|
card = mountStatus(stage, inst(), { follow: false, onRetry: () => load({ again: true }), focusMap: () => { if (state.canvas) state.canvas.focus(); } });
|
|
153
167
|
}
|
|
@@ -243,11 +257,11 @@ function syncWork() {
|
|
|
243
257
|
if (stage) stage.classList.toggle('is-work', open);
|
|
244
258
|
paintBar();
|
|
245
259
|
if (open !== wasOn) {
|
|
246
|
-
if (open)
|
|
260
|
+
if (open) paintBadge(work().counts.waiting);
|
|
261
|
+
inst().emit('layers:redraw'); // the Layers menu lists the Work view's rows from the first moment, the answer here or not, and the map's own again (with the Work layer's row) when the view is left
|
|
247
262
|
wasOn = open;
|
|
248
|
-
|
|
249
|
-
if (open)
|
|
250
|
-
else {
|
|
263
|
+
armPoll();
|
|
264
|
+
if (!open) {
|
|
251
265
|
if (card) card.clear();
|
|
252
266
|
closeForge({ restoreFocus: false }); // the list is the Work view's
|
|
253
267
|
if (!state.selectedNode) inst().emit('node:close'); // a piece of work the node panel showed from the lists, with nothing selected
|
|
@@ -255,13 +269,45 @@ function syncWork() {
|
|
|
255
269
|
}
|
|
256
270
|
}
|
|
257
271
|
|
|
272
|
+
/** The one poll: every minute while the Work view is open, or the Work layer is on (the same read, never a second one) */
|
|
273
|
+
function armPoll() {
|
|
274
|
+
clearTimeout(timer);
|
|
275
|
+
if (on() || layerWanted()) timer = setTimeout(poll, RUNS_POLL_MS);
|
|
276
|
+
}
|
|
277
|
+
|
|
258
278
|
function poll() {
|
|
259
279
|
clearTimeout(timer);
|
|
260
|
-
if (!on()) return;
|
|
261
|
-
|
|
280
|
+
if (!on() && !layerWanted()) return;
|
|
281
|
+
// a read on its way is this minute's: a slow forge is never asked twice at once (one that has had no answer for five minutes is given up for a new one)
|
|
282
|
+
if (document.visibilityState !== 'hidden' && !(reading && Date.now() - reading.at < STALLED_MS)) load({ again: true, quiet: true });
|
|
262
283
|
timer = setTimeout(poll, RUNS_POLL_MS);
|
|
263
284
|
}
|
|
264
285
|
|
|
286
|
+
// ---------------------------------------------------------------------------
|
|
287
|
+
// The Work layer on the Map view (spec 0012 D4)
|
|
288
|
+
// ---------------------------------------------------------------------------
|
|
289
|
+
|
|
290
|
+
/** Whether the viewer has the Work layer on and there is a forge to read: it is what asks for the graph (not the layer's state in the Work view, which has its own layers) */
|
|
291
|
+
const layerWanted = () => offered && state.activeLayers[WORK_BADGE_LAYER] === true && !!inst().ask('work:on');
|
|
292
|
+
/** The index of what is drawn: only on the Map view, with no proposal under review (its marks are the review's), and once the answer is here; null otherwise */
|
|
293
|
+
const badgesDrawn = () => (layerWanted() && state.view === 'orbit' && !state.proposal && work().status === 'ok' ? work().badges : null);
|
|
294
|
+
/** The open work touching a node, when the layer is drawing it: the node panel and the keyboard's words read it */
|
|
295
|
+
const badgesOf = (node) => { const index = badgesDrawn(); return index && node ? index.get(node.id) || null : null; };
|
|
296
|
+
/** A kind's colour as the pill is drawn: the theme's token, deepened on a light ground as the map's own are */
|
|
297
|
+
const badgeColor = (kind) => onGround(colorOf(kind), state.theme);
|
|
298
|
+
|
|
299
|
+
/** The layer came on or went off (or the forge became reachable): the first time it is on, the graph is asked for unless the Work view has it */
|
|
300
|
+
function syncBadges() {
|
|
301
|
+
const want = layerWanted();
|
|
302
|
+
if (want === badgeWas) return;
|
|
303
|
+
badgeWas = want;
|
|
304
|
+
armPoll();
|
|
305
|
+
const w = work();
|
|
306
|
+
if (want && w.status !== 'ok' && w.status !== 'loading') load({});
|
|
307
|
+
else render();
|
|
308
|
+
inst().emit('work:changed'); // a node panel open on a badged node shows its Open work, or no longer does
|
|
309
|
+
}
|
|
310
|
+
|
|
265
311
|
// ---------------------------------------------------------------------------
|
|
266
312
|
// Opening, and the answer
|
|
267
313
|
// ---------------------------------------------------------------------------
|
|
@@ -290,7 +336,34 @@ export function closeWork() {
|
|
|
290
336
|
setView('orbit');
|
|
291
337
|
}
|
|
292
338
|
|
|
293
|
-
|
|
339
|
+
/** The read on its way, if there is one: what its answer is to be used for. The Work view and the Work layer share it: a second ask while it is on its way waits for it, never starts another */
|
|
340
|
+
let reading = null;
|
|
341
|
+
/** How long a read on its way keeps the minute's poll from asking again */
|
|
342
|
+
const STALLED_MS = 5 * RUNS_POLL_MS;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Reads the graph (spec 0012 D7): once at a time. Asked while a read is on its way (the Work layer's, or the view's), it waits for that one and adds what it wants done with the answer
|
|
346
|
+
* (a node to select); a refresh (`again`) or the minute's poll starts a read of its own, which takes over what the read it replaces was to do (its answer is dropped).
|
|
347
|
+
*/
|
|
348
|
+
function load({ select = null, ask = null, again = false, quiet = false } = {}) {
|
|
349
|
+
if (reading && !again && !quiet) {
|
|
350
|
+
if (select) reading.select = select;
|
|
351
|
+
if (ask) reading.ask = ask;
|
|
352
|
+
reading.quiet = false;
|
|
353
|
+
return reading.done;
|
|
354
|
+
}
|
|
355
|
+
if (reading) { // the read on its way is dropped for this one: the node it was to select, and its being said, are this one's now
|
|
356
|
+
select = select || reading.select;
|
|
357
|
+
ask = ask || reading.ask;
|
|
358
|
+
quiet = quiet && reading.quiet;
|
|
359
|
+
}
|
|
360
|
+
const mine = { select, ask, quiet, done: null, at: Date.now() };
|
|
361
|
+
mine.done = fetchGraph(mine, again).finally(() => { if (reading === mine) reading = null; });
|
|
362
|
+
reading = mine;
|
|
363
|
+
return mine.done;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
async function fetchGraph(request, again) {
|
|
294
367
|
const i = inst();
|
|
295
368
|
const mine = ++seq;
|
|
296
369
|
const w = work();
|
|
@@ -300,25 +373,26 @@ async function load({ select = null, ask = null, again = false, quiet = false }
|
|
|
300
373
|
w.status = 'loading';
|
|
301
374
|
card.clear();
|
|
302
375
|
paintBar();
|
|
376
|
+
if (!on()) i.emit('layers:redraw'); // the Work layer's row says "reading…"
|
|
303
377
|
announce(i, 'Work: reading the work from the forge.');
|
|
304
|
-
} else if (!quiet) { w.updating = true; paintBar(); } // a refresh keeps the last answer on the map until the new one is here
|
|
378
|
+
} else if (!request.quiet) { w.updating = true; paintBar(); } // a refresh keeps the last answer on the map until the new one is here
|
|
305
379
|
let res;
|
|
306
380
|
try {
|
|
307
|
-
res = await credentialed(i)(GRAPH_URL, { headers: { accept: 'application/json', ...(again && !quiet ? { 'cache-control': 'no-cache' } : {}) } }); // Refresh asks the forge again
|
|
381
|
+
res = await credentialed(i)(GRAPH_URL, { headers: { accept: 'application/json', ...(again && !request.quiet ? { 'cache-control': 'no-cache' } : {}) } }); // Refresh asks the forge again
|
|
308
382
|
} catch {
|
|
309
383
|
if (mine !== seq) return false;
|
|
310
|
-
return refuse(i.offline() ? { state: 'offline' } : { state: 'server', message: 'cornfield could not be reached.' }, quiet);
|
|
384
|
+
return refuse(i.offline() ? { state: 'offline' } : { state: 'server', message: 'cornfield could not be reached.' }, request.quiet);
|
|
311
385
|
}
|
|
312
386
|
if (mine !== seq) return false;
|
|
313
|
-
if (res.status === 401 || res.status === 403) return refuse({ state: 'sign-in', status: res.status, signIn: signInUrl(location.origin, location.href) }, quiet);
|
|
387
|
+
if (res.status === 401 || res.status === 403) return refuse({ state: 'sign-in', status: res.status, signIn: signInUrl(location.origin, location.href) }, request.quiet);
|
|
314
388
|
let body = null;
|
|
315
389
|
try { body = await res.json(); } catch { body = null; }
|
|
316
390
|
if (mine !== seq) return false;
|
|
317
391
|
if (!res.ok || !body || body.ok === false || !Array.isArray(body.nodes)) {
|
|
318
392
|
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}.`;
|
|
319
|
-
return refuse({ state: 'server', message: words }, quiet);
|
|
393
|
+
return refuse({ state: 'server', message: words }, request.quiet);
|
|
320
394
|
}
|
|
321
|
-
return arrive(body,
|
|
395
|
+
return arrive(body, request);
|
|
322
396
|
}
|
|
323
397
|
|
|
324
398
|
/**
|
|
@@ -342,10 +416,12 @@ function refuse(detail, quiet) {
|
|
|
342
416
|
w.problems = [];
|
|
343
417
|
w.stale = '';
|
|
344
418
|
w.lastError = '';
|
|
345
|
-
|
|
346
|
-
|
|
419
|
+
w.badges = new Map();
|
|
420
|
+
if (on()) { showWork(state); applyWorkLayout(state, { phone: isPhone() }); inst().touchScene(); inst().emit('layers:redraw'); render(); } else { inst().emit('layers:redraw'); render(); } // off the Work view the layer's row says why: the map shows no card for it
|
|
421
|
+
if (on()) card.show(detail);
|
|
347
422
|
paintBar();
|
|
348
423
|
paintBadge(0);
|
|
424
|
+
inst().emit('work:changed');
|
|
349
425
|
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.'}`);
|
|
350
426
|
return false;
|
|
351
427
|
}
|
|
@@ -356,7 +432,9 @@ function arrive(body, { select, ask, quiet }) {
|
|
|
356
432
|
const first = w.status !== 'ok';
|
|
357
433
|
const before = state.selectedNode ? state.selectedNode.id : null;
|
|
358
434
|
const base = state.baseNodes && state.baseNodes.length ? state.baseNodes : (w.saved ? w.saved.nodes : state.nodes);
|
|
435
|
+
const had = w.badges ? w.badges.size : -1;
|
|
359
436
|
setWorkGraph(state, body, base);
|
|
437
|
+
w.badges = badgeIndex(w.nodes, w.edges);
|
|
360
438
|
w.status = 'ok';
|
|
361
439
|
w.updating = false;
|
|
362
440
|
w.lastError = '';
|
|
@@ -374,6 +452,13 @@ function arrive(body, { select, ask, quiet }) {
|
|
|
374
452
|
}
|
|
375
453
|
paintBar();
|
|
376
454
|
paintBadge(w.counts.waiting);
|
|
455
|
+
i.emit('work:changed'); // the node panel's section for the work touching its node is drawn again, if it says something else now
|
|
456
|
+
if (!on()) { // the Map view: the Work layer's badges, from the same answer
|
|
457
|
+
if (first || !quiet || had !== w.badges.size) i.emit('layers:redraw'); // the row's count
|
|
458
|
+
render(); // the badges are drawn from this answer
|
|
459
|
+
if ((first || !quiet) && badgesDrawn()) announce(i, `Work layer: ${w.badges.size} ${w.badges.size === 1 ? 'node has' : 'nodes have'} open work.`);
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
377
462
|
// 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
|
|
378
463
|
const opened = first || !quiet ? openedWords(w.counts) : '';
|
|
379
464
|
const id = select || nodeForAddress(ask, w.nodes);
|
|
@@ -459,7 +544,9 @@ function panelFor(node) {
|
|
|
459
544
|
const p = node.old ? panelOf(node, [], []) : panelOf(node, w.nodes, w.edges);
|
|
460
545
|
return { replace: true, badge: p.kind, title: p.title, html: workPanelHtml(p, node, { color: colorOf }) };
|
|
461
546
|
}
|
|
462
|
-
|
|
547
|
+
if (on()) return { replace: false, html: codePanelHtml(node, touchedBy(node, w.nodes, w.edges), { color: colorOf }) };
|
|
548
|
+
const items = badgesOf(node); // the Map view with the Work layer on: the open work touching the node, each a link into the Work view
|
|
549
|
+
return items ? { replace: false, html: openWorkHtml(items, { color: colorOf, address: (id) => { const n = w.nodes.find((x) => x.id === id); return n ? addressOf(n) : null; } }) } : undefined;
|
|
463
550
|
}
|
|
464
551
|
|
|
465
552
|
/** A row of the Work list (or a link) names a piece of work: its node is selected on the map, with the camera on it, and the live region says where it is; false when the view does not draw it */
|
|
@@ -505,6 +592,12 @@ function onClick(e) {
|
|
|
505
592
|
if (show && on()) { setWaiting(show.dataset.workShow === 'waiting'); return; }
|
|
506
593
|
const act = t_.closest('[data-work-action]');
|
|
507
594
|
if (!act) return;
|
|
595
|
+
if (act.dataset.workAction === 'open-item') { // a node panel's "Open work" link: the Work view opens on that piece of work (a new tab, by the link's own address, is left alone)
|
|
596
|
+
if (e.button || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
597
|
+
e.preventDefault();
|
|
598
|
+
openWork({ select: act.dataset.id });
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
508
601
|
if (act.dataset.workAction === 'review') { reviewSpec(act.dataset.slug, act.dataset.source); return; }
|
|
509
602
|
const node = state.nodes.find((n) => n.id === act.dataset.id);
|
|
510
603
|
if (node && act.dataset.workAction === 'show-on-map') showOnMap(node.id);
|
|
@@ -539,7 +632,7 @@ export async function followWorkAddress(search = location.search) {
|
|
|
539
632
|
return openWork({ ask: ask.kind ? ask : null });
|
|
540
633
|
}
|
|
541
634
|
|
|
542
|
-
/** What an address that asks for work is, for the page to decide whether it is the Work view's (the old Work
|
|
635
|
+
/** What an address that asks for work is, for the page to decide whether it is the Work view's (the old Work list's links are `?run=` and `?issue=` too: step 3 of spec 0012 moves them) */
|
|
543
636
|
export const asksForWork = (search) => workAddress(search) !== null;
|
|
544
637
|
|
|
545
638
|
function spend() {
|
|
@@ -557,6 +650,10 @@ export function resetWorkViewForTests() {
|
|
|
557
650
|
clearTimeout(timer);
|
|
558
651
|
if (offPaint) offPaint();
|
|
559
652
|
offPaint = null;
|
|
653
|
+
if (badges) badges.destroy();
|
|
654
|
+
badges = null;
|
|
655
|
+
badgeWas = false;
|
|
656
|
+
reading = null;
|
|
560
657
|
laneEls = [];
|
|
561
658
|
laneKey = null;
|
|
562
659
|
wired = false;
|