cornfield 0.55.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/contrast.js +12 -1
- package/core/schema.js +6 -0
- package/core/strings.js +1 -2
- 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/page.css +0 -8
- package/explorer/css/sheets.css +1 -1
- package/explorer/css/work.css +9 -30
- package/explorer/deep-link.js +11 -24
- 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/map-style.js +4 -1
- 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-model.js +2 -36
- package/explorer/forge-panel.js +4 -9
- package/explorer/index.html +2 -11
- package/explorer/instance-state.js +0 -6
- package/explorer/instance.js +15 -9
- package/explorer/page-pieces.js +1 -1
- package/explorer/page.js +5 -4
- package/explorer/pieces/decision.js +3 -3
- package/explorer/pieces/layers.js +1 -1
- package/explorer/pieces/node-panel.js +38 -14
- package/explorer/pieces/proposal.js +6 -6
- package/explorer/pieces/review.js +2 -2
- package/explorer/pieces/work-agent.js +3 -2
- package/explorer/pieces/work-common.js +14 -15
- package/explorer/pieces/work-confirm.js +11 -10
- package/explorer/pieces/work-data.js +24 -31
- package/explorer/pieces/work-deploys.js +42 -41
- package/explorer/pieces/work-issues.js +32 -29
- package/explorer/pieces/work-list.js +406 -0
- package/explorer/pieces/work-markup.js +9 -14
- package/explorer/pieces/work-notes.js +0 -1
- package/explorer/pieces/work-paint.js +74 -62
- package/explorer/pieces/work-prs.js +25 -66
- package/explorer/pieces/work-runs.js +47 -57
- package/explorer/pieces/work-specs.js +19 -2
- package/explorer/pieces/work-threads.js +28 -48
- package/explorer/pieces/work.js +38 -40
- package/explorer/proposal-model.js +6 -6
- package/explorer/proposal.js +1 -1
- package/explorer/runs-view.js +10 -18
- package/explorer/scene.js +1 -3
- package/explorer/sheets.js +1 -1
- package/explorer/tokens.css +6 -2
- package/explorer/waiting-view.js +3 -3
- package/explorer/work-badge-model.js +161 -0
- package/explorer/work-badges.js +143 -0
- package/explorer/work-model.js +80 -39
- package/explorer/work-view.css +11 -4
- package/explorer/work-view.js +193 -68
- package/package.json +1 -1
- package/explorer/pieces/work-events.js +0 -285
|
@@ -170,7 +170,7 @@ export function proposalPanelHtml(item) {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
// ---------------------------------------------------------------------------
|
|
173
|
-
// A proposal as a row of the Work
|
|
173
|
+
// A proposal as a row of the Work list's Specs tab
|
|
174
174
|
// ---------------------------------------------------------------------------
|
|
175
175
|
|
|
176
176
|
/** Where a listing entry is, as a line of meta: "PR #11", or the checkout or worktree it is in; a proposal that is also somewhere else says so ("PR #11, and a copy in the checkout") */
|
|
@@ -212,12 +212,12 @@ export function mergeSpecs(entries) {
|
|
|
212
212
|
* One row: title, a pill that says its review state (To decide, Changed since approved, Sent back, Approved, Draft PR, Local, spec 0010 D4),
|
|
213
213
|
* who and when beside it ("Approved by maintainer-one \u00b7 2 hours ago", "Waiting 2 days"), a line of what it is for, and the meta (spec number,
|
|
214
214
|
* where it is, +added ~changed \u2212removed, scenarios). A review that could not be read says so, with a way to try again, and never looks
|
|
215
|
-
* unreviewed. A proposal that could not be read is a row that says why and opens nothing.
|
|
215
|
+
* unreviewed. A proposal that could not be read is a row that says why and opens nothing. A row selects the proposal's node (`data-work-ref`: work-list.js); the review is opened from the node panel.
|
|
216
216
|
* What the forge said (a login, a date) is escaped; the pill's state is one of a fixed list.
|
|
217
217
|
* @param {{ slug: string, source: string, title?: string, summary?: string, spec?: string, pull?: {number: number, draft?: boolean}, review?: object | null, counts?: {added?: number, changed?: number, removed?: number, scenarios?: number}, errors?: number, error?: string }} entry
|
|
218
|
-
* @param {{
|
|
218
|
+
* @param {{ shown?: string | null, nowMs?: number }} [opts] the row the node panel shows now (`proposal:<slug>`); the clock
|
|
219
219
|
*/
|
|
220
|
-
export function specRowHtml(entry, {
|
|
220
|
+
export function specRowHtml(entry, { shown = null, nowMs = Date.now() } = {}) {
|
|
221
221
|
const head = `<span class="hx-forge-title">${escHtml(entry.title || entry.slug)}</span>`;
|
|
222
222
|
if (entry.error) {
|
|
223
223
|
return `<li class="hx-forge-item"><div class="hx-forge-row hx-forge-spec" data-corn="row">${head}<span class="hx-forge-sum hx-error-text">${escHtml(entry.error)}</span><span class="hx-forge-meta">${escHtml(specWhere(entry))}</span></div></li>`;
|
|
@@ -237,9 +237,9 @@ export function specRowHtml(entry, { current = null, nowMs = Date.now() } = {})
|
|
|
237
237
|
c.scenarios ? `<span>${c.scenarios} ${c.scenarios === 1 ? 'scenario' : 'scenarios'}</span>` : '',
|
|
238
238
|
entry.errors ? `<span class="hx-warn">${entry.errors} ${entry.errors === 1 ? 'problem' : 'problems'}</span>` : '',
|
|
239
239
|
].filter(Boolean).join('');
|
|
240
|
-
const mine =
|
|
240
|
+
const mine = shown === `proposal:${entry.slug}`;
|
|
241
241
|
const unread = state === 'unknown' ? `<p class="hx-forge-meta hx-forge-unread" data-corn="message" data-corn-state="failure">${escHtml(entry.review && entry.review.error ? entry.review.error : 'The forge could not be asked.')} <button type="button" class="hx-btn hx-forge-act" data-corn-kind="quiet" data-action="retry-forge" aria-label="Try again: ${escHtml(entry.title || entry.slug)}">Try again</button></p>` : '';
|
|
242
|
-
return `<li class="hx-forge-item"><button type="button" class="hx-forge-row hx-forge-spec" data-
|
|
242
|
+
return `<li class="hx-forge-item"><button type="button" class="hx-forge-row hx-forge-spec" data-work-ref="proposal:${escHtml(entry.slug)}" aria-pressed="${mine}" data-corn="row">`
|
|
243
243
|
+ `<span class="hx-forge-line">${head}${pill}</span>`
|
|
244
244
|
+ `${entry.summary ? `<span class="hx-forge-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-forge-meta hx-forge-facts">${meta}</span></button>${unread}</li>`;
|
|
245
245
|
}
|
package/explorer/proposal.js
CHANGED
|
@@ -48,7 +48,7 @@ for (const name of Object.keys(ADAPT)) {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
/** What the server listed last, for the Work
|
|
51
|
+
/** What the server listed last, for the Work list's Specs tab: the entries (null before the first answer), why the list could not be read, why the spec PRs are missing, and when */
|
|
52
52
|
export const proposalListing = () => E.proposalListing(pageInstance());
|
|
53
53
|
/** Calls `fn` each time the list is read again; returns the way to stop */
|
|
54
54
|
export const onProposalListing = (fn) => E.onProposalListing(pageInstance(), fn);
|
package/explorer/runs-view.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { relativeTime } from './review-model.js';
|
|
12
|
-
import { runTone, canRetry, aboutWords, runName, statusWords, statusWhy, runMeta, canStop, canAnswer,
|
|
12
|
+
import { runTone, canRetry, aboutWords, runName, statusWords, statusWhy, runMeta, canStop, canAnswer, limitRows, checksWords, timelineWords, nodeLabels, collisionWords, answerWords } from './runs-model.js';
|
|
13
13
|
import { cornState, cornStateAttr, stateIconHtml } from './corn-state.js';
|
|
14
14
|
import { t } from './strings.js';
|
|
15
15
|
import { runGroups } from './waiting-model.js';
|
|
@@ -25,7 +25,6 @@ import { runGroupHeadingHtml } from './waiting-view.js';
|
|
|
25
25
|
* @property {string} forgeType 'github' | 'forgejo'
|
|
26
26
|
* @property {number} now
|
|
27
27
|
* @property {{ id: string, label?: string }[]} nodes the map's nodes, for names
|
|
28
|
-
* @property {string | null} selected the run lit on the map
|
|
29
28
|
* @property {Set<string>} timelines the runs whose timeline is open
|
|
30
29
|
* @property {boolean} busy an action is in flight
|
|
31
30
|
* @property {Map<string, string>} [replies] the reply typed so far for each waiting run, so a repaint keeps it
|
|
@@ -143,7 +142,6 @@ export function loadingLinesHtml(n = 1) {
|
|
|
143
142
|
/** One run */
|
|
144
143
|
export function runHtml(ctx, run, all) {
|
|
145
144
|
const say = ctx.t || t;
|
|
146
|
-
const lit = ctx.selected === run.runId;
|
|
147
145
|
const open = ctx.timelines.has(run.runId);
|
|
148
146
|
const why = statusWhy(run);
|
|
149
147
|
const name = ctx.esc(runName(run, ctx.now));
|
|
@@ -157,8 +155,6 @@ export function runHtml(ctx, run, all) {
|
|
|
157
155
|
const limits = limitRows(run);
|
|
158
156
|
const count = (run.timeline || []).length;
|
|
159
157
|
const links = linksHtml(ctx, run);
|
|
160
|
-
const noNodes = !(run.nodes || []).length;
|
|
161
|
-
const lightWords = lit ? 'Lit on the map' : 'Light on the map';
|
|
162
158
|
const result = resultHtml(ctx, run);
|
|
163
159
|
return `<li class="hx-run hx-forge-file" data-run="${ctx.esc(run.runId)}" tabindex="-1" data-corn="run"${cornStateAttr(run.status)}>
|
|
164
160
|
<div class="hx-run-head">${runPillHtml(ctx, run, statusWords(run))} <span class="hx-name">${ctx.esc(run.kind)} on ${ctx.esc(aboutWords(run.refs))}</span>${run.profile ? ` <span class="hx-faint">profile ${ctx.esc(run.profile)}</span>` : ''}</div>
|
|
@@ -171,25 +167,21 @@ export function runHtml(ctx, run, all) {
|
|
|
171
167
|
${links ? `<p class="hx-forge-meta">${links}</p>` : ''}
|
|
172
168
|
${answering ? `${answerHtml(ctx, run)}${result}` : unsentHtml(ctx, run)}${run.answer && !answering ? answeredHtml(ctx, run) : ''}
|
|
173
169
|
<div class="hx-run-actions" data-corn="run-actions">${stop}${retry}
|
|
174
|
-
<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-run-select="${ctx.esc(run.runId)}" aria-pressed="${lit}" aria-label="${lightWords}: ${name}"${noNodes ? ` disabled title="No node on the map yet, so there is nothing to light" aria-describedby="run-nodes-${ctx.esc(run.runId)}"` : ''}>${lightWords}</button>
|
|
175
170
|
<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-run-timeline="${ctx.esc(run.runId)}" aria-expanded="${open}" aria-controls="run-tl-${ctx.esc(run.runId)}">Timeline (${count})</button></div>
|
|
176
171
|
${answering ? '' : result}
|
|
177
172
|
${open ? timelineHtml(ctx, run, all) : ''}</li>`;
|
|
178
173
|
}
|
|
179
174
|
|
|
180
175
|
/**
|
|
181
|
-
* The list, in groups (spec 0010 D6): Needs you (oldest question first), In motion, Finished (each newest first), each starting with a heading that
|
|
182
|
-
* says how many
|
|
183
|
-
* @param {ViewContext} ctx
|
|
176
|
+
* The Runs list of the Work list, in groups (spec 0010 D6): Needs you (oldest question first), In motion, Finished (each newest first), each starting with a heading that
|
|
177
|
+
* says how many. A row is a button that selects the run's node (work-list.js); the card, with its answer field, is the node panel's (`runHtml`).
|
|
178
|
+
* @param {ViewContext & { shown?: string | null }} ctx `shown`: the run the node panel has now
|
|
184
179
|
* @param {object[]} runs
|
|
185
180
|
*/
|
|
186
|
-
export function
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
<p class="hx-forge-meta hx-faint">The same request under each profile, side by side.</p>
|
|
193
|
-
<ul class="hx-run-columns" aria-label="${ctx.esc(g.runs.length)} profiles compared">${g.runs.map((r) => runHtml(ctx, r, runs)).join('')}</ul></section></li>`;
|
|
194
|
-
}).join('')).join('');
|
|
181
|
+
export function runRowsHtml(ctx, runs) {
|
|
182
|
+
const say = ctx.t || t;
|
|
183
|
+
const row = (run) => `<li class="hx-forge-item" data-key="${ctx.esc(run.runId)}"><button type="button" class="hx-forge-row" data-work-ref="run:${ctx.esc(run.runId)}" aria-pressed="${ctx.shown === run.runId}" data-corn="row"${cornStateAttr(run.status)}>
|
|
184
|
+
<span class="hx-forge-title">${ctx.esc(run.kind)} on ${ctx.esc(aboutWords(run.refs))}</span>
|
|
185
|
+
<span class="hx-forge-meta">${runPillHtml(ctx, run, statusWords(run))} ${ctx.esc(runMeta(run, ctx.now))}</span></button></li>`;
|
|
186
|
+
return runGroups(runs).map((group) => runGroupHeadingHtml(group, say) + group.items.flatMap((g) => (g.kind === 'run' ? [g.run] : g.runs)).map(row).join('')).join('');
|
|
195
187
|
}
|
package/explorer/scene.js
CHANGED
|
@@ -177,7 +177,6 @@ import { NODE_THEMES, shapeOf } from '../core/schema.js';
|
|
|
177
177
|
import { WORK_KINDS } from '../core/schema.js';
|
|
178
178
|
import { hasGlyph } from './glyphs.js';
|
|
179
179
|
import { outageFor, paintOutage } from './outage-model.js';
|
|
180
|
-
import { paintForge } from './forge-panel-model.js';
|
|
181
180
|
import { lightColor, lightenScene, parseColor } from './theme-model.js';
|
|
182
181
|
import { matchIds } from './search-match.js';
|
|
183
182
|
import { nodeColor } from './css-color.js';
|
|
@@ -500,7 +499,7 @@ function buildEdges(state, subgraph, reduceMotion) {
|
|
|
500
499
|
const target = byId.get(edge.to);
|
|
501
500
|
if (!source || !target || !isNodeVisible(state, source) || !isNodeVisible(state, target)) return;
|
|
502
501
|
|
|
503
|
-
if (state.view === 'work') { out.push(state.workEdge(edge, source, target, subgraph ? subgraph.connectedEdgeKeys.has(focusKey(edge)) : true, !!subgraph, edgeKeyOf(edge), { PROPOSED_DASH, USAGE_DASH })); return; } // the Work view's lines are work-model.js's (the page installs `workEdge`)
|
|
502
|
+
if (state.view === 'work') { out.push(state.workEdge(edge, source, target, subgraph ? subgraph.connectedEdgeKeys.has(focusKey(edge)) : true, !!subgraph, edgeKeyOf(edge), { PROPOSED_DASH, USAGE_DASH }, state.workEdgeColors)); return; } // the Work view's lines are work-model.js's (the page installs `workEdge`)
|
|
504
503
|
if (preset) return flow(edge, source, target);
|
|
505
504
|
if (state.view === 'house') { const how = houseEdgeStyle(edge, source, target); if (how === 'flow') flow(edge, source, target); else if (how === 'link') out.push(linkEdge(edge, source, target, subgraph)); return; }
|
|
506
505
|
|
|
@@ -758,7 +757,6 @@ export function buildScene(state, opts = {}) {
|
|
|
758
757
|
const colours = { nodes: scene.nodes.map((n) => n.color), edges: scene.edges.map((e) => e.color) };
|
|
759
758
|
if (state.scenario) paintOutage(scene, outageFor(state.scenario, state.nodes, state.edges)); // CLOUD-07: red, amber, violet by when the outage bites
|
|
760
759
|
if (state.scenario) paintVerdict(scene, state.scenario); // PHY-10: red, green or amber by the step's permission check
|
|
761
|
-
if (state.forgeLit) paintForge(scene, state.forgeLit); // CF-07: the selected pull request's nodes, the rest faded
|
|
762
760
|
// The nodes and edges a painter above gave a colour: the map's own styling (map-style.js) leaves them to it
|
|
763
761
|
scene.nodes.forEach((n, i) => { if (colours.nodes.length === scene.nodes.length && n.color !== colours.nodes[i]) scene.painted.nodes.add(n.id); });
|
|
764
762
|
scene.edges.forEach((e, i) => { if (colours.edges.length === scene.edges.length && e.color !== colours.edges[i]) scene.painted.edges.add(e.key); });
|
package/explorer/sheets.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A bridge (spec 0011 D2, step 4): the phone's bottom sheets now live in engine/sheets.js, one set per instance (the node panel registers its
|
|
5
5
|
* own, pieces/node-panel.js, and so does the proposal's bar, pieces/proposal.js). This file keeps the old names for the modules that are not yet on an
|
|
6
|
-
* instance (the Work
|
|
6
|
+
* instance (the Work list, deep links, the House), bound to the page's instance. It goes when the last of them is converted.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { pageInstance } from './state.js';
|
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));
|
|
@@ -199,6 +199,10 @@
|
|
|
199
199
|
--corn-work-run: auto;
|
|
200
200
|
--corn-work-pull: auto;
|
|
201
201
|
--corn-work-deploy: auto;
|
|
202
|
+
/* …and its lines: a link between work, a link to code, and what a proposal adds (core/schema.js WORK_EDGE_THEMES) */
|
|
203
|
+
--corn-work-edge-work: auto;
|
|
204
|
+
--corn-work-edge-code: auto;
|
|
205
|
+
--corn-work-edge-adds: auto;
|
|
202
206
|
/* Node fill by group */
|
|
203
207
|
--corn-map-group-app: auto;
|
|
204
208
|
--corn-map-group-pkg: auto;
|
package/explorer/waiting-view.js
CHANGED
|
@@ -13,9 +13,9 @@ import { specGroupTitle, runGroupTitle, groupCountWords } from './waiting-model.
|
|
|
13
13
|
* The Specs tab's groups, each a heading with its count and its rows. Drafts past ten rows are folded behind a button on the header
|
|
14
14
|
* (`draftsOpen` says whether the person opened it). With a search, a group's count reads "2 of 6".
|
|
15
15
|
* @param {ReturnType<import('./waiting-model.js').specGroups>} groups
|
|
16
|
-
* @param {{
|
|
16
|
+
* @param {{ shown?: string | null, nowMs?: number, draftsOpen?: boolean | null, say?: (key: string) => string }} [opts]
|
|
17
17
|
*/
|
|
18
|
-
export function specGroupsHtml(groups, {
|
|
18
|
+
export function specGroupsHtml(groups, { shown = null, nowMs = Date.now(), draftsOpen = null, say } = {}) {
|
|
19
19
|
return groups.map((g) => {
|
|
20
20
|
const id = `spec-group-${g.key}`;
|
|
21
21
|
const words = `${specGroupTitle(g.key, say)} · ${groupCountWords(g)}`;
|
|
@@ -24,7 +24,7 @@ export function specGroupsHtml(groups, { current = null, nowMs = Date.now(), dra
|
|
|
24
24
|
const title = foldable
|
|
25
25
|
? `<button type="button" class="hx-forge-gtoggle" data-spec-group-toggle="${escHtml(g.key)}" aria-expanded="${!folded}" aria-controls="${id}-list" data-corn-kind="quiet">${escHtml(words)}</button>`
|
|
26
26
|
: escHtml(words);
|
|
27
|
-
const rows = g.rows.map((r) => specRowHtml(r.entry, {
|
|
27
|
+
const rows = g.rows.map((r) => specRowHtml(r.entry, { shown, nowMs })).join('');
|
|
28
28
|
return `<li class="hx-forge-group hx-spec-group" data-key="${id}" data-corn="spec-group" data-group="${escHtml(g.key)}"><h3 class="hx-forge-gtitle" id="${id}">${title}</h3>`
|
|
29
29
|
+ `<ul class="hx-forge-list" id="${id}-list" aria-labelledby="${id}"${folded ? ' hidden' : ''}>${rows}</ul></li>`;
|
|
30
30
|
}).join('');
|
|
@@ -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
|
+
}
|