@popcorn245/cornfield 0.59.0 → 0.60.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/explorer/css/node-panel.css +13 -0
- package/explorer/history-model.js +178 -0
- package/explorer/history.js +78 -0
- package/explorer/instance-state.js +2 -0
- package/explorer/instance.js +2 -0
- package/explorer/page.js +2 -0
- package/explorer/pieces/node-panel.js +23 -1
- package/explorer/scene.js +3 -1
- package/package.json +1 -1
|
@@ -188,3 +188,16 @@
|
|
|
188
188
|
/* The head never shrinks: the body is a flex column that scrolls, and a short box (a panel in a host's 200px place, a short window) would squash the head to its
|
|
189
189
|
min-height, laying a title that wraps, or a kicker that does ("Added by" a proposal), over the line under it */
|
|
190
190
|
.hx-drawer-head { min-height: var(--corn-panel-head-height); flex-shrink: 0; }
|
|
191
|
+
|
|
192
|
+
/* History (spec 0014 D2): a node's commits, each with its trail from spec to issue to pull request to commit; a gap is dashed */
|
|
193
|
+
.hx-history-stats { margin: 0; color: var(--corn-text-2); font-size: var(--corn-text-sm); }
|
|
194
|
+
.hx-history-k { margin: var(--corn-space-3) 0 var(--corn-space-1); font-size: var(--corn-text-xs); font-weight: 600; color: var(--corn-text-3); text-transform: uppercase; letter-spacing: 0.04em; }
|
|
195
|
+
.hx-history-issues { margin: var(--corn-space-2) 0 0; font-size: var(--corn-text-sm); color: var(--corn-text-2); }
|
|
196
|
+
.hx-history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--corn-space-2); }
|
|
197
|
+
.hx-history-commit { display: flex; flex-direction: column; gap: var(--corn-space-1); padding: var(--corn-space-3) var(--corn-space-4); border: var(--corn-border) solid var(--corn-line-soft); border-radius: var(--corn-radius-sm); background: var(--corn-surface-2); }
|
|
198
|
+
.hx-history-subject { color: var(--corn-text); overflow-wrap: anywhere; }
|
|
199
|
+
.hx-trail { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-1); }
|
|
200
|
+
.hx-trail-arrow { color: var(--corn-text-3); font-size: var(--corn-text-xs); }
|
|
201
|
+
.hx-trail-chip { display: inline-flex; align-items: center; padding: 0 var(--corn-space-2); min-height: 22px; border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); color: var(--corn-text-2); font-size: var(--corn-text-xs); text-decoration: none; white-space: nowrap; }
|
|
202
|
+
a.hx-trail-chip:hover { border-color: var(--corn-accent-hover); color: var(--corn-text); }
|
|
203
|
+
.hx-trail-chip[data-trail="gap"] { border-style: dashed; color: var(--corn-text-3); }
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/history-model
|
|
3
|
+
*
|
|
4
|
+
* The pure half of a node's history (spec 0014 D2): the links of a commit's trail on the forge, and the node panel's History section.
|
|
5
|
+
* No DOM, no state, no fetch; explorer/history.js holds the answer of `GET /api/history` (core/history.js) and asks these.
|
|
6
|
+
*
|
|
7
|
+
* forgeLinks(forge) { commit(sha), pull(n), issue(n) }: where each is on the forge's site, or null (only https; GitHub and Forgejo)
|
|
8
|
+
* specFiles(nodes) spec number -> its file (`docs/specs/0012-work-as-a-view.md`), from the map's doc pages
|
|
9
|
+
* nodeTrail(history, nodeId) a node's commits, newest first, with what the History section counts
|
|
10
|
+
* trailHtml(commit, ctx) a commit's trail: `Spec 0012 → Issue #283 → PR #284 → 0281cba`, a gap dashed (`no spec`, `no issue`)
|
|
11
|
+
* historySectionHtml(node, ctx) the node panel's History section
|
|
12
|
+
* specReach(history, spec) the nodes a spec's commits touched, and how many commits named it
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { escapeHtml as esc } from '../core/text.js';
|
|
16
|
+
import { fileUrl } from './file-url.js';
|
|
17
|
+
|
|
18
|
+
/** The most commits the section lists before "Show all N" */
|
|
19
|
+
export const HISTORY_CAP = 12;
|
|
20
|
+
|
|
21
|
+
/** Where a commit, a pull request and an issue are on each forge's site */
|
|
22
|
+
const SHAPES = {
|
|
23
|
+
github: { commit: 'commit', pull: 'pull', issue: 'issues' },
|
|
24
|
+
forgejo: { commit: 'commit', pull: 'pulls', issue: 'issues' },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The links of a trail on the forge, or null when there is no forge cornfield can link to. Built like file-url.js: `URL`, each segment encoded,
|
|
29
|
+
* only `https:`, no user name and no backslash in `forge.url`.
|
|
30
|
+
* @param {{ type: string, url: string, repo: string, baseBranch?: string } | null} forge the client config's
|
|
31
|
+
*/
|
|
32
|
+
export function forgeLinks(forge) {
|
|
33
|
+
const shape = forge && Object.hasOwn(SHAPES, forge.type) ? SHAPES[forge.type] : null;
|
|
34
|
+
const repo = forge && typeof forge.repo === 'string' ? forge.repo.split('/') : [];
|
|
35
|
+
if (!shape || repo.length !== 2 || !repo.every((s) => /^[A-Za-z0-9_.-]+$/.test(s) && s !== '.' && s !== '..')) return null;
|
|
36
|
+
let base;
|
|
37
|
+
try {
|
|
38
|
+
base = new URL(forge.url);
|
|
39
|
+
if (base.protocol !== 'https:' || base.username || base.password || String(forge.url).includes('\\')) return null;
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const at = (...segs) => {
|
|
44
|
+
const u = new URL(base.href);
|
|
45
|
+
u.pathname = `${u.pathname.replace(/\/+$/, '')}/${[...repo, ...segs].map(encodeURIComponent).join('/')}`;
|
|
46
|
+
u.search = '';
|
|
47
|
+
u.hash = '';
|
|
48
|
+
return u.href;
|
|
49
|
+
};
|
|
50
|
+
const num = (n) => Number.isInteger(n) && n > 0;
|
|
51
|
+
return {
|
|
52
|
+
commit: (sha) => (typeof sha === 'string' && /^[0-9a-f]{7,40}$/.test(sha) ? at(shape.commit, sha) : null),
|
|
53
|
+
pull: (n) => (num(n) ? at(shape.pull, String(n)) : null),
|
|
54
|
+
issue: (n) => (num(n) ? at(shape.issue, String(n)) : null),
|
|
55
|
+
file: (path) => fileUrl(forge, path, forge.baseBranch),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A spec's short title from its doc page: "Work as a view" from "Spec 0012: Work as a view (issues, …)"; else its number */
|
|
60
|
+
const titleOf = (n, num) => {
|
|
61
|
+
const m = typeof n.desc === 'string' && /^Spec \d{4}:\s*([^(]+?)\s*(?:\(|$)/.exec(n.desc);
|
|
62
|
+
return m ? m[1] : `Spec ${num}`;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** Spec number -> its file, from the map's pages of `docs/specs/NNNN-*.md` (the docs deriver puts each doc on the map) */
|
|
66
|
+
export function specFiles(nodes) {
|
|
67
|
+
const out = new Map();
|
|
68
|
+
for (const n of nodes || []) {
|
|
69
|
+
const m = n && typeof n.file === 'string' && /^docs\/specs\/(\d{4})-[^/]+\.md$/.exec(n.file);
|
|
70
|
+
if (m && !out.has(m[1])) out.set(m[1], { file: n.file, label: titleOf(n, m[1]), id: n.id });
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A node's commits, newest first, and what the section counts of them: pull requests, the specs and issues they name, and how many name a spec or an issue.
|
|
77
|
+
* @param {{ commits: object[], nodes: Record<string, { born: number, commits: number[] }> } | null} history
|
|
78
|
+
* @param {string} nodeId
|
|
79
|
+
*/
|
|
80
|
+
export function nodeTrail(history, nodeId) {
|
|
81
|
+
const entry = history && history.nodes && Object.hasOwn(history.nodes, nodeId) ? history.nodes[nodeId] : null;
|
|
82
|
+
if (!entry) return null;
|
|
83
|
+
const commits = entry.commits.map((i) => ({ ...history.commits[i], index: i })).filter((c) => c.sha).reverse();
|
|
84
|
+
const uniq = (xs) => [...new Set(xs)];
|
|
85
|
+
return {
|
|
86
|
+
commits,
|
|
87
|
+
born: history.commits[entry.born] ? { ...history.commits[entry.born], index: entry.born } : null,
|
|
88
|
+
pulls: uniq(commits.map((c) => c.pr).filter((n) => n != null)),
|
|
89
|
+
specs: uniq(commits.flatMap((c) => c.specs || [])),
|
|
90
|
+
issues: uniq(commits.flatMap((c) => c.issues || [])),
|
|
91
|
+
traced: commits.filter((c) => (c.specs && c.specs.length) || (c.issues && c.issues.length) || (c.keys && c.keys.length)).length,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const chip = (kind, href, words, title) => (href
|
|
96
|
+
? `<a class="hx-trail-chip" data-corn="text-link" data-trail="${kind}" href="${esc(href)}" target="_blank" rel="noreferrer"${title ? ` title="${esc(title)}"` : ''}>${words}</a>`
|
|
97
|
+
: `<span class="hx-trail-chip" data-trail="${kind}"${title ? ` title="${esc(title)}"` : ''}>${words}</span>`);
|
|
98
|
+
const gap = (what) => `<span class="hx-trail-chip" data-trail="gap">no ${what}</span>`;
|
|
99
|
+
const ARROW = '<span class="hx-trail-arrow" aria-hidden="true">→</span>';
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A commit's trail, from spec to issue to pull request to commit. Each a link on the forge when there is one (a spec to its file); what the commit does not name is a dashed gap.
|
|
103
|
+
* @param {{ sha: string, pr: number | null, issues: number[], specs: string[], keys?: string[] }} c
|
|
104
|
+
* @param {{ links: ReturnType<typeof forgeLinks>, specs: ReturnType<typeof specFiles> }} ctx
|
|
105
|
+
*/
|
|
106
|
+
export function trailHtml(c, { links, specs }) {
|
|
107
|
+
const parts = [];
|
|
108
|
+
if (c.specs && c.specs.length) {
|
|
109
|
+
for (const s of c.specs) {
|
|
110
|
+
const spec = specs.get(s);
|
|
111
|
+
parts.push(chip('spec', spec && links ? links.file(spec.file) : null, `Spec ${esc(s)}`, spec ? spec.label : ''));
|
|
112
|
+
}
|
|
113
|
+
} else parts.push(gap('spec'));
|
|
114
|
+
if (c.issues && c.issues.length) for (const n of c.issues) parts.push(chip('issue', links && links.issue(n), `Issue #${esc(n)}`));
|
|
115
|
+
else if (c.keys && c.keys.length) for (const k of c.keys) parts.push(chip('issue', null, esc(k)));
|
|
116
|
+
else parts.push(gap('issue'));
|
|
117
|
+
if (c.pr != null) parts.push(chip('pull', links && links.pull(c.pr), `PR #${esc(c.pr)}`));
|
|
118
|
+
else parts.push(gap('pull request'));
|
|
119
|
+
parts.push(chip('commit', links && links.commit(c.sha), `<span class="hx-mono">${esc(String(c.sha).slice(0, 7))}</span>`, 'The commit on the forge'));
|
|
120
|
+
return `<span class="hx-trail" role="group" aria-label="Spec, issue, pull request and commit">${parts.join(ARROW)}</span>`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** "26 Nov 2026": a commit's day, in the viewer's own words for it */
|
|
124
|
+
export const dayOf = (iso, locale) => {
|
|
125
|
+
const d = new Date(iso);
|
|
126
|
+
return Number.isNaN(d.getTime()) ? '' : d.toLocaleDateString(locale, { day: 'numeric', month: 'short', year: 'numeric' });
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The node panel's History section (spec 0014 D2): counts, the specs behind the node (each picks what the spec reached on the map), the issues, and its commits newest first
|
|
131
|
+
* with their trails. Every word from git and the forge is escaped; only https links are made.
|
|
132
|
+
* @param {{ id: string }} node
|
|
133
|
+
* @param {{ history: object | null, status: 'off' | 'loading' | 'ready' | 'error', error?: string, links: ReturnType<typeof forgeLinks>, specs: ReturnType<typeof specFiles>, picked?: string | null, all?: boolean, locale?: string }} ctx
|
|
134
|
+
*/
|
|
135
|
+
export function historySectionHtml(node, ctx) {
|
|
136
|
+
const head = '<h3 class="hx-sec-title">History</h3>';
|
|
137
|
+
const wrap = (body) => `<div class="hx-sec-block hx-history" data-corn="section" data-history>${head}${body}</div>`;
|
|
138
|
+
if (ctx.status === 'off') return '';
|
|
139
|
+
if (ctx.status === 'loading') return wrap('<p class="hx-faint" data-corn="loading">Reading the history…</p>');
|
|
140
|
+
if (ctx.status === 'error') return wrap(`<p class="hx-faint" data-corn="error">${esc(ctx.error || 'The history could not be read.')}</p>`);
|
|
141
|
+
const t = nodeTrail(ctx.history, node.id);
|
|
142
|
+
if (!t) return wrap('<p class="hx-faint">This node is not in the history yet: run <code class="hx-code">cornfield sync</code> and commit the map.</p>');
|
|
143
|
+
if (!t.commits.length) return wrap('<p class="hx-faint">No commit has changed this node\'s file yet.</p>');
|
|
144
|
+
const n = t.commits.length;
|
|
145
|
+
const share = Math.round((t.traced / n) * 100);
|
|
146
|
+
const stats = `<p class="hx-history-stats"><span><b class="hx-ms">${n}</b> ${n === 1 ? 'commit' : 'commits'}</span> · <span><b class="hx-ms">${t.pulls.length}</b> ${t.pulls.length === 1 ? 'pull request' : 'pull requests'}</span> · <span><b class="hx-ms">${share}%</b> traced to a spec or issue</span></p>`;
|
|
147
|
+
const specChips = t.specs.map((s) => {
|
|
148
|
+
const spec = ctx.specs.get(s);
|
|
149
|
+
const on = ctx.picked === s;
|
|
150
|
+
return `<button type="button" class="hx-lines-kind" data-corn-kind="quiet" data-history-spec="${esc(s)}" aria-pressed="${on}" title="Light every node spec ${esc(s)} reached">Spec ${esc(s)}${spec ? ` <span class="hx-faint">${esc(spec.label)}</span>` : ''}</button>`;
|
|
151
|
+
});
|
|
152
|
+
const specs = specChips.length ? `<div class="hx-chips" role="group" aria-label="Specs behind it">${specChips.join('')}</div>` : '<p class="hx-faint">No commit to this node names a spec.</p>';
|
|
153
|
+
const issues = t.issues.length ? `<p class="hx-history-issues">Issues: ${t.issues.map((i) => { const href = ctx.links && ctx.links.issue(i); return href ? `<a class="hx-link" data-corn="text-link" href="${esc(href)}" target="_blank" rel="noreferrer">#${esc(i)}</a>` : `#${esc(i)}`; }).join(', ')}</p>` : '';
|
|
154
|
+
const shown = ctx.all ? t.commits : t.commits.slice(0, HISTORY_CAP);
|
|
155
|
+
const rows = shown.map((c) => `<li class="hx-history-commit" data-corn="row">`
|
|
156
|
+
+ `<div class="hx-row-meta">${esc(dayOf(c.date, ctx.locale))} · ${c.nodes.length} ${c.nodes.length === 1 ? 'node' : 'nodes'}${t.born && c.index === t.born.index ? ' · <span class="hx-history-born">born here</span>' : ''}</div>`
|
|
157
|
+
+ `<div class="hx-history-subject">${esc(c.subject)}</div>`
|
|
158
|
+
+ trailHtml(c, ctx)
|
|
159
|
+
+ '</li>');
|
|
160
|
+
const more = shown.length < n ? `<button type="button" class="hx-btn hx-btn--quiet hx-textact" data-corn="more" data-corn-kind="quiet" data-history-all>Show all ${n}</button>` : '';
|
|
161
|
+
return wrap(`${stats}<h4 class="hx-history-k">Specs behind it</h4>${specs}${issues}<h4 class="hx-history-k">Commits, newest first</h4><ol class="hx-history-list">${rows.join('')}</ol>${more}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* What a spec reached: the nodes its commits touched, and how many commits named it (spec 0014 D3: picking a spec lights them).
|
|
166
|
+
* @param {{ commits: { specs: string[], nodes: string[] }[] } | null} history
|
|
167
|
+
* @param {string} spec
|
|
168
|
+
*/
|
|
169
|
+
export function specReach(history, spec) {
|
|
170
|
+
const nodes = new Set();
|
|
171
|
+
let commits = 0;
|
|
172
|
+
for (const c of (history && history.commits) || []) {
|
|
173
|
+
if (!c.specs || !c.specs.includes(spec)) continue;
|
|
174
|
+
commits++;
|
|
175
|
+
for (const id of c.nodes) nodes.add(id);
|
|
176
|
+
}
|
|
177
|
+
return { nodes, commits };
|
|
178
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/history
|
|
3
|
+
*
|
|
4
|
+
* A node's history on an instance (spec 0014 D2): reads `GET /api/history` (core/history.js) once, the first time the node panel asks, and
|
|
5
|
+
* answers the panel's History section; picking a spec lights every node its commits touched (`state.historyPick`, which scene.js dims around).
|
|
6
|
+
* Nothing is fetched while the config says `history: false`, and the panel then has no History section.
|
|
7
|
+
*
|
|
8
|
+
* initHistory(inst, config) once, with the client config (`history`, `forge`); returns how to stop
|
|
9
|
+
*
|
|
10
|
+
* What it answers and hears (instance.js lists them):
|
|
11
|
+
* history:section node -> HTML | undefined the node panel's History section; asking starts the one read
|
|
12
|
+
* history:pick spec | null (emit) light what that spec reached, or nothing; picking the lit spec again ends it
|
|
13
|
+
* history:all (none) (emit) the section lists every commit, not only the newest
|
|
14
|
+
* history:changed (none) (emitted) the read ended, or a pick changed: the open panel draws its History section again
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { credentialed } from './engine/connection.js';
|
|
18
|
+
import { announce } from './engine/keyboard.js';
|
|
19
|
+
import { forgeLinks, historySectionHtml, specFiles, specReach } from './history-model.js';
|
|
20
|
+
|
|
21
|
+
/** Where the server answers the history (server/server.js) */
|
|
22
|
+
export const HISTORY_PATH = '/api/history';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {ReturnType<typeof import('./instance.js').createInstance>} inst
|
|
26
|
+
* @param {{ history?: boolean, forge?: object | null }} config the client config (/cornfield/config.json)
|
|
27
|
+
* @returns {() => void}
|
|
28
|
+
*/
|
|
29
|
+
export function initHistory(inst, config) {
|
|
30
|
+
const { state } = inst;
|
|
31
|
+
const on = !!(config && config.history === true);
|
|
32
|
+
const mem = { status: on ? 'idle' : 'off', history: null, error: '', all: false, node: null, links: forgeLinks(config && config.forge), specs: null };
|
|
33
|
+
const stops = [];
|
|
34
|
+
|
|
35
|
+
async function load() {
|
|
36
|
+
if (mem.status !== 'idle') return;
|
|
37
|
+
mem.status = 'loading';
|
|
38
|
+
try {
|
|
39
|
+
const res = await credentialed(inst)(HISTORY_PATH);
|
|
40
|
+
const body = await res.json().catch(() => null);
|
|
41
|
+
if (!res.ok || !body || body.ok !== true) throw new Error(body && typeof body.error === 'string' ? body.error : `The history could not be read (${res.status}).`);
|
|
42
|
+
mem.history = body;
|
|
43
|
+
mem.status = 'ready';
|
|
44
|
+
} catch (err) {
|
|
45
|
+
mem.status = 'error';
|
|
46
|
+
mem.error = inst.offline() ? 'You are offline, so the history could not be read.' : String(err && err.message ? err.message : err);
|
|
47
|
+
}
|
|
48
|
+
inst.emit('history:changed');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function pick(spec) {
|
|
52
|
+
if (!spec || (state.historyPick && state.historyPick.spec === spec) || mem.status !== 'ready') {
|
|
53
|
+
if (!state.historyPick) return;
|
|
54
|
+
state.historyPick = null;
|
|
55
|
+
announce(inst, 'Showing the whole map again');
|
|
56
|
+
} else {
|
|
57
|
+
const { nodes, commits } = specReach(mem.history, spec);
|
|
58
|
+
state.historyPick = { spec, nodes };
|
|
59
|
+
announce(inst, `Spec ${spec}: ${commits} ${commits === 1 ? 'commit' : 'commits'} reached ${nodes.size} ${nodes.size === 1 ? 'node' : 'nodes'}; the rest is dimmed`);
|
|
60
|
+
}
|
|
61
|
+
inst.touchScene();
|
|
62
|
+
if (inst.map) inst.map.render();
|
|
63
|
+
inst.emit('history:changed');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
stops.push(inst.on('history:section', (node) => {
|
|
67
|
+
if (mem.status === 'off' || !node || typeof node.id !== 'string') return undefined;
|
|
68
|
+
if (mem.node !== node.id) { mem.node = node.id; mem.all = false; } // "Show all" is for the node it was pressed on
|
|
69
|
+
if (mem.status === 'idle') load();
|
|
70
|
+
if (!mem.specs) mem.specs = specFiles(state.nodes);
|
|
71
|
+
return historySectionHtml(node, { history: mem.history, status: mem.status === 'idle' ? 'loading' : mem.status, error: mem.error, links: mem.links, specs: mem.specs, picked: state.historyPick ? state.historyPick.spec : null, all: mem.all });
|
|
72
|
+
}));
|
|
73
|
+
stops.push(inst.on('history:pick', (spec) => pick(typeof spec === 'string' ? spec : null)));
|
|
74
|
+
// A selection cleared (the bare map, Escape, Close) ends a pick too: nothing on screen would say why the map is dim
|
|
75
|
+
stops.push(inst.on('selection', () => { if (!state.selectedNode && state.historyPick) pick(null); }));
|
|
76
|
+
stops.push(inst.on('history:all', () => { mem.all = true; inst.emit('history:changed'); }));
|
|
77
|
+
return () => { stops.forEach((s) => s()); if (state.historyPick) { state.historyPick = null; inst.touchScene(); } };
|
|
78
|
+
}
|
|
@@ -43,6 +43,8 @@ export function createState() {
|
|
|
43
43
|
/** The config's `forge` (`{ type, url, repo, baseBranch? }`), or null: where a node's file is opened (file-url.js) */
|
|
44
44
|
forge: null,
|
|
45
45
|
searchQuery: '',
|
|
46
|
+
/** The spec picked in a node's History (history.js, spec 0014 D3): `{ spec, nodes }`, the nodes its commits touched, lit while the rest dims; or null */
|
|
47
|
+
historyPick: null,
|
|
46
48
|
/** The id of the search match the stepping is on (search.js), or null: the map draws its halo and places its label first of the matches */
|
|
47
49
|
searchCurrent: null,
|
|
48
50
|
/** The id of the node the pointer is on (input.js): a node with no label is named by a chip while it is */
|
package/explorer/instance.js
CHANGED
|
@@ -99,6 +99,8 @@
|
|
|
99
99
|
* player:seat bar -> true the dock's owner (engine/sheets.js) seats the scenario player's bar as a sheet above the node panel's
|
|
100
100
|
* threads:index nodeId -> { threads: thread[] | null, forge: string, start: true } | undefined the Work list's list of the threads that mention a node, for the node panel's "Threads"; `threads` is null until the list was read; no answer: no Threads section
|
|
101
101
|
* threads:ensure (none) (emit) the node panel was filled: the Work list reads the threads list once; threads:changed: it was read, or the map changed, so the node panel draws "Threads" again
|
|
102
|
+
* history:section node -> HTML | undefined (ask, answered by history.js when the config says `history: true`) the node panel's History section (spec 0014 D2); history:pick spec | null
|
|
103
|
+
* (emit): light what a spec's commits reached; history:all (emit): list every commit; history:changed (emit): the panel draws History again
|
|
102
104
|
* work:list { open } the Work list opened or closed (pieces/work-list.js)
|
|
103
105
|
* work:pick { kind, key } -> true (ask, answered by the Work view: explorer/work-view.js) select the node of that piece of work (`pull`, `issue`, `thread`, `run`, `deploy`, `proposal`, and its number, id or slug) on the map; no answer: the Work piece shows it in the node panel alone, as it shows work older than the graph's 14 days
|
|
104
106
|
* work:panel node -> { replace, badge, title, html } | undefined (ask, answered by the Work view) what the node panel shows for a piece of work or, in the Work view, a node of code; the html holds `forge-detail`, where the Work piece draws the actions
|
package/explorer/page.js
CHANGED
|
@@ -62,6 +62,7 @@ import { initTheme, setThemeChoice } from './theme.js';
|
|
|
62
62
|
import { initAccountMenu } from './account-menu.js';
|
|
63
63
|
import { watchHeaderFit } from './header-fit.js';
|
|
64
64
|
import { watchHint } from './hint.js';
|
|
65
|
+
import { initHistory } from './history.js';
|
|
65
66
|
|
|
66
67
|
/** The instance and its map: made by `startPage`, the one of this document */
|
|
67
68
|
let inst;
|
|
@@ -203,6 +204,7 @@ export function startPage() {
|
|
|
203
204
|
initWhatIf(); // before a proposal can open, so its edits come with it
|
|
204
205
|
initReview(); // the decision follows the what-if editor's edits
|
|
205
206
|
initMockups(); // a proposal's screens open from the node they name
|
|
207
|
+
initHistory(inst, config); // a node's commits and their trails in the node panel, read when first shown (history.js; only with `history: true`)
|
|
206
208
|
// /?proposal=<slug> (&source=, &proposalView=) opens a proposal, as a host would ask for one (page-address.js)
|
|
207
209
|
const proposalOpened = await openFromAddress(inst, window.location.search);
|
|
208
210
|
// The live layer (live.js): loads only once a live layer goes on in the Layers menu; with no source it stays off
|
|
@@ -370,7 +370,7 @@ export function mount(root, inst, options = {}) {
|
|
|
370
370
|
}
|
|
371
371
|
|
|
372
372
|
const metaList = own('drawer-meta-list');
|
|
373
|
-
scope.listen(metaList, 'click', (e) => { if (!onLinesClick(e)) toggleCapped(e.target); });
|
|
373
|
+
scope.listen(metaList, 'click', (e) => { if (!onLinesClick(e) && !onHistoryClick(e)) toggleCapped(e.target); });
|
|
374
374
|
scope.listen(metaList, 'change', onLinesChange);
|
|
375
375
|
|
|
376
376
|
/** Keeps "9 connected · 3 off screen" true as the camera moves (after every draw, while a node is selected and its panel is open) */
|
|
@@ -391,6 +391,26 @@ export function mount(root, inst, options = {}) {
|
|
|
391
391
|
addParts(box);
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
+
/** Draws "History" again in the open panel (spec 0014 D2: the history was read, a spec was picked, or Show all); nothing else in the panel moves */
|
|
395
|
+
function repaintHistory() {
|
|
396
|
+
const box = own('drawer-history');
|
|
397
|
+
const node = state.selectedNode;
|
|
398
|
+
if (!box || !node || gone) return;
|
|
399
|
+
const active = inst.active();
|
|
400
|
+
const key = active && box.contains(active) ? (active.dataset.historySpec ? `spec:${active.dataset.historySpec}` : active.hasAttribute('data-history-all') ? 'all' : '') : '';
|
|
401
|
+
box.innerHTML = inst.ask('history:section', node) || '';
|
|
402
|
+
addParts(box);
|
|
403
|
+
if (key.startsWith('spec:')) { const el = [...box.querySelectorAll('[data-history-spec]')].find((x) => `spec:${x.dataset.historySpec}` === key); if (el) el.focus(); }
|
|
404
|
+
else if (key === 'all') { const first = box.querySelector('.hx-history-commit a'); if (first) first.focus(); }
|
|
405
|
+
}
|
|
406
|
+
/** A spec's chip in "History" picks it (or ends the pick); "Show all" lists every commit */
|
|
407
|
+
function onHistoryClick(e) {
|
|
408
|
+
const spec = e.target.closest && e.target.closest('[data-history-spec]');
|
|
409
|
+
if (spec) { inst.emit('history:pick', spec.dataset.historySpec); return true; }
|
|
410
|
+
if (e.target.closest && e.target.closest('[data-history-all]')) { inst.emit('history:all'); return true; }
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
|
|
394
414
|
/** What the Work view put first in the panel for a node of code (the Work layer's "Open work", or the work touching it in the Work view): its elements and its markup */
|
|
395
415
|
let workShown = { node: null, html: '', els: [] };
|
|
396
416
|
function putWork(node, html) {
|
|
@@ -437,6 +457,7 @@ export function mount(root, inst, options = {}) {
|
|
|
437
457
|
<div id="drawer-live">${live}</div>
|
|
438
458
|
${nodeMockupsHtml(state, node.id)}
|
|
439
459
|
<div id="drawer-threads">${sections.threadsSection(node)}</div>
|
|
460
|
+
<div id="drawer-history">${inst.ask('history:section', node) || ''}</div>
|
|
440
461
|
${sections.diffSection(node)}`;
|
|
441
462
|
addParts(metaList);
|
|
442
463
|
inst.emit('threads:ensure'); // the Work list reads the threads once, for "Mentioned in"
|
|
@@ -573,6 +594,7 @@ export function mount(root, inst, options = {}) {
|
|
|
573
594
|
});
|
|
574
595
|
// The threads that mention nodes changed (the list was read, or the map changed): the section is drawn again
|
|
575
596
|
scope.on('threads:changed', () => repaintThreads());
|
|
597
|
+
scope.on('history:changed', () => repaintHistory());
|
|
576
598
|
scope.on('work:changed', () => repaintWork());
|
|
577
599
|
// The dim layer behind the panel: on a phone a tap there folds the panel to its peek; elsewhere it closes it
|
|
578
600
|
if (!inline) {
|
package/explorer/scene.js
CHANGED
|
@@ -589,9 +589,11 @@ function buildNodes(state, subgraph) {
|
|
|
589
589
|
// deep dimming for what is not connected; a proposal's Diff view fades what it does not touch, less deeply, and a removed node is faded too
|
|
590
590
|
// A search's matches are what the reader asked for: a selection's focus does not dim them, so each keeps its label (spec 0008 D4)
|
|
591
591
|
const dimmed = state.view === 'work' ? PROPOSAL_DIM_ALPHA : DIM_ALPHA; // the Work view dims to what the mock shows: the rest is still readable
|
|
592
|
-
|
|
592
|
+
const picked = !!state.historyPick && state.historyPick.nodes.has(node.id); // a picked spec's nodes are what the reader asked for, as a search's matches are
|
|
593
|
+
let alpha = subgraph && !connected && !(searching && match) && !picked ? dimmed : 1;
|
|
593
594
|
if (searching && !match && !selected && !(subgraph && connected)) alpha = dimmed; // a search dims what it did not find, as a focus does
|
|
594
595
|
if (node.dim === true) alpha = Math.min(alpha, dimmed); // "Waiting on you" (work-view.js)
|
|
596
|
+
if (state.historyPick && !picked && !selected) alpha = Math.min(alpha, dimmed); // a picked spec lights what it reached (history.js, spec 0014 D3)
|
|
595
597
|
const greyed = grey && !!focus && !focus.touched.has(node.id);
|
|
596
598
|
if (focus && !focus.touched.has(node.id)) alpha = Math.min(alpha, greyed ? GREY_ALPHA : PROPOSAL_DIM_ALPHA);
|
|
597
599
|
if (look) alpha *= gone ? MARK.removed.alpha : look.alpha;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@popcorn245/cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.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)",
|